@vegintech/langchain-react-agent 0.0.34 → 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 +2 -0
- package/dist/index.mjs +21 -10
- package/package.json +1 -1
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,7 +565,7 @@ 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
570
|
if (executedCallsRef.current.has(callId)) {
|
|
571
571
|
notifiedCompletedRef.current.add(callId);
|
|
@@ -578,7 +578,7 @@ function useToolExecution({ tools, toolCalls, isLoading = false, onExecutionChan
|
|
|
578
578
|
callId,
|
|
579
579
|
name: call.name,
|
|
580
580
|
args: call.args,
|
|
581
|
-
status: "success",
|
|
581
|
+
status: call.status || "success",
|
|
582
582
|
result
|
|
583
583
|
});
|
|
584
584
|
});
|
|
@@ -749,10 +749,14 @@ function toChatMessage(message, toolResults) {
|
|
|
749
749
|
if (message.type === "human") msgType = "human";
|
|
750
750
|
const toolCalls = extractToolCalls(message);
|
|
751
751
|
let toolCallsWithResult = toolCalls;
|
|
752
|
-
if (toolCalls) toolCallsWithResult = toolCalls.map((tc) =>
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
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
|
+
});
|
|
756
760
|
const reasoningContent = additionalKwargs.reasoning_content;
|
|
757
761
|
return {
|
|
758
762
|
id: message.id || crypto.randomUUID(),
|
|
@@ -765,7 +769,7 @@ function toChatMessage(message, toolResults) {
|
|
|
765
769
|
};
|
|
766
770
|
}
|
|
767
771
|
/**
|
|
768
|
-
* 预处理消息列表:建立 tool_call_id -> result 映射,并过滤 ToolMessage
|
|
772
|
+
* 预处理消息列表:建立 tool_call_id -> { result, status } 映射,并过滤 ToolMessage
|
|
769
773
|
*/
|
|
770
774
|
function processMessages(rawMessages) {
|
|
771
775
|
const toolResults = /* @__PURE__ */ new Map();
|
|
@@ -773,10 +777,17 @@ function processMessages(rawMessages) {
|
|
|
773
777
|
const toolCallId = message.tool_call_id || message.additional_kwargs?.tool_call_id;
|
|
774
778
|
if (toolCallId) {
|
|
775
779
|
const textContent = extractTextFromContent(extractContent(message));
|
|
780
|
+
const status = message.status;
|
|
776
781
|
try {
|
|
777
|
-
toolResults.set(toolCallId,
|
|
782
|
+
toolResults.set(toolCallId, {
|
|
783
|
+
result: JSON.parse(textContent),
|
|
784
|
+
status
|
|
785
|
+
});
|
|
778
786
|
} catch {
|
|
779
|
-
toolResults.set(toolCallId,
|
|
787
|
+
toolResults.set(toolCallId, {
|
|
788
|
+
result: textContent,
|
|
789
|
+
status
|
|
790
|
+
});
|
|
780
791
|
}
|
|
781
792
|
}
|
|
782
793
|
}
|