@blueking/chat-helper 0.0.1-beta.8 → 0.0.1-beta.9

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
@@ -41,16 +41,16 @@ const { agent } = chatHelper;
41
41
  // 响应式数据
42
42
  agent.info; // Ref<IAgentInfo | null> - agent 信息
43
43
  agent.isInfoLoading; // Ref<boolean> - agent 信息加载状态
44
- agent.userInput; // Ref<string> - 用户输入内容
45
44
 
46
45
  // 方法
47
46
  agent.getAgentInfo(); // () => Promise<void> - 获取 agent 信息
48
- agent.chat(sessionCode, url?, config?); // (sessionCode: string, url?: string, config?: IRequestConfig) => Promise<void> - 开始聊天(流式响应)
47
+ agent.chat(userInput, sessionCode, url?, config?); // (userInput: string, sessionCode: string, url?: string, config?: IRequestConfig) => Promise<void> - 开始聊天(流式响应)
49
48
  agent.stopChat(); // () => Promise<void> - 停止聊天
50
49
  ```
51
50
 
52
51
  **参数说明**:
53
52
 
53
+ - `userInput`: 用户输入的消息内容,必需参数
54
54
  - `sessionCode`: 会话代码,必需参数,标识当前聊天会话
55
55
  - `url`: 可选参数,自定义聊天接口地址,默认为 `'chat_completion/'`
56
56
  - `config`: 可选参数,额外的请求配置(如自定义 headers、data 等)
@@ -62,11 +62,11 @@ agent.stopChat(); // () => Promise<void> - 停止聊天
62
62
  <div>
63
63
  <div v-if="agent.isInfoLoading">加载中...</div>
64
64
  <div v-else-if="agent.info">
65
- <h2>{{ agent.info.name }}</h2>
66
- <p>{{ agent.info.description }}</p>
65
+ <h2>{{ agent.info.agentName }}</h2>
66
+ <p>{{ agent.info.conversationSettings?.openingRemark }}</p>
67
67
  </div>
68
68
  <input
69
- v-model="agent.userInput"
69
+ v-model="userInput"
70
70
  placeholder="请输入消息..."
71
71
  />
72
72
  <button @click="startChat">开始对话</button>
@@ -75,20 +75,23 @@ agent.stopChat(); // () => Promise<void> - 停止聊天
75
75
  </template>
76
76
 
77
77
  <script setup lang="ts">
78
- import { onMounted } from 'vue';
78
+ import { onMounted, ref } from 'vue';
79
79
  import { useChatHelper } from '@blueking/chat-helper';
80
80
 
81
81
  const { agent, session } = useChatHelper({
82
82
  /* ... */
83
83
  });
84
84
 
85
+ const userInput = ref('');
86
+
85
87
  onMounted(() => {
86
88
  agent.getAgentInfo();
87
89
  });
88
90
 
89
91
  const startChat = () => {
90
- if (session.current?.sessionCode) {
91
- agent.chat(session.current.sessionCode);
92
+ if (session.current?.sessionCode && userInput.value.trim()) {
93
+ agent.chat(userInput.value, session.current.sessionCode);
94
+ userInput.value = ''; // 清空输入框
92
95
  }
93
96
  };
94
97
  </script>
@@ -98,10 +101,10 @@ agent.stopChat(); // () => Promise<void> - 停止聊天
98
101
 
99
102
  ```typescript
100
103
  // 使用自定义 URL
101
- agent.chat(sessionCode, 'custom_chat_endpoint/');
104
+ agent.chat('你好', sessionCode, 'custom_chat_endpoint/');
102
105
 
103
106
  // 使用自定义请求配置
104
- agent.chat(sessionCode, undefined, {
107
+ agent.chat('你好', sessionCode, undefined, {
105
108
  headers: {
106
109
  'X-Custom-Header': 'value',
107
110
  },
@@ -112,7 +115,7 @@ agent.chat(sessionCode, undefined, {
112
115
  });
113
116
 
114
117
  // 同时使用自定义 URL 和配置
115
- agent.chat(sessionCode, 'custom_chat_endpoint/', {
118
+ agent.chat('你好', sessionCode, 'custom_chat_endpoint/', {
116
119
  headers: {
117
120
  'X-Custom-Header': 'value',
118
121
  },
@@ -156,7 +159,7 @@ session.deleteSession(sessionCode); // (sessionCode: string) => Promise<void> -
156
159
  @click="session.chooseSession(item.sessionCode)"
157
160
  :class="{ active: session.current?.sessionCode === item.sessionCode }"
158
161
  >
159
- {{ item.title }}
162
+ {{ item.sessionName }}
160
163
  </li>
161
164
  </ul>
162
165
  <button @click="createNewSession">新建会话</button>
@@ -177,7 +180,8 @@ session.deleteSession(sessionCode); // (sessionCode: string) => Promise<void> -
177
180
 
178
181
  const createNewSession = () => {
179
182
  session.createSession({
180
- title: '新会话',
183
+ sessionName: '新会话',
184
+ sessionCode: `session_${Date.now()}`,
181
185
  // ... 其他会话属性
182
186
  });
183
187
  };
@@ -758,7 +762,7 @@ class SafeProtocol extends AGUIProtocol {
758
762
 
759
763
  ### 场景 1:带输入框的聊天界面
760
764
 
761
- 使用 `agent.userInput` 实现双向绑定:
765
+ 使用独立的 `ref` 管理用户输入:
762
766
 
763
767
  ```vue
764
768
  <template>
@@ -773,7 +777,7 @@ class SafeProtocol extends AGUIProtocol {
773
777
  </div>
774
778
  <div class="input-box">
775
779
  <textarea
776
- v-model="agent.userInput"
780
+ v-model="userInput"
777
781
  @keydown.enter.prevent="handleSend"
778
782
  placeholder="输入消息,按 Enter 发送..."
779
783
  :disabled="isStreaming"
@@ -796,15 +800,18 @@ class SafeProtocol extends AGUIProtocol {
796
800
  /* ... */
797
801
  });
798
802
  const isStreaming = ref(false);
803
+ const userInput = ref('');
799
804
 
800
805
  const canSend = computed(
801
- () => !isStreaming.value && agent.userInput.value.trim().length > 0 && session.current?.sessionCode,
806
+ () => !isStreaming.value && userInput.value.trim().length > 0 && session.current?.sessionCode,
802
807
  );
803
808
 
804
809
  const handleSend = () => {
805
810
  if (canSend.value) {
806
811
  isStreaming.value = true;
807
- agent.chat(session.current!.sessionCode).finally(() => {
812
+ const input = userInput.value;
813
+ userInput.value = ''; // 立即清空输入框
814
+ agent.chat(input, session.current!.sessionCode).finally(() => {
808
815
  isStreaming.value = false;
809
816
  });
810
817
  }
@@ -989,7 +996,7 @@ class SafeProtocol extends AGUIProtocol {
989
996
  </div>
990
997
 
991
998
  <textarea
992
- v-model="agent.userInput"
999
+ v-model="userInput"
993
1000
  placeholder="输入消息..."
994
1001
  />
995
1002
  <button @click="sendWithConfig">发送</button>
@@ -1004,12 +1011,13 @@ class SafeProtocol extends AGUIProtocol {
1004
1011
  /* ... */
1005
1012
  });
1006
1013
 
1014
+ const userInput = ref('');
1007
1015
  const temperature = ref(0.7);
1008
1016
  const maxTokens = ref(1000);
1009
1017
  const mode = ref('default');
1010
1018
 
1011
1019
  const sendWithConfig = () => {
1012
- if (!session.current?.sessionCode) return;
1020
+ if (!session.current?.sessionCode || !userInput.value.trim()) return;
1013
1021
 
1014
1022
  // 根据模式设置不同的端点
1015
1023
  const endpoint =
@@ -1020,7 +1028,7 @@ class SafeProtocol extends AGUIProtocol {
1020
1028
  : undefined;
1021
1029
 
1022
1030
  // 自定义请求参数
1023
- agent.chat(session.current.sessionCode, endpoint, {
1031
+ agent.chat(userInput.value, session.current.sessionCode, endpoint, {
1024
1032
  data: {
1025
1033
  temperature: temperature.value,
1026
1034
  max_tokens: maxTokens.value,
@@ -1030,6 +1038,8 @@ class SafeProtocol extends AGUIProtocol {
1030
1038
  'X-Chat-Mode': mode.value,
1031
1039
  },
1032
1040
  });
1041
+
1042
+ userInput.value = ''; // 清空输入框
1033
1043
  };
1034
1044
  </script>
1035
1045
  ```
@@ -1051,7 +1061,7 @@ class SafeProtocol extends AGUIProtocol {
1051
1061
  @click="session.chooseSession(item.sessionCode)"
1052
1062
  :class="{ active: session.current?.sessionCode === item.sessionCode }"
1053
1063
  >
1054
- {{ item.title }}
1064
+ {{ item.sessionName }}
1055
1065
  <button @click.stop="session.deleteSession(item.sessionCode)">删除</button>
1056
1066
  </li>
1057
1067
  </ul>
@@ -1108,7 +1118,7 @@ class SafeProtocol extends AGUIProtocol {
1108
1118
  <!-- 输入区域 -->
1109
1119
  <div class="input-area">
1110
1120
  <input
1111
- v-model="agent.userInput"
1121
+ v-model="userInput"
1112
1122
  @keyup.enter="sendMessage"
1113
1123
  placeholder="输入消息..."
1114
1124
  :disabled="isStreaming"
@@ -1135,6 +1145,7 @@ class SafeProtocol extends AGUIProtocol {
1135
1145
  import { useChatHelper, AGUIProtocol } from '@blueking/chat-helper';
1136
1146
 
1137
1147
  const isStreaming = ref(false);
1148
+ const userInput = ref('');
1138
1149
 
1139
1150
  const { agent, session, message } = useChatHelper({
1140
1151
  requestData: {
@@ -1186,14 +1197,15 @@ class SafeProtocol extends AGUIProtocol {
1186
1197
 
1187
1198
  const createNewSession = () => {
1188
1199
  session.createSession({
1189
- title: `会话 ${new Date().toLocaleString()}`,
1200
+ sessionName: `会话 ${new Date().toLocaleString()}`,
1190
1201
  sessionCode: `session_${Date.now()}`,
1191
1202
  });
1192
1203
  };
1193
1204
 
1194
1205
  const sendMessage = () => {
1195
- if (session.current?.sessionCode && agent.userInput.value.trim()) {
1196
- agent.chat(session.current.sessionCode);
1206
+ if (session.current?.sessionCode && userInput.value.trim()) {
1207
+ agent.chat(userInput.value, session.current.sessionCode);
1208
+ userInput.value = ''; // 清空输入框
1197
1209
  }
1198
1210
  };
1199
1211
  </script>
@@ -1306,6 +1318,12 @@ class SafeProtocol extends AGUIProtocol {
1306
1318
 
1307
1319
  <!-- 输入区域 -->
1308
1320
  <div class="input-area">
1321
+ <input
1322
+ v-model="userInput"
1323
+ @keyup.enter="sendMessage"
1324
+ placeholder="输入消息..."
1325
+ :disabled="isStreaming"
1326
+ />
1309
1327
  <button
1310
1328
  @click="sendMessage"
1311
1329
  :disabled="isStreaming"
@@ -1334,6 +1352,7 @@ class SafeProtocol extends AGUIProtocol {
1334
1352
 
1335
1353
  const isStreaming = ref(false);
1336
1354
  const status = ref<{ type: string; message: string } | null>(null);
1355
+ const userInput = ref('');
1337
1356
 
1338
1357
  // 自定义 Protocol,添加各种钩子
1339
1358
  class CustomChatProtocol extends AGUIProtocol {
@@ -1370,7 +1389,7 @@ class SafeProtocol extends AGUIProtocol {
1370
1389
  }
1371
1390
  }
1372
1391
 
1373
- const { agent } = useChatHelper({
1392
+ const { agent, session, message } = useChatHelper({
1374
1393
  requestData: {
1375
1394
  urlPrefix: 'https://your-api-domain.com/api/',
1376
1395
  },
@@ -1410,7 +1429,10 @@ class SafeProtocol extends AGUIProtocol {
1410
1429
  });
1411
1430
 
1412
1431
  const sendMessage = () => {
1413
- agent.chat();
1432
+ if (session.current?.sessionCode && userInput.value.trim()) {
1433
+ agent.chat(userInput.value, session.current.sessionCode);
1434
+ userInput.value = ''; // 清空输入框
1435
+ }
1414
1436
  };
1415
1437
 
1416
1438
  const stopStreaming = () => {
@@ -1464,16 +1486,38 @@ class SafeProtocol extends AGUIProtocol {
1464
1486
 
1465
1487
  ```typescript
1466
1488
  import type {
1489
+ // 主要配置和模块类型
1467
1490
  IUseChatHelperOptions,
1468
1491
  IAgentModule,
1469
1492
  ISessionModule,
1470
1493
  IMessageModule,
1471
1494
  IHttpModule,
1495
+
1496
+ // 核心数据类型
1472
1497
  IMessage,
1473
1498
  ISession,
1499
+ IAgentInfo,
1500
+
1501
+ // 消息相关枚举
1474
1502
  MessageRole,
1475
1503
  MessageStatus,
1476
1504
  MessageContentType,
1505
+ MessageContentStatus,
1506
+
1507
+ // 协议相关
1508
+ ISSEProtocol,
1509
+ AGUIProtocol,
1510
+
1511
+ // 事件类型(用于自定义 Protocol)
1512
+ IEvent,
1513
+ IRunStartedEvent,
1514
+ IRunFinishedEvent,
1515
+ IRunErrorEvent,
1516
+ ITextMessageChunkEvent,
1517
+ IThinkingStartEvent,
1518
+ IThinkingEndEvent,
1519
+ IToolCallStartEvent,
1520
+ // ... 更多事件类型
1477
1521
  } from '@blueking/chat-helper';
1478
1522
  ```
1479
1523