@syntrologie/adapt-chatbot 2.8.0-canary.31 → 2.8.0-canary.310
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/AdaptiveChatBar.d.ts +85 -0
- package/dist/AdaptiveChatBar.d.ts.map +1 -0
- package/dist/AdaptiveChatBar.js +10 -0
- package/dist/AdaptiveChatBar.js.map +7 -0
- package/dist/AdaptiveChatBarMountable.d.ts +35 -0
- package/dist/AdaptiveChatBarMountable.d.ts.map +1 -0
- package/dist/AdaptiveChatTrail.d.ts +85 -0
- package/dist/AdaptiveChatTrail.d.ts.map +1 -0
- package/dist/AdaptiveChatTrail.js +9 -0
- package/dist/AdaptiveChatTrail.js.map +7 -0
- package/dist/AdaptiveChipsStrip.d.ts +1150 -0
- package/dist/AdaptiveChipsStrip.d.ts.map +1 -0
- package/dist/AdaptiveChipsStrip.js +11 -0
- package/dist/AdaptiveChipsStrip.js.map +7 -0
- package/dist/AdaptiveChipsStripMountable.d.ts +24 -0
- package/dist/AdaptiveChipsStripMountable.d.ts.map +1 -0
- package/dist/ChatAssistantLit.d.ts +60 -0
- package/dist/ChatAssistantLit.d.ts.map +1 -0
- package/dist/ChatAssistantLit.js +12 -0
- package/dist/ChatAssistantLit.js.map +7 -0
- package/dist/ChatSession.d.ts +178 -0
- package/dist/ChatSession.d.ts.map +1 -0
- package/dist/ChatTransport.d.ts +283 -0
- package/dist/ChatTransport.d.ts.map +1 -0
- package/dist/NavLinkMountable.d.ts +25 -0
- package/dist/NavLinkMountable.d.ts.map +1 -0
- package/dist/NavLinkMountable.test.d.ts +2 -0
- package/dist/NavLinkMountable.test.d.ts.map +1 -0
- package/dist/TextAnswerMountable.d.ts +17 -0
- package/dist/TextAnswerMountable.d.ts.map +1 -0
- package/dist/Turnstile.d.ts +83 -0
- package/dist/Turnstile.d.ts.map +1 -0
- package/dist/cdn.d.ts +2 -6
- package/dist/cdn.d.ts.map +1 -1
- package/dist/chunk-2ZUJ7DZI.js +8770 -0
- package/dist/chunk-2ZUJ7DZI.js.map +7 -0
- package/dist/chunk-BNN5YLN3.js +417 -0
- package/dist/chunk-BNN5YLN3.js.map +7 -0
- package/dist/chunk-FVNSOP7B.js +634 -0
- package/dist/chunk-FVNSOP7B.js.map +7 -0
- package/dist/chunk-ONGGPQER.js +3722 -0
- package/dist/chunk-ONGGPQER.js.map +7 -0
- package/dist/chunk-SCVTTLFJ.js +334 -0
- package/dist/chunk-SCVTTLFJ.js.map +7 -0
- package/dist/chunk-UVKRO5ER.js +13 -0
- package/dist/chunk-UVKRO5ER.js.map +7 -0
- package/dist/chunk-VLJ3WOEX.js +231 -0
- package/dist/chunk-VLJ3WOEX.js.map +7 -0
- package/dist/editor-lit.d.ts +37 -0
- package/dist/editor-lit.d.ts.map +1 -0
- package/dist/editor-lit.js +134 -0
- package/dist/editor-lit.js.map +7 -0
- package/dist/elements/ActionHandler.d.ts +34 -0
- package/dist/elements/ActionHandler.d.ts.map +1 -0
- package/dist/elements/ElementInstanceStore.d.ts +155 -0
- package/dist/elements/ElementInstanceStore.d.ts.map +1 -0
- package/dist/elements/ElementInstanceStore.test.d.ts +2 -0
- package/dist/elements/ElementInstanceStore.test.d.ts.map +1 -0
- package/dist/elements/ElementTypeHandler.d.ts +77 -0
- package/dist/elements/ElementTypeHandler.d.ts.map +1 -0
- package/dist/elements/ItemHandler.d.ts +60 -0
- package/dist/elements/ItemHandler.d.ts.map +1 -0
- package/dist/elements/ItemHandler.test.d.ts +2 -0
- package/dist/elements/ItemHandler.test.d.ts.map +1 -0
- package/dist/elements/TileHandler.d.ts +52 -0
- package/dist/elements/TileHandler.d.ts.map +1 -0
- package/dist/elements/blockRenderer.d.ts +46 -0
- package/dist/elements/blockRenderer.d.ts.map +1 -0
- package/dist/elements/blockRenderer.test.d.ts +13 -0
- package/dist/elements/blockRenderer.test.d.ts.map +1 -0
- package/dist/elements/blocks.d.ts +58 -0
- package/dist/elements/blocks.d.ts.map +1 -0
- package/dist/elements/envelope.d.ts +24 -0
- package/dist/elements/envelope.d.ts.map +1 -0
- package/dist/elements/fetcher.d.ts +40 -0
- package/dist/elements/fetcher.d.ts.map +1 -0
- package/dist/elements/index.d.ts +32 -0
- package/dist/elements/index.d.ts.map +1 -0
- package/dist/elements/types.d.ts +106 -0
- package/dist/elements/types.d.ts.map +1 -0
- package/dist/observer/__tests__/allowlist.test.d.ts +9 -0
- package/dist/observer/__tests__/allowlist.test.d.ts.map +1 -0
- package/dist/observer/__tests__/observer-isolation.test.d.ts +13 -0
- package/dist/observer/__tests__/observer-isolation.test.d.ts.map +1 -0
- package/dist/observer/__tests__/queue.test.d.ts +2 -0
- package/dist/observer/__tests__/queue.test.d.ts.map +1 -0
- package/dist/observer/__tests__/transport.test.d.ts +2 -0
- package/dist/observer/__tests__/transport.test.d.ts.map +1 -0
- package/dist/observer/allowlist.d.ts +32 -0
- package/dist/observer/allowlist.d.ts.map +1 -0
- package/dist/observer/index.d.ts +35 -0
- package/dist/observer/index.d.ts.map +1 -0
- package/dist/observer/queue.d.ts +57 -0
- package/dist/observer/queue.d.ts.map +1 -0
- package/dist/observer/transport.d.ts +26 -0
- package/dist/observer/transport.d.ts.map +1 -0
- package/dist/runtime-lit.d.ts +8 -0
- package/dist/runtime-lit.d.ts.map +1 -0
- package/dist/runtime.d.ts +8 -3
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +1649 -29
- package/dist/runtime.js.map +7 -0
- package/dist/schema.d.ts +3298 -11
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +126 -31
- package/dist/schema.js.map +7 -0
- package/dist/types.d.ts +47 -31
- package/dist/types.d.ts.map +1 -1
- package/package.json +50 -19
- package/dist/ChatAssistant.d.ts +0 -18
- package/dist/ChatAssistant.d.ts.map +0 -1
- package/dist/ChatAssistant.js +0 -178
- package/dist/actionParser.d.ts +0 -15
- package/dist/actionParser.d.ts.map +0 -1
- package/dist/actionParser.js +0 -52
- package/dist/apiClient.d.ts +0 -23
- package/dist/apiClient.d.ts.map +0 -1
- package/dist/apiClient.js +0 -51
- package/dist/cdn.js +0 -37
- package/dist/editor.d.ts +0 -17
- package/dist/editor.d.ts.map +0 -1
- package/dist/editor.js +0 -36
- package/dist/types.js +0 -6
- package/dist/useChat.d.ts +0 -25
- package/dist/useChat.d.ts.map +0 -1
- package/dist/useChat.js +0 -106
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Item element handler — translates `parent_tile`-placed mount/patch/
|
|
3
|
+
* unmount mutations into pub/sub events that container widgets subscribe
|
|
4
|
+
* to.
|
|
5
|
+
*
|
|
6
|
+
* Container widgets (chips strip, FAQ accordion, nav tips) declare
|
|
7
|
+
* themselves participants by implementing the `CompositionalContainer`
|
|
8
|
+
* contract and subscribing to `runtime.events` with
|
|
9
|
+
* `element.compositional_append` / `element.compositional_patch` /
|
|
10
|
+
* `element.compositional_remove`. Each container filters by
|
|
11
|
+
* `props.tile_id === this.tileId`.
|
|
12
|
+
*
|
|
13
|
+
* Why pub/sub rather than DOM lookup? The runtime's event bus is
|
|
14
|
+
* domain-agnostic and already exists. Container widgets that aren't
|
|
15
|
+
* mounted yet (slow inline-slot wrapper hydration) miss the event,
|
|
16
|
+
* but the next subscribe-then-replay pass at container mount time picks
|
|
17
|
+
* up the durable session state from the LLM's `mounted_elements`. No
|
|
18
|
+
* DOM crawling, no MutationObserver wiring, no ordering assumption.
|
|
19
|
+
*
|
|
20
|
+
* The handler is dumb: it forwards the wire `content` as the `item`
|
|
21
|
+
* payload. The backend wrote that content as a fully-formed
|
|
22
|
+
* compositional-item envelope (`{kind, config: {id, title, payload}}`)
|
|
23
|
+
* so the receiving container can append it verbatim.
|
|
24
|
+
*/
|
|
25
|
+
import type { ElementHandlerContext, ElementTypeHandler, ValidateResult } from './ElementTypeHandler';
|
|
26
|
+
import type { MountedElement } from './types';
|
|
27
|
+
/** Event names. Kept as module constants so subscribers can import them
|
|
28
|
+
* instead of memorizing strings. */
|
|
29
|
+
export declare const COMPOSITIONAL_APPEND_EVENT = "element.compositional_append";
|
|
30
|
+
export declare const COMPOSITIONAL_PATCH_EVENT = "element.compositional_patch";
|
|
31
|
+
export declare const COMPOSITIONAL_REMOVE_EVENT = "element.compositional_remove";
|
|
32
|
+
export interface CompositionalAppendEvent {
|
|
33
|
+
/** Parent tile id from the mount's placement. Receivers filter on this. */
|
|
34
|
+
tile_id: string;
|
|
35
|
+
/** Unique id of the mounted item — the receiving container should also
|
|
36
|
+
* set this on the item's DOM as `data-syntro-element-id`. */
|
|
37
|
+
instance_id: string;
|
|
38
|
+
/** Wire shape constructed by the backend — `{kind, config: {…}}`. */
|
|
39
|
+
item: Record<string, unknown>;
|
|
40
|
+
/** Insertion position — receivers honor this when appending. */
|
|
41
|
+
position: 'append' | 'prepend';
|
|
42
|
+
}
|
|
43
|
+
export interface CompositionalPatchEvent {
|
|
44
|
+
tile_id: string;
|
|
45
|
+
instance_id: string;
|
|
46
|
+
item: Record<string, unknown>;
|
|
47
|
+
}
|
|
48
|
+
export interface CompositionalRemoveEvent {
|
|
49
|
+
tile_id: string;
|
|
50
|
+
instance_id: string;
|
|
51
|
+
}
|
|
52
|
+
export declare class ItemHandler implements ElementTypeHandler {
|
|
53
|
+
readonly typeName: "item";
|
|
54
|
+
readonly lifecycle: "stateful";
|
|
55
|
+
validate(instance: MountedElement, _ctx: ElementHandlerContext): ValidateResult;
|
|
56
|
+
mount(instance: MountedElement, ctx: ElementHandlerContext): Promise<void>;
|
|
57
|
+
patch(instance: MountedElement, ctx: ElementHandlerContext): Promise<void>;
|
|
58
|
+
unmount(instance: MountedElement, ctx: ElementHandlerContext): Promise<void>;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=ItemHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ItemHandler.d.ts","sourceRoot":"","sources":["../../src/elements/ItemHandler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EACV,qBAAqB,EACrB,kBAAkB,EAClB,cAAc,EACf,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,cAAc,EAAuB,MAAM,SAAS,CAAC;AAEnE;qCACqC;AACrC,eAAO,MAAM,0BAA0B,iCAAiC,CAAC;AACzE,eAAO,MAAM,yBAAyB,gCAAgC,CAAC;AACvE,eAAO,MAAM,0BAA0B,iCAAiC,CAAC;AAEzE,MAAM,WAAW,wBAAwB;IACvC,2EAA2E;IAC3E,OAAO,EAAE,MAAM,CAAC;IAChB;kEAC8D;IAC9D,WAAW,EAAE,MAAM,CAAC;IACpB,qEAAqE;IACrE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,gEAAgE;IAChE,QAAQ,EAAE,QAAQ,GAAG,SAAS,CAAC;CAChC;AAED,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,qBAAa,WAAY,YAAW,kBAAkB;IACpD,QAAQ,CAAC,QAAQ,EAAG,MAAM,CAAU;IACpC,QAAQ,CAAC,SAAS,EAAG,UAAU,CAAU;IAEzC,QAAQ,CAAC,QAAQ,EAAE,cAAc,EAAE,IAAI,EAAE,qBAAqB,GAAG,cAAc;IAqBzE,KAAK,CAAC,QAAQ,EAAE,cAAc,EAAE,GAAG,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;IAW1E,KAAK,CAAC,QAAQ,EAAE,cAAc,EAAE,GAAG,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;IAU1E,OAAO,CAAC,QAAQ,EAAE,cAAc,EAAE,GAAG,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;CAQnF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ItemHandler.test.d.ts","sourceRoot":"","sources":["../../src/elements/ItemHandler.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tile element handler — translates `slot`-placed mount/patch/unmount
|
|
3
|
+
* mutations into pub/sub events that the runtime SDK subscribes to.
|
|
4
|
+
*
|
|
5
|
+
* The runtime SDK's `SmartCanvasElementLit` already routes config-driven
|
|
6
|
+
* tiles to inline slots via `tile.slot === slotName`. LLM-authored tiles
|
|
7
|
+
* use the same path: we publish a TileConfig-shaped envelope and the
|
|
8
|
+
* runtime merges it into its tile array, then existing routing renders
|
|
9
|
+
* it inside the slot's `<syntro-tile-stack>` alongside any config tiles.
|
|
10
|
+
*
|
|
11
|
+
* Why pub/sub instead of `core:mountWidget` via ActionEngine?
|
|
12
|
+
*
|
|
13
|
+
* - `Surfaces.mount` is exclusive per slot — a second LLM tile to the
|
|
14
|
+
* same slot would displace the first.
|
|
15
|
+
* - `Surfaces` only knows built-in slot names; inline slots resolve
|
|
16
|
+
* anchors via SyntroInlineSlot, not via Surfaces.
|
|
17
|
+
* - Tiles need the SyntroTileCard chrome (chromeless handling, theme
|
|
18
|
+
* overrides, dismiss control) that `core:mountWidget` skips.
|
|
19
|
+
*
|
|
20
|
+
* Container widgets stay dumb: the runtime owns one tile array per slot
|
|
21
|
+
* and renders it the same way regardless of provenance. Subscribers
|
|
22
|
+
* filter on `slot === this.name`.
|
|
23
|
+
*
|
|
24
|
+
* Event names + payload types live in `@syntrologie/sdk-contracts` so
|
|
25
|
+
* both packages share the contract. Renaming a field there is a TS
|
|
26
|
+
* error here and in the runtime subscriber — no silent drift.
|
|
27
|
+
*/
|
|
28
|
+
import type { ElementHandlerContext, ElementTypeHandler, ValidateResult } from './ElementTypeHandler';
|
|
29
|
+
import type { MountedElement } from './types';
|
|
30
|
+
export { TILE_MOUNTED_EVENT, TILE_PATCHED_EVENT, TILE_UNMOUNTED_EVENT, } from '@syntrologie/sdk-contracts';
|
|
31
|
+
/**
|
|
32
|
+
* Optional template→widget resolver. ``uiTemplates`` declares both
|
|
33
|
+
* the LLM-facing ``id`` (e.g. ``"product-card"``) and the runtime
|
|
34
|
+
* widget the chrome should render (e.g. ``"adaptive-product:card"``).
|
|
35
|
+
* Without this resolver, the handler falls back to ``template_id`` as
|
|
36
|
+
* the widget id — which only works when the admin chose ids matching
|
|
37
|
+
* the widget registry, and silently mounts to "Widget not available"
|
|
38
|
+
* when they don't.
|
|
39
|
+
*/
|
|
40
|
+
export type TileTemplateWidgetResolver = (templateId: string) => string | undefined;
|
|
41
|
+
export declare class TileHandler implements ElementTypeHandler {
|
|
42
|
+
private readonly resolveWidget?;
|
|
43
|
+
readonly typeName: "tile";
|
|
44
|
+
readonly lifecycle: "stateful";
|
|
45
|
+
constructor(resolveWidget?: TileTemplateWidgetResolver | undefined);
|
|
46
|
+
private _widgetFor;
|
|
47
|
+
validate(instance: MountedElement, _ctx: ElementHandlerContext): ValidateResult;
|
|
48
|
+
mount(instance: MountedElement, ctx: ElementHandlerContext): Promise<void>;
|
|
49
|
+
patch(instance: MountedElement, ctx: ElementHandlerContext): Promise<void>;
|
|
50
|
+
unmount(instance: MountedElement, ctx: ElementHandlerContext): Promise<void>;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=TileHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TileHandler.d.ts","sourceRoot":"","sources":["../../src/elements/TileHandler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAUH,OAAO,KAAK,EACV,qBAAqB,EACrB,kBAAkB,EAClB,cAAc,EACf,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,cAAc,EAAiB,MAAM,SAAS,CAAC;AAE7D,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,4BAA4B,CAAC;AAEpC;;;;;;;;GAQG;AACH,MAAM,MAAM,0BAA0B,GAAG,CAAC,UAAU,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;AAEpF,qBAAa,WAAY,YAAW,kBAAkB;IAIxC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC;IAH3C,QAAQ,CAAC,QAAQ,EAAG,MAAM,CAAU;IACpC,QAAQ,CAAC,SAAS,EAAG,UAAU,CAAU;gBAEZ,aAAa,CAAC,EAAE,0BAA0B,YAAA;IAEvE,OAAO,CAAC,UAAU;IAIlB,QAAQ,CAAC,QAAQ,EAAE,cAAc,EAAE,IAAI,EAAE,qBAAqB,GAAG,cAAc;IAiBzE,KAAK,CAAC,QAAQ,EAAE,cAAc,EAAE,GAAG,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;IAY1E,KAAK,CAAC,QAAQ,EAAE,cAAc,EAAE,GAAG,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;IAY1E,OAAO,CAAC,QAAQ,EAAE,cAAc,EAAE,GAAG,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;CASnF"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Portable Text block renderer — Phase 7 of the LLM-authored UI element
|
|
3
|
+
* instantiation work.
|
|
4
|
+
*
|
|
5
|
+
* `renderBlocks(blocks)` walks a Portable Text tree and produces a
|
|
6
|
+
* `DocumentFragment` of known-safe DOM. Calling code attaches the
|
|
7
|
+
* fragment via `target.appendChild(fragment)` /
|
|
8
|
+
* `target.insertAdjacentElement(...)` — **never** via `innerHTML`.
|
|
9
|
+
*
|
|
10
|
+
* The safety story:
|
|
11
|
+
*
|
|
12
|
+
* 1. **No `innerHTML` from agent data, ever.** Every text reaches the
|
|
13
|
+
* DOM through `document.createTextNode` or `element.textContent`.
|
|
14
|
+
* Even if an agent slips a `<script>` tag into a span's text, it's
|
|
15
|
+
* rendered as the literal characters `<script>` inside a text node,
|
|
16
|
+
* never parsed as HTML.
|
|
17
|
+
* 2. **Closed mark vocabulary.** Only `bold` / `italic` / `code` / `link`
|
|
18
|
+
* are honored. Unknown marks are dropped at render time.
|
|
19
|
+
* 3. **Closed block vocabulary.** Only `paragraph` / `heading` / `list` /
|
|
20
|
+
* `list_item` / `code` are honored. Unknown block types are dropped.
|
|
21
|
+
* 4. **Link href validation.** Backend already rejects `javascript:` /
|
|
22
|
+
* `data:` / `vbscript:` etc., but the renderer re-checks for defense
|
|
23
|
+
* in depth. Rejected links render as plain text spans.
|
|
24
|
+
* 5. **No inline styles, no event handlers, no custom attributes.**
|
|
25
|
+
* Every attribute set on the output DOM is hard-coded in this file.
|
|
26
|
+
*
|
|
27
|
+
* Forward-compat: unknown block / mark types drop silently rather than
|
|
28
|
+
* throw — a future schema bump can add types without breaking today's
|
|
29
|
+
* renderer.
|
|
30
|
+
*/
|
|
31
|
+
import type { BlockNode } from './blocks';
|
|
32
|
+
export interface RenderOptions {
|
|
33
|
+
/** Override the document used for `createElement` / `createTextNode`.
|
|
34
|
+
* Tests inject jsdom's document; SSR contexts can pass a custom impl
|
|
35
|
+
* if needed. Defaults to `globalThis.document`. */
|
|
36
|
+
doc?: Document;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Render an array of blocks into a `DocumentFragment` of safe DOM.
|
|
40
|
+
*
|
|
41
|
+
* Unknown / malformed entries are silently dropped — the caller has
|
|
42
|
+
* already validated server-side; the renderer is the last line of
|
|
43
|
+
* defense and stays fault-tolerant.
|
|
44
|
+
*/
|
|
45
|
+
export declare function renderBlocks(blocks: BlockNode[], options?: RenderOptions): DocumentFragment;
|
|
46
|
+
//# sourceMappingURL=blockRenderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blockRenderer.d.ts","sourceRoot":"","sources":["../../src/elements/blockRenderer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,KAAK,EACV,SAAS,EAQV,MAAM,UAAU,CAAC;AAQlB,MAAM,WAAW,aAAa;IAC5B;;wDAEoD;IACpD,GAAG,CAAC,EAAE,QAAQ,CAAC;CAChB;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,OAAO,GAAE,aAAkB,GAAG,gBAAgB,CAiB/F"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the Portable Text block renderer — Phase 7.
|
|
3
|
+
*
|
|
4
|
+
* The bulk of this file is a hostile-input corpus. The point of the
|
|
5
|
+
* renderer is that **agent-authored text cannot produce script execution
|
|
6
|
+
* or unsafe DOM**, by construction, regardless of what the agent
|
|
7
|
+
* sends. Each test below pumps a different attack shape through
|
|
8
|
+
* `renderBlocks` and asserts that the resulting DOM contains no
|
|
9
|
+
* dangerous nodes, no live script content, and no `javascript:` /
|
|
10
|
+
* `data:` URIs on anchor tags.
|
|
11
|
+
*/
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=blockRenderer.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blockRenderer.test.d.ts","sourceRoot":"","sources":["../../src/elements/blockRenderer.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Portable Text block + mark types — Phase 7 of the LLM-authored UI
|
|
3
|
+
* element instantiation work.
|
|
4
|
+
*
|
|
5
|
+
* Mirror of `platform/common/syntrologie_common/sdk/blocks.py`. Closed
|
|
6
|
+
* vocabulary (block types + mark types) the LLM may author in
|
|
7
|
+
* `rich_text_blocks` fields. The renderer walks this tree and produces
|
|
8
|
+
* DOM via `document.createElement` + `textContent` — **agent never
|
|
9
|
+
* writes HTML strings**. XSS-class attacks have no surface because
|
|
10
|
+
* there's no HTML on the wire.
|
|
11
|
+
*
|
|
12
|
+
* Forward-compat: unknown block types and unknown marks are dropped at
|
|
13
|
+
* render time (not thrown). A future protocol bump can add new types
|
|
14
|
+
* without breaking today's renderer.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* The closed inline-mark vocabulary. Adding a mark is a deliberate
|
|
18
|
+
* code change with review, never an allowlist tweak.
|
|
19
|
+
*/
|
|
20
|
+
export type MarkType = 'bold' | 'italic' | 'code' | 'link';
|
|
21
|
+
export type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
|
|
22
|
+
export type ListStyle = 'bullet' | 'numbered';
|
|
23
|
+
export interface LinkMark {
|
|
24
|
+
/** Validated server-side; renderer revalidates for defense in depth. */
|
|
25
|
+
href: string;
|
|
26
|
+
}
|
|
27
|
+
export interface TextSpan {
|
|
28
|
+
text: string;
|
|
29
|
+
marks?: MarkType[];
|
|
30
|
+
link?: LinkMark;
|
|
31
|
+
}
|
|
32
|
+
export interface ParagraphBlock {
|
|
33
|
+
type: 'paragraph';
|
|
34
|
+
spans: TextSpan[];
|
|
35
|
+
}
|
|
36
|
+
export interface HeadingBlock {
|
|
37
|
+
type: 'heading';
|
|
38
|
+
level: HeadingLevel;
|
|
39
|
+
spans: TextSpan[];
|
|
40
|
+
}
|
|
41
|
+
export interface ListItemBlock {
|
|
42
|
+
type: 'list_item';
|
|
43
|
+
spans: TextSpan[];
|
|
44
|
+
}
|
|
45
|
+
export interface ListBlock {
|
|
46
|
+
type: 'list';
|
|
47
|
+
style: ListStyle;
|
|
48
|
+
items: ListItemBlock[];
|
|
49
|
+
}
|
|
50
|
+
export interface CodeBlock {
|
|
51
|
+
type: 'code';
|
|
52
|
+
/** Raw code text. Rendered inside `<pre><code>` via `textContent` —
|
|
53
|
+
* no HTML interpretation, no syntax-highlight injection. */
|
|
54
|
+
text: string;
|
|
55
|
+
language?: string;
|
|
56
|
+
}
|
|
57
|
+
export type BlockNode = ParagraphBlock | HeadingBlock | ListBlock | CodeBlock;
|
|
58
|
+
//# sourceMappingURL=blocks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../../src/elements/blocks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;GAGG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;AAE3D,MAAM,MAAM,YAAY,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAEjD,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,UAAU,CAAC;AAE9C,MAAM,WAAW,QAAQ;IACvB,wEAAwE;IACxE,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC;IACnB,IAAI,CAAC,EAAE,QAAQ,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,WAAW,CAAC;IAClB,KAAK,EAAE,QAAQ,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,YAAY,CAAC;IACpB,KAAK,EAAE,QAAQ,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,WAAW,CAAC;IAClB,KAAK,EAAE,QAAQ,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,aAAa,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb;iEAC6D;IAC7D,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,SAAS,GAAG,cAAc,GAAG,YAAY,GAAG,SAAS,GAAG,SAAS,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helpers for decoding AG-UI custom event payloads — Phase 6b.
|
|
3
|
+
*
|
|
4
|
+
* `AgUiTransport.onA2UIEvent` historically forwarded the raw `event.value`
|
|
5
|
+
* payload as an `ActionStep` directly to `runtime.actions.applyBatch`.
|
|
6
|
+
* Phase 5's backend now also emits `syntro.element.mutation` envelopes
|
|
7
|
+
* (mounts/patches/unmounts authored by the LLM via `mount_element` &c.),
|
|
8
|
+
* which the SDK routes to `ElementInstanceStore.apply` instead.
|
|
9
|
+
*
|
|
10
|
+
* Discrimination is by the envelope's `type` field. Non-element payloads
|
|
11
|
+
* (raw ActionStep, A2UI `createSurface` / `updateDataModel` envelopes
|
|
12
|
+
* from any A2UI integration) fall through to the legacy path.
|
|
13
|
+
*/
|
|
14
|
+
import type { ElementMutation } from './types';
|
|
15
|
+
/**
|
|
16
|
+
* Returns the mutations array if `payload` is a well-formed
|
|
17
|
+
* `syntro.element.mutation` envelope, otherwise `null`.
|
|
18
|
+
*
|
|
19
|
+
* Validates only the discriminator + the structural shape needed to
|
|
20
|
+
* route to the store. Per-mutation validation lives in the store / its
|
|
21
|
+
* type handlers (defense in depth), so this stays small.
|
|
22
|
+
*/
|
|
23
|
+
export declare function decodeMutationEnvelope(payload: unknown): ElementMutation[] | null;
|
|
24
|
+
//# sourceMappingURL=envelope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../../src/elements/envelope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAoB,MAAM,SAAS,CAAC;AAEjE;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,GAAG,eAAe,EAAE,GAAG,IAAI,CAOjF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Boot-time fetcher for `GET /api/adaptive/mounted_elements`.
|
|
3
|
+
*
|
|
4
|
+
* Follows the SDK's vanilla-fetch convention (see
|
|
5
|
+
* `packages/runtime-sdk/src/overlays/fetcher.ts` for the sibling pattern
|
|
6
|
+
* — no shared HTTP client, no axios, no fetch wrapper).
|
|
7
|
+
*
|
|
8
|
+
* Auth: forwards the SDK token from `window.__SYNTRO_CONFIG__.token`
|
|
9
|
+
* as a Bearer header. Cookies (`syntro_chat_session`) are sent via
|
|
10
|
+
* `credentials: 'include'` so the backend can scope to the same Redis
|
|
11
|
+
* session the chat uses.
|
|
12
|
+
*
|
|
13
|
+
* 404 contract: the backend returns 404 only when the workspace's SDK
|
|
14
|
+
* token doesn't resolve to a workspace. The SDK treats 404 as
|
|
15
|
+
* "feature unavailable" — no error UI, no retries — per the design doc.
|
|
16
|
+
* Network errors are logged + swallowed so the SDK boot path stays
|
|
17
|
+
* resilient to backend hiccups.
|
|
18
|
+
*/
|
|
19
|
+
import type { MountedElementsResponse } from './types';
|
|
20
|
+
export interface FetchMountedElementsOptions {
|
|
21
|
+
/** Override the endpoint URL (defaults to same-origin
|
|
22
|
+
* `/api/adaptive/mounted_elements`). Tests + multi-environment
|
|
23
|
+
* deploys use this. */
|
|
24
|
+
endpoint?: string;
|
|
25
|
+
/** SDK token. Defaults to `window.__SYNTRO_CONFIG__.token`. */
|
|
26
|
+
token?: string;
|
|
27
|
+
/** Custom fetch implementation — used by tests to mock the network. */
|
|
28
|
+
fetchImpl?: typeof fetch;
|
|
29
|
+
/** Logger — used by tests to capture log output. */
|
|
30
|
+
logger?: Pick<Console, 'warn'>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Fetch the visitor's currently-mounted elements + session expiry.
|
|
34
|
+
*
|
|
35
|
+
* Returns `null` on any failure (404, network error, malformed JSON,
|
|
36
|
+
* etc.). The caller treats `null` as "feature unavailable, no
|
|
37
|
+
* rehydrate" — boot continues normally with an empty element store.
|
|
38
|
+
*/
|
|
39
|
+
export declare function fetchMountedElements(options?: FetchMountedElementsOptions): Promise<MountedElementsResponse | null>;
|
|
40
|
+
//# sourceMappingURL=fetcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../../src/elements/fetcher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAIvD,MAAM,WAAW,2BAA2B;IAC1C;;4BAEwB;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,+DAA+D;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uEAAuE;IACvE,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;IACzB,oDAAoD;IACpD,MAAM,CAAC,EAAE,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;CAChC;AAED;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,GAAE,2BAAgC,GACxC,OAAO,CAAC,uBAAuB,GAAG,IAAI,CAAC,CA+CzC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Element-instantiation machinery for the adaptive chatbot.
|
|
3
|
+
*
|
|
4
|
+
* Originally added in runtime-sdk; moved here in two passes:
|
|
5
|
+
* - Phase 6c: store / handlers / fetcher / envelope / wire types
|
|
6
|
+
* (every consumer was the chat surface).
|
|
7
|
+
* - Phase 6c.1: Portable Text vocab + safe renderer (`renderBlocks`,
|
|
8
|
+
* `BlockNode`, etc.). Generic by shape but zero non-chat consumers
|
|
9
|
+
* in practice, so leaving it in the universal CDN bundle made every
|
|
10
|
+
* non-chat customer pay the bundle cost for nothing — the
|
|
11
|
+
* runtime-as-OS principle says don't ship interfaces with no
|
|
12
|
+
* consumers in the universal bundle.
|
|
13
|
+
*
|
|
14
|
+
* If a second adaptive ever needs Portable Text rendering, promote
|
|
15
|
+
* `blocks.ts` + `blockRenderer.ts` to a leaf shared package
|
|
16
|
+
* (`@syntrologie/portable-text`) and have both consumers depend on it.
|
|
17
|
+
* Do NOT push it back into runtime-sdk.
|
|
18
|
+
*/
|
|
19
|
+
export { ActionHandler } from './ActionHandler';
|
|
20
|
+
export type { RenderOptions } from './blockRenderer';
|
|
21
|
+
export { renderBlocks } from './blockRenderer';
|
|
22
|
+
export type { BlockNode, CodeBlock, HeadingBlock, HeadingLevel, LinkMark, ListBlock, ListItemBlock, ListStyle, MarkType, ParagraphBlock, TextSpan, } from './blocks';
|
|
23
|
+
export { ElementInstanceStore } from './ElementInstanceStore';
|
|
24
|
+
export type { ElementHandlerContext, ElementLifecycle, ElementMutationContext, ElementTypeHandler, ValidateResult, } from './ElementTypeHandler';
|
|
25
|
+
export { decodeMutationEnvelope } from './envelope';
|
|
26
|
+
export type { FetchMountedElementsOptions } from './fetcher';
|
|
27
|
+
export { fetchMountedElements } from './fetcher';
|
|
28
|
+
export type { CompositionalAppendEvent, CompositionalPatchEvent, CompositionalRemoveEvent, } from './ItemHandler';
|
|
29
|
+
export { COMPOSITIONAL_APPEND_EVENT, COMPOSITIONAL_PATCH_EVENT, COMPOSITIONAL_REMOVE_EVENT, ItemHandler, } from './ItemHandler';
|
|
30
|
+
export { TileHandler } from './TileHandler';
|
|
31
|
+
export type { AgentProvenance, ElementMutation, ElementState, MountedElement, MountedElementsResponse, MountMutation, Mutation, MutationEnvelope, NoPlacement, ParentTilePlacement, PatchMutation, Placement, SelectorPlacement, SlotPlacement, UnmountMutation, } from './types';
|
|
32
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/elements/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,YAAY,EACV,SAAS,EACT,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,aAAa,EACb,SAAS,EACT,QAAQ,EACR,cAAc,EACd,QAAQ,GACT,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,YAAY,EACV,qBAAqB,EACrB,gBAAgB,EAChB,sBAAsB,EACtB,kBAAkB,EAClB,cAAc,GACf,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACpD,YAAY,EAAE,2BAA2B,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACjD,YAAY,EACV,wBAAwB,EACxB,uBAAuB,EACvB,wBAAwB,GACzB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,0BAA0B,EAC1B,yBAAyB,EACzB,0BAA0B,EAC1B,WAAW,GACZ,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,YAAY,EACV,eAAe,EACf,eAAe,EACf,YAAY,EACZ,cAAc,EACd,uBAAuB,EACvB,aAAa,EACb,QAAQ,EACR,gBAAgB,EAChB,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,SAAS,EACT,iBAAiB,EACjB,aAAa,EACb,eAAe,GAChB,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire types for LLM-authored UI element instantiation — Phase 6.
|
|
3
|
+
*
|
|
4
|
+
* These mirror the backend Pydantic models in
|
|
5
|
+
* `platform/backend/app/services/agents/elements_models.py`. Kept as
|
|
6
|
+
* plain TypeScript types (no Zod validators) for v1 — the SDK trusts
|
|
7
|
+
* what it fetches from the workspace's own backend per the design doc's
|
|
8
|
+
* "backend is the sole enforcer" stance. Add Zod here if defence-in-depth
|
|
9
|
+
* ever becomes a real concern.
|
|
10
|
+
*
|
|
11
|
+
* Wire format documented in
|
|
12
|
+
* `docs/plans/current/2026-05-24-adaptive-chatbot-action-triggers-design.md`.
|
|
13
|
+
*/
|
|
14
|
+
export type ElementState = 'active' | 'applied' | 'reverted' | 'expired';
|
|
15
|
+
export interface AgentProvenance {
|
|
16
|
+
agent_id: string;
|
|
17
|
+
turn_id: string;
|
|
18
|
+
}
|
|
19
|
+
export interface Mutation {
|
|
20
|
+
op: 'mount' | 'patch' | 'unmount';
|
|
21
|
+
at: string;
|
|
22
|
+
by: AgentProvenance;
|
|
23
|
+
paths?: string[];
|
|
24
|
+
}
|
|
25
|
+
export interface SlotPlacement {
|
|
26
|
+
type: 'slot';
|
|
27
|
+
slot: string;
|
|
28
|
+
}
|
|
29
|
+
export interface SelectorPlacement {
|
|
30
|
+
type: 'selector';
|
|
31
|
+
selector: string;
|
|
32
|
+
position: 'beforebegin' | 'afterbegin' | 'beforeend' | 'afterend' | 'replace' | 'modify';
|
|
33
|
+
}
|
|
34
|
+
export interface NoPlacement {
|
|
35
|
+
type: 'none';
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Compositional-item placement — for chips, FAQ items, nav tips that
|
|
39
|
+
* mount INSIDE an existing tile's compositional-actions list rather
|
|
40
|
+
* than occupying their own slot. `tile_id` references a tile by its
|
|
41
|
+
* config-time id (e.g. `hero-chips`); `position` controls insertion
|
|
42
|
+
* order in the parent's items array.
|
|
43
|
+
*
|
|
44
|
+
* Backend mirror: `ParentTilePlacement` in
|
|
45
|
+
* `platform/backend/app/services/agents/elements_models.py`.
|
|
46
|
+
*/
|
|
47
|
+
export interface ParentTilePlacement {
|
|
48
|
+
type: 'parent_tile';
|
|
49
|
+
tile_id: string;
|
|
50
|
+
position: 'append' | 'prepend';
|
|
51
|
+
}
|
|
52
|
+
export type Placement = SlotPlacement | SelectorPlacement | NoPlacement | ParentTilePlacement;
|
|
53
|
+
export interface MountedElement {
|
|
54
|
+
instance_id: string;
|
|
55
|
+
element_type: 'tile' | 'action' | 'item';
|
|
56
|
+
template_id: string;
|
|
57
|
+
placement: Placement;
|
|
58
|
+
content: Record<string, unknown>;
|
|
59
|
+
state: ElementState;
|
|
60
|
+
mounted_by: AgentProvenance;
|
|
61
|
+
mounted_at: string;
|
|
62
|
+
version: number;
|
|
63
|
+
mutation_log?: Mutation[];
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Live-mutation envelope carried on the `syntro.element.mutation`
|
|
67
|
+
* AG-UI custom event.
|
|
68
|
+
*/
|
|
69
|
+
export interface MutationEnvelope {
|
|
70
|
+
type: 'syntro.element.mutation';
|
|
71
|
+
schema_version: 'v0';
|
|
72
|
+
mutations: ElementMutation[];
|
|
73
|
+
}
|
|
74
|
+
export type ElementMutation = MountMutation | PatchMutation | UnmountMutation;
|
|
75
|
+
export interface MountMutation {
|
|
76
|
+
op: 'mount';
|
|
77
|
+
instance: MountedElement;
|
|
78
|
+
}
|
|
79
|
+
export interface PatchMutation {
|
|
80
|
+
op: 'patch';
|
|
81
|
+
instance_id: string;
|
|
82
|
+
patches: {
|
|
83
|
+
path: string;
|
|
84
|
+
value: unknown;
|
|
85
|
+
}[];
|
|
86
|
+
expected_version: number;
|
|
87
|
+
/** New version after patch, sent by the backend. SDK uses this for dedup. */
|
|
88
|
+
resulting_version: number;
|
|
89
|
+
/** Full content snapshot after patch — saves the SDK from having to
|
|
90
|
+
* apply patches client-side. */
|
|
91
|
+
resulting_content: Record<string, unknown>;
|
|
92
|
+
}
|
|
93
|
+
export interface UnmountMutation {
|
|
94
|
+
op: 'unmount';
|
|
95
|
+
instance_id: string;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Response shape from `GET /api/adaptive/mounted_elements`. Matches the
|
|
99
|
+
* backend `MountedElementsResponse` (Phase 4).
|
|
100
|
+
*/
|
|
101
|
+
export interface MountedElementsResponse {
|
|
102
|
+
mounted_elements: MountedElement[];
|
|
103
|
+
session_expires_at: string | null;
|
|
104
|
+
schema_version: 'v0';
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/elements/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,CAAC;AAEzE,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,CAAC;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,eAAe,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,aAAa,GAAG,YAAY,GAAG,WAAW,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAC;CAC1F;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,aAAa,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,QAAQ,GAAG,SAAS,CAAC;CAChC;AAED,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,iBAAiB,GAAG,WAAW,GAAG,mBAAmB,CAAC;AAE9F,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC;IACzC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,SAAS,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,KAAK,EAAE,YAAY,CAAC;IACpB,UAAU,EAAE,eAAe,CAAC;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,QAAQ,EAAE,CAAC;CAC3B;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,yBAAyB,CAAC;IAChC,cAAc,EAAE,IAAI,CAAC;IACrB,SAAS,EAAE,eAAe,EAAE,CAAC;CAC9B;AAED,MAAM,MAAM,eAAe,GAAG,aAAa,GAAG,aAAa,GAAG,eAAe,CAAC;AAE9E,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,OAAO,CAAC;IACZ,QAAQ,EAAE,cAAc,CAAC;CAC1B;AAED,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,OAAO,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,EAAE,CAAC;IAC5C,gBAAgB,EAAE,MAAM,CAAC;IACzB,6EAA6E;IAC7E,iBAAiB,EAAE,MAAM,CAAC;IAC1B;qCACiC;IACjC,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC5C;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,SAAS,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACtC,gBAAgB,EAAE,cAAc,EAAE,CAAC;IACnC,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,cAAc,EAAE,IAAI,CAAC;CACtB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the pure event-allowlist module.
|
|
3
|
+
*
|
|
4
|
+
* Each PostHog autocapture event shape maps to either:
|
|
5
|
+
* - a templated ObservationEvent ready for transport, or
|
|
6
|
+
* - null (drop — not significant).
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=allowlist.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"allowlist.test.d.ts","sourceRoot":"","sources":["../../../src/observer/__tests__/allowlist.test.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Isolation tests for the observer.
|
|
3
|
+
*
|
|
4
|
+
* The observer must never include host-page PII in observation text.
|
|
5
|
+
* PostHog autocapture strips sensitive properties from $elements before
|
|
6
|
+
* delivery, but we add a belt-and-suspenders check here against text
|
|
7
|
+
* fields that look like emails, phones, or credit-card patterns.
|
|
8
|
+
*
|
|
9
|
+
* If this test ever fails, the templates in allowlist.ts have regressed
|
|
10
|
+
* — fix there, not by suppressing this test.
|
|
11
|
+
*/
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=observer-isolation.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observer-isolation.test.d.ts","sourceRoot":"","sources":["../../../src/observer/__tests__/observer-isolation.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.test.d.ts","sourceRoot":"","sources":["../../../src/observer/__tests__/queue.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.test.d.ts","sourceRoot":"","sources":["../../../src/observer/__tests__/transport.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure mapping from raw PostHog events to ObservationEvents.
|
|
3
|
+
*
|
|
4
|
+
* One function: matchEvent(raw, opts) → ObservationEvent | null. Null means
|
|
5
|
+
* "drop, not significant." This module is the single source of truth for what
|
|
6
|
+
* the chat agent sees on the in-session timeline; the SDK observer never
|
|
7
|
+
* forwards anything matchEvent returns null for.
|
|
8
|
+
*
|
|
9
|
+
* Kept dependency-free (no DOM access, no PostHog SDK imports) so the
|
|
10
|
+
* Vitest unit tests run without any browser shim.
|
|
11
|
+
*/
|
|
12
|
+
export type ObservationKind = 'nav' | 'click' | 'form' | 'rage' | 'dead' | 'scroll' | 'view' | 'idle' | 'hover' | 'hesitation' | 'custom';
|
|
13
|
+
export interface ObservationEvent {
|
|
14
|
+
ts: number;
|
|
15
|
+
kind: ObservationKind;
|
|
16
|
+
text: string;
|
|
17
|
+
ref?: string;
|
|
18
|
+
}
|
|
19
|
+
/** Shape of a raw event reaching matchEvent. Loose by design — PostHog's
|
|
20
|
+
* event shape evolves, and we want matchEvent to be resilient to extra
|
|
21
|
+
* properties. */
|
|
22
|
+
export interface RawEvent {
|
|
23
|
+
event: string;
|
|
24
|
+
timestamp: number;
|
|
25
|
+
properties: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
export interface MatchOptions {
|
|
28
|
+
/** Workspace-configured custom event names to forward as kind="custom". */
|
|
29
|
+
observableEvents?: readonly string[];
|
|
30
|
+
}
|
|
31
|
+
export declare function matchEvent(raw: RawEvent, opts?: MatchOptions): ObservationEvent | null;
|
|
32
|
+
//# sourceMappingURL=allowlist.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"allowlist.d.ts","sourceRoot":"","sources":["../../src/observer/allowlist.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,MAAM,eAAe,GACvB,KAAK,GACL,OAAO,GACP,MAAM,GACN,MAAM,GACN,MAAM,GACN,QAAQ,GACR,MAAM,GACN,MAAM,GACN,OAAO,GACP,YAAY,GACZ,QAAQ,CAAC;AAEb,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,eAAe,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;kBAEkB;AAClB,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC;AAED,MAAM,WAAW,YAAY;IAC3B,2EAA2E;IAC3E,gBAAgB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACtC;AA0ED,wBAAgB,UAAU,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,GAAE,YAAiB,GAAG,gBAAgB,GAAG,IAAI,CA4I1F"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Observer entry point.
|
|
3
|
+
*
|
|
4
|
+
* startObserver wires the four pieces — allowlist filter + queue +
|
|
5
|
+
* transport + PostHog subscription — into a single lifecycle controlled
|
|
6
|
+
* via the returned handle. The handle is reference-counted: multiple
|
|
7
|
+
* call sites (e.g. multiple chatbot widgets on the same page) share
|
|
8
|
+
* one observer.
|
|
9
|
+
*
|
|
10
|
+
* Idempotent: calling startObserver twice with equivalent options
|
|
11
|
+
* returns the same instance. Calling stop() decrements the ref count;
|
|
12
|
+
* the observer tears down only when the count reaches zero.
|
|
13
|
+
*/
|
|
14
|
+
import { type RawEvent } from './allowlist';
|
|
15
|
+
import { type ObserverStats } from './queue';
|
|
16
|
+
import { type Transport } from './transport';
|
|
17
|
+
export interface StartObserverOptions {
|
|
18
|
+
url: string;
|
|
19
|
+
token: () => string;
|
|
20
|
+
getDistinctId: () => string | null;
|
|
21
|
+
observableEvents?: readonly string[];
|
|
22
|
+
/** Test seam: override fetch/timer behavior by injecting a custom transport. */
|
|
23
|
+
transport?: Transport;
|
|
24
|
+
}
|
|
25
|
+
export interface ObserverHandle {
|
|
26
|
+
stop(): void;
|
|
27
|
+
stats(): ObserverStats;
|
|
28
|
+
/** Test seam: ingest a raw event directly without depending on PostHog being loaded. */
|
|
29
|
+
ingest(raw: RawEvent): void;
|
|
30
|
+
flushNow(): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
export declare function startObserver(opts: StartObserverOptions): ObserverHandle;
|
|
33
|
+
/** Test-only: reset module singleton state. */
|
|
34
|
+
export declare function _resetObserverForTests(): void;
|
|
35
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/observer/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAc,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAiB,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,EAAmB,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAE9D,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IACnC,gBAAgB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,gFAAgF;IAChF,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,IAAI,IAAI,CAAC;IACb,KAAK,IAAI,aAAa,CAAC;IACvB,wFAAwF;IACxF,MAAM,CAAC,GAAG,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC5B,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B;AAoDD,wBAAgB,aAAa,CAAC,IAAI,EAAE,oBAAoB,GAAG,cAAc,CAoCxE;AAoCD,+CAA+C;AAC/C,wBAAgB,sBAAsB,IAAI,IAAI,CAK7C"}
|