@syntrologie/adapt-chatbot 2.26.0 → 2.28.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 (99) hide show
  1. package/dist/AdaptiveChatBar.d.ts +76 -0
  2. package/dist/AdaptiveChatBar.d.ts.map +1 -0
  3. package/dist/AdaptiveChatBar.js +10 -0
  4. package/dist/AdaptiveChatBar.js.map +7 -0
  5. package/dist/AdaptiveChatBarMountable.d.ts +35 -0
  6. package/dist/AdaptiveChatBarMountable.d.ts.map +1 -0
  7. package/dist/AdaptiveChatTrail.d.ts +77 -0
  8. package/dist/AdaptiveChatTrail.d.ts.map +1 -0
  9. package/dist/AdaptiveChatTrail.js +9 -0
  10. package/dist/AdaptiveChatTrail.js.map +7 -0
  11. package/dist/AdaptiveChipsStrip.d.ts +1150 -0
  12. package/dist/AdaptiveChipsStrip.d.ts.map +1 -0
  13. package/dist/AdaptiveChipsStrip.js +11 -0
  14. package/dist/AdaptiveChipsStrip.js.map +7 -0
  15. package/dist/AdaptiveChipsStripMountable.d.ts +24 -0
  16. package/dist/AdaptiveChipsStripMountable.d.ts.map +1 -0
  17. package/dist/ChatAssistantLit.d.ts +23 -21
  18. package/dist/ChatAssistantLit.d.ts.map +1 -1
  19. package/dist/ChatAssistantLit.js +5 -3
  20. package/dist/ChatSession.d.ts +178 -0
  21. package/dist/ChatSession.d.ts.map +1 -0
  22. package/dist/ChatTransport.d.ts +283 -0
  23. package/dist/ChatTransport.d.ts.map +1 -0
  24. package/dist/NavLinkMountable.d.ts +25 -0
  25. package/dist/NavLinkMountable.d.ts.map +1 -0
  26. package/dist/NavLinkMountable.test.d.ts +2 -0
  27. package/dist/NavLinkMountable.test.d.ts.map +1 -0
  28. package/dist/TextAnswerMountable.d.ts +17 -0
  29. package/dist/TextAnswerMountable.d.ts.map +1 -0
  30. package/dist/Turnstile.d.ts +83 -0
  31. package/dist/Turnstile.d.ts.map +1 -0
  32. package/dist/chunk-435KJD27.js +192 -0
  33. package/dist/chunk-435KJD27.js.map +7 -0
  34. package/dist/chunk-AUER7ZCK.js +634 -0
  35. package/dist/chunk-AUER7ZCK.js.map +7 -0
  36. package/dist/chunk-DOMEUJR7.js +382 -0
  37. package/dist/chunk-DOMEUJR7.js.map +7 -0
  38. package/dist/{chunk-O7RWNUVU.js → chunk-KUO67E2W.js} +1573 -4079
  39. package/dist/chunk-KUO67E2W.js.map +7 -0
  40. package/dist/chunk-QELVKBQV.js +214 -0
  41. package/dist/chunk-QELVKBQV.js.map +7 -0
  42. package/dist/chunk-UC4XU6GH.js +3306 -0
  43. package/dist/chunk-UC4XU6GH.js.map +7 -0
  44. package/dist/elements/ActionHandler.d.ts +34 -0
  45. package/dist/elements/ActionHandler.d.ts.map +1 -0
  46. package/dist/elements/ElementInstanceStore.d.ts +155 -0
  47. package/dist/elements/ElementInstanceStore.d.ts.map +1 -0
  48. package/dist/elements/ElementInstanceStore.test.d.ts +2 -0
  49. package/dist/elements/ElementInstanceStore.test.d.ts.map +1 -0
  50. package/dist/elements/ElementTypeHandler.d.ts +77 -0
  51. package/dist/elements/ElementTypeHandler.d.ts.map +1 -0
  52. package/dist/elements/ItemHandler.d.ts +60 -0
  53. package/dist/elements/ItemHandler.d.ts.map +1 -0
  54. package/dist/elements/ItemHandler.test.d.ts +2 -0
  55. package/dist/elements/ItemHandler.test.d.ts.map +1 -0
  56. package/dist/elements/TileHandler.d.ts +52 -0
  57. package/dist/elements/TileHandler.d.ts.map +1 -0
  58. package/dist/elements/blockRenderer.d.ts +46 -0
  59. package/dist/elements/blockRenderer.d.ts.map +1 -0
  60. package/dist/elements/blockRenderer.test.d.ts +13 -0
  61. package/dist/elements/blockRenderer.test.d.ts.map +1 -0
  62. package/dist/elements/blocks.d.ts +58 -0
  63. package/dist/elements/blocks.d.ts.map +1 -0
  64. package/dist/elements/envelope.d.ts +24 -0
  65. package/dist/elements/envelope.d.ts.map +1 -0
  66. package/dist/elements/fetcher.d.ts +40 -0
  67. package/dist/elements/fetcher.d.ts.map +1 -0
  68. package/dist/elements/index.d.ts +32 -0
  69. package/dist/elements/index.d.ts.map +1 -0
  70. package/dist/elements/types.d.ts +106 -0
  71. package/dist/elements/types.d.ts.map +1 -0
  72. package/dist/observer/__tests__/allowlist.test.d.ts +9 -0
  73. package/dist/observer/__tests__/allowlist.test.d.ts.map +1 -0
  74. package/dist/observer/__tests__/observer-isolation.test.d.ts +13 -0
  75. package/dist/observer/__tests__/observer-isolation.test.d.ts.map +1 -0
  76. package/dist/observer/__tests__/queue.test.d.ts +2 -0
  77. package/dist/observer/__tests__/queue.test.d.ts.map +1 -0
  78. package/dist/observer/__tests__/transport.test.d.ts +2 -0
  79. package/dist/observer/__tests__/transport.test.d.ts.map +1 -0
  80. package/dist/observer/allowlist.d.ts +32 -0
  81. package/dist/observer/allowlist.d.ts.map +1 -0
  82. package/dist/observer/index.d.ts +35 -0
  83. package/dist/observer/index.d.ts.map +1 -0
  84. package/dist/observer/queue.d.ts +57 -0
  85. package/dist/observer/queue.d.ts.map +1 -0
  86. package/dist/observer/transport.d.ts +26 -0
  87. package/dist/observer/transport.d.ts.map +1 -0
  88. package/dist/runtime.d.ts +7 -0
  89. package/dist/runtime.d.ts.map +1 -1
  90. package/dist/runtime.js +1617 -2
  91. package/dist/runtime.js.map +4 -4
  92. package/dist/schema.d.ts +3120 -7
  93. package/dist/schema.d.ts.map +1 -1
  94. package/dist/schema.js +40 -0
  95. package/dist/schema.js.map +2 -2
  96. package/dist/types.d.ts +30 -2
  97. package/dist/types.d.ts.map +1 -1
  98. package/package.json +13 -1
  99. package/dist/chunk-O7RWNUVU.js.map +0 -7
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AdaptiveChipsStrip.d.ts","sourceRoot":"","sources":["../src/AdaptiveChipsStrip.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAGH,OAAO,EAAQ,UAAU,EAAW,KAAK,cAAc,EAAE,MAAM,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C,aAAa,CAIL;IAEP,gBAAgB,IAAI,WAAW;IAI/B,oBAAoB,IAAI,IAAI;IAS5B,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAiCrD,OAAO,CAAC,cAAc;IAKtB;;;;;;OAMG;IACH,OAAO,CAAC,uBAAuB;IA0C/B,0DAA0D;IAC1D,UAAU,CACR,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,QAAQ,EAAE,QAAQ,GAAG,SAAS,GAC7B,IAAI;IAWP;;mBAEe;IACf,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IASlE;yCACqC;IACrC,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IASpC;;;;;OAKG;IACH,OAAO,CAAC,kBAAkB;IAsB1B;;;;;OAKG;IACH,OAAO,CAAC,wBAAwB;IAShC,OAAO,CAAC,cAAc,CAEpB;IAEF;;;;OAIG;IACH,OAAO,CAAC,SAAS;IAOjB,OAAO,CAAC,eAAe;IAWvB;;;;;OAKG;IACH,OAAO,CAAC,iBAAiB;IAwCzB,OAAO,CAAC,YAAY;IAgBpB,OAAO,CAAC,cAAc;IAgBtB,OAAO,CAAC,eAAe,CAErB;IAEO,MAAM,IAAI,cAAc;CAsIlC;AA+OD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,sBAAsB,EAAE,kBAAkB,CAAC;KAC5C;CACF"}
@@ -0,0 +1,11 @@
1
+ import {
2
+ AdaptiveChipsStrip,
3
+ SuggestionChipSchema
4
+ } from "./chunk-AUER7ZCK.js";
5
+ import "./chunk-435KJD27.js";
6
+ import "./chunk-UVKRO5ER.js";
7
+ export {
8
+ AdaptiveChipsStrip,
9
+ SuggestionChipSchema
10
+ };
11
+ //# sourceMappingURL=AdaptiveChipsStrip.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * AdaptiveChipsStripMountable — `MountableWidget` adapter for
3
+ * `<adaptive-chips-strip>`. Registered as widget id
4
+ * `adaptive-chatbot:chips-strip`.
5
+ *
6
+ * Mirrors `AdaptiveChatBarMountable`: creates the Lit element, forwards
7
+ * props, bridges DOM events → prop callbacks, cleans up on unmount.
8
+ *
9
+ * Props (passed via mountConfig):
10
+ * - `chips: SuggestionChip[]` — the strip's contents (required)
11
+ * - `onChipRevealed?: ({id, payload}) => void` — fires when a chip
12
+ * is opened
13
+ * - `onChipDismissed?: ({id}) => void` — fires when × is clicked
14
+ *
15
+ * The runtime registry injects `runtime` into mountConfig (see
16
+ * `WidgetRegistry.mount`). We forward it as `runtimeRef` on the strip
17
+ * so it can mount chip payload widgets through the same registry.
18
+ */
19
+ import './AdaptiveChipsStrip';
20
+ export declare const AdaptiveChipsStripMountable: {
21
+ mount(container: HTMLElement, mountConfig?: Record<string, unknown>): () => void;
22
+ update(container: HTMLElement, mountConfig?: Record<string, unknown>): void;
23
+ };
24
+ //# sourceMappingURL=AdaptiveChipsStripMountable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AdaptiveChipsStripMountable.d.ts","sourceRoot":"","sources":["../src/AdaptiveChipsStripMountable.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,sBAAsB,CAAC;AA0C9B,eAAO,MAAM,2BAA2B;qBACrB,WAAW,gBAAgB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,IAAI;sBAqC9D,WAAW,gBAAgB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;CAqB5E,CAAC"}
@@ -11,13 +11,23 @@
11
11
  * `window.__SYNTRO_CONFIG__.token` (set by runtime-config.js) — we read
12
12
  * it at mount time and forward it via `Authorization: Bearer` header.
13
13
  *
14
- * 2. Cloudflare Turnstile bot-check token. When `TURNSTILE_SITEKEY` is set
15
- * (hardcoded at the top of this file — operator updates after running
16
- * terraform apply on cloudflare/turnstile in the infra repo), the
17
- * widget dynamically loads Cloudflare's Turnstile JS, renders an
18
- * invisible widget, and acquires a token before the first message.
19
- * The token is forwarded via `CF-Turnstile-Token` header.
20
- * If sitekey is empty (default), this step is skipped entirely.
14
+ * 2. Cloudflare Turnstile bot-check token. When `TURNSTILE_SITEKEY` is
15
+ * set, render a single `size: 'flexible'` widget with
16
+ * `appearance: 'interaction-only'` against a `managed`-mode sitekey:
17
+ * Clean traffic: CF passive-grades silently, token resolves in
18
+ * ~100ms, no UI is ever shown.
19
+ * Flagged traffic (datacenter IP, automation, strict-privacy):
20
+ * CF renders an "I am human" checkbox inside the in-chat verify
21
+ * panel; on solve, swap to the chat UI.
22
+ * • Total failure (CSP blocks CF, network error, user dismisses):
23
+ * fall through with no token; backend enforcement 403s and the
24
+ * existing fallback card renders.
25
+ * The widget mode MUST be `managed` on the CF side — see
26
+ * cloudflare/turnstile/main.tf in syntro-infra. (`mode = 'invisible'`
27
+ * rejects any `size` other than `invisible`, and `size: 'invisible'`
28
+ * against `mode = 'managed'` fails with a synchronous TurnstileError —
29
+ * don't mix.)
30
+ * If sitekey is empty, this step is skipped entirely.
21
31
  *
22
32
  * 3. Fallback card. If the first agent run fails (Cloudflare Turnstile
23
33
  * bot-check failure, CORS / network error, or a server-side rejection),
@@ -31,27 +41,19 @@
31
41
  * inside the chat surface.
32
42
  */
33
43
  import '@syntrologie/chat';
34
- import type { ChatbotConfig, ChatbotWidgetRuntime } from './types.js';
44
+ import type { ChatbotConfig, ChatbotFallback, ChatbotWidgetRuntime } from './types.js';
35
45
  export interface ChatAssistantLitProps {
36
46
  config: ChatbotConfig;
37
47
  runtime: ChatbotWidgetRuntime;
38
48
  tileId?: string;
39
49
  }
40
50
  /**
41
- * Acquire a Cloudflare Turnstile token. Returns null when:
42
- * TURNSTILE_SITEKEY is empty (Turnstile disabled at build time)
43
- * the script fails to load (customer CSP blocks Cloudflare, etc.)
44
- * the render callback doesn't fire within TURNSTILE_ACQUIRE_TIMEOUT_MS
45
- * • Cloudflare returns an error-callback (e.g., rate-limited, bad sitekey)
46
- *
47
- * When null is returned, the widget proceeds WITHOUT a Turnstile token.
48
- * If backend enforcement is on, the request 403s and the fallback card
49
- * renders via the existing failure-detection path. If enforcement is off,
50
- * the request succeeds.
51
- *
52
- * Exported for tests; the production code path goes through `mount()`.
51
+ * Build the inline HTML for the fallback card. Customer-supplied copy wins;
52
+ * everything else falls back to generic copy. The card avoids any reference
53
+ * to Cloudflare or Turnstile so the end-user is never confronted with our
54
+ * implementation details.
53
55
  */
54
- export declare function acquireTurnstileToken(): Promise<string | null>;
56
+ export declare function renderFallbackHtml(fallback: ChatbotFallback | undefined): string;
55
57
  export declare const ChatAssistantLitMountable: {
56
58
  mount(container: HTMLElement, mountConfig?: Record<string, unknown>): () => void;
57
59
  };
@@ -1 +1 @@
1
- {"version":3,"file":"ChatAssistantLit.d.ts","sourceRoot":"","sources":["../src/ChatAssistantLit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAGH,OAAO,mBAAmB,CAAC;AAK3B,OAAO,KAAK,EAAE,aAAa,EAAmB,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEvF,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,oBAAoB,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAqGD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAkDpE;AAiGD,eAAO,MAAM,yBAAyB;qBACnB,WAAW,gBAAgB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CA2LpE,CAAC"}
1
+ {"version":3,"file":"ChatAssistantLit.d.ts","sourceRoot":"","sources":["../src/ChatAssistantLit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAGH,OAAO,mBAAmB,CAAC;AAa3B,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEvF,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,oBAAoB,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AA8CD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,eAAe,GAAG,SAAS,GAAG,MAAM,CAiEhF;AAED,eAAO,MAAM,yBAAyB;qBACnB,WAAW,gBAAgB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAgbpE,CAAC"}
@@ -1,10 +1,12 @@
1
1
  import {
2
2
  ChatAssistantLitMountable,
3
- acquireTurnstileToken
4
- } from "./chunk-O7RWNUVU.js";
3
+ renderFallbackHtml
4
+ } from "./chunk-KUO67E2W.js";
5
+ import "./chunk-UC4XU6GH.js";
6
+ import "./chunk-435KJD27.js";
5
7
  import "./chunk-UVKRO5ER.js";
6
8
  export {
7
9
  ChatAssistantLitMountable,
8
- acquireTurnstileToken
10
+ renderFallbackHtml
9
11
  };
10
12
  //# sourceMappingURL=ChatAssistantLit.js.map
@@ -0,0 +1,178 @@
1
+ /**
2
+ * ChatSession — singleton holder of the chat conversation state.
3
+ *
4
+ * The chat is conceptually one thing. Whether it's rendered in the
5
+ * mini-canvas's lid, the drawer's lid, or as a tile inside any slot,
6
+ * they're all VIEWS of the same conversation. This module owns that
7
+ * shared state.
8
+ *
9
+ * Why a module-level singleton (not on `runtime`):
10
+ * - Per-page scope is the right granularity for a chat (one user,
11
+ * one conversation, however many canvas instances on the page).
12
+ * - Avoids a new SmartCanvasRuntime API surface for now. Easy to
13
+ * promote to `runtime.chat` later without breaking the widget API.
14
+ * - Module identity is stable per page; multiple imports return the
15
+ * same instance.
16
+ *
17
+ * Separation of concerns:
18
+ * - `ChatSession` owns state: messages, inFlight.
19
+ * - Views (AdaptiveChatBar via AdaptiveChatBarMountable) subscribe
20
+ * to state changes and dispatch user actions back via send() /
21
+ * interrupt().
22
+ * - Transports (the LLM call, SSE pipeline, stub timers) listen
23
+ * for "send" / "interrupt" events and eventually call receive()
24
+ * with the assistant's reply. Transports are NOT owned by this
25
+ * module — adapters live separately.
26
+ *
27
+ * No persistence in this slice. Future: snapshot to runtime.state
28
+ * for cross-session continuity.
29
+ */
30
+ import type { TrailMessage, TrailToolCall } from './AdaptiveChatTrail';
31
+ export interface ChatSessionState {
32
+ readonly messages: readonly TrailMessage[];
33
+ readonly inFlight: boolean;
34
+ }
35
+ export interface ToolResultEvent {
36
+ toolCallId: string;
37
+ result: unknown;
38
+ approved: boolean;
39
+ }
40
+ export type ChatSessionSubscriber = (state: ChatSessionState) => void;
41
+ export type SendListener = (event: {
42
+ text: string;
43
+ activeLidSlot?: string;
44
+ }) => void;
45
+ export type InterruptListener = () => void;
46
+ export type ToolResultListener = (event: ToolResultEvent) => void;
47
+ /** Optional per-send envelope. */
48
+ export interface SendOptions {
49
+ /**
50
+ * The slot the calling chat-bar lives in (e.g. ``"drawer"``,
51
+ * ``"adaptive-chat"``). Forwarded to transport listeners so the
52
+ * outbound request can tag the correct ``X-Active-Lid-Slot`` regardless
53
+ * of which bar most recently configured the singleton transport.
54
+ * Without per-send threading, two coexisting chat-bars race over the
55
+ * transport's cached ``activeLidSlot`` and the user-facing routing
56
+ * silently follows whichever bar configured last.
57
+ */
58
+ activeLidSlot?: string;
59
+ }
60
+ export type Unsubscribe = () => void;
61
+ export declare const CHAT_SESSION_STORAGE_KEY = "syntro:chat:v1";
62
+ export declare class ChatSession {
63
+ private _messages;
64
+ private _inFlight;
65
+ private _nextId;
66
+ private subscribers;
67
+ private sendListeners;
68
+ private interruptListeners;
69
+ private toolResultListeners;
70
+ constructor();
71
+ /** Snapshot the current state. Always returns a fresh immutable view. */
72
+ getState(): ChatSessionState;
73
+ /**
74
+ * Subscribe to state changes. Called immediately with the current
75
+ * state, then again on every change. Returns an unsubscribe function.
76
+ */
77
+ subscribe(cb: ChatSessionSubscriber): Unsubscribe;
78
+ /**
79
+ * User submitted a message. Appends a user-role message, sets
80
+ * inFlight=true, notifies state subscribers, and fires a "send"
81
+ * event so transports can pick it up. Empty/whitespace text is a
82
+ * no-op (matches the chat bar's local guard).
83
+ */
84
+ send(text: string, opts?: SendOptions): void;
85
+ /**
86
+ * Single-shot assistant reply (no streaming). Equivalent to
87
+ * receiveStart + receiveDelta + receiveEnd in one call. Useful for
88
+ * stub transports and tests that don't model streaming.
89
+ */
90
+ receive(text: string): void;
91
+ /**
92
+ * Begin a streaming assistant message. Appends an empty assistant
93
+ * message with status='streaming'. Caller (transport adapter) feeds
94
+ * deltas via receiveDelta(id, text) and signals completion via
95
+ * receiveEnd(id). `inFlight` stays true through the stream.
96
+ */
97
+ receiveStart(id: string): void;
98
+ /**
99
+ * Append a delta to a streaming message. No-op when the id is
100
+ * unknown (race between transport events and reset, etc.) — never
101
+ * throws so transports can fire-and-forget.
102
+ */
103
+ receiveDelta(id: string, delta: string): void;
104
+ /**
105
+ * Mark a streaming message complete and clear inFlight. No-op when
106
+ * the id is unknown (defensive against transport double-fires).
107
+ */
108
+ receiveEnd(id: string): void;
109
+ /**
110
+ * Transport reports a fatal error. Marks any in-flight streaming
111
+ * message as 'error' (so the trail can render a styled error chip
112
+ * instead of pretending the partial text was a complete answer),
113
+ * appends a system-role message with the error text for visibility,
114
+ * and clears inFlight.
115
+ */
116
+ error(message: string): void;
117
+ /**
118
+ * User clicked the in-flight stop button. Clears inFlight and
119
+ * fires an "interrupt" event so transports can cancel their
120
+ * in-flight request. No-op if not in-flight (idempotent).
121
+ */
122
+ interrupt(): void;
123
+ /**
124
+ * Wipe state. Used by the canvas-close path (start a fresh
125
+ * conversation next time) and by tests.
126
+ */
127
+ reset(): void;
128
+ /** Register a transport's send listener. Returns unsubscribe. */
129
+ onSend(listener: SendListener): Unsubscribe;
130
+ /**
131
+ * True when at least one transport has wired itself to the session's
132
+ * send pipeline. Views can use this to surface "no chat backend
133
+ * connected" affordances instead of hanging in `inFlight` after a
134
+ * send fires into the void.
135
+ */
136
+ hasTransport(): boolean;
137
+ /** Register a transport's interrupt listener. Returns unsubscribe. */
138
+ onInterrupt(listener: InterruptListener): Unsubscribe;
139
+ /**
140
+ * Register a transport's tool-result listener. The transport
141
+ * forwards `tool-result` actions back to the agent after the user
142
+ * approves or rejects a client-tool call. Returns unsubscribe.
143
+ */
144
+ onToolResult(listener: ToolResultListener): Unsubscribe;
145
+ /**
146
+ * Attach a tool call to a streaming assistant message. No-op when
147
+ * the message id is unknown (race between transport events and
148
+ * reset / late mount).
149
+ */
150
+ addToolCall(messageId: string | number, toolCall: TrailToolCall): void;
151
+ /**
152
+ * Partially update a tool call by id. Used by the transport to
153
+ * advance status (args-streaming → running → done) as AG-UI events
154
+ * arrive. No-op when the id is unknown.
155
+ */
156
+ updateToolCall(toolCallId: string, patch: Partial<TrailToolCall>): void;
157
+ /**
158
+ * Resolve a (client-) tool call. Marks the call done, persists, and
159
+ * fires onToolResult so the transport can forward the result + the
160
+ * user's approve/reject decision back to the agent. No-op when the
161
+ * id is unknown.
162
+ */
163
+ resolveToolCall(toolCallId: string, result: unknown, approved: boolean): void;
164
+ private notify;
165
+ private persist;
166
+ }
167
+ /**
168
+ * The module-level singleton. Every `<adaptive-chat-bar>` (regardless
169
+ * of which slot it lives in) reads from and writes to this instance.
170
+ * Multiple imports of this module return the same object.
171
+ *
172
+ * Scope: per-page. Correct for the canonical case (one user, one
173
+ * conversation, however many canvas views surface it). Multiple
174
+ * `<smart-canvas>` instances on the same page will share state —
175
+ * tracked in project_future_work.md for per-runtime scoping.
176
+ */
177
+ export declare const chatSession: ChatSession;
178
+ //# s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OAAO,CAAC,MAAM;IAMd,OAAO,CAAC,OAAO;CAYhB;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW,aAAoB,CAAC"}
@@ -0,0 +1,283 @@
1
+ /**
2
+ * ChatTransport — singleton transport adapter that bridges chatSession
3
+ * (the view-side state holder) to the real backend chat pipeline
4
+ * (AG-UI SSE at `/api/adaptive/stream`).
5
+ *
6
+ * This is the unification of two formerly separate paths:
7
+ * - `ChatAssistantLit` (old) owns the transport plumbing —
8
+ * AgUiTransport, Cloudflare Turnstile, headers, A2UI passthrough,
9
+ * telemetry, fallback card.
10
+ * - `AdaptiveChatBar` + `chatSession` (new) owns the canvas-lid UX —
11
+ * glassmorphism bar, bubble-up trail, per-page persistence.
12
+ *
13
+ * This module ports every transport-side concern from ChatAssistantLit
14
+ * into a session-shaped adapter so the new bar gets full backend
15
+ * parity. The bar stays a pure view; the transport stays a pure pipe.
16
+ *
17
+ * Lifecycle:
18
+ * - `configure({ backendUrl, runtime, ... })` — called once by the
19
+ * SDK runtime at bootstrap from chat config. Idempotent; second
20
+ * call with the same backendUrl is a no-op.
21
+ * - Connection is LAZY. The transport doesn't acquire Turnstile or
22
+ * open the SSE until the first chatSession.send() — saves cost
23
+ * on pages where the user never opens chat.
24
+ * - On chatSession.send → transport ensures connected (acquires
25
+ * Turnstile token, builds AgUiTransport) then forwards
26
+ * `{type:'user-message', text}` to the agent.
27
+ * - On chatSession.onInterrupt → transport sends stop-generation.
28
+ * - AgUi events stream into chatSession via receiveStart / Delta /
29
+ * End / error.
30
+ * - A2UI custom events forward to runtime.actions.applyBatch so the
31
+ * agent can drive canvas updates.
32
+ *
33
+ * Telemetry parity with ChatAssistantLit:
34
+ * - chatbot.transport_error (every error, with status/body/name)
35
+ * - chatbot.a2ui_applied
36
+ * - chatbot.fallback_rendered — emitted when the transport gives up
37
+ * (Turnstile failed AND backend rejected) so existing PostHog
38
+ * queries keep working.
39
+ *
40
+ * Threading model: single-flight per page. Multiple concurrent sends
41
+ * are queued by AgUiTransport itself. Multiple bar mounts share this
42
+ * one transport via chatSession.
43
+ */
44
+ import type { ElementMutation } from './elements';
45
+ import type { ChatbotWidgetRuntime } from './types';
46
+ /**
47
+ * Per-customer "chat unavailable" card config. Surfaced via onFallback
48
+ * when the transport gives up after repeated failures. Mirrors
49
+ * ChatbotFallback in types.ts so consumers can pass the same config.
50
+ */
51
+ export interface ChatbotFallbackConfig {
52
+ title?: string;
53
+ message?: string;
54
+ ctaLabel?: string;
55
+ ctaHref?: string;
56
+ }
57
+ export interface ChatTransportConfig {
58
+ /** Backend host, e.g. "https://demo-api.syntrologie.com" or "" for same-origin. */
59
+ backendUrl: string;
60
+ /** Runtime hooks for A2UI apply + telemetry. */
61
+ runtime: ChatbotWidgetRuntime;
62
+ /** Optional thread id for conversation continuity across reloads. */
63
+ threadId?: string;
64
+ /**
65
+ * Optional set of client-tool names the transport should treat as
66
+ * "needs user approval" (surfaced via chatSession.toolCalls instead
67
+ * of auto-executed server-side). Empty by default — all tool calls
68
+ * are server-driven and the transport just emits the "tool call
69
+ * happened" event.
70
+ */
71
+ clientTools?: Set<string>;
72
+ /**
73
+ * Per-customer "chat unavailable" card. Rendered by the host
74
+ * (typically AdaptiveChatBarMountable) after repeated connect
75
+ * failures wipe the chat surface — exactly the same UX
76
+ * ChatAssistantLit's fallback path provides.
77
+ */
78
+ fallback?: ChatbotFallbackConfig;
79
+ /**
80
+ * Arbitrary JSON object attached to every AG-UI request as
81
+ * `forwardedProps`. Used by the adaptive chat surface to ship the
82
+ * LLM-authored UI element config (`uiTemplates`, `elementsEnabled`)
83
+ * per request — the backend reads these to enable the
84
+ * `mount_element` / `patch_element` / `unmount_element` tools.
85
+ * Callable form is re-evaluated on every turn so a config edit can
86
+ * land mid-conversation.
87
+ */
88
+ forwardedProps?: Record<string, unknown> | (() => Record<string, unknown> | undefined);
89
+ /**
90
+ * Optional callback for `syntro.element.mutation` AG-UI custom events.
91
+ * The transport decodes the envelope on receipt; if it matches the
92
+ * element-mutation schema, mutations are routed here instead of the
93
+ * generic `runtime.actions.applyBatch` legacy path. Consumers are
94
+ * expected to forward to `ElementInstanceStore.apply(mutations)` —
95
+ * we don't take a store reference directly so the transport stays
96
+ * agnostic of which surface owns the store (the chat-bar widget
97
+ * may own one; ChatAssistantLit owns its own; both share this
98
+ * singleton transport).
99
+ *
100
+ * When unset, element-mutation envelopes fall back to applyBatch,
101
+ * matching legacy behaviour (which would no-op since applyBatch
102
+ * doesn't know about MutationEnvelope).
103
+ */
104
+ onElementMutation?: (mutations: ElementMutation[]) => void;
105
+ /**
106
+ * Slot the chat-bar widget is mounted into (e.g. ``"drawer"``,
107
+ * ``"adaptive-chat"``). Forwarded as ``X-Active-Lid-Slot`` on every
108
+ * ``/api/adaptive/stream`` request so the backend can route mounts to
109
+ * the canvas next to whichever lid the visitor sent from. Optional —
110
+ * omitting it falls back to the template's static ``default_slot``
111
+ * server-side, which is the pre-change behaviour.
112
+ */
113
+ activeLidSlot?: string;
114
+ }
115
+ /**
116
+ * Debounce window for connect errors. Single transient errors
117
+ * (cold-start 502, brief CORS preflight failure) should NOT swap the
118
+ * chat to the fallback card; only sustained failure should. Matches
119
+ * ChatAssistantLit's ERROR_DEBOUNCE_MS.
120
+ */
121
+ export declare const FALLBACK_DEBOUNCE_MS = 1500;
122
+ export interface FallbackPayload {
123
+ reason: 'connect_failed' | 'connect_timeout';
124
+ fallback: ChatbotFallbackConfig;
125
+ transportId: string;
126
+ transportAgeMs: number;
127
+ messagesSucceeded: number;
128
+ hadTurnstileToken: boolean | null;
129
+ errorStatus: number | null;
130
+ errorBody: string | null;
131
+ errorMessage: string | null;
132
+ errorName: string | null;
133
+ }
134
+ export type FallbackListener = (payload: FallbackPayload) => void;
135
+ export declare class ChatTransport {
136
+ private _config;
137
+ private _status;
138
+ private _agui;
139
+ private _transportUnsub;
140
+ private _sessionUnsubSend;
141
+ private _sessionUnsubInterrupt;
142
+ private _sessionUnsubToolResult;
143
+ private _connectInFlight;
144
+ /** Bounded streaming-message id for the currently-being-typed assistant turn. */
145
+ private _currentAssistantMessageId;
146
+ /** Outcome bookkeeping for telemetry. */
147
+ private _hadTurnstileToken;
148
+ /** Count of successful round-trips for telemetry payloads. */
149
+ private _messagesSucceeded;
150
+ /** True once a successful assistant message has landed — gates fallback. */
151
+ private _hasSucceeded;
152
+ /** True once fallback has fired (one-shot). */
153
+ private _fallbackRendered;
154
+ /**
155
+ * Per-send override for ``X-Active-Lid-Slot``. Set in the
156
+ * ``chatSession.onSend`` listener immediately before each
157
+ * ``_forwardUserMessage`` and consumed by ``buildHeaders`` on the
158
+ * outbound request. The singleton transport is shared by every
159
+ * mounted chat-bar (drawer + inline) so cached ``_config.activeLidSlot``
160
+ * follows whichever bar last reconfigured — using that for routing
161
+ * silently misroutes tiles when both bars coexist. Per-send threading
162
+ * pins the header to the bar that actually sent the message.
163
+ */
164
+ private _pendingLidSlot;
165
+ /** Active debounce timer; null when no debounce pending. */
166
+ private _errorDebounceTimer;
167
+ /** Most recent error payload, captured so debounced fallback can attach it. */
168
+ private _lastErrorPayload;
169
+ private _fallbackListeners;
170
+ /**
171
+ * Per-configure-cycle id for correlating telemetry events from a
172
+ * single transport lifetime. Mirrors ChatAssistantLit's mountId
173
+ * but scoped to configure cycles since the transport is a
174
+ * singleton across mounts.
175
+ */
176
+ private _transportId;
177
+ private _configuredAt;
178
+ /**
179
+ * Configure the transport. Idempotent — calling again with the same
180
+ * backendUrl is a no-op; calling with a different backendUrl tears
181
+ * the connection down and re-arms.
182
+ */
183
+ configure(config: ChatTransportConfig): void;
184
+ /** ms since the most recent configure() call. 0 before any configure. */
185
+ private _ageMs;
186
+ /** True when configure() has been called and we're ready to lazy-connect on send. */
187
+ get isConfigured(): boolean;
188
+ /** True when AgUiTransport is up. */
189
+ get isConnected(): boolean;
190
+ /**
191
+ * Subscribe to fallback events — fires once per configure cycle
192
+ * when the transport gives up after sustained failure. Hosts
193
+ * (typically AdaptiveChatBarMountable) use this to swap the chat
194
+ * bar for a static "contact support" card.
195
+ */
196
+ onFallback(listener: FallbackListener): () => void;
197
+ /**
198
+ * Test seam — drive a synthetic error event through the transport's
199
+ * error handling without standing up a real AgUi transport. Production
200
+ * code path uses _onTransportEvent. Exported as a public method to
201
+ * keep the test isolation simple; not part of the documented API.
202
+ */
203
+ simulateError(payload: {
204
+ message?: string;
205
+ status?: number | null;
206
+ body?: string | null;
207
+ errorName?: string | null;
208
+ }): void;
209
+ /**
210
+ * Test seam — register a synthetic successful message-complete so
211
+ * the hasSucceeded gate flips without a real AgUi round-trip.
212
+ */
213
+ simulateSuccessfulMessage(): void;
214
+ /**
215
+ * Test seam — return the lid slot that the next outbound request
216
+ * WOULD tag ``X-Active-Lid-Slot`` with, given current state. Mirrors
217
+ * the exact resolution buildHeaders uses (per-send slot wins over
218
+ * cached config). Not part of the documented API.
219
+ */
220
+ getActiveLidSlotForTest(): string | null;
221
+ /**
222
+ * Tear connection-level state down. Used internally by configure()
223
+ * to swap backends; preserves host-registered fallback listeners
224
+ * because the host UI handler (e.g. AdaptiveChatBarMountable's
225
+ * "swap to fallback card" callback) is configuration-independent.
226
+ */
227
+ private _disconnect;
228
+ /**
229
+ * Tear everything down — connection state PLUS host listeners.
230
+ * Use this in test teardown or when fully shutting the transport
231
+ * (page unload, integration test reset). The mountable calls
232
+ * _disconnect indirectly via reconfigure.
233
+ */
234
+ reset(): void;
235
+ private _clearDebounceTimer;
236
+ /**
237
+ * Shared error-handling kernel — called by the AG-UI subscriber and
238
+ * by the simulateError test seam. Publishes transport_error
239
+ * telemetry, captures lastErrorPayload, and starts the debounce
240
+ * timer that will fire fallback if no successful message arrives
241
+ * before it expires. Gated by hasSucceeded (post-success errors
242
+ * never fallback) and _fallbackRendered (one-shot).
243
+ */
244
+ private _handleErrorEvent;
245
+ /**
246
+ * Fire the fallback. One-shot per configure cycle. Notifies all
247
+ * fallback listeners with the per-customer card config and the
248
+ * diagnostic snapshot for telemetry/debug.
249
+ */
250
+ private _renderFallback;
251
+ private _wireSession;
252
+ private _forwardUserMessage;
253
+ /**
254
+ * Ensure AgUiTransport is up. Idempotent — multiple concurrent calls
255
+ * dedupe to a single Turnstile acquisition + transport setup.
256
+ * Returns true on success, false on terminal failure.
257
+ */
258
+ private _ensureConnected;
259
+ /**
260
+ * Acquire a Turnstile token via the managed-challenge flow.
261
+ * Delegates to the shared Turnstile helper that owns the verify
262
+ * panel lifecycle. Returns null when Turnstile is disabled at
263
+ * build time or acquisition fails.
264
+ */
265
+ private _acquireTurnstileWithChallenge;
266
+ /**
267
+ * Look up a tool call's current chatSession-side status by id.
268
+ * Used to decide between addToolCall (first sighting) and
269
+ * updateToolCall (subsequent updates) when AG-UI re-emits
270
+ * `tool-call` events for client tools transitioning to 'pending'.
271
+ */
272
+ private _findToolCallStatus;
273
+ /** Map AG-UI ToolCallStatus to TrailToolCall status. */
274
+ private _mapToolCallStatus;
275
+ private _onTransportEvent;
276
+ }
277
+ /**
278
+ * The module-level singleton. Imported by both the SDK runtime
279
+ * bootstrap (to call configure) and any code that needs to read
280
+ * transport state. Mirrors the chatSession singleton shape.
281
+ */
282
+ export declare const chatTransport: ChatTransport;
283
+ //# sourceMappingURL=ChatTransport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChatTransport.d.ts","sourceRoot":"","sources":["../src/ChatTransport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AASH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAGlD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAEpD;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,mBAAmB;IAClC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G;IACH,yBAAyB,IAAI,IAAI;IAMjC;;;;;OAKG;IACH,uBAAuB,IAAI,MAAM,GAAG,IAAI;IAIxC;;;;;OAKG;IACH,OAAO,CAAC,WAAW;IAkCnB;;;;;OAKG;IACH,KAAK,IAAI,IAAI;IAKb,OAAO,CAAC,mBAAmB;IAO3B;;;;;;;OAOG;IACH,OAAO,CAAC,iBAAiB;IAoCzB;;;;OAIG;IACH,OAAO,CAAC,eAAe;IA4BvB,OAAO,CAAC,YAAY;YAkBN,mBAAmB;IAgBjC;;;;OAIG;YACW,gBAAgB;IAuI9B;;;;;OAKG;YACW,8BAA8B;IAS5C;;;;;OAKG;IACH,OAAO,CAAC,mBAAmB;IAS3B,wDAAwD;IACxD,OAAO,CAAC,kBAAkB;IAiB1B,OAAO,CAAC,iBAAiB;CAuH1B;AAED;;;;GAIG;AACH,eAAO,MAAM,aAAa,eAAsB,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * NavLinkMountable — `MountableWidget` used as the payload of an
3
+ * LLM-authored navigation chip.
4
+ *
5
+ * Flow:
6
+ * LLM mounts `suggest-navigation` ItemTemplate with `{title, url}`
7
+ * → backend builds chip with payload `{widget: 'adaptive-chatbot:nav-link', props: {url}}`
8
+ * → user clicks the chip → chips-strip mounts THIS widget into the
9
+ * chip's drawer
10
+ * → user clicks the "Go to <url>" button this widget renders
11
+ * → same-origin SPA navigation via pushState + popstate (matches
12
+ * `adaptive-nav`'s `executeNavigate` path for SPA-router compatibility)
13
+ *
14
+ * Registered as widget id `adaptive-chatbot:nav-link`.
15
+ *
16
+ * Security note: only http(s), same-origin destinations are honored.
17
+ * `javascript:`, `data:`, and cross-origin URLs are silently dropped at
18
+ * URL construction. The ItemTemplate's EnumField allowlist is the
19
+ * primary constraint; this is defense-in-depth.
20
+ */
21
+ export declare const NavLinkMountable: {
22
+ mount(container: HTMLElement, mountConfig?: Record<string, unknown>): () => void;
23
+ update(container: HTMLElement, mountConfig?: Record<string, unknown>): void;
24
+ };
25
+ //# sourceMappingURL=NavLinkMountable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NavLinkMountable.d.ts","sourceRoot":"","sources":["../src/NavLinkMountable.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAmEH,eAAO,MAAM,gBAAgB;qBACV,WAAW,gBAAgB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,IAAI;sBAkB9D,WAAW,gBAAgB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;CAO5E,CAAC"}