Update workspace/tools/client.ts
This commit is contained in:
parent
ea11e9b060
commit
6127a01e0d
|
|
@ -0,0 +1,56 @@
|
|||
/**
|
||||
* Tool Proxy Client
|
||||
*
|
||||
* Communicates with Kleap tool proxy server to execute AI tools from sandbox scripts.
|
||||
* Auto-generated - do not modify manually.
|
||||
*/
|
||||
|
||||
const TOOL_PROXY_URL = "http://localhost:3000/api/tool-proxy";
|
||||
const APP_ID = 1857;
|
||||
const USER_ID = "4981edbc-e162-498f-a681-00190c16a8c7";
|
||||
|
||||
interface ToolCallResult {
|
||||
success: boolean;
|
||||
result?: any;
|
||||
error?: string;
|
||||
executionTime?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call a Kleap AI tool from sandbox code
|
||||
* @param toolName - Name of the tool to execute
|
||||
* @param params - Parameters for the tool
|
||||
* @returns Tool execution result
|
||||
*/
|
||||
export async function callTool(toolName: string, params: any): Promise<any> {
|
||||
try {
|
||||
const response = await fetch(TOOL_PROXY_URL, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
tool: toolName,
|
||||
params,
|
||||
appId: APP_ID,
|
||||
userId: USER_ID,
|
||||
}),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.text();
|
||||
throw new Error(`Tool ${toolName} failed: ${error}`);
|
||||
}
|
||||
|
||||
const data: ToolCallResult = await response.json();
|
||||
|
||||
if (!data.success) {
|
||||
throw new Error(data.error || `Tool ${toolName} failed`);
|
||||
}
|
||||
|
||||
return data.result;
|
||||
} catch (error: any) {
|
||||
console.error(`[TOOL-CLIENT] Error calling ${toolName}:`, error.message);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue