@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
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import { CONFIG_DIR } from '../../../core/paths.js';
|
|
4
|
+
import { atomicWrite } from '../../../core/atomic-write.js';
|
|
5
|
+
import { readGatewayYaml } from '../../../core/gateway-generator.js';
|
|
6
|
+
import { modelKey, validateModelRef, validateEngineSelection, } from '../../agents/engine-selection.js';
|
|
7
|
+
import { GATEWAY_CONFIG_PATH } from '../../pi-providers/gateway-route-store.js';
|
|
8
|
+
import { modelsRepo, modelsWriteLock } from '../../../store/models-repo.js';
|
|
9
|
+
import { selectionForModel } from '../../agents/models.js';
|
|
10
|
+
import { getModelMemory, rememberModelSelection } from '../../agents/config.js';
|
|
11
|
+
import { modelsFavoriteInput, modelsSetDefaultInput, modelsSetThinkingInput } from '../input-schemas.js';
|
|
12
|
+
function invalid(message) {
|
|
13
|
+
return Object.assign(new Error(message), { code: 'invalid-args' });
|
|
14
|
+
}
|
|
15
|
+
function validate(fn) {
|
|
16
|
+
try {
|
|
17
|
+
return fn();
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
throw invalid(error instanceof Error ? error.message : String(error));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
async function readModelsFile(configDir, initial) {
|
|
24
|
+
try {
|
|
25
|
+
const raw = JSON.parse(await fs.readFile(path.join(configDir, 'models.json'), 'utf8'));
|
|
26
|
+
if (!raw || typeof raw !== 'object' || !Array.isArray(raw.favorites)) {
|
|
27
|
+
throw invalid('models.json must contain a default selection and favorites array');
|
|
28
|
+
}
|
|
29
|
+
validate(() => validateEngineSelection(raw.default ?? initial));
|
|
30
|
+
return raw;
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
if (error.code === 'ENOENT' && initial)
|
|
34
|
+
return { default: initial, favorites: [] };
|
|
35
|
+
throw invalid(`Cannot read models.json: ${error instanceof Error ? error.message : String(error)}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async function writeModelsFile(configDir, next) {
|
|
39
|
+
await atomicWrite(path.join(configDir, 'models.json'), JSON.stringify(next, null, 2) + '\n');
|
|
40
|
+
// The next run must see the write before the file watcher's debounce expires.
|
|
41
|
+
modelsRepo.invalidate();
|
|
42
|
+
}
|
|
43
|
+
function favorite(args) {
|
|
44
|
+
return validate(() => {
|
|
45
|
+
const parsed = modelsFavoriteInput.parse(args);
|
|
46
|
+
const ref = { backend: parsed.backend, provider: parsed.provider ?? null, model: parsed.model };
|
|
47
|
+
validateModelRef(ref);
|
|
48
|
+
return ref;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
export async function addFavorite(configDir, args) {
|
|
52
|
+
const ref = favorite(args);
|
|
53
|
+
return modelsWriteLock.run(async () => {
|
|
54
|
+
const raw = await readModelsFile(configDir);
|
|
55
|
+
if (raw.favorites.some((entry) => modelKey(entry) === modelKey(ref)))
|
|
56
|
+
return false;
|
|
57
|
+
await writeModelsFile(configDir, { ...raw, favorites: [...raw.favorites, ref] });
|
|
58
|
+
return true;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
export async function removeFavorite(configDir, args) {
|
|
62
|
+
const ref = favorite(args);
|
|
63
|
+
return modelsWriteLock.run(async () => {
|
|
64
|
+
const raw = await readModelsFile(configDir);
|
|
65
|
+
const favorites = raw.favorites.filter((entry) => modelKey(entry) !== modelKey(ref));
|
|
66
|
+
if (favorites.length === raw.favorites.length)
|
|
67
|
+
return false;
|
|
68
|
+
await writeModelsFile(configDir, { ...raw, favorites });
|
|
69
|
+
return true;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function validateDefault(selection, readGateway) {
|
|
73
|
+
validateEngineSelection(selection);
|
|
74
|
+
const endpoint = selection.backend === 'claude' ? 'anthropic' : selection.provider;
|
|
75
|
+
const gateway = readGateway();
|
|
76
|
+
const modes = Object.keys(gateway?.endpoints?.[endpoint] ?? {});
|
|
77
|
+
if (gateway && !modes.includes(selection.mode))
|
|
78
|
+
throw invalid(`Unknown mode '${selection.mode}' for ${endpoint}`);
|
|
79
|
+
}
|
|
80
|
+
export async function setDefaultModel(configDir, args, readGateway = () => readGatewayYaml(GATEWAY_CONFIG_PATH)) {
|
|
81
|
+
const { selection } = validate(() => modelsSetDefaultInput.parse(args));
|
|
82
|
+
validate(() => validateDefault(selection, readGateway));
|
|
83
|
+
return modelsWriteLock.run(async () => {
|
|
84
|
+
const file = path.join(configDir, 'models.json');
|
|
85
|
+
const exists = await fs.stat(file).then(() => true, (error) => {
|
|
86
|
+
if (error.code === 'ENOENT')
|
|
87
|
+
return false;
|
|
88
|
+
throw error;
|
|
89
|
+
});
|
|
90
|
+
const raw = await readModelsFile(configDir, selection);
|
|
91
|
+
if (exists && raw.default && modelKey(raw.default) === modelKey(selection)
|
|
92
|
+
&& raw.default.thinking === selection.thinking && raw.default.mode === selection.mode)
|
|
93
|
+
return false;
|
|
94
|
+
await writeModelsFile(configDir, { ...raw, default: selection });
|
|
95
|
+
rememberModelSelection(selection);
|
|
96
|
+
return true;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
export async function setModelThinking(configDir, args, resolveSelection = selectionForModel) {
|
|
100
|
+
const { ref, thinking } = validate(() => modelsSetThinkingInput.parse(args));
|
|
101
|
+
validate(() => validateModelRef(ref));
|
|
102
|
+
return modelsWriteLock.run(async () => {
|
|
103
|
+
const raw = await readModelsFile(configDir);
|
|
104
|
+
if (!raw.favorites.some(entry => modelKey(entry) === modelKey(ref)))
|
|
105
|
+
throw invalid('Model is not a favorite');
|
|
106
|
+
const selection = validate(() => ({ ...resolveSelection(ref), thinking }));
|
|
107
|
+
validate(() => validateEngineSelection(selection));
|
|
108
|
+
if (getModelMemory()[modelKey(ref)]?.thinking === thinking)
|
|
109
|
+
return false;
|
|
110
|
+
rememberModelSelection(selection);
|
|
111
|
+
return true;
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
async function mutation(write) {
|
|
115
|
+
try {
|
|
116
|
+
return { ok: true, data: { changed: await write() } };
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
return {
|
|
120
|
+
ok: false,
|
|
121
|
+
code: error.code === 'invalid-args' ? 'invalid-args' : 'internal',
|
|
122
|
+
message: error instanceof Error ? error.message : String(error),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
export async function handleModelsFavoriteAdd(_deps, args) {
|
|
127
|
+
return mutation(() => addFavorite(CONFIG_DIR, args));
|
|
128
|
+
}
|
|
129
|
+
export async function handleModelsFavoriteRemove(_deps, args) {
|
|
130
|
+
return mutation(() => removeFavorite(CONFIG_DIR, args));
|
|
131
|
+
}
|
|
132
|
+
export async function handleModelsSetDefault(_deps, args) {
|
|
133
|
+
return mutation(() => setDefaultModel(CONFIG_DIR, args));
|
|
134
|
+
}
|
|
135
|
+
export async function handleModelsSetThinking(_deps, args) {
|
|
136
|
+
return mutation(() => setModelThinking(CONFIG_DIR, args));
|
|
137
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ResolveMediaInput, ResolveMediaResult } from '../inline-media-types.js';
|
|
2
|
+
import type { Result, UiServiceDeps } from '../types.js';
|
|
3
|
+
/** Media failures are successful RPC replies so the UI can translate their stable codes. */
|
|
4
|
+
export declare function handleResolveMedia(deps: UiServiceDeps, args: ResolveMediaInput): Promise<Result<ResolveMediaResult>>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { sessionsResolveMediaInput } from '../input-schemas.js';
|
|
2
|
+
/** Media failures are successful RPC replies so the UI can translate their stable codes. */
|
|
3
|
+
export async function handleResolveMedia(deps, args) {
|
|
4
|
+
const parsed = sessionsResolveMediaInput.safeParse(args);
|
|
5
|
+
if (!parsed.success)
|
|
6
|
+
return { ok: false, code: 'invalid-args', message: parsed.error.message };
|
|
7
|
+
try {
|
|
8
|
+
const session = await deps.sessionStore.getById(parsed.data.sessionId);
|
|
9
|
+
if (!session)
|
|
10
|
+
return { ok: true, data: { error: { code: 'not_found', reason: 'Session not found' } } };
|
|
11
|
+
return { ok: true, data: await deps.resolveMedia(parsed.data) };
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
15
|
+
return { ok: true, data: { error: { code: 'load_failed', reason } } };
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { UiServiceDeps, Result, SessionsCreateReturn, SessionsSendReturn, SessionsCompactReturn, SessionsMarkManyReadReturn, SessionsCancelReturn,
|
|
1
|
+
import type { UiServiceDeps, Result, SessionsCreateReturn, SessionsSendReturn, SessionsCompactReturn, SessionsMarkManyReadReturn, SessionsCancelReturn, SessionsSetAgentReturn, SessionsSetSelectionReturn, SessionsCreateAndSendReturn, SessionsRespondDecisionReturn, SessionsInteractionMutateReturn, SessionsRewindReturn, SessionsCancelResumeReturn, MutateArgs } from '../types.js';
|
|
2
2
|
export declare function handleCreateSession(deps: UiServiceDeps, args: MutateArgs<'sessions.create'>): Promise<Result<SessionsCreateReturn>>;
|
|
3
3
|
export declare function handleSendSession(deps: UiServiceDeps, args: MutateArgs<'sessions.send'>): Promise<Result<SessionsSendReturn>>;
|
|
4
4
|
export declare function handleCancelSession(deps: UiServiceDeps, args: MutateArgs<'sessions.cancel'>): Promise<Result<SessionsCancelReturn>>;
|
|
@@ -9,8 +9,8 @@ export declare function handleMarkReadSession(deps: UiServiceDeps, args: MutateA
|
|
|
9
9
|
* the user asked to clear what they see, and a half-stale list must still clear. */
|
|
10
10
|
export declare function handleMarkManyReadSessions(deps: UiServiceDeps, args: MutateArgs<'sessions.markManyRead'>): Promise<Result<SessionsMarkManyReadReturn>>;
|
|
11
11
|
export declare function handleCreateAndSend(deps: UiServiceDeps, args: MutateArgs<'sessions.createAndSend'>): Promise<Result<SessionsCreateAndSendReturn>>;
|
|
12
|
-
export declare function handleSetProfile(deps: UiServiceDeps, args: MutateArgs<'sessions.setProfile'>): Promise<Result<SessionsSetProfileReturn>>;
|
|
13
12
|
export declare function handleSetAgent(deps: UiServiceDeps, args: MutateArgs<'sessions.setAgent'>): Promise<Result<SessionsSetAgentReturn>>;
|
|
13
|
+
/** Apply the whole engine choice through the shared domain rule, preserving explicit nulls. */
|
|
14
14
|
export declare function handleSetSelection(deps: UiServiceDeps, args: MutateArgs<'sessions.setSelection'>): Promise<Result<SessionsSetSelectionReturn>>;
|
|
15
15
|
export declare function handleRewindSession(deps: UiServiceDeps, args: MutateArgs<'sessions.rewind'>): Promise<Result<SessionsRewindReturn>>;
|
|
16
16
|
export declare function handleAnswerQuestion(deps: UiServiceDeps, args: MutateArgs<'sessions.answerQuestion'>): Promise<Result<SessionsInteractionMutateReturn>>;
|
|
@@ -15,9 +15,7 @@ function expectedOneOf(allowed) {
|
|
|
15
15
|
}
|
|
16
16
|
export async function handleCreateSession(deps, args) {
|
|
17
17
|
const projectId = args.projectId ?? deps.projectStore.getDefault().id;
|
|
18
|
-
const { sessionId } = await deps.createDirectSession({
|
|
19
|
-
projectId, browser: args.browser ?? null,
|
|
20
|
-
});
|
|
18
|
+
const { sessionId } = await deps.createDirectSession({ projectId });
|
|
21
19
|
return { ok: true, data: { sessionId } };
|
|
22
20
|
}
|
|
23
21
|
export async function handleSendSession(deps, args) {
|
|
@@ -109,8 +107,8 @@ export async function handleMarkManyReadSessions(deps, args) {
|
|
|
109
107
|
}
|
|
110
108
|
// Create a fresh session AND send the first message in one atomic operation. Used by the workbench
|
|
111
109
|
// "New Conversation" draft flow (task 15b): the session is created only when the user sends their
|
|
112
|
-
// first message, at which point the
|
|
113
|
-
// Creates the session via `createDirectSession` with the given
|
|
110
|
+
// first message, at which point the engine choice is known and the backend is resolved correctly.
|
|
111
|
+
// Creates the session via `createDirectSession` with the given selection, then routes the
|
|
114
112
|
// message as a fire-and-forget send. Returns the new sessionId so the client can transition from
|
|
115
113
|
// draft to a real session.
|
|
116
114
|
export async function handleCreateAndSend(deps, args) {
|
|
@@ -119,18 +117,12 @@ export async function handleCreateAndSend(deps, args) {
|
|
|
119
117
|
}
|
|
120
118
|
const { sessionId, channel } = await deps.createDirectSession({
|
|
121
119
|
projectId: args.projectId,
|
|
122
|
-
profileName: args.profileName ?? null,
|
|
123
120
|
// The draft composer's environment choice, applied at creation for the same reason as the
|
|
124
121
|
// selection below: the agent decides the spawned process's prompt and tool surface, and there
|
|
125
122
|
// is no session to `setAgent` on before the first turn.
|
|
126
123
|
agentName: args.agentName ?? null,
|
|
127
|
-
//
|
|
128
|
-
|
|
129
|
-
// none is stating the empty selection ("follow the profile"), not staying silent: this is the
|
|
130
|
-
// one create path that always has a composer behind it, and the empty case is exactly the one
|
|
131
|
-
// that has to re-seed what the NEXT new conversation opens on.
|
|
132
|
-
selection: args.selection ?? {},
|
|
133
|
-
browser: args.browser ?? null,
|
|
124
|
+
// Apply the complete engine choice before the first turn.
|
|
125
|
+
selection: args.selection,
|
|
134
126
|
});
|
|
135
127
|
// If the client uploaded files under a draft upload id, move them to the real
|
|
136
128
|
// session's attachment directory and update path references.
|
|
@@ -150,39 +142,7 @@ export async function handleCreateAndSend(deps, args) {
|
|
|
150
142
|
});
|
|
151
143
|
return { ok: true, data: { sessionId, acceptedAt } };
|
|
152
144
|
}
|
|
153
|
-
// Switch
|
|
154
|
-
// `switchChannelProfile` the Slack/Feishu `!profile` command uses, injected as `switchSessionProfile`).
|
|
155
|
-
// Resolves the session→channel, delegates to the rule, and maps its structured outcome to a Result:
|
|
156
|
-
// • unknown-profile → invalid-args
|
|
157
|
-
// • cross-backend-live-session → conflict (the conversation can't swap backends; start a new session)
|
|
158
|
-
// A same-backend switch keeps the conversation (no reset) — only the model changes on the next turn.
|
|
159
|
-
export async function handleSetProfile(deps, args) {
|
|
160
|
-
const session = await deps.sessionStore.getById(args.sessionId);
|
|
161
|
-
if (!session) {
|
|
162
|
-
return { ok: false, code: 'not-found', message: t('ui.session.notFound', { id: args.sessionId }) };
|
|
163
|
-
}
|
|
164
|
-
const res = await deps.switchSessionProfile({ channel: session.channel, name: args.profileName });
|
|
165
|
-
if (!res.ok) {
|
|
166
|
-
if (res.reason === 'unknown-profile') {
|
|
167
|
-
return { ok: false, code: 'invalid-args', message: t('ui.session.unknownProfile', { name: args.profileName }) };
|
|
168
|
-
}
|
|
169
|
-
return {
|
|
170
|
-
ok: false,
|
|
171
|
-
code: 'backend-locked', // maps to CONFLICT in the tRPC layer
|
|
172
|
-
message: t('ui.session.backendLockedNamed', {
|
|
173
|
-
name: res.name, target: res.targetBackend, current: res.currentBackend,
|
|
174
|
-
}),
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
return { ok: true, data: { profileName: res.name, backendChanged: res.backendChanged } };
|
|
178
|
-
}
|
|
179
|
-
// Switch the session's agent — its execution environment — under the shared agent-switch rule (the
|
|
180
|
-
// same `switchChannelAgent` the Slack/Feishu `!agent` command uses, injected as `switchSessionAgent`).
|
|
181
|
-
// The error mapping is `handleSetProfile`'s, for the same reasons:
|
|
182
|
-
// • unknown-agent → invalid-args
|
|
183
|
-
// • cross-backend-live-session → conflict (an agent pinning a profile on the other backend is a
|
|
184
|
-
// backend move; a live conversation can't be resumed there)
|
|
185
|
-
// A null `agentName` clears the selection: the session follows the global default again.
|
|
145
|
+
// Switch execution environment independently of the engine. Null follows the default agent.
|
|
186
146
|
export async function handleSetAgent(deps, args) {
|
|
187
147
|
const session = await deps.sessionStore.getById(args.sessionId);
|
|
188
148
|
if (!session) {
|
|
@@ -191,96 +151,39 @@ export async function handleSetAgent(deps, args) {
|
|
|
191
151
|
const name = args.agentName ?? null;
|
|
192
152
|
const res = await deps.switchSessionAgent({ channel: session.channel, name });
|
|
193
153
|
if (!res.ok) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
154
|
+
return { ok: false, code: 'invalid-args', message: t('ui.session.unknownAgent', { name: String(name) }) };
|
|
155
|
+
}
|
|
156
|
+
return { ok: true, data: { agentName: res.agentName } };
|
|
157
|
+
}
|
|
158
|
+
function selectionError(result, args) {
|
|
159
|
+
if (result.reason === 'cross-backend-live-session') {
|
|
197
160
|
return {
|
|
198
|
-
ok: false,
|
|
199
|
-
|
|
200
|
-
message: t('ui.session.backendLockedNamed', {
|
|
201
|
-
name: String(name), target: res.targetBackend, current: res.currentBackend,
|
|
202
|
-
}),
|
|
161
|
+
ok: false, code: 'backend-locked',
|
|
162
|
+
message: t('ui.session.backendLocked', { target: result.targetBackend, current: result.currentBackend }),
|
|
203
163
|
};
|
|
204
164
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
},
|
|
165
|
+
const messages = {
|
|
166
|
+
'invalid-thinking': () => t('ui.session.invalidThinking', {
|
|
167
|
+
level: String(args.selection.thinking), expected: expectedOneOf(result.allowed),
|
|
168
|
+
}),
|
|
169
|
+
'invalid-mode': () => t('ui.session.invalidMode', {
|
|
170
|
+
mode: args.selection.mode, expected: expectedOneOf(result.allowed),
|
|
171
|
+
}),
|
|
172
|
+
'provider-not-supported': () => t('ui.session.noProvider', { provider: String(args.selection.provider) }),
|
|
212
173
|
};
|
|
174
|
+
return { ok: false, code: 'invalid-args', message: messages[result.reason]?.() ?? result.reason ?? 'Invalid selection' };
|
|
213
175
|
}
|
|
214
|
-
|
|
215
|
-
// level, or any combination — through the ONE domain rule (`applyChannelSelection`, injected as
|
|
216
|
-
// `applySessionSelection`). The composer's greying-out is a preview of that rule; this is where it
|
|
217
|
-
// is enforced. Refusals map to:
|
|
218
|
-
// • unknown-profile / provider-not-supported / invalid-thinking → invalid-args
|
|
219
|
-
// • cross-backend-live-session → conflict (start a new session)
|
|
220
|
-
// A same-backend change keeps the conversation — only the next turn differs.
|
|
176
|
+
/** Apply the whole engine choice through the shared domain rule, preserving explicit nulls. */
|
|
221
177
|
export async function handleSetSelection(deps, args) {
|
|
222
178
|
const session = await deps.sessionStore.getById(args.sessionId);
|
|
223
179
|
if (!session) {
|
|
224
180
|
return { ok: false, code: 'not-found', message: t('ui.session.notFound', { id: args.sessionId }) };
|
|
225
181
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
const
|
|
230
|
-
|
|
231
|
-
profileName: args.profileName,
|
|
232
|
-
...(stated
|
|
233
|
-
? {
|
|
234
|
-
model: stated.model ?? null, provider: stated.provider ?? null,
|
|
235
|
-
thinking: stated.thinking ?? null, mode: stated.mode ?? null,
|
|
236
|
-
}
|
|
237
|
-
: {}),
|
|
238
|
-
});
|
|
239
|
-
if (!result.ok) {
|
|
240
|
-
if (result.reason === 'cross-backend-live-session') {
|
|
241
|
-
return {
|
|
242
|
-
ok: false,
|
|
243
|
-
code: 'backend-locked', // maps to CONFLICT in the tRPC layer
|
|
244
|
-
message: t('ui.session.backendLocked', { target: result.targetBackend, current: result.currentBackend }),
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
if (result.reason === 'invalid-thinking') {
|
|
248
|
-
return {
|
|
249
|
-
ok: false, code: 'invalid-args',
|
|
250
|
-
message: t('ui.session.invalidThinking', {
|
|
251
|
-
level: String(args.selection?.thinking), expected: expectedOneOf(result.allowed),
|
|
252
|
-
}),
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
if (result.reason === 'invalid-mode') {
|
|
256
|
-
return {
|
|
257
|
-
ok: false, code: 'invalid-args',
|
|
258
|
-
message: t('ui.session.invalidMode', {
|
|
259
|
-
mode: String(args.selection?.mode), expected: expectedOneOf(result.allowed),
|
|
260
|
-
}),
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
if (result.reason === 'provider-not-supported') {
|
|
264
|
-
return {
|
|
265
|
-
ok: false, code: 'invalid-args',
|
|
266
|
-
message: t('ui.session.noProvider', { provider: String(args.selection?.provider) }),
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
return { ok: false, code: 'invalid-args', message: t('ui.session.unknownProfile', { name: String(args.profileName) }) };
|
|
270
|
-
}
|
|
271
|
-
return {
|
|
272
|
-
ok: true,
|
|
273
|
-
data: {
|
|
274
|
-
profileName: result.profileName,
|
|
275
|
-
backend: result.backend,
|
|
276
|
-
model: result.model,
|
|
277
|
-
provider: result.provider,
|
|
278
|
-
thinking: result.thinking,
|
|
279
|
-
mode: result.mode,
|
|
280
|
-
override: result.override,
|
|
281
|
-
backendChanged: result.backendChanged,
|
|
282
|
-
},
|
|
283
|
-
};
|
|
182
|
+
const result = await deps.applySessionSelection({ channel: session.channel, ...args.selection });
|
|
183
|
+
if (!result.ok)
|
|
184
|
+
return selectionError(result, args);
|
|
185
|
+
const { backend, provider, model, thinking, mode, backendChanged } = result;
|
|
186
|
+
return { ok: true, data: { backend, provider, model, thinking, mode, backendChanged } };
|
|
284
187
|
}
|
|
285
188
|
// Message edit + rewind (desktop design 23 / mobile 7): resolve session→channel and delegate to
|
|
286
189
|
// the injected orchestration rewind path (ledger rollback + backend backup restore + display-history
|
|
@@ -9,6 +9,7 @@ import { getLocale } from '../../../core/i18n.js';
|
|
|
9
9
|
import { langSource } from '../../system/preferences.js';
|
|
10
10
|
import { defaultHookRegistryDirs, loadMountedHookSummaries } from '../../../store/hook-registry.js';
|
|
11
11
|
import { ENVIRONMENTS_DIRNAME } from '../../agents/environments/paths.js';
|
|
12
|
+
import { engineSelectionInput, modelRefInput } from '../input-schemas.js';
|
|
12
13
|
const MASK = '••••••••';
|
|
13
14
|
async function readJson(file) {
|
|
14
15
|
try {
|
|
@@ -19,7 +20,7 @@ async function readJson(file) {
|
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
/** The execution environments (`config/environments/`), read as documents rather than filenames: a
|
|
22
|
-
* picker has to say what each environment is for
|
|
23
|
+
* picker has to say what each environment is for. Read under
|
|
23
24
|
* `configDir`, so the snapshot stays hermetic; a malformed file is skipped rather than failing the
|
|
24
25
|
* whole snapshot. */
|
|
25
26
|
async function readAgentEntries(dir, names) {
|
|
@@ -28,9 +29,8 @@ async function readAgentEntries(dir, names) {
|
|
|
28
29
|
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
29
30
|
return null;
|
|
30
31
|
const doc = raw;
|
|
31
|
-
const profile = typeof doc.profile === 'string' && doc.profile ? doc.profile : '__active__';
|
|
32
32
|
const description = typeof doc.description === 'string' && doc.description ? doc.description : undefined;
|
|
33
|
-
return { name,
|
|
33
|
+
return { name, ...(description ? { description } : {}) };
|
|
34
34
|
}));
|
|
35
35
|
return entries.filter((entry) => entry !== null);
|
|
36
36
|
}
|
|
@@ -69,42 +69,17 @@ function parseBudget(raw) {
|
|
|
69
69
|
projects: parseProjectBudgets(raw.projects),
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
|
-
function
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
function parseStringMap(raw) {
|
|
77
|
-
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
78
|
-
return {};
|
|
79
|
-
return Object.fromEntries(Object.entries(raw).filter((pair) => typeof pair[1] === 'string'));
|
|
80
|
-
}
|
|
81
|
-
function parseProfiles(raw) {
|
|
82
|
-
if (!raw || typeof raw !== 'object' || !raw.profiles || typeof raw.profiles !== 'object')
|
|
83
|
-
return null;
|
|
84
|
-
const profiles = Object.entries(raw.profiles).flatMap(([name, p]) => {
|
|
85
|
-
if (p?.backend != null && !isLiveBackend(p.backend))
|
|
86
|
-
return [];
|
|
87
|
-
return [{
|
|
88
|
-
name,
|
|
89
|
-
model: typeof p?.model === 'string' ? p.model : null,
|
|
90
|
-
backend: isLiveBackend(p?.backend) ? p.backend : null,
|
|
91
|
-
mode: typeof p?.mode === 'string' ? p.mode : null,
|
|
92
|
-
thinking: typeof p?.thinking === 'string' ? p.thinking : null,
|
|
93
|
-
provider: typeof p?.provider === 'string' ? p.provider : null,
|
|
94
|
-
extraOption: parseStringMap(p?.extraOption),
|
|
95
|
-
// KEYS ONLY — an extraEnv value is injected into the agent environment and may be a token.
|
|
96
|
-
extraEnvKeys: p?.extraEnv && typeof p.extraEnv === 'object' && !Array.isArray(p.extraEnv)
|
|
97
|
-
? Object.keys(p.extraEnv).sort()
|
|
98
|
-
: [],
|
|
99
|
-
fallbackCount: Array.isArray(p?.fallback) ? p.fallback.length : 0,
|
|
100
|
-
}];
|
|
101
|
-
});
|
|
102
|
-
const requestedDefault = typeof raw.defaultProfile === 'string' ? raw.defaultProfile : null;
|
|
72
|
+
function parseModels(raw) {
|
|
73
|
+
const file = raw;
|
|
74
|
+
const selection = engineSelectionInput.safeParse(file?.default);
|
|
75
|
+
const favorites = Array.isArray(file?.favorites) ? file.favorites : [];
|
|
103
76
|
return {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
77
|
+
default: selection.success ? selection.data : null,
|
|
78
|
+
favorites: favorites.flatMap((ref) => {
|
|
79
|
+
const parsed = modelRefInput.safeParse(ref);
|
|
80
|
+
return parsed.success ? [parsed.data] : [];
|
|
81
|
+
}),
|
|
82
|
+
memory: {},
|
|
108
83
|
};
|
|
109
84
|
}
|
|
110
85
|
function parseMachines(raw) {
|
|
@@ -163,16 +138,17 @@ export async function readConfigSnapshot(configDir, liveSettings, lang, builtinH
|
|
|
163
138
|
const hooks = loadMountedHookSummaries({ user: path.join(configDir, 'hooks'), builtin: builtinHooksDir });
|
|
164
139
|
const parts = await Promise.all([
|
|
165
140
|
readJson(path.join(configDir, 'budget.json')),
|
|
166
|
-
readJson(path.join(configDir, '
|
|
141
|
+
readJson(path.join(configDir, 'models.json')),
|
|
167
142
|
readJson(path.join(configDir, 'machines.json')),
|
|
168
143
|
readJson(path.join(configDir, 'mcp-config.json')),
|
|
169
144
|
readEnv(path.join(configDir, '.env')),
|
|
170
145
|
listJsonBasenames(path.join(configDir, ENVIRONMENTS_DIRNAME)),
|
|
171
146
|
]);
|
|
172
|
-
const [budget,
|
|
147
|
+
const [budget, models, machines, mcp, env, environments] = parts;
|
|
173
148
|
return {
|
|
174
149
|
platforms: await readPlatformSettings(path.join(configDir, '.env')),
|
|
175
|
-
budget: parseBudget(budget),
|
|
150
|
+
budget: parseBudget(budget), models: parseModels(models), machines: parseMachines(machines),
|
|
151
|
+
selectionDefault: null,
|
|
176
152
|
mcp: parseMcp(mcp),
|
|
177
153
|
agents: await readAgentEntries(path.join(configDir, ENVIRONMENTS_DIRNAME), environments),
|
|
178
154
|
hooks, env, settings: liveSettings, lang,
|
|
@@ -183,5 +159,9 @@ export async function handleConfigGet(deps, _params) {
|
|
|
183
159
|
// restart, and the UI must follow what Cortex is actually speaking. `source` is read from disk
|
|
184
160
|
// and the environment, and is the only thing that can say "CORTEX_LANG will win again at boot".
|
|
185
161
|
const snapshot = await readConfigSnapshot(CONFIG_DIR, getSettingsSnapshot(), { value: getLocale(), source: langSource() });
|
|
186
|
-
return {
|
|
162
|
+
return {
|
|
163
|
+
...snapshot,
|
|
164
|
+
models: { ...snapshot.models, memory: deps.getModelMemory() },
|
|
165
|
+
selectionDefault: deps.getSelectionDefault() ?? null,
|
|
166
|
+
};
|
|
187
167
|
}
|
|
@@ -3,9 +3,9 @@ import { anthropicModelDiscovery, anthropicModelIds, anthropicModelThinking, } f
|
|
|
3
3
|
import { readGatewayYaml } from '../../../core/gateway-generator.js';
|
|
4
4
|
import { defaultCustomProviderStores, listCustomProviders, GATEWAY_CONFIG_PATH, } from '../../pi-providers/index.js';
|
|
5
5
|
import { piProviderDiscovery } from '../../../agent-adapter/pi/discovery.js';
|
|
6
|
-
import { THINKING_LEVELS_BY_BACKEND } from '../../agents/
|
|
6
|
+
import { THINKING_LEVELS_BY_BACKEND } from '../../agents/engine-selection.js';
|
|
7
7
|
/**
|
|
8
|
-
* The catalog is a UNION, never an intersection: a
|
|
8
|
+
* The catalog is a UNION, never an intersection: a model must stay selectable for an endpoint the
|
|
9
9
|
* host cannot currently enumerate (PI reports only providers with usable auth, and a scan can fail
|
|
10
10
|
* outright). Every source therefore only ADDS — an endpoint known solely from gateway.yaml still
|
|
11
11
|
* appears, with an empty model list, and the editor falls back to free text for it.
|
|
@@ -5,7 +5,7 @@ export function toScheduleInfo(s) {
|
|
|
5
5
|
type: s.type,
|
|
6
6
|
message: s.message,
|
|
7
7
|
projectId: s.projectId,
|
|
8
|
-
|
|
8
|
+
selection: s.selection ?? null,
|
|
9
9
|
nextRun: s.nextRun != null ? new Date(s.nextRun).toISOString() : null,
|
|
10
10
|
lastRun: s.lastRun != null ? new Date(s.lastRun).toISOString() : null,
|
|
11
11
|
paused: s.isPaused ?? false,
|
|
@@ -68,17 +68,14 @@ export async function handleSessionsList(deps, params) {
|
|
|
68
68
|
const live = totalsBySession.get(sessionId);
|
|
69
69
|
totalsBySession.set(sessionId, addTotalsAcc(live ?? emptyTotalsAcc(), carried));
|
|
70
70
|
}
|
|
71
|
-
//
|
|
72
|
-
|
|
73
|
-
// a 300-session list resolve (and revalidate) profiles.json 300 times per request.
|
|
74
|
-
const compactionByProfile = new Map();
|
|
71
|
+
// Compaction support depends only on the backend, not a model choice.
|
|
72
|
+
const compactionByBackend = new Map();
|
|
75
73
|
const supportsCompaction = (session) => {
|
|
76
|
-
const
|
|
77
|
-
const known = compactionByProfile.get(key);
|
|
74
|
+
const known = compactionByBackend.get(session.backend);
|
|
78
75
|
if (known !== undefined)
|
|
79
76
|
return known;
|
|
80
77
|
const supported = deps.supportsSessionCompaction(session);
|
|
81
|
-
|
|
78
|
+
compactionByBackend.set(session.backend, supported);
|
|
82
79
|
return supported;
|
|
83
80
|
};
|
|
84
81
|
const resolveNumTurns = (sessionId, inTurn, liveNumTurns) => {
|
|
@@ -149,16 +146,12 @@ export async function handleSessionsList(deps, params) {
|
|
|
149
146
|
label: s.label ?? null,
|
|
150
147
|
starred: s.starred ?? false,
|
|
151
148
|
labelRenamed: s.labelRenamed ?? false,
|
|
152
|
-
|
|
149
|
+
selection: s.selection ?? null,
|
|
153
150
|
// The environment half of the same question: which agent template the session runs as.
|
|
154
151
|
agentName: s.agentName ?? null,
|
|
155
|
-
// The other half of "what will the next turn run": the profile alone would misreport every
|
|
156
|
-
// session whose model or thinking level the user picked in the composer.
|
|
157
|
-
selectionOverride: deps.getChannelSelectionOverride(s.channel) ?? null,
|
|
158
|
-
browser: s.browser ?? null,
|
|
159
152
|
contextUsage: s.contextUsage ?? null,
|
|
160
153
|
todos: deps.getSessionTodos(s.sessionId) ?? null,
|
|
161
|
-
contextCompactionSupported: supportsCompaction({ backend: s.backend
|
|
154
|
+
contextCompactionSupported: supportsCompaction({ backend: s.backend }),
|
|
162
155
|
running,
|
|
163
156
|
backgroundRunning: bgHeld,
|
|
164
157
|
awaitingInput,
|
|
@@ -277,6 +270,7 @@ function messageFromEvent(deps, event, elapsedMs) {
|
|
|
277
270
|
...(event.type === 'tool' && event.teamAction ? { teamAction: event.teamAction } : {}),
|
|
278
271
|
...(event.type === 'tool' && event.boardAction ? { boardAction: event.boardAction } : {}),
|
|
279
272
|
...(event.type === 'worker-progress' && event.worker ? { worker: event.worker } : {}),
|
|
273
|
+
...(event.type === 'thinking' && event.blockId ? { blockId: event.blockId } : {}),
|
|
280
274
|
ts: event.ts,
|
|
281
275
|
elapsedMs,
|
|
282
276
|
// Tool rows carry the images the call returned (see `appendToolImages`).
|