@object-ui/plugin-chatbot 6.2.1 → 6.2.2

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.
package/dist/index.js CHANGED
@@ -15,31 +15,31 @@ import { nanoid as Ct } from "nanoid";
15
15
  import { codeToHtml as wt } from "shiki";
16
16
  import { useControllableState as Tt } from "@radix-ui/react-use-controllable-state";
17
17
  import { motion as Et } from "motion/react";
18
- import { ComponentRegistry as J } from "@object-ui/core";
18
+ import { ComponentRegistry as Dt } from "@object-ui/core";
19
19
  //#region \0rolldown/runtime.js
20
- var Dt = Object.defineProperty, Ot = (e, t) => {
20
+ var Ot = Object.defineProperty, kt = (e, t) => {
21
21
  let n = {};
22
- for (var r in e) Dt(n, r, {
22
+ for (var r in e) Ot(n, r, {
23
23
  get: e[r],
24
24
  enumerable: !0
25
25
  });
26
- return t || Dt(n, Symbol.toStringTag, { value: "Module" }), n;
26
+ return t || Ot(n, Symbol.toStringTag, { value: "Module" }), n;
27
27
  };
28
28
  //#endregion
29
29
  //#region src/utils.ts
30
- function kt(e = "msg") {
30
+ function At(e = "msg") {
31
31
  return typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : `${e}-${Date.now()}-${Math.random().toString(36).slice(2)}`;
32
32
  }
33
33
  //#endregion
34
34
  //#region src/mapMessages.ts
35
- function At(e, t) {
35
+ function jt(e, t) {
36
36
  return typeof e.content == "string" ? e.content : t.filter((e) => e.type === "text").map((e) => e.text ?? "").join("");
37
37
  }
38
- function jt(e) {
38
+ function Mt(e) {
39
39
  let t = e.filter((e) => e.type === "reasoning" || e.type === "reasoning-delta").map((e) => e.text ?? "").join("\n").trim();
40
40
  return t.length > 0 ? t : void 0;
41
41
  }
42
- function Mt(e) {
42
+ function Nt(e) {
43
43
  let t = (e) => {
44
44
  if (e && typeof e == "object") return e;
45
45
  if (typeof e != "string") return;
@@ -62,9 +62,9 @@ function Mt(e) {
62
62
  };
63
63
  }
64
64
  }
65
- function Nt(e) {
65
+ function Pt(e) {
66
66
  return e.filter((e) => e.type === "dynamic-tool" ? !0 : typeof e.type == "string" && e.type.startsWith("tool-")).map((e) => {
67
- let t = e.type === "dynamic-tool" ? e.toolName ?? "tool" : typeof e.type == "string" ? e.type.replace(/^tool-/, "") : "tool", n = e.output ?? e.result, r = Mt(n), i = e.state, a = r && i !== "output-error" ? "approval-requested" : i;
67
+ let t = e.type === "dynamic-tool" ? e.toolName ?? "tool" : typeof e.type == "string" ? e.type.replace(/^tool-/, "") : "tool", n = e.output ?? e.result, r = Nt(n), i = e.state, a = r && i !== "output-error" ? "approval-requested" : i;
68
68
  return {
69
69
  toolCallId: e.toolCallId ?? e.id ?? `${e.type ?? "tool"}-${Math.random().toString(36).slice(2, 8)}`,
70
70
  toolName: t,
@@ -76,7 +76,7 @@ function Nt(e) {
76
76
  };
77
77
  });
78
78
  }
79
- function Pt(e) {
79
+ function Ft(e) {
80
80
  let t = e.filter((e) => e.type === "source-url" || e.type === "source").map((e) => ({
81
81
  id: e.id,
82
82
  title: e.title,
@@ -84,26 +84,26 @@ function Pt(e) {
84
84
  })).filter((e) => !!e.url);
85
85
  return t.length > 0 ? t : void 0;
86
86
  }
87
- function Ft(e, t = {}) {
88
- let n = Array.isArray(e.parts) ? e.parts : [], r = Nt(n), i = Array.isArray(e.toolInvocations) ? e.toolInvocations : [];
87
+ function It(e, t = {}) {
88
+ let n = Array.isArray(e.parts) ? e.parts : [], r = Pt(n), i = Array.isArray(e.toolInvocations) ? e.toolInvocations : [];
89
89
  return {
90
90
  id: e.id ?? `msg-${Math.random().toString(36).slice(2, 8)}`,
91
91
  role: e.role ?? "assistant",
92
- content: At(e, n),
93
- reasoning: jt(n),
92
+ content: jt(e, n),
93
+ reasoning: Mt(n),
94
94
  toolInvocations: r.length > 0 ? r : i,
95
- sources: Pt(n),
95
+ sources: Ft(n),
96
96
  streaming: t.streaming
97
97
  };
98
98
  }
99
- function It(e, t = {}) {
99
+ function Lt(e, t = {}) {
100
100
  if (!Array.isArray(e) || e.length === 0) return [];
101
101
  let n = e.length - 1;
102
- return e.map((e, r) => Ft(e, { streaming: !!t.isStreaming && r === n && e.role === "assistant" }));
102
+ return e.map((e, r) => It(e, { streaming: !!t.isStreaming && r === n && e.role === "assistant" }));
103
103
  }
104
104
  //#endregion
105
105
  //#region src/useObjectChat.ts
106
- function Lt(e) {
106
+ function Rt(e) {
107
107
  return (e ?? []).map((e, t) => ({
108
108
  id: e.id || `msg-${t}`,
109
109
  role: e.role || "user",
@@ -114,8 +114,8 @@ function Lt(e) {
114
114
  toolInvocations: e.toolInvocations
115
115
  }));
116
116
  }
117
- function Y(e = {}) {
118
- let { api: t, initialMessages: n, conversationId: r, systemPrompt: i, model: a, streamingEnabled: s = !0, headers: f, body: p, maxToolRoundtrips: m = 5, onError: h, showTimestamp: g, autoResponse: _, autoResponseText: v, autoResponseDelay: y = 1e3, onSend: b } = e, x = u(t ? "api" : "local").current === "api", S = l(() => Lt(n).map((e) => ({
117
+ function J(e = {}) {
118
+ let { api: t, initialMessages: n, conversationId: r, systemPrompt: i, model: a, streamingEnabled: s = !0, headers: f, body: p, maxToolRoundtrips: m = 5, onError: h, showTimestamp: g, autoResponse: _, autoResponseText: v, autoResponseDelay: y = 1e3, onSend: b } = e, x = u(t ? "api" : "local").current === "api", S = l(() => Rt(n).map((e) => ({
119
119
  id: e.id,
120
120
  role: e.role,
121
121
  parts: [{
@@ -149,11 +149,11 @@ function Y(e = {}) {
149
149
  onError: x ? (e) => {
150
150
  h?.(e);
151
151
  } : void 0
152
- }), [w, T] = d(() => Lt(n)), [E, D] = d(!1), [O, k] = d(""), [A, j] = d(""), M = u(null);
152
+ }), [w, T] = d(() => Rt(n)), [E, D] = d(!1), [O, k] = d(""), [A, j] = d(""), M = u(null);
153
153
  if (c(() => () => {
154
154
  M.current &&= (clearTimeout(M.current), null);
155
155
  }, []), x) {
156
- let { messages: e, status: t, error: n, sendMessage: r, regenerate: i, stop: a, setMessages: s } = C, c = t === "submitted" || t === "streaming", l = It(e, { isStreaming: c }).map((t, n) => ({
156
+ let { messages: e, status: t, error: n, sendMessage: r, regenerate: i, stop: a, setMessages: s } = C, c = t === "submitted" || t === "streaming", l = Lt(e, { isStreaming: c }).map((t, n) => ({
157
157
  ...t,
158
158
  metadata: e[n]?.metadata
159
159
  }));
@@ -165,7 +165,7 @@ function Y(e = {}) {
165
165
  let t = e.trim();
166
166
  if (!t) return;
167
167
  let n = [...l, {
168
- id: kt("msg"),
168
+ id: At("msg"),
169
169
  role: "user",
170
170
  content: t
171
171
  }];
@@ -198,7 +198,7 @@ function Y(e = {}) {
198
198
  sendMessage: o((e) => {
199
199
  if (!e.trim()) return;
200
200
  let t = {
201
- id: kt("msg"),
201
+ id: At("msg"),
202
202
  role: "user",
203
203
  content: e.trim(),
204
204
  timestamp: g ? (/* @__PURE__ */ new Date()).toLocaleTimeString() : void 0
@@ -208,7 +208,7 @@ function Y(e = {}) {
208
208
  return b?.(e.trim(), r), r;
209
209
  }), k(""), _ && (D(!0), M.current = setTimeout(() => {
210
210
  let e = {
211
- id: kt("msg"),
211
+ id: At("msg"),
212
212
  role: "assistant",
213
213
  content: v || "Thank you for your message!",
214
214
  timestamp: g ? (/* @__PURE__ */ new Date()).toLocaleTimeString() : void 0
@@ -237,7 +237,7 @@ function Y(e = {}) {
237
237
  }
238
238
  //#endregion
239
239
  //#region src/useAgents.ts
240
- function Rt(e) {
240
+ function zt(e) {
241
241
  return e.filter((e) => typeof e?.name == "string" && e.name.length > 0).map((e) => ({
242
242
  name: e.name,
243
243
  label: e.label || e.name,
@@ -246,7 +246,7 @@ function Rt(e) {
246
246
  active: e.active !== !1
247
247
  }));
248
248
  }
249
- function zt(e = {}) {
249
+ function Bt(e = {}) {
250
250
  let { apiBase: t, headers: n, enabled: r = !0, fallback: i = [] } = e, [a, s] = d(i), [l, f] = d(!1), [p, m] = d(void 0), [h, g] = d(0), _ = u(n);
251
251
  return _.current = n, c(() => {
252
252
  if (!r || !t) return;
@@ -266,7 +266,7 @@ function zt(e = {}) {
266
266
  return e.json();
267
267
  }).then((e) => {
268
268
  if (n) return;
269
- let t = Rt(Array.isArray(e) ? e : e?.agents ?? []);
269
+ let t = zt(Array.isArray(e) ? e : e?.agents ?? []);
270
270
  s(t.length > 0 ? t : i);
271
271
  }).catch((e) => {
272
272
  n || e.name === "AbortError" || (m(e), s(i));
@@ -288,8 +288,8 @@ function zt(e = {}) {
288
288
  }
289
289
  //#endregion
290
290
  //#region src/FloatingChatbotProvider.tsx
291
- var Bt = e.createContext(null);
292
- function Vt({ defaultOpen: t = !1, children: n }) {
291
+ var Vt = e.createContext(null);
292
+ function Ht({ defaultOpen: t = !1, children: n }) {
293
293
  let [r, i] = e.useState(t), [a, o] = e.useState(!1), s = e.useMemo(() => ({
294
294
  isOpen: r,
295
295
  isFullscreen: a,
@@ -300,19 +300,19 @@ function Vt({ defaultOpen: t = !1, children: n }) {
300
300
  toggle: () => i((e) => !e),
301
301
  toggleFullscreen: () => o((e) => !e)
302
302
  }), [r, a]);
303
- return /* @__PURE__ */ K(Bt.Provider, {
303
+ return /* @__PURE__ */ K(Vt.Provider, {
304
304
  value: s,
305
305
  children: n
306
306
  });
307
307
  }
308
- function Ht() {
309
- let t = e.useContext(Bt);
308
+ function Ut() {
309
+ let t = e.useContext(Vt);
310
310
  if (!t) throw Error("useFloatingChatbot must be used within a <FloatingChatbotProvider>");
311
311
  return t;
312
312
  }
313
313
  //#endregion
314
314
  //#region src/FloatingChatbotTrigger.tsx
315
- function Ut() {
315
+ function Wt() {
316
316
  try {
317
317
  let { t: e } = _t();
318
318
  return (t, n) => {
@@ -323,8 +323,8 @@ function Ut() {
323
323
  return (e, t) => t;
324
324
  }
325
325
  }
326
- function Wt({ position: e = "bottom-right", size: t = 56, className: n }) {
327
- let { isOpen: r, toggle: i } = Ht(), a = Ut();
326
+ function Gt({ position: e = "bottom-right", size: t = 56, className: n }) {
327
+ let { isOpen: r, toggle: i } = Ut(), a = Wt();
328
328
  return /* @__PURE__ */ K(v, {
329
329
  onClick: i,
330
330
  className: H("fixed z-50 rounded-full shadow-lg transition-transform hover:scale-105", e === "bottom-right" ? "right-6 bottom-20 sm:bottom-6" : "left-6 bottom-20 sm:bottom-6", n),
@@ -340,10 +340,10 @@ function Wt({ position: e = "bottom-right", size: t = 56, className: n }) {
340
340
  }
341
341
  //#endregion
342
342
  //#region src/FloatingChatbotPanel.tsx
343
- function Gt({ title: e = "Chat", position: t = "bottom-right", width: n = 400, height: r = 520, children: i, className: a, headerExtra: o }) {
344
- let { isOpen: s, isFullscreen: c, close: l, toggleFullscreen: u } = Ht();
345
- if (!s) return null;
346
- let d = c ? {
343
+ function Kt({ title: e = "Chat", position: t = "bottom-right", width: n = 400, height: r = 520, children: i, className: a, headerExtra: o, headerActions: s }) {
344
+ let { isOpen: c, isFullscreen: l, close: u, toggleFullscreen: d } = Ut();
345
+ if (!c) return null;
346
+ let f = l ? {
347
347
  inset: 0,
348
348
  width: "100vw",
349
349
  height: "100vh"
@@ -353,8 +353,8 @@ function Gt({ title: e = "Chat", position: t = "bottom-right", width: n = 400, h
353
353
  maxHeight: "calc(100vh - 100px)"
354
354
  };
355
355
  return /* @__PURE__ */ q("div", {
356
- className: H("fixed z-50 flex flex-col rounded-lg border bg-background shadow-xl overflow-hidden transition-all", c ? "inset-0 rounded-none" : t === "bottom-right" ? "right-6 bottom-20" : "left-6 bottom-20", a),
357
- style: d,
356
+ className: H("fixed z-50 flex flex-col rounded-lg border bg-background shadow-xl overflow-hidden transition-all", l ? "inset-0 rounded-none" : t === "bottom-right" ? "right-6 bottom-20" : "left-6 bottom-20", a),
357
+ style: f,
358
358
  role: "dialog",
359
359
  "aria-label": e,
360
360
  "data-testid": "floating-chatbot-panel",
@@ -372,23 +372,27 @@ function Gt({ title: e = "Chat", position: t = "bottom-right", width: n = 400, h
372
372
  }) : null,
373
373
  /* @__PURE__ */ q("div", {
374
374
  className: "flex items-center gap-1 shrink-0",
375
- children: [/* @__PURE__ */ K(v, {
376
- variant: "ghost",
377
- size: "icon",
378
- className: "h-7 w-7",
379
- onClick: u,
380
- "aria-label": c ? "Exit fullscreen" : "Fullscreen",
381
- "data-testid": "floating-chatbot-fullscreen",
382
- children: K(c ? at : rt, { className: "h-4 w-4" })
383
- }), /* @__PURE__ */ K(v, {
384
- variant: "ghost",
385
- size: "icon",
386
- className: "h-7 w-7",
387
- onClick: l,
388
- "aria-label": "Close chat",
389
- "data-testid": "floating-chatbot-close",
390
- children: /* @__PURE__ */ K(ft, { className: "h-4 w-4" })
391
- })]
375
+ children: [
376
+ s,
377
+ /* @__PURE__ */ K(v, {
378
+ variant: "ghost",
379
+ size: "icon",
380
+ className: "h-7 w-7",
381
+ onClick: d,
382
+ "aria-label": l ? "Exit fullscreen" : "Fullscreen",
383
+ "data-testid": "floating-chatbot-fullscreen",
384
+ children: K(l ? at : rt, { className: "h-4 w-4" })
385
+ }),
386
+ /* @__PURE__ */ K(v, {
387
+ variant: "ghost",
388
+ size: "icon",
389
+ className: "h-7 w-7",
390
+ onClick: u,
391
+ "aria-label": "Close chat",
392
+ "data-testid": "floating-chatbot-close",
393
+ children: /* @__PURE__ */ K(ft, { className: "h-4 w-4" })
394
+ })
395
+ ]
392
396
  })
393
397
  ]
394
398
  }), /* @__PURE__ */ K("div", {
@@ -399,7 +403,7 @@ function Gt({ title: e = "Chat", position: t = "bottom-right", width: n = 400, h
399
403
  }
400
404
  //#endregion
401
405
  //#region src/tool-display.ts
402
- var Kt = {
406
+ var qt = {
403
407
  ai: "AI",
404
408
  api: "API",
405
409
  crm: "CRM",
@@ -411,17 +415,17 @@ var Kt = {
411
415
  url: "URL",
412
416
  utc: "UTC"
413
417
  };
414
- function qt(e) {
418
+ function Jt(e) {
415
419
  if (!e) return "";
416
420
  let t = String(e).trim();
417
421
  if (!t) return "";
418
422
  let n = t.replace(/[_-]+/g, " ").replace(/([a-z])([A-Z])/g, "$1 $2").split(/\s+/).filter(Boolean);
419
423
  return n.length === 0 ? t : n.map((e, t) => {
420
424
  let n = e.toLowerCase();
421
- return Kt[n] ? Kt[n] : t === 0 ? n.charAt(0).toUpperCase() + n.slice(1) : n;
425
+ return qt[n] ? qt[n] : t === 0 ? n.charAt(0).toUpperCase() + n.slice(1) : n;
422
426
  }).join(" ");
423
427
  }
424
- function Jt(e) {
428
+ function Yt(e) {
425
429
  if (e == null) return e;
426
430
  let t = e;
427
431
  for (let e = 0; e < 2; e++) {
@@ -439,7 +443,7 @@ function Jt(e) {
439
443
  }
440
444
  return t;
441
445
  }
442
- function Yt(e) {
446
+ function Xt(e) {
443
447
  let t = (e instanceof Error ? e.message : String(e ?? "")).replace(/\s+/g, " ").trim();
444
448
  if (!t) return { summary: "Something went wrong. Please try again." };
445
449
  let n = t.replace(/^Failed after \d+ attempts?\.\s*Last error:\s*/i, ""), r = n.match(/^([^.;:]+[.;:!?])\s/)?.[1]?.trim() ?? (n.length > 140 ? `${n.slice(0, 137).trimEnd()}…` : n);
@@ -450,16 +454,16 @@ function Yt(e) {
450
454
  }
451
455
  //#endregion
452
456
  //#region src/elements/conversation.tsx
453
- var Xt = ({ className: e, ...t }) => /* @__PURE__ */ K(vt, {
457
+ var Zt = ({ className: e, ...t }) => /* @__PURE__ */ K(vt, {
454
458
  className: H("relative flex-1 overflow-y-hidden", e),
455
459
  initial: "smooth",
456
460
  resize: "smooth",
457
461
  role: "log",
458
462
  ...t
459
- }), Zt = ({ className: e, ...t }) => /* @__PURE__ */ K(vt.Content, {
463
+ }), Qt = ({ className: e, ...t }) => /* @__PURE__ */ K(vt.Content, {
460
464
  className: H("flex flex-col gap-8 p-4", e),
461
465
  ...t
462
- }), Qt = ({ className: e, title: t = "No messages yet", description: n = "Start a conversation to see messages here", icon: r, children: i, ...a }) => /* @__PURE__ */ K("div", {
466
+ }), $t = ({ className: e, title: t = "No messages yet", description: n = "Start a conversation to see messages here", icon: r, children: i, ...a }) => /* @__PURE__ */ K("div", {
463
467
  className: H("flex size-full flex-col items-center justify-center gap-3 p-8 text-center", e),
464
468
  ...a,
465
469
  children: i ?? /* @__PURE__ */ q(G, { children: [r && /* @__PURE__ */ K("div", {
@@ -475,7 +479,7 @@ var Xt = ({ className: e, ...t }) => /* @__PURE__ */ K(vt, {
475
479
  children: n
476
480
  })]
477
481
  })] })
478
- }), $t = ({ className: e, ...t }) => {
482
+ }), en = ({ className: e, ...t }) => {
479
483
  let { isAtBottom: n, scrollToBottom: r } = yt(), i = o(() => {
480
484
  r();
481
485
  }, [r]);
@@ -488,23 +492,23 @@ var Xt = ({ className: e, ...t }) => /* @__PURE__ */ K(vt, {
488
492
  ...t,
489
493
  children: /* @__PURE__ */ K(Fe, { className: "size-4" })
490
494
  });
491
- }, en = bt("flex w-fit items-stretch has-[>[data-slot=button-group]]:gap-2 [&>*]:focus-visible:relative [&>*]:focus-visible:z-10 has-[select[aria-hidden=true]:last-child]:[&>[data-slot=select-trigger]:last-of-type]:rounded-r-md [&>[data-slot=select-trigger]:not([class*='w-'])]:w-fit [&>input]:flex-1", {
495
+ }, tn = bt("flex w-fit items-stretch has-[>[data-slot=button-group]]:gap-2 [&>*]:focus-visible:relative [&>*]:focus-visible:z-10 has-[select[aria-hidden=true]:last-child]:[&>[data-slot=select-trigger]:last-of-type]:rounded-r-md [&>[data-slot=select-trigger]:not([class*='w-'])]:w-fit [&>input]:flex-1", {
492
496
  variants: { orientation: {
493
497
  horizontal: "[&>*:not(:first-child)]:rounded-l-none [&>*:not(:first-child)]:border-l-0 [&>*:not(:last-child)]:rounded-r-none",
494
498
  vertical: "flex-col [&>*:not(:first-child)]:rounded-t-none [&>*:not(:first-child)]:border-t-0 [&>*:not(:last-child)]:rounded-b-none"
495
499
  } },
496
500
  defaultVariants: { orientation: "horizontal" }
497
501
  });
498
- function tn({ className: e, orientation: t, ...n }) {
502
+ function nn({ className: e, orientation: t, ...n }) {
499
503
  return /* @__PURE__ */ K("div", {
500
504
  role: "group",
501
505
  "data-slot": "button-group",
502
506
  "data-orientation": t,
503
- className: H(en({ orientation: t }), e),
507
+ className: H(tn({ orientation: t }), e),
504
508
  ...n
505
509
  });
506
510
  }
507
- function nn({ className: e, asChild: t = !1, ...n }) {
511
+ function rn({ className: e, asChild: t = !1, ...n }) {
508
512
  return /* @__PURE__ */ K(t ? xt : "div", {
509
513
  className: H("flex items-center gap-2 rounded-md border bg-muted px-4 text-sm font-medium shadow-xs [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4", e),
510
514
  ...n
@@ -512,18 +516,18 @@ function nn({ className: e, asChild: t = !1, ...n }) {
512
516
  }
513
517
  //#endregion
514
518
  //#region src/elements/message.tsx
515
- var rn = ({ className: e, from: t, ...n }) => /* @__PURE__ */ K("div", {
519
+ var an = ({ className: e, from: t, ...n }) => /* @__PURE__ */ K("div", {
516
520
  className: H("group flex w-full max-w-[95%] flex-col gap-2", t === "user" ? "is-user ml-auto justify-end" : "is-assistant", e),
517
521
  ...n
518
- }), an = ({ children: e, className: t, ...n }) => /* @__PURE__ */ K("div", {
522
+ }), on = ({ children: e, className: t, ...n }) => /* @__PURE__ */ K("div", {
519
523
  className: H("is-user:dark flex w-fit max-w-full min-w-0 flex-col gap-2 overflow-hidden text-sm", "group-[.is-user]:ml-auto group-[.is-user]:rounded-lg group-[.is-user]:bg-secondary group-[.is-user]:px-4 group-[.is-user]:py-3 group-[.is-user]:text-foreground", "group-[.is-assistant]:text-foreground", t),
520
524
  ...n,
521
525
  children: e
522
- }), on = ({ className: e, children: t, ...n }) => /* @__PURE__ */ K("div", {
526
+ }), sn = ({ className: e, children: t, ...n }) => /* @__PURE__ */ K("div", {
523
527
  className: H("flex items-center gap-1", e),
524
528
  ...n,
525
529
  children: t
526
- }), sn = ({ tooltip: e, children: t, label: n, variant: r = "ghost", size: i = "icon", ...a }) => {
530
+ }), cn = ({ tooltip: e, children: t, label: n, variant: r = "ghost", size: i = "icon", ...a }) => {
527
531
  let o = /* @__PURE__ */ q(v, {
528
532
  size: i,
529
533
  type: "button",
@@ -538,11 +542,11 @@ var rn = ({ className: e, from: t, ...n }) => /* @__PURE__ */ K("div", {
538
542
  asChild: !0,
539
543
  children: o
540
544
  }), /* @__PURE__ */ K(je, { children: /* @__PURE__ */ K("p", { children: e }) })] }) }) : o;
541
- }, cn = r(null), X = () => {
542
- let e = s(cn);
545
+ }, ln = r(null), Y = () => {
546
+ let e = s(ln);
543
547
  if (!e) throw Error("MessageBranch components must be used within MessageBranch");
544
548
  return e;
545
- }, ln = ({ defaultBranch: e = 0, onBranchChange: t, className: n, ...r }) => {
549
+ }, un = ({ defaultBranch: e = 0, onBranchChange: t, className: n, ...r }) => {
546
550
  let [i, a] = d(e), [o, s] = d([]), c = (e) => {
547
551
  a(e), t?.(e);
548
552
  }, l = {
@@ -557,15 +561,15 @@ var rn = ({ className: e, from: t, ...n }) => /* @__PURE__ */ K("div", {
557
561
  branches: o,
558
562
  setBranches: s
559
563
  };
560
- return /* @__PURE__ */ K(cn.Provider, {
564
+ return /* @__PURE__ */ K(ln.Provider, {
561
565
  value: l,
562
566
  children: /* @__PURE__ */ K("div", {
563
567
  className: H("grid w-full gap-2 [&>div]:pb-0", n),
564
568
  ...r
565
569
  })
566
570
  });
567
- }, un = ({ children: e, ...t }) => {
568
- let { currentBranch: n, setBranches: r, branches: i } = X(), a = Array.isArray(e) ? e : [e];
571
+ }, dn = ({ children: e, ...t }) => {
572
+ let { currentBranch: n, setBranches: r, branches: i } = Y(), a = Array.isArray(e) ? e : [e];
569
573
  return c(() => {
570
574
  i.length !== a.length && r(a);
571
575
  }, [
@@ -577,15 +581,15 @@ var rn = ({ className: e, from: t, ...n }) => /* @__PURE__ */ K("div", {
577
581
  ...t,
578
582
  children: e
579
583
  }, e.key));
580
- }, dn = ({ className: e, from: t, ...n }) => {
581
- let { totalBranches: r } = X();
582
- return r <= 1 ? null : /* @__PURE__ */ K(tn, {
584
+ }, fn = ({ className: e, from: t, ...n }) => {
585
+ let { totalBranches: r } = Y();
586
+ return r <= 1 ? null : /* @__PURE__ */ K(nn, {
583
587
  className: "[&>*:not(:first-child)]:rounded-l-md [&>*:not(:last-child)]:rounded-r-md",
584
588
  orientation: "horizontal",
585
589
  ...n
586
590
  });
587
- }, fn = ({ children: e, ...t }) => {
588
- let { goToPrevious: n, totalBranches: r } = X();
591
+ }, pn = ({ children: e, ...t }) => {
592
+ let { goToPrevious: n, totalBranches: r } = Y();
589
593
  return /* @__PURE__ */ K(v, {
590
594
  "aria-label": "Previous branch",
591
595
  disabled: r <= 1,
@@ -596,8 +600,8 @@ var rn = ({ className: e, from: t, ...n }) => /* @__PURE__ */ K("div", {
596
600
  ...t,
597
601
  children: e ?? /* @__PURE__ */ K(We, { size: 14 })
598
602
  });
599
- }, pn = ({ children: e, className: t, ...n }) => {
600
- let { goToNext: r, totalBranches: i } = X();
603
+ }, mn = ({ children: e, className: t, ...n }) => {
604
+ let { goToNext: r, totalBranches: i } = Y();
601
605
  return /* @__PURE__ */ K(v, {
602
606
  "aria-label": "Next branch",
603
607
  disabled: i <= 1,
@@ -608,9 +612,9 @@ var rn = ({ className: e, from: t, ...n }) => /* @__PURE__ */ K("div", {
608
612
  ...n,
609
613
  children: e ?? /* @__PURE__ */ K(Ge, { size: 14 })
610
614
  });
611
- }, mn = ({ className: e, ...t }) => {
612
- let { currentBranch: n, totalBranches: r } = X();
613
- return /* @__PURE__ */ q(nn, {
615
+ }, hn = ({ className: e, ...t }) => {
616
+ let { currentBranch: n, totalBranches: r } = Y();
617
+ return /* @__PURE__ */ q(rn, {
614
618
  className: H("border-none bg-transparent text-muted-foreground shadow-none", e),
615
619
  ...t,
616
620
  children: [
@@ -619,11 +623,11 @@ var rn = ({ className: e, from: t, ...n }) => /* @__PURE__ */ K("div", {
619
623
  r
620
624
  ]
621
625
  });
622
- }, hn = a(({ className: e, ...t }) => /* @__PURE__ */ K(St, {
626
+ }, X = a(({ className: e, ...t }) => /* @__PURE__ */ K(St, {
623
627
  className: H("size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0", e),
624
628
  ...t
625
629
  }), (e, t) => e.children === t.children);
626
- hn.displayName = "MessageResponse";
630
+ X.displayName = "MessageResponse";
627
631
  function gn({ data: e, className: t, onRemove: n, ...r }) {
628
632
  let i = e.filename || "", a = (e.mediaType?.startsWith("image/") && e.url ? "image" : "file") == "image", o = i || (a ? "Image" : "Attachment");
629
633
  return /* @__PURE__ */ K("div", {
@@ -1550,6 +1554,15 @@ function Br(e, t) {
1550
1554
  function Vr(e) {
1551
1555
  return e === "user" ? "user" : "assistant";
1552
1556
  }
1557
+ function Hr(e) {
1558
+ let t = e.trim();
1559
+ if (t.length < 2 || !(t.startsWith("{") || t.startsWith("[")) || !(t.endsWith("}") || t.endsWith("]"))) return !1;
1560
+ try {
1561
+ return JSON.parse(t), !0;
1562
+ } catch {
1563
+ return !1;
1564
+ }
1565
+ }
1553
1566
  var $ = e.forwardRef(({ className: t, messages: n = [], placeholder: r = "Type your message...", onSendMessage: i, onClear: a, onStop: o, onReload: s, disabled: c = !1, isLoading: l = !1, error: u, showTimestamp: d = !1, userAvatarUrl: f, userAvatarFallback: p = "You", assistantAvatarUrl: m, assistantAvatarFallback: h = "AI", maxHeight: g = "500px", enableMarkdown: _ = !0, enableFileUpload: v = !1, acceptedFileTypes: y = "image/*,.pdf,.doc,.docx,.txt", maxFileSize: b = 10 * 1024 * 1024, suggestions: x, models: S, selectedModelId: C, onModelChange: w, headerSlot: T, promptOverlaySlot: E, onInputChange: D, onToolApprove: O, toolApproveLabel: k = "Approve", toolDenyLabel: A = "Deny", toolDenyReason: j = "User denied the operation", toolDecisions: M, ...N }, P) => {
1554
1567
  let F = Br(l, u), [I, L] = e.useState(null), ee = e.useCallback((e) => {
1555
1568
  let t = !!e.text?.trim(), n = e.files?.map((e) => e.file).filter(Boolean), r = !!(n && n.length > 0);
@@ -1585,11 +1598,11 @@ var $ = e.forwardRef(({ className: t, messages: n = [], placeholder: r = "Type y
1585
1598
  className: "shrink-0 border-b bg-background/50",
1586
1599
  children: T
1587
1600
  }) : null,
1588
- /* @__PURE__ */ q(Xt, {
1601
+ /* @__PURE__ */ q(Zt, {
1589
1602
  className: "flex-1 min-h-0",
1590
- children: [/* @__PURE__ */ K(Zt, {
1603
+ children: [/* @__PURE__ */ K(Qt, {
1591
1604
  className: "space-y-4 px-4 py-3",
1592
- children: n.length === 0 ? /* @__PURE__ */ K(Qt, {
1605
+ children: n.length === 0 ? /* @__PURE__ */ K($t, {
1593
1606
  title: "Start a conversation",
1594
1607
  description: "Ask anything — the assistant has access to your current app context.",
1595
1608
  children: x && x.length > 0 ? /* @__PURE__ */ K(hr, {
@@ -1601,16 +1614,16 @@ var $ = e.forwardRef(({ className: t, messages: n = [], placeholder: r = "Type y
1601
1614
  }) : null
1602
1615
  }) : n.map((e) => {
1603
1616
  let t = e.role === "user", n = e.toolInvocations ?? [], r = e.reasoning?.trim(), i = e.sources ?? [];
1604
- return /* @__PURE__ */ q(rn, {
1617
+ return /* @__PURE__ */ q(an, {
1605
1618
  from: Vr(e.role),
1606
- children: [/* @__PURE__ */ q(an, { children: [
1619
+ children: [/* @__PURE__ */ q(on, { children: [
1607
1620
  !t && r ? /* @__PURE__ */ q(Mr, {
1608
1621
  isStreaming: !!e.streaming && !e.content,
1609
1622
  className: "mb-2",
1610
1623
  children: [/* @__PURE__ */ K(Pr, {}), /* @__PURE__ */ K(Fr, { children: r })]
1611
1624
  }) : null,
1612
1625
  !t && n.length > 0 ? n.map((e) => {
1613
- let t = e.state ?? (e.errorText ? "output-error" : e.result === void 0 ? "input-available" : "output-available"), n = `tool-${e.toolName}`, r = M?.[e.toolCallId], i = t === "approval-requested" && !!O && !r, a = t === "approval-requested" && !!e.pendingActionId, o = qt(e.toolName), s = Jt(e.result), c = /* @__PURE__ */ q("span", {
1626
+ let t = e.state ?? (e.errorText ? "output-error" : e.result === void 0 ? "input-available" : "output-available"), n = `tool-${e.toolName}`, r = M?.[e.toolCallId], i = t === "approval-requested" && !!O && !r, a = t === "approval-requested" && !!e.pendingActionId, o = Jt(e.toolName), s = Yt(e.result), c = /* @__PURE__ */ q("span", {
1614
1627
  className: "inline-flex items-center gap-2",
1615
1628
  children: [/* @__PURE__ */ K("span", { children: o || e.toolName }), o && o.toLowerCase() !== e.toolName.toLowerCase() ? /* @__PURE__ */ K("code", {
1616
1629
  className: "rounded bg-muted px-1 py-px text-[10px] font-mono text-muted-foreground",
@@ -1618,14 +1631,14 @@ var $ = e.forwardRef(({ className: t, messages: n = [], placeholder: r = "Type y
1618
1631
  }) : null]
1619
1632
  });
1620
1633
  return /* @__PURE__ */ q(xr, {
1621
- defaultOpen: t !== "output-available",
1634
+ defaultOpen: t === "output-error" || t === "approval-requested",
1622
1635
  children: [/* @__PURE__ */ K(Cr, {
1623
1636
  type: n,
1624
1637
  state: t,
1625
1638
  title: c
1626
1639
  }), /* @__PURE__ */ q(wr, { children: [
1627
1640
  e.args === void 0 ? null : /* @__PURE__ */ K(Tr, { input: e.args }),
1628
- a ? null : /* @__PURE__ */ K(Er, {
1641
+ a ? null : /* @__PURE__ */ K(Wr, {
1629
1642
  output: s,
1630
1643
  errorText: e.errorText
1631
1644
  }),
@@ -1653,7 +1666,10 @@ var $ = e.forwardRef(({ className: t, messages: n = [], placeholder: r = "Type y
1653
1666
  ] })]
1654
1667
  }, e.toolCallId);
1655
1668
  }) : null,
1656
- e.content,
1669
+ t ? e.content ? /* @__PURE__ */ K("div", {
1670
+ className: "whitespace-pre-wrap break-words",
1671
+ children: e.content
1672
+ }) : null : e.content ? /* @__PURE__ */ K(X, { children: e.content }) : null,
1657
1673
  e.streaming ? /* @__PURE__ */ K("span", {
1658
1674
  "aria-hidden": !0,
1659
1675
  className: "ml-0.5 inline-block w-[2px] h-4 align-middle bg-current animate-pulse"
@@ -1666,14 +1682,14 @@ var $ = e.forwardRef(({ className: t, messages: n = [], placeholder: r = "Type y
1666
1682
  className: "text-[10px] opacity-70 mt-1",
1667
1683
  children: e.timestamp
1668
1684
  }) : null
1669
- ] }), t ? null : /* @__PURE__ */ q(on, { children: [
1670
- /* @__PURE__ */ K(sn, {
1685
+ ] }), t ? null : /* @__PURE__ */ q(sn, { children: [
1686
+ /* @__PURE__ */ K(cn, {
1671
1687
  label: "Copy",
1672
1688
  tooltip: "Copy",
1673
1689
  onClick: () => ne(e),
1674
1690
  children: I === e.id ? /* @__PURE__ */ K(ze, { className: "size-3.5" }) : /* @__PURE__ */ K(Ye, { className: "size-3.5" })
1675
1691
  }),
1676
- s ? /* @__PURE__ */ K(sn, {
1692
+ s ? /* @__PURE__ */ K(cn, {
1677
1693
  label: "Regenerate",
1678
1694
  tooltip: "Regenerate",
1679
1695
  onClick: s,
@@ -1689,9 +1705,9 @@ var $ = e.forwardRef(({ className: t, messages: n = [], placeholder: r = "Type y
1689
1705
  ] })]
1690
1706
  }, e.id);
1691
1707
  })
1692
- }), /* @__PURE__ */ K($t, {})]
1708
+ }), /* @__PURE__ */ K(en, {})]
1693
1709
  }),
1694
- u ? /* @__PURE__ */ K(Hr, {
1710
+ u ? /* @__PURE__ */ K(Ur, {
1695
1711
  error: u,
1696
1712
  onReload: s
1697
1713
  }) : null,
@@ -1758,8 +1774,8 @@ var $ = e.forwardRef(({ className: t, messages: n = [], placeholder: r = "Type y
1758
1774
  });
1759
1775
  });
1760
1776
  $.displayName = "ChatbotEnhanced";
1761
- function Hr({ error: t, onReload: n }) {
1762
- let { summary: r, details: i } = e.useMemo(() => Yt(t), [t]), [a, o] = e.useState(!1);
1777
+ function Ur({ error: t, onReload: n }) {
1778
+ let { summary: r, details: i } = e.useMemo(() => Xt(t), [t]), [a, o] = e.useState(!1);
1763
1779
  return /* @__PURE__ */ q("div", {
1764
1780
  className: "flex flex-col gap-1 border-t bg-destructive/10 px-4 py-2 text-destructive text-sm",
1765
1781
  role: "alert",
@@ -1791,38 +1807,57 @@ function Hr({ error: t, onReload: n }) {
1791
1807
  }) : null]
1792
1808
  });
1793
1809
  }
1810
+ function Wr({ output: e, errorText: t }) {
1811
+ return t ? /* @__PURE__ */ K(Er, {
1812
+ output: void 0,
1813
+ errorText: t
1814
+ }) : e == null || e === "" ? null : typeof e == "string" && !Hr(e) ? /* @__PURE__ */ q("div", {
1815
+ className: "space-y-2 p-4",
1816
+ children: [/* @__PURE__ */ K("h4", {
1817
+ className: "font-medium text-muted-foreground text-xs uppercase tracking-wide",
1818
+ children: "Result"
1819
+ }), /* @__PURE__ */ K("div", {
1820
+ className: "overflow-x-auto rounded-md bg-muted/40 px-3 py-2 text-sm text-foreground",
1821
+ children: /* @__PURE__ */ K(X, { children: e })
1822
+ })]
1823
+ }) : /* @__PURE__ */ K(Er, {
1824
+ output: e,
1825
+ errorText: void 0
1826
+ });
1827
+ }
1794
1828
  //#endregion
1795
1829
  //#region src/FloatingChatbot.tsx
1796
- function Ur({ floatingConfig: t, headerExtra: n, ...r }) {
1797
- let { position: i = "bottom-right", defaultOpen: a = !1, panelWidth: o = 400, panelHeight: s = 520, title: c = "Chat", triggerSize: l = 56 } = t ?? {}, [u, d] = e.useState(null);
1830
+ function Gr({ floatingConfig: t, headerExtra: n, headerActions: r, ...i }) {
1831
+ let { position: a = "bottom-right", defaultOpen: o = !1, panelWidth: s = 400, panelHeight: c = 520, title: l = "Chat", triggerSize: u = 56 } = t ?? {}, [d, f] = e.useState(null);
1798
1832
  e.useEffect(() => {
1799
1833
  let e = document.getElementById("floating-chatbot-portal");
1800
- return e || (e = document.createElement("div"), e.id = "floating-chatbot-portal", document.body.appendChild(e)), d(e), () => {
1834
+ return e || (e = document.createElement("div"), e.id = "floating-chatbot-portal", document.body.appendChild(e)), f(e), () => {
1801
1835
  e && e.parentNode && !e.hasChildNodes() && e.parentNode.removeChild(e);
1802
1836
  };
1803
1837
  }, []);
1804
- let f = /* @__PURE__ */ q(Vt, {
1805
- defaultOpen: a,
1806
- children: [/* @__PURE__ */ K(Wt, {
1807
- position: i,
1808
- size: l
1809
- }), /* @__PURE__ */ K(Gt, {
1810
- title: c,
1811
- position: i,
1812
- width: o,
1813
- height: s,
1838
+ let p = /* @__PURE__ */ q(Ht, {
1839
+ defaultOpen: o,
1840
+ children: [/* @__PURE__ */ K(Gt, {
1841
+ position: a,
1842
+ size: u
1843
+ }), /* @__PURE__ */ K(Kt, {
1844
+ title: l,
1845
+ position: a,
1846
+ width: s,
1847
+ height: c,
1814
1848
  headerExtra: n,
1849
+ headerActions: r,
1815
1850
  children: /* @__PURE__ */ K($, {
1816
- ...r,
1851
+ ...i,
1817
1852
  maxHeight: "100%",
1818
1853
  className: "h-full border-0 rounded-none"
1819
1854
  })
1820
1855
  })]
1821
1856
  });
1822
- return u ? gt.createPortal(f, u) : f;
1857
+ return d ? gt.createPortal(p, d) : p;
1823
1858
  }
1824
- J.register("chatbot", ({ schema: e, className: t, ...n }) => {
1825
- let { messages: r, isLoading: i, sendMessage: a } = Y({
1859
+ Dt.register("chatbot", ({ schema: e, className: t, ...n }) => {
1860
+ let { messages: r, isLoading: i, sendMessage: a } = J({
1826
1861
  api: e.api,
1827
1862
  initialMessages: e.messages,
1828
1863
  conversationId: e.conversationId,
@@ -1839,7 +1874,7 @@ J.register("chatbot", ({ schema: e, className: t, ...n }) => {
1839
1874
  autoResponseDelay: e.autoResponseDelay,
1840
1875
  onSend: e.onSend
1841
1876
  });
1842
- return /* @__PURE__ */ K(ui, {
1877
+ return /* @__PURE__ */ K(fi, {
1843
1878
  messages: r,
1844
1879
  placeholder: e.placeholder,
1845
1880
  onSendMessage: (e) => {
@@ -1987,8 +2022,8 @@ J.register("chatbot", ({ schema: e, className: t, ...n }) => {
1987
2022
  autoResponseDelay: 1e3,
1988
2023
  className: "w-full max-w-2xl"
1989
2024
  }
1990
- }), J.register("chatbot-enhanced", ({ schema: e, className: t, ...n }) => {
1991
- let { messages: r, isLoading: i, error: a, sendMessage: o, stop: s, reload: c, clear: l, isApiMode: u } = Y({
2025
+ }), Dt.register("chatbot-enhanced", ({ schema: e, className: t, ...n }) => {
2026
+ let { messages: r, isLoading: i, error: a, sendMessage: o, stop: s, reload: c, clear: l, isApiMode: u } = J({
1992
2027
  api: e.api,
1993
2028
  initialMessages: e.messages,
1994
2029
  conversationId: e.conversationId,
@@ -2167,8 +2202,8 @@ J.register("chatbot", ({ schema: e, className: t, ...n }) => {
2167
2202
  autoResponseDelay: 1e3,
2168
2203
  className: "w-full max-w-2xl"
2169
2204
  }
2170
- }), J.register("chatbot-floating", ({ schema: e, className: t, ...n }) => {
2171
- let { messages: r, isLoading: i, error: a, sendMessage: o, stop: s, reload: c, clear: l, isApiMode: u } = Y({
2205
+ }), Dt.register("chatbot-floating", ({ schema: e, className: t, ...n }) => {
2206
+ let { messages: r, isLoading: i, error: a, sendMessage: o, stop: s, reload: c, clear: l, isApiMode: u } = J({
2172
2207
  api: e.api,
2173
2208
  initialMessages: e.messages,
2174
2209
  conversationId: e.conversationId,
@@ -2185,7 +2220,7 @@ J.register("chatbot", ({ schema: e, className: t, ...n }) => {
2185
2220
  autoResponseDelay: e.autoResponseDelay,
2186
2221
  onSend: e.onSend
2187
2222
  });
2188
- return /* @__PURE__ */ K(Ur, {
2223
+ return /* @__PURE__ */ K(Gr, {
2189
2224
  floatingConfig: e.floatingConfig,
2190
2225
  messages: r,
2191
2226
  placeholder: e.placeholder,
@@ -2357,7 +2392,7 @@ J.register("chatbot", ({ schema: e, className: t, ...n }) => {
2357
2392
  });
2358
2393
  //#endregion
2359
2394
  //#region src/elements/loader.tsx
2360
- var Wr = ({ size: e = 16 }) => /* @__PURE__ */ q("svg", {
2395
+ var Kr = ({ size: e = 16 }) => /* @__PURE__ */ q("svg", {
2361
2396
  height: e,
2362
2397
  strokeLinejoin: "round",
2363
2398
  style: { color: "currentcolor" },
@@ -2438,31 +2473,31 @@ var Wr = ({ size: e = 16 }) => /* @__PURE__ */ q("svg", {
2438
2473
  })
2439
2474
  }) })
2440
2475
  ]
2441
- }), Gr = ({ className: e, size: t = 16, ...n }) => /* @__PURE__ */ K("div", {
2476
+ }), qr = ({ className: e, size: t = 16, ...n }) => /* @__PURE__ */ K("div", {
2442
2477
  className: H("inline-flex animate-spin items-center justify-center", e),
2443
2478
  ...n,
2444
- children: /* @__PURE__ */ K(Wr, { size: t })
2445
- }), Kr = /* @__PURE__ */ Ot({
2479
+ children: /* @__PURE__ */ K(Kr, { size: t })
2480
+ }), Jr = /* @__PURE__ */ kt({
2446
2481
  CodeBlock: () => Q,
2447
2482
  CodeBlockCopyButton: () => br,
2448
- Conversation: () => Xt,
2449
- ConversationContent: () => Zt,
2450
- ConversationEmptyState: () => Qt,
2451
- ConversationScrollButton: () => $t,
2452
- Loader: () => Gr,
2453
- Message: () => rn,
2454
- MessageAction: () => sn,
2455
- MessageActions: () => on,
2483
+ Conversation: () => Zt,
2484
+ ConversationContent: () => Qt,
2485
+ ConversationEmptyState: () => $t,
2486
+ ConversationScrollButton: () => en,
2487
+ Loader: () => qr,
2488
+ Message: () => an,
2489
+ MessageAction: () => cn,
2490
+ MessageActions: () => sn,
2456
2491
  MessageAttachment: () => gn,
2457
2492
  MessageAttachments: () => _n,
2458
- MessageBranch: () => ln,
2459
- MessageBranchContent: () => un,
2460
- MessageBranchNext: () => pn,
2461
- MessageBranchPage: () => mn,
2462
- MessageBranchPrevious: () => fn,
2463
- MessageBranchSelector: () => dn,
2464
- MessageContent: () => an,
2465
- MessageResponse: () => hn,
2493
+ MessageBranch: () => un,
2494
+ MessageBranchContent: () => dn,
2495
+ MessageBranchNext: () => mn,
2496
+ MessageBranchPage: () => hn,
2497
+ MessageBranchPrevious: () => pn,
2498
+ MessageBranchSelector: () => fn,
2499
+ MessageContent: () => on,
2500
+ MessageResponse: () => X,
2466
2501
  MessageToolbar: () => vn,
2467
2502
  PromptInput: () => In,
2468
2503
  PromptInputActionAddAttachments: () => Fn,
@@ -2521,14 +2556,14 @@ var Wr = ({ size: e = 16 }) => /* @__PURE__ */ q("svg", {
2521
2556
  usePromptInputController: () => Dn,
2522
2557
  useProviderAttachments: () => kn,
2523
2558
  useReasoning: () => kr
2524
- }), qr = "/api/v1/ai";
2525
- function Jr(e, t, n) {
2559
+ }), Yr = "/api/v1/ai";
2560
+ function Xr(e, t, n) {
2526
2561
  let r = e.replace(/\/$/, ""), i = new URLSearchParams();
2527
2562
  if (n) for (let [e, t] of Object.entries(n)) t == null || t === "" || i.set(e, String(t));
2528
2563
  let a = i.toString();
2529
2564
  return `${r}${t}${a ? `?${a}` : ""}`;
2530
2565
  }
2531
- async function Yr(e, t, n) {
2566
+ async function Zr(e, t, n) {
2532
2567
  let r = await fetch(e, {
2533
2568
  credentials: "include",
2534
2569
  ...t,
@@ -2548,8 +2583,8 @@ async function Yr(e, t, n) {
2548
2583
  }
2549
2584
  return i;
2550
2585
  }
2551
- function Xr(t = {}) {
2552
- let { apiBase: n = qr, status: r = "pending", conversationId: i, limit: a, headers: o, pollInterval: s = 5e3, enabled: c = !0 } = t, [l, u] = e.useState([]), [d, f] = e.useState(0), [p, m] = e.useState(!1), [h, g] = e.useState(void 0), _ = e.useRef({
2586
+ function Qr(t = {}) {
2587
+ let { apiBase: n = Yr, status: r = "pending", conversationId: i, limit: a, headers: o, pollInterval: s = 5e3, enabled: c = !0 } = t, [l, u] = e.useState([]), [d, f] = e.useState(0), [p, m] = e.useState(!1), [h, g] = e.useState(void 0), _ = e.useRef({
2553
2588
  apiBase: n,
2554
2589
  status: r,
2555
2590
  conversationId: i,
@@ -2567,7 +2602,7 @@ function Xr(t = {}) {
2567
2602
  let { apiBase: e, status: t, conversationId: n, limit: r, headers: i } = _.current;
2568
2603
  m(!0), g(void 0);
2569
2604
  try {
2570
- let a = await Yr(Jr(e, "/pending-actions", {
2605
+ let a = await Zr(Xr(e, "/pending-actions", {
2571
2606
  status: t && t !== "all" ? t : void 0,
2572
2607
  conversationId: n,
2573
2608
  limit: r
@@ -2579,9 +2614,9 @@ function Xr(t = {}) {
2579
2614
  m(!1);
2580
2615
  }
2581
2616
  }, []), y = e.useCallback(async (e) => {
2582
- let { apiBase: t, headers: n } = _.current, r = Jr(t, `/pending-actions/${encodeURIComponent(e)}/approve`);
2617
+ let { apiBase: t, headers: n } = _.current, r = Xr(t, `/pending-actions/${encodeURIComponent(e)}/approve`);
2583
2618
  try {
2584
- return await Yr(r, {
2619
+ return await Zr(r, {
2585
2620
  method: "POST",
2586
2621
  body: "{}"
2587
2622
  }, n);
@@ -2589,9 +2624,9 @@ function Xr(t = {}) {
2589
2624
  v();
2590
2625
  }
2591
2626
  }, [v]), b = e.useCallback(async (e, t) => {
2592
- let { apiBase: n, headers: r } = _.current, i = Jr(n, `/pending-actions/${encodeURIComponent(e)}/reject`);
2627
+ let { apiBase: n, headers: r } = _.current, i = Xr(n, `/pending-actions/${encodeURIComponent(e)}/reject`);
2593
2628
  try {
2594
- return await Yr(i, {
2629
+ return await Zr(i, {
2595
2630
  method: "POST",
2596
2631
  body: JSON.stringify(t ? { reason: t } : {})
2597
2632
  }, r);
@@ -2625,7 +2660,7 @@ function Xr(t = {}) {
2625
2660
  }
2626
2661
  //#endregion
2627
2662
  //#region src/AiPendingActionsInbox.tsx
2628
- var Zr = {
2663
+ var $r = {
2629
2664
  pending: {
2630
2665
  variant: "secondary",
2631
2666
  label: "Pending"
@@ -2647,8 +2682,8 @@ var Zr = {
2647
2682
  label: "Rejected"
2648
2683
  }
2649
2684
  };
2650
- function Qr({ status: e }) {
2651
- let t = Zr[e] ?? {
2685
+ function ei({ status: e }) {
2686
+ let t = $r[e] ?? {
2652
2687
  variant: "outline",
2653
2688
  label: e
2654
2689
  };
@@ -2657,7 +2692,7 @@ function Qr({ status: e }) {
2657
2692
  children: t.label
2658
2693
  });
2659
2694
  }
2660
- function $r(e) {
2695
+ function ti(e) {
2661
2696
  if (!e) return "—";
2662
2697
  let t = Date.parse(e);
2663
2698
  if (Number.isNaN(t)) return e;
@@ -2675,7 +2710,7 @@ function $r(e) {
2675
2710
  return e;
2676
2711
  }
2677
2712
  }
2678
- function ei(e) {
2713
+ function ni(e) {
2679
2714
  if (!e) return null;
2680
2715
  try {
2681
2716
  return JSON.parse(e);
@@ -2683,7 +2718,7 @@ function ei(e) {
2683
2718
  return e;
2684
2719
  }
2685
2720
  }
2686
- function ti({ value: e, max: t = 320 }) {
2721
+ function ri({ value: e, max: t = 320 }) {
2687
2722
  let n = typeof e == "string" ? e : JSON.stringify(e, null, 2);
2688
2723
  return n == null || n === "" ? /* @__PURE__ */ K("span", {
2689
2724
  className: "text-muted-foreground text-xs",
@@ -2694,20 +2729,20 @@ function ti({ value: e, max: t = 320 }) {
2694
2729
  children: n
2695
2730
  });
2696
2731
  }
2697
- function ni(e) {
2732
+ function ii(e) {
2698
2733
  switch (e) {
2699
2734
  case "pending": return "pending";
2700
2735
  case "all": return "all";
2701
2736
  case "decided": return "all";
2702
2737
  }
2703
2738
  }
2704
- function ri({ apiBase: t, headers: n, pollInterval: r = 5e3, conversationId: i, variant: a = "card", title: o = "AI Approvals", description: s = "Actions an AI agent proposed that need a human review before execution.", className: c }) {
2705
- let [l, u] = e.useState("pending"), [d, m] = e.useState(null), [h, g] = e.useState(null), [_, w] = e.useState(""), [T, E] = e.useState(null), [D, O] = e.useState(null), [k, A] = e.useState(null), { items: j, isLoading: M, error: N, refresh: P, approve: F, reject: I } = Xr({
2739
+ function ai({ apiBase: t, headers: n, pollInterval: r = 5e3, conversationId: i, variant: a = "card", title: o = "AI Approvals", description: s = "Actions an AI agent proposed that need a human review before execution.", className: c }) {
2740
+ let [l, u] = e.useState("pending"), [d, m] = e.useState(null), [h, g] = e.useState(null), [_, w] = e.useState(""), [T, E] = e.useState(null), [D, O] = e.useState(null), [k, A] = e.useState(null), { items: j, isLoading: M, error: N, refresh: P, approve: F, reject: I } = Qr({
2706
2741
  apiBase: t,
2707
2742
  headers: n,
2708
2743
  pollInterval: r,
2709
2744
  conversationId: i,
2710
- status: ni(l)
2745
+ status: ii(l)
2711
2746
  }), L = e.useMemo(() => l === "decided" ? j.filter((e) => e.status !== "pending") : j, [j, l]), R = e.useMemo(() => d ? j.find((e) => e.id === d) ?? null : null, [d, j]), ae = e.useCallback(async (e) => {
2712
2747
  E(e), O(null);
2713
2748
  try {
@@ -2856,7 +2891,7 @@ function ri({ apiBase: t, headers: n, pollInterval: r = 5e3, conversationId: i,
2856
2891
  className: "text-sm",
2857
2892
  children: e.object_name
2858
2893
  }),
2859
- /* @__PURE__ */ K(B, { children: /* @__PURE__ */ K(Qr, { status: e.status }) }),
2894
+ /* @__PURE__ */ K(B, { children: /* @__PURE__ */ K(ei, { status: e.status }) }),
2860
2895
  /* @__PURE__ */ K(B, {
2861
2896
  className: "text-xs text-muted-foreground",
2862
2897
  children: /* @__PURE__ */ q("span", {
@@ -2864,7 +2899,7 @@ function ri({ apiBase: t, headers: n, pollInterval: r = 5e3, conversationId: i,
2864
2899
  children: [
2865
2900
  /* @__PURE__ */ K(qe, { className: "h-3 w-3" }),
2866
2901
  " ",
2867
- $r(e.proposed_at)
2902
+ ti(e.proposed_at)
2868
2903
  ]
2869
2904
  })
2870
2905
  }),
@@ -2953,14 +2988,14 @@ function ri({ apiBase: t, headers: n, pollInterval: r = 5e3, conversationId: i,
2953
2988
  children: "Status"
2954
2989
  }), /* @__PURE__ */ K("div", {
2955
2990
  className: "mt-1",
2956
- children: /* @__PURE__ */ K(Qr, { status: R.status })
2991
+ children: /* @__PURE__ */ K(ei, { status: R.status })
2957
2992
  })] }),
2958
2993
  /* @__PURE__ */ q("div", { children: [/* @__PURE__ */ K(z, {
2959
2994
  className: "text-xs text-muted-foreground",
2960
2995
  children: "Proposed"
2961
2996
  }), /* @__PURE__ */ K("div", {
2962
2997
  className: "mt-1 text-xs",
2963
- children: $r(R.proposed_at)
2998
+ children: ti(R.proposed_at)
2964
2999
  })] }),
2965
3000
  /* @__PURE__ */ q("div", { children: [/* @__PURE__ */ K(z, {
2966
3001
  className: "text-xs text-muted-foreground",
@@ -2994,21 +3029,21 @@ function ri({ apiBase: t, headers: n, pollInterval: r = 5e3, conversationId: i,
2994
3029
  children: "Tool input"
2995
3030
  }), /* @__PURE__ */ K("div", {
2996
3031
  className: "mt-1.5",
2997
- children: /* @__PURE__ */ K(ti, { value: ei(R.tool_input) })
3032
+ children: /* @__PURE__ */ K(ri, { value: ni(R.tool_input) })
2998
3033
  })] }),
2999
3034
  R.result ? /* @__PURE__ */ q("div", { children: [/* @__PURE__ */ K(z, {
3000
3035
  className: "text-xs",
3001
3036
  children: "Result"
3002
3037
  }), /* @__PURE__ */ K("div", {
3003
3038
  className: "mt-1.5",
3004
- children: /* @__PURE__ */ K(ti, { value: ei(R.result) })
3039
+ children: /* @__PURE__ */ K(ri, { value: ni(R.result) })
3005
3040
  })] }) : null,
3006
3041
  R.error ? /* @__PURE__ */ q("div", { children: [/* @__PURE__ */ K(z, {
3007
3042
  className: "text-xs text-destructive",
3008
3043
  children: "Error"
3009
3044
  }), /* @__PURE__ */ K("div", {
3010
3045
  className: "mt-1.5",
3011
- children: /* @__PURE__ */ K(ti, { value: R.error })
3046
+ children: /* @__PURE__ */ K(ri, { value: R.error })
3012
3047
  })] }) : null,
3013
3048
  R.rejection_reason ? /* @__PURE__ */ q("div", { children: [/* @__PURE__ */ K(z, {
3014
3049
  className: "text-xs",
@@ -3079,14 +3114,14 @@ function ri({ apiBase: t, headers: n, pollInterval: r = 5e3, conversationId: i,
3079
3114
  }
3080
3115
  //#endregion
3081
3116
  //#region src/useHitlInChat.ts
3082
- function ii(e) {
3117
+ function oi(e) {
3083
3118
  return !e || e.length === 0 ? "/api/v1/ai" : e.endsWith("/") ? e.slice(0, -1) : e;
3084
3119
  }
3085
- function ai(e, t) {
3120
+ function si(e, t) {
3086
3121
  let n = { ...e ?? {} };
3087
3122
  return t && (n["Content-Type"] = "application/json"), n;
3088
3123
  }
3089
- async function oi(e) {
3124
+ async function ci(e) {
3090
3125
  let t = await e.text();
3091
3126
  if (!t) return null;
3092
3127
  try {
@@ -3095,8 +3130,8 @@ async function oi(e) {
3095
3130
  return { raw: t };
3096
3131
  }
3097
3132
  }
3098
- function si(t) {
3099
- let { messages: n, apiBase: r, headers: i, onDecided: a, continueConversation: o } = t, s = ii(r), c = e.useMemo(() => {
3133
+ function li(t) {
3134
+ let { messages: n, apiBase: r, headers: i, onDecided: a, continueConversation: o } = t, s = oi(r), c = e.useMemo(() => {
3100
3135
  let e = /* @__PURE__ */ new Map();
3101
3136
  for (let t of n) {
3102
3137
  let n = t.toolInvocations ?? [];
@@ -3139,9 +3174,9 @@ function si(t) {
3139
3174
  let r = `${s}/pending-actions/${encodeURIComponent(l)}/${t ? "approve" : "reject"}`, c = t ? "{}" : JSON.stringify({ reason: n ?? "" }), d = await fetch(r, {
3140
3175
  method: "POST",
3141
3176
  credentials: "include",
3142
- headers: ai(i, !0),
3177
+ headers: si(i, !0),
3143
3178
  body: c
3144
- }), f = await oi(d) ?? {};
3179
+ }), f = await ci(d) ?? {};
3145
3180
  if (!d.ok) {
3146
3181
  let t = typeof f.error == "string" ? f.error : `Approval failed: HTTP ${d.status}`;
3147
3182
  m(e, {
@@ -3168,7 +3203,7 @@ function si(t) {
3168
3203
  state: "success",
3169
3204
  message: `Status: ${p}`
3170
3205
  }), h = !0), a?.(e, f), h && o) {
3171
- let r = ci({
3206
+ let r = ui({
3172
3207
  approved: t,
3173
3208
  status: p,
3174
3209
  toolName: u,
@@ -3203,24 +3238,24 @@ function si(t) {
3203
3238
  isDeciding: f
3204
3239
  };
3205
3240
  }
3206
- function ci(e) {
3241
+ function ui(e) {
3207
3242
  let { approved: t, status: n, toolName: r, pendingActionId: i, outcome: a, reason: o } = e, s = `[HITL ${i}]`;
3208
3243
  if (t && n === "executed") {
3209
3244
  let e = a.result;
3210
- return `${s} The operator approved the \`${r}\` call. It executed successfully with result: ${e == null ? "(no payload)" : typeof e == "string" ? e : li(JSON.stringify(e), 800)}. Acknowledge the outcome concisely and continue the user's task.`;
3245
+ return `${s} The operator approved the \`${r}\` call. It executed successfully with result: ${e == null ? "(no payload)" : typeof e == "string" ? e : di(JSON.stringify(e), 800)}. Acknowledge the outcome concisely and continue the user's task.`;
3211
3246
  }
3212
3247
  if (!t && n === "rejected") return `${s} The operator rejected the \`${r}\` call.${o && o.trim().length > 0 ? ` Reason: ${o}.` : ""} Acknowledge the rejection and ask whether to try a different approach.`;
3213
3248
  if (n === "failed") {
3214
3249
  let e = a.error;
3215
- return `${s} The \`${r}\` call was approved but execution failed: ${typeof e == "string" ? e : li(JSON.stringify(e ?? {}), 400)}. Apologize concisely and offer alternatives.`;
3250
+ return `${s} The \`${r}\` call was approved but execution failed: ${typeof e == "string" ? e : di(JSON.stringify(e ?? {}), 400)}. Apologize concisely and offer alternatives.`;
3216
3251
  }
3217
3252
  }
3218
- function li(e, t) {
3253
+ function di(e, t) {
3219
3254
  return e.length <= t ? e : `${e.slice(0, t - 1)}…`;
3220
3255
  }
3221
3256
  //#endregion
3222
3257
  //#region src/index.tsx
3223
- var ui = e.forwardRef(({ className: t, messages: n = [], placeholder: r = "Type your message...", onSendMessage: i, disabled: a = !1, showTimestamp: o = !1, userAvatarUrl: s, userAvatarFallback: c = "You", assistantAvatarUrl: l, assistantAvatarFallback: u = "AI", maxHeight: d = "500px", ...f }, p) => {
3258
+ var fi = e.forwardRef(({ className: t, messages: n = [], placeholder: r = "Type your message...", onSendMessage: i, disabled: a = !1, showTimestamp: o = !1, userAvatarUrl: s, userAvatarFallback: c = "You", assistantAvatarUrl: l, assistantAvatarFallback: u = "AI", maxHeight: d = "500px", ...f }, p) => {
3224
3259
  let [m, h] = e.useState(""), g = e.useRef(null), _ = e.useRef(null);
3225
3260
  e.useEffect(() => {
3226
3261
  if (g.current) {
@@ -3246,7 +3281,7 @@ var ui = e.forwardRef(({ className: t, messages: n = [], placeholder: r = "Type
3246
3281
  children: n.length === 0 ? /* @__PURE__ */ K("div", {
3247
3282
  className: "flex items-center justify-center h-32 text-muted-foreground text-sm",
3248
3283
  children: "No messages yet. Start a conversation!"
3249
- }) : n.map((e) => /* @__PURE__ */ K(di, {
3284
+ }) : n.map((e) => /* @__PURE__ */ K(pi, {
3250
3285
  message: e,
3251
3286
  showTimestamp: o,
3252
3287
  userAvatarUrl: s,
@@ -3277,8 +3312,8 @@ var ui = e.forwardRef(({ className: t, messages: n = [], placeholder: r = "Type
3277
3312
  })]
3278
3313
  });
3279
3314
  });
3280
- ui.displayName = "Chatbot";
3281
- var di = ({ message: e, showTimestamp: t, userAvatarUrl: n, userAvatarFallback: r, assistantAvatarUrl: i, assistantAvatarFallback: a }) => {
3315
+ fi.displayName = "Chatbot";
3316
+ var pi = ({ message: e, showTimestamp: t, userAvatarUrl: n, userAvatarFallback: r, assistantAvatarUrl: i, assistantAvatarFallback: a }) => {
3282
3317
  let o = e.role === "user";
3283
3318
  if (e.role === "system") return /* @__PURE__ */ K("div", {
3284
3319
  className: "flex justify-center",
@@ -3310,7 +3345,7 @@ var di = ({ message: e, showTimestamp: t, userAvatarUrl: n, userAvatarFallback:
3310
3345
  })]
3311
3346
  })]
3312
3347
  });
3313
- }, fi = e.forwardRef(({ className: e, avatarSrc: t, avatarFallback: n = "AI", ...r }, i) => /* @__PURE__ */ q("div", {
3348
+ }, mi = e.forwardRef(({ className: e, avatarSrc: t, avatarFallback: n = "AI", ...r }, i) => /* @__PURE__ */ q("div", {
3314
3349
  ref: i,
3315
3350
  className: H("flex gap-3", e),
3316
3351
  ...r,
@@ -3332,6 +3367,6 @@ var di = ({ message: e, showTimestamp: t, userAvatarUrl: n, userAvatarFallback:
3332
3367
  })
3333
3368
  })]
3334
3369
  }));
3335
- fi.displayName = "TypingIndicator";
3370
+ mi.displayName = "TypingIndicator";
3336
3371
  //#endregion
3337
- export { Kr as AIElements, ri as AiPendingActionsInbox, ui as Chatbot, $ as ChatbotEnhanced, Ur as FloatingChatbot, Gt as FloatingChatbotPanel, Vt as FloatingChatbotProvider, Wt as FloatingChatbotTrigger, fi as TypingIndicator, qt as humanizeToolName, Yt as summarizeChatError, Ft as uiMessageToChatMessage, It as uiMessagesToChatMessages, Jt as unwrapToolResult, zt as useAgents, Ht as useFloatingChatbot, si as useHitlInChat, Y as useObjectChat, Xr as usePendingActions };
3372
+ export { Jr as AIElements, ai as AiPendingActionsInbox, fi as Chatbot, $ as ChatbotEnhanced, Gr as FloatingChatbot, Kt as FloatingChatbotPanel, Ht as FloatingChatbotProvider, Gt as FloatingChatbotTrigger, mi as TypingIndicator, Jt as humanizeToolName, Xt as summarizeChatError, It as uiMessageToChatMessage, Lt as uiMessagesToChatMessages, Yt as unwrapToolResult, Bt as useAgents, Ut as useFloatingChatbot, li as useHitlInChat, J as useObjectChat, Qr as usePendingActions };