Skip to content

Commit 87a4b1a

Browse files
committed
fix(ad-script): check replay surfaces without growing the eager closure
1 parent f90a483 commit 87a4b1a

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

‎packages/ad-script/src/internal/open-script.ts‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { SessionAction } from '@agent-device/contracts/session';
2-
import { parseSessionSurface } from '@agent-device/contracts/session';
1+
import { AppError } from '@agent-device/kernel/errors';
2+
import type { SessionAction, SessionSurface } from '@agent-device/contracts/session';
33
import {
44
appendRuntimeHintFlags,
55
formatScriptArg,
@@ -68,7 +68,7 @@ export function parseReplayOpenFlags(args: string[]): {
6868
for (let index = 0; index < args.length; index += 1) {
6969
const token = args[index]!;
7070
if (token === '--surface') {
71-
flags.surface = parseSessionSurface(args[index + 1]);
71+
flags.surface = parseReplaySurface(args[index + 1]);
7272
index += 1;
7373
continue;
7474
}
@@ -94,6 +94,26 @@ export function parseReplayOpenFlags(args: string[]): {
9494
};
9595
}
9696

97+
const REPLAY_SURFACES: Record<SessionSurface, true> = {
98+
app: true,
99+
'frontmost-app': true,
100+
desktop: true,
101+
menubar: true,
102+
};
103+
104+
function isReplaySurface(value: string): value is SessionSurface {
105+
return Object.hasOwn(REPLAY_SURFACES, value);
106+
}
107+
108+
function parseReplaySurface(value: string | undefined): SessionSurface {
109+
const normalized = value?.trim().toLowerCase();
110+
if (normalized !== undefined && isReplaySurface(normalized)) return normalized;
111+
throw new AppError(
112+
'INVALID_ARGS',
113+
`Invalid surface: ${value}. Use ${Object.keys(REPLAY_SURFACES).join('|')}.`,
114+
);
115+
}
116+
97117
function hasReplayOpenRuntimeHints(
98118
flags: ReturnType<typeof parseReplayRuntimeFlags>['flags'],
99119
): boolean {

0 commit comments

Comments
 (0)