@cortex-agent/server 2026.10.15 → 2026.10.21
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/README.md +76 -50
- package/defaults/board/board.css +140 -62
- package/defaults/board/scaffold.html +36 -13
- package/defaults/config/environments/creative.json +0 -1
- package/defaults/config/environments/main.json +1 -2
- package/defaults/plugins/cortex-board/skills/board/SKILL.md +30 -22
- package/defaults/plugins/cortex-system/plugin.json +2 -2
- package/defaults/plugins/cortex-system/skills/browser/SKILL.md +56 -0
- package/dist/agent-adapter/claude/adapter.d.ts +2 -5
- package/dist/agent-adapter/claude/adapter.js +6 -5
- package/dist/agent-adapter/claude/assistant-blocks.d.ts +5 -0
- package/dist/agent-adapter/claude/assistant-blocks.js +61 -0
- package/dist/agent-adapter/claude/cache-refresh.d.ts +58 -0
- package/dist/agent-adapter/claude/cache-refresh.js +145 -0
- package/dist/agent-adapter/claude/cache-touch.d.ts +12 -0
- package/dist/agent-adapter/claude/cache-touch.js +75 -0
- package/dist/agent-adapter/claude/event-parser.d.ts +8 -3
- package/dist/agent-adapter/claude/event-parser.js +33 -17
- package/dist/agent-adapter/claude/event-translator.d.ts +2 -0
- package/dist/agent-adapter/claude/event-translator.js +2 -0
- package/dist/agent-adapter/claude/session-options.d.ts +6 -13
- package/dist/agent-adapter/claude/session-options.js +2 -13
- package/dist/agent-adapter/claude/spawn-args.d.ts +4 -21
- package/dist/agent-adapter/claude/spawn-args.js +17 -24
- package/dist/agent-adapter/claude/transcript-clear.d.ts +42 -0
- package/dist/agent-adapter/claude/transcript-clear.js +217 -0
- package/dist/agent-adapter/claude/turn-machine.d.ts +3 -2
- package/dist/agent-adapter/claude/turn-machine.js +21 -68
- package/dist/agent-adapter/claude/window-warmup.d.ts +13 -0
- package/dist/agent-adapter/claude/window-warmup.js +38 -0
- package/dist/agent-adapter/continuation-phase.js +3 -0
- package/dist/agent-adapter/normalize/event-types.d.ts +8 -0
- package/dist/agent-adapter/pi/adapter.d.ts +0 -1
- package/dist/agent-adapter/pi/adapter.js +5 -13
- package/dist/agent-adapter/pi/event-parser.d.ts +1 -1
- package/dist/agent-adapter/pi/event-parser.js +43 -27
- package/dist/agent-adapter/pi/mcp-bridge.d.ts +1 -1
- package/dist/agent-adapter/pi/pi-session.d.ts +2 -0
- package/dist/agent-adapter/pi/pi-session.js +15 -0
- package/dist/agent-adapter/pi/providers-config.d.ts +2 -2
- package/dist/agent-adapter/pi/providers-config.js +1 -1
- package/dist/agent-adapter/pi/quota-sink.d.ts +3 -3
- package/dist/agent-adapter/pi/quota-sink.js +3 -3
- package/dist/agent-adapter/pi/runtime.js +6 -1
- package/dist/agent-adapter/pi/session-options.d.ts +9 -13
- package/dist/agent-adapter/pi/session-options.js +12 -25
- package/dist/agent-adapter/run-events.d.ts +11 -10
- package/dist/agent-adapter/run-events.js +2 -0
- package/dist/agent-adapter/types.d.ts +5 -4
- package/dist/client-bundle/manifest.json +2 -2
- package/dist/core/codex-quota.d.ts +1 -1
- package/dist/core/codex-quota.js +1 -1
- package/dist/core/gateway-generator.d.ts +9 -11
- package/dist/core/gateway-generator.js +31 -58
- package/dist/core/locales/en.d.ts +51 -77
- package/dist/core/locales/slices/commands.d.ts +26 -31
- package/dist/core/locales/slices/commands.js +54 -64
- package/dist/core/locales/slices/init.d.ts +8 -19
- package/dist/core/locales/slices/init.js +17 -53
- package/dist/core/locales/slices/interactions.d.ts +3 -3
- package/dist/core/locales/slices/interactions.js +6 -6
- package/dist/core/locales/slices/notices.d.ts +1 -3
- package/dist/core/locales/slices/notices.js +2 -6
- package/dist/core/locales/slices/scheduling.d.ts +9 -9
- package/dist/core/locales/slices/scheduling.js +18 -18
- package/dist/core/locales/slices/status.d.ts +0 -4
- package/dist/core/locales/slices/status.js +0 -8
- package/dist/core/locales/slices/tui.d.ts +0 -1
- package/dist/core/locales/slices/tui.js +0 -2
- package/dist/core/locales/slices/uimsg.d.ts +4 -7
- package/dist/core/locales/slices/uimsg.js +9 -15
- package/dist/core/models-generator.d.ts +29 -0
- package/dist/core/models-generator.js +82 -0
- package/dist/core/paths.d.ts +1 -1
- package/dist/core/paths.js +1 -1
- package/dist/core/settings-spec.d.ts +25 -0
- package/dist/core/settings-spec.js +34 -0
- package/dist/core/status-format.d.ts +3 -2
- package/dist/core/status-format.js +2 -2
- package/dist/core/types/environment-types.d.ts +0 -2
- package/dist/domain/agents/agent-state.d.ts +11 -56
- package/dist/domain/agents/agent-state.js +48 -115
- package/dist/domain/agents/agent-switch.d.ts +2 -24
- package/dist/domain/agents/agent-switch.js +9 -72
- package/dist/domain/agents/config.d.ts +11 -61
- package/dist/domain/agents/config.js +47 -154
- package/dist/domain/agents/engine-selection.d.ts +21 -0
- package/dist/domain/agents/engine-selection.js +37 -0
- package/dist/domain/agents/environments/registry.js +2 -1
- package/dist/domain/agents/environments/resolve.js +0 -1
- package/dist/domain/agents/environments/schema.d.ts +0 -1
- package/dist/domain/agents/environments/schema.js +0 -1
- package/dist/domain/agents/index.d.ts +2 -1
- package/dist/domain/agents/index.js +3 -7
- package/dist/domain/agents/model-selection.d.ts +18 -70
- package/dist/domain/agents/model-selection.js +100 -150
- package/dist/domain/agents/models.d.ts +12 -0
- package/dist/domain/agents/models.js +94 -0
- package/dist/domain/agents/subagent/registry.d.ts +2 -0
- package/dist/domain/agents/subagent/registry.js +8 -0
- package/dist/domain/agents/subagent/runner.d.ts +5 -5
- package/dist/domain/agents/subagent/runner.js +12 -35
- package/dist/domain/auth/auth-status.d.ts +4 -4
- package/dist/domain/auth/auth-status.js +17 -28
- package/dist/domain/auth/gateway-sync.d.ts +6 -26
- package/dist/domain/auth/gateway-sync.js +31 -75
- package/dist/domain/benchmark/identity.d.ts +3 -5
- package/dist/domain/benchmark/identity.js +0 -1
- package/dist/domain/benchmark/production-attempt-identity.d.ts +6 -5
- package/dist/domain/benchmark/production-attempt-identity.js +32 -35
- package/dist/domain/benchmark/session-evidence.d.ts +2 -1
- package/dist/domain/benchmark/session-evidence.js +8 -1
- package/dist/domain/browser/broker.d.ts +99 -0
- package/dist/domain/browser/broker.js +487 -0
- package/dist/domain/costs/claude-account.js +21 -0
- package/dist/domain/costs/rate-limit-throttle.js +3 -1
- package/dist/domain/costs/reset-account.d.ts +2 -0
- package/dist/domain/costs/usage-service.d.ts +1 -1
- package/dist/domain/costs/usage-service.js +20 -7
- package/dist/domain/mcp/tools/context.d.ts +5 -6
- package/dist/domain/mcp/tools/context.js +17 -3
- package/dist/domain/mcp/tools/subagent.js +1 -1
- package/dist/domain/mcp/tools/ui-file.js +1 -1
- package/dist/domain/pi-providers/custom-provider-model.d.ts +1 -1
- package/dist/domain/pi-providers/custom-provider-model.js +1 -1
- package/dist/domain/remote/device-browser.js +1 -1
- package/dist/domain/remote/device-chrome-commands.js +2 -0
- package/dist/domain/remote/device-port.js +2 -2
- package/dist/domain/runs/attempt.d.ts +3 -3
- package/dist/domain/runs/attempt.js +2 -3
- package/dist/domain/runs/builders.d.ts +4 -4
- package/dist/domain/runs/builders.js +4 -5
- package/dist/domain/runs/compact.d.ts +4 -17
- package/dist/domain/runs/compact.js +14 -56
- package/dist/domain/runs/config-resolver.d.ts +15 -83
- package/dist/domain/runs/config-resolver.js +24 -150
- package/dist/domain/runs/engine-spec.d.ts +8 -8
- package/dist/domain/runs/engine-spec.js +15 -31
- package/dist/domain/runs/events.d.ts +1 -1
- package/dist/domain/runs/fallback.d.ts +6 -38
- package/dist/domain/runs/fallback.js +10 -72
- package/dist/domain/runs/notices.d.ts +1 -11
- package/dist/domain/runs/notices.js +3 -30
- package/dist/domain/runs/request.d.ts +4 -3
- package/dist/domain/runs/retryable-errors.d.ts +0 -13
- package/dist/domain/runs/retryable-errors.js +0 -17
- package/dist/domain/runs/run.d.ts +12 -42
- package/dist/domain/runs/run.js +40 -147
- package/dist/domain/runs/service.d.ts +1 -1
- package/dist/domain/runs/service.js +8 -3
- package/dist/domain/runs/spec-loader.d.ts +1 -1
- package/dist/domain/runs/spend.d.ts +1 -1
- package/dist/domain/runs/spend.js +1 -1
- package/dist/domain/scheduling/jobs/scheduled-task.d.ts +3 -2
- package/dist/domain/scheduling/jobs/scheduled-task.js +25 -19
- package/dist/domain/scheduling/schedule-ops.d.ts +0 -1
- package/dist/domain/scheduling/schedule-ops.js +2 -5
- package/dist/domain/scheduling/schedule-selection.d.ts +3 -0
- package/dist/domain/scheduling/schedule-selection.js +16 -0
- package/dist/domain/scheduling/schedule-spec.d.ts +6 -5
- package/dist/domain/scheduling/schedule-spec.js +6 -6
- package/dist/domain/scheduling/scheduler.d.ts +3 -1
- package/dist/domain/scheduling/scheduler.js +22 -21
- package/dist/domain/sessions/session-hooks.d.ts +5 -4
- package/dist/domain/sessions/session-hooks.js +15 -33
- package/dist/domain/sessions/session-lifecycle.d.ts +19 -51
- package/dist/domain/sessions/session-lifecycle.js +34 -96
- package/dist/domain/system/doctor.d.ts +3 -3
- package/dist/domain/system/doctor.js +22 -26
- package/dist/domain/system/own-bin-path.d.ts +13 -0
- package/dist/domain/system/own-bin-path.js +36 -0
- package/dist/domain/system/terminal-cli/index.d.ts +58 -0
- package/dist/domain/system/terminal-cli/index.js +100 -0
- package/dist/domain/system/terminal-cli/posix-profiles.d.ts +23 -0
- package/dist/domain/system/terminal-cli/posix-profiles.js +74 -0
- package/dist/domain/system/terminal-cli/registrar.d.ts +12 -0
- package/dist/domain/system/terminal-cli/registrar.js +1 -0
- package/dist/domain/system/terminal-cli/shims.d.ts +27 -0
- package/dist/domain/system/terminal-cli/shims.js +108 -0
- package/dist/domain/system/terminal-cli/state.d.ts +7 -0
- package/dist/domain/system/terminal-cli/state.js +36 -0
- package/dist/domain/system/terminal-cli/windows-user-path.d.ts +13 -0
- package/dist/domain/system/terminal-cli/windows-user-path.js +67 -0
- package/dist/domain/tui-session/tui-session-service.js +1 -1
- package/dist/domain/tui-session/types.d.ts +2 -2
- package/dist/domain/ui-service/app-router.d.ts +49 -71
- package/dist/domain/ui-service/app-router.js +9 -13
- package/dist/domain/ui-service/assistant-snapshots.js +2 -0
- package/dist/domain/ui-service/contract.parity.d.ts +19 -0
- package/dist/domain/ui-service/contract.parity.js +1 -0
- package/dist/domain/ui-service/inline-media-types.d.ts +18 -0
- package/dist/domain/ui-service/inline-media-types.js +1 -0
- package/dist/domain/ui-service/input-schemas.d.ts +52 -115
- package/dist/domain/ui-service/input-schemas.js +38 -84
- package/dist/domain/ui-service/mutate/auth.d.ts +1 -1
- package/dist/domain/ui-service/mutate/auth.js +3 -2
- package/dist/domain/ui-service/mutate/config.d.ts +0 -8
- package/dist/domain/ui-service/mutate/config.js +0 -22
- package/dist/domain/ui-service/mutate/models.d.ts +13 -0
- package/dist/domain/ui-service/mutate/models.js +137 -0
- package/dist/domain/ui-service/mutate/resolve-media.d.ts +4 -0
- package/dist/domain/ui-service/mutate/resolve-media.js +17 -0
- package/dist/domain/ui-service/mutate/sessions.d.ts +2 -2
- package/dist/domain/ui-service/mutate/sessions.js +29 -126
- package/dist/domain/ui-service/query/config.js +22 -42
- package/dist/domain/ui-service/query/models.js +2 -2
- package/dist/domain/ui-service/query/schedules.js +1 -1
- package/dist/domain/ui-service/query/sessions.js +7 -13
- package/dist/domain/ui-service/types.d.ts +51 -177
- package/dist/domain/ui-service/ui-service.d.ts +23 -49
- package/dist/domain/ui-service/ui-service.js +8 -6
- package/dist/entry/app.js +42 -19
- package/dist/entry/browser-cli.d.ts +39 -0
- package/dist/entry/browser-cli.js +317 -0
- package/dist/entry/cli-help.d.ts +1 -0
- package/dist/entry/cli-help.js +37 -6
- package/dist/entry/cli.js +16 -14
- package/dist/entry/daemon.js +2 -0
- package/dist/entry/init-auth.js +1 -1
- package/dist/entry/init.d.ts +7 -8
- package/dist/entry/init.js +89 -249
- package/dist/entry/path-cli.d.ts +4 -0
- package/dist/entry/path-cli.js +65 -0
- package/dist/entry/schedule-cli.js +13 -6
- package/dist/entry/shutdown.d.ts +1 -1
- package/dist/entry/shutdown.js +8 -1
- package/dist/entry/start-ui-http.js +8 -0
- package/dist/entry/ui-service-wiring.js +8 -10
- package/dist/events/event-types.d.ts +3 -2
- package/dist/orchestration/agent-runner.d.ts +2 -2
- package/dist/orchestration/agent-runner.js +10 -9
- package/dist/orchestration/benchmark-session-webhook.js +13 -1
- package/dist/orchestration/browser-webhook.d.ts +11 -0
- package/dist/orchestration/browser-webhook.js +28 -0
- package/dist/orchestration/cache-keep-warm.d.ts +77 -0
- package/dist/orchestration/cache-keep-warm.js +213 -0
- package/dist/orchestration/claude-window-warmup.d.ts +40 -0
- package/dist/orchestration/claude-window-warmup.js +126 -0
- package/dist/orchestration/conversation-request.d.ts +6 -10
- package/dist/orchestration/conversation-request.js +5 -23
- package/dist/orchestration/delta-coalescer.d.ts +4 -2
- package/dist/orchestration/delta-coalescer.js +5 -5
- package/dist/orchestration/edit-retry.js +9 -11
- package/dist/orchestration/inline-media-eager.d.ts +13 -0
- package/dist/orchestration/inline-media-eager.js +58 -0
- package/dist/orchestration/inline-media.d.ts +22 -0
- package/dist/orchestration/inline-media.js +151 -0
- package/dist/orchestration/interactions/ask-user-resume.js +3 -7
- package/dist/orchestration/interactions/interaction-handlers.js +6 -6
- package/dist/orchestration/mid-turn-inject.d.ts +2 -1
- package/dist/orchestration/mid-turn-inject.js +1 -1
- package/dist/orchestration/pending-injection-recovery.d.ts +2 -1
- package/dist/orchestration/pending-injection-recovery.js +1 -1
- package/dist/orchestration/routing/commands/index.js +4 -4
- package/dist/orchestration/routing/commands/mode.d.ts +5 -44
- package/dist/orchestration/routing/commands/mode.js +98 -272
- package/dist/orchestration/routing/commands/schedule.js +29 -18
- package/dist/orchestration/routing/commands/session.js +9 -9
- package/dist/orchestration/routing/commands/status.js +1 -1
- package/dist/orchestration/routing/commands/usage-format.js +3 -0
- package/dist/orchestration/routing/webhook.js +4 -0
- package/dist/orchestration/session-compact.d.ts +0 -1
- package/dist/orchestration/session-compact.js +5 -7
- package/dist/orchestration/session-events.d.ts +2 -1
- package/dist/orchestration/session-events.js +1 -0
- package/dist/orchestration/status-helpers.d.ts +0 -4
- package/dist/orchestration/status-helpers.js +0 -18
- package/dist/orchestration/subagent-webhook.js +9 -34
- package/dist/orchestration/team-webhook.d.ts +8 -9
- package/dist/orchestration/team-webhook.js +16 -42
- package/dist/orchestration/transcript-sink.d.ts +6 -0
- package/dist/orchestration/transcript-sink.js +21 -2
- package/dist/orchestration/turn/terminal.js +7 -7
- package/dist/orchestration/turn/turn-prep.d.ts +0 -8
- package/dist/orchestration/turn/turn-prep.js +0 -51
- package/dist/orchestration/turn/turn-tracking.d.ts +2 -2
- package/dist/orchestration/turn/turn-tracking.js +8 -5
- package/dist/orchestration/turn/turn.d.ts +0 -2
- package/dist/orchestration/turn/turn.js +13 -15
- package/dist/platform/adapters/tui/ports.d.ts +1 -1
- package/dist/platform/adapters/tui/tui-transcript.js +2 -0
- package/dist/platform/browser/agent-browser.d.ts +50 -0
- package/dist/platform/browser/agent-browser.js +165 -0
- package/dist/platform/browser/managed-browser.d.ts +1 -11
- package/dist/platform/browser/managed-browser.js +4 -12
- package/dist/platform/ui-http/browser-stream.d.ts +110 -0
- package/dist/platform/ui-http/browser-stream.js +447 -0
- package/dist/platform/ui-http/ui-http-server.d.ts +12 -0
- package/dist/platform/ui-http/ui-http-server.js +23 -6
- package/dist/store/conversation-history-reader.js +8 -0
- package/dist/store/conversation-history-repo.d.ts +8 -1
- package/dist/store/conversation-history-repo.js +5 -0
- package/dist/store/conversation-ledger-repo.d.ts +6 -6
- package/dist/store/conversation-ledger-repo.js +4 -4
- package/dist/store/models-repo.d.ts +18 -0
- package/dist/store/models-repo.js +74 -0
- package/dist/store/pending-injection-repo.d.ts +2 -1
- package/dist/store/pending-injection-repo.js +3 -1
- package/dist/store/retire-profiles-migration.d.ts +28 -0
- package/dist/store/retire-profiles-migration.js +335 -0
- package/dist/store/schedule-repo.d.ts +2 -1
- package/dist/store/session-registry-import.js +3 -2
- package/dist/store/session-registry-journal.d.ts +10 -13
- package/dist/store/session-registry-journal.js +48 -25
- package/dist/store/session-registry-repo.d.ts +4 -4
- package/dist/store/session-registry-repo.js +4 -5
- package/dist/store/version-migrations.d.ts +2 -3
- package/dist/store/version-migrations.js +19 -3
- package/dist/tui/slash-commands.js +2 -2
- package/dist/tui/turn-status.js +1 -1
- package/package.json +6 -4
- package/web/dist/assets/board-math-css-CB4GJ6qO.js +2 -0
- package/web/dist/assets/index-CaSZPg_H.css +1 -0
- package/web/dist/assets/index-CzOR7Edh.js +522 -0
- package/web/dist/assets/{index-CndZZ1IQ.js → index-cIGFv27z.js} +1 -1
- package/web/dist/index.html +3 -2
- package/web/dist/theme.css +6 -0
- package/dist/agent-adapter/browser-mcp-server.d.ts +0 -13
- package/dist/agent-adapter/browser-mcp-server.js +0 -28
- package/dist/agent-adapter/claude/browser-mcp.d.ts +0 -9
- package/dist/agent-adapter/claude/browser-mcp.js +0 -10
- package/dist/core/profile-generator.d.ts +0 -79
- package/dist/core/profile-generator.js +0 -215
- package/dist/domain/agents/profile-manager.d.ts +0 -103
- package/dist/domain/agents/profile-manager.js +0 -286
- package/dist/domain/agents/profile-switch.d.ts +0 -49
- package/dist/domain/agents/profile-switch.js +0 -62
- package/dist/domain/ui-service/mutate/profiles.d.ts +0 -36
- package/dist/domain/ui-service/mutate/profiles.js +0 -151
- package/dist/store/profile-repo.d.ts +0 -20
- package/dist/store/profile-repo.js +0 -97
- package/web/dist/assets/index-B76ueW3q.js +0 -494
- package/web/dist/assets/index-C8O0yxg8.css +0 -1
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { resolveMcpComposition } from '../types.js';
|
|
2
2
|
import { fromCanonical } from '../../core/tool-names.js';
|
|
3
|
-
import { browserMcpServer } from '../browser-mcp-server.js';
|
|
4
3
|
import { MCP_TOOL_ALLOWLIST_ENV } from '../../core/mcp-tool-gate.js';
|
|
5
4
|
export const PI_MCP_COMPOSITION_ENV = 'CORTEX_PI_MCP_COMPOSITION';
|
|
6
5
|
export const PI_INTERACTION_BRIDGE_ENV = 'CORTEX_PI_INTERACTION_BRIDGE';
|
|
@@ -8,7 +7,8 @@ export const PI_TEAM_LEAD_ENV = 'CORTEX_PI_TEAM_LEAD';
|
|
|
8
7
|
export const PI_TEAM_WORKER_ENV = 'CORTEX_PI_TEAM_WORKER';
|
|
9
8
|
const RESET_CONTEXT_KEYS = [
|
|
10
9
|
'SLACK_CHANNEL', 'FEISHU_CHANNEL',
|
|
11
|
-
'CORTEX_SESSION_ID', 'CORTEX_PROFILE',
|
|
10
|
+
'CORTEX_SESSION_ID', 'CORTEX_PROFILE', // Strip the retired context key from inherited env.
|
|
11
|
+
'CORTEX_BACKEND', 'CORTEX_MODEL', 'CORTEX_PROVIDER', 'CORTEX_THINKING', 'CORTEX_MODE',
|
|
12
12
|
'CORTEX_PROJECT', 'CORTEX_SESSION_NAME', 'CORTEX_EXECUTION_ID',
|
|
13
13
|
'CORTEX_CALLBACK_SOURCE', 'CORTEX_SCHEDULE_TASK_ID',
|
|
14
14
|
'CORTEX_CONFIG_IMMUTABLE', 'CORTEX_PRODUCTION_AUTH_FILE',
|
|
@@ -23,10 +23,13 @@ function setOptional(env, key, value) {
|
|
|
23
23
|
}
|
|
24
24
|
function applyContext(env, options) {
|
|
25
25
|
const context = options.context;
|
|
26
|
+
setOptional(env, 'CORTEX_MODEL', context?.selection?.model);
|
|
27
|
+
setOptional(env, 'CORTEX_PROVIDER', context?.selection?.provider);
|
|
28
|
+
setOptional(env, 'CORTEX_THINKING', context?.selection?.thinking);
|
|
29
|
+
setOptional(env, 'CORTEX_MODE', context?.selection?.mode);
|
|
26
30
|
setOptional(env, 'CORTEX_SESSION_ID', context?.trackSessionId ?? options.sessionId);
|
|
27
31
|
setOptional(env, 'CORTEX_CALLBACK_SOURCE', options.callbackSource);
|
|
28
32
|
setOptional(env, 'CORTEX_SCHEDULE_TASK_ID', options.scheduleTaskId);
|
|
29
|
-
setOptional(env, 'CORTEX_PROFILE', context?.profile);
|
|
30
33
|
setOptional(env, 'CORTEX_PROJECT', context?.project);
|
|
31
34
|
setOptional(env, 'CORTEX_EXECUTION_ID', context?.executionId);
|
|
32
35
|
}
|
|
@@ -36,7 +39,7 @@ function applyContext(env, options) {
|
|
|
36
39
|
* read their scope from it, and it doubles as part of the pooled-session identity.
|
|
37
40
|
*/
|
|
38
41
|
export function buildPiEnv(options, inheritedEnv = process.env) {
|
|
39
|
-
const env = { ...inheritedEnv, ...(options.
|
|
42
|
+
const env = { ...inheritedEnv, ...(options.routeEnv ?? {}) };
|
|
40
43
|
for (const key of RESET_CONTEXT_KEYS)
|
|
41
44
|
delete env[key];
|
|
42
45
|
// After the merge: deletion is the only way to express "absent", since '' is a legal value here.
|
|
@@ -83,28 +86,11 @@ function allowedToolLabels(spec) {
|
|
|
83
86
|
function subagentMarker(spec) {
|
|
84
87
|
return spec.env.sets?.CORTEX_PI_SUBAGENT === '1' ? '1' : undefined;
|
|
85
88
|
}
|
|
86
|
-
/**
|
|
87
|
-
* Plugin MCP servers for this session. Browser control rides along like any other plugin server,
|
|
88
|
-
* gated on `direct` for the same reason Claude gates it: an unattended worker sharing one browser
|
|
89
|
-
* is a cross-run side channel, not a feature.
|
|
90
|
-
*/
|
|
89
|
+
/** Plugin MCP servers for this session; only the direct composition carries them. */
|
|
91
90
|
export function pluginMcpServers(spec, composition) {
|
|
92
91
|
if (composition !== 'direct')
|
|
93
92
|
return [];
|
|
94
|
-
|
|
95
|
-
if (spec.mcp.browserCdpEndpoint && composition === 'direct') {
|
|
96
|
-
servers.push(browserMcpServer(spec.mcp.browserCdpEndpoint));
|
|
97
|
-
}
|
|
98
|
-
return servers;
|
|
99
|
-
}
|
|
100
|
-
/** Thinking level: the profile field wins unless `extraOption` carries an explicit `--thinking`. */
|
|
101
|
-
function thinkingLevel(spec) {
|
|
102
|
-
const explicit = spec.extraOption?.['--thinking'];
|
|
103
|
-
return explicit || spec.model.thinking || null;
|
|
104
|
-
}
|
|
105
|
-
/** `extraOption` keys other than `--thinking` were PI CLI flags; there is no CLI to hand them to. */
|
|
106
|
-
export function unsupportedExtraOptions(spec) {
|
|
107
|
-
return Object.keys(spec.extraOption ?? {}).filter((key) => key !== '--thinking');
|
|
93
|
+
return [...(spec.mcp.servers ?? [])];
|
|
108
94
|
}
|
|
109
95
|
export function buildSessionRequest(spec, inputs) {
|
|
110
96
|
const composition = resolveMcpComposition(spec.mcp.composition);
|
|
@@ -114,7 +100,7 @@ export function buildSessionRequest(spec, inputs) {
|
|
|
114
100
|
channel: spec.context.channel,
|
|
115
101
|
callbackSource: spec.context.callbackSource,
|
|
116
102
|
scheduleTaskId: spec.context.scheduleTaskId,
|
|
117
|
-
|
|
103
|
+
routeEnv: spec.env.sets,
|
|
118
104
|
unsetEnv: spec.env.unsets,
|
|
119
105
|
context: spec.env.context,
|
|
120
106
|
piAgentDir: inputs.agentDir,
|
|
@@ -140,7 +126,8 @@ export function buildSessionRequest(spec, inputs) {
|
|
|
140
126
|
sessionPath: inputs.sessionPath,
|
|
141
127
|
provider: spec.model.provider ?? null,
|
|
142
128
|
model: spec.model.id ? stripModelSuffix(spec.model.id) : null,
|
|
143
|
-
|
|
129
|
+
benchmarkMaxOutputTokens: spec.model.benchmarkMaxOutputTokens,
|
|
130
|
+
thinking: spec.model.thinking ?? null,
|
|
144
131
|
systemPrompt: spec.prompt.system || null,
|
|
145
132
|
appendSystemPrompt: promptValues(spec.prompt.append),
|
|
146
133
|
// PI has no skill layer of its own to switch off: its skills are exactly the roots handed to
|
|
@@ -6,13 +6,9 @@ import type { NormalizedEvent, ToolUseSubagent } from './normalize/event-types.j
|
|
|
6
6
|
* (Claude background tasks, PI deferred completion, post-result injected messages).
|
|
7
7
|
* - `done` — terminal bookkeeping after every background task has settled. */
|
|
8
8
|
export type RunPhase = 'foreground' | 'background' | 'done';
|
|
9
|
-
/** Opaque label identifying one attempt of the fallback chain, e.g. `model/mode`.
|
|
10
|
-
* The plan sketches `run_fallback` with this type but does not define it; declared here so the
|
|
11
|
-
* event union is self-contained until `domain/runs/run.ts` owns the real shape. */
|
|
12
|
-
export type AttemptLabel = string;
|
|
13
9
|
/** The one event union every run produces. Passthrough kinds keep the exact field names of the
|
|
14
10
|
* `NormalizedEvent` member they translate from and add a `phase` tag; the remaining kinds are the
|
|
15
|
-
* run's own vocabulary (dialogs, injections, accounting,
|
|
11
|
+
* run's own vocabulary (dialogs, injections, accounting, terminal results). */
|
|
16
12
|
export type RunEvent = {
|
|
17
13
|
type: 'engine_started';
|
|
18
14
|
backendSessionId: string;
|
|
@@ -36,6 +32,16 @@ export type RunEvent = {
|
|
|
36
32
|
text: string;
|
|
37
33
|
blockId: string;
|
|
38
34
|
phase: RunPhase;
|
|
35
|
+
} | {
|
|
36
|
+
type: 'assistant_thinking';
|
|
37
|
+
text: string;
|
|
38
|
+
blockId?: string;
|
|
39
|
+
phase: RunPhase;
|
|
40
|
+
} | {
|
|
41
|
+
type: 'assistant_thinking_delta';
|
|
42
|
+
text: string;
|
|
43
|
+
blockId: string;
|
|
44
|
+
phase: RunPhase;
|
|
39
45
|
} | {
|
|
40
46
|
type: 'tool_use';
|
|
41
47
|
toolUseId: string;
|
|
@@ -124,11 +130,6 @@ export type RunEvent = {
|
|
|
124
130
|
} | {
|
|
125
131
|
type: 'turn_progress';
|
|
126
132
|
numTurns: number;
|
|
127
|
-
} | {
|
|
128
|
-
type: 'run_fallback';
|
|
129
|
-
from: AttemptLabel;
|
|
130
|
-
to: AttemptLabel;
|
|
131
|
-
reason: 'rate-limited' | 'transport-error';
|
|
132
133
|
} | {
|
|
133
134
|
type: 'foreground_result';
|
|
134
135
|
result: AgentResult;
|
|
@@ -3,6 +3,7 @@ import type { NormalizedEvent, ToolUseSubagent } from './normalize/event-types.j
|
|
|
3
3
|
import type { AwaitBackground } from './continuation-phase.js';
|
|
4
4
|
import type { RunEvent } from './run-events.js';
|
|
5
5
|
import type { AgentResult, ContextUsage, ToolResultImage } from '../core/types/agent-types.js';
|
|
6
|
+
import type { EngineSelection } from '../domain/agents/engine-selection.js';
|
|
6
7
|
import type { Backend } from '../core/types/agent-types.js';
|
|
7
8
|
export type { Backend };
|
|
8
9
|
export type McpComposition = 'direct' | 'none';
|
|
@@ -29,7 +30,8 @@ export interface RateLimitOrigin {
|
|
|
29
30
|
export type RateLimitReporter = (info: RateLimitObservation, origin: RateLimitOrigin) => Promise<void>;
|
|
30
31
|
/** Cortex execution context surfaced to child processes as CORTEX_* env vars. */
|
|
31
32
|
export interface CortexContextEnv {
|
|
32
|
-
|
|
33
|
+
/** The actual selected attempt, not the request's original selection. */
|
|
34
|
+
selection?: EngineSelection;
|
|
33
35
|
project?: string | null;
|
|
34
36
|
/** Stable Cortex tracking id (decoupled from the backend `sessionId`). Surfaced as
|
|
35
37
|
* CORTEX_SESSION_ID so session-activity logs + MCP context tools key on the stable UI-facing
|
|
@@ -55,7 +57,7 @@ export interface EngineSpec {
|
|
|
55
57
|
id?: string;
|
|
56
58
|
provider?: string;
|
|
57
59
|
thinking?: string;
|
|
58
|
-
|
|
60
|
+
benchmarkMaxOutputTokens?: number;
|
|
59
61
|
};
|
|
60
62
|
prompt: {
|
|
61
63
|
system?: string;
|
|
@@ -77,7 +79,6 @@ export interface EngineSpec {
|
|
|
77
79
|
servers?: McpServerConfig[];
|
|
78
80
|
allowlist?: string[];
|
|
79
81
|
configPaths?: string[];
|
|
80
|
-
browserCdpEndpoint?: string;
|
|
81
82
|
};
|
|
82
83
|
env: {
|
|
83
84
|
sets?: Record<string, string>;
|
|
@@ -110,7 +111,6 @@ export interface EngineSpec {
|
|
|
110
111
|
callbackSource?: string;
|
|
111
112
|
scheduleTaskId?: string;
|
|
112
113
|
};
|
|
113
|
-
extraOption?: Record<string, string>;
|
|
114
114
|
backend: {
|
|
115
115
|
kind: 'claude';
|
|
116
116
|
claudeAgent?: string;
|
|
@@ -193,6 +193,7 @@ export interface BackgroundTurnSink {
|
|
|
193
193
|
/** Assistant text from the continuation turn (append to the original reply). `subagent` is set
|
|
194
194
|
* only when a native subagent produced it (see ToolUseSubagent). */
|
|
195
195
|
onAssistantText: (text: string, model?: string | null, subagent?: ToolUseSubagent) => void;
|
|
196
|
+
onAssistantThinking?: (text: string, blockId?: string) => void;
|
|
196
197
|
/** Optional tool_use trace from the continuation turn, preserving its correlation id and,
|
|
197
198
|
* when a native subagent made the call, its attribution. */
|
|
198
199
|
onToolUse?: (name: string, input: any, toolUseId?: string, subagent?: ToolUseSubagent) => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Provider slug this reading is attributed to; matches the gateway route and
|
|
1
|
+
/** Provider slug this reading is attributed to; matches the gateway route and model provider. */
|
|
2
2
|
export declare const CODEX_PROVIDER = "openai-codex";
|
|
3
3
|
export interface QuotaWindow {
|
|
4
4
|
/** Codex limit family, preserving the provider's primary/secondary distinction. */
|
package/dist/core/codex-quota.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Provider slug this reading is attributed to; matches the gateway route and
|
|
1
|
+
/** Provider slug this reading is attributed to; matches the gateway route and model provider. */
|
|
2
2
|
export const CODEX_PROVIDER = 'openai-codex';
|
|
3
3
|
/** The two limit buckets Codex advertises per response. `secondary` is empty on plans without a
|
|
4
4
|
* short window (pro, 2026-08), so a bucket is only real when its window length is positive. */
|
|
@@ -23,13 +23,13 @@ export interface MergeGatewayResult {
|
|
|
23
23
|
}>;
|
|
24
24
|
}
|
|
25
25
|
export interface GatewayValidationIssue {
|
|
26
|
-
|
|
26
|
+
model: string;
|
|
27
27
|
mode: string;
|
|
28
28
|
provider?: string;
|
|
29
29
|
reason: string;
|
|
30
30
|
}
|
|
31
31
|
export interface DiscoveredEndpoint {
|
|
32
|
-
/** Mode key in gateway.yaml
|
|
32
|
+
/** Mode key in gateway.yaml (e.g. "plan", "deepseek", "openai-codex") */
|
|
33
33
|
mode: string;
|
|
34
34
|
/** Endpoint group name (e.g. "anthropic", "deepseek", "openai-codex") */
|
|
35
35
|
endpoint: string;
|
|
@@ -40,7 +40,7 @@ export interface DiscoveredEndpoint {
|
|
|
40
40
|
/** Model IDs known to be available for this endpoint */
|
|
41
41
|
models: string[];
|
|
42
42
|
/** Whether gateway.yaml should render an endpoint section for this entry. PI providers without a
|
|
43
|
-
* known upstream URL are surfaced as
|
|
43
|
+
* known upstream URL are surfaced as models but skipped in gateway.yaml. */
|
|
44
44
|
gatewayManaged: boolean;
|
|
45
45
|
/** The model this endpoint recommends when nothing is chosen — PI's per-provider default, or the
|
|
46
46
|
* newest Claude flagship. Always one of `models`; absent when the endpoint has no preference. */
|
|
@@ -77,12 +77,12 @@ export interface DiscoverEndpointsOptions {
|
|
|
77
77
|
* @param backends - Optional filter: when provided, only discover endpoints for the listed backends
|
|
78
78
|
* (e.g. `['claude']`, `['pi']`, `['claude', 'pi']`). When omitted, all backends are discovered.
|
|
79
79
|
*
|
|
80
|
-
* Claude endpoints come first, then PI providers in PI's order;
|
|
80
|
+
* Claude endpoints come first, then PI providers in PI's order; model recommendations follow that order.
|
|
81
81
|
* - Claude Code plan mode: only when Claude Code holds a subscription login.
|
|
82
82
|
* - Claude Code api mode: only when a real ANTHROPIC_API_KEY is available.
|
|
83
83
|
* - PI providers: those PI reports usable auth for. Each provider becomes one endpoint with
|
|
84
84
|
* `mode = endpoint = provider name`. `gatewayManaged` is true only if the provider has a known
|
|
85
|
-
* upstream URL in PI_PROVIDER_UPSTREAM (otherwise
|
|
85
|
+
* upstream URL in PI_PROVIDER_UPSTREAM (otherwise the model is discovered but gateway.yaml entry is
|
|
86
86
|
* skipped).
|
|
87
87
|
*/
|
|
88
88
|
export declare function discoverEndpoints(backends?: string[], options?: DiscoverEndpointsOptions): Promise<DiscoveredEndpoint[]>;
|
|
@@ -90,7 +90,7 @@ export declare function discoverEndpoints(backends?: string[], options?: Discove
|
|
|
90
90
|
* Generate gateway.yaml content from discovered endpoints.
|
|
91
91
|
* Outputs a formatted YAML string with comments explaining each mode.
|
|
92
92
|
*
|
|
93
|
-
* Endpoints with gatewayManaged=false are skipped (their
|
|
93
|
+
* Endpoints with gatewayManaged=false are skipped (their models still exist in models.json,
|
|
94
94
|
* but gateway.yaml has no entry for them — PI traffic to those providers is currently direct).
|
|
95
95
|
*/
|
|
96
96
|
export declare function generateGatewayYaml(endpoints: DiscoveredEndpoint[], defaultMode?: string): string;
|
|
@@ -104,7 +104,7 @@ export declare function discoveredToEndpointMap(endpoints: DiscoveredEndpoint[])
|
|
|
104
104
|
/**
|
|
105
105
|
* Merge freshly discovered endpoints over an existing gateway config.
|
|
106
106
|
*
|
|
107
|
-
* Add-only at the (endpoint, mode) PAIR level (
|
|
107
|
+
* Add-only at the (endpoint, mode) PAIR level (preserving existing operator choices): a pair
|
|
108
108
|
* absent from the existing file is added from discovery; any pair that already exists is preserved
|
|
109
109
|
* verbatim — its base_url, auth_style and (critically) managed keys are never clobbered. This both
|
|
110
110
|
* fixes the original bug (a missing mode gets added) and protects hand-customized routes, e.g. a
|
|
@@ -125,11 +125,9 @@ export declare function writeMergedGatewayYaml(discovered: DiscoveredEndpoint[],
|
|
|
125
125
|
result: MergeGatewayResult;
|
|
126
126
|
};
|
|
127
127
|
/**
|
|
128
|
-
*
|
|
129
|
-
* that actually exists in the merged endpoint map. Pure + non-fatal — returns the list of problems
|
|
130
|
-
* so the caller can warn loudly. This is what catches the `400 Unknown mode: <x>` class of bug.
|
|
128
|
+
* Check the default's selected route and whether each favorite has an available endpoint route.
|
|
131
129
|
*/
|
|
132
|
-
export declare function
|
|
130
|
+
export declare function validateModelsAgainstGateway(mergedEndpoints: EndpointMap, configDir?: string): GatewayValidationIssue[];
|
|
133
131
|
/**
|
|
134
132
|
* Run discovery and return the YAML string (without writing to disk).
|
|
135
133
|
* Useful for dry-run / preview.
|
|
@@ -23,7 +23,7 @@ const FLAT_MODE = 'default';
|
|
|
23
23
|
* Map a PI built-in provider name to its real upstream URL. Used by `generateGatewayYaml` so PI
|
|
24
24
|
* traffic can be routed through the gateway. Entries are sourced from PI source / docs.
|
|
25
25
|
*
|
|
26
|
-
* Providers absent from this table are still surfaced as
|
|
26
|
+
* Providers absent from this table are still surfaced as models, but no gateway endpoint
|
|
27
27
|
* is generated for them (gatewayManaged=false). PI will then either fail (if the cortex spawn path
|
|
28
28
|
* forces gateway routing) or direct-call the upstream (if the spawn path leaves models.json
|
|
29
29
|
* untouched for that provider). Full provider plumbing remains future work.
|
|
@@ -55,7 +55,7 @@ const PI_PROVIDER_UPSTREAM = {
|
|
|
55
55
|
'google-antigravity': { url: 'https://daily-cloudcode-pa.sandbox.googleapis.com', auth_style: 'bearer' },
|
|
56
56
|
// Other built-ins
|
|
57
57
|
google: { url: 'https://generativelanguage.googleapis.com/v1beta', auth_style: 'bearer' },
|
|
58
|
-
// amazon-bedrock / google-vertex / azure
|
|
58
|
+
// amazon-bedrock / google-vertex / azure / cloudflare-workers-ai use
|
|
59
59
|
// env-driven URLs (region / account ID / resource name) — not safely templated here.
|
|
60
60
|
// Users wanting these through the gateway must edit gateway.yaml manually.
|
|
61
61
|
};
|
|
@@ -126,12 +126,12 @@ async function scanPiForEndpoints() {
|
|
|
126
126
|
* @param backends - Optional filter: when provided, only discover endpoints for the listed backends
|
|
127
127
|
* (e.g. `['claude']`, `['pi']`, `['claude', 'pi']`). When omitted, all backends are discovered.
|
|
128
128
|
*
|
|
129
|
-
* Claude endpoints come first, then PI providers in PI's order;
|
|
129
|
+
* Claude endpoints come first, then PI providers in PI's order; model recommendations follow that order.
|
|
130
130
|
* - Claude Code plan mode: only when Claude Code holds a subscription login.
|
|
131
131
|
* - Claude Code api mode: only when a real ANTHROPIC_API_KEY is available.
|
|
132
132
|
* - PI providers: those PI reports usable auth for. Each provider becomes one endpoint with
|
|
133
133
|
* `mode = endpoint = provider name`. `gatewayManaged` is true only if the provider has a known
|
|
134
|
-
* upstream URL in PI_PROVIDER_UPSTREAM (otherwise
|
|
134
|
+
* upstream URL in PI_PROVIDER_UPSTREAM (otherwise the model is discovered but gateway.yaml entry is
|
|
135
135
|
* skipped).
|
|
136
136
|
*/
|
|
137
137
|
export async function discoverEndpoints(backends, options = {}) {
|
|
@@ -156,7 +156,7 @@ function anthropicEndpoint(mode, models, defaultModel) {
|
|
|
156
156
|
}
|
|
157
157
|
/**
|
|
158
158
|
* Claude Code's endpoints, each present only when its credential is: an endpoint nobody logged
|
|
159
|
-
* into would otherwise become the default
|
|
159
|
+
* into would otherwise become the default selection and lock the user out of the one they did log
|
|
160
160
|
* into (merges never overwrite an existing plan/execute).
|
|
161
161
|
*/
|
|
162
162
|
async function discoverClaudeEndpoints(options) {
|
|
@@ -218,7 +218,7 @@ function capitalize(s) {
|
|
|
218
218
|
* Generate gateway.yaml content from discovered endpoints.
|
|
219
219
|
* Outputs a formatted YAML string with comments explaining each mode.
|
|
220
220
|
*
|
|
221
|
-
* Endpoints with gatewayManaged=false are skipped (their
|
|
221
|
+
* Endpoints with gatewayManaged=false are skipped (their models still exist in models.json,
|
|
222
222
|
* but gateway.yaml has no entry for them — PI traffic to those providers is currently direct).
|
|
223
223
|
*/
|
|
224
224
|
export function generateGatewayYaml(endpoints, defaultMode) {
|
|
@@ -280,7 +280,7 @@ export function generateGatewayYaml(endpoints, defaultMode) {
|
|
|
280
280
|
for (const s of skipped) {
|
|
281
281
|
lines.push(`# ${s.mode} (${s.models.length} model${s.models.length === 1 ? '' : 's'})`);
|
|
282
282
|
}
|
|
283
|
-
lines.push('# These providers appear in
|
|
283
|
+
lines.push('# These providers appear in models.json but are not routed through this gateway.');
|
|
284
284
|
}
|
|
285
285
|
lines.push('');
|
|
286
286
|
return lines.join('\n');
|
|
@@ -355,7 +355,7 @@ export function discoveredToEndpointMap(endpoints) {
|
|
|
355
355
|
/**
|
|
356
356
|
* Merge freshly discovered endpoints over an existing gateway config.
|
|
357
357
|
*
|
|
358
|
-
* Add-only at the (endpoint, mode) PAIR level (
|
|
358
|
+
* Add-only at the (endpoint, mode) PAIR level (preserving existing operator choices): a pair
|
|
359
359
|
* absent from the existing file is added from discovery; any pair that already exists is preserved
|
|
360
360
|
* verbatim — its base_url, auth_style and (critically) managed keys are never clobbered. This both
|
|
361
361
|
* fixes the original bug (a missing mode gets added) and protects hand-customized routes, e.g. a
|
|
@@ -476,64 +476,37 @@ export function writeMergedGatewayYaml(discovered, outputDir, defaultMode) {
|
|
|
476
476
|
return { path: configPath, result };
|
|
477
477
|
}
|
|
478
478
|
/**
|
|
479
|
-
*
|
|
480
|
-
* that actually exists in the merged endpoint map. Pure + non-fatal — returns the list of problems
|
|
481
|
-
* so the caller can warn loudly. This is what catches the `400 Unknown mode: <x>` class of bug.
|
|
479
|
+
* Check the default's selected route and whether each favorite has an available endpoint route.
|
|
482
480
|
*/
|
|
483
|
-
export function
|
|
484
|
-
const
|
|
481
|
+
export function validateModelsAgainstGateway(mergedEndpoints, configDir = CONFIG_DIR) {
|
|
482
|
+
const file = path.join(configDir, 'models.json');
|
|
485
483
|
let parsed;
|
|
486
484
|
try {
|
|
487
|
-
if (!existsSync(
|
|
485
|
+
if (!existsSync(file))
|
|
488
486
|
return [];
|
|
489
|
-
parsed = JSON.parse(readFileSync(
|
|
487
|
+
parsed = JSON.parse(readFileSync(file, 'utf8'));
|
|
490
488
|
}
|
|
491
|
-
catch (
|
|
492
|
-
log.warn(`Failed to read
|
|
489
|
+
catch (error) {
|
|
490
|
+
log.warn(`Failed to read models.json for validation: ${error.message}`);
|
|
493
491
|
return [];
|
|
494
492
|
}
|
|
495
|
-
if (!isPlainObject(parsed)
|
|
493
|
+
if (!isPlainObject(parsed))
|
|
496
494
|
return [];
|
|
497
|
-
const
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
return; // Unknown backends do not route through gateway modes here.
|
|
513
|
-
if (backend === 'pi' && !provider) {
|
|
514
|
-
issues.push({ profile: label, mode, reason: `pi profile is missing a provider (cannot resolve gateway endpoint)` });
|
|
515
|
-
return;
|
|
516
|
-
}
|
|
517
|
-
if (!endpoint || !mergedEndpoints[endpoint]?.[mode]) {
|
|
518
|
-
const reason = !modeExistsAnywhere(mode)
|
|
519
|
-
? `mode "${mode}" is not configured in gateway.yaml`
|
|
520
|
-
: `endpoint "${endpoint}" is not configured under mode "${mode}"`;
|
|
521
|
-
issues.push({ profile: label, mode, provider, reason });
|
|
522
|
-
}
|
|
523
|
-
};
|
|
524
|
-
for (const [name, profileVal] of Object.entries(parsed.profiles)) {
|
|
525
|
-
if (!isPlainObject(profileVal))
|
|
526
|
-
continue;
|
|
527
|
-
checkEntry(profileVal, name);
|
|
528
|
-
const fallback = profileVal.fallback;
|
|
529
|
-
if (Array.isArray(fallback)) {
|
|
530
|
-
fallback.forEach((fb, i) => {
|
|
531
|
-
if (isPlainObject(fb))
|
|
532
|
-
checkEntry(fb, `${name} (fallback #${i + 1})`);
|
|
533
|
-
});
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
return issues;
|
|
495
|
+
const entries = [parsed.default, ...(Array.isArray(parsed.favorites) ? parsed.favorites : [])];
|
|
496
|
+
return entries.filter(isPlainObject).flatMap(entry => validateModelRoute(entry, mergedEndpoints));
|
|
497
|
+
}
|
|
498
|
+
function validateModelRoute(entry, endpoints) {
|
|
499
|
+
const provider = typeof entry.provider === 'string' ? entry.provider : undefined;
|
|
500
|
+
const endpoint = entry.backend === 'claude' ? 'anthropic' : provider;
|
|
501
|
+
const mode = typeof entry.mode === 'string' ? entry.mode : '';
|
|
502
|
+
const model = String(entry.model ?? '(unknown)');
|
|
503
|
+
if (!endpoint)
|
|
504
|
+
return [{ model, mode, reason: 'PI model is missing a provider (cannot resolve gateway endpoint)' }];
|
|
505
|
+
const routes = endpoints[endpoint] ?? {};
|
|
506
|
+
const available = mode ? !!routes[mode] : Object.keys(routes).length > 0;
|
|
507
|
+
if (available)
|
|
508
|
+
return [];
|
|
509
|
+
return [{ model, mode, provider, reason: `endpoint "${endpoint}" has no configured ${mode ? `mode "${mode}"` : 'route'} in gateway.yaml` }];
|
|
537
510
|
}
|
|
538
511
|
/**
|
|
539
512
|
* Run discovery and return the YAML string (without writing to disk).
|