@syntrologie/adapt-chatbot 2.25.2 → 2.26.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.
@@ -2,11 +2,33 @@
2
2
  * Adaptive Chatbot — Lit Mountable
3
3
  *
4
4
  * Thin wrapper that mounts <syntro-chat> from @syntrologie/chat with an
5
- * SsePostTransport pointed at the adaptive SSE backend.
5
+ * AgUiTransport pointed at the adaptive AG-UI streaming endpoint.
6
6
  *
7
- * The old hand-rolled ChatAssistantElement (Lit component with inline
8
- * styles, message management, and action parsing) is fully replaced by
9
- * the shared @syntrologie/chat package.
7
+ * Four pieces this mountable owns:
8
+ *
9
+ * 1. SDK token plumbing. The chat backend (`/api/adaptive/*`) is identified
10
+ * by the workspace's `syn_*` SDK token. The token lives on
11
+ * `window.__SYNTRO_CONFIG__.token` (set by runtime-config.js) — we read
12
+ * it at mount time and forward it via `Authorization: Bearer` header.
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.
21
+ *
22
+ * 3. Fallback card. If the first agent run fails (Cloudflare Turnstile
23
+ * bot-check failure, CORS / network error, or a server-side rejection),
24
+ * swap the chat UI for a per-customer fallback card built from
25
+ * `props.fallback`. The end-user is redirected to the customer's normal
26
+ * support path instead of seeing a raw error.
27
+ *
28
+ * 4. A2UI passthrough. AG-UI CUSTOM events carrying A2UI payloads
29
+ * (createSurface, updateDataModel, …) get forwarded to
30
+ * `runtime.actions.applyBatch` so tiles can render server-driven UI
31
+ * inside the chat surface.
10
32
  */
11
33
  import '@syntrologie/chat';
12
34
  import type { ChatbotConfig, ChatbotWidgetRuntime } from './types.js';
@@ -15,6 +37,21 @@ export interface ChatAssistantLitProps {
15
37
  runtime: ChatbotWidgetRuntime;
16
38
  tileId?: string;
17
39
  }
40
+ /**
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()`.
53
+ */
54
+ export declare function acquireTurnstileToken(): Promise<string | null>;
18
55
  export declare const ChatAssistantLitMountable: {
19
56
  mount(container: HTMLElement, mountConfig?: Record<string, unknown>): () => void;
20
57
  };
@@ -1 +1 @@
1
- {"version":3,"file":"ChatAssistantLit.d.ts","sourceRoot":"","sources":["../src/ChatAssistantLit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,mBAAmB,CAAC;AAI3B,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEtE,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,oBAAoB,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,yBAAyB;qBACnB,WAAW,gBAAgB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAsDpE,CAAC"}
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,8 +1,10 @@
1
1
  import {
2
- ChatAssistantLitMountable
3
- } from "./chunk-FI7F22ED.js";
4
- import "./chunk-V6TY7KAL.js";
2
+ ChatAssistantLitMountable,
3
+ acquireTurnstileToken
4
+ } from "./chunk-O7RWNUVU.js";
5
+ import "./chunk-UVKRO5ER.js";
5
6
  export {
6
- ChatAssistantLitMountable
7
+ ChatAssistantLitMountable,
8
+ acquireTurnstileToken
7
9
  };
8
10
  //# sourceMappingURL=ChatAssistantLit.js.map