@opengeni/sdk 0.57.0 → 1.0.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.
- package/README.md +1017 -26
- package/dist/accounts.d.ts +153 -0
- package/dist/accounts.js +307 -0
- package/dist/accounts.js.map +1 -0
- package/dist/adapters/express.d.ts +31 -0
- package/dist/adapters/express.js +87 -0
- package/dist/adapters/express.js.map +1 -0
- package/dist/adapters/hono.d.ts +16 -0
- package/dist/adapters/hono.js +8 -0
- package/dist/adapters/hono.js.map +1 -0
- package/dist/adapters/next.d.ts +29 -0
- package/dist/adapters/next.js +22 -0
- package/dist/adapters/next.js.map +1 -0
- package/dist/allowance-refusal.d.ts +2 -0
- package/dist/allowance-refusal.js +50 -0
- package/dist/allowance-refusal.js.map +1 -0
- package/dist/artifact-catalog.d.ts +31 -0
- package/dist/artifact-client.d.ts +23 -11
- package/dist/artifacts.d.ts +1 -1
- package/dist/artifacts.js +7 -5
- package/dist/automations-client.d.ts +17 -0
- package/dist/automations.d.ts +3 -0
- package/dist/automations.js +84 -0
- package/dist/automations.js.map +1 -0
- package/dist/browser.d.ts +11 -0
- package/dist/browser.js +47 -0
- package/dist/browser.js.map +1 -0
- package/dist/chat/fold.d.ts +75 -0
- package/dist/chat/handler.d.ts +41 -0
- package/dist/chat/http.d.ts +67 -0
- package/dist/chat/ids.d.ts +34 -0
- package/dist/chat/index.d.ts +9 -0
- package/dist/chat/index.js +1694 -0
- package/dist/chat/index.js.map +1 -0
- package/dist/chat/openai.d.ts +30 -0
- package/dist/chat/opengeni.d.ts +128 -0
- package/dist/chat/types.d.ts +207 -0
- package/dist/chat/vercel.d.ts +49 -0
- package/dist/chats.d.ts +8 -0
- package/dist/{chunk-JDLDDRNE.js → chunk-2UXZUCEZ.js} +291 -34
- package/dist/chunk-2UXZUCEZ.js.map +1 -0
- package/dist/chunk-4SMEOV3P.js +246 -0
- package/dist/chunk-4SMEOV3P.js.map +1 -0
- package/dist/{chunk-JRPFWI6T.js → chunk-AH5D5Q5V.js} +31 -35
- package/dist/chunk-AH5D5Q5V.js.map +1 -0
- package/dist/chunk-APXVSSSY.js +301 -0
- package/dist/chunk-APXVSSSY.js.map +1 -0
- package/dist/chunk-DUVIYER4.js +639 -0
- package/dist/chunk-DUVIYER4.js.map +1 -0
- package/dist/{chunk-PKQ377ED.js → chunk-FG3OO5LM.js} +2686 -611
- package/dist/chunk-FG3OO5LM.js.map +1 -0
- package/dist/chunk-GZYZT22T.js +260 -0
- package/dist/chunk-GZYZT22T.js.map +1 -0
- package/dist/chunk-HMGADJGZ.js +150 -0
- package/dist/chunk-HMGADJGZ.js.map +1 -0
- package/dist/{chunk-YKZME56C.js → chunk-KWADQ227.js} +3 -3
- package/dist/{chunk-YKZME56C.js.map → chunk-KWADQ227.js.map} +1 -1
- package/dist/chunk-LY2K6ELJ.js +126 -0
- package/dist/chunk-LY2K6ELJ.js.map +1 -0
- package/dist/chunk-MOTJYIYL.js +340 -0
- package/dist/chunk-MOTJYIYL.js.map +1 -0
- package/dist/{chunk-ST5DDKJP.js → chunk-NC57YMUO.js} +121 -3
- package/dist/chunk-NC57YMUO.js.map +1 -0
- package/dist/chunk-RWKB6YZG.js +1270 -0
- package/dist/chunk-RWKB6YZG.js.map +1 -0
- package/dist/chunk-U6CV2SXO.js +195 -0
- package/dist/chunk-U6CV2SXO.js.map +1 -0
- package/dist/chunk-UM4ZXXJR.js +9 -0
- package/dist/chunk-UM4ZXXJR.js.map +1 -0
- package/dist/chunk-V6GIY62B.js +229 -0
- package/dist/chunk-V6GIY62B.js.map +1 -0
- package/dist/chunk-WU6GQG25.js +268 -0
- package/dist/chunk-WU6GQG25.js.map +1 -0
- package/dist/{chunk-VWE2QIVO.js → chunk-XNG7YGR3.js} +23 -6
- package/dist/chunk-XNG7YGR3.js.map +1 -0
- package/dist/{chunk-HJ3HHUT5.js → chunk-YIKA2QT4.js} +33 -2
- package/dist/chunk-YIKA2QT4.js.map +1 -0
- package/dist/chunk-ZKPY6YAJ.js +135 -0
- package/dist/chunk-ZKPY6YAJ.js.map +1 -0
- package/dist/client.d.ts +740 -94
- package/dist/codex-realtime-controller.d.ts +3 -0
- package/dist/codex-realtime-controller.js +2 -2
- package/dist/codex-realtime-v3.d.ts +13 -2
- package/dist/company-brain.d.ts +22 -0
- package/dist/company-profile.d.ts +14 -1
- package/dist/core.d.ts +9 -3
- package/dist/core.js +25 -6
- package/dist/deprecation.d.ts +47 -0
- package/dist/document-authority-client.d.ts +51 -0
- package/dist/document-authority.d.ts +2 -0
- package/dist/document-authority.js +12 -0
- package/dist/document-authority.js.map +1 -0
- package/dist/editable-artifacts/browser-session.d.ts +7 -3
- package/dist/editable-artifacts/controller.d.ts +4 -1
- package/dist/editable-artifacts/errors.d.ts +1 -1
- package/dist/editable-artifacts/http-live-transport.d.ts +6 -2
- package/dist/editable-artifacts/index.d.ts +2 -0
- package/dist/editable-artifacts/open-failure.d.ts +9 -0
- package/dist/editable-artifacts/types.d.ts +6 -3
- package/dist/editable-artifacts/worker/kernel-adapter.d.ts +1 -1
- package/dist/editable-artifacts-worker.js +44 -17
- package/dist/editable-artifacts-worker.js.map +1 -1
- package/dist/editable-artifacts.js +240 -121
- package/dist/editable-artifacts.js.map +1 -1
- package/dist/embedding-client.d.ts +129 -0
- package/dist/errors.d.ts +36 -1
- package/dist/feedback.d.ts +23 -0
- package/dist/gateway-realtime-transport.js +1 -1
- package/dist/github-repositories.d.ts +10 -0
- package/dist/github-repositories.js +36 -0
- package/dist/github-repositories.js.map +1 -0
- package/dist/index.d.ts +56 -11
- package/dist/index.js +242 -125
- package/dist/index.js.map +1 -1
- package/dist/interaction.d.ts +84 -1
- package/dist/interaction.js +6 -1
- package/dist/knowledge.d.ts +7 -0
- package/dist/knowledge.js +20 -0
- package/dist/knowledge.js.map +1 -0
- package/dist/message-links.d.ts +68 -0
- package/dist/model-context.d.ts +68 -0
- package/dist/model-display.d.ts +2 -0
- package/dist/model-display.js +15 -0
- package/dist/model-display.js.map +1 -0
- package/dist/model-picker-order.d.ts +1 -0
- package/dist/model-picker-order.js +10 -0
- package/dist/model-picker-order.js.map +1 -0
- package/dist/organization-integration-policy.d.ts +26 -0
- package/dist/organization-integration-policy.js +26 -0
- package/dist/organization-integration-policy.js.map +1 -0
- package/dist/organization-private-session-settings.d.ts +6 -0
- package/dist/organization-private-session-settings.js +22 -0
- package/dist/organization-private-session-settings.js.map +1 -0
- package/dist/organization-user-setup.d.ts +8 -0
- package/dist/organization-user-setup.js +16 -0
- package/dist/organization-user-setup.js.map +1 -0
- package/dist/pr-review-client.d.ts +16 -0
- package/dist/pr-review.d.ts +4 -0
- package/dist/pr-review.js +62 -0
- package/dist/pr-review.js.map +1 -0
- package/dist/preference-registry.d.ts +9 -1
- package/dist/proxy.d.ts +7 -5
- package/dist/realtime.d.ts +3 -1
- package/dist/realtime.js +6 -6
- package/dist/realtime.js.map +1 -1
- package/dist/retained-artifacts.d.ts +5 -1
- package/dist/session-history-import.d.ts +22 -0
- package/dist/session-history-import.js +36 -0
- package/dist/session-history-import.js.map +1 -0
- package/dist/session-list-entries.d.ts +1 -0
- package/dist/session-list-entries.js +7 -0
- package/dist/session-list-entries.js.map +1 -0
- package/dist/session-message-search.d.ts +53 -0
- package/dist/session-proxy-client.d.ts +24 -0
- package/dist/session-proxy.d.ts +245 -0
- package/dist/session-proxy.js +24 -0
- package/dist/session-proxy.js.map +1 -0
- package/dist/session-titles.d.ts +2 -0
- package/dist/site-browser-entry.d.ts +1 -0
- package/dist/site-browser-runtime.gen.d.ts +1 -0
- package/dist/site-document.d.ts +5 -0
- package/dist/site-document.js +20 -0
- package/dist/site-document.js.map +1 -0
- package/dist/site-document.test.d.ts +1 -0
- package/dist/site-http.d.ts +16 -0
- package/dist/site-tool-bridge.d.ts +44 -0
- package/dist/site.d.ts +101 -0
- package/dist/site.js +49 -0
- package/dist/site.js.map +1 -0
- package/dist/skills.d.ts +75 -0
- package/dist/stream.d.ts +2 -0
- package/dist/tenant-workspaces.d.ts +47 -0
- package/dist/tenant-workspaces.js +8 -0
- package/dist/tenant-workspaces.js.map +1 -0
- package/dist/tool-auth.d.ts +87 -0
- package/dist/tool-auth.js +23 -0
- package/dist/tool-auth.js.map +1 -0
- package/dist/tool-display-metadata.d.ts +3 -0
- package/dist/tools-FXBLUWAE.js +12 -0
- package/dist/tools-FXBLUWAE.js.map +1 -0
- package/dist/tools.d.ts +61 -0
- package/dist/types.d.ts +2863 -424
- package/dist/usage-allowances.d.ts +36 -0
- package/dist/usage-allowances.js +80 -0
- package/dist/usage-allowances.js.map +1 -0
- package/dist/workspace-artifacts.d.ts +33 -5
- package/dist/workspace-instruction-policies.d.ts +24 -2
- package/dist/workspace-integrations.d.ts +74 -0
- package/dist/workspace-integrations.js +65 -0
- package/dist/workspace-integrations.js.map +1 -0
- package/dist/workspace-learning.d.ts +124 -0
- package/dist/workspace-state.d.ts +8 -71
- package/package.json +108 -3
- package/src/accounts.ts +443 -0
- package/src/adapters/express.ts +136 -0
- package/src/adapters/hono.ts +18 -0
- package/src/adapters/next.ts +42 -0
- package/src/allowance-refusal.ts +5 -0
- package/src/artifact-catalog.ts +41 -0
- package/src/artifact-client.ts +43 -52
- package/src/artifacts.ts +7 -1
- package/src/automations-client.ts +124 -0
- package/src/automations.ts +15 -0
- package/src/browser.ts +54 -0
- package/src/chat/fold.ts +431 -0
- package/src/chat/handler.ts +240 -0
- package/src/chat/http.ts +257 -0
- package/src/chat/ids.ts +85 -0
- package/src/chat/index.ts +87 -0
- package/src/chat/openai.ts +439 -0
- package/src/chat/opengeni.ts +722 -0
- package/src/chat/types.ts +219 -0
- package/src/chat/vercel.ts +204 -0
- package/src/chats.ts +16 -0
- package/src/client.ts +4084 -515
- package/src/codex-realtime-controller.ts +235 -5
- package/src/codex-realtime-v3.ts +162 -31
- package/src/codex-realtime.ts +1 -1
- package/src/company-brain.ts +59 -0
- package/src/company-profile.ts +17 -1
- package/src/core.ts +23 -1
- package/src/deprecation.ts +149 -0
- package/src/document-authority-client.ts +219 -0
- package/src/document-authority.ts +17 -0
- package/src/editable-artifacts/browser-session.ts +36 -22
- package/src/editable-artifacts/controller.ts +102 -47
- package/src/editable-artifacts/errors.ts +2 -0
- package/src/editable-artifacts/http-live-transport.ts +62 -37
- package/src/editable-artifacts/index.ts +6 -0
- package/src/editable-artifacts/open-failure.ts +79 -0
- package/src/editable-artifacts/storage.ts +31 -40
- package/src/editable-artifacts/types.ts +6 -3
- package/src/editable-artifacts/worker/kernel-adapter.ts +23 -7
- package/src/editable-artifacts/worker/runtime.ts +26 -13
- package/src/editable-artifacts/worker/wire-codec.ts +23 -5
- package/src/embedding-client.ts +519 -0
- package/src/errors.ts +169 -2
- package/src/feedback.ts +20 -0
- package/src/gateway-realtime-transport.ts +3 -3
- package/src/github-repositories.ts +60 -0
- package/src/index.ts +561 -41
- package/src/interaction.ts +276 -4
- package/src/knowledge.ts +72 -0
- package/src/message-links.ts +178 -0
- package/src/model-context.ts +112 -0
- package/src/model-display.ts +10 -0
- package/src/model-picker-order.ts +6 -0
- package/src/organization-integration-policy.ts +54 -0
- package/src/organization-private-session-settings.ts +33 -0
- package/src/organization-user-setup.ts +31 -0
- package/src/pr-review-client.ts +92 -0
- package/src/pr-review.ts +17 -0
- package/src/preference-registry.ts +11 -0
- package/src/proxy.ts +17 -6
- package/src/realtime.ts +1 -0
- package/src/retained-artifacts.ts +101 -0
- package/src/session-history-import.ts +84 -0
- package/src/session-list-entries.ts +1 -0
- package/src/session-message-search.ts +47 -0
- package/src/session-proxy-client.ts +64 -0
- package/src/session-proxy.ts +1473 -0
- package/src/session-titles.ts +10 -0
- package/src/site-browser-entry.ts +6 -0
- package/src/site-browser-runtime.gen.ts +2 -0
- package/src/site-document.test.ts +64 -0
- package/src/site-document.ts +18 -0
- package/src/site-http.ts +162 -0
- package/src/site-tool-bridge.ts +146 -0
- package/src/site.ts +585 -0
- package/src/skills.ts +69 -0
- package/src/sse.ts +8 -2
- package/src/stream.ts +38 -4
- package/src/tenant-workspaces.ts +148 -0
- package/src/tool-auth.ts +301 -0
- package/src/tool-display-metadata.ts +19 -0
- package/src/tools.ts +396 -0
- package/src/types.ts +3346 -501
- package/src/usage-allowances.ts +189 -0
- package/src/workspace-artifacts.ts +40 -6
- package/src/workspace-instruction-policies.ts +26 -1
- package/src/workspace-integrations.ts +402 -0
- package/src/workspace-learning.ts +138 -0
- package/src/workspace-state.ts +8 -82
- package/dist/chunk-GU6JF75T.js +0 -119
- package/dist/chunk-GU6JF75T.js.map +0 -1
- package/dist/chunk-HJ3HHUT5.js.map +0 -1
- package/dist/chunk-JDLDDRNE.js.map +0 -1
- package/dist/chunk-JRPFWI6T.js.map +0 -1
- package/dist/chunk-PKQ377ED.js.map +0 -1
- package/dist/chunk-ST5DDKJP.js.map +0 -1
- package/dist/chunk-VWE2QIVO.js.map +0 -1
|
@@ -0,0 +1,639 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OpenGeniToolsClient
|
|
3
|
+
} from "./chunk-4SMEOV3P.js";
|
|
4
|
+
import {
|
|
5
|
+
OpenGeniClient
|
|
6
|
+
} from "./chunk-FG3OO5LM.js";
|
|
7
|
+
import {
|
|
8
|
+
OpenGeniApiError
|
|
9
|
+
} from "./chunk-V6GIY62B.js";
|
|
10
|
+
|
|
11
|
+
// ../contracts/src/site-session-http.ts
|
|
12
|
+
var SITE_WORKSPACE_PREFIX = "/v1/workspaces/site-host";
|
|
13
|
+
var SiteSessionPathError = class extends Error {
|
|
14
|
+
code = "site_session_path_unsupported";
|
|
15
|
+
constructor() {
|
|
16
|
+
super("Unsupported Site session API path");
|
|
17
|
+
this.name = "SiteSessionPathError";
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
function siteSessionPath(path, workspaceId, _method = "GET", siteId) {
|
|
21
|
+
const pathname = path.split("?")[0];
|
|
22
|
+
const workspace = pathname === SITE_WORKSPACE_PREFIX || pathname.startsWith(`${SITE_WORKSPACE_PREFIX}/`);
|
|
23
|
+
const context = pathname === "/v1/config/client";
|
|
24
|
+
if (!workspace && !context || /[%\\#\u0000-\u0020\u007f]/u.test(pathname) || pathname.split("/").some((p) => p === "." || p === "..")) {
|
|
25
|
+
throw new SiteSessionPathError();
|
|
26
|
+
}
|
|
27
|
+
const rewritten = path.replace(
|
|
28
|
+
"/workspaces/site-host",
|
|
29
|
+
`/workspaces/${encodeURIComponent(workspaceId)}`
|
|
30
|
+
);
|
|
31
|
+
const url = new URL(rewritten, "http://site.invalid");
|
|
32
|
+
if (url.searchParams.get("originSiteId") === "current" && workspaceId !== "site-host") {
|
|
33
|
+
url.searchParams.set("originSiteId", siteId ?? "00000000-0000-0000-0000-000000000000");
|
|
34
|
+
return url.pathname + url.search;
|
|
35
|
+
}
|
|
36
|
+
return rewritten;
|
|
37
|
+
}
|
|
38
|
+
function siteRequestHeaders(input) {
|
|
39
|
+
const headers = new Headers(input);
|
|
40
|
+
const connectionHeaders = (headers.get("connection") ?? "").split(",").map((value) => value.trim().toLowerCase());
|
|
41
|
+
for (const name of [...headers.keys()]) {
|
|
42
|
+
if (connectionHeaders.includes(name) || /^(authorization|proxy-authorization|cookie|cookie2|host|origin|referer|connection|keep-alive|proxy-connection|te|trailer|transfer-encoding|upgrade|content-length|accept-encoding|forwarded|x-api-key)$/i.test(
|
|
43
|
+
name
|
|
44
|
+
) || /^(sec-|x-forwarded-|x-opengeni-(access-key|external-actor|site-|managed-actor))/i.test(name))
|
|
45
|
+
headers.delete(name);
|
|
46
|
+
}
|
|
47
|
+
return headers;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// src/site-http.ts
|
|
51
|
+
var SITE_HTTP = "opengeni.site.http";
|
|
52
|
+
var SITE_WORKSPACE = "site-host";
|
|
53
|
+
function isSiteHttpRequest(value) {
|
|
54
|
+
if (!value || typeof value !== "object") return false;
|
|
55
|
+
const v = value;
|
|
56
|
+
return v.type === SITE_HTTP && typeof v.requestId === "string" && typeof v.path === "string" && typeof v.method === "string" && /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/u.test(v.method) && (v.body === void 0 || typeof v.body === "string") && Array.isArray(v.headers) && v.headers.every(
|
|
57
|
+
(h) => Array.isArray(h) && h.length === 2 && h.every((x) => typeof x === "string")
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
async function serveSiteHttp(message, port, fetchResponse, signal) {
|
|
61
|
+
let reader;
|
|
62
|
+
let wake;
|
|
63
|
+
let pulling = false;
|
|
64
|
+
const onMessage = (event) => {
|
|
65
|
+
if (event.data === "pull") {
|
|
66
|
+
pulling = true;
|
|
67
|
+
wake?.();
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const abort = () => {
|
|
71
|
+
void reader?.cancel(signal.reason).catch(() => {
|
|
72
|
+
});
|
|
73
|
+
wake?.();
|
|
74
|
+
};
|
|
75
|
+
port.addEventListener("message", onMessage);
|
|
76
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
77
|
+
port.start();
|
|
78
|
+
try {
|
|
79
|
+
if (signal.aborted) throw signal.reason;
|
|
80
|
+
const response = await fetchResponse(message, signal);
|
|
81
|
+
reader = response.body?.getReader();
|
|
82
|
+
port.postMessage({ status: response.status, headers: [...response.headers], body: !!reader });
|
|
83
|
+
if (reader)
|
|
84
|
+
while (!signal.aborted) {
|
|
85
|
+
if (!pulling)
|
|
86
|
+
await new Promise((resolve) => {
|
|
87
|
+
wake = resolve;
|
|
88
|
+
});
|
|
89
|
+
wake = void 0;
|
|
90
|
+
if (signal.aborted) break;
|
|
91
|
+
pulling = false;
|
|
92
|
+
const part = await reader.read();
|
|
93
|
+
if (part.done) {
|
|
94
|
+
port.postMessage({ done: true });
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
port.postMessage({ chunk: part.value });
|
|
98
|
+
}
|
|
99
|
+
if (signal.aborted) throw signal.reason;
|
|
100
|
+
} catch (error) {
|
|
101
|
+
port.postMessage({ error: error instanceof Error ? error.message : "Site request failed" });
|
|
102
|
+
} finally {
|
|
103
|
+
signal.removeEventListener("abort", abort);
|
|
104
|
+
port.removeEventListener("message", onMessage);
|
|
105
|
+
await reader?.cancel().catch(() => {
|
|
106
|
+
});
|
|
107
|
+
port.close();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async function sitePortFetch(port, input, init) {
|
|
111
|
+
const request = new Request(input, init);
|
|
112
|
+
const url = new URL(request.url);
|
|
113
|
+
const path = `${url.pathname}${url.search}`;
|
|
114
|
+
siteSessionPath(path, SITE_WORKSPACE, request.method);
|
|
115
|
+
const channel = new MessageChannel();
|
|
116
|
+
const requestId = crypto.randomUUID();
|
|
117
|
+
const body = request.body ? await request.text() : void 0;
|
|
118
|
+
return await new Promise((resolve, reject) => {
|
|
119
|
+
let controller;
|
|
120
|
+
let finished = false;
|
|
121
|
+
const cleanup = () => {
|
|
122
|
+
finished = true;
|
|
123
|
+
request.signal.removeEventListener("abort", abort);
|
|
124
|
+
channel.port1.close();
|
|
125
|
+
};
|
|
126
|
+
const abort = () => {
|
|
127
|
+
if (finished) return;
|
|
128
|
+
port.postMessage({ type: "opengeni.site.cancel", version: 2, requestId });
|
|
129
|
+
const error = request.signal.reason ?? new DOMException("Cancelled", "AbortError");
|
|
130
|
+
controller?.error(error);
|
|
131
|
+
reject(error);
|
|
132
|
+
cleanup();
|
|
133
|
+
};
|
|
134
|
+
channel.port1.onmessage = (event) => {
|
|
135
|
+
const data = event.data;
|
|
136
|
+
if (data.error) {
|
|
137
|
+
const error = new Error(data.error);
|
|
138
|
+
controller?.error(error);
|
|
139
|
+
reject(error);
|
|
140
|
+
cleanup();
|
|
141
|
+
} else if (data.status) {
|
|
142
|
+
const stream = data.body ? new ReadableStream({
|
|
143
|
+
start(c) {
|
|
144
|
+
controller = c;
|
|
145
|
+
},
|
|
146
|
+
pull() {
|
|
147
|
+
channel.port1.postMessage("pull");
|
|
148
|
+
},
|
|
149
|
+
cancel() {
|
|
150
|
+
controller = void 0;
|
|
151
|
+
abort();
|
|
152
|
+
}
|
|
153
|
+
}) : null;
|
|
154
|
+
resolve(new Response(stream, { status: data.status, headers: data.headers }));
|
|
155
|
+
if (!data.body) cleanup();
|
|
156
|
+
} else if (data.done) {
|
|
157
|
+
controller?.close();
|
|
158
|
+
cleanup();
|
|
159
|
+
} else if (data.chunk) controller?.enqueue(data.chunk);
|
|
160
|
+
};
|
|
161
|
+
if (request.signal.aborted) {
|
|
162
|
+
abort();
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
request.signal.addEventListener("abort", abort, { once: true });
|
|
166
|
+
port.postMessage(
|
|
167
|
+
{
|
|
168
|
+
type: SITE_HTTP,
|
|
169
|
+
requestId,
|
|
170
|
+
path,
|
|
171
|
+
method: request.method,
|
|
172
|
+
headers: [...request.headers],
|
|
173
|
+
...body === void 0 ? {} : { body }
|
|
174
|
+
},
|
|
175
|
+
[channel.port2]
|
|
176
|
+
);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// src/site-tool-bridge.ts
|
|
181
|
+
function createSiteToolBridge(input) {
|
|
182
|
+
const allowed = input.requestedTools ? new Set(input.requestedTools.map(identityKey)) : null;
|
|
183
|
+
let projectedCatalog = null;
|
|
184
|
+
const loadCatalog = async ({
|
|
185
|
+
signal,
|
|
186
|
+
refresh = false
|
|
187
|
+
}) => {
|
|
188
|
+
signal.throwIfAborted();
|
|
189
|
+
if (projectedCatalog && !refresh) return projectedCatalog;
|
|
190
|
+
const current = await input.workspaceTools.$catalog({
|
|
191
|
+
signal,
|
|
192
|
+
...refresh ? { refresh } : {}
|
|
193
|
+
});
|
|
194
|
+
signal.throwIfAborted();
|
|
195
|
+
if (current.workspaceId !== input.workspaceId)
|
|
196
|
+
throw new Error("Site catalog workspace mismatch");
|
|
197
|
+
projectedCatalog = {
|
|
198
|
+
version: current.version,
|
|
199
|
+
generation: current.generation,
|
|
200
|
+
digest: current.digest,
|
|
201
|
+
createdAt: current.createdAt,
|
|
202
|
+
entries: current.entries.filter(
|
|
203
|
+
(entry) => !allowed || allowed.has(identityKey(entry.identity))
|
|
204
|
+
)
|
|
205
|
+
};
|
|
206
|
+
return projectedCatalog;
|
|
207
|
+
};
|
|
208
|
+
return {
|
|
209
|
+
...input.fetchResponse ? {
|
|
210
|
+
fetch: async (message, signal) => {
|
|
211
|
+
const path = siteSessionPath(
|
|
212
|
+
message.path,
|
|
213
|
+
input.workspaceId,
|
|
214
|
+
message.method,
|
|
215
|
+
input.artifactId
|
|
216
|
+
);
|
|
217
|
+
const headers = siteRequestHeaders(message.headers);
|
|
218
|
+
if (input.artifactId) {
|
|
219
|
+
headers.set("x-opengeni-site-id", input.artifactId);
|
|
220
|
+
headers.set("x-opengeni-site-version", input.siteVersionId);
|
|
221
|
+
}
|
|
222
|
+
return input.fetchResponse(path, {
|
|
223
|
+
method: message.method,
|
|
224
|
+
signal,
|
|
225
|
+
headers: Object.fromEntries(headers),
|
|
226
|
+
...message.body === void 0 ? {} : { body: message.body }
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
} : {},
|
|
230
|
+
catalog: loadCatalog,
|
|
231
|
+
call: async (request, { signal }) => {
|
|
232
|
+
if (allowed && !allowed.has(identityKey(request.identity)))
|
|
233
|
+
throw new Error("This tool is not available to the Site");
|
|
234
|
+
const call = async (refresh = false) => {
|
|
235
|
+
const catalog = await loadCatalog({ signal, refresh });
|
|
236
|
+
if (!catalog.entries.some(
|
|
237
|
+
(entry) => identityKey(entry.identity) === identityKey(request.identity)
|
|
238
|
+
))
|
|
239
|
+
throw new Error("This requested tool is not enabled in the workspace");
|
|
240
|
+
return input.callTool({
|
|
241
|
+
workspaceId: input.workspaceId,
|
|
242
|
+
signal,
|
|
243
|
+
request: {
|
|
244
|
+
...request.operationId ? { operationId: request.operationId } : {},
|
|
245
|
+
catalogDigest: catalog.digest,
|
|
246
|
+
identity: request.identity,
|
|
247
|
+
arguments: request.arguments,
|
|
248
|
+
...input.artifactId ? { siteArtifactId: input.artifactId, siteVersionId: input.siteVersionId } : {}
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
};
|
|
252
|
+
try {
|
|
253
|
+
return await call();
|
|
254
|
+
} catch (error) {
|
|
255
|
+
if (!(input.isCatalogStale ?? isSiteCatalogStaleError)(error)) throw error;
|
|
256
|
+
projectedCatalog = null;
|
|
257
|
+
return await call(true);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
function isSiteCatalogStaleError(error) {
|
|
263
|
+
return error instanceof OpenGeniApiError && error.status === 409 && error.details?.code === "catalog_stale";
|
|
264
|
+
}
|
|
265
|
+
function identityKey(identity) {
|
|
266
|
+
return `${identity.serverId}\0${identity.toolName}`;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// src/site.ts
|
|
270
|
+
var OPENGENI_SITE_BRIDGE_VERSION = 2;
|
|
271
|
+
var OPENGENI_SITE_BRIDGE_CONNECT = "opengeni.site.connect";
|
|
272
|
+
var OPENGENI_SITE_BRIDGE_READY = "opengeni.site.ready";
|
|
273
|
+
var OPENGENI_SITE_BRIDGE_REQUEST = "opengeni.site.request";
|
|
274
|
+
var OPENGENI_SITE_BRIDGE_RESPONSE = "opengeni.site.response";
|
|
275
|
+
var OPENGENI_SITE_BRIDGE_CANCEL = "opengeni.site.cancel";
|
|
276
|
+
var OPENGENI_SITE_BRIDGE_BOOTSTRAP_GLOBAL = "__opengeniSiteBridgeBootstrapV2";
|
|
277
|
+
var OPENGENI_SITE_LOCAL_CODEMODE_PATH = "/__opengeni/site-tools";
|
|
278
|
+
var OpenGeniSiteBridgeError = class extends Error {
|
|
279
|
+
constructor(code, message, retryable = false, outcomeUnknown = false) {
|
|
280
|
+
super(message);
|
|
281
|
+
this.code = code;
|
|
282
|
+
this.retryable = retryable;
|
|
283
|
+
this.outcomeUnknown = outcomeUnknown;
|
|
284
|
+
this.name = "OpenGeniSiteBridgeError";
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
function createOpenGeniSiteClient(options = {}) {
|
|
288
|
+
const transport = shouldUseLocalCodemode(options) ? new OpenGeniSiteLocalCodemodeTransport(options) : new OpenGeniSiteBridgeTransport(options);
|
|
289
|
+
return {
|
|
290
|
+
client: new OpenGeniClient({
|
|
291
|
+
baseUrl: "https://site.opengeni.invalid",
|
|
292
|
+
fetch: (input, init) => transport.fetch(input, init)
|
|
293
|
+
}),
|
|
294
|
+
workspaceId: SITE_WORKSPACE,
|
|
295
|
+
tools: new OpenGeniToolsClient(transport).forWorkspace("site-host"),
|
|
296
|
+
close: () => transport.close()
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
var OpenGeniSiteLocalCodemodeTransport = class {
|
|
300
|
+
fetchImpl;
|
|
301
|
+
basePath;
|
|
302
|
+
constructor(options) {
|
|
303
|
+
this.fetchImpl = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
304
|
+
const configured = options.localCodemodePath;
|
|
305
|
+
this.basePath = (typeof configured === "string" ? configured : OPENGENI_SITE_LOCAL_CODEMODE_PATH).replace(/\/+$/u, "");
|
|
306
|
+
}
|
|
307
|
+
close() {
|
|
308
|
+
}
|
|
309
|
+
async fetch(input, init) {
|
|
310
|
+
const request = new Request(input, init);
|
|
311
|
+
const url = new URL(request.url);
|
|
312
|
+
const path = `${url.pathname}${url.search}`;
|
|
313
|
+
siteSessionPath(path, SITE_WORKSPACE, request.method);
|
|
314
|
+
return this.fetchImpl(`${this.basePath}/sdk${path}`, {
|
|
315
|
+
method: request.method,
|
|
316
|
+
headers: request.headers,
|
|
317
|
+
signal: request.signal,
|
|
318
|
+
...request.body ? { body: await request.text() } : {}
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
async requestJson(method, path, body, _query, options = {}) {
|
|
322
|
+
const suffix = localCodemodeSuffix(method, path);
|
|
323
|
+
const response = await this.fetchImpl(`${this.basePath}${suffix}`, {
|
|
324
|
+
method,
|
|
325
|
+
...options.signal ? { signal: options.signal } : {},
|
|
326
|
+
...body === void 0 ? {} : {
|
|
327
|
+
headers: { "content-type": "application/json" },
|
|
328
|
+
body: JSON.stringify(body)
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
const value = await response.json();
|
|
332
|
+
if (response.ok) return value;
|
|
333
|
+
const envelope = isRecord(value) && isRecord(value.error) ? value.error : {};
|
|
334
|
+
throw new OpenGeniSiteBridgeError(
|
|
335
|
+
typeof envelope.code === "string" ? envelope.code : "local_codemode_error",
|
|
336
|
+
typeof envelope.message === "string" ? envelope.message : `Local Site tool request failed with HTTP ${response.status}`,
|
|
337
|
+
envelope.retryable === true,
|
|
338
|
+
envelope.outcomeUnknown === true
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
function shouldUseLocalCodemode(options) {
|
|
343
|
+
if (options.localCodemodePath === false || options.bootstrapPort) return false;
|
|
344
|
+
if (typeof options.localCodemodePath === "string") return true;
|
|
345
|
+
const siteWindow = options.siteWindow ?? globalThis.window;
|
|
346
|
+
return Boolean(siteWindow && siteWindow.parent === siteWindow);
|
|
347
|
+
}
|
|
348
|
+
function localCodemodeSuffix(method, path) {
|
|
349
|
+
if (method === "GET" && path.endsWith("/tools/catalog")) return "/catalog";
|
|
350
|
+
if (method === "GET" && path.endsWith("/tools/declarations")) return "/declarations";
|
|
351
|
+
if (method === "POST" && path.endsWith("/tools/calls")) return "/calls";
|
|
352
|
+
throw new OpenGeniSiteBridgeError("unsupported_request", "Unsupported Site tool request");
|
|
353
|
+
}
|
|
354
|
+
function isOpenGeniSiteBridgeConnectMessage(value) {
|
|
355
|
+
return isRecord(value) && value.type === OPENGENI_SITE_BRIDGE_CONNECT && value.version === OPENGENI_SITE_BRIDGE_VERSION;
|
|
356
|
+
}
|
|
357
|
+
function isOpenGeniSiteBridgeRequestMessage(value) {
|
|
358
|
+
if (!isRecord(value) || value.type !== OPENGENI_SITE_BRIDGE_REQUEST || value.version !== OPENGENI_SITE_BRIDGE_VERSION || typeof value.requestId !== "string" || !value.requestId) {
|
|
359
|
+
return false;
|
|
360
|
+
}
|
|
361
|
+
if (value.method === "catalog" || value.method === "declarations") return true;
|
|
362
|
+
return value.method === "call" && isRecord(value.payload);
|
|
363
|
+
}
|
|
364
|
+
function isOpenGeniSiteBridgeCancelMessage(value) {
|
|
365
|
+
return isRecord(value) && value.type === OPENGENI_SITE_BRIDGE_CANCEL && value.version === OPENGENI_SITE_BRIDGE_VERSION && typeof value.requestId === "string" && Boolean(value.requestId);
|
|
366
|
+
}
|
|
367
|
+
function sanitizeOpenGeniSiteToolCallRequest(value) {
|
|
368
|
+
return {
|
|
369
|
+
...value.operationId === void 0 ? {} : { operationId: value.operationId },
|
|
370
|
+
catalogDigest: value.catalogDigest,
|
|
371
|
+
identity: value.identity,
|
|
372
|
+
arguments: value.arguments
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
var OpenGeniSiteBridgeTransport = class {
|
|
376
|
+
options;
|
|
377
|
+
bootstrap;
|
|
378
|
+
port = null;
|
|
379
|
+
connecting = null;
|
|
380
|
+
closed = false;
|
|
381
|
+
constructor(options) {
|
|
382
|
+
this.options = options;
|
|
383
|
+
this.bootstrap = createSiteBridgeBootstrap(options);
|
|
384
|
+
}
|
|
385
|
+
async fetch(input, init) {
|
|
386
|
+
return sitePortFetch(await this.connect(), input, init);
|
|
387
|
+
}
|
|
388
|
+
async requestJson(method, path, body, _query, requestOptions = {}) {
|
|
389
|
+
if (method === "GET" && path.endsWith("/tools/catalog")) {
|
|
390
|
+
return await this.request({ method: "catalog" }, requestOptions);
|
|
391
|
+
}
|
|
392
|
+
if (method === "GET" && path.endsWith("/tools/declarations")) {
|
|
393
|
+
return await this.request({ method: "declarations" }, requestOptions);
|
|
394
|
+
}
|
|
395
|
+
if (method === "POST" && path.endsWith("/tools/calls")) {
|
|
396
|
+
if (!isRecord(body)) throw new TypeError("Site tool call payload is required");
|
|
397
|
+
return await this.request(
|
|
398
|
+
{
|
|
399
|
+
method: "call",
|
|
400
|
+
payload: sanitizeOpenGeniSiteToolCallRequest(body)
|
|
401
|
+
},
|
|
402
|
+
requestOptions
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
throw new OpenGeniSiteBridgeError("unsupported_request", "Unsupported Site bridge request");
|
|
406
|
+
}
|
|
407
|
+
close() {
|
|
408
|
+
if (this.closed) return;
|
|
409
|
+
this.closed = true;
|
|
410
|
+
this.bootstrap.close();
|
|
411
|
+
this.port?.close();
|
|
412
|
+
this.port = null;
|
|
413
|
+
}
|
|
414
|
+
async request(request, options) {
|
|
415
|
+
const port = await this.connect();
|
|
416
|
+
const requestId = crypto.randomUUID();
|
|
417
|
+
const timeoutMs = positiveTimeout(
|
|
418
|
+
options.timeoutMs ?? this.options.requestTimeoutMs ?? 12e4,
|
|
419
|
+
"requestTimeoutMs"
|
|
420
|
+
);
|
|
421
|
+
return await new Promise((resolve, reject) => {
|
|
422
|
+
const timeout = setTimeout(() => {
|
|
423
|
+
cleanup();
|
|
424
|
+
cancel(port, requestId);
|
|
425
|
+
reject(
|
|
426
|
+
request.method === "call" ? new OpenGeniSiteBridgeError(
|
|
427
|
+
"timeout",
|
|
428
|
+
"Site tool request timed out after execution may have started",
|
|
429
|
+
false,
|
|
430
|
+
true
|
|
431
|
+
) : new OpenGeniSiteBridgeError("timeout", "Site tool request timed out", true)
|
|
432
|
+
);
|
|
433
|
+
}, timeoutMs);
|
|
434
|
+
const abort = () => {
|
|
435
|
+
cleanup();
|
|
436
|
+
cancel(port, requestId);
|
|
437
|
+
reject(options.signal?.reason ?? new DOMException("Request aborted", "AbortError"));
|
|
438
|
+
};
|
|
439
|
+
const onMessage = (event) => {
|
|
440
|
+
const response = event.data;
|
|
441
|
+
if (!isRecord(response) || response.type !== OPENGENI_SITE_BRIDGE_RESPONSE || response.version !== OPENGENI_SITE_BRIDGE_VERSION || response.requestId !== requestId || typeof response.ok !== "boolean") {
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
cleanup();
|
|
445
|
+
if (response.ok) {
|
|
446
|
+
resolve(response.value);
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
const error = isRecord(response.error) ? response.error : {};
|
|
450
|
+
reject(
|
|
451
|
+
new OpenGeniSiteBridgeError(
|
|
452
|
+
typeof error.code === "string" ? error.code : "bridge_error",
|
|
453
|
+
typeof error.message === "string" ? error.message : "Site tool request failed",
|
|
454
|
+
error.retryable === true,
|
|
455
|
+
error.outcomeUnknown === true
|
|
456
|
+
)
|
|
457
|
+
);
|
|
458
|
+
};
|
|
459
|
+
const cleanup = () => {
|
|
460
|
+
clearTimeout(timeout);
|
|
461
|
+
options.signal?.removeEventListener("abort", abort);
|
|
462
|
+
port.removeEventListener("message", onMessage);
|
|
463
|
+
};
|
|
464
|
+
if (options.signal?.aborted) {
|
|
465
|
+
abort();
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
options.signal?.addEventListener("abort", abort, { once: true });
|
|
469
|
+
port.addEventListener("message", onMessage);
|
|
470
|
+
port.postMessage({
|
|
471
|
+
type: OPENGENI_SITE_BRIDGE_REQUEST,
|
|
472
|
+
version: OPENGENI_SITE_BRIDGE_VERSION,
|
|
473
|
+
requestId,
|
|
474
|
+
...request
|
|
475
|
+
});
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
async connect() {
|
|
479
|
+
if (this.closed) throw new OpenGeniSiteBridgeError("closed", "Site bridge is closed");
|
|
480
|
+
if (this.port) return this.port;
|
|
481
|
+
if (this.connecting) return await this.connecting;
|
|
482
|
+
const channel = (this.options.createMessageChannel ?? (() => new MessageChannel()))();
|
|
483
|
+
const timeoutMs = positiveTimeout(this.options.connectTimeoutMs ?? 1e4, "connectTimeoutMs");
|
|
484
|
+
this.connecting = new Promise((resolve, reject) => {
|
|
485
|
+
let active = true;
|
|
486
|
+
const timeout = setTimeout(() => {
|
|
487
|
+
cleanup();
|
|
488
|
+
channel.port1.close();
|
|
489
|
+
reject(new OpenGeniSiteBridgeError("host_timeout", "Opengeni Site host did not respond"));
|
|
490
|
+
}, timeoutMs);
|
|
491
|
+
const onMessage = (event) => {
|
|
492
|
+
const message = event.data;
|
|
493
|
+
if (!isRecord(message) || message.type !== OPENGENI_SITE_BRIDGE_READY || message.version !== OPENGENI_SITE_BRIDGE_VERSION) {
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
cleanup();
|
|
497
|
+
this.port = channel.port1;
|
|
498
|
+
resolve(channel.port1);
|
|
499
|
+
};
|
|
500
|
+
const cleanup = () => {
|
|
501
|
+
active = false;
|
|
502
|
+
clearTimeout(timeout);
|
|
503
|
+
channel.port1.removeEventListener("message", onMessage);
|
|
504
|
+
};
|
|
505
|
+
channel.port1.addEventListener("message", onMessage);
|
|
506
|
+
channel.port1.start();
|
|
507
|
+
void this.bootstrap.port().then((bootstrapPort) => {
|
|
508
|
+
if (!active) return;
|
|
509
|
+
if (this.closed) throw new OpenGeniSiteBridgeError("closed", "Site bridge is closed");
|
|
510
|
+
bootstrapPort.postMessage(
|
|
511
|
+
{
|
|
512
|
+
type: OPENGENI_SITE_BRIDGE_CONNECT,
|
|
513
|
+
version: OPENGENI_SITE_BRIDGE_VERSION
|
|
514
|
+
},
|
|
515
|
+
[channel.port2]
|
|
516
|
+
);
|
|
517
|
+
}).catch((error) => {
|
|
518
|
+
cleanup();
|
|
519
|
+
channel.port1.close();
|
|
520
|
+
reject(error);
|
|
521
|
+
});
|
|
522
|
+
}).finally(() => {
|
|
523
|
+
this.connecting = null;
|
|
524
|
+
});
|
|
525
|
+
return await this.connecting;
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
function createSiteBridgeBootstrap(options) {
|
|
529
|
+
if (options.bootstrapPort) {
|
|
530
|
+
return {
|
|
531
|
+
port: async () => options.bootstrapPort,
|
|
532
|
+
close: () => options.bootstrapPort?.close()
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
const siteWindow = options.siteWindow ?? globalThis.window;
|
|
536
|
+
const parentWindow = options.parentWindow ?? siteWindow?.parent;
|
|
537
|
+
if (!siteWindow || !parentWindow || parentWindow === siteWindow) {
|
|
538
|
+
return {
|
|
539
|
+
port: async () => {
|
|
540
|
+
throw new OpenGeniSiteBridgeError(
|
|
541
|
+
"host_unavailable",
|
|
542
|
+
"Opengeni Site client must run inside a hosted iframe"
|
|
543
|
+
);
|
|
544
|
+
},
|
|
545
|
+
close: () => void 0
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
const retainedPort = retainedSiteBridgeBootstrapPort(siteWindow);
|
|
549
|
+
if (retainedPort) {
|
|
550
|
+
return {
|
|
551
|
+
port: async () => retainedPort,
|
|
552
|
+
close: () => void 0
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
let settledPort = null;
|
|
556
|
+
let rejectBootstrap = null;
|
|
557
|
+
const onMessage = (event) => {
|
|
558
|
+
if (event.source !== parentWindow || !isOpenGeniSiteBridgeReadyMessage(event.data) || event.ports.length !== 1) {
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
cleanup();
|
|
562
|
+
settledPort = event.ports[0];
|
|
563
|
+
settledPort.start();
|
|
564
|
+
retainSiteBridgeBootstrapPort(siteWindow, settledPort);
|
|
565
|
+
resolveBootstrap?.(settledPort);
|
|
566
|
+
};
|
|
567
|
+
let resolveBootstrap = null;
|
|
568
|
+
const cleanup = () => siteWindow.removeEventListener("message", onMessage);
|
|
569
|
+
const port = new Promise((resolve, reject) => {
|
|
570
|
+
resolveBootstrap = resolve;
|
|
571
|
+
rejectBootstrap = reject;
|
|
572
|
+
siteWindow.addEventListener("message", onMessage);
|
|
573
|
+
});
|
|
574
|
+
void port.catch(() => void 0);
|
|
575
|
+
return {
|
|
576
|
+
port: async () => await port,
|
|
577
|
+
close: () => {
|
|
578
|
+
cleanup();
|
|
579
|
+
rejectBootstrap?.(new OpenGeniSiteBridgeError("closed", "Site bridge is closed"));
|
|
580
|
+
resolveBootstrap = null;
|
|
581
|
+
rejectBootstrap = null;
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
function retainedSiteBridgeBootstrapPort(siteWindow) {
|
|
586
|
+
const state = siteWindow[OPENGENI_SITE_BRIDGE_BOOTSTRAP_GLOBAL];
|
|
587
|
+
if (!isRecord(state)) return null;
|
|
588
|
+
const candidate = state.port;
|
|
589
|
+
return candidate && typeof candidate.postMessage === "function" && typeof candidate.addEventListener === "function" && typeof candidate.start === "function" ? candidate : null;
|
|
590
|
+
}
|
|
591
|
+
function retainSiteBridgeBootstrapPort(siteWindow, port) {
|
|
592
|
+
try {
|
|
593
|
+
Object.defineProperty(siteWindow, OPENGENI_SITE_BRIDGE_BOOTSTRAP_GLOBAL, {
|
|
594
|
+
configurable: true,
|
|
595
|
+
value: { port }
|
|
596
|
+
});
|
|
597
|
+
} catch {
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
function isOpenGeniSiteBridgeReadyMessage(value) {
|
|
601
|
+
return isRecord(value) && value.type === OPENGENI_SITE_BRIDGE_READY && value.version === OPENGENI_SITE_BRIDGE_VERSION;
|
|
602
|
+
}
|
|
603
|
+
function cancel(port, requestId) {
|
|
604
|
+
port.postMessage({
|
|
605
|
+
type: OPENGENI_SITE_BRIDGE_CANCEL,
|
|
606
|
+
version: OPENGENI_SITE_BRIDGE_VERSION,
|
|
607
|
+
requestId
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
function positiveTimeout(value, label) {
|
|
611
|
+
if (!Number.isFinite(value) || value <= 0) throw new RangeError(`${label} must be positive`);
|
|
612
|
+
return value;
|
|
613
|
+
}
|
|
614
|
+
function isRecord(value) {
|
|
615
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
export {
|
|
619
|
+
siteSessionPath,
|
|
620
|
+
isSiteHttpRequest,
|
|
621
|
+
serveSiteHttp,
|
|
622
|
+
createSiteToolBridge,
|
|
623
|
+
isSiteCatalogStaleError,
|
|
624
|
+
OPENGENI_SITE_BRIDGE_VERSION,
|
|
625
|
+
OPENGENI_SITE_BRIDGE_CONNECT,
|
|
626
|
+
OPENGENI_SITE_BRIDGE_READY,
|
|
627
|
+
OPENGENI_SITE_BRIDGE_REQUEST,
|
|
628
|
+
OPENGENI_SITE_BRIDGE_RESPONSE,
|
|
629
|
+
OPENGENI_SITE_BRIDGE_CANCEL,
|
|
630
|
+
OPENGENI_SITE_BRIDGE_BOOTSTRAP_GLOBAL,
|
|
631
|
+
OPENGENI_SITE_LOCAL_CODEMODE_PATH,
|
|
632
|
+
OpenGeniSiteBridgeError,
|
|
633
|
+
createOpenGeniSiteClient,
|
|
634
|
+
isOpenGeniSiteBridgeConnectMessage,
|
|
635
|
+
isOpenGeniSiteBridgeRequestMessage,
|
|
636
|
+
isOpenGeniSiteBridgeCancelMessage,
|
|
637
|
+
sanitizeOpenGeniSiteToolCallRequest
|
|
638
|
+
};
|
|
639
|
+
//# sourceMappingURL=chunk-DUVIYER4.js.map
|