first commit
This commit is contained in:
33
app/chrome-extension/entrypoints/background/tools/index.ts
Normal file
33
app/chrome-extension/entrypoints/background/tools/index.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { createErrorResponse } from '@/common/tool-handler';
|
||||
import { ERROR_MESSAGES } from '@/common/constants';
|
||||
import * as browserTools from './browser';
|
||||
|
||||
const tools = { ...browserTools };
|
||||
const toolsMap = new Map(Object.values(tools).map((tool) => [tool.name, tool]));
|
||||
|
||||
/**
|
||||
* Tool call parameter interface
|
||||
*/
|
||||
export interface ToolCallParam {
|
||||
name: string;
|
||||
args: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle tool execution
|
||||
*/
|
||||
export const handleCallTool = async (param: ToolCallParam) => {
|
||||
const tool = toolsMap.get(param.name);
|
||||
if (!tool) {
|
||||
return createErrorResponse(`Tool ${param.name} not found`);
|
||||
}
|
||||
|
||||
try {
|
||||
return await tool.execute(param.args);
|
||||
} catch (error) {
|
||||
console.error(`Tool execution failed for ${param.name}:`, error);
|
||||
return createErrorResponse(
|
||||
error instanceof Error ? error.message : ERROR_MESSAGES.TOOL_EXECUTION_FAILED,
|
||||
);
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user