synabun 2.4.0 → 2.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +47 -0
- package/README.md +1 -1
- package/browser-extension/content.js +73 -11
- package/browser-extension/engine.js +196 -15
- package/browser-extension/manifest.json +4 -2
- package/browser-extension/popup-strings.js +10 -4
- package/browser-extension/popup-view.js +1 -1
- package/browser-extension/popup.css +1 -0
- package/browser-extension/popup.html +4 -1
- package/browser-extension/popup.js +22 -10
- package/browser-extension/protocol.js +102 -11
- package/browser-extension/service-worker.js +20 -4
- package/browser-extension/tokens.css +1 -1
- package/docs/browser-extension-bridge.md +25 -5
- package/lib/data-home-files.js +47 -0
- package/lib/data-home-migration.js +34 -58
- package/lib/first-launch-protection.js +8 -2
- package/lib/update-snapshot.js +11 -4
- package/mcp-server/dist/http.d.ts.map +1 -1
- package/mcp-server/dist/http.js +25 -2
- package/mcp-server/dist/http.js.map +1 -1
- package/mcp-server/dist/index.d.ts.map +1 -1
- package/mcp-server/dist/index.js +62 -17
- package/mcp-server/dist/index.js.map +1 -1
- package/mcp-server/dist/services/browser-bench.d.ts +22 -22
- package/mcp-server/dist/services/memory-maintenance.d.ts +1 -0
- package/mcp-server/dist/services/memory-maintenance.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-maintenance.js +34 -45
- package/mcp-server/dist/services/memory-maintenance.js.map +1 -1
- package/mcp-server/dist/services/memory-migration-copy.d.ts +144 -0
- package/mcp-server/dist/services/memory-migration-copy.d.ts.map +1 -0
- package/mcp-server/dist/services/memory-migration-copy.js +467 -0
- package/mcp-server/dist/services/memory-migration-copy.js.map +1 -0
- package/mcp-server/dist/services/memory-migration-worker.d.ts +2 -0
- package/mcp-server/dist/services/memory-migration-worker.d.ts.map +1 -0
- package/mcp-server/dist/services/memory-migration-worker.js +60 -0
- package/mcp-server/dist/services/memory-migration-worker.js.map +1 -0
- package/mcp-server/dist/services/memory-retrieval.d.ts +4 -0
- package/mcp-server/dist/services/memory-retrieval.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-retrieval.js +188 -40
- package/mcp-server/dist/services/memory-retrieval.js.map +1 -1
- package/mcp-server/dist/services/memory-schema.d.ts +58 -2
- package/mcp-server/dist/services/memory-schema.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-schema.js +190 -13
- package/mcp-server/dist/services/memory-schema.js.map +1 -1
- package/mcp-server/dist/services/memory-sessions.d.ts +19 -1
- package/mcp-server/dist/services/memory-sessions.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-sessions.js +56 -20
- package/mcp-server/dist/services/memory-sessions.js.map +1 -1
- package/mcp-server/dist/services/memory-verification.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-verification.js +8 -5
- package/mcp-server/dist/services/memory-verification.js.map +1 -1
- package/mcp-server/dist/services/neural-interface.d.ts +6 -0
- package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
- package/mcp-server/dist/services/neural-interface.js +19 -2
- package/mcp-server/dist/services/neural-interface.js.map +1 -1
- package/mcp-server/dist/services/retrieval-reader-worker.d.ts +2 -0
- package/mcp-server/dist/services/retrieval-reader-worker.d.ts.map +1 -0
- package/mcp-server/dist/services/retrieval-reader-worker.js +76 -0
- package/mcp-server/dist/services/retrieval-reader-worker.js.map +1 -0
- package/mcp-server/dist/services/retrieval-reader.d.ts +38 -0
- package/mcp-server/dist/services/retrieval-reader.d.ts.map +1 -0
- package/mcp-server/dist/services/retrieval-reader.js +145 -0
- package/mcp-server/dist/services/retrieval-reader.js.map +1 -0
- package/mcp-server/dist/services/sqlite-write.d.ts +14 -0
- package/mcp-server/dist/services/sqlite-write.d.ts.map +1 -0
- package/mcp-server/dist/services/sqlite-write.js +94 -0
- package/mcp-server/dist/services/sqlite-write.js.map +1 -0
- package/mcp-server/dist/services/sqlite.d.ts +39 -0
- package/mcp-server/dist/services/sqlite.d.ts.map +1 -1
- package/mcp-server/dist/services/sqlite.js +249 -8
- package/mcp-server/dist/services/sqlite.js.map +1 -1
- package/mcp-server/dist/services/tool-catalog.d.ts +1 -1
- package/mcp-server/dist/services/typesafe-config.d.ts +7 -1
- package/mcp-server/dist/services/typesafe-config.d.ts.map +1 -1
- package/mcp-server/dist/services/typesafe-config.js +32 -10
- package/mcp-server/dist/services/typesafe-config.js.map +1 -1
- package/mcp-server/dist/services/typesafe.d.ts.map +1 -1
- package/mcp-server/dist/services/typesafe.js +9 -7
- package/mcp-server/dist/services/typesafe.js.map +1 -1
- package/mcp-server/dist/services/vector-cache.d.ts +32 -0
- package/mcp-server/dist/services/vector-cache.d.ts.map +1 -1
- package/mcp-server/dist/services/vector-cache.js +161 -8
- package/mcp-server/dist/services/vector-cache.js.map +1 -1
- package/mcp-server/dist/tools/agent-definition.d.ts +2 -2
- package/mcp-server/dist/tools/agents.d.ts +13 -8
- package/mcp-server/dist/tools/agents.d.ts.map +1 -1
- package/mcp-server/dist/tools/agents.js +35 -15
- package/mcp-server/dist/tools/agents.js.map +1 -1
- package/mcp-server/dist/tools/browser-advanced.d.ts +1 -1
- package/mcp-server/dist/tools/browser-advanced.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-advanced.js +10 -3
- package/mcp-server/dist/tools/browser-advanced.js.map +1 -1
- package/mcp-server/dist/tools/browser-extension-setup.d.ts +5 -0
- package/mcp-server/dist/tools/browser-extension-setup.d.ts.map +1 -0
- package/mcp-server/dist/tools/browser-extension-setup.js +23 -0
- package/mcp-server/dist/tools/browser-extension-setup.js.map +1 -0
- package/mcp-server/dist/tools/browser-interact.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-interact.js +6 -1
- package/mcp-server/dist/tools/browser-interact.js.map +1 -1
- package/mcp-server/dist/tools/fb-groups.d.ts +2 -2
- package/mcp-server/dist/tools/skill-tools.d.ts +4 -4
- package/mcp-server/dist/tools/tool-groups.d.ts +1 -1
- package/mcp-server/package-lock.json +2 -2
- package/mcp-server/package.json +1 -1
- package/mcp-server/src/http.ts +20 -2
- package/mcp-server/src/index.ts +59 -17
- package/mcp-server/src/services/memory-maintenance.ts +31 -28
- package/mcp-server/src/services/memory-migration-copy.ts +419 -0
- package/mcp-server/src/services/memory-migration-worker.ts +55 -0
- package/mcp-server/src/services/memory-retrieval.ts +173 -32
- package/mcp-server/src/services/memory-schema.ts +194 -12
- package/mcp-server/src/services/memory-sessions.ts +54 -21
- package/mcp-server/src/services/memory-verification.ts +7 -4
- package/mcp-server/src/services/neural-interface.ts +23 -2
- package/mcp-server/src/services/retrieval-reader-worker.ts +67 -0
- package/mcp-server/src/services/retrieval-reader.ts +131 -0
- package/mcp-server/src/services/sqlite-write.ts +60 -0
- package/mcp-server/src/services/sqlite.ts +246 -8
- package/mcp-server/src/services/typesafe-config.ts +25 -6
- package/mcp-server/src/services/typesafe.ts +9 -7
- package/mcp-server/src/services/vector-cache.ts +154 -9
- package/mcp-server/src/tools/agents.ts +33 -14
- package/mcp-server/src/tools/browser-advanced.ts +10 -3
- package/mcp-server/src/tools/browser-extension-setup.ts +30 -0
- package/mcp-server/src/tools/browser-interact.ts +5 -1
- package/neural-interface/i18n/en.json +266 -2
- package/neural-interface/i18n/pt-BR.json +267 -3
- package/neural-interface/lib/agents/builtins.json +207 -0
- package/neural-interface/lib/agents/registry.js +60 -15
- package/neural-interface/lib/agents/resolve.js +69 -10
- package/neural-interface/lib/agents/split.js +32 -4
- package/neural-interface/lib/assistant-api.js +19 -8
- package/neural-interface/lib/assistant-brains/claude.js +2 -0
- package/neural-interface/lib/assistant-brains/opencode.js +60 -11
- package/neural-interface/lib/assistant-catalog.js +2 -2
- package/neural-interface/lib/assistant-config.js +0 -7
- package/neural-interface/lib/assistant-dispatch.js +384 -119
- package/neural-interface/lib/assistant-persona.js +17 -5
- package/neural-interface/lib/assistant-pricing.js +65 -14
- package/neural-interface/lib/assistant-router.js +181 -54
- package/neural-interface/lib/assistant-run-wait.js +45 -28
- package/neural-interface/lib/assistant-runtime.js +48 -34
- package/neural-interface/lib/backup-contents.js +158 -0
- package/neural-interface/lib/backup-crypto-io.js +330 -0
- package/neural-interface/lib/backup-crypto-worker.js +130 -0
- package/neural-interface/lib/backup-crypto.js +525 -0
- package/neural-interface/lib/backup-download.js +268 -0
- package/neural-interface/lib/backup-encryption.js +318 -0
- package/neural-interface/lib/backup-groups.js +287 -0
- package/neural-interface/lib/backup-restore-session.js +176 -0
- package/neural-interface/lib/backup-restore-stage.js +60 -0
- package/neural-interface/lib/backup-service.js +836 -322
- package/neural-interface/lib/backup-zip-reader.js +30 -18
- package/neural-interface/lib/backup-zip-writer.js +34 -10
- package/neural-interface/lib/browser-extension-adapter.js +109 -24
- package/neural-interface/lib/browser-extension-bridge.js +42 -8
- package/neural-interface/lib/claude-agent-bridge.js +1 -0
- package/neural-interface/lib/claude-session-cleanup.js +5 -1
- package/neural-interface/lib/cli-update-planner.js +105 -6
- package/neural-interface/lib/client-diagnostics.js +42 -0
- package/neural-interface/lib/confined-fs.js +7 -2
- package/neural-interface/lib/coordination/README.md +8 -2
- package/neural-interface/lib/coordination/contract.js +161 -0
- package/neural-interface/lib/coordination/database.js +999 -0
- package/neural-interface/lib/coordination/operations.js +436 -0
- package/neural-interface/lib/coordination/service.js +68 -537
- package/neural-interface/lib/coordination/storage-worker.js +101 -0
- package/neural-interface/lib/coordination/store.js +219 -1111
- package/neural-interface/lib/db.js +70 -32
- package/neural-interface/lib/health-count.js +37 -0
- package/neural-interface/lib/loop-stall.js +139 -0
- package/neural-interface/lib/maritaca/client.js +2 -2
- package/neural-interface/lib/maritaca/models.js +12 -17
- package/neural-interface/lib/maritaca/opencode.js +4 -2
- package/neural-interface/lib/memory-api.js +9 -1
- package/neural-interface/lib/memory-session-capture.js +42 -10
- package/neural-interface/lib/memory-store-gate.js +313 -0
- package/neural-interface/lib/memory-store-migrate.js +65 -0
- package/neural-interface/lib/memory-timers.js +7 -7
- package/neural-interface/lib/native-loop-providers.js +13 -16
- package/neural-interface/lib/native-loop-runtime.js +34 -14
- package/neural-interface/lib/opencode-build-preflight.js +30 -8
- package/neural-interface/lib/opencode-native-boundary.js +69 -8
- package/neural-interface/lib/opencode-provider-view.js +14 -3
- package/neural-interface/lib/opencode-v2-ws-requests.js +31 -1
- package/neural-interface/lib/opencode2-client.js +2 -1
- package/neural-interface/lib/peer-identity.js +13 -8
- package/neural-interface/lib/recall-impact.js +122 -0
- package/neural-interface/lib/scratch-evidence.js +420 -0
- package/neural-interface/lib/scratch-process-guard.js +139 -0
- package/neural-interface/lib/scratch-references.js +279 -0
- package/neural-interface/lib/scratch-retention-core.js +385 -0
- package/neural-interface/lib/scratch-retention-worker.js +37 -0
- package/neural-interface/lib/scratch-retention.js +151 -0
- package/neural-interface/lib/session-cache-builder.js +70 -44
- package/neural-interface/lib/session-cache-worker.js +157 -0
- package/neural-interface/lib/session-indexer.js +28 -21
- package/neural-interface/lib/session-search-index.js +85 -0
- package/neural-interface/lib/skills/creation.js +1 -1
- package/neural-interface/lib/sqlite-integrity-worker.js +3 -1
- package/neural-interface/lib/style-guide/store.js +43 -3
- package/neural-interface/lib/system-restore.js +50 -0
- package/neural-interface/lib/teams/api.js +15 -6
- package/neural-interface/lib/teams/claims.js +67 -31
- package/neural-interface/lib/teams/index.js +7 -7
- package/neural-interface/lib/teams/integration.js +40 -40
- package/neural-interface/lib/teams/landing.js +6 -6
- package/neural-interface/lib/teams/recovery.js +24 -23
- package/neural-interface/lib/teams/scheduler.js +196 -97
- package/neural-interface/lib/teams/schema.js +1 -1
- package/neural-interface/lib/teams/state.js +14 -14
- package/neural-interface/lib/teams/worktrees.js +27 -27
- package/neural-interface/lib/whatsapp/bridge.js +2 -1
- package/neural-interface/lib/worker-confinement.js +47 -2
- package/neural-interface/lib/worker-mcp-channel.js +2 -0
- package/neural-interface/lib/worker-resume.js +5 -0
- package/neural-interface/lib/worker-stop.js +86 -0
- package/neural-interface/package-lock.json +2 -2
- package/neural-interface/package.json +1 -1
- package/neural-interface/public/index.html +260 -0
- package/neural-interface/public/offline.html +4 -3
- package/neural-interface/public/onboarding.html +259 -34
- package/neural-interface/public/shared/agents/studio/ax-agent-view.js +2 -2
- package/neural-interface/public/shared/agents/studio/ax-editor-view.js +1 -1
- package/neural-interface/public/shared/agents/studio/ax-library.js +0 -6
- package/neural-interface/public/shared/agents/studio/ax-main.js +14 -7
- package/neural-interface/public/shared/agents/studio/ax-ui.js +2 -2
- package/neural-interface/public/shared/agy/agy-options.js +11 -0
- package/neural-interface/public/shared/agy/agy-panel.js +29 -10
- package/neural-interface/public/shared/agy/agy-styles.js +14 -12
- package/neural-interface/public/shared/agy/agy-tabs-logic.js +4 -1
- package/neural-interface/public/shared/api.js +3 -2
- package/neural-interface/public/shared/assistant/asst-api.js +3 -3
- package/neural-interface/public/shared/assistant/asst-brain-picker.js +13 -6
- package/neural-interface/public/shared/assistant/asst-control.js +2 -0
- package/neural-interface/public/shared/assistant/asst-motion-gate.js +78 -4
- package/neural-interface/public/shared/assistant/asst-panel.js +18 -2
- package/neural-interface/public/shared/assistant/asst-rack-styles.js +4 -0
- package/neural-interface/public/shared/assistant/asst-render.js +106 -38
- package/neural-interface/public/shared/assistant/asst-route.js +102 -21
- package/neural-interface/public/shared/assistant/asst-routes-editor.js +1 -1
- package/neural-interface/public/shared/assistant/asst-sidepanel.js +4 -2
- package/neural-interface/public/shared/assistant/asst-state.js +11 -0
- package/neural-interface/public/shared/assistant/asst-styles.js +10 -23
- package/neural-interface/public/shared/assistant/route-identity.js +2 -1
- package/neural-interface/public/shared/cc-dropdown.js +21 -15
- package/neural-interface/public/shared/cdx/cdx-render.js +9 -0
- package/neural-interface/public/shared/cdx/cdx-settings.js +3 -1
- package/neural-interface/public/shared/cdx/cdx-styles.js +6 -0
- package/neural-interface/public/shared/cdx/cdx-tabs.js +29 -9
- package/neural-interface/public/shared/client-diagnostics.js +94 -0
- package/neural-interface/public/shared/cp/cp-markdown.js +7 -2
- package/neural-interface/public/shared/cp/cp-styles.js +1 -1
- package/neural-interface/public/shared/effort-i18n.js +118 -0
- package/neural-interface/public/shared/html-shell.js +4 -51
- package/neural-interface/public/shared/loading-diagnostic-entry.js +64 -0
- package/neural-interface/public/shared/memory-store-wait.js +52 -0
- package/neural-interface/public/shared/morelogin-profile-field.js +1 -1
- package/neural-interface/public/shared/mtc/mtc-logic.js +2 -1
- package/neural-interface/public/shared/mtc/mtc-panel.js +8 -1
- package/neural-interface/public/shared/mtc/mtc-styles.js +13 -12
- package/neural-interface/public/shared/ocp-v2/ocp-v2-childpanel.js +7 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-location-logic.js +109 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-modelpicker.js +8 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +118 -6
- package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +27 -3
- package/neural-interface/public/shared/ocp-v2/ocp-v2-send.js +13 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-session-actions.js +2 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-styles.js +27 -93
- package/neural-interface/public/shared/ocp-v2/ocp-v2-variantpicker.js +17 -6
- package/neural-interface/public/shared/output-format.js +294 -0
- package/neural-interface/public/shared/owner-authority-view.js +4 -10
- package/neural-interface/public/shared/page-session.js +1 -1
- package/neural-interface/public/shared/provider-icons.js +6 -0
- package/neural-interface/public/shared/schedules-view.js +2 -1
- package/neural-interface/public/shared/server-presence.js +77 -0
- package/neural-interface/public/shared/settings/settings-ai-browser.js +5 -5
- package/neural-interface/public/shared/settings/settings-backup-contents.js +241 -0
- package/neural-interface/public/shared/settings/settings-backup-download.js +298 -0
- package/neural-interface/public/shared/settings/settings-backup-encryption-pane.js +335 -0
- package/neural-interface/public/shared/settings/settings-backup-encryption.js +545 -0
- package/neural-interface/public/shared/settings/settings-ia.js +1 -1
- package/neural-interface/public/shared/skills/studio/sx-geometry.js +12 -3
- package/neural-interface/public/shared/skills/studio/sx-main.js +14 -7
- package/neural-interface/public/shared/start-bridge.js +2 -2
- package/neural-interface/public/shared/studio-attention.js +6 -0
- package/neural-interface/public/shared/styles.css +354 -438
- package/neural-interface/public/shared/transcript-rows.js +28 -3
- package/neural-interface/public/shared/tray-auto-close.js +18 -5
- package/neural-interface/public/shared/ui-agents.js +1 -2
- package/neural-interface/public/shared/ui-automation-studio.js +168 -108
- package/neural-interface/public/shared/ui-claude-panel.js +42 -65
- package/neural-interface/public/shared/ui-loading.js +185 -25
- package/neural-interface/public/shared/ui-native-loop-router.js +59 -20
- package/neural-interface/public/shared/ui-navbar.js +2 -1
- package/neural-interface/public/shared/ui-output.js +533 -0
- package/neural-interface/public/shared/ui-owner-authority.js +48 -25
- package/neural-interface/public/shared/ui-schedules-studio.js +165 -128
- package/neural-interface/public/shared/ui-scroll-follow.js +97 -6
- package/neural-interface/public/shared/ui-sessions.js +2 -2
- package/neural-interface/public/shared/ui-settings-entry.js +18 -0
- package/neural-interface/public/shared/ui-settings.js +234 -67
- package/neural-interface/public/shared/ui-sidepanel-tray.js +3 -2
- package/neural-interface/public/shared/ui-sync.js +1 -0
- package/neural-interface/public/shared/ui-tooltip.js +16 -0
- package/neural-interface/public/shared/ui-tutorial.js +5 -6
- package/neural-interface/public/shared/ui-worker-end.js +27 -8
- package/neural-interface/public/shared/worker-end.js +9 -4
- package/neural-interface/public/sw.js +4 -3
- package/neural-interface/public/variant/2d/main.js +5 -0
- package/neural-interface/public/variant/3d/app.js +10 -0
- package/neural-interface/public/variant/3d/main.js +17 -4
- package/neural-interface/scripts/scratch-retention.mjs +20 -0
- package/neural-interface/server.js +507 -160
- package/npm-shrinkwrap.json +2 -2
- package/package.json +2 -1
- package/scripts/restore-data-home-from-backup.mjs +175 -8
- package/setup.js +18 -4
|
@@ -32,7 +32,8 @@
|
|
|
32
32
|
// Catalog, config and runtime I/O are injected. The split planner checks git before worktree approval.
|
|
33
33
|
|
|
34
34
|
import { routeTaskIdentity } from '../public/shared/assistant/route-identity.js';
|
|
35
|
-
import {
|
|
35
|
+
import { agentPinOf, agentRefOf, routedAgent } from './agents/resolve.js';
|
|
36
|
+
import { planRouteSplit, splitChanged } from './agents/split.js';
|
|
36
37
|
import { normalizeAgentDensity } from './agents/density.js';
|
|
37
38
|
import { randomBytes } from 'node:crypto';
|
|
38
39
|
import { CATALOG_PROVIDERS, TIERS, defaultIsHidden, defaultModelRow, findModel, hiddenModelId, priceText, providerAllHidden, providerEmpty, rowIsHidden, rowMakes } from './assistant-catalog.js';
|
|
@@ -210,13 +211,16 @@ export function normalizeRouteRequest(body = {}, { brain = {} } = {}) {
|
|
|
210
211
|
const needsVision = !!(body.needs_vision ?? body.needsVision) || VISION_CLASSES.has(taskClass) || visionOnly;
|
|
211
212
|
const needsOutput = meta.requires || null;
|
|
212
213
|
const dispatchOnly = meta.dispatchOnly === true;
|
|
214
|
+
const needsHost = body.needs_host === true || body.needsHost === true;
|
|
215
|
+
if (needsHost && dispatchOnly) throw routeError('ROUTE_INVALID', 'This task class requires a worker and cannot run here.');
|
|
213
216
|
const proposals = [];
|
|
214
217
|
let coercedDirect = false;
|
|
215
218
|
let coercedProvider = null;
|
|
216
219
|
for (const raw of Array.isArray(body.proposals) ? body.proposals.slice(0, 3) : []) {
|
|
217
220
|
if (!raw || typeof raw !== 'object') continue;
|
|
221
|
+
const requested = agentRefOf(raw);
|
|
218
222
|
let kind = raw.kind === 'direct' ? 'direct' : 'dispatch';
|
|
219
|
-
let provider = CATALOG_PROVIDERS.includes(raw.provider) ? raw.provider : null;
|
|
223
|
+
let provider = CATALOG_PROVIDERS.includes(raw.provider) ? raw.provider : requested === 'none' ? brain.provider : null;
|
|
220
224
|
let model = raw.model ? String(raw.model).trim().slice(0, 200) : null;
|
|
221
225
|
if (kind === 'direct') {
|
|
222
226
|
if (provider && provider !== brain.provider) {
|
|
@@ -225,29 +229,38 @@ export function normalizeRouteRequest(body = {}, { brain = {} } = {}) {
|
|
|
225
229
|
} else provider = brain.provider || provider;
|
|
226
230
|
}
|
|
227
231
|
if (!provider) continue;
|
|
232
|
+
if (needsHost && !runsHere({ kind, provider, accountId: raw.accountId || raw.account_id }, brain)) continue;
|
|
228
233
|
if (dispatchOnly && kind === 'direct') {
|
|
229
234
|
kind = 'dispatch';
|
|
230
235
|
model = model || brain.model || null;
|
|
231
236
|
if (!proposals.length) coercedDirect = true;
|
|
232
237
|
}
|
|
233
238
|
proposals.push({
|
|
234
|
-
kind, provider, model,
|
|
239
|
+
kind, provider, model: model || (needsHost ? brain.model || null : null),
|
|
240
|
+
...(requested ? { agentRequest: requested } : {}),
|
|
235
241
|
effort: raw.effort ? String(raw.effort).trim().slice(0, 40) : null,
|
|
236
242
|
...(raw.accountId || raw.account_id ? { accountId: String(raw.accountId || raw.account_id).slice(0, 64) } : {}),
|
|
237
243
|
reason: raw.reason ? clip(raw.reason, 240) : null,
|
|
238
244
|
});
|
|
239
245
|
}
|
|
240
246
|
if (!proposals.length) {
|
|
241
|
-
const kind = meta.defaultKind;
|
|
247
|
+
const kind = needsHost ? 'direct' : meta.defaultKind;
|
|
242
248
|
proposals.push({ kind, provider: brain.provider || 'claude-code', model: kind === 'direct' ? (brain.model || null) : null, effort: null, reason: null });
|
|
243
249
|
}
|
|
244
250
|
const request = { taskClass, taskClassLabel: meta.label, summary: clip(body.summary || '', 400), confidence, needsVision, proposals };
|
|
245
251
|
if (needsOutput || dispatchOnly) Object.assign(request, { needsOutput, dispatchOnly, coercedDirect });
|
|
252
|
+
if (needsHost) request.needsHost = true;
|
|
246
253
|
if (visionOnly) request.visionOnly = true;
|
|
247
|
-
if (coercedProvider) request.coercedProvider = coercedProvider;
|
|
254
|
+
if (!needsHost && coercedProvider) request.coercedProvider = coercedProvider;
|
|
248
255
|
return request;
|
|
249
256
|
}
|
|
250
257
|
|
|
258
|
+
/** A direct continuation shares the running conversation's provider and account. */
|
|
259
|
+
function runsHere(target, brain) {
|
|
260
|
+
return target?.kind === 'direct' && target.provider === brain.provider
|
|
261
|
+
&& (!target.accountId || target.accountId === (brain.accountId || 'default'));
|
|
262
|
+
}
|
|
263
|
+
|
|
251
264
|
/** Why a "here" on `provider` runs on a worker: only the brain's own provider runs in this conversation. */
|
|
252
265
|
function otherProviderCorrection(provider, brain = {}) {
|
|
253
266
|
return {
|
|
@@ -300,11 +313,11 @@ export function effortChecked(target, catalog, corrections = null) {
|
|
|
300
313
|
* A saved route as a target. `dispatchOnly` (image / video creation): a saved
|
|
301
314
|
* "here" becomes a dispatch onto the same model (the brain's, when it named none).
|
|
302
315
|
*/
|
|
303
|
-
function preferenceTarget(pref, brain, catalog = null, { dispatchOnly = false } = {}) {
|
|
316
|
+
function preferenceTarget(pref, brain, catalog = null, { dispatchOnly = false, needsHost = false } = {}) {
|
|
304
317
|
if (!pref?.provider) return null;
|
|
305
318
|
const here = pref.kind === 'direct' && pref.provider === brain.provider;
|
|
306
319
|
const kind = here && !dispatchOnly ? 'direct' : 'dispatch';
|
|
307
|
-
const model = pref.model || (here && dispatchOnly ? brain.model || null : null);
|
|
320
|
+
const model = pref.model || (here && (dispatchOnly || needsHost) ? brain.model || null : null);
|
|
308
321
|
const target = { kind, provider: pref.provider, model, effort: pref.effort || null };
|
|
309
322
|
if (hasRouteAccounts(pref.provider) && pref.accountId) target.accountId = pref.accountId;
|
|
310
323
|
// A remembered route onto a model the user since disabled is not applied.
|
|
@@ -420,6 +433,14 @@ function budgetReroute({ target, request, catalog, brain, routing, coverage, cap
|
|
|
420
433
|
const t = pick({ kind: p.kind === 'direct' && p.provider === brain.provider && !request.dispatchOnly ? 'direct' : 'dispatch', provider: p.provider, model: p.model || null, effort: p.effort || null, ...(p.accountId ? { accountId: p.accountId } : {}) });
|
|
421
434
|
if (t) return { target: t, moved: true, step: 'proposal' };
|
|
422
435
|
}
|
|
436
|
+
if (request.needsHost) {
|
|
437
|
+
if (isUnpricedProvider(brain.provider)) return { declined: true, unpriced: brain.provider };
|
|
438
|
+
for (const [candidate] of hereCandidates({ request, catalog, brain })) {
|
|
439
|
+
const t = pick(candidate);
|
|
440
|
+
if (t) return { target: t, moved: true, step: 'here' };
|
|
441
|
+
}
|
|
442
|
+
return { declined: true, dry: [brain.provider] };
|
|
443
|
+
}
|
|
423
444
|
// 2. The same tier on another provider.
|
|
424
445
|
const tierOf = (t) => (t?.model ? findModel(catalog, t.provider, t.model)?.row?.tier : defaultModelRow(catalog, t?.provider)?.tier) || null;
|
|
425
446
|
const tier = tierOf(target);
|
|
@@ -478,12 +499,12 @@ export function capableFor(request, { catalog = null, brain = {}, brainInfo = nu
|
|
|
478
499
|
}
|
|
479
500
|
/**
|
|
480
501
|
* An approved route whose provider ran out of share after approval: move the dispatch the same way
|
|
481
|
-
* agent_route would (budgetReroute).
|
|
502
|
+
* agent_route would (budgetReroute). A decline names the dry providers or the unpriced host provider.
|
|
482
503
|
*/
|
|
483
504
|
export function budgetMove({ target, request, catalog = null, brain = {}, brainInfo = null, routing = {}, coverage = null }) {
|
|
484
505
|
if (!coverage || budgetCovers(coverage, catalog, target)) return { target, correction: null };
|
|
485
506
|
const moved = budgetReroute({ target, request, catalog, brain, routing, coverage, capable: capableFor(request, { catalog, brain, brainInfo }) });
|
|
486
|
-
if (moved.declined) return
|
|
507
|
+
if (moved.declined) return moved;
|
|
487
508
|
const next = effortChecked(request.dispatchOnly && moved.target.kind !== 'dispatch' ? { ...moved.target, kind: 'dispatch' } : moved.target, catalog);
|
|
488
509
|
return {
|
|
489
510
|
target: next,
|
|
@@ -502,8 +523,8 @@ export function budgetMove({ target, request, catalog = null, brain = {}, brainI
|
|
|
502
523
|
* `budget` ({ coverage }: assistant-budget-split.js coverageOf, null under No limit): a target whose
|
|
503
524
|
* provider has no share left moves to the next capable provider with money (budgetReroute) and the
|
|
504
525
|
* corrections say so (reason budget_share); with a budget the saved routes yield to this. When nothing
|
|
505
|
-
* can pay: { ask: false, unavailable: 'budget_exhausted', dry }.
|
|
506
|
-
*
|
|
526
|
+
* can pay: { ask: false, unavailable: 'budget_exhausted', dry }. An unpriced host returns
|
|
527
|
+
* 'budget_unpriced'. Otherwise `budgetFrom` names the target whose share can be re-split.
|
|
507
528
|
*/
|
|
508
529
|
export function evaluateRoute({ mode, routing = {}, request, brain = {}, brainInfo = null, catalog = null, budget = null }) {
|
|
509
530
|
const reasons = [];
|
|
@@ -542,7 +563,7 @@ export function evaluateRoute({ mode, routing = {}, request, brain = {}, brainIn
|
|
|
542
563
|
const applyBudget = (target) => {
|
|
543
564
|
if (!coverage || !target) return { target };
|
|
544
565
|
const moved = budgetReroute({ target, request, catalog, brain, routing, coverage, capable });
|
|
545
|
-
if (moved.declined) return {
|
|
566
|
+
if (moved.declined) return { ...moved, from: target };
|
|
546
567
|
if (!moved.moved) return { target };
|
|
547
568
|
const next = effortChecked(dispatchOnly && moved.target.kind !== 'dispatch' ? { ...moved.target, kind: 'dispatch' } : moved.target, catalog, corrections);
|
|
548
569
|
corrections.push({
|
|
@@ -551,15 +572,19 @@ export function evaluateRoute({ mode, routing = {}, request, brain = {}, brainIn
|
|
|
551
572
|
});
|
|
552
573
|
return { target: next, from: target };
|
|
553
574
|
};
|
|
554
|
-
const budgetDeclined = (outcome
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
575
|
+
const budgetDeclined = (outcome) => {
|
|
576
|
+
const unavailable = outcome.unpriced ? 'budget_unpriced' : 'budget_exhausted';
|
|
577
|
+
return {
|
|
578
|
+
ask: false, unavailable, reasons: [unavailable], auto: null, proposal, corrections, source, bound: false,
|
|
579
|
+
dry: outcome.dry || [], budgetFrom: outcome.unpriced ? null : outcome.from,
|
|
580
|
+
};
|
|
581
|
+
};
|
|
582
|
+
const remembered = preferenceTarget(routing.preferences?.[request.taskClass], brain, null, request);
|
|
559
583
|
const disabled = !!remembered && isDisabled(catalog, remembered);
|
|
560
584
|
// A saved route onto a model that cannot make the medium (or, for design, is not known to see) is not applied either.
|
|
561
585
|
const incapable = !!remembered && !disabled && (!targetMakes(catalog, remembered, medium) || (visionOnly && tooBlind(remembered)));
|
|
562
|
-
const
|
|
586
|
+
const fitsHost = !request.needsHost || runsHere(remembered, brain);
|
|
587
|
+
const pref = remembered && !disabled && !incapable && fitsHost ? remembered : null;
|
|
563
588
|
// In either asking mode, a proposal of the saved target carries its saved account too.
|
|
564
589
|
if (pref && sameTarget({ ...proposal, accountId: null, effort: null }, { ...pref, accountId: null, effort: null }) && (!pref.effort || pref.effort === proposal.effort) && (pref.accountId || proposal.accountId)) proposal.accountId = pref.accountId || null;
|
|
565
590
|
// Omitted model: a remembered preference for the class fills it.
|
|
@@ -624,11 +649,16 @@ export function evaluateRoute({ mode, routing = {}, request, brain = {}, brainIn
|
|
|
624
649
|
field: 'route', from: routeText(remembered), to: null, reason: 'remembered_incapable',
|
|
625
650
|
text: `saved ${label} route ${routeText(remembered)} ${cannot}; not applied`,
|
|
626
651
|
});
|
|
652
|
+
} else if (remembered && !fitsHost) {
|
|
653
|
+
corrections.push({
|
|
654
|
+
field: 'route', from: routeText(remembered), to: null, reason: 'remembered_host',
|
|
655
|
+
text: `The saved ${label} route ${routeText(remembered)} needs a worker. This task requires host access.`,
|
|
656
|
+
});
|
|
627
657
|
}
|
|
628
658
|
const invalid = reasons.find((r) => r === 'model_unknown' || r === 'model_disabled');
|
|
629
659
|
if (invalid && auto.model) {
|
|
630
660
|
corrections.push({ field: 'model', from: auto.model, to: null, reason: invalid });
|
|
631
|
-
auto = { ...auto, model: null };
|
|
661
|
+
auto = { ...auto, model: request.needsHost ? brain.model || null : null };
|
|
632
662
|
}
|
|
633
663
|
// No model and the provider default is hidden: name the visible stand-in.
|
|
634
664
|
const pinned = pinnedDefault(catalog, auto);
|
|
@@ -672,11 +702,14 @@ export function evaluateRoute({ mode, routing = {}, request, brain = {}, brainIn
|
|
|
672
702
|
}
|
|
673
703
|
}
|
|
674
704
|
}
|
|
705
|
+
if (request.needsHost && (auto.kind !== 'direct' || isDisabled(catalog, auto) || (request.needsVision && tooBlind(auto)))) {
|
|
706
|
+
return { ask: true, reasons, auto: null, proposal, corrections, source };
|
|
707
|
+
}
|
|
675
708
|
if (dispatchOnly && auto.kind !== 'dispatch') auto = { ...auto, kind: 'dispatch' };
|
|
676
709
|
// A corrected model or provider re-checks the effort.
|
|
677
710
|
auto = effortChecked(auto, catalog, corrections);
|
|
678
711
|
// The provider rule only names what always happened (a "here" elsewhere is a worker): it corrects nothing.
|
|
679
|
-
if (!bound && corrections.some((c) =>
|
|
712
|
+
if (!bound && corrections.some((c) => !['remembered_disabled', 'remembered_incapable', 'remembered_host', 'other_provider'].includes(c.reason))) source = 'corrected';
|
|
680
713
|
// With a budget the saved route yields: a provider with no share left moves the task on.
|
|
681
714
|
const budgeted = applyBudget(auto);
|
|
682
715
|
if (budgeted.declined) return budgetDeclined(budgeted);
|
|
@@ -781,7 +814,10 @@ export function buildRouteOptions({ request, evaluation, brain = {}, brainInfo =
|
|
|
781
814
|
const visionOnly = request.visionOnly === true;
|
|
782
815
|
const ctx = { catalog, brain, brainInfo, needsVision: request.needsVision, needsOutput: medium, visionOnly, coverage };
|
|
783
816
|
const options = [];
|
|
784
|
-
const push = (option) => {
|
|
817
|
+
const push = (option) => {
|
|
818
|
+
if (request.needsHost && !runsHere(option, brain)) return;
|
|
819
|
+
if (!options.some((o) => sameTarget(o, option))) options.push(option);
|
|
820
|
+
};
|
|
785
821
|
const hereTarget = { kind: 'direct', provider: brain.provider, model: brain.model || null, effort: brain.effort || null };
|
|
786
822
|
// A direct pick on the brain's own model with no effort is "here" as the brain runs now: one row, not two.
|
|
787
823
|
const onBrainModel = (t) => t.kind === 'direct' && t.provider === brain.provider && String(t.model || '') === String(brain.model || '');
|
|
@@ -794,7 +830,7 @@ export function buildRouteOptions({ request, evaluation, brain = {}, brainInfo =
|
|
|
794
830
|
// The session budget moved the suggestion: the brain's own pick stays on the card, disabled with why.
|
|
795
831
|
if (evaluation.budgetFrom && coverage) push(optionFor('b0', evaluation.budgetFrom, 'suggested', { ...ctx, reason: request.proposals[0]?.reason || null }));
|
|
796
832
|
if (!dispatchOnly) push(optionFor('here', hereTarget, 'current', ctx));
|
|
797
|
-
const pref = preferenceTarget(routing.preferences?.[request.taskClass], brain, catalog,
|
|
833
|
+
const pref = preferenceTarget(routing.preferences?.[request.taskClass], brain, catalog, request);
|
|
798
834
|
// Always ask: the saved route is offered and its side starts on it (never binding: the card still asks).
|
|
799
835
|
if (pref) {
|
|
800
836
|
const saved = optionFor('r1', pref, 'remembered', ctx);
|
|
@@ -840,7 +876,7 @@ export function buildRouteOptions({ request, evaluation, brain = {}, brainInfo =
|
|
|
840
876
|
if (first && !options.some((o) => o.kind === kind)) push(first);
|
|
841
877
|
};
|
|
842
878
|
if (request.taskClass !== 'chat' && !dispatchOnly && !runnable('direct')) offer('direct', 'h1', hereCandidates({ request, catalog, brain }));
|
|
843
|
-
if (request.taskClass !== 'chat' && !runnable('dispatch')) offer('dispatch', 'w1', workerCandidates({ request, catalog, brain, brainInfo }));
|
|
879
|
+
if (!request.needsHost && request.taskClass !== 'chat' && !runnable('dispatch')) offer('dispatch', 'w1', workerCandidates({ request, catalog, brain, brainInfo }));
|
|
844
880
|
// Order: suggested first, then here, remembered, a capable stand-in, cheaper, stronger.
|
|
845
881
|
const order = { suggested: 0, current: 1, remembered: 2, capable: 3, cheaper: 4, stronger: 5 };
|
|
846
882
|
options.sort((a, b) => (order[a.badge] ?? 9) - (order[b.badge] ?? 9) || String(a.id).localeCompare(String(b.id)));
|
|
@@ -906,6 +942,7 @@ export function routeSides({ options = [], request = {}, defaultOptionId = null
|
|
|
906
942
|
|| (chosen?.kind === kind && usable(chosen) ? chosen : null) || options.find((o) => o.kind === kind && usable(o)) || null;
|
|
907
943
|
const label = request.taskClassLabel || TASK_CLASS_META[request.taskClass]?.label || 'This task';
|
|
908
944
|
const side = (kind) => {
|
|
945
|
+
if (kind === 'dispatch' && request.needsHost) return { available: false, code: 'host_only', reason: 'This task requires host access in this conversation.' };
|
|
909
946
|
if (firstOf(kind)) return { available: true, reason: null, code: null };
|
|
910
947
|
if (kind === 'direct' && request.dispatchOnly) return { available: false, code: 'worker_only', reason: request.plannedSplit ? 'This task uses the approved worker plan.' : `${label} always runs on a worker.` };
|
|
911
948
|
if (kind === 'direct' && options.some((o) => o.kind === 'dispatch' && o.accountKind === 'direct')) {
|
|
@@ -923,6 +960,10 @@ export function routeSides({ options = [], request = {}, defaultOptionId = null
|
|
|
923
960
|
};
|
|
924
961
|
}
|
|
925
962
|
|
|
963
|
+
function hostRouteError() {
|
|
964
|
+
return routeError('ROUTE_IS_DIRECT', 'This task requires host access. Run it here in the Assistant conversation.', 409);
|
|
965
|
+
}
|
|
966
|
+
|
|
926
967
|
/** Validate a route-card answer; returns { declined } or { target, optionId, remember }. */
|
|
927
968
|
export function targetFromAnswer({ card, response = {}, catalog = null, brain = {} }) {
|
|
928
969
|
if (response.decline === true || response.behavior === 'deny' || response.cancel === true) return { declined: true };
|
|
@@ -936,6 +977,7 @@ export function targetFromAnswer({ card, response = {}, catalog = null, brain =
|
|
|
936
977
|
// A card can remain open while the catalog or hidden-model list changes.
|
|
937
978
|
// Check the chosen target again instead of trusting the option's old state.
|
|
938
979
|
const ensureAvailable = (target) => {
|
|
980
|
+
if (card.needsHost && !runsHere(target, brain)) throw hostRouteError();
|
|
939
981
|
const own = onBrain(target);
|
|
940
982
|
if (target.model && (own ? isDisabled(catalog, target) : findModel(catalog, target.provider, target.model) === null)) {
|
|
941
983
|
if (isDisabled(catalog, target)) throw routeError('MODEL_DISABLED', `${target.model} is disabled in the Assistant's Models list. Pick an enabled model.`);
|
|
@@ -977,7 +1019,8 @@ export function targetFromAnswer({ card, response = {}, catalog = null, brain =
|
|
|
977
1019
|
? { field: 'kind', from: 'direct', to: 'dispatch', reason: 'dispatch_only', text: `${TASK_CLASS_META[card.taskClass]?.label || 'This task'} always runs on a worker, not here` }
|
|
978
1020
|
: otherProviderCorrection(t.provider, brain));
|
|
979
1021
|
}
|
|
980
|
-
const
|
|
1022
|
+
const model = t.model ? String(t.model) : card.needsHost && kind === 'direct' ? brain.model || null : null;
|
|
1023
|
+
const target = effortChecked({ kind, provider: t.provider, model, effort: t.effort ? String(t.effort).trim().slice(0, 40) : null, accountId: t.accountId ? String(t.accountId).trim() : null }, catalog, corrections);
|
|
981
1024
|
ensureAvailable(target);
|
|
982
1025
|
return { target, optionId: 'other', remember, corrections };
|
|
983
1026
|
}
|
|
@@ -1058,7 +1101,7 @@ export function escalationFor({ run, catalog = null, routing = {}, depth = 0 })
|
|
|
1058
1101
|
* @param {object} deps.sinks { sendCard(sessionId, packet), cancelCard(sessionId, requestId, reason),
|
|
1059
1102
|
* routeEvent(sessionId, phase, route), mailbox(sessionId, item),
|
|
1060
1103
|
* continueDirect(sessionId, {target, route, text}) → false when the pick's turn is gone,
|
|
1061
|
-
* startHeld(runId, target, meta),
|
|
1104
|
+
* activeRouteRuns(sessionId, routeId) → [{ runId, title, state }], startHeld(runId, target, meta),
|
|
1062
1105
|
* checkHeld(runId, target) → why the held run could not start on target ({ code, message, status }) or null,
|
|
1063
1106
|
* declineHeld(runId, reason), routed(sessionId, result), routeFailed(sessionId, error) }
|
|
1064
1107
|
* @param {object} [deps.clarifier] assistant-clarify.js — { blocking(sessionId, { independent }) }: while the
|
|
@@ -1070,6 +1113,7 @@ export function escalationFor({ run, catalog = null, routing = {}, depth = 0 })
|
|
|
1070
1113
|
export function createAssistantRouter({
|
|
1071
1114
|
catalog,
|
|
1072
1115
|
configStore = null,
|
|
1116
|
+
agents = null,
|
|
1073
1117
|
getSession = () => null,
|
|
1074
1118
|
sinks = {},
|
|
1075
1119
|
now = Date.now,
|
|
@@ -1092,6 +1136,32 @@ export function createAssistantRouter({
|
|
|
1092
1136
|
const lastClosed = new Map(); // routeId → { routeId, settled } of recently closed cards
|
|
1093
1137
|
const call = (name, ...args) => { try { return sinks[name]?.(...args); } catch (error) { log('router:sink-error', `${name}: ${error?.message || error}`); return undefined; } };
|
|
1094
1138
|
|
|
1139
|
+
// Resolve each distinct proposed role once. A different model (saved preference, budget or
|
|
1140
|
+
// custom card choice) can still run the proposed role. Direct choices never use a worker.
|
|
1141
|
+
function workerRoles(request, cwd, pin = null) {
|
|
1142
|
+
const roles = new Map();
|
|
1143
|
+
return request.proposals.map(proposal => {
|
|
1144
|
+
const ref = proposal.agentRequest;
|
|
1145
|
+
if (pin) return { agentRef: pin.ref, agentRevision: pin.revision, agentRequest: pin.ref };
|
|
1146
|
+
if (!roles.has(ref)) {
|
|
1147
|
+
const role = agents ? routedAgent(agents, request.taskClass, cwd, ref) : {};
|
|
1148
|
+
roles.set(ref, role.meta || (role.note ? { agentCorrection: role.note } : {}));
|
|
1149
|
+
}
|
|
1150
|
+
return roles.get(ref);
|
|
1151
|
+
});
|
|
1152
|
+
}
|
|
1153
|
+
function workerRole(request, target, optionId) {
|
|
1154
|
+
if (target?.kind !== 'dispatch' || !request.roles) return {};
|
|
1155
|
+
const suggestion = /^s([1-3])$/.exec(optionId || '');
|
|
1156
|
+
const index = suggestion ? Number(suggestion[1]) - 1 : 0;
|
|
1157
|
+
return request.roles[index] || request.roles[0] || {};
|
|
1158
|
+
}
|
|
1159
|
+
function agentFields(record) {
|
|
1160
|
+
if (!record) return {};
|
|
1161
|
+
const { agentRef, agentRevision, agentRequest, agentCorrection } = record;
|
|
1162
|
+
return { ...(agentRef ? { agentRef, agentRevision } : {}), ...(agentRequest ? { agentRequest } : {}),
|
|
1163
|
+
...(agentCorrection ? { agentCorrection } : {}) };
|
|
1164
|
+
}
|
|
1095
1165
|
function routing() { try { return configStore?.routing?.() || effectiveRouting({}); } catch { return effectiveRouting({}); } }
|
|
1096
1166
|
function modeFor(sessionId) {
|
|
1097
1167
|
const session = getSession(sessionId);
|
|
@@ -1152,17 +1222,20 @@ export function createAssistantRouter({
|
|
|
1152
1222
|
function budgetDeclinedResult({ sessionId, request, mode, cat, brain, brainInfo, evaluation }) {
|
|
1153
1223
|
const routeId = `route-${randomId()}`;
|
|
1154
1224
|
const dry = evaluation.dry || [];
|
|
1225
|
+
const unpriced = evaluation.unavailable === 'budget_unpriced' ? unpricedText(brain.provider) : null;
|
|
1226
|
+
const reasonCode = unpriced ? 'BUDGET_UNPRICED' : 'budget_exhausted';
|
|
1155
1227
|
const route = {
|
|
1156
1228
|
routeId, status: 'declined', sessionId, taskClass: request.taskClass, summary: request.summary, confidence: request.confidence,
|
|
1157
|
-
target: null, decidedBy: 'budget', remembered: false, corrections: evaluation.corrections || [], mode, runIds: [], reasonCode
|
|
1158
|
-
|
|
1229
|
+
target: null, decidedBy: 'budget', remembered: false, corrections: evaluation.corrections || [], mode, runIds: [], reasonCode, dry,
|
|
1230
|
+
...(unpriced ? { provider: brain.provider } : {}),
|
|
1231
|
+
reason: unpriced || (dry.length ? `Budget: the ${dry.join(', ')} share${dry.length === 1 ? ' is' : 's are'} used up.` : "Budget: this session's budget is spent."),
|
|
1159
1232
|
};
|
|
1160
1233
|
call('routeEvent', sessionId, 'declined', routeView(route, { catalog: cat, brain, brainInfo }));
|
|
1161
|
-
return {
|
|
1162
|
-
ok: true, status: 'declined', reason:
|
|
1234
|
+
return reportSupersededRuns(request, {
|
|
1235
|
+
ok: true, status: 'declined', reason: evaluation.unavailable, reasonCode, dry, routeId, mode, source: 'budget', target: null,
|
|
1163
1236
|
remembered: false, continuation: false, corrections: evaluation.corrections || [], runIds: [], expiresAt: null,
|
|
1164
|
-
budget: compactBudget(sessionId), next: budgetDeclinedText(sessionId, dry),
|
|
1165
|
-
};
|
|
1237
|
+
budget: compactBudget(sessionId), next: unpriced || budgetDeclinedText(sessionId, dry),
|
|
1238
|
+
});
|
|
1166
1239
|
}
|
|
1167
1240
|
function liveAccounts(cat) { return accountUsage ? accountUsage.list() : listAccounts ? listAccounts() : cat?.accounts || {}; }
|
|
1168
1241
|
function accountTarget(target, brain, cat, { check = true, fallback = null, select = true } = {}) {
|
|
@@ -1219,13 +1292,16 @@ export function createAssistantRouter({
|
|
|
1219
1292
|
function routeView(source, { catalog: cat = null, brain = {}, brainInfo = null } = {}) {
|
|
1220
1293
|
const target = source.target ? describeTarget(source.target, { catalog: cat, brain, brainInfo }) : null;
|
|
1221
1294
|
return {
|
|
1295
|
+
...agentFields(source),
|
|
1222
1296
|
routeId: source.routeId, runIds: [...(source.runIds || [])], taskClass: source.taskClass, taskClassLabel: TASK_CLASS_META[source.taskClass]?.label || source.taskClass,
|
|
1297
|
+
...(source.needsHost ? { needsHost: true } : {}),
|
|
1223
1298
|
plannedSplit: source.plannedSplit || null, sessionId: source.sessionId || null, taskId: source.taskId || null, taskKey: source.taskKey || '',
|
|
1224
1299
|
summary: source.summary || '', confidence: source.confidence ?? null, reason: source.reason || null,
|
|
1225
1300
|
target, alternatives: (source.alternatives || []).slice(0, 4), decidedBy: source.decidedBy || null, remembered: !!source.remembered,
|
|
1226
1301
|
optionId: source.optionId || null, corrections: source.corrections || [], mode: source.mode || null, status: source.status || null,
|
|
1227
1302
|
// Why a route was declined without a card (no_capable_model), else null.
|
|
1228
1303
|
reasonCode: source.reasonCode || null,
|
|
1304
|
+
...(source.reasonCode === 'BUDGET_UNPRICED' ? { provider: source.provider } : {}),
|
|
1229
1305
|
// Design's no_capable_model: no model can see.
|
|
1230
1306
|
...(source.needs ? { needs: source.needs } : {}),
|
|
1231
1307
|
// budget_exhausted: the providers whose share is used up (the panel names them).
|
|
@@ -1421,6 +1497,19 @@ export function createAssistantRouter({
|
|
|
1421
1497
|
return !session || session.closing === true;
|
|
1422
1498
|
}
|
|
1423
1499
|
|
|
1500
|
+
// Read the old route's runs at delivery. A worker may finish while the Here card is open.
|
|
1501
|
+
function reportSupersededRuns(request, result) {
|
|
1502
|
+
if (!request?.needsHost || !request.taskId) return result;
|
|
1503
|
+
const key = routeTaskIdentity(request);
|
|
1504
|
+
const old = [...decided.values()].find(r => r.supersededByHost && r.status === 'approved' && routeTaskIdentity(r) === key);
|
|
1505
|
+
const runs = old && call('activeRouteRuns', request.sessionId, old.routeId);
|
|
1506
|
+
if (!runs?.length) return result;
|
|
1507
|
+
const names = runs.map(r => `${r.runId} ("${r.title}", ${r.state})`).join(', ');
|
|
1508
|
+
const text = `The previous dispatch still has active work (${names}). Use agent_stop with the run ID for any duplicate work.`;
|
|
1509
|
+
const correction = { reason: 'superseded_run_active', routeId: old.routeId, runs, text };
|
|
1510
|
+
return { ...result, corrections: [...(result.corrections || []), correction], next: `${text} ${result.next}` };
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1424
1513
|
function resultFor(status, { routeId, mode, source = null, target = null, card = null, runIds = [], corrections = [], cat = null, brain = {}, brainInfo = null, remembered = false, continuation = false, sessionId = null, switched = null, droppedRuns = [] } = {}) {
|
|
1425
1514
|
const described = target ? { ...describeTarget(target, { catalog: cat, brain, brainInfo }), continuation } : null;
|
|
1426
1515
|
// The user's pick was the other kind than the brain proposed; a "here" pick on another account runs on a worker.
|
|
@@ -1452,14 +1541,15 @@ export function createAssistantRouter({
|
|
|
1452
1541
|
? `Call agent_team action "plan" with task_class="${record.taskClass}" and these ${plannedSplit.workers} slice titles (${["research", "review"].includes(record.taskClass) ? "read-only: owned_paths []" : "disjoint owned_paths"}), then action "start" with route_id="${routeId}". One approval covers every slice; never route a slice. Wait on its workflow_id, then ${["research", "review"].includes(record.taskClass) ? "synthesize the results; worktrees are cleaned up automatically, no integration or landing" : "verify the integration result"}.`
|
|
1453
1542
|
: `Call agent_dispatch with route_id="${routeId}" for one worker. Explain: ${plannedSplit.reason}`
|
|
1454
1543
|
: null;
|
|
1455
|
-
return {
|
|
1544
|
+
return reportSupersededRuns(record, {
|
|
1545
|
+
...agentFields(record),
|
|
1456
1546
|
ok: true, status, routeId, mode, source: source || record?.decidedBy || (status === 'expired' ? 'timeout' : status === 'cancelled' ? 'system' : null), reasonCode: record?.reasonCode || (status === 'expired' ? 'expired' : status === 'cancelled' ? 'cancelled' : null), target: described, remembered, continuation,
|
|
1457
1547
|
taskClass: record?.taskClass || null, sessionId: sessionId || record?.sessionId || null, taskId: record?.taskId || null, taskKey: record?.taskKey || '',
|
|
1458
1548
|
agentDensity: plannedSplit?.density || normalizeAgentDensity(getSession(sessionId || record?.sessionId)?.agentDensity), expectedWorkers: plannedSplit?.workers || 1, plannedSplit, workflowId: record?.workflowId || null,
|
|
1459
|
-
corrections, runIds, expiresAt: card?.expiresAt ? new Date(card.expiresAt).toISOString() : null,
|
|
1549
|
+
corrections: record?.agentCorrection ? [...corrections, record.agentCorrection] : corrections, runIds, expiresAt: card?.expiresAt ? new Date(card.expiresAt).toISOString() : null,
|
|
1460
1550
|
...(shares ? { budget: shares } : {}),
|
|
1461
1551
|
next: `${waitLead}${lead}${status === 'approved' ? kindLead : ''}${splitNext || nextText(record?.reasonCode === 'moved_on' ? 'moved_on' : status, described, { routeId, label: status === 'declined' ? record?.reasonCode : described?.label })}`,
|
|
1462
|
-
};
|
|
1552
|
+
});
|
|
1463
1553
|
}
|
|
1464
1554
|
|
|
1465
1555
|
/** What the brain tells the user when no model makes the medium, or can see for design (agent_route's `next`, the NO_CAPABLE_MODEL refusal). */
|
|
@@ -1515,7 +1605,8 @@ export function createAssistantRouter({
|
|
|
1515
1605
|
for (const option of options) {
|
|
1516
1606
|
const first = request.proposals[0];
|
|
1517
1607
|
const fallback = origin === 'dispatch' && option.badge !== 'remembered' && option.provider === first?.provider ? first.accountId : null;
|
|
1518
|
-
Object.assign(option, accountTarget(option, brain, cat, { check: false, fallback }));
|
|
1608
|
+
Object.assign(option, accountTarget(option, brain, cat, { check: false, fallback, select: !request.needsHost }));
|
|
1609
|
+
Object.assign(option, workerRole(request, option, option.id));
|
|
1519
1610
|
if (option.accountError) { option.disabled = true; option.disabledReason = option.accountError.message; }
|
|
1520
1611
|
// A "here" whose account cannot take it (this conversation's is out of usage) runs on a worker
|
|
1521
1612
|
// on another account: the card names it as a worker and says why, never "Do it here".
|
|
@@ -1528,15 +1619,17 @@ export function createAssistantRouter({
|
|
|
1528
1619
|
// The sides and defaults as the options are sent (the account check can disable or move one).
|
|
1529
1620
|
const { defaultOptionId, sides, defaults } = routeSides({ options, request, defaultOptionId: built.defaultOptionId });
|
|
1530
1621
|
const computer = computerConsent({ session, request, options, defaultOptionId, brain, origin });
|
|
1531
|
-
const expiresAt = now() + r.cardTimeoutMinutes * 60_000;
|
|
1532
1622
|
const pref = r.preferences?.[request.taskClass];
|
|
1533
1623
|
const card = {
|
|
1624
|
+
...agentFields(options.find(o => o.id === (defaults.dispatch || defaultOptionId))),
|
|
1534
1625
|
routeId, requestId, sessionId, origin, status: 'pending', mode, workflowId,
|
|
1535
1626
|
plannedSplit: request.plannedSplit || null, taskId: request.taskId, taskKey: request.taskKey || '',
|
|
1536
1627
|
taskClass: request.taskClass, summary: request.summary, confidence: request.confidence, needsVision: request.needsVision,
|
|
1628
|
+
...(request.needsHost ? { needsHost: true } : {}),
|
|
1537
1629
|
needsOutput: request.needsOutput || null, dispatchOnly: request.dispatchOnly === true, visionOnly: request.visionOnly === true,
|
|
1538
1630
|
reasons: evaluation.reasons, request, options, defaultOptionId, sides, defaults, runIds: new Set(runIds), waiters: new Set(),
|
|
1539
|
-
|
|
1631
|
+
// No deadline: a card stays open until the user answers it, moves on, or its session ends.
|
|
1632
|
+
createdAt: now(), expiresAt: null, mailboxOnDecision: origin === 'dispatch', brain,
|
|
1540
1633
|
// The option whose approval is also the computer approval (computerConsent), as this card was sent.
|
|
1541
1634
|
computer,
|
|
1542
1635
|
alternatives: options.filter((o) => o.badge !== 'suggested').map((o) => ({ id: o.id, kind: o.kind, provider: o.provider, model: o.model, effort: o.effort, label: o.label, badge: o.badge })),
|
|
@@ -1549,6 +1642,7 @@ export function createAssistantRouter({
|
|
|
1549
1642
|
reasons: evaluation.reasons, taskClass: request.taskClass, taskClassLabel: request.taskClassLabel, summary: request.summary,
|
|
1550
1643
|
plannedSplit: request.plannedSplit || null, taskId: request.taskId || null, taskKey: request.taskKey || '',
|
|
1551
1644
|
confidence: request.confidence, needsVision: request.needsVision,
|
|
1645
|
+
...(request.needsHost ? { needsHost: true } : {}),
|
|
1552
1646
|
// Image / video creation: the medium the model must generate, and no "here" (always a worker).
|
|
1553
1647
|
requires: request.needsOutput || null, dispatchOnly: request.dispatchOnly === true,
|
|
1554
1648
|
// Design: only models that can see.
|
|
@@ -1557,16 +1651,14 @@ export function createAssistantRouter({
|
|
|
1557
1651
|
options, defaultOptionId,
|
|
1558
1652
|
// The card's Here / Dispatch switch: which side can run the task (and why not), and the option each side starts on.
|
|
1559
1653
|
sides, defaults,
|
|
1560
|
-
other: { allowed: true, providers: CATALOG_PROVIDERS, catalogPath: '/api/assistant/catalog' },
|
|
1654
|
+
other: { allowed: true, providers: request.needsHost ? [brain.provider] : CATALOG_PROVIDERS, catalogPath: '/api/assistant/catalog' },
|
|
1561
1655
|
remember: { available: request.taskClass !== 'chat', taskClass: request.taskClass, label: request.taskClassLabel, current: pref ? (pref.label || [pref.provider, pref.model].filter(Boolean).join('/')) : null },
|
|
1562
1656
|
decline: { allowed: true, label: 'Cancel' },
|
|
1563
1657
|
// Approving this option also lets the Assistant control the Mac for the task: every host says so in words.
|
|
1564
1658
|
...(computer ? { computer: { optionId: computer.optionId } } : {}),
|
|
1565
|
-
createdAt: new Date(card.createdAt).toISOString(), expiresAt:
|
|
1659
|
+
createdAt: new Date(card.createdAt).toISOString(), expiresAt: null,
|
|
1566
1660
|
},
|
|
1567
1661
|
};
|
|
1568
|
-
card.timer = setTimeout(() => expire(routeId), Math.max(1000, expiresAt - now()));
|
|
1569
|
-
card.timer.unref?.();
|
|
1570
1662
|
cards.set(routeId, card);
|
|
1571
1663
|
byRequest.set(requestId, routeId);
|
|
1572
1664
|
return card;
|
|
@@ -1591,7 +1683,6 @@ export function createAssistantRouter({
|
|
|
1591
1683
|
return routeError('ROUTE_CANCELLED', text, 409, { routeId: card?.routeId || null });
|
|
1592
1684
|
}
|
|
1593
1685
|
function closeCard(card) {
|
|
1594
|
-
if (card.timer) { clearTimeout(card.timer); card.timer = null; }
|
|
1595
1686
|
byRequest.delete(card.requestId);
|
|
1596
1687
|
cards.delete(card.routeId);
|
|
1597
1688
|
// Why it closed, for a producer that attaches a run a moment too late (bounded).
|
|
@@ -1684,9 +1775,28 @@ export function createAssistantRouter({
|
|
|
1684
1775
|
const key = routeTaskIdentity(request);
|
|
1685
1776
|
if (!key) return null;
|
|
1686
1777
|
const card = [...cards.values()].find(c => routeTaskIdentity(c) === key);
|
|
1687
|
-
const prior = card || [...decided.values()].find(c => routeTaskIdentity(c) === key);
|
|
1778
|
+
const prior = card || [...decided.values()].find(c => !c.supersededByHost && !c.supersededBySplit && routeTaskIdentity(c) === key);
|
|
1688
1779
|
if (!prior) return null;
|
|
1689
1780
|
assertCurrentTask(sessionId, request.taskId);
|
|
1781
|
+
if (request.needsHost && prior.status === 'approved' && prior.target?.kind === 'direct') {
|
|
1782
|
+
prior.needsHost = true;
|
|
1783
|
+
}
|
|
1784
|
+
// A newly identified host requirement supersedes an earlier worker-capable choice.
|
|
1785
|
+
if (request.needsHost && !prior.needsHost && ['pending', 'approved'].includes(prior.status)) {
|
|
1786
|
+
if (card) expire(card.routeId, 'superseded');
|
|
1787
|
+
const old = decided.get(prior.routeId);
|
|
1788
|
+
if (old) Object.assign(old, { supersededByHost: true, needsHost: true });
|
|
1789
|
+
return null;
|
|
1790
|
+
}
|
|
1791
|
+
// A changed planned_split before any team or worker used the route: the new plan is routed afresh
|
|
1792
|
+
// (a new card, so Always ask asks again) instead of answering with the stale split.
|
|
1793
|
+
if (splitChanged(request.requestedSplit, prior.plannedSplit) && ['pending', 'approved'].includes(prior.status)
|
|
1794
|
+
&& !prior.workflowId && !(prior.runIds?.size ?? prior.runIds?.length ?? 0)) {
|
|
1795
|
+
if (card) expire(card.routeId, 'superseded');
|
|
1796
|
+
const old = decided.get(prior.routeId);
|
|
1797
|
+
if (old) Object.assign(old, { supersededBySplit: true, status: old.status === 'approved' ? 'expired' : old.status });
|
|
1798
|
+
return null;
|
|
1799
|
+
}
|
|
1690
1800
|
let continuation = false;
|
|
1691
1801
|
// A thinking switch that waited is decided again now (the background work may have reported since).
|
|
1692
1802
|
let corrections = (prior.corrections || []).filter((c) => c?.reason !== 'thinking_waits');
|
|
@@ -1726,11 +1836,13 @@ export function createAssistantRouter({
|
|
|
1726
1836
|
const brainInfo = brainInfoFor(brain);
|
|
1727
1837
|
const request = normalizeRouteRequest(body, { brain });
|
|
1728
1838
|
Object.assign(request, taskIdentity(sessionId, session, body));
|
|
1839
|
+
request.requestedSplit = body.planned_split ?? body.plannedSplit ?? null;
|
|
1729
1840
|
// The same task routed again (a later turn: a task notification, a mailbox event, the user's next words).
|
|
1730
1841
|
const existing = existingTaskResult(request, sessionId, { cat, brain, brainInfo }, { deliver: origin === 'agent_route' });
|
|
1731
1842
|
if (existing) return existing;
|
|
1732
|
-
request.plannedSplit = await planRouteSplit(body, session, request.taskClass);
|
|
1843
|
+
request.plannedSplit = request.needsHost ? null : await planRouteSplit(body, session, request.taskClass);
|
|
1733
1844
|
request.projectPath = request.plannedSplit?.projectPath || null;
|
|
1845
|
+
request.roles = workerRoles(request, body.cwd || body.project);
|
|
1734
1846
|
if (request.plannedSplit) {
|
|
1735
1847
|
request.dispatchOnly = true;
|
|
1736
1848
|
request.proposals = request.proposals.map(p => ({ ...p, kind: 'dispatch' }));
|
|
@@ -1741,24 +1853,27 @@ export function createAssistantRouter({
|
|
|
1741
1853
|
const raced = existingTaskResult(request, sessionId, { cat, brain, brainInfo }, { deliver: origin === 'agent_route' });
|
|
1742
1854
|
if (raced) return raced;
|
|
1743
1855
|
assertCurrentTask(sessionId, request.taskId);
|
|
1744
|
-
if (evaluation.unavailable
|
|
1856
|
+
if (['budget_exhausted', 'budget_unpriced'].includes(evaluation.unavailable)) return budgetDeclinedResult({ sessionId, request, mode, cat, brain, brainInfo, evaluation });
|
|
1745
1857
|
if (evaluation.unavailable) return unavailableResult({ sessionId, request, mode, cat, brain, brainInfo });
|
|
1746
1858
|
if (!evaluation.ask) {
|
|
1747
1859
|
const routeId = `route-${randomId()}`;
|
|
1748
1860
|
let target = evaluation.auto;
|
|
1749
|
-
const checked = accountTarget(target, brain, cat, { check: false, select: request.taskClass !== 'chat' });
|
|
1861
|
+
const checked = accountTarget(target, brain, cat, { check: false, select: !request.needsHost && request.taskClass !== 'chat' });
|
|
1862
|
+
if (request.needsHost && checked.kind !== 'direct') throw hostRouteError();
|
|
1750
1863
|
if (checked.accountError) {
|
|
1751
1864
|
const failed = { routeId, sessionId, taskClass: request.taskClass, summary: request.summary, target: checked, status: 'declined', decidedBy: 'account', reason: checked.accountError.message, reasonCode: checked.accountError.code, mode };
|
|
1752
1865
|
call('routeEvent', sessionId, 'declined', routeView(failed, { catalog: cat, brain, brainInfo }));
|
|
1753
|
-
return { ok: false, status: 'declined', routeId, mode, source: 'account', reasonCode: checked.accountError.code, code: checked.accountError.code, target: describeTarget(checked, { catalog: cat, brain }), next: checked.accountError.message };
|
|
1866
|
+
return reportSupersededRuns(request, { ok: false, status: 'declined', routeId, mode, source: 'account', reasonCode: checked.accountError.code, code: checked.accountError.code, target: describeTarget(checked, { catalog: cat, brain }), next: checked.accountError.message });
|
|
1754
1867
|
}
|
|
1755
1868
|
target = checked;
|
|
1756
1869
|
const decidedBy = evaluation.source === 'remembered' ? 'remembered' : evaluation.source === 'budget' ? 'budget' : 'brain';
|
|
1757
1870
|
// Off to or from a level that waits for Claude Code's background work: in place, and the answer says so.
|
|
1758
1871
|
const waits = origin === 'agent_route' && request.taskClass !== 'chat' ? thinkingWaits(sessionId, target, brain, turnBrain(sessionId, brain)) : null;
|
|
1759
1872
|
const route = {
|
|
1873
|
+
...(request.needsHost ? { needsHost: true } : {}),
|
|
1760
1874
|
taskId: request.taskId, taskKey: request.taskKey || '', plannedSplit: request.plannedSplit || null, workflowId: null,
|
|
1761
1875
|
routeId, status: 'approved', sessionId, taskClass: request.taskClass, summary: request.summary, confidence: request.confidence,
|
|
1876
|
+
...workerRole(request, target),
|
|
1762
1877
|
target, decidedBy, remembered: evaluation.source === 'remembered', corrections: [...accountCorrections(target, evaluation.corrections), ...(waits ? [waits] : [])], mode,
|
|
1763
1878
|
reason: request.proposals[0]?.reason || null, runIds: [], expiresAt: now() + DECIDED_TTL_MS,
|
|
1764
1879
|
};
|
|
@@ -1840,7 +1955,11 @@ export function createAssistantRouter({
|
|
|
1840
1955
|
return result;
|
|
1841
1956
|
}
|
|
1842
1957
|
const { optionId, remember } = parsed;
|
|
1843
|
-
const target =
|
|
1958
|
+
const target = card.needsHost
|
|
1959
|
+
? accountTarget(parsed.target, brain, cat, { select: false })
|
|
1960
|
+
: checkedTarget(parsed.target, brain, cat, null, null, card.mode === 'always-ask');
|
|
1961
|
+
if (card.needsHost && target.kind !== 'direct') throw hostRouteError();
|
|
1962
|
+
const pickedRole = workerRole(card.request, target, optionId);
|
|
1844
1963
|
const corrections = accountCorrections(target, parsed.corrections || []);
|
|
1845
1964
|
// The session budget must be able to pay for the pick: a provider with no share left divides the
|
|
1846
1965
|
// unspent budget again first; still none, and the card stays open with the reason.
|
|
@@ -1861,7 +1980,7 @@ export function createAssistantRouter({
|
|
|
1861
1980
|
// or reported started: the card stays open with the reason. A "here" pick starts none.
|
|
1862
1981
|
if (!keptHere) {
|
|
1863
1982
|
for (const runId of card.runIds) {
|
|
1864
|
-
const refusal = call('checkHeld', runId, target);
|
|
1983
|
+
const refusal = call('checkHeld', runId, target, pickedRole);
|
|
1865
1984
|
if (refusal) throw routeError(refusal.code || 'ROUTE_INVALID', refusal.message || 'The held run cannot start on that model.', Number(refusal.status) || 400);
|
|
1866
1985
|
}
|
|
1867
1986
|
}
|
|
@@ -1900,8 +2019,10 @@ export function createAssistantRouter({
|
|
|
1900
2019
|
const heldRuns = keptHere ? [] : [...card.runIds];
|
|
1901
2020
|
const droppedRuns = keptHere ? [...card.runIds] : [];
|
|
1902
2021
|
const route = {
|
|
2022
|
+
...(card.needsHost ? { needsHost: true } : {}),
|
|
1903
2023
|
taskId: card.taskId, taskKey: card.taskKey || '', plannedSplit: card.plannedSplit || null, workflowId: null,
|
|
1904
2024
|
routeId, status: 'approved', sessionId: card.sessionId, taskClass: card.taskClass, summary: card.summary, confidence: card.confidence,
|
|
2025
|
+
...pickedRole,
|
|
1905
2026
|
target, decidedBy: 'user', remembered, optionId, corrections, mode: card.mode, runIds: heldRuns,
|
|
1906
2027
|
reason: card.options.find((o) => o.id === optionId)?.reason || null, alternatives: card.alternatives, expiresAt: now() + DECIDED_TTL_MS,
|
|
1907
2028
|
};
|
|
@@ -1910,7 +2031,7 @@ export function createAssistantRouter({
|
|
|
1910
2031
|
// A remote session: the held run this card was for is its one dispatch.
|
|
1911
2032
|
if (heldRuns.length && session.remote === true) route.consumed = true;
|
|
1912
2033
|
for (const runId of droppedRuns) call('declineHeld', runId, 'route_here');
|
|
1913
|
-
for (const runId of heldRuns) call('startHeld', runId, target, { routeId, decidedBy: 'user', remembered, optionId });
|
|
2034
|
+
for (const runId of heldRuns) call('startHeld', runId, target, { routeId, decidedBy: 'user', remembered, optionId, agentRequest: route.agentRequest });
|
|
1914
2035
|
const view = routeView(route, { catalog: cat, brain, brainInfo });
|
|
1915
2036
|
call('routeEvent', card.sessionId, 'decided', view);
|
|
1916
2037
|
const inTurnWaiter = card.waiters.size > 0;
|
|
@@ -1967,6 +2088,7 @@ export function createAssistantRouter({
|
|
|
1967
2088
|
const approved = decided.get(routeId);
|
|
1968
2089
|
const bound = approved || cards.get(routeId);
|
|
1969
2090
|
if (bound?.sessionId === sessionId && !team) assertCurrentTask(sessionId, bound.taskId);
|
|
2091
|
+
if (bound?.sessionId === sessionId && bound.needsHost) throw hostRouteError();
|
|
1970
2092
|
if (bound?.taskId && ['expired', 'cancelled'].includes(bound.status)) throw routeClosedError(lastClosed.get(routeId) || bound);
|
|
1971
2093
|
if (bound?.taskId && (bound.status !== 'approved' && bound.status !== 'pending' || bound.consumed)) throw routeError('ROUTE_NOT_APPROVED', 'This task route is closed or already used.', 409);
|
|
1972
2094
|
// The user picked "here" on this route's card: it runs in this conversation, never on a worker
|
|
@@ -2023,6 +2145,8 @@ export function createAssistantRouter({
|
|
|
2023
2145
|
expireOtherTasks(sessionId, session.latestTaskId || request.taskId);
|
|
2024
2146
|
const prior = existingTaskResult(request, sessionId, { cat, brain, brainInfo });
|
|
2025
2147
|
if (prior && prior.routeId !== routeId) return resolveDispatch({ sessionId, spec: { ...spec, routeId: prior.routeId }, origin, team });
|
|
2148
|
+
request.proposals[0].agentRequest = agentRefOf(spec);
|
|
2149
|
+
request.roles = workerRoles(request, spec.cwd || spec.project, agentPinOf(spec));
|
|
2026
2150
|
if (!spec.provider) request.proposals[0].provider = brain.provider || 'claude-code';
|
|
2027
2151
|
const evaluation = await evaluateWithBudget(sessionId, { mode, routing: r, request, brain, brainInfo, catalog: cat });
|
|
2028
2152
|
if (evaluation.unavailable === 'budget_exhausted') {
|
|
@@ -2035,8 +2159,9 @@ export function createAssistantRouter({
|
|
|
2035
2159
|
if (raced) return resolveDispatch({ sessionId, spec: { ...spec, routeId: raced.routeId }, origin, team });
|
|
2036
2160
|
const t = checkedTarget(evaluation.auto, brain, cat);
|
|
2037
2161
|
noteBudgetTask(sessionId, request, t);
|
|
2038
|
-
const applied = { ...spec, provider: t.provider, model: t.model || null, effort: t.effort
|
|
2162
|
+
const applied = { ...spec, provider: t.provider, model: t.model || null, effort: t.effort ?? null, accountId: t.accountId || null, codexAccountId: null, claudeAccountId: null };
|
|
2039
2163
|
const route = {
|
|
2164
|
+
...workerRole(request, { ...t, kind: 'dispatch' }),
|
|
2040
2165
|
routeId: `route-${randomId()}`, status: 'auto', decidedBy: evaluation.source === 'remembered' ? 'remembered' : evaluation.source === 'budget' ? 'budget' : 'brain', mode,
|
|
2041
2166
|
taskClass: request.taskClass, confidence: request.confidence, target: t, corrections: accountCorrections(t, evaluation.corrections),
|
|
2042
2167
|
remembered: evaluation.source === 'remembered',
|
|
@@ -2061,6 +2186,7 @@ export function createAssistantRouter({
|
|
|
2061
2186
|
|
|
2062
2187
|
function routeMeta(route, cat, brain, brainInfo) {
|
|
2063
2188
|
return {
|
|
2189
|
+
...agentFields(route),
|
|
2064
2190
|
routeId: route.routeId, status: route.status === 'approved' ? 'approved' : route.status, decidedBy: route.decidedBy || null, mode: route.mode || null,
|
|
2065
2191
|
plannedSplit: route.plannedSplit || null, taskId: route.taskId || null, taskKey: route.taskKey || '', sessionId: route.sessionId || null,
|
|
2066
2192
|
taskClass: route.taskClass || null, taskClassLabel: TASK_CLASS_META[route.taskClass]?.label || null, confidence: route.confidence ?? null,
|
|
@@ -2070,6 +2196,7 @@ export function createAssistantRouter({
|
|
|
2070
2196
|
}
|
|
2071
2197
|
function pendingMeta(card) {
|
|
2072
2198
|
return {
|
|
2199
|
+
...agentFields(card),
|
|
2073
2200
|
routeId: card.routeId, taskId: card.taskId || null, taskKey: card.taskKey || '', sessionId: card.sessionId || null, status: 'pending', decidedBy: null, mode: card.mode, taskClass: card.taskClass,
|
|
2074
2201
|
taskClassLabel: TASK_CLASS_META[card.taskClass]?.label || null, confidence: card.confidence ?? null,
|
|
2075
2202
|
target: null, corrections: [], remembered: false, decidedAt: null,
|
|
@@ -2167,9 +2294,9 @@ export function createAssistantRouter({
|
|
|
2167
2294
|
}
|
|
2168
2295
|
function status(routeId) {
|
|
2169
2296
|
const card = cards.get(routeId);
|
|
2170
|
-
if (card) return { routeId, status: card.status, sessionId: card.sessionId, taskId: card.taskId || null, taskKey: card.taskKey || '', runIds: [...card.runIds], taskClass: card.taskClass, expiresAt: new Date(card.expiresAt).toISOString(), request: card.packet.request };
|
|
2297
|
+
if (card) return { ...agentFields(card), routeId, status: card.status, sessionId: card.sessionId, taskId: card.taskId || null, taskKey: card.taskKey || '', runIds: [...card.runIds], taskClass: card.taskClass, expiresAt: new Date(card.expiresAt).toISOString(), request: card.packet.request };
|
|
2171
2298
|
const route = decided.get(routeId);
|
|
2172
|
-
if (route) return { routeId, status: route.status, sessionId: route.sessionId, taskId: route.taskId || null, taskKey: route.taskKey || '', runIds: route.runIds || [], taskClass: route.taskClass, target: route.target, decidedBy: route.decidedBy, plannedSplit: route.plannedSplit || null, workflowId: route.workflowId || null };
|
|
2299
|
+
if (route) return { ...agentFields(route), routeId, status: route.status, sessionId: route.sessionId, taskId: route.taskId || null, taskKey: route.taskKey || '', runIds: route.runIds || [], taskClass: route.taskClass, target: route.target, decidedBy: route.decidedBy, plannedSplit: route.plannedSplit || null, workflowId: route.workflowId || null };
|
|
2173
2300
|
return null;
|
|
2174
2301
|
}
|
|
2175
2302
|
|
|
@@ -2190,7 +2317,7 @@ export function createAssistantRouter({
|
|
|
2190
2317
|
function shutdown() {
|
|
2191
2318
|
for (const entry of continuations.values()) closeContinuation(entry);
|
|
2192
2319
|
continuations.clear();
|
|
2193
|
-
for (const card of [...cards.values()])
|
|
2320
|
+
for (const card of [...cards.values()]) settle(card, { status: 'cancelled' });
|
|
2194
2321
|
cards.clear();
|
|
2195
2322
|
byRequest.clear();
|
|
2196
2323
|
}
|