@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
|
@@ -20,20 +20,3 @@ export function isRetryableError(error) {
|
|
|
20
20
|
|| TRANSIENT_TRANSPORT_ERROR.test(message)
|
|
21
21
|
|| TRANSIENT_PROVIDER_GUIDANCE.test(message);
|
|
22
22
|
}
|
|
23
|
-
/** A retryable thrown failure is either the provider refusing on quota or the request failing on
|
|
24
|
-
* its way (connection reset, 5xx, timeout). Only call this on an `isRetryableError` failure. */
|
|
25
|
-
export function fallbackReasonOf(error) {
|
|
26
|
-
return isApiRateLimitError(error.message) ? 'rate-limited' : 'transport-error';
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* A retryable failure the chain deliberately did not retry: the attempt had already started a tool
|
|
30
|
-
* call, and re-running the turn on a fallback would run that tool again. It ends the turn as a
|
|
31
|
-
* plain failure — no fallback, and no automatic resume either, which is what a rate-limit message
|
|
32
|
-
* would otherwise get. The message itself says what happened and asks the user to send again.
|
|
33
|
-
*/
|
|
34
|
-
export function notRetriedFailure(message) {
|
|
35
|
-
return Object.assign(new Error(message), { notRetried: true });
|
|
36
|
-
}
|
|
37
|
-
export function isNotRetriedFailure(error) {
|
|
38
|
-
return typeof error === 'object' && error !== null && error.notRetried === true;
|
|
39
|
-
}
|
|
@@ -3,7 +3,7 @@ import { Capability } from '../../agent-adapter/capabilities.js';
|
|
|
3
3
|
import type { UserMessage } from '../../agent-adapter/types.js';
|
|
4
4
|
import type { RunEvent, RunPhase } from '../../agent-adapter/run-events.js';
|
|
5
5
|
import { type RunSpend } from './spend.js';
|
|
6
|
-
import type {
|
|
6
|
+
import type { EngineSelection } from '../agents/engine-selection.js';
|
|
7
7
|
import type { RunObserver, RunRequest, RunResult } from './request.js';
|
|
8
8
|
/** How a run ends. `rate-limited` stays its own outcome; the execution record files it as a failure
|
|
9
9
|
* that names the rate limit (`executions/registry.ts` teardownExecution). */
|
|
@@ -20,15 +20,11 @@ export interface AgentRun {
|
|
|
20
20
|
readonly numTurns: number | null;
|
|
21
21
|
readonly attempt: {
|
|
22
22
|
index: number;
|
|
23
|
-
config:
|
|
23
|
+
config: EngineSelection;
|
|
24
24
|
};
|
|
25
|
-
/**
|
|
26
|
-
* The session's resume target: the backend session id on the session's OWN backend (the
|
|
27
|
-
* profile's). A fallback attempt on another backend never names it — its id would be resumed by
|
|
28
|
-
* the wrong CLI next turn — so across such a fallback this keeps the primary's id.
|
|
29
|
-
*/
|
|
25
|
+
/** The session's resume target on the selected backend. */
|
|
30
26
|
readonly backendSessionId: string | null;
|
|
31
|
-
/** What the
|
|
27
|
+
/** What the selected backend can do. */
|
|
32
28
|
readonly capabilities: ReadonlySet<Capability>;
|
|
33
29
|
/** The awaited foreground turn's result. */
|
|
34
30
|
readonly result: Promise<RunResult>;
|
|
@@ -72,9 +68,7 @@ export interface RunTerminalInfo {
|
|
|
72
68
|
/** What the run had produced when it ended — the foreground turn plus every continuation that
|
|
73
69
|
* settled, also on a cancelled or failed run, so the spend already incurred is not lost. */
|
|
74
70
|
result: RunResult | null;
|
|
75
|
-
/** Everything the run spent,
|
|
76
|
-
* the session totals carry. The attempts the chain moved past count by the cost rows they
|
|
77
|
-
* streamed (the rows the ledger got); the last one by `result` when there is one. */
|
|
71
|
+
/** Everything the run spent, including background continuations. */
|
|
78
72
|
spend: RunSpend;
|
|
79
73
|
error?: Error;
|
|
80
74
|
durationS: number;
|
|
@@ -107,9 +101,6 @@ export declare class AgentRunImpl implements AgentRun {
|
|
|
107
101
|
/** Continuation results seen so far. The live tally and a run that ends before its attempt
|
|
108
102
|
* settles (Stop, failure) read them; a settled attempt reports its own merged result. */
|
|
109
103
|
private readonly continuations;
|
|
110
|
-
/** What each attempt the chain moved past had spent. Each entry keeps counting until the run
|
|
111
|
-
* ends: a retired attempt's late cost rows still reach the ledger, so they count here too. */
|
|
112
|
-
private readonly retiredSpend;
|
|
113
104
|
/** What the running attempt has streamed so far: a run that ends with no result still cost it. */
|
|
114
105
|
private liveSpend;
|
|
115
106
|
private readonly observers;
|
|
@@ -118,9 +109,7 @@ export declare class AgentRunImpl implements AgentRun {
|
|
|
118
109
|
private readonly startedAt;
|
|
119
110
|
private readonly settleDeferred;
|
|
120
111
|
private readonly resultDeferred;
|
|
121
|
-
/**
|
|
122
|
-
private readonly plan;
|
|
123
|
-
/** Narrates the chain. It sits IN the event path because it can swallow a line. */
|
|
112
|
+
/** Narrates the attempt. It sits in the event path because it can swallow a line. */
|
|
124
113
|
private readonly notices;
|
|
125
114
|
/** Mirrors the old dispatcher's `active`: once the foreground turn is over, the run stops
|
|
126
115
|
* synthesizing notices about itself — the background phase is not a new turn to announce. */
|
|
@@ -134,7 +123,7 @@ export declare class AgentRunImpl implements AgentRun {
|
|
|
134
123
|
constructor(args: CreateAgentRunArgs);
|
|
135
124
|
get attempt(): {
|
|
136
125
|
index: number;
|
|
137
|
-
config:
|
|
126
|
+
config: EngineSelection;
|
|
138
127
|
};
|
|
139
128
|
get status(): RunStatus;
|
|
140
129
|
get phase(): RunPhase;
|
|
@@ -150,29 +139,11 @@ export declare class AgentRunImpl implements AgentRun {
|
|
|
150
139
|
claimBackgroundTranscript(): void;
|
|
151
140
|
/** Begin the run. Called exactly once by `startRun`, synchronously. */
|
|
152
141
|
start(): void;
|
|
153
|
-
/**
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
*
|
|
158
|
-
* The whole chain is one run: the same runId, the same observers, one execution record. Only
|
|
159
|
-
* `attempt.index` moves.
|
|
160
|
-
*/
|
|
161
|
-
private walkChain;
|
|
162
|
-
/**
|
|
163
|
-
* One attempt. Returns 'settled' when the run is over, or why the chain should advance.
|
|
164
|
-
*
|
|
165
|
-
* A fallback re-runs the whole turn in a fresh backend conversation. That is only safe before
|
|
166
|
-
* the turn started any tool call — a rate limit or a transport failure alike; after one, the
|
|
167
|
-
* re-run would repeat its side effects, so the turn ends with an error that says why it was not
|
|
168
|
-
* retried. The last attempt has nothing to fall back to and settles as it always did.
|
|
169
|
-
*/
|
|
170
|
-
private runAttempt;
|
|
171
|
-
/** The route (base URL + credentials) this attempt runs under. Per-attempt, because a fallback
|
|
172
|
-
* may be a different mode entirely. */
|
|
142
|
+
/** One selection, at most one spawn. Background work never waits for a throttled provider. */
|
|
143
|
+
private runOnce;
|
|
144
|
+
private openAttempt;
|
|
145
|
+
/** The route (base URL + credentials) this run uses. */
|
|
173
146
|
private routeFor;
|
|
174
|
-
/** The chain moved on. Report it on the stream; the surface renders the notice. */
|
|
175
|
-
private advanceAttempt;
|
|
176
147
|
/** Every attempt that reached a backend settles here: provider attribution and the auth
|
|
177
148
|
* lifecycle apply to the WHOLE attempt, background phase included, which is why they are done
|
|
178
149
|
* on the settled value rather than wrapped around the foreground promise. */
|
|
@@ -182,8 +153,7 @@ export declare class AgentRunImpl implements AgentRun {
|
|
|
182
153
|
* record open forever, because nothing ever emitted the engine's terminal `phase`.) */
|
|
183
154
|
private settleBlocked;
|
|
184
155
|
private onAttemptError;
|
|
185
|
-
/** Stamp the
|
|
186
|
-
* selection (an unknown profile name) names no provider: see `attemptProviderOrNull`. */
|
|
156
|
+
/** Stamp the selected provider onto a result that did not name one. */
|
|
187
157
|
private attribute;
|
|
188
158
|
private attributeError;
|
|
189
159
|
/** Auth is a property of the provider, not of the turn: a run that came back without a rate
|
package/dist/domain/runs/run.js
CHANGED
|
@@ -4,10 +4,10 @@ import { mergeContinuation } from '../../agent-adapter/continuation-phase.js';
|
|
|
4
4
|
import { CAPABILITIES_BY_BACKEND, Capability } from '../../agent-adapter/capabilities.js';
|
|
5
5
|
import { getSettings } from '../../core/settings.js';
|
|
6
6
|
import { t } from '../../core/i18n.js';
|
|
7
|
-
import {
|
|
8
|
-
import { NO_SPEND,
|
|
7
|
+
import { isRetryableError } from './retryable-errors.js';
|
|
8
|
+
import { NO_SPEND, countSpend, spendOfResult } from './spend.js';
|
|
9
9
|
import { publishAuthRecovered, publishAuthRequired, classifyAuthError } from '../auth/auth-events.js';
|
|
10
|
-
import { attemptAuthType, attemptProvider, attemptProviderOrNull, rateLimitedResult, shouldSkipAttempt,
|
|
10
|
+
import { attemptAuthType, attemptProvider, attemptProviderOrNull, rateLimitedResult, shouldSkipAttempt, } from './fallback.js';
|
|
11
11
|
import { requestRoute } from './config-resolver.js';
|
|
12
12
|
import { AttemptNoticeTracker, assistantNoticeLevel } from './notices.js';
|
|
13
13
|
import { startAttempt } from './attempt.js';
|
|
@@ -17,12 +17,6 @@ const PLUGIN_WARNINGS_SHOWN = 3;
|
|
|
17
17
|
function asError(error) {
|
|
18
18
|
return error instanceof Error ? error : new Error(String(error));
|
|
19
19
|
}
|
|
20
|
-
/** The error a turn ends with when a retryable failure hit after it had started a tool call. It
|
|
21
|
-
* keeps the original message — auth classification and provider attribution read it. */
|
|
22
|
-
function notRetriedAfterTools(reason, message) {
|
|
23
|
-
const key = reason === 'rate-limited' ? 'status.rateLimitedMidTurn' : 'status.notRetriedAfterTools';
|
|
24
|
-
return notRetriedFailure(t(key, { message }));
|
|
25
|
-
}
|
|
26
20
|
function cancellationError(reason) {
|
|
27
21
|
return Object.assign(new Error(`Run cancelled (${reason})`), { cancelled: true });
|
|
28
22
|
}
|
|
@@ -45,9 +39,6 @@ export class AgentRunImpl {
|
|
|
45
39
|
/** Continuation results seen so far. The live tally and a run that ends before its attempt
|
|
46
40
|
* settles (Stop, failure) read them; a settled attempt reports its own merged result. */
|
|
47
41
|
continuations = [];
|
|
48
|
-
/** What each attempt the chain moved past had spent. Each entry keeps counting until the run
|
|
49
|
-
* ends: a retired attempt's late cost rows still reach the ledger, so they count here too. */
|
|
50
|
-
retiredSpend = [];
|
|
51
42
|
/** What the running attempt has streamed so far: a run that ends with no result still cost it. */
|
|
52
43
|
liveSpend = null;
|
|
53
44
|
observers;
|
|
@@ -56,9 +47,7 @@ export class AgentRunImpl {
|
|
|
56
47
|
startedAt;
|
|
57
48
|
settleDeferred = deferred();
|
|
58
49
|
resultDeferred = deferred();
|
|
59
|
-
/**
|
|
60
|
-
plan;
|
|
61
|
-
/** Narrates the chain. It sits IN the event path because it can swallow a line. */
|
|
50
|
+
/** Narrates the attempt. It sits in the event path because it can swallow a line. */
|
|
62
51
|
notices;
|
|
63
52
|
/** Mirrors the old dispatcher's `active`: once the foreground turn is over, the run stops
|
|
64
53
|
* synthesizing notices about itself — the background phase is not a new turn to announce. */
|
|
@@ -73,8 +62,7 @@ export class AgentRunImpl {
|
|
|
73
62
|
this.request = args.request;
|
|
74
63
|
this.executionId = args.executionId;
|
|
75
64
|
this.id = args.request.runId;
|
|
76
|
-
this.
|
|
77
|
-
this.attemptValue = { index: 0, config: this.plan[0] };
|
|
65
|
+
this.attemptValue = { index: 0, config: args.request.selection };
|
|
78
66
|
this.notices = new AttemptNoticeTracker({
|
|
79
67
|
channel: args.request.context.channel,
|
|
80
68
|
isUserInitiated: args.request.context.isUserInitiated,
|
|
@@ -110,7 +98,7 @@ export class AgentRunImpl {
|
|
|
110
98
|
/** True while the running attempt is on the session's own backend, i.e. while its backend id
|
|
111
99
|
* may become the session's resume target (see `backendSessionId`). */
|
|
112
100
|
get onSessionBackend() {
|
|
113
|
-
return this.attemptValue.config.backend === this.request.
|
|
101
|
+
return this.attemptValue.config.backend === this.request.selection.backend;
|
|
114
102
|
}
|
|
115
103
|
/** Adopt `id` as the resume target, unless the running attempt is on another backend. */
|
|
116
104
|
adoptBackendSessionId(id) {
|
|
@@ -124,146 +112,52 @@ export class AgentRunImpl {
|
|
|
124
112
|
if (this.started)
|
|
125
113
|
return;
|
|
126
114
|
this.started = true;
|
|
127
|
-
void this.
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
async walkChain() {
|
|
138
|
-
let reason = 'rate-limited';
|
|
139
|
-
for (let index = 0; index < this.plan.length; index++) {
|
|
140
|
-
if (this.terminal)
|
|
141
|
-
return;
|
|
142
|
-
const attempt = this.plan[index];
|
|
143
|
-
const isLast = index === this.plan.length - 1;
|
|
144
|
-
if (index > 0)
|
|
145
|
-
this.advanceAttempt(index, attempt, reason);
|
|
146
|
-
if (shouldSkipAttempt(attempt, { isUserInitiated: this.request.context.isUserInitiated })) {
|
|
147
|
-
const blocked = rateLimitedResult(attempt.mode || 'api', attemptProvider(attempt));
|
|
148
|
-
if (isLast) {
|
|
149
|
-
this.notices.emitTerminalRateLimit(blocked);
|
|
150
|
-
this.settleBlocked(blocked);
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
log.info(`${attemptLabel(attempt)} rate-limited, skipping to fallback[${index}]`);
|
|
154
|
-
reason = 'rate-limited';
|
|
155
|
-
this.notices.transitionToFallback(attempt, this.plan[index + 1], reason);
|
|
156
|
-
continue;
|
|
157
|
-
}
|
|
158
|
-
const outcome = await this.runAttempt(attempt, index, isLast);
|
|
159
|
-
if (outcome === 'settled')
|
|
160
|
-
return;
|
|
161
|
-
reason = outcome;
|
|
162
|
-
this.notices.transitionToFallback(attempt, this.plan[index + 1], reason);
|
|
115
|
+
void this.runOnce();
|
|
116
|
+
}
|
|
117
|
+
/** One selection, at most one spawn. Background work never waits for a throttled provider. */
|
|
118
|
+
async runOnce() {
|
|
119
|
+
const attempt = this.request.selection;
|
|
120
|
+
if (shouldSkipAttempt(attempt, this.request.context)) {
|
|
121
|
+
const blocked = rateLimitedResult(attempt.mode, attemptProvider(attempt));
|
|
122
|
+
this.notices.emitTerminalRateLimit(blocked);
|
|
123
|
+
this.settleBlocked(blocked);
|
|
124
|
+
return;
|
|
163
125
|
}
|
|
164
|
-
// Unreachable: the last attempt always settles or throws. Guard rather than hang.
|
|
165
|
-
if (!this.terminal)
|
|
166
|
-
this.finishForegroundError(new Error('All fallback configs exhausted without result'));
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* One attempt. Returns 'settled' when the run is over, or why the chain should advance.
|
|
170
|
-
*
|
|
171
|
-
* A fallback re-runs the whole turn in a fresh backend conversation. That is only safe before
|
|
172
|
-
* the turn started any tool call — a rate limit or a transport failure alike; after one, the
|
|
173
|
-
* re-run would repeat its side effects, so the turn ends with an error that says why it was not
|
|
174
|
-
* retried. The last attempt has nothing to fall back to and settles as it always did.
|
|
175
|
-
*/
|
|
176
|
-
async runAttempt(attempt, index, isLast) {
|
|
177
|
-
// A retry starts a fresh backend conversation: the previous attempt's resume target belongs to
|
|
178
|
-
// a provider that just failed us.
|
|
179
|
-
const request = index === 0
|
|
180
|
-
? this.request
|
|
181
|
-
: { ...this.request, session: { ...this.request.session, backendSessionId: null } };
|
|
182
|
-
// Once the chain moves on, whatever this attempt still streams (a hold-mode background phase,
|
|
183
|
-
// the close of its engine) belongs to no one: observers follow the attempt that replaced it.
|
|
184
|
-
let abandoned = false;
|
|
185
|
-
let toolStarted = false;
|
|
186
|
-
const spend = { ...NO_SPEND };
|
|
187
|
-
this.liveSpend = spend;
|
|
188
|
-
const retire = (reason) => {
|
|
189
|
-
abandoned = true;
|
|
190
|
-
this.retiredSpend.push(spend);
|
|
191
|
-
this.liveSpend = null;
|
|
192
|
-
return reason;
|
|
193
|
-
};
|
|
194
126
|
let current;
|
|
195
127
|
try {
|
|
196
|
-
current =
|
|
197
|
-
request, attempt, executionId: this.executionId,
|
|
198
|
-
route: this.routeFor(attempt),
|
|
199
|
-
onEvent: (event) => {
|
|
200
|
-
countSpend(spend, event);
|
|
201
|
-
if (abandoned)
|
|
202
|
-
return;
|
|
203
|
-
if (event.type === 'tool_use')
|
|
204
|
-
toolStarted = true;
|
|
205
|
-
this.onRunEvent(event);
|
|
206
|
-
},
|
|
207
|
-
});
|
|
128
|
+
current = this.openAttempt(attempt);
|
|
208
129
|
}
|
|
209
130
|
catch (error) {
|
|
210
131
|
this.onForegroundError(error);
|
|
211
|
-
return
|
|
132
|
+
return;
|
|
212
133
|
}
|
|
213
|
-
this.current = current;
|
|
214
|
-
this.registerAttempt(current);
|
|
215
|
-
this.announcePluginWarnings(current.spec);
|
|
216
134
|
try {
|
|
217
|
-
|
|
218
|
-
if (!isRetryableResult(result) || isLast) {
|
|
219
|
-
this.settleAttemptResult(current, result);
|
|
220
|
-
return 'settled';
|
|
221
|
-
}
|
|
222
|
-
// The attempt ends here with a result of its own: its turn count is the last word.
|
|
223
|
-
const resultTurns = spendOfResult(result).numTurns;
|
|
224
|
-
if (resultTurns !== null)
|
|
225
|
-
spend.numTurns = Math.max(spend.numTurns ?? 0, resultTurns);
|
|
226
|
-
if (toolStarted) {
|
|
227
|
-
log.info(`${attemptLabel(attempt)} rate limited after a tool ran; not retrying on fallback[${index}]`);
|
|
228
|
-
const detail = result.rateLimitMessage || t('status.rateLimitedExhausted');
|
|
229
|
-
this.onAttemptError(current, attempt, notRetriedAfterTools('rate-limited', detail));
|
|
230
|
-
return 'settled';
|
|
231
|
-
}
|
|
232
|
-
log.info(`${attemptLabel(attempt)} rate limited, trying fallback[${index}]`);
|
|
233
|
-
return retire('rate-limited');
|
|
135
|
+
this.settleAttemptResult(current, await current.foreground);
|
|
234
136
|
}
|
|
235
137
|
catch (error) {
|
|
236
|
-
|
|
237
|
-
if (this.cancelRequested || !isRetryableError(failure) || isLast) {
|
|
238
|
-
this.onAttemptError(current, attempt, error);
|
|
239
|
-
return 'settled';
|
|
240
|
-
}
|
|
241
|
-
const reason = fallbackReasonOf(failure);
|
|
242
|
-
if (toolStarted) {
|
|
243
|
-
log.info(`${attemptLabel(attempt)} ${reason} after a tool ran; not retrying on fallback[${index}]`);
|
|
244
|
-
this.onAttemptError(current, attempt, notRetriedAfterTools(reason, failure.message));
|
|
245
|
-
return 'settled';
|
|
246
|
-
}
|
|
247
|
-
log.info(`${attemptLabel(attempt)} retryable error (${reason}), trying fallback[${index}]`);
|
|
248
|
-
return retire(reason);
|
|
138
|
+
this.onAttemptError(current, attempt, error);
|
|
249
139
|
}
|
|
250
140
|
}
|
|
251
|
-
|
|
252
|
-
|
|
141
|
+
openAttempt(attempt) {
|
|
142
|
+
const spend = { ...NO_SPEND };
|
|
143
|
+
this.liveSpend = spend;
|
|
144
|
+
const current = startAttempt({
|
|
145
|
+
request: this.request, attempt, executionId: this.executionId,
|
|
146
|
+
route: this.routeFor(attempt),
|
|
147
|
+
onEvent: (event) => {
|
|
148
|
+
countSpend(spend, event);
|
|
149
|
+
this.onRunEvent(event);
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
this.current = current;
|
|
153
|
+
this.registerAttempt(current);
|
|
154
|
+
this.announcePluginWarnings(current.spec);
|
|
155
|
+
return current;
|
|
156
|
+
}
|
|
157
|
+
/** The route (base URL + credentials) this run uses. */
|
|
253
158
|
routeFor(attempt) {
|
|
254
159
|
return requestRoute(this.request, attempt);
|
|
255
160
|
}
|
|
256
|
-
/** The chain moved on. Report it on the stream; the surface renders the notice. */
|
|
257
|
-
advanceAttempt(index, next, reason) {
|
|
258
|
-
const previous = this.attemptValue.config;
|
|
259
|
-
this.attemptValue = { index, config: next };
|
|
260
|
-
this.absorb({
|
|
261
|
-
type: 'run_fallback',
|
|
262
|
-
from: attemptLabel(previous),
|
|
263
|
-
to: attemptLabel(next),
|
|
264
|
-
reason,
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
161
|
/** Every attempt that reached a backend settles here: provider attribution and the auth
|
|
268
162
|
* lifecycle apply to the WHOLE attempt, background phase included, which is why they are done
|
|
269
163
|
* on the settled value rather than wrapped around the foreground promise. */
|
|
@@ -291,8 +185,7 @@ export class AgentRunImpl {
|
|
|
291
185
|
void current.settled.catch(() => undefined);
|
|
292
186
|
this.onForegroundError(failure);
|
|
293
187
|
}
|
|
294
|
-
/** Stamp the
|
|
295
|
-
* selection (an unknown profile name) names no provider: see `attemptProviderOrNull`. */
|
|
188
|
+
/** Stamp the selected provider onto a result that did not name one. */
|
|
296
189
|
attribute(result) {
|
|
297
190
|
const provider = attemptProviderOrNull(this.attemptValue.config);
|
|
298
191
|
if (!provider || result.rateLimitProvider)
|
|
@@ -444,7 +337,7 @@ export class AgentRunImpl {
|
|
|
444
337
|
}
|
|
445
338
|
break;
|
|
446
339
|
case 'model_fallback':
|
|
447
|
-
// The
|
|
340
|
+
// The backend itself swapped models — report its native event.
|
|
448
341
|
if (this.noticesActive) {
|
|
449
342
|
this.notices.observe(t('notify.agentFallback', {
|
|
450
343
|
from: event.originalModel, to: event.fallbackModel,
|
|
@@ -637,7 +530,7 @@ export class AgentRunImpl {
|
|
|
637
530
|
* what it streamed. */
|
|
638
531
|
runSpend(result) {
|
|
639
532
|
const last = result ? spendOfResult(result) : this.liveSpend ?? NO_SPEND;
|
|
640
|
-
return
|
|
533
|
+
return last;
|
|
641
534
|
}
|
|
642
535
|
// ── observer fan-out ───────────────────────────────────────────────────
|
|
643
536
|
fanOut(event) {
|
|
@@ -5,7 +5,7 @@ import type { RunObserver, RunRequest } from './request.js';
|
|
|
5
5
|
* `AgentRun` that owns the rest of the lifecycle. This is the single entry point every surface is
|
|
6
6
|
* meant to call.
|
|
7
7
|
*
|
|
8
|
-
* The run
|
|
8
|
+
* The run opens one attempt on its pooled engine session and feeds every signal through
|
|
9
9
|
* one `RunEvent` stream. `teardownExecution` and the registry removal happen exactly once, from
|
|
10
10
|
* the run's terminal handler.
|
|
11
11
|
*/
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { runRegistry } from '../../core/run-registry.js';
|
|
2
|
+
import { sessionBenchmarkMaxOutputTokens } from '../benchmark/session-evidence.js';
|
|
2
3
|
import * as executionRegistry from '../executions/registry.js';
|
|
3
4
|
import { AgentRunImpl } from './run.js';
|
|
4
5
|
/**
|
|
@@ -6,19 +7,23 @@ import { AgentRunImpl } from './run.js';
|
|
|
6
7
|
* `AgentRun` that owns the rest of the lifecycle. This is the single entry point every surface is
|
|
7
8
|
* meant to call.
|
|
8
9
|
*
|
|
9
|
-
* The run
|
|
10
|
+
* The run opens one attempt on its pooled engine session and feeds every signal through
|
|
10
11
|
* one `RunEvent` stream. `teardownExecution` and the registry removal happen exactly once, from
|
|
11
12
|
* the run's terminal handler.
|
|
12
13
|
*/
|
|
13
14
|
export function startRun(request, observers) {
|
|
15
|
+
if (request.benchmark?.evidenceContext && request.session.sessionId) {
|
|
16
|
+
request = { ...request, benchmarkMaxOutputTokens: request.benchmarkMaxOutputTokens
|
|
17
|
+
?? sessionBenchmarkMaxOutputTokens(request.session.sessionId) };
|
|
18
|
+
}
|
|
14
19
|
const startedAt = Date.now();
|
|
15
20
|
const execution = executionRegistry.startLocalExecution({
|
|
16
21
|
kind: request.context.executionKind,
|
|
17
22
|
channel: request.context.channel,
|
|
18
23
|
project: request.context.project,
|
|
19
24
|
trigger: request.context.trigger,
|
|
20
|
-
backend: request.
|
|
21
|
-
billingMode: request.
|
|
25
|
+
backend: request.selection.backend,
|
|
26
|
+
billingMode: request.selection.mode || 'api',
|
|
22
27
|
sessionId: request.session.sessionId,
|
|
23
28
|
ownerSessionId: request.context.ownerSessionId ?? null,
|
|
24
29
|
label: request.prompt.text.substring(0, 60),
|
|
@@ -17,7 +17,7 @@ import type { McpComposition } from '../../agent-adapter/types.js';
|
|
|
17
17
|
*/
|
|
18
18
|
export type ToolSurface = string[] | string | null;
|
|
19
19
|
/**
|
|
20
|
-
* What an agent *is*, independent of which
|
|
20
|
+
* What an agent *is*, independent of which model/route runs it. Every field is resolved: no
|
|
21
21
|
* file refs, no `__active__`, no template placeholders left to expand.
|
|
22
22
|
*/
|
|
23
23
|
export interface AgentSpec {
|
|
@@ -11,6 +11,6 @@ export declare function spendOfResult(result: RunResult): RunSpend;
|
|
|
11
11
|
/**
|
|
12
12
|
* Fold one event of an attempt's stream into what that attempt has spent: every cost row (the
|
|
13
13
|
* same rows the ledger records) and its latest turn count. This is how an attempt that ends with
|
|
14
|
-
* no result of its own —
|
|
14
|
+
* no result of its own — failed or stopped — still accounts for its spend.
|
|
15
15
|
*/
|
|
16
16
|
export declare function countSpend(spend: RunSpend, event: RunEvent): void;
|
|
@@ -17,7 +17,7 @@ export function spendOfResult(result) {
|
|
|
17
17
|
/**
|
|
18
18
|
* Fold one event of an attempt's stream into what that attempt has spent: every cost row (the
|
|
19
19
|
* same rows the ledger records) and its latest turn count. This is how an attempt that ends with
|
|
20
|
-
* no result of its own —
|
|
20
|
+
* no result of its own — failed or stopped — still accounts for its spend.
|
|
21
21
|
*/
|
|
22
22
|
export function countSpend(spend, event) {
|
|
23
23
|
if (event.type === 'cost_record') {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { applyChannelSelection } from '../../agents/index.js';
|
|
2
|
+
import type { EngineSelection } from '../../agents/engine-selection.js';
|
|
2
3
|
import { createDirectSession } from '../../sessions/session-lifecycle.js';
|
|
3
4
|
export interface RunScheduledTaskInput {
|
|
4
5
|
message: string;
|
|
5
6
|
projectId: string;
|
|
6
7
|
scheduleTaskId: string;
|
|
7
|
-
|
|
8
|
+
selection: EngineSelection;
|
|
8
9
|
}
|
|
9
10
|
/** Collaborators the run is opened with. Production uses the real stores; tests inject their own. */
|
|
10
11
|
export interface ScheduledRunDeps {
|
|
@@ -20,4 +21,4 @@ export declare function runScheduledTask(input: RunScheduledTaskInput, deps?: Sc
|
|
|
20
21
|
* the schedule's run — and delivers the schedule's prompt as its first turn. Everything after that
|
|
21
22
|
* (the run itself, a rate-limit pause and its resume, a reply adopting the run) is the session's.
|
|
22
23
|
*/
|
|
23
|
-
export declare function fireScheduledTask(
|
|
24
|
+
export declare function fireScheduledTask(input: RunScheduledTaskInput, deps?: ScheduledRunDeps): Promise<void>;
|
|
@@ -5,12 +5,11 @@ import * as executionRegistry from '../../executions/registry.js';
|
|
|
5
5
|
import { sessionStore } from '../../../store/session-registry-repo.js';
|
|
6
6
|
import { conversationLedger } from '../../../store/conversation-ledger-repo.js';
|
|
7
7
|
import { applyChannelSelection, resolveBackendForChannel } from '../../agents/index.js';
|
|
8
|
-
import { getDefaultProfileName } from '../../agents/profile-manager.js';
|
|
9
8
|
import { projectStore } from '../../projects/index.js';
|
|
10
9
|
import { createDirectSession } from '../../sessions/session-lifecycle.js';
|
|
11
10
|
import { setSessionAsync } from '../../sessions/session.js';
|
|
12
11
|
import { isValidDispatchPrompt, hasRunningExecutionForSchedule } from '../run-guards.js';
|
|
13
|
-
import {
|
|
12
|
+
import { configIsRateLimited } from '../../agents/provider-run-lifecycle.js';
|
|
14
13
|
import { t } from '../../../core/i18n.js';
|
|
15
14
|
import { publishSystemNotice } from '../../system/system-notice.js';
|
|
16
15
|
const log = createLogger('scheduled-task');
|
|
@@ -47,22 +46,19 @@ export function runScheduledTask(input, deps = defaultDeps) {
|
|
|
47
46
|
* the schedule's run — and delivers the schedule's prompt as its first turn. Everything after that
|
|
48
47
|
* (the run itself, a rate-limit pause and its resume, a reply adopting the run) is the session's.
|
|
49
48
|
*/
|
|
50
|
-
export async function fireScheduledTask(
|
|
49
|
+
export async function fireScheduledTask(input, deps = defaultDeps) {
|
|
50
|
+
const { projectId, scheduleTaskId } = input;
|
|
51
51
|
const schedKey = `sched:${scheduleTaskId || projectId}`;
|
|
52
52
|
if (!passScheduledGuards(schedKey, scheduleTaskId))
|
|
53
53
|
return;
|
|
54
|
-
if (!
|
|
55
|
-
log.warn(`Guard dropped null/empty prompt for schedule ${scheduleTaskId} (project=${projectId}, profile=${profileName}): "${message?.substring(0, 60) || String(message)}"`);
|
|
54
|
+
if (!(await canOpenScheduledRun(input)))
|
|
56
55
|
return;
|
|
57
|
-
|
|
58
|
-
if (
|
|
59
|
-
log.info(`Skipping schedule ${scheduleTaskId} — all configs rate-limited for profile ${profileName}`);
|
|
60
|
-
await notifySkippedSchedule(projectId, t('notice.schedule.rateLimited', { id: scheduleTaskId, message }));
|
|
56
|
+
// Re-check after the async guard: another fire may already have reserved this schedule.
|
|
57
|
+
if (!passScheduledGuards(schedKey, scheduleTaskId))
|
|
61
58
|
return;
|
|
62
|
-
}
|
|
63
59
|
scheduledTaskActive.add(schedKey);
|
|
64
60
|
try {
|
|
65
|
-
await openScheduledRun(
|
|
61
|
+
await openScheduledRun(input, deps);
|
|
66
62
|
}
|
|
67
63
|
catch (error) {
|
|
68
64
|
// Nothing ran, so the notice is the only trace this fire leaves.
|
|
@@ -73,23 +69,33 @@ export async function fireScheduledTask({ message, projectId, scheduleTaskId, pr
|
|
|
73
69
|
scheduledTaskActive.delete(schedKey);
|
|
74
70
|
}
|
|
75
71
|
}
|
|
76
|
-
async function
|
|
72
|
+
async function canOpenScheduledRun({ message, projectId, scheduleTaskId, selection }) {
|
|
73
|
+
if (!isValidDispatchPrompt(message)) {
|
|
74
|
+
log.warn(`Guard dropped null/empty prompt for schedule ${scheduleTaskId} (project=${projectId}, model=${selection.model}): "${message?.substring(0, 60) || String(message)}"`);
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
if (!configIsRateLimited(selection))
|
|
78
|
+
return true;
|
|
79
|
+
log.info(`Skipping schedule ${scheduleTaskId} — selection ${selection.backend}/${selection.model} is rate-limited`);
|
|
80
|
+
await notifySkippedSchedule(projectId, t('notice.schedule.rateLimited', { id: scheduleTaskId, message }));
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
async function openScheduledRun({ message, projectId, scheduleTaskId, selection }, deps) {
|
|
77
84
|
const deliver = requireJobCtx('deliverScheduledTurn');
|
|
78
85
|
const sessionId = deps.newSessionId();
|
|
79
86
|
const channel = `web:${sessionId}`;
|
|
80
|
-
//
|
|
81
|
-
//
|
|
82
|
-
const applied = await deps.applySelection({
|
|
83
|
-
channel, profileName: profileName || getDefaultProfileName(), seedDefault: false,
|
|
84
|
-
});
|
|
87
|
+
// Apply the complete stored selection before creating the session, without changing the seed
|
|
88
|
+
// for the user's next conversation.
|
|
89
|
+
const applied = await deps.applySelection({ channel, ...selection, seedDefault: false });
|
|
85
90
|
if (!applied.ok)
|
|
86
|
-
throw new Error(`cannot run on
|
|
91
|
+
throw new Error(`cannot run on model "${selection.model}": ${applied.reason}`);
|
|
87
92
|
const created = await deps.createSession({
|
|
88
93
|
projectId: projectStore.exists(projectId)
|
|
89
94
|
? projectId
|
|
90
95
|
: projectStore.resolveFromMessage(message)?.id ?? 'general',
|
|
91
96
|
sessionId,
|
|
92
|
-
|
|
97
|
+
selection,
|
|
98
|
+
seedDefault: false,
|
|
93
99
|
scheduleId: scheduleTaskId || null,
|
|
94
100
|
label: message.substring(0, 60) || null,
|
|
95
101
|
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { ScheduleRepo, ScheduleTask } from '../../store/schedule-repo.js';
|
|
2
2
|
import { type ScheduleSpec, type SchedulePatch } from './schedule-spec.js';
|
|
3
3
|
type Repo = Pick<ScheduleRepo, 'mutate' | 'updateTask'>;
|
|
4
|
-
export declare function resolveTaskProfile(profile: string | null | undefined): string;
|
|
5
4
|
/** Persist a new schedule. With an idempotency key, a schedule already created under that key is
|
|
6
5
|
* returned instead of adding a second one. */
|
|
7
6
|
export declare function addSchedule(repo: Repo, spec: ScheduleSpec, opts?: {
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { randomBytes } from 'crypto';
|
|
2
|
-
import {
|
|
2
|
+
import { getDefaultSelection } from '../agents/models.js';
|
|
3
3
|
import { buildScheduleTask, normalizeSchedulePatch, retimeTask, } from './schedule-spec.js';
|
|
4
|
-
export function resolveTaskProfile(profile) {
|
|
5
|
-
return profile || getDefaultProfileName();
|
|
6
|
-
}
|
|
7
4
|
/** Persist a new schedule. With an idempotency key, a schedule already created under that key is
|
|
8
5
|
* returned instead of adding a second one. */
|
|
9
6
|
export async function addSchedule(repo, spec, opts = {}) {
|
|
10
|
-
const task = buildScheduleTask(spec, randomBytes(4).toString('hex'), Date.now(),
|
|
7
|
+
const task = buildScheduleTask(spec, randomBytes(4).toString('hex'), Date.now(), spec.selection ?? getDefaultSelection());
|
|
11
8
|
const key = opts.idempotencyKey;
|
|
12
9
|
if (key)
|
|
13
10
|
task.idempotencyKey = key;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type EngineSelection } from '../agents/engine-selection.js';
|
|
2
|
+
/** CLI/chat model flags resolve once, at creation or edit, never again when the task fires. */
|
|
3
|
+
export declare function resolveScheduleSelection(model?: string, thinking?: string, current?: EngineSelection): EngineSelection | undefined;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { getDefaultSelection, resolveModelRef, selectionForModel } from '../agents/models.js';
|
|
2
|
+
import { isValidThinkingLevel, THINKING_LEVELS_BY_BACKEND } from '../agents/engine-selection.js';
|
|
3
|
+
import { ScheduleSpecError } from './schedule-spec.js';
|
|
4
|
+
/** CLI/chat model flags resolve once, at creation or edit, never again when the task fires. */
|
|
5
|
+
export function resolveScheduleSelection(model, thinking, current) {
|
|
6
|
+
if (model === undefined && thinking === undefined)
|
|
7
|
+
return undefined;
|
|
8
|
+
const selection = model === undefined ? current ?? getDefaultSelection() : selectionForModel(resolveModelRef(model));
|
|
9
|
+
if (thinking === undefined)
|
|
10
|
+
return { ...selection };
|
|
11
|
+
if (!isValidThinkingLevel(selection.backend, thinking)) {
|
|
12
|
+
const levels = THINKING_LEVELS_BY_BACKEND[selection.backend].join(', ');
|
|
13
|
+
throw new ScheduleSpecError('thinking', `Invalid thinking '${thinking}' for ${selection.backend}. Valid values: ${levels}`, thinking);
|
|
14
|
+
}
|
|
15
|
+
return { ...selection, thinking };
|
|
16
|
+
}
|