@@ -34,6 +34,7 @@ import {
3434 ComputerUseCapabilityDescriptorSchema ,
3535 type ComputerUseCapabilityDescriptor ,
3636} from "../plugins/computer-use-contract.js" ;
37+ import { hasExactOwnKeys } from "./protocol-record.js" ;
3738import { isWorkerToolName , type WorkerToolAuthority } from "./tool-authority.js" ;
3839import { isWorkerTranscriptMessageFrameSafe } from "./transcript-message.js" ;
3940import {
@@ -99,13 +100,6 @@ export type WorkerLaunchDescriptor = WorkerLaunchPlan & {
99100 connectionEndpoint : WorkerConnectionEndpoint ;
100101} ;
101102
102- function hasExactKeys ( value : Record < string , unknown > , required : string [ ] , optional : string [ ] = [ ] ) {
103- const allowed = new Set ( [ ...required , ...optional ] ) ;
104- return (
105- required . every ( ( key ) => key in value ) && Object . keys ( value ) . every ( ( key ) => allowed . has ( key ) )
106- ) ;
107- }
108-
109103function isIdentifier ( value : unknown ) : value is string {
110104 return (
111105 typeof value === "string" &&
@@ -130,7 +124,7 @@ function isInferenceOptions(value: unknown): value is WorkerInferenceOptions {
130124function parseToolAuthority ( value : unknown ) : WorkerToolAuthority | undefined {
131125 if (
132126 ! isRecord ( value ) ||
133- ! hasExactKeys ( value , [ "allowedToolNames" ] ) ||
127+ ! hasExactOwnKeys ( value , [ "allowedToolNames" ] ) ||
134128 ! Array . isArray ( value . allowedToolNames ) ||
135129 ! value . allowedToolNames . every ( isWorkerToolName ) ||
136130 new Set ( value . allowedToolNames ) . size !== value . allowedToolNames . length
@@ -143,7 +137,7 @@ function parseToolAuthority(value: unknown): WorkerToolAuthority | undefined {
143137function parseBrowserLaunchDescriptor ( value : unknown ) : WorkerBrowserLaunchDescriptor | undefined {
144138 if (
145139 ! isRecord ( value ) ||
146- ! hasExactKeys ( value , [ "cdpUrl" , "launcherPath" ] ) ||
140+ ! hasExactOwnKeys ( value , [ "cdpUrl" , "launcherPath" ] ) ||
147141 typeof value . cdpUrl !== "string" ||
148142 typeof value . launcherPath !== "string" ||
149143 ! isAbsoluteHostPath ( value . launcherPath )
@@ -181,7 +175,7 @@ function parseBrowserLaunchDescriptor(value: unknown): WorkerBrowserLaunchDescri
181175function parseAssignment ( value : unknown ) : WorkerLaunchAssignment | undefined {
182176 if (
183177 ! isRecord ( value ) ||
184- ! hasExactKeys (
178+ ! hasExactOwnKeys (
185179 value ,
186180 [
187181 "agentId" ,
@@ -257,7 +251,7 @@ function parseAssignment(value: unknown): WorkerLaunchAssignment | undefined {
257251 toolAuthority . allowedToolNames . includes ( "computer" ) !== ( value . computer !== undefined ) ||
258252 ( value . computer !== undefined &&
259253 ( ! isRecord ( value . computer ) ||
260- ! hasExactKeys ( value . computer , [ "nodeId" , "computerUse" ] ) ||
254+ ! hasExactOwnKeys ( value . computer , [ "nodeId" , "computerUse" ] ) ||
261255 ! isIdentifier ( value . computer . nodeId ) ||
262256 ! Value . Check ( ComputerUseCapabilityDescriptorSchema , value . computer . computerUse ) ) )
263257 ) {
@@ -271,15 +265,15 @@ function parseAssignment(value: unknown): WorkerLaunchAssignment | undefined {
271265 }
272266 if (
273267 ! isRecord ( value . transcript ) ||
274- ! hasExactKeys ( value . transcript , [ "baseLeafId" , "nextSeq" ] ) ||
268+ ! hasExactOwnKeys ( value . transcript , [ "baseLeafId" , "nextSeq" ] ) ||
275269 ( value . transcript . baseLeafId !== null && ! isIdentifier ( value . transcript . baseLeafId ) ) ||
276270 ! isSafeSequence ( value . transcript . nextSeq , 1 )
277271 ) {
278272 return undefined ;
279273 }
280274 if (
281275 ! isRecord ( value . liveEvents ) ||
282- ! hasExactKeys ( value . liveEvents , [ "ackedSeq" , "nextSeq" ] ) ||
276+ ! hasExactOwnKeys ( value . liveEvents , [ "ackedSeq" , "nextSeq" ] ) ||
283277 ! isSafeSequence ( value . liveEvents . ackedSeq , 0 ) ||
284278 ! isSafeSequence ( value . liveEvents . nextSeq , 1 ) ||
285279 value . liveEvents . nextSeq !== value . liveEvents . ackedSeq + 1
@@ -345,7 +339,7 @@ function validateWorkerLaunchPlan(candidate: WorkerLaunchPlan): WorkerLaunchPlan
345339export function parseWorkerLaunchPlan ( value : unknown ) : WorkerLaunchPlan {
346340 if (
347341 ! isRecord ( value ) ||
348- ! hasExactKeys ( value , [ "version" , "admission" , "assignment" ] ) ||
342+ ! hasExactOwnKeys ( value , [ "version" , "admission" , "assignment" ] ) ||
349343 value . version !== LAUNCH_VERSION
350344 ) {
351345 throw new Error ( "invalid worker launch descriptor" ) ;
@@ -376,7 +370,7 @@ export function completeWorkerLaunchDescriptor(
376370export function parseWorkerLaunchDescriptor ( value : unknown ) : WorkerLaunchDescriptor {
377371 if (
378372 ! isRecord ( value ) ||
379- ! hasExactKeys ( value , [ "version" , "connectionEndpoint" , "admission" , "assignment" ] )
373+ ! hasExactOwnKeys ( value , [ "version" , "connectionEndpoint" , "admission" , "assignment" ] )
380374 ) {
381375 throw new Error ( "invalid worker launch descriptor" ) ;
382376 }
0 commit comments