@uipath/ui-widgets-conversational-agent-chat 1.1.7 → 1.1.9
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/ConnectionsSection.stories.d.ts +30 -0
- package/dist/ConnectionsSection.stories.d.ts.map +1 -0
- package/dist/ConnectionsSection.stories.js +232 -0
- package/dist/ConnectionsSection.stories.js.map +1 -0
- package/dist/ConversationalAgentChat.css +53 -0
- package/dist/ConversationalAgentChat.d.ts.map +1 -1
- package/dist/ConversationalAgentChat.js +415 -25
- package/dist/ConversationalAgentChat.js.map +1 -1
- package/dist/ConversationalAgentChat.stories.d.ts +2 -2
- package/dist/components/ConnectionReadinessCard.d.ts +32 -0
- package/dist/components/ConnectionReadinessCard.d.ts.map +1 -0
- package/dist/components/ConnectionReadinessCard.js +269 -0
- package/dist/components/ConnectionReadinessCard.js.map +1 -0
- package/dist/components/ConnectionReadinessRenderer.d.ts +18 -0
- package/dist/components/ConnectionReadinessRenderer.d.ts.map +1 -0
- package/dist/components/ConnectionReadinessRenderer.js +32 -0
- package/dist/components/ConnectionReadinessRenderer.js.map +1 -0
- package/dist/components/PdfJsViewer.d.ts.map +1 -1
- package/dist/components/PdfJsViewer.js +16 -4
- package/dist/components/PdfJsViewer.js.map +1 -1
- package/dist/components/SettingsDialog/ConnectionsSection.d.ts +10 -0
- package/dist/components/SettingsDialog/ConnectionsSection.d.ts.map +1 -0
- package/dist/components/SettingsDialog/ConnectionsSection.js +289 -0
- package/dist/components/SettingsDialog/ConnectionsSection.js.map +1 -0
- package/dist/components/SettingsDialog/ProfileSection.d.ts.map +1 -1
- package/dist/components/SettingsDialog/ProfileSection.js +1 -1
- package/dist/components/SettingsDialog/ProfileSection.js.map +1 -1
- package/dist/components/SettingsDialog/SettingsDialog.d.ts +7 -1
- package/dist/components/SettingsDialog/SettingsDialog.d.ts.map +1 -1
- package/dist/components/SettingsDialog/SettingsDialog.js +3 -2
- package/dist/components/SettingsDialog/SettingsDialog.js.map +1 -1
- package/dist/constants/connectionStatus.d.ts +5 -0
- package/dist/constants/connectionStatus.d.ts.map +1 -0
- package/dist/constants/connectionStatus.js +16 -0
- package/dist/constants/connectionStatus.js.map +1 -0
- package/dist/i18n/locales/de/index.json +44 -1
- package/dist/i18n/locales/en/index.json +44 -1
- package/dist/i18n/locales/es/index.json +44 -1
- package/dist/i18n/locales/es-mx/index.json +44 -1
- package/dist/i18n/locales/fr/index.json +44 -1
- package/dist/i18n/locales/ja/index.json +44 -1
- package/dist/i18n/locales/keys/index.json +44 -1
- package/dist/i18n/locales/ko/index.json +44 -1
- package/dist/i18n/locales/pt/index.json +44 -1
- package/dist/i18n/locales/pt-br/index.json +44 -1
- package/dist/i18n/locales/ro/index.json +44 -1
- package/dist/i18n/locales/tr/index.json +44 -1
- package/dist/i18n/locales/zh-cn/index.json +44 -1
- package/dist/i18n/locales/zh-tw/index.json +44 -1
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/spanTree.d.ts +21 -0
- package/dist/utils/spanTree.d.ts.map +1 -0
- package/dist/utils/spanTree.js +118 -0
- package/dist/utils/spanTree.js.map +1 -0
- package/dist/utils.d.ts +2 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +3 -1
- package/dist/utils.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
|
@@ -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
|
-
import { convertAttachmentToFile, createFileKey, getConversationHistoryDisplayItems, getFirstRunExperience, mapCitationSource, mapExchangesToChatMessages, normalizeInput, sortEvaluationSets, } from "./utils";
|
|
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;
|
|
@@ -71,6 +76,7 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
71
76
|
// Per-instance so unmounting one widget doesn't tear down another's React roots.
|
|
72
77
|
const toolConfirmationRenderer = useMemo(() => createToolConfirmationRenderer(), []);
|
|
73
78
|
const clientSideToolRenderer = useMemo(() => createClientSideToolRenderer(), []);
|
|
79
|
+
const connectionReadinessRenderer = useMemo(() => createConnectionReadinessRenderer(), []);
|
|
74
80
|
// useLayoutEffect is ok here because the work is minimal enough that the cost is essentially zero
|
|
75
81
|
// needed because React 19 doesn't support ref writes on render
|
|
76
82
|
useLayoutEffect(() => {
|
|
@@ -99,6 +105,7 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
99
105
|
onUserMessageSent,
|
|
100
106
|
citationPreview,
|
|
101
107
|
folderId,
|
|
108
|
+
locale,
|
|
102
109
|
t,
|
|
103
110
|
]);
|
|
104
111
|
// Rebuild the SDK service when sdk or externalUserId change. Skip the first run because the
|
|
@@ -117,12 +124,24 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
117
124
|
const pastConversations = useRef([]);
|
|
118
125
|
const uploadedAttachments = useRef(new Map());
|
|
119
126
|
const conversationsCursor = useRef(undefined);
|
|
127
|
+
// Why the active conversation ended, or null while it's open. A ref so the
|
|
128
|
+
// send handler reads the current value without re-registering.
|
|
129
|
+
const endReasonRef = useRef(null);
|
|
120
130
|
// Cursor for the active conversation's exchange history. Reset whenever a
|
|
121
131
|
// conversation is opened/started; undefined means no older pages remain.
|
|
122
132
|
const exchangesCursor = useRef(undefined);
|
|
123
133
|
const agentIdRef = useRef(undefined);
|
|
124
134
|
const agentKeyRef = useRef(undefined);
|
|
135
|
+
const toolDisplayModeRef = useRef(undefined);
|
|
136
|
+
const isFlowAgentRef = useRef(false);
|
|
125
137
|
const searchTextRef = useRef("");
|
|
138
|
+
// Latest spans for the active conversation's trace, polled only in FullTrace mode
|
|
139
|
+
const traceSpansRef = useRef([]);
|
|
140
|
+
// toolCallId -> JSON of the last-sent meta, so unchanged tool calls aren't re-sent each poll.
|
|
141
|
+
const sentToolCallMetaJsonRef = useRef(new Map());
|
|
142
|
+
const tracePollIntervalRef = useRef(null);
|
|
143
|
+
const tracePollInFlightRef = useRef(null);
|
|
144
|
+
const isMountedRef = useRef(false);
|
|
126
145
|
const [chatService, setChatService] = useState();
|
|
127
146
|
const [error, setError] = useState(null);
|
|
128
147
|
const [inputSchemaState, setInputSchemaState] = useState(null);
|
|
@@ -138,11 +157,13 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
138
157
|
const [citationPreviewData, setCitationPreviewData] = useState(null);
|
|
139
158
|
const citationPreviewRef = useRef(citationPreview);
|
|
140
159
|
const [hasMessages, setHasMessages] = useState(false);
|
|
160
|
+
const [connectionReadiness, setConnectionReadiness] = useState(null);
|
|
141
161
|
const [themeRoot, setThemeRoot] = useState(null);
|
|
142
162
|
const onEvaluationSetClickedRef = useRef(onEvaluationSetClicked);
|
|
143
163
|
const onUserMessageSentRef = useRef(onUserMessageSent);
|
|
144
164
|
const chatServiceRef = useRef(null);
|
|
145
165
|
const settingsRootRef = useRef(null);
|
|
166
|
+
const autoBindTimeoutRef = useRef(null);
|
|
146
167
|
// Last-applied agent inputs for the active conversation. Pre-populates the
|
|
147
168
|
// settings inputs form when reopened; cleared on New Chat.
|
|
148
169
|
const storedAgentInputs = useRef({});
|
|
@@ -152,6 +173,96 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
152
173
|
useLayoutEffect(() => {
|
|
153
174
|
inputSchemaStateRef.current = inputSchemaState;
|
|
154
175
|
}, [inputSchemaState]);
|
|
176
|
+
// Merge the trace's "conversationToolCall" spans into their tool call messages (keyed by toolCallId)
|
|
177
|
+
const applyTraceSpans = useCallback((spans) => {
|
|
178
|
+
// Only FullTrace renders the span tree; other modes use the SDK's tool call events alone.
|
|
179
|
+
if (toolDisplayModeRef.current !== "FullTrace")
|
|
180
|
+
return;
|
|
181
|
+
const chat = chatServiceRef.current;
|
|
182
|
+
if (!chat)
|
|
183
|
+
return;
|
|
184
|
+
traceSpansRef.current = spans;
|
|
185
|
+
const conversation = chat.getConversation() ?? [];
|
|
186
|
+
for (const trace of getToolCallTraces(spans)) {
|
|
187
|
+
// The trace only enriches tool call messages the SDK or history already
|
|
188
|
+
// created, so it can't show a tool call before its deferred spinner
|
|
189
|
+
// (e.g. while a confirmation is pending).
|
|
190
|
+
const existing = conversation.find((m) => m.id === trace.toolCallId);
|
|
191
|
+
if (!existing)
|
|
192
|
+
continue;
|
|
193
|
+
const meta = mergeToolCallTraceMeta(trace, existing.meta, toolDisplayModeRef.current);
|
|
194
|
+
const metaJson = JSON.stringify(meta);
|
|
195
|
+
if (sentToolCallMetaJsonRef.current.get(trace.toolCallId) === metaJson) {
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
chat.sendResponse({
|
|
199
|
+
...existing,
|
|
200
|
+
id: trace.toolCallId,
|
|
201
|
+
content: t("performing_action_message", {
|
|
202
|
+
action: meta.toolName ?? "",
|
|
203
|
+
}),
|
|
204
|
+
created_at: existing.created_at ?? trace.startTime,
|
|
205
|
+
widget: MessageWidget.ApolloAgentsToolCall,
|
|
206
|
+
meta,
|
|
207
|
+
});
|
|
208
|
+
sentToolCallMetaJsonRef.current.set(trace.toolCallId, metaJson);
|
|
209
|
+
}
|
|
210
|
+
}, [t]);
|
|
211
|
+
const fetchAndApplyTrace = useCallback(async (traceId) => {
|
|
212
|
+
try {
|
|
213
|
+
const spans = await new Traces(sdk).getById(traceId);
|
|
214
|
+
if (!isMountedRef.current ||
|
|
215
|
+
currentConversation.current?.traceId !== traceId) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
applyTraceSpans(spans);
|
|
219
|
+
}
|
|
220
|
+
catch {
|
|
221
|
+
// Transient errors: the next poll tick (or reopening) retries.
|
|
222
|
+
}
|
|
223
|
+
}, [sdk, applyTraceSpans]);
|
|
224
|
+
// Live polling on FullTrace mode only.
|
|
225
|
+
const startTracePolling = useCallback(() => {
|
|
226
|
+
if (toolDisplayModeRef.current !== "FullTrace")
|
|
227
|
+
return;
|
|
228
|
+
const traceId = currentConversation.current?.traceId;
|
|
229
|
+
if (!traceId || tracePollIntervalRef.current)
|
|
230
|
+
return;
|
|
231
|
+
const tick = async () => {
|
|
232
|
+
if (tracePollInFlightRef.current)
|
|
233
|
+
return;
|
|
234
|
+
const poll = fetchAndApplyTrace(traceId);
|
|
235
|
+
tracePollInFlightRef.current = poll;
|
|
236
|
+
try {
|
|
237
|
+
await poll;
|
|
238
|
+
}
|
|
239
|
+
finally {
|
|
240
|
+
tracePollInFlightRef.current = null;
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
void tick();
|
|
244
|
+
tracePollIntervalRef.current = setInterval(tick, 1000);
|
|
245
|
+
}, [fetchAndApplyTrace]);
|
|
246
|
+
const stopTracePolling = useCallback((finalFetch) => {
|
|
247
|
+
if (!tracePollIntervalRef.current)
|
|
248
|
+
return;
|
|
249
|
+
clearInterval(tracePollIntervalRef.current);
|
|
250
|
+
tracePollIntervalRef.current = null;
|
|
251
|
+
const traceId = currentConversation.current?.traceId;
|
|
252
|
+
if (!finalFetch || !traceId)
|
|
253
|
+
return;
|
|
254
|
+
const pendingPoll = tracePollInFlightRef.current;
|
|
255
|
+
void (async () => {
|
|
256
|
+
await pendingPoll;
|
|
257
|
+
await fetchAndApplyTrace(traceId);
|
|
258
|
+
})();
|
|
259
|
+
}, [fetchAndApplyTrace]);
|
|
260
|
+
// On leaving a conversation, stop polling
|
|
261
|
+
const resetTraceState = useCallback(() => {
|
|
262
|
+
stopTracePolling(false);
|
|
263
|
+
traceSpansRef.current = [];
|
|
264
|
+
sentToolCallMetaJsonRef.current = new Map();
|
|
265
|
+
}, [stopTracePolling]);
|
|
155
266
|
const setupExchangeHandlers = useCallback((exchange) => {
|
|
156
267
|
if (!chatService)
|
|
157
268
|
return;
|
|
@@ -163,6 +274,10 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
163
274
|
});
|
|
164
275
|
exchange.onMessageStart((message) => {
|
|
165
276
|
if (message.startEvent.role === "assistant") {
|
|
277
|
+
if (toolDisplayModeRef.current === "FullTrace") {
|
|
278
|
+
startTracePolling();
|
|
279
|
+
message.onMessageEnd(() => stopTracePolling(true));
|
|
280
|
+
}
|
|
166
281
|
const messageId = message.messageId;
|
|
167
282
|
const messageTimestamp = message.startEvent.timestamp;
|
|
168
283
|
const exchangeId = exchange.exchangeId;
|
|
@@ -214,6 +329,17 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
214
329
|
});
|
|
215
330
|
// Track tool calls so we can defer the spinner when an interrupt arrives
|
|
216
331
|
const pendingToolCalls = new Map();
|
|
332
|
+
// In FullTrace the SDK's tool call events still render the tool call,
|
|
333
|
+
// so it appears and completes even if trace fetches fail
|
|
334
|
+
const withTraceSpan = (toolCallId, meta) => {
|
|
335
|
+
if (toolDisplayModeRef.current !== "FullTrace")
|
|
336
|
+
return meta;
|
|
337
|
+
sentToolCallMetaJsonRef.current.delete(toolCallId);
|
|
338
|
+
const span = chatService
|
|
339
|
+
.getConversation()
|
|
340
|
+
?.find((m) => m.id === toolCallId)?.meta?.span;
|
|
341
|
+
return span ? { ...meta, span } : meta;
|
|
342
|
+
};
|
|
217
343
|
const sendToolCallSpinner = (toolCallId) => {
|
|
218
344
|
const pending = pendingToolCalls.get(toolCallId);
|
|
219
345
|
if (!pending || pending.spinnerSent)
|
|
@@ -226,11 +352,12 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
226
352
|
}),
|
|
227
353
|
created_at: pending.startTimeIso,
|
|
228
354
|
widget: MessageWidget.ApolloAgentsToolCall,
|
|
229
|
-
meta: {
|
|
355
|
+
meta: withTraceSpan(toolCallId, {
|
|
230
356
|
toolName: pending.toolName,
|
|
231
357
|
input: pending.toolInput,
|
|
232
358
|
startTime: pending.startTimeIso,
|
|
233
|
-
|
|
359
|
+
displayMode: toolDisplayModeRef.current,
|
|
360
|
+
}),
|
|
234
361
|
});
|
|
235
362
|
};
|
|
236
363
|
// Caller supplies the approve/reject channel.
|
|
@@ -302,7 +429,7 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
302
429
|
}),
|
|
303
430
|
created_at: endTimeIso,
|
|
304
431
|
widget: MessageWidget.ApolloAgentsToolCall,
|
|
305
|
-
meta: {
|
|
432
|
+
meta: withTraceSpan(toolCall.toolCallId, {
|
|
306
433
|
toolName: startEvent.toolName,
|
|
307
434
|
input: toolInput,
|
|
308
435
|
startTime: startTimeIso,
|
|
@@ -310,7 +437,8 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
310
437
|
endTime: endTimeIso,
|
|
311
438
|
isError,
|
|
312
439
|
...(cancelled && { cancelled: true }),
|
|
313
|
-
|
|
440
|
+
displayMode: toolDisplayModeRef.current,
|
|
441
|
+
}),
|
|
314
442
|
});
|
|
315
443
|
pendingToolCalls.delete(toolCall.toolCallId);
|
|
316
444
|
};
|
|
@@ -396,13 +524,14 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
396
524
|
}
|
|
397
525
|
});
|
|
398
526
|
exchange.onExchangeEnd(() => {
|
|
527
|
+
stopTracePolling(true);
|
|
399
528
|
activeExchange.current = null;
|
|
400
529
|
chatService.sendOutputStreamEvent({ turnComplete: true });
|
|
401
530
|
chatService.setShowLoading(false);
|
|
402
531
|
chatService.setWaiting(false);
|
|
403
532
|
setHasMessages(true);
|
|
404
533
|
});
|
|
405
|
-
}, [chatService, t]);
|
|
534
|
+
}, [chatService, startTracePolling, stopTracePolling, t]);
|
|
406
535
|
const resolveAgent = useCallback(async () => {
|
|
407
536
|
let effectiveAgentId = agentId;
|
|
408
537
|
let effectiveFolderId = folderIdRef.current;
|
|
@@ -471,6 +600,26 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
471
600
|
setConversationHistory,
|
|
472
601
|
t,
|
|
473
602
|
]);
|
|
603
|
+
const showEndedBanner = useCallback((reason) => {
|
|
604
|
+
const message = reason === ConversationEndReason.Failed
|
|
605
|
+
? t("conversation_ended_failed")
|
|
606
|
+
: reason === ConversationEndReason.Cancelled
|
|
607
|
+
? t("conversation_ended_cancelled")
|
|
608
|
+
: t("conversation_ended_completed");
|
|
609
|
+
// Clearing also unmounts a dismissed banner; Apollo's alert keeps its hidden state otherwise.
|
|
610
|
+
chatServiceRef.current?.clearError();
|
|
611
|
+
chatServiceRef.current?.setError(message, reason === ConversationEndReason.Completed ? "warn" : "error");
|
|
612
|
+
}, [t]);
|
|
613
|
+
const applyEndedState = useCallback((reason) => {
|
|
614
|
+
endReasonRef.current = reason ?? ConversationEndReason.Completed;
|
|
615
|
+
showEndedBanner(endReasonRef.current);
|
|
616
|
+
}, [showEndedBanner]);
|
|
617
|
+
const clearEndedState = useCallback(() => {
|
|
618
|
+
if (!endReasonRef.current)
|
|
619
|
+
return;
|
|
620
|
+
endReasonRef.current = null;
|
|
621
|
+
chatServiceRef.current?.clearError();
|
|
622
|
+
}, []);
|
|
474
623
|
const getSessionHelper = useCallback(async () => {
|
|
475
624
|
if (session.current) {
|
|
476
625
|
return session.current;
|
|
@@ -486,6 +635,20 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
486
635
|
sessionHelper.onLabelUpdated(({ label }) => {
|
|
487
636
|
setConversationHistory(pastConversations.current.map((c) => c.id === conversation.id ? { ...c, label } : c));
|
|
488
637
|
});
|
|
638
|
+
sessionHelper.onConversationEnd(({ reason }) => {
|
|
639
|
+
const endReason = reason ?? ConversationEndReason.Completed;
|
|
640
|
+
const endedTime = new Date().toISOString();
|
|
641
|
+
// Mark it ended in the history list so reopening it later shows the ended state.
|
|
642
|
+
setConversationHistory(pastConversations.current.map((c) => c.id === conversation.id ? { ...c, endedTime, endReason } : c));
|
|
643
|
+
if (currentConversation.current?.id !== conversation.id)
|
|
644
|
+
return;
|
|
645
|
+
currentConversation.current = {
|
|
646
|
+
...currentConversation.current,
|
|
647
|
+
endedTime,
|
|
648
|
+
endReason,
|
|
649
|
+
};
|
|
650
|
+
applyEndedState(endReason);
|
|
651
|
+
});
|
|
489
652
|
// Buffer outgoing events until the server confirms the session is started,
|
|
490
653
|
// then flush — so a send never blocks on the sessionStarted round-trip.
|
|
491
654
|
// Combined with ending the session on switch (see endActiveSession), a
|
|
@@ -518,7 +681,13 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
518
681
|
chatService?.setError(error.message || t("error_generic"));
|
|
519
682
|
});
|
|
520
683
|
return sessionHelper;
|
|
521
|
-
}, [
|
|
684
|
+
}, [
|
|
685
|
+
applyEndedState,
|
|
686
|
+
chatService,
|
|
687
|
+
getConversation,
|
|
688
|
+
setConversationHistory,
|
|
689
|
+
t,
|
|
690
|
+
]);
|
|
522
691
|
// End the session on conversation switch/unmount so a reopen starts fresh and
|
|
523
692
|
// gets a new `sessionStarted` — reusing a stale session hangs the send. The
|
|
524
693
|
// in-flight exchange is left running (ending it is reserved for onStopResponse),
|
|
@@ -533,14 +702,61 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
533
702
|
activeExchange.current = null;
|
|
534
703
|
session.current = null;
|
|
535
704
|
}, []);
|
|
705
|
+
// Shared helper: fetch connection readiness and update state.
|
|
706
|
+
const fetchConnectionReadiness = useCallback(() => {
|
|
707
|
+
const capturedAgentId = agentIdRef.current;
|
|
708
|
+
const capturedFolderId = folderIdRef.current;
|
|
709
|
+
if (capturedAgentId == null || capturedFolderId == null)
|
|
710
|
+
return;
|
|
711
|
+
const capturedInitKey = initializedFor.current;
|
|
712
|
+
const applyReadiness = (items) => {
|
|
713
|
+
if (initializedFor.current !== capturedInitKey)
|
|
714
|
+
return;
|
|
715
|
+
if (items.length === 0) {
|
|
716
|
+
setConnectionReadiness(null);
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
const readiness = items.map((item) => {
|
|
720
|
+
const selectedConn = item.currentConnectionId
|
|
721
|
+
? item.connections?.find((c) => c.id === item.currentConnectionId)
|
|
722
|
+
: undefined;
|
|
723
|
+
return {
|
|
724
|
+
connectorKey: item.connectorKey,
|
|
725
|
+
connectorName: item.connectorName ?? item.connectorKey,
|
|
726
|
+
connectorImage: item.connectorImage,
|
|
727
|
+
isConfigurable: item.isConfigurable !== false,
|
|
728
|
+
currentConnectionId: item.currentConnectionId,
|
|
729
|
+
currentConnectionName: item.currentConnectionName,
|
|
730
|
+
currentConnectionState: selectedConn?.state ??
|
|
731
|
+
(item.currentConnectionId ? ConnectionState.Expired : undefined),
|
|
732
|
+
connectionsUrl: item.connectionsUrl,
|
|
733
|
+
};
|
|
734
|
+
});
|
|
735
|
+
const hasUnresolved = readiness.some((c) => c.isConfigurable &&
|
|
736
|
+
(!c.currentConnectionId ||
|
|
737
|
+
c.currentConnectionState !== ConnectionState.Enabled));
|
|
738
|
+
setConnectionReadiness(hasUnresolved ? readiness : null);
|
|
739
|
+
};
|
|
740
|
+
agentService.current
|
|
741
|
+
.getAvailableConnections(capturedAgentId, capturedFolderId)
|
|
742
|
+
.then(applyReadiness)
|
|
743
|
+
.catch(() => {
|
|
744
|
+
if (initializedFor.current !== capturedInitKey)
|
|
745
|
+
return;
|
|
746
|
+
setConnectionReadiness(null);
|
|
747
|
+
});
|
|
748
|
+
}, []);
|
|
536
749
|
const onNewChat = useCallback(() => {
|
|
537
750
|
endActiveSession();
|
|
751
|
+
clearEndedState();
|
|
538
752
|
currentConversation.current = null;
|
|
539
753
|
session.current = null;
|
|
540
754
|
activeExchange.current = null;
|
|
541
755
|
exchangesCursor.current = undefined;
|
|
542
756
|
storedAgentInputs.current = {};
|
|
757
|
+
resetTraceState();
|
|
543
758
|
setHasMessages(false);
|
|
759
|
+
connectionReadinessRenderer.unmountAll();
|
|
544
760
|
// Re-show the InputsPage with a cleared form when the agent's schema has
|
|
545
761
|
// required inputs. Bumping the counter forces an unmount/remount via the
|
|
546
762
|
// key on <InputsPage>, which resets internal form state.
|
|
@@ -548,8 +764,16 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
548
764
|
setInputsInstance((n) => n + 1);
|
|
549
765
|
setShowInputPage(true);
|
|
550
766
|
}
|
|
767
|
+
fetchConnectionReadiness();
|
|
551
768
|
trackTelemetry(TelemetryEvent.NewChat, TelemetryStatus.Success);
|
|
552
|
-
}, [
|
|
769
|
+
}, [
|
|
770
|
+
clearEndedState,
|
|
771
|
+
endActiveSession,
|
|
772
|
+
fetchConnectionReadiness,
|
|
773
|
+
inputSchemaState,
|
|
774
|
+
connectionReadinessRenderer,
|
|
775
|
+
resetTraceState,
|
|
776
|
+
]);
|
|
553
777
|
const buildHistoryFilterOptions = useCallback(() => {
|
|
554
778
|
// The SDK's URL builder calls value.toString() without a null check, so
|
|
555
779
|
// omit any param that is undefined/empty rather than passing it as such.
|
|
@@ -619,9 +843,21 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
619
843
|
}
|
|
620
844
|
}, [chatService, setConversationHistory, t, toasterId]);
|
|
621
845
|
const onSendMessage = useCallback(async (data) => {
|
|
846
|
+
// An ended conversation accepts no input. Apollo has already added the
|
|
847
|
+
// request bubble and loading state before this runs, and has no pre-hook
|
|
848
|
+
// for sends, so re-show the banner and undo the loading state.
|
|
849
|
+
if (endReasonRef.current) {
|
|
850
|
+
showEndedBanner(endReasonRef.current);
|
|
851
|
+
chatService?.stopResponse();
|
|
852
|
+
return;
|
|
853
|
+
}
|
|
622
854
|
try {
|
|
623
855
|
// required for debug-mode hosts that need to gate agent execution on the first user message
|
|
624
856
|
onUserMessageSentRef.current?.({ content: data.content });
|
|
857
|
+
// Clearing also unmounts a dismissed banner; Apollo's alert keeps its hidden state otherwise.
|
|
858
|
+
chatService?.clearError();
|
|
859
|
+
setHasMessages(true);
|
|
860
|
+
setConnectionReadiness(null);
|
|
625
861
|
const sessionHelper = await getSessionHelper();
|
|
626
862
|
const exchange = sessionHelper.startExchange();
|
|
627
863
|
chatService?.setWaiting(true);
|
|
@@ -657,7 +893,7 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
657
893
|
});
|
|
658
894
|
chatService?.setError(t("error_send_message", { errorMessage }));
|
|
659
895
|
}
|
|
660
|
-
}, [chatService, getSessionHelper, setupExchangeHandlers, t]);
|
|
896
|
+
}, [chatService, getSessionHelper, setupExchangeHandlers, showEndedBanner, t]);
|
|
661
897
|
const processAttachmentsInBatch = useCallback(async (attachmentBatch) => {
|
|
662
898
|
if (!chatService)
|
|
663
899
|
return;
|
|
@@ -751,13 +987,26 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
751
987
|
if (!selectedConversation)
|
|
752
988
|
return;
|
|
753
989
|
endActiveSession();
|
|
990
|
+
resetTraceState();
|
|
754
991
|
currentConversation.current = selectedConversation;
|
|
755
992
|
session.current = null;
|
|
756
993
|
exchangesCursor.current = undefined;
|
|
994
|
+
connectionReadinessRenderer.unmountAll();
|
|
757
995
|
const { exchanges } = await fetchExchanges(selectedConversation.id);
|
|
758
|
-
const messages = mapExchangesToChatMessages(exchanges);
|
|
996
|
+
const messages = mapExchangesToChatMessages(exchanges, toolDisplayModeRef.current);
|
|
759
997
|
chatService.setConversation(messages);
|
|
760
998
|
setHasMessages(messages.length > 0);
|
|
999
|
+
if (selectedConversation.endedTime) {
|
|
1000
|
+
applyEndedState(selectedConversation.endReason);
|
|
1001
|
+
}
|
|
1002
|
+
else {
|
|
1003
|
+
endReasonRef.current = null;
|
|
1004
|
+
}
|
|
1005
|
+
fetchConnectionReadiness();
|
|
1006
|
+
if (toolDisplayModeRef.current === "FullTrace" &&
|
|
1007
|
+
selectedConversation.traceId) {
|
|
1008
|
+
void fetchAndApplyTrace(selectedConversation.traceId);
|
|
1009
|
+
}
|
|
761
1010
|
trackTelemetry(TelemetryEvent.OpenConversation, TelemetryStatus.Success, {
|
|
762
1011
|
conversationId: id,
|
|
763
1012
|
});
|
|
@@ -770,7 +1019,17 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
770
1019
|
});
|
|
771
1020
|
chatService.setError(t("error_open_conversation", { errorMessage }));
|
|
772
1021
|
}
|
|
773
|
-
}, [
|
|
1022
|
+
}, [
|
|
1023
|
+
applyEndedState,
|
|
1024
|
+
chatService,
|
|
1025
|
+
connectionReadinessRenderer,
|
|
1026
|
+
endActiveSession,
|
|
1027
|
+
fetchAndApplyTrace,
|
|
1028
|
+
fetchConnectionReadiness,
|
|
1029
|
+
fetchExchanges,
|
|
1030
|
+
resetTraceState,
|
|
1031
|
+
t,
|
|
1032
|
+
]);
|
|
774
1033
|
// Apollo fires this when the user scrolls to the top of the message list.
|
|
775
1034
|
// Prepend the next older page; signal `done` (no more pages) so Apollo stops
|
|
776
1035
|
// requesting once the cursor is exhausted.
|
|
@@ -784,7 +1043,8 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
784
1043
|
}
|
|
785
1044
|
try {
|
|
786
1045
|
const { exchanges, hasNextPage } = await fetchExchanges(conversationId, exchangesCursor.current);
|
|
787
|
-
chatService.prependOlderMessages(mapExchangesToChatMessages(exchanges), !hasNextPage);
|
|
1046
|
+
chatService.prependOlderMessages(mapExchangesToChatMessages(exchanges, toolDisplayModeRef.current), !hasNextPage);
|
|
1047
|
+
applyTraceSpans(traceSpansRef.current);
|
|
788
1048
|
}
|
|
789
1049
|
catch (err) {
|
|
790
1050
|
chatService.prependOlderMessages([], true);
|
|
@@ -794,14 +1054,23 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
794
1054
|
error: errorMessage,
|
|
795
1055
|
});
|
|
796
1056
|
}
|
|
797
|
-
}, [chatService, fetchExchanges]);
|
|
1057
|
+
}, [applyTraceSpans, chatService, fetchExchanges]);
|
|
798
1058
|
const initChat = useCallback(async () => {
|
|
799
1059
|
const initKey = `${agentId}-${folderId}-${existingConversationId ?? ""}-${externalUserId ?? ""}`;
|
|
800
1060
|
try {
|
|
801
1061
|
initializedFor.current = initKey;
|
|
1062
|
+
setConnectionReadiness(null);
|
|
1063
|
+
if (autoBindTimeoutRef.current) {
|
|
1064
|
+
clearTimeout(autoBindTimeoutRef.current);
|
|
1065
|
+
autoBindTimeoutRef.current = null;
|
|
1066
|
+
}
|
|
802
1067
|
const agentRelease = await resolveAgent();
|
|
803
1068
|
agentIdRef.current = agentRelease?.id;
|
|
804
1069
|
agentKeyRef.current = agentRelease?.releaseKey;
|
|
1070
|
+
toolDisplayModeRef.current =
|
|
1071
|
+
agentRelease?.appearance
|
|
1072
|
+
?.displayMode ?? "InputsAndOutputs";
|
|
1073
|
+
isFlowAgentRef.current = isFlowAgent(agentRelease);
|
|
805
1074
|
const agentName = agentRelease?.name ?? "";
|
|
806
1075
|
// In debug mode the agent (and its derived schema) may not be resolvable,
|
|
807
1076
|
// so an explicit `inputSchema` override takes precedence. Normal usage
|
|
@@ -829,6 +1098,17 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
829
1098
|
// callers can override the welcome copy and starting prompts, falling
|
|
830
1099
|
// back to the agent's own appearance.
|
|
831
1100
|
const firstRunExperienceConfig = getFirstRunExperience(firstRunExperienceRef.current, agentRelease?.appearance);
|
|
1101
|
+
// Fetch connection readiness (fire-and-forget; card is optional)
|
|
1102
|
+
if (agentRelease) {
|
|
1103
|
+
fetchConnectionReadiness();
|
|
1104
|
+
// Re-fetch after a delay to pick up server-side auto-bind results
|
|
1105
|
+
autoBindTimeoutRef.current = setTimeout(() => {
|
|
1106
|
+
autoBindTimeoutRef.current = null;
|
|
1107
|
+
if (initializedFor.current !== initKey)
|
|
1108
|
+
return;
|
|
1109
|
+
fetchConnectionReadiness();
|
|
1110
|
+
}, 1500);
|
|
1111
|
+
}
|
|
832
1112
|
// Persists agent inputs against the active conversation via
|
|
833
1113
|
// updateConversation. Server-side this applies to all subsequent
|
|
834
1114
|
// messages; we don't prepend per send.
|
|
@@ -867,7 +1147,10 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
867
1147
|
: "no-agent";
|
|
868
1148
|
const conversationId = currentConversation.current?.id ?? "no-conv";
|
|
869
1149
|
const inputsResetKey = `${profileResetKey}-${conversationId}`;
|
|
870
|
-
root.render(_jsx(PortalContainerProvider, { children: _jsx(SettingsDialog, { profileResetKey: profileResetKey, conversationalAgent: agentService.current, onClose: () =>
|
|
1150
|
+
root.render(_jsx(PortalContainerProvider, { children: _jsx(SettingsDialog, { profileResetKey: profileResetKey, conversationalAgent: agentService.current, onClose: () => {
|
|
1151
|
+
chatServiceRef.current?.toggleSettings(false);
|
|
1152
|
+
fetchConnectionReadiness();
|
|
1153
|
+
}, inputSchema: inputSchemaStateRef.current, initialInputs: storedAgentInputs.current, onApplyInputs: handleApplySettingsInputs, inputsResetKey: inputsResetKey, agentId: agentIdRef.current, folderId: folderIdRef.current, onConnectionsChanged: fetchConnectionReadiness }) }));
|
|
871
1154
|
};
|
|
872
1155
|
const chatServiceInstance = AutopilotChatService.Instantiate({
|
|
873
1156
|
instanceName: `agent-${agentId}-${folderId}`,
|
|
@@ -977,6 +1260,7 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
977
1260
|
renameChat: false,
|
|
978
1261
|
...(!agentId ? { newChat: true, history: true } : {}),
|
|
979
1262
|
...disabledFeaturesRef.current,
|
|
1263
|
+
...(isFlowAgentRef.current ? { stopResponse: true } : {}),
|
|
980
1264
|
},
|
|
981
1265
|
},
|
|
982
1266
|
});
|
|
@@ -984,14 +1268,26 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
984
1268
|
// Singleton keeps the previous conversation's unsent draft and error banner; drop both before the awaits.
|
|
985
1269
|
chatServiceInstance.setPrompt("");
|
|
986
1270
|
chatServiceInstance.clearError();
|
|
1271
|
+
endReasonRef.current = null;
|
|
987
1272
|
if (!disabledFeaturesRef.current?.attachments) {
|
|
988
1273
|
chatServiceInstance.setAllowedAttachments(ALLOWED_ATTACHMENTS);
|
|
989
1274
|
}
|
|
1275
|
+
// Clean up any existing readiness roots before replacing the conversation
|
|
1276
|
+
connectionReadinessRenderer.unmountAll();
|
|
990
1277
|
if (existingConversationId) {
|
|
991
1278
|
const conversation = await getConversation();
|
|
992
1279
|
exchangesCursor.current = undefined;
|
|
993
1280
|
const { exchanges } = await fetchExchanges(conversation.id);
|
|
994
|
-
|
|
1281
|
+
const messages = mapExchangesToChatMessages(exchanges);
|
|
1282
|
+
chatServiceInstance.setConversation(mapExchangesToChatMessages(exchanges, toolDisplayModeRef.current));
|
|
1283
|
+
if (conversation.endedTime) {
|
|
1284
|
+
applyEndedState(conversation.endReason);
|
|
1285
|
+
}
|
|
1286
|
+
if (toolDisplayModeRef.current === "FullTrace" &&
|
|
1287
|
+
conversation.traceId) {
|
|
1288
|
+
void fetchAndApplyTrace(conversation.traceId);
|
|
1289
|
+
}
|
|
1290
|
+
setHasMessages(messages.length > 0);
|
|
995
1291
|
}
|
|
996
1292
|
else {
|
|
997
1293
|
// AutopilotChatService is a singleton, so it may still hold the
|
|
@@ -1007,6 +1303,8 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
1007
1303
|
}
|
|
1008
1304
|
}, [
|
|
1009
1305
|
agentId,
|
|
1306
|
+
applyEndedState,
|
|
1307
|
+
fetchAndApplyTrace,
|
|
1010
1308
|
folderId,
|
|
1011
1309
|
existingConversationId,
|
|
1012
1310
|
externalUserId,
|
|
@@ -1016,6 +1314,8 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
1016
1314
|
readOnly,
|
|
1017
1315
|
resolveAgent,
|
|
1018
1316
|
getConversation,
|
|
1317
|
+
fetchConnectionReadiness,
|
|
1318
|
+
connectionReadinessRenderer,
|
|
1019
1319
|
fetchExchanges,
|
|
1020
1320
|
t,
|
|
1021
1321
|
toasterId,
|
|
@@ -1029,14 +1329,20 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
1029
1329
|
const onStopResponse = useCallback(() => {
|
|
1030
1330
|
if (!chatService)
|
|
1031
1331
|
return;
|
|
1332
|
+
stopTracePolling(true);
|
|
1032
1333
|
if (activeExchange.current) {
|
|
1033
|
-
|
|
1334
|
+
// Flows own their exchange; a client exchange end strands them. Switching
|
|
1335
|
+
// conversations still fires StopResponse.
|
|
1336
|
+
if (!isFlowAgentRef.current) {
|
|
1337
|
+
activeExchange.current.sendExchangeEnd();
|
|
1338
|
+
chatService.setError(t("response_stopped_message"), "warn");
|
|
1339
|
+
}
|
|
1034
1340
|
activeExchange.current = null;
|
|
1035
1341
|
}
|
|
1036
1342
|
chatService.sendOutputStreamEvent({ turnComplete: true });
|
|
1037
1343
|
chatService.setShowLoading(false);
|
|
1038
1344
|
chatService.setWaiting(false);
|
|
1039
|
-
}, [chatService]);
|
|
1345
|
+
}, [chatService, stopTracePolling, t]);
|
|
1040
1346
|
const onCustomHeaderActionClicked = useCallback((action) => {
|
|
1041
1347
|
if (action.id.startsWith("eval-")) {
|
|
1042
1348
|
const evaluationSetId = action.id.replace("eval-", "");
|
|
@@ -1101,6 +1407,10 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
1101
1407
|
settingsRootRef.current.unmount();
|
|
1102
1408
|
settingsRootRef.current = null;
|
|
1103
1409
|
}
|
|
1410
|
+
if (autoBindTimeoutRef.current) {
|
|
1411
|
+
clearTimeout(autoBindTimeoutRef.current);
|
|
1412
|
+
autoBindTimeoutRef.current = null;
|
|
1413
|
+
}
|
|
1104
1414
|
};
|
|
1105
1415
|
}, []);
|
|
1106
1416
|
useEffect(() => {
|
|
@@ -1109,10 +1419,20 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
1109
1419
|
useEffect(() => {
|
|
1110
1420
|
chatService?.setChatMode(mode);
|
|
1111
1421
|
}, [chatService, mode]);
|
|
1112
|
-
|
|
1422
|
+
useEffect(() => {
|
|
1423
|
+
isMountedRef.current = true;
|
|
1424
|
+
return () => {
|
|
1425
|
+
isMountedRef.current = false;
|
|
1426
|
+
};
|
|
1427
|
+
}, []);
|
|
1428
|
+
// Close the SDK session and stop trace polling on unmount so neither lingers
|
|
1113
1429
|
useEffect(() => {
|
|
1114
1430
|
return () => {
|
|
1115
1431
|
endActiveSession();
|
|
1432
|
+
if (tracePollIntervalRef.current) {
|
|
1433
|
+
clearInterval(tracePollIntervalRef.current);
|
|
1434
|
+
tracePollIntervalRef.current = null;
|
|
1435
|
+
}
|
|
1116
1436
|
};
|
|
1117
1437
|
}, [endActiveSession]);
|
|
1118
1438
|
// Release React state held by the imperative tool-confirmation and client-side tool roots.
|
|
@@ -1120,8 +1440,13 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
1120
1440
|
return () => {
|
|
1121
1441
|
toolConfirmationRenderer.unmountAll();
|
|
1122
1442
|
clientSideToolRenderer.unmountAll();
|
|
1443
|
+
connectionReadinessRenderer.unmountAll();
|
|
1123
1444
|
};
|
|
1124
|
-
}, [
|
|
1445
|
+
}, [
|
|
1446
|
+
toolConfirmationRenderer,
|
|
1447
|
+
clientSideToolRenderer,
|
|
1448
|
+
connectionReadinessRenderer,
|
|
1449
|
+
]);
|
|
1125
1450
|
// Register event handlers after chatService is available
|
|
1126
1451
|
useEffect(() => {
|
|
1127
1452
|
if (!chatService)
|
|
@@ -1145,6 +1470,15 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
1145
1470
|
name: MessageWidget.ClientSideToolInput,
|
|
1146
1471
|
render: (container, message) => clientSideToolRenderer.render(container, message),
|
|
1147
1472
|
});
|
|
1473
|
+
chatService.injectMessageRenderer({
|
|
1474
|
+
name: CONNECTION_READINESS_CARD,
|
|
1475
|
+
render: (container, message) => connectionReadinessRenderer.render(container, message, {
|
|
1476
|
+
conversationalAgent: agentService.current,
|
|
1477
|
+
onAllConnected: () => setConnectionReadiness(null),
|
|
1478
|
+
onOpenSettings: () => chatServiceRef.current?.toggleSettings(true),
|
|
1479
|
+
onConnectionsChanged: fetchConnectionReadiness,
|
|
1480
|
+
}),
|
|
1481
|
+
});
|
|
1148
1482
|
}
|
|
1149
1483
|
catch (err) {
|
|
1150
1484
|
const message = err instanceof Error ? err.message : t("error_load_history");
|
|
@@ -1175,6 +1509,62 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
1175
1509
|
t,
|
|
1176
1510
|
toolConfirmationRenderer,
|
|
1177
1511
|
clientSideToolRenderer,
|
|
1512
|
+
connectionReadinessRenderer,
|
|
1513
|
+
fetchConnectionReadiness,
|
|
1514
|
+
]);
|
|
1515
|
+
// Inject/update/remove the connection readiness card as a message in the
|
|
1516
|
+
// conversation — matching CAS positioning inside the scroll area.
|
|
1517
|
+
useEffect(() => {
|
|
1518
|
+
if (!chatService)
|
|
1519
|
+
return;
|
|
1520
|
+
const conversation = chatService.getConversation() ?? [];
|
|
1521
|
+
const existingIndex = conversation.findIndex(
|
|
1522
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1523
|
+
(m) => m.id === CONNECTION_READINESS_CARD_ID);
|
|
1524
|
+
if (connectionReadiness) {
|
|
1525
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1526
|
+
const cardMessage = {
|
|
1527
|
+
id: CONNECTION_READINESS_CARD_ID,
|
|
1528
|
+
content: " ",
|
|
1529
|
+
created_at: new Date().toISOString(),
|
|
1530
|
+
role: "assistant",
|
|
1531
|
+
widget: CONNECTION_READINESS_CARD,
|
|
1532
|
+
done: true,
|
|
1533
|
+
disableActions: true,
|
|
1534
|
+
meta: {
|
|
1535
|
+
connectors: connectionReadiness,
|
|
1536
|
+
agentId: agentIdRef.current,
|
|
1537
|
+
folderId: folderIdRef.current,
|
|
1538
|
+
defaultCollapsed: hasMessages,
|
|
1539
|
+
},
|
|
1540
|
+
};
|
|
1541
|
+
if (existingIndex >= 0) {
|
|
1542
|
+
const updated = [...conversation];
|
|
1543
|
+
updated[existingIndex] = cardMessage;
|
|
1544
|
+
chatService.setConversation(updated);
|
|
1545
|
+
}
|
|
1546
|
+
else if (hasMessages) {
|
|
1547
|
+
// Append so the card appears near the bottom where the user is
|
|
1548
|
+
chatService.setConversation([...conversation, cardMessage]);
|
|
1549
|
+
}
|
|
1550
|
+
else {
|
|
1551
|
+
// Fresh conversation — card goes first, before welcome message
|
|
1552
|
+
chatService.setConversation([cardMessage, ...conversation]);
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
else if (existingIndex >= 0) {
|
|
1556
|
+
// Defer unmount — the card's onAllConnected effect may still be
|
|
1557
|
+
// executing inside this root's React tree when this runs.
|
|
1558
|
+
queueMicrotask(() => connectionReadinessRenderer.unmountAll());
|
|
1559
|
+
chatService.setConversation(
|
|
1560
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1561
|
+
conversation.filter((m) => m.id !== CONNECTION_READINESS_CARD_ID));
|
|
1562
|
+
}
|
|
1563
|
+
}, [
|
|
1564
|
+
chatService,
|
|
1565
|
+
connectionReadiness,
|
|
1566
|
+
hasMessages,
|
|
1567
|
+
connectionReadinessRenderer,
|
|
1178
1568
|
]);
|
|
1179
1569
|
useEffect(() => {
|
|
1180
1570
|
if (!chatService ||
|
|
@@ -1229,10 +1619,10 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
1229
1619
|
}
|
|
1230
1620
|
storedAgentInputs.current = inputs;
|
|
1231
1621
|
setShowInputPage(false);
|
|
1232
|
-
} }, `${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,
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1622
|
+
} }, `${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,
|
|
1623
|
+
// Keep Apollo's tooltips, menus and history popover inside the
|
|
1624
|
+
// themed wrapper; portalled to <body> they'd lose the theme tokens.
|
|
1625
|
+
portalContainer: themeRoot ?? undefined }, locale) })), _jsx(FeedbackDialog, { open: feedbackDialogOpen, isPositive: feedbackIsPositive, onOpenChange: setFeedbackDialogOpen, onSubmit: onFeedbackSubmit, onCancel: onFeedbackCancel }), _jsx(Dialog, { open: !!citationPreviewData, onOpenChange: (open) => {
|
|
1236
1626
|
if (!open)
|
|
1237
1627
|
setCitationPreviewData(null);
|
|
1238
1628
|
}, 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 })] }) }) }));
|