tianxincode 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +57 -0
- package/dist/api/api.types.d.ts +350 -0
- package/dist/api/api.types.d.ts.map +1 -0
- package/dist/api/api.types.js +12 -0
- package/dist/api/api.types.js.map +1 -0
- package/dist/api/chat.routes.d.ts +26 -0
- package/dist/api/chat.routes.d.ts.map +1 -0
- package/dist/api/chat.routes.js +275 -0
- package/dist/api/chat.routes.js.map +1 -0
- package/dist/api/config.routes.d.ts +10 -0
- package/dist/api/config.routes.d.ts.map +1 -0
- package/dist/api/config.routes.js +150 -0
- package/dist/api/config.routes.js.map +1 -0
- package/dist/api/db.routes.d.ts +12 -0
- package/dist/api/db.routes.d.ts.map +1 -0
- package/dist/api/db.routes.js +108 -0
- package/dist/api/db.routes.js.map +1 -0
- package/dist/api/files.routes.d.ts +14 -0
- package/dist/api/files.routes.d.ts.map +1 -0
- package/dist/api/files.routes.js +220 -0
- package/dist/api/files.routes.js.map +1 -0
- package/dist/api/filesystem.routes.d.ts +10 -0
- package/dist/api/filesystem.routes.d.ts.map +1 -0
- package/dist/api/filesystem.routes.js +181 -0
- package/dist/api/filesystem.routes.js.map +1 -0
- package/dist/api/index.d.ts +6 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +25 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/lsp.d.ts +5 -0
- package/dist/api/lsp.d.ts.map +1 -0
- package/dist/api/lsp.js +103 -0
- package/dist/api/lsp.js.map +1 -0
- package/dist/api/projects.routes.d.ts +18 -0
- package/dist/api/projects.routes.d.ts.map +1 -0
- package/dist/api/projects.routes.js +306 -0
- package/dist/api/projects.routes.js.map +1 -0
- package/dist/api/session.routes.d.ts +18 -0
- package/dist/api/session.routes.d.ts.map +1 -0
- package/dist/api/session.routes.js +186 -0
- package/dist/api/session.routes.js.map +1 -0
- package/dist/api/skills.routes.d.ts +6 -0
- package/dist/api/skills.routes.d.ts.map +1 -0
- package/dist/api/skills.routes.js +54 -0
- package/dist/api/skills.routes.js.map +1 -0
- package/dist/cli/args.d.ts +49 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +77 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/cli.types.d.ts +22 -0
- package/dist/cli/cli.types.d.ts.map +1 -0
- package/dist/cli/cli.types.js +5 -0
- package/dist/cli/cli.types.js.map +1 -0
- package/dist/cli/commands.d.ts +30 -0
- package/dist/cli/commands.d.ts.map +1 -0
- package/dist/cli/commands.js +263 -0
- package/dist/cli/commands.js.map +1 -0
- package/dist/cli/index.d.ts +7 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +6 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/components/App.d.ts +34 -0
- package/dist/components/App.d.ts.map +1 -0
- package/dist/components/App.js +639 -0
- package/dist/components/App.js.map +1 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +2 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/tx.config.d.ts +31 -0
- package/dist/config/tx.config.d.ts.map +1 -0
- package/dist/config/tx.config.js +29 -0
- package/dist/config/tx.config.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +79 -0
- package/dist/index.js.map +1 -0
- package/dist/lsp/client.d.ts +55 -0
- package/dist/lsp/client.d.ts.map +1 -0
- package/dist/lsp/client.js +252 -0
- package/dist/lsp/client.js.map +1 -0
- package/dist/lsp/downloader.d.ts +17 -0
- package/dist/lsp/downloader.d.ts.map +1 -0
- package/dist/lsp/downloader.js +302 -0
- package/dist/lsp/downloader.js.map +1 -0
- package/dist/lsp/index.d.ts +13 -0
- package/dist/lsp/index.d.ts.map +1 -0
- package/dist/lsp/index.js +30 -0
- package/dist/lsp/index.js.map +1 -0
- package/dist/lsp/launch.d.ts +17 -0
- package/dist/lsp/launch.d.ts.map +1 -0
- package/dist/lsp/launch.js +69 -0
- package/dist/lsp/launch.js.map +1 -0
- package/dist/lsp/manager.d.ts +19 -0
- package/dist/lsp/manager.d.ts.map +1 -0
- package/dist/lsp/manager.js +251 -0
- package/dist/lsp/manager.js.map +1 -0
- package/dist/lsp/server.d.ts +11 -0
- package/dist/lsp/server.d.ts.map +1 -0
- package/dist/lsp/server.js +302 -0
- package/dist/lsp/server.js.map +1 -0
- package/dist/lsp/sql.d.ts +11 -0
- package/dist/lsp/sql.d.ts.map +1 -0
- package/dist/lsp/sql.js +23 -0
- package/dist/lsp/sql.js.map +1 -0
- package/dist/lsp/types.d.ts +58 -0
- package/dist/lsp/types.d.ts.map +1 -0
- package/dist/lsp/types.js +13 -0
- package/dist/lsp/types.js.map +1 -0
- package/dist/modules/ai/ai.service.d.ts +182 -0
- package/dist/modules/ai/ai.service.d.ts.map +1 -0
- package/dist/modules/ai/ai.service.js +280 -0
- package/dist/modules/ai/ai.service.js.map +1 -0
- package/dist/modules/ai/ai.types.d.ts +54 -0
- package/dist/modules/ai/ai.types.d.ts.map +1 -0
- package/dist/modules/ai/ai.types.js +2 -0
- package/dist/modules/ai/ai.types.js.map +1 -0
- package/dist/modules/ai/index.d.ts +6 -0
- package/dist/modules/ai/index.d.ts.map +1 -0
- package/dist/modules/ai/index.js +5 -0
- package/dist/modules/ai/index.js.map +1 -0
- package/dist/modules/ai/openai.provider.d.ts +138 -0
- package/dist/modules/ai/openai.provider.d.ts.map +1 -0
- package/dist/modules/ai/openai.provider.js +279 -0
- package/dist/modules/ai/openai.provider.js.map +1 -0
- package/dist/modules/ai/react/index.d.ts +5 -0
- package/dist/modules/ai/react/index.d.ts.map +1 -0
- package/dist/modules/ai/react/index.js +4 -0
- package/dist/modules/ai/react/index.js.map +1 -0
- package/dist/modules/ai/react/prompt/role.txt +51 -0
- package/dist/modules/ai/react/react.parser.d.ts +75 -0
- package/dist/modules/ai/react/react.parser.d.ts.map +1 -0
- package/dist/modules/ai/react/react.parser.js +278 -0
- package/dist/modules/ai/react/react.parser.js.map +1 -0
- package/dist/modules/ai/react/react.prompts.d.ts +26 -0
- package/dist/modules/ai/react/react.prompts.d.ts.map +1 -0
- package/dist/modules/ai/react/react.prompts.js +180 -0
- package/dist/modules/ai/react/react.prompts.js.map +1 -0
- package/dist/modules/ai/react/react.types.d.ts +47 -0
- package/dist/modules/ai/react/react.types.d.ts.map +1 -0
- package/dist/modules/ai/react/react.types.js +2 -0
- package/dist/modules/ai/react/react.types.js.map +1 -0
- package/dist/modules/ai/react.agent.d.ts +40 -0
- package/dist/modules/ai/react.agent.d.ts.map +1 -0
- package/dist/modules/ai/react.agent.js +136 -0
- package/dist/modules/ai/react.agent.js.map +1 -0
- package/dist/modules/ai/summarizer/index.d.ts +4 -0
- package/dist/modules/ai/summarizer/index.d.ts.map +1 -0
- package/dist/modules/ai/summarizer/index.js +3 -0
- package/dist/modules/ai/summarizer/index.js.map +1 -0
- package/dist/modules/ai/summarizer/summarizer.prompts.d.ts +15 -0
- package/dist/modules/ai/summarizer/summarizer.prompts.d.ts.map +1 -0
- package/dist/modules/ai/summarizer/summarizer.prompts.js +47 -0
- package/dist/modules/ai/summarizer/summarizer.prompts.js.map +1 -0
- package/dist/modules/ai/summarizer/summarizer.service.d.ts +24 -0
- package/dist/modules/ai/summarizer/summarizer.service.d.ts.map +1 -0
- package/dist/modules/ai/summarizer/summarizer.service.js +153 -0
- package/dist/modules/ai/summarizer/summarizer.service.js.map +1 -0
- package/dist/modules/ai/summarizer/summarizer.types.d.ts +21 -0
- package/dist/modules/ai/summarizer/summarizer.types.d.ts.map +1 -0
- package/dist/modules/ai/summarizer/summarizer.types.js +5 -0
- package/dist/modules/ai/summarizer/summarizer.types.js.map +1 -0
- package/dist/modules/config/config.service.d.ts +32 -0
- package/dist/modules/config/config.service.d.ts.map +1 -0
- package/dist/modules/config/config.service.js +163 -0
- package/dist/modules/config/config.service.js.map +1 -0
- package/dist/modules/config/config.types.d.ts +44 -0
- package/dist/modules/config/config.types.d.ts.map +1 -0
- package/dist/modules/config/config.types.js +21 -0
- package/dist/modules/config/config.types.js.map +1 -0
- package/dist/modules/config/index.d.ts +10 -0
- package/dist/modules/config/index.d.ts.map +1 -0
- package/dist/modules/config/index.js +10 -0
- package/dist/modules/config/index.js.map +1 -0
- package/dist/modules/context/context.service.d.ts +46 -0
- package/dist/modules/context/context.service.d.ts.map +1 -0
- package/dist/modules/context/context.service.js +216 -0
- package/dist/modules/context/context.service.js.map +1 -0
- package/dist/modules/context/context.types.d.ts +30 -0
- package/dist/modules/context/context.types.d.ts.map +1 -0
- package/dist/modules/context/context.types.js +5 -0
- package/dist/modules/context/context.types.js.map +1 -0
- package/dist/modules/context/index.d.ts +10 -0
- package/dist/modules/context/index.d.ts.map +1 -0
- package/dist/modules/context/index.js +10 -0
- package/dist/modules/context/index.js.map +1 -0
- package/dist/modules/db/db.service.d.ts +97 -0
- package/dist/modules/db/db.service.d.ts.map +1 -0
- package/dist/modules/db/db.service.js +387 -0
- package/dist/modules/db/db.service.js.map +1 -0
- package/dist/modules/db/db.types.d.ts +8 -0
- package/dist/modules/db/db.types.d.ts.map +1 -0
- package/dist/modules/db/db.types.js +7 -0
- package/dist/modules/db/db.types.js.map +1 -0
- package/dist/modules/db/index.d.ts +10 -0
- package/dist/modules/db/index.d.ts.map +1 -0
- package/dist/modules/db/index.js +9 -0
- package/dist/modules/db/index.js.map +1 -0
- package/dist/modules/logger/index.d.ts +2 -0
- package/dist/modules/logger/index.d.ts.map +1 -0
- package/dist/modules/logger/index.js +2 -0
- package/dist/modules/logger/index.js.map +1 -0
- package/dist/modules/logger/logger.d.ts +26 -0
- package/dist/modules/logger/logger.d.ts.map +1 -0
- package/dist/modules/logger/logger.js +57 -0
- package/dist/modules/logger/logger.js.map +1 -0
- package/dist/modules/memory/index.d.ts +9 -0
- package/dist/modules/memory/index.d.ts.map +1 -0
- package/dist/modules/memory/index.js +9 -0
- package/dist/modules/memory/index.js.map +1 -0
- package/dist/modules/memory/memory.service.d.ts +191 -0
- package/dist/modules/memory/memory.service.d.ts.map +1 -0
- package/dist/modules/memory/memory.service.js +282 -0
- package/dist/modules/memory/memory.service.js.map +1 -0
- package/dist/modules/memory/memory.types.d.ts +13 -0
- package/dist/modules/memory/memory.types.d.ts.map +1 -0
- package/dist/modules/memory/memory.types.js +5 -0
- package/dist/modules/memory/memory.types.js.map +1 -0
- package/dist/modules/session/index.d.ts +9 -0
- package/dist/modules/session/index.d.ts.map +1 -0
- package/dist/modules/session/index.js +9 -0
- package/dist/modules/session/index.js.map +1 -0
- package/dist/modules/session/session.service.d.ts +252 -0
- package/dist/modules/session/session.service.d.ts.map +1 -0
- package/dist/modules/session/session.service.js +406 -0
- package/dist/modules/session/session.service.js.map +1 -0
- package/dist/modules/session/session.types.d.ts +34 -0
- package/dist/modules/session/session.types.d.ts.map +1 -0
- package/dist/modules/session/session.types.js +5 -0
- package/dist/modules/session/session.types.js.map +1 -0
- package/dist/modules/skill/index.d.ts +8 -0
- package/dist/modules/skill/index.d.ts.map +1 -0
- package/dist/modules/skill/index.js +7 -0
- package/dist/modules/skill/index.js.map +1 -0
- package/dist/modules/skill/skill.service.d.ts +72 -0
- package/dist/modules/skill/skill.service.d.ts.map +1 -0
- package/dist/modules/skill/skill.service.js +283 -0
- package/dist/modules/skill/skill.service.js.map +1 -0
- package/dist/modules/skill/skill.tool.d.ts +19 -0
- package/dist/modules/skill/skill.tool.d.ts.map +1 -0
- package/dist/modules/skill/skill.tool.js +92 -0
- package/dist/modules/skill/skill.tool.js.map +1 -0
- package/dist/modules/skill/skill.txt +18 -0
- package/dist/modules/skill/skill.types.d.ts +40 -0
- package/dist/modules/skill/skill.types.d.ts.map +1 -0
- package/dist/modules/skill/skill.types.js +6 -0
- package/dist/modules/skill/skill.types.js.map +1 -0
- package/dist/modules/skill/skills.manager.d.ts +30 -0
- package/dist/modules/skill/skills.manager.d.ts.map +1 -0
- package/dist/modules/skill/skills.manager.js +182 -0
- package/dist/modules/skill/skills.manager.js.map +1 -0
- package/dist/modules/tools/builtin/bash.d.ts +3 -0
- package/dist/modules/tools/builtin/bash.d.ts.map +1 -0
- package/dist/modules/tools/builtin/bash.js +124 -0
- package/dist/modules/tools/builtin/bash.js.map +1 -0
- package/dist/modules/tools/builtin/bash.tool.d.ts +6 -0
- package/dist/modules/tools/builtin/bash.tool.d.ts.map +1 -0
- package/dist/modules/tools/builtin/bash.tool.js +52 -0
- package/dist/modules/tools/builtin/bash.tool.js.map +1 -0
- package/dist/modules/tools/builtin/bash.txt +81 -0
- package/dist/modules/tools/builtin/code_search.d.ts +3 -0
- package/dist/modules/tools/builtin/code_search.d.ts.map +1 -0
- package/dist/modules/tools/builtin/code_search.js +85 -0
- package/dist/modules/tools/builtin/code_search.js.map +1 -0
- package/dist/modules/tools/builtin/code_search.txt +18 -0
- package/dist/modules/tools/builtin/edit-file.tool.d.ts +6 -0
- package/dist/modules/tools/builtin/edit-file.tool.d.ts.map +1 -0
- package/dist/modules/tools/builtin/edit-file.tool.js +58 -0
- package/dist/modules/tools/builtin/edit-file.tool.js.map +1 -0
- package/dist/modules/tools/builtin/edit_file.d.ts +3 -0
- package/dist/modules/tools/builtin/edit_file.d.ts.map +1 -0
- package/dist/modules/tools/builtin/edit_file.js +69 -0
- package/dist/modules/tools/builtin/edit_file.js.map +1 -0
- package/dist/modules/tools/builtin/edit_file.txt +10 -0
- package/dist/modules/tools/builtin/glob.d.ts +3 -0
- package/dist/modules/tools/builtin/glob.d.ts.map +1 -0
- package/dist/modules/tools/builtin/glob.js +84 -0
- package/dist/modules/tools/builtin/glob.js.map +1 -0
- package/dist/modules/tools/builtin/glob.tool.d.ts +6 -0
- package/dist/modules/tools/builtin/glob.tool.d.ts.map +1 -0
- package/dist/modules/tools/builtin/glob.tool.js +81 -0
- package/dist/modules/tools/builtin/glob.tool.js.map +1 -0
- package/dist/modules/tools/builtin/glob.txt +10 -0
- package/dist/modules/tools/builtin/grep.d.ts +3 -0
- package/dist/modules/tools/builtin/grep.d.ts.map +1 -0
- package/dist/modules/tools/builtin/grep.js +93 -0
- package/dist/modules/tools/builtin/grep.js.map +1 -0
- package/dist/modules/tools/builtin/grep.tool.d.ts +6 -0
- package/dist/modules/tools/builtin/grep.tool.d.ts.map +1 -0
- package/dist/modules/tools/builtin/grep.tool.js +96 -0
- package/dist/modules/tools/builtin/grep.tool.js.map +1 -0
- package/dist/modules/tools/builtin/grep.txt +12 -0
- package/dist/modules/tools/builtin/index.d.ts +8 -0
- package/dist/modules/tools/builtin/index.d.ts.map +1 -0
- package/dist/modules/tools/builtin/index.js +88 -0
- package/dist/modules/tools/builtin/index.js.map +1 -0
- package/dist/modules/tools/builtin/lsp.d.ts +7 -0
- package/dist/modules/tools/builtin/lsp.d.ts.map +1 -0
- package/dist/modules/tools/builtin/lsp.js +125 -0
- package/dist/modules/tools/builtin/lsp.js.map +1 -0
- package/dist/modules/tools/builtin/lsp.txt +19 -0
- package/dist/modules/tools/builtin/memory.d.ts +3 -0
- package/dist/modules/tools/builtin/memory.d.ts.map +1 -0
- package/dist/modules/tools/builtin/memory.js +76 -0
- package/dist/modules/tools/builtin/memory.js.map +1 -0
- package/dist/modules/tools/builtin/memory.txt +36 -0
- package/dist/modules/tools/builtin/read-file.tool.d.ts +6 -0
- package/dist/modules/tools/builtin/read-file.tool.d.ts.map +1 -0
- package/dist/modules/tools/builtin/read-file.tool.js +46 -0
- package/dist/modules/tools/builtin/read-file.tool.js.map +1 -0
- package/dist/modules/tools/builtin/read_file.d.ts +3 -0
- package/dist/modules/tools/builtin/read_file.d.ts.map +1 -0
- package/dist/modules/tools/builtin/read_file.js +99 -0
- package/dist/modules/tools/builtin/read_file.js.map +1 -0
- package/dist/modules/tools/builtin/read_file.txt +15 -0
- package/dist/modules/tools/builtin/todo_read.d.ts +6 -0
- package/dist/modules/tools/builtin/todo_read.d.ts.map +1 -0
- package/dist/modules/tools/builtin/todo_read.js +24 -0
- package/dist/modules/tools/builtin/todo_read.js.map +1 -0
- package/dist/modules/tools/builtin/todo_read.txt +14 -0
- package/dist/modules/tools/builtin/todo_write.d.ts +6 -0
- package/dist/modules/tools/builtin/todo_write.d.ts.map +1 -0
- package/dist/modules/tools/builtin/todo_write.js +45 -0
- package/dist/modules/tools/builtin/todo_write.js.map +1 -0
- package/dist/modules/tools/builtin/todo_write.txt +46 -0
- package/dist/modules/tools/builtin/web_fetch.d.ts +3 -0
- package/dist/modules/tools/builtin/web_fetch.d.ts.map +1 -0
- package/dist/modules/tools/builtin/web_fetch.js +51 -0
- package/dist/modules/tools/builtin/web_fetch.js.map +1 -0
- package/dist/modules/tools/builtin/web_fetch.txt +15 -0
- package/dist/modules/tools/builtin/web_search.d.ts +3 -0
- package/dist/modules/tools/builtin/web_search.d.ts.map +1 -0
- package/dist/modules/tools/builtin/web_search.js +99 -0
- package/dist/modules/tools/builtin/web_search.js.map +1 -0
- package/dist/modules/tools/builtin/web_search.txt +16 -0
- package/dist/modules/tools/builtin/write-file.tool.d.ts +6 -0
- package/dist/modules/tools/builtin/write-file.tool.d.ts.map +1 -0
- package/dist/modules/tools/builtin/write-file.tool.js +38 -0
- package/dist/modules/tools/builtin/write-file.tool.js.map +1 -0
- package/dist/modules/tools/builtin/write_file.d.ts +3 -0
- package/dist/modules/tools/builtin/write_file.d.ts.map +1 -0
- package/dist/modules/tools/builtin/write_file.js +46 -0
- package/dist/modules/tools/builtin/write_file.js.map +1 -0
- package/dist/modules/tools/builtin/write_file.txt +9 -0
- package/dist/modules/tools/index.d.ts +11 -0
- package/dist/modules/tools/index.d.ts.map +1 -0
- package/dist/modules/tools/index.js +10 -0
- package/dist/modules/tools/index.js.map +1 -0
- package/dist/modules/tools/tool.service.d.ts +207 -0
- package/dist/modules/tools/tool.service.d.ts.map +1 -0
- package/dist/modules/tools/tool.service.js +331 -0
- package/dist/modules/tools/tool.service.js.map +1 -0
- package/dist/modules/tools/tool.types.d.ts +39 -0
- package/dist/modules/tools/tool.types.d.ts.map +1 -0
- package/dist/modules/tools/tool.types.js +5 -0
- package/dist/modules/tools/tool.types.js.map +1 -0
- package/dist/web/index.d.ts +10 -0
- package/dist/web/index.d.ts.map +1 -0
- package/dist/web/index.js +20 -0
- package/dist/web/index.js.map +1 -0
- package/dist/web/web.service.d.ts +95 -0
- package/dist/web/web.service.d.ts.map +1 -0
- package/dist/web/web.service.js +396 -0
- package/dist/web/web.service.js.map +1 -0
- package/package.json +57 -0
- package/web/dist/assets/Layout-Bb76CGAL.js +1 -0
- package/web/dist/assets/element-icons-B-tDfklg.woff +0 -0
- package/web/dist/assets/element-icons-_lZGOqcG.ttf +0 -0
- package/web/dist/assets/index-DQRR0ggU.js +199 -0
- package/web/dist/assets/index-KTH-myBB.css +1 -0
- package/web/dist/index.html +14 -0
- package/web/index.html +13 -0
- package/web/package.json +24 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 工具服务模块
|
|
3
|
+
*
|
|
4
|
+
* 本模块负责工具的注册、管理和执行
|
|
5
|
+
*
|
|
6
|
+
* 核心功能:
|
|
7
|
+
* 1. 工具注册 - 提供 register() 方法添加新工具
|
|
8
|
+
* 2. 工具获取 - 提供 get() 方法根据名称获取工具
|
|
9
|
+
* 3. 工具执行 - 提供 execute() 方法执行工具逻辑
|
|
10
|
+
* 4. 工具列表 - 提供 getAll() 方法获取所有已注册工具
|
|
11
|
+
* 5. 内置工具 - 初始化时自动注册常用工具 (文件读写、命令执行等)
|
|
12
|
+
*
|
|
13
|
+
* 内置工具列表:
|
|
14
|
+
* - read_file: 读取文件内容
|
|
15
|
+
* - write_file: 创建新文件
|
|
16
|
+
* - edit_file: 编辑现有文件
|
|
17
|
+
* - execute_bash: 执行 Shell 命令
|
|
18
|
+
* - find_files / glob: 文件搜索
|
|
19
|
+
* - grep: 内容搜索
|
|
20
|
+
* - loadSkill: 加载技能
|
|
21
|
+
*/
|
|
22
|
+
import { Tool, ToolCall, ToolCallResult } from './tool.types.js';
|
|
23
|
+
/**
|
|
24
|
+
* ToolService 类
|
|
25
|
+
*
|
|
26
|
+
* 工具服务是整个 Agent 系统的核心组件之一
|
|
27
|
+
* 负责管理系统中所有可用的工具,包括内置工具和自定义工具
|
|
28
|
+
*
|
|
29
|
+
* 使用方式:
|
|
30
|
+
* import { toolService } from '../tools/index.js';
|
|
31
|
+
*
|
|
32
|
+
* // 执行工具
|
|
33
|
+
* const result = await toolService.execute('read_file', { file_path: 'src/index.ts' });
|
|
34
|
+
*
|
|
35
|
+
* // 注册自定义工具
|
|
36
|
+
* toolService.register({
|
|
37
|
+
* name: 'my_custom_tool',
|
|
38
|
+
* description: '自定义工具描述',
|
|
39
|
+
* parameters: { ... },
|
|
40
|
+
* execute: async (params) => { ... }
|
|
41
|
+
* });
|
|
42
|
+
*/
|
|
43
|
+
export declare class ToolService {
|
|
44
|
+
/** 工具注册表,使用 Map 存储,key 为工具名称 */
|
|
45
|
+
private tools;
|
|
46
|
+
private initialized;
|
|
47
|
+
private initPromise;
|
|
48
|
+
/**
|
|
49
|
+
* 构造函数
|
|
50
|
+
*
|
|
51
|
+
* 初始化时自动调用 registerBuiltinTools() 注册内置工具
|
|
52
|
+
* 这样应用启动后立即可以使用所有内置工具
|
|
53
|
+
*/
|
|
54
|
+
constructor();
|
|
55
|
+
/**
|
|
56
|
+
* 等待工具服务初始化完成
|
|
57
|
+
*/
|
|
58
|
+
waitForInit(): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* 注册内置工具
|
|
61
|
+
*
|
|
62
|
+
* 从 builtin/index.ts 导入所有内置工具并注册
|
|
63
|
+
* 内置工具包括文件操作、命令执行、搜索等功能
|
|
64
|
+
*
|
|
65
|
+
* 注册流程:
|
|
66
|
+
* 1. 调用 getBuiltinToolsInstance() 获取内置工具
|
|
67
|
+
* 2. 遍历工具数组
|
|
68
|
+
* 3. 将每个工具的名称作为 key,工具对象作为 value 存入 Map
|
|
69
|
+
*/
|
|
70
|
+
private registerBuiltinTools;
|
|
71
|
+
/**
|
|
72
|
+
* 注册工具
|
|
73
|
+
*
|
|
74
|
+
* 用于添加自定义工具到系统中
|
|
75
|
+
* 可以覆盖同名的内置工具 (不推荐)
|
|
76
|
+
*
|
|
77
|
+
* @param tool - 工具对象,包含 name、description、parameters、execute
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* toolService.register({
|
|
81
|
+
* name: 'my_tool',
|
|
82
|
+
* description: '我的自定义工具',
|
|
83
|
+
* parameters: {
|
|
84
|
+
* type: 'object',
|
|
85
|
+
* properties: { input: { type: 'string' } },
|
|
86
|
+
* required: ['input']
|
|
87
|
+
* },
|
|
88
|
+
* execute: async (params) => {
|
|
89
|
+
* return `处理: ${params.input}`;
|
|
90
|
+
* }
|
|
91
|
+
* });
|
|
92
|
+
*/
|
|
93
|
+
register(tool: Tool): void;
|
|
94
|
+
/**
|
|
95
|
+
* 获取工具
|
|
96
|
+
*
|
|
97
|
+
* 根据工具名称获取对应的工具对象
|
|
98
|
+
*
|
|
99
|
+
* @param name - 工具名称
|
|
100
|
+
* @returns {Tool | undefined} 工具对象,如果不存在则返回 undefined
|
|
101
|
+
*/
|
|
102
|
+
get(name: string): Promise<Tool | undefined>;
|
|
103
|
+
/**
|
|
104
|
+
* 获取所有工具
|
|
105
|
+
*
|
|
106
|
+
* 返回已注册的所有工具列表,包括内置工具和自定义工具
|
|
107
|
+
*
|
|
108
|
+
* @returns {Tool[]} 工具数组
|
|
109
|
+
*/
|
|
110
|
+
getAll(): Promise<Tool[]>;
|
|
111
|
+
/**
|
|
112
|
+
* 执行工具
|
|
113
|
+
*
|
|
114
|
+
* 根据工具名称和参数执行对应的工具逻辑
|
|
115
|
+
*
|
|
116
|
+
* 执行流程:
|
|
117
|
+
* 1. 根据名称从 Map 中获取工具对象
|
|
118
|
+
* 2. 如果工具不存在,抛出错误
|
|
119
|
+
* 3. 调用工具的 execute() 方法,传入参数
|
|
120
|
+
* 4. 返回工具执行结果
|
|
121
|
+
*
|
|
122
|
+
* @param name - 工具名称
|
|
123
|
+
* @param params - 工具参数字典
|
|
124
|
+
* @returns {Promise<string>} 工具执行结果 (字符串形式)
|
|
125
|
+
* @throws {Error} 如果工具不存在
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* // 读取文件
|
|
129
|
+
* const content = await toolService.execute('read_file', { file_path: 'src/index.ts' });
|
|
130
|
+
*
|
|
131
|
+
* // 执行命令
|
|
132
|
+
* const result = await toolService.execute('execute_bash', { command: 'ls -la' });
|
|
133
|
+
*/
|
|
134
|
+
execute(name: string, params: any): Promise<string>;
|
|
135
|
+
executeParallel(calls: ToolCall[]): Promise<ToolCallResult[]>;
|
|
136
|
+
executeSequential(calls: ToolCall[]): Promise<ToolCallResult[]>;
|
|
137
|
+
/**
|
|
138
|
+
* 获取工具定义 (用于 AI)
|
|
139
|
+
*
|
|
140
|
+
* 返回符合 OpenAI Function Calling 格式的工具定义
|
|
141
|
+
* 这些定义会被添加到 AI 的系统提示词中
|
|
142
|
+
* 让 AI 知道有哪些工具可以使用以及如何调用
|
|
143
|
+
*
|
|
144
|
+
* @returns {Array} 工具定义数组
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* 返回格式:
|
|
148
|
+
* [
|
|
149
|
+
* {
|
|
150
|
+
* type: 'function',
|
|
151
|
+
* function: {
|
|
152
|
+
* name: 'read_file',
|
|
153
|
+
* description: '读取文件内容...',
|
|
154
|
+
* parameters: { type: 'object', properties: {...}, required: [...] }
|
|
155
|
+
* }
|
|
156
|
+
* }
|
|
157
|
+
* ]
|
|
158
|
+
*/
|
|
159
|
+
getToolDefinitions(): Promise<Array<{
|
|
160
|
+
type: 'function';
|
|
161
|
+
function: {
|
|
162
|
+
name: string;
|
|
163
|
+
description: string;
|
|
164
|
+
parameters: Record<string, any>;
|
|
165
|
+
};
|
|
166
|
+
}>>;
|
|
167
|
+
/**
|
|
168
|
+
* 检查工具是否存在
|
|
169
|
+
*
|
|
170
|
+
* @param name - 工具名称
|
|
171
|
+
* @returns {boolean} 如果工具存在返回 true,否则返回 false
|
|
172
|
+
*/
|
|
173
|
+
has(name: string): Promise<boolean>;
|
|
174
|
+
/**
|
|
175
|
+
* 移除工具
|
|
176
|
+
*
|
|
177
|
+
* 从注册表中删除指定工具
|
|
178
|
+
*
|
|
179
|
+
* @param name - 工具名称
|
|
180
|
+
* @returns {boolean} 如果成功删除返回 true,工具不存在返回 false
|
|
181
|
+
*/
|
|
182
|
+
remove(name: string): Promise<boolean>;
|
|
183
|
+
/**
|
|
184
|
+
* 清空所有自定义工具
|
|
185
|
+
*
|
|
186
|
+
* 保留所有内置工具,只删除用户自定义的工具
|
|
187
|
+
*
|
|
188
|
+
* 使用场景:
|
|
189
|
+
* - 切换项目时重置工具配置
|
|
190
|
+
* - 清除临时添加的工具
|
|
191
|
+
*/
|
|
192
|
+
clearCustom(): Promise<void>;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* 工具服务单例实例
|
|
196
|
+
*
|
|
197
|
+
* 在整个应用中共享同一个 ToolService 实例
|
|
198
|
+
* 应用启动时自动注册所有内置工具
|
|
199
|
+
*
|
|
200
|
+
* 使用方式:
|
|
201
|
+
* import { toolService } from '../tools/index.js';
|
|
202
|
+
*
|
|
203
|
+
* // 执行工具
|
|
204
|
+
* const result = await toolService.execute('read_file', { file_path: '...' });
|
|
205
|
+
*/
|
|
206
|
+
export declare const toolService: ToolService;
|
|
207
|
+
//# sourceMappingURL=tool.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool.service.d.ts","sourceRoot":"","sources":["../../../src/modules/tools/tool.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,IAAI,EAAe,QAAQ,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAG9E;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,WAAW;IACtB,gCAAgC;IAChC,OAAO,CAAC,KAAK,CAAg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AUnC;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,WAAW,aAAoB,CAAC"}
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 工具服务模块
|
|
3
|
+
*
|
|
4
|
+
* 本模块负责工具的注册、管理和执行
|
|
5
|
+
*
|
|
6
|
+
* 核心功能:
|
|
7
|
+
* 1. 工具注册 - 提供 register() 方法添加新工具
|
|
8
|
+
* 2. 工具获取 - 提供 get() 方法根据名称获取工具
|
|
9
|
+
* 3. 工具执行 - 提供 execute() 方法执行工具逻辑
|
|
10
|
+
* 4. 工具列表 - 提供 getAll() 方法获取所有已注册工具
|
|
11
|
+
* 5. 内置工具 - 初始化时自动注册常用工具 (文件读写、命令执行等)
|
|
12
|
+
*
|
|
13
|
+
* 内置工具列表:
|
|
14
|
+
* - read_file: 读取文件内容
|
|
15
|
+
* - write_file: 创建新文件
|
|
16
|
+
* - edit_file: 编辑现有文件
|
|
17
|
+
* - execute_bash: 执行 Shell 命令
|
|
18
|
+
* - find_files / glob: 文件搜索
|
|
19
|
+
* - grep: 内容搜索
|
|
20
|
+
* - loadSkill: 加载技能
|
|
21
|
+
*/
|
|
22
|
+
import { getBuiltinToolsInstance } from './builtin/index.js';
|
|
23
|
+
/**
|
|
24
|
+
* ToolService 类
|
|
25
|
+
*
|
|
26
|
+
* 工具服务是整个 Agent 系统的核心组件之一
|
|
27
|
+
* 负责管理系统中所有可用的工具,包括内置工具和自定义工具
|
|
28
|
+
*
|
|
29
|
+
* 使用方式:
|
|
30
|
+
* import { toolService } from '../tools/index.js';
|
|
31
|
+
*
|
|
32
|
+
* // 执行工具
|
|
33
|
+
* const result = await toolService.execute('read_file', { file_path: 'src/index.ts' });
|
|
34
|
+
*
|
|
35
|
+
* // 注册自定义工具
|
|
36
|
+
* toolService.register({
|
|
37
|
+
* name: 'my_custom_tool',
|
|
38
|
+
* description: '自定义工具描述',
|
|
39
|
+
* parameters: { ... },
|
|
40
|
+
* execute: async (params) => { ... }
|
|
41
|
+
* });
|
|
42
|
+
*/
|
|
43
|
+
export class ToolService {
|
|
44
|
+
/**
|
|
45
|
+
* 构造函数
|
|
46
|
+
*
|
|
47
|
+
* 初始化时自动调用 registerBuiltinTools() 注册内置工具
|
|
48
|
+
* 这样应用启动后立即可以使用所有内置工具
|
|
49
|
+
*/
|
|
50
|
+
constructor() {
|
|
51
|
+
/** 工具注册表,使用 Map 存储,key 为工具名称 */
|
|
52
|
+
this.tools = new Map();
|
|
53
|
+
this.initialized = false;
|
|
54
|
+
this.initPromise = null;
|
|
55
|
+
this.initPromise = this.registerBuiltinTools();
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* 等待工具服务初始化完成
|
|
59
|
+
*/
|
|
60
|
+
async waitForInit() {
|
|
61
|
+
if (this.initialized)
|
|
62
|
+
return;
|
|
63
|
+
if (this.initPromise) {
|
|
64
|
+
await this.initPromise;
|
|
65
|
+
this.initialized = true;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* 注册内置工具
|
|
70
|
+
*
|
|
71
|
+
* 从 builtin/index.ts 导入所有内置工具并注册
|
|
72
|
+
* 内置工具包括文件操作、命令执行、搜索等功能
|
|
73
|
+
*
|
|
74
|
+
* 注册流程:
|
|
75
|
+
* 1. 调用 getBuiltinToolsInstance() 获取内置工具
|
|
76
|
+
* 2. 遍历工具数组
|
|
77
|
+
* 3. 将每个工具的名称作为 key,工具对象作为 value 存入 Map
|
|
78
|
+
*/
|
|
79
|
+
async registerBuiltinTools() {
|
|
80
|
+
const builtinTools = await getBuiltinToolsInstance();
|
|
81
|
+
for (const tool of builtinTools) {
|
|
82
|
+
this.tools.set(tool.name, tool);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* 注册工具
|
|
87
|
+
*
|
|
88
|
+
* 用于添加自定义工具到系统中
|
|
89
|
+
* 可以覆盖同名的内置工具 (不推荐)
|
|
90
|
+
*
|
|
91
|
+
* @param tool - 工具对象,包含 name、description、parameters、execute
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* toolService.register({
|
|
95
|
+
* name: 'my_tool',
|
|
96
|
+
* description: '我的自定义工具',
|
|
97
|
+
* parameters: {
|
|
98
|
+
* type: 'object',
|
|
99
|
+
* properties: { input: { type: 'string' } },
|
|
100
|
+
* required: ['input']
|
|
101
|
+
* },
|
|
102
|
+
* execute: async (params) => {
|
|
103
|
+
* return `处理: ${params.input}`;
|
|
104
|
+
* }
|
|
105
|
+
* });
|
|
106
|
+
*/
|
|
107
|
+
register(tool) {
|
|
108
|
+
this.tools.set(tool.name, tool);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* 获取工具
|
|
112
|
+
*
|
|
113
|
+
* 根据工具名称获取对应的工具对象
|
|
114
|
+
*
|
|
115
|
+
* @param name - 工具名称
|
|
116
|
+
* @returns {Tool | undefined} 工具对象,如果不存在则返回 undefined
|
|
117
|
+
*/
|
|
118
|
+
async get(name) {
|
|
119
|
+
await this.waitForInit();
|
|
120
|
+
return this.tools.get(name);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* 获取所有工具
|
|
124
|
+
*
|
|
125
|
+
* 返回已注册的所有工具列表,包括内置工具和自定义工具
|
|
126
|
+
*
|
|
127
|
+
* @returns {Tool[]} 工具数组
|
|
128
|
+
*/
|
|
129
|
+
async getAll() {
|
|
130
|
+
await this.waitForInit();
|
|
131
|
+
return Array.from(this.tools.values());
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* 执行工具
|
|
135
|
+
*
|
|
136
|
+
* 根据工具名称和参数执行对应的工具逻辑
|
|
137
|
+
*
|
|
138
|
+
* 执行流程:
|
|
139
|
+
* 1. 根据名称从 Map 中获取工具对象
|
|
140
|
+
* 2. 如果工具不存在,抛出错误
|
|
141
|
+
* 3. 调用工具的 execute() 方法,传入参数
|
|
142
|
+
* 4. 返回工具执行结果
|
|
143
|
+
*
|
|
144
|
+
* @param name - 工具名称
|
|
145
|
+
* @param params - 工具参数字典
|
|
146
|
+
* @returns {Promise<string>} 工具执行结果 (字符串形式)
|
|
147
|
+
* @throws {Error} 如果工具不存在
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* // 读取文件
|
|
151
|
+
* const content = await toolService.execute('read_file', { file_path: 'src/index.ts' });
|
|
152
|
+
*
|
|
153
|
+
* // 执行命令
|
|
154
|
+
* const result = await toolService.execute('execute_bash', { command: 'ls -la' });
|
|
155
|
+
*/
|
|
156
|
+
async execute(name, params) {
|
|
157
|
+
await this.waitForInit();
|
|
158
|
+
const tool = this.tools.get(name);
|
|
159
|
+
if (!tool) {
|
|
160
|
+
throw new Error(`Tool not found: ${name}`);
|
|
161
|
+
}
|
|
162
|
+
const context = {
|
|
163
|
+
sessionId: '',
|
|
164
|
+
workDir: process.cwd(),
|
|
165
|
+
};
|
|
166
|
+
const result = await tool.execute(params, context);
|
|
167
|
+
return result.output;
|
|
168
|
+
}
|
|
169
|
+
async executeParallel(calls) {
|
|
170
|
+
await this.waitForInit();
|
|
171
|
+
const context = {
|
|
172
|
+
sessionId: '',
|
|
173
|
+
workDir: process.cwd(),
|
|
174
|
+
};
|
|
175
|
+
const executeCall = async (call) => {
|
|
176
|
+
const startTime = Date.now();
|
|
177
|
+
try {
|
|
178
|
+
const tool = this.tools.get(call.name);
|
|
179
|
+
if (!tool) {
|
|
180
|
+
throw new Error(`Tool not found: ${call.name}`);
|
|
181
|
+
}
|
|
182
|
+
const result = await tool.execute(call.params, context);
|
|
183
|
+
return {
|
|
184
|
+
name: call.name,
|
|
185
|
+
params: call.params,
|
|
186
|
+
success: result.success,
|
|
187
|
+
output: result.output,
|
|
188
|
+
error: result.error,
|
|
189
|
+
metadata: result.metadata,
|
|
190
|
+
duration: Date.now() - startTime,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
return {
|
|
195
|
+
name: call.name,
|
|
196
|
+
params: call.params,
|
|
197
|
+
success: false,
|
|
198
|
+
output: '',
|
|
199
|
+
error: error instanceof Error ? error.message : String(error),
|
|
200
|
+
duration: Date.now() - startTime,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
return Promise.all(calls.map(executeCall));
|
|
205
|
+
}
|
|
206
|
+
async executeSequential(calls) {
|
|
207
|
+
await this.waitForInit();
|
|
208
|
+
const context = {
|
|
209
|
+
sessionId: '',
|
|
210
|
+
workDir: process.cwd(),
|
|
211
|
+
};
|
|
212
|
+
const results = [];
|
|
213
|
+
for (const call of calls) {
|
|
214
|
+
const startTime = Date.now();
|
|
215
|
+
try {
|
|
216
|
+
const tool = this.tools.get(call.name);
|
|
217
|
+
if (!tool) {
|
|
218
|
+
throw new Error(`Tool not found: ${call.name}`);
|
|
219
|
+
}
|
|
220
|
+
const result = await tool.execute(call.params, context);
|
|
221
|
+
results.push({
|
|
222
|
+
name: call.name,
|
|
223
|
+
params: call.params,
|
|
224
|
+
success: result.success,
|
|
225
|
+
output: result.output,
|
|
226
|
+
error: result.error,
|
|
227
|
+
metadata: result.metadata,
|
|
228
|
+
duration: Date.now() - startTime,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
catch (error) {
|
|
232
|
+
results.push({
|
|
233
|
+
name: call.name,
|
|
234
|
+
params: call.params,
|
|
235
|
+
success: false,
|
|
236
|
+
output: '',
|
|
237
|
+
error: error instanceof Error ? error.message : String(error),
|
|
238
|
+
duration: Date.now() - startTime,
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return results;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* 获取工具定义 (用于 AI)
|
|
246
|
+
*
|
|
247
|
+
* 返回符合 OpenAI Function Calling 格式的工具定义
|
|
248
|
+
* 这些定义会被添加到 AI 的系统提示词中
|
|
249
|
+
* 让 AI 知道有哪些工具可以使用以及如何调用
|
|
250
|
+
*
|
|
251
|
+
* @returns {Array} 工具定义数组
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* 返回格式:
|
|
255
|
+
* [
|
|
256
|
+
* {
|
|
257
|
+
* type: 'function',
|
|
258
|
+
* function: {
|
|
259
|
+
* name: 'read_file',
|
|
260
|
+
* description: '读取文件内容...',
|
|
261
|
+
* parameters: { type: 'object', properties: {...}, required: [...] }
|
|
262
|
+
* }
|
|
263
|
+
* }
|
|
264
|
+
* ]
|
|
265
|
+
*/
|
|
266
|
+
async getToolDefinitions() {
|
|
267
|
+
const tools = await this.getAll();
|
|
268
|
+
return tools.map((tool) => ({
|
|
269
|
+
type: 'function',
|
|
270
|
+
function: {
|
|
271
|
+
name: tool.name,
|
|
272
|
+
description: tool.description,
|
|
273
|
+
parameters: tool.parameters,
|
|
274
|
+
},
|
|
275
|
+
}));
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* 检查工具是否存在
|
|
279
|
+
*
|
|
280
|
+
* @param name - 工具名称
|
|
281
|
+
* @returns {boolean} 如果工具存在返回 true,否则返回 false
|
|
282
|
+
*/
|
|
283
|
+
async has(name) {
|
|
284
|
+
await this.waitForInit();
|
|
285
|
+
return this.tools.has(name);
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* 移除工具
|
|
289
|
+
*
|
|
290
|
+
* 从注册表中删除指定工具
|
|
291
|
+
*
|
|
292
|
+
* @param name - 工具名称
|
|
293
|
+
* @returns {boolean} 如果成功删除返回 true,工具不存在返回 false
|
|
294
|
+
*/
|
|
295
|
+
async remove(name) {
|
|
296
|
+
await this.waitForInit();
|
|
297
|
+
return this.tools.delete(name);
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* 清空所有自定义工具
|
|
301
|
+
*
|
|
302
|
+
* 保留所有内置工具,只删除用户自定义的工具
|
|
303
|
+
*
|
|
304
|
+
* 使用场景:
|
|
305
|
+
* - 切换项目时重置工具配置
|
|
306
|
+
* - 清除临时添加的工具
|
|
307
|
+
*/
|
|
308
|
+
async clearCustom() {
|
|
309
|
+
const builtinTools = await getBuiltinToolsInstance();
|
|
310
|
+
const builtinNames = new Set(builtinTools.map(t => t.name));
|
|
311
|
+
for (const name of this.tools.keys()) {
|
|
312
|
+
if (!builtinNames.has(name)) {
|
|
313
|
+
this.tools.delete(name);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* 工具服务单例实例
|
|
320
|
+
*
|
|
321
|
+
* 在整个应用中共享同一个 ToolService 实例
|
|
322
|
+
* 应用启动时自动注册所有内置工具
|
|
323
|
+
*
|
|
324
|
+
* 使用方式:
|
|
325
|
+
* import { toolService } from '../tools/index.js';
|
|
326
|
+
*
|
|
327
|
+
* // 执行工具
|
|
328
|
+
* const result = await toolService.execute('read_file', { file_path: '...' });
|
|
329
|
+
*/
|
|
330
|
+
export const toolService = new ToolService();
|
|
331
|
+
//# sourceMappingURL=tool.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool.service.js","sourceRoot":"","sources":["../../../src/modules/tools/tool.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,WAAW;IAMtB;;;;;OAKG;IACH;QAXA,gCAAgC;QACxB,UAAK,GAAsB,IAAI,GAAG,EAAE,CAAC;QACrC,gBAAW,GAAY,KAAK,CAAC;QAC7B,gBAAW,GAAyB,IAAI,CAAC;QAS/C,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;IACjD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,WAAW;QACf,IAAI,IAAI,CAAC,WAAW;YAAE,OAAO;QAC7B,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,MAAM,IAAI,CAAC,W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AAM,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,WAAW;QACf,MAAM,YAAY,GAAG,MAAM,uBAAuB,EAAE,CAAC;QACrD,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QAE5D,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC;YACrC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC5B,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAC1B,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAED;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tools 模块类型定义
|
|
3
|
+
*/
|
|
4
|
+
export interface Tool {
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
parameters: {
|
|
8
|
+
type: 'object';
|
|
9
|
+
properties: Record<string, any>;
|
|
10
|
+
required?: string[];
|
|
11
|
+
};
|
|
12
|
+
execute: (params: any, context: ToolContext) => Promise<ToolResult>;
|
|
13
|
+
}
|
|
14
|
+
export interface ToolContext {
|
|
15
|
+
sessionId: string;
|
|
16
|
+
workDir: string;
|
|
17
|
+
abortSignal?: AbortSignal;
|
|
18
|
+
onProgress?: (msg: string) => void;
|
|
19
|
+
}
|
|
20
|
+
export interface ToolResult {
|
|
21
|
+
success: boolean;
|
|
22
|
+
output: string;
|
|
23
|
+
error?: string;
|
|
24
|
+
metadata?: Record<string, any>;
|
|
25
|
+
}
|
|
26
|
+
export interface ToolCall {
|
|
27
|
+
name: string;
|
|
28
|
+
params: Record<string, any>;
|
|
29
|
+
}
|
|
30
|
+
export interface ToolCallResult {
|
|
31
|
+
name: string;
|
|
32
|
+
params: Record<string, any>;
|
|
33
|
+
success: boolean;
|
|
34
|
+
output: string;
|
|
35
|
+
error?: string;
|
|
36
|
+
metadata?: Record<string, any>;
|
|
37
|
+
duration?: number;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=tool.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool.types.d.ts","sourceRoot":"","sources":["../../../src/modules/tools/tool.types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE;QACV,IAAI,EAAE,QAAQ,CAAA;QACd,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;QAC/B,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;KACpB,CAAA;IACD,OAAO,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,UAAU,CAAC,CAAA;CACpE;AAED,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;IACf,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;CACnC;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAC/B;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAC5B;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC3B,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool.types.js","sourceRoot":"","sources":["../../../src/modules/tools/tool.types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/web/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,OAA8B,MAAM,SAAS,CAAC;AAIrD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,CAAC,WAAW,GAAG,IAAI,CAU/D"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web 模块
|
|
3
|
+
*/
|
|
4
|
+
import express from 'express';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
export { WebService } from './web.service.js';
|
|
7
|
+
/**
|
|
8
|
+
* 静态文件服务
|
|
9
|
+
*/
|
|
10
|
+
export function setupStaticFiles(app) {
|
|
11
|
+
const publicDir = path.join(__dirname, 'public');
|
|
12
|
+
app.use(express.static(publicDir));
|
|
13
|
+
// SPA fallback
|
|
14
|
+
app.get('*', (req, res) => {
|
|
15
|
+
if (!req.path.startsWith('/api')) {
|
|
16
|
+
res.sendFile(path.join(publicDir, 'index.html'));
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/web/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,OAA8B,MAAM,SAAS,CAAC;AACrD,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAwB;IACvD,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IACjD,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;IAEnC,eAAe;IACf,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAY,EAAE,GAAa,EAAE,EAAE;QAC3C,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;YACjC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC;QACnD,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
|