@zero-library/chat-agent 2.3.16 → 2.4.1

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 +1,55 @@
1
- ## lolr 会话
1
+ # @zero-library/chat-agent
2
+
3
+ AI 会话 UI 组件库。提供页面级聊天组件 `ChatCopilot`,并内置会话/消息编排、HTTP 服务封装、WebSocket 收消息、文件预览等能力。
4
+
5
+ 该文档只维护稳定信息(安装、入口、能力、开发方式)。所有具体类型/方法以源码与类型注释为准,避免文档与实现重复维护。
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ pnpm add @zero-library/chat-agent
11
+ ```
12
+
13
+ 样式(建议在应用入口引入一次):
14
+
15
+ ```ts
16
+ import '@zero-library/chat-agent/style'
17
+ ```
18
+
19
+ ## 快速开始
20
+
21
+ ```tsx
22
+ import { ChatCopilot } from '@zero-library/chat-agent'
23
+ import '@zero-library/chat-agent/style'
24
+
25
+ export default function App() {
26
+ return <ChatCopilot config={{ receiverType: 3, receiverId: 'agent-001' }} services={{ http: { config: { baseURL: '/api' } } }} />
27
+ }
28
+ ```
29
+
30
+ ## 能力与边界
31
+
32
+ - 组件:`ChatCopilot`(主聊天 UI),以及少量通用子组件(发言框/附件/消息渲染)
33
+ - 状态:Valtio store 统一管理会话、消息、预览等
34
+ - HTTP:内置服务层,默认基于 `@zero-library/common` 的请求封装
35
+ - WebSocket:支持配置主/备地址,提升可用性
36
+ - 预览:支持 URL 文件预览与 Markdown 文本预览
37
+
38
+ ## 入口与结构
39
+
40
+ - 对外导出入口:`src/index.ts`
41
+ - UI:`src/ui`
42
+ - 状态与业务编排:`src/stores`
43
+ - 服务与类型:`src/services`
44
+
45
+ ## 开发
46
+
47
+ ```bash
48
+ pnpm --filter=chat-agent run dev
49
+ pnpm --filter=chat-agent run build
50
+ ```
51
+
52
+ ## 维护约定
53
+
54
+ - README 仅描述稳定能力与使用约定,不罗列具体方法列表
55
+ - API/类型说明以源码的类型与注释为准(例如 `src/ui/layouts/types.ts`、`src/stores/types.ts`、`src/services/*.ts`)
package/dist/index.cjs.js CHANGED
@@ -142,13 +142,9 @@ var init_IndexQuote = __esm({
142
142
  IndexQuote_default = ({ data, loading, message: message2 }) => {
143
143
  const [open, setOpen] = react.useState(false);
144
144
  const citation = react.useMemo(() => {
145
- let citations = [];
146
- try {
147
- citations = JSON.parse(message2.citations);
148
- } catch (e) {
149
- }
145
+ const citations = message2.msgExtra?.citations ?? [];
150
146
  return citations?.find((item) => String(item.citationId) === String(data.citationId));
151
- }, [data.citationId, message2.citations]);
147
+ }, [data.citationId, message2.msgExtra?.citations]);
152
148
  const onClick = () => {
153
149
  if (!citation?.citationUrl) return;
154
150
  if (common.isExternal(citation.citationUrl)) {
@@ -428,7 +424,7 @@ var createChatService = (request) => {
428
424
  return request.delete("/lolr/label/item", { id });
429
425
  };
430
426
  const labelsQuery = (params) => {
431
- return request.get("/lolr/label", params);
427
+ return request.post("/lolr/label", params);
432
428
  };
433
429
  const labelItemsQuery = (params) => {
434
430
  return request.get("/lolr/label/item", params);
@@ -593,7 +589,7 @@ function createChatStore() {
593
589
  if (file?.fileUrl) {
594
590
  window.open(file.fileUrl, "_blank");
595
591
  } else if (file?.content) {
596
- console.log("\u5F53\u524D\u73AF\u5883\u4E0D\u652F\u6301\u9884\u89C8");
592
+ antd.message.warning("\u5F53\u524D\u73AF\u5883\u4E0D\u652F\u6301\u9884\u89C8");
597
593
  }
598
594
  }
599
595
  config.hooks?.onAfterFilePreview?.(file, preview);
@@ -866,16 +862,17 @@ function createChatStore() {
866
862
  conversation.messages[conversationId].questionList = [];
867
863
  }
868
864
  };
869
- const getQuestionList = async (conversationId, messageId) => {
865
+ const getQuestionList = async (message2) => {
866
+ if (message2?.msgExtra?.sug === 0) return;
870
867
  if (receiver.active.feature?.prompts === false) return;
871
- const messages = conversation.messages[conversationId]?.message;
868
+ const messages = conversation.messages[message2.conversationId]?.message;
872
869
  if (!messages?.length) return;
873
870
  let lastMessage = messages[messages.length - 1];
874
- if (!lastMessage || lastMessage.sender.type !== 3 || lastMessage.id !== messageId) return;
875
- const { data } = await config.services.request.messageSuggestedQuery(messageId);
871
+ if (!lastMessage || lastMessage.sender.type !== 3 || lastMessage.id !== message2.id) return;
872
+ const { data } = await config.services.request.messageSuggestedQuery(message2.id);
876
873
  lastMessage = messages[messages.length - 1];
877
- if (lastMessage.id !== messageId) return;
878
- conversation.messages[conversationId].questionList = data;
874
+ if (lastMessage.id !== message2.id) return;
875
+ conversation.messages[message2.conversationId].questionList = data;
879
876
  };
880
877
  const getRecommendQuestions = async (conversationId) => {
881
878
  if (conversationId === conversation.active.id && conversation.active.member.agent?.memberId && !conversation.messages[conversationId].message.length) {
@@ -1124,16 +1121,19 @@ function createChatStore() {
1124
1121
  type: void 0
1125
1122
  };
1126
1123
  conversation.messages[msg.conversationId].loading = false;
1127
- getQuestionList(msg.conversationId, msg.id);
1124
+ getQuestionList(messages[idx]);
1128
1125
  };
1129
- const citationCallback = (msg) => {
1126
+ const extraMsgCallback = (msg) => {
1130
1127
  const messages = conversation.messages[msg.conversationId]?.message;
1131
1128
  const idx = findMsgIndex(msg.id, messages);
1132
1129
  if (idx === -1) return;
1133
1130
  conversation.messages[msg.conversationId].loading = true;
1134
1131
  messages[idx] = {
1135
1132
  ...messages[idx],
1136
- citations: msg.msgContent
1133
+ msgExtra: {
1134
+ ...messages[idx]?.msgExtra,
1135
+ ...msg.msgExtra
1136
+ }
1137
1137
  };
1138
1138
  };
1139
1139
  const errCallback = (msg) => {
@@ -1171,7 +1171,7 @@ function createChatStore() {
1171
1171
  endCallback(newMessage.data);
1172
1172
  break;
1173
1173
  case "TEXT_MESSAGE_CITATION":
1174
- citationCallback(newMessage.data);
1174
+ extraMsgCallback(newMessage.data);
1175
1175
  break;
1176
1176
  case "RUN_ERROR":
1177
1177
  errCallback(newMessage.data);