@matterfact/embed 0.12.0 → 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-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 +82 -32
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +28 -1
- package/dist/react.d.ts +28 -1
- package/dist/react.js +29 -1
- 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/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/react.d.cts
CHANGED
|
@@ -108,7 +108,30 @@ interface ToolEvent {
|
|
|
108
108
|
* - `chat` — a chat-turn moment. Content-free: phase + opaque chatId only.
|
|
109
109
|
* - `tool` — a host-tool lifecycle event (the `ToolEvent` shape, tagged). Also
|
|
110
110
|
* still delivered untagged to the legacy `onToolEvent` hook for back-compat.
|
|
111
|
+
* - `artifactParams` — an artifact param changed in the widget.
|
|
111
112
|
*/
|
|
113
|
+
/**
|
|
114
|
+
* A value an artifact param can carry. Mirrors the app's `ParamValue`
|
|
115
|
+
* (`enum` / `enum[]` / `entity` / `date` / `daterange` / `boolean` / `number`)
|
|
116
|
+
* DELIBERATELY BY COPY, not by import: this is a wire contract between two
|
|
117
|
+
* independently-deployed artifacts, and a shared type would let a rename
|
|
118
|
+
* compile on both sides while still breaking the wire. Bump PROTOCOL_VERSION
|
|
119
|
+
* instead. See this file's header.
|
|
120
|
+
*/
|
|
121
|
+
type ArtifactParamValue = string | string[] | number | boolean
|
|
122
|
+
/** `daterange`: a [from, to] pair of YYYY-MM-DD strings. */
|
|
123
|
+
| [string, string];
|
|
124
|
+
/**
|
|
125
|
+
* Artifact params on the wire, keyed by declared param name.
|
|
126
|
+
*
|
|
127
|
+
* Values are typed but NOT verified against the artifact's declared spec —
|
|
128
|
+
* a host can send anything, and the widget's param store coerces each value
|
|
129
|
+
* to its declared type (or drops it) on arrival. This type says what a
|
|
130
|
+
* well-behaved host means to send, not what the widget trusts it to have sent.
|
|
131
|
+
*/
|
|
132
|
+
type ArtifactParams = {
|
|
133
|
+
[name: string]: ArtifactParamValue;
|
|
134
|
+
};
|
|
112
135
|
type MatterfactEvent = {
|
|
113
136
|
type: 'ready';
|
|
114
137
|
} | {
|
|
@@ -130,7 +153,11 @@ type MatterfactEvent = {
|
|
|
130
153
|
chatId?: string;
|
|
131
154
|
} | ({
|
|
132
155
|
type: 'tool';
|
|
133
|
-
} & ToolEvent)
|
|
156
|
+
} & ToolEvent) | {
|
|
157
|
+
type: 'artifactParams';
|
|
158
|
+
params: ArtifactParams;
|
|
159
|
+
source: 'user' | 'context';
|
|
160
|
+
};
|
|
134
161
|
|
|
135
162
|
/**
|
|
136
163
|
* The Hoist adapter — a pure transform from a `HoistRuntime` (already read out of
|
package/dist/react.d.ts
CHANGED
|
@@ -108,7 +108,30 @@ interface ToolEvent {
|
|
|
108
108
|
* - `chat` — a chat-turn moment. Content-free: phase + opaque chatId only.
|
|
109
109
|
* - `tool` — a host-tool lifecycle event (the `ToolEvent` shape, tagged). Also
|
|
110
110
|
* still delivered untagged to the legacy `onToolEvent` hook for back-compat.
|
|
111
|
+
* - `artifactParams` — an artifact param changed in the widget.
|
|
111
112
|
*/
|
|
113
|
+
/**
|
|
114
|
+
* A value an artifact param can carry. Mirrors the app's `ParamValue`
|
|
115
|
+
* (`enum` / `enum[]` / `entity` / `date` / `daterange` / `boolean` / `number`)
|
|
116
|
+
* DELIBERATELY BY COPY, not by import: this is a wire contract between two
|
|
117
|
+
* independently-deployed artifacts, and a shared type would let a rename
|
|
118
|
+
* compile on both sides while still breaking the wire. Bump PROTOCOL_VERSION
|
|
119
|
+
* instead. See this file's header.
|
|
120
|
+
*/
|
|
121
|
+
type ArtifactParamValue = string | string[] | number | boolean
|
|
122
|
+
/** `daterange`: a [from, to] pair of YYYY-MM-DD strings. */
|
|
123
|
+
| [string, string];
|
|
124
|
+
/**
|
|
125
|
+
* Artifact params on the wire, keyed by declared param name.
|
|
126
|
+
*
|
|
127
|
+
* Values are typed but NOT verified against the artifact's declared spec —
|
|
128
|
+
* a host can send anything, and the widget's param store coerces each value
|
|
129
|
+
* to its declared type (or drops it) on arrival. This type says what a
|
|
130
|
+
* well-behaved host means to send, not what the widget trusts it to have sent.
|
|
131
|
+
*/
|
|
132
|
+
type ArtifactParams = {
|
|
133
|
+
[name: string]: ArtifactParamValue;
|
|
134
|
+
};
|
|
112
135
|
type MatterfactEvent = {
|
|
113
136
|
type: 'ready';
|
|
114
137
|
} | {
|
|
@@ -130,7 +153,11 @@ type MatterfactEvent = {
|
|
|
130
153
|
chatId?: string;
|
|
131
154
|
} | ({
|
|
132
155
|
type: 'tool';
|
|
133
|
-
} & ToolEvent)
|
|
156
|
+
} & ToolEvent) | {
|
|
157
|
+
type: 'artifactParams';
|
|
158
|
+
params: ArtifactParams;
|
|
159
|
+
source: 'user' | 'context';
|
|
160
|
+
};
|
|
134
161
|
|
|
135
162
|
/**
|
|
136
163
|
* The Hoist adapter — a pure transform from a `HoistRuntime` (already read out of
|
package/dist/react.js
CHANGED
|
@@ -613,6 +613,13 @@ var EmbedHost = class {
|
|
|
613
613
|
case "widget.chat":
|
|
614
614
|
this.emit({ type: "chat", phase: msg.phase, chatId: msg.chatId });
|
|
615
615
|
break;
|
|
616
|
+
case "widget.artifactParams":
|
|
617
|
+
this.emit({
|
|
618
|
+
type: "artifactParams",
|
|
619
|
+
params: msg.params,
|
|
620
|
+
source: msg.source
|
|
621
|
+
});
|
|
622
|
+
break;
|
|
616
623
|
}
|
|
617
624
|
}
|
|
618
625
|
/**
|
|
@@ -739,7 +746,7 @@ var EmbedHost = class {
|
|
|
739
746
|
}
|
|
740
747
|
}
|
|
741
748
|
loadContext() {
|
|
742
|
-
this.context ?? (this.context = import("./context-
|
|
749
|
+
this.context ?? (this.context = import("./context-IJK345PN.js").then((m) => {
|
|
743
750
|
m.start(
|
|
744
751
|
this.send,
|
|
745
752
|
this.config.origin,
|
|
@@ -758,6 +765,23 @@ var EmbedHost = class {
|
|
|
758
765
|
this.queue = [];
|
|
759
766
|
for (const m of pending) this.send(m);
|
|
760
767
|
}
|
|
768
|
+
/**
|
|
769
|
+
* Push artifact param values into the widget — a PARTIAL patch; only the named
|
|
770
|
+
* params change. Buffered like every other host→widget message until the widget
|
|
771
|
+
* says it's listening.
|
|
772
|
+
*
|
|
773
|
+
* Explicit and deliberate, so it applies even to a param whose page-context binding
|
|
774
|
+
* the viewer has overridden (spec §7.3).
|
|
775
|
+
*/
|
|
776
|
+
setArtifactParams(params) {
|
|
777
|
+
if (params == null || typeof params !== "object" || Array.isArray(params)) {
|
|
778
|
+
console.error(
|
|
779
|
+
"[matterfact] setArtifactParams expects an object of param values"
|
|
780
|
+
);
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
this.send({ type: "host.artifactParams", params });
|
|
784
|
+
}
|
|
761
785
|
/** Tear down: stop listening and remove the host element. For the React wrapper's
|
|
762
786
|
* unmount — the vanilla `<script>` loader lives for the page's lifetime and never
|
|
763
787
|
* calls this. */
|
|
@@ -775,6 +799,10 @@ var EmbedHost = class {
|
|
|
775
799
|
function mount(config) {
|
|
776
800
|
const host = new EmbedHost(config);
|
|
777
801
|
host.mount();
|
|
802
|
+
window.matterfact = {
|
|
803
|
+
...window.matterfact ?? {},
|
|
804
|
+
setArtifactParams: (params) => host.setArtifactParams(params)
|
|
805
|
+
};
|
|
778
806
|
return host;
|
|
779
807
|
}
|
|
780
808
|
|