refactor: Updates after server updates
This commit is contained in:
parent
4419355fe7
commit
f4baf05baa
|
|
@ -19,7 +19,8 @@
|
|||
import { FILE_TYPE_ICONS, TOOLTIP_DELAY_DURATION } from '$lib/constants';
|
||||
import { conversationsStore } from '$lib/stores/conversations.svelte';
|
||||
import { mcpStore } from '$lib/stores/mcp.svelte';
|
||||
import { toolsStore, ToolSource, type ToolGroup } from '$lib/stores/tools.svelte';
|
||||
import { toolsStore, type ToolGroup } from '$lib/stores/tools.svelte';
|
||||
import { ToolSource } from '$lib/enums';
|
||||
|
||||
import { SvelteSet } from 'svelte/reactivity';
|
||||
|
||||
|
|
|
|||
|
|
@ -50,3 +50,5 @@ export { ParameterSource, SyncableParameterType, SettingsFieldType } from './set
|
|||
export { ColorMode, McpPromptVariant, UrlProtocol } from './ui';
|
||||
|
||||
export { KeyboardKey } from './keyboard';
|
||||
|
||||
export { ToolSource, ToolResponseField } from './tools';
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
export enum ToolSource {
|
||||
BUILTIN = 'builtin',
|
||||
MCP = 'mcp',
|
||||
CUSTOM = 'custom'
|
||||
}
|
||||
|
||||
export enum ToolResponseField {
|
||||
PLAIN_TEXT = 'plain_text_response',
|
||||
ERROR = 'error'
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
import { apiFetch } from '$lib/utils';
|
||||
import { API_TOOLS } from '$lib/constants';
|
||||
import type { OpenAIToolDefinition, ToolExecutionResult } from '$lib/types';
|
||||
import { ToolResponseField } from '$lib/enums';
|
||||
import type { ToolExecutionResult, ServerBuiltinToolInfo } from '$lib/types';
|
||||
|
||||
export class ToolsService {
|
||||
/**
|
||||
|
|
@ -8,8 +9,8 @@ export class ToolsService {
|
|||
*
|
||||
* @returns Array of tool definitions in OpenAI-compatible format
|
||||
*/
|
||||
static async list(): Promise<OpenAIToolDefinition[]> {
|
||||
return apiFetch<OpenAIToolDefinition[]>(API_TOOLS.LIST);
|
||||
static async list(): Promise<ServerBuiltinToolInfo[]> {
|
||||
return apiFetch<ServerBuiltinToolInfo[]>(API_TOOLS.LIST);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -25,8 +26,15 @@ export class ToolsService {
|
|||
body: JSON.stringify({ tool: toolName, params }),
|
||||
signal
|
||||
});
|
||||
const isError = 'error' in result;
|
||||
const content = isError ? String(result.error) : JSON.stringify(result);
|
||||
return { content, isError };
|
||||
|
||||
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 };
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,8 @@ import { ChatService } from '$lib/services';
|
|||
import { config } from '$lib/stores/settings.svelte';
|
||||
import { mcpStore } from '$lib/stores/mcp.svelte';
|
||||
import { modelsStore } from '$lib/stores/models.svelte';
|
||||
import { toolsStore, ToolSource } from '$lib/stores/tools.svelte';
|
||||
import { toolsStore } from '$lib/stores/tools.svelte';
|
||||
import { ToolSource } from '$lib/enums';
|
||||
import { ToolsService } from '$lib/services/tools.service';
|
||||
import { isAbortError } from '$lib/utils';
|
||||
import {
|
||||
|
|
|
|||
|
|
@ -1,17 +1,11 @@
|
|||
import type { OpenAIToolDefinition } from '$lib/types';
|
||||
import { ToolsService } from '$lib/services/tools.service';
|
||||
import { mcpStore } from '$lib/stores/mcp.svelte';
|
||||
import { HealthCheckStatus } from '$lib/enums';
|
||||
import { HealthCheckStatus, ToolSource } from '$lib/enums';
|
||||
import { config } from '$lib/stores/settings.svelte';
|
||||
import { DISABLED_TOOLS_LOCALSTORAGE_KEY } from '$lib/constants';
|
||||
import { SvelteSet } from 'svelte/reactivity';
|
||||
|
||||
export enum ToolSource {
|
||||
BUILTIN = 'builtin',
|
||||
MCP = 'mcp',
|
||||
CUSTOM = 'custom'
|
||||
}
|
||||
|
||||
export interface ToolEntry {
|
||||
source: ToolSource;
|
||||
/** For MCP tools, the server ID; otherwise undefined */
|
||||
|
|
@ -351,7 +345,8 @@ class ToolsStore {
|
|||
this._error = null;
|
||||
|
||||
try {
|
||||
this._builtinTools = await ToolsService.list();
|
||||
const toolInfos = await ToolsService.list();
|
||||
this._builtinTools = toolInfos.map((info) => info.definition);
|
||||
} catch (err) {
|
||||
this._error = err instanceof Error ? err.message : String(err);
|
||||
console.error('[ToolsStore] Failed to fetch built-in tools:', err);
|
||||
|
|
|
|||
|
|
@ -116,6 +116,7 @@ export type {
|
|||
ServerStatus,
|
||||
ToolCallParams,
|
||||
ToolExecutionResult,
|
||||
ServerBuiltinToolInfo,
|
||||
Tool,
|
||||
Prompt,
|
||||
GetPromptResult,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import type { MCPConnectionPhase, MCPLogLevel, HealthCheckStatus } from '$lib/enums/mcp';
|
||||
import type { ToolSource } from '$lib/enums/tools';
|
||||
import type {
|
||||
Client,
|
||||
ClientCapabilities as SDKClientCapabilities,
|
||||
|
|
@ -256,6 +257,16 @@ export interface ToolExecutionResult {
|
|||
isError: boolean;
|
||||
}
|
||||
|
||||
export interface ServerBuiltinToolInfo {
|
||||
display_name: string;
|
||||
tool: string;
|
||||
type: ToolSource.BUILTIN;
|
||||
permissions: {
|
||||
write: boolean;
|
||||
};
|
||||
definition: OpenAIToolDefinition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Progress tracking state for a specific operation
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue