@opengeni/react 4.0.2 → 5.0.2-canary.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 (48) hide show
  1. package/README.md +42 -0
  2. package/dist/artifacts.js +24 -285
  3. package/dist/artifacts.js.map +1 -1
  4. package/dist/chunk-BRFMGY4L.js +274 -0
  5. package/dist/chunk-BRFMGY4L.js.map +1 -0
  6. package/dist/chunk-IWIDV7SB.js +1 -0
  7. package/dist/chunk-IWIDV7SB.js.map +1 -0
  8. package/dist/{chunk-CQG7YUJB.js → chunk-WRVKY242.js} +1169 -1017
  9. package/dist/chunk-WRVKY242.js.map +1 -0
  10. package/dist/clipboard.js +1 -0
  11. package/dist/components/message-timeline.d.ts +7 -3
  12. package/dist/connect-accounts.d.ts +10 -0
  13. package/dist/connect-chooser.d.ts +11 -0
  14. package/dist/connect-panel.d.ts +10 -0
  15. package/dist/connect-setup.d.ts +12 -0
  16. package/dist/connect.d.ts +30 -0
  17. package/dist/connect.js +831 -0
  18. package/dist/connect.js.map +1 -0
  19. package/dist/device-authorization.d.ts +15 -0
  20. package/dist/identity-link-accounts.d.ts +11 -0
  21. package/dist/identity-link-consent.d.ts +18 -0
  22. package/dist/index.js +523 -663
  23. package/dist/index.js.map +1 -1
  24. package/dist/session-ui.d.ts +2 -0
  25. package/dist/session-ui.js +3 -1
  26. package/dist/sites-ui.d.ts +33 -0
  27. package/dist/sites.d.ts +3 -0
  28. package/dist/sites.js +288 -0
  29. package/dist/sites.js.map +1 -0
  30. package/package.json +16 -2
  31. package/src/components/message-timeline.tsx +22 -5
  32. package/src/components/sandbox-workspace.tsx +9 -2
  33. package/src/connect-accounts.tsx +171 -0
  34. package/src/connect-chooser.tsx +144 -0
  35. package/src/connect-panel.tsx +29 -0
  36. package/src/connect-setup.tsx +260 -0
  37. package/src/connect.ts +48 -0
  38. package/src/device-authorization.tsx +90 -0
  39. package/src/hooks/use-workspace-capture.ts +3 -2
  40. package/src/identity-link-accounts.tsx +144 -0
  41. package/src/identity-link-consent.tsx +192 -0
  42. package/src/session-ui.ts +2 -0
  43. package/src/sites-ui.tsx +385 -0
  44. package/src/sites.ts +3 -0
  45. package/src/timeline/tool-renderers.tsx +1 -1
  46. package/styles/connect.css +48 -0
  47. package/styles/connect.d.ts +1 -0
  48. package/dist/chunk-CQG7YUJB.js.map +0 -1
@@ -0,0 +1,274 @@
1
+ // src/components/artifacts/published-html-artifact-frame.tsx
2
+ import {
3
+ OPENGENI_SITE_BRIDGE_BOOTSTRAP_GLOBAL,
4
+ OPENGENI_SITE_BRIDGE_READY,
5
+ OPENGENI_SITE_BRIDGE_RESPONSE,
6
+ OPENGENI_SITE_BRIDGE_VERSION,
7
+ isOpenGeniSiteBridgeCancelMessage,
8
+ isOpenGeniSiteBridgeConnectMessage,
9
+ isOpenGeniSiteBridgeRequestMessage,
10
+ sanitizeOpenGeniSiteToolCallRequest,
11
+ isSiteHttpRequest,
12
+ serveSiteHttp
13
+ } from "@opengeni/sdk/site";
14
+ import { useEffect, useRef } from "react";
15
+ import { jsx } from "react/jsx-runtime";
16
+ var PUBLISHED_HTML_ARTIFACT_IFRAME_SANDBOX = [
17
+ "allow-downloads",
18
+ "allow-forms",
19
+ "allow-modals",
20
+ "allow-orientation-lock",
21
+ "allow-pointer-lock",
22
+ "allow-popups",
23
+ "allow-popups-to-escape-sandbox",
24
+ "allow-presentation",
25
+ "allow-scripts"
26
+ ].join(" ");
27
+ var SITE_BRIDGE_BOOTSTRAP_SCRIPT = `<script>(()=>{const key=${JSON.stringify(
28
+ OPENGENI_SITE_BRIDGE_BOOTSTRAP_GLOBAL
29
+ )};const parentWindow=window.parent;if(parentWindow===window)return;window.addEventListener("message",event=>{const data=event.data;if(event.source!==parentWindow||!data||data.type!==${JSON.stringify(
30
+ OPENGENI_SITE_BRIDGE_READY
31
+ )}||data.version!==${OPENGENI_SITE_BRIDGE_VERSION}||event.ports.length!==1)return;const port=event.ports[0];const previous=window[key]?.port;if(previous&&previous!==port)previous.close();Object.defineProperty(window,key,{configurable:true,value:{port}});port.start();});})();</script>`;
32
+ function publishedHtmlArtifactDocument(html, toolBridgeEnabled) {
33
+ if (!toolBridgeEnabled) return html;
34
+ const doctypeEnd = leadingDoctypeEnd(html);
35
+ if (doctypeEnd >= 0) {
36
+ return `${html.slice(0, doctypeEnd + 1)}${SITE_BRIDGE_BOOTSTRAP_SCRIPT}${html.slice(doctypeEnd + 1)}`;
37
+ }
38
+ return `${SITE_BRIDGE_BOOTSTRAP_SCRIPT}${html}`;
39
+ }
40
+ function leadingDoctypeEnd(html) {
41
+ const lower = html.toLowerCase();
42
+ let cursor = html.charCodeAt(0) === 65279 ? 1 : 0;
43
+ while (cursor < html.length) {
44
+ while (/\s/.test(html[cursor] ?? "")) cursor += 1;
45
+ if (!html.startsWith("<!--", cursor)) break;
46
+ const commentEnd = html.indexOf("-->", cursor + 4);
47
+ if (commentEnd < 0) return -1;
48
+ cursor = commentEnd + 3;
49
+ }
50
+ if (!lower.startsWith("<!doctype", cursor)) return -1;
51
+ return html.indexOf(">", cursor + 9);
52
+ }
53
+ function PublishedHtmlArtifactFrame(props) {
54
+ const frameRef = useRef(null);
55
+ const bridgeRef = useRef(props.toolBridge);
56
+ const onFrameLoadRef = useRef(() => void 0);
57
+ const frameLoadPendingRef = useRef(false);
58
+ const toolBridgeEnabled = props.toolBridge !== void 0;
59
+ useEffect(() => {
60
+ bridgeRef.current = props.toolBridge;
61
+ }, [props.toolBridge]);
62
+ useEffect(() => {
63
+ if (!toolBridgeEnabled || typeof window === "undefined") return;
64
+ const requests = new SiteBridgeRequestRegistry();
65
+ const attachToolPort = (data, ports) => {
66
+ const port = openGeniSiteBridgePortFromBootstrap(data, ports);
67
+ if (!port) return;
68
+ requests.addPort(port);
69
+ port.addEventListener("message", (portEvent) => {
70
+ const message = portEvent.data;
71
+ if (isOpenGeniSiteBridgeCancelMessage(message)) {
72
+ requests.cancel(port, message.requestId);
73
+ return;
74
+ }
75
+ if (isSiteHttpRequest(message) && portEvent.ports.length === 1) {
76
+ const controller2 = requests.start(port, message.requestId);
77
+ if (!controller2) {
78
+ portEvent.ports[0].close();
79
+ return;
80
+ }
81
+ void serveSiteHttp(
82
+ message,
83
+ portEvent.ports[0],
84
+ async (request, signal) => {
85
+ const fetch = bridgeRef.current?.fetch;
86
+ if (!fetch) throw new Error("This Site host does not support the session SDK");
87
+ return fetch(request, signal);
88
+ },
89
+ controller2.signal
90
+ ).finally(() => requests.complete(port, message.requestId, controller2));
91
+ return;
92
+ }
93
+ if (!isOpenGeniSiteBridgeRequestMessage(message)) return;
94
+ const controller = requests.start(port, message.requestId);
95
+ if (!controller) {
96
+ port.postMessage({
97
+ type: OPENGENI_SITE_BRIDGE_RESPONSE,
98
+ version: OPENGENI_SITE_BRIDGE_VERSION,
99
+ requestId: message.requestId,
100
+ ok: false,
101
+ error: {
102
+ code: "duplicate_request_id",
103
+ message: "A Site tool request with this id is already running",
104
+ retryable: false
105
+ }
106
+ });
107
+ return;
108
+ }
109
+ void handleSiteBridgeRequest(bridgeRef.current, message, controller.signal).then((value) => {
110
+ if (!controller.signal.aborted) {
111
+ port.postMessage({
112
+ type: OPENGENI_SITE_BRIDGE_RESPONSE,
113
+ version: OPENGENI_SITE_BRIDGE_VERSION,
114
+ requestId: message.requestId,
115
+ ok: true,
116
+ value
117
+ });
118
+ }
119
+ }).catch((error) => {
120
+ if (!controller.signal.aborted) {
121
+ port.postMessage({
122
+ type: OPENGENI_SITE_BRIDGE_RESPONSE,
123
+ version: OPENGENI_SITE_BRIDGE_VERSION,
124
+ requestId: message.requestId,
125
+ ok: false,
126
+ error: siteBridgeError(error)
127
+ });
128
+ }
129
+ }).finally(() => requests.complete(port, message.requestId, controller));
130
+ });
131
+ port.addEventListener("messageerror", () => requests.closePort(port));
132
+ port.start();
133
+ port.postMessage({
134
+ type: OPENGENI_SITE_BRIDGE_READY,
135
+ version: OPENGENI_SITE_BRIDGE_VERSION
136
+ });
137
+ };
138
+ const documentLease = new SiteBridgeDocumentLease(attachToolPort, () => requests.closeAll());
139
+ const onFrameLoad = () => {
140
+ frameLoadPendingRef.current = false;
141
+ const frameWindow = frameRef.current?.contentWindow ?? null;
142
+ if (!frameWindow) return;
143
+ documentLease.load(frameWindow);
144
+ };
145
+ onFrameLoadRef.current = onFrameLoad;
146
+ if (frameLoadPendingRef.current) {
147
+ frameLoadPendingRef.current = false;
148
+ onFrameLoad();
149
+ }
150
+ return () => {
151
+ onFrameLoadRef.current = () => void 0;
152
+ documentLease.close();
153
+ };
154
+ }, [props.html, toolBridgeEnabled]);
155
+ return /* @__PURE__ */ jsx(
156
+ "iframe",
157
+ {
158
+ ref: frameRef,
159
+ title: props.title,
160
+ sandbox: PUBLISHED_HTML_ARTIFACT_IFRAME_SANDBOX,
161
+ referrerPolicy: "no-referrer",
162
+ srcDoc: publishedHtmlArtifactDocument(props.html, toolBridgeEnabled),
163
+ onLoad: () => {
164
+ frameLoadPendingRef.current = true;
165
+ onFrameLoadRef.current();
166
+ },
167
+ className: props.className,
168
+ style: props.style
169
+ }
170
+ );
171
+ }
172
+ var SiteBridgeRequestRegistry = class {
173
+ controllersByPort = /* @__PURE__ */ new Map();
174
+ addPort(port) {
175
+ if (!this.controllersByPort.has(port)) this.controllersByPort.set(port, /* @__PURE__ */ new Map());
176
+ }
177
+ start(port, requestId) {
178
+ const controllers = this.controllersByPort.get(port);
179
+ if (!controllers || controllers.has(requestId)) return null;
180
+ const controller = new AbortController();
181
+ controllers.set(requestId, controller);
182
+ return controller;
183
+ }
184
+ cancel(port, requestId) {
185
+ const controllers = this.controllersByPort.get(port);
186
+ const controller = controllers?.get(requestId);
187
+ if (!controller) return;
188
+ controller.abort(new Error("Site tool request cancelled"));
189
+ controllers.delete(requestId);
190
+ }
191
+ complete(port, requestId, controller) {
192
+ const controllers = this.controllersByPort.get(port);
193
+ if (controllers?.get(requestId) === controller) controllers.delete(requestId);
194
+ }
195
+ closePort(port) {
196
+ const controllers = this.controllersByPort.get(port);
197
+ if (!controllers) return;
198
+ for (const controller of controllers.values()) {
199
+ controller.abort(new Error("Site tool bridge port closed"));
200
+ }
201
+ controllers.clear();
202
+ this.controllersByPort.delete(port);
203
+ port.close();
204
+ }
205
+ closeAll() {
206
+ for (const port of [...this.controllersByPort.keys()]) this.closePort(port);
207
+ }
208
+ };
209
+ var SiteBridgeDocumentLease = class {
210
+ constructor(attachToolPort, closeActivePorts, createMessageChannel = () => new MessageChannel()) {
211
+ this.attachToolPort = attachToolPort;
212
+ this.closeActivePorts = closeActivePorts;
213
+ this.createMessageChannel = createMessageChannel;
214
+ }
215
+ loaded = false;
216
+ bootstrapPort = null;
217
+ load(frameWindow) {
218
+ if (this.loaded) {
219
+ this.close();
220
+ return false;
221
+ }
222
+ this.loaded = true;
223
+ const channel = this.createMessageChannel();
224
+ this.bootstrapPort = channel.port1;
225
+ channel.port1.addEventListener("message", (event) => {
226
+ this.attachToolPort(event.data, event.ports);
227
+ });
228
+ channel.port1.start();
229
+ frameWindow.postMessage(
230
+ {
231
+ type: OPENGENI_SITE_BRIDGE_READY,
232
+ version: OPENGENI_SITE_BRIDGE_VERSION
233
+ },
234
+ "*",
235
+ [channel.port2]
236
+ );
237
+ return true;
238
+ }
239
+ close() {
240
+ this.bootstrapPort?.close();
241
+ this.bootstrapPort = null;
242
+ this.closeActivePorts();
243
+ }
244
+ };
245
+ function openGeniSiteBridgePortFromBootstrap(data, ports) {
246
+ if (!isOpenGeniSiteBridgeConnectMessage(data)) return null;
247
+ return ports.length === 1 ? ports[0] : null;
248
+ }
249
+ async function handleSiteBridgeRequest(bridge, message, signal) {
250
+ if (!bridge) throw new Error("Site tool bridge is unavailable");
251
+ if (message.method === "catalog") return await bridge.catalog({ signal });
252
+ if (message.method === "declarations") {
253
+ if (!bridge.declarations) throw new Error("Site tool declarations are unavailable");
254
+ return await bridge.declarations({ signal });
255
+ }
256
+ return await bridge.call(sanitizeOpenGeniSiteToolCallRequest(message.payload), { signal });
257
+ }
258
+ function siteBridgeError(error) {
259
+ const candidate = error;
260
+ return {
261
+ code: typeof candidate?.code === "string" ? candidate.code : "site_tool_call_failed",
262
+ message: typeof candidate?.message === "string" ? candidate.message : "Site tool request failed",
263
+ retryable: candidate?.retryable === true,
264
+ outcomeUnknown: candidate?.outcomeUnknown === true
265
+ };
266
+ }
267
+
268
+ export {
269
+ PUBLISHED_HTML_ARTIFACT_IFRAME_SANDBOX,
270
+ publishedHtmlArtifactDocument,
271
+ PublishedHtmlArtifactFrame,
272
+ openGeniSiteBridgePortFromBootstrap
273
+ };
274
+ //# sourceMappingURL=chunk-BRFMGY4L.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/artifacts/published-html-artifact-frame.tsx"],"sourcesContent":["import {\n OPENGENI_SITE_BRIDGE_BOOTSTRAP_GLOBAL,\n OPENGENI_SITE_BRIDGE_READY,\n OPENGENI_SITE_BRIDGE_RESPONSE,\n OPENGENI_SITE_BRIDGE_VERSION,\n isOpenGeniSiteBridgeCancelMessage,\n isOpenGeniSiteBridgeConnectMessage,\n isOpenGeniSiteBridgeRequestMessage,\n sanitizeOpenGeniSiteToolCallRequest,\n isSiteHttpRequest,\n serveSiteHttp,\n type SiteHttpRequest,\n type OpenGeniSiteBridgeResponseMessage,\n type OpenGeniSiteToolCatalog,\n} from \"@opengeni/sdk/site\";\nimport type {\n ToolGatewayCallRequest,\n ToolGatewayCallResponse,\n ToolGatewayDeclarationsResponse,\n} from \"@opengeni/sdk\";\nimport { useEffect, useRef, type CSSProperties } from \"react\";\n\nexport const PUBLISHED_HTML_ARTIFACT_IFRAME_SANDBOX = [\n \"allow-downloads\",\n \"allow-forms\",\n \"allow-modals\",\n \"allow-orientation-lock\",\n \"allow-pointer-lock\",\n \"allow-popups\",\n \"allow-popups-to-escape-sandbox\",\n \"allow-presentation\",\n \"allow-scripts\",\n].join(\" \");\n\nexport type PublishedHtmlArtifactFrameProps = {\n html: string;\n title: string;\n className?: string;\n style?: CSSProperties;\n toolBridge?: PublishedHtmlArtifactToolBridge;\n};\n\nexport type PublishedHtmlArtifactToolBridge = {\n fetch?: (request: SiteHttpRequest, signal: AbortSignal) => Promise<Response>;\n catalog: (options: { signal: AbortSignal }) => Promise<OpenGeniSiteToolCatalog>;\n call: (\n request: ToolGatewayCallRequest,\n options: { signal: AbortSignal },\n ) => Promise<ToolGatewayCallResponse>;\n declarations?: (options: { signal: AbortSignal }) => Promise<ToolGatewayDeclarationsResponse>;\n};\n\nconst SITE_BRIDGE_BOOTSTRAP_SCRIPT = `<script>(()=>{const key=${JSON.stringify(\n OPENGENI_SITE_BRIDGE_BOOTSTRAP_GLOBAL,\n)};const parentWindow=window.parent;if(parentWindow===window)return;window.addEventListener(\"message\",event=>{const data=event.data;if(event.source!==parentWindow||!data||data.type!==${JSON.stringify(\n OPENGENI_SITE_BRIDGE_READY,\n)}||data.version!==${OPENGENI_SITE_BRIDGE_VERSION}||event.ports.length!==1)return;const port=event.ports[0];const previous=window[key]?.port;if(previous&&previous!==port)previous.close();Object.defineProperty(window,key,{configurable:true,value:{port}});port.start();});})();</script>`;\n\nexport function publishedHtmlArtifactDocument(html: string, toolBridgeEnabled: boolean): string {\n if (!toolBridgeEnabled) return html;\n const doctypeEnd = leadingDoctypeEnd(html);\n if (doctypeEnd >= 0) {\n return `${html.slice(0, doctypeEnd + 1)}${SITE_BRIDGE_BOOTSTRAP_SCRIPT}${html.slice(doctypeEnd + 1)}`;\n }\n return `${SITE_BRIDGE_BOOTSTRAP_SCRIPT}${html}`;\n}\n\nfunction leadingDoctypeEnd(html: string): number {\n const lower = html.toLowerCase();\n let cursor = html.charCodeAt(0) === 0xfeff ? 1 : 0;\n while (cursor < html.length) {\n while (/\\s/.test(html[cursor] ?? \"\")) cursor += 1;\n if (!html.startsWith(\"<!--\", cursor)) break;\n const commentEnd = html.indexOf(\"-->\", cursor + 4);\n if (commentEnd < 0) return -1;\n cursor = commentEnd + 3;\n }\n if (!lower.startsWith(\"<!doctype\", cursor)) return -1;\n return html.indexOf(\">\", cursor + 9);\n}\n\n/**\n * Render exact published HTML in an opaque-origin iframe. Artifact scripts,\n * external resources, forms, popups, downloads, and the host-filtered tool\n * bridge work without granting parent-origin authority, shared cookies/storage,\n * or top-level navigation.\n */\nexport function PublishedHtmlArtifactFrame(props: PublishedHtmlArtifactFrameProps) {\n const frameRef = useRef<HTMLIFrameElement | null>(null);\n const bridgeRef = useRef(props.toolBridge);\n const onFrameLoadRef = useRef<() => void>(() => undefined);\n const frameLoadPendingRef = useRef(false);\n const toolBridgeEnabled = props.toolBridge !== undefined;\n useEffect(() => {\n bridgeRef.current = props.toolBridge;\n }, [props.toolBridge]);\n useEffect(() => {\n if (!toolBridgeEnabled || typeof window === \"undefined\") return;\n const requests = new SiteBridgeRequestRegistry();\n const attachToolPort = (data: unknown, ports: readonly MessagePort[]) => {\n const port = openGeniSiteBridgePortFromBootstrap(data, ports);\n if (!port) return;\n requests.addPort(port);\n port.addEventListener(\"message\", (portEvent: MessageEvent<unknown>) => {\n const message = portEvent.data;\n if (isOpenGeniSiteBridgeCancelMessage(message)) {\n requests.cancel(port, message.requestId);\n return;\n }\n if (isSiteHttpRequest(message) && portEvent.ports.length === 1) {\n const controller = requests.start(port, message.requestId);\n if (!controller) {\n portEvent.ports[0]!.close();\n return;\n }\n void serveSiteHttp(\n message,\n portEvent.ports[0]!,\n async (request, signal) => {\n const fetch = bridgeRef.current?.fetch;\n if (!fetch) throw new Error(\"This Site host does not support the session SDK\");\n return fetch(request, signal);\n },\n controller.signal,\n ).finally(() => requests.complete(port, message.requestId, controller));\n return;\n }\n if (!isOpenGeniSiteBridgeRequestMessage(message)) return;\n const controller = requests.start(port, message.requestId);\n if (!controller) {\n port.postMessage({\n type: OPENGENI_SITE_BRIDGE_RESPONSE,\n version: OPENGENI_SITE_BRIDGE_VERSION,\n requestId: message.requestId,\n ok: false,\n error: {\n code: \"duplicate_request_id\",\n message: \"A Site tool request with this id is already running\",\n retryable: false,\n },\n } satisfies OpenGeniSiteBridgeResponseMessage);\n return;\n }\n void handleSiteBridgeRequest(bridgeRef.current, message, controller.signal)\n .then((value) => {\n if (!controller.signal.aborted) {\n port.postMessage({\n type: OPENGENI_SITE_BRIDGE_RESPONSE,\n version: OPENGENI_SITE_BRIDGE_VERSION,\n requestId: message.requestId,\n ok: true,\n value,\n } satisfies OpenGeniSiteBridgeResponseMessage);\n }\n })\n .catch((error) => {\n if (!controller.signal.aborted) {\n port.postMessage({\n type: OPENGENI_SITE_BRIDGE_RESPONSE,\n version: OPENGENI_SITE_BRIDGE_VERSION,\n requestId: message.requestId,\n ok: false,\n error: siteBridgeError(error),\n } satisfies OpenGeniSiteBridgeResponseMessage);\n }\n })\n .finally(() => requests.complete(port, message.requestId, controller));\n });\n port.addEventListener(\"messageerror\", () => requests.closePort(port));\n port.start();\n port.postMessage({\n type: OPENGENI_SITE_BRIDGE_READY,\n version: OPENGENI_SITE_BRIDGE_VERSION,\n });\n };\n const documentLease = new SiteBridgeDocumentLease(attachToolPort, () => requests.closeAll());\n const onFrameLoad = () => {\n frameLoadPendingRef.current = false;\n const frameWindow = frameRef.current?.contentWindow ?? null;\n if (!frameWindow) return;\n documentLease.load(frameWindow);\n };\n onFrameLoadRef.current = onFrameLoad;\n if (frameLoadPendingRef.current) {\n frameLoadPendingRef.current = false;\n onFrameLoad();\n }\n return () => {\n onFrameLoadRef.current = () => undefined;\n documentLease.close();\n };\n }, [props.html, toolBridgeEnabled]);\n return (\n <iframe\n ref={frameRef}\n title={props.title}\n sandbox={PUBLISHED_HTML_ARTIFACT_IFRAME_SANDBOX}\n referrerPolicy=\"no-referrer\"\n srcDoc={publishedHtmlArtifactDocument(props.html, toolBridgeEnabled)}\n onLoad={() => {\n frameLoadPendingRef.current = true;\n onFrameLoadRef.current();\n }}\n className={props.className}\n style={props.style}\n />\n );\n}\n\nexport class SiteBridgeRequestRegistry {\n private readonly controllersByPort = new Map<MessagePort, Map<string, AbortController>>();\n\n addPort(port: MessagePort): void {\n // Several SDK clients may share one document bootstrap. Document teardown,\n // not another client connecting, revokes all of that document's ports.\n if (!this.controllersByPort.has(port)) this.controllersByPort.set(port, new Map());\n }\n\n start(port: MessagePort, requestId: string): AbortController | null {\n const controllers = this.controllersByPort.get(port);\n if (!controllers || controllers.has(requestId)) return null;\n const controller = new AbortController();\n controllers.set(requestId, controller);\n return controller;\n }\n\n cancel(port: MessagePort, requestId: string): void {\n const controllers = this.controllersByPort.get(port);\n const controller = controllers?.get(requestId);\n if (!controller) return;\n controller.abort(new Error(\"Site tool request cancelled\"));\n controllers!.delete(requestId);\n }\n\n complete(port: MessagePort, requestId: string, controller: AbortController): void {\n const controllers = this.controllersByPort.get(port);\n if (controllers?.get(requestId) === controller) controllers.delete(requestId);\n }\n\n closePort(port: MessagePort): void {\n const controllers = this.controllersByPort.get(port);\n if (!controllers) return;\n for (const controller of controllers.values()) {\n controller.abort(new Error(\"Site tool bridge port closed\"));\n }\n controllers.clear();\n this.controllersByPort.delete(port);\n port.close();\n }\n\n closeAll(): void {\n for (const port of [...this.controllersByPort.keys()]) this.closePort(port);\n }\n}\n\nexport class SiteBridgeDocumentLease {\n private loaded = false;\n private bootstrapPort: MessagePort | null = null;\n\n constructor(\n private readonly attachToolPort: (data: unknown, ports: readonly MessagePort[]) => void,\n private readonly closeActivePorts: () => void,\n private readonly createMessageChannel: () => MessageChannel = () => new MessageChannel(),\n ) {}\n\n load(frameWindow: Pick<Window, \"postMessage\">): boolean {\n if (this.loaded) {\n this.close();\n return false;\n }\n this.loaded = true;\n const channel = this.createMessageChannel();\n this.bootstrapPort = channel.port1;\n channel.port1.addEventListener(\"message\", (event: MessageEvent<unknown>) => {\n this.attachToolPort(event.data, event.ports);\n });\n channel.port1.start();\n frameWindow.postMessage(\n {\n type: OPENGENI_SITE_BRIDGE_READY,\n version: OPENGENI_SITE_BRIDGE_VERSION,\n },\n \"*\",\n [channel.port2],\n );\n return true;\n }\n\n close(): void {\n this.bootstrapPort?.close();\n this.bootstrapPort = null;\n this.closeActivePorts();\n }\n}\n\nexport function openGeniSiteBridgePortFromBootstrap(\n data: unknown,\n ports: readonly MessagePort[],\n): MessagePort | null {\n if (!isOpenGeniSiteBridgeConnectMessage(data)) return null;\n return ports.length === 1 ? ports[0]! : null;\n}\n\nasync function handleSiteBridgeRequest(\n bridge: PublishedHtmlArtifactToolBridge | undefined,\n message: Parameters<typeof isOpenGeniSiteBridgeRequestMessage>[0] & {\n method: \"catalog\" | \"call\" | \"declarations\";\n requestId: string;\n payload?: ToolGatewayCallRequest;\n },\n signal: AbortSignal,\n): Promise<OpenGeniSiteToolCatalog | ToolGatewayCallResponse | ToolGatewayDeclarationsResponse> {\n if (!bridge) throw new Error(\"Site tool bridge is unavailable\");\n if (message.method === \"catalog\") return await bridge.catalog({ signal });\n if (message.method === \"declarations\") {\n if (!bridge.declarations) throw new Error(\"Site tool declarations are unavailable\");\n return await bridge.declarations({ signal });\n }\n return await bridge.call(sanitizeOpenGeniSiteToolCallRequest(message.payload!), { signal });\n}\n\nexport function siteBridgeError(error: unknown): {\n code: string;\n message: string;\n retryable: boolean;\n outcomeUnknown: boolean;\n} {\n const candidate = error as {\n code?: unknown;\n message?: unknown;\n retryable?: unknown;\n outcomeUnknown?: unknown;\n };\n return {\n code: typeof candidate?.code === \"string\" ? candidate.code : \"site_tool_call_failed\",\n message:\n typeof candidate?.message === \"string\" ? candidate.message : \"Site tool request failed\",\n retryable: candidate?.retryable === true,\n outcomeUnknown: candidate?.outcomeUnknown === true,\n };\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAMP,SAAS,WAAW,cAAkC;AA6KlD;AA3KG,IAAM,yCAAyC;AAAA,EACpD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,EAAE,KAAK,G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