@matterfact/embed 0.12.0 → 0.15.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-M5TS546Z.js → chunk-C7DXO37G.js} +2 -2
- package/dist/{chunk-ZXMJWCQV.js → chunk-JLJG3MDX.js} +57 -35
- 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-C4XGE6BO.js → chunk-S6OT47DL.js} +56 -34
- package/dist/chunk-S6OT47DL.js.map +1 -0
- package/dist/{chunk-WAUSVV7Y.js → chunk-UA4Y2O64.js} +2 -2
- package/dist/{context-4LP3EDXL.js → context-DAXACLSP.js} +3 -3
- package/dist/{context-4LP3EDXL.js.map → context-DAXACLSP.js.map} +1 -1
- package/dist/{context-ZSPDZWIB.js → context-IJK345PN.js} +2 -2
- package/dist/embed.js +1 -1
- package/dist/embed.js.map +3 -3
- package/dist/index.cjs +82 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +73 -2
- package/dist/index.d.ts +73 -2
- package/dist/index.js +29 -1
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +281 -55
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +168 -12
- package/dist/react.d.ts +168 -12
- package/dist/react.js +221 -19
- package/dist/react.js.map +1 -1
- package/dist/{snapshot-OR5SVEUD.js → snapshot-EVBNVVCT.js} +2 -2
- package/dist/{snapshot-X6FPP3HF.js → snapshot-P5SVKSPB.js} +3 -3
- package/dist/{snapshot-X6FPP3HF.js.map → snapshot-P5SVKSPB.js.map} +1 -1
- package/examples/embed-demo/.env.example +9 -0
- package/examples/embed-demo/README.md +66 -12
- package/examples/embed-demo/src/App.tsx +56 -12
- package/examples/embed-demo/src/config.ts +8 -0
- package/package.json +1 -1
- package/dist/chunk-C4XGE6BO.js.map +0 -1
- package/dist/chunk-SR4ZNUAN.js +0 -3
- package/dist/chunk-SR4ZNUAN.js.map +0 -7
- package/dist/chunk-ZXMJWCQV.js.map +0 -1
- /package/dist/{chunk-M5TS546Z.js.map → chunk-C7DXO37G.js.map} +0 -0
- /package/dist/{chunk-WAUSVV7Y.js.map → chunk-UA4Y2O64.js.map} +0 -0
- /package/dist/{context-ZSPDZWIB.js.map → context-IJK345PN.js.map} +0 -0
- /package/dist/{snapshot-OR5SVEUD.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
|
|
@@ -500,6 +537,17 @@ type WidgetToHost = {
|
|
|
500
537
|
type: 'widget.chat';
|
|
501
538
|
phase: 'message' | 'response-start' | 'response-end';
|
|
502
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';
|
|
503
551
|
};
|
|
504
552
|
/**
|
|
505
553
|
* Everything on the wire is wrapped.
|
|
@@ -527,6 +575,20 @@ declare function isEnvelope(data: unknown): data is Envelope<unknown>;
|
|
|
527
575
|
*/
|
|
528
576
|
type PageContextProvider = () => PageContext | null | undefined | Promise<PageContext | null | undefined>;
|
|
529
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
|
+
}
|
|
530
592
|
/**
|
|
531
593
|
* The matterfact embed loader.
|
|
532
594
|
*
|
|
@@ -738,6 +800,15 @@ declare class EmbedHost {
|
|
|
738
800
|
private loadContext;
|
|
739
801
|
private send;
|
|
740
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;
|
|
741
812
|
/** Tear down: stop listening and remove the host element. For the React wrapper's
|
|
742
813
|
* unmount — the vanilla `<script>` loader lives for the page's lifetime and never
|
|
743
814
|
* calls this. */
|
|
@@ -750,4 +821,4 @@ declare class EmbedHost {
|
|
|
750
821
|
*/
|
|
751
822
|
declare function mount(config: LoaderConfig): EmbedHost;
|
|
752
823
|
|
|
753
|
-
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
|
|
@@ -500,6 +537,17 @@ type WidgetToHost = {
|
|
|
500
537
|
type: 'widget.chat';
|
|
501
538
|
phase: 'message' | 'response-start' | 'response-end';
|
|
502
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';
|
|
503
551
|
};
|
|
504
552
|
/**
|
|
505
553
|
* Everything on the wire is wrapped.
|
|
@@ -527,6 +575,20 @@ declare function isEnvelope(data: unknown): data is Envelope<unknown>;
|
|
|
527
575
|
*/
|
|
528
576
|
type PageContextProvider = () => PageContext | null | undefined | Promise<PageContext | null | undefined>;
|
|
529
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
|
+
}
|
|
530
592
|
/**
|
|
531
593
|
* The matterfact embed loader.
|
|
532
594
|
*
|
|
@@ -738,6 +800,15 @@ declare class EmbedHost {
|
|
|
738
800
|
private loadContext;
|
|
739
801
|
private send;
|
|
740
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;
|
|
741
812
|
/** Tear down: stop listening and remove the host element. For the React wrapper's
|
|
742
813
|
* unmount — the vanilla `<script>` loader lives for the page's lifetime and never
|
|
743
814
|
* calls this. */
|
|
@@ -750,4 +821,4 @@ declare class EmbedHost {
|
|
|
750
821
|
*/
|
|
751
822
|
declare function mount(config: LoaderConfig): EmbedHost;
|
|
752
823
|
|
|
753
|
-
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
|
@@ -645,6 +645,13 @@ var EmbedHost = class {
|
|
|
645
645
|
case "widget.chat":
|
|
646
646
|
this.emit({ type: "chat", phase: msg.phase, chatId: msg.chatId });
|
|
647
647
|
break;
|
|
648
|
+
case "widget.artifactParams":
|
|
649
|
+
this.emit({
|
|
650
|
+
type: "artifactParams",
|
|
651
|
+
params: msg.params,
|
|
652
|
+
source: msg.source
|
|
653
|
+
});
|
|
654
|
+
break;
|
|
648
655
|
}
|
|
649
656
|
}
|
|
650
657
|
/**
|
|
@@ -771,7 +778,7 @@ var EmbedHost = class {
|
|
|
771
778
|
}
|
|
772
779
|
}
|
|
773
780
|
loadContext() {
|
|
774
|
-
this.context ?? (this.context = import('./context-
|
|
781
|
+
this.context ?? (this.context = import('./context-DAXACLSP.js').then((m) => {
|
|
775
782
|
m.start(
|
|
776
783
|
this.send,
|
|
777
784
|
this.config.origin,
|
|
@@ -790,6 +797,23 @@ var EmbedHost = class {
|
|
|
790
797
|
this.queue = [];
|
|
791
798
|
for (const m of pending) this.send(m);
|
|
792
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
|
+
}
|
|
793
817
|
/** Tear down: stop listening and remove the host element. For the React wrapper's
|
|
794
818
|
* unmount — the vanilla `<script>` loader lives for the page's lifetime and never
|
|
795
819
|
* calls this. */
|
|
@@ -807,6 +831,10 @@ var EmbedHost = class {
|
|
|
807
831
|
function mount(config) {
|
|
808
832
|
const host = new EmbedHost(config);
|
|
809
833
|
host.mount();
|
|
834
|
+
window.matterfact = {
|
|
835
|
+
...window.matterfact ?? {},
|
|
836
|
+
setArtifactParams: (params) => host.setArtifactParams(params)
|
|
837
|
+
};
|
|
810
838
|
return host;
|
|
811
839
|
}
|
|
812
840
|
|