@assistant-ui/react 0.15.16 → 0.15.17

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 (223) hide show
  1. package/README.md +3 -3
  2. package/dist/index.d.ts +4 -3
  3. package/dist/index.js +2 -2
  4. package/dist/mcp-apps/McpAppRenderer.d.ts +6 -1
  5. package/dist/mcp-apps/McpAppRenderer.d.ts.map +1 -1
  6. package/dist/mcp-apps/McpAppRenderer.js +19 -12
  7. package/dist/mcp-apps/McpAppRenderer.js.map +1 -1
  8. package/dist/mcp-apps/McpAppsRemoteHost.d.ts.map +1 -1
  9. package/dist/mcp-apps/McpAppsRemoteHost.js +20 -17
  10. package/dist/mcp-apps/McpAppsRemoteHost.js.map +1 -1
  11. package/dist/mcp-apps/app-frame.d.ts.map +1 -1
  12. package/dist/mcp-apps/app-frame.js +189 -94
  13. package/dist/mcp-apps/app-frame.js.map +1 -1
  14. package/dist/mcp-apps/index.d.ts +2 -2
  15. package/dist/model-context/frame/useAssistantFrameHost.d.ts +1 -1
  16. package/dist/model-context/frame/useAssistantFrameHost.js +10 -11
  17. package/dist/model-context/frame/useAssistantFrameHost.js.map +1 -1
  18. package/dist/model-context/makeAssistantVisible.js +1 -1
  19. package/dist/model-context/makeAssistantVisible.js.map +1 -1
  20. package/dist/primitives/actionBar/ActionBarCopy.js +3 -3
  21. package/dist/primitives/actionBar/ActionBarCopy.js.map +1 -1
  22. package/dist/primitives/actionBar/ActionBarExportMarkdown.js +3 -3
  23. package/dist/primitives/actionBar/ActionBarExportMarkdown.js.map +1 -1
  24. package/dist/primitives/actionBar/ActionBarFeedbackNegative.js +3 -3
  25. package/dist/primitives/actionBar/ActionBarFeedbackNegative.js.map +1 -1
  26. package/dist/primitives/actionBar/ActionBarFeedbackPositive.js +3 -3
  27. package/dist/primitives/actionBar/ActionBarFeedbackPositive.js.map +1 -1
  28. package/dist/primitives/actionBar/ActionBarRoot.js.map +1 -1
  29. package/dist/primitives/actionBar/ActionBarStopSpeaking.js +3 -3
  30. package/dist/primitives/actionBar/ActionBarStopSpeaking.js.map +1 -1
  31. package/dist/primitives/actionBarMore/ActionBarMoreContent.js.map +1 -1
  32. package/dist/primitives/actionBarMore/ActionBarMoreItem.js.map +1 -1
  33. package/dist/primitives/actionBarMore/ActionBarMoreRoot.js.map +1 -1
  34. package/dist/primitives/actionBarMore/ActionBarMoreSeparator.js.map +1 -1
  35. package/dist/primitives/actionBarMore/ActionBarMoreTrigger.js.map +1 -1
  36. package/dist/primitives/actionBarMore/scope.d.ts +2 -2
  37. package/dist/primitives/actionBarMore/scope.d.ts.map +1 -1
  38. package/dist/primitives/actionBarMore/scope.js.map +1 -1
  39. package/dist/primitives/assistantModal/AssistantModalAnchor.js.map +1 -1
  40. package/dist/primitives/assistantModal/AssistantModalContent.js +1 -1
  41. package/dist/primitives/assistantModal/AssistantModalContent.js.map +1 -1
  42. package/dist/primitives/assistantModal/AssistantModalRoot.js.map +1 -1
  43. package/dist/primitives/assistantModal/AssistantModalTrigger.js.map +1 -1
  44. package/dist/primitives/assistantModal/scope.d.ts +2 -2
  45. package/dist/primitives/assistantModal/scope.d.ts.map +1 -1
  46. package/dist/primitives/assistantModal/scope.js.map +1 -1
  47. package/dist/primitives/branchPicker/BranchPickerRoot.js.map +1 -1
  48. package/dist/primitives/composer/ComposerAttachmentDropzone.js +1 -1
  49. package/dist/primitives/composer/ComposerAttachmentDropzone.js.map +1 -1
  50. package/dist/primitives/composer/ComposerDictationTranscript.js.map +1 -1
  51. package/dist/primitives/composer/ComposerInput.js +1 -3
  52. package/dist/primitives/composer/ComposerInput.js.map +1 -1
  53. package/dist/primitives/composer/ComposerQuote.js +5 -5
  54. package/dist/primitives/composer/ComposerQuote.js.map +1 -1
  55. package/dist/primitives/composer/ComposerRoot.js +3 -3
  56. package/dist/primitives/composer/ComposerRoot.js.map +1 -1
  57. package/dist/primitives/composer/trigger/TriggerPopover.d.ts +5 -0
  58. package/dist/primitives/composer/trigger/TriggerPopover.d.ts.map +1 -1
  59. package/dist/primitives/composer/trigger/TriggerPopover.js +157 -130
  60. package/dist/primitives/composer/trigger/TriggerPopover.js.map +1 -1
  61. package/dist/primitives/composer/trigger/TriggerPopoverBack.js +3 -3
  62. package/dist/primitives/composer/trigger/TriggerPopoverBack.js.map +1 -1
  63. package/dist/primitives/composer/trigger/TriggerPopoverCategories.js +4 -4
  64. package/dist/primitives/composer/trigger/TriggerPopoverCategories.js.map +1 -1
  65. package/dist/primitives/composer/trigger/TriggerPopoverItems.js +4 -4
  66. package/dist/primitives/composer/trigger/TriggerPopoverItems.js.map +1 -1
  67. package/dist/primitives/composer/trigger/TriggerPopoverResource.d.ts +2 -0
  68. package/dist/primitives/composer/trigger/TriggerPopoverResource.d.ts.map +1 -1
  69. package/dist/primitives/composer/trigger/TriggerPopoverResource.js +63 -61
  70. package/dist/primitives/composer/trigger/TriggerPopoverResource.js.map +1 -1
  71. package/dist/primitives/composer/trigger/TriggerPopoverRootContext.d.ts +2 -0
  72. package/dist/primitives/composer/trigger/TriggerPopoverRootContext.d.ts.map +1 -1
  73. package/dist/primitives/composer/trigger/TriggerPopoverRootContext.js.map +1 -1
  74. package/dist/primitives/composer/trigger/detectTrigger.d.ts +21 -1
  75. package/dist/primitives/composer/trigger/detectTrigger.d.ts.map +1 -0
  76. package/dist/primitives/composer/trigger/detectTrigger.js +17 -3
  77. package/dist/primitives/composer/trigger/detectTrigger.js.map +1 -1
  78. package/dist/primitives/composer/trigger/index.d.ts +3 -1
  79. package/dist/primitives/composer/trigger/index.d.ts.map +1 -1
  80. package/dist/primitives/composer/trigger/index.js.map +1 -1
  81. package/dist/primitives/composer/trigger/triggerDetectionResource.d.ts +3 -4
  82. package/dist/primitives/composer/trigger/triggerDetectionResource.d.ts.map +1 -1
  83. package/dist/primitives/composer/trigger/triggerDetectionResource.js +15 -14
  84. package/dist/primitives/composer/trigger/triggerDetectionResource.js.map +1 -1
  85. package/dist/primitives/composer/trigger/triggerSelectionResource.d.ts.map +1 -1
  86. package/dist/primitives/composer/trigger/triggerSelectionResource.js +18 -19
  87. package/dist/primitives/composer/trigger/triggerSelectionResource.js.map +1 -1
  88. package/dist/primitives/composer.d.ts +3 -2
  89. package/dist/primitives/composer.js.map +1 -1
  90. package/dist/primitives/error/ErrorMessage.js.map +1 -1
  91. package/dist/primitives/message/MessageIf.js.map +1 -1
  92. package/dist/primitives/message/MessageParts.js.map +1 -1
  93. package/dist/primitives/message/MessagePartsGrouped.js.map +1 -1
  94. package/dist/primitives/message/MessageRoot.js +4 -4
  95. package/dist/primitives/message/MessageRoot.js.map +1 -1
  96. package/dist/primitives/messagePart/MessagePartText.js.map +1 -1
  97. package/dist/primitives/selectionToolbar/SelectionToolbarQuote.js +3 -3
  98. package/dist/primitives/selectionToolbar/SelectionToolbarQuote.js.map +1 -1
  99. package/dist/primitives/selectionToolbar/SelectionToolbarRoot.js +3 -3
  100. package/dist/primitives/selectionToolbar/SelectionToolbarRoot.js.map +1 -1
  101. package/dist/primitives/thread/ThreadIf.js.map +1 -1
  102. package/dist/primitives/thread/ThreadViewport.js +3 -3
  103. package/dist/primitives/thread/ThreadViewport.js.map +1 -1
  104. package/dist/primitives/thread/ThreadViewportFooter.js +3 -3
  105. package/dist/primitives/thread/ThreadViewportFooter.js.map +1 -1
  106. package/dist/primitives/thread/useThreadViewportAutoScroll.js +1 -1
  107. package/dist/primitives/thread/useThreadViewportAutoScroll.js.map +1 -1
  108. package/dist/primitives/threadList/ThreadListNew.js +3 -3
  109. package/dist/primitives/threadList/ThreadListNew.js.map +1 -1
  110. package/dist/primitives/threadListFocusGroup.d.ts +2 -1
  111. package/dist/primitives/threadListFocusGroup.d.ts.map +1 -1
  112. package/dist/primitives/threadListFocusGroup.js +2 -2
  113. package/dist/primitives/threadListFocusGroup.js.map +1 -1
  114. package/dist/primitives/threadListItem/ThreadListItemRoot.js +3 -3
  115. package/dist/primitives/threadListItem/ThreadListItemRoot.js.map +1 -1
  116. package/dist/primitives/threadListItem/ThreadListItemTrigger.js +1 -1
  117. package/dist/primitives/threadListItem/ThreadListItemTrigger.js.map +1 -1
  118. package/dist/primitives/threadListItemMore/ThreadListItemMoreContent.js +1 -1
  119. package/dist/primitives/threadListItemMore/ThreadListItemMoreContent.js.map +1 -1
  120. package/dist/primitives/threadListItemMore/ThreadListItemMoreItem.js.map +1 -1
  121. package/dist/primitives/threadListItemMore/ThreadListItemMoreRoot.js +1 -1
  122. package/dist/primitives/threadListItemMore/ThreadListItemMoreRoot.js.map +1 -1
  123. package/dist/primitives/threadListItemMore/ThreadListItemMoreSeparator.js.map +1 -1
  124. package/dist/primitives/threadListItemMore/ThreadListItemMoreTrigger.js +1 -2
  125. package/dist/primitives/threadListItemMore/ThreadListItemMoreTrigger.js.map +1 -1
  126. package/dist/primitives/threadListItemMore/scope.d.ts +2 -2
  127. package/dist/primitives/threadListItemMore/scope.d.ts.map +1 -1
  128. package/dist/primitives/threadListItemMore/scope.js.map +1 -1
  129. package/dist/sandbox-host/SandboxHost.d.ts.map +1 -1
  130. package/dist/sandbox-host/SandboxHost.js +137 -70
  131. package/dist/sandbox-host/SandboxHost.js.map +1 -1
  132. package/dist/unstable/useLiveCompletionAdapter.js +3 -1
  133. package/dist/unstable/useLiveCompletionAdapter.js.map +1 -1
  134. package/dist/unstable/useSlashCommandAdapter.js +41 -27
  135. package/dist/unstable/useSlashCommandAdapter.js.map +1 -1
  136. package/dist/utils/Primitive.d.ts +2 -2
  137. package/dist/utils/Primitive.js +2 -2
  138. package/dist/utils/Primitive.js.map +1 -1
  139. package/dist/utils/createActionButton.js +3 -3
  140. package/dist/utils/createActionButton.js.map +1 -1
  141. package/dist/utils/hooks/useOnResizeContent.js +1 -1
  142. package/dist/utils/hooks/useOnResizeContent.js.map +1 -1
  143. package/dist/utils/hooks/useOnScrollToBottom.js +1 -1
  144. package/dist/utils/hooks/useOnScrollToBottom.js.map +1 -1
  145. package/dist/utils/smooth/SmoothContext.d.ts +24 -0
  146. package/dist/utils/smooth/SmoothContext.d.ts.map +1 -1
  147. package/dist/utils/smooth/useSmooth.js +1 -1
  148. package/dist/utils/smooth/useSmooth.js.map +1 -1
  149. package/dist/utils/useToolArgsFieldStatus.d.ts +5 -1
  150. package/package.json +11 -19
  151. package/src/index.ts +9 -1
  152. package/src/mcp-apps/McpAppRenderer.test.tsx +133 -4
  153. package/src/mcp-apps/McpAppRenderer.tsx +28 -21
  154. package/src/mcp-apps/McpAppsRemoteHost.concurrent.test.tsx +215 -0
  155. package/src/mcp-apps/McpAppsRemoteHost.ts +28 -12
  156. package/src/mcp-apps/app-frame.test.tsx +102 -0
  157. package/src/mcp-apps/app-frame.tsx +17 -4
  158. package/src/mcp-apps/index.ts +1 -0
  159. package/src/model-context/frame/AssistantFrame.test.ts +3 -3
  160. package/src/model-context/frame/SPEC_AssistantFrame.md +1 -1
  161. package/src/model-context/frame/useAssistantFrameHost.ts +2 -2
  162. package/src/model-context/makeAssistantVisible.tsx +1 -1
  163. package/src/primitives/actionBar/ActionBarCopy.tsx +1 -1
  164. package/src/primitives/actionBar/ActionBarExportMarkdown.tsx +1 -1
  165. package/src/primitives/actionBar/ActionBarFeedbackNegative.tsx +1 -1
  166. package/src/primitives/actionBar/ActionBarFeedbackPositive.tsx +1 -1
  167. package/src/primitives/actionBar/ActionBarStopSpeaking.tsx +1 -1
  168. package/src/primitives/actionBarMore/scope.ts +2 -2
  169. package/src/primitives/assistantModal/AssistantModalContent.tsx +1 -1
  170. package/src/primitives/assistantModal/scope.ts +2 -2
  171. package/src/primitives/composer/ComposerAttachmentDropzone.tsx +1 -1
  172. package/src/primitives/composer/ComposerInput.test.tsx +2 -1
  173. package/src/primitives/composer/ComposerInput.tsx +3 -3
  174. package/src/primitives/composer/ComposerQuote.tsx +1 -1
  175. package/src/primitives/composer/ComposerRoot.tsx +1 -1
  176. package/src/primitives/composer/trigger/TriggerPopover.tsx +16 -1
  177. package/src/primitives/composer/trigger/TriggerPopoverBack.tsx +1 -1
  178. package/src/primitives/composer/trigger/TriggerPopoverCategories.tsx +1 -1
  179. package/src/primitives/composer/trigger/TriggerPopoverItems.tsx +1 -1
  180. package/src/primitives/composer/trigger/TriggerPopoverResource.ts +4 -1
  181. package/src/primitives/composer/trigger/TriggerPopoverRootContext.tsx +2 -0
  182. package/src/primitives/composer/trigger/detectTrigger.test.ts +88 -5
  183. package/src/primitives/composer/trigger/detectTrigger.ts +50 -9
  184. package/src/primitives/composer/trigger/index.ts +1 -0
  185. package/src/primitives/composer/trigger/triggerDetectionResource.ts +10 -7
  186. package/src/primitives/composer/trigger/triggerSelectionResource.test.ts +15 -3
  187. package/src/primitives/composer/trigger/triggerSelectionResource.ts +1 -4
  188. package/src/primitives/composer.ts +1 -0
  189. package/src/primitives/message/MessageRoot.tsx +1 -1
  190. package/src/primitives/selectionToolbar/SelectionToolbarQuote.tsx +1 -1
  191. package/src/primitives/selectionToolbar/SelectionToolbarRoot.tsx +1 -1
  192. package/src/primitives/thread/ThreadViewport.tsx +1 -1
  193. package/src/primitives/thread/ThreadViewportFooter.tsx +1 -1
  194. package/src/primitives/thread/useThreadViewportAutoScroll.ts +1 -1
  195. package/src/primitives/threadList/ThreadListNew.tsx +1 -1
  196. package/src/primitives/threadListFocusGroup.ts +2 -2
  197. package/src/primitives/threadListItem/ThreadListItemRoot.tsx +1 -1
  198. package/src/primitives/threadListItem/ThreadListItemTrigger.tsx +1 -1
  199. package/src/primitives/threadListItemMore/ThreadListItemMoreContent.tsx +1 -1
  200. package/src/primitives/threadListItemMore/ThreadListItemMoreRoot.tsx +1 -1
  201. package/src/primitives/threadListItemMore/ThreadListItemMoreTrigger.tsx +2 -2
  202. package/src/primitives/threadListItemMore/scope.ts +2 -2
  203. package/src/sandbox-host/SandboxHost.test.tsx +45 -1
  204. package/src/sandbox-host/SandboxHost.tsx +16 -3
  205. package/src/tests/RemoteThreadListRuntime.adapterProvider.test.tsx +31 -1
  206. package/src/unstable/useLiveCompletionAdapter.test.tsx +60 -1
  207. package/src/unstable/useLiveCompletionAdapter.ts +4 -1
  208. package/src/unstable/useSlashCommandAdapter.test.tsx +141 -0
  209. package/src/unstable/useSlashCommandAdapter.ts +52 -17
  210. package/src/utils/Primitive.tsx +2 -2
  211. package/src/utils/createActionButton.tsx +1 -1
  212. package/src/utils/hooks/useOnResizeContent.ts +1 -1
  213. package/src/utils/hooks/useOnScrollToBottom.ts +1 -1
  214. package/src/utils/smooth/useSmooth.ts +1 -1
  215. package/dist/legacy-runtime/runtime/MessagePartRuntime.d.ts +0 -3
  216. package/dist/legacy-runtime/runtime/MessagePartRuntime.js +0 -2
  217. package/dist/legacy-runtime/runtime/MessageRuntime.d.ts +0 -3
  218. package/dist/legacy-runtime/runtime/MessageRuntime.js +0 -2
  219. package/dist/legacy-runtime/runtime/ThreadListRuntime.d.ts +0 -3
  220. package/dist/legacy-runtime/runtime/ThreadListRuntime.js +0 -2
  221. package/src/legacy-runtime/runtime/MessagePartRuntime.ts +0 -2
  222. package/src/legacy-runtime/runtime/MessageRuntime.ts +0 -3
  223. package/src/legacy-runtime/runtime/ThreadListRuntime.ts +0 -4
@@ -2,7 +2,7 @@
2
2
  import { createMcpAppBridge } from "./bridge.js";
3
3
  import { SandboxHost } from "../sandbox-host/SandboxHost.js";
4
4
  import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
5
- import { useEffect, useRef } from "@assistant-ui/tap/react-shim";
5
+ import { useEffect, useLayoutEffect, useRef } from "@assistant-ui/tap/react-shim";
6
6
  import { jsx } from "react/jsx-runtime";
7
7
  //#region src/mcp-apps/app-frame.tsx
8
8
  const DEFAULT_PRODUCT = "assistant-ui-mcp-app";
@@ -67,7 +67,10 @@ function buildLiveHandlers(initial, liveRef) {
67
67
  out.onError = (e) => live()?.onError?.(e);
68
68
  return out;
69
69
  }
70
- function McpAppFrame({ app, resource, input, output, sandbox, handlers, hostInfo, hostContext, maxHeight = DEFAULT_MAX_HEIGHT }) {
70
+ function McpAppFrame(t0) {
71
+ const $ = c(29);
72
+ const { app, resource, input, output, sandbox, handlers, hostInfo, hostContext, maxHeight: t1 } = t0;
73
+ const maxHeight = t1 === void 0 ? DEFAULT_MAX_HEIGHT : t1;
71
74
  const bridgeRef = useRef(null);
72
75
  const lastSentInputRef = useRef(void 0);
73
76
  const lastSentOutputRef = useRef(void 0);
@@ -76,105 +79,197 @@ function McpAppFrame({ app, resource, input, output, sandbox, handlers, hostInfo
76
79
  const pendingInputRef = useRef(void 0);
77
80
  const pendingOutputRef = useRef(void 0);
78
81
  const pendingHostContextRef = useRef(void 0);
79
- const liveRef = useRef(null);
80
- liveRef.current = {
81
- handlers,
82
- hostInfo,
83
- hostContext,
84
- input,
85
- output
86
- };
87
- const createBridge = (frame, host) => {
88
- const current = liveRef.current;
89
- let initTimeoutId = null;
90
- const flushPending = () => {
91
- if (widgetReadyRef.current) return;
92
- widgetReadyRef.current = true;
93
- const b = bridgeRef.current;
94
- if (!b) return;
95
- if (pendingInputRef.current !== void 0) {
96
- b.notifyToolInput(pendingInputRef.current);
97
- lastSentInputRef.current = pendingInputRef.current;
98
- pendingInputRef.current = void 0;
99
- }
100
- if (pendingOutputRef.current !== void 0) {
101
- b.notifyToolResult(pendingOutputRef.current);
102
- lastSentOutputRef.current = pendingOutputRef.current;
103
- pendingOutputRef.current = void 0;
104
- }
105
- if (pendingHostContextRef.current !== void 0) {
106
- b.notifyHostContextChanged(pendingHostContextRef.current);
107
- lastSentHostContextRef.current = pendingHostContextRef.current;
108
- pendingHostContextRef.current = void 0;
109
- }
82
+ let t2;
83
+ if ($[0] !== handlers || $[1] !== hostContext || $[2] !== hostInfo || $[3] !== input || $[4] !== output) {
84
+ t2 = {
85
+ handlers,
86
+ hostInfo,
87
+ hostContext,
88
+ input,
89
+ output
110
90
  };
111
- const liveHandlers = buildLiveHandlers(current.handlers, liveRef);
112
- const liveOnInitialized = liveHandlers.onInitialized;
113
- const wrappedHandlers = {
114
- ...liveHandlers,
115
- onInitialized: () => {
116
- if (initTimeoutId !== null) {
117
- clearTimeout(initTimeoutId);
118
- initTimeoutId = null;
91
+ $[0] = handlers;
92
+ $[1] = hostContext;
93
+ $[2] = hostInfo;
94
+ $[3] = input;
95
+ $[4] = output;
96
+ $[5] = t2;
97
+ } else t2 = $[5];
98
+ const liveRef = useRef(t2);
99
+ let t3;
100
+ let t4;
101
+ if ($[6] !== handlers || $[7] !== hostContext || $[8] !== hostInfo || $[9] !== input || $[10] !== output) {
102
+ t3 = () => {
103
+ liveRef.current = {
104
+ handlers,
105
+ hostInfo,
106
+ hostContext,
107
+ input,
108
+ output
109
+ };
110
+ };
111
+ t4 = [
112
+ handlers,
113
+ hostInfo,
114
+ hostContext,
115
+ input,
116
+ output
117
+ ];
118
+ $[6] = handlers;
119
+ $[7] = hostContext;
120
+ $[8] = hostInfo;
121
+ $[9] = input;
122
+ $[10] = output;
123
+ $[11] = t3;
124
+ $[12] = t4;
125
+ } else {
126
+ t3 = $[11];
127
+ t4 = $[12];
128
+ }
129
+ useLayoutEffect(t3, t4);
130
+ let t5;
131
+ if ($[13] === Symbol.for("react.memo_cache_sentinel")) {
132
+ t5 = (frame, host) => {
133
+ const current = liveRef.current;
134
+ let initTimeoutId = null;
135
+ const flushPending = () => {
136
+ if (widgetReadyRef.current) return;
137
+ widgetReadyRef.current = true;
138
+ const b = bridgeRef.current;
139
+ if (!b) return;
140
+ if (pendingInputRef.current !== void 0) {
141
+ b.notifyToolInput(pendingInputRef.current);
142
+ lastSentInputRef.current = pendingInputRef.current;
143
+ pendingInputRef.current = void 0;
144
+ }
145
+ if (pendingOutputRef.current !== void 0) {
146
+ b.notifyToolResult(pendingOutputRef.current);
147
+ lastSentOutputRef.current = pendingOutputRef.current;
148
+ pendingOutputRef.current = void 0;
119
149
  }
150
+ if (pendingHostContextRef.current !== void 0) {
151
+ b.notifyHostContextChanged(pendingHostContextRef.current);
152
+ lastSentHostContextRef.current = pendingHostContextRef.current;
153
+ pendingHostContextRef.current = void 0;
154
+ }
155
+ };
156
+ const liveHandlers = buildLiveHandlers(current.handlers, liveRef);
157
+ const liveOnInitialized = liveHandlers.onInitialized;
158
+ const wrappedHandlers = {
159
+ ...liveHandlers,
160
+ onInitialized: () => {
161
+ if (initTimeoutId !== null) {
162
+ clearTimeout(initTimeoutId);
163
+ initTimeoutId = null;
164
+ }
165
+ flushPending();
166
+ liveOnInitialized?.();
167
+ },
168
+ onSizeChange: (p) => {
169
+ if (p.height != null) host.setHeight(p.height);
170
+ liveHandlers.onSizeChange?.(p);
171
+ }
172
+ };
173
+ initTimeoutId = setTimeout(() => {
174
+ initTimeoutId = null;
120
175
  flushPending();
121
- liveOnInitialized?.();
122
- },
123
- onSizeChange: (p) => {
124
- if (p.height != null) host.setHeight(p.height);
125
- liveHandlers.onSizeChange?.(p);
126
- }
127
- };
128
- initTimeoutId = setTimeout(() => {
129
- initTimeoutId = null;
130
- flushPending();
131
- }, INIT_TIMEOUT_MS);
132
- const bridge = createMcpAppBridge({
133
- frame,
134
- handlers: wrappedHandlers,
135
- hostInfo: current.hostInfo,
136
- hostContext: current.hostContext
137
- });
138
- bridgeRef.current = bridge;
139
- if (current.input !== void 0) pendingInputRef.current = current.input;
140
- if (current.output !== void 0) pendingOutputRef.current = current.output;
141
- return {
142
- onMessage: bridge.onMessage,
143
- dispose: () => {
144
- if (initTimeoutId !== null) {
145
- clearTimeout(initTimeoutId);
146
- initTimeoutId = null;
176
+ }, INIT_TIMEOUT_MS);
177
+ const bridge = createMcpAppBridge({
178
+ frame,
179
+ handlers: wrappedHandlers,
180
+ hostInfo: current.hostInfo,
181
+ hostContext: current.hostContext
182
+ });
183
+ bridgeRef.current = bridge;
184
+ if (current.input !== void 0) pendingInputRef.current = current.input;
185
+ if (current.output !== void 0) pendingOutputRef.current = current.output;
186
+ return {
187
+ onMessage: bridge.onMessage,
188
+ dispose: () => {
189
+ if (initTimeoutId !== null) {
190
+ clearTimeout(initTimeoutId);
191
+ initTimeoutId = null;
192
+ }
193
+ bridge.dispose();
194
+ bridgeRef.current = null;
195
+ lastSentInputRef.current = void 0;
196
+ lastSentOutputRef.current = void 0;
197
+ lastSentHostContextRef.current = void 0;
198
+ widgetReadyRef.current = false;
199
+ pendingInputRef.current = void 0;
200
+ pendingOutputRef.current = void 0;
201
+ pendingHostContextRef.current = void 0;
147
202
  }
148
- bridge.dispose();
149
- bridgeRef.current = null;
150
- lastSentInputRef.current = void 0;
151
- lastSentOutputRef.current = void 0;
152
- lastSentHostContextRef.current = void 0;
153
- widgetReadyRef.current = false;
154
- pendingInputRef.current = void 0;
155
- pendingOutputRef.current = void 0;
156
- pendingHostContextRef.current = void 0;
157
- }
203
+ };
158
204
  };
159
- };
160
- useBridgeNotify(input, bridgeRef, widgetReadyRef, pendingInputRef, lastSentInputRef, (b_0, v) => b_0.notifyToolInput(v));
161
- useBridgeNotify(output, bridgeRef, widgetReadyRef, pendingOutputRef, lastSentOutputRef, (b_1, v_0) => b_1.notifyToolResult(v_0));
162
- useBridgeNotify(hostContext, bridgeRef, widgetReadyRef, pendingHostContextRef, lastSentHostContextRef, (b_2, v_1) => b_2.notifyHostContextChanged(v_1));
163
- return /* @__PURE__ */ jsx(SandboxHost, {
164
- content: { html: resource.html },
165
- contentKey: app.serverId ? `${app.serverId} ${resource.uri}` : resource.uri,
166
- sandbox: {
205
+ $[13] = t5;
206
+ } else t5 = $[13];
207
+ const createBridge = t5;
208
+ useBridgeNotify(input, bridgeRef, widgetReadyRef, pendingInputRef, lastSentInputRef, _temp);
209
+ useBridgeNotify(output, bridgeRef, widgetReadyRef, pendingOutputRef, lastSentOutputRef, _temp2);
210
+ useBridgeNotify(hostContext, bridgeRef, widgetReadyRef, pendingHostContextRef, lastSentHostContextRef, _temp3);
211
+ let t6;
212
+ if ($[14] !== resource.html) {
213
+ t6 = { html: resource.html };
214
+ $[14] = resource.html;
215
+ $[15] = t6;
216
+ } else t6 = $[15];
217
+ const t7 = app.serverId ? `${app.serverId} ${resource.uri}` : resource.uri;
218
+ const t8 = sandbox?.product ?? DEFAULT_PRODUCT;
219
+ let t9;
220
+ if ($[16] !== sandbox || $[17] !== t8) {
221
+ t9 = {
167
222
  ...sandbox,
168
- product: sandbox?.product ?? DEFAULT_PRODUCT
169
- },
170
- maxHeight,
171
- createBridge,
172
- onError: (err) => liveRef.current.handlers?.onError?.(err),
173
- containerProps: {
223
+ product: t8
224
+ };
225
+ $[16] = sandbox;
226
+ $[17] = t8;
227
+ $[18] = t9;
228
+ } else t9 = $[18];
229
+ let t10;
230
+ if ($[19] === Symbol.for("react.memo_cache_sentinel")) {
231
+ t10 = (err) => liveRef.current.handlers?.onError?.(err);
232
+ $[19] = t10;
233
+ } else t10 = $[19];
234
+ const t11 = resource.meta?.prefersBorder ? "" : void 0;
235
+ let t12;
236
+ if ($[20] !== app.resourceUri || $[21] !== t11) {
237
+ t12 = {
174
238
  "data-mcp-app-resource": app.resourceUri,
175
- "data-mcp-app-prefers-border": resource.meta?.prefersBorder ? "" : void 0
176
- }
177
- });
239
+ "data-mcp-app-prefers-border": t11
240
+ };
241
+ $[20] = app.resourceUri;
242
+ $[21] = t11;
243
+ $[22] = t12;
244
+ } else t12 = $[22];
245
+ let t13;
246
+ if ($[23] !== maxHeight || $[24] !== t12 || $[25] !== t6 || $[26] !== t7 || $[27] !== t9) {
247
+ t13 = /* @__PURE__ */ jsx(SandboxHost, {
248
+ content: t6,
249
+ contentKey: t7,
250
+ sandbox: t9,
251
+ maxHeight,
252
+ createBridge,
253
+ onError: t10,
254
+ containerProps: t12
255
+ });
256
+ $[23] = maxHeight;
257
+ $[24] = t12;
258
+ $[25] = t6;
259
+ $[26] = t7;
260
+ $[27] = t9;
261
+ $[28] = t13;
262
+ } else t13 = $[28];
263
+ return t13;
264
+ }
265
+ function _temp3(b_2, v_1) {
266
+ return b_2.notifyHostContextChanged(v_1);
267
+ }
268
+ function _temp2(b_1, v_0) {
269
+ return b_1.notifyToolResult(v_0);
270
+ }
271
+ function _temp(b_0, v) {
272
+ return b_0.notifyToolInput(v);
178
273
  }
179
274
  //#endregion
180
275
  export { McpAppFrame };
@@ -1 +1 @@
1
- {"version":3,"file":"app-frame.js","names":["c","_c","MutableRefObject","useEffect","useRef","McpAppBridge","createMcpAppBridge","SandboxHost","SandboxBridge","SandboxHostApi","SandboxHostFrame","McpAppBridgeHandlers","McpAppFrameProps","McpAppHostContext","DEFAULT_PRODUCT","INIT_TIMEOUT_MS","DEFAULT_MAX_HEIGHT","useBridgeNotify","value","bridgeRef","widgetReadyRef","pendingRef","lastSentRef","notify","$","t0","current","undefined","t1","LiveSnapshot","handlers","hostInfo","hostContext","input","output","buildLiveHandlers","initial","liveRef","live","has","key","K","out","Object","defineProperty","get","allowedTools","enumerable","configurable","liveCall","NonNullable","p","fn","Error","callTool","readResource","listResources","openLink","sendMessage","updateModelContext","requestDisplayMode","onSizeChange","onInitialized","onRequestTeardown","onLog","onError","e","McpAppFrame","app","resource","sandbox","maxHeight","lastSentInputRef","lastSentOutputRef","lastSentHostContextRef","pendingInputRef","pendingOutputRef","pendingHostContextRef","createBridge","frame","host","initTimeoutId","ReturnType","setTimeout","flushPending","b","notifyToolInput","notifyToolResult","notifyHostContextChanged","liveHandlers","liveOnInitialized","wrappedHandlers","clearTimeout","height","setHeight","bridge","onMessage","dispose","v","html","serverId","uri","product","err","resourceUri","meta","prefersBorder"],"sources":["../../src/mcp-apps/app-frame.tsx"],"sourcesContent":["\"use client\";\n\nimport { type MutableRefObject, useEffect, useRef } from \"react\";\nimport { type McpAppBridge, createMcpAppBridge } from \"./bridge\";\nimport {\n SandboxHost,\n type SandboxBridge,\n type SandboxHostApi,\n type SandboxHostFrame,\n} from \"../sandbox-host/SandboxHost\";\nimport type {\n McpAppBridgeHandlers,\n McpAppFrameProps,\n McpAppHostContext,\n} from \"./types\";\n\nconst DEFAULT_PRODUCT = \"assistant-ui-mcp-app\";\nconst INIT_TIMEOUT_MS = 5000;\nconst DEFAULT_MAX_HEIGHT = 800;\n\nfunction useBridgeNotify<T>(\n value: T | undefined,\n bridgeRef: MutableRefObject<McpAppBridge | null>,\n widgetReadyRef: MutableRefObject<boolean>,\n pendingRef: MutableRefObject<T | undefined>,\n lastSentRef: MutableRefObject<T | undefined>,\n notify: (bridge: McpAppBridge, v: T) => void,\n) {\n useEffect(() => {\n if (!bridgeRef.current) return;\n if (value === undefined) return;\n if (lastSentRef.current === value) return;\n if (!widgetReadyRef.current) {\n pendingRef.current = value;\n return;\n }\n notify(bridgeRef.current, value);\n lastSentRef.current = value;\n // oxlint-disable-next-line react/exhaustive-deps -- refs are stable; notify is assumed stable; re-run only when value changes\n }, [value]);\n}\n\ntype LiveSnapshot = {\n handlers: McpAppBridgeHandlers | undefined;\n hostInfo: McpAppFrameProps[\"hostInfo\"];\n hostContext: McpAppFrameProps[\"hostContext\"];\n input: unknown;\n output: unknown;\n};\n\n// Proxy each per-call handler through liveRef so the bridge always dispatches\n// to the latest handler reference (e.g. inline callbacks closing over state).\n// Capability presence is snapshot at mount: a handler added later requires a\n// remount (keyed on resource URI) to expose the capability to the widget.\nfunction buildLiveHandlers(\n initial: McpAppBridgeHandlers | undefined,\n liveRef: { readonly current: LiveSnapshot },\n): McpAppBridgeHandlers {\n const live = () => liveRef.current.handlers;\n const has = <K extends keyof McpAppBridgeHandlers>(key: K) =>\n initial?.[key] !== undefined;\n const out: McpAppBridgeHandlers = {};\n if (has(\"allowedTools\")) {\n Object.defineProperty(out, \"allowedTools\", {\n get: () => live()?.allowedTools,\n enumerable: true,\n configurable: true,\n });\n }\n const liveCall = <K extends keyof McpAppBridgeHandlers>(\n key: K,\n ): NonNullable<McpAppBridgeHandlers[K]> =>\n ((p: unknown) => {\n const fn = live()?.[key] as ((p: unknown) => unknown) | undefined;\n if (!fn) {\n throw new Error(`${key} handler is no longer available`);\n }\n return fn(p);\n }) as NonNullable<McpAppBridgeHandlers[K]>;\n if (has(\"callTool\")) out.callTool = liveCall(\"callTool\");\n if (has(\"readResource\")) out.readResource = liveCall(\"readResource\");\n if (has(\"listResources\")) out.listResources = liveCall(\"listResources\");\n if (has(\"openLink\")) out.openLink = liveCall(\"openLink\");\n if (has(\"sendMessage\")) out.sendMessage = liveCall(\"sendMessage\");\n if (has(\"updateModelContext\"))\n out.updateModelContext = liveCall(\"updateModelContext\");\n if (has(\"requestDisplayMode\"))\n out.requestDisplayMode = liveCall(\"requestDisplayMode\");\n out.onSizeChange = (p) => live()?.onSizeChange?.(p);\n out.onInitialized = () => live()?.onInitialized?.();\n out.onRequestTeardown = (p) => live()?.onRequestTeardown?.(p);\n out.onLog = (p) => live()?.onLog?.(p);\n out.onError = (e) => live()?.onError?.(e);\n return out;\n}\n\nexport function McpAppFrame({\n app,\n resource,\n input,\n output,\n sandbox,\n handlers,\n hostInfo,\n hostContext,\n maxHeight = DEFAULT_MAX_HEIGHT,\n}: McpAppFrameProps) {\n const bridgeRef = useRef<McpAppBridge | null>(null);\n const lastSentInputRef = useRef<unknown>(undefined);\n const lastSentOutputRef = useRef<unknown>(undefined);\n const lastSentHostContextRef = useRef<McpAppHostContext | undefined>(\n undefined,\n );\n // Per MCP Apps spec, the host should defer notifications until the widget\n // signals readiness via `notifications/initialized`. Until then, we record\n // pending values and flush them on init.\n const widgetReadyRef = useRef(false);\n const pendingInputRef = useRef<unknown>(undefined);\n const pendingOutputRef = useRef<unknown>(undefined);\n const pendingHostContextRef = useRef<McpAppHostContext | undefined>(\n undefined,\n );\n\n const liveRef = useRef<LiveSnapshot>(null!);\n liveRef.current = {\n handlers,\n hostInfo,\n hostContext,\n input,\n output,\n };\n\n const createBridge = (\n frame: SandboxHostFrame,\n host: SandboxHostApi,\n ): SandboxBridge => {\n const current = liveRef.current;\n let initTimeoutId: ReturnType<typeof setTimeout> | null = null;\n\n const flushPending = () => {\n if (widgetReadyRef.current) return;\n widgetReadyRef.current = true;\n const b = bridgeRef.current;\n if (!b) return;\n if (pendingInputRef.current !== undefined) {\n b.notifyToolInput(pendingInputRef.current);\n lastSentInputRef.current = pendingInputRef.current;\n pendingInputRef.current = undefined;\n }\n if (pendingOutputRef.current !== undefined) {\n b.notifyToolResult(pendingOutputRef.current);\n lastSentOutputRef.current = pendingOutputRef.current;\n pendingOutputRef.current = undefined;\n }\n if (pendingHostContextRef.current !== undefined) {\n b.notifyHostContextChanged(pendingHostContextRef.current);\n lastSentHostContextRef.current = pendingHostContextRef.current;\n pendingHostContextRef.current = undefined;\n }\n };\n\n const liveHandlers = buildLiveHandlers(current.handlers, liveRef);\n const liveOnInitialized = liveHandlers.onInitialized;\n const wrappedHandlers: McpAppBridgeHandlers = {\n ...liveHandlers,\n onInitialized: () => {\n if (initTimeoutId !== null) {\n clearTimeout(initTimeoutId);\n initTimeoutId = null;\n }\n flushPending();\n liveOnInitialized?.();\n },\n onSizeChange: (p) => {\n if (p.height != null) host.setHeight(p.height);\n liveHandlers.onSizeChange?.(p);\n },\n };\n\n // Safety net: if the widget never sends notifications/initialized (broken\n // or non-spec-compliant), flush the queue anyway so the host doesn't\n // appear hung.\n initTimeoutId = setTimeout(() => {\n initTimeoutId = null;\n flushPending();\n }, INIT_TIMEOUT_MS);\n\n const bridge = createMcpAppBridge({\n frame,\n handlers: wrappedHandlers,\n hostInfo: current.hostInfo,\n hostContext: current.hostContext,\n });\n bridgeRef.current = bridge;\n\n if (current.input !== undefined) pendingInputRef.current = current.input;\n if (current.output !== undefined) pendingOutputRef.current = current.output;\n // hostContext is delivered inside the ui/initialize response; subsequent\n // changes flow through useBridgeNotify's pending path.\n\n return {\n onMessage: bridge.onMessage,\n dispose: () => {\n if (initTimeoutId !== null) {\n clearTimeout(initTimeoutId);\n initTimeoutId = null;\n }\n bridge.dispose();\n bridgeRef.current = null;\n lastSentInputRef.current = undefined;\n lastSentOutputRef.current = undefined;\n lastSentHostContextRef.current = undefined;\n widgetReadyRef.current = false;\n pendingInputRef.current = undefined;\n pendingOutputRef.current = undefined;\n pendingHostContextRef.current = undefined;\n },\n };\n };\n\n useBridgeNotify(\n input,\n bridgeRef,\n widgetReadyRef,\n pendingInputRef,\n lastSentInputRef,\n (b, v) => b.notifyToolInput(v),\n );\n useBridgeNotify(\n output,\n bridgeRef,\n widgetReadyRef,\n pendingOutputRef,\n lastSentOutputRef,\n (b, v) => b.notifyToolResult(v),\n );\n useBridgeNotify(\n hostContext,\n bridgeRef,\n widgetReadyRef,\n pendingHostContextRef,\n lastSentHostContextRef,\n (b, v) => b.notifyHostContextChanged(v),\n );\n\n return (\n <SandboxHost\n content={{ html: resource.html }}\n contentKey={\n app.serverId ? `${app.serverId} ${resource.uri}` : resource.uri\n }\n sandbox={{ ...sandbox, product: sandbox?.product ?? DEFAULT_PRODUCT }}\n maxHeight={maxHeight}\n createBridge={createBridge}\n onError={(err) => liveRef.current.handlers?.onError?.(err)}\n containerProps={{\n \"data-mcp-app-resource\": app.resourceUri,\n \"data-mcp-app-prefers-border\": resource.meta?.prefersBorder\n ? \"\"\n : undefined,\n }}\n />\n );\n}\n"],"mappings":";;;;;;;AAgBA,MAAMc,kBAAkB;AACxB,MAAMC,kBAAkB;AACxB,MAAMC,qBAAqB;AAE3B,SAAAC,gBAAAC,OAAAC,WAAAC,gBAAAC,YAAAC,aAAAC,QAAA;CAAA,MAAAC,IAAAvB,EAAA,CAAA;CAAA,IAAAwB;CAAA,IAAAD,EAAA,OAAAL,aAAAK,EAAA,OAAAF,eAAAE,EAAA,OAAAD,UAAAC,EAAA,OAAAH,cAAAG,EAAA,OAAAN,SAAAM,EAAA,OAAAJ,gBAAA;EAQYK,WAAA;GACR,IAAI,CAACN,UAASO,SAAQ;GACtB,IAAIR,UAAUS,KAAAA,GAAS;GACvB,IAAIL,YAAWI,YAAaR,OAAK;GACjC,IAAI,CAACE,eAAcM,SAAQ;IACzBL,WAAUK,UAAWR;IAAH;GAAA;GAGpBK,OAAOJ,UAASO,SAAUR,KAAK;GAC/BI,YAAWI,UAAWR;EAAH;EAEpBM,EAAA,KAAAL;EAAAK,EAAA,KAAAF;EAAAE,EAAA,KAAAD;EAAAC,EAAA,KAAAH;EAAAG,EAAA,KAAAN;EAAAM,EAAA,KAAAJ;EAAAI,EAA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UAAU;IACzBiD,gBAAgBjD,UAAUC,KAAAA;IAC1BiD,iBAAiBlD,UAAUC,KAAAA;IAC3BkD,sBAAsBnD,UAAUC,KAAAA;GAClC;EACF;CACF;CAEAV,gBACEgB,OACAd,WACAC,gBACAuD,iBACAH,mBACCa,KAAGa,MAAMb,IAAEC,gBAAgBY,CAAC,CAC/B;CACAjF,gBACEiB,QACAf,WACAC,gBACAwD,kBACAH,oBACCY,KAAGa,QAAMb,IAAEE,iBAAiBW,GAAC,CAChC;CACAjF,gBACEe,aACAb,WACAC,gBACAyD,uBACAH,yBACCW,KAAGa,QAAMb,IAAEG,yBAAyBU,GAAC,CACxC;CAEA,OACE,oBAAC,aAAD;EACE,SAAS,EAAEC,MAAM9B,SAAS8B,KAAK;EAC/B,YACE/B,IAAIgC,WAAW,GAAGhC,IAAIgC,SAAQ,GAAI/B,SAASgC,QAAQhC,SAASgC;EAE9D,SAAS;GAAE,GAAG/B;GAASgC,SAAShC,SAASgC,WAAWxF;EAAgB;EACzDyD;EACGO;EACd,UAAUyB,QAAQlE,QAAQX,QAAQI,UAAUmC,UAAUsC,GAAG;EACzD,gBAAgB;GACd,yBAAyBnC,IAAIoC;GAC7B,+BAA+BnC,SAASoC,MAAMC,gBAC1C,KACA/E,KAAAA;EACN;CAAE,CAAA;AAGR"}
1
+ {"version":3,"file":"app-frame.js","names":["c","_c","MutableRefObject","useEffect","useLayoutEffect","useRef","McpAppBridge","createMcpAppBridge","SandboxHost","SandboxBridge","SandboxHostApi","SandboxHostFrame","McpAppBridgeHandlers","McpAppFrameProps","McpAppHostContext","DEFAULT_PRODUCT","INIT_TIMEOUT_MS","DEFAULT_MAX_HEIGHT","useBridgeNotify","value","bridgeRef","widgetReadyRef","pendingRef","lastSentRef","notify","$","t0","current","undefined","t1","LiveSnapshot","handlers","hostInfo","hostContext","input","output","buildLiveHandlers","initial","liveRef","live","has","key","K","out","Object","defineProperty","get","allowedTools","enumerable","configurable","liveCall","NonNullable","p","fn","Error","callTool","readResource","listResources","openLink","sendMessage","updateModelContext","requestDisplayMode","onSizeChange","onInitialized","onRequestTeardown","onLog","onError","e","McpAppFrame","app","resource","sandbox","maxHeight","lastSentInputRef","lastSentOutputRef","lastSentHostContextRef","pendingInputRef","pendingOutputRef","pendingHostContextRef","t2","t3","t4","t5","Symbol","for","frame","host","initTimeoutId","flushPending","b","notifyToolInput","notifyToolResult","notifyHostContextChanged","liveHandlers","liveOnInitialized","wrappedHandlers","clearTimeout","height","setHeight","setTimeout","bridge","onMessage","dispose","createBridge","_temp","_temp2","_temp3","t6","html","t7","serverId","uri","t8","product","t9","t10","err","t11","meta","prefersBorder","t12","resourceUri","t13","b_2","v_1","v","b_1","v_0","b_0"],"sources":["../../src/mcp-apps/app-frame.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type MutableRefObject,\n useEffect,\n useLayoutEffect,\n useRef,\n} from \"react\";\nimport { type McpAppBridge, createMcpAppBridge } from \"./bridge\";\nimport {\n SandboxHost,\n type SandboxBridge,\n type SandboxHostApi,\n type SandboxHostFrame,\n} from \"../sandbox-host/SandboxHost\";\nimport type {\n McpAppBridgeHandlers,\n McpAppFrameProps,\n McpAppHostContext,\n} from \"./types\";\n\nconst DEFAULT_PRODUCT = \"assistant-ui-mcp-app\";\nconst INIT_TIMEOUT_MS = 5000;\nconst DEFAULT_MAX_HEIGHT = 800;\n\nfunction useBridgeNotify<T>(\n value: T | undefined,\n bridgeRef: MutableRefObject<McpAppBridge | null>,\n widgetReadyRef: MutableRefObject<boolean>,\n pendingRef: MutableRefObject<T | undefined>,\n lastSentRef: MutableRefObject<T | undefined>,\n notify: (bridge: McpAppBridge, v: T) => void,\n) {\n useEffect(() => {\n if (!bridgeRef.current) return;\n if (value === undefined) return;\n if (lastSentRef.current === value) return;\n if (!widgetReadyRef.current) {\n pendingRef.current = value;\n return;\n }\n notify(bridgeRef.current, value);\n lastSentRef.current = value;\n // oxlint-disable-next-line react/exhaustive-deps -- refs are stable; notify is assumed stable; re-run only when value changes\n }, [value]);\n}\n\ntype LiveSnapshot = {\n handlers: McpAppBridgeHandlers | undefined;\n hostInfo: McpAppFrameProps[\"hostInfo\"];\n hostContext: McpAppFrameProps[\"hostContext\"];\n input: unknown;\n output: unknown;\n};\n\n// Proxy each per-call handler through liveRef so the bridge always dispatches\n// to the latest handler reference (e.g. inline callbacks closing over state).\n// Capability presence is snapshot at mount: a handler added later requires a\n// remount (keyed on resource URI) to expose the capability to the widget.\nfunction buildLiveHandlers(\n initial: McpAppBridgeHandlers | undefined,\n liveRef: { readonly current: LiveSnapshot },\n): McpAppBridgeHandlers {\n const live = () => liveRef.current.handlers;\n const has = <K extends keyof McpAppBridgeHandlers>(key: K) =>\n initial?.[key] !== undefined;\n const out: McpAppBridgeHandlers = {};\n if (has(\"allowedTools\")) {\n Object.defineProperty(out, \"allowedTools\", {\n get: () => live()?.allowedTools,\n enumerable: true,\n configurable: true,\n });\n }\n const liveCall = <K extends keyof McpAppBridgeHandlers>(\n key: K,\n ): NonNullable<McpAppBridgeHandlers[K]> =>\n ((p: unknown) => {\n const fn = live()?.[key] as ((p: unknown) => unknown) | undefined;\n if (!fn) {\n throw new Error(`${key} handler is no longer available`);\n }\n return fn(p);\n }) as NonNullable<McpAppBridgeHandlers[K]>;\n if (has(\"callTool\")) out.callTool = liveCall(\"callTool\");\n if (has(\"readResource\")) out.readResource = liveCall(\"readResource\");\n if (has(\"listResources\")) out.listResources = liveCall(\"listResources\");\n if (has(\"openLink\")) out.openLink = liveCall(\"openLink\");\n if (has(\"sendMessage\")) out.sendMessage = liveCall(\"sendMessage\");\n if (has(\"updateModelContext\"))\n out.updateModelContext = liveCall(\"updateModelContext\");\n if (has(\"requestDisplayMode\"))\n out.requestDisplayMode = liveCall(\"requestDisplayMode\");\n out.onSizeChange = (p) => live()?.onSizeChange?.(p);\n out.onInitialized = () => live()?.onInitialized?.();\n out.onRequestTeardown = (p) => live()?.onRequestTeardown?.(p);\n out.onLog = (p) => live()?.onLog?.(p);\n out.onError = (e) => live()?.onError?.(e);\n return out;\n}\n\nexport function McpAppFrame({\n app,\n resource,\n input,\n output,\n sandbox,\n handlers,\n hostInfo,\n hostContext,\n maxHeight = DEFAULT_MAX_HEIGHT,\n}: McpAppFrameProps) {\n const bridgeRef = useRef<McpAppBridge | null>(null);\n const lastSentInputRef = useRef<unknown>(undefined);\n const lastSentOutputRef = useRef<unknown>(undefined);\n const lastSentHostContextRef = useRef<McpAppHostContext | undefined>(\n undefined,\n );\n // Per MCP Apps spec, the host should defer notifications until the widget\n // signals readiness via `notifications/initialized`. Until then, we record\n // pending values and flush them on init.\n const widgetReadyRef = useRef(false);\n const pendingInputRef = useRef<unknown>(undefined);\n const pendingOutputRef = useRef<unknown>(undefined);\n const pendingHostContextRef = useRef<McpAppHostContext | undefined>(\n undefined,\n );\n\n const liveRef = useRef<LiveSnapshot>({\n handlers,\n hostInfo,\n hostContext,\n input,\n output,\n });\n useLayoutEffect(() => {\n liveRef.current = {\n handlers,\n hostInfo,\n hostContext,\n input,\n output,\n };\n }, [handlers, hostInfo, hostContext, input, output]);\n\n const createBridge = (\n frame: SandboxHostFrame,\n host: SandboxHostApi,\n ): SandboxBridge => {\n const current = liveRef.current;\n let initTimeoutId: ReturnType<typeof setTimeout> | null = null;\n\n const flushPending = () => {\n if (widgetReadyRef.current) return;\n widgetReadyRef.current = true;\n const b = bridgeRef.current;\n if (!b) return;\n if (pendingInputRef.current !== undefined) {\n b.notifyToolInput(pendingInputRef.current);\n lastSentInputRef.current = pendingInputRef.current;\n pendingInputRef.current = undefined;\n }\n if (pendingOutputRef.current !== undefined) {\n b.notifyToolResult(pendingOutputRef.current);\n lastSentOutputRef.current = pendingOutputRef.current;\n pendingOutputRef.current = undefined;\n }\n if (pendingHostContextRef.current !== undefined) {\n b.notifyHostContextChanged(pendingHostContextRef.current);\n lastSentHostContextRef.current = pendingHostContextRef.current;\n pendingHostContextRef.current = undefined;\n }\n };\n\n const liveHandlers = buildLiveHandlers(current.handlers, liveRef);\n const liveOnInitialized = liveHandlers.onInitialized;\n const wrappedHandlers: McpAppBridgeHandlers = {\n ...liveHandlers,\n onInitialized: () => {\n if (initTimeoutId !== null) {\n clearTimeout(initTimeoutId);\n initTimeoutId = null;\n }\n flushPending();\n liveOnInitialized?.();\n },\n onSizeChange: (p) => {\n if (p.height != null) host.setHeight(p.height);\n liveHandlers.onSizeChange?.(p);\n },\n };\n\n // Safety net: if the widget never sends notifications/initialized (broken\n // or non-spec-compliant), flush the queue anyway so the host doesn't\n // appear hung.\n initTimeoutId = setTimeout(() => {\n initTimeoutId = null;\n flushPending();\n }, INIT_TIMEOUT_MS);\n\n const bridge = createMcpAppBridge({\n frame,\n handlers: wrappedHandlers,\n hostInfo: current.hostInfo,\n hostContext: current.hostContext,\n });\n bridgeRef.current = bridge;\n\n if (current.input !== undefined) pendingInputRef.current = current.input;\n if (current.output !== undefined) pendingOutputRef.current = current.output;\n // hostContext is delivered inside the ui/initialize response; subsequent\n // changes flow through useBridgeNotify's pending path.\n\n return {\n onMessage: bridge.onMessage,\n dispose: () => {\n if (initTimeoutId !== null) {\n clearTimeout(initTimeoutId);\n initTimeoutId = null;\n }\n bridge.dispose();\n bridgeRef.current = null;\n lastSentInputRef.current = undefined;\n lastSentOutputRef.current = undefined;\n lastSentHostContextRef.current = undefined;\n widgetReadyRef.current = false;\n pendingInputRef.current = undefined;\n pendingOutputRef.current = undefined;\n pendingHostContextRef.current = undefined;\n },\n };\n };\n\n useBridgeNotify(\n input,\n bridgeRef,\n widgetReadyRef,\n pendingInputRef,\n lastSentInputRef,\n (b, v) => b.notifyToolInput(v),\n );\n useBridgeNotify(\n output,\n bridgeRef,\n widgetReadyRef,\n pendingOutputRef,\n lastSentOutputRef,\n (b, v) => b.notifyToolResult(v),\n );\n useBridgeNotify(\n hostContext,\n bridgeRef,\n widgetReadyRef,\n pendingHostContextRef,\n lastSentHostContextRef,\n (b, v) => b.notifyHostContextChanged(v),\n );\n\n return (\n <SandboxHost\n content={{ html: resource.html }}\n contentKey={\n app.serverId ? `${app.serverId} ${resource.uri}` : resource.uri\n }\n sandbox={{ ...sandbox, product: sandbox?.product ?? DEFAULT_PRODUCT }}\n maxHeight={maxHeight}\n createBridge={createBridge}\n onError={(err) => liveRef.current.handlers?.onError?.(err)}\n containerProps={{\n \"data-mcp-app-resource\": app.resourceUri,\n \"data-mcp-app-prefers-border\": resource.meta?.prefersBorder\n ? \"\"\n : undefined,\n }}\n />\n );\n}\n"],"mappings":";;;;;;;AAqBA,MAAMe,kBAAkB;AACxB,MAAMC,kBAAkB;AACxB,MAAMC,qBAAqB;AAE3B,SAAAC,gBAAAC,OAAAC,WAAAC,gBAAAC,YAAAC,aAAAC,QAAA;CAAA,MAAAC,IAAAxB,EAAA,CAAA;CAAA,IAAAyB;CAAA,IAAAD,EAAA,OAAAL,aAAAK,EAAA,OAAAF,eAAAE,EAAA,OAAAD,UAAAC,EAAA,OAAAH,cAAAG,EAAA,OAAAN,SAAAM,EAAA,OAAAJ,gBAAA;EAQYK,WAAA;GACR,IAAI,CAACN,UAASO,SAAQ;GACtB,IAAIR,UAAUS,KAAAA,GAAS;GACvB,IAAIL,YAAWI,YAAaR,OAAK;GACjC,IAAI,CAACE,eAAcM,SAAQ;IACzBL,WAAUK,UAAWR;IAAH;GAAA;GAGpBK,OAAOJ,UAASO,SAAUR,KAAK;GAC/BI,YAAWI,UAAWR;EAAH;EAEpBM,EAAA,KAAAL;EAAAK,EAAA,KAAAF;EAAAE,EAAA,KAAAD;EAAAC,EAAA,KAAAH;EAAAG,EAAA,KAAAN;EAAAM,EAAA,KAAAJ;EAAAI,EAAA,KAAAC;CAAA,OAAAA,KAAAD,EAAA;CAAA,IAAAI;CAAA,IAAAJ,EAAA,OAAAN,OAAA;EAAEU,KAAA,CAACV,KAAK;EAACM,EAAA,KAAAN;EAAAM,EAAA,KAAAI;CAAA,OAAAA,KAAAJ,EAAA;CAXVtB,UAAUuB,IAWPG,EAAO;AAAC;AAeb,SAASO,kBACPC,SACAC,S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A,MAAAkF;EAAAlF,EAAA,MAAAoF;EAAApF,EAAA,MAAAyF;EAAAzF,EAAA,MAAAiG;CAAA,OAAAA,MAAAjG,EAAA;CAAA,OAfFiG;AAeE;AA7KC,SAAAhB,OAAAiB,KAAAC,KAAA;CAAA,OA0JOnC,IAACG,yBAA0BiC,GAAC;AAAC;AA1JpC,SAAApB,OAAAqB,KAAAC,KAAA;CAAA,OAkJOtC,IAACE,iBAAkBkC,GAAC;AAAC;AAlJ5B,SAAArB,MAAAwB,KAAAH,GAAA;CAAA,OA0IOpC,IAACC,gBAAiBmC,CAAC;AAAC"}
@@ -1,5 +1,5 @@
1
- import { McpAppDisplayMode, McpAppHostContext, McpAppHostInfo, McpAppMetadata, McpAppResource, McpAppResourceCSP, McpAppResourceMeta, McpAppSandboxConfig, McpAppToolCallParams, McpAppsHost, McpAppsRemoteHostOptions, ToolCallMessagePartMcpMetadata } from "./types.js";
1
+ import { McpAppBridgeHandlers, McpAppDisplayMode, McpAppHostContext, McpAppHostInfo, McpAppMetadata, McpAppResource, McpAppResourceCSP, McpAppResourceMeta, McpAppSandboxConfig, McpAppToolCallParams, McpAppsHost, McpAppsRemoteHostOptions, ToolCallMessagePartMcpMetadata } from "./types.js";
2
2
  import { McpAppRenderer, McpAppRendererOptions } from "./McpAppRenderer.js";
3
3
  import { McpAppsRemoteHost } from "./McpAppsRemoteHost.js";
4
4
  import { getMcpAppFromToolPart } from "./utils.js";
5
- export { type McpAppDisplayMode, type McpAppHostContext, type McpAppHostInfo, type McpAppMetadata, McpAppRenderer, type McpAppRendererOptions, type McpAppResource, type McpAppResourceCSP, type McpAppResourceMeta, type McpAppSandboxConfig, type McpAppToolCallParams, type McpAppsHost, McpAppsRemoteHost, type McpAppsRemoteHostOptions, type ToolCallMessagePartMcpMetadata, getMcpAppFromToolPart };
5
+ export { type McpAppBridgeHandlers, type McpAppDisplayMode, type McpAppHostContext, type McpAppHostInfo, type McpAppMetadata, McpAppRenderer, type McpAppRendererOptions, type McpAppResource, type McpAppResourceCSP, type McpAppResourceMeta, type McpAppSandboxConfig, type McpAppToolCallParams, type McpAppsHost, McpAppsRemoteHost, type McpAppsRemoteHostOptions, type ToolCallMessagePartMcpMetadata, getMcpAppFromToolPart };
@@ -16,7 +16,7 @@ type UseAssistantFrameHostOptions = {
16
16
  *
17
17
  * useAssistantFrameHost({
18
18
  * iframeRef,
19
- * targetOrigin: "https://trusted-domain.com", // optional
19
+ * targetOrigin: "https://trusted-domain.com",
20
20
  * });
21
21
  *
22
22
  * return <iframe ref={iframeRef} src="..." />;
@@ -13,7 +13,7 @@ import { useEffect } from "@assistant-ui/tap/react-shim";
13
13
  *
14
14
  * useAssistantFrameHost({
15
15
  * iframeRef,
16
- * targetOrigin: "https://trusted-domain.com", // optional
16
+ * targetOrigin: "https://trusted-domain.com",
17
17
  * });
18
18
  *
19
19
  * return <iframe ref={iframeRef} src="..." />;
@@ -22,12 +22,11 @@ import { useEffect } from "@assistant-ui/tap/react-shim";
22
22
  */
23
23
  const useAssistantFrameHost = (t0) => {
24
24
  const $ = c(5);
25
- const { iframeRef, targetOrigin: t1, register } = t0;
26
- const targetOrigin = t1 === void 0 ? "*" : t1;
25
+ const { iframeRef, targetOrigin, register } = t0;
26
+ let t1;
27
27
  let t2;
28
- let t3;
29
28
  if ($[0] !== iframeRef || $[1] !== register || $[2] !== targetOrigin) {
30
- t2 = () => {
29
+ t1 = () => {
31
30
  const iframeWindow = iframeRef.current?.contentWindow;
32
31
  if (!iframeWindow) return;
33
32
  const frameHost = new AssistantFrameHost(iframeWindow, targetOrigin);
@@ -37,7 +36,7 @@ const useAssistantFrameHost = (t0) => {
37
36
  unsubscribe();
38
37
  };
39
38
  };
40
- t3 = [
39
+ t2 = [
41
40
  iframeRef,
42
41
  targetOrigin,
43
42
  register
@@ -45,13 +44,13 @@ const useAssistantFrameHost = (t0) => {
45
44
  $[0] = iframeRef;
46
45
  $[1] = register;
47
46
  $[2] = targetOrigin;
48
- $[3] = t2;
49
- $[4] = t3;
47
+ $[3] = t1;
48
+ $[4] = t2;
50
49
  } else {
51
- t2 = $[3];
52
- t3 = $[4];
50
+ t1 = $[3];
51
+ t2 = $[4];
53
52
  }
54
- useEffect(t2, t3);
53
+ useEffect(t1, t2);
55
54
  };
56
55
  //#endregion
57
56
  export { useAssistantFrameHost };
@@ -1 +1 @@
1
- {"version":3,"file":"useAssistantFrameHost.js","names":["c","_c","Unsubscribe","useEffect","RefObject","AssistantFrameHost","UseAssistantFrameHostOptions","iframeRef","Readonly","HTMLIFrameElement","targetOrigin","register","frameHost","useAssistantFrameHost","t0","$","t1","undefined","t2","t3","iframeWindow","current","contentWindow","unsubscribe","dispose"],"sources":["../../../src/model-context/frame/useAssistantFrameHost.ts"],"sourcesContent":["\"use client\";\n\nimport type { Unsubscribe } from \"@assistant-ui/core\";\nimport { useEffect, type RefObject } from \"react\";\nimport { AssistantFrameHost } from \"@assistant-ui/core\";\n\ntype UseAssistantFrameHostOptions = {\n iframeRef: Readonly<RefObject<HTMLIFrameElement | null | undefined>>;\n targetOrigin?: string;\n register: (frameHost: AssistantFrameHost) => Unsubscribe;\n};\n\n/**\n * React hook that manages the lifecycle of an AssistantFrameHost and its binding to the current AssistantRuntime.\n *\n * Usage example:\n * ```typescript\n * function MyComponent() {\n * const iframeRef = useRef<HTMLIFrameElement>(null);\n *\n * useAssistantFrameHost({\n * iframeRef,\n * targetOrigin: \"https://trusted-domain.com\", // optional\n * });\n *\n * return <iframe ref={iframeRef} src=\"...\" />;\n * }\n * ```\n */\nexport const useAssistantFrameHost = ({\n iframeRef,\n targetOrigin = \"*\",\n register,\n}: UseAssistantFrameHostOptions): void => {\n useEffect(() => {\n const iframeWindow = iframeRef.current?.contentWindow;\n if (!iframeWindow) return;\n\n const frameHost = new AssistantFrameHost(iframeWindow, targetOrigin);\n\n const unsubscribe = register(frameHost);\n\n return () => {\n frameHost.dispose();\n unsubscribe();\n };\n }, [iframeRef, targetOrigin, register]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA6BA,MAAaa,yBAAwBC,OAAA;CAAA,MAAAC,IAAAd,EAAA,CAAA;CAAC,MAAA,EAAAM,WAAAG,cAAAM,IAAAL,aAAAG;CAEpC,MAAAJ,eAAAM,OAAAC,KAAAA,IAAA,MAAAD;CAAkB,IAAAE;CAAA,IAAAC;CAAA,IAAAJ,EAAA,OAAAR,aAAAQ,EAAA,OAAAJ,YAAAI,EAAA,OAAAL,cAAA;EAGRQ,WAAA;GACR,MAAAE,eAAqBb,UAASc,SAAuBC;GACrD,IAAI,CAACF,cAAY;GAEjB,MAAAR,YAAkB,IAAIP,mBAAmBe,cAAcV,YAAY;GAEnE,MAAAa,cAAoBZ,SAASC,SAAS;GAAE,aAEjC;IACLA,UAASY,QAAS;IAClBD,YAAY;GAAC;EACd;EACAJ,KAAA;GAACZ;GAAWG;GAAcC;EAAQ;EAACI,EAAA,KAAAR;EAAAQ,EAAA,KAAAJ;EAAAI,EAAA,KAAAL;EAAAK,EAAA,KAAAG;EAAAH,EAAA,KAAAI;CAAA,OAAA;EAAAD,KAAAH,EAAA;EAAAI,KAAAJ,EAAA;CAAA;CAZtCZ,UAAUe,IAYPC,EAAmC;AAAC"}
1
+ {"version":3,"file":"useAssistantFrameHost.js","names":["c","_c","Unsubscribe","useEffect","RefObject","AssistantFrameHost","UseAssistantFrameHostOptions","iframeRef","Readonly","HTMLIFrameElement","targetOrigin","register","frameHost","useAssistantFrameHost","t0","$","t1","t2","iframeWindow","current","contentWindow","unsubscribe","dispose"],"sources":["../../../src/model-context/frame/useAssistantFrameHost.ts"],"sourcesContent":["\"use client\";\n\nimport type { Unsubscribe } from \"@assistant-ui/core\";\nimport { useEffect, type RefObject } from \"react\";\nimport { AssistantFrameHost } from \"@assistant-ui/core\";\n\ntype UseAssistantFrameHostOptions = {\n iframeRef: Readonly<RefObject<HTMLIFrameElement | null | undefined>>;\n targetOrigin?: string;\n register: (frameHost: AssistantFrameHost) => Unsubscribe;\n};\n\n/**\n * React hook that manages the lifecycle of an AssistantFrameHost and its binding to the current AssistantRuntime.\n *\n * Usage example:\n * ```typescript\n * function MyComponent() {\n * const iframeRef = useRef<HTMLIFrameElement>(null);\n *\n * useAssistantFrameHost({\n * iframeRef,\n * targetOrigin: \"https://trusted-domain.com\",\n * });\n *\n * return <iframe ref={iframeRef} src=\"...\" />;\n * }\n * ```\n */\nexport const useAssistantFrameHost = ({\n iframeRef,\n targetOrigin,\n register,\n}: UseAssistantFrameHostOptions): void => {\n useEffect(() => {\n const iframeWindow = iframeRef.current?.contentWindow;\n if (!iframeWindow) return;\n\n const frameHost = new AssistantFrameHost(iframeWindow, targetOrigin);\n\n const unsubscribe = register(frameHost);\n\n return () => {\n frameHost.dispose();\n unsubscribe();\n };\n }, [iframeRef, targetOrigin, register]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA6BA,MAAaa,yBAAwBC,OAAA;CAAA,MAAAC,IAAAd,EAAA,CAAA;CAAC,MAAA,EAAAM,WAAAG,cAAAC,aAAAG;CAIP,IAAAE;CAAA,IAAAC;CAAA,IAAAF,EAAA,OAAAR,aAAAQ,EAAA,OAAAJ,YAAAI,EAAA,OAAAL,cAAA;EACnBM,WAAA;GACR,MAAAE,eAAqBX,UAASY,SAAuBC;GACrD,IAAI,CAACF,cAAY;GAEjB,MAAAN,YAAkB,IAAIP,mBAAmBa,cAAcR,YAAY;GAEnE,MAAAW,cAAoBV,SAASC,SAAS;GAAE,aAEjC;IACLA,UAASU,QAAS;IAClBD,YAAY;GAAC;EACd;EACAJ,KAAA;GAACV;GAAWG;GAAcC;EAAQ;EAACI,EAAA,KAAAR;EAAAQ,EAAA,KAAAJ;EAAAI,EAAA,KAAAL;EAAAK,EAAA,KAAAC;EAAAD,EAAA,KAAAE;CAAA,OAAA;EAAAD,KAAAD,EAAA;EAAAE,KAAAF,EAAA;CAAA;CAZtCZ,UAAUa,IAYPC,EAAmC;AAAC"}
@@ -4,7 +4,7 @@ import { useAui } from "@assistant-ui/store";
4
4
  import { tool } from "@assistant-ui/core";
5
5
  import { createContext, forwardRef, useContext, useEffect, useId, useRef } from "@assistant-ui/tap/react-shim";
6
6
  import { jsx } from "react/jsx-runtime";
7
- import { useComposedRefs } from "@radix-ui/react-compose-refs";
7
+ import { useComposedRefs } from "radix-ui/internal";
8
8
  //#region src/model-context/makeAssistantVisible.tsx
9
9
  const click = tool({
10
10
  parameters: {
@@ -1 +1 @@
1
- {"version":3,"file":"makeAssistantVisible.js","names":["c","_c","useEffect","useRef","forwardRef","ComponentType","ForwardedRef","PropsWithoutRef","useId","createContext","useContext","useAui","useComposedRefs","tool","click","parameters","type","properties","clickId","required","execute","escapedClickId","CSS","escape","el","document","querySelector","HTMLElement","Promise","resolve","setTimeout","setNativeValue","element","HTMLInputElement","HTMLTextAreaElement","value","prototype","setter","Object","getOwnPropertyDescriptor","set","call","edit","editId","escapedEditId","dispatchEvent","Event","bubbles","ReadableContext","makeAssistantVisible","Component","T","config","clickable","editable","ReadableComponent","props","outerRef","$","isNestedReadable","componentRef","aui","t0","Symbol","for","t1","modelContext","register","getModelContext","tools","system","current","outerHTML","undefined","t2","ref","t3","t4","t5","t6","displayName"],"sources":["../../src/model-context/makeAssistantVisible.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n useEffect,\n useRef,\n forwardRef,\n type ComponentType,\n type ForwardedRef,\n type PropsWithoutRef,\n useId,\n createContext,\n useContext,\n} from \"react\";\nimport { useAui } from \"@assistant-ui/store\";\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport { tool } from \"@assistant-ui/core\";\n\nconst click = tool({\n parameters: {\n type: \"object\",\n properties: {\n clickId: {\n type: \"string\",\n },\n },\n required: [\"clickId\"],\n },\n execute: async ({ clickId }: { clickId: string }) => {\n const escapedClickId = CSS.escape(clickId);\n const el = document.querySelector(`[data-click-id='${escapedClickId}']`);\n if (el instanceof HTMLElement) {\n el.click();\n\n // todo make adjustable\n await new Promise((resolve) => setTimeout(resolve, 2000));\n return {};\n } else {\n return \"Element not found\";\n }\n },\n});\n\nconst setNativeValue = (\n element: HTMLInputElement | HTMLTextAreaElement,\n value: string,\n) => {\n const prototype =\n element instanceof HTMLInputElement\n ? HTMLInputElement.prototype\n : HTMLTextAreaElement.prototype;\n const setter = Object.getOwnPropertyDescriptor(prototype, \"value\")?.set;\n\n if (setter) {\n setter.call(element, value);\n } else {\n element.value = value;\n }\n};\n\nconst edit = tool({\n parameters: {\n type: \"object\",\n properties: {\n editId: {\n type: \"string\",\n },\n value: {\n type: \"string\",\n },\n },\n required: [\"editId\", \"value\"],\n },\n execute: async ({ editId, value }: { editId: string; value: string }) => {\n const escapedEditId = CSS.escape(editId);\n const el = document.querySelector(`[data-edit-id='${escapedEditId}']`);\n if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {\n setNativeValue(el, value);\n el.dispatchEvent(new Event(\"input\", { bubbles: true }));\n el.dispatchEvent(new Event(\"change\", { bubbles: true }));\n\n // todo make adjustable\n await new Promise((resolve) => setTimeout(resolve, 2000));\n return {};\n } else {\n return \"Element not found\";\n }\n },\n});\n\nconst ReadableContext = createContext<boolean>(false);\n\nexport const makeAssistantVisible = <T extends ComponentType<any>>(\n Component: T,\n config?: { clickable?: boolean | undefined; editable?: boolean | undefined },\n) => {\n const ReadableComponent = forwardRef(\n (props: PropsWithoutRef<T>, outerRef: ForwardedRef<any>) => {\n const isNestedReadable = useContext(ReadableContext);\n\n const clickId = useId();\n const componentRef = useRef<HTMLElement>(null);\n\n const aui = useAui();\n\n const { clickable, editable } = config ?? {};\n useEffect(() => {\n return aui.modelContext.register({\n getModelContext: () => {\n return {\n tools: {\n ...(clickable ? { click } : {}),\n ...(editable ? { edit } : {}),\n },\n system: !isNestedReadable // only pass content if this readable isn't nested in another readable\n ? componentRef.current?.outerHTML\n : undefined,\n };\n },\n });\n }, [isNestedReadable, aui, clickable, editable]);\n\n const ref = useComposedRefs(componentRef, outerRef);\n\n return (\n <ReadableContext.Provider value={true}>\n <Component\n {...(props as any)}\n {...(config?.clickable ? { \"data-click-id\": clickId } : {})}\n {...(config?.editable ? { \"data-edit-id\": clickId } : {})}\n ref={ref}\n />\n </ReadableContext.Provider>\n );\n },\n );\n\n ReadableComponent.displayName = Component.displayName;\n\n return ReadableComponent as unknown as T;\n};\n\nexport default makeAssistantVisible;\n"],"mappings":";;;;;;;;AAiBA,MAAMc,QAAQD,KAAK;CACjBE,YAAY;EACVC,MAAM;EACNC,YAAY,EACVC,SAAS,EACPF,MAAM,SACR,EACF;EACAG,UAAU,CAAC,SAAS;CACtB;CACAC,SAAS,OAAO,EAAEF,cAAmC;EACnD,MAAMG,iBAAiBC,IAAIC,OAAOL,OAAO;EACzC,MAAMM,KAAKC,SAASC,cAAc,mBAAmBL,eAAc,GAAI;EACvE,IAAIG,cAAcG,aAAa;GAC7BH,GAAGV,MAAM;GAGT,MAAM,IAAIc,SAASC,YAAYC,WAAWD,SAAS,GAAI,CAAC;GACxD,OAAO,CAAC;EACV,OACE,OAAO;CAEX;AACF,CAAC;AAED,MAAME,kBACJC,SACAG,UACG;CACH,MAAMC,YACJJ,mBAAmBC,mBACfA,iBAAiBG,YACjBF,oBAAoBE;CAC1B,MAAMC,SAASC,OAAOC,yBAAyBH,WAAW,OAAO,CAAC,EAAEI;CAEpE,IAAIH,QACFA,OAAOI,KAAKT,SAASG,KAAK;MAE1BH,QAAQG,QAAQA;AAEpB;AAEA,MAAMO,OAAO7B,KAAK;CAChBE,YAAY;EACVC,MAAM;EACNC,YAAY;GACV0B,QAAQ,EACN3B,MAAM,SACR;GACAmB,OAAO,EACLnB,MAAM,SACR;EACF;EACAG,UAAU,CAAC,UAAU,OAAO;CAC9B;CACAC,SAAS,OAAO,EAAEuB,QAAQR,YAA+C;EACvE,MAAMS,gBAAgBtB,IAAIC,OAAOoB,MAAM;EACvC,MAAMnB,KAAKC,SAASC,cAAc,kBAAkBkB,cAAa,GAAI;EACrE,IAAIpB,cAAcS,oBAAoBT,cAAcU,qBAAqB;GACvEH,eAA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AA;IAACf;IAAkBE;IAAKR;IAAWC;GAAQ;GAACI,EAAA,KAAAG;GAAAH,EAAA,KAAAC;GAAAD,EAAA,KAAAgB;EAAA,OAAAA,KAAAhB,EAAA;EAd/CxD,UAAU+D,IAcPS,EAA4C;EAE/C,MAAAC,MAAY/D,gBAAgBgD,cAAcH,QAAQ;EAKvC,MAAAmB,KAAApB;EAAY,IAAAqB;EAAA,IAAAC;EAAA,IAAApB,EAAA,OAAAxC,SAAA;GACZ2D,KAAAzB,QAAMC,YAAN,EAAA,iBAAuCnC,QAAa,IAApD,CAAoD;GACpD4D,KAAA1B,QAAME,WAAN,EAAA,gBAAqCpC,QAAa,IAAlD,CAAkD;GAACwC,EAAA,KAAAxC;GAAAwC,EAAA,KAAAmB;GAAAnB,EAAA,KAAAoB;EAAA,OAAA;GAAAD,KAAAnB,EAAA;GAAAoB,KAAApB,EAAA;EAAA;EAAA,IAAAqB;EAAA,IAAArB,EAAA,QAAAiB,OAAAjB,EAAA,QAAAkB,MAAAlB,EAAA,QAAAmB,MAAAnB,EAAA,QAAAoB,IAAA;GAJ5DC,KAAA,oBAAA,gBAAA,UAAA;IAAiC,OAAA;IAC/B,UAAA,oBAAC,WAAD;KAAU,GACHH;KAAY,GACZC;KAAqD,GACrDC;KACAH;IAAG,CAAA;GAEZ,CAAA;GAA2BjB,EAAA,MAAAiB;GAAAjB,EAAA,MAAAkB;GAAAlB,EAAA,MAAAmB;GAAAnB,EAAA,MAAAoB;GAAApB,EAAA,MAAAqB;EAAA,OAAAA,KAAArB,EAAA;EAAA,OAP3BqB;CAO2B,CAGjC;CAEAxB,kBAAkByB,cAAc9B,UAAU8B;CAE1C,OAAOzB;AACT"}
1
+ {"version":3,"file":"makeAssistantVisible.js","names":["c","_c","useEffect","useRef","forwardRef","ComponentType","ForwardedRef","PropsWithoutRef","useId","createContext","useContext","useAui","useComposedRefs","tool","click","parameters","type","properties","clickId","required","execute","escapedClickId","CSS","escape","el","document","querySelector","HTMLElement","Promise","resolve","setTimeout","setNativeValue","element","HTMLInputElement","HTMLTextAreaElement","value","prototype","setter","Object","getOwnPropertyDescriptor","set","call","edit","editId","escapedEditId","dispatchEvent","Event","bubbles","ReadableContext","makeAssistantVisible","Component","T","config","clickable","editable","ReadableComponent","props","outerRef","$","isNestedReadable","componentRef","aui","t0","Symbol","for","t1","modelContext","register","getModelContext","tools","system","current","outerHTML","undefined","t2","ref","t3","t4","t5","t6","displayName"],"sources":["../../src/model-context/makeAssistantVisible.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n useEffect,\n useRef,\n forwardRef,\n type ComponentType,\n type ForwardedRef,\n type PropsWithoutRef,\n useId,\n createContext,\n useContext,\n} from \"react\";\nimport { useAui } from \"@assistant-ui/store\";\nimport { useComposedRefs } from \"radix-ui/internal\";\nimport { tool } from \"@assistant-ui/core\";\n\nconst click = tool({\n parameters: {\n type: \"object\",\n properties: {\n clickId: {\n type: \"string\",\n },\n },\n required: [\"clickId\"],\n },\n execute: async ({ clickId }: { clickId: string }) => {\n const escapedClickId = CSS.escape(clickId);\n const el = document.querySelector(`[data-click-id='${escapedClickId}']`);\n if (el instanceof HTMLElement) {\n el.click();\n\n // todo make adjustable\n await new Promise((resolve) => setTimeout(resolve, 2000));\n return {};\n } else {\n return \"Element not found\";\n }\n },\n});\n\nconst setNativeValue = (\n element: HTMLInputElement | HTMLTextAreaElement,\n value: string,\n) => {\n const prototype =\n element instanceof HTMLInputElement\n ? HTMLInputElement.prototype\n : HTMLTextAreaElement.prototype;\n const setter = Object.getOwnPropertyDescriptor(prototype, \"value\")?.set;\n\n if (setter) {\n setter.call(element, value);\n } else {\n element.value = value;\n }\n};\n\nconst edit = tool({\n parameters: {\n type: \"object\",\n properties: {\n editId: {\n type: \"string\",\n },\n value: {\n type: \"string\",\n },\n },\n required: [\"editId\", \"value\"],\n },\n execute: async ({ editId, value }: { editId: string; value: string }) => {\n const escapedEditId = CSS.escape(editId);\n const el = document.querySelector(`[data-edit-id='${escapedEditId}']`);\n if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {\n setNativeValue(el, value);\n el.dispatchEvent(new Event(\"input\", { bubbles: true }));\n el.dispatchEvent(new Event(\"change\", { bubbles: true }));\n\n // todo make adjustable\n await new Promise((resolve) => setTimeout(resolve, 2000));\n return {};\n } else {\n return \"Element not found\";\n }\n },\n});\n\nconst ReadableContext = createContext<boolean>(false);\n\nexport const makeAssistantVisible = <T extends ComponentType<any>>(\n Component: T,\n config?: { clickable?: boolean | undefined; editable?: boolean | undefined },\n) => {\n const ReadableComponent = forwardRef(\n (props: PropsWithoutRef<T>, outerRef: ForwardedRef<any>) => {\n const isNestedReadable = useContext(ReadableContext);\n\n const clickId = useId();\n const componentRef = useRef<HTMLElement>(null);\n\n const aui = useAui();\n\n const { clickable, editable } = config ?? {};\n useEffect(() => {\n return aui.modelContext.register({\n getModelContext: () => {\n return {\n tools: {\n ...(clickable ? { click } : {}),\n ...(editable ? { edit } : {}),\n },\n system: !isNestedReadable // only pass content if this readable isn't nested in another readable\n ? componentRef.current?.outerHTML\n : undefined,\n };\n },\n });\n }, [isNestedReadable, aui, clickable, editable]);\n\n const ref = useComposedRefs(componentRef, outerRef);\n\n return (\n <ReadableContext.Provider value={true}>\n <Component\n {...(props as any)}\n {...(config?.clickable ? { \"data-click-id\": clickId } : {})}\n {...(config?.editable ? { \"data-edit-id\": clickId } : {})}\n ref={ref}\n />\n </ReadableContext.Provider>\n );\n },\n );\n\n ReadableComponent.displayName = Component.displayName;\n\n return ReadableComponent as unknown as T;\n};\n\nexport default makeAssistantVisible;\n"],"mappings":";;;;;;;;AAiBA,MAAMc,QAAQD,KAAK;CACjBE,YAAY;EACVC,MAAM;EACNC,YAAY,EACVC,SAAS,EACPF,MAAM,SACR,EACF;EACAG,UAAU,CAAC,SAAS;CACtB;CACAC,SAAS,OAAO,EAAEF,cAAmC;EACnD,MAAMG,iBAAiBC,IAAIC,OAAOL,OAAO;EACzC,MAAMM,KAAKC,SAASC,cAAc,mBAA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EAAA,KAAAmB;GAAAnB,EAAA,KAAAoB;EAAA,OAAA;GAAAD,KAAAnB,EAAA;GAAAoB,KAAApB,EAAA;EAAA;EAAA,IAAAqB;EAAA,IAAArB,EAAA,QAAAiB,OAAAjB,EAAA,QAAAkB,MAAAlB,EAAA,QAAAmB,MAAAnB,EAAA,QAAAoB,IAAA;GAJ5DC,KAAA,oBAAA,gBAAA,UAAA;IAAiC,OAAA;IAC/B,UAAA,oBAAC,WAAD;KAAU,GACHH;KAAY,GACZC;KAAqD,GACrDC;KACAH;IAAG,CAAA;GAEZ,CAAA;GAA2BjB,EAAA,MAAAiB;GAAAjB,EAAA,MAAAkB;GAAAlB,EAAA,MAAAmB;GAAAnB,EAAA,MAAAoB;GAAApB,EAAA,MAAAqB;EAAA,OAAAA,KAAArB,EAAA;EAAA,OAP3BqB;CAO2B,CAGjC;CAEAxB,kBAAkByB,cAAc9B,UAAU8B;CAE1C,OAAOzB;AACT"}
@@ -1,11 +1,11 @@
1
1
  "use client";
2
- import { Primitive } from "../../utils/Primitive.js";
2
+ import { Primitive as Primitive$1 } from "../../utils/Primitive.js";
3
3
  import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
4
4
  import { useActionBarCopy } from "@assistant-ui/core/react";
5
5
  import { useAuiState } from "@assistant-ui/store";
6
6
  import { forwardRef } from "@assistant-ui/tap/react-shim";
7
7
  import { jsx } from "react/jsx-runtime";
8
- import { composeEventHandlers } from "@radix-ui/primitive";
8
+ import { composeEventHandlers } from "radix-ui/internal";
9
9
  //#region src/primitives/actionBar/ActionBarCopy.tsx
10
10
  /**
11
11
  * Hook that provides copy functionality for action bar buttons.
@@ -119,7 +119,7 @@ const ActionBarPrimitiveCopy = forwardRef((t0, forwardedRef) => {
119
119
  } else t5 = $[13];
120
120
  let t6;
121
121
  if ($[14] !== forwardedRef || $[15] !== props || $[16] !== t2 || $[17] !== t3 || $[18] !== t5) {
122
- t6 = /* @__PURE__ */ jsx(Primitive.button, {
122
+ t6 = /* @__PURE__ */ jsx(Primitive$1.button, {
123
123
  type: "button",
124
124
  ...t2,
125
125
  ...props,
@@ -1 +1 @@
1
- {"version":3,"file":"ActionBarCopy.js","names":["c","_c","forwardRef","ActionButtonProps","composeEventHandlers","Primitive","useActionBarCopy","useAuiState","useActionBarPrimitiveCopy","t0","$","t1","undefined","copiedDuration","t2","t3","copyToClipboard","_temp","copy","disabled","ActionBarPrimitiveCopy","Element","HTMLButtonElement","Props","forwardedRef","onClick","props","isCopied","_temp2","callback","t4","t5","t6","displayName","text","navigator","clipboard","Promise","reject","Error","writeText","s","message"],"sources":["../../../src/primitives/actionBar/ActionBarCopy.tsx"],"sourcesContent":["\"use client\";\n\nimport { forwardRef } from \"react\";\nimport type { ActionButtonProps } from \"../../utils/createActionButton\";\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport { Primitive } from \"../../utils/Primitive\";\nimport { useActionBarCopy } from \"@assistant-ui/core/react\";\nimport { useAuiState } from \"@assistant-ui/store\";\n\n/**\n * Hook that provides copy functionality for action bar buttons.\n *\n * This hook returns a callback function that copies message content to the clipboard,\n * or null if copying is not available. It handles both regular message content and\n * composer text when in editing mode.\n *\n * @param options Configuration options\n * @param options.copiedDuration Duration in milliseconds to show the copied state\n * @returns A copy callback function, or null if copying is disabled\n *\n * @example\n * ```tsx\n * function CustomCopyButton() {\n * const copy = useActionBarPrimitiveCopy({ copiedDuration: 2000 });\n *\n * return (\n * <button onClick={copy} disabled={!copy}>\n * {copy ? \"Copy\" : \"Cannot Copy\"}\n * </button>\n * );\n * }\n * ```\n */\nconst useActionBarPrimitiveCopy = ({\n copiedDuration = 3000,\n}: {\n copiedDuration?: number | undefined;\n} = {}) => {\n const { copy, disabled } = useActionBarCopy({\n copiedDuration,\n copyToClipboard: (text) => {\n if (typeof navigator === \"undefined\" || !navigator.clipboard) {\n return Promise.reject(new Error(\"Clipboard API is unavailable\"));\n }\n return navigator.clipboard.writeText(text);\n },\n });\n if (disabled) return null;\n return copy;\n};\n\nexport namespace ActionBarPrimitiveCopy {\n export type Element = HTMLButtonElement;\n /**\n * Props for the ActionBarPrimitive.Copy component.\n * Inherits all button element props and action button functionality.\n */\n export type Props = ActionButtonProps<typeof useActionBarPrimitiveCopy>;\n}\n\n/**\n * A button component that copies message content to the clipboard.\n *\n * This component automatically handles copying message text to the clipboard\n * and provides visual feedback through the data-copied attribute. It's disabled\n * when there's no copyable content available.\n *\n * @example\n * ```tsx\n * <ActionBarPrimitive.Copy copiedDuration={2000}>\n * Copy Message\n * </ActionBarPrimitive.Copy>\n * ```\n */\nexport const ActionBarPrimitiveCopy = forwardRef<\n ActionBarPrimitiveCopy.Element,\n ActionBarPrimitiveCopy.Props\n>(({ copiedDuration, onClick, disabled, ...props }, forwardedRef) => {\n const isCopied = useAuiState((s) => s.message.isCopied);\n const callback = useActionBarPrimitiveCopy({ copiedDuration });\n return (\n <Primitive.button\n type=\"button\"\n {...(isCopied ? { \"data-copied\": \"true\" } : {})}\n {...props}\n ref={forwardedRef}\n disabled={disabled || !callback}\n onClick={composeEventHandlers(onClick, () => {\n callback?.();\n })}\n />\n );\n});\n\nActionBarPrimitiveCopy.displayName = \"ActionBarPrimitive.Copy\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAMQ,6BAA4BC,OAAA;CAAA,MAAAC,IAAAT,EAAA,CAAA;CAAA,IAAAU;CAAA,IAAAD,EAAA,OAAAD,IAAA;EAACE,KAAAF,OAAAG,KAAAA,IAAA,CAI9B,IAJ8BH;EAI7BC,EAAA,KAAAD;EAAAC,EAAA,KAAAC;CAAA,OAAAA,KAAAD,EAAA;CAJ6B,MAAA,EAAAG,gBAAAC,OAAAH;CACjC,MAAAE,iBAAAC,OAAAF,KAAAA,IAAA,MAAAE;CAAqB,IAAAC;CAAA,IAAAL,EAAA,OAAAG,gBAAA;EAIuBE,KAAA;GAAAF;GAAAG,iBAEzBC;EAMnB;EAACP,EAAA,KAAAG;EAAAH,EAAA,KAAAK;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,qBAAqBqB,SAASK,EAEtC;EAACpB,EAAA,MAAAe;EAAAf,EAAA,MAAAoB;EAAApB,EAAA,MAAAqB;CAAA,OAAAA,KAAArB,EAAA;CAAA,IAAAsB;CAAA,IAAAtB,EAAA,QAAAc,gBAAAd,EAAA,QAAAgB,SAAAhB,EAAA,QAAAI,MAAAJ,EAAA,QAAAK,MAAAL,EAAA,QAAAqB,IAAA;EARJC,KAAA,oBAAA,UAAA,QAAA;GACO,MAAA;GAAQ,GACRlB;GAAyC,GAC1CY;GACCF,KAAAA;GACK,UAAAT;GACD,SAAAgB;EAEP,CAAA;EACFrB,EAAA,MAAAc;EAAAd,EAAA,MAAAgB;EAAAhB,EAAA,MAAAI;EAAAJ,EAAA,MAAAK;EAAAL,EAAA,MAAAqB;EAAArB,EAAA,MAAAsB;CAAA,OAAAA,KAAAtB,EAAA;CAAA,OATFsB;AASE,CAEL;AAEDZ,uBAAuBa,cAAc;AA7DH,SAAAhB,MAAAiB,MAAA;CAQ5B,IAAI,OAAOC,cAAc,eAArB,CAAqCA,UAASC,WAAU,OACnDC,QAAOC,uBAAQ,IAAIC,MAAM,8BAA8B,CAAC;CAChE,OACMJ,UAASC,UAAUI,UAAWN,IAAI;AAAC;AAiC9C,SAAAN,OAAAa,GAAA;CAAA,OACoCA,EAACC,QAAQf;AAAS"}
1
+ {"version":3,"file":"ActionBarCopy.js","names":["c","_c","forwardRef","ActionButtonProps","composeEventHandlers","Primitive","useActionBarCopy","useAuiState","useActionBarPrimitiveCopy","t0","$","t1","undefined","copiedDuration","t2","t3","copyToClipboard","_temp","copy","disabled","ActionBarPrimitiveCopy","Element","HTMLButtonElement","Props","forwardedRef","onClick","props","isCopied","_temp2","callback","t4","t5","t6","displayName","text","navigator","clipboard","Promise","reject","Error","writeText","s","message"],"sources":["../../../src/primitives/actionBar/ActionBarCopy.tsx"],"sourcesContent":["\"use client\";\n\nimport { forwardRef } from \"react\";\nimport type { ActionButtonProps } from \"../../utils/createActionButton\";\nimport { composeEventHandlers } from \"radix-ui/internal\";\nimport { Primitive } from \"../../utils/Primitive\";\nimport { useActionBarCopy } from \"@assistant-ui/core/react\";\nimport { useAuiState } from \"@assistant-ui/store\";\n\n/**\n * Hook that provides copy functionality for action bar buttons.\n *\n * This hook returns a callback function that copies message content to the clipboard,\n * or null if copying is not available. It handles both regular message content and\n * composer text when in editing mode.\n *\n * @param options Configuration options\n * @param options.copiedDuration Duration in milliseconds to show the copied state\n * @returns A copy callback function, or null if copying is disabled\n *\n * @example\n * ```tsx\n * function CustomCopyButton() {\n * const copy = useActionBarPrimitiveCopy({ copiedDuration: 2000 });\n *\n * return (\n * <button onClick={copy} disabled={!copy}>\n * {copy ? \"Copy\" : \"Cannot Copy\"}\n * </button>\n * );\n * }\n * ```\n */\nconst useActionBarPrimitiveCopy = ({\n copiedDuration = 3000,\n}: {\n copiedDuration?: number | undefined;\n} = {}) => {\n const { copy, disabled } = useActionBarCopy({\n copiedDuration,\n copyToClipboard: (text) => {\n if (typeof navigator === \"undefined\" || !navigator.clipboard) {\n return Promise.reject(new Error(\"Clipboard API is unavailable\"));\n }\n return navigator.clipboard.writeText(text);\n },\n });\n if (disabled) return null;\n return copy;\n};\n\nexport namespace ActionBarPrimitiveCopy {\n export type Element = HTMLButtonElement;\n /**\n * Props for the ActionBarPrimitive.Copy component.\n * Inherits all button element props and action button functionality.\n */\n export type Props = ActionButtonProps<typeof useActionBarPrimitiveCopy>;\n}\n\n/**\n * A button component that copies message content to the clipboard.\n *\n * This component automatically handles copying message text to the clipboard\n * and provides visual feedback through the data-copied attribute. It's disabled\n * when there's no copyable content available.\n *\n * @example\n * ```tsx\n * <ActionBarPrimitive.Copy copiedDuration={2000}>\n * Copy Message\n * </ActionBarPrimitive.Copy>\n * ```\n */\nexport const ActionBarPrimitiveCopy = forwardRef<\n ActionBarPrimitiveCopy.Element,\n ActionBarPrimitiveCopy.Props\n>(({ copiedDuration, onClick, disabled, ...props }, forwardedRef) => {\n const isCopied = useAuiState((s) => s.message.isCopied);\n const callback = useActionBarPrimitiveCopy({ copiedDuration });\n return (\n <Primitive.button\n type=\"button\"\n {...(isCopied ? { \"data-copied\": \"true\" } : {})}\n {...props}\n ref={forwardedRef}\n disabled={disabled || !callback}\n onClick={composeEventHandlers(onClick, () => {\n callback?.();\n })}\n />\n );\n});\n\nActionBarPrimitiveCopy.displayName = \"ActionBarPrimitive.Copy\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAMQ,6BAA4BC,OAAA;CAAA,MAAAC,IAAAT,EAAA,CAAA;CAAA,IAAAU;CAAA,IAAAD,EAAA,OAAAD,IAAA;EAACE,KAAAF,OAAAG,KAAAA,IAAA,CAI9B,IAJ8BH;EAI7BC,EAAA,KAAAD;EAAAC,EAAA,KAAAC;CAAA,OAAAA,KAAAD,EAAA;CAJ6B,MAAA,EAAAG,gBAAAC,OAAAH;CACjC,MAAAE,iBAAAC,OAAAF,KAAAA,IAAA,MAAAE;CAAqB,IAAAC;CAAA,IAAAL,EAAA,OAAAG,gBAAA;EAIuBE,KAAA;GAAAF;GAAAG,iBAEzBC;EAMnB;EAACP,EAAA,KAAAG;EAAAH,EAAA,KAAAK;CAAA,OAAAA,KAAAL,EAAA;CARD,MAAA,EAAAQ,MAAAC,aAA2Bb,iBAAiBS,EAQ3C;CACD,IAAII,UAAQ,OAAS;CAAK,OACnBD;AAAI;;;;;;;;;;;;;;;AA0Bb,MAAaE,yBAAyBlB,YAGpCO,IAAAe,iBAAA;CAAA,MAAAd,IAAAT,EAAA,EAAA;CAAA,IAAAY;CAAA,IAAAM;CAAA,IAAAM;CAAA,IAAAC;CAAA,IAAAhB,EAAA,OAAAD,IAAA;EAAC,CAAA,CAAAI,gBAAAY,SAAAN,UAAA,GAAAO,SAAAjB;EAA+CC,EAAA,KAAAD;EAAAC,EAAA,KAAAG;EAAAH,EAAA,KAAAS;EAAAT,EAAA,KAAAe;EAAAf,EAAA,KAAAgB;CAAA,OAAA;EAAAb,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AArB,EAAA,MAAAsB;CAAA,OAAAA,KAAAtB,EAAA;CAAA,OATFsB;AASE,CAEL;AAEDZ,uBAAuBa,cAAc;AA7DH,SAAAhB,MAAAiB,MAAA;CAQ5B,IAAI,OAAOC,cAAc,eAArB,CAAqCA,UAASC,WAAU,OACnDC,QAAOC,uBAAQ,IAAIC,MAAM,8BAA8B,CAAC;CAChE,OACMJ,UAASC,UAAUI,UAAWN,IAAI;AAAC;AAiC9C,SAAAN,OAAAa,GAAA;CAAA,OACoCA,EAACC,QAAQf;AAAS"}
@@ -1,10 +1,10 @@
1
1
  "use client";
2
- import { Primitive } from "../../utils/Primitive.js";
2
+ import { Primitive as Primitive$1 } from "../../utils/Primitive.js";
3
3
  import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
4
4
  import { useAui, useAuiState } from "@assistant-ui/store";
5
5
  import { forwardRef } from "@assistant-ui/tap/react-shim";
6
6
  import { jsx } from "react/jsx-runtime";
7
- import { composeEventHandlers } from "@radix-ui/primitive";
7
+ import { composeEventHandlers } from "radix-ui/internal";
8
8
  //#region src/primitives/actionBar/ActionBarExportMarkdown.tsx
9
9
  const useActionBarExportMarkdown = (t0) => {
10
10
  const $ = c(6);
@@ -94,7 +94,7 @@ const ActionBarPrimitiveExportMarkdown = forwardRef((t0, forwardedRef) => {
94
94
  } else t4 = $[13];
95
95
  let t5;
96
96
  if ($[14] !== forwardedRef || $[15] !== props || $[16] !== t2 || $[17] !== t4) {
97
- t5 = /* @__PURE__ */ jsx(Primitive.button, {
97
+ t5 = /* @__PURE__ */ jsx(Primitive$1.button, {
98
98
  type: "button",
99
99
  ...props,
100
100
  ref: forwardedRef,