@vegintech/langchain-react-agent 0.0.20 → 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 +31 -14
- package/dist/index.mjs +7 -6
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -2,8 +2,9 @@ import * as react from "react";
|
|
|
2
2
|
import React$1, { ReactNode } from "react";
|
|
3
3
|
import { ThoughtChainItemProps } from "@ant-design/x";
|
|
4
4
|
import { Components } from "streamdown";
|
|
5
|
+
import * as _langchain_langgraph_sdk_react0 from "@langchain/langgraph-sdk/react";
|
|
5
6
|
import { BaseNode, InsertPosition, NodeRender, SenderProps, SkillType, SlotConfigType } from "@ant-design/x/es/sender/interface.ts";
|
|
6
|
-
import { Message
|
|
7
|
+
import { Message } from "@langchain/langgraph-sdk";
|
|
7
8
|
|
|
8
9
|
//#region src/types.d.ts
|
|
9
10
|
/** ToolCard 组件 Props */
|
|
@@ -165,25 +166,29 @@ interface ToolRenderProps<TArgs = Record<string, unknown>> {
|
|
|
165
166
|
status: ToolExecutionStatus;
|
|
166
167
|
error?: string;
|
|
167
168
|
}
|
|
168
|
-
/**
|
|
169
|
-
interface
|
|
169
|
+
/** 前端工具:需要完整的工具定义(用于前端执行) */
|
|
170
|
+
interface FrontendTool<TArgs = Record<string, unknown>> {
|
|
171
|
+
/** 工具类型 */
|
|
172
|
+
type: "frontend";
|
|
173
|
+
/** 工具名称 */
|
|
170
174
|
name: string;
|
|
175
|
+
/** 工具描述 */
|
|
171
176
|
description: string;
|
|
177
|
+
/** 参数 JSON Schema */
|
|
172
178
|
parameters: ToolParameterSchema;
|
|
179
|
+
/** 前端工具执行函数 */
|
|
180
|
+
execute: (args: TArgs) => Promise<unknown> | unknown;
|
|
173
181
|
/** 渲染函数:可选,用于在消息列表中展示工具调用过程/结果 */
|
|
174
182
|
render?: (props: ToolRenderProps<TArgs>) => ReactNode;
|
|
175
183
|
}
|
|
176
|
-
/**
|
|
177
|
-
interface
|
|
178
|
-
/**
|
|
179
|
-
type: "frontend";
|
|
180
|
-
execute: (args: TArgs) => Promise<unknown> | unknown;
|
|
181
|
-
}
|
|
182
|
-
/** 后端工具:不能有 execute */
|
|
183
|
-
interface BackendTool<TArgs = Record<string, unknown>> extends ToolBase<TArgs> {
|
|
184
|
-
/** 后端工具由 Agent 执行 */
|
|
184
|
+
/** 后端工具:仅用于展示,只需要 name 和 render */
|
|
185
|
+
interface BackendTool<TArgs = Record<string, unknown>> {
|
|
186
|
+
/** 工具类型 */
|
|
185
187
|
type: "backend";
|
|
186
|
-
|
|
188
|
+
/** 工具名称(用于匹配后端定义的工具) */
|
|
189
|
+
name: string;
|
|
190
|
+
/** 渲染函数:用于在消息列表中展示工具调用过程/结果 */
|
|
191
|
+
render: (props: ToolRenderProps<TArgs>) => ReactNode;
|
|
187
192
|
}
|
|
188
193
|
/** 工具定义联合类型 */
|
|
189
194
|
type ToolDefinition<TArgs = Record<string, unknown>> = FrontendTool<TArgs> | BackendTool<TArgs>;
|
|
@@ -246,7 +251,19 @@ interface AgentChatRef {
|
|
|
246
251
|
clearInput: () => void;
|
|
247
252
|
/** 聚焦输入框 */
|
|
248
253
|
focusInput: () => void;
|
|
249
|
-
|
|
254
|
+
/**
|
|
255
|
+
* LangGraph Stream 实例
|
|
256
|
+
* 提供对底层流式连接的完整访问,包括:
|
|
257
|
+
* - messages: 当前消息列表
|
|
258
|
+
* - values: Agent 状态值
|
|
259
|
+
* - isLoading: 是否正在加载
|
|
260
|
+
* - submit: 提交消息
|
|
261
|
+
* - stop: 停止流
|
|
262
|
+
* - interrupt: 中断事件
|
|
263
|
+
* - client: LangGraph 客户端(可通过 client.threads.create() 创建新线程)
|
|
264
|
+
* 等完整功能
|
|
265
|
+
*/
|
|
266
|
+
stream: ReturnType<typeof _langchain_langgraph_sdk_react0.useStream> | null;
|
|
250
267
|
}
|
|
251
268
|
/** Streamdown 安全过滤配置 */
|
|
252
269
|
interface StreamdownSecurityConfig {
|
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
|
*/
|
|
@@ -1377,9 +1378,9 @@ const AgentChat = forwardRef(({ apiUrl, assistantId, headers, threadId, onThread
|
|
|
1377
1378
|
useImperativeHandle(ref, () => ({
|
|
1378
1379
|
input: chatInputRef.current,
|
|
1379
1380
|
setSkill: (skill) => chatInputRef.current?.setSkill?.(skill),
|
|
1380
|
-
createThread: () => stream.client.threads.create(),
|
|
1381
1381
|
clearInput: () => chatInputRef.current?.clear?.(),
|
|
1382
|
-
focusInput: () => chatInputRef.current?.focus?.()
|
|
1382
|
+
focusInput: () => chatInputRef.current?.focus?.(),
|
|
1383
|
+
stream
|
|
1383
1384
|
}));
|
|
1384
1385
|
useEffect(() => {
|
|
1385
1386
|
if (stream.values && onAgentStateChange) onAgentStateChange(stream.values);
|