@vegintech/langchain-react-agent 0.0.1 → 0.0.3

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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # @vegintech/agentkit
1
+ # @vegintech/langchain-react-agent
2
2
 
3
3
  一个用于 React 的 LangChain Agent UI 组件库,基于 Ant Design X 构建,提供开箱即用的智能对话界面。
4
4
 
@@ -14,11 +14,11 @@
14
14
  ## 安装
15
15
 
16
16
  ```bash
17
- npm install @vegintech/agentkit
17
+ npm install @vegintech/langchain-react-agent
18
18
  # 或
19
- yarn add @vegintech/agentkit
19
+ yarn add @vegintech/langchain-react-agent
20
20
  # 或
21
- pnpm add @vegintech/agentkit
21
+ pnpm add @vegintech/langchain-react-agent
22
22
  ```
23
23
 
24
24
  ### 对等依赖
@@ -32,16 +32,15 @@ npm install react react-dom @langchain/react
32
32
  ## 快速开始
33
33
 
34
34
  ```tsx
35
- import { AgentChat } from '@vegintech/agentkit';
36
- import '@vegintech/agentkit/style.css';
35
+ import { AgentChat } from "@vegintech/langchain-react-agent";
37
36
 
38
37
  function App() {
39
38
  return (
40
39
  <AgentChat
41
- apiUrl="http://localhost:8000/api"
40
+ apiUrl="http://localhost:2024"
42
41
  assistantId="my-assistant"
43
42
  onThreadIdChange={(threadId) => {
44
- console.log('New thread:', threadId);
43
+ console.log("New thread:", threadId);
45
44
  }}
46
45
  />
47
46
  );
@@ -55,39 +54,36 @@ function App() {
55
54
  核心聊天组件,封装了消息列表、输入框和工具管理功能。
56
55
 
57
56
  ```tsx
58
- import { AgentChat } from '@vegintech/agentkit';
57
+ import { AgentChat } from "@vegintech/langchain-react-agent";
59
58
 
60
59
  <AgentChat
61
60
  // 连接配置
62
61
  apiUrl="https://api.example.com"
63
62
  assistantId="your-assistant-id"
64
- threadId={threadId} // 可选:会话 ID
65
- headers={{ Authorization: 'Bearer token' }} // 可选:自定义请求头
66
- onThreadIdChange={(id) => setThreadId(id)} // 可选:会话 ID 变化回调
67
-
63
+ threadId={threadId} // 可选:会话 ID
64
+ headers={{ Authorization: "Bearer token" }} // 可选:自定义请求头
65
+ onThreadIdChange={(id) => setThreadId(id)} // 可选:会话 ID 变化回调
68
66
  // 工具配置
69
- tools={[frontendTool, backendTool]} // 可选:工具定义数组
70
-
67
+ tools={[frontendTool, backendTool]} // 可选:工具定义数组
71
68
  // 上下文
72
- contexts={[{ description: '用户信息', value: '用户ID: 123' }]} // 可选
73
-
69
+ contexts={[{ description: "用户信息", value: "用户ID: 123" }]} // 可选
74
70
  // 消息渲染配置
75
71
  messageConfig={{
76
- components: { /* 自定义 Markdown 组件 */ },
77
- allowedTags: { div: ['class'] },
72
+ components: {
73
+ /* 自定义 Markdown 组件 */
74
+ },
75
+ allowedTags: { div: ["class"] },
78
76
  }}
79
-
80
77
  // 输入框配置
81
78
  inputConfig={{
82
- placeholder: '请输入消息...',
79
+ placeholder: "请输入消息...",
83
80
  onPreSend: (params) => ({
84
- messages: [{ type: 'human', content: params.message }],
81
+ messages: [{ type: "human", content: params.message }],
85
82
  }),
86
83
  }}
87
-
88
84
  // 错误处理
89
85
  onError={(error) => console.error(error)}
90
- />
86
+ />;
91
87
  ```
92
88
 
93
89
  ## 工具定义
@@ -97,27 +93,25 @@ import { AgentChat } from '@vegintech/agentkit';
97
93
  前端工具在浏览器端执行,适用于需要访问浏览器 API 或不需要后端处理的场景。
98
94
 
99
95
  ```tsx
100
- import type { FrontendTool } from '@vegintech/agentkit';
96
+ import type { FrontendTool } from "@vegintech/langchain-react-agent";
101
97
 
102
98
  const alertTool: FrontendTool = {
103
- type: 'frontend',
104
- name: 'alert',
105
- description: '显示一个警告弹窗',
99
+ type: "frontend",
100
+ name: "alert",
101
+ description: "显示一个警告弹窗",
106
102
  parameters: {
107
- type: 'object',
103
+ type: "object",
108
104
  properties: {
109
- message: { type: 'string', description: '警告消息内容' },
105
+ message: { type: "string", description: "警告消息内容" },
110
106
  },
111
- required: ['message'],
107
+ required: ["message"],
112
108
  },
113
109
  execute: async (args) => {
114
110
  alert(args.message);
115
111
  return { success: true };
116
112
  },
117
113
  render: (props) => (
118
- <div className="tool-alert">
119
- {props.status === 'running' ? '显示弹窗中...' : '弹窗已显示'}
120
- </div>
114
+ <div className="tool-alert">{props.status === "running" ? "显示弹窗中..." : "弹窗已显示"}</div>
121
115
  ),
122
116
  };
123
117
  ```
@@ -127,24 +121,24 @@ const alertTool: FrontendTool = {
127
121
  后端工具由 LangChain Agent 在后端执行,适用于需要访问数据库、API 等后端资源的场景。
128
122
 
129
123
  ```tsx
130
- import type { BackendTool } from '@vegintech/agentkit';
124
+ import type { BackendTool } from "@vegintech/langchain-react-agent";
131
125
 
132
126
  const searchTool: BackendTool = {
133
- type: 'backend',
134
- name: 'search',
135
- description: '搜索知识库',
127
+ type: "backend",
128
+ name: "search",
129
+ description: "搜索知识库",
136
130
  parameters: {
137
- type: 'object',
131
+ type: "object",
138
132
  properties: {
139
- query: { type: 'string', description: '搜索关键词' },
133
+ query: { type: "string", description: "搜索关键词" },
140
134
  },
141
- required: ['query'],
135
+ required: ["query"],
142
136
  },
143
137
  render: (props) => (
144
138
  <div className="tool-search">
145
- {props.status === 'pending' && '等待执行...'}
146
- {props.status === 'running' && `搜索: ${props.arguments.query}`}
147
- {props.status === 'success' && `找到 ${props.result?.count || 0} 条结果`}
139
+ {props.status === "pending" && "等待执行..."}
140
+ {props.status === "running" && `搜索: ${props.arguments.query}`}
141
+ {props.status === "success" && `找到 ${props.result?.count || 0} 条结果`}
148
142
  </div>
149
143
  ),
150
144
  };
@@ -154,19 +148,19 @@ const searchTool: BackendTool = {
154
148
 
155
149
  ### AgentChat Props
156
150
 
157
- | 属性 | 类型 | 必填 | 说明 |
158
- |------|------|------|------|
159
- | apiUrl | string | 是 | LangGraph API 地址 |
160
- | assistantId | string | 是 | 助手 ID |
161
- | threadId | string | 否 | 会话 ID,不传则创建新会话 |
162
- | headers | Record<string, string \| undefined \| null> | 否 | 自定义请求头 |
163
- | onThreadIdChange | (threadId: string) => void | 否 | 会话 ID 变化回调 |
164
- | className | string | 否 | 自定义 CSS 类名 |
165
- | tools | ToolDefinition[] | 否 | 工具定义数组 |
166
- | contexts | ContextItem[] | 否 | 上下文信息数组 |
167
- | messageConfig | MessageConfig | 否 | 消息渲染配置 |
168
- | inputConfig | InputConfig | 否 | 输入框配置 |
169
- | onError | (error: Error) => void | 否 | 错误处理回调 |
151
+ | 属性 | 类型 | 必填 | 说明 |
152
+ | ---------------- | ------------------------------------------- | ---- | ------------------------- |
153
+ | apiUrl | string | 是 | LangGraph API 地址 |
154
+ | assistantId | string | 是 | 助手 ID |
155
+ | threadId | string | 否 | 会话 ID,不传则创建新会话 |
156
+ | headers | Record<string, string \| undefined \| null> | 否 | 自定义请求头 |
157
+ | onThreadIdChange | (threadId: string) => void | 否 | 会话 ID 变化回调 |
158
+ | className | string | 否 | 自定义 CSS 类名 |
159
+ | tools | ToolDefinition[] | 否 | 工具定义数组 |
160
+ | contexts | ContextItem[] | 否 | 上下文信息数组 |
161
+ | messageConfig | MessageConfig | 否 | 消息渲染配置 |
162
+ | inputConfig | InputConfig | 否 | 输入框配置 |
163
+ | onError | (error: Error) => void | 否 | 错误处理回调 |
170
164
 
171
165
  ### 类型定义
172
166
 
@@ -181,28 +175,5 @@ import type {
181
175
  ContextItem,
182
176
  MessageConfig,
183
177
  InputConfig,
184
- } from '@vegintech/agentkit';
185
- ```
186
-
187
- ## 开发
188
-
189
- ```bash
190
- # 安装依赖
191
- vp install
192
-
193
- # 开发模式
194
- vp dev
195
-
196
- # 运行测试
197
- vp test
198
-
199
- # 构建
200
- vp pack
201
-
202
- # 代码检查
203
- vp check
204
- ```
205
-
206
- ## 许可证
207
-
208
- MIT
178
+ } from "@vegintech/langchain-react-agent";
179
+ ```
package/dist/index.d.mts CHANGED
@@ -13,7 +13,7 @@ interface ContextItem {
13
13
  value: string;
14
14
  }
15
15
  /** Sender onSubmit 插槽配置类型 */
16
- type SenderSlotConfig = SenderProps['slotConfig'];
16
+ type SenderSlotConfig = SenderProps["slotConfig"];
17
17
  /** Sender onSubmit 完整参数 */
18
18
  interface SenderSubmitParams {
19
19
  message: string;
@@ -66,7 +66,7 @@ interface ToolParameterSchema {
66
66
  [key: string]: unknown;
67
67
  }
68
68
  /** 消息类型,用于区分用户和助手消息 */
69
- type MessageType = 'human' | 'ai' | 'system' | 'tool' | 'function';
69
+ type MessageType = "human" | "ai" | "system" | "tool" | "function";
70
70
  /** 扩展的消息类型,确保包含 id 和必要的字段 */
71
71
  interface ChatMessage {
72
72
  id: string;
@@ -92,7 +92,7 @@ interface ToolCallInput {
92
92
  result?: unknown;
93
93
  }
94
94
  /** 工具执行状态 */
95
- type ToolExecutionStatus = 'pending' | 'running' | 'success' | 'error';
95
+ type ToolExecutionStatus = "pending" | "running" | "success" | "error";
96
96
  /** 工具执行结果 */
97
97
  interface ToolExecutionRecord {
98
98
  callId: string;
@@ -121,13 +121,13 @@ interface ToolBase<TArgs = Record<string, unknown>> {
121
121
  /** 前端工具:必须有 execute */
122
122
  interface FrontendTool<TArgs = Record<string, unknown>> extends ToolBase<TArgs> {
123
123
  /** 前端工具必须有 execute */
124
- type: 'frontend';
124
+ type: "frontend";
125
125
  execute: (args: TArgs) => Promise<unknown> | unknown;
126
126
  }
127
127
  /** 后端工具:不能有 execute */
128
128
  interface BackendTool<TArgs = Record<string, unknown>> extends ToolBase<TArgs> {
129
129
  /** 后端工具由 Agent 执行 */
130
- type: 'backend';
130
+ type: "backend";
131
131
  execute?: never;
132
132
  }
133
133
  /** 工具定义联合类型 */
@@ -140,6 +140,8 @@ interface MessageConfig {
140
140
  allowedTags?: Record<string, string[]>;
141
141
  /** 作为字面量内容处理的标签(不解析内部 Markdown) */
142
142
  literalTagContent?: string[];
143
+ /** Loading 动画颜色,支持 CSS 颜色值 */
144
+ loadingColor?: string;
143
145
  }
144
146
  /** 输入框配置 */
145
147
  interface InputConfig extends SenderCustomizationProps {
package/dist/index.mjs CHANGED
@@ -162,7 +162,7 @@ ChatInput.displayName = "ChatInput";
162
162
  //#region src/ToolCallRenderer.tsx
163
163
  /**
164
164
  * 工具调用渲染组件
165
- *
165
+ *
166
166
  * 职责:
167
167
  * 1. 渲染单个工具调用的状态和结果
168
168
  * 2. 支持自定义 render 函数
@@ -212,12 +212,12 @@ const DefaultToolCallRenderer = ({ record }) => {
212
212
  //#region src/ToolManager.tsx
213
213
  /**
214
214
  * 工具管理器组件
215
- *
215
+ *
216
216
  * 职责:
217
217
  * 1. 管理工具执行状态
218
218
  * 2. 自动执行前端工具(避免重复执行)
219
219
  * 3. 通知外部执行状态变化
220
- *
220
+ *
221
221
  * 这是一个无 UI 组件,只负责逻辑处理
222
222
  */
223
223
  const ToolManager = ({ tools, toolCalls, isLoading = false, onExecutionChange, onToolResult, completedToolResults }) => {
@@ -383,7 +383,7 @@ const ReasoningContent = ({ content }) => {
383
383
  border: "none",
384
384
  background: "transparent",
385
385
  cursor: "pointer",
386
- color: "#1677ff"
386
+ color: "#ffffff"
387
387
  },
388
388
  children: "查看全部"
389
389
  })] });
@@ -546,7 +546,7 @@ const roleConfig = {
546
546
  }
547
547
  }
548
548
  };
549
- const MessageList = ({ messages, isLoading = false, className = "", tools, toolExecutions, components, securityConfig }) => {
549
+ const MessageList = ({ messages, isLoading = false, className = "", tools, toolExecutions, components, securityConfig, loadingColor }) => {
550
550
  const reasoningCacheRef = useRef(/* @__PURE__ */ new Map());
551
551
  const processedMessages = useMemo(() => {
552
552
  const cache = reasoningCacheRef.current;
@@ -593,7 +593,7 @@ const MessageList = ({ messages, isLoading = false, className = "", tools, toolE
593
593
  const allItems = processedMessages[processedMessages.length - 1]?.type === "human" && isLoading ? [...items, {
594
594
  key: "loading",
595
595
  role: "ai",
596
- content: /* @__PURE__ */ jsx(WaveLoading, {}),
596
+ content: /* @__PURE__ */ jsx(WaveLoading, { color: loadingColor }),
597
597
  placement: "start",
598
598
  style: { paddingBlock: 0 }
599
599
  }] : items;
@@ -800,7 +800,8 @@ const AgentChat = forwardRef(({ apiUrl, assistantId, headers, threadId: external
800
800
  securityConfig: {
801
801
  allowedTags: messageConfig?.allowedTags,
802
802
  literalTagContent: messageConfig?.literalTagContent
803
- }
803
+ },
804
+ loadingColor: messageConfig?.loadingColor
804
805
  }),
805
806
  /* @__PURE__ */ jsx(ChatInput, {
806
807
  ref: chatInputRef,
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@vegintech/langchain-react-agent",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "LangChain Agent UI component library for React",
5
5
  "license": "MIT",
6
- "sideEffects": false,
7
6
  "files": [
8
7
  "dist"
9
8
  ],
10
9
  "type": "module",
10
+ "sideEffects": false,
11
11
  "exports": {
12
12
  ".": "./dist/index.mjs",
13
13
  "./package.json": "./package.json"
@@ -22,26 +22,26 @@
22
22
  "check": "vp check",
23
23
  "prepublishOnly": "vp run build"
24
24
  },
25
- "peerDependencies": {
26
- "react": ">=18.0.0",
27
- "react-dom": ">=18.0.0"
25
+ "dependencies": {
26
+ "@ant-design/x": "^2.4.0",
27
+ "@langchain/core": "^1.1.36",
28
+ "@langchain/react": "^0.2.3",
29
+ "streamdown": "^2.5.0"
28
30
  },
29
31
  "devDependencies": {
30
32
  "@types/node": "^25.5.0",
31
- "@types/react": "^19.0.0",
32
- "@types/react-dom": "^19.0.0",
33
+ "@types/react": "^19.2.14",
34
+ "@types/react-dom": "^19.2.3",
33
35
  "@typescript/native-preview": "7.0.0-dev.20260316.1",
34
- "@vitejs/plugin-react": "catalog:",
36
+ "@vitejs/plugin-react": "^6.0.1",
35
37
  "bumpp": "^11.0.1",
36
- "react": "^19.0.0",
37
- "react-dom": "^19.0.0",
38
+ "react": "^19.2.4",
39
+ "react-dom": "^19.2.4",
38
40
  "typescript": "^5.9.3",
39
- "vite-plus": "^0.1.11"
41
+ "vite-plus": "^0.1.14"
40
42
  },
41
- "dependencies": {
42
- "@ant-design/x": "catalog:",
43
- "@langchain/core": "catalog:",
44
- "@langchain/react": "catalog:",
45
- "streamdown": "catalog:"
43
+ "peerDependencies": {
44
+ "react": ">=18.0.0",
45
+ "react-dom": ">=18.0.0"
46
46
  }
47
47
  }