@tyvm/knowhow 0.0.46 → 0.0.48
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/benchmarks/results/27b0a06/2025-09-27/xai/xai-grok-code-fast-1.json +2909 -0
- package/benchmarks/results/4057aed/2025-08-14/anthropic/anthropic-claude-sonnet-4-20250514.json +1671 -0
- package/jest.config.js +2 -2
- package/package.json +8 -3
- package/src/agents/base/base.ts +30 -24
- package/src/agents/patcher/patcher.ts +26 -5
- package/src/agents/tools/agentCall.ts +4 -2
- package/src/agents/tools/aiClient.ts +3 -11
- package/src/agents/tools/ast/astAppendNode.ts +90 -0
- package/src/agents/tools/ast/astDeleteNode.ts +88 -0
- package/src/agents/tools/ast/astEditNode.ts +95 -0
- package/src/agents/tools/ast/astGetPathForLine.ts +73 -0
- package/src/agents/tools/ast/astListPaths.ts +66 -0
- package/src/agents/tools/ast/index.ts +7 -0
- package/src/agents/tools/callPlugin.ts +8 -2
- package/src/agents/tools/embeddingSearch.ts +2 -1
- package/src/agents/tools/execCommand.ts +239 -94
- package/src/agents/tools/fileSearch.ts +15 -17
- package/src/agents/tools/index.ts +1 -0
- package/src/agents/tools/language/definitions.ts +10 -2
- package/src/agents/tools/language/index.ts +3 -2
- package/src/agents/tools/lintFile.ts +4 -2
- package/src/agents/tools/list.ts +203 -62
- package/src/agents/tools/patch.ts +48 -14
- package/src/agents/tools/readBlocks.ts +34 -0
- package/src/agents/tools/readFile.ts +23 -0
- package/src/agents/tools/stringReplace.ts +33 -9
- package/src/agents/tools/writeFile.ts +55 -0
- package/src/agents/tools/ycmd/server.ts +14 -4
- package/src/chat/CliChatService.ts +6 -1
- package/src/chat/modules/AgentModule.ts +107 -64
- package/src/chat/modules/AskModule.ts +0 -1
- package/src/chat/modules/SetupModule.ts +4 -4
- package/src/chat/modules/SystemModule.ts +28 -5
- package/src/chat/types.ts +2 -0
- package/src/chat-old.ts +2 -2
- package/src/clients/anthropic.ts +22 -1
- package/src/clients/openai.ts +1 -1
- package/src/clients/types.ts +1 -1
- package/src/clients/xai.ts +15 -5
- package/src/config.ts +17 -5
- package/src/dataset/diffs/generate.ts +2 -2
- package/src/dataset/diffs/jsonl.ts +0 -1
- package/src/embeddings.ts +6 -4
- package/src/index.ts +11 -5
- package/src/plugins/GitPlugin.ts +530 -0
- package/src/plugins/LinterPlugin.ts +89 -0
- package/src/plugins/PluginBase.ts +4 -2
- package/src/plugins/asana.ts +4 -2
- package/src/plugins/downloader/plugin.ts +5 -2
- package/src/plugins/embedding.ts +24 -4
- package/src/plugins/figma.ts +7 -3
- package/src/plugins/github.ts +4 -2
- package/src/plugins/jira.ts +4 -2
- package/src/plugins/language.ts +134 -27
- package/src/plugins/linear.ts +4 -2
- package/src/plugins/notion.ts +4 -2
- package/src/plugins/plugins.ts +27 -16
- package/src/plugins/tree-sitter/editor.ts +369 -0
- package/src/plugins/tree-sitter/lang-packs/index.ts +23 -0
- package/src/plugins/tree-sitter/lang-packs/java.ts +59 -0
- package/src/plugins/tree-sitter/lang-packs/javascript.ts +57 -0
- package/src/plugins/tree-sitter/lang-packs/python.ts +45 -0
- package/src/plugins/tree-sitter/lang-packs/types.ts +79 -0
- package/src/plugins/tree-sitter/lang-packs/typescript.ts +49 -0
- package/src/plugins/tree-sitter/parser.ts +444 -0
- package/src/plugins/tree-sitter/simple-paths.ts +467 -0
- package/src/plugins/types.ts +11 -0
- package/src/plugins/url.ts +5 -3
- package/src/plugins/vim.ts +8 -5
- package/src/processors/CustomVariables.ts +19 -7
- package/src/processors/TokenCompressor.ts +13 -13
- package/src/processors/ToolResponseCache.ts +15 -6
- package/src/services/EmbeddingService.ts +18 -9
- package/src/services/EventService.ts +80 -0
- package/src/services/Mcp.ts +5 -0
- package/src/services/S3.ts +4 -3
- package/src/services/Tools.ts +125 -53
- package/src/services/index.ts +16 -11
- package/src/services/types.ts +3 -3
- package/src/types.ts +7 -2
- package/src/worker.ts +14 -1
- package/test-comprehensive.ts +31 -0
- package/tests/clients/AIClient.test.ts +490 -0
- package/tests/manual/agent-events/run-test.ts +203 -0
- package/tests/{integration → manual/file-edits}/figma.test.ts +1 -1
- package/tests/{integration → manual/file-edits}/fileblocks/readwrite.test.ts +7 -3
- package/tests/{integration → manual/file-edits}/patching.test.ts +11 -8
- package/tests/plugins/language/languagePlugin-content-triggers.test.ts +332 -0
- package/tests/plugins/language/languagePlugin-integration.test.ts +456 -0
- package/tests/plugins/language/languagePlugin.test.ts +363 -0
- package/tests/processors/Base64ImageDetector.test.ts +403 -0
- package/tests/processors/CustomVariables.test.ts +430 -0
- package/tests/processors/HarmonyToolProcessor.test.ts +490 -0
- package/tests/processors/TokenCompressor.test.ts +391 -0
- package/tests/processors/ToolResponseCache.test.ts +688 -0
- package/tests/services/Tools.test.ts +1339 -0
- package/tests/test.spec.ts +162 -117
- package/tests/tree-sitter/editor.test.ts +113 -0
- package/tests/tree-sitter/invalid.test.ts +299 -0
- package/tests/tree-sitter/paths/common-edits.test.ts +564 -0
- package/tests/tree-sitter/paths/debug-exact-position.test.ts +44 -0
- package/tests/tree-sitter/paths/debug-line-indexing.test.ts +49 -0
- package/tests/tree-sitter/paths/debug-paths.test.ts +90 -0
- package/tests/tree-sitter/paths/paths.test.ts +170 -0
- package/tests/tree-sitter/paths/simple-paths.test.ts +367 -0
- package/tests/tree-sitter/sample-after.ts +48 -0
- package/tests/tree-sitter/sample-before.ts +25 -0
- package/tests/tree-sitter/test-files/completely-broken.ts +7 -0
- package/tests/tree-sitter/test-files/duplicate-braces.ts +39 -0
- package/tests/tree-sitter/test-files/invalid-nesting.ts +39 -0
- package/tests/tree-sitter/test-files/malformed-signature.ts +39 -0
- package/tests/tree-sitter/test-files/mismatched-parens.ts +39 -0
- package/tests/tree-sitter/test-files/missing-semicolon.ts +39 -0
- package/tests/tree-sitter/test-files/partially-broken.ts +20 -0
- package/tests/tree-sitter/test-files/specific-errors.ts +14 -0
- package/tests/tree-sitter/test-files/unclosed-string.ts +39 -0
- package/tests/tree-sitter/tree-sitter.test.ts +251 -0
- package/ts_build/package.json +8 -3
- package/ts_build/src/agents/base/base.d.ts +2 -2
- package/ts_build/src/agents/base/base.js +24 -20
- package/ts_build/src/agents/base/base.js.map +1 -1
- package/ts_build/src/agents/patcher/patcher.js +26 -5
- package/ts_build/src/agents/patcher/patcher.js.map +1 -1
- package/ts_build/src/agents/tools/agentCall.js +2 -1
- package/ts_build/src/agents/tools/agentCall.js.map +1 -1
- package/ts_build/src/agents/tools/aiClient.d.ts +7 -8
- package/ts_build/src/agents/tools/aiClient.js.map +1 -1
- package/ts_build/src/agents/tools/ast/astAppendNode.d.ts +1 -0
- package/ts_build/src/agents/tools/ast/astAppendNode.js +96 -0
- package/ts_build/src/agents/tools/ast/astAppendNode.js.map +1 -0
- package/ts_build/src/agents/tools/ast/astDeleteNode.d.ts +1 -0
- package/ts_build/src/agents/tools/ast/astDeleteNode.js +94 -0
- package/ts_build/src/agents/tools/ast/astDeleteNode.js.map +1 -0
- package/ts_build/src/agents/tools/ast/astEditNode.d.ts +1 -0
- package/ts_build/src/agents/tools/ast/astEditNode.js +96 -0
- package/ts_build/src/agents/tools/ast/astEditNode.js.map +1 -0
- package/ts_build/src/agents/tools/ast/astGetPathForLine.d.ts +1 -0
- package/ts_build/src/agents/tools/ast/astGetPathForLine.js +78 -0
- package/ts_build/src/agents/tools/ast/astGetPathForLine.js.map +1 -0
- package/ts_build/src/agents/tools/ast/astListPaths.d.ts +1 -0
- package/ts_build/src/agents/tools/ast/astListPaths.js +78 -0
- package/ts_build/src/agents/tools/ast/astListPaths.js.map +1 -0
- package/ts_build/src/agents/tools/ast/index.d.ts +5 -0
- package/ts_build/src/agents/tools/ast/index.js +14 -0
- package/ts_build/src/agents/tools/ast/index.js.map +1 -0
- package/ts_build/src/agents/tools/astAppendNode.d.ts +1 -0
- package/ts_build/src/agents/tools/astAppendNode.js +98 -0
- package/ts_build/src/agents/tools/astAppendNode.js.map +1 -0
- package/ts_build/src/agents/tools/astDeleteNode.d.ts +1 -0
- package/ts_build/src/agents/tools/astDeleteNode.js +95 -0
- package/ts_build/src/agents/tools/astDeleteNode.js.map +1 -0
- package/ts_build/src/agents/tools/astEditNode.d.ts +1 -0
- package/ts_build/src/agents/tools/astEditNode.js +98 -0
- package/ts_build/src/agents/tools/astEditNode.js.map +1 -0
- package/ts_build/src/agents/tools/astGetPathForLine.d.ts +1 -0
- package/ts_build/src/agents/tools/astGetPathForLine.js +89 -0
- package/ts_build/src/agents/tools/astGetPathForLine.js.map +1 -0
- package/ts_build/src/agents/tools/astListPaths.d.ts +1 -0
- package/ts_build/src/agents/tools/astListPaths.js +82 -0
- package/ts_build/src/agents/tools/astListPaths.js.map +1 -0
- package/ts_build/src/agents/tools/callPlugin.js +4 -2
- package/ts_build/src/agents/tools/callPlugin.js.map +1 -1
- package/ts_build/src/agents/tools/embeddingSearch.js +3 -2
- package/ts_build/src/agents/tools/embeddingSearch.js.map +1 -1
- package/ts_build/src/agents/tools/execCommand.d.ts +2 -2
- package/ts_build/src/agents/tools/execCommand.js +201 -67
- package/ts_build/src/agents/tools/execCommand.js.map +1 -1
- package/ts_build/src/agents/tools/fileSearch.d.ts +1 -1
- package/ts_build/src/agents/tools/fileSearch.js +11 -15
- package/ts_build/src/agents/tools/fileSearch.js.map +1 -1
- package/ts_build/src/agents/tools/github/index.d.ts +1 -1
- package/ts_build/src/agents/tools/index.d.ts +1 -0
- package/ts_build/src/agents/tools/index.js +1 -0
- package/ts_build/src/agents/tools/index.js.map +1 -1
- package/ts_build/src/agents/tools/language/definitions.js +11 -2
- package/ts_build/src/agents/tools/language/definitions.js.map +1 -1
- package/ts_build/src/agents/tools/language/index.js +4 -3
- package/ts_build/src/agents/tools/language/index.js.map +1 -1
- package/ts_build/src/agents/tools/lintFile.js +4 -2
- package/ts_build/src/agents/tools/lintFile.js.map +1 -1
- package/ts_build/src/agents/tools/list.js +185 -49
- package/ts_build/src/agents/tools/list.js.map +1 -1
- package/ts_build/src/agents/tools/patch.js +33 -10
- package/ts_build/src/agents/tools/patch.js.map +1 -1
- package/ts_build/src/agents/tools/readBlocks.js +23 -0
- package/ts_build/src/agents/tools/readBlocks.js.map +1 -1
- package/ts_build/src/agents/tools/readFile.js +14 -0
- package/ts_build/src/agents/tools/readFile.js.map +1 -1
- package/ts_build/src/agents/tools/stringReplace.js +19 -2
- package/ts_build/src/agents/tools/stringReplace.js.map +1 -1
- package/ts_build/src/agents/tools/writeFile.js +40 -0
- package/ts_build/src/agents/tools/writeFile.js.map +1 -1
- package/ts_build/src/agents/tools/ycmd/server.js +5 -0
- package/ts_build/src/agents/tools/ycmd/server.js.map +1 -1
- package/ts_build/src/chat/CliChatService.d.ts +1 -0
- package/ts_build/src/chat/CliChatService.js +6 -2
- package/ts_build/src/chat/CliChatService.js.map +1 -1
- package/ts_build/src/chat/modules/AgentModule.d.ts +5 -1
- package/ts_build/src/chat/modules/AgentModule.js +53 -31
- package/ts_build/src/chat/modules/AgentModule.js.map +1 -1
- package/ts_build/src/chat/modules/AskModule.js.map +1 -1
- package/ts_build/src/chat/modules/SetupModule.js +4 -3
- package/ts_build/src/chat/modules/SetupModule.js.map +1 -1
- package/ts_build/src/chat/modules/SystemModule.js +19 -4
- package/ts_build/src/chat/modules/SystemModule.js.map +1 -1
- package/ts_build/src/chat/modules/index.d.ts +5 -0
- package/ts_build/src/chat/modules/index.js +14 -0
- package/ts_build/src/chat/modules/index.js.map +1 -0
- package/ts_build/src/chat/types.d.ts +2 -0
- package/ts_build/src/chat-old.js +3 -3
- package/ts_build/src/chat-old.js.map +1 -1
- package/ts_build/src/clients/anthropic.d.ts +1 -0
- package/ts_build/src/clients/anthropic.js +22 -1
- package/ts_build/src/clients/anthropic.js.map +1 -1
- package/ts_build/src/clients/openai.js +1 -1
- package/ts_build/src/clients/openai.js.map +1 -1
- package/ts_build/src/clients/types.d.ts +1 -1
- package/ts_build/src/clients/xai.d.ts +7 -0
- package/ts_build/src/clients/xai.js +13 -4
- package/ts_build/src/clients/xai.js.map +1 -1
- package/ts_build/src/config.js +14 -3
- package/ts_build/src/config.js.map +1 -1
- package/ts_build/src/dataset/diffs/generate.js +2 -2
- package/ts_build/src/dataset/diffs/generate.js.map +1 -1
- package/ts_build/src/dataset/diffs/jsonl.js.map +1 -1
- package/ts_build/src/embeddings.js +7 -9
- package/ts_build/src/embeddings.js.map +1 -1
- package/ts_build/src/index.js +10 -10
- package/ts_build/src/index.js.map +1 -1
- package/ts_build/src/plugins/GitPlugin.d.ts +39 -0
- package/ts_build/src/plugins/GitPlugin.js +439 -0
- package/ts_build/src/plugins/GitPlugin.js.map +1 -0
- package/ts_build/src/plugins/LinterPlugin.d.ts +15 -0
- package/ts_build/src/plugins/LinterPlugin.js +65 -0
- package/ts_build/src/plugins/LinterPlugin.js.map +1 -0
- package/ts_build/src/plugins/PluginBase.d.ts +4 -3
- package/ts_build/src/plugins/PluginBase.js +3 -3
- package/ts_build/src/plugins/PluginBase.js.map +1 -1
- package/ts_build/src/plugins/asana.d.ts +3 -1
- package/ts_build/src/plugins/asana.js +3 -2
- package/ts_build/src/plugins/asana.js.map +1 -1
- package/ts_build/src/plugins/downloader/plugin.d.ts +3 -1
- package/ts_build/src/plugins/downloader/plugin.js +3 -2
- package/ts_build/src/plugins/downloader/plugin.js.map +1 -1
- package/ts_build/src/plugins/embedding.d.ts +5 -1
- package/ts_build/src/plugins/embedding.js +15 -3
- package/ts_build/src/plugins/embedding.js.map +1 -1
- package/ts_build/src/plugins/figma.d.ts +3 -1
- package/ts_build/src/plugins/figma.js +28 -4
- package/ts_build/src/plugins/figma.js.map +1 -1
- package/ts_build/src/plugins/github.d.ts +3 -1
- package/ts_build/src/plugins/github.js +3 -2
- package/ts_build/src/plugins/github.js.map +1 -1
- package/ts_build/src/plugins/jira.d.ts +3 -1
- package/ts_build/src/plugins/jira.js +3 -2
- package/ts_build/src/plugins/jira.js.map +1 -1
- package/ts_build/src/plugins/language.d.ts +7 -4
- package/ts_build/src/plugins/language.js +85 -20
- package/ts_build/src/plugins/language.js.map +1 -1
- package/ts_build/src/plugins/linear.d.ts +3 -1
- package/ts_build/src/plugins/linear.js +3 -2
- package/ts_build/src/plugins/linear.js.map +1 -1
- package/ts_build/src/plugins/notion.d.ts +3 -1
- package/ts_build/src/plugins/notion.js +3 -2
- package/ts_build/src/plugins/notion.js.map +1 -1
- package/ts_build/src/plugins/plugins.d.ts +4 -3
- package/ts_build/src/plugins/plugins.js +24 -14
- package/ts_build/src/plugins/plugins.js.map +1 -1
- package/ts_build/src/plugins/tree-sitter/editor.d.ts +34 -0
- package/ts_build/src/plugins/tree-sitter/editor.js +218 -0
- package/ts_build/src/plugins/tree-sitter/editor.js.map +1 -0
- package/ts_build/src/plugins/tree-sitter/human-readable-paths-new.d.ts +29 -0
- package/ts_build/src/plugins/tree-sitter/human-readable-paths-new.js +538 -0
- package/ts_build/src/plugins/tree-sitter/human-readable-paths-new.js.map +1 -0
- package/ts_build/src/plugins/tree-sitter/human-readable-paths.d.ts +22 -0
- package/ts_build/src/plugins/tree-sitter/human-readable-paths.js +332 -0
- package/ts_build/src/plugins/tree-sitter/human-readable-paths.js.map +1 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/index.d.ts +8 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/index.js +26 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/index.js.map +1 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/java.d.ts +2 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/java.js +61 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/java.js.map +1 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/javascript.d.ts +2 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/javascript.js +59 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/javascript.js.map +1 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/python.d.ts +2 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/python.js +47 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/python.js.map +1 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/types.d.ts +43 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/types.js +3 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/types.js.map +1 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/typescript.d.ts +2 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/typescript.js +50 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/typescript.js.map +1 -0
- package/ts_build/src/plugins/tree-sitter/parser.d.ts +75 -0
- package/ts_build/src/plugins/tree-sitter/parser.js +306 -0
- package/ts_build/src/plugins/tree-sitter/parser.js.map +1 -0
- package/ts_build/src/plugins/tree-sitter/simple-paths.d.ts +22 -0
- package/ts_build/src/plugins/tree-sitter/simple-paths.js +332 -0
- package/ts_build/src/plugins/tree-sitter/simple-paths.js.map +1 -0
- package/ts_build/src/plugins/types.d.ts +10 -0
- package/ts_build/src/plugins/url.d.ts +3 -2
- package/ts_build/src/plugins/url.js +3 -2
- package/ts_build/src/plugins/url.js.map +1 -1
- package/ts_build/src/plugins/vim.d.ts +4 -2
- package/ts_build/src/plugins/vim.js +6 -8
- package/ts_build/src/plugins/vim.js.map +1 -1
- package/ts_build/src/processors/CustomVariables.js +12 -3
- package/ts_build/src/processors/CustomVariables.js.map +1 -1
- package/ts_build/src/processors/TokenCompressor.js +8 -11
- package/ts_build/src/processors/TokenCompressor.js.map +1 -1
- package/ts_build/src/processors/ToolResponseCache.d.ts +2 -2
- package/ts_build/src/processors/ToolResponseCache.js +12 -2
- package/ts_build/src/processors/ToolResponseCache.js.map +1 -1
- package/ts_build/src/services/EmbeddingService.d.ts +10 -1
- package/ts_build/src/services/EmbeddingService.js +12 -12
- package/ts_build/src/services/EmbeddingService.js.map +1 -1
- package/ts_build/src/services/EventService.d.ts +7 -0
- package/ts_build/src/services/EventService.js +49 -0
- package/ts_build/src/services/EventService.js.map +1 -1
- package/ts_build/src/services/Mcp.js +8 -0
- package/ts_build/src/services/Mcp.js.map +1 -1
- package/ts_build/src/services/S3.js +4 -3
- package/ts_build/src/services/S3.js.map +1 -1
- package/ts_build/src/services/Tools.d.ts +1 -0
- package/ts_build/src/services/Tools.js +97 -35
- package/ts_build/src/services/Tools.js.map +1 -1
- package/ts_build/src/services/index.d.ts +4 -5
- package/ts_build/src/services/index.js +14 -9
- package/ts_build/src/services/index.js.map +1 -1
- package/ts_build/src/services/types.js +3 -3
- package/ts_build/src/services/types.js.map +1 -1
- package/ts_build/src/types.d.ts +7 -1
- package/ts_build/src/types.js +4 -0
- package/ts_build/src/types.js.map +1 -1
- package/ts_build/src/worker.js +12 -1
- package/ts_build/src/worker.js.map +1 -1
- package/ts_build/tests/clients/AIClient.test.d.ts +1 -0
- package/ts_build/tests/clients/AIClient.test.js +377 -0
- package/ts_build/tests/clients/AIClient.test.js.map +1 -0
- package/ts_build/tests/languagePlugin.test.js +217 -11
- package/ts_build/tests/languagePlugin.test.js.map +1 -1
- package/ts_build/tests/manual/agent-events/event-handler-reliability.test.d.ts +1 -0
- package/ts_build/tests/manual/agent-events/event-handler-reliability.test.js +315 -0
- package/ts_build/tests/manual/agent-events/event-handler-reliability.test.js.map +1 -0
- package/ts_build/tests/manual/agent-events/run-test.d.ts +2 -0
- package/ts_build/tests/manual/agent-events/run-test.js +148 -0
- package/ts_build/tests/manual/agent-events/run-test.js.map +1 -0
- package/ts_build/tests/manual/file-edits/figma.test.d.ts +1 -0
- package/ts_build/tests/manual/file-edits/figma.test.js +47 -0
- package/ts_build/tests/manual/file-edits/figma.test.js.map +1 -0
- package/ts_build/tests/manual/file-edits/fileblocks/readwrite.test.d.ts +1 -0
- package/ts_build/tests/manual/file-edits/fileblocks/readwrite.test.js +100 -0
- package/ts_build/tests/manual/file-edits/fileblocks/readwrite.test.js.map +1 -0
- package/ts_build/tests/manual/file-edits/patching.test.d.ts +1 -0
- package/ts_build/tests/manual/file-edits/patching.test.js +119 -0
- package/ts_build/tests/manual/file-edits/patching.test.js.map +1 -0
- package/ts_build/tests/plugins/language/languagePlugin-content-triggers.test.d.ts +1 -0
- package/ts_build/tests/plugins/language/languagePlugin-content-triggers.test.js +277 -0
- package/ts_build/tests/plugins/language/languagePlugin-content-triggers.test.js.map +1 -0
- package/ts_build/tests/plugins/language/languagePlugin-integration.test.d.ts +1 -0
- package/ts_build/tests/plugins/language/languagePlugin-integration.test.js +331 -0
- package/ts_build/tests/plugins/language/languagePlugin-integration.test.js.map +1 -0
- package/ts_build/tests/plugins/language/languagePlugin.test.d.ts +1 -0
- package/ts_build/tests/plugins/language/languagePlugin.test.js +286 -0
- package/ts_build/tests/plugins/language/languagePlugin.test.js.map +1 -0
- package/ts_build/tests/processors/Base64ImageDetector.test.d.ts +1 -0
- package/ts_build/tests/processors/Base64ImageDetector.test.js +351 -0
- package/ts_build/tests/processors/Base64ImageDetector.test.js.map +1 -0
- package/ts_build/tests/processors/CustomVariables.test.d.ts +1 -0
- package/ts_build/tests/processors/CustomVariables.test.js +351 -0
- package/ts_build/tests/processors/CustomVariables.test.js.map +1 -0
- package/ts_build/tests/processors/HarmonyToolProcessor.test.d.ts +1 -0
- package/ts_build/tests/processors/HarmonyToolProcessor.test.js +382 -0
- package/ts_build/tests/processors/HarmonyToolProcessor.test.js.map +1 -0
- package/ts_build/tests/processors/TokenCompressor.test.d.ts +1 -0
- package/ts_build/tests/processors/TokenCompressor.test.js +300 -0
- package/ts_build/tests/processors/TokenCompressor.test.js.map +1 -0
- package/ts_build/tests/processors/ToolResponseCache.test.d.ts +1 -0
- package/ts_build/tests/processors/ToolResponseCache.test.js +539 -0
- package/ts_build/tests/processors/ToolResponseCache.test.js.map +1 -0
- package/ts_build/tests/services/Plugins/plugin-event-integration.test.d.ts +1 -0
- package/ts_build/tests/services/Plugins/plugin-event-integration.test.js +232 -0
- package/ts_build/tests/services/Plugins/plugin-event-integration.test.js.map +1 -0
- package/ts_build/tests/services/Tools.test.d.ts +1 -0
- package/ts_build/tests/services/Tools.test.js +1059 -0
- package/ts_build/tests/services/Tools.test.js.map +1 -0
- package/ts_build/tests/test.spec.js +110 -68
- package/ts_build/tests/test.spec.js.map +1 -1
- package/ts_build/tests/tree-sitter/editor.test.d.ts +1 -0
- package/ts_build/tests/tree-sitter/editor.test.js +85 -0
- package/ts_build/tests/tree-sitter/editor.test.js.map +1 -0
- package/ts_build/tests/tree-sitter/invalid.test.d.ts +1 -0
- package/ts_build/tests/tree-sitter/invalid.test.js +198 -0
- package/ts_build/tests/tree-sitter/invalid.test.js.map +1 -0
- package/ts_build/tests/tree-sitter/paths/common-edits.test.d.ts +1 -0
- package/ts_build/tests/tree-sitter/paths/common-edits.test.js +347 -0
- package/ts_build/tests/tree-sitter/paths/common-edits.test.js.map +1 -0
- package/ts_build/tests/tree-sitter/paths/debug-exact-position.test.d.ts +1 -0
- package/ts_build/tests/tree-sitter/paths/debug-exact-position.test.js +35 -0
- package/ts_build/tests/tree-sitter/paths/debug-exact-position.test.js.map +1 -0
- package/ts_build/tests/tree-sitter/paths/debug-line-indexing.test.d.ts +1 -0
- package/ts_build/tests/tree-sitter/paths/debug-line-indexing.test.js +38 -0
- package/ts_build/tests/tree-sitter/paths/debug-line-indexing.test.js.map +1 -0
- package/ts_build/tests/tree-sitter/paths/debug-paths.test.d.ts +1 -0
- package/ts_build/tests/tree-sitter/paths/debug-paths.test.js +74 -0
- package/ts_build/tests/tree-sitter/paths/debug-paths.test.js.map +1 -0
- package/ts_build/tests/tree-sitter/paths/human-readable-paths.test.d.ts +1 -0
- package/ts_build/tests/tree-sitter/paths/human-readable-paths.test.js +302 -0
- package/ts_build/tests/tree-sitter/paths/human-readable-paths.test.js.map +1 -0
- package/ts_build/tests/tree-sitter/paths/paths.test.d.ts +1 -0
- package/ts_build/tests/tree-sitter/paths/paths.test.js +116 -0
- package/ts_build/tests/tree-sitter/paths/paths.test.js.map +1 -0
- package/ts_build/tests/tree-sitter/paths/simple-paths.test.d.ts +1 -0
- package/ts_build/tests/tree-sitter/paths/simple-paths.test.js +302 -0
- package/ts_build/tests/tree-sitter/paths/simple-paths.test.js.map +1 -0
- package/ts_build/tests/tree-sitter/sample-after.d.ts +11 -0
- package/ts_build/tests/tree-sitter/sample-after.js +44 -0
- package/ts_build/tests/tree-sitter/sample-after.js.map +1 -0
- package/ts_build/tests/tree-sitter/sample-before.d.ts +9 -0
- package/ts_build/tests/tree-sitter/sample-before.js +28 -0
- package/ts_build/tests/tree-sitter/sample-before.js.map +1 -0
- package/ts_build/tests/tree-sitter/test-files/completely-broken.d.ts +2 -0
- package/ts_build/tests/tree-sitter/test-files/completely-broken.js +17 -0
- package/ts_build/tests/tree-sitter/test-files/completely-broken.js.map +1 -0
- package/ts_build/tests/tree-sitter/test-files/duplicate-braces.d.ts +8 -0
- package/ts_build/tests/tree-sitter/test-files/duplicate-braces.js +38 -0
- package/ts_build/tests/tree-sitter/test-files/duplicate-braces.js.map +1 -0
- package/ts_build/tests/tree-sitter/test-files/invalid-nesting.d.ts +8 -0
- package/ts_build/tests/tree-sitter/test-files/invalid-nesting.js +38 -0
- package/ts_build/tests/tree-sitter/test-files/invalid-nesting.js.map +1 -0
- package/ts_build/tests/tree-sitter/test-files/malformed-signature.d.ts +8 -0
- package/ts_build/tests/tree-sitter/test-files/malformed-signature.js +38 -0
- package/ts_build/tests/tree-sitter/test-files/malformed-signature.js.map +1 -0
- package/ts_build/tests/tree-sitter/test-files/mismatched-parens.d.ts +10 -0
- package/ts_build/tests/tree-sitter/test-files/mismatched-parens.js +38 -0
- package/ts_build/tests/tree-sitter/test-files/mismatched-parens.js.map +1 -0
- package/ts_build/tests/tree-sitter/test-files/missing-semicolon.d.ts +8 -0
- package/ts_build/tests/tree-sitter/test-files/missing-semicolon.js +38 -0
- package/ts_build/tests/tree-sitter/test-files/missing-semicolon.js.map +1 -0
- package/ts_build/tests/tree-sitter/test-files/partially-broken.d.ts +6 -0
- package/ts_build/tests/tree-sitter/test-files/partially-broken.js +20 -0
- package/ts_build/tests/tree-sitter/test-files/partially-broken.js.map +1 -0
- package/ts_build/tests/tree-sitter/test-files/specific-errors.d.ts +7 -0
- package/ts_build/tests/tree-sitter/test-files/specific-errors.js +14 -0
- package/ts_build/tests/tree-sitter/test-files/specific-errors.js.map +1 -0
- package/ts_build/tests/tree-sitter/test-files/unclosed-string.d.ts +8 -0
- package/ts_build/tests/tree-sitter/test-files/unclosed-string.js +38 -0
- package/ts_build/tests/tree-sitter/test-files/unclosed-string.js.map +1 -0
- package/ts_build/tests/tree-sitter/tree-sitter.test.d.ts +1 -0
- package/ts_build/tests/tree-sitter/tree-sitter.test.js +185 -0
- package/ts_build/tests/tree-sitter/tree-sitter.test.js.map +1 -0
- package/tsconfig.json +2 -1
- package/tests/languagePlugin.test.ts +0 -74
- /package/src/chat/modules/{index.js → index.ts} +0 -0
- /package/tests/{integration → manual/file-edits}/patching/input.txt +0 -0
- /package/tests/{integration → manual/file-edits}/patching/output.txt +0 -0
- /package/tests/{integration → manual/file-edits}/patching/patch.txt +0 -0
- /package/tests/{integration → manual/file-edits}/patching/unseen.txt +0 -0
|
@@ -41,7 +41,7 @@ export class ToolResponseCache {
|
|
|
41
41
|
/**
|
|
42
42
|
* Recursively searches for JSON strings within an object and parses them
|
|
43
43
|
*/
|
|
44
|
-
|
|
44
|
+
public parseNestedJsonStrings(obj: any): any {
|
|
45
45
|
if (typeof obj === "string") {
|
|
46
46
|
const parsed = this.tryParseJson(obj);
|
|
47
47
|
if (parsed) {
|
|
@@ -68,7 +68,7 @@ export class ToolResponseCache {
|
|
|
68
68
|
/**
|
|
69
69
|
* Stores a tool response for later manipulation
|
|
70
70
|
*/
|
|
71
|
-
|
|
71
|
+
public storeToolResponse(content: string, toolCallId: string): void {
|
|
72
72
|
// Always store the original content for later JQ manipulation
|
|
73
73
|
this.storage[toolCallId] = content;
|
|
74
74
|
|
|
@@ -130,17 +130,26 @@ export class ToolResponseCache {
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
try {
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
|
|
134
|
+
// First parse the stored string as JSON, then handle nested JSON strings
|
|
135
|
+
const jsonData = this.tryParseJson(data);
|
|
136
|
+
if (!jsonData) {
|
|
137
|
+
return `Error: Tool response data is not valid JSON for toolCallId "${toolCallId}"`;
|
|
138
|
+
}
|
|
139
|
+
const parsedData = this.parseNestedJsonStrings(jsonData);
|
|
135
140
|
|
|
136
141
|
// Execute JQ query
|
|
137
142
|
const result = await jq.run(jqQuery, parsedData, { input: "json" });
|
|
138
143
|
|
|
139
|
-
//
|
|
144
|
+
// Handle the result based on its type
|
|
140
145
|
if (typeof result === "string") {
|
|
141
146
|
return result;
|
|
147
|
+
} else if (typeof result === "number" || typeof result === "boolean") {
|
|
148
|
+
return String(result);
|
|
149
|
+
} else if (result === null) {
|
|
150
|
+
return "null";
|
|
142
151
|
} else {
|
|
143
|
-
return JSON.stringify(result
|
|
152
|
+
return JSON.stringify(result);
|
|
144
153
|
}
|
|
145
154
|
} catch (error: any) {
|
|
146
155
|
// If JQ fails, try to provide helpful error message
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import * as path from "path";
|
|
2
|
+
import { globSync } from "glob";
|
|
3
|
+
|
|
1
4
|
import {
|
|
2
5
|
Config,
|
|
3
6
|
Embeddable,
|
|
@@ -13,10 +16,8 @@ import {
|
|
|
13
16
|
cosineSimilarity,
|
|
14
17
|
} from "../utils";
|
|
15
18
|
import { summarizeTexts, chunkText } from "../ai";
|
|
16
|
-
import { Plugins } from "../plugins/plugins";
|
|
17
19
|
import { Clients, GenericClient } from "../clients";
|
|
18
|
-
import
|
|
19
|
-
import glob from "glob";
|
|
20
|
+
import { PluginService } from "..//plugins/plugins";
|
|
20
21
|
|
|
21
22
|
export type CreateEmbeddingOptions = {
|
|
22
23
|
provider?: string;
|
|
@@ -31,13 +32,21 @@ export type EmbedOptions = {
|
|
|
31
32
|
minLength?: number;
|
|
32
33
|
};
|
|
33
34
|
|
|
35
|
+
interface EmbeddingServiceContext {
|
|
36
|
+
config: Config;
|
|
37
|
+
embeddingClient?: GenericClient;
|
|
38
|
+
plugins: PluginService;
|
|
39
|
+
}
|
|
40
|
+
|
|
34
41
|
export class EmbeddingService {
|
|
35
42
|
private config: Config;
|
|
36
43
|
private embeddingClient: GenericClient;
|
|
44
|
+
private plugins: PluginService;
|
|
37
45
|
|
|
38
|
-
constructor(
|
|
39
|
-
this.config = config;
|
|
40
|
-
this.embeddingClient = embeddingClient;
|
|
46
|
+
constructor(protected context: EmbeddingServiceContext) {
|
|
47
|
+
this.config = context.config;
|
|
48
|
+
this.embeddingClient = context.embeddingClient;
|
|
49
|
+
this.plugins = context.plugins;
|
|
41
50
|
}
|
|
42
51
|
|
|
43
52
|
setEmbeddingClient(client: GenericClient) {
|
|
@@ -102,7 +111,7 @@ export class EmbeddingService {
|
|
|
102
111
|
}
|
|
103
112
|
|
|
104
113
|
console.log("Embedding", source.input, "to", source.output);
|
|
105
|
-
let files = await
|
|
114
|
+
let files = await globSync(source.input, { ignore: ignorePattern });
|
|
106
115
|
|
|
107
116
|
if (source.kind && files.length === 0) {
|
|
108
117
|
files = [source.input];
|
|
@@ -193,9 +202,9 @@ export class EmbeddingService {
|
|
|
193
202
|
const contents = "";
|
|
194
203
|
const ids = [];
|
|
195
204
|
|
|
196
|
-
if (
|
|
205
|
+
if (this.plugins.isPlugin(kind)) {
|
|
197
206
|
console.log("Embedding with plugin", kind);
|
|
198
|
-
return
|
|
207
|
+
return this.plugins.embed(kind, input);
|
|
199
208
|
}
|
|
200
209
|
switch (kind) {
|
|
201
210
|
case "text":
|
|
@@ -1,11 +1,91 @@
|
|
|
1
1
|
import { EventEmitter } from "events";
|
|
2
2
|
import { IAgent } from "../agents/interface";
|
|
3
3
|
|
|
4
|
+
export interface EventHandler {
|
|
5
|
+
handler: (...args: any[]) => any;
|
|
6
|
+
}
|
|
7
|
+
|
|
4
8
|
export class EventService extends EventEmitter {
|
|
9
|
+
private blockingHandlers: Map<string, EventHandler[]> = new Map();
|
|
10
|
+
|
|
5
11
|
constructor() {
|
|
6
12
|
super();
|
|
7
13
|
}
|
|
8
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Register an event handler as blocking or non-blocking
|
|
17
|
+
* @param event The event name
|
|
18
|
+
* @param handler The event handler function
|
|
19
|
+
* @param isBlocking Whether this handler should be blocking
|
|
20
|
+
*/
|
|
21
|
+
onBlocking(event: string, handler: (...args: any[]) => any): void {
|
|
22
|
+
if (!this.blockingHandlers.has(event)) {
|
|
23
|
+
this.blockingHandlers.set(event, []);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
this.blockingHandlers.get(event)!.push({ handler });
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Emit a blocking event - if any blocking handler throws, execution stops
|
|
31
|
+
* @param event The event name
|
|
32
|
+
* @param args Arguments to pass to handlers
|
|
33
|
+
* @returns Promise that resolves with array of handler results when all handlers complete, or rejects if any blocking handler throws
|
|
34
|
+
*/
|
|
35
|
+
async emitBlocking(event: string, ...args: any[]): Promise<any[]> {
|
|
36
|
+
const results: any[] = [];
|
|
37
|
+
|
|
38
|
+
const handlers = this.blockingHandlers.get(event) || [];
|
|
39
|
+
|
|
40
|
+
for (const { handler } of handlers) {
|
|
41
|
+
try {
|
|
42
|
+
const result = handler(...args);
|
|
43
|
+
if (result instanceof Promise) {
|
|
44
|
+
const awaitedResult = await result;
|
|
45
|
+
results.push(awaitedResult);
|
|
46
|
+
} else {
|
|
47
|
+
results.push(result);
|
|
48
|
+
}
|
|
49
|
+
} catch (error) {
|
|
50
|
+
// If this is a blocking handler and it throws, stop execution
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
this.emit(event, ...args);
|
|
56
|
+
return results.filter((r) => Boolean(r));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Emit a non-blocking event - all handlers run, errors are logged but don't stop execution
|
|
61
|
+
* @param event The event name
|
|
62
|
+
* @param args Arguments to pass to handlers
|
|
63
|
+
* @returns Promise that resolves with array of handler results when all handlers complete
|
|
64
|
+
*/
|
|
65
|
+
async emitNonBlocking(event: string, ...args: any[]): Promise<any[]> {
|
|
66
|
+
const handlers = this.blockingHandlers.get(event) || [];
|
|
67
|
+
const results: any[] = [];
|
|
68
|
+
for (const { handler } of handlers) {
|
|
69
|
+
try {
|
|
70
|
+
const result = handler(...args);
|
|
71
|
+
if (result instanceof Promise) {
|
|
72
|
+
const awaitedResult = await result;
|
|
73
|
+
results.push(awaitedResult);
|
|
74
|
+
} else {
|
|
75
|
+
results.push(result);
|
|
76
|
+
}
|
|
77
|
+
} catch (error) {
|
|
78
|
+
console.error(
|
|
79
|
+
`Non-blocking handler error for event '${event}':`,
|
|
80
|
+
error
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
this.emit(event, ...args);
|
|
86
|
+
return results.filter((r) => Boolean(r));
|
|
87
|
+
}
|
|
88
|
+
|
|
9
89
|
registerAgent(agent: IAgent): void {
|
|
10
90
|
this.emit("agents:register", { name: agent.name, agent });
|
|
11
91
|
}
|
package/src/services/Mcp.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js"
|
|
|
2
2
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
3
3
|
import Anthropic from "@anthropic-ai/sdk";
|
|
4
4
|
|
|
5
|
+
import fs from "fs";
|
|
5
6
|
import { McpConfig } from "../types";
|
|
6
7
|
import { Tool } from "../clients";
|
|
7
8
|
import { getConfig } from "../config";
|
|
@@ -79,6 +80,10 @@ export class McpService {
|
|
|
79
80
|
}
|
|
80
81
|
if (mcp.url) {
|
|
81
82
|
// TODO: also support refresh tokens
|
|
83
|
+
if (mcp.authorization_token_file) {
|
|
84
|
+
const token = fs.readFileSync(mcp.authorization_token_file, "utf-8");
|
|
85
|
+
mcp.authorization_token = token.trim();
|
|
86
|
+
}
|
|
82
87
|
return new StreamableHTTPClientTransport(new URL(mcp.url), {
|
|
83
88
|
requestInit: {
|
|
84
89
|
headers: {
|
package/src/services/S3.ts
CHANGED
|
@@ -8,7 +8,8 @@ import {
|
|
|
8
8
|
PutObjectCommandInput,
|
|
9
9
|
} from "@aws-sdk/client-s3";
|
|
10
10
|
|
|
11
|
-
import fs from "fs
|
|
11
|
+
import * as fs from "fs";
|
|
12
|
+
const fsPromises = fs.promises;
|
|
12
13
|
import { createWriteStream } from "fs";
|
|
13
14
|
import * as path from "path";
|
|
14
15
|
import { pipeline } from "stream";
|
|
@@ -30,7 +31,7 @@ export class S3Service {
|
|
|
30
31
|
bucketName: string,
|
|
31
32
|
key: string
|
|
32
33
|
): Promise<void> {
|
|
33
|
-
const fileContent = await
|
|
34
|
+
const fileContent = await fsPromises.readFile(filePath);
|
|
34
35
|
|
|
35
36
|
const params = {
|
|
36
37
|
Bucket: bucketName,
|
|
@@ -80,7 +81,7 @@ export class S3Service {
|
|
|
80
81
|
): Promise<void> {
|
|
81
82
|
try {
|
|
82
83
|
const fileStream = createReadStream(filePath);
|
|
83
|
-
const fileStats = await
|
|
84
|
+
const fileStats = await fsPromises.stat(filePath);
|
|
84
85
|
|
|
85
86
|
const response = await axios.put(presignedUrl, fileStream, {
|
|
86
87
|
headers: {
|
package/src/services/Tools.ts
CHANGED
|
@@ -82,49 +82,30 @@ export class ToolsService {
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
getFunction(name: string) {
|
|
85
|
-
//
|
|
85
|
+
// Apply overrides and wrappers before returning (even if no base function exists)
|
|
86
|
+
if (this.functions[name] || this.originalFunctions[name]) {
|
|
87
|
+
this.applyOverridesAndWrappers(name);
|
|
88
|
+
} else {
|
|
89
|
+
// Check if there are overrides for this name even without a base function
|
|
90
|
+
const matchingOverride = this.findMatchingOverride(name);
|
|
91
|
+
if (matchingOverride) {
|
|
92
|
+
this.functions[name] = matchingOverride.override;
|
|
93
|
+
} else {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
86
97
|
return this.functions[name];
|
|
87
98
|
}
|
|
88
99
|
|
|
89
100
|
setFunction(name: string, func: (...args: any) => any) {
|
|
90
101
|
// Store original function if not already stored
|
|
91
102
|
if (!this.originalFunctions[name]) {
|
|
92
|
-
this.originalFunctions[name] = func;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// Auto-bind function to this ToolsService instance
|
|
96
|
-
const boundFunc = func.bind(this);
|
|
97
|
-
|
|
98
|
-
// Check for overrides first
|
|
99
|
-
const override = this.findMatchingOverride(name);
|
|
100
|
-
if (override) {
|
|
101
|
-
this.functions[name] = async (...args: any[]) => {
|
|
102
|
-
const tool = this.getTool(name);
|
|
103
|
-
return await override.override(args, tool);
|
|
104
|
-
};
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// Check for wrappers
|
|
109
|
-
const wrappers = this.findMatchingWrappers(name);
|
|
110
|
-
if (wrappers.length > 0) {
|
|
111
|
-
let wrappedFunction = boundFunc;
|
|
112
|
-
|
|
113
|
-
// Apply wrappers in priority order
|
|
114
|
-
for (const wrapperReg of wrappers) {
|
|
115
|
-
const currentFunction = wrappedFunction;
|
|
116
|
-
wrappedFunction = async (...args: any[]) => {
|
|
117
|
-
const tool = this.getTool(name);
|
|
118
|
-
return await wrapperReg.wrapper(currentFunction, args, tool);
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
this.functions[name] = wrappedFunction;
|
|
123
|
-
return;
|
|
103
|
+
this.originalFunctions[name] = func.bind(this);
|
|
124
104
|
}
|
|
125
105
|
|
|
126
|
-
//
|
|
127
|
-
this.functions[name] =
|
|
106
|
+
// Set the function (bound) and apply any overrides/wrappers
|
|
107
|
+
this.functions[name] = func.bind(this);
|
|
108
|
+
this.applyOverridesAndWrappers(name);
|
|
128
109
|
}
|
|
129
110
|
|
|
130
111
|
setFunctions(names: string[], funcs: ((...args: any) => any)[]) {
|
|
@@ -167,12 +148,20 @@ export class ToolsService {
|
|
|
167
148
|
|
|
168
149
|
async callTool(toolCall: ToolCall, enabledTools = this.getToolNames()) {
|
|
169
150
|
const functionName = toolCall.function.name;
|
|
170
|
-
|
|
171
|
-
typeof toolCall.function.arguments === "string"
|
|
172
|
-
? JSON.parse(restoreEscapedNewLines(toolCall.function.arguments))
|
|
173
|
-
: toolCall.function.arguments;
|
|
151
|
+
let functionArgs: any;
|
|
174
152
|
|
|
175
153
|
try {
|
|
154
|
+
try {
|
|
155
|
+
functionArgs =
|
|
156
|
+
typeof toolCall.function.arguments === "string"
|
|
157
|
+
? JSON.parse(restoreEscapedNewLines(toolCall.function.arguments))
|
|
158
|
+
: toolCall.function.arguments;
|
|
159
|
+
} catch (error) {
|
|
160
|
+
throw new Error(
|
|
161
|
+
`Invalid JSON in tool call arguments: ${error.message}`
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
176
165
|
// Check if tool is enabled
|
|
177
166
|
if (!enabledTools.includes(functionName)) {
|
|
178
167
|
const options = enabledTools.join(", ");
|
|
@@ -204,20 +193,22 @@ export class ToolsService {
|
|
|
204
193
|
? Object.keys(properties).map((p) => functionArgs[p])
|
|
205
194
|
: functionArgs;
|
|
206
195
|
|
|
207
|
-
console.log(
|
|
208
|
-
`Calling function ${functionName} with args:`,
|
|
209
|
-
JSON.stringify(fnArgs, null, 2)
|
|
210
|
-
);
|
|
211
|
-
|
|
212
196
|
// Execute the function
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
197
|
+
const rawResponse = isPositional
|
|
198
|
+
? functionToCall.call(this, ...fnArgs)
|
|
199
|
+
: functionToCall.call(this, fnArgs);
|
|
200
|
+
const functionResponse = await Promise.resolve(rawResponse).catch((e) => {
|
|
216
201
|
throw new Error("ERROR: " + e.message);
|
|
217
202
|
});
|
|
218
203
|
|
|
219
204
|
// Helper function to convert objects to JSON
|
|
220
205
|
const toJsonIfObject = (arg: any) => {
|
|
206
|
+
if (arg === null) {
|
|
207
|
+
return "null";
|
|
208
|
+
}
|
|
209
|
+
if (arg === undefined) {
|
|
210
|
+
return "undefined";
|
|
211
|
+
}
|
|
221
212
|
if (typeof arg === "object") {
|
|
222
213
|
return JSON.stringify(arg, null, 2);
|
|
223
214
|
}
|
|
@@ -228,14 +219,18 @@ export class ToolsService {
|
|
|
228
219
|
|
|
229
220
|
// Handle special case for parallel tool use
|
|
230
221
|
if (functionName === "multi_tool_use.parallel") {
|
|
231
|
-
|
|
222
|
+
// Extract tool_calls array from arguments
|
|
223
|
+
const toolCallsArg = Array.isArray(fnArgs) ? fnArgs : [fnArgs];
|
|
224
|
+
const toolCalls = Array.isArray(toolCallsArg) ? toolCallsArg : [];
|
|
225
|
+
|
|
226
|
+
const calls = toolCalls as {
|
|
232
227
|
recipient_name: string;
|
|
233
228
|
parameters: any;
|
|
234
229
|
}[];
|
|
235
230
|
|
|
236
|
-
toolMessages =
|
|
231
|
+
toolMessages = calls.map((call, index) => {
|
|
237
232
|
return {
|
|
238
|
-
tool_call_id:
|
|
233
|
+
tool_call_id: `call_parallel_${index}`,
|
|
239
234
|
role: "tool",
|
|
240
235
|
name: call.recipient_name.split(".").pop(),
|
|
241
236
|
content: toJsonIfObject(functionResponse[index]) || "Done",
|
|
@@ -257,7 +252,7 @@ export class ToolsService {
|
|
|
257
252
|
toolCallId: toolCall.id,
|
|
258
253
|
functionName,
|
|
259
254
|
functionArgs,
|
|
260
|
-
functionResp: functionResponse,
|
|
255
|
+
functionResp: functionResponse || "Done",
|
|
261
256
|
};
|
|
262
257
|
} catch (error) {
|
|
263
258
|
console.log(error.message);
|
|
@@ -288,6 +283,13 @@ export class ToolsService {
|
|
|
288
283
|
): void {
|
|
289
284
|
this.overrides.push({ pattern, override, priority });
|
|
290
285
|
this.overrides.sort((a, b) => b.priority - a.priority);
|
|
286
|
+
|
|
287
|
+
// Re-apply overrides to existing functions
|
|
288
|
+
for (const toolName of this.getToolNames()) {
|
|
289
|
+
if (this.functions[toolName]) {
|
|
290
|
+
this.applyOverridesAndWrappers(toolName);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
291
293
|
}
|
|
292
294
|
|
|
293
295
|
registerWrapper(
|
|
@@ -296,27 +298,97 @@ export class ToolsService {
|
|
|
296
298
|
priority: number = 0
|
|
297
299
|
): void {
|
|
298
300
|
this.wrappers.push({ pattern, wrapper, priority });
|
|
301
|
+
|
|
302
|
+
// Sort wrappers by priority first
|
|
299
303
|
this.wrappers.sort((a, b) => b.priority - a.priority);
|
|
304
|
+
|
|
305
|
+
// Re-apply wrappers to existing functions
|
|
306
|
+
for (const toolName of this.getToolNames()) {
|
|
307
|
+
if (this.functions[toolName]) {
|
|
308
|
+
this.applyOverridesAndWrappers(toolName);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
300
311
|
}
|
|
301
312
|
|
|
302
313
|
removeOverride(pattern: string | RegExp): void {
|
|
303
314
|
this.overrides = this.overrides.filter((reg) => reg.pattern !== pattern);
|
|
315
|
+
// Re-apply functions after removing override
|
|
316
|
+
for (const toolName of this.getToolNames()) {
|
|
317
|
+
if (this.originalFunctions[toolName]) {
|
|
318
|
+
this.setFunction(toolName, this.originalFunctions[toolName]);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
304
321
|
}
|
|
305
322
|
|
|
306
323
|
removeWrapper(pattern: string | RegExp): void {
|
|
307
324
|
this.wrappers = this.wrappers.filter((reg) => reg.pattern !== pattern);
|
|
325
|
+
// Re-apply functions after removing wrapper
|
|
326
|
+
for (const toolName of this.getToolNames()) {
|
|
327
|
+
if (this.originalFunctions[toolName]) {
|
|
328
|
+
this.setFunction(toolName, this.originalFunctions[toolName]);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
private applyOverridesAndWrappers(name: string): void {
|
|
334
|
+
if (!this.originalFunctions[name]) {
|
|
335
|
+
// Store original function if not already stored
|
|
336
|
+
this.originalFunctions[name] = this.functions[name];
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const originalFunc = this.originalFunctions[name];
|
|
340
|
+
|
|
341
|
+
// Check for overrides first
|
|
342
|
+
const matchingOverride = this.findMatchingOverride(name);
|
|
343
|
+
if (matchingOverride) {
|
|
344
|
+
// Create a wrapper function that calls the override with correct arguments
|
|
345
|
+
this.functions[name] = ((...args: any[]) => {
|
|
346
|
+
// Call the override function with originalArgs array and tool definition
|
|
347
|
+
const toolDefinition = this.getTool(name);
|
|
348
|
+
// Override functions expect (originalArgs: any[], originalTool: Tool)
|
|
349
|
+
return matchingOverride.override.call(this, args, toolDefinition);
|
|
350
|
+
}).bind(this);
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// Check for wrappers
|
|
355
|
+
const wrappers = this.findMatchingWrappers(name);
|
|
356
|
+
if (wrappers.length > 0) {
|
|
357
|
+
let wrappedFunction = originalFunc;
|
|
358
|
+
|
|
359
|
+
// Apply wrappers in priority order
|
|
360
|
+
for (const wrapperReg of wrappers) {
|
|
361
|
+
const innerFunc = wrappedFunction;
|
|
362
|
+
wrappedFunction = ((args: any) => {
|
|
363
|
+
const toolDefinition = this.getTool(name);
|
|
364
|
+
return wrapperReg.wrapper(innerFunc, args, toolDefinition);
|
|
365
|
+
}).bind(this);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
this.functions[name] = wrappedFunction.bind(this);
|
|
369
|
+
} else {
|
|
370
|
+
// No wrappers, use current function (might be override or original)
|
|
371
|
+
this.functions[name] = originalFunc;
|
|
372
|
+
}
|
|
308
373
|
}
|
|
309
374
|
|
|
310
375
|
private findMatchingOverride(
|
|
311
376
|
toolName: string
|
|
312
377
|
): ToolOverrideRegistration | null {
|
|
378
|
+
let bestMatch: ToolOverrideRegistration | null = null;
|
|
379
|
+
let highestPriority = -1;
|
|
380
|
+
|
|
313
381
|
for (const registration of this.overrides) {
|
|
314
382
|
const matcher = createPatternMatcher(registration.pattern);
|
|
315
383
|
if (matcher.matches(toolName)) {
|
|
316
|
-
|
|
384
|
+
if (registration.priority > highestPriority) {
|
|
385
|
+
highestPriority = registration.priority;
|
|
386
|
+
bestMatch = registration;
|
|
387
|
+
}
|
|
317
388
|
}
|
|
318
389
|
}
|
|
319
|
-
|
|
390
|
+
|
|
391
|
+
return bestMatch;
|
|
320
392
|
}
|
|
321
393
|
|
|
322
394
|
private findMatchingWrappers(toolName: string): ToolWrapperRegistration[] {
|
package/src/services/index.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { DownloaderService } from "../plugins/downloader/downloader";
|
|
2
|
-
import { Clients } from "../clients";
|
|
3
|
-
import { Plugins } from "../plugins/plugins";
|
|
2
|
+
import { AIClient, Clients } from "../clients";
|
|
4
3
|
import { AgentService } from "./AgentService";
|
|
5
4
|
import { EventService } from "./EventService";
|
|
6
5
|
import { FlagsService } from "./flags";
|
|
@@ -9,6 +8,7 @@ import { KnowhowSimpleClient } from "./KnowhowClient";
|
|
|
9
8
|
import { McpService } from "./Mcp";
|
|
10
9
|
import { S3Service } from "./S3";
|
|
11
10
|
import { ToolsService } from "./Tools";
|
|
11
|
+
import { PluginService } from "../plugins/plugins";
|
|
12
12
|
|
|
13
13
|
export * from "./AgentService";
|
|
14
14
|
export * from "./EventService";
|
|
@@ -19,7 +19,6 @@ export * from "./Tools";
|
|
|
19
19
|
export * as MCP from "./Mcp";
|
|
20
20
|
export * from "./EmbeddingService";
|
|
21
21
|
export { Clients } from "../clients";
|
|
22
|
-
export { Plugins };
|
|
23
22
|
|
|
24
23
|
let Singletons = {} as {
|
|
25
24
|
Tools: ToolsService;
|
|
@@ -30,8 +29,8 @@ let Singletons = {} as {
|
|
|
30
29
|
Mcp: McpService;
|
|
31
30
|
AwsS3: S3Service;
|
|
32
31
|
knowhowApiClient: KnowhowSimpleClient;
|
|
33
|
-
Plugins:
|
|
34
|
-
Clients:
|
|
32
|
+
Plugins: PluginService;
|
|
33
|
+
Clients: AIClient;
|
|
35
34
|
Downloader: DownloaderService;
|
|
36
35
|
};
|
|
37
36
|
|
|
@@ -41,19 +40,25 @@ export const services = (): typeof Singletons => {
|
|
|
41
40
|
const Events = new EventService();
|
|
42
41
|
const Agents = new AgentService(Tools, Events);
|
|
43
42
|
const Downloader = new DownloaderService(Clients);
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
const Plugins = new PluginService({
|
|
44
|
+
Agents,
|
|
46
45
|
Events,
|
|
46
|
+
Tools,
|
|
47
|
+
Clients,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
Singletons = {
|
|
47
51
|
Agents,
|
|
52
|
+
AwsS3: new S3Service(),
|
|
53
|
+
Clients,
|
|
48
54
|
Downloader,
|
|
49
|
-
|
|
55
|
+
Events,
|
|
50
56
|
Flags: new FlagsService(),
|
|
51
57
|
GitHub: new GitHubService(),
|
|
52
58
|
Mcp: new McpService(),
|
|
53
|
-
AwsS3: new S3Service(),
|
|
54
|
-
knowhowApiClient: new KnowhowSimpleClient(process.env.KNOWHOW_API_URL),
|
|
55
59
|
Plugins,
|
|
56
|
-
|
|
60
|
+
Tools,
|
|
61
|
+
knowhowApiClient: new KnowhowSimpleClient(process.env.KNOWHOW_API_URL),
|
|
57
62
|
};
|
|
58
63
|
|
|
59
64
|
Singletons.Tools.setContext({
|
package/src/services/types.ts
CHANGED
|
@@ -34,9 +34,9 @@ export class StringPatternMatcher implements PatternMatcher {
|
|
|
34
34
|
matches(toolName: string): boolean {
|
|
35
35
|
// Convert glob pattern to regex
|
|
36
36
|
const regexPattern = this.pattern
|
|
37
|
-
.replace(/[
|
|
38
|
-
.replace(
|
|
39
|
-
.replace(
|
|
37
|
+
.replace(/[.+^${}()|[\]\\]/g, "\\$&") // Escape special regex chars except * and ?
|
|
38
|
+
.replace(/\*/g, ".*") // Convert * to .*
|
|
39
|
+
.replace(/\?/g, "."); // Convert ? to .
|
|
40
40
|
|
|
41
41
|
const regex = new RegExp(`^${regexPattern}$`);
|
|
42
42
|
return regex.test(toolName);
|
package/src/types.ts
CHANGED
|
@@ -57,7 +57,7 @@ export type Config = {
|
|
|
57
57
|
enabled?: boolean;
|
|
58
58
|
installPath?: string;
|
|
59
59
|
port?: number;
|
|
60
|
-
logLevel?:
|
|
60
|
+
logLevel?: "debug" | "info" | "warning" | "error";
|
|
61
61
|
completionTimeout?: number;
|
|
62
62
|
};
|
|
63
63
|
|
|
@@ -82,6 +82,7 @@ export type McpConfig = {
|
|
|
82
82
|
env?: { [key: string]: string };
|
|
83
83
|
params?: Partial<{ socket: WebSocket }>;
|
|
84
84
|
authorization_token?: string;
|
|
85
|
+
authorization_token_file?: string;
|
|
85
86
|
};
|
|
86
87
|
|
|
87
88
|
export type ModelProvider = {
|
|
@@ -122,6 +123,7 @@ export interface IDatasource {
|
|
|
122
123
|
|
|
123
124
|
export type Language = {
|
|
124
125
|
[term: string]: {
|
|
126
|
+
events: string[];
|
|
125
127
|
sources: IDatasource[];
|
|
126
128
|
context?: string;
|
|
127
129
|
};
|
|
@@ -137,6 +139,9 @@ export type ChatInteraction = {
|
|
|
137
139
|
export const Models = {
|
|
138
140
|
anthropic: {
|
|
139
141
|
Opus4: "claude-opus-4-20250514",
|
|
142
|
+
Opus4_1: "claude-opus-4-1-20250805",
|
|
143
|
+
Sonnet4_5: "claude-sonnet-4-5-20250929",
|
|
144
|
+
Haiku4_5: "claude-haiku-4-5-20251001",
|
|
140
145
|
Sonnet4: "claude-sonnet-4-20250514",
|
|
141
146
|
Sonnet3_7: "claude-3-7-sonnet-20250219",
|
|
142
147
|
Sonnet3_5: "claude-3-5-sonnet-20241022",
|
|
@@ -145,6 +150,7 @@ export const Models = {
|
|
|
145
150
|
Haiku3: "claude-3-haiku-20240307",
|
|
146
151
|
},
|
|
147
152
|
xai: {
|
|
153
|
+
GrokCodeFast: "grok-code-fast-1",
|
|
148
154
|
Grok4: "grok-4-0709",
|
|
149
155
|
Grok3Beta: "grok-3-beta",
|
|
150
156
|
Grok3MiniBeta: "grok-3-mini-beta",
|
|
@@ -248,4 +254,3 @@ export const GoogleImageModels = [
|
|
|
248
254
|
export const GoogleVideoModels = [Models.google.Veo_2];
|
|
249
255
|
|
|
250
256
|
export const GoogleEmbeddingModels = [EmbeddingModels.google.Gemini_Embedding];
|
|
251
|
-
|
package/src/worker.ts
CHANGED
|
@@ -68,12 +68,25 @@ export async function worker() {
|
|
|
68
68
|
});
|
|
69
69
|
|
|
70
70
|
mcpServer.runWsServer(ws);
|
|
71
|
+
|
|
72
|
+
return { ws, mcpServer };
|
|
71
73
|
}
|
|
72
74
|
|
|
73
75
|
while (true) {
|
|
76
|
+
let connection: { ws: WebSocket; mcpServer: McpServerService } | null =
|
|
77
|
+
null;
|
|
78
|
+
|
|
74
79
|
if (!connected) {
|
|
75
80
|
console.log("Attempting to connect...");
|
|
76
|
-
connectWebSocket();
|
|
81
|
+
connection = await connectWebSocket();
|
|
82
|
+
}
|
|
83
|
+
if (connection && connected) {
|
|
84
|
+
try {
|
|
85
|
+
await connection.ws.ping();
|
|
86
|
+
} catch (error) {
|
|
87
|
+
console.error("WebSocket ping failed:", error);
|
|
88
|
+
connected = false;
|
|
89
|
+
}
|
|
77
90
|
}
|
|
78
91
|
await wait(5000);
|
|
79
92
|
}
|