@ai-group/chat-sdk 3.6.7 → 3.6.8

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/components/XAdkChatbot/components/FunctionCallRender/index.tsx"],
4
- "sourcesContent": ["import React from \"react\";\nimport { Alert, Button, Flex, Form, Popover, Tooltip, Typography } from \"antd\";\nimport {\n CopyOutlined,\n ToolOutlined,\n CheckCircleTwoTone,\n LoadingOutlined,\n UserSwitchOutlined,\n InfoCircleOutlined,\n} from \"@ant-design/icons\";\nimport type { FunctionCallRenderProps, FunctionCall } from \"@/types\";\nimport { useStyles } from \"./styles\";\nimport { defaultToolKindResolver } from \"@/types/FunctionCallRender\";\nimport JsonView from \"@/components/XAiJsonView\";\n\nconst FunctionCallRender: React.FC<FunctionCallRenderProps> = ({\n msg,\n showDetail,\n onConfirm,\n kind: kindProp,\n toolKindResolver = defaultToolKindResolver,\n renderApproval,\n renderHandoff,\n}) => {\n const styles = useStyles();\n const fnCall = msg.functionCall as FunctionCall;\n const fnRes = msg.functionResponse;\n const name = fnCall?.name || fnRes?.name;\n const kind = kindProp ?? toolKindResolver(name);\n\n if (kind === \"approval\") {\n if (renderApproval) {\n const custom = renderApproval(msg, onConfirm);\n if (custom !== null && custom !== undefined) return <>{custom}</>;\n }\n if (fnRes) {\n if (msg.role === \"bot\") return null;\n const confirmed = fnRes.response?.confirmed;\n return (\n <div key={msg.id} className={styles.wrapper}>\n {confirmed ? (\n <Alert\n message=\"已确认\"\n type=\"success\"\n showIcon\n className={styles.alert}\n />\n ) : (\n <Alert\n message=\"已取消\"\n type=\"error\"\n showIcon\n className={styles.alert}\n />\n )}\n </div>\n );\n }\n const originalFn = msg?.functionCall?.args?.originalFunctionCall;\n return (\n <div\n key={msg.id}\n className={styles.wrapper}\n style={{ justifyContent: \"flex-end\" }}\n >\n <div className={styles.confirm}>\n <div className={styles.confirmText}>\n 请确认是否执行工具:{originalFn?.name}\n </div>\n <Flex justify=\"end\" gap={8}>\n <Button\n type=\"default\"\n size=\"small\"\n onClick={() => onConfirm?.(fnCall, false)}\n >\n 取消\n </Button>\n <Button\n type=\"primary\"\n size=\"small\"\n onClick={() => onConfirm?.(fnCall, true)}\n >\n 确认\n </Button>\n </Flex>\n </div>\n </div>\n );\n }\n if (kind === \"handoff\") {\n if (renderHandoff) {\n const custom = renderHandoff(msg);\n if (custom !== null && custom !== undefined) return <>{custom}</>;\n }\n const agentName = fnCall?.args?.agentName;\n return (\n <div key={msg.id} className={styles.wrapper}>\n <div className={styles.fnCall}>\n <UserSwitchOutlined style={{ color: \"#888\" }} />\n <Typography.Text\n ellipsis={{ tooltip: agentName }}\n style={{ maxWidth: 300, lineHeight: \"16px\" }}\n >\n 任务转交:{agentName}\n </Typography.Text>\n {msg.functionResponse ? (\n <CheckCircleTwoTone twoToneColor=\"#52c41a\" />\n ) : (\n <LoadingOutlined />\n )}\n </div>\n </div>\n );\n }\n const renderItem = (obj: any, text: string) => {\n const str = JSON.stringify(obj, null, 2);\n return (\n <Form.Item\n label={\n <Flex align=\"center\">\n <span className=\"mr-2\">{text}</span>\n <Typography.Text\n copyable={{\n text: str,\n icon: <CopyOutlined />,\n }}\n />\n </Flex>\n }\n style={{ marginBottom: 12 }}\n >\n <JsonView value={str} />\n </Form.Item>\n );\n };\n const renderResponse = () => {\n const res = msg.functionResponse;\n if (res) {\n if (res.response?.error) {\n return (\n <Tooltip title={res.response.error}>\n <InfoCircleOutlined style={{ color: \"#faad14\" }} />\n </Tooltip>\n );\n }\n return <CheckCircleTwoTone twoToneColor=\"#52c41a\" />;\n }\n return <LoadingOutlined />;\n };\n return (\n <div key={msg.id} className={styles.wrapper}>\n {showDetail ? (\n <Popover\n placement=\"left\"\n content={\n <Form style={{ width: 400 }} layout=\"vertical\">\n {renderItem(fnCall?.args, \"工具参数\")}\n {renderItem(msg.functionResponse?.response, \"工具响应\")}\n </Form>\n }\n >\n <div className={styles.fnCall}>\n <ToolOutlined style={{ color: \"#888\" }} />\n <Typography.Text\n ellipsis={{ tooltip: name }}\n style={{ maxWidth: 300, lineHeight: \"16px\" }}\n >\n 调用工具:{name}\n </Typography.Text>\n {renderResponse()}\n </div>\n </Popover>\n ) : (\n <div className={styles.fnCall}>\n <ToolOutlined style={{ color: \"#888\" }} />\n <Typography.Text\n ellipsis={{ tooltip: name }}\n style={{ maxWidth: 300, lineHeight: \"16px\" }}\n >\n 调用工具:{name}\n </Typography.Text>\n {renderResponse()}\n </div>\n )}\n </div>\n );\n};\n\nexport default FunctionCallRender;\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAAwE;AACxE,mBAOO;AAEP,oBAA0B;AAC1B,gCAAwC;AACxC,yBAAqB;AAoBqC;AAlB1D,IAAM,qBAAwD,CAAC;AAAA,EAC7D;AAAA,EACA;AAAA,EACA;AAAA,EACA,MAAM;AAAA,EACN,mBAAmB;AAAA,EACnB;AAAA,EACA;AACF,MAAM;AAvBN;AAwBE,QAAM,aAAS,yBAAU;AACzB,QAAM,SAAS,IAAI;AACnB,QAAM,QAAQ,IAAI;AAClB,QAAM,QAAO,iCAAQ,UAAQ,+BAAO;AACpC,QAAM,OAAO,YAAY,iBAAiB,IAAI;AAE9C,MAAI,SAAS,YAAY;AACvB,QAAI,gBAAgB;AAClB,YAAM,SAAS,eAAe,KAAK,SAAS;AAC5C,UAAI,WAAW,QAAQ,WAAW;AAAW,eAAO,2EAAG,kBAAO;AAAA,IAChE;AACA,QAAI,OAAO;AACT,UAAI,IAAI,SAAS;AAAO,eAAO;AAC/B,YAAM,aAAY,WAAM,aAAN,mBAAgB;AAClC,aACE,4CAAC,SAAiB,WAAW,OAAO,SACjC,sBACC;AAAA,QAAC;AAAA;AAAA,UACC,SAAQ;AAAA,UACR,MAAK;AAAA,UACL,UAAQ;AAAA,UACR,WAAW,OA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,qBAAJ,mBAAsB,UAAU,MAAM;AAAA,SACpD;AAAA,MAGF,uDAAC,SAAI,WAAW,OAAO,QACrB;AAAA,oDAAC,6BAAa,OAAO,EAAE,OAAO,OAAO,GAAG;AAAA,QACxC;AAAA,UAAC,uBAAW;AAAA,UAAX;AAAA,YACC,UAAU,EAAE,SAAS,KAAK;AAAA,YAC1B,OAAO,EAAE,UAAU,KAAK,YAAY,OAAO;AAAA,YAC5C;AAAA;AAAA,cACO;AAAA;AAAA;AAAA,QACR;AAAA,QACC,eAAe;AAAA,SAClB;AAAA;AAAA,EACF,IAEA,6CAAC,SAAI,WAAW,OAAO,QACrB;AAAA,gDAAC,6BAAa,OAAO,EAAE,OAAO,OAAO,GAAG;AAAA,IACxC;AAAA,MAAC,uBAAW;AAAA,MAAX;AAAA,QACC,UAAU,EAAE,SAAS,KAAK;AAAA,QAC1B,OAAO,EAAE,UAAU,KAAK,YAAY,OAAO;AAAA,QAC5C;AAAA;AAAA,UACO;AAAA;AAAA;AAAA,IACR;AAAA,IACC,eAAe;AAAA,KAClB,KAhCM,IAAI,EAkCd;AAEJ;AAEA,IAAO,6BAAQ;",
4
+ "sourcesContent": ["import React from \"react\";\nimport { Alert, Button, Flex, Form, Popover, Tooltip, Typography } from \"antd\";\nimport {\n CopyOutlined,\n ToolOutlined,\n CheckCircleTwoTone,\n LoadingOutlined,\n UserSwitchOutlined,\n InfoCircleOutlined,\n} from \"@ant-design/icons\";\nimport type { FunctionCallRenderProps, FunctionCall } from \"@/types\";\nimport { useStyles } from \"./styles\";\nimport { defaultToolKindResolver } from \"@/types/FunctionCallRender\";\nimport JsonView from \"@/components/XAiJsonView\";\n\n// 工具调用组件\nconst FunctionCallRender: React.FC<FunctionCallRenderProps> = ({\n msg,\n showDetail,\n onConfirm,\n kind: kindProp,\n toolKindResolver = defaultToolKindResolver,\n renderApproval,\n renderHandoff,\n}) => {\n const styles = useStyles();\n const fnCall = msg.functionCall as FunctionCall;\n const fnRes = msg.functionResponse;\n const name = fnCall?.name || fnRes?.name;\n const kind = kindProp ?? toolKindResolver(name);\n\n if (kind === \"approval\") {\n if (renderApproval) {\n const custom = renderApproval(msg, onConfirm);\n if (custom !== null && custom !== undefined) return <>{custom}</>;\n }\n if (fnRes) {\n if (msg.role === \"bot\") return null;\n const confirmed = fnRes.response?.confirmed;\n return (\n <div key={msg.id} className={styles.wrapper}>\n {confirmed ? (\n <Alert\n message=\"已确认\"\n type=\"success\"\n showIcon\n className={styles.alert}\n />\n ) : (\n <Alert\n message=\"已取消\"\n type=\"error\"\n showIcon\n className={styles.alert}\n />\n )}\n </div>\n );\n }\n const originalFn = msg?.functionCall?.args?.originalFunctionCall;\n return (\n <div\n key={msg.id}\n className={styles.wrapper}\n style={{ justifyContent: \"flex-end\" }}\n >\n <div className={styles.confirm}>\n <div className={styles.confirmText}>\n 请确认是否执行工具:{originalFn?.name}\n </div>\n <Flex justify=\"end\" gap={8}>\n <Button\n type=\"default\"\n size=\"small\"\n onClick={() => onConfirm?.(fnCall, false)}\n >\n 取消\n </Button>\n <Button\n type=\"primary\"\n size=\"small\"\n onClick={() => onConfirm?.(fnCall, true)}\n >\n 确认\n </Button>\n </Flex>\n </div>\n </div>\n );\n }\n if (kind === \"handoff\") {\n if (renderHandoff) {\n const custom = renderHandoff(msg);\n if (custom !== null && custom !== undefined) return <>{custom}</>;\n }\n const agentName = fnCall?.args?.agentName;\n return (\n <div key={msg.id} className={styles.wrapper}>\n <div className={styles.fnCall}>\n <UserSwitchOutlined style={{ color: \"#888\" }} />\n <Typography.Text\n ellipsis={{ tooltip: agentName }}\n style={{ maxWidth: 300, lineHeight: \"16px\" }}\n >\n 任务转交:{agentName}\n </Typography.Text>\n {msg.functionResponse ? (\n <CheckCircleTwoTone twoToneColor=\"#52c41a\" />\n ) : (\n <LoadingOutlined />\n )}\n </div>\n </div>\n );\n }\n const renderItem = (obj: any, text: string) => {\n const str = JSON.stringify(obj, null, 2);\n return (\n <Form.Item\n label={\n <Flex align=\"center\">\n <span className=\"mr-2\">{text}</span>\n <Typography.Text\n copyable={{\n text: str,\n icon: <CopyOutlined />,\n }}\n />\n </Flex>\n }\n style={{ marginBottom: 12 }}\n >\n <JsonView value={str} />\n </Form.Item>\n );\n };\n const renderResponse = () => {\n const res = msg.functionResponse;\n if (res) {\n if (res.response?.error) {\n return (\n <Tooltip title={res.response.error}>\n <InfoCircleOutlined style={{ color: \"#faad14\" }} />\n </Tooltip>\n );\n }\n return <CheckCircleTwoTone twoToneColor=\"#52c41a\" />;\n }\n return <LoadingOutlined />;\n };\n return (\n <div key={msg.id} className={styles.wrapper}>\n {showDetail ? (\n <Popover\n placement=\"left\"\n content={\n <Form style={{ width: 400 }} layout=\"vertical\">\n {renderItem(fnCall?.args, \"工具参数\")}\n {renderItem(msg.functionResponse?.response, \"工具响应\")}\n </Form>\n }\n >\n <div className={styles.fnCall}>\n <ToolOutlined style={{ color: \"#888\" }} />\n <Typography.Text\n ellipsis={{ tooltip: name }}\n style={{ maxWidth: 300, lineHeight: \"16px\" }}\n >\n 调用工具:{name}\n </Typography.Text>\n {renderResponse()}\n </div>\n </Popover>\n ) : (\n <div className={styles.fnCall}>\n <ToolOutlined style={{ color: \"#888\" }} />\n <Typography.Text\n ellipsis={{ tooltip: name }}\n style={{ maxWidth: 300, lineHeight: \"16px\" }}\n >\n 调用工具:{name}\n </Typography.Text>\n {renderResponse()}\n </div>\n )}\n </div>\n );\n};\n\nexport default FunctionCallRender;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAAwE;AACxE,mBAOO;AAEP,oBAA0B;AAC1B,gCAAwC;AACxC,yBAAqB;AAqBqC;AAlB1D,IAAM,qBAAwD,CAAC;AAAA,EAC7D;AAAA,EACA;AAAA,EACA;AAAA,EACA,MAAM;AAAA,EACN,mBAAmB;AAAA,EACnB;AAAA,EACA;AACF,MAAM;AAxBN;AAyBE,QAAM,aAAS,yBAAU;AACzB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onView", "_a"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import { DebugOptions, FunctionCall, SendContent, SessionData, Event, IMessage, Part } from "../types";
3
3
  import { type ChatConfig } from "../services/api";
4
- declare function useADKChat({ url, token, config, type, enabled, // ← 新增: 是否启用 Hook
4
+ declare function useADKChat({ url, token, config, type: _type, enabled, // ← 新增: 是否启用 Hook
5
5
  strategies, onError, onMessage, onSuccess, onStream, }: DebugOptions): {
6
6
  appInfo: ChatConfig | null;
7
7
  startChat: ({ text, files, functionResponse, }: SendContent) => Promise<void>;
@@ -24,7 +24,7 @@ strategies, onError, onMessage, onSuccess, onStream, }: DebugOptions): {
24
24
  sessionLoading: boolean;
25
25
  messages: IMessage[];
26
26
  insertSuggestedQuestions: (suggested_questions?: string[]) => void;
27
- insertPrologue: (prologue: string) => void;
27
+ insertPrologue: (prologueText: string) => void;
28
28
  deleteSession: (sessionId: string) => Promise<void>;
29
29
  updateSession: (sessionId: string, title: string) => Promise<void>;
30
30
  setSuggestedQuestions: import("react").Dispatch<import("react").SetStateAction<string[]>>;
@@ -50,6 +50,42 @@ var combineTextParts = (parts) => {
50
50
  return result;
51
51
  };
52
52
  var DEFAULT_SESSION_EVENTS_POLLING_INTERVAL = 1e4;
53
+ var buildNonTextMessage = (event, part, role = "bot") => {
54
+ const msg = {
55
+ id: (0, import_uuid.v4)(),
56
+ author: event.author,
57
+ invocationId: event.invocationId,
58
+ eventId: event.id,
59
+ timestamp: event.timestamp,
60
+ isLike: event.isLike || 0,
61
+ role,
62
+ modelCode: event.modelCode,
63
+ usageMetadata: event.usageMetadata,
64
+ finishReason: event.finishReason,
65
+ raw: event
66
+ };
67
+ if (part.inlineData) {
68
+ msg.inlineData = {
69
+ displayName: part.inlineData.displayName,
70
+ data: part.inlineData.data,
71
+ mimeType: part.inlineData.mimeType
72
+ };
73
+ } else if (part.fileData) {
74
+ msg.fileData = [part.fileData];
75
+ } else if (part.functionCall) {
76
+ msg.functionCall = part.functionCall;
77
+ } else if (part.functionResponse) {
78
+ msg.functionResponse = part.functionResponse;
79
+ } else if (part.executableCode) {
80
+ msg.executableCode = part.executableCode;
81
+ } else if (part.codeExecutionResult) {
82
+ msg.codeExecutionResult = part.codeExecutionResult;
83
+ } else if (part.text) {
84
+ msg.text = part.text;
85
+ msg.thought = part.thought;
86
+ }
87
+ return msg;
88
+ };
53
89
  var getMessageEventId = (messageItem) => {
54
90
  var _a;
55
91
  return messageItem.eventId || ((_a = messageItem.raw) == null ? void 0 : _a.id);
@@ -106,6 +142,8 @@ var mapSessionMessages = (sessionEvents) => {
106
142
  return;
107
143
  if (item.author === "user" && item.content.parts.some((part) => part.task))
108
144
  return;
145
+ if (item.content.role === "user" && item.content.parts.every((part) => !part || part.functionResponse))
146
+ return;
109
147
  const role = (item.content.role || "").toLowerCase() === "user" ? "user" : "bot";
110
148
  const parts = item.content.parts.filter((part) => {
111
149
  if (!part)
@@ -123,9 +161,10 @@ var mapSessionMessages = (sessionEvents) => {
123
161
  const otherParts = parts.filter(
124
162
  (part) => !part.text && !part.errorMessage && !part.inlineData && !part.fileData
125
163
  );
164
+ let partCounter = 0;
126
165
  if (textParts.length > 0 || fileDataParts.length > 0) {
127
166
  const messageItem = {
128
- id: (0, import_uuid.v4)(),
167
+ id: `session-event:${item.id}:${partCounter++}`,
129
168
  author: item.author,
130
169
  invocationId: item.invocationId,
131
170
  eventId: item.id,
@@ -167,7 +206,7 @@ var mapSessionMessages = (sessionEvents) => {
167
206
  }
168
207
  otherParts.forEach((part) => {
169
208
  const messageItem = {
170
- id: (0, import_uuid.v4)(),
209
+ id: `session-event:${item.id}:${partCounter++}`,
171
210
  author: item.author,
172
211
  invocationId: item.invocationId,
173
212
  eventId: item.id,
@@ -202,64 +241,54 @@ var mapSessionMessages = (sessionEvents) => {
202
241
  });
203
242
  return mapped;
204
243
  };
205
- var getComparableMessageContent = (messageItem) => {
206
- var _a;
207
- return JSON.stringify({
208
- role: messageItem.role,
209
- text: ((_a = messageItem.text) == null ? void 0 : _a.replace(/\r\n/g, "\n").trim()) || "",
210
- thought: Boolean(messageItem.thought),
211
- inlineData: messageItem.inlineData || null,
212
- fileData: messageItem.fileData || null,
213
- functionCall: messageItem.functionCall || null,
214
- functionResponse: messageItem.functionResponse || null,
215
- executableCode: messageItem.executableCode || null,
216
- codeExecutionResult: messageItem.codeExecutionResult || null
217
- });
218
- };
219
- var isStreamMessageWithoutServerEventId = (messageItem) => {
220
- const eventId = getMessageEventId(messageItem);
221
- return Boolean(messageItem.invocationId) && (!eventId || eventId === messageItem.invocationId);
222
- };
223
- var insertMissingSessionEvents = (currentMessages, sessionEvents) => {
244
+ var insertMissingSessionEvents = (currentMessages, sessionEvents, removedInvocationIds) => {
224
245
  const renderedEventIds = new Set(
225
246
  currentMessages.map(getMessageEventId).filter(Boolean)
226
247
  );
227
- const unmatchedStreamMessageIndexes = new Set(
228
- currentMessages.map(
229
- (messageItem, index) => isStreamMessageWithoutServerEventId(messageItem) ? index : -1
230
- ).filter((index) => index >= 0)
231
- );
248
+ let nextMessages = [...currentMessages];
249
+ const fnResMap = /* @__PURE__ */ new Map();
250
+ sessionEvents.forEach((event) => {
251
+ var _a, _b;
252
+ if (((_a = event.content) == null ? void 0 : _a.role) !== "user" || !Array.isArray((_b = event.content) == null ? void 0 : _b.parts))
253
+ return;
254
+ event.content.parts.forEach((p) => {
255
+ var _a2;
256
+ if ((_a2 = p.functionResponse) == null ? void 0 : _a2.id) {
257
+ fnResMap.set(p.functionResponse.id, p.functionResponse);
258
+ }
259
+ });
260
+ });
261
+ if (fnResMap.size > 0) {
262
+ let paired = false;
263
+ nextMessages = nextMessages.map((msg) => {
264
+ if (msg.functionCall && !msg.functionResponse) {
265
+ const callId = msg.functionCall.id;
266
+ if (callId && fnResMap.has(callId)) {
267
+ paired = true;
268
+ return { ...msg, functionResponse: fnResMap.get(callId) };
269
+ }
270
+ }
271
+ return msg;
272
+ });
273
+ if (!paired)
274
+ nextMessages = currentMessages;
275
+ }
232
276
  const missingEvents = sessionEvents.filter((event) => {
233
277
  var _a, _b;
234
278
  const parts = (_a = event.content) == null ? void 0 : _a.parts;
235
279
  const canRender = Boolean(event.id) && ((_b = event.content) == null ? void 0 : _b.role) === "model" && Array.isArray(parts) && parts.length > 0;
236
280
  if (!canRender || renderedEventIds.has(event.id))
237
281
  return false;
238
- const eventMessages = mapSessionMessages([event]);
239
- const matchedIndexes = [];
240
- const isRenderedByStream = eventMessages.length > 0 && eventMessages.every((eventMessage) => {
241
- const comparableContent = getComparableMessageContent(eventMessage);
242
- const matchedIndex = currentMessages.findIndex(
243
- (currentMessage, index) => unmatchedStreamMessageIndexes.has(index) && !matchedIndexes.includes(index) && currentMessage.invocationId === eventMessage.invocationId && getComparableMessageContent(currentMessage) === comparableContent
244
- );
245
- if (matchedIndex < 0)
246
- return false;
247
- matchedIndexes.push(matchedIndex);
248
- return true;
249
- });
250
- if (isRenderedByStream) {
251
- matchedIndexes.forEach(
252
- (index) => unmatchedStreamMessageIndexes.delete(index)
253
- );
282
+ if (removedInvocationIds && removedInvocationIds.size > 0 && event.invocationId && removedInvocationIds.has(event.invocationId)) {
254
283
  return false;
255
284
  }
256
285
  return true;
257
286
  });
258
287
  if (missingEvents.length === 0)
259
- return currentMessages;
288
+ return nextMessages;
260
289
  const missingMessages = mapSessionMessages(missingEvents);
261
290
  if (missingMessages.length === 0)
262
- return currentMessages;
291
+ return nextMessages;
263
292
  const eventOrder = new Map(
264
293
  sessionEvents.map((event, index) => [event.id, index])
265
294
  );
@@ -277,7 +306,6 @@ var insertMissingSessionEvents = (currentMessages, sessionEvents) => {
277
306
  }
278
307
  return Number.POSITIVE_INFINITY;
279
308
  };
280
- const nextMessages = [...currentMessages];
281
309
  missingMessages.forEach((messageItem) => {
282
310
  const targetOrder = getMessageOrder(messageItem);
283
311
  let insertIndex = nextMessages.findIndex((currentMessage) => {
@@ -294,7 +322,7 @@ function useADKChat({
294
322
  url = window.location.origin,
295
323
  token,
296
324
  config = {},
297
- type = "agentDebug",
325
+ type: _type = "agentDebug",
298
326
  enabled = true,
299
327
  // ← 新增: 是否启用 Hook
300
328
  strategies,
@@ -334,10 +362,9 @@ function useADKChat({
334
362
  const [suggestedQuestions, setSuggestedQuestions] = (0, import_react.useState)([]);
335
363
  const [messages, setMessages] = (0, import_react.useState)([]);
336
364
  const pendingSessionEventsRef = (0, import_react.useRef)(null);
337
- const sessionEventsFlushTimerRef = (0, import_react.useRef)(null);
338
- const sessionEventsSyncingRef = (0, import_react.useRef)(false);
339
365
  const sessionDetailLoadingRef = (0, import_react.useRef)(false);
340
366
  const stateDeltaRef = (0, import_react.useRef)(void 0);
367
+ const reChatRemovedInvocationIdsRef = (0, import_react.useRef)(/* @__PURE__ */ new Set());
341
368
  const backgroundRef = (0, import_react.useRef)(/* @__PURE__ */ new Map());
342
369
  const messagesRef = (0, import_react.useRef)(messages);
343
370
  messagesRef.current = messages;
@@ -365,42 +392,24 @@ function useADKChat({
365
392
  }, [messages]);
366
393
  const textMsgRef = (0, import_react.useRef)(null);
367
394
  const eventDataRef = (0, import_react.useRef)(/* @__PURE__ */ new Map());
368
- const cancelSessionEventsFlush = (0, import_react.useCallback)(() => {
369
- if (sessionEventsFlushTimerRef.current === null)
370
- return;
371
- clearTimeout(sessionEventsFlushTimerRef.current);
372
- sessionEventsFlushTimerRef.current = null;
373
- }, []);
374
395
  const flushPendingSessionEvents = (0, import_react.useCallback)(() => {
375
396
  const pending = pendingSessionEventsRef.current;
376
- const replyInProgress = loadingRef.current || sendingRef.current || textMsgRef.current !== null;
397
+ const replyInProgress = sendingRef.current || textMsgRef.current !== null;
377
398
  if (!pending || replyInProgress || pending.sessionId !== currentSessionIdRef.current)
378
399
  return;
379
- const previewMessages = insertMissingSessionEvents(
380
- messagesRef.current,
381
- pending.events
382
- );
383
400
  pendingSessionEventsRef.current = null;
384
- if (previewMessages === messagesRef.current)
385
- return;
386
- sessionEventsSyncingRef.current = true;
387
- setLoading(true);
388
- sessionEventsFlushTimerRef.current = setTimeout(() => {
389
- sessionEventsFlushTimerRef.current = null;
390
- if (pending.sessionId === currentSessionIdRef.current) {
391
- setMessages((prev) => {
392
- const nextMessages = insertMissingSessionEvents(
393
- prev,
394
- pending.events
395
- );
396
- messagesRef.current = nextMessages;
397
- return nextMessages;
398
- });
399
- }
400
- sessionEventsSyncingRef.current = false;
401
- setLoading(false);
402
- }, 0);
403
- }, [setLoading]);
401
+ setMessages((prev) => {
402
+ const nextMessages = insertMissingSessionEvents(
403
+ prev,
404
+ pending.events,
405
+ reChatRemovedInvocationIdsRef.current
406
+ );
407
+ if (nextMessages === prev)
408
+ return prev;
409
+ messagesRef.current = nextMessages;
410
+ return nextMessages;
411
+ });
412
+ }, []);
404
413
  const syncSessionEvents = (0, import_react.useCallback)(
405
414
  (events, targetSessionId) => {
406
415
  if (targetSessionId !== currentSessionIdRef.current)
@@ -415,12 +424,7 @@ function useADKChat({
415
424
  );
416
425
  (0, import_react.useEffect)(() => {
417
426
  pendingSessionEventsRef.current = null;
418
- cancelSessionEventsFlush();
419
- if (sessionEventsSyncingRef.current) {
420
- sessionEventsSyncingRef.current = false;
421
- setLoading(false);
422
- }
423
- }, [cancelSessionEventsFlush, currentSessionId, setLoading]);
427
+ }, [currentSessionId]);
424
428
  (0, import_react.useEffect)(() => {
425
429
  if (!loading)
426
430
  flushPendingSessionEvents();
@@ -434,18 +438,21 @@ function useADKChat({
434
438
  return [...prev, msg];
435
439
  });
436
440
  }, []);
437
- const insertSuggestedQuestions = (suggested_questions = []) => {
438
- if (!(suggested_questions == null ? void 0 : suggested_questions.length))
439
- return;
440
- if (messages.length === 0 && suggested_questions.length) {
441
- setSuggestedQuestions(suggested_questions);
442
- }
443
- };
444
- const insertPrologue = (prologue2) => {
445
- if (prologue2) {
446
- setPrologue(prologue2);
441
+ const insertSuggestedQuestions = (0, import_react.useCallback)(
442
+ (suggested_questions = []) => {
443
+ if (!(suggested_questions == null ? void 0 : suggested_questions.length))
444
+ return;
445
+ setSuggestedQuestions(
446
+ (prev) => messages.length === 0 ? suggested_questions : prev
447
+ );
448
+ },
449
+ [messages.length]
450
+ );
451
+ const insertPrologue = (0, import_react.useCallback)((prologueText) => {
452
+ if (prologueText) {
453
+ setPrologue(prologueText);
447
454
  }
448
- };
455
+ }, []);
449
456
  const updateMessage = (0, import_react.useCallback)((msg) => {
450
457
  setMessages((prev) => {
451
458
  return prev.map((m) => {
@@ -511,47 +518,13 @@ function useADKChat({
511
518
  const storeMessage = (0, import_react.useCallback)(
512
519
  (part, event, role) => {
513
520
  var _a2, _b2;
514
- const msg = {
515
- id: (0, import_uuid.v4)(),
516
- author: event.author,
517
- invocationId: event.invocationId,
518
- eventId: event.id,
519
- timestamp: event.timestamp,
520
- isLike: event.isLike || 0,
521
- role,
522
- modelCode: event.modelCode,
523
- usageMetadata: event.usageMetadata,
524
- finishReason: event.finishReason,
525
- raw: event
526
- };
527
- if (part) {
528
- if (part.inlineData) {
529
- msg.inlineData = {
530
- displayName: part.inlineData.displayName,
531
- data: part.inlineData.data,
532
- mimeType: part.inlineData.mimeType
533
- };
534
- } else if (part.text) {
535
- msg.text = part.text;
536
- msg.thought = part.thought;
537
- if ((_b2 = (_a2 = event == null ? void 0 : event.groundingMetadata) == null ? void 0 : _a2.searchEntryPoint) == null ? void 0 : _b2.renderedContent) {
538
- msg.renderedContent = event.groundingMetadata.searchEntryPoint.renderedContent;
539
- }
540
- } else if (part.fileData) {
541
- msg.fileData = [part.fileData];
542
- } else if (part.functionCall) {
543
- msg.functionCall = part.functionCall;
544
- } else if (part.functionResponse) {
545
- msg.functionResponse = part.functionResponse;
546
- } else if (part.executableCode) {
547
- msg.executableCode = part.executableCode;
548
- } else if (part.codeExecutionResult) {
549
- msg.codeExecutionResult = part.codeExecutionResult;
550
- }
551
- }
552
- if (part && Object.keys(part).length > 0) {
553
- insertMessage(msg);
521
+ if (!part || Object.keys(part).length === 0)
522
+ return;
523
+ const msg = buildNonTextMessage(event, part, role);
524
+ if (part.text && ((_b2 = (_a2 = event == null ? void 0 : event.groundingMetadata) == null ? void 0 : _a2.searchEntryPoint) == null ? void 0 : _b2.renderedContent)) {
525
+ msg.renderedContent = event.groundingMetadata.searchEntryPoint.renderedContent;
554
526
  }
527
+ insertMessage(msg);
555
528
  },
556
529
  [insertMessage]
557
530
  );
@@ -620,7 +593,7 @@ function useADKChat({
620
593
  setSuggestedQuestions((prev) => [...prev, text]);
621
594
  }
622
595
  },
623
- [storeEvents, insertMessage]
596
+ [storeEvents]
624
597
  );
625
598
  const processErrorMessage = (0, import_react.useCallback)(
626
599
  (chunkJson) => {
@@ -746,29 +719,10 @@ function useADKChat({
746
719
  }
747
720
  } else {
748
721
  bgTextMsg = null;
749
- const msg = {
750
- id: (0, import_uuid.v4)(),
751
- author: chunkJson.author,
752
- invocationId: chunkJson.invocationId,
753
- eventId: chunkJson.id,
754
- timestamp: chunkJson.timestamp,
755
- role: "bot"
756
- };
757
- if (part.functionCall)
758
- msg.functionCall = part.functionCall;
759
- else if (part.functionResponse)
760
- msg.functionResponse = part.functionResponse;
761
- else if (part.executableCode)
762
- msg.executableCode = part.executableCode;
763
- else if (part.codeExecutionResult)
764
- msg.codeExecutionResult = part.codeExecutionResult;
765
- else {
766
- msg.text = part.text;
767
- msg.thought = part.thought;
768
- if (part.fileData)
769
- msg.fileData = [part.fileData];
770
- }
771
- bg.messages = [...bg.messages, msg];
722
+ bg.messages = [
723
+ ...bg.messages,
724
+ buildNonTextMessage(chunkJson, part)
725
+ ];
772
726
  }
773
727
  }
774
728
  } else if (chunkJson.errorMessage) {
@@ -805,12 +759,17 @@ function useADKChat({
805
759
  bg.loading = false;
806
760
  bg.textMsgRef = null;
807
761
  }
762
+ if (!backgroundRef.current.has(targetSessionId) && currentSessionIdRef.current === targetSessionId) {
763
+ setLoading(false);
764
+ textMsgRef.current = null;
765
+ }
808
766
  } else {
809
767
  setLoading(false);
810
768
  if (textMsgRef.current) {
811
769
  onMessage == null ? void 0 : onMessage(((_a2 = textMsgRef.current) == null ? void 0 : _a2.text) || "", textMsgRef.current);
812
770
  }
813
771
  textMsgRef.current = null;
772
+ ctrl.current = null;
814
773
  }
815
774
  resolve();
816
775
  },
@@ -820,8 +779,13 @@ function useADKChat({
820
779
  const bg = backgroundRef.current.get(targetSessionId);
821
780
  if (bg)
822
781
  bg.loading = false;
782
+ if (!backgroundRef.current.has(targetSessionId) && currentSessionIdRef.current === targetSessionId) {
783
+ setLoading(false);
784
+ ctrl.current = null;
785
+ }
823
786
  } else {
824
787
  setLoading(false);
788
+ ctrl.current = null;
825
789
  }
826
790
  resolve();
827
791
  console.error("EventSource failed:", error);
@@ -831,8 +795,6 @@ function useADKChat({
831
795
  });
832
796
  },
833
797
  [
834
- type,
835
- currentSessionId,
836
798
  processActionArtifact,
837
799
  processErrorMessage,
838
800
  processPart,
@@ -850,6 +812,7 @@ function useADKChat({
850
812
  return;
851
813
  sendingRef.current = true;
852
814
  setSuggestedQuestions([]);
815
+ reChatRemovedInvocationIdsRef.current = /* @__PURE__ */ new Set();
853
816
  setMessages((prev) => {
854
817
  let temp = [...prev];
855
818
  if (text.trim()) {
@@ -925,6 +888,13 @@ function useADKChat({
925
888
  }
926
889
  const newMessages = messages.slice(0, lastUserIndex + 1);
927
890
  setMessages(newMessages);
891
+ const removedInvocationIds = /* @__PURE__ */ new Set();
892
+ for (let i = lastUserIndex + 1; i < messages.length; i++) {
893
+ const msg = messages[i];
894
+ if (msg.invocationId)
895
+ removedInvocationIds.add(msg.invocationId);
896
+ }
897
+ reChatRemovedInvocationIdsRef.current = removedInvocationIds;
928
898
  const lastUserMessage = newMessages[lastUserIndex];
929
899
  const { text = "", fileData = [] } = lastUserMessage;
930
900
  try {
@@ -972,17 +942,16 @@ function useADKChat({
972
942
  const stopChat = (0, import_react.useCallback)(() => {
973
943
  var _a2;
974
944
  pendingSessionEventsRef.current = null;
975
- cancelSessionEventsFlush();
976
- sessionEventsSyncingRef.current = false;
977
945
  (_a2 = ctrl.current) == null ? void 0 : _a2.abort();
978
946
  ctrl.current = null;
979
947
  setLoading(false);
980
948
  textMsgRef.current = null;
981
- }, [cancelSessionEventsFlush, setLoading]);
949
+ }, [setLoading]);
982
950
  const clearChat = () => {
983
951
  var _a2, _b2;
984
952
  const newSessionId = (0, import_uuid.v4)();
985
953
  setCurrentSessionId(newSessionId);
954
+ reChatRemovedInvocationIdsRef.current = /* @__PURE__ */ new Set();
986
955
  stopChat();
987
956
  setPrologue(((_a2 = appInfo == null ? void 0 : appInfo.onboardingInfo) == null ? void 0 : _a2.prologue) || "");
988
957
  setMessages([]);
@@ -1002,11 +971,7 @@ function useADKChat({
1002
971
  return;
1003
972
  }
1004
973
  pendingSessionEventsRef.current = null;
1005
- cancelSessionEventsFlush();
1006
- if (sessionEventsSyncingRef.current) {
1007
- sessionEventsSyncingRef.current = false;
1008
- setLoading(false);
1009
- }
974
+ reChatRemovedInvocationIdsRef.current = /* @__PURE__ */ new Set();
1010
975
  const prevSessionId = currentSessionId;
1011
976
  if (ctrl.current) {
1012
977
  backgroundRef.current.set(prevSessionId, {
@@ -1029,9 +994,11 @@ function useADKChat({
1029
994
  const bg = backgroundRef.current.get(sessionId);
1030
995
  if (bg) {
1031
996
  setMessages(bg.messages);
1032
- setLoading(bg.loading);
997
+ messagesRef.current = bg.messages;
1033
998
  textMsgRef.current = bg.textMsgRef;
1034
- ctrl.current = bg.loading ? bg.ctrl : null;
999
+ const isSseStillActive = bg.loading && !bg.ctrl.signal.aborted;
1000
+ setLoading(isSseStillActive);
1001
+ ctrl.current = isSseStillActive ? bg.ctrl : null;
1035
1002
  setCurrentSessionId(sessionId);
1036
1003
  setInitialized(true);
1037
1004
  backgroundRef.current.delete(sessionId);
@@ -1238,7 +1205,7 @@ function useADKChat({
1238
1205
  let requesting = false;
1239
1206
  const pollingSessionId = currentSessionId;
1240
1207
  const poll = async () => {
1241
- if (requesting || sessionDetailLoadingRef.current)
1208
+ if (disposed || requesting || sessionDetailLoadingRef.current)
1242
1209
  return;
1243
1210
  requesting = true;
1244
1211
  try {
@@ -1256,7 +1223,6 @@ function useADKChat({
1256
1223
  requesting = false;
1257
1224
  }
1258
1225
  };
1259
- void poll();
1260
1226
  const timer = window.setInterval(poll, sessionEventsPollingInterval);
1261
1227
  return () => {
1262
1228
  disposed = true;
@@ -1275,7 +1241,6 @@ function useADKChat({
1275
1241
  (0, import_react.useEffect)(() => {
1276
1242
  return () => {
1277
1243
  var _a2;
1278
- cancelSessionEventsFlush();
1279
1244
  (_a2 = ctrl.current) == null ? void 0 : _a2.abort();
1280
1245
  backgroundRef.current.forEach((bg) => {
1281
1246
  var _a3;
@@ -1283,7 +1248,7 @@ function useADKChat({
1283
1248
  });
1284
1249
  backgroundRef.current.clear();
1285
1250
  };
1286
- }, [cancelSessionEventsFlush]);
1251
+ }, []);
1287
1252
  return {
1288
1253
  appInfo,
1289
1254
  startChat,