MCPcopy Create free account
hub / github.com/cloudflare/computer / encodeCall

Function encodeCall

packages/computer/src/runtime/bridge.ts:462–474  ·  view source on GitHub ↗
(run: () => Promise<unknown>, maxPayloadBytes: number)

Source from the content-addressed store, hash-verified

460}
461
462async function encodeCall(run: () => Promise<unknown>, maxPayloadBytes: number) {
463 try {
464 const result = await run();
465 assertResponseWithin(result, maxPayloadBytes);
466 const encoded = JSON.stringify({ result: encodeBridgeValue(result) });
467 if (new TextEncoder().encode(encoded).byteLength > maxPayloadBytes) {
468 throw new Error(`Workspace capability response exceeds ${maxPayloadBytes} bytes.`);
469 }
470 return encoded;
471 } catch (error) {
472 return encodeBoundedError(error, maxPayloadBytes);
473 }
474}
475
476function assertResponseWithin(value: unknown, maxBytes: number) {
477 let bytes = 0;

Callers 1

callMethod · 0.85

Calls 4

assertResponseWithinFunction · 0.85
encodeBridgeValueFunction · 0.85
encodeBoundedErrorFunction · 0.85
runFunction · 0.50

Tested by

no test coverage detected