besser-agentic-framework-ui 0.1.0 → 0.2.1

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.
@@ -1,10 +1,10 @@
1
- import { useCallback as e, useEffect as t, useId as n, useMemo as r, useRef as i, useState as a } from "react";
2
- import o from "react-markdown";
3
- import s from "remark-gfm";
4
- import c from "dompurify";
5
- import { jsx as l, jsxs as u } from "react/jsx-runtime";
1
+ import { createContext as e, useCallback as t, useContext as n, useEffect as r, useId as i, useMemo as a, useRef as o, useState as s } from "react";
2
+ import c from "react-markdown";
3
+ import l from "remark-gfm";
4
+ import u from "dompurify";
5
+ import { Fragment as d, jsx as f, jsxs as p } from "react/jsx-runtime";
6
6
  //#region src/types/payload.ts
7
- var d = {
7
+ var m = {
8
8
  USER_MESSAGE: "user_message",
9
9
  USER_VOICE: "user_voice",
10
10
  USER_FILE: "user_file",
@@ -23,10 +23,11 @@ var d = {
23
23
  AGENT_REPLY_REASONING_STEP: "agent_reply_reasoning_step",
24
24
  AGENT_REPLY_TASK_LIST_UPDATE: "agent_reply_task_list_update",
25
25
  AGENT_REPLY_AUDIO: "agent_reply_audio",
26
- AGENT_REPLY_UI: "agent_reply_ui",
27
- USER_UPDATE_UI: "user_update_ui",
26
+ AGENT_REPLY_GUI: "agent_reply_gui",
27
+ AGENT_REPLY_GUI_UPDATE: "agent_reply_gui_update",
28
+ USER_GUI_EVENT: "user_gui_event",
28
29
  FETCH_USER_MESSAGES: "fetch_user_messages"
29
- }, f = {
30
+ }, h = {
30
31
  REASONING_STARTED: "reasoning_started",
31
32
  REASONING_FINISHED: "reasoning_finished",
32
33
  LLM_TEXT: "llm_text",
@@ -37,27 +38,27 @@ var d = {
37
38
  TASK_SKIPPED: "task_skipped",
38
39
  PUSHBACK: "pushback",
39
40
  MAX_STEPS: "max_steps"
40
- }, p = {
41
+ }, g = {
41
42
  PENDING: "pending",
42
43
  IN_PROGRESS: "in_progress",
43
44
  COMPLETED: "completed",
44
45
  SKIPPED: "skipped"
45
- }, m = "reasoning_trace";
46
- function h(e) {
47
- return e.kind === f.REASONING_STARTED;
46
+ }, _ = "reasoning_trace";
47
+ function v(e) {
48
+ return e.kind === h.REASONING_STARTED;
48
49
  }
49
- function g(e) {
50
- return e.kind === f.REASONING_FINISHED;
50
+ function y(e) {
51
+ return e.kind === h.REASONING_FINISHED;
51
52
  }
52
- function _(e) {
53
- return e.steps.filter((e) => !h(e) && !g(e));
53
+ function b(e) {
54
+ return e.steps.filter((e) => !v(e) && !y(e));
54
55
  }
55
- function v(e) {
56
- return _(e).length === 0;
56
+ function x(e) {
57
+ return b(e).length === 0;
57
58
  }
58
59
  //#endregion
59
60
  //#region src/utils/contentDetect.ts
60
- var y = [
61
+ var S = [
61
62
  /^#{1,6}\s+\S/m,
62
63
  /^\s*[-*+]\s+\S/m,
63
64
  /^\s*\d+\.\s+\S/m,
@@ -70,10 +71,10 @@ var y = [
70
71
  /^\|[^\n]+\|\s*$/m,
71
72
  /^---+\s*$/m
72
73
  ];
73
- function b(e) {
74
- return !e || e.length < 2 ? !1 : y.some((t) => t.test(e));
74
+ function C(e) {
75
+ return !e || e.length < 2 ? !1 : S.some((t) => t.test(e));
75
76
  }
76
- var x = RegExp("^\\s*(" + [
77
+ var w = RegExp("^\\s*(" + [
77
78
  "function\\s",
78
79
  "def\\s",
79
80
  "class\\s",
@@ -95,20 +96,24 @@ var x = RegExp("^\\s*(" + [
95
96
  "<\\?php\\b",
96
97
  "<!DOCTYPE\\s"
97
98
  ].join("|") + ")", "m");
98
- function S(e) {
99
+ function T(e) {
99
100
  if (!e || e.length < 8) return !1;
100
101
  let t = e.split("\n");
101
- return t.length < 2 ? !1 : !!(x.test(e) || (e.match(/[{}();=]/g) ?? []).length / e.length > .05 && t.length >= 3);
102
+ return t.length < 2 ? !1 : !!(w.test(e) || (e.match(/[{}();=]/g) ?? []).length / e.length > .05 && t.length >= 3);
102
103
  }
103
- function C(e) {
104
- return b(e) ? "markdown" : S(e) ? "code" : "plain";
104
+ function E(e) {
105
+ return C(e) ? "markdown" : T(e) ? "code" : "plain";
105
106
  }
106
107
  //#endregion
107
108
  //#region src/components/GUIRenderer.tsx
108
- function w(e) {
109
+ var D = e(null);
110
+ function O(e) {
109
111
  return e.replace(/_([a-z])/g, (e, t) => t.toUpperCase());
110
112
  }
111
- var T = new Set(["unit_size", "icon_size"]), E = new Set([
113
+ function k(e) {
114
+ return e.replace(/\s*!important\s*$/, "");
115
+ }
116
+ var A = new Set(["unit_size", "icon_size"]), j = new Set([
112
117
  "color_palette",
113
118
  "primary_color",
114
119
  "line_color",
@@ -117,36 +122,59 @@ var T = new Set(["unit_size", "icon_size"]), E = new Set([
117
122
  "bar_color",
118
123
  "label_color",
119
124
  "fill_color"
120
- ]), D = {
125
+ ]), M = {
121
126
  background_color: "background",
122
127
  text_color: "color"
123
- }, O = new Set(["layout_type"]), k = new Set(["p_type", "alignment"]);
124
- function A(e) {
128
+ }, N = new Set(["layout_type", "alignment"]), P = new Set(["p_type"]);
129
+ function F(e) {
125
130
  if (!e) return {};
126
131
  let t = {};
127
- if (e.size) for (let [n, r] of Object.entries(e.size)) !r || T.has(n) || (t[w(n)] = r);
128
- if (e.position) for (let [n, r] of Object.entries(e.position)) !r || k.has(n) || (n === "display" ? r === "table" || r === "table-row" ? (t.display = "flex", t.flexWrap = "wrap", t.alignItems = "stretch") : r === "table-cell" ? (t.display = "flex", t.flex = "1", t.flexDirection = "column", t.height = "auto") : t.display = r : t[w(n)] = r);
129
- if (e.color) for (let [n, r] of Object.entries(e.color)) !r || E.has(n) || (t[D[n] ?? w(n)] = r);
132
+ if (e.size) for (let [n, r] of Object.entries(e.size)) !r || A.has(n) || (t[O(n)] = typeof r == "string" ? k(r) : r);
133
+ if (e.position) for (let [n, r] of Object.entries(e.position)) !r || P.has(n) || (n === "alignment" ? t.textAlign = typeof r == "string" ? k(r) : r : n === "display" ? r === "table" || r === "table-row" ? (t.display = "flex", t.flexWrap = "wrap", t.alignItems = "stretch") : r === "table-cell" ? (t.display = "flex", t.flex = "1", t.flexDirection = "column", t.height = "auto") : t.display = typeof r == "string" ? k(r) : r : t[O(n)] = typeof r == "string" ? k(r) : r);
134
+ if (e.color) for (let [n, r] of Object.entries(e.color)) !r || j.has(n) || (t[M[n] ?? O(n)] = typeof r == "string" ? k(r) : r);
130
135
  if (e.layout) {
131
136
  let n = e.layout.layout_type;
132
137
  n === "flex" ? t.display = "flex" : n === "grid" && (t.display = "grid");
133
- for (let [n, r] of Object.entries(e.layout)) !r || O.has(n) || (t[w(n)] = r);
138
+ for (let [n, r] of Object.entries(e.layout)) !r || N.has(n) || (t[O(n)] = typeof r == "string" ? k(r) : r);
134
139
  }
135
140
  return t;
136
141
  }
137
- function j(e, t) {
142
+ function ee(e) {
143
+ let t = e.trim().toLowerCase();
144
+ if (t.includes("gradient")) return !1;
145
+ if (t === "transparent" || t === "none" || t === "initial" || t === "" || t === "white" || t === "#fff" || t === "#ffffff") return !0;
146
+ let n = t.match(/^#([0-9a-f]{6})$/);
147
+ if (n) {
148
+ let e = parseInt(n[1], 16), t = e >> 16 & 255, r = e >> 8 & 255, i = e & 255;
149
+ return (t + r + i) / 3 > 200;
150
+ }
151
+ let r = t.match(/^#([0-9a-f])([0-9a-f])([0-9a-f])$/);
152
+ if (r) {
153
+ let e = parseInt(r[1] + r[1], 16), t = parseInt(r[2] + r[2], 16), n = parseInt(r[3] + r[3], 16);
154
+ return (e + t + n) / 3 > 200;
155
+ }
156
+ return !1;
157
+ }
158
+ function I(e) {
159
+ let t = {
160
+ fontFamily: "inherit",
161
+ ...e
162
+ }, n = typeof t.background == "string" ? t.background : typeof t.backgroundColor == "string" ? t.backgroundColor : null;
163
+ return (n === null || ee(n)) && (delete t.background, delete t.backgroundColor, delete t.color), t;
164
+ }
165
+ function te(e, t, n = !1) {
138
166
  if (!Array.isArray(e)) return "";
139
- let n = "";
140
- for (let r of e) {
141
- if (!r.selectors?.length || !r.style) continue;
142
- let e = { ...r.style }, i = e.display;
143
- i === "table" || i === "table-row" ? (e.display = "flex", e["flex-wrap"] = "wrap") : i === "table-cell" && (e.display = "flex", e["flex-direction"] = "column", e.flex = "1", delete e.height, delete e.width);
144
- let a = Object.entries(e).map(([e, t]) => ` ${e}: ${t};`).join("\n"), o = (e) => `${e} {\n${a}\n}`, s = r.selectors.map((e) => `.${t} ${e}`).join(", ");
145
- r.atRuleType === "media" && r.mediaText ? n += `@media ${r.mediaText} {\n${o(s)}\n}\n` : n += o(s) + "\n";
167
+ let r = "";
168
+ for (let i of e) {
169
+ if (!i.selectors?.length || !i.style) continue;
170
+ let e = { ...i.style }, a = e.display;
171
+ a === "table" || a === "table-row" ? (e.display = "flex", e["flex-wrap"] = "wrap") : a === "table-cell" && (e.display = "flex", e["flex-direction"] = "column", e.flex = "1", delete e.height, delete e.width), n && (delete e.background, delete e["background-color"], delete e.color);
172
+ let o = Object.entries(e).map(([e, t]) => ` ${e}: ${t};`).join("\n"), s = (e) => `${e} {\n${o}\n}`, c = i.selectors.map((e) => `.${t} ${e}`).join(", ");
173
+ i.atRuleType === "media" && i.mediaText ? r += `@media ${i.mediaText} {\n${s(c)}\n}\n` : r += s(c) + "\n";
146
174
  }
147
- return n;
175
+ return r;
148
176
  }
149
- function M(e) {
177
+ function ne(e) {
150
178
  let t = [], n = e.custom_attributes?.series;
151
179
  if (typeof n == "string") try {
152
180
  t = JSON.parse(n);
@@ -286,36 +314,981 @@ function M(e) {
286
314
  };
287
315
  }
288
316
  }
289
- function N({ el: e }) {
290
- let n = i(null);
291
- t(() => {
292
- let t = n.current;
293
- if (!t) return;
294
- let r = !0, { traces: i, layout: a } = M(e);
295
- return import("plotly.js-dist-min").then((e) => {
296
- !r || !t || e.newPlot(t, i, a, {
317
+ var L = null, R = null;
318
+ function re() {
319
+ return L ? Promise.resolve(L) : (R ||= import("plotly.js-dist-min").then((e) => (L = e, e)), R);
320
+ }
321
+ function ie({ el: e }) {
322
+ let t = o(null);
323
+ r(() => {
324
+ let n = t.current;
325
+ if (!n) return;
326
+ let r = !0, { traces: i, layout: a } = ne(e);
327
+ return re().then((e) => {
328
+ !r || !n || e.newPlot(n, i, a, {
297
329
  responsive: !0,
298
330
  displayModeBar: !1
299
331
  });
300
332
  }), () => {
301
- r = !1, import("plotly.js-dist-min").then((e) => {
302
- t && e.purge(t);
333
+ r = !1, L && n ? L.purge(n) : R && R.then((e) => {
334
+ n && e.purge(n);
303
335
  });
304
336
  };
305
337
  }, [e.name, e.type]);
306
- let r = A(e.styling);
307
- return /* @__PURE__ */ l("div", {
338
+ let n = F(e.styling);
339
+ return /* @__PURE__ */ f("div", {
308
340
  id: e.component_id ?? void 0,
309
341
  className: (e.css_classes ?? []).join(" ") || void 0,
310
342
  style: {
311
343
  minHeight: "300px",
344
+ ...n
345
+ },
346
+ ref: t
347
+ });
348
+ }
349
+ var z = {
350
+ info: {
351
+ bg: "#eff6ff",
352
+ border: "#bfdbfe",
353
+ text: "#1e40af",
354
+ icon: "ℹ"
355
+ },
356
+ success: {
357
+ bg: "#f0fdf4",
358
+ border: "#bbf7d0",
359
+ text: "#166534",
360
+ icon: "✓"
361
+ },
362
+ warning: {
363
+ bg: "#fffbeb",
364
+ border: "#fde68a",
365
+ text: "#92400e",
366
+ icon: "⚠"
367
+ },
368
+ error: {
369
+ bg: "#fef2f2",
370
+ border: "#fecaca",
371
+ text: "#991b1b",
372
+ icon: "✕"
373
+ }
374
+ };
375
+ function ae({ el: e, id: t, className: n, style: r }) {
376
+ let [i, a] = s(!1);
377
+ if (i) return null;
378
+ let o = z[e.severity ?? "info"] ?? z.info;
379
+ return /* @__PURE__ */ p("div", {
380
+ id: t,
381
+ className: n,
382
+ role: "alert",
383
+ style: {
384
+ display: "flex",
385
+ alignItems: "flex-start",
386
+ gap: "10px",
387
+ padding: "10px 14px",
388
+ borderRadius: "6px",
389
+ border: `1px solid ${o.border}`,
390
+ background: o.bg,
391
+ color: o.text,
392
+ fontSize: "0.88em",
312
393
  ...r
313
394
  },
314
- ref: n
395
+ children: [
396
+ /* @__PURE__ */ f("span", {
397
+ style: {
398
+ fontWeight: 700,
399
+ flexShrink: 0
400
+ },
401
+ children: o.icon
402
+ }),
403
+ /* @__PURE__ */ p("div", {
404
+ style: { flex: 1 },
405
+ children: [e.title && /* @__PURE__ */ f("div", {
406
+ style: {
407
+ fontWeight: 600,
408
+ marginBottom: 2
409
+ },
410
+ children: e.title
411
+ }), /* @__PURE__ */ f("div", { children: e.content })]
412
+ }),
413
+ e.dismissible && /* @__PURE__ */ f("button", {
414
+ onClick: () => a(!0),
415
+ style: {
416
+ background: "none",
417
+ border: "none",
418
+ cursor: "pointer",
419
+ color: o.text,
420
+ padding: 0,
421
+ lineHeight: 1
422
+ },
423
+ "aria-label": "Dismiss",
424
+ children: "×"
425
+ })
426
+ ]
427
+ });
428
+ }
429
+ function oe({ el: e, id: t, onInteract: n }) {
430
+ let [r, i] = s(!!e.default_value);
431
+ return /* @__PURE__ */ f("div", {
432
+ style: { marginBottom: "4px" },
433
+ children: /* @__PURE__ */ p("label", {
434
+ style: {
435
+ display: "inline-flex",
436
+ alignItems: "center",
437
+ gap: "8px",
438
+ cursor: e.disabled ? "default" : "pointer",
439
+ userSelect: "none"
440
+ },
441
+ children: [e.label && /* @__PURE__ */ f("span", {
442
+ style: {
443
+ fontSize: "0.875em",
444
+ fontWeight: 500,
445
+ color: "#374151"
446
+ },
447
+ children: e.label
448
+ }), /* @__PURE__ */ p("span", {
449
+ style: {
450
+ position: "relative",
451
+ display: "inline-block",
452
+ width: "44px",
453
+ height: "24px",
454
+ flexShrink: 0
455
+ },
456
+ children: [
457
+ /* @__PURE__ */ f("input", {
458
+ type: "checkbox",
459
+ id: t,
460
+ name: e.name,
461
+ checked: r,
462
+ disabled: e.disabled,
463
+ style: {
464
+ opacity: 0,
465
+ width: 0,
466
+ height: 0,
467
+ position: "absolute"
468
+ },
469
+ onChange: (r) => {
470
+ i(r.target.checked), n?.(JSON.stringify({
471
+ elementId: t ?? e.name,
472
+ name: e.name,
473
+ fieldType: e.field_type,
474
+ label: e.label || void 0,
475
+ action: "onChange",
476
+ value: r.target.checked
477
+ }));
478
+ }
479
+ }),
480
+ /* @__PURE__ */ f("span", { style: {
481
+ position: "absolute",
482
+ inset: 0,
483
+ background: r ? "#2563eb" : "#cbd5e1",
484
+ borderRadius: "24px",
485
+ transition: "background 0.2s",
486
+ pointerEvents: "none"
487
+ } }),
488
+ /* @__PURE__ */ f("span", { style: {
489
+ position: "absolute",
490
+ top: "3px",
491
+ left: r ? "23px" : "3px",
492
+ width: "18px",
493
+ height: "18px",
494
+ borderRadius: "50%",
495
+ background: "#fff",
496
+ transition: "left 0.2s",
497
+ boxShadow: "0 1px 3px rgba(0,0,0,0.2)",
498
+ pointerEvents: "none"
499
+ } })
500
+ ]
501
+ })]
502
+ })
503
+ });
504
+ }
505
+ function se({ el: e, id: t, onInteract: n }) {
506
+ let [r, i] = s(typeof e.default_value == "number" ? e.default_value : e.min_value ?? 0);
507
+ return /* @__PURE__ */ p("div", {
508
+ style: {
509
+ display: "flex",
510
+ alignItems: "center",
511
+ gap: "10px"
512
+ },
513
+ children: [/* @__PURE__ */ f("input", {
514
+ type: "range",
515
+ id: t,
516
+ name: e.name,
517
+ min: e.min_value ?? 0,
518
+ max: e.max_value ?? 100,
519
+ step: e.step ?? 1,
520
+ value: r,
521
+ disabled: e.disabled,
522
+ style: { flex: 1 },
523
+ onChange: (r) => {
524
+ let a = Number(r.target.value);
525
+ i(a), n?.(JSON.stringify({
526
+ elementId: t ?? e.name,
527
+ name: e.name,
528
+ fieldType: e.field_type,
529
+ label: e.label || void 0,
530
+ action: "onChange",
531
+ value: a
532
+ }));
533
+ }
534
+ }), /* @__PURE__ */ f("span", {
535
+ style: {
536
+ minWidth: "2.5em",
537
+ textAlign: "right",
538
+ fontSize: "0.875em",
539
+ color: "#374151"
540
+ },
541
+ children: r
542
+ })]
543
+ });
544
+ }
545
+ function ce({ el: e, id: t, className: n, onInteract: r }) {
546
+ let [i, a] = s(typeof e.default_value == "number" ? e.default_value : 0), [o, c] = s(0), l = e.max_value ?? 5;
547
+ return /* @__PURE__ */ p("div", {
548
+ id: t,
549
+ className: n,
550
+ style: {
551
+ display: "flex",
552
+ gap: "2px"
553
+ },
554
+ children: [/* @__PURE__ */ f("input", {
555
+ type: "hidden",
556
+ name: e.name,
557
+ "data-value-type": "number",
558
+ value: String(i)
559
+ }), Array.from({ length: l }, (e, t) => t + 1).map((n) => /* @__PURE__ */ f("button", {
560
+ type: "button",
561
+ "aria-label": `${n} star${n === 1 ? "" : "s"}`,
562
+ style: {
563
+ background: "none",
564
+ border: "none",
565
+ padding: "0 2px",
566
+ cursor: e.disabled ? "default" : "pointer",
567
+ fontSize: "1.5em",
568
+ color: n <= (o || i) ? "#f59e0b" : "#d1d5db",
569
+ transition: "color 0.1s"
570
+ },
571
+ disabled: e.disabled,
572
+ onClick: () => {
573
+ let o = n === i ? 0 : n;
574
+ a(o), r?.(JSON.stringify({
575
+ elementId: t ?? e.name,
576
+ name: e.name,
577
+ fieldType: e.field_type,
578
+ label: e.label || void 0,
579
+ action: "onChange",
580
+ value: o
581
+ }));
582
+ },
583
+ onMouseEnter: () => !e.disabled && c(n),
584
+ onMouseLeave: () => c(0),
585
+ children: "★"
586
+ }, n))]
587
+ });
588
+ }
589
+ function le({ el: e, id: t, className: n, onInteract: r }) {
590
+ let [i, a] = s([]), [o, c] = s(""), l = (n) => {
591
+ let o = n.trim();
592
+ if (o && !i.includes(o)) {
593
+ let n = [...i, o];
594
+ a(n), r?.(JSON.stringify({
595
+ elementId: t ?? e.name,
596
+ name: e.name,
597
+ fieldType: e.field_type,
598
+ label: e.label || void 0,
599
+ action: "onChange",
600
+ value: n
601
+ }));
602
+ }
603
+ c("");
604
+ }, u = (n) => {
605
+ let o = i.filter((e) => e !== n);
606
+ a(o), r?.(JSON.stringify({
607
+ elementId: t ?? e.name,
608
+ name: e.name,
609
+ fieldType: e.field_type,
610
+ label: e.label || void 0,
611
+ action: "onChange",
612
+ value: o
613
+ }));
614
+ };
615
+ return /* @__PURE__ */ p("div", {
616
+ id: t,
617
+ className: [n, "gui-tags-container"].filter(Boolean).join(" "),
618
+ style: {
619
+ display: "flex",
620
+ flexWrap: "wrap",
621
+ alignItems: "center",
622
+ gap: "4px",
623
+ padding: "4px 8px",
624
+ border: "1px solid #cbd5e1",
625
+ borderRadius: "4px",
626
+ minHeight: "38px"
627
+ },
628
+ children: [i.map((e) => /* @__PURE__ */ p("span", {
629
+ className: "gui-chip",
630
+ style: {
631
+ display: "inline-flex",
632
+ alignItems: "center",
633
+ gap: "4px",
634
+ padding: "2px 8px",
635
+ background: "#eff6ff",
636
+ color: "#1d4ed8",
637
+ borderRadius: "12px",
638
+ fontSize: "0.82em"
639
+ },
640
+ children: [e, /* @__PURE__ */ f("button", {
641
+ type: "button",
642
+ onClick: () => u(e),
643
+ style: {
644
+ background: "none",
645
+ border: "none",
646
+ cursor: "pointer",
647
+ color: "inherit",
648
+ padding: 0,
649
+ lineHeight: 1
650
+ },
651
+ children: "×"
652
+ })]
653
+ }, e)), /* @__PURE__ */ f("input", {
654
+ type: "text",
655
+ value: o,
656
+ placeholder: i.length === 0 ? e.placeholder ?? e.description ?? "Add tags…" : void 0,
657
+ disabled: e.disabled,
658
+ style: {
659
+ border: "none",
660
+ outline: "none",
661
+ fontFamily: "inherit",
662
+ fontSize: "inherit",
663
+ flex: "1 1 80px",
664
+ minWidth: "80px",
665
+ padding: "2px 0"
666
+ },
667
+ onChange: (e) => c(e.target.value),
668
+ onKeyDown: (e) => {
669
+ (e.key === "Enter" || e.key === ",") && (e.preventDefault(), l(o)), e.key === "Backspace" && !o && i.length && u(i[i.length - 1]);
670
+ },
671
+ onBlur: () => {
672
+ o && l(o);
673
+ }
674
+ })]
675
+ });
676
+ }
677
+ function ue({ el: e, id: t, className: n, onInteract: r }) {
678
+ let i = Math.max(2, Math.min(8, e.max_value ?? 6)), [a, c] = s(() => Array(i).fill("")), l = o(Array(i).fill(null)), u = (n, o) => {
679
+ let s = o.replace(/\D/g, "").slice(-1), u = [...a];
680
+ u[n] = s, c(u), r?.(JSON.stringify({
681
+ elementId: t ?? e.name,
682
+ name: e.name,
683
+ fieldType: e.field_type,
684
+ label: e.label || void 0,
685
+ action: "onChange",
686
+ value: u.join("")
687
+ })), s && n < i - 1 && l.current[n + 1]?.focus();
688
+ }, d = (e, t) => {
689
+ t.key === "Backspace" && !a[e] && e > 0 && l.current[e - 1]?.focus();
690
+ };
691
+ return /* @__PURE__ */ f("div", {
692
+ id: t,
693
+ className: n,
694
+ style: {
695
+ display: "flex",
696
+ gap: "8px"
697
+ },
698
+ children: a.map((t, n) => /* @__PURE__ */ f("input", {
699
+ ref: (e) => {
700
+ l.current[n] = e;
701
+ },
702
+ type: "text",
703
+ inputMode: "numeric",
704
+ maxLength: 1,
705
+ value: t,
706
+ disabled: e.disabled,
707
+ onChange: (e) => u(n, e.target.value),
708
+ onKeyDown: (e) => d(n, e),
709
+ style: {
710
+ width: "40px",
711
+ height: "44px",
712
+ textAlign: "center",
713
+ border: "1px solid #cbd5e1",
714
+ borderRadius: "6px",
715
+ fontSize: "1.25em",
716
+ fontFamily: "inherit"
717
+ }
718
+ }, n))
315
719
  });
316
720
  }
317
- function P(e, t, n) {
318
- let r = A(e.styling), i = e.component_id ?? void 0, a = (e.css_classes ?? []).join(" ") || void 0;
721
+ function de({ el: e, id: t, className: n, onInteract: r }) {
722
+ let [i, a] = s(""), [o, c] = s(""), l = {
723
+ padding: "6px 10px",
724
+ border: "1px solid #cbd5e1",
725
+ borderRadius: "4px",
726
+ fontFamily: "inherit"
727
+ }, u = (n, i) => r?.(JSON.stringify({
728
+ elementId: t ?? e.name,
729
+ name: e.name,
730
+ fieldType: e.field_type,
731
+ label: e.label || void 0,
732
+ action: "onChange",
733
+ value: {
734
+ from: n,
735
+ to: i
736
+ }
737
+ }));
738
+ return /* @__PURE__ */ p("div", {
739
+ id: t,
740
+ className: n,
741
+ style: {
742
+ display: "flex",
743
+ alignItems: "center",
744
+ gap: "8px",
745
+ flexWrap: "wrap"
746
+ },
747
+ children: [
748
+ /* @__PURE__ */ f("input", {
749
+ type: "date",
750
+ value: i,
751
+ max: o || void 0,
752
+ disabled: e.disabled,
753
+ style: l,
754
+ onChange: (e) => {
755
+ a(e.target.value), u(e.target.value, o);
756
+ }
757
+ }),
758
+ /* @__PURE__ */ f("span", {
759
+ style: {
760
+ color: "#94a3b8",
761
+ fontSize: "0.9em"
762
+ },
763
+ children: "to"
764
+ }),
765
+ /* @__PURE__ */ f("input", {
766
+ type: "date",
767
+ value: o,
768
+ min: i || void 0,
769
+ disabled: e.disabled,
770
+ style: l,
771
+ onChange: (e) => {
772
+ c(e.target.value), u(i, e.target.value);
773
+ }
774
+ })
775
+ ]
776
+ });
777
+ }
778
+ function fe({ el: e, id: t, className: n, onInteract: r }) {
779
+ let i = e.options ?? [], [a, c] = s(() => typeof e.default_value == "string" && e.default_value ? e.default_value.split(",").map((e) => e.trim()).filter(Boolean) : []), l = o(null), u = (n) => {
780
+ let i = a.includes(n) ? a.filter((e) => e !== n) : [...a, n];
781
+ c(i), l.current && (l.current.value = JSON.stringify(i)), r?.(JSON.stringify({
782
+ elementId: t ?? e.name,
783
+ name: e.name,
784
+ fieldType: e.field_type,
785
+ label: e.label || void 0,
786
+ action: "onChange",
787
+ value: i
788
+ }));
789
+ };
790
+ return /* @__PURE__ */ p("div", {
791
+ id: t,
792
+ className: n,
793
+ style: {
794
+ display: "flex",
795
+ flexDirection: "column",
796
+ gap: "6px"
797
+ },
798
+ children: [
799
+ /* @__PURE__ */ f("input", {
800
+ type: "hidden",
801
+ ref: l,
802
+ name: e.name,
803
+ "data-value-type": "json",
804
+ defaultValue: JSON.stringify(a)
805
+ }),
806
+ a.length > 0 && /* @__PURE__ */ f("div", {
807
+ style: {
808
+ display: "flex",
809
+ flexWrap: "wrap",
810
+ gap: "4px"
811
+ },
812
+ children: a.map((t) => /* @__PURE__ */ p("span", {
813
+ className: "gui-chip",
814
+ style: {
815
+ display: "inline-flex",
816
+ alignItems: "center",
817
+ gap: "4px",
818
+ padding: "2px 8px",
819
+ background: "#eff6ff",
820
+ color: "#1d4ed8",
821
+ borderRadius: "12px",
822
+ fontSize: "0.82em"
823
+ },
824
+ children: [i.find((e) => e.value === t)?.label ?? t, /* @__PURE__ */ f("button", {
825
+ type: "button",
826
+ onClick: () => u(t),
827
+ disabled: e.disabled,
828
+ style: {
829
+ background: "none",
830
+ border: "none",
831
+ cursor: "pointer",
832
+ color: "inherit",
833
+ padding: 0,
834
+ lineHeight: 1
835
+ },
836
+ children: "×"
837
+ })]
838
+ }, t))
839
+ }),
840
+ /* @__PURE__ */ f("div", {
841
+ className: "gui-ms-list",
842
+ style: {
843
+ border: "1px solid #cbd5e1",
844
+ borderRadius: "4px",
845
+ overflow: "hidden"
846
+ },
847
+ children: i.map((t, n) => {
848
+ let r = a.includes(t.value);
849
+ return /* @__PURE__ */ p("div", {
850
+ className: `gui-ms-item${r ? " gui-ms-item--selected" : ""}`,
851
+ onClick: () => !e.disabled && u(t.value),
852
+ style: {
853
+ padding: "6px 10px",
854
+ cursor: e.disabled ? "default" : "pointer",
855
+ background: r ? "#dbeafe" : n % 2 == 0 ? "#fff" : "#f8fafc",
856
+ color: r ? "#1d4ed8" : "#374151",
857
+ fontWeight: r ? 500 : 400,
858
+ borderBottom: n < i.length - 1 ? "1px solid #e2e8f0" : "none",
859
+ userSelect: "none",
860
+ display: "flex",
861
+ justifyContent: "space-between",
862
+ alignItems: "center"
863
+ },
864
+ children: [/* @__PURE__ */ f("span", { children: t.label }), r && /* @__PURE__ */ f("span", {
865
+ style: {
866
+ color: "#2563eb",
867
+ fontWeight: 700
868
+ },
869
+ children: "✓"
870
+ })]
871
+ }, n);
872
+ })
873
+ })
874
+ ]
875
+ });
876
+ }
877
+ function B({ el: e, id: t, className: n, onInteract: r }) {
878
+ let i = e.options ?? [], [a, c] = s(() => Object.fromEntries(i.map((e) => [e.value, !1]))), l = o(null), u = e.disabled ?? !1, d = (n, i) => {
879
+ let o = {
880
+ ...a,
881
+ [n]: i
882
+ };
883
+ c(o), l.current && (l.current.value = JSON.stringify(o)), r?.(JSON.stringify({
884
+ elementId: t ?? e.name,
885
+ name: e.name,
886
+ fieldType: e.field_type,
887
+ label: e.label || void 0,
888
+ action: "onChange",
889
+ value: o
890
+ }));
891
+ };
892
+ return /* @__PURE__ */ p("div", {
893
+ id: t,
894
+ className: n,
895
+ style: {
896
+ display: "flex",
897
+ flexDirection: "column",
898
+ gap: "6px"
899
+ },
900
+ children: [/* @__PURE__ */ f("input", {
901
+ type: "hidden",
902
+ ref: l,
903
+ name: e.name,
904
+ "data-value-type": "json",
905
+ defaultValue: JSON.stringify(a)
906
+ }), i.map((e, t) => /* @__PURE__ */ p("label", {
907
+ style: {
908
+ display: "flex",
909
+ alignItems: "center",
910
+ gap: "6px",
911
+ cursor: u ? "default" : "pointer"
912
+ },
913
+ children: [/* @__PURE__ */ f("input", {
914
+ type: "checkbox",
915
+ checked: a[e.value] ?? !1,
916
+ disabled: u,
917
+ onChange: (t) => d(e.value, t.target.checked)
918
+ }), e.label]
919
+ }, t))]
920
+ });
921
+ }
922
+ var V = {
923
+ Text: "text",
924
+ Password: "password",
925
+ Email: "email",
926
+ Number: "number",
927
+ Date: "date",
928
+ Time: "time",
929
+ Color: "color",
930
+ File: "file",
931
+ Search: "search",
932
+ URL: "url",
933
+ Tel: "tel",
934
+ Hidden: "hidden",
935
+ Range: "range",
936
+ Checkbox: "checkbox"
937
+ };
938
+ function pe({ el: e, onInteract: t }) {
939
+ let n = e.custom_attributes ?? {}, r = e.label ?? n["data-label"] ?? void 0, i = e.placeholder ?? n["data-placeholder"] ?? e.description ?? e.name, a = e.required ?? n["data-required"] === "true", o = e.min_value ?? (n["data-min"] == null ? void 0 : Number(n["data-min"])), s = e.max_value ?? (n["data-max"] == null ? void 0 : Number(n["data-max"])), c = e.step ?? (n["data-step"] == null ? void 0 : Number(n["data-step"])), l = e.default_value;
940
+ l == null && n["data-default-checked"] != null && (l = String(n["data-default-checked"]).toLowerCase() === "true");
941
+ let u = e.options ?? [];
942
+ u.length === 0 && n["data-options"] && (u = String(n["data-options"]).split(",").map((e) => e.trim()).filter(Boolean).map((e) => ({
943
+ label: e,
944
+ value: e
945
+ })));
946
+ let m = {
947
+ ...e,
948
+ label: r,
949
+ placeholder: i,
950
+ required: a,
951
+ min_value: o,
952
+ max_value: s,
953
+ step: c,
954
+ default_value: l,
955
+ options: u
956
+ }, h = F(e.styling), g = e.component_id ?? void 0, _ = (e.css_classes ?? []).join(" ") || void 0, v = e.field_type ?? "Text", y = i, b = e.disabled ?? !1, x = e.readonly ?? !1, S = {
957
+ padding: "6px 10px",
958
+ border: "1px solid #cbd5e1",
959
+ borderRadius: "4px",
960
+ fontFamily: "inherit",
961
+ width: "100%",
962
+ boxSizing: "border-box",
963
+ ...h
964
+ }, C = (n) => t?.(JSON.stringify({
965
+ elementId: g ?? e.name,
966
+ name: e.name,
967
+ fieldType: v,
968
+ label: r || void 0,
969
+ action: "onChange",
970
+ value: n
971
+ })), w = (e) => r ? /* @__PURE__ */ p("div", {
972
+ style: {
973
+ display: "flex",
974
+ flexDirection: "column",
975
+ gap: "4px"
976
+ },
977
+ children: [/* @__PURE__ */ p("label", {
978
+ htmlFor: g,
979
+ style: {
980
+ fontSize: "0.875em",
981
+ fontWeight: 500,
982
+ color: "#374151"
983
+ },
984
+ children: [r, a && /* @__PURE__ */ f("span", {
985
+ style: {
986
+ color: "#ef4444",
987
+ marginLeft: 2
988
+ },
989
+ children: "*"
990
+ })]
991
+ }), e]
992
+ }) : /* @__PURE__ */ f(d, { children: e });
993
+ switch (v) {
994
+ case "TextArea":
995
+ case "RichText": return w(/* @__PURE__ */ f("textarea", {
996
+ id: g,
997
+ name: e.name,
998
+ className: _,
999
+ style: {
1000
+ ...S,
1001
+ minHeight: "80px",
1002
+ resize: "vertical"
1003
+ },
1004
+ placeholder: y,
1005
+ required: a,
1006
+ disabled: b,
1007
+ readOnly: x,
1008
+ defaultValue: l,
1009
+ onBlur: (e) => C(e.target.value)
1010
+ }));
1011
+ case "Dropdown": return w(/* @__PURE__ */ p("select", {
1012
+ id: g,
1013
+ name: e.name,
1014
+ className: _,
1015
+ style: S,
1016
+ required: a,
1017
+ disabled: b,
1018
+ defaultValue: l,
1019
+ onChange: (e) => C(e.target.value),
1020
+ children: [/* @__PURE__ */ f("option", {
1021
+ value: "",
1022
+ children: "— Select —"
1023
+ }), u.map((e, t) => /* @__PURE__ */ f("option", {
1024
+ value: e.value,
1025
+ children: e.label
1026
+ }, t))]
1027
+ }));
1028
+ case "MultiSelect": return w(/* @__PURE__ */ f(fe, {
1029
+ el: m,
1030
+ id: g,
1031
+ className: _,
1032
+ onInteract: t
1033
+ }));
1034
+ case "RadioGroup": return w(/* @__PURE__ */ f("div", {
1035
+ role: "radiogroup",
1036
+ style: {
1037
+ display: "flex",
1038
+ flexDirection: "column",
1039
+ gap: "6px"
1040
+ },
1041
+ children: u.map((t, n) => /* @__PURE__ */ p("label", {
1042
+ style: {
1043
+ display: "flex",
1044
+ alignItems: "center",
1045
+ gap: "6px",
1046
+ cursor: b ? "default" : "pointer"
1047
+ },
1048
+ children: [/* @__PURE__ */ f("input", {
1049
+ type: "radio",
1050
+ name: e.name,
1051
+ value: t.value,
1052
+ required: a,
1053
+ disabled: b,
1054
+ onChange: () => C(t.value)
1055
+ }), t.label]
1056
+ }, n))
1057
+ }));
1058
+ case "CheckboxGroup": return w(/* @__PURE__ */ f(B, {
1059
+ el: m,
1060
+ id: g,
1061
+ className: _,
1062
+ onInteract: t
1063
+ }));
1064
+ case "Toggle": return /* @__PURE__ */ f(oe, {
1065
+ el: m,
1066
+ id: g,
1067
+ onInteract: t
1068
+ });
1069
+ case "Slider": return w(/* @__PURE__ */ f(se, {
1070
+ el: m,
1071
+ id: g,
1072
+ onInteract: t
1073
+ }));
1074
+ case "Spinner": return w(/* @__PURE__ */ f("input", {
1075
+ type: "number",
1076
+ id: g,
1077
+ name: e.name,
1078
+ className: _,
1079
+ style: S,
1080
+ placeholder: y,
1081
+ required: a,
1082
+ disabled: b,
1083
+ readOnly: x,
1084
+ min: o,
1085
+ max: s,
1086
+ step: c ?? 1,
1087
+ defaultValue: l,
1088
+ onBlur: (e) => C(Number(e.target.value))
1089
+ }));
1090
+ case "Rating": return w(/* @__PURE__ */ f(ce, {
1091
+ el: m,
1092
+ id: g,
1093
+ className: _,
1094
+ onInteract: t
1095
+ }));
1096
+ case "Tags": return w(/* @__PURE__ */ f(le, {
1097
+ el: m,
1098
+ id: g,
1099
+ className: _,
1100
+ onInteract: t
1101
+ }));
1102
+ case "OTP": return w(/* @__PURE__ */ f(ue, {
1103
+ el: m,
1104
+ id: g,
1105
+ className: _,
1106
+ onInteract: t
1107
+ }));
1108
+ case "DateRange": return w(/* @__PURE__ */ f(de, {
1109
+ el: m,
1110
+ id: g,
1111
+ className: _,
1112
+ onInteract: t
1113
+ }));
1114
+ case "DateTime": return w(/* @__PURE__ */ f("input", {
1115
+ type: "datetime-local",
1116
+ id: g,
1117
+ name: e.name,
1118
+ className: _,
1119
+ style: S,
1120
+ required: a,
1121
+ disabled: b,
1122
+ readOnly: x,
1123
+ defaultValue: l,
1124
+ onBlur: (e) => C(e.target.value)
1125
+ }));
1126
+ case "Color": return w(/* @__PURE__ */ f("input", {
1127
+ type: "color",
1128
+ id: g,
1129
+ name: e.name,
1130
+ className: _,
1131
+ style: {
1132
+ width: "48px",
1133
+ height: "36px",
1134
+ padding: "2px",
1135
+ border: "1px solid #cbd5e1",
1136
+ borderRadius: "4px",
1137
+ cursor: b ? "default" : "pointer"
1138
+ },
1139
+ disabled: b,
1140
+ defaultValue: l || "#000000",
1141
+ onChange: (e) => C(e.target.value)
1142
+ }));
1143
+ case "Checkbox": return /* @__PURE__ */ f("div", {
1144
+ style: h,
1145
+ children: /* @__PURE__ */ p("label", {
1146
+ htmlFor: g,
1147
+ style: {
1148
+ display: "inline-flex",
1149
+ alignItems: "center",
1150
+ gap: "6px",
1151
+ cursor: b ? "default" : "pointer",
1152
+ userSelect: "none",
1153
+ fontSize: "0.875em",
1154
+ fontWeight: 500,
1155
+ color: "#374151"
1156
+ },
1157
+ children: [/* @__PURE__ */ f("input", {
1158
+ type: "checkbox",
1159
+ id: g,
1160
+ name: e.name,
1161
+ className: _,
1162
+ required: a,
1163
+ disabled: b,
1164
+ defaultChecked: !!l,
1165
+ onChange: (e) => C(e.target.checked)
1166
+ }), r && /* @__PURE__ */ p("span", { children: [r, a && /* @__PURE__ */ f("span", {
1167
+ style: {
1168
+ color: "#ef4444",
1169
+ marginLeft: 2
1170
+ },
1171
+ children: "*"
1172
+ })] })]
1173
+ })
1174
+ });
1175
+ case "File": {
1176
+ let t = n["data-accept"] || void 0, r = e.multiple === !0 || n["data-multiple"] === "true";
1177
+ return w(/* @__PURE__ */ f("input", {
1178
+ type: "file",
1179
+ id: g,
1180
+ name: e.name,
1181
+ className: _,
1182
+ style: S,
1183
+ required: a,
1184
+ disabled: b,
1185
+ accept: t,
1186
+ multiple: r,
1187
+ onChange: (e) => {
1188
+ let t = e.target.files;
1189
+ if (!t || t.length === 0) {
1190
+ C(null);
1191
+ return;
1192
+ }
1193
+ let n = Array.from(t).map((e) => e.name);
1194
+ C(r ? n : n[0]);
1195
+ }
1196
+ }));
1197
+ }
1198
+ case "ImageUpload": return w(/* @__PURE__ */ f("input", {
1199
+ type: "file",
1200
+ id: g,
1201
+ name: e.name,
1202
+ className: _,
1203
+ style: S,
1204
+ required: a,
1205
+ disabled: b,
1206
+ accept: "image/*",
1207
+ onChange: (e) => C(e.target.files?.[0]?.name)
1208
+ }));
1209
+ default: return w(/* @__PURE__ */ f("input", {
1210
+ type: V[v] ?? v.toLowerCase(),
1211
+ id: g,
1212
+ name: e.name,
1213
+ className: _,
1214
+ style: S,
1215
+ placeholder: y,
1216
+ required: a,
1217
+ disabled: b,
1218
+ readOnly: x,
1219
+ min: o,
1220
+ max: s,
1221
+ step: c,
1222
+ defaultValue: l,
1223
+ onBlur: (e) => C(e.target.value)
1224
+ }));
1225
+ }
1226
+ }
1227
+ function me({ el: e, id: t, className: r, style: i }) {
1228
+ let a = n(D);
1229
+ return a ? /* @__PURE__ */ p("div", {
1230
+ id: t,
1231
+ className: ["gui-agent-widget", r].filter(Boolean).join(" "),
1232
+ style: {
1233
+ display: "flex",
1234
+ flexDirection: "column",
1235
+ border: "1px solid #e2e8f0",
1236
+ borderRadius: 8,
1237
+ overflow: "hidden",
1238
+ background: "#fff",
1239
+ ...i
1240
+ },
1241
+ children: [/* @__PURE__ */ p("div", {
1242
+ style: {
1243
+ padding: "10px 14px",
1244
+ background: "#f8fafc",
1245
+ borderBottom: "1px solid #e2e8f0",
1246
+ fontWeight: 600,
1247
+ fontSize: "0.9em",
1248
+ display: "flex",
1249
+ alignItems: "center",
1250
+ gap: 8,
1251
+ flexShrink: 0
1252
+ },
1253
+ children: [
1254
+ /* @__PURE__ */ f("span", {
1255
+ style: { fontSize: "1.1em" },
1256
+ children: "🤖"
1257
+ }),
1258
+ e.agent_title ?? e.agent_name ?? "Agent",
1259
+ /* @__PURE__ */ f("span", { style: {
1260
+ marginLeft: "auto",
1261
+ width: 8,
1262
+ height: 8,
1263
+ borderRadius: "50%",
1264
+ background: a.status === "connected" ? "#22c55e" : "#f59e0b",
1265
+ flexShrink: 0
1266
+ } })
1267
+ ]
1268
+ }), /* @__PURE__ */ f($, {
1269
+ messages: a.messages,
1270
+ setMessages: a.setMessages,
1271
+ status: a.status,
1272
+ send: a.send
1273
+ })]
1274
+ }) : /* @__PURE__ */ f("div", {
1275
+ id: t,
1276
+ className: r,
1277
+ style: {
1278
+ display: "flex",
1279
+ alignItems: "center",
1280
+ justifyContent: "center",
1281
+ padding: 24,
1282
+ color: "#94a3b8",
1283
+ border: "1px solid #e2e8f0",
1284
+ borderRadius: 8,
1285
+ ...i
1286
+ },
1287
+ children: "Chat widget not connected"
1288
+ });
1289
+ }
1290
+ function H(e, t, n, r = !1) {
1291
+ let i = F(e.styling), a = e.component_id ?? void 0, o = (e.css_classes ?? []).join(" ") || void 0;
319
1292
  switch (e.type) {
320
1293
  case "Text": {
321
1294
  let t = new Set([
@@ -332,102 +1305,141 @@ function P(e, t, n) {
332
1305
  "li",
333
1306
  "td",
334
1307
  "th"
335
- ]);
336
- return /* @__PURE__ */ l(e.tag_name && t.has(e.tag_name) ? e.tag_name : "p", {
337
- id: i,
338
- className: a,
339
- style: r,
1308
+ ]), n = e.tag_name && t.has(e.tag_name) ? e.tag_name : "p";
1309
+ return n === "p" && (i.display === "flex" || i.display === "grid") && (n = "div"), /* @__PURE__ */ f(n, {
1310
+ id: a,
1311
+ className: o,
1312
+ style: r ? I(i) : i,
340
1313
  children: e.content
341
1314
  }, e.name);
342
1315
  }
343
- case "Link": return /* @__PURE__ */ l("a", {
344
- id: i,
345
- className: a,
346
- style: r,
1316
+ case "Link": return /* @__PURE__ */ f("a", {
1317
+ id: a,
1318
+ className: o,
1319
+ style: r ? I(i) : {
1320
+ fontFamily: "inherit",
1321
+ ...i
1322
+ },
347
1323
  href: e.url ?? "#",
348
1324
  target: e.target ?? "_self",
349
1325
  rel: e.rel ?? (e.target === "_blank" ? "noopener noreferrer" : void 0),
350
1326
  onClick: (r) => {
351
1327
  e.url && n?.(e.url) ? r.preventDefault() : t?.(JSON.stringify({
352
- elementId: i ?? e.name,
1328
+ elementId: a ?? e.name,
1329
+ name: e.name,
1330
+ label: e.label || void 0,
353
1331
  action: "onClick",
354
1332
  value: e.url
355
1333
  }));
356
1334
  },
357
1335
  children: e.label
358
1336
  }, e.name);
359
- case "Button": return /* @__PURE__ */ l("button", {
360
- id: i,
361
- className: a,
362
- style: r,
363
- type: "button",
364
- onClick: () => {
365
- e.actionType === "navigate" && e.url && n?.(e.url) || t?.(JSON.stringify({
366
- elementId: i ?? e.name,
367
- action: "onClick"
368
- }));
369
- },
370
- children: e.label
371
- }, e.name);
372
- case "Image": return /* @__PURE__ */ l("img", {
373
- id: i,
374
- className: a,
375
- style: r,
1337
+ case "Button": {
1338
+ let r = e.buttonType?.toLowerCase() ?? "";
1339
+ return /* @__PURE__ */ f("button", {
1340
+ id: a,
1341
+ className: [
1342
+ "gui-form-btn",
1343
+ r === "outlined button" ? "gui-form-btn--outlined" : r === "flat button" ? "gui-form-btn--flat" : r === "floating action button" ? "gui-form-btn--fab" : "gui-form-btn--submit",
1344
+ o
1345
+ ].filter(Boolean).join(" "),
1346
+ style: {
1347
+ fontFamily: "inherit",
1348
+ lineHeight: "inherit",
1349
+ ...i
1350
+ },
1351
+ type: "button",
1352
+ onClick: () => {
1353
+ e.actionType?.toLowerCase() === "navigate" && e.url && n?.(e.url) || t?.(JSON.stringify({
1354
+ elementId: a ?? e.name,
1355
+ name: e.name,
1356
+ label: e.label || void 0,
1357
+ actionType: e.actionType || void 0,
1358
+ action: "onClick"
1359
+ }));
1360
+ },
1361
+ children: e.label
1362
+ }, e.name);
1363
+ }
1364
+ case "Image": return /* @__PURE__ */ f("img", {
1365
+ id: a,
1366
+ className: o,
1367
+ style: i,
376
1368
  src: e.source ?? "",
377
1369
  alt: e.name,
378
1370
  onError: (e) => {
379
1371
  e.target.style.display = "none";
380
1372
  }
381
1373
  }, e.name);
382
- case "InputField": return /* @__PURE__ */ l("input", {
383
- id: i,
384
- name: e.name,
385
- className: a,
386
- style: {
387
- padding: "6px 10px",
388
- border: "1px solid #cbd5e1",
389
- borderRadius: "4px",
390
- ...r
391
- },
392
- type: (e.field_type ?? "text").toLowerCase(),
393
- placeholder: e.description || e.name,
394
- onBlur: (n) => t?.(JSON.stringify({
395
- elementId: i ?? e.name,
396
- action: "onChange",
397
- value: n.target.value
398
- }))
1374
+ case "InputField": return /* @__PURE__ */ f(pe, {
1375
+ el: e,
1376
+ onInteract: t
399
1377
  }, e.name);
400
- case "Form": return /* @__PURE__ */ l("form", {
401
- id: i,
402
- className: a,
1378
+ case "Form": return /* @__PURE__ */ p("form", {
1379
+ id: a,
1380
+ className: o,
403
1381
  style: {
404
1382
  display: "flex",
405
1383
  flexDirection: "column",
406
1384
  gap: "8px",
407
- ...r
1385
+ ...r ? I(i) : i
408
1386
  },
409
1387
  onSubmit: (n) => {
410
1388
  n.preventDefault();
411
- let r = Object.fromEntries(new FormData(n.currentTarget));
412
- t?.(JSON.stringify({
413
- elementId: i ?? e.name,
1389
+ let r = n.currentTarget, i = {};
1390
+ for (let [e, t] of new FormData(r).entries()) {
1391
+ let n = r.querySelector(`[name="${e}"][data-value-type="json"]`), a = r.querySelector(`[name="${e}"][data-value-type="number"]`);
1392
+ if (n && typeof t == "string") try {
1393
+ i[e] = JSON.parse(t);
1394
+ } catch {
1395
+ i[e] = t;
1396
+ }
1397
+ else a && typeof t == "string" ? i[e] = Number(t) : i[e] = t;
1398
+ }
1399
+ r.querySelectorAll("input[type=\"checkbox\"]").forEach((e) => {
1400
+ e.name && (i[e.name] = e.checked);
1401
+ }), r.querySelectorAll("input[type=\"radio\"]").forEach((e) => {
1402
+ e.name && !(e.name in i) && (i[e.name] = "");
1403
+ }), t?.(JSON.stringify({
1404
+ elementId: a ?? e.name,
1405
+ name: e.name,
414
1406
  action: "onSubmit",
415
- value: r
1407
+ value: i
416
1408
  }));
417
1409
  },
418
- children: (e.inputFields ?? []).map((e) => P(e, t, n))
1410
+ children: [(e.inputFields ?? []).map((e) => H(e, t, n, r)), /* @__PURE__ */ p("div", {
1411
+ style: {
1412
+ display: "flex",
1413
+ gap: "8px",
1414
+ marginTop: "4px"
1415
+ },
1416
+ children: [/* @__PURE__ */ f("button", {
1417
+ type: "submit",
1418
+ className: "gui-form-btn gui-form-btn--submit",
1419
+ children: e.submit_label ?? "Submit"
1420
+ }), e.show_cancel && /* @__PURE__ */ f("button", {
1421
+ type: "button",
1422
+ className: "gui-form-btn gui-form-btn--cancel",
1423
+ onClick: () => t?.(JSON.stringify({
1424
+ elementId: a ?? e.name,
1425
+ name: e.name,
1426
+ action: "onCancel"
1427
+ })),
1428
+ children: e.cancel_label ?? "Cancel"
1429
+ })]
1430
+ })]
419
1431
  }, e.name);
420
- case "Menu": return /* @__PURE__ */ l(e.tag_name && e.tag_name === "nav" ? "nav" : "div", {
421
- id: i,
422
- className: a,
423
- style: r,
424
- children: /* @__PURE__ */ l("ul", {
1432
+ case "Menu": return /* @__PURE__ */ f(e.tag_name && e.tag_name === "nav" ? "nav" : "div", {
1433
+ id: a,
1434
+ className: o,
1435
+ style: r ? I(i) : i,
1436
+ children: /* @__PURE__ */ f("ul", {
425
1437
  style: {
426
1438
  listStyle: "none",
427
1439
  padding: 0,
428
1440
  margin: 0
429
1441
  },
430
- children: (e.menuItems ?? []).map((r, i) => /* @__PURE__ */ l("li", { children: /* @__PURE__ */ l("a", {
1442
+ children: (e.menuItems ?? []).map((r, i) => /* @__PURE__ */ f("li", { children: /* @__PURE__ */ f("a", {
431
1443
  href: r.url ?? "#",
432
1444
  target: r.target,
433
1445
  rel: r.target === "_blank" ? "noopener noreferrer" : void 0,
@@ -435,6 +1447,8 @@ function P(e, t, n) {
435
1447
  onClick: (i) => {
436
1448
  r.url && n?.(r.url) ? i.preventDefault() : t?.(JSON.stringify({
437
1449
  elementId: e.component_id ?? e.name,
1450
+ name: e.name,
1451
+ label: r.label,
438
1452
  action: "onClick",
439
1453
  value: r.url
440
1454
  }));
@@ -443,14 +1457,14 @@ function P(e, t, n) {
443
1457
  }) }, i))
444
1458
  })
445
1459
  }, e.name);
446
- case "DataList": return /* @__PURE__ */ l("ul", {
447
- id: i,
448
- className: a,
1460
+ case "DataList": return /* @__PURE__ */ f("ul", {
1461
+ id: a,
1462
+ className: o,
449
1463
  style: {
450
1464
  padding: 0,
451
- ...r
1465
+ ...r ? I(i) : i
452
1466
  },
453
- children: (e.list_sources ?? []).map((e, t) => /* @__PURE__ */ u("li", {
1467
+ children: (e.list_sources ?? []).map((e, t) => /* @__PURE__ */ p("li", {
454
1468
  style: {
455
1469
  padding: "4px 0",
456
1470
  color: "#94a3b8",
@@ -463,36 +1477,42 @@ function P(e, t, n) {
463
1477
  ]
464
1478
  }, t))
465
1479
  }, e.name);
1480
+ case "Alert": return /* @__PURE__ */ f(ae, {
1481
+ el: e,
1482
+ id: a,
1483
+ className: o,
1484
+ style: i
1485
+ }, e.name);
466
1486
  case "EmbeddedContent": {
467
1487
  let t = e.source ?? e.extra_props?.src ?? "";
468
- return t ? /* @__PURE__ */ l("iframe", {
469
- id: i,
470
- className: a,
1488
+ return t ? /* @__PURE__ */ f("iframe", {
1489
+ id: a,
1490
+ className: o,
471
1491
  style: {
472
1492
  width: "100%",
473
1493
  height: "300px",
474
1494
  border: "none",
475
- ...r
1495
+ ...i
476
1496
  },
477
1497
  src: t,
478
1498
  title: e.name,
479
1499
  loading: "lazy",
480
1500
  sandbox: "allow-scripts allow-same-origin"
481
- }, e.name) : /* @__PURE__ */ l("div", {
482
- id: i,
483
- className: a,
484
- style: r,
1501
+ }, e.name) : /* @__PURE__ */ f("div", {
1502
+ id: a,
1503
+ className: o,
1504
+ style: i,
485
1505
  children: "[Embedded Content]"
486
1506
  }, e.name);
487
1507
  }
488
1508
  case "ViewContainer": {
489
- let o = { ...r };
1509
+ let s = { ...i };
490
1510
  if (e.layout) {
491
1511
  let t = e.layout.layout_type;
492
- t === "flex" ? o.display = "flex" : t === "grid" && (o.display = "grid");
493
- for (let [t, n] of Object.entries(e.layout)) !n || t === "layout_type" || (o[w(t)] = n);
1512
+ t === "flex" ? s.display = "flex" : t === "grid" && (s.display = "grid");
1513
+ for (let [t, n] of Object.entries(e.layout)) !n || t === "layout_type" || t === "alignment" || (s[O(t)] = typeof n == "string" ? k(n) : n);
494
1514
  }
495
- let s = new Set([
1515
+ let c = r ? I(s) : s, l = new Set([
496
1516
  "div",
497
1517
  "section",
498
1518
  "article",
@@ -504,39 +1524,39 @@ function P(e, t, n) {
504
1524
  "ul",
505
1525
  "ol"
506
1526
  ]);
507
- return /* @__PURE__ */ l(e.tag_name && s.has(e.tag_name) ? e.tag_name : "div", {
508
- id: i,
509
- className: a,
510
- style: o,
511
- children: (e.view_elements ?? []).map((e) => P(e, t, n))
1527
+ return /* @__PURE__ */ f(e.tag_name && l.has(e.tag_name) ? e.tag_name : "div", {
1528
+ id: a,
1529
+ className: o,
1530
+ style: c,
1531
+ children: (e.view_elements ?? []).map((e) => H(e, t, n, r))
512
1532
  }, e.name);
513
1533
  }
514
1534
  case "LineChart":
515
1535
  case "BarChart":
516
1536
  case "PieChart":
517
1537
  case "RadarChart":
518
- case "RadialBarChart": return /* @__PURE__ */ l(N, { el: e }, e.name);
519
- case "Table": return /* @__PURE__ */ u("div", {
520
- id: i,
521
- className: a,
1538
+ case "RadialBarChart": return /* @__PURE__ */ f(ie, { el: e }, e.name);
1539
+ case "Table": return /* @__PURE__ */ p("div", {
1540
+ id: a,
1541
+ className: o,
522
1542
  style: {
523
1543
  overflowX: "auto",
524
- ...r
1544
+ ...r ? I(i) : i
525
1545
  },
526
- children: [e.title && /* @__PURE__ */ l("div", {
1546
+ children: [e.title && /* @__PURE__ */ f("div", {
527
1547
  style: {
528
1548
  fontWeight: 600,
529
1549
  marginBottom: 8,
530
1550
  fontSize: "0.95em"
531
1551
  },
532
1552
  children: e.title
533
- }), /* @__PURE__ */ u("table", {
1553
+ }), /* @__PURE__ */ p("table", {
534
1554
  style: {
535
1555
  borderCollapse: "collapse",
536
1556
  width: "100%",
537
1557
  fontSize: "0.88em"
538
1558
  },
539
- children: [e.show_header !== !1 && (e.columns ?? []).length > 0 && /* @__PURE__ */ l("thead", { children: /* @__PURE__ */ l("tr", { children: (e.columns ?? []).map((e, t) => /* @__PURE__ */ l("th", {
1559
+ children: [e.show_header !== !1 && (e.columns ?? []).length > 0 && /* @__PURE__ */ f("thead", { children: /* @__PURE__ */ f("tr", { children: (e.columns ?? []).map((e, t) => /* @__PURE__ */ f("th", {
540
1560
  style: {
541
1561
  padding: "6px 10px",
542
1562
  borderBottom: "2px solid #e2e8f0",
@@ -544,7 +1564,7 @@ function P(e, t, n) {
544
1564
  fontWeight: 600
545
1565
  },
546
1566
  children: e.label
547
- }, t)) }) }), /* @__PURE__ */ l("tbody", { children: /* @__PURE__ */ l("tr", { children: /* @__PURE__ */ l("td", {
1567
+ }, t)) }) }), /* @__PURE__ */ f("tbody", { children: /* @__PURE__ */ f("tr", { children: /* @__PURE__ */ f("td", {
548
1568
  colSpan: (e.columns ?? []).length || 1,
549
1569
  style: {
550
1570
  padding: "8px 10px",
@@ -555,216 +1575,226 @@ function P(e, t, n) {
555
1575
  }) }) })]
556
1576
  })]
557
1577
  }, e.name);
558
- case "MetricCard": return /* @__PURE__ */ u("div", {
559
- id: i,
560
- className: ["gui-metric-card", a].filter(Boolean).join(" "),
561
- style: r,
1578
+ case "MetricCard": return /* @__PURE__ */ p("div", {
1579
+ id: a,
1580
+ className: ["gui-metric-card", o].filter(Boolean).join(" "),
1581
+ style: r ? I(i) : i,
562
1582
  children: [
563
- /* @__PURE__ */ l("div", {
1583
+ /* @__PURE__ */ f("div", {
564
1584
  className: "gui-metric-card__title",
565
1585
  children: e.metric_title ?? e.name
566
1586
  }),
567
- /* @__PURE__ */ l("div", {
1587
+ /* @__PURE__ */ f("div", {
568
1588
  className: "gui-metric-card__value",
569
1589
  style: { color: e.value_color ?? "#2c3e50" },
570
1590
  children: "—"
571
1591
  }),
572
- /* @__PURE__ */ l("div", {
1592
+ /* @__PURE__ */ f("div", {
573
1593
  className: "gui-metric-card__format",
574
1594
  children: e.format
575
1595
  })
576
1596
  ]
577
1597
  }, e.name);
578
- case "AgentComponent": return /* @__PURE__ */ u("div", {
579
- id: i,
580
- className: ["gui-agent-component", a].filter(Boolean).join(" "),
581
- style: r,
582
- children: [/* @__PURE__ */ l("span", { children: "🤖" }), /* @__PURE__ */ u("span", { children: [e.agent_title ?? e.agent_name ?? "Agent", " Widget"] })]
1598
+ case "AgentComponent": return /* @__PURE__ */ f(me, {
1599
+ el: e,
1600
+ id: a,
1601
+ className: o,
1602
+ style: i
583
1603
  }, e.name);
584
1604
  default: return null;
585
1605
  }
586
1606
  }
587
- function F({ content: i, onInteract: o }) {
588
- let s = "gui-s" + n().replace(/[^a-zA-Z0-9]/g, ""), c = r(() => {
1607
+ function U({ content: e, onInteract: n, messageId: o, chatProps: c, chatMode: l = !1 }) {
1608
+ let u = "gui-s" + i().replace(/[^a-zA-Z0-9]/g, ""), d = a(() => {
589
1609
  try {
590
- let e = typeof i == "string" ? i : JSON.stringify(i);
591
- return JSON.parse(e);
1610
+ let t = typeof e == "string" ? e : JSON.stringify(e);
1611
+ return JSON.parse(t);
592
1612
  } catch {
593
1613
  return null;
594
1614
  }
595
- }, [i]), d = r(() => (c?.modules ?? []).flatMap((e) => e.screens), [c]), [f, p] = a(0), m = e((e) => {
596
- let t = d.findIndex((t) => t.name === e);
597
- if (t >= 0) return p(t), !0;
598
- let n = d.findIndex((t) => t.route_path === e);
599
- if (n >= 0) return p(n), !0;
1615
+ }, [e]), m = a(() => (d?.modules ?? []).flatMap((e) => e.screens), [d]), h = t((e) => {
1616
+ if (n) {
1617
+ if (!o) {
1618
+ n(e);
1619
+ return;
1620
+ }
1621
+ try {
1622
+ let t = JSON.parse(e);
1623
+ n(JSON.stringify({
1624
+ ...t,
1625
+ messageId: o
1626
+ }));
1627
+ } catch {
1628
+ n(e);
1629
+ }
1630
+ }
1631
+ }, [n, o]), [g, _] = s(0), v = t((e) => {
1632
+ let t = m.findIndex((t) => t.name === e);
1633
+ if (t >= 0) return _(t), !0;
1634
+ let n = m.findIndex((t) => t.route_path === e);
1635
+ if (n >= 0) return _(n), !0;
600
1636
  if (e === "/" || e === "") {
601
- let e = d.findIndex((e) => e.is_main_page);
602
- return p(e >= 0 ? e : 0), !0;
1637
+ let e = m.findIndex((e) => e.is_main_page);
1638
+ return _(e >= 0 ? e : 0), !0;
603
1639
  }
604
1640
  return !1;
605
- }, [d]);
606
- t(() => {
607
- let e = d.findIndex((e) => e.is_main_page);
608
- p(e >= 0 ? e : 0);
609
- }, [d]);
610
- let h = r(() => c?.style_entries ? j(c.style_entries, s) : "", [c, s]);
611
- if (t(() => {
612
- if (!h) return;
1641
+ }, [m]);
1642
+ r(() => {
1643
+ let e = m.findIndex((e) => e.is_main_page);
1644
+ _(e >= 0 ? e : 0);
1645
+ }, [m]);
1646
+ let y = a(() => d?.style_entries ? te(d.style_entries, u, l) : "", [
1647
+ d,
1648
+ u,
1649
+ l
1650
+ ]);
1651
+ if (r(() => {
1652
+ if (!y) return;
613
1653
  let e = document.createElement("style");
614
- return e.setAttribute("data-gui-scope", s), e.textContent = h, document.head.appendChild(e), () => {
1654
+ return e.setAttribute("data-gui-scope", u), e.textContent = y, document.head.appendChild(e), () => {
615
1655
  document.head.removeChild(e);
616
1656
  };
617
- }, [h, s]), !c) return /* @__PURE__ */ l("p", {
1657
+ }, [y, u]), !d) return /* @__PURE__ */ f("p", {
618
1658
  className: "msg-text--muted",
619
1659
  children: "[Invalid UI definition]"
620
1660
  });
621
- let g = d[f];
622
- if (!g) return /* @__PURE__ */ l("p", {
1661
+ let b = m[g];
1662
+ if (!b) return /* @__PURE__ */ f("p", {
623
1663
  className: "msg-text--muted",
624
1664
  children: "[No screens defined]"
625
1665
  });
626
- let _ = c.modules.length > 1, v = d.length > 1;
627
- return /* @__PURE__ */ u("div", {
628
- className: "gui-renderer",
629
- children: [
630
- /* @__PURE__ */ u("div", {
631
- className: "gui-renderer__header",
632
- children: [/* @__PURE__ */ l("span", {
633
- className: "gui-renderer__title",
634
- children: c.name
635
- }), c.description && /* @__PURE__ */ l("span", {
636
- className: "gui-renderer__description",
637
- children: c.description
638
- })]
639
- }),
640
- (_ || v) && /* @__PURE__ */ l("div", {
1666
+ let x = d.modules.length > 1, S = m.length > 1;
1667
+ return /* @__PURE__ */ f(D.Provider, {
1668
+ value: c ?? null,
1669
+ children: /* @__PURE__ */ p("div", {
1670
+ className: `gui-renderer${l ? " gui-renderer--chat" : ""}`,
1671
+ children: [(x || S) && /* @__PURE__ */ f("div", {
641
1672
  className: "gui-renderer__tabs",
642
1673
  role: "tablist",
643
- children: d.map((e, t) => /* @__PURE__ */ u("button", {
1674
+ children: m.map((e, t) => /* @__PURE__ */ p("button", {
644
1675
  role: "tab",
645
- "aria-selected": t === f,
646
- className: `gui-renderer__tab${t === f ? " gui-renderer__tab--active" : ""}`,
647
- onClick: () => p(t),
648
- children: [e.name, e.is_main_page && /* @__PURE__ */ l("span", {
1676
+ "aria-selected": t === g,
1677
+ className: `gui-renderer__tab${t === g ? " gui-renderer__tab--active" : ""}`,
1678
+ onClick: () => _(t),
1679
+ children: [e.name, e.is_main_page && /* @__PURE__ */ f("span", {
649
1680
  className: "gui-renderer__tab-badge",
650
1681
  children: "home"
651
1682
  })]
652
1683
  }, t))
653
- }),
654
- /* @__PURE__ */ l("div", {
655
- className: `gui-renderer__screen ${s}`,
656
- children: (g.view_elements ?? []).map((e) => P(e, o, m))
657
- })
658
- ]
1684
+ }), /* @__PURE__ */ f("div", {
1685
+ className: `gui-renderer__screen ${u}`,
1686
+ children: (b.view_elements ?? []).map((e) => H(e, h, v, l))
1687
+ })]
1688
+ })
659
1689
  });
660
1690
  }
661
1691
  //#endregion
662
1692
  //#region src/components/ReasoningTrace.tsx
663
- var I = new Set([
664
- f.TASK_ADDED,
665
- f.TASK_COMPLETED,
666
- f.TASK_SKIPPED
667
- ]), L = new Set([
1693
+ var he = new Set([
1694
+ h.TASK_ADDED,
1695
+ h.TASK_COMPLETED,
1696
+ h.TASK_SKIPPED
1697
+ ]), ge = new Set([
668
1698
  "add_tasks",
669
1699
  "complete_task",
670
1700
  "skip_task"
671
1701
  ]);
672
- function R(e) {
673
- if (e.kind !== f.LLM_TOOL_CALLS) return !1;
1702
+ function _e(e) {
1703
+ if (e.kind !== h.LLM_TOOL_CALLS) return !1;
674
1704
  let t = e.details?.tool_calls ?? [];
675
- return t.length === 0 ? !1 : t.every((e) => e.name !== void 0 && L.has(e.name));
1705
+ return t.length === 0 ? !1 : t.every((e) => e.name !== void 0 && ge.has(e.name));
676
1706
  }
677
- function z({ trace: e }) {
678
- let [n, r] = a(e.inProgress);
679
- t(() => {
680
- e.inProgress || r(!1);
1707
+ function W({ trace: e }) {
1708
+ let [t, n] = s(e.inProgress);
1709
+ r(() => {
1710
+ e.inProgress || n(!1);
681
1711
  }, [e.inProgress]);
682
- let i = e.inProgress || n, o = e.steps.filter((e) => !(e.kind === f.REASONING_STARTED || e.kind === f.REASONING_FINISHED || I.has(e.kind) || R(e))), s = new Set(o.map((e) => e.step)).size;
683
- return /* @__PURE__ */ u("div", {
1712
+ let i = e.inProgress || t, a = e.steps.filter((e) => !(e.kind === h.REASONING_STARTED || e.kind === h.REASONING_FINISHED || he.has(e.kind) || _e(e))), o = new Set(a.map((e) => e.step)).size;
1713
+ return /* @__PURE__ */ p("div", {
684
1714
  className: `reasoning-trace${e.inProgress ? " reasoning-trace--live" : ""}`,
685
- children: [/* @__PURE__ */ u("button", {
1715
+ children: [/* @__PURE__ */ p("button", {
686
1716
  type: "button",
687
1717
  className: `reasoning-trace__summary${i ? " reasoning-trace__summary--open" : ""}`,
688
- onClick: () => !e.inProgress && r((e) => !e),
1718
+ onClick: () => !e.inProgress && n((e) => !e),
689
1719
  disabled: e.inProgress,
690
1720
  "aria-expanded": i,
691
1721
  children: [
692
- /* @__PURE__ */ l("span", {
1722
+ /* @__PURE__ */ f("span", {
693
1723
  className: "reasoning-trace__icon",
694
1724
  "aria-hidden": !0,
695
1725
  children: e.inProgress ? "🧠" : "✨"
696
1726
  }),
697
- /* @__PURE__ */ l("span", {
1727
+ /* @__PURE__ */ f("span", {
698
1728
  className: "reasoning-trace__label",
699
- children: e.inProgress ? `Reasoning… (${s} step${s === 1 ? "" : "s"})` : `Reasoned across ${s} step${s === 1 ? "" : "s"}`
1729
+ children: e.inProgress ? `Reasoning… (${o} step${o === 1 ? "" : "s"})` : `Reasoned across ${o} step${o === 1 ? "" : "s"}`
700
1730
  }),
701
- !e.inProgress && /* @__PURE__ */ l("span", {
1731
+ !e.inProgress && /* @__PURE__ */ f("span", {
702
1732
  className: "reasoning-trace__chevron",
703
1733
  "aria-hidden": !0,
704
1734
  children: "▶"
705
1735
  })
706
1736
  ]
707
- }), /* @__PURE__ */ l("div", {
1737
+ }), /* @__PURE__ */ f("div", {
708
1738
  className: `reasoning-trace__body-wrapper${i ? " reasoning-trace__body-wrapper--open" : ""}`,
709
- children: /* @__PURE__ */ u("div", {
1739
+ children: /* @__PURE__ */ p("div", {
710
1740
  className: "reasoning-trace__body-inner",
711
- children: [/* @__PURE__ */ l(ne, { steps: o }), e.tasks.length > 0 && /* @__PURE__ */ l(ee, { tasks: e.tasks })]
1741
+ children: [/* @__PURE__ */ f(be, { steps: a }), e.tasks.length > 0 && /* @__PURE__ */ f(ve, { tasks: e.tasks })]
712
1742
  })
713
1743
  })]
714
1744
  });
715
1745
  }
716
- var B = {
717
- [p.PENDING]: "pending",
718
- [p.IN_PROGRESS]: "in progress",
719
- [p.COMPLETED]: "completed",
720
- [p.SKIPPED]: "skipped"
1746
+ var G = {
1747
+ [g.PENDING]: "pending",
1748
+ [g.IN_PROGRESS]: "in progress",
1749
+ [g.COMPLETED]: "completed",
1750
+ [g.SKIPPED]: "skipped"
721
1751
  };
722
- function ee({ tasks: e }) {
723
- let t = e.reduce((e, t) => (e[t.status] = (e[t.status] ?? 0) + 1, e), {}), n = t[p.COMPLETED] ?? 0, r = t[p.SKIPPED] ?? 0, i = (t[p.PENDING] ?? 0) + (t[p.IN_PROGRESS] ?? 0);
724
- return /* @__PURE__ */ u("div", {
1752
+ function ve({ tasks: e }) {
1753
+ let t = e.reduce((e, t) => (e[t.status] = (e[t.status] ?? 0) + 1, e), {}), n = t[g.COMPLETED] ?? 0, r = t[g.SKIPPED] ?? 0, i = (t[g.PENDING] ?? 0) + (t[g.IN_PROGRESS] ?? 0);
1754
+ return /* @__PURE__ */ p("div", {
725
1755
  className: "task-panel",
726
- children: [/* @__PURE__ */ u("div", {
1756
+ children: [/* @__PURE__ */ p("div", {
727
1757
  className: "task-panel__header",
728
- children: [/* @__PURE__ */ l("span", {
1758
+ children: [/* @__PURE__ */ f("span", {
729
1759
  className: "task-panel__title",
730
1760
  children: "Tasks"
731
- }), /* @__PURE__ */ u("span", {
1761
+ }), /* @__PURE__ */ p("span", {
732
1762
  className: "task-panel__counts",
733
1763
  children: [
734
- n > 0 && /* @__PURE__ */ u("span", {
1764
+ n > 0 && /* @__PURE__ */ p("span", {
735
1765
  className: "task-panel__count task-panel__count--completed",
736
1766
  children: [n, " ✓"]
737
1767
  }),
738
- r > 0 && /* @__PURE__ */ u("span", {
1768
+ r > 0 && /* @__PURE__ */ p("span", {
739
1769
  className: "task-panel__count task-panel__count--skipped",
740
1770
  children: [r, " ⊘"]
741
1771
  }),
742
- i > 0 && /* @__PURE__ */ u("span", {
1772
+ i > 0 && /* @__PURE__ */ p("span", {
743
1773
  className: "task-panel__count task-panel__count--pending",
744
1774
  children: [i, " pending"]
745
1775
  })
746
1776
  ]
747
1777
  })]
748
- }), /* @__PURE__ */ l("ul", {
1778
+ }), /* @__PURE__ */ f("ul", {
749
1779
  className: "task-panel__list",
750
- children: e.map((e) => /* @__PURE__ */ u("li", {
1780
+ children: e.map((e) => /* @__PURE__ */ p("li", {
751
1781
  className: `task-panel__item task-panel__item--${e.status}`,
752
- children: [/* @__PURE__ */ l("span", {
1782
+ children: [/* @__PURE__ */ f("span", {
753
1783
  className: `task-panel__box task-panel__box--${e.status}`,
754
- title: B[e.status] ?? e.status,
755
- "aria-label": B[e.status] ?? e.status
756
- }), /* @__PURE__ */ u("span", {
1784
+ title: G[e.status] ?? e.status,
1785
+ "aria-label": G[e.status] ?? e.status
1786
+ }), /* @__PURE__ */ p("span", {
757
1787
  className: "task-panel__text",
758
1788
  children: [
759
- /* @__PURE__ */ u("span", {
1789
+ /* @__PURE__ */ p("span", {
760
1790
  className: "task-panel__id",
761
1791
  children: ["#", e.id]
762
1792
  }),
763
- /* @__PURE__ */ l("span", {
1793
+ /* @__PURE__ */ f("span", {
764
1794
  className: "task-panel__description",
765
1795
  children: e.description
766
1796
  }),
767
- e.result && /* @__PURE__ */ u("span", {
1797
+ e.result && /* @__PURE__ */ p("span", {
768
1798
  className: "task-panel__result",
769
1799
  title: e.result,
770
1800
  children: ["→ ", e.result]
@@ -775,11 +1805,11 @@ function ee({ tasks: e }) {
775
1805
  })]
776
1806
  });
777
1807
  }
778
- function te(e) {
1808
+ function ye(e) {
779
1809
  let t = [], n = 0;
780
- for (; n < e.length;) if (e[n].kind === f.TOOL_RESULT) {
1810
+ for (; n < e.length;) if (e[n].kind === h.TOOL_RESULT) {
781
1811
  let r = n;
782
- for (; r < e.length && e[r].kind === f.TOOL_RESULT;) r++;
1812
+ for (; r < e.length && e[r].kind === h.TOOL_RESULT;) r++;
783
1813
  let i = e.slice(n, r);
784
1814
  if (i.length > 2) t.push({
785
1815
  type: "tool_result_group",
@@ -796,7 +1826,7 @@ function te(e) {
796
1826
  }), n++;
797
1827
  return t;
798
1828
  }
799
- function ne({ steps: e }) {
1829
+ function be({ steps: e }) {
800
1830
  let t = [];
801
1831
  for (let n of e) {
802
1832
  let e = t[t.length - 1];
@@ -805,47 +1835,47 @@ function ne({ steps: e }) {
805
1835
  events: [n]
806
1836
  });
807
1837
  }
808
- return t.length === 0 ? null : /* @__PURE__ */ l("div", {
1838
+ return t.length === 0 ? null : /* @__PURE__ */ f("div", {
809
1839
  className: "reasoning-trace__steps",
810
- children: t.map((e, t) => /* @__PURE__ */ u("div", {
1840
+ children: t.map((e, t) => /* @__PURE__ */ p("div", {
811
1841
  className: "reasoning-trace__step-group",
812
- children: [/* @__PURE__ */ u("div", {
1842
+ children: [/* @__PURE__ */ p("div", {
813
1843
  className: "reasoning-trace__step-header",
814
1844
  title: `actual reasoning iteration #${e.step}`,
815
1845
  children: ["STEP ", t]
816
- }), /* @__PURE__ */ l("ol", {
1846
+ }), /* @__PURE__ */ f("ol", {
817
1847
  className: "reasoning-trace__step-list",
818
- children: te(e.events).map((e, t) => e.type === "tool_result_group" ? /* @__PURE__ */ l(H, { steps: e.steps }, t) : /* @__PURE__ */ l(U, { step: e.step }, t))
1848
+ children: ye(e.events).map((e, t) => e.type === "tool_result_group" ? /* @__PURE__ */ f(Se, { steps: e.steps }, t) : /* @__PURE__ */ f(K, { step: e.step }, t))
819
1849
  })]
820
1850
  }, t))
821
1851
  });
822
1852
  }
823
- var V = {
824
- [f.LLM_TEXT]: "💬",
825
- [f.LLM_TOOL_CALLS]: "🛠️",
826
- [f.TOOL_RESULT]: "📥",
827
- [f.TASK_ADDED]: "📝",
828
- [f.TASK_COMPLETED]: "✅",
829
- [f.TASK_SKIPPED]: "⏭️",
830
- [f.PUSHBACK]: "↩️",
831
- [f.MAX_STEPS]: "⏱️"
1853
+ var xe = {
1854
+ [h.LLM_TEXT]: "💬",
1855
+ [h.LLM_TOOL_CALLS]: "🛠️",
1856
+ [h.TOOL_RESULT]: "📥",
1857
+ [h.TASK_ADDED]: "📝",
1858
+ [h.TASK_COMPLETED]: "✅",
1859
+ [h.TASK_SKIPPED]: "⏭️",
1860
+ [h.PUSHBACK]: "↩️",
1861
+ [h.MAX_STEPS]: "⏱️"
832
1862
  };
833
- function H({ steps: e }) {
834
- let [t, n] = a(!1);
835
- return /* @__PURE__ */ u("li", {
1863
+ function Se({ steps: e }) {
1864
+ let [t, n] = s(!1);
1865
+ return /* @__PURE__ */ p("li", {
836
1866
  className: "reasoning-trace__step",
837
- children: [/* @__PURE__ */ u("button", {
1867
+ children: [/* @__PURE__ */ p("button", {
838
1868
  type: "button",
839
1869
  className: "reasoning-trace__step-line",
840
1870
  onClick: () => n((e) => !e),
841
1871
  title: "Click to expand tool results",
842
1872
  children: [
843
- /* @__PURE__ */ l("span", {
1873
+ /* @__PURE__ */ f("span", {
844
1874
  className: "reasoning-trace__step-icon",
845
1875
  "aria-hidden": !0,
846
1876
  children: "📥"
847
1877
  }),
848
- /* @__PURE__ */ u("span", {
1878
+ /* @__PURE__ */ p("span", {
849
1879
  className: "reasoning-trace__step-summary",
850
1880
  children: [
851
1881
  "Completed ",
@@ -853,7 +1883,7 @@ function H({ steps: e }) {
853
1883
  " tool calls"
854
1884
  ]
855
1885
  }),
856
- /* @__PURE__ */ l("span", {
1886
+ /* @__PURE__ */ f("span", {
857
1887
  className: "reasoning-trace__step-chevron",
858
1888
  "aria-hidden": !0,
859
1889
  style: {
@@ -864,31 +1894,31 @@ function H({ steps: e }) {
864
1894
  children: "▶"
865
1895
  })
866
1896
  ]
867
- }), t && /* @__PURE__ */ l("ol", {
1897
+ }), t && /* @__PURE__ */ f("ol", {
868
1898
  className: "reasoning-trace__step-list reasoning-trace__step-list--nested",
869
- children: e.map((e, t) => /* @__PURE__ */ l(U, { step: e }, t))
1899
+ children: e.map((e, t) => /* @__PURE__ */ f(K, { step: e }, t))
870
1900
  })]
871
1901
  });
872
1902
  }
873
- function U({ step: e }) {
874
- let [t, n] = a(!1), r = V[e.kind] ?? "🔹", i = e.details && Object.keys(e.details).length > 0;
875
- return /* @__PURE__ */ u("li", {
1903
+ function K({ step: e }) {
1904
+ let [t, n] = s(!1), r = xe[e.kind] ?? "🔹", i = e.details && Object.keys(e.details).length > 0;
1905
+ return /* @__PURE__ */ p("li", {
876
1906
  className: "reasoning-trace__step",
877
- children: [/* @__PURE__ */ u("button", {
1907
+ children: [/* @__PURE__ */ p("button", {
878
1908
  type: "button",
879
1909
  className: "reasoning-trace__step-line",
880
1910
  onClick: () => i && n((e) => !e),
881
1911
  disabled: !i,
882
1912
  title: i ? "Click to toggle details" : void 0,
883
- children: [/* @__PURE__ */ l("span", {
1913
+ children: [/* @__PURE__ */ f("span", {
884
1914
  className: "reasoning-trace__step-icon",
885
1915
  "aria-hidden": !0,
886
1916
  children: r
887
- }), /* @__PURE__ */ l("span", {
1917
+ }), /* @__PURE__ */ f("span", {
888
1918
  className: "reasoning-trace__step-summary",
889
1919
  children: e.summary
890
1920
  })]
891
- }), i && t && /* @__PURE__ */ l("pre", {
1921
+ }), i && t && /* @__PURE__ */ f("pre", {
892
1922
  className: "reasoning-trace__step-details",
893
1923
  children: JSON.stringify(e.details, null, 2)
894
1924
  })]
@@ -896,106 +1926,116 @@ function U({ step: e }) {
896
1926
  }
897
1927
  //#endregion
898
1928
  //#region src/components/MessageBubble.tsx
899
- function W({ message: e, onOptionSelect: t, onUIInteract: n }) {
900
- let { action: r, message: i, isUser: a, timestamp: o } = e, s = o ?? null;
901
- if (!a && r === "reasoning_trace") {
902
- let e = i;
903
- return v(e) ? null : /* @__PURE__ */ u("div", {
1929
+ function q({ message: e, onOptionSelect: t, onUIInteract: n }) {
1930
+ let { id: r, action: i, message: a, isUser: o, timestamp: s } = e, c = s ?? null;
1931
+ if (!o && i === "reasoning_trace") {
1932
+ let e = a;
1933
+ return x(e) ? null : /* @__PURE__ */ p("div", {
904
1934
  className: "message message--agent message--reasoning",
905
- children: [s && /* @__PURE__ */ l("span", {
1935
+ children: [c && /* @__PURE__ */ f("span", {
906
1936
  className: "message__timestamp",
907
- children: s
908
- }), /* @__PURE__ */ l("div", {
1937
+ children: c
1938
+ }), /* @__PURE__ */ f("div", {
909
1939
  className: "message__body",
910
- children: /* @__PURE__ */ l(z, { trace: e })
1940
+ children: /* @__PURE__ */ f(W, { trace: e })
911
1941
  })]
912
1942
  });
913
1943
  }
914
- if (a) {
915
- if (r === d.USER_VOICE) {
916
- let e = typeof i == "string" ? i : i.data;
917
- return /* @__PURE__ */ u("div", {
1944
+ if (o) {
1945
+ if (i === m.USER_VOICE) {
1946
+ let e = typeof a == "string" ? a : a.data;
1947
+ return /* @__PURE__ */ p("div", {
918
1948
  className: "message message--user",
919
- children: [s && /* @__PURE__ */ l("span", {
1949
+ children: [c && /* @__PURE__ */ f("span", {
920
1950
  className: "message__timestamp message__timestamp--user",
921
- children: s
922
- }), /* @__PURE__ */ l("div", {
1951
+ children: c
1952
+ }), /* @__PURE__ */ f("div", {
923
1953
  className: "message__body",
924
- children: /* @__PURE__ */ l("div", {
1954
+ children: /* @__PURE__ */ f("div", {
925
1955
  className: "message__bubble message__bubble--user message__bubble--media",
926
- children: /* @__PURE__ */ l(Q, { data: e })
1956
+ children: /* @__PURE__ */ f(Z, { data: e })
927
1957
  })
928
1958
  })]
929
1959
  });
930
1960
  }
931
- return r === d.USER_FILE ? /* @__PURE__ */ u("div", {
1961
+ return i === m.USER_FILE ? /* @__PURE__ */ p("div", {
932
1962
  className: "message message--user",
933
- children: [s && /* @__PURE__ */ l("span", {
1963
+ children: [c && /* @__PURE__ */ f("span", {
934
1964
  className: "message__timestamp message__timestamp--user",
935
- children: s
936
- }), /* @__PURE__ */ l("div", {
1965
+ children: c
1966
+ }), /* @__PURE__ */ f("div", {
937
1967
  className: "message__body",
938
- children: /* @__PURE__ */ l("div", {
1968
+ children: /* @__PURE__ */ f("div", {
939
1969
  className: "message__bubble message__bubble--user message__bubble--media",
940
- children: /* @__PURE__ */ l(K, { content: i })
1970
+ children: /* @__PURE__ */ f(J, { content: a })
941
1971
  })
942
1972
  })]
943
- }) : /* @__PURE__ */ u("div", {
1973
+ }) : /* @__PURE__ */ p("div", {
944
1974
  className: "message message--user",
945
- children: [s && /* @__PURE__ */ l("span", {
1975
+ children: [c && /* @__PURE__ */ f("span", {
946
1976
  className: "message__timestamp message__timestamp--user",
947
- children: s
948
- }), /* @__PURE__ */ l("div", {
1977
+ children: c
1978
+ }), /* @__PURE__ */ f("div", {
949
1979
  className: "message__body",
950
- children: /* @__PURE__ */ l("div", {
1980
+ children: /* @__PURE__ */ f("div", {
951
1981
  className: "message__bubble message__bubble--user",
952
- children: typeof i == "string" ? i : JSON.stringify(i)
1982
+ children: typeof a == "string" ? a : JSON.stringify(a)
953
1983
  })
954
1984
  })]
955
1985
  });
956
1986
  }
957
- return /* @__PURE__ */ u("div", {
1987
+ let l, u;
1988
+ if (i === m.AGENT_REPLY_GUI) try {
1989
+ let e = typeof a == "string" ? JSON.parse(a) : a;
1990
+ e?.width && (l = {
1991
+ width: e.width,
1992
+ maxWidth: e.width
1993
+ }, u = { width: "100%" });
1994
+ } catch {}
1995
+ return /* @__PURE__ */ p("div", {
958
1996
  className: "message message--agent",
959
- children: [s && /* @__PURE__ */ l("span", {
1997
+ style: l,
1998
+ children: [c && /* @__PURE__ */ f("span", {
960
1999
  className: "message__timestamp",
961
- children: s
962
- }), /* @__PURE__ */ l("div", {
2000
+ children: c
2001
+ }), /* @__PURE__ */ f("div", {
963
2002
  className: "message__body",
964
- children: /* @__PURE__ */ l("div", {
2003
+ style: u,
2004
+ children: /* @__PURE__ */ f("div", {
965
2005
  className: "message__bubble message__bubble--agent",
966
- children: G(r, i, t, n)
2006
+ children: Ce(i, a, t, n, r)
967
2007
  })
968
2008
  })]
969
2009
  });
970
2010
  }
971
- function G(e, t, n, r) {
2011
+ function Ce(e, t, n, r, i) {
972
2012
  switch (e) {
973
- case d.AGENT_REPLY_STR: {
974
- let e = String(t), n = C(e);
975
- return n === "markdown" ? /* @__PURE__ */ l("div", {
2013
+ case m.AGENT_REPLY_STR: {
2014
+ let e = String(t), n = E(e);
2015
+ return n === "markdown" ? /* @__PURE__ */ f("div", {
976
2016
  className: "msg-markdown",
977
- children: /* @__PURE__ */ l(o, {
978
- remarkPlugins: [s],
2017
+ children: /* @__PURE__ */ f(c, {
2018
+ remarkPlugins: [l],
979
2019
  children: e
980
2020
  })
981
- }) : n === "code" ? /* @__PURE__ */ l("pre", {
2021
+ }) : n === "code" ? /* @__PURE__ */ f("pre", {
982
2022
  className: "msg-code",
983
- children: /* @__PURE__ */ l("code", { children: e })
984
- }) : /* @__PURE__ */ l("p", {
2023
+ children: /* @__PURE__ */ f("code", { children: e })
2024
+ }) : /* @__PURE__ */ f("p", {
985
2025
  className: "msg-text",
986
2026
  children: e
987
2027
  });
988
2028
  }
989
- case d.AGENT_REPLY_MARKDOWN: return /* @__PURE__ */ l("div", {
2029
+ case m.AGENT_REPLY_MARKDOWN: return /* @__PURE__ */ f("div", {
990
2030
  className: "msg-markdown",
991
- children: /* @__PURE__ */ l(o, {
992
- remarkPlugins: [s],
2031
+ children: /* @__PURE__ */ f(c, {
2032
+ remarkPlugins: [l],
993
2033
  children: String(t)
994
2034
  })
995
2035
  });
996
- case d.AGENT_REPLY_HTML: return /* @__PURE__ */ l("div", {
2036
+ case m.AGENT_REPLY_HTML: return /* @__PURE__ */ f("div", {
997
2037
  className: "msg-html",
998
- dangerouslySetInnerHTML: { __html: c.sanitize(String(t), {
2038
+ dangerouslySetInnerHTML: { __html: u.sanitize(String(t), {
999
2039
  ALLOWED_TAGS: /* @__PURE__ */ "p.br.b.i.em.strong.a.ul.ol.li.code.pre.h1.h2.h3.h4.h5.h6.blockquote.table.thead.tbody.tr.th.td.div.span.hr".split("."),
1000
2040
  ALLOWED_ATTR: [
1001
2041
  "href",
@@ -1015,22 +2055,24 @@ function G(e, t, n, r) {
1015
2055
  FORCE_BODY: !0
1016
2056
  }) }
1017
2057
  });
1018
- case d.AGENT_REPLY_FILE: return /* @__PURE__ */ l(K, { content: t });
1019
- case d.AGENT_REPLY_IMAGE: return /* @__PURE__ */ l(q, { content: t });
1020
- case d.AGENT_REPLY_DF: return /* @__PURE__ */ l(J, { content: t });
1021
- case d.AGENT_REPLY_PLOTLY: return /* @__PURE__ */ l(Y, { content: t });
1022
- case d.AGENT_REPLY_OPTIONS: return /* @__PURE__ */ l(X, {
2058
+ case m.AGENT_REPLY_FILE: return /* @__PURE__ */ f(J, { content: t });
2059
+ case m.AGENT_REPLY_IMAGE: return /* @__PURE__ */ f(we, { content: t });
2060
+ case m.AGENT_REPLY_DF: return /* @__PURE__ */ f(Te, { content: t });
2061
+ case m.AGENT_REPLY_PLOTLY: return /* @__PURE__ */ f(Ee, { content: t });
2062
+ case m.AGENT_REPLY_OPTIONS: return /* @__PURE__ */ f(De, {
1023
2063
  content: t,
1024
2064
  onSelect: n
1025
2065
  });
1026
- case d.AGENT_REPLY_LOCATION: return /* @__PURE__ */ l(Z, { content: t });
1027
- case d.AGENT_REPLY_RAG: return /* @__PURE__ */ l(re, { content: t });
1028
- case d.AGENT_REPLY_AUDIO: return /* @__PURE__ */ l(ie, { content: t });
1029
- case d.AGENT_REPLY_UI: return /* @__PURE__ */ l(F, {
2066
+ case m.AGENT_REPLY_LOCATION: return /* @__PURE__ */ f(Oe, { content: t });
2067
+ case m.AGENT_REPLY_RAG: return /* @__PURE__ */ f(ke, { content: t });
2068
+ case m.AGENT_REPLY_AUDIO: return /* @__PURE__ */ f(Ae, { content: t });
2069
+ case m.AGENT_REPLY_GUI: return /* @__PURE__ */ f(U, {
1030
2070
  content: t,
1031
- onInteract: r
2071
+ onInteract: r,
2072
+ messageId: i,
2073
+ chatMode: !0
1032
2074
  });
1033
- default: return /* @__PURE__ */ u("p", {
2075
+ default: return /* @__PURE__ */ p("p", {
1034
2076
  className: "msg-text msg-text--muted",
1035
2077
  children: [
1036
2078
  "[Unsupported message type: ",
@@ -1040,7 +2082,7 @@ function G(e, t, n, r) {
1040
2082
  });
1041
2083
  }
1042
2084
  }
1043
- function K({ content: e }) {
2085
+ function J({ content: e }) {
1044
2086
  let t = e, n = t.data ?? t.base64 ?? "";
1045
2087
  function r() {
1046
2088
  try {
@@ -1052,82 +2094,82 @@ function K({ content: e }) {
1052
2094
  console.error("Failed to decode file data");
1053
2095
  }
1054
2096
  }
1055
- return /* @__PURE__ */ u("button", {
2097
+ return /* @__PURE__ */ p("button", {
1056
2098
  className: "msg-file-btn",
1057
2099
  onClick: r,
1058
2100
  children: ["📄 ", t.name ?? "Download file"]
1059
2101
  });
1060
2102
  }
1061
- function q({ content: e }) {
2103
+ function we({ content: e }) {
1062
2104
  let t, n;
1063
2105
  if (typeof e == "string") t = e, n = "image/png";
1064
2106
  else {
1065
2107
  let r = e;
1066
2108
  t = r.data ?? r.base64 ?? "", n = r.type ?? (r.format ? `image/${r.format.toLowerCase()}` : "image/png");
1067
2109
  }
1068
- return t ? /* @__PURE__ */ l("div", {
2110
+ return t ? /* @__PURE__ */ f("div", {
1069
2111
  className: "msg-image",
1070
- children: /* @__PURE__ */ l("img", {
2112
+ children: /* @__PURE__ */ f("img", {
1071
2113
  src: `data:${n};base64,${t}`,
1072
2114
  alt: typeof e == "object" && e ? e.name ?? "Image" : "Image",
1073
2115
  onError: (e) => {
1074
2116
  e.target.style.display = "none";
1075
2117
  }
1076
2118
  })
1077
- }) : /* @__PURE__ */ l("span", {
2119
+ }) : /* @__PURE__ */ f("span", {
1078
2120
  className: "msg-text--muted",
1079
2121
  children: "Image unavailable"
1080
2122
  });
1081
2123
  }
1082
- function J({ content: e }) {
1083
- let [t, n] = a(null), [r, i] = a(!0), o = [], s = [];
1084
- if (Array.isArray(e) && e.length > 0) o = Object.keys(e[0]), s = e.map((e) => o.map((t) => e[t]));
2124
+ function Te({ content: e }) {
2125
+ let [t, n] = s(null), [r, i] = s(!0), a = [], o = [];
2126
+ if (Array.isArray(e) && e.length > 0) a = Object.keys(e[0]), o = e.map((e) => a.map((t) => e[t]));
1085
2127
  else if (typeof e == "object" && e) {
1086
2128
  let t = e;
1087
- if (Array.isArray(t.data) && Array.isArray(t.columns)) o = t.columns, s = t.data;
2129
+ if (Array.isArray(t.data) && Array.isArray(t.columns)) a = t.columns, o = t.data;
1088
2130
  else {
1089
2131
  let e = Object.keys(t), n = t[e[0]];
1090
2132
  if (e.length > 0 && typeof n == "object" && n && !Array.isArray(n)) {
1091
- o = e;
2133
+ a = e;
1092
2134
  let n = t;
1093
- s = Object.keys(n[o[0]]).map((e) => o.map((t) => n[t][e]));
2135
+ o = Object.keys(n[a[0]]).map((e) => a.map((t) => n[t][e]));
1094
2136
  }
1095
2137
  }
1096
2138
  }
1097
- if (o.length === 0) return /* @__PURE__ */ l("pre", {
2139
+ if (a.length === 0) return /* @__PURE__ */ f("pre", {
1098
2140
  className: "msg-code",
1099
2141
  children: JSON.stringify(e, null, 2)
1100
2142
  });
1101
2143
  function c(e) {
1102
2144
  t === e ? i((e) => !e) : (n(e), i(!0));
1103
2145
  }
1104
- let d = t === null ? s : [...s].sort((e, n) => {
2146
+ let l = t === null ? o : [...o].sort((e, n) => {
1105
2147
  let i = e[t], a = n[t];
1106
2148
  return i == null && a == null ? 0 : i == null ? r ? 1 : -1 : a == null ? r ? -1 : 1 : typeof i == "number" && typeof a == "number" ? r ? i - a : a - i : r ? String(i).localeCompare(String(a)) : String(a).localeCompare(String(i));
1107
2149
  });
1108
- return /* @__PURE__ */ l("div", {
2150
+ return /* @__PURE__ */ f("div", {
1109
2151
  className: "msg-table-wrapper",
1110
- children: /* @__PURE__ */ u("table", {
2152
+ children: /* @__PURE__ */ p("table", {
1111
2153
  className: "msg-table",
1112
- children: [/* @__PURE__ */ l("thead", { children: /* @__PURE__ */ l("tr", { children: o.map((e, n) => /* @__PURE__ */ u("th", {
2154
+ children: [/* @__PURE__ */ f("thead", { children: /* @__PURE__ */ f("tr", { children: a.map((e, n) => /* @__PURE__ */ p("th", {
1113
2155
  className: `msg-table__th${t === n ? " msg-table__th--sorted" : ""}`,
1114
2156
  onClick: () => c(n),
1115
- children: [e, /* @__PURE__ */ l("span", {
2157
+ children: [e, /* @__PURE__ */ f("span", {
1116
2158
  className: "msg-table__sort-icon",
1117
2159
  children: t === n ? r ? "↑" : "↓" : "↕"
1118
2160
  })]
1119
- }, e)) }) }), /* @__PURE__ */ l("tbody", { children: d.map((e, t) => /* @__PURE__ */ l("tr", { children: e.map((e, t) => /* @__PURE__ */ l("td", { children: String(e ?? "") }, t)) }, t)) })]
2161
+ }, e)) }) }), /* @__PURE__ */ f("tbody", { children: l.map((e, t) => /* @__PURE__ */ f("tr", { children: e.map((e, t) => /* @__PURE__ */ f("td", { children: String(e ?? "") }, t)) }, t)) })]
1120
2162
  })
1121
2163
  });
1122
2164
  }
1123
- function Y({ content: e }) {
1124
- let n = i(null);
1125
- return t(() => {
1126
- let t = n.current;
1127
- if (!t) return;
2165
+ function Ee({ content: e }) {
2166
+ let t = o(null);
2167
+ return r(() => {
2168
+ let n = t.current;
2169
+ if (!n) return;
1128
2170
  let r = !0, i = e;
1129
2171
  return import("plotly.js-dist-min").then((e) => {
1130
- !r || !t || e.newPlot(t, i.data ?? [], {
2172
+ !r || !n || e.newPlot(n, i.data ?? [], {
1131
2173
  margin: {
1132
2174
  t: 24,
1133
2175
  r: 10,
@@ -1142,36 +2184,36 @@ function Y({ content: e }) {
1142
2184
  });
1143
2185
  }), () => {
1144
2186
  r = !1, import("plotly.js-dist-min").then((e) => {
1145
- t && e.purge(t);
2187
+ n && e.purge(n);
1146
2188
  });
1147
2189
  };
1148
- }, [e]), /* @__PURE__ */ l("div", {
1149
- ref: n,
2190
+ }, [e]), /* @__PURE__ */ f("div", {
2191
+ ref: t,
1150
2192
  className: "msg-plotly"
1151
2193
  });
1152
2194
  }
1153
- function X({ content: e, onSelect: t }) {
2195
+ function De({ content: e, onSelect: t }) {
1154
2196
  let n;
1155
- return n = Array.isArray(e) ? e.map(String) : typeof e == "object" && e ? Object.values(e).map(String) : [], /* @__PURE__ */ l("div", {
2197
+ return n = Array.isArray(e) ? e.map(String) : typeof e == "object" && e ? Object.values(e).map(String) : [], /* @__PURE__ */ f("div", {
1156
2198
  className: "msg-options",
1157
- children: n.map((e, n) => /* @__PURE__ */ l("button", {
2199
+ children: n.map((e, n) => /* @__PURE__ */ f("button", {
1158
2200
  className: "msg-option-btn",
1159
2201
  onClick: () => t?.(e),
1160
2202
  children: e
1161
2203
  }, n))
1162
2204
  });
1163
2205
  }
1164
- function Z({ content: e }) {
2206
+ function Oe({ content: e }) {
1165
2207
  let { latitude: t, longitude: n, zoom: r = 15 } = e, i = 360 / 2 ** (r + 1), a = `https://www.openstreetmap.org/export/embed.html?bbox=${`${n - i},${t - i},${n + i},${t + i}`}&layer=mapnik&marker=${t},${n}`, o = `https://www.openstreetmap.org/?mlat=${t}&mlon=${n}#map=${r}/${t}/${n}`;
1166
- return /* @__PURE__ */ u("div", {
2208
+ return /* @__PURE__ */ p("div", {
1167
2209
  className: "msg-location",
1168
- children: [/* @__PURE__ */ l("iframe", {
2210
+ children: [/* @__PURE__ */ f("iframe", {
1169
2211
  src: a,
1170
2212
  className: "msg-location__map",
1171
2213
  title: "Location map",
1172
2214
  loading: "lazy",
1173
2215
  referrerPolicy: "no-referrer"
1174
- }), /* @__PURE__ */ u("a", {
2216
+ }), /* @__PURE__ */ p("a", {
1175
2217
  className: "msg-location__link",
1176
2218
  href: o,
1177
2219
  target: "_blank",
@@ -1186,45 +2228,45 @@ function Z({ content: e }) {
1186
2228
  })]
1187
2229
  });
1188
2230
  }
1189
- function re({ content: e }) {
1190
- let [t, n] = a(!1), r = e, i = r.docs ?? r.documents ?? [];
1191
- return /* @__PURE__ */ u("div", {
2231
+ function ke({ content: e }) {
2232
+ let [t, n] = s(!1), r = e, i = r.docs ?? r.documents ?? [];
2233
+ return /* @__PURE__ */ p("div", {
1192
2234
  className: "msg-rag",
1193
- children: [/* @__PURE__ */ l("p", {
2235
+ children: [/* @__PURE__ */ f("p", {
1194
2236
  className: "msg-rag__answer",
1195
2237
  children: r.answer
1196
- }), i.length > 0 && /* @__PURE__ */ u("div", {
2238
+ }), i.length > 0 && /* @__PURE__ */ p("div", {
1197
2239
  className: "msg-rag__details",
1198
- children: [/* @__PURE__ */ u("button", {
2240
+ children: [/* @__PURE__ */ p("button", {
1199
2241
  type: "button",
1200
2242
  className: `msg-rag__summary${t ? " msg-rag__summary--open" : ""}`,
1201
2243
  onClick: () => n((e) => !e),
1202
- children: [/* @__PURE__ */ l("span", {
2244
+ children: [/* @__PURE__ */ f("span", {
1203
2245
  className: "msg-rag__summary-arrow",
1204
2246
  children: "▶"
1205
2247
  }), "Details"]
1206
- }), /* @__PURE__ */ l("div", {
2248
+ }), /* @__PURE__ */ f("div", {
1207
2249
  className: `msg-rag__body-wrapper${t ? " msg-rag__body-wrapper--open" : ""}`,
1208
- children: /* @__PURE__ */ l("div", {
2250
+ children: /* @__PURE__ */ f("div", {
1209
2251
  className: "msg-rag__body-inner",
1210
- children: /* @__PURE__ */ u("div", {
2252
+ children: /* @__PURE__ */ p("div", {
1211
2253
  className: "msg-rag__details-body",
1212
2254
  children: [
1213
- /* @__PURE__ */ l("div", {
2255
+ /* @__PURE__ */ f("div", {
1214
2256
  className: "msg-rag__rag-answer-label",
1215
2257
  children: "RAG Answer"
1216
2258
  }),
1217
- r.llm_name && /* @__PURE__ */ u("div", {
2259
+ r.llm_name && /* @__PURE__ */ p("div", {
1218
2260
  className: "msg-rag__llm-row",
1219
- children: [/* @__PURE__ */ l("span", {
2261
+ children: [/* @__PURE__ */ f("span", {
1220
2262
  className: "msg-rag__llm-label",
1221
2263
  children: "Model"
1222
- }), /* @__PURE__ */ l("code", {
2264
+ }), /* @__PURE__ */ f("code", {
1223
2265
  className: "msg-rag__llm-badge",
1224
2266
  children: r.llm_name
1225
2267
  })]
1226
2268
  }),
1227
- /* @__PURE__ */ u("div", {
2269
+ /* @__PURE__ */ p("div", {
1228
2270
  className: "msg-rag__context-label",
1229
2271
  children: [
1230
2272
  "Context (",
@@ -1232,14 +2274,14 @@ function re({ content: e }) {
1232
2274
  " Documents)"
1233
2275
  ]
1234
2276
  }),
1235
- /* @__PURE__ */ l("div", {
2277
+ /* @__PURE__ */ f("div", {
1236
2278
  className: "msg-rag__docs",
1237
2279
  children: i.map((e, t) => {
1238
2280
  let n = e.metadata?.source, r = e.metadata?.page;
1239
- return /* @__PURE__ */ u("div", {
2281
+ return /* @__PURE__ */ p("div", {
1240
2282
  className: "msg-rag__doc-card",
1241
2283
  children: [
1242
- /* @__PURE__ */ u("div", {
2284
+ /* @__PURE__ */ p("div", {
1243
2285
  className: "msg-rag__doc-header",
1244
2286
  children: [
1245
2287
  "Document ",
@@ -1248,32 +2290,32 @@ function re({ content: e }) {
1248
2290
  i.length
1249
2291
  ]
1250
2292
  }),
1251
- n && /* @__PURE__ */ u("div", {
2293
+ n && /* @__PURE__ */ p("div", {
1252
2294
  className: "msg-rag__doc-row",
1253
- children: [/* @__PURE__ */ l("span", {
2295
+ children: [/* @__PURE__ */ f("span", {
1254
2296
  className: "msg-rag__doc-key",
1255
2297
  children: "Source"
1256
- }), /* @__PURE__ */ l("span", {
2298
+ }), /* @__PURE__ */ f("span", {
1257
2299
  className: "msg-rag__doc-value",
1258
2300
  children: n
1259
2301
  })]
1260
2302
  }),
1261
- r != null && /* @__PURE__ */ u("div", {
2303
+ r != null && /* @__PURE__ */ p("div", {
1262
2304
  className: "msg-rag__doc-row",
1263
- children: [/* @__PURE__ */ l("span", {
2305
+ children: [/* @__PURE__ */ f("span", {
1264
2306
  className: "msg-rag__doc-key",
1265
2307
  children: "Page"
1266
- }), /* @__PURE__ */ l("span", {
2308
+ }), /* @__PURE__ */ f("span", {
1267
2309
  className: "msg-rag__doc-value",
1268
2310
  children: String(r)
1269
2311
  })]
1270
2312
  }),
1271
- /* @__PURE__ */ u("div", {
2313
+ /* @__PURE__ */ p("div", {
1272
2314
  className: "msg-rag__doc-row msg-rag__doc-row--content",
1273
- children: [/* @__PURE__ */ l("span", {
2315
+ children: [/* @__PURE__ */ f("span", {
1274
2316
  className: "msg-rag__doc-key",
1275
2317
  children: "Content"
1276
- }), /* @__PURE__ */ l("span", {
2318
+ }), /* @__PURE__ */ f("span", {
1277
2319
  className: "msg-rag__doc-value msg-rag__doc-content",
1278
2320
  children: e.content
1279
2321
  })]
@@ -1289,58 +2331,92 @@ function re({ content: e }) {
1289
2331
  })]
1290
2332
  });
1291
2333
  }
1292
- function Q({ data: e, mimeType: n = "audio/wav" }) {
1293
- let [r, i] = a(null);
1294
- return t(() => {
1295
- let t = null;
2334
+ function Y(e, t, n) {
2335
+ for (let r = 0; r < n.length; r++) e.setUint8(t + r, n.charCodeAt(r));
2336
+ return t + n.length;
2337
+ }
2338
+ function X(e, t, n, r) {
2339
+ let i = r.length > 1 ? r[0] : 1, a = r.length > 1 ? r[r.length - 1] : r[0], o, s, c;
2340
+ if (n === "int16") o = e, s = 16, c = 1;
2341
+ else {
2342
+ let t;
2343
+ if (n === "float32") t = new Float32Array(e);
2344
+ else if (n === "float64") {
2345
+ let n = new Float64Array(e);
2346
+ t = new Float32Array(n.length);
2347
+ for (let e = 0; e < n.length; e++) t[e] = n[e];
2348
+ } else if (n === "int32") {
2349
+ let n = new Int32Array(e);
2350
+ t = new Float32Array(n.length);
2351
+ for (let e = 0; e < n.length; e++) t[e] = n[e] / 2147483648;
2352
+ } else t = new Float32Array(e);
2353
+ if (i > 1) {
2354
+ let e = new Float32Array(i * a);
2355
+ for (let n = 0; n < a; n++) for (let r = 0; r < i; r++) e[n * i + r] = t[r * a + n];
2356
+ o = e.buffer;
2357
+ } else o = t.buffer;
2358
+ s = 32, c = 3;
2359
+ }
2360
+ let l = o.byteLength, u = new ArrayBuffer(44 + l), d = new DataView(u), f = 0;
2361
+ return f = Y(d, f, "RIFF"), d.setUint32(f, 36 + l, !0), f += 4, f = Y(d, f, "WAVE"), f = Y(d, f, "fmt "), d.setUint32(f, 16, !0), f += 4, d.setUint16(f, c, !0), f += 2, d.setUint16(f, i, !0), f += 2, d.setUint32(f, t, !0), f += 4, d.setUint32(f, t * i * s / 8, !0), f += 4, d.setUint16(f, i * s / 8, !0), f += 2, d.setUint16(f, s, !0), f += 2, f = Y(d, f, "data"), d.setUint32(f, l, !0), f += 4, new Uint8Array(u, f).set(new Uint8Array(o)), new Blob([u], { type: "audio/wav" });
2362
+ }
2363
+ function Z({ data: e, sampleRate: t, dtype: n, shape: i }) {
2364
+ let [a, o] = s(null);
2365
+ return r(() => {
2366
+ let r = null;
1296
2367
  try {
1297
- let r = atob(e), a = new Uint8Array(r.length);
1298
- for (let e = 0; e < r.length; e++) a[e] = r.charCodeAt(e);
1299
- let o = new Blob([a], { type: n });
1300
- t = URL.createObjectURL(o), i(t);
2368
+ let a = atob(e), s = new Uint8Array(a.length);
2369
+ for (let e = 0; e < a.length; e++) s[e] = a.charCodeAt(e);
2370
+ let c;
2371
+ c = t && n && i ? X(s.buffer, t, n, i) : new Blob([s], { type: "audio/wav" }), r = URL.createObjectURL(c), o(r);
1301
2372
  } catch {
1302
- i(null);
2373
+ o(null);
1303
2374
  }
1304
2375
  return () => {
1305
- t && URL.revokeObjectURL(t);
2376
+ r && URL.revokeObjectURL(r);
1306
2377
  };
1307
- }, [e, n]), r ? /* @__PURE__ */ l("audio", {
2378
+ }, [
2379
+ e,
2380
+ t,
2381
+ n,
2382
+ JSON.stringify(i)
2383
+ ]), a ? /* @__PURE__ */ f("audio", {
1308
2384
  controls: !0,
1309
- src: r,
2385
+ src: a,
1310
2386
  className: "msg-audio__player"
1311
- }) : /* @__PURE__ */ l("span", {
2387
+ }) : /* @__PURE__ */ f("span", {
1312
2388
  className: "msg-text--muted",
1313
2389
  children: "Audio unavailable"
1314
2390
  });
1315
2391
  }
1316
- function ie({ content: e }) {
1317
- let t = typeof e == "string" ? { data: e } : e;
1318
- return /* @__PURE__ */ u("div", {
2392
+ function Ae({ content: e }) {
2393
+ if (typeof e != "object" || !e) return /* @__PURE__ */ f("span", {
2394
+ className: "msg-text--muted",
2395
+ children: "Audio unavailable"
2396
+ });
2397
+ let t = e, n = t.metadata ?? {};
2398
+ return /* @__PURE__ */ f("div", {
1319
2399
  className: "msg-audio",
1320
- children: [/* @__PURE__ */ l(Q, {
1321
- data: t.data,
1322
- mimeType: t.type ?? "audio/wav"
1323
- }), t.sample_rate != null && /* @__PURE__ */ u("span", {
1324
- className: "msg-audio__meta",
1325
- children: [
1326
- t.sample_rate,
1327
- " Hz",
1328
- t.dtype ? ` · ${t.dtype}` : ""
1329
- ]
1330
- })]
2400
+ children: /* @__PURE__ */ f(Z, {
2401
+ data: t.audio_data_base64,
2402
+ sampleRate: n.sample_rate,
2403
+ dtype: n.dtype,
2404
+ shape: n.shape
2405
+ })
1331
2406
  });
1332
2407
  }
1333
2408
  //#endregion
1334
2409
  //#region src/components/ChatArea.tsx
1335
- function $() {
2410
+ function Q() {
1336
2411
  let e = /* @__PURE__ */ new Date(), t = (e) => String(e).padStart(2, "0");
1337
2412
  return `${e.getFullYear()}-${t(e.getMonth() + 1)}-${t(e.getDate())} ${t(e.getHours())}:${t(e.getMinutes())}:${t(e.getSeconds())}`;
1338
2413
  }
1339
- function ae({ messages: n, setMessages: r, status: o, send: s }) {
1340
- let [c, f] = a(""), [p, m] = a([]), [h, g] = a(!1), [_, v] = a(!1), y = i(null), b = i(null), x = i(null), S = i(null), C = i(null), w = i([]);
1341
- t(() => {
1342
- y.current?.scrollIntoView({ behavior: "smooth" });
1343
- }, [n]), t(() => {
2414
+ function $({ messages: e, setMessages: n, status: i, send: a }) {
2415
+ let [c, l] = s(""), [u, d] = s([]), [h, g] = s(!1), [_, v] = s(!1), y = o(null), b = o(null), x = o(null), S = o(null), C = o(null), w = o([]);
2416
+ r(() => {
2417
+ let e = y.current;
2418
+ e && (e.scrollTop = e.scrollHeight);
2419
+ }, [e]), r(() => {
1344
2420
  if (!h) return;
1345
2421
  function e(e) {
1346
2422
  S.current && !S.current.contains(e.target) && g(!1);
@@ -1353,24 +2429,24 @@ function ae({ messages: n, setMessages: r, status: o, send: s }) {
1353
2429
  }
1354
2430
  async function E() {
1355
2431
  try {
1356
- let e = await navigator.mediaDevices.getUserMedia({ audio: !0 }), t = MediaRecorder.isTypeSupported("audio/webm") ? "audio/webm" : "audio/ogg", n = new MediaRecorder(e, { mimeType: t });
1357
- w.current = [], n.ondataavailable = (e) => {
2432
+ let e = await navigator.mediaDevices.getUserMedia({ audio: !0 }), t = MediaRecorder.isTypeSupported("audio/webm") ? "audio/webm" : "audio/ogg", r = new MediaRecorder(e, { mimeType: t });
2433
+ w.current = [], r.ondataavailable = (e) => {
1358
2434
  e.data.size > 0 && w.current.push(e.data);
1359
- }, n.onstop = () => {
1360
- let n = new Blob(w.current, { type: t });
2435
+ }, r.onstop = () => {
2436
+ let r = new Blob(w.current, { type: t });
1361
2437
  e.getTracks().forEach((e) => e.stop());
1362
2438
  let i = new FileReader();
1363
2439
  i.onload = () => {
1364
2440
  let e = i.result.split(",")[1] ?? "";
1365
- r((t) => [...t, {
2441
+ n((t) => [...t, {
1366
2442
  id: crypto.randomUUID(),
1367
- action: d.USER_VOICE,
2443
+ action: m.USER_VOICE,
1368
2444
  message: e,
1369
2445
  isUser: !0,
1370
- timestamp: $()
1371
- }]), s(d.USER_VOICE, e);
1372
- }, i.readAsDataURL(n), v(!1);
1373
- }, n.start(), C.current = n, v(!0);
2446
+ timestamp: Q()
2447
+ }]), a(m.USER_VOICE, e);
2448
+ }, i.readAsDataURL(r), v(!1);
2449
+ }, r.start(), C.current = r, v(!0);
1374
2450
  } catch {
1375
2451
  console.error("Microphone access denied or unavailable");
1376
2452
  }
@@ -1378,53 +2454,53 @@ function ae({ messages: n, setMessages: r, status: o, send: s }) {
1378
2454
  function D() {
1379
2455
  _ ? (C.current?.stop(), C.current = null) : E();
1380
2456
  }
1381
- let O = e(() => {
1382
- let e = c.trim(), t = p.length > 0;
1383
- if (!(!e && !t || o !== "connected")) {
1384
- for (let e of p) r((t) => [...t, {
2457
+ let O = t(() => {
2458
+ let e = c.trim(), t = u.length > 0;
2459
+ if (!(!e && !t || i !== "connected")) {
2460
+ for (let e of u) n((t) => [...t, {
1385
2461
  id: crypto.randomUUID(),
1386
- action: d.USER_FILE,
2462
+ action: m.USER_FILE,
1387
2463
  message: {
1388
2464
  name: e.name,
1389
2465
  type: e.mimeType,
1390
2466
  base64: e.base64
1391
2467
  },
1392
2468
  isUser: !0,
1393
- timestamp: $()
1394
- }]), s(d.USER_FILE, JSON.stringify({
2469
+ timestamp: Q()
2470
+ }]), a(m.USER_FILE, JSON.stringify({
1395
2471
  name: e.name,
1396
2472
  type: e.mimeType,
1397
2473
  base64: e.base64
1398
2474
  }));
1399
- m([]), e && (r((t) => [...t, {
2475
+ d([]), e && (n((t) => [...t, {
1400
2476
  id: crypto.randomUUID(),
1401
- action: d.USER_MESSAGE,
2477
+ action: m.USER_MESSAGE,
1402
2478
  message: e,
1403
2479
  isUser: !0,
1404
- timestamp: $()
1405
- }]), s(d.USER_MESSAGE, e), f(""), b.current && (b.current.style.height = "auto"));
2480
+ timestamp: Q()
2481
+ }]), a(m.USER_MESSAGE, e), l(""), b.current && (b.current.style.height = "auto"));
1406
2482
  }
1407
2483
  }, [
1408
2484
  c,
1409
- p,
1410
- o,
1411
- s,
1412
- r
2485
+ u,
2486
+ i,
2487
+ a,
2488
+ n
1413
2489
  ]);
1414
2490
  function k(e) {
1415
2491
  e.key === "Enter" && !e.shiftKey && (e.preventDefault(), O());
1416
2492
  }
1417
2493
  function A(e) {
1418
- r((t) => [...t, {
2494
+ n((t) => [...t, {
1419
2495
  id: crypto.randomUUID(),
1420
- action: d.USER_MESSAGE,
2496
+ action: m.USER_MESSAGE,
1421
2497
  message: e,
1422
2498
  isUser: !0,
1423
- timestamp: $()
1424
- }]), s(d.USER_MESSAGE, e);
2499
+ timestamp: Q()
2500
+ }]), a(m.USER_MESSAGE, e);
1425
2501
  }
1426
2502
  function j(e) {
1427
- s(d.USER_UPDATE_UI, e);
2503
+ a(m.USER_GUI_EVENT, e);
1428
2504
  }
1429
2505
  function M(e) {
1430
2506
  let t = Array.from(e.target.files ?? []);
@@ -1432,7 +2508,7 @@ function ae({ messages: n, setMessages: r, status: o, send: s }) {
1432
2508
  let t = new FileReader();
1433
2509
  t.onload = () => {
1434
2510
  let n = t.result.split(",")[1] ?? "";
1435
- m((t) => [...t, {
2511
+ d((t) => [...t, {
1436
2512
  id: crypto.randomUUID(),
1437
2513
  name: e.name,
1438
2514
  base64: n,
@@ -1442,51 +2518,48 @@ function ae({ messages: n, setMessages: r, status: o, send: s }) {
1442
2518
  }), e.target.value = "", g(!1));
1443
2519
  }
1444
2520
  function N(e) {
1445
- m((t) => t.filter((t) => t.id !== e));
2521
+ d((t) => t.filter((t) => t.id !== e));
1446
2522
  }
1447
- let P = o === "connected" ? "Type a message… (Enter to send, Shift+Enter for new line)" : o === "connecting" ? "Connecting…" : "Not connected", F = o === "connected" && (c.trim().length > 0 || p.length > 0);
1448
- return /* @__PURE__ */ u("div", {
2523
+ let P = i === "connected" ? "Type a message… (Enter to send, Shift+Enter for new line)" : i === "connecting" ? "Connecting…" : "Not connected", F = i === "connected" && (c.trim().length > 0 || u.length > 0);
2524
+ return /* @__PURE__ */ p("div", {
1449
2525
  className: "chat-area",
1450
- children: [/* @__PURE__ */ u("div", {
2526
+ children: [/* @__PURE__ */ p("div", {
1451
2527
  className: "chat-area__messages",
1452
- children: [
1453
- n.length === 0 && /* @__PURE__ */ l("div", {
1454
- className: "chat-area__empty",
1455
- children: o === "connecting" ? "Connecting to agent…" : o === "connected" ? "Send a message to start the conversation" : o === "error" ? "Connection error — check the agent URL" : "Disconnected"
1456
- }),
1457
- n.map((e) => /* @__PURE__ */ l(W, {
1458
- message: e,
1459
- onOptionSelect: A,
1460
- onUIInteract: j
1461
- }, e.id)),
1462
- /* @__PURE__ */ l("div", { ref: y })
1463
- ]
1464
- }), /* @__PURE__ */ u("div", {
2528
+ ref: y,
2529
+ children: [e.length === 0 && /* @__PURE__ */ f("div", {
2530
+ className: "chat-area__empty",
2531
+ children: i === "connecting" ? "Connecting to agent…" : i === "connected" ? "Send a message to start the conversation" : i === "error" ? "Connection error — check the agent URL" : "Disconnected"
2532
+ }), e.map((e) => /* @__PURE__ */ f(q, {
2533
+ message: e,
2534
+ onOptionSelect: A,
2535
+ onUIInteract: j
2536
+ }, e.id))]
2537
+ }), /* @__PURE__ */ p("div", {
1465
2538
  className: "chat-area__input-row",
1466
2539
  children: [
1467
- /* @__PURE__ */ l("input", {
2540
+ /* @__PURE__ */ f("input", {
1468
2541
  ref: x,
1469
2542
  type: "file",
1470
2543
  multiple: !0,
1471
2544
  style: { display: "none" },
1472
2545
  onChange: M
1473
2546
  }),
1474
- /* @__PURE__ */ u("div", {
2547
+ /* @__PURE__ */ p("div", {
1475
2548
  className: "chat-area__composer",
1476
- children: [p.length > 0 && /* @__PURE__ */ l("div", {
2549
+ children: [u.length > 0 && /* @__PURE__ */ f("div", {
1477
2550
  className: "chat-area__attachments",
1478
- children: p.map((e) => /* @__PURE__ */ u("div", {
2551
+ children: u.map((e) => /* @__PURE__ */ p("div", {
1479
2552
  className: "attachment-chip",
1480
2553
  children: [
1481
- /* @__PURE__ */ l("span", {
2554
+ /* @__PURE__ */ f("span", {
1482
2555
  className: "attachment-chip__icon",
1483
2556
  children: "📄"
1484
2557
  }),
1485
- /* @__PURE__ */ l("span", {
2558
+ /* @__PURE__ */ f("span", {
1486
2559
  className: "attachment-chip__name",
1487
2560
  children: e.name
1488
2561
  }),
1489
- /* @__PURE__ */ l("button", {
2562
+ /* @__PURE__ */ f("button", {
1490
2563
  className: "attachment-chip__remove",
1491
2564
  onClick: () => N(e.id),
1492
2565
  title: "Remove file",
@@ -1494,79 +2567,79 @@ function ae({ messages: n, setMessages: r, status: o, send: s }) {
1494
2567
  })
1495
2568
  ]
1496
2569
  }, e.id))
1497
- }), /* @__PURE__ */ l("div", {
2570
+ }), /* @__PURE__ */ f("div", {
1498
2571
  className: "chat-area__input-line",
1499
- children: /* @__PURE__ */ l("textarea", {
2572
+ children: /* @__PURE__ */ f("textarea", {
1500
2573
  ref: b,
1501
2574
  className: "chat-area__textarea",
1502
2575
  value: c,
1503
2576
  rows: 1,
1504
2577
  placeholder: P,
1505
- disabled: o !== "connected",
2578
+ disabled: i !== "connected",
1506
2579
  onChange: (e) => {
1507
- f(e.target.value), T();
2580
+ l(e.target.value), T();
1508
2581
  },
1509
2582
  onKeyDown: k
1510
2583
  })
1511
2584
  })]
1512
2585
  }),
1513
- /* @__PURE__ */ u("div", {
2586
+ /* @__PURE__ */ p("div", {
1514
2587
  className: "attach-menu-anchor",
1515
2588
  ref: S,
1516
- children: [/* @__PURE__ */ l("button", {
2589
+ children: [/* @__PURE__ */ f("button", {
1517
2590
  className: "btn chat-area__icon-btn",
1518
2591
  title: "Attach",
1519
- disabled: o !== "connected",
2592
+ disabled: i !== "connected",
1520
2593
  onClick: () => g((e) => !e),
1521
2594
  children: "+"
1522
- }), h && /* @__PURE__ */ l("div", {
2595
+ }), h && /* @__PURE__ */ f("div", {
1523
2596
  className: "attach-menu",
1524
- children: /* @__PURE__ */ l("button", {
2597
+ children: /* @__PURE__ */ f("button", {
1525
2598
  className: "attach-menu__item",
1526
2599
  onClick: () => x.current?.click(),
1527
2600
  children: "Add Files"
1528
2601
  })
1529
2602
  })]
1530
2603
  }),
1531
- /* @__PURE__ */ l("button", {
2604
+ /* @__PURE__ */ f("button", {
1532
2605
  type: "button",
1533
2606
  className: `btn chat-area__icon-btn chat-area__mic-btn${_ ? " chat-area__mic-btn--recording" : ""}`,
1534
2607
  title: _ ? "Stop recording" : "Record voice message",
1535
- disabled: o !== "connected",
2608
+ disabled: i !== "connected",
1536
2609
  onClick: D,
1537
- children: _ ? /* @__PURE__ */ l("svg", {
2610
+ children: _ ? /* @__PURE__ */ f("svg", {
1538
2611
  width: "14",
1539
2612
  height: "14",
1540
2613
  viewBox: "0 0 14 14",
1541
2614
  fill: "currentColor",
1542
- children: /* @__PURE__ */ l("rect", {
2615
+ children: /* @__PURE__ */ f("rect", {
1543
2616
  x: "1",
1544
2617
  y: "1",
1545
2618
  width: "12",
1546
2619
  height: "12",
1547
2620
  rx: "2"
1548
2621
  })
1549
- }) : /* @__PURE__ */ u("svg", {
2622
+ }) : /* @__PURE__ */ p("svg", {
1550
2623
  width: "16",
1551
2624
  height: "16",
1552
2625
  viewBox: "0 0 16 16",
1553
2626
  fill: "currentColor",
1554
2627
  children: [
1555
- /* @__PURE__ */ l("rect", {
2628
+ /* @__PURE__ */ f("rect", {
1556
2629
  x: "5",
1557
2630
  y: "1",
1558
2631
  width: "6",
1559
2632
  height: "9",
1560
2633
  rx: "3"
1561
2634
  }),
1562
- /* @__PURE__ */ l("path", {
2635
+ /* @__PURE__ */ f("path", {
1563
2636
  d: "M3 7a5 5 0 0 0 10 0",
1564
2637
  stroke: "currentColor",
1565
2638
  strokeWidth: "1.5",
1566
2639
  fill: "none",
1567
2640
  strokeLinecap: "round"
1568
2641
  }),
1569
- /* @__PURE__ */ l("line", {
2642
+ /* @__PURE__ */ f("line", {
1570
2643
  x1: "8",
1571
2644
  y1: "12",
1572
2645
  x2: "8",
@@ -1575,7 +2648,7 @@ function ae({ messages: n, setMessages: r, status: o, send: s }) {
1575
2648
  strokeWidth: "1.5",
1576
2649
  strokeLinecap: "round"
1577
2650
  }),
1578
- /* @__PURE__ */ l("line", {
2651
+ /* @__PURE__ */ f("line", {
1579
2652
  x1: "5.5",
1580
2653
  y1: "15",
1581
2654
  x2: "10.5",
@@ -1587,7 +2660,7 @@ function ae({ messages: n, setMessages: r, status: o, send: s }) {
1587
2660
  ]
1588
2661
  })
1589
2662
  }),
1590
- /* @__PURE__ */ l("button", {
2663
+ /* @__PURE__ */ f("button", {
1591
2664
  className: "btn btn--primary chat-area__send-btn",
1592
2665
  onClick: O,
1593
2666
  disabled: !F,
@@ -1600,18 +2673,18 @@ function ae({ messages: n, setMessages: r, status: o, send: s }) {
1600
2673
  }
1601
2674
  //#endregion
1602
2675
  //#region src/hooks/useWebSocket.ts
1603
- function oe(n, r) {
1604
- let [o, s] = a("disconnected"), c = i(null), l = i(r);
1605
- return l.current = r, t(() => {
1606
- if (!n) {
1607
- s("disconnected");
2676
+ function je(e, n) {
2677
+ let [i, a] = s("disconnected"), c = o(null), l = o(n);
2678
+ return l.current = n, r(() => {
2679
+ if (!e) {
2680
+ a("disconnected");
1608
2681
  return;
1609
2682
  }
1610
- s("connecting");
1611
- let e = new WebSocket(n);
1612
- return c.current = e, e.onopen = () => {
1613
- s("connected"), l.current.onOpen?.();
1614
- }, e.onclose = () => s("disconnected"), e.onerror = () => s("error"), e.onmessage = (e) => {
2683
+ a("connecting");
2684
+ let t = new WebSocket(e);
2685
+ return c.current = t, t.onopen = () => {
2686
+ a("connected"), l.current.onOpen?.();
2687
+ }, t.onclose = () => a("disconnected"), t.onerror = () => a("error"), t.onmessage = (e) => {
1615
2688
  try {
1616
2689
  let t = JSON.parse(e.data);
1617
2690
  if (typeof t.message == "string") try {
@@ -1626,20 +2699,20 @@ function oe(n, r) {
1626
2699
  console.error("Failed to parse WS message:", e.data);
1627
2700
  }
1628
2701
  }, () => {
1629
- e.close(), c.current = null;
2702
+ t.close(), c.current = null;
1630
2703
  };
1631
- }, [n]), {
1632
- status: o,
1633
- send: e((e, t) => {
2704
+ }, [e]), {
2705
+ status: i,
2706
+ send: t((e, t) => {
1634
2707
  c.current?.readyState === WebSocket.OPEN && c.current.send(JSON.stringify({
1635
2708
  action: e,
1636
2709
  message: t
1637
2710
  }));
1638
2711
  }, []),
1639
- disconnect: e(() => {
2712
+ disconnect: t(() => {
1640
2713
  c.current?.close(), c.current = null;
1641
2714
  }, [])
1642
2715
  };
1643
2716
  }
1644
2717
  //#endregion
1645
- export { ae as ChatArea, F as GUIRenderer, W as MessageBubble, d as PayloadAction, m as REASONING_TRACE_ACTION, f as ReasoningStepKind, z as ReasoningTrace, p as TaskStatus, C as detectContentKind, v as isEmptyTrace, g as isReasoningEnd, h as isReasoningStart, S as looksLikeCode, b as looksLikeMarkdown, oe as useWebSocket, _ as visibleSteps };
2718
+ export { $ as ChatArea, U as GUIRenderer, q as MessageBubble, m as PayloadAction, _ as REASONING_TRACE_ACTION, h as ReasoningStepKind, W as ReasoningTrace, g as TaskStatus, E as detectContentKind, x as isEmptyTrace, y as isReasoningEnd, v as isReasoningStart, T as looksLikeCode, C as looksLikeMarkdown, je as useWebSocket, b as visibleSteps };