(run: () => Promise<unknown>, maxPayloadBytes: number)
| 460 | } |
| 461 | |
| 462 | async 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 | |
| 476 | function assertResponseWithin(value: unknown, maxBytes: number) { |
| 477 | let bytes = 0; |
no test coverage detected