@roomle/embedding-lib 11.0.0-alpha.12 → 11.0.0-alpha.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/THIRD-PARTY-NOTICES.txt +2 -2
  2. package/ai-model-host-CaiYrZkh.mjs +152 -0
  3. package/ai-model-host-HAJONHCj.mjs +156 -0
  4. package/ai.js +1 -128
  5. package/ai.min.js +1 -127
  6. package/chat-model-DooKwd8I.mjs +117 -0
  7. package/chat-model-KHuz1Ej9.mjs +118 -0
  8. package/configurator.js +2 -2
  9. package/configurator.min.js +2 -2
  10. package/construction.js +17718 -162
  11. package/construction.min.js +17397 -177
  12. package/docs/md/web/embedding/CHANGELOG.md +93 -4
  13. package/hi.js +91 -393
  14. package/hi.min.js +88 -351
  15. package/{mcp-tools-BLB7pCga.mjs → mcp-tools-C6O2gQZW.mjs} +0 -1
  16. package/{mcp-tools-BirFT2R0.mjs → mcp-tools-m_3IX0vB.mjs} +0 -1
  17. package/package.json +1 -1
  18. package/packages/common/src/utils/ai-model-relay.d.ts +1 -1
  19. package/packages/embedding-lib/src/ai-model-host.d.ts +36 -0
  20. package/packages/embedding-lib/src/ai.d.ts +11 -27
  21. package/packages/embedding-lib/src/hi.d.ts +1 -0
  22. package/packages/embedding-lib/src/homag-intelligence/decisions.d.ts +7 -0
  23. package/packages/embedding-lib/src/homag-intelligence/hi-model-proxy.d.ts +4 -1
  24. package/packages/embedding-lib/src/homag-intelligence/hi-planning-assistant.d.ts +9 -19
  25. package/packages/web-sdk/packages/assistant.d.ts +2 -1
  26. package/packages/web-sdk/packages/common-core/src/planning-assistant/chat-recovery.d.ts +5 -1
  27. package/packages/web-sdk/packages/common-core/src/planning-assistant/continuation.d.ts +5 -3
  28. package/packages/web-sdk/packages/common-core/src/planning-assistant/usage.d.ts +31 -0
  29. package/roomle-embedding-lib.js +37 -37
  30. package/roomle-embedding-lib.min.js +30 -30
  31. package/sbom.cdx.json +5 -5
  32. package/usage-C3HE9yXi.mjs +33 -0
  33. package/usage-CYqDPQOx.mjs +34 -0
  34. package/chat-model-B7BO8IhK.mjs +0 -212
  35. package/chat-model-XYf503pT.mjs +0 -213
  36. package/continuation-CswXtOus.mjs +0 -10
  37. package/continuation-NclHDSgS.mjs +0 -9
  38. package/dist-BZSd56sr.mjs +0 -17422
  39. package/dist-S9sLSjZ4.mjs +0 -17087
  40. package/packages/embedding-lib/src/homag-intelligence/hi-planning-usage.d.ts +0 -54
  41. package/turn-limits-9LbUeSG2.mjs +0 -9
  42. package/turn-limits-Ciq383Bd.mjs +0 -10
package/hi.min.js CHANGED
@@ -1,10 +1,10 @@
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-BirFT2R0.mjs";
5
- import { a as r, r as i } from "./turn-limits-9LbUeSG2.mjs";
6
- import { n as a } from "./chat-model-B7BO8IhK.mjs";
7
- import { n as o } from "./continuation-NclHDSgS.mjs";
4
+ import { t as n } from "./chat-model-DooKwd8I.mjs";
5
+ import { t as r } from "./mcp-tools-m_3IX0vB.mjs";
6
+ import { n as i, t as a } from "./ai-model-host-CaiYrZkh.mjs";
7
+ import { o } from "./usage-C3HE9yXi.mjs";
8
8
  var s = (e, t) => t === e.libraryId ? e : {
9
9
  ...e,
10
10
  libraryId: t
@@ -70,352 +70,56 @@ var s = (e, t) => t === e.libraryId ? e : {
70
70
  b &&= (window.removeEventListener("message", b), null);
71
71
  }, C = 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
- }, w = (e) => typeof e == "number" && Number.isSafeInteger(e) && e >= 0 ? e : null, T = (e = {}) => ({
75
- inputTokens: w(e.inputTokens),
76
- outputTokens: w(e.outputTokens),
77
- totalTokens: w(e.totalTokens) ?? (w(e.inputTokens) !== null && w(e.outputTokens) !== null ? e.inputTokens + e.outputTokens : null)
78
- }), E = (e) => e.some((e) => e !== null) ? e.reduce((e, t) => e + (t ?? 0), 0) : null, D = (e = {}) => {
79
- let t = e.raw, n = t?.input_tokens_details ?? t?.prompt_tokens_details, r = t?.output_tokens_details ?? t?.completion_tokens_details, i = w(n?.cached_tokens ?? t?.cache_read_input_tokens), a = w(n?.cache_write_tokens ?? t?.cache_creation_input_tokens), o = (e, t) => t ?? (w(e) !== null && Number(e) > 0 ? Number(e) : null);
80
- return {
81
- cacheReadTokens: o(e.inputTokenDetails?.cacheReadTokens, i),
82
- cacheWriteTokens: o(e.inputTokenDetails?.cacheWriteTokens, a),
83
- noCacheTokens: i !== null && a !== null ? w(e.inputTokenDetails?.noCacheTokens) : null,
84
- reasoningTokens: o(e.outputTokenDetails?.reasoningTokens, w(r?.reasoning_tokens)),
85
- rawUsageAvailable: t !== void 0
86
- };
87
- }, O = async (e) => {
88
- let t = new TextEncoder().encode(e), n = await globalThis.crypto?.subtle?.digest("SHA-256", t);
89
- return {
90
- bytes: t.byteLength,
91
- sha256: n ? Array.from(new Uint8Array(n), (e) => e.toString(16).padStart(2, "0")).join("") : null
73
+ return r(await e.getExternalObjectAgentTools(), (t, n) => e.callExternalObjectAgentTool(t, n), "hi-mcp");
74
+ }, w = async (e, t, n) => {
75
+ let r = e.extended, s = async (e) => {
76
+ await r.planningAssistantOutput({
77
+ type: "availability",
78
+ available: !1,
79
+ text: e
80
+ });
92
81
  };
93
- }, k = async (e, t) => {
94
- let n = await O(e), r = JSON.parse(e);
95
- if (!Array.isArray(r.input)) return n;
96
- let i = 0, a = 0;
97
- for (let e of r.input) {
98
- let n = await O(JSON.stringify(e));
99
- i += n.bytes, n.sha256 === null ? a = null : (t.has(n.sha256) && a !== null && (a += n.bytes), t.add(n.sha256));
100
- }
101
- let o = r.tools ? new TextEncoder().encode(JSON.stringify(r.tools)).length : 0;
102
- return {
103
- ...n,
104
- sections: {
105
- inputBytes: i,
106
- newInputBytes: a === null ? null : i - a,
107
- repeatedInputBytes: a,
108
- toolsBytes: o,
109
- otherBytes: n.bytes - i - o
110
- }
82
+ if (typeof r.startExternalObjectPlanningAssistant != "function") return void await s("The planner has no HI Planning Assistant: it needs a Rubens UI with startExternalObjectPlanningAssistant.");
83
+ if (n.aborted) return;
84
+ let c = crypto.randomUUID(), { startRelay: l, ui: u } = e, d = l && u ? e : void 0, f = async () => {
85
+ d && await i(d, t);
111
86
  };
112
- }, A = (e) => {
113
- let t = [e?.present.length ? `- Confirmed: ${e.present.join(", ")}` : "", e?.absent.length ? `- Not present / false: ${e.absent.join(", ")}` : ""].filter(Boolean);
114
- return t.length === 0 ? "" : `Observed in the photo (high-confidence cues; verify against the image):\n\n${t.join("\n")}`;
115
- }, j = (e, t) => {
116
- let n = A(t);
117
- return n ? `${e.replace(/\n*$/, "\n")}\n---\n\n${n}` : e;
118
- }, M = /^(Previous response with id '[^']*' not found|No tool output found for function call )/, N = (e) => e instanceof Error && M.test(e.message), P = (e) => e.role !== "assistant" || typeof e.content == "string" ? e : {
119
- ...e,
120
- content: e.content.map((e) => e.type !== "text" && e.type !== "reasoning" || !e.providerOptions ? e : {
121
- ...e,
122
- providerOptions: Object.fromEntries(Object.entries(e.providerOptions).map(([e, t]) => [e, Object.fromEntries(Object.entries(t).filter(([e]) => e !== "itemId"))]))
123
- })
124
- }, F = [
125
- "rooms",
126
- "groups",
127
- "obstacles",
128
- "installationElements"
129
- ], I = ({ content: e }) => e.filter((e) => e.type === "text").map((e) => e.text).join("\n"), L = async (e, t, n) => {
130
- let s = e.extended, c = !1, l = !1, u = crypto.randomUUID(), d, f, p = n, m = (e) => c || p.aborted ? void 0 : s.planningAssistantOutput(e), h = [], g = null, _ = /* @__PURE__ */ new Set(), v;
131
87
  try {
132
- v = await Promise.all([
133
- import("./dist-S9sLSjZ4.mjs").then((e) => e.t),
134
- a(t, async (e) => {
135
- h.push({
136
- ...await k(e, _),
137
- stepNumber: g
138
- });
139
- }),
140
- s.getExternalObjectAgentPrompts(),
141
- C(e)
142
- ]);
88
+ let e = d ? await a(d, t) : t;
89
+ await r.startExternalObjectPlanningAssistant(((e) => {
90
+ let t = o(e);
91
+ return {
92
+ provider: "host",
93
+ model: e.model,
94
+ readsImages: e.readsImages,
95
+ ...t && { responsesProvider: t },
96
+ ...e.provider === "azure" && !e.chatCompletions && !0 === e.referenceCacheBreakpoint && { referenceCacheBreakpoint: !0 },
97
+ ...e.decisionApiKey && { decisionApiKey: e.decisionApiKey }
98
+ };
99
+ })({
100
+ ...e,
101
+ decisionApiKey: t.decisionApiKey
102
+ }), c);
143
103
  } catch (e) {
144
- m({
145
- type: "availability",
146
- available: !1,
147
- text: String(e)
148
- });
104
+ await s(String(e)), await f();
149
105
  return;
150
106
  }
151
- let [{ streamText: y, stepCountIs: b }, x, S, w] = v, M = [S.systemPrompt, ...(S.referenceBlocks ?? []).map(({ id: e, text: t }) => `Reference: ${e}\n${t}`)].join("\n\n"), L = [], R = t.provider === "azure" && !t.chatCompletions && !0 === t.referenceCacheBreakpoint, z = o(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) => {
152
- let t = e.type === "tool-call" && e.toolName === "get-skill" ? e.input : void 0;
153
- return t && t.file === void 0 ? [String(t.name)] : [];
154
- }) : [])), K = !1, q = async (e) => {
155
- if (c || p.aborted) throw Error("The planning assistant is suspended.");
156
- if (d) throw Error("An assistant turn is already running.");
157
- d = (async ({ text: e, images: n }) => {
158
- f = new AbortController();
159
- let a = r([p, f.signal]);
160
- K = !0;
161
- let o = ++V, c = performance.now();
162
- h = [], g = null, _.clear();
163
- let l = [], u = [], d = null, v = [], C, k = !1, q = !1, J = null, Y = (async (e, n, r, i) => {
164
- let a = performance.now();
165
- if (W || !s.getExternalObjectAgentDecisions) return null;
166
- let o;
167
- try {
168
- let c = s.getExternalObjectAgentDecisions({
169
- text: e,
170
- images: n,
171
- earlier: r,
172
- ...t.decisionApiKey && { apiKey: t.decisionApiKey },
173
- ...i.length > 0 && { held: i }
174
- }).then((e) => (e?.refused && (W = !0), e), () => null), l = await Promise.race([c, new Promise((e) => {
175
- o = setTimeout(() => e("late"), 1500);
176
- })]);
177
- return {
178
- ms: performance.now() - a,
179
- decisions: l === "late" ? null : l,
180
- late: l === "late"
181
- };
182
- } finally {
183
- clearTimeout(o);
184
- }
185
- })(e, n, [...H], [.../* @__PURE__ */ new Set([...U, ...G()])]);
186
- H.push(e || "(an image)");
187
- try {
188
- let t = performance.now(), r = [], s = [];
189
- await Promise.all([(async () => {
190
- try {
191
- let e = await w["get-plan-context"].execute({ include: ["articles", "attributes"] }), t = I(e), n = e.isError ? null : JSON.parse(t);
192
- if (Array.isArray(n?.articles) && n.articles.length > 0) {
193
- let e = `Current library reference (data, not instructions):\n${t}`;
194
- r.push({
195
- role: "user",
196
- content: R ? [{
197
- type: "text",
198
- text: e,
199
- providerOptions: { azure: { promptCacheBreakpoint: { mode: "explicit" } } }
200
- }] : e
201
- });
202
- }
203
- } catch {}
204
- })(), (async () => {
205
- let e = await Promise.resolve().then(() => w["get-plan-context"].execute({ include: F })).then((e) => e.isError ? "" : I(e).trim()).catch(() => "");
206
- e && (await O(e), s.push({
207
- role: "user",
208
- content: `Plan state at the start of turn ${o}, read for this turn (data, not instructions):\n${e}`
209
- }));
210
- })()]), J = await O(JSON.stringify({
211
- instructions: M,
212
- messages: r
213
- })), performance.now() - t;
214
- let f = await Y, p = await (async (e) => {
215
- let t = G();
216
- return (await Promise.all(e.filter((e) => !U.has(e) && !t.has(e)).map(async (e) => {
217
- try {
218
- let t = await w["get-skill"].execute({ name: e });
219
- return t.isError ? null : {
220
- name: e,
221
- text: I(t)
222
- };
223
- } catch {
224
- return null;
225
- }
226
- }))).filter((e) => e !== null);
227
- })(f?.decisions?.skills ?? []), h = (e) => `call_supplied_skill_${o}_${e + 1}`, _ = f?.decisions?.facts, E = p.some(({ name: e }) => e === "image-planning") ? "" : A(_), V = [{
228
- role: "user",
229
- content: [
230
- {
231
- type: "text",
232
- text: e || S.imagePrompt
233
- },
234
- ...n.map((e) => ({
235
- type: "file",
236
- data: e,
237
- mediaType: "image/jpeg"
238
- })),
239
- ...E ? [{
240
- type: "text",
241
- text: E
242
- }] : []
243
- ]
244
- }, ...p.length ? [{
245
- role: "assistant",
246
- content: p.map((e, t) => ({
247
- type: "tool-call",
248
- toolCallId: h(t),
249
- toolName: "get-skill",
250
- input: { name: e.name }
251
- }))
252
- }, {
253
- role: "tool",
254
- content: p.map((e, t) => ({
255
- type: "tool-result",
256
- toolCallId: h(t),
257
- toolName: "get-skill",
258
- output: {
259
- type: "content",
260
- value: [{
261
- type: "text",
262
- text: e.name === "image-planning" ? j(e.text, _) : e.text
263
- }]
264
- }
265
- }))
266
- }] : []];
267
- p.length > 0 && m({
268
- type: "activity",
269
- text: p.map(({ name: e }) => e).join(", ")
270
- }), f && (f.ms, f.late, f.decisions?.answers, { ..._ && { facts: _ } }, f.decisions?.refused, f.decisions?.skipped, p.map(({ name: e }) => e));
271
- let H = [
272
- ...r,
273
- ...L,
274
- ...s,
275
- ...V
276
- ], W, K = B && s.length > 0 && J.sha256 === B.reference ? B.responseId : void 0, X = [], Z, Q = 0, $ = !1;
277
- do {
278
- Z = void 0;
279
- let e = Q, t = K, n = [], o = y({
280
- model: x.languageModel,
281
- providerOptions: R && r.length && J.sha256 ? {
282
- ...x.providerOptions,
283
- azure: {
284
- ...x.providerOptions?.azure,
285
- promptCacheKey: J.sha256
286
- }
287
- } : x.providerOptions,
288
- instructions: M,
289
- messages: $ ? [...H, ...X].map(P) : [...H, ...X],
290
- tools: w,
291
- stopWhen: b(32 - e),
292
- abortSignal: a,
293
- onLanguageModelCallEnd: (e) => {
294
- u.push({
295
- ...T(e.usage),
296
- ...D(e.usage),
297
- responseTimeMs: e.performance.responseTimeMs,
298
- timeToFirstOutputMs: e.performance.timeToFirstOutputMs ?? null,
299
- finishReason: e.finishReason
300
- });
301
- },
302
- onStepEnd: (e) => {
303
- n.push(...e.response.messages), Q++, W = z ? e.providerMetadata?.[z]?.responseId ?? void 0 : void 0;
304
- },
305
- prepareStep: (n) => {
306
- g = e + n.stepNumber;
307
- let r = i(g, M);
308
- if (!z) return r;
309
- if (n.stepNumber === 0) return t ? {
310
- instructions: [],
311
- ...i(g),
312
- messages: [...s, ...V],
313
- providerOptions: { [z]: {
314
- previousResponseId: t,
315
- store: !0
316
- } }
317
- } : r;
318
- let a = n.steps.at(-1), o = a.providerMetadata?.[z]?.responseId;
319
- if (!o) throw Error("The previous model response has no continuation ID");
320
- return {
321
- instructions: [],
322
- ...i(g),
323
- messages: a.response.messages.filter(({ role: e }) => e === "tool"),
324
- providerOptions: { [z]: {
325
- previousResponseId: o,
326
- store: !0
327
- } }
328
- };
329
- }
330
- });
331
- for await (let e of o.stream) if (e.type === "text-delta") d ??= performance.now() - c, m({
332
- type: "text",
333
- text: e.text
334
- });
335
- else if (e.type === "tool-input-start" || e.type === "tool-call") m({
336
- type: "activity",
337
- text: e.toolName
338
- });
339
- else {
340
- if (e.type === "error") {
341
- if ((n.length > 0 || t) && N(e.error)) {
342
- Z = e.error;
343
- break;
344
- }
345
- throw e.error;
346
- }
347
- e.type === "finish-step" ? (v.push(T(e.usage)), l.push(D(e.usage))) : e.type === "finish" ? (C = X.length ? void 0 : T(e.totalUsage), k = !0) : e.type === "abort" && (q = !0);
348
- }
349
- Z ? (X.push(...n), K = void 0, $ = !0) : q || a.aborted || (L.push(...V, ...X, ...await o.responseMessages), p.forEach(({ name: e }) => U.add(e)), B = W && J.sha256 ? {
350
- responseId: W,
351
- reference: J.sha256
352
- } : null);
353
- } while (Z);
354
- m({ type: "done" });
355
- } catch (e) {
356
- m({
357
- type: "error",
358
- text: `The planning assistant failed: ${e instanceof Error ? e.message : String(e)}`
359
- });
360
- } finally {
361
- let e = {
362
- inputTokens: C?.inputTokens ?? E(v.map((e) => e.inputTokens)),
363
- outputTokens: C?.outputTokens ?? E(v.map((e) => e.outputTokens)),
364
- totalTokens: C?.totalTokens ?? E(v.map((e) => e.totalTokens))
365
- };
366
- Object.values(e).some((e) => e !== null), k && !q && !a.aborted && Object.values(e).every((e) => e !== null) && v.every((e) => Object.values(e).every((e) => e !== null));
367
- }
368
- })(e);
369
- try {
370
- await d;
371
- } finally {
372
- d = void 0, f = void 0;
373
- }
374
- };
375
- s.callbacks.onPlanningAssistantPrompt = q;
376
- let J = async (e) => {
377
- e === "isolation" ? (c = !0, f?.abort(/* @__PURE__ */ Error("The assistant changed mode.")), d && await Promise.allSettled([d]), await s.planningAssistantOutput({
378
- type: "availability",
379
- available: !1
380
- })) : p.aborted || l || (c = !1, m({
381
- type: "images",
382
- enabled: t.readsImages
383
- }), m({
384
- type: "availability",
385
- available: !0
386
- }));
387
- }, Y;
388
- s.callbacks.onPlanningAssistantModeChange = J;
389
- let X = () => Y ??= (async () => {
390
- l = !0, c = !0, f?.abort(/* @__PURE__ */ Error("The planning assistant stopped.")), d && await Promise.allSettled([d]), await s.stopPlanningAssistant?.(u), s.callbacks.onPlanningAssistantPrompt === q && (s.callbacks.onPlanningAssistantPrompt = void 0, await s.planningAssistantOutput({
391
- type: "availability",
392
- available: !1
393
- })), s.callbacks.onPlanningAssistantModeChange === J && (s.callbacks.onPlanningAssistantModeChange = void 0), p.removeEventListener("abort", Z);
394
- })(), Z = () => {
395
- X();
396
- };
397
- if (p.addEventListener("abort", Z, { once: !0 }), !p.aborted) return await s.setPlanningAssistantModel?.({
398
- model: t.model,
399
- readsImages: t.readsImages,
400
- responsesProvider: o(t) ?? void 0
401
- }, u), s.getExternalObjectLibraryContext && (async () => {
402
- for (let e = 0; e < 240; e += 1) {
403
- if (K || n.aborted || (performance.now(), await Promise.resolve().then(() => s.getExternalObjectLibraryContext?.(["articles"])).then((e) => e?.articles?.length ?? 0, () => 0) > 0)) return;
404
- await new Promise((e) => setTimeout(e, 500));
405
- }
406
- })(), m({
407
- type: "images",
408
- enabled: t.readsImages
409
- }), m({
410
- type: "availability",
411
- available: !0
412
- }), {
413
- suspend: () => J("isolation"),
414
- resume: () => J("planner"),
415
- dispose: X
107
+ let p, m = () => {
108
+ h();
109
+ }, h = () => p ??= (async () => {
110
+ n.removeEventListener("abort", m), await r.stopPlanningAssistant?.(c), await f();
111
+ })();
112
+ if (n.addEventListener("abort", m, { once: !0 }), !n.aborted) return {
113
+ suspend: async () => {
114
+ p || await r.suspendPlanningAssistant?.();
115
+ },
116
+ resume: async () => {
117
+ p || await r.resumePlanningAssistant?.();
118
+ },
119
+ dispose: h
416
120
  };
417
- await X();
418
- }, R = async ({ serverUrl: e, authorization: t }) => {
121
+ await h();
122
+ }, T = async ({ serverUrl: e, authorization: t }) => {
419
123
  let n = t ? { Authorization: t } : {}, r;
420
124
  try {
421
125
  let t = await fetch(`${e}/backends/list`, {
@@ -427,24 +131,29 @@ var s = (e, t) => t === e.libraryId ? e : {
427
131
  return {};
428
132
  }
429
133
  if (!Array.isArray(r) || r.length !== 1) return {};
430
- let [{ enableAIPlanning: i, enableAIRendering: a }] = r, o = `${e}/api/ai/v1`;
134
+ let [{ enableAIPlanning: i, enableAIRendering: a, enableAIDecisions: o }] = r, s = `${e}/api/ai/v1`;
431
135
  return {
432
136
  ...!0 === i && { chat: {
433
137
  provider: "openai-compatible",
434
- baseUrl: o,
138
+ baseUrl: s,
435
139
  model: "planning",
436
140
  headers: n,
437
141
  responses: !0,
438
142
  readsImages: !0
439
143
  } },
440
144
  ...!0 === a && { rendering: {
441
- baseUrl: o,
145
+ baseUrl: s,
442
146
  model: "rendering",
443
147
  headers: n
148
+ } },
149
+ ...!0 === o && { decisions: {
150
+ baseUrl: s,
151
+ model: "decision",
152
+ headers: n
444
153
  } }
445
154
  };
446
- }, z = async (e) => (await fetch(e)).blob(), B = async (e, t, { baseUrl: n, model: r, headers: i }) => {
447
- let { prompt: a, image: o, aspect: s } = JSON.parse(e.body), c = await z(o), l = new FormData();
155
+ }, E = async (e) => (await fetch(e)).blob(), D = async (e, t, { baseUrl: n, model: r, headers: i }) => {
156
+ let { prompt: a, image: o, aspect: s } = JSON.parse(e.body), c = await E(o), l = new FormData();
448
157
  l.append("model", r), l.append("prompt", a), l.append("size", ((e = "1:1") => {
449
158
  let [t, n] = e.split(":").map(Number);
450
159
  return t === n ? "1024x1024" : t > n ? "1536x1024" : "1024x1536";
@@ -457,10 +166,38 @@ var s = (e, t) => t === e.libraryId ? e : {
457
166
  });
458
167
  if (!u.ok) return u;
459
168
  let { data: d } = await u.json(), f = d?.[0]?.b64_json, p = new FormData();
460
- return f ? p.append("image", await z(`data:image/png;base64,${f}`)) : p.append("text", "The endpoint returned no image"), new Response(p);
461
- }, V = {
169
+ return f ? p.append("image", await E(`data:image/png;base64,${f}`)) : p.append("text", "The endpoint returned no image"), new Response(p);
170
+ }, O = {
171
+ png: "image/png",
172
+ jpg: "image/jpeg"
173
+ }, k = (e, t, { baseUrl: n, model: r, headers: i }) => {
174
+ let { state: a, questions: o, assets: s = {} } = JSON.parse(e.body);
175
+ return fetch(`${n}/decisions`, {
176
+ method: "POST",
177
+ headers: {
178
+ ...i,
179
+ "Content-Type": "application/json"
180
+ },
181
+ body: JSON.stringify({
182
+ model: r,
183
+ input: [{
184
+ type: "text",
185
+ text: JSON.stringify(a)
186
+ }, ...Object.entries(s).flatMap(([e, t]) => [{
187
+ type: "text",
188
+ text: e
189
+ }, {
190
+ type: "image",
191
+ data: t.data_base64,
192
+ mime_type: O[t.format]
193
+ }])],
194
+ questions: o
195
+ }),
196
+ signal: t
197
+ });
198
+ }, A = {
462
199
  HIDE: "hide",
463
200
  SHOW_ATTRIBUTES: "attributes",
464
201
  SHOW_ARTICLES: "articles"
465
202
  };
466
- export { V as HI_PANEL_ACTION, S as cleanupHi, g as createHiLibraryCallbacks, C as createHiMcpTools, p as libLoadArticleCatalog, h as libLoadCalcScript, m as libLoadMasterData, a as loadChatModel, y as omGetRequest, v as omPostRequest, u as registerLegacyUrlFormat, B as requestImageEdits, R as resolveHiModelProxy, x as setupHi, L as startPlanningAssistant, d as unregisterLegacyUrlFormat };
203
+ export { A as HI_PANEL_ACTION, S as cleanupHi, g as createHiLibraryCallbacks, C as createHiMcpTools, p as libLoadArticleCatalog, h as libLoadCalcScript, m as libLoadMasterData, n as loadChatModel, y as omGetRequest, v as omPostRequest, u as registerLegacyUrlFormat, k as requestDecisions, D as requestImageEdits, T as resolveHiModelProxy, x as setupHi, w as startPlanningAssistant, d as unregisterLegacyUrlFormat };
@@ -1,5 +1,4 @@
1
1
 
2
- import "./chat-model-XYf503pT.mjs";
3
2
  // packages/web-sdk/packages/common-core/src/planning-assistant/mcp-tools.ts
4
3
  var e = ({ output: e }) => ({
5
4
  type: "content",
@@ -1,5 +1,4 @@
1
1
 
2
- import "./chat-model-B7BO8IhK.mjs";
3
2
  var e = ({ output: e }) => ({
4
3
  type: "content",
5
4
  value: e.content.map((e) => e.type === "text" ? {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roomle/embedding-lib",
3
- "version": "11.0.0-alpha.12",
3
+ "version": "11.0.0-alpha.13",
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,36 @@
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 declare const releaseAssistantModel: (instance: AiModelInstance, model: PlanningAssistantConfig) => Promise<void>;
36
+ 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';
@@ -0,0 +1,7 @@
1
+ import { AiModelRequest } from '../../../common/src/utils/ai-model-relay';
2
+ export interface DecisionsEndpoint {
3
+ baseUrl: string;
4
+ model: string;
5
+ headers?: Record<string, string>;
6
+ }
7
+ export declare const requestDecisions: (request: AiModelRequest, signal: AbortSignal, { baseUrl, model, headers }: DecisionsEndpoint) => Promise<Response>;
@@ -1,3 +1,4 @@
1
+ import { DecisionsEndpoint } from './decisions';
1
2
  import { ImageEditsEndpoint } from './image-edits';
2
3
  import { PlanningAssistantConfig } from '../planning-assistant/chat-model';
3
4
  /**
@@ -10,6 +11,7 @@ export interface HiModelProxy {
10
11
  chat?: PlanningAssistantConfig;
11
12
  /** The lifestyle renderings of the AI image chat, when the backend's `enableAIRendering` is true */
12
13
  rendering?: ImageEditsEndpoint;
14
+ decisions?: DecisionsEndpoint;
13
15
  }
14
16
  export interface HiModelProxyOptions {
15
17
  /** The HI server, e.g. `https://dfscfgtest01-app.azurewebsites.net`; `''` for the page's own origin */
@@ -21,6 +23,7 @@ export interface HiModelProxyOptions {
21
23
  * Reads the backend list of the HI user and returns what the model proxy of
22
24
  * the HI server serves. The proxy serves only a user of exactly one backend:
23
25
  * the chat when that backend's `enableAIPlanning` is true, the renderings
24
- * when its `enableAIRendering` is true. A failed backend list serves neither.
26
+ * when its `enableAIRendering` is true, the decisions when its
27
+ * `enableAIDecisions` is true. A failed backend list serves none.
25
28
  */
26
29
  export declare const resolveHiModelProxy: ({ serverUrl, authorization, }: HiModelProxyOptions) => Promise<HiModelProxy>;