@ai-group/chat-sdk 2.1.13 → 2.1.14
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/cjs/components/XAdkChatbot/components/FunctionCallRender/index.d.ts +1 -1
- package/dist/cjs/components/XAdkChatbot/components/FunctionCallRender/index.js +41 -5
- package/dist/cjs/components/XAdkChatbot/components/FunctionCallRender/index.js.map +2 -2
- package/dist/cjs/components/XAdkChatbot/components/FunctionCallRender/styles.d.ts +1 -0
- package/dist/cjs/components/XAdkChatbot/components/FunctionCallRender/styles.js +14 -3
- package/dist/cjs/components/XAdkChatbot/components/FunctionCallRender/styles.js.map +2 -2
- package/dist/cjs/components/XAdkChatbot/index.d.ts +1 -1
- package/dist/cjs/components/XAdkChatbot/index.js +30 -13
- package/dist/cjs/components/XAdkChatbot/index.js.map +3 -3
- package/dist/cjs/components/XAdkWebProvider/XAdkWebProvider.stories.d.ts +2 -2
- package/dist/cjs/components/XAdkWebProvider/XAdkWebProvider.stories.js +26 -9
- package/dist/cjs/components/XAdkWebProvider/XAdkWebProvider.stories.js.map +2 -2
- package/dist/cjs/components/XAiThoughtChain/XAiThoughtChain.stories.d.ts +6 -0
- package/dist/cjs/components/XAiThoughtChain/XAiThoughtChain.stories.js +180 -0
- package/dist/cjs/components/XAiThoughtChain/XAiThoughtChain.stories.js.map +7 -0
- package/dist/cjs/components/XAiThoughtChain/index.d.ts +4 -0
- package/dist/cjs/components/XAiThoughtChain/index.js +155 -0
- package/dist/cjs/components/XAiThoughtChain/index.js.map +7 -0
- package/dist/cjs/components/XAiThoughtChain/styles.d.ts +60 -0
- package/dist/cjs/components/XAiThoughtChain/styles.js +195 -0
- package/dist/cjs/components/XAiThoughtChain/styles.js.map +7 -0
- package/dist/cjs/hooks/useADKChat.d.ts +2 -2
- package/dist/cjs/hooks/useADKChat.js +228 -180
- package/dist/cjs/hooks/useADKChat.js.map +2 -2
- package/dist/cjs/types/XAiThoughtChain.d.ts +25 -0
- package/dist/cjs/types/XAiThoughtChain.js +18 -0
- package/dist/cjs/types/XAiThoughtChain.js.map +7 -0
- package/dist/cjs/types/index.d.ts +9 -8
- package/dist/cjs/types/index.js +2 -0
- package/dist/cjs/types/index.js.map +2 -2
- package/dist/cjs/utils/index.d.ts +1 -0
- package/dist/cjs/utils/index.js +7 -0
- package/dist/cjs/utils/index.js.map +2 -2
- package/dist/esm/components/XAdkChatbot/components/FunctionCallRender/index.d.ts +1 -1
- package/dist/esm/components/XAdkChatbot/components/FunctionCallRender/index.js +17 -15
- package/dist/esm/components/XAdkChatbot/components/FunctionCallRender/index.js.map +1 -1
- package/dist/esm/components/XAdkChatbot/components/FunctionCallRender/styles.d.ts +1 -0
- package/dist/esm/components/XAdkChatbot/components/FunctionCallRender/styles.js +7 -6
- package/dist/esm/components/XAdkChatbot/components/FunctionCallRender/styles.js.map +1 -1
- package/dist/esm/components/XAdkChatbot/index.d.ts +1 -1
- package/dist/esm/components/XAdkChatbot/index.js +20 -18
- package/dist/esm/components/XAdkChatbot/index.js.map +1 -1
- package/dist/esm/components/XAdkWebProvider/XAdkWebProvider.stories.d.ts +2 -2
- package/dist/esm/components/XAdkWebProvider/XAdkWebProvider.stories.js +45 -40
- package/dist/esm/components/XAdkWebProvider/XAdkWebProvider.stories.js.map +1 -1
- package/dist/esm/components/XAiThoughtChain/XAiThoughtChain.stories.d.ts +6 -0
- package/dist/esm/components/XAiThoughtChain/XAiThoughtChain.stories.js +159 -0
- package/dist/esm/components/XAiThoughtChain/XAiThoughtChain.stories.js.map +1 -0
- package/dist/esm/components/XAiThoughtChain/index.d.ts +4 -0
- package/dist/esm/components/XAiThoughtChain/index.js +180 -0
- package/dist/esm/components/XAiThoughtChain/index.js.map +1 -0
- package/dist/esm/components/XAiThoughtChain/styles.d.ts +60 -0
- package/dist/esm/components/XAiThoughtChain/styles.js +40 -0
- package/dist/esm/components/XAiThoughtChain/styles.js.map +1 -0
- package/dist/esm/hooks/useADKChat.d.ts +2 -2
- package/dist/esm/hooks/useADKChat.js +59 -57
- package/dist/esm/hooks/useADKChat.js.map +1 -1
- package/dist/esm/types/XAiThoughtChain.d.ts +25 -0
- package/dist/esm/types/XAiThoughtChain.js +2 -0
- package/dist/esm/types/XAiThoughtChain.js.map +1 -0
- package/dist/esm/types/index.d.ts +9 -8
- package/dist/esm/types/index.js +1 -0
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm/utils/index.d.ts +1 -0
- package/dist/esm/utils/index.js +4 -0
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/umd/chat-sdk.min.js +1 -1
- package/package.json +1 -1
|
@@ -4,10 +4,10 @@ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
|
4
4
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
5
5
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
6
6
|
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
7
|
-
import { useEffect, useCallback, useMemo, useRef, useState } from
|
|
8
|
-
import { fetchEventSource, EventStreamContentType } from
|
|
9
|
-
import { message } from
|
|
10
|
-
import { v4 } from
|
|
7
|
+
import { useEffect, useCallback, useMemo, useRef, useState } from "react";
|
|
8
|
+
import { fetchEventSource, EventStreamContentType } from "@microsoft/fetch-event-source";
|
|
9
|
+
import { message } from "antd";
|
|
10
|
+
import { v4 } from "uuid";
|
|
11
11
|
import { SESSION_PAGE_SIZE, API_SUCCESS_CODE } from "../constants";
|
|
12
12
|
import { SuccessCode, ErrorCode } from "../types";
|
|
13
13
|
import { fetchAppConfig, fetchSessionList, fetchSessionDetail, closeSession, updateSessionTitle } from "../services/api";
|
|
@@ -48,7 +48,7 @@ function useADKChat(_ref) {
|
|
|
48
48
|
_ref$config = _ref.config,
|
|
49
49
|
config = _ref$config === void 0 ? {} : _ref$config,
|
|
50
50
|
_ref$type = _ref.type,
|
|
51
|
-
type = _ref$type === void 0 ?
|
|
51
|
+
type = _ref$type === void 0 ? "agentDebug" : _ref$type,
|
|
52
52
|
onError = _ref.onError,
|
|
53
53
|
onMessage = _ref.onMessage,
|
|
54
54
|
onSuccess = _ref.onSuccess,
|
|
@@ -77,7 +77,9 @@ function useADKChat(_ref) {
|
|
|
77
77
|
sessionList = _useState8[0],
|
|
78
78
|
setSessionList = _useState8[1];
|
|
79
79
|
// 当前会话
|
|
80
|
-
var _useState9 = useState(
|
|
80
|
+
var _useState9 = useState(function () {
|
|
81
|
+
return v4();
|
|
82
|
+
}),
|
|
81
83
|
_useState10 = _slicedToArray(_useState9, 2),
|
|
82
84
|
currentSessionId = _useState10[0],
|
|
83
85
|
setCurrentSessionId = _useState10[1];
|
|
@@ -91,7 +93,7 @@ function useADKChat(_ref) {
|
|
|
91
93
|
sessionPagination = _useState12[0],
|
|
92
94
|
setSessionPagination = _useState12[1];
|
|
93
95
|
// 开场白
|
|
94
|
-
var _useState13 = useState(
|
|
96
|
+
var _useState13 = useState(""),
|
|
95
97
|
_useState14 = _slicedToArray(_useState13, 2),
|
|
96
98
|
prologue = _useState14[0],
|
|
97
99
|
setPrologue = _useState14[1];
|
|
@@ -109,14 +111,14 @@ function useADKChat(_ref) {
|
|
|
109
111
|
messages.forEach(function (msg) {
|
|
110
112
|
if (msg.functionResponse) {
|
|
111
113
|
var _msg$functionResponse;
|
|
112
|
-
fnResMap[(msg === null || msg === void 0 || (_msg$functionResponse = msg.functionResponse) === null || _msg$functionResponse === void 0 ? void 0 : _msg$functionResponse.id) ||
|
|
114
|
+
fnResMap[(msg === null || msg === void 0 || (_msg$functionResponse = msg.functionResponse) === null || _msg$functionResponse === void 0 ? void 0 : _msg$functionResponse.id) || ""] = msg.functionResponse;
|
|
113
115
|
}
|
|
114
116
|
});
|
|
115
117
|
return messages.map(function (msg) {
|
|
116
118
|
if (msg.functionCall) {
|
|
117
119
|
var _msg$functionCall;
|
|
118
120
|
return _objectSpread(_objectSpread({}, msg), {}, {
|
|
119
|
-
functionResponse: fnResMap[(msg === null || msg === void 0 || (_msg$functionCall = msg.functionCall) === null || _msg$functionCall === void 0 ? void 0 : _msg$functionCall.id) ||
|
|
121
|
+
functionResponse: fnResMap[(msg === null || msg === void 0 || (_msg$functionCall = msg.functionCall) === null || _msg$functionCall === void 0 ? void 0 : _msg$functionCall.id) || ""]
|
|
120
122
|
});
|
|
121
123
|
}
|
|
122
124
|
return msg;
|
|
@@ -144,7 +146,6 @@ function useADKChat(_ref) {
|
|
|
144
146
|
if (messages.length === 0 && suggested_questions.length) {
|
|
145
147
|
setSuggestedQuestions(suggested_questions);
|
|
146
148
|
}
|
|
147
|
-
;
|
|
148
149
|
};
|
|
149
150
|
|
|
150
151
|
// 初始化开场白
|
|
@@ -169,9 +170,9 @@ function useADKChat(_ref) {
|
|
|
169
170
|
// 存储事件
|
|
170
171
|
var storeEvents = useCallback(function (part, event) {
|
|
171
172
|
var _event$actions;
|
|
172
|
-
var title =
|
|
173
|
+
var title = "";
|
|
173
174
|
if (part == null && (_event$actions = event.actions) !== null && _event$actions !== void 0 && _event$actions.artifactDelta) {
|
|
174
|
-
title +=
|
|
175
|
+
title += "eventAction: artifact";
|
|
175
176
|
} else if (part) {
|
|
176
177
|
if (part.text) {
|
|
177
178
|
title += "text:".concat(part.text);
|
|
@@ -250,7 +251,7 @@ function useADKChat(_ref) {
|
|
|
250
251
|
invocationId: event.invocationId,
|
|
251
252
|
eventId: event.id,
|
|
252
253
|
timestamp: event.timestamp,
|
|
253
|
-
role:
|
|
254
|
+
role: "bot",
|
|
254
255
|
text: newChunk,
|
|
255
256
|
thought: part.thought
|
|
256
257
|
};
|
|
@@ -274,14 +275,14 @@ function useADKChat(_ref) {
|
|
|
274
275
|
});
|
|
275
276
|
}
|
|
276
277
|
textMsgRef.current = _objectSpread(_objectSpread({}, textMsgRef.current), {}, {
|
|
277
|
-
text: (textMsgRef.current.text ||
|
|
278
|
+
text: (textMsgRef.current.text || "") + newChunk
|
|
278
279
|
});
|
|
279
280
|
updateMessage(textMsgRef.current);
|
|
280
281
|
}
|
|
281
282
|
} else {
|
|
282
283
|
textMsgRef.current = null;
|
|
283
284
|
storeEvents(part, event);
|
|
284
|
-
storeMessage(part, event,
|
|
285
|
+
storeMessage(part, event, "bot");
|
|
285
286
|
}
|
|
286
287
|
}, [storeEvents, storeMessage, insertMessage, updateMessage]);
|
|
287
288
|
|
|
@@ -290,7 +291,7 @@ function useADKChat(_ref) {
|
|
|
290
291
|
var _event$content;
|
|
291
292
|
// 获取建议类消息的文本内容
|
|
292
293
|
var part = (event === null || event === void 0 || (_event$content = event.content) === null || _event$content === void 0 || (_event$content = _event$content.parts) === null || _event$content === void 0 ? void 0 : _event$content[0]) || null;
|
|
293
|
-
var text = (part === null || part === void 0 ? void 0 : part.text) ||
|
|
294
|
+
var text = (part === null || part === void 0 ? void 0 : part.text) || "";
|
|
294
295
|
storeEvents(part, event);
|
|
295
296
|
if (text) {
|
|
296
297
|
setSuggestedQuestions(function (prev) {
|
|
@@ -305,7 +306,7 @@ function useADKChat(_ref) {
|
|
|
305
306
|
insertMessage({
|
|
306
307
|
id: v4(),
|
|
307
308
|
text: chunkJson.errorMessage,
|
|
308
|
-
role:
|
|
309
|
+
role: "bot"
|
|
309
310
|
});
|
|
310
311
|
}, [storeEvents, insertMessage]);
|
|
311
312
|
|
|
@@ -313,7 +314,7 @@ function useADKChat(_ref) {
|
|
|
313
314
|
var processActionArtifact = useCallback(function (event) {
|
|
314
315
|
if (event.actions && event.actions.artifactDelta) {
|
|
315
316
|
storeEvents(null, event);
|
|
316
|
-
storeMessage(null, event,
|
|
317
|
+
storeMessage(null, event, "bot");
|
|
317
318
|
}
|
|
318
319
|
}, [storeEvents, storeMessage]);
|
|
319
320
|
|
|
@@ -327,14 +328,14 @@ function useADKChat(_ref) {
|
|
|
327
328
|
ctrl.current = new AbortController();
|
|
328
329
|
var requestUrl = "".concat(url, "/api/gateway-web/openApi/v1/aizt/app/").concat(appNo, "/sendMsgStreaming");
|
|
329
330
|
fetchEventSource(requestUrl, {
|
|
330
|
-
method:
|
|
331
|
+
method: "POST",
|
|
331
332
|
signal: ctrl.current.signal,
|
|
332
333
|
body: JSON.stringify(values),
|
|
333
334
|
openWhenHidden: true,
|
|
334
335
|
headers: {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
stream:
|
|
336
|
+
"Content-Type": "application/json",
|
|
337
|
+
"Cache-Control": "no-cache",
|
|
338
|
+
stream: "true",
|
|
338
339
|
Authorization: "Bearer ".concat(token)
|
|
339
340
|
},
|
|
340
341
|
onopen: function onopen(response) {
|
|
@@ -342,7 +343,7 @@ function useADKChat(_ref) {
|
|
|
342
343
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
343
344
|
while (1) switch (_context.prev = _context.next) {
|
|
344
345
|
case 0:
|
|
345
|
-
if (response.ok && response.headers.get(
|
|
346
|
+
if (response.ok && response.headers.get("content-type") === EventStreamContentType) {
|
|
346
347
|
// everything's good
|
|
347
348
|
} else if (response.status >= 400 && response.status < 500 && response.status !== 429) {
|
|
348
349
|
resolve();
|
|
@@ -364,8 +365,8 @@ function useADKChat(_ref) {
|
|
|
364
365
|
}
|
|
365
366
|
onStream === null || onStream === void 0 || onStream(chunkJson);
|
|
366
367
|
if (chunkJson.content) {
|
|
367
|
-
// 建议类消息单独处理
|
|
368
|
-
if (chunkJson.content.role ===
|
|
368
|
+
// 建议类消息单独处理
|
|
369
|
+
if (chunkJson.content.role === "followup") {
|
|
369
370
|
processFollowupPart(chunkJson);
|
|
370
371
|
return;
|
|
371
372
|
}
|
|
@@ -392,7 +393,7 @@ function useADKChat(_ref) {
|
|
|
392
393
|
setLoading(false);
|
|
393
394
|
if (textMsgRef.current) {
|
|
394
395
|
var _textMsgRef$current;
|
|
395
|
-
onMessage === null || onMessage === void 0 || onMessage(((_textMsgRef$current = textMsgRef.current) === null || _textMsgRef$current === void 0 ? void 0 : _textMsgRef$current.text) ||
|
|
396
|
+
onMessage === null || onMessage === void 0 || onMessage(((_textMsgRef$current = textMsgRef.current) === null || _textMsgRef$current === void 0 ? void 0 : _textMsgRef$current.text) || "", textMsgRef.current);
|
|
396
397
|
}
|
|
397
398
|
textMsgRef.current = null;
|
|
398
399
|
resolve();
|
|
@@ -400,7 +401,7 @@ function useADKChat(_ref) {
|
|
|
400
401
|
onerror: function onerror(error) {
|
|
401
402
|
setLoading(false);
|
|
402
403
|
resolve();
|
|
403
|
-
console.error(
|
|
404
|
+
console.error("EventSource failed:", error);
|
|
404
405
|
throw error;
|
|
405
406
|
}
|
|
406
407
|
});
|
|
@@ -414,19 +415,20 @@ function useADKChat(_ref) {
|
|
|
414
415
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
415
416
|
while (1) switch (_context2.prev = _context2.next) {
|
|
416
417
|
case 0:
|
|
417
|
-
_ref3$text = _ref3.text, text = _ref3$text === void 0 ?
|
|
418
|
+
_ref3$text = _ref3.text, text = _ref3$text === void 0 ? "" : _ref3$text, _ref3$files = _ref3.files, files = _ref3$files === void 0 ? [] : _ref3$files, functionResponse = _ref3.functionResponse;
|
|
419
|
+
console.log(text, loading);
|
|
418
420
|
if (!loading) {
|
|
419
|
-
_context2.next =
|
|
421
|
+
_context2.next = 4;
|
|
420
422
|
break;
|
|
421
423
|
}
|
|
422
424
|
return _context2.abrupt("return");
|
|
423
|
-
case
|
|
425
|
+
case 4:
|
|
424
426
|
if (!(!text.trim() && !functionResponse)) {
|
|
425
|
-
_context2.next =
|
|
427
|
+
_context2.next = 6;
|
|
426
428
|
break;
|
|
427
429
|
}
|
|
428
430
|
return _context2.abrupt("return");
|
|
429
|
-
case
|
|
431
|
+
case 6:
|
|
430
432
|
// 清空建议问题
|
|
431
433
|
setSuggestedQuestions([]);
|
|
432
434
|
// 发送消息
|
|
@@ -436,7 +438,7 @@ function useADKChat(_ref) {
|
|
|
436
438
|
if (text.trim()) {
|
|
437
439
|
temp.push({
|
|
438
440
|
id: v4(),
|
|
439
|
-
role:
|
|
441
|
+
role: "user",
|
|
440
442
|
text: text
|
|
441
443
|
});
|
|
442
444
|
}
|
|
@@ -444,7 +446,7 @@ function useADKChat(_ref) {
|
|
|
444
446
|
if (files.length > 0) {
|
|
445
447
|
temp.push({
|
|
446
448
|
id: v4(),
|
|
447
|
-
role:
|
|
449
|
+
role: "user",
|
|
448
450
|
fileData: files.map(function (file) {
|
|
449
451
|
var _file$response, _file$response2;
|
|
450
452
|
return {
|
|
@@ -459,18 +461,18 @@ function useADKChat(_ref) {
|
|
|
459
461
|
if (functionResponse) {
|
|
460
462
|
temp.push({
|
|
461
463
|
id: v4(),
|
|
462
|
-
role:
|
|
464
|
+
role: "user",
|
|
463
465
|
functionResponse: functionResponse
|
|
464
466
|
});
|
|
465
467
|
}
|
|
466
468
|
return temp;
|
|
467
469
|
});
|
|
468
|
-
_context2.next =
|
|
470
|
+
_context2.next = 10;
|
|
469
471
|
return sendMessageRequest({
|
|
470
472
|
stream: true,
|
|
471
473
|
sessionId: currentSessionId,
|
|
472
474
|
content: {
|
|
473
|
-
role:
|
|
475
|
+
role: "user",
|
|
474
476
|
parts: functionResponse ? [{
|
|
475
477
|
functionResponse: functionResponse
|
|
476
478
|
}] : [{
|
|
@@ -488,10 +490,10 @@ function useADKChat(_ref) {
|
|
|
488
490
|
};
|
|
489
491
|
})
|
|
490
492
|
});
|
|
491
|
-
case
|
|
493
|
+
case 10:
|
|
492
494
|
// 获取聊天记录
|
|
493
495
|
initAppConversations();
|
|
494
|
-
case
|
|
496
|
+
case 11:
|
|
495
497
|
case "end":
|
|
496
498
|
return _context2.stop();
|
|
497
499
|
}
|
|
@@ -510,7 +512,7 @@ function useADKChat(_ref) {
|
|
|
510
512
|
var newMessages = _toConsumableArray(prev);
|
|
511
513
|
// 删除最后一条 AI 消息
|
|
512
514
|
var lastAIIndex = newMessages.findLastIndex(function (msg) {
|
|
513
|
-
return msg.role ===
|
|
515
|
+
return msg.role === "bot";
|
|
514
516
|
});
|
|
515
517
|
if (lastAIIndex !== -1) {
|
|
516
518
|
newMessages.splice(lastAIIndex, 1);
|
|
@@ -519,18 +521,18 @@ function useADKChat(_ref) {
|
|
|
519
521
|
setSuggestedQuestions([]);
|
|
520
522
|
// 重新发送最后一条用户消息
|
|
521
523
|
var lastUserMessage = newMessages.findLast(function (msg) {
|
|
522
|
-
return msg.role ===
|
|
524
|
+
return msg.role === "user";
|
|
523
525
|
});
|
|
524
526
|
if (lastUserMessage) {
|
|
525
527
|
var _lastUserMessage$text = lastUserMessage.text,
|
|
526
|
-
text = _lastUserMessage$text === void 0 ?
|
|
528
|
+
text = _lastUserMessage$text === void 0 ? "" : _lastUserMessage$text,
|
|
527
529
|
_lastUserMessage$file = lastUserMessage.fileData,
|
|
528
530
|
fileData = _lastUserMessage$file === void 0 ? [] : _lastUserMessage$file;
|
|
529
531
|
sendMessageRequest({
|
|
530
532
|
stream: true,
|
|
531
533
|
sessionId: currentSessionId,
|
|
532
534
|
content: {
|
|
533
|
-
role:
|
|
535
|
+
role: "user",
|
|
534
536
|
parts: [{
|
|
535
537
|
text: text
|
|
536
538
|
}]
|
|
@@ -586,7 +588,7 @@ function useADKChat(_ref) {
|
|
|
586
588
|
setCurrentSessionId(newSessionId);
|
|
587
589
|
// 重置聊天内容
|
|
588
590
|
stopChat();
|
|
589
|
-
setPrologue((appInfo === null || appInfo === void 0 || (_appInfo$onboardingIn = appInfo.onboardingInfo) === null || _appInfo$onboardingIn === void 0 ? void 0 : _appInfo$onboardingIn.prologue) ||
|
|
591
|
+
setPrologue((appInfo === null || appInfo === void 0 || (_appInfo$onboardingIn = appInfo.onboardingInfo) === null || _appInfo$onboardingIn === void 0 ? void 0 : _appInfo$onboardingIn.prologue) || "");
|
|
590
592
|
setMessages([]);
|
|
591
593
|
setSuggestedQuestions((appInfo === null || appInfo === void 0 || (_appInfo$onboardingIn2 = appInfo.onboardingInfo) === null || _appInfo$onboardingIn2 === void 0 ? void 0 : _appInfo$onboardingIn2.suggested_questions) || []);
|
|
592
594
|
};
|
|
@@ -597,7 +599,7 @@ function useADKChat(_ref) {
|
|
|
597
599
|
var mapped = [];
|
|
598
600
|
messages.forEach(function (item) {
|
|
599
601
|
if (!item || !item.content || !Array.isArray(item.content.parts)) return;
|
|
600
|
-
var role = (item.content.role ||
|
|
602
|
+
var role = (item.content.role || "").toLowerCase() === "user" ? "user" : "bot";
|
|
601
603
|
var parts = Array.isArray(item.content.parts) ? item.content.parts.filter(function (p) {
|
|
602
604
|
if (!p) return false;
|
|
603
605
|
return Boolean(p.text || p.inlineData || p.functionCall || p.functionResponse || p.fileData || p.executableCode || p.codeExecutionResult || p.errorMessage);
|
|
@@ -622,12 +624,12 @@ function useADKChat(_ref) {
|
|
|
622
624
|
}
|
|
623
625
|
if (part.text) {
|
|
624
626
|
msg.text = part.text;
|
|
625
|
-
if (typeof part.thought !==
|
|
627
|
+
if (typeof part.thought !== "undefined") msg.thought = part.thought;
|
|
626
628
|
}
|
|
627
629
|
if (part.functionCall) msg.functionCall = part.functionCall;
|
|
628
630
|
if (part.fileData) {
|
|
629
631
|
msg.inlineData = {
|
|
630
|
-
displayName: part.fileData.displayName ||
|
|
632
|
+
displayName: part.fileData.displayName || "",
|
|
631
633
|
data: part.fileData.fileUri,
|
|
632
634
|
mimeType: part.fileData.mimeType
|
|
633
635
|
};
|
|
@@ -685,7 +687,7 @@ function useADKChat(_ref) {
|
|
|
685
687
|
data = _yield$fetchSessionDe.data;
|
|
686
688
|
result = _yield$fetchSessionDe.result;
|
|
687
689
|
if ((result === null || result === void 0 ? void 0 : result.code) === API_SUCCESS_CODE) {
|
|
688
|
-
setPrologue((appInfo === null || appInfo === void 0 || (_appInfo$onboardingIn3 = appInfo.onboardingInfo) === null || _appInfo$onboardingIn3 === void 0 ? void 0 : _appInfo$onboardingIn3.prologue) ||
|
|
690
|
+
setPrologue((appInfo === null || appInfo === void 0 || (_appInfo$onboardingIn3 = appInfo.onboardingInfo) === null || _appInfo$onboardingIn3 === void 0 ? void 0 : _appInfo$onboardingIn3.prologue) || "");
|
|
689
691
|
// 新接口直接返回按 event/item 结构的数组,传入 formatMessages 处理
|
|
690
692
|
if (Array.isArray(data) && data.length > 0) {
|
|
691
693
|
formatMessages(data, true);
|
|
@@ -748,7 +750,7 @@ function useADKChat(_ref) {
|
|
|
748
750
|
formatSessions = data.map(function (item) {
|
|
749
751
|
return {
|
|
750
752
|
key: item.sessionId,
|
|
751
|
-
label: item.title ||
|
|
753
|
+
label: item.title || "新对话",
|
|
752
754
|
timestamp: new Date(item.startTime).getTime(),
|
|
753
755
|
messages: [],
|
|
754
756
|
meta: _objectSpread({}, item)
|
|
@@ -765,14 +767,14 @@ function useADKChat(_ref) {
|
|
|
765
767
|
if (showFirstSession) {
|
|
766
768
|
fetchDetail && setCurrentSessionDetail(sessionId);
|
|
767
769
|
} else {
|
|
768
|
-
setPrologue((appInfo === null || appInfo === void 0 || (_appInfo$onboardingIn5 = appInfo.onboardingInfo) === null || _appInfo$onboardingIn5 === void 0 ? void 0 : _appInfo$onboardingIn5.prologue) ||
|
|
770
|
+
setPrologue((appInfo === null || appInfo === void 0 || (_appInfo$onboardingIn5 = appInfo.onboardingInfo) === null || _appInfo$onboardingIn5 === void 0 ? void 0 : _appInfo$onboardingIn5.prologue) || "");
|
|
769
771
|
setSuggestedQuestions((appInfo === null || appInfo === void 0 || (_appInfo$onboardingIn6 = appInfo.onboardingInfo) === null || _appInfo$onboardingIn6 === void 0 ? void 0 : _appInfo$onboardingIn6.suggested_questions) || []);
|
|
770
772
|
}
|
|
771
773
|
// 成功回调
|
|
772
774
|
if (!initialized) {
|
|
773
775
|
onSuccess === null || onSuccess === void 0 || onSuccess({
|
|
774
776
|
code: SuccessCode.APP_MESSAGES_INIT_SUCCESS,
|
|
775
|
-
message:
|
|
777
|
+
message: "初始化聊天记录成功",
|
|
776
778
|
data: {
|
|
777
779
|
sessionId: sessionId
|
|
778
780
|
}
|
|
@@ -786,7 +788,7 @@ function useADKChat(_ref) {
|
|
|
786
788
|
} else {
|
|
787
789
|
setSessionList([]);
|
|
788
790
|
setCurrentSessionId(v4());
|
|
789
|
-
setPrologue(
|
|
791
|
+
setPrologue("");
|
|
790
792
|
setSuggestedQuestions([]);
|
|
791
793
|
}
|
|
792
794
|
_context4.next = 15;
|
|
@@ -840,7 +842,7 @@ function useADKChat(_ref) {
|
|
|
840
842
|
clearChat();
|
|
841
843
|
}
|
|
842
844
|
} else {
|
|
843
|
-
message.error(
|
|
845
|
+
message.error("删除会话失败");
|
|
844
846
|
}
|
|
845
847
|
case 7:
|
|
846
848
|
case "end":
|
|
@@ -881,7 +883,7 @@ function useADKChat(_ref) {
|
|
|
881
883
|
// 编辑成功后,重新获取会话列表
|
|
882
884
|
initAppConversations();
|
|
883
885
|
} else {
|
|
884
|
-
message.error(
|
|
886
|
+
message.error("更新会话失败");
|
|
885
887
|
}
|
|
886
888
|
case 7:
|
|
887
889
|
case "end":
|
|
@@ -917,12 +919,12 @@ function useADKChat(_ref) {
|
|
|
917
919
|
// 成功回调
|
|
918
920
|
onSuccess === null || onSuccess === void 0 || onSuccess({
|
|
919
921
|
code: SuccessCode.APP_CONFIG_INIT_SUCCESS,
|
|
920
|
-
message:
|
|
922
|
+
message: "初始化配置成功"
|
|
921
923
|
});
|
|
922
924
|
} else {
|
|
923
925
|
onError === null || onError === void 0 || onError({
|
|
924
926
|
code: result.code || ErrorCode.APP_NOT_FOUND,
|
|
925
|
-
message: result.message ||
|
|
927
|
+
message: result.message || "获取应用配置失败"
|
|
926
928
|
});
|
|
927
929
|
}
|
|
928
930
|
_context7.next = 13;
|
|
@@ -932,7 +934,7 @@ function useADKChat(_ref) {
|
|
|
932
934
|
_context7.t0 = _context7["catch"](0);
|
|
933
935
|
onError === null || onError === void 0 || onError({
|
|
934
936
|
code: ErrorCode.API_ERROR,
|
|
935
|
-
message:
|
|
937
|
+
message: "获取应用配置失败"
|
|
936
938
|
});
|
|
937
939
|
case 13:
|
|
938
940
|
_context7.prev = 13;
|