@uipath/ui-widgets-conversational-agent-chat 1.1.8 → 1.2.0-beta.0

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.
Files changed (69) hide show
  1. package/dist/ConnectionsSection.stories.d.ts +30 -0
  2. package/dist/ConnectionsSection.stories.d.ts.map +1 -0
  3. package/dist/ConnectionsSection.stories.js +232 -0
  4. package/dist/ConnectionsSection.stories.js.map +1 -0
  5. package/dist/ConversationalAgentChat.css +2842 -97
  6. package/dist/ConversationalAgentChat.d.ts +1 -1
  7. package/dist/ConversationalAgentChat.d.ts.map +1 -1
  8. package/dist/ConversationalAgentChat.js +414 -24
  9. package/dist/ConversationalAgentChat.js.map +1 -1
  10. package/dist/ConversationalAgentChat.stories.d.ts +17 -3
  11. package/dist/ConversationalAgentChat.stories.d.ts.map +1 -1
  12. package/dist/ConversationalAgentChat.stories.js +13 -0
  13. package/dist/ConversationalAgentChat.stories.js.map +1 -1
  14. package/dist/components/ConnectionReadinessCard.d.ts +32 -0
  15. package/dist/components/ConnectionReadinessCard.d.ts.map +1 -0
  16. package/dist/components/ConnectionReadinessCard.js +269 -0
  17. package/dist/components/ConnectionReadinessCard.js.map +1 -0
  18. package/dist/components/ConnectionReadinessRenderer.d.ts +18 -0
  19. package/dist/components/ConnectionReadinessRenderer.d.ts.map +1 -0
  20. package/dist/components/ConnectionReadinessRenderer.js +32 -0
  21. package/dist/components/ConnectionReadinessRenderer.js.map +1 -0
  22. package/dist/components/PdfJsViewer.d.ts.map +1 -1
  23. package/dist/components/PdfJsViewer.js +16 -4
  24. package/dist/components/PdfJsViewer.js.map +1 -1
  25. package/dist/components/SettingsDialog/ConnectionsSection.d.ts +10 -0
  26. package/dist/components/SettingsDialog/ConnectionsSection.d.ts.map +1 -0
  27. package/dist/components/SettingsDialog/ConnectionsSection.js +289 -0
  28. package/dist/components/SettingsDialog/ConnectionsSection.js.map +1 -0
  29. package/dist/components/SettingsDialog/ProfileSection.d.ts.map +1 -1
  30. package/dist/components/SettingsDialog/ProfileSection.js +1 -1
  31. package/dist/components/SettingsDialog/ProfileSection.js.map +1 -1
  32. package/dist/components/SettingsDialog/SettingsDialog.d.ts +7 -1
  33. package/dist/components/SettingsDialog/SettingsDialog.d.ts.map +1 -1
  34. package/dist/components/SettingsDialog/SettingsDialog.js +3 -2
  35. package/dist/components/SettingsDialog/SettingsDialog.js.map +1 -1
  36. package/dist/constants/connectionStatus.d.ts +5 -0
  37. package/dist/constants/connectionStatus.d.ts.map +1 -0
  38. package/dist/constants/connectionStatus.js +16 -0
  39. package/dist/constants/connectionStatus.js.map +1 -0
  40. package/dist/i18n/locales/de/index.json +44 -1
  41. package/dist/i18n/locales/en/index.json +44 -1
  42. package/dist/i18n/locales/es/index.json +44 -1
  43. package/dist/i18n/locales/es-mx/index.json +44 -1
  44. package/dist/i18n/locales/fr/index.json +44 -1
  45. package/dist/i18n/locales/ja/index.json +44 -1
  46. package/dist/i18n/locales/keys/index.json +44 -1
  47. package/dist/i18n/locales/ko/index.json +44 -1
  48. package/dist/i18n/locales/pt/index.json +44 -1
  49. package/dist/i18n/locales/pt-br/index.json +44 -1
  50. package/dist/i18n/locales/ro/index.json +44 -1
  51. package/dist/i18n/locales/tr/index.json +44 -1
  52. package/dist/i18n/locales/zh-cn/index.json +44 -1
  53. package/dist/i18n/locales/zh-tw/index.json +44 -1
  54. package/dist/types.d.ts +6 -1
  55. package/dist/types.d.ts.map +1 -1
  56. package/dist/types.js.map +1 -1
  57. package/dist/utils/spanTree.d.ts +21 -0
  58. package/dist/utils/spanTree.d.ts.map +1 -0
  59. package/dist/utils/spanTree.js +118 -0
  60. package/dist/utils/spanTree.js.map +1 -0
  61. package/dist/utils.d.ts +1 -1
  62. package/dist/utils.d.ts.map +1 -1
  63. package/dist/utils.js +2 -1
  64. package/dist/utils.js.map +1 -1
  65. package/dist/version.d.ts +1 -1
  66. package/dist/version.d.ts.map +1 -1
  67. package/dist/version.js +1 -1
  68. package/dist/version.js.map +1 -1
  69. package/package.json +4 -4
@@ -1,8 +1,9 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { ApChat, AutopilotChatEvent, AutopilotChatMode, AutopilotChatPreHookAction, AutopilotChatService, } from "@uipath/apollo-react/material/components";
3
3
  import { FontVariantToken } from "@uipath/apollo-core";
4
4
  import { Alert, AlertDescription, Button, Column, Dialog, DialogContent, DialogHeader, DialogTitle, PortalContainerProvider, Toaster, toast, } from "@uipath/apollo-wind";
5
- import { ConversationalAgent, FeedbackRating, SortOrder, } from "@uipath/uipath-typescript/conversational-agent";
5
+ import { ConversationalAgent, ConversationEndReason, ConnectionState, FeedbackRating, SortOrder, } from "@uipath/uipath-typescript/conversational-agent";
6
+ import { Traces } from "@uipath/uipath-typescript/traces";
6
7
  import { useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, } from "react";
7
8
  import { createRoot } from "react-dom/client";
8
9
  import { useWidgetTranslation } from "./i18n/useWidgetTranslation";
@@ -12,10 +13,12 @@ import { Loader } from "./components/Loader";
12
13
  import { SettingsDialog } from "./components/SettingsDialog";
13
14
  import { createToolConfirmationRenderer, } from "./components/ToolConfirmationRenderer";
14
15
  import { createClientSideToolRenderer, } from "./components/ClientSideToolRenderer";
16
+ import { createConnectionReadinessRenderer } from "./components/ConnectionReadinessRenderer";
15
17
  import { ALLOWED_ATTACHMENTS } from "./constants/attachments";
16
18
  import "./ConversationalAgentChat.css";
17
19
  import { TelemetryEvent, MessageWidget, TelemetryStatus, } from "./types";
18
20
  import { convertAttachmentToFile, createFileKey, getConversationHistoryDisplayItems, getFirstRunExperience, isFlowAgent, mapCitationSource, mapExchangesToChatMessages, normalizeInput, sortEvaluationSets, } from "./utils";
21
+ import { getToolCallTraces, mergeToolCallTraceMeta } from "./utils/spanTree";
19
22
  import { trackTelemetry } from "./utils/telemetryUtils";
20
23
  import { getI18n } from "./i18n";
21
24
  import { resolveAgent as fetchAgentRelease } from "./utils/resolveAgent";
@@ -24,6 +27,8 @@ import FilePreviewer from "./components/FilePreviewer";
24
27
  // host (Studio Web) may already own. See i18n/i18n.config.ts.
25
28
  const i18n = getI18n();
26
29
  const TOOL_CONFIRMATION_WIDGET_ID_PREFIX = "confirmation-";
30
+ const CONNECTION_READINESS_CARD = "cas-connection-readiness";
31
+ const CONNECTION_READINESS_CARD_ID = "connection-readiness-card";
27
32
  // Exchanges per page when lazily loading a conversation's history. Pages are
28
33
  // fetched newest-first and prepended as the user scrolls toward the top.
29
34
  const EXCHANGES_PAGE_SIZE = 15;
@@ -37,7 +42,7 @@ const CONVERSATION_LABEL_MAX_LENGTH = 100;
37
42
  function toApolloSupportedLocale(widgetLocale) {
38
43
  return widgetLocale === "keys" ? "en" : widgetLocale;
39
44
  }
40
- export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConversationId, externalUserId, inputSchema: inputSchemaProp, locale = "en", theme: themeProp, mode = AutopilotChatMode.Embedded, readOnly = false, overrideLabels, firstRunExperience, disabledFeatures, citationPreview = true, usePdfJsViewer = true, jobStartOverrides, isDebugMode = false, evaluationSets, addToEvalButtonLabel, onEvaluationSetClicked, onUserMessageSent, surfaceName, surfaceVersion, }) => {
45
+ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConversationId, externalUserId, inputSchema: inputSchemaProp, locale = "en", theme: themeProp, mode = AutopilotChatMode.Embedded, renderer = "material", readOnly = false, overrideLabels, firstRunExperience, disabledFeatures, citationPreview = true, usePdfJsViewer = true, jobStartOverrides, isDebugMode = false, evaluationSets, addToEvalButtonLabel, onEvaluationSetClicked, onUserMessageSent, surfaceName, surfaceVersion, }) => {
41
46
  // `inputSchema` is an internal debug-only override. In normal usage the
42
47
  // schema is resolved from the agent release, so accepting it outside debug
43
48
  // mode would only confuse callers — reject the combination loudly.
@@ -61,6 +66,7 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
61
66
  const initializedFor = useRef(null);
62
67
  const themeRef = useRef(theme);
63
68
  const modeRef = useRef(mode);
69
+ const rendererRef = useRef(renderer);
64
70
  const overrideLabelsRef = useRef(overrideLabels);
65
71
  const disabledFeaturesRef = useRef(disabledFeatures);
66
72
  const firstRunExperienceRef = useRef(firstRunExperience);
@@ -71,11 +77,13 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
71
77
  // Per-instance so unmounting one widget doesn't tear down another's React roots.
72
78
  const toolConfirmationRenderer = useMemo(() => createToolConfirmationRenderer(), []);
73
79
  const clientSideToolRenderer = useMemo(() => createClientSideToolRenderer(), []);
80
+ const connectionReadinessRenderer = useMemo(() => createConnectionReadinessRenderer(), []);
74
81
  // useLayoutEffect is ok here because the work is minimal enough that the cost is essentially zero
75
82
  // needed because React 19 doesn't support ref writes on render
76
83
  useLayoutEffect(() => {
77
84
  themeRef.current = theme;
78
85
  modeRef.current = mode;
86
+ rendererRef.current = renderer;
79
87
  overrideLabelsRef.current = overrideLabels;
80
88
  disabledFeaturesRef.current = disabledFeatures;
81
89
  firstRunExperienceRef.current = firstRunExperience;
@@ -92,6 +100,7 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
92
100
  }, [
93
101
  theme,
94
102
  mode,
103
+ renderer,
95
104
  overrideLabels,
96
105
  disabledFeatures,
97
106
  firstRunExperience,
@@ -99,6 +108,7 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
99
108
  onUserMessageSent,
100
109
  citationPreview,
101
110
  folderId,
111
+ locale,
102
112
  t,
103
113
  ]);
104
114
  // Rebuild the SDK service when sdk or externalUserId change. Skip the first run because the
@@ -117,13 +127,24 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
117
127
  const pastConversations = useRef([]);
118
128
  const uploadedAttachments = useRef(new Map());
119
129
  const conversationsCursor = useRef(undefined);
130
+ // Why the active conversation ended, or null while it's open. A ref so the
131
+ // send handler reads the current value without re-registering.
132
+ const endReasonRef = useRef(null);
120
133
  // Cursor for the active conversation's exchange history. Reset whenever a
121
134
  // conversation is opened/started; undefined means no older pages remain.
122
135
  const exchangesCursor = useRef(undefined);
123
136
  const agentIdRef = useRef(undefined);
124
137
  const agentKeyRef = useRef(undefined);
138
+ const toolDisplayModeRef = useRef(undefined);
125
139
  const isFlowAgentRef = useRef(false);
126
140
  const searchTextRef = useRef("");
141
+ // Latest spans for the active conversation's trace, polled only in FullTrace mode
142
+ const traceSpansRef = useRef([]);
143
+ // toolCallId -> JSON of the last-sent meta, so unchanged tool calls aren't re-sent each poll.
144
+ const sentToolCallMetaJsonRef = useRef(new Map());
145
+ const tracePollIntervalRef = useRef(null);
146
+ const tracePollInFlightRef = useRef(null);
147
+ const isMountedRef = useRef(false);
127
148
  const [chatService, setChatService] = useState();
128
149
  const [error, setError] = useState(null);
129
150
  const [inputSchemaState, setInputSchemaState] = useState(null);
@@ -139,11 +160,13 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
139
160
  const [citationPreviewData, setCitationPreviewData] = useState(null);
140
161
  const citationPreviewRef = useRef(citationPreview);
141
162
  const [hasMessages, setHasMessages] = useState(false);
163
+ const [connectionReadiness, setConnectionReadiness] = useState(null);
142
164
  const [themeRoot, setThemeRoot] = useState(null);
143
165
  const onEvaluationSetClickedRef = useRef(onEvaluationSetClicked);
144
166
  const onUserMessageSentRef = useRef(onUserMessageSent);
145
167
  const chatServiceRef = useRef(null);
146
168
  const settingsRootRef = useRef(null);
169
+ const autoBindTimeoutRef = useRef(null);
147
170
  // Last-applied agent inputs for the active conversation. Pre-populates the
148
171
  // settings inputs form when reopened; cleared on New Chat.
149
172
  const storedAgentInputs = useRef({});
@@ -153,6 +176,96 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
153
176
  useLayoutEffect(() => {
154
177
  inputSchemaStateRef.current = inputSchemaState;
155
178
  }, [inputSchemaState]);
179
+ // Merge the trace's "conversationToolCall" spans into their tool call messages (keyed by toolCallId)
180
+ const applyTraceSpans = useCallback((spans) => {
181
+ // Only FullTrace renders the span tree; other modes use the SDK's tool call events alone.
182
+ if (toolDisplayModeRef.current !== "FullTrace")
183
+ return;
184
+ const chat = chatServiceRef.current;
185
+ if (!chat)
186
+ return;
187
+ traceSpansRef.current = spans;
188
+ const conversation = chat.getConversation() ?? [];
189
+ for (const trace of getToolCallTraces(spans)) {
190
+ // The trace only enriches tool call messages the SDK or history already
191
+ // created, so it can't show a tool call before its deferred spinner
192
+ // (e.g. while a confirmation is pending).
193
+ const existing = conversation.find((m) => m.id === trace.toolCallId);
194
+ if (!existing)
195
+ continue;
196
+ const meta = mergeToolCallTraceMeta(trace, existing.meta, toolDisplayModeRef.current);
197
+ const metaJson = JSON.stringify(meta);
198
+ if (sentToolCallMetaJsonRef.current.get(trace.toolCallId) === metaJson) {
199
+ continue;
200
+ }
201
+ chat.sendResponse({
202
+ ...existing,
203
+ id: trace.toolCallId,
204
+ content: t("performing_action_message", {
205
+ action: meta.toolName ?? "",
206
+ }),
207
+ created_at: existing.created_at ?? trace.startTime,
208
+ widget: MessageWidget.ApolloAgentsToolCall,
209
+ meta,
210
+ });
211
+ sentToolCallMetaJsonRef.current.set(trace.toolCallId, metaJson);
212
+ }
213
+ }, [t]);
214
+ const fetchAndApplyTrace = useCallback(async (traceId) => {
215
+ try {
216
+ const spans = await new Traces(sdk).getById(traceId);
217
+ if (!isMountedRef.current ||
218
+ currentConversation.current?.traceId !== traceId) {
219
+ return;
220
+ }
221
+ applyTraceSpans(spans);
222
+ }
223
+ catch {
224
+ // Transient errors: the next poll tick (or reopening) retries.
225
+ }
226
+ }, [sdk, applyTraceSpans]);
227
+ // Live polling on FullTrace mode only.
228
+ const startTracePolling = useCallback(() => {
229
+ if (toolDisplayModeRef.current !== "FullTrace")
230
+ return;
231
+ const traceId = currentConversation.current?.traceId;
232
+ if (!traceId || tracePollIntervalRef.current)
233
+ return;
234
+ const tick = async () => {
235
+ if (tracePollInFlightRef.current)
236
+ return;
237
+ const poll = fetchAndApplyTrace(traceId);
238
+ tracePollInFlightRef.current = poll;
239
+ try {
240
+ await poll;
241
+ }
242
+ finally {
243
+ tracePollInFlightRef.current = null;
244
+ }
245
+ };
246
+ void tick();
247
+ tracePollIntervalRef.current = setInterval(tick, 1000);
248
+ }, [fetchAndApplyTrace]);
249
+ const stopTracePolling = useCallback((finalFetch) => {
250
+ if (!tracePollIntervalRef.current)
251
+ return;
252
+ clearInterval(tracePollIntervalRef.current);
253
+ tracePollIntervalRef.current = null;
254
+ const traceId = currentConversation.current?.traceId;
255
+ if (!finalFetch || !traceId)
256
+ return;
257
+ const pendingPoll = tracePollInFlightRef.current;
258
+ void (async () => {
259
+ await pendingPoll;
260
+ await fetchAndApplyTrace(traceId);
261
+ })();
262
+ }, [fetchAndApplyTrace]);
263
+ // On leaving a conversation, stop polling
264
+ const resetTraceState = useCallback(() => {
265
+ stopTracePolling(false);
266
+ traceSpansRef.current = [];
267
+ sentToolCallMetaJsonRef.current = new Map();
268
+ }, [stopTracePolling]);
156
269
  const setupExchangeHandlers = useCallback((exchange) => {
157
270
  if (!chatService)
158
271
  return;
@@ -164,6 +277,10 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
164
277
  });
165
278
  exchange.onMessageStart((message) => {
166
279
  if (message.startEvent.role === "assistant") {
280
+ if (toolDisplayModeRef.current === "FullTrace") {
281
+ startTracePolling();
282
+ message.onMessageEnd(() => stopTracePolling(true));
283
+ }
167
284
  const messageId = message.messageId;
168
285
  const messageTimestamp = message.startEvent.timestamp;
169
286
  const exchangeId = exchange.exchangeId;
@@ -215,6 +332,17 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
215
332
  });
216
333
  // Track tool calls so we can defer the spinner when an interrupt arrives
217
334
  const pendingToolCalls = new Map();
335
+ // In FullTrace the SDK's tool call events still render the tool call,
336
+ // so it appears and completes even if trace fetches fail
337
+ const withTraceSpan = (toolCallId, meta) => {
338
+ if (toolDisplayModeRef.current !== "FullTrace")
339
+ return meta;
340
+ sentToolCallMetaJsonRef.current.delete(toolCallId);
341
+ const span = chatService
342
+ .getConversation()
343
+ ?.find((m) => m.id === toolCallId)?.meta?.span;
344
+ return span ? { ...meta, span } : meta;
345
+ };
218
346
  const sendToolCallSpinner = (toolCallId) => {
219
347
  const pending = pendingToolCalls.get(toolCallId);
220
348
  if (!pending || pending.spinnerSent)
@@ -227,11 +355,12 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
227
355
  }),
228
356
  created_at: pending.startTimeIso,
229
357
  widget: MessageWidget.ApolloAgentsToolCall,
230
- meta: {
358
+ meta: withTraceSpan(toolCallId, {
231
359
  toolName: pending.toolName,
232
360
  input: pending.toolInput,
233
361
  startTime: pending.startTimeIso,
234
- },
362
+ displayMode: toolDisplayModeRef.current,
363
+ }),
235
364
  });
236
365
  };
237
366
  // Caller supplies the approve/reject channel.
@@ -303,7 +432,7 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
303
432
  }),
304
433
  created_at: endTimeIso,
305
434
  widget: MessageWidget.ApolloAgentsToolCall,
306
- meta: {
435
+ meta: withTraceSpan(toolCall.toolCallId, {
307
436
  toolName: startEvent.toolName,
308
437
  input: toolInput,
309
438
  startTime: startTimeIso,
@@ -311,7 +440,8 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
311
440
  endTime: endTimeIso,
312
441
  isError,
313
442
  ...(cancelled && { cancelled: true }),
314
- },
443
+ displayMode: toolDisplayModeRef.current,
444
+ }),
315
445
  });
316
446
  pendingToolCalls.delete(toolCall.toolCallId);
317
447
  };
@@ -397,13 +527,14 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
397
527
  }
398
528
  });
399
529
  exchange.onExchangeEnd(() => {
530
+ stopTracePolling(true);
400
531
  activeExchange.current = null;
401
532
  chatService.sendOutputStreamEvent({ turnComplete: true });
402
533
  chatService.setShowLoading(false);
403
534
  chatService.setWaiting(false);
404
535
  setHasMessages(true);
405
536
  });
406
- }, [chatService, t]);
537
+ }, [chatService, startTracePolling, stopTracePolling, t]);
407
538
  const resolveAgent = useCallback(async () => {
408
539
  let effectiveAgentId = agentId;
409
540
  let effectiveFolderId = folderIdRef.current;
@@ -472,6 +603,26 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
472
603
  setConversationHistory,
473
604
  t,
474
605
  ]);
606
+ const showEndedBanner = useCallback((reason) => {
607
+ const message = reason === ConversationEndReason.Failed
608
+ ? t("conversation_ended_failed")
609
+ : reason === ConversationEndReason.Cancelled
610
+ ? t("conversation_ended_cancelled")
611
+ : t("conversation_ended_completed");
612
+ // Clearing also unmounts a dismissed banner; Apollo's alert keeps its hidden state otherwise.
613
+ chatServiceRef.current?.clearError();
614
+ chatServiceRef.current?.setError(message, reason === ConversationEndReason.Completed ? "warn" : "error");
615
+ }, [t]);
616
+ const applyEndedState = useCallback((reason) => {
617
+ endReasonRef.current = reason ?? ConversationEndReason.Completed;
618
+ showEndedBanner(endReasonRef.current);
619
+ }, [showEndedBanner]);
620
+ const clearEndedState = useCallback(() => {
621
+ if (!endReasonRef.current)
622
+ return;
623
+ endReasonRef.current = null;
624
+ chatServiceRef.current?.clearError();
625
+ }, []);
475
626
  const getSessionHelper = useCallback(async () => {
476
627
  if (session.current) {
477
628
  return session.current;
@@ -487,6 +638,20 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
487
638
  sessionHelper.onLabelUpdated(({ label }) => {
488
639
  setConversationHistory(pastConversations.current.map((c) => c.id === conversation.id ? { ...c, label } : c));
489
640
  });
641
+ sessionHelper.onConversationEnd(({ reason }) => {
642
+ const endReason = reason ?? ConversationEndReason.Completed;
643
+ const endedTime = new Date().toISOString();
644
+ // Mark it ended in the history list so reopening it later shows the ended state.
645
+ setConversationHistory(pastConversations.current.map((c) => c.id === conversation.id ? { ...c, endedTime, endReason } : c));
646
+ if (currentConversation.current?.id !== conversation.id)
647
+ return;
648
+ currentConversation.current = {
649
+ ...currentConversation.current,
650
+ endedTime,
651
+ endReason,
652
+ };
653
+ applyEndedState(endReason);
654
+ });
490
655
  // Buffer outgoing events until the server confirms the session is started,
491
656
  // then flush — so a send never blocks on the sessionStarted round-trip.
492
657
  // Combined with ending the session on switch (see endActiveSession), a
@@ -519,7 +684,13 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
519
684
  chatService?.setError(error.message || t("error_generic"));
520
685
  });
521
686
  return sessionHelper;
522
- }, [chatService, getConversation, setConversationHistory, t]);
687
+ }, [
688
+ applyEndedState,
689
+ chatService,
690
+ getConversation,
691
+ setConversationHistory,
692
+ t,
693
+ ]);
523
694
  // End the session on conversation switch/unmount so a reopen starts fresh and
524
695
  // gets a new `sessionStarted` — reusing a stale session hangs the send. The
525
696
  // in-flight exchange is left running (ending it is reserved for onStopResponse),
@@ -534,14 +705,61 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
534
705
  activeExchange.current = null;
535
706
  session.current = null;
536
707
  }, []);
708
+ // Shared helper: fetch connection readiness and update state.
709
+ const fetchConnectionReadiness = useCallback(() => {
710
+ const capturedAgentId = agentIdRef.current;
711
+ const capturedFolderId = folderIdRef.current;
712
+ if (capturedAgentId == null || capturedFolderId == null)
713
+ return;
714
+ const capturedInitKey = initializedFor.current;
715
+ const applyReadiness = (items) => {
716
+ if (initializedFor.current !== capturedInitKey)
717
+ return;
718
+ if (items.length === 0) {
719
+ setConnectionReadiness(null);
720
+ return;
721
+ }
722
+ const readiness = items.map((item) => {
723
+ const selectedConn = item.currentConnectionId
724
+ ? item.connections?.find((c) => c.id === item.currentConnectionId)
725
+ : undefined;
726
+ return {
727
+ connectorKey: item.connectorKey,
728
+ connectorName: item.connectorName ?? item.connectorKey,
729
+ connectorImage: item.connectorImage,
730
+ isConfigurable: item.isConfigurable !== false,
731
+ currentConnectionId: item.currentConnectionId,
732
+ currentConnectionName: item.currentConnectionName,
733
+ currentConnectionState: selectedConn?.state ??
734
+ (item.currentConnectionId ? ConnectionState.Expired : undefined),
735
+ connectionsUrl: item.connectionsUrl,
736
+ };
737
+ });
738
+ const hasUnresolved = readiness.some((c) => c.isConfigurable &&
739
+ (!c.currentConnectionId ||
740
+ c.currentConnectionState !== ConnectionState.Enabled));
741
+ setConnectionReadiness(hasUnresolved ? readiness : null);
742
+ };
743
+ agentService.current
744
+ .getAvailableConnections(capturedAgentId, capturedFolderId)
745
+ .then(applyReadiness)
746
+ .catch(() => {
747
+ if (initializedFor.current !== capturedInitKey)
748
+ return;
749
+ setConnectionReadiness(null);
750
+ });
751
+ }, []);
537
752
  const onNewChat = useCallback(() => {
538
753
  endActiveSession();
754
+ clearEndedState();
539
755
  currentConversation.current = null;
540
756
  session.current = null;
541
757
  activeExchange.current = null;
542
758
  exchangesCursor.current = undefined;
543
759
  storedAgentInputs.current = {};
760
+ resetTraceState();
544
761
  setHasMessages(false);
762
+ connectionReadinessRenderer.unmountAll();
545
763
  // Re-show the InputsPage with a cleared form when the agent's schema has
546
764
  // required inputs. Bumping the counter forces an unmount/remount via the
547
765
  // key on <InputsPage>, which resets internal form state.
@@ -549,8 +767,16 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
549
767
  setInputsInstance((n) => n + 1);
550
768
  setShowInputPage(true);
551
769
  }
770
+ fetchConnectionReadiness();
552
771
  trackTelemetry(TelemetryEvent.NewChat, TelemetryStatus.Success);
553
- }, [endActiveSession, inputSchemaState]);
772
+ }, [
773
+ clearEndedState,
774
+ endActiveSession,
775
+ fetchConnectionReadiness,
776
+ inputSchemaState,
777
+ connectionReadinessRenderer,
778
+ resetTraceState,
779
+ ]);
554
780
  const buildHistoryFilterOptions = useCallback(() => {
555
781
  // The SDK's URL builder calls value.toString() without a null check, so
556
782
  // omit any param that is undefined/empty rather than passing it as such.
@@ -620,9 +846,21 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
620
846
  }
621
847
  }, [chatService, setConversationHistory, t, toasterId]);
622
848
  const onSendMessage = useCallback(async (data) => {
849
+ // An ended conversation accepts no input. Apollo has already added the
850
+ // request bubble and loading state before this runs, and has no pre-hook
851
+ // for sends, so re-show the banner and undo the loading state.
852
+ if (endReasonRef.current) {
853
+ showEndedBanner(endReasonRef.current);
854
+ chatService?.stopResponse();
855
+ return;
856
+ }
623
857
  try {
624
858
  // required for debug-mode hosts that need to gate agent execution on the first user message
625
859
  onUserMessageSentRef.current?.({ content: data.content });
860
+ // Clearing also unmounts a dismissed banner; Apollo's alert keeps its hidden state otherwise.
861
+ chatService?.clearError();
862
+ setHasMessages(true);
863
+ setConnectionReadiness(null);
626
864
  const sessionHelper = await getSessionHelper();
627
865
  const exchange = sessionHelper.startExchange();
628
866
  chatService?.setWaiting(true);
@@ -658,7 +896,7 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
658
896
  });
659
897
  chatService?.setError(t("error_send_message", { errorMessage }));
660
898
  }
661
- }, [chatService, getSessionHelper, setupExchangeHandlers, t]);
899
+ }, [chatService, getSessionHelper, setupExchangeHandlers, showEndedBanner, t]);
662
900
  const processAttachmentsInBatch = useCallback(async (attachmentBatch) => {
663
901
  if (!chatService)
664
902
  return;
@@ -752,13 +990,26 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
752
990
  if (!selectedConversation)
753
991
  return;
754
992
  endActiveSession();
993
+ resetTraceState();
755
994
  currentConversation.current = selectedConversation;
756
995
  session.current = null;
757
996
  exchangesCursor.current = undefined;
997
+ connectionReadinessRenderer.unmountAll();
758
998
  const { exchanges } = await fetchExchanges(selectedConversation.id);
759
- const messages = mapExchangesToChatMessages(exchanges);
999
+ const messages = mapExchangesToChatMessages(exchanges, toolDisplayModeRef.current);
760
1000
  chatService.setConversation(messages);
761
1001
  setHasMessages(messages.length > 0);
1002
+ if (selectedConversation.endedTime) {
1003
+ applyEndedState(selectedConversation.endReason);
1004
+ }
1005
+ else {
1006
+ endReasonRef.current = null;
1007
+ }
1008
+ fetchConnectionReadiness();
1009
+ if (toolDisplayModeRef.current === "FullTrace" &&
1010
+ selectedConversation.traceId) {
1011
+ void fetchAndApplyTrace(selectedConversation.traceId);
1012
+ }
762
1013
  trackTelemetry(TelemetryEvent.OpenConversation, TelemetryStatus.Success, {
763
1014
  conversationId: id,
764
1015
  });
@@ -771,7 +1022,17 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
771
1022
  });
772
1023
  chatService.setError(t("error_open_conversation", { errorMessage }));
773
1024
  }
774
- }, [chatService, endActiveSession, fetchExchanges, t]);
1025
+ }, [
1026
+ applyEndedState,
1027
+ chatService,
1028
+ connectionReadinessRenderer,
1029
+ endActiveSession,
1030
+ fetchAndApplyTrace,
1031
+ fetchConnectionReadiness,
1032
+ fetchExchanges,
1033
+ resetTraceState,
1034
+ t,
1035
+ ]);
775
1036
  // Apollo fires this when the user scrolls to the top of the message list.
776
1037
  // Prepend the next older page; signal `done` (no more pages) so Apollo stops
777
1038
  // requesting once the cursor is exhausted.
@@ -785,7 +1046,8 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
785
1046
  }
786
1047
  try {
787
1048
  const { exchanges, hasNextPage } = await fetchExchanges(conversationId, exchangesCursor.current);
788
- chatService.prependOlderMessages(mapExchangesToChatMessages(exchanges), !hasNextPage);
1049
+ chatService.prependOlderMessages(mapExchangesToChatMessages(exchanges, toolDisplayModeRef.current), !hasNextPage);
1050
+ applyTraceSpans(traceSpansRef.current);
789
1051
  }
790
1052
  catch (err) {
791
1053
  chatService.prependOlderMessages([], true);
@@ -795,14 +1057,22 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
795
1057
  error: errorMessage,
796
1058
  });
797
1059
  }
798
- }, [chatService, fetchExchanges]);
1060
+ }, [applyTraceSpans, chatService, fetchExchanges]);
799
1061
  const initChat = useCallback(async () => {
800
1062
  const initKey = `${agentId}-${folderId}-${existingConversationId ?? ""}-${externalUserId ?? ""}`;
801
1063
  try {
802
1064
  initializedFor.current = initKey;
1065
+ setConnectionReadiness(null);
1066
+ if (autoBindTimeoutRef.current) {
1067
+ clearTimeout(autoBindTimeoutRef.current);
1068
+ autoBindTimeoutRef.current = null;
1069
+ }
803
1070
  const agentRelease = await resolveAgent();
804
1071
  agentIdRef.current = agentRelease?.id;
805
1072
  agentKeyRef.current = agentRelease?.releaseKey;
1073
+ toolDisplayModeRef.current =
1074
+ agentRelease?.appearance
1075
+ ?.displayMode ?? "InputsAndOutputs";
806
1076
  isFlowAgentRef.current = isFlowAgent(agentRelease);
807
1077
  const agentName = agentRelease?.name ?? "";
808
1078
  // In debug mode the agent (and its derived schema) may not be resolvable,
@@ -831,6 +1101,17 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
831
1101
  // callers can override the welcome copy and starting prompts, falling
832
1102
  // back to the agent's own appearance.
833
1103
  const firstRunExperienceConfig = getFirstRunExperience(firstRunExperienceRef.current, agentRelease?.appearance);
1104
+ // Fetch connection readiness (fire-and-forget; card is optional)
1105
+ if (agentRelease) {
1106
+ fetchConnectionReadiness();
1107
+ // Re-fetch after a delay to pick up server-side auto-bind results
1108
+ autoBindTimeoutRef.current = setTimeout(() => {
1109
+ autoBindTimeoutRef.current = null;
1110
+ if (initializedFor.current !== initKey)
1111
+ return;
1112
+ fetchConnectionReadiness();
1113
+ }, 1500);
1114
+ }
834
1115
  // Persists agent inputs against the active conversation via
835
1116
  // updateConversation. Server-side this applies to all subsequent
836
1117
  // messages; we don't prepend per send.
@@ -869,12 +1150,16 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
869
1150
  : "no-agent";
870
1151
  const conversationId = currentConversation.current?.id ?? "no-conv";
871
1152
  const inputsResetKey = `${profileResetKey}-${conversationId}`;
872
- root.render(_jsx(PortalContainerProvider, { children: _jsx(SettingsDialog, { profileResetKey: profileResetKey, conversationalAgent: agentService.current, onClose: () => chatServiceRef.current?.toggleSettings(false), inputSchema: inputSchemaStateRef.current, initialInputs: storedAgentInputs.current, onApplyInputs: handleApplySettingsInputs, inputsResetKey: inputsResetKey }) }));
1153
+ root.render(_jsx(PortalContainerProvider, { children: _jsx(SettingsDialog, { profileResetKey: profileResetKey, conversationalAgent: agentService.current, onClose: () => {
1154
+ chatServiceRef.current?.toggleSettings(false);
1155
+ fetchConnectionReadiness();
1156
+ }, inputSchema: inputSchemaStateRef.current, initialInputs: storedAgentInputs.current, onApplyInputs: handleApplySettingsInputs, inputsResetKey: inputsResetKey, agentId: agentIdRef.current, folderId: folderIdRef.current, onConnectionsChanged: fetchConnectionReadiness }) }));
873
1157
  };
874
1158
  const chatServiceInstance = AutopilotChatService.Instantiate({
875
1159
  instanceName: `agent-${agentId}-${folderId}`,
876
1160
  config: {
877
1161
  mode: modeRef.current,
1162
+ renderer: rendererRef.current,
878
1163
  locale: toApolloSupportedLocale(locale),
879
1164
  theme: themeRef.current,
880
1165
  readOnly,
@@ -987,14 +1272,26 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
987
1272
  // Singleton keeps the previous conversation's unsent draft and error banner; drop both before the awaits.
988
1273
  chatServiceInstance.setPrompt("");
989
1274
  chatServiceInstance.clearError();
1275
+ endReasonRef.current = null;
990
1276
  if (!disabledFeaturesRef.current?.attachments) {
991
1277
  chatServiceInstance.setAllowedAttachments(ALLOWED_ATTACHMENTS);
992
1278
  }
1279
+ // Clean up any existing readiness roots before replacing the conversation
1280
+ connectionReadinessRenderer.unmountAll();
993
1281
  if (existingConversationId) {
994
1282
  const conversation = await getConversation();
995
1283
  exchangesCursor.current = undefined;
996
1284
  const { exchanges } = await fetchExchanges(conversation.id);
997
- chatServiceInstance.setConversation(mapExchangesToChatMessages(exchanges));
1285
+ const messages = mapExchangesToChatMessages(exchanges);
1286
+ chatServiceInstance.setConversation(mapExchangesToChatMessages(exchanges, toolDisplayModeRef.current));
1287
+ if (conversation.endedTime) {
1288
+ applyEndedState(conversation.endReason);
1289
+ }
1290
+ if (toolDisplayModeRef.current === "FullTrace" &&
1291
+ conversation.traceId) {
1292
+ void fetchAndApplyTrace(conversation.traceId);
1293
+ }
1294
+ setHasMessages(messages.length > 0);
998
1295
  }
999
1296
  else {
1000
1297
  // AutopilotChatService is a singleton, so it may still hold the
@@ -1010,6 +1307,8 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
1010
1307
  }
1011
1308
  }, [
1012
1309
  agentId,
1310
+ applyEndedState,
1311
+ fetchAndApplyTrace,
1013
1312
  folderId,
1014
1313
  existingConversationId,
1015
1314
  externalUserId,
@@ -1019,6 +1318,8 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
1019
1318
  readOnly,
1020
1319
  resolveAgent,
1021
1320
  getConversation,
1321
+ fetchConnectionReadiness,
1322
+ connectionReadinessRenderer,
1022
1323
  fetchExchanges,
1023
1324
  t,
1024
1325
  toasterId,
@@ -1032,18 +1333,20 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
1032
1333
  const onStopResponse = useCallback(() => {
1033
1334
  if (!chatService)
1034
1335
  return;
1336
+ stopTracePolling(true);
1035
1337
  if (activeExchange.current) {
1036
1338
  // Flows own their exchange; a client exchange end strands them. Switching
1037
1339
  // conversations still fires StopResponse.
1038
1340
  if (!isFlowAgentRef.current) {
1039
1341
  activeExchange.current.sendExchangeEnd();
1342
+ chatService.setError(t("response_stopped_message"), "warn");
1040
1343
  }
1041
1344
  activeExchange.current = null;
1042
1345
  }
1043
1346
  chatService.sendOutputStreamEvent({ turnComplete: true });
1044
1347
  chatService.setShowLoading(false);
1045
1348
  chatService.setWaiting(false);
1046
- }, [chatService]);
1349
+ }, [chatService, stopTracePolling, t]);
1047
1350
  const onCustomHeaderActionClicked = useCallback((action) => {
1048
1351
  if (action.id.startsWith("eval-")) {
1049
1352
  const evaluationSetId = action.id.replace("eval-", "");
@@ -1108,6 +1411,10 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
1108
1411
  settingsRootRef.current.unmount();
1109
1412
  settingsRootRef.current = null;
1110
1413
  }
1414
+ if (autoBindTimeoutRef.current) {
1415
+ clearTimeout(autoBindTimeoutRef.current);
1416
+ autoBindTimeoutRef.current = null;
1417
+ }
1111
1418
  };
1112
1419
  }, []);
1113
1420
  useEffect(() => {
@@ -1116,10 +1423,23 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
1116
1423
  useEffect(() => {
1117
1424
  chatService?.setChatMode(mode);
1118
1425
  }, [chatService, mode]);
1119
- // Close the SDK session on unmount so the WebSocket doesn't linger.
1426
+ useEffect(() => {
1427
+ chatService?.setRenderer(renderer);
1428
+ }, [chatService, renderer]);
1429
+ useEffect(() => {
1430
+ isMountedRef.current = true;
1431
+ return () => {
1432
+ isMountedRef.current = false;
1433
+ };
1434
+ }, []);
1435
+ // Close the SDK session and stop trace polling on unmount so neither lingers
1120
1436
  useEffect(() => {
1121
1437
  return () => {
1122
1438
  endActiveSession();
1439
+ if (tracePollIntervalRef.current) {
1440
+ clearInterval(tracePollIntervalRef.current);
1441
+ tracePollIntervalRef.current = null;
1442
+ }
1123
1443
  };
1124
1444
  }, [endActiveSession]);
1125
1445
  // Release React state held by the imperative tool-confirmation and client-side tool roots.
@@ -1127,8 +1447,13 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
1127
1447
  return () => {
1128
1448
  toolConfirmationRenderer.unmountAll();
1129
1449
  clientSideToolRenderer.unmountAll();
1450
+ connectionReadinessRenderer.unmountAll();
1130
1451
  };
1131
- }, [toolConfirmationRenderer, clientSideToolRenderer]);
1452
+ }, [
1453
+ toolConfirmationRenderer,
1454
+ clientSideToolRenderer,
1455
+ connectionReadinessRenderer,
1456
+ ]);
1132
1457
  // Register event handlers after chatService is available
1133
1458
  useEffect(() => {
1134
1459
  if (!chatService)
@@ -1152,6 +1477,15 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
1152
1477
  name: MessageWidget.ClientSideToolInput,
1153
1478
  render: (container, message) => clientSideToolRenderer.render(container, message),
1154
1479
  });
1480
+ chatService.injectMessageRenderer({
1481
+ name: CONNECTION_READINESS_CARD,
1482
+ render: (container, message) => connectionReadinessRenderer.render(container, message, {
1483
+ conversationalAgent: agentService.current,
1484
+ onAllConnected: () => setConnectionReadiness(null),
1485
+ onOpenSettings: () => chatServiceRef.current?.toggleSettings(true),
1486
+ onConnectionsChanged: fetchConnectionReadiness,
1487
+ }),
1488
+ });
1155
1489
  }
1156
1490
  catch (err) {
1157
1491
  const message = err instanceof Error ? err.message : t("error_load_history");
@@ -1182,6 +1516,62 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
1182
1516
  t,
1183
1517
  toolConfirmationRenderer,
1184
1518
  clientSideToolRenderer,
1519
+ connectionReadinessRenderer,
1520
+ fetchConnectionReadiness,
1521
+ ]);
1522
+ // Inject/update/remove the connection readiness card as a message in the
1523
+ // conversation — matching CAS positioning inside the scroll area.
1524
+ useEffect(() => {
1525
+ if (!chatService)
1526
+ return;
1527
+ const conversation = chatService.getConversation() ?? [];
1528
+ const existingIndex = conversation.findIndex(
1529
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1530
+ (m) => m.id === CONNECTION_READINESS_CARD_ID);
1531
+ if (connectionReadiness) {
1532
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1533
+ const cardMessage = {
1534
+ id: CONNECTION_READINESS_CARD_ID,
1535
+ content: " ",
1536
+ created_at: new Date().toISOString(),
1537
+ role: "assistant",
1538
+ widget: CONNECTION_READINESS_CARD,
1539
+ done: true,
1540
+ disableActions: true,
1541
+ meta: {
1542
+ connectors: connectionReadiness,
1543
+ agentId: agentIdRef.current,
1544
+ folderId: folderIdRef.current,
1545
+ defaultCollapsed: hasMessages,
1546
+ },
1547
+ };
1548
+ if (existingIndex >= 0) {
1549
+ const updated = [...conversation];
1550
+ updated[existingIndex] = cardMessage;
1551
+ chatService.setConversation(updated);
1552
+ }
1553
+ else if (hasMessages) {
1554
+ // Append so the card appears near the bottom where the user is
1555
+ chatService.setConversation([...conversation, cardMessage]);
1556
+ }
1557
+ else {
1558
+ // Fresh conversation — card goes first, before welcome message
1559
+ chatService.setConversation([cardMessage, ...conversation]);
1560
+ }
1561
+ }
1562
+ else if (existingIndex >= 0) {
1563
+ // Defer unmount — the card's onAllConnected effect may still be
1564
+ // executing inside this root's React tree when this runs.
1565
+ queueMicrotask(() => connectionReadinessRenderer.unmountAll());
1566
+ chatService.setConversation(
1567
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1568
+ conversation.filter((m) => m.id !== CONNECTION_READINESS_CARD_ID));
1569
+ }
1570
+ }, [
1571
+ chatService,
1572
+ connectionReadiness,
1573
+ hasMessages,
1574
+ connectionReadinessRenderer,
1185
1575
  ]);
1186
1576
  useEffect(() => {
1187
1577
  if (!chatService ||
@@ -1236,10 +1626,10 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
1236
1626
  }
1237
1627
  storedAgentInputs.current = inputs;
1238
1628
  setShowInputPage(false);
1239
- } }, `${agentId}-${inputsInstance}`)), error && (_jsxs("div", { className: "info-container", children: [_jsx(Alert, { variant: "destructive", children: _jsx(AlertDescription, { children: error }) }), _jsx(Button, { variant: "outline", onClick: handleReload, children: t("reload") })] })), !error && !chatService && (_jsxs("div", { className: "info-container", children: [_jsx("div", { children: t("loading") }), _jsx(Loader, {})] })), !error && chatService && !showInputPage && (_jsx(ApChat, { chatServiceInstance: chatService, locale: toApolloSupportedLocale(locale), theme: theme, enableInternalThemeProvider: true,
1240
- // Keep Apollo's tooltips, menus and history popover inside the
1241
- // themed wrapper; portalled to <body> they'd lose the theme tokens.
1242
- portalContainer: themeRoot ?? undefined }, locale)), _jsx(FeedbackDialog, { open: feedbackDialogOpen, isPositive: feedbackIsPositive, onOpenChange: setFeedbackDialogOpen, onSubmit: onFeedbackSubmit, onCancel: onFeedbackCancel }), _jsx(Dialog, { open: !!citationPreviewData, onOpenChange: (open) => {
1629
+ } }, `${agentId}-${inputsInstance}`)), error && (_jsxs("div", { className: "info-container", children: [_jsx(Alert, { variant: "destructive", children: _jsx(AlertDescription, { children: error }) }), _jsx(Button, { variant: "outline", onClick: handleReload, children: t("reload") })] })), !error && !chatService && (_jsxs("div", { className: "info-container", children: [_jsx("div", { children: t("loading") }), _jsx(Loader, {})] })), !error && chatService && !showInputPage && (_jsx(_Fragment, { children: _jsx(ApChat, { chatServiceInstance: chatService, locale: toApolloSupportedLocale(locale), theme: theme, enableInternalThemeProvider: true,
1630
+ // Keep Apollo's tooltips, menus and history popover inside the
1631
+ // themed wrapper; portalled to <body> they'd lose the theme tokens.
1632
+ portalContainer: themeRoot ?? undefined }, locale) })), _jsx(FeedbackDialog, { open: feedbackDialogOpen, isPositive: feedbackIsPositive, onOpenChange: setFeedbackDialogOpen, onSubmit: onFeedbackSubmit, onCancel: onFeedbackCancel }), _jsx(Dialog, { open: !!citationPreviewData, onOpenChange: (open) => {
1243
1633
  if (!open)
1244
1634
  setCitationPreviewData(null);
1245
1635
  }, children: citationPreviewData && (_jsxs(DialogContent, { className: "sm:max-w-4xl", children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { children: citationPreviewData.title }) }), citationPreviewData.error ? (_jsx(Column, { w: "full", align: "center", justify: "center", style: { height: "60vh", maxHeight: "600px" }, children: t("file_preview_error") })) : (_jsx(FilePreviewer, { file: citationPreviewData.file, usePdfJs: usePdfJsViewer, pageNumber: citationPreviewData.pageNumber, iframeParams: `#page=${citationPreviewData.pageNumber}` }))] })) }), _jsx(Toaster, { id: toasterId, position: "top-right", richColors: true })] }) }) }));