@matterfact/embed 0.10.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.
Files changed (41) hide show
  1. package/README.md +9 -6
  2. package/dist/{chunk-CFDPCZO3.js → chunk-AANODHBV.js} +11 -2
  3. package/dist/chunk-AANODHBV.js.map +1 -0
  4. package/dist/{chunk-4AE5WINC.js → chunk-CTZEDOH7.js} +12 -3
  5. package/dist/chunk-CTZEDOH7.js.map +1 -0
  6. package/dist/{chunk-DXLHTFB4.js → chunk-JO3GWFMJ.js} +2 -2
  7. package/dist/{chunk-RL6VIGWK.js → chunk-SKJFF7RD.js} +2 -2
  8. package/dist/chunk-Y7I25VHL.js +3 -0
  9. package/dist/chunk-Y7I25VHL.js.map +7 -0
  10. package/dist/{context-SSQ4HUP3.js → context-FR7VFENN.js} +3 -3
  11. package/dist/{context-SSQ4HUP3.js.map → context-FR7VFENN.js.map} +1 -1
  12. package/dist/{context-HOOW63MO.js → context-IK5MECUW.js} +2 -2
  13. package/dist/embed.js +1 -1
  14. package/dist/embed.js.map +3 -3
  15. package/dist/index.cjs +33 -0
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.cts +56 -1
  18. package/dist/index.d.ts +56 -1
  19. package/dist/index.js +25 -1
  20. package/dist/index.js.map +1 -1
  21. package/dist/react.cjs +46 -4
  22. package/dist/react.cjs.map +1 -1
  23. package/dist/react.d.cts +51 -2
  24. package/dist/react.d.ts +51 -2
  25. package/dist/react.js +38 -5
  26. package/dist/react.js.map +1 -1
  27. package/dist/{snapshot-EYRXPLRC.js → snapshot-2V5SDSH2.js} +2 -2
  28. package/dist/{snapshot-CRY2IBX6.js → snapshot-Y5BF2UJR.js} +3 -3
  29. package/dist/{snapshot-CRY2IBX6.js.map → snapshot-Y5BF2UJR.js.map} +1 -1
  30. package/examples/embed-demo/README.md +22 -0
  31. package/examples/embed-demo/src/App.tsx +105 -2
  32. package/examples/embed-demo/src/styles.css +29 -0
  33. package/package.json +1 -1
  34. package/dist/chunk-4AE5WINC.js.map +0 -1
  35. package/dist/chunk-CFDPCZO3.js.map +0 -1
  36. package/dist/chunk-TWMHQF7O.js +0 -3
  37. package/dist/chunk-TWMHQF7O.js.map +0 -7
  38. /package/dist/{chunk-DXLHTFB4.js.map → chunk-JO3GWFMJ.js.map} +0 -0
  39. /package/dist/{chunk-RL6VIGWK.js.map → chunk-SKJFF7RD.js.map} +0 -0
  40. /package/dist/{context-HOOW63MO.js.map → context-IK5MECUW.js.map} +0 -0
  41. /package/dist/{snapshot-EYRXPLRC.js.map → snapshot-2V5SDSH2.js.map} +0 -0
package/dist/index.d.cts CHANGED
@@ -134,6 +134,44 @@ interface ToolEvent {
134
134
  error?: string;
135
135
  ms?: number;
136
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);
137
175
  /**
138
176
  * A snapshot of the page as the agent sees it.
139
177
  *
@@ -446,6 +484,15 @@ type WidgetToHost = {
446
484
  | {
447
485
  type: 'widget.navigate';
448
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;
449
496
  };
450
497
  /**
451
498
  * Everything on the wire is wrapped.
@@ -622,6 +669,14 @@ declare class EmbedHost {
622
669
  * without weakening the origin/source checks above, which stay the only real door.
623
670
  */
624
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;
625
680
  private handle;
626
681
  /**
627
682
  * Own a drag for its lifetime.
@@ -693,4 +748,4 @@ declare class EmbedHost {
693
748
  */
694
749
  declare function mount(config: LoaderConfig): EmbedHost;
695
750
 
696
- 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, PROTOCOL_VERSION, type PageContext, type PageEntity, type SiteMapEntry, type ToolCall, type ToolEvent, 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
@@ -134,6 +134,44 @@ interface ToolEvent {
134
134
  error?: string;
135
135
  ms?: number;
136
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);
137
175
  /**
138
176
  * A snapshot of the page as the agent sees it.
139
177
  *
@@ -446,6 +484,15 @@ type WidgetToHost = {
446
484
  | {
447
485
  type: 'widget.navigate';
448
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;
449
496
  };
450
497
  /**
451
498
  * Everything on the wire is wrapped.
@@ -622,6 +669,14 @@ declare class EmbedHost {
622
669
  * without weakening the origin/source checks above, which stay the only real door.
623
670
  */
624
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;
625
680
  private handle;
626
681
  /**
627
682
  * Own a drag for its lifetime.
@@ -693,4 +748,4 @@ declare class EmbedHost {
693
748
  */
694
749
  declare function mount(config: LoaderConfig): EmbedHost;
695
750
 
696
- 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, PROTOCOL_VERSION, type PageContext, type PageEntity, type SiteMapEntry, type ToolCall, type ToolEvent, 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-SSQ4HUP3.js').then((m) => {
745
+ this.context ?? (this.context = import('./context-FR7VFENN.js').then((m) => {
722
746
  m.start(
723
747
  this.send,
724
748
  this.config.origin,