@roomle/embedding-lib 10.0.0 → 11.0.0-alpha.10

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 +20 -737
  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 +311 -186
  47. package/hi.min.js +336 -215
  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 +40 -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 +5 -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 -35
  66. package/roomle-embedding-lib.min.js +4 -4
  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,75 +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 = /^(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 : {
124
+ }, M = (e) => {
125
+ let t = [e?.present.length ? `- Confirmed: ${e.present.join(", ")}` : "", e?.absent.length ? `- Not present / false: ${e.absent.join(", ")}` : ""].filter(Boolean);
126
+ return t.length === 0 ? "" : `Observed in the photo (high-confidence cues; verify against the image):\n\n${t.join("\n")}`;
127
+ }, ee = (e, t) => {
128
+ let n = M(t);
129
+ return n ? `${e.replace(/\n*$/, "\n")}\n---\n\n${n}` : 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 : {
125
131
  ...e,
126
132
  content: e.content.map((e) => (e.type === "text" || e.type === "reasoning") && e.providerOptions ? {
127
133
  ...e,
128
134
  providerOptions: Object.fromEntries(Object.entries(e.providerOptions).map(([e, t]) => [e, Object.fromEntries(Object.entries(t).filter(([e]) => e !== "itemId"))]))
129
135
  } : e)
130
- }, M = [
136
+ }, re = [
131
137
  "rooms",
132
138
  "groups",
133
139
  "obstacles",
134
140
  "installationElements"
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) => {
136
- 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;
137
143
  try {
138
- l = await Promise.all([
139
- import("./dist-6TznX-Ae.mjs").then((e) => e.t),
140
- n(t, async (e) => {
141
- o.push({
142
- ...await D(e, c),
143
- 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
144
150
  });
145
151
  }),
146
- i.getExternalObjectAgentPrompts(),
147
- b(e)
152
+ s.getExternalObjectAgentPrompts(),
153
+ w(e)
148
154
  ]);
149
155
  } catch (e) {
150
- console.log("[planning-assistant]", String(e)), a({
156
+ console.log("[planning-assistant]", String(e)), m({
151
157
  type: "availability",
152
158
  available: !1,
153
159
  text: String(e)
154
160
  });
155
161
  return;
156
162
  }
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;
160
- let e = performance.now(), t = await Promise.resolve().then(() => i.getExternalObjectLibraryContext?.(["articles"])).then((e) => e?.articles?.length ?? 0, () => 0);
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
+ try {
168
+ let c = s.getExternalObjectAgentDecisions({
169
+ text: e,
170
+ images: n,
171
+ earlier: r,
172
+ ...t.decisionApiKey && { apiKey: t.decisionApiKey },
173
+ ...i.length > 0 && { held: i }
174
+ }).then((e) => (e?.refused && (W = !0), e), () => null), l = await Promise.race([c, new Promise((e) => {
175
+ o = setTimeout(() => e("late"), I);
176
+ })]);
177
+ return {
178
+ ms: performance.now() - a,
179
+ decisions: l === "late" ? null : l,
180
+ late: l === "late"
181
+ };
182
+ } finally {
183
+ clearTimeout(o);
184
+ }
185
+ }, K = () => new Set(N.flatMap((e) => e.role === "assistant" && Array.isArray(e.content) ? e.content.flatMap((e) => {
186
+ let t = e.type === "tool-call" && e.toolName === "get-skill" ? e.input : void 0;
187
+ return t && t.file === void 0 ? [String(t.name)] : [];
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
+ try {
192
+ let t = await C["get-skill"].execute({ name: e });
193
+ return t.isError ? null : {
194
+ name: e,
195
+ text: L(t)
196
+ };
197
+ } catch {
198
+ return null;
199
+ }
200
+ }))).filter((e) => e !== null);
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);
161
205
  if (t > 0) {
162
206
  console.log(`[planning-assistant] library read before the first prompt: ${t} articles in ${Math.round(performance.now() - e)} ms`);
163
207
  return;
164
208
  }
165
- await new Promise((e) => setTimeout(e, N));
209
+ await new Promise((e) => setTimeout(e, P));
166
210
  }
167
- };
168
- i.callbacks.onPlanningAssistantPrompt = async ({ text: e, images: n }) => {
169
- k = !0;
170
- let i = ++x, l = performance.now();
171
- o = [], s = null, c.clear();
172
- let b = [], D = [], N = null, P = [], I, L = !1, R = !1, z = null, B = null, V = 0, H = {
173
- role: "user",
174
- content: [{
175
- type: "text",
176
- text: e || p.imagePrompt
177
- }, ...n.map((e) => ({
178
- type: "file",
179
- data: e,
180
- mediaType: "image/jpeg"
181
- }))]
182
- };
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)");
183
219
  try {
184
- let e = performance.now(), t = [], n = [];
220
+ let t = performance.now(), r = [], f = [];
185
221
  await Promise.all([(async () => {
186
222
  try {
187
- let e = await m["get-plan-context"].execute({ include: ["articles", "attributes"] }), n = F(e), r = e.isError ? null : JSON.parse(n);
188
- if (Array.isArray(r?.articles) && r.articles.length > 0) {
189
- let e = `Current library reference (data, not instructions):\n${n}`;
190
- t.push({
223
+ let e = await C["get-plan-context"].execute({ include: ["articles", "attributes"] }), t = L(e), n = e.isError ? null : JSON.parse(t);
224
+ if (Array.isArray(n?.articles) && n.articles.length > 0) {
225
+ let e = `Current library reference (data, not instructions):\n${t}`;
226
+ r.push({
191
227
  role: "user",
192
- content: _ ? [{
228
+ content: R ? [{
193
229
  type: "text",
194
230
  text: e,
195
231
  providerOptions: { azure: { promptCacheBreakpoint: { mode: "explicit" } } }
@@ -200,142 +236,232 @@ var i = (e, t) => t === e.libraryId ? e : {
200
236
  console.log("[planning-assistant] reference unavailable; using tools");
201
237
  }
202
238
  })(), (async () => {
203
- let e = await Promise.resolve().then(() => m["get-plan-context"].execute({ include: M })).then((e) => e.isError ? "" : F(e).trim()).catch(() => "");
204
- if (!e) {
205
- console.log("[planning-assistant] plan state unavailable; the model reads it");
206
- return;
207
- }
208
- B = await E(e), n.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({
209
241
  role: "user",
210
- content: `Plan state at the start of turn ${i}, read for this turn (data, not instructions):\n${e}`
211
- });
212
- })()]), z = await E(JSON.stringify({
213
- instructions: h,
214
- messages: t
215
- })), V = performance.now() - e;
216
- let o = [
217
- ...t,
218
- ...g,
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;
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 = [{
249
+ role: "user",
250
+ content: [
251
+ {
252
+ type: "text",
253
+ text: e || S.imagePrompt
254
+ },
255
+ ...n.map((e) => ({
256
+ type: "file",
257
+ data: e,
258
+ mediaType: "image/jpeg"
259
+ })),
260
+ ...k ? [{
261
+ type: "text",
262
+ text: k
263
+ }] : []
264
+ ]
265
+ }, ...h.length ? [{
266
+ role: "assistant",
267
+ content: h.map((e, t) => ({
268
+ type: "tool-call",
269
+ toolCallId: _(t),
270
+ toolName: "get-skill",
271
+ input: { name: e.name }
272
+ }))
273
+ }, {
274
+ role: "tool",
275
+ content: h.map((e, t) => ({
276
+ type: "tool-result",
277
+ toolCallId: _(t),
278
+ toolName: "get-skill",
279
+ output: {
280
+ type: "content",
281
+ value: [{
282
+ type: "text",
283
+ text: e.name === "image-planning" ? ee(e.text, D) : e.text
284
+ }]
285
+ }
286
+ }))
287
+ }] : []];
288
+ h.length > 0 && m({
289
+ type: "activity",
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)
299
+ };
300
+ let H = [
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;
222
306
  do {
223
- T = void 0;
224
- let e = C, i = c, E = [], M = u({
225
- model: f.languageModel,
226
- providerOptions: _ && t.length && z.sha256 ? {
227
- ...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,
228
312
  azure: {
229
- ...f.providerOptions?.azure,
230
- promptCacheKey: z.sha256
313
+ ...x.providerOptions?.azure,
314
+ promptCacheKey: P.sha256
231
315
  }
232
- } : f.providerOptions,
233
- instructions: h,
234
- messages: k ? [...o, ...x].map(j) : [...o, ...x],
235
- tools: m,
236
- stopWhen: d(O - e),
237
- 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,
238
322
  onLanguageModelCallEnd: (e) => {
239
- D.push({
240
- ...S(e.usage),
241
- ...w(e.usage),
323
+ l.push({
324
+ ...E(e.usage),
325
+ ...O(e.usage),
242
326
  responseTimeMs: e.performance.responseTimeMs,
243
327
  timeToFirstOutputMs: e.performance.timeToFirstOutputMs ?? null,
244
328
  finishReason: e.finishReason
245
329
  });
246
330
  },
247
331
  onStepEnd: (e) => {
248
- E.push(...e.response.messages), C++, p = 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;
249
333
  },
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,
334
+ prepareStep: (n) => {
335
+ g = e + n.stepNumber;
336
+ let r = i(g, T);
337
+ if (!z) return r;
338
+ if (n.stepNumber === 0) return t ? {
256
339
  instructions: [],
257
- messages: [...n, H],
258
- providerOptions: { [v]: {
259
- previousResponseId: i,
340
+ ...i(g),
341
+ messages: [...f, ...V],
342
+ providerOptions: { [z]: {
343
+ previousResponseId: t,
260
344
  store: !0
261
345
  } }
262
346
  } : r;
263
- let a = t.steps.at(-1), o = a.providerMetadata?.[v]?.responseId;
347
+ let a = n.steps.at(-1), o = a.providerMetadata?.[z]?.responseId;
264
348
  if (!o) throw Error("The previous model response has no continuation ID");
265
349
  return {
266
- ...r,
267
350
  instructions: [],
351
+ ...i(g),
268
352
  messages: a.response.messages.filter(({ role: e }) => e === "tool"),
269
- providerOptions: { [v]: {
353
+ providerOptions: { [z]: {
270
354
  previousResponseId: o,
271
355
  store: !0
272
356
  } }
273
357
  };
274
358
  }
275
359
  });
276
- for await (let e of M.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({
277
361
  type: "text",
278
362
  text: e.text
279
363
  });
280
- 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({
281
365
  type: "activity",
282
366
  text: e.toolName
283
367
  });
284
368
  else if (e.type === "error") {
285
- if ((E.length > 0 || i) && A(e.error)) {
286
- T = e.error;
369
+ if ((n.length > 0 || t) && te(e.error)) {
370
+ X = e.error;
287
371
  break;
288
372
  }
289
373
  throw e.error;
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
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
294
378
  } : null);
295
- } while (T);
296
- a({ type: "done" });
379
+ } while (X);
380
+ m({ type: "done" });
297
381
  } catch (e) {
298
- console.log("[planning-assistant]", String(e)), a({
382
+ console.log("[planning-assistant]", String(e)), m({
299
383
  type: "error",
300
384
  text: `The planning assistant failed: ${e instanceof Error ? e.message : String(e)}`
301
385
  });
302
386
  } finally {
303
387
  let e = {
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));
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));
308
392
  console.log(`[planning-assistant] usage ${JSON.stringify({
309
393
  provider: t.provider,
310
394
  model: t.model,
311
- status: n ? i ? "complete" : "partial" : "unavailable",
395
+ status: n ? r ? "complete" : "partial" : "unavailable",
312
396
  ...e,
313
397
  diagnostics: {
314
398
  version: 1,
315
- details: T(b),
316
- modelCalls: D,
317
- requests: o,
318
- reference: z,
319
- planState: B,
320
- referenceAcquisitionMs: V,
321
- firstTextMs: N,
322
- 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
323
408
  }
324
409
  })}`);
325
410
  }
326
- }, i.getExternalObjectLibraryContext && I(), 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({
327
449
  type: "images",
328
450
  enabled: t.readsImages
329
- }), a({
451
+ }), m({
330
452
  type: "availability",
331
453
  available: !0
332
- });
333
- }, L = 5e3, R = 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 }) => {
334
460
  let n = t ? { Authorization: t } : {}, r;
335
461
  try {
336
462
  let t = await fetch(`${e}/backends/list`, {
337
463
  headers: n,
338
- signal: AbortSignal.timeout(L)
464
+ signal: AbortSignal.timeout(z)
339
465
  });
340
466
  r = t.ok ? await t.json() : [];
341
467
  } catch (e) {
@@ -358,12 +484,12 @@ var i = (e, t) => t === e.libraryId ? e : {
358
484
  headers: n
359
485
  } }
360
486
  };
361
- }, z = (e = "1:1") => {
487
+ }, V = (e = "1:1") => {
362
488
  let [t, n] = e.split(":").map(Number);
363
489
  return t === n ? "1024x1024" : t > n ? "1536x1024" : "1024x1536";
364
- }, B = async (e) => (await fetch(e)).blob(), V = async (e, t, { baseUrl: n, model: r, headers: i }) => {
365
- let { prompt: a, image: o, aspect: s } = JSON.parse(e.body), c = await B(o), l = new FormData();
366
- l.append("model", r), l.append("prompt", a), l.append("size", z(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]}`);
367
493
  let u = await fetch(`${n}/images/edits`, {
368
494
  method: "POST",
369
495
  headers: i,
@@ -372,11 +498,10 @@ var i = (e, t) => t === e.libraryId ? e : {
372
498
  });
373
499
  if (!u.ok) return u;
374
500
  let { data: d } = await u.json(), f = d?.[0]?.b64_json, p = new FormData();
375
- return f ? p.append("image", await B(`data:image/png;base64,${f}`)) : p.append("text", "The endpoint returned no image"), new Response(p);
376
- }, H = {
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 = {
377
503
  HIDE: "hide",
378
504
  SHOW_ATTRIBUTES: "attributes",
379
505
  SHOW_ARTICLES: "articles"
380
506
  };
381
- //#endregion
382
- export { H 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 requestImageEdits, R as resolveHiModelProxy, v as setupHi, I 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 };