chore: flatten tool calling, prep for timeout handling (#205)

This commit is contained in:
Pavel Feldman
2025-04-16 19:36:48 -07:00
committed by GitHub
parent cea347d067
commit 7e4a964b0a
16 changed files with 484 additions and 336 deletions

View File

@@ -25,27 +25,35 @@ const uploadFileSchema = z.object({
const uploadFile: ToolFactory = captureSnapshot => ({
capability: 'files',
schema: {
name: 'browser_file_upload',
description: 'Upload one or multiple files',
inputSchema: zodToJsonSchema(uploadFileSchema),
},
handle: async (context, params) => {
const validatedParams = uploadFileSchema.parse(params);
const tab = context.currentTab();
return await tab.runAndWait(async () => {
const modalState = context.modalStates().find(state => state.type === 'fileChooser');
if (!modalState)
throw new Error('No file chooser visible');
const modalState = context.modalStates().find(state => state.type === 'fileChooser');
if (!modalState)
throw new Error('No file chooser visible');
const code = [
`// <internal code to chose files ${validatedParams.paths.join(', ')}`,
];
const action = async () => {
await modalState.fileChooser.setFiles(validatedParams.paths);
context.clearModalState(modalState);
const code = [
`// <internal code to chose files ${validatedParams.paths.join(', ')}`,
];
return { code };
}, {
return {};
};
return {
code,
action,
captureSnapshot,
});
waitForNetwork: true,
};
},
clearsModalState: 'fileChooser',
});