@vegintech/langchain-react-agent 0.0.33 → 0.0.35

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.d.mts CHANGED
@@ -150,6 +150,8 @@ interface ToolCallInput {
150
150
  args: Record<string, unknown>;
151
151
  /** 后端工具执行结果(来自 ToolMessage) */
152
152
  result?: unknown;
153
+ /** 后端工具执行状态(来自 ToolMessage.status) */
154
+ status?: "success" | "error";
153
155
  }
154
156
  /** 工具执行状态 */
155
157
  type ToolExecutionStatus = "pending" | "running" | "success" | "error";
package/dist/index.mjs CHANGED
@@ -356,7 +356,7 @@ const renderToolCalls = (toolCalls, tools, toolExecutions, isLoading) => {
356
356
  callId: call.id,
357
357
  name: call.name,
358
358
  args: call.args,
359
- status: call.result !== void 0 ? "success" : "pending",
359
+ status: call.status || (call.result !== void 0 ? "success" : "pending"),
360
360
  result: call.result
361
361
  };
362
362
  return /* @__PURE__ */ jsx(ToolCallRenderer, {
@@ -565,8 +565,12 @@ function useToolExecution({ tools, toolCalls, isLoading = false, onExecutionChan
565
565
  const batchSubmittedRef = useRef(false);
566
566
  useEffect(() => {
567
567
  if (!completedToolResults || completedToolResults.size === 0) return;
568
- completedToolResults.forEach((result, callId) => {
568
+ completedToolResults.forEach(({ result, status }, callId) => {
569
569
  if (notifiedCompletedRef.current.has(callId)) return;
570
+ if (executedCallsRef.current.has(callId)) {
571
+ notifiedCompletedRef.current.add(callId);
572
+ return;
573
+ }
570
574
  notifiedCompletedRef.current.add(callId);
571
575
  executedCallsRef.current.add(callId);
572
576
  const call = toolCalls.find((c) => c.id === callId);
@@ -574,7 +578,7 @@ function useToolExecution({ tools, toolCalls, isLoading = false, onExecutionChan
574
578
  callId,
575
579
  name: call.name,
576
580
  args: call.args,
577
- status: "success",
581
+ status: call.status || "success",
578
582
  result
579
583
  });
580
584
  });
@@ -745,10 +749,14 @@ function toChatMessage(message, toolResults) {
745
749
  if (message.type === "human") msgType = "human";
746
750
  const toolCalls = extractToolCalls(message);
747
751
  let toolCallsWithResult = toolCalls;
748
- if (toolCalls) toolCallsWithResult = toolCalls.map((tc) => ({
749
- ...tc,
750
- result: toolResults.get(tc.id)
751
- }));
752
+ if (toolCalls) toolCallsWithResult = toolCalls.map((tc) => {
753
+ const toolResult = toolResults.get(tc.id);
754
+ return {
755
+ ...tc,
756
+ result: toolResult?.result,
757
+ status: toolResult?.status
758
+ };
759
+ });
752
760
  const reasoningContent = additionalKwargs.reasoning_content;
753
761
  return {
754
762
  id: message.id || crypto.randomUUID(),
@@ -761,7 +769,7 @@ function toChatMessage(message, toolResults) {
761
769
  };
762
770
  }
763
771
  /**
764
- * 预处理消息列表:建立 tool_call_id -> result 映射,并过滤 ToolMessage
772
+ * 预处理消息列表:建立 tool_call_id -> { result, status } 映射,并过滤 ToolMessage
765
773
  */
766
774
  function processMessages(rawMessages) {
767
775
  const toolResults = /* @__PURE__ */ new Map();
@@ -769,10 +777,17 @@ function processMessages(rawMessages) {
769
777
  const toolCallId = message.tool_call_id || message.additional_kwargs?.tool_call_id;
770
778
  if (toolCallId) {
771
779
  const textContent = extractTextFromContent(extractContent(message));
780
+ const status = message.status;
772
781
  try {
773
- toolResults.set(toolCallId, JSON.parse(textContent));
782
+ toolResults.set(toolCallId, {
783
+ result: JSON.parse(textContent),
784
+ status
785
+ });
774
786
  } catch {
775
- toolResults.set(toolCallId, textContent);
787
+ toolResults.set(toolCallId, {
788
+ result: textContent,
789
+ status
790
+ });
776
791
  }
777
792
  }
778
793
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vegintech/langchain-react-agent",
3
- "version": "0.0.33",
3
+ "version": "0.0.35",
4
4
  "description": "LangChain Agent UI component library for React",
5
5
  "license": "MIT",
6
6
  "files": [