@apteva/apteva-kit 0.1.111 → 0.1.113

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1439,7 +1439,74 @@ function Table({ widget, onAction }) {
1439
1439
 
1440
1440
  // src/components/Widgets/widget-library/Form.tsx
1441
1441
 
1442
-
1442
+ var _reactdom = require('react-dom');
1443
+
1444
+ function PortalDropdown({
1445
+ anchorRef,
1446
+ open,
1447
+ onClose,
1448
+ width,
1449
+ children
1450
+ }) {
1451
+ const dropdownRef = _react.useRef.call(void 0, null);
1452
+ const [pos, setPos] = _react.useState.call(void 0, { top: 0, left: 0, width: 0 });
1453
+ _react.useEffect.call(void 0, () => {
1454
+ if (!open || !anchorRef.current) return;
1455
+ const update = () => {
1456
+ const rect = anchorRef.current.getBoundingClientRect();
1457
+ setPos({
1458
+ top: rect.bottom + window.scrollY + 4,
1459
+ left: rect.left + window.scrollX,
1460
+ width: rect.width
1461
+ });
1462
+ };
1463
+ update();
1464
+ window.addEventListener("scroll", update, true);
1465
+ window.addEventListener("resize", update);
1466
+ return () => {
1467
+ window.removeEventListener("scroll", update, true);
1468
+ window.removeEventListener("resize", update);
1469
+ };
1470
+ }, [open, anchorRef]);
1471
+ _react.useEffect.call(void 0, () => {
1472
+ if (!open) return;
1473
+ const handler = (e) => {
1474
+ const target = e.target;
1475
+ if (dropdownRef.current && !dropdownRef.current.contains(target) && anchorRef.current && !anchorRef.current.contains(target)) {
1476
+ onClose();
1477
+ }
1478
+ };
1479
+ document.addEventListener("mousedown", handler);
1480
+ return () => document.removeEventListener("mousedown", handler);
1481
+ }, [open, onClose, anchorRef]);
1482
+ _react.useEffect.call(void 0, () => {
1483
+ if (!open) return;
1484
+ const handler = (e) => {
1485
+ if (e.key === "Escape") onClose();
1486
+ };
1487
+ document.addEventListener("keydown", handler);
1488
+ return () => document.removeEventListener("keydown", handler);
1489
+ }, [open, onClose]);
1490
+ if (!open) return null;
1491
+ return _reactdom.createPortal.call(void 0,
1492
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
1493
+ "div",
1494
+ {
1495
+ ref: dropdownRef,
1496
+ className: "apteva-widget",
1497
+ style: {
1498
+ position: "absolute",
1499
+ top: pos.top,
1500
+ left: pos.left,
1501
+ width: width === "match" ? pos.width : void 0,
1502
+ zIndex: 99999
1503
+ },
1504
+ children
1505
+ }
1506
+ ),
1507
+ document.body
1508
+ );
1509
+ }
1443
1510
  function CustomSelect({
1444
1511
  name,
1445
1512
  value,
@@ -1449,17 +1516,10 @@ function CustomSelect({
1449
1516
  onChange
1450
1517
  }) {
1451
1518
  const [open, setOpen] = _react.useState.call(void 0, false);
1452
- const ref = _react.useRef.call(void 0, null);
1519
+ const triggerRef = _react.useRef.call(void 0, null);
1453
1520
  const selected = _optionalChain([options, 'optionalAccess', _18 => _18.find, 'call', _19 => _19((o) => o.value === value)]);
1454
- _react.useEffect.call(void 0, () => {
1455
- if (!open) return;
1456
- const handler = (e) => {
1457
- if (ref.current && !ref.current.contains(e.target)) setOpen(false);
1458
- };
1459
- document.addEventListener("mousedown", handler);
1460
- return () => document.removeEventListener("mousedown", handler);
1461
- }, [open]);
1462
- return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { ref, className: "apteva-select relative", children: [
1521
+ const close = _react.useCallback.call(void 0, () => setOpen(false), []);
1522
+ return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "apteva-select relative", children: [
1463
1523
  /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
1464
1524
  "select",
1465
1525
  {
@@ -1480,6 +1540,7 @@ function CustomSelect({
1480
1540
  /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
1481
1541
  "button",
1482
1542
  {
1543
+ ref: triggerRef,
1483
1544
  type: "button",
1484
1545
  onClick: () => setOpen(!open),
1485
1546
  className: "apteva-select-trigger w-full flex items-center justify-between px-3 py-2 rounded-lg border transition-colors text-left",
@@ -1498,14 +1559,14 @@ function CustomSelect({
1498
1559
  ]
1499
1560
  }
1500
1561
  ),
1501
- open && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "apteva-select-dropdown absolute z-50 w-full mt-1 rounded-lg border shadow-lg overflow-hidden", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "max-h-48 overflow-y-auto py-1", children: [
1562
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, PortalDropdown, { anchorRef: triggerRef, open, onClose: close, width: "match", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "apteva-select-dropdown rounded-lg border shadow-lg overflow-hidden", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "max-h-48 overflow-y-auto py-1", children: [
1502
1563
  _optionalChain([options, 'optionalAccess', _22 => _22.map, 'call', _23 => _23((opt) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
1503
1564
  "button",
1504
1565
  {
1505
1566
  type: "button",
1506
1567
  onClick: () => {
1507
1568
  onChange(opt.value);
1508
- setOpen(false);
1569
+ close();
1509
1570
  },
1510
1571
  className: `apteva-select-option w-full text-left px-3 py-2 text-sm transition-colors ${opt.value === value ? "apteva-select-option-active" : ""}`,
1511
1572
  children: opt.label
@@ -1513,7 +1574,7 @@ function CustomSelect({
1513
1574
  opt.value
1514
1575
  ))]),
1515
1576
  (!options || options.length === 0) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "px-3 py-2 text-sm apteva-select-placeholder", children: "No options" })
1516
- ] }) })
1577
+ ] }) }) })
1517
1578
  ] });
1518
1579
  }
1519
1580
  function CustomDatePicker({
@@ -1524,7 +1585,8 @@ function CustomDatePicker({
1524
1585
  onChange
1525
1586
  }) {
1526
1587
  const [open, setOpen] = _react.useState.call(void 0, false);
1527
- const ref = _react.useRef.call(void 0, null);
1588
+ const triggerRef = _react.useRef.call(void 0, null);
1589
+ const close = _react.useCallback.call(void 0, () => setOpen(false), []);
1528
1590
  const parseDate = (v) => {
1529
1591
  if (v) {
1530
1592
  const [y, m, d] = v.split("-").map(Number);
@@ -1536,14 +1598,6 @@ function CustomDatePicker({
1536
1598
  const parsed = parseDate(value);
1537
1599
  const [viewYear, setViewYear] = _react.useState.call(void 0, parsed.year);
1538
1600
  const [viewMonth, setViewMonth] = _react.useState.call(void 0, parsed.month);
1539
- _react.useEffect.call(void 0, () => {
1540
- if (!open) return;
1541
- const handler = (e) => {
1542
- if (ref.current && !ref.current.contains(e.target)) setOpen(false);
1543
- };
1544
- document.addEventListener("mousedown", handler);
1545
- return () => document.removeEventListener("mousedown", handler);
1546
- }, [open]);
1547
1601
  _react.useEffect.call(void 0, () => {
1548
1602
  if (value) {
1549
1603
  const p = parseDate(value);
@@ -1570,7 +1624,7 @@ function CustomDatePicker({
1570
1624
  const m = String(viewMonth + 1).padStart(2, "0");
1571
1625
  const d = String(day).padStart(2, "0");
1572
1626
  onChange(`${viewYear}-${m}-${d}`);
1573
- setOpen(false);
1627
+ close();
1574
1628
  };
1575
1629
  const formatDisplay = (v) => {
1576
1630
  if (!v) return "";
@@ -1588,7 +1642,7 @@ function CustomDatePicker({
1588
1642
  const now = /* @__PURE__ */ new Date();
1589
1643
  return now.getFullYear() === viewYear && now.getMonth() === viewMonth && now.getDate() === day;
1590
1644
  };
1591
- return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { ref, className: "apteva-datepicker relative", children: [
1645
+ return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "apteva-datepicker relative", children: [
1592
1646
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
1593
1647
  "input",
1594
1648
  {
@@ -1606,6 +1660,7 @@ function CustomDatePicker({
1606
1660
  /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
1607
1661
  "button",
1608
1662
  {
1663
+ ref: triggerRef,
1609
1664
  type: "button",
1610
1665
  onClick: () => setOpen(!open),
1611
1666
  className: "apteva-datepicker-trigger w-full flex items-center justify-between px-3 py-2 rounded-lg border transition-colors text-left",
@@ -1615,7 +1670,7 @@ function CustomDatePicker({
1615
1670
  ]
1616
1671
  }
1617
1672
  ),
1618
- open && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "apteva-datepicker-dropdown absolute z-50 mt-1 rounded-lg border shadow-lg overflow-hidden", children: [
1673
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, PortalDropdown, { anchorRef: triggerRef, open, onClose: close, width: "auto", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "apteva-datepicker-dropdown rounded-lg border shadow-lg overflow-hidden", children: [
1619
1674
  /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "apteva-datepicker-header flex items-center justify-between px-3 py-2", children: [
1620
1675
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "button", { type: "button", onClick: prevMonth, className: "apteva-datepicker-nav p-1 rounded transition-colors", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M15 19l-7-7 7-7" }) }) }),
1621
1676
  /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { className: "apteva-datepicker-title text-sm font-semibold", children: [
@@ -1648,7 +1703,7 @@ function CustomDatePicker({
1648
1703
  );
1649
1704
  })
1650
1705
  ] })
1651
- ] })
1706
+ ] }) })
1652
1707
  ] });
1653
1708
  }
1654
1709
  function Form({ widget, onAction }) {
@@ -3283,7 +3338,11 @@ function MessageList({
3283
3338
  // src/components/Chat/Composer.tsx
3284
3339
 
3285
3340
 
3286
- function Composer({ onSendMessage, placeholder = "Type a message...", disabled = false, isLoading = false, onStop, onFileUpload, onSwitchMode }) {
3341
+ var getSpeechRecognition = () => {
3342
+ if (typeof window === "undefined") return null;
3343
+ return window.SpeechRecognition || window.webkitSpeechRecognition || null;
3344
+ };
3345
+ function Composer({ onSendMessage, placeholder = "Type a message...", disabled = false, isLoading = false, onStop, onFileUpload, onSwitchMode, speechToText }) {
3287
3346
  const [text, setText] = _react.useState.call(void 0, "");
3288
3347
  const [showMenu, setShowMenu] = _react.useState.call(void 0, false);
3289
3348
  const [pendingFiles, setPendingFiles] = _react.useState.call(void 0, []);
@@ -3292,6 +3351,190 @@ function Composer({ onSendMessage, placeholder = "Type a message...", disabled =
3292
3351
  const textareaRef = _react.useRef.call(void 0, null);
3293
3352
  const fileInputRef = _react.useRef.call(void 0, null);
3294
3353
  const menuButtonRef = _react.useRef.call(void 0, null);
3354
+ const [isRecording, setIsRecording] = _react.useState.call(void 0, false);
3355
+ const [recordingTime, setRecordingTime] = _react.useState.call(void 0, 0);
3356
+ const [transcriptFlash, setTranscriptFlash] = _react.useState.call(void 0, null);
3357
+ const recognitionRef = _react.useRef.call(void 0, null);
3358
+ const mediaStreamRef = _react.useRef.call(void 0, null);
3359
+ const audioContextRef = _react.useRef.call(void 0, null);
3360
+ const analyserRef = _react.useRef.call(void 0, null);
3361
+ const canvasRef = _react.useRef.call(void 0, null);
3362
+ const animFrameRef = _react.useRef.call(void 0, 0);
3363
+ const silenceTimerRef = _react.useRef.call(void 0, null);
3364
+ const recordingTimerRef = _react.useRef.call(void 0, null);
3365
+ const finalTranscriptRef = _react.useRef.call(void 0, "");
3366
+ const manualStopRef = _react.useRef.call(void 0, false);
3367
+ const sttConfig = speechToText ? typeof speechToText === "object" ? speechToText : {} : null;
3368
+ const sttSupported = !!sttConfig && !!getSpeechRecognition();
3369
+ const silenceTimeout = _nullishCoalesce(_optionalChain([sttConfig, 'optionalAccess', _54 => _54.silenceTimeout]), () => ( 2e3));
3370
+ const autoSend = _optionalChain([sttConfig, 'optionalAccess', _55 => _55.autoSend]) !== false;
3371
+ _react.useEffect.call(void 0, () => {
3372
+ return () => {
3373
+ stopRecording(true);
3374
+ };
3375
+ }, []);
3376
+ const drawWaveform = _react.useCallback.call(void 0, () => {
3377
+ const canvas = canvasRef.current;
3378
+ const analyser = analyserRef.current;
3379
+ if (!canvas || !analyser) return;
3380
+ const ctx = canvas.getContext("2d");
3381
+ if (!ctx) return;
3382
+ const bufferLength = analyser.frequencyBinCount;
3383
+ const dataArray = new Uint8Array(bufferLength);
3384
+ const draw = () => {
3385
+ animFrameRef.current = requestAnimationFrame(draw);
3386
+ analyser.getByteTimeDomainData(dataArray);
3387
+ const { width, height } = canvas;
3388
+ ctx.clearRect(0, 0, width, height);
3389
+ const barCount = 32;
3390
+ const barWidth = Math.max(2, (width - (barCount - 1) * 2) / barCount);
3391
+ const gap = 2;
3392
+ const samplesPerBar = Math.floor(bufferLength / barCount);
3393
+ for (let i = 0; i < barCount; i++) {
3394
+ let sum = 0;
3395
+ for (let j = 0; j < samplesPerBar; j++) {
3396
+ const val = dataArray[i * samplesPerBar + j] - 128;
3397
+ sum += Math.abs(val);
3398
+ }
3399
+ const avg = sum / samplesPerBar;
3400
+ const barHeight = Math.max(3, avg / 128 * height * 2.5);
3401
+ const x = i * (barWidth + gap);
3402
+ const y = (height - barHeight) / 2;
3403
+ ctx.fillStyle = "#3b82f6";
3404
+ ctx.beginPath();
3405
+ ctx.roundRect(x, y, barWidth, barHeight, barWidth / 2);
3406
+ ctx.fill();
3407
+ }
3408
+ };
3409
+ draw();
3410
+ }, []);
3411
+ const startRecording = _react.useCallback.call(void 0, async () => {
3412
+ const SpeechRecognitionCtor = getSpeechRecognition();
3413
+ if (!SpeechRecognitionCtor) return;
3414
+ try {
3415
+ const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
3416
+ mediaStreamRef.current = stream;
3417
+ const audioCtx = new AudioContext();
3418
+ audioContextRef.current = audioCtx;
3419
+ const source = audioCtx.createMediaStreamSource(stream);
3420
+ const analyser = audioCtx.createAnalyser();
3421
+ analyser.fftSize = 256;
3422
+ source.connect(analyser);
3423
+ analyserRef.current = analyser;
3424
+ const recognition = new SpeechRecognitionCtor();
3425
+ recognition.continuous = true;
3426
+ recognition.interimResults = true;
3427
+ recognition.lang = _optionalChain([sttConfig, 'optionalAccess', _56 => _56.language]) || navigator.language || "en-US";
3428
+ recognitionRef.current = recognition;
3429
+ finalTranscriptRef.current = "";
3430
+ manualStopRef.current = false;
3431
+ recognition.onresult = (event) => {
3432
+ let final = "";
3433
+ let interim = "";
3434
+ for (let i = 0; i < event.results.length; i++) {
3435
+ const result = event.results[i];
3436
+ if (result.isFinal) {
3437
+ final += result[0].transcript;
3438
+ } else {
3439
+ interim += result[0].transcript;
3440
+ }
3441
+ }
3442
+ finalTranscriptRef.current = final;
3443
+ if (silenceTimerRef.current) {
3444
+ clearTimeout(silenceTimerRef.current);
3445
+ }
3446
+ silenceTimerRef.current = setTimeout(() => {
3447
+ stopRecording(false);
3448
+ }, silenceTimeout);
3449
+ };
3450
+ recognition.onerror = (event) => {
3451
+ if (event.error !== "aborted") {
3452
+ console.warn("Speech recognition error:", event.error);
3453
+ }
3454
+ stopRecording(true);
3455
+ };
3456
+ recognition.onend = () => {
3457
+ if (!manualStopRef.current && isRecording) {
3458
+ finishRecording();
3459
+ }
3460
+ };
3461
+ recognition.start();
3462
+ setIsRecording(true);
3463
+ setRecordingTime(0);
3464
+ recordingTimerRef.current = setInterval(() => {
3465
+ setRecordingTime((t) => t + 1);
3466
+ }, 1e3);
3467
+ requestAnimationFrame(() => drawWaveform());
3468
+ silenceTimerRef.current = setTimeout(() => {
3469
+ stopRecording(false);
3470
+ }, silenceTimeout + 1e3);
3471
+ } catch (err) {
3472
+ console.warn("Microphone access denied or error:", err);
3473
+ setFileError("Microphone access denied");
3474
+ setTimeout(() => setFileError(null), 3e3);
3475
+ }
3476
+ }, [_optionalChain([sttConfig, 'optionalAccess', _57 => _57.language]), silenceTimeout, drawWaveform]);
3477
+ const finishRecording = _react.useCallback.call(void 0, () => {
3478
+ const transcript = finalTranscriptRef.current.trim();
3479
+ setIsRecording(false);
3480
+ setRecordingTime(0);
3481
+ if (transcript) {
3482
+ if (autoSend) {
3483
+ setTranscriptFlash(transcript);
3484
+ setTimeout(() => {
3485
+ setTranscriptFlash(null);
3486
+ onSendMessage(transcript);
3487
+ }, 600);
3488
+ } else {
3489
+ setText((prev) => prev ? `${prev} ${transcript}` : transcript);
3490
+ }
3491
+ }
3492
+ }, [autoSend, onSendMessage]);
3493
+ const stopRecording = _react.useCallback.call(void 0, (isCleanupOnly) => {
3494
+ manualStopRef.current = true;
3495
+ if (silenceTimerRef.current) {
3496
+ clearTimeout(silenceTimerRef.current);
3497
+ silenceTimerRef.current = null;
3498
+ }
3499
+ if (recordingTimerRef.current) {
3500
+ clearInterval(recordingTimerRef.current);
3501
+ recordingTimerRef.current = null;
3502
+ }
3503
+ if (animFrameRef.current) {
3504
+ cancelAnimationFrame(animFrameRef.current);
3505
+ animFrameRef.current = 0;
3506
+ }
3507
+ if (recognitionRef.current) {
3508
+ try {
3509
+ recognitionRef.current.stop();
3510
+ } catch (_e) {
3511
+ }
3512
+ recognitionRef.current = null;
3513
+ }
3514
+ if (mediaStreamRef.current) {
3515
+ mediaStreamRef.current.getTracks().forEach((t) => t.stop());
3516
+ mediaStreamRef.current = null;
3517
+ }
3518
+ if (audioContextRef.current) {
3519
+ try {
3520
+ audioContextRef.current.close();
3521
+ } catch (_e) {
3522
+ }
3523
+ audioContextRef.current = null;
3524
+ }
3525
+ analyserRef.current = null;
3526
+ if (!isCleanupOnly) {
3527
+ finishRecording();
3528
+ } else {
3529
+ setIsRecording(false);
3530
+ setRecordingTime(0);
3531
+ }
3532
+ }, [finishRecording]);
3533
+ const formatTime = (seconds) => {
3534
+ const m = Math.floor(seconds / 60);
3535
+ const s = seconds % 60;
3536
+ return `${m.toString().padStart(2, "0")}:${s.toString().padStart(2, "0")}`;
3537
+ };
3295
3538
  const handleKeyDown = (e) => {
3296
3539
  if (e.key === "Enter" && !e.shiftKey) {
3297
3540
  e.preventDefault();
@@ -3351,7 +3594,7 @@ function Composer({ onSendMessage, placeholder = "Type a message...", disabled =
3351
3594
  setFileError(errors.join(", "));
3352
3595
  setTimeout(() => setFileError(null), 5e3);
3353
3596
  }
3354
- _optionalChain([onFileUpload, 'optionalCall', _54 => _54(e.target.files)]);
3597
+ _optionalChain([onFileUpload, 'optionalCall', _58 => _58(e.target.files)]);
3355
3598
  setShowMenu(false);
3356
3599
  e.target.value = "";
3357
3600
  }
@@ -3374,12 +3617,17 @@ function Composer({ onSendMessage, placeholder = "Type a message...", disabled =
3374
3617
  }
3375
3618
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" }) });
3376
3619
  };
3620
+ const hasMic = sttSupported && !isRecording;
3621
+ const gridCols = hasMic ? "auto 1fr auto auto" : "auto 1fr auto";
3622
+ const gridAreas = isRecording ? '"plus waveform waveform stop"' : isMultiLine ? hasMic ? '"textarea textarea textarea textarea" "plus . mic send"' : '"textarea textarea textarea" "plus . send"' : hasMic ? '"plus textarea mic send"' : '"plus textarea send"';
3623
+ const gridColsRecording = "auto 1fr auto";
3377
3624
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "px-4 py-3 relative", children: [
3378
3625
  fileError && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "apteva-file-error", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "apteva-file-error-content", children: [
3379
3626
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" }) }),
3380
3627
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: fileError })
3381
3628
  ] }) }),
3382
- pendingFiles.length > 0 && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "apteva-file-preview", children: pendingFiles.map((pf, index) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "apteva-file-item", children: [
3629
+ transcriptFlash && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "apteva-transcript-flash", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: transcriptFlash }) }),
3630
+ pendingFiles.length > 0 && !isRecording && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "apteva-file-preview", children: pendingFiles.map((pf, index) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "apteva-file-item", children: [
3383
3631
  pf.preview ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "img", { src: pf.preview, alt: pf.file.name, className: "apteva-file-thumb" }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "apteva-file-icon", children: getFileIcon(pf.file.type) }),
3384
3632
  /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "apteva-file-info", children: [
3385
3633
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "apteva-file-name", children: pf.file.name }),
@@ -3400,12 +3648,12 @@ function Composer({ onSendMessage, placeholder = "Type a message...", disabled =
3400
3648
  {
3401
3649
  className: "apteva-composer",
3402
3650
  style: {
3403
- gridTemplateColumns: "auto 1fr auto",
3404
- gridTemplateAreas: isMultiLine ? '"textarea textarea textarea" "plus . send"' : '"plus textarea send"',
3651
+ gridTemplateColumns: isRecording ? gridColsRecording : gridCols,
3652
+ gridTemplateAreas: isRecording ? '"plus waveform stop"' : gridAreas,
3405
3653
  alignItems: "end"
3406
3654
  },
3407
3655
  children: [
3408
- /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "relative flex-shrink-0 self-end", style: { gridArea: "plus" }, children: [
3656
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "relative flex-shrink-0 self-end", style: { gridArea: "plus" }, children: isRecording ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "apteva-composer-rec-dot", title: "Recording...", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", {}) }) : /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
3409
3657
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
3410
3658
  "button",
3411
3659
  {
@@ -3423,15 +3671,15 @@ function Composer({ onSendMessage, placeholder = "Type a message...", disabled =
3423
3671
  {
3424
3672
  className: "apteva-composer-menu fixed bg-neutral-800 dark:bg-neutral-800 rounded-xl shadow-lg overflow-hidden z-[9999] min-w-[200px]",
3425
3673
  style: {
3426
- left: _nullishCoalesce(_optionalChain([menuButtonRef, 'access', _55 => _55.current, 'optionalAccess', _56 => _56.getBoundingClientRect, 'call', _57 => _57(), 'access', _58 => _58.left]), () => ( 0)),
3427
- bottom: window.innerHeight - (_nullishCoalesce(_optionalChain([menuButtonRef, 'access', _59 => _59.current, 'optionalAccess', _60 => _60.getBoundingClientRect, 'call', _61 => _61(), 'access', _62 => _62.top]), () => ( 0))) + 8
3674
+ left: _nullishCoalesce(_optionalChain([menuButtonRef, 'access', _59 => _59.current, 'optionalAccess', _60 => _60.getBoundingClientRect, 'call', _61 => _61(), 'access', _62 => _62.left]), () => ( 0)),
3675
+ bottom: window.innerHeight - (_nullishCoalesce(_optionalChain([menuButtonRef, 'access', _63 => _63.current, 'optionalAccess', _64 => _64.getBoundingClientRect, 'call', _65 => _65(), 'access', _66 => _66.top]), () => ( 0))) + 8
3428
3676
  },
3429
3677
  children: [
3430
3678
  /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
3431
3679
  "button",
3432
3680
  {
3433
3681
  onClick: () => {
3434
- _optionalChain([fileInputRef, 'access', _63 => _63.current, 'optionalAccess', _64 => _64.click, 'call', _65 => _65()]);
3682
+ _optionalChain([fileInputRef, 'access', _67 => _67.current, 'optionalAccess', _68 => _68.click, 'call', _69 => _69()]);
3435
3683
  setShowMenu(false);
3436
3684
  },
3437
3685
  className: "w-full flex items-center gap-3 px-4 py-3 hover:bg-neutral-700 dark:hover:bg-neutral-700 transition-colors !text-white text-left",
@@ -3459,39 +3707,77 @@ function Composer({ onSendMessage, placeholder = "Type a message...", disabled =
3459
3707
  }
3460
3708
  )
3461
3709
  ] })
3462
- ] }),
3463
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
3464
- "textarea",
3465
- {
3466
- ref: textareaRef,
3467
- value: text,
3468
- onChange: handleChange,
3469
- onKeyDown: handleKeyDown,
3470
- placeholder,
3471
- disabled,
3472
- className: "apteva-composer-textarea resize-none bg-transparent border-none focus:outline-none !text-neutral-900 dark:!text-neutral-100 placeholder-neutral-400 dark:placeholder-neutral-500 py-1 disabled:opacity-50 disabled:cursor-not-allowed overflow-y-auto max-h-[200px]",
3473
- style: { gridArea: "textarea" },
3474
- rows: 1
3475
- }
3476
- ),
3477
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "self-end", style: { gridArea: "send" }, children: isLoading && onStop ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
3478
- "button",
3479
- {
3480
- onClick: onStop,
3481
- className: "apteva-composer-stop-btn",
3482
- title: "Stop generation",
3483
- children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "rect", { x: "2", y: "2", width: "10", height: "10", rx: "1", fill: "currentColor" }) })
3484
- }
3485
- ) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
3486
- "button",
3487
- {
3488
- onClick: handleSend,
3489
- disabled: !text.trim() && pendingFiles.length === 0 || disabled,
3490
- className: "apteva-composer-send-btn w-8 h-8 rounded-lg flex items-center justify-center font-bold transition-all flex-shrink-0 border border-neutral-300 dark:border-neutral-600 bg-white dark:bg-neutral-800 !text-neutral-700 dark:!text-neutral-300 hover:bg-neutral-50 dark:hover:bg-neutral-700 disabled:opacity-30 disabled:cursor-not-allowed !text-lg",
3491
- title: "Send message",
3492
- children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "M8 3L8 13M8 3L4 7M8 3L12 7", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) })
3493
- }
3494
- ) })
3710
+ ] }) }),
3711
+ isRecording ? /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
3712
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "apteva-composer-waveform", style: { gridArea: "waveform" }, children: [
3713
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
3714
+ "canvas",
3715
+ {
3716
+ ref: canvasRef,
3717
+ width: 300,
3718
+ height: 36,
3719
+ className: "apteva-composer-waveform-canvas"
3720
+ }
3721
+ ),
3722
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "apteva-composer-recording-timer", children: formatTime(recordingTime) })
3723
+ ] }),
3724
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "self-end", style: { gridArea: "stop" }, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
3725
+ "button",
3726
+ {
3727
+ onClick: () => stopRecording(false),
3728
+ className: "apteva-composer-stop-btn",
3729
+ title: "Stop recording",
3730
+ children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "rect", { x: "2", y: "2", width: "10", height: "10", rx: "1", fill: "currentColor" }) })
3731
+ }
3732
+ ) })
3733
+ ] }) : /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
3734
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
3735
+ "textarea",
3736
+ {
3737
+ ref: textareaRef,
3738
+ value: text,
3739
+ onChange: handleChange,
3740
+ onKeyDown: handleKeyDown,
3741
+ placeholder,
3742
+ disabled,
3743
+ className: "apteva-composer-textarea resize-none bg-transparent border-none focus:outline-none !text-neutral-900 dark:!text-neutral-100 placeholder-neutral-400 dark:placeholder-neutral-500 py-1 disabled:opacity-50 disabled:cursor-not-allowed overflow-y-auto max-h-[200px]",
3744
+ style: { gridArea: "textarea" },
3745
+ rows: 1
3746
+ }
3747
+ ),
3748
+ sttSupported && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "self-end", style: { gridArea: "mic" }, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
3749
+ "button",
3750
+ {
3751
+ onClick: startRecording,
3752
+ disabled: disabled || isLoading,
3753
+ className: "apteva-composer-mic-btn",
3754
+ title: "Voice input",
3755
+ children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
3756
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "M12 1a3 3 0 00-3 3v8a3 3 0 006 0V4a3 3 0 00-3-3z", fill: "currentColor" }),
3757
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "M19 10v2a7 7 0 01-14 0v-2", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }),
3758
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "M12 19v4M8 23h8", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" })
3759
+ ] })
3760
+ }
3761
+ ) }),
3762
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "self-end", style: { gridArea: "send" }, children: isLoading && onStop ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
3763
+ "button",
3764
+ {
3765
+ onClick: onStop,
3766
+ className: "apteva-composer-stop-btn",
3767
+ title: "Stop generation",
3768
+ children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "rect", { x: "2", y: "2", width: "10", height: "10", rx: "1", fill: "currentColor" }) })
3769
+ }
3770
+ ) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
3771
+ "button",
3772
+ {
3773
+ onClick: handleSend,
3774
+ disabled: !text.trim() && pendingFiles.length === 0 || disabled,
3775
+ className: "apteva-composer-send-btn w-8 h-8 rounded-lg flex items-center justify-center font-bold transition-all flex-shrink-0 border border-neutral-300 dark:border-neutral-600 bg-white dark:bg-neutral-800 !text-neutral-700 dark:!text-neutral-300 hover:bg-neutral-50 dark:hover:bg-neutral-700 disabled:opacity-30 disabled:cursor-not-allowed !text-lg",
3776
+ title: "Send message",
3777
+ children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "M8 3L8 13M8 3L4 7M8 3L12 7", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) })
3778
+ }
3779
+ ) })
3780
+ ] })
3495
3781
  ]
3496
3782
  }
3497
3783
  ),
@@ -3552,8 +3838,8 @@ function CommandComposer({
3552
3838
  }
3553
3839
  };
3554
3840
  const handleNewCommand = () => {
3555
- _optionalChain([onReset, 'optionalCall', _66 => _66()]);
3556
- _optionalChain([inputRef, 'access', _67 => _67.current, 'optionalAccess', _68 => _68.focus, 'call', _69 => _69()]);
3841
+ _optionalChain([onReset, 'optionalCall', _70 => _70()]);
3842
+ _optionalChain([inputRef, 'access', _71 => _71.current, 'optionalAccess', _72 => _72.focus, 'call', _73 => _73()]);
3557
3843
  };
3558
3844
  const handleInputChange = (value) => {
3559
3845
  setInput(value);
@@ -3667,15 +3953,15 @@ function CommandComposer({
3667
3953
  {
3668
3954
  className: "apteva-composer-menu fixed bg-neutral-800 dark:bg-neutral-800 rounded-xl shadow-lg overflow-hidden z-[9999] min-w-[200px]",
3669
3955
  style: {
3670
- left: _nullishCoalesce(_optionalChain([menuButtonRef, 'access', _70 => _70.current, 'optionalAccess', _71 => _71.getBoundingClientRect, 'call', _72 => _72(), 'access', _73 => _73.left]), () => ( 0)),
3671
- top: (_nullishCoalesce(_optionalChain([menuButtonRef, 'access', _74 => _74.current, 'optionalAccess', _75 => _75.getBoundingClientRect, 'call', _76 => _76(), 'access', _77 => _77.bottom]), () => ( 0))) + 8
3956
+ left: _nullishCoalesce(_optionalChain([menuButtonRef, 'access', _74 => _74.current, 'optionalAccess', _75 => _75.getBoundingClientRect, 'call', _76 => _76(), 'access', _77 => _77.left]), () => ( 0)),
3957
+ top: (_nullishCoalesce(_optionalChain([menuButtonRef, 'access', _78 => _78.current, 'optionalAccess', _79 => _79.getBoundingClientRect, 'call', _80 => _80(), 'access', _81 => _81.bottom]), () => ( 0))) + 8
3672
3958
  },
3673
3959
  children: [
3674
3960
  /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
3675
3961
  "button",
3676
3962
  {
3677
3963
  onClick: () => {
3678
- _optionalChain([fileInputRef, 'access', _78 => _78.current, 'optionalAccess', _79 => _79.click, 'call', _80 => _80()]);
3964
+ _optionalChain([fileInputRef, 'access', _82 => _82.current, 'optionalAccess', _83 => _83.click, 'call', _84 => _84()]);
3679
3965
  setShowMenu(false);
3680
3966
  },
3681
3967
  className: "w-full flex items-center gap-3 px-4 py-3 hover:bg-neutral-700 dark:hover:bg-neutral-700 transition-colors !text-white text-left",
@@ -3828,8 +4114,8 @@ var AptevaClient = class {
3828
4114
  constructor(config) {
3829
4115
  __publicField(this, "config");
3830
4116
  this.config = {
3831
- apiUrl: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _81 => _81.apiUrl]), () => ( "")),
3832
- apiKey: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _82 => _82.apiKey]), () => ( ""))
4117
+ apiUrl: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _85 => _85.apiUrl]), () => ( "")),
4118
+ apiKey: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _86 => _86.apiKey]), () => ( ""))
3833
4119
  };
3834
4120
  }
3835
4121
  /**
@@ -3906,7 +4192,7 @@ var AptevaClient = class {
3906
4192
  const error = await response.json().catch(() => ({ error: "Request failed" }));
3907
4193
  throw new Error(error.error || `Request failed with status ${response.status}`);
3908
4194
  }
3909
- const reader = _optionalChain([response, 'access', _83 => _83.body, 'optionalAccess', _84 => _84.getReader, 'call', _85 => _85()]);
4195
+ const reader = _optionalChain([response, 'access', _87 => _87.body, 'optionalAccess', _88 => _88.getReader, 'call', _89 => _89()]);
3910
4196
  if (!reader) {
3911
4197
  throw new Error("Response body is not readable");
3912
4198
  }
@@ -3924,7 +4210,7 @@ var AptevaClient = class {
3924
4210
  if (line.startsWith("data: ")) {
3925
4211
  const data = line.slice(6);
3926
4212
  if (data === "[DONE]") {
3927
- _optionalChain([onComplete, 'optionalCall', _86 => _86(threadId)]);
4213
+ _optionalChain([onComplete, 'optionalCall', _90 => _90(threadId)]);
3928
4214
  return;
3929
4215
  }
3930
4216
  try {
@@ -3939,10 +4225,10 @@ var AptevaClient = class {
3939
4225
  }
3940
4226
  }
3941
4227
  }
3942
- _optionalChain([onComplete, 'optionalCall', _87 => _87(threadId)]);
4228
+ _optionalChain([onComplete, 'optionalCall', _91 => _91(threadId)]);
3943
4229
  } catch (error) {
3944
4230
  const err = error instanceof Error ? error : new Error("Unknown error");
3945
- _optionalChain([onError, 'optionalCall', _88 => _88(err)]);
4231
+ _optionalChain([onError, 'optionalCall', _92 => _92(err)]);
3946
4232
  throw err;
3947
4233
  }
3948
4234
  }
@@ -4090,6 +4376,8 @@ var Chat = _react.forwardRef.call(void 0, function Chat2({
4090
4376
  availableWidgets,
4091
4377
  compactWidgetContext = false,
4092
4378
  onWidgetRender,
4379
+ // Speech to text
4380
+ speechToText,
4093
4381
  className
4094
4382
  }, ref) {
4095
4383
  const [messages, setMessages] = _react.useState.call(void 0, initialMessages);
@@ -4165,7 +4453,7 @@ ${widgetContext}` : widgetContext;
4165
4453
  }, [apiUrl, apiKey]);
4166
4454
  _react.useEffect.call(void 0, () => {
4167
4455
  if (threadId) {
4168
- _optionalChain([onThreadChange, 'optionalCall', _89 => _89(threadId)]);
4456
+ _optionalChain([onThreadChange, 'optionalCall', _93 => _93(threadId)]);
4169
4457
  }
4170
4458
  }, [threadId, onThreadChange]);
4171
4459
  _react.useEffect.call(void 0, () => {
@@ -4183,7 +4471,7 @@ ${widgetContext}` : widgetContext;
4183
4471
  }, [showSettingsMenu]);
4184
4472
  const handleModeChange = (newMode) => {
4185
4473
  setMode(newMode);
4186
- _optionalChain([onModeChange, 'optionalCall', _90 => _90(newMode)]);
4474
+ _optionalChain([onModeChange, 'optionalCall', _94 => _94(newMode)]);
4187
4475
  if (newMode === "command") {
4188
4476
  setCommandState("idle");
4189
4477
  setCommandResult(null);
@@ -4192,8 +4480,8 @@ ${widgetContext}` : widgetContext;
4192
4480
  };
4193
4481
  const defaultPlaceholder = mode === "chat" ? "Type a message..." : "Enter your command...";
4194
4482
  const handleWidgetAction = _react.useCallback.call(void 0, (action) => {
4195
- _optionalChain([onAction, 'optionalCall', _91 => _91(action)]);
4196
- if (action.type === "submit" && _optionalChain([action, 'access', _92 => _92.payload, 'optionalAccess', _93 => _93.formData])) {
4483
+ _optionalChain([onAction, 'optionalCall', _95 => _95(action)]);
4484
+ if (action.type === "submit" && _optionalChain([action, 'access', _96 => _96.payload, 'optionalAccess', _97 => _97.formData])) {
4197
4485
  const formData = action.payload.formData;
4198
4486
  const lines = [];
4199
4487
  for (const [key, value] of Object.entries(formData)) {
@@ -4232,7 +4520,7 @@ ${widgetContext}` : widgetContext;
4232
4520
  metadata: hasFiles ? { attachments } : void 0
4233
4521
  };
4234
4522
  setMessages((prev) => [...prev, userMessage]);
4235
- _optionalChain([onMessageSent, 'optionalCall', _94 => _94(userMessage)]);
4523
+ _optionalChain([onMessageSent, 'optionalCall', _98 => _98(userMessage)]);
4236
4524
  }
4237
4525
  setIsLoading(true);
4238
4526
  try {
@@ -4300,7 +4588,7 @@ ${widgetContext}` : widgetContext;
4300
4588
  responseThreadId = chunk.thread_id;
4301
4589
  if (!currentThreadId) {
4302
4590
  setCurrentThreadId(chunk.thread_id);
4303
- _optionalChain([onThreadChange, 'optionalCall', _95 => _95(chunk.thread_id)]);
4591
+ _optionalChain([onThreadChange, 'optionalCall', _99 => _99(chunk.thread_id)]);
4304
4592
  }
4305
4593
  }
4306
4594
  break;
@@ -4332,7 +4620,7 @@ ${widgetContext}` : widgetContext;
4332
4620
  contentSegments.push({ type: "tool", id: chunk.tool_id, name: displayName, status: "preparing" });
4333
4621
  toolInputBuffers[chunk.tool_id] = "";
4334
4622
  setChatToolName(displayName);
4335
- _optionalChain([onToolCall, 'optionalCall', _96 => _96(chunk.tool_name, chunk.tool_id)]);
4623
+ _optionalChain([onToolCall, 'optionalCall', _100 => _100(chunk.tool_name, chunk.tool_id)]);
4336
4624
  updateMessage();
4337
4625
  }
4338
4626
  break;
@@ -4392,7 +4680,7 @@ ${widgetContext}` : widgetContext;
4392
4680
  toolSegment.result = chunk.content;
4393
4681
  toolSegment.status = "completed";
4394
4682
  toolSegment.isReceiving = false;
4395
- _optionalChain([onToolResult, 'optionalCall', _97 => _97(toolSegment.name, chunk.content)]);
4683
+ _optionalChain([onToolResult, 'optionalCall', _101 => _101(toolSegment.name, chunk.content)]);
4396
4684
  }
4397
4685
  setChatToolName(null);
4398
4686
  updateMessage();
@@ -4436,7 +4724,7 @@ ${widgetContext}` : widgetContext;
4436
4724
  });
4437
4725
  if (threadId2 && threadId2 !== currentThreadId) {
4438
4726
  setCurrentThreadId(threadId2);
4439
- _optionalChain([onThreadChange, 'optionalCall', _98 => _98(threadId2)]);
4727
+ _optionalChain([onThreadChange, 'optionalCall', _102 => _102(threadId2)]);
4440
4728
  }
4441
4729
  setIsLoading(false);
4442
4730
  setCurrentRequestId(null);
@@ -4460,7 +4748,7 @@ ${widgetContext}` : widgetContext;
4460
4748
  setIsLoading(false);
4461
4749
  setCurrentRequestId(null);
4462
4750
  setChatToolName(null);
4463
- _optionalChain([onError, 'optionalCall', _99 => _99(error)]);
4751
+ _optionalChain([onError, 'optionalCall', _103 => _103(error)]);
4464
4752
  }
4465
4753
  );
4466
4754
  }
@@ -4473,7 +4761,7 @@ ${widgetContext}` : widgetContext;
4473
4761
  metadata: { error: true }
4474
4762
  };
4475
4763
  setMessages((prev) => [...prev, errorMessage]);
4476
- _optionalChain([onError, 'optionalCall', _100 => _100(error instanceof Error ? error : new Error("Unknown error"))]);
4764
+ _optionalChain([onError, 'optionalCall', _104 => _104(error instanceof Error ? error : new Error("Unknown error"))]);
4477
4765
  } finally {
4478
4766
  setIsLoading(false);
4479
4767
  }
@@ -4519,7 +4807,7 @@ ${planningInstruction}` : planningInstruction;
4519
4807
  const error = err instanceof Error ? err : new Error("Failed to generate plan");
4520
4808
  setCommandError(error);
4521
4809
  setCommandState("error");
4522
- _optionalChain([onError, 'optionalCall', _101 => _101(error)]);
4810
+ _optionalChain([onError, 'optionalCall', _105 => _105(error)]);
4523
4811
  }
4524
4812
  }
4525
4813
  return;
@@ -4552,12 +4840,12 @@ ${planningInstruction}` : planningInstruction;
4552
4840
  setCommandResult(result);
4553
4841
  setCommandState("success");
4554
4842
  setProgress(100);
4555
- _optionalChain([onComplete, 'optionalCall', _102 => _102(result)]);
4843
+ _optionalChain([onComplete, 'optionalCall', _106 => _106(result)]);
4556
4844
  },
4557
4845
  (error) => {
4558
4846
  setCommandError(error);
4559
4847
  setCommandState("error");
4560
- _optionalChain([onError, 'optionalCall', _103 => _103(error)]);
4848
+ _optionalChain([onError, 'optionalCall', _107 => _107(error)]);
4561
4849
  }
4562
4850
  );
4563
4851
  } else {
@@ -4570,7 +4858,7 @@ ${planningInstruction}` : planningInstruction;
4570
4858
  setCommandResult(result);
4571
4859
  setCommandState("success");
4572
4860
  setProgress(100);
4573
- _optionalChain([onComplete, 'optionalCall', _104 => _104(result)]);
4861
+ _optionalChain([onComplete, 'optionalCall', _108 => _108(result)]);
4574
4862
  }
4575
4863
  } else {
4576
4864
  const commandInstruction = `CRITICAL COMMAND MODE: Maximum 10 words per response. Execute the command immediately. Make reasonable assumptions based on context. Use sensible defaults for missing details. DO NOT ask questions unless something is truly impossible without user input (e.g., missing required password). State what you're doing or the result. Examples: "Analyzing customer data from last quarter..." or "Created 5 new database entries successfully" or "Search complete: found 12 matching results". NO greetings, NO filler words, NO clarification requests. Action/result only.`;
@@ -4600,16 +4888,16 @@ ${commandInstruction}` : commandInstruction;
4600
4888
  const displayName = chunk.tool_display_name || chunk.tool_name;
4601
4889
  lastToolName = chunk.tool_name;
4602
4890
  setCurrentToolName(displayName);
4603
- _optionalChain([onToolCall, 'optionalCall', _105 => _105(chunk.tool_name, chunk.tool_id || "")]);
4891
+ _optionalChain([onToolCall, 'optionalCall', _109 => _109(chunk.tool_name, chunk.tool_id || "")]);
4604
4892
  accumulatedContent = "";
4605
4893
  setStreamedContent("");
4606
4894
  } else if (chunk.type === "tool_result") {
4607
- _optionalChain([onToolResult, 'optionalCall', _106 => _106(lastToolName, chunk.content)]);
4895
+ _optionalChain([onToolResult, 'optionalCall', _110 => _110(lastToolName, chunk.content)]);
4608
4896
  setCurrentToolName(null);
4609
4897
  } else if (chunk.type === "thread_id" && chunk.thread_id) {
4610
4898
  if (!currentThreadId) {
4611
4899
  setCurrentThreadId(chunk.thread_id);
4612
- _optionalChain([onThreadChange, 'optionalCall', _107 => _107(chunk.thread_id)]);
4900
+ _optionalChain([onThreadChange, 'optionalCall', _111 => _111(chunk.thread_id)]);
4613
4901
  }
4614
4902
  } else if (chunk.type === "request_id" && chunk.request_id) {
4615
4903
  setCurrentRequestId(chunk.request_id);
@@ -4625,13 +4913,13 @@ ${commandInstruction}` : commandInstruction;
4625
4913
  setCommandState("success");
4626
4914
  setProgress(100);
4627
4915
  setCurrentRequestId(null);
4628
- _optionalChain([onComplete, 'optionalCall', _108 => _108(result)]);
4916
+ _optionalChain([onComplete, 'optionalCall', _112 => _112(result)]);
4629
4917
  },
4630
4918
  (error) => {
4631
4919
  setCommandError(error);
4632
4920
  setCommandState("error");
4633
4921
  setCurrentRequestId(null);
4634
- _optionalChain([onError, 'optionalCall', _109 => _109(error)]);
4922
+ _optionalChain([onError, 'optionalCall', _113 => _113(error)]);
4635
4923
  }
4636
4924
  );
4637
4925
  } else {
@@ -4651,14 +4939,14 @@ ${commandInstruction}` : commandInstruction;
4651
4939
  setCommandResult(result);
4652
4940
  setCommandState("success");
4653
4941
  setProgress(100);
4654
- _optionalChain([onComplete, 'optionalCall', _110 => _110(result)]);
4942
+ _optionalChain([onComplete, 'optionalCall', _114 => _114(result)]);
4655
4943
  }
4656
4944
  }
4657
4945
  } catch (err) {
4658
4946
  const error = err instanceof Error ? err : new Error("Unknown error");
4659
4947
  setCommandError(error);
4660
4948
  setCommandState("error");
4661
- _optionalChain([onError, 'optionalCall', _111 => _111(error)]);
4949
+ _optionalChain([onError, 'optionalCall', _115 => _115(error)]);
4662
4950
  }
4663
4951
  };
4664
4952
  const resetCommand = () => {
@@ -4745,7 +5033,8 @@ ${planToExecute}`;
4745
5033
  isLoading,
4746
5034
  onStop: handleStop,
4747
5035
  onFileUpload,
4748
- onSwitchMode: showModeToggle ? () => handleModeChange("command") : void 0
5036
+ onSwitchMode: showModeToggle ? () => handleModeChange("command") : void 0,
5037
+ speechToText
4749
5038
  }
4750
5039
  )
4751
5040
  ] }),
@@ -4757,8 +5046,8 @@ ${planToExecute}`;
4757
5046
  executeCommand(text, files);
4758
5047
  },
4759
5048
  state: commandState,
4760
- response: _optionalChain([commandResult, 'optionalAccess', _112 => _112.data, 'optionalAccess', _113 => _113.summary]) || _optionalChain([commandResult, 'optionalAccess', _114 => _114.message]),
4761
- error: _optionalChain([commandError, 'optionalAccess', _115 => _115.message]),
5049
+ response: _optionalChain([commandResult, 'optionalAccess', _116 => _116.data, 'optionalAccess', _117 => _117.summary]) || _optionalChain([commandResult, 'optionalAccess', _118 => _118.message]),
5050
+ error: _optionalChain([commandError, 'optionalAccess', _119 => _119.message]),
4762
5051
  plan,
4763
5052
  streamedContent,
4764
5053
  toolName: currentToolName,
@@ -4926,13 +5215,13 @@ ${planningInstruction}` : planningInstruction;
4926
5215
  const error2 = err instanceof Error ? err : new Error("Failed to generate plan");
4927
5216
  setError(error2);
4928
5217
  setState("error");
4929
- _optionalChain([onError, 'optionalCall', _116 => _116(error2)]);
5218
+ _optionalChain([onError, 'optionalCall', _120 => _120(error2)]);
4930
5219
  });
4931
5220
  } catch (err) {
4932
5221
  const error2 = err instanceof Error ? err : new Error("Failed to generate plan");
4933
5222
  setError(error2);
4934
5223
  setState("error");
4935
- _optionalChain([onError, 'optionalCall', _117 => _117(error2)]);
5224
+ _optionalChain([onError, 'optionalCall', _121 => _121(error2)]);
4936
5225
  }
4937
5226
  }
4938
5227
  return;
@@ -4943,7 +5232,7 @@ ${planningInstruction}` : planningInstruction;
4943
5232
  setStreamedContent("");
4944
5233
  setCommand("");
4945
5234
  setUploadedFiles([]);
4946
- _optionalChain([onStart, 'optionalCall', _118 => _118()]);
5235
+ _optionalChain([onStart, 'optionalCall', _122 => _122()]);
4947
5236
  try {
4948
5237
  if (useMock) {
4949
5238
  if (enableStreaming) {
@@ -4954,16 +5243,16 @@ ${planningInstruction}` : planningInstruction;
4954
5243
  if (chunk.type === "token" && chunk.content) {
4955
5244
  accumulatedContent += chunk.content;
4956
5245
  setStreamedContent(accumulatedContent);
4957
- _optionalChain([onChunk, 'optionalCall', _119 => _119(chunk.content)]);
5246
+ _optionalChain([onChunk, 'optionalCall', _123 => _123(chunk.content)]);
4958
5247
  const estimatedProgress = Math.min(Math.round(accumulatedContent.length / 10), 90);
4959
5248
  setProgress(estimatedProgress);
4960
- _optionalChain([onProgress, 'optionalCall', _120 => _120(estimatedProgress)]);
5249
+ _optionalChain([onProgress, 'optionalCall', _124 => _124(estimatedProgress)]);
4961
5250
  } else if (chunk.type === "widget" && chunk.widget) {
4962
5251
  const widget = chunk.widget;
4963
5252
  setResult((prev) => ({
4964
5253
  success: true,
4965
- data: _optionalChain([prev, 'optionalAccess', _121 => _121.data]) || {},
4966
- widgets: [..._optionalChain([prev, 'optionalAccess', _122 => _122.widgets]) || [], widget],
5254
+ data: _optionalChain([prev, 'optionalAccess', _125 => _125.data]) || {},
5255
+ widgets: [..._optionalChain([prev, 'optionalAccess', _126 => _126.widgets]) || [], widget],
4967
5256
  message: accumulatedContent || "Command executed successfully"
4968
5257
  }));
4969
5258
  }
@@ -4983,19 +5272,19 @@ ${planningInstruction}` : planningInstruction;
4983
5272
  setResult(result2);
4984
5273
  setState("success");
4985
5274
  setProgress(100);
4986
- _optionalChain([onComplete, 'optionalCall', _123 => _123(result2)]);
5275
+ _optionalChain([onComplete, 'optionalCall', _127 => _127(result2)]);
4987
5276
  },
4988
5277
  (error2) => {
4989
5278
  setError(error2);
4990
5279
  setState("error");
4991
- _optionalChain([onError, 'optionalCall', _124 => _124(error2)]);
5280
+ _optionalChain([onError, 'optionalCall', _128 => _128(error2)]);
4992
5281
  }
4993
5282
  );
4994
5283
  } else {
4995
5284
  const progressInterval = setInterval(() => {
4996
5285
  setProgress((prev) => {
4997
5286
  const next = Math.min(prev + 10, 90);
4998
- _optionalChain([onProgress, 'optionalCall', _125 => _125(next)]);
5287
+ _optionalChain([onProgress, 'optionalCall', _129 => _129(next)]);
4999
5288
  return next;
5000
5289
  });
5001
5290
  }, 200);
@@ -5019,7 +5308,7 @@ ${planningInstruction}` : planningInstruction;
5019
5308
  setResult(result2);
5020
5309
  setState("success");
5021
5310
  setProgress(100);
5022
- _optionalChain([onComplete, 'optionalCall', _126 => _126(result2)]);
5311
+ _optionalChain([onComplete, 'optionalCall', _130 => _130(result2)]);
5023
5312
  }
5024
5313
  } else {
5025
5314
  if (enableStreaming) {
@@ -5065,16 +5354,16 @@ ${commandInstruction}` : commandInstruction;
5065
5354
  if (chunk.type === "token" && chunk.content) {
5066
5355
  accumulatedContent += chunk.content;
5067
5356
  setStreamedContent(accumulatedContent);
5068
- _optionalChain([onChunk, 'optionalCall', _127 => _127(chunk.content)]);
5357
+ _optionalChain([onChunk, 'optionalCall', _131 => _131(chunk.content)]);
5069
5358
  const estimatedProgress = Math.min(Math.round(accumulatedContent.length / 10), 90);
5070
5359
  setProgress(estimatedProgress);
5071
- _optionalChain([onProgress, 'optionalCall', _128 => _128(estimatedProgress)]);
5360
+ _optionalChain([onProgress, 'optionalCall', _132 => _132(estimatedProgress)]);
5072
5361
  } else if (chunk.type === "widget" && chunk.widget) {
5073
5362
  const widget = chunk.widget;
5074
5363
  setResult((prev) => ({
5075
5364
  success: true,
5076
- data: _optionalChain([prev, 'optionalAccess', _129 => _129.data]) || {},
5077
- widgets: [..._optionalChain([prev, 'optionalAccess', _130 => _130.widgets]) || [], widget],
5365
+ data: _optionalChain([prev, 'optionalAccess', _133 => _133.data]) || {},
5366
+ widgets: [..._optionalChain([prev, 'optionalAccess', _134 => _134.widgets]) || [], widget],
5078
5367
  message: accumulatedContent || "Command executed successfully"
5079
5368
  }));
5080
5369
  }
@@ -5094,20 +5383,20 @@ ${commandInstruction}` : commandInstruction;
5094
5383
  setResult(result2);
5095
5384
  setState("success");
5096
5385
  setProgress(100);
5097
- _optionalChain([onComplete, 'optionalCall', _131 => _131(result2)]);
5386
+ _optionalChain([onComplete, 'optionalCall', _135 => _135(result2)]);
5098
5387
  },
5099
5388
  (error2) => {
5100
5389
  const err = error2 instanceof Error ? error2 : new Error("Unknown error");
5101
5390
  setError(err);
5102
5391
  setState("error");
5103
- _optionalChain([onError, 'optionalCall', _132 => _132(err)]);
5392
+ _optionalChain([onError, 'optionalCall', _136 => _136(err)]);
5104
5393
  }
5105
5394
  );
5106
5395
  } else {
5107
5396
  const progressInterval = setInterval(() => {
5108
5397
  setProgress((prev) => {
5109
5398
  const next = Math.min(prev + 10, 90);
5110
- _optionalChain([onProgress, 'optionalCall', _133 => _133(next)]);
5399
+ _optionalChain([onProgress, 'optionalCall', _137 => _137(next)]);
5111
5400
  return next;
5112
5401
  });
5113
5402
  }, 200);
@@ -5163,14 +5452,14 @@ ${commandInstruction}` : commandInstruction;
5163
5452
  setResult(result2);
5164
5453
  setState("success");
5165
5454
  setProgress(100);
5166
- _optionalChain([onComplete, 'optionalCall', _134 => _134(result2)]);
5455
+ _optionalChain([onComplete, 'optionalCall', _138 => _138(result2)]);
5167
5456
  }
5168
5457
  }
5169
5458
  } catch (err) {
5170
5459
  const error2 = err instanceof Error ? err : new Error("Unknown error");
5171
5460
  setError(error2);
5172
5461
  setState("error");
5173
- _optionalChain([onError, 'optionalCall', _135 => _135(error2)]);
5462
+ _optionalChain([onError, 'optionalCall', _139 => _139(error2)]);
5174
5463
  }
5175
5464
  };
5176
5465
  const resetCommand = () => {
@@ -5203,14 +5492,14 @@ ${planToExecute}`;
5203
5492
  };
5204
5493
  const handleFileSelect = async (e) => {
5205
5494
  if (e.target.files && e.target.files.length > 0) {
5206
- _optionalChain([onFileUpload, 'optionalCall', _136 => _136(e.target.files)]);
5495
+ _optionalChain([onFileUpload, 'optionalCall', _140 => _140(e.target.files)]);
5207
5496
  const files = [];
5208
5497
  for (let i = 0; i < e.target.files.length; i++) {
5209
5498
  const file = e.target.files[i];
5210
5499
  const reader = new FileReader();
5211
5500
  await new Promise((resolve) => {
5212
5501
  reader.onload = (event) => {
5213
- if (_optionalChain([event, 'access', _137 => _137.target, 'optionalAccess', _138 => _138.result])) {
5502
+ if (_optionalChain([event, 'access', _141 => _141.target, 'optionalAccess', _142 => _142.result])) {
5214
5503
  const fullDataUrl = event.target.result;
5215
5504
  const base64Data = fullDataUrl.split(",")[1];
5216
5505
  if (file.type.startsWith("image/")) {
@@ -5304,7 +5593,7 @@ ${planToExecute}`;
5304
5593
  enableFileUpload && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
5305
5594
  "button",
5306
5595
  {
5307
- onClick: () => _optionalChain([fileInputRef, 'access', _139 => _139.current, 'optionalAccess', _140 => _140.click, 'call', _141 => _141()]),
5596
+ onClick: () => _optionalChain([fileInputRef, 'access', _143 => _143.current, 'optionalAccess', _144 => _144.click, 'call', _145 => _145()]),
5308
5597
  className: "w-8 h-8 rounded-lg flex items-center justify-center transition-all flex-shrink-0 !text-neutral-500 dark:!text-neutral-500 hover:bg-neutral-100 dark:hover:bg-neutral-800",
5309
5598
  title: "Attach file",
5310
5599
  children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "M8.4 2.8L4.4 6.8C3.736 7.464 3.736 8.536 4.4 9.2C5.064 9.864 6.136 9.864 6.8 9.2L11.6 4.4C12.704 3.296 12.704 1.504 11.6 0.4C10.496 -0.704 8.704 -0.704 7.6 0.4L2.8 5.2C1.256 6.744 1.256 9.256 2.8 10.8C4.344 12.344 6.856 12.344 8.4 10.8L12.4 6.8", stroke: "currentColor", strokeWidth: "1.2", strokeLinecap: "round", strokeLinejoin: "round", transform: "translate(1.6, 2.4)" }) })
@@ -5523,7 +5812,7 @@ ${planToExecute}`;
5523
5812
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { className: "w-5 h-5 text-red-600 mt-0.5 flex-shrink-0", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" }) }),
5524
5813
  /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { children: [
5525
5814
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h3", { className: "text-sm font-semibold text-red-800 dark:text-red-400", children: "Error" }),
5526
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-red-700 dark:text-red-300 text-sm mt-1", children: _optionalChain([error, 'optionalAccess', _142 => _142.message]) })
5815
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-red-700 dark:text-red-300 text-sm mt-1", children: _optionalChain([error, 'optionalAccess', _146 => _146.message]) })
5527
5816
  ] })
5528
5817
  ] }) }),
5529
5818
  allowInput && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
@@ -5551,7 +5840,7 @@ ${planToExecute}`;
5551
5840
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-green-700 dark:text-green-300 text-sm", children: "Command executed successfully" })
5552
5841
  ] })
5553
5842
  ] }),
5554
- _optionalChain([result, 'access', _143 => _143.data, 'optionalAccess', _144 => _144.summary]) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "text-neutral-700 dark:text-neutral-300 text-sm leading-relaxed whitespace-pre-line", children: result.data.summary }),
5843
+ _optionalChain([result, 'access', _147 => _147.data, 'optionalAccess', _148 => _148.summary]) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "text-neutral-700 dark:text-neutral-300 text-sm leading-relaxed whitespace-pre-line", children: result.data.summary }),
5555
5844
  result.widgets && result.widgets.length > 0 && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "space-y-3", children: result.widgets.map((widget) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
5556
5845
  WidgetRenderer,
5557
5846
  {
@@ -5602,7 +5891,7 @@ ${planToExecute}`;
5602
5891
  enableFileUpload && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
5603
5892
  "button",
5604
5893
  {
5605
- onClick: () => _optionalChain([fileInputRef, 'access', _145 => _145.current, 'optionalAccess', _146 => _146.click, 'call', _147 => _147()]),
5894
+ onClick: () => _optionalChain([fileInputRef, 'access', _149 => _149.current, 'optionalAccess', _150 => _150.click, 'call', _151 => _151()]),
5606
5895
  className: "w-8 h-8 rounded-lg flex items-center justify-center transition-all flex-shrink-0 !text-neutral-500 dark:!text-neutral-500 hover:bg-neutral-100 dark:hover:bg-neutral-800",
5607
5896
  title: "Attach file",
5608
5897
  children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "M8.4 2.8L4.4 6.8C3.736 7.464 3.736 8.536 4.4 9.2C5.064 9.864 6.136 9.864 6.8 9.2L11.6 4.4C12.704 3.296 12.704 1.504 11.6 0.4C10.496 -0.704 8.704 -0.704 7.6 0.4L2.8 5.2C1.256 6.744 1.256 9.256 2.8 10.8C4.344 12.344 6.856 12.344 8.4 10.8L12.4 6.8", stroke: "currentColor", strokeWidth: "1.2", strokeLinecap: "round", strokeLinejoin: "round", transform: "translate(1.6, 2.4)" }) })
@@ -5788,25 +6077,25 @@ function Prompt({
5788
6077
  const newValue = e.target.value;
5789
6078
  if (!maxLength || newValue.length <= maxLength) {
5790
6079
  setValue(newValue);
5791
- _optionalChain([onChange, 'optionalCall', _148 => _148(newValue)]);
6080
+ _optionalChain([onChange, 'optionalCall', _152 => _152(newValue)]);
5792
6081
  }
5793
6082
  };
5794
6083
  const handleSubmit = async () => {
5795
6084
  if (value.length < minLength) return;
5796
- _optionalChain([onSubmit, 'optionalCall', _149 => _149(value)]);
6085
+ _optionalChain([onSubmit, 'optionalCall', _153 => _153(value)]);
5797
6086
  setIsLoading(true);
5798
6087
  try {
5799
6088
  if (useMock) {
5800
6089
  await new Promise((resolve) => setTimeout(resolve, 1500));
5801
6090
  const mockResult = `Enhanced version: ${value} [AI-generated content]`;
5802
- _optionalChain([onResult, 'optionalCall', _150 => _150(mockResult)]);
6091
+ _optionalChain([onResult, 'optionalCall', _154 => _154(mockResult)]);
5803
6092
  setValue("");
5804
6093
  } else {
5805
6094
  const response = await aptevaClient.chat({
5806
6095
  agent_id: agentId,
5807
6096
  message: value
5808
6097
  });
5809
- _optionalChain([onResult, 'optionalCall', _151 => _151(response.message)]);
6098
+ _optionalChain([onResult, 'optionalCall', _155 => _155(response.message)]);
5810
6099
  setValue("");
5811
6100
  }
5812
6101
  } catch (error) {
@@ -5901,7 +6190,7 @@ function Stream({
5901
6190
  }, [autoStart]);
5902
6191
  const startStreaming = async () => {
5903
6192
  setIsStreaming(true);
5904
- _optionalChain([onStart, 'optionalCall', _152 => _152()]);
6193
+ _optionalChain([onStart, 'optionalCall', _156 => _156()]);
5905
6194
  try {
5906
6195
  if (useMock) {
5907
6196
  const mockText = "This is a simulated streaming response from the AI agent. In a real implementation, this would stream data from your backend API. The text appears word by word to simulate the streaming effect. You can customize the typing speed and styling based on your needs.";
@@ -5909,13 +6198,13 @@ function Stream({
5909
6198
  mockText,
5910
6199
  (chunk) => {
5911
6200
  setText((prev) => prev + chunk);
5912
- _optionalChain([onChunk, 'optionalCall', _153 => _153(chunk)]);
6201
+ _optionalChain([onChunk, 'optionalCall', _157 => _157(chunk)]);
5913
6202
  },
5914
6203
  typingSpeed
5915
6204
  );
5916
6205
  setIsComplete(true);
5917
6206
  setIsStreaming(false);
5918
- _optionalChain([onComplete, 'optionalCall', _154 => _154(text + mockText)]);
6207
+ _optionalChain([onComplete, 'optionalCall', _158 => _158(text + mockText)]);
5919
6208
  } else {
5920
6209
  let accumulatedText = "";
5921
6210
  await aptevaClient.chatStream(
@@ -5928,24 +6217,24 @@ function Stream({
5928
6217
  if (chunk.type === "token" && chunk.content) {
5929
6218
  accumulatedText += chunk.content;
5930
6219
  setText(accumulatedText);
5931
- _optionalChain([onChunk, 'optionalCall', _155 => _155(chunk.content)]);
6220
+ _optionalChain([onChunk, 'optionalCall', _159 => _159(chunk.content)]);
5932
6221
  }
5933
6222
  },
5934
6223
  () => {
5935
6224
  setIsComplete(true);
5936
6225
  setIsStreaming(false);
5937
- _optionalChain([onComplete, 'optionalCall', _156 => _156(accumulatedText)]);
6226
+ _optionalChain([onComplete, 'optionalCall', _160 => _160(accumulatedText)]);
5938
6227
  },
5939
6228
  (error) => {
5940
6229
  const err = error instanceof Error ? error : new Error("Streaming error");
5941
- _optionalChain([onError, 'optionalCall', _157 => _157(err)]);
6230
+ _optionalChain([onError, 'optionalCall', _161 => _161(err)]);
5942
6231
  setIsStreaming(false);
5943
6232
  }
5944
6233
  );
5945
6234
  }
5946
6235
  } catch (error) {
5947
6236
  const err = error instanceof Error ? error : new Error("Streaming error");
5948
- _optionalChain([onError, 'optionalCall', _158 => _158(err)]);
6237
+ _optionalChain([onError, 'optionalCall', _162 => _162(err)]);
5949
6238
  setIsStreaming(false);
5950
6239
  }
5951
6240
  };
@@ -6037,7 +6326,7 @@ function ThreadList({
6037
6326
  }) {
6038
6327
  const [searchQuery, setSearchQuery] = _react.useState.call(void 0, "");
6039
6328
  const filteredThreads = threads.filter(
6040
- (thread) => thread.title.toLowerCase().includes(searchQuery.toLowerCase()) || _optionalChain([thread, 'access', _159 => _159.preview, 'optionalAccess', _160 => _160.toLowerCase, 'call', _161 => _161(), 'access', _162 => _162.includes, 'call', _163 => _163(searchQuery.toLowerCase())])
6329
+ (thread) => thread.title.toLowerCase().includes(searchQuery.toLowerCase()) || _optionalChain([thread, 'access', _163 => _163.preview, 'optionalAccess', _164 => _164.toLowerCase, 'call', _165 => _165(), 'access', _166 => _166.includes, 'call', _167 => _167(searchQuery.toLowerCase())])
6041
6330
  );
6042
6331
  const groupedThreads = groupBy === "date" ? groupThreadsByDate(filteredThreads) : { All: filteredThreads };
6043
6332
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex flex-col h-full", children: [
@@ -6059,8 +6348,8 @@ function ThreadList({
6059
6348
  {
6060
6349
  thread,
6061
6350
  isActive: thread.id === currentThreadId,
6062
- onSelect: () => _optionalChain([onThreadSelect, 'optionalCall', _164 => _164(thread.id)]),
6063
- onDelete: () => _optionalChain([onThreadDelete, 'optionalCall', _165 => _165(thread.id)])
6351
+ onSelect: () => _optionalChain([onThreadSelect, 'optionalCall', _168 => _168(thread.id)]),
6352
+ onDelete: () => _optionalChain([onThreadDelete, 'optionalCall', _169 => _169(thread.id)])
6064
6353
  },
6065
6354
  thread.id
6066
6355
  ))
@@ -6122,7 +6411,7 @@ function Threads({
6122
6411
  threads.slice(0, 5).map((thread) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
6123
6412
  "button",
6124
6413
  {
6125
- onClick: () => _optionalChain([onThreadSelect, 'optionalCall', _166 => _166(thread.id)]),
6414
+ onClick: () => _optionalChain([onThreadSelect, 'optionalCall', _170 => _170(thread.id)]),
6126
6415
  className: cn(
6127
6416
  "px-4 py-2 whitespace-nowrap font-medium transition-colors",
6128
6417
  thread.id === currentThreadId ? "border-b-2 border-apteva-500 text-apteva-500" : "text-neutral-600 hover:text-neutral-900"
@@ -6307,7 +6596,7 @@ function TabsLayout({ node, renderNode }) {
6307
6596
  var STRUCTURAL_KEYS = /* @__PURE__ */ new Set(["type", "id", "layout", "props", "children", "actions", "metadata", "isStreaming"]);
6308
6597
  function normalizeNode(n) {
6309
6598
  let node = { ...n };
6310
- if (node.type === "widget" && _optionalChain([node, 'access', _167 => _167.props, 'optionalAccess', _168 => _168.widget])) {
6599
+ if (node.type === "widget" && _optionalChain([node, 'access', _171 => _171.props, 'optionalAccess', _172 => _172.widget])) {
6311
6600
  node.type = node.props.widget;
6312
6601
  const { widget: _, ...rest } = node.props;
6313
6602
  node.props = rest;
@@ -6445,10 +6734,10 @@ function AutoInterface({
6445
6734
  ].filter(Boolean).join("\n\n");
6446
6735
  const updateInterface = _react.useCallback.call(void 0, (newSpec) => {
6447
6736
  setInterfaceSpec(newSpec);
6448
- _optionalChain([onInterfaceChange, 'optionalCall', _169 => _169(newSpec)]);
6737
+ _optionalChain([onInterfaceChange, 'optionalCall', _173 => _173(newSpec)]);
6449
6738
  }, [onInterfaceChange]);
6450
6739
  const handleAction = _react.useCallback.call(void 0, (action) => {
6451
- _optionalChain([onAction, 'optionalCall', _170 => _170(action)]);
6740
+ _optionalChain([onAction, 'optionalCall', _174 => _174(action)]);
6452
6741
  if (chatRef.current) {
6453
6742
  chatRef.current.sendMessage(
6454
6743
  `[Action: ${action.type} on widget ${action.widgetId || "unknown"}. Payload: ${JSON.stringify(action.payload)}]`
@@ -6456,7 +6745,7 @@ function AutoInterface({
6456
6745
  }
6457
6746
  }, [onAction]);
6458
6747
  const handleMessageComplete = _react.useCallback.call(void 0, (result) => {
6459
- if (!_optionalChain([result, 'optionalAccess', _171 => _171.data])) return;
6748
+ if (!_optionalChain([result, 'optionalAccess', _175 => _175.data])) return;
6460
6749
  const text = typeof result.data === "string" ? result.data : result.data.message || "";
6461
6750
  console.log("[AutoInterface] Chat message complete, text (" + text.length + " chars):", text.substring(0, 300));
6462
6751
  const parsed = parseInterfaceFromText(text);
@@ -6496,7 +6785,7 @@ function AutoInterface({
6496
6785
  }).catch((err) => {
6497
6786
  if (cancelled) return;
6498
6787
  console.error("[AutoInterface] Initial generation failed:", err);
6499
- _optionalChain([onError, 'optionalCall', _172 => _172(err instanceof Error ? err : new Error(String(err)))]);
6788
+ _optionalChain([onError, 'optionalCall', _176 => _176(err instanceof Error ? err : new Error(String(err)))]);
6500
6789
  setIsGenerating(false);
6501
6790
  });
6502
6791
  return () => {
@@ -6662,7 +6951,7 @@ function useInterfaceAI({
6662
6951
  }
6663
6952
  const sendMessage = _react.useCallback.call(void 0, async (message) => {
6664
6953
  accumulatedTextRef.current = "";
6665
- _optionalChain([onStreamStart, 'optionalCall', _173 => _173()]);
6954
+ _optionalChain([onStreamStart, 'optionalCall', _177 => _177()]);
6666
6955
  const systemPrompt = [
6667
6956
  generateInterfaceContext(),
6668
6957
  context || ""
@@ -6685,27 +6974,27 @@ function useInterfaceAI({
6685
6974
  accumulatedTextRef.current += chunk.content || "";
6686
6975
  const parsed = parseInterfaceFromText(accumulatedTextRef.current);
6687
6976
  if (parsed) {
6688
- _optionalChain([onInterface, 'optionalCall', _174 => _174(parsed)]);
6977
+ _optionalChain([onInterface, 'optionalCall', _178 => _178(parsed)]);
6689
6978
  }
6690
6979
  const updates = parseUpdatesFromText(accumulatedTextRef.current);
6691
6980
  if (updates.length > 0) {
6692
- _optionalChain([onUpdates, 'optionalCall', _175 => _175(updates)]);
6981
+ _optionalChain([onUpdates, 'optionalCall', _179 => _179(updates)]);
6693
6982
  }
6694
6983
  }
6695
6984
  },
6696
6985
  // onComplete
6697
6986
  () => {
6698
- _optionalChain([onStreamEnd, 'optionalCall', _176 => _176()]);
6987
+ _optionalChain([onStreamEnd, 'optionalCall', _180 => _180()]);
6699
6988
  },
6700
6989
  // onError
6701
6990
  (error) => {
6702
- _optionalChain([onError, 'optionalCall', _177 => _177(error)]);
6703
- _optionalChain([onStreamEnd, 'optionalCall', _178 => _178()]);
6991
+ _optionalChain([onError, 'optionalCall', _181 => _181(error)]);
6992
+ _optionalChain([onStreamEnd, 'optionalCall', _182 => _182()]);
6704
6993
  }
6705
6994
  );
6706
6995
  } catch (error) {
6707
- _optionalChain([onError, 'optionalCall', _179 => _179(error instanceof Error ? error : new Error("Unknown error"))]);
6708
- _optionalChain([onStreamEnd, 'optionalCall', _180 => _180()]);
6996
+ _optionalChain([onError, 'optionalCall', _183 => _183(error instanceof Error ? error : new Error("Unknown error"))]);
6997
+ _optionalChain([onStreamEnd, 'optionalCall', _184 => _184()]);
6709
6998
  }
6710
6999
  }, [agentId, context, onInterface, onUpdates, onError, onStreamStart, onStreamEnd]);
6711
7000
  return {