@blueking/chat-helper 0.0.12-beta.20 → 0.0.12-beta.22
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 +44 -0
- package/dist/event/ag-ui.d.ts +1 -1
- package/dist/event/ag-ui.ts.js +66 -5
- package/dist/event/type.d.ts +1 -0
- package/dist/http/transform/message.ts.js +11 -5
- package/dist/index.d.ts +308 -0
- package/dist/message/type.d.ts +10 -0
- package/dist/message/type.ts.js +14 -0
- package/dist/message/use-message.d.ts +88 -0
- package/dist/session/use-session.d.ts +176 -0
- package/package.json +1 -1
|
@@ -124,6 +124,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
124
124
|
};
|
|
125
125
|
};
|
|
126
126
|
role: MessageRole.Activity;
|
|
127
|
+
createdAt?: string;
|
|
127
128
|
id?: string;
|
|
128
129
|
messageId?: string;
|
|
129
130
|
name?: string;
|
|
@@ -167,6 +168,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
167
168
|
id: string;
|
|
168
169
|
type: import("../message").MessageType.Function;
|
|
169
170
|
}[];
|
|
171
|
+
createdAt?: string;
|
|
170
172
|
id?: string;
|
|
171
173
|
messageId?: string;
|
|
172
174
|
name?: string;
|
|
@@ -175,6 +177,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
175
177
|
} | {
|
|
176
178
|
content: string;
|
|
177
179
|
role: MessageRole.Developer;
|
|
180
|
+
createdAt?: string;
|
|
178
181
|
id?: string;
|
|
179
182
|
messageId?: string;
|
|
180
183
|
name?: string;
|
|
@@ -183,6 +186,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
183
186
|
} | {
|
|
184
187
|
content: string;
|
|
185
188
|
role: MessageRole.Guide;
|
|
189
|
+
createdAt?: string;
|
|
186
190
|
id?: string;
|
|
187
191
|
messageId?: string;
|
|
188
192
|
name?: string;
|
|
@@ -191,6 +195,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
191
195
|
} | {
|
|
192
196
|
content: string;
|
|
193
197
|
role: MessageRole.HiddenAssistant;
|
|
198
|
+
createdAt?: string;
|
|
194
199
|
id?: string;
|
|
195
200
|
messageId?: string;
|
|
196
201
|
name?: string;
|
|
@@ -199,6 +204,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
199
204
|
} | {
|
|
200
205
|
content: string;
|
|
201
206
|
role: MessageRole.HiddenGuide;
|
|
207
|
+
createdAt?: string;
|
|
202
208
|
id?: string;
|
|
203
209
|
messageId?: string;
|
|
204
210
|
name?: string;
|
|
@@ -207,6 +213,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
207
213
|
} | {
|
|
208
214
|
content: string;
|
|
209
215
|
role: MessageRole.Hidden;
|
|
216
|
+
createdAt?: string;
|
|
210
217
|
id?: string;
|
|
211
218
|
messageId?: string;
|
|
212
219
|
name?: string;
|
|
@@ -215,6 +222,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
215
222
|
} | {
|
|
216
223
|
content: string;
|
|
217
224
|
role: MessageRole.HiddenSystem;
|
|
225
|
+
createdAt?: string;
|
|
218
226
|
id?: string;
|
|
219
227
|
messageId?: string;
|
|
220
228
|
name?: string;
|
|
@@ -223,6 +231,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
223
231
|
} | {
|
|
224
232
|
content: string;
|
|
225
233
|
role: MessageRole.HiddenUser;
|
|
234
|
+
createdAt?: string;
|
|
226
235
|
id?: string;
|
|
227
236
|
messageId?: string;
|
|
228
237
|
name?: string;
|
|
@@ -231,6 +240,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
231
240
|
} | {
|
|
232
241
|
content: string;
|
|
233
242
|
role: MessageRole.Info;
|
|
243
|
+
createdAt?: string;
|
|
234
244
|
id?: string;
|
|
235
245
|
messageId?: string;
|
|
236
246
|
name?: string;
|
|
@@ -239,6 +249,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
239
249
|
} | {
|
|
240
250
|
content: string;
|
|
241
251
|
role: MessageRole.Pause;
|
|
252
|
+
createdAt?: string;
|
|
242
253
|
id?: string;
|
|
243
254
|
messageId?: string;
|
|
244
255
|
name?: string;
|
|
@@ -247,6 +258,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
247
258
|
} | {
|
|
248
259
|
content: string;
|
|
249
260
|
role: MessageRole.Placeholder;
|
|
261
|
+
createdAt?: string;
|
|
250
262
|
id?: string;
|
|
251
263
|
messageId?: string;
|
|
252
264
|
name?: string;
|
|
@@ -256,6 +268,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
256
268
|
content: string[];
|
|
257
269
|
duration?: number;
|
|
258
270
|
role: MessageRole.Reasoning;
|
|
271
|
+
createdAt?: string;
|
|
259
272
|
id?: string;
|
|
260
273
|
messageId?: string;
|
|
261
274
|
name?: string;
|
|
@@ -264,6 +277,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
264
277
|
} | {
|
|
265
278
|
content: string;
|
|
266
279
|
role: MessageRole.System;
|
|
280
|
+
createdAt?: string;
|
|
267
281
|
id?: string;
|
|
268
282
|
messageId?: string;
|
|
269
283
|
name?: string;
|
|
@@ -272,6 +286,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
272
286
|
} | {
|
|
273
287
|
content: string;
|
|
274
288
|
role: MessageRole.TemplateAssistant;
|
|
289
|
+
createdAt?: string;
|
|
275
290
|
id?: string;
|
|
276
291
|
messageId?: string;
|
|
277
292
|
name?: string;
|
|
@@ -280,6 +295,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
280
295
|
} | {
|
|
281
296
|
content: string;
|
|
282
297
|
role: MessageRole.TemplateGuide;
|
|
298
|
+
createdAt?: string;
|
|
283
299
|
id?: string;
|
|
284
300
|
messageId?: string;
|
|
285
301
|
name?: string;
|
|
@@ -288,6 +304,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
288
304
|
} | {
|
|
289
305
|
content: string;
|
|
290
306
|
role: MessageRole.TemplateHidden;
|
|
307
|
+
createdAt?: string;
|
|
291
308
|
id?: string;
|
|
292
309
|
messageId?: string;
|
|
293
310
|
name?: string;
|
|
@@ -296,6 +313,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
296
313
|
} | {
|
|
297
314
|
content: string;
|
|
298
315
|
role: MessageRole.TemplateSystem;
|
|
316
|
+
createdAt?: string;
|
|
299
317
|
id?: string;
|
|
300
318
|
messageId?: string;
|
|
301
319
|
name?: string;
|
|
@@ -304,6 +322,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
304
322
|
} | {
|
|
305
323
|
content: string;
|
|
306
324
|
role: MessageRole.TemplateUser;
|
|
325
|
+
createdAt?: string;
|
|
307
326
|
id?: string;
|
|
308
327
|
messageId?: string;
|
|
309
328
|
name?: string;
|
|
@@ -315,6 +334,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
315
334
|
error?: string;
|
|
316
335
|
role: MessageRole.Tool;
|
|
317
336
|
toolCallId: string;
|
|
337
|
+
createdAt?: string;
|
|
318
338
|
id?: string;
|
|
319
339
|
messageId?: string;
|
|
320
340
|
name?: string;
|
|
@@ -358,6 +378,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
358
378
|
};
|
|
359
379
|
};
|
|
360
380
|
role: MessageRole.User;
|
|
381
|
+
createdAt?: string;
|
|
361
382
|
id?: string;
|
|
362
383
|
messageId?: string;
|
|
363
384
|
name?: string;
|
|
@@ -988,6 +1009,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
988
1009
|
timestamp?: number;
|
|
989
1010
|
};
|
|
990
1011
|
role: MessageRole.Interrupt;
|
|
1012
|
+
createdAt?: string;
|
|
991
1013
|
id?: string;
|
|
992
1014
|
messageId?: string;
|
|
993
1015
|
name?: string;
|
|
@@ -1112,6 +1134,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
1112
1134
|
};
|
|
1113
1135
|
};
|
|
1114
1136
|
role: MessageRole.Activity;
|
|
1137
|
+
createdAt?: string;
|
|
1115
1138
|
id?: string;
|
|
1116
1139
|
messageId?: string;
|
|
1117
1140
|
name?: string;
|
|
@@ -1155,6 +1178,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
1155
1178
|
id: string;
|
|
1156
1179
|
type: import("../message").MessageType.Function;
|
|
1157
1180
|
}[];
|
|
1181
|
+
createdAt?: string;
|
|
1158
1182
|
id?: string;
|
|
1159
1183
|
messageId?: string;
|
|
1160
1184
|
name?: string;
|
|
@@ -1163,6 +1187,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
1163
1187
|
} | {
|
|
1164
1188
|
content: string;
|
|
1165
1189
|
role: MessageRole.Developer;
|
|
1190
|
+
createdAt?: string;
|
|
1166
1191
|
id?: string;
|
|
1167
1192
|
messageId?: string;
|
|
1168
1193
|
name?: string;
|
|
@@ -1171,6 +1196,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
1171
1196
|
} | {
|
|
1172
1197
|
content: string;
|
|
1173
1198
|
role: MessageRole.Guide;
|
|
1199
|
+
createdAt?: string;
|
|
1174
1200
|
id?: string;
|
|
1175
1201
|
messageId?: string;
|
|
1176
1202
|
name?: string;
|
|
@@ -1179,6 +1205,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
1179
1205
|
} | {
|
|
1180
1206
|
content: string;
|
|
1181
1207
|
role: MessageRole.HiddenAssistant;
|
|
1208
|
+
createdAt?: string;
|
|
1182
1209
|
id?: string;
|
|
1183
1210
|
messageId?: string;
|
|
1184
1211
|
name?: string;
|
|
@@ -1187,6 +1214,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
1187
1214
|
} | {
|
|
1188
1215
|
content: string;
|
|
1189
1216
|
role: MessageRole.HiddenGuide;
|
|
1217
|
+
createdAt?: string;
|
|
1190
1218
|
id?: string;
|
|
1191
1219
|
messageId?: string;
|
|
1192
1220
|
name?: string;
|
|
@@ -1195,6 +1223,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
1195
1223
|
} | {
|
|
1196
1224
|
content: string;
|
|
1197
1225
|
role: MessageRole.Hidden;
|
|
1226
|
+
createdAt?: string;
|
|
1198
1227
|
id?: string;
|
|
1199
1228
|
messageId?: string;
|
|
1200
1229
|
name?: string;
|
|
@@ -1203,6 +1232,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
1203
1232
|
} | {
|
|
1204
1233
|
content: string;
|
|
1205
1234
|
role: MessageRole.HiddenSystem;
|
|
1235
|
+
createdAt?: string;
|
|
1206
1236
|
id?: string;
|
|
1207
1237
|
messageId?: string;
|
|
1208
1238
|
name?: string;
|
|
@@ -1211,6 +1241,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
1211
1241
|
} | {
|
|
1212
1242
|
content: string;
|
|
1213
1243
|
role: MessageRole.HiddenUser;
|
|
1244
|
+
createdAt?: string;
|
|
1214
1245
|
id?: string;
|
|
1215
1246
|
messageId?: string;
|
|
1216
1247
|
name?: string;
|
|
@@ -1219,6 +1250,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
1219
1250
|
} | {
|
|
1220
1251
|
content: string;
|
|
1221
1252
|
role: MessageRole.Info;
|
|
1253
|
+
createdAt?: string;
|
|
1222
1254
|
id?: string;
|
|
1223
1255
|
messageId?: string;
|
|
1224
1256
|
name?: string;
|
|
@@ -1227,6 +1259,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
1227
1259
|
} | {
|
|
1228
1260
|
content: string;
|
|
1229
1261
|
role: MessageRole.Pause;
|
|
1262
|
+
createdAt?: string;
|
|
1230
1263
|
id?: string;
|
|
1231
1264
|
messageId?: string;
|
|
1232
1265
|
name?: string;
|
|
@@ -1235,6 +1268,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
1235
1268
|
} | {
|
|
1236
1269
|
content: string;
|
|
1237
1270
|
role: MessageRole.Placeholder;
|
|
1271
|
+
createdAt?: string;
|
|
1238
1272
|
id?: string;
|
|
1239
1273
|
messageId?: string;
|
|
1240
1274
|
name?: string;
|
|
@@ -1244,6 +1278,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
1244
1278
|
content: string[];
|
|
1245
1279
|
duration?: number;
|
|
1246
1280
|
role: MessageRole.Reasoning;
|
|
1281
|
+
createdAt?: string;
|
|
1247
1282
|
id?: string;
|
|
1248
1283
|
messageId?: string;
|
|
1249
1284
|
name?: string;
|
|
@@ -1252,6 +1287,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
1252
1287
|
} | {
|
|
1253
1288
|
content: string;
|
|
1254
1289
|
role: MessageRole.System;
|
|
1290
|
+
createdAt?: string;
|
|
1255
1291
|
id?: string;
|
|
1256
1292
|
messageId?: string;
|
|
1257
1293
|
name?: string;
|
|
@@ -1260,6 +1296,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
1260
1296
|
} | {
|
|
1261
1297
|
content: string;
|
|
1262
1298
|
role: MessageRole.TemplateAssistant;
|
|
1299
|
+
createdAt?: string;
|
|
1263
1300
|
id?: string;
|
|
1264
1301
|
messageId?: string;
|
|
1265
1302
|
name?: string;
|
|
@@ -1268,6 +1305,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
1268
1305
|
} | {
|
|
1269
1306
|
content: string;
|
|
1270
1307
|
role: MessageRole.TemplateGuide;
|
|
1308
|
+
createdAt?: string;
|
|
1271
1309
|
id?: string;
|
|
1272
1310
|
messageId?: string;
|
|
1273
1311
|
name?: string;
|
|
@@ -1276,6 +1314,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
1276
1314
|
} | {
|
|
1277
1315
|
content: string;
|
|
1278
1316
|
role: MessageRole.TemplateHidden;
|
|
1317
|
+
createdAt?: string;
|
|
1279
1318
|
id?: string;
|
|
1280
1319
|
messageId?: string;
|
|
1281
1320
|
name?: string;
|
|
@@ -1284,6 +1323,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
1284
1323
|
} | {
|
|
1285
1324
|
content: string;
|
|
1286
1325
|
role: MessageRole.TemplateSystem;
|
|
1326
|
+
createdAt?: string;
|
|
1287
1327
|
id?: string;
|
|
1288
1328
|
messageId?: string;
|
|
1289
1329
|
name?: string;
|
|
@@ -1292,6 +1332,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
1292
1332
|
} | {
|
|
1293
1333
|
content: string;
|
|
1294
1334
|
role: MessageRole.TemplateUser;
|
|
1335
|
+
createdAt?: string;
|
|
1295
1336
|
id?: string;
|
|
1296
1337
|
messageId?: string;
|
|
1297
1338
|
name?: string;
|
|
@@ -1303,6 +1344,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
1303
1344
|
error?: string;
|
|
1304
1345
|
role: MessageRole.Tool;
|
|
1305
1346
|
toolCallId: string;
|
|
1347
|
+
createdAt?: string;
|
|
1306
1348
|
id?: string;
|
|
1307
1349
|
messageId?: string;
|
|
1308
1350
|
name?: string;
|
|
@@ -1346,6 +1388,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
1346
1388
|
};
|
|
1347
1389
|
};
|
|
1348
1390
|
role: MessageRole.User;
|
|
1391
|
+
createdAt?: string;
|
|
1349
1392
|
id?: string;
|
|
1350
1393
|
messageId?: string;
|
|
1351
1394
|
name?: string;
|
|
@@ -1976,6 +2019,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
|
|
|
1976
2019
|
timestamp?: number;
|
|
1977
2020
|
};
|
|
1978
2021
|
role: MessageRole.Interrupt;
|
|
2022
|
+
createdAt?: string;
|
|
1979
2023
|
id?: string;
|
|
1980
2024
|
messageId?: string;
|
|
1981
2025
|
name?: string;
|
package/dist/event/ag-ui.d.ts
CHANGED
|
@@ -71,7 +71,7 @@ export declare class AGUIProtocol implements ISSEProtocol {
|
|
|
71
71
|
handleKnowledgeRagTextContentCustomEvent(event: ICustomEvent): void;
|
|
72
72
|
/**
|
|
73
73
|
* 处理消息快照事件
|
|
74
|
-
*
|
|
74
|
+
* 用于同步多端消息状态;chat_completion 首帧会全量返回历史消息(含 created_at)
|
|
75
75
|
*/
|
|
76
76
|
handleMessagesSnapshotEvent(event: IMessagesSnapshotEvent): void;
|
|
77
77
|
/**
|
package/dist/event/ag-ui.ts.js
CHANGED
|
@@ -35,7 +35,46 @@
|
|
|
35
35
|
}
|
|
36
36
|
return obj;
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
function _object_spread(target) {
|
|
39
|
+
for(var i = 1; i < arguments.length; i++){
|
|
40
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
41
|
+
var ownKeys = Object.keys(source);
|
|
42
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
43
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
44
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
ownKeys.forEach(function(key) {
|
|
48
|
+
_define_property(target, key, source[key]);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return target;
|
|
52
|
+
}
|
|
53
|
+
function ownKeys(object, enumerableOnly) {
|
|
54
|
+
var keys = Object.keys(object);
|
|
55
|
+
if (Object.getOwnPropertySymbols) {
|
|
56
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
57
|
+
if (enumerableOnly) {
|
|
58
|
+
symbols = symbols.filter(function(sym) {
|
|
59
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
keys.push.apply(keys, symbols);
|
|
63
|
+
}
|
|
64
|
+
return keys;
|
|
65
|
+
}
|
|
66
|
+
function _object_spread_props(target, source) {
|
|
67
|
+
source = source != null ? source : {};
|
|
68
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
69
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
70
|
+
} else {
|
|
71
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
72
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return target;
|
|
76
|
+
}
|
|
77
|
+
import { ActivityType, MessageRole, MessageStatus, MessageType, formatEventTimestampToCreatedAt, resolveMessageCreatedAt } from '../message/index.ts.js';
|
|
39
78
|
import { CustomEventName, EventType, FlowTaskState, RunFinishedOutcomeType } from './type.ts.js';
|
|
40
79
|
/**
|
|
41
80
|
* AGUI 协议
|
|
@@ -242,10 +281,10 @@ import { CustomEventName, EventType, FlowTaskState, RunFinishedOutcomeType } fro
|
|
|
242
281
|
}
|
|
243
282
|
/**
|
|
244
283
|
* 处理消息快照事件
|
|
245
|
-
*
|
|
284
|
+
* 用于同步多端消息状态;chat_completion 首帧会全量返回历史消息(含 created_at)
|
|
246
285
|
*/ handleMessagesSnapshotEvent(event) {
|
|
247
286
|
if (event.messages && event.messages.length > 0) {
|
|
248
|
-
this.messageModule.list.value = event.messages;
|
|
287
|
+
this.messageModule.list.value = event.messages.map(normalizeSnapshotMessage);
|
|
249
288
|
}
|
|
250
289
|
}
|
|
251
290
|
/**
|
|
@@ -284,17 +323,24 @@ import { CustomEventName, EventType, FlowTaskState, RunFinishedOutcomeType } fro
|
|
|
284
323
|
* 处理运行完成事件
|
|
285
324
|
*/ handleRunFinishedEvent(event) {
|
|
286
325
|
var _event_outcome, _event_outcome1;
|
|
326
|
+
const createdAt = formatEventTimestampToCreatedAt(event.timestamp);
|
|
287
327
|
const message = this.messageModule.getCurrentLoadingMessage();
|
|
288
328
|
if (message) {
|
|
289
329
|
message.status = MessageStatus.Complete;
|
|
290
330
|
}
|
|
331
|
+
// 本轮流式消息在落库前没有 createdAt,用 RUN_FINISHED.timestamp 转成 ISO 后补上;已有时间的历史消息不覆盖
|
|
332
|
+
if (createdAt) {
|
|
333
|
+
applyCreatedAtToCurrentRun(this.messageModule.list.value, createdAt);
|
|
334
|
+
}
|
|
291
335
|
// 如果是中断消息,则创建一个中断消息
|
|
292
336
|
if (((_event_outcome = event.outcome) === null || _event_outcome === void 0 ? void 0 : _event_outcome.type) === RunFinishedOutcomeType.Interrupt) {
|
|
293
|
-
this.messageModule.plusMessage({
|
|
337
|
+
this.messageModule.plusMessage(_object_spread({
|
|
294
338
|
role: MessageRole.Interrupt,
|
|
295
339
|
content: event,
|
|
296
340
|
status: MessageStatus.Pending
|
|
297
|
-
}
|
|
341
|
+
}, createdAt ? {
|
|
342
|
+
createdAt
|
|
343
|
+
} : {}));
|
|
298
344
|
}
|
|
299
345
|
// 二次返回,直接更新消息内容
|
|
300
346
|
if (((_event_outcome1 = event.outcome) === null || _event_outcome1 === void 0 ? void 0 : _event_outcome1.type) === RunFinishedOutcomeType.Success && (message === null || message === void 0 ? void 0 : message.role) === MessageRole.Interrupt) {
|
|
@@ -618,3 +664,18 @@ import { CustomEventName, EventType, FlowTaskState, RunFinishedOutcomeType } fro
|
|
|
618
664
|
this.onStartCallback = params === null || params === void 0 ? void 0 : params.onStart;
|
|
619
665
|
}
|
|
620
666
|
}
|
|
667
|
+
/** chat_completion 快照可能是 camelCase 或 REST snake_case,统一落到 createdAt */ function normalizeSnapshotMessage(message) {
|
|
668
|
+
const createdAt = resolveMessageCreatedAt(message);
|
|
669
|
+
return createdAt ? _object_spread_props(_object_spread({}, message), {
|
|
670
|
+
createdAt
|
|
671
|
+
}) : message;
|
|
672
|
+
}
|
|
673
|
+
/** 从列表尾部向前,给本轮尚未带时间的消息补 createdAt,遇到已有时间的历史消息即停 */ function applyCreatedAtToCurrentRun(messages, createdAt) {
|
|
674
|
+
for(let index = messages.length - 1; index >= 0; index--){
|
|
675
|
+
const item = messages[index];
|
|
676
|
+
if (item.createdAt) {
|
|
677
|
+
break;
|
|
678
|
+
}
|
|
679
|
+
item.createdAt = createdAt;
|
|
680
|
+
}
|
|
681
|
+
}
|
package/dist/event/type.d.ts
CHANGED
|
@@ -74,20 +74,23 @@ function _object_spread_props(target, source) {
|
|
|
74
74
|
}
|
|
75
75
|
return target;
|
|
76
76
|
}
|
|
77
|
-
import { ActivityType, MessageRole, MessageType } from '../../message/type.ts.js';
|
|
77
|
+
import { ActivityType, MessageRole, MessageType, resolveMessageCreatedAt } from '../../message/type.ts.js';
|
|
78
78
|
/**
|
|
79
79
|
* 将 API 返回的消息数据转换为前端使用的消息数据
|
|
80
80
|
* @param data API 返回的消息数据
|
|
81
81
|
* @returns 前端使用的消息数据
|
|
82
82
|
*/ export const transferMessageApi2Message = (data)=>{
|
|
83
|
-
const
|
|
83
|
+
const createdAt = resolveMessageCreatedAt(data);
|
|
84
|
+
const baseMessage = _object_spread_props(_object_spread({}, createdAt ? {
|
|
85
|
+
createdAt
|
|
86
|
+
} : {}), {
|
|
84
87
|
id: data.id,
|
|
85
88
|
messageId: data.message_id,
|
|
86
89
|
name: data.name,
|
|
87
90
|
role: data.role,
|
|
88
91
|
sessionCode: data.session_code,
|
|
89
92
|
status: data.status
|
|
90
|
-
};
|
|
93
|
+
});
|
|
91
94
|
// 处理不同类型的消息
|
|
92
95
|
switch(data.role){
|
|
93
96
|
case MessageRole.Activity:
|
|
@@ -351,14 +354,17 @@ import { ActivityType, MessageRole, MessageType } from '../../message/type.ts.js
|
|
|
351
354
|
* @param data 前端使用的消息数据
|
|
352
355
|
* @returns API 使用的消息数据
|
|
353
356
|
*/ export const transferMessage2MessageApi = (data)=>{
|
|
354
|
-
const
|
|
357
|
+
const createdAt = resolveMessageCreatedAt(data);
|
|
358
|
+
const baseMessage = _object_spread_props(_object_spread({}, createdAt ? {
|
|
359
|
+
created_at: createdAt
|
|
360
|
+
} : {}), {
|
|
355
361
|
id: data.id,
|
|
356
362
|
message_id: data.messageId,
|
|
357
363
|
name: data.name,
|
|
358
364
|
role: data.role,
|
|
359
365
|
session_code: data.sessionCode,
|
|
360
366
|
status: data.status
|
|
361
|
-
};
|
|
367
|
+
});
|
|
362
368
|
// 处理不同类型的消息
|
|
363
369
|
switch(data.role){
|
|
364
370
|
case MessageRole.Activity:
|