MCPcopy Create free account
hub / github.com/simstudioai/sim / handle

Function handle

apps/sim/lib/execution/sandbox/brokers/workspace-file.ts:26–46  ·  view source on GitHub ↗
(ctx, args)

Source from the content-addressed store, hash-verified

24export const workspaceFileBroker: SandboxBroker<WorkspaceFileArgs, WorkspaceFileResult> = {
25 name: 'workspaceFile',
26 async handle(ctx, args) {
27 if (!args || typeof args.fileId !== 'string' || args.fileId.length === 0) {
28 throw new Error('workspaceFile broker requires a non-empty fileId')
29 }
30 if (!ctx.workspaceId) {
31 throw new Error('workspaceFile broker requires a workspaceId')
32 }
33
34 const record = await getWorkspaceFile(ctx.workspaceId, args.fileId)
35 if (!record) {
36 logger.warn('Workspace file not found for sandbox broker', {
37 workspaceId: ctx.workspaceId,
38 fileId: args.fileId,
39 })
40 throw new Error(`File not found: ${args.fileId}`)
41 }
42
43 const buffer = await fetchWorkspaceFileBuffer(record)
44 const mime = record.type || 'image/png'
45 return { dataUri: `data:${mime};base64,${buffer.toString('base64')}` }
46 },
47}

Callers 1

transformStringsFunction · 0.85

Calls 4

getWorkspaceFileFunction · 0.90
fetchWorkspaceFileBufferFunction · 0.90
warnMethod · 0.65
toStringMethod · 0.45

Tested by

no test coverage detected