@tyvm/knowhow 0.0.1
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/.vscode/launch.json +14 -0
- package/CONFIG.md +336 -0
- package/README.md +49 -0
- package/autodoc/chat.mdx +20 -0
- package/autodoc/cli.mdx +11 -0
- package/autodoc/plugins/asana.mdx +47 -0
- package/autodoc/plugins/downloader/downloader.mdx +38 -0
- package/autodoc/plugins/downloader/plugin.mdx +37 -0
- package/autodoc/plugins/downloader/types.mdx +42 -0
- package/autodoc/plugins/embedding.mdx +41 -0
- package/autodoc/plugins/figma.mdx +45 -0
- package/autodoc/plugins/github.mdx +40 -0
- package/autodoc/plugins/jira.mdx +46 -0
- package/autodoc/plugins/language.mdx +37 -0
- package/autodoc/plugins/linear.mdx +35 -0
- package/autodoc/plugins/notion.mdx +38 -0
- package/autodoc/plugins/plugins.mdx +59 -0
- package/autodoc/plugins/types.mdx +51 -0
- package/autodoc/plugins/vim.mdx +39 -0
- package/autodoc/tools/addInternalTools.mdx +1 -0
- package/autodoc/tools/agentCall.mdx +1 -0
- package/autodoc/tools/asana/definitions.mdx +10 -0
- package/autodoc/tools/asana/index.mdx +12 -0
- package/autodoc/tools/askHuman.mdx +1 -0
- package/autodoc/tools/callPlugin.mdx +1 -0
- package/autodoc/tools/embeddingSearch.mdx +1 -0
- package/autodoc/tools/execCommand.mdx +1 -0
- package/autodoc/tools/fileSearch.mdx +1 -0
- package/autodoc/tools/finalAnswer.mdx +1 -0
- package/autodoc/tools/github/definitions.mdx +6 -0
- package/autodoc/tools/github/index.mdx +8 -0
- package/autodoc/tools/index.mdx +14 -0
- package/autodoc/tools/lintFile.mdx +7 -0
- package/autodoc/tools/list.mdx +16 -0
- package/autodoc/tools/modifyFile.mdx +7 -0
- package/autodoc/tools/patch.mdx +9 -0
- package/autodoc/tools/readBlocks.mdx +1 -0
- package/autodoc/tools/readFile.mdx +1 -0
- package/autodoc/tools/scanFile.mdx +1 -0
- package/autodoc/tools/textSearch.mdx +6 -0
- package/autodoc/tools/types/fileblock.mdx +1 -0
- package/autodoc/tools/visionTool.mdx +1 -0
- package/autodoc/tools/writeFile.mdx +1 -0
- package/jest.config.js +18 -0
- package/package.json +89 -0
- package/src/agents/base/base.ts +619 -0
- package/src/agents/base/prompt.ts +26 -0
- package/src/agents/configurable/ConfigAgent.ts +23 -0
- package/src/agents/developer/developer.ts +69 -0
- package/src/agents/index.ts +8 -0
- package/src/agents/interface.ts +11 -0
- package/src/agents/patcher/codebase.md +27 -0
- package/src/agents/patcher/patcher.ts +110 -0
- package/src/agents/researcher/researcher.ts +109 -0
- package/src/agents/tools/addInternalTools.ts +21 -0
- package/src/agents/tools/agentCall.ts +18 -0
- package/src/agents/tools/aiClient.ts +36 -0
- package/src/agents/tools/asana/definitions.ts +199 -0
- package/src/agents/tools/asana/index.ts +108 -0
- package/src/agents/tools/askHuman.ts +8 -0
- package/src/agents/tools/callPlugin.ts +4 -0
- package/src/agents/tools/embeddingSearch.ts +5 -0
- package/src/agents/tools/execCommand.ts +26 -0
- package/src/agents/tools/fileSearch.ts +33 -0
- package/src/agents/tools/finalAnswer.ts +4 -0
- package/src/agents/tools/github/definitions.ts +89 -0
- package/src/agents/tools/github/index.ts +67 -0
- package/src/agents/tools/googleSearch.ts +242 -0
- package/src/agents/tools/index.ts +24 -0
- package/src/agents/tools/language/definitions.ts +97 -0
- package/src/agents/tools/language/index.ts +19 -0
- package/src/agents/tools/lintFile.ts +17 -0
- package/src/agents/tools/list.ts +514 -0
- package/src/agents/tools/loadWebpage.ts +129 -0
- package/src/agents/tools/modifyFile.ts +53 -0
- package/src/agents/tools/patch.ts +672 -0
- package/src/agents/tools/readBlocks.ts +41 -0
- package/src/agents/tools/readFile.ts +39 -0
- package/src/agents/tools/scanFile.ts +16 -0
- package/src/agents/tools/textSearch.ts +21 -0
- package/src/agents/tools/types/fileblock.ts +5 -0
- package/src/agents/tools/visionTool.ts +5 -0
- package/src/agents/tools/writeFile.ts +46 -0
- package/src/agents/vim/vim.ts +153 -0
- package/src/ai.ts +167 -0
- package/src/chat.ts +412 -0
- package/src/cli.ts +85 -0
- package/src/clients/anthropic.ts +399 -0
- package/src/clients/gemini.ts +486 -0
- package/src/clients/http.ts +107 -0
- package/src/clients/index.ts +183 -0
- package/src/clients/knowhow.ts +33 -0
- package/src/clients/openai.ts +253 -0
- package/src/clients/types.ts +91 -0
- package/src/clients/xai.ts +132 -0
- package/src/config.ts +211 -0
- package/src/conversion.ts +140 -0
- package/src/dataset/diffs/README.md +12 -0
- package/src/dataset/diffs/debug-errors.ts +29 -0
- package/src/dataset/diffs/debug.ts +64 -0
- package/src/dataset/diffs/generate.ts +71 -0
- package/src/dataset/diffs/jsonl.ts +54 -0
- package/src/dataset/diffs/test.ts +193 -0
- package/src/embeddings.ts +411 -0
- package/src/hashes.ts +67 -0
- package/src/index.ts +376 -0
- package/src/login.ts +78 -0
- package/src/microphone.ts +136 -0
- package/src/modules/index.ts +37 -0
- package/src/modules/types.ts +48 -0
- package/src/plugins/asana.ts +134 -0
- package/src/plugins/downloader/downloader.ts +204 -0
- package/src/plugins/downloader/plugin.ts +85 -0
- package/src/plugins/downloader/types.ts +85 -0
- package/src/plugins/embedding.ts +42 -0
- package/src/plugins/figma.ts +137 -0
- package/src/plugins/github.ts +153 -0
- package/src/plugins/jira.ts +104 -0
- package/src/plugins/language.ts +100 -0
- package/src/plugins/linear.ts +219 -0
- package/src/plugins/notion.ts +170 -0
- package/src/plugins/plugins.ts +56 -0
- package/src/plugins/types.ts +5 -0
- package/src/plugins/url.ts +63 -0
- package/src/plugins/vim.ts +73 -0
- package/src/prompts/BasicCodeDocumenter.ts +1 -0
- package/src/prompts/BasicProjectDocumenter.ts +1 -0
- package/src/prompts/EmbeddingSeachHelper.ts +1 -0
- package/src/prompts/index.ts +9 -0
- package/src/server/index.ts +14 -0
- package/src/services/AgentService.ts +98 -0
- package/src/services/EmbeddingService.ts +410 -0
- package/src/services/EventService.ts +20 -0
- package/src/services/GitHub.ts +60 -0
- package/src/services/KnowhowClient.ts +113 -0
- package/src/services/Mcp.ts +270 -0
- package/src/services/McpServer.ts +119 -0
- package/src/services/McpWebsocketTransport.ts +64 -0
- package/src/services/S3.ts +126 -0
- package/src/services/Tools.ts +65 -0
- package/src/services/flags.ts +52 -0
- package/src/services/index.ts +8 -0
- package/src/types.ts +225 -0
- package/src/utils/index.ts +108 -0
- package/src/worker.ts +80 -0
- package/tests/integration/figma.test.ts +70 -0
- package/tests/integration/fileblocks/readwrite.test.ts +95 -0
- package/tests/integration/patching/input.txt +145 -0
- package/tests/integration/patching/output.txt +145 -0
- package/tests/integration/patching/patch.txt +15 -0
- package/tests/integration/patching/unseen.txt +80 -0
- package/tests/integration/patching.test.ts +136 -0
- package/tests/languagePlugin.test.ts +74 -0
- package/tests/patching/corrupted.test.ts +78 -0
- package/tests/patching/imports.patch.txt +11 -0
- package/tests/patching/imports.test.ts +43 -0
- package/tests/patching/imports.txt +11 -0
- package/tests/patching/interface.patch.txt +15 -0
- package/tests/patching/interface.txt +7 -0
- package/tests/test.spec.ts +132 -0
- package/ts_build/src/agents/base/base.d.ts +88 -0
- package/ts_build/src/agents/base/base.js +464 -0
- package/ts_build/src/agents/base/base.js.map +1 -0
- package/ts_build/src/agents/base/prompt.d.ts +1 -0
- package/ts_build/src/agents/base/prompt.js +30 -0
- package/ts_build/src/agents/base/prompt.js.map +1 -0
- package/ts_build/src/agents/configurable/ConfigAgent.d.ts +10 -0
- package/ts_build/src/agents/configurable/ConfigAgent.js +25 -0
- package/ts_build/src/agents/configurable/ConfigAgent.js.map +1 -0
- package/ts_build/src/agents/configurable/OpenAIAgent.d.ts +0 -0
- package/ts_build/src/agents/configurable/OpenAIAgent.js +1 -0
- package/ts_build/src/agents/configurable/OpenAIAgent.js.map +1 -0
- package/ts_build/src/agents/developer/developer.d.ts +9 -0
- package/ts_build/src/agents/developer/developer.js +69 -0
- package/ts_build/src/agents/developer/developer.js.map +1 -0
- package/ts_build/src/agents/index.d.ts +7 -0
- package/ts_build/src/agents/index.js +38 -0
- package/ts_build/src/agents/index.js.map +1 -0
- package/ts_build/src/agents/interface.d.ts +10 -0
- package/ts_build/src/agents/interface.js +3 -0
- package/ts_build/src/agents/interface.js.map +1 -0
- package/ts_build/src/agents/patcher/patcher.d.ts +9 -0
- package/ts_build/src/agents/patcher/patcher.js +106 -0
- package/ts_build/src/agents/patcher/patcher.js.map +1 -0
- package/ts_build/src/agents/researcher/researcher.d.ts +9 -0
- package/ts_build/src/agents/researcher/researcher.js +107 -0
- package/ts_build/src/agents/researcher/researcher.js.map +1 -0
- package/ts_build/src/agents/tools/addInternalTools.d.ts +5 -0
- package/ts_build/src/agents/tools/addInternalTools.js +18 -0
- package/ts_build/src/agents/tools/addInternalTools.js.map +1 -0
- package/ts_build/src/agents/tools/agentCall.d.ts +1 -0
- package/ts_build/src/agents/tools/agentCall.js +21 -0
- package/ts_build/src/agents/tools/agentCall.js.map +1 -0
- package/ts_build/src/agents/tools/aiClient.d.ts +6 -0
- package/ts_build/src/agents/tools/aiClient.js +25 -0
- package/ts_build/src/agents/tools/aiClient.js.map +1 -0
- package/ts_build/src/agents/tools/asana/definitions.d.ts +202 -0
- package/ts_build/src/agents/tools/asana/definitions.js +197 -0
- package/ts_build/src/agents/tools/asana/definitions.js.map +1 -0
- package/ts_build/src/agents/tools/asana/index.d.ts +8 -0
- package/ts_build/src/agents/tools/asana/index.js +98 -0
- package/ts_build/src/agents/tools/asana/index.js.map +1 -0
- package/ts_build/src/agents/tools/askHuman.d.ts +1 -0
- package/ts_build/src/agents/tools/askHuman.js +15 -0
- package/ts_build/src/agents/tools/askHuman.js.map +1 -0
- package/ts_build/src/agents/tools/callPlugin.d.ts +1 -0
- package/ts_build/src/agents/tools/callPlugin.js +9 -0
- package/ts_build/src/agents/tools/callPlugin.js.map +1 -0
- package/ts_build/src/agents/tools/client.d.ts +5 -0
- package/ts_build/src/agents/tools/client.js +21 -0
- package/ts_build/src/agents/tools/client.js.map +1 -0
- package/ts_build/src/agents/tools/embeddingSearch.d.ts +1 -0
- package/ts_build/src/agents/tools/embeddingSearch.js +9 -0
- package/ts_build/src/agents/tools/embeddingSearch.js.map +1 -0
- package/ts_build/src/agents/tools/execCommand.d.ts +1 -0
- package/ts_build/src/agents/tools/execCommand.js +25 -0
- package/ts_build/src/agents/tools/execCommand.js.map +1 -0
- package/ts_build/src/agents/tools/fileSearch.d.ts +1 -0
- package/ts_build/src/agents/tools/fileSearch.js +31 -0
- package/ts_build/src/agents/tools/fileSearch.js.map +1 -0
- package/ts_build/src/agents/tools/finalAnswer.d.ts +1 -0
- package/ts_build/src/agents/tools/finalAnswer.js +8 -0
- package/ts_build/src/agents/tools/finalAnswer.js.map +1 -0
- package/ts_build/src/agents/tools/github/definitions.d.ts +47 -0
- package/ts_build/src/agents/tools/github/definitions.js +86 -0
- package/ts_build/src/agents/tools/github/definitions.js.map +1 -0
- package/ts_build/src/agents/tools/github/index.d.ts +789 -0
- package/ts_build/src/agents/tools/github/index.js +56 -0
- package/ts_build/src/agents/tools/github/index.js.map +1 -0
- package/ts_build/src/agents/tools/googleSearch.d.ts +93 -0
- package/ts_build/src/agents/tools/googleSearch.js +117 -0
- package/ts_build/src/agents/tools/googleSearch.js.map +1 -0
- package/ts_build/src/agents/tools/googleSearchTypes.d.ts +74 -0
- package/ts_build/src/agents/tools/googleSearchTypes.js +3 -0
- package/ts_build/src/agents/tools/googleSearchTypes.js.map +1 -0
- package/ts_build/src/agents/tools/index.d.ts +24 -0
- package/ts_build/src/agents/tools/index.js +41 -0
- package/ts_build/src/agents/tools/index.js.map +1 -0
- package/ts_build/src/agents/tools/language/definitions.d.ts +89 -0
- package/ts_build/src/agents/tools/language/definitions.js +95 -0
- package/ts_build/src/agents/tools/language/definitions.js.map +1 -0
- package/ts_build/src/agents/tools/language/index.d.ts +4 -0
- package/ts_build/src/agents/tools/language/index.js +22 -0
- package/ts_build/src/agents/tools/language/index.js.map +1 -0
- package/ts_build/src/agents/tools/lintFile.d.ts +1 -0
- package/ts_build/src/agents/tools/lintFile.js +22 -0
- package/ts_build/src/agents/tools/lintFile.js.map +1 -0
- package/ts_build/src/agents/tools/list.d.ts +2 -0
- package/ts_build/src/agents/tools/list.js +505 -0
- package/ts_build/src/agents/tools/list.js.map +1 -0
- package/ts_build/src/agents/tools/loadWebpage.d.ts +8 -0
- package/ts_build/src/agents/tools/loadWebpage.js +97 -0
- package/ts_build/src/agents/tools/loadWebpage.js.map +1 -0
- package/ts_build/src/agents/tools/modifyFile.d.ts +2 -0
- package/ts_build/src/agents/tools/modifyFile.js +74 -0
- package/ts_build/src/agents/tools/modifyFile.js.map +1 -0
- package/ts_build/src/agents/tools/patch.d.ts +21 -0
- package/ts_build/src/agents/tools/patch.js +443 -0
- package/ts_build/src/agents/tools/patch.js.map +1 -0
- package/ts_build/src/agents/tools/readBlocks.d.ts +2 -0
- package/ts_build/src/agents/tools/readBlocks.js +59 -0
- package/ts_build/src/agents/tools/readBlocks.js.map +1 -0
- package/ts_build/src/agents/tools/readFile.d.ts +1 -0
- package/ts_build/src/agents/tools/readFile.js +46 -0
- package/ts_build/src/agents/tools/readFile.js.map +1 -0
- package/ts_build/src/agents/tools/scanFile.d.ts +1 -0
- package/ts_build/src/agents/tools/scanFile.js +36 -0
- package/ts_build/src/agents/tools/scanFile.js.map +1 -0
- package/ts_build/src/agents/tools/textSearch.d.ts +1 -0
- package/ts_build/src/agents/tools/textSearch.js +22 -0
- package/ts_build/src/agents/tools/textSearch.js.map +1 -0
- package/ts_build/src/agents/tools/types/fileblock.d.ts +5 -0
- package/ts_build/src/agents/tools/types/fileblock.js +3 -0
- package/ts_build/src/agents/tools/types/fileblock.js.map +1 -0
- package/ts_build/src/agents/tools/visionTool.d.ts +1 -0
- package/ts_build/src/agents/tools/visionTool.js +9 -0
- package/ts_build/src/agents/tools/visionTool.js.map +1 -0
- package/ts_build/src/agents/tools/writeFile.d.ts +2 -0
- package/ts_build/src/agents/tools/writeFile.js +61 -0
- package/ts_build/src/agents/tools/writeFile.js.map +1 -0
- package/ts_build/src/agents/vim/vim.d.ts +14 -0
- package/ts_build/src/agents/vim/vim.js +171 -0
- package/ts_build/src/agents/vim/vim.js.map +1 -0
- package/ts_build/src/ai.d.ts +10 -0
- package/ts_build/src/ai.js +102 -0
- package/ts_build/src/ai.js.map +1 -0
- package/ts_build/src/chat.d.ts +13 -0
- package/ts_build/src/chat.js +319 -0
- package/ts_build/src/chat.js.map +1 -0
- package/ts_build/src/cli.d.ts +2 -0
- package/ts_build/src/cli.js +98 -0
- package/ts_build/src/cli.js.map +1 -0
- package/ts_build/src/clients/anthropic.d.ts +31 -0
- package/ts_build/src/clients/anthropic.js +344 -0
- package/ts_build/src/clients/anthropic.js.map +1 -0
- package/ts_build/src/clients/gemini.d.ts +20 -0
- package/ts_build/src/clients/gemini.js +347 -0
- package/ts_build/src/clients/gemini.js.map +1 -0
- package/ts_build/src/clients/http.d.ts +12 -0
- package/ts_build/src/clients/http.js +91 -0
- package/ts_build/src/clients/http.js.map +1 -0
- package/ts_build/src/clients/index.d.ts +47 -0
- package/ts_build/src/clients/index.js +143 -0
- package/ts_build/src/clients/index.js.map +1 -0
- package/ts_build/src/clients/knowhow.d.ts +10 -0
- package/ts_build/src/clients/knowhow.js +24 -0
- package/ts_build/src/clients/knowhow.js.map +1 -0
- package/ts_build/src/clients/openai.d.ts +20 -0
- package/ts_build/src/clients/openai.js +221 -0
- package/ts_build/src/clients/openai.js.map +1 -0
- package/ts_build/src/clients/types.d.ts +89 -0
- package/ts_build/src/clients/types.js +3 -0
- package/ts_build/src/clients/types.js.map +1 -0
- package/ts_build/src/clients/xai.d.ts +22 -0
- package/ts_build/src/clients/xai.js +108 -0
- package/ts_build/src/clients/xai.js.map +1 -0
- package/ts_build/src/config.d.ts +9 -0
- package/ts_build/src/config.js +216 -0
- package/ts_build/src/config.js.map +1 -0
- package/ts_build/src/conversion.d.ts +7 -0
- package/ts_build/src/conversion.js +114 -0
- package/ts_build/src/conversion.js.map +1 -0
- package/ts_build/src/dataset/diffs/debug-errors.d.ts +1 -0
- package/ts_build/src/dataset/diffs/debug-errors.js +28 -0
- package/ts_build/src/dataset/diffs/debug-errors.js.map +1 -0
- package/ts_build/src/dataset/diffs/debug.d.ts +1 -0
- package/ts_build/src/dataset/diffs/debug.js +50 -0
- package/ts_build/src/dataset/diffs/debug.js.map +1 -0
- package/ts_build/src/dataset/diffs/generate.d.ts +1 -0
- package/ts_build/src/dataset/diffs/generate.js +70 -0
- package/ts_build/src/dataset/diffs/generate.js.map +1 -0
- package/ts_build/src/dataset/diffs/jsonl.d.ts +1 -0
- package/ts_build/src/dataset/diffs/jsonl.js +47 -0
- package/ts_build/src/dataset/diffs/jsonl.js.map +1 -0
- package/ts_build/src/dataset/diffs/test.d.ts +1 -0
- package/ts_build/src/dataset/diffs/test.js +114 -0
- package/ts_build/src/dataset/diffs/test.js.map +1 -0
- package/ts_build/src/embeddings.d.ts +19 -0
- package/ts_build/src/embeddings.js +322 -0
- package/ts_build/src/embeddings.js.map +1 -0
- package/ts_build/src/hashes.d.ts +6 -0
- package/ts_build/src/hashes.js +78 -0
- package/ts_build/src/hashes.js.map +1 -0
- package/ts_build/src/index.d.ts +14 -0
- package/ts_build/src/index.js +258 -0
- package/ts_build/src/index.js.map +1 -0
- package/ts_build/src/login.d.ts +2 -0
- package/ts_build/src/login.js +63 -0
- package/ts_build/src/login.js.map +1 -0
- package/ts_build/src/microphone.d.ts +9 -0
- package/ts_build/src/microphone.js +131 -0
- package/ts_build/src/microphone.js.map +1 -0
- package/ts_build/src/modules/index.d.ts +3 -0
- package/ts_build/src/modules/index.js +34 -0
- package/ts_build/src/modules/index.js.map +1 -0
- package/ts_build/src/modules/types.d.ts +37 -0
- package/ts_build/src/modules/types.js +3 -0
- package/ts_build/src/modules/types.js.map +1 -0
- package/ts_build/src/plugins/asana.d.ts +16 -0
- package/ts_build/src/plugins/asana.js +114 -0
- package/ts_build/src/plugins/asana.js.map +1 -0
- package/ts_build/src/plugins/downloader/downloader.d.ts +12 -0
- package/ts_build/src/plugins/downloader/downloader.js +174 -0
- package/ts_build/src/plugins/downloader/downloader.js.map +1 -0
- package/ts_build/src/plugins/downloader/index.d.ts +3 -0
- package/ts_build/src/plugins/downloader/index.js +41 -0
- package/ts_build/src/plugins/downloader/index.js.map +1 -0
- package/ts_build/src/plugins/downloader/plugin.d.ts +8 -0
- package/ts_build/src/plugins/downloader/plugin.js +83 -0
- package/ts_build/src/plugins/downloader/plugin.js.map +1 -0
- package/ts_build/src/plugins/downloader/types.d.ts +82 -0
- package/ts_build/src/plugins/downloader/types.js +79 -0
- package/ts_build/src/plugins/downloader/types.js.map +1 -0
- package/ts_build/src/plugins/embedding.d.ts +5 -0
- package/ts_build/src/plugins/embedding.js +28 -0
- package/ts_build/src/plugins/embedding.js.map +1 -0
- package/ts_build/src/plugins/figma.d.ts +20 -0
- package/ts_build/src/plugins/figma.js +94 -0
- package/ts_build/src/plugins/figma.js.map +1 -0
- package/ts_build/src/plugins/github.d.ts +1223 -0
- package/ts_build/src/plugins/github.js +115 -0
- package/ts_build/src/plugins/github.js.map +1 -0
- package/ts_build/src/plugins/jira.d.ts +15 -0
- package/ts_build/src/plugins/jira.js +94 -0
- package/ts_build/src/plugins/jira.js.map +1 -0
- package/ts_build/src/plugins/language.d.ts +8 -0
- package/ts_build/src/plugins/language.js +69 -0
- package/ts_build/src/plugins/language.js.map +1 -0
- package/ts_build/src/plugins/linear.d.ts +23 -0
- package/ts_build/src/plugins/linear.js +184 -0
- package/ts_build/src/plugins/linear.js.map +1 -0
- package/ts_build/src/plugins/notion.d.ts +32 -0
- package/ts_build/src/plugins/notion.js +131 -0
- package/ts_build/src/plugins/notion.js.map +1 -0
- package/ts_build/src/plugins/plugins.d.ts +11 -0
- package/ts_build/src/plugins/plugins.js +51 -0
- package/ts_build/src/plugins/plugins.js.map +1 -0
- package/ts_build/src/plugins/types.d.ts +5 -0
- package/ts_build/src/plugins/types.js +3 -0
- package/ts_build/src/plugins/types.js.map +1 -0
- package/ts_build/src/plugins/url.d.ts +8 -0
- package/ts_build/src/plugins/url.js +50 -0
- package/ts_build/src/plugins/url.js.map +1 -0
- package/ts_build/src/plugins/vim.d.ts +11 -0
- package/ts_build/src/plugins/vim.js +63 -0
- package/ts_build/src/plugins/vim.js.map +1 -0
- package/ts_build/src/prompts/BasicCodeDocumenter.d.ts +2 -0
- package/ts_build/src/prompts/BasicCodeDocumenter.js +4 -0
- package/ts_build/src/prompts/BasicCodeDocumenter.js.map +1 -0
- package/ts_build/src/prompts/BasicProjectDocumenter.d.ts +2 -0
- package/ts_build/src/prompts/BasicProjectDocumenter.js +4 -0
- package/ts_build/src/prompts/BasicProjectDocumenter.js.map +1 -0
- package/ts_build/src/prompts/EmbeddingSeachHelper.d.ts +2 -0
- package/ts_build/src/prompts/EmbeddingSeachHelper.js +4 -0
- package/ts_build/src/prompts/EmbeddingSeachHelper.js.map +1 -0
- package/ts_build/src/prompts/index.d.ts +13 -0
- package/ts_build/src/prompts/index.js +15 -0
- package/ts_build/src/prompts/index.js.map +1 -0
- package/ts_build/src/server/index.d.ts +1 -0
- package/ts_build/src/server/index.js +17 -0
- package/ts_build/src/server/index.js.map +1 -0
- package/ts_build/src/services/AgentService.d.ts +14 -0
- package/ts_build/src/services/AgentService.js +87 -0
- package/ts_build/src/services/AgentService.js.map +1 -0
- package/ts_build/src/services/EmbeddingService.d.ts +39 -0
- package/ts_build/src/services/EmbeddingService.js +307 -0
- package/ts_build/src/services/EmbeddingService.js.map +1 -0
- package/ts_build/src/services/EventService.d.ts +9 -0
- package/ts_build/src/services/EventService.js +20 -0
- package/ts_build/src/services/EventService.js.map +1 -0
- package/ts_build/src/services/GitHub.d.ts +11 -0
- package/ts_build/src/services/GitHub.js +52 -0
- package/ts_build/src/services/GitHub.js.map +1 -0
- package/ts_build/src/services/KnowhowClient.d.ts +18 -0
- package/ts_build/src/services/KnowhowClient.js +85 -0
- package/ts_build/src/services/KnowhowClient.js.map +1 -0
- package/ts_build/src/services/Mcp.d.ts +377 -0
- package/ts_build/src/services/Mcp.js +221 -0
- package/ts_build/src/services/Mcp.js.map +1 -0
- package/ts_build/src/services/McpServer.d.ts +19 -0
- package/ts_build/src/services/McpServer.js +104 -0
- package/ts_build/src/services/McpServer.js.map +1 -0
- package/ts_build/src/services/McpWebsocketTransport.d.ts +13 -0
- package/ts_build/src/services/McpWebsocketTransport.js +59 -0
- package/ts_build/src/services/McpWebsocketTransport.js.map +1 -0
- package/ts_build/src/services/S3.d.ts +9 -0
- package/ts_build/src/services/S3.js +116 -0
- package/ts_build/src/services/S3.js.map +1 -0
- package/ts_build/src/services/Tools.d.ts +19 -0
- package/ts_build/src/services/Tools.js +51 -0
- package/ts_build/src/services/Tools.js.map +1 -0
- package/ts_build/src/services/flags.d.ts +13 -0
- package/ts_build/src/services/flags.js +48 -0
- package/ts_build/src/services/flags.js.map +1 -0
- package/ts_build/src/services/index.d.ts +8 -0
- package/ts_build/src/services/index.js +38 -0
- package/ts_build/src/services/index.js.map +1 -0
- package/ts_build/src/terminal.d.ts +1 -0
- package/ts_build/src/terminal.js +35 -0
- package/ts_build/src/terminal.js.map +1 -0
- package/ts_build/src/types.d.ts +181 -0
- package/ts_build/src/types.js +94 -0
- package/ts_build/src/types.js.map +1 -0
- package/ts_build/src/utils/index.d.ts +24 -0
- package/ts_build/src/utils/index.js +116 -0
- package/ts_build/src/utils/index.js.map +1 -0
- package/ts_build/src/worker.d.ts +1 -0
- package/ts_build/src/worker.js +68 -0
- package/ts_build/src/worker.js.map +1 -0
- package/ts_build/tests/integration/figma.test.d.ts +1 -0
- package/ts_build/tests/integration/figma.test.js +47 -0
- package/ts_build/tests/integration/figma.test.js.map +1 -0
- package/ts_build/tests/integration/fileblocks/readwrite.test.d.ts +1 -0
- package/ts_build/tests/integration/fileblocks/readwrite.test.js +95 -0
- package/ts_build/tests/integration/fileblocks/readwrite.test.js.map +1 -0
- package/ts_build/tests/integration/patching.test.d.ts +1 -0
- package/ts_build/tests/integration/patching.test.js +117 -0
- package/ts_build/tests/integration/patching.test.js.map +1 -0
- package/ts_build/tests/languagePlugin.test.d.ts +1 -0
- package/ts_build/tests/languagePlugin.test.js +78 -0
- package/ts_build/tests/languagePlugin.test.js.map +1 -0
- package/ts_build/tests/patching/corrupted.test.d.ts +1 -0
- package/ts_build/tests/patching/corrupted.test.js +53 -0
- package/ts_build/tests/patching/corrupted.test.js.map +1 -0
- package/ts_build/tests/patching/imports.test.d.ts +1 -0
- package/ts_build/tests/patching/imports.test.js +61 -0
- package/ts_build/tests/patching/imports.test.js.map +1 -0
- package/ts_build/tests/test.spec.d.ts +1 -0
- package/ts_build/tests/test.spec.js +101 -0
- package/ts_build/tests/test.spec.js.map +1 -0
- package/tsconfig.json +31 -0
- package/tslint.json +11 -0
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
2
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
3
|
+
import Anthropic from "@anthropic-ai/sdk";
|
|
4
|
+
|
|
5
|
+
import { McpConfig } from "../types";
|
|
6
|
+
import { Tool } from "../clients";
|
|
7
|
+
import { getConfig } from "../config";
|
|
8
|
+
import { ToolsService } from "./Tools";
|
|
9
|
+
import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
10
|
+
import { CallToolResultSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
11
|
+
import { StdioServerParameters } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
12
|
+
import { MCPWebSocketTransport } from "./McpWebsocketTransport";
|
|
13
|
+
|
|
14
|
+
type CachedTool = Anthropic.Tool;
|
|
15
|
+
export type McpTool = CachedTool & {
|
|
16
|
+
inputSchema: CachedTool["input_schema"];
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const knowhowMcpClient = {
|
|
20
|
+
name: "knowhow-mcp-client",
|
|
21
|
+
version: "1.0.0",
|
|
22
|
+
};
|
|
23
|
+
export const knowhowConfig = {
|
|
24
|
+
capabilities: {
|
|
25
|
+
prompts: {},
|
|
26
|
+
resources: {},
|
|
27
|
+
tools: {},
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export * from "./McpServer";
|
|
32
|
+
export * from "./McpWebsocketTransport";
|
|
33
|
+
|
|
34
|
+
export class McpService {
|
|
35
|
+
connected = [];
|
|
36
|
+
transports: Transport[] = [];
|
|
37
|
+
clients: Client[] = [];
|
|
38
|
+
config: McpConfig[] = [];
|
|
39
|
+
tools: Tool[] = [];
|
|
40
|
+
mcpPrefix = "mcp";
|
|
41
|
+
|
|
42
|
+
async createStdioClients(mcpServers: McpConfig[] = []) {
|
|
43
|
+
if (this.clients.length) {
|
|
44
|
+
return this.clients;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
this.config = mcpServers;
|
|
48
|
+
this.transports = mcpServers.map((mcp) => {
|
|
49
|
+
const logFormat = `${mcp.name}: ${[
|
|
50
|
+
mcp.command,
|
|
51
|
+
...mcp.args,
|
|
52
|
+
mcp.url,
|
|
53
|
+
].join(" ")}`;
|
|
54
|
+
|
|
55
|
+
console.log("Creating transport for", logFormat);
|
|
56
|
+
if (mcp.command) {
|
|
57
|
+
return new StdioClientTransport(mcp as StdioServerParameters);
|
|
58
|
+
}
|
|
59
|
+
if (mcp?.params?.socket) {
|
|
60
|
+
return new MCPWebSocketTransport(mcp.params.socket);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
this.clients = this.transports.map((transport) => {
|
|
65
|
+
return new Client(knowhowMcpClient, knowhowConfig);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
return this.clients;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
setMcpPrefix(prefix: string) {
|
|
72
|
+
this.mcpPrefix = prefix;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
createClient(mcp: McpConfig, transport: Transport) {
|
|
76
|
+
this.config.push(mcp);
|
|
77
|
+
this.clients.push(new Client(knowhowMcpClient, knowhowConfig));
|
|
78
|
+
this.transports.push(transport);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async connectToConfigured(tools?: ToolsService) {
|
|
82
|
+
const config = await getConfig();
|
|
83
|
+
|
|
84
|
+
return this.connectTo(config.mcps, tools);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async connectTo(mcpServers: McpConfig[] = [], tools?: ToolsService) {
|
|
88
|
+
const clients = await this.createStdioClients(mcpServers);
|
|
89
|
+
await this.connectAll();
|
|
90
|
+
|
|
91
|
+
if (tools) {
|
|
92
|
+
await this.addTools(tools);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async addTools(tools: ToolsService) {
|
|
97
|
+
tools.addTools(await this.getTools());
|
|
98
|
+
tools.addFunctions(await this.getToolMap());
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async copyFrom(mcp: McpService) {
|
|
102
|
+
this.clients.push(...mcp.clients);
|
|
103
|
+
this.transports.push(...mcp.transports);
|
|
104
|
+
this.config.push(...mcp.config);
|
|
105
|
+
this.connected.push(...mcp.connected);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async closeTransports() {
|
|
109
|
+
await Promise.all(
|
|
110
|
+
this.transports.map(async (transport, index) => {
|
|
111
|
+
this.connected[index] = false;
|
|
112
|
+
return transport.close();
|
|
113
|
+
})
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
this.transports = [];
|
|
117
|
+
this.connected = [];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async closeClients() {
|
|
121
|
+
await Promise.all(
|
|
122
|
+
this.clients.map((client) => {
|
|
123
|
+
return client.close();
|
|
124
|
+
})
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
this.clients = [];
|
|
128
|
+
this.connected = [];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async closeAll() {
|
|
132
|
+
await this.closeTransports();
|
|
133
|
+
await this.closeClients();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
getClientIndex(clientName: string) {
|
|
137
|
+
const index = this.config.findIndex((mcp) => mcp.name === clientName);
|
|
138
|
+
return index;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
parseToolName(toolName: string) {
|
|
142
|
+
const split = toolName.split("_");
|
|
143
|
+
|
|
144
|
+
if (split.length < 2) {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return split.slice(2).join("_");
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
getToolClientIndex(toolName: string) {
|
|
152
|
+
const split = toolName.split("_");
|
|
153
|
+
|
|
154
|
+
if (split.length < 2) {
|
|
155
|
+
return -1;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const index = Number(split[1]);
|
|
159
|
+
return index;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
getToolClient(toolName: string) {
|
|
163
|
+
const index = this.getToolClientIndex(toolName);
|
|
164
|
+
|
|
165
|
+
if (index < 0) {
|
|
166
|
+
throw new Error(`Invalid tool name ${toolName}`);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return this.clients[index];
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
getFunction(toolName: string) {
|
|
173
|
+
const client = this.getToolClient(toolName);
|
|
174
|
+
|
|
175
|
+
const realName = this.parseToolName(toolName);
|
|
176
|
+
return async (args: any) => {
|
|
177
|
+
console.log("Calling tool", realName, "with args", args);
|
|
178
|
+
const tool = await client.callTool(
|
|
179
|
+
{
|
|
180
|
+
name: realName,
|
|
181
|
+
arguments: args,
|
|
182
|
+
},
|
|
183
|
+
CallToolResultSchema,
|
|
184
|
+
{
|
|
185
|
+
timeout: 10 * 60 * 1000,
|
|
186
|
+
maxTotalTimeout: 10 * 60 * 1000,
|
|
187
|
+
}
|
|
188
|
+
);
|
|
189
|
+
return tool;
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async getFunctions() {
|
|
194
|
+
const tools = await this.getTools();
|
|
195
|
+
return tools.map((tool) => {
|
|
196
|
+
return this.getFunction(tool.function.name);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
async getToolMap() {
|
|
201
|
+
const tools = await this.getTools();
|
|
202
|
+
return tools.reduce((acc, tool) => {
|
|
203
|
+
acc[tool.function.name] = this.getFunction(tool.function.name);
|
|
204
|
+
return acc;
|
|
205
|
+
}, {});
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async connectAll() {
|
|
209
|
+
await Promise.all(
|
|
210
|
+
this.clients.map(async (client, index) => {
|
|
211
|
+
if (this.connected[index]) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
await client.connect(this.transports[index]);
|
|
215
|
+
this.connected[index] = true;
|
|
216
|
+
})
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
async getClient() {
|
|
221
|
+
if (this.clients.length) {
|
|
222
|
+
return this.clients;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
this.clients = await this.createStdioClients(this.config);
|
|
226
|
+
|
|
227
|
+
return this.clients;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
async getTools() {
|
|
231
|
+
if (this.tools.length) {
|
|
232
|
+
return this.tools;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const tools = [] as Tool[];
|
|
236
|
+
|
|
237
|
+
for (let i = 0; i < this.config.length; i++) {
|
|
238
|
+
const config = this.config[i];
|
|
239
|
+
const client = this.clients[i];
|
|
240
|
+
const clientTools = await client.listTools();
|
|
241
|
+
const transformedTools = clientTools.tools.map((tool) => {
|
|
242
|
+
return this.toOpenAiTool(i, tool as any as McpTool);
|
|
243
|
+
});
|
|
244
|
+
tools.push(...transformedTools);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
this.tools = tools;
|
|
248
|
+
return tools;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
toOpenAiTool(index: number, tool: McpTool) {
|
|
252
|
+
const transformed: Tool = {
|
|
253
|
+
type: "function",
|
|
254
|
+
function: {
|
|
255
|
+
name: `${this.mcpPrefix}_${index}_${tool.name}`,
|
|
256
|
+
description: tool.description,
|
|
257
|
+
parameters: {
|
|
258
|
+
type: "object",
|
|
259
|
+
positional: Boolean(tool.inputSchema.positional),
|
|
260
|
+
properties: tool.inputSchema.properties as any,
|
|
261
|
+
required: tool.inputSchema.required as string[],
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
return transformed;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export const Mcp = new McpService();
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
|
|
5
|
+
import { Tool, ToolProp } from "../clients/types";
|
|
6
|
+
import { ToolsService } from "./Tools";
|
|
7
|
+
import { MCPWebSocketTransport } from "./McpWebsocketTransport";
|
|
8
|
+
import { WebSocket } from "ws";
|
|
9
|
+
|
|
10
|
+
export class McpServerService {
|
|
11
|
+
server: McpServer | null = null;
|
|
12
|
+
constructor(private toolsService: ToolsService) {}
|
|
13
|
+
registeredTools = new Set<string>();
|
|
14
|
+
|
|
15
|
+
createServer(name: string, version: string) {
|
|
16
|
+
if (this.server) {
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
this.server = new McpServer({
|
|
21
|
+
name,
|
|
22
|
+
version,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
toZodSchema(properties: { [key: string]: ToolProp }): z.ZodObject<any> {
|
|
29
|
+
const schema: Record<string, z.ZodTypeAny> = {};
|
|
30
|
+
for (const [key, value] of Object.entries(properties)) {
|
|
31
|
+
if (value.type === "string") {
|
|
32
|
+
schema[key] = z.string();
|
|
33
|
+
} else if (value.type === "number") {
|
|
34
|
+
schema[key] = z.number();
|
|
35
|
+
} else if (value.type === "boolean") {
|
|
36
|
+
schema[key] = z.boolean();
|
|
37
|
+
} else if (value.type === "array" && value?.items?.properties) {
|
|
38
|
+
schema[key] = z.array(this.toZodSchema(value.items.properties));
|
|
39
|
+
} else if (value.type === "object" && value.properties) {
|
|
40
|
+
schema[key] = this.toZodSchema(value.properties);
|
|
41
|
+
} else {
|
|
42
|
+
schema[key] = z.any();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return z.object(schema);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
withTools(tools: Tool[]) {
|
|
49
|
+
for (const tool of tools) {
|
|
50
|
+
const props = tool.function.parameters.properties;
|
|
51
|
+
|
|
52
|
+
if (!props) {
|
|
53
|
+
console.warn(`Tool ${tool.function.name} has no properties`);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (this.registeredTools.has(tool.function.name)) {
|
|
58
|
+
console.log(`Tool ${tool.function.name} already registered`);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
console.log(`Registering tool ${tool.function.name}`);
|
|
63
|
+
this.registeredTools.add(tool.function.name);
|
|
64
|
+
|
|
65
|
+
const shape = this.toZodSchema(props).shape;
|
|
66
|
+
|
|
67
|
+
this.server.tool(
|
|
68
|
+
tool.function.name,
|
|
69
|
+
tool.function.description,
|
|
70
|
+
shape,
|
|
71
|
+
async (args, extra) => {
|
|
72
|
+
const fn = this.toolsService.getFunction(tool.function.name);
|
|
73
|
+
|
|
74
|
+
let response = "" as string | any;
|
|
75
|
+
if (tool.function.parameters.positional) {
|
|
76
|
+
response = await fn(...Object.values(args));
|
|
77
|
+
} else {
|
|
78
|
+
response = await fn(args);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (response && typeof response === "object" && response.content) {
|
|
82
|
+
return response;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
content: [
|
|
87
|
+
{
|
|
88
|
+
type: "text",
|
|
89
|
+
text:
|
|
90
|
+
typeof response === "string"
|
|
91
|
+
? response
|
|
92
|
+
: JSON.stringify(response),
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
createServerWithAllTools(name: string, version: string) {
|
|
103
|
+
return this.createServer(name, version).withTools(
|
|
104
|
+
this.toolsService.getTools()
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async runStdioServer() {
|
|
109
|
+
const transport = new StdioServerTransport();
|
|
110
|
+
await this.server.connect(transport);
|
|
111
|
+
console.error(`MCP Server running on stdio`);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async runWsServer(ws: WebSocket) {
|
|
115
|
+
const transport = new MCPWebSocketTransport(ws);
|
|
116
|
+
await this.server.connect(transport);
|
|
117
|
+
console.error(`MCP Server running on websocket`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
2
|
+
import {
|
|
3
|
+
JSONRPCMessage,
|
|
4
|
+
JSONRPCMessageSchema,
|
|
5
|
+
} from "@modelcontextprotocol/sdk/types.js";
|
|
6
|
+
import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
7
|
+
import { WebSocket } from "ws";
|
|
8
|
+
|
|
9
|
+
export class MCPWebSocketTransport implements Transport {
|
|
10
|
+
protected _socket: WebSocket;
|
|
11
|
+
onmessage?: (message: JSONRPCMessage) => void;
|
|
12
|
+
onerror?: (error: Error) => void;
|
|
13
|
+
onclose?: () => void;
|
|
14
|
+
|
|
15
|
+
constructor(socket: WebSocket) {
|
|
16
|
+
this._socket = socket;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async start(): Promise<void> {
|
|
20
|
+
this._socket.on("message", (data: any) => {
|
|
21
|
+
try {
|
|
22
|
+
let parsed: unknown;
|
|
23
|
+
if (typeof data === "string") {
|
|
24
|
+
parsed = JSON.parse(data);
|
|
25
|
+
} else if (Buffer.isBuffer(data)) {
|
|
26
|
+
parsed = JSON.parse(data.toString("utf-8"));
|
|
27
|
+
} else {
|
|
28
|
+
parsed = JSON.parse(data.toString());
|
|
29
|
+
}
|
|
30
|
+
console.log("MCPW Message received", JSON.stringify(parsed));
|
|
31
|
+
const message = JSONRPCMessageSchema.parse(parsed);
|
|
32
|
+
this.onmessage?.(message);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
this.onerror?.(error as Error);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
this._socket.on("close", () => {
|
|
39
|
+
this.onclose?.();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
this._socket.on("error", (err) => {
|
|
43
|
+
this.onerror?.(err as Error);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async send(message: JSONRPCMessage): Promise<void> {
|
|
48
|
+
return new Promise((resolve, reject) => {
|
|
49
|
+
const json = JSON.stringify(message);
|
|
50
|
+
console.log("MCPWs sending", json);
|
|
51
|
+
this._socket.send(json, (error?: Error) => {
|
|
52
|
+
if (error) {
|
|
53
|
+
this.onerror?.(error);
|
|
54
|
+
return reject(error);
|
|
55
|
+
}
|
|
56
|
+
resolve();
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async close(): Promise<void> {
|
|
62
|
+
this._socket.close();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import {
|
|
2
|
+
S3Client,
|
|
3
|
+
HeadBucketCommand,
|
|
4
|
+
CreateBucketCommand,
|
|
5
|
+
GetObjectCommand,
|
|
6
|
+
PutObjectCommand,
|
|
7
|
+
GetObjectCommandInput,
|
|
8
|
+
PutObjectCommandInput,
|
|
9
|
+
} from "@aws-sdk/client-s3";
|
|
10
|
+
|
|
11
|
+
import fs from "fs/promises";
|
|
12
|
+
import { createWriteStream } from "fs";
|
|
13
|
+
import * as path from "path";
|
|
14
|
+
import { pipeline } from "stream";
|
|
15
|
+
import * as util from "util";
|
|
16
|
+
import axios from "axios";
|
|
17
|
+
|
|
18
|
+
import { createReadStream } from "fs";
|
|
19
|
+
const pipelineAsync = util.promisify(pipeline);
|
|
20
|
+
|
|
21
|
+
export class S3Service {
|
|
22
|
+
private s3: S3Client;
|
|
23
|
+
|
|
24
|
+
constructor() {
|
|
25
|
+
this.s3 = new S3Client();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async uploadFile(
|
|
29
|
+
filePath: string,
|
|
30
|
+
bucketName: string,
|
|
31
|
+
key: string
|
|
32
|
+
): Promise<void> {
|
|
33
|
+
const fileContent = await fs.readFile(filePath);
|
|
34
|
+
|
|
35
|
+
const params = {
|
|
36
|
+
Bucket: bucketName,
|
|
37
|
+
Key: key,
|
|
38
|
+
Body: fileContent,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// create bucket if it doesn't exist
|
|
42
|
+
try {
|
|
43
|
+
await this.s3.send(new HeadBucketCommand({ Bucket: bucketName }));
|
|
44
|
+
} catch (error) {
|
|
45
|
+
const statusCode = error.$metadata.httpStatusCode;
|
|
46
|
+
if (statusCode === 404) {
|
|
47
|
+
await this.s3.send(new CreateBucketCommand({ Bucket: bucketName }));
|
|
48
|
+
console.log(`Bucket ${bucketName} created successfully`);
|
|
49
|
+
} else {
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
await this.s3.send(new PutObjectCommand(params));
|
|
55
|
+
console.log(`File uploaded successfully to ${bucketName}/${key}`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async downloadFile(
|
|
59
|
+
bucketName: string,
|
|
60
|
+
key: string,
|
|
61
|
+
destinationPath: string
|
|
62
|
+
): Promise<void> {
|
|
63
|
+
const params = {
|
|
64
|
+
Bucket: bucketName,
|
|
65
|
+
Key: key,
|
|
66
|
+
};
|
|
67
|
+
const { Body } = await this.s3.send(new GetObjectCommand(params));
|
|
68
|
+
const fileStream = createWriteStream(destinationPath);
|
|
69
|
+
|
|
70
|
+
await pipelineAsync(Body as NodeJS.ReadableStream, fileStream);
|
|
71
|
+
|
|
72
|
+
console.log(
|
|
73
|
+
`File downloaded successfully from ${bucketName}/${key} to ${destinationPath}`
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async uploadToPresignedUrl(
|
|
78
|
+
presignedUrl: string,
|
|
79
|
+
filePath: string
|
|
80
|
+
): Promise<void> {
|
|
81
|
+
try {
|
|
82
|
+
const fileStream = createReadStream(filePath);
|
|
83
|
+
const fileStats = await fs.stat(filePath);
|
|
84
|
+
|
|
85
|
+
const response = await axios.put(presignedUrl, fileStream, {
|
|
86
|
+
headers: {
|
|
87
|
+
"Content-Length": fileStats.size,
|
|
88
|
+
},
|
|
89
|
+
maxBodyLength: Infinity,
|
|
90
|
+
maxContentLength: Infinity,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
if (response.status === 200) {
|
|
94
|
+
console.log("File uploaded successfully to pre-signed URL");
|
|
95
|
+
} else {
|
|
96
|
+
throw new Error(`Upload failed with status code: ${response.status}`);
|
|
97
|
+
}
|
|
98
|
+
} catch (error) {
|
|
99
|
+
console.error("Error uploading file to pre-signed URL:", error);
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async downloadFromPresignedUrl(
|
|
105
|
+
presignedUrl: string,
|
|
106
|
+
destinationPath: string
|
|
107
|
+
): Promise<void> {
|
|
108
|
+
try {
|
|
109
|
+
const response = await axios.get(presignedUrl, {
|
|
110
|
+
responseType: "stream",
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const fileStream = createWriteStream(destinationPath);
|
|
114
|
+
await pipelineAsync(response.data, fileStream);
|
|
115
|
+
|
|
116
|
+
console.log(
|
|
117
|
+
`File downloaded successfully from pre-signed URL to ${destinationPath}`
|
|
118
|
+
);
|
|
119
|
+
} catch (error) {
|
|
120
|
+
console.error("Error downloading file from pre-signed URL:", error);
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export const AwsS3 = new S3Service();
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { ChatCompletionTool } from "openai/resources/chat";
|
|
2
|
+
import { includedTools } from "../agents/tools/list";
|
|
3
|
+
import { Tool } from "../clients/types";
|
|
4
|
+
|
|
5
|
+
export class ToolsService {
|
|
6
|
+
tools = [] as Tool[];
|
|
7
|
+
|
|
8
|
+
functions = {};
|
|
9
|
+
|
|
10
|
+
getTools() {
|
|
11
|
+
return this.tools;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
getToolsByNames(names: string[]) {
|
|
15
|
+
return this.tools.filter((tool) => names.includes(tool.function.name));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
copyToolsFrom(toolNames: string[], toolsService: ToolsService) {
|
|
19
|
+
const tools = toolsService.getToolsByNames(toolNames);
|
|
20
|
+
this.addTools(tools);
|
|
21
|
+
|
|
22
|
+
for (const name of toolNames) {
|
|
23
|
+
this.setFunction(name, toolsService.getFunction(name));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
getToolNames() {
|
|
28
|
+
return this.tools.map((tool) => tool.function.name);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
getTool(name: string): Tool {
|
|
32
|
+
return this.tools.find((tool) => tool.function.name === name);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
getFunction(name: string) {
|
|
36
|
+
// return this.functions[name] || allTools.addInternalTools(allTools)[name];
|
|
37
|
+
return this.functions[name];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
setFunction(name: string, func: (...args: any) => any) {
|
|
41
|
+
this.functions[name] = func;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
setFunctions(names: string[], funcs: ((...args: any) => any)[]) {
|
|
45
|
+
for (let i = 0; i < names.length; i++) {
|
|
46
|
+
this.setFunction(names[i], funcs[i]);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
addTool(tool: Tool) {
|
|
51
|
+
this.tools.push(tool);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
addTools(tools: Tool[]) {
|
|
55
|
+
this.tools.push(...tools);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
addFunctions(fns: { [fnName: string]: (...args: any) => any }) {
|
|
59
|
+
for (const fnName of Object.keys(fns)) {
|
|
60
|
+
this.setFunction(fnName, fns[fnName]);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export const Tools = new ToolsService();
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export class FlagsService {
|
|
2
|
+
flags = {};
|
|
3
|
+
log = false;
|
|
4
|
+
|
|
5
|
+
constructor(flags: string[] = [], log = false) {
|
|
6
|
+
this.register(flags);
|
|
7
|
+
this.log = log;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
register(flags: string[]) {
|
|
11
|
+
flags.forEach((flag) => {
|
|
12
|
+
this.flags[flag] = false;
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
enable(flag: string) {
|
|
17
|
+
this.flags[flag] = true;
|
|
18
|
+
if (this.log) {
|
|
19
|
+
console.log(`${flag} is now enabled \n`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
disable(flag: string) {
|
|
24
|
+
this.flags[flag] = false;
|
|
25
|
+
if (this.log) {
|
|
26
|
+
console.log(`${flag} is now disabled \n`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
flip(flag: string) {
|
|
31
|
+
this.flags[flag] = !this.flags[flag];
|
|
32
|
+
if (this.log) {
|
|
33
|
+
const status = this.flags[flag] ? "enabled" : "disabled";
|
|
34
|
+
const message = `${flag} is now ${status}`;
|
|
35
|
+
console.log(message);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
enableLogging() {
|
|
40
|
+
this.log = true;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
disableLogging() {
|
|
44
|
+
this.log = false;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
enabled(flag: string): boolean {
|
|
48
|
+
return this.flags[flag];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const Flags = new FlagsService();
|