@humain/humain-code 0.4.15 → 0.4.17
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/CHANGELOG.md +74 -0
- package/README.md +1 -1
- package/dist/bundle/agent-monitor.js +1 -1
- package/dist/bundle/chunks/anthropic-messages-TSNY5MWH.js +67 -0
- package/dist/bundle/chunks/azure-openai-responses-Z4DCXO2G.js +15 -0
- package/dist/bundle/chunks/bedrock-converse-stream.js +59 -42
- package/dist/bundle/chunks/{chunk-JRX7GYW3.js → chunk-4NFYTS4C.js} +8 -8
- package/dist/bundle/chunks/{chunk-MF2NEHP4.js → chunk-4XU7TDAL.js} +939 -560
- package/dist/bundle/chunks/{chunk-LUL775V7.js → chunk-5K5RFXXO.js} +4 -4
- package/dist/bundle/chunks/chunk-65U7MPF4.js +1790 -0
- package/dist/bundle/chunks/{chunk-AIXI6RIE.js → chunk-7PRU6YW3.js} +114 -82
- package/dist/bundle/chunks/{chunk-W5YJZKPF.js → chunk-AOL6QG6L.js} +2231 -2399
- package/dist/bundle/chunks/chunk-AWCJWXGD.js +212 -0
- package/dist/bundle/chunks/{chunk-NNKA2PAP.js → chunk-FHVNUUBF.js} +1 -1
- package/dist/bundle/chunks/chunk-FZUJXM6D.js +816 -0
- package/dist/bundle/chunks/chunk-IJYVMOB4.js +6 -0
- package/dist/bundle/chunks/chunk-LG2PJ6JN.js +131 -0
- package/dist/bundle/chunks/chunk-NCQ6WAQK.js +125 -0
- package/dist/bundle/chunks/{chunk-Z74ZYQPX.js → chunk-OKALNPTJ.js} +80 -210
- package/dist/bundle/chunks/{chunk-OX2IBCCA.js → chunk-PTP2ZHFQ.js} +88 -82
- package/dist/bundle/chunks/chunk-PY7SOXCA.js +10 -0
- package/dist/bundle/chunks/chunk-Q7VXYXY3.js +7 -0
- package/dist/bundle/chunks/{chunk-COF5P635.js → chunk-QEF72EIZ.js} +13 -13
- package/dist/bundle/chunks/{chunk-EYIYBQAR.js → chunk-RXOCQRBG.js} +1 -1
- package/dist/bundle/chunks/{chunk-BVHXWQLD.js → chunk-SCBU5WOP.js} +1 -1
- package/dist/bundle/chunks/{chunk-UDVC7A5S.js → chunk-TIFFHHW6.js} +16 -14
- package/dist/bundle/chunks/{chunk-L3J4P5JR.js → chunk-UGJAAWNC.js} +1 -1
- package/dist/bundle/chunks/chunk-V76YPIMT.js +48 -0
- package/dist/bundle/chunks/{chunk-Y3RFGBG2.js → chunk-X3O5MCKJ.js} +1 -1
- package/dist/bundle/chunks/{chunk-KK3KUUMM.js → chunk-X6OTEVGA.js} +71 -66
- package/dist/bundle/chunks/chunk-Y26OS23T.js +80 -0
- package/dist/bundle/chunks/chunk-YDBNMIA3.js +34 -0
- package/dist/bundle/chunks/{chunk-UHLW4KJ7.js → chunk-ZRGFX6T6.js} +92 -89
- package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-JGN7NZCV.js → cloudflare-workers-ai-system-one-MUJQ6LT2.js} +1 -1
- package/dist/bundle/chunks/{compat-2S3PCPEI.js → compat-ARQPWKBQ.js} +8 -8
- package/dist/bundle/chunks/{dist-SGQMXO45.js → dist-D7M52E3X.js} +1416 -866
- package/dist/bundle/chunks/dist-LKDZAEUQ.js +7 -0
- package/dist/bundle/chunks/{dist-JXEXN6S2.js → dist-XVXV2CL4.js} +1 -1
- package/dist/bundle/chunks/dist-cjs-AXBW3N4F.js +182 -0
- package/dist/bundle/chunks/{easter-egg-3d-ZJ2JUFOA.js → easter-egg-3d-4SUPLBUF.js} +1 -1
- package/dist/bundle/chunks/{execute-LRTXH4YJ.js → execute-NTO3U76E.js} +10 -9
- package/dist/bundle/chunks/{extract-OZW5JHG6.js → extract-BKBHK4AK.js} +14 -13
- package/dist/bundle/chunks/github-copilot.js +34 -47
- package/dist/bundle/chunks/{google-generative-ai-YXXFSTX7.js → google-generative-ai-SJ4JO2MY.js} +2 -2
- package/dist/bundle/chunks/{google-vertex-3IVWLYJ5.js → google-vertex-KNLNNDET.js} +2 -2
- package/dist/bundle/chunks/host-63SNKK5Y.js +2 -0
- package/dist/bundle/chunks/jiti-static-loader-7OZNBOCI.js +2 -0
- package/dist/bundle/chunks/{mistral-conversations-Y7GWO3QB.js → mistral-conversations-G3GN6CMT.js} +20 -20
- package/dist/bundle/chunks/{node-SPBTZUUS.js → node-DZCAT4Q6.js} +1 -1
- package/dist/bundle/chunks/{openai-codex-responses-NSXWHIDT.js → openai-codex-responses-FJFDAWHI.js} +17 -17
- package/dist/bundle/chunks/openai-completions-IC7WRLTI.js +82 -0
- package/dist/bundle/chunks/{openai-decisions-QWEISDVO.js → openai-decisions-HESOHYZB.js} +1 -1
- package/dist/bundle/chunks/openai-responses-XXCYDFSM.js +24 -0
- package/dist/bundle/chunks/{openrouter-images-BMVMAROU.js → openrouter-images-DT2HMZNO.js} +1 -1
- package/dist/bundle/chunks/pdfjs-EK6K7CXX.js +3593 -0
- package/dist/bundle/chunks/{pi-messages-XNEG23NU.js → pi-messages-SAOV3JNW.js} +1 -1
- package/dist/bundle/chunks/{typesafe-system-one-62YHYXZV.js → typesafe-system-one-HCMGHK6A.js} +1 -1
- package/dist/bundle/chunks/{undici-7EW63V4X.js → undici-N4LWJ3S3.js} +1 -1
- package/dist/bundle/chunks/virtual-modules-LP2ULVLW.js +5 -0
- package/dist/bundle/cli-runtime.js +3 -3
- package/dist/bundle/cli.js +2 -2
- package/dist/bundle/flow/package.json +6 -5
- package/dist/bundle/index.js +8 -8
- package/dist/bundle/rpc-entry.js +3 -3
- package/dist/cli/credential-print.d.ts.map +1 -1
- package/dist/cli/credential-print.js +4 -4
- package/dist/cli/credential-print.js.map +1 -1
- package/dist/coordination/adapter/index.d.ts.map +1 -1
- package/dist/coordination/adapter/index.js +1 -1
- package/dist/coordination/adapter/index.js.map +1 -1
- package/dist/coordination/adapter/integration-notices.d.ts +1 -1
- package/dist/coordination/adapter/integration-notices.d.ts.map +1 -1
- package/dist/coordination/adapter/integration-notices.js +5 -2
- package/dist/coordination/adapter/integration-notices.js.map +1 -1
- package/dist/coordination/broker/extension-state.js +3 -3
- package/dist/coordination/broker/extension-state.js.map +1 -1
- package/dist/coordination/transport/framing.d.ts.map +1 -1
- package/dist/coordination/transport/framing.js +2 -1
- package/dist/coordination/transport/framing.js.map +1 -1
- package/dist/core/account-reporting.d.ts +3 -1
- package/dist/core/account-reporting.d.ts.map +1 -1
- package/dist/core/account-reporting.js +12 -2
- package/dist/core/account-reporting.js.map +1 -1
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +39 -36
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +4 -2
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +5 -4
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/codex-usage.d.ts +11 -2
- package/dist/core/codex-usage.d.ts.map +1 -1
- package/dist/core/codex-usage.js +74 -2
- package/dist/core/codex-usage.js.map +1 -1
- package/dist/core/export-html/template.js +21 -16
- package/dist/core/model-config.d.ts +33 -8
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +22 -4
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-resolver.d.ts +56 -43
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +256 -361
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts +6 -3
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +19 -5
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/models-store.d.ts.map +1 -1
- package/dist/core/models-store.js +7 -2
- package/dist/core/models-store.js.map +1 -1
- package/dist/core/oauth-account-pool.d.ts +9 -1
- package/dist/core/oauth-account-pool.d.ts.map +1 -1
- package/dist/core/oauth-account-pool.js +63 -12
- package/dist/core/oauth-account-pool.js.map +1 -1
- package/dist/core/prompt-templates.d.ts.map +1 -1
- package/dist/core/prompt-templates.js +7 -2
- package/dist/core/prompt-templates.js.map +1 -1
- package/dist/core/settings-defaults.d.ts +2 -0
- package/dist/core/settings-defaults.d.ts.map +1 -1
- package/dist/core/settings-defaults.js +2 -0
- package/dist/core/settings-defaults.js.map +1 -1
- package/dist/core/settings-manager.d.ts +4 -2
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +11 -0
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/settings-schema.d.ts +4 -0
- package/dist/core/settings-schema.d.ts.map +1 -1
- package/dist/core/settings-schema.js +8 -0
- package/dist/core/settings-schema.js.map +1 -1
- package/dist/core/slash-commands.js +1 -1
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/tools/render-utils.d.ts +2 -0
- package/dist/core/tools/render-utils.d.ts.map +1 -1
- package/dist/core/tools/render-utils.js +21 -0
- package/dist/core/tools/render-utils.js.map +1 -1
- package/dist/core/tools/renderers/read.d.ts.map +1 -1
- package/dist/core/tools/renderers/read.js +7 -10
- package/dist/core/tools/renderers/read.js.map +1 -1
- package/dist/core/tools/subagent.d.ts.map +1 -1
- package/dist/core/tools/subagent.js +4 -7
- package/dist/core/tools/subagent.js.map +1 -1
- package/dist/core/trace/redaction.d.ts.map +1 -1
- package/dist/core/trace/redaction.js +3 -1
- package/dist/core/trace/redaction.js.map +1 -1
- package/dist/extensions/codemode/execute.d.ts.map +1 -1
- package/dist/extensions/codemode/execute.js +12 -0
- package/dist/extensions/codemode/execute.js.map +1 -1
- package/dist/extensions/codemode/index.d.ts.map +1 -1
- package/dist/extensions/codemode/index.js +5 -0
- package/dist/extensions/codemode/index.js.map +1 -1
- package/dist/humain/bedrock-provider/vendor/index.bundle.mjs +74 -20
- package/dist/humain/flow-accounts-host.d.ts.map +1 -1
- package/dist/humain/flow-accounts-host.js +3 -0
- package/dist/humain/flow-accounts-host.js.map +1 -1
- package/dist/humain/node-provider.d.ts.map +1 -1
- package/dist/humain/node-provider.js +2 -0
- package/dist/humain/node-provider.js.map +1 -1
- package/dist/humain/trace-capture/index.js +3 -3
- package/dist/humain/trace-capture/index.js.map +1 -1
- package/dist/humain/web-access/vendor/credential-source.d.ts +2 -0
- package/dist/humain/web-access/vendor/credential-source.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/credential-source.js +50 -4
- package/dist/humain/web-access/vendor/credential-source.js.map +1 -1
- package/dist/humain/web-access/vendor/curator-page.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/curator-page.js +3 -1
- package/dist/humain/web-access/vendor/curator-page.js.map +1 -1
- package/dist/humain/web-access/vendor/curator-server.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/curator-server.js +2 -0
- package/dist/humain/web-access/vendor/curator-server.js.map +1 -1
- package/dist/humain/web-access/vendor/deepseek.d.ts +4 -0
- package/dist/humain/web-access/vendor/deepseek.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/deepseek.js +201 -0
- package/dist/humain/web-access/vendor/deepseek.js.map +1 -0
- package/dist/humain/web-access/vendor/extract.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/extract.js +4 -2
- package/dist/humain/web-access/vendor/extract.js.map +1 -1
- package/dist/humain/web-access/vendor/gemini-adc.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/gemini-adc.js +49 -5
- package/dist/humain/web-access/vendor/gemini-adc.js.map +1 -1
- package/dist/humain/web-access/vendor/gemini-search.d.ts +3 -3
- package/dist/humain/web-access/vendor/gemini-search.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/gemini-search.js +11 -4
- package/dist/humain/web-access/vendor/gemini-search.js.map +1 -1
- package/dist/humain/web-access/vendor/index.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/index.js +16 -1
- package/dist/humain/web-access/vendor/index.js.map +1 -1
- package/dist/humain/web-access/vendor/page-query.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/page-query.js +12 -6
- package/dist/humain/web-access/vendor/page-query.js.map +1 -1
- package/dist/humain/web-access/vendor/query-rewrite.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/query-rewrite.js +11 -4
- package/dist/humain/web-access/vendor/query-rewrite.js.map +1 -1
- package/dist/humain/web-access/vendor/searxng.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/searxng.js +2 -1
- package/dist/humain/web-access/vendor/searxng.js.map +1 -1
- package/dist/humain/web-access/vendor/ssrf-protection.d.ts +1 -0
- package/dist/humain/web-access/vendor/ssrf-protection.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/ssrf-protection.js +10 -0
- package/dist/humain/web-access/vendor/ssrf-protection.js.map +1 -1
- package/dist/humain/web-access/vendor/summary-review.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/summary-review.js +17 -6
- package/dist/humain/web-access/vendor/summary-review.js.map +1 -1
- package/dist/humain/web-access/vendor/utils.d.ts +2 -0
- package/dist/humain/web-access/vendor/utils.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/utils.js +18 -0
- package/dist/humain/web-access/vendor/utils.js.map +1 -1
- package/dist/humain/web-access/vendor/web-tool-core.d.ts +2 -0
- package/dist/humain/web-access/vendor/web-tool-core.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/web-tool-core.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +1 -0
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +3 -1
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +10 -0
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/status-indicator.d.ts +5 -0
- package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -1
- package/dist/modes/interactive/components/status-indicator.js +27 -2
- package/dist/modes/interactive/components/status-indicator.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +2 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +4 -2
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector.js +2 -9
- package/dist/modes/interactive/components/tree-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +28 -14
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/oauth-account-format.d.ts +4 -4
- package/dist/modes/interactive/oauth-account-format.d.ts.map +1 -1
- package/dist/modes/interactive/oauth-account-format.js +5 -2
- package/dist/modes/interactive/oauth-account-format.js.map +1 -1
- package/dist/modes/interactive/session-share.d.ts.map +1 -1
- package/dist/modes/interactive/session-share.js +9 -2
- package/dist/modes/interactive/session-share.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +8 -3
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +2 -1
- package/dist/utils/tools-manager.js.map +1 -1
- package/docs/cli.md +3 -3
- package/docs/codemode.md +3 -1
- package/docs/coordination.md +6 -0
- package/docs/docs.json +4 -0
- package/docs/environment-variables.md +4 -0
- package/docs/flow.md +6 -0
- package/docs/humain-code-forge-flow-walkthrough.md +1 -1
- package/docs/humain-code.md +2 -4
- package/docs/json.md +2 -2
- package/docs/llama-cpp.md +1 -1
- package/docs/nvidia-rtx-llama-cpp.md +96 -0
- package/docs/rpc-commands.md +1 -1
- package/docs/rpc.md +9 -1
- package/docs/sessions.md +1 -1
- package/docs/settings.md +2 -0
- package/docs/trace.md +4 -0
- package/docs/usage.md +1 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +16 -6
- package/examples/extensions/custom-provider-anthropic/package.json +2 -2
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +16 -16
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/minimal-mode.ts +4 -4
- package/examples/extensions/sandbox/package-lock.json +6 -6
- package/examples/extensions/sandbox/package.json +2 -2
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/plugins/pi-example-plugin/package.json +2 -2
- package/examples/rpc-subagent-progress-host.ts +6 -2
- package/npm-shrinkwrap.json +129 -171
- package/package.json +19 -19
- package/schemas/models.schema.json +9 -5
- package/schemas/settings.schema.json +32 -0
- package/src/coordination/UPSTREAM.md +31 -1
- package/src/coordination/upstream.json +3 -3
- package/src/humain/adhd/UPSTREAM.md +8 -0
- package/src/humain/caveman/UPSTREAM.md +19 -3
- package/src/humain/caveman/upstream.json +2 -2
- package/src/humain/ponytail/UPSTREAM.md +23 -2
- package/src/humain/ponytail/upstream.json +8 -8
- package/src/humain/ponytail/vendor/skills/ponytail/SKILL.md +1 -1
- package/src/humain/ponytail/vendor/skills/ponytail-debt/SKILL.md +1 -2
- package/src/humain/ponytail/vendor/skills/ponytail-gain/SKILL.md +0 -1
- package/src/humain/web-access/UPSTREAM.md +45 -1
- package/src/humain/web-access/upstream.json +4 -4
- package/dist/bundle/chunks/anthropic-messages-YSAHA7QM.js +0 -67
- package/dist/bundle/chunks/azure-openai-responses-Z5XYDPHS.js +0 -15
- package/dist/bundle/chunks/chunk-2TTB6GIB.js +0 -47
- package/dist/bundle/chunks/chunk-5JHUWRJN.js +0 -1790
- package/dist/bundle/chunks/chunk-A7QKOI62.js +0 -572
- package/dist/bundle/chunks/chunk-FRUFMISJ.js +0 -505
- package/dist/bundle/chunks/chunk-MG5PX4KU.js +0 -31
- package/dist/bundle/chunks/chunk-OEOXBLWI.js +0 -540
- package/dist/bundle/chunks/chunk-RYC5BYVE.js +0 -5
- package/dist/bundle/chunks/chunk-YJ3NQWES.js +0 -9
- package/dist/bundle/chunks/dist-MNSGVI4C.js +0 -7
- package/dist/bundle/chunks/dist-cjs-4BMVQ74V.js +0 -179
- package/dist/bundle/chunks/host-2RMBOGA7.js +0 -2
- package/dist/bundle/chunks/jiti-static-loader-2RCDI6B4.js +0 -2
- package/dist/bundle/chunks/openai-completions-WGBQHTYA.js +0 -79
- package/dist/bundle/chunks/openai-responses-OKGCSIEY.js +0 -23
- package/dist/bundle/chunks/pdfjs-6UVU6XFX.js +0 -3564
- package/dist/bundle/chunks/virtual-modules-7HDINPIK.js +0 -5
|
@@ -20,7 +20,7 @@ export const defaultModelPerProvider = {
|
|
|
20
20
|
deepseek: "deepseek-v4-pro",
|
|
21
21
|
google: "gemini-3.1-pro-preview",
|
|
22
22
|
"google-vertex": "gemini-3.1-pro-preview",
|
|
23
|
-
"github-copilot": "gpt-5.
|
|
23
|
+
"github-copilot": "gpt-5.6-terra",
|
|
24
24
|
openrouter: "moonshotai/kimi-k2.6",
|
|
25
25
|
"vercel-ai-gateway": "zai/glm-5.1",
|
|
26
26
|
xai: "grok-4.7",
|
|
@@ -47,93 +47,172 @@ export const defaultModelPerProvider = {
|
|
|
47
47
|
"qwen-token-plan-cn": "qwen3.7-max",
|
|
48
48
|
"qwen-token-plan-individual": "qwen3.8-max",
|
|
49
49
|
"humain-node": "humain-m3-research-preview",
|
|
50
|
-
xiaomi: "mimo-v2.
|
|
51
|
-
"xiaomi-token-plan-cn": "mimo-v2.
|
|
52
|
-
"xiaomi-token-plan-ams": "mimo-v2.
|
|
53
|
-
"xiaomi-token-plan-sgp": "mimo-v2.
|
|
50
|
+
xiaomi: "mimo-v2.6-pro",
|
|
51
|
+
"xiaomi-token-plan-cn": "mimo-v2.6-pro",
|
|
52
|
+
"xiaomi-token-plan-ams": "mimo-v2.6-pro",
|
|
53
|
+
"xiaomi-token-plan-sgp": "mimo-v2.6-pro",
|
|
54
54
|
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (id.endsWith("-latest"))
|
|
62
|
-
return true;
|
|
63
|
-
// Check if ID ends with a date pattern (-YYYYMMDD)
|
|
64
|
-
const datePattern = /-\d{8}$/;
|
|
65
|
-
return !datePattern.test(id);
|
|
55
|
+
function splitThinkingSuffix(text) {
|
|
56
|
+
const colonIndex = text.lastIndexOf(":");
|
|
57
|
+
const suffix = text.substring(colonIndex + 1);
|
|
58
|
+
if (colonIndex === -1 || !isValidThinkingLevel(suffix))
|
|
59
|
+
return undefined;
|
|
60
|
+
return { base: text.substring(0, colonIndex), thinkingLevel: suffix };
|
|
66
61
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
* When matching by bare id, ambiguous matches across providers are rejected.
|
|
71
|
-
*/
|
|
72
|
-
export function findExactModelReferenceMatch(modelReference, availableModels) {
|
|
73
|
-
const trimmedReference = modelReference.trim();
|
|
74
|
-
if (!trimmedReference) {
|
|
62
|
+
function splitProviderPrefix(text, models) {
|
|
63
|
+
const slashIndex = text.indexOf("/");
|
|
64
|
+
if (slashIndex === -1)
|
|
75
65
|
return undefined;
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
if (canonicalMatches.length === 1) {
|
|
80
|
-
return canonicalMatches[0];
|
|
81
|
-
}
|
|
82
|
-
if (canonicalMatches.length > 1) {
|
|
66
|
+
const prefix = text.substring(0, slashIndex).trim().toLowerCase();
|
|
67
|
+
const modelText = text.substring(slashIndex + 1).trim();
|
|
68
|
+
if (!prefix || !modelText)
|
|
83
69
|
return undefined;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (slashIndex !== -1) {
|
|
87
|
-
const provider = trimmedReference.substring(0, slashIndex).trim();
|
|
88
|
-
const modelId = trimmedReference.substring(slashIndex + 1).trim();
|
|
89
|
-
if (provider && modelId) {
|
|
90
|
-
const providerMatches = availableModels.filter((model) => model.provider.toLowerCase() === provider.toLowerCase() &&
|
|
91
|
-
model.id.toLowerCase() === modelId.toLowerCase());
|
|
92
|
-
if (providerMatches.length === 1) {
|
|
93
|
-
return providerMatches[0];
|
|
94
|
-
}
|
|
95
|
-
if (providerMatches.length > 1) {
|
|
96
|
-
return undefined;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
const idMatches = availableModels.filter((model) => model.id.toLowerCase() === normalizedReference);
|
|
101
|
-
return idMatches.length === 1 ? idMatches[0] : undefined;
|
|
70
|
+
const provider = models.find((model) => model.provider.toLowerCase() === prefix)?.provider;
|
|
71
|
+
return provider ? { provider, modelText } : undefined;
|
|
102
72
|
}
|
|
103
73
|
/**
|
|
104
|
-
*
|
|
105
|
-
*
|
|
74
|
+
* `usable` only breaks ties between providers, so a unique match resolves even without credentials
|
|
75
|
+
* (`--api-key` first-time setup).
|
|
106
76
|
*/
|
|
107
|
-
function
|
|
108
|
-
const
|
|
109
|
-
if (
|
|
110
|
-
return
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
77
|
+
export function resolveModelReference(request, models, usable) {
|
|
78
|
+
const text = request.text.trim();
|
|
79
|
+
if (!text)
|
|
80
|
+
return { status: "not-found" };
|
|
81
|
+
const constraint = request.provider?.toLowerCase();
|
|
82
|
+
const pool = constraint ? models.filter((model) => model.provider.toLowerCase() === constraint) : models;
|
|
83
|
+
const result = resolveText(text, request, pool, usable);
|
|
84
|
+
if (result.status !== "not-found")
|
|
85
|
+
return result;
|
|
86
|
+
const split = splitProviderPrefix(text, pool);
|
|
87
|
+
const anchor = constraint ? pool[0] : pool.find((model) => model.provider === split?.provider);
|
|
88
|
+
if (!anchor)
|
|
89
|
+
return result;
|
|
90
|
+
const modelText = split?.modelText ?? text;
|
|
91
|
+
const suffix = request.thinkingSuffix === "none" ? undefined : splitThinkingSuffix(modelText);
|
|
92
|
+
return {
|
|
93
|
+
status: "not-found",
|
|
94
|
+
target: {
|
|
95
|
+
provider: anchor.provider,
|
|
96
|
+
providerModels: [anchor, ...pool.filter((model) => model.provider === anchor.provider && model !== anchor)],
|
|
97
|
+
modelText,
|
|
98
|
+
modelId: suffix?.base ?? modelText,
|
|
99
|
+
thinkingLevel: suffix?.thinkingLevel,
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/** Exact `provider/id` or bare id lookup without thinking suffixes or fuzzy matching. */
|
|
104
|
+
export function findExactModelReferenceMatch(modelReference, models) {
|
|
105
|
+
const result = resolveModelReference({ text: modelReference, thinkingSuffix: "none", fuzzy: false }, models, () => true);
|
|
106
|
+
return result.status === "resolved" ? result.model : undefined;
|
|
107
|
+
}
|
|
108
|
+
function resolveText(text, request, pool, usable) {
|
|
109
|
+
// An explicit provider makes its literal catalog IDs authoritative, even if they repeat the provider prefix.
|
|
110
|
+
const literal = request.provider ? pool.find((model) => model.id.toLowerCase() === text.toLowerCase()) : undefined;
|
|
111
|
+
if (literal)
|
|
112
|
+
return { status: "resolved", model: literal };
|
|
113
|
+
const reference = selectReference(text, pool, request.fuzzy, usable);
|
|
114
|
+
if (reference)
|
|
115
|
+
return reference;
|
|
116
|
+
if (request.fuzzy) {
|
|
117
|
+
const fuzzy = selectFuzzy(fuzzyMatches(text, pool), usable);
|
|
118
|
+
if (fuzzy)
|
|
119
|
+
return fuzzy;
|
|
120
|
+
}
|
|
121
|
+
if (request.thinkingSuffix === "none")
|
|
122
|
+
return { status: "not-found" };
|
|
123
|
+
const thinking = splitThinkingSuffix(text);
|
|
124
|
+
if (thinking) {
|
|
125
|
+
const inner = resolveText(thinking.base, request, pool, usable);
|
|
126
|
+
if (inner.status === "not-found")
|
|
127
|
+
return inner;
|
|
128
|
+
// Only use this thinking level if no warning from inner recursion
|
|
129
|
+
return { ...inner, thinkingLevel: inner.warning ? undefined : thinking.thinkingLevel };
|
|
130
|
+
}
|
|
131
|
+
// Keep an invalid suffix as part of the id and fail, rather than resolve a different model
|
|
132
|
+
if (request.thinkingSuffix === "strict")
|
|
133
|
+
return { status: "not-found" };
|
|
134
|
+
const colonIndex = text.lastIndexOf(":");
|
|
135
|
+
if (colonIndex === -1)
|
|
136
|
+
return { status: "not-found" };
|
|
137
|
+
const suffix = text.substring(colonIndex + 1);
|
|
138
|
+
const inner = resolveText(text.substring(0, colonIndex), request, pool, usable);
|
|
139
|
+
if (inner.status === "not-found")
|
|
140
|
+
return inner;
|
|
141
|
+
return {
|
|
142
|
+
...inner,
|
|
143
|
+
thinkingLevel: undefined,
|
|
144
|
+
warning: `Invalid thinking level "${suffix}" in pattern "${text}". Using default instead.`,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* `provider/rest` is only a hint: the whole text may also be a model id on another provider, such as
|
|
149
|
+
* gateway id `zai/glm-5` or commandcode id `xiaomi/mimo-v2.5-pro`. The named provider wins when usable,
|
|
150
|
+
* since that is what the syntax usually means; otherwise a sole usable raw match wins, since the named
|
|
151
|
+
* provider could not serve the request. An unusable named match is still preferred over unusable raw
|
|
152
|
+
* matches, so `--api-key` can set up the named provider.
|
|
153
|
+
*/
|
|
154
|
+
function selectReference(text, pool, fuzzy, usable) {
|
|
155
|
+
const lowerText = text.toLowerCase();
|
|
156
|
+
const raw = pool.filter((model) => model.id.toLowerCase() === lowerText);
|
|
157
|
+
const split = splitProviderPrefix(text, pool);
|
|
158
|
+
let named;
|
|
159
|
+
if (split) {
|
|
160
|
+
const providerModels = pool.filter((model) => model.provider === split.provider);
|
|
161
|
+
const lowerModelText = split.modelText.toLowerCase();
|
|
162
|
+
// The provider's own literal id (OpenRouter's `openrouter/free`) beats its fuzzy matches
|
|
163
|
+
named =
|
|
164
|
+
providerModels.find((model) => model.id.toLowerCase() === lowerModelText) ??
|
|
165
|
+
raw.find((model) => model.provider === split.provider) ??
|
|
166
|
+
(fuzzy ? bestFuzzyMatch(fuzzyMatches(split.modelText, providerModels)) : undefined);
|
|
167
|
+
}
|
|
168
|
+
const others = raw.filter((model) => model !== named);
|
|
169
|
+
const candidates = named ? [named, ...others] : others;
|
|
170
|
+
if (candidates.length === 0)
|
|
116
171
|
return undefined;
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
// No alias found, pick latest dated version
|
|
128
|
-
datedVersions.sort((a, b) => b.id.localeCompare(a.id));
|
|
129
|
-
return datedVersions[0];
|
|
130
|
-
}
|
|
172
|
+
if (new Set(candidates.map((model) => model.provider)).size === 1)
|
|
173
|
+
return { status: "resolved", model: candidates[0] };
|
|
174
|
+
if (named && usable(named.provider))
|
|
175
|
+
return { status: "resolved", model: named };
|
|
176
|
+
const usableOthers = others.filter((model) => usable(model.provider));
|
|
177
|
+
if (usableOthers.length === 1)
|
|
178
|
+
return { status: "resolved", model: usableOthers[0] };
|
|
179
|
+
if (usableOthers.length === 0 && named)
|
|
180
|
+
return { status: "resolved", model: named };
|
|
181
|
+
return { status: "ambiguous", candidates, usableCount: usableOthers.length };
|
|
131
182
|
}
|
|
132
|
-
function
|
|
133
|
-
const
|
|
134
|
-
|
|
183
|
+
function fuzzyMatches(text, models) {
|
|
184
|
+
const lowerText = text.toLowerCase();
|
|
185
|
+
return models.filter((model) => model.id.toLowerCase().includes(lowerText) || model.name?.toLowerCase().includes(lowerText));
|
|
186
|
+
}
|
|
187
|
+
function selectFuzzy(matches, usable) {
|
|
188
|
+
if (matches.length === 0)
|
|
189
|
+
return undefined;
|
|
190
|
+
const multipleProviders = new Set(matches.map((model) => model.provider)).size > 1;
|
|
191
|
+
const usableMatches = multipleProviders ? matches.filter((model) => usable(model.provider)) : [];
|
|
192
|
+
const pool = usableMatches.length > 0 ? usableMatches : matches;
|
|
193
|
+
const best = bestFuzzyMatch(pool);
|
|
194
|
+
if (!best)
|
|
135
195
|
return undefined;
|
|
136
|
-
|
|
196
|
+
// The same id on several providers would otherwise be decided by catalog order
|
|
197
|
+
const tied = pool.filter((model) => model.id === best.id);
|
|
198
|
+
if (new Set(tied.map((model) => model.provider)).size === 1)
|
|
199
|
+
return { status: "resolved", model: best };
|
|
200
|
+
return {
|
|
201
|
+
status: "ambiguous",
|
|
202
|
+
candidates: tied,
|
|
203
|
+
usableCount: usableMatches.length > 0 ? tied.length : 0,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
/** Prefer aliases (`claude-sonnet-4-5`) over dated versions (`claude-sonnet-4-5-20250929`), then the latest. */
|
|
207
|
+
function bestFuzzyMatch(matches) {
|
|
208
|
+
const aliases = matches.filter((model) => isAlias(model.id));
|
|
209
|
+
return [...(aliases.length > 0 ? aliases : matches)].sort((a, b) => b.id.localeCompare(a.id))[0];
|
|
210
|
+
}
|
|
211
|
+
function isAlias(id) {
|
|
212
|
+
return id.endsWith("-latest") || !/-\d{8}$/.test(id);
|
|
213
|
+
}
|
|
214
|
+
function buildFallbackModel(providerModels, modelId) {
|
|
215
|
+
const defaultId = defaultModelPerProvider[providerModels[0].provider];
|
|
137
216
|
const baseModel = defaultId
|
|
138
217
|
? (providerModels.find((m) => m.id === defaultId) ?? providerModels[0])
|
|
139
218
|
: providerModels[0];
|
|
@@ -144,129 +223,70 @@ function buildFallbackModel(provider, modelId, availableModels) {
|
|
|
144
223
|
};
|
|
145
224
|
}
|
|
146
225
|
/**
|
|
147
|
-
*
|
|
148
|
-
* Handles models with colons in their IDs (e.g., OpenRouter's :exacto suffix).
|
|
226
|
+
* Resolve scope patterns (`--models`, `enabledModels`) to models with optional thinking levels.
|
|
149
227
|
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
* 2. If found, return it with "off" thinking level
|
|
153
|
-
* 3. If not found and has colons, split on last colon:
|
|
154
|
-
* - If suffix is valid thinking level, use it and recurse on prefix
|
|
155
|
-
* - If suffix is invalid, warn and recurse on prefix with "off"
|
|
156
|
-
*
|
|
157
|
-
* @internal Exported for testing
|
|
228
|
+
* Every model in `models` is usable, so credentials cannot choose between providers offering the same
|
|
229
|
+
* id. All of them are added, with a warning so the user can pick one with `provider/id`.
|
|
158
230
|
*/
|
|
159
|
-
export function parseModelPattern(pattern, availableModels, options) {
|
|
160
|
-
// Try exact match first
|
|
161
|
-
const exactMatch = tryMatchModel(pattern, availableModels);
|
|
162
|
-
if (exactMatch) {
|
|
163
|
-
return { model: exactMatch, thinkingLevel: undefined, warning: undefined };
|
|
164
|
-
}
|
|
165
|
-
// No match - try splitting on last colon if present
|
|
166
|
-
const lastColonIndex = pattern.lastIndexOf(":");
|
|
167
|
-
if (lastColonIndex === -1) {
|
|
168
|
-
// No colons, pattern simply doesn't match any model
|
|
169
|
-
return { model: undefined, thinkingLevel: undefined, warning: undefined };
|
|
170
|
-
}
|
|
171
|
-
const prefix = pattern.substring(0, lastColonIndex);
|
|
172
|
-
const suffix = pattern.substring(lastColonIndex + 1);
|
|
173
|
-
if (isValidThinkingLevel(suffix)) {
|
|
174
|
-
// Valid thinking level - recurse on prefix and use this level
|
|
175
|
-
const result = parseModelPattern(prefix, availableModels, options);
|
|
176
|
-
if (result.model) {
|
|
177
|
-
// Only use this thinking level if no warning from inner recursion
|
|
178
|
-
return {
|
|
179
|
-
model: result.model,
|
|
180
|
-
thinkingLevel: result.warning ? undefined : suffix,
|
|
181
|
-
warning: result.warning,
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
return result;
|
|
185
|
-
}
|
|
186
|
-
else {
|
|
187
|
-
// Invalid suffix
|
|
188
|
-
const allowFallback = options?.allowInvalidThinkingLevelFallback ?? true;
|
|
189
|
-
if (!allowFallback) {
|
|
190
|
-
// In strict mode (CLI --model parsing), treat it as part of the model id and fail.
|
|
191
|
-
// This avoids accidentally resolving to a different model.
|
|
192
|
-
return { model: undefined, thinkingLevel: undefined, warning: undefined };
|
|
193
|
-
}
|
|
194
|
-
// Scope mode: recurse on prefix and warn
|
|
195
|
-
const result = parseModelPattern(prefix, availableModels, options);
|
|
196
|
-
if (result.model) {
|
|
197
|
-
return {
|
|
198
|
-
model: result.model,
|
|
199
|
-
thinkingLevel: undefined,
|
|
200
|
-
warning: `Invalid thinking level "${suffix}" in pattern "${pattern}". Using default instead.`,
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
return result;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
231
|
export function resolveModelScopeFromModels(patterns, models) {
|
|
207
|
-
const availableModels = [...models];
|
|
208
232
|
const scopedModels = [];
|
|
209
233
|
const diagnostics = [];
|
|
234
|
+
const add = (model, thinkingLevel) => {
|
|
235
|
+
if (!scopedModels.some((scoped) => modelsAreEqual(scoped.model, model))) {
|
|
236
|
+
scopedModels.push({ model, thinkingLevel });
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
const noMatch = (pattern) => diagnostics.push({ type: "warning", code: "no-match", message: `No models match pattern "${pattern}"`, pattern });
|
|
240
|
+
const ambiguous = (pattern, candidates) => {
|
|
241
|
+
const providers = [...new Set(candidates.map((m) => m.provider))].sort((a, b) => a.localeCompare(b));
|
|
242
|
+
diagnostics.push({
|
|
243
|
+
type: "warning",
|
|
244
|
+
code: "ambiguous",
|
|
245
|
+
message: `Pattern "${pattern}" matches several providers: ${providers.join(", ")}. Use provider/id to choose one.`,
|
|
246
|
+
pattern,
|
|
247
|
+
});
|
|
248
|
+
};
|
|
210
249
|
for (const pattern of patterns) {
|
|
211
250
|
// Check if pattern contains glob characters
|
|
212
251
|
if (pattern.includes("*") || pattern.includes("?") || pattern.includes("[")) {
|
|
213
252
|
// Extract optional thinking level suffix (e.g., "provider/*:high")
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
if (exactMatch) {
|
|
226
|
-
if (!scopedModels.find((sm) => modelsAreEqual(sm.model, exactMatch))) {
|
|
227
|
-
scopedModels.push({ model: exactMatch, thinkingLevel });
|
|
228
|
-
}
|
|
229
|
-
continue;
|
|
253
|
+
const thinking = splitThinkingSuffix(pattern);
|
|
254
|
+
const globPattern = thinking?.base ?? pattern;
|
|
255
|
+
const thinkingLevel = thinking?.thinkingLevel;
|
|
256
|
+
// Ids such as `bracketed-model[1m]` are not globs
|
|
257
|
+
const exact = resolveModelReference({ text: globPattern, thinkingSuffix: "none", fuzzy: false }, models, () => true);
|
|
258
|
+
let matches = [];
|
|
259
|
+
if (exact.status === "resolved")
|
|
260
|
+
matches = [exact.model];
|
|
261
|
+
else if (exact.status === "ambiguous") {
|
|
262
|
+
matches = exact.candidates;
|
|
263
|
+
ambiguous(pattern, matches);
|
|
230
264
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
});
|
|
237
|
-
if (matchingModels.length === 0) {
|
|
238
|
-
diagnostics.push({
|
|
239
|
-
type: "warning",
|
|
240
|
-
code: "no-match",
|
|
241
|
-
message: `No models match pattern "${pattern}"`,
|
|
242
|
-
pattern,
|
|
243
|
-
});
|
|
244
|
-
continue;
|
|
245
|
-
}
|
|
246
|
-
for (const model of matchingModels) {
|
|
247
|
-
if (!scopedModels.find((sm) => modelsAreEqual(sm.model, model))) {
|
|
248
|
-
scopedModels.push({ model, thinkingLevel });
|
|
249
|
-
}
|
|
265
|
+
else {
|
|
266
|
+
// Match against "provider/modelId" format OR just model ID
|
|
267
|
+
// This allows "*sonnet*" to match without requiring "anthropic/*sonnet*"
|
|
268
|
+
matches = models.filter((m) => minimatch(`${m.provider}/${m.id}`, globPattern, { nocase: true }) ||
|
|
269
|
+
minimatch(m.id, globPattern, { nocase: true }));
|
|
250
270
|
}
|
|
271
|
+
if (matches.length === 0)
|
|
272
|
+
noMatch(pattern);
|
|
273
|
+
for (const model of matches)
|
|
274
|
+
add(model, thinkingLevel);
|
|
251
275
|
continue;
|
|
252
276
|
}
|
|
253
|
-
const {
|
|
254
|
-
if (
|
|
255
|
-
|
|
256
|
-
}
|
|
257
|
-
if (!model) {
|
|
258
|
-
diagnostics.push({
|
|
259
|
-
type: "warning",
|
|
260
|
-
code: "no-match",
|
|
261
|
-
message: `No models match pattern "${pattern}"`,
|
|
262
|
-
pattern,
|
|
263
|
-
});
|
|
277
|
+
const result = resolveModelReference({ text: pattern, thinkingSuffix: "lenient", fuzzy: true }, models, () => true);
|
|
278
|
+
if (result.status === "not-found") {
|
|
279
|
+
noMatch(pattern);
|
|
264
280
|
continue;
|
|
265
281
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
scopedModels.push({ model, thinkingLevel });
|
|
282
|
+
if (result.warning) {
|
|
283
|
+
diagnostics.push({ type: "warning", code: "invalid-thinking-level", message: result.warning, pattern });
|
|
269
284
|
}
|
|
285
|
+
if (result.status === "ambiguous")
|
|
286
|
+
ambiguous(pattern, result.candidates);
|
|
287
|
+
const matches = result.status === "resolved" ? [result.model] : result.candidates;
|
|
288
|
+
for (const model of matches)
|
|
289
|
+
add(model, result.thinkingLevel);
|
|
270
290
|
}
|
|
271
291
|
return { scopedModels, diagnostics };
|
|
272
292
|
}
|
|
@@ -292,26 +312,23 @@ export async function resolveModelScope(patterns, modelRuntime, options) {
|
|
|
292
312
|
* return a thinking level from "<pattern>:<thinking>" so the caller can apply it.
|
|
293
313
|
*/
|
|
294
314
|
export function resolveCliModel(options) {
|
|
295
|
-
const { cliProvider, cliModel, cliThinking, modelRuntime } = options;
|
|
315
|
+
const { cliProvider, cliModel, cliThinking, inlineApiKey, modelRuntime } = options;
|
|
296
316
|
if (!cliModel) {
|
|
297
317
|
return { model: undefined, warning: undefined, error: undefined };
|
|
298
318
|
}
|
|
299
319
|
// Important: use *all* models here, not just models with pre-configured auth.
|
|
300
320
|
// This allows "--api-key" to be used for first-time setup.
|
|
301
|
-
const
|
|
302
|
-
if (
|
|
321
|
+
const models = [...modelRuntime.getModels()];
|
|
322
|
+
if (models.length === 0) {
|
|
303
323
|
return {
|
|
304
324
|
model: undefined,
|
|
305
325
|
warning: undefined,
|
|
306
326
|
error: "No models available. Check your installation or add models to models.json.",
|
|
307
327
|
};
|
|
308
328
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
providerMap.set(m.provider.toLowerCase(), m.provider);
|
|
313
|
-
}
|
|
314
|
-
let provider = cliProvider ? providerMap.get(cliProvider.toLowerCase()) : undefined;
|
|
329
|
+
const provider = cliProvider
|
|
330
|
+
? models.find((m) => m.provider.toLowerCase() === cliProvider.toLowerCase())?.provider
|
|
331
|
+
: undefined;
|
|
315
332
|
if (cliProvider && !provider) {
|
|
316
333
|
return {
|
|
317
334
|
model: undefined,
|
|
@@ -319,183 +336,61 @@ export function resolveCliModel(options) {
|
|
|
319
336
|
error: `Unknown provider "${cliProvider}". Use --list-models to see available providers/models.`,
|
|
320
337
|
};
|
|
321
338
|
}
|
|
322
|
-
|
|
323
|
-
//
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
pattern = cliModel.substring(slashIndex + 1);
|
|
337
|
-
inferredProvider = true;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
// If no provider was inferred from the slash, try exact matches without provider inference.
|
|
342
|
-
// This handles models whose IDs naturally contain slashes (e.g. OpenRouter-style IDs).
|
|
343
|
-
// Bare exact IDs can exist in multiple providers, so do not choose by catalog order.
|
|
344
|
-
// Prefer the sole authenticated provider when there is one; otherwise require an
|
|
345
|
-
// explicit provider to avoid silently selecting an unusable provider.
|
|
346
|
-
if (!provider) {
|
|
347
|
-
const lower = cliModel.toLowerCase();
|
|
348
|
-
const exactMatches = availableModels.filter((m) => m.id.toLowerCase() === lower || `${m.provider}/${m.id}`.toLowerCase() === lower);
|
|
349
|
-
if (exactMatches.length === 1) {
|
|
350
|
-
return { model: exactMatches[0], warning: undefined, thinkingLevel: undefined, error: undefined };
|
|
351
|
-
}
|
|
352
|
-
if (exactMatches.length > 1) {
|
|
353
|
-
const authenticatedExactMatches = exactMatches.filter((m) => modelRuntime.hasConfiguredAuth(m.provider));
|
|
354
|
-
if (authenticatedExactMatches.length === 1) {
|
|
355
|
-
return {
|
|
356
|
-
model: authenticatedExactMatches[0],
|
|
357
|
-
warning: undefined,
|
|
358
|
-
thinkingLevel: undefined,
|
|
359
|
-
error: undefined,
|
|
360
|
-
};
|
|
361
|
-
}
|
|
362
|
-
const matches = exactMatches
|
|
363
|
-
.map((m) => `${m.provider}/${m.id}`)
|
|
364
|
-
.sort((a, b) => a.localeCompare(b))
|
|
365
|
-
.join(", ");
|
|
366
|
-
const authHint = authenticatedExactMatches.length === 0
|
|
339
|
+
const result = resolveModelReference({ text: cliModel, provider, thinkingSuffix: "strict", fuzzy: true }, models,
|
|
340
|
+
// An inline key goes to whichever provider is selected, so stored credentials must not choose it
|
|
341
|
+
inlineApiKey ? () => false : (providerId) => modelRuntime.hasConfiguredAuth(providerId));
|
|
342
|
+
if (result.status === "resolved") {
|
|
343
|
+
return { model: result.model, thinkingLevel: result.thinkingLevel, warning: result.warning, error: undefined };
|
|
344
|
+
}
|
|
345
|
+
if (result.status === "ambiguous") {
|
|
346
|
+
const matches = result.candidates
|
|
347
|
+
.map((m) => `${m.provider}/${m.id}`)
|
|
348
|
+
.sort((a, b) => a.localeCompare(b))
|
|
349
|
+
.join(", ");
|
|
350
|
+
const authHint = inlineApiKey
|
|
351
|
+
? "--api-key does not choose a provider."
|
|
352
|
+
: result.usableCount === 0
|
|
367
353
|
? "No matching provider is authenticated."
|
|
368
354
|
: "More than one matching provider is authenticated.";
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
};
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
if (cliProvider && provider) {
|
|
378
|
-
const exactModel = availableModels.find((model) => model.provider === provider && model.id.toLowerCase() === cliModel.toLowerCase());
|
|
379
|
-
if (exactModel) {
|
|
380
|
-
return { model: exactModel, warning: undefined, thinkingLevel: undefined, error: undefined };
|
|
381
|
-
}
|
|
382
|
-
// If both were provided, tolerate --model <provider>/<pattern> by stripping the provider prefix
|
|
383
|
-
const prefix = `${provider}/`;
|
|
384
|
-
if (cliModel.toLowerCase().startsWith(prefix.toLowerCase())) {
|
|
385
|
-
pattern = cliModel.substring(prefix.length);
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
const candidates = provider ? availableModels.filter((m) => m.provider === provider) : availableModels;
|
|
389
|
-
const { model, thinkingLevel, warning } = parseModelPattern(pattern, candidates, {
|
|
390
|
-
allowInvalidThinkingLevelFallback: false,
|
|
391
|
-
});
|
|
392
|
-
if (model) {
|
|
393
|
-
// If provider inference matched an unauthenticated provider/model pair, prefer
|
|
394
|
-
// one exact raw model-id match that is authenticated. This keeps
|
|
395
|
-
// "provider/model" syntax preferred when usable, but handles models whose
|
|
396
|
-
// literal id starts with a known provider name (for example
|
|
397
|
-
// commandcode model id "xiaomi/mimo-v2.5-pro").
|
|
398
|
-
if (inferredProvider) {
|
|
399
|
-
const rawExactMatches = availableModels.filter((m) => m.id.toLowerCase() === cliModel.toLowerCase() && !modelsAreEqual(m, model));
|
|
400
|
-
if (rawExactMatches.length > 0 && !modelRuntime.hasConfiguredAuth(model.provider)) {
|
|
401
|
-
const authenticatedRawMatches = rawExactMatches.filter((m) => modelRuntime.hasConfiguredAuth(m.provider));
|
|
402
|
-
if (authenticatedRawMatches.length === 1) {
|
|
403
|
-
return {
|
|
404
|
-
model: authenticatedRawMatches[0],
|
|
405
|
-
thinkingLevel: undefined,
|
|
406
|
-
warning: undefined,
|
|
407
|
-
error: undefined,
|
|
408
|
-
};
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
return { model, thinkingLevel, warning, error: undefined };
|
|
413
|
-
}
|
|
414
|
-
// If we inferred a provider from the slash but found no match within that provider,
|
|
415
|
-
// fall back to matching the full input as a raw model id across all models.
|
|
416
|
-
// This handles OpenRouter-style IDs like "openai/gpt-4o:extended" where "openai"
|
|
417
|
-
// looks like a provider but the full string is actually a model id on openrouter.
|
|
418
|
-
if (inferredProvider) {
|
|
419
|
-
const lower = cliModel.toLowerCase();
|
|
420
|
-
const exact = availableModels.find((m) => m.id.toLowerCase() === lower || `${m.provider}/${m.id}`.toLowerCase() === lower);
|
|
421
|
-
if (exact) {
|
|
422
|
-
return { model: exact, warning: undefined, thinkingLevel: undefined, error: undefined };
|
|
423
|
-
}
|
|
424
|
-
// Also try parseModelPattern on the full input against all models
|
|
425
|
-
const fallback = parseModelPattern(cliModel, availableModels, {
|
|
426
|
-
allowInvalidThinkingLevelFallback: false,
|
|
427
|
-
});
|
|
428
|
-
if (fallback.model) {
|
|
429
|
-
return {
|
|
430
|
-
model: fallback.model,
|
|
431
|
-
thinkingLevel: fallback.thinkingLevel,
|
|
432
|
-
warning: fallback.warning,
|
|
433
|
-
error: undefined,
|
|
434
|
-
};
|
|
435
|
-
}
|
|
355
|
+
return {
|
|
356
|
+
model: undefined,
|
|
357
|
+
warning: undefined,
|
|
358
|
+
error: `Model "${cliModel}" is ambiguous across providers: ${matches}. ${authHint} Use --provider or provider/model.`,
|
|
359
|
+
};
|
|
436
360
|
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
const lastColon = pattern.lastIndexOf(":");
|
|
445
|
-
if (lastColon !== -1) {
|
|
446
|
-
const suffix = pattern.substring(lastColon + 1);
|
|
447
|
-
if (isValidThinkingLevel(suffix)) {
|
|
448
|
-
fallbackPattern = pattern.substring(0, lastColon);
|
|
449
|
-
fallbackThinking = suffix;
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
const fallbackModel = buildFallbackModel(provider, fallbackPattern, availableModels);
|
|
454
|
-
if (fallbackModel) {
|
|
455
|
-
const requestedThinking = cliThinking ?? fallbackThinking;
|
|
456
|
-
const model = requestedThinking && requestedThinking !== "off" ? { ...fallbackModel, reasoning: true } : fallbackModel;
|
|
457
|
-
const fallbackWarning = warning
|
|
458
|
-
? `${warning} Model "${fallbackPattern}" not found for provider "${provider}". Using custom model id.`
|
|
459
|
-
: `Model "${fallbackPattern}" not found for provider "${provider}". Using custom model id.`;
|
|
460
|
-
return { model, thinkingLevel: fallbackThinking, warning: fallbackWarning, error: undefined };
|
|
461
|
-
}
|
|
361
|
+
const { target } = result;
|
|
362
|
+
if (!target) {
|
|
363
|
+
return {
|
|
364
|
+
model: undefined,
|
|
365
|
+
warning: undefined,
|
|
366
|
+
error: `Model "${cliModel}" not found. Use --list-models to see available models.`,
|
|
367
|
+
};
|
|
462
368
|
}
|
|
463
|
-
|
|
369
|
+
// Use the thinking level suffix only when --thinking is not explicitly provided; otherwise it
|
|
370
|
+
// stays part of the custom model id.
|
|
371
|
+
// e.g. "zai-org/GLM-5.1-FP8:high" → modelId="zai-org/GLM-5.1-FP8", fallbackThinking="high"
|
|
372
|
+
const modelId = cliThinking ? target.modelText : target.modelId;
|
|
373
|
+
const fallbackThinking = cliThinking ? undefined : target.thinkingLevel;
|
|
374
|
+
const fallbackModel = buildFallbackModel(target.providerModels, modelId);
|
|
375
|
+
const requestedThinking = cliThinking ?? fallbackThinking;
|
|
464
376
|
return {
|
|
465
|
-
model:
|
|
466
|
-
thinkingLevel:
|
|
467
|
-
warning
|
|
468
|
-
error:
|
|
377
|
+
model: requestedThinking && requestedThinking !== "off" ? { ...fallbackModel, reasoning: true } : fallbackModel,
|
|
378
|
+
thinkingLevel: fallbackThinking,
|
|
379
|
+
warning: `Model "${modelId}" not found for provider "${target.provider}". Using custom model id.`,
|
|
380
|
+
error: undefined,
|
|
469
381
|
};
|
|
470
382
|
}
|
|
471
383
|
/**
|
|
472
384
|
* Find the initial model to use based on priority:
|
|
473
|
-
* 1.
|
|
474
|
-
* 2.
|
|
475
|
-
* 3.
|
|
476
|
-
* 4. Saved default from settings
|
|
477
|
-
* 5. First available model with valid API key
|
|
385
|
+
* 1. First model from scoped models (if not continuing/resuming)
|
|
386
|
+
* 2. Saved default from settings
|
|
387
|
+
* 3. First available model with valid API key
|
|
478
388
|
*/
|
|
479
389
|
export async function findInitialModel(options) {
|
|
480
|
-
const {
|
|
390
|
+
const { scopedModels, isContinuing, defaultProvider, defaultModelId, defaultThinkingLevel, modelThinkingLevels, modelRuntime, } = options;
|
|
481
391
|
let model;
|
|
482
392
|
let thinkingLevel = DEFAULT_THINKING_LEVEL;
|
|
483
|
-
// 1.
|
|
484
|
-
if (cliProvider && cliModel) {
|
|
485
|
-
const resolved = resolveCliModel({
|
|
486
|
-
cliProvider,
|
|
487
|
-
cliModel,
|
|
488
|
-
modelRuntime,
|
|
489
|
-
});
|
|
490
|
-
if (resolved.error) {
|
|
491
|
-
console.error(chalk.red(resolved.error));
|
|
492
|
-
process.exit(1);
|
|
493
|
-
}
|
|
494
|
-
if (resolved.model) {
|
|
495
|
-
return { model: resolved.model, thinkingLevel: DEFAULT_THINKING_LEVEL, fallbackMessage: undefined };
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
// 2. Use first model from scoped models (skip if continuing/resuming)
|
|
393
|
+
// 1. Use first model from scoped models (skip if continuing/resuming)
|
|
499
394
|
if (scopedModels.length > 0 && !isContinuing) {
|
|
500
395
|
const scopedModel = scopedModels[0];
|
|
501
396
|
const perModel = modelThinkingLevels?.[`${scopedModel.model.provider}/${scopedModel.model.id}`];
|
|
@@ -505,7 +400,7 @@ export async function findInitialModel(options) {
|
|
|
505
400
|
fallbackMessage: undefined,
|
|
506
401
|
};
|
|
507
402
|
}
|
|
508
|
-
//
|
|
403
|
+
// 2. Try saved default from settings if auth is configured.
|
|
509
404
|
if (defaultProvider && defaultModelId) {
|
|
510
405
|
const found = modelRuntime.getModel(defaultProvider, defaultModelId);
|
|
511
406
|
if (found && modelRuntime.hasConfiguredAuth(found.provider)) {
|
|
@@ -520,7 +415,7 @@ export async function findInitialModel(options) {
|
|
|
520
415
|
return { model, thinkingLevel, fallbackMessage: undefined };
|
|
521
416
|
}
|
|
522
417
|
}
|
|
523
|
-
//
|
|
418
|
+
// 3. Try first available model with valid API key
|
|
524
419
|
const availableModels = [...modelRuntime.getAvailableSnapshot()];
|
|
525
420
|
if (availableModels.length > 0) {
|
|
526
421
|
// Try to find a default model from known providers
|
|
@@ -534,7 +429,7 @@ export async function findInitialModel(options) {
|
|
|
534
429
|
// If no default found, use first available
|
|
535
430
|
return { model: availableModels[0], thinkingLevel: DEFAULT_THINKING_LEVEL, fallbackMessage: undefined };
|
|
536
431
|
}
|
|
537
|
-
//
|
|
432
|
+
// 4. No model found
|
|
538
433
|
return { model: undefined, thinkingLevel: DEFAULT_THINKING_LEVEL, fallbackMessage: undefined };
|
|
539
434
|
}
|
|
540
435
|
/**
|