@roomle/embedding-lib 0.0.0-dev-ec00289 → 0.0.0-dev-2e65be5
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/THIRD-PARTY-NOTICES.txt +2 -2
- package/ai.d.ts +2 -0
- package/ai.js +60 -0
- package/ai.min.js +58 -0
- package/chat-model-DKlWonm6.mjs +322 -0
- package/chat-model-gyIajfDW.mjs +327 -0
- package/{comlink-Dc3LZUoi.mjs → comlink-BYqErFai.mjs} +87 -77
- package/{comlink-Cmiqa2s0.mjs → comlink-m82YLjsS.mjs} +29 -22
- package/configurator.js +1 -1
- package/configurator.min.js +1 -1
- package/{dist-XEy6Tk_Y.mjs → dist-6TznX-Ae.mjs} +1657 -1484
- package/{dist-B9yy8ym8.mjs → dist-BsVeWZ8R.mjs} +1 -1
- package/{dist-Bb2L1Zel.mjs → dist-CjIZv2gB.mjs} +1 -1
- package/{dist-5jYYtT4q.mjs → dist-Cmx_tCV5.mjs} +1 -1
- package/{dist-C5fKJXpB.mjs → dist-CnTUCpLZ.mjs} +1 -1
- package/{dist-GTk8ppiK.mjs → dist-Cxe4osFc.mjs} +1 -1
- package/{dist-DJtonrDM.mjs → dist-D0XFfKEL.mjs} +3081 -2908
- package/{dist-Bo3WzRdf.mjs → dist-DCzWWudD.mjs} +1 -1
- package/{drag-ghost-yXe7c8jA.mjs → drag-ghost-B24KVqgc.mjs} +1 -1
- package/{drag-ghost-D7FnWbO4.mjs → drag-ghost-C1WS2KmW.mjs} +1 -1
- package/{drag-in-t7T6Pqwc.mjs → drag-in-CWHSbwvG.mjs} +3 -3
- package/{drag-in-BiEe2Lgv.mjs → drag-in-O5uwMddL.mjs} +3 -3
- package/embedding-plugins.js +1 -1
- package/embedding-plugins.min.js +1 -1
- package/fence.d.ts +2 -0
- package/fence.js +58 -0
- package/fence.min.js +56 -0
- package/{from-custom-view-CTBapIc6.mjs → from-custom-view-BgmiWIEN.mjs} +3 -3
- package/{from-custom-view-xbjgsLll.mjs → from-custom-view-CxmIIsHU.mjs} +3 -3
- package/{from-website-JwG7Ic_U.mjs → from-website-B8qFEG_R.mjs} +3 -3
- package/{from-website-DUPMQPl6.mjs → from-website-CvcnHmr2.mjs} +3 -3
- package/hi.js +81 -63
- package/hi.min.js +70 -52
- package/package.json +15 -1
- package/packages/embedding-lib/src/ai.d.ts +28 -0
- package/packages/embedding-lib/src/construction-agent/construction-mcp-tools.d.ts +10 -0
- package/packages/embedding-lib/src/construction-agent/construction-planning-assistant.d.ts +7 -0
- package/packages/embedding-lib/src/construction.d.ts +3 -0
- package/packages/embedding-lib/src/planning-assistant/chat-recovery.d.ts +1 -0
- package/packages/embedding-lib/src/planning-assistant/planning-assistant.d.ts +15 -0
- package/packages/embedding-lib/src/roomle-embedding-lib.d.ts +17 -0
- package/packages/web-sdk/packages/assistant.d.ts +3 -1
- package/packages/web-sdk/packages/common-core/src/planning-assistant/types.d.ts +5 -0
- package/roomle-embedding-lib.js +17 -4
- package/roomle-embedding-lib.min.js +17 -4
- package/sbom.cdx.json +5 -5
- package/mcp-tools-Cnhgobge.mjs +0 -153
- package/mcp-tools-D3Ei3Apu.mjs +0 -151
- /package/{browser-D6As4Zxr.mjs → browser-BjtSrqbu.mjs} +0 -0
- /package/{browser-zrjtYpL8.mjs → browser-D6M-d6y5.mjs} +0 -0
- /package/{dist-CXemOs84.mjs → dist-BI_3AeI-.mjs} +0 -0
- /package/{dist-CqpDM10w.mjs → dist-CGgFMwb1.mjs} +0 -0
- /package/{dist-CqP0aX0A.mjs → dist-CZbrRF4T.mjs} +0 -0
- /package/{dist-D0kh4WfT.mjs → dist-Dr3LcjP6.mjs} +0 -0
- /package/{dist-COgAdYY1.mjs → dist-Ur4DqwwC.mjs} +0 -0
- /package/{dist-D5HdKuwj.mjs → dist-wPZpiGiu.mjs} +0 -0
- /package/{experimental-evaluation-D56MbtjO.mjs → experimental-evaluation-DPkDk-5A.mjs} +0 -0
- /package/{experimental-evaluation-BgWFolud.mjs → experimental-evaluation-DyONuPyk.mjs} +0 -0
- /package/{utils-CAAGdgk8.mjs → utils-BoELtcEK.mjs} +0 -0
- /package/{utils-WeolMfC5.mjs → utils-BwWn6Fw4.mjs} +0 -0
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
|
|
2
|
+
import { _n as e } from "./dist-BV-32IEX.mjs";
|
|
3
|
+
//#region packages/web-sdk/packages/common-core/src/planning-assistant/chat-model.ts
|
|
4
|
+
var t = "The images of this result follow in the next message.", n = (e) => e.flatMap((e) => {
|
|
5
|
+
if (e.role !== "tool") return [e];
|
|
6
|
+
let n = [], r = e.content.map((e) => {
|
|
7
|
+
if (e.type !== "tool-result" || e.output.type !== "content") return e;
|
|
8
|
+
let r = e.output.value.filter((e) => e.type === "file");
|
|
9
|
+
return r.length ? (n.push(...r), {
|
|
10
|
+
...e,
|
|
11
|
+
output: {
|
|
12
|
+
...e.output,
|
|
13
|
+
value: [...e.output.value.filter((e) => e.type !== "file"), {
|
|
14
|
+
type: "text",
|
|
15
|
+
text: t
|
|
16
|
+
}]
|
|
17
|
+
}
|
|
18
|
+
}) : e;
|
|
19
|
+
});
|
|
20
|
+
return n.length ? [{
|
|
21
|
+
...e,
|
|
22
|
+
content: r
|
|
23
|
+
}, {
|
|
24
|
+
role: "user",
|
|
25
|
+
content: n
|
|
26
|
+
}] : [e];
|
|
27
|
+
}), r = (e) => ({
|
|
28
|
+
specificationVersion: e.specificationVersion,
|
|
29
|
+
provider: e.provider,
|
|
30
|
+
modelId: e.modelId,
|
|
31
|
+
supportedUrls: e.supportedUrls,
|
|
32
|
+
doGenerate: (t) => e.doGenerate({
|
|
33
|
+
...t,
|
|
34
|
+
prompt: n(t.prompt)
|
|
35
|
+
}),
|
|
36
|
+
doStream: (t) => e.doStream({
|
|
37
|
+
...t,
|
|
38
|
+
prompt: n(t.prompt)
|
|
39
|
+
})
|
|
40
|
+
}), i = async ({ provider: e, model: t, apiKey: n, baseUrl: i, headers: a, chatCompletions: o, responses: s, reasoningEffort: c }, l) => {
|
|
41
|
+
let u = l ? { fetch: new Proxy(fetch, { apply: async (e, t, n) => (typeof n[1]?.body == "string" && await l(n[1].body), fetch(...n)) }) } : {};
|
|
42
|
+
switch (e) {
|
|
43
|
+
case "openai": {
|
|
44
|
+
let { createOpenAI: e } = await import("./dist-Cxe4osFc.mjs");
|
|
45
|
+
return { languageModel: e({
|
|
46
|
+
apiKey: n,
|
|
47
|
+
...u
|
|
48
|
+
})(t) };
|
|
49
|
+
}
|
|
50
|
+
case "azure": {
|
|
51
|
+
let { createAzure: e } = await import("./dist-Dr3LcjP6.mjs"), r = e({
|
|
52
|
+
apiKey: n,
|
|
53
|
+
baseURL: i,
|
|
54
|
+
...u
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
languageModel: o ? r.chat(t) : r(t),
|
|
58
|
+
providerOptions: c ? { azure: { reasoningEffort: c } } : void 0
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
case "openai-compatible": {
|
|
62
|
+
if (!i) throw Error("The provider \"openai-compatible\" needs a baseUrl");
|
|
63
|
+
if (s) {
|
|
64
|
+
let { createOpenAI: e } = await import("./dist-Cxe4osFc.mjs"), r = {
|
|
65
|
+
...!n && !a?.Authorization ? { Authorization: void 0 } : {},
|
|
66
|
+
...a
|
|
67
|
+
};
|
|
68
|
+
return {
|
|
69
|
+
languageModel: e({
|
|
70
|
+
baseURL: i,
|
|
71
|
+
apiKey: n ?? "none",
|
|
72
|
+
headers: r,
|
|
73
|
+
...u
|
|
74
|
+
}).responses(t),
|
|
75
|
+
providerOptions: { openai: {
|
|
76
|
+
store: !1,
|
|
77
|
+
forceReasoning: !0
|
|
78
|
+
} }
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
let { createOpenAICompatible: e } = await import("./dist-wPZpiGiu.mjs");
|
|
82
|
+
return { languageModel: r(e({
|
|
83
|
+
name: "openai-compatible",
|
|
84
|
+
baseURL: i,
|
|
85
|
+
apiKey: n,
|
|
86
|
+
headers: a,
|
|
87
|
+
includeUsage: !0,
|
|
88
|
+
...u
|
|
89
|
+
})(t)) };
|
|
90
|
+
}
|
|
91
|
+
case "mistral": {
|
|
92
|
+
let { createMistral: e } = await import("./dist-CZbrRF4T.mjs");
|
|
93
|
+
return { languageModel: r(e({
|
|
94
|
+
apiKey: n,
|
|
95
|
+
...u
|
|
96
|
+
})(t)) };
|
|
97
|
+
}
|
|
98
|
+
case "anthropic": {
|
|
99
|
+
let { createAnthropic: e } = await import("./dist-CnTUCpLZ.mjs");
|
|
100
|
+
return { languageModel: e({
|
|
101
|
+
apiKey: n,
|
|
102
|
+
headers: { "anthropic-dangerous-direct-browser-access": "true" },
|
|
103
|
+
...u
|
|
104
|
+
})(t) };
|
|
105
|
+
}
|
|
106
|
+
case "google": {
|
|
107
|
+
let { createGoogleGenerativeAI: e } = await import("./dist-DCzWWudD.mjs");
|
|
108
|
+
return { languageModel: e({
|
|
109
|
+
apiKey: n,
|
|
110
|
+
...u
|
|
111
|
+
})(t) };
|
|
112
|
+
}
|
|
113
|
+
default: throw Error(`Unknown provider "${e}" - supported: azure, openai, openai-compatible, mistral, anthropic, google`);
|
|
114
|
+
}
|
|
115
|
+
}, a = ({ output: e }) => ({
|
|
116
|
+
type: "content",
|
|
117
|
+
value: e.content.map((e) => e.type === "text" ? {
|
|
118
|
+
type: "text",
|
|
119
|
+
text: e.text
|
|
120
|
+
} : {
|
|
121
|
+
type: "file",
|
|
122
|
+
mediaType: e.mimeType,
|
|
123
|
+
data: {
|
|
124
|
+
type: "data",
|
|
125
|
+
data: e.data
|
|
126
|
+
}
|
|
127
|
+
})
|
|
128
|
+
}), o = (e, t, n) => Object.fromEntries(e.map(({ name: e, description: r, inputSchema: i, annotations: o }) => {
|
|
129
|
+
let s = () => i;
|
|
130
|
+
return [e, {
|
|
131
|
+
type: "dynamic",
|
|
132
|
+
...o && { annotations: o },
|
|
133
|
+
description: r,
|
|
134
|
+
inputSchema: { "~standard": {
|
|
135
|
+
version: 1,
|
|
136
|
+
vendor: n,
|
|
137
|
+
validate: (e) => ({ value: e }),
|
|
138
|
+
jsonSchema: {
|
|
139
|
+
input: s,
|
|
140
|
+
output: s
|
|
141
|
+
}
|
|
142
|
+
} },
|
|
143
|
+
execute: (n) => t(e, n).catch((e) => ({
|
|
144
|
+
content: [{
|
|
145
|
+
type: "text",
|
|
146
|
+
text: e instanceof Error ? e.message : String(e)
|
|
147
|
+
}],
|
|
148
|
+
isError: !0
|
|
149
|
+
})),
|
|
150
|
+
toModelOutput: a
|
|
151
|
+
}];
|
|
152
|
+
})), s = (e = {}) => ({
|
|
153
|
+
inputTokens: e.inputTokens ?? null,
|
|
154
|
+
outputTokens: e.outputTokens ?? null,
|
|
155
|
+
totalTokens: e.totalTokens ?? (e.inputTokens !== void 0 && e.outputTokens !== void 0 ? e.inputTokens + e.outputTokens : null)
|
|
156
|
+
}), c = (e) => e.some((e) => e !== null) ? e.reduce((e, t) => e + (t ?? 0), 0) : null, l = async (t, n, r, a, o) => {
|
|
157
|
+
let l = await Promise.all([
|
|
158
|
+
import("./dist-6TznX-Ae.mjs").then((e) => e.t),
|
|
159
|
+
i(t),
|
|
160
|
+
a()
|
|
161
|
+
]);
|
|
162
|
+
n.throwIfAborted();
|
|
163
|
+
let [{ streamText: u, stepCountIs: d }, f, { prompts: p, tools: m }] = l, h = [];
|
|
164
|
+
return async ({ text: i, images: a }) => {
|
|
165
|
+
let l = [], g, _ = !1, v = {
|
|
166
|
+
role: "user",
|
|
167
|
+
content: [{
|
|
168
|
+
type: "text",
|
|
169
|
+
text: i || p.imagePrompt
|
|
170
|
+
}, ...a.map((e) => ({
|
|
171
|
+
type: "file",
|
|
172
|
+
data: e,
|
|
173
|
+
mediaType: "image/jpeg"
|
|
174
|
+
}))]
|
|
175
|
+
}, y = o?.recovery(m), b = new AbortController(), x = () => b.abort(n.reason);
|
|
176
|
+
n.addEventListener("abort", x, { once: !0 }), n.aborted && x();
|
|
177
|
+
let S = o ? setTimeout(() => b.abort(/* @__PURE__ */ Error("The assistant turn exceeded five minutes.")), o.timeoutMs) : void 0;
|
|
178
|
+
try {
|
|
179
|
+
let e = u({
|
|
180
|
+
model: f.languageModel,
|
|
181
|
+
providerOptions: f.providerOptions,
|
|
182
|
+
instructions: p.systemPrompt,
|
|
183
|
+
messages: [...h, v],
|
|
184
|
+
tools: y?.tools ?? m,
|
|
185
|
+
stopWhen: d(16),
|
|
186
|
+
abortSignal: o ? b.signal : n,
|
|
187
|
+
prepareStep: ({ stepNumber: e }) => e === 15 ? { toolChoice: "none" } : void 0
|
|
188
|
+
});
|
|
189
|
+
for await (let t of e.stream) if (t.type === "text-delta") r({
|
|
190
|
+
type: "text",
|
|
191
|
+
text: t.text
|
|
192
|
+
});
|
|
193
|
+
else if (t.type === "tool-call") r({
|
|
194
|
+
type: "activity",
|
|
195
|
+
text: t.toolName
|
|
196
|
+
});
|
|
197
|
+
else if (t.type === "error") throw t.error;
|
|
198
|
+
else if (t.type === "finish-step") l.push(s(t.usage));
|
|
199
|
+
else if (t.type === "finish") g = s(t.totalUsage);
|
|
200
|
+
else if (t.type === "abort" && (_ = !0, o)) throw b.signal.reason ?? /* @__PURE__ */ Error("Turn aborted");
|
|
201
|
+
if (o && b.signal.aborted) throw b.signal.reason;
|
|
202
|
+
h.push(v, ...await e.responseMessages), r({ type: "done" });
|
|
203
|
+
} catch (t) {
|
|
204
|
+
let n = y?.summary();
|
|
205
|
+
n && h.push(v, {
|
|
206
|
+
role: "assistant",
|
|
207
|
+
content: n
|
|
208
|
+
}), r({
|
|
209
|
+
type: "error",
|
|
210
|
+
...e.isInstance(t) && { statusCode: t.statusCode },
|
|
211
|
+
text: `The planning assistant failed: ${t instanceof Error ? t.message : String(t)}${n ? `\n\n${n}` : ""}`
|
|
212
|
+
});
|
|
213
|
+
} finally {
|
|
214
|
+
clearTimeout(S), n.removeEventListener("abort", x);
|
|
215
|
+
let e = {
|
|
216
|
+
inputTokens: g?.inputTokens ?? c(l.map((e) => e.inputTokens)),
|
|
217
|
+
outputTokens: g?.outputTokens ?? c(l.map((e) => e.outputTokens)),
|
|
218
|
+
totalTokens: g?.totalTokens ?? c(l.map((e) => e.totalTokens))
|
|
219
|
+
}, r = Object.values(e).some((e) => e !== null), i = g && !_ && !b.signal.aborted && Object.values(e).every((e) => e !== null) && l.every((e) => Object.values(e).every((e) => e !== null));
|
|
220
|
+
console.log(`[planning-assistant] usage ${JSON.stringify({
|
|
221
|
+
provider: t.provider,
|
|
222
|
+
model: t.model,
|
|
223
|
+
status: r ? i ? "complete" : "partial" : "unavailable",
|
|
224
|
+
...e
|
|
225
|
+
})}`);
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
}, u = {
|
|
229
|
+
undo: "Undo",
|
|
230
|
+
redo: "Redo",
|
|
231
|
+
"change-component-parameter": "Component parameter change",
|
|
232
|
+
"change-global-parameter": "Global parameter change",
|
|
233
|
+
"dock-component": "Component dock",
|
|
234
|
+
"drag-component": "Component drag",
|
|
235
|
+
"delete-component": "Component deletion",
|
|
236
|
+
"load-configuration": "Configuration load",
|
|
237
|
+
"get-configurator-capabilities": "Capabilities read",
|
|
238
|
+
"get-configuration": "Configuration read",
|
|
239
|
+
"get-component-parameters": "Component parameters read",
|
|
240
|
+
"get-global-parameters": "Global parameters read",
|
|
241
|
+
"get-possible-children": "Possible children read",
|
|
242
|
+
"get-docking-positions": "Docking positions read",
|
|
243
|
+
"get-component-docking-positions": "Component docking positions read",
|
|
244
|
+
"get-delete-impact": "Delete impact read"
|
|
245
|
+
}, d = new Set(Object.keys(u).filter((e) => e.startsWith("get-"))), f = (e) => {
|
|
246
|
+
if (e instanceof Error) return e.message;
|
|
247
|
+
try {
|
|
248
|
+
return typeof e == "string" ? e : JSON.stringify(e) ?? String(e);
|
|
249
|
+
} catch {
|
|
250
|
+
return Object.prototype.toString.call(e);
|
|
251
|
+
}
|
|
252
|
+
}, p = (e) => {
|
|
253
|
+
if (e?.structuredContent !== void 0) return e.structuredContent;
|
|
254
|
+
let t = e?.content?.filter((e) => e.type === "text").map((e) => e.text).join("\n");
|
|
255
|
+
if (t === void 0) return e;
|
|
256
|
+
try {
|
|
257
|
+
return JSON.parse(t);
|
|
258
|
+
} catch {
|
|
259
|
+
return t;
|
|
260
|
+
}
|
|
261
|
+
}, m = (e) => {
|
|
262
|
+
if (!e || typeof e != "object") return e == null ? [] : [f(e)];
|
|
263
|
+
let t = [];
|
|
264
|
+
for (let n of [
|
|
265
|
+
"applied",
|
|
266
|
+
"undone",
|
|
267
|
+
"redone",
|
|
268
|
+
"confirmed",
|
|
269
|
+
"canUndo",
|
|
270
|
+
"canRedo"
|
|
271
|
+
]) e[n] !== void 0 && t.push(`${n}: ${f(e[n])}`);
|
|
272
|
+
return e.hint && t.push(f(e.hint)), t;
|
|
273
|
+
}, h = (e, t = {
|
|
274
|
+
subject: "configuration",
|
|
275
|
+
readTools: d
|
|
276
|
+
}) => {
|
|
277
|
+
let n = [];
|
|
278
|
+
return {
|
|
279
|
+
tools: Object.fromEntries(Object.entries(e).map(([e, t]) => {
|
|
280
|
+
if (!t.execute) return [e, t];
|
|
281
|
+
let r = t.execute.bind(t);
|
|
282
|
+
return [e, {
|
|
283
|
+
...t,
|
|
284
|
+
execute: async (t) => {
|
|
285
|
+
let i = {
|
|
286
|
+
toolName: e,
|
|
287
|
+
status: "pending"
|
|
288
|
+
};
|
|
289
|
+
n.push(i);
|
|
290
|
+
try {
|
|
291
|
+
let e = await r(t);
|
|
292
|
+
return i.result = e, i.status = "returned", e;
|
|
293
|
+
} catch (e) {
|
|
294
|
+
throw i.error = e, i.status = "threw", e;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}];
|
|
298
|
+
})),
|
|
299
|
+
summary: () => {
|
|
300
|
+
let e = ["The assistant's reply was interrupted. Any text above is incomplete."];
|
|
301
|
+
if (!n.length) return e.push(`No tool ran, so the ${t.subject} was not changed.`), e.join("\n\n");
|
|
302
|
+
for (let r of n) {
|
|
303
|
+
let n = u[r.toolName] ?? r.toolName;
|
|
304
|
+
if (t.readTools.has(r.toolName)) {
|
|
305
|
+
let i = r.status === "returned" && !r.result?.isError, a = i ? p(r.result) : void 0;
|
|
306
|
+
e.push(i ? `- Completed ${n}: ${a?.complete === !1 ? "some requested information was unresolved" : "information was returned"}. The read did not change the ${t.subject}.` : `- Incomplete ${n}: ${r.status === "pending" ? "no result was received" : "the read failed"}. The read did not change the ${t.subject}.`);
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
if (r.status === "returned" && !r.result?.isError) {
|
|
310
|
+
let i = p(r.result);
|
|
311
|
+
if (i?.confirmed === !1) {
|
|
312
|
+
e.push(`- Unconfirmed ${n}: ${i?.hint ?? i?.unresolved?.join(" ") ?? `the SDK did not confirm the ${t.subject} change`}. Check the ${t.subject} before trying this operation again.`);
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
let a = m(i);
|
|
316
|
+
e.push(`- Completed ${n}: ${a.length ? a.join("; ") : "the tool returned successfully."}`);
|
|
317
|
+
} else {
|
|
318
|
+
let i = r.status === "threw" ? f(r.error) : r.status === "returned" ? f(p(r.result)) : "no result was received";
|
|
319
|
+
e.push(`- Unconfirmed ${n}: ${i}. Check the ${t.subject} before trying this operation again.`);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return e.push("These are the recorded tool outcomes; no operation was repeated automatically."), e.join("\n\n");
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
};
|
|
326
|
+
//#endregion
|
|
327
|
+
export { i, l as n, o as r, h as t };
|
|
@@ -5,19 +5,7 @@ var e = Symbol("Comlink.proxy"), t = Symbol("Comlink.endpoint"), n = Symbol("Com
|
|
|
5
5
|
let { port1: t, port2: n } = new MessageChannel();
|
|
6
6
|
return s(e, t), [n, [n]];
|
|
7
7
|
},
|
|
8
|
-
deserialize: (e) => (e.start(),
|
|
9
|
-
let t = /* @__PURE__ */ new Map();
|
|
10
|
-
return e.addEventListener("message", function(e) {
|
|
11
|
-
let { data: n } = e;
|
|
12
|
-
if (!n || !n.id) return;
|
|
13
|
-
let r = t.get(n.id);
|
|
14
|
-
if (r) try {
|
|
15
|
-
r(n);
|
|
16
|
-
} finally {
|
|
17
|
-
t.delete(n.id);
|
|
18
|
-
}
|
|
19
|
-
}), p(e, t, [], void 0);
|
|
20
|
-
}(e))
|
|
8
|
+
deserialize: (e) => (e.start(), l(e))
|
|
21
9
|
}], ["throw", {
|
|
22
10
|
canHandle: (e) => a(e) && i in e,
|
|
23
11
|
serialize({ value: e }) {
|
|
@@ -38,142 +26,164 @@ var e = Symbol("Comlink.proxy"), t = Symbol("Comlink.endpoint"), n = Symbol("Com
|
|
|
38
26
|
throw e.isError ? Object.assign(Error(e.value.message), e.value) : e.value;
|
|
39
27
|
}
|
|
40
28
|
}]]);
|
|
41
|
-
function s(
|
|
42
|
-
|
|
43
|
-
if (!
|
|
29
|
+
function s(e, t = globalThis, n = ["*"]) {
|
|
30
|
+
t.addEventListener("message", function a(o) {
|
|
31
|
+
if (!o || !o.data || !function(e, t) {
|
|
44
32
|
for (let n of e) if (t === n || n === "*" || n instanceof RegExp && n.test(t)) return !0;
|
|
45
33
|
return !1;
|
|
46
|
-
}(
|
|
47
|
-
let { id:
|
|
34
|
+
}(n, o.origin)) return;
|
|
35
|
+
let { id: l, type: u, path: d } = Object.assign({ path: [] }, o.data), f = (o.data.argumentList || []).map(x), p;
|
|
48
36
|
try {
|
|
49
|
-
let
|
|
50
|
-
switch (
|
|
37
|
+
let t = d.slice(0, -1).reduce((e, t) => e[t], e), n = d.reduce((e, t) => e[t], e);
|
|
38
|
+
switch (u) {
|
|
51
39
|
case "GET":
|
|
52
|
-
|
|
40
|
+
p = n;
|
|
53
41
|
break;
|
|
54
42
|
case "SET":
|
|
55
|
-
|
|
43
|
+
t[d.slice(-1)[0]] = x(o.data.value), p = !0;
|
|
56
44
|
break;
|
|
57
45
|
case "APPLY":
|
|
58
|
-
|
|
46
|
+
p = n.apply(t, f);
|
|
59
47
|
break;
|
|
60
48
|
case "CONSTRUCT":
|
|
61
|
-
|
|
62
|
-
return Object.assign(t, { [e]: !0 });
|
|
63
|
-
}(new r(...p));
|
|
49
|
+
p = v(new n(...f));
|
|
64
50
|
break;
|
|
65
51
|
case "ENDPOINT":
|
|
66
52
|
{
|
|
67
|
-
let { port1:
|
|
68
|
-
s(
|
|
69
|
-
return h.set(e, t), e;
|
|
70
|
-
}(e, [e]);
|
|
53
|
+
let { port1: t, port2: n } = new MessageChannel();
|
|
54
|
+
s(e, n), p = _(t, [t]);
|
|
71
55
|
}
|
|
72
56
|
break;
|
|
73
57
|
case "RELEASE":
|
|
74
|
-
|
|
58
|
+
p = void 0;
|
|
75
59
|
break;
|
|
76
60
|
default: return;
|
|
77
61
|
}
|
|
78
62
|
} catch (e) {
|
|
79
|
-
|
|
63
|
+
p = {
|
|
80
64
|
value: e,
|
|
81
65
|
[i]: 0
|
|
82
66
|
};
|
|
83
67
|
}
|
|
84
|
-
Promise.resolve(
|
|
68
|
+
Promise.resolve(p).catch((e) => ({
|
|
85
69
|
value: e,
|
|
86
70
|
[i]: 0
|
|
87
|
-
})).then((
|
|
88
|
-
let [i,
|
|
89
|
-
|
|
71
|
+
})).then((n) => {
|
|
72
|
+
let [i, o] = b(n);
|
|
73
|
+
t.postMessage(Object.assign(Object.assign({}, i), { id: l }), o), u === "RELEASE" && (t.removeEventListener("message", a), c(t), r in e && typeof e[r] == "function" && e[r]());
|
|
90
74
|
}).catch((e) => {
|
|
91
|
-
let [
|
|
75
|
+
let [n, r] = b({
|
|
92
76
|
value: /* @__PURE__ */ TypeError("Unserializable return value"),
|
|
93
77
|
[i]: 0
|
|
94
78
|
});
|
|
95
|
-
|
|
79
|
+
t.postMessage(Object.assign(Object.assign({}, n), { id: l }), r);
|
|
96
80
|
});
|
|
97
|
-
}),
|
|
81
|
+
}), t.start && t.start();
|
|
98
82
|
}
|
|
99
83
|
function c(e) {
|
|
100
84
|
(function(e) {
|
|
101
85
|
return e.constructor.name === "MessagePort";
|
|
102
86
|
})(e) && e.close();
|
|
103
87
|
}
|
|
104
|
-
function l(e) {
|
|
105
|
-
|
|
88
|
+
function l(e, t) {
|
|
89
|
+
let n = /* @__PURE__ */ new Map();
|
|
90
|
+
return e.addEventListener("message", function(e) {
|
|
91
|
+
let { data: t } = e;
|
|
92
|
+
if (!t || !t.id) return;
|
|
93
|
+
let r = n.get(t.id);
|
|
94
|
+
if (r) try {
|
|
95
|
+
r(t);
|
|
96
|
+
} finally {
|
|
97
|
+
n.delete(t.id);
|
|
98
|
+
}
|
|
99
|
+
}), m(e, n, [], t);
|
|
106
100
|
}
|
|
107
101
|
function u(e) {
|
|
108
|
-
|
|
102
|
+
if (e) throw Error("Proxy has been released and is not useable");
|
|
103
|
+
}
|
|
104
|
+
function d(e) {
|
|
105
|
+
return S(e, /* @__PURE__ */ new Map(), { type: "RELEASE" }).then(() => {
|
|
109
106
|
c(e);
|
|
110
107
|
});
|
|
111
108
|
}
|
|
112
|
-
var
|
|
113
|
-
let t = (
|
|
114
|
-
|
|
109
|
+
var f = /* @__PURE__ */ new WeakMap(), p = "FinalizationRegistry" in globalThis && new FinalizationRegistry((e) => {
|
|
110
|
+
let t = (f.get(e) || 0) - 1;
|
|
111
|
+
f.set(e, t), t === 0 && d(e);
|
|
115
112
|
});
|
|
116
|
-
function
|
|
113
|
+
function m(e, r, i = [], a = function() {}) {
|
|
117
114
|
let o = !1, s = new Proxy(a, {
|
|
118
115
|
get(t, a) {
|
|
119
|
-
if (
|
|
116
|
+
if (u(o), a === n) return () => {
|
|
120
117
|
(function(e) {
|
|
121
|
-
|
|
122
|
-
})(s),
|
|
118
|
+
p && p.unregister(e);
|
|
119
|
+
})(s), d(e), r.clear(), o = !0;
|
|
123
120
|
};
|
|
124
121
|
if (a === "then") {
|
|
125
122
|
if (i.length === 0) return { then: () => s };
|
|
126
|
-
let t =
|
|
123
|
+
let t = S(e, r, {
|
|
127
124
|
type: "GET",
|
|
128
125
|
path: i.map((e) => e.toString())
|
|
129
|
-
}).then(
|
|
126
|
+
}).then(x);
|
|
130
127
|
return t.then.bind(t);
|
|
131
128
|
}
|
|
132
|
-
return
|
|
129
|
+
return m(e, r, [...i, a]);
|
|
133
130
|
},
|
|
134
131
|
set(t, n, a) {
|
|
135
|
-
|
|
136
|
-
let [s, c] =
|
|
137
|
-
return
|
|
132
|
+
u(o);
|
|
133
|
+
let [s, c] = b(a);
|
|
134
|
+
return S(e, r, {
|
|
138
135
|
type: "SET",
|
|
139
136
|
path: [...i, n].map((e) => e.toString()),
|
|
140
137
|
value: s
|
|
141
|
-
}, c).then(
|
|
138
|
+
}, c).then(x);
|
|
142
139
|
},
|
|
143
140
|
apply(n, a, s) {
|
|
144
|
-
|
|
141
|
+
u(o);
|
|
145
142
|
let c = i[i.length - 1];
|
|
146
|
-
if (c === t) return
|
|
147
|
-
if (c === "bind") return
|
|
148
|
-
let [
|
|
149
|
-
return
|
|
143
|
+
if (c === t) return S(e, r, { type: "ENDPOINT" }).then(x);
|
|
144
|
+
if (c === "bind") return m(e, r, i.slice(0, -1));
|
|
145
|
+
let [l, d] = h(s);
|
|
146
|
+
return S(e, r, {
|
|
150
147
|
type: "APPLY",
|
|
151
148
|
path: i.map((e) => e.toString()),
|
|
152
|
-
argumentList:
|
|
153
|
-
}, d).then(
|
|
149
|
+
argumentList: l
|
|
150
|
+
}, d).then(x);
|
|
154
151
|
},
|
|
155
152
|
construct(t, n) {
|
|
156
|
-
|
|
157
|
-
let [a, s] =
|
|
158
|
-
return
|
|
153
|
+
u(o);
|
|
154
|
+
let [a, s] = h(n);
|
|
155
|
+
return S(e, r, {
|
|
159
156
|
type: "CONSTRUCT",
|
|
160
157
|
path: i.map((e) => e.toString()),
|
|
161
158
|
argumentList: a
|
|
162
|
-
}, s).then(
|
|
159
|
+
}, s).then(x);
|
|
163
160
|
}
|
|
164
161
|
});
|
|
165
162
|
return function(e, t) {
|
|
166
|
-
let n = (
|
|
167
|
-
|
|
163
|
+
let n = (f.get(t) || 0) + 1;
|
|
164
|
+
f.set(t, n), p && p.register(e, t, e);
|
|
168
165
|
}(s, e), s;
|
|
169
166
|
}
|
|
170
|
-
function
|
|
171
|
-
let t = e.map(
|
|
167
|
+
function h(e) {
|
|
168
|
+
let t = e.map(b);
|
|
172
169
|
return [t.map((e) => e[0]), (n = t.map((e) => e[1]), Array.prototype.concat.apply([], n))];
|
|
173
170
|
var n;
|
|
174
171
|
}
|
|
175
|
-
var
|
|
176
|
-
function
|
|
172
|
+
var g = /* @__PURE__ */ new WeakMap();
|
|
173
|
+
function _(e, t) {
|
|
174
|
+
return g.set(e, t), e;
|
|
175
|
+
}
|
|
176
|
+
function v(t) {
|
|
177
|
+
return Object.assign(t, { [e]: !0 });
|
|
178
|
+
}
|
|
179
|
+
function y(e, t = globalThis, n = "*") {
|
|
180
|
+
return {
|
|
181
|
+
postMessage: (t, r) => e.postMessage(t, n, r),
|
|
182
|
+
addEventListener: t.addEventListener.bind(t),
|
|
183
|
+
removeEventListener: t.removeEventListener.bind(t)
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
function b(e) {
|
|
177
187
|
for (let [t, n] of o) if (n.canHandle(e)) {
|
|
178
188
|
let [r, i] = n.serialize(e);
|
|
179
189
|
return [{
|
|
@@ -185,15 +195,15 @@ function g(e) {
|
|
|
185
195
|
return [{
|
|
186
196
|
type: "RAW",
|
|
187
197
|
value: e
|
|
188
|
-
},
|
|
198
|
+
}, g.get(e) || []];
|
|
189
199
|
}
|
|
190
|
-
function
|
|
200
|
+
function x(e) {
|
|
191
201
|
switch (e.type) {
|
|
192
202
|
case "HANDLER": return o.get(e.name).deserialize(e.value);
|
|
193
203
|
case "RAW": return e.value;
|
|
194
204
|
}
|
|
195
205
|
}
|
|
196
|
-
function
|
|
206
|
+
function S(e, t, n, r) {
|
|
197
207
|
return new Promise((i) => {
|
|
198
208
|
let a = [
|
|
199
209
|
,
|
|
@@ -204,4 +214,4 @@ function v(e, t, n, r) {
|
|
|
204
214
|
t.set(a, i), e.start && e.start(), e.postMessage(Object.assign({ id: a }, n), r);
|
|
205
215
|
});
|
|
206
216
|
}
|
|
207
|
-
export { s as expose };
|
|
217
|
+
export { t as createEndpoint, s as expose, r as finalizer, v as proxy, e as proxyMarker, n as releaseProxy, _ as transfer, o as transferHandlers, y as windowEndpoint, l as wrap };
|