// Registry of built-in and frontend (browser) tools whose renderer // shows a recognizable icon and friendly label inline in the chat UI. // // To add a new built-in tool, add an entry to BUILTIN_TOOL_UI. To give a // tool a custom title or body renderer, add a dedicated component under // ChatMessageToolCall/ and route it in ChatMessageToolCallBlock.svelte // (see ChatMessageToolCallBlockGetDatetime and // ChatMessageToolCallBlockSearchResults for prior art). import { Braces, Clock, FilePen, FilePlus, FileSearch, FileText, Info, SearchCode, Terminal } from '@lucide/svelte'; import { BuiltInTool, ToolSource } from '$lib/enums'; import type { Component } from 'svelte'; export interface BuiltinToolUiEntry { icon: Component; label: string; source: ToolSource.BUILTIN | ToolSource.FRONTEND; } export const BUILTIN_TOOL_UI: Readonly> = { [BuiltInTool.EDIT_FILE]: { icon: FilePen, label: 'Edit file', source: ToolSource.BUILTIN }, [BuiltInTool.EXEC_SHELL_COMMAND]: { icon: Terminal, label: 'Run command', source: ToolSource.BUILTIN }, [BuiltInTool.FILE_GLOB_SEARCH]: { icon: FileSearch, label: 'Search files', source: ToolSource.BUILTIN }, [BuiltInTool.GET_DATETIME]: { icon: Clock, label: 'Current time', source: ToolSource.BUILTIN }, [BuiltInTool.GET_INFO]: { icon: Info, label: 'Runtime info', source: ToolSource.BUILTIN }, [BuiltInTool.GREP_SEARCH]: { icon: SearchCode, label: 'Search in files', source: ToolSource.BUILTIN }, [BuiltInTool.READ_FILE]: { icon: FileText, label: 'Read file', source: ToolSource.BUILTIN }, [BuiltInTool.RUN_JAVASCRIPT]: { icon: Braces, label: 'Run JavaScript', source: ToolSource.FRONTEND }, [BuiltInTool.WRITE_FILE]: { icon: FilePlus, label: 'Write file', source: ToolSource.BUILTIN } } as const; export function getBuiltinToolUi(toolName: string | undefined): BuiltinToolUiEntry | null { if (!toolName) return null; return (BUILTIN_TOOL_UI as Record)[toolName] ?? null; } import { JsonSchemaType, ToolCallType } from '$lib/enums'; import type { OpenAIToolDefinition } from '$lib/types'; export const DEFAULT_BUILTIN_TOOL_DEFINITIONS: OpenAIToolDefinition[] = [ { function: { description: 'Read file contents from the project directory', name: BuiltInTool.READ_FILE, parameters: { properties: { end_line: { description: '1-indexed ending line (inclusive)', type: 'integer' }, path: { description: 'Path to the file to read', type: 'string' }, start_line: { description: '1-indexed starting line (inclusive)', type: 'integer' } }, required: ['path'], type: 'object' } }, type: ToolCallType.FUNCTION }, { function: { description: 'Write or create a file in the project directory', name: BuiltInTool.WRITE_FILE, parameters: { properties: { content: { description: 'File content to write', type: 'string' }, path: { description: 'Path to the file to write', type: 'string' } }, required: ['path', 'content'], type: 'object' } }, type: ToolCallType.FUNCTION }, { function: { description: 'Surgically edit an existing file by replacing a contiguous text block', name: BuiltInTool.EDIT_FILE, parameters: { properties: { new_str: { description: 'New replacement text', type: 'string' }, old_str: { description: 'Exact text to replace', type: 'string' }, path: { description: 'Path to the file to edit', type: 'string' } }, required: ['path', 'old_str', 'new_str'], type: 'object' } }, type: ToolCallType.FUNCTION }, { function: { description: 'Search files and directories matching a glob pattern', name: BuiltInTool.FILE_GLOB_SEARCH, parameters: { properties: { limit: { description: 'Maximum number of results to return', type: 'integer' }, path: { description: 'Directory to search in (default: .)', type: 'string' }, pattern: { description: 'Glob pattern to match against (e.g. **/*.ts)', type: 'string' }, type: { description: 'Entry type to match: file, dir, or all', type: 'string' } }, type: 'object' } }, type: ToolCallType.FUNCTION }, { function: { description: 'Search for text or regular expressions across files in the project', name: BuiltInTool.GREP_SEARCH, parameters: { properties: { case_sensitive: { description: 'Whether search should be case sensitive', type: 'boolean' }, path: { description: 'Directory or file to search in', type: 'string' }, query: { description: 'Text or regex search query', type: 'string' } }, required: ['query'], type: 'object' } }, type: ToolCallType.FUNCTION }, { function: { description: 'Run a shell command on the server and capture its output', name: BuiltInTool.EXEC_SHELL_COMMAND, parameters: { properties: { command: { description: 'Shell command string to execute', type: 'string' }, timeout: { description: 'Timeout in seconds (default: 10)', type: 'integer' } }, required: ['command'], type: 'object' } }, type: ToolCallType.FUNCTION }, { function: { description: 'Get the current date, time, and timezone information', name: BuiltInTool.GET_DATETIME, parameters: { properties: {}, type: 'object' } }, type: ToolCallType.FUNCTION }, { function: { description: 'Get runtime, operating system, and hardware host environment information', name: BuiltInTool.GET_INFO, parameters: { properties: {}, type: 'object' } }, type: ToolCallType.FUNCTION } ];