(ctx, args)
| 24 | export 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 | } |
no test coverage detected