MCPcopy Create free account
hub / github.com/apache/maka / snapshotComputerParams

Function snapshotComputerParams

packages/runtime/src/computer-use-codec.ts:476–496  ·  view source on GitHub ↗
(args: ComputerParams)

Source from the content-addressed store, hash-verified

474const point = (c?: [number, number]): CuPoint | undefined => (c ? { x: c[0], y: c[1] } : undefined);
475
476export function snapshotComputerParams(args: ComputerParams): ComputerParams {
477 for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(args))) {
478 if (descriptor.get || descriptor.set) {
479 throw new Error(`invalid_computer_params: '${key}' must be a plain data property`);
480 }
481 }
482 const cloneTuple = <T extends readonly number[] | undefined>(value: T): T =>
483 (value ? Object.freeze([...value]) : value) as T;
484 const source = args as ComputerParams & Record<string, unknown>;
485 const snapshot = { ...source } as Record<string, unknown>;
486 if (Object.hasOwn(source, 'coordinate')) {
487 snapshot.coordinate = cloneTuple(source.coordinate as [number, number] | undefined);
488 }
489 if (Object.hasOwn(args, 'start_coordinate')) {
490 snapshot.start_coordinate = cloneTuple(source.start_coordinate as [number, number] | undefined);
491 }
492 if (Object.hasOwn(source, 'region')) {
493 snapshot.region = cloneTuple(source.region as [number, number, number, number] | undefined);
494 }
495 return Object.freeze(snapshot) as ComputerParams;
496}
497
498/**
499 * Map the provider-neutral wire grammar onto the discriminated `CuAction` the

Callers 2

buildComputerUseToolsFunction · 0.85

Calls 2

cloneTupleFunction · 0.85
entriesMethod · 0.65

Tested by

no test coverage detected