likec4 1.57.0 → 1.58.0

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 (168) hide show
  1. package/__app__/codegen/react.mjs +7 -8
  2. package/__app__/codegen/webcomponent.mjs +70 -881
  3. package/__app__/src/aichat/index.mjs +8 -1
  4. package/__app__/src/chunks/AIChat.mjs +959 -0
  5. package/__app__/src/chunks/DiagramActorProvider.mjs +7638 -0
  6. package/__app__/src/chunks/LikeC4Styles.mjs +1866 -0
  7. package/__app__/src/chunks/Markdown.mjs +146 -0
  8. package/__app__/src/chunks/NavigationPanel.mjs +61 -0
  9. package/__app__/src/chunks/ProjectsOverview.mjs +540 -0
  10. package/__app__/src/chunks/adhoc-editor.mjs +3386 -0
  11. package/__app__/src/chunks/es.mjs +439 -0
  12. package/__app__/src/chunks/hooks.mjs +145 -0
  13. package/__app__/src/chunks/libs/@dagrejs/dagre.mjs +1894 -0
  14. package/__app__/src/chunks/libs/@floating-ui.mjs +2218 -0
  15. package/__app__/src/chunks/libs/@mantine.mjs +12070 -0
  16. package/__app__/src/chunks/libs/@tabler/icons-react.mjs +252 -0
  17. package/__app__/src/chunks/libs/@tanstack-ai.mjs +1768 -0
  18. package/__app__/src/chunks/libs/@tanstack.mjs +2718 -0
  19. package/__app__/src/chunks/libs/@xstate/react.mjs +1982 -0
  20. package/__app__/src/chunks/libs/@xyflow/react.mjs +5256 -0
  21. package/__app__/src/chunks/libs/bezier-js.mjs +1003 -0
  22. package/__app__/src/chunks/libs/d3.mjs +2842 -0
  23. package/__app__/src/chunks/libs/fast-equals.mjs +268 -0
  24. package/__app__/src/chunks/libs/framer.mjs +5872 -0
  25. package/__app__/src/chunks/libs/remeda.mjs +642 -0
  26. package/__app__/src/chunks/libs/zod.mjs +3170 -0
  27. package/__app__/src/chunks/rolldown-runtime.mjs +23 -0
  28. package/__app__/src/chunks/styled-system.mjs +1040 -0
  29. package/__app__/src/fonts.css +1 -1
  30. package/__app__/src/main.mjs +14816 -14
  31. package/__app__/src/style.css +1 -1
  32. package/dist/chunks/enableServer.mjs +1 -1
  33. package/dist/chunks/filenames.mjs +2 -2
  34. package/dist/chunks/index2.d.mts +1877 -734
  35. package/dist/chunks/libs/@chevrotain/gast.mjs +1 -1
  36. package/dist/chunks/libs/@logtape/logtape.mjs +4 -3
  37. package/dist/chunks/libs/chevrotain-allstar.mjs +2 -2
  38. package/dist/chunks/libs/chevrotain.mjs +25 -25
  39. package/dist/chunks/libs/langium.mjs +1 -1
  40. package/dist/chunks/libs/merge-error-cause.mjs +1 -1
  41. package/dist/chunks/libs/pretty-ms.mjs +1 -1
  42. package/dist/chunks/libs/remeda.mjs +1 -1
  43. package/dist/chunks/libs/ufo.mjs +1 -1
  44. package/dist/chunks/libs/unstorage.mjs +1 -1
  45. package/dist/chunks/libs/which.mjs +1 -1
  46. package/dist/chunks/libs/zod.mjs +65 -0
  47. package/dist/chunks/node.mjs +73 -62
  48. package/dist/chunks/{plugin.mjs → vite-plugin.mjs} +41 -41
  49. package/dist/cli/index.mjs +184 -144
  50. package/dist/index.d.mts +1 -1
  51. package/dist/index.mjs +1 -1
  52. package/dist/model/index.d.mts +1 -1
  53. package/dist/vite-plugin/index.mjs +1 -1
  54. package/dist/vite-plugin/internal/index.d.mts +52 -57
  55. package/dist/vite-plugin/internal/index.mjs +946 -1
  56. package/package.json +46 -47
  57. package/react/index.d.mts +92 -23
  58. package/react/index.mjs +44551 -42605
  59. package/__app__/chunks/AIChat2.mjs +0 -2
  60. package/__app__/chunks/DiagramActorProvider.mjs +0 -10
  61. package/__app__/chunks/EmbedPage.mjs +0 -1
  62. package/__app__/chunks/ExportPage.mjs +0 -2
  63. package/__app__/chunks/LikeC4Diagram.mjs +0 -19
  64. package/__app__/chunks/LikeC4Styles.mjs +0 -48
  65. package/__app__/chunks/Markdown.mjs +0 -1
  66. package/__app__/chunks/NavigationPanel.mjs +0 -1
  67. package/__app__/chunks/ViewReact.mjs +0 -1
  68. package/__app__/chunks/adhoc-editor.mjs +0 -1
  69. package/__app__/chunks/aichat.mjs +0 -1
  70. package/__app__/chunks/box.mjs +0 -1
  71. package/__app__/chunks/create-style-context.mjs +0 -1
  72. package/__app__/chunks/css.mjs +0 -1
  73. package/__app__/chunks/factory.mjs +0 -1
  74. package/__app__/chunks/hooks.mjs +0 -1
  75. package/__app__/chunks/hstack.mjs +0 -1
  76. package/__app__/chunks/libs/@dagrejs/dagre.mjs +0 -1
  77. package/__app__/chunks/libs/@floating-ui/core.mjs +0 -1
  78. package/__app__/chunks/libs/@floating-ui/dom.mjs +0 -1
  79. package/__app__/chunks/libs/@floating-ui/react.mjs +0 -1
  80. package/__app__/chunks/libs/@mantine/core.mjs +0 -41
  81. package/__app__/chunks/libs/@mantine/hooks.mjs +0 -1
  82. package/__app__/chunks/libs/@nanostores/react.mjs +0 -1
  83. package/__app__/chunks/libs/@react-hookz/web.mjs +0 -1
  84. package/__app__/chunks/libs/@tabler/icons-react.mjs +0 -358
  85. package/__app__/chunks/libs/@tanstack/ai-client.mjs +0 -2
  86. package/__app__/chunks/libs/@tanstack/ai-react-ui.mjs +0 -1
  87. package/__app__/chunks/libs/@tanstack/ai-react.mjs +0 -1
  88. package/__app__/chunks/libs/@tanstack/ai.mjs +0 -2
  89. package/__app__/chunks/libs/@tanstack/history.mjs +0 -1
  90. package/__app__/chunks/libs/@tanstack/react-router.mjs +0 -3
  91. package/__app__/chunks/libs/@tanstack/router-core.mjs +0 -1
  92. package/__app__/chunks/libs/@xstate/react.mjs +0 -1
  93. package/__app__/chunks/libs/@xstate/store.mjs +0 -1
  94. package/__app__/chunks/libs/@xyflow/react.mjs +0 -7
  95. package/__app__/chunks/libs/@zag-js/anatomy.mjs +0 -1
  96. package/__app__/chunks/libs/@zag-js/collection.mjs +0 -1
  97. package/__app__/chunks/libs/@zag-js/core.mjs +0 -1
  98. package/__app__/chunks/libs/@zag-js/react.mjs +0 -1
  99. package/__app__/chunks/libs/@zag-js/tree-view.mjs +0 -1
  100. package/__app__/chunks/libs/bezier-js.mjs +0 -1
  101. package/__app__/chunks/libs/copy-anything.mjs +0 -1
  102. package/__app__/chunks/libs/d3-path.mjs +0 -1
  103. package/__app__/chunks/libs/d3-shape.mjs +0 -1
  104. package/__app__/chunks/libs/fast-equals.mjs +0 -1
  105. package/__app__/chunks/libs/framer-motion.mjs +0 -9
  106. package/__app__/chunks/libs/html-to-image.mjs +0 -2
  107. package/__app__/chunks/libs/motion-dom.mjs +0 -1
  108. package/__app__/chunks/libs/nanostores.mjs +0 -1
  109. package/__app__/chunks/libs/react-error-boundary.mjs +0 -1
  110. package/__app__/chunks/libs/react-resizable-panels.mjs +0 -1
  111. package/__app__/chunks/libs/remeda.mjs +0 -1
  112. package/__app__/chunks/libs/superjson.mjs +0 -1
  113. package/__app__/chunks/libs/zod.mjs +0 -64
  114. package/__app__/chunks/rolldown-runtime.mjs +0 -1
  115. package/__app__/chunks/styles.css.mjs +0 -1
  116. package/__app__/chunks/txt.mjs +0 -1
  117. package/__app__/chunks/useLikeC4Project.mjs +0 -1
  118. package/__app__/src/pages/AdHocViewEditor.mjs +0 -1
  119. package/__app__/src/pages/EmbedPage.mjs +0 -1
  120. package/__app__/src/pages/ExportPage.mjs +0 -1
  121. package/__app__/src/pages/ProjectsOverview.mjs +0 -1
  122. package/__app__/src/pages/ViewAsD2.mjs +0 -1
  123. package/__app__/src/pages/ViewAsDot.mjs +0 -1
  124. package/__app__/src/pages/ViewAsMmd.mjs +0 -1
  125. package/__app__/src/pages/ViewAsPuml.mjs +0 -1
  126. package/__app__/src/pages/ViewEditor.mjs +0 -1
  127. package/__app__/src/pages/ViewReact.mjs +0 -1
  128. package/dist/chunks/libs/@chevrotain/utils.mjs +0 -1
  129. package/dist/chunks/libs/@hono/mcp.mjs +0 -70
  130. package/dist/chunks/libs/@hono/node-server.mjs +0 -1
  131. package/dist/chunks/libs/@logtape/logtape.d.mts +0 -1023
  132. package/dist/chunks/libs/@modelcontextprotocol/sdk.mjs +0 -12
  133. package/dist/chunks/libs/ajv.mjs +0 -1
  134. package/dist/chunks/libs/ansi-align.mjs +0 -2
  135. package/dist/chunks/libs/ansi-regex.mjs +0 -1
  136. package/dist/chunks/libs/ansi-styles.mjs +0 -1
  137. package/dist/chunks/libs/atomically.mjs +0 -1
  138. package/dist/chunks/libs/boxen.mjs +0 -22
  139. package/dist/chunks/libs/conf.mjs +0 -1
  140. package/dist/chunks/libs/defu.mjs +0 -1
  141. package/dist/chunks/libs/destr.mjs +0 -1
  142. package/dist/chunks/libs/find-up-simple.mjs +0 -1
  143. package/dist/chunks/libs/get-port.mjs +0 -1
  144. package/dist/chunks/libs/hono.mjs +0 -1
  145. package/dist/chunks/libs/is-docker.mjs +0 -1
  146. package/dist/chunks/libs/is-error-instance.mjs +0 -1
  147. package/dist/chunks/libs/is-inside-container.mjs +0 -1
  148. package/dist/chunks/libs/is-plain-obj.mjs +0 -1
  149. package/dist/chunks/libs/isexe.mjs +0 -1
  150. package/dist/chunks/libs/ky.mjs +0 -3
  151. package/dist/chunks/libs/p-debounce.mjs +0 -1
  152. package/dist/chunks/libs/p-limit.mjs +0 -1
  153. package/dist/chunks/libs/p-timeout.mjs +0 -1
  154. package/dist/chunks/libs/package-up.mjs +0 -1
  155. package/dist/chunks/libs/parse-ms.mjs +0 -1
  156. package/dist/chunks/libs/safe-stringify.mjs +0 -1
  157. package/dist/chunks/libs/strip-indent.mjs +0 -1
  158. package/dist/chunks/libs/tinyrainbow.mjs +0 -1
  159. package/dist/chunks/libs/ts-graphviz.mjs +0 -1
  160. package/dist/chunks/libs/unctx.mjs +0 -1
  161. package/dist/chunks/libs/vscode-languageserver.mjs +0 -1
  162. package/dist/chunks/libs/word-wrap.mjs +0 -12
  163. package/dist/vite-plugin/internal/chunks/libs/@nanostores/react.mjs +0 -1
  164. package/dist/vite-plugin/internal/chunks/libs/birpc.mjs +0 -1
  165. package/dist/vite-plugin/internal/chunks/libs/fast-equals.mjs +0 -1
  166. package/dist/vite-plugin/internal/chunks/libs/nanostores.mjs +0 -1
  167. package/dist/vite-plugin/internal/chunks/libs/remeda.mjs +0 -1
  168. package/dist/vite-plugin/internal/chunks/rolldown-runtime.mjs +0 -1
@@ -0,0 +1,1768 @@
1
+ import { t as e } from "../rolldown-runtime.mjs";
2
+ import { createContext as t, useCallback as n, useEffect as r, useId as i, useMemo as a, useRef as o, useState as s } from "react";
3
+ import { Fragment as c, jsx as l, jsxs as u } from "react/jsx-runtime";
4
+ //#region ../../node_modules/.pnpm/@tanstack+devtools-event-client@0.4.3/node_modules/@tanstack/devtools-event-client/dist/esm/plugin.js
5
+ var EventClient = class {
6
+ #e = !0;
7
+ #t;
8
+ #n;
9
+ #r;
10
+ #i;
11
+ #a;
12
+ #o;
13
+ #s;
14
+ #c = 0;
15
+ #l = 5;
16
+ #u = !1;
17
+ #d = !1;
18
+ #f = null;
19
+ #p = () => {
20
+ this.debugLog("Connected to event bus"), this.#a = !0, this.#u = !1, this.debugLog("Emitting queued events", this.#i), this.#i.forEach((e) => this.emitEventToBus(e)), this.#i = [], this.stopConnectLoop(), this.#n().removeEventListener("tanstack-connect-success", this.#p);
21
+ };
22
+ #m = () => {
23
+ if (this.#c < this.#l) {
24
+ this.#c++, this.dispatchCustomEvent("tanstack-connect", {});
25
+ return;
26
+ }
27
+ this.#n().removeEventListener("tanstack-connect", this.#m), this.#d = !0, this.debugLog("Max retries reached, giving up on connection"), this.stopConnectLoop();
28
+ };
29
+ #h = () => {
30
+ this.#u || (this.#u = !0, this.#n().addEventListener("tanstack-connect-success", this.#p), this.#m());
31
+ };
32
+ constructor({ pluginId: e, debug: t = !1, enabled: n = !0, reconnectEveryMs: r = 300 }) {
33
+ this.#t = e, this.#e = n, this.#n = this.getGlobalTarget, this.#r = t, this.debugLog(" Initializing event subscription for plugin", this.#t), this.#i = [], this.#a = !1, this.#d = !1, this.#o = null, this.#s = r;
34
+ }
35
+ startConnectLoop() {
36
+ this.#o !== null || this.#a || (this.debugLog(`Starting connect loop (every ${this.#s}ms)`), this.#o = setInterval(this.#m, this.#s));
37
+ }
38
+ stopConnectLoop() {
39
+ this.#u = !1, this.#o !== null && (clearInterval(this.#o), this.#o = null, this.#i = [], this.debugLog("Stopped connect loop"));
40
+ }
41
+ debugLog(...e) {
42
+ this.#r && console.log(`🌴 [tanstack-devtools:${this.#t}-plugin]`, ...e);
43
+ }
44
+ getGlobalTarget() {
45
+ if (typeof globalThis < "u" && globalThis.__TANSTACK_EVENT_TARGET__) return this.debugLog("Using global event target"), globalThis.__TANSTACK_EVENT_TARGET__;
46
+ if (typeof window < "u" && window.addEventListener !== void 0) return this.debugLog("Using window as event target"), window;
47
+ let e = typeof EventTarget < "u" ? new EventTarget() : void 0;
48
+ return e === void 0 || e.addEventListener === void 0 ? (this.debugLog("No event mechanism available, running in non-web environment"), {
49
+ addEventListener: () => {},
50
+ removeEventListener: () => {},
51
+ dispatchEvent: () => !1
52
+ }) : (this.debugLog("Using new EventTarget as fallback"), e);
53
+ }
54
+ getPluginId() {
55
+ return this.#t;
56
+ }
57
+ dispatchCustomEventShim(e, t) {
58
+ try {
59
+ let n = new Event(e, { detail: t });
60
+ this.#n().dispatchEvent(n);
61
+ } catch {
62
+ this.debugLog("Failed to dispatch shim event");
63
+ }
64
+ }
65
+ dispatchCustomEvent(e, t) {
66
+ try {
67
+ this.#n().dispatchEvent(new CustomEvent(e, { detail: t }));
68
+ } catch {
69
+ this.dispatchCustomEventShim(e, t);
70
+ }
71
+ }
72
+ emitEventToBus(e) {
73
+ this.debugLog("Emitting event to client bus", e), this.dispatchCustomEvent("tanstack-dispatch-event", e);
74
+ }
75
+ createEventPayload(e, t) {
76
+ return {
77
+ type: `${this.#t}:${e}`,
78
+ payload: t,
79
+ pluginId: this.#t
80
+ };
81
+ }
82
+ emit(e, t) {
83
+ if (!this.#e) {
84
+ this.debugLog("Event bus client is disabled, not emitting event", e, t);
85
+ return;
86
+ }
87
+ if (this.#f && (this.debugLog("Emitting event to internal event target", e, t), this.#f.dispatchEvent(new CustomEvent(`${this.#t}:${e}`, { detail: this.createEventPayload(e, t) }))), this.#d) {
88
+ this.debugLog("Previously failed to connect, not emitting to bus");
89
+ return;
90
+ }
91
+ if (!this.#a) {
92
+ this.debugLog("Bus not available, will be pushed as soon as connected"), this.#i.push(this.createEventPayload(e, t)), typeof CustomEvent < "u" && !this.#u && (this.#h(), this.startConnectLoop());
93
+ return;
94
+ }
95
+ return this.emitEventToBus(this.createEventPayload(e, t));
96
+ }
97
+ on(e, t, n) {
98
+ let r = n?.withEventTarget ?? !1, i = `${this.#t}:${e}`;
99
+ if (r && (this.#f ||= new EventTarget(), this.#f.addEventListener(i, (e) => {
100
+ t(e.detail);
101
+ })), !this.#e) return this.debugLog("Event bus client is disabled, not registering event", i), () => {};
102
+ let handler = (e) => {
103
+ this.debugLog("Received event from bus", e.detail), t(e.detail);
104
+ };
105
+ return this.#n().addEventListener(i, handler), this.debugLog("Registered event to bus", i), () => {
106
+ r && this.#f?.removeEventListener(i, handler), this.#n().removeEventListener(i, handler);
107
+ };
108
+ }
109
+ onAll(e) {
110
+ if (!this.#e) return this.debugLog("Event bus client is disabled, not registering event"), () => {};
111
+ let handler = (t) => {
112
+ let n = t.detail;
113
+ e(n);
114
+ };
115
+ return this.#n().addEventListener("tanstack-devtools-global", handler), () => this.#n().removeEventListener("tanstack-devtools-global", handler);
116
+ }
117
+ onAllPluginEvents(e) {
118
+ if (!this.#e) return this.debugLog("Event bus client is disabled, not registering event"), () => {};
119
+ let handler = (t) => {
120
+ let n = t.detail;
121
+ this.#t && n.pluginId !== this.#t || e(n);
122
+ };
123
+ return this.#n().addEventListener("tanstack-devtools-global", handler), () => this.#n().removeEventListener("tanstack-devtools-global", handler);
124
+ }
125
+ }, AiEventClient = class extends EventClient {
126
+ constructor() {
127
+ super({ pluginId: "tanstack-ai-devtools" });
128
+ }
129
+ }, d = new AiEventClient();
130
+ //#endregion
131
+ //#region ../../node_modules/.pnpm/@tanstack+ai@0.14.0/node_modules/@tanstack/ai/dist/esm/activities/chat/messages.js
132
+ function isContentPart(e) {
133
+ return e.type === "text" || e.type === "image" || e.type === "audio" || e.type === "video" || e.type === "document";
134
+ }
135
+ function collapseContentParts(e) {
136
+ return e.length === 0 ? null : e.every((e) => e.type === "text") ? e.map((e) => e.content).join("") || null : e;
137
+ }
138
+ function getTextContent(e) {
139
+ return e === null ? "" : typeof e == "string" ? e : e.filter((e) => e.type === "text").map((e) => e.content).join("");
140
+ }
141
+ function uiMessageToModelMessages(e) {
142
+ return e.role === "system" ? [] : e.role === "assistant" ? buildAssistantMessages(e) : [buildUserOrToolMessage(e)];
143
+ }
144
+ function buildUserOrToolMessage(e) {
145
+ let t = [];
146
+ for (let n of e.parts) isContentPart(n) && t.push(n);
147
+ return {
148
+ role: e.role,
149
+ content: collapseContentParts(t)
150
+ };
151
+ }
152
+ function createSegment() {
153
+ return {
154
+ contentParts: [],
155
+ toolCalls: []
156
+ };
157
+ }
158
+ function isToolCallIncluded(e) {
159
+ return e.state === "input-complete" || e.state === "approval-responded" || e.output !== void 0;
160
+ }
161
+ function buildAssistantMessages(e) {
162
+ let t = [], n = createSegment(), r = /* @__PURE__ */ new Set();
163
+ function flushSegment() {
164
+ let e = collapseContentParts(n.contentParts), r = e !== null, i = n.toolCalls.length > 0;
165
+ (r || i) && t.push({
166
+ role: "assistant",
167
+ content: e,
168
+ ...i && { toolCalls: n.toolCalls }
169
+ }), n = createSegment();
170
+ }
171
+ for (let i of e.parts) switch (i.type) {
172
+ case "text":
173
+ case "image":
174
+ case "audio":
175
+ case "video":
176
+ case "document":
177
+ n.contentParts.push(i);
178
+ break;
179
+ case "tool-call":
180
+ isToolCallIncluded(i) && n.toolCalls.push({
181
+ id: i.id,
182
+ type: "function",
183
+ function: {
184
+ name: i.name,
185
+ arguments: i.arguments
186
+ }
187
+ });
188
+ break;
189
+ case "tool-result":
190
+ flushSegment(), (i.state === "complete" || i.state === "error") && !r.has(i.toolCallId) && (t.push({
191
+ role: "tool",
192
+ content: i.content,
193
+ toolCallId: i.toolCallId
194
+ }), r.add(i.toolCallId));
195
+ break;
196
+ }
197
+ flushSegment();
198
+ for (let n of e.parts) if (n.type === "tool-call" && (n.output !== void 0 && !r.has(n.id) && (t.push({
199
+ role: "tool",
200
+ content: JSON.stringify(n.output),
201
+ toolCallId: n.id
202
+ }), r.add(n.id)), n.output === void 0 && n.state === "approval-responded" && n.approval?.approved !== void 0 && !r.has(n.id))) {
203
+ let e = n.approval.approved;
204
+ t.push({
205
+ role: "tool",
206
+ content: JSON.stringify({
207
+ approved: e,
208
+ ...e && { pendingExecution: !0 },
209
+ message: e ? "User approved this action" : "User denied this action"
210
+ }),
211
+ toolCallId: n.id
212
+ }), r.add(n.id);
213
+ }
214
+ return t.length === 0 && t.push({
215
+ role: "assistant",
216
+ content: null
217
+ }), t;
218
+ }
219
+ function modelMessageToUIMessage(e, t) {
220
+ let n = [];
221
+ if (e.role === "tool" && e.toolCallId) n.push({
222
+ type: "tool-result",
223
+ toolCallId: e.toolCallId,
224
+ content: getTextContent(e.content),
225
+ state: "complete"
226
+ });
227
+ else if (Array.isArray(e.content)) for (let t of e.content) n.push(t);
228
+ else {
229
+ let t = getTextContent(e.content);
230
+ t && n.push({
231
+ type: "text",
232
+ content: t
233
+ });
234
+ }
235
+ if (e.toolCalls && e.toolCalls.length > 0) for (let t of e.toolCalls) n.push({
236
+ type: "tool-call",
237
+ id: t.id,
238
+ name: t.function.name,
239
+ arguments: t.function.arguments,
240
+ state: "input-complete"
241
+ });
242
+ return {
243
+ id: t || generateMessageId(),
244
+ role: e.role === "tool" ? "assistant" : e.role,
245
+ parts: n
246
+ };
247
+ }
248
+ function normalizeToUIMessage(e, t) {
249
+ return "parts" in e ? {
250
+ ...e,
251
+ id: e.id || t(),
252
+ createdAt: e.createdAt || /* @__PURE__ */ new Date()
253
+ } : {
254
+ ...modelMessageToUIMessage(e, t()),
255
+ createdAt: /* @__PURE__ */ new Date()
256
+ };
257
+ }
258
+ function generateMessageId() {
259
+ return `msg-${Date.now()}-${Math.random().toString(36).substring(7)}`;
260
+ }
261
+ //#endregion
262
+ //#region ../../node_modules/.pnpm/@tanstack+ai@0.14.0/node_modules/@tanstack/ai/dist/esm/activities/chat/tools/tool-definition.js
263
+ function toolDefinition(e) {
264
+ return {
265
+ __toolSide: "definition",
266
+ ...e,
267
+ server(t) {
268
+ return {
269
+ __toolSide: "server",
270
+ ...e,
271
+ execute: t
272
+ };
273
+ },
274
+ client(t) {
275
+ return {
276
+ __toolSide: "client",
277
+ ...e,
278
+ execute: t
279
+ };
280
+ }
281
+ };
282
+ }
283
+ //#endregion
284
+ //#region ../../node_modules/.pnpm/partial-json@0.1.7/node_modules/partial-json/dist/options.js
285
+ var f = /* @__PURE__ */ e(((e) => {
286
+ Object.defineProperty(e, "__esModule", { value: !0 }), e.Allow = e.ALL = e.COLLECTION = e.ATOM = e.SPECIAL = e.INF = e._INFINITY = e.INFINITY = e.NAN = e.BOOL = e.NULL = e.OBJ = e.ARR = e.NUM = e.STR = void 0, e.STR = 1, e.NUM = 2, e.ARR = 4, e.OBJ = 8, e.NULL = 16, e.BOOL = 32, e.NAN = 64, e.INFINITY = 128, e._INFINITY = 256, e.INF = e.INFINITY | e._INFINITY, e.SPECIAL = e.NULL | e.BOOL | e.INF | e.NAN, e.ATOM = e.STR | e.NUM | e.SPECIAL, e.COLLECTION = e.ARR | e.OBJ, e.ALL = e.ATOM | e.COLLECTION, e.Allow = {
287
+ STR: e.STR,
288
+ NUM: e.NUM,
289
+ ARR: e.ARR,
290
+ OBJ: e.OBJ,
291
+ NULL: e.NULL,
292
+ BOOL: e.BOOL,
293
+ NAN: e.NAN,
294
+ INFINITY: e.INFINITY,
295
+ _INFINITY: e._INFINITY,
296
+ INF: e.INF,
297
+ SPECIAL: e.SPECIAL,
298
+ ATOM: e.ATOM,
299
+ COLLECTION: e.COLLECTION,
300
+ ALL: e.ALL
301
+ }, e.default = e.Allow;
302
+ })), p = (/* @__PURE__ */ e(((e) => {
303
+ var t = e && e.__createBinding || (Object.create ? (function(e, t, n, r) {
304
+ r === void 0 && (r = n);
305
+ var i = Object.getOwnPropertyDescriptor(t, n);
306
+ (!i || ("get" in i ? !t.__esModule : i.writable || i.configurable)) && (i = {
307
+ enumerable: !0,
308
+ get: function() {
309
+ return t[n];
310
+ }
311
+ }), Object.defineProperty(e, r, i);
312
+ }) : (function(e, t, n, r) {
313
+ r === void 0 && (r = n), e[r] = t[n];
314
+ })), n = e && e.__exportStar || function(e, n) {
315
+ for (var r in e) r !== "default" && !Object.prototype.hasOwnProperty.call(n, r) && t(n, e, r);
316
+ };
317
+ Object.defineProperty(e, "__esModule", { value: !0 }), e.Allow = e.MalformedJSON = e.PartialJSON = e.parseJSON = e.parse = void 0;
318
+ var r = f();
319
+ Object.defineProperty(e, "Allow", {
320
+ enumerable: !0,
321
+ get: function() {
322
+ return r.Allow;
323
+ }
324
+ }), n(f(), e);
325
+ var PartialJSON = class extends Error {};
326
+ e.PartialJSON = PartialJSON;
327
+ var MalformedJSON = class extends Error {};
328
+ e.MalformedJSON = MalformedJSON;
329
+ function parseJSON(e, t = r.Allow.ALL) {
330
+ if (typeof e != "string") throw TypeError(`expecting str, got ${typeof e}`);
331
+ if (!e.trim()) throw Error(`${e} is empty`);
332
+ return _parseJSON(e.trim(), t);
333
+ }
334
+ e.parseJSON = parseJSON;
335
+ var _parseJSON = (e, t) => {
336
+ let n = e.length, i = 0, markPartialJSON = (e) => {
337
+ throw new PartialJSON(`${e} at position ${i}`);
338
+ }, throwMalformedError = (e) => {
339
+ throw new MalformedJSON(`${e} at position ${i}`);
340
+ }, parseAny = () => (skipBlank(), i >= n && markPartialJSON("Unexpected end of input"), e[i] === "\"" ? parseStr() : e[i] === "{" ? parseObj() : e[i] === "[" ? parseArr() : e.substring(i, i + 4) === "null" || r.Allow.NULL & t && n - i < 4 && "null".startsWith(e.substring(i)) ? (i += 4, null) : e.substring(i, i + 4) === "true" || r.Allow.BOOL & t && n - i < 4 && "true".startsWith(e.substring(i)) ? (i += 4, !0) : e.substring(i, i + 5) === "false" || r.Allow.BOOL & t && n - i < 5 && "false".startsWith(e.substring(i)) ? (i += 5, !1) : e.substring(i, i + 8) === "Infinity" || r.Allow.INFINITY & t && n - i < 8 && "Infinity".startsWith(e.substring(i)) ? (i += 8, Infinity) : e.substring(i, i + 9) === "-Infinity" || r.Allow._INFINITY & t && 1 < n - i && n - i < 9 && "-Infinity".startsWith(e.substring(i)) ? (i += 9, -Infinity) : e.substring(i, i + 3) === "NaN" || r.Allow.NAN & t && n - i < 3 && "NaN".startsWith(e.substring(i)) ? (i += 3, NaN) : parseNum()), parseStr = () => {
341
+ let a = i, o = !1;
342
+ for (i++; i < n && (e[i] !== "\"" || o && e[i - 1] === "\\");) o = e[i] === "\\" ? !o : !1, i++;
343
+ if (e.charAt(i) == "\"") try {
344
+ return JSON.parse(e.substring(a, ++i - Number(o)));
345
+ } catch (e) {
346
+ throwMalformedError(String(e));
347
+ }
348
+ else if (r.Allow.STR & t) try {
349
+ return JSON.parse(e.substring(a, i - Number(o)) + "\"");
350
+ } catch {
351
+ return JSON.parse(e.substring(a, e.lastIndexOf("\\")) + "\"");
352
+ }
353
+ markPartialJSON("Unterminated string literal");
354
+ }, parseObj = () => {
355
+ i++, skipBlank();
356
+ let a = {};
357
+ try {
358
+ for (; e[i] !== "}";) {
359
+ if (skipBlank(), i >= n && r.Allow.OBJ & t) return a;
360
+ let o = parseStr();
361
+ skipBlank(), i++;
362
+ try {
363
+ a[o] = parseAny();
364
+ } catch (e) {
365
+ if (r.Allow.OBJ & t) return a;
366
+ throw e;
367
+ }
368
+ skipBlank(), e[i] === "," && i++;
369
+ }
370
+ } catch {
371
+ if (r.Allow.OBJ & t) return a;
372
+ markPartialJSON("Expected '}' at end of object");
373
+ }
374
+ return i++, a;
375
+ }, parseArr = () => {
376
+ i++;
377
+ let n = [];
378
+ try {
379
+ for (; e[i] !== "]";) n.push(parseAny()), skipBlank(), e[i] === "," && i++;
380
+ } catch {
381
+ if (r.Allow.ARR & t) return n;
382
+ markPartialJSON("Expected ']' at end of array");
383
+ }
384
+ return i++, n;
385
+ }, parseNum = () => {
386
+ if (i === 0) {
387
+ e === "-" && throwMalformedError("Not sure what '-' is");
388
+ try {
389
+ return JSON.parse(e);
390
+ } catch (n) {
391
+ if (r.Allow.NUM & t) try {
392
+ return JSON.parse(e.substring(0, e.lastIndexOf("e")));
393
+ } catch {}
394
+ throwMalformedError(String(n));
395
+ }
396
+ }
397
+ let a = i;
398
+ for (e[i] === "-" && i++; e[i] && ",]}".indexOf(e[i]) === -1;) i++;
399
+ i == n && !(r.Allow.NUM & t) && markPartialJSON("Unterminated number literal");
400
+ try {
401
+ return JSON.parse(e.substring(a, i));
402
+ } catch {
403
+ e.substring(a, i) === "-" && markPartialJSON("Not sure what '-' is");
404
+ try {
405
+ return JSON.parse(e.substring(a, e.lastIndexOf("e")));
406
+ } catch (e) {
407
+ throwMalformedError(String(e));
408
+ }
409
+ }
410
+ }, skipBlank = () => {
411
+ for (; i < n && " \n\r ".includes(e[i]);) i++;
412
+ };
413
+ return parseAny();
414
+ };
415
+ e.parse = parseJSON;
416
+ })))(), PartialJSONParser = class {
417
+ parse(e) {
418
+ if (!(!e || e.trim() === "")) try {
419
+ return (0, p.parse)(e);
420
+ } catch {
421
+ return;
422
+ }
423
+ }
424
+ }, m = new PartialJSONParser();
425
+ //#endregion
426
+ //#region ../../node_modules/.pnpm/@tanstack+ai@0.14.0/node_modules/@tanstack/ai/dist/esm/activities/chat/stream/message-updaters.js
427
+ function updateTextPart(e, t, n) {
428
+ return e.map((e) => {
429
+ if (e.id !== t) return e;
430
+ let r = [...e.parts], i = r.length > 0 ? r[r.length - 1] : null;
431
+ return i && i.type === "text" ? r[r.length - 1] = {
432
+ type: "text",
433
+ content: n
434
+ } : r.push({
435
+ type: "text",
436
+ content: n
437
+ }), {
438
+ ...e,
439
+ parts: r
440
+ };
441
+ });
442
+ }
443
+ function updateToolCallPart(e, t, n) {
444
+ return e.map((e) => {
445
+ if (e.id !== t) return e;
446
+ let r = [...e.parts], i = r.find((e) => e.type === "tool-call" && e.id === n.id), a = {
447
+ type: "tool-call",
448
+ id: n.id,
449
+ name: n.name,
450
+ arguments: n.arguments,
451
+ state: n.state,
452
+ ...i?.approval && { approval: { ...i.approval } },
453
+ ...i?.output !== void 0 && { output: i.output }
454
+ };
455
+ return i ? r[r.indexOf(i)] = a : r.push(a), {
456
+ ...e,
457
+ parts: r
458
+ };
459
+ });
460
+ }
461
+ function updateToolResultPart(e, t, n, r, i, a) {
462
+ return e.map((e) => {
463
+ if (e.id !== t) return e;
464
+ let o = [...e.parts], s = o.findIndex((e) => e.type === "tool-result" && e.toolCallId === n), c = {
465
+ type: "tool-result",
466
+ toolCallId: n,
467
+ content: r,
468
+ state: i,
469
+ ...a && { error: a }
470
+ };
471
+ return s >= 0 ? o[s] = c : o.push(c), {
472
+ ...e,
473
+ parts: o
474
+ };
475
+ });
476
+ }
477
+ function updateToolCallApproval(e, t, n, r) {
478
+ return e.map((e) => {
479
+ if (e.id !== t) return e;
480
+ let i = [...e.parts], a = i.find((e) => e.type === "tool-call" && e.id === n);
481
+ return a && (a.state = "approval-requested", a.approval = {
482
+ id: r,
483
+ needsApproval: !0
484
+ }), {
485
+ ...e,
486
+ parts: i
487
+ };
488
+ });
489
+ }
490
+ function updateToolCallWithOutput(e, t, n, r, i) {
491
+ return e.map((e) => {
492
+ let a = [...e.parts], o = a.find((e) => e.type === "tool-call" && e.id === t);
493
+ return o && (o.output = i ? { error: i } : n, r ? o.state = r : o.state = "input-complete"), {
494
+ ...e,
495
+ parts: a
496
+ };
497
+ });
498
+ }
499
+ function updateToolCallApprovalResponse(e, t, n) {
500
+ return e.map((e) => {
501
+ let r = [...e.parts], i = r.find((e) => e.type === "tool-call" && e.approval?.id === t);
502
+ return i && i.approval && (i.approval.approved = n, i.state = "approval-responded"), {
503
+ ...e,
504
+ parts: r
505
+ };
506
+ });
507
+ }
508
+ function updateThinkingPart(e, t, n) {
509
+ return e.map((e) => {
510
+ if (e.id !== t) return e;
511
+ let r = [...e.parts], i = r.findIndex((e) => e.type === "thinking"), a = {
512
+ type: "thinking",
513
+ content: n
514
+ };
515
+ return i >= 0 ? r[i] = a : r.push(a), {
516
+ ...e,
517
+ parts: r
518
+ };
519
+ });
520
+ }
521
+ //#endregion
522
+ //#region ../../node_modules/.pnpm/@tanstack+ai@0.14.0/node_modules/@tanstack/ai/dist/esm/activities/chat/stream/strategies.js
523
+ var ImmediateStrategy = class {
524
+ shouldEmit(e, t) {
525
+ return !0;
526
+ }
527
+ }, h = class StreamProcessor {
528
+ constructor(e = {}) {
529
+ this.messages = [], this.messageStates = /* @__PURE__ */ new Map(), this.activeMessageIds = /* @__PURE__ */ new Set(), this.toolCallToMessage = /* @__PURE__ */ new Map(), this.pendingManualMessageId = null, this.activeRuns = /* @__PURE__ */ new Set(), this.finishReason = null, this.hasError = !1, this.isDone = !1, this.recording = null, this.recordingStartTime = 0, this.chunkStrategy = e.chunkStrategy || new ImmediateStrategy(), this.events = e.events || {}, this.jsonParser = e.jsonParser || m, this.recordingEnabled = e.recording ?? !1, e.initialMessages && (this.messages = [...e.initialMessages]);
530
+ }
531
+ setMessages(e) {
532
+ this.messages = [...e], this.emitMessagesChange();
533
+ }
534
+ addUserMessage(e, t) {
535
+ let n = typeof e == "string" ? [{
536
+ type: "text",
537
+ content: e
538
+ }] : e.map((e) => e), r = {
539
+ id: t ?? generateMessageId(),
540
+ role: "user",
541
+ parts: n,
542
+ createdAt: /* @__PURE__ */ new Date()
543
+ };
544
+ return this.messages = [...this.messages, r], this.emitMessagesChange(), r;
545
+ }
546
+ prepareAssistantMessage() {
547
+ this.resetStreamState();
548
+ }
549
+ startAssistantMessage(e) {
550
+ this.prepareAssistantMessage();
551
+ let { messageId: t } = this.ensureAssistantMessage(e);
552
+ return this.pendingManualMessageId = t, t;
553
+ }
554
+ getCurrentAssistantMessageId() {
555
+ let e = null;
556
+ for (let [t, n] of this.messageStates) n.role === "assistant" && (e = t);
557
+ return e;
558
+ }
559
+ addToolResult(e, t, n) {
560
+ let r = this.messages.find((t) => t.parts.some((t) => t.type === "tool-call" && t.id === e));
561
+ if (!r) {
562
+ console.warn(`[StreamProcessor] Could not find message with tool call ${e}`);
563
+ return;
564
+ }
565
+ let i = updateToolCallWithOutput(this.messages, e, t, n ? "input-complete" : void 0, n), a = typeof t == "string" ? t : JSON.stringify(t), o = n ? "error" : "complete";
566
+ i = updateToolResultPart(i, r.id, e, a, o, n), this.messages = i, this.emitMessagesChange();
567
+ }
568
+ addToolApprovalResponse(e, t) {
569
+ this.messages = updateToolCallApprovalResponse(this.messages, e, t), this.emitMessagesChange();
570
+ }
571
+ toModelMessages() {
572
+ let e = [];
573
+ for (let t of this.messages) e.push(...uiMessageToModelMessages(t));
574
+ return e;
575
+ }
576
+ getMessages() {
577
+ return this.messages;
578
+ }
579
+ areAllToolsComplete() {
580
+ let e = this.messages.findLast((e) => e.role === "assistant");
581
+ if (!e) return !0;
582
+ let t = e.parts.filter((e) => e.type === "tool-call");
583
+ if (t.length === 0) return !0;
584
+ let n = new Set(e.parts.filter((e) => e.type === "tool-result").map((e) => e.toolCallId));
585
+ return t.every((e) => e.state === "approval-responded" || e.output !== void 0 && !e.approval || n.has(e.id));
586
+ }
587
+ removeMessagesAfter(e) {
588
+ this.messages = this.messages.slice(0, e + 1), this.emitMessagesChange();
589
+ }
590
+ clearMessages() {
591
+ this.messages = [], this.messageStates.clear(), this.activeMessageIds.clear(), this.toolCallToMessage.clear(), this.pendingManualMessageId = null, this.emitMessagesChange();
592
+ }
593
+ async process(e) {
594
+ this.resetStreamState(), this.recordingEnabled && this.startRecording();
595
+ for await (let t of e) this.processChunk(t);
596
+ return this.finalizeStream(), this.recording && (this.recording.result = this.getResult()), this.getResult();
597
+ }
598
+ processChunk(e) {
599
+ switch (this.recording && this.recording.chunks.push({
600
+ chunk: e,
601
+ timestamp: Date.now(),
602
+ index: this.recording.chunks.length
603
+ }), e.type) {
604
+ case "TEXT_MESSAGE_START":
605
+ this.handleTextMessageStartEvent(e);
606
+ break;
607
+ case "TEXT_MESSAGE_CONTENT":
608
+ this.handleTextMessageContentEvent(e);
609
+ break;
610
+ case "TEXT_MESSAGE_END":
611
+ this.handleTextMessageEndEvent(e);
612
+ break;
613
+ case "TOOL_CALL_START":
614
+ this.handleToolCallStartEvent(e);
615
+ break;
616
+ case "TOOL_CALL_ARGS":
617
+ this.handleToolCallArgsEvent(e);
618
+ break;
619
+ case "TOOL_CALL_END":
620
+ this.handleToolCallEndEvent(e);
621
+ break;
622
+ case "RUN_FINISHED":
623
+ this.handleRunFinishedEvent(e);
624
+ break;
625
+ case "RUN_ERROR":
626
+ this.handleRunErrorEvent(e);
627
+ break;
628
+ case "STEP_FINISHED":
629
+ this.handleStepFinishedEvent(e);
630
+ break;
631
+ case "MESSAGES_SNAPSHOT":
632
+ this.handleMessagesSnapshotEvent(e);
633
+ break;
634
+ case "CUSTOM":
635
+ this.handleCustomEvent(e);
636
+ break;
637
+ case "RUN_STARTED":
638
+ this.handleRunStartedEvent(e);
639
+ break;
640
+ case "REASONING_START":
641
+ case "REASONING_MESSAGE_START":
642
+ case "REASONING_MESSAGE_END":
643
+ case "REASONING_END": break;
644
+ case "REASONING_MESSAGE_CONTENT":
645
+ this.handleReasoningMessageContentEvent(e);
646
+ break;
647
+ case "TOOL_CALL_RESULT":
648
+ this.handleToolCallResultEvent(e);
649
+ break;
650
+ }
651
+ }
652
+ createMessageState(e, t) {
653
+ let n = {
654
+ id: e,
655
+ role: t,
656
+ totalTextContent: "",
657
+ currentSegmentText: "",
658
+ lastEmittedText: "",
659
+ thinkingContent: "",
660
+ hasSeenReasoningEvents: !1,
661
+ toolCalls: /* @__PURE__ */ new Map(),
662
+ toolCallOrder: [],
663
+ hasToolCallsSinceTextStart: !1,
664
+ isComplete: !1
665
+ };
666
+ return this.messageStates.set(e, n), n;
667
+ }
668
+ getMessageState(e) {
669
+ return this.messageStates.get(e);
670
+ }
671
+ getActiveAssistantMessageId() {
672
+ let e = Array.from(this.activeMessageIds);
673
+ for (let t = e.length - 1; t >= 0; t--) {
674
+ let n = e[t], r = this.messageStates.get(n);
675
+ if (r && r.role === "assistant") return n;
676
+ }
677
+ return null;
678
+ }
679
+ ensureAssistantMessage(e) {
680
+ if (e) {
681
+ let t = this.getMessageState(e);
682
+ if (t) return {
683
+ messageId: e,
684
+ state: t
685
+ };
686
+ }
687
+ let t = this.getActiveAssistantMessageId();
688
+ if (t) return {
689
+ messageId: t,
690
+ state: this.getMessageState(t)
691
+ };
692
+ if (e) {
693
+ let t = this.messages.find((t) => t.id === e);
694
+ if (t) {
695
+ let n = this.createMessageState(e, t.role);
696
+ this.activeMessageIds.add(e);
697
+ let r = t.parts.length > 0 ? t.parts[t.parts.length - 1] : null;
698
+ return r && r.type === "text" && (n.currentSegmentText = r.content, n.lastEmittedText = r.content, n.totalTextContent = r.content), {
699
+ messageId: e,
700
+ state: n
701
+ };
702
+ }
703
+ }
704
+ let n = e || generateMessageId(), r = {
705
+ id: n,
706
+ role: "assistant",
707
+ parts: [],
708
+ createdAt: /* @__PURE__ */ new Date()
709
+ };
710
+ this.messages = [...this.messages, r];
711
+ let i = this.createMessageState(n, "assistant");
712
+ return this.activeMessageIds.add(n), this.pendingManualMessageId = n, this.events.onStreamStart?.(), this.emitMessagesChange(), {
713
+ messageId: n,
714
+ state: i
715
+ };
716
+ }
717
+ handleTextMessageStartEvent(e) {
718
+ let { messageId: t, role: n } = e, r = n === "user" || n === "system" ? n : "assistant";
719
+ if (this.pendingManualMessageId) {
720
+ let e = this.pendingManualMessageId;
721
+ if (this.pendingManualMessageId = null, e !== t) {
722
+ this.messages = this.messages.map((n) => n.id === e ? {
723
+ ...n,
724
+ id: t
725
+ } : n);
726
+ let n = this.messageStates.get(e);
727
+ n && (n.id = t, this.messageStates.delete(e), this.messageStates.set(t, n)), this.activeMessageIds.delete(e), this.activeMessageIds.add(t);
728
+ }
729
+ this.messageStates.has(t) || (this.createMessageState(t, r), this.activeMessageIds.add(t)), this.emitMessagesChange();
730
+ return;
731
+ }
732
+ if (this.messages.find((e) => e.id === t)) {
733
+ if (this.activeMessageIds.add(t), !this.messageStates.has(t)) this.createMessageState(t, r);
734
+ else {
735
+ let e = this.messageStates.get(t);
736
+ e.hasToolCallsSinceTextStart &&= (e.currentSegmentText !== e.lastEmittedText && this.emitTextUpdateForMessage(t), e.currentSegmentText = "", e.lastEmittedText = "", !1);
737
+ }
738
+ return;
739
+ }
740
+ let i = {
741
+ id: t,
742
+ role: r,
743
+ parts: [],
744
+ createdAt: /* @__PURE__ */ new Date()
745
+ };
746
+ this.messages = [...this.messages, i], this.createMessageState(t, r), this.activeMessageIds.add(t), this.events.onStreamStart?.(), this.emitMessagesChange();
747
+ }
748
+ handleTextMessageEndEvent(e) {
749
+ let { messageId: t } = e, n = this.getMessageState(t);
750
+ n && (n.isComplete || (n.currentSegmentText !== n.lastEmittedText && this.emitTextUpdateForMessage(t), this.completeAllToolCallsForMessage(t)));
751
+ }
752
+ handleMessagesSnapshotEvent(e) {
753
+ this.resetStreamState(), this.messages = [...e.messages], this.emitMessagesChange();
754
+ }
755
+ handleTextMessageContentEvent(e) {
756
+ let { messageId: t, state: n } = this.ensureAssistantMessage(e.messageId);
757
+ this.completeAllToolCallsForMessage(t);
758
+ let r = n.currentSegmentText;
759
+ n.hasToolCallsSinceTextStart && r.length > 0 && this.isNewTextSegment(e, r) && (r !== n.lastEmittedText && this.emitTextUpdateForMessage(t), n.currentSegmentText = "", n.lastEmittedText = "", n.hasToolCallsSinceTextStart = !1);
760
+ let i = n.currentSegmentText, a = i, o = e.delta || "";
761
+ o === "" ? e.content !== void 0 && e.content !== "" && (a = e.content.startsWith(i) ? e.content : i.startsWith(e.content) ? i : i + e.content) : a = i + o;
762
+ let s = a.slice(i.length);
763
+ n.currentSegmentText = a, n.totalTextContent += s;
764
+ let c = e.delta || e.content || "";
765
+ this.chunkStrategy.shouldEmit(c, n.currentSegmentText) && n.currentSegmentText !== n.lastEmittedText && this.emitTextUpdateForMessage(t);
766
+ }
767
+ handleToolCallStartEvent(e) {
768
+ let t = e.parentMessageId ?? this.getActiveAssistantMessageId(), { messageId: n, state: r } = this.ensureAssistantMessage(t ?? void 0);
769
+ r.hasToolCallsSinceTextStart = !0;
770
+ let i = e.toolCallId;
771
+ if (!r.toolCalls.get(i)) {
772
+ let t = "awaiting-input", a = e.toolCallName, o = {
773
+ id: e.toolCallId,
774
+ name: a,
775
+ arguments: "",
776
+ state: t,
777
+ parsedArguments: void 0,
778
+ index: e.index ?? r.toolCalls.size
779
+ };
780
+ r.toolCalls.set(i, o), r.toolCallOrder.push(i), this.toolCallToMessage.set(i, n), this.messages = updateToolCallPart(this.messages, n, {
781
+ id: e.toolCallId,
782
+ name: a,
783
+ arguments: "",
784
+ state: t
785
+ }), this.emitMessagesChange(), this.events.onToolCallStateChange?.(n, e.toolCallId, t, "");
786
+ }
787
+ }
788
+ handleToolCallArgsEvent(e) {
789
+ let t = e.toolCallId, n = this.toolCallToMessage.get(t);
790
+ if (!n) return;
791
+ let r = this.getMessageState(n);
792
+ if (!r) return;
793
+ let i = r.toolCalls.get(t);
794
+ if (!i) return;
795
+ let a = i.state === "awaiting-input";
796
+ i.arguments += e.delta || "", a && e.delta && (i.state = "input-streaming"), i.parsedArguments = this.jsonParser.parse(i.arguments), this.messages = updateToolCallPart(this.messages, n, {
797
+ id: i.id,
798
+ name: i.name,
799
+ arguments: i.arguments,
800
+ state: i.state
801
+ }), this.emitMessagesChange(), this.events.onToolCallStateChange?.(n, i.id, i.state, i.arguments);
802
+ }
803
+ handleToolCallEndEvent(e) {
804
+ let t = this.toolCallToMessage.get(e.toolCallId);
805
+ if (!t) return;
806
+ let n = this.getMessageState(t);
807
+ if (!n) return;
808
+ let r = n.toolCalls.get(e.toolCallId);
809
+ if (r && r.state !== "input-complete") {
810
+ e.input !== void 0 && !r.arguments && (r.arguments = JSON.stringify(e.input));
811
+ let i = n.toolCallOrder.indexOf(e.toolCallId);
812
+ this.completeToolCall(t, i, r), e.input !== void 0 && (r.parsedArguments = e.input);
813
+ }
814
+ if (e.result) {
815
+ let n;
816
+ try {
817
+ n = JSON.parse(e.result);
818
+ } catch {
819
+ n = e.result;
820
+ }
821
+ this.messages = updateToolCallWithOutput(this.messages, e.toolCallId, n), this.messages = updateToolResultPart(this.messages, t, e.toolCallId, e.result, "complete"), this.emitMessagesChange();
822
+ }
823
+ }
824
+ handleToolCallResultEvent(e) {
825
+ let t = this.toolCallToMessage.get(e.toolCallId);
826
+ if (!t) return;
827
+ let n;
828
+ try {
829
+ n = JSON.parse(e.content);
830
+ } catch {
831
+ n = e.content;
832
+ }
833
+ this.messages = updateToolCallWithOutput(this.messages, e.toolCallId, n), this.messages = updateToolResultPart(this.messages, t, e.toolCallId, e.content, "complete"), this.emitMessagesChange();
834
+ }
835
+ handleRunStartedEvent(e) {
836
+ this.activeRuns.add(e.runId);
837
+ }
838
+ handleRunFinishedEvent(e) {
839
+ this.finishReason = e.finishReason ?? null, this.activeRuns.delete(e.runId), this.activeRuns.size === 0 && (this.isDone = !0, this.completeAllToolCalls(), this.finalizeStream());
840
+ }
841
+ handleRunErrorEvent(e) {
842
+ this.hasError = !0;
843
+ let t = e.runId;
844
+ t ? this.activeRuns.delete(t) : this.activeRuns.clear(), this.ensureAssistantMessage();
845
+ let n = e.message || e.error?.message || "An error occurred";
846
+ this.events.onError?.(Error(n));
847
+ }
848
+ handleStepFinishedEvent(e) {
849
+ let { messageId: t, state: n } = this.ensureAssistantMessage(this.getActiveAssistantMessageId() ?? void 0);
850
+ if (n.hasSeenReasoningEvents) return;
851
+ let r = n.thinkingContent, i = r;
852
+ e.delta && e.delta !== "" ? i = r + e.delta : e.content && e.content !== "" && (i = e.content.startsWith(r) ? e.content : r.startsWith(e.content) ? r : r + e.content), n.thinkingContent = i, this.messages = updateThinkingPart(this.messages, t, n.thinkingContent), this.emitMessagesChange(), this.events.onThinkingUpdate?.(t, n.thinkingContent);
853
+ }
854
+ handleReasoningMessageContentEvent(e) {
855
+ let { messageId: t, state: n } = this.ensureAssistantMessage(this.getActiveAssistantMessageId() ?? void 0);
856
+ n.hasSeenReasoningEvents = !0;
857
+ let r = e.delta || "";
858
+ n.thinkingContent += r, this.messages = updateThinkingPart(this.messages, t, n.thinkingContent), this.emitMessagesChange(), this.events.onThinkingUpdate?.(t, n.thinkingContent);
859
+ }
860
+ handleCustomEvent(e) {
861
+ let t = this.getActiveAssistantMessageId();
862
+ if (e.name === "tool-input-available" && e.value) {
863
+ let { toolCallId: t, toolName: n, input: r } = e.value;
864
+ this.events.onToolCall?.({
865
+ toolCallId: t,
866
+ toolName: n,
867
+ input: r
868
+ });
869
+ return;
870
+ }
871
+ if (e.name === "approval-requested" && e.value) {
872
+ let { toolCallId: n, toolName: r, input: i, approval: a } = e.value, o = t ?? this.toolCallToMessage.get(n);
873
+ o && (this.messages = updateToolCallApproval(this.messages, o, n, a.id), this.emitMessagesChange()), this.events.onApprovalRequest?.({
874
+ toolCallId: n,
875
+ toolName: r,
876
+ input: i,
877
+ approvalId: a.id
878
+ });
879
+ return;
880
+ }
881
+ if (this.events.onCustomEvent) {
882
+ let t = e.value && typeof e.value == "object" ? e.value.toolCallId : void 0;
883
+ this.events.onCustomEvent(e.name, e.value, { toolCallId: t });
884
+ }
885
+ }
886
+ isNewTextSegment(e, t) {
887
+ return e.content !== void 0 && (e.content.length < t.length || !e.content.startsWith(t) && !t.startsWith(e.content));
888
+ }
889
+ completeAllToolCalls() {
890
+ for (let e of this.activeMessageIds) this.completeAllToolCallsForMessage(e);
891
+ }
892
+ completeAllToolCallsForMessage(e) {
893
+ let t = this.getMessageState(e);
894
+ t && t.toolCalls.forEach((n, r) => {
895
+ if (n.state !== "input-complete") {
896
+ let i = t.toolCallOrder.indexOf(r);
897
+ this.completeToolCall(e, i, n);
898
+ }
899
+ });
900
+ }
901
+ completeToolCall(e, t, n) {
902
+ n.state = "input-complete", n.parsedArguments = this.jsonParser.parse(n.arguments), this.messages = updateToolCallPart(this.messages, e, {
903
+ id: n.id,
904
+ name: n.name,
905
+ arguments: n.arguments,
906
+ state: "input-complete"
907
+ }), this.emitMessagesChange(), this.events.onToolCallStateChange?.(e, n.id, "input-complete", n.arguments);
908
+ }
909
+ emitTextUpdateForMessage(e) {
910
+ let t = this.getMessageState(e);
911
+ t && (t.lastEmittedText = t.currentSegmentText, this.messages = updateTextPart(this.messages, e, t.currentSegmentText), this.emitMessagesChange(), this.events.onTextUpdate?.(e, t.currentSegmentText));
912
+ }
913
+ emitMessagesChange() {
914
+ this.events.onMessagesChange?.([...this.messages]);
915
+ }
916
+ finalizeStream() {
917
+ let e;
918
+ for (let t of this.activeMessageIds) {
919
+ let n = this.getMessageState(t);
920
+ if (!n) continue;
921
+ this.completeAllToolCallsForMessage(t), n.currentSegmentText !== n.lastEmittedText && this.emitTextUpdateForMessage(t), n.isComplete = !0;
922
+ let r = this.messages.find((e) => e.id === t);
923
+ r && r.role === "assistant" && (e = r);
924
+ }
925
+ if (this.activeMessageIds.clear(), e && !this.hasError && this.isWhitespaceOnlyMessage(e)) {
926
+ this.messages = this.messages.filter((t) => t.id !== e.id), this.emitMessagesChange();
927
+ return;
928
+ }
929
+ e && this.events.onStreamEnd?.(e);
930
+ }
931
+ getCompletedToolCalls() {
932
+ let e = [];
933
+ for (let t of this.messageStates.values()) for (let n of t.toolCalls.values()) n.state === "input-complete" && e.push({
934
+ id: n.id,
935
+ type: "function",
936
+ function: {
937
+ name: n.name,
938
+ arguments: n.arguments
939
+ }
940
+ });
941
+ return e;
942
+ }
943
+ getResult() {
944
+ let e = this.getCompletedToolCalls(), t = "", n = "";
945
+ for (let e of this.messageStates.values()) t += e.totalTextContent, n += e.thinkingContent;
946
+ return {
947
+ content: t,
948
+ thinking: n || void 0,
949
+ toolCalls: e.length > 0 ? e : void 0,
950
+ finishReason: this.finishReason
951
+ };
952
+ }
953
+ getState() {
954
+ let e = "", t = "", n = /* @__PURE__ */ new Map(), r = [];
955
+ for (let i of this.messageStates.values()) {
956
+ e += i.totalTextContent, t += i.thinkingContent;
957
+ for (let [e, t] of i.toolCalls) n.set(e, t);
958
+ r.push(...i.toolCallOrder);
959
+ }
960
+ return {
961
+ content: e,
962
+ thinking: t,
963
+ toolCalls: n,
964
+ toolCallOrder: r,
965
+ finishReason: this.finishReason,
966
+ done: this.isDone
967
+ };
968
+ }
969
+ startRecording() {
970
+ this.recordingEnabled = !0, this.recordingStartTime = Date.now(), this.recording = {
971
+ version: "1.0",
972
+ timestamp: this.recordingStartTime,
973
+ chunks: []
974
+ };
975
+ }
976
+ getRecording() {
977
+ return this.recording;
978
+ }
979
+ resetStreamState() {
980
+ this.messageStates.clear(), this.activeMessageIds.clear(), this.activeRuns.clear(), this.toolCallToMessage.clear(), this.pendingManualMessageId = null, this.finishReason = null, this.hasError = !1, this.isDone = !1, this.chunkStrategy.reset?.();
981
+ }
982
+ reset() {
983
+ this.resetStreamState(), this.messages = [];
984
+ }
985
+ isWhitespaceOnlyMessage(e) {
986
+ return e.parts.length === 0 ? !1 : e.parts.every((e) => e.type === "text" && e.content.trim() === "");
987
+ }
988
+ static async replay(e, t) {
989
+ return new StreamProcessor(t).process(createReplayStream(e));
990
+ }
991
+ };
992
+ function createReplayStream(e) {
993
+ return { async *[Symbol.asyncIterator]() {
994
+ for (let { chunk: t } of e.chunks) yield t;
995
+ } };
996
+ }
997
+ //#endregion
998
+ //#region ../../node_modules/.pnpm/@tanstack+ai-client@0.8.0/node_modules/@tanstack/ai-client/dist/esm/events.js
999
+ var ChatClientEventEmitter = class {
1000
+ constructor(e) {
1001
+ this.clientId = e;
1002
+ }
1003
+ clientCreated(e) {
1004
+ this.emitEvent("client:created", { initialMessageCount: e });
1005
+ }
1006
+ loadingChanged(e) {
1007
+ this.emitEvent("client:loading:changed", { isLoading: e });
1008
+ }
1009
+ errorChanged(e) {
1010
+ this.emitEvent("client:error:changed", { error: e });
1011
+ }
1012
+ textUpdated(e, t, n) {
1013
+ this.emitEvent("text:chunk:content", {
1014
+ streamId: e,
1015
+ messageId: t,
1016
+ content: n
1017
+ });
1018
+ }
1019
+ toolCallStateChanged(e, t, n, r, i, a) {
1020
+ this.emitEvent("tools:call:updated", {
1021
+ streamId: e,
1022
+ messageId: t,
1023
+ toolCallId: n,
1024
+ toolName: r,
1025
+ state: i,
1026
+ arguments: a
1027
+ });
1028
+ }
1029
+ thinkingUpdated(e, t, n, r) {
1030
+ this.emitEvent("text:chunk:thinking", {
1031
+ streamId: e,
1032
+ messageId: t,
1033
+ content: n,
1034
+ delta: r
1035
+ });
1036
+ }
1037
+ approvalRequested(e, t, n, r, i, a) {
1038
+ this.emitEvent("tools:approval:requested", {
1039
+ streamId: e,
1040
+ messageId: t,
1041
+ toolCallId: n,
1042
+ toolName: r,
1043
+ input: i,
1044
+ approvalId: a
1045
+ });
1046
+ }
1047
+ messageAppended(e, t) {
1048
+ let n = e.parts.filter((e) => e.type === "text").map((e) => e.content).join(" ");
1049
+ this.emitEvent("text:message:created", {
1050
+ streamId: t,
1051
+ messageId: e.id,
1052
+ role: e.role,
1053
+ content: n,
1054
+ parts: e.parts
1055
+ });
1056
+ }
1057
+ messageSent(e, t) {
1058
+ let n = typeof t == "string" ? t : t.filter((e) => e.type === "text").map((e) => e.content).join("");
1059
+ this.emitEvent("text:message:created", {
1060
+ messageId: e,
1061
+ role: "user",
1062
+ content: n,
1063
+ ...Array.isArray(t) && { parts: t }
1064
+ }), this.emitEvent("text:message:user", {
1065
+ messageId: e,
1066
+ role: "user",
1067
+ content: n,
1068
+ ...Array.isArray(t) && { parts: t }
1069
+ });
1070
+ }
1071
+ reloaded(e) {
1072
+ this.emitEvent("client:reloaded", { fromMessageIndex: e });
1073
+ }
1074
+ stopped() {
1075
+ this.emitEvent("client:stopped");
1076
+ }
1077
+ messagesCleared() {
1078
+ this.emitEvent("client:messages:cleared");
1079
+ }
1080
+ toolResultAdded(e, t, n, r) {
1081
+ this.emitEvent("tools:result:added", {
1082
+ toolCallId: e,
1083
+ toolName: t,
1084
+ output: n,
1085
+ state: r
1086
+ });
1087
+ }
1088
+ toolApprovalResponded(e, t, n) {
1089
+ this.emitEvent("tools:approval:responded", {
1090
+ approvalId: e,
1091
+ toolCallId: t,
1092
+ approved: n
1093
+ });
1094
+ }
1095
+ }, DefaultChatClientEventEmitter = class extends ChatClientEventEmitter {
1096
+ emitEvent(e, t) {
1097
+ e.startsWith("client:") || e.startsWith("tools:") || e.startsWith("text:") ? d.emit(e, {
1098
+ ...t,
1099
+ clientId: this.clientId,
1100
+ source: "client",
1101
+ timestamp: Date.now()
1102
+ }) : d.emit(e, {
1103
+ ...t,
1104
+ timestamp: Date.now()
1105
+ });
1106
+ }
1107
+ };
1108
+ //#endregion
1109
+ //#region ../../node_modules/.pnpm/@tanstack+ai-client@0.8.0/node_modules/@tanstack/ai-client/dist/esm/connection-adapters.js
1110
+ function mergeHeaders(e) {
1111
+ if (!e) return {};
1112
+ if (e instanceof Headers) {
1113
+ let t = {};
1114
+ return e.forEach((e, n) => {
1115
+ t[n] = e;
1116
+ }), t;
1117
+ }
1118
+ return e;
1119
+ }
1120
+ async function* readStreamLines(e, t) {
1121
+ try {
1122
+ let n = new TextDecoder(), r = "";
1123
+ for (; !t?.aborted;) {
1124
+ let { done: t, value: i } = await e.read();
1125
+ if (t) break;
1126
+ r += n.decode(i, { stream: !0 });
1127
+ let a = r.split("\n");
1128
+ r = a.pop() || "";
1129
+ for (let e of a) e.trim() && (yield e);
1130
+ }
1131
+ r.trim() && (yield r);
1132
+ } finally {
1133
+ e.releaseLock();
1134
+ }
1135
+ }
1136
+ function normalizeConnectionAdapter(e) {
1137
+ if (!e) throw Error("Connection adapter is required");
1138
+ let t = "connect" in e, n = "subscribe" in e, r = "send" in e;
1139
+ if (t && (n || r)) throw Error("Connection adapter must provide either connect or both subscribe and send, not both modes");
1140
+ if (n && r) return {
1141
+ subscribe: e.subscribe.bind(e),
1142
+ send: e.send.bind(e)
1143
+ };
1144
+ if (!t) throw Error("Connection adapter must provide either connect or both subscribe and send");
1145
+ let i = [], a = [];
1146
+ function push(e) {
1147
+ let t = a.shift();
1148
+ t ? t(e) : i.push(e);
1149
+ }
1150
+ return {
1151
+ subscribe(e) {
1152
+ let t = i.splice(0), n = [];
1153
+ return i = t, a = n, (async function* () {
1154
+ for (; !e?.aborted;) {
1155
+ let r;
1156
+ r = t.length > 0 ? t.shift() : await new Promise((t) => {
1157
+ let onAbort = () => t(null);
1158
+ n.push((n) => {
1159
+ e?.removeEventListener("abort", onAbort), t(n);
1160
+ }), e?.addEventListener("abort", onAbort, { once: !0 });
1161
+ }), r !== null && (yield r);
1162
+ }
1163
+ })();
1164
+ },
1165
+ async send(t, n, r) {
1166
+ let i = !1;
1167
+ try {
1168
+ let a = e.connect(t, n, r);
1169
+ for await (let e of a) (e.type === "RUN_FINISHED" || e.type === "RUN_ERROR") && (i = !0), push(e);
1170
+ !r?.aborted && !i && push({
1171
+ type: "RUN_FINISHED",
1172
+ runId: `run-${Date.now()}`,
1173
+ model: "connect-wrapper",
1174
+ timestamp: Date.now(),
1175
+ finishReason: "stop"
1176
+ });
1177
+ } catch (e) {
1178
+ throw !r?.aborted && !i && push({
1179
+ type: "RUN_ERROR",
1180
+ timestamp: Date.now(),
1181
+ message: e instanceof Error ? e.message : "Unknown error in connect()",
1182
+ error: { message: e instanceof Error ? e.message : "Unknown error in connect()" }
1183
+ }), e;
1184
+ }
1185
+ }
1186
+ };
1187
+ }
1188
+ function fetchServerSentEvents(e, t = {}) {
1189
+ return { async *connect(n, r, i) {
1190
+ let a = typeof e == "function" ? e() : e, o = typeof t == "function" ? await t() : t, s = {
1191
+ "Content-Type": "application/json",
1192
+ ...mergeHeaders(o.headers)
1193
+ }, c = {
1194
+ messages: n,
1195
+ data: r,
1196
+ ...o.body
1197
+ }, l = await (o.fetchClient ?? fetch)(a, {
1198
+ method: "POST",
1199
+ headers: s,
1200
+ body: JSON.stringify(c),
1201
+ credentials: o.credentials || "same-origin",
1202
+ signal: i || o.signal
1203
+ });
1204
+ if (!l.ok) throw Error(`HTTP error! status: ${l.status} ${l.statusText}`);
1205
+ let u = l.body?.getReader();
1206
+ if (!u) throw Error("Response body is not readable");
1207
+ for await (let e of readStreamLines(u, i)) {
1208
+ let t = e.startsWith("data: ") ? e.slice(6) : e;
1209
+ if (t === "[DONE]") {
1210
+ console.warn("[@tanstack/ai-client] Received [DONE] sentinel. This is deprecated — upgrade your @tanstack/ai server package. RUN_FINISHED is the stream terminator.");
1211
+ continue;
1212
+ }
1213
+ try {
1214
+ yield JSON.parse(t);
1215
+ } catch {
1216
+ console.warn("Failed to parse SSE chunk:", t);
1217
+ }
1218
+ }
1219
+ } };
1220
+ }
1221
+ //#endregion
1222
+ //#region ../../node_modules/.pnpm/@tanstack+ai-client@0.8.0/node_modules/@tanstack/ai-client/dist/esm/chat-client.js
1223
+ var ChatClient = class {
1224
+ constructor(e) {
1225
+ if (this.body = {}, this.pendingMessageBody = void 0, this.isLoading = !1, this.isSubscribed = !1, this.error = void 0, this.status = "ready", this.connectionStatus = "disconnected", this.abortController = null, this.currentStreamId = null, this.currentMessageId = null, this.postStreamActions = [], this.pendingToolExecutions = /* @__PURE__ */ new Map(), this.continuationPending = !1, this.subscriptionAbortController = null, this.processingResolve = null, this.errorReportedGeneration = null, this.streamGeneration = 0, this.continuationSkipped = !1, this.draining = !1, this.sessionGenerating = !1, this.activeRunIds = /* @__PURE__ */ new Set(), this.uniqueId = e.id || this.generateUniqueId("chat"), this.body = e.body || {}, this.connection = normalizeConnectionAdapter(e.connection), this.events = new DefaultChatClientEventEmitter(this.uniqueId), this.clientToolsRef = { current: /* @__PURE__ */ new Map() }, e.tools) for (let t of e.tools) this.clientToolsRef.current.set(t.name, t);
1226
+ this.callbacksRef = { current: {
1227
+ onResponse: e.onResponse || (() => {}),
1228
+ onChunk: e.onChunk || (() => {}),
1229
+ onFinish: e.onFinish || (() => {}),
1230
+ onError: e.onError || (() => {}),
1231
+ onMessagesChange: e.onMessagesChange || (() => {}),
1232
+ onLoadingChange: e.onLoadingChange || (() => {}),
1233
+ onErrorChange: e.onErrorChange || (() => {}),
1234
+ onStatusChange: e.onStatusChange || (() => {}),
1235
+ onSubscriptionChange: e.onSubscriptionChange || (() => {}),
1236
+ onConnectionStatusChange: e.onConnectionStatusChange || (() => {}),
1237
+ onSessionGeneratingChange: e.onSessionGeneratingChange || (() => {}),
1238
+ onCustomEvent: e.onCustomEvent || (() => {})
1239
+ } }, this.processor = new h({
1240
+ chunkStrategy: e.streamProcessor?.chunkStrategy,
1241
+ initialMessages: e.initialMessages,
1242
+ events: {
1243
+ onMessagesChange: (e) => {
1244
+ this.callbacksRef.current.onMessagesChange(e);
1245
+ },
1246
+ onStreamStart: () => {
1247
+ this.setStatus("streaming");
1248
+ let e = this.processor.getCurrentAssistantMessageId();
1249
+ if (!e) return;
1250
+ let t = this.processor.getMessages().find((t) => t.id === e);
1251
+ t && (this.currentMessageId = t.id, this.events.messageAppended(t, this.currentStreamId || void 0));
1252
+ },
1253
+ onStreamEnd: (e) => {
1254
+ this.callbacksRef.current.onFinish(e), this.setStatus("ready"), this.resolveProcessing();
1255
+ },
1256
+ onError: (e) => {
1257
+ this.reportStreamError(e);
1258
+ },
1259
+ onTextUpdate: (e, t) => {
1260
+ this.currentStreamId && this.events.textUpdated(this.currentStreamId, e, t);
1261
+ },
1262
+ onThinkingUpdate: (e, t) => {
1263
+ this.currentStreamId && this.events.thinkingUpdated(this.currentStreamId, e, t);
1264
+ },
1265
+ onToolCallStateChange: (e, t, n, r) => {
1266
+ let i = this.processor.getMessages().find((t) => t.id === e)?.parts.find((e) => e.type === "tool-call" && e.id === t)?.name || "unknown";
1267
+ this.currentStreamId && this.events.toolCallStateChanged(this.currentStreamId, e, t, i, n, r);
1268
+ },
1269
+ onToolCall: (e) => {
1270
+ let t = this.clientToolsRef.current.get(e.toolName)?.execute;
1271
+ if (t) {
1272
+ let n = (async () => {
1273
+ try {
1274
+ let n = await t(e.input);
1275
+ await this.addToolResult({
1276
+ toolCallId: e.toolCallId,
1277
+ tool: e.toolName,
1278
+ output: n,
1279
+ state: "output-available"
1280
+ });
1281
+ } catch (t) {
1282
+ await this.addToolResult({
1283
+ toolCallId: e.toolCallId,
1284
+ tool: e.toolName,
1285
+ output: null,
1286
+ state: "output-error",
1287
+ errorText: t.message
1288
+ });
1289
+ } finally {
1290
+ this.pendingToolExecutions.delete(e.toolCallId);
1291
+ }
1292
+ })();
1293
+ this.pendingToolExecutions.set(e.toolCallId, n);
1294
+ }
1295
+ },
1296
+ onApprovalRequest: (e) => {
1297
+ this.currentStreamId && this.events.approvalRequested(this.currentStreamId, this.currentMessageId || "", e.toolCallId, e.toolName, e.input, e.approvalId);
1298
+ },
1299
+ onCustomEvent: (e, t, n) => {
1300
+ this.callbacksRef.current.onCustomEvent(e, t, n);
1301
+ }
1302
+ }
1303
+ }), this.events.clientCreated(this.processor.getMessages().length);
1304
+ }
1305
+ generateUniqueId(e) {
1306
+ return `${e}-${Date.now()}-${Math.random().toString(36).substring(7)}`;
1307
+ }
1308
+ setIsLoading(e) {
1309
+ this.isLoading = e, this.callbacksRef.current.onLoadingChange(e), this.events.loadingChanged(e);
1310
+ }
1311
+ setStatus(e) {
1312
+ this.status = e, this.callbacksRef.current.onStatusChange(e);
1313
+ }
1314
+ setIsSubscribed(e) {
1315
+ this.isSubscribed = e, this.callbacksRef.current.onSubscriptionChange(e);
1316
+ }
1317
+ setConnectionStatus(e) {
1318
+ this.connectionStatus = e, this.callbacksRef.current.onConnectionStatusChange(e);
1319
+ }
1320
+ setSessionGenerating(e) {
1321
+ this.sessionGenerating !== e && (this.sessionGenerating = e, this.callbacksRef.current.onSessionGeneratingChange(e));
1322
+ }
1323
+ resetSessionGenerating() {
1324
+ this.activeRunIds.clear(), this.setSessionGenerating(!1);
1325
+ }
1326
+ setError(e) {
1327
+ this.error = e, this.callbacksRef.current.onErrorChange(e), this.events.errorChanged(e?.message || null);
1328
+ }
1329
+ abortSubscriptionLoop() {
1330
+ this.subscriptionAbortController?.abort(), this.subscriptionAbortController = null;
1331
+ }
1332
+ resolveProcessing() {
1333
+ this.processingResolve?.(), this.processingResolve = null;
1334
+ }
1335
+ cancelInFlightStream(e) {
1336
+ this.abortController?.abort(), this.abortController = null, e?.abortSubscription && this.abortSubscriptionLoop(), this.resolveProcessing(), this.setIsLoading(!1), e?.setReadyStatus && this.setStatus("ready");
1337
+ }
1338
+ reportStreamError(e) {
1339
+ let t = this.errorReportedGeneration === this.streamGeneration;
1340
+ this.setError(e), (this.isLoading || this.status === "submitted" || this.status === "streaming") && this.setStatus("error"), t || (this.errorReportedGeneration = this.streamGeneration, this.callbacksRef.current.onError(e));
1341
+ }
1342
+ startSubscription() {
1343
+ this.subscriptionAbortController = new AbortController();
1344
+ let e = this.subscriptionAbortController.signal;
1345
+ this.consumeSubscription(e).catch((e) => {
1346
+ e instanceof Error && e.name !== "AbortError" && (this.setConnectionStatus("error"), this.resetSessionGenerating(), this.setIsSubscribed(!1), this.reportStreamError(e)), this.resolveProcessing();
1347
+ }).finally(() => {
1348
+ this.subscriptionAbortController?.signal === e && (this.subscriptionAbortController = null, !e.aborted && this.isSubscribed && (this.setIsSubscribed(!1), this.connectionStatus !== "error" && this.setConnectionStatus("disconnected")));
1349
+ });
1350
+ }
1351
+ async consumeSubscription(e) {
1352
+ let t = this.connection.subscribe(e);
1353
+ for await (let n of t) {
1354
+ if (e.aborted) break;
1355
+ if (this.connectionStatus === "connecting" && this.setConnectionStatus("connected"), this.callbacksRef.current.onChunk(n), this.processor.processChunk(n), n.type === "RUN_STARTED" && (this.activeRunIds.add(n.runId), this.setSessionGenerating(!0)), n.type === "RUN_FINISHED" || n.type === "RUN_ERROR") {
1356
+ let e = n.type === "RUN_FINISHED" ? n.runId : void 0;
1357
+ e ? this.activeRunIds.delete(e) : n.type === "RUN_ERROR" && this.activeRunIds.clear(), this.setSessionGenerating(this.activeRunIds.size > 0), this.resolveProcessing();
1358
+ }
1359
+ await new Promise((e) => setTimeout(e, 0));
1360
+ }
1361
+ }
1362
+ ensureSubscription() {
1363
+ if (!this.isSubscribed) {
1364
+ this.subscribe();
1365
+ return;
1366
+ }
1367
+ (!this.subscriptionAbortController || this.subscriptionAbortController.signal.aborted) && this.subscribe({ restart: !0 });
1368
+ }
1369
+ waitForProcessing() {
1370
+ return this.resolveProcessing(), new Promise((e) => {
1371
+ this.processingResolve = e;
1372
+ });
1373
+ }
1374
+ async sendMessage(e, t) {
1375
+ if (typeof e == "string" && !e.trim() || this.isLoading) return;
1376
+ let n = this.normalizeMessageInput(e);
1377
+ this.pendingMessageBody = t;
1378
+ let r = this.processor.addUserMessage(n.content, n.id);
1379
+ this.events.messageSent(r.id, n.content), await this.streamResponse();
1380
+ }
1381
+ normalizeMessageInput(e) {
1382
+ return typeof e == "string" ? { content: e.trim() } : {
1383
+ content: e.content,
1384
+ id: e.id
1385
+ };
1386
+ }
1387
+ async append(e) {
1388
+ let t = normalizeToUIMessage(e, generateMessageId);
1389
+ if (t.role === "system") return;
1390
+ let n = t;
1391
+ this.events.messageAppended(n);
1392
+ let r = this.processor.getMessages();
1393
+ if (this.processor.setMessages([...r, n]), this.isLoading) {
1394
+ this.queuePostStreamAction(async () => {
1395
+ await this.streamResponse();
1396
+ });
1397
+ return;
1398
+ }
1399
+ await this.streamResponse();
1400
+ }
1401
+ async streamResponse() {
1402
+ if (this.isLoading) return !1;
1403
+ let e = ++this.streamGeneration;
1404
+ this.setIsLoading(!0), this.setStatus("submitted"), this.setError(void 0), this.errorReportedGeneration = null, this.abortController = new AbortController(), this.pendingToolExecutions.clear();
1405
+ let t = !1;
1406
+ try {
1407
+ let n = this.processor.getMessages();
1408
+ await this.callbacksRef.current.onResponse();
1409
+ let r = {
1410
+ ...this.body,
1411
+ ...this.pendingMessageBody,
1412
+ conversationId: this.uniqueId
1413
+ };
1414
+ this.pendingMessageBody = void 0, this.currentStreamId = this.generateUniqueId("stream"), this.currentMessageId = null, this.processor.prepareAssistantMessage(), this.ensureSubscription();
1415
+ let i = this.waitForProcessing();
1416
+ if (await this.connection.send(n, r, this.abortController.signal), await i, e !== this.streamGeneration || this.status === "error") return !1;
1417
+ this.pendingToolExecutions.size > 0 && await Promise.all(this.pendingToolExecutions.values()), this.processor.finalizeStream(), t = !0;
1418
+ } catch (t) {
1419
+ if (t instanceof Error) {
1420
+ if (t.name === "AbortError") return !1;
1421
+ e === this.streamGeneration && this.reportStreamError(t);
1422
+ }
1423
+ } finally {
1424
+ if (e === this.streamGeneration && (this.currentStreamId = null, this.currentMessageId = null, this.abortController = null, this.setIsLoading(!1), this.pendingMessageBody = void 0, await this.drainPostStreamActions(), t)) {
1425
+ let e = this.processor.getMessages().at(-1)?.parts.at(-1), { finishReason: t } = this.processor.getState();
1426
+ if (e?.type === "tool-result" && t !== "stop" && this.shouldAutoSend()) try {
1427
+ await this.checkForContinuation();
1428
+ } catch (e) {
1429
+ console.error("Failed to continue flow after tool result:", e);
1430
+ }
1431
+ }
1432
+ }
1433
+ return t;
1434
+ }
1435
+ subscribe(e) {
1436
+ let t = e?.restart === !0;
1437
+ this.isSubscribed && !t || (this.isSubscribed && t && this.abortSubscriptionLoop(), this.setIsSubscribed(!0), this.setConnectionStatus("connecting"), this.startSubscription());
1438
+ }
1439
+ unsubscribe() {
1440
+ this.cancelInFlightStream({
1441
+ setReadyStatus: !0,
1442
+ abortSubscription: !0
1443
+ }), this.resetSessionGenerating(), this.setIsSubscribed(!1), this.setConnectionStatus("disconnected");
1444
+ }
1445
+ async reload() {
1446
+ let e = this.processor.getMessages();
1447
+ if (e.length === 0) return;
1448
+ let t = e.findLastIndex((e) => e.role === "user");
1449
+ t !== -1 && (this.isLoading && this.cancelInFlightStream(), this.events.reloaded(t), this.processor.removeMessagesAfter(t), await this.streamResponse());
1450
+ }
1451
+ stop() {
1452
+ this.cancelInFlightStream({ setReadyStatus: !0 }), this.events.stopped();
1453
+ }
1454
+ clear() {
1455
+ this.processor.clearMessages(), this.setError(void 0), this.events.messagesCleared();
1456
+ }
1457
+ async addToolResult(e) {
1458
+ if (this.events.toolResultAdded(e.toolCallId, e.tool, e.output, e.state || "output-available"), this.processor.addToolResult(e.toolCallId, e.output, e.errorText), this.isLoading) {
1459
+ this.queuePostStreamAction(() => this.checkForContinuation());
1460
+ return;
1461
+ }
1462
+ await this.checkForContinuation();
1463
+ }
1464
+ async addToolApprovalResponse(e) {
1465
+ let t = this.processor.getMessages(), n;
1466
+ for (let r of t) {
1467
+ let t = r.parts.find((t) => t.type === "tool-call" && t.approval?.id === e.id);
1468
+ if (t) {
1469
+ n = t.id;
1470
+ break;
1471
+ }
1472
+ }
1473
+ if (n && this.events.toolApprovalResponded(e.id, n, e.approved), this.processor.addToolApprovalResponse(e.id, e.approved), this.isLoading) {
1474
+ this.queuePostStreamAction(() => this.checkForContinuation());
1475
+ return;
1476
+ }
1477
+ await this.checkForContinuation();
1478
+ }
1479
+ queuePostStreamAction(e) {
1480
+ this.postStreamActions.push(e);
1481
+ }
1482
+ async drainPostStreamActions() {
1483
+ if (!this.draining) {
1484
+ this.draining = !0;
1485
+ try {
1486
+ for (; this.postStreamActions.length > 0;) await this.postStreamActions.shift()();
1487
+ } finally {
1488
+ this.draining = !1;
1489
+ }
1490
+ }
1491
+ }
1492
+ async checkForContinuation() {
1493
+ if (this.continuationPending || this.isLoading) {
1494
+ this.continuationSkipped = !0;
1495
+ return;
1496
+ }
1497
+ if (this.shouldAutoSend()) {
1498
+ this.continuationPending = !0, this.continuationSkipped = !1;
1499
+ let e = !1;
1500
+ try {
1501
+ e = await this.streamResponse();
1502
+ } finally {
1503
+ this.continuationPending = !1;
1504
+ }
1505
+ this.continuationSkipped && e && (this.continuationSkipped = !1, await this.checkForContinuation());
1506
+ }
1507
+ }
1508
+ shouldAutoSend() {
1509
+ let e = this.processor.getMessages().findLast((e) => e.role === "assistant");
1510
+ return !e || !e.parts.some((e) => e.type === "tool-call") ? !1 : this.processor.areAllToolsComplete();
1511
+ }
1512
+ getMessages() {
1513
+ return this.processor.getMessages();
1514
+ }
1515
+ getIsLoading() {
1516
+ return this.isLoading;
1517
+ }
1518
+ getStatus() {
1519
+ return this.status;
1520
+ }
1521
+ getIsSubscribed() {
1522
+ return this.isSubscribed;
1523
+ }
1524
+ getConnectionStatus() {
1525
+ return this.connectionStatus;
1526
+ }
1527
+ getSessionGenerating() {
1528
+ return this.sessionGenerating;
1529
+ }
1530
+ getError() {
1531
+ return this.error;
1532
+ }
1533
+ setMessagesManually(e) {
1534
+ this.processor.setMessages(e);
1535
+ }
1536
+ updateOptions(e) {
1537
+ if (e.connection !== void 0) {
1538
+ let t = this.isSubscribed;
1539
+ this.isLoading ? this.cancelInFlightStream({
1540
+ setReadyStatus: !0,
1541
+ abortSubscription: !0
1542
+ }) : t && this.abortSubscriptionLoop(), this.resetSessionGenerating(), this.setIsSubscribed(!1), this.setConnectionStatus("disconnected"), this.connection = normalizeConnectionAdapter(e.connection), t && this.subscribe();
1543
+ }
1544
+ if (e.body !== void 0 && (this.body = e.body), e.tools !== void 0) {
1545
+ this.clientToolsRef.current = /* @__PURE__ */ new Map();
1546
+ for (let t of e.tools) this.clientToolsRef.current.set(t.name, t);
1547
+ }
1548
+ e.onResponse !== void 0 && (this.callbacksRef.current.onResponse = e.onResponse), e.onChunk !== void 0 && (this.callbacksRef.current.onChunk = e.onChunk), e.onFinish !== void 0 && (this.callbacksRef.current.onFinish = e.onFinish), e.onError !== void 0 && (this.callbacksRef.current.onError = e.onError), e.onSubscriptionChange !== void 0 && (this.callbacksRef.current.onSubscriptionChange = e.onSubscriptionChange), e.onConnectionStatusChange !== void 0 && (this.callbacksRef.current.onConnectionStatusChange = e.onConnectionStatusChange), e.onSessionGeneratingChange !== void 0 && (this.callbacksRef.current.onSessionGeneratingChange = e.onSessionGeneratingChange), e.onCustomEvent !== void 0 && (this.callbacksRef.current.onCustomEvent = e.onCustomEvent);
1549
+ }
1550
+ };
1551
+ //#endregion
1552
+ //#region ../../node_modules/.pnpm/@tanstack+ai-client@0.8.0/node_modules/@tanstack/ai-client/dist/esm/types.js
1553
+ function clientTools(...e) {
1554
+ return e;
1555
+ }
1556
+ //#endregion
1557
+ //#region ../../node_modules/.pnpm/@tanstack+ai-react@0.8.0_@tanstack+ai@0.14.0_@types+react@19.2.16_react@19.2.7/node_modules/@tanstack/ai-react/dist/esm/use-chat.js
1558
+ function useChat(e) {
1559
+ let t = i(), c = e.id || t, [l, u] = s(e.initialMessages || []), [d, f] = s(!1), [p, m] = s(void 0), [h, g] = s("ready"), [_, v] = s(!1), [y, b] = s("disconnected"), [x, S] = s(!1), C = o(e.initialMessages || []), w = o(!0);
1560
+ C.current = l;
1561
+ let T = o(e);
1562
+ T.current = e;
1563
+ let E = a(() => {
1564
+ let t = w.current ? e.initialMessages || [] : C.current;
1565
+ return w.current = !1, new ChatClient({
1566
+ connection: T.current.connection,
1567
+ id: c,
1568
+ initialMessages: t,
1569
+ body: T.current.body,
1570
+ onResponse: (e) => T.current.onResponse?.(e),
1571
+ onChunk: (e) => T.current.onChunk?.(e),
1572
+ onFinish: (e) => {
1573
+ T.current.onFinish?.(e);
1574
+ },
1575
+ onError: (e) => {
1576
+ T.current.onError?.(e);
1577
+ },
1578
+ tools: T.current.tools,
1579
+ onCustomEvent: (e, t, n) => T.current.onCustomEvent?.(e, t, n),
1580
+ streamProcessor: e.streamProcessor,
1581
+ onMessagesChange: (e) => {
1582
+ u(e);
1583
+ },
1584
+ onLoadingChange: (e) => {
1585
+ f(e);
1586
+ },
1587
+ onErrorChange: (e) => {
1588
+ m(e);
1589
+ },
1590
+ onStatusChange: (e) => {
1591
+ g(e);
1592
+ },
1593
+ onSubscriptionChange: (e) => {
1594
+ v(e);
1595
+ },
1596
+ onConnectionStatusChange: (e) => {
1597
+ b(e);
1598
+ },
1599
+ onSessionGeneratingChange: (e) => {
1600
+ S(e);
1601
+ }
1602
+ });
1603
+ }, [c]);
1604
+ r(() => {
1605
+ E.updateOptions({ body: e.body });
1606
+ }, [E, e.body]), r(() => {
1607
+ e.initialMessages && e.initialMessages.length > 0 && l.length === 0 && E.setMessagesManually(e.initialMessages);
1608
+ }, []), r(() => {
1609
+ e.live ? E.subscribe() : E.unsubscribe();
1610
+ }, [E, e.live]), r(() => () => {
1611
+ e.live ? E.unsubscribe() : E.stop();
1612
+ }, [E, e.live]);
1613
+ let D = n(async (e) => {
1614
+ await E.sendMessage(e);
1615
+ }, [E]), O = n(async (e) => {
1616
+ await E.append(e);
1617
+ }, [E]), k = n(async () => {
1618
+ await E.reload();
1619
+ }, [E]), A = n(() => {
1620
+ E.stop();
1621
+ }, [E]), j = n(() => {
1622
+ E.clear();
1623
+ }, [E]);
1624
+ return {
1625
+ messages: l,
1626
+ sendMessage: D,
1627
+ append: O,
1628
+ reload: k,
1629
+ stop: A,
1630
+ isLoading: d,
1631
+ error: p,
1632
+ status: h,
1633
+ isSubscribed: _,
1634
+ connectionStatus: y,
1635
+ sessionGenerating: x,
1636
+ setMessages: n((e) => {
1637
+ E.setMessagesManually(e);
1638
+ }, [E]),
1639
+ clear: j,
1640
+ addToolResult: n(async (e) => {
1641
+ await E.addToolResult(e);
1642
+ }, [E]),
1643
+ addToolApprovalResponse: n(async (e) => {
1644
+ await E.addToolApprovalResponse(e);
1645
+ }, [E])
1646
+ };
1647
+ }
1648
+ new Uint8Array(128).fill(128), t(null);
1649
+ //#endregion
1650
+ //#region ../../node_modules/.pnpm/@tanstack+ai-react-ui@0.6.2_@tanstack+ai-client@0.8.0_@tanstack+ai-react@0.8.0_@tanstac_8d26c9713f9262cc53d0ebd12334c287/node_modules/@tanstack/ai-react-ui/dist/esm/thinking-part.js
1651
+ function ThinkingPart({ content: e, className: t = "", isComplete: n = !1 }) {
1652
+ let [i, a] = s(!1);
1653
+ return r(() => {
1654
+ n && a(!0);
1655
+ }, [n]), /* @__PURE__ */ u("div", {
1656
+ className: t || void 0,
1657
+ "data-part-type": "thinking",
1658
+ "data-part-content": !0,
1659
+ children: [/* @__PURE__ */ u("button", {
1660
+ onClick: () => a(!i),
1661
+ className: "flex items-center gap-2 text-sm text-gray-400 hover:text-gray-300 transition-colors mb-2",
1662
+ "aria-expanded": !i,
1663
+ "aria-label": i ? "Expand thinking" : "Collapse thinking",
1664
+ children: [
1665
+ /* @__PURE__ */ l("span", {
1666
+ className: "text-xs",
1667
+ children: i ? "▶" : "▼"
1668
+ }),
1669
+ /* @__PURE__ */ l("span", {
1670
+ className: "italic",
1671
+ children: "💭 Thinking..."
1672
+ }),
1673
+ n && /* @__PURE__ */ l("span", {
1674
+ className: "text-xs text-gray-500",
1675
+ children: "(complete)"
1676
+ })
1677
+ ]
1678
+ }), !i && /* @__PURE__ */ l("div", {
1679
+ className: "text-gray-300 whitespace-pre-wrap font-mono text-sm",
1680
+ children: e
1681
+ })]
1682
+ });
1683
+ }
1684
+ //#endregion
1685
+ //#region ../../node_modules/.pnpm/@tanstack+ai-react-ui@0.6.2_@tanstack+ai-client@0.8.0_@tanstack+ai-react@0.8.0_@tanstac_8d26c9713f9262cc53d0ebd12334c287/node_modules/@tanstack/ai-react-ui/dist/esm/chat-message.js
1686
+ function ChatMessage({ message: e, className: t = "", userClassName: n = "", assistantClassName: r = "", textPartRenderer: i, thinkingPartRenderer: a, toolsRenderer: o, defaultToolRenderer: s, toolResultRenderer: c }) {
1687
+ return /* @__PURE__ */ l("div", {
1688
+ className: [t, e.role === "user" ? n : r].filter(Boolean).join(" ") || void 0,
1689
+ "data-message-id": e.id,
1690
+ "data-message-role": e.role,
1691
+ "data-message-created": e.createdAt?.toISOString(),
1692
+ children: e.parts.map((t, n) => /* @__PURE__ */ l(MessagePart, {
1693
+ part: t,
1694
+ isThinkingComplete: t.type === "thinking" && e.parts.slice(n + 1).some((e) => e.type === "text"),
1695
+ textPartRenderer: i,
1696
+ thinkingPartRenderer: a,
1697
+ toolsRenderer: o,
1698
+ defaultToolRenderer: s,
1699
+ toolResultRenderer: c
1700
+ }, `${e.id}-part-${n}`))
1701
+ });
1702
+ }
1703
+ function MessagePart({ part: e, isThinkingComplete: t, textPartRenderer: n, thinkingPartRenderer: r, toolsRenderer: i, defaultToolRenderer: a, toolResultRenderer: o }) {
1704
+ if (e.type === "text") return n ? /* @__PURE__ */ l(c, { children: n({ content: e.content }) }) : /* @__PURE__ */ l("div", {
1705
+ "data-part-type": "text",
1706
+ "data-part-content": !0,
1707
+ children: e.content
1708
+ });
1709
+ if (e.type === "thinking") return r ? /* @__PURE__ */ l(c, { children: r({
1710
+ content: e.content,
1711
+ isComplete: t
1712
+ }) }) : /* @__PURE__ */ l(ThinkingPart, {
1713
+ content: e.content,
1714
+ isComplete: t
1715
+ });
1716
+ if (e.type === "tool-call") {
1717
+ let t = {
1718
+ id: e.id,
1719
+ name: e.name,
1720
+ arguments: e.arguments,
1721
+ state: e.state,
1722
+ approval: e.approval,
1723
+ output: e.output
1724
+ };
1725
+ return i?.[e.name] ? /* @__PURE__ */ l(c, { children: i[e.name]?.(t) }) : a ? /* @__PURE__ */ l(c, { children: a(t) }) : /* @__PURE__ */ u("div", {
1726
+ "data-part-type": "tool-call",
1727
+ "data-tool-name": e.name,
1728
+ "data-tool-state": e.state,
1729
+ "data-tool-id": e.id,
1730
+ children: [
1731
+ /* @__PURE__ */ u("div", {
1732
+ "data-tool-header": !0,
1733
+ children: [/* @__PURE__ */ l("strong", { children: e.name }), /* @__PURE__ */ l("span", {
1734
+ "data-tool-state-badge": !0,
1735
+ children: e.state
1736
+ })]
1737
+ }),
1738
+ e.arguments && /* @__PURE__ */ l("div", {
1739
+ "data-tool-arguments": !0,
1740
+ children: /* @__PURE__ */ l("pre", { children: e.arguments })
1741
+ }),
1742
+ e.approval && /* @__PURE__ */ l("div", {
1743
+ "data-tool-approval": !0,
1744
+ children: e.approval.approved === void 0 ? "⏳ Awaiting approval..." : e.approval.approved ? "✓ Approved" : "✗ Denied"
1745
+ }),
1746
+ e.output && /* @__PURE__ */ l("div", {
1747
+ "data-tool-output": !0,
1748
+ children: /* @__PURE__ */ l("pre", { children: JSON.stringify(e.output, null, 2) })
1749
+ })
1750
+ ]
1751
+ });
1752
+ }
1753
+ return e.type === "tool-result" ? o ? /* @__PURE__ */ l(c, { children: o({
1754
+ toolCallId: e.toolCallId,
1755
+ content: e.content,
1756
+ state: e.state
1757
+ }) }) : /* @__PURE__ */ l("div", {
1758
+ "data-part-type": "tool-result",
1759
+ "data-tool-call-id": e.toolCallId,
1760
+ "data-tool-result-state": e.state,
1761
+ children: /* @__PURE__ */ l("div", {
1762
+ "data-tool-result-content": !0,
1763
+ children: e.content
1764
+ })
1765
+ }) : null;
1766
+ }
1767
+ //#endregion
1768
+ export { toolDefinition as a, fetchServerSentEvents as i, useChat as n, clientTools as r, ChatMessage as t };