11import type Limrun from '@limrun/api' ;
2- import type { DeviceLease } from '@agent-device/contracts/device' ;
2+ import type { DeviceLease , LeaseLifecycleContext } from '@agent-device/contracts/device' ;
33import { AppError } from '@agent-device/kernel/errors' ;
44import { createLimrunAndroidSession , type LimrunAndroidSession } from './android.ts' ;
55import { buildLimrunDevice } from './device.ts' ;
66import { createLimrunIosSession , type LimrunIosSession } from './ios.ts' ;
7- import type { LimrunAppAsset } from './app-catalog.ts' ;
7+ import {
8+ resolveInstalledAppIdForAsset ,
9+ resolveLimrunAppAsset ,
10+ type LimrunAppAsset ,
11+ } from './app-catalog.ts' ;
12+ import { createLimrunDeviceSession } from './device-session.ts' ;
813import type { LimrunRuntimeDependencies } from './runtime-dependencies.ts' ;
914
1015type LimrunInstance = {
@@ -28,6 +33,31 @@ type SessionAllocationParams = Readonly<{
2833 dependencies : LimrunRuntimeDependencies ;
2934} > ;
3035
36+ export async function resolveRequestedLimrunAppAsset (
37+ limrun : Limrun ,
38+ platform : 'android' | 'ios' ,
39+ context ?: LeaseLifecycleContext ,
40+ ) : Promise < LimrunAppAsset | undefined > {
41+ const value = context ?. flags ?. providerApp ;
42+ const name = typeof value === 'string' ? value . trim ( ) : '' ;
43+ if ( ! name ) return undefined ;
44+ return await resolveLimrunAppAsset ( limrun , platform , name , context ?. signal ) ;
45+ }
46+
47+ export async function resolvePreinstalledAppId (
48+ session : LimrunAndroidSession | LimrunIosSession ,
49+ asset : LimrunAppAsset ,
50+ ) : Promise < string > {
51+ const apps = await createLimrunDeviceSession ( session ) . listApps ( 'user-installed' ) ;
52+ const matchedAppId = resolveInstalledAppIdForAsset ( asset . name , apps ) ;
53+ if ( matchedAppId ) return matchedAppId ;
54+ throw new AppError (
55+ 'COMMAND_FAILED' ,
56+ `Limrun installed ${ asset . name } , but its application identifier could not be resolved unambiguously.` ,
57+ { asset : asset . name , installedApps : apps . map ( ( app ) => app . id ) } ,
58+ ) ;
59+ }
60+
3161export async function allocateLimrunIosSession (
3262 params : SessionAllocationParams ,
3363) : Promise < LimrunIosSession > {
0 commit comments