@genesislcap/ai-assistant 15.81.0 → 15.82.0

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.
@@ -330,7 +330,9 @@ export class OrchestratingDriver extends BaseDriverDecorator {
330
330
  const routingInput = delegated.delegate
331
331
  ? frameDelegatedContent(input, delegated.delegateFraming)
332
332
  : input;
333
- const pinned = this.resolvePinnedAgent();
333
+ // This message's own routing, when the sender gave one, in place of the sticky pin.
334
+ const pin = options === null || options === void 0 ? void 0 : options.agent;
335
+ const pinned = this.resolvePinnedAgent(pin);
334
336
  if (!pinned)
335
337
  this.dispatchEvent(new CustomEvent('orchestrating-start'));
336
338
  let routed;
@@ -364,7 +366,7 @@ export class OrchestratingDriver extends BaseDriverDecorator {
364
366
  if (this.cancelled)
365
367
  break;
366
368
  // oxlint-disable-next-line no-await-in-loop
367
- yield this.installAgent(currentAgent);
369
+ yield this.installAgent(currentAgent, pin);
368
370
  // A Stop that landed while the agent was being installed, after the check above. The inner
369
371
  // driver was idle, so nothing else would stop it: the call below would run the next agent,
370
372
  // and a continuation would even give it a scope of its own.
@@ -601,7 +603,11 @@ export class OrchestratingDriver extends BaseDriverDecorator {
601
603
  }
602
604
  return winner ? Object.assign(Object.assign({}, winner), { agentName, basis: 'reachable-max' }) : undefined;
603
605
  }
604
- installAgent(agent) {
606
+ /**
607
+ * `pin` stands in for the user-pin when given, as for
608
+ * {@link OrchestratingDriver.resolvePinnedAgent}.
609
+ */
610
+ installAgent(agent, pin) {
605
611
  return __awaiter(this, void 0, void 0, function* () {
606
612
  // The transition — handoff record, lifecycle hooks, restored state, flow lock — belongs to
607
613
  // the session, and the inner driver raises its events (GENC-1485). What is left below is this
@@ -617,7 +623,7 @@ export class OrchestratingDriver extends BaseDriverDecorator {
617
623
  // classifier mid-machine. Capture the tool loop until the
618
624
  // user (or the agent itself, via `releaseAgent`) releases.
619
625
  const isTerminal = isFallback(agent) ||
620
- this.agentSession.getPinned() !== null ||
626
+ (pin === undefined ? this.agentSession.getPinned() : pin) !== null ||
621
627
  this.agentSession.getFlowOwner() !== null ||
622
628
  !!(agent.onActivate || agent.onDeactivate);
623
629
  let agentToApply = agent;
@@ -917,9 +923,11 @@ export class OrchestratingDriver extends BaseDriverDecorator {
917
923
  *
918
924
  * Logs and returns `undefined` if a name no longer matches the agents array
919
925
  * — protects against stale state after an agents-array reassignment.
926
+ *
927
+ * `pin` stands in for the user-pin when given — `SendMessageOptions.agent`.
920
928
  */
921
- resolvePinnedAgent() {
922
- const name = this.agentSession.getLockedName();
929
+ resolvePinnedAgent(pin) {
930
+ const name = this.agentSession.getLockedName(pin);
923
931
  if (name === null)
924
932
  return undefined;
925
933
  const match = this.agents.find((a) => a.name === name);
@@ -1323,7 +1323,8 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
1323
1323
  /**
1324
1324
  * Name of the agent the user has pinned via the agent picker. `null` means
1325
1325
  * orchestration: the assistant routes each message. Persisted on the session store, so it survives
1326
- * pop-in/pop-out but resets on page refresh.
1326
+ * pop-in/pop-out. A page refresh resets it unless session persistence is on, which saves it with
1327
+ * the session and restores it.
1327
1328
  *
1328
1329
  * Only changes on explicit user action (picker click or host's `setAgent`).
1329
1330
  * The orchestrator's auto-pin on stateful activation writes
@@ -1335,7 +1336,7 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
1335
1336
  return (_b = (_a = this._sessionRef) === null || _a === void 0 ? void 0 : _a.store.aiAssistant.pinnedAgentName) !== null && _b !== void 0 ? _b : null;
1336
1337
  }
1337
1338
  set pinnedAgentName(value) {
1338
- var _a, _b, _c, _d;
1339
+ var _a, _b, _c, _d, _e;
1339
1340
  const previous = (_b = (_a = this._sessionRef) === null || _a === void 0 ? void 0 : _a.store.aiAssistant.pinnedAgentName) !== null && _b !== void 0 ? _b : null;
1340
1341
  (_c = this._sessionRef) === null || _c === void 0 ? void 0 : _c.actions.aiAssistant.setPinnedAgentName(value);
1341
1342
  (_d = this.driver) === null || _d === void 0 ? void 0 : _d.setPinnedAgent(value);
@@ -1343,6 +1344,9 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
1343
1344
  // fetch when the user pins/unpins so the prompts match the new agent.
1344
1345
  if (previous !== value) {
1345
1346
  this.logMeta(value ? 'agent.pinned' : 'agent.unpinned', { agent: value !== null && value !== void 0 ? value : previous });
1347
+ // The pin is part of the saved session, but nothing else saves when only the pin changes.
1348
+ // Without this, the last save of a turn keeps a pin that was changed after it.
1349
+ (_e = this.persister()) === null || _e === void 0 ? void 0 : _e.scheduleSave();
1346
1350
  this.suggestionsState = { status: 'idle' };
1347
1351
  this.fetchSuggestions();
1348
1352
  }
@@ -4634,29 +4638,29 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
4634
4638
  this.send();
4635
4639
  }
4636
4640
  /**
4637
- * Programmatically submit a message. Equivalent to the user typing into the
4638
- * built-in composer and pressing send, but callable from external code — most
4639
- * commonly a custom input rendered inside `slot="splash"` when paired with
4640
- * `chatConfig.ui.hideComposer`.
4641
+ * Programmatically submit a message. Sends it the way the built-in composer's
4642
+ * Send does, but from external code — a custom input rendered inside
4643
+ * `slot="splash"` when paired with `chatConfig.ui.hideComposer`, or a host
4644
+ * sending on the user's behalf.
4641
4645
  *
4642
- * The input fully describes the turn: `text` and `files` REPLACE any current
4643
- * composer state (they are not appended to it). Files are validated against
4646
+ * The input fully describes the turn: `text` and `files` are sent as given,
4647
+ * and the composer is never read or cleared, so whatever the user has typed or
4648
+ * attached there stays where it is. Files are validated against
4644
4649
  * `chatConfig.ui.acceptedFiles` using the same pipeline as the composer's
4645
- * attach button.
4650
+ * attach button. `options` routes the message — see {@link SubmitMessageOptions}.
4646
4651
  *
4647
- * Atomic on validation: if any file fails validation, no attachments are
4648
- * committed and no send is dispatched. Failure messages are returned in
4649
- * `errors` AND appended to the `attachmentErrors` observable so the built-in
4650
- * chip UI still surfaces them when visible.
4652
+ * Atomic on validation: if any file fails validation, no send is dispatched,
4653
+ * and the failure messages are returned in `errors`. They are not shown as
4654
+ * composer chips: the files are the caller's, not the user's.
4651
4655
  *
4652
- * Resolves once the underlying send has been kicked off — it does NOT await
4653
- * the assistant's response.
4656
+ * Resolves when the send settles: it awaits the driver's `sendMessage`, which
4657
+ * for the built-in drivers is the whole turn, the assistant's response included.
4654
4658
  *
4655
4659
  * @beta
4656
4660
  */
4657
- submitMessage(input) {
4661
+ submitMessage(input, options) {
4658
4662
  return __awaiter(this, void 0, void 0, function* () {
4659
- var _a, _b, _c;
4663
+ var _a, _b, _c, _d;
4660
4664
  if (this.sendBlocked) {
4661
4665
  return { ok: false, errors: [this.sendRefusalReason()] };
4662
4666
  }
@@ -4664,8 +4668,8 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
4664
4668
  if ((_a = input.files) === null || _a === void 0 ? void 0 : _a.length) {
4665
4669
  const { attachments, errors } = yield this.attachmentCtrl.process(input.files);
4666
4670
  // State may have flipped to 'loading' during the async file processing
4667
- // (e.g. a concurrent send via the composer). Re-check before committing
4668
- // any composer state. Beyond this point execution is synchronous up to
4671
+ // (e.g. a concurrent send via the composer). Re-check before sending.
4672
+ // Beyond this point execution is synchronous up to
4669
4673
  // `await this.send()`, and `send()` sets `state='loading'` before its
4670
4674
  // own first await — so no further race window exists.
4671
4675
  // (Cast widens through TS's narrowing of `this.state` from the earlier
@@ -4674,25 +4678,26 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
4674
4678
  return { ok: false, errors: [this.sendRefusalReason()] };
4675
4679
  }
4676
4680
  if (errors.length) {
4677
- this.attachmentErrors = errors;
4678
4681
  return { ok: false, errors };
4679
4682
  }
4680
4683
  nextAttachments = attachments;
4681
4684
  }
4682
- const text = ((_b = input.text) !== null && _b !== void 0 ? _b : '').trim();
4685
+ // After the file read, as the busy re-check is: `agents` may have changed during it.
4686
+ const agent = options === null || options === void 0 ? void 0 : options.agent;
4687
+ if (typeof agent === 'string' && !((_b = this.agents) !== null && _b !== void 0 ? _b : []).some((a) => a.name === agent)) {
4688
+ return { ok: false, errors: [`Unknown agent: ${agent}`] };
4689
+ }
4690
+ const text = ((_c = input.text) !== null && _c !== void 0 ? _c : '').trim();
4683
4691
  if (!text && !nextAttachments.length) {
4684
4692
  return { ok: false, errors: ['Empty message'] };
4685
4693
  }
4686
- this.inputValue = text;
4687
- this.attachments = nextAttachments;
4688
- this.attachmentErrors = [];
4689
4694
  try {
4690
- yield this.send();
4695
+ yield this.send({ text, attachments: nextAttachments }, agent !== undefined ? { agent } : undefined);
4691
4696
  return { ok: true, errors: [] };
4692
4697
  }
4693
4698
  catch (e) {
4694
4699
  logger.error('submitMessage send failed:', e);
4695
- return { ok: false, errors: [(_c = e === null || e === void 0 ? void 0 : e.message) !== null && _c !== void 0 ? _c : 'Send failed'] };
4700
+ return { ok: false, errors: [(_d = e === null || e === void 0 ? void 0 : e.message) !== null && _d !== void 0 ? _d : 'Send failed'] };
4696
4701
  }
4697
4702
  });
4698
4703
  }
@@ -4768,11 +4773,17 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
4768
4773
  }
4769
4774
  });
4770
4775
  }
4771
- send() {
4776
+ /**
4777
+ * @param message - What to send in place of the composer's contents, which are then neither
4778
+ * read nor cleared (`submitMessage`). Left out, the composer's contents are sent and cleared.
4779
+ * @param routing - Passed on to the driver: how this one message is routed.
4780
+ */
4781
+ send(message, routing) {
4772
4782
  return __awaiter(this, void 0, void 0, function* () {
4773
4783
  var _a;
4774
- const input = this.inputValue.trim();
4775
- if ((!input && !this.attachments.length) || this.sendBlocked)
4784
+ const input = message ? message.text : this.inputValue.trim();
4785
+ const attachments = message ? message.attachments : this.attachments;
4786
+ if ((!input && !attachments.length) || this.sendBlocked)
4776
4787
  return;
4777
4788
  this._pendingSendPrompt = input;
4778
4789
  // Capture the session ref before any await. If a lifecycle event occurs during
@@ -4781,8 +4792,14 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
4781
4792
  // which in turn triggers the _executionCompletionUnsub subscription on whichever
4782
4793
  // element is currently active (e.g. the collapse-mode element after docking).
4783
4794
  const capturedSessionRef = this._sessionRef;
4784
- const pendingAttachments = this.attachmentCtrl.take();
4785
- this.inputValue = '';
4795
+ let pendingAttachments;
4796
+ if (message) {
4797
+ pendingAttachments = attachments.length ? attachments : undefined;
4798
+ }
4799
+ else {
4800
+ pendingAttachments = this.attachmentCtrl.take();
4801
+ this.inputValue = '';
4802
+ }
4786
4803
  this.suggestionsState = { status: 'idle' };
4787
4804
  this._userScrolledAway = false;
4788
4805
  // Close the picker on send — the toggle button is disabled during loading,
@@ -4795,7 +4812,7 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
4795
4812
  this.startLoadingTimer();
4796
4813
  const displayInput = withAttachmentNote(input, pendingAttachments);
4797
4814
  try {
4798
- const result = yield ((_a = this.driver) === null || _a === void 0 ? void 0 : _a.sendMessage(displayInput, pendingAttachments));
4815
+ const result = yield ((_a = this.driver) === null || _a === void 0 ? void 0 : _a.sendMessage(displayInput, pendingAttachments, routing));
4799
4816
  // Latch the backend block the moment the driver reports it, so the composer
4800
4817
  // locks without waiting on the host's next pre-flight. The bus subscription
4801
4818
  // in `connectedCallback` covers most walls; this covers the one it cannot —
@@ -266,7 +266,7 @@ export const DEBUG_LOG_README = [
266
266
  'Sub-agent meta events: a sub-agent\'s own turn.retry/turn.error/tool.failed/tool.unresolved events are merged into this same timeline, tagged with `detail.subAgent` — a `"<parent> › <sub-agent>"` breadcrumb that composes when nested (e.g. `"UI Builder › Planner › Grounding"`) — and interleaved by their original timestamps within the subagent.started→completed/failed bracket. These are the per-attempt/per-failure signals that do NOT appear among the sub-agent\'s (hoisted) messages: a malformed/empty attempt that gets retried produces no message, and the stale-vs-hallucinated split and streak counts live only on the event. A sub-agent\'s high-volume, message-derivable events (turn.start/turn.end, provider.selected, context.updated) are intentionally NOT merged — read its hoisted messages for model/tokens/cost and turn-by-turn activity, and the bracketing subagent.* events for the run\'s span.',
267
267
  "`meta` holds context captured at export time: agentSummary (full agent configs), context (active model, contextTokens/contextLimit/contextUsagePercent for the last call, and the session totals — sessionCostUsd, sessionTokensConsumed, and the four-bucket sessionUsage lifted to the top of this log), activeDebugSnapshot (the active agent's `getDebugSnapshot()` taken fresh at export — reflects state NOW, which may have advanced beyond the last turn's agentSnapshot), debug (optional host-supplied debug state), host, and the export timestamp.",
268
268
  'Note the two different scopes in `meta.context`: `contextTokens` is the prompt size of the LAST call (against `contextLimit`, the model context window), while `sessionUsage`/`sessionTokensConsumed` are cumulative BILLED throughput. Every turn resends the conversation, so the cumulative figure counts each turn’s prompt again in the next turn’s and is expected to dwarf the context size — that is not double-counting.',
269
- "kind:'event' type 'routing.decided' — how ONE turn was routed, emitted by the orchestrating driver before the agent runs (and again after every handoff). `decision` is why that agent was chosen: 'classified' (the classifier ran and picked one), 'no-match' (it ran and answered -1 — nothing listed covers the request), 'ballot-exhausted' (every eligible specialist had already handed off this turn, so the ballot was empty and NO call was made — distinct from 'no-match', where one ran and declined), 'pinned' (a user pin or an active stateful flow owned the turn, so no call was made), 'single-candidate'/'no-specialists' (configuration left nothing to decide), 'provider-unavailable' (the registry default exposes no chat()), 'classifier-failed' (every attempt threw — `error` carries the last one). `to` names the agent and `fallback` says whether that agent is the fallback. `candidates` is what was actually ON THE BALLOT, in ballot order, so `index` — the classifier's own answer — indexes it directly; `excluded` names the specialists left off because they already handed off this turn, so the full eligible set is `candidates` ∪ `excluded`. `candidates` is absent on the four decisions that put nothing to a vote — 'pinned', 'single-candidate', 'no-specialists', 'ballot-exhausted'. It IS present on 'provider-unavailable', which is not an exception worth removing: the ballot was built there, it simply never got sent. `attempts` covers the retry ladder. `durationMs` is on EVERY routing.decided, and is the field to read when a decision looks wrong: the four decisions that can reach the fallback are told apart by the clock as much as by their name, because a fallback routing that resolved in tens of milliseconds made no network call at all whatever its `decision` says.",
269
+ "kind:'event' type 'routing.decided' — how ONE turn was routed, emitted by the orchestrating driver before the agent runs (and again after every handoff). `decision` is why that agent was chosen: 'classified' (the classifier ran and picked one), 'no-match' (it ran and answered -1 — nothing listed covers the request), 'ballot-exhausted' (every eligible specialist had already handed off this turn, so the ballot was empty and NO call was made — distinct from 'no-match', where one ran and declined), 'pinned' (a user pin, an agent named for that one message by the send's `agent` option, or an active stateful flow owned the turn, so no call was made), 'single-candidate'/'no-specialists' (configuration left nothing to decide), 'provider-unavailable' (the registry default exposes no chat()), 'classifier-failed' (every attempt threw — `error` carries the last one). `to` names the agent and `fallback` says whether that agent is the fallback. `candidates` is what was actually ON THE BALLOT, in ballot order, so `index` — the classifier's own answer — indexes it directly; `excluded` names the specialists left off because they already handed off this turn, so the full eligible set is `candidates` ∪ `excluded`. `candidates` is absent on the four decisions that put nothing to a vote — 'pinned', 'single-candidate', 'no-specialists', 'ballot-exhausted'. It IS present on 'provider-unavailable', which is not an exception worth removing: the ballot was built there, it simply never got sent. `attempts` covers the retry ladder. `durationMs` is on EVERY routing.decided, and is the field to read when a decision looks wrong: the four decisions that can reach the fallback are told apart by the clock as much as by their name, because a fallback routing that resolved in tens of milliseconds made no network call at all whatever its `decision` says.",
270
270
  "kind:'event' type 'routing.decided'.`usage` — what that classifier call cost, in the same four-bucket + costUsd shape as `sessionUsage`, plus `model`. Absent on the decisions that make no call (see 'pinned' and the configuration ones). THIS SPEND IS NOT IN `sessionUsage`: a classifier call never enters the transcript and `sessionUsage` is derived from the transcript, so classifier cost is missing from the session total by construction, not by accident. Sum these events to close that gap — it is the one component of a session's real spend that the totals cannot see.",
271
271
  'To debug a failure: find the last turn.error or tool.failed, then read upward for the user message, the turn(s), and the agent/provider/state events that led into it. For a turn that went to the wrong agent, read its routing.decided first — `decision` says whether anything was actually asked.',
272
272
  ];
@@ -79,6 +79,12 @@ export class SessionPersister {
79
79
  * the "boundary unmoved" skip below can never swallow the stamp itself (GENC-1511).
80
80
  */
81
81
  this._interruptedStamped = false;
82
+ /**
83
+ * The pin the current episode's frozen write carried, the other half of the "boundary
84
+ * unmoved" skip key. A pin change on its own moves no boundary, but the frozen snapshot
85
+ * still has to carry the new pin, or a reload restores the old one (GENC-1737).
86
+ */
87
+ this._frozenPinnedAgentName = null;
82
88
  /** Consecutive failed saves; reset by any success. GENC-1511. */
83
89
  this._saveFailures = 0;
84
90
  /** Whether this broken episode has already been reported to the host. */
@@ -397,7 +403,10 @@ export class SessionPersister {
397
403
  // it re-arms the moment the boundary moves, and the resumable path below clears it,
398
404
  // so it can never become the one-way "never write again" state it replaces. It also
399
405
  // drops the `provider.load` this branch used to issue on every single autosave.
400
- if (this._persistedMessages === frozen.messages.length && this._interruptedStamped) {
406
+ // The pin is part of the key too: changing it moves no boundary, but is new content.
407
+ if (this._persistedMessages === frozen.messages.length &&
408
+ this._interruptedStamped &&
409
+ this._frozenPinnedAgentName === frozen.pinnedAgentName) {
401
410
  return;
402
411
  }
403
412
  this.logMeta('persistence.suppressed', {
@@ -410,6 +419,7 @@ export class SessionPersister {
410
419
  yield provider.save(key, Object.assign(Object.assign({}, frozen), { interrupted: { message: resumeMessage, prompt: resumePrompt } }));
411
420
  this._persistedMessages = frozen.messages.length;
412
421
  this._interruptedStamped = true;
422
+ this._frozenPinnedAgentName = frozen.pinnedAgentName;
413
423
  this.recordSaveOutcome(true, '', frozen.savedAt);
414
424
  logger.debug('Flow non-resumable — froze snapshot + stamped interrupted marker', { key });
415
425
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@genesislcap/ai-assistant",
3
3
  "description": "Genesis AI Assistant micro-frontend",
4
- "version": "15.81.0",
4
+ "version": "15.82.0",
5
5
  "license": "SEE LICENSE IN license.txt",
6
6
  "main": "dist/esm/index.js",
7
7
  "types": "dist/ai-assistant.d.ts",
@@ -92,31 +92,31 @@
92
92
  }
93
93
  },
94
94
  "devDependencies": {
95
- "@genesislcap/foundation-comms": "15.81.0",
96
- "@genesislcap/foundation-testing": "15.81.0",
97
- "@genesislcap/genx": "15.81.0",
98
- "@genesislcap/ts-builder": "15.81.0",
99
- "@genesislcap/uvu-playwright-builder": "15.81.0",
100
- "@genesislcap/vite-builder": "15.81.0",
101
- "@genesislcap/webpack-builder": "15.81.0",
95
+ "@genesislcap/foundation-comms": "15.82.0",
96
+ "@genesislcap/foundation-testing": "15.82.0",
97
+ "@genesislcap/genx": "15.82.0",
98
+ "@genesislcap/ts-builder": "15.82.0",
99
+ "@genesislcap/uvu-playwright-builder": "15.82.0",
100
+ "@genesislcap/vite-builder": "15.82.0",
101
+ "@genesislcap/webpack-builder": "15.82.0",
102
102
  "@types/dompurify": "^3.0.5",
103
103
  "@types/marked": "^5.0.2",
104
104
  "esbuild": "0.25.12"
105
105
  },
106
106
  "dependencies": {
107
- "@genesislcap/foundation-ai": "15.81.0",
108
- "@genesislcap/foundation-logger": "15.81.0",
109
- "@genesislcap/foundation-notifications": "15.81.0",
110
- "@genesislcap/foundation-redux": "15.81.0",
111
- "@genesislcap/foundation-ui": "15.81.0",
112
- "@genesislcap/foundation-utils": "15.81.0",
113
- "@genesislcap/rapid-design-system": "15.81.0",
114
- "@genesislcap/web-core": "15.81.0",
107
+ "@genesislcap/foundation-ai": "15.82.0",
108
+ "@genesislcap/foundation-logger": "15.82.0",
109
+ "@genesislcap/foundation-notifications": "15.82.0",
110
+ "@genesislcap/foundation-redux": "15.82.0",
111
+ "@genesislcap/foundation-ui": "15.82.0",
112
+ "@genesislcap/foundation-utils": "15.82.0",
113
+ "@genesislcap/rapid-design-system": "15.82.0",
114
+ "@genesislcap/web-core": "15.82.0",
115
115
  "dompurify": "^3.3.1",
116
116
  "marked": "^17.0.3"
117
117
  },
118
118
  "peerDependencies": {
119
- "@genesislcap/foundation-comms": "^15.81.0"
119
+ "@genesislcap/foundation-comms": "^15.82.0"
120
120
  },
121
121
  "peerDependenciesMeta": {
122
122
  "@genesislcap/foundation-comms": {