@travisennis/acai 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/.acai/acai.json +9 -0
- package/.acai/prompts/add-openrouter-model.md +13 -0
- package/.acai/prompts/project-status.md +4 -0
- package/.acai/prompts/update-architecture-document.md +9 -0
- package/.acai/rules/learned-rules.md +9 -0
- package/.ai/docs/available-tools.txt +3 -0
- package/.ai/docs/cognitive_complexity_refactoring_progress.md +65 -0
- package/.ai/docs/deleted_tools.md +168 -0
- package/.ai/docs/deleted_tools_88ced9ef.md +56 -0
- package/.ai/docs/image-pasting.md +46 -0
- package/.ai/docs/initialize-app.md +117 -0
- package/.ai/docs/issue-4-plan.md +44 -0
- package/.ai/docs/marked-renderer-debug.md +15 -0
- package/.ai/docs/marked-renderer-refactor-plan.md +64 -0
- package/.ai/docs/memory-use-cases.md +55 -0
- package/.ai/docs/prompt-consistency.md +31 -0
- package/.ai/docs/refactoring-tools.md +98 -0
- package/.ai/docs/system-prompt-update.md +174 -0
- package/.ai/docs/system_prompt.txt +210 -0
- package/.ai/docs/tasks.md +49 -0
- package/.ai/plan.md +131 -0
- package/.ai/prompt.md +1 -0
- package/.ai/scripts/fetch_models.js +27 -0
- package/.ai/scripts/generateSystemPrompt.ts +15 -0
- package/.ai/scripts/list-tools.mjs +4 -0
- package/.ai/scripts/p5_geometric_shapes.js +149 -0
- package/.husky/commit-msg +1 -0
- package/.husky/pre-commit +3 -0
- package/.husky/pre-push +1 -0
- package/.ignore +4 -0
- package/AGENTS.md +25 -0
- package/ARCHITECTURE.md +304 -0
- package/LICENSE +21 -0
- package/README.md +392 -0
- package/TODO.md +2 -0
- package/biome.json +61 -0
- package/commitlint.config.js +3 -0
- package/dist/cli.d.ts +19 -0
- package/dist/cli.js +116 -0
- package/dist/commands/application-log-command.d.ts +2 -0
- package/dist/commands/application-log-command.js +43 -0
- package/dist/commands/clear-command.d.ts +2 -0
- package/dist/commands/clear-command.js +12 -0
- package/dist/commands/compact-command.d.ts +2 -0
- package/dist/commands/compact-command.js +51 -0
- package/dist/commands/copy-command.d.ts +2 -0
- package/dist/commands/copy-command.js +51 -0
- package/dist/commands/edit-command.d.ts +2 -0
- package/dist/commands/edit-command.js +53 -0
- package/dist/commands/edit-prompt-command.d.ts +2 -0
- package/dist/commands/edit-prompt-command.js +25 -0
- package/dist/commands/exit-command.d.ts +2 -0
- package/dist/commands/exit-command.js +14 -0
- package/dist/commands/files-command.d.ts +2 -0
- package/dist/commands/files-command.js +63 -0
- package/dist/commands/generate-rules-command.d.ts +2 -0
- package/dist/commands/generate-rules-command.js +61 -0
- package/dist/commands/help-command.d.ts +2 -0
- package/dist/commands/help-command.js +19 -0
- package/dist/commands/init-command.d.ts +2 -0
- package/dist/commands/init-command.js +40 -0
- package/dist/commands/last-log-command.d.ts +2 -0
- package/dist/commands/last-log-command.js +76 -0
- package/dist/commands/manager.d.ts +22 -0
- package/dist/commands/manager.js +123 -0
- package/dist/commands/model-command.d.ts +2 -0
- package/dist/commands/model-command.js +84 -0
- package/dist/commands/paste-command.d.ts +2 -0
- package/dist/commands/paste-command.js +40 -0
- package/dist/commands/prompt-command.d.ts +2 -0
- package/dist/commands/prompt-command.js +111 -0
- package/dist/commands/reset-command.d.ts +2 -0
- package/dist/commands/reset-command.js +16 -0
- package/dist/commands/rules-command.d.ts +2 -0
- package/dist/commands/rules-command.js +68 -0
- package/dist/commands/save-command.d.ts +2 -0
- package/dist/commands/save-command.js +14 -0
- package/dist/commands/types.d.ts +26 -0
- package/dist/commands/types.js +1 -0
- package/dist/commands/usage-command.d.ts +2 -0
- package/dist/commands/usage-command.js +21 -0
- package/dist/config.d.ts +60 -0
- package/dist/config.js +193 -0
- package/dist/conversation-analyzer.d.ts +10 -0
- package/dist/conversation-analyzer.js +88 -0
- package/dist/dedent.d.ts +3 -0
- package/dist/dedent.js +38 -0
- package/dist/formatting.d.ts +17 -0
- package/dist/formatting.js +103 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +213 -0
- package/dist/logger.d.ts +2 -0
- package/dist/logger.js +24 -0
- package/dist/mentions.d.ts +9 -0
- package/dist/mentions.js +182 -0
- package/dist/messages.d.ts +69 -0
- package/dist/messages.js +261 -0
- package/dist/middleware/audit-message.d.ts +5 -0
- package/dist/middleware/audit-message.js +95 -0
- package/dist/middleware/index.d.ts +2 -0
- package/dist/middleware/index.js +2 -0
- package/dist/middleware/rate-limit.d.ts +4 -0
- package/dist/middleware/rate-limit.js +17 -0
- package/dist/models/ai-config.d.ts +12 -0
- package/dist/models/ai-config.js +87 -0
- package/dist/models/anthropic-provider.d.ts +25 -0
- package/dist/models/anthropic-provider.js +184 -0
- package/dist/models/deepseek-provider.d.ts +20 -0
- package/dist/models/deepseek-provider.js +42 -0
- package/dist/models/google-provider.d.ts +19 -0
- package/dist/models/google-provider.js +56 -0
- package/dist/models/manager.d.ts +15 -0
- package/dist/models/manager.js +48 -0
- package/dist/models/openai-provider.d.ts +22 -0
- package/dist/models/openai-provider.js +70 -0
- package/dist/models/openrouter-provider.d.ts +36 -0
- package/dist/models/openrouter-provider.js +276 -0
- package/dist/models/providers.d.ts +33 -0
- package/dist/models/providers.js +116 -0
- package/dist/models/xai-provider.d.ts +20 -0
- package/dist/models/xai-provider.js +47 -0
- package/dist/parsing.d.ts +2 -0
- package/dist/parsing.js +18 -0
- package/dist/prompts/manager.d.ts +19 -0
- package/dist/prompts/manager.js +71 -0
- package/dist/prompts.d.ts +4 -0
- package/dist/prompts.js +158 -0
- package/dist/repl-prompt.d.ts +14 -0
- package/dist/repl-prompt.js +147 -0
- package/dist/repl.d.ts +27 -0
- package/dist/repl.js +431 -0
- package/dist/source/cli.d.ts +19 -0
- package/dist/source/cli.js +116 -0
- package/dist/source/commands/application-log-command.d.ts +2 -0
- package/dist/source/commands/application-log-command.js +43 -0
- package/dist/source/commands/clear-command.d.ts +2 -0
- package/dist/source/commands/clear-command.js +12 -0
- package/dist/source/commands/compact-command.d.ts +2 -0
- package/dist/source/commands/compact-command.js +51 -0
- package/dist/source/commands/copy-command.d.ts +2 -0
- package/dist/source/commands/copy-command.js +51 -0
- package/dist/source/commands/edit-command.d.ts +2 -0
- package/dist/source/commands/edit-command.js +53 -0
- package/dist/source/commands/edit-prompt-command.d.ts +2 -0
- package/dist/source/commands/edit-prompt-command.js +25 -0
- package/dist/source/commands/exit-command.d.ts +2 -0
- package/dist/source/commands/exit-command.js +14 -0
- package/dist/source/commands/files-command.d.ts +2 -0
- package/dist/source/commands/files-command.js +63 -0
- package/dist/source/commands/generate-rules-command.d.ts +2 -0
- package/dist/source/commands/generate-rules-command.js +61 -0
- package/dist/source/commands/help-command.d.ts +2 -0
- package/dist/source/commands/help-command.js +19 -0
- package/dist/source/commands/init-command.d.ts +2 -0
- package/dist/source/commands/init-command.js +40 -0
- package/dist/source/commands/last-log-command.d.ts +2 -0
- package/dist/source/commands/last-log-command.js +76 -0
- package/dist/source/commands/manager.d.ts +22 -0
- package/dist/source/commands/manager.js +123 -0
- package/dist/source/commands/model-command.d.ts +2 -0
- package/dist/source/commands/model-command.js +84 -0
- package/dist/source/commands/paste-command.d.ts +2 -0
- package/dist/source/commands/paste-command.js +40 -0
- package/dist/source/commands/prompt-command.d.ts +2 -0
- package/dist/source/commands/prompt-command.js +111 -0
- package/dist/source/commands/reset-command.d.ts +2 -0
- package/dist/source/commands/reset-command.js +16 -0
- package/dist/source/commands/rules-command.d.ts +2 -0
- package/dist/source/commands/rules-command.js +68 -0
- package/dist/source/commands/save-command.d.ts +2 -0
- package/dist/source/commands/save-command.js +14 -0
- package/dist/source/commands/types.d.ts +26 -0
- package/dist/source/commands/types.js +1 -0
- package/dist/source/commands/usage-command.d.ts +2 -0
- package/dist/source/commands/usage-command.js +21 -0
- package/dist/source/config.d.ts +60 -0
- package/dist/source/config.js +193 -0
- package/dist/source/conversation-analyzer.d.ts +10 -0
- package/dist/source/conversation-analyzer.js +88 -0
- package/dist/source/dedent.d.ts +3 -0
- package/dist/source/dedent.js +38 -0
- package/dist/source/formatting.d.ts +17 -0
- package/dist/source/formatting.js +103 -0
- package/dist/source/index.d.ts +18 -0
- package/dist/source/index.js +213 -0
- package/dist/source/logger.d.ts +2 -0
- package/dist/source/logger.js +24 -0
- package/dist/source/mentions.d.ts +9 -0
- package/dist/source/mentions.js +182 -0
- package/dist/source/messages.d.ts +69 -0
- package/dist/source/messages.js +261 -0
- package/dist/source/middleware/audit-message.d.ts +5 -0
- package/dist/source/middleware/audit-message.js +95 -0
- package/dist/source/middleware/index.d.ts +2 -0
- package/dist/source/middleware/index.js +2 -0
- package/dist/source/middleware/rate-limit.d.ts +4 -0
- package/dist/source/middleware/rate-limit.js +17 -0
- package/dist/source/models/ai-config.d.ts +12 -0
- package/dist/source/models/ai-config.js +87 -0
- package/dist/source/models/anthropic-provider.d.ts +25 -0
- package/dist/source/models/anthropic-provider.js +184 -0
- package/dist/source/models/deepseek-provider.d.ts +20 -0
- package/dist/source/models/deepseek-provider.js +42 -0
- package/dist/source/models/google-provider.d.ts +19 -0
- package/dist/source/models/google-provider.js +56 -0
- package/dist/source/models/manager.d.ts +15 -0
- package/dist/source/models/manager.js +48 -0
- package/dist/source/models/openai-provider.d.ts +22 -0
- package/dist/source/models/openai-provider.js +70 -0
- package/dist/source/models/openrouter-provider.d.ts +36 -0
- package/dist/source/models/openrouter-provider.js +276 -0
- package/dist/source/models/providers.d.ts +33 -0
- package/dist/source/models/providers.js +116 -0
- package/dist/source/models/xai-provider.d.ts +20 -0
- package/dist/source/models/xai-provider.js +47 -0
- package/dist/source/parsing.d.ts +2 -0
- package/dist/source/parsing.js +18 -0
- package/dist/source/prompts/manager.d.ts +19 -0
- package/dist/source/prompts/manager.js +71 -0
- package/dist/source/prompts.d.ts +4 -0
- package/dist/source/prompts.js +158 -0
- package/dist/source/repl-prompt.d.ts +14 -0
- package/dist/source/repl-prompt.js +147 -0
- package/dist/source/repl.d.ts +27 -0
- package/dist/source/repl.js +431 -0
- package/dist/source/terminal/formatting.d.ts +37 -0
- package/dist/source/terminal/formatting.js +106 -0
- package/dist/source/terminal/index.d.ts +94 -0
- package/dist/source/terminal/index.js +420 -0
- package/dist/source/terminal/markdown-utils.d.ts +2 -0
- package/dist/source/terminal/markdown-utils.js +81 -0
- package/dist/source/terminal/markdown.d.ts +1 -0
- package/dist/source/terminal/markdown.js +111 -0
- package/dist/source/terminal/types.d.ts +71 -0
- package/dist/source/terminal/types.js +1 -0
- package/dist/source/terminal-output.d.ts +8 -0
- package/dist/source/terminal-output.js +213 -0
- package/dist/source/terminal-output.test.d.ts +8 -0
- package/dist/source/terminal-output.test.js +213 -0
- package/dist/source/token-tracker.d.ts +14 -0
- package/dist/source/token-tracker.js +53 -0
- package/dist/source/token-utils.d.ts +7 -0
- package/dist/source/token-utils.js +13 -0
- package/dist/source/tools/agent.d.ts +17 -0
- package/dist/source/tools/agent.js +87 -0
- package/dist/source/tools/bash.d.ts +19 -0
- package/dist/source/tools/bash.js +294 -0
- package/dist/source/tools/code-interpreter.d.ts +12 -0
- package/dist/source/tools/code-interpreter.js +131 -0
- package/dist/source/tools/command-validation.d.ts +8 -0
- package/dist/source/tools/command-validation.js +69 -0
- package/dist/source/tools/delete-file.d.ts +12 -0
- package/dist/source/tools/delete-file.js +56 -0
- package/dist/source/tools/directory-tree.d.ts +12 -0
- package/dist/source/tools/directory-tree.js +38 -0
- package/dist/source/tools/edit-file.d.ts +19 -0
- package/dist/source/tools/edit-file.js +107 -0
- package/dist/source/tools/filesystem-utils.d.ts +22 -0
- package/dist/source/tools/filesystem-utils.js +191 -0
- package/dist/source/tools/git-utils.d.ts +14 -0
- package/dist/source/tools/git-utils.js +64 -0
- package/dist/source/tools/grep.d.ts +17 -0
- package/dist/source/tools/grep.js +138 -0
- package/dist/source/tools/index.d.ts +161 -0
- package/dist/source/tools/index.js +209 -0
- package/dist/source/tools/memory-read.d.ts +13 -0
- package/dist/source/tools/memory-read.js +135 -0
- package/dist/source/tools/memory-write.d.ts +12 -0
- package/dist/source/tools/memory-write.js +83 -0
- package/dist/source/tools/move-file.d.ts +13 -0
- package/dist/source/tools/move-file.js +44 -0
- package/dist/source/tools/read-file.d.ts +17 -0
- package/dist/source/tools/read-file.js +86 -0
- package/dist/source/tools/read-multiple-files.d.ts +14 -0
- package/dist/source/tools/read-multiple-files.js +55 -0
- package/dist/source/tools/save-file.d.ts +17 -0
- package/dist/source/tools/save-file.js +98 -0
- package/dist/source/tools/think.d.ts +11 -0
- package/dist/source/tools/think.js +45 -0
- package/dist/source/tools/types.d.ts +29 -0
- package/dist/source/tools/types.js +14 -0
- package/dist/source/tools/web-fetch.d.ts +47 -0
- package/dist/source/tools/web-fetch.js +246 -0
- package/dist/source/tools/web-search.d.ts +13 -0
- package/dist/source/tools/web-search.js +80 -0
- package/dist/source/utils/process.d.ts +36 -0
- package/dist/source/utils/process.js +75 -0
- package/dist/source/version.d.ts +1 -0
- package/dist/source/version.js +21 -0
- package/dist/terminal/formatting.d.ts +37 -0
- package/dist/terminal/formatting.js +106 -0
- package/dist/terminal/index.d.ts +94 -0
- package/dist/terminal/index.js +420 -0
- package/dist/terminal/markdown-utils.d.ts +2 -0
- package/dist/terminal/markdown-utils.js +81 -0
- package/dist/terminal/markdown.d.ts +1 -0
- package/dist/terminal/markdown.js +111 -0
- package/dist/terminal/types.d.ts +71 -0
- package/dist/terminal/types.js +1 -0
- package/dist/terminal-output.d.ts +8 -0
- package/dist/terminal-output.js +213 -0
- package/dist/token-tracker.d.ts +14 -0
- package/dist/token-tracker.js +53 -0
- package/dist/token-utils.d.ts +7 -0
- package/dist/token-utils.js +13 -0
- package/dist/tools/agent.d.ts +17 -0
- package/dist/tools/agent.js +87 -0
- package/dist/tools/bash.d.ts +19 -0
- package/dist/tools/bash.js +294 -0
- package/dist/tools/code-interpreter.d.ts +12 -0
- package/dist/tools/code-interpreter.js +131 -0
- package/dist/tools/command-validation.d.ts +8 -0
- package/dist/tools/command-validation.js +69 -0
- package/dist/tools/delete-file.d.ts +12 -0
- package/dist/tools/delete-file.js +56 -0
- package/dist/tools/directory-tree.d.ts +12 -0
- package/dist/tools/directory-tree.js +38 -0
- package/dist/tools/edit-file.d.ts +19 -0
- package/dist/tools/edit-file.js +107 -0
- package/dist/tools/filesystem-utils.d.ts +22 -0
- package/dist/tools/filesystem-utils.js +191 -0
- package/dist/tools/git-utils.d.ts +14 -0
- package/dist/tools/git-utils.js +64 -0
- package/dist/tools/grep.d.ts +17 -0
- package/dist/tools/grep.js +138 -0
- package/dist/tools/index.d.ts +161 -0
- package/dist/tools/index.js +209 -0
- package/dist/tools/memory-read.d.ts +13 -0
- package/dist/tools/memory-read.js +135 -0
- package/dist/tools/memory-write.d.ts +12 -0
- package/dist/tools/memory-write.js +83 -0
- package/dist/tools/move-file.d.ts +13 -0
- package/dist/tools/move-file.js +44 -0
- package/dist/tools/read-file.d.ts +17 -0
- package/dist/tools/read-file.js +86 -0
- package/dist/tools/read-multiple-files.d.ts +14 -0
- package/dist/tools/read-multiple-files.js +55 -0
- package/dist/tools/save-file.d.ts +17 -0
- package/dist/tools/save-file.js +98 -0
- package/dist/tools/think.d.ts +11 -0
- package/dist/tools/think.js +45 -0
- package/dist/tools/types.d.ts +29 -0
- package/dist/tools/types.js +14 -0
- package/dist/tools/web-fetch.d.ts +47 -0
- package/dist/tools/web-fetch.js +246 -0
- package/dist/tools/web-search.d.ts +13 -0
- package/dist/tools/web-search.js +80 -0
- package/dist/utils/process.d.ts +36 -0
- package/dist/utils/process.js +75 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +21 -0
- package/knip.json +5 -0
- package/package.json +83 -0
- package/source/cli.ts +172 -0
- package/source/commands/application-log-command.ts +53 -0
- package/source/commands/clear-command.ts +14 -0
- package/source/commands/compact-command.ts +64 -0
- package/source/commands/copy-command.ts +55 -0
- package/source/commands/edit-command.ts +63 -0
- package/source/commands/edit-prompt-command.ts +31 -0
- package/source/commands/exit-command.ts +18 -0
- package/source/commands/files-command.ts +85 -0
- package/source/commands/generate-rules-command.ts +82 -0
- package/source/commands/help-command.ts +27 -0
- package/source/commands/init-command.ts +48 -0
- package/source/commands/last-log-command.ts +88 -0
- package/source/commands/manager.ts +151 -0
- package/source/commands/model-command.ts +123 -0
- package/source/commands/paste-command.ts +62 -0
- package/source/commands/prompt-command.ts +150 -0
- package/source/commands/reset-command.ts +22 -0
- package/source/commands/rules-command.ts +76 -0
- package/source/commands/save-command.ts +20 -0
- package/source/commands/types.ts +28 -0
- package/source/commands/usage-command.ts +26 -0
- package/source/config.ts +223 -0
- package/source/conversation-analyzer.ts +115 -0
- package/source/dedent.ts +53 -0
- package/source/formatting.ts +132 -0
- package/source/index.ts +240 -0
- package/source/logger.ts +29 -0
- package/source/mentions.ts +227 -0
- package/source/messages.ts +360 -0
- package/source/middleware/audit-message.ts +133 -0
- package/source/middleware/index.ts +2 -0
- package/source/middleware/rate-limit.ts +24 -0
- package/source/models/ai-config.ts +109 -0
- package/source/models/anthropic-provider.ts +199 -0
- package/source/models/deepseek-provider.ts +53 -0
- package/source/models/google-provider.ts +68 -0
- package/source/models/manager.ts +84 -0
- package/source/models/openai-provider.ts +81 -0
- package/source/models/openrouter-provider.ts +288 -0
- package/source/models/providers.ts +197 -0
- package/source/models/xai-provider.ts +59 -0
- package/source/parsing.ts +20 -0
- package/source/prompts/manager.ts +90 -0
- package/source/prompts.ts +172 -0
- package/source/repl-prompt.ts +196 -0
- package/source/repl.ts +572 -0
- package/source/terminal/formatting.ts +121 -0
- package/source/terminal/index.ts +518 -0
- package/source/terminal/markdown-utils.ts +89 -0
- package/source/terminal/markdown.ts +155 -0
- package/source/terminal/types.ts +84 -0
- package/source/terminal-output.test.ts +266 -0
- package/source/token-tracker.ts +78 -0
- package/source/token-utils.ts +17 -0
- package/source/tools/agent.ts +107 -0
- package/source/tools/bash.ts +367 -0
- package/source/tools/code-interpreter.ts +172 -0
- package/source/tools/command-validation.ts +81 -0
- package/source/tools/delete-file.ts +71 -0
- package/source/tools/directory-tree.ts +54 -0
- package/source/tools/edit-file.ts +155 -0
- package/source/tools/filesystem-utils.ts +265 -0
- package/source/tools/git-utils.ts +70 -0
- package/source/tools/grep.ts +184 -0
- package/source/tools/index.ts +278 -0
- package/source/tools/memory-read.ts +174 -0
- package/source/tools/memory-write.ts +105 -0
- package/source/tools/move-file.ts +59 -0
- package/source/tools/read-file.ts +129 -0
- package/source/tools/read-multiple-files.ts +80 -0
- package/source/tools/save-file.ts +147 -0
- package/source/tools/think.ts +51 -0
- package/source/tools/types.ts +58 -0
- package/source/tools/web-fetch.ts +327 -0
- package/source/tools/web-search.ts +101 -0
- package/source/utils/process.ts +121 -0
- package/source/version.ts +21 -0
- package/test/commands/copy-command.test.ts +69 -0
- package/test/config.test.ts +200 -0
- package/test/terminal/markdown-utils.test.ts +124 -0
- package/test/tools/bash-tool.test.ts +58 -0
- package/test/tools/code-interpreter.test.ts +91 -0
- package/test/tools/command-validation.test.ts +48 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +30 -0
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
2
|
+
import { objectKeys } from "@travisennis/stdlib/object";
|
|
3
|
+
import { customProvider } from "ai";
|
|
4
|
+
import type { ModelMetadata } from "./providers.ts";
|
|
5
|
+
|
|
6
|
+
const openRouterClient = createOpenAICompatible({
|
|
7
|
+
name: "openrouter",
|
|
8
|
+
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
|
|
9
|
+
// biome-ignore lint/style/useNamingConvention: third-party controlled
|
|
10
|
+
baseURL: "https://openrouter.ai/api/v1",
|
|
11
|
+
headers: {
|
|
12
|
+
"HTTP-Referer": "https://github.com/travisennis/acai-ts",
|
|
13
|
+
"X-Title": "acai",
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const openrouterModels = {
|
|
18
|
+
"deepseek-v3": openRouterClient("deepseek/deepseek-chat-v3-0324"),
|
|
19
|
+
"deepseek-r1": openRouterClient("deepseek/deepseek-r1-0528"),
|
|
20
|
+
"deepseek-v3-free": openRouterClient("deepseek/deepseek-chat-v3-0324:free"),
|
|
21
|
+
"deepseek-r1-free": openRouterClient("deepseek/deepseek-r1-0528:free"),
|
|
22
|
+
"gemini-flash25": openRouterClient("google/gemini-2.5-flash"),
|
|
23
|
+
"gemini-pro25": openRouterClient("google/gemini-2.5-pro"),
|
|
24
|
+
sonnet4: openRouterClient("anthropic/claude-sonnet-4"),
|
|
25
|
+
opus4: openRouterClient("anthropic/claude-opus-4"),
|
|
26
|
+
"opus-4.1": openRouterClient("anthropic/claude-opus-4.1"),
|
|
27
|
+
"gpt-4.1": openRouterClient("openai/gpt-4.1"),
|
|
28
|
+
"kimi-k2": openRouterClient("moonshotai/kimi-k2:nitro"),
|
|
29
|
+
"kimi-k2-free": openRouterClient("moonshotai/kimi-k2:free"),
|
|
30
|
+
"devstral-medium": openRouterClient("mistralai/devstral-medium"),
|
|
31
|
+
"qwen3-coder": openRouterClient("qwen/qwen3-coder"),
|
|
32
|
+
"qwen3-coder-free": openRouterClient("qwen/qwen3-coder:free"),
|
|
33
|
+
"glm-4.5": openRouterClient("z-ai/glm-4.5"),
|
|
34
|
+
"gpt-5": openRouterClient("openai/gpt-5"),
|
|
35
|
+
"gpt-5-mini": openRouterClient("openai/gpt-5-mini"),
|
|
36
|
+
} as const;
|
|
37
|
+
|
|
38
|
+
type ModelName = `openrouter:${keyof typeof openrouterModels}`;
|
|
39
|
+
|
|
40
|
+
export const openrouterModelNames: ModelName[] = objectKeys(
|
|
41
|
+
openrouterModels,
|
|
42
|
+
).map((key) => `openrouter:${key}` as const);
|
|
43
|
+
|
|
44
|
+
export const openrouterProvider = {
|
|
45
|
+
openrouter: customProvider({
|
|
46
|
+
languageModels: openrouterModels,
|
|
47
|
+
fallbackProvider: openRouterClient,
|
|
48
|
+
}),
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const openrouterModelRegistry: {
|
|
52
|
+
[K in ModelName]: ModelMetadata<ModelName>;
|
|
53
|
+
} = {
|
|
54
|
+
"openrouter:deepseek-v3": {
|
|
55
|
+
id: "openrouter:deepseek-v3",
|
|
56
|
+
provider: "openrouter",
|
|
57
|
+
contextWindow: 128000,
|
|
58
|
+
maxOutputTokens: 8000,
|
|
59
|
+
defaultTemperature: 0.3,
|
|
60
|
+
promptFormat: "bracket",
|
|
61
|
+
supportsReasoning: false,
|
|
62
|
+
supportsToolCalling: true,
|
|
63
|
+
costPerInputToken: 0, // Assuming free tier or unknown cost
|
|
64
|
+
costPerOutputToken: 0, // Assuming free tier or unknown cost
|
|
65
|
+
category: "balanced",
|
|
66
|
+
},
|
|
67
|
+
"openrouter:deepseek-r1": {
|
|
68
|
+
id: "openrouter:deepseek-r1",
|
|
69
|
+
provider: "openrouter",
|
|
70
|
+
contextWindow: 128000,
|
|
71
|
+
maxOutputTokens: 32768,
|
|
72
|
+
defaultTemperature: 0.6,
|
|
73
|
+
promptFormat: "bracket",
|
|
74
|
+
supportsReasoning: true,
|
|
75
|
+
supportsToolCalling: true,
|
|
76
|
+
costPerInputToken: 0, // Assuming free tier or unknown cost
|
|
77
|
+
costPerOutputToken: 0, // Assuming free tier or unknown cost
|
|
78
|
+
category: "balanced",
|
|
79
|
+
},
|
|
80
|
+
"openrouter:deepseek-v3-free": {
|
|
81
|
+
id: "openrouter:deepseek-v3-free",
|
|
82
|
+
provider: "openrouter",
|
|
83
|
+
contextWindow: 128000,
|
|
84
|
+
maxOutputTokens: 8000,
|
|
85
|
+
defaultTemperature: 0.3,
|
|
86
|
+
promptFormat: "bracket",
|
|
87
|
+
supportsReasoning: false,
|
|
88
|
+
supportsToolCalling: true,
|
|
89
|
+
costPerInputToken: 0, // Assuming free tier or unknown cost
|
|
90
|
+
costPerOutputToken: 0, // Assuming free tier or unknown cost
|
|
91
|
+
category: "balanced",
|
|
92
|
+
},
|
|
93
|
+
"openrouter:deepseek-r1-free": {
|
|
94
|
+
id: "openrouter:deepseek-r1-free",
|
|
95
|
+
provider: "openrouter",
|
|
96
|
+
contextWindow: 128000,
|
|
97
|
+
maxOutputTokens: 32768,
|
|
98
|
+
defaultTemperature: 0.6,
|
|
99
|
+
promptFormat: "bracket",
|
|
100
|
+
supportsReasoning: true,
|
|
101
|
+
supportsToolCalling: true,
|
|
102
|
+
costPerInputToken: 0, // Assuming free tier or unknown cost
|
|
103
|
+
costPerOutputToken: 0, // Assuming free tier or unknown cost
|
|
104
|
+
category: "balanced",
|
|
105
|
+
},
|
|
106
|
+
"openrouter:gemini-flash25": {
|
|
107
|
+
id: "openrouter:gemini-flash25",
|
|
108
|
+
provider: "openrouter",
|
|
109
|
+
contextWindow: 1000000,
|
|
110
|
+
maxOutputTokens: 66000,
|
|
111
|
+
defaultTemperature: 0.5,
|
|
112
|
+
promptFormat: "markdown",
|
|
113
|
+
supportsReasoning: true,
|
|
114
|
+
supportsToolCalling: true,
|
|
115
|
+
costPerInputToken: 0,
|
|
116
|
+
costPerOutputToken: 0,
|
|
117
|
+
category: "fast",
|
|
118
|
+
},
|
|
119
|
+
"openrouter:gemini-pro25": {
|
|
120
|
+
id: "openrouter:gemini-pro25",
|
|
121
|
+
provider: "openrouter",
|
|
122
|
+
contextWindow: 1000000,
|
|
123
|
+
maxOutputTokens: 64000,
|
|
124
|
+
defaultTemperature: 0.5,
|
|
125
|
+
promptFormat: "markdown",
|
|
126
|
+
supportsReasoning: true,
|
|
127
|
+
supportsToolCalling: true,
|
|
128
|
+
costPerInputToken: 0,
|
|
129
|
+
costPerOutputToken: 0,
|
|
130
|
+
category: "powerful",
|
|
131
|
+
},
|
|
132
|
+
"openrouter:opus4": {
|
|
133
|
+
id: "openrouter:opus4",
|
|
134
|
+
provider: "openrouter",
|
|
135
|
+
contextWindow: 200000,
|
|
136
|
+
maxOutputTokens: 64000,
|
|
137
|
+
defaultTemperature: 0.5,
|
|
138
|
+
promptFormat: "markdown",
|
|
139
|
+
supportsReasoning: true,
|
|
140
|
+
supportsToolCalling: true,
|
|
141
|
+
costPerInputToken: 0,
|
|
142
|
+
costPerOutputToken: 0,
|
|
143
|
+
category: "powerful",
|
|
144
|
+
},
|
|
145
|
+
"openrouter:opus-4.1": {
|
|
146
|
+
id: "openrouter:opus-4.1",
|
|
147
|
+
provider: "openrouter",
|
|
148
|
+
contextWindow: 200000,
|
|
149
|
+
maxOutputTokens: 32000,
|
|
150
|
+
defaultTemperature: 0.5,
|
|
151
|
+
promptFormat: "markdown",
|
|
152
|
+
supportsReasoning: true,
|
|
153
|
+
supportsToolCalling: true,
|
|
154
|
+
costPerInputToken: 0.000015,
|
|
155
|
+
costPerOutputToken: 0.000075,
|
|
156
|
+
category: "powerful",
|
|
157
|
+
},
|
|
158
|
+
"openrouter:sonnet4": {
|
|
159
|
+
id: "openrouter:sonnet4",
|
|
160
|
+
provider: "openrouter",
|
|
161
|
+
contextWindow: 200000,
|
|
162
|
+
maxOutputTokens: 64000,
|
|
163
|
+
defaultTemperature: 0.5,
|
|
164
|
+
promptFormat: "markdown",
|
|
165
|
+
supportsReasoning: true,
|
|
166
|
+
supportsToolCalling: true,
|
|
167
|
+
costPerInputToken: 0,
|
|
168
|
+
costPerOutputToken: 0,
|
|
169
|
+
category: "balanced",
|
|
170
|
+
},
|
|
171
|
+
"openrouter:gpt-4.1": {
|
|
172
|
+
id: "openrouter:gpt-4.1",
|
|
173
|
+
provider: "openrouter",
|
|
174
|
+
contextWindow: 1000000,
|
|
175
|
+
maxOutputTokens: 32768,
|
|
176
|
+
defaultTemperature: 0.3,
|
|
177
|
+
promptFormat: "markdown",
|
|
178
|
+
supportsReasoning: false,
|
|
179
|
+
supportsToolCalling: true,
|
|
180
|
+
costPerInputToken: 0.000002,
|
|
181
|
+
costPerOutputToken: 0.000008,
|
|
182
|
+
category: "balanced",
|
|
183
|
+
},
|
|
184
|
+
"openrouter:kimi-k2": {
|
|
185
|
+
id: "openrouter:kimi-k2",
|
|
186
|
+
provider: "openrouter",
|
|
187
|
+
contextWindow: 131072,
|
|
188
|
+
maxOutputTokens: 8192,
|
|
189
|
+
defaultTemperature: 0.6,
|
|
190
|
+
promptFormat: "markdown",
|
|
191
|
+
supportsReasoning: false,
|
|
192
|
+
supportsToolCalling: true,
|
|
193
|
+
costPerInputToken: 0.00000057,
|
|
194
|
+
costPerOutputToken: 0.0000023,
|
|
195
|
+
category: "balanced",
|
|
196
|
+
},
|
|
197
|
+
"openrouter:kimi-k2-free": {
|
|
198
|
+
id: "openrouter:kimi-k2-free",
|
|
199
|
+
provider: "openrouter",
|
|
200
|
+
contextWindow: 65536,
|
|
201
|
+
maxOutputTokens: 8192,
|
|
202
|
+
defaultTemperature: 0.6,
|
|
203
|
+
promptFormat: "markdown",
|
|
204
|
+
supportsReasoning: false,
|
|
205
|
+
supportsToolCalling: true,
|
|
206
|
+
costPerInputToken: 0,
|
|
207
|
+
costPerOutputToken: 0,
|
|
208
|
+
category: "balanced",
|
|
209
|
+
},
|
|
210
|
+
"openrouter:devstral-medium": {
|
|
211
|
+
id: "openrouter:devstral-medium",
|
|
212
|
+
provider: "openrouter",
|
|
213
|
+
contextWindow: 131000,
|
|
214
|
+
maxOutputTokens: 8192,
|
|
215
|
+
defaultTemperature: 0.3,
|
|
216
|
+
promptFormat: "markdown",
|
|
217
|
+
supportsReasoning: false,
|
|
218
|
+
supportsToolCalling: true,
|
|
219
|
+
costPerInputToken: 0.0000004,
|
|
220
|
+
costPerOutputToken: 0.000002,
|
|
221
|
+
category: "balanced",
|
|
222
|
+
},
|
|
223
|
+
"openrouter:qwen3-coder": {
|
|
224
|
+
id: "openrouter:qwen3-coder",
|
|
225
|
+
provider: "openrouter",
|
|
226
|
+
contextWindow: 262000,
|
|
227
|
+
maxOutputTokens: 66000,
|
|
228
|
+
defaultTemperature: 0.7,
|
|
229
|
+
promptFormat: "markdown",
|
|
230
|
+
supportsReasoning: false,
|
|
231
|
+
supportsToolCalling: true,
|
|
232
|
+
costPerInputToken: 0.0000004,
|
|
233
|
+
costPerOutputToken: 0.000002,
|
|
234
|
+
category: "balanced",
|
|
235
|
+
},
|
|
236
|
+
"openrouter:qwen3-coder-free": {
|
|
237
|
+
id: "openrouter:qwen3-coder-free",
|
|
238
|
+
provider: "openrouter",
|
|
239
|
+
contextWindow: 262000,
|
|
240
|
+
maxOutputTokens: 66000,
|
|
241
|
+
defaultTemperature: 0.7,
|
|
242
|
+
promptFormat: "markdown",
|
|
243
|
+
supportsReasoning: false,
|
|
244
|
+
supportsToolCalling: true,
|
|
245
|
+
costPerInputToken: 0.0000004,
|
|
246
|
+
costPerOutputToken: 0.000002,
|
|
247
|
+
category: "balanced",
|
|
248
|
+
},
|
|
249
|
+
"openrouter:glm-4.5": {
|
|
250
|
+
id: "openrouter:glm-4.5",
|
|
251
|
+
provider: "openrouter",
|
|
252
|
+
contextWindow: 128000,
|
|
253
|
+
maxOutputTokens: 8192,
|
|
254
|
+
defaultTemperature: 0.7,
|
|
255
|
+
promptFormat: "markdown",
|
|
256
|
+
supportsReasoning: true,
|
|
257
|
+
supportsToolCalling: true,
|
|
258
|
+
costPerInputToken: 0.0000006,
|
|
259
|
+
costPerOutputToken: 0.0000022,
|
|
260
|
+
category: "balanced",
|
|
261
|
+
},
|
|
262
|
+
"openrouter:gpt-5": {
|
|
263
|
+
id: "openrouter:gpt-5",
|
|
264
|
+
provider: "openrouter",
|
|
265
|
+
contextWindow: 400000,
|
|
266
|
+
maxOutputTokens: 128000,
|
|
267
|
+
defaultTemperature: 0.3,
|
|
268
|
+
promptFormat: "markdown",
|
|
269
|
+
supportsReasoning: true,
|
|
270
|
+
supportsToolCalling: true,
|
|
271
|
+
costPerInputToken: 0.00000125,
|
|
272
|
+
costPerOutputToken: 0.00001,
|
|
273
|
+
category: "powerful",
|
|
274
|
+
},
|
|
275
|
+
"openrouter:gpt-5-mini": {
|
|
276
|
+
id: "openrouter:gpt-5-mini",
|
|
277
|
+
provider: "openrouter",
|
|
278
|
+
contextWindow: 200000,
|
|
279
|
+
maxOutputTokens: 64000,
|
|
280
|
+
defaultTemperature: 0.3,
|
|
281
|
+
promptFormat: "markdown",
|
|
282
|
+
supportsReasoning: true,
|
|
283
|
+
supportsToolCalling: true,
|
|
284
|
+
costPerInputToken: 0.00000015,
|
|
285
|
+
costPerOutputToken: 0.0000006,
|
|
286
|
+
category: "balanced",
|
|
287
|
+
},
|
|
288
|
+
};
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { isString } from "@travisennis/stdlib/typeguards";
|
|
2
|
+
import { createProviderRegistry } from "ai";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import {
|
|
5
|
+
anthropicModelNames,
|
|
6
|
+
anthropicModelRegistry,
|
|
7
|
+
anthropicProvider,
|
|
8
|
+
} from "./anthropic-provider.ts";
|
|
9
|
+
import {
|
|
10
|
+
deepseekModelNames,
|
|
11
|
+
deepseekModelRegistry,
|
|
12
|
+
deepseekProvider,
|
|
13
|
+
} from "./deepseek-provider.ts";
|
|
14
|
+
import {
|
|
15
|
+
googleModelNames,
|
|
16
|
+
googleModelRegistry,
|
|
17
|
+
googleProvider,
|
|
18
|
+
} from "./google-provider.ts";
|
|
19
|
+
import {
|
|
20
|
+
openaiModelNames,
|
|
21
|
+
openaiModelRegistry,
|
|
22
|
+
openaiProvider,
|
|
23
|
+
} from "./openai-provider.ts";
|
|
24
|
+
import {
|
|
25
|
+
openrouterModelNames,
|
|
26
|
+
openrouterModelRegistry,
|
|
27
|
+
openrouterProvider,
|
|
28
|
+
} from "./openrouter-provider.ts";
|
|
29
|
+
import {
|
|
30
|
+
xaiModelNames,
|
|
31
|
+
xaiModelRegistry,
|
|
32
|
+
xaiProvider,
|
|
33
|
+
} from "./xai-provider.ts";
|
|
34
|
+
|
|
35
|
+
export const providers = [
|
|
36
|
+
"anthropic",
|
|
37
|
+
"openai",
|
|
38
|
+
"google",
|
|
39
|
+
"deepseek",
|
|
40
|
+
"openrouter",
|
|
41
|
+
"xai",
|
|
42
|
+
] as const;
|
|
43
|
+
|
|
44
|
+
export type ModelProvider = (typeof providers)[number];
|
|
45
|
+
|
|
46
|
+
const registry = createProviderRegistry({
|
|
47
|
+
...anthropicProvider,
|
|
48
|
+
...deepseekProvider,
|
|
49
|
+
...googleProvider,
|
|
50
|
+
...openaiProvider,
|
|
51
|
+
...openrouterProvider,
|
|
52
|
+
...xaiProvider,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
export const models = [
|
|
56
|
+
...anthropicModelNames,
|
|
57
|
+
...openaiModelNames,
|
|
58
|
+
...googleModelNames,
|
|
59
|
+
...deepseekModelNames,
|
|
60
|
+
...openrouterModelNames,
|
|
61
|
+
...xaiModelNames,
|
|
62
|
+
] as const;
|
|
63
|
+
|
|
64
|
+
export type ModelName =
|
|
65
|
+
| (typeof models)[number]
|
|
66
|
+
| (`xai:${string}` & {})
|
|
67
|
+
| (`openai:${string}` & {})
|
|
68
|
+
| (`anthropic:${string}` & {})
|
|
69
|
+
| (`google:${string}` & {})
|
|
70
|
+
| (`deepseek:${string}` & {})
|
|
71
|
+
| (`openrouter:${string}` & {});
|
|
72
|
+
|
|
73
|
+
export function isSupportedModel(model: unknown): model is ModelName {
|
|
74
|
+
return (
|
|
75
|
+
models.includes(model as (typeof models)[number]) ||
|
|
76
|
+
(isString(model) &&
|
|
77
|
+
(model.startsWith("openrouter:") ||
|
|
78
|
+
model.startsWith("anthropic:") ||
|
|
79
|
+
model.startsWith("openai:") ||
|
|
80
|
+
model.startsWith("google:") ||
|
|
81
|
+
model.startsWith("xai:") ||
|
|
82
|
+
model.startsWith("deepseek:")))
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function languageModel(model: ModelName) {
|
|
87
|
+
return registry.languageModel(model as (typeof models)[number]);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface ModelMetadata<T = ModelName> {
|
|
91
|
+
id: T;
|
|
92
|
+
provider: ModelProvider;
|
|
93
|
+
// displayName: string;
|
|
94
|
+
// description: string;
|
|
95
|
+
contextWindow: number;
|
|
96
|
+
supportsToolCalling: boolean;
|
|
97
|
+
supportsReasoning: boolean;
|
|
98
|
+
costPerInputToken: number;
|
|
99
|
+
costPerOutputToken: number;
|
|
100
|
+
maxOutputTokens: number;
|
|
101
|
+
defaultTemperature: number;
|
|
102
|
+
promptFormat: "xml" | "markdown" | "bracket";
|
|
103
|
+
category: "fast" | "balanced" | "powerful";
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// https://openrouter.ai/api/v1/models
|
|
107
|
+
export const modelRegistry: Record<ModelName, ModelMetadata> = {
|
|
108
|
+
...anthropicModelRegistry,
|
|
109
|
+
...openaiModelRegistry,
|
|
110
|
+
...googleModelRegistry,
|
|
111
|
+
...deepseekModelRegistry,
|
|
112
|
+
...openrouterModelRegistry,
|
|
113
|
+
...xaiModelRegistry,
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// Schema for validating model selection
|
|
117
|
+
export const ModelSelectionSchema = z.enum(
|
|
118
|
+
Object.keys(modelRegistry) as [string, ...string[]],
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
// Get available models grouped by provider
|
|
122
|
+
export function getModelsByProvider(): Record<ModelProvider, ModelMetadata[]> {
|
|
123
|
+
const result: Record<ModelProvider, ModelMetadata[]> = {
|
|
124
|
+
anthropic: [],
|
|
125
|
+
openai: [],
|
|
126
|
+
google: [],
|
|
127
|
+
deepseek: [],
|
|
128
|
+
openrouter: [],
|
|
129
|
+
xai: [],
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
for (const model of Object.values(modelRegistry)) {
|
|
133
|
+
result[model.provider].push(model);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function getModelsById(): Record<ModelName, string> {
|
|
140
|
+
const result: Map<ModelName, string> = new Map();
|
|
141
|
+
|
|
142
|
+
for (const name of models) {
|
|
143
|
+
const langModel = registry.languageModel(name);
|
|
144
|
+
result.set(name, langModel.modelId);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return Object.fromEntries(result) as Record<ModelName, string>;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Get detailed information about a specific model
|
|
151
|
+
export function getModelInfo(modelName: ModelName): ModelMetadata | undefined {
|
|
152
|
+
return modelRegistry[modelName];
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Get models by category
|
|
156
|
+
export function getModelsByCategory(
|
|
157
|
+
category: "fast" | "balanced" | "powerful",
|
|
158
|
+
): ModelMetadata[] {
|
|
159
|
+
return Object.values(modelRegistry).filter(
|
|
160
|
+
(model) => model.category === category,
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Format model information for display
|
|
165
|
+
export function formatModelInfo(model: ModelMetadata): string {
|
|
166
|
+
return `${model.id} [${model.category}] - Tools: ${model.supportsToolCalling ? "✓" : "✗"}, Reasoning: ${model.supportsReasoning ? "✓" : "✗"}`;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Check if a model name is valid
|
|
170
|
+
export function isValidModel(modelName: string): modelName is ModelName {
|
|
171
|
+
return modelName in modelRegistry;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Get recommended models based on task requirements
|
|
175
|
+
export function getRecommendedModels(options: {
|
|
176
|
+
requiresTools?: boolean;
|
|
177
|
+
requiresReasoning?: boolean;
|
|
178
|
+
speedPriority?: boolean;
|
|
179
|
+
}): ModelName[] {
|
|
180
|
+
return Object.values(modelRegistry)
|
|
181
|
+
.filter((model) => {
|
|
182
|
+
if (options.requiresTools && !model.supportsToolCalling) {
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
if (options.requiresReasoning && !model.supportsReasoning) {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
return true;
|
|
189
|
+
})
|
|
190
|
+
.sort((a, b) => {
|
|
191
|
+
if (options.speedPriority) {
|
|
192
|
+
return a.category === "fast" ? -1 : 1;
|
|
193
|
+
}
|
|
194
|
+
return b.contextWindow - a.contextWindow;
|
|
195
|
+
})
|
|
196
|
+
.map((model) => model.id);
|
|
197
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { createOpenAI } from "@ai-sdk/openai";
|
|
2
|
+
import { objectKeys } from "@travisennis/stdlib/object";
|
|
3
|
+
import { customProvider } from "ai";
|
|
4
|
+
import type { ModelMetadata } from "./providers.ts";
|
|
5
|
+
|
|
6
|
+
const xaiClient = createOpenAI({
|
|
7
|
+
apiKey: process.env["X_AI_API_KEY"] ?? process.env["XAI_API_KEY"],
|
|
8
|
+
// biome-ignore lint/style/useNamingConvention: third-party controlled
|
|
9
|
+
baseURL: "https://api.x.ai/v1",
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const xaiModels = {
|
|
13
|
+
grok3: xaiClient("grok-3"),
|
|
14
|
+
"grok3-mini": xaiClient("grok-3-mini-beta"),
|
|
15
|
+
} as const;
|
|
16
|
+
|
|
17
|
+
type ModelName = `xai:${keyof typeof xaiModels}`;
|
|
18
|
+
|
|
19
|
+
export const xaiModelNames: ModelName[] = objectKeys(xaiModels).map(
|
|
20
|
+
(key) => `xai:${key}` as const,
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
export const xaiProvider = {
|
|
24
|
+
xai: customProvider({
|
|
25
|
+
languageModels: xaiModels,
|
|
26
|
+
fallbackProvider: xaiClient,
|
|
27
|
+
}),
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const xaiModelRegistry: {
|
|
31
|
+
[K in ModelName]: ModelMetadata<ModelName>;
|
|
32
|
+
} = {
|
|
33
|
+
"xai:grok3": {
|
|
34
|
+
id: "xai:grok3",
|
|
35
|
+
provider: "xai",
|
|
36
|
+
contextWindow: 131072,
|
|
37
|
+
maxOutputTokens: 131072, // Note: API docs might specify lower practical limits
|
|
38
|
+
defaultTemperature: 0.6,
|
|
39
|
+
promptFormat: "markdown",
|
|
40
|
+
supportsReasoning: false, // Assuming based on typical chat models
|
|
41
|
+
supportsToolCalling: true,
|
|
42
|
+
costPerInputToken: 0.000003, // Placeholder, check official pricing
|
|
43
|
+
costPerOutputToken: 0.000015, // Placeholder, check official pricing
|
|
44
|
+
category: "balanced",
|
|
45
|
+
},
|
|
46
|
+
"xai:grok3-mini": {
|
|
47
|
+
id: "xai:grok3-mini",
|
|
48
|
+
provider: "xai",
|
|
49
|
+
contextWindow: 131072,
|
|
50
|
+
maxOutputTokens: 131072, // Note: API docs might specify lower practical limits
|
|
51
|
+
defaultTemperature: 0.6,
|
|
52
|
+
promptFormat: "markdown",
|
|
53
|
+
supportsReasoning: true, // Assuming based on typical chat models
|
|
54
|
+
supportsToolCalling: true,
|
|
55
|
+
costPerInputToken: 0.0000003, // Placeholder, check official pricing
|
|
56
|
+
costPerOutputToken: 0.0000005, // Placeholder, check official pricing
|
|
57
|
+
category: "fast", // Or "fast" depending on performance
|
|
58
|
+
},
|
|
59
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ZodIssueCode, z } from "zod";
|
|
2
|
+
|
|
3
|
+
const parseJsonPreprocessor = (value: unknown, ctx: z.RefinementCtx) => {
|
|
4
|
+
if (typeof value === "string") {
|
|
5
|
+
try {
|
|
6
|
+
return JSON.parse(value);
|
|
7
|
+
} catch (e) {
|
|
8
|
+
ctx.addIssue({
|
|
9
|
+
code: ZodIssueCode.custom,
|
|
10
|
+
message: (e as Error).message,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return value;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export function jsonParser<T extends z.ZodTypeAny>(input: T) {
|
|
19
|
+
return z.preprocess(parseJsonPreprocessor, input);
|
|
20
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { isString } from "@travisennis/stdlib/typeguards";
|
|
2
|
+
import type { TextPart, UserModelMessage } from "ai"; // Corrected import
|
|
3
|
+
import { createUserMessage, type UserMessageContentItem } from "../messages.ts";
|
|
4
|
+
import type { TokenCounter } from "../token-utils.ts";
|
|
5
|
+
|
|
6
|
+
export type ContextItem = UserMessageContentItem;
|
|
7
|
+
|
|
8
|
+
export class PromptManager {
|
|
9
|
+
private prompt: string | undefined;
|
|
10
|
+
private context: ContextItem[];
|
|
11
|
+
private tokenCounter: TokenCounter;
|
|
12
|
+
|
|
13
|
+
constructor(tokenCounter: TokenCounter) {
|
|
14
|
+
this.prompt = undefined;
|
|
15
|
+
this.context = [];
|
|
16
|
+
this.tokenCounter = tokenCounter;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
set(prompt: string) {
|
|
20
|
+
this.prompt = prompt;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
get() {
|
|
24
|
+
const prompt = this.prompt;
|
|
25
|
+
if (isString(prompt) && prompt.trim().length > 0) {
|
|
26
|
+
return prompt;
|
|
27
|
+
}
|
|
28
|
+
throw new Error("No prompt available.");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
getUserMessage(): UserModelMessage {
|
|
32
|
+
const currentPrompt = this.prompt;
|
|
33
|
+
if (isString(currentPrompt) && currentPrompt.trim().length > 0) {
|
|
34
|
+
let userMessage: UserModelMessage;
|
|
35
|
+
if (this.hasContext()) {
|
|
36
|
+
// Pass context items and the prompt string to createUserMessage
|
|
37
|
+
userMessage = createUserMessage([...this.context], currentPrompt);
|
|
38
|
+
this.clearAll(); // Clear context and prompt after using
|
|
39
|
+
} else {
|
|
40
|
+
// Pass an empty array for context items if no context
|
|
41
|
+
userMessage = createUserMessage([], currentPrompt);
|
|
42
|
+
this.prompt = undefined; // Clear only prompt if no context was used
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return this._applyProviderOptionsToMessage(userMessage);
|
|
46
|
+
}
|
|
47
|
+
throw new Error("No prompt available.");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private _applyProviderOptionsToMessage(
|
|
51
|
+
userMessage: UserModelMessage,
|
|
52
|
+
): UserModelMessage {
|
|
53
|
+
if (Array.isArray(userMessage.content)) {
|
|
54
|
+
for (const part of userMessage.content) {
|
|
55
|
+
if (typeof part === "object" && part !== null && part.type === "text") {
|
|
56
|
+
const textPart = part as TextPart & {
|
|
57
|
+
providerOptions?: Record<string, unknown>;
|
|
58
|
+
};
|
|
59
|
+
if (this.tokenCounter.count(textPart.text) > 4096) {
|
|
60
|
+
textPart.providerOptions = {
|
|
61
|
+
anthropic: { cacheControl: { type: "ephemeral" } },
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return userMessage;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
isPending() {
|
|
71
|
+
return isString(this.prompt) && this.prompt.trim().length > 0;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
addContext(item: ContextItem): void {
|
|
75
|
+
this.context.push(item);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
hasContext() {
|
|
79
|
+
return this.context.length > 0;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
clearContext() {
|
|
83
|
+
this.context.length = 0;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
clearAll() {
|
|
87
|
+
this.clearContext();
|
|
88
|
+
this.prompt = undefined;
|
|
89
|
+
}
|
|
90
|
+
}
|