@stigmer/embed 3.1.8

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 ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 Stigmer Contributors
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/define.d.ts ADDED
@@ -0,0 +1,8 @@
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
+ export {};
8
+ //# sourceMappingURL=define.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define.d.ts","sourceRoot":"","sources":["../src/define.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
package/define.js ADDED
@@ -0,0 +1,9 @@
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
+ import { defineStigmerAgent } from "./element.js";
8
+ defineStigmerAgent();
9
+ //# sourceMappingURL=define.js.map
package/define.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define.js","sourceRoot":"","sources":["../src/define.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD,kBAAkB,EAAE,CAAC"}
package/element.d.ts ADDED
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The `<stigmer-agent>` custom element — the widget a site owner pastes next
3
+ * to the one-line loader script:
4
+ *
5
+ * ```html
6
+ * <script src="https://app.stigmer.ai/embed.js" async></script>
7
+ * <stigmer-agent org="acme" agent="support-bot"></stigmer-agent>
8
+ * ```
9
+ *
10
+ * The element renders a cross-origin iframe onto the hosted chat page — the
11
+ * iframe is the isolation boundary; no Stigmer UI code runs in the host page.
12
+ * It hides itself when the platform refuses the embed context (origin not in
13
+ * the agent's allowed list), re-dispatching lifecycle signals as
14
+ * `stigmer:ready` / `stigmer:refused` CustomEvents for host-page scripting.
15
+ */
16
+ /** Sets the fallback origin used when an element has no `app-origin` attribute. */
17
+ export declare function setDefaultAppOrigin(origin: string): void;
18
+ export declare class StigmerAgentElement extends HTMLElement {
19
+ static get observedAttributes(): readonly string[];
20
+ private iframe;
21
+ private host;
22
+ connectedCallback(): void;
23
+ disconnectedCallback(): void;
24
+ attributeChangedCallback(): void;
25
+ private attach;
26
+ private detach;
27
+ }
28
+ /** Registers `<stigmer-agent>`; safe to call more than once. */
29
+ export declare function defineStigmerAgent(): void;
30
+ //# sourceMappingURL=element.d.ts.map
@@ -0,0 +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"}
package/element.js ADDED
@@ -0,0 +1,147 @@
1
+ /**
2
+ * The `<stigmer-agent>` custom element — the widget a site owner pastes next
3
+ * to the one-line loader script:
4
+ *
5
+ * ```html
6
+ * <script src="https://app.stigmer.ai/embed.js" async></script>
7
+ * <stigmer-agent org="acme" agent="support-bot"></stigmer-agent>
8
+ * ```
9
+ *
10
+ * The element renders a cross-origin iframe onto the hosted chat page — the
11
+ * iframe is the isolation boundary; no Stigmer UI code runs in the host page.
12
+ * It hides itself when the platform refuses the embed context (origin not in
13
+ * the agent's allowed list), re-dispatching lifecycle signals as
14
+ * `stigmer:ready` / `stigmer:refused` CustomEvents for host-page scripting.
15
+ */
16
+ import { createEmbedHost } from "./host.js";
17
+ /** Attribute-driven configuration of `<stigmer-agent>`. */
18
+ const OBSERVED_ATTRIBUTES = [
19
+ "org",
20
+ "agent",
21
+ "token",
22
+ "theme",
23
+ "width",
24
+ "height",
25
+ "app-origin",
26
+ ];
27
+ /** Matches the T03 iframe snippet's default footprint. */
28
+ const DEFAULT_WIDTH = "400px";
29
+ const DEFAULT_HEIGHT = "600px";
30
+ /**
31
+ * App origin the IIFE loader derives from its own `<script src>` (see
32
+ * `global.ts`). ESM consumers either call {@link setDefaultAppOrigin} or set
33
+ * the `app-origin` attribute per element.
34
+ */
35
+ let defaultAppOrigin = null;
36
+ /** Sets the fallback origin used when an element has no `app-origin` attribute. */
37
+ export function setDefaultAppOrigin(origin) {
38
+ defaultAppOrigin = origin;
39
+ }
40
+ export class StigmerAgentElement extends HTMLElement {
41
+ static get observedAttributes() {
42
+ return OBSERVED_ATTRIBUTES;
43
+ }
44
+ iframe = null;
45
+ host = null;
46
+ connectedCallback() {
47
+ this.attach();
48
+ }
49
+ disconnectedCallback() {
50
+ this.detach();
51
+ }
52
+ attributeChangedCallback() {
53
+ // Identity/config changes rebuild the frame; a chat conversation cannot
54
+ // survive a change of agent, theme, or origin anyway.
55
+ if (this.isConnected) {
56
+ this.attach();
57
+ }
58
+ }
59
+ attach() {
60
+ this.detach();
61
+ const org = this.getAttribute("org");
62
+ const agent = this.getAttribute("agent");
63
+ const appOrigin = this.getAttribute("app-origin") ?? defaultAppOrigin;
64
+ if (!org || !agent) {
65
+ console.error("[stigmer-agent] the org and agent attributes are required");
66
+ return;
67
+ }
68
+ if (!appOrigin) {
69
+ console.error("[stigmer-agent] no app origin: load embed.js from your Stigmer app " +
70
+ 'origin, or set the app-origin attribute (e.g. app-origin="https://app.stigmer.ai")');
71
+ return;
72
+ }
73
+ this.style.display = "inline-block";
74
+ this.style.width = cssLength(this.getAttribute("width"), DEFAULT_WIDTH);
75
+ this.style.height = cssLength(this.getAttribute("height"), DEFAULT_HEIGHT);
76
+ const iframe = document.createElement("iframe");
77
+ iframe.src = buildChatUrl(appOrigin, org, agent, this.getAttribute("token"), this.getAttribute("theme"));
78
+ iframe.title = `Chat with ${agent}`;
79
+ iframe.setAttribute("loading", "lazy");
80
+ iframe.style.cssText =
81
+ "width:100%;height:100%;border:0;border-radius:12px";
82
+ this.appendChild(iframe);
83
+ this.iframe = iframe;
84
+ this.host = createEmbedHost(iframe, appOrigin, {
85
+ onReady: () => {
86
+ this.dispatchEvent(new CustomEvent("stigmer:ready"));
87
+ },
88
+ onRefused: () => {
89
+ // Hide gracefully rather than erroring — the requirement for embeds
90
+ // on sites the agent owner has not allowed.
91
+ this.style.display = "none";
92
+ this.dispatchEvent(new CustomEvent("stigmer:refused"));
93
+ },
94
+ });
95
+ }
96
+ detach() {
97
+ this.host?.destroy();
98
+ this.host = null;
99
+ this.iframe?.remove();
100
+ this.iframe = null;
101
+ }
102
+ }
103
+ function buildChatUrl(appOrigin, org, agent, token, theme) {
104
+ const url = new URL(`/chat/${encodeURIComponent(org)}/${encodeURIComponent(agent)}`, appOrigin);
105
+ // `k` is the platform's link-token parameter (see @stigmer/sdk's
106
+ // LINK_TOKEN_PARAM — not imported: this loader stays dependency-free).
107
+ // Required when the share link is locked; the hosted page forwards it
108
+ // on its guest mint, where the server validates it.
109
+ if (token) {
110
+ url.searchParams.set("k", token);
111
+ }
112
+ const resolved = resolveTheme(theme);
113
+ if (resolved) {
114
+ url.searchParams.set("theme", resolved);
115
+ }
116
+ return url.toString();
117
+ }
118
+ /**
119
+ * Resolves the theme attribute once, at mount. Deliberately not live-tracked:
120
+ * a theme flip mid-conversation would reload the iframe and destroy the
121
+ * visitor's chat, which is worse than a stale theme.
122
+ */
123
+ function resolveTheme(theme) {
124
+ if (theme === "light" || theme === "dark")
125
+ return theme;
126
+ if (theme === "auto") {
127
+ return window.matchMedia?.("(prefers-color-scheme: dark)").matches
128
+ ? "dark"
129
+ : "light";
130
+ }
131
+ // No attribute: let the hosted page use its own default.
132
+ return null;
133
+ }
134
+ function cssLength(value, fallback) {
135
+ if (!value)
136
+ return fallback;
137
+ return /^\d+$/.test(value) ? `${value}px` : value;
138
+ }
139
+ /** Registers `<stigmer-agent>`; safe to call more than once. */
140
+ export function defineStigmerAgent() {
141
+ if (typeof customElements === "undefined")
142
+ return;
143
+ if (!customElements.get("stigmer-agent")) {
144
+ customElements.define("stigmer-agent", StigmerAgentElement);
145
+ }
146
+ }
147
+ //# sourceMappingURL=element.js.map
package/element.js.map ADDED
@@ -0,0 +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,MAAM,GAA6B,IAAI,CAAC;IACxC,IAAI,GAAqB,IAAI,CAAC;IAEtC,iBAAiB;QACf,IAAI,CAAC,MAAM,EAAE,CAAC;IAChB,CAAC;IAED,oBAAoB;QAClB,IAAI,CAAC,MAAM,EAAE,CAAC;IAChB,CAAC;IAED,wBAAwB;QACtB,wEAAwE;QACxE,sDAAsD;QACtD,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,IAAI,CAAC,M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AC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;AACxB,CAAC;AAED;;;;GAIG;AACH,SAAS,YAAY,CAAC,KAAoB;IACxC,IAAI,KAAK,KAAK,OAAO,IAAI,KAAK,KAAK,MAAM;QAAE,OAAO,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"}
@@ -0,0 +1 @@
1
+ var StigmerEmbed=(function(s){"use strict";var L=Object.defineProperty;var k=(s,o,c)=>o in s?L(s,o,{enumerable:!0,configurable:!0,writable:!0,value:c}):s[o]=c;var l=(s,o,c)=>k(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}class m extends HTMLElement{constructor(){super(...arguments);l(this,"iframe",null);l(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=T(a);return u&&n.searchParams.set("theme",u),n.toString()}function T(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 g=document.currentScript;return g instanceof HTMLScriptElement&&g.src&&h(new URL(g.src).origin),p(),s.StigmerAgentElement=m,s.defineStigmerAgent=p,s.setDefaultAppOrigin=h,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"}),s})({});
package/frame.d.ts ADDED
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Frame-side helpers — the half of the embed protocol that runs inside the
3
+ * hosted chat page (`/chat/<org>/<slug>` in `client-apps/web`).
4
+ *
5
+ * The embedding site cannot alter this code (it is served from the Stigmer app
6
+ * origin), so the parent origin discovered here is honest by construction.
7
+ * Every source in the discovery ladder is browser-controlled:
8
+ *
9
+ * 1. `location.ancestorOrigins[0]` — the direct parent's origin (Chromium and
10
+ * WebKit; not implemented in Firefox).
11
+ * 2. `document.referrer` — the parent page URL at iframe load (all browsers,
12
+ * but suppressible via the embedder's Referrer-Policy).
13
+ * 3. The `hello`/`init` postMessage handshake with the loader — the browser
14
+ * stamps `event.origin` on the parent's reply, which no page can forge.
15
+ *
16
+ * When all three fail (a plain iframe with suppressed referrer and no loader),
17
+ * the ladder resolves to {@link OPAQUE_ORIGIN} — the WHATWG serialization of
18
+ * an opaque origin — which the platform refuses whenever the agent's
19
+ * `allowed_origins` list is non-empty (fail closed in strict mode).
20
+ */
21
+ import { type FrameToHostMessage } from "./protocol.js";
22
+ /**
23
+ * Serialization of an opaque/undiscoverable origin (WHATWG HTML spec).
24
+ * Mirrors `SharingOriginPolicy.OPAQUE_ORIGIN` on the server.
25
+ */
26
+ export declare const OPAQUE_ORIGIN = "null";
27
+ /**
28
+ * Whether the page is running inside an iframe. `false` during SSR/prerender
29
+ * (no `window`), so static export never takes the embed path.
30
+ */
31
+ export declare function isEmbedded(): boolean;
32
+ /**
33
+ * Resolves the embedding page's origin via the discovery ladder above.
34
+ * Only meaningful when {@link isEmbedded} is `true`. Never rejects — an
35
+ * undiscoverable parent resolves to {@link OPAQUE_ORIGIN}.
36
+ */
37
+ export declare function resolveParentOrigin(timeoutMs?: number): Promise<string>;
38
+ /**
39
+ * Posts a lifecycle signal to the embedding page's loader.
40
+ *
41
+ * Targets the discovered parent origin when known; `ready`/`refused` carry no
42
+ * payload, so the `"*"` fallback for an opaque parent leaks nothing.
43
+ */
44
+ export declare function notifyParent(message: FrameToHostMessage, parentOrigin: string): void;
45
+ //# sourceMappingURL=frame.d.ts.map
package/frame.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frame.d.ts","sourceRoot":"","sources":["../src/frame.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAGL,KAAK,kBAAkB,EACxB,MAAM,eAAe,CAAC;AAEvB;;;GAGG;AACH,eAAO,MAAM,aAAa,SAAS,CAAC;AAKpC;;;GAGG;AACH,wBAAgB,UAAU,IAAI,OAAO,CASpC;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,GAAE,MAA6B,GACvC,OAAO,CAAC,MAAM,CAAC,CAQjB;AAiDD;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,kBAAkB,EAC3B,YAAY,EAAE,MAAM,GACnB,IAAI,CAIN"}
package/frame.js ADDED
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Frame-side helpers — the half of the embed protocol that runs inside the
3
+ * hosted chat page (`/chat/<org>/<slug>` in `client-apps/web`).
4
+ *
5
+ * The embedding site cannot alter this code (it is served from the Stigmer app
6
+ * origin), so the parent origin discovered here is honest by construction.
7
+ * Every source in the discovery ladder is browser-controlled:
8
+ *
9
+ * 1. `location.ancestorOrigins[0]` — the direct parent's origin (Chromium and
10
+ * WebKit; not implemented in Firefox).
11
+ * 2. `document.referrer` — the parent page URL at iframe load (all browsers,
12
+ * but suppressible via the embedder's Referrer-Policy).
13
+ * 3. The `hello`/`init` postMessage handshake with the loader — the browser
14
+ * stamps `event.origin` on the parent's reply, which no page can forge.
15
+ *
16
+ * When all three fail (a plain iframe with suppressed referrer and no loader),
17
+ * the ladder resolves to {@link OPAQUE_ORIGIN} — the WHATWG serialization of
18
+ * an opaque origin — which the platform refuses whenever the agent's
19
+ * `allowed_origins` list is non-empty (fail closed in strict mode).
20
+ */
21
+ import { parseHostMessage, toWire, } from "./protocol.js";
22
+ /**
23
+ * Serialization of an opaque/undiscoverable origin (WHATWG HTML spec).
24
+ * Mirrors `SharingOriginPolicy.OPAQUE_ORIGIN` on the server.
25
+ */
26
+ export const OPAQUE_ORIGIN = "null";
27
+ /** How long to wait for the loader's `init` reply before giving up. */
28
+ const HANDSHAKE_TIMEOUT_MS = 1_500;
29
+ /**
30
+ * Whether the page is running inside an iframe. `false` during SSR/prerender
31
+ * (no `window`), so static export never takes the embed path.
32
+ */
33
+ export function isEmbedded() {
34
+ if (typeof window === "undefined")
35
+ return false;
36
+ try {
37
+ return window.self !== window.top;
38
+ }
39
+ catch {
40
+ // Cross-origin access to window.top throws in some engines — which
41
+ // itself proves the page is framed by a foreign origin.
42
+ return true;
43
+ }
44
+ }
45
+ /**
46
+ * Resolves the embedding page's origin via the discovery ladder above.
47
+ * Only meaningful when {@link isEmbedded} is `true`. Never rejects — an
48
+ * undiscoverable parent resolves to {@link OPAQUE_ORIGIN}.
49
+ */
50
+ export function resolveParentOrigin(timeoutMs = HANDSHAKE_TIMEOUT_MS) {
51
+ const ancestor = ancestorOrigin();
52
+ if (ancestor)
53
+ return Promise.resolve(ancestor);
54
+ const referrer = referrerOrigin();
55
+ if (referrer)
56
+ return Promise.resolve(referrer);
57
+ return handshakeOrigin(timeoutMs);
58
+ }
59
+ function ancestorOrigin() {
60
+ const origins = window.location.ancestorOrigins;
61
+ const direct = origins && origins.length > 0 ? origins[0] : null;
62
+ // An opaque ancestor serializes as "null"; treat it as undiscovered so the
63
+ // remaining rungs get a chance before the opaque fallback.
64
+ return direct && direct !== OPAQUE_ORIGIN ? direct : null;
65
+ }
66
+ function referrerOrigin() {
67
+ const referrer = document.referrer;
68
+ if (!referrer)
69
+ return null;
70
+ try {
71
+ return new URL(referrer).origin;
72
+ }
73
+ catch {
74
+ return null;
75
+ }
76
+ }
77
+ /**
78
+ * Asks the loader for `init` and reads the browser-authentic `event.origin`
79
+ * off the reply. The `hello` is posted to `"*"` because the parent origin is
80
+ * exactly what we do not know yet — it carries no payload, so broadcasting
81
+ * it is safe.
82
+ */
83
+ function handshakeOrigin(timeoutMs) {
84
+ return new Promise((resolveOrigin) => {
85
+ let settled = false;
86
+ const settle = (origin) => {
87
+ if (settled)
88
+ return;
89
+ settled = true;
90
+ window.removeEventListener("message", onMessage);
91
+ clearTimeout(timer);
92
+ resolveOrigin(origin);
93
+ };
94
+ const onMessage = (event) => {
95
+ if (event.source !== window.parent)
96
+ return;
97
+ if (!parseHostMessage(event.data))
98
+ return;
99
+ settle(event.origin === "" ? OPAQUE_ORIGIN : event.origin);
100
+ };
101
+ const timer = setTimeout(() => settle(OPAQUE_ORIGIN), timeoutMs);
102
+ window.addEventListener("message", onMessage);
103
+ window.parent.postMessage(toWire({ type: "hello" }), "*");
104
+ });
105
+ }
106
+ /**
107
+ * Posts a lifecycle signal to the embedding page's loader.
108
+ *
109
+ * Targets the discovered parent origin when known; `ready`/`refused` carry no
110
+ * payload, so the `"*"` fallback for an opaque parent leaks nothing.
111
+ */
112
+ export function notifyParent(message, parentOrigin) {
113
+ if (!isEmbedded())
114
+ return;
115
+ const target = parentOrigin === OPAQUE_ORIGIN ? "*" : parentOrigin;
116
+ window.parent.postMessage(toWire(message), target);
117
+ }
118
+ //# sourceMappingURL=frame.js.map
package/frame.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frame.js","sourceRoot":"","sources":["../src/frame.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;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AAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAC1B,OAA2B,EAC3B,YAAoB;IAEpB,IAAI,CAAC,UAAU,EAAE;QAAE,OAAO;IAC1B,MAAM,MAAM,GAAG,YAAY,KAAK,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC;IACnE,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC;AACrD,CAAC"}
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
@@ -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"}