easc-cli 1.1.28
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/AGENTS.md +27 -0
- package/Dockerfile +18 -0
- package/README.md +15 -0
- package/bin/opencode +108 -0
- package/bunfig.toml +7 -0
- package/package.json +132 -0
- package/parsers-config.ts +253 -0
- package/script/build.ts +172 -0
- package/script/deploy.ts +64 -0
- package/script/postinstall.mjs +125 -0
- package/script/publish-registries.ts +187 -0
- package/script/publish.ts +70 -0
- package/script/schema.ts +47 -0
- package/script/seed-e2e.ts +50 -0
- package/src/acp/README.md +164 -0
- package/src/acp/agent.ts +1285 -0
- package/src/acp/session.ts +105 -0
- package/src/acp/types.ts +22 -0
- package/src/agent/agent.ts +332 -0
- package/src/agent/generate.txt +75 -0
- package/src/agent/prompt/compaction.txt +12 -0
- package/src/agent/prompt/explore.txt +18 -0
- package/src/agent/prompt/summary.txt +11 -0
- package/src/agent/prompt/title.txt +43 -0
- package/src/auth/eliseart.ts +76 -0
- package/src/auth/index.ts +73 -0
- package/src/bun/index.ts +134 -0
- package/src/bus/bus-event.ts +43 -0
- package/src/bus/global.ts +10 -0
- package/src/bus/index.ts +105 -0
- package/src/cli/bootstrap.ts +17 -0
- package/src/cli/cmd/account.ts +81 -0
- package/src/cli/cmd/acp.ts +69 -0
- package/src/cli/cmd/agent.ts +257 -0
- package/src/cli/cmd/auth.ts +427 -0
- package/src/cli/cmd/cmd.ts +7 -0
- package/src/cli/cmd/debug/agent.ts +166 -0
- package/src/cli/cmd/debug/config.ts +16 -0
- package/src/cli/cmd/debug/file.ts +97 -0
- package/src/cli/cmd/debug/index.ts +48 -0
- package/src/cli/cmd/debug/lsp.ts +52 -0
- package/src/cli/cmd/debug/ripgrep.ts +87 -0
- package/src/cli/cmd/debug/scrap.ts +16 -0
- package/src/cli/cmd/debug/skill.ts +16 -0
- package/src/cli/cmd/debug/snapshot.ts +52 -0
- package/src/cli/cmd/export.ts +88 -0
- package/src/cli/cmd/generate.ts +38 -0
- package/src/cli/cmd/github.ts +1548 -0
- package/src/cli/cmd/import.ts +98 -0
- package/src/cli/cmd/mcp.ts +827 -0
- package/src/cli/cmd/models.ts +77 -0
- package/src/cli/cmd/pr.ts +112 -0
- package/src/cli/cmd/run.ts +407 -0
- package/src/cli/cmd/serve.ts +20 -0
- package/src/cli/cmd/session.ts +135 -0
- package/src/cli/cmd/stats.ts +402 -0
- package/src/cli/cmd/tui/app.tsx +774 -0
- package/src/cli/cmd/tui/attach.ts +31 -0
- package/src/cli/cmd/tui/component/border.tsx +21 -0
- package/src/cli/cmd/tui/component/dialog-agent.tsx +31 -0
- package/src/cli/cmd/tui/component/dialog-command.tsx +148 -0
- package/src/cli/cmd/tui/component/dialog-mcp.tsx +86 -0
- package/src/cli/cmd/tui/component/dialog-model.tsx +234 -0
- package/src/cli/cmd/tui/component/dialog-provider.tsx +256 -0
- package/src/cli/cmd/tui/component/dialog-session-list.tsx +114 -0
- package/src/cli/cmd/tui/component/dialog-session-rename.tsx +31 -0
- package/src/cli/cmd/tui/component/dialog-stash.tsx +87 -0
- package/src/cli/cmd/tui/component/dialog-status.tsx +164 -0
- package/src/cli/cmd/tui/component/dialog-supabase.tsx +102 -0
- package/src/cli/cmd/tui/component/dialog-tag.tsx +44 -0
- package/src/cli/cmd/tui/component/dialog-theme-list.tsx +50 -0
- package/src/cli/cmd/tui/component/logo.tsx +88 -0
- package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +653 -0
- package/src/cli/cmd/tui/component/prompt/frecency.tsx +89 -0
- package/src/cli/cmd/tui/component/prompt/history.tsx +108 -0
- package/src/cli/cmd/tui/component/prompt/index.tsx +1182 -0
- package/src/cli/cmd/tui/component/prompt/stash.tsx +101 -0
- package/src/cli/cmd/tui/component/spinner.tsx +16 -0
- package/src/cli/cmd/tui/component/textarea-keybindings.ts +73 -0
- package/src/cli/cmd/tui/component/tips.tsx +153 -0
- package/src/cli/cmd/tui/component/todo-item.tsx +32 -0
- package/src/cli/cmd/tui/context/args.tsx +14 -0
- package/src/cli/cmd/tui/context/directory.ts +13 -0
- package/src/cli/cmd/tui/context/exit.tsx +23 -0
- package/src/cli/cmd/tui/context/helper.tsx +25 -0
- package/src/cli/cmd/tui/context/keybind.tsx +101 -0
- package/src/cli/cmd/tui/context/kv.tsx +52 -0
- package/src/cli/cmd/tui/context/local.tsx +402 -0
- package/src/cli/cmd/tui/context/prompt.tsx +18 -0
- package/src/cli/cmd/tui/context/route.tsx +46 -0
- package/src/cli/cmd/tui/context/sdk.tsx +94 -0
- package/src/cli/cmd/tui/context/sync.tsx +445 -0
- package/src/cli/cmd/tui/context/theme/aura.json +69 -0
- package/src/cli/cmd/tui/context/theme/ayu.json +80 -0
- package/src/cli/cmd/tui/context/theme/carbonfox.json +248 -0
- package/src/cli/cmd/tui/context/theme/catppuccin-frappe.json +233 -0
- package/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +233 -0
- package/src/cli/cmd/tui/context/theme/catppuccin.json +112 -0
- package/src/cli/cmd/tui/context/theme/cobalt2.json +228 -0
- package/src/cli/cmd/tui/context/theme/cursor.json +249 -0
- package/src/cli/cmd/tui/context/theme/dracula.json +219 -0
- package/src/cli/cmd/tui/context/theme/everforest.json +241 -0
- package/src/cli/cmd/tui/context/theme/flexoki.json +237 -0
- package/src/cli/cmd/tui/context/theme/github.json +233 -0
- package/src/cli/cmd/tui/context/theme/gruvbox.json +95 -0
- package/src/cli/cmd/tui/context/theme/kanagawa.json +77 -0
- package/src/cli/cmd/tui/context/theme/lucent-orng.json +237 -0
- package/src/cli/cmd/tui/context/theme/material.json +235 -0
- package/src/cli/cmd/tui/context/theme/matrix.json +77 -0
- package/src/cli/cmd/tui/context/theme/mercury.json +252 -0
- package/src/cli/cmd/tui/context/theme/monokai.json +221 -0
- package/src/cli/cmd/tui/context/theme/nightowl.json +221 -0
- package/src/cli/cmd/tui/context/theme/nord.json +223 -0
- package/src/cli/cmd/tui/context/theme/one-dark.json +84 -0
- package/src/cli/cmd/tui/context/theme/orng.json +249 -0
- package/src/cli/cmd/tui/context/theme/osaka-jade.json +93 -0
- package/src/cli/cmd/tui/context/theme/palenight.json +222 -0
- package/src/cli/cmd/tui/context/theme/rosepine.json +234 -0
- package/src/cli/cmd/tui/context/theme/solarized.json +223 -0
- package/src/cli/cmd/tui/context/theme/synthwave84.json +226 -0
- package/src/cli/cmd/tui/context/theme/tokyonight.json +243 -0
- package/src/cli/cmd/tui/context/theme/vercel.json +245 -0
- package/src/cli/cmd/tui/context/theme/vesper.json +218 -0
- package/src/cli/cmd/tui/context/theme/zenburn.json +223 -0
- package/src/cli/cmd/tui/context/theme.tsx +1152 -0
- package/src/cli/cmd/tui/event.ts +48 -0
- package/src/cli/cmd/tui/routes/home.tsx +140 -0
- package/src/cli/cmd/tui/routes/session/dialog-fork-from-timeline.tsx +64 -0
- package/src/cli/cmd/tui/routes/session/dialog-message.tsx +109 -0
- package/src/cli/cmd/tui/routes/session/dialog-subagent.tsx +26 -0
- package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +47 -0
- package/src/cli/cmd/tui/routes/session/dialog-tool.tsx +63 -0
- package/src/cli/cmd/tui/routes/session/footer.tsx +129 -0
- package/src/cli/cmd/tui/routes/session/header.tsx +136 -0
- package/src/cli/cmd/tui/routes/session/index.tsx +2132 -0
- package/src/cli/cmd/tui/routes/session/permission.tsx +495 -0
- package/src/cli/cmd/tui/routes/session/question.tsx +435 -0
- package/src/cli/cmd/tui/routes/session/sidebar.tsx +313 -0
- package/src/cli/cmd/tui/thread.ts +165 -0
- package/src/cli/cmd/tui/ui/dialog-alert.tsx +57 -0
- package/src/cli/cmd/tui/ui/dialog-confirm.tsx +83 -0
- package/src/cli/cmd/tui/ui/dialog-export-options.tsx +204 -0
- package/src/cli/cmd/tui/ui/dialog-help.tsx +38 -0
- package/src/cli/cmd/tui/ui/dialog-prompt.tsx +77 -0
- package/src/cli/cmd/tui/ui/dialog-select.tsx +376 -0
- package/src/cli/cmd/tui/ui/dialog.tsx +167 -0
- package/src/cli/cmd/tui/ui/link.tsx +28 -0
- package/src/cli/cmd/tui/ui/spinner.ts +368 -0
- package/src/cli/cmd/tui/ui/toast.tsx +100 -0
- package/src/cli/cmd/tui/util/clipboard.ts +160 -0
- package/src/cli/cmd/tui/util/editor.ts +32 -0
- package/src/cli/cmd/tui/util/signal.ts +7 -0
- package/src/cli/cmd/tui/util/terminal.ts +114 -0
- package/src/cli/cmd/tui/util/transcript.ts +98 -0
- package/src/cli/cmd/tui/worker.ts +152 -0
- package/src/cli/cmd/uninstall.ts +357 -0
- package/src/cli/cmd/upgrade.ts +73 -0
- package/src/cli/cmd/web.ts +81 -0
- package/src/cli/error.ts +57 -0
- package/src/cli/network.ts +53 -0
- package/src/cli/ui.ts +84 -0
- package/src/cli/upgrade.ts +25 -0
- package/src/command/index.ts +131 -0
- package/src/command/template/initialize.txt +10 -0
- package/src/command/template/review.txt +99 -0
- package/src/config/config.ts +1361 -0
- package/src/config/markdown.ts +93 -0
- package/src/env/index.ts +26 -0
- package/src/file/ignore.ts +83 -0
- package/src/file/index.ts +411 -0
- package/src/file/ripgrep.ts +407 -0
- package/src/file/time.ts +64 -0
- package/src/file/watcher.ts +127 -0
- package/src/flag/flag.ts +54 -0
- package/src/format/formatter.ts +342 -0
- package/src/format/index.ts +137 -0
- package/src/global/index.ts +55 -0
- package/src/id/id.ts +83 -0
- package/src/ide/index.ts +76 -0
- package/src/index.ts +162 -0
- package/src/installation/index.ts +246 -0
- package/src/lsp/client.ts +252 -0
- package/src/lsp/index.ts +485 -0
- package/src/lsp/language.ts +119 -0
- package/src/lsp/server.ts +2046 -0
- package/src/mcp/auth.ts +135 -0
- package/src/mcp/index.ts +931 -0
- package/src/mcp/oauth-callback.ts +200 -0
- package/src/mcp/oauth-provider.ts +154 -0
- package/src/patch/index.ts +680 -0
- package/src/permission/arity.ts +163 -0
- package/src/permission/index.ts +210 -0
- package/src/permission/next.ts +269 -0
- package/src/plugin/codex.ts +493 -0
- package/src/plugin/copilot.ts +269 -0
- package/src/plugin/index.ts +135 -0
- package/src/project/bootstrap.ts +35 -0
- package/src/project/instance.ts +91 -0
- package/src/project/project.ts +339 -0
- package/src/project/state.ts +66 -0
- package/src/project/vcs.ts +76 -0
- package/src/provider/auth.ts +147 -0
- package/src/provider/models-macro.ts +11 -0
- package/src/provider/models.ts +112 -0
- package/src/provider/provider.ts +1391 -0
- package/src/provider/sdk/openai-compatible/src/README.md +5 -0
- package/src/provider/sdk/openai-compatible/src/index.ts +2 -0
- package/src/provider/sdk/openai-compatible/src/openai-compatible-provider.ts +100 -0
- package/src/provider/sdk/openai-compatible/src/responses/convert-to-openai-responses-input.ts +303 -0
- package/src/provider/sdk/openai-compatible/src/responses/map-openai-responses-finish-reason.ts +22 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-config.ts +18 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-error.ts +22 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-responses-api-types.ts +207 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-responses-language-model.ts +1732 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-responses-prepare-tools.ts +177 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-responses-settings.ts +1 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/code-interpreter.ts +88 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/file-search.ts +128 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/image-generation.ts +115 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/local-shell.ts +65 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/web-search-preview.ts +104 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/web-search.ts +103 -0
- package/src/provider/transform.ts +733 -0
- package/src/pty/index.ts +232 -0
- package/src/question/index.ts +171 -0
- package/src/scheduler/index.ts +61 -0
- package/src/server/error.ts +36 -0
- package/src/server/event.ts +7 -0
- package/src/server/mdns.ts +59 -0
- package/src/server/routes/config.ts +92 -0
- package/src/server/routes/experimental.ts +208 -0
- package/src/server/routes/file.ts +197 -0
- package/src/server/routes/global.ts +135 -0
- package/src/server/routes/mcp.ts +361 -0
- package/src/server/routes/permission.ts +68 -0
- package/src/server/routes/project.ts +82 -0
- package/src/server/routes/provider.ts +165 -0
- package/src/server/routes/pty.ts +169 -0
- package/src/server/routes/question.ts +98 -0
- package/src/server/routes/session.ts +935 -0
- package/src/server/routes/tui.ts +379 -0
- package/src/server/server.ts +573 -0
- package/src/session/compaction.ts +225 -0
- package/src/session/index.ts +488 -0
- package/src/session/llm.ts +279 -0
- package/src/session/message-v2.ts +702 -0
- package/src/session/message.ts +189 -0
- package/src/session/processor.ts +406 -0
- package/src/session/prompt/anthropic-20250930.txt +166 -0
- package/src/session/prompt/anthropic.txt +105 -0
- package/src/session/prompt/anthropic_spoof.txt +1 -0
- package/src/session/prompt/beast.txt +147 -0
- package/src/session/prompt/build-switch.txt +5 -0
- package/src/session/prompt/codex_header.txt +79 -0
- package/src/session/prompt/copilot-gpt-5.txt +143 -0
- package/src/session/prompt/gemini.txt +155 -0
- package/src/session/prompt/max-steps.txt +16 -0
- package/src/session/prompt/plan-reminder-anthropic.txt +67 -0
- package/src/session/prompt/plan.txt +26 -0
- package/src/session/prompt/qwen.txt +109 -0
- package/src/session/prompt.ts +1820 -0
- package/src/session/retry.ts +90 -0
- package/src/session/revert.ts +108 -0
- package/src/session/status.ts +76 -0
- package/src/session/summary.ts +150 -0
- package/src/session/system.ts +152 -0
- package/src/session/todo.ts +37 -0
- package/src/share/share-next.ts +200 -0
- package/src/share/share.ts +92 -0
- package/src/shell/shell.ts +67 -0
- package/src/skill/index.ts +1 -0
- package/src/skill/skill.ts +136 -0
- package/src/snapshot/index.ts +236 -0
- package/src/storage/storage.ts +227 -0
- package/src/tool/apply_patch.ts +269 -0
- package/src/tool/apply_patch.txt +33 -0
- package/src/tool/bash.ts +259 -0
- package/src/tool/bash.txt +115 -0
- package/src/tool/batch.ts +175 -0
- package/src/tool/batch.txt +24 -0
- package/src/tool/codesearch.ts +132 -0
- package/src/tool/codesearch.txt +12 -0
- package/src/tool/edit.ts +645 -0
- package/src/tool/edit.txt +10 -0
- package/src/tool/external-directory.ts +32 -0
- package/src/tool/glob.ts +77 -0
- package/src/tool/glob.txt +6 -0
- package/src/tool/grep.ts +154 -0
- package/src/tool/grep.txt +8 -0
- package/src/tool/invalid.ts +17 -0
- package/src/tool/ls.ts +121 -0
- package/src/tool/ls.txt +1 -0
- package/src/tool/lsp.ts +96 -0
- package/src/tool/lsp.txt +19 -0
- package/src/tool/multiedit.ts +46 -0
- package/src/tool/multiedit.txt +41 -0
- package/src/tool/plan-enter.txt +14 -0
- package/src/tool/plan-exit.txt +13 -0
- package/src/tool/plan.ts +130 -0
- package/src/tool/question.ts +33 -0
- package/src/tool/question.txt +10 -0
- package/src/tool/read.ts +202 -0
- package/src/tool/read.txt +12 -0
- package/src/tool/registry.ts +163 -0
- package/src/tool/skill.ts +75 -0
- package/src/tool/task.ts +188 -0
- package/src/tool/task.txt +60 -0
- package/src/tool/todo.ts +53 -0
- package/src/tool/todoread.txt +14 -0
- package/src/tool/todowrite.txt +167 -0
- package/src/tool/tool.ts +88 -0
- package/src/tool/truncation.ts +106 -0
- package/src/tool/webfetch.ts +182 -0
- package/src/tool/webfetch.txt +13 -0
- package/src/tool/websearch.ts +150 -0
- package/src/tool/websearch.txt +14 -0
- package/src/tool/write.ts +80 -0
- package/src/tool/write.txt +8 -0
- package/src/util/archive.ts +16 -0
- package/src/util/color.ts +19 -0
- package/src/util/context.ts +25 -0
- package/src/util/defer.ts +12 -0
- package/src/util/eventloop.ts +20 -0
- package/src/util/filesystem.ts +93 -0
- package/src/util/fn.ts +11 -0
- package/src/util/format.ts +20 -0
- package/src/util/iife.ts +3 -0
- package/src/util/keybind.ts +103 -0
- package/src/util/lazy.ts +18 -0
- package/src/util/locale.ts +81 -0
- package/src/util/lock.ts +98 -0
- package/src/util/log.ts +180 -0
- package/src/util/queue.ts +32 -0
- package/src/util/rpc.ts +66 -0
- package/src/util/scrap.ts +10 -0
- package/src/util/signal.ts +12 -0
- package/src/util/timeout.ts +14 -0
- package/src/util/token.ts +7 -0
- package/src/util/wildcard.ts +56 -0
- package/src/worktree/index.ts +424 -0
- package/sst-env.d.ts +9 -0
- package/test/acp/event-subscription.test.ts +436 -0
- package/test/agent/agent.test.ts +638 -0
- package/test/bun.test.ts +53 -0
- package/test/cli/github-action.test.ts +129 -0
- package/test/cli/github-remote.test.ts +80 -0
- package/test/cli/tui/transcript.test.ts +297 -0
- package/test/config/agent-color.test.ts +66 -0
- package/test/config/config.test.ts +1414 -0
- package/test/config/fixtures/empty-frontmatter.md +4 -0
- package/test/config/fixtures/frontmatter.md +28 -0
- package/test/config/fixtures/no-frontmatter.md +1 -0
- package/test/config/markdown.test.ts +192 -0
- package/test/file/ignore.test.ts +10 -0
- package/test/file/path-traversal.test.ts +198 -0
- package/test/fixture/fixture.ts +45 -0
- package/test/fixture/lsp/fake-lsp-server.js +77 -0
- package/test/ide/ide.test.ts +82 -0
- package/test/keybind.test.ts +421 -0
- package/test/lsp/client.test.ts +95 -0
- package/test/mcp/headers.test.ts +153 -0
- package/test/mcp/oauth-browser.test.ts +261 -0
- package/test/patch/patch.test.ts +348 -0
- package/test/permission/arity.test.ts +33 -0
- package/test/permission/next.test.ts +652 -0
- package/test/permission-task.test.ts +319 -0
- package/test/plugin/codex.test.ts +123 -0
- package/test/preload.ts +65 -0
- package/test/project/project.test.ts +120 -0
- package/test/provider/amazon-bedrock.test.ts +268 -0
- package/test/provider/gitlab-duo.test.ts +286 -0
- package/test/provider/provider.test.ts +2149 -0
- package/test/provider/transform.test.ts +1596 -0
- package/test/question/question.test.ts +300 -0
- package/test/scheduler.test.ts +73 -0
- package/test/server/session-list.test.ts +39 -0
- package/test/server/session-select.test.ts +78 -0
- package/test/session/compaction.test.ts +293 -0
- package/test/session/llm.test.ts +90 -0
- package/test/session/message-v2.test.ts +662 -0
- package/test/session/retry.test.ts +131 -0
- package/test/session/revert-compact.test.ts +285 -0
- package/test/session/session.test.ts +71 -0
- package/test/skill/skill.test.ts +185 -0
- package/test/snapshot/snapshot.test.ts +939 -0
- package/test/tool/__snapshots__/tool.test.ts.snap +9 -0
- package/test/tool/apply_patch.test.ts +499 -0
- package/test/tool/bash.test.ts +320 -0
- package/test/tool/external-directory.test.ts +126 -0
- package/test/tool/fixtures/large-image.png +0 -0
- package/test/tool/fixtures/models-api.json +33453 -0
- package/test/tool/grep.test.ts +109 -0
- package/test/tool/question.test.ts +105 -0
- package/test/tool/read.test.ts +332 -0
- package/test/tool/registry.test.ts +76 -0
- package/test/tool/truncation.test.ts +159 -0
- package/test/util/filesystem.test.ts +39 -0
- package/test/util/format.test.ts +59 -0
- package/test/util/iife.test.ts +36 -0
- package/test/util/lazy.test.ts +50 -0
- package/test/util/lock.test.ts +72 -0
- package/test/util/timeout.test.ts +21 -0
- package/test/util/wildcard.test.ts +75 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,733 @@
|
|
|
1
|
+
import type { APICallError, ModelMessage } from "ai"
|
|
2
|
+
import { unique } from "remeda"
|
|
3
|
+
import type { JSONSchema } from "zod/v4/core"
|
|
4
|
+
import type { Provider } from "./provider"
|
|
5
|
+
import type { ModelsDev } from "./models"
|
|
6
|
+
import { iife } from "@/util/iife"
|
|
7
|
+
|
|
8
|
+
type Modality = NonNullable<ModelsDev.Model["modalities"]>["input"][number]
|
|
9
|
+
|
|
10
|
+
function mimeToModality(mime: string): Modality | undefined {
|
|
11
|
+
if (mime.startsWith("image/")) return "image"
|
|
12
|
+
if (mime.startsWith("audio/")) return "audio"
|
|
13
|
+
if (mime.startsWith("video/")) return "video"
|
|
14
|
+
if (mime === "application/pdf") return "pdf"
|
|
15
|
+
return undefined
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export namespace ProviderTransform {
|
|
19
|
+
// Maps npm package to the key the AI SDK expects for providerOptions
|
|
20
|
+
function sdkKey(npm: string): string | undefined {
|
|
21
|
+
switch (npm) {
|
|
22
|
+
case "@ai-sdk/github-copilot":
|
|
23
|
+
case "@ai-sdk/openai":
|
|
24
|
+
case "@ai-sdk/azure":
|
|
25
|
+
return "openai"
|
|
26
|
+
case "@ai-sdk/amazon-bedrock":
|
|
27
|
+
return "bedrock"
|
|
28
|
+
case "@ai-sdk/anthropic":
|
|
29
|
+
return "anthropic"
|
|
30
|
+
case "@ai-sdk/google-vertex":
|
|
31
|
+
case "@ai-sdk/google":
|
|
32
|
+
return "google"
|
|
33
|
+
case "@ai-sdk/gateway":
|
|
34
|
+
return "gateway"
|
|
35
|
+
case "@openrouter/ai-sdk-provider":
|
|
36
|
+
return "openrouter"
|
|
37
|
+
}
|
|
38
|
+
return undefined
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function normalizeMessages(
|
|
42
|
+
msgs: ModelMessage[],
|
|
43
|
+
model: Provider.Model,
|
|
44
|
+
options: Record<string, unknown>,
|
|
45
|
+
): ModelMessage[] {
|
|
46
|
+
// Anthropic rejects messages with empty content - filter out empty string messages
|
|
47
|
+
// and remove empty text/reasoning parts from array content
|
|
48
|
+
if (model.api.npm === "@ai-sdk/anthropic") {
|
|
49
|
+
msgs = msgs
|
|
50
|
+
.map((msg) => {
|
|
51
|
+
if (typeof msg.content === "string") {
|
|
52
|
+
if (msg.content === "") return undefined
|
|
53
|
+
return msg
|
|
54
|
+
}
|
|
55
|
+
if (!Array.isArray(msg.content)) return msg
|
|
56
|
+
const filtered = msg.content.filter((part) => {
|
|
57
|
+
if (part.type === "text" || part.type === "reasoning") {
|
|
58
|
+
return part.text !== ""
|
|
59
|
+
}
|
|
60
|
+
return true
|
|
61
|
+
})
|
|
62
|
+
if (filtered.length === 0) return undefined
|
|
63
|
+
return { ...msg, content: filtered }
|
|
64
|
+
})
|
|
65
|
+
.filter((msg): msg is ModelMessage => msg !== undefined && msg.content !== "")
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (model.api.id.includes("claude")) {
|
|
69
|
+
return msgs.map((msg) => {
|
|
70
|
+
if ((msg.role === "assistant" || msg.role === "tool") && Array.isArray(msg.content)) {
|
|
71
|
+
msg.content = msg.content.map((part) => {
|
|
72
|
+
if ((part.type === "tool-call" || part.type === "tool-result") && "toolCallId" in part) {
|
|
73
|
+
return {
|
|
74
|
+
...part,
|
|
75
|
+
toolCallId: part.toolCallId.replace(/[^a-zA-Z0-9_-]/g, "_"),
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return part
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
return msg
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
if (model.providerID === "mistral" || model.api.id.toLowerCase().includes("mistral")) {
|
|
85
|
+
const result: ModelMessage[] = []
|
|
86
|
+
for (let i = 0; i < msgs.length; i++) {
|
|
87
|
+
const msg = msgs[i]
|
|
88
|
+
const nextMsg = msgs[i + 1]
|
|
89
|
+
|
|
90
|
+
if ((msg.role === "assistant" || msg.role === "tool") && Array.isArray(msg.content)) {
|
|
91
|
+
msg.content = msg.content.map((part) => {
|
|
92
|
+
if ((part.type === "tool-call" || part.type === "tool-result") && "toolCallId" in part) {
|
|
93
|
+
// Mistral requires alphanumeric tool call IDs with exactly 9 characters
|
|
94
|
+
const normalizedId = part.toolCallId
|
|
95
|
+
.replace(/[^a-zA-Z0-9]/g, "") // Remove non-alphanumeric characters
|
|
96
|
+
.substring(0, 9) // Take first 9 characters
|
|
97
|
+
.padEnd(9, "0") // Pad with zeros if less than 9 characters
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
...part,
|
|
101
|
+
toolCallId: normalizedId,
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return part
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
result.push(msg)
|
|
109
|
+
|
|
110
|
+
// Fix message sequence: tool messages cannot be followed by user messages
|
|
111
|
+
if (msg.role === "tool" && nextMsg?.role === "user") {
|
|
112
|
+
result.push({
|
|
113
|
+
role: "assistant",
|
|
114
|
+
content: [
|
|
115
|
+
{
|
|
116
|
+
type: "text",
|
|
117
|
+
text: "Done.",
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
})
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return result
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (typeof model.capabilities.interleaved === "object" && model.capabilities.interleaved.field) {
|
|
127
|
+
const field = model.capabilities.interleaved.field
|
|
128
|
+
return msgs.map((msg) => {
|
|
129
|
+
if (msg.role === "assistant" && Array.isArray(msg.content)) {
|
|
130
|
+
const reasoningParts = msg.content.filter((part: any) => part.type === "reasoning")
|
|
131
|
+
const reasoningText = reasoningParts.map((part: any) => part.text).join("")
|
|
132
|
+
|
|
133
|
+
// Filter out reasoning parts from content
|
|
134
|
+
const filteredContent = msg.content.filter((part: any) => part.type !== "reasoning")
|
|
135
|
+
|
|
136
|
+
// Include reasoning_content | reasoning_details directly on the message for all assistant messages
|
|
137
|
+
if (reasoningText) {
|
|
138
|
+
return {
|
|
139
|
+
...msg,
|
|
140
|
+
content: filteredContent,
|
|
141
|
+
providerOptions: {
|
|
142
|
+
...msg.providerOptions,
|
|
143
|
+
openaiCompatible: {
|
|
144
|
+
...(msg.providerOptions as any)?.openaiCompatible,
|
|
145
|
+
[field]: reasoningText,
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
...msg,
|
|
153
|
+
content: filteredContent,
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return msg
|
|
158
|
+
})
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return msgs
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function applyCaching(msgs: ModelMessage[], providerID: string): ModelMessage[] {
|
|
165
|
+
const system = msgs.filter((msg) => msg.role === "system").slice(0, 2)
|
|
166
|
+
const final = msgs.filter((msg) => msg.role !== "system").slice(-2)
|
|
167
|
+
|
|
168
|
+
const providerOptions = {
|
|
169
|
+
anthropic: {
|
|
170
|
+
cacheControl: { type: "ephemeral" },
|
|
171
|
+
},
|
|
172
|
+
openrouter: {
|
|
173
|
+
cacheControl: { type: "ephemeral" },
|
|
174
|
+
},
|
|
175
|
+
bedrock: {
|
|
176
|
+
cachePoint: { type: "ephemeral" },
|
|
177
|
+
},
|
|
178
|
+
openaiCompatible: {
|
|
179
|
+
cache_control: { type: "ephemeral" },
|
|
180
|
+
},
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
for (const msg of unique([...system, ...final])) {
|
|
184
|
+
const shouldUseContentOptions = providerID !== "anthropic" && Array.isArray(msg.content) && msg.content.length > 0
|
|
185
|
+
|
|
186
|
+
if (shouldUseContentOptions) {
|
|
187
|
+
const lastContent = msg.content[msg.content.length - 1]
|
|
188
|
+
if (lastContent && typeof lastContent === "object") {
|
|
189
|
+
lastContent.providerOptions = {
|
|
190
|
+
...lastContent.providerOptions,
|
|
191
|
+
...providerOptions,
|
|
192
|
+
}
|
|
193
|
+
continue
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
msg.providerOptions = {
|
|
198
|
+
...msg.providerOptions,
|
|
199
|
+
...providerOptions,
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return msgs
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function unsupportedParts(msgs: ModelMessage[], model: Provider.Model): ModelMessage[] {
|
|
207
|
+
return msgs.map((msg) => {
|
|
208
|
+
if (msg.role !== "user" || !Array.isArray(msg.content)) return msg
|
|
209
|
+
|
|
210
|
+
const filtered = msg.content.map((part) => {
|
|
211
|
+
if (part.type !== "file" && part.type !== "image") return part
|
|
212
|
+
|
|
213
|
+
// Check for empty base64 image data
|
|
214
|
+
if (part.type === "image") {
|
|
215
|
+
const imageStr = part.image.toString()
|
|
216
|
+
if (imageStr.startsWith("data:")) {
|
|
217
|
+
const match = imageStr.match(/^data:([^;]+);base64,(.*)$/)
|
|
218
|
+
if (match && (!match[2] || match[2].length === 0)) {
|
|
219
|
+
return {
|
|
220
|
+
type: "text" as const,
|
|
221
|
+
text: "ERROR: Image file is empty or corrupted. Please provide a valid image.",
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const mime = part.type === "image" ? part.image.toString().split(";")[0].replace("data:", "") : part.mediaType
|
|
228
|
+
const filename = part.type === "file" ? part.filename : undefined
|
|
229
|
+
const modality = mimeToModality(mime)
|
|
230
|
+
if (!modality) return part
|
|
231
|
+
if (model.capabilities.input[modality]) return part
|
|
232
|
+
|
|
233
|
+
const name = filename ? `"${filename}"` : modality
|
|
234
|
+
return {
|
|
235
|
+
type: "text" as const,
|
|
236
|
+
text: `ERROR: Cannot read ${name} (this model does not support ${modality} input). Inform the user.`,
|
|
237
|
+
}
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
return { ...msg, content: filtered }
|
|
241
|
+
})
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export function message(msgs: ModelMessage[], model: Provider.Model, options: Record<string, unknown>) {
|
|
245
|
+
msgs = unsupportedParts(msgs, model)
|
|
246
|
+
msgs = normalizeMessages(msgs, model, options)
|
|
247
|
+
if (
|
|
248
|
+
model.providerID === "anthropic" ||
|
|
249
|
+
model.api.id.includes("anthropic") ||
|
|
250
|
+
model.api.id.includes("claude") ||
|
|
251
|
+
model.api.npm === "@ai-sdk/anthropic"
|
|
252
|
+
) {
|
|
253
|
+
msgs = applyCaching(msgs, model.providerID)
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Remap providerOptions keys from stored providerID to expected SDK key
|
|
257
|
+
const key = sdkKey(model.api.npm)
|
|
258
|
+
if (key && key !== model.providerID && model.api.npm !== "@ai-sdk/azure") {
|
|
259
|
+
const remap = (opts: Record<string, any> | undefined) => {
|
|
260
|
+
if (!opts) return opts
|
|
261
|
+
if (!(model.providerID in opts)) return opts
|
|
262
|
+
const result = { ...opts }
|
|
263
|
+
result[key] = result[model.providerID]
|
|
264
|
+
delete result[model.providerID]
|
|
265
|
+
return result
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
msgs = msgs.map((msg) => {
|
|
269
|
+
if (!Array.isArray(msg.content)) return { ...msg, providerOptions: remap(msg.providerOptions) }
|
|
270
|
+
return {
|
|
271
|
+
...msg,
|
|
272
|
+
providerOptions: remap(msg.providerOptions),
|
|
273
|
+
content: msg.content.map((part) => ({ ...part, providerOptions: remap(part.providerOptions) })),
|
|
274
|
+
} as typeof msg
|
|
275
|
+
})
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return msgs
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export function temperature(model: Provider.Model) {
|
|
282
|
+
const id = model.id.toLowerCase()
|
|
283
|
+
if (id.includes("qwen")) return 0.55
|
|
284
|
+
if (id.includes("claude")) return undefined
|
|
285
|
+
if (id.includes("gemini")) return 1.0
|
|
286
|
+
if (id.includes("glm-4.6")) return 1.0
|
|
287
|
+
if (id.includes("glm-4.7")) return 1.0
|
|
288
|
+
if (id.includes("minimax-m2")) return 1.0
|
|
289
|
+
if (id.includes("kimi-k2")) {
|
|
290
|
+
if (id.includes("thinking")) return 1.0
|
|
291
|
+
return 0.6
|
|
292
|
+
}
|
|
293
|
+
return undefined
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export function topP(model: Provider.Model) {
|
|
297
|
+
const id = model.id.toLowerCase()
|
|
298
|
+
if (id.includes("qwen")) return 1
|
|
299
|
+
if (id.includes("minimax-m2")) {
|
|
300
|
+
return 0.95
|
|
301
|
+
}
|
|
302
|
+
if (id.includes("gemini")) return 0.95
|
|
303
|
+
return undefined
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export function topK(model: Provider.Model) {
|
|
307
|
+
const id = model.id.toLowerCase()
|
|
308
|
+
if (id.includes("minimax-m2")) {
|
|
309
|
+
if (id.includes("m2.1")) return 40
|
|
310
|
+
return 20
|
|
311
|
+
}
|
|
312
|
+
if (id.includes("gemini")) return 64
|
|
313
|
+
return undefined
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
const WIDELY_SUPPORTED_EFFORTS = ["low", "medium", "high"]
|
|
317
|
+
const OPENAI_EFFORTS = ["none", "minimal", ...WIDELY_SUPPORTED_EFFORTS, "xhigh"]
|
|
318
|
+
|
|
319
|
+
export function variants(model: Provider.Model): Record<string, Record<string, any>> {
|
|
320
|
+
if (!model.capabilities.reasoning) return {}
|
|
321
|
+
|
|
322
|
+
const id = model.id.toLowerCase()
|
|
323
|
+
if (id.includes("deepseek") || id.includes("minimax") || id.includes("glm") || id.includes("mistral")) return {}
|
|
324
|
+
|
|
325
|
+
// see: https://docs.x.ai/docs/guides/reasoning#control-how-hard-the-model-thinks
|
|
326
|
+
if (id.includes("grok") && id.includes("grok-3-mini")) {
|
|
327
|
+
if (model.api.npm === "@openrouter/ai-sdk-provider") {
|
|
328
|
+
return {
|
|
329
|
+
low: { reasoning: { effort: "low" } },
|
|
330
|
+
high: { reasoning: { effort: "high" } },
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return {
|
|
334
|
+
low: { reasoningEffort: "low" },
|
|
335
|
+
high: { reasoningEffort: "high" },
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
if (id.includes("grok")) return {}
|
|
339
|
+
|
|
340
|
+
switch (model.api.npm) {
|
|
341
|
+
case "@openrouter/ai-sdk-provider":
|
|
342
|
+
if (!model.id.includes("gpt") && !model.id.includes("gemini-3")) return {}
|
|
343
|
+
return Object.fromEntries(OPENAI_EFFORTS.map((effort) => [effort, { reasoning: { effort } }]))
|
|
344
|
+
|
|
345
|
+
// TODO: YOU CANNOT SET max_tokens if this is set!!!
|
|
346
|
+
case "@ai-sdk/gateway":
|
|
347
|
+
return Object.fromEntries(OPENAI_EFFORTS.map((effort) => [effort, { reasoningEffort: effort }]))
|
|
348
|
+
|
|
349
|
+
case "@ai-sdk/github-copilot":
|
|
350
|
+
return Object.fromEntries(
|
|
351
|
+
WIDELY_SUPPORTED_EFFORTS.map((effort) => [
|
|
352
|
+
effort,
|
|
353
|
+
{
|
|
354
|
+
reasoningEffort: effort,
|
|
355
|
+
reasoningSummary: "auto",
|
|
356
|
+
include: ["reasoning.encrypted_content"],
|
|
357
|
+
},
|
|
358
|
+
]),
|
|
359
|
+
)
|
|
360
|
+
|
|
361
|
+
case "@ai-sdk/cerebras":
|
|
362
|
+
// https://v5.ai-sdk.dev/providers/ai-sdk-providers/cerebras
|
|
363
|
+
case "@ai-sdk/togetherai":
|
|
364
|
+
// https://v5.ai-sdk.dev/providers/ai-sdk-providers/togetherai
|
|
365
|
+
case "@ai-sdk/xai":
|
|
366
|
+
// https://v5.ai-sdk.dev/providers/ai-sdk-providers/xai
|
|
367
|
+
case "@ai-sdk/deepinfra":
|
|
368
|
+
// https://v5.ai-sdk.dev/providers/ai-sdk-providers/deepinfra
|
|
369
|
+
case "@ai-sdk/openai-compatible":
|
|
370
|
+
return Object.fromEntries(WIDELY_SUPPORTED_EFFORTS.map((effort) => [effort, { reasoningEffort: effort }]))
|
|
371
|
+
|
|
372
|
+
case "@ai-sdk/azure":
|
|
373
|
+
// https://v5.ai-sdk.dev/providers/ai-sdk-providers/azure
|
|
374
|
+
if (id === "o1-mini") return {}
|
|
375
|
+
const azureEfforts = ["low", "medium", "high"]
|
|
376
|
+
if (id.includes("gpt-5-") || id === "gpt-5") {
|
|
377
|
+
azureEfforts.unshift("minimal")
|
|
378
|
+
}
|
|
379
|
+
return Object.fromEntries(
|
|
380
|
+
azureEfforts.map((effort) => [
|
|
381
|
+
effort,
|
|
382
|
+
{
|
|
383
|
+
reasoningEffort: effort,
|
|
384
|
+
reasoningSummary: "auto",
|
|
385
|
+
include: ["reasoning.encrypted_content"],
|
|
386
|
+
},
|
|
387
|
+
]),
|
|
388
|
+
)
|
|
389
|
+
case "@ai-sdk/openai":
|
|
390
|
+
// https://v5.ai-sdk.dev/providers/ai-sdk-providers/openai
|
|
391
|
+
if (id === "gpt-5-pro") return {}
|
|
392
|
+
const openaiEfforts = iife(() => {
|
|
393
|
+
if (id.includes("codex")) {
|
|
394
|
+
if (id.includes("5.2")) return [...WIDELY_SUPPORTED_EFFORTS, "xhigh"]
|
|
395
|
+
return WIDELY_SUPPORTED_EFFORTS
|
|
396
|
+
}
|
|
397
|
+
const arr = [...WIDELY_SUPPORTED_EFFORTS]
|
|
398
|
+
if (id.includes("gpt-5-") || id === "gpt-5") {
|
|
399
|
+
arr.unshift("minimal")
|
|
400
|
+
}
|
|
401
|
+
if (model.release_date >= "2025-11-13") {
|
|
402
|
+
arr.unshift("none")
|
|
403
|
+
}
|
|
404
|
+
if (model.release_date >= "2025-12-04") {
|
|
405
|
+
arr.push("xhigh")
|
|
406
|
+
}
|
|
407
|
+
return arr
|
|
408
|
+
})
|
|
409
|
+
return Object.fromEntries(
|
|
410
|
+
openaiEfforts.map((effort) => [
|
|
411
|
+
effort,
|
|
412
|
+
{
|
|
413
|
+
reasoningEffort: effort,
|
|
414
|
+
reasoningSummary: "auto",
|
|
415
|
+
include: ["reasoning.encrypted_content"],
|
|
416
|
+
},
|
|
417
|
+
]),
|
|
418
|
+
)
|
|
419
|
+
|
|
420
|
+
case "@ai-sdk/anthropic":
|
|
421
|
+
// https://v5.ai-sdk.dev/providers/ai-sdk-providers/anthropic
|
|
422
|
+
return {
|
|
423
|
+
high: {
|
|
424
|
+
thinking: {
|
|
425
|
+
type: "enabled",
|
|
426
|
+
budgetTokens: 16000,
|
|
427
|
+
},
|
|
428
|
+
},
|
|
429
|
+
max: {
|
|
430
|
+
thinking: {
|
|
431
|
+
type: "enabled",
|
|
432
|
+
budgetTokens: 31999,
|
|
433
|
+
},
|
|
434
|
+
},
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
case "@ai-sdk/amazon-bedrock":
|
|
438
|
+
// https://v5.ai-sdk.dev/providers/ai-sdk-providers/amazon-bedrock
|
|
439
|
+
// For Anthropic models on Bedrock, use reasoningConfig with budgetTokens
|
|
440
|
+
if (model.api.id.includes("anthropic")) {
|
|
441
|
+
return {
|
|
442
|
+
high: {
|
|
443
|
+
reasoningConfig: {
|
|
444
|
+
type: "enabled",
|
|
445
|
+
budgetTokens: 16000,
|
|
446
|
+
},
|
|
447
|
+
},
|
|
448
|
+
max: {
|
|
449
|
+
reasoningConfig: {
|
|
450
|
+
type: "enabled",
|
|
451
|
+
budgetTokens: 31999,
|
|
452
|
+
},
|
|
453
|
+
},
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// For Amazon Nova models, use reasoningConfig with maxReasoningEffort
|
|
458
|
+
return Object.fromEntries(
|
|
459
|
+
WIDELY_SUPPORTED_EFFORTS.map((effort) => [
|
|
460
|
+
effort,
|
|
461
|
+
{
|
|
462
|
+
reasoningConfig: {
|
|
463
|
+
type: "enabled",
|
|
464
|
+
maxReasoningEffort: effort,
|
|
465
|
+
},
|
|
466
|
+
},
|
|
467
|
+
]),
|
|
468
|
+
)
|
|
469
|
+
|
|
470
|
+
case "@ai-sdk/google-vertex":
|
|
471
|
+
// https://v5.ai-sdk.dev/providers/ai-sdk-providers/google-vertex
|
|
472
|
+
case "@ai-sdk/google":
|
|
473
|
+
// https://v5.ai-sdk.dev/providers/ai-sdk-providers/google-generative-ai
|
|
474
|
+
if (id.includes("2.5")) {
|
|
475
|
+
return {
|
|
476
|
+
high: {
|
|
477
|
+
thinkingConfig: {
|
|
478
|
+
includeThoughts: true,
|
|
479
|
+
thinkingBudget: 16000,
|
|
480
|
+
},
|
|
481
|
+
},
|
|
482
|
+
max: {
|
|
483
|
+
thinkingConfig: {
|
|
484
|
+
includeThoughts: true,
|
|
485
|
+
thinkingBudget: 24576,
|
|
486
|
+
},
|
|
487
|
+
},
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
return Object.fromEntries(
|
|
491
|
+
["low", "high"].map((effort) => [
|
|
492
|
+
effort,
|
|
493
|
+
{
|
|
494
|
+
includeThoughts: true,
|
|
495
|
+
thinkingLevel: effort,
|
|
496
|
+
},
|
|
497
|
+
]),
|
|
498
|
+
)
|
|
499
|
+
|
|
500
|
+
case "@ai-sdk/mistral":
|
|
501
|
+
// https://v5.ai-sdk.dev/providers/ai-sdk-providers/mistral
|
|
502
|
+
return {}
|
|
503
|
+
|
|
504
|
+
case "@ai-sdk/cohere":
|
|
505
|
+
// https://v5.ai-sdk.dev/providers/ai-sdk-providers/cohere
|
|
506
|
+
return {}
|
|
507
|
+
|
|
508
|
+
case "@ai-sdk/groq":
|
|
509
|
+
// https://v5.ai-sdk.dev/providers/ai-sdk-providers/groq
|
|
510
|
+
const groqEffort = ["none", ...WIDELY_SUPPORTED_EFFORTS]
|
|
511
|
+
return Object.fromEntries(
|
|
512
|
+
groqEffort.map((effort) => [
|
|
513
|
+
effort,
|
|
514
|
+
{
|
|
515
|
+
includeThoughts: true,
|
|
516
|
+
thinkingLevel: effort,
|
|
517
|
+
},
|
|
518
|
+
]),
|
|
519
|
+
)
|
|
520
|
+
|
|
521
|
+
case "@ai-sdk/perplexity":
|
|
522
|
+
// https://v5.ai-sdk.dev/providers/ai-sdk-providers/perplexity
|
|
523
|
+
return {}
|
|
524
|
+
}
|
|
525
|
+
return {}
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
export function options(input: {
|
|
529
|
+
model: Provider.Model
|
|
530
|
+
sessionID: string
|
|
531
|
+
providerOptions?: Record<string, any>
|
|
532
|
+
}): Record<string, any> {
|
|
533
|
+
const result: Record<string, any> = {}
|
|
534
|
+
|
|
535
|
+
// openai and providers using openai package should set store to false by default.
|
|
536
|
+
if (
|
|
537
|
+
input.model.providerID === "openai" ||
|
|
538
|
+
input.model.api.npm === "@ai-sdk/openai" ||
|
|
539
|
+
input.model.api.npm === "@ai-sdk/github-copilot"
|
|
540
|
+
) {
|
|
541
|
+
result["store"] = false
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
if (input.model.api.npm === "@openrouter/ai-sdk-provider") {
|
|
545
|
+
result["usage"] = {
|
|
546
|
+
include: true,
|
|
547
|
+
}
|
|
548
|
+
if (input.model.api.id.includes("gemini-3")) {
|
|
549
|
+
result["reasoning"] = { effort: "high" }
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
if (
|
|
554
|
+
input.model.providerID === "baseten" ||
|
|
555
|
+
(input.model.providerID === "opencode" && ["kimi-k2-thinking", "glm-4.6"].includes(input.model.api.id))
|
|
556
|
+
) {
|
|
557
|
+
result["chat_template_args"] = { enable_thinking: true }
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
if (["zai", "zhipuai"].includes(input.model.providerID) && input.model.api.npm === "@ai-sdk/openai-compatible") {
|
|
561
|
+
result["thinking"] = {
|
|
562
|
+
type: "enabled",
|
|
563
|
+
clear_thinking: false,
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
if (input.model.providerID === "openai" || input.providerOptions?.setCacheKey) {
|
|
568
|
+
result["promptCacheKey"] = input.sessionID
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
if (input.model.api.npm === "@ai-sdk/google" || input.model.api.npm === "@ai-sdk/google-vertex") {
|
|
572
|
+
result["thinkingConfig"] = {
|
|
573
|
+
includeThoughts: true,
|
|
574
|
+
}
|
|
575
|
+
if (input.model.api.id.includes("gemini-3")) {
|
|
576
|
+
result["thinkingConfig"]["thinkingLevel"] = "high"
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
if (input.model.api.id.includes("gpt-5") && !input.model.api.id.includes("gpt-5-chat")) {
|
|
581
|
+
if (input.model.providerID.includes("codex")) {
|
|
582
|
+
result["store"] = false
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
if (!input.model.api.id.includes("codex") && !input.model.api.id.includes("gpt-5-pro")) {
|
|
586
|
+
result["reasoningEffort"] = "medium"
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
if (input.model.api.id.endsWith("gpt-5.") && input.model.providerID !== "azure") {
|
|
590
|
+
result["textVerbosity"] = "low"
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
if (input.model.providerID.startsWith("opencode")) {
|
|
594
|
+
result["promptCacheKey"] = input.sessionID
|
|
595
|
+
result["include"] = ["reasoning.encrypted_content"]
|
|
596
|
+
result["reasoningSummary"] = "auto"
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
return result
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
export function smallOptions(model: Provider.Model) {
|
|
603
|
+
if (model.providerID === "openai" || model.api.id.includes("gpt-5")) {
|
|
604
|
+
if (model.api.id.includes("5.")) {
|
|
605
|
+
return { reasoningEffort: "low" }
|
|
606
|
+
}
|
|
607
|
+
return { reasoningEffort: "minimal" }
|
|
608
|
+
}
|
|
609
|
+
if (model.providerID === "google") {
|
|
610
|
+
// gemini-3 uses thinkingLevel, gemini-2.5 uses thinkingBudget
|
|
611
|
+
if (model.api.id.includes("gemini-3")) {
|
|
612
|
+
return { thinkingConfig: { thinkingLevel: "minimal" } }
|
|
613
|
+
}
|
|
614
|
+
return { thinkingConfig: { thinkingBudget: 0 } }
|
|
615
|
+
}
|
|
616
|
+
if (model.providerID === "openrouter") {
|
|
617
|
+
if (model.api.id.includes("google")) {
|
|
618
|
+
return { reasoning: { enabled: false } }
|
|
619
|
+
}
|
|
620
|
+
return { reasoningEffort: "minimal" }
|
|
621
|
+
}
|
|
622
|
+
return {}
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
export function providerOptions(model: Provider.Model, options: { [x: string]: any }) {
|
|
626
|
+
const key = sdkKey(model.api.npm) ?? model.providerID
|
|
627
|
+
return { [key]: options }
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
export function maxOutputTokens(
|
|
631
|
+
npm: string,
|
|
632
|
+
options: Record<string, any>,
|
|
633
|
+
modelLimit: number,
|
|
634
|
+
globalLimit: number,
|
|
635
|
+
): number {
|
|
636
|
+
const modelCap = modelLimit || globalLimit
|
|
637
|
+
const standardLimit = Math.min(modelCap, globalLimit)
|
|
638
|
+
|
|
639
|
+
if (npm === "@ai-sdk/anthropic") {
|
|
640
|
+
const thinking = options?.["thinking"]
|
|
641
|
+
const budgetTokens = typeof thinking?.["budgetTokens"] === "number" ? thinking["budgetTokens"] : 0
|
|
642
|
+
const enabled = thinking?.["type"] === "enabled"
|
|
643
|
+
if (enabled && budgetTokens > 0) {
|
|
644
|
+
// Return text tokens so that text + thinking <= model cap, preferring 32k text when possible.
|
|
645
|
+
if (budgetTokens + standardLimit <= modelCap) {
|
|
646
|
+
return standardLimit
|
|
647
|
+
}
|
|
648
|
+
return modelCap - budgetTokens
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
return standardLimit
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
export function schema(model: Provider.Model, schema: JSONSchema.BaseSchema) {
|
|
656
|
+
/*
|
|
657
|
+
if (["openai", "azure"].includes(providerID)) {
|
|
658
|
+
if (schema.type === "object" && schema.properties) {
|
|
659
|
+
for (const [key, value] of Object.entries(schema.properties)) {
|
|
660
|
+
if (schema.required?.includes(key)) continue
|
|
661
|
+
schema.properties[key] = {
|
|
662
|
+
anyOf: [
|
|
663
|
+
value as JSONSchema.JSONSchema,
|
|
664
|
+
{
|
|
665
|
+
type: "null",
|
|
666
|
+
},
|
|
667
|
+
],
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
*/
|
|
673
|
+
|
|
674
|
+
// Convert integer enums to string enums for Google/Gemini
|
|
675
|
+
if (model.providerID === "google" || model.api.id.includes("gemini")) {
|
|
676
|
+
const sanitizeGemini = (obj: any): any => {
|
|
677
|
+
if (obj === null || typeof obj !== "object") {
|
|
678
|
+
return obj
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
if (Array.isArray(obj)) {
|
|
682
|
+
return obj.map(sanitizeGemini)
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
const result: any = {}
|
|
686
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
687
|
+
if (key === "enum" && Array.isArray(value)) {
|
|
688
|
+
// Convert all enum values to strings
|
|
689
|
+
result[key] = value.map((v) => String(v))
|
|
690
|
+
// If we have integer type with enum, change type to string
|
|
691
|
+
if (result.type === "integer" || result.type === "number") {
|
|
692
|
+
result.type = "string"
|
|
693
|
+
}
|
|
694
|
+
} else if (typeof value === "object" && value !== null) {
|
|
695
|
+
result[key] = sanitizeGemini(value)
|
|
696
|
+
} else {
|
|
697
|
+
result[key] = value
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
// Filter required array to only include fields that exist in properties
|
|
702
|
+
if (result.type === "object" && result.properties && Array.isArray(result.required)) {
|
|
703
|
+
result.required = result.required.filter((field: any) => field in result.properties)
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
if (result.type === "array" && result.items == null) {
|
|
707
|
+
result.items = {}
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
return result
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
schema = sanitizeGemini(schema)
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
return schema
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
export function error(providerID: string, error: APICallError) {
|
|
720
|
+
let message = error.message
|
|
721
|
+
if (providerID.includes("github-copilot") && error.statusCode === 403) {
|
|
722
|
+
return "Please reauthenticate with the copilot provider to ensure your credentials work properly with OpenCode."
|
|
723
|
+
}
|
|
724
|
+
if (providerID.includes("github-copilot") && message.includes("The requested model is not supported")) {
|
|
725
|
+
return (
|
|
726
|
+
message +
|
|
727
|
+
"\n\nMake sure the model is enabled in your copilot settings: https://github.com/settings/copilot/features"
|
|
728
|
+
)
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
return message
|
|
732
|
+
}
|
|
733
|
+
}
|