frohzinn's picture
download
raw
1.19 kB
import { apiFetch } from '$lib/utils';
import { API_TOOLS } from '$lib/constants';
import { ToolResponseField } from '$lib/enums';
import type { ToolExecutionResult, ServerBuiltinToolInfo } from '$lib/types';
export class ToolsService {
/**
* Fetch the list of built-in tools from the server.
*
* @returns Array of tool definitions in OpenAI-compatible format
*/
static async list(): Promise<ServerBuiltinToolInfo[]> {
return apiFetch<ServerBuiltinToolInfo[]>(API_TOOLS.LIST);
}
/**
* Execute a built-in tool on the server.
*/
static async executeTool(
toolName: string,
params: Record<string, unknown>,
signal?: AbortSignal
): Promise<ToolExecutionResult> {
const result = await apiFetch<Record<string, unknown>>(API_TOOLS.EXECUTE, {
method: 'POST',
body: JSON.stringify({ tool: toolName, params }),
signal
});
if (ToolResponseField.ERROR in result) {
return { content: String(result[ToolResponseField.ERROR]), isError: true };
}
if (ToolResponseField.PLAIN_TEXT in result) {
return { content: String(result[ToolResponseField.PLAIN_TEXT]), isError: false };
}
return { content: JSON.stringify(result), isError: false };
}
}

Xet Storage Details

Size:
1.19 kB
·
Xet hash:
1c64979a2a7d18cd5980d8b423d51229e7ef22f9aaaef64ee9768c7afacd0ed5

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.