@blueking/chat-helper 0.0.12-beta.9 → 0.0.13-dev.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 +21 -7
- package/dist/agent/type.d.ts +82 -0
- package/dist/agent/type.ts.js +5 -1
- package/dist/agent/use-agent.d.ts +229 -10
- package/dist/agent/use-agent.ts.js +365 -25
- package/dist/event/ag-ui.d.ts +4 -1
- package/dist/event/ag-ui.ts.js +76 -6
- package/dist/event/type.d.ts +14 -2
- package/dist/event/type.ts.js +2 -0
- package/dist/http/fetch/fetch.spec.d.ts +1 -0
- package/dist/http/fetch/fetch.ts.js +106 -22
- package/dist/http/index.d.ts +11 -5
- package/dist/http/module/agent.d.ts +2 -0
- package/dist/http/module/agent.ts.js +19 -2
- package/dist/http/module/index.d.ts +11 -5
- package/dist/http/module/message.d.ts +1 -1
- package/dist/http/module/message.ts.js +4 -3
- package/dist/http/module/session.d.ts +10 -5
- package/dist/http/module/session.ts.js +60 -3
- package/dist/http/transform/agent.d.ts +9 -1
- package/dist/http/transform/agent.spec.d.ts +1 -0
- package/dist/http/transform/agent.ts.js +29 -0
- package/dist/http/transform/message.spec.d.ts +1 -0
- package/dist/http/transform/message.ts.js +19 -5
- package/dist/index.d.ts +1194 -16
- package/dist/message/type.d.ts +35 -3
- package/dist/message/type.ts.js +16 -0
- package/dist/message/use-message.d.ts +316 -0
- package/dist/session/index.d.ts +1 -0
- package/dist/session/index.ts.js +2 -1
- package/dist/session/pv-file-upload.d.ts +7 -0
- package/dist/session/pv-file-upload.spec.d.ts +1 -0
- package/dist/session/pv-file-upload.ts.js +64 -0
- package/dist/session/type.d.ts +57 -0
- package/dist/session/use-session.d.ts +644 -6
- package/dist/session/use-session.spec.d.ts +1 -0
- package/dist/session/use-session.ts.js +117 -10
- package/package.json +4 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -79,7 +79,9 @@ function _object_spread(target) {
|
|
|
79
79
|
}
|
|
80
80
|
return target;
|
|
81
81
|
}
|
|
82
|
-
import { ref } from 'vue';
|
|
82
|
+
import { computed, ref } from 'vue';
|
|
83
|
+
import { isPvFileUploadSupported } from './pv-file-upload.ts.js';
|
|
84
|
+
/** 会话列表默认每页条数 */ const DEFAULT_PAGE_SIZE = 20;
|
|
83
85
|
/**
|
|
84
86
|
* 使用会话模块,主要做业务的组合
|
|
85
87
|
* @param mediator - 中介者模块,用于获取其他模块的引用
|
|
@@ -87,13 +89,18 @@ import { ref } from 'vue';
|
|
|
87
89
|
*/ export const useSession = (mediator)=>{
|
|
88
90
|
const list = ref([]);
|
|
89
91
|
const current = ref(null);
|
|
92
|
+
const page = ref(0);
|
|
93
|
+
const numPages = ref(0);
|
|
94
|
+
const count = ref(0);
|
|
90
95
|
const isCurrentLoading = ref(false);
|
|
91
96
|
const isListLoading = ref(false);
|
|
97
|
+
const isLoadingMore = ref(false);
|
|
92
98
|
const isCreateLoading = ref(false);
|
|
93
99
|
const isUpdateLoading = ref(false);
|
|
94
100
|
const isDeleteLoading = ref(false);
|
|
95
101
|
const isBatchDeleteLoading = ref(false);
|
|
96
102
|
const isRenameLoading = ref(false);
|
|
103
|
+
const hasMore = computed(()=>page.value > 0 && page.value < numPages.value);
|
|
97
104
|
/**
|
|
98
105
|
* 更新 list 中的 session,并同步更新 current
|
|
99
106
|
* @param session - Partial session
|
|
@@ -101,22 +108,62 @@ import { ref } from 'vue';
|
|
|
101
108
|
var _current_value;
|
|
102
109
|
// 先更新 list 中对应的 session
|
|
103
110
|
list.value = list.value.map((item)=>item.sessionCode === session.sessionCode ? _object_spread({}, item, session) : item);
|
|
104
|
-
//
|
|
111
|
+
// 同步 current:优先指向 list 中更新后的对象;若不在 list(分页外 / getSession 单独写入),直接合并字段
|
|
105
112
|
if (((_current_value = current.value) === null || _current_value === void 0 ? void 0 : _current_value.sessionCode) === session.sessionCode) {
|
|
106
113
|
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;
|
|
114
|
+
current.value = (_list_value_find = list.value.find((item)=>item.sessionCode === session.sessionCode)) !== null && _list_value_find !== void 0 ? _list_value_find : _object_spread({}, current.value, session);
|
|
108
115
|
}
|
|
109
116
|
};
|
|
110
|
-
|
|
117
|
+
/**
|
|
118
|
+
* 拉取会话列表(默认第 1 页并替换本地 list)
|
|
119
|
+
*/ const getSessions = (params)=>{
|
|
111
120
|
var _mediator_http;
|
|
112
121
|
isListLoading.value = true;
|
|
113
|
-
|
|
114
|
-
|
|
122
|
+
var _params_page, _params_page_size;
|
|
123
|
+
const requestParams = {
|
|
124
|
+
page: (_params_page = params === null || params === void 0 ? void 0 : params.page) !== null && _params_page !== void 0 ? _params_page : 1,
|
|
125
|
+
page_size: (_params_page_size = params === null || params === void 0 ? void 0 : params.page_size) !== null && _params_page_size !== void 0 ? _params_page_size : DEFAULT_PAGE_SIZE
|
|
126
|
+
};
|
|
127
|
+
return (_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.session.getSessions(requestParams).then((res)=>{
|
|
128
|
+
list.value = res.results;
|
|
129
|
+
page.value = res.page;
|
|
130
|
+
numPages.value = res.numPages;
|
|
131
|
+
count.value = res.count;
|
|
115
132
|
}).finally(()=>{
|
|
116
133
|
isListLoading.value = false;
|
|
117
134
|
});
|
|
118
135
|
};
|
|
119
136
|
/**
|
|
137
|
+
* 加载下一页会话并追加到 list(按 sessionCode 去重)
|
|
138
|
+
*/ const loadMoreSessions = function() {
|
|
139
|
+
var _ref = _async_to_generator(function*(pageSize = DEFAULT_PAGE_SIZE) {
|
|
140
|
+
if (!hasMore.value || isListLoading.value || isLoadingMore.value) return;
|
|
141
|
+
isLoadingMore.value = true;
|
|
142
|
+
try {
|
|
143
|
+
var _mediator_http;
|
|
144
|
+
const res = yield (_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.session.getSessions({
|
|
145
|
+
page: page.value + 1,
|
|
146
|
+
page_size: pageSize
|
|
147
|
+
});
|
|
148
|
+
if (!res) return;
|
|
149
|
+
const existing = new Set(list.value.map((s)=>s.sessionCode));
|
|
150
|
+
const appended = res.results.filter((s)=>!existing.has(s.sessionCode));
|
|
151
|
+
list.value = [
|
|
152
|
+
...list.value,
|
|
153
|
+
...appended
|
|
154
|
+
];
|
|
155
|
+
page.value = res.page;
|
|
156
|
+
numPages.value = res.numPages;
|
|
157
|
+
count.value = res.count;
|
|
158
|
+
} finally{
|
|
159
|
+
isLoadingMore.value = false;
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
return function loadMoreSessions() {
|
|
163
|
+
return _ref.apply(this, arguments);
|
|
164
|
+
};
|
|
165
|
+
}();
|
|
166
|
+
/**
|
|
120
167
|
* 切换会话
|
|
121
168
|
* @param sessionCode - 会话编码
|
|
122
169
|
* @param options - 选项
|
|
@@ -177,6 +224,7 @@ import { ref } from 'vue';
|
|
|
177
224
|
const res = yield (_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.session.plusSession(session);
|
|
178
225
|
if (res) {
|
|
179
226
|
list.value.unshift(res); // 新会话插入到列表头部
|
|
227
|
+
count.value += 1;
|
|
180
228
|
var _options_loadMessages;
|
|
181
229
|
// 新会话默认不加载消息(消息必定为空),优化 UX
|
|
182
230
|
yield chooseSession(res.sessionCode, {
|
|
@@ -207,6 +255,7 @@ import { ref } from 'vue';
|
|
|
207
255
|
var _mediator_http, _current_value, _list_value_;
|
|
208
256
|
yield (_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.session.deleteSession(sessionCode);
|
|
209
257
|
list.value = list.value.filter((item)=>item.sessionCode !== sessionCode);
|
|
258
|
+
count.value = Math.max(0, count.value - 1);
|
|
210
259
|
// 如果当前会话被删除,选择第一个会话
|
|
211
260
|
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)) {
|
|
212
261
|
yield chooseSession(list.value[0].sessionCode);
|
|
@@ -230,7 +279,10 @@ import { ref } from 'vue';
|
|
|
230
279
|
var _mediator_http;
|
|
231
280
|
yield (_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.session.batchDeleteSessions(sessionCodes);
|
|
232
281
|
const deletedSet = new Set(sessionCodes);
|
|
282
|
+
const beforeLength = list.value.length;
|
|
233
283
|
list.value = list.value.filter((item)=>!deletedSet.has(item.sessionCode));
|
|
284
|
+
const removedCount = beforeLength - list.value.length;
|
|
285
|
+
count.value = Math.max(0, count.value - removedCount);
|
|
234
286
|
if (current.value && deletedSet.has(current.value.sessionCode)) {
|
|
235
287
|
if (list.value.length > 0) {
|
|
236
288
|
yield chooseSession(list.value[0].sessionCode);
|
|
@@ -261,7 +313,7 @@ import { ref } from 'vue';
|
|
|
261
313
|
var _mediator_http;
|
|
262
314
|
return (_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.session.getSessionFeedbackReasons(rate);
|
|
263
315
|
};
|
|
264
|
-
//
|
|
316
|
+
// 会话重命名(返回接口最新 session,供上层事件直接使用新名称)
|
|
265
317
|
const renameSession = (sessionCode)=>{
|
|
266
318
|
var _mediator_http;
|
|
267
319
|
isRenameLoading.value = true;
|
|
@@ -270,22 +322,69 @@ import { ref } from 'vue';
|
|
|
270
322
|
sessionCode: res.sessionCode,
|
|
271
323
|
sessionName: res.sessionName
|
|
272
324
|
});
|
|
325
|
+
return res;
|
|
273
326
|
}).finally(()=>{
|
|
274
327
|
isRenameLoading.value = false;
|
|
275
328
|
});
|
|
276
329
|
};
|
|
277
|
-
|
|
278
|
-
|
|
330
|
+
const resolvePvUploadItem = (item)=>{
|
|
331
|
+
if (!item) {
|
|
332
|
+
throw new Error('Upload failed: empty results');
|
|
333
|
+
}
|
|
334
|
+
return item;
|
|
335
|
+
};
|
|
336
|
+
/**
|
|
337
|
+
* 上传文件到会话。
|
|
338
|
+
* 能解析且 agent_sdk_version < 2.2.2rc25 走旧 upload/{fileName}/;否则(含空字符串 / 缺省)走 pv_files/upload。
|
|
339
|
+
*/ const uploadFile = (sessionCode, file)=>{
|
|
340
|
+
var _mediator_agent_info_value, _mediator_agent, _mediator_http;
|
|
341
|
+
const sdkVersion = (_mediator_agent = mediator.agent) === null || _mediator_agent === void 0 ? void 0 : (_mediator_agent_info_value = _mediator_agent.info.value) === null || _mediator_agent_info_value === void 0 ? void 0 : _mediator_agent_info_value.agentSdkVersion;
|
|
342
|
+
if (isPvFileUploadSupported(sdkVersion)) {
|
|
343
|
+
var _mediator_http1;
|
|
344
|
+
return Promise.resolve((_mediator_http1 = mediator.http) === null || _mediator_http1 === void 0 ? void 0 : _mediator_http1.session.uploadPvFiles(sessionCode, [
|
|
345
|
+
file
|
|
346
|
+
])).then((res)=>{
|
|
347
|
+
var _res_results;
|
|
348
|
+
return resolvePvUploadItem(res === null || res === void 0 ? void 0 : (_res_results = res.results) === null || _res_results === void 0 ? void 0 : _res_results[0]);
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
return Promise.resolve((_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.session.uploadFile(sessionCode, file));
|
|
352
|
+
};
|
|
353
|
+
const uploadFiles = function() {
|
|
354
|
+
var _ref = _async_to_generator(function*(sessionCode, files) {
|
|
355
|
+
var _mediator_agent_info_value, _mediator_agent;
|
|
356
|
+
const sdkVersion = (_mediator_agent = mediator.agent) === null || _mediator_agent === void 0 ? void 0 : (_mediator_agent_info_value = _mediator_agent.info.value) === null || _mediator_agent_info_value === void 0 ? void 0 : _mediator_agent_info_value.agentSdkVersion;
|
|
357
|
+
if (isPvFileUploadSupported(sdkVersion)) {
|
|
358
|
+
var _mediator_http;
|
|
359
|
+
const res = yield (_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.session.uploadPvFiles(sessionCode, files);
|
|
360
|
+
var _res_results;
|
|
361
|
+
return (_res_results = res === null || res === void 0 ? void 0 : res.results) !== null && _res_results !== void 0 ? _res_results : [];
|
|
362
|
+
}
|
|
363
|
+
const results = yield Promise.all(files.map((file)=>{
|
|
364
|
+
var _mediator_http;
|
|
365
|
+
return (_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.session.uploadFile(sessionCode, file);
|
|
366
|
+
}));
|
|
367
|
+
return results.filter((item)=>!!item);
|
|
368
|
+
});
|
|
369
|
+
return function uploadFiles(sessionCode, files) {
|
|
370
|
+
return _ref.apply(this, arguments);
|
|
371
|
+
};
|
|
372
|
+
}();
|
|
373
|
+
const getPvFileDownloadUrl = (sessionCode, path, options)=>{
|
|
279
374
|
var _mediator_http;
|
|
280
|
-
return (_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.session.
|
|
375
|
+
return (_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.session.getPvFileDownloadUrl(sessionCode, path, options);
|
|
281
376
|
};
|
|
282
377
|
/**
|
|
283
378
|
* 重置 session 模块状态
|
|
284
379
|
*/ const reset = ()=>{
|
|
285
380
|
list.value = [];
|
|
286
381
|
current.value = null;
|
|
382
|
+
page.value = 0;
|
|
383
|
+
numPages.value = 0;
|
|
384
|
+
count.value = 0;
|
|
287
385
|
isCurrentLoading.value = false;
|
|
288
386
|
isListLoading.value = false;
|
|
387
|
+
isLoadingMore.value = false;
|
|
289
388
|
isCreateLoading.value = false;
|
|
290
389
|
isUpdateLoading.value = false;
|
|
291
390
|
isDeleteLoading.value = false;
|
|
@@ -295,13 +394,19 @@ import { ref } from 'vue';
|
|
|
295
394
|
return {
|
|
296
395
|
list,
|
|
297
396
|
current,
|
|
397
|
+
page,
|
|
398
|
+
numPages,
|
|
399
|
+
count,
|
|
400
|
+
hasMore,
|
|
298
401
|
isCurrentLoading,
|
|
299
402
|
isListLoading,
|
|
403
|
+
isLoadingMore,
|
|
300
404
|
isCreateLoading,
|
|
301
405
|
isUpdateLoading,
|
|
302
406
|
isDeleteLoading,
|
|
303
407
|
isBatchDeleteLoading,
|
|
304
408
|
getSessions,
|
|
409
|
+
loadMoreSessions,
|
|
305
410
|
chooseSession,
|
|
306
411
|
getSession,
|
|
307
412
|
createSession,
|
|
@@ -312,6 +417,8 @@ import { ref } from 'vue';
|
|
|
312
417
|
getSessionFeedbackReasons,
|
|
313
418
|
renameSession,
|
|
314
419
|
uploadFile,
|
|
420
|
+
uploadFiles,
|
|
421
|
+
getPvFileDownloadUrl,
|
|
315
422
|
reset
|
|
316
423
|
};
|
|
317
424
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blueking/chat-helper",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13-dev.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.ts.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -24,12 +24,14 @@
|
|
|
24
24
|
"@blueking/cli-service": "0.1.0-beta.31",
|
|
25
25
|
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
26
26
|
"typescript": "^5.5.4",
|
|
27
|
+
"vitest": "^4.0.18",
|
|
27
28
|
"vue-tsc": "^3.1.4"
|
|
28
29
|
},
|
|
29
30
|
"dependencies": {
|
|
30
31
|
"@types/json-schema": "^7.0.15"
|
|
31
32
|
},
|
|
32
33
|
"scripts": {
|
|
33
|
-
"build": "bk-cli-service build && vue-tsc --emitDeclarationOnly"
|
|
34
|
+
"build": "bk-cli-service build && vue-tsc --emitDeclarationOnly",
|
|
35
|
+
"test": "vitest run"
|
|
34
36
|
}
|
|
35
37
|
}
|