@vegintech/langchain-react-agent 0.0.21 → 0.0.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.d.mts +16 -12
- package/dist/index.mjs +5 -4
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -166,25 +166,29 @@ interface ToolRenderProps<TArgs = Record<string, unknown>> {
|
|
|
166
166
|
status: ToolExecutionStatus;
|
|
167
167
|
error?: string;
|
|
168
168
|
}
|
|
169
|
-
/**
|
|
170
|
-
interface
|
|
169
|
+
/** 前端工具:需要完整的工具定义(用于前端执行) */
|
|
170
|
+
interface FrontendTool<TArgs = Record<string, unknown>> {
|
|
171
|
+
/** 工具类型 */
|
|
172
|
+
type: "frontend";
|
|
173
|
+
/** 工具名称 */
|
|
171
174
|
name: string;
|
|
175
|
+
/** 工具描述 */
|
|
172
176
|
description: string;
|
|
177
|
+
/** 参数 JSON Schema */
|
|
173
178
|
parameters: ToolParameterSchema;
|
|
179
|
+
/** 前端工具执行函数 */
|
|
180
|
+
execute: (args: TArgs) => Promise<unknown> | unknown;
|
|
174
181
|
/** 渲染函数:可选,用于在消息列表中展示工具调用过程/结果 */
|
|
175
182
|
render?: (props: ToolRenderProps<TArgs>) => ReactNode;
|
|
176
183
|
}
|
|
177
|
-
/**
|
|
178
|
-
interface
|
|
179
|
-
/**
|
|
180
|
-
type: "frontend";
|
|
181
|
-
execute: (args: TArgs) => Promise<unknown> | unknown;
|
|
182
|
-
}
|
|
183
|
-
/** 后端工具:不能有 execute */
|
|
184
|
-
interface BackendTool<TArgs = Record<string, unknown>> extends ToolBase<TArgs> {
|
|
185
|
-
/** 后端工具由 Agent 执行 */
|
|
184
|
+
/** 后端工具:仅用于展示,只需要 name 和 render */
|
|
185
|
+
interface BackendTool<TArgs = Record<string, unknown>> {
|
|
186
|
+
/** 工具类型 */
|
|
186
187
|
type: "backend";
|
|
187
|
-
|
|
188
|
+
/** 工具名称(用于匹配后端定义的工具) */
|
|
189
|
+
name: string;
|
|
190
|
+
/** 渲染函数:用于在消息列表中展示工具调用过程/结果 */
|
|
191
|
+
render: (props: ToolRenderProps<TArgs>) => ReactNode;
|
|
188
192
|
}
|
|
189
193
|
/** 工具定义联合类型 */
|
|
190
194
|
type ToolDefinition<TArgs = Record<string, unknown>> = FrontendTool<TArgs> | BackendTool<TArgs>;
|
package/dist/index.mjs
CHANGED
|
@@ -991,15 +991,16 @@ function useToolExecution({ tools, toolCalls, isLoading = false, onExecutionChan
|
|
|
991
991
|
const executedCallsRef = useRef(/* @__PURE__ */ new Set());
|
|
992
992
|
const executingCallsRef = useRef(/* @__PURE__ */ new Set());
|
|
993
993
|
const pendingNotifiedRef = useRef(/* @__PURE__ */ new Set());
|
|
994
|
-
const
|
|
994
|
+
const notifiedCompletedRef = useRef(/* @__PURE__ */ new Set());
|
|
995
995
|
const batchCallIdsRef = useRef(/* @__PURE__ */ new Set());
|
|
996
996
|
const batchResultsRef = useRef(/* @__PURE__ */ new Map());
|
|
997
997
|
const isProcessingRef = useRef(false);
|
|
998
998
|
const batchSubmittedRef = useRef(false);
|
|
999
999
|
useEffect(() => {
|
|
1000
|
-
if (
|
|
1001
|
-
initializedRef.current = true;
|
|
1000
|
+
if (!completedToolResults || completedToolResults.size === 0) return;
|
|
1002
1001
|
completedToolResults.forEach((result, callId) => {
|
|
1002
|
+
if (notifiedCompletedRef.current.has(callId)) return;
|
|
1003
|
+
notifiedCompletedRef.current.add(callId);
|
|
1003
1004
|
executedCallsRef.current.add(callId);
|
|
1004
1005
|
const call = toolCalls.find((c) => c.id === callId);
|
|
1005
1006
|
if (call) onExecutionChange?.({
|
|
@@ -1010,7 +1011,7 @@ function useToolExecution({ tools, toolCalls, isLoading = false, onExecutionChan
|
|
|
1010
1011
|
result
|
|
1011
1012
|
});
|
|
1012
1013
|
});
|
|
1013
|
-
}, [completedToolResults]);
|
|
1014
|
+
}, [completedToolResults, toolCalls]);
|
|
1014
1015
|
/**
|
|
1015
1016
|
* 检查批次是否完成并提交结果
|
|
1016
1017
|
*/
|