@roomle/embedding-lib 0.0.0-dev-d66646c → 0.0.0-dev-f0a595f

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/hi.min.js CHANGED
@@ -1,14 +1,14 @@
1
1
  /*! Third-party licenses: THIRD-PARTY-NOTICES.txt and sbom.cdx.json in the root of this package */
2
2
  import { t as e } from "./utils-DdNhTbJr.mjs";
3
3
  import { t } from "./browser-CzLpXYFF.mjs";
4
- import { t as n } from "./mcp-tools-m_3IX0vB.mjs";
5
- import { i as r, l as i, n as a, r as o, s } from "./usage-CgXarvBY.mjs";
6
- import { n as c, r as l, t as u } from "./continuation-D2hsmYf1.mjs";
7
- import { t as d } from "./chat-model-DooKwd8I.mjs";
8
- var f = (e, t) => t === e.libraryId ? e : {
4
+ import { t as n } from "./chat-model-DooKwd8I.mjs";
5
+ import { t as r } from "./mcp-tools-m_3IX0vB.mjs";
6
+ import { t as i } from "./ai-model-host-BE_xdV6e.mjs";
7
+ import { o as a } from "./usage-C3HE9yXi.mjs";
8
+ var o = (e, t) => t === e.libraryId ? e : {
9
9
  ...e,
10
10
  libraryId: t
11
- }, p = async (e, t, n, r = { property: "default" }) => {
11
+ }, s = async (e, t, n, r = { property: "default" }) => {
12
12
  let i = n.serverOptions ?? {}, a = { headers: {
13
13
  "Content-Type": t === "json" ? "application/json" : "text/plain",
14
14
  "Access-Control-Allow-Origin": "*"
@@ -22,22 +22,22 @@ var f = (e, t) => t === e.libraryId ? e : {
22
22
  } catch (e) {
23
23
  throw e;
24
24
  }
25
- }, m = { "e2fe8b3d-da31-4a20-92ab-ab6e3839300e": /* @__PURE__ */ new Set(["Furniture_Smith"]) }, h = (e, t) => {
26
- m[e] || (m[e] = /* @__PURE__ */ new Set()), m[e].add(t);
27
- }, g = (e, t) => {
28
- m[e]?.delete(t), m[e]?.size === 0 && delete m[e];
29
- }, _ = (e, t) => {
25
+ }, c = { "e2fe8b3d-da31-4a20-92ab-ab6e3839300e": /* @__PURE__ */ new Set(["Furniture_Smith"]) }, l = (e, t) => {
26
+ c[e] || (c[e] = /* @__PURE__ */ new Set()), c[e].add(t);
27
+ }, u = (e, t) => {
28
+ c[e]?.delete(t), c[e]?.size === 0 && delete c[e];
29
+ }, d = (e, t) => {
30
30
  let { libraryId: n, serverOptions: r } = e;
31
- return r?.subscriptionId && m[r.subscriptionId]?.has(n) ? `api/pos/${t}?libraryId=${n}` : `api/pos/libraries/${n}/${t}`;
32
- }, v = async (e) => await (await p(_(e, "articles"), "json", e, { property: "articles" })).json(), y = async (e) => await (await p(_(e, "masterData"), "json", e, { property: "masterData" })).json(), b = async (e) => {
33
- let t = await (await p(_(e, "calc.js"), "text", e, { property: "calc.js" })).text();
31
+ return r?.subscriptionId && c[r.subscriptionId]?.has(n) ? `api/pos/${t}?libraryId=${n}` : `api/pos/libraries/${n}/${t}`;
32
+ }, f = async (e) => await (await s(d(e, "articles"), "json", e, { property: "articles" })).json(), p = async (e) => await (await s(d(e, "masterData"), "json", e, { property: "masterData" })).json(), m = async (e) => {
33
+ let t = await (await s(d(e, "calc.js"), "text", e, { property: "calc.js" })).text();
34
34
  if (!t) throw Error("Script load error");
35
35
  return t;
36
- }, x = (e) => ({
37
- onLoadJavascript: (t) => b(f(e, t)),
38
- onLoadArticleCatalog: (t) => v(f(e, t)),
39
- onLoadMasterData: (t) => y(f(e, t))
40
- }), S = async (e, t, n, r) => {
36
+ }, h = (e) => ({
37
+ onLoadJavascript: (t) => m(o(e, t)),
38
+ onLoadArticleCatalog: (t) => f(o(e, t)),
39
+ onLoadMasterData: (t) => p(o(e, t))
40
+ }), g = async (e, t, n, r) => {
41
41
  let { baseUrl: i, om: a } = e.serverOptions ?? {}, o = encodeURIComponent(a?.endpointUrl || ""), s = encodeURIComponent(a?.subscriptionId || ""), c = a?.key || "", l = await fetch((i ?? "https://europe-west3-rml-showcases.cloudfunctions.net/proxy_request?url=") + `${encodeURIComponent(t)}&subscriptionId=${s}&apiKey=${c}&baseUrl=${o}`, {
42
42
  ...n,
43
43
  headers: {
@@ -50,376 +50,75 @@ var f = (e, t) => t === e.libraryId ? e : {
50
50
  throw Error(`Order Manager request ${t} failed with ${e}${n ? `: ${n}` : ""}`);
51
51
  }
52
52
  return l.json();
53
- }, C = async (e, t, n, r = {}) => S(e, n, {
53
+ }, _ = async (e, t, n, r = {}) => g(e, n, {
54
54
  method: "POST",
55
55
  body: JSON.stringify(t)
56
- }, r), w = async (e, t, n = {}) => S(e, t, { method: "GET" }, n), T = null, E = async (n, r = {}) => {
57
- T && window.removeEventListener("message", T);
56
+ }, r), v = async (e, t, n = {}) => g(e, t, { method: "GET" }, n), y = null, b = async (n, r = {}) => {
57
+ y && window.removeEventListener("message", y);
58
58
  let i = typeof n == "string" ? { libraryId: n } : n;
59
- r.onLoadJavascript === void 0 && (r.onLoadJavascript = (e) => b(f(i, e))), r.onLoadArticleCatalog === void 0 && (r.onLoadArticleCatalog = (e) => v(f(i, e))), r.onLoadMasterData === void 0 && (r.onLoadMasterData = (e) => y(f(i, e)));
59
+ r.onLoadJavascript === void 0 && (r.onLoadJavascript = (e) => m(o(i, e))), r.onLoadArticleCatalog === void 0 && (r.onLoadArticleCatalog = (e) => f(o(i, e))), r.onLoadMasterData === void 0 && (r.onLoadMasterData = (e) => p(o(i, e)));
60
60
  let { expose: a } = await import("./comlink-DKhvPU0o.mjs");
61
- T = (n) => {
61
+ y = (n) => {
62
62
  if (n.data.type === "connect_hi" && n.data.port) {
63
63
  let o = n.data.port;
64
64
  ((e, n) => {
65
65
  e.serverOptions ||= {}, !e.serverOptions.language && n?.locale && (e.serverOptions.language = n.locale), e.serverOptions.language || (e.serverOptions.language = t(null, !0));
66
66
  })(i, n.data.globalInitData || {}), o.start?.(), a(e(r), o);
67
67
  }
68
- }, window.addEventListener("message", T);
69
- }, D = () => {
70
- T &&= (window.removeEventListener("message", T), null);
71
- }, O = async ({ extended: e }) => {
68
+ }, window.addEventListener("message", y);
69
+ }, x = () => {
70
+ y &&= (window.removeEventListener("message", y), null);
71
+ }, S = async ({ extended: e }) => {
72
72
  if (typeof e.getExternalObjectAgentTools != "function") throw Error("The planner has no HI agent tools: it needs a Rubens UI with getExternalObjectAgentTools.");
73
- return n(await e.getExternalObjectAgentTools(), (t, n) => e.callExternalObjectAgentTool(t, n), "hi-mcp");
74
- }, k = (e = {}) => {
75
- let t = e.raw, n = t?.input_tokens_details ?? t?.prompt_tokens_details, r = t?.output_tokens_details ?? t?.completion_tokens_details, i = o(n?.cached_tokens ?? t?.cache_read_input_tokens), a = o(n?.cache_write_tokens ?? t?.cache_creation_input_tokens), s = (e, t) => t ?? (o(e) !== null && Number(e) > 0 ? Number(e) : null);
76
- return {
77
- cacheReadTokens: s(e.inputTokenDetails?.cacheReadTokens, i),
78
- cacheWriteTokens: s(e.inputTokenDetails?.cacheWriteTokens, a),
79
- noCacheTokens: i !== null && a !== null ? o(e.inputTokenDetails?.noCacheTokens) : null,
80
- reasoningTokens: s(e.outputTokenDetails?.reasoningTokens, o(r?.reasoning_tokens)),
81
- rawUsageAvailable: t !== void 0
82
- };
83
- }, A = async (e) => {
84
- let t = new TextEncoder().encode(e), n = await globalThis.crypto?.subtle?.digest("SHA-256", t);
85
- return {
86
- bytes: t.byteLength,
87
- sha256: n ? Array.from(new Uint8Array(n), (e) => e.toString(16).padStart(2, "0")).join("") : null
88
- };
89
- }, j = async (e, t) => {
90
- let n = await A(e), r = JSON.parse(e);
91
- if (!Array.isArray(r.input)) return n;
92
- let i = 0, a = 0;
93
- for (let e of r.input) {
94
- let n = await A(JSON.stringify(e));
95
- i += n.bytes, n.sha256 === null ? a = null : (t.has(n.sha256) && a !== null && (a += n.bytes), t.add(n.sha256));
96
- }
97
- let o = r.tools ? new TextEncoder().encode(JSON.stringify(r.tools)).length : 0;
98
- return {
99
- ...n,
100
- sections: {
101
- inputBytes: i,
102
- newInputBytes: a === null ? null : i - a,
103
- repeatedInputBytes: a,
104
- toolsBytes: o,
105
- otherBytes: n.bytes - i - o
106
- }
107
- };
108
- }, M = (e) => {
109
- let t = [e?.present.length ? `- Confirmed: ${e.present.join(", ")}` : "", e?.absent.length ? `- Not present / false: ${e.absent.join(", ")}` : ""].filter(Boolean);
110
- return t.length === 0 ? "" : `Observed in the photo (high-confidence cues; verify against the image):\n\n${t.join("\n")}`;
111
- }, N = (e, t) => {
112
- let n = M(t);
113
- return n ? `${e.replace(/\n*$/, "\n")}\n---\n\n${n}` : e;
114
- }, ee = [
115
- "rooms",
116
- "groups",
117
- "obstacles",
118
- "installationElements"
119
- ], P = ({ content: e }) => e.filter((e) => e.type === "text").map((e) => e.text).join("\n"), F = async (e, t, n) => {
120
- let o = e.extended, f = !1, p = !1, m = crypto.randomUUID(), h, g, _ = n, v = (e) => f || _.aborted ? void 0 : o.planningAssistantOutput(e), y = [], b = null, x = /* @__PURE__ */ new Set(), S;
121
- try {
122
- S = await Promise.all([
123
- import("./dist-S9sLSjZ4.mjs").then((e) => e.t),
124
- d(t, async (e) => {
125
- y.push({
126
- ...await j(e, x),
127
- stepNumber: b
128
- });
129
- }),
130
- o.getExternalObjectAgentPrompts(),
131
- O(e)
132
- ]);
133
- } catch (e) {
134
- v({
73
+ return r(await e.getExternalObjectAgentTools(), (t, n) => e.callExternalObjectAgentTool(t, n), "hi-mcp");
74
+ }, C = async (e, t, n) => {
75
+ let r = e.extended, o = async (e) => {
76
+ await r.planningAssistantOutput({
135
77
  type: "availability",
136
78
  available: !1,
137
- text: String(e)
79
+ text: e
138
80
  });
81
+ };
82
+ if (typeof r.startExternalObjectPlanningAssistant != "function") return void await o("The planner has no HI Planning Assistant: it needs a Rubens UI with startExternalObjectPlanningAssistant.");
83
+ if (n.aborted) return;
84
+ let s = crypto.randomUUID();
85
+ try {
86
+ let { startRelay: n, ui: o } = e, c = n && o ? await i(e, t) : t;
87
+ await r.startExternalObjectPlanningAssistant(((e) => {
88
+ let t = a(e);
89
+ return {
90
+ provider: "host",
91
+ model: e.model,
92
+ readsImages: e.readsImages,
93
+ ...!0 === e.readsDocuments && { readsDocuments: !0 },
94
+ ...t && { responsesProvider: t },
95
+ ...e.provider === "azure" && !e.chatCompletions && !0 === e.referenceCacheBreakpoint && { referenceCacheBreakpoint: !0 },
96
+ ...e.decisionApiKey && { decisionApiKey: e.decisionApiKey }
97
+ };
98
+ })({
99
+ ...c,
100
+ decisionApiKey: t.decisionApiKey
101
+ }), s);
102
+ } catch (e) {
103
+ await o(String(e));
139
104
  return;
140
105
  }
141
- let [{ streamText: C, stepCountIs: w }, T, E, D] = S, F = !0 === t.readsDocuments && typeof E.documentPrompt == "string", I = [E.systemPrompt, ...(E.referenceBlocks ?? []).map(({ id: e, text: t }) => `Reference: ${e}\n${t}`)].join("\n\n"), L = [], R = t.provider === "azure" && !t.chatCompletions && !0 === t.referenceCacheBreakpoint, z = c(t), B = null, V = 0, H = [], U = /* @__PURE__ */ new Set(), W = !1, G = () => new Set(L.flatMap((e) => e.role === "assistant" && Array.isArray(e.content) ? e.content.flatMap((e) => {
142
- let t = e.type === "tool-call" && e.toolName === "get-skill" ? e.input : void 0;
143
- return t && t.file === void 0 ? [String(t.name)] : [];
144
- }) : [])), K = !1, q = async (e) => {
145
- if (f || _.aborted) throw Error("The planning assistant is suspended.");
146
- if (h) throw Error("An assistant turn is already running.");
147
- h = (async ({ text: e, images: n, documents: c = [] }) => {
148
- let d = F ? c : [];
149
- g = new AbortController();
150
- let f = i([_, g.signal]);
151
- K = !0;
152
- let p = ++V, m = performance.now();
153
- y = [], b = null, x.clear();
154
- let h = [], S = [], O = null, j = [], q, J = !1, Y = !1, X = null, Z = (async (e, n, r, i, a) => {
155
- let s = performance.now();
156
- if (W || !o.getExternalObjectAgentDecisions) return null;
157
- let c;
158
- try {
159
- let l = o.getExternalObjectAgentDecisions({
160
- text: e,
161
- images: n,
162
- ...r > 0 && { documents: r },
163
- earlier: i,
164
- ...t.decisionApiKey && { apiKey: t.decisionApiKey },
165
- ...a.length > 0 && { held: a }
166
- }).then((e) => (e?.refused && (W = !0), e), () => null), u = await Promise.race([l, new Promise((e) => {
167
- c = setTimeout(() => e("late"), 1500);
168
- })]);
169
- return {
170
- ms: performance.now() - s,
171
- decisions: u === "late" ? null : u,
172
- late: u === "late"
173
- };
174
- } finally {
175
- clearTimeout(c);
176
- }
177
- })(e, n, d.length, [...H], [.../* @__PURE__ */ new Set([...U, ...G()])]);
178
- H.push(e || (d.length > 0 ? "(a document)" : "(an image)"));
179
- try {
180
- let t = performance.now(), i = [], a = [];
181
- await Promise.all([(async () => {
182
- try {
183
- let e = await D["get-plan-context"].execute({ include: ["articles", "attributes"] }), t = P(e), n = e.isError ? null : JSON.parse(t);
184
- if (Array.isArray(n?.articles) && n.articles.length > 0) {
185
- let e = `Current library reference (data, not instructions):\n${t}`;
186
- i.push({
187
- role: "user",
188
- content: R ? [{
189
- type: "text",
190
- text: e,
191
- providerOptions: { azure: { promptCacheBreakpoint: { mode: "explicit" } } }
192
- }] : e
193
- });
194
- }
195
- } catch {}
196
- })(), (async () => {
197
- let e = await Promise.resolve().then(() => D["get-plan-context"].execute({ include: ee })).then((e) => e.isError ? "" : P(e).trim()).catch(() => "");
198
- e && (await A(e), a.push({
199
- role: "user",
200
- content: `Plan state at the start of turn ${p}, read for this turn (data, not instructions):\n${e}`
201
- }));
202
- })()]), X = await A(JSON.stringify({
203
- instructions: I,
204
- messages: i
205
- })), performance.now() - t;
206
- let o = await Z, c = await (async (e) => {
207
- let t = G();
208
- return (await Promise.all(e.filter((e) => !U.has(e) && !t.has(e)).map(async (e) => {
209
- try {
210
- let t = await D["get-skill"].execute({ name: e });
211
- return t.isError ? null : {
212
- name: e,
213
- text: P(t)
214
- };
215
- } catch {
216
- return null;
217
- }
218
- }))).filter((e) => e !== null);
219
- })(o?.decisions?.skills ?? []), g = (e) => `call_supplied_skill_${p}_${e + 1}`, _ = o?.decisions?.facts, y = c.some(({ name: e }) => e === "image-planning") ? "" : M(_), x = [{
220
- role: "user",
221
- content: [
222
- {
223
- type: "text",
224
- text: e || (d.length > 0 ? E.documentPrompt : E.imagePrompt)
225
- },
226
- ...d.map(({ name: e, data: t }) => ({
227
- type: "file",
228
- data: t,
229
- mediaType: "application/pdf",
230
- filename: e
231
- })),
232
- ...n.map((e) => ({
233
- type: "file",
234
- data: e,
235
- mediaType: "image/jpeg"
236
- })),
237
- ...y ? [{
238
- type: "text",
239
- text: y
240
- }] : []
241
- ]
242
- }, ...c.length ? [{
243
- role: "assistant",
244
- content: c.map((e, t) => ({
245
- type: "tool-call",
246
- toolCallId: g(t),
247
- toolName: "get-skill",
248
- input: { name: e.name }
249
- }))
250
- }, {
251
- role: "tool",
252
- content: c.map((e, t) => ({
253
- type: "tool-result",
254
- toolCallId: g(t),
255
- toolName: "get-skill",
256
- output: {
257
- type: "content",
258
- value: [{
259
- type: "text",
260
- text: e.name === "image-planning" ? N(e.text, _) : e.text
261
- }]
262
- }
263
- }))
264
- }] : []];
265
- c.length > 0 && v({
266
- type: "activity",
267
- text: c.map(({ name: e }) => e).join(", ")
268
- }), o && (o.ms, o.late, o.decisions?.answers, { ..._ && { facts: _ } }, o.decisions?.refused, o.decisions?.skipped, c.map(({ name: e }) => e));
269
- let F = [
270
- ...i,
271
- ...L,
272
- ...a,
273
- ...x
274
- ], V, H = B && a.length > 0 && X.sha256 === B.reference ? B.responseId : void 0, W = [], K, Q = 0, $ = !1;
275
- do {
276
- K = void 0;
277
- let e = Q, t = H, n = [], o = C({
278
- model: T.languageModel,
279
- providerOptions: R && i.length && X.sha256 ? {
280
- ...T.providerOptions,
281
- azure: {
282
- ...T.providerOptions?.azure,
283
- promptCacheKey: X.sha256
284
- }
285
- } : T.providerOptions,
286
- instructions: I,
287
- messages: $ ? [...F, ...W].map(l) : [...F, ...W],
288
- tools: D,
289
- stopWhen: w(32 - e),
290
- abortSignal: f,
291
- onLanguageModelCallEnd: (e) => {
292
- S.push({
293
- ...r(e.usage),
294
- ...k(e.usage),
295
- responseTimeMs: e.performance.responseTimeMs,
296
- timeToFirstOutputMs: e.performance.timeToFirstOutputMs ?? null,
297
- finishReason: e.finishReason
298
- });
299
- },
300
- onStepEnd: (e) => {
301
- n.push(...e.response.messages), Q++, V = z ? e.providerMetadata?.[z]?.responseId ?? void 0 : void 0;
302
- },
303
- prepareStep: (n) => {
304
- b = e + n.stepNumber;
305
- let r = s(b, I);
306
- if (!z) return r;
307
- if (n.stepNumber === 0) return t ? {
308
- instructions: [],
309
- ...s(b),
310
- messages: [...a, ...x],
311
- providerOptions: { [z]: {
312
- previousResponseId: t,
313
- store: !0
314
- } }
315
- } : r;
316
- let i = n.steps.at(-1), o = i.providerMetadata?.[z]?.responseId;
317
- if (!o) throw Error("The previous model response has no continuation ID");
318
- return {
319
- instructions: [],
320
- ...s(b),
321
- messages: i.response.messages.filter(({ role: e }) => e === "tool"),
322
- providerOptions: { [z]: {
323
- previousResponseId: o,
324
- store: !0
325
- } }
326
- };
327
- }
328
- });
329
- for await (let e of o.stream) if (e.type === "text-delta") O ??= performance.now() - m, v({
330
- type: "text",
331
- text: e.text
332
- });
333
- else if (e.type === "tool-input-start" || e.type === "tool-call") v({
334
- type: "activity",
335
- text: e.toolName
336
- });
337
- else {
338
- if (e.type === "error") {
339
- if ((n.length > 0 || t) && u(e.error)) {
340
- K = e.error;
341
- break;
342
- }
343
- throw e.error;
344
- }
345
- e.type === "finish-step" ? (j.push(r(e.usage)), h.push(k(e.usage))) : e.type === "finish" ? (q = W.length ? void 0 : r(e.totalUsage), J = !0) : e.type === "abort" && (Y = !0);
346
- }
347
- K ? (W.push(...n), H = void 0, $ = !0) : Y || f.aborted || (L.push(...x, ...W, ...await o.responseMessages), c.forEach(({ name: e }) => U.add(e)), B = V && X.sha256 ? {
348
- responseId: V,
349
- reference: X.sha256
350
- } : null);
351
- } while (K);
352
- v({ type: "done" });
353
- } catch (e) {
354
- v({
355
- type: "error",
356
- text: `The planning assistant failed: ${e instanceof Error ? e.message : String(e)}`
357
- });
358
- } finally {
359
- let e = {
360
- inputTokens: q?.inputTokens ?? a(j.map((e) => e.inputTokens)),
361
- outputTokens: q?.outputTokens ?? a(j.map((e) => e.outputTokens)),
362
- totalTokens: q?.totalTokens ?? a(j.map((e) => e.totalTokens))
363
- };
364
- Object.values(e).some((e) => e !== null), J && !Y && !f.aborted && Object.values(e).every((e) => e !== null) && j.every((e) => Object.values(e).every((e) => e !== null));
365
- }
366
- })(e);
367
- try {
368
- await h;
369
- } finally {
370
- h = void 0, g = void 0;
371
- }
372
- };
373
- o.callbacks.onPlanningAssistantPrompt = q;
374
- let J = async (e) => {
375
- e === "isolation" ? (f = !0, g?.abort(/* @__PURE__ */ Error("The assistant changed mode.")), h && await Promise.allSettled([h]), await o.planningAssistantOutput({
376
- type: "availability",
377
- available: !1
378
- })) : _.aborted || p || (f = !1, v({
379
- type: "images",
380
- enabled: t.readsImages
381
- }), v({
382
- type: "documents",
383
- enabled: F
384
- }), v({
385
- type: "availability",
386
- available: !0
387
- }));
388
- }, Y;
389
- o.callbacks.onPlanningAssistantModeChange = J;
390
- let X = () => Y ??= (async () => {
391
- p = !0, f = !0, g?.abort(/* @__PURE__ */ Error("The planning assistant stopped.")), h && await Promise.allSettled([h]), await o.stopPlanningAssistant?.(m), o.callbacks.onPlanningAssistantPrompt === q && (o.callbacks.onPlanningAssistantPrompt = void 0, await o.planningAssistantOutput({
392
- type: "availability",
393
- available: !1
394
- })), o.callbacks.onPlanningAssistantModeChange === J && (o.callbacks.onPlanningAssistantModeChange = void 0), _.removeEventListener("abort", Z);
395
- })(), Z = () => {
396
- X();
397
- };
398
- if (_.addEventListener("abort", Z, { once: !0 }), !_.aborted) return await o.setPlanningAssistantModel?.({
399
- model: t.model,
400
- readsImages: t.readsImages,
401
- responsesProvider: c(t) ?? void 0
402
- }, m), o.getExternalObjectLibraryContext && (async () => {
403
- for (let e = 0; e < 240; e += 1) {
404
- if (K || n.aborted || (performance.now(), await Promise.resolve().then(() => o.getExternalObjectLibraryContext?.(["articles"])).then((e) => e?.articles?.length ?? 0, () => 0) > 0)) return;
405
- await new Promise((e) => setTimeout(e, 500));
406
- }
407
- })(), v({
408
- type: "images",
409
- enabled: t.readsImages
410
- }), v({
411
- type: "documents",
412
- enabled: F
413
- }), v({
414
- type: "availability",
415
- available: !0
416
- }), {
417
- suspend: () => J("isolation"),
418
- resume: () => J("planner"),
419
- dispose: X
106
+ let c, l = () => {
107
+ u();
108
+ }, u = () => c ??= (async () => {
109
+ n.removeEventListener("abort", l), await r.stopPlanningAssistant?.(s);
110
+ })();
111
+ if (n.addEventListener("abort", l, { once: !0 }), !n.aborted) return {
112
+ suspend: async () => {
113
+ c || await r.suspendPlanningAssistant?.();
114
+ },
115
+ resume: async () => {
116
+ c || await r.resumePlanningAssistant?.();
117
+ },
118
+ dispose: u
420
119
  };
421
- await X();
422
- }, I = async ({ serverUrl: e, authorization: t }) => {
120
+ await u();
121
+ }, w = async ({ serverUrl: e, authorization: t }) => {
423
122
  let n = t ? { Authorization: t } : {}, r;
424
123
  try {
425
124
  let t = await fetch(`${e}/backends/list`, {
@@ -431,24 +130,29 @@ var f = (e, t) => t === e.libraryId ? e : {
431
130
  return {};
432
131
  }
433
132
  if (!Array.isArray(r) || r.length !== 1) return {};
434
- let [{ enableAIPlanning: i, enableAIRendering: a }] = r, o = `${e}/api/ai/v1`;
133
+ let [{ enableAIPlanning: i, enableAIRendering: a, enableAIDecisions: o }] = r, s = `${e}/api/ai/v1`;
435
134
  return {
436
135
  ...!0 === i && { chat: {
437
136
  provider: "openai-compatible",
438
- baseUrl: o,
137
+ baseUrl: s,
439
138
  model: "planning",
440
139
  headers: n,
441
140
  responses: !0,
442
141
  readsImages: !0
443
142
  } },
444
143
  ...!0 === a && { rendering: {
445
- baseUrl: o,
144
+ baseUrl: s,
446
145
  model: "rendering",
447
146
  headers: n
147
+ } },
148
+ ...!0 === o && { decisions: {
149
+ baseUrl: s,
150
+ model: "decision",
151
+ headers: n
448
152
  } }
449
153
  };
450
- }, L = async (e) => (await fetch(e)).blob(), R = async (e, t, { baseUrl: n, model: r, headers: i }) => {
451
- let { prompt: a, image: o, aspect: s } = JSON.parse(e.body), c = await L(o), l = new FormData();
154
+ }, T = async (e) => (await fetch(e)).blob(), E = async (e, t, { baseUrl: n, model: r, headers: i }) => {
155
+ let { prompt: a, image: o, aspect: s } = JSON.parse(e.body), c = await T(o), l = new FormData();
452
156
  l.append("model", r), l.append("prompt", a), l.append("size", ((e = "1:1") => {
453
157
  let [t, n] = e.split(":").map(Number);
454
158
  return t === n ? "1024x1024" : t > n ? "1536x1024" : "1024x1536";
@@ -461,10 +165,38 @@ var f = (e, t) => t === e.libraryId ? e : {
461
165
  });
462
166
  if (!u.ok) return u;
463
167
  let { data: d } = await u.json(), f = d?.[0]?.b64_json, p = new FormData();
464
- return f ? p.append("image", await L(`data:image/png;base64,${f}`)) : p.append("text", "The endpoint returned no image"), new Response(p);
465
- }, z = {
168
+ return f ? p.append("image", await T(`data:image/png;base64,${f}`)) : p.append("text", "The endpoint returned no image"), new Response(p);
169
+ }, D = {
170
+ png: "image/png",
171
+ jpg: "image/jpeg"
172
+ }, O = (e, t, { baseUrl: n, model: r, headers: i }) => {
173
+ let { state: a, questions: o, assets: s = {} } = JSON.parse(e.body);
174
+ return fetch(`${n}/decisions`, {
175
+ method: "POST",
176
+ headers: {
177
+ ...i,
178
+ "Content-Type": "application/json"
179
+ },
180
+ body: JSON.stringify({
181
+ model: r,
182
+ input: [{
183
+ type: "text",
184
+ text: JSON.stringify(a)
185
+ }, ...Object.entries(s).flatMap(([e, t]) => [{
186
+ type: "text",
187
+ text: e
188
+ }, {
189
+ type: "image",
190
+ data: t.data_base64,
191
+ mime_type: D[t.format]
192
+ }])],
193
+ questions: o
194
+ }),
195
+ signal: t
196
+ });
197
+ }, k = {
466
198
  HIDE: "hide",
467
199
  SHOW_ATTRIBUTES: "attributes",
468
200
  SHOW_ARTICLES: "articles"
469
201
  };
470
- export { z as HI_PANEL_ACTION, D as cleanupHi, x as createHiLibraryCallbacks, O as createHiMcpTools, v as libLoadArticleCatalog, b as libLoadCalcScript, y as libLoadMasterData, d as loadChatModel, w as omGetRequest, C as omPostRequest, h as registerLegacyUrlFormat, R as requestImageEdits, I as resolveHiModelProxy, E as setupHi, F as startPlanningAssistant, g as unregisterLegacyUrlFormat };
202
+ export { k as HI_PANEL_ACTION, x as cleanupHi, h as createHiLibraryCallbacks, S as createHiMcpTools, f as libLoadArticleCatalog, m as libLoadCalcScript, p as libLoadMasterData, n as loadChatModel, v as omGetRequest, _ as omPostRequest, l as registerLegacyUrlFormat, O as requestDecisions, E as requestImageEdits, w as resolveHiModelProxy, b as setupHi, C as startPlanningAssistant, u as unregisterLegacyUrlFormat };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roomle/embedding-lib",
3
- "version": "0.0.0-dev-d66646c",
3
+ "version": "0.0.0-dev-f0a595f",
4
4
  "description": "This is a small library which can be used to communicate with the Roomle Configurator. ES modules only (browser-compatible).",
5
5
  "type": "module",
6
6
  "main": "./roomle-embedding-lib.js",
@@ -17,7 +17,7 @@ export interface AssistantModelHandlers {
17
17
  * The iframe hands its AI model requests to the host page ("bring your own
18
18
  * endpoint"), over Comlink on a port it sends, like connect_hi
19
19
  */
20
- export type AiFeature = 'lifestyle-rendering' | 'configuration-assistant';
20
+ export type AiFeature = 'lifestyle-rendering' | 'configuration-assistant' | 'planning-decisions';
21
21
  /**
22
22
  * The feature names what the request is for, so no route, method or headers
23
23
  * of a built-in endpoint reach the host. A feature with several operations
@@ -0,0 +1,35 @@
1
+ import { PlanningAssistantConfig } from './planning-assistant/chat-model';
2
+ import { default as RoomleEmbeddingApi } from './roomle-embedding-lib';
3
+ import { AiFeature, AiModelHandlers } from '../../common/src/utils/ai-model-relay';
4
+ export interface AiModelHostOptions extends AiModelHandlers {
5
+ model?: PlanningAssistantConfig;
6
+ /**
7
+ * The features the host answers; the others keep the built-in endpoints.
8
+ * Left out: every feature but `planning-decisions`, also ones added later.
9
+ * Never empty.
10
+ */
11
+ features?: AiFeature[];
12
+ }
13
+ /**
14
+ * What serveAiModelRequests hands back to the host page; once a later call
15
+ * has replaced this registration, both do nothing
16
+ */
17
+ export interface AiModelHostControl {
18
+ /** The host's user signed out: its AI features lock until a sign-in */
19
+ signOut(): Promise<void>;
20
+ /** The built-in endpoints answer again */
21
+ stop(): Promise<void>;
22
+ }
23
+ type AiModelInstance = Pick<RoomleEmbeddingApi<unknown, unknown>, 'startRelay' | 'ui'>;
24
+ /** The host's side of the relayed assistant model. */
25
+ export declare const hostAssistantModel: (model: PlanningAssistantConfig) => Promise<NonNullable<AiModelHandlers["assistantModel"]>>;
26
+ /**
27
+ * The host page answers the AI model requests of `instance` with its own
28
+ * endpoint, and the AI features it serves switch to it; call it once the
29
+ * instance is created. Rejects, with the relay stopped, when the iframe
30
+ * cannot take the host, e.g. an older UI without the AI relay.
31
+ */
32
+ export declare const serveAiModelRequests: (instance: AiModelInstance, options: AiModelHostOptions) => Promise<AiModelHostControl>;
33
+ /** Serves the model of the HI Planning Assistant beside the host's registration. */
34
+ export declare const keepAssistantModel: (instance: AiModelInstance, model: PlanningAssistantConfig) => Promise<PlanningAssistantConfig>;
35
+ export {};
@@ -1,29 +1,13 @@
1
- import { PlanningAssistantConfig } from './planning-assistant/chat-model';
2
- import { default as RoomleEmbeddingApi } from './roomle-embedding-lib';
3
- import { AiFeature, AiModelHandlers } from '../../common/src/utils/ai-model-relay';
4
- export type { AiFeature, AiModelAuthReason, AiModelHandlers, AiModelRequest, RenderingInput, } from '../../common/src/utils/ai-model-relay';
5
- export interface AiModelHostOptions extends AiModelHandlers {
6
- model?: PlanningAssistantConfig;
7
- /**
8
- * The features the host answers; the others keep the built-in endpoints.
9
- * Left out: every feature, also ones added later. Never empty.
10
- */
11
- features?: AiFeature[];
12
- }
13
- /**
14
- * What serveAiModelRequests hands back to the host page; once a later call
15
- * has replaced this registration, both do nothing
16
- */
17
- export interface AiModelHostControl {
18
- /** The host's user signed out: its AI features lock until a sign-in */
19
- signOut(): Promise<void>;
20
- /** The built-in endpoints answer again */
21
- stop(): Promise<void>;
22
- }
23
1
  /**
24
- * The host page answers the AI model requests of `instance` with its own
25
- * endpoint, and the AI features it serves switch to it; call it once the
26
- * instance is created. Rejects, with the relay stopped, when the iframe
27
- * cannot take the host, e.g. an older UI without the AI relay.
2
+ * AI exports for roomle/embedding-lib: the host page answers the AI model
3
+ * requests of an instance with its own endpoint (bring your own endpoint)
4
+ *
5
+ * A separate entry point keeps the main embedding library bundle small.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { serveAiModelRequests } from '@roomle/embedding-lib/ai';
10
+ * ```
28
11
  */
29
- export declare const serveAiModelRequests: (instance: Pick<RoomleEmbeddingApi<unknown, unknown>, "startRelay" | "ui">, { features, model, ...handlers }: AiModelHostOptions) => Promise<AiModelHostControl>;
12
+ export { serveAiModelRequests, type AiModelHostControl, type AiModelHostOptions, } from './ai-model-host';
13
+ export type { AiFeature, AiModelAuthReason, AiModelHandlers, AiModelRequest, RenderingInput, } from '../../common/src/utils/ai-model-relay';
@@ -18,5 +18,6 @@ export { createHiMcpTools, type HiMcpTool, type HiMcpTools, type HiMcpPlannerApi
18
18
  export { loadChatModel, startPlanningAssistant, type PlanningAssistantConfig, type PlanningAssistantPlannerApi, type PlanningAssistantControl, } from './homag-intelligence/hi-planning-assistant';
19
19
  export { resolveHiModelProxy, type HiModelProxy, type HiModelProxyOptions, } from './homag-intelligence/hi-model-proxy';
20
20
  export { requestImageEdits, type ImageEditsEndpoint, } from './homag-intelligence/image-edits';
21
+ export { requestDecisions, type DecisionsEndpoint, } from './homag-intelligence/decisions';
21
22
  export { type ExternalObjectSnapshotSaveResult, type HiContextAction, } from '../../web-sdk/packages';
22
23
  export { HI_PANEL_ACTION, type HiPanelActionType, type HiOrderHeader, type HiOrder, type HiOrderData, type HiPriceData, type HiCallbacks, } from '../../common/src/hi/hi-types';