@mgamadeus/ddd-agents 0.5.17 → 0.6.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.
Files changed (99) hide show
  1. package/README.md +164 -6
  2. package/boundary.json +13 -0
  3. package/dist/chat.js +148 -773
  4. package/dist/chat.js.map +1 -1
  5. package/dist/chunks/{canvas-title-slot-context-DK4sfhkl.js → ConversationMarkdown-BsCjyhj4.js} +14 -43
  6. package/dist/chunks/ConversationMarkdown-BsCjyhj4.js.map +1 -0
  7. package/dist/chunks/{ConversationMessageInputComposerWidgets-B3Zf69rD.js → ConversationMessageInputComposerWidgets-CE8LpyXY.js} +10 -37
  8. package/dist/chunks/ConversationMessageInputComposerWidgets-CE8LpyXY.js.map +1 -0
  9. package/dist/chunks/VoiceBarsIcon-BIcURsBF.js +643 -0
  10. package/dist/chunks/VoiceBarsIcon-BIcURsBF.js.map +1 -0
  11. package/dist/chunks/{WebSearchResultsConversationWidget-887v8Wen.js → WebSearchResultsConversationWidget-DXhfSikV.js} +2 -2
  12. package/dist/chunks/{WebSearchResultsConversationWidget-887v8Wen.js.map → WebSearchResultsConversationWidget-DXhfSikV.js.map} +1 -1
  13. package/dist/chunks/{browser-request-interception-BdKjYz31.js → browser-request-interception-BnzFbH0m.js} +2 -2
  14. package/dist/chunks/{browser-request-interception-BdKjYz31.js.map → browser-request-interception-BnzFbH0m.js.map} +1 -1
  15. package/dist/chunks/{canvas-reducers-CwFA3rQ6.js → canvas-reducers-D-YxAR4B.js} +2 -2
  16. package/dist/chunks/{canvas-reducers-CwFA3rQ6.js.map → canvas-reducers-D-YxAR4B.js.map} +1 -1
  17. package/dist/chunks/canvas-title-slot-context-D6UXrkdJ.js +36 -0
  18. package/dist/chunks/canvas-title-slot-context-D6UXrkdJ.js.map +1 -0
  19. package/dist/chunks/{canvasBodies-C7qqThc9.js → canvasBodies-CQEBkIVw.js} +4 -4
  20. package/dist/chunks/{canvasBodies-C7qqThc9.js.map → canvasBodies-CQEBkIVw.js.map} +1 -1
  21. package/dist/chunks/{canvasStorage-i2wKVSBf.js → canvasStorage-BbEI3h-8.js} +2 -2
  22. package/dist/chunks/{canvasStorage-i2wKVSBf.js.map → canvasStorage-BbEI3h-8.js.map} +1 -1
  23. package/dist/chunks/format-agent-voice-call-duration-C-3hRc9p.js +10 -0
  24. package/dist/chunks/format-agent-voice-call-duration-C-3hRc9p.js.map +1 -0
  25. package/dist/chunks/{link-navigation-CNX8Am2L.js → link-navigation-BUcy5qWW.js} +2 -2
  26. package/dist/chunks/{link-navigation-CNX8Am2L.js.map → link-navigation-BUcy5qWW.js.map} +1 -1
  27. package/dist/chunks/{realtime-arrival-BTLE3jjt.js → realtime-arrival-BfsAPwqQ.js} +8 -3
  28. package/dist/chunks/realtime-arrival-BfsAPwqQ.js.map +1 -0
  29. package/dist/chunks/use-agents-chat-store-CuIkCz9v.js +34 -0
  30. package/dist/chunks/use-agents-chat-store-CuIkCz9v.js.map +1 -0
  31. package/dist/chunks/{widget-name-resolver-BVEuAsW5.js → widget-name-resolver-B9k-s_cF.js} +3 -3
  32. package/dist/chunks/{widget-name-resolver-BVEuAsW5.js.map → widget-name-resolver-B9k-s_cF.js.map} +1 -1
  33. package/dist/chunks/withPollingChangeSubscription-CnQnubfK.js.map +1 -1
  34. package/dist/client-testing.js +4 -4
  35. package/dist/client.js +14 -3
  36. package/dist/client.js.map +1 -1
  37. package/dist/files/i18n-keys.json +1128 -100
  38. package/dist/image-render.js +7 -7
  39. package/dist/index.js +6 -6
  40. package/dist/kit.js +2 -2
  41. package/dist/preview.js +7 -7
  42. package/dist/provider.js +1 -1
  43. package/dist/renderer.js +25 -24
  44. package/dist/renderer.js.map +1 -1
  45. package/dist/styles.css +531 -93
  46. package/dist/types/client/AgentsConversationClient.d.ts +4 -1
  47. package/dist/types/client/http/createAgentsHttpConversationClient.d.ts +2 -1
  48. package/dist/types/entries/voice-admin.d.ts +7 -0
  49. package/dist/types/entries/voice.d.ts +24 -0
  50. package/dist/types/ui/account-realtime.d.ts +50 -11
  51. package/dist/types/voice/AgentVoiceCallBand/AgentVoiceCallBand.d.ts +49 -0
  52. package/dist/types/voice/AgentVoiceCallBand/agent-voice-call-outcome-title-text-key.d.ts +8 -0
  53. package/dist/types/voice/AgentVoiceCallCaptions/AgentVoiceCallCaptions.d.ts +15 -0
  54. package/dist/types/voice/AgentVoiceCallCaptions/saved-messages-of-agent-voice-chat.d.ts +12 -0
  55. package/dist/types/voice/AgentVoiceCallProvider/AgentVoiceCallProvider.d.ts +21 -0
  56. package/dist/types/voice/AgentVoiceCallProvider/agent-voice-call-context.d.ts +17 -0
  57. package/dist/types/voice/AgentVoiceChatStartButton/AgentVoiceChatStartButton.d.ts +15 -0
  58. package/dist/types/voice/AgentVoiceIcons/AgentVoiceIcons.d.ts +10 -0
  59. package/dist/types/voice/AgentVoiceIncomingCall/AgentVoiceIncomingCall.d.ts +28 -0
  60. package/dist/types/voice/AgentVoiceInputGlow/AgentVoiceInputGlow.d.ts +11 -0
  61. package/dist/types/voice/AgentVoiceInputGlow/agent-voice-input-glow-voice.d.ts +8 -0
  62. package/dist/types/voice/admin/AgentVoiceCallConversationLink/AgentVoiceCallConversationLink.d.ts +10 -0
  63. package/dist/types/voice/admin/AgentVoiceCallDetailScreen/AgentVoiceCallDetailScreen.d.ts +27 -0
  64. package/dist/types/voice/admin/AgentVoiceCallStateBadges/AgentVoiceCallStateBadges.d.ts +12 -0
  65. package/dist/types/voice/admin/AgentVoiceCallsScreen/AgentVoiceCallsScreen.d.ts +33 -0
  66. package/dist/types/voice/admin/agent-voice-admin-api.d.ts +59 -0
  67. package/dist/types/voice/admin/agent-voice-admin-format.d.ts +38 -0
  68. package/dist/types/voice/admin/agent-voice-admin-types.d.ts +110 -0
  69. package/dist/types/voice/agent-voice-api.d.ts +114 -0
  70. package/dist/types/voice/call/agent-voice-call-elapsed-seconds.d.ts +6 -0
  71. package/dist/types/voice/call/agent-voice-call-end-reasons.d.ts +3 -0
  72. package/dist/types/voice/call/agent-voice-call-store.d.ts +111 -0
  73. package/dist/types/voice/call/agent-voice-call-turn.d.ts +4 -0
  74. package/dist/types/voice/call/build-unsaved-agent-voice-call-lines.d.ts +14 -0
  75. package/dist/types/voice/call/format-agent-voice-call-duration.d.ts +2 -0
  76. package/dist/types/voice/call/use-agent-voice-call-elapsed-seconds.d.ts +3 -0
  77. package/dist/types/voice/call/use-agent-voice-call-server-end.d.ts +15 -0
  78. package/dist/types/voice/call/use-agent-voice-call.d.ts +12 -0
  79. package/dist/types/voice/call/use-follow-agent-voice-call-conversation.d.ts +9 -0
  80. package/dist/types/voice/ring/agent-voice-caller-label.d.ts +21 -0
  81. package/dist/types/voice/ring/agent-voice-incoming-ring-list.d.ts +10 -0
  82. package/dist/types/voice/ring/agent-voice-incoming-ring-store.d.ts +47 -0
  83. package/dist/types/voice/ring/agent-voice-ring-source.d.ts +75 -0
  84. package/dist/types/voice/ring/agent-voice-ring.d.ts +35 -0
  85. package/dist/types/voice/ring/answer-incoming-agent-voice-call.d.ts +13 -0
  86. package/dist/types/voice/ring/use-agent-voice-incoming-rings.d.ts +14 -0
  87. package/dist/types/voice/ring/use-agent-voice-ring-tone.d.ts +6 -0
  88. package/dist/ui.js +82 -19
  89. package/dist/ui.js.map +1 -1
  90. package/dist/voice-admin.js +738 -0
  91. package/dist/voice-admin.js.map +1 -0
  92. package/dist/voice.js +1586 -0
  93. package/dist/voice.js.map +1 -0
  94. package/dist/widgets.js +4 -4
  95. package/package.json +27 -1
  96. package/public-api.json +156 -0
  97. package/dist/chunks/ConversationMessageInputComposerWidgets-B3Zf69rD.js.map +0 -1
  98. package/dist/chunks/canvas-title-slot-context-DK4sfhkl.js.map +0 -1
  99. package/dist/chunks/realtime-arrival-BTLE3jjt.js.map +0 -1
package/dist/chat.js CHANGED
@@ -1,35 +1,39 @@
1
1
  "use client";
2
- import { jsx, jsxs, Fragment } from "react/jsx-runtime";
3
- import { useRef, useEffect, useMemo, useState, useImperativeHandle, useLayoutEffect, useCallback, useContext, memo, Fragment as Fragment$1, useReducer } from "react";
2
+ import { jsx, jsxs, Fragment as Fragment$1 } from "react/jsx-runtime";
3
+ import { useRef, useEffect, useMemo, useState, useImperativeHandle, useLayoutEffect, memo, useCallback, Fragment, useReducer } from "react";
4
4
  import { u as useAgentsConversationClient, a as useOptionalAgentsConversationClient, A as AgentsConversationClientProvider } from "./chunks/AgentsConversationClientContext-C4T7g_Qk.js";
5
5
  import { w as withPollingChangeSubscription } from "./chunks/withPollingChangeSubscription-CnQnubfK.js";
6
- import { s as Text, F as classNames, I as Icon, ab as useAgentsTexts, G as GlowFrame, v as Tooltip, B as Button, n as Skeleton, a5 as useAgentsEnvironment, j as Markdown, K as getAgentDisplayName, a3 as useAgentsBudgetLimit, h as InteractiveSurface, L as LoadingSpinner, a1 as translateText, p as SplitView, _ as reportRunningTurn, a2 as useAgentsActiveAgentSpaceKey, P as ProgressBar } from "./chunks/link-navigation-CNX8Am2L.js";
6
+ import { s as Text, F as classNames, I as Icon, ab as useAgentsTexts, G as GlowFrame, v as Tooltip, B as Button, n as Skeleton, j as Markdown, K as getAgentDisplayName, a3 as useAgentsBudgetLimit, a5 as useAgentsEnvironment, h as InteractiveSurface, L as LoadingSpinner, a1 as translateText, p as SplitView, _ as reportRunningTurn, a2 as useAgentsActiveAgentSpaceKey, P as ProgressBar } from "./chunks/link-navigation-BUcy5qWW.js";
7
7
  import { i as isAgentsClientError, a as AgentsClientError } from "./chunks/conversation-CbWEHPbL.js";
8
- import { h as findBalancedJsonObjectEnd, r as resolveDeepLinkableWidget, d as buildMessageTextWithComposerWidgets, s as splitComposerWidgetFencesFromMessageText, j as WidgetWindowRootContext, a as ConversationMarkdown, i as isWidgetClickSignalSource, C as CanvasTitleSlotContext, e as buildWidgetRenderReportSignal, W as WIDGET_RENDER_REPORT_SIGNAL_SOURCE, k as createWidgetRenderReportCollector, l as WidgetRenderReportCollectorContext } from "./chunks/canvas-title-slot-context-DK4sfhkl.js";
9
- import { W as WIDGET_FENCE_LANG, G as resolveWidgetName, j as conversationWidgetRegistry, n as findWidgetFencesInMarkdown, o as ConversationWidgetErrorBoundary, p as ConversationWidgetFeatureGate, T as parseWidgetJsonObject, F as resolveCanonicalWidgetName, y as getConversationWidgetRegistryRevision, U as BARE_WIDGET_LINE_GLOBAL, t as closestWidgetNames } from "./chunks/widget-name-resolver-BVEuAsW5.js";
10
- import { a0 as useConversationWidgetContext, h as canvasBehaviourOf, I as canvasKindOpenerWidgetNamesOf, p as payloadHashOfInstanceId, z as buildWidgetAgentSpaceKeyProps, q as CHAT_COLUMN_MIN_WIDTH_PX, o as CANVAS_MIN_WIDTH_PX, b5 as useCanvasViable, D as DEFAULT_CANVAS_WIDTH_PERCENT, J as canvasWidthPercentOf, C as CANVAS_BOXED_INSET_PX, ar as ElementWidthCanvasViability, af as CanvasViabilityContext } from "./chunks/WebSearchResultsConversationWidget-887v8Wen.js";
11
- import { r as readStoredCanvas, c as clearStoredCanvas } from "./chunks/canvasStorage-i2wKVSBf.js";
12
- import { b as ConversationErrorType, a as ConversationMessageInputComposerWidgets, u as useAgentsChatSelector, C as ConversationWidgetProvider, c as createAgentsChatStore } from "./chunks/ConversationMessageInputComposerWidgets-B3Zf69rD.js";
13
- import { A, d, E, I, r, e, f, g, h } from "./chunks/ConversationMessageInputComposerWidgets-B3Zf69rD.js";
8
+ import { n as normalizeServerMessageToMarkdown, V as VoiceBarsIcon, b as ConversationMessageHeader, a as ConversationMessageUser, C as ConversationMessageWidgets } from "./chunks/VoiceBarsIcon-BIcURsBF.js";
9
+ import { a0 as useConversationWidgetContext, h as canvasBehaviourOf, I as canvasKindOpenerWidgetNamesOf, p as payloadHashOfInstanceId, z as buildWidgetAgentSpaceKeyProps, q as CHAT_COLUMN_MIN_WIDTH_PX, o as CANVAS_MIN_WIDTH_PX, b5 as useCanvasViable, D as DEFAULT_CANVAS_WIDTH_PERCENT, J as canvasWidthPercentOf, C as CANVAS_BOXED_INSET_PX, ar as ElementWidthCanvasViability, af as CanvasViabilityContext } from "./chunks/WebSearchResultsConversationWidget-DXhfSikV.js";
10
+ import { j as conversationWidgetRegistry, n as findWidgetFencesInMarkdown, o as ConversationWidgetErrorBoundary, p as ConversationWidgetFeatureGate, T as parseWidgetJsonObject, F as resolveCanonicalWidgetName, W as WIDGET_FENCE_LANG, y as getConversationWidgetRegistryRevision, U as BARE_WIDGET_LINE_GLOBAL, G as resolveWidgetName, t as closestWidgetNames } from "./chunks/widget-name-resolver-B9k-s_cF.js";
11
+ import { r as readStoredCanvas, c as clearStoredCanvas } from "./chunks/canvasStorage-BbEI3h-8.js";
12
+ import { r as resolveDeepLinkableWidget, i as isWidgetClickSignalSource, C as CanvasTitleSlotContext } from "./chunks/canvas-title-slot-context-D6UXrkdJ.js";
13
+ import { b as ConversationErrorType, a as ConversationMessageInputComposerWidgets, C as ConversationWidgetProvider, c as createAgentsChatStore } from "./chunks/ConversationMessageInputComposerWidgets-CE8LpyXY.js";
14
+ import { A, E, I, r, d } from "./chunks/ConversationMessageInputComposerWidgets-CE8LpyXY.js";
15
+ import { c as buildMessageTextWithComposerWidgets, e as WidgetWindowRootContext, f as findBalancedJsonObjectEnd, d as buildWidgetRenderReportSignal, W as WIDGET_RENDER_REPORT_SIGNAL_SOURCE, g as createWidgetRenderReportCollector, h as WidgetRenderReportCollectorContext } from "./chunks/ConversationMarkdown-BsCjyhj4.js";
14
16
  import { l as lastWireMessageIsUnansweredUserMessage, P as PHONE_CALL_LIFECYCLE_SIGNAL_SOURCES, b as buildChangedMessagesRequest, d as deriveAgentActivity } from "./chunks/contract-C18owGKs.js";
15
17
  import { S } from "./chunks/contract-C18owGKs.js";
16
18
  import { t as textKey } from "./chunks/text-key-DnoZ4lAk.js";
17
- import { c as canvasBodies } from "./chunks/canvasBodies-C7qqThc9.js";
19
+ import { c as canvasBodies } from "./chunks/canvasBodies-CQEBkIVw.js";
18
20
  import { a as canvasFeatureFlagOf } from "./chunks/canvas-feature-flags-Cn8xBliA.js";
19
21
  import { flushSync } from "react-dom";
22
+ import { u as useAgentsChatSelector } from "./chunks/use-agents-chat-store-CuIkCz9v.js";
23
+ import { A as A2, b, c, a } from "./chunks/use-agents-chat-store-CuIkCz9v.js";
20
24
  const history = "agents_history_BIbikt";
21
- const styles$n = {
25
+ const styles$j = {
22
26
  history
23
27
  };
24
28
  const AgentChatActivityHistory = (props) => {
25
29
  const { turn } = props;
26
30
  if (turn === null || turn.lines.length === 0) return null;
27
- return /* @__PURE__ */ jsx("div", { className: styles$n.history, "data-testid": "agent-chat-activity-history", children: turn.lines.map((line2) => /* @__PURE__ */ jsx(Text, { role: "help", color: "--agents-fg-light", translate: false, children: line2.line }, `${line2.toolCallMessageId}-${line2.state}`)) });
31
+ return /* @__PURE__ */ jsx("div", { className: styles$j.history, "data-testid": "agent-chat-activity-history", children: turn.lines.map((line2) => /* @__PURE__ */ jsx(Text, { role: "help", color: "--agents-fg-light", translate: false, children: line2.line }, `${line2.toolCallMessageId}-${line2.state}`)) });
28
32
  };
29
33
  const dots = "agents_dots_ndE4a-";
30
34
  const bounce = "agents_bounce_rAVWhT";
31
35
  const pulse = "agents_pulse_r0EheQ";
32
- const styles$m = {
36
+ const styles$i = {
33
37
  dots,
34
38
  bounce,
35
39
  pulse
@@ -37,7 +41,7 @@ const styles$m = {
37
41
  const AgentChatActivityDots = ({ variant = "bounce" }) => /* @__PURE__ */ jsxs(
38
42
  "div",
39
43
  {
40
- className: classNames(styles$m.dots, variant === "pulse" ? styles$m.pulse : styles$m.bounce),
44
+ className: classNames(styles$i.dots, variant === "pulse" ? styles$i.pulse : styles$i.bounce),
41
45
  "aria-hidden": "true",
42
46
  "data-agents-activity-dots": variant,
43
47
  children: [
@@ -48,7 +52,7 @@ const AgentChatActivityDots = ({ variant = "bounce" }) => /* @__PURE__ */ jsxs(
48
52
  }
49
53
  );
50
54
  const activity = "agents_activity_Gv-0ee";
51
- const styles$l = {
55
+ const styles$h = {
52
56
  activity
53
57
  };
54
58
  const AgentChatActivityIndicator = (props) => {
@@ -57,259 +61,22 @@ const AgentChatActivityIndicator = (props) => {
57
61
  if (!isWorking) return null;
58
62
  const currentLines = activityTicker.currentTurn?.lines ?? [];
59
63
  const currentLine = currentLines.length > 0 ? currentLines[currentLines.length - 1].line : null;
60
- return /* @__PURE__ */ jsxs("div", { className: styles$l.activity, role: "status", "aria-live": "polite", "data-testid": "agent-chat-activity", children: [
64
+ return /* @__PURE__ */ jsxs("div", { className: styles$h.activity, role: "status", "aria-live": "polite", "data-testid": "agent-chat-activity", children: [
61
65
  /* @__PURE__ */ jsx(AgentChatActivityDots, { variant: dotsVariant }),
62
66
  currentLine !== null ? /* @__PURE__ */ jsx(Text, { role: "help", color: "--agents-fg-light", translate: false, children: currentLine }) : /* @__PURE__ */ jsx(Text, { role: "help", color: "--agents-fg-light", children: "Working on it…" })
63
67
  ] });
64
68
  };
65
69
  const bar = "agents_bar_DAkgRp";
66
- const styles$k = {
70
+ const styles$g = {
67
71
  bar
68
72
  };
69
73
  const ConversationClosedBar = (props) => {
70
74
  const { text = "This conversation is closed." } = props;
71
- return /* @__PURE__ */ jsxs("div", { className: styles$k.bar, "data-testid": "agent-chat-closed-bar", children: [
75
+ return /* @__PURE__ */ jsxs("div", { className: styles$g.bar, "data-testid": "agent-chat-closed-bar", children: [
72
76
  /* @__PURE__ */ jsx(Icon, { name: "check", color: "--agents-success-500" }),
73
77
  /* @__PURE__ */ jsx(Text, { children: text })
74
78
  ] });
75
79
  };
76
- const ANY_FENCE_DELIM_LINE = /^ {0,3}(`{3,}|~{3,})(.*)$/;
77
- const parseFenceDelimiterLine = (line2) => {
78
- const match = ANY_FENCE_DELIM_LINE.exec(line2);
79
- if (!match) return null;
80
- const marker = match[1];
81
- const char = marker[0];
82
- const info = match[2].trim();
83
- if (char === "`" && info.includes("`")) return null;
84
- return { char, length: marker.length, info };
85
- };
86
- const isWidgetFenceInfo = (info) => new RegExp(`^${WIDGET_FENCE_LANG}\\b`).test(info.trim());
87
- const widgetOpenerPattern = () => new RegExp("```[ \\t]*" + WIDGET_FENCE_LANG + "\\b");
88
- const readLine = (text, lineStart) => {
89
- const newlineIndex = text.indexOf("\n", lineStart);
90
- const lineEnd = newlineIndex === -1 ? text.length : newlineIndex;
91
- const afterLine = newlineIndex === -1 ? text.length : newlineIndex + 1;
92
- const rawContent = text.slice(lineStart, lineEnd);
93
- return { content: rawContent.endsWith("\r") ? rawContent.slice(0, -1) : rawContent, afterLine };
94
- };
95
- const findClosingFenceEnd = (text, bodyStart, opener) => {
96
- let cursor = bodyStart;
97
- while (cursor < text.length) {
98
- const { content: content2, afterLine } = readLine(text, cursor);
99
- const delimiter = parseFenceDelimiterLine(content2);
100
- if (delimiter && delimiter.char === opener.char && delimiter.length >= opener.length && delimiter.info === "") {
101
- return afterLine;
102
- }
103
- cursor = afterLine;
104
- }
105
- return text.length;
106
- };
107
- const findFencedBlockRanges = (text) => {
108
- const ranges = [];
109
- let cursor = 0;
110
- while (cursor < text.length) {
111
- const { content: content2, afterLine } = readLine(text, cursor);
112
- const opener = parseFenceDelimiterLine(content2);
113
- if (opener) {
114
- const end = findClosingFenceEnd(text, afterLine, opener);
115
- ranges.push([cursor, end]);
116
- cursor = end;
117
- continue;
118
- }
119
- cursor = afterLine;
120
- }
121
- return ranges;
122
- };
123
- const findFenceEnd = (text, bodyStart) => {
124
- let cursor = bodyStart;
125
- while (cursor < text.length) {
126
- const { content: content2, afterLine } = readLine(text, cursor);
127
- const delimiter = parseFenceDelimiterLine(content2);
128
- if (delimiter && delimiter.char === "`") {
129
- return delimiter.info === "" ? { closesAt: afterLine } : { unclosedBoundary: cursor };
130
- }
131
- cursor = afterLine;
132
- }
133
- return { unclosedBoundary: text.length };
134
- };
135
- const closeWidgetFenceBody = (text, bodyStart) => {
136
- const end = findFenceEnd(text, bodyStart);
137
- if ("closesAt" in end) {
138
- return { appended: text.slice(bodyStart, end.closesAt), resumeAt: end.closesAt };
139
- }
140
- const jsonObjectEnd = findBalancedJsonObjectEnd(text, bodyStart);
141
- if (jsonObjectEnd === null) {
142
- return { appended: text.slice(bodyStart), resumeAt: text.length };
143
- }
144
- return { appended: text.slice(bodyStart, jsonObjectEnd + 1) + "\n```", resumeAt: jsonObjectEnd + 1 };
145
- };
146
- const repairMalformedWidgetFences = (text) => {
147
- if (!widgetOpenerPattern().test(text)) return text;
148
- let result = "";
149
- let cursor = 0;
150
- while (cursor < text.length) {
151
- const { content: content2, afterLine } = readLine(text, cursor);
152
- const delimiter = parseFenceDelimiterLine(content2);
153
- if (delimiter && delimiter.char === "`") {
154
- const info = delimiter.info;
155
- if (info !== "" && isWidgetFenceInfo(info)) {
156
- result += content2 + text.slice(cursor + content2.length, afterLine);
157
- const { appended, resumeAt } = closeWidgetFenceBody(text, afterLine);
158
- result += appended;
159
- cursor = resumeAt;
160
- continue;
161
- }
162
- if (info !== "") {
163
- const otherFenceEnd = findFenceEnd(text, afterLine);
164
- const bodyEnd = "closesAt" in otherFenceEnd ? otherFenceEnd.closesAt : text.length;
165
- result += text.slice(cursor, bodyEnd);
166
- cursor = bodyEnd;
167
- continue;
168
- }
169
- }
170
- const gluedMatch = widgetOpenerPattern().exec(content2);
171
- if (gluedMatch && gluedMatch.index > 0 && content2.slice(0, gluedMatch.index).trim() !== "") {
172
- const bodyStart = afterLine;
173
- if (findBalancedJsonObjectEnd(text, bodyStart) !== null) {
174
- const openerLine = content2.slice(gluedMatch.index) + text.slice(cursor + content2.length, afterLine);
175
- result += content2.slice(0, gluedMatch.index) + "\n" + openerLine;
176
- const { appended, resumeAt } = closeWidgetFenceBody(text, bodyStart);
177
- result += appended;
178
- cursor = resumeAt;
179
- continue;
180
- }
181
- }
182
- result += text.slice(cursor, afterLine);
183
- cursor = afterLine;
184
- }
185
- return result;
186
- };
187
- const scanLineStartingJsonSpans = (text) => {
188
- const spans = [];
189
- const lines2 = text.split("\n");
190
- let offset = 0;
191
- for (const line2 of lines2) {
192
- const lineStart = offset;
193
- offset += line2.length + 1;
194
- if (!line2.trimStart().startsWith("{")) continue;
195
- const openIndex = lineStart + line2.indexOf("{");
196
- const jsonObjectEnd = findBalancedJsonObjectEnd(text, openIndex);
197
- if (jsonObjectEnd !== null) {
198
- spans.push({ json: text.slice(openIndex, jsonObjectEnd + 1), start: openIndex, end: jsonObjectEnd + 1 });
199
- }
200
- }
201
- return spans;
202
- };
203
- const widgetTypeOf = (jsonCandidate) => {
204
- let parsed;
205
- try {
206
- parsed = JSON.parse(jsonCandidate);
207
- } catch {
208
- return null;
209
- }
210
- if (typeof parsed !== "object" || parsed === null) return null;
211
- const type = parsed.type;
212
- return typeof type === "string" && type !== "" ? type : null;
213
- };
214
- const referenceNakedWidgetJson = (text) => {
215
- if (!text.includes('"type"')) return text;
216
- const fencedRanges = findFencedBlockRanges(text);
217
- const isInsideFence = (position) => fencedRanges.some(([start, end]) => position >= start && position < end);
218
- const spans = scanLineStartingJsonSpans(text).filter((span) => !isInsideFence(span.start)).reverse();
219
- let result = text;
220
- for (const span of spans) {
221
- const type = widgetTypeOf(span.json);
222
- if (type === null || resolveWidgetName(type) === void 0) continue;
223
- const fencedBlock = "```widget\n" + span.json + "\n```";
224
- result = result.slice(0, span.start) + fencedBlock + result.slice(span.end);
225
- }
226
- return result;
227
- };
228
- const PRE_CALL_MESSAGE_MARKER = "{preCallMessage}";
229
- const MANGLED_PRE_CALL_RE = /\{\s*"preCallMessage"\s*:\s*"((?:[^"\\]|\\.)*)"\s*,?\s*[^}]*\}\s*(?:<\S*)?/g;
230
- const stripPreCallMessageMarker = (text) => {
231
- if (!text) return text;
232
- const leading = text.replace(/^\s+/, "");
233
- if (leading.length < PRE_CALL_MESSAGE_MARKER.length && PRE_CALL_MESSAGE_MARKER.startsWith(leading)) return "";
234
- const mangledPrefix = '{ "preCallMessage"';
235
- const normalizedLeading = leading.replace(/\s+/g, " ");
236
- if (normalizedLeading.length < mangledPrefix.length && mangledPrefix.startsWith(normalizedLeading) || normalizedLeading.startsWith(mangledPrefix) && !normalizedLeading.includes("}")) {
237
- return "";
238
- }
239
- const withMangledNormalized = text.replace(MANGLED_PRE_CALL_RE, (_match, escapedStatusLine) => {
240
- try {
241
- return JSON.parse(`"${escapedStatusLine}"`);
242
- } catch {
243
- return escapedStatusLine;
244
- }
245
- });
246
- const withMarkerRemoved = withMangledNormalized.split(PRE_CALL_MESSAGE_MARKER).join("");
247
- const markerWasLeading = leading.startsWith(PRE_CALL_MESSAGE_MARKER) || normalizedLeading.startsWith(mangledPrefix);
248
- return markerWasLeading ? withMarkerRemoved.replace(/^\s+/, "") : withMarkerRemoved;
249
- };
250
- const WIDGET_ATTR_KEY = /^[a-zA-Z_:][a-zA-Z0-9_.:-]*$/;
251
- const isRecord = (value) => typeof value === "object" && value !== null;
252
- const isTextPart = (part) => isRecord(part) && part.type === "text";
253
- const isComponentPart = (part) => isRecord(part) && part.type === "component" && typeof part.name === "string" && part.name.length > 0;
254
- const isToolUsePart = (part) => isRecord(part) && part.type === "tool_use";
255
- const isMessagePart = (part) => isTextPart(part) || isComponentPart(part) || isToolUsePart(part);
256
- const isPayload = (value) => {
257
- if (!isRecord(value)) return false;
258
- const parts = value.content ?? value.parts;
259
- return Array.isArray(parts) && parts.every(isMessagePart);
260
- };
261
- const coerceSinglePartPayload = (value) => {
262
- if (!isRecord(value)) return null;
263
- const part = value.content ?? value.parts;
264
- if (!isMessagePart(part)) return null;
265
- const rest = { ...value };
266
- delete rest.parts;
267
- return { ...rest, content: [part] };
268
- };
269
- const encodeAttrValue = (value) => JSON.stringify(value).replace(/'/g, "\\u0027");
270
- const propsToAttrs = (props) => Object.entries(props).filter(([key, value]) => value !== void 0 && WIDGET_ATTR_KEY.test(key)).map(([key, value]) => `${key}='${encodeAttrValue(value)}'`).join(" ");
271
- const componentPartToWidget = (part) => {
272
- const attrs = propsToAttrs(part.props ?? {});
273
- return attrs ? `::${part.name}{${attrs}}` : `::${part.name}`;
274
- };
275
- const toolUsePartToWidget = (part) => {
276
- const payload = encodeAttrValue({ name: part.name, input: part.input });
277
- return `::ToolTrace{payload='${payload}'}`;
278
- };
279
- const partToMarkdown = (part) => {
280
- if (isTextPart(part)) return part.text?.trim() ?? "";
281
- if (isToolUsePart(part)) return toolUsePartToWidget(part);
282
- return componentPartToWidget(part);
283
- };
284
- const payloadToMarkdown = (payload) => {
285
- return (payload.content ?? payload.parts ?? []).map(partToMarkdown).filter(Boolean).join("\n\n");
286
- };
287
- const tryParsePayload = (value) => {
288
- try {
289
- const parsed = JSON.parse(value);
290
- return isPayload(parsed) ? parsed : coerceSinglePartPayload(parsed);
291
- } catch {
292
- return null;
293
- }
294
- };
295
- const normalizeServerMessageToMarkdown = (message2) => {
296
- let result;
297
- if (typeof message2 === "string") {
298
- const parsed = tryParsePayload(message2);
299
- result = parsed ? payloadToMarkdown(parsed) : message2;
300
- } else if (isPayload(message2)) {
301
- result = payloadToMarkdown(message2);
302
- } else {
303
- const coerced = coerceSinglePartPayload(message2);
304
- if (coerced) {
305
- result = payloadToMarkdown(coerced);
306
- } else {
307
- console.warn("[AIExtensions] normalizeServerMessageToMarkdown: unrecognized message shape", message2);
308
- result = "";
309
- }
310
- }
311
- return referenceNakedWidgetJson(repairMalformedWidgetFences(stripPreCallMessageMarker(result)));
312
- };
313
80
  const anchorMessageCarriesCanvasWidget = (pointer, anchorMessage) => {
314
81
  const openers = /* @__PURE__ */ new Set([
315
82
  ...conversationWidgetRegistry.widgets.filter((entry) => entry.opensCanvases?.includes(pointer.canvasId)).map((entry) => entry.name),
@@ -344,11 +111,11 @@ const CanvasRestoreOnMount = ({ conversationId, messages }) => {
344
111
  restore();
345
112
  return;
346
113
  }
347
- if (messages === null || !messages.some((message2) => message2.conversationId === conversationId)) return;
114
+ if (messages === null || !messages.some((message) => message.conversationId === conversationId)) return;
348
115
  restoredForConversationIdRef.current = conversationId;
349
116
  const anchorMessageId = pointer.anchor.messageId;
350
- const anchorMessage = messages.find((message2) => message2.id === anchorMessageId);
351
- const newestAssistantMessage = [...messages].reverse().find((message2) => message2.role === "ASSISTANT");
117
+ const anchorMessage = messages.find((message) => message.id === anchorMessageId);
118
+ const newestAssistantMessage = [...messages].reverse().find((message) => message.role === "ASSISTANT");
352
119
  const turnIsOver = canvasBehaviourOf(pointer.canvasId)?.lifetime === "turn" && newestAssistantMessage?.id !== anchorMessageId;
353
120
  if (anchorMessage === void 0 || turnIsOver || !anchorMessageCarriesCanvasWidget(pointer, anchorMessage)) {
354
121
  clearStoredCanvas(conversationId);
@@ -389,7 +156,7 @@ const input = "agents_input_GCtiXU";
389
156
  const inputReplacement = "agents_inputReplacement_EAhjsv";
390
157
  const inputInCategory = "agents_inputInCategory_RDuOYA";
391
158
  const olderLoading = "agents_olderLoading_5X7nMg";
392
- const styles$j = {
159
+ const styles$f = {
393
160
  chat,
394
161
  genericChat,
395
162
  customBg,
@@ -424,7 +191,7 @@ const compactTopSlot = "agents_compactTopSlot_x57yOL";
424
191
  const compactActionsStart = "agents_compactActionsStart_3SeY5C";
425
192
  const collapsed = "agents_collapsed_v3Ekqz";
426
193
  const collapsedPillSizer = "agents_collapsedPillSizer_aqw7WI";
427
- const styles$i = {
194
+ const styles$e = {
428
195
  inputContainer,
429
196
  aiGlow,
430
197
  editableInput,
@@ -533,15 +300,15 @@ const ConversationMessageInput = (props) => {
533
300
  replaceComposerWidgetFields(lastWidget.composerWidgetId, nextFields);
534
301
  }
535
302
  };
536
- const handleKeyPress = (e2) => {
537
- if (e2.key === "Enter" && !e2.shiftKey) {
303
+ const handleKeyPress = (e) => {
304
+ if (e.key === "Enter" && !e.shiftKey) {
538
305
  if (isComposingRef.current) return;
539
- e2.preventDefault();
306
+ e.preventDefault();
540
307
  handleSendMessage();
541
308
  return;
542
309
  }
543
- if (e2.key === "Backspace" && inputValue === "" && (outgoingComposerWidgets?.length ?? 0) > 0) {
544
- e2.preventDefault();
310
+ if (e.key === "Backspace" && inputValue === "" && (outgoingComposerWidgets?.length ?? 0) > 0) {
311
+ e.preventDefault();
545
312
  handleBackspaceOnEmptyInput();
546
313
  }
547
314
  };
@@ -557,12 +324,12 @@ const ConversationMessageInput = (props) => {
557
324
  isComposingRef.current = false;
558
325
  handleInput();
559
326
  };
560
- const handleContainerMouseDown = (e2) => {
561
- const target = e2.target;
327
+ const handleContainerMouseDown = (e) => {
328
+ const target = e.target;
562
329
  if (target === inputRef.current || inputRef.current?.contains(target)) return;
563
330
  if (target.closest("button")) return;
564
331
  if (disabled || isProcessing) return;
565
- e2.preventDefault();
332
+ e.preventDefault();
566
333
  focusInputAtEnd();
567
334
  };
568
335
  useLayoutEffect(() => {
@@ -582,9 +349,9 @@ const ConversationMessageInput = (props) => {
582
349
  wasProcessingRef.current = isProcessing;
583
350
  }, [isProcessing, disabled]);
584
351
  useEffect(() => {
585
- const handlePasteEvent = (e2) => {
586
- e2.preventDefault();
587
- const text = e2.clipboardData?.getData("text/plain");
352
+ const handlePasteEvent = (e) => {
353
+ e.preventDefault();
354
+ const text = e.clipboardData?.getData("text/plain");
588
355
  if (!text) {
589
356
  return;
590
357
  }
@@ -610,7 +377,7 @@ const ConversationMessageInput = (props) => {
610
377
  /* @__PURE__ */ jsx(
611
378
  GlowFrame,
612
379
  {
613
- className: classNames(styles$i.aiGlow),
380
+ className: classNames(styles$e.aiGlow),
614
381
  color: isMessageTooLong ? "var(--agents-danger-500)" : void 0,
615
382
  borderRadius: compact2 ? COMPACT_INPUT_RADIUS_PX : void 0,
616
383
  borderWidth: 2,
@@ -619,20 +386,20 @@ const ConversationMessageInput = (props) => {
619
386
  "div",
620
387
  {
621
388
  className: classNames(
622
- styles$i.inputContainer,
389
+ styles$e.inputContainer,
623
390
  {
624
- [styles$i.compact]: compact2,
625
- [styles$i.compactStacked]: isCompactStacked,
626
- [styles$i.compactWithActionsStart]: isCompactStacked && !!actionsSlotStart,
627
- [styles$i.collapsed]: compact2 && collapsed2
391
+ [styles$e.compact]: compact2,
392
+ [styles$e.compactStacked]: isCompactStacked,
393
+ [styles$e.compactWithActionsStart]: isCompactStacked && !!actionsSlotStart,
394
+ [styles$e.collapsed]: compact2 && collapsed2
628
395
  },
629
396
  inputContainerClassName
630
397
  ),
631
398
  onMouseDown: handleContainerMouseDown,
632
399
  children: [
633
- isCompactStacked && !!topSlot && /* @__PURE__ */ jsx("div", { className: styles$i.compactTopSlot, children: topSlot }),
400
+ isCompactStacked && !!topSlot && /* @__PURE__ */ jsx("div", { className: styles$e.compactTopSlot, children: topSlot }),
634
401
  !isCompactStacked && topSlot,
635
- isCompactStacked && !!actionsSlotStart && /* @__PURE__ */ jsx("div", { className: styles$i.compactActionsStart, children: actionsSlotStart }),
402
+ isCompactStacked && !!actionsSlotStart && /* @__PURE__ */ jsx("div", { className: styles$e.compactActionsStart, children: actionsSlotStart }),
636
403
  /* @__PURE__ */ jsx(
637
404
  "span",
638
405
  {
@@ -642,26 +409,26 @@ const ConversationMessageInput = (props) => {
642
409
  onCompositionStart: handleCompositionStart,
643
410
  onCompositionEnd: handleCompositionEnd,
644
411
  onKeyDown: handleKeyPress,
645
- className: `${styles$i.editableInput} ${!inputValue ? styles$i.showPlaceholder : ""}`,
412
+ className: `${styles$e.editableInput} ${!inputValue ? styles$e.showPlaceholder : ""}`,
646
413
  "data-placeholder": translatedPlaceholder,
647
414
  "data-testid": `${testId}-textarea`
648
415
  }
649
416
  ),
650
- inputValue.length >= CHARACTER_COUNTER_SHOWN_FROM_LENGTH && /* @__PURE__ */ jsx("div", { className: styles$i.statusRow, children: /* @__PURE__ */ jsx(
417
+ inputValue.length >= CHARACTER_COUNTER_SHOWN_FROM_LENGTH && /* @__PURE__ */ jsx("div", { className: styles$e.statusRow, children: /* @__PURE__ */ jsx(
651
418
  Text,
652
419
  {
653
420
  role: "caption",
654
421
  translate: false,
655
422
  color: isMessageTooLong ? "var(--agents-danger-500)" : "var(--agents-fg-lightest)",
656
- className: styles$i.characterCounter,
423
+ className: styles$e.characterCounter,
657
424
  testId: `${testId}-character-counter`,
658
425
  children: `${inputValue.length.toLocaleString()} / ${MAX_MESSAGE_LENGTH.toLocaleString()}`
659
426
  }
660
427
  ) }),
661
- /* @__PURE__ */ jsxs("div", { className: styles$i.actions, children: [
662
- !isCompactStacked && !!actionsSlotStart && /* @__PURE__ */ jsx("div", { className: styles$i.actionsStart, children: actionsSlotStart }),
428
+ /* @__PURE__ */ jsxs("div", { className: styles$e.actions, children: [
429
+ !isCompactStacked && !!actionsSlotStart && /* @__PURE__ */ jsx("div", { className: styles$e.actionsStart, children: actionsSlotStart }),
663
430
  actionsSlot,
664
- sendReplacementWhenEmpty && !hasSendableContent ? sendReplacementWhenEmpty : /* @__PURE__ */ jsx("div", { className: classNames(styles$i.ownAction, { [styles$i.sendBlocked]: isMessageTooLong }), children: /* @__PURE__ */ jsx(
431
+ sendReplacementWhenEmpty && !hasSendableContent ? sendReplacementWhenEmpty : /* @__PURE__ */ jsx("div", { className: classNames(styles$e.ownAction, { [styles$e.sendBlocked]: isMessageTooLong }), children: /* @__PURE__ */ jsx(
665
432
  Tooltip,
666
433
  {
667
434
  text: isMessageTooLong ? "Your message is over the %maxLength% character limit" : void 0,
@@ -688,7 +455,7 @@ const ConversationMessageInput = (props) => {
688
455
  )
689
456
  }
690
457
  ),
691
- measuresCollapsedPillWidth && /* @__PURE__ */ jsx("span", { ref: collapsedPillSizerRef, className: styles$i.collapsedPillSizer, "aria-hidden": "true", children: translatedPlaceholder })
458
+ measuresCollapsedPillWidth && /* @__PURE__ */ jsx("span", { ref: collapsedPillSizerRef, className: styles$e.collapsedPillSizer, "aria-hidden": "true", children: translatedPlaceholder })
692
459
  ] });
693
460
  };
694
461
  const canvasReopenControl = "agents_canvasReopenControl_7vGS8F";
@@ -758,390 +525,6 @@ const ConversationLoading = () => {
758
525
  /* @__PURE__ */ jsx(Skeleton, { className: loadingStyles.messageBody, borderRadius: SKEL_RADIUS })
759
526
  ] });
760
527
  };
761
- const message = "agents_message_BScH1l";
762
- const messageWithWidgetsAboveBubble = "agents_messageWithWidgetsAboveBubble_bWTYWp";
763
- const whiteBubble = "agents_whiteBubble_4-I21V";
764
- const darkBubble = "agents_darkBubble_YdEIoi";
765
- const primaryBubble = "agents_primaryBubble_jo9Zj-";
766
- const styles$h = {
767
- message,
768
- messageWithWidgetsAboveBubble,
769
- whiteBubble,
770
- darkBubble,
771
- primaryBubble
772
- };
773
- const ConversationMessageUserWidgets = (props) => {
774
- const { widgets } = props;
775
- if (widgets.length === 0) return null;
776
- return /* @__PURE__ */ jsx(Fragment, { children: widgets.map((widget) => {
777
- const entry = conversationWidgetRegistry.widgets.find((candidate) => candidate.name === widget.widgetName);
778
- if (!entry) return null;
779
- const Component = entry.component;
780
- return /* @__PURE__ */ jsx(ConversationWidgetErrorBoundary, { widgetName: entry.name, children: /* @__PURE__ */ jsx(Component, { payload: JSON.stringify(widget.fields), fresh: false }) }, widget.composerWidgetId);
781
- }) });
782
- };
783
- const isShownAboveBubble = (widget) => conversationWidgetRegistry.widgets.find((entry) => entry.name === widget.widgetName)?.customerMessagePlacement === "aboveBubble";
784
- const ConversationMessageUser = (props) => {
785
- const { text, isGenericChat, theme = "default" } = props;
786
- const { text: proseText, widgets } = useMemo(() => splitComposerWidgetFencesFromMessageText(text), [text]);
787
- const widgetsAboveBubble = useMemo(() => widgets.filter(isShownAboveBubble), [widgets]);
788
- const widgetsInsideBubble = useMemo(() => widgets.filter((widget) => !isShownAboveBubble(widget)), [widgets]);
789
- const bubbleClass = theme === "light" ? styles$h.whiteBubble : theme === "dark" ? styles$h.darkBubble : theme === "primary" ? styles$h.primaryBubble : void 0;
790
- const textColor = theme === "light" ? "var(--agents-fg)" : theme === "dark" ? "var(--agents-chat-user-bubble-text)" : "var(--agents-fg-on-accent)";
791
- const bubble = /* @__PURE__ */ jsxs("div", { className: classNames(styles$h.message, bubbleClass), "data-testid": "chat-message-user", children: [
792
- /* @__PURE__ */ jsx(ConversationMessageUserWidgets, { widgets: widgetsInsideBubble }),
793
- proseText !== "" && /* @__PURE__ */ jsx(Text, { allowNewLines: true, translate: false, color: textColor, children: proseText })
794
- ] });
795
- if (widgetsAboveBubble.length === 0) return bubble;
796
- return /* @__PURE__ */ jsxs("div", { className: styles$h.messageWithWidgetsAboveBubble, children: [
797
- /* @__PURE__ */ jsx(ConversationMessageUserWidgets, { widgets: widgetsAboveBubble }),
798
- (proseText !== "" || widgetsInsideBubble.length > 0) && bubble
799
- ] });
800
- };
801
- const responseContainer$2 = "agents_responseContainer_1-FSNs";
802
- const responseMessage = "agents_responseMessage_Xrs7fL";
803
- const styles$g = {
804
- responseContainer: responseContainer$2,
805
- responseMessage
806
- };
807
- const useTypewriter = (options = {}) => {
808
- const { speed = 200, commitIntervalMs = 50 } = options;
809
- const [displayedText, setDisplayedText] = useState("");
810
- const [isFinished, setIsFinished] = useState(false);
811
- const fullTextRef = useRef("");
812
- const typeRAFRef = useRef(null);
813
- const lastTimestampRef = useRef(null);
814
- const renderedLengthRef = useRef(0);
815
- const speedRef = useRef(speed);
816
- const commitIntervalRef = useRef(commitIntervalMs);
817
- const lastCommitTsRef = useRef(0);
818
- const startTypewriter = useCallback(() => {
819
- if (typeRAFRef.current !== null) return;
820
- if (renderedLengthRef.current >= fullTextRef.current.length) return;
821
- const animate = (timestamp) => {
822
- if (lastTimestampRef.current === null) {
823
- lastTimestampRef.current = timestamp;
824
- }
825
- const elapsedSeconds = (timestamp - lastTimestampRef.current) / 1e3;
826
- lastTimestampRef.current = timestamp;
827
- const charactersToAdd = Math.max(1, Math.floor(elapsedSeconds * speedRef.current));
828
- const nextLength = Math.min(fullTextRef.current.length, renderedLengthRef.current + charactersToAdd);
829
- renderedLengthRef.current = nextLength;
830
- if (timestamp - lastCommitTsRef.current >= commitIntervalRef.current || nextLength === fullTextRef.current.length) {
831
- const nextText = fullTextRef.current.slice(0, nextLength);
832
- setDisplayedText(nextText);
833
- lastCommitTsRef.current = timestamp;
834
- }
835
- if (nextLength < fullTextRef.current.length) {
836
- typeRAFRef.current = requestAnimationFrame(animate);
837
- } else {
838
- typeRAFRef.current = null;
839
- lastTimestampRef.current = null;
840
- setIsFinished(true);
841
- }
842
- };
843
- typeRAFRef.current = requestAnimationFrame(animate);
844
- }, []);
845
- const appendText = useCallback(
846
- (text) => {
847
- if (!text) return;
848
- fullTextRef.current += text;
849
- setIsFinished(false);
850
- startTypewriter();
851
- },
852
- [startTypewriter]
853
- );
854
- const stopTypewriter = useCallback(() => {
855
- if (typeRAFRef.current !== null) {
856
- cancelAnimationFrame(typeRAFRef.current);
857
- typeRAFRef.current = null;
858
- lastTimestampRef.current = null;
859
- }
860
- }, []);
861
- const finishTypewriter = useCallback(() => {
862
- stopTypewriter();
863
- setDisplayedText(fullTextRef.current);
864
- renderedLengthRef.current = fullTextRef.current.length;
865
- setIsFinished(true);
866
- }, [stopTypewriter]);
867
- return {
868
- displayedText,
869
- appendText,
870
- stopTypewriter,
871
- finishTypewriter,
872
- isFinished
873
- };
874
- };
875
- const useStreamingText = ({ eventSource, onTextChunk, onError, onDone }) => {
876
- const bufferRef = useRef("");
877
- const flushRAFRef = useRef(null);
878
- const onTextChunkRef = useRef(null);
879
- const onErrorRef = useRef(null);
880
- const onDoneRef = useRef(null);
881
- onTextChunkRef.current = onTextChunk;
882
- onErrorRef.current = onError;
883
- onDoneRef.current = onDone;
884
- const flushBuffer = useCallback(() => {
885
- flushRAFRef.current = null;
886
- if (!bufferRef.current) return;
887
- const chunk = bufferRef.current;
888
- bufferRef.current = "";
889
- onTextChunkRef.current?.(chunk);
890
- }, []);
891
- const finish = useCallback(() => {
892
- if (flushRAFRef.current !== null) {
893
- cancelAnimationFrame(flushRAFRef.current);
894
- flushRAFRef.current = null;
895
- }
896
- flushBuffer();
897
- onDoneRef.current?.();
898
- }, [flushBuffer]);
899
- const handleMessage = useCallback(
900
- (event) => {
901
- if (event.data === "[DONE]") {
902
- finish();
903
- return;
904
- }
905
- try {
906
- const parsed = JSON.parse(event.data);
907
- const piece = parsed?.choices?.[0]?.delta?.content ?? // fallback: support simple formats too
908
- (typeof parsed === "string" ? parsed : parsed?.text ?? "");
909
- const finishReason = parsed?.choices?.[0]?.finish_reason;
910
- if (piece) {
911
- bufferRef.current += piece;
912
- if (flushRAFRef.current === null) {
913
- flushRAFRef.current = requestAnimationFrame(flushBuffer);
914
- }
915
- }
916
- if (finishReason === "stop") {
917
- finish();
918
- }
919
- } catch (error) {
920
- console.error("Error parsing SSE message:", error, event.data);
921
- onErrorRef.current?.();
922
- }
923
- },
924
- [flushBuffer, finish]
925
- );
926
- const handleError = useCallback(() => {
927
- onErrorRef.current?.();
928
- if (flushRAFRef.current !== null) {
929
- cancelAnimationFrame(flushRAFRef.current);
930
- flushRAFRef.current = null;
931
- }
932
- flushBuffer();
933
- }, [flushBuffer]);
934
- useEffect(() => {
935
- if (typeof window === "undefined" || !eventSource) return;
936
- eventSource.addEventListener("message", handleMessage);
937
- eventSource.addEventListener("error", handleError);
938
- return () => {
939
- eventSource.removeEventListener("message", handleMessage);
940
- eventSource.removeEventListener("error", handleError);
941
- if (flushRAFRef.current !== null) {
942
- cancelAnimationFrame(flushRAFRef.current);
943
- flushRAFRef.current = null;
944
- }
945
- flushBuffer();
946
- };
947
- }, [eventSource, handleMessage, handleError, flushBuffer]);
948
- };
949
- const STAGGER_STEP_MS = 90;
950
- const STAGGER_CAP_MS = 720;
951
- const INITIAL_FADE_MS = 550;
952
- const SCROLL_REVEAL_ROOT_MARGIN = "0px";
953
- const VISIBILITY_DEADLINE_MS = 2500;
954
- const alreadyRevealedMessageIds = /* @__PURE__ */ new Set();
955
- const useFreshMessageBlockReveal = (options) => {
956
- const { containerRef, enabled, messageId } = options;
957
- const scrollRoot = useContext(WidgetWindowRootContext);
958
- useLayoutEffect(() => {
959
- if (!enabled) return;
960
- if (messageId != null && alreadyRevealedMessageIds.has(messageId)) return;
961
- if (typeof IntersectionObserver === "undefined") return;
962
- if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) return;
963
- if (scrollRoot == null) return;
964
- const blocksRoot = containerRef.current?.querySelector(":scope > [data-markdown-blocks-root]");
965
- if (blocksRoot == null) return;
966
- const blocks = Array.from(blocksRoot.children);
967
- if (blocks.length === 0) return;
968
- for (const block of blocks) block.dataset.blockReveal = "hidden";
969
- if (messageId != null) alreadyRevealedMessageIds.add(messageId);
970
- let finalized = false;
971
- let scrollRevealObserver = null;
972
- let initialViewportObserver = null;
973
- const finalize = () => {
974
- if (finalized) return;
975
- finalized = true;
976
- initialViewportObserver?.disconnect();
977
- scrollRevealObserver?.disconnect();
978
- for (const block of blocks) {
979
- if (block.dataset.blockReveal === "hidden") {
980
- delete block.dataset.blockReveal;
981
- block.style.animationDelay = "";
982
- block.style.animationDuration = "";
983
- }
984
- }
985
- };
986
- const deadline = window.setTimeout(finalize, VISIBILITY_DEADLINE_MS);
987
- scrollRevealObserver = new IntersectionObserver(
988
- (entries, observer) => {
989
- if (finalized) return;
990
- for (const entry of entries) {
991
- if (!entry.isIntersecting) continue;
992
- entry.target.dataset.blockReveal = "revealed";
993
- observer.unobserve(entry.target);
994
- }
995
- },
996
- { root: scrollRoot, rootMargin: SCROLL_REVEAL_ROOT_MARGIN, threshold: 0 }
997
- );
998
- initialViewportObserver = new IntersectionObserver(
999
- (entries, observer) => {
1000
- if (finalized) return;
1001
- let staggerIndex = 0;
1002
- for (const entry of entries) {
1003
- const block = entry.target;
1004
- if (entry.isIntersecting) {
1005
- block.style.animationDelay = `${Math.min(staggerIndex * STAGGER_STEP_MS, STAGGER_CAP_MS)}ms`;
1006
- block.style.animationDuration = `${INITIAL_FADE_MS}ms`;
1007
- staggerIndex++;
1008
- block.dataset.blockReveal = "revealed";
1009
- } else {
1010
- scrollRevealObserver?.observe(block);
1011
- }
1012
- }
1013
- observer.disconnect();
1014
- },
1015
- { root: scrollRoot, threshold: 0 }
1016
- );
1017
- for (const block of blocks) initialViewportObserver.observe(block);
1018
- return () => {
1019
- window.clearTimeout(deadline);
1020
- finalize();
1021
- };
1022
- }, [enabled, messageId, scrollRoot, containerRef]);
1023
- };
1024
- const iconContainer$1 = "agents_iconContainer_JupHNn";
1025
- const responseHeader$1 = "agents_responseHeader_ulXYcn";
1026
- const styles$f = {
1027
- iconContainer: iconContainer$1,
1028
- responseHeader: responseHeader$1
1029
- };
1030
- const ConversationMessageHeader = memo((props) => {
1031
- const { aiPromptExtensionCategory, aiPromptExtension } = props;
1032
- const iconName = aiPromptExtension?.iconClass ?? "ai";
1033
- return /* @__PURE__ */ jsxs("div", { className: styles$f.responseHeader, children: [
1034
- /* @__PURE__ */ jsx("span", { className: styles$f.iconContainer, children: /* @__PURE__ */ jsx(Icon, { color: "var(--agents-fg-on-accent)", hostIconName: iconName }) }),
1035
- /* @__PURE__ */ jsxs("div", { children: [
1036
- /* @__PURE__ */ jsx(Text, { role: "help", weight: "bold", children: aiPromptExtension?.name ?? "AI Extensions" }),
1037
- aiPromptExtensionCategory !== void 0 ? /* @__PURE__ */ jsx(Text, { role: "caption", replacements: { productName: aiPromptExtensionCategory?.name }, children: "%productName% Assistant" }) : null,
1038
- aiPromptExtensionCategory === void 0 ? /* @__PURE__ */ jsx(Text, { role: "caption", children: "Assistant" }) : null
1039
- ] })
1040
- ] });
1041
- });
1042
- async function copyRichToClipboard(plainText, html) {
1043
- if (!plainText) {
1044
- console.warn("No text to copy");
1045
- return;
1046
- }
1047
- if (!navigator.clipboard) {
1048
- console.warn("Clipboard API not available");
1049
- return;
1050
- }
1051
- if (!(html && typeof ClipboardItem !== "undefined" && navigator.clipboard.write)) {
1052
- console.warn("Clipboard does not support rich text, copying plain text only");
1053
- return navigator.clipboard.writeText(plainText);
1054
- }
1055
- try {
1056
- const item = new ClipboardItem({
1057
- "text/plain": new Blob([plainText], { type: "text/plain" }),
1058
- "text/html": new Blob([html], { type: "text/html" })
1059
- });
1060
- return navigator.clipboard.write([item]);
1061
- } catch (error) {
1062
- console.error("Failed to copy rich text to clipboard:", error);
1063
- return navigator.clipboard.writeText(plainText);
1064
- }
1065
- }
1066
- const ConversationMessageWidgets = memo((props) => {
1067
- const {
1068
- aiPromptExtensionCategory,
1069
- aiPromptExtension,
1070
- eventSource,
1071
- message: message2,
1072
- interactive = false,
1073
- justDelivered = false,
1074
- hideWidgets = false,
1075
- hideAssistantMeta = false,
1076
- enableFreshMessageBlockReveal = false,
1077
- messageId
1078
- } = props;
1079
- const { MessageFooter } = useAgentsEnvironment();
1080
- const [copied, setCopied] = useState(false);
1081
- const timeoutRef = useRef(null);
1082
- const renderedRef = useRef(null);
1083
- const { displayedText, appendText, finishTypewriter } = useTypewriter({
1084
- speed: 200,
1085
- commitIntervalMs: 100
1086
- });
1087
- useEffect(() => {
1088
- return () => {
1089
- if (timeoutRef.current != null) window.clearTimeout(timeoutRef.current);
1090
- };
1091
- }, []);
1092
- useStreamingText({
1093
- eventSource: message2 != null ? void 0 : eventSource,
1094
- onTextChunk: appendText,
1095
- onError: finishTypewriter,
1096
- onDone: finishTypewriter
1097
- });
1098
- const textToRender = message2 != null ? normalizeServerMessageToMarkdown(message2) : stripPreCallMessageMarker(displayedText);
1099
- useFreshMessageBlockReveal({
1100
- containerRef: renderedRef,
1101
- enabled: enableFreshMessageBlockReveal && justDelivered && message2 != null,
1102
- messageId
1103
- });
1104
- const onCopy = useCallback(async () => {
1105
- const fallbackText = textToRender || "";
1106
- const plain = renderedRef.current?.innerText?.trim() || fallbackText;
1107
- const html = renderedRef.current?.innerHTML || "";
1108
- await copyRichToClipboard(plain, html);
1109
- setCopied(true);
1110
- if (timeoutRef.current != null) window.clearTimeout(timeoutRef.current);
1111
- timeoutRef.current = window.setTimeout(() => setCopied(false), 2e3);
1112
- }, [textToRender]);
1113
- return /* @__PURE__ */ jsxs("div", { className: styles$g.responseContainer, children: [
1114
- !hideAssistantMeta ? /* @__PURE__ */ jsx(
1115
- ConversationMessageHeader,
1116
- {
1117
- aiPromptExtensionCategory,
1118
- aiPromptExtension
1119
- }
1120
- ) : null,
1121
- /* @__PURE__ */ jsxs("div", { className: styles$g.responseMessage, children: [
1122
- /* @__PURE__ */ jsx("div", { ref: renderedRef, children: /* @__PURE__ */ jsx(
1123
- ConversationMarkdown,
1124
- {
1125
- markdown: textToRender,
1126
- interactive,
1127
- justDelivered,
1128
- messageId: messageId ?? void 0,
1129
- hideWidgets
1130
- }
1131
- ) }),
1132
- !hideAssistantMeta ? /* @__PURE__ */ jsx(
1133
- Button,
1134
- {
1135
- variant: "muted",
1136
- icon: copied ? "check" : "duplicate",
1137
- onClick: onCopy,
1138
- size: "small"
1139
- }
1140
- ) : null
1141
- ] }),
1142
- MessageFooter ? /* @__PURE__ */ jsx(MessageFooter, { message: message2 }) : null
1143
- ] });
1144
- });
1145
528
  let widgetNames;
1146
529
  let widgetNamesRevision = -1;
1147
530
  const getWidgetNames = () => {
@@ -1188,29 +571,29 @@ const isBareUnknownTypeJson = (markdown) => {
1188
571
  if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return false;
1189
572
  return typeof parsed.type === "string";
1190
573
  };
1191
- const assistantMessageHasRenderableMarkdown = (message2) => {
1192
- if (message2 == null) return false;
1193
- if (typeof message2 === "string" && message2.trim() === "") return false;
1194
- const markdown = normalizeServerMessageToMarkdown(message2).trim();
574
+ const assistantMessageHasRenderableMarkdown = (message) => {
575
+ if (message == null) return false;
576
+ if (typeof message === "string" && message.trim() === "") return false;
577
+ const markdown = normalizeServerMessageToMarkdown(message).trim();
1195
578
  return markdown !== "" && !isBareUnknownTypeJson(markdown);
1196
579
  };
1197
580
  const responseContainer$1 = "agents_responseContainer_LFzKoO";
1198
- const styles$e = {
581
+ const styles$d = {
1199
582
  responseContainer: responseContainer$1
1200
583
  };
1201
584
  const responseHeaderLayout = "agents_responseHeaderLayout_WuoaNs";
1202
585
  const iconContainer = "agents_iconContainer_C1c9yQ";
1203
586
  const responseHeader = "agents_responseHeader_-CQw8U";
1204
- const styles$d = {
587
+ const styles$c = {
1205
588
  responseHeaderLayout,
1206
589
  iconContainer,
1207
590
  responseHeader
1208
591
  };
1209
592
  const ConversationMessageSystemHeader = memo((props) => {
1210
593
  const { aiPromptExtensionCategory, aiPromptExtension, isContentExpanded, onExpandContentClick } = props;
1211
- return /* @__PURE__ */ jsxs("div", { className: styles$d.responseHeaderLayout, children: [
1212
- /* @__PURE__ */ jsxs("div", { className: styles$d.responseHeader, children: [
1213
- /* @__PURE__ */ jsx("span", { className: styles$d.iconContainer, children: /* @__PURE__ */ jsx(Icon, { color: "var(--agents-fg-on-accent)", name: "wizard" }) }),
594
+ return /* @__PURE__ */ jsxs("div", { className: styles$c.responseHeaderLayout, children: [
595
+ /* @__PURE__ */ jsxs("div", { className: styles$c.responseHeader, children: [
596
+ /* @__PURE__ */ jsx("span", { className: styles$c.iconContainer, children: /* @__PURE__ */ jsx(Icon, { color: "var(--agents-fg-on-accent)", name: "wizard" }) }),
1214
597
  /* @__PURE__ */ jsxs("div", { children: [
1215
598
  /* @__PURE__ */ jsx(Text, { role: "help", weight: "bold", children: aiPromptExtension?.name ?? "AI Extensions" }),
1216
599
  aiPromptExtensionCategory !== void 0 ? /* @__PURE__ */ jsxs(Text, { role: "caption", children: [
@@ -1220,7 +603,7 @@ const ConversationMessageSystemHeader = memo((props) => {
1220
603
  aiPromptExtensionCategory === void 0 ? /* @__PURE__ */ jsx(Text, { role: "caption", children: "System" }) : null
1221
604
  ] })
1222
605
  ] }),
1223
- /* @__PURE__ */ jsx("div", { className: styles$d.responseHeaderAction, children: /* @__PURE__ */ jsx(
606
+ /* @__PURE__ */ jsx("div", { className: styles$c.responseHeaderAction, children: /* @__PURE__ */ jsx(
1224
607
  Button,
1225
608
  {
1226
609
  variant: "muted",
@@ -1231,9 +614,9 @@ const ConversationMessageSystemHeader = memo((props) => {
1231
614
  ] });
1232
615
  });
1233
616
  const ConversationMessageSystem = memo((props) => {
1234
- const { aiPromptExtensionCategory, aiPromptExtension, message: message2 } = props;
617
+ const { aiPromptExtensionCategory, aiPromptExtension, message } = props;
1235
618
  const [isContentExpanded, setIsContentExpanded] = useState(false);
1236
- return /* @__PURE__ */ jsxs("div", { className: styles$e.responseContainer, children: [
619
+ return /* @__PURE__ */ jsxs("div", { className: styles$d.responseContainer, children: [
1237
620
  /* @__PURE__ */ jsx(
1238
621
  ConversationMessageSystemHeader,
1239
622
  {
@@ -1243,17 +626,9 @@ const ConversationMessageSystem = memo((props) => {
1243
626
  isContentExpanded
1244
627
  }
1245
628
  ),
1246
- /* @__PURE__ */ jsx("div", { style: { display: isContentExpanded ? void 0 : "none" }, children: /* @__PURE__ */ jsx("div", { className: styles$e.responseMessage, children: /* @__PURE__ */ jsx(Markdown, { markdown: message2 }) }) })
629
+ /* @__PURE__ */ jsx("div", { style: { display: isContentExpanded ? void 0 : "none" }, children: /* @__PURE__ */ jsx("div", { className: styles$d.responseMessage, children: /* @__PURE__ */ jsx(Markdown, { markdown: message }) }) })
1247
630
  ] });
1248
631
  });
1249
- const icon = "agents_icon_DD3OXD";
1250
- const styles$c = {
1251
- icon
1252
- };
1253
- const VoiceBarsIcon = (props) => {
1254
- const { size = 18 } = props;
1255
- return /* @__PURE__ */ jsx("svg", { className: styles$c.icon, width: size, height: size, viewBox: "0 0 24 24", "aria-hidden": true, focusable: "false", children: /* @__PURE__ */ jsx("path", { d: "M3.5 10.5v3M7.75 8v8M12 4.5v15M16.25 8v8M20.5 10.5v3" }) });
1256
- };
1257
632
  const markerRow = "agents_markerRow_zl8Pcg";
1258
633
  const markerChip = "agents_markerChip_u9Z-aO";
1259
634
  const markerIcon = "agents_markerIcon_En-miz";
@@ -1386,7 +761,7 @@ const ConversationErrorWidget = (props) => {
1386
761
  setRetrying(false);
1387
762
  }
1388
763
  }, [onRetry, retrying]);
1389
- const { icon: icon2, title: title2, description, replacements } = useMemo(() => {
764
+ const { icon, title: title2, description, replacements } = useMemo(() => {
1390
765
  let title22 = "Network error";
1391
766
  let description2 = "We’re sorry, something went wrong. Please refresh the page or try again later.";
1392
767
  let replacements2 = void 0;
@@ -1431,7 +806,7 @@ const ConversationErrorWidget = (props) => {
1431
806
  return /* @__PURE__ */ jsxs("div", { className: styles$8.errorMessageContainer, children: [
1432
807
  /* @__PURE__ */ jsxs("div", { children: [
1433
808
  /* @__PURE__ */ jsxs("div", { className: styles$8.errorMessageTitle, children: [
1434
- /* @__PURE__ */ jsx(Icon, { name: icon2 }),
809
+ /* @__PURE__ */ jsx(Icon, { name: icon }),
1435
810
  /* @__PURE__ */ jsx(Text, { weight: "bold", children: title2 })
1436
811
  ] }),
1437
812
  /* @__PURE__ */ jsx(Text, { replacements, children: description })
@@ -1441,13 +816,13 @@ const ConversationErrorWidget = (props) => {
1441
816
  ] });
1442
817
  };
1443
818
  const WIDGET_VISIBILITY_WINDOW = 15;
1444
- const widgetNamesOfMessage = (message2) => message2.role === "ASSISTANT" ? widgetNamesInMarkdown(normalizeServerMessageToMarkdown(message2.message)) : [];
819
+ const widgetNamesOfMessage = (message) => message.role === "ASSISTANT" ? widgetNamesInMarkdown(normalizeServerMessageToMarkdown(message.message)) : [];
1445
820
  const findUnansweredWidgetMessageId = (messages) => {
1446
821
  for (let index = messages.length - 1; index >= 0; index -= 1) {
1447
- const message2 = messages[index];
1448
- if (message2.role === "USER") return null;
1449
- if (message2.messageType === "SIGNAL" && isWidgetClickSignalSource(message2.signalSource)) return null;
1450
- if (widgetNamesOfMessage(message2).length > 0) return message2.id ?? null;
822
+ const message = messages[index];
823
+ if (message.role === "USER") return null;
824
+ if (message.messageType === "SIGNAL" && isWidgetClickSignalSource(message.signalSource)) return null;
825
+ if (widgetNamesOfMessage(message).length > 0) return message.id ?? null;
1451
826
  }
1452
827
  return null;
1453
828
  };
@@ -1455,14 +830,14 @@ const findSupersededWidgetMessageIds = (messages) => {
1455
830
  const supersededIds = /* @__PURE__ */ new Set();
1456
831
  const newestMessageIdByWidgetName = /* @__PURE__ */ new Map();
1457
832
  for (let index = messages.length - 1; index >= 0; index -= 1) {
1458
- const message2 = messages[index];
1459
- if (message2.id == null) continue;
1460
- for (const widgetName of widgetNamesOfMessage(message2)) {
833
+ const message = messages[index];
834
+ if (message.id == null) continue;
835
+ for (const widgetName of widgetNamesOfMessage(message)) {
1461
836
  const newestMessageId = newestMessageIdByWidgetName.get(widgetName);
1462
837
  if (newestMessageId === void 0) {
1463
- newestMessageIdByWidgetName.set(widgetName, message2.id);
1464
- } else if (newestMessageId !== message2.id) {
1465
- supersededIds.add(message2.id);
838
+ newestMessageIdByWidgetName.set(widgetName, message.id);
839
+ } else if (newestMessageId !== message.id) {
840
+ supersededIds.add(message.id);
1466
841
  }
1467
842
  }
1468
843
  }
@@ -1497,54 +872,54 @@ const ConversationMessageList = ({
1497
872
  reloadReopenMessageIdRef.current = findUnansweredWidgetMessageId(list);
1498
873
  }
1499
874
  const supersededWidgetMessageIds = useMemo(() => findSupersededWidgetMessageIds(messages ?? []), [messages]);
1500
- const renderMessageRow = (message2, index) => {
875
+ const renderMessageRow = (message, index) => {
1501
876
  const hideWidgets = index < hideWidgetsBeforeIndex;
1502
- if (message2.messageType === "SIGNAL" && PHONE_CALL_LIFECYCLE_SIGNAL_SOURCES.includes(message2.signalSource ?? "")) {
877
+ if (message.messageType === "SIGNAL" && PHONE_CALL_LIFECYCLE_SIGNAL_SOURCES.includes(message.signalSource ?? "")) {
1503
878
  return /* @__PURE__ */ jsx(
1504
879
  ConversationCallMarkerChip,
1505
880
  {
1506
- signalSource: message2.signalSource ?? "",
1507
- signalText: message2.message ?? ""
881
+ signalSource: message.signalSource ?? "",
882
+ signalText: message.message ?? ""
1508
883
  },
1509
- message2.id ?? index
884
+ message.id ?? index
1510
885
  );
1511
886
  }
1512
- if (message2.messageType === "SIGNAL") return null;
1513
- if (message2.messageType === "ERROR") return null;
887
+ if (message.messageType === "SIGNAL") return null;
888
+ if (message.messageType === "ERROR") return null;
1514
889
  let messageNode = null;
1515
- if (message2.role === "USER") {
1516
- if (message2.message?.startsWith("/toolresult ")) return null;
1517
- messageNode = taskInstructionMessageId != null && message2.id === taskInstructionMessageId ? /* @__PURE__ */ jsx(ConversationTaskInstructionDisclosure, { instructionText: message2.message ?? "" }) : /* @__PURE__ */ jsx(ConversationMessageUser, { text: message2.message ?? "", theme: userTheme });
1518
- } else if (message2.role === "ASSISTANT") {
1519
- if (!assistantMessageHasRenderableMarkdown(message2.message)) return null;
890
+ if (message.role === "USER") {
891
+ if (message.message?.startsWith("/toolresult ")) return null;
892
+ messageNode = taskInstructionMessageId != null && message.id === taskInstructionMessageId ? /* @__PURE__ */ jsx(ConversationTaskInstructionDisclosure, { instructionText: message.message ?? "" }) : /* @__PURE__ */ jsx(ConversationMessageUser, { text: message.message ?? "", theme: userTheme });
893
+ } else if (message.role === "ASSISTANT") {
894
+ if (!assistantMessageHasRenderableMarkdown(message.message)) return null;
1520
895
  messageNode = /* @__PURE__ */ jsx(
1521
896
  ConversationMessageWidgets,
1522
897
  {
1523
- interactive: !isConversationClosed && !(message2.id != null && supersededWidgetMessageIds.has(message2.id)) && ((message2.fresh ?? false) || message2.id != null && message2.id === reloadReopenMessageIdRef.current),
1524
- justDelivered: message2.fresh ?? false,
898
+ interactive: !isConversationClosed && !(message.id != null && supersededWidgetMessageIds.has(message.id)) && ((message.fresh ?? false) || message.id != null && message.id === reloadReopenMessageIdRef.current),
899
+ justDelivered: message.fresh ?? false,
1525
900
  aiPromptExtensionCategory: currentCategory,
1526
901
  aiPromptExtension,
1527
- message: message2.message,
1528
- messageId: message2.id,
902
+ message: message.message,
903
+ messageId: message.id,
1529
904
  hideWidgets,
1530
905
  hideAssistantMeta,
1531
906
  enableFreshMessageBlockReveal
1532
907
  },
1533
- message2.id
908
+ message.id
1534
909
  );
1535
910
  if (renderAssistantAvatar) {
1536
911
  messageNode = /* @__PURE__ */ jsxs("div", { className: classes$1.assistantMessageWithAvatar, children: [
1537
- /* @__PURE__ */ jsx("div", { className: classes$1.assistantAvatar, children: renderAssistantAvatar(message2) }),
912
+ /* @__PURE__ */ jsx("div", { className: classes$1.assistantAvatar, children: renderAssistantAvatar(message) }),
1538
913
  /* @__PURE__ */ jsx("div", { className: classes$1.assistantMessageBesideAvatar, children: messageNode })
1539
- ] }, message2.id);
914
+ ] }, message.id);
1540
915
  }
1541
- } else if (message2.role === "SYSTEM" && isDebugMode) {
916
+ } else if (message.role === "SYSTEM" && isDebugMode) {
1542
917
  messageNode = /* @__PURE__ */ jsx(
1543
918
  ConversationMessageSystem,
1544
919
  {
1545
920
  aiPromptExtensionCategory: currentCategory,
1546
921
  aiPromptExtension,
1547
- message: message2.message
922
+ message: message.message
1548
923
  }
1549
924
  );
1550
925
  }
@@ -1553,23 +928,23 @@ const ConversationMessageList = ({
1553
928
  "div",
1554
929
  {
1555
930
  className: classes$1.messageRow,
1556
- "data-message-id": message2.id ?? void 0,
1557
- "data-message-role": message2.role,
931
+ "data-message-id": message.id ?? void 0,
932
+ "data-message-role": message.role,
1558
933
  children: messageNode
1559
934
  },
1560
- message2.id ?? `pending-${message2.role}-${index}`
935
+ message.id ?? `pending-${message.role}-${index}`
1561
936
  );
1562
937
  };
1563
938
  return /* @__PURE__ */ jsxs("div", { className: classNames(classes$1.chatMessages, className), ref: messagesListRef, children: [
1564
939
  list.map(
1565
- (message2, index) => renderAfterMessage ? (
940
+ (message, index) => renderAfterMessage ? (
1566
941
  // Keyed like the row itself and present for every row, so a node that appears after a message never
1567
942
  // changes the row's position in the tree (and never remounts the message and its widgets).
1568
- /* @__PURE__ */ jsxs(Fragment$1, { children: [
1569
- renderMessageRow(message2, index),
1570
- renderAfterMessage(message2)
1571
- ] }, message2.id ?? `pending-${message2.role}-${index}`)
1572
- ) : renderMessageRow(message2, index)
943
+ /* @__PURE__ */ jsxs(Fragment, { children: [
944
+ renderMessageRow(message, index),
945
+ renderAfterMessage(message)
946
+ ] }, message.id ?? `pending-${message.role}-${index}`)
947
+ ) : renderMessageRow(message, index)
1573
948
  ),
1574
949
  thinkingIndicator ?? (aiThinking ? /* @__PURE__ */ jsx(
1575
950
  ConversationMessageThinking,
@@ -1842,7 +1217,7 @@ const ConversationViewBody = (props) => {
1842
1217
  );
1843
1218
  const { readAssistantThemeClassName, AssistantBackground } = useAgentsEnvironment();
1844
1219
  const colorPalette = useMemo(
1845
- () => currentCategory?.alias ? readAssistantThemeClassName?.(currentCategory.alias) ?? styles$j.genericChat : styles$j.genericChat,
1220
+ () => currentCategory?.alias ? readAssistantThemeClassName?.(currentCategory.alias) ?? styles$f.genericChat : styles$f.genericChat,
1846
1221
  [currentCategory, readAssistantThemeClassName]
1847
1222
  );
1848
1223
  const isMessageListVisible = !!messages && (!!conversationId || !!showMessagesWithoutConversation) || startingNewConversation || !!error && error !== ConversationErrorType.CONVERSATION_NOT_FOUND;
@@ -2047,7 +1422,7 @@ const ConversationViewBody = (props) => {
2047
1422
  const messageColumn = /* @__PURE__ */ jsxs(
2048
1423
  "div",
2049
1424
  {
2050
- className: styles$j.contentWrapper,
1425
+ className: styles$f.contentWrapper,
2051
1426
  "data-agents-chat-scroll": "",
2052
1427
  "data-testid": "chat-messages-scroll",
2053
1428
  ref: handleContentWrapperRef,
@@ -2065,11 +1440,11 @@ const ConversationViewBody = (props) => {
2065
1440
  onSuggestionClick
2066
1441
  }
2067
1442
  ) : null,
2068
- !!loadingOlder ? /* @__PURE__ */ jsx("span", { className: styles$j.olderLoading, children: /* @__PURE__ */ jsx(Text, { children: "Loading older messages…" }) }) : null,
2069
- isMessageListVisible ? /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(WidgetWindowRootContext.Provider, { value: scrollContainer, children: /* @__PURE__ */ jsx(
1443
+ !!loadingOlder ? /* @__PURE__ */ jsx("span", { className: styles$f.olderLoading, children: /* @__PURE__ */ jsx(Text, { children: "Loading older messages…" }) }) : null,
1444
+ isMessageListVisible ? /* @__PURE__ */ jsx(Fragment$1, { children: /* @__PURE__ */ jsx(WidgetWindowRootContext.Provider, { value: scrollContainer, children: /* @__PURE__ */ jsx(
2070
1445
  ConversationMessageList,
2071
1446
  {
2072
- className: enablePinQuestionAndRevealAnswer && (conversationId || startingNewConversation || aiThinking || error) ? styles$j.topAlignedMessages : void 0,
1447
+ className: enablePinQuestionAndRevealAnswer && (conversationId || startingNewConversation || aiThinking || error) ? styles$f.topAlignedMessages : void 0,
2073
1448
  messages,
2074
1449
  currentCategory,
2075
1450
  aiPromptExtension,
@@ -2097,46 +1472,46 @@ const ConversationViewBody = (props) => {
2097
1472
  "div",
2098
1473
  {
2099
1474
  className: classNames(
2100
- styles$j.chat,
2101
- background || backgroundPaintedByHost2 ? styles$j.customBg : colorPalette,
2102
- backgroundPaintedByHost2 ? styles$j.backgroundPaintedByHost : void 0,
2103
- isCompact ? styles$j.chatCompact : void 0,
2104
- confineTopBlurBandToChatPane2 ? styles$j.confineTopBlurBandToChatPane : void 0
1475
+ styles$f.chat,
1476
+ background || backgroundPaintedByHost2 ? styles$f.customBg : colorPalette,
1477
+ backgroundPaintedByHost2 ? styles$f.backgroundPaintedByHost : void 0,
1478
+ isCompact ? styles$f.chatCompact : void 0,
1479
+ confineTopBlurBandToChatPane2 ? styles$f.confineTopBlurBandToChatPane : void 0
2105
1480
  ),
2106
1481
  children: [
2107
- background ? /* @__PURE__ */ jsx("div", { className: styles$j.backgroundLayer, children: background }) : backgroundPaintedByHost2 ? null : AssistantBackground ? /* @__PURE__ */ jsx(AssistantBackground, { category: currentCategory, categoryAlias: currentCategory?.alias ?? void 0 }) : null,
1482
+ background ? /* @__PURE__ */ jsx("div", { className: styles$f.backgroundLayer, children: background }) : backgroundPaintedByHost2 ? null : AssistantBackground ? /* @__PURE__ */ jsx(AssistantBackground, { category: currentCategory, categoryAlias: currentCategory?.alias ?? void 0 }) : null,
2108
1483
  progressStepperSlot,
2109
1484
  fileDropHintSlot,
2110
- contentOverlaySlot !== void 0 ? /* @__PURE__ */ jsxs("div", { className: styles$j.contentLayers, "data-overlay-shown": isContentOverlayShown || void 0, children: [
1485
+ contentOverlaySlot !== void 0 ? /* @__PURE__ */ jsxs("div", { className: styles$f.contentLayers, "data-overlay-shown": isContentOverlayShown || void 0, children: [
2111
1486
  messageColumn,
2112
1487
  /* @__PURE__ */ jsx(
2113
1488
  "div",
2114
1489
  {
2115
- className: styles$j.contentOverlay,
1490
+ className: styles$f.contentOverlay,
2116
1491
  "aria-hidden": !isContentOverlayShown || void 0,
2117
1492
  inert: !isContentOverlayShown || void 0,
2118
1493
  children: contentOverlaySlot
2119
1494
  }
2120
1495
  )
2121
1496
  ] }) : messageColumn,
2122
- enablePinQuestionAndRevealAnswer && /* @__PURE__ */ jsx("div", { className: styles$j.scrollToLatestAnchor, children: /* @__PURE__ */ jsx(
1497
+ enablePinQuestionAndRevealAnswer && /* @__PURE__ */ jsx("div", { className: styles$f.scrollToLatestAnchor, children: /* @__PURE__ */ jsx(
2123
1498
  ConversationScrollToLatestMessageButton,
2124
1499
  {
2125
1500
  visible: isMessagesBottomOutOfView,
2126
1501
  onClick: scrollToLatestMessage
2127
1502
  }
2128
1503
  ) }),
2129
- inputReplacementSlot ? /* @__PURE__ */ jsx("div", { className: styles$j.inputReplacement, children: inputReplacementSlot }) : /* @__PURE__ */ jsxs(Fragment, { children: [
1504
+ inputReplacementSlot ? /* @__PURE__ */ jsx("div", { className: styles$f.inputReplacement, children: inputReplacementSlot }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [
2130
1505
  inputBandSlot,
2131
1506
  /* @__PURE__ */ jsx(
2132
1507
  ConversationMessageInput,
2133
1508
  {
2134
- className: classNames(styles$j.input, currentCategory?.alias ? styles$j.inputInCategory : void 0),
1509
+ className: classNames(styles$f.input, currentCategory?.alias ? styles$f.inputInCategory : void 0),
2135
1510
  isProcessing: allowSendWhileAiThinking ? !!startingNewConversation : aiThinking,
2136
1511
  onSendMessage,
2137
1512
  actionsSlot: inputActionsSlot,
2138
1513
  actionsSlotStart: inputActionsSlotStart,
2139
- topSlot: /* @__PURE__ */ jsxs(Fragment, { children: [
1514
+ topSlot: /* @__PURE__ */ jsxs(Fragment$1, { children: [
2140
1515
  /* @__PURE__ */ jsx(ConversationMessageInputComposerWidgets, { testId: "chat-input" }),
2141
1516
  inputTopSlot
2142
1517
  ] }),
@@ -2181,7 +1556,7 @@ const OpeningLoader = () => (
2181
1556
  /* @__PURE__ */ jsx("div", { className: classes.openingLoader, "aria-hidden": true, children: /* @__PURE__ */ jsx(LoadingSpinner, {}) })
2182
1557
  );
2183
1558
  const CanvasPane = ({ messages, boxed = false }) => {
2184
- const CanvasBodyContainer = useAgentsEnvironment().CanvasBodyContainer ?? Fragment$1;
1559
+ const CanvasBodyContainer = useAgentsEnvironment().CanvasBodyContainer ?? Fragment;
2185
1560
  const { canvas, closeCanvas, chatAgentSpaceKey } = useConversationWidgetContext();
2186
1561
  const mountGeneration = canvas?.mountGeneration;
2187
1562
  const [contentReady, setContentReady] = useState(false);
@@ -2198,7 +1573,7 @@ const CanvasPane = ({ messages, boxed = false }) => {
2198
1573
  const behaviour = canvasBehaviourOf(canvas.canvasId);
2199
1574
  const featureFlag = canvasFeatureFlagOf(canvas.canvasId);
2200
1575
  const anchor = canvas.anchor;
2201
- const anchorMessage = anchor.kind === "message" ? (messages ?? []).find((message2) => message2.id === anchor.messageId) : void 0;
1576
+ const anchorMessage = anchor.kind === "message" ? (messages ?? []).find((message) => message.id === anchor.messageId) : void 0;
2202
1577
  const anchorMessageMarkdown = anchorMessage !== void 0 ? normalizeServerMessageToMarkdown(anchorMessage.message) : null;
2203
1578
  const body = /* @__PURE__ */ jsx(Body, { canvas, agentSpaceKey: chatAgentSpaceKey, anchorMessageMarkdown });
2204
1579
  return /* @__PURE__ */ jsxs(
@@ -2500,9 +1875,9 @@ const ConversationView = (props) => {
2500
1875
  const canvasBehaviour = canvas ? canvasBehaviourOf(canvas.canvasId) ?? null : null;
2501
1876
  const isCanvasOpen = canvas !== null;
2502
1877
  useCanvasShellTransitions({ conversationId, canvasViable });
2503
- const handleSendMessage = (message2, options) => {
1878
+ const handleSendMessage = (message, options) => {
2504
1879
  resetCanvasForNewTurn();
2505
- onSendMessage(message2, options);
1880
+ onSendMessage(message, options);
2506
1881
  };
2507
1882
  const lastCanvasWidthPercentRef = useRef(DEFAULT_CANVAS_WIDTH_PERCENT);
2508
1883
  if (canvasBehaviour) lastCanvasWidthPercentRef.current = canvasWidthPercentOf(canvasBehaviour);
@@ -3182,7 +2557,7 @@ class ChatStoreLiveUpdateReads {
3182
2557
  this.readConversationMetadata = () => {
3183
2558
  void this.messagePagesRef.current.readConversationMetadata(this.conversationId);
3184
2559
  };
3185
- this.hasLoadedMessage = (messageId) => (this.chatStore.getState().messages ?? []).some((message2) => message2.id === messageId);
2560
+ this.hasLoadedMessage = (messageId) => (this.chatStore.getState().messages ?? []).some((message) => message.id === messageId);
3186
2561
  }
3187
2562
  }
3188
2563
  class RunStatusOnlyLiveUpdateReads {
@@ -3598,7 +2973,7 @@ const useConversationSignals = (inputs) => {
3598
2973
  if (runStatus !== "idle" || !sawRunningForWidgetCheckRef.current) return;
3599
2974
  if (widgetCorrectionCountRef.current >= WIDGET_CORRECTION_CAP || !messages) return;
3600
2975
  const latestAssistantMessage = [...messages].reverse().find(
3601
- (message2) => message2.role === "ASSISTANT" && message2.messageType === "TEXT"
2976
+ (message) => message.role === "ASSISTANT" && message.messageType === "TEXT"
3602
2977
  );
3603
2978
  const messageId = latestAssistantMessage?.id;
3604
2979
  if (!messageId || !latestAssistantMessage?.message) return;
@@ -3632,7 +3007,7 @@ const useConversationSignals = (inputs) => {
3632
3007
  useEffect(() => () => renderReportCollector.dispose(), [renderReportCollector]);
3633
3008
  return { handleInjectSignal, renderReportCollector };
3634
3009
  };
3635
- const hasBudgetReachedError = (messages) => (messages ?? []).some((message2) => message2.messageType === "ERROR" && message2.signalSource === "AI_BUDGET_REACHED");
3010
+ const hasBudgetReachedError = (messages) => (messages ?? []).some((message) => message.messageType === "ERROR" && message.signalSource === "AI_BUDGET_REACHED");
3636
3011
  const toAgentsClientErrorOfPort = (failure) => isAgentsClientError(failure) ? failure : new AgentsClientError("other");
3637
3012
  const selectMessages = (state) => state.messages;
3638
3013
  const selectError = (state) => state.error;
@@ -3835,23 +3210,23 @@ const AgentChatController = (props) => {
3835
3210
  setScrollToBottomNonce((nonce) => nonce + 1);
3836
3211
  }, [chatStore]);
3837
3212
  const handleSendMessage = useCallback(
3838
- (message2, { startSignalText, attachments, composerWidgets, entryPointKey }) => {
3213
+ (message, { startSignalText, attachments, composerWidgets, entryPointKey }) => {
3839
3214
  if (isConversationRunEnded) {
3840
3215
  rejectAsConversationClosed();
3841
3216
  return false;
3842
3217
  }
3843
3218
  chatStore.dispatch({ type: "canvasResetForNewTurn" });
3844
3219
  const model = sendModelSource?.readModelForNextSend();
3845
- const sentMessageText = client.composeSentMessageText ? client.composeSentMessageText(message2, attachments) : message2;
3220
+ const sentMessageText = client.composeSentMessageText ? client.composeSentMessageText(message, attachments) : message;
3846
3221
  const reportAcceptedSend = () => {
3847
3222
  if (attachments?.length) onAttachmentsSent?.();
3848
3223
  if (composerWidgets?.length) onComposerWidgetsSent?.(composerWidgets);
3849
- onMessageSent?.(message2);
3224
+ onMessageSent?.(message);
3850
3225
  };
3851
3226
  if (conversation?.id) {
3852
3227
  const postConversationId = conversation.id;
3853
3228
  chatStore.dispatch({ type: "messagePostRequested", message: { message: sentMessageText, role: "USER" } });
3854
- client.postMessage(postConversationId, { text: message2, model, attachments }).then(
3229
+ client.postMessage(postConversationId, { text: message, model, attachments }).then(
3855
3230
  (posted) => chatStore.dispatch({ type: "messagePostReceived", conversationId: postConversationId, posted })
3856
3231
  ).catch(
3857
3232
  (failure) => chatStore.dispatch({ type: "messagePostFailed", error: toAgentsClientErrorOfPort(failure) })
@@ -3862,7 +3237,7 @@ const AgentChatController = (props) => {
3862
3237
  if (startingNewConversation) return false;
3863
3238
  chatStore.dispatch({ type: "startRequested", message: { message: sentMessageText, role: "USER" } });
3864
3239
  const startToken = chatStore.getState().pendingStartToken;
3865
- client.startConversation({ agentSpaceKey, text: message2, startSignalText, entryPointKey, model, attachments }).then((started) => {
3240
+ client.startConversation({ agentSpaceKey, text: message, startSignalText, entryPointKey, model, attachments }).then((started) => {
3866
3241
  const isAnswerOfPendingStart = chatStore.getState().pendingStartToken === startToken;
3867
3242
  chatStore.dispatch({ type: "startReceived", startToken, started });
3868
3243
  if (!isAnswerOfPendingStart) return;
@@ -3959,7 +3334,7 @@ const AgentChatController = (props) => {
3959
3334
  const widgetCallbacks = useMemo(
3960
3335
  () => ({
3961
3336
  // Message-only for widgets; resolves true only once the send was accepted (a widget locks on it).
3962
- sendMessageToChat: (message2) => Promise.resolve(handleSendMessage(message2, {}) === true),
3337
+ sendMessageToChat: (message) => Promise.resolve(handleSendMessage(message, {}) === true),
3963
3338
  injectSignal: handleInjectSignal,
3964
3339
  prefillComposer: (text) => conversationMessageInputApiRef.current?.insertTextIntoInput(text),
3965
3340
  attachLibraryFilesToComposer,
@@ -3999,7 +3374,7 @@ const AgentChatController = (props) => {
3999
3374
  const isScheduleRunConversation = conversation?.initiatorType === "SCHEDULE";
4000
3375
  const taskInstructionMessageId = useMemo(() => {
4001
3376
  if (!isScheduleRunConversation || hasMoreOlder || !messages?.length) return void 0;
4002
- return messages.find((message2) => message2.role === "USER")?.id ?? void 0;
3377
+ return messages.find((message) => message.role === "USER")?.id ?? void 0;
4003
3378
  }, [isScheduleRunConversation, hasMoreOlder, messages]);
4004
3379
  const activityHistoryByTurnMessageId = useMemo(() => {
4005
3380
  const historyTurnsByTurnMessageId = /* @__PURE__ */ new Map();
@@ -4015,17 +3390,17 @@ const AgentChatController = (props) => {
4015
3390
  return [startingIdeasMessage];
4016
3391
  }, [showsStartingIdeas, startingIdeasMarkdown, messages]);
4017
3392
  const renderActivityHistoryAfterMessage = useCallback(
4018
- (message2) => ActivityHistory ? /* @__PURE__ */ jsx(
3393
+ (message) => ActivityHistory ? /* @__PURE__ */ jsx(
4019
3394
  ActivityHistory,
4020
3395
  {
4021
- turn: typeof message2.id === "number" ? activityHistoryByTurnMessageId.get(message2.id) ?? null : null
3396
+ turn: typeof message.id === "number" ? activityHistoryByTurnMessageId.get(message.id) ?? null : null
4022
3397
  }
4023
3398
  ) : null,
4024
3399
  [ActivityHistory, activityHistoryByTurnMessageId]
4025
3400
  );
4026
3401
  const unansweredWidgetMessageId = useMemo(() => findUnansweredWidgetMessageId(messages ?? []), [messages]);
4027
3402
  const renderAssistantAvatar = useCallback(
4028
- (message2) => AssistantAvatar ? /* @__PURE__ */ jsx(AssistantAvatar, { message: message2 }) : null,
3403
+ (message) => AssistantAvatar ? /* @__PURE__ */ jsx(AssistantAvatar, { message }) : null,
4029
3404
  [AssistantAvatar]
4030
3405
  );
4031
3406
  const activityProps = {
@@ -4534,7 +3909,7 @@ export {
4534
3909
  AgentChatActivityStack,
4535
3910
  AgentChatController,
4536
3911
  A as AgentsChatStateContainer,
4537
- d as AgentsChatStoreProvider,
3912
+ A2 as AgentsChatStoreProvider,
4538
3913
  CanvasPane,
4539
3914
  CanvasRestoreOnMount,
4540
3915
  ConversationClosedBar,
@@ -4566,17 +3941,17 @@ export {
4566
3941
  isStepStillRunning,
4567
3942
  normalizeServerMessageToMarkdown,
4568
3943
  r as readConversationErrorTypeOfRefusedSend,
4569
- e as reduceAgentsChatState,
3944
+ d as reduceAgentsChatState,
4570
3945
  resolveAgentChatActivityTiming,
4571
3946
  useActivityTicker,
4572
3947
  useAgentsChatSelector,
4573
- f as useAgentsChatState,
4574
- g as useAgentsChatStore,
3948
+ b as useAgentsChatState,
3949
+ c as useAgentsChatStore,
4575
3950
  useAgentsConversationClient,
4576
3951
  useAgentsConversationRunStatus,
4577
3952
  useConversationMessageSearch,
4578
3953
  useConversationsSearch,
4579
- h as useOptionalAgentsChatStore,
3954
+ a as useOptionalAgentsChatStore,
4580
3955
  useOptionalAgentsConversationClient
4581
3956
  };
4582
3957
  //# sourceMappingURL=chat.js.map