@vegintech/langchain-react-agent 0.0.2 → 0.0.4
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 +11 -35
- package/dist/index.d.mts +22 -24
- package/dist/index.mjs +41 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @vegintech/
|
|
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/
|
|
17
|
+
npm install @vegintech/langchain-react-agent
|
|
18
18
|
# 或
|
|
19
|
-
yarn add @vegintech/
|
|
19
|
+
yarn add @vegintech/langchain-react-agent
|
|
20
20
|
# 或
|
|
21
|
-
pnpm add @vegintech/
|
|
21
|
+
pnpm add @vegintech/langchain-react-agent
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
### 对等依赖
|
|
@@ -32,13 +32,12 @@ npm install react react-dom @langchain/react
|
|
|
32
32
|
## 快速开始
|
|
33
33
|
|
|
34
34
|
```tsx
|
|
35
|
-
import { AgentChat } from "@vegintech/
|
|
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:
|
|
40
|
+
apiUrl="http://localhost:2024"
|
|
42
41
|
assistantId="my-assistant"
|
|
43
42
|
onThreadIdChange={(threadId) => {
|
|
44
43
|
console.log("New thread:", threadId);
|
|
@@ -55,7 +54,7 @@ function App() {
|
|
|
55
54
|
核心聊天组件,封装了消息列表、输入框和工具管理功能。
|
|
56
55
|
|
|
57
56
|
```tsx
|
|
58
|
-
import { AgentChat } from "@vegintech/
|
|
57
|
+
import { AgentChat } from "@vegintech/langchain-react-agent";
|
|
59
58
|
|
|
60
59
|
<AgentChat
|
|
61
60
|
// 连接配置
|
|
@@ -94,7 +93,7 @@ import { AgentChat } from "@vegintech/agentkit";
|
|
|
94
93
|
前端工具在浏览器端执行,适用于需要访问浏览器 API 或不需要后端处理的场景。
|
|
95
94
|
|
|
96
95
|
```tsx
|
|
97
|
-
import type { FrontendTool } from "@vegintech/
|
|
96
|
+
import type { FrontendTool } from "@vegintech/langchain-react-agent";
|
|
98
97
|
|
|
99
98
|
const alertTool: FrontendTool = {
|
|
100
99
|
type: "frontend",
|
|
@@ -122,7 +121,7 @@ const alertTool: FrontendTool = {
|
|
|
122
121
|
后端工具由 LangChain Agent 在后端执行,适用于需要访问数据库、API 等后端资源的场景。
|
|
123
122
|
|
|
124
123
|
```tsx
|
|
125
|
-
import type { BackendTool } from "@vegintech/
|
|
124
|
+
import type { BackendTool } from "@vegintech/langchain-react-agent";
|
|
126
125
|
|
|
127
126
|
const searchTool: BackendTool = {
|
|
128
127
|
type: "backend",
|
|
@@ -176,28 +175,5 @@ import type {
|
|
|
176
175
|
ContextItem,
|
|
177
176
|
MessageConfig,
|
|
178
177
|
InputConfig,
|
|
179
|
-
} from "@vegintech/
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
## 开发
|
|
183
|
-
|
|
184
|
-
```bash
|
|
185
|
-
# 安装依赖
|
|
186
|
-
vp install
|
|
187
|
-
|
|
188
|
-
# 开发模式
|
|
189
|
-
vp dev
|
|
190
|
-
|
|
191
|
-
# 运行测试
|
|
192
|
-
vp test
|
|
193
|
-
|
|
194
|
-
# 构建
|
|
195
|
-
vp pack
|
|
196
|
-
|
|
197
|
-
# 代码检查
|
|
198
|
-
vp check
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
## 许可证
|
|
202
|
-
|
|
203
|
-
MIT
|
|
178
|
+
} from "@vegintech/langchain-react-agent";
|
|
179
|
+
```
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import * as react from "react";
|
|
2
|
-
import { ReactNode } from "react";
|
|
2
|
+
import React, { ReactNode } from "react";
|
|
3
3
|
import { Components } from "streamdown";
|
|
4
4
|
import { BaseNode, InsertPosition, NodeRender, SenderProps, SkillType, SlotConfigType } from "@ant-design/x/es/sender/interface.ts";
|
|
5
|
-
import { BaseMessage } from "@langchain/core/messages";
|
|
6
5
|
|
|
7
6
|
//#region src/types.d.ts
|
|
8
7
|
/** Context Item,用于传递上下文信息 */
|
|
@@ -140,6 +139,8 @@ interface MessageConfig {
|
|
|
140
139
|
allowedTags?: Record<string, string[]>;
|
|
141
140
|
/** 作为字面量内容处理的标签(不解析内部 Markdown) */
|
|
142
141
|
literalTagContent?: string[];
|
|
142
|
+
/** Loading 动画颜色,支持 CSS 颜色值 */
|
|
143
|
+
loadingColor?: string;
|
|
143
144
|
}
|
|
144
145
|
/** 输入框配置 */
|
|
145
146
|
interface InputConfig extends SenderCustomizationProps {
|
|
@@ -176,28 +177,25 @@ interface AgentChatRef {
|
|
|
176
177
|
//#region src/AgentChat.d.ts
|
|
177
178
|
declare const AgentChat: react.ForwardRefExoticComponent<AgentChatProps & react.RefAttributes<AgentChatRef>>;
|
|
178
179
|
//#endregion
|
|
179
|
-
//#region src/
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
180
|
+
//#region src/ToolCard.d.ts
|
|
181
|
+
interface ToolCardProps {
|
|
182
|
+
/**
|
|
183
|
+
* 前缀文本(中文,使用小字体)
|
|
184
|
+
*/
|
|
185
|
+
prefix: string;
|
|
186
|
+
/**
|
|
187
|
+
* 正文内容(英文/文件名,保持默认大小)
|
|
188
|
+
*/
|
|
189
|
+
content?: string;
|
|
190
|
+
/**
|
|
191
|
+
* 左侧图标
|
|
192
|
+
*/
|
|
193
|
+
icon: React.ReactNode;
|
|
194
|
+
}
|
|
192
195
|
/**
|
|
193
|
-
*
|
|
196
|
+
* ToolCard 组件 - 用于展示工具调用结果
|
|
197
|
+
* 样式:圆角矩形框,左侧 icon,label 分两行显示(prefix 小字体,content 默认字体)
|
|
194
198
|
*/
|
|
195
|
-
declare
|
|
196
|
-
messages: ChatMessage[];
|
|
197
|
-
toolResults: Map<string, unknown>;
|
|
198
|
-
};
|
|
199
|
-
//#endregion
|
|
200
|
-
//#region src/injectStyles.d.ts
|
|
201
|
-
declare function injectStyles(): void;
|
|
199
|
+
declare const ToolCard: React.FC<ToolCardProps>;
|
|
202
200
|
//#endregion
|
|
203
|
-
export { AgentChat, type AgentChatInputRef, type AgentChatProps, type AgentChatRef, type BackendTool, type ChatMessage, type ContextItem, type FrontendTool, type InputConfig, type MessageConfig, type MessageType, type SenderCustomizationProps, type SenderSlotConfig, type SenderSubmitParams, type ToolCallInput, type ToolDefinition, type ToolExecutionRecord, type ToolExecutionStatus, type ToolParameterSchema, type ToolRenderProps
|
|
201
|
+
export { AgentChat, type AgentChatInputRef, type AgentChatProps, type AgentChatRef, type BackendTool, type ChatMessage, type ContextItem, type FrontendTool, type InputConfig, type MessageConfig, type MessageType, type SenderCustomizationProps, type SenderSlotConfig, type SenderSubmitParams, type ToolCallInput, ToolCard, type ToolCardProps, type ToolDefinition, type ToolExecutionRecord, type ToolExecutionStatus, type ToolParameterSchema, type ToolRenderProps };
|
package/dist/index.mjs
CHANGED
|
@@ -383,7 +383,7 @@ const ReasoningContent = ({ content }) => {
|
|
|
383
383
|
border: "none",
|
|
384
384
|
background: "transparent",
|
|
385
385
|
cursor: "pointer",
|
|
386
|
-
color: "#
|
|
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,
|
|
@@ -820,4 +821,39 @@ const AgentChat = forwardRef(({ apiUrl, assistantId, headers, threadId: external
|
|
|
820
821
|
});
|
|
821
822
|
AgentChat.displayName = "AgentChat";
|
|
822
823
|
//#endregion
|
|
823
|
-
|
|
824
|
+
//#region src/ToolCard.tsx
|
|
825
|
+
/**
|
|
826
|
+
* ToolCard 组件 - 用于展示工具调用结果
|
|
827
|
+
* 样式:圆角矩形框,左侧 icon,label 分两行显示(prefix 小字体,content 默认字体)
|
|
828
|
+
*/
|
|
829
|
+
const ToolCard = ({ prefix, content, icon }) => {
|
|
830
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
831
|
+
style: {
|
|
832
|
+
display: "inline-flex",
|
|
833
|
+
alignItems: "center",
|
|
834
|
+
gap: 8,
|
|
835
|
+
borderRadius: 8,
|
|
836
|
+
fontSize: 13
|
|
837
|
+
},
|
|
838
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
839
|
+
style: {
|
|
840
|
+
display: "flex",
|
|
841
|
+
alignItems: "center"
|
|
842
|
+
},
|
|
843
|
+
children: icon
|
|
844
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
845
|
+
style: {
|
|
846
|
+
display: "flex",
|
|
847
|
+
alignItems: "center",
|
|
848
|
+
gap: 4,
|
|
849
|
+
color: "rgba(0, 0, 0, 0.45)"
|
|
850
|
+
},
|
|
851
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
852
|
+
style: { fontSize: 12 },
|
|
853
|
+
children: prefix
|
|
854
|
+
}), /* @__PURE__ */ jsx("span", { children: content })]
|
|
855
|
+
})]
|
|
856
|
+
});
|
|
857
|
+
};
|
|
858
|
+
//#endregion
|
|
859
|
+
export { AgentChat, ToolCard };
|