@@ -4,6 +4,11 @@ import type { DaemonRequest, SessionRuntimeHints } from './daemon/types.ts';
44import { AppError , type NormalizedError } from './utils/errors.ts' ;
55import type { SnapshotNode } from './utils/snapshot.ts' ;
66import { buildAppIdentifiers , buildDeviceIdentifiers } from './client-shared.ts' ;
7+ import {
8+ leaseScopeFromOptions ,
9+ leaseScopeToCommandFlags ,
10+ leaseScopeToRequestMeta ,
11+ } from './core/lease-scope.ts' ;
712import type {
813 AgentDeviceDevice ,
914 AgentDeviceSession ,
@@ -157,13 +162,12 @@ function buildClientDevicePlatformFields(
157162}
158163
159164export function normalizeRuntimeHints ( value : unknown ) : SessionRuntimeHints | undefined {
160- if ( value === null || typeof value !== 'object' || Array . isArray ( value ) ) return undefined ;
161- const record = value as Record < string , unknown > ;
162- const platform = record . platform ;
163- const metroHost = readOptionalString ( record , 'metroHost' ) ;
164- const metroPort = typeof record . metroPort === 'number' ? record . metroPort : undefined ;
165- const bundleUrl = readOptionalString ( record , 'bundleUrl' ) ;
166- const launchUrl = readOptionalString ( record , 'launchUrl' ) ;
165+ if ( ! isRecord ( value ) ) return undefined ;
166+ const platform = value . platform ;
167+ const metroHost = readOptionalString ( value , 'metroHost' ) ;
168+ const metroPort = typeof value . metroPort === 'number' ? value . metroPort : undefined ;
169+ const bundleUrl = readOptionalString ( value , 'bundleUrl' ) ;
170+ const launchUrl = readOptionalString ( value , 'launchUrl' ) ;
167171 return {
168172 platform : platform === 'ios' || platform === 'android' ? platform : undefined ,
169173 metroHost,
@@ -211,21 +215,20 @@ export function normalizeOpenDevice(
211215}
212216
213217export function normalizeStartupSample ( value : unknown ) : StartupPerfSample | undefined {
214- if ( value === null || typeof value !== 'object' || Array . isArray ( value ) ) return undefined ;
215- const record = value as Record < string , unknown > ;
218+ if ( ! isRecord ( value ) ) return undefined ;
216219 if (
217- typeof record . durationMs !== 'number' ||
218- typeof record . measuredAt !== 'string' ||
219- typeof record . method !== 'string'
220+ typeof value . durationMs !== 'number' ||
221+ typeof value . measuredAt !== 'string' ||
222+ typeof value . method !== 'string'
220223 ) {
221224 return undefined ;
222225 }
223226 return {
224- durationMs : record . durationMs ,
225- measuredAt : record . measuredAt ,
226- method : record . method ,
227- appTarget : readOptionalString ( record , 'appTarget' ) ,
228- appBundleId : readOptionalString ( record , 'appBundleId' ) ,
227+ durationMs : value . durationMs ,
228+ measuredAt : value . measuredAt ,
229+ method : value . method ,
230+ appTarget : readOptionalString ( value , 'appTarget' ) ,
231+ appBundleId : readOptionalString ( value , 'appBundleId' ) ,
229232 } ;
230233}
231234
@@ -268,17 +271,15 @@ export function readSnapshotNodes(value: unknown): SnapshotNode[] {
268271}
269272
270273export function buildFlags ( options : InternalRequestOptions ) : CommandFlags {
274+ const leaseScope = leaseScopeFromOptions ( options ) ;
271275 return stripUndefined ( {
272276 stateDir : options . stateDir ,
273277 daemonBaseUrl : options . daemonBaseUrl ,
274278 daemonAuthToken : options . daemonAuthToken ,
275279 daemonTransport : options . daemonTransport ,
276280 daemonServerMode : options . daemonServerMode ,
277- tenant : options . tenant ,
281+ ... leaseScopeToCommandFlags ( leaseScope ) ,
278282 sessionIsolation : options . sessionIsolation ,
279- runId : options . runId ,
280- leaseId : options . leaseId ,
281- leaseBackend : options . leaseBackend ,
282283 platform : options . platform ,
283284 target : options . target ,
284285 device : options . device ,
@@ -352,21 +353,15 @@ export function buildFlags(options: InternalRequestOptions): CommandFlags {
352353}
353354
354355export function buildMeta ( options : InternalRequestOptions ) : DaemonRequest [ 'meta' ] {
356+ const leaseScope = leaseScopeFromOptions ( options ) ;
355357 return stripUndefined ( {
356358 requestId : options . requestId ,
357359 cwd : options . cwd ,
358360 sessionExplicit : options . session !== undefined ,
359361 debug : options . debug ,
360362 lockPolicy : options . lockPolicy ,
361363 lockPlatform : options . lockPlatform ,
362- tenantId : options . tenant ,
363- runId : options . runId ,
364- leaseId : options . leaseId ,
365- leaseBackend : options . leaseBackend ,
366- leaseTtlMs : options . leaseTtlMs ,
367- leaseProvider : options . leaseProvider ,
368- clientId : options . clientId ,
369- deviceKey : options . deviceKey ,
364+ ...leaseScopeToRequestMeta ( leaseScope ) ,
370365 sessionIsolation : options . sessionIsolation ,
371366 installSource : options . installSource ,
372367 retainMaterializedPaths : options . retainMaterializedPaths ,
0 commit comments