File tree Expand file tree Collapse file tree
packages/ad-script/src/internal Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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' ;
33import {
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+
97117function hasReplayOpenRuntimeHints (
98118 flags : ReturnType < typeof parseReplayRuntimeFlags > [ 'flags' ] ,
99119) : boolean {
You can’t perform that action at this time.
0 commit comments