@blueking/chat-helper 0.0.1-beta.6 → 0.0.1-beta.7
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 +1 -1
- package/dist/agent/use-agent.d.ts +36 -2
- package/dist/agent/use-agent.ts.js +41 -9
- package/dist/event/ag-ui.d.ts +3 -1
- package/dist/event/ag-ui.ts.js +8 -7
- package/dist/http/fetch/fetch.d.ts +32 -32
- package/dist/http/fetch/fetch.ts.js +1 -1
- package/dist/http/index.d.ts +17 -16
- package/dist/http/index.ts.js +1 -0
- package/dist/http/module/agent.d.ts +2 -2
- package/dist/http/module/index.d.ts +16 -16
- package/dist/http/module/message.d.ts +6 -6
- package/dist/http/module/message.ts.js +3 -2
- package/dist/http/module/session.d.ts +11 -11
- package/dist/http/transform/message.ts.js +2 -0
- package/dist/index.d.ts +256 -18
- package/dist/message/type.d.ts +2 -0
- package/dist/message/use-message.d.ts +69 -1
- package/dist/message/use-message.ts.js +8 -3
- package/dist/session/use-session.d.ts +136 -0
- package/dist/type.d.ts +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IHttpModule } from '../http';
|
|
1
|
+
import type { IHttpModule, IRequestConfig } from '../http';
|
|
2
2
|
import type { IMessageModule } from '../message';
|
|
3
3
|
import type { IUseChatHelperOptions } from '../type';
|
|
4
4
|
import type { IAgentInfo } from './type';
|
|
@@ -88,6 +88,7 @@ export declare const useAgent: (options: IUseChatHelperOptions, http: IHttpModul
|
|
|
88
88
|
})[];
|
|
89
89
|
id: number;
|
|
90
90
|
property?: Record<string, unknown>;
|
|
91
|
+
sessionCode: string;
|
|
91
92
|
status?: import("../message").MessageStatus;
|
|
92
93
|
} | {
|
|
93
94
|
content: {
|
|
@@ -99,6 +100,7 @@ export declare const useAgent: (options: IUseChatHelperOptions, http: IHttpModul
|
|
|
99
100
|
role: import("../message").MessageRole.Guide;
|
|
100
101
|
id: number;
|
|
101
102
|
property?: Record<string, unknown>;
|
|
103
|
+
sessionCode: string;
|
|
102
104
|
status?: import("../message").MessageStatus;
|
|
103
105
|
} | {
|
|
104
106
|
content: {
|
|
@@ -110,6 +112,7 @@ export declare const useAgent: (options: IUseChatHelperOptions, http: IHttpModul
|
|
|
110
112
|
role: import("../message").MessageRole.HiddenAssistant;
|
|
111
113
|
id: number;
|
|
112
114
|
property?: Record<string, unknown>;
|
|
115
|
+
sessionCode: string;
|
|
113
116
|
status?: import("../message").MessageStatus;
|
|
114
117
|
} | {
|
|
115
118
|
content: {
|
|
@@ -121,6 +124,7 @@ export declare const useAgent: (options: IUseChatHelperOptions, http: IHttpModul
|
|
|
121
124
|
role: import("../message").MessageRole.HiddenGuide;
|
|
122
125
|
id: number;
|
|
123
126
|
property?: Record<string, unknown>;
|
|
127
|
+
sessionCode: string;
|
|
124
128
|
status?: import("../message").MessageStatus;
|
|
125
129
|
} | {
|
|
126
130
|
content: {
|
|
@@ -132,6 +136,7 @@ export declare const useAgent: (options: IUseChatHelperOptions, http: IHttpModul
|
|
|
132
136
|
role: import("../message").MessageRole.Hidden;
|
|
133
137
|
id: number;
|
|
134
138
|
property?: Record<string, unknown>;
|
|
139
|
+
sessionCode: string;
|
|
135
140
|
status?: import("../message").MessageStatus;
|
|
136
141
|
} | {
|
|
137
142
|
content: {
|
|
@@ -143,6 +148,7 @@ export declare const useAgent: (options: IUseChatHelperOptions, http: IHttpModul
|
|
|
143
148
|
role: import("../message").MessageRole.HiddenSystem;
|
|
144
149
|
id: number;
|
|
145
150
|
property?: Record<string, unknown>;
|
|
151
|
+
sessionCode: string;
|
|
146
152
|
status?: import("../message").MessageStatus;
|
|
147
153
|
} | {
|
|
148
154
|
content: {
|
|
@@ -154,6 +160,7 @@ export declare const useAgent: (options: IUseChatHelperOptions, http: IHttpModul
|
|
|
154
160
|
role: import("../message").MessageRole.HiddenUser;
|
|
155
161
|
id: number;
|
|
156
162
|
property?: Record<string, unknown>;
|
|
163
|
+
sessionCode: string;
|
|
157
164
|
status?: import("../message").MessageStatus;
|
|
158
165
|
} | {
|
|
159
166
|
content: {
|
|
@@ -165,6 +172,7 @@ export declare const useAgent: (options: IUseChatHelperOptions, http: IHttpModul
|
|
|
165
172
|
role: import("../message").MessageRole.Info;
|
|
166
173
|
id: number;
|
|
167
174
|
property?: Record<string, unknown>;
|
|
175
|
+
sessionCode: string;
|
|
168
176
|
status?: import("../message").MessageStatus;
|
|
169
177
|
} | {
|
|
170
178
|
content: {
|
|
@@ -176,6 +184,7 @@ export declare const useAgent: (options: IUseChatHelperOptions, http: IHttpModul
|
|
|
176
184
|
role: import("../message").MessageRole.Pause;
|
|
177
185
|
id: number;
|
|
178
186
|
property?: Record<string, unknown>;
|
|
187
|
+
sessionCode: string;
|
|
179
188
|
status?: import("../message").MessageStatus;
|
|
180
189
|
} | {
|
|
181
190
|
content: {
|
|
@@ -187,6 +196,7 @@ export declare const useAgent: (options: IUseChatHelperOptions, http: IHttpModul
|
|
|
187
196
|
role: import("../message").MessageRole.Placeholder;
|
|
188
197
|
id: number;
|
|
189
198
|
property?: Record<string, unknown>;
|
|
199
|
+
sessionCode: string;
|
|
190
200
|
status?: import("../message").MessageStatus;
|
|
191
201
|
} | {
|
|
192
202
|
content: {
|
|
@@ -198,6 +208,7 @@ export declare const useAgent: (options: IUseChatHelperOptions, http: IHttpModul
|
|
|
198
208
|
role: import("../message").MessageRole.System;
|
|
199
209
|
id: number;
|
|
200
210
|
property?: Record<string, unknown>;
|
|
211
|
+
sessionCode: string;
|
|
201
212
|
status?: import("../message").MessageStatus;
|
|
202
213
|
} | {
|
|
203
214
|
content: {
|
|
@@ -209,6 +220,7 @@ export declare const useAgent: (options: IUseChatHelperOptions, http: IHttpModul
|
|
|
209
220
|
role: import("../message").MessageRole.TemplateAssistant;
|
|
210
221
|
id: number;
|
|
211
222
|
property?: Record<string, unknown>;
|
|
223
|
+
sessionCode: string;
|
|
212
224
|
status?: import("../message").MessageStatus;
|
|
213
225
|
} | {
|
|
214
226
|
content: {
|
|
@@ -220,6 +232,7 @@ export declare const useAgent: (options: IUseChatHelperOptions, http: IHttpModul
|
|
|
220
232
|
role: import("../message").MessageRole.TemplateGuide;
|
|
221
233
|
id: number;
|
|
222
234
|
property?: Record<string, unknown>;
|
|
235
|
+
sessionCode: string;
|
|
223
236
|
status?: import("../message").MessageStatus;
|
|
224
237
|
} | {
|
|
225
238
|
content: {
|
|
@@ -231,6 +244,7 @@ export declare const useAgent: (options: IUseChatHelperOptions, http: IHttpModul
|
|
|
231
244
|
role: import("../message").MessageRole.TemplateHidden;
|
|
232
245
|
id: number;
|
|
233
246
|
property?: Record<string, unknown>;
|
|
247
|
+
sessionCode: string;
|
|
234
248
|
status?: import("../message").MessageStatus;
|
|
235
249
|
} | {
|
|
236
250
|
content: {
|
|
@@ -242,6 +256,7 @@ export declare const useAgent: (options: IUseChatHelperOptions, http: IHttpModul
|
|
|
242
256
|
role: import("../message").MessageRole.TemplateSystem;
|
|
243
257
|
id: number;
|
|
244
258
|
property?: Record<string, unknown>;
|
|
259
|
+
sessionCode: string;
|
|
245
260
|
status?: import("../message").MessageStatus;
|
|
246
261
|
} | {
|
|
247
262
|
content: {
|
|
@@ -253,6 +268,7 @@ export declare const useAgent: (options: IUseChatHelperOptions, http: IHttpModul
|
|
|
253
268
|
role: import("../message").MessageRole.TemplateUser;
|
|
254
269
|
id: number;
|
|
255
270
|
property?: Record<string, unknown>;
|
|
271
|
+
sessionCode: string;
|
|
256
272
|
status?: import("../message").MessageStatus;
|
|
257
273
|
} | {
|
|
258
274
|
content: {
|
|
@@ -264,6 +280,7 @@ export declare const useAgent: (options: IUseChatHelperOptions, http: IHttpModul
|
|
|
264
280
|
role: import("../message").MessageRole.User;
|
|
265
281
|
id: number;
|
|
266
282
|
property?: Record<string, unknown>;
|
|
283
|
+
sessionCode: string;
|
|
267
284
|
status?: import("../message").MessageStatus;
|
|
268
285
|
})[];
|
|
269
286
|
};
|
|
@@ -352,6 +369,7 @@ export declare const useAgent: (options: IUseChatHelperOptions, http: IHttpModul
|
|
|
352
369
|
})[];
|
|
353
370
|
id: number;
|
|
354
371
|
property?: Record<string, unknown>;
|
|
372
|
+
sessionCode: string;
|
|
355
373
|
status?: import("../message").MessageStatus;
|
|
356
374
|
} | {
|
|
357
375
|
content: {
|
|
@@ -363,6 +381,7 @@ export declare const useAgent: (options: IUseChatHelperOptions, http: IHttpModul
|
|
|
363
381
|
role: import("../message").MessageRole.Guide;
|
|
364
382
|
id: number;
|
|
365
383
|
property?: Record<string, unknown>;
|
|
384
|
+
sessionCode: string;
|
|
366
385
|
status?: import("../message").MessageStatus;
|
|
367
386
|
} | {
|
|
368
387
|
content: {
|
|
@@ -374,6 +393,7 @@ export declare const useAgent: (options: IUseChatHelperOptions, http: IHttpModul
|
|
|
374
393
|
role: import("../message").MessageRole.HiddenAssistant;
|
|
375
394
|
id: number;
|
|
376
395
|
property?: Record<string, unknown>;
|
|
396
|
+
sessionCode: string;
|
|
377
397
|
status?: import("../message").MessageStatus;
|
|
378
398
|
} | {
|
|
379
399
|
content: {
|
|
@@ -385,6 +405,7 @@ export declare const useAgent: (options: IUseChatHelperOptions, http: IHttpModul
|
|
|
385
405
|
role: import("../message").MessageRole.HiddenGuide;
|
|
386
406
|
id: number;
|
|
387
407
|
property?: Record<string, unknown>;
|
|
408
|
+
sessionCode: string;
|
|
388
409
|
status?: import("../message").MessageStatus;
|
|
389
410
|
} | {
|
|
390
411
|
content: {
|
|
@@ -396,6 +417,7 @@ export declare const useAgent: (options: IUseChatHelperOptions, http: IHttpModul
|
|
|
396
417
|
role: import("../message").MessageRole.Hidden;
|
|
397
418
|
id: number;
|
|
398
419
|
property?: Record<string, unknown>;
|
|
420
|
+
sessionCode: string;
|
|
399
421
|
status?: import("../message").MessageStatus;
|
|
400
422
|
} | {
|
|
401
423
|
content: {
|
|
@@ -407,6 +429,7 @@ export declare const useAgent: (options: IUseChatHelperOptions, http: IHttpModul
|
|
|
407
429
|
role: import("../message").MessageRole.HiddenSystem;
|
|
408
430
|
id: number;
|
|
409
431
|
property?: Record<string, unknown>;
|
|
432
|
+
sessionCode: string;
|
|
410
433
|
status?: import("../message").MessageStatus;
|
|
411
434
|
} | {
|
|
412
435
|
content: {
|
|
@@ -418,6 +441,7 @@ export declare const useAgent: (options: IUseChatHelperOptions, http: IHttpModul
|
|
|
418
441
|
role: import("../message").MessageRole.HiddenUser;
|
|
419
442
|
id: number;
|
|
420
443
|
property?: Record<string, unknown>;
|
|
444
|
+
sessionCode: string;
|
|
421
445
|
status?: import("../message").MessageStatus;
|
|
422
446
|
} | {
|
|
423
447
|
content: {
|
|
@@ -429,6 +453,7 @@ export declare const useAgent: (options: IUseChatHelperOptions, http: IHttpModul
|
|
|
429
453
|
role: import("../message").MessageRole.Info;
|
|
430
454
|
id: number;
|
|
431
455
|
property?: Record<string, unknown>;
|
|
456
|
+
sessionCode: string;
|
|
432
457
|
status?: import("../message").MessageStatus;
|
|
433
458
|
} | {
|
|
434
459
|
content: {
|
|
@@ -440,6 +465,7 @@ export declare const useAgent: (options: IUseChatHelperOptions, http: IHttpModul
|
|
|
440
465
|
role: import("../message").MessageRole.Pause;
|
|
441
466
|
id: number;
|
|
442
467
|
property?: Record<string, unknown>;
|
|
468
|
+
sessionCode: string;
|
|
443
469
|
status?: import("../message").MessageStatus;
|
|
444
470
|
} | {
|
|
445
471
|
content: {
|
|
@@ -451,6 +477,7 @@ export declare const useAgent: (options: IUseChatHelperOptions, http: IHttpModul
|
|
|
451
477
|
role: import("../message").MessageRole.Placeholder;
|
|
452
478
|
id: number;
|
|
453
479
|
property?: Record<string, unknown>;
|
|
480
|
+
sessionCode: string;
|
|
454
481
|
status?: import("../message").MessageStatus;
|
|
455
482
|
} | {
|
|
456
483
|
content: {
|
|
@@ -462,6 +489,7 @@ export declare const useAgent: (options: IUseChatHelperOptions, http: IHttpModul
|
|
|
462
489
|
role: import("../message").MessageRole.System;
|
|
463
490
|
id: number;
|
|
464
491
|
property?: Record<string, unknown>;
|
|
492
|
+
sessionCode: string;
|
|
465
493
|
status?: import("../message").MessageStatus;
|
|
466
494
|
} | {
|
|
467
495
|
content: {
|
|
@@ -473,6 +501,7 @@ export declare const useAgent: (options: IUseChatHelperOptions, http: IHttpModul
|
|
|
473
501
|
role: import("../message").MessageRole.TemplateAssistant;
|
|
474
502
|
id: number;
|
|
475
503
|
property?: Record<string, unknown>;
|
|
504
|
+
sessionCode: string;
|
|
476
505
|
status?: import("../message").MessageStatus;
|
|
477
506
|
} | {
|
|
478
507
|
content: {
|
|
@@ -484,6 +513,7 @@ export declare const useAgent: (options: IUseChatHelperOptions, http: IHttpModul
|
|
|
484
513
|
role: import("../message").MessageRole.TemplateGuide;
|
|
485
514
|
id: number;
|
|
486
515
|
property?: Record<string, unknown>;
|
|
516
|
+
sessionCode: string;
|
|
487
517
|
status?: import("../message").MessageStatus;
|
|
488
518
|
} | {
|
|
489
519
|
content: {
|
|
@@ -495,6 +525,7 @@ export declare const useAgent: (options: IUseChatHelperOptions, http: IHttpModul
|
|
|
495
525
|
role: import("../message").MessageRole.TemplateHidden;
|
|
496
526
|
id: number;
|
|
497
527
|
property?: Record<string, unknown>;
|
|
528
|
+
sessionCode: string;
|
|
498
529
|
status?: import("../message").MessageStatus;
|
|
499
530
|
} | {
|
|
500
531
|
content: {
|
|
@@ -506,6 +537,7 @@ export declare const useAgent: (options: IUseChatHelperOptions, http: IHttpModul
|
|
|
506
537
|
role: import("../message").MessageRole.TemplateSystem;
|
|
507
538
|
id: number;
|
|
508
539
|
property?: Record<string, unknown>;
|
|
540
|
+
sessionCode: string;
|
|
509
541
|
status?: import("../message").MessageStatus;
|
|
510
542
|
} | {
|
|
511
543
|
content: {
|
|
@@ -517,6 +549,7 @@ export declare const useAgent: (options: IUseChatHelperOptions, http: IHttpModul
|
|
|
517
549
|
role: import("../message").MessageRole.TemplateUser;
|
|
518
550
|
id: number;
|
|
519
551
|
property?: Record<string, unknown>;
|
|
552
|
+
sessionCode: string;
|
|
520
553
|
status?: import("../message").MessageStatus;
|
|
521
554
|
} | {
|
|
522
555
|
content: {
|
|
@@ -528,12 +561,13 @@ export declare const useAgent: (options: IUseChatHelperOptions, http: IHttpModul
|
|
|
528
561
|
role: import("../message").MessageRole.User;
|
|
529
562
|
id: number;
|
|
530
563
|
property?: Record<string, unknown>;
|
|
564
|
+
sessionCode: string;
|
|
531
565
|
status?: import("../message").MessageStatus;
|
|
532
566
|
})[];
|
|
533
567
|
};
|
|
534
568
|
}>;
|
|
535
569
|
isInfoLoading: import("vue").Ref<boolean, boolean>;
|
|
536
|
-
chat: (
|
|
570
|
+
chat: (sessionCode: string, url?: string, config?: IRequestConfig) => void;
|
|
537
571
|
stopChat: () => Promise<void>;
|
|
538
572
|
getAgentInfo: () => Promise<void>;
|
|
539
573
|
};
|
|
@@ -51,6 +51,34 @@ 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
|
import { AGUIProtocol } from '../event/index.ts.js';
|
|
56
84
|
import { useFetch } from '../http/fetch/index.ts.js';
|
|
@@ -67,21 +95,25 @@ export const useAgent = (options, http, message)=>{
|
|
|
67
95
|
isInfoLoading.value = false;
|
|
68
96
|
});
|
|
69
97
|
};
|
|
70
|
-
const chat = (url)=>{
|
|
98
|
+
const chat = (sessionCode, url, config)=>{
|
|
71
99
|
chatController = new AbortController();
|
|
72
100
|
const protocol = options.protocol || new AGUIProtocol();
|
|
73
|
-
// ag-ui
|
|
101
|
+
// ag-ui 协议需要注入消息模块、sessionCode
|
|
74
102
|
if (protocol instanceof AGUIProtocol) {
|
|
75
103
|
protocol.injectMessageModule(message);
|
|
104
|
+
protocol.injectSessionCode(sessionCode);
|
|
76
105
|
}
|
|
77
|
-
fetchClient.streamRequest({
|
|
78
|
-
url: url || '
|
|
106
|
+
fetchClient.streamRequest(_object_spread({
|
|
107
|
+
url: url || 'chat_completion/',
|
|
108
|
+
data: {
|
|
109
|
+
session_code: sessionCode
|
|
110
|
+
},
|
|
79
111
|
controller: chatController,
|
|
80
|
-
onDone: protocol.onDone,
|
|
81
|
-
onError: protocol.onError,
|
|
82
|
-
onMessage: protocol.onMessage,
|
|
83
|
-
onStart: protocol.onStart
|
|
84
|
-
});
|
|
112
|
+
onDone: protocol.onDone.bind(protocol),
|
|
113
|
+
onError: protocol.onError.bind(protocol),
|
|
114
|
+
onMessage: protocol.onMessage.bind(protocol),
|
|
115
|
+
onStart: protocol.onStart.bind(protocol)
|
|
116
|
+
}, config));
|
|
85
117
|
};
|
|
86
118
|
const stopChat = function() {
|
|
87
119
|
var _ref = _async_to_generator(function*() {
|
package/dist/event/ag-ui.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export declare class AGUIProtocol implements ISSEProtocol {
|
|
|
11
11
|
private onErrorCallback?;
|
|
12
12
|
private onMessageCallback?;
|
|
13
13
|
private onStartCallback?;
|
|
14
|
+
private sessionCode;
|
|
14
15
|
constructor(params?: {
|
|
15
16
|
onDone?: () => void;
|
|
16
17
|
onError?: (error: unknown) => void;
|
|
@@ -56,7 +57,7 @@ export declare class AGUIProtocol implements ISSEProtocol {
|
|
|
56
57
|
/**
|
|
57
58
|
* 处理运行开始事件
|
|
58
59
|
*/
|
|
59
|
-
handleRunStartedEvent(
|
|
60
|
+
handleRunStartedEvent(_event: IRunStartedEvent): void;
|
|
60
61
|
/**
|
|
61
62
|
* 处理状态增量更新事件
|
|
62
63
|
*/
|
|
@@ -130,6 +131,7 @@ export declare class AGUIProtocol implements ISSEProtocol {
|
|
|
130
131
|
*/
|
|
131
132
|
handleToolCallStartEvent(event: IToolCallStartEvent): void;
|
|
132
133
|
injectMessageModule(message: IMessageModule): void;
|
|
134
|
+
injectSessionCode(sessionCode: string): void;
|
|
133
135
|
onDone(): void;
|
|
134
136
|
onError(error: Error): void;
|
|
135
137
|
onMessage(message: unknown): void;
|
package/dist/event/ag-ui.ts.js
CHANGED
|
@@ -119,13 +119,8 @@ let tempTimestamp = 0;
|
|
|
119
119
|
}
|
|
120
120
|
/**
|
|
121
121
|
* 处理运行开始事件
|
|
122
|
-
*/ handleRunStartedEvent(
|
|
123
|
-
this.messageModule.
|
|
124
|
-
id: event.runId,
|
|
125
|
-
role: MessageRole.Assistant,
|
|
126
|
-
content: [],
|
|
127
|
-
status: MessageStatus.Streaming
|
|
128
|
-
});
|
|
122
|
+
*/ handleRunStartedEvent(_event) {
|
|
123
|
+
this.messageModule.plusLatestMessage(this.sessionCode);
|
|
129
124
|
}
|
|
130
125
|
/**
|
|
131
126
|
* 处理状态增量更新事件
|
|
@@ -319,6 +314,9 @@ let tempTimestamp = 0;
|
|
|
319
314
|
injectMessageModule(message) {
|
|
320
315
|
this.messageModule = message;
|
|
321
316
|
}
|
|
317
|
+
injectSessionCode(sessionCode) {
|
|
318
|
+
this.sessionCode = sessionCode;
|
|
319
|
+
}
|
|
322
320
|
onDone() {
|
|
323
321
|
var // 回调给上层
|
|
324
322
|
_this_onDoneCallback, _this;
|
|
@@ -344,6 +342,8 @@ let tempTimestamp = 0;
|
|
|
344
342
|
status: MessageContentStatus.Error
|
|
345
343
|
}
|
|
346
344
|
];
|
|
345
|
+
} else {
|
|
346
|
+
this.messageModule.plusLatestMessage(this.sessionCode);
|
|
347
347
|
}
|
|
348
348
|
}
|
|
349
349
|
onMessage(message) {
|
|
@@ -445,6 +445,7 @@ let tempTimestamp = 0;
|
|
|
445
445
|
_define_property(this, "onErrorCallback", void 0);
|
|
446
446
|
_define_property(this, "onMessageCallback", void 0);
|
|
447
447
|
_define_property(this, "onStartCallback", void 0);
|
|
448
|
+
_define_property(this, "sessionCode", void 0);
|
|
448
449
|
this.onDoneCallback = params === null || params === void 0 ? void 0 : params.onDone;
|
|
449
450
|
this.onErrorCallback = params === null || params === void 0 ? void 0 : params.onError;
|
|
450
451
|
this.onMessageCallback = params === null || params === void 0 ? void 0 : params.onMessage;
|
|
@@ -3,13 +3,7 @@ export interface ApiResponse<T = unknown> {
|
|
|
3
3
|
data: T;
|
|
4
4
|
message: string;
|
|
5
5
|
}
|
|
6
|
-
export interface
|
|
7
|
-
onDone?: () => void;
|
|
8
|
-
onError?: (error: Error) => void;
|
|
9
|
-
onMessage?: (event: unknown) => void;
|
|
10
|
-
onStart?: () => void;
|
|
11
|
-
}
|
|
12
|
-
export interface RequestConfig {
|
|
6
|
+
export interface IRequestConfig {
|
|
13
7
|
baseURL?: string;
|
|
14
8
|
controller?: AbortController;
|
|
15
9
|
credentials?: 'include' | 'omit' | 'same-origin';
|
|
@@ -25,22 +19,28 @@ export interface RequestConfig {
|
|
|
25
19
|
transformResponse?: (data: unknown) => unknown;
|
|
26
20
|
validateStatus?: (status: number) => boolean;
|
|
27
21
|
}
|
|
28
|
-
export interface
|
|
22
|
+
export interface IRequestError extends Error {
|
|
29
23
|
code?: string;
|
|
30
|
-
config:
|
|
24
|
+
config: IRequestConfig;
|
|
31
25
|
isAxiosError: boolean;
|
|
32
|
-
response?:
|
|
26
|
+
response?: IResponse;
|
|
33
27
|
}
|
|
34
|
-
export interface
|
|
35
|
-
config:
|
|
28
|
+
export interface IResponse<T = unknown> {
|
|
29
|
+
config: IRequestConfig;
|
|
36
30
|
data: T;
|
|
37
31
|
headers: Headers;
|
|
38
32
|
status: number;
|
|
39
33
|
statusText: string;
|
|
40
34
|
}
|
|
41
|
-
export interface
|
|
35
|
+
export interface ISSEConfig extends ISSEProtocol, Omit<IRequestConfig, 'responseType'> {
|
|
36
|
+
}
|
|
37
|
+
export interface ISSEProtocol {
|
|
38
|
+
onDone?: () => void;
|
|
39
|
+
onError?: (error: Error) => void;
|
|
40
|
+
onMessage?: (event: unknown) => void;
|
|
41
|
+
onStart?: () => void;
|
|
42
42
|
}
|
|
43
|
-
interface
|
|
43
|
+
interface IInterceptor<T> {
|
|
44
44
|
fulfilled?: (value: T) => T;
|
|
45
45
|
rejected?: (error: unknown) => unknown;
|
|
46
46
|
}
|
|
@@ -48,27 +48,27 @@ declare class InterceptorManager<T> {
|
|
|
48
48
|
private handlers;
|
|
49
49
|
clear(): void;
|
|
50
50
|
eject(id: number): void;
|
|
51
|
-
forEach(fn: (interceptor:
|
|
51
|
+
forEach(fn: (interceptor: IInterceptor<T>) => void): void;
|
|
52
52
|
use(fulfilled?: (value: T) => T, rejected?: (error: unknown) => unknown): number;
|
|
53
53
|
}
|
|
54
54
|
export declare class FetchClient {
|
|
55
|
-
defaults:
|
|
55
|
+
defaults: IRequestConfig;
|
|
56
56
|
interceptors: {
|
|
57
|
-
request: InterceptorManager<
|
|
58
|
-
response: InterceptorManager<
|
|
57
|
+
request: InterceptorManager<IRequestConfig>;
|
|
58
|
+
response: InterceptorManager<IResponse>;
|
|
59
59
|
};
|
|
60
|
-
constructor(config?:
|
|
60
|
+
constructor(config?: IRequestConfig);
|
|
61
61
|
applyResponseErrorInterceptors(error: unknown): unknown;
|
|
62
|
-
create(config?:
|
|
63
|
-
delete<T = unknown>(url: string, params?: Record<string, unknown>, config?:
|
|
64
|
-
get<T = unknown>(url: string, params?: Record<string, unknown>, config?:
|
|
65
|
-
head<T = unknown>(url: string, params?: Record<string, unknown>, config?:
|
|
66
|
-
options<T = unknown>(url: string, params?: Record<string, unknown>, config?:
|
|
67
|
-
patch<T = unknown>(url: string, data?: unknown, config?:
|
|
68
|
-
post<T = unknown>(url: string, data?: unknown, config?:
|
|
69
|
-
prepareRequest(config:
|
|
62
|
+
create(config?: IRequestConfig): FetchClient;
|
|
63
|
+
delete<T = unknown>(url: string, params?: Record<string, unknown>, config?: IRequestConfig): Promise<T>;
|
|
64
|
+
get<T = unknown>(url: string, params?: Record<string, unknown>, config?: IRequestConfig): Promise<T>;
|
|
65
|
+
head<T = unknown>(url: string, params?: Record<string, unknown>, config?: IRequestConfig): Promise<T>;
|
|
66
|
+
options<T = unknown>(url: string, params?: Record<string, unknown>, config?: IRequestConfig): Promise<T>;
|
|
67
|
+
patch<T = unknown>(url: string, data?: unknown, config?: IRequestConfig): Promise<T>;
|
|
68
|
+
post<T = unknown>(url: string, data?: unknown, config?: IRequestConfig): Promise<T>;
|
|
69
|
+
prepareRequest(config: IRequestConfig, isStream?: boolean): {
|
|
70
70
|
url: string;
|
|
71
|
-
requestConfig:
|
|
71
|
+
requestConfig: IRequestConfig;
|
|
72
72
|
fetchConfig: {
|
|
73
73
|
method: string;
|
|
74
74
|
credentials: "include" | "omit" | "same-origin";
|
|
@@ -78,10 +78,10 @@ export declare class FetchClient {
|
|
|
78
78
|
controller: AbortController;
|
|
79
79
|
};
|
|
80
80
|
};
|
|
81
|
-
put<T = unknown>(url: string, data?: unknown, config?:
|
|
82
|
-
request<T = unknown>(config:
|
|
83
|
-
stream(url: string, config?:
|
|
84
|
-
streamRequest(config:
|
|
81
|
+
put<T = unknown>(url: string, data?: unknown, config?: IRequestConfig): Promise<T>;
|
|
82
|
+
request<T = unknown>(config: IRequestConfig): Promise<T>;
|
|
83
|
+
stream(url: string, config?: ISSEConfig): Promise<void>;
|
|
84
|
+
streamRequest(config: ISSEConfig): Promise<void>;
|
|
85
85
|
}
|
|
86
86
|
declare const fetchClient: FetchClient;
|
|
87
87
|
export default fetchClient;
|
|
@@ -383,7 +383,7 @@ export class FetchClient {
|
|
|
383
383
|
const reader = (_fetchResponse_body = fetchResponse.body) === null || _fetchResponse_body === void 0 ? void 0 : _fetchResponse_body.pipeThrough(new window.TextDecoderStream()).getReader();
|
|
384
384
|
if (!reader) {
|
|
385
385
|
var _config_onError1;
|
|
386
|
-
const error = new Error('
|
|
386
|
+
const error = new Error('IResponse body is not readable');
|
|
387
387
|
(_config_onError1 = config.onError) === null || _config_onError1 === void 0 ? void 0 : _config_onError1.call(config, error);
|
|
388
388
|
return;
|
|
389
389
|
}
|
package/dist/http/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { IUseChatHelperOptions } from '../type';
|
|
2
|
+
export * from './fetch';
|
|
2
3
|
export * from './transform';
|
|
3
4
|
/**
|
|
4
5
|
* 使用 HTTP 模块
|
|
@@ -7,32 +8,32 @@ export * from './transform';
|
|
|
7
8
|
*/
|
|
8
9
|
export declare const useHttp: (options: IUseChatHelperOptions) => {
|
|
9
10
|
agent: {
|
|
10
|
-
getAgentInfo: (config?: import("./fetch").
|
|
11
|
+
getAgentInfo: (config?: import("./fetch").IRequestConfig) => Promise<import("..").IAgentInfo>;
|
|
11
12
|
};
|
|
12
13
|
session: {
|
|
13
|
-
clearSession: (sessionCode: string, config?: import("./fetch").
|
|
14
|
-
getSessions: (config?: import("./fetch").
|
|
15
|
-
plusSession: (data: import("..").ISession, config?: import("./fetch").
|
|
16
|
-
modifySession: (data: import("..").ISession, config?: import("./fetch").
|
|
17
|
-
deleteSession: (sessionCode: string, config?: import("./fetch").
|
|
18
|
-
batchDeleteSessions: (sessionCodes: string[], config?: import("./fetch").
|
|
19
|
-
getSession: (sessionCode: string, config?: import("./fetch").
|
|
20
|
-
postSessionFeedback: (data: import("..").ISessionFeedback, config?: import("./fetch").
|
|
14
|
+
clearSession: (sessionCode: string, config?: import("./fetch").IRequestConfig) => Promise<unknown>;
|
|
15
|
+
getSessions: (config?: import("./fetch").IRequestConfig) => Promise<import("..").ISession<unknown, unknown>[]>;
|
|
16
|
+
plusSession: (data: import("..").ISession, config?: import("./fetch").IRequestConfig) => Promise<import("..").ISession<unknown, unknown>>;
|
|
17
|
+
modifySession: (data: import("..").ISession, config?: import("./fetch").IRequestConfig) => Promise<import("..").ISession<unknown, unknown>>;
|
|
18
|
+
deleteSession: (sessionCode: string, config?: import("./fetch").IRequestConfig) => Promise<unknown>;
|
|
19
|
+
batchDeleteSessions: (sessionCodes: string[], config?: import("./fetch").IRequestConfig) => Promise<number>;
|
|
20
|
+
getSession: (sessionCode: string, config?: import("./fetch").IRequestConfig) => Promise<import("..").ISession<unknown, unknown>>;
|
|
21
|
+
postSessionFeedback: (data: import("..").ISessionFeedback, config?: import("./fetch").IRequestConfig) => Promise<{
|
|
21
22
|
sessionCode: string;
|
|
22
23
|
sessionContentIds: number[];
|
|
23
24
|
rate: number;
|
|
24
25
|
comment: string;
|
|
25
26
|
labels: string[];
|
|
26
27
|
}>;
|
|
27
|
-
getSessionFeedbackLabels: (rate: number, config?: import("./fetch").
|
|
28
|
-
renameSession: (sessionCode: string, config?: import("./fetch").
|
|
28
|
+
getSessionFeedbackLabels: (rate: number, config?: import("./fetch").IRequestConfig) => Promise<string[]>;
|
|
29
|
+
renameSession: (sessionCode: string, config?: import("./fetch").IRequestConfig) => Promise<import("..").ISession<unknown, unknown>>;
|
|
29
30
|
};
|
|
30
31
|
message: {
|
|
31
|
-
getMessages: (sessionCode: string, config?: import("./fetch").
|
|
32
|
-
plusMessage: (data: import("..").IMessage, config?: import("./fetch").
|
|
33
|
-
modifyMessage: (data: import("..").IMessage, config?: import("./fetch").
|
|
34
|
-
deleteMessage: (id: number, config?: import("./fetch").
|
|
35
|
-
batchDeleteMessages: (ids: number[], config?: import("./fetch").
|
|
32
|
+
getMessages: (sessionCode: string, limit?: number, config?: import("./fetch").IRequestConfig) => Promise<import("..").IMessage[]>;
|
|
33
|
+
plusMessage: (data: import("..").IMessage, config?: import("./fetch").IRequestConfig) => Promise<import("..").IMessageApi>;
|
|
34
|
+
modifyMessage: (data: import("..").IMessage, config?: import("./fetch").IRequestConfig) => Promise<import("..").IMessageApi>;
|
|
35
|
+
deleteMessage: (id: number, config?: import("./fetch").IRequestConfig) => Promise<import("..").IMessageApi>;
|
|
36
|
+
batchDeleteMessages: (ids: number[], config?: import("./fetch").IRequestConfig) => Promise<number>;
|
|
36
37
|
};
|
|
37
38
|
};
|
|
38
39
|
export type IHttpModule = ReturnType<typeof useHttp>;
|
package/dist/http/index.ts.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { FetchClient,
|
|
1
|
+
import type { FetchClient, IRequestConfig } from '../fetch';
|
|
2
2
|
/**
|
|
3
3
|
* agent 相关 http 接口
|
|
4
4
|
* @param fetchClient - 请求客户端
|
|
5
5
|
* @returns agent 相关 http 接口
|
|
6
6
|
*/
|
|
7
7
|
export declare const useAgent: (fetchClient: FetchClient) => {
|
|
8
|
-
getAgentInfo: (config?:
|
|
8
|
+
getAgentInfo: (config?: IRequestConfig) => Promise<import("../../agent/type").IAgentInfo>;
|
|
9
9
|
};
|