@vegintech/langchain-react-agent 0.0.24 → 0.0.25
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 +25 -23
- package/dist/index.mjs +21 -21
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -2,10 +2,28 @@ 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
|
|
5
|
+
import { UseStreamOptions, useStream } from "@langchain/langgraph-sdk/react";
|
|
6
6
|
import { BaseNode, InsertPosition, NodeRender, SenderProps, SkillType, SlotConfigType } from "@ant-design/x/es/sender/interface.ts";
|
|
7
7
|
import { Message } from "@langchain/langgraph-sdk";
|
|
8
8
|
|
|
9
|
+
//#region src/hooks/useAgentStream.d.ts
|
|
10
|
+
type AgentStreamOptions = UseStreamOptions;
|
|
11
|
+
type AgentStream = ReturnType<typeof useStream>;
|
|
12
|
+
/**
|
|
13
|
+
* 包装 useStream hook,为 AgentChat 提供统一的 stream 实例创建方式
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* const stream = useAgentStream({
|
|
18
|
+
* apiUrl: "http://localhost:2026",
|
|
19
|
+
* assistantId: "demo",
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* <AgentChat stream={stream} />
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
declare function useAgentStream(options: AgentStreamOptions): AgentStream;
|
|
26
|
+
//#endregion
|
|
9
27
|
//#region src/types.d.ts
|
|
10
28
|
/** ToolCard 组件 Props */
|
|
11
29
|
interface ToolCardProps extends Omit<ThoughtChainItemProps, "children"> {
|
|
@@ -220,22 +238,19 @@ interface InputConfig extends SenderCustomizationProps {
|
|
|
220
238
|
placeholder?: string;
|
|
221
239
|
}
|
|
222
240
|
interface AgentChatProps {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
241
|
+
/**
|
|
242
|
+
* Stream 实例
|
|
243
|
+
* 由外部通过 useAgentStream hook 创建并传入
|
|
244
|
+
*/
|
|
245
|
+
stream: AgentStream;
|
|
228
246
|
className?: string;
|
|
229
247
|
tools?: ToolDefinition<any>[];
|
|
230
248
|
contexts?: ContextItem[];
|
|
231
249
|
messageConfig?: MessageConfig;
|
|
232
250
|
inputConfig?: InputConfig;
|
|
233
|
-
onError?: (error: Error) => void;
|
|
234
251
|
interruptConfig?: InterruptConfig;
|
|
235
252
|
/** Agent 状态值 */
|
|
236
253
|
agentState?: Record<string, unknown>;
|
|
237
|
-
/** Agent 状态变化回调 */
|
|
238
|
-
onAgentStateChange?: (state: Record<string, unknown>) => void;
|
|
239
254
|
/** 是否显示调试面板,默认 false。仅在开发环境生效 */
|
|
240
255
|
showDebug?: boolean;
|
|
241
256
|
/** 欢迎组件,当消息列表为空且非加载状态时显示 */
|
|
@@ -251,19 +266,6 @@ interface AgentChatRef {
|
|
|
251
266
|
clearInput: () => void;
|
|
252
267
|
/** 聚焦输入框 */
|
|
253
268
|
focusInput: () => void;
|
|
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;
|
|
267
269
|
}
|
|
268
270
|
/** Streamdown 安全过滤配置 */
|
|
269
271
|
interface StreamdownSecurityConfig {
|
|
@@ -309,4 +311,4 @@ interface MessageContentRendererProps {
|
|
|
309
311
|
/** 消息内容渲染组件 - 支持字符串和多模态内容块 */
|
|
310
312
|
declare const MessageContentRenderer: React$1.FC<MessageContentRendererProps>;
|
|
311
313
|
//#endregion
|
|
312
|
-
export { AgentChat, type AgentChatInputRef, type AgentChatProps, type AgentChatRef, type BackendTool, type ChatMessage, type ContextItem, type EmptyStateConfig, type FrontendTool, type InputConfig, type InterruptConfig, type InterruptEvent, type InterruptManagerProps, type InterruptRenderProps, type MessageConfig, type MessageContent, type MessageContentBlock, MessageContentRenderer, type MessageContentRendererProps, type MessageType, type SenderCustomizationProps, type SenderSlotConfig, type SenderSubmitParams, type ToolCallInput, ToolCard, type ToolCardProps, type ToolDefinition, type ToolExecutionRecord, type ToolExecutionStatus, type ToolParameterSchema, type ToolRenderProps };
|
|
314
|
+
export { AgentChat, type AgentChatInputRef, type AgentChatProps, type AgentChatRef, type AgentStream, type AgentStreamOptions, type BackendTool, type ChatMessage, type ContextItem, type EmptyStateConfig, type FrontendTool, type InputConfig, type InterruptConfig, type InterruptEvent, type InterruptManagerProps, type InterruptRenderProps, type MessageConfig, type MessageContent, type MessageContentBlock, MessageContentRenderer, type MessageContentRendererProps, type MessageType, type SenderCustomizationProps, type SenderSlotConfig, type SenderSubmitParams, type ToolCallInput, ToolCard, type ToolCardProps, type ToolDefinition, type ToolExecutionRecord, type ToolExecutionStatus, type ToolParameterSchema, type ToolRenderProps, useAgentStream };
|
package/dist/index.mjs
CHANGED
|
@@ -1349,33 +1349,15 @@ function injectStyles() {
|
|
|
1349
1349
|
//#endregion
|
|
1350
1350
|
//#region src/components/AgentChat.tsx
|
|
1351
1351
|
injectStyles();
|
|
1352
|
-
const AgentChat = forwardRef(({
|
|
1352
|
+
const AgentChat = forwardRef(({ stream, className = "", tools, contexts, messageConfig, inputConfig, interruptConfig, agentState, showDebug, welcome }, ref) => {
|
|
1353
1353
|
const { onPreSend, ...chatInputConfig } = inputConfig || {};
|
|
1354
1354
|
const chatInputRef = useRef(null);
|
|
1355
|
-
const stream = useStream({
|
|
1356
|
-
apiUrl,
|
|
1357
|
-
assistantId,
|
|
1358
|
-
threadId,
|
|
1359
|
-
onThreadId: (newThreadId) => {
|
|
1360
|
-
onThreadIdChange?.(newThreadId);
|
|
1361
|
-
},
|
|
1362
|
-
defaultHeaders: headers,
|
|
1363
|
-
messagesKey: "messages",
|
|
1364
|
-
onError: (error) => {
|
|
1365
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
1366
|
-
onError?.(err);
|
|
1367
|
-
}
|
|
1368
|
-
});
|
|
1369
1355
|
useImperativeHandle(ref, () => ({
|
|
1370
1356
|
input: chatInputRef.current,
|
|
1371
1357
|
setSkill: (skill) => chatInputRef.current?.setSkill?.(skill),
|
|
1372
1358
|
clearInput: () => chatInputRef.current?.clear?.(),
|
|
1373
|
-
focusInput: () => chatInputRef.current?.focus?.()
|
|
1374
|
-
stream
|
|
1359
|
+
focusInput: () => chatInputRef.current?.focus?.()
|
|
1375
1360
|
}));
|
|
1376
|
-
useEffect(() => {
|
|
1377
|
-
if (stream.values && onAgentStateChange) onAgentStateChange(stream.values);
|
|
1378
|
-
}, [stream.values, onAgentStateChange]);
|
|
1379
1361
|
const { renderInterrupt: interruptRender } = useInterrupt({
|
|
1380
1362
|
interrupt: stream.interrupt,
|
|
1381
1363
|
config: interruptConfig,
|
|
@@ -1520,4 +1502,22 @@ const ToolCard = ({ children, style, ...rest }) => {
|
|
|
1520
1502
|
}), children] });
|
|
1521
1503
|
};
|
|
1522
1504
|
//#endregion
|
|
1523
|
-
|
|
1505
|
+
//#region src/hooks/useAgentStream.ts
|
|
1506
|
+
/**
|
|
1507
|
+
* 包装 useStream hook,为 AgentChat 提供统一的 stream 实例创建方式
|
|
1508
|
+
*
|
|
1509
|
+
* @example
|
|
1510
|
+
* ```tsx
|
|
1511
|
+
* const stream = useAgentStream({
|
|
1512
|
+
* apiUrl: "http://localhost:2026",
|
|
1513
|
+
* assistantId: "demo",
|
|
1514
|
+
* });
|
|
1515
|
+
*
|
|
1516
|
+
* <AgentChat stream={stream} />
|
|
1517
|
+
* ```
|
|
1518
|
+
*/
|
|
1519
|
+
function useAgentStream(options) {
|
|
1520
|
+
return useStream(options);
|
|
1521
|
+
}
|
|
1522
|
+
//#endregion
|
|
1523
|
+
export { AgentChat, MessageContentRenderer, ToolCard, useAgentStream };
|