@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.min.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-BjtSrqbu.mjs";
3
- import { t } from "./utils-BoELtcEK.mjs";
4
- import { i as n, r } from "./chat-model-CFuHw4cp.mjs";
5
- var i = (e, t) => t === e.libraryId ? e : {
2
+ import { t as e } from "./utils-DdNhTbJr.mjs";
3
+ import { t } from "./browser-CzLpXYFF.mjs";
4
+ import { t as n } from "./mcp-tools-BirFT2R0.mjs";
5
+ import { a as r, r as i } from "./turn-limits-9LbUeSG2.mjs";
6
+ import { n as a } from "./chat-model-B7BO8IhK.mjs";
7
+ import { n as o } from "./continuation-NclHDSgS.mjs";
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": "*"
@@ -19,83 +22,80 @@ var i = (e, t) => t === e.libraryId ? e : {
19
22
  } catch (e) {
20
23
  throw e;
21
24
  }
22
- }, o = { "e2fe8b3d-da31-4a20-92ab-ab6e3839300e": new Set(["Furniture_Smith"]) }, s = (e, t) => {
23
- o[e] || (o[e] = /* @__PURE__ */ new Set()), o[e].add(t);
24
- }, c = (e, t) => {
25
- o[e]?.delete(t), o[e]?.size === 0 && delete o[e];
26
- }, l = (e, t) => {
25
+ }, l = { "e2fe8b3d-da31-4a20-92ab-ab6e3839300e": /* @__PURE__ */ new Set(["Furniture_Smith"]) }, u = (e, t) => {
26
+ l[e] || (l[e] = /* @__PURE__ */ new Set()), l[e].add(t);
27
+ }, d = (e, t) => {
28
+ l[e]?.delete(t), l[e]?.size === 0 && delete l[e];
29
+ }, f = (e, t) => {
27
30
  let { libraryId: n, serverOptions: r } = e;
28
- return r?.subscriptionId && o[r.subscriptionId]?.has(n) ? `api/pos/${t}?libraryId=${n}` : `api/pos/libraries/${n}/${t}`;
29
- }, 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) => {
30
- let t = await (await a(l(e, "calc.js"), "text", e, { property: "calc.js" })).text();
31
+ return r?.subscriptionId && l[r.subscriptionId]?.has(n) ? `api/pos/${t}?libraryId=${n}` : `api/pos/libraries/${n}/${t}`;
32
+ }, 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) => {
33
+ let t = await (await c(f(e, "calc.js"), "text", e, { property: "calc.js" })).text();
31
34
  if (!t) throw Error("Script load error");
32
35
  return t;
33
- }, p = (e) => ({
34
- onLoadJavascript: (t) => f(i(e, t)),
35
- onLoadArticleCatalog: (t) => u(i(e, t)),
36
- onLoadMasterData: (t) => d(i(e, t))
37
- }), m = 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),
36
+ }, g = (e) => ({
37
+ onLoadJavascript: (t) => h(s(e, t)),
38
+ onLoadArticleCatalog: (t) => p(s(e, t)),
39
+ onLoadMasterData: (t) => m(s(e, t))
40
+ }), _ = async (e, t, n, r) => {
41
+ 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}`, {
42
+ ...n,
42
43
  headers: {
43
44
  "Content-Type": "application/json",
44
45
  ...r
45
46
  }
46
- })).json();
47
- }, h = 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
- }, g = null, _ = async (n, r = {}) => {
57
- g && window.removeEventListener("message", g);
58
- let a = typeof n == "string" ? { libraryId: n } : n;
59
- r.onLoadJavascript === void 0 && (r.onLoadJavascript = (e) => f(i(a, e))), r.onLoadArticleCatalog === void 0 && (r.onLoadArticleCatalog = (e) => u(i(a, e))), r.onLoadMasterData === void 0 && (r.onLoadMasterData = (e) => d(i(a, e)));
60
- let { expose: o } = await import("./comlink-BYqErFai.mjs");
61
- g = (n) => {
47
+ });
48
+ if (!l.ok) {
49
+ let e = `HTTP ${l.status} ${l.statusText}`.trimEnd(), n = await l.text();
50
+ throw Error(`Order Manager request ${t} failed with ${e}${n ? `: ${n}` : ""}`);
51
+ }
52
+ return l.json();
53
+ }, v = async (e, t, n, r = {}) => _(e, n, {
54
+ method: "POST",
55
+ body: JSON.stringify(t)
56
+ }, r), y = async (e, t, n = {}) => _(e, t, { method: "GET" }, n), b = null, x = async (n, r = {}) => {
57
+ b && window.removeEventListener("message", b);
58
+ let i = typeof n == "string" ? { libraryId: n } : n;
59
+ r.onLoadJavascript === void 0 && (r.onLoadJavascript = (e) => h(s(i, e))), r.onLoadArticleCatalog === void 0 && (r.onLoadArticleCatalog = (e) => p(s(i, e))), r.onLoadMasterData === void 0 && (r.onLoadMasterData = (e) => m(s(i, e)));
60
+ let { expose: a } = await import("./comlink-DKhvPU0o.mjs");
61
+ b = (n) => {
62
62
  if (n.data.type === "connect_hi" && n.data.port) {
63
- let i = n.data.port;
64
- ((t, n) => {
65
- t.serverOptions ||= {}, !t.serverOptions.language && n?.locale && (t.serverOptions.language = n.locale), t.serverOptions.language || (t.serverOptions.language = e(null, !0));
66
- })(a, n.data.globalInitData || {}), i.start?.(), o(t(r), i);
63
+ let o = n.data.port;
64
+ ((e, n) => {
65
+ e.serverOptions ||= {}, !e.serverOptions.language && n?.locale && (e.serverOptions.language = n.locale), e.serverOptions.language || (e.serverOptions.language = t(null, !0));
66
+ })(i, n.data.globalInitData || {}), o.start?.(), a(e(r), o);
67
67
  }
68
- }, window.addEventListener("message", g);
69
- }, v = () => {
70
- g &&= (window.removeEventListener("message", g), null);
71
- }, y = async ({ extended: e }) => {
68
+ }, window.addEventListener("message", b);
69
+ }, S = () => {
70
+ b &&= (window.removeEventListener("message", b), null);
71
+ }, C = async ({ extended: e }) => {
72
72
  if (typeof e.getExternalObjectAgentTools != "function") throw Error("The planner has no HI agent tools: it needs a Rubens UI with getExternalObjectAgentTools.");
73
- return r(await e.getExternalObjectAgentTools(), (t, n) => e.callExternalObjectAgentTool(t, n), "hi-mcp");
74
- }, b = (e) => typeof e == "number" && Number.isSafeInteger(e) && e >= 0 ? e : null, x = (e = {}) => ({
75
- inputTokens: b(e.inputTokens),
76
- outputTokens: b(e.outputTokens),
77
- totalTokens: b(e.totalTokens) ?? (b(e.inputTokens) !== null && b(e.outputTokens) !== null ? e.inputTokens + e.outputTokens : null)
78
- }), S = (e) => e.some((e) => e !== null) ? e.reduce((e, t) => e + (t ?? 0), 0) : null, C = (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 = b(n?.cached_tokens ?? t?.cache_read_input_tokens), a = b(n?.cache_write_tokens ?? t?.cache_creation_input_tokens), o = (e, t) => t ?? (b(e) !== null && Number(e) > 0 ? Number(e) : null);
73
+ return n(await e.getExternalObjectAgentTools(), (t, n) => e.callExternalObjectAgentTool(t, n), "hi-mcp");
74
+ }, w = (e) => typeof e == "number" && Number.isSafeInteger(e) && e >= 0 ? e : null, T = (e = {}) => ({
75
+ inputTokens: w(e.inputTokens),
76
+ outputTokens: w(e.outputTokens),
77
+ totalTokens: w(e.totalTokens) ?? (w(e.inputTokens) !== null && w(e.outputTokens) !== null ? e.inputTokens + e.outputTokens : null)
78
+ }), E = (e) => e.some((e) => e !== null) ? e.reduce((e, t) => e + (t ?? 0), 0) : null, D = (e = {}) => {
79
+ let t = e.raw, n = t?.input_tokens_details ?? t?.prompt_tokens_details, r = t?.output_tokens_details ?? t?.completion_tokens_details, i = w(n?.cached_tokens ?? t?.cache_read_input_tokens), a = w(n?.cache_write_tokens ?? t?.cache_creation_input_tokens), o = (e, t) => t ?? (w(e) !== null && Number(e) > 0 ? Number(e) : null);
80
80
  return {
81
81
  cacheReadTokens: o(e.inputTokenDetails?.cacheReadTokens, i),
82
82
  cacheWriteTokens: o(e.inputTokenDetails?.cacheWriteTokens, a),
83
- noCacheTokens: i !== null && a !== null ? b(e.inputTokenDetails?.noCacheTokens) : null,
84
- reasoningTokens: o(e.outputTokenDetails?.reasoningTokens, b(r?.reasoning_tokens)),
83
+ noCacheTokens: i !== null && a !== null ? w(e.inputTokenDetails?.noCacheTokens) : null,
84
+ reasoningTokens: o(e.outputTokenDetails?.reasoningTokens, w(r?.reasoning_tokens)),
85
85
  rawUsageAvailable: t !== void 0
86
86
  };
87
- }, w = async (e) => {
87
+ }, O = async (e) => {
88
88
  let t = new TextEncoder().encode(e), n = await globalThis.crypto?.subtle?.digest("SHA-256", t);
89
89
  return {
90
90
  bytes: t.byteLength,
91
91
  sha256: n ? Array.from(new Uint8Array(n), (e) => e.toString(16).padStart(2, "0")).join("") : null
92
92
  };
93
- }, T = async (e, t) => {
94
- let n = await w(e), r = JSON.parse(e);
93
+ }, k = async (e, t) => {
94
+ let n = await O(e), r = JSON.parse(e);
95
95
  if (!Array.isArray(r.input)) return n;
96
96
  let i = 0, a = 0;
97
97
  for (let e of r.input) {
98
- let n = await w(JSON.stringify(e));
98
+ let n = await O(JSON.stringify(e));
99
99
  i += n.bytes, n.sha256 === null ? a = null : (t.has(n.sha256) && a !== null && (a += n.bytes), t.add(n.sha256));
100
100
  }
101
101
  let o = r.tools ? new TextEncoder().encode(JSON.stringify(r.tools)).length : 0;
@@ -109,192 +109,313 @@ var i = (e, t) => t === e.libraryId ? e : {
109
109
  otherBytes: n.bytes - i - o
110
110
  }
111
111
  };
112
- }, E = /^(Previous response with id '[^']*' not found|No tool output found for function call )/, D = (e) => e instanceof Error && E.test(e.message), O = (e) => e.role !== "assistant" || typeof e.content == "string" ? e : {
112
+ }, A = (e) => {
113
+ let t = [e?.present.length ? `- Confirmed: ${e.present.join(", ")}` : "", e?.absent.length ? `- Not present / false: ${e.absent.join(", ")}` : ""].filter(Boolean);
114
+ return t.length === 0 ? "" : `Observed in the photo (high-confidence cues; verify against the image):\n\n${t.join("\n")}`;
115
+ }, j = (e, t) => {
116
+ let n = A(t);
117
+ return n ? `${e.replace(/\n*$/, "\n")}\n---\n\n${n}` : e;
118
+ }, M = /^(Previous response with id '[^']*' not found|No tool output found for function call )/, N = (e) => e instanceof Error && M.test(e.message), P = (e) => e.role !== "assistant" || typeof e.content == "string" ? e : {
113
119
  ...e,
114
120
  content: e.content.map((e) => e.type !== "text" && e.type !== "reasoning" || !e.providerOptions ? e : {
115
121
  ...e,
116
122
  providerOptions: Object.fromEntries(Object.entries(e.providerOptions).map(([e, t]) => [e, Object.fromEntries(Object.entries(t).filter(([e]) => e !== "itemId"))]))
117
123
  })
118
- }, k = [
124
+ }, F = [
119
125
  "rooms",
120
126
  "groups",
121
127
  "obstacles",
122
128
  "installationElements"
123
- ], A = ({ content: e }) => e.filter((e) => e.type === "text").map((e) => e.text).join("\n"), j = async (e, t, r) => {
124
- let i = e.extended, a = (e) => i.planningAssistantOutput(e), o = [], s = null, c = /* @__PURE__ */ new Set(), l;
129
+ ], I = ({ content: e }) => e.filter((e) => e.type === "text").map((e) => e.text).join("\n"), L = async (e, t, n) => {
130
+ let s = e.extended, c = !1, l = !1, u = crypto.randomUUID(), d, f, p = n, m = (e) => c || p.aborted ? void 0 : s.planningAssistantOutput(e), h = [], g = null, _ = /* @__PURE__ */ new Set(), v;
125
131
  try {
126
- l = await Promise.all([
127
- import("./dist-D0XFfKEL.mjs").then((e) => e.t),
128
- n(t, async (e) => {
129
- o.push({
130
- ...await T(e, c),
131
- stepNumber: s
132
+ v = await Promise.all([
133
+ import("./dist-S9sLSjZ4.mjs").then((e) => e.t),
134
+ a(t, async (e) => {
135
+ h.push({
136
+ ...await k(e, _),
137
+ stepNumber: g
132
138
  });
133
139
  }),
134
- i.getExternalObjectAgentPrompts(),
135
- y(e)
140
+ s.getExternalObjectAgentPrompts(),
141
+ C(e)
136
142
  ]);
137
143
  } catch (e) {
138
- a({
144
+ m({
139
145
  type: "availability",
140
146
  available: !1,
141
147
  text: String(e)
142
148
  });
143
149
  return;
144
150
  }
145
- let [{ streamText: u, stepCountIs: d }, f, p, m] = l, h = [p.systemPrompt, ...(p.referenceBlocks ?? []).map(({ id: e, text: t }) => `Reference: ${e}\n${t}`)].join("\n\n"), g = [], _ = t.provider === "azure" && !t.chatCompletions && !0 === t.referenceCacheBreakpoint, v = t.provider === "openai" || t.provider === "azure" && !t.chatCompletions ? t.provider : null, b = null, E = 0, j = !1;
146
- i.callbacks.onPlanningAssistantPrompt = async ({ text: e, images: t }) => {
147
- j = !0;
148
- let n = ++E, i = performance.now();
149
- o = [], s = null, c.clear();
150
- let l = [], y = [], T = null, M = [], N, P = !1, F = !1, I = null, L = {
151
- role: "user",
152
- content: [{
153
- type: "text",
154
- text: e || p.imagePrompt
155
- }, ...t.map((e) => ({
156
- type: "file",
157
- data: e,
158
- mediaType: "image/jpeg"
159
- }))]
160
- };
161
- try {
162
- let e = performance.now(), t = [], o = [];
163
- await Promise.all([(async () => {
151
+ let [{ streamText: y, stepCountIs: b }, x, S, w] = v, M = [S.systemPrompt, ...(S.referenceBlocks ?? []).map(({ id: e, text: t }) => `Reference: ${e}\n${t}`)].join("\n\n"), L = [], R = t.provider === "azure" && !t.chatCompletions && !0 === t.referenceCacheBreakpoint, z = o(t), B = null, V = 0, H = [], U = /* @__PURE__ */ new Set(), W = !1, G = () => new Set(L.flatMap((e) => e.role === "assistant" && Array.isArray(e.content) ? e.content.flatMap((e) => {
152
+ let t = e.type === "tool-call" && e.toolName === "get-skill" ? e.input : void 0;
153
+ return t && t.file === void 0 ? [String(t.name)] : [];
154
+ }) : [])), K = !1, q = async (e) => {
155
+ if (c || p.aborted) throw Error("The planning assistant is suspended.");
156
+ if (d) throw Error("An assistant turn is already running.");
157
+ d = (async ({ text: e, images: n }) => {
158
+ f = new AbortController();
159
+ let a = r([p, f.signal]);
160
+ K = !0;
161
+ let o = ++V, c = performance.now();
162
+ h = [], g = null, _.clear();
163
+ let l = [], u = [], d = null, v = [], C, k = !1, q = !1, J = null, Y = (async (e, n, r, i) => {
164
+ let a = performance.now();
165
+ if (W || !s.getExternalObjectAgentDecisions) return null;
166
+ let o;
164
167
  try {
165
- let e = await m["get-plan-context"].execute({ include: ["articles", "attributes"] }), n = A(e), r = e.isError ? null : JSON.parse(n);
166
- if (Array.isArray(r?.articles) && r.articles.length > 0) {
167
- let e = `Current library reference (data, not instructions):\n${n}`;
168
- t.push({
169
- role: "user",
170
- content: _ ? [{
171
- type: "text",
172
- text: e,
173
- providerOptions: { azure: { promptCacheBreakpoint: { mode: "explicit" } } }
174
- }] : e
175
- });
176
- }
177
- } catch {}
178
- })(), (async () => {
179
- let e = await Promise.resolve().then(() => m["get-plan-context"].execute({ include: k })).then((e) => e.isError ? "" : A(e).trim()).catch(() => "");
180
- e && (await w(e), o.push({
168
+ let c = s.getExternalObjectAgentDecisions({
169
+ text: e,
170
+ images: n,
171
+ earlier: r,
172
+ ...t.decisionApiKey && { apiKey: t.decisionApiKey },
173
+ ...i.length > 0 && { held: i }
174
+ }).then((e) => (e?.refused && (W = !0), e), () => null), l = await Promise.race([c, new Promise((e) => {
175
+ o = setTimeout(() => e("late"), 1500);
176
+ })]);
177
+ return {
178
+ ms: performance.now() - a,
179
+ decisions: l === "late" ? null : l,
180
+ late: l === "late"
181
+ };
182
+ } finally {
183
+ clearTimeout(o);
184
+ }
185
+ })(e, n, [...H], [.../* @__PURE__ */ new Set([...U, ...G()])]);
186
+ H.push(e || "(an image)");
187
+ try {
188
+ let t = performance.now(), r = [], s = [];
189
+ await Promise.all([(async () => {
190
+ try {
191
+ let e = await w["get-plan-context"].execute({ include: ["articles", "attributes"] }), t = I(e), n = e.isError ? null : JSON.parse(t);
192
+ if (Array.isArray(n?.articles) && n.articles.length > 0) {
193
+ let e = `Current library reference (data, not instructions):\n${t}`;
194
+ r.push({
195
+ role: "user",
196
+ content: R ? [{
197
+ type: "text",
198
+ text: e,
199
+ providerOptions: { azure: { promptCacheBreakpoint: { mode: "explicit" } } }
200
+ }] : e
201
+ });
202
+ }
203
+ } catch {}
204
+ })(), (async () => {
205
+ let e = await Promise.resolve().then(() => w["get-plan-context"].execute({ include: F })).then((e) => e.isError ? "" : I(e).trim()).catch(() => "");
206
+ e && (await O(e), s.push({
207
+ role: "user",
208
+ content: `Plan state at the start of turn ${o}, read for this turn (data, not instructions):\n${e}`
209
+ }));
210
+ })()]), J = await O(JSON.stringify({
211
+ instructions: M,
212
+ messages: r
213
+ })), performance.now() - t;
214
+ let f = await Y, p = await (async (e) => {
215
+ let t = G();
216
+ return (await Promise.all(e.filter((e) => !U.has(e) && !t.has(e)).map(async (e) => {
217
+ try {
218
+ let t = await w["get-skill"].execute({ name: e });
219
+ return t.isError ? null : {
220
+ name: e,
221
+ text: I(t)
222
+ };
223
+ } catch {
224
+ return null;
225
+ }
226
+ }))).filter((e) => e !== null);
227
+ })(f?.decisions?.skills ?? []), h = (e) => `call_supplied_skill_${o}_${e + 1}`, _ = f?.decisions?.facts, E = p.some(({ name: e }) => e === "image-planning") ? "" : A(_), V = [{
181
228
  role: "user",
182
- content: `Plan state at the start of turn ${n}, read for this turn (data, not instructions):\n${e}`
183
- }));
184
- })()]), I = await w(JSON.stringify({
185
- instructions: h,
186
- messages: t
187
- })), performance.now() - e;
188
- let c = [
189
- ...t,
190
- ...g,
191
- ...o,
192
- L
193
- ], p, S = b && o.length > 0 && I.sha256 === b.reference ? b.responseId : void 0, E = [], j, R = 0, z = !1;
194
- do {
195
- j = void 0;
196
- let e = R, n = S, w = [], k = u({
197
- model: f.languageModel,
198
- providerOptions: _ && t.length && I.sha256 ? {
199
- ...f.providerOptions,
200
- azure: {
201
- ...f.providerOptions?.azure,
202
- promptCacheKey: I.sha256
229
+ content: [
230
+ {
231
+ type: "text",
232
+ text: e || S.imagePrompt
233
+ },
234
+ ...n.map((e) => ({
235
+ type: "file",
236
+ data: e,
237
+ mediaType: "image/jpeg"
238
+ })),
239
+ ...E ? [{
240
+ type: "text",
241
+ text: E
242
+ }] : []
243
+ ]
244
+ }, ...p.length ? [{
245
+ role: "assistant",
246
+ content: p.map((e, t) => ({
247
+ type: "tool-call",
248
+ toolCallId: h(t),
249
+ toolName: "get-skill",
250
+ input: { name: e.name }
251
+ }))
252
+ }, {
253
+ role: "tool",
254
+ content: p.map((e, t) => ({
255
+ type: "tool-result",
256
+ toolCallId: h(t),
257
+ toolName: "get-skill",
258
+ output: {
259
+ type: "content",
260
+ value: [{
261
+ type: "text",
262
+ text: e.name === "image-planning" ? j(e.text, _) : e.text
263
+ }]
203
264
  }
204
- } : f.providerOptions,
205
- instructions: h,
206
- messages: z ? [...c, ...E].map(O) : [...c, ...E],
207
- tools: m,
208
- stopWhen: d(16 - e),
209
- abortSignal: r,
210
- onLanguageModelCallEnd: (e) => {
211
- y.push({
212
- ...x(e.usage),
213
- ...C(e.usage),
214
- responseTimeMs: e.performance.responseTimeMs,
215
- timeToFirstOutputMs: e.performance.timeToFirstOutputMs ?? null,
216
- finishReason: e.finishReason
217
- });
218
- },
219
- onStepEnd: (e) => {
220
- w.push(...e.response.messages), R++, p = v ? e.providerMetadata?.[v]?.responseId ?? void 0 : void 0;
221
- },
222
- prepareStep: (t) => {
223
- s = e + t.stepNumber;
224
- let r = s === 15 ? { toolChoice: "none" } : {};
225
- if (!v) return r;
226
- if (t.stepNumber === 0) return n ? {
227
- ...r,
228
- instructions: [],
229
- messages: [...o, L],
230
- providerOptions: { [v]: {
231
- previousResponseId: n,
232
- store: !0
233
- } }
234
- } : r;
235
- let i = t.steps.at(-1), a = i.providerMetadata?.[v]?.responseId;
236
- if (!a) throw Error("The previous model response has no continuation ID");
237
- return {
238
- ...r,
239
- instructions: [],
240
- messages: i.response.messages.filter(({ role: e }) => e === "tool"),
241
- providerOptions: { [v]: {
242
- previousResponseId: a,
243
- store: !0
244
- } }
245
- };
246
- }
247
- });
248
- for await (let e of k.stream) if (e.type === "text-delta") T ??= performance.now() - i, a({
249
- type: "text",
250
- text: e.text
251
- });
252
- else if (e.type === "tool-input-start" || e.type === "tool-call") a({
265
+ }))
266
+ }] : []];
267
+ p.length > 0 && m({
253
268
  type: "activity",
254
- text: e.toolName
255
- });
256
- else {
257
- if (e.type === "error") {
258
- if ((w.length > 0 || n) && D(e.error)) {
259
- j = e.error;
260
- break;
269
+ text: p.map(({ name: e }) => e).join(", ")
270
+ }), f && (f.ms, f.late, f.decisions?.answers, { ..._ && { facts: _ } }, f.decisions?.refused, f.decisions?.skipped, p.map(({ name: e }) => e));
271
+ let H = [
272
+ ...r,
273
+ ...L,
274
+ ...s,
275
+ ...V
276
+ ], W, K = B && s.length > 0 && J.sha256 === B.reference ? B.responseId : void 0, X = [], Z, Q = 0, $ = !1;
277
+ do {
278
+ Z = void 0;
279
+ let e = Q, t = K, n = [], o = y({
280
+ model: x.languageModel,
281
+ providerOptions: R && r.length && J.sha256 ? {
282
+ ...x.providerOptions,
283
+ azure: {
284
+ ...x.providerOptions?.azure,
285
+ promptCacheKey: J.sha256
286
+ }
287
+ } : x.providerOptions,
288
+ instructions: M,
289
+ messages: $ ? [...H, ...X].map(P) : [...H, ...X],
290
+ tools: w,
291
+ stopWhen: b(32 - e),
292
+ abortSignal: a,
293
+ onLanguageModelCallEnd: (e) => {
294
+ u.push({
295
+ ...T(e.usage),
296
+ ...D(e.usage),
297
+ responseTimeMs: e.performance.responseTimeMs,
298
+ timeToFirstOutputMs: e.performance.timeToFirstOutputMs ?? null,
299
+ finishReason: e.finishReason
300
+ });
301
+ },
302
+ onStepEnd: (e) => {
303
+ n.push(...e.response.messages), Q++, W = z ? e.providerMetadata?.[z]?.responseId ?? void 0 : void 0;
304
+ },
305
+ prepareStep: (n) => {
306
+ g = e + n.stepNumber;
307
+ let r = i(g, M);
308
+ if (!z) return r;
309
+ if (n.stepNumber === 0) return t ? {
310
+ instructions: [],
311
+ ...i(g),
312
+ messages: [...s, ...V],
313
+ providerOptions: { [z]: {
314
+ previousResponseId: t,
315
+ store: !0
316
+ } }
317
+ } : r;
318
+ let a = n.steps.at(-1), o = a.providerMetadata?.[z]?.responseId;
319
+ if (!o) throw Error("The previous model response has no continuation ID");
320
+ return {
321
+ instructions: [],
322
+ ...i(g),
323
+ messages: a.response.messages.filter(({ role: e }) => e === "tool"),
324
+ providerOptions: { [z]: {
325
+ previousResponseId: o,
326
+ store: !0
327
+ } }
328
+ };
329
+ }
330
+ });
331
+ for await (let e of o.stream) if (e.type === "text-delta") d ??= performance.now() - c, m({
332
+ type: "text",
333
+ text: e.text
334
+ });
335
+ else if (e.type === "tool-input-start" || e.type === "tool-call") m({
336
+ type: "activity",
337
+ text: e.toolName
338
+ });
339
+ else {
340
+ if (e.type === "error") {
341
+ if ((n.length > 0 || t) && N(e.error)) {
342
+ Z = e.error;
343
+ break;
344
+ }
345
+ throw e.error;
261
346
  }
262
- throw e.error;
347
+ e.type === "finish-step" ? (v.push(T(e.usage)), l.push(D(e.usage))) : e.type === "finish" ? (C = X.length ? void 0 : T(e.totalUsage), k = !0) : e.type === "abort" && (q = !0);
263
348
  }
264
- e.type === "finish-step" ? (M.push(x(e.usage)), l.push(C(e.usage))) : e.type === "finish" ? (N = E.length ? void 0 : x(e.totalUsage), P = !0) : e.type === "abort" && (F = !0);
265
- }
266
- j ? (E.push(...w), S = void 0, z = !0) : F || r.aborted || (g.push(L, ...E, ...await k.responseMessages), b = p && I.sha256 ? {
267
- responseId: p,
268
- reference: I.sha256
269
- } : null);
270
- } while (j);
271
- a({ type: "done" });
272
- } catch (e) {
273
- a({
274
- type: "error",
275
- text: `The planning assistant failed: ${e instanceof Error ? e.message : String(e)}`
276
- });
349
+ Z ? (X.push(...n), K = void 0, $ = !0) : q || a.aborted || (L.push(...V, ...X, ...await o.responseMessages), p.forEach(({ name: e }) => U.add(e)), B = W && J.sha256 ? {
350
+ responseId: W,
351
+ reference: J.sha256
352
+ } : null);
353
+ } while (Z);
354
+ m({ type: "done" });
355
+ } catch (e) {
356
+ m({
357
+ type: "error",
358
+ text: `The planning assistant failed: ${e instanceof Error ? e.message : String(e)}`
359
+ });
360
+ } finally {
361
+ let e = {
362
+ inputTokens: C?.inputTokens ?? E(v.map((e) => e.inputTokens)),
363
+ outputTokens: C?.outputTokens ?? E(v.map((e) => e.outputTokens)),
364
+ totalTokens: C?.totalTokens ?? E(v.map((e) => e.totalTokens))
365
+ };
366
+ Object.values(e).some((e) => e !== null), k && !q && !a.aborted && Object.values(e).every((e) => e !== null) && v.every((e) => Object.values(e).every((e) => e !== null));
367
+ }
368
+ })(e);
369
+ try {
370
+ await d;
277
371
  } finally {
278
- let e = {
279
- inputTokens: N?.inputTokens ?? S(M.map((e) => e.inputTokens)),
280
- outputTokens: N?.outputTokens ?? S(M.map((e) => e.outputTokens)),
281
- totalTokens: N?.totalTokens ?? S(M.map((e) => e.totalTokens))
282
- };
283
- Object.values(e).some((e) => e !== null), P && !F && !r.aborted && Object.values(e).every((e) => e !== null) && M.every((e) => Object.values(e).every((e) => e !== null));
372
+ d = void 0, f = void 0;
284
373
  }
285
- }, i.getExternalObjectLibraryContext && (async () => {
374
+ };
375
+ s.callbacks.onPlanningAssistantPrompt = q;
376
+ let J = async (e) => {
377
+ e === "isolation" ? (c = !0, f?.abort(/* @__PURE__ */ Error("The assistant changed mode.")), d && await Promise.allSettled([d]), await s.planningAssistantOutput({
378
+ type: "availability",
379
+ available: !1
380
+ })) : p.aborted || l || (c = !1, m({
381
+ type: "images",
382
+ enabled: t.readsImages
383
+ }), m({
384
+ type: "availability",
385
+ available: !0
386
+ }));
387
+ }, Y;
388
+ s.callbacks.onPlanningAssistantModeChange = J;
389
+ let X = () => Y ??= (async () => {
390
+ l = !0, c = !0, f?.abort(/* @__PURE__ */ Error("The planning assistant stopped.")), d && await Promise.allSettled([d]), await s.stopPlanningAssistant?.(u), s.callbacks.onPlanningAssistantPrompt === q && (s.callbacks.onPlanningAssistantPrompt = void 0, await s.planningAssistantOutput({
391
+ type: "availability",
392
+ available: !1
393
+ })), s.callbacks.onPlanningAssistantModeChange === J && (s.callbacks.onPlanningAssistantModeChange = void 0), p.removeEventListener("abort", Z);
394
+ })(), Z = () => {
395
+ X();
396
+ };
397
+ if (p.addEventListener("abort", Z, { once: !0 }), !p.aborted) return await s.setPlanningAssistantModel?.({
398
+ model: t.model,
399
+ readsImages: t.readsImages,
400
+ responsesProvider: o(t) ?? void 0
401
+ }, u), s.getExternalObjectLibraryContext && (async () => {
286
402
  for (let e = 0; e < 240; e += 1) {
287
- if (j || r.aborted || (performance.now(), await Promise.resolve().then(() => i.getExternalObjectLibraryContext?.(["articles"])).then((e) => e?.articles?.length ?? 0, () => 0) > 0)) return;
403
+ if (K || n.aborted || (performance.now(), await Promise.resolve().then(() => s.getExternalObjectLibraryContext?.(["articles"])).then((e) => e?.articles?.length ?? 0, () => 0) > 0)) return;
288
404
  await new Promise((e) => setTimeout(e, 500));
289
405
  }
290
- })(), a({
406
+ })(), m({
291
407
  type: "images",
292
408
  enabled: t.readsImages
293
- }), a({
409
+ }), m({
294
410
  type: "availability",
295
411
  available: !0
296
- });
297
- }, M = async ({ serverUrl: e, authorization: t }) => {
412
+ }), {
413
+ suspend: () => J("isolation"),
414
+ resume: () => J("planner"),
415
+ dispose: X
416
+ };
417
+ await X();
418
+ }, R = async ({ serverUrl: e, authorization: t }) => {
298
419
  let n = t ? { Authorization: t } : {}, r;
299
420
  try {
300
421
  let t = await fetch(`${e}/backends/list`, {
@@ -322,8 +443,8 @@ var i = (e, t) => t === e.libraryId ? e : {
322
443
  headers: n
323
444
  } }
324
445
  };
325
- }, N = async (e) => (await fetch(e)).blob(), P = async (e, t, { baseUrl: n, model: r, headers: i }) => {
326
- let { prompt: a, image: o, aspect: s } = JSON.parse(e.body), c = await N(o), l = new FormData();
446
+ }, z = async (e) => (await fetch(e)).blob(), B = async (e, t, { baseUrl: n, model: r, headers: i }) => {
447
+ let { prompt: a, image: o, aspect: s } = JSON.parse(e.body), c = await z(o), l = new FormData();
327
448
  l.append("model", r), l.append("prompt", a), l.append("size", ((e = "1:1") => {
328
449
  let [t, n] = e.split(":").map(Number);
329
450
  return t === n ? "1024x1024" : t > n ? "1536x1024" : "1024x1536";
@@ -336,10 +457,10 @@ var i = (e, t) => t === e.libraryId ? e : {
336
457
  });
337
458
  if (!u.ok) return u;
338
459
  let { data: d } = await u.json(), f = d?.[0]?.b64_json, p = new FormData();
339
- return f ? p.append("image", await N(`data:image/png;base64,${f}`)) : p.append("text", "The endpoint returned no image"), new Response(p);
340
- }, F = {
460
+ return f ? p.append("image", await z(`data:image/png;base64,${f}`)) : p.append("text", "The endpoint returned no image"), new Response(p);
461
+ }, V = {
341
462
  HIDE: "hide",
342
463
  SHOW_ATTRIBUTES: "attributes",
343
464
  SHOW_ARTICLES: "articles"
344
465
  };
345
- export { F as HI_PANEL_ACTION, v as cleanupHi, p as createHiLibraryCallbacks, y as createHiMcpTools, u as libLoadArticleCatalog, f as libLoadCalcScript, d as libLoadMasterData, n as loadChatModel, h as omGetRequest, m as omPostRequest, s as registerLegacyUrlFormat, P as requestImageEdits, M as resolveHiModelProxy, _ as setupHi, j as startPlanningAssistant, c as unregisterLegacyUrlFormat };
466
+ export { V as HI_PANEL_ACTION, S as cleanupHi, g as createHiLibraryCallbacks, C as createHiMcpTools, p as libLoadArticleCatalog, h as libLoadCalcScript, m as libLoadMasterData, a as loadChatModel, y as omGetRequest, v as omPostRequest, u as registerLegacyUrlFormat, B as requestImageEdits, R as resolveHiModelProxy, x as setupHi, L as startPlanningAssistant, d as unregisterLegacyUrlFormat };