2026-08-14 15:48:49 +08:00

88 lines
2.4 KiB
TypeScript

import type { ModelTool } from "../ports/model-port";
export const workspaceTools: readonly ModelTool[] = [
{
name: "list_directory",
description:
"列出当前会话工作区内某个目录的直接子项。路径必须是工作区相对路径。",
parameters: {
type: "object",
properties: {
path: {
type: "string",
description: "目录相对路径,根目录使用空字符串",
},
},
required: ["path"],
additionalProperties: false,
},
},
{
name: "search_files",
description: "按文件名和 UTF-8 文本内容搜索当前会话工作区。",
parameters: {
type: "object",
properties: { query: { type: "string" } },
required: ["query"],
additionalProperties: false,
},
},
{
name: "read_text_file",
description: "读取当前会话工作区内不超过 2 MiB 的 UTF-8 文本文件。",
parameters: {
type: "object",
properties: { path: { type: "string" } },
required: ["path"],
additionalProperties: false,
},
},
{
name: "create_text_file",
description:
"在当前会话工作区内创建新的 UTF-8 文本文件;文件已存在时失败。",
parameters: {
type: "object",
properties: {
path: { type: "string" },
content: { type: "string" },
},
required: ["path", "content"],
additionalProperties: false,
},
},
{
name: "apply_text_patch",
description:
"使用读取文件时得到的 SHA-256 哈希,对文本执行精确替换。默认每项旧文本必须只出现一次。",
parameters: {
type: "object",
properties: {
path: { type: "string" },
expectedHash: { type: "string" },
replacements: {
type: "array",
minItems: 1,
maxItems: 50,
items: {
type: "object",
properties: {
oldText: { type: "string" },
newText: { type: "string" },
replaceAll: { type: "boolean" },
},
required: ["oldText", "newText"],
additionalProperties: false,
},
},
},
required: ["path", "expectedHash", "replacements"],
additionalProperties: false,
},
},
];
export function isWorkspaceTool(name: string): boolean {
return workspaceTools.some((tool) => tool.name === name);
}