synabun 2.4.1 → 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 +30 -0
- package/README.md +1 -1
- package/browser-extension/content.js +56 -14
- package/browser-extension/engine.js +158 -8
- package/browser-extension/manifest.json +3 -1
- package/browser-extension/protocol.js +91 -6
- package/browser-extension/service-worker.js +13 -5
- package/browser-extension/tokens.css +1 -1
- package/docs/browser-extension-bridge.md +24 -4
- package/lib/data-home-files.js +4 -2
- 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 +5 -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 +11 -7
- package/mcp-server/dist/tools/agents.d.ts.map +1 -1
- package/mcp-server/dist/tools/agents.js +27 -9
- 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 +22 -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 +26 -9
- 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 +263 -1
- package/neural-interface/i18n/pt-BR.json +264 -2
- 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-catalog.js +2 -2
- package/neural-interface/lib/assistant-config.js +0 -7
- package/neural-interface/lib/assistant-dispatch.js +257 -95
- package/neural-interface/lib/assistant-persona.js +16 -4
- package/neural-interface/lib/assistant-pricing.js +65 -14
- package/neural-interface/lib/assistant-router.js +131 -47
- package/neural-interface/lib/assistant-run-wait.js +45 -28
- package/neural-interface/lib/assistant-runtime.js +39 -33
- 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 +788 -233
- 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 +89 -13
- package/neural-interface/lib/browser-extension-bridge.js +18 -7
- 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 +28 -7
- package/neural-interface/lib/opencode-build-preflight.js +18 -1
- 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/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 +31 -43
- 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 +194 -95
- 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 +233 -24
- package/neural-interface/public/onboarding.html +259 -34
- 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/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 +1 -1
- 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 +105 -38
- package/neural-interface/public/shared/assistant/asst-route.js +100 -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/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 -52
- 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/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-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/studio-attention.js +6 -0
- package/neural-interface/public/shared/styles.css +341 -437
- 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 +124 -17
- package/neural-interface/public/shared/ui-native-loop-router.js +10 -0
- 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-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 +224 -65
- package/neural-interface/public/shared/ui-sidepanel-tray.js +3 -2
- 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/variant/2d/main.js +5 -0
- package/neural-interface/public/variant/3d/app.js +10 -0
- package/neural-interface/public/variant/3d/main.js +5 -1
- package/neural-interface/scripts/scratch-retention.mjs +20 -0
- package/neural-interface/server.js +477 -139
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/scripts/restore-data-home-from-backup.mjs +175 -8
- package/setup.js +18 -4
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
|
|
34
34
|
import { routeTaskIdentity } from '../public/shared/assistant/route-identity.js';
|
|
35
35
|
import { agentPinOf, agentRefOf, routedAgent } from './agents/resolve.js';
|
|
36
|
-
import { planRouteSplit } from './agents/split.js';
|
|
36
|
+
import { planRouteSplit, splitChanged } from './agents/split.js';
|
|
37
37
|
import { normalizeAgentDensity } from './agents/density.js';
|
|
38
38
|
import { randomBytes } from 'node:crypto';
|
|
39
39
|
import { CATALOG_PROVIDERS, TIERS, defaultIsHidden, defaultModelRow, findModel, hiddenModelId, priceText, providerAllHidden, providerEmpty, rowIsHidden, rowMakes } from './assistant-catalog.js';
|
|
@@ -211,6 +211,8 @@ export function normalizeRouteRequest(body = {}, { brain = {} } = {}) {
|
|
|
211
211
|
const needsVision = !!(body.needs_vision ?? body.needsVision) || VISION_CLASSES.has(taskClass) || visionOnly;
|
|
212
212
|
const needsOutput = meta.requires || null;
|
|
213
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.');
|
|
214
216
|
const proposals = [];
|
|
215
217
|
let coercedDirect = false;
|
|
216
218
|
let coercedProvider = null;
|
|
@@ -227,13 +229,14 @@ export function normalizeRouteRequest(body = {}, { brain = {} } = {}) {
|
|
|
227
229
|
} else provider = brain.provider || provider;
|
|
228
230
|
}
|
|
229
231
|
if (!provider) continue;
|
|
232
|
+
if (needsHost && !runsHere({ kind, provider, accountId: raw.accountId || raw.account_id }, brain)) continue;
|
|
230
233
|
if (dispatchOnly && kind === 'direct') {
|
|
231
234
|
kind = 'dispatch';
|
|
232
235
|
model = model || brain.model || null;
|
|
233
236
|
if (!proposals.length) coercedDirect = true;
|
|
234
237
|
}
|
|
235
238
|
proposals.push({
|
|
236
|
-
kind, provider, model,
|
|
239
|
+
kind, provider, model: model || (needsHost ? brain.model || null : null),
|
|
237
240
|
...(requested ? { agentRequest: requested } : {}),
|
|
238
241
|
effort: raw.effort ? String(raw.effort).trim().slice(0, 40) : null,
|
|
239
242
|
...(raw.accountId || raw.account_id ? { accountId: String(raw.accountId || raw.account_id).slice(0, 64) } : {}),
|
|
@@ -241,16 +244,23 @@ export function normalizeRouteRequest(body = {}, { brain = {} } = {}) {
|
|
|
241
244
|
});
|
|
242
245
|
}
|
|
243
246
|
if (!proposals.length) {
|
|
244
|
-
const kind = meta.defaultKind;
|
|
247
|
+
const kind = needsHost ? 'direct' : meta.defaultKind;
|
|
245
248
|
proposals.push({ kind, provider: brain.provider || 'claude-code', model: kind === 'direct' ? (brain.model || null) : null, effort: null, reason: null });
|
|
246
249
|
}
|
|
247
250
|
const request = { taskClass, taskClassLabel: meta.label, summary: clip(body.summary || '', 400), confidence, needsVision, proposals };
|
|
248
251
|
if (needsOutput || dispatchOnly) Object.assign(request, { needsOutput, dispatchOnly, coercedDirect });
|
|
252
|
+
if (needsHost) request.needsHost = true;
|
|
249
253
|
if (visionOnly) request.visionOnly = true;
|
|
250
|
-
if (coercedProvider) request.coercedProvider = coercedProvider;
|
|
254
|
+
if (!needsHost && coercedProvider) request.coercedProvider = coercedProvider;
|
|
251
255
|
return request;
|
|
252
256
|
}
|
|
253
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
|
+
|
|
254
264
|
/** Why a "here" on `provider` runs on a worker: only the brain's own provider runs in this conversation. */
|
|
255
265
|
function otherProviderCorrection(provider, brain = {}) {
|
|
256
266
|
return {
|
|
@@ -303,11 +313,11 @@ export function effortChecked(target, catalog, corrections = null) {
|
|
|
303
313
|
* A saved route as a target. `dispatchOnly` (image / video creation): a saved
|
|
304
314
|
* "here" becomes a dispatch onto the same model (the brain's, when it named none).
|
|
305
315
|
*/
|
|
306
|
-
function preferenceTarget(pref, brain, catalog = null, { dispatchOnly = false } = {}) {
|
|
316
|
+
function preferenceTarget(pref, brain, catalog = null, { dispatchOnly = false, needsHost = false } = {}) {
|
|
307
317
|
if (!pref?.provider) return null;
|
|
308
318
|
const here = pref.kind === 'direct' && pref.provider === brain.provider;
|
|
309
319
|
const kind = here && !dispatchOnly ? 'direct' : 'dispatch';
|
|
310
|
-
const model = pref.model || (here && dispatchOnly ? brain.model || null : null);
|
|
320
|
+
const model = pref.model || (here && (dispatchOnly || needsHost) ? brain.model || null : null);
|
|
311
321
|
const target = { kind, provider: pref.provider, model, effort: pref.effort || null };
|
|
312
322
|
if (hasRouteAccounts(pref.provider) && pref.accountId) target.accountId = pref.accountId;
|
|
313
323
|
// A remembered route onto a model the user since disabled is not applied.
|
|
@@ -423,6 +433,14 @@ function budgetReroute({ target, request, catalog, brain, routing, coverage, cap
|
|
|
423
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 } : {}) });
|
|
424
434
|
if (t) return { target: t, moved: true, step: 'proposal' };
|
|
425
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
|
+
}
|
|
426
444
|
// 2. The same tier on another provider.
|
|
427
445
|
const tierOf = (t) => (t?.model ? findModel(catalog, t.provider, t.model)?.row?.tier : defaultModelRow(catalog, t?.provider)?.tier) || null;
|
|
428
446
|
const tier = tierOf(target);
|
|
@@ -481,12 +499,12 @@ export function capableFor(request, { catalog = null, brain = {}, brainInfo = nu
|
|
|
481
499
|
}
|
|
482
500
|
/**
|
|
483
501
|
* An approved route whose provider ran out of share after approval: move the dispatch the same way
|
|
484
|
-
* agent_route would (budgetReroute).
|
|
502
|
+
* agent_route would (budgetReroute). A decline names the dry providers or the unpriced host provider.
|
|
485
503
|
*/
|
|
486
504
|
export function budgetMove({ target, request, catalog = null, brain = {}, brainInfo = null, routing = {}, coverage = null }) {
|
|
487
505
|
if (!coverage || budgetCovers(coverage, catalog, target)) return { target, correction: null };
|
|
488
506
|
const moved = budgetReroute({ target, request, catalog, brain, routing, coverage, capable: capableFor(request, { catalog, brain, brainInfo }) });
|
|
489
|
-
if (moved.declined) return
|
|
507
|
+
if (moved.declined) return moved;
|
|
490
508
|
const next = effortChecked(request.dispatchOnly && moved.target.kind !== 'dispatch' ? { ...moved.target, kind: 'dispatch' } : moved.target, catalog);
|
|
491
509
|
return {
|
|
492
510
|
target: next,
|
|
@@ -505,8 +523,8 @@ export function budgetMove({ target, request, catalog = null, brain = {}, brainI
|
|
|
505
523
|
* `budget` ({ coverage }: assistant-budget-split.js coverageOf, null under No limit): a target whose
|
|
506
524
|
* provider has no share left moves to the next capable provider with money (budgetReroute) and the
|
|
507
525
|
* corrections say so (reason budget_share); with a budget the saved routes yield to this. When nothing
|
|
508
|
-
* can pay: { ask: false, unavailable: 'budget_exhausted', dry }.
|
|
509
|
-
*
|
|
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.
|
|
510
528
|
*/
|
|
511
529
|
export function evaluateRoute({ mode, routing = {}, request, brain = {}, brainInfo = null, catalog = null, budget = null }) {
|
|
512
530
|
const reasons = [];
|
|
@@ -545,7 +563,7 @@ export function evaluateRoute({ mode, routing = {}, request, brain = {}, brainIn
|
|
|
545
563
|
const applyBudget = (target) => {
|
|
546
564
|
if (!coverage || !target) return { target };
|
|
547
565
|
const moved = budgetReroute({ target, request, catalog, brain, routing, coverage, capable });
|
|
548
|
-
if (moved.declined) return {
|
|
566
|
+
if (moved.declined) return { ...moved, from: target };
|
|
549
567
|
if (!moved.moved) return { target };
|
|
550
568
|
const next = effortChecked(dispatchOnly && moved.target.kind !== 'dispatch' ? { ...moved.target, kind: 'dispatch' } : moved.target, catalog, corrections);
|
|
551
569
|
corrections.push({
|
|
@@ -554,15 +572,19 @@ export function evaluateRoute({ mode, routing = {}, request, brain = {}, brainIn
|
|
|
554
572
|
});
|
|
555
573
|
return { target: next, from: target };
|
|
556
574
|
};
|
|
557
|
-
const budgetDeclined = (outcome
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
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);
|
|
562
583
|
const disabled = !!remembered && isDisabled(catalog, remembered);
|
|
563
584
|
// A saved route onto a model that cannot make the medium (or, for design, is not known to see) is not applied either.
|
|
564
585
|
const incapable = !!remembered && !disabled && (!targetMakes(catalog, remembered, medium) || (visionOnly && tooBlind(remembered)));
|
|
565
|
-
const
|
|
586
|
+
const fitsHost = !request.needsHost || runsHere(remembered, brain);
|
|
587
|
+
const pref = remembered && !disabled && !incapable && fitsHost ? remembered : null;
|
|
566
588
|
// In either asking mode, a proposal of the saved target carries its saved account too.
|
|
567
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;
|
|
568
590
|
// Omitted model: a remembered preference for the class fills it.
|
|
@@ -627,11 +649,16 @@ export function evaluateRoute({ mode, routing = {}, request, brain = {}, brainIn
|
|
|
627
649
|
field: 'route', from: routeText(remembered), to: null, reason: 'remembered_incapable',
|
|
628
650
|
text: `saved ${label} route ${routeText(remembered)} ${cannot}; not applied`,
|
|
629
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
|
+
});
|
|
630
657
|
}
|
|
631
658
|
const invalid = reasons.find((r) => r === 'model_unknown' || r === 'model_disabled');
|
|
632
659
|
if (invalid && auto.model) {
|
|
633
660
|
corrections.push({ field: 'model', from: auto.model, to: null, reason: invalid });
|
|
634
|
-
auto = { ...auto, model: null };
|
|
661
|
+
auto = { ...auto, model: request.needsHost ? brain.model || null : null };
|
|
635
662
|
}
|
|
636
663
|
// No model and the provider default is hidden: name the visible stand-in.
|
|
637
664
|
const pinned = pinnedDefault(catalog, auto);
|
|
@@ -675,11 +702,14 @@ export function evaluateRoute({ mode, routing = {}, request, brain = {}, brainIn
|
|
|
675
702
|
}
|
|
676
703
|
}
|
|
677
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
|
+
}
|
|
678
708
|
if (dispatchOnly && auto.kind !== 'dispatch') auto = { ...auto, kind: 'dispatch' };
|
|
679
709
|
// A corrected model or provider re-checks the effort.
|
|
680
710
|
auto = effortChecked(auto, catalog, corrections);
|
|
681
711
|
// The provider rule only names what always happened (a "here" elsewhere is a worker): it corrects nothing.
|
|
682
|
-
if (!bound && corrections.some((c) =>
|
|
712
|
+
if (!bound && corrections.some((c) => !['remembered_disabled', 'remembered_incapable', 'remembered_host', 'other_provider'].includes(c.reason))) source = 'corrected';
|
|
683
713
|
// With a budget the saved route yields: a provider with no share left moves the task on.
|
|
684
714
|
const budgeted = applyBudget(auto);
|
|
685
715
|
if (budgeted.declined) return budgetDeclined(budgeted);
|
|
@@ -784,7 +814,10 @@ export function buildRouteOptions({ request, evaluation, brain = {}, brainInfo =
|
|
|
784
814
|
const visionOnly = request.visionOnly === true;
|
|
785
815
|
const ctx = { catalog, brain, brainInfo, needsVision: request.needsVision, needsOutput: medium, visionOnly, coverage };
|
|
786
816
|
const options = [];
|
|
787
|
-
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
|
+
};
|
|
788
821
|
const hereTarget = { kind: 'direct', provider: brain.provider, model: brain.model || null, effort: brain.effort || null };
|
|
789
822
|
// A direct pick on the brain's own model with no effort is "here" as the brain runs now: one row, not two.
|
|
790
823
|
const onBrainModel = (t) => t.kind === 'direct' && t.provider === brain.provider && String(t.model || '') === String(brain.model || '');
|
|
@@ -797,7 +830,7 @@ export function buildRouteOptions({ request, evaluation, brain = {}, brainInfo =
|
|
|
797
830
|
// The session budget moved the suggestion: the brain's own pick stays on the card, disabled with why.
|
|
798
831
|
if (evaluation.budgetFrom && coverage) push(optionFor('b0', evaluation.budgetFrom, 'suggested', { ...ctx, reason: request.proposals[0]?.reason || null }));
|
|
799
832
|
if (!dispatchOnly) push(optionFor('here', hereTarget, 'current', ctx));
|
|
800
|
-
const pref = preferenceTarget(routing.preferences?.[request.taskClass], brain, catalog,
|
|
833
|
+
const pref = preferenceTarget(routing.preferences?.[request.taskClass], brain, catalog, request);
|
|
801
834
|
// Always ask: the saved route is offered and its side starts on it (never binding: the card still asks).
|
|
802
835
|
if (pref) {
|
|
803
836
|
const saved = optionFor('r1', pref, 'remembered', ctx);
|
|
@@ -843,7 +876,7 @@ export function buildRouteOptions({ request, evaluation, brain = {}, brainInfo =
|
|
|
843
876
|
if (first && !options.some((o) => o.kind === kind)) push(first);
|
|
844
877
|
};
|
|
845
878
|
if (request.taskClass !== 'chat' && !dispatchOnly && !runnable('direct')) offer('direct', 'h1', hereCandidates({ request, catalog, brain }));
|
|
846
|
-
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 }));
|
|
847
880
|
// Order: suggested first, then here, remembered, a capable stand-in, cheaper, stronger.
|
|
848
881
|
const order = { suggested: 0, current: 1, remembered: 2, capable: 3, cheaper: 4, stronger: 5 };
|
|
849
882
|
options.sort((a, b) => (order[a.badge] ?? 9) - (order[b.badge] ?? 9) || String(a.id).localeCompare(String(b.id)));
|
|
@@ -909,6 +942,7 @@ export function routeSides({ options = [], request = {}, defaultOptionId = null
|
|
|
909
942
|
|| (chosen?.kind === kind && usable(chosen) ? chosen : null) || options.find((o) => o.kind === kind && usable(o)) || null;
|
|
910
943
|
const label = request.taskClassLabel || TASK_CLASS_META[request.taskClass]?.label || 'This task';
|
|
911
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.' };
|
|
912
946
|
if (firstOf(kind)) return { available: true, reason: null, code: null };
|
|
913
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.` };
|
|
914
948
|
if (kind === 'direct' && options.some((o) => o.kind === 'dispatch' && o.accountKind === 'direct')) {
|
|
@@ -926,6 +960,10 @@ export function routeSides({ options = [], request = {}, defaultOptionId = null
|
|
|
926
960
|
};
|
|
927
961
|
}
|
|
928
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
|
+
|
|
929
967
|
/** Validate a route-card answer; returns { declined } or { target, optionId, remember }. */
|
|
930
968
|
export function targetFromAnswer({ card, response = {}, catalog = null, brain = {} }) {
|
|
931
969
|
if (response.decline === true || response.behavior === 'deny' || response.cancel === true) return { declined: true };
|
|
@@ -939,6 +977,7 @@ export function targetFromAnswer({ card, response = {}, catalog = null, brain =
|
|
|
939
977
|
// A card can remain open while the catalog or hidden-model list changes.
|
|
940
978
|
// Check the chosen target again instead of trusting the option's old state.
|
|
941
979
|
const ensureAvailable = (target) => {
|
|
980
|
+
if (card.needsHost && !runsHere(target, brain)) throw hostRouteError();
|
|
942
981
|
const own = onBrain(target);
|
|
943
982
|
if (target.model && (own ? isDisabled(catalog, target) : findModel(catalog, target.provider, target.model) === null)) {
|
|
944
983
|
if (isDisabled(catalog, target)) throw routeError('MODEL_DISABLED', `${target.model} is disabled in the Assistant's Models list. Pick an enabled model.`);
|
|
@@ -980,7 +1019,8 @@ export function targetFromAnswer({ card, response = {}, catalog = null, brain =
|
|
|
980
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` }
|
|
981
1020
|
: otherProviderCorrection(t.provider, brain));
|
|
982
1021
|
}
|
|
983
|
-
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);
|
|
984
1024
|
ensureAvailable(target);
|
|
985
1025
|
return { target, optionId: 'other', remember, corrections };
|
|
986
1026
|
}
|
|
@@ -1061,7 +1101,7 @@ export function escalationFor({ run, catalog = null, routing = {}, depth = 0 })
|
|
|
1061
1101
|
* @param {object} deps.sinks { sendCard(sessionId, packet), cancelCard(sessionId, requestId, reason),
|
|
1062
1102
|
* routeEvent(sessionId, phase, route), mailbox(sessionId, item),
|
|
1063
1103
|
* continueDirect(sessionId, {target, route, text}) → false when the pick's turn is gone,
|
|
1064
|
-
* startHeld(runId, target, meta),
|
|
1104
|
+
* activeRouteRuns(sessionId, routeId) → [{ runId, title, state }], startHeld(runId, target, meta),
|
|
1065
1105
|
* checkHeld(runId, target) → why the held run could not start on target ({ code, message, status }) or null,
|
|
1066
1106
|
* declineHeld(runId, reason), routed(sessionId, result), routeFailed(sessionId, error) }
|
|
1067
1107
|
* @param {object} [deps.clarifier] assistant-clarify.js — { blocking(sessionId, { independent }) }: while the
|
|
@@ -1182,17 +1222,20 @@ export function createAssistantRouter({
|
|
|
1182
1222
|
function budgetDeclinedResult({ sessionId, request, mode, cat, brain, brainInfo, evaluation }) {
|
|
1183
1223
|
const routeId = `route-${randomId()}`;
|
|
1184
1224
|
const dry = evaluation.dry || [];
|
|
1225
|
+
const unpriced = evaluation.unavailable === 'budget_unpriced' ? unpricedText(brain.provider) : null;
|
|
1226
|
+
const reasonCode = unpriced ? 'BUDGET_UNPRICED' : 'budget_exhausted';
|
|
1185
1227
|
const route = {
|
|
1186
1228
|
routeId, status: 'declined', sessionId, taskClass: request.taskClass, summary: request.summary, confidence: request.confidence,
|
|
1187
|
-
target: null, decidedBy: 'budget', remembered: false, corrections: evaluation.corrections || [], mode, runIds: [], reasonCode
|
|
1188
|
-
|
|
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."),
|
|
1189
1232
|
};
|
|
1190
1233
|
call('routeEvent', sessionId, 'declined', routeView(route, { catalog: cat, brain, brainInfo }));
|
|
1191
|
-
return {
|
|
1192
|
-
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,
|
|
1193
1236
|
remembered: false, continuation: false, corrections: evaluation.corrections || [], runIds: [], expiresAt: null,
|
|
1194
|
-
budget: compactBudget(sessionId), next: budgetDeclinedText(sessionId, dry),
|
|
1195
|
-
};
|
|
1237
|
+
budget: compactBudget(sessionId), next: unpriced || budgetDeclinedText(sessionId, dry),
|
|
1238
|
+
});
|
|
1196
1239
|
}
|
|
1197
1240
|
function liveAccounts(cat) { return accountUsage ? accountUsage.list() : listAccounts ? listAccounts() : cat?.accounts || {}; }
|
|
1198
1241
|
function accountTarget(target, brain, cat, { check = true, fallback = null, select = true } = {}) {
|
|
@@ -1251,12 +1294,14 @@ export function createAssistantRouter({
|
|
|
1251
1294
|
return {
|
|
1252
1295
|
...agentFields(source),
|
|
1253
1296
|
routeId: source.routeId, runIds: [...(source.runIds || [])], taskClass: source.taskClass, taskClassLabel: TASK_CLASS_META[source.taskClass]?.label || source.taskClass,
|
|
1297
|
+
...(source.needsHost ? { needsHost: true } : {}),
|
|
1254
1298
|
plannedSplit: source.plannedSplit || null, sessionId: source.sessionId || null, taskId: source.taskId || null, taskKey: source.taskKey || '',
|
|
1255
1299
|
summary: source.summary || '', confidence: source.confidence ?? null, reason: source.reason || null,
|
|
1256
1300
|
target, alternatives: (source.alternatives || []).slice(0, 4), decidedBy: source.decidedBy || null, remembered: !!source.remembered,
|
|
1257
1301
|
optionId: source.optionId || null, corrections: source.corrections || [], mode: source.mode || null, status: source.status || null,
|
|
1258
1302
|
// Why a route was declined without a card (no_capable_model), else null.
|
|
1259
1303
|
reasonCode: source.reasonCode || null,
|
|
1304
|
+
...(source.reasonCode === 'BUDGET_UNPRICED' ? { provider: source.provider } : {}),
|
|
1260
1305
|
// Design's no_capable_model: no model can see.
|
|
1261
1306
|
...(source.needs ? { needs: source.needs } : {}),
|
|
1262
1307
|
// budget_exhausted: the providers whose share is used up (the panel names them).
|
|
@@ -1452,6 +1497,19 @@ export function createAssistantRouter({
|
|
|
1452
1497
|
return !session || session.closing === true;
|
|
1453
1498
|
}
|
|
1454
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
|
+
|
|
1455
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 = [] } = {}) {
|
|
1456
1514
|
const described = target ? { ...describeTarget(target, { catalog: cat, brain, brainInfo }), continuation } : null;
|
|
1457
1515
|
// The user's pick was the other kind than the brain proposed; a "here" pick on another account runs on a worker.
|
|
@@ -1483,7 +1541,7 @@ export function createAssistantRouter({
|
|
|
1483
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"}.`
|
|
1484
1542
|
: `Call agent_dispatch with route_id="${routeId}" for one worker. Explain: ${plannedSplit.reason}`
|
|
1485
1543
|
: null;
|
|
1486
|
-
return {
|
|
1544
|
+
return reportSupersededRuns(record, {
|
|
1487
1545
|
...agentFields(record),
|
|
1488
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,
|
|
1489
1547
|
taskClass: record?.taskClass || null, sessionId: sessionId || record?.sessionId || null, taskId: record?.taskId || null, taskKey: record?.taskKey || '',
|
|
@@ -1491,7 +1549,7 @@ export function createAssistantRouter({
|
|
|
1491
1549
|
corrections: record?.agentCorrection ? [...corrections, record.agentCorrection] : corrections, runIds, expiresAt: card?.expiresAt ? new Date(card.expiresAt).toISOString() : null,
|
|
1492
1550
|
...(shares ? { budget: shares } : {}),
|
|
1493
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 })}`,
|
|
1494
|
-
};
|
|
1552
|
+
});
|
|
1495
1553
|
}
|
|
1496
1554
|
|
|
1497
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). */
|
|
@@ -1547,7 +1605,7 @@ export function createAssistantRouter({
|
|
|
1547
1605
|
for (const option of options) {
|
|
1548
1606
|
const first = request.proposals[0];
|
|
1549
1607
|
const fallback = origin === 'dispatch' && option.badge !== 'remembered' && option.provider === first?.provider ? first.accountId : null;
|
|
1550
|
-
Object.assign(option, accountTarget(option, brain, cat, { check: false, fallback }));
|
|
1608
|
+
Object.assign(option, accountTarget(option, brain, cat, { check: false, fallback, select: !request.needsHost }));
|
|
1551
1609
|
Object.assign(option, workerRole(request, option, option.id));
|
|
1552
1610
|
if (option.accountError) { option.disabled = true; option.disabledReason = option.accountError.message; }
|
|
1553
1611
|
// A "here" whose account cannot take it (this conversation's is out of usage) runs on a worker
|
|
@@ -1561,16 +1619,17 @@ export function createAssistantRouter({
|
|
|
1561
1619
|
// The sides and defaults as the options are sent (the account check can disable or move one).
|
|
1562
1620
|
const { defaultOptionId, sides, defaults } = routeSides({ options, request, defaultOptionId: built.defaultOptionId });
|
|
1563
1621
|
const computer = computerConsent({ session, request, options, defaultOptionId, brain, origin });
|
|
1564
|
-
const expiresAt = now() + r.cardTimeoutMinutes * 60_000;
|
|
1565
1622
|
const pref = r.preferences?.[request.taskClass];
|
|
1566
1623
|
const card = {
|
|
1567
1624
|
...agentFields(options.find(o => o.id === (defaults.dispatch || defaultOptionId))),
|
|
1568
1625
|
routeId, requestId, sessionId, origin, status: 'pending', mode, workflowId,
|
|
1569
1626
|
plannedSplit: request.plannedSplit || null, taskId: request.taskId, taskKey: request.taskKey || '',
|
|
1570
1627
|
taskClass: request.taskClass, summary: request.summary, confidence: request.confidence, needsVision: request.needsVision,
|
|
1628
|
+
...(request.needsHost ? { needsHost: true } : {}),
|
|
1571
1629
|
needsOutput: request.needsOutput || null, dispatchOnly: request.dispatchOnly === true, visionOnly: request.visionOnly === true,
|
|
1572
1630
|
reasons: evaluation.reasons, request, options, defaultOptionId, sides, defaults, runIds: new Set(runIds), waiters: new Set(),
|
|
1573
|
-
|
|
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,
|
|
1574
1633
|
// The option whose approval is also the computer approval (computerConsent), as this card was sent.
|
|
1575
1634
|
computer,
|
|
1576
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 })),
|
|
@@ -1583,6 +1642,7 @@ export function createAssistantRouter({
|
|
|
1583
1642
|
reasons: evaluation.reasons, taskClass: request.taskClass, taskClassLabel: request.taskClassLabel, summary: request.summary,
|
|
1584
1643
|
plannedSplit: request.plannedSplit || null, taskId: request.taskId || null, taskKey: request.taskKey || '',
|
|
1585
1644
|
confidence: request.confidence, needsVision: request.needsVision,
|
|
1645
|
+
...(request.needsHost ? { needsHost: true } : {}),
|
|
1586
1646
|
// Image / video creation: the medium the model must generate, and no "here" (always a worker).
|
|
1587
1647
|
requires: request.needsOutput || null, dispatchOnly: request.dispatchOnly === true,
|
|
1588
1648
|
// Design: only models that can see.
|
|
@@ -1591,16 +1651,14 @@ export function createAssistantRouter({
|
|
|
1591
1651
|
options, defaultOptionId,
|
|
1592
1652
|
// The card's Here / Dispatch switch: which side can run the task (and why not), and the option each side starts on.
|
|
1593
1653
|
sides, defaults,
|
|
1594
|
-
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' },
|
|
1595
1655
|
remember: { available: request.taskClass !== 'chat', taskClass: request.taskClass, label: request.taskClassLabel, current: pref ? (pref.label || [pref.provider, pref.model].filter(Boolean).join('/')) : null },
|
|
1596
1656
|
decline: { allowed: true, label: 'Cancel' },
|
|
1597
1657
|
// Approving this option also lets the Assistant control the Mac for the task: every host says so in words.
|
|
1598
1658
|
...(computer ? { computer: { optionId: computer.optionId } } : {}),
|
|
1599
|
-
createdAt: new Date(card.createdAt).toISOString(), expiresAt:
|
|
1659
|
+
createdAt: new Date(card.createdAt).toISOString(), expiresAt: null,
|
|
1600
1660
|
},
|
|
1601
1661
|
};
|
|
1602
|
-
card.timer = setTimeout(() => expire(routeId), Math.max(1000, expiresAt - now()));
|
|
1603
|
-
card.timer.unref?.();
|
|
1604
1662
|
cards.set(routeId, card);
|
|
1605
1663
|
byRequest.set(requestId, routeId);
|
|
1606
1664
|
return card;
|
|
@@ -1625,7 +1683,6 @@ export function createAssistantRouter({
|
|
|
1625
1683
|
return routeError('ROUTE_CANCELLED', text, 409, { routeId: card?.routeId || null });
|
|
1626
1684
|
}
|
|
1627
1685
|
function closeCard(card) {
|
|
1628
|
-
if (card.timer) { clearTimeout(card.timer); card.timer = null; }
|
|
1629
1686
|
byRequest.delete(card.requestId);
|
|
1630
1687
|
cards.delete(card.routeId);
|
|
1631
1688
|
// Why it closed, for a producer that attaches a run a moment too late (bounded).
|
|
@@ -1718,9 +1775,28 @@ export function createAssistantRouter({
|
|
|
1718
1775
|
const key = routeTaskIdentity(request);
|
|
1719
1776
|
if (!key) return null;
|
|
1720
1777
|
const card = [...cards.values()].find(c => routeTaskIdentity(c) === key);
|
|
1721
|
-
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);
|
|
1722
1779
|
if (!prior) return null;
|
|
1723
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
|
+
}
|
|
1724
1800
|
let continuation = false;
|
|
1725
1801
|
// A thinking switch that waited is decided again now (the background work may have reported since).
|
|
1726
1802
|
let corrections = (prior.corrections || []).filter((c) => c?.reason !== 'thinking_waits');
|
|
@@ -1760,10 +1836,11 @@ export function createAssistantRouter({
|
|
|
1760
1836
|
const brainInfo = brainInfoFor(brain);
|
|
1761
1837
|
const request = normalizeRouteRequest(body, { brain });
|
|
1762
1838
|
Object.assign(request, taskIdentity(sessionId, session, body));
|
|
1839
|
+
request.requestedSplit = body.planned_split ?? body.plannedSplit ?? null;
|
|
1763
1840
|
// The same task routed again (a later turn: a task notification, a mailbox event, the user's next words).
|
|
1764
1841
|
const existing = existingTaskResult(request, sessionId, { cat, brain, brainInfo }, { deliver: origin === 'agent_route' });
|
|
1765
1842
|
if (existing) return existing;
|
|
1766
|
-
request.plannedSplit = await planRouteSplit(body, session, request.taskClass);
|
|
1843
|
+
request.plannedSplit = request.needsHost ? null : await planRouteSplit(body, session, request.taskClass);
|
|
1767
1844
|
request.projectPath = request.plannedSplit?.projectPath || null;
|
|
1768
1845
|
request.roles = workerRoles(request, body.cwd || body.project);
|
|
1769
1846
|
if (request.plannedSplit) {
|
|
@@ -1776,22 +1853,24 @@ export function createAssistantRouter({
|
|
|
1776
1853
|
const raced = existingTaskResult(request, sessionId, { cat, brain, brainInfo }, { deliver: origin === 'agent_route' });
|
|
1777
1854
|
if (raced) return raced;
|
|
1778
1855
|
assertCurrentTask(sessionId, request.taskId);
|
|
1779
|
-
if (evaluation.unavailable
|
|
1856
|
+
if (['budget_exhausted', 'budget_unpriced'].includes(evaluation.unavailable)) return budgetDeclinedResult({ sessionId, request, mode, cat, brain, brainInfo, evaluation });
|
|
1780
1857
|
if (evaluation.unavailable) return unavailableResult({ sessionId, request, mode, cat, brain, brainInfo });
|
|
1781
1858
|
if (!evaluation.ask) {
|
|
1782
1859
|
const routeId = `route-${randomId()}`;
|
|
1783
1860
|
let target = evaluation.auto;
|
|
1784
|
-
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();
|
|
1785
1863
|
if (checked.accountError) {
|
|
1786
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 };
|
|
1787
1865
|
call('routeEvent', sessionId, 'declined', routeView(failed, { catalog: cat, brain, brainInfo }));
|
|
1788
|
-
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 });
|
|
1789
1867
|
}
|
|
1790
1868
|
target = checked;
|
|
1791
1869
|
const decidedBy = evaluation.source === 'remembered' ? 'remembered' : evaluation.source === 'budget' ? 'budget' : 'brain';
|
|
1792
1870
|
// Off to or from a level that waits for Claude Code's background work: in place, and the answer says so.
|
|
1793
1871
|
const waits = origin === 'agent_route' && request.taskClass !== 'chat' ? thinkingWaits(sessionId, target, brain, turnBrain(sessionId, brain)) : null;
|
|
1794
1872
|
const route = {
|
|
1873
|
+
...(request.needsHost ? { needsHost: true } : {}),
|
|
1795
1874
|
taskId: request.taskId, taskKey: request.taskKey || '', plannedSplit: request.plannedSplit || null, workflowId: null,
|
|
1796
1875
|
routeId, status: 'approved', sessionId, taskClass: request.taskClass, summary: request.summary, confidence: request.confidence,
|
|
1797
1876
|
...workerRole(request, target),
|
|
@@ -1876,7 +1955,10 @@ export function createAssistantRouter({
|
|
|
1876
1955
|
return result;
|
|
1877
1956
|
}
|
|
1878
1957
|
const { optionId, remember } = parsed;
|
|
1879
|
-
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();
|
|
1880
1962
|
const pickedRole = workerRole(card.request, target, optionId);
|
|
1881
1963
|
const corrections = accountCorrections(target, parsed.corrections || []);
|
|
1882
1964
|
// The session budget must be able to pay for the pick: a provider with no share left divides the
|
|
@@ -1937,6 +2019,7 @@ export function createAssistantRouter({
|
|
|
1937
2019
|
const heldRuns = keptHere ? [] : [...card.runIds];
|
|
1938
2020
|
const droppedRuns = keptHere ? [...card.runIds] : [];
|
|
1939
2021
|
const route = {
|
|
2022
|
+
...(card.needsHost ? { needsHost: true } : {}),
|
|
1940
2023
|
taskId: card.taskId, taskKey: card.taskKey || '', plannedSplit: card.plannedSplit || null, workflowId: null,
|
|
1941
2024
|
routeId, status: 'approved', sessionId: card.sessionId, taskClass: card.taskClass, summary: card.summary, confidence: card.confidence,
|
|
1942
2025
|
...pickedRole,
|
|
@@ -2005,6 +2088,7 @@ export function createAssistantRouter({
|
|
|
2005
2088
|
const approved = decided.get(routeId);
|
|
2006
2089
|
const bound = approved || cards.get(routeId);
|
|
2007
2090
|
if (bound?.sessionId === sessionId && !team) assertCurrentTask(sessionId, bound.taskId);
|
|
2091
|
+
if (bound?.sessionId === sessionId && bound.needsHost) throw hostRouteError();
|
|
2008
2092
|
if (bound?.taskId && ['expired', 'cancelled'].includes(bound.status)) throw routeClosedError(lastClosed.get(routeId) || bound);
|
|
2009
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);
|
|
2010
2094
|
// The user picked "here" on this route's card: it runs in this conversation, never on a worker
|
|
@@ -2233,7 +2317,7 @@ export function createAssistantRouter({
|
|
|
2233
2317
|
function shutdown() {
|
|
2234
2318
|
for (const entry of continuations.values()) closeContinuation(entry);
|
|
2235
2319
|
continuations.clear();
|
|
2236
|
-
for (const card of [...cards.values()])
|
|
2320
|
+
for (const card of [...cards.values()]) settle(card, { status: 'cancelled' });
|
|
2237
2321
|
cards.clear();
|
|
2238
2322
|
byRequest.clear();
|
|
2239
2323
|
}
|
|
@@ -41,7 +41,7 @@ export function createRunWaits({ entries, view, isTerminal, coordination, now =
|
|
|
41
41
|
/** A run changed: every wait looks again. */
|
|
42
42
|
function notify() {
|
|
43
43
|
for (const waiter of [...waiters]) {
|
|
44
|
-
|
|
44
|
+
waiter.wake();
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -111,15 +111,14 @@ export function createRunWaits({ entries, view, isTerminal, coordination, now =
|
|
|
111
111
|
from = Number(afterSeq);
|
|
112
112
|
if (!Number.isInteger(from) || from < 0) throw fail('INVALID_CURSOR', 'after_seq is a whole number from 0: the cursor of an earlier agent_wait answer.', { status: 400 });
|
|
113
113
|
} else {
|
|
114
|
-
from = lastSeq();
|
|
114
|
+
from = await lastSeq();
|
|
115
115
|
// The brain itself asks: what it has not been told yet counts, though it happened before this call.
|
|
116
|
-
if (unseenFor) from = Math.min(from, unseenStart(String(unseenFor), ids, from));
|
|
116
|
+
if (unseenFor) from = Math.min(from, await unseenStart(String(unseenFor), ids, from));
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
|
-
const eventsNow = () => {
|
|
119
|
+
const eventsNow = async () => {
|
|
120
120
|
if (!typed) return [];
|
|
121
|
-
|
|
122
|
-
catch { return []; }
|
|
121
|
+
return coordination.runEvents({ runIds: ids, afterSeq: from, kinds: wanted, limit: RUN_WAIT_LIMITS.maxEvents });
|
|
123
122
|
};
|
|
124
123
|
const satisfied = (events) => ids.filter((id) => {
|
|
125
124
|
const entry = entries.get(id);
|
|
@@ -130,21 +129,41 @@ export function createRunWaits({ entries, view, isTerminal, coordination, now =
|
|
|
130
129
|
if (!cursorGiven && (entry.state === 'awaiting_permission' || entry.state === 'awaiting_route')) return true;
|
|
131
130
|
return events.some((event) => event.runId === id);
|
|
132
131
|
});
|
|
133
|
-
const check = () => {
|
|
132
|
+
const check = async () => {
|
|
134
133
|
ids = members();
|
|
135
|
-
const done = satisfied(eventsNow());
|
|
134
|
+
const done = satisfied(await eventsNow());
|
|
136
135
|
return mode === 'any' ? done.length > 0 : done.length === ids.length;
|
|
137
136
|
};
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
waiters.
|
|
144
|
-
|
|
145
|
-
|
|
137
|
+
// Subscribe before the first read. Coalesce notifications while a read is
|
|
138
|
+
// outstanding so an event between that read and its reply still wakes us.
|
|
139
|
+
await new Promise((resolveWait, rejectWait) => {
|
|
140
|
+
let checking = false, again = false;
|
|
141
|
+
function finish(error) {
|
|
142
|
+
if (!waiters.delete(waiter)) return;
|
|
143
|
+
clearTimeout(timer);
|
|
144
|
+
if (error) rejectWait(error); else resolveWait();
|
|
145
|
+
}
|
|
146
|
+
const waiter = { async wake() {
|
|
147
|
+
if (checking) { again = true; return; }
|
|
148
|
+
checking = true;
|
|
149
|
+
try {
|
|
150
|
+
do {
|
|
151
|
+
again = false;
|
|
152
|
+
if (await check()) { finish(); break; }
|
|
153
|
+
} while (again && waiters.has(waiter));
|
|
154
|
+
} catch (error) { finish(error); }
|
|
155
|
+
checking = false;
|
|
156
|
+
} };
|
|
157
|
+
const timer = setTimeout(finish, budget);
|
|
158
|
+
timer.unref?.();
|
|
159
|
+
waiters.add(waiter);
|
|
160
|
+
waiter.wake();
|
|
161
|
+
});
|
|
146
162
|
ids = members();
|
|
147
|
-
|
|
163
|
+
// Sample the watermark before fetching the rows. A later commit must
|
|
164
|
+
// appear in this answer or remain above the returned cursor.
|
|
165
|
+
const watermark = await lastSeq();
|
|
166
|
+
const events = await eventsNow();
|
|
148
167
|
const done = satisfied(events);
|
|
149
168
|
const pendingIds = ids.filter((id) => !done.includes(id));
|
|
150
169
|
const timedOut = !(mode === 'any' ? done.length > 0 : done.length === ids.length);
|
|
@@ -158,25 +177,23 @@ export function createRunWaits({ entries, view, isTerminal, coordination, now =
|
|
|
158
177
|
if (typed) {
|
|
159
178
|
out.events = events;
|
|
160
179
|
// Pass it back as after_seq to go on from here. A full page stops at its last event: more may follow.
|
|
161
|
-
out.cursor = events.length >= RUN_WAIT_LIMITS.maxEvents ? events[events.length - 1].seq : Math.max(from,
|
|
180
|
+
out.cursor = events.length >= RUN_WAIT_LIMITS.maxEvents ? events[events.length - 1].seq : Math.max(from, watermark, events.at(-1)?.seq || 0);
|
|
162
181
|
} else {
|
|
163
|
-
out.cursor =
|
|
182
|
+
out.cursor = watermark;
|
|
164
183
|
}
|
|
165
184
|
if (overflow) out.notWaitedFor = overflow;
|
|
166
185
|
return out;
|
|
167
186
|
}
|
|
168
187
|
|
|
169
|
-
function lastSeq() {
|
|
170
|
-
|
|
188
|
+
async function lastSeq() {
|
|
189
|
+
return Number(await coordination.lastSeq()) || 0;
|
|
171
190
|
}
|
|
172
191
|
/** Just before the oldest event of these runs the session's brain was not told yet (`fallback` when there is none). */
|
|
173
|
-
function unseenStart(sessionId, ids, fallback) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
return seqs.length ? Math.min(...seqs) - 1 : fallback;
|
|
179
|
-
} catch { return fallback; }
|
|
192
|
+
async function unseenStart(sessionId, ids, fallback) {
|
|
193
|
+
const wantedRuns = new Set(ids);
|
|
194
|
+
const { items } = await coordination.mailbox.pending(sessionId, { limit: 1000, peek: true });
|
|
195
|
+
const seqs = items.filter((item) => item.run?.runId && wantedRuns.has(String(item.run.runId))).map((item) => Number(item.seq)).filter((seq) => Number.isFinite(seq));
|
|
196
|
+
return seqs.length ? Math.min(...seqs) - 1 : fallback;
|
|
180
197
|
}
|
|
181
198
|
|
|
182
199
|
return { wait, notify, satisfies, pending: () => waiters.size };
|