(options: { cwd: string; autoResizeImages: boolean })
| 117 | } |
| 118 | |
| 119 | export function createAttachmentFileTools(options: { cwd: string; autoResizeImages: boolean }): { |
| 120 | tools: ToolDefinition[] |
| 121 | access: AttachmentFileAccess |
| 122 | } { |
| 123 | const grants: AttachmentGrant = { files: new Set(), directories: new Set() } |
| 124 | const attachmentAccess = createAttachmentFileAccess(grants) |
| 125 | |
| 126 | const readTool = createReadToolDefinition(options.cwd, { |
| 127 | autoResizeImages: options.autoResizeImages, |
| 128 | }) |
| 129 | const readExecute = readTool.execute.bind(readTool) |
| 130 | readTool.execute = async (toolCallId, params, signal, onUpdate, ctx) => { |
| 131 | await assertGrantedPath(params.path, grants, options.cwd) |
| 132 | return await readExecute(toolCallId, params, signal, onUpdate, ctx) |
| 133 | } |
| 134 | |
| 135 | const lsTool = createLsToolDefinition(options.cwd) |
| 136 | const lsExecute = lsTool.execute.bind(lsTool) |
| 137 | lsTool.execute = async (toolCallId, params, signal, onUpdate, ctx) => { |
| 138 | await assertGrantedDirectoryPath(params.path ?? '.', grants, options.cwd) |
| 139 | return await lsExecute(toolCallId, params, signal, onUpdate, ctx) |
| 140 | } |
| 141 | |
| 142 | return { tools: [readTool, lsTool] as unknown as ToolDefinition[], access: attachmentAccess } |
| 143 | } |
no test coverage detected