@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,196 +1,89 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { loadAgentState, saveAgentState
|
|
3
|
-
|
|
1
|
+
import { getDefaultSelection, getDefaultSelectionForBackend } from './models.js';
|
|
2
|
+
import { loadAgentState, saveAgentState } from './agent-state.js';
|
|
3
|
+
import { copySelection, modelKey } from './engine-selection.js';
|
|
4
4
|
let agentState = loadAgentState();
|
|
5
|
+
/** Startup migrations run after static imports and may replace the persisted state. */
|
|
6
|
+
export function reloadAgentState() {
|
|
7
|
+
agentState = loadAgentState();
|
|
8
|
+
}
|
|
5
9
|
function commit(next) {
|
|
10
|
+
saveAgentState(next);
|
|
6
11
|
agentState = next;
|
|
7
|
-
saveAgentState(agentState);
|
|
8
12
|
}
|
|
9
|
-
/** `map` with `key` set to `value`, or removed when `value` is null. */
|
|
10
13
|
function withEntry(map, key, value) {
|
|
11
14
|
const next = { ...map };
|
|
12
|
-
if (value)
|
|
15
|
+
if (value !== null)
|
|
13
16
|
next[key] = value;
|
|
14
17
|
else
|
|
15
18
|
delete next[key];
|
|
16
19
|
return next;
|
|
17
20
|
}
|
|
18
|
-
export function
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
21
|
+
export function getChannelSelection(channel) {
|
|
22
|
+
const selection = channel ? agentState.channelSelections[channel] : null;
|
|
23
|
+
return selection ? copySelection(selection) : null;
|
|
24
|
+
}
|
|
25
|
+
export function setChannelSelection(channel, selection) {
|
|
26
|
+
const next = selection ? copySelection(selection) : null;
|
|
27
|
+
commit({ ...agentState, channelSelections: withEntry(agentState.channelSelections, channel, next) });
|
|
28
|
+
}
|
|
29
|
+
export function clearChannelSelection(channel) {
|
|
30
|
+
setChannelSelection(channel, null);
|
|
31
|
+
}
|
|
32
|
+
export function getModelMemory() {
|
|
33
|
+
return Object.fromEntries(Object.entries(agentState.modelMemory).map(([key, value]) => [key, { ...value }]));
|
|
34
|
+
}
|
|
35
|
+
export function rememberModelSelection(selection) {
|
|
36
|
+
const memory = { thinking: selection.thinking, mode: selection.mode };
|
|
37
|
+
commit({ ...agentState, modelMemory: withEntry(agentState.modelMemory, modelKey(selection), memory) });
|
|
32
38
|
}
|
|
33
|
-
const DEFAULT_CLAUDE_MODEL = 'opus';
|
|
34
|
-
/** The Claude model a channel with no selection of its own runs — the default profile's (D5) —
|
|
35
|
-
* else the stock alias when that profile is not a Claude one or cannot be read. */
|
|
36
39
|
export function defaultClaudeModel() {
|
|
37
40
|
try {
|
|
38
|
-
|
|
39
|
-
if (profile.backend === 'claude' && profile.model)
|
|
40
|
-
return profile.model;
|
|
41
|
+
return getDefaultSelectionForBackend('claude')?.model ?? 'opus';
|
|
41
42
|
}
|
|
42
43
|
catch {
|
|
43
|
-
|
|
44
|
+
return 'opus';
|
|
44
45
|
}
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* The backend a channel runs: its profile's, falling back to the default profile's.
|
|
49
|
-
*
|
|
50
|
-
* DEVIATION from plan D5, which has this "degenerate into reading the session record". That was
|
|
51
|
-
* the right move while the session store keyed on `backend:channel` and the caller had to know the
|
|
52
|
-
* backend to find the session at all — but the backend is no longer part of the key, so no session
|
|
53
|
-
* lookup needs this any more. What is left are callers asking which backend a channel runs
|
|
54
|
-
* (conversation ledger, rollback, compaction support), and for them the profile is the source of
|
|
55
|
-
* truth, not a record of what some earlier session happened to use. Reading the record would also
|
|
56
|
-
* make this async and ripple through fifteen synchronous call sites for a worse answer.
|
|
57
|
-
*
|
|
58
|
-
* Equivalent to `resolveRunBackend({ channel })` minus the session/override layers. The two cannot
|
|
59
|
-
* be folded together here: `config-resolver` imports this module, so doing so would be an import
|
|
60
|
-
* cycle.
|
|
61
|
-
*/
|
|
46
|
+
}
|
|
62
47
|
export function resolveBackendForChannel(channel) {
|
|
63
|
-
const
|
|
64
|
-
if (
|
|
65
|
-
|
|
66
|
-
const cfg = resolveProfileConfig(profileName);
|
|
67
|
-
if (cfg.backend)
|
|
68
|
-
return cfg.backend;
|
|
69
|
-
}
|
|
70
|
-
catch {
|
|
71
|
-
// Profile referenced by channelProfiles no longer exists — fall through to the default.
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
// D5: with no daemon-wide backend left, the floor is the default profile's, and 'claude' only
|
|
75
|
-
// when profiles.json itself cannot be read.
|
|
48
|
+
const selection = getChannelSelection(channel);
|
|
49
|
+
if (selection)
|
|
50
|
+
return selection.backend;
|
|
76
51
|
try {
|
|
77
|
-
return
|
|
52
|
+
return getDefaultSelection().backend;
|
|
78
53
|
}
|
|
79
54
|
catch {
|
|
80
55
|
return 'claude';
|
|
81
56
|
}
|
|
82
57
|
}
|
|
83
|
-
|
|
84
|
-
if (!channel) {
|
|
85
|
-
commit({ ...agentState, activeProfile: profileName });
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
commit({ ...agentState, channelProfiles: withEntry(agentState.channelProfiles, channel, profileName) });
|
|
89
|
-
}
|
|
90
|
-
export function clearChannelProfile(channel) {
|
|
91
|
-
setActiveProfile(null, channel);
|
|
92
|
-
}
|
|
93
|
-
/** The channel's whole selection on top of its profile (model / provider / thinking). null when the
|
|
94
|
-
* channel runs its profile as declared, which is the normal case. */
|
|
95
|
-
export function getChannelOverride(channel) {
|
|
96
|
-
if (!channel)
|
|
97
|
-
return null;
|
|
98
|
-
const override = agentState.channelOverrides[channel];
|
|
99
|
-
return override && Object.keys(override).length > 0 ? { ...override } : null;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Patch the channel's selection. A field set to `null` is cleared, a field left out is untouched,
|
|
103
|
-
* and an override with nothing left in it is removed entirely (so "has a selection" stays a
|
|
104
|
-
* truthful question to ask of the map).
|
|
105
|
-
*
|
|
106
|
-
* Takes effect on the next turn — a live turn already has its EngineSpec.
|
|
107
|
-
*/
|
|
108
|
-
export function setChannelOverride(channel, patch) {
|
|
109
|
-
const overrides = { ...agentState.channelOverrides };
|
|
110
|
-
const next = { ...overrides[channel] };
|
|
111
|
-
for (const [field, value] of Object.entries(patch)) {
|
|
112
|
-
if (value === undefined)
|
|
113
|
-
continue;
|
|
114
|
-
if (value === null)
|
|
115
|
-
delete next[field];
|
|
116
|
-
else
|
|
117
|
-
next[field] = value;
|
|
118
|
-
}
|
|
119
|
-
if (Object.keys(next).length > 0)
|
|
120
|
-
overrides[channel] = next;
|
|
121
|
-
else
|
|
122
|
-
delete overrides[channel];
|
|
123
|
-
commit({ ...agentState, channelOverrides: overrides });
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Remember a composer's pick as the seed a brand-new conversation starts on.
|
|
127
|
-
*
|
|
128
|
-
* Written for direct (`web:`) channels only, by `applyChannelSelection` — never for a platform
|
|
129
|
-
* channel, and never for `!model` / `!thinking`, which pass `seedDefault: false`. Those are
|
|
130
|
-
* channel-scoped tools; letting one of them decide what the next Web session runs would be action
|
|
131
|
-
* at a distance. Clearing back to the profile IS a choice and is remembered as one — the
|
|
132
|
-
* seed then carries a profile and no overrides.
|
|
133
|
-
*/
|
|
58
|
+
/** Engine and agent picks are independent; a model pick preserves the environment seed. */
|
|
134
59
|
export function setSelectionDefault(seed) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const next = seed && agentName && !seed.agentName ? { ...seed, agentName } : seed;
|
|
140
|
-
commit({ ...agentState, selectionDefault: next ?? undefined });
|
|
141
|
-
}
|
|
142
|
-
/** Remember the composer's AGENT pick in the same seed, leaving the engine half alone. A null name
|
|
143
|
-
* records "the next conversation opens on the global default", which is a choice like any other. */
|
|
60
|
+
const agentName = seed?.agentName ?? agentState.selectionDefault?.agentName;
|
|
61
|
+
const next = seed ? { ...copySelection(seed), ...(agentName ? { agentName } : {}) } : undefined;
|
|
62
|
+
commit({ ...agentState, selectionDefault: next });
|
|
63
|
+
}
|
|
144
64
|
export function setSelectionDefaultAgent(agentName) {
|
|
145
|
-
const seed = { ...(agentState.selectionDefault ??
|
|
65
|
+
const seed = { ...(agentState.selectionDefault ?? getDefaultSelection()) };
|
|
146
66
|
if (agentName)
|
|
147
67
|
seed.agentName = agentName;
|
|
148
68
|
else
|
|
149
69
|
delete seed.agentName;
|
|
150
|
-
commit({ ...agentState, selectionDefault:
|
|
70
|
+
commit({ ...agentState, selectionDefault: seed });
|
|
151
71
|
}
|
|
152
|
-
/** The seed for the next conversation, or null when nothing has been picked on this host yet. */
|
|
153
72
|
export function getSelectionDefault() {
|
|
154
|
-
return agentState.selectionDefault
|
|
155
|
-
}
|
|
156
|
-
/** Drop every override the channel carries — what an explicit "run this profile as declared"
|
|
157
|
-
* (a profile switch) means. */
|
|
158
|
-
export function clearChannelOverride(channel) {
|
|
159
|
-
if (!agentState.channelOverrides[channel])
|
|
160
|
-
return;
|
|
161
|
-
const overrides = { ...agentState.channelOverrides };
|
|
162
|
-
delete overrides[channel];
|
|
163
|
-
commit({ ...agentState, channelOverrides: overrides });
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* The agent a channel runs: its own selection, else the global default. Null when neither is set
|
|
167
|
-
* and the caller's own fallback applies.
|
|
168
|
-
*
|
|
169
|
-
* The channel layer is what makes an agent a per-conversation choice rather than a daemon-wide
|
|
170
|
-
* one — the same shape `getActiveProfile` has, and deliberately so: profile and agent are two
|
|
171
|
-
* independent axes (which model vs which environment) and each has its own channel map.
|
|
172
|
-
*/
|
|
73
|
+
return agentState.selectionDefault ? { ...agentState.selectionDefault } : null;
|
|
74
|
+
}
|
|
173
75
|
export function getDefaultAgent(channel) {
|
|
174
|
-
|
|
175
|
-
return channelAgent || agentState.defaultAgent;
|
|
76
|
+
return (channel && agentState.channelAgents[channel]) || agentState.defaultAgent;
|
|
176
77
|
}
|
|
177
|
-
/** Set the agent for one channel (`channel` given) or the global default (omitted). A null name
|
|
178
|
-
* clears: for a channel that means "follow the global default again", globally it means "no
|
|
179
|
-
* default agent at all". */
|
|
180
78
|
export function setDefaultAgent(name, channel) {
|
|
181
|
-
if (!channel)
|
|
182
|
-
commit({ ...agentState, defaultAgent: name });
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
79
|
+
if (!channel)
|
|
80
|
+
return commit({ ...agentState, defaultAgent: name });
|
|
185
81
|
commit({ ...agentState, channelAgents: withEntry(agentState.channelAgents, channel, name) });
|
|
186
82
|
}
|
|
187
|
-
/** Drop the channel's agent selection — it follows the global default again. */
|
|
188
83
|
export function clearChannelAgent(channel) {
|
|
189
|
-
if (
|
|
190
|
-
|
|
191
|
-
setDefaultAgent(null, channel);
|
|
84
|
+
if (agentState.channelAgents[channel])
|
|
85
|
+
setDefaultAgent(null, channel);
|
|
192
86
|
}
|
|
193
|
-
/** Every channel that has selected an agent of its own. */
|
|
194
87
|
export function getChannelAgents() {
|
|
195
88
|
return { ...agentState.channelAgents };
|
|
196
89
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Backend } from '../../core/types/agent-types.js';
|
|
2
|
+
/** A complete, concrete engine choice. Environments are an independent axis. */
|
|
3
|
+
export interface EngineSelection {
|
|
4
|
+
backend: Backend;
|
|
5
|
+
provider: string | null;
|
|
6
|
+
model: string;
|
|
7
|
+
thinking: string | null;
|
|
8
|
+
mode: string;
|
|
9
|
+
}
|
|
10
|
+
export type ModelRef = Pick<EngineSelection, 'backend' | 'provider' | 'model'>;
|
|
11
|
+
export interface ModelsFile {
|
|
12
|
+
default: EngineSelection;
|
|
13
|
+
favorites: ModelRef[];
|
|
14
|
+
}
|
|
15
|
+
export declare function modelKey(ref: ModelRef): string;
|
|
16
|
+
export declare const THINKING_LEVELS_BY_BACKEND: Record<Backend, readonly string[]>;
|
|
17
|
+
export declare function isValidThinkingLevel(backend: Backend, level: string): boolean;
|
|
18
|
+
export declare function validateModelRef(value: unknown): asserts value is ModelRef;
|
|
19
|
+
export declare function validateEngineSelection(value: unknown): asserts value is EngineSelection;
|
|
20
|
+
/** Copy only the public selection fields, never retired or foreign configuration. */
|
|
21
|
+
export declare function copySelection(selection: EngineSelection): EngineSelection;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export function modelKey(ref) {
|
|
2
|
+
return JSON.stringify([ref.backend, ref.provider, ref.model]);
|
|
3
|
+
}
|
|
4
|
+
export const THINKING_LEVELS_BY_BACKEND = {
|
|
5
|
+
claude: ['low', 'medium', 'high', 'xhigh', 'max'],
|
|
6
|
+
pi: ['off', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'],
|
|
7
|
+
};
|
|
8
|
+
export function isValidThinkingLevel(backend, level) {
|
|
9
|
+
return THINKING_LEVELS_BY_BACKEND[backend]?.includes(level) ?? false;
|
|
10
|
+
}
|
|
11
|
+
const SAFE_NAME = /^[a-zA-Z0-9_-]+$/;
|
|
12
|
+
export function validateModelRef(value) {
|
|
13
|
+
const ref = value;
|
|
14
|
+
if (!ref || (ref.backend !== 'claude' && ref.backend !== 'pi'))
|
|
15
|
+
throw new Error('Invalid backend');
|
|
16
|
+
if (typeof ref.model !== 'string' || !ref.model.trim())
|
|
17
|
+
throw new Error('Model must be a non-empty string');
|
|
18
|
+
const validProvider = ref.backend === 'claude'
|
|
19
|
+
? ref.provider === null
|
|
20
|
+
: typeof ref.provider === 'string' && SAFE_NAME.test(ref.provider);
|
|
21
|
+
if (!validProvider)
|
|
22
|
+
throw new Error('Invalid provider: PI requires a provider; Claude requires null');
|
|
23
|
+
}
|
|
24
|
+
export function validateEngineSelection(value) {
|
|
25
|
+
validateModelRef(value);
|
|
26
|
+
const selection = value;
|
|
27
|
+
if (selection.thinking !== null && !isValidThinkingLevel(selection.backend, selection.thinking)) {
|
|
28
|
+
throw new Error(`Invalid thinking for backend '${selection.backend}'`);
|
|
29
|
+
}
|
|
30
|
+
if (typeof selection.mode !== 'string' || !SAFE_NAME.test(selection.mode))
|
|
31
|
+
throw new Error('Invalid mode');
|
|
32
|
+
}
|
|
33
|
+
/** Copy only the public selection fields, never retired or foreign configuration. */
|
|
34
|
+
export function copySelection(selection) {
|
|
35
|
+
const { backend, provider, model, thinking, mode } = selection;
|
|
36
|
+
return { backend, provider, model, thinking, mode };
|
|
37
|
+
}
|
|
@@ -7,7 +7,7 @@ import { environmentPluginDirs } from '../../plugins/builtin.js';
|
|
|
7
7
|
import { fsRefResolver, resolveFileRef } from './file-refs.js';
|
|
8
8
|
import { validateEnvironment } from './schema.js';
|
|
9
9
|
const log = createLogger('environments');
|
|
10
|
-
/** Definitions
|
|
10
|
+
/** Definitions with retired engine fields removed (no `file:` refs resolved), keyed by file name. */
|
|
11
11
|
let definitions = {};
|
|
12
12
|
let loaded = false;
|
|
13
13
|
let revision = 0;
|
|
@@ -42,6 +42,7 @@ function readDefinitions(dir) {
|
|
|
42
42
|
log.warn(`Skipping environment ${file}: name field "${def?.name}" ≠ filename`);
|
|
43
43
|
continue;
|
|
44
44
|
}
|
|
45
|
+
delete def.profile;
|
|
45
46
|
out[name] = def;
|
|
46
47
|
}
|
|
47
48
|
return out;
|
|
@@ -12,7 +12,6 @@ export function resolveActiveAgentName(name, channel) {
|
|
|
12
12
|
/** The run config for a loaded environment definition. */
|
|
13
13
|
export function resolveEnvironment(def) {
|
|
14
14
|
return {
|
|
15
|
-
profile: def.profile,
|
|
16
15
|
directive: def.directive,
|
|
17
16
|
systemPrompt: def.systemPrompt,
|
|
18
17
|
promptTemplate: def.promptTemplate,
|
|
@@ -36,7 +36,6 @@ export declare const environmentSchema: z.ZodObject<{
|
|
|
36
36
|
projectContext: z.ZodOptional<z.ZodBoolean>;
|
|
37
37
|
name: z.ZodString;
|
|
38
38
|
description: z.ZodOptional<z.ZodString>;
|
|
39
|
-
profile: z.ZodString;
|
|
40
39
|
persistSession: z.ZodOptional<z.ZodBoolean>;
|
|
41
40
|
directive: z.ZodOptional<z.ZodString>;
|
|
42
41
|
systemPrompt: z.ZodOptional<z.ZodString>;
|
|
@@ -15,7 +15,6 @@ export const environmentFieldsShape = {
|
|
|
15
15
|
export const environmentSchema = z.object({
|
|
16
16
|
name: z.string().min(1),
|
|
17
17
|
description: z.string().optional(),
|
|
18
|
-
profile: z.string().min(1),
|
|
19
18
|
persistSession: z.boolean().optional(),
|
|
20
19
|
directive: z.string().optional(),
|
|
21
20
|
systemPrompt: z.string().optional(),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
export * from './engine-selection.js';
|
|
2
|
+
export * from './models.js';
|
|
1
3
|
export * from './config.js';
|
|
2
|
-
export * from './profile-switch.js';
|
|
3
4
|
export * from './agent-switch.js';
|
|
4
5
|
export * from './model-selection.js';
|
|
5
6
|
export { resolveRateLimitProvider } from './provider-run-lifecycle.js';
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
// all belong to the run layer: import `startRun` from `@domain/runs/service.js`,
|
|
5
|
-
// `compactAgentContext` from `@domain/runs/compact.js`, `buildEngineSpec` from
|
|
6
|
-
// `@domain/runs/engine-spec.js`.
|
|
1
|
+
// Engine selection and environments. Run startup and engine specs belong to domain/runs.
|
|
2
|
+
export * from './engine-selection.js';
|
|
3
|
+
export * from './models.js';
|
|
7
4
|
export * from './config.js';
|
|
8
|
-
export * from './profile-switch.js';
|
|
9
5
|
export * from './agent-switch.js';
|
|
10
6
|
export * from './model-selection.js';
|
|
11
7
|
export { resolveRateLimitProvider } from './provider-run-lifecycle.js';
|
|
@@ -1,82 +1,30 @@
|
|
|
1
|
-
import type { Backend } from '../../agent-adapter/types.js';
|
|
2
1
|
import { readGatewayYaml } from '../../core/gateway-generator.js';
|
|
3
|
-
import type
|
|
4
|
-
|
|
5
|
-
* One channel's model selection, written in one place.
|
|
6
|
-
*
|
|
7
|
-
* The product rule this module implements: **the profile stays the base**. It owns the backend, the
|
|
8
|
-
* gateway route, extraEnv/extraOption and the fallback chain; a selection layers a model, a PI
|
|
9
|
-
* provider and a thinking level on top of it (see `effectiveProfile`). Everything that decides
|
|
10
|
-
* whether a change is allowed lives here, so the Web composer, `!model` and any future surface
|
|
11
|
-
* reach identical answers — the UI's greying-out is a preview of this function, never a second rule.
|
|
12
|
-
*/
|
|
13
|
-
/** A field left `undefined` is untouched; `null` clears it; a string sets it. */
|
|
14
|
-
export interface SelectionPatch {
|
|
15
|
-
model?: string | null;
|
|
16
|
-
provider?: string | null;
|
|
17
|
-
thinking?: string | null;
|
|
18
|
-
mode?: string | null;
|
|
19
|
-
}
|
|
20
|
-
export interface ApplySelectionRequest extends SelectionPatch {
|
|
2
|
+
import { type EngineSelection } from './engine-selection.js';
|
|
3
|
+
export interface ApplySelectionRequest extends Partial<EngineSelection> {
|
|
21
4
|
channel: string;
|
|
22
|
-
/** Injected in tests so the route check does not depend on the host's ~/.aistatus/gateway.yaml. */
|
|
23
|
-
readGateway?: () => ReturnType<typeof readGatewayYaml>;
|
|
24
|
-
/** Switch the channel to this profile first. Doing both in one call is what "pick a model that
|
|
25
|
-
* belongs to another profile" compiles down to. */
|
|
26
|
-
profileName?: string;
|
|
27
|
-
/** Whether a `web:` channel's pick also becomes what the next new conversation opens on.
|
|
28
|
-
* Default true; false for a selection no user made (a lead spawning a worker). */
|
|
29
5
|
seedDefault?: boolean;
|
|
6
|
+
readGateway?: () => ReturnType<typeof readGatewayYaml>;
|
|
30
7
|
}
|
|
31
|
-
export type SelectionFailure = '
|
|
32
|
-
|
|
33
|
-
export interface ChannelSelection {
|
|
34
|
-
profileName: string;
|
|
35
|
-
backend: Backend;
|
|
36
|
-
/** Effective values — the profile's own, unless the selection overrode them. */
|
|
37
|
-
model: string;
|
|
38
|
-
provider: string | null;
|
|
39
|
-
thinking: string | null;
|
|
40
|
-
/** The gateway route the next turn bills to. */
|
|
41
|
-
mode: string;
|
|
42
|
-
/** Which of the effective values came from the selection rather than the profile. */
|
|
43
|
-
override: ChannelOverride | null;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* The outcome, shaped like {@link SwitchProfileResult}: one flat record rather than a discriminated
|
|
47
|
-
* union, because this package compiles with `strictNullChecks: false`, where a `ok: true | false`
|
|
48
|
-
* discriminant does not narrow.
|
|
49
|
-
*
|
|
50
|
-
* The selection fields are always the channel's CURRENT ones — the new selection when the change
|
|
51
|
-
* landed, the untouched one when it was refused. A caller that shows the result therefore shows the
|
|
52
|
-
* truth either way, with no second read.
|
|
53
|
-
*/
|
|
54
|
-
export interface ApplySelectionResult extends ChannelSelection {
|
|
8
|
+
export type SelectionFailure = 'cross-backend-live-session' | 'invalid-thinking' | 'provider-not-supported' | 'invalid-mode' | 'invalid-model' | 'no-model-for-backend';
|
|
9
|
+
export interface ApplySelectionResult extends EngineSelection {
|
|
55
10
|
ok: boolean;
|
|
56
11
|
backendChanged: boolean;
|
|
57
|
-
/** Present only when `ok` is false. */
|
|
58
12
|
reason?: SelectionFailure;
|
|
59
|
-
/** Present for 'cross-backend-live-session', so the caller can name both sides. */
|
|
60
13
|
currentBackend?: string;
|
|
61
14
|
targetBackend?: string;
|
|
62
|
-
/** Present for 'invalid-thinking' and 'invalid-mode': what the backend or endpoint does accept. */
|
|
63
15
|
allowed?: readonly string[];
|
|
64
16
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
* has one for that provider, the channel moves there instead of carrying a provider override,
|
|
79
|
-
* so the route, env and fallback chain stay the ones the user configured for that provider.
|
|
80
|
-
* 4. The remaining fields are patched onto the channel's override.
|
|
81
|
-
*/
|
|
17
|
+
export type BackendSwitchDecision = {
|
|
18
|
+
allowed: true;
|
|
19
|
+
backendChanged: boolean;
|
|
20
|
+
} | {
|
|
21
|
+
allowed: false;
|
|
22
|
+
reason: 'cross-backend-live-session';
|
|
23
|
+
};
|
|
24
|
+
export declare function decideBackendSwitch(opts: {
|
|
25
|
+
currentBackend: string;
|
|
26
|
+
targetBackend: string;
|
|
27
|
+
hasHistory: boolean;
|
|
28
|
+
}): BackendSwitchDecision;
|
|
29
|
+
export declare function readChannelSelection(channel: string): EngineSelection;
|
|
82
30
|
export declare function applyChannelSelection(request: ApplySelectionRequest): Promise<ApplySelectionResult>;
|