@qredence/fleet 0.5.0 → 0.5.5

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 (122) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +8 -1
  3. package/bin/fleet-prime.mjs +6 -0
  4. package/dist/web/client/assets/action-swap-roll-DX5o_33Q.js +1 -0
  5. package/dist/web/client/assets/artifacts-panel-C3yewUBP.js +1 -0
  6. package/dist/web/client/assets/artifacts-utils-N_kUFbz2.js +1 -0
  7. package/dist/web/client/assets/bot-Bs7QWJ2q.js +1 -0
  8. package/dist/web/client/assets/{chat-C64Sv6V-.js → chat-W-yOMyG_.js} +5 -5
  9. package/dist/web/client/assets/chat-command-palette-D0xDK1j4.js +1 -0
  10. package/dist/web/client/assets/command-CQzrtjyj.js +2 -0
  11. package/dist/web/client/assets/ease-vFBiNFNK.js +9 -0
  12. package/dist/web/client/assets/{fleet-pi-tool-renderer-ZKiX6Ob_.js → fleet-pi-tool-renderer-B0Y7ou0U.js} +28 -30
  13. package/dist/web/client/assets/generative-text-renderer-SS9c1kNX.js +6 -0
  14. package/dist/web/client/assets/globals-D_Hy9bT1.css +2 -0
  15. package/dist/web/client/assets/horizontal-resize-C1TpRLNC.js +1 -0
  16. package/dist/web/client/assets/index-C9FloFgj.js +12 -0
  17. package/dist/web/client/assets/{input-Clyn18XG.js → input-CqC82Agz.js} +1 -1
  18. package/dist/web/client/assets/{input-group-MxDAWX3j.js → input-group-H0TG-mkU.js} +1 -1
  19. package/dist/web/client/assets/ipython-tool-BrMePqD-.js +3 -0
  20. package/dist/web/client/assets/markdown-DG7pUdsX.js +2 -0
  21. package/dist/web/client/assets/{markdown-code-pIaEVDUU.js → markdown-code-BgMzpy7O.js} +1 -1
  22. package/dist/web/client/assets/notify-Duj26eeZ.js +1 -0
  23. package/dist/web/client/assets/{openui-renderer-NLUpAS3h.js → openui-renderer-CCfQqUfE.js} +5 -5
  24. package/dist/web/client/assets/openui-utils-DawGoQNp.js +1 -0
  25. package/dist/web/client/assets/prime-agent-artifacts-C-g1VPiW.js +5 -0
  26. package/dist/web/client/assets/{provider-catalog-Gx9qaHBM.js → provider-catalog-BZhZuKSz.js} +1 -1
  27. package/dist/web/client/assets/provider-label-jKm8v18u.js +1 -0
  28. package/dist/web/client/assets/range-65lubOFp.js +2 -0
  29. package/dist/web/client/assets/repl-panel-CCh4ly7J.js +1 -0
  30. package/dist/web/client/assets/resource-helpers-ULlyU8qK.js +2 -0
  31. package/dist/web/client/assets/resources-panel-DSU7VGX2.js +1 -0
  32. package/dist/web/client/assets/routes-DSTyx_J0.js +16 -0
  33. package/dist/web/client/assets/session-insights-panel-CQdT90Op.js +1 -0
  34. package/dist/web/client/assets/settings-dialog-CkfpTKfM.js +1 -0
  35. package/dist/web/client/assets/skeleton-loaders-fStjEeRP.js +1 -0
  36. package/dist/web/client/assets/square-terminal-BYTN_I86.js +1 -0
  37. package/dist/web/client/assets/subagent-chat-panel-D-qw4uWb.js +1 -0
  38. package/dist/web/client/assets/subagent-transcript-C7oRwEEP.js +1 -0
  39. package/dist/web/client/assets/subagents-panel-aSMWZP9p.js +1 -0
  40. package/dist/web/client/assets/{switch-ojzdMno9.js → switch-BFEBpUEU.js} +1 -1
  41. package/dist/web/client/assets/{tool-result-QvhjpNGX.js → tool-result-C2NvnN32.js} +3 -3
  42. package/dist/web/client/assets/ui-preferences-DUEFuJFj.js +1 -0
  43. package/dist/web/client/assets/workspace-panel-CjdXlEvd.js +1 -0
  44. package/dist/web/client/assets/workspace-path-nav-C0AQNZyy.js +1 -0
  45. package/dist/web/server/{_tanstack-start-manifest_v-uZddQetG-MNZGQOSA.js → _tanstack-start-manifest_v-DZc7dwm7-6ZQLGXB7.js} +23 -16
  46. package/dist/web/server/{artifacts-panel-knpQvJ-q-WJLZ76QB.js → artifacts-panel-Bt7YUzm4-NCBMXJ25.js} +39 -72
  47. package/dist/web/server/{chat-command-palette-CPv5GmGJ-22J32S6P.js → chat-command-palette-Co1L3rUY-RQLNME4T.js} +43 -20
  48. package/dist/web/server/{chunk-5277VI3D.js → chunk-2V6B62OF.js} +213 -275
  49. package/dist/web/server/{chunk-W7LNJCRJ.js → chunk-3HUI75QM.js} +75 -67
  50. package/dist/web/server/{chunk-I3FDTJFO.js → chunk-46VQY7SG.js} +6 -87
  51. package/dist/web/server/{chunk-PRT4QYOB.js → chunk-4UBOIY2S.js} +2 -35
  52. package/dist/web/server/{chunk-WTYNN6EV.js → chunk-54II5QXQ.js} +23 -1
  53. package/dist/web/server/chunk-56HSKUBD.js +1805 -0
  54. package/dist/web/server/{chunk-RPROZ2JC.js → chunk-5RQ6QAZX.js} +133 -133
  55. package/dist/web/server/{chunk-APN3LVRT.js → chunk-6D524OCJ.js} +201 -204
  56. package/dist/web/server/chunk-6GMKRR3C.js +161 -0
  57. package/dist/web/server/chunk-74QOI457.js +45 -0
  58. package/dist/web/server/{chunk-UBUXV2TW.js → chunk-AECEK3K7.js} +8 -8
  59. package/dist/web/server/chunk-AQ66E5OW.js +33 -0
  60. package/dist/web/server/{chunk-JD6EWZCU.js → chunk-AWFOBHH4.js} +50 -50
  61. package/dist/web/server/{chunk-MK3P3OBZ.js → chunk-BEMDNODD.js} +5 -5
  62. package/dist/web/server/{chunk-X2TUFLTP.js → chunk-BLVCDQ7E.js} +438 -438
  63. package/dist/web/server/chunk-FZRBAPUM.js +48 -0
  64. package/dist/web/server/chunk-G5BCQQ5N.js +34 -0
  65. package/dist/web/server/chunk-KOIPYBJF.js +3773 -0
  66. package/dist/web/server/{chunk-XYYNYFFD.js → chunk-LSIHVSUT.js} +2 -2
  67. package/dist/web/server/{chunk-KVHPE5XH.js → chunk-MDYA4NXK.js} +22 -8
  68. package/dist/web/server/chunk-NFRJDPB3.js +52 -0
  69. package/dist/web/server/chunk-P66QQWUM.js +67 -0
  70. package/dist/web/server/{chunk-4KFMONRT.js → chunk-PDRD2X5G.js} +9 -9
  71. package/dist/web/server/{chunk-XXNFEXDU.js → chunk-QJBEWT4E.js} +2 -70
  72. package/dist/web/server/{chunk-AQWTGP35.js → chunk-RX62LUDV.js} +8 -8
  73. package/dist/web/server/chunk-SR65ARVS.js +192 -0
  74. package/dist/web/server/{chunk-WK7CQS2N.js → chunk-SZ65K4CO.js} +48 -48
  75. package/dist/web/server/{chunk-C7EKOPZU.js → chunk-TO3YPLNZ.js} +89 -89
  76. package/dist/web/server/{chunk-IFV5M33X.js → chunk-UKINNXJY.js} +12 -26
  77. package/dist/web/server/chunk-VGDP4YDU.js +401 -0
  78. package/dist/web/server/{fleet-pi-tool-renderer-5vYFNeZS-IHKMLT7W.js → chunk-VRLTWOVJ.js} +46 -393
  79. package/dist/web/server/{chunk-KDSISV4P.js → chunk-WN77JNYY.js} +2 -50
  80. package/dist/web/server/{chunk-OADQILSQ.js → chunk-WZNZQNI4.js} +267 -3667
  81. package/dist/web/server/{chunk-KAWYGHDN.js → chunk-XFVL5ITL.js} +2354 -2314
  82. package/dist/web/server/{chunk-ZX3XOSYO.js → chunk-XLCTCC4W.js} +3 -3
  83. package/dist/web/server/{chunk-TTQ75CXC.js → chunk-Y4MHIA7B.js} +97 -40
  84. package/dist/web/server/fleet-pi-tool-renderer-CE45vM6T-2UQN6RJM.js +37 -0
  85. package/dist/web/server/{fork-picker-dialog-BZzfxdQd-C6SPHFAW.js → fork-picker-dialog-DCzuGelH-TN2Q5OXI.js} +5 -5
  86. package/dist/web/server/{markdown-Ct_q4D-z-VFWZRBTY.js → markdown-Boni3lHk-AZGKDNAR.js} +1 -1
  87. package/dist/web/server/{markdown-code-C_ih1bX1-5CIWT3CH.js → markdown-code-BrWukbg3-D2GN4Y77.js} +2 -2
  88. package/dist/web/server/{openui-renderer-BT5jL0Yf-XYLLN5U6.js → openui-renderer-c36_GYes-HX46N4M5.js} +14 -13
  89. package/dist/web/server/repl-panel-D9E8nkQy-L45ZNG2V.js +118 -0
  90. package/dist/web/server/{resources-panel-DNCVHTIg-PJYMXVGE.js → resources-panel-CwKh4U9f-D3VDEMDW.js} +6 -6
  91. package/dist/web/server/{router-DDxOMz3K-HRBXILHM.js → router-_ZpegqiQ-QIE44PIB.js} +1811 -1334
  92. package/dist/web/server/{routes-BX4Tv-6R-FHIZYUWW.js → routes-Ct81-8Tq-LHRMOS7R.js} +3958 -4534
  93. package/dist/web/server/server.js +3 -3
  94. package/dist/web/server/{session-insights-panel-gYkkAE8H-W4O74Z7H.js → session-insights-panel-BHZyKDTo-LRMAMA3O.js} +5 -3
  95. package/dist/web/server/{settings-dialog-BTBFLQ1P-ZENQ4KWK.js → settings-dialog-B4uUS6f--AZ4I4ZOT.js} +179 -193
  96. package/dist/web/server/{start-CLAD7RcD-56S4BWMM.js → start-BYVnok_H-IA6TWGA3.js} +1 -1
  97. package/dist/web/server/subagent-chat-panel-C97S3WID-DLOAD5TG.js +63 -0
  98. package/dist/web/server/subagents-panel-iHpvMIZy-LI6XK66M.js +181 -0
  99. package/dist/web/server/{chunk-5SZXUN3Y.js → workspace-panel-CHPoiXEo-YB4WS3MK.js} +29 -16
  100. package/package.json +15 -7
  101. package/dist/web/client/assets/artifacts-panel-8TyrNBM_.js +0 -1
  102. package/dist/web/client/assets/chat-command-palette-HpsmKfLO.js +0 -1
  103. package/dist/web/client/assets/collapsible-WCSnxhr2.js +0 -1
  104. package/dist/web/client/assets/command-DgfiCKcY.js +0 -2
  105. package/dist/web/client/assets/globals-BmxtUHFx.css +0 -2
  106. package/dist/web/client/assets/horizontal-resize-B76jjn5v.js +0 -1
  107. package/dist/web/client/assets/index-0pBr_bKy.js +0 -12
  108. package/dist/web/client/assets/markdown-BXWmNJo7.js +0 -2
  109. package/dist/web/client/assets/prime-agent-artifacts-k9JiTDZM.js +0 -5
  110. package/dist/web/client/assets/provider-brand-icon-VCebsuTD.js +0 -1
  111. package/dist/web/client/assets/range-KAaLzImH.js +0 -2
  112. package/dist/web/client/assets/resources-panel-BWuKeyrb.js +0 -1
  113. package/dist/web/client/assets/routes-BPRw0UzV.js +0 -20
  114. package/dist/web/client/assets/session-insights-panel-CPymkzZT.js +0 -1
  115. package/dist/web/client/assets/settings-dialog-6p8mjg8t.js +0 -1
  116. package/dist/web/client/assets/shared-DAI9OAw0.js +0 -2
  117. package/dist/web/client/assets/skeleton-loaders-qxIkJKCA.js +0 -1
  118. package/dist/web/client/assets/workspace-panel-C67-fqw4.js +0 -1
  119. package/dist/web/client/assets/workspace-path-nav-BrQHo6es.js +0 -9
  120. package/dist/web/server/chunk-KJ4UUAEU.js +0 -83
  121. package/dist/web/server/chunk-NGI44XRR.js +0 -334
  122. package/dist/web/server/workspace-panel-BNAXF57q-EQCBPEG4.js +0 -28
@@ -0,0 +1,1805 @@
1
+ import {
2
+ LazyMarkdown,
3
+ Terminal,
4
+ useHoverCapable
5
+ } from "./chunk-3HUI75QM.js";
6
+ import {
7
+ notify
8
+ } from "./chunk-FZRBAPUM.js";
9
+ import {
10
+ CircleX,
11
+ Copy,
12
+ Wrench
13
+ } from "./chunk-6D524OCJ.js";
14
+ import {
15
+ AnimatePresence,
16
+ EASE_OUT,
17
+ SPRING_LAYOUT,
18
+ m,
19
+ useReducedMotion
20
+ } from "./chunk-QJBEWT4E.js";
21
+ import {
22
+ CircleCheck,
23
+ LoaderCircle
24
+ } from "./chunk-PKCTG7EW.js";
25
+ import {
26
+ ChevronRight
27
+ } from "./chunk-7QCDOBZ3.js";
28
+ import {
29
+ segmentOpenUIContent
30
+ } from "./chunk-NFRJDPB3.js";
31
+ import {
32
+ ChevronDown
33
+ } from "./chunk-QLY3L4A2.js";
34
+ import {
35
+ Check
36
+ } from "./chunk-NLIUTTKL.js";
37
+ import {
38
+ X
39
+ } from "./chunk-BLVCDQ7E.js";
40
+ import {
41
+ CircleAlert,
42
+ FileText
43
+ } from "./chunk-7APYEQIO.js";
44
+ import {
45
+ createLucideIcon
46
+ } from "./chunk-E26EAQIM.js";
47
+ import {
48
+ cn
49
+ } from "./chunk-DJMHPJBP.js";
50
+
51
+ // web/app/dist/server/assets/generative-text-renderer-Cn-31rC8.js
52
+ import { Suspense, cloneElement, createContext, lazy, memo, useCallback, useContext, useEffect, useEffectEvent, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
53
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
54
+ import { createPortal } from "react-dom";
55
+ var ChevronLeft = createLucideIcon("chevron-left", [["path", {
56
+ d: "m15 18-6-6 6-6",
57
+ key: "1wnfg3"
58
+ }]]);
59
+ var FileBraces = createLucideIcon("file-braces", [
60
+ ["path", {
61
+ d: "M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",
62
+ key: "1oefj6"
63
+ }],
64
+ ["path", {
65
+ d: "M14 2v5a1 1 0 0 0 1 1h5",
66
+ key: "wfsgrz"
67
+ }],
68
+ ["path", {
69
+ d: "M10 12a1 1 0 0 0-1 1v1a1 1 0 0 1-1 1 1 1 0 0 1 1 1v1a1 1 0 0 0 1 1",
70
+ key: "1oajmo"
71
+ }],
72
+ ["path", {
73
+ d: "M14 18a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1 1 1 0 0 1-1-1v-1a1 1 0 0 0-1-1",
74
+ key: "mpwhp6"
75
+ }]
76
+ ]);
77
+ var FileCode = createLucideIcon("file-code", [
78
+ ["path", {
79
+ d: "M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",
80
+ key: "1oefj6"
81
+ }],
82
+ ["path", {
83
+ d: "M14 2v5a1 1 0 0 0 1 1h5",
84
+ key: "wfsgrz"
85
+ }],
86
+ ["path", {
87
+ d: "M10 12.5 8 15l2 2.5",
88
+ key: "1tg20x"
89
+ }],
90
+ ["path", {
91
+ d: "m14 12.5 2 2.5-2 2.5",
92
+ key: "yinavb"
93
+ }]
94
+ ]);
95
+ var FilePenLine = createLucideIcon("file-pen-line", [
96
+ ["path", {
97
+ d: "M14.364 13.634a2 2 0 0 0-.506.854l-.837 2.87a.5.5 0 0 0 .62.62l2.87-.837a2 2 0 0 0 .854-.506l4.013-4.009a1 1 0 0 0-3.004-3.004z",
98
+ key: "ukzhwg"
99
+ }],
100
+ ["path", {
101
+ d: "M14.487 7.858A1 1 0 0 1 14 7V2",
102
+ key: "1klhew"
103
+ }],
104
+ ["path", {
105
+ d: "M20 19.645V20a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l2.516 2.516",
106
+ key: "rxaxab"
107
+ }],
108
+ ["path", {
109
+ d: "M8 18h1",
110
+ key: "13wk12"
111
+ }]
112
+ ]);
113
+ var FileSearch = createLucideIcon("file-search", [
114
+ ["path", {
115
+ d: "M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",
116
+ key: "1oefj6"
117
+ }],
118
+ ["path", {
119
+ d: "M14 2v5a1 1 0 0 0 1 1h5",
120
+ key: "wfsgrz"
121
+ }],
122
+ ["circle", {
123
+ cx: "11.5",
124
+ cy: "14.5",
125
+ r: "2.5",
126
+ key: "1bq0ko"
127
+ }],
128
+ ["path", {
129
+ d: "M13.3 16.3 15 18",
130
+ key: "2quom7"
131
+ }]
132
+ ]);
133
+ var Image = createLucideIcon("image", [
134
+ ["rect", {
135
+ width: "18",
136
+ height: "18",
137
+ x: "3",
138
+ y: "3",
139
+ rx: "2",
140
+ ry: "2",
141
+ key: "1m3agn"
142
+ }],
143
+ ["circle", {
144
+ cx: "9",
145
+ cy: "9",
146
+ r: "2",
147
+ key: "af1f0g"
148
+ }],
149
+ ["path", {
150
+ d: "m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",
151
+ key: "1xmnt7"
152
+ }]
153
+ ]);
154
+ var RotateCw = createLucideIcon("rotate-cw", [["path", {
155
+ d: "M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",
156
+ key: "1p45f6"
157
+ }], ["path", {
158
+ d: "M21 3v5h-5",
159
+ key: "1q7to0"
160
+ }]]);
161
+ var MessageSideContext = createContext(void 0);
162
+ var MessageBubbleContext = createContext({
163
+ animateIn: true,
164
+ variant: "soft"
165
+ });
166
+ var MessageBubbleLayoutContext = createContext(() => {
167
+ });
168
+ function mergeRefs(...refs) {
169
+ return (node) => {
170
+ for (const ref of refs) if (typeof ref === "function") ref(node);
171
+ else if (ref) ref.current = node;
172
+ };
173
+ }
174
+ var BUBBLE_CONTENT_REVEAL = {
175
+ duration: 0.12,
176
+ ease: EASE_OUT,
177
+ delay: 0.04
178
+ };
179
+ var BUBBLE_POP = {
180
+ type: "spring",
181
+ stiffness: 520,
182
+ damping: 27,
183
+ mass: 0.52
184
+ };
185
+ function MessageBubble({ variant = "soft", align, animateIn = false, className, children, initial, animate, exit, transition, layout, ...props }) {
186
+ const reduce = useReducedMotion() ?? false;
187
+ const messageSide = useContext(MessageSideContext);
188
+ const resolvedAlign = align ?? messageSide ?? "start";
189
+ const messageBubbleContextValue = useMemo(() => ({
190
+ align: resolvedAlign,
191
+ animateIn,
192
+ variant
193
+ }), [
194
+ animateIn,
195
+ resolvedAlign,
196
+ variant
197
+ ]);
198
+ return /* @__PURE__ */ jsx(MessageBubbleContext.Provider, {
199
+ value: messageBubbleContextValue,
200
+ children: /* @__PURE__ */ jsx(m.div, {
201
+ "data-slot": "message-bubble",
202
+ "data-align": resolvedAlign,
203
+ "data-variant": variant,
204
+ layout,
205
+ initial: initial ?? false,
206
+ animate,
207
+ exit: exit ?? (reduce ? { opacity: 0 } : {
208
+ opacity: 0,
209
+ y: -3,
210
+ scale: 0.99
211
+ }),
212
+ transition: transition ?? (reduce ? { duration: 0.12 } : SPRING_LAYOUT),
213
+ className: cn("group/bubble flex w-full flex-col", resolvedAlign === "end" ? "items-end" : "items-start", className),
214
+ ...props,
215
+ children
216
+ })
217
+ });
218
+ }
219
+ function bubbleContentClass(variant, interactive) {
220
+ return cn("relative z-0 min-w-9 max-w-[82%] rounded-2xl px-3.5 py-2.5 text-sm leading-6 text-foreground", "[&_a]:font-medium [&_a]:underline [&_a]:underline-offset-4 [&_code]:rounded [&_code]:bg-background/60 [&_code]:px-1 [&_code]:py-0.5 [&_code]:font-mono [&_code]:text-[0.9em] [&_ol]:my-2 [&_ol]:list-decimal [&_ol]:pl-5 [&_p+p]:mt-2 [&_pre]:my-2 [&_pre]:overflow-x-auto [&_pre]:rounded-xl [&_pre]:bg-background/60 [&_pre]:p-3 [&_ul]:my-2 [&_ul]:list-disc [&_ul]:pl-5", variant === "solid" && "text-background", variant === "ghost" && "w-full max-w-none rounded-none px-0 py-0", variant === "danger" && "text-destructive", interactive && "cursor-pointer text-left outline-none transition-[background-color,color,transform] duration-150 hover:brightness-[0.98] focus-visible:ring-2 focus-visible:ring-ring active:scale-[0.99]");
221
+ }
222
+ function bubbleSurfaceClass(variant, align) {
223
+ return cn("pointer-events-none absolute inset-0 -z-10 rounded-[inherit]", align === "end" ? "origin-bottom-right" : "origin-bottom-left", variant === "solid" && "bg-foreground", variant === "soft" && "bg-muted", variant === "tint" && "bg-primary/10", variant === "outline" && "border border-border/70 bg-background", variant === "danger" && "bg-destructive/10");
224
+ }
225
+ function MessageBubbleContent({ render, className, children, ref, ...props }) {
226
+ const reduce = useReducedMotion() ?? false;
227
+ const { align = "start", animateIn, variant } = useContext(MessageBubbleContext);
228
+ const [layoutVersion, setLayoutVersion] = useState(0);
229
+ const notifyLayout = useCallback(() => setLayoutVersion((version) => version + 1), []);
230
+ const interactive = render?.type === "button" || render?.type === "a";
231
+ const classes = cn(bubbleContentClass(variant, interactive), className);
232
+ const composedChildren = /* @__PURE__ */ jsxs(Fragment$1, { children: [variant !== "ghost" ? /* @__PURE__ */ jsx(m.span, {
233
+ "aria-hidden": "true",
234
+ layout: reduce ? false : "size",
235
+ layoutDependency: layoutVersion,
236
+ initial: animateIn && !reduce ? {
237
+ opacity: 0,
238
+ scale: 0.92
239
+ } : false,
240
+ animate: {
241
+ opacity: 1,
242
+ scale: 1
243
+ },
244
+ transition: reduce ? { duration: 0 } : {
245
+ opacity: {
246
+ duration: 0.12,
247
+ ease: EASE_OUT
248
+ },
249
+ scale: BUBBLE_POP,
250
+ layout: SPRING_LAYOUT
251
+ },
252
+ className: bubbleSurfaceClass(variant, align)
253
+ }) : null, /* @__PURE__ */ jsx(MessageBubbleLayoutContext.Provider, {
254
+ value: notifyLayout,
255
+ children: /* @__PURE__ */ jsx(m.div, {
256
+ initial: animateIn ? reduce ? { opacity: 0 } : { opacity: 0 } : false,
257
+ animate: { opacity: 1 },
258
+ transition: reduce ? {
259
+ duration: 0.12,
260
+ ease: EASE_OUT
261
+ } : BUBBLE_CONTENT_REVEAL,
262
+ className: "relative",
263
+ children
264
+ })
265
+ })] });
266
+ if (render) {
267
+ const child = render;
268
+ return cloneElement(child, {
269
+ ...props,
270
+ ref: mergeRefs(child.props.ref, ref),
271
+ className: cn(classes, child.props.className),
272
+ children: composedChildren,
273
+ "data-slot": "message-bubble-content"
274
+ });
275
+ }
276
+ return /* @__PURE__ */ jsx("div", {
277
+ ref,
278
+ "data-slot": "message-bubble-content",
279
+ className: classes,
280
+ ...props,
281
+ children: composedChildren
282
+ });
283
+ }
284
+ function DefaultPreview({ item }) {
285
+ return /* @__PURE__ */ jsxs("div", {
286
+ "data-slot": "preview-rail-card",
287
+ className: "rounded-2xl border border-border bg-card p-4 shadow-sm",
288
+ children: [/* @__PURE__ */ jsx("p", {
289
+ "data-slot": "preview-rail-title",
290
+ className: "font-medium text-card-foreground",
291
+ children: item.label
292
+ }), item.description ? /* @__PURE__ */ jsx("div", {
293
+ "data-slot": "preview-rail-description",
294
+ className: "mt-1 text-sm leading-6 text-muted-foreground",
295
+ children: item.description
296
+ }) : null]
297
+ });
298
+ }
299
+ function PreviewRail({ items, label = "Section navigation", orientation = "vertical", activeId, defaultActiveId, onActiveChange, onItemSelect, renderPreview, showPreview = true, previewSide = "after", highlightActive = false, itemSize = 24, children, className, railClassName, previewContainerClassName, previewClassName }) {
300
+ const uid = useId();
301
+ const reduce = useReducedMotion();
302
+ const canHover = useHoverCapable();
303
+ const [internalActiveId, setInternalActiveId] = useState(defaultActiveId ?? items[0]?.id ?? "");
304
+ const [hoveredId, setHoveredId] = useState(null);
305
+ const [focusedId, setFocusedId] = useState(null);
306
+ const requestedActiveId = activeId ?? internalActiveId;
307
+ const selectedId = items.some((item) => item.id === requestedActiveId) ? requestedActiveId : items[0]?.id ?? "";
308
+ const displayedId = hoveredId ?? focusedId ?? "";
309
+ const highlightedId = displayedId || (highlightActive ? selectedId : "");
310
+ const displayedIndex = items.findIndex((item) => item.id === highlightedId);
311
+ const rowTemplate = items.length ? `repeat(${items.length}, ${itemSize}px)` : void 0;
312
+ const isHorizontal = orientation === "horizontal";
313
+ const selectItem = (id) => {
314
+ if (activeId === void 0) setInternalActiveId(id);
315
+ onActiveChange?.(id);
316
+ };
317
+ return /* @__PURE__ */ jsxs(m.div, {
318
+ layoutRoot: true,
319
+ onBlur: (event) => {
320
+ if (!event.currentTarget.contains(event.relatedTarget)) setFocusedId(null);
321
+ },
322
+ className: cn("isolate relative flex w-full overflow-visible", isHorizontal ? "min-h-64 flex-col items-center justify-center" : "min-h-80", className),
323
+ children: [
324
+ /* @__PURE__ */ jsx("nav", {
325
+ "aria-label": label,
326
+ onPointerLeave: () => setHoveredId(null),
327
+ style: isHorizontal ? { gridTemplateColumns: rowTemplate } : { gridTemplateRows: rowTemplate },
328
+ className: cn("relative z-10 grid shrink-0", isHorizontal ? "h-12 w-fit max-w-full self-center justify-center" : "w-12 content-center", railClassName),
329
+ children: items.map((item, index) => {
330
+ const selected = item.id === selectedId;
331
+ const highlighted = item.id === highlightedId;
332
+ const distance = displayedIndex < 0 ? Number.POSITIVE_INFINITY : Math.abs(index - displayedIndex);
333
+ const scale = highlighted ? 1 : distance === 1 ? 0.68 : distance === 2 ? 0.44 : 0.25;
334
+ const itemContent = /* @__PURE__ */ jsx(Fragment$1, { children: /* @__PURE__ */ jsx(m.span, {
335
+ "data-slot": "preview-rail-tick",
336
+ "aria-hidden": "true",
337
+ animate: isHorizontal ? { scaleY: scale } : { scaleX: scale },
338
+ transition: reduce ? { duration: 0 } : SPRING_LAYOUT,
339
+ className: cn("block bg-current", isHorizontal ? "h-12 w-0.5 origin-bottom" : "h-0.5 w-12 origin-left", highlighted ? "text-foreground" : void 0)
340
+ }) });
341
+ const sharedClassName = cn("relative flex text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background", isHorizontal ? "h-12 w-6 items-end justify-center" : "h-6 w-12 items-center");
342
+ const sharedStyle = isHorizontal ? { width: itemSize } : { height: itemSize };
343
+ const handlePointerEnter = () => {
344
+ if (canHover) setHoveredId(item.id);
345
+ };
346
+ const handleFocus = (currentTarget) => {
347
+ if (currentTarget.matches(":focus-visible")) setFocusedId(item.id);
348
+ };
349
+ const handleSelect = () => {
350
+ selectItem(item.id);
351
+ onItemSelect?.(item);
352
+ };
353
+ return item.href ? /* @__PURE__ */ jsx("a", {
354
+ "data-slot": "preview-rail-item",
355
+ href: item.href,
356
+ target: item.target,
357
+ rel: item.rel ?? (item.target === "_blank" ? "noreferrer noopener" : void 0),
358
+ "aria-label": item.ariaLabel ?? item.label,
359
+ "aria-current": selected ? "page" : void 0,
360
+ onPointerEnter: handlePointerEnter,
361
+ onMouseEnter: handlePointerEnter,
362
+ onPointerDown: () => setFocusedId(null),
363
+ onFocus: (event) => handleFocus(event.currentTarget),
364
+ onClick: handleSelect,
365
+ style: sharedStyle,
366
+ className: sharedClassName,
367
+ children: itemContent
368
+ }, item.id) : /* @__PURE__ */ jsx("button", {
369
+ "data-slot": "preview-rail-item",
370
+ type: "button",
371
+ "aria-label": item.ariaLabel ?? item.label,
372
+ "aria-current": selected ? "location" : void 0,
373
+ onPointerEnter: handlePointerEnter,
374
+ onMouseEnter: handlePointerEnter,
375
+ onPointerDown: () => setFocusedId(null),
376
+ onFocus: (event) => handleFocus(event.currentTarget),
377
+ onClick: handleSelect,
378
+ style: sharedStyle,
379
+ className: sharedClassName,
380
+ children: itemContent
381
+ }, item.id);
382
+ })
383
+ }),
384
+ showPreview ? /* @__PURE__ */ jsx("div", {
385
+ "aria-hidden": "true",
386
+ style: isHorizontal ? { gridTemplateColumns: rowTemplate } : { gridTemplateRows: rowTemplate },
387
+ className: cn("pointer-events-none absolute z-50 grid", isHorizontal ? "top-1/2 left-1/2 h-5 w-fit max-w-full -translate-x-1/2 -translate-y-1/2 justify-center" : previewSide === "before" ? "inset-y-0 right-16 left-4 content-center" : "inset-y-0 right-4 left-16 content-center", previewContainerClassName),
388
+ children: items.map((item) => /* @__PURE__ */ jsx("div", {
389
+ style: isHorizontal ? { width: itemSize } : { height: itemSize },
390
+ className: cn("relative flex items-center", isHorizontal ? "justify-center" : void 0),
391
+ children: /* @__PURE__ */ jsx(AnimatePresence, {
392
+ mode: "wait",
393
+ initial: false,
394
+ children: item.id === displayedId ? /* @__PURE__ */ jsx(m.div, {
395
+ initial: reduce ? { opacity: 0 } : {
396
+ opacity: 0,
397
+ y: 4,
398
+ filter: "blur(6px)"
399
+ },
400
+ animate: reduce ? { opacity: 1 } : {
401
+ opacity: 1,
402
+ y: 0,
403
+ filter: "blur(0px)"
404
+ },
405
+ exit: reduce ? { opacity: 0 } : {
406
+ opacity: 0,
407
+ y: -2,
408
+ filter: "blur(4px)",
409
+ transition: {
410
+ duration: 0.12,
411
+ ease: EASE_OUT
412
+ }
413
+ },
414
+ transition: {
415
+ duration: reduce ? 0 : 0.18,
416
+ ease: EASE_OUT
417
+ },
418
+ className: cn(isHorizontal ? "absolute bottom-12 left-1/2 w-72 -translate-x-1/2" : cn("w-full max-w-sm", previewSide === "before" && "ml-auto"), previewClassName),
419
+ children: /* @__PURE__ */ jsx(m.div, {
420
+ layoutId: `preview-rail-card-${uid}`,
421
+ transition: reduce ? { duration: 0 } : SPRING_LAYOUT,
422
+ children: renderPreview ? renderPreview(item) : /* @__PURE__ */ jsx(DefaultPreview, { item })
423
+ })
424
+ }, item.id) : null
425
+ })
426
+ }, item.id))
427
+ }) : null,
428
+ children ? /* @__PURE__ */ jsx("div", {
429
+ className: "min-h-0 min-w-0 flex-1",
430
+ children
431
+ }) : null
432
+ ]
433
+ });
434
+ }
435
+ var PREVIEW_TITLE_LENGTH = 56;
436
+ var PREVIEW_DESCRIPTION_LENGTH = 88;
437
+ function truncateMessageText(text, limit) {
438
+ if (text.length <= limit) return text;
439
+ const excerpt = text.slice(0, limit);
440
+ const boundary = excerpt.lastIndexOf(" ");
441
+ return `${excerpt.slice(0, boundary > limit * 0.65 ? boundary : limit).trim()}\u2026`;
442
+ }
443
+ function getMessageText(message) {
444
+ return ((message.querySelector('[data-slot="message-bubble-content"]') ?? message.querySelector('[data-slot="message-content"]') ?? message).textContent ?? "").replace(/\s+/g, " ").trim();
445
+ }
446
+ function getMessagePreview(message, assistantResponse) {
447
+ const text = getMessageText(message);
448
+ if (!text) return {
449
+ label: "Message",
450
+ description: void 0
451
+ };
452
+ if (text.length <= PREVIEW_TITLE_LENGTH) {
453
+ const responseText2 = assistantResponse ? getMessageText(assistantResponse) : "";
454
+ return {
455
+ label: text,
456
+ description: responseText2 ? truncateMessageText(responseText2, PREVIEW_DESCRIPTION_LENGTH) : void 0
457
+ };
458
+ }
459
+ const titleBoundary = text.slice(0, PREVIEW_TITLE_LENGTH).lastIndexOf(" ");
460
+ const titleEnd = titleBoundary > PREVIEW_TITLE_LENGTH * 0.65 ? titleBoundary : PREVIEW_TITLE_LENGTH;
461
+ const label = `${text.slice(0, titleEnd).trim()}\u2026`;
462
+ const responseText = assistantResponse ? getMessageText(assistantResponse) : text.slice(titleEnd).trim();
463
+ return {
464
+ label,
465
+ description: responseText ? truncateMessageText(responseText, PREVIEW_DESCRIPTION_LENGTH) : void 0
466
+ };
467
+ }
468
+ function useMessageScrollerRail({ navigation, followThreshold, contentRef, viewportRef, reduce, smooth, scrollToEnd, setFollowing, markProgrammaticScroll }) {
469
+ const railFrameRef = useRef(void 0);
470
+ const railIdRef = useRef(/* @__PURE__ */ new WeakMap());
471
+ const railIdCounterRef = useRef(0);
472
+ const railTargetsRef = useRef(/* @__PURE__ */ new Map());
473
+ const [railItems, setRailItems] = useState([]);
474
+ const [activeRailId, setActiveRailId] = useState("");
475
+ const [railOverflowing, setRailOverflowing] = useState(false);
476
+ const updateActiveRailItem = useCallback(() => {
477
+ if (navigation !== "rail") return;
478
+ const viewport = viewportRef.current;
479
+ const targets = [...railTargetsRef.current.entries()];
480
+ if (!viewport || targets.length === 0) return;
481
+ const viewportRect = viewport.getBoundingClientRect();
482
+ if (viewport.scrollTop <= followThreshold) {
483
+ const firstId = targets[0]?.[0] ?? "";
484
+ setActiveRailId((current) => current === firstId ? current : firstId);
485
+ return;
486
+ }
487
+ if (viewport.scrollHeight - viewport.scrollTop - viewport.clientHeight <= followThreshold) {
488
+ const lastId = targets.at(-1)?.[0] ?? "";
489
+ setActiveRailId((current) => current === lastId ? current : lastId);
490
+ return;
491
+ }
492
+ const viewportCenter = viewportRect.top + viewportRect.height / 2;
493
+ let nearestId = targets[0]?.[0] ?? "";
494
+ let nearestDistance = Number.POSITIVE_INFINITY;
495
+ for (const [id, element] of targets) {
496
+ const rect = element.getBoundingClientRect();
497
+ const distance = Math.abs(rect.top + rect.height / 2 - viewportCenter);
498
+ if (distance < nearestDistance) {
499
+ nearestDistance = distance;
500
+ nearestId = id;
501
+ }
502
+ }
503
+ setActiveRailId((current) => current === nearestId ? current : nearestId);
504
+ }, [
505
+ followThreshold,
506
+ navigation,
507
+ viewportRef
508
+ ]);
509
+ const syncRailItems = useCallback(() => {
510
+ if (navigation !== "rail") return;
511
+ const content = contentRef.current;
512
+ const viewport = viewportRef.current;
513
+ if (!content || !viewport) return;
514
+ const messages = Array.from(content.querySelectorAll('[data-slot="message"]'));
515
+ const targets = /* @__PURE__ */ new Map();
516
+ const nextItems = messages.map((message, index) => {
517
+ let id = railIdRef.current.get(message);
518
+ if (!id) {
519
+ railIdCounterRef.current += 1;
520
+ id = `message-rail-${railIdCounterRef.current}`;
521
+ railIdRef.current.set(message, id);
522
+ }
523
+ targets.set(id, message);
524
+ const sender = message.dataset.from ?? "conversation";
525
+ const preview = getMessagePreview(message, sender === "user" ? messages.slice(index + 1).find((candidate) => candidate.dataset.from === "assistant") : void 0);
526
+ return {
527
+ id,
528
+ label: preview.label,
529
+ description: preview.description,
530
+ ariaLabel: `Go to ${sender} message ${index + 1} of ${messages.length}`
531
+ };
532
+ });
533
+ railTargetsRef.current = targets;
534
+ setRailItems((current) => {
535
+ return current.length === nextItems.length && current.every((item, index) => item.id === nextItems[index]?.id && item.label === nextItems[index]?.label && item.description === nextItems[index]?.description && item.ariaLabel === nextItems[index]?.ariaLabel) ? current : nextItems;
536
+ });
537
+ setRailOverflowing(viewport.scrollHeight > viewport.clientHeight + 1 && messages.length > 1);
538
+ }, [
539
+ contentRef,
540
+ navigation,
541
+ viewportRef
542
+ ]);
543
+ const scheduleRailSync = useCallback(() => {
544
+ if (navigation !== "rail") return;
545
+ if (railFrameRef.current) cancelAnimationFrame(railFrameRef.current);
546
+ railFrameRef.current = requestAnimationFrame(() => {
547
+ syncRailItems();
548
+ updateActiveRailItem();
549
+ });
550
+ }, [
551
+ navigation,
552
+ syncRailItems,
553
+ updateActiveRailItem
554
+ ]);
555
+ useEffect(() => {
556
+ if (navigation !== "rail") {
557
+ railTargetsRef.current.clear();
558
+ setRailItems([]);
559
+ setRailOverflowing(false);
560
+ return;
561
+ }
562
+ const content = contentRef.current;
563
+ const viewport = viewportRef.current;
564
+ if (!content || !viewport) return;
565
+ scheduleRailSync();
566
+ const mutationObserver = typeof MutationObserver === "undefined" ? null : new MutationObserver(scheduleRailSync);
567
+ mutationObserver?.observe(content, {
568
+ childList: true,
569
+ characterData: true,
570
+ subtree: true
571
+ });
572
+ const resizeObserver = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(scheduleRailSync);
573
+ resizeObserver?.observe(content);
574
+ resizeObserver?.observe(viewport);
575
+ return () => {
576
+ mutationObserver?.disconnect();
577
+ resizeObserver?.disconnect();
578
+ };
579
+ }, [
580
+ contentRef,
581
+ navigation,
582
+ scheduleRailSync,
583
+ viewportRef
584
+ ]);
585
+ useEffect(() => () => {
586
+ if (railFrameRef.current) cancelAnimationFrame(railFrameRef.current);
587
+ }, []);
588
+ return {
589
+ activeRailId,
590
+ railItems,
591
+ railOverflowing,
592
+ scheduleRailSync,
593
+ scrollToRailItem: useCallback((item) => {
594
+ const viewport = viewportRef.current;
595
+ const target2 = railTargetsRef.current.get(item.id);
596
+ if (!viewport || !target2) return;
597
+ const lastItem = railItems.at(-1)?.id === item.id;
598
+ setActiveRailId(item.id);
599
+ if (lastItem) {
600
+ setFollowing(true);
601
+ scrollToEnd(reduce || !smooth ? "auto" : "smooth");
602
+ return;
603
+ }
604
+ setFollowing(false);
605
+ markProgrammaticScroll(reduce || !smooth ? "auto" : "smooth");
606
+ const viewportRect = viewport.getBoundingClientRect();
607
+ const targetRect = target2.getBoundingClientRect();
608
+ const top = viewport.scrollTop + targetRect.top - viewportRect.top - (viewport.clientHeight - targetRect.height) / 2;
609
+ const behavior = reduce || !smooth ? "auto" : "smooth";
610
+ if (typeof viewport.scrollTo === "function") viewport.scrollTo({
611
+ top,
612
+ behavior
613
+ });
614
+ else viewport.scrollTop = top;
615
+ }, [
616
+ markProgrammaticScroll,
617
+ railItems,
618
+ reduce,
619
+ scrollToEnd,
620
+ setFollowing,
621
+ smooth,
622
+ viewportRef
623
+ ])
624
+ };
625
+ }
626
+ function MessageScroller({ followOutput = true, followThreshold = 56, smooth = true, onFollowChange, label = "Conversation", busy, navigation, navigationLabel = "Message navigation", viewportClassName, contentClassName, railClassName, viewportRef: externalViewportRef, viewportProps, contentProps, className, children, ...props }) {
627
+ const reduce = useReducedMotion() ?? false;
628
+ const viewportRef = useRef(null);
629
+ const contentRef = useRef(null);
630
+ const followingRef = useRef(followOutput);
631
+ const programmaticScrollRef = useRef(false);
632
+ const scrollTimerRef = useRef(void 0);
633
+ const frameRef = useRef(void 0);
634
+ const { onScroll: onViewportScroll, onWheel: onViewportWheel, onTouchStart: onViewportTouchStart, onKeyDown: onViewportKeyDown, ...restViewportProps } = viewportProps ?? {};
635
+ const setViewportRef = useCallback((node) => {
636
+ viewportRef.current = node;
637
+ if (typeof externalViewportRef === "function") externalViewportRef(node);
638
+ else if (externalViewportRef) externalViewportRef.current = node;
639
+ }, [externalViewportRef]);
640
+ const setFollowing = useCallback((next) => {
641
+ if (followingRef.current === next) return;
642
+ followingRef.current = next;
643
+ onFollowChange?.(next);
644
+ }, [onFollowChange]);
645
+ const markProgrammaticScroll = useCallback((behavior) => {
646
+ programmaticScrollRef.current = true;
647
+ if (scrollTimerRef.current) window.clearTimeout(scrollTimerRef.current);
648
+ scrollTimerRef.current = window.setTimeout(() => {
649
+ programmaticScrollRef.current = false;
650
+ }, behavior === "smooth" ? 320 : 0);
651
+ }, []);
652
+ const scrollToEnd = useCallback((behavior) => {
653
+ const viewport2 = viewportRef.current;
654
+ if (!viewport2) return;
655
+ markProgrammaticScroll(behavior);
656
+ if (typeof viewport2.scrollTo === "function") viewport2.scrollTo({
657
+ top: viewport2.scrollHeight,
658
+ behavior
659
+ });
660
+ else viewport2.scrollTop = viewport2.scrollHeight;
661
+ }, [markProgrammaticScroll]);
662
+ const { activeRailId, railItems, railOverflowing, scheduleRailSync, scrollToRailItem } = useMessageScrollerRail({
663
+ navigation,
664
+ followThreshold,
665
+ contentRef,
666
+ viewportRef,
667
+ reduce,
668
+ smooth,
669
+ scrollToEnd,
670
+ setFollowing,
671
+ markProgrammaticScroll
672
+ });
673
+ const scheduleRailSyncEvent = useEffectEvent(scheduleRailSync);
674
+ const scrollToEndEvent = useEffectEvent(scrollToEnd);
675
+ const handleScroll = useCallback(() => {
676
+ const viewport2 = viewportRef.current;
677
+ if (!viewport2 || programmaticScrollRef.current) return;
678
+ const distance = viewport2.scrollHeight - viewport2.scrollTop - viewport2.clientHeight;
679
+ setFollowing(distance <= followThreshold);
680
+ scheduleRailSync();
681
+ }, [
682
+ followThreshold,
683
+ scheduleRailSync,
684
+ setFollowing
685
+ ]);
686
+ const leaveLiveEdge = useCallback(() => {
687
+ programmaticScrollRef.current = false;
688
+ }, []);
689
+ useLayoutEffect(() => {
690
+ followingRef.current = followOutput;
691
+ if (!followOutput) return;
692
+ frameRef.current = requestAnimationFrame(() => scrollToEndEvent("auto"));
693
+ return () => {
694
+ if (frameRef.current) cancelAnimationFrame(frameRef.current);
695
+ };
696
+ }, [followOutput]);
697
+ useEffect(() => {
698
+ const content = contentRef.current;
699
+ if (!content || typeof ResizeObserver === "undefined") return;
700
+ const observer = new ResizeObserver(() => {
701
+ scheduleRailSyncEvent();
702
+ if (!followOutput || !followingRef.current) return;
703
+ scrollToEndEvent(reduce || !smooth ? "auto" : "smooth");
704
+ });
705
+ observer.observe(content);
706
+ return () => observer.disconnect();
707
+ }, [
708
+ followOutput,
709
+ reduce,
710
+ smooth
711
+ ]);
712
+ useEffect(() => () => {
713
+ if (scrollTimerRef.current) window.clearTimeout(scrollTimerRef.current);
714
+ if (frameRef.current) cancelAnimationFrame(frameRef.current);
715
+ }, []);
716
+ const viewport = /* @__PURE__ */ jsx("section", {
717
+ ref: setViewportRef,
718
+ "aria-label": label,
719
+ ...restViewportProps,
720
+ onScroll: (event) => {
721
+ handleScroll();
722
+ onViewportScroll?.(event);
723
+ },
724
+ onWheel: (event) => {
725
+ leaveLiveEdge();
726
+ onViewportWheel?.(event);
727
+ },
728
+ onTouchStart: (event) => {
729
+ leaveLiveEdge();
730
+ onViewportTouchStart?.(event);
731
+ },
732
+ onKeyDown: (event) => {
733
+ if ([
734
+ "ArrowUp",
735
+ "PageUp",
736
+ "Home"
737
+ ].includes(event.key)) leaveLiveEdge();
738
+ onViewportKeyDown?.(event);
739
+ },
740
+ className: cn("h-full overflow-y-auto overscroll-contain outline-none [overflow-anchor:none] focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring", navigation === "rail" ? "[-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden" : "[scrollbar-gutter:stable]", viewportClassName, navigation === "rail" && railOverflowing && "pr-10"),
741
+ children: /* @__PURE__ */ jsx("div", {
742
+ ref: contentRef,
743
+ role: "log",
744
+ "aria-live": "polite",
745
+ "aria-relevant": "additions text",
746
+ "aria-busy": busy,
747
+ className: contentClassName,
748
+ ...contentProps,
749
+ children
750
+ })
751
+ });
752
+ return /* @__PURE__ */ jsx("div", {
753
+ "data-slot": "message-scroller",
754
+ className: cn("min-h-0", className),
755
+ ...props,
756
+ children: navigation === "rail" ? /* @__PURE__ */ jsx(PreviewRail, {
757
+ items: railOverflowing ? railItems : [],
758
+ label: navigationLabel,
759
+ activeId: activeRailId,
760
+ onItemSelect: scrollToRailItem,
761
+ previewSide: "before",
762
+ highlightActive: true,
763
+ itemSize: 14,
764
+ className: "h-full min-h-0 overflow-hidden",
765
+ previewContainerClassName: "right-8 left-3",
766
+ previewClassName: "mr-1 w-64 max-w-full [&_[data-slot=preview-rail-card]]:h-20 [&_[data-slot=preview-rail-card]]:overflow-hidden [&_[data-slot=preview-rail-card]]:p-3 [&_[data-slot=preview-rail-title]]:line-clamp-1 [&_[data-slot=preview-rail-title]]:text-xs [&_[data-slot=preview-rail-title]]:leading-4 [&_[data-slot=preview-rail-description]]:line-clamp-2 [&_[data-slot=preview-rail-description]]:text-xs [&_[data-slot=preview-rail-description]]:leading-4",
767
+ railClassName: cn("absolute inset-y-3 right-1 w-7 content-center py-1 [&_[data-slot=preview-rail-item]]:w-7 [&_[data-slot=preview-rail-item]]:justify-end [&_[data-slot=preview-rail-tick]]:h-px [&_[data-slot=preview-rail-tick]]:w-4 [&_[data-slot=preview-rail-tick]]:origin-right", railOverflowing ? "pointer-events-auto opacity-100" : "pointer-events-none opacity-0", railClassName),
768
+ children: viewport
769
+ }) : viewport
770
+ });
771
+ }
772
+ var MessageContext = createContext({ from: "assistant" });
773
+ var MESSAGE_POP_UP = {
774
+ type: "spring",
775
+ stiffness: 480,
776
+ damping: 32,
777
+ mass: 0.62
778
+ };
779
+ function Message({ from, animateIn = false, children, className, initial, animate, transition, exit, style, ...props }) {
780
+ const reduce = useReducedMotion() ?? false;
781
+ const messageContextValue = useMemo(() => ({ from }), [from]);
782
+ return /* @__PURE__ */ jsx(MessageSideContext.Provider, {
783
+ value: from === "user" ? "end" : "start",
784
+ children: /* @__PURE__ */ jsx(MessageContext.Provider, {
785
+ value: messageContextValue,
786
+ children: /* @__PURE__ */ jsx(m.article, {
787
+ "data-slot": "message",
788
+ "data-from": from,
789
+ "aria-label": props["aria-label"] ?? `${from} message`,
790
+ initial: initial ?? (animateIn && !reduce ? {
791
+ opacity: 0,
792
+ transform: "translateY(8px) scale(0.95)"
793
+ } : false),
794
+ animate: animate ?? (animateIn && !reduce ? {
795
+ opacity: 1,
796
+ transform: "translateY(0px) scale(1)"
797
+ } : { opacity: 1 }),
798
+ exit: exit ?? (reduce ? { opacity: 0 } : {
799
+ opacity: 0,
800
+ transform: "translateY(-3px) scale(0.99)"
801
+ }),
802
+ transition: transition ?? (reduce ? { duration: 0.12 } : MESSAGE_POP_UP),
803
+ style: {
804
+ transformOrigin: from === "user" ? "100% 100%" : "0% 100%",
805
+ ...style
806
+ },
807
+ className: cn("group/message flex w-full items-start gap-2", from === "user" ? "flex-row-reverse" : "flex-row", className),
808
+ ...props,
809
+ children
810
+ })
811
+ })
812
+ });
813
+ }
814
+ function MessageContent({ className, ...props }) {
815
+ const { from } = useContext(MessageContext);
816
+ return /* @__PURE__ */ jsx("div", {
817
+ "data-slot": "message-content",
818
+ className: cn("flex min-w-0 flex-1 flex-col gap-1.5", from === "user" ? "items-end" : "items-start", className),
819
+ ...props
820
+ });
821
+ }
822
+ function ImageLightbox({ open, onClose, images, initialIndex = 0 }) {
823
+ const [currentIndex, setCurrentIndex] = useState(initialIndex);
824
+ const hasMultipleImages = images.length > 1;
825
+ useEffect(() => {
826
+ if (open) setCurrentIndex(initialIndex);
827
+ }, [open, initialIndex]);
828
+ const goToPrevious = useCallback((event) => {
829
+ event?.stopPropagation();
830
+ setCurrentIndex((prev) => prev > 0 ? prev - 1 : images.length - 1);
831
+ }, [images.length]);
832
+ const goToNext = useCallback((event) => {
833
+ event?.stopPropagation();
834
+ setCurrentIndex((prev) => prev < images.length - 1 ? prev + 1 : 0);
835
+ }, [images.length]);
836
+ const onLightboxKeyDown = useEffectEvent((event) => {
837
+ switch (event.key) {
838
+ case "ArrowLeft":
839
+ event.preventDefault();
840
+ if (hasMultipleImages) goToPrevious();
841
+ break;
842
+ case "ArrowRight":
843
+ event.preventDefault();
844
+ if (hasMultipleImages) goToNext();
845
+ }
846
+ });
847
+ useEffect(() => {
848
+ if (!open) return;
849
+ const handler = (event) => onLightboxKeyDown(event);
850
+ window.addEventListener("keydown", handler, true);
851
+ return () => window.removeEventListener("keydown", handler, true);
852
+ }, [open]);
853
+ useEffect(() => {
854
+ if (!open) return;
855
+ const previousOverflow = document.body.style.overflow;
856
+ document.body.style.overflow = "hidden";
857
+ return () => {
858
+ document.body.style.overflow = previousOverflow;
859
+ };
860
+ }, [open]);
861
+ const dialogRef = useRef(null);
862
+ const onLightDismiss = useEffectEvent((event) => {
863
+ if (dialogRef.current && event.target === dialogRef.current) onClose();
864
+ });
865
+ useEffect(() => {
866
+ if (!open) return;
867
+ const dialog = dialogRef.current;
868
+ if (!dialog) return;
869
+ if (!dialog.open) dialog.showModal();
870
+ const handler = (event) => onLightDismiss(event);
871
+ dialog.addEventListener("click", handler);
872
+ return () => {
873
+ dialog.removeEventListener("click", handler);
874
+ if (dialog.open) dialog.close();
875
+ };
876
+ }, [open]);
877
+ if (typeof document === "undefined") return null;
878
+ if (!open) return null;
879
+ const currentImage = images[currentIndex] ?? images[0];
880
+ if (!currentImage?.url) return null;
881
+ return createPortal(/* @__PURE__ */ jsxs("dialog", {
882
+ ref: dialogRef,
883
+ "aria-label": "Image viewer",
884
+ onClose: () => onClose(),
885
+ className: "fixed inset-0 z-50 m-0 flex h-full max-h-none w-full max-w-none items-center justify-center border-0 bg-black/90 p-0 backdrop:bg-transparent",
886
+ children: [
887
+ /* @__PURE__ */ jsx("button", {
888
+ type: "button",
889
+ onClick: onClose,
890
+ "aria-label": "Close fullscreen (Esc)",
891
+ className: "absolute top-4 right-4 z-10 inline-flex size-9 items-center justify-center rounded-full bg-black/50 text-white transition-colors hover:bg-black/70",
892
+ children: /* @__PURE__ */ jsx(X, { className: "size-5" })
893
+ }),
894
+ hasMultipleImages && /* @__PURE__ */ jsx("button", {
895
+ type: "button",
896
+ onClick: goToPrevious,
897
+ "aria-label": "Previous image (\u2190)",
898
+ className: "absolute top-1/2 left-4 z-10 inline-flex size-10 -translate-y-1/2 items-center justify-center rounded-full bg-black/50 text-white transition-colors hover:bg-black/70",
899
+ children: /* @__PURE__ */ jsx(ChevronLeft, { className: "size-6" })
900
+ }),
901
+ /* @__PURE__ */ jsx("img", {
902
+ src: currentImage.url,
903
+ alt: currentImage.filename ?? "Image preview",
904
+ className: "max-h-[85vh] max-w-[90vw] object-contain select-none",
905
+ onClick: (event) => event.stopPropagation(),
906
+ draggable: false
907
+ }),
908
+ hasMultipleImages && /* @__PURE__ */ jsx("button", {
909
+ type: "button",
910
+ onClick: goToNext,
911
+ "aria-label": "Next image (\u2192)",
912
+ className: "absolute top-1/2 right-4 z-10 inline-flex size-10 -translate-y-1/2 items-center justify-center rounded-full bg-black/50 text-white transition-colors hover:bg-black/70",
913
+ children: /* @__PURE__ */ jsx(ChevronRight, { className: "size-6" })
914
+ }),
915
+ hasMultipleImages && /* @__PURE__ */ jsxs("div", {
916
+ className: "absolute bottom-6 left-1/2 flex -translate-x-1/2 flex-col items-center gap-3",
917
+ children: [/* @__PURE__ */ jsx("div", {
918
+ className: "flex gap-2",
919
+ children: images.map((image, idx) => /* @__PURE__ */ jsx("button", {
920
+ type: "button",
921
+ onClick: (event) => {
922
+ event.stopPropagation();
923
+ setCurrentIndex(idx);
924
+ },
925
+ "aria-label": `Go to image ${idx + 1}`,
926
+ className: cn("size-2 rounded-full transition-all", idx === currentIndex ? "scale-125 bg-white" : "bg-white/40 hover:bg-white/60")
927
+ }, image.url))
928
+ }), /* @__PURE__ */ jsxs("span", {
929
+ className: "text-sm text-white/70",
930
+ children: [
931
+ currentIndex + 1,
932
+ " / ",
933
+ images.length
934
+ ]
935
+ })]
936
+ })
937
+ ]
938
+ }), document.body);
939
+ }
940
+ function formatFileSize(bytes) {
941
+ if (bytes < 1024) return `${bytes} B`;
942
+ if (bytes < 1048576) return `${(bytes / 1024).toFixed(1)} KB`;
943
+ return `${(bytes / 1048576).toFixed(1)} MB`;
944
+ }
945
+ function getFileIconName(filename, isImage) {
946
+ if (isImage) return "image";
947
+ const ext = filename.split(".").pop()?.toLowerCase();
948
+ if ([
949
+ "js",
950
+ "ts",
951
+ "jsx",
952
+ "tsx",
953
+ "py",
954
+ "rb",
955
+ "go",
956
+ "rs",
957
+ "java",
958
+ "kt",
959
+ "swift",
960
+ "c",
961
+ "cpp",
962
+ "h",
963
+ "hpp",
964
+ "cs",
965
+ "php"
966
+ ].includes(ext || "")) return "code";
967
+ if ([
968
+ "json",
969
+ "yaml",
970
+ "yml",
971
+ "xml"
972
+ ].includes(ext || "")) return "data";
973
+ return "text";
974
+ }
975
+ function renderFileIcon(iconName) {
976
+ switch (iconName) {
977
+ case "image":
978
+ return /* @__PURE__ */ jsx(Image, { className: "size-4 text-muted-foreground" });
979
+ case "code":
980
+ return /* @__PURE__ */ jsx(FileCode, { className: "size-4 text-muted-foreground" });
981
+ case "data":
982
+ return /* @__PURE__ */ jsx(FileBraces, { className: "size-4 text-muted-foreground" });
983
+ default:
984
+ return /* @__PURE__ */ jsx(FileText, { className: "size-4 text-muted-foreground" });
985
+ }
986
+ }
987
+ function FileAttachment({ id, filename, size, isImage, url, onRemove, className, display = "chip", enableImagePreview = true }) {
988
+ const [isHovered, setIsHovered] = useState(false);
989
+ const [isLightboxOpen, setIsLightboxOpen] = useState(false);
990
+ const iconName = getFileIconName(filename, isImage);
991
+ const isImageOnly = display === "image-only" && isImage && !!url;
992
+ const canPreview = Boolean(enableImagePreview && isImage && url);
993
+ const openLightbox = (event) => {
994
+ event?.stopPropagation();
995
+ setIsLightboxOpen(true);
996
+ };
997
+ return /* @__PURE__ */ jsxs("div", {
998
+ className: cn("relative rounded-[calc(var(--an-input-border-radius)-var(--an-context-padding))] bg-muted/50", isImageOnly ? "flex size-10 items-center justify-center" : "flex max-w-[200px] min-w-[120px] items-center gap-2 py-1 pr-2 pl-1", className),
999
+ onMouseEnter: () => setIsHovered(true),
1000
+ onMouseLeave: () => setIsHovered(false),
1001
+ children: [
1002
+ isImageOnly ? /* @__PURE__ */ jsx("div", {
1003
+ className: cn("size-8 shrink-0 overflow-hidden rounded-[calc(var(--an-input-border-radius)-var(--an-context-padding)-2px)]", canPreview && "cursor-pointer"),
1004
+ onClick: canPreview ? openLightbox : void 0,
1005
+ role: canPreview ? "button" : void 0,
1006
+ tabIndex: canPreview ? 0 : void 0,
1007
+ "aria-label": canPreview ? `Preview ${filename}` : void 0,
1008
+ onKeyDown: canPreview ? (event) => {
1009
+ if (event.key === "Enter" || event.key === " ") {
1010
+ event.preventDefault();
1011
+ openLightbox();
1012
+ }
1013
+ } : void 0,
1014
+ children: /* @__PURE__ */ jsx("img", {
1015
+ src: url,
1016
+ alt: filename,
1017
+ className: "h-full w-full object-cover"
1018
+ })
1019
+ }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [isImage && url ? /* @__PURE__ */ jsx("div", {
1020
+ className: cn("w-8 shrink-0 self-stretch overflow-hidden rounded-[calc(var(--an-input-border-radius)-var(--an-context-padding)-2px)]", canPreview && "cursor-pointer"),
1021
+ onClick: canPreview ? openLightbox : void 0,
1022
+ role: canPreview ? "button" : void 0,
1023
+ tabIndex: canPreview ? 0 : void 0,
1024
+ "aria-label": canPreview ? `Preview ${filename}` : void 0,
1025
+ onKeyDown: canPreview ? (event) => {
1026
+ if (event.key === "Enter" || event.key === " ") {
1027
+ event.preventDefault();
1028
+ openLightbox();
1029
+ }
1030
+ } : void 0,
1031
+ children: /* @__PURE__ */ jsx("img", {
1032
+ src: url,
1033
+ alt: filename,
1034
+ className: "aspect-square h-full w-full object-cover"
1035
+ })
1036
+ }) : /* @__PURE__ */ jsx("div", {
1037
+ className: "flex w-8 shrink-0 items-center justify-center self-stretch rounded-[calc(var(--an-input-border-radius)-var(--an-context-padding)-2px)] bg-muted",
1038
+ children: renderFileIcon(iconName)
1039
+ }), /* @__PURE__ */ jsxs("div", {
1040
+ className: "flex min-w-0 flex-col",
1041
+ children: [/* @__PURE__ */ jsx("span", {
1042
+ className: "truncate text-sm font-medium text-foreground",
1043
+ title: filename,
1044
+ children: filename
1045
+ }), size !== void 0 && /* @__PURE__ */ jsx("span", {
1046
+ className: "text-[10px] text-muted-foreground",
1047
+ children: formatFileSize(size)
1048
+ })]
1049
+ })] }),
1050
+ onRemove && /* @__PURE__ */ jsx("button", {
1051
+ onClick: (e) => {
1052
+ e.stopPropagation();
1053
+ onRemove();
1054
+ },
1055
+ "aria-label": `Remove ${filename}`,
1056
+ className: `absolute -top-1.5 -right-1.5 z-10 flex size-4 items-center justify-center rounded-full border border-border bg-background text-muted-foreground transition-[opacity,transform] duration-150 ease-out hover:text-foreground active:scale-[0.97] ${isHovered ? "opacity-100" : "opacity-0"}`,
1057
+ type: "button",
1058
+ children: /* @__PURE__ */ jsx(X, { className: "size-3" })
1059
+ }),
1060
+ canPreview && url && /* @__PURE__ */ jsx(ImageLightbox, {
1061
+ open: isLightboxOpen,
1062
+ onClose: () => setIsLightboxOpen(false),
1063
+ images: [{
1064
+ id,
1065
+ url,
1066
+ filename
1067
+ }]
1068
+ })
1069
+ ]
1070
+ });
1071
+ }
1072
+ function isRecord$2(value) {
1073
+ return typeof value === "object" && value !== null;
1074
+ }
1075
+ function isTextPart(part) {
1076
+ return isRecord$2(part) && part.type === "text" && typeof part.text === "string";
1077
+ }
1078
+ function isErrorPart(part) {
1079
+ return isRecord$2(part) && part.type === "error" && typeof part.message === "string";
1080
+ }
1081
+ function isPayloadPart(part) {
1082
+ return isRecord$2(part) && part.type === "payload" && typeof part.kind === "string" && typeof part.title === "string";
1083
+ }
1084
+ function isV5ToolPart(part) {
1085
+ if (!isRecord$2(part)) return false;
1086
+ const partType = part.type;
1087
+ return partType === "dynamic-tool" || typeof partType === "string" && partType.startsWith("tool-");
1088
+ }
1089
+ function getTextFromParts(parts, joiner) {
1090
+ const texts = [];
1091
+ for (const part of parts) if (isTextPart(part)) texts.push(part.text);
1092
+ return texts.join(joiner);
1093
+ }
1094
+ function isRecord$1(value) {
1095
+ return typeof value === "object" && value !== null;
1096
+ }
1097
+ function getImageUrlFromPart(part) {
1098
+ if (!isRecord$1(part)) return null;
1099
+ const type = part.type;
1100
+ if (typeof type !== "string") return null;
1101
+ if (type === "image") {
1102
+ const imagePart = part;
1103
+ return imagePart.url ?? imagePart.image ?? null;
1104
+ }
1105
+ if (type === "data-image") return part.data?.url ?? null;
1106
+ if (type === "file") {
1107
+ const filePart = part;
1108
+ if (filePart.mimeType?.startsWith("image/")) {
1109
+ if (filePart.url) return filePart.url;
1110
+ if (filePart.data) return `data:${filePart.mimeType};base64,${filePart.data}`;
1111
+ }
1112
+ }
1113
+ return null;
1114
+ }
1115
+ function getFileFromPart(part) {
1116
+ if (!isRecord$1(part)) return null;
1117
+ if (part.type !== "file") return null;
1118
+ const filePart = part;
1119
+ const filename = filePart.filename || filePart.name || filePart.fileName || "Attachment";
1120
+ if (filePart.mimeType?.startsWith("image/") ?? false) return null;
1121
+ return {
1122
+ filename,
1123
+ size: filePart.size
1124
+ };
1125
+ }
1126
+ var UserMessage = memo(function UserMessage2({ message, className, enableImagePreview = true }) {
1127
+ const [lightboxIndex, setLightboxIndex] = useState(null);
1128
+ const text = (message.parts?.filter(isTextPart) ?? []).map((p) => p.text).join("");
1129
+ const images = [];
1130
+ const files = [];
1131
+ for (const part of message.parts ?? []) {
1132
+ const imageUrl = getImageUrlFromPart(part);
1133
+ if (imageUrl) images.push(imageUrl);
1134
+ const file = getFileFromPart(part);
1135
+ if (file) files.push(file);
1136
+ }
1137
+ if (isRecord$1(message) && Array.isArray(message.experimental_attachments)) {
1138
+ for (const att of message.experimental_attachments) if (att.contentType?.startsWith("image/") && att.url) images.push(att.url);
1139
+ }
1140
+ if (!text && images.length === 0 && files.length === 0) return null;
1141
+ const lightboxImages = images.map((url, i) => ({
1142
+ id: `${message.id}-img-${i}`,
1143
+ url,
1144
+ filename: `image-${i + 1}`
1145
+ }));
1146
+ return /* @__PURE__ */ jsxs("div", {
1147
+ className: cn("flex flex-col items-end gap-1", className),
1148
+ children: [
1149
+ images.length > 0 && images.map((url, i) => /* @__PURE__ */ jsx("div", {
1150
+ className: cn("max-w-[200px] rounded-an-message bg-an-foreground/4 p-1.5", enableImagePreview && "cursor-pointer"),
1151
+ onClick: enableImagePreview ? () => setLightboxIndex(i) : void 0,
1152
+ role: enableImagePreview ? "button" : void 0,
1153
+ tabIndex: enableImagePreview ? 0 : void 0,
1154
+ onKeyDown: enableImagePreview ? (event) => {
1155
+ if (event.key === "Enter" || event.key === " ") {
1156
+ event.preventDefault();
1157
+ setLightboxIndex(i);
1158
+ }
1159
+ } : void 0,
1160
+ children: /* @__PURE__ */ jsx("img", {
1161
+ src: url,
1162
+ alt: "attachment",
1163
+ className: "block max-h-[120px] max-w-[184px] rounded-an-message-inner object-cover"
1164
+ })
1165
+ }, url)),
1166
+ enableImagePreview && lightboxImages.length > 0 && /* @__PURE__ */ jsx(ImageLightbox, {
1167
+ open: lightboxIndex !== null,
1168
+ onClose: () => setLightboxIndex(null),
1169
+ images: lightboxImages,
1170
+ initialIndex: lightboxIndex ?? 0
1171
+ }),
1172
+ files.length > 0 && /* @__PURE__ */ jsx("div", {
1173
+ className: "flex flex-col items-end gap-2",
1174
+ children: files.map((file, i) => /* @__PURE__ */ jsx(FileAttachment, {
1175
+ id: `${file.filename}-${i}`,
1176
+ filename: file.filename,
1177
+ size: file.size
1178
+ }, `${file.filename}-${file.size}`))
1179
+ }),
1180
+ text && /* @__PURE__ */ jsx("div", {
1181
+ className: "ms-[70px] max-w-[calc(95%-40px)]",
1182
+ children: /* @__PURE__ */ jsx("div", {
1183
+ className: "rounded-an-message bg-an-user-message-bg px-3.5 py-1.5 text-sm text-an-user-message-text transition-colors",
1184
+ children: /* @__PURE__ */ jsx("p", {
1185
+ className: "leading-5 wrap-break-word whitespace-pre-wrap",
1186
+ children: text
1187
+ })
1188
+ })
1189
+ })
1190
+ ]
1191
+ });
1192
+ });
1193
+ var ErrorMessage = memo(function ErrorMessage2({ title = "Something went wrong", message, className }) {
1194
+ return /* @__PURE__ */ jsx("div", {
1195
+ className: cn("flex justify-start", className),
1196
+ children: /* @__PURE__ */ jsxs("div", {
1197
+ className: "rounded-[8px] border border-red-500/30 bg-red-500/10 px-4 py-2.5 text-sm text-an-foreground",
1198
+ children: [/* @__PURE__ */ jsx("div", {
1199
+ className: "font-medium text-an-foreground",
1200
+ children: title
1201
+ }), /* @__PURE__ */ jsx("div", {
1202
+ className: "mt-0.5 text-an-foreground-muted",
1203
+ children: message
1204
+ })]
1205
+ })
1206
+ });
1207
+ });
1208
+ function formatPayload(value) {
1209
+ if (typeof value === "string") return value;
1210
+ if (value === void 0) return "";
1211
+ try {
1212
+ return JSON.stringify(value, null, 2) ?? "";
1213
+ } catch {
1214
+ return String(value);
1215
+ }
1216
+ }
1217
+ function PayloadPart({ part }) {
1218
+ const payload = formatPayload(part.payload);
1219
+ return /* @__PURE__ */ jsxs("section", {
1220
+ "data-payload-kind": part.kind,
1221
+ className: "w-full min-w-0 overflow-hidden rounded-xl border border-border/60 bg-muted/40 text-sm",
1222
+ children: [
1223
+ /* @__PURE__ */ jsx("div", {
1224
+ className: "border-b border-border/50 px-3 py-2 text-xs font-medium text-muted-foreground",
1225
+ children: part.title
1226
+ }),
1227
+ part.text ? /* @__PURE__ */ jsx("pre", {
1228
+ className: "m-0 whitespace-pre-wrap break-words px-3 py-3 font-mono text-xs leading-5 text-foreground/80",
1229
+ children: part.text
1230
+ }) : null,
1231
+ payload ? /* @__PURE__ */ jsxs("details", {
1232
+ open: true,
1233
+ className: "border-t border-border/50 px-3 py-2",
1234
+ children: [/* @__PURE__ */ jsx("summary", {
1235
+ className: "cursor-pointer text-xs font-medium text-muted-foreground",
1236
+ children: "Payload"
1237
+ }), /* @__PURE__ */ jsx("pre", {
1238
+ className: "m-0 mt-2 max-w-full whitespace-pre-wrap break-words font-mono text-xs leading-5 text-foreground/70",
1239
+ children: payload
1240
+ })]
1241
+ }) : null
1242
+ ]
1243
+ });
1244
+ }
1245
+ function isRecord(value) {
1246
+ return typeof value === "object" && value !== null;
1247
+ }
1248
+ function parseStructuredJson(value) {
1249
+ if (typeof value !== "string") return value;
1250
+ const trimmed = value.trim();
1251
+ if (!trimmed) return value;
1252
+ try {
1253
+ const parsed = JSON.parse(trimmed);
1254
+ return isRecord(parsed) || Array.isArray(parsed) ? parsed : value;
1255
+ } catch {
1256
+ return value;
1257
+ }
1258
+ }
1259
+ function normalizeToolPart(part) {
1260
+ if (!isRecord(part)) return part;
1261
+ if (typeof part.type !== "string" || !part.type.startsWith("tool-")) return part;
1262
+ const normalizedInput = parseStructuredJson(part.input);
1263
+ const normalizedOutput = parseStructuredJson(part.output);
1264
+ const normalizedResult = parseStructuredJson(part.result);
1265
+ const inputChanged = normalizedInput !== part.input;
1266
+ const outputChanged = normalizedOutput !== part.output;
1267
+ const resultChanged = normalizedResult !== part.result;
1268
+ if (!inputChanged && !outputChanged && !resultChanged) return part;
1269
+ const normalizedPart = { ...part };
1270
+ if (inputChanged) normalizedPart.input = normalizedInput;
1271
+ if (outputChanged) normalizedPart.output = normalizedOutput;
1272
+ if (resultChanged) normalizedPart.result = normalizedResult;
1273
+ return normalizedPart;
1274
+ }
1275
+ function normalizeAssistantToolParts(parts) {
1276
+ let changed = false;
1277
+ const normalizedParts = parts.map((part) => {
1278
+ const normalizedPart = normalizeToolPart(part);
1279
+ if (normalizedPart !== part) changed = true;
1280
+ return normalizedPart;
1281
+ });
1282
+ return changed ? normalizedParts : parts;
1283
+ }
1284
+ var timeFormatter = new Intl.DateTimeFormat("en-US", {
1285
+ hour: "numeric",
1286
+ minute: "2-digit",
1287
+ hour12: true
1288
+ });
1289
+ var dateFormatter = new Intl.DateTimeFormat("en-US", {
1290
+ month: "short",
1291
+ day: "numeric"
1292
+ });
1293
+ function formatTimestamp(date) {
1294
+ const now = /* @__PURE__ */ new Date();
1295
+ if (date.getFullYear() === now.getFullYear() && date.getMonth() === now.getMonth() && date.getDate() === now.getDate()) return timeFormatter.format(date);
1296
+ return dateFormatter.format(date);
1297
+ }
1298
+ function CopyButton({ text, onCopied }) {
1299
+ const [copied, setCopied] = useState(false);
1300
+ const copiedTimerRef = useRef(null);
1301
+ useEffect(() => {
1302
+ return () => {
1303
+ if (copiedTimerRef.current) window.clearTimeout(copiedTimerRef.current);
1304
+ };
1305
+ }, []);
1306
+ const handleCopy = async () => {
1307
+ try {
1308
+ await navigator.clipboard.writeText(text);
1309
+ setCopied(true);
1310
+ if (copiedTimerRef.current) window.clearTimeout(copiedTimerRef.current);
1311
+ copiedTimerRef.current = window.setTimeout(() => {
1312
+ setCopied(false);
1313
+ copiedTimerRef.current = null;
1314
+ }, 2e3);
1315
+ notify.success("Copied to clipboard");
1316
+ onCopied?.();
1317
+ } catch {
1318
+ notify.error("Failed to copy to clipboard");
1319
+ }
1320
+ };
1321
+ return /* @__PURE__ */ jsx("button", {
1322
+ type: "button",
1323
+ tabIndex: -1,
1324
+ "aria-label": copied ? "Copied" : "Copy message",
1325
+ onClick: handleCopy,
1326
+ onPointerDown: (event) => {
1327
+ event.stopPropagation();
1328
+ },
1329
+ onMouseDown: (event) => event.stopPropagation(),
1330
+ className: cn("flex size-6 items-center justify-center rounded-md transition-[background-color,opacity,transform] duration-150 ease-out active:scale-[0.97]", "bg-transparent opacity-50 hover:bg-an-foreground/10 hover:opacity-100"),
1331
+ children: /* @__PURE__ */ jsxs("div", {
1332
+ className: "relative h-3.5 w-3.5",
1333
+ children: [/* @__PURE__ */ jsx(Copy, { className: cn("absolute inset-0 h-3.5 w-3.5 text-an-foreground-muted transition-[opacity,transform] duration-150 ease-out", copied ? "scale-50 opacity-0" : "scale-100 opacity-100") }), /* @__PURE__ */ jsx(Check, { className: cn("absolute inset-0 h-3.5 w-3.5 text-an-foreground-muted transition-[opacity,transform] duration-150 ease-out", copied ? "scale-100 opacity-100" : "scale-50 opacity-0") })]
1334
+ })
1335
+ });
1336
+ }
1337
+ function MessageToolbar({ text, timestamp, heightClass, hoverClass, isVisible, alignClass, onCopied }) {
1338
+ return /* @__PURE__ */ jsxs("div", {
1339
+ className: cn("pointer-events-none flex items-center gap-1 pt-1 text-xs text-an-foreground-muted/70 opacity-0 transition-opacity duration-100", heightClass, alignClass, hoverClass, isVisible && "pointer-events-auto opacity-100"),
1340
+ onMouseDown: (event) => event.stopPropagation(),
1341
+ onPointerDown: (event) => event.stopPropagation(),
1342
+ children: [timestamp && /* @__PURE__ */ jsx("span", { children: timestamp }), text && /* @__PURE__ */ jsx(CopyButton, {
1343
+ text,
1344
+ onCopied
1345
+ })]
1346
+ });
1347
+ }
1348
+ memo(function UserTurn(props) {
1349
+ const { message, UserMessageComponent, userMessageClassName, onCopied, display } = props;
1350
+ const { enableImagePreview, showCopyToolbar, isMounted, isCopyVisible } = display;
1351
+ const text = getTextFromParts(message.parts ?? [], "");
1352
+ const hasParts = (message.parts ?? []).length > 0;
1353
+ if (!text && !hasParts) return null;
1354
+ const userCreatedAt = message?.createdAt;
1355
+ const userCopyKey = `user-${message.id}`;
1356
+ const userTimestamp = isMounted && userCreatedAt ? formatTimestamp(new Date(userCreatedAt)) : void 0;
1357
+ return /* @__PURE__ */ jsxs("div", {
1358
+ className: "group/user-message",
1359
+ children: [/* @__PURE__ */ jsx(UserMessageComponent, {
1360
+ message,
1361
+ className: userMessageClassName,
1362
+ enableImagePreview
1363
+ }), (showCopyToolbar && Boolean(text) || Boolean(userTimestamp)) && /* @__PURE__ */ jsx(MessageToolbar, {
1364
+ text: showCopyToolbar ? text : "",
1365
+ timestamp: userTimestamp,
1366
+ heightClass: "h-[28px]",
1367
+ hoverClass: "group-hover/user-message:opacity-100 group-hover/user-message:pointer-events-auto",
1368
+ isVisible: isCopyVisible,
1369
+ alignClass: "justify-end",
1370
+ onCopied: () => onCopied(userCopyKey)
1371
+ })]
1372
+ });
1373
+ });
1374
+ memo(function AssistantTurn(props) {
1375
+ const { assistantMsgs, turnKey, ToolRendererComponent, TextRendererComponent, toolRenderers, onOpenUIAction, onOpenUIArtifactReady, onOpenArtifact, onCopied, stream, copy, display } = props;
1376
+ const { isLast: isLastTurn, isStreaming } = stream;
1377
+ const { enabled: showCopyToolbar, isVisible: isCopyVisible } = copy;
1378
+ const { suppressQuestionTool } = display;
1379
+ const assistantText = getTextFromParts(assistantMsgs.flatMap((msg) => msg.parts ?? []), "\n\n");
1380
+ const isTurnStreaming = isStreaming && isLastTurn;
1381
+ const showToolbar = showCopyToolbar && Boolean(assistantText.trim()) && !isTurnStreaming;
1382
+ const copyKey = `assistant-${turnKey}-all`;
1383
+ const toolbarText = showCopyToolbar ? assistantText : "";
1384
+ return /* @__PURE__ */ jsxs("div", {
1385
+ className: "group/assistant-turn",
1386
+ children: [/* @__PURE__ */ jsx("div", {
1387
+ className: "flex flex-col gap-3",
1388
+ children: assistantMsgs.map((msg, i) => {
1389
+ const isLastMsg = isLastTurn && i === assistantMsgs.length - 1;
1390
+ return /* @__PURE__ */ jsx(AssistantParts, {
1391
+ msg,
1392
+ isLast: isLastMsg,
1393
+ isStreaming,
1394
+ suppressQuestionTool,
1395
+ ToolRendererComponent,
1396
+ TextRendererComponent,
1397
+ toolRenderers,
1398
+ onOpenUIAction,
1399
+ onOpenUIArtifactReady,
1400
+ onOpenArtifact
1401
+ }, msg.id);
1402
+ })
1403
+ }), (showToolbar || isCopyVisible) && /* @__PURE__ */ jsx(MessageToolbar, {
1404
+ text: toolbarText,
1405
+ heightClass: "h-[48px] flex items-start w-full",
1406
+ hoverClass: "group-hover/assistant-turn:opacity-100 group-hover/assistant-turn:pointer-events-auto",
1407
+ isVisible: isCopyVisible,
1408
+ alignClass: "justify-start",
1409
+ onCopied: () => onCopied(copyKey)
1410
+ })]
1411
+ });
1412
+ });
1413
+ var TOOL_CALL_KEY_PREFIX = "tool-call:";
1414
+ var UNKEYED_TOOL_KEY_PREFIX = "unkeyed-tool:";
1415
+ function getAssistantToolElementKey(messageId, part, occurrence) {
1416
+ if (part.toolCallId) return `${TOOL_CALL_KEY_PREFIX}${part.toolCallId}`;
1417
+ return `${UNKEYED_TOOL_KEY_PREFIX}${messageId}:${part.type}:${occurrence}`;
1418
+ }
1419
+ function buildAssistantElements(parts, opts) {
1420
+ const { messageId, isLast, isStreaming, suppressQuestionTool, suppressTextWhenPlanWrite = false, ToolRendererComponent, TextRendererComponent, toolRenderers, onOpenUIAction, onOpenUIArtifactReady, onOpenArtifact } = opts;
1421
+ const elems = [];
1422
+ const textChunks = [];
1423
+ const hasPlanWritePresentation = suppressTextWhenPlanWrite && parts.some((part) => isV5ToolPart(part) && part.type === "tool-PlanWrite");
1424
+ const taskPartIds = new Set(parts.filter((p) => isV5ToolPart(p) && (p.type === "tool-Task" || p.type === "tool-Agent") && typeof p.toolCallId === "string").map((p) => p.toolCallId));
1425
+ const nestedToolsMap = /* @__PURE__ */ new Map();
1426
+ const nestedToolIds = /* @__PURE__ */ new Set();
1427
+ const unkeyedToolOccurrences = /* @__PURE__ */ new Map();
1428
+ for (const part of parts) {
1429
+ if (!isV5ToolPart(part)) continue;
1430
+ if (part.type === "tool-TaskOutput") continue;
1431
+ if (!part.toolCallId || !part.toolCallId.includes(":")) continue;
1432
+ const parentId = part.toolCallId.split(":")[0];
1433
+ if (!taskPartIds.has(parentId)) continue;
1434
+ if (!nestedToolsMap.has(parentId)) nestedToolsMap.set(parentId, []);
1435
+ nestedToolsMap.get(parentId).push(part);
1436
+ nestedToolIds.add(part.toolCallId);
1437
+ }
1438
+ let i = 0;
1439
+ while (i < parts.length) {
1440
+ const part = parts[i];
1441
+ if (isV5ToolPart(part) && part.type === "tool-TaskOutput") {
1442
+ i++;
1443
+ continue;
1444
+ }
1445
+ if (isTextPart(part)) {
1446
+ const text2 = part.text;
1447
+ if (text2 && !hasPlanWritePresentation) textChunks.push(text2);
1448
+ i++;
1449
+ continue;
1450
+ }
1451
+ if (isErrorPart(part)) {
1452
+ elems.push(/* @__PURE__ */ jsx(ErrorMessage, {
1453
+ title: part.title,
1454
+ message: part.message
1455
+ }, `${messageId}-error-${part.title}-${part.message}`));
1456
+ i++;
1457
+ continue;
1458
+ }
1459
+ if (isPayloadPart(part)) {
1460
+ elems.push(/* @__PURE__ */ jsx(PayloadPart, { part }, `${messageId}-payload-${i}`));
1461
+ i++;
1462
+ continue;
1463
+ }
1464
+ if (isV5ToolPart(part)) {
1465
+ if (suppressQuestionTool && part.type === "tool-Question") {
1466
+ i++;
1467
+ continue;
1468
+ }
1469
+ if (part.toolCallId && nestedToolIds.has(part.toolCallId)) {
1470
+ i++;
1471
+ continue;
1472
+ }
1473
+ const chatStreamingStatus = isLast && isStreaming ? "streaming" : void 0;
1474
+ const toolCallId = part.toolCallId;
1475
+ const nestedTools = (part.type === "tool-Task" || part.type === "tool-Agent") && toolCallId ? nestedToolsMap.get(toolCallId) || [] : void 0;
1476
+ const occurrence = part.toolCallId ? 0 : unkeyedToolOccurrences.get(part.type) ?? 0;
1477
+ if (!part.toolCallId) unkeyedToolOccurrences.set(part.type, occurrence + 1);
1478
+ elems.push(/* @__PURE__ */ jsx(ToolRendererComponent, {
1479
+ part,
1480
+ nestedTools,
1481
+ chatStatus: chatStreamingStatus,
1482
+ toolRenderers
1483
+ }, getAssistantToolElementKey(messageId, part, occurrence)));
1484
+ i++;
1485
+ continue;
1486
+ }
1487
+ i++;
1488
+ }
1489
+ const text = textChunks.join("\n\n");
1490
+ if (text) elems.push(/* @__PURE__ */ jsx("div", {
1491
+ className: "group/assistant-text text-[14px]",
1492
+ children: /* @__PURE__ */ jsx(TextRendererComponent, {
1493
+ content: text,
1494
+ isStreaming,
1495
+ messageId,
1496
+ onOpenUIAction,
1497
+ onOpenUIArtifactReady,
1498
+ onOpenArtifact,
1499
+ className: "leading-relaxed [&_p]:leading-relaxed"
1500
+ })
1501
+ }, `${messageId}-text-final`));
1502
+ return elems;
1503
+ }
1504
+ function AssistantParts({ msg, isLast, isStreaming, suppressQuestionTool, ToolRendererComponent, TextRendererComponent, toolRenderers, onOpenUIAction, onOpenUIArtifactReady, onOpenArtifact }) {
1505
+ const parts = useMemo(() => normalizeAssistantToolParts(msg.parts ?? []), [msg.parts]);
1506
+ const elements = useMemo(() => buildAssistantElements(parts, {
1507
+ messageId: msg.id,
1508
+ isLast,
1509
+ isStreaming,
1510
+ suppressQuestionTool,
1511
+ ToolRendererComponent,
1512
+ TextRendererComponent,
1513
+ toolRenderers,
1514
+ onOpenUIAction,
1515
+ onOpenUIArtifactReady,
1516
+ onOpenArtifact
1517
+ }), [
1518
+ parts,
1519
+ msg.id,
1520
+ isLast,
1521
+ isStreaming,
1522
+ suppressQuestionTool,
1523
+ ToolRendererComponent,
1524
+ TextRendererComponent,
1525
+ toolRenderers,
1526
+ onOpenUIAction,
1527
+ onOpenUIArtifactReady,
1528
+ onOpenArtifact
1529
+ ]);
1530
+ if (elements.length > 1) return /* @__PURE__ */ jsx("div", {
1531
+ className: "group/assistant-turn flex flex-col gap-3",
1532
+ children: elements
1533
+ });
1534
+ return /* @__PURE__ */ jsx("div", {
1535
+ className: "group/assistant-turn",
1536
+ children: elements
1537
+ });
1538
+ }
1539
+ function orderedRlmChildren(children, tree) {
1540
+ const byId = new Map(children.map((child) => [child.id, child]));
1541
+ const visited = /* @__PURE__ */ new Set();
1542
+ const ordered = [];
1543
+ const visit = (id) => {
1544
+ if (visited.has(id)) return;
1545
+ visited.add(id);
1546
+ const child = byId.get(id);
1547
+ if (child) ordered.push(child);
1548
+ for (const nextId of tree?.nodes[id]?.childrenIds ?? []) visit(nextId);
1549
+ };
1550
+ for (const id of tree?.rootChildrenIds ?? []) visit(id);
1551
+ for (const child of children) visit(child.id);
1552
+ return ordered;
1553
+ }
1554
+ function rlmStatusIcon(status2) {
1555
+ if (status2 === "done") return /* @__PURE__ */ jsx(CircleCheck, { className: "size-3.5 text-emerald-600 dark:text-emerald-400" });
1556
+ if (status2 === "error" || status2 === "failed") return /* @__PURE__ */ jsx(CircleAlert, { className: "size-3.5 text-destructive" });
1557
+ if (status2 === "cancelled") return /* @__PURE__ */ jsx(CircleX, { className: "size-3.5 text-muted-foreground" });
1558
+ if (status2 === "recovering") return /* @__PURE__ */ jsx(RotateCw, { className: "size-3.5 animate-spin text-amber-500 dark:text-amber-400" });
1559
+ return /* @__PURE__ */ jsx(LoaderCircle, { className: "size-3.5 animate-spin text-blue-600 dark:text-blue-400" });
1560
+ }
1561
+ function FleetSubagentList({ children, tree, className }) {
1562
+ const agents = useMemo(() => orderedRlmChildren(children, tree), [children, tree]);
1563
+ const active = agents.some((child) => child.status === "queued" || child.status === "running" || child.status === "recovering");
1564
+ const [open, setOpen] = useState(active);
1565
+ if (agents.length === 0) return null;
1566
+ return /* @__PURE__ */ jsxs("section", {
1567
+ className: cn("mt-2 rounded-xl border border-border/60 bg-muted/20", className),
1568
+ children: [/* @__PURE__ */ jsxs("button", {
1569
+ type: "button",
1570
+ "aria-expanded": open || active,
1571
+ onClick: () => setOpen((current) => !current),
1572
+ className: "flex w-full items-center gap-2 px-3 py-2 text-left text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
1573
+ children: [
1574
+ active ? /* @__PURE__ */ jsx(LoaderCircle, { className: "size-3.5 animate-spin text-blue-600 dark:text-blue-400" }) : /* @__PURE__ */ jsx(CircleCheck, { className: "size-3.5 text-emerald-600 dark:text-emerald-400" }),
1575
+ /* @__PURE__ */ jsx("span", {
1576
+ className: "flex-1 font-medium",
1577
+ children: active ? "Subagents working" : "Subagents completed"
1578
+ }),
1579
+ /* @__PURE__ */ jsx("span", {
1580
+ className: "text-xs text-muted-foreground",
1581
+ children: agents.length
1582
+ }),
1583
+ /* @__PURE__ */ jsx(ChevronDown, { className: cn("size-3.5 text-muted-foreground transition-transform", (open || active) && "rotate-180") })
1584
+ ]
1585
+ }), open || active ? /* @__PURE__ */ jsx("div", {
1586
+ className: "space-y-1 border-t border-border/50 px-3 py-2",
1587
+ children: agents.map((child) => /* @__PURE__ */ jsxs("div", {
1588
+ className: "flex min-w-0 items-start gap-2",
1589
+ style: { paddingLeft: `${Math.max(0, child.depth ?? 0) * 12}px` },
1590
+ children: [
1591
+ /* @__PURE__ */ jsx("span", {
1592
+ className: "mt-0.5 shrink-0",
1593
+ children: rlmStatusIcon(child.status)
1594
+ }),
1595
+ /* @__PURE__ */ jsxs("div", {
1596
+ className: "min-w-0 flex-1",
1597
+ children: [/* @__PURE__ */ jsxs("div", {
1598
+ className: "flex min-w-0 items-baseline gap-2",
1599
+ children: [/* @__PURE__ */ jsx("span", {
1600
+ className: "truncate text-sm text-foreground/85",
1601
+ children: child.label
1602
+ }), child.model ? /* @__PURE__ */ jsx("span", {
1603
+ className: "truncate font-mono text-[10px] text-muted-foreground",
1604
+ children: child.model
1605
+ }) : null]
1606
+ }), child.answerPreview || child.activity?.toolName || child.error ? /* @__PURE__ */ jsx("p", {
1607
+ className: "truncate text-xs text-muted-foreground",
1608
+ children: child.error ?? child.answerPreview ?? child.activity?.toolName
1609
+ }) : null]
1610
+ }),
1611
+ /* @__PURE__ */ jsx("span", {
1612
+ className: "shrink-0 text-[10px] capitalize text-muted-foreground",
1613
+ children: child.status
1614
+ })
1615
+ ]
1616
+ }, child.id))
1617
+ }) : null]
1618
+ });
1619
+ }
1620
+ function record(value) {
1621
+ return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
1622
+ }
1623
+ function target(input, fallback) {
1624
+ const source = record(input);
1625
+ for (const key of [
1626
+ "path",
1627
+ "filePath",
1628
+ "command",
1629
+ "cmd",
1630
+ "query",
1631
+ "pattern",
1632
+ "code"
1633
+ ]) if (typeof source?.[key] === "string" && source[key]) return source[key];
1634
+ return fallback;
1635
+ }
1636
+ function status(part, streaming) {
1637
+ const state = part.state;
1638
+ if (state === "output-error" || state === "error") return "error";
1639
+ if (state === "cancelled" || state === "canceled" || state === "aborted") return "cancelled";
1640
+ if (state === "input-streaming" || state === "streaming") return streaming ? "running" : "cancelled";
1641
+ return streaming && part.output === void 0 && part.result === void 0 ? "running" : "complete";
1642
+ }
1643
+ function toolStep(part, fallbackId, streaming) {
1644
+ const type = part.type;
1645
+ if (typeof type !== "string" || !type.startsWith("tool-") || type === "tool-FleetReasoning" || type === "tool-Thinking") return void 0;
1646
+ const name = type.slice(5);
1647
+ const lower = name.toLowerCase();
1648
+ const icon = lower.includes("edit") || lower.includes("write") || lower.includes("patch") ? FilePenLine : lower.includes("read") || lower.includes("search") || lower.includes("grep") || lower.includes("glob") ? FileSearch : lower.includes("bash") || lower.includes("shell") || lower.includes("python") || lower.includes("ipython") ? Terminal : Wrench;
1649
+ const verb = lower.includes("edit") || lower.includes("write") || lower.includes("patch") ? "Edited" : lower.includes("read") ? "Read" : lower.includes("search") || lower.includes("grep") || lower.includes("glob") ? "Searched" : lower.includes("bash") || lower.includes("shell") || lower.includes("python") || lower.includes("ipython") ? "Ran" : name;
1650
+ return {
1651
+ id: typeof part.toolCallId === "string" ? part.toolCallId : fallbackId,
1652
+ icon,
1653
+ verb,
1654
+ target: target(part.input ?? part.args, name),
1655
+ status: status(part, streaming)
1656
+ };
1657
+ }
1658
+ function artifactStep(artifact) {
1659
+ const icon = artifact.kind === "diff" ? FilePenLine : artifact.kind === "bash" || artifact.kind === "ipython" ? Terminal : Wrench;
1660
+ return {
1661
+ id: `artifact:${artifact.id}`,
1662
+ icon,
1663
+ verb: artifact.kind === "compaction" ? "Compacted" : artifact.kind === "refinement" ? "Refined" : artifact.kind === "recap" ? "Recapped" : artifact.kind === "rlm" ? "Delegated" : artifact.kind === "diff" ? "Edited" : "Completed",
1664
+ target: artifact.title,
1665
+ status: artifact.status === "success" ? "complete" : artifact.status
1666
+ };
1667
+ }
1668
+ function statusClass(status2) {
1669
+ if (status2 === "running") return "text-blue-600 dark:text-blue-400";
1670
+ if (status2 === "error") return "text-destructive";
1671
+ if (status2 === "cancelled") return "text-muted-foreground";
1672
+ return "text-emerald-600 dark:text-emerald-400";
1673
+ }
1674
+ function FleetToolTimeline({ messages, artifacts = [], streaming, className }) {
1675
+ const steps = useMemo(() => {
1676
+ const seen = /* @__PURE__ */ new Set();
1677
+ const fromMessages = messages.flatMap((message) => message.parts.flatMap((part, index) => {
1678
+ const step = toolStep(record(part) ?? {}, `${message.id}:${index}`, streaming);
1679
+ if (!step || seen.has(step.id)) return [];
1680
+ seen.add(step.id);
1681
+ return [step];
1682
+ }));
1683
+ const fromArtifacts = artifacts.flatMap((artifact) => {
1684
+ if (artifact.sourceToolCallId && seen.has(artifact.sourceToolCallId)) return [];
1685
+ const step = artifactStep(artifact);
1686
+ if (seen.has(step.id)) return [];
1687
+ seen.add(step.id);
1688
+ return [step];
1689
+ });
1690
+ return [...fromMessages, ...fromArtifacts];
1691
+ }, [
1692
+ artifacts,
1693
+ messages,
1694
+ streaming
1695
+ ]);
1696
+ const [open, setOpen] = useState(true);
1697
+ if (steps.length === 0) return null;
1698
+ const active = steps.at(-1);
1699
+ const ActiveIcon = active?.icon;
1700
+ return /* @__PURE__ */ jsxs("section", {
1701
+ className: cn("mb-2 rounded-xl border border-border/60 bg-muted/20", className),
1702
+ children: [/* @__PURE__ */ jsxs("button", {
1703
+ type: "button",
1704
+ "aria-expanded": open,
1705
+ onClick: () => setOpen((current) => !current),
1706
+ className: "flex w-full items-center gap-2 px-3 py-2 text-left text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
1707
+ children: [
1708
+ active && ActiveIcon ? /* @__PURE__ */ jsx(ActiveIcon, { className: cn("size-3.5 shrink-0", statusClass(active.status), active.status === "running" && "animate-pulse") }) : null,
1709
+ /* @__PURE__ */ jsx("span", {
1710
+ className: "min-w-0 flex-1 truncate font-medium",
1711
+ children: streaming && active ? `${active.verb} ${active.target}` : `${steps.length} tool ${steps.length === 1 ? "action" : "actions"}`
1712
+ }),
1713
+ /* @__PURE__ */ jsx(ChevronDown, { className: cn("size-3.5 text-muted-foreground transition-transform", open && "rotate-180") })
1714
+ ]
1715
+ }), open ? /* @__PURE__ */ jsx("div", {
1716
+ className: "space-y-1 border-t border-border/50 px-3 py-2",
1717
+ children: steps.map((step) => {
1718
+ const Icon = step.icon;
1719
+ return /* @__PURE__ */ jsxs("div", {
1720
+ className: "flex min-w-0 items-center gap-2 text-xs",
1721
+ children: [
1722
+ /* @__PURE__ */ jsx(Icon, { className: cn("size-3.5 shrink-0", statusClass(step.status)) }),
1723
+ /* @__PURE__ */ jsx("span", {
1724
+ className: "shrink-0 text-muted-foreground",
1725
+ children: step.verb
1726
+ }),
1727
+ /* @__PURE__ */ jsx("span", {
1728
+ className: "min-w-0 flex-1 truncate font-mono text-foreground/75",
1729
+ children: step.target
1730
+ })
1731
+ ]
1732
+ }, step.id);
1733
+ })
1734
+ }) : null]
1735
+ });
1736
+ }
1737
+ function groupMessages(messages) {
1738
+ const turns = [];
1739
+ let current;
1740
+ for (const message of messages) {
1741
+ if (message.role === "user") {
1742
+ if (current) turns.push(current);
1743
+ current = {
1744
+ user: message,
1745
+ assistants: []
1746
+ };
1747
+ continue;
1748
+ }
1749
+ if (message.role !== "assistant") continue;
1750
+ if (!current || message.source === "local") {
1751
+ if (current) turns.push(current);
1752
+ current = { assistants: [message] };
1753
+ continue;
1754
+ }
1755
+ current.assistants.push(message);
1756
+ }
1757
+ if (current) turns.push(current);
1758
+ return turns;
1759
+ }
1760
+ var LazyGenerativeTextRenderer = lazy(() => import("./openui-renderer-c36_GYes-HX46N4M5.js").then((n) => n.n).then(({ GenerativeTextRenderer }) => ({ default: GenerativeTextRenderer })));
1761
+ function PlainTextFallback({ className, content }) {
1762
+ return /* @__PURE__ */ jsx("div", {
1763
+ className: className ? `${className} whitespace-pre-wrap` : "whitespace-pre-wrap",
1764
+ children: content
1765
+ });
1766
+ }
1767
+ function FleetGenerativeTextRenderer(props) {
1768
+ if (!useMemo(() => segmentOpenUIContent(props.content).some((segment) => segment.type === "openui"), [props.content])) return /* @__PURE__ */ jsx(LazyMarkdown, {
1769
+ className: props.className,
1770
+ content: props.content
1771
+ });
1772
+ return /* @__PURE__ */ jsx(Suspense, {
1773
+ fallback: /* @__PURE__ */ jsx(PlainTextFallback, {
1774
+ className: props.className,
1775
+ content: props.content
1776
+ }),
1777
+ children: /* @__PURE__ */ jsx(LazyGenerativeTextRenderer, { ...props })
1778
+ });
1779
+ }
1780
+
1781
+ export {
1782
+ ChevronLeft,
1783
+ Image,
1784
+ MessageBubble,
1785
+ MessageBubbleContent,
1786
+ MessageScroller,
1787
+ Message,
1788
+ MessageContent,
1789
+ FileAttachment,
1790
+ UserMessage,
1791
+ normalizeAssistantToolParts,
1792
+ buildAssistantElements,
1793
+ orderedRlmChildren,
1794
+ rlmStatusIcon,
1795
+ FleetSubagentList,
1796
+ FleetToolTimeline,
1797
+ groupMessages,
1798
+ FleetGenerativeTextRenderer
1799
+ };
1800
+ /**
1801
+ * @license lucide-react v1.33.0 - ISC
1802
+ *
1803
+ * This source code is licensed under the ISC license.
1804
+ * See the LICENSE file in the root directory of this source tree.
1805
+ */