@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
|
@@ -3,7 +3,7 @@ import { DebugOptions, FunctionCall, SendContent, SessionData, Event, IMessage,
|
|
|
3
3
|
import { type ChatConfig } from "../services/api";
|
|
4
4
|
declare function useADKChat({ url, token, config, type, onError, onMessage, onSuccess, onStream, }: DebugOptions): {
|
|
5
5
|
appInfo: ChatConfig | null;
|
|
6
|
-
startChat: ({ text, files, functionResponse }: SendContent) => Promise<void>;
|
|
6
|
+
startChat: ({ text, files, functionResponse, }: SendContent) => Promise<void>;
|
|
7
7
|
reChat: () => void;
|
|
8
8
|
stopChat: () => void;
|
|
9
9
|
clearChat: () => void;
|
|
@@ -24,6 +24,6 @@ declare function useADKChat({ url, token, config, type, onError, onMessage, onSu
|
|
|
24
24
|
setCurrentSessionDetail: (sessionId: string) => Promise<void>;
|
|
25
25
|
setMessages: import("react").Dispatch<import("react").SetStateAction<IMessage[]>>;
|
|
26
26
|
storeEvents: (part: Part | null, event: any) => void;
|
|
27
|
-
storeMessage: (part: Part | null, event: Event, role:
|
|
27
|
+
storeMessage: (part: Part | null, event: Event, role: "user" | "bot") => void;
|
|
28
28
|
};
|
|
29
29
|
export default useADKChat;
|
|
@@ -64,8 +64,12 @@ function useADKChat({
|
|
|
64
64
|
const [appInfo, setAppInfo] = (0, import_react.useState)(null);
|
|
65
65
|
const [initialized, setInitialized] = (0, import_react.useState)(false);
|
|
66
66
|
const [sessionList, setSessionList] = (0, import_react.useState)([]);
|
|
67
|
-
const [currentSessionId, setCurrentSessionId] = (0, import_react.useState)(
|
|
68
|
-
const [sessionPagination, setSessionPagination] = (0, import_react.useState)({
|
|
67
|
+
const [currentSessionId, setCurrentSessionId] = (0, import_react.useState)(() => (0, import_uuid.v4)());
|
|
68
|
+
const [sessionPagination, setSessionPagination] = (0, import_react.useState)({
|
|
69
|
+
total: 0,
|
|
70
|
+
pageNum: 1,
|
|
71
|
+
pageSize: import_constants.SESSION_PAGE_SIZE
|
|
72
|
+
});
|
|
69
73
|
const [prologue, setPrologue] = (0, import_react.useState)("");
|
|
70
74
|
const [suggestedQuestions, setSuggestedQuestions] = (0, import_react.useState)([]);
|
|
71
75
|
const [messages, setMessages] = (0, import_react.useState)([]);
|
|
@@ -105,7 +109,6 @@ function useADKChat({
|
|
|
105
109
|
if (messages.length === 0 && suggested_questions.length) {
|
|
106
110
|
setSuggestedQuestions(suggested_questions);
|
|
107
111
|
}
|
|
108
|
-
;
|
|
109
112
|
};
|
|
110
113
|
const insertPrologue = (prologue2) => {
|
|
111
114
|
if (prologue2) {
|
|
@@ -147,185 +150,210 @@ function useADKChat({
|
|
|
147
150
|
newEventData.set(event.id, updatedEvent);
|
|
148
151
|
eventDataRef.current = newEventData;
|
|
149
152
|
}, []);
|
|
150
|
-
const storeMessage = (0, import_react.useCallback)(
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
if (part
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
153
|
+
const storeMessage = (0, import_react.useCallback)(
|
|
154
|
+
(part, event, role) => {
|
|
155
|
+
var _a, _b;
|
|
156
|
+
const msg = {
|
|
157
|
+
id: (0, import_uuid.v4)(),
|
|
158
|
+
author: event.author,
|
|
159
|
+
invocationId: event.invocationId,
|
|
160
|
+
eventId: event.id,
|
|
161
|
+
timestamp: event.timestamp,
|
|
162
|
+
role
|
|
163
|
+
};
|
|
164
|
+
if (part) {
|
|
165
|
+
if (part.inlineData) {
|
|
166
|
+
msg.inlineData = {
|
|
167
|
+
displayName: part.inlineData.displayName,
|
|
168
|
+
data: part.inlineData.data,
|
|
169
|
+
mimeType: part.inlineData.mimeType
|
|
170
|
+
};
|
|
171
|
+
} else if (part.text) {
|
|
172
|
+
msg.text = part.text;
|
|
173
|
+
msg.thought = part.thought;
|
|
174
|
+
if ((_b = (_a = event == null ? void 0 : event.groundingMetadata) == null ? void 0 : _a.searchEntryPoint) == null ? void 0 : _b.renderedContent) {
|
|
175
|
+
msg.renderedContent = event.groundingMetadata.searchEntryPoint.renderedContent;
|
|
176
|
+
}
|
|
177
|
+
} else if (part.fileData) {
|
|
178
|
+
msg.fileData = [part.fileData];
|
|
179
|
+
} else if (part.functionCall) {
|
|
180
|
+
msg.functionCall = part.functionCall;
|
|
181
|
+
} else if (part.functionResponse) {
|
|
182
|
+
msg.functionResponse = part.functionResponse;
|
|
183
|
+
} else if (part.executableCode) {
|
|
184
|
+
msg.executableCode = part.executableCode;
|
|
185
|
+
} else if (part.codeExecutionResult) {
|
|
186
|
+
msg.codeExecutionResult = part.codeExecutionResult;
|
|
172
187
|
}
|
|
173
|
-
} else if (part.fileData) {
|
|
174
|
-
msg.fileData = [part.fileData];
|
|
175
|
-
} else if (part.functionCall) {
|
|
176
|
-
msg.functionCall = part.functionCall;
|
|
177
|
-
} else if (part.functionResponse) {
|
|
178
|
-
msg.functionResponse = part.functionResponse;
|
|
179
|
-
} else if (part.executableCode) {
|
|
180
|
-
msg.executableCode = part.executableCode;
|
|
181
|
-
} else if (part.codeExecutionResult) {
|
|
182
|
-
msg.codeExecutionResult = part.codeExecutionResult;
|
|
183
188
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const
|
|
194
|
-
if (
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
} else {
|
|
212
|
-
if (event.partial === false) {
|
|
189
|
+
if (part && Object.keys(part).length > 0) {
|
|
190
|
+
insertMessage(msg);
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
[insertMessage]
|
|
194
|
+
);
|
|
195
|
+
const processPart = (0, import_react.useCallback)(
|
|
196
|
+
(event, part) => {
|
|
197
|
+
var _a, _b;
|
|
198
|
+
const renderedContent = (_b = (_a = event.groundingMetadata) == null ? void 0 : _a.searchEntryPoint) == null ? void 0 : _b.renderedContent;
|
|
199
|
+
if (part.text) {
|
|
200
|
+
const newChunk = part.text;
|
|
201
|
+
if (!textMsgRef.current || textMsgRef.current.thought !== part.thought) {
|
|
202
|
+
const newMessage = {
|
|
203
|
+
id: (0, import_uuid.v4)(),
|
|
204
|
+
author: event.author,
|
|
205
|
+
invocationId: event.invocationId,
|
|
206
|
+
eventId: event.id,
|
|
207
|
+
timestamp: event.timestamp,
|
|
208
|
+
role: "bot",
|
|
209
|
+
text: newChunk,
|
|
210
|
+
thought: part.thought
|
|
211
|
+
};
|
|
212
|
+
if (renderedContent) {
|
|
213
|
+
newMessage.renderedContent = renderedContent;
|
|
214
|
+
}
|
|
215
|
+
textMsgRef.current = newMessage;
|
|
213
216
|
storeEvents(part, event);
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
217
|
+
insertMessage(newMessage);
|
|
218
|
+
} else {
|
|
219
|
+
if (event.partial === false) {
|
|
220
|
+
storeEvents(part, event);
|
|
221
|
+
textMsgRef.current = null;
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
if (renderedContent) {
|
|
225
|
+
textMsgRef.current = {
|
|
226
|
+
...textMsgRef.current,
|
|
227
|
+
renderedContent
|
|
228
|
+
};
|
|
229
|
+
}
|
|
218
230
|
textMsgRef.current = {
|
|
219
231
|
...textMsgRef.current,
|
|
220
|
-
|
|
232
|
+
text: (textMsgRef.current.text || "") + newChunk
|
|
221
233
|
};
|
|
234
|
+
updateMessage(textMsgRef.current);
|
|
222
235
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
updateMessage(textMsgRef.current);
|
|
236
|
+
} else {
|
|
237
|
+
textMsgRef.current = null;
|
|
238
|
+
storeEvents(part, event);
|
|
239
|
+
storeMessage(part, event, "bot");
|
|
228
240
|
}
|
|
229
|
-
}
|
|
230
|
-
|
|
241
|
+
},
|
|
242
|
+
[storeEvents, storeMessage, insertMessage, updateMessage]
|
|
243
|
+
);
|
|
244
|
+
const processFollowupPart = (0, import_react.useCallback)(
|
|
245
|
+
(event) => {
|
|
246
|
+
var _a, _b;
|
|
247
|
+
const part = ((_b = (_a = event == null ? void 0 : event.content) == null ? void 0 : _a.parts) == null ? void 0 : _b[0]) || null;
|
|
248
|
+
const text = (part == null ? void 0 : part.text) || "";
|
|
231
249
|
storeEvents(part, event);
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
event,
|
|
235
|
-
"bot"
|
|
236
|
-
);
|
|
237
|
-
}
|
|
238
|
-
}, [storeEvents, storeMessage, insertMessage, updateMessage]);
|
|
239
|
-
const processFollowupPart = (0, import_react.useCallback)((event) => {
|
|
240
|
-
var _a, _b;
|
|
241
|
-
const part = ((_b = (_a = event == null ? void 0 : event.content) == null ? void 0 : _a.parts) == null ? void 0 : _b[0]) || null;
|
|
242
|
-
const text = (part == null ? void 0 : part.text) || "";
|
|
243
|
-
storeEvents(part, event);
|
|
244
|
-
if (text) {
|
|
245
|
-
setSuggestedQuestions((prev) => [...prev, text]);
|
|
246
|
-
}
|
|
247
|
-
}, [storeEvents, insertMessage]);
|
|
248
|
-
const processErrorMessage = (0, import_react.useCallback)((chunkJson) => {
|
|
249
|
-
storeEvents(null, chunkJson);
|
|
250
|
-
insertMessage({
|
|
251
|
-
id: (0, import_uuid.v4)(),
|
|
252
|
-
text: chunkJson.errorMessage,
|
|
253
|
-
role: "bot"
|
|
254
|
-
});
|
|
255
|
-
}, [storeEvents, insertMessage]);
|
|
256
|
-
const processActionArtifact = (0, import_react.useCallback)((event) => {
|
|
257
|
-
if (event.actions && event.actions.artifactDelta) {
|
|
258
|
-
storeEvents(null, event);
|
|
259
|
-
storeMessage(null, event, "bot");
|
|
260
|
-
}
|
|
261
|
-
}, [storeEvents, storeMessage]);
|
|
262
|
-
const sendMessageRequest = (0, import_react.useCallback)((values) => {
|
|
263
|
-
return new Promise((resolve) => {
|
|
264
|
-
if (ctrl.current) {
|
|
265
|
-
ctrl.current.abort();
|
|
250
|
+
if (text) {
|
|
251
|
+
setSuggestedQuestions((prev) => [...prev, text]);
|
|
266
252
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
253
|
+
},
|
|
254
|
+
[storeEvents, insertMessage]
|
|
255
|
+
);
|
|
256
|
+
const processErrorMessage = (0, import_react.useCallback)(
|
|
257
|
+
(chunkJson) => {
|
|
258
|
+
storeEvents(null, chunkJson);
|
|
259
|
+
insertMessage({
|
|
260
|
+
id: (0, import_uuid.v4)(),
|
|
261
|
+
text: chunkJson.errorMessage,
|
|
262
|
+
role: "bot"
|
|
263
|
+
});
|
|
264
|
+
},
|
|
265
|
+
[storeEvents, insertMessage]
|
|
266
|
+
);
|
|
267
|
+
const processActionArtifact = (0, import_react.useCallback)(
|
|
268
|
+
(event) => {
|
|
269
|
+
if (event.actions && event.actions.artifactDelta) {
|
|
270
|
+
storeEvents(null, event);
|
|
271
|
+
storeMessage(null, event, "bot");
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
[storeEvents, storeMessage]
|
|
275
|
+
);
|
|
276
|
+
const sendMessageRequest = (0, import_react.useCallback)(
|
|
277
|
+
(values) => {
|
|
278
|
+
return new Promise((resolve) => {
|
|
279
|
+
if (ctrl.current) {
|
|
280
|
+
ctrl.current.abort();
|
|
281
|
+
}
|
|
282
|
+
setLoading(true);
|
|
283
|
+
ctrl.current = new AbortController();
|
|
284
|
+
const requestUrl = `${url}/api/gateway-web/openApi/v1/aizt/app/${appNo}/sendMsgStreaming`;
|
|
285
|
+
(0, import_fetch_event_source.fetchEventSource)(requestUrl, {
|
|
286
|
+
method: "POST",
|
|
287
|
+
signal: ctrl.current.signal,
|
|
288
|
+
body: JSON.stringify(values),
|
|
289
|
+
openWhenHidden: true,
|
|
290
|
+
headers: {
|
|
291
|
+
"Content-Type": "application/json",
|
|
292
|
+
"Cache-Control": "no-cache",
|
|
293
|
+
stream: "true",
|
|
294
|
+
Authorization: `Bearer ${token}`
|
|
295
|
+
},
|
|
296
|
+
async onopen(response) {
|
|
297
|
+
if (response.ok && response.headers.get("content-type") === import_fetch_event_source.EventStreamContentType) {
|
|
298
|
+
} else if (response.status >= 400 && response.status < 500 && response.status !== 429) {
|
|
299
|
+
resolve();
|
|
300
|
+
} else {
|
|
301
|
+
resolve();
|
|
302
|
+
}
|
|
303
|
+
},
|
|
304
|
+
onmessage: (event) => {
|
|
305
|
+
const chunkJson = (0, import_utils.safeJsonParse)(event.data, {});
|
|
306
|
+
if (chunkJson.error) {
|
|
307
|
+
import_antd.message.warning(chunkJson.error);
|
|
299
308
|
return;
|
|
300
309
|
}
|
|
301
|
-
|
|
302
|
-
|
|
310
|
+
onStream == null ? void 0 : onStream(chunkJson);
|
|
311
|
+
if (chunkJson.content) {
|
|
312
|
+
if (chunkJson.content.role === "followup") {
|
|
313
|
+
processFollowupPart(chunkJson);
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
for (const part of combineTextParts(chunkJson.content.parts)) {
|
|
317
|
+
processPart(chunkJson, part);
|
|
318
|
+
}
|
|
319
|
+
} else if (chunkJson.errorMessage) {
|
|
320
|
+
processErrorMessage(chunkJson);
|
|
321
|
+
} else if (chunkJson.actions) {
|
|
322
|
+
processActionArtifact(chunkJson);
|
|
303
323
|
}
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
324
|
+
},
|
|
325
|
+
onclose: () => {
|
|
326
|
+
var _a;
|
|
327
|
+
setLoading(false);
|
|
328
|
+
if (textMsgRef.current) {
|
|
329
|
+
onMessage == null ? void 0 : onMessage(((_a = textMsgRef.current) == null ? void 0 : _a.text) || "", textMsgRef.current);
|
|
330
|
+
}
|
|
331
|
+
textMsgRef.current = null;
|
|
332
|
+
resolve();
|
|
333
|
+
},
|
|
334
|
+
onerror: (error) => {
|
|
335
|
+
setLoading(false);
|
|
336
|
+
resolve();
|
|
337
|
+
console.error("EventSource failed:", error);
|
|
338
|
+
throw error;
|
|
315
339
|
}
|
|
316
|
-
|
|
317
|
-
resolve();
|
|
318
|
-
},
|
|
319
|
-
onerror: (error) => {
|
|
320
|
-
setLoading(false);
|
|
321
|
-
resolve();
|
|
322
|
-
console.error("EventSource failed:", error);
|
|
323
|
-
throw error;
|
|
324
|
-
}
|
|
340
|
+
});
|
|
325
341
|
});
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
|
|
342
|
+
},
|
|
343
|
+
[
|
|
344
|
+
type,
|
|
345
|
+
currentSessionId,
|
|
346
|
+
processActionArtifact,
|
|
347
|
+
processErrorMessage,
|
|
348
|
+
processPart
|
|
349
|
+
]
|
|
350
|
+
);
|
|
351
|
+
const startChat = async ({
|
|
352
|
+
text = "",
|
|
353
|
+
files = [],
|
|
354
|
+
functionResponse
|
|
355
|
+
}) => {
|
|
356
|
+
console.log(text, loading);
|
|
329
357
|
if (loading)
|
|
330
358
|
return;
|
|
331
359
|
if (!text.trim() && !functionResponse)
|
|
@@ -390,12 +418,16 @@ function useADKChat({
|
|
|
390
418
|
return;
|
|
391
419
|
setMessages((prev) => {
|
|
392
420
|
const newMessages = [...prev];
|
|
393
|
-
const lastAIIndex = newMessages.findLastIndex(
|
|
421
|
+
const lastAIIndex = newMessages.findLastIndex(
|
|
422
|
+
(msg) => msg.role === "bot"
|
|
423
|
+
);
|
|
394
424
|
if (lastAIIndex !== -1) {
|
|
395
425
|
newMessages.splice(lastAIIndex, 1);
|
|
396
426
|
}
|
|
397
427
|
setSuggestedQuestions([]);
|
|
398
|
-
const lastUserMessage = newMessages.findLast(
|
|
428
|
+
const lastUserMessage = newMessages.findLast(
|
|
429
|
+
(msg) => msg.role === "user"
|
|
430
|
+
);
|
|
399
431
|
if (lastUserMessage) {
|
|
400
432
|
const { text = "", fileData = [] } = lastUserMessage;
|
|
401
433
|
sendMessageRequest({
|
|
@@ -403,9 +435,11 @@ function useADKChat({
|
|
|
403
435
|
sessionId: currentSessionId,
|
|
404
436
|
content: {
|
|
405
437
|
role: "user",
|
|
406
|
-
parts: [
|
|
407
|
-
|
|
408
|
-
|
|
438
|
+
parts: [
|
|
439
|
+
{
|
|
440
|
+
text
|
|
441
|
+
}
|
|
442
|
+
]
|
|
409
443
|
},
|
|
410
444
|
files: fileData == null ? void 0 : fileData.map((file) => ({
|
|
411
445
|
fileName: file.displayName,
|
|
@@ -501,10 +535,12 @@ function useADKChat({
|
|
|
501
535
|
if (part.errorMessage)
|
|
502
536
|
msg.text = part.errorMessage;
|
|
503
537
|
if (part.functionResponse) {
|
|
504
|
-
const functionCallMsg = mapped.find(
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
538
|
+
const functionCallMsg = mapped.find(
|
|
539
|
+
(msg2) => {
|
|
540
|
+
var _a, _b;
|
|
541
|
+
return ((_a = msg2.functionCall) == null ? void 0 : _a.id) === ((_b = part.functionResponse) == null ? void 0 : _b.id);
|
|
542
|
+
}
|
|
543
|
+
);
|
|
508
544
|
if (functionCallMsg) {
|
|
509
545
|
functionCallMsg.functionResponse = part.functionResponse;
|
|
510
546
|
}
|
|
@@ -533,7 +569,9 @@ function useADKChat({
|
|
|
533
569
|
if (Array.isArray(data) && data.length > 0) {
|
|
534
570
|
formatMessages(data, true);
|
|
535
571
|
} else {
|
|
536
|
-
setSuggestedQuestions(
|
|
572
|
+
setSuggestedQuestions(
|
|
573
|
+
((_b = appInfo == null ? void 0 : appInfo.onboardingInfo) == null ? void 0 : _b.suggested_questions) || []
|
|
574
|
+
);
|
|
537
575
|
}
|
|
538
576
|
}
|
|
539
577
|
} else {
|
|
@@ -544,7 +582,11 @@ function useADKChat({
|
|
|
544
582
|
var _a, _b;
|
|
545
583
|
try {
|
|
546
584
|
setLoading(true);
|
|
547
|
-
const {
|
|
585
|
+
const {
|
|
586
|
+
data = [],
|
|
587
|
+
pagination,
|
|
588
|
+
result
|
|
589
|
+
} = await (0, import_api.fetchSessionList)({
|
|
548
590
|
url,
|
|
549
591
|
appNo,
|
|
550
592
|
token,
|
|
@@ -564,13 +606,19 @@ function useADKChat({
|
|
|
564
606
|
};
|
|
565
607
|
});
|
|
566
608
|
setSessionList(formatSessions);
|
|
567
|
-
setSessionPagination({
|
|
609
|
+
setSessionPagination({
|
|
610
|
+
pageNum: sessionPagination.pageNum,
|
|
611
|
+
pageSize: sessionPagination.pageSize,
|
|
612
|
+
total: (pagination == null ? void 0 : pagination.total) || 0
|
|
613
|
+
});
|
|
568
614
|
const { sessionId } = data == null ? void 0 : data[0];
|
|
569
615
|
if (showFirstSession) {
|
|
570
616
|
fetchDetail && setCurrentSessionDetail(sessionId);
|
|
571
617
|
} else {
|
|
572
618
|
setPrologue(((_a = appInfo == null ? void 0 : appInfo.onboardingInfo) == null ? void 0 : _a.prologue) || "");
|
|
573
|
-
setSuggestedQuestions(
|
|
619
|
+
setSuggestedQuestions(
|
|
620
|
+
((_b = appInfo == null ? void 0 : appInfo.onboardingInfo) == null ? void 0 : _b.suggested_questions) || []
|
|
621
|
+
);
|
|
574
622
|
}
|
|
575
623
|
if (!initialized) {
|
|
576
624
|
onSuccess == null ? void 0 : onSuccess({
|