@apteva/apteva-kit 0.1.39 → 0.1.41

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.mjs CHANGED
@@ -1251,7 +1251,7 @@ function ToolCall({ name, status }) {
1251
1251
  }
1252
1252
 
1253
1253
  // src/components/Chat/Message.tsx
1254
- import { Fragment, jsx as jsx11, jsxs as jsxs8 } from "react/jsx-runtime";
1254
+ import { jsx as jsx11, jsxs as jsxs8 } from "react/jsx-runtime";
1255
1255
  function Message({ message, onAction, enableWidgets, onWidgetRender }) {
1256
1256
  const isUser = message.role === "user";
1257
1257
  const contentSegments = message.metadata?.content_segments;
@@ -1290,21 +1290,50 @@ function Message({ message, onAction, enableWidgets, onWidgetRender }) {
1290
1290
  return /* @__PURE__ */ jsx11(MarkdownContent, { content: text });
1291
1291
  }
1292
1292
  const parsed = parseWidgetsFromText(text);
1293
- if (parsed.segments.length === 0) {
1293
+ const cleanedText = parsed.segments.filter((seg) => seg.type === "text" && seg.content).map((seg) => seg.content).join("");
1294
+ if (!cleanedText.trim()) {
1294
1295
  return null;
1295
1296
  }
1296
- return /* @__PURE__ */ jsx11(Fragment, { children: parsed.segments.map((segment, index) => {
1297
+ return /* @__PURE__ */ jsx11(MarkdownContent, { content: cleanedText });
1298
+ };
1299
+ const renderContentWithWidgets = () => {
1300
+ if (!enableWidgets || isUser || !message.content) {
1301
+ return null;
1302
+ }
1303
+ const parsed = parseWidgetsFromText(message.content);
1304
+ const elements = [];
1305
+ let textBuffer = "";
1306
+ parsed.segments.forEach((segment, index) => {
1297
1307
  if (segment.type === "text" && segment.content) {
1298
- return /* @__PURE__ */ jsx11(MarkdownContent, { content: segment.content }, `text-${index}`);
1299
- }
1300
- if (segment.type === "widget" && segment.widget) {
1301
- return /* @__PURE__ */ jsx11("div", { className: "my-3", children: /* @__PURE__ */ jsx11(WidgetRenderer, { widget: segment.widget, onAction }) }, `widget-${index}`);
1302
- }
1303
- if (segment.type === "widget_pending" && segment.pendingType) {
1304
- return /* @__PURE__ */ jsx11("div", { className: "my-3", children: /* @__PURE__ */ jsx11(WidgetSkeleton, { type: segment.pendingType }) }, `pending-${index}`);
1308
+ textBuffer += segment.content;
1309
+ } else if (segment.type === "widget" && segment.widget) {
1310
+ if (textBuffer.trim()) {
1311
+ elements.push(
1312
+ /* @__PURE__ */ jsx11("div", { className: "apteva-message-bubble apteva-message-assistant", children: /* @__PURE__ */ jsx11("div", { className: "apteva-message-content-assistant", children: /* @__PURE__ */ jsx11(MarkdownContent, { content: textBuffer }) }) }, `text-${index}`)
1313
+ );
1314
+ textBuffer = "";
1315
+ }
1316
+ elements.push(
1317
+ /* @__PURE__ */ jsx11("div", { className: "apteva-widget-standalone", children: /* @__PURE__ */ jsx11(WidgetRenderer, { widget: segment.widget, onAction }) }, `widget-${index}`)
1318
+ );
1319
+ } else if (segment.type === "widget_pending" && segment.pendingType) {
1320
+ if (textBuffer.trim()) {
1321
+ elements.push(
1322
+ /* @__PURE__ */ jsx11("div", { className: "apteva-message-bubble apteva-message-assistant", children: /* @__PURE__ */ jsx11("div", { className: "apteva-message-content-assistant", children: /* @__PURE__ */ jsx11(MarkdownContent, { content: textBuffer }) }) }, `text-${index}`)
1323
+ );
1324
+ textBuffer = "";
1325
+ }
1326
+ elements.push(
1327
+ /* @__PURE__ */ jsx11("div", { className: "apteva-widget-standalone", children: /* @__PURE__ */ jsx11(WidgetSkeleton, { type: segment.pendingType }) }, `pending-${index}`)
1328
+ );
1305
1329
  }
1306
- return null;
1307
- }) });
1330
+ });
1331
+ if (textBuffer.trim()) {
1332
+ elements.push(
1333
+ /* @__PURE__ */ jsx11("div", { className: "apteva-message-bubble apteva-message-assistant", children: /* @__PURE__ */ jsx11("div", { className: "apteva-message-content-assistant", children: /* @__PURE__ */ jsx11(MarkdownContent, { content: textBuffer }) }) }, "text-final")
1334
+ );
1335
+ }
1336
+ return elements.length > 0 ? elements : null;
1308
1337
  };
1309
1338
  const renderContent = () => {
1310
1339
  if (isUser) {
@@ -1322,6 +1351,45 @@ function Message({ message, onAction, enableWidgets, onWidgetRender }) {
1322
1351
  }
1323
1352
  return renderTextContent(message.content);
1324
1353
  };
1354
+ const renderTextSegmentWithWidgets = (text, keyPrefix) => {
1355
+ if (!enableWidgets) {
1356
+ return /* @__PURE__ */ jsx11("div", { className: "apteva-message-bubble apteva-message-assistant", children: /* @__PURE__ */ jsx11("div", { className: "apteva-message-content-assistant", children: /* @__PURE__ */ jsx11(MarkdownContent, { content: text }) }) }, keyPrefix);
1357
+ }
1358
+ const parsed = parseWidgetsFromText(text);
1359
+ const elements = [];
1360
+ let textBuffer = "";
1361
+ parsed.segments.forEach((seg, idx) => {
1362
+ if (seg.type === "text" && seg.content) {
1363
+ textBuffer += seg.content;
1364
+ } else if (seg.type === "widget" && seg.widget) {
1365
+ if (textBuffer.trim()) {
1366
+ elements.push(
1367
+ /* @__PURE__ */ jsx11("div", { className: "apteva-message-bubble apteva-message-assistant", children: /* @__PURE__ */ jsx11("div", { className: "apteva-message-content-assistant", children: /* @__PURE__ */ jsx11(MarkdownContent, { content: textBuffer }) }) }, `${keyPrefix}-text-${idx}`)
1368
+ );
1369
+ textBuffer = "";
1370
+ }
1371
+ elements.push(
1372
+ /* @__PURE__ */ jsx11("div", { className: "apteva-widget-standalone", children: /* @__PURE__ */ jsx11(WidgetRenderer, { widget: seg.widget, onAction }) }, `${keyPrefix}-widget-${idx}`)
1373
+ );
1374
+ } else if (seg.type === "widget_pending" && seg.pendingType) {
1375
+ if (textBuffer.trim()) {
1376
+ elements.push(
1377
+ /* @__PURE__ */ jsx11("div", { className: "apteva-message-bubble apteva-message-assistant", children: /* @__PURE__ */ jsx11("div", { className: "apteva-message-content-assistant", children: /* @__PURE__ */ jsx11(MarkdownContent, { content: textBuffer }) }) }, `${keyPrefix}-text-${idx}`)
1378
+ );
1379
+ textBuffer = "";
1380
+ }
1381
+ elements.push(
1382
+ /* @__PURE__ */ jsx11("div", { className: "apteva-widget-standalone", children: /* @__PURE__ */ jsx11(WidgetSkeleton, { type: seg.pendingType }) }, `${keyPrefix}-pending-${idx}`)
1383
+ );
1384
+ }
1385
+ });
1386
+ if (textBuffer.trim()) {
1387
+ elements.push(
1388
+ /* @__PURE__ */ jsx11("div", { className: "apteva-message-bubble apteva-message-assistant", children: /* @__PURE__ */ jsx11("div", { className: "apteva-message-content-assistant", children: /* @__PURE__ */ jsx11(MarkdownContent, { content: textBuffer }) }) }, `${keyPrefix}-text-final`)
1389
+ );
1390
+ }
1391
+ return elements;
1392
+ };
1325
1393
  const renderSegmentedContent = () => {
1326
1394
  if (!contentSegments || contentSegments.length === 0) {
1327
1395
  return null;
@@ -1329,16 +1397,12 @@ function Message({ message, onAction, enableWidgets, onWidgetRender }) {
1329
1397
  const elements = [];
1330
1398
  contentSegments.forEach((segment, index) => {
1331
1399
  if (segment.type === "text" && segment.content) {
1332
- elements.push(
1333
- /* @__PURE__ */ jsx11(
1334
- "div",
1335
- {
1336
- className: "apteva-message-bubble apteva-message-assistant",
1337
- children: /* @__PURE__ */ jsx11("div", { className: "apteva-message-content-assistant", children: renderTextContent(segment.content) })
1338
- },
1339
- `text-${index}`
1340
- )
1341
- );
1400
+ const textElements = renderTextSegmentWithWidgets(segment.content, `seg-${index}`);
1401
+ if (Array.isArray(textElements)) {
1402
+ elements.push(...textElements);
1403
+ } else {
1404
+ elements.push(textElements);
1405
+ }
1342
1406
  } else if (segment.type === "tool") {
1343
1407
  elements.push(
1344
1408
  /* @__PURE__ */ jsx11("div", { className: "apteva-tool-call-standalone", children: /* @__PURE__ */ jsx11(
@@ -1356,7 +1420,15 @@ function Message({ message, onAction, enableWidgets, onWidgetRender }) {
1356
1420
  if (!isUser && contentSegments && contentSegments.length > 0) {
1357
1421
  return /* @__PURE__ */ jsxs8("div", { className: "apteva-message-segmented", children: [
1358
1422
  renderSegmentedContent(),
1359
- message.widgets && message.widgets.length > 0 && /* @__PURE__ */ jsx11("div", { className: "apteva-message-widgets", children: /* @__PURE__ */ jsx11(Widgets, { widgets: message.widgets, onAction, layout: "stack" }) }),
1423
+ message.widgets && message.widgets.length > 0 && /* @__PURE__ */ jsx11("div", { className: "apteva-widget-standalone", children: /* @__PURE__ */ jsx11(Widgets, { widgets: message.widgets, onAction, layout: "stack" }) }),
1424
+ /* @__PURE__ */ jsx11("div", { className: "apteva-message-timestamp apteva-message-timestamp-assistant", suppressHydrationWarning: true, children: message.timestamp.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }) })
1425
+ ] });
1426
+ }
1427
+ const widgetContent = renderContentWithWidgets();
1428
+ if (!isUser && enableWidgets && widgetContent) {
1429
+ return /* @__PURE__ */ jsxs8("div", { className: "apteva-message-segmented", children: [
1430
+ widgetContent,
1431
+ message.widgets && message.widgets.length > 0 && /* @__PURE__ */ jsx11("div", { className: "apteva-widget-standalone", children: /* @__PURE__ */ jsx11(Widgets, { widgets: message.widgets, onAction, layout: "stack" }) }),
1360
1432
  /* @__PURE__ */ jsx11("div", { className: "apteva-message-timestamp apteva-message-timestamp-assistant", suppressHydrationWarning: true, children: message.timestamp.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }) })
1361
1433
  ] });
1362
1434
  }
@@ -1369,7 +1441,7 @@ function Message({ message, onAction, enableWidgets, onWidgetRender }) {
1369
1441
  ),
1370
1442
  children: [
1371
1443
  /* @__PURE__ */ jsx11("div", { className: isUser ? "apteva-message-content-user" : "apteva-message-content-assistant", children: renderContent() }),
1372
- message.widgets && message.widgets.length > 0 && /* @__PURE__ */ jsx11("div", { className: "apteva-message-widgets", children: /* @__PURE__ */ jsx11(Widgets, { widgets: message.widgets, onAction, layout: "stack" }) }),
1444
+ message.widgets && message.widgets.length > 0 && /* @__PURE__ */ jsx11("div", { className: "apteva-widget-standalone", children: /* @__PURE__ */ jsx11(Widgets, { widgets: message.widgets, onAction, layout: "stack" }) }),
1373
1445
  /* @__PURE__ */ jsx11("div", { className: cn("apteva-message-timestamp", isUser ? "apteva-message-timestamp-user" : "apteva-message-timestamp-assistant"), suppressHydrationWarning: true, children: message.timestamp.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }) })
1374
1446
  ]
1375
1447
  }
@@ -1553,7 +1625,7 @@ function MessageList({
1553
1625
 
1554
1626
  // src/components/Chat/Composer.tsx
1555
1627
  import { useState, useRef as useRef3 } from "react";
1556
- import { Fragment as Fragment2, jsx as jsx14, jsxs as jsxs10 } from "react/jsx-runtime";
1628
+ import { Fragment, jsx as jsx14, jsxs as jsxs10 } from "react/jsx-runtime";
1557
1629
  function Composer({ onSendMessage, placeholder = "Type a message...", disabled = false, isLoading = false, onStop, onFileUpload, onSwitchMode }) {
1558
1630
  const [text, setText] = useState("");
1559
1631
  const [showMenu, setShowMenu] = useState(false);
@@ -1674,7 +1746,7 @@ function Composer({ onSendMessage, placeholder = "Type a message...", disabled =
1674
1746
  children: /* @__PURE__ */ jsx14("svg", { width: "20", height: "20", viewBox: "0 0 20 20", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsx14("path", { d: "M10 5v10M5 10h10", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) })
1675
1747
  }
1676
1748
  ),
1677
- showMenu && /* @__PURE__ */ jsxs10(Fragment2, { children: [
1749
+ showMenu && /* @__PURE__ */ jsxs10(Fragment, { children: [
1678
1750
  /* @__PURE__ */ jsx14("div", { className: "fixed inset-0 z-[9998]", onClick: () => setShowMenu(false) }),
1679
1751
  /* @__PURE__ */ jsxs10(
1680
1752
  "div",
@@ -1767,7 +1839,7 @@ function Composer({ onSendMessage, placeholder = "Type a message...", disabled =
1767
1839
 
1768
1840
  // src/components/Chat/CommandComposer.tsx
1769
1841
  import { useState as useState2, useRef as useRef4 } from "react";
1770
- import { Fragment as Fragment3, jsx as jsx15, jsxs as jsxs11 } from "react/jsx-runtime";
1842
+ import { Fragment as Fragment2, jsx as jsx15, jsxs as jsxs11 } from "react/jsx-runtime";
1771
1843
  function CommandComposer({
1772
1844
  onExecute,
1773
1845
  state,
@@ -1916,7 +1988,7 @@ function CommandComposer({
1916
1988
  children: /* @__PURE__ */ jsx15("svg", { width: "18", height: "18", viewBox: "0 0 20 20", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsx15("path", { d: "M10 5v10M5 10h10", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) })
1917
1989
  }
1918
1990
  ),
1919
- showMenu && /* @__PURE__ */ jsxs11(Fragment3, { children: [
1991
+ showMenu && /* @__PURE__ */ jsxs11(Fragment2, { children: [
1920
1992
  /* @__PURE__ */ jsx15("div", { className: "fixed inset-0 z-[9998]", onClick: () => setShowMenu(false) }),
1921
1993
  /* @__PURE__ */ jsxs11(
1922
1994
  "div",
@@ -2012,7 +2084,7 @@ function CommandComposer({
2012
2084
  state === "error" && "!text-red-600 dark:!text-red-400",
2013
2085
  state === "plan-pending" && "!text-amber-700 dark:!text-amber-300"
2014
2086
  ),
2015
- children: isToolCall ? /* @__PURE__ */ jsxs11(Fragment3, { children: [
2087
+ children: isToolCall ? /* @__PURE__ */ jsxs11(Fragment2, { children: [
2016
2088
  /* @__PURE__ */ jsx15("span", { className: "font-mono", children: displayContent }),
2017
2089
  /* @__PURE__ */ jsx15("span", { className: "text-gray-400 dark:text-gray-500", children: "Running..." })
2018
2090
  ] }) : displayContent
@@ -2035,7 +2107,7 @@ function CommandComposer({
2035
2107
  children: "Modify"
2036
2108
  }
2037
2109
  )
2038
- ] }) : /* @__PURE__ */ jsxs11(Fragment3, { children: [
2110
+ ] }) : /* @__PURE__ */ jsxs11(Fragment2, { children: [
2039
2111
  state === "loading" && onStop && /* @__PURE__ */ jsx15(
2040
2112
  "button",
2041
2113
  {
@@ -2273,7 +2345,7 @@ var AptevaClient = class {
2273
2345
  var aptevaClient = new AptevaClient();
2274
2346
 
2275
2347
  // src/components/Chat/Chat.tsx
2276
- import { Fragment as Fragment4, jsx as jsx16, jsxs as jsxs12 } from "react/jsx-runtime";
2348
+ import { Fragment as Fragment3, jsx as jsx16, jsxs as jsxs12 } from "react/jsx-runtime";
2277
2349
  var Chat = forwardRef(function Chat2({
2278
2350
  agentId,
2279
2351
  threadId,
@@ -2832,7 +2904,7 @@ ${planToExecute}`;
2832
2904
  isLoading ? chatToolName ? "apteva-chat-status-tool" : "apteva-chat-status-thinking" : "apteva-chat-status-ready"
2833
2905
  ), children: isLoading ? chatToolName ? `Using ${chatToolName}...` : "Thinking..." : "Ready" })
2834
2906
  ] }) }),
2835
- mode === "chat" && /* @__PURE__ */ jsxs12(Fragment4, { children: [
2907
+ mode === "chat" && /* @__PURE__ */ jsxs12(Fragment3, { children: [
2836
2908
  /* @__PURE__ */ jsx16(
2837
2909
  MessageList,
2838
2910
  {
@@ -2905,7 +2977,7 @@ import { jsx as jsx17, jsxs as jsxs13 } from "react/jsx-runtime";
2905
2977
 
2906
2978
  // src/components/Command/Command.tsx
2907
2979
  import React, { useState as useState5, useEffect as useEffect5 } from "react";
2908
- import { Fragment as Fragment5, jsx as jsx18, jsxs as jsxs14 } from "react/jsx-runtime";
2980
+ import { Fragment as Fragment4, jsx as jsx18, jsxs as jsxs14 } from "react/jsx-runtime";
2909
2981
  function Command({
2910
2982
  agentId,
2911
2983
  command: initialCommand,
@@ -3371,7 +3443,7 @@ ${planToExecute}`;
3371
3443
  style: { minHeight: isCompact ? "auto" : "180px" },
3372
3444
  children: [
3373
3445
  /* @__PURE__ */ jsxs14("div", { className: cn("flex-1 flex", isCompact ? "flex-row items-center p-3 gap-3" : "flex-col p-4"), children: [
3374
- state === "idle" && allowInput && !isCompact && /* @__PURE__ */ jsxs14(Fragment5, { children: [
3446
+ state === "idle" && allowInput && !isCompact && /* @__PURE__ */ jsxs14(Fragment4, { children: [
3375
3447
  /* @__PURE__ */ jsx18(
3376
3448
  "textarea",
3377
3449
  {
@@ -3411,7 +3483,7 @@ ${planToExecute}`;
3411
3483
  )
3412
3484
  ] }, index)) })
3413
3485
  ] }),
3414
- state === "idle" && allowInput && isCompact && /* @__PURE__ */ jsxs14(Fragment5, { children: [
3486
+ state === "idle" && allowInput && isCompact && /* @__PURE__ */ jsxs14(Fragment4, { children: [
3415
3487
  /* @__PURE__ */ jsxs14("div", { className: "flex items-center gap-0.5 flex-shrink-0", children: [
3416
3488
  enableFileUpload && /* @__PURE__ */ jsx18(
3417
3489
  "button",
@@ -3551,7 +3623,7 @@ ${planToExecute}`;
3551
3623
  ] })
3552
3624
  ] })
3553
3625
  ] }),
3554
- state === "loading" && isCompact && /* @__PURE__ */ jsxs14(Fragment5, { children: [
3626
+ state === "loading" && isCompact && /* @__PURE__ */ jsxs14(Fragment4, { children: [
3555
3627
  /* @__PURE__ */ jsxs14("div", { className: "flex-1 flex items-center gap-3 py-1", children: [
3556
3628
  /* @__PURE__ */ jsx18("div", { className: "w-4 h-4 border-2 border-gray-300 border-t-blue-500 rounded-full animate-spin" }),
3557
3629
  /* @__PURE__ */ jsx18("div", { className: "text-gray-600 dark:text-gray-400 text-sm truncate", children: enableStreaming && streamedContent ? streamedContent : loadingText })
@@ -3599,7 +3671,7 @@ ${planToExecute}`;
3599
3671
  )
3600
3672
  ] })
3601
3673
  ] }) }),
3602
- state === "plan-pending" && isCompact && /* @__PURE__ */ jsxs14(Fragment5, { children: [
3674
+ state === "plan-pending" && isCompact && /* @__PURE__ */ jsxs14(Fragment4, { children: [
3603
3675
  /* @__PURE__ */ jsxs14(
3604
3676
  "button",
3605
3677
  {
@@ -3673,7 +3745,7 @@ ${planToExecute}`;
3673
3745
  widget.id
3674
3746
  )) })
3675
3747
  ] }) }),
3676
- state === "success" && result && isCompact && /* @__PURE__ */ jsxs14(Fragment5, { children: [
3748
+ state === "success" && result && isCompact && /* @__PURE__ */ jsxs14(Fragment4, { children: [
3677
3749
  /* @__PURE__ */ jsxs14(
3678
3750
  "div",
3679
3751
  {
@@ -3710,7 +3782,7 @@ ${planToExecute}`;
3710
3782
  ] })
3711
3783
  ] }),
3712
3784
  !isCompact && /* @__PURE__ */ jsxs14("div", { className: "p-3 flex items-center justify-between gap-2", children: [
3713
- /* @__PURE__ */ jsx18("div", { className: "flex items-center gap-1", children: state === "idle" && allowInput && /* @__PURE__ */ jsxs14(Fragment5, { children: [
3785
+ /* @__PURE__ */ jsx18("div", { className: "flex items-center gap-1", children: state === "idle" && allowInput && /* @__PURE__ */ jsxs14(Fragment4, { children: [
3714
3786
  enableFileUpload && /* @__PURE__ */ jsx18(
3715
3787
  "button",
3716
3788
  {