@vegintech/langchain-react-agent 0.0.21 → 0.0.23

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
@@ -166,25 +166,29 @@ interface ToolRenderProps<TArgs = Record<string, unknown>> {
166
166
  status: ToolExecutionStatus;
167
167
  error?: string;
168
168
  }
169
- /** 工具基础属性 */
170
- interface ToolBase<TArgs = Record<string, unknown>> {
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
- /** 前端工具:必须有 execute */
178
- interface FrontendTool<TArgs = Record<string, unknown>> extends ToolBase<TArgs> {
179
- /** 前端工具必须有 execute */
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
- execute?: never;
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 initializedRef = useRef(false);
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 (initializedRef.current || !completedToolResults || completedToolResults.size === 0) return;
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
  */
@@ -1408,12 +1409,15 @@ const AgentChat = forwardRef(({ apiUrl, assistantId, headers, threadId, onThread
1408
1409
  return next;
1409
1410
  });
1410
1411
  }, []);
1412
+ const frontendTools = useMemo(() => {
1413
+ return tools?.filter(isFrontendTool) || [];
1414
+ }, [tools]);
1411
1415
  const submitToStream = useCallback(async (submitMessages) => {
1412
1416
  await stream.submit({
1413
1417
  ...agentState,
1414
1418
  messages: submitMessages,
1415
1419
  agentkit: {
1416
- actions: tools,
1420
+ actions: frontendTools,
1417
1421
  context: contexts
1418
1422
  }
1419
1423
  }, {
@@ -1430,7 +1434,7 @@ const AgentChat = forwardRef(({ apiUrl, assistantId, headers, threadId, onThread
1430
1434
  });
1431
1435
  }, [
1432
1436
  stream,
1433
- tools,
1437
+ frontendTools,
1434
1438
  contexts,
1435
1439
  agentState
1436
1440
  ]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vegintech/langchain-react-agent",
3
- "version": "0.0.21",
3
+ "version": "0.0.23",
4
4
  "description": "LangChain Agent UI component library for React",
5
5
  "license": "MIT",
6
6
  "files": [