@matterfact/embed 0.11.3 → 0.13.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.
- package/README.md +41 -0
- package/dist/chunk-C7DXO37G.js +2 -0
- package/dist/{chunk-CTZEDOH7.js → chunk-JLJG3MDX.js} +101 -51
- package/dist/chunk-JLJG3MDX.js.map +1 -0
- package/dist/chunk-QZCUQZJK.js +3 -0
- package/dist/chunk-QZCUQZJK.js.map +7 -0
- package/dist/{chunk-AANODHBV.js → chunk-S6OT47DL.js} +100 -49
- package/dist/chunk-S6OT47DL.js.map +1 -0
- package/dist/{chunk-JO3GWFMJ.js → chunk-UA4Y2O64.js} +2 -2
- package/dist/{context-FR7VFENN.js → context-DAXACLSP.js} +3 -3
- package/dist/{context-FR7VFENN.js.map → context-DAXACLSP.js.map} +1 -1
- package/dist/{context-IK5MECUW.js → context-IJK345PN.js} +4 -2
- package/dist/embed.js +1 -1
- package/dist/embed.js.map +3 -3
- package/dist/index.cjs +167 -53
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +83 -10
- package/dist/index.d.ts +83 -10
- package/dist/index.js +63 -6
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +159 -52
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +29 -2
- package/dist/react.d.ts +29 -2
- package/dist/react.js +54 -5
- package/dist/react.js.map +1 -1
- package/dist/{snapshot-2V5SDSH2.js → snapshot-EVBNVVCT.js} +2 -2
- package/dist/{snapshot-Y5BF2UJR.js → snapshot-P5SVKSPB.js} +3 -3
- package/dist/{snapshot-Y5BF2UJR.js.map → snapshot-P5SVKSPB.js.map} +1 -1
- package/examples/embed-demo/.env.example +7 -3
- package/examples/embed-demo/README.md +25 -4
- package/examples/embed-demo/src/App.tsx +67 -7
- package/examples/embed-demo/src/styles.css +52 -0
- package/examples/embed-demo/vite.config.ts +3 -2
- package/package.json +1 -1
- package/dist/chunk-AANODHBV.js.map +0 -1
- package/dist/chunk-CTZEDOH7.js.map +0 -1
- package/dist/chunk-SKJFF7RD.js +0 -2
- package/dist/chunk-Y7I25VHL.js +0 -3
- package/dist/chunk-Y7I25VHL.js.map +0 -7
- /package/dist/{chunk-SKJFF7RD.js.map → chunk-C7DXO37G.js.map} +0 -0
- /package/dist/{chunk-JO3GWFMJ.js.map → chunk-UA4Y2O64.js.map} +0 -0
- /package/dist/{context-IK5MECUW.js.map → context-IJK345PN.js.map} +0 -0
- /package/dist/{snapshot-2V5SDSH2.js.map → snapshot-EVBNVVCT.js.map} +0 -0
package/dist/index.d.cts
CHANGED
|
@@ -149,7 +149,30 @@ interface ToolEvent {
|
|
|
149
149
|
* - `chat` — a chat-turn moment. Content-free: phase + opaque chatId only.
|
|
150
150
|
* - `tool` — a host-tool lifecycle event (the `ToolEvent` shape, tagged). Also
|
|
151
151
|
* still delivered untagged to the legacy `onToolEvent` hook for back-compat.
|
|
152
|
+
* - `artifactParams` — an artifact param changed in the widget.
|
|
152
153
|
*/
|
|
154
|
+
/**
|
|
155
|
+
* A value an artifact param can carry. Mirrors the app's `ParamValue`
|
|
156
|
+
* (`enum` / `enum[]` / `entity` / `date` / `daterange` / `boolean` / `number`)
|
|
157
|
+
* DELIBERATELY BY COPY, not by import: this is a wire contract between two
|
|
158
|
+
* independently-deployed artifacts, and a shared type would let a rename
|
|
159
|
+
* compile on both sides while still breaking the wire. Bump PROTOCOL_VERSION
|
|
160
|
+
* instead. See this file's header.
|
|
161
|
+
*/
|
|
162
|
+
type ArtifactParamValue = string | string[] | number | boolean
|
|
163
|
+
/** `daterange`: a [from, to] pair of YYYY-MM-DD strings. */
|
|
164
|
+
| [string, string];
|
|
165
|
+
/**
|
|
166
|
+
* Artifact params on the wire, keyed by declared param name.
|
|
167
|
+
*
|
|
168
|
+
* Values are typed but NOT verified against the artifact's declared spec —
|
|
169
|
+
* a host can send anything, and the widget's param store coerces each value
|
|
170
|
+
* to its declared type (or drops it) on arrival. This type says what a
|
|
171
|
+
* well-behaved host means to send, not what the widget trusts it to have sent.
|
|
172
|
+
*/
|
|
173
|
+
type ArtifactParams = {
|
|
174
|
+
[name: string]: ArtifactParamValue;
|
|
175
|
+
};
|
|
153
176
|
type MatterfactEvent = {
|
|
154
177
|
type: 'ready';
|
|
155
178
|
} | {
|
|
@@ -171,7 +194,11 @@ type MatterfactEvent = {
|
|
|
171
194
|
chatId?: string;
|
|
172
195
|
} | ({
|
|
173
196
|
type: 'tool';
|
|
174
|
-
} & ToolEvent)
|
|
197
|
+
} & ToolEvent) | {
|
|
198
|
+
type: 'artifactParams';
|
|
199
|
+
params: ArtifactParams;
|
|
200
|
+
source: 'user' | 'context';
|
|
201
|
+
};
|
|
175
202
|
/**
|
|
176
203
|
* A snapshot of the page as the agent sees it.
|
|
177
204
|
*
|
|
@@ -282,6 +309,16 @@ type HostToWidget = {
|
|
|
282
309
|
type: 'host.artifactGrants';
|
|
283
310
|
grants: ArtifactGrant[];
|
|
284
311
|
}
|
|
312
|
+
/**
|
|
313
|
+
* Set artifact param values. A PARTIAL patch — only the named params change, and
|
|
314
|
+
* each value is validated against its declared spec before it applies (unknown or
|
|
315
|
+
* invalid entries are dropped). Explicit and deliberate, so it always applies, even
|
|
316
|
+
* to a param whose page-context binding the viewer has overridden.
|
|
317
|
+
*/
|
|
318
|
+
| {
|
|
319
|
+
type: 'host.artifactParams';
|
|
320
|
+
params: ArtifactParams;
|
|
321
|
+
}
|
|
285
322
|
/**
|
|
286
323
|
* The annotated site map — the app's routes with the host's content
|
|
287
324
|
* classification. Sent on mount and re-sent on navigation (a virtualized SPA can
|
|
@@ -370,6 +407,13 @@ type WidgetToHost = {
|
|
|
370
407
|
| {
|
|
371
408
|
type: 'widget.requestContext';
|
|
372
409
|
}
|
|
410
|
+
/**
|
|
411
|
+
* Admin max page-context mode from bootstrap — host clamps observation to this.
|
|
412
|
+
*/
|
|
413
|
+
| {
|
|
414
|
+
type: 'widget.pageContextMax';
|
|
415
|
+
mode: 'full' | 'declared' | 'off';
|
|
416
|
+
}
|
|
373
417
|
/** Zoom in: the a11y sub-tree under one ref (a table, a form, a card the agent cares about). */
|
|
374
418
|
| {
|
|
375
419
|
type: 'widget.readRegion';
|
|
@@ -493,6 +537,17 @@ type WidgetToHost = {
|
|
|
493
537
|
type: 'widget.chat';
|
|
494
538
|
phase: 'message' | 'response-start' | 'response-end';
|
|
495
539
|
chatId?: string;
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* An artifact param changed. Emitted ONLY for user- and context-originated changes,
|
|
543
|
+
* never for a change the host itself pushed. The type excludes `'host'` so a caller
|
|
544
|
+
* cannot mislabel an echo as legitimate; the actual no-echo guarantee comes from the
|
|
545
|
+
* param store filtering by `source` before this callback is invoked.
|
|
546
|
+
*/
|
|
547
|
+
| {
|
|
548
|
+
type: 'widget.artifactParams';
|
|
549
|
+
params: ArtifactParams;
|
|
550
|
+
source: 'user' | 'context';
|
|
496
551
|
};
|
|
497
552
|
/**
|
|
498
553
|
* Everything on the wire is wrapped.
|
|
@@ -520,6 +575,20 @@ declare function isEnvelope(data: unknown): data is Envelope<unknown>;
|
|
|
520
575
|
*/
|
|
521
576
|
type PageContextProvider = () => PageContext | null | undefined | Promise<PageContext | null | undefined>;
|
|
522
577
|
|
|
578
|
+
declare global {
|
|
579
|
+
interface Window {
|
|
580
|
+
/**
|
|
581
|
+
* The loader's public host API. Declared here so the members this file
|
|
582
|
+
* installs are checked on both the read and the write; hosts also see a
|
|
583
|
+
* typed surface instead of an opaque bag.
|
|
584
|
+
*/
|
|
585
|
+
matterfact?: {
|
|
586
|
+
setArtifactParams?: (params: ArtifactParams) => void;
|
|
587
|
+
getPageContext?: unknown;
|
|
588
|
+
[key: string]: unknown;
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
}
|
|
523
592
|
/**
|
|
524
593
|
* The matterfact embed loader.
|
|
525
594
|
*
|
|
@@ -590,15 +659,10 @@ interface LoaderConfig {
|
|
|
590
659
|
*/
|
|
591
660
|
container?: HTMLElement | null;
|
|
592
661
|
/**
|
|
593
|
-
*
|
|
594
|
-
*
|
|
595
|
-
* gets sent: when this is false the loader never installs the DOM/nav/focus/activity
|
|
596
|
-
* observers in the first place, and an inbound `widget.requestSnapshot` is ignored
|
|
597
|
-
* rather than answered. Default `true` — seeing the page is the widget's whole value
|
|
598
|
-
* proposition; this is the escape hatch for a host that wants agent chat with nothing
|
|
599
|
-
* about the page ever reaching it.
|
|
662
|
+
* Page observation mode: `full` (default / `true`), `declared` (getPageContext +
|
|
663
|
+
* host sitemap only), or `off` (`false`). Auto DOM/focus/activity require `full`.
|
|
600
664
|
*/
|
|
601
|
-
pageContext?: boolean;
|
|
665
|
+
pageContext?: boolean | 'full' | 'declared' | 'off';
|
|
602
666
|
/**
|
|
603
667
|
* Force dev mode (see `devRequested()` below) without needing `?mfdev=1` on the host
|
|
604
668
|
* URL. This is the programmatic equivalent of that trigger, not a replacement for it —
|
|
@@ -736,6 +800,15 @@ declare class EmbedHost {
|
|
|
736
800
|
private loadContext;
|
|
737
801
|
private send;
|
|
738
802
|
private flush;
|
|
803
|
+
/**
|
|
804
|
+
* Push artifact param values into the widget — a PARTIAL patch; only the named
|
|
805
|
+
* params change. Buffered like every other host→widget message until the widget
|
|
806
|
+
* says it's listening.
|
|
807
|
+
*
|
|
808
|
+
* Explicit and deliberate, so it applies even to a param whose page-context binding
|
|
809
|
+
* the viewer has overridden (spec §7.3).
|
|
810
|
+
*/
|
|
811
|
+
setArtifactParams(params: ArtifactParams): void;
|
|
739
812
|
/** Tear down: stop listening and remove the host element. For the React wrapper's
|
|
740
813
|
* unmount — the vanilla `<script>` loader lives for the page's lifetime and never
|
|
741
814
|
* calls this. */
|
|
@@ -748,4 +821,4 @@ declare class EmbedHost {
|
|
|
748
821
|
*/
|
|
749
822
|
declare function mount(config: LoaderConfig): EmbedHost;
|
|
750
823
|
|
|
751
|
-
export { type ActivityEvent, type ArtifactGrant, CHANNEL, type ContentClass, type DeclaredArtifact, type DomSnapshot, type ElementRef, EmbedHost, type Envelope, type FocusContext, type HostToWidget, type HostTool, type LoaderConfig, type MatterfactEvent, PROTOCOL_VERSION, type PageContext, type PageEntity, type SiteMapEntry, type ToolCall, type ToolEvent, type WidgetToHost, envelope, isEnvelope, mount, readConfig };
|
|
824
|
+
export { type ActivityEvent, type ArtifactGrant, type ArtifactParamValue, type ArtifactParams, CHANNEL, type ContentClass, type DeclaredArtifact, type DomSnapshot, type ElementRef, EmbedHost, type Envelope, type FocusContext, type HostToWidget, type HostTool, type LoaderConfig, type MatterfactEvent, PROTOCOL_VERSION, type PageContext, type PageEntity, type SiteMapEntry, type ToolCall, type ToolEvent, type WidgetToHost, envelope, isEnvelope, mount, readConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -149,7 +149,30 @@ interface ToolEvent {
|
|
|
149
149
|
* - `chat` — a chat-turn moment. Content-free: phase + opaque chatId only.
|
|
150
150
|
* - `tool` — a host-tool lifecycle event (the `ToolEvent` shape, tagged). Also
|
|
151
151
|
* still delivered untagged to the legacy `onToolEvent` hook for back-compat.
|
|
152
|
+
* - `artifactParams` — an artifact param changed in the widget.
|
|
152
153
|
*/
|
|
154
|
+
/**
|
|
155
|
+
* A value an artifact param can carry. Mirrors the app's `ParamValue`
|
|
156
|
+
* (`enum` / `enum[]` / `entity` / `date` / `daterange` / `boolean` / `number`)
|
|
157
|
+
* DELIBERATELY BY COPY, not by import: this is a wire contract between two
|
|
158
|
+
* independently-deployed artifacts, and a shared type would let a rename
|
|
159
|
+
* compile on both sides while still breaking the wire. Bump PROTOCOL_VERSION
|
|
160
|
+
* instead. See this file's header.
|
|
161
|
+
*/
|
|
162
|
+
type ArtifactParamValue = string | string[] | number | boolean
|
|
163
|
+
/** `daterange`: a [from, to] pair of YYYY-MM-DD strings. */
|
|
164
|
+
| [string, string];
|
|
165
|
+
/**
|
|
166
|
+
* Artifact params on the wire, keyed by declared param name.
|
|
167
|
+
*
|
|
168
|
+
* Values are typed but NOT verified against the artifact's declared spec —
|
|
169
|
+
* a host can send anything, and the widget's param store coerces each value
|
|
170
|
+
* to its declared type (or drops it) on arrival. This type says what a
|
|
171
|
+
* well-behaved host means to send, not what the widget trusts it to have sent.
|
|
172
|
+
*/
|
|
173
|
+
type ArtifactParams = {
|
|
174
|
+
[name: string]: ArtifactParamValue;
|
|
175
|
+
};
|
|
153
176
|
type MatterfactEvent = {
|
|
154
177
|
type: 'ready';
|
|
155
178
|
} | {
|
|
@@ -171,7 +194,11 @@ type MatterfactEvent = {
|
|
|
171
194
|
chatId?: string;
|
|
172
195
|
} | ({
|
|
173
196
|
type: 'tool';
|
|
174
|
-
} & ToolEvent)
|
|
197
|
+
} & ToolEvent) | {
|
|
198
|
+
type: 'artifactParams';
|
|
199
|
+
params: ArtifactParams;
|
|
200
|
+
source: 'user' | 'context';
|
|
201
|
+
};
|
|
175
202
|
/**
|
|
176
203
|
* A snapshot of the page as the agent sees it.
|
|
177
204
|
*
|
|
@@ -282,6 +309,16 @@ type HostToWidget = {
|
|
|
282
309
|
type: 'host.artifactGrants';
|
|
283
310
|
grants: ArtifactGrant[];
|
|
284
311
|
}
|
|
312
|
+
/**
|
|
313
|
+
* Set artifact param values. A PARTIAL patch — only the named params change, and
|
|
314
|
+
* each value is validated against its declared spec before it applies (unknown or
|
|
315
|
+
* invalid entries are dropped). Explicit and deliberate, so it always applies, even
|
|
316
|
+
* to a param whose page-context binding the viewer has overridden.
|
|
317
|
+
*/
|
|
318
|
+
| {
|
|
319
|
+
type: 'host.artifactParams';
|
|
320
|
+
params: ArtifactParams;
|
|
321
|
+
}
|
|
285
322
|
/**
|
|
286
323
|
* The annotated site map — the app's routes with the host's content
|
|
287
324
|
* classification. Sent on mount and re-sent on navigation (a virtualized SPA can
|
|
@@ -370,6 +407,13 @@ type WidgetToHost = {
|
|
|
370
407
|
| {
|
|
371
408
|
type: 'widget.requestContext';
|
|
372
409
|
}
|
|
410
|
+
/**
|
|
411
|
+
* Admin max page-context mode from bootstrap — host clamps observation to this.
|
|
412
|
+
*/
|
|
413
|
+
| {
|
|
414
|
+
type: 'widget.pageContextMax';
|
|
415
|
+
mode: 'full' | 'declared' | 'off';
|
|
416
|
+
}
|
|
373
417
|
/** Zoom in: the a11y sub-tree under one ref (a table, a form, a card the agent cares about). */
|
|
374
418
|
| {
|
|
375
419
|
type: 'widget.readRegion';
|
|
@@ -493,6 +537,17 @@ type WidgetToHost = {
|
|
|
493
537
|
type: 'widget.chat';
|
|
494
538
|
phase: 'message' | 'response-start' | 'response-end';
|
|
495
539
|
chatId?: string;
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* An artifact param changed. Emitted ONLY for user- and context-originated changes,
|
|
543
|
+
* never for a change the host itself pushed. The type excludes `'host'` so a caller
|
|
544
|
+
* cannot mislabel an echo as legitimate; the actual no-echo guarantee comes from the
|
|
545
|
+
* param store filtering by `source` before this callback is invoked.
|
|
546
|
+
*/
|
|
547
|
+
| {
|
|
548
|
+
type: 'widget.artifactParams';
|
|
549
|
+
params: ArtifactParams;
|
|
550
|
+
source: 'user' | 'context';
|
|
496
551
|
};
|
|
497
552
|
/**
|
|
498
553
|
* Everything on the wire is wrapped.
|
|
@@ -520,6 +575,20 @@ declare function isEnvelope(data: unknown): data is Envelope<unknown>;
|
|
|
520
575
|
*/
|
|
521
576
|
type PageContextProvider = () => PageContext | null | undefined | Promise<PageContext | null | undefined>;
|
|
522
577
|
|
|
578
|
+
declare global {
|
|
579
|
+
interface Window {
|
|
580
|
+
/**
|
|
581
|
+
* The loader's public host API. Declared here so the members this file
|
|
582
|
+
* installs are checked on both the read and the write; hosts also see a
|
|
583
|
+
* typed surface instead of an opaque bag.
|
|
584
|
+
*/
|
|
585
|
+
matterfact?: {
|
|
586
|
+
setArtifactParams?: (params: ArtifactParams) => void;
|
|
587
|
+
getPageContext?: unknown;
|
|
588
|
+
[key: string]: unknown;
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
}
|
|
523
592
|
/**
|
|
524
593
|
* The matterfact embed loader.
|
|
525
594
|
*
|
|
@@ -590,15 +659,10 @@ interface LoaderConfig {
|
|
|
590
659
|
*/
|
|
591
660
|
container?: HTMLElement | null;
|
|
592
661
|
/**
|
|
593
|
-
*
|
|
594
|
-
*
|
|
595
|
-
* gets sent: when this is false the loader never installs the DOM/nav/focus/activity
|
|
596
|
-
* observers in the first place, and an inbound `widget.requestSnapshot` is ignored
|
|
597
|
-
* rather than answered. Default `true` — seeing the page is the widget's whole value
|
|
598
|
-
* proposition; this is the escape hatch for a host that wants agent chat with nothing
|
|
599
|
-
* about the page ever reaching it.
|
|
662
|
+
* Page observation mode: `full` (default / `true`), `declared` (getPageContext +
|
|
663
|
+
* host sitemap only), or `off` (`false`). Auto DOM/focus/activity require `full`.
|
|
600
664
|
*/
|
|
601
|
-
pageContext?: boolean;
|
|
665
|
+
pageContext?: boolean | 'full' | 'declared' | 'off';
|
|
602
666
|
/**
|
|
603
667
|
* Force dev mode (see `devRequested()` below) without needing `?mfdev=1` on the host
|
|
604
668
|
* URL. This is the programmatic equivalent of that trigger, not a replacement for it —
|
|
@@ -736,6 +800,15 @@ declare class EmbedHost {
|
|
|
736
800
|
private loadContext;
|
|
737
801
|
private send;
|
|
738
802
|
private flush;
|
|
803
|
+
/**
|
|
804
|
+
* Push artifact param values into the widget — a PARTIAL patch; only the named
|
|
805
|
+
* params change. Buffered like every other host→widget message until the widget
|
|
806
|
+
* says it's listening.
|
|
807
|
+
*
|
|
808
|
+
* Explicit and deliberate, so it applies even to a param whose page-context binding
|
|
809
|
+
* the viewer has overridden (spec §7.3).
|
|
810
|
+
*/
|
|
811
|
+
setArtifactParams(params: ArtifactParams): void;
|
|
739
812
|
/** Tear down: stop listening and remove the host element. For the React wrapper's
|
|
740
813
|
* unmount — the vanilla `<script>` loader lives for the page's lifetime and never
|
|
741
814
|
* calls this. */
|
|
@@ -748,4 +821,4 @@ declare class EmbedHost {
|
|
|
748
821
|
*/
|
|
749
822
|
declare function mount(config: LoaderConfig): EmbedHost;
|
|
750
823
|
|
|
751
|
-
export { type ActivityEvent, type ArtifactGrant, CHANNEL, type ContentClass, type DeclaredArtifact, type DomSnapshot, type ElementRef, EmbedHost, type Envelope, type FocusContext, type HostToWidget, type HostTool, type LoaderConfig, type MatterfactEvent, PROTOCOL_VERSION, type PageContext, type PageEntity, type SiteMapEntry, type ToolCall, type ToolEvent, type WidgetToHost, envelope, isEnvelope, mount, readConfig };
|
|
824
|
+
export { type ActivityEvent, type ArtifactGrant, type ArtifactParamValue, type ArtifactParams, CHANNEL, type ContentClass, type DeclaredArtifact, type DomSnapshot, type ElementRef, EmbedHost, type Envelope, type FocusContext, type HostToWidget, type HostTool, type LoaderConfig, type MatterfactEvent, PROTOCOL_VERSION, type PageContext, type PageEntity, type SiteMapEntry, type ToolCall, type ToolEvent, type WidgetToHost, envelope, isEnvelope, mount, readConfig };
|
package/dist/index.js
CHANGED
|
@@ -224,11 +224,19 @@ function dockBox(g, vw, _vh) {
|
|
|
224
224
|
var DEFAULT_ORIGIN = "https://app.matterfact.com";
|
|
225
225
|
function devRequested() {
|
|
226
226
|
try {
|
|
227
|
-
|
|
227
|
+
if (new URLSearchParams(location.search).get("mfdev") === "1") return true;
|
|
228
|
+
try {
|
|
229
|
+
return localStorage.getItem("mfdev") === "1";
|
|
230
|
+
} catch {
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
228
233
|
} catch {
|
|
229
234
|
return false;
|
|
230
235
|
}
|
|
231
236
|
}
|
|
237
|
+
function alog(m, x) {
|
|
238
|
+
if (devRequested()) console.info("[embed auth] host: " + m, x ?? "");
|
|
239
|
+
}
|
|
232
240
|
function readConfig() {
|
|
233
241
|
const el = document.currentScript ?? document.querySelector('script[data-key][src*="embed"]');
|
|
234
242
|
const publishableKey = el?.dataset.key;
|
|
@@ -244,13 +252,21 @@ function readConfig() {
|
|
|
244
252
|
);
|
|
245
253
|
}
|
|
246
254
|
const pageContextAttr = el?.dataset.pageContext?.toLowerCase();
|
|
255
|
+
let pageContext = true;
|
|
256
|
+
if (pageContextAttr === "off" || pageContextAttr === "false" || pageContextAttr === "0") {
|
|
257
|
+
pageContext = false;
|
|
258
|
+
} else if (pageContextAttr === "declared") {
|
|
259
|
+
pageContext = "declared";
|
|
260
|
+
} else if (pageContextAttr === "full" || pageContextAttr === "on" || pageContextAttr === "true" || pageContextAttr === "1") {
|
|
261
|
+
pageContext = true;
|
|
262
|
+
}
|
|
247
263
|
return {
|
|
248
264
|
publishableKey,
|
|
249
265
|
origin: el?.dataset.origin || DEFAULT_ORIGIN,
|
|
250
266
|
theme: el?.dataset.theme || "auto",
|
|
251
267
|
surface: el?.dataset.surface || "",
|
|
252
268
|
container,
|
|
253
|
-
pageContext
|
|
269
|
+
pageContext
|
|
254
270
|
// No `data-dev` — see the `dev` field's doc comment: the URL trigger is the
|
|
255
271
|
// point for the script-tag path, so there is deliberately no script-tag knob here.
|
|
256
272
|
// No `data-actions` either: the action policy lives entirely in the lazy chunk,
|
|
@@ -520,6 +536,11 @@ var EmbedHost = class {
|
|
|
520
536
|
case "widget.requestContext":
|
|
521
537
|
void this.loadContext().then((m) => m.provideContext());
|
|
522
538
|
break;
|
|
539
|
+
case "widget.pageContextMax":
|
|
540
|
+
void this.loadContext().then((m) => {
|
|
541
|
+
m.setPageContextMax(msg.mode);
|
|
542
|
+
});
|
|
543
|
+
break;
|
|
523
544
|
case "widget.requestSnapshot":
|
|
524
545
|
void this.loadContext().then((m) => m.sendSnapshot(this.send));
|
|
525
546
|
break;
|
|
@@ -624,6 +645,13 @@ var EmbedHost = class {
|
|
|
624
645
|
case "widget.chat":
|
|
625
646
|
this.emit({ type: "chat", phase: msg.phase, chatId: msg.chatId });
|
|
626
647
|
break;
|
|
648
|
+
case "widget.artifactParams":
|
|
649
|
+
this.emit({
|
|
650
|
+
type: "artifactParams",
|
|
651
|
+
params: msg.params,
|
|
652
|
+
source: msg.source
|
|
653
|
+
});
|
|
654
|
+
break;
|
|
627
655
|
}
|
|
628
656
|
}
|
|
629
657
|
/**
|
|
@@ -731,18 +759,26 @@ var EmbedHost = class {
|
|
|
731
759
|
*/
|
|
732
760
|
async provideAuth() {
|
|
733
761
|
const provider = this.config.authTokenProvider ?? globalThis.matterfact?.getEmbedAuthToken;
|
|
734
|
-
if (!provider)
|
|
735
|
-
|
|
762
|
+
if (!provider) {
|
|
763
|
+
alog("no provider");
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
if (++this.ac > 5) {
|
|
767
|
+
alog("storm cap");
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
736
770
|
try {
|
|
737
771
|
const token = await provider();
|
|
738
772
|
if (token) this.send({ type: "host.auth", token, expiresAt: 0 });
|
|
739
773
|
this.emit({ type: "auth", phase: token ? "granted" : "failed" });
|
|
740
|
-
|
|
774
|
+
alog(token ? "token" : "empty");
|
|
775
|
+
} catch (e) {
|
|
741
776
|
this.emit({ type: "auth", phase: "failed" });
|
|
777
|
+
alog("threw", e);
|
|
742
778
|
}
|
|
743
779
|
}
|
|
744
780
|
loadContext() {
|
|
745
|
-
this.context ?? (this.context = import('./context-
|
|
781
|
+
this.context ?? (this.context = import('./context-DAXACLSP.js').then((m) => {
|
|
746
782
|
m.start(
|
|
747
783
|
this.send,
|
|
748
784
|
this.config.origin,
|
|
@@ -761,6 +797,23 @@ var EmbedHost = class {
|
|
|
761
797
|
this.queue = [];
|
|
762
798
|
for (const m of pending) this.send(m);
|
|
763
799
|
}
|
|
800
|
+
/**
|
|
801
|
+
* Push artifact param values into the widget — a PARTIAL patch; only the named
|
|
802
|
+
* params change. Buffered like every other host→widget message until the widget
|
|
803
|
+
* says it's listening.
|
|
804
|
+
*
|
|
805
|
+
* Explicit and deliberate, so it applies even to a param whose page-context binding
|
|
806
|
+
* the viewer has overridden (spec §7.3).
|
|
807
|
+
*/
|
|
808
|
+
setArtifactParams(params) {
|
|
809
|
+
if (params == null || typeof params !== "object" || Array.isArray(params)) {
|
|
810
|
+
console.error(
|
|
811
|
+
"[matterfact] setArtifactParams expects an object of param values"
|
|
812
|
+
);
|
|
813
|
+
return;
|
|
814
|
+
}
|
|
815
|
+
this.send({ type: "host.artifactParams", params });
|
|
816
|
+
}
|
|
764
817
|
/** Tear down: stop listening and remove the host element. For the React wrapper's
|
|
765
818
|
* unmount — the vanilla `<script>` loader lives for the page's lifetime and never
|
|
766
819
|
* calls this. */
|
|
@@ -778,6 +831,10 @@ var EmbedHost = class {
|
|
|
778
831
|
function mount(config) {
|
|
779
832
|
const host = new EmbedHost(config);
|
|
780
833
|
host.mount();
|
|
834
|
+
window.matterfact = {
|
|
835
|
+
...window.matterfact ?? {},
|
|
836
|
+
setArtifactParams: (params) => host.setArtifactParams(params)
|
|
837
|
+
};
|
|
781
838
|
return host;
|
|
782
839
|
}
|
|
783
840
|
|