@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,486 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GoogleGenAI,
|
|
3
|
+
Part,
|
|
4
|
+
Content,
|
|
5
|
+
Tool as GoogleTool, // Rename to avoid conflict with your Tool type
|
|
6
|
+
FunctionDeclaration,
|
|
7
|
+
FunctionCallingConfigMode,
|
|
8
|
+
GenerationConfig,
|
|
9
|
+
ToolConfig,
|
|
10
|
+
UsageMetadata,
|
|
11
|
+
} from "@google/genai";
|
|
12
|
+
import { wait } from "../utils";
|
|
13
|
+
import { Models } from "../types";
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
GenericClient,
|
|
17
|
+
CompletionOptions,
|
|
18
|
+
CompletionResponse,
|
|
19
|
+
EmbeddingOptions,
|
|
20
|
+
EmbeddingResponse,
|
|
21
|
+
Tool,
|
|
22
|
+
Message,
|
|
23
|
+
MessageContent,
|
|
24
|
+
ToolCall,
|
|
25
|
+
OutputMessage,
|
|
26
|
+
} from "./types";
|
|
27
|
+
|
|
28
|
+
function getMimeTypeFromUrl(url: string): string {
|
|
29
|
+
if (url.endsWith(".png")) return "image/png";
|
|
30
|
+
if (url.endsWith(".gif")) return "image/gif";
|
|
31
|
+
if (url.endsWith(".webp")) return "image/webp";
|
|
32
|
+
return "image/jpeg";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export class GenericGeminiClient extends GoogleGenAI implements GenericClient {
|
|
36
|
+
constructor() {
|
|
37
|
+
super({
|
|
38
|
+
apiKey: process.env.GEMINI_API_KEY,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Transforms a generic MessageContent array or string into Google GenAI ContentPart array.
|
|
44
|
+
* Handles text and image_url types.
|
|
45
|
+
* @param content The generic message content.
|
|
46
|
+
* @returns An array of Google GenAI ContentPart.
|
|
47
|
+
*/
|
|
48
|
+
transformContentParts(content: string | MessageContent[]): Part[] {
|
|
49
|
+
if (typeof content === "string") {
|
|
50
|
+
return [{ text: content }];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return content
|
|
54
|
+
.map((part) => {
|
|
55
|
+
if (part.type === "text") {
|
|
56
|
+
return { text: part.text };
|
|
57
|
+
}
|
|
58
|
+
if (part.type === "image_url") {
|
|
59
|
+
// Google GenAI's fileData part type uses a URI.
|
|
60
|
+
// The example uses createPartFromUri which takes a uri string and mimeType.
|
|
61
|
+
// We assume the image_url.url can be used as the uri.
|
|
62
|
+
// Note: Google's example uploads files first and uses the resulting URI.
|
|
63
|
+
// Directly using a URL here might have limitations depending on the URL type
|
|
64
|
+
// (e.g., data URLs vs. public http URLs).
|
|
65
|
+
const mimeType = getMimeTypeFromUrl(part.image_url.url);
|
|
66
|
+
return {
|
|
67
|
+
fileData: {
|
|
68
|
+
uri: part.image_url.url,
|
|
69
|
+
mimeType,
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
// Handle other potential generic message content types if necessary
|
|
74
|
+
// For now, only text and image_url are explicitly handled.
|
|
75
|
+
console.warn(
|
|
76
|
+
`Unsupported generic message content part type: ${(part as any).type}`
|
|
77
|
+
);
|
|
78
|
+
return { text: `[Unsupported content type: ${(part as any).type}]` };
|
|
79
|
+
})
|
|
80
|
+
.filter((part) => !!part); // Filter out any null/undefined parts if transformation fails
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Transforms a generic Message array into a Google GenAI Content array.
|
|
85
|
+
* Extracts system messages separately. Maps user, assistant, and tool roles.
|
|
86
|
+
* Maps OpenAI-style tool messages to Google's functionResponse parts within user roles.
|
|
87
|
+
* Maps OpenAI-style assistant messages with tool_calls to Google's tool_use parts within assistant roles.
|
|
88
|
+
* @param messages The generic message array.
|
|
89
|
+
* @returns An object containing the system instruction (if any) and the Content array for the API call.
|
|
90
|
+
*/
|
|
91
|
+
transformMessages(messages: Message[]): {
|
|
92
|
+
systemInstruction: string | undefined;
|
|
93
|
+
contents: Content[];
|
|
94
|
+
} {
|
|
95
|
+
const googleContents: Content[] = [];
|
|
96
|
+
let systemInstruction: string | undefined;
|
|
97
|
+
|
|
98
|
+
// Temporary storage for assistant tool calls keyed by ID, needed to map tool results
|
|
99
|
+
const assistantToolCalls: { [id: string]: ToolCall } = {};
|
|
100
|
+
|
|
101
|
+
for (const msg of messages) {
|
|
102
|
+
if (msg.role === "system") {
|
|
103
|
+
// System messages go into the systemInstruction field
|
|
104
|
+
if (typeof msg.content === "string") {
|
|
105
|
+
systemInstruction =
|
|
106
|
+
(systemInstruction ? systemInstruction + "\n" : "") + msg.content;
|
|
107
|
+
} else {
|
|
108
|
+
// System message content is typically string, handle array as text parts?
|
|
109
|
+
// Google's systemInstruction is string, so concatenate text parts if array.
|
|
110
|
+
systemInstruction =
|
|
111
|
+
(systemInstruction ? systemInstruction + "\n" : "") +
|
|
112
|
+
this.transformContentParts(msg.content)
|
|
113
|
+
.filter((p) => "text" in p && typeof p.text === "string")
|
|
114
|
+
.map((p) => (p as any).text)
|
|
115
|
+
.join("\n");
|
|
116
|
+
}
|
|
117
|
+
} else if (msg.role === "user" || msg.role === "assistant") {
|
|
118
|
+
const parts = msg.content
|
|
119
|
+
? this.transformContentParts(msg.content)
|
|
120
|
+
: [];
|
|
121
|
+
|
|
122
|
+
// Add tool_use parts if the assistant message has tool_calls
|
|
123
|
+
if (
|
|
124
|
+
msg.role === "assistant" &&
|
|
125
|
+
msg.tool_calls &&
|
|
126
|
+
msg.tool_calls.length > 0
|
|
127
|
+
) {
|
|
128
|
+
for (const toolCall of msg.tool_calls) {
|
|
129
|
+
parts.push({
|
|
130
|
+
functionCall: {
|
|
131
|
+
name: toolCall.function.name,
|
|
132
|
+
// Google expects arguments as a parsed object, not a string
|
|
133
|
+
args: JSON.parse(toolCall.function.arguments || "{}"),
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
// Store the tool call to potentially link with a future tool response message
|
|
137
|
+
assistantToolCalls[toolCall.id] = toolCall;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (parts.length > 0) {
|
|
142
|
+
googleContents.push({
|
|
143
|
+
role: msg.role === "user" ? "user" : "model",
|
|
144
|
+
parts,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
} else if (msg.role === "tool") {
|
|
148
|
+
// OpenAI tool messages represent the *result* of a tool call.
|
|
149
|
+
// Google represents this as a 'functionResponse' part within a 'user' role message.
|
|
150
|
+
// The content of the tool message is the tool output (usually a string).
|
|
151
|
+
// The tool_call_id links it back to the assistant's tool_use part.
|
|
152
|
+
|
|
153
|
+
if (!msg.tool_call_id) {
|
|
154
|
+
throw new Error("Tool message must have a tool_call_id.");
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Ensure content is treated as string for functionResponse
|
|
158
|
+
const toolOutputContent =
|
|
159
|
+
typeof msg.content === "string"
|
|
160
|
+
? msg.content
|
|
161
|
+
: JSON.stringify(msg.content); // Coerce array content to string representation if necessary
|
|
162
|
+
|
|
163
|
+
// Find the matching tool call name from the stored assistant tool calls
|
|
164
|
+
// This is needed for the functionResponse part's name field in Google's API.
|
|
165
|
+
const matchingToolCall = assistantToolCalls[msg.tool_call_id];
|
|
166
|
+
const functionName = matchingToolCall
|
|
167
|
+
? matchingToolCall.function.name
|
|
168
|
+
: "unknown_function";
|
|
169
|
+
|
|
170
|
+
if (!matchingToolCall) {
|
|
171
|
+
console.warn(
|
|
172
|
+
`Matching assistant tool call not found for tool_call_id: ${msg.tool_call_id}. Using name '${functionName}'.`,
|
|
173
|
+
msg
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Add the user message with the functionResponse part
|
|
178
|
+
// Google's API expects the user role for tool results.
|
|
179
|
+
googleContents.push({
|
|
180
|
+
role: "user",
|
|
181
|
+
parts: [
|
|
182
|
+
{
|
|
183
|
+
functionResponse: {
|
|
184
|
+
name: functionName, // Google API requires the function name here
|
|
185
|
+
response: {
|
|
186
|
+
result: toolOutputContent,
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
],
|
|
191
|
+
});
|
|
192
|
+
} else {
|
|
193
|
+
console.warn(
|
|
194
|
+
`Unsupported generic message role: ${msg.role}, skipping.`
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return { systemInstruction, contents: googleContents };
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Transforms generic Tool array into Google GenAI tools format.
|
|
204
|
+
* @param tools The generic tool array.
|
|
205
|
+
* @returns An array of Google GenAI Tool objects, or undefined if no tools.
|
|
206
|
+
*/
|
|
207
|
+
transformTools(tools?: Tool[]): GoogleTool[] | undefined {
|
|
208
|
+
if (!tools || tools.length === 0) {
|
|
209
|
+
return undefined;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const functionDeclarations: FunctionDeclaration[] = tools.map((tool) => {
|
|
213
|
+
for (const key in tool.function.parameters.properties) {
|
|
214
|
+
if (
|
|
215
|
+
!Object.prototype.hasOwnProperty.call(
|
|
216
|
+
tool.function.parameters.properties,
|
|
217
|
+
key
|
|
218
|
+
)
|
|
219
|
+
) {
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
tool.function.parameters.properties[key].type =
|
|
224
|
+
tool.function.parameters.properties[key].type.toUpperCase();
|
|
225
|
+
}
|
|
226
|
+
return {
|
|
227
|
+
name: tool.function.name,
|
|
228
|
+
description: tool.function.description || "",
|
|
229
|
+
// Parameters mapping - need to map your ToolProp structure to Google's OpenAPI subset
|
|
230
|
+
parameters: {
|
|
231
|
+
type: "OBJECT",
|
|
232
|
+
properties: tool.function.parameters.properties, // Assume direct compatibility for properties structure
|
|
233
|
+
required: tool.function.parameters.required || [],
|
|
234
|
+
} as any,
|
|
235
|
+
};
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
// Google's tools structure is an array of objects, where each object
|
|
239
|
+
// can contain 'functionDeclarations', 'googleSearch', 'codeExecution', etc.
|
|
240
|
+
// Based on the provided docs, function calling tools go under `functionDeclarations`.
|
|
241
|
+
return [{ functionDeclarations }];
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
async createChatCompletion(
|
|
245
|
+
options: CompletionOptions
|
|
246
|
+
): Promise<CompletionResponse> {
|
|
247
|
+
const { systemInstruction, contents } = this.transformMessages(
|
|
248
|
+
options.messages
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
try {
|
|
252
|
+
await wait(2000);
|
|
253
|
+
const response = await this.models.generateContent({
|
|
254
|
+
model: options.model,
|
|
255
|
+
contents,
|
|
256
|
+
config: {
|
|
257
|
+
systemInstruction,
|
|
258
|
+
tools: this.transformTools(options.tools),
|
|
259
|
+
maxOutputTokens: options.max_tokens,
|
|
260
|
+
},
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
let toolCalls: ToolCall[] = [];
|
|
264
|
+
|
|
265
|
+
if (response.functionCalls) {
|
|
266
|
+
for (const call of response.functionCalls) {
|
|
267
|
+
toolCalls.push({
|
|
268
|
+
id:
|
|
269
|
+
call.id ||
|
|
270
|
+
`fc_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
|
|
271
|
+
type: "function",
|
|
272
|
+
function: {
|
|
273
|
+
name: call.name,
|
|
274
|
+
arguments: JSON.stringify(call.args || {}),
|
|
275
|
+
},
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
if (response?.promptFeedback?.blockReason) {
|
|
281
|
+
// lame
|
|
282
|
+
throw new Error(
|
|
283
|
+
`Google GenAI blocked the response due to: ${response.promptFeedback.blockReason}`
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// Map Google response to generic CompletionResponse
|
|
288
|
+
const choices: CompletionResponse["choices"] =
|
|
289
|
+
response.candidates?.map((candidate) => {
|
|
290
|
+
const message: OutputMessage = {
|
|
291
|
+
role: candidate.content.role === "model" ? "assistant" : "user",
|
|
292
|
+
content: "", // Initialize content
|
|
293
|
+
tool_calls: [...toolCalls], // Initialize tool calls
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
// Collect text and tool_use parts
|
|
297
|
+
let textContent = "";
|
|
298
|
+
|
|
299
|
+
// after the first message uses the top level tool calls we should empty it
|
|
300
|
+
if (toolCalls.length) {
|
|
301
|
+
toolCalls = [];
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
if (!candidate?.content?.parts) {
|
|
305
|
+
console.warn("No content parts in candidate:", candidate);
|
|
306
|
+
return { message };
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
candidate?.content?.parts?.forEach((part) => {
|
|
310
|
+
if ("text" in part && typeof part.text === "string") {
|
|
311
|
+
textContent += part.text; // Concatenate text parts
|
|
312
|
+
} else if ("functionCall" in part && part.functionCall) {
|
|
313
|
+
message.tool_calls.push({
|
|
314
|
+
id:
|
|
315
|
+
part.functionCall.id ||
|
|
316
|
+
`fc_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
|
|
317
|
+
type: "function",
|
|
318
|
+
function: {
|
|
319
|
+
name: part.functionCall.name,
|
|
320
|
+
arguments: JSON.stringify(part.functionCall.args || {}),
|
|
321
|
+
},
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
message.content = textContent || null;
|
|
327
|
+
|
|
328
|
+
return { message };
|
|
329
|
+
}) || []; // Handle case with no candidates
|
|
330
|
+
|
|
331
|
+
const usage = response.usageMetadata;
|
|
332
|
+
const usdCost = usage
|
|
333
|
+
? this.calculateCost(options.model, usage)
|
|
334
|
+
: undefined;
|
|
335
|
+
|
|
336
|
+
return {
|
|
337
|
+
choices,
|
|
338
|
+
model: options.model,
|
|
339
|
+
usage,
|
|
340
|
+
usd_cost: usdCost,
|
|
341
|
+
};
|
|
342
|
+
} catch (error) {
|
|
343
|
+
console.error("Error calling Google GenAI generateContent:", error);
|
|
344
|
+
throw error;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
pricesPerMillion(): { [key: string]: any } {
|
|
349
|
+
return {
|
|
350
|
+
[Models.google.Gemini_25_Flash_Preview]: {
|
|
351
|
+
input: 0.15,
|
|
352
|
+
output: 0.6,
|
|
353
|
+
thinking_output: 3.5,
|
|
354
|
+
context_caching: 0.0375,
|
|
355
|
+
},
|
|
356
|
+
[Models.google.Gemini_25_Pro_Preview]: {
|
|
357
|
+
input: 1.25,
|
|
358
|
+
output: 10.0,
|
|
359
|
+
context_caching: 0.31,
|
|
360
|
+
},
|
|
361
|
+
[Models.google.Gemini_20_Flash]: {
|
|
362
|
+
input: 0.1,
|
|
363
|
+
output: 0.4,
|
|
364
|
+
context_caching: 0.025,
|
|
365
|
+
},
|
|
366
|
+
[Models.google.Gemini_20_Flash_Preview_Image_Generation]: {
|
|
367
|
+
input: 0.1,
|
|
368
|
+
output: 0.4,
|
|
369
|
+
image_generation: 0.039,
|
|
370
|
+
},
|
|
371
|
+
[Models.google.Gemini_20_Flash_Lite]: {
|
|
372
|
+
input: 0.075,
|
|
373
|
+
output: 0.3,
|
|
374
|
+
},
|
|
375
|
+
[Models.google.Gemini_15_Flash]: {
|
|
376
|
+
input: 0.075,
|
|
377
|
+
output: 0.3,
|
|
378
|
+
context_caching: 0.01875,
|
|
379
|
+
},
|
|
380
|
+
[Models.google.Gemini_15_Flash_8B]: {
|
|
381
|
+
input: 0.0375,
|
|
382
|
+
output: 0.15,
|
|
383
|
+
context_caching: 0.01,
|
|
384
|
+
},
|
|
385
|
+
[Models.google.Gemini_15_Pro]: {
|
|
386
|
+
input: 1.25,
|
|
387
|
+
output: 5.0,
|
|
388
|
+
context_caching: 0.3125,
|
|
389
|
+
},
|
|
390
|
+
[Models.google.Imagen_3]: {
|
|
391
|
+
image_generation: 0.03,
|
|
392
|
+
},
|
|
393
|
+
[Models.google.Veo_2]: {
|
|
394
|
+
video_generation: 0.35,
|
|
395
|
+
},
|
|
396
|
+
[Models.google.Gemini_Embedding]: {
|
|
397
|
+
input: 0, // Free of charge
|
|
398
|
+
output: 0, // Free of charge
|
|
399
|
+
},
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
calculateCost(model: string, usage: UsageMetadata): number | undefined {
|
|
404
|
+
const pricing = this.pricesPerMillion()[model];
|
|
405
|
+
if (!pricing || !usage) {
|
|
406
|
+
return 0;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
let cost = 0;
|
|
410
|
+
|
|
411
|
+
if ("promptTokenCount" in usage && usage.promptTokenCount) {
|
|
412
|
+
cost += (usage.promptTokenCount * pricing.input) / 1e6;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
if ("responseTokenCount" in usage && usage.responseTokenCount) {
|
|
416
|
+
cost += (usage.responseTokenCount * pricing.output) / 1e6;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
if (
|
|
420
|
+
"cachedContentTokenCount" in usage &&
|
|
421
|
+
usage.cachedContentTokenCount &&
|
|
422
|
+
pricing.context_caching
|
|
423
|
+
) {
|
|
424
|
+
cost += (usage.cachedContentTokenCount * pricing.context_caching) / 1e6;
|
|
425
|
+
}
|
|
426
|
+
return cost;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
async getModels() {
|
|
430
|
+
try {
|
|
431
|
+
const models = await this.models.list();
|
|
432
|
+
return models.page.map((m) => ({
|
|
433
|
+
id: m.name!,
|
|
434
|
+
}));
|
|
435
|
+
} catch (error) {
|
|
436
|
+
console.error("Error fetching Google GenAI models:", error);
|
|
437
|
+
throw error;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
async createEmbedding(options: EmbeddingOptions): Promise<EmbeddingResponse> {
|
|
442
|
+
if (!options.model) {
|
|
443
|
+
console.warn(
|
|
444
|
+
"Embedding model not specified, using default 'text-embedding-004'."
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
try {
|
|
449
|
+
const googleEmbedding = await this.models.embedContent({
|
|
450
|
+
model: options.model,
|
|
451
|
+
contents: options.input,
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
console.log(
|
|
455
|
+
JSON.stringify({ googleEmbeddingResponse: googleEmbedding }, null, 2)
|
|
456
|
+
);
|
|
457
|
+
|
|
458
|
+
// Map Google EmbeddingResponse to generic EmbeddingResponse
|
|
459
|
+
const data = googleEmbedding.embeddings.map((e, index) => ({
|
|
460
|
+
object: "embedding", // Hardcode as per OpenAI's object type for embeddings
|
|
461
|
+
embedding: e.values, // Google's embedding values
|
|
462
|
+
index, // Use array index
|
|
463
|
+
}));
|
|
464
|
+
|
|
465
|
+
const usage = {
|
|
466
|
+
promptTokenCount: googleEmbedding.metadata.billableCharacterCount || 0,
|
|
467
|
+
totalTokenCount: googleEmbedding.metadata.billableCharacterCount || 0,
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
const usdCost = this.calculateCost(options.model, usage);
|
|
471
|
+
|
|
472
|
+
return {
|
|
473
|
+
data,
|
|
474
|
+
model: options.model,
|
|
475
|
+
usage: {
|
|
476
|
+
prompt_tokens: usage.promptTokenCount,
|
|
477
|
+
total_tokens: usage.totalTokenCount,
|
|
478
|
+
},
|
|
479
|
+
usd_cost: usdCost,
|
|
480
|
+
};
|
|
481
|
+
} catch (error) {
|
|
482
|
+
console.error("Error calling Google GenAI embedContent:", error);
|
|
483
|
+
throw error;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import {
|
|
3
|
+
GenericClient,
|
|
4
|
+
CompletionOptions,
|
|
5
|
+
CompletionResponse,
|
|
6
|
+
EmbeddingOptions,
|
|
7
|
+
EmbeddingResponse,
|
|
8
|
+
} from "./types";
|
|
9
|
+
import fs from "fs";
|
|
10
|
+
import path from "path";
|
|
11
|
+
|
|
12
|
+
export class HttpClient implements GenericClient {
|
|
13
|
+
constructor(private baseUrl: string, private headers = {}) {}
|
|
14
|
+
|
|
15
|
+
setJwt(jwt: string) {
|
|
16
|
+
this.headers = {
|
|
17
|
+
...this.headers,
|
|
18
|
+
Authorization: `Bearer ${jwt}`,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
setBaseUrl(baseUrl: string) {
|
|
23
|
+
this.baseUrl = baseUrl;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
loadJwtFile(filePath: string) {
|
|
27
|
+
try {
|
|
28
|
+
const jwtFile = path.join(process.cwd(), filePath);
|
|
29
|
+
if (!fs.existsSync(jwtFile)) {
|
|
30
|
+
throw new Error(`JWT file not found: ${filePath}`);
|
|
31
|
+
}
|
|
32
|
+
const jwt = fs.readFileSync(jwtFile, "utf-8").trim();
|
|
33
|
+
this.setJwt(jwt);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.error(`Error loading JWT file: ${error}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async createChatCompletion(
|
|
40
|
+
options: CompletionOptions
|
|
41
|
+
): Promise<CompletionResponse> {
|
|
42
|
+
const response = await axios.post(
|
|
43
|
+
`${this.baseUrl}/v1/chat/completions`,
|
|
44
|
+
{
|
|
45
|
+
model: options.model,
|
|
46
|
+
messages: options.messages,
|
|
47
|
+
max_tokens: options.max_tokens,
|
|
48
|
+
tools: options.tools,
|
|
49
|
+
tool_choice: options.tool_choice,
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
headers: this.headers,
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const data = response.data;
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
choices: data.choices.map((choice: any) => ({
|
|
60
|
+
message: {
|
|
61
|
+
role: choice.message.role,
|
|
62
|
+
content: choice.message.content,
|
|
63
|
+
tool_calls: choice.message.tool_calls,
|
|
64
|
+
},
|
|
65
|
+
})),
|
|
66
|
+
model: data.model,
|
|
67
|
+
usage: data.usage,
|
|
68
|
+
usd_cost: data.usd_cost,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async createEmbedding(options: EmbeddingOptions): Promise<EmbeddingResponse> {
|
|
73
|
+
const response = await axios.post(
|
|
74
|
+
`${this.baseUrl}/v1/embeddings`,
|
|
75
|
+
{
|
|
76
|
+
model: options.model,
|
|
77
|
+
input: options.input,
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
headers: this.headers,
|
|
81
|
+
}
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const data = response.data;
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
data: data.data,
|
|
88
|
+
model: options.model,
|
|
89
|
+
usage: data.usage,
|
|
90
|
+
usd_cost: data.usd_cost,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async getModels() {
|
|
95
|
+
const response = await axios.get(`${this.baseUrl}/v1/models`, {
|
|
96
|
+
headers: this.headers,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const data = response.data?.data;
|
|
100
|
+
|
|
101
|
+
return data.map((model: any) => ({
|
|
102
|
+
id: model.id,
|
|
103
|
+
object: model.object,
|
|
104
|
+
owned_by: model.owned_by,
|
|
105
|
+
}));
|
|
106
|
+
}
|
|
107
|
+
}
|