@matterfact/embed 0.9.0 → 0.11.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 +122 -0
- package/dist/{chunk-6EM7T2JV.js → chunk-AANODHBV.js} +217 -15
- package/dist/chunk-AANODHBV.js.map +1 -0
- package/dist/{chunk-URGQBG4I.js → chunk-CTZEDOH7.js} +218 -17
- package/dist/chunk-CTZEDOH7.js.map +1 -0
- package/dist/{chunk-BKKXHSYU.js → chunk-JO3GWFMJ.js} +2 -2
- package/dist/chunk-SKJFF7RD.js +2 -0
- package/dist/chunk-Y7I25VHL.js +3 -0
- package/dist/chunk-Y7I25VHL.js.map +7 -0
- package/dist/context-FR7VFENN.js +3 -0
- package/dist/{context-ACFBWIFH.js.map → context-FR7VFENN.js.map} +1 -1
- package/dist/{context-U2HJJN2S.js → context-IK5MECUW.js} +4 -2
- package/dist/embed.js +1 -1
- package/dist/embed.js.map +3 -3
- package/dist/index.cjs +247 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +88 -1
- package/dist/index.d.ts +88 -1
- package/dist/index.js +25 -1
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +302 -15
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +174 -2
- package/dist/react.d.ts +174 -2
- package/dist/react.js +79 -3
- package/dist/react.js.map +1 -1
- package/dist/{snapshot-4GXT6PKZ.js → snapshot-2V5SDSH2.js} +2 -2
- package/dist/{snapshot-Y75SCGCM.js → snapshot-Y5BF2UJR.js} +3 -3
- package/dist/{snapshot-Y75SCGCM.js.map → snapshot-Y5BF2UJR.js.map} +1 -1
- package/examples/embed-demo/README.md +22 -0
- package/examples/embed-demo/src/App.tsx +105 -2
- package/examples/embed-demo/src/styles.css +29 -0
- package/package.json +1 -1
- package/dist/chunk-6EM7T2JV.js.map +0 -1
- package/dist/chunk-FEXG4LQJ.js +0 -3
- package/dist/chunk-FEXG4LQJ.js.map +0 -7
- package/dist/chunk-NWNMS34P.js +0 -2
- package/dist/chunk-URGQBG4I.js.map +0 -1
- package/dist/context-ACFBWIFH.js +0 -3
- /package/dist/{chunk-BKKXHSYU.js.map → chunk-JO3GWFMJ.js.map} +0 -0
- /package/dist/{chunk-NWNMS34P.js.map → chunk-SKJFF7RD.js.map} +0 -0
- /package/dist/{context-U2HJJN2S.js.map → context-IK5MECUW.js.map} +0 -0
- /package/dist/{snapshot-4GXT6PKZ.js.map → snapshot-2V5SDSH2.js.map} +0 -0
package/dist/index.d.cts
CHANGED
|
@@ -102,6 +102,76 @@ interface ArtifactGrant {
|
|
|
102
102
|
owner: string;
|
|
103
103
|
token: string;
|
|
104
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* A DECLARED artifact grant — the `<MatterfactAgent artifacts>` prop (or
|
|
107
|
+
* `window.matterfact.artifacts`). Same wire shape as a grant discovered by scanning
|
|
108
|
+
* co-embedded `<MatterfactArtifact>` iframes, plus an optional `label`; it feeds the
|
|
109
|
+
* SAME `host.artifactGrants` channel. This is how a host makes a board reachable from
|
|
110
|
+
* a route where its iframe ISN'T mounted, without hidden zero-size iframes smuggling
|
|
111
|
+
* the token into the DOM. The token stays in the grant channel, never in message text.
|
|
112
|
+
*/
|
|
113
|
+
interface DeclaredArtifact {
|
|
114
|
+
slug: string;
|
|
115
|
+
owner: string;
|
|
116
|
+
token: string;
|
|
117
|
+
label?: string;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* One host-tool lifecycle event, surfaced to the host via `onToolEvent` (and the dev
|
|
121
|
+
* panel) — the host's own telemetry hook. Fired loader-side; a throwing or slow
|
|
122
|
+
* callback here NEVER blocks or breaks the call path.
|
|
123
|
+
*
|
|
124
|
+
* - `advertise` — the merged tool list changed (fired with the new set's names).
|
|
125
|
+
* - `call` — a tool call is about to run (`args` present).
|
|
126
|
+
* - `result` — the call settled (`ok`/`error`/`ms`).
|
|
127
|
+
*/
|
|
128
|
+
interface ToolEvent {
|
|
129
|
+
phase: 'advertise' | 'call' | 'result';
|
|
130
|
+
name: string;
|
|
131
|
+
toolClass: 'hoist' | 'mf' | 'app';
|
|
132
|
+
args?: unknown;
|
|
133
|
+
ok?: boolean;
|
|
134
|
+
error?: string;
|
|
135
|
+
ms?: number;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* One embed lifecycle event, surfaced to the host via `onEvent` — the host's single
|
|
139
|
+
* telemetry hook. Fired loader-side (lifecycle) and widget-side (chat); a throwing or
|
|
140
|
+
* slow callback NEVER blocks or breaks the mount/call/auth/run path.
|
|
141
|
+
*
|
|
142
|
+
* - `ready` — the widget connected (protocol handshake done).
|
|
143
|
+
* - `open`/`close` — the corner widget was opened/closed. (Inline has no open event —
|
|
144
|
+
* the host's own panel is the open/close control.)
|
|
145
|
+
* - `navigate` — the agent deeplinked the host to one of its own routes.
|
|
146
|
+
* - `auth` — host-auth passthrough: `required` (widget asked), `granted` (a
|
|
147
|
+
* token was handed over), `failed` (no provider result / the provider threw).
|
|
148
|
+
* - `error` — the widget failed to mount / load.
|
|
149
|
+
* - `chat` — a chat-turn moment. Content-free: phase + opaque chatId only.
|
|
150
|
+
* - `tool` — a host-tool lifecycle event (the `ToolEvent` shape, tagged). Also
|
|
151
|
+
* still delivered untagged to the legacy `onToolEvent` hook for back-compat.
|
|
152
|
+
*/
|
|
153
|
+
type MatterfactEvent = {
|
|
154
|
+
type: 'ready';
|
|
155
|
+
} | {
|
|
156
|
+
type: 'open';
|
|
157
|
+
} | {
|
|
158
|
+
type: 'close';
|
|
159
|
+
} | {
|
|
160
|
+
type: 'navigate';
|
|
161
|
+
href: string;
|
|
162
|
+
} | {
|
|
163
|
+
type: 'auth';
|
|
164
|
+
phase: 'required' | 'granted' | 'failed';
|
|
165
|
+
} | {
|
|
166
|
+
type: 'error';
|
|
167
|
+
message: string;
|
|
168
|
+
} | {
|
|
169
|
+
type: 'chat';
|
|
170
|
+
phase: 'message' | 'response-start' | 'response-end';
|
|
171
|
+
chatId?: string;
|
|
172
|
+
} | ({
|
|
173
|
+
type: 'tool';
|
|
174
|
+
} & ToolEvent);
|
|
105
175
|
/**
|
|
106
176
|
* A snapshot of the page as the agent sees it.
|
|
107
177
|
*
|
|
@@ -414,6 +484,15 @@ type WidgetToHost = {
|
|
|
414
484
|
| {
|
|
415
485
|
type: 'widget.navigate';
|
|
416
486
|
href: string;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* A chat-turn lifecycle moment, forwarded by the loader to the host's `onEvent`.
|
|
490
|
+
* Content-free: `phase` + an opaque `chatId`, never message text. Additive.
|
|
491
|
+
*/
|
|
492
|
+
| {
|
|
493
|
+
type: 'widget.chat';
|
|
494
|
+
phase: 'message' | 'response-start' | 'response-end';
|
|
495
|
+
chatId?: string;
|
|
417
496
|
};
|
|
418
497
|
/**
|
|
419
498
|
* Everything on the wire is wrapped.
|
|
@@ -590,6 +669,14 @@ declare class EmbedHost {
|
|
|
590
669
|
* without weakening the origin/source checks above, which stay the only real door.
|
|
591
670
|
*/
|
|
592
671
|
__testHandle(msg: WidgetToHost): void;
|
|
672
|
+
/**
|
|
673
|
+
* The eager stub's own emit-and-swallow for the host's `onEvent` telemetry hook.
|
|
674
|
+
* Deliberately does NOT import the registry's `emitEvent`: pulling the lazy ./context
|
|
675
|
+
* chunk (where the registry lives) into the size-budgeted stub would blow it, so this
|
|
676
|
+
* ~5-line duplication across the bundle boundary is intentional. Host telemetry is
|
|
677
|
+
* host code — a throw here must never break the widget.
|
|
678
|
+
*/
|
|
679
|
+
private emit;
|
|
593
680
|
private handle;
|
|
594
681
|
/**
|
|
595
682
|
* Own a drag for its lifetime.
|
|
@@ -661,4 +748,4 @@ declare class EmbedHost {
|
|
|
661
748
|
*/
|
|
662
749
|
declare function mount(config: LoaderConfig): EmbedHost;
|
|
663
750
|
|
|
664
|
-
export { type ActivityEvent, type ArtifactGrant, CHANNEL, type ContentClass, type DomSnapshot, type ElementRef, EmbedHost, type Envelope, type FocusContext, type HostToWidget, type HostTool, type LoaderConfig, PROTOCOL_VERSION, type PageContext, type PageEntity, type SiteMapEntry, type ToolCall, type WidgetToHost, envelope, isEnvelope, mount, readConfig };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -102,6 +102,76 @@ interface ArtifactGrant {
|
|
|
102
102
|
owner: string;
|
|
103
103
|
token: string;
|
|
104
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* A DECLARED artifact grant — the `<MatterfactAgent artifacts>` prop (or
|
|
107
|
+
* `window.matterfact.artifacts`). Same wire shape as a grant discovered by scanning
|
|
108
|
+
* co-embedded `<MatterfactArtifact>` iframes, plus an optional `label`; it feeds the
|
|
109
|
+
* SAME `host.artifactGrants` channel. This is how a host makes a board reachable from
|
|
110
|
+
* a route where its iframe ISN'T mounted, without hidden zero-size iframes smuggling
|
|
111
|
+
* the token into the DOM. The token stays in the grant channel, never in message text.
|
|
112
|
+
*/
|
|
113
|
+
interface DeclaredArtifact {
|
|
114
|
+
slug: string;
|
|
115
|
+
owner: string;
|
|
116
|
+
token: string;
|
|
117
|
+
label?: string;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* One host-tool lifecycle event, surfaced to the host via `onToolEvent` (and the dev
|
|
121
|
+
* panel) — the host's own telemetry hook. Fired loader-side; a throwing or slow
|
|
122
|
+
* callback here NEVER blocks or breaks the call path.
|
|
123
|
+
*
|
|
124
|
+
* - `advertise` — the merged tool list changed (fired with the new set's names).
|
|
125
|
+
* - `call` — a tool call is about to run (`args` present).
|
|
126
|
+
* - `result` — the call settled (`ok`/`error`/`ms`).
|
|
127
|
+
*/
|
|
128
|
+
interface ToolEvent {
|
|
129
|
+
phase: 'advertise' | 'call' | 'result';
|
|
130
|
+
name: string;
|
|
131
|
+
toolClass: 'hoist' | 'mf' | 'app';
|
|
132
|
+
args?: unknown;
|
|
133
|
+
ok?: boolean;
|
|
134
|
+
error?: string;
|
|
135
|
+
ms?: number;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* One embed lifecycle event, surfaced to the host via `onEvent` — the host's single
|
|
139
|
+
* telemetry hook. Fired loader-side (lifecycle) and widget-side (chat); a throwing or
|
|
140
|
+
* slow callback NEVER blocks or breaks the mount/call/auth/run path.
|
|
141
|
+
*
|
|
142
|
+
* - `ready` — the widget connected (protocol handshake done).
|
|
143
|
+
* - `open`/`close` — the corner widget was opened/closed. (Inline has no open event —
|
|
144
|
+
* the host's own panel is the open/close control.)
|
|
145
|
+
* - `navigate` — the agent deeplinked the host to one of its own routes.
|
|
146
|
+
* - `auth` — host-auth passthrough: `required` (widget asked), `granted` (a
|
|
147
|
+
* token was handed over), `failed` (no provider result / the provider threw).
|
|
148
|
+
* - `error` — the widget failed to mount / load.
|
|
149
|
+
* - `chat` — a chat-turn moment. Content-free: phase + opaque chatId only.
|
|
150
|
+
* - `tool` — a host-tool lifecycle event (the `ToolEvent` shape, tagged). Also
|
|
151
|
+
* still delivered untagged to the legacy `onToolEvent` hook for back-compat.
|
|
152
|
+
*/
|
|
153
|
+
type MatterfactEvent = {
|
|
154
|
+
type: 'ready';
|
|
155
|
+
} | {
|
|
156
|
+
type: 'open';
|
|
157
|
+
} | {
|
|
158
|
+
type: 'close';
|
|
159
|
+
} | {
|
|
160
|
+
type: 'navigate';
|
|
161
|
+
href: string;
|
|
162
|
+
} | {
|
|
163
|
+
type: 'auth';
|
|
164
|
+
phase: 'required' | 'granted' | 'failed';
|
|
165
|
+
} | {
|
|
166
|
+
type: 'error';
|
|
167
|
+
message: string;
|
|
168
|
+
} | {
|
|
169
|
+
type: 'chat';
|
|
170
|
+
phase: 'message' | 'response-start' | 'response-end';
|
|
171
|
+
chatId?: string;
|
|
172
|
+
} | ({
|
|
173
|
+
type: 'tool';
|
|
174
|
+
} & ToolEvent);
|
|
105
175
|
/**
|
|
106
176
|
* A snapshot of the page as the agent sees it.
|
|
107
177
|
*
|
|
@@ -414,6 +484,15 @@ type WidgetToHost = {
|
|
|
414
484
|
| {
|
|
415
485
|
type: 'widget.navigate';
|
|
416
486
|
href: string;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* A chat-turn lifecycle moment, forwarded by the loader to the host's `onEvent`.
|
|
490
|
+
* Content-free: `phase` + an opaque `chatId`, never message text. Additive.
|
|
491
|
+
*/
|
|
492
|
+
| {
|
|
493
|
+
type: 'widget.chat';
|
|
494
|
+
phase: 'message' | 'response-start' | 'response-end';
|
|
495
|
+
chatId?: string;
|
|
417
496
|
};
|
|
418
497
|
/**
|
|
419
498
|
* Everything on the wire is wrapped.
|
|
@@ -590,6 +669,14 @@ declare class EmbedHost {
|
|
|
590
669
|
* without weakening the origin/source checks above, which stay the only real door.
|
|
591
670
|
*/
|
|
592
671
|
__testHandle(msg: WidgetToHost): void;
|
|
672
|
+
/**
|
|
673
|
+
* The eager stub's own emit-and-swallow for the host's `onEvent` telemetry hook.
|
|
674
|
+
* Deliberately does NOT import the registry's `emitEvent`: pulling the lazy ./context
|
|
675
|
+
* chunk (where the registry lives) into the size-budgeted stub would blow it, so this
|
|
676
|
+
* ~5-line duplication across the bundle boundary is intentional. Host telemetry is
|
|
677
|
+
* host code — a throw here must never break the widget.
|
|
678
|
+
*/
|
|
679
|
+
private emit;
|
|
593
680
|
private handle;
|
|
594
681
|
/**
|
|
595
682
|
* Own a drag for its lifetime.
|
|
@@ -661,4 +748,4 @@ declare class EmbedHost {
|
|
|
661
748
|
*/
|
|
662
749
|
declare function mount(config: LoaderConfig): EmbedHost;
|
|
663
750
|
|
|
664
|
-
export { type ActivityEvent, type ArtifactGrant, CHANNEL, type ContentClass, type DomSnapshot, type ElementRef, EmbedHost, type Envelope, type FocusContext, type HostToWidget, type HostTool, type LoaderConfig, PROTOCOL_VERSION, type PageContext, type PageEntity, type SiteMapEntry, type ToolCall, type WidgetToHost, envelope, isEnvelope, mount, readConfig };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -396,6 +396,21 @@ var EmbedHost = class {
|
|
|
396
396
|
__testHandle(msg) {
|
|
397
397
|
this.handle(msg);
|
|
398
398
|
}
|
|
399
|
+
/**
|
|
400
|
+
* The eager stub's own emit-and-swallow for the host's `onEvent` telemetry hook.
|
|
401
|
+
* Deliberately does NOT import the registry's `emitEvent`: pulling the lazy ./context
|
|
402
|
+
* chunk (where the registry lives) into the size-budgeted stub would blow it, so this
|
|
403
|
+
* ~5-line duplication across the bundle boundary is intentional. Host telemetry is
|
|
404
|
+
* host code — a throw here must never break the widget.
|
|
405
|
+
*/
|
|
406
|
+
emit(e) {
|
|
407
|
+
const cb = globalThis.matterfact?.onEvent;
|
|
408
|
+
if (typeof cb !== "function") return;
|
|
409
|
+
try {
|
|
410
|
+
cb(e);
|
|
411
|
+
} catch {
|
|
412
|
+
}
|
|
413
|
+
}
|
|
399
414
|
handle(msg) {
|
|
400
415
|
switch (msg.type) {
|
|
401
416
|
case "widget.ready":
|
|
@@ -408,8 +423,10 @@ var EmbedHost = class {
|
|
|
408
423
|
this.send({ type: "host.theme", mode: this.themeMode() });
|
|
409
424
|
this.flush();
|
|
410
425
|
if (this.inline) void this.loadContext();
|
|
426
|
+
this.emit({ type: "ready" });
|
|
411
427
|
break;
|
|
412
428
|
case "widget.setOpen":
|
|
429
|
+
this.emit({ type: msg.open ? "open" : "close" });
|
|
413
430
|
if (this.inline) break;
|
|
414
431
|
this.open = msg.open;
|
|
415
432
|
this.place();
|
|
@@ -597,11 +614,16 @@ var EmbedHost = class {
|
|
|
597
614
|
if (this.hostEl) this.hostEl.style.display = "none";
|
|
598
615
|
break;
|
|
599
616
|
case "widget.needsAuth":
|
|
617
|
+
this.emit({ type: "auth", phase: "required" });
|
|
600
618
|
void this.provideAuth();
|
|
601
619
|
break;
|
|
602
620
|
case "widget.navigate":
|
|
621
|
+
this.emit({ type: "navigate", href: msg.href });
|
|
603
622
|
void this.loadContext().then((m) => m.navigateHost(msg.href));
|
|
604
623
|
break;
|
|
624
|
+
case "widget.chat":
|
|
625
|
+
this.emit({ type: "chat", phase: msg.phase, chatId: msg.chatId });
|
|
626
|
+
break;
|
|
605
627
|
}
|
|
606
628
|
}
|
|
607
629
|
/**
|
|
@@ -714,11 +736,13 @@ var EmbedHost = class {
|
|
|
714
736
|
try {
|
|
715
737
|
const token = await provider();
|
|
716
738
|
if (token) this.send({ type: "host.auth", token, expiresAt: 0 });
|
|
739
|
+
this.emit({ type: "auth", phase: token ? "granted" : "failed" });
|
|
717
740
|
} catch {
|
|
741
|
+
this.emit({ type: "auth", phase: "failed" });
|
|
718
742
|
}
|
|
719
743
|
}
|
|
720
744
|
loadContext() {
|
|
721
|
-
this.context ?? (this.context = import('./context-
|
|
745
|
+
this.context ?? (this.context = import('./context-FR7VFENN.js').then((m) => {
|
|
722
746
|
m.start(
|
|
723
747
|
this.send,
|
|
724
748
|
this.config.origin,
|