impact-chatbot 3.0.0 → 3.1.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/index.cjs.js CHANGED
@@ -41,10 +41,19 @@ require('highcharts/esm/modules/heatmap.js');
41
41
  require('highcharts/esm/modules/pareto.js');
42
42
  var makeStyles = require('@mui/styles/makeStyles');
43
43
  var ChevronRightIcon$1 = require('@mui/icons-material/ChevronRight');
44
+ var DescriptionOutlinedIcon = require('@mui/icons-material/DescriptionOutlined');
45
+ var OpenInNewIcon = require('@mui/icons-material/OpenInNew');
44
46
  var FormatListBulletedOutlinedIcon = require('@mui/icons-material/FormatListBulletedOutlined');
45
47
  var PsychologyOutlinedIcon = require('@mui/icons-material/PsychologyOutlined');
46
48
  var SaveOutlinedIcon = require('@mui/icons-material/SaveOutlined');
47
49
  require('react-dates/lib/css/_datepicker.css');
50
+ var reactDom = require('react-dom');
51
+ var VisibilityOutlinedIcon = require('@mui/icons-material/VisibilityOutlined');
52
+ var OpenInFullIcon = require('@mui/icons-material/OpenInFull');
53
+ var CloseFullscreenIcon = require('@mui/icons-material/CloseFullscreen');
54
+ var CloseIcon = require('@mui/icons-material/Close');
55
+ var ExpandMoreIcon = require('@mui/icons-material/ExpandMore');
56
+ var ArrowForwardIcon = require('@mui/icons-material/ArrowForward');
48
57
 
49
58
  function _interopNamespaceDefault(e) {
50
59
  var n = Object.create(null);
@@ -833,6 +842,21 @@ const getTableRecords = async (payload, baseUrl, tableName) => {
833
842
  return null;
834
843
  }
835
844
  };
845
+ /** A read for a generated surface (frame protocol iui:query): the agent runs one read tool as the signed-in
846
+ * user and answers {rows, total}. */
847
+ const postUiQuery = async (payload, baseUrl) => {
848
+ try {
849
+ return axiosInstance({
850
+ url: `${baseUrl}/chatbot/agent/ui-query`,
851
+ method: 'POST',
852
+ data: payload,
853
+ });
854
+ }
855
+ catch (error) {
856
+ console.error('postUiQuery error:', error);
857
+ return null;
858
+ }
859
+ };
836
860
  const getTableRecordsByUrl = async (payload, url) => {
837
861
  try {
838
862
  return httpRequest({
@@ -1455,6 +1479,7 @@ const parseResponse = (data, type, agentId = "", currentMode = "", disableTimeAn
1455
1479
  isDisabled: data?.data?.isDisabled,
1456
1480
  orientation: data?.data?.orientation,
1457
1481
  options: data?.data?.options,
1482
+ defaultSelected: data?.data?.defaultSelected,
1458
1483
  paramName: data?.data?.param_name
1459
1484
  }
1460
1485
  };
@@ -1534,6 +1559,17 @@ const parseResponse = (data, type, agentId = "", currentMode = "", disableTimeAn
1534
1559
  bodyType: "html",
1535
1560
  bodyText: { content: data?.data?.content || "" },
1536
1561
  };
1562
+ case "allocation_plan_card":
1563
+ return {
1564
+ ...data,
1565
+ timeStamp: timeString,
1566
+ userType: "bot",
1567
+ userName: userName,
1568
+ headerTitle: "",
1569
+ noShowHeaderTitle: true,
1570
+ bodyType: "allocation_plan_card",
1571
+ bodyText: data?.data || data,
1572
+ };
1537
1573
  case "image":
1538
1574
  return {
1539
1575
  ...data,
@@ -1561,6 +1597,18 @@ const parseResponse = (data, type, agentId = "", currentMode = "", disableTimeAn
1561
1597
  thinkingResponse: utilityObject?.thinkingResponse,
1562
1598
  enableLikes: true
1563
1599
  };
1600
+ case "surface_frame":
1601
+ // A generated UI surface drawn by the UI service's renderer page (Impact UI 5), which SurfaceFrameContent embeds
1602
+ return {
1603
+ ...data,
1604
+ agentId: agentId,
1605
+ timeStamp: timeString,
1606
+ userType: "bot",
1607
+ userName: userName,
1608
+ headerTitle: data?.data?.surface?.title || "",
1609
+ bodyType: "surface_frame",
1610
+ bodyText: data?.data,
1611
+ };
1564
1612
  default:
1565
1613
  return null;
1566
1614
  }
@@ -2823,6 +2871,10 @@ const useAgentFlow = (dateFormat, chatDataRef, currentMode, setShowChatPlacehold
2823
2871
  answer_mode: data?.answerMode || "auto",
2824
2872
  ...(!isEmpty(utilityObjectData?.additionalArgs) ? utilityObjectData.additionalArgs : {}),
2825
2873
  };
2874
+ if (data?.uiContext && typeof data.uiContext === "object") {
2875
+ // a follow-up asked from a generated surface: which surface, and its input values
2876
+ payload.ui_context = data.uiContext;
2877
+ }
2826
2878
  // Handle @ filter mentions - user_explicit_input contains filter values
2827
2879
  if (!isEmpty(data?.userExplicitInput)) {
2828
2880
  payload.user_explicit_input = data?.userExplicitInput;
@@ -3283,9 +3335,16 @@ const useChatFlow = (chatDataRef, setLoader, setFlowType, setScreenName, setUser
3283
3335
  else if (data.actionType === "indirect") {
3284
3336
  setUserInput(data.displayText);
3285
3337
  }
3286
- else {
3338
+ else if (data.screen_name) {
3287
3339
  fetchUserResultsFromQuery(data, true, "", activeConversationId);
3288
3340
  }
3341
+ else {
3342
+ // No screen_name (e.g. suggested follow-up chips from navigation-v2):
3343
+ // treat the chip's displayText as a regular user query so it flows
3344
+ // through the navigation streaming endpoint instead of the
3345
+ // fetchRelatedQuestions screen-based endpoint.
3346
+ fetchUserResultsFromQuery(data, false, data.displayText, activeConversationId);
3347
+ }
3289
3348
  }, [activeConversationId, baseUrl]);
3290
3349
  const fetchUserResultsFromQuery = React.useCallback(async (refObject, fetchQuestions = false, inputValue = userInput, conversationId = activeConversationId) => {
3291
3350
  let flowType = refObject?.flow_type ? refObject?.flow_type : currentMode;
@@ -6017,6 +6076,73 @@ const QuestionsContent = ({ bodyText, props }) => {
6017
6076
  }) }));
6018
6077
  };
6019
6078
 
6079
+ /**
6080
+ * One widget per generated surface in a stream: the agent may send a surface more than once (a placeholder
6081
+ * while it is composed, `status: "pending"`, version 0; then the surface, version 1; or its withdrawal), and
6082
+ * frame protocol 1 replaces a surface by its id (agent-ui-service-ssr docs/chat-frame-widget.md, rule 4).
6083
+ * No imports: the stream reader (AxiosEventSource) uses it too. Ported from core's smartBot
6084
+ * (insideinsight/core feat/iui-surface, e386f8f0).
6085
+ */
6086
+ /** A surface's version; one when it gives none. */
6087
+ const surfaceVersion = (surface) => (Number.isFinite(surface?.version) ? surface.version : 1);
6088
+ const surfaceIdOf = (widget) => (widget?.type === "surface_frame" ? widget?.data?.surface?.id : undefined);
6089
+ /** A stream's widgets with these added: a surface_frame widget whose surface the list already holds replaces
6090
+ * it in place (a lower version is dropped); any other widget is added at the end. */
6091
+ const mergeSurfaceWidgets = (previous, incoming) => {
6092
+ const merged = Array.isArray(previous) ? previous.slice() : previous ? [previous] : [];
6093
+ for (const widget of Array.isArray(incoming) ? incoming : [incoming]) {
6094
+ const id = surfaceIdOf(widget);
6095
+ const at = id === undefined ? -1 : merged.findIndex((w) => surfaceIdOf(w) === id);
6096
+ if (at < 0)
6097
+ merged.push(widget);
6098
+ else if (surfaceVersion(widget.data.surface) >= surfaceVersion(merged[at].data.surface))
6099
+ merged[at] = widget;
6100
+ }
6101
+ return merged;
6102
+ };
6103
+ /*
6104
+ * Across the chat's messages (one page per surface): a surface revised in a later turn is shown, newest
6105
+ * version, where that turn put it; each earlier widget of it collapses to a line. Every SurfaceFrameContent
6106
+ * says which version it shows; a widget whose surface another widget shows in a higher version collapses.
6107
+ * Placeholders and withdrawn surfaces take no part. Equal versions (the same surface drawn in two places)
6108
+ * both show.
6109
+ */
6110
+ const shownVersions = new Map(); // surface id -> Map(widget token -> version)
6111
+ const watchers = new Set();
6112
+ let lastToken = 0;
6113
+ /** A token for one widget. */
6114
+ const surfaceToken = () => {
6115
+ lastToken += 1;
6116
+ return lastToken;
6117
+ };
6118
+ const notify = () => watchers.forEach((watch) => watch());
6119
+ /** This widget shows `version` of surface `id`. */
6120
+ const showSurface = (id, token, version) => {
6121
+ if (!shownVersions.has(id))
6122
+ shownVersions.set(id, new Map());
6123
+ shownVersions.get(id).set(token, version);
6124
+ notify();
6125
+ };
6126
+ /** This widget no longer shows surface `id`. */
6127
+ const hideSurface = (id, token) => {
6128
+ const versions = shownVersions.get(id);
6129
+ if (!versions)
6130
+ return;
6131
+ versions.delete(token);
6132
+ if (versions.size === 0)
6133
+ shownVersions.delete(id);
6134
+ notify();
6135
+ };
6136
+ /** Whether another widget shows surface `id` in a version higher than `version`. */
6137
+ const newerShown = (id, version) => [...(shownVersions.get(id)?.values() ?? [])].some((v) => v > version);
6138
+ /** Calls `watch` whenever a widget starts or stops showing a surface; returns the unsubscribe. */
6139
+ const watchSurfaces = (watch) => {
6140
+ watchers.add(watch);
6141
+ return () => {
6142
+ watchers.delete(watch);
6143
+ };
6144
+ };
6145
+
6020
6146
  // Utility: check whether a string is a likely complete JSON value
6021
6147
  const isLikelyCompleteJson = (message) => {
6022
6148
  try {
@@ -6224,10 +6350,8 @@ const sseevent = (message, messageToStoreRef) => {
6224
6350
  let previousWidgetData = lodash.isArray(messageToStoreRef.current.appendedData)
6225
6351
  ? messageToStoreRef.current.appendedData
6226
6352
  : [messageToStoreRef.current.appendedData];
6227
- messageToStoreRef.current.appendedData = [
6228
- ...previousWidgetData,
6229
- ...finalWidgetData,
6230
- ];
6353
+ // a surface sent again (placeholder, then the surface) replaces its widget in place
6354
+ messageToStoreRef.current.appendedData = mergeSurfaceWidgets(previousWidgetData, finalWidgetData);
6231
6355
  messageToStoreRef.current.sessionId = parsedData.session_id;
6232
6356
  messageToStoreRef.current.uniqueChatId = parsedData?.chat_id
6233
6357
  ? parsedData.chat_id
@@ -6267,10 +6391,8 @@ const sseevent = (message, messageToStoreRef) => {
6267
6391
  let previousWidgetData = lodash.isArray(messageToStoreRef.current.appendedData)
6268
6392
  ? messageToStoreRef.current.appendedData
6269
6393
  : [messageToStoreRef.current.appendedData];
6270
- messageToStoreRef.current.appendedData = [
6271
- ...previousWidgetData,
6272
- ...finalWidgetData,
6273
- ];
6394
+ // a surface sent again (placeholder, then the surface) replaces its widget in place
6395
+ messageToStoreRef.current.appendedData = mergeSurfaceWidgets(previousWidgetData, finalWidgetData);
6274
6396
  messageToStoreRef.current.additionalArgs = parsedData?.additional_args
6275
6397
  ? parsedData.additional_args
6276
6398
  : {};
@@ -9177,13 +9299,36 @@ const CheckboxGroupContent = ({ bodyText, isFormDisabled = false, messageIndex }
9177
9299
  const RadioContent = ({ bodyText, isFormDisabled = false, messageIndex }) => {
9178
9300
  const formKey = `${messageIndex}_${bodyText?.paramName}`;
9179
9301
  const classes = useStyles$b();
9180
- const { label, isDisabled, orientation, options } = bodyText;
9302
+ const { label, isDisabled, orientation, options, defaultSelected } = bodyText;
9181
9303
  const chatbotContext = reactRedux.useSelector((state) => state.smartBotReducer.chatbotContext);
9182
9304
  const chatbotContextRef = React.useRef(chatbotContext);
9183
9305
  chatbotContextRef.current = chatbotContext;
9184
9306
  const persistedFormValues = reactRedux.useSelector((state) => state.smartBotReducer.persistedFormValues);
9185
9307
  const dispatch = reactRedux.useDispatch();
9186
- const [selectedOption, setSelectedOption] = React.useState(persistedFormValues[formKey] ?? null);
9308
+ const [selectedOption, setSelectedOption] = React.useState(persistedFormValues[formKey] ?? defaultSelected ?? null);
9309
+ // When a defaultSelected value is provided and nothing was previously persisted,
9310
+ // seed Redux state so submit-validation and context are aware of the pre-selection.
9311
+ // Uses getState inside a thunk to read the latest chatbotContext at dispatch time,
9312
+ // avoiding stale-ref overwrites when multiple radio widgets mount in the same flush.
9313
+ React.useEffect(() => {
9314
+ if (defaultSelected && !persistedFormValues[formKey]) {
9315
+ dispatch((dispatchAction, getState) => {
9316
+ const currentContext = getState().smartBotReducer.chatbotContext;
9317
+ dispatchAction({
9318
+ type: "SET_CHATBOT_CONTEXT",
9319
+ payload: {
9320
+ ...currentContext,
9321
+ [bodyText?.paramName]: {
9322
+ ...currentContext?.[bodyText?.paramName],
9323
+ [bodyText?.paramName]: defaultSelected,
9324
+ updated: true,
9325
+ },
9326
+ },
9327
+ });
9328
+ });
9329
+ dispatch(setPersistedFormValues({ [formKey]: defaultSelected }));
9330
+ }
9331
+ }, []);
9187
9332
  if (lodash.isEmpty(bodyText))
9188
9333
  return null;
9189
9334
  const handleChange = (selectedOption) => {
@@ -9261,6 +9406,183 @@ const ImageContent = ({ bodyText }) => {
9261
9406
  } })), caption && (jsxRuntime.jsx("div", { children: jsxRuntime.jsx(TextRenderer, { text: caption }) }))] }));
9262
9407
  };
9263
9408
 
9409
+ const SUBMIT = { buttons: [{ label: "Submit", variant: "primary" }] };
9410
+ /** A follow-up's limits: longer ones are ignored. */
9411
+ const PROMPT_TEXT_MAX = 1000;
9412
+ const PROMPT_CONTEXT_MAX = 16000;
9413
+ /** The window event the chat listens to for a follow-up asked from a surface. */
9414
+ const PROMPT_EVENT = "iris:prompt";
9415
+ /** The source a surface names for this temp table, if it names it: the only tables its page may ask pages
9416
+ * of, and the endpoint address the agent gave (the page's own copy of the source is not trusted for it). */
9417
+ const sourceOf = (surface, table) => Object.values(surface?.data || {}).map((entry) => entry?.source).find((source) => typeof source?.table === "string" && source.table === table);
9418
+ /** Whether the surface binds this tool: the only tools its page may ask to read again. */
9419
+ const bindsTool = (surface, tool) => typeof tool === "string" && tool !== "rows" && Object.values(surface?.data || {}).some((entry) => entry?.tool === tool);
9420
+ const baseUrl = () => sessionStorage.getItem("stepForm_baseUrl") || "";
9421
+ /** One page of a source, from the agent's paging endpoint (its pages hold at most 10 rows): at the address
9422
+ * the agent gave, as TableContent does with temp_table_url, else under the stream's base URL. `search`: a
9423
+ * filter Control over the kept rows (catalog 0.3), each `{field, value}` an exact match the endpoint applies. */
9424
+ const pageOf = async ({ source, page, pageSize, sort, search }) => {
9425
+ const payload = {
9426
+ limit: { page, page_size: pageSize },
9427
+ search: (Array.isArray(search) ? search : [])
9428
+ .filter((s) => s && typeof s.field === "string" && s.value !== undefined && s.value !== null)
9429
+ .slice(0, 5)
9430
+ .map((s) => ({ column: s.field, pattern: String(s.value), search_type: "equals" })),
9431
+ sort: (Array.isArray(sort) ? sort : []).map((s) => ({ column: s.field, order: s.order === "desc" ? "desc" : "asc" })),
9432
+ };
9433
+ const response = source.url
9434
+ ? await getTableRecordsByUrl(payload, source.url)
9435
+ : await getTableRecords(payload, baseUrl(), source.table);
9436
+ const rows = response?.data?.data;
9437
+ const total = response?.data?.total_count;
9438
+ if (!Array.isArray(rows) || !Number.isFinite(total))
9439
+ throw new Error("no rows");
9440
+ return { rows, total };
9441
+ };
9442
+ /** A read tool the surface binds, run again by the agent with these arguments. */
9443
+ const readOf = async ({ surface, tool, args }) => {
9444
+ const response = await postUiQuery({ surface, tool, args: args && typeof args === "object" ? args : {} }, baseUrl());
9445
+ const rows = response?.data?.rows;
9446
+ const total = response?.data?.total;
9447
+ if (!Array.isArray(rows) || !Number.isFinite(total))
9448
+ throw new Error(response?.data?.error || "no rows");
9449
+ return { rows, total };
9450
+ };
9451
+ /** The page's origin, for http(s) addresses only; anything else is refused. */
9452
+ const frameOrigin = (src) => {
9453
+ try {
9454
+ const url = new URL(src, window.location.href);
9455
+ return url.protocol === "https:" || url.protocol === "http:" ? url.origin : null;
9456
+ }
9457
+ catch {
9458
+ return null;
9459
+ }
9460
+ };
9461
+ /** A follow-up within the limits, or null. */
9462
+ const promptOf = (data, surfaceId) => {
9463
+ const text = typeof data?.text === "string" ? data.text.trim() : "";
9464
+ const context = data?.context && typeof data.context === "object" ? { ...data.context, surface: surfaceId } : { surface: surfaceId };
9465
+ let size = Infinity;
9466
+ try {
9467
+ size = JSON.stringify(context).length;
9468
+ }
9469
+ catch {
9470
+ // a context that cannot be sent is not sent
9471
+ }
9472
+ if (!text || text.length > PROMPT_TEXT_MAX || size > PROMPT_CONTEXT_MAX)
9473
+ return null;
9474
+ return { text, uiContext: context };
9475
+ };
9476
+ const SurfaceFrameContent = ({ frame, isFormDisabled = false, messageIndex = 0 }) => {
9477
+ const dispatch = reactRedux.useDispatch();
9478
+ const chatbotContext = reactRedux.useSelector((state) => state.smartBotReducer.chatbotContext);
9479
+ const contextRef = React.useRef(chatbotContext);
9480
+ contextRef.current = chatbotContext;
9481
+ const iframeRef = React.useRef(null);
9482
+ const ready = React.useRef(false);
9483
+ const [height, setHeight] = React.useState(120);
9484
+ const [form, setForm] = React.useState({ values: {}, inputs: [], missing: [] });
9485
+ const formRef = React.useRef(form);
9486
+ formRef.current = form;
9487
+ const src = frame?.src;
9488
+ const incoming = frame?.surface;
9489
+ // the surface shown: a newer version of the same surface replaces it, a lower one is ignored
9490
+ const [surface, setSurface] = React.useState(incoming);
9491
+ React.useEffect(() => {
9492
+ if (incoming && (!surface || incoming.id !== surface.id || surfaceVersion(incoming) >= surfaceVersion(surface)))
9493
+ setSurface(incoming);
9494
+ }, [incoming]); // eslint-disable-line react-hooks/exhaustive-deps
9495
+ const origin = React.useMemo(() => frameOrigin(src), [src]);
9496
+ const ask = surface?.mode === "ask";
9497
+ // which version of its surface each widget shows, across the chat's messages
9498
+ const token = React.useRef(null);
9499
+ if (token.current === null)
9500
+ token.current = surfaceToken();
9501
+ const [, setShownChange] = React.useState(0);
9502
+ React.useEffect(() => watchSurfaces(() => setShownChange((n) => n + 1)), []);
9503
+ React.useEffect(() => {
9504
+ if (!surface?.id || surface.status === "pending" || surface.status === "withdrawn")
9505
+ return undefined;
9506
+ showSurface(surface.id, token.current, surfaceVersion(surface));
9507
+ return () => hideSurface(surface.id, token.current);
9508
+ }, [surface?.id, surface?.version, surface?.status]); // eslint-disable-line react-hooks/exhaustive-deps
9509
+ const send = (target, values) => target?.postMessage({ type: "iui:surface", surface, values, disabled: Boolean(isFormDisabled), query: true, ...(ask ? { submit: false } : {}) }, origin);
9510
+ React.useEffect(() => {
9511
+ if (!origin || !surface)
9512
+ return undefined;
9513
+ const onMessage = (event) => {
9514
+ const target = iframeRef.current?.contentWindow;
9515
+ if (!target || event.source !== target || event.origin !== origin)
9516
+ return;
9517
+ const data = event.data || {};
9518
+ // every message but iui:ready and iui:height names its surface: this widget answers for its own only
9519
+ const own = data.surface === undefined || data.surface === surface.id;
9520
+ if (data.type === "iui:ready") {
9521
+ ready.current = true;
9522
+ send(target, undefined);
9523
+ }
9524
+ else if (data.type === "iui:height" && Number.isFinite(data.height))
9525
+ setHeight(Math.max(40, Math.ceil(data.height)));
9526
+ else if (data.type === "iui:query" && own) {
9527
+ const reply = (body) => target.postMessage({ type: "iui:data", surface: surface.id, id: data.id, ...body }, origin);
9528
+ const args = data.args || {};
9529
+ if (data.tool === "rows") {
9530
+ const source = sourceOf(surface, args.source?.table);
9531
+ if (!source)
9532
+ reply({ error: "not a table of this answer" });
9533
+ else
9534
+ pageOf({ ...args, source }).then(reply, () => reply({ error: "the rows could not be loaded" }));
9535
+ }
9536
+ else if (bindsTool(surface, data.tool)) {
9537
+ readOf({ surface: surface.id, tool: data.tool, args }).then(reply, () => reply({ error: "the data could not be loaded" }));
9538
+ }
9539
+ else
9540
+ reply({ error: "not a tool of this answer" });
9541
+ }
9542
+ else if (data.type === "iui:prompt" && data.surface === surface.id) {
9543
+ const prompt = promptOf(data, surface.id);
9544
+ if (prompt)
9545
+ window.dispatchEvent(new CustomEvent(PROMPT_EVENT, { detail: prompt }));
9546
+ }
9547
+ else if (data.type === "iui:change" && ask && own) {
9548
+ const values = data.values || {};
9549
+ setForm({ values, inputs: Array.isArray(data.inputs) ? data.inputs : Object.keys(values), missing: Array.isArray(data.missing) ? data.missing : [] });
9550
+ // as this chat's own inputs record their values, for the step form's Submit (ButtonContent)
9551
+ const context = { ...contextRef.current };
9552
+ for (const [name, value] of Object.entries(values)) {
9553
+ const empty = value === "" || value === null || value === undefined || (Array.isArray(value) && value.length === 0);
9554
+ context[name] = { ...context[name], [name]: value, updated: !empty };
9555
+ }
9556
+ dispatch(setChatbotContext(context));
9557
+ // only what was filled in: ButtonContent sends a persisted value even when it is empty
9558
+ const filled = Object.entries(values).filter(([name]) => context[name].updated);
9559
+ dispatch(setPersistedFormValues(Object.fromEntries(filled.map(([name, value]) => [`${messageIndex}_${name}`, value]))));
9560
+ }
9561
+ // anything else: a message type this chat does not know, ignored
9562
+ };
9563
+ window.addEventListener("message", onMessage);
9564
+ return () => window.removeEventListener("message", onMessage);
9565
+ }, [origin, surface, isFormDisabled, ask, messageIndex]); // eslint-disable-line react-hooks/exhaustive-deps
9566
+ // a newer version of the surface goes into the page that shows it
9567
+ React.useEffect(() => {
9568
+ if (ready.current)
9569
+ send(iframeRef.current?.contentWindow, undefined);
9570
+ }, [surface]); // eslint-disable-line react-hooks/exhaustive-deps
9571
+ // a submitted form is posted again, disabled, with what was filled in
9572
+ React.useEffect(() => {
9573
+ if (isFormDisabled && ask)
9574
+ send(iframeRef.current?.contentWindow, formRef.current.values);
9575
+ }, [isFormDisabled]); // eslint-disable-line react-hooks/exhaustive-deps
9576
+ // a surface that will not come after all (its composition failed): nothing to draw
9577
+ if (!origin || !surface || surface.status === "withdrawn")
9578
+ return null;
9579
+ // a later message shows this surface revised: one line here, the surface there
9580
+ if (newerShown(surface.id, surfaceVersion(surface))) {
9581
+ 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}` : ""}.` }));
9582
+ }
9583
+ 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] }));
9584
+ };
9585
+
9264
9586
  // Key used to persist timeout state in sessionStorage (survives component remounts from tab switches)
9265
9587
  const STEP_FORM_TIMEOUT_KEY = "__stepFormTimedOut";
9266
9588
  /**
@@ -9690,11 +10012,17 @@ const StepFormContent = ({ formData, messageIndex = 0, isFormDisabled = false, s
9690
10012
  case "radio":
9691
10013
  return jsxRuntime.jsx(RadioContent, { bodyText: parsedData.bodyText, isFormDisabled: formFieldsDisabled, messageIndex: messageIndex }, key);
9692
10014
  case "button":
10015
+ // A form in the renderer page has its Submit drawn by SurfaceFrameContent, which knows the page's inputs
10016
+ if (formData.some((item) => item?.type === "surface_frame"))
10017
+ return null;
9693
10018
  return jsxRuntime.jsx(ButtonContent, { bodyText: parsedData.bodyText, isFormDisabled: isFormDisabled || isFormSubmitted || isTimedOut, isStepFormSubmit: true, isFormValid: requiredFieldsFilled && checkboxGroupsValid, formParamNames: formParamNames, messageIndex: messageIndex }, key);
9694
10019
  case "input":
9695
10020
  return jsxRuntime.jsx(InputContent, { bodyText: parsedData.bodyText, isFormDisabled: formFieldsDisabled, messageIndex: messageIndex }, key);
9696
10021
  case "image":
9697
10022
  return jsxRuntime.jsx(ImageContent, { bodyText: parsedData.bodyText }, key);
10023
+ case "surface_frame":
10024
+ // The whole form in the renderer page; the widget draws this form's Submit (its inputs are in the page)
10025
+ return jsxRuntime.jsx(SurfaceFrameContent, { frame: parsedData.bodyText, isFormDisabled: isFormDisabled || isFormSubmitted || isTimedOut, messageIndex: messageIndex }, parsedData.bodyText?.surface?.id || key);
9698
10026
  default:
9699
10027
  return null;
9700
10028
  }
@@ -10090,7 +10418,7 @@ const ProgressBarItem$1 = ({ question, questionSteps, isLast, classes, formData,
10090
10418
  const [isExpanded, setIsExpanded] = React.useState(true);
10091
10419
  const dotClass = status === "completed"
10092
10420
  ? "completed"
10093
- : status === "in-progress"
10421
+ : status === "in-progress" || status === "not-started"
10094
10422
  ? "in-progress"
10095
10423
  : status === "error"
10096
10424
  ? "error"
@@ -10211,6 +10539,479 @@ const Steps$1 = ({ steps, setSteps, done, setTabValue, setDone, finalStepDone, s
10211
10539
  }, children: jsxRuntime.jsx(ProgressBarItem$1, { question: "Thinking", questionSteps: [{ header: "", sub_header: "", step_status: "not-completed" }], isLast: true, classes: classes, formData: null, isFormDisabled: isFormDisabled }) }))] }));
10212
10540
  };
10213
10541
 
10542
+ const useAllocationPanelStyles = styles.makeStyles((theme) => ({
10543
+ // AllocationPlanCard styles (inside chatbot)
10544
+ planCard: {
10545
+ border: "1.5px solid #e2e8f0",
10546
+ borderRadius: "14px",
10547
+ padding: "14px 16px",
10548
+ display: "flex",
10549
+ alignItems: "center",
10550
+ gap: "14px",
10551
+ cursor: "pointer",
10552
+ position: "relative",
10553
+ overflow: "hidden",
10554
+ transition: "border-color 0.25s ease, box-shadow 0.25s ease, background 0.25s ease",
10555
+ background: "#fafbff",
10556
+ "&:hover": {
10557
+ borderColor: "#b4beff",
10558
+ boxShadow: "0 2px 12px rgba(66, 89, 238, 0.10)",
10559
+ background: "linear-gradient(135deg, #f5f7ff 0%, #eef1ff 60%, #e8ecff 100%)",
10560
+ },
10561
+ },
10562
+ planCardIcon: {
10563
+ width: "48px",
10564
+ height: "48px",
10565
+ borderRadius: "12px",
10566
+ background: "linear-gradient(135deg, #e8edff 0%, #dbe1ff 100%)",
10567
+ display: "flex",
10568
+ alignItems: "center",
10569
+ justifyContent: "center",
10570
+ flexShrink: 0,
10571
+ "& svg": {
10572
+ color: "#4259EE",
10573
+ fontSize: "22px",
10574
+ },
10575
+ },
10576
+ planCardContent: {
10577
+ flex: 1,
10578
+ minWidth: 0,
10579
+ },
10580
+ planCardTitle: {
10581
+ fontSize: "14px",
10582
+ fontWeight: 700,
10583
+ color: "#1e293b",
10584
+ lineHeight: 1.4,
10585
+ marginBottom: "4px",
10586
+ },
10587
+ planCardLinks: {
10588
+ display: "flex",
10589
+ alignItems: "center",
10590
+ gap: "4px",
10591
+ flexWrap: "wrap",
10592
+ fontSize: "13px",
10593
+ color: "#64748b",
10594
+ },
10595
+ planCardLink: {
10596
+ color: "#64748b",
10597
+ cursor: "pointer",
10598
+ textDecoration: "none",
10599
+ transition: "color 0.2s ease",
10600
+ "&:hover": {
10601
+ color: "#4259EE",
10602
+ },
10603
+ },
10604
+ planCardLinkSeparator: {
10605
+ color: "#94a3b8",
10606
+ margin: "0 3px",
10607
+ },
10608
+ planCardOpenIcon: {
10609
+ flexShrink: 0,
10610
+ color: "#94a3b8",
10611
+ fontSize: "20px !important",
10612
+ padding: "6px",
10613
+ borderRadius: "8px",
10614
+ border: "1px solid #e2e8f0",
10615
+ background: "#ffffff",
10616
+ transition: "border-color 0.25s ease, color 0.25s ease",
10617
+ "$planCard:hover &": {
10618
+ borderColor: "#b4beff",
10619
+ color: "#4259EE",
10620
+ },
10621
+ },
10622
+
10623
+ // PanelHeader styles
10624
+ panelHeader: {
10625
+ display: "flex",
10626
+ alignItems: "center",
10627
+ justifyContent: "space-between",
10628
+ padding: "16px",
10629
+ borderBottom: "1px solid #f0f0f0",
10630
+ flexShrink: 0,
10631
+ },
10632
+ panelHeaderLeft: {
10633
+ display: "flex",
10634
+ alignItems: "center",
10635
+ gap: "8px",
10636
+ flex: 1,
10637
+ minWidth: 0,
10638
+ },
10639
+ panelHeaderIcon: {
10640
+ color: "#666",
10641
+ fontSize: "20px",
10642
+ cursor: "pointer",
10643
+ },
10644
+ panelTitle: {
10645
+ fontSize: "14px",
10646
+ fontWeight: 600,
10647
+ color: "#1a1a1a",
10648
+ lineHeight: 1.4,
10649
+ overflow: "hidden",
10650
+ textOverflow: "ellipsis",
10651
+ whiteSpace: "nowrap",
10652
+ },
10653
+ panelHeaderActions: {
10654
+ display: "flex",
10655
+ alignItems: "center",
10656
+ gap: "6px",
10657
+ flexShrink: 0,
10658
+ },
10659
+ panelHeaderActionBtn: {
10660
+ width: "28px !important",
10661
+ height: "28px !important",
10662
+ borderRadius: "8px !important",
10663
+ background: "#f1f5f9 !important",
10664
+ color: "#475569 !important",
10665
+ padding: "0 !important",
10666
+ "&:hover": {
10667
+ background: "#e2e8f0 !important",
10668
+ color: "#1e293b !important",
10669
+ },
10670
+ },
10671
+
10672
+ // ReportSummaryCard styles
10673
+ reportSummaryCard: {
10674
+ border: "1px solid #f0c36d",
10675
+ borderRadius: "8px",
10676
+ padding: "14px",
10677
+ margin: "16px 0",
10678
+ background: "#fffdf5",
10679
+ },
10680
+ reportBadge: {
10681
+ display: "inline-block",
10682
+ fontSize: "11px",
10683
+ fontWeight: 500,
10684
+ padding: "3px 8px",
10685
+ borderRadius: "4px",
10686
+ marginBottom: "8px",
10687
+ border: "1px solid #f0c36d",
10688
+ color: "#8b6914",
10689
+ background: "transparent",
10690
+ },
10691
+ reportDescription: {
10692
+ fontSize: "12px",
10693
+ lineHeight: 1.6,
10694
+ color: "#333",
10695
+ marginBottom: "10px",
10696
+ },
10697
+ baselinePlanRow: {
10698
+ fontSize: "12px",
10699
+ color: "#666",
10700
+ display: "flex",
10701
+ alignItems: "center",
10702
+ gap: "4px",
10703
+ },
10704
+ baselinePlanLink: {
10705
+ color: "#2563eb",
10706
+ textDecoration: "underline",
10707
+ cursor: "pointer",
10708
+ wordBreak: "break-all",
10709
+ },
10710
+
10711
+ // PanelSection (Accordion) styles
10712
+ sectionAccordion: {
10713
+ boxShadow: "none !important",
10714
+ border: "none !important",
10715
+ borderRadius: "12px !important",
10716
+ marginBottom: "10px !important",
10717
+ background: "#f8fafc !important",
10718
+ "&:before": {
10719
+ display: "none !important",
10720
+ content: "none !important",
10721
+ background: "none !important",
10722
+ width: "0 !important",
10723
+ height: "0 !important",
10724
+ },
10725
+ "&.Mui-expanded": {
10726
+ margin: "0 0 10px 0 !important",
10727
+ background: "#ffffff !important",
10728
+ boxShadow: "0 1px 8px rgba(0, 0, 0, 0.06) !important",
10729
+ border: "1px solid #e2e8f0 !important",
10730
+ },
10731
+ },
10732
+ sectionSummary: {
10733
+ minHeight: "48px !important",
10734
+ padding: "0 16px !important",
10735
+ border: "none !important",
10736
+ flexDirection: "row-reverse !important",
10737
+ gap: "10px",
10738
+ "&:before": {
10739
+ display: "none !important",
10740
+ content: "none !important",
10741
+ background: "none !important",
10742
+ width: "0 !important",
10743
+ height: "0 !important",
10744
+ },
10745
+ "& .MuiAccordionSummary-content": {
10746
+ margin: "12px 0 !important",
10747
+ },
10748
+ "& .MuiAccordionSummary-expandIconWrapper": {
10749
+ color: "#64748b",
10750
+ transform: "rotate(-90deg)",
10751
+ padding: "0 !important",
10752
+ marginRight: "0 !important",
10753
+ "&.Mui-expanded": {
10754
+ transform: "rotate(0deg)",
10755
+ },
10756
+ },
10757
+ },
10758
+ sectionTitle: {
10759
+ fontSize: "14px",
10760
+ fontWeight: 600,
10761
+ color: "#1e293b",
10762
+ },
10763
+ sectionDetails: {
10764
+ padding: "0 16px 16px !important",
10765
+ border: "none !important",
10766
+ "&:before": {
10767
+ display: "none !important",
10768
+ content: "none !important",
10769
+ background: "none !important",
10770
+ width: "0 !important",
10771
+ height: "0 !important",
10772
+ },
10773
+ },
10774
+
10775
+ // StructuredComparison styles
10776
+ comparisonSubtitle: {
10777
+ fontSize: "12px",
10778
+ color: "#666",
10779
+ marginBottom: "12px",
10780
+ lineHeight: 1.5,
10781
+ },
10782
+ scenarioLabel: {
10783
+ fontSize: "12px",
10784
+ fontWeight: 500,
10785
+ color: "#1a1a1a",
10786
+ padding: "8px 12px",
10787
+ background: "#f8f9fa",
10788
+ borderRadius: "6px",
10789
+ marginBottom: "12px",
10790
+ },
10791
+ comparisonCard: {
10792
+ background: "#f8f9fa",
10793
+ borderRadius: "8px",
10794
+ padding: "12px",
10795
+ marginBottom: "10px",
10796
+ },
10797
+ comparisonParamRow: {
10798
+ display: "flex",
10799
+ alignItems: "center",
10800
+ gap: "8px",
10801
+ marginBottom: "10px",
10802
+ },
10803
+ comparisonParamName: {
10804
+ fontSize: "13px",
10805
+ fontWeight: 600,
10806
+ color: "#1a1a1a",
10807
+ },
10808
+ comparisonTag: {
10809
+ display: "inline-block",
10810
+ fontSize: "10px",
10811
+ fontWeight: 500,
10812
+ padding: "2px 6px",
10813
+ borderRadius: "4px",
10814
+ color: "#2563eb",
10815
+ border: "1px solid #bfdbfe",
10816
+ background: "#eff6ff",
10817
+ },
10818
+ comparisonValues: {
10819
+ display: "flex",
10820
+ alignItems: "center",
10821
+ gap: "8px",
10822
+ },
10823
+ comparisonValueBox: {
10824
+ flex: 1,
10825
+ background: theme.palette.common.white,
10826
+ borderRadius: "6px",
10827
+ padding: "8px 10px",
10828
+ border: "1px solid #e8e8e8",
10829
+ },
10830
+ comparisonValueLabel: {
10831
+ fontSize: "10px",
10832
+ color: "#999",
10833
+ marginBottom: "2px",
10834
+ },
10835
+ comparisonValueText: {
10836
+ fontSize: "12px",
10837
+ fontWeight: 600,
10838
+ color: "#1a1a1a",
10839
+ },
10840
+ comparisonArrow: {
10841
+ color: "#999",
10842
+ fontSize: "16px",
10843
+ flexShrink: 0,
10844
+ },
10845
+
10846
+ // Panel-specific HTML content wrapper (font size/line-height for panel context)
10847
+ panelHtmlContainer: {
10848
+ fontSize: "12px",
10849
+ lineHeight: 1.6,
10850
+ },
10851
+
10852
+ // Slide-in keyframes for panel entry
10853
+ "@keyframes panelSlideIn": {
10854
+ "0%": {
10855
+ transform: "translateX(100%)",
10856
+ opacity: 0,
10857
+ },
10858
+ "100%": {
10859
+ transform: "translateX(0)",
10860
+ opacity: 1,
10861
+ },
10862
+ },
10863
+ // AllocationDetailPanel container (portaled)
10864
+ panelContainer: {
10865
+ position: "fixed",
10866
+ top: 56,
10867
+ right: 0,
10868
+ width: "calc(50vw - 32px)",
10869
+ maxWidth: "520px",
10870
+ height: "calc(100vh - 56px)",
10871
+ zIndex: 99999,
10872
+ display: "flex",
10873
+ flexDirection: "column",
10874
+ background: "#ffffff",
10875
+ boxShadow: "-4px 0 16px rgba(0, 0, 0, 0.15)",
10876
+ borderLeft: "1px solid #e8e8e8",
10877
+ borderRadius: "12px 0 0 12px",
10878
+ overflow: "hidden",
10879
+ animation: "$panelSlideIn 0.3s ease forwards",
10880
+ transition: "width 0.3s ease, max-width 0.3s ease, border-radius 0.3s ease",
10881
+ },
10882
+ // Expanded / maximized panel — covers the chatbot area too
10883
+ panelExpanded: {
10884
+ width: "calc(100vw - 4rem)",
10885
+ maxWidth: "calc(100vw - 4rem)",
10886
+ borderRadius: "0",
10887
+ },
10888
+ panelScrollBody: {
10889
+ flex: 1,
10890
+ overflowY: "auto",
10891
+ padding: "0 16px 24px",
10892
+ },
10893
+
10894
+ // Footer
10895
+ panelFooter: {
10896
+ display: "flex",
10897
+ justifyContent: "flex-end",
10898
+ alignItems: "center",
10899
+ gap: "10px",
10900
+ padding: "12px 16px",
10901
+ borderTop: "1px solid #e2e8f0",
10902
+ background: "#ffffff",
10903
+ flexShrink: 0,
10904
+ position: "relative",
10905
+ },
10906
+ footerBtnOutlined: {
10907
+ display: "inline-flex",
10908
+ alignItems: "center",
10909
+ justifyContent: "center",
10910
+ height: "32px",
10911
+ padding: "0 12px",
10912
+ fontSize: "14px",
10913
+ fontWeight: 600,
10914
+ fontFamily: "Manrope, sans-serif",
10915
+ lineHeight: 1,
10916
+ borderRadius: "8px",
10917
+ border: "1px solid #d1d5db",
10918
+ background: "#ffffff",
10919
+ color: "#1e293b",
10920
+ cursor: "pointer",
10921
+ textTransform: "none",
10922
+ },
10923
+ footerBtnPrimary: {
10924
+ display: "inline-flex",
10925
+ alignItems: "center",
10926
+ justifyContent: "center",
10927
+ height: "32px",
10928
+ padding: "0 12px",
10929
+ fontSize: "14px",
10930
+ fontWeight: 600,
10931
+ fontFamily: "Manrope, sans-serif",
10932
+ lineHeight: 1,
10933
+ borderRadius: "8px",
10934
+ border: "1px solid #4259EE",
10935
+ background: "#4259EE",
10936
+ color: "#ffffff",
10937
+ cursor: "pointer",
10938
+ textTransform: "none",
10939
+ },
10940
+
10941
+ // Footer options popover
10942
+ optionsCard: {
10943
+ position: "absolute",
10944
+ bottom: "100%",
10945
+ right: 0,
10946
+ marginBottom: "8px",
10947
+ background: "#ffffff",
10948
+ borderRadius: "12px",
10949
+ boxShadow: "0 4px 20px rgba(0, 0, 0, 0.12)",
10950
+ border: "1px solid #e2e8f0",
10951
+ padding: "8px",
10952
+ minWidth: "280px",
10953
+ zIndex: 1,
10954
+ },
10955
+ optionRow: {
10956
+ display: "flex",
10957
+ alignItems: "center",
10958
+ gap: "10px",
10959
+ padding: "10px 12px",
10960
+ borderRadius: "8px",
10961
+ cursor: "pointer",
10962
+ fontSize: "13px",
10963
+ fontWeight: 500,
10964
+ color: "#1e293b",
10965
+ background: "#f8fafc",
10966
+ marginBottom: "4px",
10967
+ border: "none",
10968
+ width: "100%",
10969
+ textAlign: "left",
10970
+ fontFamily: "Manrope, sans-serif",
10971
+ "&:hover": {
10972
+ background: "#eef2ff",
10973
+ },
10974
+ "&:last-child": {
10975
+ marginBottom: 0,
10976
+ },
10977
+ },
10978
+ optionIcon: {
10979
+ color: "#6366f1",
10980
+ fontSize: "16px",
10981
+ },
10982
+ }));
10983
+
10984
+ const AllocationPlanCard = ({ bodyText }) => {
10985
+ const classes = useAllocationPanelStyles();
10986
+ const title = bodyText?.title || "Allocation Plan";
10987
+ const links = bodyText?.links || [];
10988
+ const panelData = bodyText?.panel_data || null;
10989
+ const handleCardClick = (target) => {
10990
+ if (!panelData)
10991
+ return;
10992
+ const openPanel = () => {
10993
+ window.dispatchEvent(new CustomEvent("openAllocationDetailPanel", {
10994
+ detail: { panelData, activeSection: target || null },
10995
+ }));
10996
+ };
10997
+ // Check if the chatbot is in a collapsed/minimized state by looking for
10998
+ // the "Expand chatbot" button (present only when collapsed)
10999
+ const expandBtn = document.querySelector('button[aria-label="Expand chatbot"]');
11000
+ if (expandBtn) {
11001
+ // Maximize first, then open the panel after chatbot finishes expanding
11002
+ window.dispatchEvent(new CustomEvent("smartBotMaximize"));
11003
+ setTimeout(openPanel, 350);
11004
+ }
11005
+ else {
11006
+ openPanel();
11007
+ }
11008
+ };
11009
+ return (jsxRuntime.jsxs("div", { className: classes.planCard, onClick: () => handleCardClick(links[0]?.target), children: [jsxRuntime.jsx("div", { className: classes.planCardIcon, children: jsxRuntime.jsx(DescriptionOutlinedIcon, {}) }), jsxRuntime.jsxs("div", { className: classes.planCardContent, children: [jsxRuntime.jsx("div", { className: classes.planCardTitle, children: title }), jsxRuntime.jsx("div", { className: classes.planCardLinks, children: links.map((link, index) => (jsxRuntime.jsxs("span", { children: [index > 0 && (jsxRuntime.jsx("span", { className: classes.planCardLinkSeparator, children: "\u00B7" })), jsxRuntime.jsx("span", { className: classes.planCardLink, onClick: (e) => {
11010
+ e.stopPropagation();
11011
+ handleCardClick(link.target);
11012
+ }, children: link.label })] }, link.target || index))) })] }), jsxRuntime.jsx(OpenInNewIcon, { className: classes.planCardOpenIcon })] }));
11013
+ };
11014
+
10214
11015
  const renderWidgetItem = (item, index, isFormDisabled) => {
10215
11016
  try {
10216
11017
  const parsedData = parseResponse(item, item.type, "", "", true);
@@ -10247,6 +11048,10 @@ const renderWidgetItem = (item, index, isFormDisabled) => {
10247
11048
  return jsxRuntime.jsx(DateRangePickerContent, { bodyText: parsedData.bodyText, isFormDisabled: isFormDisabled }, key);
10248
11049
  case "html":
10249
11050
  return jsxRuntime.jsx(HtmlContent, { bodyText: parsedData.bodyText }, key);
11051
+ case "surface_frame":
11052
+ return jsxRuntime.jsx(SurfaceFrameContent, { frame: parsedData.bodyText }, parsedData.bodyText?.surface?.id || key);
11053
+ case "allocation_plan_card":
11054
+ return jsxRuntime.jsx(AllocationPlanCard, { bodyText: parsedData.bodyText }, key);
10250
11055
  default:
10251
11056
  return null;
10252
11057
  }
@@ -11119,7 +11924,8 @@ const StreamedContent = ({ botData, botProps }) => {
11119
11924
  const widgetItems = isArray(data.widget_data)
11120
11925
  ? data.widget_data
11121
11926
  : [data.widget_data];
11122
- setStreamingWidgetData((prev) => [...prev, ...widgetItems]);
11927
+ // a surface sent again (placeholder, then the surface) replaces its widget in place
11928
+ setStreamingWidgetData((prev) => mergeSurfaceWidgets(prev, widgetItems));
11123
11929
  }
11124
11930
  else if (data.message !== "[DONE]") {
11125
11931
  if (!thinkingDoneRef?.current && currentMode === "agent") {
@@ -12289,6 +13095,8 @@ const TabularContent = ({ steps: initialSteps, currentTabValue, children, questi
12289
13095
  return jsxRuntime.jsx(TableContent, { bodyText: parsedData.bodyText }, parsedData.bodyText?.table_name || key);
12290
13096
  case "graph":
12291
13097
  return jsxRuntime.jsx(GraphContent, { bodyText: parsedData.bodyText }, key);
13098
+ case "surface_frame":
13099
+ return jsxRuntime.jsx(SurfaceFrameContent, { frame: parsedData.bodyText }, parsedData.bodyText?.surface?.id || key);
12292
13100
  case "radio":
12293
13101
  return jsxRuntime.jsx(RadioContent, { bodyText: parsedData.bodyText, isFormDisabled: isFormDisabled }, key);
12294
13102
  case "checkbox":
@@ -12368,7 +13176,8 @@ const TabularContent = ({ steps: initialSteps, currentTabValue, children, questi
12368
13176
  }
12369
13177
  });
12370
13178
  if (newWidgets.length > 0) {
12371
- setWidgetContent((prev) => [...prev, ...newWidgets]);
13179
+ // a surface sent again (placeholder, then the surface) replaces its widget in place
13180
+ setWidgetContent((prev) => mergeSurfaceWidgets(prev, newWidgets));
12372
13181
  }
12373
13182
  return;
12374
13183
  }
@@ -12499,7 +13308,7 @@ const TabularContent = ({ steps: initialSteps, currentTabValue, children, questi
12499
13308
  let newQuestions = [...questionsRef.current];
12500
13309
  let newQuestionsStepsMap = lodash.cloneDeep(questionsStepsMapRef.current);
12501
13310
  let newStepFormDataMap = lodash.cloneDeep(stepFormDataMapRef.current);
12502
- const newWidgets = [];
13311
+ let newWidgets = [];
12503
13312
  chunks.forEach((data) => {
12504
13313
  if (data.status === "questions") {
12505
13314
  const incomingQuestions = data.widget_data?.[0]?.questions || [];
@@ -12596,10 +13405,8 @@ const TabularContent = ({ steps: initialSteps, currentTabValue, children, questi
12596
13405
  }
12597
13406
  if (data.status === "widget") {
12598
13407
  const widgetItems = isArray$1(data.widget_data) ? data.widget_data : [data.widget_data];
12599
- widgetItems.forEach((item) => {
12600
- if (item)
12601
- newWidgets.push(item);
12602
- });
13408
+ // a surface sent again (placeholder, then the surface) replaces its widget in place
13409
+ newWidgets = mergeSurfaceWidgets(newWidgets, widgetItems.filter(Boolean));
12603
13410
  }
12604
13411
  if (data.status === "content" && data.message) {
12605
13412
  newWidgets.push({ type: "text", response: data.message });
@@ -12726,6 +13533,10 @@ const CombinedContent = ({ botData, props }) => {
12726
13533
  return jsxRuntime.jsx(ImageContent, { bodyText: parsedData.bodyText }, key);
12727
13534
  case "html":
12728
13535
  return jsxRuntime.jsx(HtmlContent, { bodyText: parsedData.bodyText }, key);
13536
+ case "surface_frame":
13537
+ return jsxRuntime.jsx(SurfaceFrameContent, { frame: parsedData.bodyText }, parsedData.bodyText?.surface?.id || key);
13538
+ case "allocation_plan_card":
13539
+ return jsxRuntime.jsx(AllocationPlanCard, { bodyText: parsedData.bodyText }, key);
12729
13540
  default:
12730
13541
  return null;
12731
13542
  }
@@ -12804,6 +13615,8 @@ const BotMessage = ({ botData, state, handleLikeDislike, props }) => {
12804
13615
  return jsxRuntime.jsx(TableContent, { bodyText: botData.bodyText });
12805
13616
  case "graph":
12806
13617
  return jsxRuntime.jsx(GraphContent, { bodyText: botData.bodyText });
13618
+ case "surface_frame":
13619
+ return jsxRuntime.jsx(SurfaceFrameContent, { frame: botData.bodyText });
12807
13620
  case "slider":
12808
13621
  return jsxRuntime.jsx(SliderContent, { bodyText: botData.bodyText, isFormDisabled: botData.isFormDisabled, messageIndex: botData.messageIndex });
12809
13622
  case "select":
@@ -12826,6 +13639,8 @@ const BotMessage = ({ botData, state, handleLikeDislike, props }) => {
12826
13639
  return jsxRuntime.jsx(ImageContent, { bodyText: botData.bodyText });
12827
13640
  case "html":
12828
13641
  return jsxRuntime.jsx(HtmlContent, { bodyText: botData.bodyText });
13642
+ case "allocation_plan_card":
13643
+ return jsxRuntime.jsx(AllocationPlanCard, { bodyText: botData.bodyText });
12829
13644
  case "combined":
12830
13645
  return jsxRuntime.jsx(CombinedContent, { botData: botData, props: props });
12831
13646
  case "dynamic":
@@ -14423,6 +15238,7 @@ const ChatbotInput = (props) => {
14423
15238
  const isTransitioningStageRef = React.useRef(false);
14424
15239
  const shouldClearCacheRef = React.useRef(false);
14425
15240
  const allFilterValuesRef = React.useRef([]);
15241
+ const initialValueOptionsRef = React.useRef([]);
14426
15242
  const windowStartRef = React.useRef(0);
14427
15243
  const INITIAL_DISPLAY_COUNT = 500;
14428
15244
  const LOAD_MORE_COUNT = 100;
@@ -14967,6 +15783,7 @@ const ChatbotInput = (props) => {
14967
15783
  setSelectionStage("values");
14968
15784
  setSelectedFilter(filterConfig);
14969
15785
  setCurrentOptions([]);
15786
+ initialValueOptionsRef.current = [];
14970
15787
  setSelectedOptions([]);
14971
15788
  setShowMentionSelect(true);
14972
15789
  setIsSelectOpen(true);
@@ -14996,10 +15813,13 @@ const ChatbotInput = (props) => {
14996
15813
  windowStartRef.current = 0;
14997
15814
  if (allValues.length > 2000) {
14998
15815
  allFilterValuesRef.current = allValues;
14999
- setCurrentOptions(allValues.slice(0, INITIAL_DISPLAY_COUNT));
15816
+ const initialSlice = allValues.slice(0, INITIAL_DISPLAY_COUNT);
15817
+ initialValueOptionsRef.current = initialSlice;
15818
+ setCurrentOptions(initialSlice);
15000
15819
  }
15001
15820
  else {
15002
15821
  allFilterValuesRef.current = [];
15822
+ initialValueOptionsRef.current = allValues;
15003
15823
  setCurrentOptions(allValues);
15004
15824
  }
15005
15825
  // Update dropdown position again after values are loaded (DOM might have shifted)
@@ -15752,7 +16572,7 @@ const ChatbotInput = (props) => {
15752
16572
  zIndex: 10000,
15753
16573
  }, children: selectionStage === "filter" ? (
15754
16574
  // Stage 1: Filter selection - always use Select
15755
- jsxRuntime.jsx(impactUiV3.Select, { currentOptions: currentOptions.length > 0 ? currentOptions : [], setCurrentOptions: setCurrentOptions, initialOptions: currentOptions.length > 0 ? currentOptions : [], placeholder: "Select a filter...", handleChange: handleMentionSelect, isOpen: isSelectOpen, setIsOpen: setIsSelectOpen, selectedOptions: selectedOptions, setSelectedOptions: setSelectedOptions, isCloseWhenClickOutside: false, isWithSearch: true, isMulti: false, disabled: false, isLoading: false, emptyMessage: "No filters available" })) : selectionStage === "values" && selectedFilter?.display_type &&
16575
+ jsxRuntime.jsx(impactUiV3.Select, { currentOptions: currentOptions.length > 0 ? currentOptions : [], setCurrentOptions: setCurrentOptions, initialOptions: formattedFilterOptions.length > 0 ? formattedFilterOptions : [], placeholder: "Select a filter...", handleChange: handleMentionSelect, isOpen: isSelectOpen, setIsOpen: setIsSelectOpen, selectedOptions: selectedOptions, setSelectedOptions: setSelectedOptions, isCloseWhenClickOutside: false, isWithSearch: true, isMulti: false, disabled: false, isLoading: false, emptyMessage: "No filters available" })) : selectionStage === "values" && selectedFilter?.display_type &&
15756
16576
  selectedFilter.display_type !== "dropdown" &&
15757
16577
  selectedFilter.display_type !== "autocompleteDropdown" &&
15758
16578
  selectedFilter.display_type !== "list" ? (
@@ -15839,7 +16659,7 @@ const ChatbotInput = (props) => {
15839
16659
  cursor: "pointer"
15840
16660
  }, children: "Cancel" })] })] })) : (
15841
16661
  // Stage 2: Value selection with dropdown - use Select
15842
- jsxRuntime.jsx(impactUiV3.Select, { currentOptions: currentOptions.length > 0 ? currentOptions : [], setCurrentOptions: setCurrentOptions, initialOptions: currentOptions.length > 0 ? currentOptions : [], placeholder: isLoadingValues
16662
+ jsxRuntime.jsx(impactUiV3.Select, { currentOptions: currentOptions.length > 0 ? currentOptions : [], setCurrentOptions: setCurrentOptions, initialOptions: initialValueOptionsRef.current.length > 0 ? initialValueOptionsRef.current : currentOptions, placeholder: isLoadingValues
15843
16663
  ? "Loading values..."
15844
16664
  : "Select values...", handleChange: handleMentionSelect, isOpen: isSelectOpen, setIsOpen: setIsSelectOpen, selectedOptions: selectedOptions, setSelectedOptions: setSelectedOptions, isCloseWhenClickOutside: false, isWithSearch: true, onMenuScrollToBottom: () => {
15845
16665
  const allValues = allFilterValuesRef.current;
@@ -16994,6 +17814,146 @@ const MinimizedChatWidget = ({ onExpand }) => {
16994
17814
  return (jsxRuntime.jsxs("div", { className: classes.widgetContainer, onClick: handleExpandClick, children: [jsxRuntime.jsxs("div", { className: classes.widgetHeader, children: [jsxRuntime.jsxs("div", { className: classes.headerLeft, children: [jsxRuntime.jsx("div", { className: !isCompleted ? classes.headerIconLogoSpin : classes.headerIconLogo, children: jsxRuntime.jsx(SvgMimimizedIconLogo, {}) }), jsxRuntime.jsx("span", { className: classes.headerText, children: isCompleted ? "Action completed" : actionLabel }), !isCompleted && (jsxRuntime.jsx("div", { className: classes.warningIcon, children: jsxRuntime.jsx(SvgStepError, {}) }))] }), jsxRuntime.jsx("button", { className: classes.minimizeBtn, onClick: handleMinimizeClick, "aria-label": "Minimize", children: jsxRuntime.jsx(SvgMinimizeDashIcon, {}) })] }), jsxRuntime.jsx("div", { className: classes.widgetContent, children: jsxRuntime.jsxs("div", { className: stepStatus === "step_form" ? classes.innerContentStepForm : classes.innerContent, children: [jsxRuntime.jsxs("div", { className: classes.innerFirstRow, children: [jsxRuntime.jsx("span", { className: classes.stepHeaderText, title: stepHeader, children: stepHeader }), jsxRuntime.jsx("button", { className: classes.expandBtn, onClick: handleExpandClick, "aria-label": "Expand chatbot", children: jsxRuntime.jsx(SvgExpandFullscreenIcon, {}) })] }), stepSubHeader && (jsxRuntime.jsxs("div", { className: classes.innerSecondRow, children: [jsxRuntime.jsxs("div", { className: stepStatus === "step_form" ? classes.subHeaderPillStepForm : classes.subHeaderPill, children: [stepStatus === "step_form" ? (jsxRuntime.jsx("div", { className: classes.exclamationIcon, children: jsxRuntime.jsx(SvgExclamationIcon, {}) })) : !isCompleted && (jsxRuntime.jsx("div", { className: classes.loaderIcon, children: jsxRuntime.jsx(SvgLoadingCircle, {}) })), jsxRuntime.jsx("span", { className: classes.subHeaderText, title: stepSubHeader, children: stepSubHeader })] }), elapsedTime && (jsxRuntime.jsx("span", { className: classes.timeText, children: elapsedTime }))] }))] }) })] }));
16995
17815
  };
16996
17816
 
17817
+ const PanelHeader = ({ title, actions = {}, onClose, isExpanded, onToggleExpand }) => {
17818
+ const classes = useAllocationPanelStyles();
17819
+ return (jsxRuntime.jsxs("div", { className: classes.panelHeader, children: [jsxRuntime.jsxs("div", { className: classes.panelHeaderLeft, children: [actions.preview && (jsxRuntime.jsx(VisibilityOutlinedIcon, { className: classes.panelHeaderIcon })), jsxRuntime.jsx("span", { className: classes.panelTitle, title: title, children: title })] }), jsxRuntime.jsxs("div", { className: classes.panelHeaderActions, children: [actions.expand_fullscreen && (jsxRuntime.jsx(material.IconButton, { className: classes.panelHeaderActionBtn, size: "small", onClick: onToggleExpand, children: isExpanded ? (jsxRuntime.jsx(CloseFullscreenIcon, { sx: { fontSize: 16 } })) : (jsxRuntime.jsx(OpenInFullIcon, { sx: { fontSize: 16 } })) })), jsxRuntime.jsx(material.IconButton, { className: classes.panelHeaderActionBtn, size: "small", onClick: onClose, children: jsxRuntime.jsx(CloseIcon, { sx: { fontSize: 16 } }) })] })] }));
17820
+ };
17821
+
17822
+ const ReportSummaryCard = ({ reportSummary }) => {
17823
+ const classes = useAllocationPanelStyles();
17824
+ if (!reportSummary)
17825
+ return null;
17826
+ const { badge, description, baseline_plan } = reportSummary;
17827
+ return (jsxRuntime.jsxs("div", { className: classes.reportSummaryCard, children: [badge && (jsxRuntime.jsx("span", { className: classes.reportBadge, children: badge.label })), description && (jsxRuntime.jsx("div", { className: classes.reportDescription, children: description })), baseline_plan && (jsxRuntime.jsxs("div", { className: classes.baselinePlanRow, children: [jsxRuntime.jsxs("span", { children: [baseline_plan.label, ":"] }), baseline_plan.link_url ? (jsxRuntime.jsx("span", { className: classes.baselinePlanLink, onClick: () => {
17828
+ if (baseline_plan.link_url) {
17829
+ window.open(baseline_plan.link_url, "_blank");
17830
+ }
17831
+ }, children: baseline_plan.value })) : (jsxRuntime.jsx("span", { children: baseline_plan.value }))] }))] }));
17832
+ };
17833
+
17834
+ const StructuredComparison = ({ content }) => {
17835
+ const classes = useAllocationPanelStyles();
17836
+ if (!content)
17837
+ return null;
17838
+ const { subtitle, scenario_groups = [] } = content;
17839
+ return (jsxRuntime.jsxs("div", { children: [subtitle && (jsxRuntime.jsx("div", { className: classes.comparisonSubtitle, children: subtitle })), scenario_groups.map((group, groupIndex) => (jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("div", { className: classes.scenarioLabel, children: group.scenario_label }), (group.comparisons || []).map((comparison, compIndex) => (jsxRuntime.jsxs("div", { className: classes.comparisonCard, children: [jsxRuntime.jsxs("div", { className: classes.comparisonParamRow, children: [jsxRuntime.jsx("span", { className: classes.comparisonParamName, children: comparison.parameter_name }), (comparison.tags || []).map((tag, tagIndex) => (jsxRuntime.jsx("span", { className: classes.comparisonTag, children: tag.label }, `tag-${tagIndex}`)))] }), jsxRuntime.jsxs("div", { className: classes.comparisonValues, children: [jsxRuntime.jsxs("div", { className: classes.comparisonValueBox, children: [jsxRuntime.jsx("div", { className: classes.comparisonValueLabel, children: comparison.baseline?.label }), jsxRuntime.jsx("div", { className: classes.comparisonValueText, children: comparison.baseline?.value })] }), jsxRuntime.jsx(ArrowForwardIcon, { className: classes.comparisonArrow }), jsxRuntime.jsxs("div", { className: classes.comparisonValueBox, children: [jsxRuntime.jsx("div", { className: classes.comparisonValueLabel, children: comparison.new_value?.label }), jsxRuntime.jsx("div", { className: classes.comparisonValueText, children: comparison.new_value?.value })] })] })] }, `comp-${groupIndex}-${compIndex}`)))] }, `group-${groupIndex}`)))] }));
17840
+ };
17841
+
17842
+ const PanelSection = ({ section }) => {
17843
+ const classes = useAllocationPanelStyles();
17844
+ if (!section)
17845
+ return null;
17846
+ const renderContent = () => {
17847
+ switch (section.content_type) {
17848
+ case "html":
17849
+ case "custom_html":
17850
+ return (jsxRuntime.jsx("div", { className: classes.panelHtmlContainer, children: jsxRuntime.jsx(HtmlContent, { bodyText: { content: section.content } }) }));
17851
+ case "structured":
17852
+ return jsxRuntime.jsx(StructuredComparison, { content: section.content });
17853
+ default:
17854
+ return null;
17855
+ }
17856
+ };
17857
+ return (jsxRuntime.jsxs(material.Accordion, { defaultExpanded: section.default_expanded, className: classes.sectionAccordion, disableGutters: true, children: [jsxRuntime.jsx(material.AccordionSummary, { expandIcon: jsxRuntime.jsx(ExpandMoreIcon, {}), className: classes.sectionSummary, children: jsxRuntime.jsx("span", { className: classes.sectionTitle, children: section.title }) }), jsxRuntime.jsx(material.AccordionDetails, { className: classes.sectionDetails, children: renderContent() })] }));
17858
+ };
17859
+
17860
+ const shiftChatbot = (panelEl) => {
17861
+ const chatbot = document.querySelector(".chatbot-component-container");
17862
+ if (!chatbot)
17863
+ return;
17864
+ const panelWidth = panelEl ? panelEl.offsetWidth : 0;
17865
+ const currentLeft = parseFloat(chatbot.style.left) || 0;
17866
+ chatbot.dataset.origLeft = chatbot.style.left;
17867
+ chatbot.style.transition = "left 0.3s ease";
17868
+ chatbot.style.left = (currentLeft - panelWidth) + "px";
17869
+ };
17870
+ const restoreChatbot = () => {
17871
+ const chatbot = document.querySelector(".chatbot-component-container");
17872
+ if (!chatbot)
17873
+ return;
17874
+ if (chatbot.dataset.origLeft) {
17875
+ chatbot.style.transition = "left 0.3s ease";
17876
+ chatbot.style.left = chatbot.dataset.origLeft;
17877
+ delete chatbot.dataset.origLeft;
17878
+ // Clean up transition after animation completes
17879
+ const onEnd = () => {
17880
+ chatbot.style.transition = "";
17881
+ chatbot.removeEventListener("transitionend", onEnd);
17882
+ };
17883
+ chatbot.addEventListener("transitionend", onEnd);
17884
+ }
17885
+ };
17886
+ const AllocationDetailPanel = () => {
17887
+ const classes = useAllocationPanelStyles();
17888
+ const [panelData, setPanelData] = React.useState(null);
17889
+ const [activeFooterAction, setActiveFooterAction] = React.useState(null);
17890
+ const [isExpanded, setIsExpanded] = React.useState(false);
17891
+ const panelRef = React.useRef(null);
17892
+ const handleOpen = React.useCallback((e) => {
17893
+ const { panelData: data } = e.detail || {};
17894
+ if (data) {
17895
+ setPanelData(data);
17896
+ }
17897
+ }, []);
17898
+ const handleClose = React.useCallback(() => {
17899
+ restoreChatbot();
17900
+ setPanelData(null);
17901
+ setIsExpanded(false);
17902
+ }, []);
17903
+ React.useEffect(() => {
17904
+ window.addEventListener("openAllocationDetailPanel", handleOpen);
17905
+ window.addEventListener("closeAllocationDetailPanel", handleClose);
17906
+ return () => {
17907
+ window.removeEventListener("openAllocationDetailPanel", handleOpen);
17908
+ window.removeEventListener("closeAllocationDetailPanel", handleClose);
17909
+ };
17910
+ }, [handleOpen, handleClose]);
17911
+ // Shift the chatbot once the panel has rendered
17912
+ React.useEffect(() => {
17913
+ if (panelData && panelRef.current) {
17914
+ // Use requestAnimationFrame to ensure the panel is laid out
17915
+ requestAnimationFrame(() => {
17916
+ shiftChatbot(panelRef.current);
17917
+ });
17918
+ }
17919
+ }, [panelData]);
17920
+ // Listen for direct clicks on the impact-ui collapse button
17921
+ React.useEffect(() => {
17922
+ if (!panelData)
17923
+ return;
17924
+ const collapseBtn = document.querySelector('button[aria-label="Collapse chatbot"]');
17925
+ if (!collapseBtn)
17926
+ return;
17927
+ const onCollapse = () => handleClose();
17928
+ collapseBtn.addEventListener("click", onCollapse);
17929
+ return () => collapseBtn.removeEventListener("click", onCollapse);
17930
+ }, [panelData, handleClose]);
17931
+ if (!panelData)
17932
+ return null;
17933
+ const footerActions = panelData.footer_actions || [
17934
+ { label: "Purge", variant: "outlined", action: "purge", options: [] },
17935
+ { label: "Finalize Plan", variant: "primary", action: "finalize", options: [] },
17936
+ ];
17937
+ const handleOptionClick = (option) => {
17938
+ setActiveFooterAction(null);
17939
+ window.dispatchEvent(new CustomEvent("allocationPanelAction", {
17940
+ detail: { value: option.value, label: option.label },
17941
+ }));
17942
+ };
17943
+ const handleFooterBtnClick = (btn) => {
17944
+ if (btn.options && btn.options.length > 0) {
17945
+ setActiveFooterAction(activeFooterAction === btn.action ? null : btn.action);
17946
+ }
17947
+ else {
17948
+ console.log("[AllocationPanel] footer action:", btn.action);
17949
+ }
17950
+ };
17951
+ const panel = (jsxRuntime.jsxs("div", { ref: panelRef, className: `${classes.panelContainer} ${isExpanded ? classes.panelExpanded : ""}`, "data-testid": "allocation-detail-panel", children: [jsxRuntime.jsx(PanelHeader, { title: panelData.title, actions: panelData.actions || {}, onClose: handleClose, isExpanded: isExpanded, onToggleExpand: () => setIsExpanded((prev) => !prev) }), jsxRuntime.jsxs("div", { className: classes.panelScrollBody, children: [jsxRuntime.jsx(ReportSummaryCard, { reportSummary: panelData.report_summary }), (panelData.sections || []).map((section) => (jsxRuntime.jsx(PanelSection, { section: section }, section.id)))] }), jsxRuntime.jsxs("div", { className: classes.panelFooter, children: [activeFooterAction && (jsxRuntime.jsx("div", { className: classes.optionsCard, children: footerActions
17952
+ .find((a) => a.action === activeFooterAction)
17953
+ ?.options?.map((opt, idx) => (jsxRuntime.jsxs("button", { className: classes.optionRow, onClick: () => handleOptionClick(opt), children: [jsxRuntime.jsx("span", { className: classes.optionIcon, children: "\u2606" }), opt.label] }, idx))) })), footerActions.map((btn, idx) => (jsxRuntime.jsx("button", { className: btn.variant === "primary" ? classes.footerBtnPrimary : classes.footerBtnOutlined, onClick: () => handleFooterBtnClick(btn), children: btn.label }, idx)))] })] }));
17954
+ return reactDom.createPortal(panel, document.body);
17955
+ };
17956
+
16997
17957
  /**
16998
17958
  * SmartBot Redux reducer.
16999
17959
  * State shape and behaviour match the consumer's core/reducers/smartBotReducer.js exactly.
@@ -17185,6 +18145,7 @@ const SmartBot = (props) => {
17185
18145
  // Minimize the chat window when the user follows an in-app link from a bot response
17186
18146
  const handleMinimizeRequest = () => {
17187
18147
  setPartialClose(true);
18148
+ window.dispatchEvent(new CustomEvent("closeAllocationDetailPanel"));
17188
18149
  };
17189
18150
  window.addEventListener("stepFormStreamStart", handleStepFormStreamStart);
17190
18151
  window.addEventListener("stepFormStreamEnd", handleStepFormStreamEnd);
@@ -17842,7 +18803,7 @@ const SmartBot = (props) => {
17842
18803
  fetchLegacyAgentInfo(); //Disabled temporarily since this was causing issue on homepage first render
17843
18804
  }
17844
18805
  }, [location]);
17845
- const handleSendMessage = async (userInput, userExplicitInput = {}, textWithColumnNames = "") => {
18806
+ const handleSendMessage = async (userInput, userExplicitInput = {}, textWithColumnNames = "", uiContext = null) => {
17846
18807
  try {
17847
18808
  // if (localStorage.getItem("isStreaming") === "true") {
17848
18809
  // displaySnackMessages(
@@ -17906,6 +18867,7 @@ const SmartBot = (props) => {
17906
18867
  userExplicitInput: userExplicitInput,
17907
18868
  textWithColumnNames: textWithColumnNames,
17908
18869
  answerMode: answerMode,
18870
+ ...(uiContext ? { uiContext } : {}),
17909
18871
  };
17910
18872
  // if(!isEmpty(userInput)) {
17911
18873
  // Clear the previous response's completed state so the incoming
@@ -17955,12 +18917,25 @@ const SmartBot = (props) => {
17955
18917
  sessionStorage.removeItem("stepForm_chatId");
17956
18918
  // dispatch(setChatbotContext({}));
17957
18919
  setUserInput(params?.text);
17958
- handleSendMessage(params?.text, params?.userExplicitInput, params?.textWithColumnNames);
18920
+ handleSendMessage(params?.text, params?.userExplicitInput, params?.textWithColumnNames, params?.uiContext);
17959
18921
  }
17960
18922
  catch (error) {
17961
18923
  console.error("onSendIconClick error", error);
17962
18924
  }
17963
18925
  };
18926
+ // A follow-up asked from a generated surface (SurfaceFrameContent's "iris:prompt"): sent as the user's next
18927
+ // message, with the surface's context as ui_context. Not while a turn runs or a form waits for its Submit.
18928
+ const surfacePromptRef = React.useRef(null);
18929
+ surfacePromptRef.current = (detail) => {
18930
+ if (!detail?.text || isStop || !lodash.isEmpty(chatbotContext))
18931
+ return;
18932
+ onSendIconClick({ text: detail.text, uiContext: detail.uiContext });
18933
+ };
18934
+ React.useEffect(() => {
18935
+ const onSurfacePrompt = (event) => surfacePromptRef.current?.(event.detail);
18936
+ window.addEventListener("iris:prompt", onSurfacePrompt);
18937
+ return () => window.removeEventListener("iris:prompt", onSurfacePrompt);
18938
+ }, []);
17964
18939
  const onStopIconClick = (params) => {
17965
18940
  try {
17966
18941
  setIsStop(false);
@@ -18194,9 +19169,35 @@ const SmartBot = (props) => {
18194
19169
  if (!root)
18195
19170
  return;
18196
19171
  const collapseBtn = root.querySelector('button[aria-label="Collapse chatbot"]');
18197
- if (collapseBtn)
19172
+ if (collapseBtn) {
18198
19173
  collapseBtn.click();
19174
+ window.dispatchEvent(new CustomEvent("closeAllocationDetailPanel"));
19175
+ }
19176
+ }, []);
19177
+ // Expand the chatbot to its full docked view by programmatically clicking
19178
+ // impact-ui's "Expand chatbot" button. Used when the allocation panel opens
19179
+ // from minimized state.
19180
+ const expandChatBotIfCollapsed = React.useCallback(() => {
19181
+ setShowModal(true);
19182
+ setPartialClose(false);
19183
+ // Use a short delay so the chatbot DOM renders before we look for the button
19184
+ setTimeout(() => {
19185
+ const root = smartBotWrapperRef.current;
19186
+ if (!root)
19187
+ return;
19188
+ const expandBtn = root.querySelector('button[aria-label="Expand chatbot"]');
19189
+ if (expandBtn) {
19190
+ expandBtn.click();
19191
+ }
19192
+ }, 100);
18199
19193
  }, []);
19194
+ // Listen for smartBotMaximize events (e.g. from allocation plan card)
19195
+ React.useEffect(() => {
19196
+ window.addEventListener("smartBotMaximize", expandChatBotIfCollapsed);
19197
+ return () => {
19198
+ window.removeEventListener("smartBotMaximize", expandChatBotIfCollapsed);
19199
+ };
19200
+ }, [expandChatBotIfCollapsed]);
18200
19201
  // Auto-collapse to draggable mode when the user interacts outside the bot.
18201
19202
  React.useEffect(() => {
18202
19203
  const handleOutsideInteraction = (e) => {
@@ -18218,6 +19219,9 @@ const SmartBot = (props) => {
18218
19219
  // Ignore clicks inside the expanded table modal portal
18219
19220
  if (e.target.closest?.(".test-modal"))
18220
19221
  return;
19222
+ // Ignore clicks inside the allocation detail panel
19223
+ if (e.target.closest?.('[data-testid="allocation-detail-panel"]'))
19224
+ return;
18221
19225
  collapseChatBotIfExpanded();
18222
19226
  };
18223
19227
  document.addEventListener("mousedown", handleOutsideInteraction, true);
@@ -18238,7 +19242,7 @@ const SmartBot = (props) => {
18238
19242
  return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [partialClose && (minimizedStreamData?.isStreaming || minimizedStreamData?.stepStatus === "step_form") && (jsxRuntime.jsx(MinimizedChatWidget, { onExpand: () => {
18239
19243
  setShowModal(true);
18240
19244
  setPartialClose(false);
18241
- } })), jsxRuntime.jsxs("div", { ref: smartBotWrapperRef, className: `${classes.agentStyleOverride} ${partialClose || !(showModal || forceOpen) ? classes.hideBotStyle : ""} `, children: [jsxRuntime.jsx(RenameModal, { open: renameOpen, renameValue: renameValue, setRenameValue: setRenameValue, onConfirm: handleRenameConfirm, onCancel: handleRenameCancel }), jsxRuntime.jsx(DeleteConfirmModal, { open: deleteOpen, onConfirm: handleDeleteConfirm, onCancel: handleDeleteCancel }), jsxRuntime.jsx(MemoryModal, { isModalOpen: isModalOpen, setIsModalOpen: setIsModalOpen, displaySnackMessages: displaySnackMessages }), jsxRuntime.jsx(UploadModal, { isUploadModalOpen: isUploadModalOpen, setIsUploadModalOpen: setIsUploadModalOpen, displaySnackMessages: displaySnackMessages }), jsxRuntime.jsx(impactUiV3.ChatBotComponent, { isFullWidth: forceOpen, userName: userName, showHistoryPanel: enableMultiChat, customInputComponent: currentMode === "agent" && !showSavedFilters ? (jsxRuntime.jsx(ChatbotInput, { newChatScreen: newChatScreen, inputValue: userInput, setInputValue: setUserInput, isStopIcon: isStop, onSendIconClick: onSendIconClick, onStopIconClick: onStopIconClick, currentMode: currentMode, filterOptions: filterOptions,
19245
+ } })), jsxRuntime.jsxs("div", { ref: smartBotWrapperRef, className: `${classes.agentStyleOverride} ${partialClose || !(showModal || forceOpen) ? classes.hideBotStyle : ""} `, children: [jsxRuntime.jsx(RenameModal, { open: renameOpen, renameValue: renameValue, setRenameValue: setRenameValue, onConfirm: handleRenameConfirm, onCancel: handleRenameCancel }), jsxRuntime.jsx(DeleteConfirmModal, { open: deleteOpen, onConfirm: handleDeleteConfirm, onCancel: handleDeleteCancel }), jsxRuntime.jsx(MemoryModal, { isModalOpen: isModalOpen, setIsModalOpen: setIsModalOpen, displaySnackMessages: displaySnackMessages }), jsxRuntime.jsx(UploadModal, { isUploadModalOpen: isUploadModalOpen, setIsUploadModalOpen: setIsUploadModalOpen, displaySnackMessages: displaySnackMessages }), jsxRuntime.jsx(impactUiV3.ChatBotComponent, { isFullWidth: forceOpen, userName: userName, showHistoryPanel: enableMultiChat, isConversationLoading: conversationLoading, customInputComponent: currentMode === "agent" && !showSavedFilters ? (jsxRuntime.jsx(ChatbotInput, { newChatScreen: newChatScreen, inputValue: userInput, setInputValue: setUserInput, isStopIcon: isStop, onSendIconClick: onSendIconClick, onStopIconClick: onStopIconClick, currentMode: currentMode, filterOptions: filterOptions,
18242
19246
  // onSaveClick={saveCurrentChat}
18243
19247
  savedFilterSets: savedFilterSets, selectedFilterSet: selectedFilterSet, onFilterSetSelect: (filterSet) => setSelectedFilterSet(filterSet), onClearFilterSet: () => setSelectedFilterSet(null), onTriggerRefresh: triggerRefreshAction, answerMode: answerMode, setAnswerMode: setAnswerMode })) : showSavedFilters ? jsxRuntime.jsx(jsxRuntime.Fragment, {}) : null, isChatBotOpen: showModal || forceOpen, historyPanelData: historyPanelData, onHistorySearchChange: (params) => { console.log("History Search Change", params); }, onHistorySelectConversation: (params) => {
18244
19248
  const convId = params?.conversation_id;
@@ -18344,6 +19348,7 @@ const SmartBot = (props) => {
18344
19348
  dispatch(setMinimizedStreamData(null));
18345
19349
  }
18346
19350
  setPartialClose(true);
19351
+ window.dispatchEvent(new CustomEvent("closeAllocationDetailPanel"));
18347
19352
  }
18348
19353
  },
18349
19354
  // assistantChats={assistantChats}
@@ -18353,7 +19358,7 @@ const SmartBot = (props) => {
18353
19358
  }, moduleList: modules, tabList: tabList, utilityList: utilityList, isAssistantThinking: false, isCustomScreen: showChatPlaceholder ? showChatPlaceholder : showSavedFilters, customScreenJsx: showChatPlaceholder ?
18354
19359
  jsxRuntime.jsx(ChatPlaceholder, { dateFormat: dateFormat, chatDataRef: chatDataRef, currentMode: currentMode, setShowChatPlaceholder: setShowChatPlaceholder, setLoader: setLoader, setCurrentAgentId: setCurrentAgentId, baseUrl: baseUrl, setBaseUrl: setBaseUrl, setCurrentSessionId: setCurrentSessionId, customChatConfig: customChatConfig, chatDataInfoRef: chatDataInfoRef, setChatDataState: setChatDataState, userInput: userInput, legacyAgentScreen: legacyAgentScreen, activeConversationId: activeConversationId, chatBodyRef: chatBodyRef, chatbotContext: chatbotContext, setInitValue: setInitValue, setSessionId: setSessionId, thinkingContent: thinkingContext?.thinkingContent, setThinkingContent: setThinkingContent, isThinking: isThinking, setIsThinking: setIsThinking, chatId: chatId, setChatId: setChatId, isStop: isStop, setIsStop: setIsStop, functionsRef: functionsRef, functionsState: functionsState, setFunctionsState: setFunctionsState, thinkingHeaderMessage: thinkingContext?.thinkingHeaderMessage, setThinkingHeaderMessage: setThinkingHeaderMessage, uniqueChatId: uniqueChatId, setUniqueChatId: setUniqueChatId, fieldNumber: fieldNumber, setFieldNumber: setFieldNumber, setAdditionalArgs: setAdditionalArgs, displayQuestions: displayQuestions, questions: questions, setActiveConversationId: setActiveConversationId, selectedFilterSet: selectedFilterSet, answerMode: answerMode })
18355
19360
  :
18356
- components?.FilterComponent ? jsxRuntime.jsx(components.FilterComponent, { savedFilterSets: savedFilterSets, partialClose: partialClose, chatBotWidth: chatBotWidth, onSetFilterConfiguration: callbacks?.onSetFilterConfiguration }) : null, inputText: userInput, threadList: ["Home"], hideMenuArrow: hideMenu, newChatScreen: newChatScreen, isModuleListLoading: modulesLoading, suggestionBanner: {
19361
+ components?.FilterComponent ? jsxRuntime.jsx(components.FilterComponent, { savedFilterSets: savedFilterSets, partialClose: partialClose, chatBotWidth: chatBotWidth, onSetFilterConfiguration: callbacks?.onSetFilterConfiguration }) : null, inputText: userInput, threadList: ["Home"], hideMenuArrow: true, newChatScreen: newChatScreen, isModuleListLoading: modulesLoading, suggestionBanner: {
18357
19362
  freeTextHeading: "Try adding more details :",
18358
19363
  freeTextContent: "Iris works better when you provide more context and pointed questions",
18359
19364
  }, isStopIcon: isStop, onStopIconClick: onStopIconClick, footerText: "AI-generated responses may contain errors\u2014please verify important information", showSuggestionBanner: showSavedFilters ? false : showSuggestionBanner, onCloseSuggestionBanner: () => {
@@ -18374,7 +19379,8 @@ const SmartBot = (props) => {
18374
19379
  setChatBotWidth(params);
18375
19380
  }, onMinimiseChatBot: () => {
18376
19381
  setPartialClose(true);
18377
- } })] })] }));
19382
+ window.dispatchEvent(new CustomEvent("closeAllocationDetailPanel"));
19383
+ } })] }), jsxRuntime.jsx(AllocationDetailPanel, {})] }));
18378
19384
  };
18379
19385
 
18380
19386
  exports.ChatbotProvider = ChatbotProvider;