impact-chatbot 2.3.104 → 2.4.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.
- package/dist/components/message-template/components/message-content/SurfaceFrameContent.d.ts +37 -0
- package/dist/components/message-template/components/message-content/surfaceWidgets.d.ts +22 -0
- package/dist/index.cjs.js +316 -17
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +317 -18
- package/dist/index.esm.js.map +1 -1
- package/dist/services/chatbot-services.d.ts +3 -0
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -23,7 +23,7 @@ import { setSelectedFilters, setFilterConfiguration, getFilterUserConfiguration
|
|
|
23
23
|
import { setThinkingContext, setChatbotContext, setStepFormStreamData, setMinimizedStreamData, setPersistedFormValues, setCurrentAgentChatId, clearPersistedFormValues, setHierarchyKeyValue, setChatbotFilterOptions, setSavedFilterSets } from 'core/actions/smartBotActions';
|
|
24
24
|
import RefreshIcon from '@mui/icons-material/Refresh';
|
|
25
25
|
import styled from 'styled-components';
|
|
26
|
-
import { CircularProgress, Typography, Grid, IconButton, Accordion, AccordionSummary, AccordionDetails } from '@mui/material';
|
|
26
|
+
import { CircularProgress, Typography, Grid, Box, IconButton, Accordion, AccordionSummary, AccordionDetails } from '@mui/material';
|
|
27
27
|
import { fetchBaseUrl, pxToRem as pxToRem$1, replaceSpecialCharacter as replaceSpecialCharacter$1, fetchLegacyAgentScreen } from 'core/Utils/functions/utils';
|
|
28
28
|
import { Button, Modal, Slider, Select, DatePicker, DateRangePicker, Checkbox, RadioButtonGroup, Input, Tabs, Loader, Prompt, Tooltip, ChatBotComponent } from 'impact-ui-v3';
|
|
29
29
|
import isArray$2 from 'lodash/isArray';
|
|
@@ -294,6 +294,21 @@ const getTableRecords = async (payload, baseUrl, tableName) => {
|
|
|
294
294
|
return null;
|
|
295
295
|
}
|
|
296
296
|
};
|
|
297
|
+
/** A read for a generated surface (frame protocol iui:query): the agent runs one read tool as the signed-in
|
|
298
|
+
* user and answers {rows, total}. */
|
|
299
|
+
const postUiQuery = async (payload, baseUrl) => {
|
|
300
|
+
try {
|
|
301
|
+
return axiosInstance({
|
|
302
|
+
url: `${baseUrl}/chatbot/agent/ui-query`,
|
|
303
|
+
method: 'POST',
|
|
304
|
+
data: payload,
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
catch (error) {
|
|
308
|
+
console.error('postUiQuery error:', error);
|
|
309
|
+
return null;
|
|
310
|
+
}
|
|
311
|
+
};
|
|
297
312
|
const getTableRecordsByUrl = async (payload, url) => {
|
|
298
313
|
try {
|
|
299
314
|
return axiosInstance({
|
|
@@ -888,6 +903,18 @@ const parseResponse = (data, type, agentId = "", currentMode = "", disableTimeAn
|
|
|
888
903
|
thinkingResponse: utilityObject?.thinkingResponse,
|
|
889
904
|
enableLikes: true
|
|
890
905
|
};
|
|
906
|
+
case "surface_frame":
|
|
907
|
+
// A generated UI surface drawn by the UI service's renderer page (Impact UI 5), which SurfaceFrameContent embeds
|
|
908
|
+
return {
|
|
909
|
+
...data,
|
|
910
|
+
agentId: agentId,
|
|
911
|
+
timeStamp: timeString,
|
|
912
|
+
userType: "bot",
|
|
913
|
+
userName: userName,
|
|
914
|
+
headerTitle: data?.data?.surface?.title || "",
|
|
915
|
+
bodyType: "surface_frame",
|
|
916
|
+
bodyText: data?.data,
|
|
917
|
+
};
|
|
891
918
|
default:
|
|
892
919
|
return null;
|
|
893
920
|
}
|
|
@@ -2419,6 +2446,10 @@ const useAgentFlow = (dateFormat, chatDataRef, currentMode, setShowChatPlacehold
|
|
|
2419
2446
|
answer_mode: data?.answerMode || "auto",
|
|
2420
2447
|
...(!isEmpty(utilityObjectData?.additionalArgs) ? utilityObjectData.additionalArgs : {}),
|
|
2421
2448
|
};
|
|
2449
|
+
if (data?.uiContext && typeof data.uiContext === "object") {
|
|
2450
|
+
// a follow-up asked from a generated surface: which surface, and its input values
|
|
2451
|
+
payload.ui_context = data.uiContext;
|
|
2452
|
+
}
|
|
2422
2453
|
// Handle @ filter mentions - user_explicit_input contains filter values
|
|
2423
2454
|
if (!isEmpty(data?.userExplicitInput)) {
|
|
2424
2455
|
payload.user_explicit_input = data?.userExplicitInput;
|
|
@@ -5566,6 +5597,73 @@ const QuestionsContent = ({ bodyText, props }) => {
|
|
|
5566
5597
|
}) }));
|
|
5567
5598
|
};
|
|
5568
5599
|
|
|
5600
|
+
/**
|
|
5601
|
+
* One widget per generated surface in a stream: the agent may send a surface more than once (a placeholder
|
|
5602
|
+
* while it is composed, `status: "pending"`, version 0; then the surface, version 1; or its withdrawal), and
|
|
5603
|
+
* frame protocol 1 replaces a surface by its id (agent-ui-service-ssr docs/chat-frame-widget.md, rule 4).
|
|
5604
|
+
* No imports: the stream reader (AxiosEventSource) uses it too. Ported from core's smartBot
|
|
5605
|
+
* (insideinsight/core feat/iui-surface, e386f8f0).
|
|
5606
|
+
*/
|
|
5607
|
+
/** A surface's version; one when it gives none. */
|
|
5608
|
+
const surfaceVersion = (surface) => (Number.isFinite(surface?.version) ? surface.version : 1);
|
|
5609
|
+
const surfaceIdOf = (widget) => (widget?.type === "surface_frame" ? widget?.data?.surface?.id : undefined);
|
|
5610
|
+
/** A stream's widgets with these added: a surface_frame widget whose surface the list already holds replaces
|
|
5611
|
+
* it in place (a lower version is dropped); any other widget is added at the end. */
|
|
5612
|
+
const mergeSurfaceWidgets = (previous, incoming) => {
|
|
5613
|
+
const merged = Array.isArray(previous) ? previous.slice() : previous ? [previous] : [];
|
|
5614
|
+
for (const widget of Array.isArray(incoming) ? incoming : [incoming]) {
|
|
5615
|
+
const id = surfaceIdOf(widget);
|
|
5616
|
+
const at = id === undefined ? -1 : merged.findIndex((w) => surfaceIdOf(w) === id);
|
|
5617
|
+
if (at < 0)
|
|
5618
|
+
merged.push(widget);
|
|
5619
|
+
else if (surfaceVersion(widget.data.surface) >= surfaceVersion(merged[at].data.surface))
|
|
5620
|
+
merged[at] = widget;
|
|
5621
|
+
}
|
|
5622
|
+
return merged;
|
|
5623
|
+
};
|
|
5624
|
+
/*
|
|
5625
|
+
* Across the chat's messages (one page per surface): a surface revised in a later turn is shown, newest
|
|
5626
|
+
* version, where that turn put it; each earlier widget of it collapses to a line. Every SurfaceFrameContent
|
|
5627
|
+
* says which version it shows; a widget whose surface another widget shows in a higher version collapses.
|
|
5628
|
+
* Placeholders and withdrawn surfaces take no part. Equal versions (the same surface drawn in two places)
|
|
5629
|
+
* both show.
|
|
5630
|
+
*/
|
|
5631
|
+
const shownVersions = new Map(); // surface id -> Map(widget token -> version)
|
|
5632
|
+
const watchers = new Set();
|
|
5633
|
+
let lastToken = 0;
|
|
5634
|
+
/** A token for one widget. */
|
|
5635
|
+
const surfaceToken = () => {
|
|
5636
|
+
lastToken += 1;
|
|
5637
|
+
return lastToken;
|
|
5638
|
+
};
|
|
5639
|
+
const notify = () => watchers.forEach((watch) => watch());
|
|
5640
|
+
/** This widget shows `version` of surface `id`. */
|
|
5641
|
+
const showSurface = (id, token, version) => {
|
|
5642
|
+
if (!shownVersions.has(id))
|
|
5643
|
+
shownVersions.set(id, new Map());
|
|
5644
|
+
shownVersions.get(id).set(token, version);
|
|
5645
|
+
notify();
|
|
5646
|
+
};
|
|
5647
|
+
/** This widget no longer shows surface `id`. */
|
|
5648
|
+
const hideSurface = (id, token) => {
|
|
5649
|
+
const versions = shownVersions.get(id);
|
|
5650
|
+
if (!versions)
|
|
5651
|
+
return;
|
|
5652
|
+
versions.delete(token);
|
|
5653
|
+
if (versions.size === 0)
|
|
5654
|
+
shownVersions.delete(id);
|
|
5655
|
+
notify();
|
|
5656
|
+
};
|
|
5657
|
+
/** Whether another widget shows surface `id` in a version higher than `version`. */
|
|
5658
|
+
const newerShown = (id, version) => [...(shownVersions.get(id)?.values() ?? [])].some((v) => v > version);
|
|
5659
|
+
/** Calls `watch` whenever a widget starts or stops showing a surface; returns the unsubscribe. */
|
|
5660
|
+
const watchSurfaces = (watch) => {
|
|
5661
|
+
watchers.add(watch);
|
|
5662
|
+
return () => {
|
|
5663
|
+
watchers.delete(watch);
|
|
5664
|
+
};
|
|
5665
|
+
};
|
|
5666
|
+
|
|
5569
5667
|
// Utility: check whether a string is a likely complete JSON value
|
|
5570
5668
|
const isLikelyCompleteJson = (message) => {
|
|
5571
5669
|
try {
|
|
@@ -5773,10 +5871,8 @@ const sseevent = (message, messageToStoreRef) => {
|
|
|
5773
5871
|
let previousWidgetData = isArray$1(messageToStoreRef.current.appendedData)
|
|
5774
5872
|
? messageToStoreRef.current.appendedData
|
|
5775
5873
|
: [messageToStoreRef.current.appendedData];
|
|
5776
|
-
|
|
5777
|
-
|
|
5778
|
-
...finalWidgetData,
|
|
5779
|
-
];
|
|
5874
|
+
// a surface sent again (placeholder, then the surface) replaces its widget in place
|
|
5875
|
+
messageToStoreRef.current.appendedData = mergeSurfaceWidgets(previousWidgetData, finalWidgetData);
|
|
5780
5876
|
messageToStoreRef.current.sessionId = parsedData.session_id;
|
|
5781
5877
|
messageToStoreRef.current.uniqueChatId = parsedData?.chat_id
|
|
5782
5878
|
? parsedData.chat_id
|
|
@@ -5816,10 +5912,8 @@ const sseevent = (message, messageToStoreRef) => {
|
|
|
5816
5912
|
let previousWidgetData = isArray$1(messageToStoreRef.current.appendedData)
|
|
5817
5913
|
? messageToStoreRef.current.appendedData
|
|
5818
5914
|
: [messageToStoreRef.current.appendedData];
|
|
5819
|
-
|
|
5820
|
-
|
|
5821
|
-
...finalWidgetData,
|
|
5822
|
-
];
|
|
5915
|
+
// a surface sent again (placeholder, then the surface) replaces its widget in place
|
|
5916
|
+
messageToStoreRef.current.appendedData = mergeSurfaceWidgets(previousWidgetData, finalWidgetData);
|
|
5823
5917
|
messageToStoreRef.current.additionalArgs = parsedData?.additional_args
|
|
5824
5918
|
? parsedData.additional_args
|
|
5825
5919
|
: {};
|
|
@@ -8010,6 +8104,183 @@ const ImageContent = ({ bodyText }) => {
|
|
|
8010
8104
|
} })), caption && (jsx("div", { children: jsx(TextRenderer, { text: caption }) }))] }));
|
|
8011
8105
|
};
|
|
8012
8106
|
|
|
8107
|
+
const SUBMIT = { buttons: [{ label: "Submit", variant: "primary" }] };
|
|
8108
|
+
/** A follow-up's limits: longer ones are ignored. */
|
|
8109
|
+
const PROMPT_TEXT_MAX = 1000;
|
|
8110
|
+
const PROMPT_CONTEXT_MAX = 16000;
|
|
8111
|
+
/** The window event the chat listens to for a follow-up asked from a surface. */
|
|
8112
|
+
const PROMPT_EVENT = "iris:prompt";
|
|
8113
|
+
/** The source a surface names for this temp table, if it names it: the only tables its page may ask pages
|
|
8114
|
+
* of, and the endpoint address the agent gave (the page's own copy of the source is not trusted for it). */
|
|
8115
|
+
const sourceOf = (surface, table) => Object.values(surface?.data || {}).map((entry) => entry?.source).find((source) => typeof source?.table === "string" && source.table === table);
|
|
8116
|
+
/** Whether the surface binds this tool: the only tools its page may ask to read again. */
|
|
8117
|
+
const bindsTool = (surface, tool) => typeof tool === "string" && tool !== "rows" && Object.values(surface?.data || {}).some((entry) => entry?.tool === tool);
|
|
8118
|
+
const baseUrl = () => sessionStorage.getItem("stepForm_baseUrl") || "";
|
|
8119
|
+
/** One page of a source, from the agent's paging endpoint (its pages hold at most 10 rows): at the address
|
|
8120
|
+
* the agent gave, as TableContent does with temp_table_url, else under the stream's base URL. `search`: a
|
|
8121
|
+
* filter Control over the kept rows (catalog 0.3), each `{field, value}` an exact match the endpoint applies. */
|
|
8122
|
+
const pageOf = async ({ source, page, pageSize, sort, search }) => {
|
|
8123
|
+
const payload = {
|
|
8124
|
+
limit: { page, page_size: pageSize },
|
|
8125
|
+
search: (Array.isArray(search) ? search : [])
|
|
8126
|
+
.filter((s) => s && typeof s.field === "string" && s.value !== undefined && s.value !== null)
|
|
8127
|
+
.slice(0, 5)
|
|
8128
|
+
.map((s) => ({ column: s.field, pattern: String(s.value), search_type: "equals" })),
|
|
8129
|
+
sort: (Array.isArray(sort) ? sort : []).map((s) => ({ column: s.field, order: s.order === "desc" ? "desc" : "asc" })),
|
|
8130
|
+
};
|
|
8131
|
+
const response = source.url
|
|
8132
|
+
? await getTableRecordsByUrl(payload, source.url)
|
|
8133
|
+
: await getTableRecords(payload, baseUrl(), source.table);
|
|
8134
|
+
const rows = response?.data?.data;
|
|
8135
|
+
const total = response?.data?.total_count;
|
|
8136
|
+
if (!Array.isArray(rows) || !Number.isFinite(total))
|
|
8137
|
+
throw new Error("no rows");
|
|
8138
|
+
return { rows, total };
|
|
8139
|
+
};
|
|
8140
|
+
/** A read tool the surface binds, run again by the agent with these arguments. */
|
|
8141
|
+
const readOf = async ({ surface, tool, args }) => {
|
|
8142
|
+
const response = await postUiQuery({ surface, tool, args: args && typeof args === "object" ? args : {} }, baseUrl());
|
|
8143
|
+
const rows = response?.data?.rows;
|
|
8144
|
+
const total = response?.data?.total;
|
|
8145
|
+
if (!Array.isArray(rows) || !Number.isFinite(total))
|
|
8146
|
+
throw new Error(response?.data?.error || "no rows");
|
|
8147
|
+
return { rows, total };
|
|
8148
|
+
};
|
|
8149
|
+
/** The page's origin, for http(s) addresses only; anything else is refused. */
|
|
8150
|
+
const frameOrigin = (src) => {
|
|
8151
|
+
try {
|
|
8152
|
+
const url = new URL(src, window.location.href);
|
|
8153
|
+
return url.protocol === "https:" || url.protocol === "http:" ? url.origin : null;
|
|
8154
|
+
}
|
|
8155
|
+
catch {
|
|
8156
|
+
return null;
|
|
8157
|
+
}
|
|
8158
|
+
};
|
|
8159
|
+
/** A follow-up within the limits, or null. */
|
|
8160
|
+
const promptOf = (data, surfaceId) => {
|
|
8161
|
+
const text = typeof data?.text === "string" ? data.text.trim() : "";
|
|
8162
|
+
const context = data?.context && typeof data.context === "object" ? { ...data.context, surface: surfaceId } : { surface: surfaceId };
|
|
8163
|
+
let size = Infinity;
|
|
8164
|
+
try {
|
|
8165
|
+
size = JSON.stringify(context).length;
|
|
8166
|
+
}
|
|
8167
|
+
catch {
|
|
8168
|
+
// a context that cannot be sent is not sent
|
|
8169
|
+
}
|
|
8170
|
+
if (!text || text.length > PROMPT_TEXT_MAX || size > PROMPT_CONTEXT_MAX)
|
|
8171
|
+
return null;
|
|
8172
|
+
return { text, uiContext: context };
|
|
8173
|
+
};
|
|
8174
|
+
const SurfaceFrameContent = ({ frame, isFormDisabled = false, messageIndex = 0 }) => {
|
|
8175
|
+
const dispatch = useDispatch();
|
|
8176
|
+
const chatbotContext = useSelector((state) => state.smartBotReducer.chatbotContext);
|
|
8177
|
+
const contextRef = useRef(chatbotContext);
|
|
8178
|
+
contextRef.current = chatbotContext;
|
|
8179
|
+
const iframeRef = useRef(null);
|
|
8180
|
+
const ready = useRef(false);
|
|
8181
|
+
const [height, setHeight] = useState(120);
|
|
8182
|
+
const [form, setForm] = useState({ values: {}, inputs: [], missing: [] });
|
|
8183
|
+
const formRef = useRef(form);
|
|
8184
|
+
formRef.current = form;
|
|
8185
|
+
const src = frame?.src;
|
|
8186
|
+
const incoming = frame?.surface;
|
|
8187
|
+
// the surface shown: a newer version of the same surface replaces it, a lower one is ignored
|
|
8188
|
+
const [surface, setSurface] = useState(incoming);
|
|
8189
|
+
useEffect(() => {
|
|
8190
|
+
if (incoming && (!surface || incoming.id !== surface.id || surfaceVersion(incoming) >= surfaceVersion(surface)))
|
|
8191
|
+
setSurface(incoming);
|
|
8192
|
+
}, [incoming]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
8193
|
+
const origin = useMemo(() => frameOrigin(src), [src]);
|
|
8194
|
+
const ask = surface?.mode === "ask";
|
|
8195
|
+
// which version of its surface each widget shows, across the chat's messages
|
|
8196
|
+
const token = useRef(null);
|
|
8197
|
+
if (token.current === null)
|
|
8198
|
+
token.current = surfaceToken();
|
|
8199
|
+
const [, setShownChange] = useState(0);
|
|
8200
|
+
useEffect(() => watchSurfaces(() => setShownChange((n) => n + 1)), []);
|
|
8201
|
+
useEffect(() => {
|
|
8202
|
+
if (!surface?.id || surface.status === "pending" || surface.status === "withdrawn")
|
|
8203
|
+
return undefined;
|
|
8204
|
+
showSurface(surface.id, token.current, surfaceVersion(surface));
|
|
8205
|
+
return () => hideSurface(surface.id, token.current);
|
|
8206
|
+
}, [surface?.id, surface?.version, surface?.status]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
8207
|
+
const send = (target, values) => target?.postMessage({ type: "iui:surface", surface, values, disabled: Boolean(isFormDisabled), query: true, ...(ask ? { submit: false } : {}) }, origin);
|
|
8208
|
+
useEffect(() => {
|
|
8209
|
+
if (!origin || !surface)
|
|
8210
|
+
return undefined;
|
|
8211
|
+
const onMessage = (event) => {
|
|
8212
|
+
const target = iframeRef.current?.contentWindow;
|
|
8213
|
+
if (!target || event.source !== target || event.origin !== origin)
|
|
8214
|
+
return;
|
|
8215
|
+
const data = event.data || {};
|
|
8216
|
+
// every message but iui:ready and iui:height names its surface: this widget answers for its own only
|
|
8217
|
+
const own = data.surface === undefined || data.surface === surface.id;
|
|
8218
|
+
if (data.type === "iui:ready") {
|
|
8219
|
+
ready.current = true;
|
|
8220
|
+
send(target, undefined);
|
|
8221
|
+
}
|
|
8222
|
+
else if (data.type === "iui:height" && Number.isFinite(data.height))
|
|
8223
|
+
setHeight(Math.max(40, Math.ceil(data.height)));
|
|
8224
|
+
else if (data.type === "iui:query" && own) {
|
|
8225
|
+
const reply = (body) => target.postMessage({ type: "iui:data", surface: surface.id, id: data.id, ...body }, origin);
|
|
8226
|
+
const args = data.args || {};
|
|
8227
|
+
if (data.tool === "rows") {
|
|
8228
|
+
const source = sourceOf(surface, args.source?.table);
|
|
8229
|
+
if (!source)
|
|
8230
|
+
reply({ error: "not a table of this answer" });
|
|
8231
|
+
else
|
|
8232
|
+
pageOf({ ...args, source }).then(reply, () => reply({ error: "the rows could not be loaded" }));
|
|
8233
|
+
}
|
|
8234
|
+
else if (bindsTool(surface, data.tool)) {
|
|
8235
|
+
readOf({ surface: surface.id, tool: data.tool, args }).then(reply, () => reply({ error: "the data could not be loaded" }));
|
|
8236
|
+
}
|
|
8237
|
+
else
|
|
8238
|
+
reply({ error: "not a tool of this answer" });
|
|
8239
|
+
}
|
|
8240
|
+
else if (data.type === "iui:prompt" && data.surface === surface.id) {
|
|
8241
|
+
const prompt = promptOf(data, surface.id);
|
|
8242
|
+
if (prompt)
|
|
8243
|
+
window.dispatchEvent(new CustomEvent(PROMPT_EVENT, { detail: prompt }));
|
|
8244
|
+
}
|
|
8245
|
+
else if (data.type === "iui:change" && ask && own) {
|
|
8246
|
+
const values = data.values || {};
|
|
8247
|
+
setForm({ values, inputs: Array.isArray(data.inputs) ? data.inputs : Object.keys(values), missing: Array.isArray(data.missing) ? data.missing : [] });
|
|
8248
|
+
// as this chat's own inputs record their values, for the step form's Submit (ButtonContent)
|
|
8249
|
+
const context = { ...contextRef.current };
|
|
8250
|
+
for (const [name, value] of Object.entries(values)) {
|
|
8251
|
+
const empty = value === "" || value === null || value === undefined || (Array.isArray(value) && value.length === 0);
|
|
8252
|
+
context[name] = { ...context[name], [name]: value, updated: !empty };
|
|
8253
|
+
}
|
|
8254
|
+
dispatch(setChatbotContext(context));
|
|
8255
|
+
// only what was filled in: ButtonContent sends a persisted value even when it is empty
|
|
8256
|
+
const filled = Object.entries(values).filter(([name]) => context[name].updated);
|
|
8257
|
+
dispatch(setPersistedFormValues(Object.fromEntries(filled.map(([name, value]) => [`${messageIndex}_${name}`, value]))));
|
|
8258
|
+
}
|
|
8259
|
+
// anything else: a message type this chat does not know, ignored
|
|
8260
|
+
};
|
|
8261
|
+
window.addEventListener("message", onMessage);
|
|
8262
|
+
return () => window.removeEventListener("message", onMessage);
|
|
8263
|
+
}, [origin, surface, isFormDisabled, ask, messageIndex]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
8264
|
+
// a newer version of the surface goes into the page that shows it
|
|
8265
|
+
useEffect(() => {
|
|
8266
|
+
if (ready.current)
|
|
8267
|
+
send(iframeRef.current?.contentWindow, undefined);
|
|
8268
|
+
}, [surface]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
8269
|
+
// a submitted form is posted again, disabled, with what was filled in
|
|
8270
|
+
useEffect(() => {
|
|
8271
|
+
if (isFormDisabled && ask)
|
|
8272
|
+
send(iframeRef.current?.contentWindow, formRef.current.values);
|
|
8273
|
+
}, [isFormDisabled]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
8274
|
+
// a surface that will not come after all (its composition failed): nothing to draw
|
|
8275
|
+
if (!origin || !surface || surface.status === "withdrawn")
|
|
8276
|
+
return null;
|
|
8277
|
+
// a later message shows this surface revised: one line here, the surface there
|
|
8278
|
+
if (newerShown(surface.id, surfaceVersion(surface))) {
|
|
8279
|
+
return (jsx(Box, { "data-iui-host": "surface-frame", "data-iui-superseded": surface.id, my: 1, sx: { fontSize: 13, color: "text.secondary" }, children: `Revised below${surface.title ? `: ${surface.title}` : ""}.` }));
|
|
8280
|
+
}
|
|
8281
|
+
return (jsxs(Box, { "data-iui-host": "surface-frame", my: 1, children: [jsx("iframe", { ref: iframeRef, src: src, title: surface.title || "Generated answer", sandbox: "allow-scripts allow-same-origin", referrerPolicy: "no-referrer", style: { width: "100%", height, border: 0, display: "block" } }), ask ? (jsx(ButtonContent, { bodyText: SUBMIT, isFormDisabled: isFormDisabled, isStepFormSubmit: true, isFormValid: form.inputs.length > 0 && form.missing.length === 0, formParamNames: form.inputs, messageIndex: messageIndex })) : null] }));
|
|
8282
|
+
};
|
|
8283
|
+
|
|
8013
8284
|
// Key used to persist timeout state in sessionStorage (survives component remounts from tab switches)
|
|
8014
8285
|
const STEP_FORM_TIMEOUT_KEY = "__stepFormTimedOut";
|
|
8015
8286
|
/**
|
|
@@ -8437,11 +8708,17 @@ const StepFormContent = ({ formData, messageIndex = 0, isFormDisabled = false, s
|
|
|
8437
8708
|
case "radio":
|
|
8438
8709
|
return jsx(RadioContent, { bodyText: parsedData.bodyText, isFormDisabled: formFieldsDisabled, messageIndex: messageIndex }, key);
|
|
8439
8710
|
case "button":
|
|
8711
|
+
// A form in the renderer page has its Submit drawn by SurfaceFrameContent, which knows the page's inputs
|
|
8712
|
+
if (formData.some((item) => item?.type === "surface_frame"))
|
|
8713
|
+
return null;
|
|
8440
8714
|
return jsx(ButtonContent, { bodyText: parsedData.bodyText, isFormDisabled: isFormDisabled || isFormSubmitted || isTimedOut, isStepFormSubmit: true, isFormValid: requiredFieldsFilled && checkboxGroupsValid, formParamNames: formParamNames, messageIndex: messageIndex }, key);
|
|
8441
8715
|
case "input":
|
|
8442
8716
|
return jsx(InputContent, { bodyText: parsedData.bodyText, isFormDisabled: formFieldsDisabled, messageIndex: messageIndex }, key);
|
|
8443
8717
|
case "image":
|
|
8444
8718
|
return jsx(ImageContent, { bodyText: parsedData.bodyText }, key);
|
|
8719
|
+
case "surface_frame":
|
|
8720
|
+
// The whole form in the renderer page; the widget draws this form's Submit (its inputs are in the page)
|
|
8721
|
+
return jsx(SurfaceFrameContent, { frame: parsedData.bodyText, isFormDisabled: isFormDisabled || isFormSubmitted || isTimedOut, messageIndex: messageIndex }, parsedData.bodyText?.surface?.id || key);
|
|
8445
8722
|
default:
|
|
8446
8723
|
return null;
|
|
8447
8724
|
}
|
|
@@ -9467,6 +9744,8 @@ const renderWidgetItem = (item, index, isFormDisabled) => {
|
|
|
9467
9744
|
return jsx(DateRangePickerContent, { bodyText: parsedData.bodyText, isFormDisabled: isFormDisabled }, key);
|
|
9468
9745
|
case "html":
|
|
9469
9746
|
return jsx(HtmlContent, { bodyText: parsedData.bodyText }, key);
|
|
9747
|
+
case "surface_frame":
|
|
9748
|
+
return jsx(SurfaceFrameContent, { frame: parsedData.bodyText }, parsedData.bodyText?.surface?.id || key);
|
|
9470
9749
|
case "allocation_plan_card":
|
|
9471
9750
|
return jsx(AllocationPlanCard, { bodyText: parsedData.bodyText }, key);
|
|
9472
9751
|
default:
|
|
@@ -10340,7 +10619,8 @@ const StreamedContent = ({ botData, botProps }) => {
|
|
|
10340
10619
|
const widgetItems = isArray(data.widget_data)
|
|
10341
10620
|
? data.widget_data
|
|
10342
10621
|
: [data.widget_data];
|
|
10343
|
-
|
|
10622
|
+
// a surface sent again (placeholder, then the surface) replaces its widget in place
|
|
10623
|
+
setStreamingWidgetData((prev) => mergeSurfaceWidgets(prev, widgetItems));
|
|
10344
10624
|
}
|
|
10345
10625
|
else if (data.message !== "[DONE]") {
|
|
10346
10626
|
if (!thinkingDoneRef?.current && currentMode === "agent") {
|
|
@@ -11510,6 +11790,8 @@ const TabularContent = ({ steps: initialSteps, currentTabValue, children, questi
|
|
|
11510
11790
|
return jsx(TableContent, { bodyText: parsedData.bodyText }, parsedData.bodyText?.table_name || key);
|
|
11511
11791
|
case "graph":
|
|
11512
11792
|
return jsx(GraphContent, { bodyText: parsedData.bodyText }, key);
|
|
11793
|
+
case "surface_frame":
|
|
11794
|
+
return jsx(SurfaceFrameContent, { frame: parsedData.bodyText }, parsedData.bodyText?.surface?.id || key);
|
|
11513
11795
|
case "radio":
|
|
11514
11796
|
return jsx(RadioContent, { bodyText: parsedData.bodyText, isFormDisabled: isFormDisabled }, key);
|
|
11515
11797
|
case "checkbox":
|
|
@@ -11589,7 +11871,8 @@ const TabularContent = ({ steps: initialSteps, currentTabValue, children, questi
|
|
|
11589
11871
|
}
|
|
11590
11872
|
});
|
|
11591
11873
|
if (newWidgets.length > 0) {
|
|
11592
|
-
|
|
11874
|
+
// a surface sent again (placeholder, then the surface) replaces its widget in place
|
|
11875
|
+
setWidgetContent((prev) => mergeSurfaceWidgets(prev, newWidgets));
|
|
11593
11876
|
}
|
|
11594
11877
|
return;
|
|
11595
11878
|
}
|
|
@@ -11720,7 +12003,7 @@ const TabularContent = ({ steps: initialSteps, currentTabValue, children, questi
|
|
|
11720
12003
|
let newQuestions = [...questionsRef.current];
|
|
11721
12004
|
let newQuestionsStepsMap = cloneDeep(questionsStepsMapRef.current);
|
|
11722
12005
|
let newStepFormDataMap = cloneDeep(stepFormDataMapRef.current);
|
|
11723
|
-
|
|
12006
|
+
let newWidgets = [];
|
|
11724
12007
|
chunks.forEach((data) => {
|
|
11725
12008
|
if (data.status === "questions") {
|
|
11726
12009
|
const incomingQuestions = data.widget_data?.[0]?.questions || [];
|
|
@@ -11817,10 +12100,8 @@ const TabularContent = ({ steps: initialSteps, currentTabValue, children, questi
|
|
|
11817
12100
|
}
|
|
11818
12101
|
if (data.status === "widget") {
|
|
11819
12102
|
const widgetItems = isArray$2(data.widget_data) ? data.widget_data : [data.widget_data];
|
|
11820
|
-
|
|
11821
|
-
|
|
11822
|
-
newWidgets.push(item);
|
|
11823
|
-
});
|
|
12103
|
+
// a surface sent again (placeholder, then the surface) replaces its widget in place
|
|
12104
|
+
newWidgets = mergeSurfaceWidgets(newWidgets, widgetItems.filter(Boolean));
|
|
11824
12105
|
}
|
|
11825
12106
|
if (data.status === "content" && data.message) {
|
|
11826
12107
|
newWidgets.push({ type: "text", response: data.message });
|
|
@@ -11947,6 +12228,8 @@ const CombinedContent = ({ botData, props }) => {
|
|
|
11947
12228
|
return jsx(ImageContent, { bodyText: parsedData.bodyText }, key);
|
|
11948
12229
|
case "html":
|
|
11949
12230
|
return jsx(HtmlContent, { bodyText: parsedData.bodyText }, key);
|
|
12231
|
+
case "surface_frame":
|
|
12232
|
+
return jsx(SurfaceFrameContent, { frame: parsedData.bodyText }, parsedData.bodyText?.surface?.id || key);
|
|
11950
12233
|
case "allocation_plan_card":
|
|
11951
12234
|
return jsx(AllocationPlanCard, { bodyText: parsedData.bodyText }, key);
|
|
11952
12235
|
default:
|
|
@@ -12027,6 +12310,8 @@ const BotMessage = ({ botData, state, handleLikeDislike, props }) => {
|
|
|
12027
12310
|
return jsx(TableContent, { bodyText: botData.bodyText });
|
|
12028
12311
|
case "graph":
|
|
12029
12312
|
return jsx(GraphContent, { bodyText: botData.bodyText });
|
|
12313
|
+
case "surface_frame":
|
|
12314
|
+
return jsx(SurfaceFrameContent, { frame: botData.bodyText });
|
|
12030
12315
|
case "slider":
|
|
12031
12316
|
return jsx(SliderContent, { bodyText: botData.bodyText, isFormDisabled: botData.isFormDisabled, messageIndex: botData.messageIndex });
|
|
12032
12317
|
case "select":
|
|
@@ -17109,7 +17394,7 @@ const SmartBot = (props) => {
|
|
|
17109
17394
|
fetchLegacyAgentInfo(); //Disabled temporarily since this was causing issue on homepage first render
|
|
17110
17395
|
}
|
|
17111
17396
|
}, [location]);
|
|
17112
|
-
const handleSendMessage = async (userInput, userExplicitInput = {}, textWithColumnNames = "") => {
|
|
17397
|
+
const handleSendMessage = async (userInput, userExplicitInput = {}, textWithColumnNames = "", uiContext = null) => {
|
|
17113
17398
|
try {
|
|
17114
17399
|
// if (localStorage.getItem("isStreaming") === "true") {
|
|
17115
17400
|
// displaySnackMessages(
|
|
@@ -17173,6 +17458,7 @@ const SmartBot = (props) => {
|
|
|
17173
17458
|
userExplicitInput: userExplicitInput,
|
|
17174
17459
|
textWithColumnNames: textWithColumnNames,
|
|
17175
17460
|
answerMode: answerMode,
|
|
17461
|
+
...(uiContext ? { uiContext } : {}),
|
|
17176
17462
|
};
|
|
17177
17463
|
// if(!isEmpty(userInput)) {
|
|
17178
17464
|
// Clear the previous response's completed state so the incoming
|
|
@@ -17222,12 +17508,25 @@ const SmartBot = (props) => {
|
|
|
17222
17508
|
sessionStorage.removeItem("stepForm_chatId");
|
|
17223
17509
|
// dispatch(setChatbotContext({}));
|
|
17224
17510
|
setUserInput(params?.text);
|
|
17225
|
-
handleSendMessage(params?.text, params?.userExplicitInput, params?.textWithColumnNames);
|
|
17511
|
+
handleSendMessage(params?.text, params?.userExplicitInput, params?.textWithColumnNames, params?.uiContext);
|
|
17226
17512
|
}
|
|
17227
17513
|
catch (error) {
|
|
17228
17514
|
console.error("onSendIconClick error", error);
|
|
17229
17515
|
}
|
|
17230
17516
|
};
|
|
17517
|
+
// A follow-up asked from a generated surface (SurfaceFrameContent's "iris:prompt"): sent as the user's next
|
|
17518
|
+
// message, with the surface's context as ui_context. Not while a turn runs or a form waits for its Submit.
|
|
17519
|
+
const surfacePromptRef = useRef(null);
|
|
17520
|
+
surfacePromptRef.current = (detail) => {
|
|
17521
|
+
if (!detail?.text || isStop || !isEmpty$1(chatbotContext))
|
|
17522
|
+
return;
|
|
17523
|
+
onSendIconClick({ text: detail.text, uiContext: detail.uiContext });
|
|
17524
|
+
};
|
|
17525
|
+
useEffect(() => {
|
|
17526
|
+
const onSurfacePrompt = (event) => surfacePromptRef.current?.(event.detail);
|
|
17527
|
+
window.addEventListener("iris:prompt", onSurfacePrompt);
|
|
17528
|
+
return () => window.removeEventListener("iris:prompt", onSurfacePrompt);
|
|
17529
|
+
}, []);
|
|
17231
17530
|
const onStopIconClick = (params) => {
|
|
17232
17531
|
try {
|
|
17233
17532
|
setIsStop(false);
|