@genesislcap/ai-assistant 15.35.3 → 15.35.4-FUI-0.9
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 +483 -0
- package/dist/ai-assistant.d.ts +213 -0
- package/dist/chat-driver.cjs +221 -4
- package/dist/chat-driver.cjs.map +2 -2
- package/dist/chat-driver.mjs +221 -4
- package/dist/chat-driver.mjs.map +2 -2
- package/dist/custom-elements.json +1189 -827
- package/dist/dts/components/ai-driver/ai-driver.d.ts +31 -0
- package/dist/dts/components/ai-driver/ai-driver.d.ts.map +1 -1
- package/dist/dts/components/chat-bubble/chat-bubble.d.ts.map +1 -1
- package/dist/dts/components/chat-bubble/chat-bubble.template.d.ts.map +1 -1
- package/dist/dts/components/chat-driver/chat-driver.d.ts +93 -0
- package/dist/dts/components/chat-driver/chat-driver.d.ts.map +1 -1
- package/dist/dts/components/chat-markdown/chat-markdown.d.ts +29 -0
- package/dist/dts/components/chat-markdown/chat-markdown.d.ts.map +1 -1
- package/dist/dts/components/halo-overlay.d.ts +30 -0
- package/dist/dts/components/halo-overlay.d.ts.map +1 -1
- package/dist/dts/components/orchestrating-driver/orchestrating-driver.d.ts +17 -0
- package/dist/dts/components/orchestrating-driver/orchestrating-driver.d.ts.map +1 -1
- package/dist/dts/main/main.template.d.ts.map +1 -1
- package/dist/dts/state/persistence/index.d.ts +1 -0
- package/dist/dts/state/persistence/index.d.ts.map +1 -1
- package/dist/dts/state/persistence/session-persister.d.ts +12 -0
- package/dist/dts/state/persistence/session-persister.d.ts.map +1 -1
- package/dist/dts/state/persistence/session-snapshot.d.ts +14 -0
- package/dist/dts/state/persistence/session-snapshot.d.ts.map +1 -1
- package/dist/dts/suggestions/chat-suggestions.d.ts +7 -0
- package/dist/dts/suggestions/chat-suggestions.d.ts.map +1 -1
- package/dist/dts/utils/condense-history.d.ts +114 -0
- package/dist/dts/utils/condense-history.d.ts.map +1 -1
- package/dist/esm/components/chat-bubble/chat-bubble.js +8 -0
- package/dist/esm/components/chat-bubble/chat-bubble.template.js +5 -3
- package/dist/esm/components/chat-driver/chat-driver.js +140 -17
- package/dist/esm/components/chat-markdown/chat-markdown.js +132 -1
- package/dist/esm/components/halo-overlay.js +96 -8
- package/dist/esm/components/orchestrating-driver/orchestrating-driver.js +17 -0
- package/dist/esm/main/main.template.js +95 -45
- package/dist/esm/state/persistence/session-persister.js +63 -15
- package/dist/esm/state/persistence/session-snapshot.js +2 -17
- package/dist/esm/suggestions/chat-suggestions.js +11 -3
- package/dist/esm/utils/condense-history.js +123 -0
- package/docs/styling.md +120 -0
- package/package.json +18 -18
package/dist/chat-driver.mjs
CHANGED
|
@@ -4008,6 +4008,79 @@ function projectCompaction(history, cut, summaryTokens = COMPACTION_SUMMARY_TOKE
|
|
|
4008
4008
|
// src/utils/condense-history.ts
|
|
4009
4009
|
var CONDENSE_MIN_CHARS = 1e3;
|
|
4010
4010
|
var CONDENSED_ARGS_KEY = "condensed";
|
|
4011
|
+
function isValidCondenseTrigger(t) {
|
|
4012
|
+
if (t?.kind === "superseded") return typeof t.by === "string" && t.by.length > 0;
|
|
4013
|
+
if (t?.kind === "age") return typeof t.turns === "number" && t.turns >= 1;
|
|
4014
|
+
return t?.kind === "turnEnd" || t?.kind === "agentEnd" || t?.kind === "phaseEnd";
|
|
4015
|
+
}
|
|
4016
|
+
function isValidCondenseResult(r) {
|
|
4017
|
+
if (r === "pointer" || r === "drop") return true;
|
|
4018
|
+
return !!r && typeof r === "object" && typeof r.replaceWith === "string";
|
|
4019
|
+
}
|
|
4020
|
+
function toolCallIdsIn(history) {
|
|
4021
|
+
const ids = /* @__PURE__ */ new Set();
|
|
4022
|
+
for (const msg of history) {
|
|
4023
|
+
for (const tc of msg.toolCalls ?? []) ids.add(tc.id);
|
|
4024
|
+
}
|
|
4025
|
+
return ids;
|
|
4026
|
+
}
|
|
4027
|
+
function snapshotCondensePolicies(policies, clocks, history) {
|
|
4028
|
+
if (policies.size === 0) return [];
|
|
4029
|
+
const present = toolCallIdsIn(history);
|
|
4030
|
+
const out = [];
|
|
4031
|
+
for (const [toolCallId, entry] of policies) {
|
|
4032
|
+
if (entry.firedTrigger || !present.has(toolCallId)) continue;
|
|
4033
|
+
out.push({
|
|
4034
|
+
toolCallId,
|
|
4035
|
+
policy: entry.policy,
|
|
4036
|
+
...entry.agent !== void 0 && { agent: entry.agent },
|
|
4037
|
+
elapsed: {
|
|
4038
|
+
// `max(0, …)`: every clock is monotonic, so these are never negative on a live driver;
|
|
4039
|
+
// the clamp only stops a malformed entry from being written out as "the future".
|
|
4040
|
+
modelCalls: Math.max(0, clocks.modelCall - entry.iteration),
|
|
4041
|
+
turns: Math.max(0, clocks.turn - entry.turn),
|
|
4042
|
+
activations: Math.max(0, clocks.activation - entry.activation),
|
|
4043
|
+
phases: Math.max(0, clocks.phaseEpoch - entry.phaseEpoch)
|
|
4044
|
+
}
|
|
4045
|
+
});
|
|
4046
|
+
}
|
|
4047
|
+
return out;
|
|
4048
|
+
}
|
|
4049
|
+
function parsePersistedCondensePolicy(value) {
|
|
4050
|
+
if (!value || typeof value !== "object") return void 0;
|
|
4051
|
+
const v = value;
|
|
4052
|
+
if (typeof v.toolCallId !== "string" || !v.toolCallId) return void 0;
|
|
4053
|
+
const policy = v.policy;
|
|
4054
|
+
if (!policy || typeof policy !== "object") return void 0;
|
|
4055
|
+
const triggers = Array.isArray(policy.on) ? policy.on : [policy.on];
|
|
4056
|
+
if (triggers.length === 0 || !triggers.every(isValidCondenseTrigger)) return void 0;
|
|
4057
|
+
if (policy.args === void 0 && policy.response === void 0) return void 0;
|
|
4058
|
+
if (policy.args !== void 0 && !isValidCondenseResult(policy.args)) return void 0;
|
|
4059
|
+
if (policy.response !== void 0 && !isValidCondenseResult(policy.response)) return void 0;
|
|
4060
|
+
const count = (n) => typeof n === "number" && Number.isFinite(n) && n > 0 ? Math.floor(n) : 0;
|
|
4061
|
+
const e = v.elapsed ?? {};
|
|
4062
|
+
return {
|
|
4063
|
+
toolCallId: v.toolCallId,
|
|
4064
|
+
policy,
|
|
4065
|
+
...typeof v.agent === "string" && { agent: v.agent },
|
|
4066
|
+
elapsed: {
|
|
4067
|
+
modelCalls: count(e.modelCalls),
|
|
4068
|
+
turns: count(e.turns),
|
|
4069
|
+
activations: count(e.activations),
|
|
4070
|
+
phases: count(e.phases)
|
|
4071
|
+
}
|
|
4072
|
+
};
|
|
4073
|
+
}
|
|
4074
|
+
function rebaseRestoredCondensePolicy(entry, clocks) {
|
|
4075
|
+
return {
|
|
4076
|
+
policy: entry.policy,
|
|
4077
|
+
iteration: clocks.modelCall - entry.elapsed.modelCalls,
|
|
4078
|
+
turn: clocks.turn - entry.elapsed.turns,
|
|
4079
|
+
activation: clocks.activation - entry.elapsed.activations,
|
|
4080
|
+
phaseEpoch: clocks.phaseEpoch - entry.elapsed.phases,
|
|
4081
|
+
...entry.agent !== void 0 && { agent: entry.agent }
|
|
4082
|
+
};
|
|
4083
|
+
}
|
|
4011
4084
|
function triggerReason(trigger) {
|
|
4012
4085
|
switch (trigger.kind) {
|
|
4013
4086
|
case "age":
|
|
@@ -5295,8 +5368,29 @@ var ChatDriver = class _ChatDriver extends EventTarget {
|
|
|
5295
5368
|
* provider call to collapse stale payloads from the model-bound history only.
|
|
5296
5369
|
* Accumulates across agents on a shared driver (a superseded read collapses no
|
|
5297
5370
|
* matter which agent made it) and is never cleared — it dies with the driver.
|
|
5371
|
+
*
|
|
5372
|
+
* "Dies with the driver" used to mean a page reload silently disarmed every policy that had
|
|
5373
|
+
* not fired yet: the restored transcript carried the full payload and nothing was left to
|
|
5374
|
+
* collapse it, so it rode every later provider call (GENC-1632). The unfired entries are now
|
|
5375
|
+
* persisted with the session and re-registered on restore — see
|
|
5376
|
+
* {@link ChatDriver.getCondensePoliciesForPersistence} and
|
|
5377
|
+
* {@link ChatDriver.restoreCondensePolicies}.
|
|
5298
5378
|
*/
|
|
5299
5379
|
this.condensePolicies = /* @__PURE__ */ new Map();
|
|
5380
|
+
/**
|
|
5381
|
+
* Restored policies whose owning activation was still live at save time, waiting for that agent
|
|
5382
|
+
* to be re-installed so they can be stamped with the activation it resumes in (GENC-1632).
|
|
5383
|
+
*
|
|
5384
|
+
* They cannot be stamped at restore time. On a fresh page `activeAgentName` is unset, so the
|
|
5385
|
+
* first `installAgent` after the reload is a "name change" and advances `currentActivation` —
|
|
5386
|
+
* which is exactly the `agentEnd` signal. An entry stamped before that bump reads as belonging
|
|
5387
|
+
* to an activation that has ended, and it and every `phaseEnd` entry (through the `agentEnd`
|
|
5388
|
+
* backstop) collapse on the first provider call after the reload, mid-flow. For Create's
|
|
5389
|
+
* Planning phase that is the uploaded scope document vanishing the moment the user carries on
|
|
5390
|
+
* talking about it — a worse failure than the one being fixed. So the stamp is deferred to that
|
|
5391
|
+
* `installAgent`, and consumed there once whichever agent it installs.
|
|
5392
|
+
*/
|
|
5393
|
+
this.condenseAwaitingReactivation = /* @__PURE__ */ new Set();
|
|
5300
5394
|
/**
|
|
5301
5395
|
* Monotonic model-call counter for the driver's whole lifetime — the age clock
|
|
5302
5396
|
* for `condenseWhen({ on: { kind: 'age' } })`. The per-`sendMessage` `iterations`
|
|
@@ -5771,7 +5865,10 @@ var ChatDriver = class _ChatDriver extends EventTarget {
|
|
|
5771
5865
|
* whether the hooks should fire is the whole difference between this and `activateAgent`.
|
|
5772
5866
|
*/
|
|
5773
5867
|
installAgent(config) {
|
|
5774
|
-
if (config.name !== this.activeAgentName)
|
|
5868
|
+
if (config.name !== this.activeAgentName) {
|
|
5869
|
+
this.currentActivation += 1;
|
|
5870
|
+
this.resumeRestoredCondensePolicies(config.name);
|
|
5871
|
+
}
|
|
5775
5872
|
this.systemPrompt = config.systemPrompt;
|
|
5776
5873
|
if (typeof config.toolDefinitions === "function") {
|
|
5777
5874
|
this.toolDefinitionsFactory = config.toolDefinitions;
|
|
@@ -6084,6 +6181,109 @@ var ChatDriver = class _ChatDriver extends EventTarget {
|
|
|
6084
6181
|
getHistoryForPersistence() {
|
|
6085
6182
|
return condenseForPersistence([...this.history], this.condensePolicies);
|
|
6086
6183
|
}
|
|
6184
|
+
/** The four condensation clocks as they read now. */
|
|
6185
|
+
condenseClocks() {
|
|
6186
|
+
return {
|
|
6187
|
+
modelCall: this.modelCallSeq,
|
|
6188
|
+
turn: this.turnSeq,
|
|
6189
|
+
activation: this.currentActivation,
|
|
6190
|
+
phaseEpoch: this.currentPhaseEpoch
|
|
6191
|
+
};
|
|
6192
|
+
}
|
|
6193
|
+
/**
|
|
6194
|
+
* The `condenseWhen` policies that have not fired yet, for the calls in `messages`, in the
|
|
6195
|
+
* clock-independent form {@link ChatDriver.restoreCondensePolicies} re-registers. See
|
|
6196
|
+
* {@link AiDriver.getCondensePoliciesForPersistence}.
|
|
6197
|
+
*
|
|
6198
|
+
* The other half of {@link ChatDriver.getHistoryForPersistence} (GENC-1632). That stores the
|
|
6199
|
+
* payloads the model has already stopped seeing as their stubs; this stores the policies for the
|
|
6200
|
+
* ones it has NOT stopped seeing yet, so a reload does not strand them at full size for the rest
|
|
6201
|
+
* of the session. Only entries whose call is in `messages` — the transcript actually being
|
|
6202
|
+
* written — are returned, so a frozen (non-resumable) or compacted save carries no policy for a
|
|
6203
|
+
* call it does not contain.
|
|
6204
|
+
*
|
|
6205
|
+
* @beta
|
|
6206
|
+
*/
|
|
6207
|
+
getCondensePoliciesForPersistence(messages) {
|
|
6208
|
+
return snapshotCondensePolicies(this.condensePolicies, this.condenseClocks(), messages);
|
|
6209
|
+
}
|
|
6210
|
+
/**
|
|
6211
|
+
* Re-register policies saved by {@link ChatDriver.getCondensePoliciesForPersistence} against
|
|
6212
|
+
* the restored transcript. See {@link AiDriver.restoreCondensePolicies}.
|
|
6213
|
+
*
|
|
6214
|
+
* Call AFTER {@link ChatDriver.loadHistory} has seeded the restored transcript: an entry is
|
|
6215
|
+
* re-registered only if its tool call is in the driver's history, so one whose call the
|
|
6216
|
+
* restorable-boundary trim cut away (an orphaned trailing `tool_use`) is dropped rather than
|
|
6217
|
+
* resurrected against nothing.
|
|
6218
|
+
*
|
|
6219
|
+
* First-wins still holds per call: an entry is skipped if a policy is already registered for its
|
|
6220
|
+
* tool call — a restore never overrides what a live handler declared. `superseded` needs no
|
|
6221
|
+
* special handling — survivors are resolved from HISTORY order on every pass, so a restored entry
|
|
6222
|
+
* and a later call on the same `by` key resolve exactly as two live ones would.
|
|
6223
|
+
*
|
|
6224
|
+
* Clocks are rebased so each trigger is exactly as far from firing as it was at save time (see
|
|
6225
|
+
* `rebaseRestoredCondensePolicy`), with one deferral. An entry owned by the activation that was
|
|
6226
|
+
* live at save time, whose agent is not the one installed right now — the normal case on a
|
|
6227
|
+
* fresh page, where nothing is installed yet — is parked in
|
|
6228
|
+
* `condenseAwaitingReactivation` and stamped by the next `installAgent`: with
|
|
6229
|
+
* that agent's resumed activation if it is the same agent, or left behind (so it reads as
|
|
6230
|
+
* ended, which it has) if a different agent took over.
|
|
6231
|
+
*
|
|
6232
|
+
* A host with no agent to re-activate (a bare driver built from a static config) loses nothing
|
|
6233
|
+
* by this: the entry's owner (`undefined`) matches the installed agent (`undefined`), so it is
|
|
6234
|
+
* stamped live straight away and ends when the driver's single activation does — on
|
|
6235
|
+
* `releaseAgent` / `completeSubAgent`, exactly as a policy registered live would.
|
|
6236
|
+
*
|
|
6237
|
+
* Returns how many entries were actually re-armed, split from how many were merely present in
|
|
6238
|
+
* `entries` (review follow-up, GENC-1632): a malformed entry, one whose call the restorable-
|
|
6239
|
+
* boundary trim removed, or a first-wins duplicate is silently dropped, so the caller's own count
|
|
6240
|
+
* of `entries` can't tell "all of them came back" from "none did". `restored` is every entry that
|
|
6241
|
+
* reached `condensePolicies`; `awaitingReactivation` is the subset of those parked pending the
|
|
6242
|
+
* next `installAgent` rather than stamped live immediately.
|
|
6243
|
+
*
|
|
6244
|
+
* @beta
|
|
6245
|
+
*/
|
|
6246
|
+
restoreCondensePolicies(entries) {
|
|
6247
|
+
if (!Array.isArray(entries) || entries.length === 0)
|
|
6248
|
+
return { restored: 0, awaitingReactivation: 0 };
|
|
6249
|
+
const present = toolCallIdsIn(this.history);
|
|
6250
|
+
const clocks = this.condenseClocks();
|
|
6251
|
+
let restored = 0;
|
|
6252
|
+
let awaitingReactivation = 0;
|
|
6253
|
+
for (const raw of entries) {
|
|
6254
|
+
const entry = parsePersistedCondensePolicy(raw);
|
|
6255
|
+
if (!entry || !present.has(entry.toolCallId)) continue;
|
|
6256
|
+
if (this.condensePolicies.has(entry.toolCallId)) continue;
|
|
6257
|
+
this.condensePolicies.set(entry.toolCallId, rebaseRestoredCondensePolicy(entry, clocks));
|
|
6258
|
+
restored += 1;
|
|
6259
|
+
if (entry.elapsed.activations === 0 && entry.agent !== this.activeAgentName) {
|
|
6260
|
+
this.condenseAwaitingReactivation.add(entry.toolCallId);
|
|
6261
|
+
awaitingReactivation += 1;
|
|
6262
|
+
}
|
|
6263
|
+
}
|
|
6264
|
+
return { restored, awaitingReactivation };
|
|
6265
|
+
}
|
|
6266
|
+
/**
|
|
6267
|
+
* Stamp the restored entries parked in `condenseAwaitingReactivation` now that
|
|
6268
|
+
* `installAgent` has advanced the activation clock for `agentName` (GENC-1632).
|
|
6269
|
+
*
|
|
6270
|
+
* Same agent → the flow the entry belonged to is resuming, so it takes the new activation and
|
|
6271
|
+
* stays full until THAT activation ends (and, for `phaseEnd`, until the next `endPhase()`).
|
|
6272
|
+
* Different agent → its owner did not come back; its activation is over, so it keeps the stamp
|
|
6273
|
+
* it was restored with, which is now behind the clock, and collapses on the next provider call
|
|
6274
|
+
* exactly as a live `agentEnd` payload does on a swap.
|
|
6275
|
+
*
|
|
6276
|
+
* One-shot: the set is emptied whatever the outcome, because only the FIRST activation after the
|
|
6277
|
+
* restore can be the resumption. Any later swap is an ordinary activation boundary.
|
|
6278
|
+
*/
|
|
6279
|
+
resumeRestoredCondensePolicies(agentName) {
|
|
6280
|
+
if (this.condenseAwaitingReactivation.size === 0) return;
|
|
6281
|
+
for (const toolCallId of this.condenseAwaitingReactivation) {
|
|
6282
|
+
const entry = this.condensePolicies.get(toolCallId);
|
|
6283
|
+
if (entry && entry.agent === agentName) entry.activation = this.currentActivation;
|
|
6284
|
+
}
|
|
6285
|
+
this.condenseAwaitingReactivation.clear();
|
|
6286
|
+
}
|
|
6087
6287
|
/**
|
|
6088
6288
|
* {@inheritDoc AiDriver.getSuggestions}
|
|
6089
6289
|
*
|
|
@@ -6399,8 +6599,7 @@ var ChatDriver = class _ChatDriver extends EventTarget {
|
|
|
6399
6599
|
return;
|
|
6400
6600
|
}
|
|
6401
6601
|
const triggers = Array.isArray(policy.on) ? policy.on : [policy.on];
|
|
6402
|
-
|
|
6403
|
-
if (triggers.length === 0 || !triggers.every(validTrigger)) {
|
|
6602
|
+
if (triggers.length === 0 || !triggers.every(isValidCondenseTrigger)) {
|
|
6404
6603
|
logger2.warn(
|
|
6405
6604
|
`ChatDriver(${this.activeAgentName ?? "unknown"}): condenseWhen called with an invalid trigger \u2014 ignoring`
|
|
6406
6605
|
);
|
|
@@ -6417,7 +6616,8 @@ var ChatDriver = class _ChatDriver extends EventTarget {
|
|
|
6417
6616
|
iteration: this.modelCallSeq,
|
|
6418
6617
|
turn: this.turnSeq,
|
|
6419
6618
|
activation: this.currentActivation,
|
|
6420
|
-
phaseEpoch: this.currentPhaseEpoch
|
|
6619
|
+
phaseEpoch: this.currentPhaseEpoch,
|
|
6620
|
+
...this.activeAgentName !== void 0 && { agent: this.activeAgentName }
|
|
6421
6621
|
});
|
|
6422
6622
|
}
|
|
6423
6623
|
};
|
|
@@ -7590,6 +7790,23 @@ var OrchestratingDriver = class extends EventTarget {
|
|
|
7590
7790
|
getHistoryForPersistence() {
|
|
7591
7791
|
return this.chatDriver.getHistoryForPersistence();
|
|
7592
7792
|
}
|
|
7793
|
+
/**
|
|
7794
|
+
* Delegates to the inner {@link ChatDriver}, which owns the condensation registry and clocks
|
|
7795
|
+
* (GENC-1632). The forward matters for the same reason as `getHistoryForPersistence` above: the
|
|
7796
|
+
* persister reaches it through `?.`, so a missing forward would compile, pass the ChatDriver
|
|
7797
|
+
* tests, and do nothing for every orchestrated host — which is every host with an agents array.
|
|
7798
|
+
*/
|
|
7799
|
+
getCondensePoliciesForPersistence(messages) {
|
|
7800
|
+
return this.chatDriver.getCondensePoliciesForPersistence(messages);
|
|
7801
|
+
}
|
|
7802
|
+
/**
|
|
7803
|
+
* Delegates to the inner {@link ChatDriver} (GENC-1632). The deferred activation stamp it
|
|
7804
|
+
* performs is taken by the inner driver's `installAgent`, which this driver's own
|
|
7805
|
+
* `installAgent` always reaches, so nothing extra is needed here.
|
|
7806
|
+
*/
|
|
7807
|
+
restoreCondensePolicies(entries) {
|
|
7808
|
+
return this.chatDriver.restoreCondensePolicies(entries);
|
|
7809
|
+
}
|
|
7593
7810
|
/** {@inheritDoc AiDriver.setContextGuard} */
|
|
7594
7811
|
setContextGuard(policy) {
|
|
7595
7812
|
this.chatDriver.setContextGuard(policy);
|