@blueking/chat-helper 0.0.1-beta.9 → 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 +631 -141
- package/dist/agent/type.d.ts +27 -2
- package/dist/agent/type.ts.js +1 -1
- package/dist/agent/use-agent.d.ts +464 -484
- package/dist/agent/use-agent.ts.js +191 -42
- package/dist/event/ag-ui.d.ts +37 -7
- package/dist/event/ag-ui.ts.js +225 -173
- package/dist/event/type.d.ts +99 -107
- package/dist/event/type.ts.js +34 -11
- package/dist/http/fetch/fetch.d.ts +5 -1
- package/dist/http/fetch/fetch.ts.js +40 -51
- package/dist/http/fetch/index.d.ts +1 -0
- package/dist/http/fetch/index.ts.js +133 -3
- package/dist/http/index.d.ts +14 -5
- package/dist/http/index.ts.js +59 -3
- package/dist/http/module/index.d.ts +13 -5
- package/dist/http/module/index.ts.js +2 -1
- package/dist/http/module/message.d.ts +22 -5
- package/dist/http/module/message.ts.js +51 -4
- package/dist/http/module/session.d.ts +4 -1
- package/dist/http/module/session.ts.js +66 -4
- package/dist/http/transform/agent.ts.js +11 -8
- package/dist/http/transform/message.d.ts +6 -6
- package/dist/http/transform/message.ts.js +566 -118
- package/dist/http/transform/session.ts.js +9 -1
- package/dist/index.d.ts +2983 -3314
- package/dist/index.ts.js +27 -5
- package/dist/mediator/index.d.ts +2 -0
- package/dist/mediator/index.ts.js +26 -0
- package/dist/mediator/type.d.ts +50 -0
- package/dist/mediator/type.ts.js +28 -0
- package/dist/mediator/use-mediator.d.ts +7 -0
- package/dist/mediator/use-mediator.ts.js +47 -0
- package/dist/message/type.d.ts +280 -146
- package/dist/message/type.ts.js +16 -15
- package/dist/message/use-message.d.ts +847 -963
- package/dist/message/use-message.ts.js +230 -37
- package/dist/session/type.d.ts +10 -0
- package/dist/session/use-session.d.ts +2006 -2214
- package/dist/session/use-session.ts.js +198 -33
- package/dist/type.d.ts +2 -0
- package/package.json +11 -6
|
@@ -51,13 +51,40 @@ function _async_to_generator(fn) {
|
|
|
51
51
|
});
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
|
+
function _define_property(obj, key, value) {
|
|
55
|
+
if (key in obj) {
|
|
56
|
+
Object.defineProperty(obj, key, {
|
|
57
|
+
value: value,
|
|
58
|
+
enumerable: true,
|
|
59
|
+
configurable: true,
|
|
60
|
+
writable: true
|
|
61
|
+
});
|
|
62
|
+
} else {
|
|
63
|
+
obj[key] = value;
|
|
64
|
+
}
|
|
65
|
+
return obj;
|
|
66
|
+
}
|
|
67
|
+
function _object_spread(target) {
|
|
68
|
+
for(var i = 1; i < arguments.length; i++){
|
|
69
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
70
|
+
var ownKeys = Object.keys(source);
|
|
71
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
72
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
73
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
76
|
+
ownKeys.forEach(function(key) {
|
|
77
|
+
_define_property(target, key, source[key]);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return target;
|
|
81
|
+
}
|
|
54
82
|
import { ref } from 'vue';
|
|
55
83
|
/**
|
|
56
84
|
* 使用会话模块,主要做业务的组合
|
|
57
|
-
* @param
|
|
58
|
-
* @param message - 消息模块
|
|
85
|
+
* @param mediator - 中介者模块,用于获取其他模块的引用
|
|
59
86
|
* @returns 会话模块
|
|
60
|
-
*/ export const useSession = (
|
|
87
|
+
*/ export const useSession = (mediator)=>{
|
|
61
88
|
const list = ref([]);
|
|
62
89
|
const current = ref(null);
|
|
63
90
|
const isCurrentLoading = ref(false);
|
|
@@ -65,67 +92,198 @@ import { ref } from 'vue';
|
|
|
65
92
|
const isCreateLoading = ref(false);
|
|
66
93
|
const isUpdateLoading = ref(false);
|
|
67
94
|
const isDeleteLoading = ref(false);
|
|
95
|
+
const isBatchDeleteLoading = ref(false);
|
|
96
|
+
const isRenameLoading = ref(false);
|
|
97
|
+
/**
|
|
98
|
+
* 更新 list 中的 session,并同步更新 current
|
|
99
|
+
* @param session - Partial session
|
|
100
|
+
*/ const updateSessionInList = (session)=>{
|
|
101
|
+
var _current_value;
|
|
102
|
+
// 先更新 list 中对应的 session
|
|
103
|
+
list.value = list.value.map((item)=>item.sessionCode === session.sessionCode ? _object_spread({}, item, session) : item);
|
|
104
|
+
// 如果 current 是被更新的 session,则让 current 重新指向 list 中更新后的对象
|
|
105
|
+
if (((_current_value = current.value) === null || _current_value === void 0 ? void 0 : _current_value.sessionCode) === session.sessionCode) {
|
|
106
|
+
var _list_value_find;
|
|
107
|
+
current.value = (_list_value_find = list.value.find((item)=>item.sessionCode === session.sessionCode)) !== null && _list_value_find !== void 0 ? _list_value_find : current.value;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
68
110
|
const getSessions = ()=>{
|
|
111
|
+
var _mediator_http;
|
|
69
112
|
isListLoading.value = true;
|
|
70
|
-
return http.session.getSessions().then((res)=>{
|
|
113
|
+
return (_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.session.getSessions().then((res)=>{
|
|
71
114
|
list.value = res;
|
|
72
115
|
}).finally(()=>{
|
|
73
116
|
isListLoading.value = false;
|
|
74
117
|
});
|
|
75
118
|
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
119
|
+
/**
|
|
120
|
+
* 切换会话
|
|
121
|
+
* @param sessionCode - 会话编码
|
|
122
|
+
* @param options - 选项
|
|
123
|
+
* @param options.loadMessages - 是否加载消息列表,默认 true。新创建的会话可设为 false 跳过加载
|
|
124
|
+
*/ const chooseSession = function() {
|
|
125
|
+
var _ref = _async_to_generator(function*(sessionCode, options) {
|
|
126
|
+
var // 中止当前聊天
|
|
127
|
+
_mediator_agent;
|
|
128
|
+
(_mediator_agent = mediator.agent) === null || _mediator_agent === void 0 ? void 0 : _mediator_agent.abortChat();
|
|
79
129
|
var _list_value_find;
|
|
80
130
|
// 选择会话
|
|
81
131
|
current.value = (_list_value_find = list.value.find((item)=>item.sessionCode === sessionCode)) !== null && _list_value_find !== void 0 ? _list_value_find : null;
|
|
82
|
-
//
|
|
83
|
-
|
|
132
|
+
// 默认加载消息,但允许跳过(新会话消息必定为空,无需加载)
|
|
133
|
+
if ((options === null || options === void 0 ? void 0 : options.loadMessages) !== false) {
|
|
134
|
+
var _mediator_message, // 继续聊天
|
|
135
|
+
_mediator_agent1;
|
|
136
|
+
// 获取会话内容
|
|
137
|
+
yield (_mediator_message = mediator.message) === null || _mediator_message === void 0 ? void 0 : _mediator_message.getMessages(sessionCode);
|
|
138
|
+
(_mediator_agent1 = mediator.agent) === null || _mediator_agent1 === void 0 ? void 0 : _mediator_agent1.resumeStreamingChat(sessionCode);
|
|
139
|
+
} else {
|
|
140
|
+
// 新会话,清空消息列表
|
|
141
|
+
if (mediator.message) {
|
|
142
|
+
mediator.message.list.value = [];
|
|
143
|
+
}
|
|
144
|
+
}
|
|
84
145
|
});
|
|
85
|
-
return function chooseSession(sessionCode) {
|
|
146
|
+
return function chooseSession(sessionCode, options) {
|
|
86
147
|
return _ref.apply(this, arguments);
|
|
87
148
|
};
|
|
88
149
|
}();
|
|
89
150
|
const getSession = (sessionCode)=>{
|
|
151
|
+
var _mediator_http;
|
|
90
152
|
isCurrentLoading.value = true;
|
|
91
|
-
return http.session.getSession(sessionCode).then((res)=>{
|
|
153
|
+
return (_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.session.getSession(sessionCode).then((res)=>{
|
|
92
154
|
current.value = res;
|
|
93
155
|
}).finally(()=>{
|
|
94
156
|
isCurrentLoading.value = false;
|
|
95
157
|
});
|
|
96
158
|
};
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
159
|
+
/**
|
|
160
|
+
* 创建新会话
|
|
161
|
+
* @param session - 会话数据
|
|
162
|
+
* @param options - 选项
|
|
163
|
+
* @param options.loadMessages - 创建后是否加载消息列表,默认 false(新会话消息必定为空)
|
|
164
|
+
*/ const createSession = function() {
|
|
165
|
+
var _ref = _async_to_generator(function*(session, options) {
|
|
166
|
+
isCreateLoading.value = true;
|
|
167
|
+
try {
|
|
168
|
+
var _mediator_http;
|
|
169
|
+
const res = yield (_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.session.plusSession(session);
|
|
170
|
+
if (res) {
|
|
171
|
+
list.value.unshift(res); // 新会话插入到列表头部
|
|
172
|
+
var _options_loadMessages;
|
|
173
|
+
// 新会话默认不加载消息(消息必定为空),优化 UX
|
|
174
|
+
yield chooseSession(res.sessionCode, {
|
|
175
|
+
loadMessages: (_options_loadMessages = options === null || options === void 0 ? void 0 : options.loadMessages) !== null && _options_loadMessages !== void 0 ? _options_loadMessages : false
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
} finally{
|
|
179
|
+
isCreateLoading.value = false;
|
|
180
|
+
}
|
|
104
181
|
});
|
|
105
|
-
|
|
182
|
+
return function createSession(session, options) {
|
|
183
|
+
return _ref.apply(this, arguments);
|
|
184
|
+
};
|
|
185
|
+
}();
|
|
106
186
|
const updateSession = (session)=>{
|
|
187
|
+
var _mediator_http;
|
|
107
188
|
isUpdateLoading.value = true;
|
|
108
|
-
return http.session.modifySession(session).then((res)=>{
|
|
109
|
-
|
|
110
|
-
list.value = list.value.map((item)=>item.sessionCode === session.sessionCode ? current.value : item);
|
|
189
|
+
return (_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.session.modifySession(session).then((res)=>{
|
|
190
|
+
updateSessionInList(res);
|
|
111
191
|
}).finally(()=>{
|
|
112
192
|
isUpdateLoading.value = false;
|
|
113
193
|
});
|
|
114
194
|
};
|
|
115
|
-
const deleteSession = (
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
195
|
+
const deleteSession = function() {
|
|
196
|
+
var _ref = _async_to_generator(function*(sessionCode) {
|
|
197
|
+
isDeleteLoading.value = true;
|
|
198
|
+
try {
|
|
199
|
+
var _mediator_http, _current_value, _list_value_;
|
|
200
|
+
yield (_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.session.deleteSession(sessionCode);
|
|
201
|
+
list.value = list.value.filter((item)=>item.sessionCode !== sessionCode);
|
|
202
|
+
// 如果当前会话被删除,选择第一个会话
|
|
203
|
+
if (((_current_value = current.value) === null || _current_value === void 0 ? void 0 : _current_value.sessionCode) === sessionCode && ((_list_value_ = list.value[0]) === null || _list_value_ === void 0 ? void 0 : _list_value_.sessionCode)) {
|
|
204
|
+
yield chooseSession(list.value[0].sessionCode);
|
|
205
|
+
}
|
|
206
|
+
} finally{
|
|
207
|
+
isDeleteLoading.value = false;
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
return function deleteSession(sessionCode) {
|
|
211
|
+
return _ref.apply(this, arguments);
|
|
212
|
+
};
|
|
213
|
+
}();
|
|
214
|
+
/**
|
|
215
|
+
* 批量删除会话
|
|
216
|
+
* @param sessionCodes - 要删除的会话编码列表
|
|
217
|
+
*/ const batchDeleteSessions = function() {
|
|
218
|
+
var _ref = _async_to_generator(function*(sessionCodes) {
|
|
219
|
+
if (sessionCodes.length === 0) return;
|
|
220
|
+
isBatchDeleteLoading.value = true;
|
|
221
|
+
try {
|
|
222
|
+
var _mediator_http;
|
|
223
|
+
yield (_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.session.batchDeleteSessions(sessionCodes);
|
|
224
|
+
const deletedSet = new Set(sessionCodes);
|
|
225
|
+
list.value = list.value.filter((item)=>!deletedSet.has(item.sessionCode));
|
|
226
|
+
if (current.value && deletedSet.has(current.value.sessionCode)) {
|
|
227
|
+
if (list.value.length > 0) {
|
|
228
|
+
yield chooseSession(list.value[0].sessionCode);
|
|
229
|
+
} else {
|
|
230
|
+
current.value = null;
|
|
231
|
+
if (mediator.message) {
|
|
232
|
+
mediator.message.list.value = [];
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
} finally{
|
|
237
|
+
isBatchDeleteLoading.value = false;
|
|
124
238
|
}
|
|
239
|
+
});
|
|
240
|
+
return function batchDeleteSessions(sessionCodes) {
|
|
241
|
+
return _ref.apply(this, arguments);
|
|
242
|
+
};
|
|
243
|
+
}();
|
|
244
|
+
/**
|
|
245
|
+
* 提交会话反馈,sessionContentIds 只需要传 user 对应的 sessionContentId
|
|
246
|
+
* @param data - ISessionFeedback
|
|
247
|
+
*/ const postSessionFeedback = (data)=>{
|
|
248
|
+
var _mediator_http;
|
|
249
|
+
return (_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.session.postSessionFeedback(data);
|
|
250
|
+
};
|
|
251
|
+
// 获取会话反馈原因
|
|
252
|
+
const getSessionFeedbackReasons = (rate)=>{
|
|
253
|
+
var _mediator_http;
|
|
254
|
+
return (_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.session.getSessionFeedbackReasons(rate);
|
|
255
|
+
};
|
|
256
|
+
// 会话重命名
|
|
257
|
+
const renameSession = (sessionCode)=>{
|
|
258
|
+
var _mediator_http;
|
|
259
|
+
isRenameLoading.value = true;
|
|
260
|
+
return (_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.session.renameSession(sessionCode).then((res)=>{
|
|
261
|
+
updateSessionInList({
|
|
262
|
+
sessionCode: res.sessionCode,
|
|
263
|
+
sessionName: res.sessionName
|
|
264
|
+
});
|
|
125
265
|
}).finally(()=>{
|
|
126
|
-
|
|
266
|
+
isRenameLoading.value = false;
|
|
127
267
|
});
|
|
128
268
|
};
|
|
269
|
+
// 上传文件到会话
|
|
270
|
+
const uploadFile = (sessionCode, file)=>{
|
|
271
|
+
var _mediator_http;
|
|
272
|
+
return (_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.session.uploadFile(sessionCode, file);
|
|
273
|
+
};
|
|
274
|
+
/**
|
|
275
|
+
* 重置 session 模块状态
|
|
276
|
+
*/ const reset = ()=>{
|
|
277
|
+
list.value = [];
|
|
278
|
+
current.value = null;
|
|
279
|
+
isCurrentLoading.value = false;
|
|
280
|
+
isListLoading.value = false;
|
|
281
|
+
isCreateLoading.value = false;
|
|
282
|
+
isUpdateLoading.value = false;
|
|
283
|
+
isDeleteLoading.value = false;
|
|
284
|
+
isBatchDeleteLoading.value = false;
|
|
285
|
+
isRenameLoading.value = false;
|
|
286
|
+
};
|
|
129
287
|
return {
|
|
130
288
|
list,
|
|
131
289
|
current,
|
|
@@ -134,11 +292,18 @@ import { ref } from 'vue';
|
|
|
134
292
|
isCreateLoading,
|
|
135
293
|
isUpdateLoading,
|
|
136
294
|
isDeleteLoading,
|
|
295
|
+
isBatchDeleteLoading,
|
|
137
296
|
getSessions,
|
|
138
297
|
chooseSession,
|
|
139
298
|
getSession,
|
|
140
299
|
createSession,
|
|
141
300
|
updateSession,
|
|
142
|
-
deleteSession
|
|
301
|
+
deleteSession,
|
|
302
|
+
batchDeleteSessions,
|
|
303
|
+
postSessionFeedback,
|
|
304
|
+
getSessionFeedbackReasons,
|
|
305
|
+
renameSession,
|
|
306
|
+
uploadFile,
|
|
307
|
+
reset
|
|
143
308
|
};
|
|
144
309
|
};
|
package/dist/type.d.ts
CHANGED
|
@@ -2,10 +2,12 @@ import type { IRequestConfig, ISSEProtocol } from './http/fetch';
|
|
|
2
2
|
import type { IResponse } from './http/fetch';
|
|
3
3
|
export interface IUseChatHelperOptions {
|
|
4
4
|
protocol?: ISSEProtocol;
|
|
5
|
+
/** 自定义拦截器,优先级高于内置 requestData 拦截器 */
|
|
5
6
|
interceptors?: {
|
|
6
7
|
request?: (config: IRequestConfig) => IRequestConfig;
|
|
7
8
|
response?: (response: IResponse) => IResponse;
|
|
8
9
|
};
|
|
10
|
+
/** 全局默认请求配置,通过内置拦截器自动合并到每次请求(函数形式可延迟求值) */
|
|
9
11
|
requestData: {
|
|
10
12
|
data?: (() => Record<string, unknown>) | Record<string, unknown>;
|
|
11
13
|
headers?: (() => Record<string, string>) | Record<string, string>;
|
package/package.json
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blueking/chat-helper",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.ts.js",
|
|
6
|
-
"
|
|
7
|
-
"build": "bk-cli-service build && vue-tsc --emitDeclarationOnly"
|
|
8
|
-
},
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
9
7
|
"keywords": [
|
|
10
8
|
"chat-helper"
|
|
11
9
|
],
|
|
12
10
|
"files": [
|
|
13
11
|
"dist"
|
|
14
12
|
],
|
|
15
|
-
"author": "",
|
|
13
|
+
"author": "Tencent BlueKing",
|
|
16
14
|
"license": "ISC",
|
|
17
|
-
"
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/TencentBlueKing/bk-aidev-agent.git",
|
|
18
|
+
"directory": "src/frontend/ai-blueking/packages/chat-helper"
|
|
19
|
+
},
|
|
18
20
|
"peerDependencies": {
|
|
19
21
|
"vue": "^3.5.24"
|
|
20
22
|
},
|
|
@@ -23,5 +25,8 @@
|
|
|
23
25
|
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
24
26
|
"typescript": "^5.5.4",
|
|
25
27
|
"vue-tsc": "^3.1.4"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "bk-cli-service build && vue-tsc --emitDeclarationOnly"
|
|
26
31
|
}
|
|
27
32
|
}
|