@blueking/chat-helper 0.0.12-beta.1 → 0.0.12-beta.10
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/dist/agent/use-agent.d.ts +1276 -4
- package/dist/agent/use-agent.ts.js +136 -19
- package/dist/event/ag-ui.d.ts +14 -2
- package/dist/event/ag-ui.ts.js +75 -7
- package/dist/event/type.d.ts +90 -24
- package/dist/event/type.ts.js +44 -16
- package/dist/http/fetch/fetch.d.ts +20 -0
- package/dist/http/fetch/fetch.ts.js +67 -18
- package/dist/http/index.d.ts +14 -3
- package/dist/http/index.ts.js +2 -1
- package/dist/http/module/index.d.ts +12 -3
- package/dist/http/module/message.d.ts +6 -3
- package/dist/http/module/message.ts.js +18 -1
- package/dist/http/module/session.d.ts +8 -2
- package/dist/http/module/session.ts.js +47 -8
- package/dist/http/transform/message.ts.js +10 -0
- package/dist/index.d.ts +8867 -18
- package/dist/index.ts.js +2 -1
- package/dist/message/type.d.ts +26 -5
- package/dist/message/type.ts.js +8 -0
- package/dist/message/use-message.d.ts +2524 -4
- package/dist/session/type.d.ts +19 -0
- package/dist/session/use-session.d.ts +5056 -10
- package/dist/session/use-session.ts.js +68 -5
- package/package.json +4 -1
|
@@ -79,7 +79,8 @@ function _object_spread(target) {
|
|
|
79
79
|
}
|
|
80
80
|
return target;
|
|
81
81
|
}
|
|
82
|
-
import { ref } from 'vue';
|
|
82
|
+
import { computed, ref } from 'vue';
|
|
83
|
+
/** 会话列表默认每页条数 */ const DEFAULT_PAGE_SIZE = 20;
|
|
83
84
|
/**
|
|
84
85
|
* 使用会话模块,主要做业务的组合
|
|
85
86
|
* @param mediator - 中介者模块,用于获取其他模块的引用
|
|
@@ -87,13 +88,18 @@ import { ref } from 'vue';
|
|
|
87
88
|
*/ export const useSession = (mediator)=>{
|
|
88
89
|
const list = ref([]);
|
|
89
90
|
const current = ref(null);
|
|
91
|
+
const page = ref(0);
|
|
92
|
+
const numPages = ref(0);
|
|
93
|
+
const count = ref(0);
|
|
90
94
|
const isCurrentLoading = ref(false);
|
|
91
95
|
const isListLoading = ref(false);
|
|
96
|
+
const isLoadingMore = ref(false);
|
|
92
97
|
const isCreateLoading = ref(false);
|
|
93
98
|
const isUpdateLoading = ref(false);
|
|
94
99
|
const isDeleteLoading = ref(false);
|
|
95
100
|
const isBatchDeleteLoading = ref(false);
|
|
96
101
|
const isRenameLoading = ref(false);
|
|
102
|
+
const hasMore = computed(()=>page.value > 0 && page.value < numPages.value);
|
|
97
103
|
/**
|
|
98
104
|
* 更新 list 中的 session,并同步更新 current
|
|
99
105
|
* @param session - Partial session
|
|
@@ -107,16 +113,56 @@ import { ref } from 'vue';
|
|
|
107
113
|
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
114
|
}
|
|
109
115
|
};
|
|
110
|
-
|
|
116
|
+
/**
|
|
117
|
+
* 拉取会话列表(默认第 1 页并替换本地 list)
|
|
118
|
+
*/ const getSessions = (params)=>{
|
|
111
119
|
var _mediator_http;
|
|
112
120
|
isListLoading.value = true;
|
|
113
|
-
|
|
114
|
-
|
|
121
|
+
var _params_page, _params_page_size;
|
|
122
|
+
const requestParams = {
|
|
123
|
+
page: (_params_page = params === null || params === void 0 ? void 0 : params.page) !== null && _params_page !== void 0 ? _params_page : 1,
|
|
124
|
+
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
|
|
125
|
+
};
|
|
126
|
+
return (_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.session.getSessions(requestParams).then((res)=>{
|
|
127
|
+
list.value = res.results;
|
|
128
|
+
page.value = res.page;
|
|
129
|
+
numPages.value = res.numPages;
|
|
130
|
+
count.value = res.count;
|
|
115
131
|
}).finally(()=>{
|
|
116
132
|
isListLoading.value = false;
|
|
117
133
|
});
|
|
118
134
|
};
|
|
119
135
|
/**
|
|
136
|
+
* 加载下一页会话并追加到 list(按 sessionCode 去重)
|
|
137
|
+
*/ const loadMoreSessions = function() {
|
|
138
|
+
var _ref = _async_to_generator(function*(pageSize = DEFAULT_PAGE_SIZE) {
|
|
139
|
+
if (!hasMore.value || isListLoading.value || isLoadingMore.value) return;
|
|
140
|
+
isLoadingMore.value = true;
|
|
141
|
+
try {
|
|
142
|
+
var _mediator_http;
|
|
143
|
+
const res = yield (_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.session.getSessions({
|
|
144
|
+
page: page.value + 1,
|
|
145
|
+
page_size: pageSize
|
|
146
|
+
});
|
|
147
|
+
if (!res) return;
|
|
148
|
+
const existing = new Set(list.value.map((s)=>s.sessionCode));
|
|
149
|
+
const appended = res.results.filter((s)=>!existing.has(s.sessionCode));
|
|
150
|
+
list.value = [
|
|
151
|
+
...list.value,
|
|
152
|
+
...appended
|
|
153
|
+
];
|
|
154
|
+
page.value = res.page;
|
|
155
|
+
numPages.value = res.numPages;
|
|
156
|
+
count.value = res.count;
|
|
157
|
+
} finally{
|
|
158
|
+
isLoadingMore.value = false;
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
return function loadMoreSessions() {
|
|
162
|
+
return _ref.apply(this, arguments);
|
|
163
|
+
};
|
|
164
|
+
}();
|
|
165
|
+
/**
|
|
120
166
|
* 切换会话
|
|
121
167
|
* @param sessionCode - 会话编码
|
|
122
168
|
* @param options - 选项
|
|
@@ -138,10 +184,12 @@ import { ref } from 'vue';
|
|
|
138
184
|
// 默认加载消息,但允许跳过(新会话消息必定为空,无需加载)
|
|
139
185
|
if (shouldLoadMessages) {
|
|
140
186
|
var _mediator_message, // 继续聊天
|
|
141
|
-
_mediator_agent1
|
|
187
|
+
_mediator_agent1, // 轮询接口,判断是否可以继续聊天
|
|
188
|
+
_mediator_agent2;
|
|
142
189
|
// 获取会话内容
|
|
143
190
|
yield (_mediator_message = mediator.message) === null || _mediator_message === void 0 ? void 0 : _mediator_message.getMessages(sessionCode);
|
|
144
191
|
(_mediator_agent1 = mediator.agent) === null || _mediator_agent1 === void 0 ? void 0 : _mediator_agent1.resumeStreamingChat(sessionCode);
|
|
192
|
+
(_mediator_agent2 = mediator.agent) === null || _mediator_agent2 === void 0 ? void 0 : _mediator_agent2.pollResumeSession(sessionCode);
|
|
145
193
|
} else {
|
|
146
194
|
// 新会话,清空消息列表
|
|
147
195
|
if (mediator.message) {
|
|
@@ -175,6 +223,7 @@ import { ref } from 'vue';
|
|
|
175
223
|
const res = yield (_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.session.plusSession(session);
|
|
176
224
|
if (res) {
|
|
177
225
|
list.value.unshift(res); // 新会话插入到列表头部
|
|
226
|
+
count.value += 1;
|
|
178
227
|
var _options_loadMessages;
|
|
179
228
|
// 新会话默认不加载消息(消息必定为空),优化 UX
|
|
180
229
|
yield chooseSession(res.sessionCode, {
|
|
@@ -205,6 +254,7 @@ import { ref } from 'vue';
|
|
|
205
254
|
var _mediator_http, _current_value, _list_value_;
|
|
206
255
|
yield (_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.session.deleteSession(sessionCode);
|
|
207
256
|
list.value = list.value.filter((item)=>item.sessionCode !== sessionCode);
|
|
257
|
+
count.value = Math.max(0, count.value - 1);
|
|
208
258
|
// 如果当前会话被删除,选择第一个会话
|
|
209
259
|
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)) {
|
|
210
260
|
yield chooseSession(list.value[0].sessionCode);
|
|
@@ -228,7 +278,10 @@ import { ref } from 'vue';
|
|
|
228
278
|
var _mediator_http;
|
|
229
279
|
yield (_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.session.batchDeleteSessions(sessionCodes);
|
|
230
280
|
const deletedSet = new Set(sessionCodes);
|
|
281
|
+
const beforeLength = list.value.length;
|
|
231
282
|
list.value = list.value.filter((item)=>!deletedSet.has(item.sessionCode));
|
|
283
|
+
const removedCount = beforeLength - list.value.length;
|
|
284
|
+
count.value = Math.max(0, count.value - removedCount);
|
|
232
285
|
if (current.value && deletedSet.has(current.value.sessionCode)) {
|
|
233
286
|
if (list.value.length > 0) {
|
|
234
287
|
yield chooseSession(list.value[0].sessionCode);
|
|
@@ -282,8 +335,12 @@ import { ref } from 'vue';
|
|
|
282
335
|
*/ const reset = ()=>{
|
|
283
336
|
list.value = [];
|
|
284
337
|
current.value = null;
|
|
338
|
+
page.value = 0;
|
|
339
|
+
numPages.value = 0;
|
|
340
|
+
count.value = 0;
|
|
285
341
|
isCurrentLoading.value = false;
|
|
286
342
|
isListLoading.value = false;
|
|
343
|
+
isLoadingMore.value = false;
|
|
287
344
|
isCreateLoading.value = false;
|
|
288
345
|
isUpdateLoading.value = false;
|
|
289
346
|
isDeleteLoading.value = false;
|
|
@@ -293,13 +350,19 @@ import { ref } from 'vue';
|
|
|
293
350
|
return {
|
|
294
351
|
list,
|
|
295
352
|
current,
|
|
353
|
+
page,
|
|
354
|
+
numPages,
|
|
355
|
+
count,
|
|
356
|
+
hasMore,
|
|
296
357
|
isCurrentLoading,
|
|
297
358
|
isListLoading,
|
|
359
|
+
isLoadingMore,
|
|
298
360
|
isCreateLoading,
|
|
299
361
|
isUpdateLoading,
|
|
300
362
|
isDeleteLoading,
|
|
301
363
|
isBatchDeleteLoading,
|
|
302
364
|
getSessions,
|
|
365
|
+
loadMoreSessions,
|
|
303
366
|
chooseSession,
|
|
304
367
|
getSession,
|
|
305
368
|
createSession,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blueking/chat-helper",
|
|
3
|
-
"version": "0.0.12-beta.
|
|
3
|
+
"version": "0.0.12-beta.10",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.ts.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -26,6 +26,9 @@
|
|
|
26
26
|
"typescript": "^5.5.4",
|
|
27
27
|
"vue-tsc": "^3.1.4"
|
|
28
28
|
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@types/json-schema": "^7.0.15"
|
|
31
|
+
},
|
|
29
32
|
"scripts": {
|
|
30
33
|
"build": "bk-cli-service build && vue-tsc --emitDeclarationOnly"
|
|
31
34
|
}
|