@roomle/embedding-lib 11.0.0-alpha.1 → 11.0.0-alpha.11

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