@stigmer/embed 3.3.0 → 3.4.1
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/element.d.ts +12 -1
- package/element.d.ts.map +1 -1
- package/element.js +12 -1
- package/element.js.map +1 -1
- package/embed.global.js +1 -1
- package/jsx.d.ts +87 -0
- package/jsx.d.ts.map +1 -0
- package/jsx.js +24 -0
- package/jsx.js.map +1 -0
- package/package.json +5 -1
- package/src/__tests__/ssr.test.ts +24 -0
- package/src/element.ts +14 -1
- package/src/jsx.ts +97 -0
package/element.d.ts
CHANGED
|
@@ -15,7 +15,17 @@
|
|
|
15
15
|
*/
|
|
16
16
|
/** Sets the fallback origin used when an element has no `app-origin` attribute. */
|
|
17
17
|
export declare function setDefaultAppOrigin(origin: string): void;
|
|
18
|
-
|
|
18
|
+
/**
|
|
19
|
+
* SSR shim: `extends HTMLElement` is evaluated when the MODULE loads, not
|
|
20
|
+
* when the class is registered — so on a server (Next.js prerenders "use
|
|
21
|
+
* client" components too) a bare `extends HTMLElement` throws
|
|
22
|
+
* `ReferenceError: HTMLElement is not defined` on import, before the
|
|
23
|
+
* `customElements` guard in {@link defineStigmerAgent} can help. Extending a
|
|
24
|
+
* dummy base keeps the module importable everywhere; nothing constructs the
|
|
25
|
+
* element server-side, so the dummy is never observable.
|
|
26
|
+
*/
|
|
27
|
+
declare const BaseElement: typeof HTMLElement;
|
|
28
|
+
export declare class StigmerAgentElement extends BaseElement {
|
|
19
29
|
static get observedAttributes(): readonly string[];
|
|
20
30
|
private iframe;
|
|
21
31
|
private host;
|
|
@@ -27,4 +37,5 @@ export declare class StigmerAgentElement extends HTMLElement {
|
|
|
27
37
|
}
|
|
28
38
|
/** Registers `<stigmer-agent>`; safe to call more than once. */
|
|
29
39
|
export declare function defineStigmerAgent(): void;
|
|
40
|
+
export {};
|
|
30
41
|
//# sourceMappingURL=element.d.ts.map
|
package/element.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element.d.ts","sourceRoot":"","sources":["../src/element.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AA0BH,mFAAmF;AACnF,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAExD;AAED,qBAAa,mBAAoB,SAAQ,WAAW;IAClD,MAAM,KAAK,kBAAkB,IAAI,SAAS,MAAM,EAAE,CAEjD;IAED,OAAO,CAAC,MAAM,CAAkC;IAChD,OAAO,CAAC,IAAI,CAA0B;IAEtC,iBAAiB,IAAI,IAAI;IAIzB,oBAAoB,IAAI,IAAI;IAI5B,wBAAwB,IAAI,IAAI;IAQhC,OAAO,CAAC,MAAM;IAkDd,OAAO,CAAC,MAAM;CAMf;AAgDD,gEAAgE;AAChE,wBAAgB,kBAAkB,IAAI,IAAI,CAKzC"}
|
|
1
|
+
{"version":3,"file":"element.d.ts","sourceRoot":"","sources":["../src/element.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AA0BH,mFAAmF;AACnF,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAExD;AAED;;;;;;;;GAQG;AACH,QAAA,MAAM,WAAW,EAEZ,OAAO,WAAW,CAAC;AAExB,qBAAa,mBAAoB,SAAQ,WAAW;IAClD,MAAM,KAAK,kBAAkB,IAAI,SAAS,MAAM,EAAE,CAEjD;IAED,OAAO,CAAC,MAAM,CAAkC;IAChD,OAAO,CAAC,IAAI,CAA0B;IAEtC,iBAAiB,IAAI,IAAI;IAIzB,oBAAoB,IAAI,IAAI;IAI5B,wBAAwB,IAAI,IAAI;IAQhC,OAAO,CAAC,MAAM;IAkDd,OAAO,CAAC,MAAM;CAMf;AAgDD,gEAAgE;AAChE,wBAAgB,kBAAkB,IAAI,IAAI,CAKzC"}
|
package/element.js
CHANGED
|
@@ -37,7 +37,18 @@ let defaultAppOrigin = null;
|
|
|
37
37
|
export function setDefaultAppOrigin(origin) {
|
|
38
38
|
defaultAppOrigin = origin;
|
|
39
39
|
}
|
|
40
|
-
|
|
40
|
+
/**
|
|
41
|
+
* SSR shim: `extends HTMLElement` is evaluated when the MODULE loads, not
|
|
42
|
+
* when the class is registered — so on a server (Next.js prerenders "use
|
|
43
|
+
* client" components too) a bare `extends HTMLElement` throws
|
|
44
|
+
* `ReferenceError: HTMLElement is not defined` on import, before the
|
|
45
|
+
* `customElements` guard in {@link defineStigmerAgent} can help. Extending a
|
|
46
|
+
* dummy base keeps the module importable everywhere; nothing constructs the
|
|
47
|
+
* element server-side, so the dummy is never observable.
|
|
48
|
+
*/
|
|
49
|
+
const BaseElement = (typeof HTMLElement === "undefined" ? class {
|
|
50
|
+
} : HTMLElement);
|
|
51
|
+
export class StigmerAgentElement extends BaseElement {
|
|
41
52
|
static get observedAttributes() {
|
|
42
53
|
return OBSERVED_ATTRIBUTES;
|
|
43
54
|
}
|
package/element.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element.js","sourceRoot":"","sources":["../src/element.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,eAAe,EAAkB,MAAM,WAAW,CAAC;AAE5D,2DAA2D;AAC3D,MAAM,mBAAmB,GAAG;IAC1B,KAAK;IACL,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,QAAQ;IACR,YAAY;CACJ,CAAC;AAEX,0DAA0D;AAC1D,MAAM,aAAa,GAAG,OAAO,CAAC;AAC9B,MAAM,cAAc,GAAG,OAAO,CAAC;AAE/B;;;;GAIG;AACH,IAAI,gBAAgB,GAAkB,IAAI,CAAC;AAE3C,mFAAmF;AACnF,MAAM,UAAU,mBAAmB,CAAC,MAAc;IAChD,gBAAgB,GAAG,MAAM,CAAC;AAC5B,CAAC;AAED,MAAM,OAAO,mBAAoB,SAAQ,WAAW;IAClD,MAAM,KAAK,kBAAkB;QAC3B,OAAO,mBAAmB,CAAC;IAC7B,CAAC;IAEO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KAAK,CAAC;IACxD,IAAI,KAAK,KAAK,MAAM,EAAE,CAAC;QACrB,OAAO,MAAM,CAAC,UAAU,EAAE,CAAC,8BAA8B,CAAC,CAAC,OAAO;YAChE,CAAC,CAAC,MAAM;YACR,CAAC,CAAC,OAAO,CAAC;IACd,CAAC;IACD,yDAAyD;IACzD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,SAAS,CAAC,KAAoB,EAAE,QAAgB;IACvD,IAAI,CAAC,KAAK;QAAE,OAAO,QAAQ,CAAC;IAC5B,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;AACpD,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,kBAAkB;IAChC,IAAI,OAAO,cAAc,KAAK,WAAW;QAAE,OAAO;IAClD,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,CAAC;QACzC,cAAc,CAAC,MAAM,CAAC,eAAe,EAAE,mBAAmB,CAAC,CAAC;IAC9D,CAAC;AACH,CAAC"}
|
package/embed.global.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var StigmerEmbed=(function(s){"use strict";var
|
|
1
|
+
var StigmerEmbed=(function(s){"use strict";var k=Object.defineProperty;var M=(s,o,c)=>o in s?k(s,o,{enumerable:!0,configurable:!0,writable:!0,value:c}):s[o]=c;var g=(s,o,c)=>M(s,typeof o!="symbol"?o+"":o,c);const o="stigmer-embed";function y(t){return{source:o,v:1,...t}}function w(t){if(typeof t!="object"||t===null)return null;const e=t;return e.source!==o||e.v!==1||typeof e.type!="string"?null:e}function A(t){const e=w(t);if(!e)return null;switch(e.type){case"hello":case"ready":case"refused":return{type:e.type};default:return null}}function O(t,e,i={}){const r=()=>{var n;(n=t.contentWindow)==null||n.postMessage(y({type:"init"}),e)},a=n=>{var E,b;if(n.source!==t.contentWindow||n.origin!==e)return;const u=A(n.data);if(u)switch(u.type){case"hello":r();break;case"ready":(E=i.onReady)==null||E.call(i);break;case"refused":(b=i.onRefused)==null||b.call(i);break}};return window.addEventListener("message",a),t.addEventListener("load",r),{destroy(){window.removeEventListener("message",a),t.removeEventListener("load",r)}}}const R=["org","agent","token","theme","width","height","app-origin"],S="400px",C="600px";let d=null;function h(t){d=t}const T=typeof HTMLElement>"u"?class{}:HTMLElement;class m extends T{constructor(){super(...arguments);g(this,"iframe",null);g(this,"host",null)}static get observedAttributes(){return R}connectedCallback(){this.attach()}disconnectedCallback(){this.detach()}attributeChangedCallback(){this.isConnected&&this.attach()}attach(){this.detach();const i=this.getAttribute("org"),r=this.getAttribute("agent"),a=this.getAttribute("app-origin")??d;if(!i||!r){console.error("[stigmer-agent] the org and agent attributes are required");return}if(!a){console.error('[stigmer-agent] no app origin: load embed.js from your Stigmer app origin, or set the app-origin attribute (e.g. app-origin="https://app.stigmer.ai")');return}this.style.display="inline-block",this.style.width=f(this.getAttribute("width"),S),this.style.height=f(this.getAttribute("height"),C);const n=document.createElement("iframe");n.src=v(a,i,r,this.getAttribute("token"),this.getAttribute("theme")),n.title=`Chat with ${r}`,n.setAttribute("loading","lazy"),n.style.cssText="width:100%;height:100%;border:0;border-radius:12px",this.appendChild(n),this.iframe=n,this.host=O(n,a,{onReady:()=>{this.dispatchEvent(new CustomEvent("stigmer:ready"))},onRefused:()=>{this.style.display="none",this.dispatchEvent(new CustomEvent("stigmer:refused"))}})}detach(){var i,r;(i=this.host)==null||i.destroy(),this.host=null,(r=this.iframe)==null||r.remove(),this.iframe=null}}function v(t,e,i,r,a){const n=new URL(`/chat/${encodeURIComponent(e)}/${encodeURIComponent(i)}`,t);r&&n.searchParams.set("k",r);const u=L(a);return u&&n.searchParams.set("theme",u),n.toString()}function L(t){var e;return t==="light"||t==="dark"?t:t==="auto"?(e=window.matchMedia)!=null&&e.call(window,"(prefers-color-scheme: dark)").matches?"dark":"light":null}function f(t,e){return t?/^\d+$/.test(t)?`${t}px`:t:e}function p(){typeof customElements>"u"||customElements.get("stigmer-agent")||customElements.define("stigmer-agent",m)}const l=document.currentScript;return l instanceof HTMLScriptElement&&l.src&&h(new URL(l.src).origin),p(),s.StigmerAgentElement=m,s.defineStigmerAgent=p,s.setDefaultAppOrigin=h,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"}),s})({});
|
package/jsx.d.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
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 (`org`, `agent`, 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
|
+
* Organization slug — first path segment of the hosted chat URL.
|
|
45
|
+
* Required at runtime (see above for why the type cannot enforce it).
|
|
46
|
+
*/
|
|
47
|
+
org?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Agent share slug — second path segment of the hosted chat URL.
|
|
50
|
+
* Required at runtime (see above for why the type cannot enforce it).
|
|
51
|
+
*/
|
|
52
|
+
agent?: string;
|
|
53
|
+
/** Link token for a locked share; forwarded as the `?k=` parameter. */
|
|
54
|
+
token?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Color mode, resolved once at mount. `auto` follows the OS
|
|
57
|
+
* `prefers-color-scheme`; omit it to let the hosted page pick its default.
|
|
58
|
+
*/
|
|
59
|
+
theme?: "light" | "dark" | "auto";
|
|
60
|
+
/** Host element CSS width; bare digits are treated as px. Default 400px. */
|
|
61
|
+
width?: string | number;
|
|
62
|
+
/** Host element CSS height; bare digits are treated as px. Default 600px. */
|
|
63
|
+
height?: string | number;
|
|
64
|
+
/**
|
|
65
|
+
* Origin of the Stigmer app hosting the chat page (e.g.
|
|
66
|
+
* `https://app.stigmer.ai`). Required for bundler consumers — there is no
|
|
67
|
+
* loader `<script src>` to derive it from.
|
|
68
|
+
*/
|
|
69
|
+
"app-origin"?: string;
|
|
70
|
+
/**
|
|
71
|
+
* `children` is omitted from the inherited attributes: the element owns its
|
|
72
|
+
* subtree (it injects the chat iframe), so React-rendered children would
|
|
73
|
+
* conflict with it. Listen for the `stigmer:ready` / `stigmer:refused`
|
|
74
|
+
* CustomEvents via a ref — colon-named events are not expressible as JSX
|
|
75
|
+
* props.
|
|
76
|
+
*/
|
|
77
|
+
children?: never;
|
|
78
|
+
}
|
|
79
|
+
declare module "react" {
|
|
80
|
+
namespace JSX {
|
|
81
|
+
interface IntrinsicElements {
|
|
82
|
+
"stigmer-agent": StigmerAgentAttributes;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
export {};
|
|
87
|
+
//# 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;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uEAAuE;IACvE,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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stigmer/embed",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.1",
|
|
4
4
|
"description": "One-line script embed for shared Stigmer agents — a framework-free <stigmer-agent> web component that bootstraps the hosted chat page in an iframe",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -36,6 +36,10 @@
|
|
|
36
36
|
"types": "./define.d.ts",
|
|
37
37
|
"import": "./define.js"
|
|
38
38
|
},
|
|
39
|
+
"./jsx": {
|
|
40
|
+
"types": "./jsx.d.ts",
|
|
41
|
+
"import": "./jsx.js"
|
|
42
|
+
},
|
|
39
43
|
"./loader": "./embed.global.js"
|
|
40
44
|
}
|
|
41
45
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
//
|
|
3
|
+
// SSR safety: React frameworks prerender "use client" components on the
|
|
4
|
+
// server, so `import "@stigmer/embed/define"` runs where neither HTMLElement
|
|
5
|
+
// nor customElements exist. This suite runs in plain Node (no happy-dom) to
|
|
6
|
+
// prove the modules load and no-op there — the regression it pins is the
|
|
7
|
+
// module-scope `extends HTMLElement` crash (element.ts's BaseElement shim).
|
|
8
|
+
|
|
9
|
+
import { describe, it, expect } from "vitest";
|
|
10
|
+
|
|
11
|
+
describe("server-side import", () => {
|
|
12
|
+
it("loads element.ts without a DOM and defineStigmerAgent no-ops", async () => {
|
|
13
|
+
const { defineStigmerAgent, StigmerAgentElement } = await import(
|
|
14
|
+
"../element.js"
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
expect(typeof StigmerAgentElement).toBe("function");
|
|
18
|
+
expect(() => defineStigmerAgent()).not.toThrow();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("loads the ./define side-effect entry without a DOM", async () => {
|
|
22
|
+
await expect(import("../define.js")).resolves.toBeDefined();
|
|
23
|
+
});
|
|
24
|
+
});
|
package/src/element.ts
CHANGED
|
@@ -43,7 +43,20 @@ export function setDefaultAppOrigin(origin: string): void {
|
|
|
43
43
|
defaultAppOrigin = origin;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
/**
|
|
47
|
+
* SSR shim: `extends HTMLElement` is evaluated when the MODULE loads, not
|
|
48
|
+
* when the class is registered — so on a server (Next.js prerenders "use
|
|
49
|
+
* client" components too) a bare `extends HTMLElement` throws
|
|
50
|
+
* `ReferenceError: HTMLElement is not defined` on import, before the
|
|
51
|
+
* `customElements` guard in {@link defineStigmerAgent} can help. Extending a
|
|
52
|
+
* dummy base keeps the module importable everywhere; nothing constructs the
|
|
53
|
+
* element server-side, so the dummy is never observable.
|
|
54
|
+
*/
|
|
55
|
+
const BaseElement = (
|
|
56
|
+
typeof HTMLElement === "undefined" ? class {} : HTMLElement
|
|
57
|
+
) as typeof HTMLElement;
|
|
58
|
+
|
|
59
|
+
export class StigmerAgentElement extends BaseElement {
|
|
47
60
|
static get observedAttributes(): readonly string[] {
|
|
48
61
|
return OBSERVED_ATTRIBUTES;
|
|
49
62
|
}
|
package/src/jsx.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
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
|
+
|
|
24
|
+
import type { ClassAttributes, HTMLAttributes } from "react";
|
|
25
|
+
// Type-only: erased at compile time, so the element implementation is never
|
|
26
|
+
// pulled into a consumer's bundle by this subpath.
|
|
27
|
+
import type { StigmerAgentElement } from "./element.js";
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* JSX attributes for `<stigmer-agent>` — one prop per observed attribute
|
|
31
|
+
* (see `OBSERVED_ATTRIBUTES` in `element.ts`; keep the two in sync).
|
|
32
|
+
*
|
|
33
|
+
* React sets these as HTML attributes (the element defines no matching
|
|
34
|
+
* properties), and the element rebuilds its iframe — destroying any
|
|
35
|
+
* in-progress conversation — whenever ANY of them changes. Keep every value
|
|
36
|
+
* referentially stable for the life of the element; resolve dynamic values
|
|
37
|
+
* (like a theme) once, before mounting.
|
|
38
|
+
*
|
|
39
|
+
* Every attribute is optional, including the two the element requires at
|
|
40
|
+
* runtime (`org`, `agent`, which it enforces with a console error). This is
|
|
41
|
+
* NOT laziness: libraries like react-markdown build mapped types over
|
|
42
|
+
* `JSX.IntrinsicElements`, and an intrinsic with required props breaks their
|
|
43
|
+
* assignability for every project that imports this augmentation. All
|
|
44
|
+
* standard intrinsics are typed all-optional for the same reason.
|
|
45
|
+
*/
|
|
46
|
+
// ClassAttributes supplies `ref`/`key` (mirroring React's DetailedHTMLProps);
|
|
47
|
+
// HTMLAttributes supplies the standard global attributes minus `children`.
|
|
48
|
+
interface StigmerAgentAttributes
|
|
49
|
+
extends ClassAttributes<StigmerAgentElement>,
|
|
50
|
+
Omit<HTMLAttributes<StigmerAgentElement>, "children"> {
|
|
51
|
+
/**
|
|
52
|
+
* Organization slug — first path segment of the hosted chat URL.
|
|
53
|
+
* Required at runtime (see above for why the type cannot enforce it).
|
|
54
|
+
*/
|
|
55
|
+
org?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Agent share slug — second path segment of the hosted chat URL.
|
|
58
|
+
* Required at runtime (see above for why the type cannot enforce it).
|
|
59
|
+
*/
|
|
60
|
+
agent?: string;
|
|
61
|
+
/** Link token for a locked share; forwarded as the `?k=` parameter. */
|
|
62
|
+
token?: string;
|
|
63
|
+
/**
|
|
64
|
+
* Color mode, resolved once at mount. `auto` follows the OS
|
|
65
|
+
* `prefers-color-scheme`; omit it to let the hosted page pick its default.
|
|
66
|
+
*/
|
|
67
|
+
theme?: "light" | "dark" | "auto";
|
|
68
|
+
/** Host element CSS width; bare digits are treated as px. Default 400px. */
|
|
69
|
+
width?: string | number;
|
|
70
|
+
/** Host element CSS height; bare digits are treated as px. Default 600px. */
|
|
71
|
+
height?: string | number;
|
|
72
|
+
/**
|
|
73
|
+
* Origin of the Stigmer app hosting the chat page (e.g.
|
|
74
|
+
* `https://app.stigmer.ai`). Required for bundler consumers — there is no
|
|
75
|
+
* loader `<script src>` to derive it from.
|
|
76
|
+
*/
|
|
77
|
+
"app-origin"?: string;
|
|
78
|
+
/**
|
|
79
|
+
* `children` is omitted from the inherited attributes: the element owns its
|
|
80
|
+
* subtree (it injects the chat iframe), so React-rendered children would
|
|
81
|
+
* conflict with it. Listen for the `stigmer:ready` / `stigmer:refused`
|
|
82
|
+
* CustomEvents via a ref — colon-named events are not expressible as JSX
|
|
83
|
+
* props.
|
|
84
|
+
*/
|
|
85
|
+
children?: never;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
declare module "react" {
|
|
89
|
+
namespace JSX {
|
|
90
|
+
interface IntrinsicElements {
|
|
91
|
+
"stigmer-agent": StigmerAgentAttributes;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Augmentations only apply from modules; this makes the file one.
|
|
97
|
+
export {};
|