Update workspace/tools/client.ts

This commit is contained in:
kleap-admin 2026-01-15 13:42:29 +00:00
parent 549df5fc9c
commit 24d58bae12
1 changed files with 56 additions and 0 deletions

56
workspace/tools/client.ts Normal file
View File

@ -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 = "https://kleap-dd99oxkse-kleap-dev.vercel.app/api/tool-proxy";
const APP_ID = 1204;
const USER_ID = "424ba091-754d-44d0-87e4-49995e8767e5";
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;
}
}