@syntrologie/adapt-chatbot 2.27.0 → 2.29.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 (131) hide show
  1. package/dist/AdaptiveChatBar.composer.test.d.ts +2 -0
  2. package/dist/AdaptiveChatBar.composer.test.d.ts.map +1 -0
  3. package/dist/AdaptiveChatBar.d.ts +212 -0
  4. package/dist/AdaptiveChatBar.d.ts.map +1 -0
  5. package/dist/AdaptiveChatBar.js +11 -0
  6. package/dist/AdaptiveChatBar.js.map +7 -0
  7. package/dist/AdaptiveChatBarMountable.d.ts +82 -0
  8. package/dist/AdaptiveChatBarMountable.d.ts.map +1 -0
  9. package/dist/AdaptiveChatTrail.anchor-scroll.test.d.ts +2 -0
  10. package/dist/AdaptiveChatTrail.anchor-scroll.test.d.ts.map +1 -0
  11. package/dist/AdaptiveChatTrail.d.ts +469 -0
  12. package/dist/AdaptiveChatTrail.d.ts.map +1 -0
  13. package/dist/AdaptiveChatTrail.js +11 -0
  14. package/dist/AdaptiveChatTrail.js.map +7 -0
  15. package/dist/AdaptiveChatTrail.test.d.ts +2 -0
  16. package/dist/AdaptiveChatTrail.test.d.ts.map +1 -0
  17. package/dist/AdaptiveChipsStrip.d.ts +1156 -0
  18. package/dist/AdaptiveChipsStrip.d.ts.map +1 -0
  19. package/dist/AdaptiveChipsStrip.js +11 -0
  20. package/dist/AdaptiveChipsStrip.js.map +7 -0
  21. package/dist/AdaptiveChipsStripMountable.d.ts +24 -0
  22. package/dist/AdaptiveChipsStripMountable.d.ts.map +1 -0
  23. package/dist/ChatAssistantLit.d.ts +22 -50
  24. package/dist/ChatAssistantLit.d.ts.map +1 -1
  25. package/dist/ChatAssistantLit.js +6 -3
  26. package/dist/ChatSession.d.ts +239 -0
  27. package/dist/ChatSession.d.ts.map +1 -0
  28. package/dist/ChatTransport.d.ts +390 -0
  29. package/dist/ChatTransport.d.ts.map +1 -0
  30. package/dist/InlineRegistryWidgetMount.test.d.ts +2 -0
  31. package/dist/InlineRegistryWidgetMount.test.d.ts.map +1 -0
  32. package/dist/InlineWidgetLiveMount.test.d.ts +2 -0
  33. package/dist/InlineWidgetLiveMount.test.d.ts.map +1 -0
  34. package/dist/NavLinkMountable.d.ts +25 -0
  35. package/dist/NavLinkMountable.d.ts.map +1 -0
  36. package/dist/NavLinkMountable.test.d.ts +2 -0
  37. package/dist/NavLinkMountable.test.d.ts.map +1 -0
  38. package/dist/TextAnswerMountable.d.ts +17 -0
  39. package/dist/TextAnswerMountable.d.ts.map +1 -0
  40. package/dist/TextAnswerMountable.test.d.ts +2 -0
  41. package/dist/TextAnswerMountable.test.d.ts.map +1 -0
  42. package/dist/Turnstile.d.ts +83 -0
  43. package/dist/Turnstile.d.ts.map +1 -0
  44. package/dist/chunk-A7RBZLIX.js +1678 -0
  45. package/dist/chunk-A7RBZLIX.js.map +7 -0
  46. package/dist/chunk-EACGDSJI.js +237 -0
  47. package/dist/chunk-EACGDSJI.js.map +7 -0
  48. package/dist/chunk-EWPPVPJ4.js +14 -0
  49. package/dist/chunk-EWPPVPJ4.js.map +7 -0
  50. package/dist/chunk-FXHYE6FY.js +632 -0
  51. package/dist/chunk-FXHYE6FY.js.map +7 -0
  52. package/dist/chunk-OIGVZGSX.js +641 -0
  53. package/dist/chunk-OIGVZGSX.js.map +7 -0
  54. package/dist/chunk-VZIUXXAM.js +4015 -0
  55. package/dist/chunk-VZIUXXAM.js.map +7 -0
  56. package/dist/{chunk-W457NMGD.js → chunk-ZXV4GXMO.js} +2149 -4254
  57. package/dist/chunk-ZXV4GXMO.js.map +7 -0
  58. package/dist/elements/ActionHandler.d.ts +34 -0
  59. package/dist/elements/ActionHandler.d.ts.map +1 -0
  60. package/dist/elements/ElementInstanceStore.d.ts +217 -0
  61. package/dist/elements/ElementInstanceStore.d.ts.map +1 -0
  62. package/dist/elements/ElementInstanceStore.test.d.ts +2 -0
  63. package/dist/elements/ElementInstanceStore.test.d.ts.map +1 -0
  64. package/dist/elements/ElementTypeHandler.d.ts +77 -0
  65. package/dist/elements/ElementTypeHandler.d.ts.map +1 -0
  66. package/dist/elements/ItemHandler.d.ts +60 -0
  67. package/dist/elements/ItemHandler.d.ts.map +1 -0
  68. package/dist/elements/ItemHandler.test.d.ts +2 -0
  69. package/dist/elements/ItemHandler.test.d.ts.map +1 -0
  70. package/dist/elements/TileHandler.d.ts +52 -0
  71. package/dist/elements/TileHandler.d.ts.map +1 -0
  72. package/dist/elements/TileHandler.test.d.ts +2 -0
  73. package/dist/elements/TileHandler.test.d.ts.map +1 -0
  74. package/dist/elements/__tests__/ElementInstanceStore.recall.test.d.ts +2 -0
  75. package/dist/elements/__tests__/ElementInstanceStore.recall.test.d.ts.map +1 -0
  76. package/dist/elements/blockRenderer.d.ts +46 -0
  77. package/dist/elements/blockRenderer.d.ts.map +1 -0
  78. package/dist/elements/blockRenderer.test.d.ts +13 -0
  79. package/dist/elements/blockRenderer.test.d.ts.map +1 -0
  80. package/dist/elements/blocks.d.ts +58 -0
  81. package/dist/elements/blocks.d.ts.map +1 -0
  82. package/dist/elements/envelope.d.ts +24 -0
  83. package/dist/elements/envelope.d.ts.map +1 -0
  84. package/dist/elements/fetcher.d.ts +40 -0
  85. package/dist/elements/fetcher.d.ts.map +1 -0
  86. package/dist/elements/index.d.ts +33 -0
  87. package/dist/elements/index.d.ts.map +1 -0
  88. package/dist/elements/store-singleton.d.ts +4 -0
  89. package/dist/elements/store-singleton.d.ts.map +1 -0
  90. package/dist/elements/types.d.ts +110 -0
  91. package/dist/elements/types.d.ts.map +1 -0
  92. package/dist/observer/__tests__/allowlist.test.d.ts +9 -0
  93. package/dist/observer/__tests__/allowlist.test.d.ts.map +1 -0
  94. package/dist/observer/__tests__/bus-translate.test.d.ts +16 -0
  95. package/dist/observer/__tests__/bus-translate.test.d.ts.map +1 -0
  96. package/dist/observer/__tests__/lifecycle.test.d.ts +2 -0
  97. package/dist/observer/__tests__/lifecycle.test.d.ts.map +1 -0
  98. package/dist/observer/__tests__/observer-enrich.test.d.ts +10 -0
  99. package/dist/observer/__tests__/observer-enrich.test.d.ts.map +1 -0
  100. package/dist/observer/__tests__/observer-isolation.test.d.ts +13 -0
  101. package/dist/observer/__tests__/observer-isolation.test.d.ts.map +1 -0
  102. package/dist/observer/__tests__/queue.test.d.ts +2 -0
  103. package/dist/observer/__tests__/queue.test.d.ts.map +1 -0
  104. package/dist/observer/__tests__/transport.test.d.ts +2 -0
  105. package/dist/observer/__tests__/transport.test.d.ts.map +1 -0
  106. package/dist/observer/allowlist.d.ts +30 -0
  107. package/dist/observer/allowlist.d.ts.map +1 -0
  108. package/dist/observer/bus-translate.d.ts +33 -0
  109. package/dist/observer/bus-translate.d.ts.map +1 -0
  110. package/dist/observer/index.d.ts +44 -0
  111. package/dist/observer/index.d.ts.map +1 -0
  112. package/dist/observer/queue.d.ts +63 -0
  113. package/dist/observer/queue.d.ts.map +1 -0
  114. package/dist/observer/transport.d.ts +27 -0
  115. package/dist/observer/transport.d.ts.map +1 -0
  116. package/dist/personas.d.ts +30 -0
  117. package/dist/personas.d.ts.map +1 -0
  118. package/dist/runtime.d.ts +9 -0
  119. package/dist/runtime.d.ts.map +1 -1
  120. package/dist/runtime.js +2345 -3
  121. package/dist/runtime.js.map +4 -4
  122. package/dist/schema.d.ts +3426 -17
  123. package/dist/schema.d.ts.map +1 -1
  124. package/dist/schema.js +213 -0
  125. package/dist/schema.js.map +2 -2
  126. package/dist/test/setup.d.ts +1 -0
  127. package/dist/test/setup.d.ts.map +1 -0
  128. package/dist/types.d.ts +46 -2
  129. package/dist/types.d.ts.map +1 -1
  130. package/package.json +17 -1
  131. package/dist/chunk-W457NMGD.js.map +0 -7
@@ -0,0 +1,469 @@
1
+ /**
2
+ * AdaptiveChatTrail — the "bubble-up" message column that sits above the
3
+ * chat bar in the canvas lid.
4
+ *
5
+ * Messages appear immediately above the chat bar and drift upward as
6
+ * newer ones arrive. Each stack position carries an opacity + blur
7
+ * falloff so older messages read as fading from the page. Beyond a
8
+ * `visibleCount` cap (default 3) the trail collapses into an "N more ·
9
+ * expand" affordance — clicking emits `trail-expand`.
10
+ *
11
+ * Shadow DOM (default Lit open root) so chip styles, markdown reset
12
+ * rules, and animation @keyframes are scoped to this element's tree.
13
+ * Theme CSS variables (--sc-tile-text-color, --sc-content-bubble-*,
14
+ * etc.) inherit through the shadow boundary, so canvas-level theming
15
+ * still reaches the chips. The earlier light-DOM render-root override
16
+ * silently broke @keyframes lookup once the trail was hosted inside
17
+ * any shadow root (sc-mount, velvet-mobile, etc.) — keyframes injected
18
+ * into `document.head` aren't visible from another tree scope.
19
+ *
20
+ * See PRD §4.3 (chat trail) for the canonical motion + falloff spec.
21
+ */
22
+ import { LitElement, nothing } from 'lit';
23
+ export interface TrailToolCall {
24
+ id: string;
25
+ name: string;
26
+ status: 'args-streaming' | 'pending' | 'running' | 'done' | 'error';
27
+ /**
28
+ * Parsed tool-call arguments, when available. Threaded through from
29
+ * the AG-UI `ToolCall.args` so the trail can render argument-derived
30
+ * affordances WITHOUT a new transport: an activity receipt for a
31
+ * `primary_response_action` mount (derives type + label from
32
+ * `template_id` / `content.title`) and inline reply chips for a
33
+ * `suggest_replies` call (reads the `replies` array). Undefined while
34
+ * args are still streaming or for tools whose args we don't surface.
35
+ */
36
+ args?: Record<string, unknown>;
37
+ }
38
+ export interface TrailMessage {
39
+ /** Stable identity for keyed rendering (must be unique within the trail). */
40
+ id: number | string;
41
+ role: 'user' | 'assistant' | 'system';
42
+ text: string;
43
+ /** Streaming → assistant text still arriving from backend. Complete → final. Error → fatal during stream. */
44
+ status?: 'streaming' | 'complete' | 'error';
45
+ /** Tool calls attached to an assistant message (rendered as compact chips). */
46
+ toolCalls?: TrailToolCall[];
47
+ }
48
+ export type TileReceipt = {
49
+ kind: 'tile';
50
+ instanceId: string;
51
+ title: string;
52
+ dismissed: boolean;
53
+ turnId?: string;
54
+ toolCallId?: string;
55
+ } | {
56
+ kind: 'alert';
57
+ instanceId: string;
58
+ title: string;
59
+ turnId?: string;
60
+ toolCallId?: string;
61
+ };
62
+ /**
63
+ * A widget the backend wants rendered INLINE IN THE CHAT TRAIL (in the
64
+ * conversation flow, like a rich message) — currently the reco carousel.
65
+ * Sourced from `ElementInstanceStore.listInlineWidgets()` (backend
66
+ * `chat-inline` slot mounts) and forwarded by AdaptiveChatBar.
67
+ *
68
+ * The trail mounts `tag` by name via `document.createElement` and assigns
69
+ * the payload as one `props` object property (`el.props = props`, the
70
+ * standard tile-widget mount contract) — it never imports the widget package (the
71
+ * element self-defines when its own bundle loads; on demos both bundles
72
+ * are present). If `tag` is not a defined custom element, the trail
73
+ * renders NOTHING for it (no broken box).
74
+ */
75
+ export interface InlineTrailWidget {
76
+ instanceId: string;
77
+ /**
78
+ * The mount identifier for the widget. For self-defining, server-mounted
79
+ * widgets this IS the custom-element tag (e.g. `syntro-product-reco-carousel`)
80
+ * and the trail creates it directly. For admin-template widgets it is the
81
+ * runtime widget-id (e.g. `adaptive-product:card`, `adaptive-faq:accordion`),
82
+ * which is NOT a valid custom-element tag — those mount through the runtime
83
+ * widget registry via {@link InlineWidgetMounter}, which resolves the id to
84
+ * its real element exactly like the deck `SyntroTileCard` path.
85
+ */
86
+ tag: string;
87
+ props: Record<string, unknown>;
88
+ /**
89
+ * `mounted_by.turn_id` of the element — the id of the user message that
90
+ * triggered the mounting turn. Lets the trail restore the widget to its
91
+ * original transcript position after a reload (see `_anchorFromTurn`).
92
+ */
93
+ turnId?: string;
94
+ /**
95
+ * `tool_call_id` of the mount call that created the element — pins the
96
+ * restored widget to the exact transcript message hosting that call
97
+ * (see `_anchorFromToolCall`); `turnId` is the coarser fallback.
98
+ */
99
+ toolCallId?: string;
100
+ }
101
+ /**
102
+ * Mounts a registry-registered widget (by its runtime widget-id) into
103
+ * `container` and returns the created element plus an unmount cleanup.
104
+ * Injected from the chat-bar mountable, bound to `runtime.widgets`. Lets the
105
+ * trail render inline tiles whose widget-id is not their custom-element tag
106
+ * (product card, comparison, FAQ accordion) — the registry owns the
107
+ * id → element resolution. Returns `null` when the id is not registered.
108
+ */
109
+ export type InlineWidgetMounter = (widgetId: string, container: HTMLElement, props: Record<string, unknown>) => {
110
+ element: HTMLElement;
111
+ cleanup: () => void;
112
+ } | null;
113
+ export declare class AdaptiveChatTrail extends LitElement {
114
+ static styles: import("lit").CSSResult;
115
+ static properties: {
116
+ messages: {
117
+ attribute: boolean;
118
+ };
119
+ visibleCount: {
120
+ type: NumberConstructor;
121
+ };
122
+ expanded: {
123
+ type: BooleanConstructor;
124
+ };
125
+ greeting: {
126
+ type: StringConstructor;
127
+ };
128
+ /** When true: trail renders fully expanded AND the
129
+ * expand/collapse affordance is hidden. Used by hosts that mount
130
+ * the chat in a full-screen surface (the mobile panel) where
131
+ * collapse makes no sense — there's nothing to collapse INTO. */
132
+ forceExpanded: {
133
+ type: BooleanConstructor;
134
+ };
135
+ /**
136
+ * Mirrors `chatSession.inFlight` — true between `send()` and the
137
+ * assistant's first `receiveStart`/`receiveDelta`, OR while a
138
+ * stream is in progress. Drives the "thinking" indicator that
139
+ * fills the gap between the user's just-sent message and the
140
+ * first assistant token. Wired through AdaptiveChatBar (it owns
141
+ * the chatSession subscription and forwards inFlight as a prop).
142
+ */
143
+ inFlight: {
144
+ type: BooleanConstructor;
145
+ };
146
+ /**
147
+ * Live reasoning narration streamed from the model via AG-UI
148
+ * `THINKING_TEXT_MESSAGE_CONTENT`. When non-empty, the thinking
149
+ * chip renders this in place of the bouncing dots so the visitor
150
+ * sees what the model is actually doing instead of staring at
151
+ * silent loading state during a tool-call gap.
152
+ */
153
+ thinkingText: {
154
+ attribute: boolean;
155
+ };
156
+ personaName: {
157
+ attribute: boolean;
158
+ };
159
+ personaAvatarSm: {
160
+ attribute: boolean;
161
+ };
162
+ /**
163
+ * Pre-conversation suggestion chip. When the visitor opens the
164
+ * chat and `messages` is empty, the trail renders this as a
165
+ * button beneath the greeting. Clicking it dispatches a
166
+ * `trail-intro-suggestion` event with the configured prompt —
167
+ * the parent (chat-bar) forwards that to chatSession.send().
168
+ * Disappears the moment the first message lands.
169
+ */
170
+ introSuggestion: {
171
+ attribute: boolean;
172
+ };
173
+ /**
174
+ * Tappable tile-receipt chips rendered once at the end of the
175
+ * trail. Produced from the store by Task 3 (AdaptiveChatBar).
176
+ * Each chip emits `tile-receipt-activate` with its instanceId.
177
+ */
178
+ tileReceipts: {
179
+ attribute: boolean;
180
+ };
181
+ /**
182
+ * Widgets rendered INLINE in the trail (reco carousel etc.),
183
+ * anchored to a message position like receipts. Sourced from the
184
+ * store's `chat-inline` slot mounts via AdaptiveChatBar.
185
+ */
186
+ inlineWidgets: {
187
+ attribute: boolean;
188
+ };
189
+ /**
190
+ * Registry-backed mounter for inline widgets whose id is not their
191
+ * custom-element tag. Injected from the chat-bar mountable.
192
+ */
193
+ mountInlineWidget: {
194
+ attribute: boolean;
195
+ };
196
+ _messagesBelow: {
197
+ state: boolean;
198
+ };
199
+ };
200
+ messages: TrailMessage[];
201
+ tileReceipts: TileReceipt[];
202
+ inlineWidgets: InlineTrailWidget[];
203
+ mountInlineWidget: InlineWidgetMounter | undefined;
204
+ visibleCount: number;
205
+ expanded: boolean;
206
+ forceExpanded: boolean;
207
+ inFlight: boolean;
208
+ thinkingText: string;
209
+ /** Persona identity (FEAT-1784917430) — name + small avatar for assistant
210
+ * turn-start chips and the thinking indicator. Empty = legacy rendering. */
211
+ personaName: string;
212
+ personaAvatarSm: string;
213
+ /** True when `m` opens an assistant run (previous visible message is not
214
+ * assistant) — the persona byline renders once per turn, not per chip. */
215
+ private _isAssistantTurnStart;
216
+ introSuggestion: {
217
+ label: string;
218
+ prompt: string;
219
+ } | undefined;
220
+ /**
221
+ * Pre-conversation phantom assistant message. Rendered only when
222
+ * `messages` is empty. NOT injected into chatSession state — the
223
+ * greeting is configuration, not conversation, so it disappears
224
+ * automatically when the first real message arrives.
225
+ */
226
+ greeting: string | undefined;
227
+ /** Follow the bottom on content growth. On by default (history
228
+ * browsing); off from a new user message until the visitor opts back in
229
+ * (pill tap or a user-gesture scroll that reaches the bottom). */
230
+ private _stickToBottom;
231
+ /** The user message the current turn is anchored to. */
232
+ private _anchorMsgId;
233
+ /** Whether a turn anchor is live (drives expand-mid-turn landing). */
234
+ private _anchorActive;
235
+ /** Keep enforcing chip-at-top on updates (late geometry, mode flips)
236
+ * until the user scrolls or opts into following. */
237
+ private _anchorHold;
238
+ /** Number of messages whose BOTTOM edge is still below the viewport —
239
+ * messages the visitor hasn't scrolled past yet. Drives the
240
+ * "⌄ N messages" pill and stays accurate as they scroll (one long
241
+ * streaming reply counts as 1 until its end has been read). Reactive. */
242
+ private _messagesBelow;
243
+ /** Timestamp of the last user scroll gesture (wheel/touch): scroll
244
+ * events outside this window are programmatic (our own pin/anchor) and
245
+ * must not re-engage following — anchoring the newest message clamps AT
246
+ * the bottom in any longer conversation. */
247
+ private _lastUserScrollIntentTs;
248
+ private static readonly _AT_BOTTOM_EPSILON_PX;
249
+ private static readonly _USER_SCROLL_INTENT_WINDOW_MS;
250
+ private get _scrollable();
251
+ private _trailContainer;
252
+ private _isAtBottom;
253
+ /** Count chips whose bottom edge hasn't entered the viewport yet. */
254
+ private _countMessagesBelow;
255
+ private _syncContentBelow;
256
+ private _markUserScrollIntent;
257
+ private _onTrailScroll;
258
+ /** Pill tap: jump to the newest content and follow for the rest of the turn. */
259
+ private _onScrollToRecent;
260
+ /** Scroll so the anchored user chip sits at the top of the trail
261
+ * viewport. Idempotent — safe to re-apply on every update while the
262
+ * hold is live (content grows BELOW the anchor, so the target is
263
+ * stable; re-applying also covers late geometry, e.g. expanding
264
+ * mid-turn from the ambient strip). */
265
+ private _applyAnchor;
266
+ private _pinToBottom;
267
+ private _onExpand;
268
+ /**
269
+ * Approve a pending client tool call. The trail emits a generic
270
+ * event so the host can decide whether to forward to chatSession
271
+ * (the common path) or override. Keeps the trail itself free of
272
+ * direct chatSession coupling — it's a pure view component.
273
+ */
274
+ private _onToolCallClick;
275
+ private _onCollapse;
276
+ /**
277
+ * Whether to render the thinking-dots chip after the last message.
278
+ * True iff a request is in flight AND the assistant hasn't started
279
+ * streaming a reply yet — once the first delta lands, the streaming
280
+ * chip's caret takes over and the thinking indicator hides so the
281
+ * visitor isn't shown both at once. Also hidden when the last
282
+ * message is an error/system message, because the request that
283
+ * "errored" is already over from the user's perspective.
284
+ */
285
+ private _shouldShowThinking;
286
+ /**
287
+ * instanceId → id of the message that was newest when the receipt first
288
+ * appeared. This is what makes a receipt read like a chat bubble: it renders
289
+ * inline right after its anchor message, so newer messages push it up into
290
+ * history instead of it staying pinned below everything. Assigned once per
291
+ * instanceId (in willUpdate, the only place that sees both `messages` and
292
+ * `tileReceipts` at the moment a tile mounts) and never re-homed — a
293
+ * dismiss/bring-back keeps the chip where it was created. `null` = the tile
294
+ * mounted before the first chat message (canvas replay); those fall to the
295
+ * tail strip (see render).
296
+ */
297
+ private readonly _receiptAnchors;
298
+ /**
299
+ * instanceId → anchor message id for inline widgets — same mechanism as
300
+ * `_receiptAnchors`. The inline carousel renders right after the message
301
+ * that was newest when it mounted, so it reads like a rich reply and
302
+ * drifts up into history as later messages append.
303
+ */
304
+ private readonly _inlineAnchors;
305
+ /**
306
+ * instanceId → the cached inline widget entry (render node + props target +
307
+ * optional registry cleanup). Cached so a prop patch (same instanceId, new
308
+ * props) updates the EXISTING element instead of tearing it down and
309
+ * re-creating it — which would reset the carousel's scroll position +
310
+ * internal state. Created lazily the first time we see the widget:
311
+ * `document.createElement(tag)` for a defined tag, or a registry mount for a
312
+ * widget-id. An unresolvable widget caches `null` so the fail-safe renders
313
+ * nothing without re-checking the registry.
314
+ */
315
+ private readonly _inlineElements;
316
+ disconnectedCallback(): void;
317
+ /**
318
+ * The id of the newest message the render will actually PAINT — the only
319
+ * valid anchor target. Anchoring to the raw last message is wrong-by-
320
+ * construction for tool-call turns: mid-turn the newest message is often a
321
+ * whitespace-only assistant shell (some providers emit whitespace text
322
+ * deltas around tool calls) that the empty-bubble filter drops, so an
323
+ * anchor recorded on it can never be in the painted set and the receipt
324
+ * falls to the tail strip forever — resurrecting BUG-1783015943 (seen live
325
+ * on vela desktop, BUG-1783630187). `isSuggestionHost=false` here: a
326
+ * message whose ONLY content is reply chips is too ephemeral to anchor on
327
+ * (the chips clear when the visitor answers), so walk past it too.
328
+ */
329
+ private _newestRenderableMessageId;
330
+ /**
331
+ * Server-authoritative anchor for a restored element: `turnId` is the
332
+ * persisted `mounted_by.turn_id` — the id of the user message that
333
+ * triggered the mounting turn. The element anchors to the first
334
+ * content-bearing assistant message of that turn (where it appeared live:
335
+ * intro text, then the mount, then any follow-up), falling back to the
336
+ * turn's user message when the assistant hasn't produced renderable text.
337
+ * Returns null when `turnId` is absent or not in the transcript (nudge
338
+ * mounts carry a runId) — the caller then uses the legacy
339
+ * newest-renderable anchor. Without this, a reload assigned every element
340
+ * to the newest message of the fully restored transcript, dumping all
341
+ * inline views below the last message (the arrival-timing bug).
342
+ */
343
+ /**
344
+ * Exact restore anchor: `toolCallId` is the persisted id of the tool call
345
+ * that mounted the element, and the transcript message hosting that call
346
+ * carries it in `toolCalls`. Anchor to the host message itself when it
347
+ * renders content, else walk BACK to the nearest renderable message — a
348
+ * standalone tool-call message persists with empty content and must not
349
+ * strand the element. This survives every turn shape (text→mount,
350
+ * text→text→mount, mount→text); `_anchorFromTurn` is the coarser fallback
351
+ * for elements persisted before tool_call_id existed.
352
+ */
353
+ private _anchorFromToolCall;
354
+ private _anchorFromTurn;
355
+ willUpdate(changed: Map<string, unknown>): void;
356
+ /**
357
+ * Create (once) or refresh the cached element for an inline widget.
358
+ *
359
+ * Two mount paths, both keeping the chat bundle free of any widget-package
360
+ * import:
361
+ * - Direct tag (self-defining, server-mounted widgets like the reco
362
+ * carousel whose declared `widget` IS its custom-element tag):
363
+ * `document.createElement(tag)`.
364
+ * - Widget-id (admin-template widgets like `adaptive-product:card` or
365
+ * `adaptive-faq:accordion`, whose `widget` is a runtime widget-id, NOT a
366
+ * valid custom-element tag): mount through the runtime widget registry
367
+ * via {@link mountInlineWidget}, which resolves the id to its real
368
+ * element exactly like the deck `SyntroTileCard` path. Without this,
369
+ * `createElement('adaptive-product:card')` yields an inert unknown
370
+ * element and the tile renders permanently blank (the "inline mode
371
+ * shows nothing but the reco" bug).
372
+ *
373
+ * Fail-safe: an id that resolves to neither a defined tag nor a registered
374
+ * widget caches `null` and renders nothing (no broken box).
375
+ */
376
+ private _ensureInlineElement;
377
+ updated(changed: Map<string, unknown>): void;
378
+ private _onTileReceiptClick;
379
+ private _onAlertReceiptClick;
380
+ /** Render a set of inline widgets (reco carousel etc.) as
381
+ * `[data-trail-widget]` blocks, anchored to a message position like
382
+ * receipts. Each block hosts the cached custom element for that
383
+ * instanceId — a defined tag mounts inline; an undefined tag renders
384
+ * nothing (fail-safe). Rendered at every trail site (inline per anchor,
385
+ * tail, empty-state) so placement can't diverge. */
386
+ private _renderInlineWidgetStrip;
387
+ /** A row of receipt chips, used at every trail render site (inline per
388
+ * anchor message, the tail fallback, and the empty-state branches) so the
389
+ * markup + styling can never diverge. Returns `nothing` for an empty list. */
390
+ private _renderReceiptStrip;
391
+ /** One receipt chip — a single, unified, single-line design for both kinds
392
+ * (nav "alert" + mounted "tile"). Same container/title/action style so they
393
+ * read as one chip family; the icon + action label carry the kind. No
394
+ * subtitle: the old "Brought up earlier" line was hardcoded (wrong for
395
+ * same-turn mounts) and made the chip taller — dropping it is the "shorter"
396
+ * chip. Rendered at every trail site so the kinds can't diverge. */
397
+ private _renderReceiptChip;
398
+ private _onIntroSuggestionClick;
399
+ /**
400
+ * Visitor tapped a `suggest_replies` inline chip. Emit
401
+ * `trail-suggested-reply` carrying the chip text — the parent
402
+ * (AdaptiveChatBar) re-dispatches it as `chat-message-sent`, the
403
+ * SAME channel the input row uses, so the reply rides the existing
404
+ * send path (mountable → chatSession.send → transport). No fabricated
405
+ * AG-UI events; this is exactly what typing the text and hitting
406
+ * Enter would do. The chips clear on their own once the reply lands
407
+ * and a newer assistant message becomes the latest.
408
+ */
409
+ private _onSuggestedReplyClick;
410
+ render(): typeof nothing | import("lit-html").TemplateResult<1>;
411
+ }
412
+ /**
413
+ * Discriminated visual state for a chip. Replaces the older
414
+ * `(role, { isStreaming, isError })` triple whose interaction order
415
+ * could produce nonsense combinations (e.g. an assistant chip
416
+ * accidentally reading as a user bubble because `isStreaming` was
417
+ * checked before role). Each kind below is a real conversational
418
+ * state with a single visual identity:
419
+ *
420
+ * - `settled` — a complete message; the user-vs-assistant
421
+ * identity comes from `role`
422
+ * - `streaming` — the assistant chip currently receiving tokens;
423
+ * keeps assistant identity (the blinking caret
424
+ * inside the chip carries "in progress")
425
+ * - `pending` — the thinking chip shown between the user's
426
+ * just-sent message and the assistant's first
427
+ * token; assistant identity (the bouncing dots
428
+ * inside carry "in progress")
429
+ * - `error` — a chip whose stream failed mid-flight, OR any
430
+ * system-role message (system messages render
431
+ * with the error identity by convention)
432
+ *
433
+ * Bug history: an earlier branch-ladder design checked `isStreaming`
434
+ * before `role`, so the `pending`/thinking chip inherited the user
435
+ * bubble border. On hosts whose chat panel sits over a light surface
436
+ * that read as a "white div" pasted into the assistant slot. The
437
+ * discriminated state prevents that combination from being expressible.
438
+ */
439
+ export type ChipVisualState = {
440
+ kind: 'settled';
441
+ role: 'user' | 'assistant' | 'system';
442
+ } | {
443
+ kind: 'streaming';
444
+ } | {
445
+ kind: 'pending';
446
+ } | {
447
+ kind: 'notice';
448
+ role: 'user' | 'assistant' | 'system';
449
+ };
450
+ /**
451
+ * A misbehaving model can emit a raw SERIALIZED response payload as plain TEXT
452
+ * on a spurious trailing turn — e.g.
453
+ * `(Empty response: {'content': [{'type': 'thinking', …}], 'stop_reason': …})`.
454
+ * Backstop for model degeneration (Kimi); the prompt (S-14) also asks for one
455
+ * brief closing, but copy can't be trusted on the very turn that degenerates.
456
+ *
457
+ * Detection avoids false positives (which are WORSE than the dump — the visitor
458
+ * would see nothing): a turn is dropped only if it OPENS with the literal
459
+ * "(Empty response" marker, OR it carries ≥2 serialization tokens at once. A
460
+ * single token (a product about a "signature blend", the agent quoting one JSON
461
+ * key) never trips it; a real response dump carries all of them.
462
+ */
463
+ export declare function looksLikeSerializedModelResponse(text: string): boolean;
464
+ declare global {
465
+ interface HTMLElementTagNameMap {
466
+ 'adaptive-chat-trail': AdaptiveChatTrail;
467
+ }
468
+ }
469
+ //# sourceMappingURL=AdaptiveChatTrail.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AdaptiveChatTrail.d.ts","sourceRoot":"","sources":["../src/AdaptiveChatTrail.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,EAAa,UAAU,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAIrD,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,gBAAgB,GAAG,SAAS,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,CAAC;IACpE;;;;;;;;OAQG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,YAAY;IAC3B,6EAA6E;IAC7E,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,6GAA6G;IAC7G,MAAM,CAAC,EAAE,WAAW,GAAG,UAAU,GAAG,OAAO,CAAC;IAC5C,+EAA+E;IAC/E,SAAS,CAAC,EAAE,aAAa,EAAE,CAAC;CAC7B;AAED,MAAM,MAAM,WAAW,GACnB;IACE,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GACD;IAAE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AAgC,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAStE;AAmaD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,qBAAqB,EAAE,iBAAiB,CAAC;KAC1C;CACF"}
@@ -0,0 +1,11 @@
1
+ import {
2
+ AdaptiveChatTrail,
3
+ looksLikeSerializedModelResponse
4
+ } from "./chunk-A7RBZLIX.js";
5
+ import "./chunk-VZIUXXAM.js";
6
+ import "./chunk-UVKRO5ER.js";
7
+ export {
8
+ AdaptiveChatTrail,
9
+ looksLikeSerializedModelResponse
10
+ };
11
+ //# sourceMappingURL=AdaptiveChatTrail.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ import './AdaptiveChatTrail';
2
+ //# sourceMappingURL=AdaptiveChatTrail.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AdaptiveChatTrail.test.d.ts","sourceRoot":"","sources":["../src/AdaptiveChatTrail.test.ts"],"names":[],"mappings":"AAgBA,OAAO,qBAAqB,CAAC"}