( context: FunctionRouteExecutionContext )
| 787 | } |
| 788 | |
| 789 | function createFunctionRuntimeBrokers( |
| 790 | context: FunctionRouteExecutionContext |
| 791 | ): Record<string, IsolatedVMBrokerHandler> { |
| 792 | context.largeValueKeys ??= [] |
| 793 | context.fileKeys ??= [] |
| 794 | const largeValueKeys = context.largeValueKeys |
| 795 | const fileKeys = context.fileKeys |
| 796 | const base = { |
| 797 | requestId: context.requestId, |
| 798 | workflowId: context.workflowId, |
| 799 | workspaceId: context.workspaceId, |
| 800 | executionId: context.executionId, |
| 801 | largeValueExecutionIds: context.largeValueExecutionIds, |
| 802 | largeValueKeys, |
| 803 | fileKeys, |
| 804 | allowLargeValueWorkflowScope: context.allowLargeValueWorkflowScope, |
| 805 | userId: context.userId, |
| 806 | logger, |
| 807 | } |
| 808 | |
| 809 | const recordMaterializedKeys = (value: unknown) => |
| 810 | recordMaterializedAccessKeys({ largeValueKeys, fileKeys }, value) |
| 811 | |
| 812 | const readFile = async (args: unknown, encoding: 'base64' | 'text', chunked = false) => { |
| 813 | const fileArgs = getBrokerFileArgs(args) |
| 814 | return readUserFileContent(fileArgs.file, { |
| 815 | ...base, |
| 816 | encoding, |
| 817 | maxBytes: fileArgs.maxBytes, |
| 818 | chunked, |
| 819 | offset: chunked ? fileArgs.offset : undefined, |
| 820 | length: chunked ? fileArgs.length : undefined, |
| 821 | }) |
| 822 | } |
| 823 | |
| 824 | return { |
| 825 | 'sim.files.readBase64': (args) => readFile(args, 'base64'), |
| 826 | 'sim.files.readText': (args) => readFile(args, 'text'), |
| 827 | 'sim.files.readBase64Chunk': (args) => readFile(args, 'base64', true), |
| 828 | 'sim.files.readTextChunk': (args) => readFile(args, 'text', true), |
| 829 | 'sim.values.read': async (args) => { |
| 830 | const record = asRecord(args) |
| 831 | const options = asRecord(record.options) |
| 832 | const ref = record.ref |
| 833 | if (!isLargeValueRef(ref)) { |
| 834 | throw new Error('Expected a large execution value reference.') |
| 835 | } |
| 836 | if (!context.executionId) { |
| 837 | throw new Error('Large execution values require an execution context.') |
| 838 | } |
| 839 | const value = await materializeLargeValueRef(ref, { |
| 840 | ...base, |
| 841 | maxBytes: clampInlineBytes(options.maxBytes, MAX_INLINE_MATERIALIZATION_BYTES), |
| 842 | }) |
| 843 | if (value === undefined) { |
| 844 | throw unavailableLargeValueError(ref) |
| 845 | } |
| 846 | recordMaterializedKeys(value) |
no test coverage detected