@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,276 @@
|
|
|
1
|
+
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
2
|
+
import { objectKeys } from "@travisennis/stdlib/object";
|
|
3
|
+
import { customProvider } from "ai";
|
|
4
|
+
const openRouterClient = createOpenAICompatible({
|
|
5
|
+
name: "openrouter",
|
|
6
|
+
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
|
|
7
|
+
// biome-ignore lint/style/useNamingConvention: third-party controlled
|
|
8
|
+
baseURL: "https://openrouter.ai/api/v1",
|
|
9
|
+
headers: {
|
|
10
|
+
"HTTP-Referer": "https://github.com/travisennis/acai-ts",
|
|
11
|
+
"X-Title": "acai",
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
const openrouterModels = {
|
|
15
|
+
"deepseek-v3": openRouterClient("deepseek/deepseek-chat-v3-0324"),
|
|
16
|
+
"deepseek-r1": openRouterClient("deepseek/deepseek-r1-0528"),
|
|
17
|
+
"deepseek-v3-free": openRouterClient("deepseek/deepseek-chat-v3-0324:free"),
|
|
18
|
+
"deepseek-r1-free": openRouterClient("deepseek/deepseek-r1-0528:free"),
|
|
19
|
+
"gemini-flash25": openRouterClient("google/gemini-2.5-flash"),
|
|
20
|
+
"gemini-pro25": openRouterClient("google/gemini-2.5-pro"),
|
|
21
|
+
sonnet4: openRouterClient("anthropic/claude-sonnet-4"),
|
|
22
|
+
opus4: openRouterClient("anthropic/claude-opus-4"),
|
|
23
|
+
"opus-4.1": openRouterClient("anthropic/claude-opus-4.1"),
|
|
24
|
+
"gpt-4.1": openRouterClient("openai/gpt-4.1"),
|
|
25
|
+
"kimi-k2": openRouterClient("moonshotai/kimi-k2:nitro"),
|
|
26
|
+
"kimi-k2-free": openRouterClient("moonshotai/kimi-k2:free"),
|
|
27
|
+
"devstral-medium": openRouterClient("mistralai/devstral-medium"),
|
|
28
|
+
"qwen3-coder": openRouterClient("qwen/qwen3-coder"),
|
|
29
|
+
"qwen3-coder-free": openRouterClient("qwen/qwen3-coder:free"),
|
|
30
|
+
"glm-4.5": openRouterClient("z-ai/glm-4.5"),
|
|
31
|
+
"gpt-5": openRouterClient("openai/gpt-5"),
|
|
32
|
+
"gpt-5-mini": openRouterClient("openai/gpt-5-mini"),
|
|
33
|
+
};
|
|
34
|
+
export const openrouterModelNames = objectKeys(openrouterModels).map((key) => `openrouter:${key}`);
|
|
35
|
+
export const openrouterProvider = {
|
|
36
|
+
openrouter: customProvider({
|
|
37
|
+
languageModels: openrouterModels,
|
|
38
|
+
fallbackProvider: openRouterClient,
|
|
39
|
+
}),
|
|
40
|
+
};
|
|
41
|
+
export const openrouterModelRegistry = {
|
|
42
|
+
"openrouter:deepseek-v3": {
|
|
43
|
+
id: "openrouter:deepseek-v3",
|
|
44
|
+
provider: "openrouter",
|
|
45
|
+
contextWindow: 128000,
|
|
46
|
+
maxOutputTokens: 8000,
|
|
47
|
+
defaultTemperature: 0.3,
|
|
48
|
+
promptFormat: "bracket",
|
|
49
|
+
supportsReasoning: false,
|
|
50
|
+
supportsToolCalling: true,
|
|
51
|
+
costPerInputToken: 0, // Assuming free tier or unknown cost
|
|
52
|
+
costPerOutputToken: 0, // Assuming free tier or unknown cost
|
|
53
|
+
category: "balanced",
|
|
54
|
+
},
|
|
55
|
+
"openrouter:deepseek-r1": {
|
|
56
|
+
id: "openrouter:deepseek-r1",
|
|
57
|
+
provider: "openrouter",
|
|
58
|
+
contextWindow: 128000,
|
|
59
|
+
maxOutputTokens: 32768,
|
|
60
|
+
defaultTemperature: 0.6,
|
|
61
|
+
promptFormat: "bracket",
|
|
62
|
+
supportsReasoning: true,
|
|
63
|
+
supportsToolCalling: true,
|
|
64
|
+
costPerInputToken: 0, // Assuming free tier or unknown cost
|
|
65
|
+
costPerOutputToken: 0, // Assuming free tier or unknown cost
|
|
66
|
+
category: "balanced",
|
|
67
|
+
},
|
|
68
|
+
"openrouter:deepseek-v3-free": {
|
|
69
|
+
id: "openrouter:deepseek-v3-free",
|
|
70
|
+
provider: "openrouter",
|
|
71
|
+
contextWindow: 128000,
|
|
72
|
+
maxOutputTokens: 8000,
|
|
73
|
+
defaultTemperature: 0.3,
|
|
74
|
+
promptFormat: "bracket",
|
|
75
|
+
supportsReasoning: false,
|
|
76
|
+
supportsToolCalling: true,
|
|
77
|
+
costPerInputToken: 0, // Assuming free tier or unknown cost
|
|
78
|
+
costPerOutputToken: 0, // Assuming free tier or unknown cost
|
|
79
|
+
category: "balanced",
|
|
80
|
+
},
|
|
81
|
+
"openrouter:deepseek-r1-free": {
|
|
82
|
+
id: "openrouter:deepseek-r1-free",
|
|
83
|
+
provider: "openrouter",
|
|
84
|
+
contextWindow: 128000,
|
|
85
|
+
maxOutputTokens: 32768,
|
|
86
|
+
defaultTemperature: 0.6,
|
|
87
|
+
promptFormat: "bracket",
|
|
88
|
+
supportsReasoning: true,
|
|
89
|
+
supportsToolCalling: true,
|
|
90
|
+
costPerInputToken: 0, // Assuming free tier or unknown cost
|
|
91
|
+
costPerOutputToken: 0, // Assuming free tier or unknown cost
|
|
92
|
+
category: "balanced",
|
|
93
|
+
},
|
|
94
|
+
"openrouter:gemini-flash25": {
|
|
95
|
+
id: "openrouter:gemini-flash25",
|
|
96
|
+
provider: "openrouter",
|
|
97
|
+
contextWindow: 1000000,
|
|
98
|
+
maxOutputTokens: 66000,
|
|
99
|
+
defaultTemperature: 0.5,
|
|
100
|
+
promptFormat: "markdown",
|
|
101
|
+
supportsReasoning: true,
|
|
102
|
+
supportsToolCalling: true,
|
|
103
|
+
costPerInputToken: 0,
|
|
104
|
+
costPerOutputToken: 0,
|
|
105
|
+
category: "fast",
|
|
106
|
+
},
|
|
107
|
+
"openrouter:gemini-pro25": {
|
|
108
|
+
id: "openrouter:gemini-pro25",
|
|
109
|
+
provider: "openrouter",
|
|
110
|
+
contextWindow: 1000000,
|
|
111
|
+
maxOutputTokens: 64000,
|
|
112
|
+
defaultTemperature: 0.5,
|
|
113
|
+
promptFormat: "markdown",
|
|
114
|
+
supportsReasoning: true,
|
|
115
|
+
supportsToolCalling: true,
|
|
116
|
+
costPerInputToken: 0,
|
|
117
|
+
costPerOutputToken: 0,
|
|
118
|
+
category: "powerful",
|
|
119
|
+
},
|
|
120
|
+
"openrouter:opus4": {
|
|
121
|
+
id: "openrouter:opus4",
|
|
122
|
+
provider: "openrouter",
|
|
123
|
+
contextWindow: 200000,
|
|
124
|
+
maxOutputTokens: 64000,
|
|
125
|
+
defaultTemperature: 0.5,
|
|
126
|
+
promptFormat: "markdown",
|
|
127
|
+
supportsReasoning: true,
|
|
128
|
+
supportsToolCalling: true,
|
|
129
|
+
costPerInputToken: 0,
|
|
130
|
+
costPerOutputToken: 0,
|
|
131
|
+
category: "powerful",
|
|
132
|
+
},
|
|
133
|
+
"openrouter:opus-4.1": {
|
|
134
|
+
id: "openrouter:opus-4.1",
|
|
135
|
+
provider: "openrouter",
|
|
136
|
+
contextWindow: 200000,
|
|
137
|
+
maxOutputTokens: 32000,
|
|
138
|
+
defaultTemperature: 0.5,
|
|
139
|
+
promptFormat: "markdown",
|
|
140
|
+
supportsReasoning: true,
|
|
141
|
+
supportsToolCalling: true,
|
|
142
|
+
costPerInputToken: 0.000015,
|
|
143
|
+
costPerOutputToken: 0.000075,
|
|
144
|
+
category: "powerful",
|
|
145
|
+
},
|
|
146
|
+
"openrouter:sonnet4": {
|
|
147
|
+
id: "openrouter:sonnet4",
|
|
148
|
+
provider: "openrouter",
|
|
149
|
+
contextWindow: 200000,
|
|
150
|
+
maxOutputTokens: 64000,
|
|
151
|
+
defaultTemperature: 0.5,
|
|
152
|
+
promptFormat: "markdown",
|
|
153
|
+
supportsReasoning: true,
|
|
154
|
+
supportsToolCalling: true,
|
|
155
|
+
costPerInputToken: 0,
|
|
156
|
+
costPerOutputToken: 0,
|
|
157
|
+
category: "balanced",
|
|
158
|
+
},
|
|
159
|
+
"openrouter:gpt-4.1": {
|
|
160
|
+
id: "openrouter:gpt-4.1",
|
|
161
|
+
provider: "openrouter",
|
|
162
|
+
contextWindow: 1000000,
|
|
163
|
+
maxOutputTokens: 32768,
|
|
164
|
+
defaultTemperature: 0.3,
|
|
165
|
+
promptFormat: "markdown",
|
|
166
|
+
supportsReasoning: false,
|
|
167
|
+
supportsToolCalling: true,
|
|
168
|
+
costPerInputToken: 0.000002,
|
|
169
|
+
costPerOutputToken: 0.000008,
|
|
170
|
+
category: "balanced",
|
|
171
|
+
},
|
|
172
|
+
"openrouter:kimi-k2": {
|
|
173
|
+
id: "openrouter:kimi-k2",
|
|
174
|
+
provider: "openrouter",
|
|
175
|
+
contextWindow: 131072,
|
|
176
|
+
maxOutputTokens: 8192,
|
|
177
|
+
defaultTemperature: 0.6,
|
|
178
|
+
promptFormat: "markdown",
|
|
179
|
+
supportsReasoning: false,
|
|
180
|
+
supportsToolCalling: true,
|
|
181
|
+
costPerInputToken: 0.00000057,
|
|
182
|
+
costPerOutputToken: 0.0000023,
|
|
183
|
+
category: "balanced",
|
|
184
|
+
},
|
|
185
|
+
"openrouter:kimi-k2-free": {
|
|
186
|
+
id: "openrouter:kimi-k2-free",
|
|
187
|
+
provider: "openrouter",
|
|
188
|
+
contextWindow: 65536,
|
|
189
|
+
maxOutputTokens: 8192,
|
|
190
|
+
defaultTemperature: 0.6,
|
|
191
|
+
promptFormat: "markdown",
|
|
192
|
+
supportsReasoning: false,
|
|
193
|
+
supportsToolCalling: true,
|
|
194
|
+
costPerInputToken: 0,
|
|
195
|
+
costPerOutputToken: 0,
|
|
196
|
+
category: "balanced",
|
|
197
|
+
},
|
|
198
|
+
"openrouter:devstral-medium": {
|
|
199
|
+
id: "openrouter:devstral-medium",
|
|
200
|
+
provider: "openrouter",
|
|
201
|
+
contextWindow: 131000,
|
|
202
|
+
maxOutputTokens: 8192,
|
|
203
|
+
defaultTemperature: 0.3,
|
|
204
|
+
promptFormat: "markdown",
|
|
205
|
+
supportsReasoning: false,
|
|
206
|
+
supportsToolCalling: true,
|
|
207
|
+
costPerInputToken: 0.0000004,
|
|
208
|
+
costPerOutputToken: 0.000002,
|
|
209
|
+
category: "balanced",
|
|
210
|
+
},
|
|
211
|
+
"openrouter:qwen3-coder": {
|
|
212
|
+
id: "openrouter:qwen3-coder",
|
|
213
|
+
provider: "openrouter",
|
|
214
|
+
contextWindow: 262000,
|
|
215
|
+
maxOutputTokens: 66000,
|
|
216
|
+
defaultTemperature: 0.7,
|
|
217
|
+
promptFormat: "markdown",
|
|
218
|
+
supportsReasoning: false,
|
|
219
|
+
supportsToolCalling: true,
|
|
220
|
+
costPerInputToken: 0.0000004,
|
|
221
|
+
costPerOutputToken: 0.000002,
|
|
222
|
+
category: "balanced",
|
|
223
|
+
},
|
|
224
|
+
"openrouter:qwen3-coder-free": {
|
|
225
|
+
id: "openrouter:qwen3-coder-free",
|
|
226
|
+
provider: "openrouter",
|
|
227
|
+
contextWindow: 262000,
|
|
228
|
+
maxOutputTokens: 66000,
|
|
229
|
+
defaultTemperature: 0.7,
|
|
230
|
+
promptFormat: "markdown",
|
|
231
|
+
supportsReasoning: false,
|
|
232
|
+
supportsToolCalling: true,
|
|
233
|
+
costPerInputToken: 0.0000004,
|
|
234
|
+
costPerOutputToken: 0.000002,
|
|
235
|
+
category: "balanced",
|
|
236
|
+
},
|
|
237
|
+
"openrouter:glm-4.5": {
|
|
238
|
+
id: "openrouter:glm-4.5",
|
|
239
|
+
provider: "openrouter",
|
|
240
|
+
contextWindow: 128000,
|
|
241
|
+
maxOutputTokens: 8192,
|
|
242
|
+
defaultTemperature: 0.7,
|
|
243
|
+
promptFormat: "markdown",
|
|
244
|
+
supportsReasoning: true,
|
|
245
|
+
supportsToolCalling: true,
|
|
246
|
+
costPerInputToken: 0.0000006,
|
|
247
|
+
costPerOutputToken: 0.0000022,
|
|
248
|
+
category: "balanced",
|
|
249
|
+
},
|
|
250
|
+
"openrouter:gpt-5": {
|
|
251
|
+
id: "openrouter:gpt-5",
|
|
252
|
+
provider: "openrouter",
|
|
253
|
+
contextWindow: 400000,
|
|
254
|
+
maxOutputTokens: 128000,
|
|
255
|
+
defaultTemperature: 0.3,
|
|
256
|
+
promptFormat: "markdown",
|
|
257
|
+
supportsReasoning: true,
|
|
258
|
+
supportsToolCalling: true,
|
|
259
|
+
costPerInputToken: 0.00000125,
|
|
260
|
+
costPerOutputToken: 0.00001,
|
|
261
|
+
category: "powerful",
|
|
262
|
+
},
|
|
263
|
+
"openrouter:gpt-5-mini": {
|
|
264
|
+
id: "openrouter:gpt-5-mini",
|
|
265
|
+
provider: "openrouter",
|
|
266
|
+
contextWindow: 200000,
|
|
267
|
+
maxOutputTokens: 64000,
|
|
268
|
+
defaultTemperature: 0.3,
|
|
269
|
+
promptFormat: "markdown",
|
|
270
|
+
supportsReasoning: true,
|
|
271
|
+
supportsToolCalling: true,
|
|
272
|
+
costPerInputToken: 0.00000015,
|
|
273
|
+
costPerOutputToken: 0.0000006,
|
|
274
|
+
category: "balanced",
|
|
275
|
+
},
|
|
276
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const providers: readonly ["anthropic", "openai", "google", "deepseek", "openrouter", "xai"];
|
|
3
|
+
export type ModelProvider = (typeof providers)[number];
|
|
4
|
+
export declare const models: readonly ("anthropic:opus" | "anthropic:sonnet" | "anthropic:sonnet37" | "anthropic:sonnet37-token-efficient-tools" | "anthropic:sonnet37-128k" | "anthropic:sonnet35" | "anthropic:haiku" | "openai:o3" | "openai:gpt-4.1" | "openai:o4-mini" | "openai:codex-mini" | "google:flash25lite" | "google:pro25" | "google:flash25" | "deepseek:deepseek-chat" | "deepseek:deepseek-reasoner" | "openrouter:gpt-5" | "openrouter:gpt-5-mini" | "openrouter:gpt-4.1" | "openrouter:deepseek-v3" | "openrouter:deepseek-r1" | "openrouter:deepseek-v3-free" | "openrouter:deepseek-r1-free" | "openrouter:gemini-flash25" | "openrouter:gemini-pro25" | "openrouter:sonnet4" | "openrouter:opus4" | "openrouter:opus-4.1" | "openrouter:kimi-k2" | "openrouter:kimi-k2-free" | "openrouter:devstral-medium" | "openrouter:qwen3-coder" | "openrouter:qwen3-coder-free" | "openrouter:glm-4.5" | "xai:grok3" | "xai:grok3-mini")[];
|
|
5
|
+
export type ModelName = (typeof models)[number] | (`xai:${string}` & {}) | (`openai:${string}` & {}) | (`anthropic:${string}` & {}) | (`google:${string}` & {}) | (`deepseek:${string}` & {}) | (`openrouter:${string}` & {});
|
|
6
|
+
export declare function isSupportedModel(model: unknown): model is ModelName;
|
|
7
|
+
export declare function languageModel(model: ModelName): import("@ai-sdk/provider").LanguageModelV2;
|
|
8
|
+
export interface ModelMetadata<T = ModelName> {
|
|
9
|
+
id: T;
|
|
10
|
+
provider: ModelProvider;
|
|
11
|
+
contextWindow: number;
|
|
12
|
+
supportsToolCalling: boolean;
|
|
13
|
+
supportsReasoning: boolean;
|
|
14
|
+
costPerInputToken: number;
|
|
15
|
+
costPerOutputToken: number;
|
|
16
|
+
maxOutputTokens: number;
|
|
17
|
+
defaultTemperature: number;
|
|
18
|
+
promptFormat: "xml" | "markdown" | "bracket";
|
|
19
|
+
category: "fast" | "balanced" | "powerful";
|
|
20
|
+
}
|
|
21
|
+
export declare const modelRegistry: Record<ModelName, ModelMetadata>;
|
|
22
|
+
export declare const ModelSelectionSchema: z.ZodEnum<[string, ...string[]]>;
|
|
23
|
+
export declare function getModelsByProvider(): Record<ModelProvider, ModelMetadata[]>;
|
|
24
|
+
export declare function getModelsById(): Record<ModelName, string>;
|
|
25
|
+
export declare function getModelInfo(modelName: ModelName): ModelMetadata | undefined;
|
|
26
|
+
export declare function getModelsByCategory(category: "fast" | "balanced" | "powerful"): ModelMetadata[];
|
|
27
|
+
export declare function formatModelInfo(model: ModelMetadata): string;
|
|
28
|
+
export declare function isValidModel(modelName: string): modelName is ModelName;
|
|
29
|
+
export declare function getRecommendedModels(options: {
|
|
30
|
+
requiresTools?: boolean;
|
|
31
|
+
requiresReasoning?: boolean;
|
|
32
|
+
speedPriority?: boolean;
|
|
33
|
+
}): ModelName[];
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { isString } from "@travisennis/stdlib/typeguards";
|
|
2
|
+
import { createProviderRegistry } from "ai";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { anthropicModelNames, anthropicModelRegistry, anthropicProvider, } from "./anthropic-provider.js";
|
|
5
|
+
import { deepseekModelNames, deepseekModelRegistry, deepseekProvider, } from "./deepseek-provider.js";
|
|
6
|
+
import { googleModelNames, googleModelRegistry, googleProvider, } from "./google-provider.js";
|
|
7
|
+
import { openaiModelNames, openaiModelRegistry, openaiProvider, } from "./openai-provider.js";
|
|
8
|
+
import { openrouterModelNames, openrouterModelRegistry, openrouterProvider, } from "./openrouter-provider.js";
|
|
9
|
+
import { xaiModelNames, xaiModelRegistry, xaiProvider, } from "./xai-provider.js";
|
|
10
|
+
export const providers = [
|
|
11
|
+
"anthropic",
|
|
12
|
+
"openai",
|
|
13
|
+
"google",
|
|
14
|
+
"deepseek",
|
|
15
|
+
"openrouter",
|
|
16
|
+
"xai",
|
|
17
|
+
];
|
|
18
|
+
const registry = createProviderRegistry({
|
|
19
|
+
...anthropicProvider,
|
|
20
|
+
...deepseekProvider,
|
|
21
|
+
...googleProvider,
|
|
22
|
+
...openaiProvider,
|
|
23
|
+
...openrouterProvider,
|
|
24
|
+
...xaiProvider,
|
|
25
|
+
});
|
|
26
|
+
export const models = [
|
|
27
|
+
...anthropicModelNames,
|
|
28
|
+
...openaiModelNames,
|
|
29
|
+
...googleModelNames,
|
|
30
|
+
...deepseekModelNames,
|
|
31
|
+
...openrouterModelNames,
|
|
32
|
+
...xaiModelNames,
|
|
33
|
+
];
|
|
34
|
+
export function isSupportedModel(model) {
|
|
35
|
+
return (models.includes(model) ||
|
|
36
|
+
(isString(model) &&
|
|
37
|
+
(model.startsWith("openrouter:") ||
|
|
38
|
+
model.startsWith("anthropic:") ||
|
|
39
|
+
model.startsWith("openai:") ||
|
|
40
|
+
model.startsWith("google:") ||
|
|
41
|
+
model.startsWith("xai:") ||
|
|
42
|
+
model.startsWith("deepseek:"))));
|
|
43
|
+
}
|
|
44
|
+
export function languageModel(model) {
|
|
45
|
+
return registry.languageModel(model);
|
|
46
|
+
}
|
|
47
|
+
// https://openrouter.ai/api/v1/models
|
|
48
|
+
export const modelRegistry = {
|
|
49
|
+
...anthropicModelRegistry,
|
|
50
|
+
...openaiModelRegistry,
|
|
51
|
+
...googleModelRegistry,
|
|
52
|
+
...deepseekModelRegistry,
|
|
53
|
+
...openrouterModelRegistry,
|
|
54
|
+
...xaiModelRegistry,
|
|
55
|
+
};
|
|
56
|
+
// Schema for validating model selection
|
|
57
|
+
export const ModelSelectionSchema = z.enum(Object.keys(modelRegistry));
|
|
58
|
+
// Get available models grouped by provider
|
|
59
|
+
export function getModelsByProvider() {
|
|
60
|
+
const result = {
|
|
61
|
+
anthropic: [],
|
|
62
|
+
openai: [],
|
|
63
|
+
google: [],
|
|
64
|
+
deepseek: [],
|
|
65
|
+
openrouter: [],
|
|
66
|
+
xai: [],
|
|
67
|
+
};
|
|
68
|
+
for (const model of Object.values(modelRegistry)) {
|
|
69
|
+
result[model.provider].push(model);
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
export function getModelsById() {
|
|
74
|
+
const result = new Map();
|
|
75
|
+
for (const name of models) {
|
|
76
|
+
const langModel = registry.languageModel(name);
|
|
77
|
+
result.set(name, langModel.modelId);
|
|
78
|
+
}
|
|
79
|
+
return Object.fromEntries(result);
|
|
80
|
+
}
|
|
81
|
+
// Get detailed information about a specific model
|
|
82
|
+
export function getModelInfo(modelName) {
|
|
83
|
+
return modelRegistry[modelName];
|
|
84
|
+
}
|
|
85
|
+
// Get models by category
|
|
86
|
+
export function getModelsByCategory(category) {
|
|
87
|
+
return Object.values(modelRegistry).filter((model) => model.category === category);
|
|
88
|
+
}
|
|
89
|
+
// Format model information for display
|
|
90
|
+
export function formatModelInfo(model) {
|
|
91
|
+
return `${model.id} [${model.category}] - Tools: ${model.supportsToolCalling ? "✓" : "✗"}, Reasoning: ${model.supportsReasoning ? "✓" : "✗"}`;
|
|
92
|
+
}
|
|
93
|
+
// Check if a model name is valid
|
|
94
|
+
export function isValidModel(modelName) {
|
|
95
|
+
return modelName in modelRegistry;
|
|
96
|
+
}
|
|
97
|
+
// Get recommended models based on task requirements
|
|
98
|
+
export function getRecommendedModels(options) {
|
|
99
|
+
return Object.values(modelRegistry)
|
|
100
|
+
.filter((model) => {
|
|
101
|
+
if (options.requiresTools && !model.supportsToolCalling) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
if (options.requiresReasoning && !model.supportsReasoning) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
return true;
|
|
108
|
+
})
|
|
109
|
+
.sort((a, b) => {
|
|
110
|
+
if (options.speedPriority) {
|
|
111
|
+
return a.category === "fast" ? -1 : 1;
|
|
112
|
+
}
|
|
113
|
+
return b.contextWindow - a.contextWindow;
|
|
114
|
+
})
|
|
115
|
+
.map((model) => model.id);
|
|
116
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ModelMetadata } from "./providers.ts";
|
|
2
|
+
declare const xaiModels: {
|
|
3
|
+
readonly grok3: import("@ai-sdk/provider").LanguageModelV2;
|
|
4
|
+
readonly "grok3-mini": import("@ai-sdk/provider").LanguageModelV2;
|
|
5
|
+
};
|
|
6
|
+
type ModelName = `xai:${keyof typeof xaiModels}`;
|
|
7
|
+
export declare const xaiModelNames: ModelName[];
|
|
8
|
+
export declare const xaiProvider: {
|
|
9
|
+
xai: import("@ai-sdk/provider").ProviderV2 & {
|
|
10
|
+
languageModel(modelId: "grok3" | "grok3-mini"): import("@ai-sdk/provider").LanguageModelV2;
|
|
11
|
+
textEmbeddingModel(modelId: string): import("@ai-sdk/provider").EmbeddingModelV2<string>;
|
|
12
|
+
imageModel(modelId: string): import("@ai-sdk/provider").ImageModelV2;
|
|
13
|
+
transcriptionModel(modelId: string): import("@ai-sdk/provider").TranscriptionModelV2;
|
|
14
|
+
speechModel(modelId: string): import("@ai-sdk/provider").SpeechModelV2;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export declare const xaiModelRegistry: {
|
|
18
|
+
[K in ModelName]: ModelMetadata<ModelName>;
|
|
19
|
+
};
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { createOpenAI } from "@ai-sdk/openai";
|
|
2
|
+
import { objectKeys } from "@travisennis/stdlib/object";
|
|
3
|
+
import { customProvider } from "ai";
|
|
4
|
+
const xaiClient = createOpenAI({
|
|
5
|
+
apiKey: process.env["X_AI_API_KEY"] ?? process.env["XAI_API_KEY"],
|
|
6
|
+
// biome-ignore lint/style/useNamingConvention: third-party controlled
|
|
7
|
+
baseURL: "https://api.x.ai/v1",
|
|
8
|
+
});
|
|
9
|
+
const xaiModels = {
|
|
10
|
+
grok3: xaiClient("grok-3"),
|
|
11
|
+
"grok3-mini": xaiClient("grok-3-mini-beta"),
|
|
12
|
+
};
|
|
13
|
+
export const xaiModelNames = objectKeys(xaiModels).map((key) => `xai:${key}`);
|
|
14
|
+
export const xaiProvider = {
|
|
15
|
+
xai: customProvider({
|
|
16
|
+
languageModels: xaiModels,
|
|
17
|
+
fallbackProvider: xaiClient,
|
|
18
|
+
}),
|
|
19
|
+
};
|
|
20
|
+
export const xaiModelRegistry = {
|
|
21
|
+
"xai:grok3": {
|
|
22
|
+
id: "xai:grok3",
|
|
23
|
+
provider: "xai",
|
|
24
|
+
contextWindow: 131072,
|
|
25
|
+
maxOutputTokens: 131072, // Note: API docs might specify lower practical limits
|
|
26
|
+
defaultTemperature: 0.6,
|
|
27
|
+
promptFormat: "markdown",
|
|
28
|
+
supportsReasoning: false, // Assuming based on typical chat models
|
|
29
|
+
supportsToolCalling: true,
|
|
30
|
+
costPerInputToken: 0.000003, // Placeholder, check official pricing
|
|
31
|
+
costPerOutputToken: 0.000015, // Placeholder, check official pricing
|
|
32
|
+
category: "balanced",
|
|
33
|
+
},
|
|
34
|
+
"xai:grok3-mini": {
|
|
35
|
+
id: "xai:grok3-mini",
|
|
36
|
+
provider: "xai",
|
|
37
|
+
contextWindow: 131072,
|
|
38
|
+
maxOutputTokens: 131072, // Note: API docs might specify lower practical limits
|
|
39
|
+
defaultTemperature: 0.6,
|
|
40
|
+
promptFormat: "markdown",
|
|
41
|
+
supportsReasoning: true, // Assuming based on typical chat models
|
|
42
|
+
supportsToolCalling: true,
|
|
43
|
+
costPerInputToken: 0.0000003, // Placeholder, check official pricing
|
|
44
|
+
costPerOutputToken: 0.0000005, // Placeholder, check official pricing
|
|
45
|
+
category: "fast", // Or "fast" depending on performance
|
|
46
|
+
},
|
|
47
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ZodIssueCode, z } from "zod";
|
|
2
|
+
const parseJsonPreprocessor = (value, ctx) => {
|
|
3
|
+
if (typeof value === "string") {
|
|
4
|
+
try {
|
|
5
|
+
return JSON.parse(value);
|
|
6
|
+
}
|
|
7
|
+
catch (e) {
|
|
8
|
+
ctx.addIssue({
|
|
9
|
+
code: ZodIssueCode.custom,
|
|
10
|
+
message: e.message,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return value;
|
|
15
|
+
};
|
|
16
|
+
export function jsonParser(input) {
|
|
17
|
+
return z.preprocess(parseJsonPreprocessor, input);
|
|
18
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { UserModelMessage } from "ai";
|
|
2
|
+
import { type UserMessageContentItem } from "../messages.ts";
|
|
3
|
+
import type { TokenCounter } from "../token-utils.ts";
|
|
4
|
+
export type ContextItem = UserMessageContentItem;
|
|
5
|
+
export declare class PromptManager {
|
|
6
|
+
private prompt;
|
|
7
|
+
private context;
|
|
8
|
+
private tokenCounter;
|
|
9
|
+
constructor(tokenCounter: TokenCounter);
|
|
10
|
+
set(prompt: string): void;
|
|
11
|
+
get(): string;
|
|
12
|
+
getUserMessage(): UserModelMessage;
|
|
13
|
+
private _applyProviderOptionsToMessage;
|
|
14
|
+
isPending(): boolean;
|
|
15
|
+
addContext(item: ContextItem): void;
|
|
16
|
+
hasContext(): boolean;
|
|
17
|
+
clearContext(): void;
|
|
18
|
+
clearAll(): void;
|
|
19
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { isString } from "@travisennis/stdlib/typeguards";
|
|
2
|
+
import { createUserMessage } from "../messages.js";
|
|
3
|
+
export class PromptManager {
|
|
4
|
+
prompt;
|
|
5
|
+
context;
|
|
6
|
+
tokenCounter;
|
|
7
|
+
constructor(tokenCounter) {
|
|
8
|
+
this.prompt = undefined;
|
|
9
|
+
this.context = [];
|
|
10
|
+
this.tokenCounter = tokenCounter;
|
|
11
|
+
}
|
|
12
|
+
set(prompt) {
|
|
13
|
+
this.prompt = prompt;
|
|
14
|
+
}
|
|
15
|
+
get() {
|
|
16
|
+
const prompt = this.prompt;
|
|
17
|
+
if (isString(prompt) && prompt.trim().length > 0) {
|
|
18
|
+
return prompt;
|
|
19
|
+
}
|
|
20
|
+
throw new Error("No prompt available.");
|
|
21
|
+
}
|
|
22
|
+
getUserMessage() {
|
|
23
|
+
const currentPrompt = this.prompt;
|
|
24
|
+
if (isString(currentPrompt) && currentPrompt.trim().length > 0) {
|
|
25
|
+
let userMessage;
|
|
26
|
+
if (this.hasContext()) {
|
|
27
|
+
// Pass context items and the prompt string to createUserMessage
|
|
28
|
+
userMessage = createUserMessage([...this.context], currentPrompt);
|
|
29
|
+
this.clearAll(); // Clear context and prompt after using
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
// Pass an empty array for context items if no context
|
|
33
|
+
userMessage = createUserMessage([], currentPrompt);
|
|
34
|
+
this.prompt = undefined; // Clear only prompt if no context was used
|
|
35
|
+
}
|
|
36
|
+
return this._applyProviderOptionsToMessage(userMessage);
|
|
37
|
+
}
|
|
38
|
+
throw new Error("No prompt available.");
|
|
39
|
+
}
|
|
40
|
+
_applyProviderOptionsToMessage(userMessage) {
|
|
41
|
+
if (Array.isArray(userMessage.content)) {
|
|
42
|
+
for (const part of userMessage.content) {
|
|
43
|
+
if (typeof part === "object" && part !== null && part.type === "text") {
|
|
44
|
+
const textPart = part;
|
|
45
|
+
if (this.tokenCounter.count(textPart.text) > 4096) {
|
|
46
|
+
textPart.providerOptions = {
|
|
47
|
+
anthropic: { cacheControl: { type: "ephemeral" } },
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return userMessage;
|
|
54
|
+
}
|
|
55
|
+
isPending() {
|
|
56
|
+
return isString(this.prompt) && this.prompt.trim().length > 0;
|
|
57
|
+
}
|
|
58
|
+
addContext(item) {
|
|
59
|
+
this.context.push(item);
|
|
60
|
+
}
|
|
61
|
+
hasContext() {
|
|
62
|
+
return this.context.length > 0;
|
|
63
|
+
}
|
|
64
|
+
clearContext() {
|
|
65
|
+
this.context.length = 0;
|
|
66
|
+
}
|
|
67
|
+
clearAll() {
|
|
68
|
+
this.clearContext();
|
|
69
|
+
this.prompt = undefined;
|
|
70
|
+
}
|
|
71
|
+
}
|