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.
@@ -0,0 +1,37 @@
1
+ export { mergeSurfaceWidgets } from "./surfaceWidgets";
2
+ /** A follow-up's limits: longer ones are ignored. */
3
+ export declare const PROMPT_TEXT_MAX = 1000;
4
+ export declare const PROMPT_CONTEXT_MAX = 16000;
5
+ /** The window event the chat listens to for a follow-up asked from a surface. */
6
+ export declare const PROMPT_EVENT = "iris:prompt";
7
+ /** The source a surface names for this temp table, if it names it: the only tables its page may ask pages
8
+ * of, and the endpoint address the agent gave (the page's own copy of the source is not trusted for it). */
9
+ export declare const sourceOf: (surface: any, table: any) => any;
10
+ /** Whether the surface binds this tool: the only tools its page may ask to read again. */
11
+ export declare const bindsTool: (surface: any, tool: any) => boolean;
12
+ /** One page of a source, from the agent's paging endpoint (its pages hold at most 10 rows): at the address
13
+ * the agent gave, as TableContent does with temp_table_url, else under the stream's base URL. `search`: a
14
+ * filter Control over the kept rows (catalog 0.3), each `{field, value}` an exact match the endpoint applies. */
15
+ export declare const pageOf: ({ source, page, pageSize, sort, search }: any) => Promise<{
16
+ rows: any[];
17
+ total: number;
18
+ }>;
19
+ /** A read tool the surface binds, run again by the agent with these arguments. */
20
+ export declare const readOf: ({ surface, tool, args }: any) => Promise<{
21
+ rows: any[];
22
+ total: number;
23
+ }>;
24
+ /** The page's origin, for http(s) addresses only; anything else is refused. */
25
+ export declare const frameOrigin: (src: any) => string | null;
26
+ /** A follow-up within the limits, or null. */
27
+ export declare const promptOf: (data: any, surfaceId: string) => {
28
+ text: string;
29
+ uiContext: any;
30
+ } | null;
31
+ interface SurfaceFrameContentProps {
32
+ frame: any;
33
+ isFormDisabled?: boolean;
34
+ messageIndex?: number;
35
+ }
36
+ declare const SurfaceFrameContent: ({ frame, isFormDisabled, messageIndex }: SurfaceFrameContentProps) => import("react/jsx-runtime").JSX.Element;
37
+ export default SurfaceFrameContent;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * One widget per generated surface in a stream: the agent may send a surface more than once (a placeholder
3
+ * while it is composed, `status: "pending"`, version 0; then the surface, version 1; or its withdrawal), and
4
+ * frame protocol 1 replaces a surface by its id (agent-ui-service-ssr docs/chat-frame-widget.md, rule 4).
5
+ * No imports: the stream reader (AxiosEventSource) uses it too. Ported from core's smartBot
6
+ * (insideinsight/core feat/iui-surface, e386f8f0).
7
+ */
8
+ /** A surface's version; one when it gives none. */
9
+ export declare const surfaceVersion: (surface: any) => number;
10
+ /** A stream's widgets with these added: a surface_frame widget whose surface the list already holds replaces
11
+ * it in place (a lower version is dropped); any other widget is added at the end. */
12
+ export declare const mergeSurfaceWidgets: (previous: any, incoming: any) => any[];
13
+ /** A token for one widget. */
14
+ export declare const surfaceToken: () => number;
15
+ /** This widget shows `version` of surface `id`. */
16
+ export declare const showSurface: (id: string, token: number, version: number) => void;
17
+ /** This widget no longer shows surface `id`. */
18
+ export declare const hideSurface: (id: string, token: number) => void;
19
+ /** Whether another widget shows surface `id` in a version higher than `version`. */
20
+ export declare const newerShown: (id: string, version: number) => boolean;
21
+ /** Calls `watch` whenever a widget starts or stops showing a surface; returns the unsubscribe. */
22
+ export declare const watchSurfaces: (watch: () => void) => (() => void);
package/dist/index.cjs.js CHANGED
@@ -316,6 +316,21 @@ const getTableRecords = async (payload, baseUrl, tableName) => {
316
316
  return null;
317
317
  }
318
318
  };
319
+ /** A read for a generated surface (frame protocol iui:query): the agent runs one read tool as the signed-in
320
+ * user and answers {rows, total}. */
321
+ const postUiQuery = async (payload, baseUrl) => {
322
+ try {
323
+ return axiosInstance({
324
+ url: `${baseUrl}/chatbot/agent/ui-query`,
325
+ method: 'POST',
326
+ data: payload,
327
+ });
328
+ }
329
+ catch (error) {
330
+ console.error('postUiQuery error:', error);
331
+ return null;
332
+ }
333
+ };
319
334
  const getTableRecordsByUrl = async (payload, url) => {
320
335
  try {
321
336
  return axiosInstance({
@@ -910,6 +925,18 @@ const parseResponse = (data, type, agentId = "", currentMode = "", disableTimeAn
910
925
  thinkingResponse: utilityObject?.thinkingResponse,
911
926
  enableLikes: true
912
927
  };
928
+ case "surface_frame":
929
+ // A generated UI surface drawn by the UI service's renderer page (Impact UI 5), which SurfaceFrameContent embeds
930
+ return {
931
+ ...data,
932
+ agentId: agentId,
933
+ timeStamp: timeString,
934
+ userType: "bot",
935
+ userName: userName,
936
+ headerTitle: data?.data?.surface?.title || "",
937
+ bodyType: "surface_frame",
938
+ bodyText: data?.data,
939
+ };
913
940
  default:
914
941
  return null;
915
942
  }
@@ -2441,6 +2468,10 @@ const useAgentFlow = (dateFormat, chatDataRef, currentMode, setShowChatPlacehold
2441
2468
  answer_mode: data?.answerMode || "auto",
2442
2469
  ...(!isEmpty(utilityObjectData?.additionalArgs) ? utilityObjectData.additionalArgs : {}),
2443
2470
  };
2471
+ if (data?.uiContext && typeof data.uiContext === "object") {
2472
+ // a follow-up asked from a generated surface: which surface, and its input values
2473
+ payload.ui_context = data.uiContext;
2474
+ }
2444
2475
  // Handle @ filter mentions - user_explicit_input contains filter values
2445
2476
  if (!isEmpty(data?.userExplicitInput)) {
2446
2477
  payload.user_explicit_input = data?.userExplicitInput;
@@ -5588,6 +5619,73 @@ const QuestionsContent = ({ bodyText, props }) => {
5588
5619
  }) }));
5589
5620
  };
5590
5621
 
5622
+ /**
5623
+ * One widget per generated surface in a stream: the agent may send a surface more than once (a placeholder
5624
+ * while it is composed, `status: "pending"`, version 0; then the surface, version 1; or its withdrawal), and
5625
+ * frame protocol 1 replaces a surface by its id (agent-ui-service-ssr docs/chat-frame-widget.md, rule 4).
5626
+ * No imports: the stream reader (AxiosEventSource) uses it too. Ported from core's smartBot
5627
+ * (insideinsight/core feat/iui-surface, e386f8f0).
5628
+ */
5629
+ /** A surface's version; one when it gives none. */
5630
+ const surfaceVersion = (surface) => (Number.isFinite(surface?.version) ? surface.version : 1);
5631
+ const surfaceIdOf = (widget) => (widget?.type === "surface_frame" ? widget?.data?.surface?.id : undefined);
5632
+ /** A stream's widgets with these added: a surface_frame widget whose surface the list already holds replaces
5633
+ * it in place (a lower version is dropped); any other widget is added at the end. */
5634
+ const mergeSurfaceWidgets = (previous, incoming) => {
5635
+ const merged = Array.isArray(previous) ? previous.slice() : previous ? [previous] : [];
5636
+ for (const widget of Array.isArray(incoming) ? incoming : [incoming]) {
5637
+ const id = surfaceIdOf(widget);
5638
+ const at = id === undefined ? -1 : merged.findIndex((w) => surfaceIdOf(w) === id);
5639
+ if (at < 0)
5640
+ merged.push(widget);
5641
+ else if (surfaceVersion(widget.data.surface) >= surfaceVersion(merged[at].data.surface))
5642
+ merged[at] = widget;
5643
+ }
5644
+ return merged;
5645
+ };
5646
+ /*
5647
+ * Across the chat's messages (one page per surface): a surface revised in a later turn is shown, newest
5648
+ * version, where that turn put it; each earlier widget of it collapses to a line. Every SurfaceFrameContent
5649
+ * says which version it shows; a widget whose surface another widget shows in a higher version collapses.
5650
+ * Placeholders and withdrawn surfaces take no part. Equal versions (the same surface drawn in two places)
5651
+ * both show.
5652
+ */
5653
+ const shownVersions = new Map(); // surface id -> Map(widget token -> version)
5654
+ const watchers = new Set();
5655
+ let lastToken = 0;
5656
+ /** A token for one widget. */
5657
+ const surfaceToken = () => {
5658
+ lastToken += 1;
5659
+ return lastToken;
5660
+ };
5661
+ const notify = () => watchers.forEach((watch) => watch());
5662
+ /** This widget shows `version` of surface `id`. */
5663
+ const showSurface = (id, token, version) => {
5664
+ if (!shownVersions.has(id))
5665
+ shownVersions.set(id, new Map());
5666
+ shownVersions.get(id).set(token, version);
5667
+ notify();
5668
+ };
5669
+ /** This widget no longer shows surface `id`. */
5670
+ const hideSurface = (id, token) => {
5671
+ const versions = shownVersions.get(id);
5672
+ if (!versions)
5673
+ return;
5674
+ versions.delete(token);
5675
+ if (versions.size === 0)
5676
+ shownVersions.delete(id);
5677
+ notify();
5678
+ };
5679
+ /** Whether another widget shows surface `id` in a version higher than `version`. */
5680
+ const newerShown = (id, version) => [...(shownVersions.get(id)?.values() ?? [])].some((v) => v > version);
5681
+ /** Calls `watch` whenever a widget starts or stops showing a surface; returns the unsubscribe. */
5682
+ const watchSurfaces = (watch) => {
5683
+ watchers.add(watch);
5684
+ return () => {
5685
+ watchers.delete(watch);
5686
+ };
5687
+ };
5688
+
5591
5689
  // Utility: check whether a string is a likely complete JSON value
5592
5690
  const isLikelyCompleteJson = (message) => {
5593
5691
  try {
@@ -5795,10 +5893,8 @@ const sseevent = (message, messageToStoreRef) => {
5795
5893
  let previousWidgetData = lodash.isArray(messageToStoreRef.current.appendedData)
5796
5894
  ? messageToStoreRef.current.appendedData
5797
5895
  : [messageToStoreRef.current.appendedData];
5798
- messageToStoreRef.current.appendedData = [
5799
- ...previousWidgetData,
5800
- ...finalWidgetData,
5801
- ];
5896
+ // a surface sent again (placeholder, then the surface) replaces its widget in place
5897
+ messageToStoreRef.current.appendedData = mergeSurfaceWidgets(previousWidgetData, finalWidgetData);
5802
5898
  messageToStoreRef.current.sessionId = parsedData.session_id;
5803
5899
  messageToStoreRef.current.uniqueChatId = parsedData?.chat_id
5804
5900
  ? parsedData.chat_id
@@ -5838,10 +5934,8 @@ const sseevent = (message, messageToStoreRef) => {
5838
5934
  let previousWidgetData = lodash.isArray(messageToStoreRef.current.appendedData)
5839
5935
  ? messageToStoreRef.current.appendedData
5840
5936
  : [messageToStoreRef.current.appendedData];
5841
- messageToStoreRef.current.appendedData = [
5842
- ...previousWidgetData,
5843
- ...finalWidgetData,
5844
- ];
5937
+ // a surface sent again (placeholder, then the surface) replaces its widget in place
5938
+ messageToStoreRef.current.appendedData = mergeSurfaceWidgets(previousWidgetData, finalWidgetData);
5845
5939
  messageToStoreRef.current.additionalArgs = parsedData?.additional_args
5846
5940
  ? parsedData.additional_args
5847
5941
  : {};
@@ -8032,6 +8126,183 @@ const ImageContent = ({ bodyText }) => {
8032
8126
  } })), caption && (jsxRuntime.jsx("div", { children: jsxRuntime.jsx(TextRenderer, { text: caption }) }))] }));
8033
8127
  };
8034
8128
 
8129
+ const SUBMIT = { buttons: [{ label: "Submit", variant: "primary" }] };
8130
+ /** A follow-up's limits: longer ones are ignored. */
8131
+ const PROMPT_TEXT_MAX = 1000;
8132
+ const PROMPT_CONTEXT_MAX = 16000;
8133
+ /** The window event the chat listens to for a follow-up asked from a surface. */
8134
+ const PROMPT_EVENT = "iris:prompt";
8135
+ /** The source a surface names for this temp table, if it names it: the only tables its page may ask pages
8136
+ * of, and the endpoint address the agent gave (the page's own copy of the source is not trusted for it). */
8137
+ const sourceOf = (surface, table) => Object.values(surface?.data || {}).map((entry) => entry?.source).find((source) => typeof source?.table === "string" && source.table === table);
8138
+ /** Whether the surface binds this tool: the only tools its page may ask to read again. */
8139
+ const bindsTool = (surface, tool) => typeof tool === "string" && tool !== "rows" && Object.values(surface?.data || {}).some((entry) => entry?.tool === tool);
8140
+ const baseUrl = () => sessionStorage.getItem("stepForm_baseUrl") || "";
8141
+ /** One page of a source, from the agent's paging endpoint (its pages hold at most 10 rows): at the address
8142
+ * the agent gave, as TableContent does with temp_table_url, else under the stream's base URL. `search`: a
8143
+ * filter Control over the kept rows (catalog 0.3), each `{field, value}` an exact match the endpoint applies. */
8144
+ const pageOf = async ({ source, page, pageSize, sort, search }) => {
8145
+ const payload = {
8146
+ limit: { page, page_size: pageSize },
8147
+ search: (Array.isArray(search) ? search : [])
8148
+ .filter((s) => s && typeof s.field === "string" && s.value !== undefined && s.value !== null)
8149
+ .slice(0, 5)
8150
+ .map((s) => ({ column: s.field, pattern: String(s.value), search_type: "equals" })),
8151
+ sort: (Array.isArray(sort) ? sort : []).map((s) => ({ column: s.field, order: s.order === "desc" ? "desc" : "asc" })),
8152
+ };
8153
+ const response = source.url
8154
+ ? await getTableRecordsByUrl(payload, source.url)
8155
+ : await getTableRecords(payload, baseUrl(), source.table);
8156
+ const rows = response?.data?.data;
8157
+ const total = response?.data?.total_count;
8158
+ if (!Array.isArray(rows) || !Number.isFinite(total))
8159
+ throw new Error("no rows");
8160
+ return { rows, total };
8161
+ };
8162
+ /** A read tool the surface binds, run again by the agent with these arguments. */
8163
+ const readOf = async ({ surface, tool, args }) => {
8164
+ const response = await postUiQuery({ surface, tool, args: args && typeof args === "object" ? args : {} }, baseUrl());
8165
+ const rows = response?.data?.rows;
8166
+ const total = response?.data?.total;
8167
+ if (!Array.isArray(rows) || !Number.isFinite(total))
8168
+ throw new Error(response?.data?.error || "no rows");
8169
+ return { rows, total };
8170
+ };
8171
+ /** The page's origin, for http(s) addresses only; anything else is refused. */
8172
+ const frameOrigin = (src) => {
8173
+ try {
8174
+ const url = new URL(src, window.location.href);
8175
+ return url.protocol === "https:" || url.protocol === "http:" ? url.origin : null;
8176
+ }
8177
+ catch {
8178
+ return null;
8179
+ }
8180
+ };
8181
+ /** A follow-up within the limits, or null. */
8182
+ const promptOf = (data, surfaceId) => {
8183
+ const text = typeof data?.text === "string" ? data.text.trim() : "";
8184
+ const context = data?.context && typeof data.context === "object" ? { ...data.context, surface: surfaceId } : { surface: surfaceId };
8185
+ let size = Infinity;
8186
+ try {
8187
+ size = JSON.stringify(context).length;
8188
+ }
8189
+ catch {
8190
+ // a context that cannot be sent is not sent
8191
+ }
8192
+ if (!text || text.length > PROMPT_TEXT_MAX || size > PROMPT_CONTEXT_MAX)
8193
+ return null;
8194
+ return { text, uiContext: context };
8195
+ };
8196
+ const SurfaceFrameContent = ({ frame, isFormDisabled = false, messageIndex = 0 }) => {
8197
+ const dispatch = reactRedux.useDispatch();
8198
+ const chatbotContext = reactRedux.useSelector((state) => state.smartBotReducer.chatbotContext);
8199
+ const contextRef = React.useRef(chatbotContext);
8200
+ contextRef.current = chatbotContext;
8201
+ const iframeRef = React.useRef(null);
8202
+ const ready = React.useRef(false);
8203
+ const [height, setHeight] = React.useState(120);
8204
+ const [form, setForm] = React.useState({ values: {}, inputs: [], missing: [] });
8205
+ const formRef = React.useRef(form);
8206
+ formRef.current = form;
8207
+ const src = frame?.src;
8208
+ const incoming = frame?.surface;
8209
+ // the surface shown: a newer version of the same surface replaces it, a lower one is ignored
8210
+ const [surface, setSurface] = React.useState(incoming);
8211
+ React.useEffect(() => {
8212
+ if (incoming && (!surface || incoming.id !== surface.id || surfaceVersion(incoming) >= surfaceVersion(surface)))
8213
+ setSurface(incoming);
8214
+ }, [incoming]); // eslint-disable-line react-hooks/exhaustive-deps
8215
+ const origin = React.useMemo(() => frameOrigin(src), [src]);
8216
+ const ask = surface?.mode === "ask";
8217
+ // which version of its surface each widget shows, across the chat's messages
8218
+ const token = React.useRef(null);
8219
+ if (token.current === null)
8220
+ token.current = surfaceToken();
8221
+ const [, setShownChange] = React.useState(0);
8222
+ React.useEffect(() => watchSurfaces(() => setShownChange((n) => n + 1)), []);
8223
+ React.useEffect(() => {
8224
+ if (!surface?.id || surface.status === "pending" || surface.status === "withdrawn")
8225
+ return undefined;
8226
+ showSurface(surface.id, token.current, surfaceVersion(surface));
8227
+ return () => hideSurface(surface.id, token.current);
8228
+ }, [surface?.id, surface?.version, surface?.status]); // eslint-disable-line react-hooks/exhaustive-deps
8229
+ const send = (target, values) => target?.postMessage({ type: "iui:surface", surface, values, disabled: Boolean(isFormDisabled), query: true, ...(ask ? { submit: false } : {}) }, origin);
8230
+ React.useEffect(() => {
8231
+ if (!origin || !surface)
8232
+ return undefined;
8233
+ const onMessage = (event) => {
8234
+ const target = iframeRef.current?.contentWindow;
8235
+ if (!target || event.source !== target || event.origin !== origin)
8236
+ return;
8237
+ const data = event.data || {};
8238
+ // every message but iui:ready and iui:height names its surface: this widget answers for its own only
8239
+ const own = data.surface === undefined || data.surface === surface.id;
8240
+ if (data.type === "iui:ready") {
8241
+ ready.current = true;
8242
+ send(target, undefined);
8243
+ }
8244
+ else if (data.type === "iui:height" && Number.isFinite(data.height))
8245
+ setHeight(Math.max(40, Math.ceil(data.height)));
8246
+ else if (data.type === "iui:query" && own) {
8247
+ const reply = (body) => target.postMessage({ type: "iui:data", surface: surface.id, id: data.id, ...body }, origin);
8248
+ const args = data.args || {};
8249
+ if (data.tool === "rows") {
8250
+ const source = sourceOf(surface, args.source?.table);
8251
+ if (!source)
8252
+ reply({ error: "not a table of this answer" });
8253
+ else
8254
+ pageOf({ ...args, source }).then(reply, () => reply({ error: "the rows could not be loaded" }));
8255
+ }
8256
+ else if (bindsTool(surface, data.tool)) {
8257
+ readOf({ surface: surface.id, tool: data.tool, args }).then(reply, () => reply({ error: "the data could not be loaded" }));
8258
+ }
8259
+ else
8260
+ reply({ error: "not a tool of this answer" });
8261
+ }
8262
+ else if (data.type === "iui:prompt" && data.surface === surface.id) {
8263
+ const prompt = promptOf(data, surface.id);
8264
+ if (prompt)
8265
+ window.dispatchEvent(new CustomEvent(PROMPT_EVENT, { detail: prompt }));
8266
+ }
8267
+ else if (data.type === "iui:change" && ask && own) {
8268
+ const values = data.values || {};
8269
+ setForm({ values, inputs: Array.isArray(data.inputs) ? data.inputs : Object.keys(values), missing: Array.isArray(data.missing) ? data.missing : [] });
8270
+ // as this chat's own inputs record their values, for the step form's Submit (ButtonContent)
8271
+ const context = { ...contextRef.current };
8272
+ for (const [name, value] of Object.entries(values)) {
8273
+ const empty = value === "" || value === null || value === undefined || (Array.isArray(value) && value.length === 0);
8274
+ context[name] = { ...context[name], [name]: value, updated: !empty };
8275
+ }
8276
+ dispatch(smartBotActions.setChatbotContext(context));
8277
+ // only what was filled in: ButtonContent sends a persisted value even when it is empty
8278
+ const filled = Object.entries(values).filter(([name]) => context[name].updated);
8279
+ dispatch(smartBotActions.setPersistedFormValues(Object.fromEntries(filled.map(([name, value]) => [`${messageIndex}_${name}`, value]))));
8280
+ }
8281
+ // anything else: a message type this chat does not know, ignored
8282
+ };
8283
+ window.addEventListener("message", onMessage);
8284
+ return () => window.removeEventListener("message", onMessage);
8285
+ }, [origin, surface, isFormDisabled, ask, messageIndex]); // eslint-disable-line react-hooks/exhaustive-deps
8286
+ // a newer version of the surface goes into the page that shows it
8287
+ React.useEffect(() => {
8288
+ if (ready.current)
8289
+ send(iframeRef.current?.contentWindow, undefined);
8290
+ }, [surface]); // eslint-disable-line react-hooks/exhaustive-deps
8291
+ // a submitted form is posted again, disabled, with what was filled in
8292
+ React.useEffect(() => {
8293
+ if (isFormDisabled && ask)
8294
+ send(iframeRef.current?.contentWindow, formRef.current.values);
8295
+ }, [isFormDisabled]); // eslint-disable-line react-hooks/exhaustive-deps
8296
+ // a surface that will not come after all (its composition failed): nothing to draw
8297
+ if (!origin || !surface || surface.status === "withdrawn")
8298
+ return null;
8299
+ // a later message shows this surface revised: one line here, the surface there
8300
+ if (newerShown(surface.id, surfaceVersion(surface))) {
8301
+ return (jsxRuntime.jsx(material.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}` : ""}.` }));
8302
+ }
8303
+ return (jsxRuntime.jsxs(material.Box, { "data-iui-host": "surface-frame", my: 1, children: [jsxRuntime.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 ? (jsxRuntime.jsx(ButtonContent, { bodyText: SUBMIT, isFormDisabled: isFormDisabled, isStepFormSubmit: true, isFormValid: form.inputs.length > 0 && form.missing.length === 0, formParamNames: form.inputs, messageIndex: messageIndex })) : null] }));
8304
+ };
8305
+
8035
8306
  // Key used to persist timeout state in sessionStorage (survives component remounts from tab switches)
8036
8307
  const STEP_FORM_TIMEOUT_KEY = "__stepFormTimedOut";
8037
8308
  /**
@@ -8459,11 +8730,17 @@ const StepFormContent = ({ formData, messageIndex = 0, isFormDisabled = false, s
8459
8730
  case "radio":
8460
8731
  return jsxRuntime.jsx(RadioContent, { bodyText: parsedData.bodyText, isFormDisabled: formFieldsDisabled, messageIndex: messageIndex }, key);
8461
8732
  case "button":
8733
+ // A form in the renderer page has its Submit drawn by SurfaceFrameContent, which knows the page's inputs
8734
+ if (formData.some((item) => item?.type === "surface_frame"))
8735
+ return null;
8462
8736
  return jsxRuntime.jsx(ButtonContent, { bodyText: parsedData.bodyText, isFormDisabled: isFormDisabled || isFormSubmitted || isTimedOut, isStepFormSubmit: true, isFormValid: requiredFieldsFilled && checkboxGroupsValid, formParamNames: formParamNames, messageIndex: messageIndex }, key);
8463
8737
  case "input":
8464
8738
  return jsxRuntime.jsx(InputContent, { bodyText: parsedData.bodyText, isFormDisabled: formFieldsDisabled, messageIndex: messageIndex }, key);
8465
8739
  case "image":
8466
8740
  return jsxRuntime.jsx(ImageContent, { bodyText: parsedData.bodyText }, key);
8741
+ case "surface_frame":
8742
+ // The whole form in the renderer page; the widget draws this form's Submit (its inputs are in the page)
8743
+ return jsxRuntime.jsx(SurfaceFrameContent, { frame: parsedData.bodyText, isFormDisabled: isFormDisabled || isFormSubmitted || isTimedOut, messageIndex: messageIndex }, parsedData.bodyText?.surface?.id || key);
8467
8744
  default:
8468
8745
  return null;
8469
8746
  }
@@ -9489,6 +9766,8 @@ const renderWidgetItem = (item, index, isFormDisabled) => {
9489
9766
  return jsxRuntime.jsx(DateRangePickerContent, { bodyText: parsedData.bodyText, isFormDisabled: isFormDisabled }, key);
9490
9767
  case "html":
9491
9768
  return jsxRuntime.jsx(HtmlContent, { bodyText: parsedData.bodyText }, key);
9769
+ case "surface_frame":
9770
+ return jsxRuntime.jsx(SurfaceFrameContent, { frame: parsedData.bodyText }, parsedData.bodyText?.surface?.id || key);
9492
9771
  case "allocation_plan_card":
9493
9772
  return jsxRuntime.jsx(AllocationPlanCard, { bodyText: parsedData.bodyText }, key);
9494
9773
  default:
@@ -10362,7 +10641,8 @@ const StreamedContent = ({ botData, botProps }) => {
10362
10641
  const widgetItems = isArray(data.widget_data)
10363
10642
  ? data.widget_data
10364
10643
  : [data.widget_data];
10365
- setStreamingWidgetData((prev) => [...prev, ...widgetItems]);
10644
+ // a surface sent again (placeholder, then the surface) replaces its widget in place
10645
+ setStreamingWidgetData((prev) => mergeSurfaceWidgets(prev, widgetItems));
10366
10646
  }
10367
10647
  else if (data.message !== "[DONE]") {
10368
10648
  if (!thinkingDoneRef?.current && currentMode === "agent") {
@@ -11532,6 +11812,8 @@ const TabularContent = ({ steps: initialSteps, currentTabValue, children, questi
11532
11812
  return jsxRuntime.jsx(TableContent, { bodyText: parsedData.bodyText }, parsedData.bodyText?.table_name || key);
11533
11813
  case "graph":
11534
11814
  return jsxRuntime.jsx(GraphContent, { bodyText: parsedData.bodyText }, key);
11815
+ case "surface_frame":
11816
+ return jsxRuntime.jsx(SurfaceFrameContent, { frame: parsedData.bodyText }, parsedData.bodyText?.surface?.id || key);
11535
11817
  case "radio":
11536
11818
  return jsxRuntime.jsx(RadioContent, { bodyText: parsedData.bodyText, isFormDisabled: isFormDisabled }, key);
11537
11819
  case "checkbox":
@@ -11611,7 +11893,8 @@ const TabularContent = ({ steps: initialSteps, currentTabValue, children, questi
11611
11893
  }
11612
11894
  });
11613
11895
  if (newWidgets.length > 0) {
11614
- setWidgetContent((prev) => [...prev, ...newWidgets]);
11896
+ // a surface sent again (placeholder, then the surface) replaces its widget in place
11897
+ setWidgetContent((prev) => mergeSurfaceWidgets(prev, newWidgets));
11615
11898
  }
11616
11899
  return;
11617
11900
  }
@@ -11742,7 +12025,7 @@ const TabularContent = ({ steps: initialSteps, currentTabValue, children, questi
11742
12025
  let newQuestions = [...questionsRef.current];
11743
12026
  let newQuestionsStepsMap = lodash.cloneDeep(questionsStepsMapRef.current);
11744
12027
  let newStepFormDataMap = lodash.cloneDeep(stepFormDataMapRef.current);
11745
- const newWidgets = [];
12028
+ let newWidgets = [];
11746
12029
  chunks.forEach((data) => {
11747
12030
  if (data.status === "questions") {
11748
12031
  const incomingQuestions = data.widget_data?.[0]?.questions || [];
@@ -11839,10 +12122,8 @@ const TabularContent = ({ steps: initialSteps, currentTabValue, children, questi
11839
12122
  }
11840
12123
  if (data.status === "widget") {
11841
12124
  const widgetItems = isArray$1(data.widget_data) ? data.widget_data : [data.widget_data];
11842
- widgetItems.forEach((item) => {
11843
- if (item)
11844
- newWidgets.push(item);
11845
- });
12125
+ // a surface sent again (placeholder, then the surface) replaces its widget in place
12126
+ newWidgets = mergeSurfaceWidgets(newWidgets, widgetItems.filter(Boolean));
11846
12127
  }
11847
12128
  if (data.status === "content" && data.message) {
11848
12129
  newWidgets.push({ type: "text", response: data.message });
@@ -11969,6 +12250,8 @@ const CombinedContent = ({ botData, props }) => {
11969
12250
  return jsxRuntime.jsx(ImageContent, { bodyText: parsedData.bodyText }, key);
11970
12251
  case "html":
11971
12252
  return jsxRuntime.jsx(HtmlContent, { bodyText: parsedData.bodyText }, key);
12253
+ case "surface_frame":
12254
+ return jsxRuntime.jsx(SurfaceFrameContent, { frame: parsedData.bodyText }, parsedData.bodyText?.surface?.id || key);
11972
12255
  case "allocation_plan_card":
11973
12256
  return jsxRuntime.jsx(AllocationPlanCard, { bodyText: parsedData.bodyText }, key);
11974
12257
  default:
@@ -12049,6 +12332,8 @@ const BotMessage = ({ botData, state, handleLikeDislike, props }) => {
12049
12332
  return jsxRuntime.jsx(TableContent, { bodyText: botData.bodyText });
12050
12333
  case "graph":
12051
12334
  return jsxRuntime.jsx(GraphContent, { bodyText: botData.bodyText });
12335
+ case "surface_frame":
12336
+ return jsxRuntime.jsx(SurfaceFrameContent, { frame: botData.bodyText });
12052
12337
  case "slider":
12053
12338
  return jsxRuntime.jsx(SliderContent, { bodyText: botData.bodyText, isFormDisabled: botData.isFormDisabled, messageIndex: botData.messageIndex });
12054
12339
  case "select":
@@ -17131,7 +17416,7 @@ const SmartBot = (props) => {
17131
17416
  fetchLegacyAgentInfo(); //Disabled temporarily since this was causing issue on homepage first render
17132
17417
  }
17133
17418
  }, [location]);
17134
- const handleSendMessage = async (userInput, userExplicitInput = {}, textWithColumnNames = "") => {
17419
+ const handleSendMessage = async (userInput, userExplicitInput = {}, textWithColumnNames = "", uiContext = null) => {
17135
17420
  try {
17136
17421
  // if (localStorage.getItem("isStreaming") === "true") {
17137
17422
  // displaySnackMessages(
@@ -17195,6 +17480,7 @@ const SmartBot = (props) => {
17195
17480
  userExplicitInput: userExplicitInput,
17196
17481
  textWithColumnNames: textWithColumnNames,
17197
17482
  answerMode: answerMode,
17483
+ ...(uiContext ? { uiContext } : {}),
17198
17484
  };
17199
17485
  // if(!isEmpty(userInput)) {
17200
17486
  // Clear the previous response's completed state so the incoming
@@ -17244,12 +17530,25 @@ const SmartBot = (props) => {
17244
17530
  sessionStorage.removeItem("stepForm_chatId");
17245
17531
  // dispatch(setChatbotContext({}));
17246
17532
  setUserInput(params?.text);
17247
- handleSendMessage(params?.text, params?.userExplicitInput, params?.textWithColumnNames);
17533
+ handleSendMessage(params?.text, params?.userExplicitInput, params?.textWithColumnNames, params?.uiContext);
17248
17534
  }
17249
17535
  catch (error) {
17250
17536
  console.error("onSendIconClick error", error);
17251
17537
  }
17252
17538
  };
17539
+ // A follow-up asked from a generated surface (SurfaceFrameContent's "iris:prompt"): sent as the user's next
17540
+ // message, with the surface's context as ui_context. Not while a turn runs or a form waits for its Submit.
17541
+ const surfacePromptRef = React.useRef(null);
17542
+ surfacePromptRef.current = (detail) => {
17543
+ if (!detail?.text || isStop || !lodash.isEmpty(chatbotContext))
17544
+ return;
17545
+ onSendIconClick({ text: detail.text, uiContext: detail.uiContext });
17546
+ };
17547
+ React.useEffect(() => {
17548
+ const onSurfacePrompt = (event) => surfacePromptRef.current?.(event.detail);
17549
+ window.addEventListener("iris:prompt", onSurfacePrompt);
17550
+ return () => window.removeEventListener("iris:prompt", onSurfacePrompt);
17551
+ }, []);
17253
17552
  const onStopIconClick = (params) => {
17254
17553
  try {
17255
17554
  setIsStop(false);