@townco/ui 0.1.6 → 0.1.7

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 (250) hide show
  1. package/README.md +11 -11
  2. package/dist/core/hooks/use-chat-input.d.ts +17 -17
  3. package/dist/core/hooks/use-chat-input.js +55 -64
  4. package/dist/core/hooks/use-chat-messages.d.ts +11 -11
  5. package/dist/core/hooks/use-chat-messages.js +114 -121
  6. package/dist/core/hooks/use-chat-session.d.ts +5 -5
  7. package/dist/core/hooks/use-chat-session.js +80 -78
  8. package/dist/core/index.d.ts +1 -1
  9. package/dist/core/index.js +1 -1
  10. package/dist/core/schemas/chat.d.ts +56 -83
  11. package/dist/core/schemas/chat.js +25 -27
  12. package/dist/core/store/chat-store.d.ts +22 -28
  13. package/dist/core/store/chat-store.js +50 -59
  14. package/dist/gui/components/Button.d.ts +7 -23
  15. package/dist/gui/components/Button.js +27 -40
  16. package/dist/gui/components/Card.d.ts +7 -26
  17. package/dist/gui/components/Card.js +8 -54
  18. package/dist/gui/components/ChatInput.d.ts +36 -58
  19. package/dist/gui/components/ChatInput.js +121 -191
  20. package/dist/gui/components/ChatSecondaryPanel.d.ts +11 -14
  21. package/dist/gui/components/ChatSecondaryPanel.js +38 -115
  22. package/dist/gui/components/ChatStatus.d.ts +2 -4
  23. package/dist/gui/components/ChatStatus.js +34 -45
  24. package/dist/gui/components/Conversation.d.ts +14 -17
  25. package/dist/gui/components/Conversation.js +83 -143
  26. package/dist/gui/components/Dialog.d.ts +11 -57
  27. package/dist/gui/components/Dialog.js +8 -84
  28. package/dist/gui/components/HeightTransition.d.ts +7 -12
  29. package/dist/gui/components/HeightTransition.js +77 -88
  30. package/dist/gui/components/Input.d.ts +6 -13
  31. package/dist/gui/components/Input.js +16 -27
  32. package/dist/gui/components/Label.d.ts +1 -7
  33. package/dist/gui/components/Label.js +2 -12
  34. package/dist/gui/components/MarkdownRenderer.d.ts +4 -6
  35. package/dist/gui/components/MarkdownRenderer.js +81 -178
  36. package/dist/gui/components/Message.d.ts +18 -25
  37. package/dist/gui/components/Message.js +23 -44
  38. package/dist/gui/components/MessageContent.d.ts +22 -29
  39. package/dist/gui/components/MessageContent.js +85 -157
  40. package/dist/gui/components/Reasoning.d.ts +24 -30
  41. package/dist/gui/components/Reasoning.js +60 -187
  42. package/dist/gui/components/Response.d.ts +9 -11
  43. package/dist/gui/components/Response.js +90 -229
  44. package/dist/gui/components/Select.d.ts +10 -69
  45. package/dist/gui/components/Select.js +12 -118
  46. package/dist/gui/components/Tabs.d.ts +4 -24
  47. package/dist/gui/components/Tabs.js +4 -32
  48. package/dist/gui/components/Task.d.ts +24 -28
  49. package/dist/gui/components/Task.js +31 -164
  50. package/dist/gui/components/Textarea.d.ts +7 -15
  51. package/dist/gui/components/Textarea.js +46 -63
  52. package/dist/gui/components/ThinkingBlock.d.ts +10 -20
  53. package/dist/gui/components/ThinkingBlock.js +35 -134
  54. package/dist/gui/components/TodoList.d.ts +10 -12
  55. package/dist/gui/components/TodoList.js +7 -22
  56. package/dist/gui/components/TodoListItem.d.ts +6 -9
  57. package/dist/gui/components/TodoListItem.js +4 -18
  58. package/dist/gui/components/index.d.ts +8 -59
  59. package/dist/gui/components/index.js +8 -42
  60. package/dist/gui/lib/utils.js +1 -1
  61. package/dist/index.d.ts +1 -1
  62. package/dist/index.js +1 -1
  63. package/dist/index.test.js +1 -0
  64. package/dist/sdk/client/acp-client.d.ts +76 -88
  65. package/dist/sdk/client/acp-client.js +217 -215
  66. package/dist/sdk/index.d.ts +1 -1
  67. package/dist/sdk/index.js +1 -1
  68. package/dist/sdk/schemas/agent.d.ts +64 -111
  69. package/dist/sdk/schemas/agent.js +24 -24
  70. package/dist/sdk/schemas/message.d.ts +147 -245
  71. package/dist/sdk/schemas/message.js +40 -40
  72. package/dist/sdk/schemas/session.d.ts +135 -219
  73. package/dist/sdk/schemas/session.js +27 -27
  74. package/dist/sdk/transports/http.d.ts +55 -55
  75. package/dist/sdk/transports/http.js +469 -472
  76. package/dist/sdk/transports/stdio.d.ts +20 -20
  77. package/dist/sdk/transports/stdio.js +286 -289
  78. package/dist/sdk/transports/types.d.ts +42 -42
  79. package/dist/sdk/transports/websocket.d.ts +12 -12
  80. package/dist/sdk/transports/websocket.js +46 -52
  81. package/dist/tui/components/ChatView.d.ts +2 -4
  82. package/dist/tui/components/ChatView.js +18 -51
  83. package/dist/tui/components/GameOfLife.js +35 -64
  84. package/dist/tui/components/InputBox.d.ts +11 -18
  85. package/dist/tui/components/InputBox.js +10 -70
  86. package/dist/tui/components/MessageList.d.ts +2 -4
  87. package/dist/tui/components/MessageList.js +10 -37
  88. package/dist/tui/components/MultiSelect.d.ts +10 -15
  89. package/dist/tui/components/MultiSelect.js +73 -116
  90. package/dist/tui/components/ReadlineInput.d.ts +6 -12
  91. package/dist/tui/components/ReadlineInput.js +237 -252
  92. package/dist/tui/components/SingleSelect.d.ts +9 -15
  93. package/dist/tui/components/SingleSelect.js +43 -84
  94. package/dist/tui/components/StatusBar.d.ts +6 -11
  95. package/dist/tui/components/StatusBar.js +67 -102
  96. package/dist/tui/index.d.ts +1 -1
  97. package/dist/tui/index.js +1 -1
  98. package/package.json +2 -2
  99. package/dist/core/hooks/index.d.ts.map +0 -1
  100. package/dist/core/hooks/index.js.map +0 -1
  101. package/dist/core/hooks/use-chat-input.d.ts.map +0 -1
  102. package/dist/core/hooks/use-chat-input.js.map +0 -1
  103. package/dist/core/hooks/use-chat-messages.d.ts.map +0 -1
  104. package/dist/core/hooks/use-chat-messages.js.map +0 -1
  105. package/dist/core/hooks/use-chat-session.d.ts.map +0 -1
  106. package/dist/core/hooks/use-chat-session.js.map +0 -1
  107. package/dist/core/hooks/use-media-query.d.ts +0 -39
  108. package/dist/core/hooks/use-media-query.js +0 -80
  109. package/dist/core/index.d.ts.map +0 -1
  110. package/dist/core/index.js.map +0 -1
  111. package/dist/core/schemas/chat.d.ts.map +0 -1
  112. package/dist/core/schemas/chat.js.map +0 -1
  113. package/dist/core/schemas/index.d.ts.map +0 -1
  114. package/dist/core/schemas/index.js.map +0 -1
  115. package/dist/core/store/chat-store.d.ts.map +0 -1
  116. package/dist/core/store/chat-store.js.map +0 -1
  117. package/dist/gui/components/Button.d.ts.map +0 -1
  118. package/dist/gui/components/Button.js.map +0 -1
  119. package/dist/gui/components/Card.d.ts.map +0 -1
  120. package/dist/gui/components/Card.js.map +0 -1
  121. package/dist/gui/components/ChatHeader.d.ts +0 -65
  122. package/dist/gui/components/ChatHeader.js +0 -189
  123. package/dist/gui/components/ChatInput.d.ts.map +0 -1
  124. package/dist/gui/components/ChatInput.js.map +0 -1
  125. package/dist/gui/components/ChatInterface.d.ts +0 -12
  126. package/dist/gui/components/ChatInterface.d.ts.map +0 -1
  127. package/dist/gui/components/ChatInterface.js +0 -204
  128. package/dist/gui/components/ChatInterface.js.map +0 -1
  129. package/dist/gui/components/ChatLayout.d.ts +0 -82
  130. package/dist/gui/components/ChatLayout.js +0 -232
  131. package/dist/gui/components/ChatPanelTabContent.d.ts +0 -27
  132. package/dist/gui/components/ChatPanelTabContent.js +0 -93
  133. package/dist/gui/components/ChatPreview.d.ts +0 -12
  134. package/dist/gui/components/ChatPreview.d.ts.map +0 -1
  135. package/dist/gui/components/ChatPreview.js +0 -214
  136. package/dist/gui/components/ChatPreview.js.map +0 -1
  137. package/dist/gui/components/ChatSecondaryPanel.d.ts.map +0 -1
  138. package/dist/gui/components/ChatSecondaryPanel.js.map +0 -1
  139. package/dist/gui/components/ChatSidebar.d.ts +0 -27
  140. package/dist/gui/components/ChatSidebar.js +0 -57
  141. package/dist/gui/components/ChatStatus.d.ts.map +0 -1
  142. package/dist/gui/components/ChatStatus.js.map +0 -1
  143. package/dist/gui/components/ChatView.d.ts +0 -8
  144. package/dist/gui/components/ChatView.d.ts.map +0 -1
  145. package/dist/gui/components/ChatView.js +0 -42
  146. package/dist/gui/components/ChatView.js.map +0 -1
  147. package/dist/gui/components/ConfigPanel.d.ts +0 -20
  148. package/dist/gui/components/ConfigPanel.d.ts.map +0 -1
  149. package/dist/gui/components/ConfigPanel.js +0 -225
  150. package/dist/gui/components/ConfigPanel.js.map +0 -1
  151. package/dist/gui/components/Conversation.d.ts.map +0 -1
  152. package/dist/gui/components/Conversation.js.map +0 -1
  153. package/dist/gui/components/Dialog.d.ts.map +0 -1
  154. package/dist/gui/components/Dialog.js.map +0 -1
  155. package/dist/gui/components/DropdownMenu.d.ts +0 -108
  156. package/dist/gui/components/DropdownMenu.js +0 -215
  157. package/dist/gui/components/HeightTransition.d.ts.map +0 -1
  158. package/dist/gui/components/HeightTransition.js.map +0 -1
  159. package/dist/gui/components/Input.d.ts.map +0 -1
  160. package/dist/gui/components/Input.js.map +0 -1
  161. package/dist/gui/components/InputBox.d.ts +0 -21
  162. package/dist/gui/components/InputBox.d.ts.map +0 -1
  163. package/dist/gui/components/InputBox.js +0 -90
  164. package/dist/gui/components/InputBox.js.map +0 -1
  165. package/dist/gui/components/Label.d.ts.map +0 -1
  166. package/dist/gui/components/Label.js.map +0 -1
  167. package/dist/gui/components/MarkdownRenderer.d.ts.map +0 -1
  168. package/dist/gui/components/MarkdownRenderer.js.map +0 -1
  169. package/dist/gui/components/Message.d.ts.map +0 -1
  170. package/dist/gui/components/Message.js.map +0 -1
  171. package/dist/gui/components/MessageContent.d.ts.map +0 -1
  172. package/dist/gui/components/MessageContent.js.map +0 -1
  173. package/dist/gui/components/MessageList.d.ts.map +0 -1
  174. package/dist/gui/components/MessageList.js.map +0 -1
  175. package/dist/gui/components/PlaygroundLayout.d.ts +0 -14
  176. package/dist/gui/components/PlaygroundLayout.d.ts.map +0 -1
  177. package/dist/gui/components/PlaygroundLayout.js +0 -49
  178. package/dist/gui/components/PlaygroundLayout.js.map +0 -1
  179. package/dist/gui/components/Reasoning.d.ts.map +0 -1
  180. package/dist/gui/components/Reasoning.js.map +0 -1
  181. package/dist/gui/components/Response.d.ts.map +0 -1
  182. package/dist/gui/components/Response.js.map +0 -1
  183. package/dist/gui/components/Select.d.ts.map +0 -1
  184. package/dist/gui/components/Select.js.map +0 -1
  185. package/dist/gui/components/Sonner.d.ts +0 -7
  186. package/dist/gui/components/Sonner.js +0 -34
  187. package/dist/gui/components/StatusBar.d.ts +0 -12
  188. package/dist/gui/components/StatusBar.d.ts.map +0 -1
  189. package/dist/gui/components/StatusBar.js +0 -58
  190. package/dist/gui/components/StatusBar.js.map +0 -1
  191. package/dist/gui/components/Tabs.d.ts.map +0 -1
  192. package/dist/gui/components/Tabs.js.map +0 -1
  193. package/dist/gui/components/Task.d.ts.map +0 -1
  194. package/dist/gui/components/Task.js.map +0 -1
  195. package/dist/gui/components/Textarea.d.ts.map +0 -1
  196. package/dist/gui/components/Textarea.js.map +0 -1
  197. package/dist/gui/components/ThinkingBlock.d.ts.map +0 -1
  198. package/dist/gui/components/ThinkingBlock.js.map +0 -1
  199. package/dist/gui/components/TodoList.d.ts.map +0 -1
  200. package/dist/gui/components/TodoList.js.map +0 -1
  201. package/dist/gui/components/TodoListItem.d.ts.map +0 -1
  202. package/dist/gui/components/TodoListItem.js.map +0 -1
  203. package/dist/gui/components/index.d.ts.map +0 -1
  204. package/dist/gui/components/index.js.map +0 -1
  205. package/dist/gui/index.d.ts.map +0 -1
  206. package/dist/gui/index.js.map +0 -1
  207. package/dist/gui/lib/utils.d.ts.map +0 -1
  208. package/dist/gui/lib/utils.js.map +0 -1
  209. package/dist/index.d.ts.map +0 -1
  210. package/dist/index.js.map +0 -1
  211. package/dist/sdk/client/acp-client.d.ts.map +0 -1
  212. package/dist/sdk/client/acp-client.js.map +0 -1
  213. package/dist/sdk/client/index.d.ts.map +0 -1
  214. package/dist/sdk/client/index.js.map +0 -1
  215. package/dist/sdk/index.d.ts.map +0 -1
  216. package/dist/sdk/index.js.map +0 -1
  217. package/dist/sdk/schemas/agent.d.ts.map +0 -1
  218. package/dist/sdk/schemas/agent.js.map +0 -1
  219. package/dist/sdk/schemas/index.d.ts.map +0 -1
  220. package/dist/sdk/schemas/index.js.map +0 -1
  221. package/dist/sdk/schemas/message.d.ts.map +0 -1
  222. package/dist/sdk/schemas/message.js.map +0 -1
  223. package/dist/sdk/schemas/session.d.ts.map +0 -1
  224. package/dist/sdk/schemas/session.js.map +0 -1
  225. package/dist/sdk/transports/http.d.ts.map +0 -1
  226. package/dist/sdk/transports/http.js.map +0 -1
  227. package/dist/sdk/transports/index.d.ts.map +0 -1
  228. package/dist/sdk/transports/index.js.map +0 -1
  229. package/dist/sdk/transports/stdio.d.ts.map +0 -1
  230. package/dist/sdk/transports/stdio.js.map +0 -1
  231. package/dist/sdk/transports/types.d.ts.map +0 -1
  232. package/dist/sdk/transports/types.js.map +0 -1
  233. package/dist/sdk/transports/websocket.d.ts.map +0 -1
  234. package/dist/sdk/transports/websocket.js.map +0 -1
  235. package/dist/tui/components/ChatView.d.ts.map +0 -1
  236. package/dist/tui/components/ChatView.js.map +0 -1
  237. package/dist/tui/components/GameOfLife.d.ts.map +0 -1
  238. package/dist/tui/components/GameOfLife.js.map +0 -1
  239. package/dist/tui/components/InputBox.d.ts.map +0 -1
  240. package/dist/tui/components/InputBox.js.map +0 -1
  241. package/dist/tui/components/MessageList.d.ts.map +0 -1
  242. package/dist/tui/components/MessageList.js.map +0 -1
  243. package/dist/tui/components/ReadlineInput.d.ts.map +0 -1
  244. package/dist/tui/components/ReadlineInput.js.map +0 -1
  245. package/dist/tui/components/StatusBar.d.ts.map +0 -1
  246. package/dist/tui/components/StatusBar.js.map +0 -1
  247. package/dist/tui/components/index.d.ts.map +0 -1
  248. package/dist/tui/components/index.js.map +0 -1
  249. package/dist/tui/index.d.ts.map +0 -1
  250. package/dist/tui/index.js.map +0 -1
@@ -1,16 +1,11 @@
1
+ import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
1
2
  import { cva } from "class-variance-authority";
2
3
  import { Loader2Icon } from "lucide-react";
3
4
  import * as React from "react";
4
- import {
5
- Fragment as _Fragment,
6
- jsx as _jsx,
7
- jsxs as _jsxs,
8
- } from "react/jsx-runtime";
9
5
  import { useChatStore } from "../../core/store/chat-store.js";
10
6
  import { cn } from "../lib/utils.js";
11
7
  import { Reasoning } from "./Reasoning.js";
12
8
  import { Response } from "./Response.js";
13
-
14
9
  /**
15
10
  * MessageContent component inspired by shadcn.io/ai
16
11
  * Provides the content container with role-based styling
@@ -18,159 +13,92 @@ import { Response } from "./Response.js";
18
13
  */
19
14
  // Synonyms of "thinking" in multiple languages
20
15
  const THINKING_WORDS = [
21
- "Thinking",
22
- "Pensando",
23
- "Pensant",
24
- "Denkend",
25
- "Pensando",
26
- "考えている",
27
- "생각 중",
28
- "思考中",
29
- "Размышляя",
30
- "Düşünüyor",
31
- "Myślący",
32
- "Tänkande",
33
- "Pensando",
34
- "Ajatellen",
35
- "Σκεπτόμενος",
36
- "חושב",
37
- "सोच रहा है",
38
- "Berpikir",
16
+ "Thinking",
17
+ "Pensando",
18
+ "Pensant",
19
+ "Denkend",
20
+ "Pensando",
21
+ "考えている",
22
+ "생각 중",
23
+ "思考中",
24
+ "Размышляя",
25
+ "Düşünüyor",
26
+ "Myślący",
27
+ "Tänkande",
28
+ "Pensando",
29
+ "Ajatellen",
30
+ "Σκεπτόμενος",
31
+ "חושב",
32
+ "सोच रहा है",
33
+ "Berpikir",
39
34
  ];
40
35
  const DOT_ANIMATIONS = ["...", "·..", ".·.", "..·", ".·.", "·.."];
41
36
  function WaitingElapsedTime({ startTime }) {
42
- const [elapsed, setElapsed] = React.useState(0);
43
- const [thinkingWord, setThinkingWord] = React.useState(
44
- () => THINKING_WORDS[Math.floor(Math.random() * THINKING_WORDS.length)],
45
- );
46
- const [dotIndex, setDotIndex] = React.useState(0);
47
- React.useEffect(() => {
48
- const interval = setInterval(() => {
49
- const now = Date.now();
50
- const elapsedMs = now - startTime;
51
- setElapsed(elapsedMs);
52
- }, 100);
53
- return () => clearInterval(interval);
54
- }, [startTime]);
55
- React.useEffect(() => {
56
- const wordInterval = setInterval(() => {
57
- const randomIndex = Math.floor(Math.random() * THINKING_WORDS.length);
58
- setThinkingWord(THINKING_WORDS[randomIndex]);
59
- }, 1500);
60
- return () => clearInterval(wordInterval);
61
- }, []);
62
- React.useEffect(() => {
63
- const dotInterval = setInterval(() => {
64
- setDotIndex((prev) => (prev + 1) % DOT_ANIMATIONS.length);
65
- }, 100);
66
- return () => clearInterval(dotInterval);
67
- }, []);
68
- const seconds = (elapsed / 1000).toFixed(1);
69
- const animatedDots = DOT_ANIMATIONS[dotIndex];
70
- return _jsxs("span", {
71
- className: "text-muted-foreground text-sm",
72
- children: [thinkingWord, animatedDots, " ", seconds, "s"],
73
- });
37
+ const [elapsed, setElapsed] = React.useState(0);
38
+ const [thinkingWord, setThinkingWord] = React.useState(() => THINKING_WORDS[Math.floor(Math.random() * THINKING_WORDS.length)]);
39
+ const [dotIndex, setDotIndex] = React.useState(0);
40
+ React.useEffect(() => {
41
+ const interval = setInterval(() => {
42
+ const now = Date.now();
43
+ const elapsedMs = now - startTime;
44
+ setElapsed(elapsedMs);
45
+ }, 100);
46
+ return () => clearInterval(interval);
47
+ }, [startTime]);
48
+ React.useEffect(() => {
49
+ const wordInterval = setInterval(() => {
50
+ const randomIndex = Math.floor(Math.random() * THINKING_WORDS.length);
51
+ setThinkingWord(THINKING_WORDS[randomIndex]);
52
+ }, 1500);
53
+ return () => clearInterval(wordInterval);
54
+ }, []);
55
+ React.useEffect(() => {
56
+ const dotInterval = setInterval(() => {
57
+ setDotIndex((prev) => (prev + 1) % DOT_ANIMATIONS.length);
58
+ }, 100);
59
+ return () => clearInterval(dotInterval);
60
+ }, []);
61
+ const seconds = (elapsed / 1000).toFixed(1);
62
+ const animatedDots = DOT_ANIMATIONS[dotIndex];
63
+ return (_jsxs("span", { className: "text-muted-foreground text-sm", children: [thinkingWord, animatedDots, " ", seconds, "s"] }));
74
64
  }
75
- const messageContentVariants = cva(
76
- "w-full px-4 py-3 rounded-xl text-[var(--font-size)] font-[var(--font-family)] leading-relaxed break-words transition-colors",
77
- {
78
- variants: {
79
- role: {
80
- user: "bg-primary text-primary-foreground shadow-sm",
81
- assistant: "bg-muted text-foreground",
82
- system:
83
- "bg-card border border-border text-foreground opacity-80 text-sm",
84
- },
85
- variant: {
86
- default: "",
87
- outline: "border border-border",
88
- ghost: "bg-transparent",
89
- },
90
- },
91
- defaultVariants: {
92
- role: "assistant",
93
- variant: "default",
94
- },
95
- },
96
- );
97
- export const MessageContent = React.forwardRef(
98
- (
99
- {
100
- role: roleProp,
101
- variant,
102
- isStreaming: isStreamingProp,
103
- message,
104
- thinkingDisplayStyle = "collapsible",
105
- className,
106
- children,
107
- ...props
108
- },
109
- ref,
110
- ) => {
111
- // Get streaming start time from store (when using smart rendering)
112
- const streamingStartTime = useChatStore(
113
- (state) => state.streamingStartTime,
114
- );
115
- // Use smart rendering if message is provided and no custom children
116
- const useSmartRendering = message && !children;
117
- // Derive props from message if using smart rendering
118
- const role = useSmartRendering ? message.role : roleProp || "assistant";
119
- const isStreaming = useSmartRendering
120
- ? message.isStreaming
121
- : isStreamingProp;
122
- let content = children;
123
- if (useSmartRendering) {
124
- // Extract thinking from metadata
125
- const thinking = message.metadata?.thinking;
126
- const hasThinking = !!thinking;
127
- // Check if waiting (streaming but no content yet)
128
- const isWaiting =
129
- message.isStreaming && !message.content && message.role === "assistant";
130
- content = _jsxs(_Fragment, {
131
- children: [
132
- message.role === "assistant" &&
133
- hasThinking &&
134
- _jsx(Reasoning, {
135
- content: thinking,
136
- isStreaming: message.isStreaming,
137
- mode: thinkingDisplayStyle,
138
- autoCollapse: true,
139
- }),
140
- isWaiting &&
141
- streamingStartTime &&
142
- _jsxs("div", {
143
- className: "flex items-center gap-2 opacity-50",
144
- children: [
145
- _jsx(Loader2Icon, {
146
- className: "size-4 animate-spin text-muted-foreground",
147
- }),
148
- _jsx(WaitingElapsedTime, { startTime: streamingStartTime }),
149
- ],
150
- }),
151
- message.role === "user"
152
- ? _jsx("div", {
153
- className: "whitespace-pre-wrap",
154
- children: message.content,
155
- })
156
- : _jsx(Response, {
157
- content: message.content,
158
- isStreaming: message.isStreaming,
159
- showEmpty: false,
160
- }),
161
- ],
162
- });
163
- }
164
- return _jsx("div", {
165
- ref: ref,
166
- className: cn(
167
- messageContentVariants({ role, variant }),
168
- isStreaming && "animate-pulse-subtle",
169
- className,
170
- ),
171
- ...props,
172
- children: content,
173
- });
174
- },
175
- );
65
+ const messageContentVariants = cva("w-full px-4 py-3 rounded-xl text-[var(--font-size)] font-[var(--font-family)] leading-relaxed break-words transition-colors", {
66
+ variants: {
67
+ role: {
68
+ user: "bg-primary text-primary-foreground shadow-sm",
69
+ assistant: "bg-muted text-foreground",
70
+ system: "bg-card border border-border text-foreground opacity-80 text-sm",
71
+ },
72
+ variant: {
73
+ default: "",
74
+ outline: "border border-border",
75
+ ghost: "bg-transparent",
76
+ },
77
+ },
78
+ defaultVariants: {
79
+ role: "assistant",
80
+ variant: "default",
81
+ },
82
+ });
83
+ export const MessageContent = React.forwardRef(({ role: roleProp, variant, isStreaming: isStreamingProp, message, thinkingDisplayStyle = "collapsible", className, children, ...props }, ref) => {
84
+ // Get streaming start time from store (when using smart rendering)
85
+ const streamingStartTime = useChatStore((state) => state.streamingStartTime);
86
+ // Use smart rendering if message is provided and no custom children
87
+ const useSmartRendering = message && !children;
88
+ // Derive props from message if using smart rendering
89
+ const role = useSmartRendering ? message.role : roleProp || "assistant";
90
+ const isStreaming = useSmartRendering
91
+ ? message.isStreaming
92
+ : isStreamingProp;
93
+ let content = children;
94
+ if (useSmartRendering) {
95
+ // Extract thinking from metadata
96
+ const thinking = message.metadata?.thinking;
97
+ const hasThinking = !!thinking;
98
+ // Check if waiting (streaming but no content yet)
99
+ const isWaiting = message.isStreaming && !message.content && message.role === "assistant";
100
+ content = (_jsxs(_Fragment, { children: [message.role === "assistant" && hasThinking && (_jsx(Reasoning, { content: thinking, isStreaming: message.isStreaming, mode: thinkingDisplayStyle, autoCollapse: true })), isWaiting && streamingStartTime && (_jsxs("div", { className: "flex items-center gap-2 opacity-50", children: [_jsx(Loader2Icon, { className: "size-4 animate-spin text-muted-foreground" }), _jsx(WaitingElapsedTime, { startTime: streamingStartTime })] })), message.role === "user" ? (_jsx("div", { className: "whitespace-pre-wrap", children: message.content })) : (_jsx(Response, { content: message.content, isStreaming: message.isStreaming, showEmpty: false }))] }));
101
+ }
102
+ return (_jsx("div", { ref: ref, className: cn(messageContentVariants({ role, variant }), isStreaming && "animate-pulse-subtle", className), ...props, children: content }));
103
+ });
176
104
  MessageContent.displayName = "MessageContent";
@@ -4,34 +4,28 @@ import * as React from "react";
4
4
  * Reasoning component inspired by shadcn.io/ai
5
5
  * Displays AI thinking/reasoning process with auto-collapse support
6
6
  */
7
- declare const reasoningContainerVariants: (
8
- props?:
9
- | ({
10
- variant?: "default" | "subtle" | "prominent" | null | undefined;
11
- } & import("class-variance-authority/types").ClassProp)
12
- | undefined,
13
- ) => string;
14
- export interface ReasoningProps
15
- extends VariantProps<typeof reasoningContainerVariants> {
16
- /** The reasoning/thinking content */
17
- content?: string;
18
- /** Whether the content is currently streaming */
19
- isStreaming?: boolean;
20
- /** Display mode - collapsible or always visible */
21
- mode?: "collapsible" | "inline";
22
- /** Default expanded state (default: false - collapsed by default) */
23
- defaultExpanded?: boolean;
24
- /** Auto-expand when streaming starts (default: false) */
25
- autoExpand?: boolean;
26
- /** Auto-collapse after streaming completes */
27
- autoCollapse?: boolean;
28
- /** Delay before auto-collapsing (ms) */
29
- autoCollapseDelay?: number;
30
- /** Custom label */
31
- label?: string;
32
- /** Additional CSS class */
33
- className?: string;
7
+ declare const reasoningContainerVariants: (props?: ({
8
+ variant?: "default" | "subtle" | "prominent" | null | undefined;
9
+ } & import("class-variance-authority/types").ClassProp) | undefined) => string;
10
+ export interface ReasoningProps extends VariantProps<typeof reasoningContainerVariants> {
11
+ /** The reasoning/thinking content */
12
+ content?: string;
13
+ /** Whether the content is currently streaming */
14
+ isStreaming?: boolean;
15
+ /** Display mode - collapsible or always visible */
16
+ mode?: "collapsible" | "inline";
17
+ /** Default expanded state (default: false - collapsed by default) */
18
+ defaultExpanded?: boolean;
19
+ /** Auto-expand when streaming starts (default: false) */
20
+ autoExpand?: boolean;
21
+ /** Auto-collapse after streaming completes */
22
+ autoCollapse?: boolean;
23
+ /** Delay before auto-collapsing (ms) */
24
+ autoCollapseDelay?: number;
25
+ /** Custom label */
26
+ label?: string;
27
+ /** Additional CSS class */
28
+ className?: string;
34
29
  }
35
- export declare const Reasoning: React.ForwardRefExoticComponent<
36
- ReasoningProps & React.RefAttributes<HTMLDivElement>
37
- >;
30
+ export declare const Reasoning: React.ForwardRefExoticComponent<ReasoningProps & React.RefAttributes<HTMLDivElement>>;
31
+ export {};
@@ -1,197 +1,70 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
2
  import { cva } from "class-variance-authority";
2
3
  import { ChevronDown } from "lucide-react";
3
4
  import * as React from "react";
4
5
  import { useEffect, useState } from "react";
5
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
6
6
  import { cn } from "../lib/utils.js";
7
-
8
7
  /**
9
8
  * Reasoning component inspired by shadcn.io/ai
10
9
  * Displays AI thinking/reasoning process with auto-collapse support
11
10
  */
12
- const reasoningContainerVariants = cva(
13
- "mb-3 rounded-lg bg-card border border-border transition-all",
14
- {
15
- variants: {
16
- variant: {
17
- default: "opacity-70",
18
- subtle: "opacity-50",
19
- prominent: "opacity-90 shadow-sm",
20
- },
21
- },
22
- defaultVariants: {
23
- variant: "default",
24
- },
25
- },
26
- );
27
- const reasoningIconVariants = cva(
28
- "w-4 h-4 text-foreground opacity-60 transition-transform duration-200",
29
- {
30
- variants: {
31
- expanded: {
32
- true: "rotate-180",
33
- false: "",
34
- },
35
- },
36
- defaultVariants: {
37
- expanded: false,
38
- },
39
- },
40
- );
41
- export const Reasoning = React.forwardRef(
42
- (
43
- {
44
- content,
45
- isStreaming = false,
46
- mode = "collapsible",
47
- defaultExpanded = false,
48
- autoExpand = false,
49
- autoCollapse = true,
50
- autoCollapseDelay = 2000,
51
- label = "Thinking",
52
- variant,
53
- className,
54
- },
55
- ref,
56
- ) => {
57
- const [isExpanded, setIsExpanded] = useState(
58
- mode === "inline" ? true : defaultExpanded,
59
- );
60
- const [shouldAutoCollapse, setShouldAutoCollapse] = useState(false);
61
- // Handle auto-collapse after streaming completes
62
- useEffect(() => {
63
- if (autoCollapse && !isStreaming && content && mode === "collapsible") {
64
- const timer = setTimeout(() => {
65
- setShouldAutoCollapse(true);
66
- setIsExpanded(false);
67
- }, autoCollapseDelay);
68
- return () => clearTimeout(timer);
69
- }
70
- return undefined;
71
- }, [isStreaming, content, autoCollapse, autoCollapseDelay, mode]);
72
- // Auto-expand when streaming starts (only if autoExpand is enabled)
73
- useEffect(() => {
74
- if (
75
- autoExpand &&
76
- isStreaming &&
77
- mode === "collapsible" &&
78
- !shouldAutoCollapse
79
- ) {
80
- setIsExpanded(true);
81
- }
82
- }, [autoExpand, isStreaming, mode, shouldAutoCollapse]);
83
- if (!content && !isStreaming) {
84
- return null;
85
- }
86
- // Inline mode - always visible
87
- if (mode === "inline") {
88
- return _jsxs("div", {
89
- ref: ref,
90
- className: cn(
91
- reasoningContainerVariants({ variant }),
92
- "p-3",
93
- className,
94
- ),
95
- children: [
96
- _jsxs("div", {
97
- className: "flex items-start gap-2 mb-2",
98
- children: [
99
- _jsx("span", {
100
- className:
101
- "text-xs font-medium text-foreground opacity-60 uppercase tracking-wide",
102
- children: label,
103
- }),
104
- isStreaming &&
105
- _jsx("span", {
106
- className:
107
- "inline-block w-2 h-2 bg-primary rounded-full animate-pulse",
108
- }),
109
- ],
110
- }),
111
- _jsxs("div", {
112
- className:
113
- "text-sm italic text-foreground opacity-80 leading-relaxed whitespace-pre-wrap",
114
- children: [
115
- content,
116
- isStreaming &&
117
- content &&
118
- _jsx("span", {
119
- className: "inline-block animate-typing text-primary",
120
- children: "...",
121
- }),
122
- ],
123
- }),
124
- ],
125
- });
126
- }
127
- // Collapsible mode
128
- return _jsxs("div", {
129
- ref: ref,
130
- className: cn("mb-3", className),
131
- children: [
132
- _jsxs("button", {
133
- type: "button",
134
- onClick: () => {
135
- setIsExpanded(!isExpanded);
136
- setShouldAutoCollapse(false); // Disable auto-collapse on manual interaction
137
- },
138
- className:
139
- "w-full flex items-center justify-between p-2.5 rounded-lg bg-card border border-border hover:bg-card/80 hover:shadow-sm transition-all text-left",
140
- "aria-expanded": isExpanded,
141
- "aria-label": `${isExpanded ? "Collapse" : "Expand"} reasoning`,
142
- children: [
143
- _jsxs("div", {
144
- className: "flex items-center gap-2 flex-1 min-w-0",
145
- children: [
146
- _jsx("span", {
147
- className:
148
- "text-xs font-medium text-foreground opacity-60 uppercase tracking-wide shrink-0",
149
- children: label,
150
- }),
151
- isStreaming &&
152
- _jsx("span", {
153
- className:
154
- "inline-block w-2 h-2 bg-primary rounded-full animate-pulse shrink-0",
155
- }),
156
- !isExpanded &&
157
- content &&
158
- _jsxs("span", {
159
- className: "text-xs text-foreground opacity-50 truncate",
160
- children: [
161
- content.substring(0, 60),
162
- content.length > 60 && "...",
163
- ],
164
- }),
165
- ],
166
- }),
167
- _jsx(ChevronDown, {
168
- className: reasoningIconVariants({ expanded: isExpanded }),
169
- "aria-hidden": "true",
170
- }),
171
- ],
172
- }),
173
- isExpanded &&
174
- _jsx("div", {
175
- className: cn(
176
- reasoningContainerVariants({ variant }),
177
- "mt-2 p-3 animate-fadeIn",
178
- ),
179
- children: _jsxs("div", {
180
- className:
181
- "text-sm italic text-foreground opacity-80 leading-relaxed whitespace-pre-wrap",
182
- children: [
183
- content,
184
- isStreaming &&
185
- content &&
186
- _jsx("span", {
187
- className: "inline-block animate-typing text-primary",
188
- children: "...",
189
- }),
190
- ],
191
- }),
192
- }),
193
- ],
194
- });
195
- },
196
- );
11
+ const reasoningContainerVariants = cva("mb-3 rounded-lg bg-card border border-border transition-all", {
12
+ variants: {
13
+ variant: {
14
+ default: "opacity-70",
15
+ subtle: "opacity-50",
16
+ prominent: "opacity-90 shadow-sm",
17
+ },
18
+ },
19
+ defaultVariants: {
20
+ variant: "default",
21
+ },
22
+ });
23
+ const reasoningIconVariants = cva("w-4 h-4 text-foreground opacity-60 transition-transform duration-200", {
24
+ variants: {
25
+ expanded: {
26
+ true: "rotate-180",
27
+ false: "",
28
+ },
29
+ },
30
+ defaultVariants: {
31
+ expanded: false,
32
+ },
33
+ });
34
+ export const Reasoning = React.forwardRef(({ content, isStreaming = false, mode = "collapsible", defaultExpanded = false, autoExpand = false, autoCollapse = true, autoCollapseDelay = 2000, label = "Thinking", variant, className, }, ref) => {
35
+ const [isExpanded, setIsExpanded] = useState(mode === "inline" ? true : defaultExpanded);
36
+ const [shouldAutoCollapse, setShouldAutoCollapse] = useState(false);
37
+ // Handle auto-collapse after streaming completes
38
+ useEffect(() => {
39
+ if (autoCollapse && !isStreaming && content && mode === "collapsible") {
40
+ const timer = setTimeout(() => {
41
+ setShouldAutoCollapse(true);
42
+ setIsExpanded(false);
43
+ }, autoCollapseDelay);
44
+ return () => clearTimeout(timer);
45
+ }
46
+ return undefined;
47
+ }, [isStreaming, content, autoCollapse, autoCollapseDelay, mode]);
48
+ // Auto-expand when streaming starts (only if autoExpand is enabled)
49
+ useEffect(() => {
50
+ if (autoExpand &&
51
+ isStreaming &&
52
+ mode === "collapsible" &&
53
+ !shouldAutoCollapse) {
54
+ setIsExpanded(true);
55
+ }
56
+ }, [autoExpand, isStreaming, mode, shouldAutoCollapse]);
57
+ if (!content && !isStreaming) {
58
+ return null;
59
+ }
60
+ // Inline mode - always visible
61
+ if (mode === "inline") {
62
+ return (_jsxs("div", { ref: ref, className: cn(reasoningContainerVariants({ variant }), "p-3", className), children: [_jsxs("div", { className: "flex items-start gap-2 mb-2", children: [_jsx("span", { className: "text-xs font-medium text-foreground opacity-60 uppercase tracking-wide", children: label }), isStreaming && (_jsx("span", { className: "inline-block w-2 h-2 bg-primary rounded-full animate-pulse" }))] }), _jsxs("div", { className: "text-sm italic text-foreground opacity-80 leading-relaxed whitespace-pre-wrap", children: [content, isStreaming && content && (_jsx("span", { className: "inline-block animate-typing text-primary", children: "..." }))] })] }));
63
+ }
64
+ // Collapsible mode
65
+ return (_jsxs("div", { ref: ref, className: cn("mb-3", className), children: [_jsxs("button", { type: "button", onClick: () => {
66
+ setIsExpanded(!isExpanded);
67
+ setShouldAutoCollapse(false); // Disable auto-collapse on manual interaction
68
+ }, className: "w-full flex items-center justify-between p-2.5 rounded-lg bg-card border border-border hover:bg-card/80 hover:shadow-sm transition-all text-left", "aria-expanded": isExpanded, "aria-label": `${isExpanded ? "Collapse" : "Expand"} reasoning`, children: [_jsxs("div", { className: "flex items-center gap-2 flex-1 min-w-0", children: [_jsx("span", { className: "text-xs font-medium text-foreground opacity-60 uppercase tracking-wide shrink-0", children: label }), isStreaming && (_jsx("span", { className: "inline-block w-2 h-2 bg-primary rounded-full animate-pulse shrink-0" })), !isExpanded && content && (_jsxs("span", { className: "text-xs text-foreground opacity-50 truncate", children: [content.substring(0, 60), content.length > 60 && "..."] }))] }), _jsx(ChevronDown, { className: reasoningIconVariants({ expanded: isExpanded }), "aria-hidden": "true" })] }), isExpanded && (_jsx("div", { className: cn(reasoningContainerVariants({ variant }), "mt-2 p-3 animate-fadeIn"), children: _jsxs("div", { className: "text-sm italic text-foreground opacity-80 leading-relaxed whitespace-pre-wrap", children: [content, isStreaming && content && (_jsx("span", { className: "inline-block animate-typing text-primary", children: "..." }))] }) }))] }));
69
+ });
197
70
  Reasoning.displayName = "Reasoning";
@@ -4,15 +4,13 @@ import * as React from "react";
4
4
  * Streaming-optimized markdown renderer for AI-generated content
5
5
  */
6
6
  export interface ResponseProps extends React.HTMLAttributes<HTMLDivElement> {
7
- /** The markdown content to render */
8
- content: string;
9
- /** Whether the content is currently streaming */
10
- isStreaming?: boolean;
11
- /** Show empty state when no content */
12
- showEmpty?: boolean;
13
- /** Custom empty state message */
14
- emptyMessage?: string;
7
+ /** The markdown content to render */
8
+ content: string;
9
+ /** Whether the content is currently streaming */
10
+ isStreaming?: boolean;
11
+ /** Show empty state when no content */
12
+ showEmpty?: boolean;
13
+ /** Custom empty state message */
14
+ emptyMessage?: string;
15
15
  }
16
- export declare const Response: React.ForwardRefExoticComponent<
17
- ResponseProps & React.RefAttributes<HTMLDivElement>
18
- >;
16
+ export declare const Response: React.ForwardRefExoticComponent<ResponseProps & React.RefAttributes<HTMLDivElement>>;