@stigmer/embed 0.1.0-dev.20261017020314.g644422724c27
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/LICENSE +194 -0
- package/define.d.ts +8 -0
- package/define.d.ts.map +1 -0
- package/define.js +9 -0
- package/define.js.map +1 -0
- package/element.d.ts +50 -0
- package/element.d.ts.map +1 -0
- package/element.js +172 -0
- package/element.js.map +1 -0
- package/embed.global.js +1 -0
- package/frame.d.ts +45 -0
- package/frame.d.ts.map +1 -0
- package/frame.js +118 -0
- package/frame.js.map +1 -0
- package/global.d.ts +18 -0
- package/global.d.ts.map +1 -0
- package/global.js +23 -0
- package/global.js.map +1 -0
- package/host.d.ts +26 -0
- package/host.d.ts.map +1 -0
- package/host.js +49 -0
- package/host.js.map +1 -0
- package/index.d.ts +15 -0
- package/index.d.ts.map +1 -0
- package/index.js +15 -0
- package/index.js.map +1 -0
- package/jsx.d.ts +89 -0
- package/jsx.d.ts.map +1 -0
- package/jsx.js +24 -0
- package/jsx.js.map +1 -0
- package/package.json +45 -0
- package/protocol.d.ts +48 -0
- package/protocol.d.ts.map +1 -0
- package/protocol.js +61 -0
- package/protocol.js.map +1 -0
- package/src/define.ts +10 -0
- package/src/element.ts +202 -0
- package/src/frame.ts +129 -0
- package/src/global.ts +30 -0
- package/src/host.ts +67 -0
- package/src/index.ts +39 -0
- package/src/jsx.ts +99 -0
- package/src/protocol.ts +76 -0
package/global.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IIFE entry for the one-line `<script>` loader (`dist/embed.global.js`,
|
|
3
|
+
* served as `embed.js` from the Stigmer app origin).
|
|
4
|
+
*
|
|
5
|
+
* Derives the app origin from its own script URL — the loader is served from
|
|
6
|
+
* the same origin as the hosted chat page, so the snippet needs zero
|
|
7
|
+
* configuration and self-hosted OSS installs work unchanged. If the loader is
|
|
8
|
+
* ever served from a dedicated CDN host instead, embedders set the
|
|
9
|
+
* `app-origin` attribute on `<stigmer-agent>` (or the CDN build bakes in
|
|
10
|
+
* {@link setDefaultAppOrigin}).
|
|
11
|
+
*
|
|
12
|
+
* Must stay a classic script (not `type="module"`): `document.currentScript`
|
|
13
|
+
* is `null` inside module scripts, and it is the only zero-config way to know
|
|
14
|
+
* where the loader came from.
|
|
15
|
+
*/
|
|
16
|
+
import { StigmerAgentElement, defineStigmerAgent, setDefaultAppOrigin } from "./element.js";
|
|
17
|
+
export { StigmerAgentElement, defineStigmerAgent, setDefaultAppOrigin };
|
|
18
|
+
//# sourceMappingURL=global.d.ts.map
|
package/global.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global.d.ts","sourceRoot":"","sources":["src/global.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,cAAc,CAAC;AAStB,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,CAAC"}
|
package/global.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IIFE entry for the one-line `<script>` loader (`dist/embed.global.js`,
|
|
3
|
+
* served as `embed.js` from the Stigmer app origin).
|
|
4
|
+
*
|
|
5
|
+
* Derives the app origin from its own script URL — the loader is served from
|
|
6
|
+
* the same origin as the hosted chat page, so the snippet needs zero
|
|
7
|
+
* configuration and self-hosted OSS installs work unchanged. If the loader is
|
|
8
|
+
* ever served from a dedicated CDN host instead, embedders set the
|
|
9
|
+
* `app-origin` attribute on `<stigmer-agent>` (or the CDN build bakes in
|
|
10
|
+
* {@link setDefaultAppOrigin}).
|
|
11
|
+
*
|
|
12
|
+
* Must stay a classic script (not `type="module"`): `document.currentScript`
|
|
13
|
+
* is `null` inside module scripts, and it is the only zero-config way to know
|
|
14
|
+
* where the loader came from.
|
|
15
|
+
*/
|
|
16
|
+
import { StigmerAgentElement, defineStigmerAgent, setDefaultAppOrigin, } from "./element.js";
|
|
17
|
+
const script = document.currentScript;
|
|
18
|
+
if (script instanceof HTMLScriptElement && script.src) {
|
|
19
|
+
setDefaultAppOrigin(new URL(script.src).origin);
|
|
20
|
+
}
|
|
21
|
+
defineStigmerAgent();
|
|
22
|
+
export { StigmerAgentElement, defineStigmerAgent, setDefaultAppOrigin };
|
|
23
|
+
//# sourceMappingURL=global.js.map
|
package/global.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global.js","sourceRoot":"","sources":["src/global.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,cAAc,CAAC;AAEtB,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC;AACtC,IAAI,MAAM,YAAY,iBAAiB,IAAI,MAAM,CAAC,GAAG,EAAE,CAAC;IACtD,mBAAmB,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC;AAClD,CAAC;AAED,kBAAkB,EAAE,CAAC;AAErB,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,CAAC"}
|
package/host.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host-side embed controller — the loader half of the protocol, shared by the
|
|
3
|
+
* `<stigmer-agent>` element (and any future framework adapters) so the
|
|
4
|
+
* message-pinning rules live in exactly one place.
|
|
5
|
+
*/
|
|
6
|
+
export interface EmbedHostHandlers {
|
|
7
|
+
/** The widget rendered inside the iframe and may be shown. */
|
|
8
|
+
readonly onReady?: () => void;
|
|
9
|
+
/** The platform refused this embed context; the caller should hide the widget. */
|
|
10
|
+
readonly onRefused?: () => void;
|
|
11
|
+
}
|
|
12
|
+
export interface EmbedHost {
|
|
13
|
+
/** Detaches listeners. Call when the iframe is removed. */
|
|
14
|
+
destroy(): void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Wires the host side of the embed bridge onto an iframe.
|
|
18
|
+
*
|
|
19
|
+
* Security posture: every inbound message is pinned to both the iframe's
|
|
20
|
+
* `contentWindow` (source) and the expected frame origin, and `init` is only
|
|
21
|
+
* ever posted to that origin. `init` is sent once the iframe loads and again
|
|
22
|
+
* on every `hello` — the frame's script may attach its listener after the
|
|
23
|
+
* load-time send, so the handshake must be answerable at any time.
|
|
24
|
+
*/
|
|
25
|
+
export declare function createEmbedHost(iframe: HTMLIFrameElement, frameOrigin: string, handlers?: EmbedHostHandlers): EmbedHost;
|
|
26
|
+
//# sourceMappingURL=host.d.ts.map
|
package/host.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["src/host.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,MAAM,WAAW,iBAAiB;IAChC,8DAA8D;IAC9D,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IAC9B,kFAAkF;IAClF,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;CACjC;AAED,MAAM,WAAW,SAAS;IACxB,2DAA2D;IAC3D,OAAO,IAAI,IAAI,CAAC;CACjB;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,iBAAiB,EACzB,WAAW,EAAE,MAAM,EACnB,QAAQ,GAAE,iBAAsB,GAC/B,SAAS,CAiCX"}
|
package/host.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host-side embed controller — the loader half of the protocol, shared by the
|
|
3
|
+
* `<stigmer-agent>` element (and any future framework adapters) so the
|
|
4
|
+
* message-pinning rules live in exactly one place.
|
|
5
|
+
*/
|
|
6
|
+
import { parseFrameMessage, toWire } from "./protocol.js";
|
|
7
|
+
/**
|
|
8
|
+
* Wires the host side of the embed bridge onto an iframe.
|
|
9
|
+
*
|
|
10
|
+
* Security posture: every inbound message is pinned to both the iframe's
|
|
11
|
+
* `contentWindow` (source) and the expected frame origin, and `init` is only
|
|
12
|
+
* ever posted to that origin. `init` is sent once the iframe loads and again
|
|
13
|
+
* on every `hello` — the frame's script may attach its listener after the
|
|
14
|
+
* load-time send, so the handshake must be answerable at any time.
|
|
15
|
+
*/
|
|
16
|
+
export function createEmbedHost(iframe, frameOrigin, handlers = {}) {
|
|
17
|
+
const sendInit = () => {
|
|
18
|
+
iframe.contentWindow?.postMessage(toWire({ type: "init" }), frameOrigin);
|
|
19
|
+
};
|
|
20
|
+
const onMessage = (event) => {
|
|
21
|
+
if (event.source !== iframe.contentWindow)
|
|
22
|
+
return;
|
|
23
|
+
if (event.origin !== frameOrigin)
|
|
24
|
+
return;
|
|
25
|
+
const message = parseFrameMessage(event.data);
|
|
26
|
+
if (!message)
|
|
27
|
+
return;
|
|
28
|
+
switch (message.type) {
|
|
29
|
+
case "hello":
|
|
30
|
+
sendInit();
|
|
31
|
+
break;
|
|
32
|
+
case "ready":
|
|
33
|
+
handlers.onReady?.();
|
|
34
|
+
break;
|
|
35
|
+
case "refused":
|
|
36
|
+
handlers.onRefused?.();
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
window.addEventListener("message", onMessage);
|
|
41
|
+
iframe.addEventListener("load", sendInit);
|
|
42
|
+
return {
|
|
43
|
+
destroy() {
|
|
44
|
+
window.removeEventListener("message", onMessage);
|
|
45
|
+
iframe.removeEventListener("load", sendInit);
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=host.js.map
|
package/host.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.js","sourceRoot":"","sources":["src/host.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAc1D;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAC7B,MAAyB,EACzB,WAAmB,EACnB,WAA8B,EAAE;IAEhC,MAAM,QAAQ,GAAG,GAAS,EAAE;QAC1B,MAAM,CAAC,aAAa,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,WAAW,CAAC,CAAC;IAC3E,CAAC,CAAC;IAEF,MAAM,SAAS,GAAG,CAAC,KAAmB,EAAQ,EAAE;QAC9C,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM,CAAC,aAAa;YAAE,OAAO;QAClD,IAAI,KAAK,CAAC,MAAM,KAAK,WAAW;YAAE,OAAO;QACzC,MAAM,OAAO,GAAG,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC9C,IAAI,CAAC,OAAO;YAAE,OAAO;QAErB,QAAQ,OAAO,CAAC,IAAI,EAAE,CAAC;YACrB,KAAK,OAAO;gBACV,QAAQ,EAAE,CAAC;gBACX,MAAM;YACR,KAAK,OAAO;gBACV,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC;gBACrB,MAAM;YACR,KAAK,SAAS;gBACZ,QAAQ,CAAC,SAAS,EAAE,EAAE,CAAC;gBACvB,MAAM;QACV,CAAC;IACH,CAAC,CAAC;IAEF,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAC9C,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAE1C,OAAO;QACL,OAAO;YACL,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;YACjD,MAAM,CAAC,mBAAmB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAC/C,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @stigmer/embed — the one-line script embed for a Stigmer agent's chat link.
|
|
3
|
+
*
|
|
4
|
+
* Three consumption forms:
|
|
5
|
+
* - `<script src=".../embed.js">` — the IIFE loader (`./loader` export),
|
|
6
|
+
* auto-registers `<stigmer-agent>` and derives the app origin from its URL.
|
|
7
|
+
* - `import "@stigmer/embed/define"` — bundler-side auto-registration.
|
|
8
|
+
* - `import { ... } from "@stigmer/embed"` — this side-effect-free API, also
|
|
9
|
+
* used by the hosted chat page itself for the frame half of the protocol.
|
|
10
|
+
*/
|
|
11
|
+
export { EMBED_SOURCE, EMBED_PROTOCOL_VERSION, parseFrameMessage, parseHostMessage, toWire, type FrameToHostMessage, type HostToFrameMessage, } from "./protocol.js";
|
|
12
|
+
export { OPAQUE_ORIGIN, isEmbedded, notifyParent, resolveParentOrigin, } from "./frame.js";
|
|
13
|
+
export { createEmbedHost, type EmbedHost, type EmbedHostHandlers, } from "./host.js";
|
|
14
|
+
export { StigmerAgentElement, defineStigmerAgent, setDefaultAppOrigin, } from "./element.js";
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
package/index.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EACL,YAAY,EACZ,sBAAsB,EACtB,iBAAiB,EACjB,gBAAgB,EAChB,MAAM,EACN,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,GACxB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,aAAa,EACb,UAAU,EACV,YAAY,EACZ,mBAAmB,GACpB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,eAAe,EACf,KAAK,SAAS,EACd,KAAK,iBAAiB,GACvB,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,cAAc,CAAC"}
|
package/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @stigmer/embed — the one-line script embed for a Stigmer agent's chat link.
|
|
3
|
+
*
|
|
4
|
+
* Three consumption forms:
|
|
5
|
+
* - `<script src=".../embed.js">` — the IIFE loader (`./loader` export),
|
|
6
|
+
* auto-registers `<stigmer-agent>` and derives the app origin from its URL.
|
|
7
|
+
* - `import "@stigmer/embed/define"` — bundler-side auto-registration.
|
|
8
|
+
* - `import { ... } from "@stigmer/embed"` — this side-effect-free API, also
|
|
9
|
+
* used by the hosted chat page itself for the frame half of the protocol.
|
|
10
|
+
*/
|
|
11
|
+
export { EMBED_SOURCE, EMBED_PROTOCOL_VERSION, parseFrameMessage, parseHostMessage, toWire, } from "./protocol.js";
|
|
12
|
+
export { OPAQUE_ORIGIN, isEmbedded, notifyParent, resolveParentOrigin, } from "./frame.js";
|
|
13
|
+
export { createEmbedHost, } from "./host.js";
|
|
14
|
+
export { StigmerAgentElement, defineStigmerAgent, setDefaultAppOrigin, } from "./element.js";
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EACL,YAAY,EACZ,sBAAsB,EACtB,iBAAiB,EACjB,gBAAgB,EAChB,MAAM,GAGP,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,aAAa,EACb,UAAU,EACV,YAAY,EACZ,mBAAmB,GACpB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,eAAe,GAGhB,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,cAAc,CAAC"}
|
package/jsx.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opt-in JSX typing for `<stigmer-agent>` — import once and the element
|
|
3
|
+
* typechecks in any React 19 TSX file:
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* import "@stigmer/embed/define"; // registers the element (runtime)
|
|
7
|
+
* import "@stigmer/embed/jsx"; // teaches TypeScript about it (types only)
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* This module is deliberately type-only: it emits an inert `dist/jsx.js` (so
|
|
11
|
+
* the subpath resolves at runtime) and carries no runtime dependency on React
|
|
12
|
+
* — the package's framework-free charter is untouched. It augments the JSX
|
|
13
|
+
* namespace exported by the `react` module itself, which `react/jsx-runtime`
|
|
14
|
+
* re-exports, so one augmentation covers the automatic runtime, the classic
|
|
15
|
+
* runtime, and direct `React.JSX` references. React 19's types define no
|
|
16
|
+
* global `JSX` namespace, so a `declare global` augmentation would silently
|
|
17
|
+
* do nothing — do not "simplify" this back to one.
|
|
18
|
+
*
|
|
19
|
+
* Importing this subpath from a project without `@types/react` fails with
|
|
20
|
+
* TypeScript's "Invalid module name in augmentation" error — acceptable and
|
|
21
|
+
* self-explanatory for an explicitly-React entry point.
|
|
22
|
+
*/
|
|
23
|
+
import type { ClassAttributes, HTMLAttributes } from "react";
|
|
24
|
+
import type { StigmerAgentElement } from "./element.js";
|
|
25
|
+
/**
|
|
26
|
+
* JSX attributes for `<stigmer-agent>` — one prop per observed attribute
|
|
27
|
+
* (see `OBSERVED_ATTRIBUTES` in `element.ts`; keep the two in sync).
|
|
28
|
+
*
|
|
29
|
+
* React sets these as HTML attributes (the element defines no matching
|
|
30
|
+
* properties), and the element rebuilds its iframe — destroying any
|
|
31
|
+
* in-progress conversation — whenever ANY of them changes. Keep every value
|
|
32
|
+
* referentially stable for the life of the element; resolve dynamic values
|
|
33
|
+
* (like a theme) once, before mounting.
|
|
34
|
+
*
|
|
35
|
+
* Every attribute is optional, including the two the element requires at
|
|
36
|
+
* runtime (`channel`, which it enforces with a console error). This is
|
|
37
|
+
* NOT laziness: libraries like react-markdown build mapped types over
|
|
38
|
+
* `JSX.IntrinsicElements`, and an intrinsic with required props breaks their
|
|
39
|
+
* assignability for every project that imports this augmentation. All
|
|
40
|
+
* standard intrinsics are typed all-optional for the same reason.
|
|
41
|
+
*/
|
|
42
|
+
interface StigmerAgentAttributes extends ClassAttributes<StigmerAgentElement>, Omit<HTMLAttributes<StigmerAgentElement>, "children"> {
|
|
43
|
+
/**
|
|
44
|
+
* The web channel's id (`ash_…`), the one path segment of the hosted
|
|
45
|
+
* chat link. Required at runtime (see above for why the type cannot
|
|
46
|
+
* enforce it); `share` is accepted in its place.
|
|
47
|
+
*/
|
|
48
|
+
channel?: string;
|
|
49
|
+
/**
|
|
50
|
+
* The former name of `channel`.
|
|
51
|
+
*
|
|
52
|
+
* @deprecated use `channel`; pages that carry `share` keep working.
|
|
53
|
+
*/
|
|
54
|
+
share?: string;
|
|
55
|
+
/** Link token for a locked chat link; forwarded as the `?k=` parameter. */
|
|
56
|
+
token?: string;
|
|
57
|
+
/**
|
|
58
|
+
* Color mode, resolved once at mount. `auto` follows the OS
|
|
59
|
+
* `prefers-color-scheme`; omit it to let the hosted page pick its default.
|
|
60
|
+
*/
|
|
61
|
+
theme?: "light" | "dark" | "auto";
|
|
62
|
+
/** Host element CSS width; bare digits are treated as px. Default 400px. */
|
|
63
|
+
width?: string | number;
|
|
64
|
+
/** Host element CSS height; bare digits are treated as px. Default 600px. */
|
|
65
|
+
height?: string | number;
|
|
66
|
+
/**
|
|
67
|
+
* Origin of the Stigmer app hosting the chat page (e.g.
|
|
68
|
+
* `https://app.stigmer.ai`). Required for bundler consumers — there is no
|
|
69
|
+
* loader `<script src>` to derive it from.
|
|
70
|
+
*/
|
|
71
|
+
"app-origin"?: string;
|
|
72
|
+
/**
|
|
73
|
+
* `children` is omitted from the inherited attributes: the element owns its
|
|
74
|
+
* subtree (it injects the chat iframe), so React-rendered children would
|
|
75
|
+
* conflict with it. Listen for the `stigmer:ready` / `stigmer:refused`
|
|
76
|
+
* CustomEvents via a ref — colon-named events are not expressible as JSX
|
|
77
|
+
* props.
|
|
78
|
+
*/
|
|
79
|
+
children?: never;
|
|
80
|
+
}
|
|
81
|
+
declare module "react" {
|
|
82
|
+
namespace JSX {
|
|
83
|
+
interface IntrinsicElements {
|
|
84
|
+
"stigmer-agent": StigmerAgentAttributes;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
export {};
|
|
89
|
+
//# sourceMappingURL=jsx.d.ts.map
|
package/jsx.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsx.d.ts","sourceRoot":"","sources":["src/jsx.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAG7D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAExD;;;;;;;;;;;;;;;;GAgBG;AAGH,UAAU,sBACR,SAAQ,eAAe,CAAC,mBAAmB,CAAC,EAC1C,IAAI,CAAC,cAAc,CAAC,mBAAmB,CAAC,EAAE,UAAU,CAAC;IACvD;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,2EAA2E;IAC3E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;IAClC,4EAA4E;IAC5E,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,6EAA6E;IAC7E,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC;CAClB;AAED,OAAO,QAAQ,OAAO,CAAC;IACrB,UAAU,GAAG,CAAC;QACZ,UAAU,iBAAiB;YACzB,eAAe,EAAE,sBAAsB,CAAC;SACzC;KACF;CACF;AAGD,OAAO,EAAE,CAAC"}
|
package/jsx.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opt-in JSX typing for `<stigmer-agent>` — import once and the element
|
|
3
|
+
* typechecks in any React 19 TSX file:
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* import "@stigmer/embed/define"; // registers the element (runtime)
|
|
7
|
+
* import "@stigmer/embed/jsx"; // teaches TypeScript about it (types only)
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* This module is deliberately type-only: it emits an inert `dist/jsx.js` (so
|
|
11
|
+
* the subpath resolves at runtime) and carries no runtime dependency on React
|
|
12
|
+
* — the package's framework-free charter is untouched. It augments the JSX
|
|
13
|
+
* namespace exported by the `react` module itself, which `react/jsx-runtime`
|
|
14
|
+
* re-exports, so one augmentation covers the automatic runtime, the classic
|
|
15
|
+
* runtime, and direct `React.JSX` references. React 19's types define no
|
|
16
|
+
* global `JSX` namespace, so a `declare global` augmentation would silently
|
|
17
|
+
* do nothing — do not "simplify" this back to one.
|
|
18
|
+
*
|
|
19
|
+
* Importing this subpath from a project without `@types/react` fails with
|
|
20
|
+
* TypeScript's "Invalid module name in augmentation" error — acceptable and
|
|
21
|
+
* self-explanatory for an explicitly-React entry point.
|
|
22
|
+
*/
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=jsx.js.map
|
package/jsx.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsx.js","sourceRoot":"","sources":["src/jsx.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG"}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stigmer/embed",
|
|
3
|
+
"version": "0.1.0-dev.20261017020314.g644422724c27",
|
|
4
|
+
"description": "One-line script embed for a Stigmer agent's chat link — a framework-free <stigmer-agent> web component that bootstraps the hosted chat page in an iframe",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": [
|
|
8
|
+
"./src/define.ts",
|
|
9
|
+
"./dist/define.js",
|
|
10
|
+
"./dist/embed.global.js"
|
|
11
|
+
],
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/stigmer/stigmer.git",
|
|
15
|
+
"directory": "sdk/embed"
|
|
16
|
+
},
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=18"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"stigmer",
|
|
22
|
+
"embed",
|
|
23
|
+
"iframe",
|
|
24
|
+
"web-component",
|
|
25
|
+
"chat-widget",
|
|
26
|
+
"ai-agents"
|
|
27
|
+
],
|
|
28
|
+
"main": "./index.js",
|
|
29
|
+
"types": "./index.d.ts",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./index.d.ts",
|
|
33
|
+
"import": "./index.js"
|
|
34
|
+
},
|
|
35
|
+
"./define": {
|
|
36
|
+
"types": "./define.d.ts",
|
|
37
|
+
"import": "./define.js"
|
|
38
|
+
},
|
|
39
|
+
"./jsx": {
|
|
40
|
+
"types": "./jsx.d.ts",
|
|
41
|
+
"import": "./jsx.js"
|
|
42
|
+
},
|
|
43
|
+
"./loader": "./embed.global.js"
|
|
44
|
+
}
|
|
45
|
+
}
|
package/protocol.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The postMessage wire contract between the embed loader (host page) and the
|
|
3
|
+
* hosted chat page (inside the iframe).
|
|
4
|
+
*
|
|
5
|
+
* This module is the single source of truth for the protocol: the loader
|
|
6
|
+
* (`element.ts` / `host.ts`) and the chat page (`frame.ts`, consumed by
|
|
7
|
+
* `client-apps/web`) both import these constants and parsers — nothing is
|
|
8
|
+
* redeclared elsewhere. Every message is stamped with {@link EMBED_SOURCE}
|
|
9
|
+
* and {@link EMBED_PROTOCOL_VERSION}; receivers must ignore anything that
|
|
10
|
+
* does not match, because the browser `message` channel is shared with the
|
|
11
|
+
* whole page.
|
|
12
|
+
*
|
|
13
|
+
* v1 messages:
|
|
14
|
+
* - host -> frame `init` — carries no payload; its value is the browser-set
|
|
15
|
+
* `event.origin`, which tells the framed page who embeds it (unforgeable).
|
|
16
|
+
* - frame -> host `hello` — asks the host to (re)send `init`, for the case
|
|
17
|
+
* where the frame's listener attaches after the host's load-time `init`.
|
|
18
|
+
* - frame -> host `ready` — the widget rendered and may be shown.
|
|
19
|
+
* - frame -> host `refused` — the platform refused this embed context (origin
|
|
20
|
+
* not allowed); the loader hides the element gracefully.
|
|
21
|
+
*/
|
|
22
|
+
export declare const EMBED_SOURCE = "stigmer-embed";
|
|
23
|
+
export declare const EMBED_PROTOCOL_VERSION = 1;
|
|
24
|
+
/** Messages sent by the hosted chat page (frame) to the embedding page (host). */
|
|
25
|
+
export type FrameToHostMessage = {
|
|
26
|
+
readonly type: "hello";
|
|
27
|
+
} | {
|
|
28
|
+
readonly type: "ready";
|
|
29
|
+
} | {
|
|
30
|
+
readonly type: "refused";
|
|
31
|
+
};
|
|
32
|
+
/** Messages sent by the embedding page (host) to the hosted chat page (frame). */
|
|
33
|
+
export type HostToFrameMessage = {
|
|
34
|
+
readonly type: "init";
|
|
35
|
+
};
|
|
36
|
+
interface Envelope {
|
|
37
|
+
readonly source: typeof EMBED_SOURCE;
|
|
38
|
+
readonly v: typeof EMBED_PROTOCOL_VERSION;
|
|
39
|
+
readonly type: string;
|
|
40
|
+
}
|
|
41
|
+
/** Wraps a message in the versioned envelope for `postMessage`. */
|
|
42
|
+
export declare function toWire(message: FrameToHostMessage | HostToFrameMessage): Envelope;
|
|
43
|
+
/** Parses an inbound message on the host side; `null` for foreign messages. */
|
|
44
|
+
export declare function parseFrameMessage(data: unknown): FrameToHostMessage | null;
|
|
45
|
+
/** Parses an inbound message on the frame side; `null` for foreign messages. */
|
|
46
|
+
export declare function parseHostMessage(data: unknown): HostToFrameMessage | null;
|
|
47
|
+
export {};
|
|
48
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,eAAO,MAAM,YAAY,kBAAkB,CAAC;AAC5C,eAAO,MAAM,sBAAsB,IAAI,CAAC;AAExC,kFAAkF;AAClF,MAAM,MAAM,kBAAkB,GAC1B;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAC1B;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAC1B;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC;AAEjC,kFAAkF;AAClF,MAAM,MAAM,kBAAkB,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3D,UAAU,QAAQ;IAChB,QAAQ,CAAC,MAAM,EAAE,OAAO,YAAY,CAAC;IACrC,QAAQ,CAAC,CAAC,EAAE,OAAO,sBAAsB,CAAC;IAC1C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,mEAAmE;AACnE,wBAAgB,MAAM,CACpB,OAAO,EAAE,kBAAkB,GAAG,kBAAkB,GAC/C,QAAQ,CAEV;AAWD,+EAA+E;AAC/E,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,OAAO,GAAG,kBAAkB,GAAG,IAAI,CAW1E;AAED,gFAAgF;AAChF,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,kBAAkB,GAAG,IAAI,CAIzE"}
|
package/protocol.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The postMessage wire contract between the embed loader (host page) and the
|
|
3
|
+
* hosted chat page (inside the iframe).
|
|
4
|
+
*
|
|
5
|
+
* This module is the single source of truth for the protocol: the loader
|
|
6
|
+
* (`element.ts` / `host.ts`) and the chat page (`frame.ts`, consumed by
|
|
7
|
+
* `client-apps/web`) both import these constants and parsers — nothing is
|
|
8
|
+
* redeclared elsewhere. Every message is stamped with {@link EMBED_SOURCE}
|
|
9
|
+
* and {@link EMBED_PROTOCOL_VERSION}; receivers must ignore anything that
|
|
10
|
+
* does not match, because the browser `message` channel is shared with the
|
|
11
|
+
* whole page.
|
|
12
|
+
*
|
|
13
|
+
* v1 messages:
|
|
14
|
+
* - host -> frame `init` — carries no payload; its value is the browser-set
|
|
15
|
+
* `event.origin`, which tells the framed page who embeds it (unforgeable).
|
|
16
|
+
* - frame -> host `hello` — asks the host to (re)send `init`, for the case
|
|
17
|
+
* where the frame's listener attaches after the host's load-time `init`.
|
|
18
|
+
* - frame -> host `ready` — the widget rendered and may be shown.
|
|
19
|
+
* - frame -> host `refused` — the platform refused this embed context (origin
|
|
20
|
+
* not allowed); the loader hides the element gracefully.
|
|
21
|
+
*/
|
|
22
|
+
export const EMBED_SOURCE = "stigmer-embed";
|
|
23
|
+
export const EMBED_PROTOCOL_VERSION = 1;
|
|
24
|
+
/** Wraps a message in the versioned envelope for `postMessage`. */
|
|
25
|
+
export function toWire(message) {
|
|
26
|
+
return { source: EMBED_SOURCE, v: EMBED_PROTOCOL_VERSION, ...message };
|
|
27
|
+
}
|
|
28
|
+
function parseEnvelope(data) {
|
|
29
|
+
if (typeof data !== "object" || data === null)
|
|
30
|
+
return null;
|
|
31
|
+
const candidate = data;
|
|
32
|
+
if (candidate.source !== EMBED_SOURCE)
|
|
33
|
+
return null;
|
|
34
|
+
if (candidate.v !== EMBED_PROTOCOL_VERSION)
|
|
35
|
+
return null;
|
|
36
|
+
if (typeof candidate.type !== "string")
|
|
37
|
+
return null;
|
|
38
|
+
return candidate;
|
|
39
|
+
}
|
|
40
|
+
/** Parses an inbound message on the host side; `null` for foreign messages. */
|
|
41
|
+
export function parseFrameMessage(data) {
|
|
42
|
+
const envelope = parseEnvelope(data);
|
|
43
|
+
if (!envelope)
|
|
44
|
+
return null;
|
|
45
|
+
switch (envelope.type) {
|
|
46
|
+
case "hello":
|
|
47
|
+
case "ready":
|
|
48
|
+
case "refused":
|
|
49
|
+
return { type: envelope.type };
|
|
50
|
+
default:
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** Parses an inbound message on the frame side; `null` for foreign messages. */
|
|
55
|
+
export function parseHostMessage(data) {
|
|
56
|
+
const envelope = parseEnvelope(data);
|
|
57
|
+
if (!envelope)
|
|
58
|
+
return null;
|
|
59
|
+
return envelope.type === "init" ? { type: "init" } : null;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=protocol.js.map
|
package/protocol.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG,eAAe,CAAC;AAC5C,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAiBxC,mEAAmE;AACnE,MAAM,UAAU,MAAM,CACpB,OAAgD;IAEhD,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,EAAE,sBAAsB,EAAE,GAAG,OAAO,EAAE,CAAC;AACzE,CAAC;AAED,SAAS,aAAa,CAAC,IAAa;IAClC,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAC3D,MAAM,SAAS,GAAG,IAA+B,CAAC;IAClD,IAAI,SAAS,CAAC,MAAM,KAAK,YAAY;QAAE,OAAO,IAAI,CAAC;IACnD,IAAI,SAAS,CAAC,CAAC,KAAK,sBAAsB;QAAE,OAAO,IAAI,CAAC;IACxD,IAAI,OAAO,SAAS,CAAC,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACpD,OAAO,SAAgC,CAAC;AAC1C,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,iBAAiB,CAAC,IAAa;IAC7C,MAAM,QAAQ,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IACrC,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC3B,QAAQ,QAAQ,CAAC,IAAI,EAAE,CAAC;QACtB,KAAK,OAAO,CAAC;QACb,KAAK,OAAO,CAAC;QACb,KAAK,SAAS;YACZ,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;QACjC;YACE,OAAO,IAAI,CAAC;IAChB,CAAC;AACH,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,gBAAgB,CAAC,IAAa;IAC5C,MAAM,QAAQ,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IACrC,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC3B,OAAO,QAAQ,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAC5D,CAAC"}
|
package/src/define.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Side-effect entry for bundler consumers: `import "@stigmer/embed/define"`
|
|
3
|
+
* registers `<stigmer-agent>` on load. Elements still need an app origin —
|
|
4
|
+
* via the `app-origin` attribute or {@link setDefaultAppOrigin} — because a
|
|
5
|
+
* bundled import has no script URL to derive it from.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { defineStigmerAgent } from "./element.js";
|
|
9
|
+
|
|
10
|
+
defineStigmerAgent();
|