@blueking/chat-helper 0.0.1-beta.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 +1112 -0
- package/dist/agent/index.d.ts +2 -0
- package/dist/agent/index.ts.js +26 -0
- package/dist/agent/type.d.ts +87 -0
- package/dist/agent/type.ts.js +25 -0
- package/dist/agent/use-agent.d.ts +540 -0
- package/dist/agent/use-agent.ts.js +102 -0
- package/dist/event/ag-ui.d.ts +137 -0
- package/dist/event/ag-ui.ts.js +434 -0
- package/dist/event/index.d.ts +2 -0
- package/dist/event/index.ts.js +26 -0
- package/dist/event/type.d.ts +329 -0
- package/dist/event/type.ts.js +64 -0
- package/dist/http/fetch/fetch.d.ts +84 -0
- package/dist/http/fetch/fetch.ts.js +503 -0
- package/dist/http/fetch/index.d.ts +6 -0
- package/dist/http/fetch/index.ts.js +41 -0
- package/dist/http/index.d.ts +38 -0
- package/dist/http/index.ts.js +36 -0
- package/dist/http/module/agent.d.ts +9 -0
- package/dist/http/module/agent.ts.js +36 -0
- package/dist/http/module/index.d.ts +36 -0
- package/dist/http/module/index.ts.js +41 -0
- package/dist/http/module/message.d.ts +14 -0
- package/dist/http/module/message.ts.js +52 -0
- package/dist/http/module/session.d.ts +25 -0
- package/dist/http/module/session.ts.js +67 -0
- package/dist/http/transform/agent.d.ts +7 -0
- package/dist/http/transform/agent.ts.js +71 -0
- package/dist/http/transform/index.d.ts +3 -0
- package/dist/http/transform/index.ts.js +27 -0
- package/dist/http/transform/message.d.ts +13 -0
- package/dist/http/transform/message.ts.js +155 -0
- package/dist/http/transform/session.d.ts +37 -0
- package/dist/http/transform/session.ts.js +100 -0
- package/dist/index.d.ts +3363 -0
- package/dist/index.ts.js +40 -0
- package/dist/message/index.d.ts +2 -0
- package/dist/message/index.ts.js +26 -0
- package/dist/message/type.d.ts +277 -0
- package/dist/message/type.ts.js +67 -0
- package/dist/message/use-message.d.ts +912 -0
- package/dist/message/use-message.ts.js +87 -0
- package/dist/session/index.d.ts +2 -0
- package/dist/session/index.ts.js +26 -0
- package/dist/session/type.d.ts +61 -0
- package/dist/session/type.ts.js +25 -0
- package/dist/session/use-session.d.ts +1898 -0
- package/dist/session/use-session.ts.js +144 -0
- package/dist/type.d.ts +14 -0
- package/package.json +27 -0
|
@@ -0,0 +1,503 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Tencent is pleased to support the open source community by making
|
|
3
|
+
* 蓝鲸智云PaaS平台 (BlueKing PaaS) available.
|
|
4
|
+
*
|
|
5
|
+
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
|
|
6
|
+
*
|
|
7
|
+
* 蓝鲸智云PaaS平台 (BlueKing PaaS) is licensed under the MIT License.
|
|
8
|
+
*
|
|
9
|
+
* License for 蓝鲸智云PaaS平台 (BlueKing PaaS):
|
|
10
|
+
*
|
|
11
|
+
* ---------------------------------------------------
|
|
12
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
13
|
+
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
|
|
14
|
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
|
|
15
|
+
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
16
|
+
*
|
|
17
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
|
|
18
|
+
* the Software.
|
|
19
|
+
*
|
|
20
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
|
21
|
+
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
|
23
|
+
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
24
|
+
* IN THE SOFTWARE.
|
|
25
|
+
*/ // API 标准响应格式
|
|
26
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
27
|
+
try {
|
|
28
|
+
var info = gen[key](arg);
|
|
29
|
+
var value = info.value;
|
|
30
|
+
} catch (error) {
|
|
31
|
+
reject(error);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (info.done) {
|
|
35
|
+
resolve(value);
|
|
36
|
+
} else {
|
|
37
|
+
Promise.resolve(value).then(_next, _throw);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function _async_to_generator(fn) {
|
|
41
|
+
return function() {
|
|
42
|
+
var self = this, args = arguments;
|
|
43
|
+
return new Promise(function(resolve, reject) {
|
|
44
|
+
var gen = fn.apply(self, args);
|
|
45
|
+
function _next(value) {
|
|
46
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
47
|
+
}
|
|
48
|
+
function _throw(err) {
|
|
49
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
50
|
+
}
|
|
51
|
+
_next(undefined);
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function _define_property(obj, key, value) {
|
|
56
|
+
if (key in obj) {
|
|
57
|
+
Object.defineProperty(obj, key, {
|
|
58
|
+
value: value,
|
|
59
|
+
enumerable: true,
|
|
60
|
+
configurable: true,
|
|
61
|
+
writable: true
|
|
62
|
+
});
|
|
63
|
+
} else {
|
|
64
|
+
obj[key] = value;
|
|
65
|
+
}
|
|
66
|
+
return obj;
|
|
67
|
+
}
|
|
68
|
+
function _object_spread(target) {
|
|
69
|
+
for(var i = 1; i < arguments.length; i++){
|
|
70
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
71
|
+
var ownKeys = Object.keys(source);
|
|
72
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
73
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
74
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
ownKeys.forEach(function(key) {
|
|
78
|
+
_define_property(target, key, source[key]);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return target;
|
|
82
|
+
}
|
|
83
|
+
function ownKeys(object, enumerableOnly) {
|
|
84
|
+
var keys = Object.keys(object);
|
|
85
|
+
if (Object.getOwnPropertySymbols) {
|
|
86
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
87
|
+
if (enumerableOnly) {
|
|
88
|
+
symbols = symbols.filter(function(sym) {
|
|
89
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
keys.push.apply(keys, symbols);
|
|
93
|
+
}
|
|
94
|
+
return keys;
|
|
95
|
+
}
|
|
96
|
+
function _object_spread_props(target, source) {
|
|
97
|
+
source = source != null ? source : {};
|
|
98
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
99
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
100
|
+
} else {
|
|
101
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
102
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return target;
|
|
106
|
+
}
|
|
107
|
+
class InterceptorManager {
|
|
108
|
+
clear() {
|
|
109
|
+
this.handlers = [];
|
|
110
|
+
}
|
|
111
|
+
eject(id) {
|
|
112
|
+
if (this.handlers[id]) {
|
|
113
|
+
this.handlers[id] = null;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
forEach(fn) {
|
|
117
|
+
this.handlers.forEach((handler)=>{
|
|
118
|
+
if (handler !== null) {
|
|
119
|
+
fn(handler);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
use(fulfilled, rejected) {
|
|
124
|
+
this.handlers.push({
|
|
125
|
+
fulfilled,
|
|
126
|
+
rejected
|
|
127
|
+
});
|
|
128
|
+
return this.handlers.length - 1;
|
|
129
|
+
}
|
|
130
|
+
constructor(){
|
|
131
|
+
_define_property(this, "handlers", []);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
export class FetchClient {
|
|
135
|
+
// 应用响应拦截器的错误处理
|
|
136
|
+
applyResponseErrorInterceptors(error) {
|
|
137
|
+
let rejectedError = error;
|
|
138
|
+
this.interceptors.response.forEach((interceptor)=>{
|
|
139
|
+
if (interceptor.rejected) {
|
|
140
|
+
rejectedError = interceptor.rejected(rejectedError);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
return rejectedError;
|
|
144
|
+
}
|
|
145
|
+
// 创建新实例
|
|
146
|
+
create(config) {
|
|
147
|
+
return new FetchClient(mergeConfig(this.defaults, config || {}));
|
|
148
|
+
}
|
|
149
|
+
delete(url, params, config) {
|
|
150
|
+
return this.request(_object_spread_props(_object_spread({}, config), {
|
|
151
|
+
url,
|
|
152
|
+
method: 'DELETE',
|
|
153
|
+
params
|
|
154
|
+
}));
|
|
155
|
+
}
|
|
156
|
+
get(url, params, config) {
|
|
157
|
+
return this.request(_object_spread_props(_object_spread({}, config), {
|
|
158
|
+
url,
|
|
159
|
+
method: 'GET',
|
|
160
|
+
params
|
|
161
|
+
}));
|
|
162
|
+
}
|
|
163
|
+
head(url, params, config) {
|
|
164
|
+
return this.request(_object_spread_props(_object_spread({}, config), {
|
|
165
|
+
url,
|
|
166
|
+
method: 'HEAD',
|
|
167
|
+
params
|
|
168
|
+
}));
|
|
169
|
+
}
|
|
170
|
+
options(url, params, config) {
|
|
171
|
+
return this.request(_object_spread_props(_object_spread({}, config), {
|
|
172
|
+
url,
|
|
173
|
+
method: 'OPTIONS',
|
|
174
|
+
params
|
|
175
|
+
}));
|
|
176
|
+
}
|
|
177
|
+
patch(url, data, config) {
|
|
178
|
+
return this.request(_object_spread_props(_object_spread({}, config), {
|
|
179
|
+
url,
|
|
180
|
+
method: 'PATCH',
|
|
181
|
+
data
|
|
182
|
+
}));
|
|
183
|
+
}
|
|
184
|
+
post(url, data, config) {
|
|
185
|
+
return this.request(_object_spread_props(_object_spread({}, config), {
|
|
186
|
+
url,
|
|
187
|
+
method: 'POST',
|
|
188
|
+
data
|
|
189
|
+
}));
|
|
190
|
+
}
|
|
191
|
+
// 准备请求:合并配置、应用拦截器、构建 URL 和请求体
|
|
192
|
+
prepareRequest(config, isStream = false) {
|
|
193
|
+
// 合并配置
|
|
194
|
+
const mergedConfig = mergeConfig(this.defaults, config);
|
|
195
|
+
// 应用请求拦截器
|
|
196
|
+
let requestConfig = mergedConfig;
|
|
197
|
+
this.interceptors.request.forEach((interceptor)=>{
|
|
198
|
+
if (interceptor.fulfilled) {
|
|
199
|
+
try {
|
|
200
|
+
requestConfig = interceptor.fulfilled(requestConfig);
|
|
201
|
+
} catch (error) {
|
|
202
|
+
if (interceptor.rejected) {
|
|
203
|
+
throw interceptor.rejected(error);
|
|
204
|
+
}
|
|
205
|
+
throw error;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
// 构建完整 URL
|
|
210
|
+
let url = requestConfig.url || '';
|
|
211
|
+
if (requestConfig.baseURL) {
|
|
212
|
+
url = requestConfig.baseURL + url;
|
|
213
|
+
}
|
|
214
|
+
url = buildURL(url, requestConfig.params);
|
|
215
|
+
// 处理请求体
|
|
216
|
+
let body = getValue(requestConfig.data);
|
|
217
|
+
const headers = new Headers(getValue(requestConfig.headers));
|
|
218
|
+
// 流式请求设置 Accept 头
|
|
219
|
+
if (isStream && !headers.has('Accept')) {
|
|
220
|
+
headers.set('Accept', 'text/event-stream');
|
|
221
|
+
}
|
|
222
|
+
if (body !== undefined && body !== null) {
|
|
223
|
+
var _headers_get;
|
|
224
|
+
if (requestConfig.transformRequest) {
|
|
225
|
+
body = requestConfig.transformRequest(body, getValue(requestConfig.headers));
|
|
226
|
+
} else if (((_headers_get = headers.get('Content-Type')) === null || _headers_get === void 0 ? void 0 : _headers_get.includes('application/json')) && typeof body === 'object' && !(body instanceof FormData) && !(body instanceof Blob) && !(body instanceof ArrayBuffer)) {
|
|
227
|
+
body = JSON.stringify(body);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
// 创建 AbortController
|
|
231
|
+
const controller = requestConfig.controller ? requestConfig.controller : new AbortController();
|
|
232
|
+
return {
|
|
233
|
+
url,
|
|
234
|
+
headers,
|
|
235
|
+
body,
|
|
236
|
+
requestConfig,
|
|
237
|
+
controller
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
put(url, data, config) {
|
|
241
|
+
return this.request(_object_spread_props(_object_spread({}, config), {
|
|
242
|
+
url,
|
|
243
|
+
method: 'PUT',
|
|
244
|
+
data
|
|
245
|
+
}));
|
|
246
|
+
}
|
|
247
|
+
request(config) {
|
|
248
|
+
var _this = this;
|
|
249
|
+
return _async_to_generator(function*() {
|
|
250
|
+
// 准备请求
|
|
251
|
+
const { url, headers, body, requestConfig, controller } = _this.prepareRequest(config);
|
|
252
|
+
// 创建超时控制
|
|
253
|
+
const timeoutId = requestConfig.timeout && requestConfig.timeout > 0 ? setTimeout(()=>controller.abort(), requestConfig.timeout) : undefined;
|
|
254
|
+
try {
|
|
255
|
+
// 发送请求
|
|
256
|
+
const request = new Request(url, {
|
|
257
|
+
method: requestConfig.method,
|
|
258
|
+
headers,
|
|
259
|
+
body,
|
|
260
|
+
signal: controller.signal
|
|
261
|
+
});
|
|
262
|
+
const fetchResponse = yield fetch(request);
|
|
263
|
+
// 清除超时定时器
|
|
264
|
+
if (timeoutId) {
|
|
265
|
+
clearTimeout(timeoutId);
|
|
266
|
+
}
|
|
267
|
+
// 解析响应数据
|
|
268
|
+
let data;
|
|
269
|
+
const responseType = requestConfig.responseType || 'json';
|
|
270
|
+
try {
|
|
271
|
+
switch(responseType){
|
|
272
|
+
case 'json':
|
|
273
|
+
data = yield fetchResponse.json();
|
|
274
|
+
break;
|
|
275
|
+
case 'text':
|
|
276
|
+
data = yield fetchResponse.text();
|
|
277
|
+
break;
|
|
278
|
+
case 'blob':
|
|
279
|
+
data = yield fetchResponse.blob();
|
|
280
|
+
break;
|
|
281
|
+
case 'arrayBuffer':
|
|
282
|
+
data = yield fetchResponse.arrayBuffer();
|
|
283
|
+
break;
|
|
284
|
+
case 'formData':
|
|
285
|
+
data = yield fetchResponse.formData();
|
|
286
|
+
break;
|
|
287
|
+
default:
|
|
288
|
+
data = yield fetchResponse.json();
|
|
289
|
+
}
|
|
290
|
+
} catch (_error) {
|
|
291
|
+
data = null;
|
|
292
|
+
}
|
|
293
|
+
// 应用响应转换
|
|
294
|
+
if (requestConfig.transformResponse) {
|
|
295
|
+
data = requestConfig.transformResponse(data);
|
|
296
|
+
}
|
|
297
|
+
// 构建响应对象
|
|
298
|
+
const response = {
|
|
299
|
+
data: data,
|
|
300
|
+
status: fetchResponse.status,
|
|
301
|
+
statusText: fetchResponse.statusText,
|
|
302
|
+
headers: fetchResponse.headers,
|
|
303
|
+
config: requestConfig,
|
|
304
|
+
request
|
|
305
|
+
};
|
|
306
|
+
// 验证状态码
|
|
307
|
+
const validateStatus = requestConfig.validateStatus || _this.defaults.validateStatus;
|
|
308
|
+
if (!validateStatus(fetchResponse.status)) {
|
|
309
|
+
throw createError(`Request failed with status code ${fetchResponse.status}`, requestConfig, `ERR_BAD_RESPONSE`, request, response);
|
|
310
|
+
}
|
|
311
|
+
// 应用响应拦截器
|
|
312
|
+
let finalResponse = response;
|
|
313
|
+
_this.interceptors.response.forEach((interceptor)=>{
|
|
314
|
+
if (interceptor.fulfilled) {
|
|
315
|
+
try {
|
|
316
|
+
finalResponse = interceptor.fulfilled(finalResponse);
|
|
317
|
+
} catch (error) {
|
|
318
|
+
if (interceptor.rejected) {
|
|
319
|
+
throw interceptor.rejected(error);
|
|
320
|
+
}
|
|
321
|
+
throw error;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
// 等待所有异步拦截器完成
|
|
326
|
+
if (finalResponse instanceof Promise) {
|
|
327
|
+
finalResponse = yield finalResponse;
|
|
328
|
+
}
|
|
329
|
+
// 检查业务逻辑状态码
|
|
330
|
+
const apiResponse = finalResponse.data;
|
|
331
|
+
if (![
|
|
332
|
+
0,
|
|
333
|
+
'success'
|
|
334
|
+
].includes(apiResponse.code)) {
|
|
335
|
+
throw createError(apiResponse.message, requestConfig, apiResponse.code, request, finalResponse);
|
|
336
|
+
}
|
|
337
|
+
return apiResponse.data;
|
|
338
|
+
} catch (error) {
|
|
339
|
+
// 清除超时定时器
|
|
340
|
+
if (timeoutId) {
|
|
341
|
+
clearTimeout(timeoutId);
|
|
342
|
+
}
|
|
343
|
+
// 处理中断错误
|
|
344
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
|
345
|
+
const requestError = createError('Request timeout', requestConfig, 'ECONNABORTED', undefined, undefined);
|
|
346
|
+
throw _this.applyResponseErrorInterceptors(requestError);
|
|
347
|
+
}
|
|
348
|
+
// 处理其他错误
|
|
349
|
+
const requestError = error.isAxiosError === true ? error : createError(error.message, requestConfig, error.code, undefined, undefined);
|
|
350
|
+
throw _this.applyResponseErrorInterceptors(requestError);
|
|
351
|
+
}
|
|
352
|
+
})();
|
|
353
|
+
}
|
|
354
|
+
// SSE 流式请求便捷方法
|
|
355
|
+
stream(url, config) {
|
|
356
|
+
return this.streamRequest(_object_spread_props(_object_spread({}, config), {
|
|
357
|
+
url
|
|
358
|
+
}));
|
|
359
|
+
}
|
|
360
|
+
// SSE 流式请求
|
|
361
|
+
streamRequest(config) {
|
|
362
|
+
var _this = this;
|
|
363
|
+
return _async_to_generator(function*() {
|
|
364
|
+
// 准备请求(标记为流式请求)
|
|
365
|
+
const { url, headers, body, requestConfig, controller } = _this.prepareRequest(config, true);
|
|
366
|
+
// 发送请求
|
|
367
|
+
const request = new Request(url, {
|
|
368
|
+
method: requestConfig.method || 'GET',
|
|
369
|
+
headers,
|
|
370
|
+
body,
|
|
371
|
+
signal: controller.signal
|
|
372
|
+
});
|
|
373
|
+
try {
|
|
374
|
+
var // 触发 onStart 回调
|
|
375
|
+
_config_onStart, _fetchResponse_body;
|
|
376
|
+
const fetchResponse = yield fetch(request);
|
|
377
|
+
// 验证状态码
|
|
378
|
+
const validateStatus = requestConfig.validateStatus || _this.defaults.validateStatus;
|
|
379
|
+
if (!validateStatus(fetchResponse.status)) {
|
|
380
|
+
var _config_onError;
|
|
381
|
+
const error = createError(`Request failed with status code ${fetchResponse.status}`, requestConfig, `ERR_BAD_RESPONSE`, request, undefined);
|
|
382
|
+
(_config_onError = config.onError) === null || _config_onError === void 0 ? void 0 : _config_onError.call(config, error);
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
(_config_onStart = config.onStart) === null || _config_onStart === void 0 ? void 0 : _config_onStart.call(config);
|
|
386
|
+
// 获取 reader
|
|
387
|
+
const reader = (_fetchResponse_body = fetchResponse.body) === null || _fetchResponse_body === void 0 ? void 0 : _fetchResponse_body.pipeThrough(new window.TextDecoderStream()).getReader();
|
|
388
|
+
if (!reader) {
|
|
389
|
+
var _config_onError1;
|
|
390
|
+
const error = new Error('Response body is not readable');
|
|
391
|
+
(_config_onError1 = config.onError) === null || _config_onError1 === void 0 ? void 0 : _config_onError1.call(config, error);
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
// 临时存储数据
|
|
395
|
+
let temp = '';
|
|
396
|
+
// eslint-disable-next-line no-constant-condition
|
|
397
|
+
while(true){
|
|
398
|
+
const { value, done } = yield reader.read();
|
|
399
|
+
// 接口完成
|
|
400
|
+
if (done) {
|
|
401
|
+
var _config_onDone;
|
|
402
|
+
(_config_onDone = config.onDone) === null || _config_onDone === void 0 ? void 0 : _config_onDone.call(config);
|
|
403
|
+
break;
|
|
404
|
+
}
|
|
405
|
+
const values = (temp + value.toString()).split('\n');
|
|
406
|
+
values.forEach((value)=>{
|
|
407
|
+
const item = value.replace('data:', '').trim();
|
|
408
|
+
if (item.endsWith('}')) {
|
|
409
|
+
var _config_onMessage;
|
|
410
|
+
const json = JSON.parse(item);
|
|
411
|
+
(_config_onMessage = config.onMessage) === null || _config_onMessage === void 0 ? void 0 : _config_onMessage.call(config, json);
|
|
412
|
+
} else if (item) {
|
|
413
|
+
temp = item;
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
} catch (error) {
|
|
418
|
+
if (error instanceof Error) {
|
|
419
|
+
if (error.name === 'AbortError') {
|
|
420
|
+
var _config_onDone1;
|
|
421
|
+
(_config_onDone1 = config.onDone) === null || _config_onDone1 === void 0 ? void 0 : _config_onDone1.call(config);
|
|
422
|
+
} else {
|
|
423
|
+
var _config_onError2;
|
|
424
|
+
(_config_onError2 = config.onError) === null || _config_onError2 === void 0 ? void 0 : _config_onError2.call(config, error);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
throw error;
|
|
428
|
+
}
|
|
429
|
+
})();
|
|
430
|
+
}
|
|
431
|
+
constructor(config = {}){
|
|
432
|
+
_define_property(this, "defaults", void 0);
|
|
433
|
+
_define_property(this, "interceptors", void 0);
|
|
434
|
+
this.defaults = _object_spread({
|
|
435
|
+
method: 'GET',
|
|
436
|
+
headers: {
|
|
437
|
+
'Content-Type': 'application/json'
|
|
438
|
+
},
|
|
439
|
+
timeout: 30000,
|
|
440
|
+
responseType: 'json',
|
|
441
|
+
credentials: 'include',
|
|
442
|
+
mode: 'cors',
|
|
443
|
+
validateStatus: (status)=>status >= 200 && status < 300
|
|
444
|
+
}, config);
|
|
445
|
+
this.interceptors = {
|
|
446
|
+
request: new InterceptorManager(),
|
|
447
|
+
response: new InterceptorManager()
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
// 构建完整 URL
|
|
452
|
+
function buildURL(url, params) {
|
|
453
|
+
if (!params) return url;
|
|
454
|
+
const searchParams = new URLSearchParams();
|
|
455
|
+
Object.keys(params).forEach((key)=>{
|
|
456
|
+
const value = params[key];
|
|
457
|
+
if (value !== null && value !== undefined) {
|
|
458
|
+
if (Array.isArray(value)) {
|
|
459
|
+
value.forEach((v)=>searchParams.append(key, String(v)));
|
|
460
|
+
} else {
|
|
461
|
+
searchParams.append(key, String(value));
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
const queryString = searchParams.toString();
|
|
466
|
+
if (queryString) {
|
|
467
|
+
const separator = url.includes('?') ? '&' : '?';
|
|
468
|
+
return `${url}${separator}${queryString}`;
|
|
469
|
+
}
|
|
470
|
+
return url;
|
|
471
|
+
}
|
|
472
|
+
// 创建错误对象
|
|
473
|
+
function createError(message, config, code, request, response) {
|
|
474
|
+
const error = new Error(message);
|
|
475
|
+
error.config = config;
|
|
476
|
+
error.code = String(code);
|
|
477
|
+
error.request = request;
|
|
478
|
+
error.response = response;
|
|
479
|
+
error.isAxiosError = true;
|
|
480
|
+
return error;
|
|
481
|
+
}
|
|
482
|
+
// 获取值
|
|
483
|
+
function getValue(value) {
|
|
484
|
+
return typeof value === 'function' ? value() : value;
|
|
485
|
+
}
|
|
486
|
+
// 合并配置
|
|
487
|
+
function mergeConfig(config1, config2) {
|
|
488
|
+
const output = _object_spread({}, config1);
|
|
489
|
+
for(const key in config2){
|
|
490
|
+
const value2 = config2[key];
|
|
491
|
+
if (value2 && typeof value2 === 'object' && !Array.isArray(value2)) {
|
|
492
|
+
const value1 = config1[key];
|
|
493
|
+
output[key] = mergeConfig(value1 || {}, value2);
|
|
494
|
+
} else {
|
|
495
|
+
output[key] = value2;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
return output;
|
|
499
|
+
}
|
|
500
|
+
// 创建默认实例
|
|
501
|
+
const fetchClient = new FetchClient();
|
|
502
|
+
// 导出默认实例
|
|
503
|
+
export default fetchClient;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Tencent is pleased to support the open source community by making
|
|
3
|
+
* 蓝鲸智云PaaS平台 (BlueKing PaaS) available.
|
|
4
|
+
*
|
|
5
|
+
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
|
|
6
|
+
*
|
|
7
|
+
* 蓝鲸智云PaaS平台 (BlueKing PaaS) is licensed under the MIT License.
|
|
8
|
+
*
|
|
9
|
+
* License for 蓝鲸智云PaaS平台 (BlueKing PaaS):
|
|
10
|
+
*
|
|
11
|
+
* ---------------------------------------------------
|
|
12
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
13
|
+
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
|
|
14
|
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
|
|
15
|
+
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
16
|
+
*
|
|
17
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
|
|
18
|
+
* the Software.
|
|
19
|
+
*
|
|
20
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
|
21
|
+
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
|
23
|
+
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
24
|
+
* IN THE SOFTWARE.
|
|
25
|
+
*/ import { FetchClient } from './fetch.ts.js';
|
|
26
|
+
export const useFetch = (options)=>{
|
|
27
|
+
var _options_interceptors, _options_interceptors1;
|
|
28
|
+
const fetchClient = new FetchClient({
|
|
29
|
+
baseURL: options.requestData.urlPrefix
|
|
30
|
+
});
|
|
31
|
+
// 用户定义拦截器
|
|
32
|
+
if ((_options_interceptors = options.interceptors) === null || _options_interceptors === void 0 ? void 0 : _options_interceptors.request) {
|
|
33
|
+
fetchClient.interceptors.request.use(options.interceptors.request);
|
|
34
|
+
}
|
|
35
|
+
if ((_options_interceptors1 = options.interceptors) === null || _options_interceptors1 === void 0 ? void 0 : _options_interceptors1.response) {
|
|
36
|
+
fetchClient.interceptors.response.use(options.interceptors.response);
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
fetchClient
|
|
40
|
+
};
|
|
41
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { IUseChatHelperOptions } from '../type';
|
|
2
|
+
export * from './transform';
|
|
3
|
+
/**
|
|
4
|
+
* 使用 HTTP 模块
|
|
5
|
+
* @param options - 选项
|
|
6
|
+
* @returns HTTP 模块
|
|
7
|
+
*/
|
|
8
|
+
export declare const useHttp: (options: IUseChatHelperOptions) => {
|
|
9
|
+
agent: {
|
|
10
|
+
getAgentInfo: (config?: import("./fetch").RequestConfig) => Promise<import("..").IAgentInfo>;
|
|
11
|
+
};
|
|
12
|
+
session: {
|
|
13
|
+
clearSession: (sessionCode: string, config?: import("./fetch").RequestConfig) => Promise<unknown>;
|
|
14
|
+
getSessions: (config?: import("./fetch").RequestConfig) => Promise<import("..").ISession<unknown, unknown>[]>;
|
|
15
|
+
plusSession: (data: import("..").ISession, config?: import("./fetch").RequestConfig) => Promise<import("..").ISession<unknown, unknown>>;
|
|
16
|
+
modifySession: (data: import("..").ISession, config?: import("./fetch").RequestConfig) => Promise<import("..").ISession<unknown, unknown>>;
|
|
17
|
+
deleteSession: (sessionCode: string, config?: import("./fetch").RequestConfig) => Promise<unknown>;
|
|
18
|
+
batchDeleteSessions: (sessionCodes: string[], config?: import("./fetch").RequestConfig) => Promise<number>;
|
|
19
|
+
getSession: (sessionCode: string, config?: import("./fetch").RequestConfig) => Promise<import("..").ISession<unknown, unknown>>;
|
|
20
|
+
postSessionFeedback: (data: import("..").ISessionFeedback, config?: import("./fetch").RequestConfig) => Promise<{
|
|
21
|
+
sessionCode: string;
|
|
22
|
+
sessionContentIds: number[];
|
|
23
|
+
rate: number;
|
|
24
|
+
comment: string;
|
|
25
|
+
labels: string[];
|
|
26
|
+
}>;
|
|
27
|
+
getSessionFeedbackLabels: (rate: number, config?: import("./fetch").RequestConfig) => Promise<string[]>;
|
|
28
|
+
renameSession: (sessionCode: string, config?: import("./fetch").RequestConfig) => Promise<import("..").ISession<unknown, unknown>>;
|
|
29
|
+
};
|
|
30
|
+
message: {
|
|
31
|
+
getMessages: (sessionCode: string, config?: import("./fetch").RequestConfig) => Promise<import("..").IMessage[]>;
|
|
32
|
+
plusMessage: (data: import("..").IMessage, config?: import("./fetch").RequestConfig) => Promise<import("..").IMessageApi>;
|
|
33
|
+
modifyMessage: (data: import("..").IMessage, config?: import("./fetch").RequestConfig) => Promise<import("..").IMessageApi>;
|
|
34
|
+
deleteMessage: (id: number, config?: import("./fetch").RequestConfig) => Promise<import("..").IMessageApi>;
|
|
35
|
+
batchDeleteMessages: (ids: number[], config?: import("./fetch").RequestConfig) => Promise<number>;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export type IHttpModule = ReturnType<typeof useHttp>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Tencent is pleased to support the open source community by making
|
|
3
|
+
* 蓝鲸智云PaaS平台 (BlueKing PaaS) available.
|
|
4
|
+
*
|
|
5
|
+
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
|
|
6
|
+
*
|
|
7
|
+
* 蓝鲸智云PaaS平台 (BlueKing PaaS) is licensed under the MIT License.
|
|
8
|
+
*
|
|
9
|
+
* License for 蓝鲸智云PaaS平台 (BlueKing PaaS):
|
|
10
|
+
*
|
|
11
|
+
* ---------------------------------------------------
|
|
12
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
13
|
+
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
|
|
14
|
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
|
|
15
|
+
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
16
|
+
*
|
|
17
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
|
|
18
|
+
* the Software.
|
|
19
|
+
*
|
|
20
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
|
21
|
+
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
|
23
|
+
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
24
|
+
* IN THE SOFTWARE.
|
|
25
|
+
*/ import { useFetch } from './fetch/index.ts.js';
|
|
26
|
+
import { useModule } from './module/index.ts.js';
|
|
27
|
+
export * from './transform/index.ts.js';
|
|
28
|
+
/**
|
|
29
|
+
* 使用 HTTP 模块
|
|
30
|
+
* @param options - 选项
|
|
31
|
+
* @returns HTTP 模块
|
|
32
|
+
*/ export const useHttp = (options)=>{
|
|
33
|
+
const { fetchClient } = useFetch(options);
|
|
34
|
+
const http = useModule(fetchClient);
|
|
35
|
+
return http;
|
|
36
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { FetchClient, RequestConfig } from '../fetch';
|
|
2
|
+
/**
|
|
3
|
+
* agent 相关 http 接口
|
|
4
|
+
* @param fetchClient - 请求客户端
|
|
5
|
+
* @returns agent 相关 http 接口
|
|
6
|
+
*/
|
|
7
|
+
export declare const useAgent: (fetchClient: FetchClient) => {
|
|
8
|
+
getAgentInfo: (config?: RequestConfig) => Promise<import("../../agent/type").IAgentInfo>;
|
|
9
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Tencent is pleased to support the open source community by making
|
|
3
|
+
* 蓝鲸智云PaaS平台 (BlueKing PaaS) available.
|
|
4
|
+
*
|
|
5
|
+
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
|
|
6
|
+
*
|
|
7
|
+
* 蓝鲸智云PaaS平台 (BlueKing PaaS) is licensed under the MIT License.
|
|
8
|
+
*
|
|
9
|
+
* License for 蓝鲸智云PaaS平台 (BlueKing PaaS):
|
|
10
|
+
*
|
|
11
|
+
* ---------------------------------------------------
|
|
12
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
13
|
+
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
|
|
14
|
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
|
|
15
|
+
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
16
|
+
*
|
|
17
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
|
|
18
|
+
* the Software.
|
|
19
|
+
*
|
|
20
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
|
21
|
+
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
|
23
|
+
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
24
|
+
* IN THE SOFTWARE.
|
|
25
|
+
*/ import { transferAgentInfoApi2AgentInfo } from '../transform/agent.ts.js';
|
|
26
|
+
/**
|
|
27
|
+
* agent 相关 http 接口
|
|
28
|
+
* @param fetchClient - 请求客户端
|
|
29
|
+
* @returns agent 相关 http 接口
|
|
30
|
+
*/ export const useAgent = (fetchClient)=>{
|
|
31
|
+
// 获取 agent 信息
|
|
32
|
+
const getAgentInfo = (config)=>fetchClient.get('agent/info/', undefined, config).then(transferAgentInfoApi2AgentInfo);
|
|
33
|
+
return {
|
|
34
|
+
getAgentInfo
|
|
35
|
+
};
|
|
36
|
+
};
|