@uipath/ui-widgets-conversational-agent-chat 1.1.0 → 1.1.1
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/ConversationalAgentChat.css +3359 -350
- package/dist/ConversationalAgentChat.d.ts +1 -1
- package/dist/ConversationalAgentChat.d.ts.map +1 -1
- package/dist/ConversationalAgentChat.js +200 -83
- package/dist/ConversationalAgentChat.js.map +1 -1
- package/dist/ConversationalAgentChat.stories.d.ts +2 -0
- package/dist/ConversationalAgentChat.stories.d.ts.map +1 -1
- package/dist/components/AgentSchemaForm/AgentSchemaField.d.ts.map +1 -1
- package/dist/components/AgentSchemaForm/AgentSchemaField.js +13 -5
- package/dist/components/AgentSchemaForm/AgentSchemaField.js.map +1 -1
- package/dist/components/AgentSchemaForm/inputs/ArrayField.d.ts.map +1 -1
- package/dist/components/AgentSchemaForm/inputs/ArrayField.js +1 -1
- package/dist/components/AgentSchemaForm/inputs/ArrayField.js.map +1 -1
- package/dist/components/FilePreviewer.d.ts +16 -0
- package/dist/components/FilePreviewer.d.ts.map +1 -0
- package/dist/components/FilePreviewer.js +161 -0
- package/dist/components/FilePreviewer.js.map +1 -0
- package/dist/components/InputsPage.js +1 -1
- package/dist/components/PdfJsViewer.d.ts +7 -0
- package/dist/components/PdfJsViewer.d.ts.map +1 -0
- package/dist/components/PdfJsViewer.js +220 -0
- package/dist/components/PdfJsViewer.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/ToolConfirmationRenderer.d.ts.map +1 -1
- package/dist/components/ToolConfirmationRenderer.js +2 -1
- package/dist/components/ToolConfirmationRenderer.js.map +1 -1
- package/dist/constants/attachments.d.ts +26 -0
- package/dist/constants/attachments.d.ts.map +1 -0
- package/dist/constants/attachments.js +30 -0
- package/dist/constants/attachments.js.map +1 -0
- package/dist/i18n/locales/en/index.json +11 -0
- package/dist/i18n/locales/keys/index.json +11 -0
- package/dist/types.d.ts +15 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +12 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +25 -1
- package/dist/utils.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import "./ConversationalAgentChat.css";
|
|
2
2
|
import { ConversationalAgentChatProps } from "./types";
|
|
3
|
-
export declare const ConversationalAgentChat: ({ sdk, agentId, folderId, existingConversationId, externalUserId, inputSchema: inputSchemaProp, locale, theme, readOnly, overrideLabels, firstRunExperience, disabledFeatures, jobStartOverrides, isDebugMode, evaluationSets, addToEvalButtonLabel, onEvaluationSetClicked, onUserMessageSent, surfaceName, surfaceVersion, }: ConversationalAgentChatProps) => import("react/jsx-runtime").JSX.Element;
|
|
3
|
+
export declare const ConversationalAgentChat: ({ sdk, agentId, folderId, existingConversationId, externalUserId, inputSchema: inputSchemaProp, locale, theme, readOnly, overrideLabels, firstRunExperience, disabledFeatures, citationPreview, usePdfJsViewer, jobStartOverrides, isDebugMode, evaluationSets, addToEvalButtonLabel, onEvaluationSetClicked, onUserMessageSent, surfaceName, surfaceVersion, }: ConversationalAgentChatProps) => import("react/jsx-runtime").JSX.Element;
|
|
4
4
|
//# sourceMappingURL=ConversationalAgentChat.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConversationalAgentChat.d.ts","sourceRoot":"","sources":["../src/ConversationalAgentChat.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ConversationalAgentChat.d.ts","sourceRoot":"","sources":["../src/ConversationalAgentChat.tsx"],"names":[],"mappings":"AAmEA,OAAO,+BAA+B,CAAC;AACvC,OAAO,EAEL,4BAA4B,EAK7B,MAAM,SAAS,CAAC;AAoCjB,eAAO,MAAM,uBAAuB,GAAI,iWAuBrC,4BAA4B,4CA+2C9B,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { ApChat, AutopilotChatEvent, AutopilotChatMode, AutopilotChatService, } from "@uipath/apollo-react/material/components";
|
|
2
|
+
import { ApChat, AutopilotChatEvent, AutopilotChatMode, AutopilotChatPreHookAction, AutopilotChatService, } from "@uipath/apollo-react/material/components";
|
|
3
3
|
import { FontVariantToken } from "@uipath/apollo-core";
|
|
4
4
|
import i18next from "i18next";
|
|
5
|
-
import { Alert, AlertDescription, Button } from "@uipath/apollo-wind";
|
|
5
|
+
import { Alert, AlertDescription, Button, Column, Dialog, DialogContent, DialogHeader, DialogTitle, PortalContainerProvider, } from "@uipath/apollo-wind";
|
|
6
6
|
import { ConversationalAgent, FeedbackRating, SortOrder, } from "@uipath/uipath-typescript/conversational-agent";
|
|
7
7
|
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, } from "react";
|
|
8
8
|
import { createRoot } from "react-dom/client";
|
|
@@ -12,19 +12,28 @@ import { FeedbackDialog } from "./components/FeedbackDialog";
|
|
|
12
12
|
import { Loader } from "./components/Loader";
|
|
13
13
|
import { SettingsDialog } from "./components/SettingsDialog";
|
|
14
14
|
import { createToolConfirmationRenderer, } from "./components/ToolConfirmationRenderer";
|
|
15
|
+
import { ALLOWED_ATTACHMENTS } from "./constants/attachments";
|
|
15
16
|
import "./ConversationalAgentChat.css";
|
|
16
17
|
import { TelemetryEvent, MessageWidget, TelemetryStatus, } from "./types";
|
|
17
|
-
import { convertAttachmentToFile, createFileKey, getConversationHistoryDisplayItems, mapCitationSource, mapExchangesToChatMessages, normalizeInput, sortEvaluationSets, } from "./utils";
|
|
18
|
+
import { convertAttachmentToFile, createFileKey, getConversationHistoryDisplayItems, getFirstRunExperience, mapCitationSource, mapExchangesToChatMessages, normalizeInput, sortEvaluationSets, } from "./utils";
|
|
18
19
|
import { trackTelemetry } from "./utils/telemetryUtils";
|
|
19
20
|
import { initI18n } from "./i18n";
|
|
20
21
|
import { resolveAgent as fetchAgentRelease } from "./utils/resolveAgent";
|
|
22
|
+
import FilePreviewer from "./components/FilePreviewer";
|
|
21
23
|
initI18n();
|
|
22
24
|
const TOOL_CONFIRMATION_WIDGET_ID_PREFIX = "confirmation-";
|
|
25
|
+
// Exchanges per page when lazily loading a conversation's history. Pages are
|
|
26
|
+
// fetched newest-first and prepended as the user scrolls toward the top.
|
|
27
|
+
const EXCHANGES_PAGE_SIZE = 15;
|
|
28
|
+
// Watchdog for a session that never starts: buffered sends only flush on
|
|
29
|
+
// `sessionStarted`, so if it never arrives, surface an error instead of
|
|
30
|
+
// leaving the send silently pending.
|
|
31
|
+
const SESSION_START_TIMEOUT_MS = 30000;
|
|
23
32
|
// Map widget Locale to Apollo supported locale to allow for locales not supported by Apollo
|
|
24
33
|
function toApolloSupportedLocale(widgetLocale) {
|
|
25
34
|
return widgetLocale === "keys" ? "en" : widgetLocale;
|
|
26
35
|
}
|
|
27
|
-
export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConversationId, externalUserId, inputSchema: inputSchemaProp, locale = "en", theme = "light", readOnly = false, overrideLabels, firstRunExperience, disabledFeatures, jobStartOverrides, isDebugMode = false, evaluationSets, addToEvalButtonLabel, onEvaluationSetClicked, onUserMessageSent, surfaceName, surfaceVersion, }) => {
|
|
36
|
+
export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConversationId, externalUserId, inputSchema: inputSchemaProp, locale = "en", theme = "light", readOnly = false, overrideLabels, firstRunExperience, disabledFeatures, citationPreview = true, usePdfJsViewer = true, jobStartOverrides, isDebugMode = false, evaluationSets, addToEvalButtonLabel, onEvaluationSetClicked, onUserMessageSent, surfaceName, surfaceVersion, }) => {
|
|
28
37
|
// `inputSchema` is an internal debug-only override. In normal usage the
|
|
29
38
|
// schema is resolved from the agent release, so accepting it outside debug
|
|
30
39
|
// mode would only confuse callers — reject the combination loudly.
|
|
@@ -63,6 +72,7 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
63
72
|
folderIdRef.current = folderId;
|
|
64
73
|
onEvaluationSetClickedRef.current = onEvaluationSetClicked;
|
|
65
74
|
onUserMessageSentRef.current = onUserMessageSent;
|
|
75
|
+
citationPreviewRef.current = citationPreview;
|
|
66
76
|
toolConfirmationLabelsRef.current = {
|
|
67
77
|
cancel: t("cancel"),
|
|
68
78
|
confirm: t("tool_confirmation_confirm"),
|
|
@@ -76,6 +86,7 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
76
86
|
firstRunExperience,
|
|
77
87
|
onEvaluationSetClicked,
|
|
78
88
|
onUserMessageSent,
|
|
89
|
+
citationPreview,
|
|
79
90
|
folderId,
|
|
80
91
|
t,
|
|
81
92
|
]);
|
|
@@ -95,6 +106,9 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
95
106
|
const pastConversations = useRef([]);
|
|
96
107
|
const uploadedAttachments = useRef(new Map());
|
|
97
108
|
const conversationsCursor = useRef(undefined);
|
|
109
|
+
// Cursor for the active conversation's exchange history. Reset whenever a
|
|
110
|
+
// conversation is opened/started; undefined means no older pages remain.
|
|
111
|
+
const exchangesCursor = useRef(undefined);
|
|
98
112
|
const agentIdRef = useRef(undefined);
|
|
99
113
|
const agentKeyRef = useRef(undefined);
|
|
100
114
|
const searchTextRef = useRef("");
|
|
@@ -109,6 +123,9 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
109
123
|
const [feedbackDialogOpen, setFeedbackDialogOpen] = useState(false);
|
|
110
124
|
const [feedbackIsPositive, setFeedbackIsPositive] = useState(false);
|
|
111
125
|
const pendingFeedback = useRef(null);
|
|
126
|
+
// Citation source-document preview, opened from a citation click.
|
|
127
|
+
const [citationPreviewData, setCitationPreviewData] = useState(null);
|
|
128
|
+
const citationPreviewRef = useRef(citationPreview);
|
|
112
129
|
const [hasMessages, setHasMessages] = useState(false);
|
|
113
130
|
const onEvaluationSetClickedRef = useRef(onEvaluationSetClicked);
|
|
114
131
|
const onUserMessageSentRef = useRef(onUserMessageSent);
|
|
@@ -387,23 +404,68 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
387
404
|
}
|
|
388
405
|
const conversation = await getConversation();
|
|
389
406
|
const sessionHelper = agentService.current.conversations.startSession(conversation.id, { echo: false });
|
|
407
|
+
// Mark active before registering handlers so a synchronous sessionStarted
|
|
408
|
+
// can't lose the `session.current === sessionHelper` guard race below.
|
|
409
|
+
session.current = sessionHelper;
|
|
390
410
|
// Refresh the sidebar label when the service auto-generates one (or the
|
|
391
411
|
// label is updated via the API). Bind to this session's conversation id
|
|
392
412
|
// so a stale event from an orphaned session can't mislabel the active one.
|
|
393
413
|
sessionHelper.onLabelUpdated(({ label }) => {
|
|
394
414
|
setConversationHistory(pastConversations.current.map((c) => c.id === conversation.id ? { ...c, label } : c));
|
|
395
415
|
});
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
416
|
+
// Buffer outgoing events until the server confirms the session is started,
|
|
417
|
+
// then flush — so a send never blocks on the sessionStarted round-trip.
|
|
418
|
+
// Combined with ending the session on switch (see endActiveSession), a
|
|
419
|
+
// reopened conversation starts fresh and its buffered send flushes as soon
|
|
420
|
+
// as the fresh sessionStarted arrives.
|
|
421
|
+
sessionHelper.pauseEmits();
|
|
422
|
+
const startTimeout = setTimeout(() => {
|
|
423
|
+
// Ignore a session abandoned by a switch/unmount so it can't error on the
|
|
424
|
+
// now-active conversation. If the active session never started, nothing
|
|
425
|
+
// flushes the buffer — surface an error and clear it so a retry can build
|
|
426
|
+
// a fresh session rather than reusing this permanently-paused one.
|
|
427
|
+
if (session.current !== sessionHelper)
|
|
428
|
+
return;
|
|
429
|
+
if (sessionHelper.isEmitPaused) {
|
|
430
|
+
session.current = null;
|
|
431
|
+
chatService?.setError(t("error_session_start_timeout"));
|
|
432
|
+
}
|
|
433
|
+
}, SESSION_START_TIMEOUT_MS);
|
|
434
|
+
sessionHelper.onSessionStarted(() => {
|
|
435
|
+
clearTimeout(startTimeout);
|
|
436
|
+
if (session.current !== sessionHelper)
|
|
437
|
+
return;
|
|
438
|
+
sessionHelper.resumeEmits();
|
|
439
|
+
});
|
|
440
|
+
sessionHelper.onErrorStart((error) => {
|
|
441
|
+
clearTimeout(startTimeout);
|
|
442
|
+
if (session.current !== sessionHelper)
|
|
443
|
+
return;
|
|
444
|
+
session.current = null;
|
|
445
|
+
chatService?.setError(error.message || t("error_generic"));
|
|
401
446
|
});
|
|
402
|
-
|
|
447
|
+
return sessionHelper;
|
|
448
|
+
}, [chatService, getConversation, setConversationHistory, t]);
|
|
449
|
+
// End the session on conversation switch/unmount so a reopen starts fresh and
|
|
450
|
+
// gets a new `sessionStarted` — reusing a stale session hangs the send. The
|
|
451
|
+
// in-flight exchange is left running (ending it is reserved for onStopResponse),
|
|
452
|
+
// so switching away from a busy conversation and reopening resumes its turn.
|
|
453
|
+
const endActiveSession = useCallback(() => {
|
|
454
|
+
try {
|
|
455
|
+
session.current?.sendSessionEnd();
|
|
456
|
+
}
|
|
457
|
+
catch {
|
|
458
|
+
/* session already closed */
|
|
459
|
+
}
|
|
460
|
+
activeExchange.current = null;
|
|
461
|
+
session.current = null;
|
|
462
|
+
}, []);
|
|
403
463
|
const onNewChat = useCallback(() => {
|
|
464
|
+
endActiveSession();
|
|
404
465
|
currentConversation.current = null;
|
|
405
466
|
session.current = null;
|
|
406
467
|
activeExchange.current = null;
|
|
468
|
+
exchangesCursor.current = undefined;
|
|
407
469
|
storedAgentInputs.current = {};
|
|
408
470
|
setHasMessages(false);
|
|
409
471
|
// Re-show the InputsPage with a cleared form when the agent's schema has
|
|
@@ -414,7 +476,7 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
414
476
|
setShowInputPage(true);
|
|
415
477
|
}
|
|
416
478
|
trackTelemetry(TelemetryEvent.NewChat, TelemetryStatus.Success);
|
|
417
|
-
}, [inputSchemaState]);
|
|
479
|
+
}, [endActiveSession, inputSchemaState]);
|
|
418
480
|
const buildHistoryFilterOptions = useCallback(() => {
|
|
419
481
|
// The SDK's URL builder calls value.toString() without a null check, so
|
|
420
482
|
// omit any param that is undefined/empty rather than passing it as such.
|
|
@@ -573,11 +635,21 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
573
635
|
}
|
|
574
636
|
}
|
|
575
637
|
}, [chatService, processAttachmentsInBatch, t]);
|
|
576
|
-
|
|
638
|
+
// Fetch one page of a conversation's exchanges, newest-first, advancing
|
|
639
|
+
// `exchangesCursor` so the next call returns the chunk immediately older.
|
|
640
|
+
// The returned page is sorted chronologically (ascending) so messages render
|
|
641
|
+
// top-to-bottom; callers prepend each older page above the existing ones.
|
|
642
|
+
const fetchExchanges = useCallback(async (conversationId, cursor) => {
|
|
577
643
|
const conversation = await agentService.current.conversations.getById(conversationId);
|
|
578
|
-
const
|
|
579
|
-
|
|
580
|
-
|
|
644
|
+
const result = await conversation.exchanges.getAll({
|
|
645
|
+
pageSize: EXCHANGES_PAGE_SIZE,
|
|
646
|
+
exchangeSort: SortOrder.Descending,
|
|
647
|
+
messageSort: SortOrder.Ascending,
|
|
648
|
+
...(cursor ? { cursor } : {}),
|
|
649
|
+
});
|
|
650
|
+
exchangesCursor.current = result.nextCursor;
|
|
651
|
+
const exchanges = [...result.items].sort((a, b) => new Date(a.createdTime).getTime() - new Date(b.createdTime).getTime());
|
|
652
|
+
return { exchanges, hasNextPage: result.hasNextPage };
|
|
581
653
|
}, []);
|
|
582
654
|
const onClickOpenConversation = useCallback(async (id) => {
|
|
583
655
|
if (!chatService)
|
|
@@ -588,10 +660,12 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
588
660
|
const selectedConversation = pastConversations.current.find((c) => c.id === id);
|
|
589
661
|
if (!selectedConversation)
|
|
590
662
|
return;
|
|
663
|
+
endActiveSession();
|
|
591
664
|
currentConversation.current = selectedConversation;
|
|
592
665
|
session.current = null;
|
|
593
|
-
|
|
594
|
-
const
|
|
666
|
+
exchangesCursor.current = undefined;
|
|
667
|
+
const { exchanges } = await fetchExchanges(selectedConversation.id);
|
|
668
|
+
const messages = mapExchangesToChatMessages(exchanges);
|
|
595
669
|
chatService.setConversation(messages);
|
|
596
670
|
setHasMessages(messages.length > 0);
|
|
597
671
|
trackTelemetry(TelemetryEvent.OpenConversation, TelemetryStatus.Success, {
|
|
@@ -606,7 +680,31 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
606
680
|
});
|
|
607
681
|
chatService.setError(t("error_open_conversation", { errorMessage }));
|
|
608
682
|
}
|
|
609
|
-
}, [chatService, fetchExchanges, t]);
|
|
683
|
+
}, [chatService, endActiveSession, fetchExchanges, t]);
|
|
684
|
+
// Apollo fires this when the user scrolls to the top of the message list.
|
|
685
|
+
// Prepend the next older page; signal `done` (no more pages) so Apollo stops
|
|
686
|
+
// requesting once the cursor is exhausted.
|
|
687
|
+
const onConversationLoadMore = useCallback(async () => {
|
|
688
|
+
if (!chatService)
|
|
689
|
+
return;
|
|
690
|
+
const conversationId = currentConversation.current?.id;
|
|
691
|
+
if (!conversationId || !exchangesCursor.current) {
|
|
692
|
+
chatService.prependOlderMessages([], true);
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
695
|
+
try {
|
|
696
|
+
const { exchanges, hasNextPage } = await fetchExchanges(conversationId, exchangesCursor.current);
|
|
697
|
+
chatService.prependOlderMessages(mapExchangesToChatMessages(exchanges), !hasNextPage);
|
|
698
|
+
}
|
|
699
|
+
catch (err) {
|
|
700
|
+
chatService.prependOlderMessages([], true);
|
|
701
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
702
|
+
trackTelemetry(TelemetryEvent.OpenConversation, TelemetryStatus.Error, {
|
|
703
|
+
conversationId,
|
|
704
|
+
error: errorMessage,
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
}, [chatService, fetchExchanges]);
|
|
610
708
|
const initChat = useCallback(async () => {
|
|
611
709
|
const initKey = `${agentId}-${folderId}-${existingConversationId ?? ""}-${externalUserId ?? ""}`;
|
|
612
710
|
try {
|
|
@@ -637,30 +735,10 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
637
735
|
setAgentNameState(agentName);
|
|
638
736
|
setShowInputPage(true);
|
|
639
737
|
}
|
|
640
|
-
//
|
|
641
|
-
//
|
|
642
|
-
//
|
|
643
|
-
|
|
644
|
-
const appearance = agentRelease?.appearance;
|
|
645
|
-
const agentSuggestions = (appearance?.startingPrompts ?? []).map((prompt) => ({
|
|
646
|
-
label: prompt.displayPrompt,
|
|
647
|
-
prompt: prompt.actualPrompt,
|
|
648
|
-
}));
|
|
649
|
-
const agentHasFre = !!appearance?.welcomeTitle ||
|
|
650
|
-
!!appearance?.welcomeDescription ||
|
|
651
|
-
agentSuggestions.length > 0;
|
|
652
|
-
const hostFallback = firstRunExperienceRef.current;
|
|
653
|
-
const firstRunExperienceConfig = agentHasFre
|
|
654
|
-
? {
|
|
655
|
-
title: appearance?.welcomeTitle ?? "",
|
|
656
|
-
description: appearance?.welcomeDescription ?? "",
|
|
657
|
-
suggestions: agentSuggestions,
|
|
658
|
-
}
|
|
659
|
-
: {
|
|
660
|
-
title: hostFallback?.title ?? "",
|
|
661
|
-
description: hostFallback?.description ?? "",
|
|
662
|
-
suggestions: hostFallback?.suggestions ?? [],
|
|
663
|
-
};
|
|
738
|
+
// Resolve the first-run experience: the host-provided config wins so
|
|
739
|
+
// callers can override the welcome copy and starting prompts, falling
|
|
740
|
+
// back to the agent's own appearance.
|
|
741
|
+
const firstRunExperienceConfig = getFirstRunExperience(firstRunExperienceRef.current, agentRelease?.appearance);
|
|
664
742
|
// Persists agent inputs against the active conversation via
|
|
665
743
|
// updateConversation. Server-side this applies to all subsequent
|
|
666
744
|
// messages; we don't prepend per send.
|
|
@@ -691,7 +769,7 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
691
769
|
: "no-agent";
|
|
692
770
|
const conversationId = currentConversation.current?.id ?? "no-conv";
|
|
693
771
|
const inputsResetKey = `${profileResetKey}-${conversationId}`;
|
|
694
|
-
root.render(_jsx(SettingsDialog, { profileResetKey: profileResetKey, conversationalAgent: agentService.current, onClose: () => chatServiceRef.current?.toggleSettings(false), inputSchema: inputSchemaStateRef.current, initialInputs: storedAgentInputs.current, onApplyInputs: handleApplySettingsInputs, inputsResetKey: inputsResetKey }));
|
|
772
|
+
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 }) }));
|
|
695
773
|
};
|
|
696
774
|
const chatServiceInstance = AutopilotChatService.Instantiate({
|
|
697
775
|
instanceName: `agent-${agentId}-${folderId}`,
|
|
@@ -700,7 +778,11 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
700
778
|
locale: toApolloSupportedLocale(locale),
|
|
701
779
|
theme: themeRef.current,
|
|
702
780
|
readOnly,
|
|
703
|
-
firstRunExperience: firstRunExperienceConfig
|
|
781
|
+
firstRunExperience: firstRunExperienceConfig && {
|
|
782
|
+
title: firstRunExperienceConfig.title ?? "",
|
|
783
|
+
description: firstRunExperienceConfig.description ?? "",
|
|
784
|
+
suggestions: firstRunExperienceConfig.suggestions ?? [],
|
|
785
|
+
},
|
|
704
786
|
overrideLabels: {
|
|
705
787
|
title: overrideLabelsRef.current?.title ?? agentName,
|
|
706
788
|
footerDisclaimer: overrideLabelsRef.current?.footerDisclaimer ??
|
|
@@ -709,7 +791,50 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
709
791
|
t("chat_input_placeholder"),
|
|
710
792
|
},
|
|
711
793
|
paginatedHistory: true,
|
|
794
|
+
paginatedMessages: true,
|
|
712
795
|
settingsRenderer: renderSettings,
|
|
796
|
+
preHooks: {
|
|
797
|
+
[AutopilotChatPreHookAction.CitationClick]: async (citationData) => {
|
|
798
|
+
// When preview is disabled, or the citation is not a
|
|
799
|
+
// context-grounding citation (no download_url to a source
|
|
800
|
+
// document), fall through to Apollo's default handling.
|
|
801
|
+
if (!citationPreviewRef.current)
|
|
802
|
+
return true;
|
|
803
|
+
const { citation } = citationData;
|
|
804
|
+
if (!citation?.download_url)
|
|
805
|
+
return true;
|
|
806
|
+
const pageNumber = Number(citation.page_number) || 1;
|
|
807
|
+
try {
|
|
808
|
+
const blob = await agentService.current.downloadCitationSource({
|
|
809
|
+
title: citation.title,
|
|
810
|
+
number: citation.number ?? citation.id ?? 0,
|
|
811
|
+
downloadUrl: citation.download_url,
|
|
812
|
+
pageNumber: String(pageNumber),
|
|
813
|
+
});
|
|
814
|
+
const file = new File([blob], citation.title, {
|
|
815
|
+
type: blob.type,
|
|
816
|
+
});
|
|
817
|
+
setCitationPreviewData({
|
|
818
|
+
file,
|
|
819
|
+
title: citation.title,
|
|
820
|
+
pageNumber,
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
catch (e) {
|
|
824
|
+
// Consume the click and surface the error in-dialog. Falling
|
|
825
|
+
// through to Apollo's default would re-open the auth-gated
|
|
826
|
+
// download_url in a new tab, which is exactly the 401 this
|
|
827
|
+
// preview replaces.
|
|
828
|
+
console.error("Failed to load citation document", e);
|
|
829
|
+
setCitationPreviewData({
|
|
830
|
+
title: citation.title,
|
|
831
|
+
pageNumber,
|
|
832
|
+
error: true,
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
return false;
|
|
836
|
+
},
|
|
837
|
+
},
|
|
713
838
|
// Apollo's ApChat defaults message text to fontSizeM (14px); the
|
|
714
839
|
// deprecated portal-shell chat used a larger size, so bump primary
|
|
715
840
|
// text and markdown body tokens to fontSizeL (16px) to match.
|
|
@@ -741,10 +866,14 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
741
866
|
},
|
|
742
867
|
});
|
|
743
868
|
chatServiceRef.current = chatServiceInstance;
|
|
869
|
+
if (!disabledFeaturesRef.current?.attachments) {
|
|
870
|
+
chatServiceInstance.setAllowedAttachments(ALLOWED_ATTACHMENTS);
|
|
871
|
+
}
|
|
744
872
|
if (existingConversationId) {
|
|
745
873
|
const conversation = await getConversation();
|
|
746
|
-
|
|
747
|
-
|
|
874
|
+
exchangesCursor.current = undefined;
|
|
875
|
+
const { exchanges } = await fetchExchanges(conversation.id);
|
|
876
|
+
chatServiceInstance.setConversation(mapExchangesToChatMessages(exchanges));
|
|
748
877
|
}
|
|
749
878
|
else {
|
|
750
879
|
// AutopilotChatService is a singleton, so it may still hold the
|
|
@@ -844,9 +973,6 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
844
973
|
useEffect(() => {
|
|
845
974
|
const initKey = `${agentId}-${folderId}-${existingConversationId ?? ""}-${externalUserId ?? ""}`;
|
|
846
975
|
if (initializedFor.current !== initKey) {
|
|
847
|
-
// initChat is async; its setStates run after awaits, not synchronously
|
|
848
|
-
// inside the effect body. The lint rule can't see that.
|
|
849
|
-
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
850
976
|
initChat();
|
|
851
977
|
}
|
|
852
978
|
}, [agentId, folderId, existingConversationId, externalUserId, initChat]);
|
|
@@ -864,22 +990,9 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
864
990
|
// Close the SDK session on unmount so the WebSocket doesn't linger.
|
|
865
991
|
useEffect(() => {
|
|
866
992
|
return () => {
|
|
867
|
-
|
|
868
|
-
activeExchange.current?.sendExchangeEnd();
|
|
869
|
-
}
|
|
870
|
-
catch {
|
|
871
|
-
/* exchange already ended */
|
|
872
|
-
}
|
|
873
|
-
try {
|
|
874
|
-
session.current?.sendSessionEnd();
|
|
875
|
-
}
|
|
876
|
-
catch {
|
|
877
|
-
/* session already closed */
|
|
878
|
-
}
|
|
879
|
-
activeExchange.current = null;
|
|
880
|
-
session.current = null;
|
|
993
|
+
endActiveSession();
|
|
881
994
|
};
|
|
882
|
-
}, []);
|
|
995
|
+
}, [endActiveSession]);
|
|
883
996
|
// Release React state held by the imperative tool-confirmation roots.
|
|
884
997
|
useEffect(() => {
|
|
885
998
|
return () => {
|
|
@@ -900,7 +1013,7 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
900
1013
|
if (cancelled)
|
|
901
1014
|
return;
|
|
902
1015
|
}
|
|
903
|
-
unsubscribers.push(chatService.on(AutopilotChatEvent.NewChat, onNewChat), chatService.on(AutopilotChatEvent.Request, onSendMessage), chatService.on(AutopilotChatEvent.SetAttachments, onSetAttachments), chatService.on(AutopilotChatEvent.OpenConversation, onClickOpenConversation), chatService.on(AutopilotChatEvent.DeleteConversation, onClickDeleteConversation), chatService.on(AutopilotChatEvent.HistoryLoadMore, onHistoryLoadMore), chatService.on(AutopilotChatEvent.HistorySearch, onHistorySearch), chatService.on(AutopilotChatEvent.Feedback, onFeedback), chatService.on(AutopilotChatEvent.StopResponse, onStopResponse));
|
|
1016
|
+
unsubscribers.push(chatService.on(AutopilotChatEvent.NewChat, onNewChat), chatService.on(AutopilotChatEvent.Request, onSendMessage), chatService.on(AutopilotChatEvent.SetAttachments, onSetAttachments), chatService.on(AutopilotChatEvent.OpenConversation, onClickOpenConversation), chatService.on(AutopilotChatEvent.DeleteConversation, onClickDeleteConversation), chatService.on(AutopilotChatEvent.HistoryLoadMore, onHistoryLoadMore), chatService.on(AutopilotChatEvent.ConversationLoadMore, onConversationLoadMore), chatService.on(AutopilotChatEvent.HistorySearch, onHistorySearch), chatService.on(AutopilotChatEvent.Feedback, onFeedback), chatService.on(AutopilotChatEvent.StopResponse, onStopResponse));
|
|
904
1017
|
chatService.injectMessageRenderer({
|
|
905
1018
|
name: MessageWidget.ToolConfirmation,
|
|
906
1019
|
render: (container, message) => toolConfirmationRenderer.render(container, message, toolConfirmationLabelsRef.current ?? undefined),
|
|
@@ -923,6 +1036,7 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
923
1036
|
folderId,
|
|
924
1037
|
onClickDeleteConversation,
|
|
925
1038
|
onClickOpenConversation,
|
|
1039
|
+
onConversationLoadMore,
|
|
926
1040
|
onFeedback,
|
|
927
1041
|
onHistoryLoadMore,
|
|
928
1042
|
onHistorySearch,
|
|
@@ -968,24 +1082,27 @@ export const ConversationalAgentChat = ({ sdk, agentId, folderId, existingConver
|
|
|
968
1082
|
onCustomHeaderActionClicked,
|
|
969
1083
|
t,
|
|
970
1084
|
]);
|
|
971
|
-
return (
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
}
|
|
976
|
-
else {
|
|
977
|
-
const agent = await resolveAgent();
|
|
978
|
-
if (!agent) {
|
|
979
|
-
throw new Error(t("error_missing_conversation_params"));
|
|
1085
|
+
return (_jsx("div", { className: "uipath-conversational-agent-chat", children: _jsxs(PortalContainerProvider, { children: [!error && showInputPage && inputSchemaState && (_jsx(InputsPage, { agentName: agentNameState, inputSchema: inputSchemaState, onSubmit: async (data) => {
|
|
1086
|
+
const inputs = data;
|
|
1087
|
+
if (isDebugMode && existingConversationId) {
|
|
1088
|
+
await agentService.current.conversations.updateById(existingConversationId, { agentInput: { inline: inputs } });
|
|
980
1089
|
}
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
1090
|
+
else {
|
|
1091
|
+
const agent = await resolveAgent();
|
|
1092
|
+
if (!agent) {
|
|
1093
|
+
throw new Error(t("error_missing_conversation_params"));
|
|
1094
|
+
}
|
|
1095
|
+
const conversation = await agent.conversations.create({
|
|
1096
|
+
...(jobStartOverrides ? { jobStartOverrides } : {}),
|
|
1097
|
+
agentInput: { inline: inputs },
|
|
1098
|
+
});
|
|
1099
|
+
currentConversation.current = conversation;
|
|
1100
|
+
}
|
|
1101
|
+
storedAgentInputs.current = inputs;
|
|
1102
|
+
setShowInputPage(false);
|
|
1103
|
+
} }, `${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 }, locale)), _jsx(FeedbackDialog, { open: feedbackDialogOpen, isPositive: feedbackIsPositive, onOpenChange: setFeedbackDialogOpen, onSubmit: onFeedbackSubmit, onCancel: onFeedbackCancel }), _jsx(Dialog, { open: !!citationPreviewData, onOpenChange: (open) => {
|
|
1104
|
+
if (!open)
|
|
1105
|
+
setCitationPreviewData(null);
|
|
1106
|
+
}, 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}` }))] })) })] }) }));
|
|
990
1107
|
};
|
|
991
1108
|
//# sourceMappingURL=ConversationalAgentChat.js.map
|