@townco/ui 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -11
- package/dist/core/hooks/index.d.ts +1 -0
- package/dist/core/hooks/index.js +1 -0
- package/dist/core/hooks/use-chat-input.d.ts +17 -17
- package/dist/core/hooks/use-chat-input.js +55 -64
- package/dist/core/hooks/use-chat-messages.d.ts +11 -11
- package/dist/core/hooks/use-chat-messages.js +114 -121
- package/dist/core/hooks/use-chat-session.d.ts +5 -5
- package/dist/core/hooks/use-chat-session.js +80 -78
- package/dist/core/hooks/use-media-query.d.ts +5 -5
- package/dist/core/hooks/use-media-query.js +42 -38
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/schemas/chat.d.ts +56 -83
- package/dist/core/schemas/chat.js +25 -27
- package/dist/core/store/chat-store.d.ts +22 -28
- package/dist/core/store/chat-store.js +50 -59
- package/dist/gui/components/Button.d.ts +7 -23
- package/dist/gui/components/Button.js +27 -40
- package/dist/gui/components/Card.d.ts +7 -26
- package/dist/gui/components/Card.js +8 -54
- package/dist/gui/components/ChatHeader.d.ts +31 -58
- package/dist/gui/components/ChatHeader.js +68 -171
- package/dist/gui/components/ChatInput.d.ts +54 -58
- package/dist/gui/components/ChatInput.js +207 -194
- package/dist/gui/components/ChatInputCommandMenu.d.ts +20 -0
- package/dist/gui/components/ChatInputCommandMenu.js +62 -0
- package/dist/gui/components/ChatLayout.d.ts +41 -71
- package/dist/gui/components/ChatLayout.js +87 -214
- package/dist/gui/components/ChatPanelTabContent.d.ts +9 -18
- package/dist/gui/components/ChatPanelTabContent.js +10 -88
- package/dist/gui/components/ChatSecondaryPanel.d.ts +11 -14
- package/dist/gui/components/ChatSecondaryPanel.js +38 -115
- package/dist/gui/components/ChatSidebar.d.ts +13 -26
- package/dist/gui/components/ChatSidebar.js +14 -48
- package/dist/gui/components/ChatStatus.d.ts +2 -4
- package/dist/gui/components/ChatStatus.js +34 -45
- package/dist/gui/components/Conversation.d.ts +14 -17
- package/dist/gui/components/Conversation.js +83 -143
- package/dist/gui/components/Dialog.d.ts +11 -57
- package/dist/gui/components/Dialog.js +8 -84
- package/dist/gui/components/DropdownMenu.d.ts +20 -101
- package/dist/gui/components/DropdownMenu.js +14 -161
- package/dist/gui/components/HeightTransition.d.ts +7 -12
- package/dist/gui/components/HeightTransition.js +77 -88
- package/dist/gui/components/Input.d.ts +6 -13
- package/dist/gui/components/Input.js +16 -27
- package/dist/gui/components/Label.d.ts +1 -7
- package/dist/gui/components/Label.js +2 -12
- package/dist/gui/components/MarkdownRenderer.d.ts +4 -6
- package/dist/gui/components/MarkdownRenderer.js +81 -178
- package/dist/gui/components/Message.d.ts +22 -25
- package/dist/gui/components/Message.js +97 -44
- package/dist/gui/components/MessageContent.d.ts +22 -29
- package/dist/gui/components/MessageContent.js +85 -157
- package/dist/gui/components/Reasoning.d.ts +24 -30
- package/dist/gui/components/Reasoning.js +60 -187
- package/dist/gui/components/Response.d.ts +9 -11
- package/dist/gui/components/Response.js +90 -229
- package/dist/gui/components/Select.d.ts +10 -69
- package/dist/gui/components/Select.js +12 -118
- package/dist/gui/components/Sonner.d.ts +1 -3
- package/dist/gui/components/Sonner.js +18 -29
- package/dist/gui/components/Tabs.d.ts +4 -24
- package/dist/gui/components/Tabs.js +4 -32
- package/dist/gui/components/Task.d.ts +24 -28
- package/dist/gui/components/Task.js +31 -164
- package/dist/gui/components/Textarea.d.ts +7 -15
- package/dist/gui/components/Textarea.js +46 -63
- package/dist/gui/components/ThinkingBlock.d.ts +10 -20
- package/dist/gui/components/ThinkingBlock.js +35 -134
- package/dist/gui/components/TodoList.d.ts +10 -12
- package/dist/gui/components/TodoList.js +7 -22
- package/dist/gui/components/TodoListItem.d.ts +6 -9
- package/dist/gui/components/TodoListItem.js +4 -18
- package/dist/gui/components/index.d.ts +16 -59
- package/dist/gui/components/index.js +18 -42
- package/dist/gui/lib/utils.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.test.js +1 -0
- package/dist/sdk/client/acp-client.d.ts +76 -88
- package/dist/sdk/client/acp-client.js +217 -215
- package/dist/sdk/index.d.ts +1 -1
- package/dist/sdk/index.js +1 -1
- package/dist/sdk/schemas/agent.d.ts +64 -111
- package/dist/sdk/schemas/agent.js +24 -24
- package/dist/sdk/schemas/message.d.ts +147 -245
- package/dist/sdk/schemas/message.js +40 -40
- package/dist/sdk/schemas/session.d.ts +135 -219
- package/dist/sdk/schemas/session.js +27 -27
- package/dist/sdk/transports/http.d.ts +55 -55
- package/dist/sdk/transports/http.js +469 -472
- package/dist/sdk/transports/stdio.d.ts +20 -20
- package/dist/sdk/transports/stdio.js +286 -289
- package/dist/sdk/transports/types.d.ts +42 -42
- package/dist/sdk/transports/websocket.d.ts +12 -12
- package/dist/sdk/transports/websocket.js +46 -52
- package/dist/tui/components/ChatView.d.ts +2 -4
- package/dist/tui/components/ChatView.js +18 -51
- package/dist/tui/components/GameOfLife.js +35 -64
- package/dist/tui/components/InputBox.d.ts +11 -18
- package/dist/tui/components/InputBox.js +10 -70
- package/dist/tui/components/MessageList.d.ts +2 -4
- package/dist/tui/components/MessageList.js +10 -37
- package/dist/tui/components/MultiSelect.d.ts +10 -15
- package/dist/tui/components/MultiSelect.js +73 -116
- package/dist/tui/components/ReadlineInput.d.ts +6 -12
- package/dist/tui/components/ReadlineInput.js +237 -252
- package/dist/tui/components/SingleSelect.d.ts +9 -15
- package/dist/tui/components/SingleSelect.js +43 -84
- package/dist/tui/components/StatusBar.d.ts +6 -11
- package/dist/tui/components/StatusBar.js +67 -102
- package/dist/tui/index.d.ts +1 -1
- package/dist/tui/index.js +1 -1
- package/package.json +6 -4
- package/src/styles/global.css +2 -0
- package/dist/core/hooks/index.d.ts.map +0 -1
- package/dist/core/hooks/index.js.map +0 -1
- package/dist/core/hooks/use-chat-input.d.ts.map +0 -1
- package/dist/core/hooks/use-chat-input.js.map +0 -1
- package/dist/core/hooks/use-chat-messages.d.ts.map +0 -1
- package/dist/core/hooks/use-chat-messages.js.map +0 -1
- package/dist/core/hooks/use-chat-session.d.ts.map +0 -1
- package/dist/core/hooks/use-chat-session.js.map +0 -1
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js.map +0 -1
- package/dist/core/schemas/chat.d.ts.map +0 -1
- package/dist/core/schemas/chat.js.map +0 -1
- package/dist/core/schemas/index.d.ts.map +0 -1
- package/dist/core/schemas/index.js.map +0 -1
- package/dist/core/store/chat-store.d.ts.map +0 -1
- package/dist/core/store/chat-store.js.map +0 -1
- package/dist/gui/components/Button.d.ts.map +0 -1
- package/dist/gui/components/Button.js.map +0 -1
- package/dist/gui/components/Card.d.ts.map +0 -1
- package/dist/gui/components/Card.js.map +0 -1
- package/dist/gui/components/ChatInput.d.ts.map +0 -1
- package/dist/gui/components/ChatInput.js.map +0 -1
- package/dist/gui/components/ChatInterface.d.ts +0 -12
- package/dist/gui/components/ChatInterface.d.ts.map +0 -1
- package/dist/gui/components/ChatInterface.js +0 -204
- package/dist/gui/components/ChatInterface.js.map +0 -1
- package/dist/gui/components/ChatPreview.d.ts +0 -12
- package/dist/gui/components/ChatPreview.d.ts.map +0 -1
- package/dist/gui/components/ChatPreview.js +0 -214
- package/dist/gui/components/ChatPreview.js.map +0 -1
- package/dist/gui/components/ChatSecondaryPanel.d.ts.map +0 -1
- package/dist/gui/components/ChatSecondaryPanel.js.map +0 -1
- package/dist/gui/components/ChatStatus.d.ts.map +0 -1
- package/dist/gui/components/ChatStatus.js.map +0 -1
- package/dist/gui/components/ChatView.d.ts +0 -8
- package/dist/gui/components/ChatView.d.ts.map +0 -1
- package/dist/gui/components/ChatView.js +0 -42
- package/dist/gui/components/ChatView.js.map +0 -1
- package/dist/gui/components/ConfigPanel.d.ts +0 -20
- package/dist/gui/components/ConfigPanel.d.ts.map +0 -1
- package/dist/gui/components/ConfigPanel.js +0 -225
- package/dist/gui/components/ConfigPanel.js.map +0 -1
- package/dist/gui/components/Conversation.d.ts.map +0 -1
- package/dist/gui/components/Conversation.js.map +0 -1
- package/dist/gui/components/Dialog.d.ts.map +0 -1
- package/dist/gui/components/Dialog.js.map +0 -1
- package/dist/gui/components/HeightTransition.d.ts.map +0 -1
- package/dist/gui/components/HeightTransition.js.map +0 -1
- package/dist/gui/components/Input.d.ts.map +0 -1
- package/dist/gui/components/Input.js.map +0 -1
- package/dist/gui/components/InputBox.d.ts +0 -21
- package/dist/gui/components/InputBox.d.ts.map +0 -1
- package/dist/gui/components/InputBox.js +0 -90
- package/dist/gui/components/InputBox.js.map +0 -1
- package/dist/gui/components/Label.d.ts.map +0 -1
- package/dist/gui/components/Label.js.map +0 -1
- package/dist/gui/components/MarkdownRenderer.d.ts.map +0 -1
- package/dist/gui/components/MarkdownRenderer.js.map +0 -1
- package/dist/gui/components/Message.d.ts.map +0 -1
- package/dist/gui/components/Message.js.map +0 -1
- package/dist/gui/components/MessageContent.d.ts.map +0 -1
- package/dist/gui/components/MessageContent.js.map +0 -1
- package/dist/gui/components/MessageList.d.ts.map +0 -1
- package/dist/gui/components/MessageList.js.map +0 -1
- package/dist/gui/components/PlaygroundLayout.d.ts +0 -14
- package/dist/gui/components/PlaygroundLayout.d.ts.map +0 -1
- package/dist/gui/components/PlaygroundLayout.js +0 -49
- package/dist/gui/components/PlaygroundLayout.js.map +0 -1
- package/dist/gui/components/Reasoning.d.ts.map +0 -1
- package/dist/gui/components/Reasoning.js.map +0 -1
- package/dist/gui/components/Response.d.ts.map +0 -1
- package/dist/gui/components/Response.js.map +0 -1
- package/dist/gui/components/Select.d.ts.map +0 -1
- package/dist/gui/components/Select.js.map +0 -1
- package/dist/gui/components/StatusBar.d.ts +0 -12
- package/dist/gui/components/StatusBar.d.ts.map +0 -1
- package/dist/gui/components/StatusBar.js +0 -58
- package/dist/gui/components/StatusBar.js.map +0 -1
- package/dist/gui/components/Tabs.d.ts.map +0 -1
- package/dist/gui/components/Tabs.js.map +0 -1
- package/dist/gui/components/Task.d.ts.map +0 -1
- package/dist/gui/components/Task.js.map +0 -1
- package/dist/gui/components/Textarea.d.ts.map +0 -1
- package/dist/gui/components/Textarea.js.map +0 -1
- package/dist/gui/components/ThinkingBlock.d.ts.map +0 -1
- package/dist/gui/components/ThinkingBlock.js.map +0 -1
- package/dist/gui/components/TodoList.d.ts.map +0 -1
- package/dist/gui/components/TodoList.js.map +0 -1
- package/dist/gui/components/TodoListItem.d.ts.map +0 -1
- package/dist/gui/components/TodoListItem.js.map +0 -1
- package/dist/gui/components/index.d.ts.map +0 -1
- package/dist/gui/components/index.js.map +0 -1
- package/dist/gui/index.d.ts.map +0 -1
- package/dist/gui/index.js.map +0 -1
- package/dist/gui/lib/utils.d.ts.map +0 -1
- package/dist/gui/lib/utils.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/sdk/client/acp-client.d.ts.map +0 -1
- package/dist/sdk/client/acp-client.js.map +0 -1
- package/dist/sdk/client/index.d.ts.map +0 -1
- package/dist/sdk/client/index.js.map +0 -1
- package/dist/sdk/index.d.ts.map +0 -1
- package/dist/sdk/index.js.map +0 -1
- package/dist/sdk/schemas/agent.d.ts.map +0 -1
- package/dist/sdk/schemas/agent.js.map +0 -1
- package/dist/sdk/schemas/index.d.ts.map +0 -1
- package/dist/sdk/schemas/index.js.map +0 -1
- package/dist/sdk/schemas/message.d.ts.map +0 -1
- package/dist/sdk/schemas/message.js.map +0 -1
- package/dist/sdk/schemas/session.d.ts.map +0 -1
- package/dist/sdk/schemas/session.js.map +0 -1
- package/dist/sdk/transports/http.d.ts.map +0 -1
- package/dist/sdk/transports/http.js.map +0 -1
- package/dist/sdk/transports/index.d.ts.map +0 -1
- package/dist/sdk/transports/index.js.map +0 -1
- package/dist/sdk/transports/stdio.d.ts.map +0 -1
- package/dist/sdk/transports/stdio.js.map +0 -1
- package/dist/sdk/transports/types.d.ts.map +0 -1
- package/dist/sdk/transports/types.js.map +0 -1
- package/dist/sdk/transports/websocket.d.ts.map +0 -1
- package/dist/sdk/transports/websocket.js.map +0 -1
- package/dist/tui/components/ChatView.d.ts.map +0 -1
- package/dist/tui/components/ChatView.js.map +0 -1
- package/dist/tui/components/GameOfLife.d.ts.map +0 -1
- package/dist/tui/components/GameOfLife.js.map +0 -1
- package/dist/tui/components/InputBox.d.ts.map +0 -1
- package/dist/tui/components/InputBox.js.map +0 -1
- package/dist/tui/components/MessageList.d.ts.map +0 -1
- package/dist/tui/components/MessageList.js.map +0 -1
- package/dist/tui/components/ReadlineInput.d.ts.map +0 -1
- package/dist/tui/components/ReadlineInput.js.map +0 -1
- package/dist/tui/components/StatusBar.d.ts.map +0 -1
- package/dist/tui/components/StatusBar.js.map +0 -1
- package/dist/tui/components/index.d.ts.map +0 -1
- package/dist/tui/components/index.js.map +0 -1
- package/dist/tui/index.d.ts.map +0 -1
- package/dist/tui/index.js.map +0 -1
|
@@ -1,54 +1,107 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
2
|
import { cva } from "class-variance-authority";
|
|
2
3
|
import * as React from "react";
|
|
3
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
4
|
import { cn } from "../lib/utils.js";
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* Message wrapper component inspired by shadcn.io/ai
|
|
8
7
|
* Provides role-based layout and styling for chat messages
|
|
9
8
|
*/
|
|
10
9
|
const messageVariants = cva("flex animate-fadeIn", {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
10
|
+
variants: {
|
|
11
|
+
role: {
|
|
12
|
+
user: "max-w-[80%] self-end ml-auto mr-2",
|
|
13
|
+
assistant: "self-start mr-auto",
|
|
14
|
+
system: "self-start mr-auto max-w-full",
|
|
15
|
+
},
|
|
16
|
+
layout: {
|
|
17
|
+
default: "",
|
|
18
|
+
full: "max-w-full",
|
|
19
|
+
compact: "max-w-[90%]",
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
defaultVariants: {
|
|
23
|
+
role: "assistant",
|
|
24
|
+
layout: "default",
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
export const Message = React.forwardRef(({ message, role: roleProp, layout, className, children, messageId: messageIdProp, autoScroll, isLastMessage = false, ...props }, ref) => {
|
|
28
|
+
// Extract role and messageId from message if provided
|
|
29
|
+
const role = message ? message.role : roleProp || "assistant";
|
|
30
|
+
const messageId = message ? message.id : messageIdProp;
|
|
31
|
+
const messageRef = React.useRef(null);
|
|
32
|
+
const [minHeight, setMinHeight] = React.useState(undefined);
|
|
33
|
+
// Merge refs
|
|
34
|
+
React.useImperativeHandle(ref, () => messageRef.current);
|
|
35
|
+
// Calculate dynamic min-height for last assistant message following a user message
|
|
36
|
+
React.useEffect(() => {
|
|
37
|
+
if (!isLastMessage || role !== "assistant") {
|
|
38
|
+
setMinHeight(undefined);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const calculateMinHeight = () => {
|
|
42
|
+
const messageElement = messageRef.current;
|
|
43
|
+
if (!messageElement)
|
|
44
|
+
return;
|
|
45
|
+
// Find the ChatLayout.Messages container (scrollable parent)
|
|
46
|
+
let scrollContainer = messageElement.parentElement;
|
|
47
|
+
while (scrollContainer &&
|
|
48
|
+
!scrollContainer.classList.contains("overflow-y-auto")) {
|
|
49
|
+
scrollContainer = scrollContainer.parentElement;
|
|
50
|
+
}
|
|
51
|
+
if (!scrollContainer)
|
|
52
|
+
return;
|
|
53
|
+
// Find the previous user message
|
|
54
|
+
const previousSibling = messageElement.previousElementSibling;
|
|
55
|
+
if (!previousSibling ||
|
|
56
|
+
previousSibling.getAttribute("aria-label") !== "user message") {
|
|
57
|
+
setMinHeight(undefined);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
// Calculate: containerHeight - previousUserMessageHeight - spacing
|
|
61
|
+
const containerHeight = scrollContainer.clientHeight;
|
|
62
|
+
const previousMessageHeight = previousSibling.offsetHeight;
|
|
63
|
+
const spacing = 32; // gap-4 = 16px
|
|
64
|
+
// Min height = container height - user message height - spacing
|
|
65
|
+
// This ensures the user message can scroll to the top
|
|
66
|
+
const calculatedMinHeight = Math.max(0, containerHeight - previousMessageHeight - spacing);
|
|
67
|
+
setMinHeight(calculatedMinHeight);
|
|
68
|
+
};
|
|
69
|
+
// Calculate on mount and recalculate on resize
|
|
70
|
+
calculateMinHeight();
|
|
71
|
+
const resizeObserver = new ResizeObserver(calculateMinHeight);
|
|
72
|
+
// Observe the message element and its parent container
|
|
73
|
+
if (messageRef.current) {
|
|
74
|
+
resizeObserver.observe(messageRef.current);
|
|
75
|
+
let scrollContainer = messageRef.current.parentElement;
|
|
76
|
+
while (scrollContainer &&
|
|
77
|
+
!scrollContainer.classList.contains("overflow-y-auto")) {
|
|
78
|
+
scrollContainer = scrollContainer.parentElement;
|
|
79
|
+
}
|
|
80
|
+
if (scrollContainer) {
|
|
81
|
+
resizeObserver.observe(scrollContainer);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return () => resizeObserver.disconnect();
|
|
85
|
+
}, [isLastMessage, role]);
|
|
86
|
+
// Auto-scroll for user messages when they first appear
|
|
87
|
+
React.useEffect(() => {
|
|
88
|
+
// Default to auto-scroll for user messages unless explicitly disabled
|
|
89
|
+
const shouldAutoScroll = autoScroll !== undefined ? autoScroll : role === "user";
|
|
90
|
+
if (shouldAutoScroll && messageRef.current) {
|
|
91
|
+
// Small delay to ensure the message is fully rendered
|
|
92
|
+
const timeoutId = setTimeout(() => {
|
|
93
|
+
messageRef.current?.scrollIntoView({
|
|
94
|
+
behavior: "smooth",
|
|
95
|
+
block: "start",
|
|
96
|
+
inline: "nearest",
|
|
97
|
+
});
|
|
98
|
+
}, 50);
|
|
99
|
+
return () => clearTimeout(timeoutId);
|
|
100
|
+
}
|
|
101
|
+
return undefined;
|
|
102
|
+
}, [role, autoScroll]);
|
|
103
|
+
return (_jsx("article", { ref: messageRef, "aria-label": `${role} message`, "data-message-id": messageId, className: cn(messageVariants({ role, layout }), className), style: {
|
|
104
|
+
minHeight: minHeight !== undefined ? `${minHeight}px` : undefined,
|
|
105
|
+
}, ...props, children: children }));
|
|
27
106
|
});
|
|
28
|
-
export const Message = React.forwardRef(
|
|
29
|
-
(
|
|
30
|
-
{
|
|
31
|
-
message,
|
|
32
|
-
role: roleProp,
|
|
33
|
-
layout,
|
|
34
|
-
className,
|
|
35
|
-
children,
|
|
36
|
-
messageId: messageIdProp,
|
|
37
|
-
...props
|
|
38
|
-
},
|
|
39
|
-
ref,
|
|
40
|
-
) => {
|
|
41
|
-
// Extract role and messageId from message if provided
|
|
42
|
-
const role = message ? message.role : roleProp || "assistant";
|
|
43
|
-
const messageId = message ? message.id : messageIdProp;
|
|
44
|
-
return _jsx("article", {
|
|
45
|
-
ref: ref,
|
|
46
|
-
"aria-label": `${role} message`,
|
|
47
|
-
"data-message-id": messageId,
|
|
48
|
-
className: cn(messageVariants({ role, layout }), className),
|
|
49
|
-
...props,
|
|
50
|
-
children: children,
|
|
51
|
-
});
|
|
52
|
-
},
|
|
53
|
-
);
|
|
54
107
|
Message.displayName = "Message";
|
|
@@ -1,33 +1,26 @@
|
|
|
1
1
|
import { type VariantProps } from "class-variance-authority";
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import type { DisplayMessage } from "./MessageList.js";
|
|
4
|
-
declare const messageContentVariants: (
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
*/
|
|
25
|
-
message?: DisplayMessage;
|
|
26
|
-
/** Display style for thinking/reasoning blocks (when using smart rendering) */
|
|
27
|
-
thinkingDisplayStyle?: "collapsible" | "inline";
|
|
28
|
-
/** Custom content (overrides smart rendering) */
|
|
29
|
-
children?: React.ReactNode;
|
|
4
|
+
declare const messageContentVariants: (props?: ({
|
|
5
|
+
role?: "user" | "assistant" | "system" | null | undefined;
|
|
6
|
+
variant?: "default" | "outline" | "ghost" | null | undefined;
|
|
7
|
+
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
8
|
+
export interface MessageContentProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "children">, VariantProps<typeof messageContentVariants> {
|
|
9
|
+
/** Message role - determines styling */
|
|
10
|
+
role?: "user" | "assistant" | "system";
|
|
11
|
+
/** Visual variant */
|
|
12
|
+
variant?: "default" | "outline" | "ghost";
|
|
13
|
+
/** Whether the message is currently streaming */
|
|
14
|
+
isStreaming?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Message object for smart rendering (optional)
|
|
17
|
+
* When provided, automatically renders thinking, waiting, and content
|
|
18
|
+
*/
|
|
19
|
+
message?: DisplayMessage;
|
|
20
|
+
/** Display style for thinking/reasoning blocks (when using smart rendering) */
|
|
21
|
+
thinkingDisplayStyle?: "collapsible" | "inline";
|
|
22
|
+
/** Custom content (overrides smart rendering) */
|
|
23
|
+
children?: React.ReactNode;
|
|
30
24
|
}
|
|
31
|
-
export declare const MessageContent: React.ForwardRefExoticComponent<
|
|
32
|
-
|
|
33
|
-
>;
|
|
25
|
+
export declare const MessageContent: React.ForwardRefExoticComponent<MessageContentProps & React.RefAttributes<HTMLDivElement>>;
|
|
26
|
+
export {};
|
|
@@ -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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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: "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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
37
|
-
>;
|
|
30
|
+
export declare const Reasoning: React.ForwardRefExoticComponent<ReasoningProps & React.RefAttributes<HTMLDivElement>>;
|
|
31
|
+
export {};
|