@apteva/apteva-kit 0.1.18 → 0.1.22

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
@@ -9,6 +9,9 @@ var _react = require('react'); var _react2 = _interopRequireDefault(_react);
9
9
  // src/components/Chat/MessageList.tsx
10
10
 
11
11
 
12
+ // src/components/Chat/Message.tsx
13
+
14
+
12
15
  // src/utils/cn.ts
13
16
  var _clsx = require('clsx');
14
17
  var _tailwindmerge = require('tailwind-merge');
@@ -499,6 +502,15 @@ function validateFile(file) {
499
502
  }
500
503
 
501
504
  // src/utils/widget-parser.ts
505
+ function simpleHash(str) {
506
+ let hash = 0;
507
+ for (let i = 0; i < str.length; i++) {
508
+ const char = str.charCodeAt(i);
509
+ hash = (hash << 5) - hash + char;
510
+ hash = hash & hash;
511
+ }
512
+ return Math.abs(hash).toString(36);
513
+ }
502
514
  function findMatchingBracket(text, startIndex) {
503
515
  let depth = 0;
504
516
  let inString = false;
@@ -583,7 +595,7 @@ function parseWidgetsFromText(text) {
583
595
  try {
584
596
  const trimmedJson = jsonContent.trim();
585
597
  const props = JSON.parse(trimmedJson);
586
- const widgetId = `widget-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
598
+ const widgetId = `widget-${widgetType}-${simpleHash(trimmedJson)}`;
587
599
  segments.push({
588
600
  type: "widget",
589
601
  widget: {
@@ -1079,17 +1091,71 @@ function WidgetSkeleton({ type, className }) {
1079
1091
 
1080
1092
  // src/components/Chat/MarkdownContent.tsx
1081
1093
 
1094
+ function isImageUrl(url) {
1095
+ const imageExtensions = /\.(jpg|jpeg|png|gif|webp|svg|bmp|ico)(\?.*)?$/i;
1096
+ return imageExtensions.test(url);
1097
+ }
1082
1098
  function parseInlineMarkdown(text, keyPrefix = "") {
1083
1099
  const result = [];
1084
- const boldRegex = /(\*\*|__)(.+?)\1/g;
1100
+ const inlineRegex = /!\[([^\]]*)\]\(([^)]+)\)|\[([^\]]+)\]\(([^)]+)\)|(\*\*|__)(.+?)\5|`([^`]+)`/g;
1085
1101
  let lastIndex = 0;
1086
1102
  let match;
1087
1103
  let key = 0;
1088
- while ((match = boldRegex.exec(text)) !== null) {
1104
+ while ((match = inlineRegex.exec(text)) !== null) {
1089
1105
  if (match.index > lastIndex) {
1090
1106
  result.push(text.slice(lastIndex, match.index));
1091
1107
  }
1092
- result.push(/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "strong", { children: match[2] }, `${keyPrefix}b${key++}`));
1108
+ if (match[1] !== void 0 || match[2] !== void 0) {
1109
+ const alt = match[1] || "";
1110
+ const src = match[2];
1111
+ result.push(
1112
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
1113
+ "img",
1114
+ {
1115
+ src,
1116
+ alt,
1117
+ className: "apteva-md-img"
1118
+ },
1119
+ `${keyPrefix}img${key++}`
1120
+ )
1121
+ );
1122
+ } else if (match[3] !== void 0 || match[4] !== void 0) {
1123
+ const linkText = match[3];
1124
+ const href = match[4];
1125
+ if (isImageUrl(href)) {
1126
+ result.push(
1127
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
1128
+ "img",
1129
+ {
1130
+ src: href,
1131
+ alt: linkText,
1132
+ className: "apteva-md-img"
1133
+ },
1134
+ `${keyPrefix}img${key++}`
1135
+ )
1136
+ );
1137
+ } else {
1138
+ result.push(
1139
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
1140
+ "a",
1141
+ {
1142
+ href,
1143
+ target: "_blank",
1144
+ rel: "noopener noreferrer",
1145
+ className: "apteva-md-link",
1146
+ children: linkText
1147
+ },
1148
+ `${keyPrefix}a${key++}`
1149
+ )
1150
+ );
1151
+ }
1152
+ } else if (match[5] !== void 0) {
1153
+ result.push(/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "strong", { children: match[6] }, `${keyPrefix}b${key++}`));
1154
+ } else if (match[7] !== void 0) {
1155
+ result.push(
1156
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "code", { className: "apteva-md-inline-code", children: match[7] }, `${keyPrefix}code${key++}`)
1157
+ );
1158
+ }
1093
1159
  lastIndex = match.index + match[0].length;
1094
1160
  }
1095
1161
  if (lastIndex < text.length) {
@@ -1163,7 +1229,7 @@ function parseMarkdown(content) {
1163
1229
  const tableMatch = line.match(/^\|(.+)\|$/);
1164
1230
  if (tableMatch && i + 1 < lines.length) {
1165
1231
  const separatorLine = lines[i + 1];
1166
- const separatorMatch = separatorLine.match(/^\|[\s:-]+\|$/);
1232
+ const separatorMatch = separatorLine.match(/^\|([\s:-]+\|)+$/);
1167
1233
  if (separatorMatch) {
1168
1234
  const headerCells = line.split("|").filter((cell) => cell.trim() !== "").map((cell) => cell.trim());
1169
1235
  i += 2;
@@ -1208,22 +1274,72 @@ function MarkdownContent({ content, className = "" }) {
1208
1274
  // src/components/Chat/ToolCall.tsx
1209
1275
 
1210
1276
  function ToolCall({ name, status }) {
1211
- return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "apteva-tool-call", children: [
1212
- status === "running" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "apteva-tool-call-dot apteva-tool-call-dot-running" }),
1213
- status === "completed" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "apteva-tool-call-dot apteva-tool-call-dot-completed" }),
1214
- status === "error" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "apteva-tool-call-dot apteva-tool-call-dot-error" }),
1215
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "apteva-tool-call-name", children: name }),
1216
- status === "running" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "apteva-tool-call-status", children: "Running..." }),
1217
- status === "completed" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "apteva-tool-call-status apteva-tool-call-status-completed", children: "Completed" }),
1218
- status === "error" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "apteva-tool-call-status apteva-tool-call-status-error", children: "Error" })
1277
+ if (status === "running") {
1278
+ return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-center gap-2 px-3 py-2 rounded-xl bg-blue-50 dark:bg-blue-900/30 border border-blue-200 dark:border-blue-700 !text-blue-700 dark:!text-blue-300 text-sm", children: [
1279
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "svg", { className: "w-4 h-4 animate-spin", fill: "none", viewBox: "0 0 24 24", children: [
1280
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }),
1281
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z" })
1282
+ ] }),
1283
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { children: [
1284
+ "Calling ",
1285
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "strong", { children: name }),
1286
+ "..."
1287
+ ] })
1288
+ ] });
1289
+ }
1290
+ if (status === "completed") {
1291
+ return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-center gap-2 px-3 py-2 rounded-xl bg-green-50 dark:bg-green-900/30 border border-green-200 dark:border-green-700 !text-green-700 dark:!text-green-300 text-sm", children: [
1292
+ /* @__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: "M5 13l4 4L19 7" }) }),
1293
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { children: [
1294
+ "Tool completed: ",
1295
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "strong", { children: name })
1296
+ ] })
1297
+ ] });
1298
+ }
1299
+ return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-center gap-2 px-3 py-2 rounded-xl bg-red-50 dark:bg-red-900/30 border border-red-200 dark:border-red-700 !text-red-700 dark:!text-red-300 text-sm", children: [
1300
+ /* @__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: "M6 18L18 6M6 6l12 12" }) }),
1301
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { children: [
1302
+ "Tool failed: ",
1303
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "strong", { children: name })
1304
+ ] })
1219
1305
  ] });
1220
1306
  }
1221
1307
 
1222
1308
  // src/components/Chat/Message.tsx
1223
1309
 
1224
- function Message({ message, onAction, enableWidgets }) {
1310
+ function Message({ message, onAction, enableWidgets, onWidgetRender }) {
1225
1311
  const isUser = message.role === "user";
1226
1312
  const contentSegments = _optionalChain([message, 'access', _19 => _19.metadata, 'optionalAccess', _20 => _20.content_segments]);
1313
+ const isStreaming = _optionalChain([message, 'access', _21 => _21.metadata, 'optionalAccess', _22 => _22.isStreaming]) === true;
1314
+ const hasContent = message.content || contentSegments && contentSegments.length > 0;
1315
+ const reportedWidgetsRef = _react.useRef.call(void 0, /* @__PURE__ */ new Set());
1316
+ const parsedWidgets = _react.useMemo.call(void 0, () => {
1317
+ if (!enableWidgets || isUser || !message.content) {
1318
+ return [];
1319
+ }
1320
+ const parsed = parseWidgetsFromText(message.content);
1321
+ return parsed.segments.filter((seg) => seg.type === "widget" && !!seg.widget).map((seg) => seg.widget);
1322
+ }, [enableWidgets, isUser, message.content]);
1323
+ _react.useEffect.call(void 0, () => {
1324
+ if (onWidgetRender && message.widgets) {
1325
+ for (const widget of message.widgets) {
1326
+ if (!reportedWidgetsRef.current.has(widget.id)) {
1327
+ reportedWidgetsRef.current.add(widget.id);
1328
+ onWidgetRender(widget);
1329
+ }
1330
+ }
1331
+ }
1332
+ }, [message.widgets, onWidgetRender]);
1333
+ _react.useEffect.call(void 0, () => {
1334
+ if (onWidgetRender && parsedWidgets.length > 0) {
1335
+ for (const widget of parsedWidgets) {
1336
+ if (!reportedWidgetsRef.current.has(widget.id)) {
1337
+ reportedWidgetsRef.current.add(widget.id);
1338
+ onWidgetRender(widget);
1339
+ }
1340
+ }
1341
+ }
1342
+ }, [parsedWidgets, onWidgetRender]);
1227
1343
  const renderTextContent = (text) => {
1228
1344
  if (!enableWidgets || isUser) {
1229
1345
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, MarkdownContent, { content: text });
@@ -1249,6 +1365,13 @@ function Message({ message, onAction, enableWidgets }) {
1249
1365
  if (isUser) {
1250
1366
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "whitespace-pre-wrap !text-sm leading-relaxed", children: message.content });
1251
1367
  }
1368
+ if (isStreaming && !hasContent) {
1369
+ return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "apteva-typing-indicator !text-gray-400", children: [
1370
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", {}),
1371
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", {}),
1372
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", {})
1373
+ ] });
1374
+ }
1252
1375
  if (contentSegments && contentSegments.length > 0) {
1253
1376
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { children: contentSegments.map((segment, index) => {
1254
1377
  if (segment.type === "text") {
@@ -1271,13 +1394,13 @@ function Message({ message, onAction, enableWidgets }) {
1271
1394
  "div",
1272
1395
  {
1273
1396
  className: cn(
1274
- "max-w-[80%]",
1275
- isUser ? "px-4 py-2.5 rounded-xl bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 !text-gray-900 dark:!text-gray-100 ml-auto" : "!text-gray-900 dark:!text-gray-100"
1397
+ "max-w-[80%] px-4 py-2.5 rounded-2xl",
1398
+ isUser ? "bg-blue-600 !text-white rounded-br-md" : "bg-gray-100 dark:bg-gray-800 !text-gray-900 dark:!text-gray-100 rounded-bl-md"
1276
1399
  ),
1277
1400
  children: [
1278
1401
  renderContent(),
1279
1402
  message.widgets && message.widgets.length > 0 && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: cn(isUser ? "mt-3" : "mt-2"), children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Widgets, { widgets: message.widgets, onAction, layout: "stack" }) }),
1280
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: cn("!text-xs opacity-70", isUser ? "mt-1.5 !text-gray-500 dark:!text-gray-400" : "mt-1 !text-gray-500 dark:!text-gray-400"), suppressHydrationWarning: true, children: message.timestamp.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }) })
1403
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: cn("!text-xs mt-1.5", isUser ? "!text-blue-200" : "!text-gray-500 dark:!text-gray-400"), suppressHydrationWarning: true, children: message.timestamp.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }) })
1281
1404
  ]
1282
1405
  }
1283
1406
  );
@@ -1435,7 +1558,8 @@ function MessageList({
1435
1558
  suggestedPrompts,
1436
1559
  welcomeVariant,
1437
1560
  onPromptClick,
1438
- enableWidgets
1561
+ enableWidgets,
1562
+ onWidgetRender
1439
1563
  }) {
1440
1564
  const listRef = _react.useRef.call(void 0, null);
1441
1565
  _react.useEffect.call(void 0, () => {
@@ -1454,7 +1578,7 @@ function MessageList({
1454
1578
  onPromptClick: onPromptClick || (() => {
1455
1579
  })
1456
1580
  }
1457
- ) : messages.map((message) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Message, { message, onAction, enableWidgets }, message.id)) });
1581
+ ) : messages.map((message) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: `flex ${message.role === "user" ? "justify-end" : "justify-start"}`, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Message, { message, onAction, enableWidgets, onWidgetRender }) }, message.id)) });
1458
1582
  }
1459
1583
 
1460
1584
  // src/components/Chat/Composer.tsx
@@ -1517,7 +1641,7 @@ function Composer({ onSendMessage, placeholder = "Type a message...", disabled =
1517
1641
  setFileError(errors.join(", "));
1518
1642
  setTimeout(() => setFileError(null), 5e3);
1519
1643
  }
1520
- _optionalChain([onFileUpload, 'optionalCall', _21 => _21(e.target.files)]);
1644
+ _optionalChain([onFileUpload, 'optionalCall', _23 => _23(e.target.files)]);
1521
1645
  setShowMenu(false);
1522
1646
  e.target.value = "";
1523
1647
  }
@@ -1587,15 +1711,15 @@ function Composer({ onSendMessage, placeholder = "Type a message...", disabled =
1587
1711
  {
1588
1712
  className: "fixed bg-gray-800 dark:bg-gray-700 rounded-xl shadow-lg overflow-hidden z-[9999] min-w-[200px]",
1589
1713
  style: {
1590
- left: _nullishCoalesce(_optionalChain([menuButtonRef, 'access', _22 => _22.current, 'optionalAccess', _23 => _23.getBoundingClientRect, 'call', _24 => _24(), 'access', _25 => _25.left]), () => ( 0)),
1591
- top: (_nullishCoalesce(_optionalChain([menuButtonRef, 'access', _26 => _26.current, 'optionalAccess', _27 => _27.getBoundingClientRect, 'call', _28 => _28(), 'access', _29 => _29.bottom]), () => ( 0))) + 8
1714
+ left: _nullishCoalesce(_optionalChain([menuButtonRef, 'access', _24 => _24.current, 'optionalAccess', _25 => _25.getBoundingClientRect, 'call', _26 => _26(), 'access', _27 => _27.left]), () => ( 0)),
1715
+ top: (_nullishCoalesce(_optionalChain([menuButtonRef, 'access', _28 => _28.current, 'optionalAccess', _29 => _29.getBoundingClientRect, 'call', _30 => _30(), 'access', _31 => _31.bottom]), () => ( 0))) + 8
1592
1716
  },
1593
1717
  children: [
1594
1718
  /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
1595
1719
  "button",
1596
1720
  {
1597
1721
  onClick: () => {
1598
- _optionalChain([fileInputRef, 'access', _30 => _30.current, 'optionalAccess', _31 => _31.click, 'call', _32 => _32()]);
1722
+ _optionalChain([fileInputRef, 'access', _32 => _32.current, 'optionalAccess', _33 => _33.click, 'call', _34 => _34()]);
1599
1723
  setShowMenu(false);
1600
1724
  },
1601
1725
  className: "w-full flex items-center gap-3 px-4 py-3 hover:bg-gray-700 dark:hover:bg-gray-600 transition-colors !text-white text-left",
@@ -1714,8 +1838,8 @@ function CommandComposer({
1714
1838
  }
1715
1839
  };
1716
1840
  const handleNewCommand = () => {
1717
- _optionalChain([onReset, 'optionalCall', _33 => _33()]);
1718
- _optionalChain([inputRef, 'access', _34 => _34.current, 'optionalAccess', _35 => _35.focus, 'call', _36 => _36()]);
1841
+ _optionalChain([onReset, 'optionalCall', _35 => _35()]);
1842
+ _optionalChain([inputRef, 'access', _36 => _36.current, 'optionalAccess', _37 => _37.focus, 'call', _38 => _38()]);
1719
1843
  };
1720
1844
  const handleInputChange = (value) => {
1721
1845
  setInput(value);
@@ -1829,15 +1953,15 @@ function CommandComposer({
1829
1953
  {
1830
1954
  className: "fixed bg-gray-800 dark:bg-gray-700 rounded-xl shadow-lg overflow-hidden z-[9999] min-w-[200px]",
1831
1955
  style: {
1832
- left: _nullishCoalesce(_optionalChain([menuButtonRef, 'access', _37 => _37.current, 'optionalAccess', _38 => _38.getBoundingClientRect, 'call', _39 => _39(), 'access', _40 => _40.left]), () => ( 0)),
1833
- top: (_nullishCoalesce(_optionalChain([menuButtonRef, 'access', _41 => _41.current, 'optionalAccess', _42 => _42.getBoundingClientRect, 'call', _43 => _43(), 'access', _44 => _44.bottom]), () => ( 0))) + 8
1956
+ left: _nullishCoalesce(_optionalChain([menuButtonRef, 'access', _39 => _39.current, 'optionalAccess', _40 => _40.getBoundingClientRect, 'call', _41 => _41(), 'access', _42 => _42.left]), () => ( 0)),
1957
+ top: (_nullishCoalesce(_optionalChain([menuButtonRef, 'access', _43 => _43.current, 'optionalAccess', _44 => _44.getBoundingClientRect, 'call', _45 => _45(), 'access', _46 => _46.bottom]), () => ( 0))) + 8
1834
1958
  },
1835
1959
  children: [
1836
1960
  /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
1837
1961
  "button",
1838
1962
  {
1839
1963
  onClick: () => {
1840
- _optionalChain([fileInputRef, 'access', _45 => _45.current, 'optionalAccess', _46 => _46.click, 'call', _47 => _47()]);
1964
+ _optionalChain([fileInputRef, 'access', _47 => _47.current, 'optionalAccess', _48 => _48.click, 'call', _49 => _49()]);
1841
1965
  setShowMenu(false);
1842
1966
  },
1843
1967
  className: "w-full flex items-center gap-3 px-4 py-3 hover:bg-gray-700 dark:hover:bg-gray-600 transition-colors !text-white text-left",
@@ -2078,7 +2202,7 @@ var AptevaClient = class {
2078
2202
  const error = await response.json().catch(() => ({ error: "Request failed" }));
2079
2203
  throw new Error(error.error || `Request failed with status ${response.status}`);
2080
2204
  }
2081
- const reader = _optionalChain([response, 'access', _48 => _48.body, 'optionalAccess', _49 => _49.getReader, 'call', _50 => _50()]);
2205
+ const reader = _optionalChain([response, 'access', _50 => _50.body, 'optionalAccess', _51 => _51.getReader, 'call', _52 => _52()]);
2082
2206
  if (!reader) {
2083
2207
  throw new Error("Response body is not readable");
2084
2208
  }
@@ -2096,7 +2220,7 @@ var AptevaClient = class {
2096
2220
  if (line.startsWith("data: ")) {
2097
2221
  const data = line.slice(6);
2098
2222
  if (data === "[DONE]") {
2099
- _optionalChain([onComplete, 'optionalCall', _51 => _51(threadId)]);
2223
+ _optionalChain([onComplete, 'optionalCall', _53 => _53(threadId)]);
2100
2224
  return;
2101
2225
  }
2102
2226
  try {
@@ -2111,10 +2235,10 @@ var AptevaClient = class {
2111
2235
  }
2112
2236
  }
2113
2237
  }
2114
- _optionalChain([onComplete, 'optionalCall', _52 => _52(threadId)]);
2238
+ _optionalChain([onComplete, 'optionalCall', _54 => _54(threadId)]);
2115
2239
  } catch (error) {
2116
2240
  const err = error instanceof Error ? error : new Error("Unknown error");
2117
- _optionalChain([onError, 'optionalCall', _53 => _53(err)]);
2241
+ _optionalChain([onError, 'optionalCall', _55 => _55(err)]);
2118
2242
  throw err;
2119
2243
  }
2120
2244
  }
@@ -2228,6 +2352,7 @@ function Chat({
2228
2352
  const [isLoading, setIsLoading] = _react.useState.call(void 0, false);
2229
2353
  const [currentThreadId, setCurrentThreadId] = _react.useState.call(void 0, threadId || null);
2230
2354
  const [mode, setMode] = _react.useState.call(void 0, initialMode);
2355
+ const [chatToolName, setChatToolName] = _react.useState.call(void 0, null);
2231
2356
  const [commandState, setCommandState] = _react.useState.call(void 0, "idle");
2232
2357
  const [commandResult, setCommandResult] = _react.useState.call(void 0, null);
2233
2358
  const [commandError, setCommandError] = _react.useState.call(void 0, null);
@@ -2257,7 +2382,7 @@ ${widgetContext}` : widgetContext;
2257
2382
  }, [apiUrl, apiKey]);
2258
2383
  _react.useEffect.call(void 0, () => {
2259
2384
  if (threadId) {
2260
- _optionalChain([onThreadChange, 'optionalCall', _54 => _54(threadId)]);
2385
+ _optionalChain([onThreadChange, 'optionalCall', _56 => _56(threadId)]);
2261
2386
  }
2262
2387
  }, [threadId, onThreadChange]);
2263
2388
  _react.useEffect.call(void 0, () => {
@@ -2275,7 +2400,7 @@ ${widgetContext}` : widgetContext;
2275
2400
  }, [showSettingsMenu]);
2276
2401
  const handleModeChange = (newMode) => {
2277
2402
  setMode(newMode);
2278
- _optionalChain([onModeChange, 'optionalCall', _55 => _55(newMode)]);
2403
+ _optionalChain([onModeChange, 'optionalCall', _57 => _57(newMode)]);
2279
2404
  if (newMode === "command") {
2280
2405
  setCommandState("idle");
2281
2406
  setCommandResult(null);
@@ -2295,7 +2420,7 @@ ${widgetContext}` : widgetContext;
2295
2420
  metadata: hasFiles ? { attachments: fileNames } : void 0
2296
2421
  };
2297
2422
  setMessages((prev) => [...prev, userMessage]);
2298
- _optionalChain([onMessageSent, 'optionalCall', _56 => _56(userMessage)]);
2423
+ _optionalChain([onMessageSent, 'optionalCall', _58 => _58(userMessage)]);
2299
2424
  setIsLoading(true);
2300
2425
  try {
2301
2426
  const messagePayload = await buildMessageWithAttachments(text, files);
@@ -2308,6 +2433,7 @@ ${widgetContext}` : widgetContext;
2308
2433
  let accumulatedWidgets = [];
2309
2434
  let responseThreadId = currentThreadId;
2310
2435
  let toolInputBuffer = "";
2436
+ const streamingMessageId = `msg-${Date.now()}`;
2311
2437
  const updateMessage = () => {
2312
2438
  const segments = [...contentSegments];
2313
2439
  if (currentTextBuffer) {
@@ -2327,19 +2453,19 @@ ${widgetContext}` : widgetContext;
2327
2453
  ...lastMessage,
2328
2454
  content: currentTextBuffer,
2329
2455
  widgets: accumulatedWidgets.length > 0 ? accumulatedWidgets : void 0,
2330
- metadata: { ...lastMessage.metadata, content_segments: segments }
2456
+ metadata: { ...lastMessage.metadata, content_segments: segments, isStreaming: true }
2331
2457
  }
2332
2458
  ];
2333
2459
  } else {
2334
2460
  return [
2335
2461
  ...prev,
2336
2462
  {
2337
- id: `msg-${Date.now()}-streaming`,
2463
+ id: streamingMessageId,
2338
2464
  role: "assistant",
2339
2465
  content: currentTextBuffer,
2340
2466
  widgets: accumulatedWidgets.length > 0 ? accumulatedWidgets : void 0,
2341
2467
  timestamp: /* @__PURE__ */ new Date(),
2342
- metadata: { content_segments: segments }
2468
+ metadata: { content_segments: segments, isStreaming: true }
2343
2469
  }
2344
2470
  ];
2345
2471
  }
@@ -2360,7 +2486,7 @@ ${widgetContext}` : widgetContext;
2360
2486
  responseThreadId = chunk.thread_id;
2361
2487
  if (!currentThreadId) {
2362
2488
  setCurrentThreadId(chunk.thread_id);
2363
- _optionalChain([onThreadChange, 'optionalCall', _57 => _57(chunk.thread_id)]);
2489
+ _optionalChain([onThreadChange, 'optionalCall', _59 => _59(chunk.thread_id)]);
2364
2490
  }
2365
2491
  }
2366
2492
  break;
@@ -2384,6 +2510,7 @@ ${widgetContext}` : widgetContext;
2384
2510
  }
2385
2511
  contentSegments.push({ type: "tool", id: chunk.tool_id, name: chunk.tool_name });
2386
2512
  toolInputBuffer = "";
2513
+ setChatToolName(chunk.tool_name);
2387
2514
  updateMessage();
2388
2515
  }
2389
2516
  break;
@@ -2397,8 +2524,9 @@ ${widgetContext}` : widgetContext;
2397
2524
  const toolSegment = contentSegments.find((s) => s.type === "tool" && s.id === chunk.tool_id);
2398
2525
  if (toolSegment) {
2399
2526
  toolSegment.result = chunk.content;
2400
- _optionalChain([onToolResult, 'optionalCall', _58 => _58(toolSegment.name, chunk.content)]);
2527
+ _optionalChain([onToolResult, 'optionalCall', _60 => _60(toolSegment.name, chunk.content)]);
2401
2528
  }
2529
+ setChatToolName(null);
2402
2530
  updateMessage();
2403
2531
  }
2404
2532
  break;
@@ -2428,10 +2556,10 @@ ${widgetContext}` : widgetContext;
2428
2556
  ...prev.slice(0, -1),
2429
2557
  {
2430
2558
  ...lastMessage,
2431
- id: `msg-${Date.now()}`,
2559
+ // Keep the same ID to avoid React remounting the component
2432
2560
  content: currentTextBuffer || "Response received",
2433
2561
  widgets: accumulatedWidgets.length > 0 ? accumulatedWidgets : void 0,
2434
- metadata: { thread_id: threadId2, content_segments: contentSegments }
2562
+ metadata: { thread_id: threadId2, content_segments: contentSegments, isStreaming: false }
2435
2563
  }
2436
2564
  ];
2437
2565
  }
@@ -2439,10 +2567,11 @@ ${widgetContext}` : widgetContext;
2439
2567
  });
2440
2568
  if (threadId2 && threadId2 !== currentThreadId) {
2441
2569
  setCurrentThreadId(threadId2);
2442
- _optionalChain([onThreadChange, 'optionalCall', _59 => _59(threadId2)]);
2570
+ _optionalChain([onThreadChange, 'optionalCall', _61 => _61(threadId2)]);
2443
2571
  }
2444
2572
  setIsLoading(false);
2445
2573
  setCurrentRequestId(null);
2574
+ setChatToolName(null);
2446
2575
  },
2447
2576
  (error) => {
2448
2577
  const errorMessage = {
@@ -2461,7 +2590,8 @@ ${widgetContext}` : widgetContext;
2461
2590
  });
2462
2591
  setIsLoading(false);
2463
2592
  setCurrentRequestId(null);
2464
- _optionalChain([onError, 'optionalCall', _60 => _60(error)]);
2593
+ setChatToolName(null);
2594
+ _optionalChain([onError, 'optionalCall', _62 => _62(error)]);
2465
2595
  }
2466
2596
  );
2467
2597
  }
@@ -2474,7 +2604,7 @@ ${widgetContext}` : widgetContext;
2474
2604
  metadata: { error: true }
2475
2605
  };
2476
2606
  setMessages((prev) => [...prev, errorMessage]);
2477
- _optionalChain([onError, 'optionalCall', _61 => _61(error instanceof Error ? error : new Error("Unknown error"))]);
2607
+ _optionalChain([onError, 'optionalCall', _63 => _63(error instanceof Error ? error : new Error("Unknown error"))]);
2478
2608
  } finally {
2479
2609
  setIsLoading(false);
2480
2610
  }
@@ -2519,7 +2649,7 @@ ${planningInstruction}` : planningInstruction;
2519
2649
  const error = err instanceof Error ? err : new Error("Failed to generate plan");
2520
2650
  setCommandError(error);
2521
2651
  setCommandState("error");
2522
- _optionalChain([onError, 'optionalCall', _62 => _62(error)]);
2652
+ _optionalChain([onError, 'optionalCall', _64 => _64(error)]);
2523
2653
  }
2524
2654
  }
2525
2655
  return;
@@ -2552,12 +2682,12 @@ ${planningInstruction}` : planningInstruction;
2552
2682
  setCommandResult(result);
2553
2683
  setCommandState("success");
2554
2684
  setProgress(100);
2555
- _optionalChain([onComplete, 'optionalCall', _63 => _63(result)]);
2685
+ _optionalChain([onComplete, 'optionalCall', _65 => _65(result)]);
2556
2686
  },
2557
2687
  (error) => {
2558
2688
  setCommandError(error);
2559
2689
  setCommandState("error");
2560
- _optionalChain([onError, 'optionalCall', _64 => _64(error)]);
2690
+ _optionalChain([onError, 'optionalCall', _66 => _66(error)]);
2561
2691
  }
2562
2692
  );
2563
2693
  } else {
@@ -2570,7 +2700,7 @@ ${planningInstruction}` : planningInstruction;
2570
2700
  setCommandResult(result);
2571
2701
  setCommandState("success");
2572
2702
  setProgress(100);
2573
- _optionalChain([onComplete, 'optionalCall', _65 => _65(result)]);
2703
+ _optionalChain([onComplete, 'optionalCall', _67 => _67(result)]);
2574
2704
  }
2575
2705
  } else {
2576
2706
  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.`;
@@ -2602,12 +2732,12 @@ ${commandInstruction}` : commandInstruction;
2602
2732
  accumulatedContent = "";
2603
2733
  setStreamedContent("");
2604
2734
  } else if (chunk.type === "tool_result") {
2605
- _optionalChain([onToolResult, 'optionalCall', _66 => _66(lastToolName, chunk.content)]);
2735
+ _optionalChain([onToolResult, 'optionalCall', _68 => _68(lastToolName, chunk.content)]);
2606
2736
  setCurrentToolName(null);
2607
2737
  } else if (chunk.type === "thread_id" && chunk.thread_id) {
2608
2738
  if (!currentThreadId) {
2609
2739
  setCurrentThreadId(chunk.thread_id);
2610
- _optionalChain([onThreadChange, 'optionalCall', _67 => _67(chunk.thread_id)]);
2740
+ _optionalChain([onThreadChange, 'optionalCall', _69 => _69(chunk.thread_id)]);
2611
2741
  }
2612
2742
  } else if (chunk.type === "request_id" && chunk.request_id) {
2613
2743
  setCurrentRequestId(chunk.request_id);
@@ -2623,13 +2753,13 @@ ${commandInstruction}` : commandInstruction;
2623
2753
  setCommandState("success");
2624
2754
  setProgress(100);
2625
2755
  setCurrentRequestId(null);
2626
- _optionalChain([onComplete, 'optionalCall', _68 => _68(result)]);
2756
+ _optionalChain([onComplete, 'optionalCall', _70 => _70(result)]);
2627
2757
  },
2628
2758
  (error) => {
2629
2759
  setCommandError(error);
2630
2760
  setCommandState("error");
2631
2761
  setCurrentRequestId(null);
2632
- _optionalChain([onError, 'optionalCall', _69 => _69(error)]);
2762
+ _optionalChain([onError, 'optionalCall', _71 => _71(error)]);
2633
2763
  }
2634
2764
  );
2635
2765
  } else {
@@ -2649,14 +2779,14 @@ ${commandInstruction}` : commandInstruction;
2649
2779
  setCommandResult(result);
2650
2780
  setCommandState("success");
2651
2781
  setProgress(100);
2652
- _optionalChain([onComplete, 'optionalCall', _70 => _70(result)]);
2782
+ _optionalChain([onComplete, 'optionalCall', _72 => _72(result)]);
2653
2783
  }
2654
2784
  }
2655
2785
  } catch (err) {
2656
2786
  const error = err instanceof Error ? err : new Error("Unknown error");
2657
2787
  setCommandError(error);
2658
2788
  setCommandState("error");
2659
- _optionalChain([onError, 'optionalCall', _71 => _71(error)]);
2789
+ _optionalChain([onError, 'optionalCall', _73 => _73(error)]);
2660
2790
  }
2661
2791
  };
2662
2792
  const resetCommand = () => {
@@ -2704,7 +2834,13 @@ ${planToExecute}`;
2704
2834
  };
2705
2835
  const isCompact = commandVariant === "compact";
2706
2836
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: cn("flex flex-col h-full", className), children: [
2707
- showHeader && mode === "chat" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "px-4 py-3 flex items-center justify-between", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h2", { className: "!text-lg font-semibold !text-gray-900 dark:!text-white", children: headerTitle }) }),
2837
+ showHeader && mode === "chat" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "px-4 py-3 flex items-center justify-between", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { children: [
2838
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h2", { className: "!text-lg font-semibold !text-gray-900 dark:!text-white", children: headerTitle }),
2839
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: cn(
2840
+ "!text-xs",
2841
+ isLoading ? chatToolName ? "!text-blue-500 dark:!text-blue-400" : "!text-gray-400 dark:!text-gray-500" : "!text-gray-400 dark:!text-gray-500"
2842
+ ), children: isLoading ? chatToolName ? `Using ${chatToolName}...` : "Thinking..." : "Ready" })
2843
+ ] }) }),
2708
2844
  mode === "chat" && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
2709
2845
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
2710
2846
  MessageList,
@@ -2717,10 +2853,10 @@ ${planToExecute}`;
2717
2853
  suggestedPrompts,
2718
2854
  welcomeVariant,
2719
2855
  onPromptClick: (prompt) => handleSendMessage(prompt),
2720
- enableWidgets
2856
+ enableWidgets,
2857
+ onWidgetRender
2721
2858
  }
2722
2859
  ),
2723
- isLoading && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "px-4 py-2 !text-sm !text-gray-500 dark:!text-gray-400 italic", children: "AI is thinking..." }),
2724
2860
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
2725
2861
  Composer,
2726
2862
  {
@@ -2742,8 +2878,8 @@ ${planToExecute}`;
2742
2878
  executeCommand(text, files);
2743
2879
  },
2744
2880
  state: commandState,
2745
- response: _optionalChain([commandResult, 'optionalAccess', _72 => _72.data, 'optionalAccess', _73 => _73.summary]) || _optionalChain([commandResult, 'optionalAccess', _74 => _74.message]),
2746
- error: _optionalChain([commandError, 'optionalAccess', _75 => _75.message]),
2881
+ response: _optionalChain([commandResult, 'optionalAccess', _74 => _74.data, 'optionalAccess', _75 => _75.summary]) || _optionalChain([commandResult, 'optionalAccess', _76 => _76.message]),
2882
+ error: _optionalChain([commandError, 'optionalAccess', _77 => _77.message]),
2747
2883
  plan,
2748
2884
  streamedContent,
2749
2885
  toolName: currentToolName,
@@ -2911,13 +3047,13 @@ ${planningInstruction}` : planningInstruction;
2911
3047
  const error2 = err instanceof Error ? err : new Error("Failed to generate plan");
2912
3048
  setError(error2);
2913
3049
  setState("error");
2914
- _optionalChain([onError, 'optionalCall', _76 => _76(error2)]);
3050
+ _optionalChain([onError, 'optionalCall', _78 => _78(error2)]);
2915
3051
  });
2916
3052
  } catch (err) {
2917
3053
  const error2 = err instanceof Error ? err : new Error("Failed to generate plan");
2918
3054
  setError(error2);
2919
3055
  setState("error");
2920
- _optionalChain([onError, 'optionalCall', _77 => _77(error2)]);
3056
+ _optionalChain([onError, 'optionalCall', _79 => _79(error2)]);
2921
3057
  }
2922
3058
  }
2923
3059
  return;
@@ -2928,7 +3064,7 @@ ${planningInstruction}` : planningInstruction;
2928
3064
  setStreamedContent("");
2929
3065
  setCommand("");
2930
3066
  setUploadedFiles([]);
2931
- _optionalChain([onStart, 'optionalCall', _78 => _78()]);
3067
+ _optionalChain([onStart, 'optionalCall', _80 => _80()]);
2932
3068
  try {
2933
3069
  if (useMock) {
2934
3070
  if (enableStreaming) {
@@ -2939,16 +3075,16 @@ ${planningInstruction}` : planningInstruction;
2939
3075
  if (chunk.type === "token" && chunk.content) {
2940
3076
  accumulatedContent += chunk.content;
2941
3077
  setStreamedContent(accumulatedContent);
2942
- _optionalChain([onChunk, 'optionalCall', _79 => _79(chunk.content)]);
3078
+ _optionalChain([onChunk, 'optionalCall', _81 => _81(chunk.content)]);
2943
3079
  const estimatedProgress = Math.min(Math.round(accumulatedContent.length / 10), 90);
2944
3080
  setProgress(estimatedProgress);
2945
- _optionalChain([onProgress, 'optionalCall', _80 => _80(estimatedProgress)]);
3081
+ _optionalChain([onProgress, 'optionalCall', _82 => _82(estimatedProgress)]);
2946
3082
  } else if (chunk.type === "widget" && chunk.widget) {
2947
3083
  const widget = chunk.widget;
2948
3084
  setResult((prev) => ({
2949
3085
  success: true,
2950
- data: _optionalChain([prev, 'optionalAccess', _81 => _81.data]) || {},
2951
- widgets: [..._optionalChain([prev, 'optionalAccess', _82 => _82.widgets]) || [], widget],
3086
+ data: _optionalChain([prev, 'optionalAccess', _83 => _83.data]) || {},
3087
+ widgets: [..._optionalChain([prev, 'optionalAccess', _84 => _84.widgets]) || [], widget],
2952
3088
  message: accumulatedContent || "Command executed successfully"
2953
3089
  }));
2954
3090
  }
@@ -2968,19 +3104,19 @@ ${planningInstruction}` : planningInstruction;
2968
3104
  setResult(result2);
2969
3105
  setState("success");
2970
3106
  setProgress(100);
2971
- _optionalChain([onComplete, 'optionalCall', _83 => _83(result2)]);
3107
+ _optionalChain([onComplete, 'optionalCall', _85 => _85(result2)]);
2972
3108
  },
2973
3109
  (error2) => {
2974
3110
  setError(error2);
2975
3111
  setState("error");
2976
- _optionalChain([onError, 'optionalCall', _84 => _84(error2)]);
3112
+ _optionalChain([onError, 'optionalCall', _86 => _86(error2)]);
2977
3113
  }
2978
3114
  );
2979
3115
  } else {
2980
3116
  const progressInterval = setInterval(() => {
2981
3117
  setProgress((prev) => {
2982
3118
  const next = Math.min(prev + 10, 90);
2983
- _optionalChain([onProgress, 'optionalCall', _85 => _85(next)]);
3119
+ _optionalChain([onProgress, 'optionalCall', _87 => _87(next)]);
2984
3120
  return next;
2985
3121
  });
2986
3122
  }, 200);
@@ -3004,7 +3140,7 @@ ${planningInstruction}` : planningInstruction;
3004
3140
  setResult(result2);
3005
3141
  setState("success");
3006
3142
  setProgress(100);
3007
- _optionalChain([onComplete, 'optionalCall', _86 => _86(result2)]);
3143
+ _optionalChain([onComplete, 'optionalCall', _88 => _88(result2)]);
3008
3144
  }
3009
3145
  } else {
3010
3146
  if (enableStreaming) {
@@ -3050,16 +3186,16 @@ ${commandInstruction}` : commandInstruction;
3050
3186
  if (chunk.type === "token" && chunk.content) {
3051
3187
  accumulatedContent += chunk.content;
3052
3188
  setStreamedContent(accumulatedContent);
3053
- _optionalChain([onChunk, 'optionalCall', _87 => _87(chunk.content)]);
3189
+ _optionalChain([onChunk, 'optionalCall', _89 => _89(chunk.content)]);
3054
3190
  const estimatedProgress = Math.min(Math.round(accumulatedContent.length / 10), 90);
3055
3191
  setProgress(estimatedProgress);
3056
- _optionalChain([onProgress, 'optionalCall', _88 => _88(estimatedProgress)]);
3192
+ _optionalChain([onProgress, 'optionalCall', _90 => _90(estimatedProgress)]);
3057
3193
  } else if (chunk.type === "widget" && chunk.widget) {
3058
3194
  const widget = chunk.widget;
3059
3195
  setResult((prev) => ({
3060
3196
  success: true,
3061
- data: _optionalChain([prev, 'optionalAccess', _89 => _89.data]) || {},
3062
- widgets: [..._optionalChain([prev, 'optionalAccess', _90 => _90.widgets]) || [], widget],
3197
+ data: _optionalChain([prev, 'optionalAccess', _91 => _91.data]) || {},
3198
+ widgets: [..._optionalChain([prev, 'optionalAccess', _92 => _92.widgets]) || [], widget],
3063
3199
  message: accumulatedContent || "Command executed successfully"
3064
3200
  }));
3065
3201
  }
@@ -3079,20 +3215,20 @@ ${commandInstruction}` : commandInstruction;
3079
3215
  setResult(result2);
3080
3216
  setState("success");
3081
3217
  setProgress(100);
3082
- _optionalChain([onComplete, 'optionalCall', _91 => _91(result2)]);
3218
+ _optionalChain([onComplete, 'optionalCall', _93 => _93(result2)]);
3083
3219
  },
3084
3220
  (error2) => {
3085
3221
  const err = error2 instanceof Error ? error2 : new Error("Unknown error");
3086
3222
  setError(err);
3087
3223
  setState("error");
3088
- _optionalChain([onError, 'optionalCall', _92 => _92(err)]);
3224
+ _optionalChain([onError, 'optionalCall', _94 => _94(err)]);
3089
3225
  }
3090
3226
  );
3091
3227
  } else {
3092
3228
  const progressInterval = setInterval(() => {
3093
3229
  setProgress((prev) => {
3094
3230
  const next = Math.min(prev + 10, 90);
3095
- _optionalChain([onProgress, 'optionalCall', _93 => _93(next)]);
3231
+ _optionalChain([onProgress, 'optionalCall', _95 => _95(next)]);
3096
3232
  return next;
3097
3233
  });
3098
3234
  }, 200);
@@ -3148,14 +3284,14 @@ ${commandInstruction}` : commandInstruction;
3148
3284
  setResult(result2);
3149
3285
  setState("success");
3150
3286
  setProgress(100);
3151
- _optionalChain([onComplete, 'optionalCall', _94 => _94(result2)]);
3287
+ _optionalChain([onComplete, 'optionalCall', _96 => _96(result2)]);
3152
3288
  }
3153
3289
  }
3154
3290
  } catch (err) {
3155
3291
  const error2 = err instanceof Error ? err : new Error("Unknown error");
3156
3292
  setError(error2);
3157
3293
  setState("error");
3158
- _optionalChain([onError, 'optionalCall', _95 => _95(error2)]);
3294
+ _optionalChain([onError, 'optionalCall', _97 => _97(error2)]);
3159
3295
  }
3160
3296
  };
3161
3297
  const resetCommand = () => {
@@ -3188,14 +3324,14 @@ ${planToExecute}`;
3188
3324
  };
3189
3325
  const handleFileSelect = async (e) => {
3190
3326
  if (e.target.files && e.target.files.length > 0) {
3191
- _optionalChain([onFileUpload, 'optionalCall', _96 => _96(e.target.files)]);
3327
+ _optionalChain([onFileUpload, 'optionalCall', _98 => _98(e.target.files)]);
3192
3328
  const files = [];
3193
3329
  for (let i = 0; i < e.target.files.length; i++) {
3194
3330
  const file = e.target.files[i];
3195
3331
  const reader = new FileReader();
3196
3332
  await new Promise((resolve) => {
3197
3333
  reader.onload = (event) => {
3198
- if (_optionalChain([event, 'access', _97 => _97.target, 'optionalAccess', _98 => _98.result])) {
3334
+ if (_optionalChain([event, 'access', _99 => _99.target, 'optionalAccess', _100 => _100.result])) {
3199
3335
  const fullDataUrl = event.target.result;
3200
3336
  const base64Data = fullDataUrl.split(",")[1];
3201
3337
  if (file.type.startsWith("image/")) {
@@ -3289,7 +3425,7 @@ ${planToExecute}`;
3289
3425
  enableFileUpload && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
3290
3426
  "button",
3291
3427
  {
3292
- onClick: () => _optionalChain([fileInputRef, 'access', _99 => _99.current, 'optionalAccess', _100 => _100.click, 'call', _101 => _101()]),
3428
+ onClick: () => _optionalChain([fileInputRef, 'access', _101 => _101.current, 'optionalAccess', _102 => _102.click, 'call', _103 => _103()]),
3293
3429
  className: "w-8 h-8 rounded-lg flex items-center justify-center transition-all flex-shrink-0 !text-gray-500 dark:!text-gray-500 hover:bg-gray-100 dark:hover:bg-gray-800",
3294
3430
  title: "Attach file",
3295
3431
  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)" }) })
@@ -3508,7 +3644,7 @@ ${planToExecute}`;
3508
3644
  /* @__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" }) }),
3509
3645
  /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { children: [
3510
3646
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h3", { className: "text-sm font-semibold text-red-800 dark:text-red-400", children: "Error" }),
3511
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-red-700 dark:text-red-300 text-sm mt-1", children: _optionalChain([error, 'optionalAccess', _102 => _102.message]) })
3647
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-red-700 dark:text-red-300 text-sm mt-1", children: _optionalChain([error, 'optionalAccess', _104 => _104.message]) })
3512
3648
  ] })
3513
3649
  ] }) }),
3514
3650
  allowInput && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
@@ -3536,7 +3672,7 @@ ${planToExecute}`;
3536
3672
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-green-700 dark:text-green-300 text-sm", children: "Command executed successfully" })
3537
3673
  ] })
3538
3674
  ] }),
3539
- _optionalChain([result, 'access', _103 => _103.data, 'optionalAccess', _104 => _104.summary]) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "text-gray-700 dark:text-gray-300 text-sm leading-relaxed whitespace-pre-line", children: result.data.summary }),
3675
+ _optionalChain([result, 'access', _105 => _105.data, 'optionalAccess', _106 => _106.summary]) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "text-gray-700 dark:text-gray-300 text-sm leading-relaxed whitespace-pre-line", children: result.data.summary }),
3540
3676
  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,
3541
3677
  WidgetRenderer,
3542
3678
  {
@@ -3587,7 +3723,7 @@ ${planToExecute}`;
3587
3723
  enableFileUpload && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
3588
3724
  "button",
3589
3725
  {
3590
- onClick: () => _optionalChain([fileInputRef, 'access', _105 => _105.current, 'optionalAccess', _106 => _106.click, 'call', _107 => _107()]),
3726
+ onClick: () => _optionalChain([fileInputRef, 'access', _107 => _107.current, 'optionalAccess', _108 => _108.click, 'call', _109 => _109()]),
3591
3727
  className: "w-8 h-8 rounded-lg flex items-center justify-center transition-all flex-shrink-0 !text-gray-500 dark:!text-gray-500 hover:bg-gray-100 dark:hover:bg-gray-800",
3592
3728
  title: "Attach file",
3593
3729
  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)" }) })
@@ -3773,25 +3909,25 @@ function Prompt({
3773
3909
  const newValue = e.target.value;
3774
3910
  if (!maxLength || newValue.length <= maxLength) {
3775
3911
  setValue(newValue);
3776
- _optionalChain([onChange, 'optionalCall', _108 => _108(newValue)]);
3912
+ _optionalChain([onChange, 'optionalCall', _110 => _110(newValue)]);
3777
3913
  }
3778
3914
  };
3779
3915
  const handleSubmit = async () => {
3780
3916
  if (value.length < minLength) return;
3781
- _optionalChain([onSubmit, 'optionalCall', _109 => _109(value)]);
3917
+ _optionalChain([onSubmit, 'optionalCall', _111 => _111(value)]);
3782
3918
  setIsLoading(true);
3783
3919
  try {
3784
3920
  if (useMock) {
3785
3921
  await new Promise((resolve) => setTimeout(resolve, 1500));
3786
3922
  const mockResult = `Enhanced version: ${value} [AI-generated content]`;
3787
- _optionalChain([onResult, 'optionalCall', _110 => _110(mockResult)]);
3923
+ _optionalChain([onResult, 'optionalCall', _112 => _112(mockResult)]);
3788
3924
  setValue("");
3789
3925
  } else {
3790
3926
  const response = await aptevaClient.chat({
3791
3927
  agent_id: agentId,
3792
3928
  message: value
3793
3929
  });
3794
- _optionalChain([onResult, 'optionalCall', _111 => _111(response.message)]);
3930
+ _optionalChain([onResult, 'optionalCall', _113 => _113(response.message)]);
3795
3931
  setValue("");
3796
3932
  }
3797
3933
  } catch (error) {
@@ -3886,7 +4022,7 @@ function Stream({
3886
4022
  }, [autoStart]);
3887
4023
  const startStreaming = async () => {
3888
4024
  setIsStreaming(true);
3889
- _optionalChain([onStart, 'optionalCall', _112 => _112()]);
4025
+ _optionalChain([onStart, 'optionalCall', _114 => _114()]);
3890
4026
  try {
3891
4027
  if (useMock) {
3892
4028
  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.";
@@ -3894,13 +4030,13 @@ function Stream({
3894
4030
  mockText,
3895
4031
  (chunk) => {
3896
4032
  setText((prev) => prev + chunk);
3897
- _optionalChain([onChunk, 'optionalCall', _113 => _113(chunk)]);
4033
+ _optionalChain([onChunk, 'optionalCall', _115 => _115(chunk)]);
3898
4034
  },
3899
4035
  typingSpeed
3900
4036
  );
3901
4037
  setIsComplete(true);
3902
4038
  setIsStreaming(false);
3903
- _optionalChain([onComplete, 'optionalCall', _114 => _114(text + mockText)]);
4039
+ _optionalChain([onComplete, 'optionalCall', _116 => _116(text + mockText)]);
3904
4040
  } else {
3905
4041
  let accumulatedText = "";
3906
4042
  await aptevaClient.chatStream(
@@ -3913,24 +4049,24 @@ function Stream({
3913
4049
  if (chunk.type === "token" && chunk.content) {
3914
4050
  accumulatedText += chunk.content;
3915
4051
  setText(accumulatedText);
3916
- _optionalChain([onChunk, 'optionalCall', _115 => _115(chunk.content)]);
4052
+ _optionalChain([onChunk, 'optionalCall', _117 => _117(chunk.content)]);
3917
4053
  }
3918
4054
  },
3919
4055
  () => {
3920
4056
  setIsComplete(true);
3921
4057
  setIsStreaming(false);
3922
- _optionalChain([onComplete, 'optionalCall', _116 => _116(accumulatedText)]);
4058
+ _optionalChain([onComplete, 'optionalCall', _118 => _118(accumulatedText)]);
3923
4059
  },
3924
4060
  (error) => {
3925
4061
  const err = error instanceof Error ? error : new Error("Streaming error");
3926
- _optionalChain([onError, 'optionalCall', _117 => _117(err)]);
4062
+ _optionalChain([onError, 'optionalCall', _119 => _119(err)]);
3927
4063
  setIsStreaming(false);
3928
4064
  }
3929
4065
  );
3930
4066
  }
3931
4067
  } catch (error) {
3932
4068
  const err = error instanceof Error ? error : new Error("Streaming error");
3933
- _optionalChain([onError, 'optionalCall', _118 => _118(err)]);
4069
+ _optionalChain([onError, 'optionalCall', _120 => _120(err)]);
3934
4070
  setIsStreaming(false);
3935
4071
  }
3936
4072
  };
@@ -4022,7 +4158,7 @@ function ThreadList({
4022
4158
  }) {
4023
4159
  const [searchQuery, setSearchQuery] = _react.useState.call(void 0, "");
4024
4160
  const filteredThreads = threads.filter(
4025
- (thread) => thread.title.toLowerCase().includes(searchQuery.toLowerCase()) || _optionalChain([thread, 'access', _119 => _119.preview, 'optionalAccess', _120 => _120.toLowerCase, 'call', _121 => _121(), 'access', _122 => _122.includes, 'call', _123 => _123(searchQuery.toLowerCase())])
4161
+ (thread) => thread.title.toLowerCase().includes(searchQuery.toLowerCase()) || _optionalChain([thread, 'access', _121 => _121.preview, 'optionalAccess', _122 => _122.toLowerCase, 'call', _123 => _123(), 'access', _124 => _124.includes, 'call', _125 => _125(searchQuery.toLowerCase())])
4026
4162
  );
4027
4163
  const groupedThreads = groupBy === "date" ? groupThreadsByDate(filteredThreads) : { All: filteredThreads };
4028
4164
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex flex-col h-full", children: [
@@ -4044,8 +4180,8 @@ function ThreadList({
4044
4180
  {
4045
4181
  thread,
4046
4182
  isActive: thread.id === currentThreadId,
4047
- onSelect: () => _optionalChain([onThreadSelect, 'optionalCall', _124 => _124(thread.id)]),
4048
- onDelete: () => _optionalChain([onThreadDelete, 'optionalCall', _125 => _125(thread.id)])
4183
+ onSelect: () => _optionalChain([onThreadSelect, 'optionalCall', _126 => _126(thread.id)]),
4184
+ onDelete: () => _optionalChain([onThreadDelete, 'optionalCall', _127 => _127(thread.id)])
4049
4185
  },
4050
4186
  thread.id
4051
4187
  ))
@@ -4107,7 +4243,7 @@ function Threads({
4107
4243
  threads.slice(0, 5).map((thread) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
4108
4244
  "button",
4109
4245
  {
4110
- onClick: () => _optionalChain([onThreadSelect, 'optionalCall', _126 => _126(thread.id)]),
4246
+ onClick: () => _optionalChain([onThreadSelect, 'optionalCall', _128 => _128(thread.id)]),
4111
4247
  className: cn(
4112
4248
  "px-4 py-2 whitespace-nowrap font-medium transition-colors",
4113
4249
  thread.id === currentThreadId ? "border-b-2 border-apteva-500 text-apteva-500" : "text-gray-600 hover:text-gray-900"