Repository navigation
Expand file tree
/
Copy pathcontext.ts
More file actions
46 lines (43 loc) · 1.76 KB
/
Copy pathcontext.ts
File metadata and controls
46 lines (43 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import type { CommandFlags } from '@agent-device/contracts/command';
import { dispatchContextFlags, type DispatchContext } from './dispatch-context.ts';
import { resolveClickButton } from '@agent-device/contracts/click-button';
import {
screenshotFlagsFromOptions,
type ScreenshotRuntimeFlags,
} from '@agent-device/contracts/capture';
import { getDiagnosticsMeta } from '@agent-device/host-kit/diagnostics';
import { getRequestSignal } from '@agent-device/host-kit/request';
import { resolveRunnerLogicalLeaseContext } from './lease-context.ts';
import type { DaemonRequest } from './daemon-request.ts';
export type DaemonCommandContext = DispatchContext & ScreenshotRuntimeFlags;
export type BoundContextFromFlags = (
flags: CommandFlags | undefined,
appBundleId?: string,
traceLogPath?: string,
) => DaemonCommandContext;
// The pass-through flags come from their one declaration
// (`DISPATCH_CONTEXT_FLAG_KEYS`); what stays written out here is what this
// mapper actually decides — the request-scope fields, and the three flag
// families that change vocabulary on the way through.
export function contextFromFlags(
logPath: string,
flags: CommandFlags | undefined,
appBundleId?: string,
traceLogPath?: string,
requestId?: string,
meta?: DaemonRequest['meta'],
): DaemonCommandContext {
const effectiveRequestId = requestId ?? getDiagnosticsMeta().requestId;
return {
requestId: effectiveRequestId,
signal: getRequestSignal(effectiveRequestId),
appBundleId,
runnerLeaseContext: resolveRunnerLogicalLeaseContext({ meta }),
logPath,
traceLogPath,
...dispatchContextFlags(flags),
screenshotCaptureBackend: flags?.maestro?.screenshotCaptureBackend,
...screenshotFlagsFromOptions(flags),
clickButton: resolveClickButton(flags),
};
}