@genesislcap/ai-assistant 15.111.4 → 15.111.5

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.
@@ -18,7 +18,7 @@ import { DEFAULT_MAX_FOLD_OPERATIONS, DEFAULT_MAX_TOOL_ITERATIONS, DEFAULT_MAX_T
18
18
  import { FoldController } from './fold-controller';
19
19
  import { IdleClock, isIdleLimit } from './idle-clock';
20
20
  import { InteractionController, } from './interaction-controller';
21
- import { TURN_FAILURE_EXITS, turnDone } from './turn-failures';
21
+ import { TURN_FAILURE_EXITS, isRefusalLike, turnDone } from './turn-failures';
22
22
  import { nestUnderSubAgent, TurnRecorder } from './turn-recorder';
23
23
  /** Re-exported so `from './chat-driver'` keeps resolving these. */
24
24
  export { EMPTY_RESPONSE_NUDGE, MALFORMED_CALL_NUDGE } from './chat-driver.constants';
@@ -400,6 +400,19 @@ export class ChatDriver extends EventTarget {
400
400
  * children costing N doomed calls plus a doomed parent one.
401
401
  */
402
402
  this.providerRefusedThisTurn = false;
403
+ /**
404
+ * Where the current turn starts in `history`: the user message `sendMessage` appends, or the
405
+ * first message a `continueFromHistory` adds. A refused turn is withdrawn from here (GENC-2045),
406
+ * not from the last user message, because a continuation adds no user message, and a driver note
407
+ * (a finish-guard or forced-tool nudge) is `role: 'user'` in the middle of a turn.
408
+ */
409
+ this.turnStartIndex = 0;
410
+ /**
411
+ * The provider refused something this turn (its own answer, a closing call, or a sub-agent's),
412
+ * so the turn is withdrawn from the provider history when it ends. Read once, in the `finally`
413
+ * of `sendMessage` and `continueFromHistory`.
414
+ */
415
+ this.withdrawTurnAtEnd = false;
403
416
  /**
404
417
  * A sub-agent was refused by the AI service this turn in a way that stops this driver too
405
418
  * (GENC-1611): a service-wide code, from the vendor this driver calls. Sub-agent path only, like
@@ -2119,6 +2132,8 @@ export class ChatDriver extends EventTarget {
2119
2132
  this.aiServiceWall = undefined;
2120
2133
  this.aiServiceNoticesShown.clear();
2121
2134
  this.aiServiceNoticesQueued = [];
2135
+ this.withdrawTurnAtEnd = false;
2136
+ this.turnStartIndex = this.history.length;
2122
2137
  this.appendToHistory(Object.assign({ role: 'user', content: userInput, attachments }, delegatedFields(options)));
2123
2138
  this.turnStartedAt = Date.now();
2124
2139
  recordMetaEvent(this.sessionKey, 'turn.start', {
@@ -2155,6 +2170,7 @@ export class ChatDriver extends EventTarget {
2155
2170
  });
2156
2171
  this.busy = false;
2157
2172
  this.endTurn();
2173
+ this.withdrawRefusedTurn();
2158
2174
  this.activityBus.publish('tool-loop-end', this.loopEndDetail(result));
2159
2175
  // In `finally` rather than on the success path: the agent asked to be released, and a turn
2160
2176
  // that later threw does not make its flow any less finished.
@@ -2577,6 +2593,7 @@ export class ChatDriver extends EventTarget {
2577
2593
  this.providerRefusedThisTurn = true;
2578
2594
  (_f = this.providerRefusedDetail) !== null && _f !== void 0 ? _f : (this.providerRefusedDetail = failure === null || failure === void 0 ? void 0 : failure.providerRefused);
2579
2595
  }
2596
+ this.noteChildRefusal(reason);
2580
2597
  // The AI SERVICE wall via a child (GENC-1611). It stops this driver too only when this driver's
2581
2598
  // next call would get the same answer: a refusal about the service rather than the child's own
2582
2599
  // request, from the vendor this driver calls. Otherwise the handler gets the failure and the
@@ -2649,6 +2666,9 @@ export class ChatDriver extends EventTarget {
2649
2666
  this.providerRefusedDetail = undefined;
2650
2667
  this.aiServiceErrorThisTurn = false;
2651
2668
  this.aiServiceWall = undefined;
2669
+ this.withdrawTurnAtEnd = false;
2670
+ if (!(options === null || options === void 0 ? void 0 : options.sameUserTurn))
2671
+ this.turnStartIndex = this.history.length;
2652
2672
  this.turnStartedAt = Date.now();
2653
2673
  recordMetaEvent(this.sessionKey, 'turn.start', {
2654
2674
  phase: 'continueFromHistory',
@@ -2684,6 +2704,7 @@ export class ChatDriver extends EventTarget {
2684
2704
  });
2685
2705
  this.busy = false;
2686
2706
  this.endTurn();
2707
+ this.withdrawRefusedTurn();
2687
2708
  this.activityBus.publish('tool-loop-end', this.loopEndDetail(result));
2688
2709
  // In `finally` rather than on the success path: the agent asked to be released, and a turn
2689
2710
  // that later threw does not make its flow any less finished.
@@ -2701,7 +2722,7 @@ export class ChatDriver extends EventTarget {
2701
2722
  // oxlint-disable-next-line complexity, max-lines-per-function
2702
2723
  runToolLoop(userInput, attachments, transientPrimer, tailNote) {
2703
2724
  return __awaiter(this, void 0, void 0, function* () {
2704
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
2725
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
2705
2726
  if (!this.systemPrompt) {
2706
2727
  logger.warn('ChatDriver: no systemPrompt set. The assistant will have no instructions — provide a systemPrompt via agents config or the foundation-ai-assistant property.');
2707
2728
  }
@@ -3255,6 +3276,12 @@ export class ChatDriver extends EventTarget {
3255
3276
  // fallback chain answered on a different model than the one we asked for.
3256
3277
  if (response.model !== undefined)
3257
3278
  turnSnapshot.model = response.model;
3279
+ // A refusal is about what this turn sent, and the next prompt would send it again: every
3280
+ // later turn in the conversation was refused too (GENC-2045). Whichever way it arrives (an
3281
+ // empty answer, text that stopped part way, a closing call) the turn is withdrawn from what
3282
+ // the provider is sent when it ends.
3283
+ if (isRefusalLike(response.responseMeta))
3284
+ this.withdrawTurnAtEnd = true;
3258
3285
  if (closing) {
3259
3286
  // What it tried to call is not run, on a transport that ignores `toolChoice` too. Saying
3260
3287
  // nothing is fine, a refusal included: no failure that would hold the hand-off up.
@@ -3271,7 +3298,7 @@ export class ChatDriver extends EventTarget {
3271
3298
  // MAX_EMPTY_RESPONSE_RETRIES turns on the most expensive models for the same outcome, ending
3272
3299
  // in the misleading "blank response" message. Treat it as a terminal, non-retried failure with
3273
3300
  // its own reason and message. (GENC-1461)
3274
- const isRefusal = ((_m = response.responseMeta) === null || _m === void 0 ? void 0 : _m.finishReason) === 'refusal';
3301
+ const isRefusal = isRefusalLike(response.responseMeta);
3275
3302
  if (isEmptyResponse) {
3276
3303
  emptyResponseAttempts += 1;
3277
3304
  if (!isRefusal && emptyResponseAttempts < MAX_EMPTY_RESPONSE_RETRIES) {
@@ -3286,6 +3313,8 @@ export class ChatDriver extends EventTarget {
3286
3313
  continue;
3287
3314
  }
3288
3315
  const exit = isRefusal ? TURN_FAILURE_EXITS.refusal : TURN_FAILURE_EXITS.emptyResponse;
3316
+ if (isRefusal)
3317
+ this.withdrawTurnAtEnd = true;
3289
3318
  logger.error(isRefusal
3290
3319
  ? 'ChatDriver: model refused the request (safety decline) — not retrying'
3291
3320
  : 'ChatDriver: empty model response after all retries');
@@ -3347,7 +3376,7 @@ export class ChatDriver extends EventTarget {
3347
3376
  setupTransportAttempts = 0;
3348
3377
  if (closing)
3349
3378
  return turnDone();
3350
- if (!((_o = response.toolCalls) === null || _o === void 0 ? void 0 : _o.length)) {
3379
+ if (!((_m = response.toolCalls) === null || _m === void 0 ? void 0 : _m.length)) {
3351
3380
  // The model ended in prose. The agent's finish guard may hold the turn open (a note stored
3352
3381
  // in history, then the next call) or end it and release the agent. Consulted on the loop's
3353
3382
  // last iteration too, since a release needs no further call; only a hold is refused there.
@@ -3359,7 +3388,7 @@ export class ChatDriver extends EventTarget {
3359
3388
  !this.handOffRequested;
3360
3389
  const verdict = guarded
3361
3390
  ? // oxlint-disable-next-line no-await-in-loop
3362
- yield this.consultFinishGuard(Object.assign(Object.assign({}, promptCtx), { history: this.history, reply: (_p = response.content) !== null && _p !== void 0 ? _p : '', continuations: finishGuardContinuations, canContinue }))
3391
+ yield this.consultFinishGuard(Object.assign(Object.assign({}, promptCtx), { history: this.history, reply: (_o = response.content) !== null && _o !== void 0 ? _o : '', continuations: finishGuardContinuations, canContinue }))
3363
3392
  : undefined;
3364
3393
  // A Stop pressed while the guard was pending wins over its verdict, whatever it was (a guard
3365
3394
  // that threw on the aborted signal included), so the turn ends with the usual stop marker.
@@ -3380,7 +3409,7 @@ export class ChatDriver extends EventTarget {
3380
3409
  continue;
3381
3410
  }
3382
3411
  if ((verdict === null || verdict === void 0 ? void 0 : verdict.action) === 'continue') {
3383
- logger.warn(`ChatDriver(${(_q = this.activeAgentName) !== null && _q !== void 0 ? _q : 'unknown'}): finishGuard answered 'continue' on the last tool-loop iteration — ending the turn`);
3412
+ logger.warn(`ChatDriver(${(_p = this.activeAgentName) !== null && _p !== void 0 ? _p : 'unknown'}): finishGuard answered 'continue' on the last tool-loop iteration — ending the turn`);
3384
3413
  }
3385
3414
  // A sub-agent returns its result only through `completeSubAgent`, so its prose is never an
3386
3415
  // answer. With no verdict from its own guard (`'end'` is the guard giving up), the driver
@@ -3406,7 +3435,7 @@ export class ChatDriver extends EventTarget {
3406
3435
  if (!this.isSubAgent &&
3407
3436
  verdict === undefined &&
3408
3437
  canContinue &&
3409
- ((_r = response.responseMeta) === null || _r === void 0 ? void 0 : _r.toolChoiceDowngraded) &&
3438
+ ((_q = response.responseMeta) === null || _q === void 0 ? void 0 : _q.toolChoiceDowngraded) &&
3410
3439
  forcedToolNudges < MAX_FORCED_TOOL_NUDGES) {
3411
3440
  forcedToolNudges += 1;
3412
3441
  recordMetaEvent(this.sessionKey, 'turn.finish-guard', {
@@ -3434,7 +3463,7 @@ export class ChatDriver extends EventTarget {
3434
3463
  // Only when X is advertised directly: a pin on a tool behind a fold is reached by opening it.
3435
3464
  let refusePinnedMiss = false;
3436
3465
  if (pinnedTool &&
3437
- ((_s = response.responseMeta) === null || _s === void 0 ? void 0 : _s.toolChoiceDowngraded) &&
3466
+ ((_r = response.responseMeta) === null || _r === void 0 ? void 0 : _r.toolChoiceDowngraded) &&
3438
3467
  toolCalls.length > 0 &&
3439
3468
  this.toolHandlers[pinnedTool] &&
3440
3469
  !toolCalls.some((tc) => tc.name === pinnedTool)) {
@@ -3463,7 +3492,7 @@ export class ChatDriver extends EventTarget {
3463
3492
  // model that keeps ignoring the instruction still runs out, but one stray miss early in a long
3464
3493
  // turn (the UI Builder's `generating` turn runs many forced iterations) does not switch the
3465
3494
  // nudges and refusals off for the rest of it.
3466
- if (((_t = response.responseMeta) === null || _t === void 0 ? void 0 : _t.toolChoiceDowngraded) &&
3495
+ if (((_s = response.responseMeta) === null || _s === void 0 ? void 0 : _s.toolChoiceDowngraded) &&
3467
3496
  toolCalls.length > 0 &&
3468
3497
  (!pinnedTool || toolCalls.some((tc) => tc.name === pinnedTool))) {
3469
3498
  if (this.isSubAgent)
@@ -3691,7 +3720,7 @@ export class ChatDriver extends EventTarget {
3691
3720
  // The response was appended before execution — find it and annotate.
3692
3721
  let tcMsgIdx = -1;
3693
3722
  for (let i = this.history.length - 1; i >= 0; i -= 1) {
3694
- if (this.history[i].role === 'assistant' && ((_u = this.history[i].toolCalls) === null || _u === void 0 ? void 0 : _u.length)) {
3723
+ if (this.history[i].role === 'assistant' && ((_t = this.history[i].toolCalls) === null || _t === void 0 ? void 0 : _t.length)) {
3695
3724
  tcMsgIdx = i;
3696
3725
  break;
3697
3726
  }
@@ -3729,7 +3758,7 @@ export class ChatDriver extends EventTarget {
3729
3758
  const unknownTools = [
3730
3759
  ...new Set([
3731
3760
  ...this.recentUnknownToolNames,
3732
- ...((_v = response.toolCalls) !== null && _v !== void 0 ? _v : [])
3761
+ ...((_u = response.toolCalls) !== null && _u !== void 0 ? _u : [])
3733
3762
  .filter((tc) => unknownToolIds.has(tc.id))
3734
3763
  .map((tc) => tc.name),
3735
3764
  ]),
@@ -3741,7 +3770,7 @@ export class ChatDriver extends EventTarget {
3741
3770
  const staleTools = [
3742
3771
  ...new Set([
3743
3772
  ...this.recentStaleToolNames,
3744
- ...((_w = response.toolCalls) !== null && _w !== void 0 ? _w : [])
3773
+ ...((_v = response.toolCalls) !== null && _v !== void 0 ? _v : [])
3745
3774
  .filter((tc) => staleToolIds.has(tc.id))
3746
3775
  .map((tc) => tc.name),
3747
3776
  ]),
@@ -3814,6 +3843,40 @@ export class ChatDriver extends EventTarget {
3814
3843
  appendDriverNotice(content) {
3815
3844
  this.appendToHistory({ role: 'assistant', content, excludeFromProvider: true });
3816
3845
  }
3846
+ /**
3847
+ * A child the model refused (GENC-2045). It was handed this driver's history, so the refused
3848
+ * content is in the parent's history too, and every later delegation would inherit it and be
3849
+ * refused again. The turn goes on, since the handler may recover, and is withdrawn when it ends.
3850
+ * A method of its own to keep `invokeSubAgent` under the complexity ceiling.
3851
+ */
3852
+ noteChildRefusal(reason) {
3853
+ if (reason === 'refusal')
3854
+ this.withdrawTurnAtEnd = true;
3855
+ }
3856
+ /**
3857
+ * Withdraws the turn that just ended from what the provider is sent, when the provider refused
3858
+ * something in it (GENC-2045). Flags every message from the turn's start `excludeFromProvider`,
3859
+ * so the next request no longer carries what was refused. The turn's tool calls and results are
3860
+ * flagged together, so none is left without the other. Nothing is removed from the history: the
3861
+ * UI and the debug log still show the turn.
3862
+ *
3863
+ * The cost: the model's next turn has no record of what the withdrawn turn did. A tool it ran
3864
+ * (a file written, a state transition, an interaction the user answered) has taken effect, but
3865
+ * the model is not told. It may repeat that work, or contradict what is on screen. A short note
3866
+ * of the completed tools would have to reach the provider as a message of its own, with the role
3867
+ * alternation that implies, so it is not done here. The refused content is what must not be sent.
3868
+ *
3869
+ * Only the top-level driver does this. A sub-agent that is refused reports `refusal` to its
3870
+ * parent (`invokeSubAgent`), which withdraws its own turn.
3871
+ */
3872
+ withdrawRefusedTurn() {
3873
+ if (!this.withdrawTurnAtEnd || this.isSubAgent)
3874
+ return;
3875
+ this.withdrawTurnAtEnd = false;
3876
+ const start = Math.min(this.turnStartIndex, this.history.length);
3877
+ this.history = this.history.map((m, i) => i >= start && !m.excludeFromProvider ? Object.assign(Object.assign({}, m), { excludeFromProvider: true }) : m);
3878
+ this.notifyHistoryUpdated();
3879
+ }
3817
3880
  appendToHistory(message) {
3818
3881
  var _a;
3819
3882
  const tagged = Object.assign(Object.assign(Object.assign({}, message), {
@@ -57,7 +57,7 @@ export const TURN_FAILURE_EXITS = {
57
57
  refusal: {
58
58
  subReason: 'refusal',
59
59
  resultReason: 'refusal',
60
- copy: 'This request was declined. Try rephrasing it, or breaking it into smaller steps.',
60
+ copy: "The AI provider declined this request. It won't be sent again with your next messages. If replies keep being declined, start a new conversation.",
61
61
  },
62
62
  emptyResponse: {
63
63
  subReason: 'empty_response',
@@ -103,3 +103,29 @@ export function turnDone(failureReason, budget, providerRefused) {
103
103
  return { reason: 'done' };
104
104
  return Object.assign(Object.assign({ reason: 'done', failureReason }, (budget ? { budget } : {})), (providerRefused ? { providerRefused } : {}));
105
105
  }
106
+ /**
107
+ * Finish reasons that mean the provider declined to answer: Anthropic `refusal`, OpenAI
108
+ * `content_filter`, Gemini's safety stops. Matched case-insensitively, since vendors differ.
109
+ */
110
+ const REFUSAL_FINISH_REASONS = new Set([
111
+ 'refusal',
112
+ 'content_filter',
113
+ 'safety',
114
+ 'prohibited_content',
115
+ 'blocklist',
116
+ 'spii',
117
+ 'image_safety',
118
+ ]);
119
+ /**
120
+ * True when a response was declined by the provider rather than generated (GENC-2045). Such a
121
+ * decline is deterministic: the request would be refused again, so it is neither retried nor left
122
+ * in the history the next request is built from. Checked whether or not the response has content,
123
+ * because a refusal can arrive after some output.
124
+ */
125
+ export function isRefusalLike(meta) {
126
+ if (!meta)
127
+ return false;
128
+ if (meta.blockReason)
129
+ return true;
130
+ return !!meta.finishReason && REFUSAL_FINISH_REASONS.has(meta.finishReason.toLowerCase());
131
+ }
@@ -381,7 +381,10 @@ export class OrchestratingDriver extends BaseDriverDecorator {
381
381
  let tailNote = yield this.afterAgentCall();
382
382
  while (tailNote !== undefined && !this.cancelled && !last.failureReason) {
383
383
  // oxlint-disable-next-line no-await-in-loop
384
- last = yield this.chatDriver.continueFromHistory(undefined, { tailNote });
384
+ last = yield this.chatDriver.continueFromHistory(undefined, {
385
+ tailNote,
386
+ sameUserTurn: true,
387
+ });
385
388
  // oxlint-disable-next-line no-await-in-loop
386
389
  tailNote = yield this.afterAgentCall();
387
390
  }
@@ -263,6 +263,7 @@ export const DEBUG_LOG_README = [
263
263
  "kind:'message' — the conversation. `role` is user/assistant/tool/system-event/synthetic-user; `agentName` says which agent produced it; `toolCalls`/`toolResult`/`interaction` carry tool and widget activity; `inputTokens`/`outputTokens`/`cost` are per-message LLM usage, where `inputTokens` is the WHOLE prompt for that request and `cacheReadTokens`/`cacheWriteTokens` BREAK IT DOWN rather than add to it — uncached input is `inputTokens` minus those two, and adding the cache fields to `inputTokens` counts the prompt twice. The cache fields are absent on providers that report no cache split (Gemini reports reads only, since implicit caching bills no write) and on messages persisted before they existed, so read them as 0 when missing. Each bucket bills at a different rate — cache reads a fraction of uncached input, cache writes a premium, output highest — so a large token count at a small cost means the prompt was mostly cache hits. `externalCostUsd` is any non-LLM cost a widget reported for its own external service calls (folded into the session cost total alongside `cost`). On model-produced assistant messages, `model` is the concrete model id that generated it (e.g. 'gemini-2.5-flash-lite') and `providerName` is the registry slot it resolved under (e.g. a tier name like 'high'/'low', or the default); together they attribute the message — and any tool calls it carries — to an exact model even across a mid-session vendor/tier switch, where one slot name can map to different models before and after the switch. Both are undefined on any entry that is NOT an LLM response: non-assistant roles (user/tool/system-event) and 'synthetic-user' echoes; assistant interaction/widget entries (empty content carrying an `interaction` — a rendered widget, not a model turn); driver-authored assistant fallbacks (the timeout, repeated-malformed-call, and empty-response apology messages); and messages restored from a session persisted before these fields existed. One partial case: on a genuine model turn whose provider exposes no `getStatus` (or reports no model), `providerName` is still set but `model` alone is undefined. A 'synthetic-user' message is a display-only echo of an interaction outcome (e.g. the answer a widget reported): it renders on the user's side of the chat and `agentName` is the agent that created it, but it is never sent to the LLM — so it has no matching 'turn' and the model learns the outcome only from the corresponding tool result. An echo of an answer an interceptor (such as an autopilot) gave is NOT synthetic-user: see the delegated-messages paragraph.",
264
264
  'The autopilot (GENC-1660) runs on a driver of its own, and everything it did is harvested into this log: entries with delegate: autopilot and an agentName ending in › Autopilot are its turns (the decision message it was sent is the user message of its turn, so what it was shown is there verbatim; its systemPrompt is its grounding, such as the brief), its tool calls (widget_read, widget_act, hand_back, any read-only tools of its own, and its widget tools — reads with parameters that a widget type declares, routed to the interaction of that type being decided and refused with a reason when none is, offered on every decision so its tool list never changes; while one is open its tail starts with a line naming them) and their results (a read, view or widget tool, is capped at about 20,000 characters, cut with a note asking for less, and leaves its history at the end of the decision as a one-line note), and its own events. Its cost is already in the session total: it is booked as externalCostUsd on the interaction each decision answered, or, for a written question it answered, on the user message it sent on the user behalf (delegate: autopilot), so do not add its turns to that total. Spend that reached no message is recorded as autopilot.cost-dropped instead.',
265
265
  "Delegated messages (GENC-1660): a message with a `delegate` field was written or sent ON THE USER'S BEHALF by a driver decorator, and `delegate` names it (e.g. autopilot). The platform stamps it; nothing else can. It renders as the assistant whatever its role. A delegated `user` message was NOT typed by the user: it is an answer given on their behalf, and the model read it with `delegateFraming` in brackets in front of the content (the stored `content` is the bare text). A delegated `assistant` message is display-only (`excludeFromProvider`): the decorator's narration note, or, when its answer carried no note, the widget's own echo of the answer (its `userMessage`), shown as the assistant and never as the person. A widget answer a decorator gave with a note is not echoed at all: the note already says what was chosen. To tell what the person decided from what was decided for them, read `interaction.answeredBy` and these fields, never the role alone. Driver notes: a `user` message with a `driverNote` field was written by the driver for the model, never by the user, and is hidden from the transcript; `driverNote: 'finish-guard'` is the agent's finishGuard holding the turn open after a prose reply, its content the guard's note in a `<system-reminder>`, and it follows a turn.finish-guard event; `driverNote: 'completion-nudge'` is the driver asking a sub-agent that replied in prose to call its completion tool; `driverNote: 'forced-tool-nudge'` is the driver asking a parent agent for the tool call its forced turn required, after a model that rejects forcing (responseMeta.toolChoiceDowngraded) replied in prose.",
266
+ "`excludeFromProvider` (GENC-2045): the message is in this log and the transcript, but was NOT sent to the model. The driver's own notices carry it, and so does a turn the provider refused: the user's prompt, and the tool calls and results that followed it, so one refusal is not sent again with every later request. A flagged `user` message is something the user really said; it just no longer reaches the model.",
266
267
  "Sub-agent messages appear inline. When a tool delegates to a sub-agent (via `requestSubAgent`), the sub-agent's whole conversation — its own assistant/tool messages, each with their own `content`/`thinking`/`toolCalls`/`toolResult` and per-message `model`/`providerName`/`inputTokens`/`outputTokens`/`cacheReadTokens`/`cacheWriteTokens`/`cost` — is hoisted into the timeline as ordinary kind:'message' entries, interleaved by timestamp right after the tool call that spawned them (so you read the delegation top-to-bottom). A hoisted entry is marked: `subAgentDepth` is its delegation depth (1 for a sub-agent, 2 for a sub-agent's sub-agent, …), `subAgentOf` is the id of the parent tool call that spawned it (correlates it back even when two sub-agents run in one parent turn), `subAgentName` is the sub-agent's own name, and `agentName` is rewritten to a `\"<parent> › <sub-agent>\"` breadcrumb (composing when nested, e.g. `\"UI Builder › Planner › Grounding\"`). The sub-agent's per-LLM-call snapshots also surface as kind:'turn' entries with a `<parentTurn>-<subAgentNo>.<childTurn>` `turnIndex` (see the kind:'turn' paragraph), and subagent.started/completed (or subagent.failed) events bracket the run. Per-message `cost` on hoisted entries is already part of the session total (it is summed from the un-flattened history), so summing the top-level timeline does NOT double-count.",
267
268
  "kind:'turn' — one LLM call. `turnIndex` is a string: a top-level turn is the bare counter ('0', '1', …); a sub-agent's turns are labelled '<parentTurn>-<subAgentNo>.<childTurn>': the parent turn that activated it, the sub-agent's number (1-based, in the order the sub-agents started within that parent turn, so it matches the order of the subagent.started events; two sub-agents in one parent turn never share a number, even when they run in parallel or share a name), and the sub-agent's own turn position (1-based) — e.g. '3-2.1', '3-2.2' are the first two turns of the second sub-agent started in parent turn 3, and a sub-agent nested under its turn '3-2.2' contributes '3-2.2-1.1', … ('.' joins the parts of one level, '-' separates levels). The `<parentTurn>-<subAgentNo>` part is the sub-agent's `turnPrefix`: the same value is stamped on its subagent.started/completed/failed events and on its harvested events as `detail.turnPrefix`, so match events to turns by value (a turn belongs to the sub-agent whose `turnPrefix` its `turnIndex` begins with) — and `agentName` names the agent that ran the turn. `systemPrompt` and `toolNames` are what the model saw. A systemPrompt of '<repeated — identical to turn N>' was byte-identical to turn N and de-duplicated; the full prompt is shown whenever it changes (often because a stateful agent advanced), so prompt evolution is visible.",
268
269
  "kind:'turn'.`model`/`providerName`/`provider` — which model ran that call: the concrete model id, the registry slot it resolved under (a tier name like 'high'/'low', or the default), and the vendor. Recorded per CALL, so an agent whose `provider` selector varies by state — a flow that plans on a high tier and executes on a low one — has every step attributed, including calls that produced no message. `model` is the SERVING model where the provider reports one, so a turn answered by a server-side fallback names the model that answered rather than the one requested; it always matches the `model` on the message that call produced. Absent when the provider exposes no `getStatus` and the transport stamped nothing.",
@@ -12,7 +12,9 @@ import { isUserUtterance } from './driver-note';
12
12
  export function freshUserMessages(toCompact) {
13
13
  return toCompact.flatMap((m) => {
14
14
  var _a;
15
- return isUserUtterance(m) && ((_a = m.content) === null || _a === void 0 ? void 0 : _a.trim())
15
+ // A prompt the provider refused is withdrawn (`excludeFromProvider`); keeping it here would put
16
+ // it back in the request word for word (GENC-2045).
17
+ return isUserUtterance(m) && !m.excludeFromProvider && ((_a = m.content) === null || _a === void 0 ? void 0 : _a.trim())
16
18
  ? [
17
19
  Object.assign(Object.assign({ content: m.content }, (m.timestamp ? { timestamp: m.timestamp } : {})), (m.delegate ? { delegate: m.delegate, delegateFraming: m.delegateFraming } : {})),
18
20
  ]
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.111.4",
4
+ "version": "15.111.5",
5
5
  "license": "SEE LICENSE IN license.txt",
6
6
  "main": "dist/esm/index.js",
7
7
  "types": "dist/dts/index.d.ts",
@@ -102,31 +102,31 @@
102
102
  }
103
103
  },
104
104
  "devDependencies": {
105
- "@genesislcap/foundation-comms": "15.111.4",
106
- "@genesislcap/foundation-testing": "15.111.4",
107
- "@genesislcap/genx": "15.111.4",
108
- "@genesislcap/ts-builder": "15.111.4",
109
- "@genesislcap/uvu-playwright-builder": "15.111.4",
110
- "@genesislcap/vite-builder": "15.111.4",
111
- "@genesislcap/webpack-builder": "15.111.4",
105
+ "@genesislcap/foundation-comms": "15.111.5",
106
+ "@genesislcap/foundation-testing": "15.111.5",
107
+ "@genesislcap/genx": "15.111.5",
108
+ "@genesislcap/ts-builder": "15.111.5",
109
+ "@genesislcap/uvu-playwright-builder": "15.111.5",
110
+ "@genesislcap/vite-builder": "15.111.5",
111
+ "@genesislcap/webpack-builder": "15.111.5",
112
112
  "@types/dompurify": "^3.0.5",
113
113
  "@types/marked": "^5.0.2",
114
114
  "esbuild": "0.25.12"
115
115
  },
116
116
  "dependencies": {
117
- "@genesislcap/foundation-ai": "15.111.4",
118
- "@genesislcap/foundation-logger": "15.111.4",
119
- "@genesislcap/foundation-notifications": "15.111.4",
120
- "@genesislcap/foundation-redux": "15.111.4",
121
- "@genesislcap/foundation-ui": "15.111.4",
122
- "@genesislcap/foundation-utils": "15.111.4",
123
- "@genesislcap/rapid-design-system": "15.111.4",
124
- "@genesislcap/web-core": "15.111.4",
117
+ "@genesislcap/foundation-ai": "15.111.5",
118
+ "@genesislcap/foundation-logger": "15.111.5",
119
+ "@genesislcap/foundation-notifications": "15.111.5",
120
+ "@genesislcap/foundation-redux": "15.111.5",
121
+ "@genesislcap/foundation-ui": "15.111.5",
122
+ "@genesislcap/foundation-utils": "15.111.5",
123
+ "@genesislcap/rapid-design-system": "15.111.5",
124
+ "@genesislcap/web-core": "15.111.5",
125
125
  "dompurify": "^3.3.1",
126
126
  "marked": "^17.0.3"
127
127
  },
128
128
  "peerDependencies": {
129
- "@genesislcap/foundation-comms": "15.111.4"
129
+ "@genesislcap/foundation-comms": "15.111.5"
130
130
  },
131
131
  "peerDependenciesMeta": {
132
132
  "@genesislcap/foundation-comms": {