@tyvm/knowhow 0.0.47 → 0.0.49
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 +39 -25
- 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 +129 -67
- 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/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 +8 -8
- 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 +60 -70
- package/src/processors/TokenCompressor.ts +15 -14
- package/src/processors/ToolResponseCache.ts +20 -14
- 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 +485 -0
- package/tests/processors/HarmonyToolProcessor.test.ts +490 -0
- package/tests/processors/TokenCompressor.test.ts +390 -0
- package/tests/processors/ToolResponseCache.test.ts +736 -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 +7 -2
- package/ts_build/src/agents/base/base.js +27 -21
- 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 +62 -32
- 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/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 +9 -13
- 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 +45 -47
- package/ts_build/src/processors/CustomVariables.js.map +1 -1
- package/ts_build/src/processors/TokenCompressor.js +10 -13
- 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 +18 -10
- 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 +354 -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 +299 -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 +550 -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
|
@@ -101,18 +101,24 @@ export class CustomVariables {
|
|
|
101
101
|
*/
|
|
102
102
|
private listVariables(): string {
|
|
103
103
|
const variableNames = Object.keys(this.variables);
|
|
104
|
-
|
|
104
|
+
|
|
105
105
|
if (variableNames.length === 0) {
|
|
106
106
|
return "No variables are currently stored.";
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
const variableList = variableNames
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
109
|
+
const variableList = variableNames
|
|
110
|
+
.map((name) => {
|
|
111
|
+
const value = this.variables[name];
|
|
112
|
+
const preview =
|
|
113
|
+
typeof value === "string"
|
|
114
|
+
? value.length > 50
|
|
115
|
+
? value.substring(0, 50) + "..."
|
|
116
|
+
: value
|
|
117
|
+
: JSON.stringify(value).substring(0, 50) +
|
|
118
|
+
(JSON.stringify(value).length > 50 ? "..." : "");
|
|
119
|
+
return `- ${name}: ${preview}`;
|
|
120
|
+
})
|
|
121
|
+
.join("\n");
|
|
116
122
|
|
|
117
123
|
return `Currently stored variables (${variableNames.length}):\n${variableList}`;
|
|
118
124
|
}
|
|
@@ -136,14 +142,28 @@ export class CustomVariables {
|
|
|
136
142
|
}
|
|
137
143
|
|
|
138
144
|
/**
|
|
139
|
-
*
|
|
145
|
+
* Processes a value to substitute {{variableName}} patterns
|
|
140
146
|
*/
|
|
141
147
|
private substituteVariables(
|
|
142
148
|
value: any,
|
|
143
149
|
processedVars: Set<string> = new Set()
|
|
144
150
|
): any {
|
|
145
151
|
if (typeof value === "string") {
|
|
146
|
-
//
|
|
152
|
+
// Check if ALL variables are undefined - if so, return just the error message for the first one
|
|
153
|
+
const variableMatches = value.match(/\{\{([a-zA-Z0-9_]+)\}\}/g);
|
|
154
|
+
if (variableMatches) {
|
|
155
|
+
const allUndefined = variableMatches.every((match) => {
|
|
156
|
+
const varName = match.replace(/[{}]/g, "");
|
|
157
|
+
return !(varName in this.variables);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
if (allUndefined && variableMatches.length > 0) {
|
|
161
|
+
const firstUndefinedVar = variableMatches[0].replace(/[{}]/g, "");
|
|
162
|
+
return `{{ERROR: Variable "${firstUndefinedVar}" is not defined}}`;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Otherwise, proceed with partial substitution
|
|
147
167
|
return value.replace(/\{\{([a-zA-Z0-9_]+)\}\}/g, (match, varName) => {
|
|
148
168
|
// Prevent infinite recursion
|
|
149
169
|
if (processedVars.has(varName)) {
|
|
@@ -156,11 +176,9 @@ export class CustomVariables {
|
|
|
156
176
|
|
|
157
177
|
const varValue = this.variables[varName];
|
|
158
178
|
|
|
159
|
-
//
|
|
179
|
+
// For nested variables, return the raw value without further processing
|
|
160
180
|
if (typeof varValue === "string") {
|
|
161
|
-
|
|
162
|
-
newProcessedVars.add(varName);
|
|
163
|
-
return this.substituteVariables(varValue, newProcessedVars);
|
|
181
|
+
return varValue;
|
|
164
182
|
}
|
|
165
183
|
|
|
166
184
|
// For non-string values, convert to JSON
|
|
@@ -239,62 +257,34 @@ export class CustomVariables {
|
|
|
239
257
|
*/
|
|
240
258
|
private registerTools(toolsService: ToolsService): void {
|
|
241
259
|
// Register setVariable tool
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
return await this.storeToolCallToVariable(
|
|
271
|
-
varName,
|
|
272
|
-
toolName,
|
|
273
|
-
toolArgs
|
|
274
|
-
);
|
|
275
|
-
},
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
// Register listVariables tool
|
|
280
|
-
if (!toolsService.getTool(this.listVariablesToolName)) {
|
|
281
|
-
toolsService.addTool(listVariablesToolDefinition);
|
|
282
|
-
toolsService.addFunctions({
|
|
283
|
-
[this.listVariablesToolName]: () => {
|
|
284
|
-
return this.listVariables();
|
|
285
|
-
},
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
// Register deleteVariable tool
|
|
290
|
-
if (!toolsService.getTool(this.deleteVariableToolName)) {
|
|
291
|
-
toolsService.addTool(deleteVariableToolDefinition);
|
|
292
|
-
toolsService.addFunctions({
|
|
293
|
-
[this.deleteVariableToolName]: (varName: string) => {
|
|
294
|
-
return this.deleteVariable(varName);
|
|
295
|
-
},
|
|
296
|
-
});
|
|
297
|
-
}
|
|
260
|
+
toolsService.addTools([
|
|
261
|
+
setVariableToolDefinition,
|
|
262
|
+
getVariableToolDefinition,
|
|
263
|
+
storeToolCallToVariableDefinition,
|
|
264
|
+
listVariablesToolDefinition,
|
|
265
|
+
deleteVariableToolDefinition,
|
|
266
|
+
]);
|
|
267
|
+
toolsService.addFunctions({
|
|
268
|
+
[this.setVariableToolName]: (name: string, contents: any) => {
|
|
269
|
+
return this.setVariable(name, contents);
|
|
270
|
+
},
|
|
271
|
+
[this.getVariableToolName]: (varName: string) => {
|
|
272
|
+
return this.getVariable(varName);
|
|
273
|
+
},
|
|
274
|
+
[this.storeToolCallToolName]: async (
|
|
275
|
+
varName: string,
|
|
276
|
+
toolName: string,
|
|
277
|
+
toolArgs: string
|
|
278
|
+
) => {
|
|
279
|
+
return await this.storeToolCallToVariable(varName, toolName, toolArgs);
|
|
280
|
+
},
|
|
281
|
+
[this.listVariablesToolName]: () => {
|
|
282
|
+
return this.listVariables();
|
|
283
|
+
},
|
|
284
|
+
[this.deleteVariableToolName]: (varName: string) => {
|
|
285
|
+
return this.deleteVariable(varName);
|
|
286
|
+
},
|
|
287
|
+
});
|
|
298
288
|
}
|
|
299
289
|
|
|
300
290
|
/**
|
|
@@ -54,10 +54,6 @@ export class TokenCompressor {
|
|
|
54
54
|
* Compresses a string into chunks from the end, creating a chain of references
|
|
55
55
|
*/
|
|
56
56
|
public compressStringInChunks(content: string, path: string = ""): string {
|
|
57
|
-
if (path === "" && this.estimateTokens(content) <= this.maxTokens) {
|
|
58
|
-
return content;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
57
|
if (content.length <= this.characterLimit) {
|
|
62
58
|
return content;
|
|
63
59
|
}
|
|
@@ -80,10 +76,14 @@ export class TokenCompressor {
|
|
|
80
76
|
}
|
|
81
77
|
|
|
82
78
|
// Store chunks and create chain of references
|
|
83
|
-
|
|
79
|
+
// First, generate all keys
|
|
80
|
+
for (let i = 0; i < chunks.length; i++) {
|
|
84
81
|
const key = this.generateKey();
|
|
85
|
-
chunkKeys.
|
|
82
|
+
chunkKeys.push(key);
|
|
83
|
+
}
|
|
86
84
|
|
|
85
|
+
// Then store chunks with proper linking
|
|
86
|
+
for (let i = 0; i < chunks.length; i++) {
|
|
87
87
|
let chunkContent = chunks[i];
|
|
88
88
|
|
|
89
89
|
// Add reference to next chunk if it exists
|
|
@@ -92,7 +92,7 @@ export class TokenCompressor {
|
|
|
92
92
|
chunkContent += `\n\n[NEXT_CHUNK_KEY: ${nextKey}]`;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
this.storeString(
|
|
95
|
+
this.storeString(chunkKeys[i], chunkContent);
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
// Return reference to the first chunk
|
|
@@ -114,11 +114,12 @@ export class TokenCompressor {
|
|
|
114
114
|
public compressContent(content: string, path: string = ""): string {
|
|
115
115
|
const tokens = this.estimateTokens(content);
|
|
116
116
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
117
|
+
// For nested properties (path !== ""), use maxTokens to avoid recompressing stored data
|
|
118
|
+
// For top-level content (path === ""), use compressionThreshold to determine compression
|
|
119
|
+
const thresholdToUse =
|
|
120
|
+
path === "" ? this.compressionThreshold : this.maxTokens;
|
|
120
121
|
|
|
121
|
-
if (tokens <=
|
|
122
|
+
if (tokens <= thresholdToUse) {
|
|
122
123
|
return content;
|
|
123
124
|
}
|
|
124
125
|
|
|
@@ -239,7 +240,7 @@ export class TokenCompressor {
|
|
|
239
240
|
|
|
240
241
|
// If not JSON or compression wasn't effective, handle as regular string
|
|
241
242
|
const tokens = this.estimateTokens(obj);
|
|
242
|
-
if (tokens > this.
|
|
243
|
+
if (tokens > this.compressionThreshold) {
|
|
243
244
|
const key = this.generateKey();
|
|
244
245
|
this.storeString(key, obj);
|
|
245
246
|
|
|
@@ -320,8 +321,8 @@ export class TokenCompressor {
|
|
|
320
321
|
}
|
|
321
322
|
|
|
322
323
|
registerTool(toolsService?: ToolsService): void {
|
|
323
|
-
if (toolsService
|
|
324
|
-
toolsService.
|
|
324
|
+
if (toolsService) {
|
|
325
|
+
toolsService.addTools([expandTokensDefinition]);
|
|
325
326
|
toolsService.addFunctions({
|
|
326
327
|
[this.toolName]: (key: string) => {
|
|
327
328
|
const data = this.retrieveString(key);
|
|
@@ -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,25 @@ export class ToolResponseCache {
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
try {
|
|
133
|
-
//
|
|
134
|
-
const
|
|
133
|
+
// First parse the stored string as JSON, then handle nested JSON strings
|
|
134
|
+
const jsonData = this.tryParseJson(data);
|
|
135
|
+
if (!jsonData) {
|
|
136
|
+
return `Error: Tool response data is not valid JSON for toolCallId "${toolCallId}"`;
|
|
137
|
+
}
|
|
138
|
+
const parsedData = this.parseNestedJsonStrings(jsonData);
|
|
135
139
|
|
|
136
140
|
// Execute JQ query
|
|
137
141
|
const result = await jq.run(jqQuery, parsedData, { input: "json" });
|
|
138
142
|
|
|
139
|
-
//
|
|
143
|
+
// Handle the result based on its type
|
|
140
144
|
if (typeof result === "string") {
|
|
141
145
|
return result;
|
|
146
|
+
} else if (typeof result === "number" || typeof result === "boolean") {
|
|
147
|
+
return String(result);
|
|
148
|
+
} else if (result === null) {
|
|
149
|
+
return "null";
|
|
142
150
|
} else {
|
|
143
|
-
return JSON.stringify(result
|
|
151
|
+
return JSON.stringify(result);
|
|
144
152
|
}
|
|
145
153
|
} catch (error: any) {
|
|
146
154
|
// If JQ fails, try to provide helpful error message
|
|
@@ -198,14 +206,12 @@ export class ToolResponseCache {
|
|
|
198
206
|
* Registers the jqToolResponse tool with the ToolsService
|
|
199
207
|
*/
|
|
200
208
|
registerTool(toolsService: ToolsService): void {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
+
toolsService.addTools([jqToolResponseDefinition]);
|
|
210
|
+
toolsService.addFunctions({
|
|
211
|
+
[this.toolName]: async (toolCallId: string, jqQuery: string) => {
|
|
212
|
+
return await this.queryToolResponse(toolCallId, jqQuery);
|
|
213
|
+
},
|
|
214
|
+
});
|
|
209
215
|
}
|
|
210
216
|
}
|
|
211
217
|
|
|
@@ -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: {
|