@roomle/embedding-lib 11.0.0-alpha.6 → 11.0.0-alpha.8

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 (69) hide show
  1. package/THIRD-PARTY-NOTICES.txt +1 -1
  2. package/ai.js +6 -6
  3. package/ai.min.js +5 -4
  4. package/{browser-D6M-d6y5.mjs → browser-Cys-y5Hy.mjs} +1 -2
  5. package/chat-model-B7BO8IhK.mjs +212 -0
  6. package/chat-model-XYf503pT.mjs +213 -0
  7. package/coerce-CuLRCRlo.mjs +6 -0
  8. package/coerce-Dup0o-HR.mjs +7 -0
  9. package/{comlink-CG3f9q6z.mjs → comlink-7u13Z2ZH.mjs} +2 -3
  10. package/{comlink-hSUzCx9j.mjs → comlink-DKhvPU0o.mjs} +1 -1
  11. package/configurator.js +3 -4
  12. package/configurator.min.js +2 -2
  13. package/construction.js +278 -24
  14. package/construction.min.js +284 -27
  15. package/continuation-CswXtOus.mjs +10 -0
  16. package/continuation-NclHDSgS.mjs +9 -0
  17. package/{dist-Cm3aF4sf.mjs → dist-7-X7Xqsl.mjs} +851 -919
  18. package/{dist-BQaw78-_.mjs → dist-BMxyw-Zs.mjs} +411 -405
  19. package/{dist-0WZWTj8T.mjs → dist-BU022PnG.mjs} +4 -9
  20. package/{dist-DkR6G9Kj.mjs → dist-BY8OLJ2p.mjs} +1 -1
  21. package/{dist-6TznX-Ae.mjs → dist-BZSd56sr.mjs} +3850 -3942
  22. package/{dist-70R0b5Mq.mjs → dist-Ba3J8AjB.mjs} +400 -390
  23. package/{dist-CTS0DDwt.mjs → dist-CbQKC1xX.mjs} +1590 -1616
  24. package/{dist-BmOBP9h9.mjs → dist-CiybWJvs.mjs} +44 -41
  25. package/{dist-CPG4atmb.mjs → dist-CkZuNdCU.mjs} +6 -4
  26. package/{dist-Bt1FopV4.mjs → dist-D2ZAAHGn.mjs} +1058 -1042
  27. package/{dist-BWNv7qW9.mjs → dist-DjsS42rR.mjs} +916 -962
  28. package/{dist-9UI7dzwc.mjs → dist-Jcq_kKKT.mjs} +403 -393
  29. package/{dist-D0XFfKEL.mjs → dist-S9sLSjZ4.mjs} +3112 -3104
  30. package/{dist-BV-32IEX.mjs → dist-XECXrV5Q.mjs} +1497 -1558
  31. package/{dist-Bc2s-kJZ.mjs → dist-a5_BIeaS.mjs} +45 -51
  32. package/{dist-Crrp-Bno.mjs → dist-bQAJDeYc.mjs} +698 -748
  33. package/docs/md/web/embedding/CHANGELOG.md +19 -64
  34. package/{drag-ghost-BpIDzSdK.mjs → drag-ghost-QZelgA-_.mjs} +2 -3
  35. package/{drag-ghost-Bhb0_67G.mjs → drag-ghost-VmgSWLva.mjs} +5 -7
  36. package/{drag-in-mE_ozj_Q.mjs → drag-in-Cd_67tzS.mjs} +4 -5
  37. package/{drag-in-CGBG4wEk.mjs → drag-in-DlDsgY4T.mjs} +3 -3
  38. package/embedding-plugins.js +1 -2
  39. package/embedding-plugins.min.js +1 -2
  40. package/{experimental-evaluation-FzKFGoye.mjs → experimental-evaluation-B4hKMgFH.mjs} +19 -38
  41. package/{experimental-evaluation-DczxmJme.mjs → experimental-evaluation-DmqghFSx.mjs} +1 -1
  42. package/{from-custom-view-B3fIWMox.mjs → from-custom-view-6HMD_sPe.mjs} +5 -4
  43. package/{from-custom-view-B3HCOhdT.mjs → from-custom-view-BRFynafo.mjs} +16 -16
  44. package/{from-website-DaTahmvJ.mjs → from-website-Dl1VN4h7.mjs} +5 -6
  45. package/{from-website-DUQ9USj1.mjs → from-website-iZzauH4C.mjs} +3 -3
  46. package/hi.js +188 -197
  47. package/hi.min.js +193 -194
  48. package/mcp-tools-BLB7pCga.mjs +42 -0
  49. package/mcp-tools-BirFT2R0.mjs +41 -0
  50. package/package.json +1 -1
  51. package/packages/web-sdk/packages/assistant.d.ts +1 -0
  52. package/packages/web-sdk/packages/common-core/src/planning-assistant/runtime.d.ts +4 -1
  53. package/packages/web-sdk/packages/common-core/src/planning-assistant.d.ts +3 -0
  54. package/rolldown-runtime--db92txo.mjs +10 -0
  55. package/rolldown-runtime-CyjYJMBa.mjs +11 -0
  56. package/roomle-embedding-lib.js +25 -34
  57. package/roomle-embedding-lib.min.js +3 -3
  58. package/sbom.cdx.json +5 -5
  59. package/turn-limits-9LbUeSG2.mjs +9 -0
  60. package/turn-limits-Ciq383Bd.mjs +10 -0
  61. package/{utils-BwWn6Fw4.mjs → utils-CJnKZceY.mjs} +3 -4
  62. package/{utils-BoELtcEK.mjs → utils-DdNhTbJr.mjs} +6 -6
  63. package/chat-model-CZfZsgX9.mjs +0 -377
  64. package/chat-model-vgLJamoj.mjs +0 -373
  65. package/coerce-CqJod_GZ.mjs +0 -8
  66. package/coerce-CsI42_k0.mjs +0 -6
  67. package/mcp-tools-8qPMNqTK.mjs +0 -2
  68. package/mcp-tools-D_GxXscW.mjs +0 -2
  69. /package/{browser-BjtSrqbu.mjs → browser-CzLpXYFF.mjs} +0 -0
package/hi.js CHANGED
@@ -1,12 +1,14 @@
1
1
  /*! Third-party licenses: THIRD-PARTY-NOTICES.txt and sbom.cdx.json in the root of this package */
2
- import { t as e } from "./browser-D6M-d6y5.mjs";
3
- import { t } from "./utils-BwWn6Fw4.mjs";
4
- import { a as n, i as r, o as i, r as a } from "./chat-model-CZfZsgX9.mjs";
5
- import "./mcp-tools-8qPMNqTK.mjs";
6
- var o = (e, t) => t === e.libraryId ? e : {
2
+ import { t as e } from "./utils-CJnKZceY.mjs";
3
+ import { t } from "./browser-Cys-y5Hy.mjs";
4
+ import { t as n } from "./mcp-tools-BLB7pCga.mjs";
5
+ import { a as r, r as i } from "./turn-limits-Ciq383Bd.mjs";
6
+ import { n as a } from "./chat-model-XYf503pT.mjs";
7
+ import { n as o } from "./continuation-CswXtOus.mjs";
8
+ var s = (e, t) => t === e.libraryId ? e : {
7
9
  ...e,
8
10
  libraryId: t
9
- }, s = async (e, t, n, r = { property: "default" }) => {
11
+ }, c = async (e, t, n, r = { property: "default" }) => {
10
12
  let i = n.serverOptions ?? {}, a = { headers: {
11
13
  "Content-Type": t === "json" ? "application/json" : "text/plain",
12
14
  "Access-Control-Allow-Origin": "*"
@@ -19,72 +21,69 @@ var o = (e, t) => t === e.libraryId ? e : {
19
21
  } catch (e) {
20
22
  throw console.warn(`Failed to fetch data from ${r.property}`), console.error(e), e;
21
23
  }
22
- }, c = { "e2fe8b3d-da31-4a20-92ab-ab6e3839300e": new Set(["Furniture_Smith"]) }, l = (e, t) => {
23
- c[e] || (c[e] = /* @__PURE__ */ new Set()), c[e].add(t);
24
- }, u = (e, t) => {
25
- c[e]?.delete(t), c[e]?.size === 0 && delete c[e];
24
+ }, l = { "e2fe8b3d-da31-4a20-92ab-ab6e3839300e": /* @__PURE__ */ new Set(["Furniture_Smith"]) }, u = (e, t) => {
25
+ l[e] || (l[e] = /* @__PURE__ */ new Set()), l[e].add(t);
26
26
  }, d = (e, t) => {
27
+ l[e]?.delete(t), l[e]?.size === 0 && delete l[e];
28
+ }, f = (e, t) => {
27
29
  let { libraryId: n, serverOptions: r } = e;
28
- return r?.subscriptionId && c[r.subscriptionId]?.has(n) ? `api/pos/${t}?libraryId=${n}` : `api/pos/libraries/${n}/${t}`;
29
- }, 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) => {
30
- let t = await (await s(d(e, "calc.js"), "text", e, { property: "calc.js" })).text();
30
+ return r?.subscriptionId && l[r.subscriptionId]?.has(n) ? `api/pos/${t}?libraryId=${n}` : `api/pos/libraries/${n}/${t}`;
31
+ }, p = async (e) => await (await c(f(e, "articles"), "json", e, { property: "articles" })).json(), m = async (e) => await (await c(f(e, "masterData"), "json", e, { property: "masterData" })).json(), h = async (e) => {
32
+ let t = await (await c(f(e, "calc.js"), "text", e, { property: "calc.js" })).text();
31
33
  if (!t) throw Error("Script load error");
32
34
  return t;
33
- }, h = (e) => ({
34
- onLoadJavascript: (t) => m(o(e, t)),
35
- onLoadArticleCatalog: (t) => f(o(e, t)),
36
- onLoadMasterData: (t) => p(o(e, t))
37
- }), g = async (e, t, n, r = {}) => {
38
- let { baseUrl: i, om: a } = e.serverOptions ?? {}, o = encodeURIComponent(a?.endpointUrl || ""), s = encodeURIComponent(a?.subscriptionId || ""), c = a?.key || "";
39
- return await (await fetch((i ?? "https://europe-west3-rml-showcases.cloudfunctions.net/proxy_request?url=") + `${encodeURIComponent(n)}&subscriptionId=${s}&apiKey=${c}&baseUrl=${o}`, {
40
- method: "POST",
41
- body: JSON.stringify(t),
35
+ }, g = (e) => ({
36
+ onLoadJavascript: (t) => h(s(e, t)),
37
+ onLoadArticleCatalog: (t) => p(s(e, t)),
38
+ onLoadMasterData: (t) => m(s(e, t))
39
+ }), _ = async (e, t, n, r) => {
40
+ 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}`, {
41
+ ...n,
42
42
  headers: {
43
43
  "Content-Type": "application/json",
44
44
  ...r
45
45
  }
46
- })).json();
47
- }, _ = async (e, t, n = {}) => {
48
- let { baseUrl: r, om: i } = e.serverOptions ?? {}, a = encodeURIComponent(i?.endpointUrl || ""), o = encodeURIComponent(i?.subscriptionId || ""), s = i?.key || "";
49
- return await (await fetch((r ?? "https://europe-west3-rml-showcases.cloudfunctions.net/proxy_request?url=") + `${encodeURIComponent(t)}&subscriptionId=${o}&apiKey=${s}&baseUrl=${a}`, {
50
- method: "GET",
51
- headers: {
52
- "Content-Type": "application/json",
53
- ...n
54
- }
55
- })).json();
56
- }, v = (t, n) => {
57
- t.serverOptions ||= {}, !t.serverOptions.language && n?.locale && (t.serverOptions.language = n.locale), t.serverOptions.language || (t.serverOptions.language = e(null, !0));
58
- }, y = null, b = async (e, n = {}) => {
59
- y && window.removeEventListener("message", y);
60
- let r = typeof e == "string" ? { libraryId: e } : e;
61
- n.onLoadJavascript === void 0 && (n.onLoadJavascript = (e) => m(o(r, e))), n.onLoadArticleCatalog === void 0 && (n.onLoadArticleCatalog = (e) => f(o(r, e))), n.onLoadMasterData === void 0 && (n.onLoadMasterData = (e) => p(o(r, e)));
62
- let { expose: i } = await import("./comlink-CG3f9q6z.mjs");
63
- y = (e) => {
64
- if (e.data.type === "connect_hi" && e.data.port) {
65
- let a = e.data.port;
66
- v(r, e.data.globalInitData || {}), a.start?.(), i(t(n), a);
46
+ });
47
+ if (!l.ok) {
48
+ let e = `HTTP ${l.status} ${l.statusText}`.trimEnd(), n = await l.text();
49
+ throw Error(`Order Manager request ${t} failed with ${e}${n ? `: ${n}` : ""}`);
50
+ }
51
+ return l.json();
52
+ }, v = async (e, t, n, r = {}) => _(e, n, {
53
+ method: "POST",
54
+ body: JSON.stringify(t)
55
+ }, r), y = async (e, t, n = {}) => _(e, t, { method: "GET" }, n), b = (e, n) => {
56
+ e.serverOptions ||= {}, !e.serverOptions.language && n?.locale && (e.serverOptions.language = n.locale), e.serverOptions.language || (e.serverOptions.language = t(null, !0));
57
+ }, x = null, S = async (t, n = {}) => {
58
+ x && window.removeEventListener("message", x);
59
+ let r = typeof t == "string" ? { libraryId: t } : t;
60
+ n.onLoadJavascript === void 0 && (n.onLoadJavascript = (e) => h(s(r, e))), n.onLoadArticleCatalog === void 0 && (n.onLoadArticleCatalog = (e) => p(s(r, e))), n.onLoadMasterData === void 0 && (n.onLoadMasterData = (e) => m(s(r, e)));
61
+ let { expose: i } = await import("./comlink-7u13Z2ZH.mjs");
62
+ x = (t) => {
63
+ if (t.data.type === "connect_hi" && t.data.port) {
64
+ let a = t.data.port;
65
+ b(r, t.data.globalInitData || {}), a.start?.(), i(e(n), a);
67
66
  }
68
- }, window.addEventListener("message", y);
69
- }, x = () => {
70
- y &&= (window.removeEventListener("message", y), null);
71
- }, S = async ({ extended: e }) => {
67
+ }, window.addEventListener("message", x);
68
+ }, C = () => {
69
+ x &&= (window.removeEventListener("message", x), null);
70
+ }, w = async ({ extended: e }) => {
72
71
  if (typeof e.getExternalObjectAgentTools != "function") throw Error("The planner has no HI agent tools: it needs a Rubens UI with getExternalObjectAgentTools.");
73
72
  return n(await e.getExternalObjectAgentTools(), (t, n) => e.callExternalObjectAgentTool(t, n), "hi-mcp");
74
- }, C = (e) => typeof e == "number" && Number.isSafeInteger(e) && e >= 0 ? e : null, w = (e = {}) => ({
75
- inputTokens: C(e.inputTokens),
76
- outputTokens: C(e.outputTokens),
77
- totalTokens: C(e.totalTokens) ?? (C(e.inputTokens) !== null && C(e.outputTokens) !== null ? e.inputTokens + e.outputTokens : null)
78
- }), T = (e) => e.some((e) => e !== null) ? e.reduce((e, t) => e + (t ?? 0), 0) : null, E = (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 = C(n?.cached_tokens ?? t?.cache_read_input_tokens), a = C(n?.cache_write_tokens ?? t?.cache_creation_input_tokens), o = (e, t) => t ?? (C(e) !== null && Number(e) > 0 ? Number(e) : null);
73
+ }, T = (e) => typeof e == "number" && Number.isSafeInteger(e) && e >= 0 ? e : null, E = (e = {}) => ({
74
+ inputTokens: T(e.inputTokens),
75
+ outputTokens: T(e.outputTokens),
76
+ totalTokens: T(e.totalTokens) ?? (T(e.inputTokens) !== null && T(e.outputTokens) !== null ? e.inputTokens + e.outputTokens : null)
77
+ }), D = (e) => e.some((e) => e !== null) ? e.reduce((e, t) => e + (t ?? 0), 0) : null, O = (e = {}) => {
78
+ let t = e.raw, n = t?.input_tokens_details ?? t?.prompt_tokens_details, r = t?.output_tokens_details ?? t?.completion_tokens_details, i = T(n?.cached_tokens ?? t?.cache_read_input_tokens), a = T(n?.cache_write_tokens ?? t?.cache_creation_input_tokens), o = (e, t) => t ?? (T(e) !== null && Number(e) > 0 ? Number(e) : null);
80
79
  return {
81
80
  cacheReadTokens: o(e.inputTokenDetails?.cacheReadTokens, i),
82
81
  cacheWriteTokens: o(e.inputTokenDetails?.cacheWriteTokens, a),
83
- noCacheTokens: i !== null && a !== null ? C(e.inputTokenDetails?.noCacheTokens) : null,
84
- reasoningTokens: o(e.outputTokenDetails?.reasoningTokens, C(r?.reasoning_tokens)),
82
+ noCacheTokens: i !== null && a !== null ? T(e.inputTokenDetails?.noCacheTokens) : null,
83
+ reasoningTokens: o(e.outputTokenDetails?.reasoningTokens, T(r?.reasoning_tokens)),
85
84
  rawUsageAvailable: t !== void 0
86
85
  };
87
- }, D = (e) => Object.fromEntries([
86
+ }, k = (e) => Object.fromEntries([
88
87
  "cacheReadTokens",
89
88
  "cacheWriteTokens",
90
89
  "noCacheTokens",
@@ -92,23 +91,23 @@ var o = (e, t) => t === e.libraryId ? e : {
92
91
  ].map((t) => {
93
92
  let n = e.map((e) => e[t]), r = n.filter((e) => e !== null).length;
94
93
  return [t, {
95
- tokens: T(n),
94
+ tokens: D(n),
96
95
  status: r === 0 ? "unavailable" : r === e.length ? "complete" : "partial",
97
96
  reportedSteps: r,
98
97
  observedSteps: e.length
99
98
  }];
100
- })), O = async (e) => {
99
+ })), A = async (e) => {
101
100
  let t = new TextEncoder().encode(e), n = await globalThis.crypto?.subtle?.digest("SHA-256", t);
102
101
  return {
103
102
  bytes: t.byteLength,
104
103
  sha256: n ? Array.from(new Uint8Array(n), (e) => e.toString(16).padStart(2, "0")).join("") : null
105
104
  };
106
- }, k = async (e, t) => {
107
- let n = await O(e), r = JSON.parse(e);
105
+ }, j = async (e, t) => {
106
+ let n = await A(e), r = JSON.parse(e);
108
107
  if (!Array.isArray(r.input)) return n;
109
108
  let i = 0, a = 0;
110
109
  for (let e of r.input) {
111
- let n = await O(JSON.stringify(e));
110
+ let n = await A(JSON.stringify(e));
112
111
  i += n.bytes, n.sha256 === null ? a = null : (t.has(n.sha256) && a !== null && (a += n.bytes), t.add(n.sha256));
113
112
  }
114
113
  let o = r.tools ? new TextEncoder().encode(JSON.stringify(r.tools)).length : 0;
@@ -122,13 +121,13 @@ var o = (e, t) => t === e.libraryId ? e : {
122
121
  otherBytes: n.bytes - i - o
123
122
  }
124
123
  };
125
- }, A = 16, j = (e) => {
124
+ }, M = (e) => {
126
125
  let t = [e?.present.length ? `- Confirmed: ${e.present.join(", ")}` : "", e?.absent.length ? `- Not present / false: ${e.absent.join(", ")}` : ""].filter(Boolean);
127
126
  return t.length === 0 ? "" : `Observed in the photo (high-confidence cues; verify against the image):\n\n${t.join("\n")}`;
128
127
  }, ee = (e, t) => {
129
- let n = j(t);
128
+ let n = M(t);
130
129
  return n ? `${e.replace(/\n*$/, "\n")}\n---\n\n${n}` : e;
131
- }, M = /^(Previous response with id '[^']*' not found|No tool output found for function call )/, te = (e) => e instanceof Error && M.test(e.message), ne = (e) => e.role !== "assistant" || typeof e.content == "string" ? e : {
130
+ }, N = /^(Previous response with id '[^']*' not found|No tool output found for function call )/, te = (e) => e instanceof Error && N.test(e.message), ne = (e) => e.role !== "assistant" || typeof e.content == "string" ? e : {
132
131
  ...e,
133
132
  content: e.content.map((e) => (e.type === "text" || e.type === "reasoning") && e.providerOptions ? {
134
133
  ...e,
@@ -139,41 +138,41 @@ var o = (e, t) => t === e.libraryId ? e : {
139
138
  "groups",
140
139
  "obstacles",
141
140
  "installationElements"
142
- ], N = 500, P = 240, F = 1500, I = ({ content: e }) => e.filter((e) => e.type === "text").map((e) => e.text).join("\n"), L = async (e, t, n) => {
143
- let o = e.extended, s = !1, c = !1, l = crypto.randomUUID(), u, d, f = n, p = (e) => !s && !f.aborted ? o.planningAssistantOutput(e) : void 0, m = [], h = null, g = /* @__PURE__ */ new Set(), _;
141
+ ], P = 500, F = 240, I = 1500, L = ({ content: e }) => e.filter((e) => e.type === "text").map((e) => e.text).join("\n"), R = async (e, t, n) => {
142
+ let s = e.extended, c = !1, l = !1, u = crypto.randomUUID(), d, f, p = n, m = (e) => !c && !p.aborted ? s.planningAssistantOutput(e) : void 0, h = [], g = null, _ = /* @__PURE__ */ new Set(), v;
144
143
  try {
145
- _ = await Promise.all([
146
- import("./dist-6TznX-Ae.mjs").then((e) => e.t),
147
- i(t, async (e) => {
148
- m.push({
149
- ...await k(e, g),
150
- stepNumber: h
144
+ v = await Promise.all([
145
+ import("./dist-BZSd56sr.mjs").then((e) => e.t),
146
+ a(t, async (e) => {
147
+ h.push({
148
+ ...await j(e, _),
149
+ stepNumber: g
151
150
  });
152
151
  }),
153
- o.getExternalObjectAgentPrompts(),
154
- S(e)
152
+ s.getExternalObjectAgentPrompts(),
153
+ w(e)
155
154
  ]);
156
155
  } catch (e) {
157
- console.log("[planning-assistant]", String(e)), p({
156
+ console.log("[planning-assistant]", String(e)), m({
158
157
  type: "availability",
159
158
  available: !1,
160
159
  text: String(e)
161
160
  });
162
161
  return;
163
162
  }
164
- let [{ streamText: v, stepCountIs: y }, b, x, C] = _, M = [x.systemPrompt, ...(x.referenceBlocks ?? []).map(({ id: e, text: t }) => `Reference: ${e}\n${t}`)].join("\n\n"), L = [], R = t.provider === "azure" && !t.chatCompletions && t.referenceCacheBreakpoint === !0, z = a(t), B = null, V = 0, H = [], U = /* @__PURE__ */ new Set(), W = !1, G = async (e, n, r, i) => {
163
+ let [{ streamText: y, stepCountIs: b }, x, S, C] = v, T = [S.systemPrompt, ...(S.referenceBlocks ?? []).map(({ id: e, text: t }) => `Reference: ${e}\n${t}`)].join("\n\n"), N = [], R = t.provider === "azure" && !t.chatCompletions && t.referenceCacheBreakpoint === !0, z = o(t), B = null, V = 0, H = [], U = /* @__PURE__ */ new Set(), W = !1, G = async (e, n, r, i) => {
165
164
  let a = performance.now();
166
- if (W || !o.getExternalObjectAgentDecisions) return null;
167
- let s;
165
+ if (W || !s.getExternalObjectAgentDecisions) return null;
166
+ let o;
168
167
  try {
169
- let c = o.getExternalObjectAgentDecisions({
168
+ let c = s.getExternalObjectAgentDecisions({
170
169
  text: e,
171
170
  images: n,
172
171
  earlier: r,
173
172
  ...t.decisionApiKey && { apiKey: t.decisionApiKey },
174
173
  ...i.length > 0 && { held: i }
175
174
  }).then((e) => (e?.refused && (W = !0), e), () => null), l = await Promise.race([c, new Promise((e) => {
176
- s = setTimeout(() => e("late"), F);
175
+ o = setTimeout(() => e("late"), I);
177
176
  })]);
178
177
  return {
179
178
  ms: performance.now() - a,
@@ -181,9 +180,9 @@ var o = (e, t) => t === e.libraryId ? e : {
181
180
  late: l === "late"
182
181
  };
183
182
  } finally {
184
- clearTimeout(s);
183
+ clearTimeout(o);
185
184
  }
186
- }, K = () => new Set(L.flatMap((e) => e.role === "assistant" && Array.isArray(e.content) ? e.content.flatMap((e) => {
185
+ }, K = () => new Set(N.flatMap((e) => e.role === "assistant" && Array.isArray(e.content) ? e.content.flatMap((e) => {
187
186
  let t = e.type === "tool-call" && e.toolName === "get-skill" ? e.input : void 0;
188
187
  return t && t.file === void 0 ? [String(t.name)] : [];
189
188
  }) : [])), ie = async (e) => {
@@ -193,35 +192,35 @@ var o = (e, t) => t === e.libraryId ? e : {
193
192
  let t = await C["get-skill"].execute({ name: e });
194
193
  return t.isError ? null : {
195
194
  name: e,
196
- text: I(t)
195
+ text: L(t)
197
196
  };
198
197
  } catch {
199
198
  return null;
200
199
  }
201
200
  }))).filter((e) => e !== null);
202
201
  }, q = !1, J = async () => {
203
- for (let e = 0; e < P; e += 1) {
202
+ for (let e = 0; e < F; e += 1) {
204
203
  if (q || n.aborted) return;
205
- let e = performance.now(), t = await Promise.resolve().then(() => o.getExternalObjectLibraryContext?.(["articles"])).then((e) => e?.articles?.length ?? 0, () => 0);
204
+ let e = performance.now(), t = await Promise.resolve().then(() => s.getExternalObjectLibraryContext?.(["articles"])).then((e) => e?.articles?.length ?? 0, () => 0);
206
205
  if (t > 0) {
207
206
  console.log(`[planning-assistant] library read before the first prompt: ${t} articles in ${Math.round(performance.now() - e)} ms`);
208
207
  return;
209
208
  }
210
- await new Promise((e) => setTimeout(e, N));
209
+ await new Promise((e) => setTimeout(e, P));
211
210
  }
212
211
  }, Y = async ({ text: e, images: n }) => {
213
- d = new AbortController();
214
- let i = r([f, d.signal]);
212
+ f = new AbortController();
213
+ let a = r([p, f.signal]);
215
214
  q = !0;
216
- let a = ++V, o = performance.now();
217
- m = [], h = null, g.clear();
218
- let s = [], c = [], l = null, u = [], _, S = !1, k = !1, N = null, P = null, F = 0, W = null, J = G(e, n, [...H], [...new Set([...U, ...K()])]);
215
+ let o = ++V, s = performance.now();
216
+ h = [], g = null, _.clear();
217
+ let c = [], l = [], u = null, d = [], v, w = !1, j = !1, P = null, F = null, I = 0, W = null, J = G(e, n, [...H], [.../* @__PURE__ */ new Set([...U, ...K()])]);
219
218
  H.push(e || "(an image)");
220
219
  try {
221
- let t = performance.now(), r = [], d = [];
220
+ let t = performance.now(), r = [], f = [];
222
221
  await Promise.all([(async () => {
223
222
  try {
224
- let e = await C["get-plan-context"].execute({ include: ["articles", "attributes"] }), t = I(e), n = e.isError ? null : JSON.parse(t);
223
+ let e = await C["get-plan-context"].execute({ include: ["articles", "attributes"] }), t = L(e), n = e.isError ? null : JSON.parse(t);
225
224
  if (Array.isArray(n?.articles) && n.articles.length > 0) {
226
225
  let e = `Current library reference (data, not instructions):\n${t}`;
227
226
  r.push({
@@ -237,97 +236,93 @@ var o = (e, t) => t === e.libraryId ? e : {
237
236
  console.log("[planning-assistant] reference unavailable; using tools");
238
237
  }
239
238
  })(), (async () => {
240
- let e = await Promise.resolve().then(() => C["get-plan-context"].execute({ include: re })).then((e) => e.isError ? "" : I(e).trim()).catch(() => "");
241
- if (!e) {
242
- console.log("[planning-assistant] plan state unavailable; the model reads it");
243
- return;
244
- }
245
- P = await O(e), d.push({
239
+ let e = await Promise.resolve().then(() => C["get-plan-context"].execute({ include: re })).then((e) => e.isError ? "" : L(e).trim()).catch(() => "");
240
+ e ? (F = await A(e), f.push({
246
241
  role: "user",
247
- content: `Plan state at the start of turn ${a}, read for this turn (data, not instructions):\n${e}`
248
- });
249
- })()]), N = await O(JSON.stringify({
250
- instructions: M,
242
+ content: `Plan state at the start of turn ${o}, read for this turn (data, not instructions):\n${e}`
243
+ })) : console.log("[planning-assistant] plan state unavailable; the model reads it");
244
+ })()]), P = await A(JSON.stringify({
245
+ instructions: T,
251
246
  messages: r
252
- })), F = performance.now() - t;
253
- let f = await J, m = await ie(f?.decisions?.skills ?? []), g = (e) => `call_supplied_skill_${a}_${e + 1}`, T = f?.decisions?.facts, D = m.some(({ name: e }) => e === "image-planning") ? "" : j(T), V = [{
247
+ })), I = performance.now() - t;
248
+ let p = await J, h = await ie(p?.decisions?.skills ?? []), _ = (e) => `call_supplied_skill_${o}_${e + 1}`, D = p?.decisions?.facts, k = h.some(({ name: e }) => e === "image-planning") ? "" : M(D), V = [{
254
249
  role: "user",
255
250
  content: [
256
251
  {
257
252
  type: "text",
258
- text: e || x.imagePrompt
253
+ text: e || S.imagePrompt
259
254
  },
260
255
  ...n.map((e) => ({
261
256
  type: "file",
262
257
  data: e,
263
258
  mediaType: "image/jpeg"
264
259
  })),
265
- ...D ? [{
260
+ ...k ? [{
266
261
  type: "text",
267
- text: D
262
+ text: k
268
263
  }] : []
269
264
  ]
270
- }, ...m.length ? [{
265
+ }, ...h.length ? [{
271
266
  role: "assistant",
272
- content: m.map((e, t) => ({
267
+ content: h.map((e, t) => ({
273
268
  type: "tool-call",
274
- toolCallId: g(t),
269
+ toolCallId: _(t),
275
270
  toolName: "get-skill",
276
271
  input: { name: e.name }
277
272
  }))
278
273
  }, {
279
274
  role: "tool",
280
- content: m.map((e, t) => ({
275
+ content: h.map((e, t) => ({
281
276
  type: "tool-result",
282
- toolCallId: g(t),
277
+ toolCallId: _(t),
283
278
  toolName: "get-skill",
284
279
  output: {
285
280
  type: "content",
286
281
  value: [{
287
282
  type: "text",
288
- text: e.name === "image-planning" ? ee(e.text, T) : e.text
283
+ text: e.name === "image-planning" ? ee(e.text, D) : e.text
289
284
  }]
290
285
  }
291
286
  }))
292
287
  }] : []];
293
- m.length > 0 && p({
288
+ h.length > 0 && m({
294
289
  type: "activity",
295
- text: m.map(({ name: e }) => e).join(", ")
296
- }), W = f && {
297
- ms: f.ms,
298
- late: f.late,
299
- answers: f.decisions?.answers ?? null,
300
- ...T && { facts: T },
301
- refused: f.decisions?.refused ?? !1,
302
- skipped: f.decisions?.skipped ?? !1,
303
- supplied: m.map(({ name: e }) => e)
290
+ text: h.map(({ name: e }) => e).join(", ")
291
+ }), W = p && {
292
+ ms: p.ms,
293
+ late: p.late,
294
+ answers: p.decisions?.answers ?? null,
295
+ ...D && { facts: D },
296
+ refused: p.decisions?.refused ?? !1,
297
+ skipped: p.decisions?.skipped ?? !1,
298
+ supplied: h.map(({ name: e }) => e)
304
299
  };
305
300
  let H = [
306
301
  ...r,
307
- ...L,
308
- ...d,
302
+ ...N,
303
+ ...f,
309
304
  ...V
310
- ], G = B && d.length > 0 && N.sha256 === B.reference ? B.responseId : void 0, K, q = [], Y = 0, X, Z = !1;
305
+ ], G = B && f.length > 0 && P.sha256 === B.reference ? B.responseId : void 0, K, q = [], Y = 0, X, Z = !1;
311
306
  do {
312
307
  X = void 0;
313
- let e = Y, t = G, n = [], a = v({
314
- model: b.languageModel,
315
- providerOptions: R && r.length && N.sha256 ? {
316
- ...b.providerOptions,
308
+ let e = Y, t = G, n = [], o = y({
309
+ model: x.languageModel,
310
+ providerOptions: R && r.length && P.sha256 ? {
311
+ ...x.providerOptions,
317
312
  azure: {
318
- ...b.providerOptions?.azure,
319
- promptCacheKey: N.sha256
313
+ ...x.providerOptions?.azure,
314
+ promptCacheKey: P.sha256
320
315
  }
321
- } : b.providerOptions,
322
- instructions: M,
316
+ } : x.providerOptions,
317
+ instructions: T,
323
318
  messages: Z ? [...H, ...q].map(ne) : [...H, ...q],
324
319
  tools: C,
325
- stopWhen: y(A - e),
326
- abortSignal: i,
320
+ stopWhen: b(32 - e),
321
+ abortSignal: a,
327
322
  onLanguageModelCallEnd: (e) => {
328
- c.push({
329
- ...w(e.usage),
323
+ l.push({
330
324
  ...E(e.usage),
325
+ ...O(e.usage),
331
326
  responseTimeMs: e.performance.responseTimeMs,
332
327
  timeToFirstOutputMs: e.performance.timeToFirstOutputMs ?? null,
333
328
  finishReason: e.finishReason
@@ -337,36 +332,36 @@ var o = (e, t) => t === e.libraryId ? e : {
337
332
  n.push(...e.response.messages), Y++, K = z ? e.providerMetadata?.[z]?.responseId ?? void 0 : void 0;
338
333
  },
339
334
  prepareStep: (n) => {
340
- h = e + n.stepNumber;
341
- let r = h === A - 1 ? { toolChoice: "none" } : {};
335
+ g = e + n.stepNumber;
336
+ let r = i(g, T);
342
337
  if (!z) return r;
343
338
  if (n.stepNumber === 0) return t ? {
344
- ...r,
345
339
  instructions: [],
346
- messages: [...d, ...V],
340
+ ...i(g),
341
+ messages: [...f, ...V],
347
342
  providerOptions: { [z]: {
348
343
  previousResponseId: t,
349
344
  store: !0
350
345
  } }
351
346
  } : r;
352
- let i = n.steps.at(-1), a = i.providerMetadata?.[z]?.responseId;
353
- if (!a) throw Error("The previous model response has no continuation ID");
347
+ let a = n.steps.at(-1), o = a.providerMetadata?.[z]?.responseId;
348
+ if (!o) throw Error("The previous model response has no continuation ID");
354
349
  return {
355
- ...r,
356
350
  instructions: [],
357
- messages: i.response.messages.filter(({ role: e }) => e === "tool"),
351
+ ...i(g),
352
+ messages: a.response.messages.filter(({ role: e }) => e === "tool"),
358
353
  providerOptions: { [z]: {
359
- previousResponseId: a,
354
+ previousResponseId: o,
360
355
  store: !0
361
356
  } }
362
357
  };
363
358
  }
364
359
  });
365
- for await (let e of a.stream) if (e.type === "text-delta") l ??= performance.now() - o, p({
360
+ for await (let e of o.stream) if (e.type === "text-delta") u ??= performance.now() - s, m({
366
361
  type: "text",
367
362
  text: e.text
368
363
  });
369
- else if (e.type === "tool-input-start" || e.type === "tool-call") p({
364
+ else if (e.type === "tool-input-start" || e.type === "tool-call") m({
370
365
  type: "activity",
371
366
  text: e.toolName
372
367
  });
@@ -376,24 +371,24 @@ var o = (e, t) => t === e.libraryId ? e : {
376
371
  break;
377
372
  }
378
373
  throw e.error;
379
- } else e.type === "finish-step" ? (u.push(w(e.usage)), s.push(E(e.usage))) : e.type === "finish" ? (_ = q.length ? void 0 : w(e.totalUsage), S = !0) : e.type === "abort" && (k = !0);
380
- X ? (console.log(`[planning-assistant] continuation rejected (${X.message}) - continuing with the whole history`), q.push(...n), G = void 0, Z = !0) : !k && !i.aborted && (L.push(...V, ...q, ...await a.responseMessages), m.forEach(({ name: e }) => U.add(e)), B = K && N.sha256 ? {
374
+ } else e.type === "finish-step" ? (d.push(E(e.usage)), c.push(O(e.usage))) : e.type === "finish" ? (v = q.length ? void 0 : E(e.totalUsage), w = !0) : e.type === "abort" && (j = !0);
375
+ X ? (console.log(`[planning-assistant] continuation rejected (${X.message}) - continuing with the whole history`), q.push(...n), G = void 0, Z = !0) : !j && !a.aborted && (N.push(...V, ...q, ...await o.responseMessages), h.forEach(({ name: e }) => U.add(e)), B = K && P.sha256 ? {
381
376
  responseId: K,
382
- reference: N.sha256
377
+ reference: P.sha256
383
378
  } : null);
384
379
  } while (X);
385
- p({ type: "done" });
380
+ m({ type: "done" });
386
381
  } catch (e) {
387
- console.log("[planning-assistant]", String(e)), p({
382
+ console.log("[planning-assistant]", String(e)), m({
388
383
  type: "error",
389
384
  text: `The planning assistant failed: ${e instanceof Error ? e.message : String(e)}`
390
385
  });
391
386
  } finally {
392
387
  let e = {
393
- inputTokens: _?.inputTokens ?? T(u.map((e) => e.inputTokens)),
394
- outputTokens: _?.outputTokens ?? T(u.map((e) => e.outputTokens)),
395
- totalTokens: _?.totalTokens ?? T(u.map((e) => e.totalTokens))
396
- }, n = Object.values(e).some((e) => e !== null), r = S && !k && !i.aborted && Object.values(e).every((e) => e !== null) && u.every((e) => Object.values(e).every((e) => e !== null));
388
+ inputTokens: v?.inputTokens ?? D(d.map((e) => e.inputTokens)),
389
+ outputTokens: v?.outputTokens ?? D(d.map((e) => e.outputTokens)),
390
+ totalTokens: v?.totalTokens ?? D(d.map((e) => e.totalTokens))
391
+ }, n = Object.values(e).some((e) => e !== null), r = w && !j && !a.aborted && Object.values(e).every((e) => e !== null) && d.every((e) => Object.values(e).every((e) => e !== null));
397
392
  console.log(`[planning-assistant] usage ${JSON.stringify({
398
393
  provider: t.provider,
399
394
  model: t.model,
@@ -401,62 +396,59 @@ var o = (e, t) => t === e.libraryId ? e : {
401
396
  ...e,
402
397
  diagnostics: {
403
398
  version: 1,
404
- details: D(s),
405
- modelCalls: c,
406
- requests: m,
407
- reference: N,
408
- planState: P,
399
+ details: k(c),
400
+ modelCalls: l,
401
+ requests: h,
402
+ reference: P,
403
+ planState: F,
409
404
  decisions: W,
410
- referenceAcquisitionMs: F,
411
- firstTextMs: l,
412
- turnMs: performance.now() - o
405
+ referenceAcquisitionMs: I,
406
+ firstTextMs: u,
407
+ turnMs: performance.now() - s
413
408
  }
414
409
  })}`);
415
410
  }
416
411
  }, X = async (e) => {
417
- if (s || f.aborted) throw Error("The planning assistant is suspended.");
418
- if (u) throw Error("An assistant turn is already running.");
419
- u = Y(e);
412
+ if (c || p.aborted) throw Error("The planning assistant is suspended.");
413
+ if (d) throw Error("An assistant turn is already running.");
414
+ d = Y(e);
420
415
  try {
421
- await u;
416
+ await d;
422
417
  } finally {
423
- u = void 0, d = void 0;
418
+ d = void 0, f = void 0;
424
419
  }
425
420
  };
426
- o.callbacks.onPlanningAssistantPrompt = X;
421
+ s.callbacks.onPlanningAssistantPrompt = X;
427
422
  let Z = async (e) => {
428
- e === "isolation" ? (s = !0, d?.abort(/* @__PURE__ */ Error("The assistant changed mode.")), u && await Promise.allSettled([u]), await o.planningAssistantOutput({
423
+ e === "isolation" ? (c = !0, f?.abort(/* @__PURE__ */ Error("The assistant changed mode.")), d && await Promise.allSettled([d]), await s.planningAssistantOutput({
429
424
  type: "availability",
430
425
  available: !1
431
- })) : !f.aborted && !c && (s = !1, p({
426
+ })) : !p.aborted && !l && (c = !1, m({
432
427
  type: "images",
433
428
  enabled: t.readsImages
434
- }), p({
429
+ }), m({
435
430
  type: "availability",
436
431
  available: !0
437
432
  }));
438
433
  };
439
- o.callbacks.onPlanningAssistantModeChange = Z;
434
+ s.callbacks.onPlanningAssistantModeChange = Z;
440
435
  let ae = async () => {
441
- c = !0, s = !0, d?.abort(/* @__PURE__ */ Error("The planning assistant stopped.")), u && await Promise.allSettled([u]), await o.stopPlanningAssistant?.(l), o.callbacks.onPlanningAssistantPrompt === X && (o.callbacks.onPlanningAssistantPrompt = void 0, await o.planningAssistantOutput({
436
+ l = !0, c = !0, f?.abort(/* @__PURE__ */ Error("The planning assistant stopped.")), d && await Promise.allSettled([d]), await s.stopPlanningAssistant?.(u), s.callbacks.onPlanningAssistantPrompt === X && (s.callbacks.onPlanningAssistantPrompt = void 0, await s.planningAssistantOutput({
442
437
  type: "availability",
443
438
  available: !1
444
- })), o.callbacks.onPlanningAssistantModeChange === Z && (o.callbacks.onPlanningAssistantModeChange = void 0), f.removeEventListener("abort", $);
439
+ })), s.callbacks.onPlanningAssistantModeChange === Z && (s.callbacks.onPlanningAssistantModeChange = void 0), p.removeEventListener("abort", $);
445
440
  }, oe, Q = () => oe ??= ae(), $ = () => {
446
441
  Q();
447
442
  };
448
- if (f.addEventListener("abort", $, { once: !0 }), f.aborted) {
449
- await Q();
450
- return;
451
- }
452
- return await o.setPlanningAssistantModel?.({
443
+ if (p.addEventListener("abort", $, { once: !0 }), p.aborted) await Q();
444
+ else return await s.setPlanningAssistantModel?.({
453
445
  model: t.model,
454
446
  readsImages: t.readsImages,
455
- responsesProvider: a(t) ?? void 0
456
- }, l), o.getExternalObjectLibraryContext && J(), p({
447
+ responsesProvider: o(t) ?? void 0
448
+ }, u), s.getExternalObjectLibraryContext && J(), m({
457
449
  type: "images",
458
450
  enabled: t.readsImages
459
- }), p({
451
+ }), m({
460
452
  type: "availability",
461
453
  available: !0
462
454
  }), {
@@ -464,12 +456,12 @@ var o = (e, t) => t === e.libraryId ? e : {
464
456
  resume: () => Z("planner"),
465
457
  dispose: Q
466
458
  };
467
- }, R = 5e3, z = async ({ serverUrl: e, authorization: t }) => {
459
+ }, z = 5e3, B = async ({ serverUrl: e, authorization: t }) => {
468
460
  let n = t ? { Authorization: t } : {}, r;
469
461
  try {
470
462
  let t = await fetch(`${e}/backends/list`, {
471
463
  headers: n,
472
- signal: AbortSignal.timeout(R)
464
+ signal: AbortSignal.timeout(z)
473
465
  });
474
466
  r = t.ok ? await t.json() : [];
475
467
  } catch (e) {
@@ -492,12 +484,12 @@ var o = (e, t) => t === e.libraryId ? e : {
492
484
  headers: n
493
485
  } }
494
486
  };
495
- }, B = (e = "1:1") => {
487
+ }, V = (e = "1:1") => {
496
488
  let [t, n] = e.split(":").map(Number);
497
489
  return t === n ? "1024x1024" : t > n ? "1536x1024" : "1024x1536";
498
- }, V = async (e) => (await fetch(e)).blob(), H = async (e, t, { baseUrl: n, model: r, headers: i }) => {
499
- let { prompt: a, image: o, aspect: s } = JSON.parse(e.body), c = await V(o), l = new FormData();
500
- l.append("model", r), l.append("prompt", a), l.append("size", B(s)), l.append("quality", "medium"), l.append("output_format", "png"), l.append("image", c, `scene.${c.type.split("/")[1]}`);
490
+ }, H = async (e) => (await fetch(e)).blob(), U = async (e, t, { baseUrl: n, model: r, headers: i }) => {
491
+ let { prompt: a, image: o, aspect: s } = JSON.parse(e.body), c = await H(o), l = new FormData();
492
+ l.append("model", r), l.append("prompt", a), l.append("size", V(s)), l.append("quality", "medium"), l.append("output_format", "png"), l.append("image", c, `scene.${c.type.split("/")[1]}`);
501
493
  let u = await fetch(`${n}/images/edits`, {
502
494
  method: "POST",
503
495
  headers: i,
@@ -506,11 +498,10 @@ var o = (e, t) => t === e.libraryId ? e : {
506
498
  });
507
499
  if (!u.ok) return u;
508
500
  let { data: d } = await u.json(), f = d?.[0]?.b64_json, p = new FormData();
509
- return f ? p.append("image", await V(`data:image/png;base64,${f}`)) : p.append("text", "The endpoint returned no image"), new Response(p);
510
- }, U = {
501
+ return f ? p.append("image", await H(`data:image/png;base64,${f}`)) : p.append("text", "The endpoint returned no image"), new Response(p);
502
+ }, W = {
511
503
  HIDE: "hide",
512
504
  SHOW_ATTRIBUTES: "attributes",
513
505
  SHOW_ARTICLES: "articles"
514
506
  };
515
- //#endregion
516
- export { U as HI_PANEL_ACTION, x as cleanupHi, h as createHiLibraryCallbacks, S as createHiMcpTools, f as libLoadArticleCatalog, m as libLoadCalcScript, p as libLoadMasterData, i as loadChatModel, _ as omGetRequest, g as omPostRequest, l as registerLegacyUrlFormat, H as requestImageEdits, z as resolveHiModelProxy, b as setupHi, L as startPlanningAssistant, u as unregisterLegacyUrlFormat };
507
+ export { W as HI_PANEL_ACTION, C as cleanupHi, g as createHiLibraryCallbacks, w as createHiMcpTools, p as libLoadArticleCatalog, h as libLoadCalcScript, m as libLoadMasterData, a as loadChatModel, y as omGetRequest, v as omPostRequest, u as registerLegacyUrlFormat, U as requestImageEdits, B as resolveHiModelProxy, S as setupHi, R as startPlanningAssistant, d as unregisterLegacyUrlFormat };