@assistant-ui/react 0.14.29 → 0.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/ExternalThread.js +4 -3
- package/dist/client/ExternalThread.js.map +1 -1
- package/dist/client/InMemoryThreadList.js +3 -3
- package/dist/client/InMemoryThreadList.js.map +1 -1
- package/dist/context/index.d.ts +1 -8
- package/dist/context/index.js +1 -8
- package/dist/hooks/useToolCallElapsed.js +24 -29
- package/dist/hooks/useToolCallElapsed.js.map +1 -1
- package/dist/index.d.ts +1 -8
- package/dist/index.js +1 -8
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js +3 -3
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js.map +1 -1
- package/dist/mcp-apps/McpAppRenderer.js +1 -1
- package/dist/mcp-apps/McpAppRenderer.js.map +1 -1
- package/dist/model-context/makeAssistantVisible.js +26 -25
- package/dist/model-context/makeAssistantVisible.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarExportMarkdown.js +3 -3
- package/dist/primitives/actionBar/ActionBarExportMarkdown.js.map +1 -1
- package/dist/primitives/attachment/AttachmentRemove.js +3 -3
- package/dist/primitives/attachment/AttachmentRemove.js.map +1 -1
- package/dist/primitives/chainOfThought/ChainOfThoughtAccordionTrigger.js +3 -3
- package/dist/primitives/chainOfThought/ChainOfThoughtAccordionTrigger.js.map +1 -1
- package/dist/primitives/composer/ComposerAddAttachment.js +3 -3
- package/dist/primitives/composer/ComposerAddAttachment.js.map +1 -1
- package/dist/primitives/composer/ComposerAttachmentDropzone.js +1 -1
- package/dist/primitives/composer/ComposerAttachmentDropzone.js.map +1 -1
- package/dist/primitives/composer/ComposerInput.js +13 -13
- package/dist/primitives/composer/ComposerInput.js.map +1 -1
- package/dist/primitives/composer/ComposerQuote.js +1 -1
- package/dist/primitives/composer/ComposerQuote.js.map +1 -1
- package/dist/primitives/composer/ComposerStopDictation.js +3 -3
- package/dist/primitives/composer/ComposerStopDictation.js.map +1 -1
- package/dist/primitives/composer/trigger/triggerSelectionResource.d.ts.map +1 -1
- package/dist/primitives/composer/trigger/triggerSelectionResource.js +3 -3
- package/dist/primitives/composer/trigger/triggerSelectionResource.js.map +1 -1
- package/dist/primitives/message/MessagePartsGrouped.d.ts.map +1 -1
- package/dist/primitives/message/MessagePartsGrouped.js +67 -89
- package/dist/primitives/message/MessagePartsGrouped.js.map +1 -1
- package/dist/primitives/message/MessageRoot.js +3 -3
- package/dist/primitives/message/MessageRoot.js.map +1 -1
- package/dist/primitives/queueItem/QueueItemRemove.js +3 -3
- package/dist/primitives/queueItem/QueueItemRemove.js.map +1 -1
- package/dist/primitives/queueItem/QueueItemSteer.js +3 -3
- package/dist/primitives/queueItem/QueueItemSteer.js.map +1 -1
- package/dist/primitives/selectionToolbar/SelectionToolbarQuote.js +1 -1
- package/dist/primitives/selectionToolbar/SelectionToolbarQuote.js.map +1 -1
- package/dist/primitives/suggestion/SuggestionTrigger.js +16 -15
- package/dist/primitives/suggestion/SuggestionTrigger.js.map +1 -1
- package/dist/unstable/useComposerInput.js +2 -2
- package/dist/unstable/useComposerInput.js.map +1 -1
- package/dist/unstable/useComposerInputHistory.js +6 -6
- package/dist/unstable/useComposerInputHistory.js.map +1 -1
- package/dist/unstable/useMentionAdapter.js +1 -1
- package/dist/unstable/useMentionAdapter.js.map +1 -1
- package/dist/utils/smooth/SmoothContext.js +3 -3
- package/dist/utils/smooth/SmoothContext.js.map +1 -1
- package/dist/utils/smooth/useSmooth.js +1 -1
- package/dist/utils/smooth/useSmooth.js.map +1 -1
- package/dist/utils/useToolArgsFieldStatus.d.ts +2 -2
- package/package.json +5 -5
- package/src/client/ExternalThread.ts +5 -3
- package/src/client/InMemoryThreadList.ts +3 -3
- package/src/context/index.ts +0 -44
- package/src/hooks/useToolCallElapsed.ts +9 -12
- package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.test.tsx +5 -9
- package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.ts +1 -1
- package/src/mcp-apps/McpAppRenderer.tsx +1 -1
- package/src/model-context/makeAssistantVisible.test.tsx +1 -1
- package/src/model-context/makeAssistantVisible.tsx +1 -1
- package/src/primitives/actionBar/ActionBarExportMarkdown.tsx +1 -1
- package/src/primitives/attachment/AttachmentRemove.ts +1 -1
- package/src/primitives/chainOfThought/ChainOfThoughtAccordionTrigger.ts +1 -1
- package/src/primitives/composer/ComposerAddAttachment.test.tsx +2 -2
- package/src/primitives/composer/ComposerAddAttachment.ts +1 -1
- package/src/primitives/composer/ComposerAttachmentDropzone.test.tsx +2 -2
- package/src/primitives/composer/ComposerAttachmentDropzone.tsx +1 -1
- package/src/primitives/composer/ComposerInput.test.tsx +7 -7
- package/src/primitives/composer/ComposerInput.tsx +13 -13
- package/src/primitives/composer/ComposerQuote.tsx +1 -1
- package/src/primitives/composer/ComposerStopDictation.ts +1 -1
- package/src/primitives/composer/trigger/triggerSelectionResource.ts +7 -9
- package/src/primitives/message/MessagePartsGrouped.tsx +6 -8
- package/src/primitives/message/MessageRoot.tsx +1 -1
- package/src/primitives/queueItem/QueueItemRemove.ts +1 -1
- package/src/primitives/queueItem/QueueItemSteer.ts +1 -1
- package/src/primitives/selectionToolbar/SelectionToolbarQuote.tsx +1 -1
- package/src/primitives/suggestion/SuggestionTrigger.ts +9 -9
- package/src/tests/DataRenderers.test.tsx +1 -1
- package/src/tests/RemoteThreadListRuntime.deferredProvider.test.tsx +3 -3
- package/src/tests/external-thread-attachments.test.tsx +21 -23
- package/src/tests/external-thread-branches.test.tsx +10 -10
- package/src/tests/external-thread-parity.test.tsx +18 -20
- package/src/tests/local-runtime-queue.test.tsx +29 -34
- package/src/tests/messagePartSwitchRace.test.tsx +30 -13
- package/src/unstable/useComposerInput.test.tsx +2 -2
- package/src/unstable/useComposerInput.ts +2 -2
- package/src/unstable/useComposerInputHistory.test.tsx +3 -3
- package/src/unstable/useComposerInputHistory.ts +6 -6
- package/src/unstable/useMentionAdapter.ts +1 -1
- package/src/utils/smooth/SmoothContext.tsx +1 -1
- package/src/utils/smooth/useSmooth.test.tsx +1 -1
- package/src/utils/smooth/useSmooth.ts +1 -1
- package/dist/context/react/utils/createStateHookForRuntime.d.ts +0 -34
- package/dist/context/react/utils/createStateHookForRuntime.d.ts.map +0 -1
- package/dist/context/react/utils/createStateHookForRuntime.js +0 -21
- package/dist/context/react/utils/createStateHookForRuntime.js.map +0 -1
- package/dist/legacy-runtime/hooks/AssistantContext.d.ts +0 -74
- package/dist/legacy-runtime/hooks/AssistantContext.d.ts.map +0 -1
- package/dist/legacy-runtime/hooks/AssistantContext.js +0 -29
- package/dist/legacy-runtime/hooks/AssistantContext.js.map +0 -1
- package/dist/legacy-runtime/hooks/AttachmentContext.d.ts +0 -1007
- package/dist/legacy-runtime/hooks/AttachmentContext.d.ts.map +0 -1
- package/dist/legacy-runtime/hooks/AttachmentContext.js +0 -47
- package/dist/legacy-runtime/hooks/AttachmentContext.js.map +0 -1
- package/dist/legacy-runtime/hooks/ComposerContext.d.ts +0 -141
- package/dist/legacy-runtime/hooks/ComposerContext.d.ts.map +0 -1
- package/dist/legacy-runtime/hooks/ComposerContext.js +0 -65
- package/dist/legacy-runtime/hooks/ComposerContext.js.map +0 -1
- package/dist/legacy-runtime/hooks/MessageContext.d.ts +0 -155
- package/dist/legacy-runtime/hooks/MessageContext.d.ts.map +0 -1
- package/dist/legacy-runtime/hooks/MessageContext.js +0 -68
- package/dist/legacy-runtime/hooks/MessageContext.js.map +0 -1
- package/dist/legacy-runtime/hooks/MessagePartContext.d.ts +0 -44
- package/dist/legacy-runtime/hooks/MessagePartContext.d.ts.map +0 -1
- package/dist/legacy-runtime/hooks/MessagePartContext.js +0 -26
- package/dist/legacy-runtime/hooks/MessagePartContext.js.map +0 -1
- package/dist/legacy-runtime/hooks/ThreadContext.d.ts +0 -139
- package/dist/legacy-runtime/hooks/ThreadContext.d.ts.map +0 -1
- package/dist/legacy-runtime/hooks/ThreadContext.js +0 -84
- package/dist/legacy-runtime/hooks/ThreadContext.js.map +0 -1
- package/dist/legacy-runtime/hooks/ThreadListItemContext.d.ts +0 -44
- package/dist/legacy-runtime/hooks/ThreadListItemContext.d.ts.map +0 -1
- package/dist/legacy-runtime/hooks/ThreadListItemContext.js +0 -26
- package/dist/legacy-runtime/hooks/ThreadListItemContext.js.map +0 -1
- package/src/context/react/utils/createStateHookForRuntime.ts +0 -82
- package/src/legacy-runtime/hooks/AssistantContext.ts +0 -67
- package/src/legacy-runtime/hooks/AttachmentContext.ts +0 -99
- package/src/legacy-runtime/hooks/ComposerContext.ts +0 -131
- package/src/legacy-runtime/hooks/MessageContext.ts +0 -127
- package/src/legacy-runtime/hooks/MessagePartContext.ts +0 -32
- package/src/legacy-runtime/hooks/ThreadContext.ts +0 -120
- package/src/legacy-runtime/hooks/ThreadListItemContext.ts +0 -36
|
@@ -72,21 +72,17 @@ const ToolUIDisplay = (t0) => {
|
|
|
72
72
|
}
|
|
73
73
|
let t1;
|
|
74
74
|
if ($[3] !== Fallback || $[4] !== props.toolName) {
|
|
75
|
-
t1 = (s) =>
|
|
76
|
-
const Render = s.tools.tools[props.toolName] ?? Fallback;
|
|
77
|
-
if (Array.isArray(Render)) return Render[0] ?? Fallback;
|
|
78
|
-
return Render;
|
|
79
|
-
};
|
|
75
|
+
t1 = (s) => s.tools.toolUIs[props.toolName]?.[0]?.render ?? Fallback;
|
|
80
76
|
$[3] = Fallback;
|
|
81
77
|
$[4] = props.toolName;
|
|
82
78
|
$[5] = t1;
|
|
83
79
|
} else t1 = $[5];
|
|
84
|
-
const
|
|
85
|
-
if (!
|
|
80
|
+
const Render = useAuiState(t1);
|
|
81
|
+
if (!Render) return null;
|
|
86
82
|
let t2;
|
|
87
|
-
if ($[6] !==
|
|
88
|
-
t2 = /* @__PURE__ */ jsx(
|
|
89
|
-
$[6] =
|
|
83
|
+
if ($[6] !== Render || $[7] !== props) {
|
|
84
|
+
t2 = /* @__PURE__ */ jsx(Render, { ...props });
|
|
85
|
+
$[6] = Render;
|
|
90
86
|
$[7] = props;
|
|
91
87
|
$[8] = t2;
|
|
92
88
|
} else t2 = $[8];
|
|
@@ -143,7 +139,7 @@ const defaultComponents = {
|
|
|
143
139
|
Group: ({ children }) => children
|
|
144
140
|
};
|
|
145
141
|
const MessagePartComponent = (t0) => {
|
|
146
|
-
const $ = c(
|
|
142
|
+
const $ = c(37);
|
|
147
143
|
const { components: t1 } = t0;
|
|
148
144
|
let t2;
|
|
149
145
|
if ($[0] !== t1) {
|
|
@@ -169,138 +165,120 @@ const MessagePartComponent = (t0) => {
|
|
|
169
165
|
const part = useAuiState(_temp2);
|
|
170
166
|
const type = part.type;
|
|
171
167
|
if (type === "tool-call") {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
$[4] = aui;
|
|
176
|
-
$[5] = t11;
|
|
177
|
-
} else t11 = $[5];
|
|
178
|
-
const addResult = t11.addToolResult;
|
|
179
|
-
let t12;
|
|
180
|
-
if ($[6] !== aui) {
|
|
181
|
-
t12 = aui.part();
|
|
182
|
-
$[6] = aui;
|
|
183
|
-
$[7] = t12;
|
|
184
|
-
} else t12 = $[7];
|
|
185
|
-
const resume = t12.resumeToolCall;
|
|
186
|
-
let t13;
|
|
187
|
-
if ($[8] !== aui) {
|
|
188
|
-
t13 = aui.part();
|
|
189
|
-
$[8] = aui;
|
|
190
|
-
$[9] = t13;
|
|
191
|
-
} else t13 = $[9];
|
|
192
|
-
const respondToApproval = t13.respondToToolApproval;
|
|
168
|
+
const addResult = aui.part.addToolResult;
|
|
169
|
+
const resume = aui.part.resumeToolCall;
|
|
170
|
+
const respondToApproval = aui.part.respondToToolApproval;
|
|
193
171
|
if ("Override" in tools) {
|
|
194
|
-
let
|
|
195
|
-
if ($[
|
|
196
|
-
|
|
172
|
+
let t11;
|
|
173
|
+
if ($[4] !== addResult || $[5] !== part || $[6] !== respondToApproval || $[7] !== resume || $[8] !== tools.Override) {
|
|
174
|
+
t11 = /* @__PURE__ */ jsx(tools.Override, {
|
|
197
175
|
...part,
|
|
198
176
|
addResult,
|
|
199
177
|
resume,
|
|
200
178
|
respondToApproval
|
|
201
179
|
});
|
|
202
|
-
$[
|
|
203
|
-
$[
|
|
204
|
-
$[
|
|
205
|
-
$[
|
|
206
|
-
$[
|
|
207
|
-
$[
|
|
208
|
-
} else
|
|
209
|
-
return
|
|
180
|
+
$[4] = addResult;
|
|
181
|
+
$[5] = part;
|
|
182
|
+
$[6] = respondToApproval;
|
|
183
|
+
$[7] = resume;
|
|
184
|
+
$[8] = tools.Override;
|
|
185
|
+
$[9] = t11;
|
|
186
|
+
} else t11 = $[9];
|
|
187
|
+
return t11;
|
|
210
188
|
}
|
|
211
189
|
const Tool = tools.by_name?.[part.toolName] ?? tools.Fallback;
|
|
212
|
-
let
|
|
213
|
-
if ($[
|
|
214
|
-
|
|
190
|
+
let t11;
|
|
191
|
+
if ($[10] !== Tool || $[11] !== addResult || $[12] !== part || $[13] !== respondToApproval || $[14] !== resume) {
|
|
192
|
+
t11 = /* @__PURE__ */ jsx(ToolUIDisplay, {
|
|
215
193
|
...part,
|
|
216
194
|
Fallback: Tool,
|
|
217
195
|
addResult,
|
|
218
196
|
resume,
|
|
219
197
|
respondToApproval
|
|
220
198
|
});
|
|
221
|
-
$[
|
|
222
|
-
$[
|
|
223
|
-
$[
|
|
224
|
-
$[
|
|
225
|
-
$[
|
|
226
|
-
$[
|
|
227
|
-
} else
|
|
228
|
-
return
|
|
199
|
+
$[10] = Tool;
|
|
200
|
+
$[11] = addResult;
|
|
201
|
+
$[12] = part;
|
|
202
|
+
$[13] = respondToApproval;
|
|
203
|
+
$[14] = resume;
|
|
204
|
+
$[15] = t11;
|
|
205
|
+
} else t11 = $[15];
|
|
206
|
+
return t11;
|
|
229
207
|
}
|
|
230
208
|
if (part.status?.type === "requires-action") throw new Error("Encountered unexpected requires-action status");
|
|
231
209
|
switch (type) {
|
|
232
210
|
case "text": {
|
|
233
211
|
let t11;
|
|
234
|
-
if ($[
|
|
212
|
+
if ($[16] !== Text || $[17] !== part) {
|
|
235
213
|
t11 = /* @__PURE__ */ jsx(Text, { ...part });
|
|
236
|
-
$[
|
|
237
|
-
$[
|
|
238
|
-
$[
|
|
239
|
-
} else t11 = $[
|
|
214
|
+
$[16] = Text;
|
|
215
|
+
$[17] = part;
|
|
216
|
+
$[18] = t11;
|
|
217
|
+
} else t11 = $[18];
|
|
240
218
|
return t11;
|
|
241
219
|
}
|
|
242
220
|
case "reasoning": {
|
|
243
221
|
let t11;
|
|
244
|
-
if ($[
|
|
222
|
+
if ($[19] !== Reasoning || $[20] !== part) {
|
|
245
223
|
t11 = /* @__PURE__ */ jsx(Reasoning, { ...part });
|
|
246
|
-
$[
|
|
247
|
-
$[
|
|
248
|
-
$[
|
|
249
|
-
} else t11 = $[
|
|
224
|
+
$[19] = Reasoning;
|
|
225
|
+
$[20] = part;
|
|
226
|
+
$[21] = t11;
|
|
227
|
+
} else t11 = $[21];
|
|
250
228
|
return t11;
|
|
251
229
|
}
|
|
252
230
|
case "source": {
|
|
253
231
|
let t11;
|
|
254
|
-
if ($[
|
|
232
|
+
if ($[22] !== Source || $[23] !== part) {
|
|
255
233
|
t11 = /* @__PURE__ */ jsx(Source, { ...part });
|
|
256
|
-
$[
|
|
257
|
-
$[
|
|
258
|
-
$[
|
|
259
|
-
} else t11 = $[
|
|
234
|
+
$[22] = Source;
|
|
235
|
+
$[23] = part;
|
|
236
|
+
$[24] = t11;
|
|
237
|
+
} else t11 = $[24];
|
|
260
238
|
return t11;
|
|
261
239
|
}
|
|
262
240
|
case "image": {
|
|
263
241
|
let t11;
|
|
264
|
-
if ($[
|
|
242
|
+
if ($[25] !== Image || $[26] !== part) {
|
|
265
243
|
t11 = /* @__PURE__ */ jsx(Image, { ...part });
|
|
266
|
-
$[
|
|
267
|
-
$[
|
|
268
|
-
$[
|
|
269
|
-
} else t11 = $[
|
|
244
|
+
$[25] = Image;
|
|
245
|
+
$[26] = part;
|
|
246
|
+
$[27] = t11;
|
|
247
|
+
} else t11 = $[27];
|
|
270
248
|
return t11;
|
|
271
249
|
}
|
|
272
250
|
case "file": {
|
|
273
251
|
let t11;
|
|
274
|
-
if ($[
|
|
252
|
+
if ($[28] !== File || $[29] !== part) {
|
|
275
253
|
t11 = /* @__PURE__ */ jsx(File, { ...part });
|
|
276
|
-
$[
|
|
277
|
-
$[
|
|
278
|
-
$[
|
|
279
|
-
} else t11 = $[
|
|
254
|
+
$[28] = File;
|
|
255
|
+
$[29] = part;
|
|
256
|
+
$[30] = t11;
|
|
257
|
+
} else t11 = $[30];
|
|
280
258
|
return t11;
|
|
281
259
|
}
|
|
282
260
|
case "audio": {
|
|
283
261
|
let t11;
|
|
284
|
-
if ($[
|
|
262
|
+
if ($[31] !== Audio || $[32] !== part) {
|
|
285
263
|
t11 = /* @__PURE__ */ jsx(Audio, { ...part });
|
|
286
|
-
$[
|
|
287
|
-
$[
|
|
288
|
-
$[
|
|
289
|
-
} else t11 = $[
|
|
264
|
+
$[31] = Audio;
|
|
265
|
+
$[32] = part;
|
|
266
|
+
$[33] = t11;
|
|
267
|
+
} else t11 = $[33];
|
|
290
268
|
return t11;
|
|
291
269
|
}
|
|
292
270
|
case "data": {
|
|
293
271
|
const Data = data?.by_name?.[part.name] ?? data?.Fallback;
|
|
294
272
|
let t11;
|
|
295
|
-
if ($[
|
|
273
|
+
if ($[34] !== Data || $[35] !== part) {
|
|
296
274
|
t11 = /* @__PURE__ */ jsx(DataUIDisplay, {
|
|
297
275
|
...part,
|
|
298
276
|
Fallback: Data
|
|
299
277
|
});
|
|
300
|
-
$[
|
|
301
|
-
$[
|
|
302
|
-
$[
|
|
303
|
-
} else t11 = $[
|
|
278
|
+
$[34] = Data;
|
|
279
|
+
$[35] = part;
|
|
280
|
+
$[36] = t11;
|
|
281
|
+
} else t11 = $[36];
|
|
304
282
|
return t11;
|
|
305
283
|
}
|
|
306
284
|
default:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessagePartsGrouped.js","names":["c","_c","ComponentType","FC","memo","PropsWithChildren","useMemo","useAuiState","useAui","PartByIndexProvider","TextMessagePartProvider","MessagePartPrimitiveText","MessagePartPrimitiveImage","Unstable_AudioMessagePartComponent","DataMessagePartComponent","DataMessagePartProps","EmptyMessagePartComponent","TextMessagePartComponent","ImageMessagePartComponent","SourceMessagePartComponent","ToolCallMessagePartComponent","ToolCallMessagePartProps","FileMessagePartComponent","ReasoningMessagePartComponent","MessagePartPrimitiveInProgress","MessagePartStatus","MessagePartGroup","groupKey","indices","GroupingFunction","parts","groupMessagePartsByParentId","groupMap","Map","i","length","part","parentId","groupId","get","push","set","groups","startsWith","undefined","useMessagePartsGrouped","groupingFunction","$","_temp","t0","bb0","t1","Symbol","for","MessagePrimitiveUnstable_PartsGrouped","Props","components","Empty","Text","Reasoning","Source","Image","File","Unstable_Audio","data","by_name","Record","Fallback","tools","Override","Group","ToolUIDisplay","props","toolName","s","Render","Array","isArray","Render_0","t2","DataUIDisplay","name","dataRenderers","renderers","defaultComponents","whiteSpace","fontFamily","children","MessagePartComponentProps","MessagePartComponent","t3","t4","t5","t6","t7","t8","t9","Audio","t10","aui","_temp2","type","t11","addResult","addToolResult","t12","resume","resumeToolCall","t13","respondToApproval","respondToToolApproval","t14","Tool","status","Error","Data","console","warn","MessagePartProps","partIndex","MessagePartImpl","MessagePart","prev","next","EmptyPartFallback","component","Component","COMPLETE_STATUS","Object","freeze","EmptyPartsImpl","_temp3","EmptyParts","contentLength","_temp4","messageGroups","group","groupIndex","GroupComponent","map","partsElements","displayName","MessagePrimitiveUnstable_PartsGroupedByParentId","Omit","message"],"sources":["../../../src/primitives/message/MessagePartsGrouped.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type ComponentType,\n type FC,\n memo,\n type PropsWithChildren,\n useMemo,\n} from \"react\";\nimport { useAuiState, useAui } from \"@assistant-ui/store\";\nimport { PartByIndexProvider } from \"../../context/providers/PartByIndexProvider\";\nimport { TextMessagePartProvider } from \"../../context/providers/TextMessagePartProvider\";\nimport { MessagePartPrimitiveText } from \"../messagePart/MessagePartText\";\nimport { MessagePartPrimitiveImage } from \"../messagePart/MessagePartImage\";\nimport type {\n Unstable_AudioMessagePartComponent,\n DataMessagePartComponent,\n DataMessagePartProps,\n EmptyMessagePartComponent,\n TextMessagePartComponent,\n ImageMessagePartComponent,\n SourceMessagePartComponent,\n ToolCallMessagePartComponent,\n ToolCallMessagePartProps,\n FileMessagePartComponent,\n ReasoningMessagePartComponent,\n} from \"@assistant-ui/core/react\";\nimport { MessagePartPrimitiveInProgress } from \"../messagePart/MessagePartInProgress\";\nimport type { MessagePartStatus } from \"@assistant-ui/core\";\n\ntype MessagePartGroup = {\n groupKey: string | undefined;\n indices: number[];\n};\n\nexport type GroupingFunction = (parts: readonly any[]) => MessagePartGroup[];\n\n/**\n * Groups message parts by their parent ID.\n * Parts without a parent ID appear in their chronological position as individual groups.\n * Parts with the same parent ID are grouped together at the position of their first occurrence.\n */\nconst groupMessagePartsByParentId: GroupingFunction = (\n parts: readonly any[],\n): MessagePartGroup[] => {\n // Map maintains insertion order, so groups appear in order of first occurrence\n const groupMap = new Map<string, number[]>();\n\n // Process each part in order\n for (let i = 0; i < parts.length; i++) {\n const part = parts[i];\n const parentId = part?.parentId as string | undefined;\n\n // For parts without parentId, assign a unique group ID to maintain their position\n const groupId = parentId ?? `__ungrouped_${i}`;\n\n // Get or create the indices array for this group\n const indices = groupMap.get(groupId) ?? [];\n indices.push(i);\n groupMap.set(groupId, indices);\n }\n\n // Convert map to array of groups\n const groups: MessagePartGroup[] = [];\n for (const [groupId, indices] of groupMap) {\n // Extract parentId (undefined for ungrouped parts)\n const groupKey = groupId.startsWith(\"__ungrouped_\") ? undefined : groupId;\n groups.push({ groupKey, indices });\n }\n\n return groups;\n};\n\nconst useMessagePartsGrouped = (\n groupingFunction: GroupingFunction,\n): MessagePartGroup[] => {\n const parts = useAuiState((s) => s.message.parts);\n\n return useMemo(() => {\n if (parts.length === 0) {\n return [];\n }\n return groupingFunction(parts);\n }, [parts, groupingFunction]);\n};\n\nexport namespace MessagePrimitiveUnstable_PartsGrouped {\n export type Props = {\n /**\n * Function that takes an array of message parts and returns an array of groups.\n * Each group contains a key (for identification) and an array of indices.\n *\n * @example\n * ```tsx\n * // Group by parent ID (default behavior)\n * groupingFunction={(parts) => {\n * const groups = new Map<string, number[]>();\n * parts.forEach((part, i) => {\n * const key = part.parentId ?? `__ungrouped_${i}`;\n * const indices = groups.get(key) ?? [];\n * indices.push(i);\n * groups.set(key, indices);\n * });\n * return Array.from(groups.entries()).map(([key, indices]) => ({\n * key: key.startsWith(\"__ungrouped_\") ? undefined : key,\n * indices\n * }));\n * }}\n * ```\n *\n * @example\n * ```tsx\n * // Group by tool name\n * import { groupMessagePartsByToolName } from \"@assistant-ui/react\";\n *\n * <MessagePrimitive.Unstable_PartsGrouped\n * groupingFunction={groupMessagePartsByToolName}\n * components={{\n * Group: ({ key, indices, children }) => {\n * if (!key) return <>{children}</>;\n * return (\n * <div className=\"tool-group\">\n * <h4>Tool: {key}</h4>\n * {children}\n * </div>\n * );\n * }\n * }}\n * />\n * ```\n */\n groupingFunction: GroupingFunction;\n\n /**\n * Component configuration for rendering different types of message content.\n *\n * You can provide custom components for each content type (text, image, file, etc.)\n * and configure tool rendering behavior. If not provided, default components will be used.\n */\n components:\n | {\n /** Component for rendering empty messages */\n Empty?: EmptyMessagePartComponent | undefined;\n /** Component for rendering text content */\n Text?: TextMessagePartComponent | undefined;\n /** Component for rendering reasoning content (typically hidden) */\n Reasoning?: ReasoningMessagePartComponent | undefined;\n /** Component for rendering source content */\n Source?: SourceMessagePartComponent | undefined;\n /** Component for rendering image content */\n Image?: ImageMessagePartComponent | undefined;\n /** Component for rendering file content */\n File?: FileMessagePartComponent | undefined;\n /** Component for rendering audio content (experimental) */\n Unstable_Audio?: Unstable_AudioMessagePartComponent | undefined;\n /** Configuration for data part rendering */\n data?:\n | {\n /** Map data event names to specific components */\n by_name?:\n | Record<string, DataMessagePartComponent | undefined>\n | undefined;\n /** Fallback component for unmatched data events */\n Fallback?: DataMessagePartComponent | undefined;\n }\n | undefined;\n /** Configuration for tool call rendering */\n tools?:\n | {\n /** Map of tool names to their specific components */\n by_name?:\n | Record<string, ToolCallMessagePartComponent | undefined>\n | undefined;\n /** Fallback component for unregistered tools */\n Fallback?: ComponentType<ToolCallMessagePartProps> | undefined;\n }\n | {\n /** Override component that handles all tool calls */\n Override: ComponentType<ToolCallMessagePartProps>;\n }\n | undefined;\n\n /**\n * Component for rendering grouped message parts.\n *\n * When provided, this component will automatically wrap message parts that share\n * the same group key as determined by the groupingFunction.\n *\n * The component receives:\n * - `groupKey`: The group key (or undefined for ungrouped parts)\n * - `indices`: Array of indices for the parts in this group\n * - `children`: The rendered message part components\n *\n * @example\n * ```tsx\n * // Collapsible group\n * Group: ({ groupKey, indices, children }) => {\n * if (!groupKey) return <>{children}</>;\n * return (\n * <details className=\"message-group\">\n * <summary>\n * Group {groupKey} ({indices.length} parts)\n * </summary>\n * <div className=\"group-content\">\n * {children}\n * </div>\n * </details>\n * );\n * }\n * ```\n *\n * @param groupKey - The group key (undefined for ungrouped parts)\n * @param indices - Array of indices for the parts in this group\n * @param children - Rendered message part components to display within the group\n */\n Group?: ComponentType<\n PropsWithChildren<{\n groupKey: string | undefined;\n indices: number[];\n }>\n >;\n }\n | undefined;\n };\n}\n\nconst ToolUIDisplay = ({\n Fallback,\n ...props\n}: {\n Fallback: ToolCallMessagePartComponent | undefined;\n} & ToolCallMessagePartProps) => {\n const Render = useAuiState((s) => {\n const Render = s.tools.tools[props.toolName] ?? Fallback;\n if (Array.isArray(Render)) return Render[0] ?? Fallback;\n return Render;\n });\n if (!Render) return null;\n return <Render {...props} />;\n};\n\nconst DataUIDisplay = ({\n Fallback,\n ...props\n}: {\n Fallback: DataMessagePartComponent | undefined;\n} & DataMessagePartProps) => {\n const Render = useAuiState((s) => {\n const Render = s.dataRenderers.renderers[props.name] ?? Fallback;\n if (Array.isArray(Render)) return Render[0] ?? Fallback;\n return Render;\n });\n if (!Render) return null;\n return <Render {...props} />;\n};\n\nconst defaultComponents = {\n Text: () => (\n <p style={{ whiteSpace: \"pre-line\" }}>\n <MessagePartPrimitiveText />\n <MessagePartPrimitiveInProgress>\n <span style={{ fontFamily: \"revert\" }}>{\" \\u25CF\"}</span>\n </MessagePartPrimitiveInProgress>\n </p>\n ),\n Reasoning: () => null,\n Source: () => null,\n Image: () => <MessagePartPrimitiveImage />,\n File: () => null,\n Unstable_Audio: () => null,\n Group: ({ children }) => children,\n} satisfies MessagePrimitiveUnstable_PartsGrouped.Props[\"components\"];\n\ntype MessagePartComponentProps = {\n components: MessagePrimitiveUnstable_PartsGrouped.Props[\"components\"];\n};\n\nconst MessagePartComponent: FC<MessagePartComponentProps> = ({\n components: {\n Text = defaultComponents.Text,\n Reasoning = defaultComponents.Reasoning,\n Image = defaultComponents.Image,\n Source = defaultComponents.Source,\n File = defaultComponents.File,\n Unstable_Audio: Audio = defaultComponents.Unstable_Audio,\n tools = {},\n data,\n } = {},\n}) => {\n const aui = useAui();\n const part = useAuiState((s) => s.part);\n\n const type = part.type;\n if (type === \"tool-call\") {\n const addResult = aui.part().addToolResult;\n const resume = aui.part().resumeToolCall;\n const respondToApproval = aui.part().respondToToolApproval;\n if (\"Override\" in tools)\n return (\n <tools.Override\n {...part}\n addResult={addResult}\n resume={resume}\n respondToApproval={respondToApproval}\n />\n );\n const Tool = tools.by_name?.[part.toolName] ?? tools.Fallback;\n return (\n <ToolUIDisplay\n {...part}\n Fallback={Tool}\n addResult={addResult}\n resume={resume}\n respondToApproval={respondToApproval}\n />\n );\n }\n\n if (part.status?.type === \"requires-action\")\n throw new Error(\"Encountered unexpected requires-action status\");\n\n switch (type) {\n case \"text\":\n return <Text {...part} />;\n\n case \"reasoning\":\n return <Reasoning {...part} />;\n\n case \"source\":\n return <Source {...part} />;\n\n case \"image\":\n return <Image {...part} />;\n\n case \"file\":\n return <File {...part} />;\n\n case \"audio\":\n return <Audio {...part} />;\n\n case \"data\": {\n const Data = data?.by_name?.[part.name] ?? data?.Fallback;\n return <DataUIDisplay {...part} Fallback={Data} />;\n }\n\n default:\n console.warn(`Unknown message part type: ${type}`);\n return null;\n }\n};\n\ntype MessagePartProps = {\n partIndex: number;\n components: MessagePrimitiveUnstable_PartsGrouped.Props[\"components\"];\n};\n\nconst MessagePartImpl: FC<MessagePartProps> = ({ partIndex, components }) => {\n return (\n <PartByIndexProvider index={partIndex}>\n <MessagePartComponent components={components} />\n </PartByIndexProvider>\n );\n};\n\nconst MessagePart = memo(\n MessagePartImpl,\n (prev, next) =>\n prev.partIndex === next.partIndex &&\n prev.components?.Text === next.components?.Text &&\n prev.components?.Reasoning === next.components?.Reasoning &&\n prev.components?.Source === next.components?.Source &&\n prev.components?.Image === next.components?.Image &&\n prev.components?.File === next.components?.File &&\n prev.components?.Unstable_Audio === next.components?.Unstable_Audio &&\n prev.components?.tools === next.components?.tools &&\n prev.components?.data === next.components?.data &&\n prev.components?.Group === next.components?.Group,\n);\n\nconst EmptyPartFallback: FC<{\n status: MessagePartStatus;\n component: TextMessagePartComponent;\n}> = ({ status, component: Component }) => {\n return (\n <TextMessagePartProvider text=\"\" isRunning={status.type === \"running\"}>\n <Component type=\"text\" text=\"\" status={status} />\n </TextMessagePartProvider>\n );\n};\n\nconst COMPLETE_STATUS: MessagePartStatus = Object.freeze({\n type: \"complete\",\n});\n\nconst EmptyPartsImpl: FC<MessagePartComponentProps> = ({ components }) => {\n const status = useAuiState(\n (s) => (s.message.status ?? COMPLETE_STATUS) as MessagePartStatus,\n );\n\n if (components?.Empty) return <components.Empty status={status} />;\n\n return (\n <EmptyPartFallback\n status={status}\n component={components?.Text ?? defaultComponents.Text}\n />\n );\n};\n\nconst EmptyParts = memo(\n EmptyPartsImpl,\n (prev, next) =>\n prev.components?.Empty === next.components?.Empty &&\n prev.components?.Text === next.components?.Text,\n);\n\n/**\n * Renders the parts of a message grouped by a custom grouping function.\n *\n * This component allows you to group message parts based on any criteria you define.\n * The grouping function receives all message parts and returns an array of groups,\n * where each group has a key and an array of part indices.\n *\n * @deprecated Prefer `<MessagePrimitive.GroupedParts>` for adjacent\n * grouping — it dispatches all rendering through one `switch (part.type)`\n * and supports nested group paths. Keep this primitive only for\n * non-adjacent clustering (e.g., gathering parts with the same parent-id\n * across the message).\n *\n * @example\n * ```tsx\n * // Group by parent ID (default behavior)\n * <MessagePrimitive.Unstable_PartsGrouped\n * components={{\n * Text: ({ text }) => <p className=\"message-text\">{text}</p>,\n * Image: ({ image }) => <img src={image} alt=\"Message image\" />,\n * Group: ({ groupKey, indices, children }) => {\n * if (!groupKey) return <>{children}</>;\n * return (\n * <div className=\"parent-group border rounded p-4\">\n * <h4>Parent ID: {groupKey}</h4>\n * {children}\n * </div>\n * );\n * }\n * }}\n * />\n * ```\n */\nexport const MessagePrimitiveUnstable_PartsGrouped: FC<\n MessagePrimitiveUnstable_PartsGrouped.Props\n> = ({ groupingFunction, components }) => {\n const contentLength = useAuiState((s) => s.message.parts.length);\n const messageGroups = useMessagePartsGrouped(groupingFunction);\n\n const partsElements = useMemo(() => {\n if (contentLength === 0) {\n return <EmptyParts components={components} />;\n }\n\n return messageGroups.map((group, groupIndex) => {\n const GroupComponent = components?.Group ?? defaultComponents.Group;\n\n return (\n <GroupComponent\n key={`group-${groupIndex}-${group.groupKey ?? \"ungrouped\"}`}\n groupKey={group.groupKey}\n indices={group.indices}\n >\n {group.indices.map((partIndex) => (\n <MessagePart\n key={partIndex}\n partIndex={partIndex}\n components={components}\n />\n ))}\n </GroupComponent>\n );\n });\n }, [messageGroups, components, contentLength]);\n\n return <>{partsElements}</>;\n};\n\nMessagePrimitiveUnstable_PartsGrouped.displayName =\n \"MessagePrimitive.Unstable_PartsGrouped\";\n\n/**\n * Renders the parts of a message grouped by their parent ID.\n * This is a convenience wrapper around Unstable_PartsGrouped with parent ID grouping.\n *\n * @deprecated Use MessagePrimitive.Unstable_PartsGrouped instead for more flexibility\n */\nexport const MessagePrimitiveUnstable_PartsGroupedByParentId: FC<\n Omit<MessagePrimitiveUnstable_PartsGrouped.Props, \"groupingFunction\">\n> = ({ components, ...props }) => {\n return (\n <MessagePrimitiveUnstable_PartsGrouped\n {...props}\n components={components}\n groupingFunction={groupMessagePartsByParentId}\n />\n );\n};\n\nMessagePrimitiveUnstable_PartsGroupedByParentId.displayName =\n \"MessagePrimitive.Unstable_PartsGroupedByParentId\";\n"],"mappings":";;;;;;;;;;;;;;;;AA0CA,MAAM+B,+BACJD,UACuB;CAEvB,MAAME,2BAAW,IAAIC,IAAsB;CAG3C,KAAK,IAAIC,IAAI,GAAGA,IAAIJ,MAAMK,QAAQD,KAAK;EAKrC,MAAMI,UAJOR,MAAMI,EACE,EAAEG,YAGK,eAAeH;EAG3C,MAAMN,UAAUI,SAASO,IAAID,OAAO,KAAK,CAAA;EACzCV,QAAQY,KAAKN,CAAC;EACdF,SAASS,IAAIH,SAASV,OAAO;CAC/B;CAGA,MAAMc,SAA6B,CAAA;CACnC,KAAK,MAAM,CAACJ,SAASV,YAAYI,UAAU;EAEzC,MAAML,WAAWW,QAAQK,WAAW,cAAc,IAAIC,KAAAA,IAAYN;EAClEI,OAAOF,KAAK;GAAEb;GAAUC;EAAQ,CAAC;CACnC;CAEA,OAAOc;AACT;AAEA,MAAMG,0BAAyBC,qBAAA;CAAA,MAAAC,IAAA9C,EAAA,CAAA;CAG7B,MAAA6B,QAAcvB,YAAYyC,KAAsB;CAAE,IAAAC;CAAAC,KAAA;EAGhD,IAAIpB,MAAKK,WAAY,GAAC;GAAA,IAAAgB;GAAA,IAAAJ,EAAA,OAAAK,OAAAC,IAAA,2BAAA,GAAA;IACbF,KAAA,CAAA;IAAEJ,EAAA,KAAAI;GAAA,OAAAA,KAAAJ,EAAA;GAATE,KAAOE;GAAP,MAAAD;EAAU;EACX,IAAAC;EAAA,IAAAJ,EAAA,OAAAD,oBAAAC,EAAA,OAAAjB,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AA,IAAAgB;CAAA,IAAAzB,EAAA,OAAAE,IAAA;EAAC,CAAA,CAAAO,eAAAgB,SAAAvB;EAAwBF,EAAA,KAAAE;EAAAF,EAAA,KAAAS;EAAAT,EAAA,KAAAyB;CAAA,OAAA;EAAAhB,aAAAT,EAAA;EAAAyB,QAAAzB,EAAA;CAAA;CAAA,IAAAI;CAAA,IAAAJ,EAAA,OAAAS,cAAAT,EAAA,OAAAyB,OAAA;EAEzBrB,KAAA,oBAAC,uCAAD;GAAsC,GAChCqB;GACQhB;GACMzB,kBAAAA;EAA2B,CAAA;EAC7CgB,EAAA,KAAAS;EAAAT,EAAA,KAAAyB;EAAAzB,EAAA,KAAAI;CAAA,OAAAA,KAAAJ,EAAA;CAAA,OAJFI;AAIE;AAIN2F,gDAAgDD,cAC9C;AAjb6B,SAAA7F,MAAA0B,GAAA;CAAA,OAGIA,EAACsE,QAAQlH;AAAM;AAyMU,SAAAsE,OAAA1B,GAAA;CAAA,OAa1BA,EAACtC;AAAK;AAwGc,SAAA+F,OAAAzD,GAAA;CAAA,OAE1CA,EAACsE,QAAQ/B,UAATc;AAAyD;AAuDjE,SAAAO,OAAA5D,GAAA;CAAA,OACuCA,EAACsE,QAAQlH,MAAMK;AAAO"}
|
|
1
|
+
{"version":3,"file":"MessagePartsGrouped.js","names":["c","_c","ComponentType","FC","memo","PropsWithChildren","useMemo","useAuiState","useAui","PartByIndexProvider","TextMessagePartProvider","MessagePartPrimitiveText","MessagePartPrimitiveImage","Unstable_AudioMessagePartComponent","DataMessagePartComponent","DataMessagePartProps","EmptyMessagePartComponent","TextMessagePartComponent","ImageMessagePartComponent","SourceMessagePartComponent","ToolCallMessagePartComponent","ToolCallMessagePartProps","FileMessagePartComponent","ReasoningMessagePartComponent","MessagePartPrimitiveInProgress","MessagePartStatus","MessagePartGroup","groupKey","indices","GroupingFunction","parts","groupMessagePartsByParentId","groupMap","Map","i","length","part","parentId","groupId","get","push","set","groups","startsWith","undefined","useMessagePartsGrouped","groupingFunction","$","_temp","t0","bb0","t1","Symbol","for","MessagePrimitiveUnstable_PartsGrouped","Props","components","Empty","Text","Reasoning","Source","Image","File","Unstable_Audio","data","by_name","Record","Fallback","tools","Override","Group","ToolUIDisplay","props","toolName","s","toolUIs","render","Render","t2","DataUIDisplay","name","dataRenderers","renderers","Array","isArray","Render_0","defaultComponents","whiteSpace","fontFamily","children","MessagePartComponentProps","MessagePartComponent","t3","t4","t5","t6","t7","t8","t9","Audio","t10","aui","_temp2","type","addResult","addToolResult","resume","resumeToolCall","respondToApproval","respondToToolApproval","t11","Tool","status","Error","Data","console","warn","MessagePartProps","partIndex","MessagePartImpl","MessagePart","prev","next","EmptyPartFallback","component","Component","COMPLETE_STATUS","Object","freeze","EmptyPartsImpl","_temp3","EmptyParts","contentLength","_temp4","messageGroups","group","groupIndex","GroupComponent","map","partsElements","displayName","MessagePrimitiveUnstable_PartsGroupedByParentId","Omit","message"],"sources":["../../../src/primitives/message/MessagePartsGrouped.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type ComponentType,\n type FC,\n memo,\n type PropsWithChildren,\n useMemo,\n} from \"react\";\nimport { useAuiState, useAui } from \"@assistant-ui/store\";\nimport { PartByIndexProvider } from \"../../context/providers/PartByIndexProvider\";\nimport { TextMessagePartProvider } from \"../../context/providers/TextMessagePartProvider\";\nimport { MessagePartPrimitiveText } from \"../messagePart/MessagePartText\";\nimport { MessagePartPrimitiveImage } from \"../messagePart/MessagePartImage\";\nimport type {\n Unstable_AudioMessagePartComponent,\n DataMessagePartComponent,\n DataMessagePartProps,\n EmptyMessagePartComponent,\n TextMessagePartComponent,\n ImageMessagePartComponent,\n SourceMessagePartComponent,\n ToolCallMessagePartComponent,\n ToolCallMessagePartProps,\n FileMessagePartComponent,\n ReasoningMessagePartComponent,\n} from \"@assistant-ui/core/react\";\nimport { MessagePartPrimitiveInProgress } from \"../messagePart/MessagePartInProgress\";\nimport type { MessagePartStatus } from \"@assistant-ui/core\";\n\ntype MessagePartGroup = {\n groupKey: string | undefined;\n indices: number[];\n};\n\nexport type GroupingFunction = (parts: readonly any[]) => MessagePartGroup[];\n\n/**\n * Groups message parts by their parent ID.\n * Parts without a parent ID appear in their chronological position as individual groups.\n * Parts with the same parent ID are grouped together at the position of their first occurrence.\n */\nconst groupMessagePartsByParentId: GroupingFunction = (\n parts: readonly any[],\n): MessagePartGroup[] => {\n // Map maintains insertion order, so groups appear in order of first occurrence\n const groupMap = new Map<string, number[]>();\n\n // Process each part in order\n for (let i = 0; i < parts.length; i++) {\n const part = parts[i];\n const parentId = part?.parentId as string | undefined;\n\n // For parts without parentId, assign a unique group ID to maintain their position\n const groupId = parentId ?? `__ungrouped_${i}`;\n\n // Get or create the indices array for this group\n const indices = groupMap.get(groupId) ?? [];\n indices.push(i);\n groupMap.set(groupId, indices);\n }\n\n // Convert map to array of groups\n const groups: MessagePartGroup[] = [];\n for (const [groupId, indices] of groupMap) {\n // Extract parentId (undefined for ungrouped parts)\n const groupKey = groupId.startsWith(\"__ungrouped_\") ? undefined : groupId;\n groups.push({ groupKey, indices });\n }\n\n return groups;\n};\n\nconst useMessagePartsGrouped = (\n groupingFunction: GroupingFunction,\n): MessagePartGroup[] => {\n const parts = useAuiState((s) => s.message.parts);\n\n return useMemo(() => {\n if (parts.length === 0) {\n return [];\n }\n return groupingFunction(parts);\n }, [parts, groupingFunction]);\n};\n\nexport namespace MessagePrimitiveUnstable_PartsGrouped {\n export type Props = {\n /**\n * Function that takes an array of message parts and returns an array of groups.\n * Each group contains a key (for identification) and an array of indices.\n *\n * @example\n * ```tsx\n * // Group by parent ID (default behavior)\n * groupingFunction={(parts) => {\n * const groups = new Map<string, number[]>();\n * parts.forEach((part, i) => {\n * const key = part.parentId ?? `__ungrouped_${i}`;\n * const indices = groups.get(key) ?? [];\n * indices.push(i);\n * groups.set(key, indices);\n * });\n * return Array.from(groups.entries()).map(([key, indices]) => ({\n * key: key.startsWith(\"__ungrouped_\") ? undefined : key,\n * indices\n * }));\n * }}\n * ```\n *\n * @example\n * ```tsx\n * // Group by tool name\n * import { groupMessagePartsByToolName } from \"@assistant-ui/react\";\n *\n * <MessagePrimitive.Unstable_PartsGrouped\n * groupingFunction={groupMessagePartsByToolName}\n * components={{\n * Group: ({ key, indices, children }) => {\n * if (!key) return <>{children}</>;\n * return (\n * <div className=\"tool-group\">\n * <h4>Tool: {key}</h4>\n * {children}\n * </div>\n * );\n * }\n * }}\n * />\n * ```\n */\n groupingFunction: GroupingFunction;\n\n /**\n * Component configuration for rendering different types of message content.\n *\n * You can provide custom components for each content type (text, image, file, etc.)\n * and configure tool rendering behavior. If not provided, default components will be used.\n */\n components:\n | {\n /** Component for rendering empty messages */\n Empty?: EmptyMessagePartComponent | undefined;\n /** Component for rendering text content */\n Text?: TextMessagePartComponent | undefined;\n /** Component for rendering reasoning content (typically hidden) */\n Reasoning?: ReasoningMessagePartComponent | undefined;\n /** Component for rendering source content */\n Source?: SourceMessagePartComponent | undefined;\n /** Component for rendering image content */\n Image?: ImageMessagePartComponent | undefined;\n /** Component for rendering file content */\n File?: FileMessagePartComponent | undefined;\n /** Component for rendering audio content (experimental) */\n Unstable_Audio?: Unstable_AudioMessagePartComponent | undefined;\n /** Configuration for data part rendering */\n data?:\n | {\n /** Map data event names to specific components */\n by_name?:\n | Record<string, DataMessagePartComponent | undefined>\n | undefined;\n /** Fallback component for unmatched data events */\n Fallback?: DataMessagePartComponent | undefined;\n }\n | undefined;\n /** Configuration for tool call rendering */\n tools?:\n | {\n /** Map of tool names to their specific components */\n by_name?:\n | Record<string, ToolCallMessagePartComponent | undefined>\n | undefined;\n /** Fallback component for unregistered tools */\n Fallback?: ComponentType<ToolCallMessagePartProps> | undefined;\n }\n | {\n /** Override component that handles all tool calls */\n Override: ComponentType<ToolCallMessagePartProps>;\n }\n | undefined;\n\n /**\n * Component for rendering grouped message parts.\n *\n * When provided, this component will automatically wrap message parts that share\n * the same group key as determined by the groupingFunction.\n *\n * The component receives:\n * - `groupKey`: The group key (or undefined for ungrouped parts)\n * - `indices`: Array of indices for the parts in this group\n * - `children`: The rendered message part components\n *\n * @example\n * ```tsx\n * // Collapsible group\n * Group: ({ groupKey, indices, children }) => {\n * if (!groupKey) return <>{children}</>;\n * return (\n * <details className=\"message-group\">\n * <summary>\n * Group {groupKey} ({indices.length} parts)\n * </summary>\n * <div className=\"group-content\">\n * {children}\n * </div>\n * </details>\n * );\n * }\n * ```\n *\n * @param groupKey - The group key (undefined for ungrouped parts)\n * @param indices - Array of indices for the parts in this group\n * @param children - Rendered message part components to display within the group\n */\n Group?: ComponentType<\n PropsWithChildren<{\n groupKey: string | undefined;\n indices: number[];\n }>\n >;\n }\n | undefined;\n };\n}\n\nconst ToolUIDisplay = ({\n Fallback,\n ...props\n}: {\n Fallback: ToolCallMessagePartComponent | undefined;\n} & ToolCallMessagePartProps) => {\n const Render = useAuiState(\n (s) => s.tools.toolUIs[props.toolName]?.[0]?.render ?? Fallback,\n );\n if (!Render) return null;\n return <Render {...props} />;\n};\n\nconst DataUIDisplay = ({\n Fallback,\n ...props\n}: {\n Fallback: DataMessagePartComponent | undefined;\n} & DataMessagePartProps) => {\n const Render = useAuiState((s) => {\n const Render = s.dataRenderers.renderers[props.name] ?? Fallback;\n if (Array.isArray(Render)) return Render[0] ?? Fallback;\n return Render;\n });\n if (!Render) return null;\n return <Render {...props} />;\n};\n\nconst defaultComponents = {\n Text: () => (\n <p style={{ whiteSpace: \"pre-line\" }}>\n <MessagePartPrimitiveText />\n <MessagePartPrimitiveInProgress>\n <span style={{ fontFamily: \"revert\" }}>{\" \\u25CF\"}</span>\n </MessagePartPrimitiveInProgress>\n </p>\n ),\n Reasoning: () => null,\n Source: () => null,\n Image: () => <MessagePartPrimitiveImage />,\n File: () => null,\n Unstable_Audio: () => null,\n Group: ({ children }) => children,\n} satisfies MessagePrimitiveUnstable_PartsGrouped.Props[\"components\"];\n\ntype MessagePartComponentProps = {\n components: MessagePrimitiveUnstable_PartsGrouped.Props[\"components\"];\n};\n\nconst MessagePartComponent: FC<MessagePartComponentProps> = ({\n components: {\n Text = defaultComponents.Text,\n Reasoning = defaultComponents.Reasoning,\n Image = defaultComponents.Image,\n Source = defaultComponents.Source,\n File = defaultComponents.File,\n Unstable_Audio: Audio = defaultComponents.Unstable_Audio,\n tools = {},\n data,\n } = {},\n}) => {\n const aui = useAui();\n const part = useAuiState((s) => s.part);\n\n const type = part.type;\n if (type === \"tool-call\") {\n const addResult = aui.part.addToolResult;\n const resume = aui.part.resumeToolCall;\n const respondToApproval = aui.part.respondToToolApproval;\n if (\"Override\" in tools)\n return (\n <tools.Override\n {...part}\n addResult={addResult}\n resume={resume}\n respondToApproval={respondToApproval}\n />\n );\n const Tool = tools.by_name?.[part.toolName] ?? tools.Fallback;\n return (\n <ToolUIDisplay\n {...part}\n Fallback={Tool}\n addResult={addResult}\n resume={resume}\n respondToApproval={respondToApproval}\n />\n );\n }\n\n if (part.status?.type === \"requires-action\")\n throw new Error(\"Encountered unexpected requires-action status\");\n\n switch (type) {\n case \"text\":\n return <Text {...part} />;\n\n case \"reasoning\":\n return <Reasoning {...part} />;\n\n case \"source\":\n return <Source {...part} />;\n\n case \"image\":\n return <Image {...part} />;\n\n case \"file\":\n return <File {...part} />;\n\n case \"audio\":\n return <Audio {...part} />;\n\n case \"data\": {\n const Data = data?.by_name?.[part.name] ?? data?.Fallback;\n return <DataUIDisplay {...part} Fallback={Data} />;\n }\n\n default:\n console.warn(`Unknown message part type: ${type}`);\n return null;\n }\n};\n\ntype MessagePartProps = {\n partIndex: number;\n components: MessagePrimitiveUnstable_PartsGrouped.Props[\"components\"];\n};\n\nconst MessagePartImpl: FC<MessagePartProps> = ({ partIndex, components }) => {\n return (\n <PartByIndexProvider index={partIndex}>\n <MessagePartComponent components={components} />\n </PartByIndexProvider>\n );\n};\n\nconst MessagePart = memo(\n MessagePartImpl,\n (prev, next) =>\n prev.partIndex === next.partIndex &&\n prev.components?.Text === next.components?.Text &&\n prev.components?.Reasoning === next.components?.Reasoning &&\n prev.components?.Source === next.components?.Source &&\n prev.components?.Image === next.components?.Image &&\n prev.components?.File === next.components?.File &&\n prev.components?.Unstable_Audio === next.components?.Unstable_Audio &&\n prev.components?.tools === next.components?.tools &&\n prev.components?.data === next.components?.data &&\n prev.components?.Group === next.components?.Group,\n);\n\nconst EmptyPartFallback: FC<{\n status: MessagePartStatus;\n component: TextMessagePartComponent;\n}> = ({ status, component: Component }) => {\n return (\n <TextMessagePartProvider text=\"\" isRunning={status.type === \"running\"}>\n <Component type=\"text\" text=\"\" status={status} />\n </TextMessagePartProvider>\n );\n};\n\nconst COMPLETE_STATUS: MessagePartStatus = Object.freeze({\n type: \"complete\",\n});\n\nconst EmptyPartsImpl: FC<MessagePartComponentProps> = ({ components }) => {\n const status = useAuiState(\n (s) => (s.message.status ?? COMPLETE_STATUS) as MessagePartStatus,\n );\n\n if (components?.Empty) return <components.Empty status={status} />;\n\n return (\n <EmptyPartFallback\n status={status}\n component={components?.Text ?? defaultComponents.Text}\n />\n );\n};\n\nconst EmptyParts = memo(\n EmptyPartsImpl,\n (prev, next) =>\n prev.components?.Empty === next.components?.Empty &&\n prev.components?.Text === next.components?.Text,\n);\n\n/**\n * Renders the parts of a message grouped by a custom grouping function.\n *\n * This component allows you to group message parts based on any criteria you define.\n * The grouping function receives all message parts and returns an array of groups,\n * where each group has a key and an array of part indices.\n *\n * @deprecated Prefer `<MessagePrimitive.GroupedParts>` for adjacent\n * grouping — it dispatches all rendering through one `switch (part.type)`\n * and supports nested group paths. Keep this primitive only for\n * non-adjacent clustering (e.g., gathering parts with the same parent-id\n * across the message).\n *\n * @example\n * ```tsx\n * // Group by parent ID (default behavior)\n * <MessagePrimitive.Unstable_PartsGrouped\n * components={{\n * Text: ({ text }) => <p className=\"message-text\">{text}</p>,\n * Image: ({ image }) => <img src={image} alt=\"Message image\" />,\n * Group: ({ groupKey, indices, children }) => {\n * if (!groupKey) return <>{children}</>;\n * return (\n * <div className=\"parent-group border rounded p-4\">\n * <h4>Parent ID: {groupKey}</h4>\n * {children}\n * </div>\n * );\n * }\n * }}\n * />\n * ```\n */\nexport const MessagePrimitiveUnstable_PartsGrouped: FC<\n MessagePrimitiveUnstable_PartsGrouped.Props\n> = ({ groupingFunction, components }) => {\n const contentLength = useAuiState((s) => s.message.parts.length);\n const messageGroups = useMessagePartsGrouped(groupingFunction);\n\n const partsElements = useMemo(() => {\n if (contentLength === 0) {\n return <EmptyParts components={components} />;\n }\n\n return messageGroups.map((group, groupIndex) => {\n const GroupComponent = components?.Group ?? defaultComponents.Group;\n\n return (\n <GroupComponent\n key={`group-${groupIndex}-${group.groupKey ?? \"ungrouped\"}`}\n groupKey={group.groupKey}\n indices={group.indices}\n >\n {group.indices.map((partIndex) => (\n <MessagePart\n key={partIndex}\n partIndex={partIndex}\n components={components}\n />\n ))}\n </GroupComponent>\n );\n });\n }, [messageGroups, components, contentLength]);\n\n return <>{partsElements}</>;\n};\n\nMessagePrimitiveUnstable_PartsGrouped.displayName =\n \"MessagePrimitive.Unstable_PartsGrouped\";\n\n/**\n * Renders the parts of a message grouped by their parent ID.\n * This is a convenience wrapper around Unstable_PartsGrouped with parent ID grouping.\n *\n * @deprecated Use MessagePrimitive.Unstable_PartsGrouped instead for more flexibility\n */\nexport const MessagePrimitiveUnstable_PartsGroupedByParentId: FC<\n Omit<MessagePrimitiveUnstable_PartsGrouped.Props, \"groupingFunction\">\n> = ({ components, ...props }) => {\n return (\n <MessagePrimitiveUnstable_PartsGrouped\n {...props}\n components={components}\n groupingFunction={groupMessagePartsByParentId}\n />\n );\n};\n\nMessagePrimitiveUnstable_PartsGroupedByParentId.displayName =\n \"MessagePrimitive.Unstable_PartsGroupedByParentId\";\n"],"mappings":";;;;;;;;;;;;;;;;AA0CA,MAAM+B,+BACJD,UACuB;CAEvB,MAAME,2BAAW,IAAIC,IAAsB;CAG3C,KAAK,IAAIC,IAAI,GAAGA,IAAIJ,MAAMK,QAAQD,KAAK;EAKrC,MAAMI,UAJOR,MAAMI,EACE,EAAEG,YAG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
|
17
|
+
t0 = () => aui.message;
|
|
18
|
+
$[0] = aui.message;
|
|
19
19
|
$[1] = t0;
|
|
20
20
|
} else t0 = $[1];
|
|
21
21
|
const message = useAuiState(t0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageRoot.js","names":["c","_c","Primitive","ComponentRef","forwardRef","ComponentPropsWithoutRef","ForwardedRef","useCallback","useAui","useAuiState","useManagedRef","useComposedRefs","useThreadViewport","useThreadViewportStore","parseCssLength","ThreadViewportStore","NonNullable","ReturnType","useIsHoveringRef","$","aui","t0","message","t1","el","handleMouseEnter","setIsHovering","handleMouseLeave","addEventListener","matches","queueMicrotask","removeEventListener","callbackRef","useIsTopAnchorUser","activeAnchorId","_temp","s_0","s","role","index","thread","messages","length","at","id","isRunning","useIsTopAnchorTarget","activeTargetId","_temp2","isLast","useTopAnchorUserRef","active","threadViewportStore","getState","registerAnchorElement","callback","useTopAnchorTargetRef","state","clamp","topAnchorMessageClamp","registerAnchorTargetElement","tallerThan","visibleHeight","targetRefCallback","MessagePrimitiveRoot","Element","div","Props","MessagePrimitiveRootInternalProps","forwardedRef","MessagePrimitiveRootDefault","props","isHoveringRef","ref","messageId","_temp3","MessagePrimitiveRootTopAnchor","isTopAnchorUser","isTopAnchorTarget","topAnchorUserRef","topAnchorTargetRef","_temp4","t2","undefined","t3","t4","turnAnchor","displayName","topAnchorTurn","anchorId","targetId"],"sources":["../../../src/primitives/message/MessageRoot.tsx"],"sourcesContent":["\"use client\";\n\nimport { Primitive } from \"../../utils/Primitive\";\nimport {\n type ComponentRef,\n forwardRef,\n type ComponentPropsWithoutRef,\n type ForwardedRef,\n useCallback,\n} from \"react\";\nimport { useAui, useAuiState } from \"@assistant-ui/store\";\nimport { useManagedRef } from \"../../utils/hooks/useManagedRef\";\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport {\n useThreadViewport,\n useThreadViewportStore,\n} from \"../../context/react/ThreadViewportContext\";\nimport { parseCssLength } from \"../thread/topAnchor/topAnchorUtils\";\n\ntype ThreadViewportStore = NonNullable<\n ReturnType<typeof useThreadViewportStore>\n>;\n\nconst useIsHoveringRef = () => {\n const aui = useAui();\n const message = useAuiState(() => aui.message());\n\n const callbackRef = useCallback(\n (el: HTMLElement) => {\n const handleMouseEnter = () => {\n message.setIsHovering(true);\n };\n const handleMouseLeave = () => {\n message.setIsHovering(false);\n };\n\n el.addEventListener(\"mouseenter\", handleMouseEnter);\n el.addEventListener(\"mouseleave\", handleMouseLeave);\n\n if (el.matches(\":hover\")) {\n // TODO this is needed for SSR to work, figure out why\n queueMicrotask(() => message.setIsHovering(true));\n }\n\n return () => {\n el.removeEventListener(\"mouseenter\", handleMouseEnter);\n el.removeEventListener(\"mouseleave\", handleMouseLeave);\n message.setIsHovering(false);\n };\n },\n [message],\n );\n\n return useManagedRef(callbackRef);\n};\n\nconst useIsTopAnchorUser = () => {\n const activeAnchorId = useThreadViewport((s) => s.topAnchorTurn?.anchorId);\n return useAuiState(\n (s) =>\n s.message.role === \"user\" &&\n s.message.index > 0 &&\n s.message.index === s.thread.messages.length - 2 &&\n s.thread.messages.at(-1)?.role === \"assistant\" &&\n (s.message.id === activeAnchorId || s.thread.isRunning),\n );\n};\n\nconst useIsTopAnchorTarget = () => {\n const activeTargetId = useThreadViewport((s) => s.topAnchorTurn?.targetId);\n return useAuiState(\n (s) =>\n s.message.isLast &&\n s.message.role === \"assistant\" &&\n s.message.index >= 1 &&\n s.thread.messages.at(s.message.index - 1)?.role === \"user\" &&\n (s.message.id === activeTargetId || s.thread.isRunning),\n );\n};\n\nconst useTopAnchorUserRef = (\n active: boolean,\n threadViewportStore: ThreadViewportStore,\n) => {\n const callback = useCallback(\n (el: HTMLElement) => {\n if (!active) return;\n return threadViewportStore.getState().registerAnchorElement(el);\n },\n [active, threadViewportStore],\n );\n\n return useManagedRef<HTMLElement>(callback);\n};\n\nconst useTopAnchorTargetRef = ({\n active,\n threadViewportStore,\n}: {\n active: boolean;\n threadViewportStore: ThreadViewportStore;\n}) => {\n const targetRefCallback = useCallback(\n (el: HTMLElement) => {\n if (!active) return;\n const state = threadViewportStore.getState();\n const clamp = state.topAnchorMessageClamp;\n\n return state.registerAnchorTargetElement(el, {\n tallerThan: parseCssLength(clamp.tallerThan, el),\n visibleHeight: parseCssLength(clamp.visibleHeight, el),\n });\n },\n [active, threadViewportStore],\n );\n\n return useManagedRef<HTMLElement>(targetRefCallback);\n};\n\nexport namespace MessagePrimitiveRoot {\n export type Element = ComponentRef<typeof Primitive.div>;\n export type Props = ComponentPropsWithoutRef<typeof Primitive.div>;\n}\n\ntype MessagePrimitiveRootInternalProps = MessagePrimitiveRoot.Props & {\n forwardedRef: ForwardedRef<MessagePrimitiveRoot.Element>;\n};\n\nconst MessagePrimitiveRootDefault = ({\n forwardedRef,\n ...props\n}: MessagePrimitiveRootInternalProps) => {\n const isHoveringRef = useIsHoveringRef();\n const ref = useComposedRefs<HTMLDivElement>(forwardedRef, isHoveringRef);\n const messageId = useAuiState((s) => s.message.id);\n\n return <Primitive.div {...props} ref={ref} data-message-id={messageId} />;\n};\n\nconst MessagePrimitiveRootTopAnchor = ({\n forwardedRef,\n threadViewportStore,\n ...props\n}: MessagePrimitiveRootInternalProps & {\n threadViewportStore: ThreadViewportStore;\n}) => {\n const isHoveringRef = useIsHoveringRef();\n const isTopAnchorUser = useIsTopAnchorUser();\n const isTopAnchorTarget = useIsTopAnchorTarget();\n const topAnchorUserRef = useTopAnchorUserRef(\n isTopAnchorUser,\n threadViewportStore,\n );\n const topAnchorTargetRef = useTopAnchorTargetRef({\n active: isTopAnchorTarget,\n threadViewportStore,\n });\n const ref = useComposedRefs<HTMLDivElement>(\n forwardedRef,\n isHoveringRef,\n topAnchorUserRef,\n topAnchorTargetRef,\n );\n const messageId = useAuiState((s) => s.message.id);\n\n return (\n <Primitive.div\n {...props}\n ref={ref}\n data-message-id={messageId}\n data-aui-top-anchor-user={isTopAnchorUser ? \"\" : undefined}\n data-aui-top-anchor-target={isTopAnchorTarget ? \"\" : undefined}\n />\n );\n};\n\n/**\n * The root container component for a message.\n *\n * This component provides the foundational wrapper for message content and handles\n * hover state management for the message. It automatically tracks when the user\n * is hovering over the message, which can be used by child components like action bars.\n *\n * When `turnAnchor=\"top\"` is set on the viewport, this component automatically\n * registers itself as the top-anchor user message (when it's the previous user\n * message) or as the top-anchor target (when it's the streaming assistant\n * response). No additional component is required.\n *\n * @example\n * ```tsx\n * <MessagePrimitive.Root>\n * <MessagePrimitive.Content />\n * <ActionBarPrimitive.Root>\n * <ActionBarPrimitive.Copy />\n * <ActionBarPrimitive.Edit />\n * </ActionBarPrimitive.Root>\n * </MessagePrimitive.Root>\n * ```\n */\nexport const MessagePrimitiveRoot = forwardRef<\n MessagePrimitiveRoot.Element,\n MessagePrimitiveRoot.Props\n>((props, forwardedRef) => {\n const threadViewportStore = useThreadViewportStore();\n // turnAnchor is initial-only viewport config (see ThreadViewportProvider).\n const turnAnchor = threadViewportStore.getState().turnAnchor;\n\n if (turnAnchor === \"top\") {\n return (\n <MessagePrimitiveRootTopAnchor\n {...props}\n forwardedRef={forwardedRef}\n threadViewportStore={threadViewportStore}\n />\n );\n }\n return <MessagePrimitiveRootDefault {...props} forwardedRef={forwardedRef} />;\n});\n\nMessagePrimitiveRoot.displayName = \"MessagePrimitive.Root\";\n"],"mappings":";;;;;;;;;;;AAuBA,MAAMkB,yBAAmB;CAAA,MAAAC,IAAAlB,EAAA,CAAA;CACvB,MAAAmB,MAAYZ,OAAO;CAAE,IAAAa;CAAA,IAAAF,EAAA,OAAAC,KAAA;EACOC,WAAMD,IAAGE,QAAS;EAACH,EAAA,KAAAC;EAAAD,EAAA,KAAAE;CAAA,OAAAA,KAAAF,EAAA;CAA/C,MAAAG,UAAgBb,YAAYY,EAAmB;CAAE,IAAAE;CAAA,IAAAJ,EAAA,OAAAG,SAAA;EAG/CC,MAAAC,OAAA;GACE,MAAAC,yBAAyB;IACvBH,QAAOI,cAAe,IAAI;GAAC;GAE7B,MA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AAA;EAAA,OAJFE;CAIE;CAEL,IAAAA;CAAA,IAAAF,EAAA,OAAAkD,gBAAAlD,EAAA,OAAAoD,OAAA;EACMlD,KAAA,oBAAC,6BAAD;GAA4B,GAAKkD;GAAqBF;EAAY,CAAA;EAAIlD,EAAA,KAAAkD;EAAAlD,EAAA,KAAAoD;EAAApD,EAAA,KAAAE;CAAA,OAAAA,KAAAF,EAAA;CAAA,OAAtEE;AAAsE,CAC9E;AAED2C,qBAAqBuB,cAAc;AAnKR,SAAApD,MAAAE,GAAA;CAAA,OACuBA,EAACmD,eAAwBC;AAAA;AAW9C,SAAAzC,OAAAX,GAAA;CAAA,OACqBA,EAACmD,eAAwBE;AAAA;AA2DvC,SAAAf,OAAAtC,GAAA;CAAA,OAMGA,EAACf,QAAQsB;AAAG;AAKb,SAAAqC,OAAA5C,GAAA;CAAA,OAwBCA,EAACf,QAAQsB;AAAG"}
|
|
1
|
+
{"version":3,"file":"MessageRoot.js","names":["c","_c","Primitive","ComponentRef","forwardRef","ComponentPropsWithoutRef","ForwardedRef","useCallback","useAui","useAuiState","useManagedRef","useComposedRefs","useThreadViewport","useThreadViewportStore","parseCssLength","ThreadViewportStore","NonNullable","ReturnType","useIsHoveringRef","$","aui","t0","message","t1","el","handleMouseEnter","setIsHovering","handleMouseLeave","addEventListener","matches","queueMicrotask","removeEventListener","callbackRef","useIsTopAnchorUser","activeAnchorId","_temp","s_0","s","role","index","thread","messages","length","at","id","isRunning","useIsTopAnchorTarget","activeTargetId","_temp2","isLast","useTopAnchorUserRef","active","threadViewportStore","getState","registerAnchorElement","callback","useTopAnchorTargetRef","state","clamp","topAnchorMessageClamp","registerAnchorTargetElement","tallerThan","visibleHeight","targetRefCallback","MessagePrimitiveRoot","Element","div","Props","MessagePrimitiveRootInternalProps","forwardedRef","MessagePrimitiveRootDefault","props","isHoveringRef","ref","messageId","_temp3","MessagePrimitiveRootTopAnchor","isTopAnchorUser","isTopAnchorTarget","topAnchorUserRef","topAnchorTargetRef","_temp4","t2","undefined","t3","t4","turnAnchor","displayName","topAnchorTurn","anchorId","targetId"],"sources":["../../../src/primitives/message/MessageRoot.tsx"],"sourcesContent":["\"use client\";\n\nimport { Primitive } from \"../../utils/Primitive\";\nimport {\n type ComponentRef,\n forwardRef,\n type ComponentPropsWithoutRef,\n type ForwardedRef,\n useCallback,\n} from \"react\";\nimport { useAui, useAuiState } from \"@assistant-ui/store\";\nimport { useManagedRef } from \"../../utils/hooks/useManagedRef\";\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport {\n useThreadViewport,\n useThreadViewportStore,\n} from \"../../context/react/ThreadViewportContext\";\nimport { parseCssLength } from \"../thread/topAnchor/topAnchorUtils\";\n\ntype ThreadViewportStore = NonNullable<\n ReturnType<typeof useThreadViewportStore>\n>;\n\nconst useIsHoveringRef = () => {\n const aui = useAui();\n const message = useAuiState(() => aui.message);\n\n const callbackRef = useCallback(\n (el: HTMLElement) => {\n const handleMouseEnter = () => {\n message.setIsHovering(true);\n };\n const handleMouseLeave = () => {\n message.setIsHovering(false);\n };\n\n el.addEventListener(\"mouseenter\", handleMouseEnter);\n el.addEventListener(\"mouseleave\", handleMouseLeave);\n\n if (el.matches(\":hover\")) {\n // TODO this is needed for SSR to work, figure out why\n queueMicrotask(() => message.setIsHovering(true));\n }\n\n return () => {\n el.removeEventListener(\"mouseenter\", handleMouseEnter);\n el.removeEventListener(\"mouseleave\", handleMouseLeave);\n message.setIsHovering(false);\n };\n },\n [message],\n );\n\n return useManagedRef(callbackRef);\n};\n\nconst useIsTopAnchorUser = () => {\n const activeAnchorId = useThreadViewport((s) => s.topAnchorTurn?.anchorId);\n return useAuiState(\n (s) =>\n s.message.role === \"user\" &&\n s.message.index > 0 &&\n s.message.index === s.thread.messages.length - 2 &&\n s.thread.messages.at(-1)?.role === \"assistant\" &&\n (s.message.id === activeAnchorId || s.thread.isRunning),\n );\n};\n\nconst useIsTopAnchorTarget = () => {\n const activeTargetId = useThreadViewport((s) => s.topAnchorTurn?.targetId);\n return useAuiState(\n (s) =>\n s.message.isLast &&\n s.message.role === \"assistant\" &&\n s.message.index >= 1 &&\n s.thread.messages.at(s.message.index - 1)?.role === \"user\" &&\n (s.message.id === activeTargetId || s.thread.isRunning),\n );\n};\n\nconst useTopAnchorUserRef = (\n active: boolean,\n threadViewportStore: ThreadViewportStore,\n) => {\n const callback = useCallback(\n (el: HTMLElement) => {\n if (!active) return;\n return threadViewportStore.getState().registerAnchorElement(el);\n },\n [active, threadViewportStore],\n );\n\n return useManagedRef<HTMLElement>(callback);\n};\n\nconst useTopAnchorTargetRef = ({\n active,\n threadViewportStore,\n}: {\n active: boolean;\n threadViewportStore: ThreadViewportStore;\n}) => {\n const targetRefCallback = useCallback(\n (el: HTMLElement) => {\n if (!active) return;\n const state = threadViewportStore.getState();\n const clamp = state.topAnchorMessageClamp;\n\n return state.registerAnchorTargetElement(el, {\n tallerThan: parseCssLength(clamp.tallerThan, el),\n visibleHeight: parseCssLength(clamp.visibleHeight, el),\n });\n },\n [active, threadViewportStore],\n );\n\n return useManagedRef<HTMLElement>(targetRefCallback);\n};\n\nexport namespace MessagePrimitiveRoot {\n export type Element = ComponentRef<typeof Primitive.div>;\n export type Props = ComponentPropsWithoutRef<typeof Primitive.div>;\n}\n\ntype MessagePrimitiveRootInternalProps = MessagePrimitiveRoot.Props & {\n forwardedRef: ForwardedRef<MessagePrimitiveRoot.Element>;\n};\n\nconst MessagePrimitiveRootDefault = ({\n forwardedRef,\n ...props\n}: MessagePrimitiveRootInternalProps) => {\n const isHoveringRef = useIsHoveringRef();\n const ref = useComposedRefs<HTMLDivElement>(forwardedRef, isHoveringRef);\n const messageId = useAuiState((s) => s.message.id);\n\n return <Primitive.div {...props} ref={ref} data-message-id={messageId} />;\n};\n\nconst MessagePrimitiveRootTopAnchor = ({\n forwardedRef,\n threadViewportStore,\n ...props\n}: MessagePrimitiveRootInternalProps & {\n threadViewportStore: ThreadViewportStore;\n}) => {\n const isHoveringRef = useIsHoveringRef();\n const isTopAnchorUser = useIsTopAnchorUser();\n const isTopAnchorTarget = useIsTopAnchorTarget();\n const topAnchorUserRef = useTopAnchorUserRef(\n isTopAnchorUser,\n threadViewportStore,\n );\n const topAnchorTargetRef = useTopAnchorTargetRef({\n active: isTopAnchorTarget,\n threadViewportStore,\n });\n const ref = useComposedRefs<HTMLDivElement>(\n forwardedRef,\n isHoveringRef,\n topAnchorUserRef,\n topAnchorTargetRef,\n );\n const messageId = useAuiState((s) => s.message.id);\n\n return (\n <Primitive.div\n {...props}\n ref={ref}\n data-message-id={messageId}\n data-aui-top-anchor-user={isTopAnchorUser ? \"\" : undefined}\n data-aui-top-anchor-target={isTopAnchorTarget ? \"\" : undefined}\n />\n );\n};\n\n/**\n * The root container component for a message.\n *\n * This component provides the foundational wrapper for message content and handles\n * hover state management for the message. It automatically tracks when the user\n * is hovering over the message, which can be used by child components like action bars.\n *\n * When `turnAnchor=\"top\"` is set on the viewport, this component automatically\n * registers itself as the top-anchor user message (when it's the previous user\n * message) or as the top-anchor target (when it's the streaming assistant\n * response). No additional component is required.\n *\n * @example\n * ```tsx\n * <MessagePrimitive.Root>\n * <MessagePrimitive.Content />\n * <ActionBarPrimitive.Root>\n * <ActionBarPrimitive.Copy />\n * <ActionBarPrimitive.Edit />\n * </ActionBarPrimitive.Root>\n * </MessagePrimitive.Root>\n * ```\n */\nexport const MessagePrimitiveRoot = forwardRef<\n MessagePrimitiveRoot.Element,\n MessagePrimitiveRoot.Props\n>((props, forwardedRef) => {\n const threadViewportStore = useThreadViewportStore();\n // turnAnchor is initial-only viewport config (see ThreadViewportProvider).\n const turnAnchor = threadViewportStore.getState().turnAnchor;\n\n if (turnAnchor === \"top\") {\n return (\n <MessagePrimitiveRootTopAnchor\n {...props}\n forwardedRef={forwardedRef}\n threadViewportStore={threadViewportStore}\n />\n );\n }\n return <MessagePrimitiveRootDefault {...props} forwardedRef={forwardedRef} />;\n});\n\nMessagePrimitiveRoot.displayName = \"MessagePrimitive.Root\";\n"],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mE,OAAAF,iBAAA;CAAA,MAAAlD,IAAAlB,EAAA,CAAA;CACA,MAAAmD,sBAA4BvC,uBAAuB;CAInD,IAFmBuC,oBAAmBC,SAAU,CAAC,CAAAiC,eAE9B,OAAK;EAAA,IAAAjE;EAAA,IAAAF,EAAA,OAAAkD,gBAAAlD,EAAA,OAAAoD,SAAApD,EAAA,OAAAiC,qBAAA;GAEpB/B,KAAA,oBAAC,+BAAD;IAA8B,GACxBkD;IACUF;IACOjB;GAAmB,CAAA;GACxCjC,EAAA,KAAAkD;GAAAlD,EAAA,KAAAoD;GAAApD,EAAA,KAAAiC;GAAAjC,EAAA,KAAAE;EAAA,OAAAA,KAAAF,EAAA;EAAA,OAJFE;CAIE;CAEL,IAAAA;CAAA,IAAAF,EAAA,OAAAkD,gBAAAlD,EAAA,OAAAoD,OAAA;EACMlD,KAAA,oBAAC,6BAAD;GAA4B,GAAKkD;GAAqBF;EAAY,CAAA;EAAIlD,EAAA,KAAAkD;EAAAlD,EAAA,KAAAoD;EAAApD,EAAA,KAAAE;CAAA,OAAAA,KAAAF,EAAA;CAAA,OAAtEE;AAAsE,CAC9E;AAED2C,qBAAqBuB,cAAc;AAnKR,SAAApD,MAAAE,GAAA;CAAA,OACuBA,EAACmD,eAAwBC;AAAA;AAW9C,SAAAzC,OAAAX,GAAA;CAAA,OACqBA,EAACmD,eAAwBE;AAAA;AA2DvC,SAAAf,OAAAtC,GAAA;CAAA,OAMGA,EAACf,QAAQsB;AAAG;AAKb,SAAAqC,OAAA5C,GAAA;CAAA,OAwBCA,EAACf,QAAQsB;AAAG"}
|
|
@@ -8,11 +8,11 @@ const useQueueItemRemove = () => {
|
|
|
8
8
|
const $ = c(2);
|
|
9
9
|
const aui = useAui();
|
|
10
10
|
let t0;
|
|
11
|
-
if ($[0] !== aui) {
|
|
11
|
+
if ($[0] !== aui.queueItem) {
|
|
12
12
|
t0 = () => {
|
|
13
|
-
aui.queueItem
|
|
13
|
+
aui.queueItem.remove();
|
|
14
14
|
};
|
|
15
|
-
$[0] = aui;
|
|
15
|
+
$[0] = aui.queueItem;
|
|
16
16
|
$[1] = t0;
|
|
17
17
|
} else t0 = $[1];
|
|
18
18
|
return t0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueueItemRemove.js","names":["c","_c","ActionButtonElement","ActionButtonProps","createActionButton","useAui","useCallback","useQueueItemRemove","$","aui","t0","queueItem","remove","callback","QueueItemPrimitiveRemove","Element","Props"],"sources":["../../../src/primitives/queueItem/QueueItemRemove.ts"],"sourcesContent":["\"use client\";\n\nimport {\n type ActionButtonElement,\n type ActionButtonProps,\n createActionButton,\n} from \"../../utils/createActionButton\";\nimport { useAui } from \"@assistant-ui/store\";\nimport { useCallback } from \"react\";\n\nconst useQueueItemRemove = () => {\n const aui = useAui();\n\n const callback = useCallback(() => {\n aui.queueItem
|
|
1
|
+
{"version":3,"file":"QueueItemRemove.js","names":["c","_c","ActionButtonElement","ActionButtonProps","createActionButton","useAui","useCallback","useQueueItemRemove","$","aui","t0","queueItem","remove","callback","QueueItemPrimitiveRemove","Element","Props"],"sources":["../../../src/primitives/queueItem/QueueItemRemove.ts"],"sourcesContent":["\"use client\";\n\nimport {\n type ActionButtonElement,\n type ActionButtonProps,\n createActionButton,\n} from \"../../utils/createActionButton\";\nimport { useAui } from \"@assistant-ui/store\";\nimport { useCallback } from \"react\";\n\nconst useQueueItemRemove = () => {\n const aui = useAui();\n\n const callback = useCallback(() => {\n aui.queueItem.remove();\n }, [aui]);\n\n return callback;\n};\n\nexport namespace QueueItemPrimitiveRemove {\n export type Element = ActionButtonElement;\n export type Props = ActionButtonProps<typeof useQueueItemRemove>;\n}\n\n/**\n * A button that removes this item from the queue.\n *\n * @example\n * ```tsx\n * <QueueItemPrimitive.Remove>×</QueueItemPrimitive.Remove>\n * ```\n */\nexport const QueueItemPrimitiveRemove = createActionButton(\n \"QueueItemPrimitive.Remove\",\n useQueueItemRemove,\n);\n"],"mappings":";;;;;;AAUA,MAAMO,2BAAqB;CAAA,MAAAC,IAAAP,EAAA,CAAA;CACzB,MAAAQ,MAAYJ,OAAO;CAAE,IAAAK;CAAA,IAAAF,EAAA,OAAAC,IAAAE,WAAA;EAEQD,WAAA;GAC3BD,IAAGE,UAAUC,OAAQ;EAAC;EACvBJ,EAAA,KAAAC,IAAAE;EAAAH,EAAA,KAAAE;CAAA,OAAAA,KAAAF,EAAA;CAAS,OAEHK;AAAQ;;;;;;;;;AAgBjB,MAAaC,2BAA2BV,mBACtC,6BACAG,kBACF"}
|
|
@@ -8,11 +8,11 @@ const useQueueItemSteer = () => {
|
|
|
8
8
|
const $ = c(2);
|
|
9
9
|
const aui = useAui();
|
|
10
10
|
let t0;
|
|
11
|
-
if ($[0] !== aui) {
|
|
11
|
+
if ($[0] !== aui.queueItem) {
|
|
12
12
|
t0 = () => {
|
|
13
|
-
aui.queueItem
|
|
13
|
+
aui.queueItem.steer();
|
|
14
14
|
};
|
|
15
|
-
$[0] = aui;
|
|
15
|
+
$[0] = aui.queueItem;
|
|
16
16
|
$[1] = t0;
|
|
17
17
|
} else t0 = $[1];
|
|
18
18
|
return t0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueueItemSteer.js","names":["c","_c","ActionButtonElement","ActionButtonProps","createActionButton","useAui","useCallback","useQueueItemSteer","$","aui","t0","queueItem","steer","callback","QueueItemPrimitiveSteer","Element","Props"],"sources":["../../../src/primitives/queueItem/QueueItemSteer.ts"],"sourcesContent":["\"use client\";\n\nimport {\n type ActionButtonElement,\n type ActionButtonProps,\n createActionButton,\n} from \"../../utils/createActionButton\";\nimport { useAui } from \"@assistant-ui/store\";\nimport { useCallback } from \"react\";\n\nconst useQueueItemSteer = () => {\n const aui = useAui();\n\n const callback = useCallback(() => {\n aui.queueItem
|
|
1
|
+
{"version":3,"file":"QueueItemSteer.js","names":["c","_c","ActionButtonElement","ActionButtonProps","createActionButton","useAui","useCallback","useQueueItemSteer","$","aui","t0","queueItem","steer","callback","QueueItemPrimitiveSteer","Element","Props"],"sources":["../../../src/primitives/queueItem/QueueItemSteer.ts"],"sourcesContent":["\"use client\";\n\nimport {\n type ActionButtonElement,\n type ActionButtonProps,\n createActionButton,\n} from \"../../utils/createActionButton\";\nimport { useAui } from \"@assistant-ui/store\";\nimport { useCallback } from \"react\";\n\nconst useQueueItemSteer = () => {\n const aui = useAui();\n\n const callback = useCallback(() => {\n aui.queueItem.steer();\n }, [aui]);\n\n return callback;\n};\n\nexport namespace QueueItemPrimitiveSteer {\n export type Element = ActionButtonElement;\n export type Props = ActionButtonProps<typeof useQueueItemSteer>;\n}\n\n/**\n * A button that steers the current run to process this queue item immediately.\n *\n * @example\n * ```tsx\n * <QueueItemPrimitive.Steer>Run Now</QueueItemPrimitive.Steer>\n * ```\n */\nexport const QueueItemPrimitiveSteer = createActionButton(\n \"QueueItemPrimitive.Steer\",\n useQueueItemSteer,\n);\n"],"mappings":";;;;;;AAUA,MAAMO,0BAAoB;CAAA,MAAAC,IAAAP,EAAA,CAAA;CACxB,MAAAQ,MAAYJ,OAAO;CAAE,IAAAK;CAAA,IAAAF,EAAA,OAAAC,IAAAE,WAAA;EAEQD,WAAA;GAC3BD,IAAGE,UAAUC,MAAO;EAAC;EACtBJ,EAAA,KAAAC,IAAAE;EAAAH,EAAA,KAAAE;CAAA,OAAAA,KAAAF,EAAA;CAAS,OAEHK;AAAQ;;;;;;;;;AAgBjB,MAAaC,0BAA0BV,mBACrC,4BACAG,iBACF"}
|
|
@@ -43,7 +43,7 @@ const SelectionToolbarPrimitiveQuote = forwardRef((t0, forwardedRef) => {
|
|
|
43
43
|
if ($[4] !== aui || $[5] !== info) {
|
|
44
44
|
t1 = () => {
|
|
45
45
|
if (!info) return;
|
|
46
|
-
aui.thread
|
|
46
|
+
aui.thread.composer().setQuote({
|
|
47
47
|
text: info.text,
|
|
48
48
|
messageId: info.messageId
|
|
49
49
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectionToolbarQuote.js","names":["c","_c","Primitive","composeEventHandlers","ComponentPropsWithoutRef","ComponentRef","forwardRef","useCallback","useAui","useSelectionToolbarInfo","SelectionToolbarPrimitiveQuote","Element","button","Props","t0","forwardedRef","$","disabled","onClick","props","aui","info","t1","thread","composer","setQuote","text","messageId","window","getSelection","removeAllRanges","handleClick","t2","t3","t4","displayName"],"sources":["../../../src/primitives/selectionToolbar/SelectionToolbarQuote.tsx"],"sourcesContent":["\"use client\";\n\nimport { Primitive } from \"../../utils/Primitive\";\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport {\n type ComponentPropsWithoutRef,\n type ComponentRef,\n forwardRef,\n useCallback,\n} from \"react\";\nimport { useAui } from \"@assistant-ui/store\";\nimport { useSelectionToolbarInfo } from \"./SelectionToolbarRoot\";\n\nexport namespace SelectionToolbarPrimitiveQuote {\n export type Element = ComponentRef<typeof Primitive.button>;\n export type Props = ComponentPropsWithoutRef<typeof Primitive.button>;\n}\n\n/**\n * A button that quotes the currently selected text.\n *\n * Must be placed inside `SelectionToolbarPrimitive.Root`. Reads the\n * selection info from context (captured by the Root), sets it as a\n * quote in the thread composer, and clears the selection.\n *\n * @example\n * ```tsx\n * <SelectionToolbarPrimitive.Quote>\n * <QuoteIcon /> Quote\n * </SelectionToolbarPrimitive.Quote>\n * ```\n */\nexport const SelectionToolbarPrimitiveQuote = forwardRef<\n SelectionToolbarPrimitiveQuote.Element,\n SelectionToolbarPrimitiveQuote.Props\n>(({ onClick, disabled, ...props }, forwardedRef) => {\n const aui = useAui();\n const info = useSelectionToolbarInfo();\n\n const handleClick = useCallback(() => {\n if (!info) return;\n\n aui.thread
|
|
1
|
+
{"version":3,"file":"SelectionToolbarQuote.js","names":["c","_c","Primitive","composeEventHandlers","ComponentPropsWithoutRef","ComponentRef","forwardRef","useCallback","useAui","useSelectionToolbarInfo","SelectionToolbarPrimitiveQuote","Element","button","Props","t0","forwardedRef","$","disabled","onClick","props","aui","info","t1","thread","composer","setQuote","text","messageId","window","getSelection","removeAllRanges","handleClick","t2","t3","t4","displayName"],"sources":["../../../src/primitives/selectionToolbar/SelectionToolbarQuote.tsx"],"sourcesContent":["\"use client\";\n\nimport { Primitive } from \"../../utils/Primitive\";\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport {\n type ComponentPropsWithoutRef,\n type ComponentRef,\n forwardRef,\n useCallback,\n} from \"react\";\nimport { useAui } from \"@assistant-ui/store\";\nimport { useSelectionToolbarInfo } from \"./SelectionToolbarRoot\";\n\nexport namespace SelectionToolbarPrimitiveQuote {\n export type Element = ComponentRef<typeof Primitive.button>;\n export type Props = ComponentPropsWithoutRef<typeof Primitive.button>;\n}\n\n/**\n * A button that quotes the currently selected text.\n *\n * Must be placed inside `SelectionToolbarPrimitive.Root`. Reads the\n * selection info from context (captured by the Root), sets it as a\n * quote in the thread composer, and clears the selection.\n *\n * @example\n * ```tsx\n * <SelectionToolbarPrimitive.Quote>\n * <QuoteIcon /> Quote\n * </SelectionToolbarPrimitive.Quote>\n * ```\n */\nexport const SelectionToolbarPrimitiveQuote = forwardRef<\n SelectionToolbarPrimitiveQuote.Element,\n SelectionToolbarPrimitiveQuote.Props\n>(({ onClick, disabled, ...props }, forwardedRef) => {\n const aui = useAui();\n const info = useSelectionToolbarInfo();\n\n const handleClick = useCallback(() => {\n if (!info) return;\n\n aui.thread.composer().setQuote({\n text: info.text,\n messageId: info.messageId,\n });\n\n window.getSelection()?.removeAllRanges();\n }, [aui, info]);\n\n return (\n <Primitive.button\n type=\"button\"\n {...props}\n ref={forwardedRef}\n disabled={disabled || !info}\n onClick={composeEventHandlers(onClick, handleClick)}\n />\n );\n});\n\nSelectionToolbarPrimitiveQuote.displayName = \"SelectionToolbarPrimitive.Quote\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAgCA,MAAaU,iCAAiCJ,YAG5CQ,IAAAC,iBAAA;CAAA,MAAAC,IAAAf,EAAA,EAAA;CAAA,IAAAgB;CAAA,IAAAC;CAAA,IAAAC;C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AAAlB,EAAA;CAAA,OANFkB;AAME,CAEL;AAEDxB,+BAA+ByB,cAAc"}
|
|
@@ -5,7 +5,7 @@ import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
|
5
5
|
import "@assistant-ui/tap/react-shim";
|
|
6
6
|
//#region src/primitives/suggestion/SuggestionTrigger.ts
|
|
7
7
|
const useSuggestionTrigger = (t0) => {
|
|
8
|
-
const $ = c(
|
|
8
|
+
const $ = c(6);
|
|
9
9
|
const { send, clearComposer: t1 } = t0;
|
|
10
10
|
const clearComposer = t1 === void 0 ? true : t1;
|
|
11
11
|
const aui = useAui();
|
|
@@ -13,30 +13,31 @@ const useSuggestionTrigger = (t0) => {
|
|
|
13
13
|
const prompt = useAuiState(_temp2);
|
|
14
14
|
const resolvedSend = send ?? false;
|
|
15
15
|
let t2;
|
|
16
|
-
if ($[0] !== aui || $[1] !==
|
|
16
|
+
if ($[0] !== aui.composer || $[1] !== aui.thread || $[2] !== clearComposer || $[3] !== prompt || $[4] !== resolvedSend) {
|
|
17
17
|
t2 = () => {
|
|
18
|
-
const isRunning = aui.thread
|
|
18
|
+
const isRunning = aui.thread.getState().isRunning;
|
|
19
19
|
if (resolvedSend && !isRunning) {
|
|
20
|
-
aui.thread
|
|
20
|
+
aui.thread.append({
|
|
21
21
|
content: [{
|
|
22
22
|
type: "text",
|
|
23
23
|
text: prompt
|
|
24
24
|
}],
|
|
25
|
-
runConfig: aui.composer
|
|
25
|
+
runConfig: aui.composer.getState().runConfig
|
|
26
26
|
});
|
|
27
|
-
if (clearComposer) aui.composer
|
|
28
|
-
} else if (clearComposer) aui.composer
|
|
27
|
+
if (clearComposer) aui.composer.setText("");
|
|
28
|
+
} else if (clearComposer) aui.composer.setText(prompt);
|
|
29
29
|
else {
|
|
30
|
-
const currentText = aui.composer
|
|
31
|
-
aui.composer
|
|
30
|
+
const currentText = aui.composer.getState().text;
|
|
31
|
+
aui.composer.setText(currentText.trim() ? `${currentText} ${prompt}` : prompt);
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
|
-
$[0] = aui;
|
|
35
|
-
$[1] =
|
|
36
|
-
$[2] =
|
|
37
|
-
$[3] =
|
|
38
|
-
$[4] =
|
|
39
|
-
|
|
34
|
+
$[0] = aui.composer;
|
|
35
|
+
$[1] = aui.thread;
|
|
36
|
+
$[2] = clearComposer;
|
|
37
|
+
$[3] = prompt;
|
|
38
|
+
$[4] = resolvedSend;
|
|
39
|
+
$[5] = t2;
|
|
40
|
+
} else t2 = $[5];
|
|
40
41
|
const callback = t2;
|
|
41
42
|
if (disabled) return null;
|
|
42
43
|
return callback;
|