@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.
- package/dist/ai-assistant.api.json +27 -0
- package/dist/ai-assistant.d.ts +44 -0
- package/dist/chat-driver.cjs +89 -10
- package/dist/chat-driver.cjs.map +2 -2
- package/dist/chat-driver.mjs +89 -10
- package/dist/chat-driver.mjs.map +2 -2
- package/dist/custom-elements.json +78 -2
- package/dist/dts/autopilot/decision-message.d.ts.map +1 -1
- package/dist/dts/components/chat-driver/chat-driver.d.ts +44 -0
- package/dist/dts/components/chat-driver/chat-driver.d.ts.map +1 -1
- package/dist/dts/components/chat-driver/turn-failures.d.ts +10 -0
- package/dist/dts/components/chat-driver/turn-failures.d.ts.map +1 -1
- package/dist/dts/components/orchestrating-driver/orchestrating-driver.d.ts.map +1 -1
- package/dist/dts/state/debug-event-log.d.ts.map +1 -1
- package/dist/dts/utils/preserved-user-messages.d.ts.map +1 -1
- package/dist/esm/autopilot/decision-message.js +2 -0
- package/dist/esm/components/chat-driver/chat-driver.js +75 -12
- package/dist/esm/components/chat-driver/turn-failures.js +27 -1
- package/dist/esm/components/orchestrating-driver/orchestrating-driver.js +4 -1
- package/dist/esm/state/debug-event-log.js +1 -0
- package/dist/esm/utils/preserved-user-messages.js +3 -1
- package/package.json +17 -17
package/dist/chat-driver.mjs
CHANGED
|
@@ -5250,6 +5250,7 @@ var DEBUG_LOG_README = [
|
|
|
5250
5250
|
"kind:'message' \u2014 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 \u2014 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 \u2014 cache reads a fraction of uncached input, cache writes a premium, output highest \u2014 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 \u2014 and any tool calls it carries \u2014 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` \u2014 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 \u2014 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.",
|
|
5251
5251
|
"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 \u203A 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 \u2014 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.",
|
|
5252
5252
|
"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.",
|
|
5253
|
+
"`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.",
|
|
5253
5254
|
"Sub-agent messages appear inline. When a tool delegates to a sub-agent (via `requestSubAgent`), the sub-agent's whole conversation \u2014 its own assistant/tool messages, each with their own `content`/`thinking`/`toolCalls`/`toolResult` and per-message `model`/`providerName`/`inputTokens`/`outputTokens`/`cacheReadTokens`/`cacheWriteTokens`/`cost` \u2014 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, \u2026), `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> \u203A <sub-agent>\"` breadcrumb (composing when nested, e.g. `\"UI Builder \u203A Planner \u203A 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.",
|
|
5254
5255
|
"kind:'turn' \u2014 one LLM call. `turnIndex` is a string: a top-level turn is the bare counter ('0', '1', \u2026); 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) \u2014 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', \u2026 ('.' 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) \u2014 and `agentName` names the agent that ran the turn. `systemPrompt` and `toolNames` are what the model saw. A systemPrompt of '<repeated \u2014 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.",
|
|
5255
5256
|
"kind:'turn'.`model`/`providerName`/`provider` \u2014 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 \u2014 a flow that plans on a high tier and executes on a low one \u2014 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.",
|
|
@@ -5299,13 +5300,17 @@ ${note.trim()}
|
|
|
5299
5300
|
// src/utils/preserved-user-messages.ts
|
|
5300
5301
|
function freshUserMessages(toCompact) {
|
|
5301
5302
|
return toCompact.flatMap(
|
|
5302
|
-
(m) =>
|
|
5303
|
-
|
|
5304
|
-
|
|
5305
|
-
|
|
5306
|
-
|
|
5307
|
-
|
|
5308
|
-
|
|
5303
|
+
(m) => (
|
|
5304
|
+
// A prompt the provider refused is withdrawn (`excludeFromProvider`); keeping it here would put
|
|
5305
|
+
// it back in the request word for word (GENC-2045).
|
|
5306
|
+
isUserUtterance(m) && !m.excludeFromProvider && m.content?.trim() ? [
|
|
5307
|
+
{
|
|
5308
|
+
content: m.content,
|
|
5309
|
+
...m.timestamp ? { timestamp: m.timestamp } : {},
|
|
5310
|
+
...m.delegate ? { delegate: m.delegate, delegateFraming: m.delegateFraming } : {}
|
|
5311
|
+
}
|
|
5312
|
+
] : []
|
|
5313
|
+
)
|
|
5309
5314
|
);
|
|
5310
5315
|
}
|
|
5311
5316
|
var preservedUserLine = (u) => `User: ${u.delegate ? frameDelegatedContent(u.content, u.delegateFraming) : u.content}`;
|
|
@@ -7961,7 +7966,7 @@ var TURN_FAILURE_EXITS = {
|
|
|
7961
7966
|
refusal: {
|
|
7962
7967
|
subReason: "refusal",
|
|
7963
7968
|
resultReason: "refusal",
|
|
7964
|
-
copy: "
|
|
7969
|
+
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."
|
|
7965
7970
|
},
|
|
7966
7971
|
emptyResponse: {
|
|
7967
7972
|
subReason: "empty_response",
|
|
@@ -8002,6 +8007,20 @@ function turnDone(failureReason, budget, providerRefused) {
|
|
|
8002
8007
|
...providerRefused ? { providerRefused } : {}
|
|
8003
8008
|
};
|
|
8004
8009
|
}
|
|
8010
|
+
var REFUSAL_FINISH_REASONS = /* @__PURE__ */ new Set([
|
|
8011
|
+
"refusal",
|
|
8012
|
+
"content_filter",
|
|
8013
|
+
"safety",
|
|
8014
|
+
"prohibited_content",
|
|
8015
|
+
"blocklist",
|
|
8016
|
+
"spii",
|
|
8017
|
+
"image_safety"
|
|
8018
|
+
]);
|
|
8019
|
+
function isRefusalLike(meta) {
|
|
8020
|
+
if (!meta) return false;
|
|
8021
|
+
if (meta.blockReason) return true;
|
|
8022
|
+
return !!meta.finishReason && REFUSAL_FINISH_REASONS.has(meta.finishReason.toLowerCase());
|
|
8023
|
+
}
|
|
8005
8024
|
|
|
8006
8025
|
// src/components/chat-driver/turn-recorder.ts
|
|
8007
8026
|
function nestUnderSubAgent(prefix, key) {
|
|
@@ -8486,6 +8505,19 @@ var ChatDriver = class _ChatDriver extends EventTarget {
|
|
|
8486
8505
|
* children costing N doomed calls plus a doomed parent one.
|
|
8487
8506
|
*/
|
|
8488
8507
|
this.providerRefusedThisTurn = false;
|
|
8508
|
+
/**
|
|
8509
|
+
* Where the current turn starts in `history`: the user message `sendMessage` appends, or the
|
|
8510
|
+
* first message a `continueFromHistory` adds. A refused turn is withdrawn from here (GENC-2045),
|
|
8511
|
+
* not from the last user message, because a continuation adds no user message, and a driver note
|
|
8512
|
+
* (a finish-guard or forced-tool nudge) is `role: 'user'` in the middle of a turn.
|
|
8513
|
+
*/
|
|
8514
|
+
this.turnStartIndex = 0;
|
|
8515
|
+
/**
|
|
8516
|
+
* The provider refused something this turn (its own answer, a closing call, or a sub-agent's),
|
|
8517
|
+
* so the turn is withdrawn from the provider history when it ends. Read once, in the `finally`
|
|
8518
|
+
* of `sendMessage` and `continueFromHistory`.
|
|
8519
|
+
*/
|
|
8520
|
+
this.withdrawTurnAtEnd = false;
|
|
8489
8521
|
/**
|
|
8490
8522
|
* A sub-agent was refused by the AI service this turn in a way that stops this driver too
|
|
8491
8523
|
* (GENC-1611): a service-wide code, from the vendor this driver calls. Sub-agent path only, like
|
|
@@ -10013,6 +10045,8 @@ var ChatDriver = class _ChatDriver extends EventTarget {
|
|
|
10013
10045
|
this.aiServiceWall = void 0;
|
|
10014
10046
|
this.aiServiceNoticesShown.clear();
|
|
10015
10047
|
this.aiServiceNoticesQueued = [];
|
|
10048
|
+
this.withdrawTurnAtEnd = false;
|
|
10049
|
+
this.turnStartIndex = this.history.length;
|
|
10016
10050
|
this.appendToHistory({
|
|
10017
10051
|
role: "user",
|
|
10018
10052
|
content: userInput,
|
|
@@ -10056,6 +10090,7 @@ var ChatDriver = class _ChatDriver extends EventTarget {
|
|
|
10056
10090
|
});
|
|
10057
10091
|
this.busy = false;
|
|
10058
10092
|
this.endTurn();
|
|
10093
|
+
this.withdrawRefusedTurn();
|
|
10059
10094
|
this.activityBus.publish("tool-loop-end", this.loopEndDetail(result));
|
|
10060
10095
|
await this.releaseIfRequested();
|
|
10061
10096
|
}
|
|
@@ -10373,6 +10408,7 @@ var ChatDriver = class _ChatDriver extends EventTarget {
|
|
|
10373
10408
|
this.providerRefusedThisTurn = true;
|
|
10374
10409
|
this.providerRefusedDetail ??= failure?.providerRefused;
|
|
10375
10410
|
}
|
|
10411
|
+
this.noteChildRefusal(reason);
|
|
10376
10412
|
const wall = failure?.aiServiceError;
|
|
10377
10413
|
if (reason === "ai_service_error" && wall && SERVICE_WIDE_REFUSALS.has(wall.code) && wall.vendor !== void 0 && wall.vendor === this.lastResolvedProvider) {
|
|
10378
10414
|
this.aiServiceErrorThisTurn = true;
|
|
@@ -10422,6 +10458,8 @@ var ChatDriver = class _ChatDriver extends EventTarget {
|
|
|
10422
10458
|
this.providerRefusedDetail = void 0;
|
|
10423
10459
|
this.aiServiceErrorThisTurn = false;
|
|
10424
10460
|
this.aiServiceWall = void 0;
|
|
10461
|
+
this.withdrawTurnAtEnd = false;
|
|
10462
|
+
if (!options?.sameUserTurn) this.turnStartIndex = this.history.length;
|
|
10425
10463
|
this.turnStartedAt = Date.now();
|
|
10426
10464
|
recordMetaEvent(this.sessionKey, "turn.start", {
|
|
10427
10465
|
phase: "continueFromHistory",
|
|
@@ -10455,6 +10493,7 @@ var ChatDriver = class _ChatDriver extends EventTarget {
|
|
|
10455
10493
|
});
|
|
10456
10494
|
this.busy = false;
|
|
10457
10495
|
this.endTurn();
|
|
10496
|
+
this.withdrawRefusedTurn();
|
|
10458
10497
|
this.activityBus.publish("tool-loop-end", this.loopEndDetail(result));
|
|
10459
10498
|
await this.releaseIfRequested();
|
|
10460
10499
|
}
|
|
@@ -10808,13 +10847,14 @@ ${tailBody}
|
|
|
10808
10847
|
}
|
|
10809
10848
|
turnSnapshot.usage = messageUsage(response);
|
|
10810
10849
|
if (response.model !== void 0) turnSnapshot.model = response.model;
|
|
10850
|
+
if (isRefusalLike(response.responseMeta)) this.withdrawTurnAtEnd = true;
|
|
10811
10851
|
if (closing) {
|
|
10812
10852
|
if (response.toolCalls?.length) response = { ...response, toolCalls: void 0 };
|
|
10813
10853
|
if (!response.content?.trim()) return turnDone();
|
|
10814
10854
|
}
|
|
10815
10855
|
const isThinkingStep = response.content && response.toolCalls?.length;
|
|
10816
10856
|
const isEmptyResponse = !response.content?.trim() && !response.toolCalls?.length;
|
|
10817
|
-
const isRefusal = response.responseMeta
|
|
10857
|
+
const isRefusal = isRefusalLike(response.responseMeta);
|
|
10818
10858
|
if (isEmptyResponse) {
|
|
10819
10859
|
emptyResponseAttempts += 1;
|
|
10820
10860
|
if (!isRefusal && emptyResponseAttempts < MAX_EMPTY_RESPONSE_RETRIES) {
|
|
@@ -10841,6 +10881,7 @@ ${tailBody}
|
|
|
10841
10881
|
continue;
|
|
10842
10882
|
}
|
|
10843
10883
|
const exit = isRefusal ? TURN_FAILURE_EXITS.refusal : TURN_FAILURE_EXITS.emptyResponse;
|
|
10884
|
+
if (isRefusal) this.withdrawTurnAtEnd = true;
|
|
10844
10885
|
logger2.error(
|
|
10845
10886
|
isRefusal ? "ChatDriver: model refused the request (safety decline) \u2014 not retrying" : "ChatDriver: empty model response after all retries"
|
|
10846
10887
|
);
|
|
@@ -11289,6 +11330,40 @@ RECOVERY: this tool failed once \u2014 you may retry it, or take a different val
|
|
|
11289
11330
|
appendDriverNotice(content) {
|
|
11290
11331
|
this.appendToHistory({ role: "assistant", content, excludeFromProvider: true });
|
|
11291
11332
|
}
|
|
11333
|
+
/**
|
|
11334
|
+
* A child the model refused (GENC-2045). It was handed this driver's history, so the refused
|
|
11335
|
+
* content is in the parent's history too, and every later delegation would inherit it and be
|
|
11336
|
+
* refused again. The turn goes on, since the handler may recover, and is withdrawn when it ends.
|
|
11337
|
+
* A method of its own to keep `invokeSubAgent` under the complexity ceiling.
|
|
11338
|
+
*/
|
|
11339
|
+
noteChildRefusal(reason) {
|
|
11340
|
+
if (reason === "refusal") this.withdrawTurnAtEnd = true;
|
|
11341
|
+
}
|
|
11342
|
+
/**
|
|
11343
|
+
* Withdraws the turn that just ended from what the provider is sent, when the provider refused
|
|
11344
|
+
* something in it (GENC-2045). Flags every message from the turn's start `excludeFromProvider`,
|
|
11345
|
+
* so the next request no longer carries what was refused. The turn's tool calls and results are
|
|
11346
|
+
* flagged together, so none is left without the other. Nothing is removed from the history: the
|
|
11347
|
+
* UI and the debug log still show the turn.
|
|
11348
|
+
*
|
|
11349
|
+
* The cost: the model's next turn has no record of what the withdrawn turn did. A tool it ran
|
|
11350
|
+
* (a file written, a state transition, an interaction the user answered) has taken effect, but
|
|
11351
|
+
* the model is not told. It may repeat that work, or contradict what is on screen. A short note
|
|
11352
|
+
* of the completed tools would have to reach the provider as a message of its own, with the role
|
|
11353
|
+
* alternation that implies, so it is not done here. The refused content is what must not be sent.
|
|
11354
|
+
*
|
|
11355
|
+
* Only the top-level driver does this. A sub-agent that is refused reports `refusal` to its
|
|
11356
|
+
* parent (`invokeSubAgent`), which withdraws its own turn.
|
|
11357
|
+
*/
|
|
11358
|
+
withdrawRefusedTurn() {
|
|
11359
|
+
if (!this.withdrawTurnAtEnd || this.isSubAgent) return;
|
|
11360
|
+
this.withdrawTurnAtEnd = false;
|
|
11361
|
+
const start = Math.min(this.turnStartIndex, this.history.length);
|
|
11362
|
+
this.history = this.history.map(
|
|
11363
|
+
(m, i) => i >= start && !m.excludeFromProvider ? { ...m, excludeFromProvider: true } : m
|
|
11364
|
+
);
|
|
11365
|
+
this.notifyHistoryUpdated();
|
|
11366
|
+
}
|
|
11292
11367
|
appendToHistory(message) {
|
|
11293
11368
|
const tagged = {
|
|
11294
11369
|
...message,
|
|
@@ -11824,7 +11899,10 @@ var OrchestratingDriver = class _OrchestratingDriver extends BaseDriverDecorator
|
|
|
11824
11899
|
let last = result;
|
|
11825
11900
|
let tailNote = await this.afterAgentCall();
|
|
11826
11901
|
while (tailNote !== void 0 && !this.cancelled && !last.failureReason) {
|
|
11827
|
-
last = await this.chatDriver.continueFromHistory(void 0, {
|
|
11902
|
+
last = await this.chatDriver.continueFromHistory(void 0, {
|
|
11903
|
+
tailNote,
|
|
11904
|
+
sameUserTurn: true
|
|
11905
|
+
});
|
|
11828
11906
|
tailNote = await this.afterAgentCall();
|
|
11829
11907
|
}
|
|
11830
11908
|
return last;
|
|
@@ -13002,6 +13080,7 @@ function visibleTranscript(messages, opts) {
|
|
|
13002
13080
|
return;
|
|
13003
13081
|
}
|
|
13004
13082
|
if (isDriverNote(m)) return;
|
|
13083
|
+
if (m.excludeFromProvider && m.role === "user") return;
|
|
13005
13084
|
if ((m.role === "user" || m.role === "synthetic-user") && m.content?.trim()) {
|
|
13006
13085
|
lines.push(m.delegate ? `User (on their behalf): ${m.content}` : `User: ${m.content}`);
|
|
13007
13086
|
return;
|