orynacode-ai 1.16.2
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 +131 -0
- package/BUN_SHELL_MIGRATION_PLAN.md +136 -0
- package/Dockerfile +18 -0
- package/README.md +15 -0
- package/bin/orynacode +199 -0
- package/bunfig.toml +7 -0
- package/git +0 -0
- package/migration/20260511173437_session-metadata/migration.sql +1 -0
- package/migration/20260511173437_session-metadata/snapshot.json +1500 -0
- package/package.json +155 -0
- package/parsers-config.ts +386 -0
- package/script/bench-search.ts +115 -0
- package/script/bench-test-suite.ts +52 -0
- package/script/build.ts +244 -0
- package/script/generate.ts +14 -0
- package/script/httpapi-exercise.ts +1 -0
- package/script/postinstall.mjs +189 -0
- package/script/profile-test-files.ts +42 -0
- package/script/publish.ts +213 -0
- package/script/run-workspace-server +106 -0
- package/script/schema.ts +77 -0
- package/script/time.ts +6 -0
- package/script/trace-imports.ts +153 -0
- package/specs/effect/error-boundaries-plan.md +235 -0
- package/specs/effect/errors.md +207 -0
- package/specs/effect/facades.md +218 -0
- package/specs/effect/guide.md +247 -0
- package/specs/effect/instance-context.md +13 -0
- package/specs/effect/loose-ends.md +30 -0
- package/specs/effect/migration.md +62 -0
- package/specs/effect/routes.md +61 -0
- package/specs/effect/schema.md +88 -0
- package/specs/effect/server-package.md +58 -0
- package/specs/effect/todo.md +241 -0
- package/specs/effect/tools.md +88 -0
- package/specs/openapi-translation-cleanup.md +204 -0
- package/specs/tui-plugins.md +544 -0
- package/specs/v2/api.ts +67 -0
- package/specs/v2/message-shape.md +136 -0
- package/specs/v2/notifications.md +13 -0
- package/specs/v2/tui-command-shim.md +67 -0
- package/src/account/account.ts +459 -0
- package/src/account/repo.ts +170 -0
- package/src/account/schema.ts +99 -0
- package/src/account/url.ts +8 -0
- package/src/acp/agent.ts +95 -0
- package/src/acp/config-option.ts +203 -0
- package/src/acp/content.ts +250 -0
- package/src/acp/directory.ts +210 -0
- package/src/acp/error.ts +90 -0
- package/src/acp/event.ts +344 -0
- package/src/acp/permission.ts +145 -0
- package/src/acp/profile.ts +42 -0
- package/src/acp/service.ts +1062 -0
- package/src/acp/session.ts +231 -0
- package/src/acp/tool.ts +317 -0
- package/src/acp/usage.ts +239 -0
- package/src/agent/agent.ts +433 -0
- package/src/agent/generate.txt +75 -0
- package/src/agent/prompt/compaction.txt +9 -0
- package/src/agent/prompt/explore.txt +18 -0
- package/src/agent/prompt/summary.txt +11 -0
- package/src/agent/prompt/title.txt +44 -0
- package/src/agent/subagent-permissions.ts +35 -0
- package/src/audio.d.ts +14 -0
- package/src/auth/index.ts +96 -0
- package/src/background/job.ts +36 -0
- package/src/bus/global.ts +22 -0
- package/src/cli/bootstrap.ts +11 -0
- package/src/cli/cmd/account.ts +264 -0
- package/src/cli/cmd/acp.ts +76 -0
- package/src/cli/cmd/agent.ts +259 -0
- package/src/cli/cmd/cmd.ts +7 -0
- package/src/cli/cmd/db.ts +62 -0
- package/src/cli/cmd/debug/agent.handler.ts +193 -0
- package/src/cli/cmd/debug/agent.ts +27 -0
- package/src/cli/cmd/debug/config.ts +14 -0
- package/src/cli/cmd/debug/file.ts +87 -0
- package/src/cli/cmd/debug/index.ts +87 -0
- package/src/cli/cmd/debug/lsp.ts +51 -0
- package/src/cli/cmd/debug/ripgrep.ts +99 -0
- package/src/cli/cmd/debug/scrap.ts +18 -0
- package/src/cli/cmd/debug/skill.ts +15 -0
- package/src/cli/cmd/debug/snapshot.ts +50 -0
- package/src/cli/cmd/debug/startup.ts +11 -0
- package/src/cli/cmd/debug/v2.ts +46 -0
- package/src/cli/cmd/export.ts +292 -0
- package/src/cli/cmd/generate.ts +54 -0
- package/src/cli/cmd/github.handler.ts +1593 -0
- package/src/cli/cmd/github.shared.ts +30 -0
- package/src/cli/cmd/github.ts +42 -0
- package/src/cli/cmd/import.ts +224 -0
- package/src/cli/cmd/mcp.ts +846 -0
- package/src/cli/cmd/models.ts +66 -0
- package/src/cli/cmd/plug.ts +230 -0
- package/src/cli/cmd/pr.ts +115 -0
- package/src/cli/cmd/prompt-display.ts +48 -0
- package/src/cli/cmd/providers.ts +506 -0
- package/src/cli/cmd/run/demo.ts +1274 -0
- package/src/cli/cmd/run/entry.body.ts +194 -0
- package/src/cli/cmd/run/footer.command.tsx +899 -0
- package/src/cli/cmd/run/footer.menu.tsx +306 -0
- package/src/cli/cmd/run/footer.permission.tsx +475 -0
- package/src/cli/cmd/run/footer.prompt.tsx +1207 -0
- package/src/cli/cmd/run/footer.question.tsx +579 -0
- package/src/cli/cmd/run/footer.subagent.tsx +171 -0
- package/src/cli/cmd/run/footer.ts +1092 -0
- package/src/cli/cmd/run/footer.view.tsx +935 -0
- package/src/cli/cmd/run/otel.ts +117 -0
- package/src/cli/cmd/run/permission.shared.ts +256 -0
- package/src/cli/cmd/run/prompt.shared.ts +147 -0
- package/src/cli/cmd/run/question.shared.ts +340 -0
- package/src/cli/cmd/run/runtime.boot.ts +210 -0
- package/src/cli/cmd/run/runtime.lifecycle.ts +369 -0
- package/src/cli/cmd/run/runtime.queue.ts +347 -0
- package/src/cli/cmd/run/runtime.shared.ts +17 -0
- package/src/cli/cmd/run/runtime.stdin.ts +37 -0
- package/src/cli/cmd/run/runtime.ts +879 -0
- package/src/cli/cmd/run/scrollback.shared.ts +92 -0
- package/src/cli/cmd/run/scrollback.surface.ts +435 -0
- package/src/cli/cmd/run/scrollback.writer.tsx +335 -0
- package/src/cli/cmd/run/session-data.ts +1113 -0
- package/src/cli/cmd/run/session-replay.ts +301 -0
- package/src/cli/cmd/run/session.shared.ts +196 -0
- package/src/cli/cmd/run/splash.ts +310 -0
- package/src/cli/cmd/run/stream.transport.ts +1465 -0
- package/src/cli/cmd/run/stream.ts +175 -0
- package/src/cli/cmd/run/subagent-data.ts +844 -0
- package/src/cli/cmd/run/theme.ts +603 -0
- package/src/cli/cmd/run/tool.ts +1489 -0
- package/src/cli/cmd/run/trace.ts +94 -0
- package/src/cli/cmd/run/types.ts +342 -0
- package/src/cli/cmd/run/variant.shared.ts +215 -0
- package/src/cli/cmd/run.ts +879 -0
- package/src/cli/cmd/serve.ts +24 -0
- package/src/cli/cmd/session.ts +147 -0
- package/src/cli/cmd/stats.ts +393 -0
- package/src/cli/cmd/tui/app.tsx +1113 -0
- package/src/cli/cmd/tui/attach.ts +103 -0
- package/src/cli/cmd/tui/attention.ts +262 -0
- package/src/cli/cmd/tui/component/bg-pulse-render.ts +436 -0
- package/src/cli/cmd/tui/component/bg-pulse.tsx +99 -0
- package/src/cli/cmd/tui/component/border.tsx +21 -0
- package/src/cli/cmd/tui/component/command-palette.tsx +79 -0
- package/src/cli/cmd/tui/component/dialog-agent.tsx +31 -0
- package/src/cli/cmd/tui/component/dialog-console-org.tsx +103 -0
- package/src/cli/cmd/tui/component/dialog-mcp.tsx +85 -0
- package/src/cli/cmd/tui/component/dialog-model.tsx +185 -0
- package/src/cli/cmd/tui/component/dialog-move-session.tsx +240 -0
- package/src/cli/cmd/tui/component/dialog-provider.tsx +687 -0
- package/src/cli/cmd/tui/component/dialog-retry-action.tsx +160 -0
- package/src/cli/cmd/tui/component/dialog-session-delete-failed.tsx +99 -0
- package/src/cli/cmd/tui/component/dialog-session-list.tsx +318 -0
- package/src/cli/cmd/tui/component/dialog-session-rename.tsx +31 -0
- package/src/cli/cmd/tui/component/dialog-skill.tsx +36 -0
- package/src/cli/cmd/tui/component/dialog-stash.tsx +87 -0
- package/src/cli/cmd/tui/component/dialog-status.tsx +168 -0
- package/src/cli/cmd/tui/component/dialog-tag.tsx +47 -0
- package/src/cli/cmd/tui/component/dialog-theme-list.tsx +50 -0
- package/src/cli/cmd/tui/component/dialog-variant.tsx +39 -0
- package/src/cli/cmd/tui/component/dialog-workspace-create.tsx +313 -0
- package/src/cli/cmd/tui/component/dialog-workspace-file-changes.tsx +144 -0
- package/src/cli/cmd/tui/component/dialog-workspace-list.tsx +112 -0
- package/src/cli/cmd/tui/component/dialog-workspace-unavailable.tsx +69 -0
- package/src/cli/cmd/tui/component/error-component.tsx +81 -0
- package/src/cli/cmd/tui/component/logo.tsx +885 -0
- package/src/cli/cmd/tui/component/plugin-route-missing.tsx +14 -0
- package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +799 -0
- package/src/cli/cmd/tui/component/prompt/cwd.ts +0 -0
- package/src/cli/cmd/tui/component/prompt/frecency.tsx +90 -0
- package/src/cli/cmd/tui/component/prompt/history.tsx +117 -0
- package/src/cli/cmd/tui/component/prompt/index.tsx +1725 -0
- package/src/cli/cmd/tui/component/prompt/move.tsx +192 -0
- package/src/cli/cmd/tui/component/prompt/part.ts +31 -0
- package/src/cli/cmd/tui/component/prompt/stash.tsx +101 -0
- package/src/cli/cmd/tui/component/prompt/traits.ts +35 -0
- package/src/cli/cmd/tui/component/prompt/workspace.tsx +137 -0
- package/src/cli/cmd/tui/component/spinner.tsx +24 -0
- package/src/cli/cmd/tui/component/startup-loading.tsx +63 -0
- package/src/cli/cmd/tui/component/todo-item.tsx +32 -0
- package/src/cli/cmd/tui/component/use-connected.tsx +9 -0
- package/src/cli/cmd/tui/component/workspace-label.tsx +19 -0
- package/src/cli/cmd/tui/config/cwd.ts +5 -0
- package/src/cli/cmd/tui/config/keybind.ts +467 -0
- package/src/cli/cmd/tui/config/tui-migrate.ts +154 -0
- package/src/cli/cmd/tui/config/tui-schema.ts +88 -0
- package/src/cli/cmd/tui/config/tui.ts +308 -0
- package/src/cli/cmd/tui/context/agent.tsx +11 -0
- package/src/cli/cmd/tui/context/aggregate-failures.ts +51 -0
- package/src/cli/cmd/tui/context/args.tsx +15 -0
- package/src/cli/cmd/tui/context/directory.ts +15 -0
- package/src/cli/cmd/tui/context/editor-zed.ts +287 -0
- package/src/cli/cmd/tui/context/editor.ts +469 -0
- package/src/cli/cmd/tui/context/event.ts +38 -0
- package/src/cli/cmd/tui/context/exit.tsx +42 -0
- package/src/cli/cmd/tui/context/helper.tsx +25 -0
- package/src/cli/cmd/tui/context/kv.tsx +76 -0
- package/src/cli/cmd/tui/context/local.tsx +510 -0
- package/src/cli/cmd/tui/context/path-format.tsx +39 -0
- package/src/cli/cmd/tui/context/project.tsx +111 -0
- package/src/cli/cmd/tui/context/prompt.tsx +18 -0
- package/src/cli/cmd/tui/context/route.tsx +52 -0
- package/src/cli/cmd/tui/context/sdk.tsx +142 -0
- package/src/cli/cmd/tui/context/sync-v2.tsx +447 -0
- package/src/cli/cmd/tui/context/sync.tsx +628 -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 +230 -0
- package/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +230 -0
- package/src/cli/cmd/tui/context/theme/catppuccin.json +112 -0
- package/src/cli/cmd/tui/context/theme/cobalt2.json +225 -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 +242 -0
- package/src/cli/cmd/tui/context/theme/kanagawa.json +77 -0
- package/src/cli/cmd/tui/context/theme/lucent-orng.json +234 -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/opencode.json +245 -0
- package/src/cli/cmd/tui/context/theme/orng.json +249 -0
- package/src/cli/cmd/tui/context/theme/oryna.json +95 -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 +1341 -0
- package/src/cli/cmd/tui/context/thinking.ts +67 -0
- package/src/cli/cmd/tui/context/tui-config.tsx +9 -0
- package/src/cli/cmd/tui/event.ts +53 -0
- package/src/cli/cmd/tui/feature-plugins/home/footer.tsx +98 -0
- package/src/cli/cmd/tui/feature-plugins/home/tips-view.tsx +288 -0
- package/src/cli/cmd/tui/feature-plugins/home/tips.tsx +59 -0
- package/src/cli/cmd/tui/feature-plugins/session/dialog.tsx +356 -0
- package/src/cli/cmd/tui/feature-plugins/session/index.tsx +32 -0
- package/src/cli/cmd/tui/feature-plugins/session/preview-pane.tsx +288 -0
- package/src/cli/cmd/tui/feature-plugins/session/util.tsx +54 -0
- package/src/cli/cmd/tui/feature-plugins/sidebar/context.tsx +65 -0
- package/src/cli/cmd/tui/feature-plugins/sidebar/files.tsx +70 -0
- package/src/cli/cmd/tui/feature-plugins/sidebar/footer.tsx +96 -0
- package/src/cli/cmd/tui/feature-plugins/sidebar/lsp.tsx +65 -0
- package/src/cli/cmd/tui/feature-plugins/sidebar/mcp.tsx +97 -0
- package/src/cli/cmd/tui/feature-plugins/sidebar/todo.tsx +49 -0
- package/src/cli/cmd/tui/feature-plugins/system/diff-viewer-file-tree-utils.ts +232 -0
- package/src/cli/cmd/tui/feature-plugins/system/diff-viewer-file-tree.tsx +162 -0
- package/src/cli/cmd/tui/feature-plugins/system/diff-viewer-ui.tsx +103 -0
- package/src/cli/cmd/tui/feature-plugins/system/diff-viewer.tsx +1058 -0
- package/src/cli/cmd/tui/feature-plugins/system/notifications.ts +94 -0
- package/src/cli/cmd/tui/feature-plugins/system/plugins.tsx +269 -0
- package/src/cli/cmd/tui/feature-plugins/system/session-v2.tsx +1184 -0
- package/src/cli/cmd/tui/feature-plugins/system/which-key.tsx +608 -0
- package/src/cli/cmd/tui/keymap.tsx +283 -0
- package/src/cli/cmd/tui/layer.ts +6 -0
- package/src/cli/cmd/tui/plugin/api.tsx +390 -0
- package/src/cli/cmd/tui/plugin/command-shim.ts +109 -0
- package/src/cli/cmd/tui/plugin/internal.ts +42 -0
- package/src/cli/cmd/tui/plugin/runtime.ts +1131 -0
- package/src/cli/cmd/tui/plugin/slots.tsx +60 -0
- package/src/cli/cmd/tui/routes/home/session-destination.tsx +39 -0
- package/src/cli/cmd/tui/routes/home.tsx +149 -0
- package/src/cli/cmd/tui/routes/session/dialog-fork-from-timeline.tsx +76 -0
- package/src/cli/cmd/tui/routes/session/dialog-message.tsx +108 -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/footer.tsx +91 -0
- package/src/cli/cmd/tui/routes/session/index.tsx +2629 -0
- package/src/cli/cmd/tui/routes/session/permission.tsx +729 -0
- package/src/cli/cmd/tui/routes/session/question.tsx +514 -0
- package/src/cli/cmd/tui/routes/session/sidebar.tsx +102 -0
- package/src/cli/cmd/tui/routes/session/subagent-footer.tsx +132 -0
- package/src/cli/cmd/tui/thread.ts +264 -0
- package/src/cli/cmd/tui/ui/dialog-alert.tsx +66 -0
- package/src/cli/cmd/tui/ui/dialog-confirm.tsx +108 -0
- package/src/cli/cmd/tui/ui/dialog-export-options.tsx +217 -0
- package/src/cli/cmd/tui/ui/dialog-help.tsx +40 -0
- package/src/cli/cmd/tui/ui/dialog-prompt.tsx +126 -0
- package/src/cli/cmd/tui/ui/dialog-select.tsx +712 -0
- package/src/cli/cmd/tui/ui/dialog.tsx +218 -0
- package/src/cli/cmd/tui/ui/link.tsx +34 -0
- package/src/cli/cmd/tui/ui/spinner.ts +368 -0
- package/src/cli/cmd/tui/ui/toast.tsx +102 -0
- package/src/cli/cmd/tui/util/audio.ts +58 -0
- package/src/cli/cmd/tui/util/clipboard.ts +181 -0
- package/src/cli/cmd/tui/util/collapse-tool-output.ts +19 -0
- package/src/cli/cmd/tui/util/editor.ts +43 -0
- package/src/cli/cmd/tui/util/layout.ts +25 -0
- package/src/cli/cmd/tui/util/model.ts +23 -0
- package/src/cli/cmd/tui/util/provider-origin.ts +7 -0
- package/src/cli/cmd/tui/util/revert-diff.ts +18 -0
- package/src/cli/cmd/tui/util/scroll.ts +25 -0
- package/src/cli/cmd/tui/util/selection.ts +73 -0
- package/src/cli/cmd/tui/util/signal.ts +41 -0
- package/src/cli/cmd/tui/util/transcript.ts +112 -0
- package/src/cli/cmd/tui/validate-session.ts +29 -0
- package/src/cli/cmd/tui/win32.ts +130 -0
- package/src/cli/cmd/tui/worker.ts +99 -0
- package/src/cli/cmd/uninstall.ts +353 -0
- package/src/cli/cmd/upgrade.ts +74 -0
- package/src/cli/cmd/web.ts +84 -0
- package/src/cli/effect/prompt.ts +37 -0
- package/src/cli/effect-cmd.ts +96 -0
- package/src/cli/error.ts +118 -0
- package/src/cli/heap.ts +59 -0
- package/src/cli/logo.ts +21 -0
- package/src/cli/network.ts +64 -0
- package/src/cli/ui.ts +132 -0
- package/src/cli/upgrade.ts +53 -0
- package/src/command/index.ts +181 -0
- package/src/command/template/initialize.txt +66 -0
- package/src/command/template/review.txt +101 -0
- package/src/config/agent.ts +68 -0
- package/src/config/command.ts +45 -0
- package/src/config/config.ts +679 -0
- package/src/config/entry-name.ts +19 -0
- package/src/config/managed.ts +77 -0
- package/src/config/markdown.ts +36 -0
- package/src/config/parse.ts +79 -0
- package/src/config/paths.ts +45 -0
- package/src/config/plugin.ts +79 -0
- package/src/config/reference.ts +48 -0
- package/src/config/variable.ts +91 -0
- package/src/control-plane/adapters/index.ts +41 -0
- package/src/control-plane/adapters/worktree.ts +96 -0
- package/src/control-plane/dev/README.md +19 -0
- package/src/control-plane/dev/debug-workspace-plugin.ts +73 -0
- package/src/control-plane/types.ts +59 -0
- package/src/control-plane/util.ts +39 -0
- package/src/control-plane/workspace-adapter-runtime.ts +51 -0
- package/src/control-plane/workspace-context.ts +26 -0
- package/src/control-plane/workspace.ts +1075 -0
- package/src/effect/app-runtime.ts +133 -0
- package/src/effect/bootstrap-runtime.ts +23 -0
- package/src/effect/bridge.ts +84 -0
- package/src/effect/config-service.ts +67 -0
- package/src/effect/instance-ref.ts +11 -0
- package/src/effect/instance-registry.ts +12 -0
- package/src/effect/instance-state.ts +72 -0
- package/src/effect/promise.ts +17 -0
- package/src/effect/run-service.ts +47 -0
- package/src/effect/runner.ts +217 -0
- package/src/effect/runtime-flags.ts +76 -0
- package/src/env/index.ts +40 -0
- package/src/event-v2-bridge.ts +76 -0
- package/src/format/formatter.ts +404 -0
- package/src/format/index.ts +212 -0
- package/src/git/index.ts +347 -0
- package/src/id/id.ts +80 -0
- package/src/ide/index.ts +70 -0
- package/src/image/image.ts +177 -0
- package/src/index.ts +208 -0
- package/src/installation/index.ts +349 -0
- package/src/lsp/client.ts +686 -0
- package/src/lsp/diagnostic.ts +29 -0
- package/src/lsp/language.ts +121 -0
- package/src/lsp/launch.ts +21 -0
- package/src/lsp/lsp.ts +517 -0
- package/src/lsp/server.ts +2064 -0
- package/src/markdown.d.ts +4 -0
- package/src/mcp/auth.ts +171 -0
- package/src/mcp/index.ts +982 -0
- package/src/mcp/oauth-callback.ts +232 -0
- package/src/mcp/oauth-provider.ts +217 -0
- package/src/node.ts +5 -0
- package/src/oryna/agent.ts +112 -0
- package/src/oryna/reply-service.ts +8 -0
- package/src/patch/index.ts +689 -0
- package/src/permission/arity.ts +163 -0
- package/src/permission/evaluate.ts +1 -0
- package/src/permission/index.ts +230 -0
- package/src/plugin/azure.ts +26 -0
- package/src/plugin/cloudflare.ts +76 -0
- package/src/plugin/digitalocean.ts +391 -0
- package/src/plugin/github-copilot/copilot.ts +417 -0
- package/src/plugin/github-copilot/models.ts +246 -0
- package/src/plugin/index.ts +323 -0
- package/src/plugin/install.ts +439 -0
- package/src/plugin/loader.ts +237 -0
- package/src/plugin/meta.ts +188 -0
- package/src/plugin/openai/README.md +31 -0
- package/src/plugin/openai/codex.ts +647 -0
- package/src/plugin/openai/ws-pool.ts +290 -0
- package/src/plugin/openai/ws.ts +381 -0
- package/src/plugin/oryna.ts +349 -0
- package/src/plugin/shared.ts +323 -0
- package/src/plugin/xai.ts +742 -0
- package/src/project/bootstrap-service.ts +9 -0
- package/src/project/bootstrap.ts +80 -0
- package/src/project/instance-context.ts +24 -0
- package/src/project/instance-layer.ts +11 -0
- package/src/project/instance-runtime.ts +16 -0
- package/src/project/instance-store.ts +207 -0
- package/src/project/project.ts +520 -0
- package/src/project/vcs.ts +435 -0
- package/src/provider/auth.ts +230 -0
- package/src/provider/error.ts +188 -0
- package/src/provider/model-status.ts +8 -0
- package/src/provider/provider.ts +2009 -0
- package/src/provider/transform.ts +1363 -0
- package/src/pty-preparation.ts +30 -0
- package/src/question/index.ts +229 -0
- package/src/question/schema.ts +10 -0
- package/src/reference/reference.ts +239 -0
- package/src/reference/repository-cache.ts +320 -0
- package/src/server/auth.ts +48 -0
- package/src/server/cors.ts +34 -0
- package/src/server/event.ts +13 -0
- package/src/server/global-lifecycle.ts +37 -0
- package/src/server/init-projectors.ts +3 -0
- package/src/server/mdns.ts +60 -0
- package/src/server/projectors.ts +1 -0
- package/src/server/proxy-util.ts +48 -0
- package/src/server/routes/instance/httpapi/AGENTS.md +39 -0
- package/src/server/routes/instance/httpapi/api.ts +78 -0
- package/src/server/routes/instance/httpapi/errors.ts +193 -0
- package/src/server/routes/instance/httpapi/groups/config.ts +65 -0
- package/src/server/routes/instance/httpapi/groups/control-plane.ts +35 -0
- package/src/server/routes/instance/httpapi/groups/control.ts +76 -0
- package/src/server/routes/instance/httpapi/groups/event.ts +29 -0
- package/src/server/routes/instance/httpapi/groups/experimental.ts +260 -0
- package/src/server/routes/instance/httpapi/groups/file.ts +172 -0
- package/src/server/routes/instance/httpapi/groups/global.ts +138 -0
- package/src/server/routes/instance/httpapi/groups/instance.ts +206 -0
- package/src/server/routes/instance/httpapi/groups/mcp.ts +156 -0
- package/src/server/routes/instance/httpapi/groups/metadata.ts +18 -0
- package/src/server/routes/instance/httpapi/groups/permission.ts +61 -0
- package/src/server/routes/instance/httpapi/groups/project-copy.ts +88 -0
- package/src/server/routes/instance/httpapi/groups/project.ts +93 -0
- package/src/server/routes/instance/httpapi/groups/provider.ts +101 -0
- package/src/server/routes/instance/httpapi/groups/pty.ts +172 -0
- package/src/server/routes/instance/httpapi/groups/query.ts +12 -0
- package/src/server/routes/instance/httpapi/groups/question.ts +74 -0
- package/src/server/routes/instance/httpapi/groups/session.ts +462 -0
- package/src/server/routes/instance/httpapi/groups/sync.ts +113 -0
- package/src/server/routes/instance/httpapi/groups/tui.ts +208 -0
- package/src/server/routes/instance/httpapi/groups/workspace.ts +141 -0
- package/src/server/routes/instance/httpapi/handlers/config.ts +151 -0
- package/src/server/routes/instance/httpapi/handlers/control-plane.ts +37 -0
- package/src/server/routes/instance/httpapi/handlers/control.ts +40 -0
- package/src/server/routes/instance/httpapi/handlers/event.ts +102 -0
- package/src/server/routes/instance/httpapi/handlers/experimental.ts +187 -0
- package/src/server/routes/instance/httpapi/handlers/file.ts +103 -0
- package/src/server/routes/instance/httpapi/handlers/global.ts +157 -0
- package/src/server/routes/instance/httpapi/handlers/instance.ts +110 -0
- package/src/server/routes/instance/httpapi/handlers/mcp.ts +111 -0
- package/src/server/routes/instance/httpapi/handlers/permission.ts +41 -0
- package/src/server/routes/instance/httpapi/handlers/project-copy.ts +157 -0
- package/src/server/routes/instance/httpapi/handlers/project.ts +63 -0
- package/src/server/routes/instance/httpapi/handlers/provider.ts +160 -0
- package/src/server/routes/instance/httpapi/handlers/pty.ts +258 -0
- package/src/server/routes/instance/httpapi/handlers/question.ts +54 -0
- package/src/server/routes/instance/httpapi/handlers/session-errors.ts +21 -0
- package/src/server/routes/instance/httpapi/handlers/session.ts +442 -0
- package/src/server/routes/instance/httpapi/handlers/sync.ts +95 -0
- package/src/server/routes/instance/httpapi/handlers/tui.ts +131 -0
- package/src/server/routes/instance/httpapi/handlers/workspace.ts +102 -0
- package/src/server/routes/instance/httpapi/lifecycle.ts +57 -0
- package/src/server/routes/instance/httpapi/middleware/authorization.ts +147 -0
- package/src/server/routes/instance/httpapi/middleware/compression.ts +64 -0
- package/src/server/routes/instance/httpapi/middleware/cors-vary.ts +29 -0
- package/src/server/routes/instance/httpapi/middleware/error.ts +36 -0
- package/src/server/routes/instance/httpapi/middleware/fence.ts +25 -0
- package/src/server/routes/instance/httpapi/middleware/instance-context.ts +43 -0
- package/src/server/routes/instance/httpapi/middleware/proxy.ts +108 -0
- package/src/server/routes/instance/httpapi/middleware/schema-error.ts +42 -0
- package/src/server/routes/instance/httpapi/middleware/workspace-routing.ts +250 -0
- package/src/server/routes/instance/httpapi/public.ts +535 -0
- package/src/server/routes/instance/httpapi/server.ts +277 -0
- package/src/server/routes/instance/httpapi/websocket-tracker.ts +57 -0
- package/src/server/server.ts +218 -0
- package/src/server/shared/fence.ts +68 -0
- package/src/server/shared/pty-ticket.ts +15 -0
- package/src/server/shared/public-ui.ts +12 -0
- package/src/server/shared/tui-control.ts +28 -0
- package/src/server/shared/ui.ts +108 -0
- package/src/server/shared/workspace-routing.ts +38 -0
- package/src/session/compaction.ts +609 -0
- package/src/session/instruction.ts +237 -0
- package/src/session/llm/AGENTS.md +90 -0
- package/src/session/llm/ai-sdk.ts +288 -0
- package/src/session/llm/native-request.ts +196 -0
- package/src/session/llm/native-runtime.ts +195 -0
- package/src/session/llm/request.ts +215 -0
- package/src/session/llm.ts +402 -0
- package/src/session/message-error.ts +14 -0
- package/src/session/message-v2.ts +745 -0
- package/src/session/message.ts +148 -0
- package/src/session/overflow.ts +34 -0
- package/src/session/processor.ts +1063 -0
- package/src/session/prompt/anthropic.txt +105 -0
- package/src/session/prompt/beast.txt +147 -0
- package/src/session/prompt/build-switch.txt +5 -0
- package/src/session/prompt/codex.txt +79 -0
- package/src/session/prompt/copilot-gpt-5.txt +143 -0
- package/src/session/prompt/default.txt +95 -0
- package/src/session/prompt/gemini.txt +155 -0
- package/src/session/prompt/gpt.txt +107 -0
- package/src/session/prompt/kimi.txt +95 -0
- package/src/session/prompt/max-steps.txt +16 -0
- package/src/session/prompt/plan-mode.txt +70 -0
- package/src/session/prompt/plan-reminder-anthropic.txt +67 -0
- package/src/session/prompt/plan.txt +26 -0
- package/src/session/prompt/reference.ts +72 -0
- package/src/session/prompt/trinity.txt +97 -0
- package/src/session/prompt.ts +1755 -0
- package/src/session/reminders.ts +92 -0
- package/src/session/retry.ts +201 -0
- package/src/session/revert.ts +153 -0
- package/src/session/run-state.ts +153 -0
- package/src/session/schema.ts +26 -0
- package/src/session/session.ts +1116 -0
- package/src/session/status.ts +94 -0
- package/src/session/summary.ts +162 -0
- package/src/session/system.ts +84 -0
- package/src/session/todo.ts +87 -0
- package/src/session/tools.ts +211 -0
- package/src/share/session.ts +58 -0
- package/src/share/share-next.ts +379 -0
- package/src/shell/shell.ts +215 -0
- package/src/skill/discovery.ts +115 -0
- package/src/skill/index.ts +357 -0
- package/src/snapshot/index.ts +759 -0
- package/src/sql.d.ts +4 -0
- package/src/storage/schema.ts +5 -0
- package/src/storage/storage.ts +329 -0
- package/src/sync/README.md +179 -0
- package/src/sync/schema.ts +11 -0
- package/src/temporary.ts +33 -0
- package/src/tool/apply_patch.ts +313 -0
- package/src/tool/apply_patch.txt +33 -0
- package/src/tool/edit.ts +737 -0
- package/src/tool/edit.txt +10 -0
- package/src/tool/external-directory.ts +49 -0
- package/src/tool/glob.ts +84 -0
- package/src/tool/glob.txt +6 -0
- package/src/tool/grep.ts +140 -0
- package/src/tool/grep.txt +8 -0
- package/src/tool/invalid.ts +21 -0
- package/src/tool/json-schema.ts +164 -0
- package/src/tool/lsp.ts +113 -0
- package/src/tool/lsp.txt +24 -0
- package/src/tool/mcp-websearch.ts +96 -0
- package/src/tool/plan-enter.txt +14 -0
- package/src/tool/plan-exit.txt +13 -0
- package/src/tool/plan.ts +79 -0
- package/src/tool/question.ts +44 -0
- package/src/tool/question.txt +10 -0
- package/src/tool/read.ts +392 -0
- package/src/tool/read.txt +14 -0
- package/src/tool/registry.ts +475 -0
- package/src/tool/reply.ts +29 -0
- package/src/tool/schema.ts +14 -0
- package/src/tool/shell/id.ts +19 -0
- package/src/tool/shell/prompt.ts +307 -0
- package/src/tool/shell/shell.txt +21 -0
- package/src/tool/shell.ts +660 -0
- package/src/tool/skill.ts +72 -0
- package/src/tool/skill.txt +5 -0
- package/src/tool/task.ts +338 -0
- package/src/tool/task.txt +19 -0
- package/src/tool/todo.ts +57 -0
- package/src/tool/todowrite.txt +44 -0
- package/src/tool/tool.ts +183 -0
- package/src/tool/truncate.ts +160 -0
- package/src/tool/truncation-dir.ts +4 -0
- package/src/tool/webfetch.ts +192 -0
- package/src/tool/webfetch.txt +13 -0
- package/src/tool/websearch.ts +143 -0
- package/src/tool/websearch.txt +14 -0
- package/src/tool/write.ts +104 -0
- package/src/tool/write.txt +8 -0
- package/src/util/archive.ts +17 -0
- package/src/util/bom.ts +27 -0
- package/src/util/data-url.ts +9 -0
- package/src/util/defer.ts +10 -0
- package/src/util/effect-http-client.ts +11 -0
- package/src/util/error.ts +88 -0
- package/src/util/filesystem.ts +251 -0
- package/src/util/format.ts +20 -0
- package/src/util/iife.ts +3 -0
- package/src/util/lan-scan.ts +90 -0
- package/src/util/lazy.ts +20 -0
- package/src/util/local-context.ts +25 -0
- package/src/util/locale.ts +86 -0
- package/src/util/media.ts +26 -0
- package/src/util/process.ts +176 -0
- package/src/util/proxy-env.ts +72 -0
- package/src/util/queue.ts +32 -0
- package/src/util/record.ts +3 -0
- package/src/util/repository.ts +232 -0
- package/src/util/rpc.ts +66 -0
- package/src/util/signal.ts +12 -0
- package/src/util/timeout.ts +13 -0
- package/src/util/token.ts +1 -0
- package/src/util/wildcard.ts +59 -0
- package/src/worktree/index.ts +645 -0
- package/sst-env.d.ts +10 -0
- package/test/AGENTS.md +204 -0
- package/test/EFFECT_TEST_MIGRATION.md +169 -0
- package/test/account/repo.test.ts +353 -0
- package/test/account/service.test.ts +453 -0
- package/test/acp/config-option.test.ts +229 -0
- package/test/acp/content.test.ts +201 -0
- package/test/acp/directory.test.ts +186 -0
- package/test/acp/error.test.ts +67 -0
- package/test/acp/event.test.ts +711 -0
- package/test/acp/permission.test.ts +273 -0
- package/test/acp/service-session.test.ts +1174 -0
- package/test/acp/session.test.ts +200 -0
- package/test/acp/tool.test.ts +210 -0
- package/test/acp/usage.test.ts +315 -0
- package/test/agent/agent.test.ts +710 -0
- package/test/agent/plan-mode-subagent-bypass.test.ts +213 -0
- package/test/agent/plugin-agent-regression.test.ts +62 -0
- package/test/auth/auth.test.ts +77 -0
- package/test/background/job.test.ts +243 -0
- package/test/cli/account.test.ts +30 -0
- package/test/cli/acp/acp-test-client.ts +97 -0
- package/test/cli/acp/config-options.test.ts +103 -0
- package/test/cli/acp/helpers.ts +96 -0
- package/test/cli/acp/initialize-auth.test.ts +61 -0
- package/test/cli/acp/lifecycle.test.ts +118 -0
- package/test/cli/acp/prompt-content.test.ts +97 -0
- package/test/cli/acp/skills.test.ts +38 -0
- package/test/cli/cmd/tui/aggregate-failures.test.ts +93 -0
- package/test/cli/cmd/tui/attention.test.ts +484 -0
- package/test/cli/cmd/tui/dialog-workspace-create.test.ts +28 -0
- package/test/cli/cmd/tui/model-options.test.ts +30 -0
- package/test/cli/cmd/tui/notifications.test.ts +267 -0
- package/test/cli/cmd/tui/prompt-history.test.ts +44 -0
- package/test/cli/cmd/tui/prompt-part.test.ts +77 -0
- package/test/cli/cmd/tui/prompt-traits.test.ts +29 -0
- package/test/cli/cmd/tui/provider-options.test.ts +29 -0
- package/test/cli/cmd/tui/sync-fixture.tsx +64 -0
- package/test/cli/cmd/tui/sync-live-hydration.test.tsx +278 -0
- package/test/cli/cmd/tui/sync-undefined-messages.test.tsx +47 -0
- package/test/cli/cmd/tui/sync.test.tsx +70 -0
- package/test/cli/effect-cmd-instance-als.test.ts +39 -0
- package/test/cli/error.test.ts +95 -0
- package/test/cli/github-action.test.ts +199 -0
- package/test/cli/github-remote.test.ts +90 -0
- package/test/cli/help/__snapshots__/help-snapshots.test.ts.snap +631 -0
- package/test/cli/help/help-snapshots.test.ts +137 -0
- package/test/cli/import.test.ts +54 -0
- package/test/cli/mcp-add.test.ts +74 -0
- package/test/cli/plugin-auth-picker.test.ts +120 -0
- package/test/cli/run/entry.body.test.ts +536 -0
- package/test/cli/run/footer.menu.test.ts +43 -0
- package/test/cli/run/footer.view.test.tsx +927 -0
- package/test/cli/run/permission.shared.test.ts +144 -0
- package/test/cli/run/prompt.shared.test.ts +133 -0
- package/test/cli/run/question.shared.test.ts +115 -0
- package/test/cli/run/run-process.test.ts +84 -0
- package/test/cli/run/runtime.boot.test.ts +282 -0
- package/test/cli/run/runtime.queue.test.ts +465 -0
- package/test/cli/run/runtime.stdin.test.ts +71 -0
- package/test/cli/run/scrollback.surface.test.ts +1048 -0
- package/test/cli/run/session-data.test.ts +595 -0
- package/test/cli/run/session-replay.test.ts +456 -0
- package/test/cli/run/session.shared.test.ts +247 -0
- package/test/cli/run/stream.test.ts +56 -0
- package/test/cli/run/stream.transport.test.ts +2363 -0
- package/test/cli/run/subagent-data.test.ts +456 -0
- package/test/cli/run/theme.test.ts +152 -0
- package/test/cli/run/variant.shared.test.ts +217 -0
- package/test/cli/serve/serve-process.test.ts +61 -0
- package/test/cli/smokes/read-only.test.ts +115 -0
- package/test/cli/tui/__snapshots__/inline-tool-wrap-snapshot.test.tsx.snap +72 -0
- package/test/cli/tui/app-lifecycle.test.ts +261 -0
- package/test/cli/tui/dialog-prompt.test.tsx +146 -0
- package/test/cli/tui/diff-viewer-file-tree-utils.test.ts +323 -0
- package/test/cli/tui/diff-viewer-file-tree.test.tsx +197 -0
- package/test/cli/tui/diff-viewer.test.tsx +230 -0
- package/test/cli/tui/editor-context-zed.test.ts +384 -0
- package/test/cli/tui/editor-context.test.tsx +288 -0
- package/test/cli/tui/inline-tool-wrap-snapshot.test.tsx +232 -0
- package/test/cli/tui/keymap.test.tsx +136 -0
- package/test/cli/tui/plugin-add.test.ts +110 -0
- package/test/cli/tui/plugin-install.test.ts +87 -0
- package/test/cli/tui/plugin-lifecycle.test.ts +224 -0
- package/test/cli/tui/plugin-loader-entrypoint.test.ts +485 -0
- package/test/cli/tui/plugin-loader-pure.test.ts +72 -0
- package/test/cli/tui/plugin-loader.test.ts +1332 -0
- package/test/cli/tui/plugin-toggle.test.ts +264 -0
- package/test/cli/tui/prompt-submit-race.test.ts +98 -0
- package/test/cli/tui/revert-diff.test.ts +35 -0
- package/test/cli/tui/slot-replace.test.tsx +50 -0
- package/test/cli/tui/sync-v2.test.tsx +558 -0
- package/test/cli/tui/theme-store.test.ts +76 -0
- package/test/cli/tui/thinking.test.ts +36 -0
- package/test/cli/tui/thread.test.ts +28 -0
- package/test/cli/tui/transcript.test.ts +426 -0
- package/test/cli/tui/use-event.test.tsx +145 -0
- package/test/config/agent-color.test.ts +47 -0
- package/test/config/config.test.ts +1991 -0
- package/test/config/entry-name.test.ts +57 -0
- package/test/config/fixtures/empty-frontmatter.md +4 -0
- package/test/config/fixtures/frontmatter.md +28 -0
- package/test/config/fixtures/markdown-header.md +11 -0
- package/test/config/fixtures/no-frontmatter.md +1 -0
- package/test/config/fixtures/weird-model-id.md +13 -0
- package/test/config/lsp.test.ts +69 -0
- package/test/config/markdown.test.ts +228 -0
- package/test/config/plugin.test.ts +0 -0
- package/test/config/tui.test.ts +878 -0
- package/test/control-plane/adapters.test.ts +71 -0
- package/test/control-plane/workspace.test.ts +1704 -0
- package/test/effect/app-runtime-logger.test.ts +105 -0
- package/test/effect/config-service.test.ts +65 -0
- package/test/effect/instance-state.test.ts +391 -0
- package/test/effect/run-service.test.ts +89 -0
- package/test/effect/runner.test.ts +514 -0
- package/test/effect/runtime-flags.test.ts +373 -0
- package/test/fake/account.ts +9 -0
- package/test/fake/auth.ts +8 -0
- package/test/fake/npm.ts +8 -0
- package/test/fake/provider.ts +82 -0
- package/test/fake/skill.ts +8 -0
- package/test/filesystem/filesystem.test.ts +319 -0
- package/test/fixture/agent-plugin.constants.ts +6 -0
- package/test/fixture/agent-plugin.ts +12 -0
- package/test/fixture/config.ts +23 -0
- package/test/fixture/db.ts +11 -0
- package/test/fixture/fixture.test.ts +26 -0
- package/test/fixture/fixture.ts +224 -0
- package/test/fixture/flag.ts +20 -0
- package/test/fixture/flock-worker.ts +72 -0
- package/test/fixture/lsp/fake-lsp-server.js +249 -0
- package/test/fixture/plug-worker.ts +93 -0
- package/test/fixture/plugin-meta-worker.ts +19 -0
- package/test/fixture/plugin.ts +10 -0
- package/test/fixture/skills/agents-sdk/SKILL.md +152 -0
- package/test/fixture/skills/agents-sdk/references/callable.md +92 -0
- package/test/fixture/skills/cloudflare/SKILL.md +211 -0
- package/test/fixture/skills/index.json +6 -0
- package/test/fixture/tui-plugin.ts +355 -0
- package/test/fixture/tui-runtime.ts +64 -0
- package/test/fixture/tui-sdk.ts +82 -0
- package/test/fixture/workspace.ts +30 -0
- package/test/fixtures/recordings/session/native-anthropic-tool-loop.json +49 -0
- package/test/fixtures/recordings/session/native-openai-oauth-tool-loop.json +45 -0
- package/test/fixtures/recordings/session/native-zen-tool-loop.json +49 -0
- package/test/format/format.test.ts +228 -0
- package/test/git/git.test.ts +178 -0
- package/test/ide/ide.test.ts +82 -0
- package/test/image/fixtures/picture-5mb-base64.png +0 -0
- package/test/image/image.test.ts +123 -0
- package/test/installation/installation.test.ts +230 -0
- package/test/lib/cli-process.ts +459 -0
- package/test/lib/effect.ts +177 -0
- package/test/lib/filesystem.ts +10 -0
- package/test/lib/llm-server.ts +771 -0
- package/test/lib/snapshot.ts +73 -0
- package/test/lib/test-provider.ts +37 -0
- package/test/lib/websocket.ts +46 -0
- package/test/lsp/client.test.ts +493 -0
- package/test/lsp/index.test.ts +232 -0
- package/test/lsp/launch.test.ts +22 -0
- package/test/lsp/lifecycle.test.ts +160 -0
- package/test/mcp/auth.test.ts +78 -0
- package/test/mcp/headers.test.ts +126 -0
- package/test/mcp/lifecycle.test.ts +888 -0
- package/test/mcp/oauth-auto-connect.test.ts +236 -0
- package/test/mcp/oauth-browser.test.ts +228 -0
- package/test/mcp/oauth-callback.test.ts +34 -0
- package/test/mcp/oauth-provider.test.ts +61 -0
- package/test/patch/patch.test.ts +383 -0
- package/test/permission/arity.test.ts +33 -0
- package/test/permission/next.test.ts +1176 -0
- package/test/permission-task.test.ts +318 -0
- package/test/plugin/auth-override.test.ts +105 -0
- package/test/plugin/cloudflare.test.ts +68 -0
- package/test/plugin/codex.test.ts +247 -0
- package/test/plugin/github-copilot-models.test.ts +332 -0
- package/test/plugin/install-concurrency.test.ts +140 -0
- package/test/plugin/install.test.ts +570 -0
- package/test/plugin/loader-shared.test.ts +1303 -0
- package/test/plugin/meta.test.ts +137 -0
- package/test/plugin/openai-rollout.test.ts +17 -0
- package/test/plugin/openai-ws.test.ts +877 -0
- package/test/plugin/shared.test.ts +88 -0
- package/test/plugin/trigger.test.ts +120 -0
- package/test/plugin/workspace-adapter.test.ts +137 -0
- package/test/plugin/xai.test.ts +634 -0
- package/test/preload.ts +95 -0
- package/test/project/instance-bootstrap.test.ts +110 -0
- package/test/project/instance.test.ts +245 -0
- package/test/project/migrate-global.test.ts +170 -0
- package/test/project/project-directory.test.ts +169 -0
- package/test/project/project.test.ts +818 -0
- package/test/project/vcs.test.ts +336 -0
- package/test/project/worktree-remove.test.ts +126 -0
- package/test/project/worktree.test.ts +320 -0
- package/test/provider/amazon-bedrock.test.ts +360 -0
- package/test/provider/cf-ai-gateway-e2e.test.ts +132 -0
- package/test/provider/digitalocean.test.ts +123 -0
- package/test/provider/gitlab-duo.test.ts +412 -0
- package/test/provider/header-timeout.test.ts +233 -0
- package/test/provider/model-status.test.ts +61 -0
- package/test/provider/provider.test.ts +1793 -0
- package/test/provider/transform.test.ts +3937 -0
- package/test/pty/pty-shell.test.ts +102 -0
- package/test/question/question.test.ts +465 -0
- package/test/reference/reference.test.ts +310 -0
- package/test/server/AGENTS.md +15 -0
- package/test/server/auth.test.ts +59 -0
- package/test/server/global-bus.ts +31 -0
- package/test/server/global-session-list.test.ts +107 -0
- package/test/server/httpapi-authorization.test.ts +174 -0
- package/test/server/httpapi-compression.test.ts +154 -0
- package/test/server/httpapi-config.test.ts +113 -0
- package/test/server/httpapi-control-plane.test.ts +63 -0
- package/test/server/httpapi-cors-vary.test.ts +66 -0
- package/test/server/httpapi-cors.test.ts +122 -0
- package/test/server/httpapi-error-middleware.test.ts +96 -0
- package/test/server/httpapi-event.test.ts +97 -0
- package/test/server/httpapi-exercise/assertions.ts +64 -0
- package/test/server/httpapi-exercise/backend.ts +144 -0
- package/test/server/httpapi-exercise/dsl.ts +210 -0
- package/test/server/httpapi-exercise/environment.ts +40 -0
- package/test/server/httpapi-exercise/index.ts +1535 -0
- package/test/server/httpapi-exercise/report.ts +66 -0
- package/test/server/httpapi-exercise/routing.ts +96 -0
- package/test/server/httpapi-exercise/runner.ts +267 -0
- package/test/server/httpapi-exercise/runtime.ts +52 -0
- package/test/server/httpapi-exercise/types.ts +123 -0
- package/test/server/httpapi-experimental.test.ts +300 -0
- package/test/server/httpapi-file.test.ts +76 -0
- package/test/server/httpapi-global.test.ts +66 -0
- package/test/server/httpapi-instance-context.test.ts +347 -0
- package/test/server/httpapi-instance-route-auth.test.ts +84 -0
- package/test/server/httpapi-instance.test.ts +265 -0
- package/test/server/httpapi-layer.ts +33 -0
- package/test/server/httpapi-listen.test.ts +415 -0
- package/test/server/httpapi-mcp-oauth.test.ts +73 -0
- package/test/server/httpapi-mcp.test.ts +226 -0
- package/test/server/httpapi-mdns.test.ts +82 -0
- package/test/server/httpapi-promptasync-context.test.ts +222 -0
- package/test/server/httpapi-provider.test.ts +403 -0
- package/test/server/httpapi-pty.test.ts +275 -0
- package/test/server/httpapi-public-openapi.test.ts +297 -0
- package/test/server/httpapi-query-schema-drift.test.ts +330 -0
- package/test/server/httpapi-schema-error-body.test.ts +165 -0
- package/test/server/httpapi-sdk.test.ts +909 -0
- package/test/server/httpapi-session.test.ts +1013 -0
- package/test/server/httpapi-sync.test.ts +154 -0
- package/test/server/httpapi-ui.test.ts +456 -0
- package/test/server/httpapi-v2-location.test.ts +85 -0
- package/test/server/httpapi-workspace-routing.test.ts +554 -0
- package/test/server/httpapi-workspace.test.ts +515 -0
- package/test/server/negative-tokens-regression.test.ts +83 -0
- package/test/server/project-copy.test.ts +101 -0
- package/test/server/project-init-git.test.ts +117 -0
- package/test/server/proxy-util.test.ts +113 -0
- package/test/server/sdk-error-shape.test.ts +84 -0
- package/test/server/sdk-v1-smoke.test.ts +60 -0
- package/test/server/session-actions.test.ts +112 -0
- package/test/server/session-diff-missing-patch.test.ts +99 -0
- package/test/server/session-list.test.ts +314 -0
- package/test/server/session-messages.test.ts +182 -0
- package/test/server/session-select.test.ts +69 -0
- package/test/server/workspace-proxy.test.ts +181 -0
- package/test/server/workspace-routing.test.ts +94 -0
- package/test/server/worktree-endpoint-repro.test.ts +307 -0
- package/test/session/compaction.test.ts +1835 -0
- package/test/session/instruction.test.ts +256 -0
- package/test/session/llm-native-recorded.test.ts +433 -0
- package/test/session/llm-native.test.ts +760 -0
- package/test/session/llm.test.ts +1932 -0
- package/test/session/message-v2.test.ts +1661 -0
- package/test/session/messages-pagination.test.ts +1059 -0
- package/test/session/processor-effect.test.ts +1101 -0
- package/test/session/prompt.test.ts +2318 -0
- package/test/session/retry.test.ts +439 -0
- package/test/session/revert-compact.test.ts +642 -0
- package/test/session/schema-decoding.test.ts +313 -0
- package/test/session/session-schema.test.ts +78 -0
- package/test/session/session.test.ts +251 -0
- package/test/session/snapshot-tool-race.test.ts +280 -0
- package/test/session/structured-output-integration.test.ts +235 -0
- package/test/session/structured-output.test.ts +387 -0
- package/test/session/system.test.ts +84 -0
- package/test/share/share-next.test.ts +344 -0
- package/test/shell/shell.test.ts +99 -0
- package/test/skill/discovery.test.ts +139 -0
- package/test/skill/skill.test.ts +571 -0
- package/test/snapshot/snapshot.test.ts +1121 -0
- package/test/storage/storage.test.ts +296 -0
- package/test/storage/workspace-time-migration.test.ts +50 -0
- package/test/tool/__snapshots__/parameters.test.ts.snap +484 -0
- package/test/tool/__snapshots__/tool.test.ts.snap +9 -0
- package/test/tool/apply_patch.test.ts +533 -0
- package/test/tool/edit.test.ts +578 -0
- package/test/tool/external-directory.test.ts +155 -0
- package/test/tool/fixtures/large-image.png +0 -0
- package/test/tool/fixtures/models-api.json +117299 -0
- package/test/tool/glob.test.ts +188 -0
- package/test/tool/grep.test.ts +266 -0
- package/test/tool/lsp.test.ts +181 -0
- package/test/tool/parameters.test.ts +293 -0
- package/test/tool/question.test.ts +138 -0
- package/test/tool/read.test.ts +654 -0
- package/test/tool/registry.test.ts +539 -0
- package/test/tool/shell.test.ts +1238 -0
- package/test/tool/skill.test.ts +132 -0
- package/test/tool/task.test.ts +901 -0
- package/test/tool/tool-define.test.ts +153 -0
- package/test/tool/truncation.test.ts +266 -0
- package/test/tool/webfetch.test.ts +113 -0
- package/test/tool/websearch.test.ts +99 -0
- package/test/tool/write.test.ts +276 -0
- package/test/util/data-url.test.ts +14 -0
- package/test/util/error.test.ts +64 -0
- package/test/util/filesystem.test.ts +656 -0
- package/test/util/format.test.ts +59 -0
- package/test/util/glob.test.ts +164 -0
- package/test/util/iife.test.ts +36 -0
- package/test/util/lazy.test.ts +50 -0
- package/test/util/log.test.ts +77 -0
- package/test/util/module.test.ts +59 -0
- package/test/util/process.test.ts +128 -0
- package/test/util/repository.test.ts +93 -0
- package/test/util/timeout.test.ts +21 -0
- package/test/util/wildcard.test.ts +90 -0
- package/test/v2/session-message-updater.test.ts +270 -0
- package/tsconfig.json +17 -0
|
@@ -0,0 +1,2009 @@
|
|
|
1
|
+
import os from "os"
|
|
2
|
+
import { ConfigV1 } from "@opencode-ai/core/v1/config/config"
|
|
3
|
+
import fuzzysort from "fuzzysort"
|
|
4
|
+
import { Config } from "@/config/config"
|
|
5
|
+
import { mapValues, mergeDeep, omit, pickBy, sortBy } from "remeda"
|
|
6
|
+
import { NoSuchModelError, type Provider as SDK } from "ai"
|
|
7
|
+
import { Log } from "@opencode-ai/core/util/log"
|
|
8
|
+
import { Npm } from "@opencode-ai/core/npm"
|
|
9
|
+
import { Hash } from "@opencode-ai/core/util/hash"
|
|
10
|
+
import { Plugin } from "../plugin"
|
|
11
|
+
import { serviceUse } from "@opencode-ai/core/effect/service-use"
|
|
12
|
+
import { type LanguageModelV3 } from "@ai-sdk/provider"
|
|
13
|
+
import { ModelsDev } from "@opencode-ai/core/models-dev"
|
|
14
|
+
import { Auth } from "../auth"
|
|
15
|
+
import { Env } from "../env"
|
|
16
|
+
import { InstallationVersion } from "@opencode-ai/core/installation/version"
|
|
17
|
+
import { iife } from "@/util/iife"
|
|
18
|
+
import { Global } from "@opencode-ai/core/global"
|
|
19
|
+
import path from "path"
|
|
20
|
+
import { pathToFileURL } from "url"
|
|
21
|
+
import { Effect, Layer, Context, Schema, Types } from "effect"
|
|
22
|
+
import { EffectBridge } from "@/effect/bridge"
|
|
23
|
+
import { InstanceState } from "@/effect/instance-state"
|
|
24
|
+
import { EffectPromise } from "@/effect/promise"
|
|
25
|
+
import { FSUtil } from "@opencode-ai/core/fs-util"
|
|
26
|
+
import { isRecord } from "@/util/record"
|
|
27
|
+
import { optionalOmitUndefined } from "@opencode-ai/core/schema"
|
|
28
|
+
import { ProviderTransform } from "./transform"
|
|
29
|
+
import { ProviderV2 } from "@opencode-ai/core/provider"
|
|
30
|
+
import { ModelV2 } from "@opencode-ai/core/model"
|
|
31
|
+
import { ModelStatus } from "./model-status"
|
|
32
|
+
import { RuntimeFlags } from "@/effect/runtime-flags"
|
|
33
|
+
import { ProviderError } from "./error"
|
|
34
|
+
|
|
35
|
+
const log = Log.create({ service: "provider" })
|
|
36
|
+
const OPENAI_HEADER_TIMEOUT_DEFAULT = 10_000
|
|
37
|
+
|
|
38
|
+
function wrapSSE(res: Response, ms: number, ctl: AbortController) {
|
|
39
|
+
if (typeof ms !== "number" || ms <= 0) return res
|
|
40
|
+
if (!res.body) return res
|
|
41
|
+
if (!res.headers.get("content-type")?.includes("text/event-stream")) return res
|
|
42
|
+
|
|
43
|
+
const reader = res.body.getReader()
|
|
44
|
+
const body = new ReadableStream<Uint8Array>({
|
|
45
|
+
async pull(ctrl) {
|
|
46
|
+
const part = await new Promise<Awaited<ReturnType<typeof reader.read>>>((resolve, reject) => {
|
|
47
|
+
const id = setTimeout(() => {
|
|
48
|
+
const err = new ProviderError.ResponseStreamError("SSE read timed out")
|
|
49
|
+
ctl.abort(err)
|
|
50
|
+
void reader.cancel(err)
|
|
51
|
+
reject(err)
|
|
52
|
+
}, ms)
|
|
53
|
+
|
|
54
|
+
reader.read().then(
|
|
55
|
+
(part) => {
|
|
56
|
+
clearTimeout(id)
|
|
57
|
+
resolve(part)
|
|
58
|
+
},
|
|
59
|
+
(err) => {
|
|
60
|
+
clearTimeout(id)
|
|
61
|
+
reject(err)
|
|
62
|
+
},
|
|
63
|
+
)
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
if (part.done) {
|
|
67
|
+
ctrl.close()
|
|
68
|
+
return
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
ctrl.enqueue(part.value)
|
|
72
|
+
},
|
|
73
|
+
async cancel(reason) {
|
|
74
|
+
ctl.abort(reason)
|
|
75
|
+
await reader.cancel(reason)
|
|
76
|
+
},
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
return new Response(body, {
|
|
80
|
+
headers: new Headers(res.headers),
|
|
81
|
+
status: res.status,
|
|
82
|
+
statusText: res.statusText,
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function timeoutController(ms: number) {
|
|
87
|
+
const ctl = new AbortController()
|
|
88
|
+
const id = setTimeout(() => ctl.abort(new ProviderError.HeaderTimeoutError(ms)), ms)
|
|
89
|
+
return {
|
|
90
|
+
signal: ctl.signal,
|
|
91
|
+
clear: () => clearTimeout(id),
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function googleVertexAnthropicBaseURL(project: string | undefined, location: string | undefined) {
|
|
96
|
+
if (!project) return
|
|
97
|
+
if (location !== "eu" && location !== "us") return
|
|
98
|
+
// Continental multi-regions require Regional Endpoint Platform domains.
|
|
99
|
+
return `https://aiplatform.${location}.rep.googleapis.com/v1/projects/${project}/locations/${location}/publishers/anthropic/models`
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
type BundledSDK = {
|
|
103
|
+
languageModel(modelId: string): LanguageModelV3
|
|
104
|
+
chat?: (modelId: string) => LanguageModelV3
|
|
105
|
+
responses?: (modelId: string) => LanguageModelV3
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const BUNDLED_PROVIDERS: Record<string, () => Promise<(opts: any) => BundledSDK>> = {
|
|
109
|
+
"@ai-sdk/amazon-bedrock": () => import("@ai-sdk/amazon-bedrock").then((m) => m.createAmazonBedrock),
|
|
110
|
+
"@ai-sdk/amazon-bedrock/mantle": () => import("@ai-sdk/amazon-bedrock/mantle").then((m) => m.createBedrockMantle),
|
|
111
|
+
"@ai-sdk/anthropic": () => import("@ai-sdk/anthropic").then((m) => m.createAnthropic),
|
|
112
|
+
"@ai-sdk/azure": () => import("@ai-sdk/azure").then((m) => m.createAzure),
|
|
113
|
+
"@ai-sdk/google": () => import("@ai-sdk/google").then((m) => m.createGoogleGenerativeAI),
|
|
114
|
+
"@ai-sdk/google-vertex": () => import("@ai-sdk/google-vertex").then((m) => m.createVertex),
|
|
115
|
+
"@ai-sdk/google-vertex/anthropic": () =>
|
|
116
|
+
import("@ai-sdk/google-vertex/anthropic").then((m) => m.createVertexAnthropic),
|
|
117
|
+
"@ai-sdk/openai": () => import("@ai-sdk/openai").then((m) => m.createOpenAI),
|
|
118
|
+
"@ai-sdk/openai-compatible": () => import("@ai-sdk/openai-compatible").then((m) => m.createOpenAICompatible),
|
|
119
|
+
"@openrouter/ai-sdk-provider": () => import("@openrouter/ai-sdk-provider").then((m) => m.createOpenRouter),
|
|
120
|
+
"@ai-sdk/xai": () => import("@ai-sdk/xai").then((m) => m.createXai),
|
|
121
|
+
"@ai-sdk/mistral": () => import("@ai-sdk/mistral").then((m) => m.createMistral),
|
|
122
|
+
"@ai-sdk/groq": () => import("@ai-sdk/groq").then((m) => m.createGroq),
|
|
123
|
+
"@ai-sdk/deepinfra": () => import("@ai-sdk/deepinfra").then((m) => m.createDeepInfra),
|
|
124
|
+
"@ai-sdk/cerebras": () => import("@ai-sdk/cerebras").then((m) => m.createCerebras),
|
|
125
|
+
"@ai-sdk/cohere": () => import("@ai-sdk/cohere").then((m) => m.createCohere),
|
|
126
|
+
"@ai-sdk/gateway": () => import("@ai-sdk/gateway").then((m) => m.createGateway),
|
|
127
|
+
"@ai-sdk/togetherai": () => import("@ai-sdk/togetherai").then((m) => m.createTogetherAI),
|
|
128
|
+
"@ai-sdk/perplexity": () => import("@ai-sdk/perplexity").then((m) => m.createPerplexity),
|
|
129
|
+
"@ai-sdk/vercel": () => import("@ai-sdk/vercel").then((m) => m.createVercel),
|
|
130
|
+
"@ai-sdk/alibaba": () => import("@ai-sdk/alibaba").then((m) => m.createAlibaba),
|
|
131
|
+
"gitlab-ai-provider": () => import("gitlab-ai-provider").then((m) => m.createGitLab),
|
|
132
|
+
"@ai-sdk/github-copilot": () =>
|
|
133
|
+
import("@opencode-ai/core/github-copilot/copilot-provider").then((m) => m.createOpenaiCompatible),
|
|
134
|
+
"venice-ai-sdk-provider": () => import("venice-ai-sdk-provider").then((m) => m.createVenice),
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
type CustomModelLoader = (sdk: any, modelID: string, options?: Record<string, any>, model?: Model) => Promise<any>
|
|
138
|
+
type CustomVarsLoader = (options: Record<string, any>) => Record<string, string>
|
|
139
|
+
type CustomDiscoverModels = () => Promise<Record<string, Model>>
|
|
140
|
+
type CustomLoader = (provider: Info) => Effect.Effect<{
|
|
141
|
+
autoload: boolean
|
|
142
|
+
getModel?: CustomModelLoader
|
|
143
|
+
vars?: CustomVarsLoader
|
|
144
|
+
options?: Record<string, any>
|
|
145
|
+
discoverModels?: CustomDiscoverModels
|
|
146
|
+
}>
|
|
147
|
+
|
|
148
|
+
type CustomDep = {
|
|
149
|
+
auth: (id: string) => Effect.Effect<Auth.Info | undefined>
|
|
150
|
+
config: () => Effect.Effect<ConfigV1.Info>
|
|
151
|
+
env: () => Effect.Effect<Record<string, string | undefined>>
|
|
152
|
+
get: (key: string) => Effect.Effect<string | undefined>
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function selectAzureLanguageModel(sdk: any, modelID: string, useChat: boolean) {
|
|
156
|
+
if (useChat && sdk.chat) return sdk.chat(modelID)
|
|
157
|
+
if (sdk.responses) return sdk.responses(modelID)
|
|
158
|
+
if (sdk.messages) return sdk.messages(modelID)
|
|
159
|
+
if (sdk.chat) return sdk.chat(modelID)
|
|
160
|
+
return sdk.languageModel(modelID)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function selectBedrockMantleLanguageModel(sdk: BundledSDK, modelID: string) {
|
|
164
|
+
if (modelID === "openai.gpt-oss-safeguard-20b" || modelID === "openai.gpt-oss-safeguard-120b")
|
|
165
|
+
return sdk.chat?.(modelID) ?? sdk.languageModel(modelID)
|
|
166
|
+
return sdk.responses?.(modelID) ?? sdk.languageModel(modelID)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function custom(dep: CustomDep): Record<string, CustomLoader> {
|
|
170
|
+
return {
|
|
171
|
+
anthropic: () =>
|
|
172
|
+
Effect.succeed({
|
|
173
|
+
autoload: false,
|
|
174
|
+
options: {
|
|
175
|
+
headers: {
|
|
176
|
+
"anthropic-beta": "interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14",
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
}),
|
|
180
|
+
opencode: Effect.fnUntraced(function* (input: Info) {
|
|
181
|
+
const env = yield* dep.env()
|
|
182
|
+
const hasKey = iife(() => {
|
|
183
|
+
if (input.env.some((item) => env[item])) return true
|
|
184
|
+
return false
|
|
185
|
+
})
|
|
186
|
+
const ok =
|
|
187
|
+
hasKey ||
|
|
188
|
+
Boolean(yield* dep.auth(input.id)) ||
|
|
189
|
+
Boolean((yield* dep.config()).provider?.["opencode"]?.options?.apiKey)
|
|
190
|
+
|
|
191
|
+
if (!ok) {
|
|
192
|
+
for (const [key, value] of Object.entries(input.models)) {
|
|
193
|
+
if (value.cost.input === 0) continue
|
|
194
|
+
delete input.models[key]
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return {
|
|
199
|
+
autoload: Object.keys(input.models).length > 0,
|
|
200
|
+
options: ok ? {} : { apiKey: "public" },
|
|
201
|
+
}
|
|
202
|
+
}),
|
|
203
|
+
openai: () =>
|
|
204
|
+
Effect.succeed({
|
|
205
|
+
autoload: false,
|
|
206
|
+
async getModel(sdk: any, modelID: string, _options?: Record<string, any>) {
|
|
207
|
+
return sdk.responses(modelID)
|
|
208
|
+
},
|
|
209
|
+
options: { headerTimeout: OPENAI_HEADER_TIMEOUT_DEFAULT },
|
|
210
|
+
}),
|
|
211
|
+
xai: () =>
|
|
212
|
+
Effect.succeed({
|
|
213
|
+
autoload: false,
|
|
214
|
+
async getModel(sdk: any, modelID: string, _options?: Record<string, any>) {
|
|
215
|
+
return sdk.responses(modelID)
|
|
216
|
+
},
|
|
217
|
+
options: {},
|
|
218
|
+
}),
|
|
219
|
+
"github-copilot": () =>
|
|
220
|
+
Effect.succeed({
|
|
221
|
+
autoload: false,
|
|
222
|
+
async getModel(sdk: any, modelID: string, _options?: Record<string, any>) {
|
|
223
|
+
if (sdk.responses === undefined && sdk.chat === undefined) return sdk.languageModel(modelID)
|
|
224
|
+
const match = /^gpt-(\d+)/.exec(modelID)
|
|
225
|
+
if (match && Number(match[1]) >= 5 && !modelID.startsWith("gpt-5-mini")) return sdk.responses(modelID)
|
|
226
|
+
return sdk.chat(modelID)
|
|
227
|
+
},
|
|
228
|
+
options: {},
|
|
229
|
+
}),
|
|
230
|
+
azure: Effect.fnUntraced(function* (provider: Info) {
|
|
231
|
+
const env = yield* dep.env()
|
|
232
|
+
const auth = yield* dep.auth(provider.id)
|
|
233
|
+
const resource = iife(() => {
|
|
234
|
+
return [
|
|
235
|
+
provider.options?.resourceName,
|
|
236
|
+
auth?.type === "api" ? auth.metadata?.resourceName : undefined,
|
|
237
|
+
env["AZURE_RESOURCE_NAME"],
|
|
238
|
+
].find((name) => typeof name === "string" && name.trim() !== "")
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
if (!resource && !provider.options?.baseURL) {
|
|
242
|
+
return {
|
|
243
|
+
autoload: false,
|
|
244
|
+
async getModel() {
|
|
245
|
+
throw new Error(
|
|
246
|
+
"AZURE_RESOURCE_NAME is missing, set it using env var or reconnecting the azure provider and setting it",
|
|
247
|
+
)
|
|
248
|
+
},
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return {
|
|
253
|
+
autoload: false,
|
|
254
|
+
async getModel(sdk: any, modelID: string, options?: Record<string, any>) {
|
|
255
|
+
return selectAzureLanguageModel(sdk, modelID, Boolean(options?.["useCompletionUrls"]))
|
|
256
|
+
},
|
|
257
|
+
options: {
|
|
258
|
+
resourceName: resource,
|
|
259
|
+
},
|
|
260
|
+
vars(_options): Record<string, string> {
|
|
261
|
+
if (resource) {
|
|
262
|
+
return {
|
|
263
|
+
AZURE_RESOURCE_NAME: resource,
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return {}
|
|
267
|
+
},
|
|
268
|
+
}
|
|
269
|
+
}),
|
|
270
|
+
"azure-cognitive-services": Effect.fnUntraced(function* () {
|
|
271
|
+
const resourceName = yield* dep.get("AZURE_COGNITIVE_SERVICES_RESOURCE_NAME")
|
|
272
|
+
return {
|
|
273
|
+
autoload: false,
|
|
274
|
+
async getModel(sdk: any, modelID: string, options?: Record<string, any>) {
|
|
275
|
+
return selectAzureLanguageModel(sdk, modelID, Boolean(options?.["useCompletionUrls"]))
|
|
276
|
+
},
|
|
277
|
+
options: {
|
|
278
|
+
baseURL: resourceName ? `https://${resourceName}.cognitiveservices.azure.com/openai` : undefined,
|
|
279
|
+
},
|
|
280
|
+
}
|
|
281
|
+
}),
|
|
282
|
+
"amazon-bedrock": Effect.fnUntraced(function* () {
|
|
283
|
+
const providerConfig = (yield* dep.config()).provider?.["amazon-bedrock"]
|
|
284
|
+
const auth = yield* dep.auth("amazon-bedrock")
|
|
285
|
+
const env = yield* dep.env()
|
|
286
|
+
|
|
287
|
+
// Region precedence: 1) config file, 2) env var, 3) default
|
|
288
|
+
const configRegion = providerConfig?.options?.region
|
|
289
|
+
const envRegion = env["AWS_REGION"]
|
|
290
|
+
const defaultRegion = configRegion ?? envRegion ?? "us-east-1"
|
|
291
|
+
|
|
292
|
+
// Profile: config file takes precedence over env var
|
|
293
|
+
const configProfile = providerConfig?.options?.profile
|
|
294
|
+
const envProfile = env["AWS_PROFILE"]
|
|
295
|
+
const profile = configProfile ?? envProfile
|
|
296
|
+
|
|
297
|
+
const awsAccessKeyId = env["AWS_ACCESS_KEY_ID"]
|
|
298
|
+
const configApiKey = providerConfig?.options?.apiKey
|
|
299
|
+
|
|
300
|
+
// TODO: Using process.env directly because Env.set only updates a process.env shallow copy,
|
|
301
|
+
// until the scope of the Env API is clarified (test only or runtime?)
|
|
302
|
+
const awsBearerToken = iife(() => {
|
|
303
|
+
const envToken = process.env.AWS_BEARER_TOKEN_BEDROCK
|
|
304
|
+
if (envToken) return envToken
|
|
305
|
+
if (auth?.type === "api") {
|
|
306
|
+
process.env.AWS_BEARER_TOKEN_BEDROCK = auth.key
|
|
307
|
+
return auth.key
|
|
308
|
+
}
|
|
309
|
+
return undefined
|
|
310
|
+
})
|
|
311
|
+
|
|
312
|
+
const awsWebIdentityTokenFile = env["AWS_WEB_IDENTITY_TOKEN_FILE"]
|
|
313
|
+
|
|
314
|
+
const containerCreds = Boolean(
|
|
315
|
+
process.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI || process.env.AWS_CONTAINER_CREDENTIALS_FULL_URI,
|
|
316
|
+
)
|
|
317
|
+
|
|
318
|
+
if (
|
|
319
|
+
!profile &&
|
|
320
|
+
!awsAccessKeyId &&
|
|
321
|
+
!awsBearerToken &&
|
|
322
|
+
!configApiKey &&
|
|
323
|
+
!awsWebIdentityTokenFile &&
|
|
324
|
+
!containerCreds
|
|
325
|
+
)
|
|
326
|
+
return { autoload: false }
|
|
327
|
+
|
|
328
|
+
const { fromNodeProviderChain } = yield* Effect.promise(() => import("@aws-sdk/credential-providers"))
|
|
329
|
+
|
|
330
|
+
const providerOptions: Record<string, any> = {
|
|
331
|
+
region: defaultRegion,
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// Only use credential chain if no bearer token exists
|
|
335
|
+
// Bearer token takes precedence over credential chain (profiles, access keys, IAM roles, web identity tokens)
|
|
336
|
+
if (!awsBearerToken && !configApiKey) {
|
|
337
|
+
// Build credential provider options (only pass profile if specified)
|
|
338
|
+
const credentialProviderOptions = profile ? { profile } : {}
|
|
339
|
+
|
|
340
|
+
providerOptions.credentialProvider = fromNodeProviderChain(credentialProviderOptions)
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// Add custom endpoint if specified (endpoint takes precedence over baseURL)
|
|
344
|
+
const endpoint = providerConfig?.options?.endpoint ?? providerConfig?.options?.baseURL
|
|
345
|
+
if (endpoint) {
|
|
346
|
+
providerOptions.baseURL = endpoint
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
return {
|
|
350
|
+
autoload: true,
|
|
351
|
+
options: providerOptions,
|
|
352
|
+
vars(options: Record<string, any>) {
|
|
353
|
+
return { AWS_REGION: options.region ?? defaultRegion }
|
|
354
|
+
},
|
|
355
|
+
async getModel(sdk: any, modelID: string, options?: Record<string, any>, model?: Model) {
|
|
356
|
+
if (model?.api.npm === "@ai-sdk/amazon-bedrock/mantle") return selectBedrockMantleLanguageModel(sdk, modelID)
|
|
357
|
+
|
|
358
|
+
// Skip region prefixing if model already has a cross-region inference profile prefix
|
|
359
|
+
// Models from models.dev may already include prefixes like us., eu., global., etc.
|
|
360
|
+
const crossRegionPrefixes = ["global.", "us.", "eu.", "jp.", "apac.", "au."]
|
|
361
|
+
if (crossRegionPrefixes.some((prefix) => modelID.startsWith(prefix))) {
|
|
362
|
+
return sdk.languageModel(modelID)
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// Region resolution precedence (highest to lowest):
|
|
366
|
+
// 1. options.region from opencode.json provider config
|
|
367
|
+
// 2. defaultRegion from AWS_REGION environment variable
|
|
368
|
+
// 3. Default "us-east-1" (baked into defaultRegion)
|
|
369
|
+
const region = options?.region ?? defaultRegion
|
|
370
|
+
|
|
371
|
+
let regionPrefix = region.split("-")[0]
|
|
372
|
+
|
|
373
|
+
switch (regionPrefix) {
|
|
374
|
+
case "us": {
|
|
375
|
+
const modelRequiresPrefix = [
|
|
376
|
+
"nova-micro",
|
|
377
|
+
"nova-lite",
|
|
378
|
+
"nova-pro",
|
|
379
|
+
"nova-premier",
|
|
380
|
+
"nova-2",
|
|
381
|
+
"claude",
|
|
382
|
+
"deepseek",
|
|
383
|
+
].some((m) => modelID.includes(m))
|
|
384
|
+
const isGovCloud = region.startsWith("us-gov")
|
|
385
|
+
if (modelRequiresPrefix && !isGovCloud) {
|
|
386
|
+
modelID = `${regionPrefix}.${modelID}`
|
|
387
|
+
}
|
|
388
|
+
break
|
|
389
|
+
}
|
|
390
|
+
case "eu": {
|
|
391
|
+
const regionRequiresPrefix = [
|
|
392
|
+
"eu-west-1",
|
|
393
|
+
"eu-west-2",
|
|
394
|
+
"eu-west-3",
|
|
395
|
+
"eu-north-1",
|
|
396
|
+
"eu-central-1",
|
|
397
|
+
"eu-south-1",
|
|
398
|
+
"eu-south-2",
|
|
399
|
+
].some((r) => region.includes(r))
|
|
400
|
+
const modelRequiresPrefix = ["claude", "nova-lite", "nova-micro", "llama3", "pixtral"].some((m) =>
|
|
401
|
+
modelID.includes(m),
|
|
402
|
+
)
|
|
403
|
+
if (regionRequiresPrefix && modelRequiresPrefix) {
|
|
404
|
+
modelID = `${regionPrefix}.${modelID}`
|
|
405
|
+
}
|
|
406
|
+
break
|
|
407
|
+
}
|
|
408
|
+
case "ap": {
|
|
409
|
+
const isAustraliaRegion = ["ap-southeast-2", "ap-southeast-4"].includes(region)
|
|
410
|
+
const isTokyoRegion = region === "ap-northeast-1"
|
|
411
|
+
if (
|
|
412
|
+
isAustraliaRegion &&
|
|
413
|
+
["anthropic.claude-sonnet-4-5", "anthropic.claude-haiku"].some((m) => modelID.includes(m))
|
|
414
|
+
) {
|
|
415
|
+
regionPrefix = "au"
|
|
416
|
+
modelID = `${regionPrefix}.${modelID}`
|
|
417
|
+
} else if (isTokyoRegion) {
|
|
418
|
+
// Tokyo region uses jp. prefix for cross-region inference
|
|
419
|
+
const modelRequiresPrefix = ["claude", "nova-lite", "nova-micro", "nova-pro"].some((m) =>
|
|
420
|
+
modelID.includes(m),
|
|
421
|
+
)
|
|
422
|
+
if (modelRequiresPrefix) {
|
|
423
|
+
regionPrefix = "jp"
|
|
424
|
+
modelID = `${regionPrefix}.${modelID}`
|
|
425
|
+
}
|
|
426
|
+
} else {
|
|
427
|
+
// Other APAC regions use apac. prefix
|
|
428
|
+
const modelRequiresPrefix = ["claude", "nova-lite", "nova-micro", "nova-pro"].some((m) =>
|
|
429
|
+
modelID.includes(m),
|
|
430
|
+
)
|
|
431
|
+
if (modelRequiresPrefix) {
|
|
432
|
+
regionPrefix = "apac"
|
|
433
|
+
modelID = `${regionPrefix}.${modelID}`
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
break
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
return sdk.languageModel(modelID)
|
|
441
|
+
},
|
|
442
|
+
}
|
|
443
|
+
}),
|
|
444
|
+
llmgateway: () =>
|
|
445
|
+
Effect.succeed({
|
|
446
|
+
autoload: false,
|
|
447
|
+
options: {
|
|
448
|
+
headers: {
|
|
449
|
+
"HTTP-Referer": "https://opencode.ai/",
|
|
450
|
+
"X-Title": "opencode",
|
|
451
|
+
"X-Source": "opencode",
|
|
452
|
+
},
|
|
453
|
+
},
|
|
454
|
+
}),
|
|
455
|
+
openrouter: () =>
|
|
456
|
+
Effect.succeed({
|
|
457
|
+
autoload: false,
|
|
458
|
+
options: {
|
|
459
|
+
headers: {
|
|
460
|
+
"HTTP-Referer": "https://opencode.ai/",
|
|
461
|
+
"X-Title": "opencode",
|
|
462
|
+
},
|
|
463
|
+
},
|
|
464
|
+
}),
|
|
465
|
+
nvidia: (provider) =>
|
|
466
|
+
Effect.succeed({
|
|
467
|
+
autoload: provider.source === "config",
|
|
468
|
+
options: {
|
|
469
|
+
headers: {
|
|
470
|
+
"HTTP-Referer": "https://opencode.ai/",
|
|
471
|
+
"X-Title": "opencode",
|
|
472
|
+
"X-BILLING-INVOKE-ORIGIN": "OpenCode",
|
|
473
|
+
},
|
|
474
|
+
},
|
|
475
|
+
}),
|
|
476
|
+
vercel: () =>
|
|
477
|
+
Effect.succeed({
|
|
478
|
+
autoload: false,
|
|
479
|
+
options: {
|
|
480
|
+
headers: {
|
|
481
|
+
"http-referer": "https://opencode.ai/",
|
|
482
|
+
"x-title": "opencode",
|
|
483
|
+
},
|
|
484
|
+
},
|
|
485
|
+
}),
|
|
486
|
+
"google-vertex": Effect.fnUntraced(function* (provider: Info) {
|
|
487
|
+
const env = yield* dep.env()
|
|
488
|
+
// models.dev advertises GOOGLE_VERTEX_PROJECT for Vertex; keep the wider
|
|
489
|
+
// Google Cloud project env names as fallbacks for existing ADC setups.
|
|
490
|
+
const project =
|
|
491
|
+
provider.options?.project ??
|
|
492
|
+
env["GOOGLE_VERTEX_PROJECT"] ??
|
|
493
|
+
env["GOOGLE_CLOUD_PROJECT"] ??
|
|
494
|
+
env["GCP_PROJECT"] ??
|
|
495
|
+
env["GCLOUD_PROJECT"]
|
|
496
|
+
|
|
497
|
+
const location = String(
|
|
498
|
+
provider.options?.location ??
|
|
499
|
+
env["GOOGLE_VERTEX_LOCATION"] ??
|
|
500
|
+
env["GOOGLE_CLOUD_LOCATION"] ??
|
|
501
|
+
env["VERTEX_LOCATION"] ??
|
|
502
|
+
"us-central1",
|
|
503
|
+
)
|
|
504
|
+
|
|
505
|
+
const autoload = Boolean(project)
|
|
506
|
+
if (!autoload) return { autoload: false }
|
|
507
|
+
return {
|
|
508
|
+
autoload: true,
|
|
509
|
+
vars(_options: Record<string, any>) {
|
|
510
|
+
const endpoint = location === "global" ? "aiplatform.googleapis.com" : `${location}-aiplatform.googleapis.com`
|
|
511
|
+
return {
|
|
512
|
+
...(project && { GOOGLE_VERTEX_PROJECT: project }),
|
|
513
|
+
GOOGLE_VERTEX_LOCATION: location,
|
|
514
|
+
GOOGLE_VERTEX_ENDPOINT: endpoint,
|
|
515
|
+
}
|
|
516
|
+
},
|
|
517
|
+
options: {
|
|
518
|
+
project,
|
|
519
|
+
location,
|
|
520
|
+
fetch: async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
521
|
+
const { GoogleAuth } = await import("google-auth-library")
|
|
522
|
+
const auth = new GoogleAuth({ scopes: ["https://www.googleapis.com/auth/cloud-platform"] })
|
|
523
|
+
const client = await auth.getClient()
|
|
524
|
+
const token = await client.getAccessToken()
|
|
525
|
+
|
|
526
|
+
const headers = new Headers(init?.headers)
|
|
527
|
+
headers.set("Authorization", `Bearer ${token.token}`)
|
|
528
|
+
|
|
529
|
+
return fetch(input, { ...init, headers })
|
|
530
|
+
},
|
|
531
|
+
},
|
|
532
|
+
async getModel(sdk: any, modelID: string) {
|
|
533
|
+
const id = String(modelID).trim()
|
|
534
|
+
return sdk.languageModel(id)
|
|
535
|
+
},
|
|
536
|
+
}
|
|
537
|
+
}),
|
|
538
|
+
"google-vertex-anthropic": Effect.fnUntraced(function* () {
|
|
539
|
+
const env = yield* dep.env()
|
|
540
|
+
const project = env["GOOGLE_CLOUD_PROJECT"] ?? env["GCP_PROJECT"] ?? env["GCLOUD_PROJECT"]
|
|
541
|
+
const location = env["GOOGLE_CLOUD_LOCATION"] ?? env["VERTEX_LOCATION"] ?? "global"
|
|
542
|
+
const autoload = Boolean(project)
|
|
543
|
+
if (!autoload) return { autoload: false }
|
|
544
|
+
const baseURL = googleVertexAnthropicBaseURL(project, location)
|
|
545
|
+
return {
|
|
546
|
+
autoload: true,
|
|
547
|
+
options: {
|
|
548
|
+
project,
|
|
549
|
+
location,
|
|
550
|
+
...(baseURL && { baseURL }),
|
|
551
|
+
},
|
|
552
|
+
async getModel(sdk: any, modelID) {
|
|
553
|
+
const id = String(modelID).trim()
|
|
554
|
+
return sdk.languageModel(id)
|
|
555
|
+
},
|
|
556
|
+
}
|
|
557
|
+
}),
|
|
558
|
+
"sap-ai-core": Effect.fnUntraced(function* () {
|
|
559
|
+
const auth = yield* dep.auth("sap-ai-core")
|
|
560
|
+
// TODO: Using process.env directly because Env.set only updates a shallow copy (not process.env),
|
|
561
|
+
// until the scope of the Env API is clarified (test only or runtime?)
|
|
562
|
+
const envServiceKey = iife(() => {
|
|
563
|
+
const envAICoreServiceKey = process.env.AICORE_SERVICE_KEY
|
|
564
|
+
if (envAICoreServiceKey) return envAICoreServiceKey
|
|
565
|
+
if (auth?.type === "api") {
|
|
566
|
+
process.env.AICORE_SERVICE_KEY = auth.key
|
|
567
|
+
return auth.key
|
|
568
|
+
}
|
|
569
|
+
return undefined
|
|
570
|
+
})
|
|
571
|
+
const deploymentId = process.env.AICORE_DEPLOYMENT_ID
|
|
572
|
+
const resourceGroup = process.env.AICORE_RESOURCE_GROUP
|
|
573
|
+
|
|
574
|
+
return {
|
|
575
|
+
autoload: !!envServiceKey,
|
|
576
|
+
options: envServiceKey ? { deploymentId, resourceGroup } : {},
|
|
577
|
+
async getModel(sdk: any, modelID: string) {
|
|
578
|
+
return sdk(modelID)
|
|
579
|
+
},
|
|
580
|
+
}
|
|
581
|
+
}),
|
|
582
|
+
zenmux: () =>
|
|
583
|
+
Effect.succeed({
|
|
584
|
+
autoload: false,
|
|
585
|
+
options: {
|
|
586
|
+
headers: {
|
|
587
|
+
"HTTP-Referer": "https://opencode.ai/",
|
|
588
|
+
"X-Title": "opencode",
|
|
589
|
+
},
|
|
590
|
+
},
|
|
591
|
+
}),
|
|
592
|
+
gitlab: Effect.fnUntraced(function* (input: Info) {
|
|
593
|
+
const {
|
|
594
|
+
VERSION: GITLAB_PROVIDER_VERSION,
|
|
595
|
+
isWorkflowModel,
|
|
596
|
+
discoverWorkflowModels,
|
|
597
|
+
} = yield* Effect.promise(() => import("gitlab-ai-provider"))
|
|
598
|
+
|
|
599
|
+
const instanceUrl = (yield* dep.get("GITLAB_INSTANCE_URL")) || "https://gitlab.com"
|
|
600
|
+
|
|
601
|
+
const auth = yield* dep.auth(input.id)
|
|
602
|
+
const apiKey = auth?.type === "oauth" ? auth.access : auth?.type === "api" ? auth.key : undefined
|
|
603
|
+
const token = apiKey ?? (yield* dep.get("GITLAB_TOKEN"))
|
|
604
|
+
|
|
605
|
+
const providerConfig = (yield* dep.config()).provider?.["gitlab"]
|
|
606
|
+
const directory = yield* InstanceState.directory
|
|
607
|
+
|
|
608
|
+
const aiGatewayHeaders = {
|
|
609
|
+
"User-Agent": `opencode/${InstallationVersion} gitlab-ai-provider/${GITLAB_PROVIDER_VERSION} (${os.platform()} ${os.release()}; ${os.arch()})`,
|
|
610
|
+
"anthropic-beta": "context-1m-2025-08-07",
|
|
611
|
+
...providerConfig?.options?.aiGatewayHeaders,
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
const featureFlags = {
|
|
615
|
+
duo_agent_platform_agentic_chat: true,
|
|
616
|
+
duo_agent_platform: true,
|
|
617
|
+
...providerConfig?.options?.featureFlags,
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
return {
|
|
621
|
+
autoload: !!token,
|
|
622
|
+
options: {
|
|
623
|
+
instanceUrl,
|
|
624
|
+
apiKey: token,
|
|
625
|
+
aiGatewayHeaders,
|
|
626
|
+
featureFlags,
|
|
627
|
+
},
|
|
628
|
+
async getModel(sdk: any, modelID: string, options?: Record<string, any>) {
|
|
629
|
+
if (modelID.startsWith("duo-workflow-")) {
|
|
630
|
+
const workflowRef = typeof options?.workflowRef === "string" ? options.workflowRef : undefined
|
|
631
|
+
// Use the static mapping if it exists, otherwise use duo-workflow with selectedModelRef
|
|
632
|
+
const sdkModelID = isWorkflowModel(modelID) ? modelID : "duo-workflow"
|
|
633
|
+
const workflowDefinition =
|
|
634
|
+
typeof options?.workflowDefinition === "string" ? options.workflowDefinition : undefined
|
|
635
|
+
const model = sdk.workflowChat(sdkModelID, {
|
|
636
|
+
featureFlags,
|
|
637
|
+
workflowDefinition,
|
|
638
|
+
})
|
|
639
|
+
if (workflowRef) {
|
|
640
|
+
model.selectedModelRef = workflowRef
|
|
641
|
+
}
|
|
642
|
+
return model
|
|
643
|
+
}
|
|
644
|
+
return sdk.agenticChat(modelID, {
|
|
645
|
+
aiGatewayHeaders,
|
|
646
|
+
featureFlags,
|
|
647
|
+
})
|
|
648
|
+
},
|
|
649
|
+
async discoverModels(): Promise<Record<string, Model>> {
|
|
650
|
+
if (!apiKey) {
|
|
651
|
+
log.info("gitlab model discovery skipped: no apiKey")
|
|
652
|
+
return {}
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
try {
|
|
656
|
+
const token = apiKey
|
|
657
|
+
const getHeaders = (): Record<string, string> =>
|
|
658
|
+
auth?.type === "api" ? { "PRIVATE-TOKEN": token } : { Authorization: `Bearer ${token}` }
|
|
659
|
+
|
|
660
|
+
log.info("gitlab model discovery starting", { instanceUrl })
|
|
661
|
+
const result = await discoverWorkflowModels({ instanceUrl, getHeaders }, { workingDirectory: directory })
|
|
662
|
+
|
|
663
|
+
if (!result.models.length) {
|
|
664
|
+
log.info("gitlab model discovery skipped: no models found", {
|
|
665
|
+
project: result.project
|
|
666
|
+
? {
|
|
667
|
+
id: result.project.id,
|
|
668
|
+
path: result.project.pathWithNamespace,
|
|
669
|
+
}
|
|
670
|
+
: null,
|
|
671
|
+
})
|
|
672
|
+
return {}
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
const models: Record<string, Model> = {}
|
|
676
|
+
for (const m of result.models) {
|
|
677
|
+
if (!input.models[m.id]) {
|
|
678
|
+
models[m.id] = {
|
|
679
|
+
id: ModelV2.ID.make(m.id),
|
|
680
|
+
providerID: ProviderV2.ID.make("gitlab"),
|
|
681
|
+
name: `Agent Platform (${m.name})`,
|
|
682
|
+
family: "",
|
|
683
|
+
api: {
|
|
684
|
+
id: m.id,
|
|
685
|
+
url: instanceUrl,
|
|
686
|
+
npm: "gitlab-ai-provider",
|
|
687
|
+
},
|
|
688
|
+
status: "active",
|
|
689
|
+
headers: {},
|
|
690
|
+
options: { workflowRef: m.ref },
|
|
691
|
+
cost: { input: 0, output: 0, cache: { read: 0, write: 0 } },
|
|
692
|
+
limit: { context: m.context, output: m.output },
|
|
693
|
+
capabilities: {
|
|
694
|
+
temperature: false,
|
|
695
|
+
reasoning: true,
|
|
696
|
+
attachment: true,
|
|
697
|
+
toolcall: true,
|
|
698
|
+
input: {
|
|
699
|
+
text: true,
|
|
700
|
+
audio: false,
|
|
701
|
+
image: true,
|
|
702
|
+
video: false,
|
|
703
|
+
pdf: true,
|
|
704
|
+
},
|
|
705
|
+
output: {
|
|
706
|
+
text: true,
|
|
707
|
+
audio: false,
|
|
708
|
+
image: false,
|
|
709
|
+
video: false,
|
|
710
|
+
pdf: false,
|
|
711
|
+
},
|
|
712
|
+
interleaved: false,
|
|
713
|
+
},
|
|
714
|
+
release_date: "",
|
|
715
|
+
variants: {},
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
log.info("gitlab model discovery complete", {
|
|
721
|
+
count: Object.keys(models).length,
|
|
722
|
+
models: Object.keys(models),
|
|
723
|
+
})
|
|
724
|
+
return models
|
|
725
|
+
} catch (e) {
|
|
726
|
+
log.warn("gitlab model discovery failed", { error: e })
|
|
727
|
+
return {}
|
|
728
|
+
}
|
|
729
|
+
},
|
|
730
|
+
}
|
|
731
|
+
}),
|
|
732
|
+
"cloudflare-workers-ai": Effect.fnUntraced(function* (input: Info) {
|
|
733
|
+
// When baseURL is already configured (e.g. corporate config routing through a proxy/gateway),
|
|
734
|
+
// skip the account ID check because the URL is already fully specified.
|
|
735
|
+
if (input.options?.baseURL) return { autoload: false }
|
|
736
|
+
|
|
737
|
+
const auth = yield* dep.auth(input.id)
|
|
738
|
+
const env = yield* dep.env()
|
|
739
|
+
const accountId = env["CLOUDFLARE_ACCOUNT_ID"] || (auth?.type === "api" ? auth.metadata?.accountId : undefined)
|
|
740
|
+
if (!accountId)
|
|
741
|
+
return {
|
|
742
|
+
autoload: false,
|
|
743
|
+
async getModel() {
|
|
744
|
+
throw new Error(
|
|
745
|
+
"CLOUDFLARE_ACCOUNT_ID is missing. Set it with: export CLOUDFLARE_ACCOUNT_ID=<your-account-id>",
|
|
746
|
+
)
|
|
747
|
+
},
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
const apiKey = env["CLOUDFLARE_API_KEY"] || (auth?.type === "api" ? auth.key : undefined)
|
|
751
|
+
|
|
752
|
+
return {
|
|
753
|
+
autoload: !!apiKey,
|
|
754
|
+
options: {
|
|
755
|
+
apiKey,
|
|
756
|
+
headers: {
|
|
757
|
+
"User-Agent": `opencode/${InstallationVersion} cloudflare-workers-ai (${os.platform()} ${os.release()}; ${os.arch()})`,
|
|
758
|
+
},
|
|
759
|
+
},
|
|
760
|
+
async getModel(sdk: any, modelID: string) {
|
|
761
|
+
return sdk.languageModel(modelID)
|
|
762
|
+
},
|
|
763
|
+
vars(_options) {
|
|
764
|
+
return {
|
|
765
|
+
CLOUDFLARE_ACCOUNT_ID: accountId,
|
|
766
|
+
}
|
|
767
|
+
},
|
|
768
|
+
}
|
|
769
|
+
}),
|
|
770
|
+
"cloudflare-ai-gateway": Effect.fnUntraced(function* (input: Info) {
|
|
771
|
+
// When baseURL is already configured (e.g. corporate config), skip the ID checks.
|
|
772
|
+
if (input.options?.baseURL) return { autoload: false }
|
|
773
|
+
|
|
774
|
+
const auth = yield* dep.auth(input.id)
|
|
775
|
+
const env = yield* dep.env()
|
|
776
|
+
const accountId = env["CLOUDFLARE_ACCOUNT_ID"] || (auth?.type === "api" ? auth.metadata?.accountId : undefined)
|
|
777
|
+
// The Cloudflare auth prompt stores this value as gatewayId metadata.
|
|
778
|
+
const gateway = env["CLOUDFLARE_GATEWAY_ID"] || (auth?.type === "api" ? auth.metadata?.gatewayId : undefined)
|
|
779
|
+
|
|
780
|
+
if (!accountId || !gateway) {
|
|
781
|
+
const missing = [
|
|
782
|
+
!accountId ? "CLOUDFLARE_ACCOUNT_ID" : undefined,
|
|
783
|
+
!gateway ? "CLOUDFLARE_GATEWAY_ID" : undefined,
|
|
784
|
+
].filter((x): x is string => Boolean(x))
|
|
785
|
+
return {
|
|
786
|
+
autoload: false,
|
|
787
|
+
async getModel() {
|
|
788
|
+
throw new Error(
|
|
789
|
+
`${missing.join(" and ")} missing. Set with: ${missing.map((x) => `export ${x}=<value>`).join(" && ")}`,
|
|
790
|
+
)
|
|
791
|
+
},
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
// Get API token from env or auth - required for authenticated gateways
|
|
796
|
+
const apiToken =
|
|
797
|
+
env["CLOUDFLARE_API_TOKEN"] || env["CF_AIG_TOKEN"] || (auth?.type === "api" ? auth.key : undefined)
|
|
798
|
+
|
|
799
|
+
if (!apiToken) {
|
|
800
|
+
throw new Error(
|
|
801
|
+
"CLOUDFLARE_API_TOKEN (or CF_AIG_TOKEN) is required for Cloudflare AI Gateway. " +
|
|
802
|
+
"Set it via environment variable or run `opencode auth cloudflare-ai-gateway`.",
|
|
803
|
+
)
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
// Use official ai-gateway-provider package (v2.x for AI SDK v5 compatibility)
|
|
807
|
+
const { createAiGateway } = yield* Effect.promise(() => import("ai-gateway-provider"))
|
|
808
|
+
const { createUnified } = yield* Effect.promise(() => import("ai-gateway-provider/providers/unified"))
|
|
809
|
+
|
|
810
|
+
const metadata = iife(() => {
|
|
811
|
+
if (input.options?.metadata) return input.options.metadata
|
|
812
|
+
try {
|
|
813
|
+
return JSON.parse(input.options?.headers?.["cf-aig-metadata"])
|
|
814
|
+
} catch {
|
|
815
|
+
return undefined
|
|
816
|
+
}
|
|
817
|
+
})
|
|
818
|
+
const opts = {
|
|
819
|
+
metadata,
|
|
820
|
+
cacheTtl: input.options?.cacheTtl,
|
|
821
|
+
cacheKey: input.options?.cacheKey,
|
|
822
|
+
skipCache: input.options?.skipCache,
|
|
823
|
+
collectLog: input.options?.collectLog,
|
|
824
|
+
headers: {
|
|
825
|
+
"User-Agent": `opencode/${InstallationVersion} cloudflare-ai-gateway (${os.platform()} ${os.release()}; ${os.arch()})`,
|
|
826
|
+
},
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
const aigateway = createAiGateway({
|
|
830
|
+
accountId,
|
|
831
|
+
gateway,
|
|
832
|
+
apiKey: apiToken,
|
|
833
|
+
...(Object.values(opts).some((v) => v !== undefined) ? { options: opts } : {}),
|
|
834
|
+
})
|
|
835
|
+
const unified = createUnified()
|
|
836
|
+
|
|
837
|
+
return {
|
|
838
|
+
autoload: true,
|
|
839
|
+
async getModel(_sdk: any, modelID: string, _options?: Record<string, any>) {
|
|
840
|
+
// Model IDs use Unified API format: provider/model (e.g., "anthropic/claude-sonnet-4-5")
|
|
841
|
+
return aigateway(unified(modelID))
|
|
842
|
+
},
|
|
843
|
+
options: {},
|
|
844
|
+
}
|
|
845
|
+
}),
|
|
846
|
+
cerebras: () =>
|
|
847
|
+
Effect.succeed({
|
|
848
|
+
autoload: false,
|
|
849
|
+
options: {
|
|
850
|
+
headers: {
|
|
851
|
+
"X-Cerebras-3rd-Party-Integration": "opencode",
|
|
852
|
+
},
|
|
853
|
+
},
|
|
854
|
+
}),
|
|
855
|
+
kilo: () =>
|
|
856
|
+
Effect.succeed({
|
|
857
|
+
autoload: false,
|
|
858
|
+
options: {
|
|
859
|
+
headers: {
|
|
860
|
+
"HTTP-Referer": "https://opencode.ai/",
|
|
861
|
+
"X-Title": "opencode",
|
|
862
|
+
},
|
|
863
|
+
},
|
|
864
|
+
}),
|
|
865
|
+
"snowflake-cortex": Effect.fnUntraced(function* (input: Info) {
|
|
866
|
+
const env = yield* dep.env()
|
|
867
|
+
const auth = yield* dep.auth(input.id)
|
|
868
|
+
|
|
869
|
+
const account =
|
|
870
|
+
env["SNOWFLAKE_ACCOUNT"] ??
|
|
871
|
+
(auth?.type === "api" ? auth.metadata?.account : undefined) ??
|
|
872
|
+
input.options?.account
|
|
873
|
+
|
|
874
|
+
const pat = env["SNOWFLAKE_CORTEX_PAT"] ?? (auth?.type === "api" ? auth.key : undefined) ?? input.options?.apiKey
|
|
875
|
+
|
|
876
|
+
if (!account || !pat) {
|
|
877
|
+
const missing = [!account && "SNOWFLAKE_ACCOUNT", !pat && "SNOWFLAKE_CORTEX_PAT"].filter(Boolean).join(", ")
|
|
878
|
+
return {
|
|
879
|
+
autoload: false,
|
|
880
|
+
async getModel() {
|
|
881
|
+
throw new Error(
|
|
882
|
+
`Snowflake Cortex: missing credentials (${missing}). Set via env var, opencode auth, or provider options.`,
|
|
883
|
+
)
|
|
884
|
+
},
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
const baseURL = `https://${account}.snowflakecomputing.com/api/v2/cortex/v1`
|
|
889
|
+
|
|
890
|
+
return {
|
|
891
|
+
autoload: input.source === "config",
|
|
892
|
+
options: {
|
|
893
|
+
baseURL,
|
|
894
|
+
apiKey: pat,
|
|
895
|
+
fetch: async (url: RequestInfo | URL, init?: RequestInit) => {
|
|
896
|
+
if (init?.body && typeof init.body === "string") {
|
|
897
|
+
try {
|
|
898
|
+
const body = JSON.parse(init.body)
|
|
899
|
+
if ("max_tokens" in body) {
|
|
900
|
+
body.max_completion_tokens = body.max_tokens
|
|
901
|
+
delete body.max_tokens
|
|
902
|
+
init = { ...init, body: JSON.stringify(body) }
|
|
903
|
+
}
|
|
904
|
+
} catch {}
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
const response = await fetch(url, init)
|
|
908
|
+
|
|
909
|
+
// Cortex returns 400 "conversation complete" as a normal stop condition
|
|
910
|
+
if (!response.ok && response.status === 400) {
|
|
911
|
+
try {
|
|
912
|
+
const errorData = await response.clone().json()
|
|
913
|
+
const errorMessage = String(errorData.message || errorData.error || "")
|
|
914
|
+
if (errorMessage.toLowerCase().includes("conversation complete")) {
|
|
915
|
+
return new Response(
|
|
916
|
+
JSON.stringify({
|
|
917
|
+
choices: [{ finish_reason: "stop", message: { content: "", role: "assistant" } }],
|
|
918
|
+
}),
|
|
919
|
+
{ status: 200, headers: new Headers({ "content-type": "application/json" }) },
|
|
920
|
+
)
|
|
921
|
+
}
|
|
922
|
+
} catch {}
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
// Cortex returns role:"" in streaming deltas; the AI SDK schema requires "assistant"
|
|
926
|
+
if (response.body && response.headers.get("content-type")?.includes("text/event-stream")) {
|
|
927
|
+
const reader = response.body.getReader()
|
|
928
|
+
const encoder = new TextEncoder()
|
|
929
|
+
const decoder = new TextDecoder()
|
|
930
|
+
const stream = new ReadableStream({
|
|
931
|
+
async pull(ctrl) {
|
|
932
|
+
const { done, value } = await reader.read()
|
|
933
|
+
if (done) {
|
|
934
|
+
ctrl.close()
|
|
935
|
+
return
|
|
936
|
+
}
|
|
937
|
+
const text = decoder.decode(value, { stream: true })
|
|
938
|
+
ctrl.enqueue(encoder.encode(text.replace(/"role"\s*:\s*""/g, '"role":"assistant"')))
|
|
939
|
+
},
|
|
940
|
+
cancel() {
|
|
941
|
+
reader.cancel()
|
|
942
|
+
},
|
|
943
|
+
})
|
|
944
|
+
return new Response(stream, { headers: response.headers, status: response.status })
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
return response
|
|
948
|
+
},
|
|
949
|
+
},
|
|
950
|
+
}
|
|
951
|
+
}),
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
const ProviderApiInfo = Schema.Struct({
|
|
956
|
+
id: Schema.String,
|
|
957
|
+
url: Schema.String,
|
|
958
|
+
npm: Schema.String,
|
|
959
|
+
})
|
|
960
|
+
|
|
961
|
+
const ProviderModalities = Schema.Struct({
|
|
962
|
+
text: Schema.Boolean,
|
|
963
|
+
audio: Schema.Boolean,
|
|
964
|
+
image: Schema.Boolean,
|
|
965
|
+
video: Schema.Boolean,
|
|
966
|
+
pdf: Schema.Boolean,
|
|
967
|
+
})
|
|
968
|
+
|
|
969
|
+
const ProviderInterleaved = Schema.Union([
|
|
970
|
+
Schema.Boolean,
|
|
971
|
+
Schema.Struct({
|
|
972
|
+
field: Schema.Literals(["reasoning_content", "reasoning_details"]),
|
|
973
|
+
}),
|
|
974
|
+
])
|
|
975
|
+
|
|
976
|
+
const ProviderCapabilities = Schema.Struct({
|
|
977
|
+
temperature: Schema.Boolean,
|
|
978
|
+
reasoning: Schema.Boolean,
|
|
979
|
+
attachment: Schema.Boolean,
|
|
980
|
+
toolcall: Schema.Boolean,
|
|
981
|
+
input: ProviderModalities,
|
|
982
|
+
output: ProviderModalities,
|
|
983
|
+
interleaved: ProviderInterleaved,
|
|
984
|
+
})
|
|
985
|
+
|
|
986
|
+
const ProviderCacheCost = Schema.Struct({
|
|
987
|
+
read: Schema.Finite,
|
|
988
|
+
write: Schema.Finite,
|
|
989
|
+
})
|
|
990
|
+
|
|
991
|
+
const ProviderCostTier = Schema.Struct({
|
|
992
|
+
input: Schema.Finite,
|
|
993
|
+
output: Schema.Finite,
|
|
994
|
+
cache: ProviderCacheCost,
|
|
995
|
+
tier: Schema.Struct({
|
|
996
|
+
type: Schema.Literal("context"),
|
|
997
|
+
size: Schema.Finite,
|
|
998
|
+
}),
|
|
999
|
+
})
|
|
1000
|
+
|
|
1001
|
+
const ProviderCost = Schema.Struct({
|
|
1002
|
+
input: Schema.Finite,
|
|
1003
|
+
output: Schema.Finite,
|
|
1004
|
+
cache: ProviderCacheCost,
|
|
1005
|
+
tiers: optionalOmitUndefined(Schema.Array(ProviderCostTier)),
|
|
1006
|
+
experimentalOver200K: optionalOmitUndefined(
|
|
1007
|
+
Schema.Struct({
|
|
1008
|
+
input: Schema.Finite,
|
|
1009
|
+
output: Schema.Finite,
|
|
1010
|
+
cache: ProviderCacheCost,
|
|
1011
|
+
}),
|
|
1012
|
+
),
|
|
1013
|
+
})
|
|
1014
|
+
|
|
1015
|
+
const ProviderLimit = Schema.Struct({
|
|
1016
|
+
context: Schema.Finite,
|
|
1017
|
+
input: optionalOmitUndefined(Schema.Finite),
|
|
1018
|
+
output: Schema.Finite,
|
|
1019
|
+
})
|
|
1020
|
+
|
|
1021
|
+
export const Model = Schema.Struct({
|
|
1022
|
+
id: ModelV2.ID,
|
|
1023
|
+
providerID: ProviderV2.ID,
|
|
1024
|
+
api: ProviderApiInfo,
|
|
1025
|
+
name: Schema.String,
|
|
1026
|
+
family: optionalOmitUndefined(Schema.String),
|
|
1027
|
+
capabilities: ProviderCapabilities,
|
|
1028
|
+
cost: ProviderCost,
|
|
1029
|
+
limit: ProviderLimit,
|
|
1030
|
+
status: ModelStatus,
|
|
1031
|
+
options: Schema.Record(Schema.String, Schema.Any),
|
|
1032
|
+
headers: Schema.Record(Schema.String, Schema.String),
|
|
1033
|
+
release_date: Schema.String,
|
|
1034
|
+
variants: optionalOmitUndefined(Schema.Record(Schema.String, Schema.Record(Schema.String, Schema.Any))),
|
|
1035
|
+
}).annotate({ identifier: "Model" })
|
|
1036
|
+
export type Model = Types.DeepMutable<Schema.Schema.Type<typeof Model>>
|
|
1037
|
+
|
|
1038
|
+
export const Info = Schema.Struct({
|
|
1039
|
+
id: ProviderV2.ID,
|
|
1040
|
+
name: Schema.String,
|
|
1041
|
+
source: Schema.Literals(["env", "config", "custom", "api"]),
|
|
1042
|
+
env: Schema.Array(Schema.String),
|
|
1043
|
+
key: optionalOmitUndefined(Schema.String),
|
|
1044
|
+
options: Schema.Record(Schema.String, Schema.Any),
|
|
1045
|
+
models: Schema.Record(Schema.String, Model),
|
|
1046
|
+
}).annotate({ identifier: "Provider" })
|
|
1047
|
+
export type Info = Types.DeepMutable<Schema.Schema.Type<typeof Info>>
|
|
1048
|
+
|
|
1049
|
+
const DefaultModelIDs = Schema.Record(Schema.String, Schema.String)
|
|
1050
|
+
|
|
1051
|
+
export const ListResult = Schema.Struct({
|
|
1052
|
+
all: Schema.Array(Info),
|
|
1053
|
+
default: DefaultModelIDs,
|
|
1054
|
+
connected: Schema.Array(Schema.String),
|
|
1055
|
+
})
|
|
1056
|
+
export type ListResult = Types.DeepMutable<Schema.Schema.Type<typeof ListResult>>
|
|
1057
|
+
|
|
1058
|
+
export const ConfigProvidersResult = Schema.Struct({
|
|
1059
|
+
providers: Schema.Array(Info),
|
|
1060
|
+
default: DefaultModelIDs,
|
|
1061
|
+
})
|
|
1062
|
+
export type ConfigProvidersResult = Types.DeepMutable<Schema.Schema.Type<typeof ConfigProvidersResult>>
|
|
1063
|
+
|
|
1064
|
+
export function toPublicInfo(provider: Info): Info {
|
|
1065
|
+
return JSON.parse(
|
|
1066
|
+
JSON.stringify(provider, (_, value) => {
|
|
1067
|
+
if (typeof value === "function" || typeof value === "symbol" || value === undefined) return undefined
|
|
1068
|
+
if (typeof value === "bigint") return value.toString()
|
|
1069
|
+
return value
|
|
1070
|
+
}),
|
|
1071
|
+
)
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
export function defaultModelIDs<T extends { models: Record<string, { id: string }> }>(providers: Record<string, T>) {
|
|
1075
|
+
return mapValues(providers, (item) => sort(Object.values(item.models))[0].id)
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
export class ModelNotFoundError extends Schema.TaggedErrorClass<ModelNotFoundError>()("ProviderModelNotFoundError", {
|
|
1079
|
+
providerID: ProviderV2.ID,
|
|
1080
|
+
modelID: ModelV2.ID,
|
|
1081
|
+
suggestions: Schema.optional(Schema.Array(Schema.String)),
|
|
1082
|
+
cause: Schema.optional(Schema.Defect),
|
|
1083
|
+
}) {
|
|
1084
|
+
static isInstance(input: unknown): input is ModelNotFoundError {
|
|
1085
|
+
return input instanceof ModelNotFoundError
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
export class InitError extends Schema.TaggedErrorClass<InitError>()("ProviderInitError", {
|
|
1090
|
+
providerID: ProviderV2.ID,
|
|
1091
|
+
cause: Schema.optional(Schema.Defect),
|
|
1092
|
+
}) {
|
|
1093
|
+
static isInstance(input: unknown): input is InitError {
|
|
1094
|
+
return input instanceof InitError
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
export class NoProvidersError extends Schema.TaggedErrorClass<NoProvidersError>()("ProviderNoProvidersError", {}) {
|
|
1099
|
+
static isInstance(input: unknown): input is NoProvidersError {
|
|
1100
|
+
return input instanceof NoProvidersError
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
export class NoModelsError extends Schema.TaggedErrorClass<NoModelsError>()("ProviderNoModelsError", {
|
|
1105
|
+
providerID: ProviderV2.ID,
|
|
1106
|
+
}) {
|
|
1107
|
+
static isInstance(input: unknown): input is NoModelsError {
|
|
1108
|
+
return input instanceof NoModelsError
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
export type DefaultModelError = ModelNotFoundError | NoProvidersError | NoModelsError
|
|
1113
|
+
export type Error = ModelNotFoundError | InitError | NoProvidersError | NoModelsError
|
|
1114
|
+
|
|
1115
|
+
export interface Interface {
|
|
1116
|
+
readonly list: () => Effect.Effect<Record<ProviderV2.ID, Info>>
|
|
1117
|
+
readonly getProvider: (providerID: ProviderV2.ID) => Effect.Effect<Info>
|
|
1118
|
+
readonly getModel: (providerID: ProviderV2.ID, modelID: ModelV2.ID) => Effect.Effect<Model, ModelNotFoundError>
|
|
1119
|
+
readonly getLanguage: (model: Model) => Effect.Effect<LanguageModelV3, ModelNotFoundError>
|
|
1120
|
+
readonly closest: (
|
|
1121
|
+
providerID: ProviderV2.ID,
|
|
1122
|
+
query: string[],
|
|
1123
|
+
) => Effect.Effect<{ providerID: ProviderV2.ID; modelID: string } | undefined>
|
|
1124
|
+
readonly getSmallModel: (providerID: ProviderV2.ID) => Effect.Effect<Model | undefined>
|
|
1125
|
+
readonly defaultModel: () => Effect.Effect<{ providerID: ProviderV2.ID; modelID: ModelV2.ID }, DefaultModelError>
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
interface State {
|
|
1129
|
+
models: Map<string, LanguageModelV3>
|
|
1130
|
+
providers: Record<ProviderV2.ID, Info>
|
|
1131
|
+
catalog: Record<ProviderV2.ID, Info>
|
|
1132
|
+
sdk: Map<string, BundledSDK>
|
|
1133
|
+
modelLoaders: Record<string, CustomModelLoader>
|
|
1134
|
+
varsLoaders: Record<string, CustomVarsLoader>
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
export class Service extends Context.Service<Service, Interface>()("@opencode/Provider") {}
|
|
1138
|
+
|
|
1139
|
+
export const use = serviceUse(Service)
|
|
1140
|
+
|
|
1141
|
+
function cost(c: ModelsDev.Model["cost"]): Model["cost"] {
|
|
1142
|
+
const result: Model["cost"] = {
|
|
1143
|
+
input: c?.input ?? 0,
|
|
1144
|
+
output: c?.output ?? 0,
|
|
1145
|
+
cache: {
|
|
1146
|
+
read: c?.cache_read ?? 0,
|
|
1147
|
+
write: c?.cache_write ?? 0,
|
|
1148
|
+
},
|
|
1149
|
+
}
|
|
1150
|
+
if (c?.tiers) {
|
|
1151
|
+
result.tiers = c.tiers.map((item) => ({
|
|
1152
|
+
input: item.input,
|
|
1153
|
+
output: item.output,
|
|
1154
|
+
cache: {
|
|
1155
|
+
read: item.cache_read ?? 0,
|
|
1156
|
+
write: item.cache_write ?? 0,
|
|
1157
|
+
},
|
|
1158
|
+
tier: item.tier,
|
|
1159
|
+
}))
|
|
1160
|
+
}
|
|
1161
|
+
if (c?.context_over_200k) {
|
|
1162
|
+
result.experimentalOver200K = {
|
|
1163
|
+
cache: {
|
|
1164
|
+
read: c.context_over_200k.cache_read ?? 0,
|
|
1165
|
+
write: c.context_over_200k.cache_write ?? 0,
|
|
1166
|
+
},
|
|
1167
|
+
input: c.context_over_200k.input,
|
|
1168
|
+
output: c.context_over_200k.output,
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
return result
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
function fromModelsDevModel(provider: ModelsDev.Provider, model: ModelsDev.Model): Model {
|
|
1175
|
+
const base: Model = {
|
|
1176
|
+
id: ModelV2.ID.make(model.id),
|
|
1177
|
+
providerID: ProviderV2.ID.make(provider.id),
|
|
1178
|
+
name: model.name,
|
|
1179
|
+
family: model.family,
|
|
1180
|
+
api: {
|
|
1181
|
+
id: model.id,
|
|
1182
|
+
url: model.provider?.api ?? provider.api ?? "",
|
|
1183
|
+
npm: model.provider?.npm ?? provider.npm ?? "@ai-sdk/openai-compatible",
|
|
1184
|
+
},
|
|
1185
|
+
status: model.status ?? "active",
|
|
1186
|
+
headers: {},
|
|
1187
|
+
options: {},
|
|
1188
|
+
cost: cost(model.cost),
|
|
1189
|
+
limit: {
|
|
1190
|
+
context: model.limit.context,
|
|
1191
|
+
input: model.limit.input,
|
|
1192
|
+
output: model.limit.output ?? 16384,
|
|
1193
|
+
},
|
|
1194
|
+
capabilities: {
|
|
1195
|
+
temperature: model.temperature ?? false,
|
|
1196
|
+
reasoning: model.reasoning ?? false,
|
|
1197
|
+
attachment: model.attachment ?? false,
|
|
1198
|
+
toolcall: model.tool_call ?? true,
|
|
1199
|
+
input: {
|
|
1200
|
+
text: model.modalities?.input?.includes("text") ?? false,
|
|
1201
|
+
audio: model.modalities?.input?.includes("audio") ?? false,
|
|
1202
|
+
image: model.modalities?.input?.includes("image") ?? false,
|
|
1203
|
+
video: model.modalities?.input?.includes("video") ?? false,
|
|
1204
|
+
pdf: model.modalities?.input?.includes("pdf") ?? false,
|
|
1205
|
+
},
|
|
1206
|
+
output: {
|
|
1207
|
+
text: model.modalities?.output?.includes("text") ?? false,
|
|
1208
|
+
audio: model.modalities?.output?.includes("audio") ?? false,
|
|
1209
|
+
image: model.modalities?.output?.includes("image") ?? false,
|
|
1210
|
+
video: model.modalities?.output?.includes("video") ?? false,
|
|
1211
|
+
pdf: model.modalities?.output?.includes("pdf") ?? false,
|
|
1212
|
+
},
|
|
1213
|
+
interleaved: model.interleaved ?? false,
|
|
1214
|
+
},
|
|
1215
|
+
release_date: model.release_date ?? "",
|
|
1216
|
+
variants: {},
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
return {
|
|
1220
|
+
...base,
|
|
1221
|
+
variants: mapValues(ProviderTransform.variants(base), (v) => v),
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
export function fromModelsDevProvider(provider: ModelsDev.Provider): Info {
|
|
1226
|
+
const models: Record<string, Model> = {}
|
|
1227
|
+
for (const [key, model] of Object.entries(provider.models)) {
|
|
1228
|
+
models[key] = fromModelsDevModel(provider, model)
|
|
1229
|
+
for (const [mode, opts] of Object.entries(model.experimental?.modes ?? {})) {
|
|
1230
|
+
const id = `${model.id}-${mode}`
|
|
1231
|
+
const base = fromModelsDevModel(provider, model)
|
|
1232
|
+
models[id] = {
|
|
1233
|
+
...base,
|
|
1234
|
+
id: ModelV2.ID.make(id),
|
|
1235
|
+
name: `${model.name} ${mode[0].toUpperCase()}${mode.slice(1)}`,
|
|
1236
|
+
cost: opts.cost ? mergeDeep(base.cost, cost(opts.cost)) : base.cost,
|
|
1237
|
+
options: opts.provider?.body
|
|
1238
|
+
? Object.fromEntries(
|
|
1239
|
+
Object.entries(opts.provider.body).map(([k, v]) => [
|
|
1240
|
+
k.replace(/_([a-z])/g, (_, c) => c.toUpperCase()),
|
|
1241
|
+
v,
|
|
1242
|
+
]),
|
|
1243
|
+
)
|
|
1244
|
+
: base.options,
|
|
1245
|
+
headers: opts.provider?.headers ?? base.headers,
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
return {
|
|
1250
|
+
id: ProviderV2.ID.make(provider.id),
|
|
1251
|
+
source: "custom",
|
|
1252
|
+
name: provider.name,
|
|
1253
|
+
env: [...(provider.env ?? [])],
|
|
1254
|
+
options: {},
|
|
1255
|
+
models,
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
function modelSuggestions(provider: Info | undefined, modelID: ModelV2.ID, enableExperimentalModels: boolean) {
|
|
1260
|
+
const available = provider
|
|
1261
|
+
? Object.keys(provider.models).filter((id) => {
|
|
1262
|
+
const model = provider.models[id]
|
|
1263
|
+
if (model.status === "deprecated") return false
|
|
1264
|
+
if (model.status === "alpha" && !enableExperimentalModels) return false
|
|
1265
|
+
return true
|
|
1266
|
+
})
|
|
1267
|
+
: []
|
|
1268
|
+
const fuzzy = fuzzysort.go(modelID, available, { limit: 3, threshold: -10000 }).map((m) => m.target)
|
|
1269
|
+
if (fuzzy.length) return fuzzy
|
|
1270
|
+
const query = modelID
|
|
1271
|
+
.toLowerCase()
|
|
1272
|
+
.split(/[^a-z0-9]+/)
|
|
1273
|
+
.filter((part) => part.length > 1)
|
|
1274
|
+
return sortBy(
|
|
1275
|
+
available
|
|
1276
|
+
.map((id) => ({
|
|
1277
|
+
id,
|
|
1278
|
+
score: query.filter((part) => id.toLowerCase().includes(part)).length,
|
|
1279
|
+
}))
|
|
1280
|
+
.filter((item) => item.score > 0),
|
|
1281
|
+
[(item) => item.score, "desc"],
|
|
1282
|
+
[(item) => item.id, "asc"],
|
|
1283
|
+
)
|
|
1284
|
+
.slice(0, 3)
|
|
1285
|
+
.map((item) => item.id)
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
export const layer = Layer.effect(
|
|
1289
|
+
Service,
|
|
1290
|
+
Effect.gen(function* () {
|
|
1291
|
+
const fs = yield* FSUtil.Service
|
|
1292
|
+
const config = yield* Config.Service
|
|
1293
|
+
const auth = yield* Auth.Service
|
|
1294
|
+
const env = yield* Env.Service
|
|
1295
|
+
const plugin = yield* Plugin.Service
|
|
1296
|
+
const modelsDevSvc = yield* ModelsDev.Service
|
|
1297
|
+
const runtimeFlags = yield* RuntimeFlags.Service
|
|
1298
|
+
|
|
1299
|
+
const state = yield* InstanceState.make<State>(() =>
|
|
1300
|
+
Effect.gen(function* () {
|
|
1301
|
+
using _ = log.time("state")
|
|
1302
|
+
const bridge = yield* EffectBridge.make()
|
|
1303
|
+
const cfg = yield* config.get()
|
|
1304
|
+
const modelsDev = yield* modelsDevSvc.get()
|
|
1305
|
+
const catalog = mapValues(modelsDev, fromModelsDevProvider)
|
|
1306
|
+
const database = mapValues(catalog, toPublicInfo)
|
|
1307
|
+
|
|
1308
|
+
const providers: Record<ProviderV2.ID, Info> = {} as Record<ProviderV2.ID, Info>
|
|
1309
|
+
const languages = new Map<string, LanguageModelV3>()
|
|
1310
|
+
const modelLoaders: {
|
|
1311
|
+
[providerID: string]: CustomModelLoader
|
|
1312
|
+
} = {}
|
|
1313
|
+
const varsLoaders: {
|
|
1314
|
+
[providerID: string]: CustomVarsLoader
|
|
1315
|
+
} = {}
|
|
1316
|
+
const sdk = new Map<string, BundledSDK>()
|
|
1317
|
+
const discoveryLoaders: {
|
|
1318
|
+
[providerID: string]: CustomDiscoverModels
|
|
1319
|
+
} = {}
|
|
1320
|
+
const dep = {
|
|
1321
|
+
auth: (id: string) => auth.get(id).pipe(Effect.orDie),
|
|
1322
|
+
config: () => config.get(),
|
|
1323
|
+
env: () => env.all(),
|
|
1324
|
+
get: (key: string) => env.get(key),
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
log.info("init")
|
|
1328
|
+
|
|
1329
|
+
function mergeProvider(providerID: ProviderV2.ID, provider: Partial<Info>) {
|
|
1330
|
+
const existing = providers[providerID]
|
|
1331
|
+
if (existing) {
|
|
1332
|
+
// @ts-expect-error
|
|
1333
|
+
providers[providerID] = mergeDeep(existing, provider)
|
|
1334
|
+
return
|
|
1335
|
+
}
|
|
1336
|
+
const match = database[providerID]
|
|
1337
|
+
if (!match) return
|
|
1338
|
+
// @ts-expect-error
|
|
1339
|
+
providers[providerID] = mergeDeep(match, provider)
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
// load plugins first so config() hook runs before reading cfg.provider
|
|
1343
|
+
const plugins = yield* plugin.list()
|
|
1344
|
+
|
|
1345
|
+
// now read config providers - includes any modifications from plugin config() hook
|
|
1346
|
+
const configProviders = Object.entries(cfg.provider ?? {})
|
|
1347
|
+
const disabled = new Set(cfg.disabled_providers ?? [])
|
|
1348
|
+
const enabled = cfg.enabled_providers ? new Set(cfg.enabled_providers) : null
|
|
1349
|
+
|
|
1350
|
+
function isProviderAllowed(providerID: ProviderV2.ID): boolean {
|
|
1351
|
+
if (enabled && !enabled.has(providerID)) return false
|
|
1352
|
+
if (disabled.has(providerID)) return false
|
|
1353
|
+
return true
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
for (const hook of plugins) {
|
|
1357
|
+
const p = hook.provider
|
|
1358
|
+
const models = p?.models
|
|
1359
|
+
if (!p || !models) continue
|
|
1360
|
+
|
|
1361
|
+
const providerID = ProviderV2.ID.make(p.id)
|
|
1362
|
+
if (disabled.has(providerID)) continue
|
|
1363
|
+
|
|
1364
|
+
let provider = database[providerID]
|
|
1365
|
+
if (!provider) {
|
|
1366
|
+
provider = toPublicInfo(
|
|
1367
|
+
fromModelsDevProvider({ id: p.id, name: p.name ?? p.id, env: [], models: {} }),
|
|
1368
|
+
)
|
|
1369
|
+
database[providerID] = provider
|
|
1370
|
+
}
|
|
1371
|
+
const pluginAuth = yield* auth.get(providerID).pipe(Effect.orDie)
|
|
1372
|
+
|
|
1373
|
+
const newModels = yield* Effect.promise(() =>
|
|
1374
|
+
models(toPublicInfo(provider), { auth: pluginAuth }),
|
|
1375
|
+
)
|
|
1376
|
+
for (const [id, model] of Object.entries(newModels)) {
|
|
1377
|
+
provider.models[id] = {
|
|
1378
|
+
...model,
|
|
1379
|
+
id: ModelV2.ID.make(id),
|
|
1380
|
+
providerID,
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
mergeProvider(providerID, {})
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
// extend database from config
|
|
1387
|
+
for (const [providerID, provider] of configProviders) {
|
|
1388
|
+
const existing = database[providerID]
|
|
1389
|
+
const parsed: Info = {
|
|
1390
|
+
id: ProviderV2.ID.make(providerID),
|
|
1391
|
+
name: provider.name ?? existing?.name ?? providerID,
|
|
1392
|
+
env: provider.env ?? existing?.env ?? [],
|
|
1393
|
+
options: mergeDeep(existing?.options ?? {}, provider.options ?? {}),
|
|
1394
|
+
source: "config",
|
|
1395
|
+
models: existing?.models ?? {},
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1398
|
+
for (const [modelID, model] of Object.entries(provider.models ?? {})) {
|
|
1399
|
+
const existingModel = parsed.models[model.id ?? modelID]
|
|
1400
|
+
const apiID = model.id ?? existingModel?.api.id ?? modelID
|
|
1401
|
+
const apiNpm =
|
|
1402
|
+
model.provider?.npm ??
|
|
1403
|
+
provider.npm ??
|
|
1404
|
+
existingModel?.api.npm ??
|
|
1405
|
+
modelsDev[providerID]?.npm ??
|
|
1406
|
+
"@ai-sdk/openai-compatible"
|
|
1407
|
+
const name = iife(() => {
|
|
1408
|
+
if (model.name) return model.name
|
|
1409
|
+
if (model.id && model.id !== modelID) return modelID
|
|
1410
|
+
return existingModel?.name ?? modelID
|
|
1411
|
+
})
|
|
1412
|
+
const parsedModel: Model = {
|
|
1413
|
+
id: ModelV2.ID.make(modelID),
|
|
1414
|
+
api: {
|
|
1415
|
+
id: apiID,
|
|
1416
|
+
npm: apiNpm,
|
|
1417
|
+
url: model.provider?.api ?? provider?.api ?? existingModel?.api.url ?? modelsDev[providerID]?.api ?? "",
|
|
1418
|
+
},
|
|
1419
|
+
status: model.status ?? existingModel?.status ?? "active",
|
|
1420
|
+
name,
|
|
1421
|
+
providerID: ProviderV2.ID.make(providerID),
|
|
1422
|
+
capabilities: {
|
|
1423
|
+
temperature: model.temperature ?? existingModel?.capabilities.temperature ?? false,
|
|
1424
|
+
reasoning: model.reasoning ?? existingModel?.capabilities.reasoning ?? false,
|
|
1425
|
+
attachment: model.attachment ?? existingModel?.capabilities.attachment ?? false,
|
|
1426
|
+
toolcall: model.tool_call ?? existingModel?.capabilities.toolcall ?? true,
|
|
1427
|
+
input: {
|
|
1428
|
+
text: model.modalities?.input?.includes("text") ?? existingModel?.capabilities.input.text ?? true,
|
|
1429
|
+
audio: model.modalities?.input?.includes("audio") ?? existingModel?.capabilities.input.audio ?? false,
|
|
1430
|
+
image: model.modalities?.input?.includes("image") ?? existingModel?.capabilities.input.image ?? false,
|
|
1431
|
+
video: model.modalities?.input?.includes("video") ?? existingModel?.capabilities.input.video ?? false,
|
|
1432
|
+
pdf: model.modalities?.input?.includes("pdf") ?? existingModel?.capabilities.input.pdf ?? false,
|
|
1433
|
+
},
|
|
1434
|
+
output: {
|
|
1435
|
+
text: model.modalities?.output?.includes("text") ?? existingModel?.capabilities.output.text ?? true,
|
|
1436
|
+
audio:
|
|
1437
|
+
model.modalities?.output?.includes("audio") ?? existingModel?.capabilities.output.audio ?? false,
|
|
1438
|
+
image:
|
|
1439
|
+
model.modalities?.output?.includes("image") ?? existingModel?.capabilities.output.image ?? false,
|
|
1440
|
+
video:
|
|
1441
|
+
model.modalities?.output?.includes("video") ?? existingModel?.capabilities.output.video ?? false,
|
|
1442
|
+
pdf: model.modalities?.output?.includes("pdf") ?? existingModel?.capabilities.output.pdf ?? false,
|
|
1443
|
+
},
|
|
1444
|
+
interleaved:
|
|
1445
|
+
model.interleaved ??
|
|
1446
|
+
existingModel?.capabilities.interleaved ??
|
|
1447
|
+
(!existingModel && apiNpm === "@ai-sdk/openai-compatible" && apiID.includes("deepseek")
|
|
1448
|
+
? { field: "reasoning_content" }
|
|
1449
|
+
: false),
|
|
1450
|
+
},
|
|
1451
|
+
cost: {
|
|
1452
|
+
input: model?.cost?.input ?? existingModel?.cost?.input ?? 0,
|
|
1453
|
+
output: model?.cost?.output ?? existingModel?.cost?.output ?? 0,
|
|
1454
|
+
cache: {
|
|
1455
|
+
read: model?.cost?.cache_read ?? existingModel?.cost?.cache.read ?? 0,
|
|
1456
|
+
write: model?.cost?.cache_write ?? existingModel?.cost?.cache.write ?? 0,
|
|
1457
|
+
},
|
|
1458
|
+
},
|
|
1459
|
+
options: mergeDeep(existingModel?.options ?? {}, model.options ?? {}),
|
|
1460
|
+
limit: {
|
|
1461
|
+
context: model.limit?.context ?? existingModel?.limit?.context ?? 0,
|
|
1462
|
+
input: model.limit?.input ?? existingModel?.limit?.input,
|
|
1463
|
+
output: model.limit?.output ?? existingModel?.limit?.output ?? 0,
|
|
1464
|
+
},
|
|
1465
|
+
headers: mergeDeep(existingModel?.headers ?? {}, model.headers ?? {}),
|
|
1466
|
+
family: model.family ?? existingModel?.family ?? "",
|
|
1467
|
+
release_date: model.release_date ?? existingModel?.release_date ?? "",
|
|
1468
|
+
variants: {},
|
|
1469
|
+
}
|
|
1470
|
+
const merged = mergeDeep(ProviderTransform.variants(parsedModel), model.variants ?? {})
|
|
1471
|
+
parsedModel.variants = mapValues(
|
|
1472
|
+
pickBy(merged, (v) => !v.disabled),
|
|
1473
|
+
(v) => omit(v, ["disabled"]),
|
|
1474
|
+
)
|
|
1475
|
+
parsed.models[modelID] = parsedModel
|
|
1476
|
+
}
|
|
1477
|
+
database[providerID] = parsed
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
// load env
|
|
1481
|
+
const envs = yield* env.all()
|
|
1482
|
+
for (const [id, provider] of Object.entries(database)) {
|
|
1483
|
+
const providerID = ProviderV2.ID.make(id)
|
|
1484
|
+
if (disabled.has(providerID)) continue
|
|
1485
|
+
const apiKey = provider.env.map((item) => envs[item]).find(Boolean)
|
|
1486
|
+
if (!apiKey) continue
|
|
1487
|
+
mergeProvider(providerID, {
|
|
1488
|
+
source: "env",
|
|
1489
|
+
key: provider.env.length === 1 ? apiKey : undefined,
|
|
1490
|
+
})
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
// load apikeys
|
|
1494
|
+
const auths = yield* auth.all().pipe(Effect.orDie)
|
|
1495
|
+
for (const [id, provider] of Object.entries(auths)) {
|
|
1496
|
+
const providerID = ProviderV2.ID.make(id)
|
|
1497
|
+
if (disabled.has(providerID)) continue
|
|
1498
|
+
if (provider.type === "api") {
|
|
1499
|
+
mergeProvider(providerID, {
|
|
1500
|
+
source: "api",
|
|
1501
|
+
key: provider.key,
|
|
1502
|
+
})
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1506
|
+
// plugin auth loader - database now has entries for config providers
|
|
1507
|
+
for (const plugin of plugins) {
|
|
1508
|
+
if (!plugin.auth) continue
|
|
1509
|
+
const providerID = ProviderV2.ID.make(plugin.auth.provider)
|
|
1510
|
+
if (disabled.has(providerID)) continue
|
|
1511
|
+
|
|
1512
|
+
const stored = yield* auth.get(providerID).pipe(Effect.orDie)
|
|
1513
|
+
if (!stored) continue
|
|
1514
|
+
if (!plugin.auth.loader) continue
|
|
1515
|
+
const dbInfo = database[plugin.auth!.provider]
|
|
1516
|
+
if (!dbInfo) continue
|
|
1517
|
+
|
|
1518
|
+
const options = yield* Effect.promise(() =>
|
|
1519
|
+
plugin.auth!.loader!(
|
|
1520
|
+
() => bridge.promise(auth.get(providerID).pipe(Effect.orDie)) as any,
|
|
1521
|
+
toPublicInfo(dbInfo),
|
|
1522
|
+
),
|
|
1523
|
+
)
|
|
1524
|
+
const opts = options ?? {}
|
|
1525
|
+
const patch: Partial<Info> = providers[providerID] ? { options: opts } : { source: "custom", options: opts }
|
|
1526
|
+
mergeProvider(providerID, patch)
|
|
1527
|
+
}
|
|
1528
|
+
|
|
1529
|
+
for (const [id, fn] of Object.entries(custom(dep))) {
|
|
1530
|
+
const providerID = ProviderV2.ID.make(id)
|
|
1531
|
+
if (disabled.has(providerID)) continue
|
|
1532
|
+
const data = database[providerID]
|
|
1533
|
+
if (!data) {
|
|
1534
|
+
log.error("Provider does not exist in model list " + providerID)
|
|
1535
|
+
continue
|
|
1536
|
+
}
|
|
1537
|
+
const result = yield* fn(data)
|
|
1538
|
+
if (result && (result.autoload || providers[providerID])) {
|
|
1539
|
+
if (result.getModel) modelLoaders[providerID] = result.getModel
|
|
1540
|
+
if (result.vars) varsLoaders[providerID] = result.vars
|
|
1541
|
+
if (result.discoverModels) discoveryLoaders[providerID] = result.discoverModels
|
|
1542
|
+
const opts = result.options ?? {}
|
|
1543
|
+
const patch: Partial<Info> = providers[providerID] ? { options: opts } : { source: "custom", options: opts }
|
|
1544
|
+
mergeProvider(providerID, patch)
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1548
|
+
// load config - re-apply with updated data
|
|
1549
|
+
for (const [id, provider] of configProviders) {
|
|
1550
|
+
const providerID = ProviderV2.ID.make(id)
|
|
1551
|
+
const partial: Partial<Info> = { source: "config" }
|
|
1552
|
+
if (provider.env) partial.env = provider.env
|
|
1553
|
+
if (provider.name) partial.name = provider.name
|
|
1554
|
+
if (provider.options) partial.options = provider.options
|
|
1555
|
+
mergeProvider(providerID, partial)
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
const gitlab = ProviderV2.ID.make("gitlab")
|
|
1559
|
+
if (discoveryLoaders[gitlab] && providers[gitlab] && isProviderAllowed(gitlab)) {
|
|
1560
|
+
yield* Effect.promise(async () => {
|
|
1561
|
+
try {
|
|
1562
|
+
const discovered = await discoveryLoaders[gitlab]()
|
|
1563
|
+
for (const [modelID, model] of Object.entries(discovered)) {
|
|
1564
|
+
if (!providers[gitlab].models[modelID]) {
|
|
1565
|
+
providers[gitlab].models[modelID] = model
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
} catch (e) {
|
|
1569
|
+
log.warn("state discovery error", { id: "gitlab", error: e })
|
|
1570
|
+
}
|
|
1571
|
+
})
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1574
|
+
for (const [id, provider] of Object.entries(providers)) {
|
|
1575
|
+
const providerID = ProviderV2.ID.make(id)
|
|
1576
|
+
if (!isProviderAllowed(providerID)) {
|
|
1577
|
+
delete providers[providerID]
|
|
1578
|
+
continue
|
|
1579
|
+
}
|
|
1580
|
+
|
|
1581
|
+
const configProvider = cfg.provider?.[providerID]
|
|
1582
|
+
|
|
1583
|
+
for (const [modelID, model] of Object.entries(provider.models)) {
|
|
1584
|
+
model.api.id = model.api.id ?? model.id ?? modelID
|
|
1585
|
+
if (
|
|
1586
|
+
// These chat aliases are invalid for the special handling in the
|
|
1587
|
+
// built-in providers below, but custom providers may support them.
|
|
1588
|
+
(modelID === "gpt-5-chat-latest" &&
|
|
1589
|
+
(providerID === ProviderV2.ID.openai ||
|
|
1590
|
+
providerID === ProviderV2.ID.githubCopilot ||
|
|
1591
|
+
providerID === ProviderV2.ID.openrouter)) ||
|
|
1592
|
+
(providerID === ProviderV2.ID.openrouter && modelID === "openai/gpt-5-chat")
|
|
1593
|
+
)
|
|
1594
|
+
delete provider.models[modelID]
|
|
1595
|
+
if (model.status === "alpha" && !runtimeFlags.enableExperimentalModels) delete provider.models[modelID]
|
|
1596
|
+
if (model.status === "deprecated") delete provider.models[modelID]
|
|
1597
|
+
if (
|
|
1598
|
+
(configProvider?.blacklist && configProvider.blacklist.includes(modelID)) ||
|
|
1599
|
+
(configProvider?.whitelist && !configProvider.whitelist.includes(modelID))
|
|
1600
|
+
)
|
|
1601
|
+
delete provider.models[modelID]
|
|
1602
|
+
|
|
1603
|
+
if (!model.variants || Object.keys(model.variants).length === 0) {
|
|
1604
|
+
model.variants = mapValues(ProviderTransform.variants(model), (v) => v)
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
const configVariants = configProvider?.models?.[modelID]?.variants
|
|
1608
|
+
if (configVariants && model.variants) {
|
|
1609
|
+
const merged = mergeDeep(model.variants, configVariants)
|
|
1610
|
+
model.variants = mapValues(
|
|
1611
|
+
pickBy(merged, (v) => !v.disabled),
|
|
1612
|
+
(v) => omit(v, ["disabled"]),
|
|
1613
|
+
)
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1617
|
+
if (Object.keys(provider.models).length === 0) {
|
|
1618
|
+
delete providers[providerID]
|
|
1619
|
+
continue
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1622
|
+
log.info("found", { providerID })
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1625
|
+
return {
|
|
1626
|
+
models: languages,
|
|
1627
|
+
providers,
|
|
1628
|
+
catalog,
|
|
1629
|
+
sdk,
|
|
1630
|
+
modelLoaders,
|
|
1631
|
+
varsLoaders,
|
|
1632
|
+
}
|
|
1633
|
+
}),
|
|
1634
|
+
)
|
|
1635
|
+
|
|
1636
|
+
const list = Effect.fn("Provider.list")(() => InstanceState.use(state, (s) => s.providers))
|
|
1637
|
+
|
|
1638
|
+
async function resolveSDK(model: Model, s: State, envs: Record<string, string | undefined>) {
|
|
1639
|
+
try {
|
|
1640
|
+
using _ = log.time("getSDK", {
|
|
1641
|
+
providerID: model.providerID,
|
|
1642
|
+
})
|
|
1643
|
+
const provider = s.providers[model.providerID]
|
|
1644
|
+
const options = { ...provider.options }
|
|
1645
|
+
|
|
1646
|
+
if (
|
|
1647
|
+
model.providerID === "google-vertex" &&
|
|
1648
|
+
model.api.npm === "@ai-sdk/google-vertex/anthropic" &&
|
|
1649
|
+
!options.baseURL
|
|
1650
|
+
) {
|
|
1651
|
+
const baseURL = googleVertexAnthropicBaseURL(
|
|
1652
|
+
typeof options.project === "string" ? options.project : undefined,
|
|
1653
|
+
typeof options.location === "string" ? options.location : undefined,
|
|
1654
|
+
)
|
|
1655
|
+
if (baseURL) options.baseURL = baseURL
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1658
|
+
if (model.providerID === "google-vertex" && !model.api.npm.includes("@ai-sdk/openai-compatible")) {
|
|
1659
|
+
delete options.fetch
|
|
1660
|
+
}
|
|
1661
|
+
|
|
1662
|
+
if (model.api.npm.includes("@ai-sdk/openai-compatible") && options["includeUsage"] !== false) {
|
|
1663
|
+
options["includeUsage"] = true
|
|
1664
|
+
}
|
|
1665
|
+
|
|
1666
|
+
const baseURL = iife(() => {
|
|
1667
|
+
let url =
|
|
1668
|
+
typeof options["baseURL"] === "string" && options["baseURL"] !== "" ? options["baseURL"] : model.api.url
|
|
1669
|
+
if (!url) return
|
|
1670
|
+
|
|
1671
|
+
const loader = s.varsLoaders[model.providerID]
|
|
1672
|
+
if (loader) {
|
|
1673
|
+
const vars = loader(options)
|
|
1674
|
+
for (const [key, value] of Object.entries(vars)) {
|
|
1675
|
+
const field = "${" + key + "}"
|
|
1676
|
+
url = url.replaceAll(field, value)
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
|
|
1680
|
+
url = url.replace(/\$\{([^}]+)\}/g, (item, key) => {
|
|
1681
|
+
const val = envs[String(key)]
|
|
1682
|
+
return val ?? item
|
|
1683
|
+
})
|
|
1684
|
+
return url
|
|
1685
|
+
})
|
|
1686
|
+
|
|
1687
|
+
if (baseURL !== undefined) options["baseURL"] = baseURL
|
|
1688
|
+
if (options["apiKey"] === undefined && provider.key) options["apiKey"] = provider.key
|
|
1689
|
+
if (model.headers)
|
|
1690
|
+
options["headers"] = {
|
|
1691
|
+
...options["headers"],
|
|
1692
|
+
...model.headers,
|
|
1693
|
+
}
|
|
1694
|
+
|
|
1695
|
+
const key = Hash.fast(
|
|
1696
|
+
JSON.stringify({
|
|
1697
|
+
providerID: model.providerID,
|
|
1698
|
+
npm: model.api.npm,
|
|
1699
|
+
options,
|
|
1700
|
+
}),
|
|
1701
|
+
)
|
|
1702
|
+
const existing = s.sdk.get(key)
|
|
1703
|
+
if (existing) return existing
|
|
1704
|
+
|
|
1705
|
+
const customFetch = options["fetch"]
|
|
1706
|
+
const chunkTimeout = options["chunkTimeout"]
|
|
1707
|
+
const headerTimeout = options["headerTimeout"]
|
|
1708
|
+
delete options["chunkTimeout"]
|
|
1709
|
+
delete options["headerTimeout"]
|
|
1710
|
+
|
|
1711
|
+
options["fetch"] = async (input: any, init?: BunFetchRequestInit) => {
|
|
1712
|
+
const fetchFn = customFetch ?? fetch
|
|
1713
|
+
const opts = init ?? {}
|
|
1714
|
+
const chunkAbortCtl = typeof chunkTimeout === "number" && chunkTimeout > 0 ? new AbortController() : undefined
|
|
1715
|
+
const headerTimeoutMs = headerTimeout === false ? undefined : headerTimeout
|
|
1716
|
+
const headerTimeoutCtl = typeof headerTimeoutMs === "number" ? timeoutController(headerTimeoutMs) : undefined
|
|
1717
|
+
const signals: AbortSignal[] = []
|
|
1718
|
+
|
|
1719
|
+
if (opts.signal) signals.push(opts.signal)
|
|
1720
|
+
if (chunkAbortCtl) signals.push(chunkAbortCtl.signal)
|
|
1721
|
+
if (headerTimeoutCtl) signals.push(headerTimeoutCtl.signal)
|
|
1722
|
+
if (options["timeout"] !== undefined && options["timeout"] !== null && options["timeout"] !== false)
|
|
1723
|
+
signals.push(AbortSignal.timeout(options["timeout"]))
|
|
1724
|
+
|
|
1725
|
+
const combined = signals.length === 0 ? null : signals.length === 1 ? signals[0] : AbortSignal.any(signals)
|
|
1726
|
+
if (combined) opts.signal = combined
|
|
1727
|
+
|
|
1728
|
+
// Strip openai itemId metadata following what codex does
|
|
1729
|
+
if (
|
|
1730
|
+
(model.api.npm === "@ai-sdk/openai" ||
|
|
1731
|
+
model.api.npm === "@ai-sdk/azure" ||
|
|
1732
|
+
model.api.npm === "@ai-sdk/amazon-bedrock/mantle") &&
|
|
1733
|
+
opts.body &&
|
|
1734
|
+
opts.method === "POST"
|
|
1735
|
+
) {
|
|
1736
|
+
const body = JSON.parse(opts.body as string)
|
|
1737
|
+
const keepIds = body.store === true
|
|
1738
|
+
if (!keepIds && Array.isArray(body.input)) {
|
|
1739
|
+
for (const item of body.input) {
|
|
1740
|
+
if ("id" in item) {
|
|
1741
|
+
delete item.id
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
opts.body = JSON.stringify(body)
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1748
|
+
const res = await fetchFn(input, {
|
|
1749
|
+
...opts,
|
|
1750
|
+
// @ts-ignore see here: https://github.com/oven-sh/bun/issues/16682
|
|
1751
|
+
timeout: false,
|
|
1752
|
+
}).finally(() => headerTimeoutCtl?.clear())
|
|
1753
|
+
|
|
1754
|
+
if (!chunkAbortCtl) return res
|
|
1755
|
+
return wrapSSE(res, chunkTimeout, chunkAbortCtl)
|
|
1756
|
+
}
|
|
1757
|
+
|
|
1758
|
+
const bundledLoader = BUNDLED_PROVIDERS[model.api.npm]
|
|
1759
|
+
if (bundledLoader) {
|
|
1760
|
+
log.info("using bundled provider", {
|
|
1761
|
+
providerID: model.providerID,
|
|
1762
|
+
pkg: model.api.npm,
|
|
1763
|
+
})
|
|
1764
|
+
const factory = await bundledLoader()
|
|
1765
|
+
const loaded = factory({
|
|
1766
|
+
name: model.providerID,
|
|
1767
|
+
...options,
|
|
1768
|
+
})
|
|
1769
|
+
s.sdk.set(key, loaded)
|
|
1770
|
+
return loaded as SDK
|
|
1771
|
+
}
|
|
1772
|
+
|
|
1773
|
+
const installedPath = await (async () => {
|
|
1774
|
+
if (model.api.npm.startsWith("file://")) {
|
|
1775
|
+
log.info("loading local provider", { pkg: model.api.npm })
|
|
1776
|
+
return model.api.npm
|
|
1777
|
+
}
|
|
1778
|
+
const item = await Npm.add(model.api.npm)
|
|
1779
|
+
if (!item.entrypoint) throw new Error(`Package ${model.api.npm} has no import entrypoint`)
|
|
1780
|
+
return item.entrypoint
|
|
1781
|
+
})()
|
|
1782
|
+
|
|
1783
|
+
// `installedPath` is a local entry path or an existing `file://` URL. Normalize
|
|
1784
|
+
// only path inputs so Node on Windows accepts the dynamic import.
|
|
1785
|
+
const importSpec = installedPath.startsWith("file://") ? installedPath : pathToFileURL(installedPath).href
|
|
1786
|
+
const mod = await import(importSpec)
|
|
1787
|
+
|
|
1788
|
+
const fn = mod[Object.keys(mod).find((key) => key.startsWith("create"))!]
|
|
1789
|
+
const loaded = fn({
|
|
1790
|
+
name: model.providerID,
|
|
1791
|
+
...options,
|
|
1792
|
+
})
|
|
1793
|
+
s.sdk.set(key, loaded)
|
|
1794
|
+
return loaded as SDK
|
|
1795
|
+
} catch (e) {
|
|
1796
|
+
throw new InitError({ providerID: model.providerID, cause: e })
|
|
1797
|
+
}
|
|
1798
|
+
}
|
|
1799
|
+
|
|
1800
|
+
const getProvider = Effect.fn("Provider.getProvider")((providerID: ProviderV2.ID) =>
|
|
1801
|
+
InstanceState.use(state, (s) => s.providers[providerID]),
|
|
1802
|
+
)
|
|
1803
|
+
|
|
1804
|
+
const getModel = Effect.fn("Provider.getModel")(function* (providerID: ProviderV2.ID, modelID: ModelV2.ID) {
|
|
1805
|
+
const s = yield* InstanceState.get(state)
|
|
1806
|
+
const provider = s.providers[providerID]
|
|
1807
|
+
if (!provider) {
|
|
1808
|
+
const catalogProvider = s.catalog[providerID]
|
|
1809
|
+
const suggestions = catalogProvider
|
|
1810
|
+
? modelSuggestions(catalogProvider, modelID, runtimeFlags.enableExperimentalModels)
|
|
1811
|
+
: fuzzysort
|
|
1812
|
+
.go(providerID, Object.keys({ ...s.catalog, ...s.providers }), { limit: 3, threshold: -10000 })
|
|
1813
|
+
.map((m) => m.target)
|
|
1814
|
+
return yield* new ModelNotFoundError({ providerID, modelID, suggestions })
|
|
1815
|
+
}
|
|
1816
|
+
|
|
1817
|
+
const info = provider.models[modelID]
|
|
1818
|
+
if (!info) {
|
|
1819
|
+
const current = modelSuggestions(provider, modelID, runtimeFlags.enableExperimentalModels)
|
|
1820
|
+
const suggestions = current.length
|
|
1821
|
+
? current
|
|
1822
|
+
: modelSuggestions(s.catalog[providerID], modelID, runtimeFlags.enableExperimentalModels)
|
|
1823
|
+
return yield* new ModelNotFoundError({ providerID, modelID, suggestions })
|
|
1824
|
+
}
|
|
1825
|
+
return info
|
|
1826
|
+
})
|
|
1827
|
+
|
|
1828
|
+
const getLanguage = Effect.fn("Provider.getLanguage")(function* (model: Model) {
|
|
1829
|
+
const s = yield* InstanceState.get(state)
|
|
1830
|
+
const envs = yield* env.all()
|
|
1831
|
+
const key = `${model.providerID}/${model.id}`
|
|
1832
|
+
if (s.models.has(key)) return s.models.get(key)!
|
|
1833
|
+
|
|
1834
|
+
const provider = s.providers[model.providerID]
|
|
1835
|
+
return yield* EffectPromise.refineRejection(
|
|
1836
|
+
async () => {
|
|
1837
|
+
const sdk = await resolveSDK(model, s, envs)
|
|
1838
|
+
const language = s.modelLoaders[model.providerID]
|
|
1839
|
+
? await s.modelLoaders[model.providerID](
|
|
1840
|
+
sdk,
|
|
1841
|
+
model.api.id,
|
|
1842
|
+
{
|
|
1843
|
+
...provider.options,
|
|
1844
|
+
...model.options,
|
|
1845
|
+
},
|
|
1846
|
+
model,
|
|
1847
|
+
)
|
|
1848
|
+
: sdk.languageModel(model.api.id)
|
|
1849
|
+
s.models.set(key, language)
|
|
1850
|
+
return language
|
|
1851
|
+
},
|
|
1852
|
+
(cause) =>
|
|
1853
|
+
cause instanceof NoSuchModelError
|
|
1854
|
+
? new ModelNotFoundError({ modelID: model.id, providerID: model.providerID, cause })
|
|
1855
|
+
: undefined,
|
|
1856
|
+
)
|
|
1857
|
+
})
|
|
1858
|
+
|
|
1859
|
+
const closest = Effect.fn("Provider.closest")(function* (providerID: ProviderV2.ID, query: string[]) {
|
|
1860
|
+
const s = yield* InstanceState.get(state)
|
|
1861
|
+
const provider = s.providers[providerID]
|
|
1862
|
+
if (!provider) return undefined
|
|
1863
|
+
for (const item of query) {
|
|
1864
|
+
for (const modelID of Object.keys(provider.models)) {
|
|
1865
|
+
if (modelID.includes(item)) return { providerID, modelID }
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
return undefined
|
|
1869
|
+
})
|
|
1870
|
+
|
|
1871
|
+
const getSmallModel = Effect.fn("Provider.getSmallModel")(function* (providerID: ProviderV2.ID) {
|
|
1872
|
+
const cfg = yield* config.get()
|
|
1873
|
+
|
|
1874
|
+
if (cfg.small_model) {
|
|
1875
|
+
const parsed = parseModel(cfg.small_model)
|
|
1876
|
+
return yield* getModel(parsed.providerID, parsed.modelID).pipe(
|
|
1877
|
+
Effect.catchTag("ProviderModelNotFoundError", () => Effect.succeed(undefined)),
|
|
1878
|
+
)
|
|
1879
|
+
}
|
|
1880
|
+
|
|
1881
|
+
const s = yield* InstanceState.get(state)
|
|
1882
|
+
const provider = s.providers[providerID]
|
|
1883
|
+
if (!provider) return undefined
|
|
1884
|
+
|
|
1885
|
+
const experimental = yield* plugin.trigger<"experimental.provider.small_model">(
|
|
1886
|
+
"experimental.provider.small_model",
|
|
1887
|
+
{ provider: toPublicInfo(provider) },
|
|
1888
|
+
{ model: undefined },
|
|
1889
|
+
)
|
|
1890
|
+
if (experimental.model) {
|
|
1891
|
+
return {
|
|
1892
|
+
...experimental.model,
|
|
1893
|
+
id: ModelV2.ID.make(experimental.model.id),
|
|
1894
|
+
providerID: ProviderV2.ID.make(experimental.model.providerID),
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
|
|
1898
|
+
const defaultPriority = [
|
|
1899
|
+
"claude-haiku-4-5",
|
|
1900
|
+
"claude-haiku-4.5",
|
|
1901
|
+
"3-5-haiku",
|
|
1902
|
+
"3.5-haiku",
|
|
1903
|
+
"gemini-3-flash",
|
|
1904
|
+
"gemini-2.5-flash",
|
|
1905
|
+
"gpt-5-nano",
|
|
1906
|
+
]
|
|
1907
|
+
const priority = providerID.startsWith("opencode")
|
|
1908
|
+
? ["gpt-5-nano"]
|
|
1909
|
+
: providerID.startsWith("github-copilot")
|
|
1910
|
+
? ["gpt-5-mini", "claude-haiku-4.5", ...defaultPriority]
|
|
1911
|
+
: defaultPriority
|
|
1912
|
+
for (const item of priority) {
|
|
1913
|
+
if (providerID === ProviderV2.ID.amazonBedrock) {
|
|
1914
|
+
const crossRegionPrefixes = ["global.", "us.", "eu."]
|
|
1915
|
+
const candidates = Object.keys(provider.models).filter((m) => m.includes(item))
|
|
1916
|
+
|
|
1917
|
+
const globalMatch = candidates.find((m) => m.startsWith("global."))
|
|
1918
|
+
if (globalMatch) return provider.models[globalMatch]
|
|
1919
|
+
|
|
1920
|
+
const region = provider.options?.region
|
|
1921
|
+
if (region) {
|
|
1922
|
+
const regionPrefix = region.split("-")[0]
|
|
1923
|
+
if (regionPrefix === "us" || regionPrefix === "eu") {
|
|
1924
|
+
const regionalMatch = candidates.find((m) => m.startsWith(`${regionPrefix}.`))
|
|
1925
|
+
if (regionalMatch) return provider.models[regionalMatch]
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
|
|
1929
|
+
const unprefixed = candidates.find((m) => !crossRegionPrefixes.some((p) => m.startsWith(p)))
|
|
1930
|
+
if (unprefixed) return provider.models[unprefixed]
|
|
1931
|
+
} else {
|
|
1932
|
+
for (const model of Object.keys(provider.models)) {
|
|
1933
|
+
if (model.includes(item)) return provider.models[model]
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
|
|
1938
|
+
return undefined
|
|
1939
|
+
})
|
|
1940
|
+
|
|
1941
|
+
const defaultModel = Effect.fn("Provider.defaultModel")(function* () {
|
|
1942
|
+
const cfg = yield* config.get()
|
|
1943
|
+
if (cfg.model) return parseModel(cfg.model)
|
|
1944
|
+
|
|
1945
|
+
const s = yield* InstanceState.get(state)
|
|
1946
|
+
const recent = yield* fs.readJson(path.join(Global.Path.state, "model.json")).pipe(
|
|
1947
|
+
Effect.map((x): { providerID: ProviderV2.ID; modelID: ModelV2.ID }[] => {
|
|
1948
|
+
if (!isRecord(x) || !Array.isArray(x.recent)) return []
|
|
1949
|
+
return x.recent.flatMap((item) => {
|
|
1950
|
+
if (!isRecord(item)) return []
|
|
1951
|
+
if (typeof item.providerID !== "string") return []
|
|
1952
|
+
if (typeof item.modelID !== "string") return []
|
|
1953
|
+
return [{ providerID: ProviderV2.ID.make(item.providerID), modelID: ModelV2.ID.make(item.modelID) }]
|
|
1954
|
+
})
|
|
1955
|
+
}),
|
|
1956
|
+
Effect.catch(() => Effect.succeed([] as { providerID: ProviderV2.ID; modelID: ModelV2.ID }[])),
|
|
1957
|
+
)
|
|
1958
|
+
for (const entry of recent) {
|
|
1959
|
+
const provider = s.providers[entry.providerID]
|
|
1960
|
+
if (!provider) continue
|
|
1961
|
+
if (!provider.models[entry.modelID]) continue
|
|
1962
|
+
return { providerID: entry.providerID, modelID: entry.modelID }
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1965
|
+
const provider = Object.values(s.providers).find((p) => !cfg.provider || Object.keys(cfg.provider).includes(p.id))
|
|
1966
|
+
if (!provider) return yield* new NoProvidersError()
|
|
1967
|
+
const [model] = sort(Object.values(provider.models))
|
|
1968
|
+
if (!model) return yield* new NoModelsError({ providerID: provider.id })
|
|
1969
|
+
return {
|
|
1970
|
+
providerID: provider.id,
|
|
1971
|
+
modelID: model.id,
|
|
1972
|
+
}
|
|
1973
|
+
})
|
|
1974
|
+
|
|
1975
|
+
return Service.of({ list, getProvider, getModel, getLanguage, closest, getSmallModel, defaultModel })
|
|
1976
|
+
}),
|
|
1977
|
+
)
|
|
1978
|
+
|
|
1979
|
+
export const defaultLayer = Layer.suspend(() =>
|
|
1980
|
+
layer.pipe(
|
|
1981
|
+
Layer.provide(FSUtil.defaultLayer),
|
|
1982
|
+
Layer.provide(Env.defaultLayer),
|
|
1983
|
+
Layer.provide(Config.defaultLayer),
|
|
1984
|
+
Layer.provide(Auth.defaultLayer),
|
|
1985
|
+
Layer.provide(Plugin.defaultLayer),
|
|
1986
|
+
Layer.provide(ModelsDev.defaultLayer),
|
|
1987
|
+
Layer.provide(RuntimeFlags.defaultLayer),
|
|
1988
|
+
),
|
|
1989
|
+
)
|
|
1990
|
+
|
|
1991
|
+
const priority = ["gpt-5", "claude-sonnet-4", "big-pickle", "gemini-3-pro"]
|
|
1992
|
+
export function sort<T extends { id: string }>(models: T[]) {
|
|
1993
|
+
return sortBy(
|
|
1994
|
+
models,
|
|
1995
|
+
[(model) => priority.findIndex((filter) => model.id.includes(filter)), "desc"],
|
|
1996
|
+
[(model) => (model.id.includes("latest") ? 0 : 1), "asc"],
|
|
1997
|
+
[(model) => model.id, "desc"],
|
|
1998
|
+
)
|
|
1999
|
+
}
|
|
2000
|
+
|
|
2001
|
+
export function parseModel(model: string) {
|
|
2002
|
+
const [providerID, ...rest] = model.split("/")
|
|
2003
|
+
return {
|
|
2004
|
+
providerID: ProviderV2.ID.make(providerID),
|
|
2005
|
+
modelID: ModelV2.ID.make(rest.join("/")),
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
|
|
2009
|
+
export * as Provider from "./provider"
|