@apteva/apteva-kit 0.1.70 → 0.1.72

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
@@ -1518,14 +1518,39 @@ function MarkdownContent({ content, className = "" }) {
1518
1518
 
1519
1519
  // src/components/Chat/ToolCall.tsx
1520
1520
 
1521
- function ToolCall({ name, status }) {
1521
+ function ToolCall({ name, status, isReceiving = false, inputLength = 0 }) {
1522
+ if (status === "preparing") {
1523
+ return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: `apteva-tool-card apteva-tool-card-preparing ${isReceiving ? "apteva-tool-receiving" : ""}`, children: [
1524
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "svg", { className: "apteva-tool-icon apteva-tool-icon-spin", fill: "none", viewBox: "0 0 24 24", children: [
1525
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "circle", { className: "apteva-tool-spinner-track", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }),
1526
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { className: "apteva-tool-spinner-fill", fill: "currentColor", d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z" })
1527
+ ] }),
1528
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { className: "apteva-tool-label", children: [
1529
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "strong", { children: name }),
1530
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "apteva-tool-status-text", children: " preparing" }),
1531
+ inputLength > 0 && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { className: "apteva-tool-char-count", children: [
1532
+ " (",
1533
+ inputLength,
1534
+ " chars)"
1535
+ ] })
1536
+ ] })
1537
+ ] });
1538
+ }
1522
1539
  if (status === "running") {
1523
1540
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "apteva-tool-card apteva-tool-card-running", children: [
1524
1541
  /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "svg", { className: "apteva-tool-icon apteva-tool-icon-spin", fill: "none", viewBox: "0 0 24 24", children: [
1525
1542
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "circle", { className: "apteva-tool-spinner-track", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }),
1526
1543
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { className: "apteva-tool-spinner-fill", fill: "currentColor", d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z" })
1527
1544
  ] }),
1528
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "apteva-tool-label", children: name })
1545
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { className: "apteva-tool-label", children: [
1546
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "strong", { children: name }),
1547
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "apteva-tool-status-text", children: " running" }),
1548
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { className: "apteva-tool-dots", children: [
1549
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: "." }),
1550
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: "." }),
1551
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: "." })
1552
+ ] })
1553
+ ] })
1529
1554
  ] });
1530
1555
  }
1531
1556
  if (status === "completed") {
@@ -1739,7 +1764,9 @@ function Message({ message, onAction, enableWidgets, onWidgetRender }) {
1739
1764
  ToolCall,
1740
1765
  {
1741
1766
  name: segment.name,
1742
- status: segment.result !== void 0 ? "completed" : "running"
1767
+ status: segment.status || (segment.result !== void 0 ? "completed" : "running"),
1768
+ isReceiving: segment.isReceiving,
1769
+ inputLength: segment.inputLength
1743
1770
  }
1744
1771
  ) }, segment.id)
1745
1772
  );
@@ -2845,6 +2872,7 @@ ${widgetContext}` : widgetContext;
2845
2872
  let accumulatedWidgets = [];
2846
2873
  let responseThreadId = currentThreadId;
2847
2874
  let toolInputBuffer = "";
2875
+ let receivingTimeout = null;
2848
2876
  const streamingMessageId = `msg-${Date.now()}`;
2849
2877
  const updateMessage = () => {
2850
2878
  const segments = [...contentSegments];
@@ -2921,7 +2949,7 @@ ${widgetContext}` : widgetContext;
2921
2949
  contentSegments.push({ type: "text", content: currentTextBuffer });
2922
2950
  currentTextBuffer = "";
2923
2951
  }
2924
- contentSegments.push({ type: "tool", id: chunk.tool_id, name: displayName });
2952
+ contentSegments.push({ type: "tool", id: chunk.tool_id, name: displayName, status: "preparing" });
2925
2953
  toolInputBuffer = "";
2926
2954
  setChatToolName(displayName);
2927
2955
  _optionalChain([onToolCall, 'optionalCall', _72 => _72(chunk.tool_name, chunk.tool_id)]);
@@ -2931,6 +2959,29 @@ ${widgetContext}` : widgetContext;
2931
2959
  case "tool_input_delta":
2932
2960
  if (chunk.tool_id && chunk.content) {
2933
2961
  toolInputBuffer += chunk.content;
2962
+ const toolSegment = contentSegments.find((s) => s.type === "tool" && s.id === chunk.tool_id);
2963
+ if (toolSegment) {
2964
+ toolSegment.isReceiving = true;
2965
+ toolSegment.inputLength = toolInputBuffer.length;
2966
+ updateMessage();
2967
+ if (receivingTimeout) clearTimeout(receivingTimeout);
2968
+ receivingTimeout = setTimeout(() => {
2969
+ if (toolSegment.status === "preparing") {
2970
+ toolSegment.isReceiving = false;
2971
+ updateMessage();
2972
+ }
2973
+ }, 150);
2974
+ }
2975
+ }
2976
+ break;
2977
+ case "tool_use":
2978
+ if (chunk.tool_id) {
2979
+ const toolSegment = contentSegments.find((s) => s.type === "tool" && s.id === chunk.tool_id);
2980
+ if (toolSegment && toolSegment.status === "preparing") {
2981
+ toolSegment.status = "running";
2982
+ toolSegment.isReceiving = false;
2983
+ updateMessage();
2984
+ }
2934
2985
  }
2935
2986
  break;
2936
2987
  case "tool_result":
@@ -2938,6 +2989,8 @@ ${widgetContext}` : widgetContext;
2938
2989
  const toolSegment = contentSegments.find((s) => s.type === "tool" && s.id === chunk.tool_id);
2939
2990
  if (toolSegment) {
2940
2991
  toolSegment.result = chunk.content;
2992
+ toolSegment.status = "completed";
2993
+ toolSegment.isReceiving = false;
2941
2994
  _optionalChain([onToolResult, 'optionalCall', _73 => _73(toolSegment.name, chunk.content)]);
2942
2995
  }
2943
2996
  setChatToolName(null);