@genesislcap/ai-assistant 14.497.0 → 14.499.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.
Files changed (37) hide show
  1. package/dist/ai-assistant.api.json +132 -0
  2. package/dist/ai-assistant.d.ts +35 -0
  3. package/dist/chat-driver.cjs +157 -0
  4. package/dist/chat-driver.cjs.map +3 -3
  5. package/dist/chat-driver.mjs +151 -0
  6. package/dist/chat-driver.mjs.map +3 -3
  7. package/dist/custom-elements.json +156 -1
  8. package/dist/dts/chat-driver-node.d.ts +7 -1
  9. package/dist/dts/chat-driver-node.d.ts.map +1 -1
  10. package/dist/dts/components/ai-driver/ai-driver.d.ts +8 -0
  11. package/dist/dts/components/ai-driver/ai-driver.d.ts.map +1 -1
  12. package/dist/dts/components/chat-driver/chat-driver.d.ts +27 -0
  13. package/dist/dts/components/chat-driver/chat-driver.d.ts.map +1 -1
  14. package/dist/dts/components/orchestrating-driver/orchestrating-driver.d.ts +3 -0
  15. package/dist/dts/components/orchestrating-driver/orchestrating-driver.d.ts.map +1 -1
  16. package/dist/dts/main/main.d.ts.map +1 -1
  17. package/dist/dts/state/debug-event-log.d.ts +1 -1
  18. package/dist/dts/state/debug-event-log.d.ts.map +1 -1
  19. package/dist/dts/state/persistence/build-timeline-entries.d.ts +37 -0
  20. package/dist/dts/state/persistence/build-timeline-entries.d.ts.map +1 -0
  21. package/dist/esm/chat-driver-node.js +16 -1
  22. package/dist/esm/components/chat-driver/chat-driver.js +103 -0
  23. package/dist/esm/components/chat-driver/chat-driver.test.js +165 -0
  24. package/dist/esm/components/orchestrating-driver/orchestrating-driver.js +4 -0
  25. package/dist/esm/main/main.js +18 -28
  26. package/dist/esm/state/debug-event-log.js +1 -0
  27. package/dist/esm/state/persistence/build-timeline-entries.js +46 -0
  28. package/dist/tsconfig.tsbuildinfo +1 -1
  29. package/package.json +17 -17
  30. package/src/chat-driver-node.ts +20 -0
  31. package/src/components/ai-driver/ai-driver.ts +9 -0
  32. package/src/components/chat-driver/chat-driver.test.ts +215 -0
  33. package/src/components/chat-driver/chat-driver.ts +109 -0
  34. package/src/components/orchestrating-driver/orchestrating-driver.ts +6 -0
  35. package/src/main/main.ts +17 -30
  36. package/src/state/debug-event-log.ts +3 -0
  37. package/src/state/persistence/build-timeline-entries.ts +66 -0
@@ -2589,6 +2589,7 @@ var META_EVENT_IMPORTANCE = {
2589
2589
  "provider.selected": "normal",
2590
2590
  "interaction.requested": "normal",
2591
2591
  "interaction.resolved": "normal",
2592
+ "external-diagnostics.folded": "normal",
2592
2593
  "session.cleared": "normal",
2593
2594
  "session.switched": "low",
2594
2595
  "session.switch-deferred": "low",
@@ -3085,6 +3086,23 @@ var ChatDriver = class _ChatDriver extends EventTarget {
3085
3086
  * arrive. See {@link TurnSnapshot} for the captured shape.
3086
3087
  */
3087
3088
  this.turnSnapshots = [];
3089
+ /**
3090
+ * `turn` + `message` diagnostic-log entries harvested from an out-of-band source (a resolved
3091
+ * interaction whose widget returned `InteractionResult.diagnostics` — e.g. a server-side
3092
+ * ChatDriver's debug log). `event` entries are NOT kept here — they're folded into the session's
3093
+ * meta-event registry via `mergeMetaEvents` (see `resolveInteraction`) so they inherit fresh host
3094
+ * indices, and reach the log through `getMetaEvents`. Append-only; the host folds these into its
3095
+ * debug log alongside this driver's own timeline. Not cleared here — it lives with the driver
3096
+ * instance, like `turnSnapshots`, so a new chat (fresh driver) starts empty while a compaction
3097
+ * (same instance) keeps it. (GENC-1461.)
3098
+ */
3099
+ this.externalDiagnostics = [];
3100
+ /**
3101
+ * Monotonic count of external-diagnostics batches harvested this driver-lifetime. Namespaces each
3102
+ * batch's re-keyed `turn` entries so distinct server generations in one chat session can't collide
3103
+ * on `turnIndex` in the forward-capture persister (which dedups turns by that key). (GENC-1461.)
3104
+ */
3105
+ this.externalDiagnosticsBatches = 0;
3088
3106
  /** Monotonic counter that survives agent swaps — useful for cross-referencing with history. */
3089
3107
  this.globalTurnIndex = 0;
3090
3108
  /**
@@ -3459,6 +3477,17 @@ var ChatDriver = class _ChatDriver extends EventTarget {
3459
3477
  getTurnSnapshots() {
3460
3478
  return this.turnSnapshots;
3461
3479
  }
3480
+ /**
3481
+ * The `turn` + `message` diagnostic-log entries harvested from resolved interactions'
3482
+ * `InteractionResult.diagnostics` (e.g. a server-side ChatDriver's collated debug log). The host
3483
+ * concatenates these into its own debug log so `downloadDebugLog`/the persisted diagnostics stream
3484
+ * include external-engine logs; `event` entries are excluded here because they're merged into the
3485
+ * session's meta-event registry instead (see `resolveInteraction`) and reach the log via
3486
+ * `getMetaEvents`. Opaque, chronologically sorted by the host at assemble time. (GENC-1461.)
3487
+ */
3488
+ getExternalDiagnostics() {
3489
+ return this.externalDiagnostics;
3490
+ }
3462
3491
  /**
3463
3492
  * Merge a sub-agent's turn snapshots into this driver's buffer so they surface
3464
3493
  * as `kind:'turn'` entries in the exported debug log. The child runs as a
@@ -3768,6 +3797,38 @@ Output format (strict):
3768
3797
  const interaction = this.pendingInteractions.get(interactionId);
3769
3798
  if (interaction) {
3770
3799
  if (interaction.timeoutHandle) clearTimeout(interaction.timeoutHandle);
3800
+ const harvestedDiagnostics = result?.diagnostics;
3801
+ if (Array.isArray(harvestedDiagnostics) && harvestedDiagnostics.length) {
3802
+ const batch = this.externalDiagnosticsBatches += 1;
3803
+ const externalEvents = [];
3804
+ let turnCount = 0;
3805
+ let messageCount = 0;
3806
+ for (const raw of harvestedDiagnostics) {
3807
+ if (!raw || typeof raw !== "object" || typeof raw.kind !== "string") {
3808
+ continue;
3809
+ }
3810
+ const entry = raw;
3811
+ if (entry.kind === "event") {
3812
+ const { kind: _kind, ...event } = entry;
3813
+ externalEvents.push(event);
3814
+ } else if (entry.kind === "turn") {
3815
+ this.externalDiagnostics.push({
3816
+ ...entry,
3817
+ turnIndex: `server-generation.${batch}:${turnCount}`
3818
+ });
3819
+ turnCount += 1;
3820
+ } else if (entry.kind === "message") {
3821
+ messageCount += 1;
3822
+ this.externalDiagnostics.push(entry);
3823
+ }
3824
+ }
3825
+ if (externalEvents.length) mergeMetaEvents(this.sessionKey, externalEvents);
3826
+ recordMetaEvent(this.sessionKey, "external-diagnostics.folded", {
3827
+ interactionId,
3828
+ batch,
3829
+ counts: { turn: turnCount, event: externalEvents.length, message: messageCount }
3830
+ });
3831
+ }
3771
3832
  const idx = this.history.findIndex((m) => m.interaction?.interactionId === interactionId);
3772
3833
  if (idx !== -1) {
3773
3834
  const costUsd = typeof result?.costUsd === "number" && Number.isFinite(result.costUsd) && result.costUsd > 0 ? result.costUsd : void 0;
@@ -5035,6 +5096,10 @@ var OrchestratingDriver = class extends EventTarget {
5035
5096
  getTurnSnapshots() {
5036
5097
  return this.chatDriver.getTurnSnapshots();
5037
5098
  }
5099
+ /** Delegates to the inner {@link ChatDriver} — interactions resolve there, so it holds the buffer. */
5100
+ getExternalDiagnostics() {
5101
+ return this.chatDriver.getExternalDiagnostics();
5102
+ }
5038
5103
  async getSuggestions(history, prompt2, count, allAgentInfo) {
5039
5104
  const pinned = this.resolvePinnedAgent();
5040
5105
  const candidates = pinned && isSpecialist(pinned) ? [pinned] : this.specialists;
@@ -5548,6 +5613,86 @@ var strictFallbackAgent = {
5548
5613
  fallback: true,
5549
5614
  systemPrompt: `You are a concise assistant. The user's request is outside your scope. Respond with a single short sentence stating what you can assist with. Do not elaborate. The available specialists are: {{agents}}.`
5550
5615
  };
5616
+
5617
+ // src/utils/flatten-sub-agent-messages.ts
5618
+ function flattenSubAgentMessages(messages, prefix = "", depth = 0, subAgentOf) {
5619
+ return messages.flatMap((m) => {
5620
+ const breadcrumb = prefix ? `${prefix} \u203A ${m.agentName ?? "?"}` : m.agentName;
5621
+ const traceCalls = m.toolCalls?.filter((tc) => tc.subAgentTrace?.length) ?? [];
5622
+ const entry = {
5623
+ kind: "message",
5624
+ ...m,
5625
+ // Move the (about-to-be-hoisted) child conversations out of the emitted tool
5626
+ // calls. Setting it to `undefined` drops the key from the serialized export.
5627
+ ...traceCalls.length > 0 && {
5628
+ toolCalls: m.toolCalls.map(
5629
+ (tc) => tc.subAgentTrace ? { ...tc, subAgentTrace: void 0 } : tc
5630
+ )
5631
+ },
5632
+ // Mark + breadcrumb hoisted sub-agent messages; top-level (depth 0) stays as-is.
5633
+ ...depth > 0 && {
5634
+ agentName: breadcrumb,
5635
+ subAgentName: m.agentName,
5636
+ subAgentDepth: depth,
5637
+ subAgentOf
5638
+ }
5639
+ };
5640
+ if (traceCalls.length === 0) return [entry];
5641
+ const hoisted = traceCalls.flatMap(
5642
+ (tc) => flattenSubAgentMessages(tc.subAgentTrace, breadcrumb ?? "", depth + 1, tc.id)
5643
+ );
5644
+ return [entry, ...hoisted];
5645
+ });
5646
+ }
5647
+
5648
+ // src/state/persistence/build-timeline-entries.ts
5649
+ function buildTimelineEntries(input) {
5650
+ const { turnSnapshots, messages, metaEvents } = input;
5651
+ let lastFullPrompt;
5652
+ let lastFullIndex = "";
5653
+ const turns = turnSnapshots.map((t) => {
5654
+ let { systemPrompt } = t;
5655
+ if (systemPrompt != null && systemPrompt === lastFullPrompt) {
5656
+ systemPrompt = `<repeated \u2014 identical to turn ${lastFullIndex}>`;
5657
+ } else if (systemPrompt != null) {
5658
+ lastFullPrompt = systemPrompt;
5659
+ lastFullIndex = t.turnIndex;
5660
+ }
5661
+ return { kind: "turn", ...t, systemPrompt };
5662
+ });
5663
+ const messageEntries = flattenSubAgentMessages(messages);
5664
+ const eventEntries = metaEvents.map((e) => ({ kind: "event", ...e }));
5665
+ return [...messageEntries, ...turns, ...eventEntries];
5666
+ }
5667
+
5668
+ // src/state/persistence/diagnostics.ts
5669
+ var KIND_RANK = { event: 0, turn: 1, message: 2 };
5670
+ var UNKNOWN_KIND_RANK = 99;
5671
+ function assembleDebugLog(entries, readme) {
5672
+ const seen = /* @__PURE__ */ new Set();
5673
+ let latestMeta;
5674
+ const timeline = [];
5675
+ for (const entry of entries) {
5676
+ const id = JSON.stringify(entry);
5677
+ if (seen.has(id)) continue;
5678
+ seen.add(id);
5679
+ if (entry.kind === "meta-snapshot") {
5680
+ if (!latestMeta || (entry.timestamp ?? "") >= (latestMeta.timestamp ?? "")) {
5681
+ latestMeta = entry;
5682
+ }
5683
+ } else {
5684
+ timeline.push(entry);
5685
+ }
5686
+ }
5687
+ timeline.sort((a, b) => {
5688
+ const ta = a.timestamp ?? "";
5689
+ const tb = b.timestamp ?? "";
5690
+ if (ta < tb) return -1;
5691
+ if (ta > tb) return 1;
5692
+ return (KIND_RANK[a.kind] ?? UNKNOWN_KIND_RANK) - (KIND_RANK[b.kind] ?? UNKNOWN_KIND_RANK);
5693
+ });
5694
+ return { readme, timeline, meta: latestMeta?.meta };
5695
+ }
5551
5696
  export {
5552
5697
  AgenticActivityBus,
5553
5698
  AnthropicProvider,
@@ -5559,10 +5704,16 @@ export {
5559
5704
  NOOP_ACTIVITY_BUS,
5560
5705
  OrchestratingDriver,
5561
5706
  REQUEST_CONTINUATION_TOOL,
5707
+ SUPPORTED_ANTHROPIC_MODEL_IDS,
5708
+ SUPPORTED_GEMINI_MODEL_IDS,
5562
5709
  agenticActivityBus,
5710
+ assembleDebugLog,
5711
+ buildTimelineEntries,
5712
+ clearSession,
5563
5713
  defineAgent,
5564
5714
  defineStatefulAgent,
5565
5715
  friendlyFallbackAgent,
5716
+ getMetaEvents,
5566
5717
  isObservableAIProviderRegistry,
5567
5718
  restoreMachine,
5568
5719
  strictFallbackAgent