mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-31 08:29:07 +08:00
feat(tools): enhance type definitions for agent tools
- Added detailed JSDoc comments for clarity on tool input types, including ReadToolInput, TaskToolInput, BashToolInput, and others. - Introduced new input types such as ListMcpResourcesToolInput and ReadMcpResourceToolInput to expand functionality. - Improved existing types to ensure better documentation and usability for developers.
This commit is contained in:
parent
a0193451a9
commit
a3c638946e
@ -23,15 +23,35 @@ export type TextOutput = {
|
||||
|
||||
// Read 工具的类型定义
|
||||
export interface ReadToolInput {
|
||||
/**
|
||||
* The absolute path to the file to read
|
||||
*/
|
||||
file_path: string
|
||||
/**
|
||||
* The line number to start reading from
|
||||
*/
|
||||
offset?: number
|
||||
/**
|
||||
* The number of lines to read
|
||||
*/
|
||||
limit?: number
|
||||
}
|
||||
|
||||
export type ReadToolOutput = string | TextOutput[]
|
||||
|
||||
// Task 工具的类型定义
|
||||
export type TaskToolInput = {
|
||||
/**
|
||||
* A short (3-5 word) description of the task
|
||||
*/
|
||||
description: string
|
||||
/**
|
||||
* The task for the agent to perform
|
||||
*/
|
||||
prompt: string
|
||||
/**
|
||||
* The type of specialized agent to use for this task
|
||||
*/
|
||||
subagent_type: string
|
||||
}
|
||||
|
||||
@ -39,8 +59,22 @@ export type TaskToolOutput = TextOutput[]
|
||||
|
||||
// Bash 工具的类型定义
|
||||
export type BashToolInput = {
|
||||
/**
|
||||
* The command to execute
|
||||
*/
|
||||
command: string
|
||||
description: string
|
||||
/**
|
||||
* Optional timeout in milliseconds (max 600000)
|
||||
*/
|
||||
timeout?: number
|
||||
/**
|
||||
* Clear, concise description of what this command does in 5-10 words
|
||||
*/
|
||||
description?: string
|
||||
/**
|
||||
* Set to true to run this command in the background
|
||||
*/
|
||||
run_in_background?: boolean
|
||||
}
|
||||
|
||||
export type BashToolOutput = string
|
||||
@ -52,16 +86,32 @@ export type SearchToolOutput = string
|
||||
|
||||
// Glob 工具的类型定义
|
||||
export interface GlobToolInput {
|
||||
/**
|
||||
* The glob pattern to match files against
|
||||
*/
|
||||
pattern: string
|
||||
/**
|
||||
* The directory to search in (defaults to cwd)
|
||||
*/
|
||||
path?: string
|
||||
}
|
||||
|
||||
export type GlobToolOutput = string
|
||||
|
||||
// TodoWrite 工具的类型定义
|
||||
export interface TodoItem {
|
||||
/**
|
||||
* The task description
|
||||
*/
|
||||
content: string
|
||||
status: 'completed' | 'in_progress' | 'pending'
|
||||
activeForm?: string
|
||||
/**
|
||||
* The task status
|
||||
*/
|
||||
status: 'pending' | 'in_progress' | 'completed'
|
||||
/**
|
||||
* Active form of the task description
|
||||
*/
|
||||
activeForm: string
|
||||
}
|
||||
|
||||
export type TodoWriteToolInput = {
|
||||
@ -72,88 +122,240 @@ export type TodoWriteToolOutput = string
|
||||
|
||||
// WebSearch 工具的类型定义
|
||||
export interface WebSearchToolInput {
|
||||
/**
|
||||
* The search query to use
|
||||
*/
|
||||
query: string
|
||||
/**
|
||||
* Only include results from these domains
|
||||
*/
|
||||
allowed_domains?: string[]
|
||||
/**
|
||||
* Never include results from these domains
|
||||
*/
|
||||
blocked_domains?: string[]
|
||||
}
|
||||
export type WebSearchToolOutput = string
|
||||
|
||||
// WebFetch 工具的类型定义
|
||||
export type WebFetchToolInput = {
|
||||
prompt: string
|
||||
/**
|
||||
* The URL to fetch content from
|
||||
*/
|
||||
url: string
|
||||
/**
|
||||
* The prompt to run on the fetched content
|
||||
*/
|
||||
prompt: string
|
||||
}
|
||||
export type WebFetchToolOutput = string
|
||||
|
||||
// Grep 工具的类型定义
|
||||
export interface GrepToolInput {
|
||||
/**
|
||||
* The regular expression pattern to search for
|
||||
*/
|
||||
pattern: string
|
||||
output_mode: string
|
||||
/**
|
||||
* File or directory to search in (defaults to cwd)
|
||||
*/
|
||||
path?: string
|
||||
/**
|
||||
* Glob pattern to filter files (e.g. "*.js")
|
||||
*/
|
||||
glob?: string
|
||||
/**
|
||||
* File type to search (e.g. "js", "py", "rust")
|
||||
*/
|
||||
type?: string
|
||||
/**
|
||||
* Output mode: "content", "files_with_matches", or "count"
|
||||
*/
|
||||
output_mode?: 'content' | 'files_with_matches' | 'count'
|
||||
/**
|
||||
* Case insensitive search
|
||||
*/
|
||||
'-i'?: boolean
|
||||
/**
|
||||
* Show line numbers (for content mode)
|
||||
*/
|
||||
'-n'?: boolean
|
||||
/**
|
||||
* Lines to show before each match
|
||||
*/
|
||||
'-B'?: number
|
||||
/**
|
||||
* Lines to show after each match
|
||||
*/
|
||||
'-A'?: number
|
||||
/**
|
||||
* Lines to show before and after each match
|
||||
*/
|
||||
'-C'?: number
|
||||
/**
|
||||
* Limit output to first N lines/entries
|
||||
*/
|
||||
head_limit?: number
|
||||
/**
|
||||
* Enable multiline mode
|
||||
*/
|
||||
multiline?: boolean
|
||||
}
|
||||
|
||||
export type GrepToolOutput = string
|
||||
|
||||
// Write 工具的类型定义
|
||||
export type WriteToolInput = {
|
||||
content: string
|
||||
/**
|
||||
* The absolute path to the file to write
|
||||
*/
|
||||
file_path: string
|
||||
/**
|
||||
* The content to write to the file
|
||||
*/
|
||||
content: string
|
||||
}
|
||||
|
||||
export type WriteToolOutput = string
|
||||
|
||||
// Edit 工具的类型定义
|
||||
export type EditToolInput = {
|
||||
/**
|
||||
* The absolute path to the file to modify
|
||||
*/
|
||||
file_path: string
|
||||
/**
|
||||
* The text to replace
|
||||
*/
|
||||
old_string: string
|
||||
/**
|
||||
* The text to replace it with (must be different from old_string)
|
||||
*/
|
||||
new_string: string
|
||||
/**
|
||||
* Replace all occurrences of old_string (default false)
|
||||
*/
|
||||
replace_all?: boolean
|
||||
}
|
||||
export type EditToolOutput = string
|
||||
|
||||
// MultiEdit 工具的类型定义
|
||||
export type MultiEditToolInput = {
|
||||
/**
|
||||
* The absolute path to the file to modify
|
||||
*/
|
||||
file_path: string
|
||||
edits: {
|
||||
/**
|
||||
* Array of edit operations to perform sequentially
|
||||
*/
|
||||
edits: Array<{
|
||||
/**
|
||||
* The text to replace
|
||||
*/
|
||||
old_string: string
|
||||
/**
|
||||
* The text to replace it with
|
||||
*/
|
||||
new_string: string
|
||||
}[]
|
||||
/**
|
||||
* Replace all occurrences (default false)
|
||||
*/
|
||||
replace_all?: boolean
|
||||
}>
|
||||
}
|
||||
export type MultiEditToolOutput = string
|
||||
|
||||
// BashOutput 工具的类型定义
|
||||
export type BashOutputToolInput = {
|
||||
/**
|
||||
* The ID of the background shell to retrieve output from
|
||||
*/
|
||||
bash_id: string
|
||||
/**
|
||||
* Optional regex to filter output lines
|
||||
*/
|
||||
filter?: string
|
||||
}
|
||||
export type BashOutputToolOutput = string
|
||||
|
||||
// NotebookEdit 工具的类型定义
|
||||
export type NotebookEditToolInput = {
|
||||
/**
|
||||
* The absolute path to the Jupyter notebook file
|
||||
*/
|
||||
notebook_path: string
|
||||
edit_mode: string
|
||||
cell_type: string
|
||||
/**
|
||||
* The ID of the cell to edit
|
||||
*/
|
||||
cell_id?: string
|
||||
/**
|
||||
* The new source for the cell
|
||||
*/
|
||||
new_source: string
|
||||
/**
|
||||
* The type of the cell (code or markdown)
|
||||
*/
|
||||
cell_type?: 'code' | 'markdown'
|
||||
/**
|
||||
* The type of edit (replace, insert, delete)
|
||||
*/
|
||||
edit_mode?: 'replace' | 'insert' | 'delete'
|
||||
}
|
||||
export type NotebookEditToolOutput = string
|
||||
|
||||
// ExitPlanModeToolInput
|
||||
export type ExitPlanModeToolInput = {
|
||||
/**
|
||||
* The plan to run by the user for approval
|
||||
*/
|
||||
plan: string
|
||||
}
|
||||
export type ExitPlanModeToolOutput = string
|
||||
|
||||
// ListMcpResourcesToolInput
|
||||
export type ListMcpResourcesToolInput = {
|
||||
/**
|
||||
* Optional server name to filter resources by
|
||||
*/
|
||||
server?: string
|
||||
}
|
||||
// ReadMcpResourceToolInput
|
||||
export type ReadMcpResourceToolInput = {
|
||||
/**
|
||||
* The MCP server name
|
||||
*/
|
||||
server: string
|
||||
/**
|
||||
* The resource URI to read
|
||||
*/
|
||||
uri: string
|
||||
}
|
||||
export type KillBashToolInput = {
|
||||
/**
|
||||
* The ID of the background shell to kill
|
||||
*/
|
||||
shell_id: string
|
||||
}
|
||||
// 联合类型
|
||||
export type ToolInput =
|
||||
| ReadToolInput
|
||||
| TaskToolInput
|
||||
| BashToolInput
|
||||
| SearchToolInput
|
||||
| GlobToolInput
|
||||
| TodoWriteToolInput
|
||||
| WebSearchToolInput
|
||||
| WebFetchToolInput
|
||||
| GrepToolInput
|
||||
| WriteToolInput
|
||||
| BashOutputToolInput
|
||||
| EditToolInput
|
||||
| MultiEditToolInput
|
||||
| BashOutputToolInput
|
||||
| ReadToolInput
|
||||
| WriteToolInput
|
||||
| GlobToolInput
|
||||
| GrepToolInput
|
||||
| KillBashToolInput
|
||||
| NotebookEditToolInput
|
||||
| WebFetchToolInput
|
||||
| WebSearchToolInput
|
||||
| TodoWriteToolInput
|
||||
| ExitPlanModeToolInput
|
||||
| ListMcpResourcesToolInput
|
||||
| ReadMcpResourceToolInput
|
||||
|
||||
export type ToolOutput =
|
||||
| ReadToolOutput
|
||||
| TaskToolOutput
|
||||
|
||||
Loading…
Reference in New Issue
Block a user