@orion-agents/orion-code 0.3.65 → 0.4.3
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 +128 -2
- package/README.md +78 -361
- package/README.zh-CN.md +71 -263
- package/bin/orion +4 -1
- package/dist/acp/session-updates.d.ts +34 -0
- package/dist/acp/session-updates.js +162 -0
- package/dist/acp/sessions.d.ts +32 -0
- package/dist/acp/sessions.js +315 -0
- package/dist/acp/stdio.d.ts +3 -0
- package/dist/acp/stdio.js +59 -0
- package/dist/cli.js +136 -185
- package/dist/commands/context-tool-command-handlers.d.ts +1 -1
- package/dist/commands/context-tool-command-handlers.js +24 -3
- package/dist/commands/core-command-handlers.js +5 -1
- package/dist/commands/diagnostic-command-handlers.js +20 -6
- package/dist/commands/diagnostic-commands.js +0 -12
- package/dist/commands/init-command.d.ts +3 -0
- package/dist/commands/init-command.js +131 -0
- package/dist/commands/model-command-handlers.d.ts +1 -2
- package/dist/commands/model-command-handlers.js +15 -100
- package/dist/commands/model-commands.js +0 -11
- package/dist/commands/registry.js +0 -18
- package/dist/commands/rsi-command.d.ts +2 -0
- package/dist/commands/rsi-command.js +180 -0
- package/dist/commands/session-command-handlers.js +28 -19
- package/dist/commands/system-commands.js +0 -1
- package/dist/commands/tool-commands.js +1 -1
- package/dist/commands/types.d.ts +4 -10
- package/dist/commands/types.js +1 -21
- package/dist/commands/workflow-command-handlers.js +13 -4
- package/dist/framework/loop-budget-contract.d.ts +7 -2
- package/dist/framework/loop-budget-contract.js +4 -1
- package/dist/framework/loop-progress.d.ts +22 -0
- package/dist/framework/loop-progress.js +79 -0
- package/dist/framework/prompt.d.ts +0 -2
- package/dist/framework/prompt.js +9 -27
- package/dist/framework/query.d.ts +27 -20
- package/dist/framework/query.js +453 -153
- package/dist/framework/store.d.ts +6 -10
- package/dist/framework/store.js +2 -21
- package/dist/framework/tool-call-orchestrator.d.ts +7 -0
- package/dist/framework/tool-call-orchestrator.js +8 -3
- package/dist/framework/tool-state.d.ts +2 -0
- package/dist/framework/tool.d.ts +0 -23
- package/dist/framework/verification-command.d.ts +15 -0
- package/dist/framework/verification-command.js +32 -0
- package/dist/harness/assembler.d.ts +1 -0
- package/dist/harness/assembler.js +24 -0
- package/dist/harness/capsule.d.ts +1 -1
- package/dist/harness/capsule.js +33 -14
- package/dist/harness/context-harness.d.ts +31 -12
- package/dist/harness/context-harness.js +491 -35
- package/dist/harness/contract.js +1 -1
- package/dist/harness/drift-guard.d.ts +4 -0
- package/dist/harness/drift-guard.js +68 -16
- package/dist/harness/intent.js +21 -0
- package/dist/harness/ledger.d.ts +6 -11
- package/dist/harness/ledger.js +39 -9
- package/dist/harness/progress-controller.d.ts +12 -7
- package/dist/harness/progress-controller.js +66 -21
- package/dist/harness/state.js +9 -1
- package/dist/harness/task-checklist.d.ts +16 -0
- package/dist/harness/task-checklist.js +95 -0
- package/dist/harness/types.d.ts +73 -1
- package/dist/harness/verification.d.ts +19 -1
- package/dist/harness/verification.js +116 -29
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -3
- package/dist/print-ui/event-stream.d.ts +38 -0
- package/dist/print-ui/event-stream.js +187 -0
- package/dist/print-ui/launch.d.ts +12 -1
- package/dist/print-ui/launch.js +173 -11
- package/dist/product/environment.d.ts +1 -1
- package/dist/product/environment.js +1 -1
- package/dist/product/identity.d.ts +1 -1
- package/dist/product/identity.js +1 -1
- package/dist/product/paths.d.ts +3 -2
- package/dist/product/paths.js +6 -2
- package/dist/runtime/agent-loop.d.ts +11 -2
- package/dist/runtime/agent-loop.js +165 -25
- package/dist/runtime/agent-runtime-controller.d.ts +13 -3
- package/dist/runtime/agent-runtime-controller.js +347 -183
- package/dist/runtime/agent-runtime-protocol.d.ts +10 -18
- package/dist/runtime/agent-runtime-runner.d.ts +10 -0
- package/dist/runtime/builtin-tool-provider.js +5 -1
- package/dist/runtime/capability-receipt-journal.js +1 -0
- package/dist/runtime/durable-tool-receipt-reader.js +2 -1
- package/dist/runtime/first-party-tool-services.d.ts +1 -0
- package/dist/runtime/first-party-tool-services.js +2 -12
- package/dist/runtime/first-party-tool-universe.d.ts +1 -0
- package/dist/runtime/first-party-tool-universe.js +1 -1
- package/dist/runtime/followup-queue-store.d.ts +16 -0
- package/dist/runtime/followup-queue-store.js +75 -0
- package/dist/runtime/goal-lifecycle-v2.d.ts +11 -1
- package/dist/runtime/goal-lifecycle-v2.js +85 -15
- package/dist/runtime/goal-runtime-coordinator.d.ts +10 -1
- package/dist/runtime/goal-runtime-coordinator.js +81 -24
- package/dist/runtime/loop-budget.js +7 -5
- package/dist/runtime/mcp/first-party-mcp-adapter.d.ts +2 -0
- package/dist/runtime/mcp/first-party-mcp-adapter.js +23 -19
- package/dist/runtime/model-coordinator.js +2 -5
- package/dist/runtime/orion-runtime-v1.d.ts +18 -2
- package/dist/runtime/orion-runtime-v1.js +135 -39
- package/dist/runtime/orion-session-runner.d.ts +7 -0
- package/dist/runtime/orion-session-runner.js +82 -0
- package/dist/runtime/plan-review.d.ts +1 -0
- package/dist/runtime/plan-review.js +8 -4
- package/dist/runtime/product-bootstrap.d.ts +6 -0
- package/dist/runtime/product-bootstrap.js +41 -51
- package/dist/runtime/product-orion-runtime.js +128 -52
- package/dist/runtime/release-receipts.d.ts +24 -124
- package/dist/runtime/release-receipts.js +129 -683
- package/dist/runtime/rich-text/layout.js +108 -65
- package/dist/runtime/rsi/contracts.d.ts +50 -0
- package/dist/runtime/rsi/contracts.js +17 -0
- package/dist/runtime/rsi/diagnosis.d.ts +46 -0
- package/dist/runtime/rsi/diagnosis.js +98 -0
- package/dist/runtime/rsi/evaluation-suite.d.ts +25 -0
- package/dist/runtime/rsi/evaluation-suite.js +141 -0
- package/dist/runtime/rsi/evaluation-worker.d.ts +19 -0
- package/dist/runtime/rsi/evaluation-worker.js +64 -0
- package/dist/runtime/rsi/evaluation.d.ts +49 -0
- package/dist/runtime/rsi/evaluation.js +351 -0
- package/dist/runtime/rsi/lifecycle.d.ts +54 -0
- package/dist/runtime/rsi/lifecycle.js +279 -0
- package/dist/runtime/rsi/proposal.d.ts +39 -0
- package/dist/runtime/rsi/proposal.js +312 -0
- package/dist/runtime/rsi/receipt.d.ts +28 -0
- package/dist/runtime/rsi/receipt.js +138 -0
- package/dist/runtime/rsi/skill-state.d.ts +7 -0
- package/dist/runtime/rsi/skill-state.js +50 -0
- package/dist/runtime/rsi/trajectory.d.ts +19 -0
- package/dist/runtime/rsi/trajectory.js +314 -0
- package/dist/runtime/rsi/triage.d.ts +274 -0
- package/dist/runtime/rsi/triage.js +58 -0
- package/dist/runtime/session-composer-control.d.ts +5 -24
- package/dist/runtime/session-composer-control.js +27 -189
- package/dist/runtime/step-snapshot.d.ts +1 -0
- package/dist/runtime/subagents/policy.js +0 -1
- package/dist/runtime/subagents/production.js +1 -1
- package/dist/runtime/subagents/runtime-integration.js +2 -4
- package/dist/runtime/subagents/types.d.ts +0 -5
- package/dist/runtime/subagents/types.js +0 -2
- package/dist/runtime/task-context-recovery.d.ts +55 -0
- package/dist/runtime/task-context-recovery.js +342 -0
- package/dist/runtime/task-context-service.d.ts +16 -10
- package/dist/runtime/task-context-service.js +35 -4
- package/dist/runtime/thread-admission.d.ts +1 -1
- package/dist/runtime/thread-admission.js +12 -6
- package/dist/runtime/thread-event-store.d.ts +2 -2
- package/dist/runtime/thread-event-store.js +7 -2
- package/dist/runtime/thread-projection.js +4 -2
- package/dist/runtime/thread-runtime.d.ts +7 -0
- package/dist/runtime/thread-runtime.js +43 -0
- package/dist/runtime/thread-session-index.d.ts +8 -0
- package/dist/runtime/thread-session-index.js +50 -1
- package/dist/runtime/thread-session-view.d.ts +2 -1
- package/dist/runtime/thread-session-view.js +4 -0
- package/dist/runtime/thread-tool-journal.d.ts +1 -0
- package/dist/runtime/thread-tool-journal.js +6 -2
- package/dist/runtime/thread-ui-adapter.d.ts +1 -0
- package/dist/runtime/thread-ui-adapter.js +88 -11
- package/dist/runtime/tool-gateway.d.ts +7 -0
- package/dist/runtime/tool-gateway.js +20 -0
- package/dist/runtime/tool-transcript-entry.d.ts +16 -0
- package/dist/runtime/tool-transcript-entry.js +73 -0
- package/dist/runtime/turn-commit.d.ts +4 -1
- package/dist/runtime/turn-commit.js +19 -15
- package/dist/runtime/ui-events.d.ts +12 -0
- package/dist/runtime/ui-view-model.d.ts +6 -5
- package/dist/runtime/ui-view-model.js +33 -19
- package/dist/runtime/workspace-runtime-kernel.js +0 -1
- package/dist/services/atomic-write.d.ts +2 -0
- package/dist/services/atomic-write.js +12 -1
- package/dist/services/code-review/format.d.ts +4 -1
- package/dist/services/code-review/format.js +5 -1
- package/dist/services/code-review/runner.d.ts +2 -2
- package/dist/services/code-review/runner.js +86 -64
- package/dist/services/code-review/snapshot.d.ts +9 -9
- package/dist/services/code-review/snapshot.js +182 -166
- package/dist/services/compact/auto-compact.d.ts +21 -6
- package/dist/services/compact/auto-compact.js +148 -22
- package/dist/services/compact/background-candidate.d.ts +33 -0
- package/dist/services/compact/background-candidate.js +184 -0
- package/dist/services/compact/compact.d.ts +4 -1
- package/dist/services/compact/compact.js +30 -3
- package/dist/services/compact/coordinator.d.ts +10 -4
- package/dist/services/compact/coordinator.js +17 -7
- package/dist/services/compact/summary-generator.d.ts +4 -2
- package/dist/services/compact/summary-generator.js +17 -3
- package/dist/services/config.d.ts +5 -5
- package/dist/services/config.js +30 -45
- package/dist/services/doctor.js +85 -13
- package/dist/services/effort.d.ts +5 -5
- package/dist/services/effort.js +5 -11
- package/dist/services/file-lock.d.ts +9 -3
- package/dist/services/file-lock.js +92 -26
- package/dist/services/global-config.d.ts +26 -56
- package/dist/services/global-config.js +213 -183
- package/dist/services/llm.d.ts +40 -4
- package/dist/services/llm.js +164 -45
- package/dist/services/model-client-pool.d.ts +15 -9
- package/dist/services/model-client-pool.js +62 -33
- package/dist/services/model-context.d.ts +2 -1
- package/dist/services/model-context.js +15 -9
- package/dist/services/model-registry.d.ts +4 -15
- package/dist/services/model-registry.js +32 -101
- package/dist/services/provider-diagnostics.d.ts +7 -0
- package/dist/services/provider-diagnostics.js +9 -10
- package/dist/services/provider-resilience/coordinator.d.ts +1 -1
- package/dist/services/provider-resilience/coordinator.js +10 -6
- package/dist/services/provider-resilience/request-gate.d.ts +3 -0
- package/dist/services/provider-resilience/request-gate.js +29 -18
- package/dist/services/provider-resilience/types.d.ts +2 -0
- package/dist/services/session-storage.d.ts +7 -10
- package/dist/services/session-storage.js +57 -30
- package/dist/services/settings-coordinator.d.ts +0 -6
- package/dist/services/settings-coordinator.js +19 -56
- package/dist/services/settings-document-repository.d.ts +3 -10
- package/dist/services/settings-document-repository.js +7 -85
- package/dist/services/usage-state.d.ts +3 -3
- package/dist/services/usage-state.js +11 -42
- package/dist/terminal-ui/answer-format.d.ts +14 -0
- package/dist/terminal-ui/answer-format.js +119 -0
- package/dist/terminal-ui/launch.d.ts +7 -6
- package/dist/terminal-ui/launch.js +160 -70
- package/dist/terminal-ui/output-queue.d.ts +2 -1
- package/dist/terminal-ui/output-queue.js +1 -1
- package/dist/terminal-ui/raw-editor.d.ts +2 -1
- package/dist/terminal-ui/raw-editor.js +56 -15
- package/dist/tools/core/edit-file.js +2 -0
- package/dist/tools/core/write-file.js +5 -0
- package/dist/tools/lsp.d.ts +16 -1
- package/dist/tools/lsp.js +60 -19
- package/dist/tools/sandbox.d.ts +1 -1
- package/dist/tools/sandbox.js +3 -16
- package/dist/tools/todo.d.ts +4 -2
- package/dist/tools/todo.js +76 -31
- package/dist/tui-core/input-parser.d.ts +1 -0
- package/dist/tui-core/input-parser.js +6 -0
- package/dist/tui-core/style.d.ts +1 -8
- package/dist/tui-core/style.js +3 -110
- package/dist/tui-ui/chrome-view-model.d.ts +1 -1
- package/dist/tui-ui/chrome-view-model.js +22 -27
- package/dist/tui-ui/launch.js +14 -14
- package/dist/tui-ui/layout.d.ts +5 -7
- package/dist/tui-ui/layout.js +129 -124
- package/dist/tui-ui/runner.d.ts +11 -12
- package/dist/tui-ui/runner.js +88 -67
- package/dist/tui-ui/state.d.ts +0 -11
- package/dist/tui-ui/state.js +22 -33
- package/dist/tui-ui/terminal-image.js +22 -4
- package/dist/tui-ui/transcript-inspector-layout.js +6 -3
- package/dist/tui-ui/transcript-inspector.d.ts +1 -0
- package/dist/tui-ui/transcript-inspector.js +7 -1
- package/dist/tui-ui/transcript-layout.js +42 -6
- package/dist/utils/terminal-text.d.ts +11 -0
- package/dist/utils/terminal-text.js +114 -0
- package/docs/cli-guide.md +562 -0
- package/docs/orion.example.yaml +42 -0
- package/docs/readme.md +12 -57
- package/npm-shrinkwrap.json +484 -1855
- package/package.json +13 -63
- package/dist/migration/command.d.ts +0 -9
- package/dist/migration/command.js +0 -100
- package/dist/migration/index.d.ts +0 -7
- package/dist/migration/index.js +0 -14
- package/dist/migration/migrate.d.ts +0 -19
- package/dist/migration/migrate.js +0 -406
- package/dist/migration/types.d.ts +0 -55
- package/dist/migration/types.js +0 -6
- package/dist/services/tool-allowlist.d.ts +0 -110
- package/dist/services/tool-allowlist.js +0 -299
- package/dist/services/yaml-config.d.ts +0 -57
- package/dist/services/yaml-config.js +0 -178
- package/dist/web/cli-options.d.ts +0 -17
- package/dist/web/cli-options.js +0 -51
- package/dist/web/code-review-run-service.d.ts +0 -68
- package/dist/web/code-review-run-service.js +0 -228
- package/dist/web/context-text.d.ts +0 -17
- package/dist/web/context-text.js +0 -40
- package/dist/web/errors.d.ts +0 -6
- package/dist/web/errors.js +0 -13
- package/dist/web/event-hub.d.ts +0 -45
- package/dist/web/event-hub.js +0 -370
- package/dist/web/file-read-service.d.ts +0 -101
- package/dist/web/file-read-service.js +0 -593
- package/dist/web/file-write-service.d.ts +0 -16
- package/dist/web/file-write-service.js +0 -103
- package/dist/web/git-compare-service.d.ts +0 -45
- package/dist/web/git-compare-service.js +0 -160
- package/dist/web/git-diff-document.d.ts +0 -102
- package/dist/web/git-diff-document.js +0 -258
- package/dist/web/git-file-source.d.ts +0 -25
- package/dist/web/git-file-source.js +0 -21
- package/dist/web/git-history-service.d.ts +0 -151
- package/dist/web/git-history-service.js +0 -619
- package/dist/web/git-index-transaction.d.ts +0 -45
- package/dist/web/git-index-transaction.js +0 -174
- package/dist/web/git-patch-builder.d.ts +0 -30
- package/dist/web/git-patch-builder.js +0 -138
- package/dist/web/git-read-model-service.d.ts +0 -452
- package/dist/web/git-read-model-service.js +0 -1833
- package/dist/web/git-version-service.d.ts +0 -79
- package/dist/web/git-version-service.js +0 -279
- package/dist/web/host-daemon.d.ts +0 -70
- package/dist/web/host-daemon.js +0 -237
- package/dist/web/index.d.ts +0 -6
- package/dist/web/index.js +0 -28
- package/dist/web/launch.d.ts +0 -12
- package/dist/web/launch.js +0 -89
- package/dist/web/native-directory-picker.d.ts +0 -63
- package/dist/web/native-directory-picker.js +0 -169
- package/dist/web/protocol.d.ts +0 -705
- package/dist/web/protocol.js +0 -639
- package/dist/web/review-service.d.ts +0 -22
- package/dist/web/review-service.js +0 -68
- package/dist/web/server.d.ts +0 -20
- package/dist/web/server.js +0 -1453
- package/dist/web/session-runtime-registry.d.ts +0 -138
- package/dist/web/session-runtime-registry.js +0 -471
- package/dist/web/terminal-manager.d.ts +0 -156
- package/dist/web/terminal-manager.js +0 -779
- package/dist/web/terminal-server.d.ts +0 -8
- package/dist/web/terminal-server.js +0 -304
- package/dist/web/workbench-controller.d.ts +0 -395
- package/dist/web/workbench-controller.js +0 -3077
- package/dist/web/workspace-discovery.d.ts +0 -92
- package/dist/web/workspace-discovery.js +0 -324
- package/dist/web/workspace-mutation-arbiter.d.ts +0 -54
- package/dist/web/workspace-mutation-arbiter.js +0 -267
- package/dist/web/workspace-open-telemetry.d.ts +0 -55
- package/dist/web/workspace-open-telemetry.js +0 -73
- package/dist/web-client/assets/FilesPanel-iBYj9ZRf.js +0 -1
- package/dist/web-client/assets/GitPanel-D33R_bZr.js +0 -4
- package/dist/web-client/assets/ReviewPanel-C_0upsDk.js +0 -6
- package/dist/web-client/assets/TerminalPanel-C7A8dMNf.js +0 -23
- package/dist/web-client/assets/TerminalPanel-DLuoa74B.css +0 -1
- package/dist/web-client/assets/index-BaOxrwGB.css +0 -1
- package/dist/web-client/assets/index-CqCgJ2ov.js +0 -20
- package/dist/web-client/assets/useAutoNotice-C1qM-_Sg.js +0 -1
- package/dist/web-client/favicon.svg +0 -9
- package/dist/web-client/index.html +0 -17
- package/docs/architecture/agent-mode-permission-contract.md +0 -87
- package/docs/architecture/v0.3.0-web-api.yaml +0 -1340
- package/docs/architecture/v0.3.1-web-api.yaml +0 -2338
- package/docs/architecture/v0.3.2-web-api.yaml +0 -3029
- package/docs/architecture/v0.3.3-web-api.yaml +0 -3205
- package/docs/architecture/v0.3.4-stabilization-contract.md +0 -32
- package/docs/migration/v0.1.9-to-v0.2.0.md +0 -98
- package/docs/migration/v0.2.2-to-v0.3.0-settings.md +0 -114
- package/docs/migration/v0.2.2-to-v0.3.0.md +0 -55
- package/docs/migration/v0.3.0-to-v0.3.1.md +0 -88
- package/docs/migration/v0.3.1-to-v0.3.2.md +0 -94
- package/docs/migration/v0.3.2-to-v0.3.3.md +0 -62
- package/docs/migration/v0.3.3-to-v0.3.4.md +0 -36
- package/docs/orion.example.json +0 -86
- package/docs/plan/v0.2.0-dsh-harness-redesign-plan.md +0 -1234
- package/docs/plan/v0.2.0-release-checklist.md +0 -91
- package/docs/plan/v0.3.0-node-runtime-compatibility-plan.md +0 -57
- package/docs/plan/v0.3.0-settings-integration-plan.md +0 -740
- package/docs/plan/v0.3.0-web-workbench-plan.md +0 -376
- package/docs/plan/v0.3.1-web-workbench-professional-shell-plan.md +0 -848
- package/docs/plan/v0.3.2-web-workbench-layout-and-composer-plan.md +0 -869
- package/docs/plan/v0.3.3-plan.md +0 -1113
- package/docs/plan/v0.3.4-stabilization-plan.md +0 -89
- package/docs/test/v0.3.1-web-workbench-e2e-plan.md +0 -140
- package/docs/test/v0.3.2-web-workbench-e2e-plan.md +0 -100
- package/docs/test/v0.3.3-web-workbench-e2e-plan.md +0 -79
- package/docs/test/v0.3.4-stabilization-e2e-plan.md +0 -54
|
@@ -13,8 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.ModelClientPool = void 0;
|
|
16
|
-
exports.
|
|
17
|
-
exports.buildRequestContext = buildRequestContext;
|
|
16
|
+
exports.resolveProviderCredential = resolveProviderCredential;
|
|
18
17
|
const openai_1 = __importDefault(require("openai"));
|
|
19
18
|
class ModelClientPool {
|
|
20
19
|
constructor() {
|
|
@@ -22,19 +21,50 @@ class ModelClientPool {
|
|
|
22
21
|
}
|
|
23
22
|
/** Get or create an OpenAI client for a provider. */
|
|
24
23
|
getClient(provider) {
|
|
24
|
+
const credential = resolveProviderCredential(provider.apiKey);
|
|
25
|
+
if (!credential.apiKey)
|
|
26
|
+
throw new Error(credential.error);
|
|
25
27
|
const existing = this.clients.get(provider.id);
|
|
26
|
-
if (existing
|
|
28
|
+
if (existing?.provider.baseUrl === provider.baseUrl &&
|
|
29
|
+
existing.client.apiKey === credential.apiKey) {
|
|
27
30
|
return existing.client;
|
|
28
|
-
|
|
29
|
-
const apiKey = resolveApiKey(provider.apiKey);
|
|
31
|
+
}
|
|
30
32
|
const client = new openai_1.default({
|
|
31
33
|
baseURL: provider.baseUrl,
|
|
32
|
-
apiKey,
|
|
34
|
+
apiKey: credential.apiKey,
|
|
35
|
+
maxRetries: 0,
|
|
36
|
+
timeout: 60000,
|
|
33
37
|
// No default model — callers must pass the resolved model ID
|
|
34
38
|
});
|
|
35
39
|
this.clients.set(provider.id, { provider, client, createdAt: Date.now() });
|
|
36
40
|
return client;
|
|
37
41
|
}
|
|
42
|
+
/** Bind the selected profile and usable fallback as a single model selection. */
|
|
43
|
+
bindModel(llm, registry, profile, preference) {
|
|
44
|
+
const provider = registry.providers.get(profile.provider);
|
|
45
|
+
if (!provider)
|
|
46
|
+
throw new Error(`Provider "${profile.provider}" not found.`);
|
|
47
|
+
const fallback = registry.fallbackProfile;
|
|
48
|
+
const fallbackProvider = fallback && registry.providers.get(fallback.provider);
|
|
49
|
+
llm.setModelRoutes(this.route(profile, provider), fallback?.enabled !== false &&
|
|
50
|
+
fallback?.id !== profile.id &&
|
|
51
|
+
fallbackProvider &&
|
|
52
|
+
fallback &&
|
|
53
|
+
resolveProviderCredential(fallbackProvider.apiKey).apiKey
|
|
54
|
+
? this.route(fallback, fallbackProvider)
|
|
55
|
+
: undefined, preference);
|
|
56
|
+
}
|
|
57
|
+
route(profile, provider) {
|
|
58
|
+
return {
|
|
59
|
+
model: profile.model,
|
|
60
|
+
providerKey: provider.id,
|
|
61
|
+
client: this.getClient(provider),
|
|
62
|
+
contextWindow: profile.resolvedContextWindow,
|
|
63
|
+
maxOutputTokens: profile.resolvedMaxOutputTokens,
|
|
64
|
+
protocol: provider.protocol,
|
|
65
|
+
reasoningCapability: profile.reasoningCapability,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
38
68
|
/** Invalidate and recreate a provider's client (e.g. after key rotation). */
|
|
39
69
|
invalidate(providerId) {
|
|
40
70
|
this.clients.delete(providerId);
|
|
@@ -55,34 +85,33 @@ exports.ModelClientPool = ModelClientPool;
|
|
|
55
85
|
// ============================================================================
|
|
56
86
|
// Helpers
|
|
57
87
|
// ============================================================================
|
|
58
|
-
function
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
88
|
+
function resolveProviderCredential(value) {
|
|
89
|
+
if (value.startsWith('$')) {
|
|
90
|
+
const reference = /^\$(?:\{([A-Za-z_]\w*)\}|([A-Za-z_]\w*))$/.exec(value);
|
|
91
|
+
const variable = reference?.[1] ?? reference?.[2];
|
|
92
|
+
if (!variable) {
|
|
93
|
+
return {
|
|
94
|
+
apiKey: '',
|
|
95
|
+
source: 'environment',
|
|
96
|
+
error: 'Invalid provider API key environment reference.',
|
|
97
|
+
};
|
|
65
98
|
}
|
|
66
|
-
|
|
99
|
+
const apiKey = process.env[variable]?.trim();
|
|
100
|
+
return apiKey
|
|
101
|
+
? { apiKey, source: 'environment' }
|
|
102
|
+
: {
|
|
103
|
+
apiKey: '',
|
|
104
|
+
source: 'environment',
|
|
105
|
+
error: `Missing environment variable ${variable} for the provider API key.`,
|
|
106
|
+
};
|
|
67
107
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return {};
|
|
77
|
-
// Default coding-agent behavior: temperature 0 for determinism.
|
|
78
|
-
return { temperature: 0 };
|
|
79
|
-
}
|
|
80
|
-
function buildRequestContext(profile) {
|
|
81
|
-
return {
|
|
82
|
-
model: profile.model,
|
|
83
|
-
contextWindow: profile.resolvedContextWindow,
|
|
84
|
-
maxOutputTokens: profile.resolvedMaxOutputTokens,
|
|
85
|
-
temperatureParams: buildTemperatureParam(profile),
|
|
86
|
-
};
|
|
108
|
+
const apiKey = value.trim();
|
|
109
|
+
return apiKey
|
|
110
|
+
? { apiKey, source: 'literal' }
|
|
111
|
+
: {
|
|
112
|
+
apiKey: '',
|
|
113
|
+
source: 'literal',
|
|
114
|
+
error: 'Missing API key. Set it in ~/.orion-code/orion.yaml.',
|
|
115
|
+
};
|
|
87
116
|
}
|
|
88
117
|
//# sourceMappingURL=model-client-pool.js.map
|
|
@@ -80,7 +80,7 @@ export declare function getModelInfo(modelId: string): ModelContextInfo | null;
|
|
|
80
80
|
* 计算上下文使用百分比
|
|
81
81
|
*/
|
|
82
82
|
export declare function calculateCtxPercent(usedTokens: number, modelId: string): number;
|
|
83
|
-
export declare function resolveContextBudget(modelId: string, requestedOutputTokens?: number): ContextBudget;
|
|
83
|
+
export declare function resolveContextBudget(modelId: string, requestedOutputTokens?: number, resolvedContextWindow?: number): ContextBudget;
|
|
84
84
|
export declare function createContextUsageSnapshot(input: {
|
|
85
85
|
modelId: string;
|
|
86
86
|
usedTokens: number;
|
|
@@ -89,6 +89,7 @@ export declare function createContextUsageSnapshot(input: {
|
|
|
89
89
|
autoCompactThreshold?: number;
|
|
90
90
|
autoCompactEnabled?: boolean;
|
|
91
91
|
outputReserveTokens?: number;
|
|
92
|
+
contextWindow?: number;
|
|
92
93
|
}): ContextUsageSnapshot;
|
|
93
94
|
/**
|
|
94
95
|
* 获取所有已知模型列表(内置 + 动态发现)
|
|
@@ -470,35 +470,41 @@ function calculateCtxPercent(usedTokens, modelId) {
|
|
|
470
470
|
const contextWindow = getModelContextWindow(modelId);
|
|
471
471
|
return Math.min(100, Math.round((usedTokens / contextWindow) * 100));
|
|
472
472
|
}
|
|
473
|
-
function resolveContextBudget(modelId, requestedOutputTokens) {
|
|
473
|
+
function resolveContextBudget(modelId, requestedOutputTokens, resolvedContextWindow) {
|
|
474
474
|
const model = resolveModelContext(modelId);
|
|
475
|
+
const contextWindow = resolvedContextWindow ?? model.contextWindow;
|
|
475
476
|
const requested = Number.isFinite(requestedOutputTokens)
|
|
476
477
|
? Math.max(0, Math.round(requestedOutputTokens ?? 0))
|
|
477
478
|
: (model.maxOutputTokens ?? 8192);
|
|
478
479
|
// 输出预留最多占上下文窗口的一半:某些条目的 maxOutputTokens 等于(甚至接近)
|
|
479
480
|
// contextWindow,直接相减会把可用输入预算打到 0/负数。
|
|
480
|
-
const reservedCeiling = Math.max(1, Math.floor(
|
|
481
|
-
const reservedOutputTokens =
|
|
482
|
-
|
|
481
|
+
const reservedCeiling = Math.max(1, Math.floor(contextWindow * exports.MAX_OUTPUT_RESERVE_RATIO));
|
|
482
|
+
const reservedOutputTokens = resolvedContextWindow === undefined
|
|
483
|
+
? Math.min(requested, model.maxOutputTokens ?? requested, reservedCeiling)
|
|
484
|
+
: Math.min(requested, Math.max(0, contextWindow - 1));
|
|
485
|
+
const defaultMargin = Math.max(1024, Math.ceil(contextWindow * 0.02));
|
|
486
|
+
const safetyMarginTokens = resolvedContextWindow === undefined
|
|
487
|
+
? defaultMargin
|
|
488
|
+
: Math.min(defaultMargin, Math.max(0, Math.floor((contextWindow - reservedOutputTokens) / 2)));
|
|
483
489
|
// 兜底:`Math.max(1, …)` 会把配置错误伪装成一个「看起来合理」的 1,
|
|
484
490
|
// 而 safeInputBudget 是 auto-compact 与状态栏占比的分母 —— ratio = used / 1
|
|
485
491
|
// 恒 ≥ 阈值,于是从第一条消息起每轮都触发压缩、状态栏钉死 100%。
|
|
486
492
|
// 非正数时退回按窗口比例估算,并记录一次告警。
|
|
487
|
-
const rawBudget =
|
|
493
|
+
const rawBudget = contextWindow - reservedOutputTokens - safetyMarginTokens;
|
|
488
494
|
let safeInputBudget = rawBudget;
|
|
489
495
|
if (safeInputBudget <= 0) {
|
|
490
|
-
safeInputBudget = Math.max(1, Math.floor(
|
|
491
|
-
warnUnusableBudgetOnce(model.matchedId || modelId,
|
|
496
|
+
safeInputBudget = Math.max(1, Math.floor(contextWindow * exports.FALLBACK_INPUT_BUDGET_RATIO));
|
|
497
|
+
warnUnusableBudgetOnce(model.matchedId || modelId, contextWindow, safeInputBudget);
|
|
492
498
|
}
|
|
493
499
|
return {
|
|
494
|
-
contextWindow
|
|
500
|
+
contextWindow,
|
|
495
501
|
reservedOutputTokens,
|
|
496
502
|
safetyMarginTokens,
|
|
497
503
|
safeInputBudget,
|
|
498
504
|
};
|
|
499
505
|
}
|
|
500
506
|
function createContextUsageSnapshot(input) {
|
|
501
|
-
const budget = resolveContextBudget(input.modelId, input.outputReserveTokens);
|
|
507
|
+
const budget = resolveContextBudget(input.modelId, input.outputReserveTokens, input.contextWindow);
|
|
502
508
|
const contextWindow = budget.contextWindow;
|
|
503
509
|
const usedTokens = Number.isFinite(input.usedTokens)
|
|
504
510
|
? Math.max(0, Math.round(input.usedTokens))
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* - Context fields follow config > discovery > builtin > default priority.
|
|
12
12
|
* - Secret-free fingerprint for change detection.
|
|
13
13
|
*/
|
|
14
|
-
import { type ReasoningCapability } from './effort';
|
|
14
|
+
import { type ReasoningCapability, type ReasoningEffortPolicy } from './effort';
|
|
15
15
|
export type ProviderProtocol = 'openai-completions' | 'anthropic-messages';
|
|
16
16
|
export interface ProviderConfig {
|
|
17
17
|
/** Unique provider id (e.g. "huoshan", "astroncodingplan"). */
|
|
@@ -42,19 +42,11 @@ export interface ModelProfile {
|
|
|
42
42
|
aliases?: string[];
|
|
43
43
|
/** Whether this profile is enabled. Disabled profiles are hidden from /model list. */
|
|
44
44
|
enabled?: boolean;
|
|
45
|
-
/**
|
|
46
|
-
|
|
47
|
-
/** Explicit effort levels and wire adapter. Legacy `reasoning: true` is not sufficient. */
|
|
48
|
-
reasoningCapability?: ReasoningCapability;
|
|
49
|
-
/** Temperature compatibility: "supported" | "unsupported". */
|
|
50
|
-
temperatureMode?: 'supported' | 'unsupported';
|
|
51
|
-
/** Optional cost per 1M tokens. */
|
|
52
|
-
cost?: {
|
|
53
|
-
input: number;
|
|
54
|
-
output: number;
|
|
55
|
-
};
|
|
45
|
+
/** Explicit levels accepted by the model's Chat Completions reasoning_effort parameter. */
|
|
46
|
+
reasoningEffort?: ReasoningEffortPolicy;
|
|
56
47
|
}
|
|
57
48
|
export interface ResolvedModelProfile extends ModelProfile {
|
|
49
|
+
reasoningCapability?: ReasoningCapability;
|
|
58
50
|
/** Resolved context window (after config>discovery>builtin>default). */
|
|
59
51
|
resolvedContextWindow: number;
|
|
60
52
|
/** Resolved max output tokens. */
|
|
@@ -92,9 +84,6 @@ export interface RegistryValidationResult {
|
|
|
92
84
|
errors: RegistryValidationError[];
|
|
93
85
|
registry: ModelRegistry | null;
|
|
94
86
|
}
|
|
95
|
-
export declare const LEGACY_FIELDS: readonly ["apiKey", "apiBaseUrl", "defaultModel", "fallbackModel"];
|
|
96
|
-
export declare function isLegacyConfig(config: Record<string, unknown>): boolean;
|
|
97
|
-
export declare function getLegacyMigrationHint(): string;
|
|
98
87
|
export declare function resolveModelProfile(profile: ModelProfile, provider: ProviderConfig, discoveryContext?: number, discoveryOutput?: number): ResolvedModelProfile;
|
|
99
88
|
export declare function buildRegistry(config: ModelRegistryConfig): RegistryValidationResult;
|
|
100
89
|
export declare function lookupProfile(registry: ModelRegistry, selector: string): ResolvedModelProfile | null;
|
|
@@ -13,9 +13,6 @@
|
|
|
13
13
|
* - Secret-free fingerprint for change detection.
|
|
14
14
|
*/
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.LEGACY_FIELDS = void 0;
|
|
17
|
-
exports.isLegacyConfig = isLegacyConfig;
|
|
18
|
-
exports.getLegacyMigrationHint = getLegacyMigrationHint;
|
|
19
16
|
exports.resolveModelProfile = resolveModelProfile;
|
|
20
17
|
exports.buildRegistry = buildRegistry;
|
|
21
18
|
exports.lookupProfile = lookupProfile;
|
|
@@ -23,107 +20,56 @@ exports.lookupProfile = lookupProfile;
|
|
|
23
20
|
// Provider types
|
|
24
21
|
// ============================================================================
|
|
25
22
|
const effort_1 = require("./effort");
|
|
26
|
-
exports.LEGACY_FIELDS = ['apiKey', 'apiBaseUrl', 'defaultModel', 'fallbackModel'];
|
|
27
|
-
function isLegacyConfig(config) {
|
|
28
|
-
return exports.LEGACY_FIELDS.some(f => typeof config[f] === 'string' && config[f].length > 0);
|
|
29
|
-
}
|
|
30
|
-
function getLegacyMigrationHint() {
|
|
31
|
-
return [
|
|
32
|
-
'Legacy configuration detected; migrate to the providers+models format.',
|
|
33
|
-
'Your orion.json uses the legacy 4-field format (apiKey/apiBaseUrl/defaultModel/fallbackModel).',
|
|
34
|
-
'',
|
|
35
|
-
'Migration example:',
|
|
36
|
-
'{',
|
|
37
|
-
' "providers": [',
|
|
38
|
-
' {',
|
|
39
|
-
' "id": "my-provider",',
|
|
40
|
-
' "baseUrl": "<your-base-url>",',
|
|
41
|
-
' "apiKey": "<your-api-key>",',
|
|
42
|
-
' "protocol": "openai-completions"',
|
|
43
|
-
' }',
|
|
44
|
-
' ],',
|
|
45
|
-
' "models": [',
|
|
46
|
-
' {',
|
|
47
|
-
' "id": "my-model",',
|
|
48
|
-
' "provider": "my-provider",',
|
|
49
|
-
' "model": "<actual-model-id>"',
|
|
50
|
-
' }',
|
|
51
|
-
' ],',
|
|
52
|
-
' "defaultModel": "my-model"',
|
|
53
|
-
'}',
|
|
54
|
-
'',
|
|
55
|
-
'See README.md#configuration for current details.',
|
|
56
|
-
].join('\n');
|
|
57
|
-
}
|
|
58
23
|
const BUILTIN_CATALOG = {
|
|
59
24
|
'gpt-4o': {
|
|
60
25
|
contextWindow: 128000,
|
|
61
26
|
maxOutputTokens: 16384,
|
|
62
|
-
temperatureMode: 'supported',
|
|
63
|
-
cost: { input: 2.5, output: 10 },
|
|
64
27
|
},
|
|
65
28
|
'gpt-4o-mini': {
|
|
66
29
|
contextWindow: 128000,
|
|
67
30
|
maxOutputTokens: 16384,
|
|
68
|
-
temperatureMode: 'supported',
|
|
69
|
-
cost: { input: 0.15, output: 0.6 },
|
|
70
31
|
},
|
|
71
32
|
'claude-opus-4-8': {
|
|
72
33
|
contextWindow: 200000,
|
|
73
34
|
maxOutputTokens: 32768,
|
|
74
|
-
reasoning: true,
|
|
75
|
-
temperatureMode: 'supported',
|
|
76
|
-
cost: { input: 15, output: 75 },
|
|
77
35
|
},
|
|
78
36
|
'claude-sonnet-4-6': {
|
|
79
37
|
contextWindow: 200000,
|
|
80
38
|
maxOutputTokens: 16384,
|
|
81
|
-
temperatureMode: 'supported',
|
|
82
|
-
cost: { input: 3, output: 15 },
|
|
83
39
|
},
|
|
84
40
|
'deepseek-chat': {
|
|
85
41
|
contextWindow: 65536,
|
|
86
42
|
maxOutputTokens: 8192,
|
|
87
|
-
temperatureMode: 'supported',
|
|
88
|
-
cost: { input: 0.14, output: 0.28 },
|
|
89
43
|
},
|
|
90
44
|
'deepseek-coder': {
|
|
91
45
|
contextWindow: 65536,
|
|
92
46
|
maxOutputTokens: 8192,
|
|
93
|
-
temperatureMode: 'supported',
|
|
94
|
-
cost: { input: 0.14, output: 0.28 },
|
|
95
47
|
},
|
|
96
48
|
// 火山方舟 Ark (huoshan / volcengine)
|
|
97
49
|
'ark-code-latest': {
|
|
98
50
|
contextWindow: 1024000,
|
|
99
51
|
maxOutputTokens: 128000,
|
|
100
|
-
provider: 'huoshan',
|
|
101
52
|
},
|
|
102
53
|
'glm-5.2': {
|
|
103
54
|
contextWindow: 1024000,
|
|
104
55
|
maxOutputTokens: 128000,
|
|
105
|
-
provider: 'huoshan',
|
|
106
56
|
},
|
|
107
57
|
'kimi-k2.7-code': {
|
|
108
58
|
contextWindow: 256000,
|
|
109
59
|
maxOutputTokens: 32768,
|
|
110
|
-
provider: 'huoshan',
|
|
111
60
|
},
|
|
112
61
|
'deepseek-v4-pro': {
|
|
113
62
|
contextWindow: 1000000,
|
|
114
63
|
maxOutputTokens: 384000,
|
|
115
|
-
provider: 'huoshan',
|
|
116
64
|
},
|
|
117
65
|
// 讯飞 MAAS (xf-yun)
|
|
118
66
|
xopdeepseekv4pro: {
|
|
119
67
|
contextWindow: 1000000,
|
|
120
68
|
maxOutputTokens: 16384,
|
|
121
|
-
provider: 'astroncodingplan',
|
|
122
69
|
},
|
|
123
70
|
xopglm51: {
|
|
124
71
|
contextWindow: 204800,
|
|
125
72
|
maxOutputTokens: 16384,
|
|
126
|
-
provider: 'astroncodingplan',
|
|
127
73
|
},
|
|
128
74
|
};
|
|
129
75
|
const DEFAULT_CONTEXT = 128000;
|
|
@@ -171,9 +117,20 @@ function resolveModelProfile(profile, provider, discoveryContext, discoveryOutpu
|
|
|
171
117
|
resolvedMaxOutputTokens = DEFAULT_MAX_OUTPUT;
|
|
172
118
|
outputSource = 'default';
|
|
173
119
|
}
|
|
120
|
+
if (outputSource !== 'config') {
|
|
121
|
+
resolvedMaxOutputTokens = Math.min(resolvedMaxOutputTokens, Math.max(1, Math.floor(resolvedContextWindow / 2)));
|
|
122
|
+
}
|
|
174
123
|
const fingerprint = computeFingerprint(profile, provider, resolvedContextWindow, resolvedMaxOutputTokens);
|
|
124
|
+
const reasoningEffort = profile.reasoningEffort;
|
|
175
125
|
return {
|
|
176
126
|
...profile,
|
|
127
|
+
reasoningCapability: reasoningEffort && provider.protocol === 'openai-completions'
|
|
128
|
+
? {
|
|
129
|
+
supportedLevels: [...reasoningEffort.supportedLevels],
|
|
130
|
+
defaultLevel: reasoningEffort.defaultLevel,
|
|
131
|
+
source: 'config',
|
|
132
|
+
}
|
|
133
|
+
: undefined,
|
|
177
134
|
resolvedContextWindow,
|
|
178
135
|
resolvedMaxOutputTokens,
|
|
179
136
|
contextSource,
|
|
@@ -242,57 +199,34 @@ function buildRegistry(config) {
|
|
|
242
199
|
(m.contextWindow <= 0 || !Number.isInteger(m.contextWindow))) {
|
|
243
200
|
errors.push({ path: `models.${m.id}.contextWindow`, message: 'Must be a positive integer.' });
|
|
244
201
|
}
|
|
245
|
-
if (m.
|
|
246
|
-
const
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
202
|
+
if (m.reasoningEffort !== undefined) {
|
|
203
|
+
const policy = m.reasoningEffort;
|
|
204
|
+
const levels = policy?.supportedLevels;
|
|
205
|
+
const supportedLevelsValid = Array.isArray(levels) &&
|
|
206
|
+
levels.length > 0 &&
|
|
207
|
+
levels.every(level => effort_1.EFFORT_LEVELS.includes(level)) &&
|
|
208
|
+
new Set(levels).size === levels.length;
|
|
251
209
|
if (!supportedLevelsValid) {
|
|
252
210
|
errors.push({
|
|
253
|
-
path: `models.${m.id}.
|
|
211
|
+
path: `models.${m.id}.reasoningEffort.supportedLevels`,
|
|
254
212
|
message: 'Must contain unique supported effort levels and cannot be empty.',
|
|
255
213
|
});
|
|
256
214
|
}
|
|
257
|
-
if (
|
|
258
|
-
|
|
259
|
-
path: `models.${m.id}.reasoningCapability.kind`,
|
|
260
|
-
message: 'Unknown reasoning capability kind.',
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
if (!['openai-chat-reasoning-effort', 'anthropic-output-config-effort'].includes(capability.adapter)) {
|
|
264
|
-
errors.push({
|
|
265
|
-
path: `models.${m.id}.reasoningCapability.adapter`,
|
|
266
|
-
message: 'Unknown reasoning capability adapter.',
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
if (!['config', 'discovery', 'builtin'].includes(capability.source)) {
|
|
215
|
+
if (policy?.defaultLevel !== undefined &&
|
|
216
|
+
(!supportedLevelsValid || !levels.includes(policy.defaultLevel))) {
|
|
270
217
|
errors.push({
|
|
271
|
-
path: `models.${m.id}.
|
|
272
|
-
message: 'Unknown reasoning capability source.',
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
if (capability.defaultLevel !== undefined &&
|
|
276
|
-
(!supportedLevelsValid || !capability.supportedLevels.includes(capability.defaultLevel))) {
|
|
277
|
-
errors.push({
|
|
278
|
-
path: `models.${m.id}.reasoningCapability.defaultLevel`,
|
|
218
|
+
path: `models.${m.id}.reasoningEffort.defaultLevel`,
|
|
279
219
|
message: 'defaultLevel must be included in supportedLevels.',
|
|
280
220
|
});
|
|
281
221
|
}
|
|
282
|
-
if (
|
|
283
|
-
provider.protocol !== 'openai-completions') {
|
|
222
|
+
if (provider.protocol !== 'openai-completions') {
|
|
284
223
|
errors.push({
|
|
285
|
-
path: `models.${m.id}.
|
|
286
|
-
message: '
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
if (capability.adapter === 'anthropic-output-config-effort' &&
|
|
290
|
-
provider.protocol !== 'anthropic-messages') {
|
|
291
|
-
errors.push({
|
|
292
|
-
path: `models.${m.id}.reasoningCapability.adapter`,
|
|
293
|
-
message: 'anthropic-output-config-effort requires anthropic-messages protocol.',
|
|
224
|
+
path: `models.${m.id}.reasoningEffort`,
|
|
225
|
+
message: 'reasoningEffort requires the openai-completions protocol.',
|
|
294
226
|
});
|
|
295
227
|
}
|
|
228
|
+
if (!supportedLevelsValid)
|
|
229
|
+
continue;
|
|
296
230
|
}
|
|
297
231
|
if (m.maxOutputTokens !== undefined &&
|
|
298
232
|
(m.maxOutputTokens <= 0 || !Number.isInteger(m.maxOutputTokens))) {
|
|
@@ -301,15 +235,13 @@ function buildRegistry(config) {
|
|
|
301
235
|
message: 'Must be a positive integer.',
|
|
302
236
|
});
|
|
303
237
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
m.maxOutputTokens >= m.contextWindow) {
|
|
238
|
+
const resolved = resolveModelProfile(m, provider);
|
|
239
|
+
if (m.maxOutputTokens !== undefined && m.maxOutputTokens >= resolved.resolvedContextWindow) {
|
|
307
240
|
errors.push({
|
|
308
241
|
path: `models.${m.id}.maxOutputTokens`,
|
|
309
|
-
message: 'maxOutputTokens must be less than contextWindow.',
|
|
242
|
+
message: 'maxOutputTokens must be less than the resolved contextWindow.',
|
|
310
243
|
});
|
|
311
244
|
}
|
|
312
|
-
const resolved = resolveModelProfile(m, provider);
|
|
313
245
|
profiles.set(m.id, resolved);
|
|
314
246
|
// Build alias index
|
|
315
247
|
if (m.aliases) {
|
|
@@ -384,9 +316,8 @@ function computeFingerprint(profile, provider, context, output) {
|
|
|
384
316
|
String(output),
|
|
385
317
|
provider.baseUrl,
|
|
386
318
|
provider.protocol,
|
|
387
|
-
profile.
|
|
388
|
-
profile.
|
|
389
|
-
profile.reasoningCapability ? JSON.stringify(profile.reasoningCapability) : '',
|
|
319
|
+
profile.reasoningEffort?.supportedLevels.join(',') ?? '',
|
|
320
|
+
profile.reasoningEffort?.defaultLevel ?? '',
|
|
390
321
|
];
|
|
391
322
|
return createHash('sha256').update(parts.join('|')).digest('hex').slice(0, 12);
|
|
392
323
|
}
|
|
@@ -17,6 +17,13 @@ export interface ProviderConfigInput {
|
|
|
17
17
|
baseUrl?: string;
|
|
18
18
|
fallbackModel?: string;
|
|
19
19
|
model: string;
|
|
20
|
+
/** v0.4 registry provider id; overrides the built-in model table lookup. */
|
|
21
|
+
provider?: string;
|
|
22
|
+
effectiveLimits?: {
|
|
23
|
+
contextWindow: number;
|
|
24
|
+
maxOutputTokens: number;
|
|
25
|
+
source: string;
|
|
26
|
+
};
|
|
20
27
|
}
|
|
21
28
|
export declare class LLMProviderError extends Error {
|
|
22
29
|
readonly diagnostic: ProviderErrorDiagnostic;
|
|
@@ -7,7 +7,6 @@ exports.toLLMProviderError = toLLMProviderError;
|
|
|
7
7
|
exports.formatProviderErrorMessage = formatProviderErrorMessage;
|
|
8
8
|
exports.diagnoseProviderConfig = diagnoseProviderConfig;
|
|
9
9
|
const model_context_1 = require("./model-context");
|
|
10
|
-
const environment_1 = require("../product/environment");
|
|
11
10
|
class LLMProviderError extends Error {
|
|
12
11
|
constructor(diagnostic) {
|
|
13
12
|
super(formatProviderErrorMessage(diagnostic));
|
|
@@ -92,17 +91,17 @@ function matchesAny(text, patterns) {
|
|
|
92
91
|
function hintFor(type) {
|
|
93
92
|
switch (type) {
|
|
94
93
|
case 'model_not_found':
|
|
95
|
-
return
|
|
94
|
+
return 'Model was not found by the provider. Check models[].model in orion.yaml.';
|
|
96
95
|
case 'invalid_endpoint':
|
|
97
|
-
return
|
|
96
|
+
return 'Endpoint appears invalid or unreachable. Check providers[].baseUrl in orion.yaml.';
|
|
98
97
|
case 'auth_failed':
|
|
99
|
-
return
|
|
98
|
+
return 'Provider authentication failed. Check providers[].apiKey and its referenced environment variable.';
|
|
100
99
|
case 'quota_or_credit_exhausted':
|
|
101
100
|
return 'Provider quota or credit appears insufficient. Recharge the provider account or switch model/provider.';
|
|
102
101
|
case 'rate_limit':
|
|
103
102
|
return 'Provider rate limit was reached. Wait before retrying, reduce request rate, or switch model/provider.';
|
|
104
103
|
case 'provider_busy':
|
|
105
|
-
return
|
|
104
|
+
return 'Provider is busy or overloaded. Retry later or configure fallbackModel in orion.yaml.';
|
|
106
105
|
case 'unsupported_effort':
|
|
107
106
|
return 'The provider rejected the configured effort override. Use /effort auto or select a supported level; Orion did not retry without the explicit override.';
|
|
108
107
|
case 'unknown_provider_error':
|
|
@@ -304,20 +303,20 @@ function diagnoseProviderConfig(input) {
|
|
|
304
303
|
const model = input.model.trim() || '(not set)';
|
|
305
304
|
const modelContext = (0, model_context_1.resolveModelContext)(model);
|
|
306
305
|
const endpoint = endpointDiagnostics(input.baseUrl);
|
|
307
|
-
const modelStatus = model === '(not set)' || modelContext.source === 'default' ? 'warn' : 'ok';
|
|
306
|
+
const modelStatus = model === '(not set)' || (modelContext.source === 'default' && !input.provider) ? 'warn' : 'ok';
|
|
308
307
|
const keyStatus = input.apiKey ? 'ok' : 'fail';
|
|
309
308
|
const status = worseStatus(worseStatus(endpoint.status, modelStatus), keyStatus);
|
|
310
|
-
const provider = modelContext.provider ?? 'unknown';
|
|
309
|
+
const provider = input.provider ?? modelContext.provider ?? 'unknown';
|
|
311
310
|
return {
|
|
312
311
|
status,
|
|
313
312
|
summary: `${model} via ${provider}, endpoint ${endpoint.endpoint}`,
|
|
314
313
|
detail: [
|
|
315
314
|
`model=${model}`,
|
|
316
315
|
`provider=${provider}`,
|
|
317
|
-
`modelSource=${modelContext.source}`,
|
|
316
|
+
`modelSource=${input.effectiveLimits?.source ?? modelContext.source}`,
|
|
318
317
|
`matchedModel=${modelContext.matchedId}`,
|
|
319
|
-
`contextWindow=${modelContext.contextWindow}`,
|
|
320
|
-
`maxOutputTokens=${modelContext.maxOutputTokens ?? '(unknown)'}`,
|
|
318
|
+
`contextWindow=${input.effectiveLimits?.contextWindow ?? modelContext.contextWindow}`,
|
|
319
|
+
`maxOutputTokens=${input.effectiveLimits?.maxOutputTokens ?? modelContext.maxOutputTokens ?? '(unknown)'}`,
|
|
321
320
|
...endpoint.detail,
|
|
322
321
|
`apiKey=${input.apiKey ? 'configured' : 'missing'}`,
|
|
323
322
|
`fallbackModel=${input.fallbackModel || '(none)'}`,
|
|
@@ -12,7 +12,7 @@ export declare class ProviderResilienceCoordinator {
|
|
|
12
12
|
private readonly config;
|
|
13
13
|
constructor(config?: Partial<ProviderResilienceConfig>, requestGate?: ProviderRequestGate | undefined);
|
|
14
14
|
/** Execute a logical request with full retry/fallback/recovery logic. */
|
|
15
|
-
execute<T>(ctx: ProviderRequestContext, transport: (attempt: number, signal?: AbortSignal, model?: string, reporter?: ProviderAttemptReporter) => Promise<{
|
|
15
|
+
execute<T>(ctx: ProviderRequestContext, transport: (attempt: number, signal?: AbortSignal, model?: string, reporter?: ProviderAttemptReporter, providerKey?: string) => Promise<{
|
|
16
16
|
response: T;
|
|
17
17
|
usage?: {
|
|
18
18
|
promptTokens: number;
|
|
@@ -37,6 +37,7 @@ class ProviderResilienceCoordinator {
|
|
|
37
37
|
const startedAt = Date.now();
|
|
38
38
|
let lastError;
|
|
39
39
|
let currentModel = ctx.requestedModel;
|
|
40
|
+
let currentProviderKey = ctx.providerKey;
|
|
40
41
|
let fallbackUsed = false;
|
|
41
42
|
let recoveredStream = false;
|
|
42
43
|
for (let attempt = 1; attempt <= this.config.maxTotalAttempts; attempt++) {
|
|
@@ -50,16 +51,16 @@ class ProviderResilienceCoordinator {
|
|
|
50
51
|
diagnostics.finalState = 'aborted';
|
|
51
52
|
throw new ProviderRetryExhaustedError(diagnostics, 'aborted by signal');
|
|
52
53
|
}
|
|
53
|
-
const attemptRecord = this.startAttempt(ctx, attempt,
|
|
54
|
+
const attemptRecord = this.startAttempt(ctx, attempt, currentModel, currentProviderKey);
|
|
54
55
|
diagnostics.attempts.push(attemptRecord);
|
|
55
56
|
let gateLease;
|
|
56
57
|
try {
|
|
57
58
|
gateLease = await this.requestGate?.acquire({
|
|
58
59
|
priority: 0,
|
|
59
|
-
providerKey:
|
|
60
|
+
providerKey: currentProviderKey,
|
|
60
61
|
...(ctx.abortSignal ? { abortSignal: ctx.abortSignal } : {}),
|
|
61
62
|
});
|
|
62
|
-
const result = await transport(attempt, ctx.abortSignal, currentModel, this.createAttemptReporter(attemptRecord));
|
|
63
|
+
const result = await transport(attempt, ctx.abortSignal, currentModel, this.createAttemptReporter(attemptRecord), currentProviderKey);
|
|
63
64
|
attemptRecord.outcome = 'succeeded';
|
|
64
65
|
attemptRecord.endedAt = Date.now();
|
|
65
66
|
if (result.usage)
|
|
@@ -90,7 +91,7 @@ class ProviderResilienceCoordinator {
|
|
|
90
91
|
throw new ProviderRetryExhaustedError(diagnostics, 'aborted by signal', error);
|
|
91
92
|
}
|
|
92
93
|
if (classification.kind === 'rate_limit' && classification.retryAfterMs) {
|
|
93
|
-
this.requestGate?.enterCooldown(
|
|
94
|
+
this.requestGate?.enterCooldown(currentProviderKey, Date.now() + classification.retryAfterMs, `Provider rate limit; retry-after ${classification.retryAfterMs}ms`);
|
|
94
95
|
}
|
|
95
96
|
attemptRecord.failureKind = classification.kind;
|
|
96
97
|
if (attemptRecord.semanticDeltaSeen && !attemptRecord.usage) {
|
|
@@ -101,7 +102,8 @@ class ProviderResilienceCoordinator {
|
|
|
101
102
|
const shouldFallback = !fallbackUsed &&
|
|
102
103
|
typeof ctx.fallbackModel === 'string' &&
|
|
103
104
|
ctx.fallbackModel.length > 0 &&
|
|
104
|
-
ctx.fallbackModel !== currentModel
|
|
105
|
+
(ctx.fallbackModel !== currentModel ||
|
|
106
|
+
(ctx.fallbackProviderKey ?? ctx.providerKey) !== currentProviderKey) &&
|
|
105
107
|
[
|
|
106
108
|
'rate_limit',
|
|
107
109
|
'provider_overloaded',
|
|
@@ -150,6 +152,7 @@ class ProviderResilienceCoordinator {
|
|
|
150
152
|
diagnostics.fallbackCount++;
|
|
151
153
|
(0, observability_1.incrementDiagnosticMetric)('provider.fallback');
|
|
152
154
|
currentModel = ctx.fallbackModel;
|
|
155
|
+
currentProviderKey = ctx.fallbackProviderKey ?? ctx.providerKey;
|
|
153
156
|
break;
|
|
154
157
|
case 'defer_until_cooldown':
|
|
155
158
|
diagnostics.finalState = 'retry_exhausted';
|
|
@@ -167,12 +170,13 @@ class ProviderResilienceCoordinator {
|
|
|
167
170
|
getConfig() {
|
|
168
171
|
return { ...this.config };
|
|
169
172
|
}
|
|
170
|
-
startAttempt(ctx, attempt,
|
|
173
|
+
startAttempt(ctx, attempt, model, providerKey) {
|
|
171
174
|
return {
|
|
172
175
|
attemptId: (0, crypto_1.randomUUID)().slice(0, 8),
|
|
173
176
|
logicalRequestId: ctx.logicalRequestId,
|
|
174
177
|
attemptNumber: attempt,
|
|
175
178
|
model,
|
|
179
|
+
providerKey,
|
|
176
180
|
startedAt: Date.now(),
|
|
177
181
|
endedAt: 0,
|
|
178
182
|
semanticDeltaSeen: false,
|
|
@@ -37,6 +37,8 @@ export declare class ProviderRequestGate {
|
|
|
37
37
|
* Priority ordering: lower number = higher priority.
|
|
38
38
|
*/
|
|
39
39
|
acquire(request: GateRequest): Promise<GateLease>;
|
|
40
|
+
/** Admit optional maintenance only when it cannot queue ahead of foreground work. */
|
|
41
|
+
tryAcquireSpeculative(providerKey: string): GateLease | undefined;
|
|
40
42
|
/**
|
|
41
43
|
* Enter cooldown for one provider key. Other providers may continue to use
|
|
42
44
|
* the shared concurrency budget. Existing requests are not aborted.
|
|
@@ -45,6 +47,7 @@ export declare class ProviderRequestGate {
|
|
|
45
47
|
/** Snapshot for diagnostics / UI. */
|
|
46
48
|
snapshot(providerKey?: string): GateSnapshot;
|
|
47
49
|
private tryDispatch;
|
|
50
|
+
private occupy;
|
|
48
51
|
private clearExpiredCooldowns;
|
|
49
52
|
private scheduleCooldownWake;
|
|
50
53
|
}
|