mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-06 05:09:09 +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 工具的类型定义
|
// Read 工具的类型定义
|
||||||
export interface ReadToolInput {
|
export interface ReadToolInput {
|
||||||
|
/**
|
||||||
|
* The absolute path to the file to read
|
||||||
|
*/
|
||||||
file_path: string
|
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[]
|
export type ReadToolOutput = string | TextOutput[]
|
||||||
|
|
||||||
// Task 工具的类型定义
|
// Task 工具的类型定义
|
||||||
export type TaskToolInput = {
|
export type TaskToolInput = {
|
||||||
|
/**
|
||||||
|
* A short (3-5 word) description of the task
|
||||||
|
*/
|
||||||
description: string
|
description: string
|
||||||
|
/**
|
||||||
|
* The task for the agent to perform
|
||||||
|
*/
|
||||||
prompt: string
|
prompt: string
|
||||||
|
/**
|
||||||
|
* The type of specialized agent to use for this task
|
||||||
|
*/
|
||||||
subagent_type: string
|
subagent_type: string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,8 +59,22 @@ export type TaskToolOutput = TextOutput[]
|
|||||||
|
|
||||||
// Bash 工具的类型定义
|
// Bash 工具的类型定义
|
||||||
export type BashToolInput = {
|
export type BashToolInput = {
|
||||||
|
/**
|
||||||
|
* The command to execute
|
||||||
|
*/
|
||||||
command: string
|
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
|
export type BashToolOutput = string
|
||||||
@ -52,16 +86,32 @@ export type SearchToolOutput = string
|
|||||||
|
|
||||||
// Glob 工具的类型定义
|
// Glob 工具的类型定义
|
||||||
export interface GlobToolInput {
|
export interface GlobToolInput {
|
||||||
|
/**
|
||||||
|
* The glob pattern to match files against
|
||||||
|
*/
|
||||||
pattern: string
|
pattern: string
|
||||||
|
/**
|
||||||
|
* The directory to search in (defaults to cwd)
|
||||||
|
*/
|
||||||
|
path?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type GlobToolOutput = string
|
export type GlobToolOutput = string
|
||||||
|
|
||||||
// TodoWrite 工具的类型定义
|
// TodoWrite 工具的类型定义
|
||||||
export interface TodoItem {
|
export interface TodoItem {
|
||||||
|
/**
|
||||||
|
* The task description
|
||||||
|
*/
|
||||||
content: string
|
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 = {
|
export type TodoWriteToolInput = {
|
||||||
@ -72,88 +122,240 @@ export type TodoWriteToolOutput = string
|
|||||||
|
|
||||||
// WebSearch 工具的类型定义
|
// WebSearch 工具的类型定义
|
||||||
export interface WebSearchToolInput {
|
export interface WebSearchToolInput {
|
||||||
|
/**
|
||||||
|
* The search query to use
|
||||||
|
*/
|
||||||
query: string
|
query: string
|
||||||
|
/**
|
||||||
|
* Only include results from these domains
|
||||||
|
*/
|
||||||
|
allowed_domains?: string[]
|
||||||
|
/**
|
||||||
|
* Never include results from these domains
|
||||||
|
*/
|
||||||
|
blocked_domains?: string[]
|
||||||
}
|
}
|
||||||
export type WebSearchToolOutput = string
|
export type WebSearchToolOutput = string
|
||||||
|
|
||||||
// WebFetch 工具的类型定义
|
// WebFetch 工具的类型定义
|
||||||
export type WebFetchToolInput = {
|
export type WebFetchToolInput = {
|
||||||
prompt: string
|
/**
|
||||||
|
* The URL to fetch content from
|
||||||
|
*/
|
||||||
url: string
|
url: string
|
||||||
|
/**
|
||||||
|
* The prompt to run on the fetched content
|
||||||
|
*/
|
||||||
|
prompt: string
|
||||||
}
|
}
|
||||||
export type WebFetchToolOutput = string
|
export type WebFetchToolOutput = string
|
||||||
|
|
||||||
// Grep 工具的类型定义
|
// Grep 工具的类型定义
|
||||||
export interface GrepToolInput {
|
export interface GrepToolInput {
|
||||||
|
/**
|
||||||
|
* The regular expression pattern to search for
|
||||||
|
*/
|
||||||
pattern: string
|
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
|
export type GrepToolOutput = string
|
||||||
|
|
||||||
// Write 工具的类型定义
|
// Write 工具的类型定义
|
||||||
export type WriteToolInput = {
|
export type WriteToolInput = {
|
||||||
content: string
|
/**
|
||||||
|
* The absolute path to the file to write
|
||||||
|
*/
|
||||||
file_path: string
|
file_path: string
|
||||||
|
/**
|
||||||
|
* The content to write to the file
|
||||||
|
*/
|
||||||
|
content: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type WriteToolOutput = string
|
export type WriteToolOutput = string
|
||||||
|
|
||||||
// Edit 工具的类型定义
|
// Edit 工具的类型定义
|
||||||
export type EditToolInput = {
|
export type EditToolInput = {
|
||||||
|
/**
|
||||||
|
* The absolute path to the file to modify
|
||||||
|
*/
|
||||||
file_path: string
|
file_path: string
|
||||||
|
/**
|
||||||
|
* The text to replace
|
||||||
|
*/
|
||||||
old_string: string
|
old_string: string
|
||||||
|
/**
|
||||||
|
* The text to replace it with (must be different from old_string)
|
||||||
|
*/
|
||||||
new_string: string
|
new_string: string
|
||||||
|
/**
|
||||||
|
* Replace all occurrences of old_string (default false)
|
||||||
|
*/
|
||||||
|
replace_all?: boolean
|
||||||
}
|
}
|
||||||
export type EditToolOutput = string
|
export type EditToolOutput = string
|
||||||
|
|
||||||
// MultiEdit 工具的类型定义
|
// MultiEdit 工具的类型定义
|
||||||
export type MultiEditToolInput = {
|
export type MultiEditToolInput = {
|
||||||
|
/**
|
||||||
|
* The absolute path to the file to modify
|
||||||
|
*/
|
||||||
file_path: string
|
file_path: string
|
||||||
edits: {
|
/**
|
||||||
|
* Array of edit operations to perform sequentially
|
||||||
|
*/
|
||||||
|
edits: Array<{
|
||||||
|
/**
|
||||||
|
* The text to replace
|
||||||
|
*/
|
||||||
old_string: string
|
old_string: string
|
||||||
|
/**
|
||||||
|
* The text to replace it with
|
||||||
|
*/
|
||||||
new_string: string
|
new_string: string
|
||||||
}[]
|
/**
|
||||||
|
* Replace all occurrences (default false)
|
||||||
|
*/
|
||||||
|
replace_all?: boolean
|
||||||
|
}>
|
||||||
}
|
}
|
||||||
export type MultiEditToolOutput = string
|
export type MultiEditToolOutput = string
|
||||||
|
|
||||||
// BashOutput 工具的类型定义
|
// BashOutput 工具的类型定义
|
||||||
export type BashOutputToolInput = {
|
export type BashOutputToolInput = {
|
||||||
|
/**
|
||||||
|
* The ID of the background shell to retrieve output from
|
||||||
|
*/
|
||||||
bash_id: string
|
bash_id: string
|
||||||
|
/**
|
||||||
|
* Optional regex to filter output lines
|
||||||
|
*/
|
||||||
|
filter?: string
|
||||||
}
|
}
|
||||||
export type BashOutputToolOutput = string
|
export type BashOutputToolOutput = string
|
||||||
|
|
||||||
// NotebookEdit 工具的类型定义
|
// NotebookEdit 工具的类型定义
|
||||||
export type NotebookEditToolInput = {
|
export type NotebookEditToolInput = {
|
||||||
|
/**
|
||||||
|
* The absolute path to the Jupyter notebook file
|
||||||
|
*/
|
||||||
notebook_path: string
|
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
|
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
|
export type NotebookEditToolOutput = string
|
||||||
|
|
||||||
|
// ExitPlanModeToolInput
|
||||||
export type ExitPlanModeToolInput = {
|
export type ExitPlanModeToolInput = {
|
||||||
|
/**
|
||||||
|
* The plan to run by the user for approval
|
||||||
|
*/
|
||||||
plan: string
|
plan: string
|
||||||
}
|
}
|
||||||
export type ExitPlanModeToolOutput = 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 =
|
export type ToolInput =
|
||||||
| ReadToolInput
|
|
||||||
| TaskToolInput
|
| TaskToolInput
|
||||||
| BashToolInput
|
| BashToolInput
|
||||||
| SearchToolInput
|
| BashOutputToolInput
|
||||||
| GlobToolInput
|
|
||||||
| TodoWriteToolInput
|
|
||||||
| WebSearchToolInput
|
|
||||||
| WebFetchToolInput
|
|
||||||
| GrepToolInput
|
|
||||||
| WriteToolInput
|
|
||||||
| EditToolInput
|
| EditToolInput
|
||||||
| MultiEditToolInput
|
| MultiEditToolInput
|
||||||
| BashOutputToolInput
|
| ReadToolInput
|
||||||
|
| WriteToolInput
|
||||||
|
| GlobToolInput
|
||||||
|
| GrepToolInput
|
||||||
|
| KillBashToolInput
|
||||||
| NotebookEditToolInput
|
| NotebookEditToolInput
|
||||||
|
| WebFetchToolInput
|
||||||
|
| WebSearchToolInput
|
||||||
|
| TodoWriteToolInput
|
||||||
| ExitPlanModeToolInput
|
| ExitPlanModeToolInput
|
||||||
|
| ListMcpResourcesToolInput
|
||||||
|
| ReadMcpResourceToolInput
|
||||||
|
|
||||||
export type ToolOutput =
|
export type ToolOutput =
|
||||||
| ReadToolOutput
|
| ReadToolOutput
|
||||||
| TaskToolOutput
|
| TaskToolOutput
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user