@roomle/embedding-lib 9.1.0-alpha.1 → 9.1.0-alpha.3

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.js CHANGED
@@ -1,7 +1,7 @@
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 "./browser-zrjtYpL8.mjs";
3
3
  import { t } from "./utils-WeolMfC5.mjs";
4
- import { n, t as r } from "./mcp-tools-D__M74CZ.mjs";
4
+ import { n, t as r } from "./mcp-tools-Cnhgobge.mjs";
5
5
  var i = (e, t) => t === e.libraryId ? e : {
6
6
  ...e,
7
7
  libraryId: t
@@ -58,7 +58,7 @@ var i = (e, t) => t === e.libraryId ? e : {
58
58
  _ && window.removeEventListener("message", _);
59
59
  let r = typeof e == "string" ? { libraryId: e } : e;
60
60
  n.onLoadJavascript === void 0 && (n.onLoadJavascript = (e) => f(i(r, e))), n.onLoadArticleCatalog === void 0 && (n.onLoadArticleCatalog = (e) => u(i(r, e))), n.onLoadMasterData === void 0 && (n.onLoadMasterData = (e) => d(i(r, e)));
61
- let { expose: a } = await import("./comlink-Cmiqa2s0.mjs");
61
+ let { expose: a } = await import("./comlink-m82YLjsS.mjs");
62
62
  _ = (e) => {
63
63
  if (e.data.type === "connect_hi" && e.data.port) {
64
64
  let i = e.data.port;
@@ -121,12 +121,18 @@ var i = (e, t) => t === e.libraryId ? e : {
121
121
  otherBytes: n.bytes - i - o
122
122
  }
123
123
  };
124
- }, O = 16, k = /^(Previous response with id '[^']*' not found|No tool output found for function call )/, A = (e) => e instanceof Error && k.test(e.message), j = [
124
+ }, O = 16, k = /^(Previous response with id '[^']*' not found|No tool output found for function call )/, A = (e) => e instanceof Error && k.test(e.message), j = (e) => e.role !== "assistant" || typeof e.content == "string" ? e : {
125
+ ...e,
126
+ content: e.content.map((e) => (e.type === "text" || e.type === "reasoning") && e.providerOptions ? {
127
+ ...e,
128
+ providerOptions: Object.fromEntries(Object.entries(e.providerOptions).map(([e, t]) => [e, Object.fromEntries(Object.entries(t).filter(([e]) => e !== "itemId"))]))
129
+ } : e)
130
+ }, M = [
125
131
  "rooms",
126
132
  "groups",
127
133
  "obstacles",
128
134
  "installationElements"
129
- ], M = 500, N = 240, P = ({ content: e }) => e.filter((e) => e.type === "text").map((e) => e.text).join("\n"), F = async (e, t, r) => {
135
+ ], N = 500, P = 240, F = ({ content: e }) => e.filter((e) => e.type === "text").map((e) => e.text).join("\n"), I = async (e, t, r) => {
130
136
  let i = e.extended, a = (e) => i.planningAssistantOutput(e), o = [], s = null, c = /* @__PURE__ */ new Set(), l;
131
137
  try {
132
138
  l = await Promise.all([
@@ -148,22 +154,22 @@ var i = (e, t) => t === e.libraryId ? e : {
148
154
  });
149
155
  return;
150
156
  }
151
- let [{ streamText: u, stepCountIs: d }, f, p, m] = l, h = [p.systemPrompt, ...(p.referenceBlocks ?? []).map(({ id: e, text: t }) => `Reference: ${e}\n${t}`)].join("\n\n"), g = [], _ = t.provider === "azure" && !t.chatCompletions && t.referenceCacheBreakpoint === !0, v = !1, y = async () => {
152
- for (let e = 0; e < N; e += 1) {
153
- if (v || r.aborted) return;
157
+ let [{ streamText: u, stepCountIs: d }, f, p, m] = l, h = [p.systemPrompt, ...(p.referenceBlocks ?? []).map(({ id: e, text: t }) => `Reference: ${e}\n${t}`)].join("\n\n"), g = [], _ = t.provider === "azure" && !t.chatCompletions && t.referenceCacheBreakpoint === !0, v = t.provider === "openai" || t.provider === "azure" && !t.chatCompletions ? t.provider : null, y = null, x = 0, k = !1, I = async () => {
158
+ for (let e = 0; e < P; e += 1) {
159
+ if (k || r.aborted) return;
154
160
  let e = performance.now(), t = await Promise.resolve().then(() => i.getExternalObjectLibraryContext?.(["articles"])).then((e) => e?.articles?.length ?? 0, () => 0);
155
161
  if (t > 0) {
156
162
  console.log(`[planning-assistant] library read before the first prompt: ${t} articles in ${Math.round(performance.now() - e)} ms`);
157
163
  return;
158
164
  }
159
- await new Promise((e) => setTimeout(e, M));
165
+ await new Promise((e) => setTimeout(e, N));
160
166
  }
161
167
  };
162
168
  i.callbacks.onPlanningAssistantPrompt = async ({ text: e, images: n }) => {
163
- v = !0;
164
- let i = performance.now();
169
+ k = !0;
170
+ let i = ++x, l = performance.now();
165
171
  o = [], s = null, c.clear();
166
- let l = [], y = [], b = null, x = [], D, k = !1, M = !1, N = null, F = null, I = 0, L = {
172
+ let b = [], D = [], N = null, P = [], I, L = !1, R = !1, z = null, B = null, V = 0, H = {
167
173
  role: "user",
168
174
  content: [{
169
175
  type: "text",
@@ -175,13 +181,13 @@ var i = (e, t) => t === e.libraryId ? e : {
175
181
  }))]
176
182
  };
177
183
  try {
178
- let e = performance.now(), n = [], o = [];
184
+ let e = performance.now(), t = [], n = [];
179
185
  await Promise.all([(async () => {
180
186
  try {
181
- let e = await m["get-plan-context"].execute({ include: ["articles", "attributes"] }), t = P(e), r = e.isError ? null : JSON.parse(t);
187
+ let e = await m["get-plan-context"].execute({ include: ["articles", "attributes"] }), n = F(e), r = e.isError ? null : JSON.parse(n);
182
188
  if (Array.isArray(r?.articles) && r.articles.length > 0) {
183
- let e = `Current library reference (data, not instructions):\n${t}`;
184
- n.push({
189
+ let e = `Current library reference (data, not instructions):\n${n}`;
190
+ t.push({
185
191
  role: "user",
186
192
  content: _ ? [{
187
193
  type: "text",
@@ -194,43 +200,43 @@ var i = (e, t) => t === e.libraryId ? e : {
194
200
  console.log("[planning-assistant] reference unavailable; using tools");
195
201
  }
196
202
  })(), (async () => {
197
- let e = await Promise.resolve().then(() => m["get-plan-context"].execute({ include: j })).then((e) => e.isError ? "" : P(e).trim()).catch(() => "");
203
+ let e = await Promise.resolve().then(() => m["get-plan-context"].execute({ include: M })).then((e) => e.isError ? "" : F(e).trim()).catch(() => "");
198
204
  if (!e) {
199
205
  console.log("[planning-assistant] plan state unavailable; the model reads it");
200
206
  return;
201
207
  }
202
- F = await E(e), o.push({
208
+ B = await E(e), n.push({
203
209
  role: "user",
204
- content: `Current plan state, read for this turn (data, not instructions):\n${e}`
210
+ content: `Plan state at the start of turn ${i}, read for this turn (data, not instructions):\n${e}`
205
211
  });
206
- })()]), N = await E(JSON.stringify({
212
+ })()]), z = await E(JSON.stringify({
207
213
  instructions: h,
208
- messages: n
209
- })), I = performance.now() - e;
210
- let c = [
211
- ...n,
214
+ messages: t
215
+ })), V = performance.now() - e;
216
+ let o = [
217
+ ...t,
212
218
  ...g,
213
- ...o,
214
- L
215
- ], p = [], v = 0, C;
219
+ ...n,
220
+ H
221
+ ], c = y && n.length > 0 && z.sha256 === y.reference ? y.responseId : void 0, p, x = [], C = 0, T, k = !1;
216
222
  do {
217
- C = void 0;
218
- let e = v, o = [], T = u({
223
+ T = void 0;
224
+ let e = C, i = c, E = [], M = u({
219
225
  model: f.languageModel,
220
- providerOptions: _ && n.length && N.sha256 ? {
226
+ providerOptions: _ && t.length && z.sha256 ? {
221
227
  ...f.providerOptions,
222
228
  azure: {
223
229
  ...f.providerOptions?.azure,
224
- promptCacheKey: N.sha256
230
+ promptCacheKey: z.sha256
225
231
  }
226
232
  } : f.providerOptions,
227
233
  instructions: h,
228
- messages: [...c, ...p],
234
+ messages: k ? [...o, ...x].map(j) : [...o, ...x],
229
235
  tools: m,
230
236
  stopWhen: d(O - e),
231
237
  abortSignal: r,
232
238
  onLanguageModelCallEnd: (e) => {
233
- y.push({
239
+ D.push({
234
240
  ...S(e.usage),
235
241
  ...w(e.usage),
236
242
  responseTimeMs: e.performance.responseTimeMs,
@@ -239,26 +245,35 @@ var i = (e, t) => t === e.libraryId ? e : {
239
245
  });
240
246
  },
241
247
  onStepEnd: (e) => {
242
- o.push(...e.response.messages), v++;
248
+ E.push(...e.response.messages), C++, p = v ? e.providerMetadata?.[v]?.responseId ?? void 0 : void 0;
243
249
  },
244
- prepareStep: (n) => {
245
- s = e + n.stepNumber;
246
- let r = s === O - 1 ? { toolChoice: "none" } : {}, i = t.provider === "openai" || t.provider === "azure" && !t.chatCompletions ? t.provider : null;
247
- if (!i || n.stepNumber === 0) return r;
248
- let a = n.steps.at(-1), o = a.providerMetadata?.[i]?.responseId;
250
+ prepareStep: (t) => {
251
+ s = e + t.stepNumber;
252
+ let r = s === O - 1 ? { toolChoice: "none" } : {};
253
+ if (!v) return r;
254
+ if (t.stepNumber === 0) return i ? {
255
+ ...r,
256
+ instructions: [],
257
+ messages: [...n, H],
258
+ providerOptions: { [v]: {
259
+ previousResponseId: i,
260
+ store: !0
261
+ } }
262
+ } : r;
263
+ let a = t.steps.at(-1), o = a.providerMetadata?.[v]?.responseId;
249
264
  if (!o) throw Error("The previous model response has no continuation ID");
250
265
  return {
251
266
  ...r,
252
267
  instructions: [],
253
268
  messages: a.response.messages.filter(({ role: e }) => e === "tool"),
254
- providerOptions: { [i]: {
269
+ providerOptions: { [v]: {
255
270
  previousResponseId: o,
256
271
  store: !0
257
272
  } }
258
273
  };
259
274
  }
260
275
  });
261
- for await (let e of T.stream) if (e.type === "text-delta") b ??= performance.now() - i, a({
276
+ for await (let e of M.stream) if (e.type === "text-delta") N ??= performance.now() - l, a({
262
277
  type: "text",
263
278
  text: e.text
264
279
  });
@@ -267,14 +282,17 @@ var i = (e, t) => t === e.libraryId ? e : {
267
282
  text: e.toolName
268
283
  });
269
284
  else if (e.type === "error") {
270
- if (o.length > 0 && A(e.error)) {
271
- C = e.error;
285
+ if ((E.length > 0 || i) && A(e.error)) {
286
+ T = e.error;
272
287
  break;
273
288
  }
274
289
  throw e.error;
275
- } else e.type === "finish-step" ? (x.push(S(e.usage)), l.push(w(e.usage))) : e.type === "finish" ? (D = p.length ? void 0 : S(e.totalUsage), k = !0) : e.type === "abort" && (M = !0);
276
- C ? (console.log(`[planning-assistant] continuation rejected (${C.message}) - continuing with the whole history`), p.push(...o)) : !M && !r.aborted && g.push(L, ...p, ...await T.responseMessages);
277
- } while (C);
290
+ } else e.type === "finish-step" ? (P.push(S(e.usage)), b.push(w(e.usage))) : e.type === "finish" ? (I = x.length ? void 0 : S(e.totalUsage), L = !0) : e.type === "abort" && (R = !0);
291
+ T ? (console.log(`[planning-assistant] continuation rejected (${T.message}) - continuing with the whole history`), x.push(...E), c = void 0, k = !0) : !R && !r.aborted && (g.push(H, ...x, ...await M.responseMessages), y = p && z.sha256 ? {
292
+ responseId: p,
293
+ reference: z.sha256
294
+ } : null);
295
+ } while (T);
278
296
  a({ type: "done" });
279
297
  } catch (e) {
280
298
  console.log("[planning-assistant]", String(e)), a({
@@ -283,39 +301,39 @@ var i = (e, t) => t === e.libraryId ? e : {
283
301
  });
284
302
  } finally {
285
303
  let e = {
286
- inputTokens: D?.inputTokens ?? C(x.map((e) => e.inputTokens)),
287
- outputTokens: D?.outputTokens ?? C(x.map((e) => e.outputTokens)),
288
- totalTokens: D?.totalTokens ?? C(x.map((e) => e.totalTokens))
289
- }, n = Object.values(e).some((e) => e !== null), a = k && !M && !r.aborted && Object.values(e).every((e) => e !== null) && x.every((e) => Object.values(e).every((e) => e !== null));
304
+ inputTokens: I?.inputTokens ?? C(P.map((e) => e.inputTokens)),
305
+ outputTokens: I?.outputTokens ?? C(P.map((e) => e.outputTokens)),
306
+ totalTokens: I?.totalTokens ?? C(P.map((e) => e.totalTokens))
307
+ }, n = Object.values(e).some((e) => e !== null), i = L && !R && !r.aborted && Object.values(e).every((e) => e !== null) && P.every((e) => Object.values(e).every((e) => e !== null));
290
308
  console.log(`[planning-assistant] usage ${JSON.stringify({
291
309
  provider: t.provider,
292
310
  model: t.model,
293
- status: n ? a ? "complete" : "partial" : "unavailable",
311
+ status: n ? i ? "complete" : "partial" : "unavailable",
294
312
  ...e,
295
313
  diagnostics: {
296
314
  version: 1,
297
- details: T(l),
298
- modelCalls: y,
315
+ details: T(b),
316
+ modelCalls: D,
299
317
  requests: o,
300
- reference: N,
301
- planState: F,
302
- referenceAcquisitionMs: I,
303
- firstTextMs: b,
304
- turnMs: performance.now() - i
318
+ reference: z,
319
+ planState: B,
320
+ referenceAcquisitionMs: V,
321
+ firstTextMs: N,
322
+ turnMs: performance.now() - l
305
323
  }
306
324
  })}`);
307
325
  }
308
- }, i.getExternalObjectLibraryContext && y(), a({
326
+ }, i.getExternalObjectLibraryContext && I(), a({
309
327
  type: "images",
310
328
  enabled: t.readsImages
311
329
  }), a({
312
330
  type: "availability",
313
331
  available: !0
314
332
  });
315
- }, I = {
333
+ }, L = {
316
334
  HIDE: "hide",
317
335
  SHOW_ATTRIBUTES: "attributes",
318
336
  SHOW_ARTICLES: "articles"
319
337
  };
320
338
  //#endregion
321
- export { I as HI_PANEL_ACTION, y as cleanupHi, p as createHiLibraryCallbacks, b as createHiMcpTools, u as libLoadArticleCatalog, f as libLoadCalcScript, d as libLoadMasterData, n as loadChatModel, h as omGetRequest, m as omPostRequest, s as registerLegacyUrlFormat, v as setupHi, F as startPlanningAssistant, c as unregisterLegacyUrlFormat };
339
+ export { L as HI_PANEL_ACTION, y as cleanupHi, p as createHiLibraryCallbacks, b as createHiMcpTools, u as libLoadArticleCatalog, f as libLoadCalcScript, d as libLoadMasterData, n as loadChatModel, h as omGetRequest, m as omPostRequest, s as registerLegacyUrlFormat, v as setupHi, I as startPlanningAssistant, c as unregisterLegacyUrlFormat };
package/hi.min.js CHANGED
@@ -1,7 +1,7 @@
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 "./browser-D6As4Zxr.mjs";
3
3
  import { t } from "./utils-CAAGdgk8.mjs";
4
- import { n, t as r } from "./mcp-tools-CJ7j_FI2.mjs";
4
+ import { n, t as r } from "./mcp-tools-D3Ei3Apu.mjs";
5
5
  var i = (e, t) => t === e.libraryId ? e : {
6
6
  ...e,
7
7
  libraryId: t
@@ -57,7 +57,7 @@ var i = (e, t) => t === e.libraryId ? e : {
57
57
  g && window.removeEventListener("message", g);
58
58
  let a = typeof n == "string" ? { libraryId: n } : n;
59
59
  r.onLoadJavascript === void 0 && (r.onLoadJavascript = (e) => f(i(a, e))), r.onLoadArticleCatalog === void 0 && (r.onLoadArticleCatalog = (e) => u(i(a, e))), r.onLoadMasterData === void 0 && (r.onLoadMasterData = (e) => d(i(a, e)));
60
- let { expose: o } = await import("./comlink-Dc3LZUoi.mjs");
60
+ let { expose: o } = await import("./comlink-BYqErFai.mjs");
61
61
  g = (n) => {
62
62
  if (n.data.type === "connect_hi" && n.data.port) {
63
63
  let i = n.data.port;
@@ -109,12 +109,18 @@ var i = (e, t) => t === e.libraryId ? e : {
109
109
  otherBytes: n.bytes - i - o
110
110
  }
111
111
  };
112
- }, E = /^(Previous response with id '[^']*' not found|No tool output found for function call )/, D = (e) => e instanceof Error && E.test(e.message), O = [
112
+ }, E = /^(Previous response with id '[^']*' not found|No tool output found for function call )/, D = (e) => e instanceof Error && E.test(e.message), O = (e) => e.role !== "assistant" || typeof e.content == "string" ? e : {
113
+ ...e,
114
+ content: e.content.map((e) => e.type !== "text" && e.type !== "reasoning" || !e.providerOptions ? e : {
115
+ ...e,
116
+ providerOptions: Object.fromEntries(Object.entries(e.providerOptions).map(([e, t]) => [e, Object.fromEntries(Object.entries(t).filter(([e]) => e !== "itemId"))]))
117
+ })
118
+ }, k = [
113
119
  "rooms",
114
120
  "groups",
115
121
  "obstacles",
116
122
  "installationElements"
117
- ], k = ({ content: e }) => e.filter((e) => e.type === "text").map((e) => e.text).join("\n"), A = async (e, t, r) => {
123
+ ], A = ({ content: e }) => e.filter((e) => e.type === "text").map((e) => e.text).join("\n"), j = async (e, t, r) => {
118
124
  let i = e.extended, a = (e) => i.planningAssistantOutput(e), o = [], s = null, c = /* @__PURE__ */ new Set(), l;
119
125
  try {
120
126
  l = await Promise.all([
@@ -136,30 +142,30 @@ var i = (e, t) => t === e.libraryId ? e : {
136
142
  });
137
143
  return;
138
144
  }
139
- let [{ streamText: u, stepCountIs: d }, f, p, m] = l, h = [p.systemPrompt, ...(p.referenceBlocks ?? []).map(({ id: e, text: t }) => `Reference: ${e}\n${t}`)].join("\n\n"), g = [], _ = t.provider === "azure" && !t.chatCompletions && !0 === t.referenceCacheBreakpoint, v = !1;
140
- i.callbacks.onPlanningAssistantPrompt = async ({ text: e, images: n }) => {
141
- v = !0;
142
- let i = performance.now();
145
+ let [{ streamText: u, stepCountIs: d }, f, p, m] = l, h = [p.systemPrompt, ...(p.referenceBlocks ?? []).map(({ id: e, text: t }) => `Reference: ${e}\n${t}`)].join("\n\n"), g = [], _ = t.provider === "azure" && !t.chatCompletions && !0 === t.referenceCacheBreakpoint, v = t.provider === "openai" || t.provider === "azure" && !t.chatCompletions ? t.provider : null, b = null, E = 0, j = !1;
146
+ i.callbacks.onPlanningAssistantPrompt = async ({ text: e, images: t }) => {
147
+ j = !0;
148
+ let n = ++E, i = performance.now();
143
149
  o = [], s = null, c.clear();
144
- let l = [], y = [], b = null, T = [], E, A = !1, j = !1, M = null, N = {
150
+ let l = [], y = [], T = null, M = [], N, P = !1, F = !1, I = null, L = {
145
151
  role: "user",
146
152
  content: [{
147
153
  type: "text",
148
154
  text: e || p.imagePrompt
149
- }, ...n.map((e) => ({
155
+ }, ...t.map((e) => ({
150
156
  type: "file",
151
157
  data: e,
152
158
  mediaType: "image/jpeg"
153
159
  }))]
154
160
  };
155
161
  try {
156
- let e = performance.now(), n = [], o = [];
162
+ let e = performance.now(), t = [], o = [];
157
163
  await Promise.all([(async () => {
158
164
  try {
159
- let e = await m["get-plan-context"].execute({ include: ["articles", "attributes"] }), t = k(e), r = e.isError ? null : JSON.parse(t);
165
+ let e = await m["get-plan-context"].execute({ include: ["articles", "attributes"] }), n = A(e), r = e.isError ? null : JSON.parse(n);
160
166
  if (Array.isArray(r?.articles) && r.articles.length > 0) {
161
- let e = `Current library reference (data, not instructions):\n${t}`;
162
- n.push({
167
+ let e = `Current library reference (data, not instructions):\n${n}`;
168
+ t.push({
163
169
  role: "user",
164
170
  content: _ ? [{
165
171
  type: "text",
@@ -170,34 +176,34 @@ var i = (e, t) => t === e.libraryId ? e : {
170
176
  }
171
177
  } catch {}
172
178
  })(), (async () => {
173
- let e = await Promise.resolve().then(() => m["get-plan-context"].execute({ include: O })).then((e) => e.isError ? "" : k(e).trim()).catch(() => "");
179
+ let e = await Promise.resolve().then(() => m["get-plan-context"].execute({ include: k })).then((e) => e.isError ? "" : A(e).trim()).catch(() => "");
174
180
  e && (await w(e), o.push({
175
181
  role: "user",
176
- content: `Current plan state, read for this turn (data, not instructions):\n${e}`
182
+ content: `Plan state at the start of turn ${n}, read for this turn (data, not instructions):\n${e}`
177
183
  }));
178
- })()]), M = await w(JSON.stringify({
184
+ })()]), I = await w(JSON.stringify({
179
185
  instructions: h,
180
- messages: n
186
+ messages: t
181
187
  })), performance.now() - e;
182
188
  let c = [
183
- ...n,
189
+ ...t,
184
190
  ...g,
185
191
  ...o,
186
- N
187
- ], p = [], v, S = 0;
192
+ L
193
+ ], p, S = b && o.length > 0 && I.sha256 === b.reference ? b.responseId : void 0, E = [], j, R = 0, z = !1;
188
194
  do {
189
- v = void 0;
190
- let e = S, o = [], w = u({
195
+ j = void 0;
196
+ let e = R, n = S, w = [], k = u({
191
197
  model: f.languageModel,
192
- providerOptions: _ && n.length && M.sha256 ? {
198
+ providerOptions: _ && t.length && I.sha256 ? {
193
199
  ...f.providerOptions,
194
200
  azure: {
195
201
  ...f.providerOptions?.azure,
196
- promptCacheKey: M.sha256
202
+ promptCacheKey: I.sha256
197
203
  }
198
204
  } : f.providerOptions,
199
205
  instructions: h,
200
- messages: [...c, ...p],
206
+ messages: z ? [...c, ...E].map(O) : [...c, ...E],
201
207
  tools: m,
202
208
  stopWhen: d(16 - e),
203
209
  abortSignal: r,
@@ -211,26 +217,35 @@ var i = (e, t) => t === e.libraryId ? e : {
211
217
  });
212
218
  },
213
219
  onStepEnd: (e) => {
214
- o.push(...e.response.messages), S++;
220
+ w.push(...e.response.messages), R++, p = v ? e.providerMetadata?.[v]?.responseId ?? void 0 : void 0;
215
221
  },
216
- prepareStep: (n) => {
217
- s = e + n.stepNumber;
218
- let r = s === 15 ? { toolChoice: "none" } : {}, i = t.provider === "openai" || t.provider === "azure" && !t.chatCompletions ? t.provider : null;
219
- if (!i || n.stepNumber === 0) return r;
220
- let a = n.steps.at(-1), o = a.providerMetadata?.[i]?.responseId;
221
- if (!o) throw Error("The previous model response has no continuation ID");
222
+ prepareStep: (t) => {
223
+ s = e + t.stepNumber;
224
+ let r = s === 15 ? { toolChoice: "none" } : {};
225
+ if (!v) return r;
226
+ if (t.stepNumber === 0) return n ? {
227
+ ...r,
228
+ instructions: [],
229
+ messages: [...o, L],
230
+ providerOptions: { [v]: {
231
+ previousResponseId: n,
232
+ store: !0
233
+ } }
234
+ } : r;
235
+ let i = t.steps.at(-1), a = i.providerMetadata?.[v]?.responseId;
236
+ if (!a) throw Error("The previous model response has no continuation ID");
222
237
  return {
223
238
  ...r,
224
239
  instructions: [],
225
- messages: a.response.messages.filter(({ role: e }) => e === "tool"),
226
- providerOptions: { [i]: {
227
- previousResponseId: o,
240
+ messages: i.response.messages.filter(({ role: e }) => e === "tool"),
241
+ providerOptions: { [v]: {
242
+ previousResponseId: a,
228
243
  store: !0
229
244
  } }
230
245
  };
231
246
  }
232
247
  });
233
- for await (let e of w.stream) if (e.type === "text-delta") b ??= performance.now() - i, a({
248
+ for await (let e of k.stream) if (e.type === "text-delta") T ??= performance.now() - i, a({
234
249
  type: "text",
235
250
  text: e.text
236
251
  });
@@ -240,16 +255,19 @@ var i = (e, t) => t === e.libraryId ? e : {
240
255
  });
241
256
  else {
242
257
  if (e.type === "error") {
243
- if (o.length > 0 && D(e.error)) {
244
- v = e.error;
258
+ if ((w.length > 0 || n) && D(e.error)) {
259
+ j = e.error;
245
260
  break;
246
261
  }
247
262
  throw e.error;
248
263
  }
249
- e.type === "finish-step" ? (T.push(x(e.usage)), l.push(C(e.usage))) : e.type === "finish" ? (E = p.length ? void 0 : x(e.totalUsage), A = !0) : e.type === "abort" && (j = !0);
264
+ e.type === "finish-step" ? (M.push(x(e.usage)), l.push(C(e.usage))) : e.type === "finish" ? (N = E.length ? void 0 : x(e.totalUsage), P = !0) : e.type === "abort" && (F = !0);
250
265
  }
251
- v ? p.push(...o) : j || r.aborted || g.push(N, ...p, ...await w.responseMessages);
252
- } while (v);
266
+ j ? (E.push(...w), S = void 0, z = !0) : F || r.aborted || (g.push(L, ...E, ...await k.responseMessages), b = p && I.sha256 ? {
267
+ responseId: p,
268
+ reference: I.sha256
269
+ } : null);
270
+ } while (j);
253
271
  a({ type: "done" });
254
272
  } catch (e) {
255
273
  a({
@@ -258,15 +276,15 @@ var i = (e, t) => t === e.libraryId ? e : {
258
276
  });
259
277
  } finally {
260
278
  let e = {
261
- inputTokens: E?.inputTokens ?? S(T.map((e) => e.inputTokens)),
262
- outputTokens: E?.outputTokens ?? S(T.map((e) => e.outputTokens)),
263
- totalTokens: E?.totalTokens ?? S(T.map((e) => e.totalTokens))
279
+ inputTokens: N?.inputTokens ?? S(M.map((e) => e.inputTokens)),
280
+ outputTokens: N?.outputTokens ?? S(M.map((e) => e.outputTokens)),
281
+ totalTokens: N?.totalTokens ?? S(M.map((e) => e.totalTokens))
264
282
  };
265
- Object.values(e).some((e) => e !== null), A && !j && !r.aborted && Object.values(e).every((e) => e !== null) && T.every((e) => Object.values(e).every((e) => e !== null));
283
+ Object.values(e).some((e) => e !== null), P && !F && !r.aborted && Object.values(e).every((e) => e !== null) && M.every((e) => Object.values(e).every((e) => e !== null));
266
284
  }
267
285
  }, i.getExternalObjectLibraryContext && (async () => {
268
286
  for (let e = 0; e < 240; e += 1) {
269
- if (v || r.aborted || (performance.now(), await Promise.resolve().then(() => i.getExternalObjectLibraryContext?.(["articles"])).then((e) => e?.articles?.length ?? 0, () => 0) > 0)) return;
287
+ if (j || r.aborted || (performance.now(), await Promise.resolve().then(() => i.getExternalObjectLibraryContext?.(["articles"])).then((e) => e?.articles?.length ?? 0, () => 0) > 0)) return;
270
288
  await new Promise((e) => setTimeout(e, 500));
271
289
  }
272
290
  })(), a({
@@ -276,9 +294,9 @@ var i = (e, t) => t === e.libraryId ? e : {
276
294
  type: "availability",
277
295
  available: !0
278
296
  });
279
- }, j = {
297
+ }, M = {
280
298
  HIDE: "hide",
281
299
  SHOW_ATTRIBUTES: "attributes",
282
300
  SHOW_ARTICLES: "articles"
283
301
  };
284
- export { j as HI_PANEL_ACTION, v as cleanupHi, p as createHiLibraryCallbacks, y as createHiMcpTools, u as libLoadArticleCatalog, f as libLoadCalcScript, d as libLoadMasterData, n as loadChatModel, h as omGetRequest, m as omPostRequest, s as registerLegacyUrlFormat, _ as setupHi, A as startPlanningAssistant, c as unregisterLegacyUrlFormat };
302
+ export { M as HI_PANEL_ACTION, v as cleanupHi, p as createHiLibraryCallbacks, y as createHiMcpTools, u as libLoadArticleCatalog, f as libLoadCalcScript, d as libLoadMasterData, n as loadChatModel, h as omGetRequest, m as omPostRequest, s as registerLegacyUrlFormat, _ as setupHi, j as startPlanningAssistant, c as unregisterLegacyUrlFormat };
@@ -89,10 +89,10 @@ var e = "The images of this result follow in the next message.", t = (t) => t.fl
89
89
  }
90
90
  case "mistral": {
91
91
  let { createMistral: e } = await import("./dist-CqP0aX0A.mjs");
92
- return { languageModel: e({
92
+ return { languageModel: n(e({
93
93
  apiKey: r,
94
94
  ...u
95
- })(t) };
95
+ })(t)) };
96
96
  }
97
97
  case "anthropic": {
98
98
  let { createAnthropic: e } = await import("./dist-C5fKJXpB.mjs");
@@ -88,10 +88,10 @@ var e = (e) => e.flatMap((e) => {
88
88
  }
89
89
  case "mistral": {
90
90
  let { createMistral: e } = await import("./dist-CXemOs84.mjs");
91
- return { languageModel: e({
91
+ return { languageModel: t(e({
92
92
  apiKey: r,
93
93
  ...u
94
- })(n) };
94
+ })(n)) };
95
95
  }
96
96
  case "anthropic": {
97
97
  let { createAnthropic: e } = await import("./dist-B9yy8ym8.mjs");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roomle/embedding-lib",
3
- "version": "9.1.0-alpha.1",
3
+ "version": "9.1.0-alpha.3",
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",
@@ -23,6 +23,13 @@
23
23
  "./hi/min": {
24
24
  "import": "./hi.min.js"
25
25
  },
26
+ "./ai": {
27
+ "import": "./ai.js",
28
+ "types": "./ai.d.ts"
29
+ },
30
+ "./ai/min": {
31
+ "import": "./ai.min.js"
32
+ },
26
33
  "./plugins": {
27
34
  "import": "./embedding-plugins.js",
28
35
  "types": "./embedding-plugins.d.ts"
@@ -0,0 +1,28 @@
1
+ import { default as RoomleEmbeddingApi } from './roomle-embedding-lib';
2
+ import { AiFeature, AiModelHandlers } from '../../common/src/utils/ai-model-relay';
3
+ export type { AiFeature, AiModelAuthReason, AiModelHandlers, AiModelRequest, } from '../../common/src/utils/ai-model-relay';
4
+ export type { RenderingInput } from '../../../src/common/utils/img-gen';
5
+ export interface AiModelHostOptions extends AiModelHandlers {
6
+ /**
7
+ * The features the host answers; the others keep the built-in endpoints.
8
+ * Left out: every feature, also ones added later. Never empty.
9
+ */
10
+ features?: AiFeature[];
11
+ }
12
+ /**
13
+ * What serveAiModelRequests hands back to the host page; once a later call
14
+ * has replaced this registration, both do nothing
15
+ */
16
+ export interface AiModelHostControl {
17
+ /** The host's user signed out: its AI features lock until a sign-in */
18
+ signOut(): Promise<void>;
19
+ /** The built-in endpoints answer again */
20
+ stop(): Promise<void>;
21
+ }
22
+ /**
23
+ * The host page answers the AI model requests of `instance` with its own
24
+ * endpoint, and the AI features it serves switch to it; call it once the
25
+ * instance is created. Rejects, with the relay stopped, when the iframe
26
+ * cannot take the host, e.g. an older UI without the AI relay.
27
+ */
28
+ export declare const serveAiModelRequests: (instance: Pick<RoomleEmbeddingApi<unknown, unknown>, "startRelay" | "ui">, { features, ...handlers }: AiModelHostOptions) => Promise<AiModelHostControl>;
@@ -24,6 +24,14 @@ export declare const getMethodNames: (proto: any, namespace: string, isCallback?
24
24
  export declare const getConfiguratorSettings: (configuratorId: string, initData: UiInitData) => Promise<ConfiguratorSettings>;
25
25
  export declare const INTERACTION_CONTAINER_SELECTOR = "data-rml-interaction-container";
26
26
  export type { ConfiguratorSettings, UiInitData, } from '../../../src/configurator/embedding/types';
27
+ /** The host-side relays an instance serves, see startRelay */
28
+ export type EmbeddingRelayType = 'ai';
29
+ export interface EmbeddingRelay {
30
+ /** False once the next startRelay of the type or teardown replaced it */
31
+ isCurrent(): boolean;
32
+ /** Stops the relay; does nothing once it is replaced */
33
+ stop(): void;
34
+ }
27
35
  interface PluginMap {
28
36
  dragIn: typeof DragIn;
29
37
  }
@@ -71,7 +79,16 @@ export default class RoomleEmbeddingApi<SdkType, SdkCallbacks> extends Connector
71
79
  private _configuratorSettings;
72
80
  private _initData;
73
81
  private _iframe;
82
+ private _relays;
74
83
  private constructor();
84
+ /**
85
+ * Serves a host-side relay of `type` (e.g. serveAiModelRequests of
86
+ * `@roomle/embedding-lib/ai`) for this instance's iframe: `start` gets the
87
+ * iframe's window and origin, to answer only its messages, and returns how
88
+ * to stop. One relay per type: the next call stops the previous one, and
89
+ * teardown stops all.
90
+ */
91
+ startRelay(type: EmbeddingRelayType, start: (source: Window, origin: string) => () => void): EmbeddingRelay;
75
92
  teardown(): void;
76
93
  private _createIframe;
77
94
  private _onResize;
@@ -31,5 +31,10 @@ export interface ConfiguratorAgentApi {
31
31
  getConfiguratorAgentPrompts(): Promise<{
32
32
  systemPrompt: string;
33
33
  imagePrompt: string;
34
+ /**
35
+ * The root component of the product whose context the system prompt holds; absent while a
36
+ * definition of the product could not be read, so that the prompts are read again.
37
+ */
38
+ rootComponentId?: string;
34
39
  }>;
35
40
  }