@moldable-ai/ui 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/LICENSE +101 -0
  2. package/dist/components/chat/chat-input.d.ts +14 -0
  3. package/dist/components/chat/chat-input.d.ts.map +1 -0
  4. package/dist/components/chat/chat-input.js +36 -0
  5. package/dist/components/chat/chat-message.d.ts +30 -0
  6. package/dist/components/chat/chat-message.d.ts.map +1 -0
  7. package/dist/components/chat/chat-message.js +250 -0
  8. package/dist/components/chat/chat-messages.d.ts +10 -0
  9. package/dist/components/chat/chat-messages.d.ts.map +1 -0
  10. package/dist/components/chat/chat-messages.js +30 -0
  11. package/dist/components/chat/chat-panel.d.ts +60 -0
  12. package/dist/components/chat/chat-panel.d.ts.map +1 -0
  13. package/dist/components/chat/chat-panel.js +115 -0
  14. package/dist/components/chat/conversation-history.d.ts +18 -0
  15. package/dist/components/chat/conversation-history.d.ts.map +1 -0
  16. package/dist/components/chat/conversation-history.js +32 -0
  17. package/dist/components/chat/index.d.ts +10 -0
  18. package/dist/components/chat/index.d.ts.map +1 -0
  19. package/dist/components/chat/index.js +9 -0
  20. package/dist/components/chat/model-selector.d.ts +16 -0
  21. package/dist/components/chat/model-selector.d.ts.map +1 -0
  22. package/dist/components/chat/model-selector.js +9 -0
  23. package/dist/components/chat/reasoning-effort-selector.d.ts +14 -0
  24. package/dist/components/chat/reasoning-effort-selector.d.ts.map +1 -0
  25. package/dist/components/chat/reasoning-effort-selector.js +10 -0
  26. package/dist/components/chat/thinking-timeline.d.ts +21 -0
  27. package/dist/components/chat/thinking-timeline.d.ts.map +1 -0
  28. package/dist/components/chat/thinking-timeline.js +46 -0
  29. package/dist/components/chat/tool-handlers.d.ts +21 -0
  30. package/dist/components/chat/tool-handlers.d.ts.map +1 -0
  31. package/dist/components/chat/tool-handlers.js +434 -0
  32. package/dist/components/code-block.d.ts +9 -0
  33. package/dist/components/code-block.d.ts.map +1 -0
  34. package/dist/components/code-block.js +112 -0
  35. package/dist/components/markdown.d.ts +10 -0
  36. package/dist/components/markdown.d.ts.map +1 -0
  37. package/dist/components/markdown.js +189 -0
  38. package/dist/components/ui/alert-dialog.d.ts +15 -0
  39. package/dist/components/ui/alert-dialog.d.ts.map +1 -0
  40. package/dist/components/ui/alert-dialog.js +38 -0
  41. package/dist/components/ui/badge.d.ts +10 -0
  42. package/dist/components/ui/badge.d.ts.map +1 -0
  43. package/dist/components/ui/badge.js +22 -0
  44. package/dist/components/ui/button.d.ts +12 -0
  45. package/dist/components/ui/button.d.ts.map +1 -0
  46. package/dist/components/ui/button.js +35 -0
  47. package/dist/components/ui/card.d.ts +9 -0
  48. package/dist/components/ui/card.d.ts.map +1 -0
  49. package/dist/components/ui/card.js +16 -0
  50. package/dist/components/ui/checkbox.d.ts +5 -0
  51. package/dist/components/ui/checkbox.d.ts.map +1 -0
  52. package/dist/components/ui/checkbox.js +9 -0
  53. package/dist/components/ui/collapsible.d.ts +6 -0
  54. package/dist/components/ui/collapsible.d.ts.map +1 -0
  55. package/dist/components/ui/collapsible.js +5 -0
  56. package/dist/components/ui/command.d.ts +19 -0
  57. package/dist/components/ui/command.d.ts.map +1 -0
  58. package/dist/components/ui/command.js +29 -0
  59. package/dist/components/ui/dialog.d.ts +20 -0
  60. package/dist/components/ui/dialog.d.ts.map +1 -0
  61. package/dist/components/ui/dialog.js +23 -0
  62. package/dist/components/ui/dropdown-menu.d.ts +26 -0
  63. package/dist/components/ui/dropdown-menu.d.ts.map +1 -0
  64. package/dist/components/ui/dropdown-menu.js +51 -0
  65. package/dist/components/ui/index.d.ts +19 -0
  66. package/dist/components/ui/index.d.ts.map +1 -0
  67. package/dist/components/ui/index.js +18 -0
  68. package/dist/components/ui/input.d.ts +5 -0
  69. package/dist/components/ui/input.d.ts.map +1 -0
  70. package/dist/components/ui/input.js +8 -0
  71. package/dist/components/ui/label.d.ts +5 -0
  72. package/dist/components/ui/label.d.ts.map +1 -0
  73. package/dist/components/ui/label.js +8 -0
  74. package/dist/components/ui/popover.d.ts +8 -0
  75. package/dist/components/ui/popover.d.ts.map +1 -0
  76. package/dist/components/ui/popover.js +16 -0
  77. package/dist/components/ui/scroll-area.d.ts +6 -0
  78. package/dist/components/ui/scroll-area.d.ts.map +1 -0
  79. package/dist/components/ui/scroll-area.js +11 -0
  80. package/dist/components/ui/select.d.ts +14 -0
  81. package/dist/components/ui/select.d.ts.map +1 -0
  82. package/dist/components/ui/select.js +26 -0
  83. package/dist/components/ui/switch.d.ts +5 -0
  84. package/dist/components/ui/switch.d.ts.map +1 -0
  85. package/dist/components/ui/switch.js +8 -0
  86. package/dist/components/ui/tabs.d.ts +8 -0
  87. package/dist/components/ui/tabs.d.ts.map +1 -0
  88. package/dist/components/ui/tabs.js +16 -0
  89. package/dist/components/ui/textarea.d.ts +5 -0
  90. package/dist/components/ui/textarea.d.ts.map +1 -0
  91. package/dist/components/ui/textarea.js +8 -0
  92. package/dist/components/ui/tooltip.d.ts +8 -0
  93. package/dist/components/ui/tooltip.d.ts.map +1 -0
  94. package/dist/components/ui/tooltip.js +17 -0
  95. package/dist/components/widget-layout.d.ts +10 -0
  96. package/dist/components/widget-layout.d.ts.map +1 -0
  97. package/dist/components/widget-layout.js +30 -0
  98. package/dist/index.d.ts +10 -0
  99. package/dist/index.d.ts.map +1 -0
  100. package/dist/index.js +18 -0
  101. package/dist/lib/commands.d.ts +74 -0
  102. package/dist/lib/commands.d.ts.map +1 -0
  103. package/dist/lib/commands.js +73 -0
  104. package/dist/lib/commands.test.d.ts +2 -0
  105. package/dist/lib/commands.test.d.ts.map +1 -0
  106. package/dist/lib/commands.test.js +111 -0
  107. package/dist/lib/theme.d.ts +25 -0
  108. package/dist/lib/theme.d.ts.map +1 -0
  109. package/dist/lib/theme.js +103 -0
  110. package/dist/lib/utils.d.ts +3 -0
  111. package/dist/lib/utils.d.ts.map +1 -0
  112. package/dist/lib/utils.js +5 -0
  113. package/dist/lib/workspace.d.ts +41 -0
  114. package/dist/lib/workspace.d.ts.map +1 -0
  115. package/dist/lib/workspace.js +82 -0
  116. package/package.json +87 -0
  117. package/src/styles/index.css +199 -0
package/LICENSE ADDED
@@ -0,0 +1,101 @@
1
+ Copyright (c) 2026-present Desiderata LLC
2
+
3
+ Portions of this software are licensed as follows:
4
+
5
+ - All third party components incorporated into the Moldable Software are licensed
6
+ under the original license provided by the owner of the applicable component.
7
+ - All other content is available under the "Elastic License 2.0" license as defined below.
8
+
9
+ Elastic License 2.0
10
+
11
+ URL: https://www.elastic.co/licensing/elastic-license
12
+
13
+ ## Acceptance
14
+
15
+ By using the software, you agree to all of the terms and conditions below.
16
+
17
+ ## Copyright License
18
+
19
+ The licensor grants you a non-exclusive, royalty-free, worldwide,
20
+ non-sublicensable, non-transferable license to use, copy, distribute, make
21
+ available, and prepare derivative works of the software, in each case subject to
22
+ the limitations and conditions below.
23
+
24
+ ## Limitations
25
+
26
+ You may not provide the software to third parties as a hosted or managed
27
+ service, where the service provides users with access to any substantial set of
28
+ the features or functionality of the software.
29
+
30
+ You may not move, change, disable, or circumvent the license key functionality
31
+ in the software, and you may not remove or obscure any functionality in the
32
+ software that is protected by the license key.
33
+
34
+ You may not alter, remove, or obscure any licensing, copyright, or other notices
35
+ of the licensor in the software. Any use of the licensor's trademarks is subject
36
+ to applicable law.
37
+
38
+ ## Patents
39
+
40
+ The licensor grants you a license, under any patent claims the licensor can
41
+ license, or becomes able to license, to make, have made, use, sell, offer for
42
+ sale, import and have imported the software, in each case subject to the
43
+ limitations and conditions in this license. This license does not cover any
44
+ patent claims that you cause to be infringed by modifications or additions to
45
+ the software. If you or your company make any written claim that the software
46
+ infringes or contributes to infringement of any patent, your patent license for
47
+ the software granted under these terms ends immediately. If your company makes
48
+ such a claim, your patent license ends immediately for work on behalf of your
49
+ company.
50
+
51
+ ## Notices
52
+
53
+ You must ensure that anyone who gets a copy of any part of the software from you
54
+ also gets a copy of these terms.
55
+
56
+ If you modify the software, you must include in any modified copies of the
57
+ software prominent notices stating that you have modified the software.
58
+
59
+ ## No Other Rights
60
+
61
+ These terms do not imply any licenses other than those expressly granted in
62
+ these terms.
63
+
64
+ ## Termination
65
+
66
+ If you use the software in violation of these terms, such use is not licensed,
67
+ and your licenses will automatically terminate. If the licensor provides you
68
+ with a notice of your violation, and you cease all violation of this license no
69
+ later than 30 days after you receive that notice, your licenses will be
70
+ reinstated retroactively. However, if you violate these terms after such
71
+ reinstatement, any additional violation of these terms will cause your licenses
72
+ to terminate automatically and permanently.
73
+
74
+ ## No Liability
75
+
76
+ _As far as the law allows, the software comes as is, without any warranty or
77
+ condition, and the licensor will not be liable to you for any damages arising
78
+ out of these terms or the use or nature of the software, under any kind of
79
+ legal claim._
80
+
81
+ ## Definitions
82
+
83
+ The **licensor** is the entity offering these terms, and the **software** is the
84
+ software the licensor makes available under these terms, including any portion
85
+ of it.
86
+
87
+ **you** refers to the individual or entity agreeing to these terms.
88
+
89
+ **your company** is any legal entity, sole proprietorship, or other kind of
90
+ organization that you work for, plus all organizations that have control over,
91
+ are under the control of, or are under common control with that
92
+ organization. **control** means ownership of substantially all the assets of an
93
+ entity, or the power to direct its management and policies by vote, contract, or
94
+ otherwise. Control can be direct or indirect.
95
+
96
+ **your licenses** are all the licenses granted to you for the software under
97
+ these terms.
98
+
99
+ **use** means anything you do with the software requiring one of your licenses.
100
+
101
+ **trademark** means trademarks, service marks, and similar rights.
@@ -0,0 +1,14 @@
1
+ import type { ChangeEvent, FormEvent, RefObject } from 'react';
2
+ type ChatInputProps = {
3
+ input: string;
4
+ onInputChange: (e: ChangeEvent<HTMLTextAreaElement>) => void;
5
+ onSubmit: (e: FormEvent<HTMLFormElement>) => void;
6
+ isResponding: boolean;
7
+ placeholder?: string;
8
+ inputRef?: RefObject<HTMLTextAreaElement | null>;
9
+ onStop?: () => void;
10
+ compact?: boolean;
11
+ };
12
+ export declare function ChatInput({ input, onInputChange, onSubmit, isResponding, placeholder, inputRef, onStop, compact, }: ChatInputProps): import("react/jsx-runtime").JSX.Element;
13
+ export {};
14
+ //# sourceMappingURL=chat-input.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat-input.d.ts","sourceRoot":"","sources":["../../../src/components/chat/chat-input.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAiB,SAAS,EAAE,MAAM,OAAO,CAAA;AAK7E,KAAK,cAAc,GAAG;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,aAAa,EAAE,CAAC,CAAC,EAAE,WAAW,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAA;IAC5D,QAAQ,EAAE,CAAC,CAAC,EAAE,SAAS,CAAC,eAAe,CAAC,KAAK,IAAI,CAAA;IACjD,YAAY,EAAE,OAAO,CAAA;IACrB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,SAAS,CAAC,mBAAmB,GAAG,IAAI,CAAC,CAAA;IAChD,MAAM,CAAC,EAAE,MAAM,IAAI,CAAA;IACnB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,wBAAgB,SAAS,CAAC,EACxB,KAAK,EACL,aAAa,EACb,QAAQ,EACR,YAAY,EACZ,WAA+B,EAC/B,QAAQ,EACR,MAAM,EACN,OAAe,GAChB,EAAE,cAAc,2CAoFhB"}
@@ -0,0 +1,36 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ArrowUp, Square } from 'lucide-react';
3
+ import { cn } from '../../lib/utils';
4
+ import { Button } from '../ui/button';
5
+ import { Textarea } from '../ui/textarea';
6
+ export function ChatInput({ input, onInputChange, onSubmit, isResponding, placeholder = 'Ask anything...', inputRef, onStop, compact = false, }) {
7
+ const hasInput = input.trim().length > 0;
8
+ const handleKeyDown = (e) => {
9
+ if (e.key === 'Enter') {
10
+ if (e.shiftKey) {
11
+ // Allow Shift+Enter for newlines
12
+ return;
13
+ }
14
+ // Submit on plain Enter (if there's input)
15
+ e.preventDefault();
16
+ if (hasInput) {
17
+ // If we have input, submit (which will stop any ongoing stream)
18
+ onSubmit(e);
19
+ }
20
+ else if (isResponding && onStop) {
21
+ // If no input but streaming, just stop
22
+ onStop();
23
+ }
24
+ }
25
+ };
26
+ const handleButtonClick = () => {
27
+ if (isResponding && !hasInput) {
28
+ // Stop button behavior: no input, just stop streaming
29
+ onStop?.();
30
+ }
31
+ // If there's input, the button acts as submit (handled by form)
32
+ };
33
+ // Show stop button only when streaming AND no input
34
+ const showStopButton = isResponding && !hasInput;
35
+ return (_jsx("div", { className: cn('isolate w-full p-2'), "data-chat-input-wrapper": true, children: _jsx("div", { className: "mx-auto max-w-5xl", children: _jsx("form", { onSubmit: onSubmit, children: _jsxs("div", { className: cn('bg-background relative flex w-full flex-col rounded-3xl border', compact && 'h-14'), children: [_jsx("div", { className: cn('w-full px-5', compact ? 'py-4' : 'py-4 pr-14'), children: _jsx(Textarea, { ref: inputRef, value: input, placeholder: placeholder, onChange: onInputChange, onKeyDown: handleKeyDown, className: cn('max-h-32 min-h-[24px] resize-none rounded-none border-0 bg-transparent p-0 text-sm shadow-none focus:outline-none focus-visible:ring-0 focus-visible:ring-offset-0', compact && 'max-h-6 min-h-6') }) }), !compact && (_jsx("div", { className: "absolute bottom-3 right-3", children: _jsxs(Button, { type: showStopButton ? 'button' : 'submit', size: "icon", className: "bg-primary text-primary-foreground size-8 cursor-pointer rounded-full hover:opacity-70 disabled:opacity-30", disabled: !hasInput && !isResponding, onClick: handleButtonClick, children: [showStopButton ? (_jsx(Square, { className: "fill-primary-foreground size-4 animate-pulse" })) : (_jsx(ArrowUp, { className: "size-4" })), _jsx("span", { className: "sr-only", children: showStopButton ? 'Stop generating' : 'Send message' })] }) }))] }) }) }) }));
36
+ }
@@ -0,0 +1,30 @@
1
+ export type ChatMessagePart = {
2
+ type: 'text';
3
+ text: string;
4
+ } | {
5
+ type: 'reasoning';
6
+ text: string;
7
+ } | {
8
+ type: 'tool-invocation';
9
+ toolCallId?: string;
10
+ toolName: string;
11
+ state: string;
12
+ args?: unknown;
13
+ output?: unknown;
14
+ };
15
+ export type ChatMessage = {
16
+ id: string;
17
+ role: 'user' | 'assistant' | 'system';
18
+ content?: string;
19
+ parts?: ChatMessagePart[];
20
+ };
21
+ type MessageProps = {
22
+ message: ChatMessage;
23
+ isLast?: boolean;
24
+ isStreaming?: boolean;
25
+ };
26
+ declare function PureMessage({ message, isLast, isStreaming, }: MessageProps): import("react/jsx-runtime").JSX.Element;
27
+ export declare const Message: import("react").MemoExoticComponent<typeof PureMessage>;
28
+ export declare function ThinkingMessage(): import("react/jsx-runtime").JSX.Element;
29
+ export {};
30
+ //# sourceMappingURL=chat-message.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat-message.d.ts","sourceRoot":"","sources":["../../../src/components/chat/chat-message.tsx"],"names":[],"mappings":"AAsBA,MAAM,MAAM,eAAe,GACvB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACnC;IACE,IAAI,EAAE,iBAAiB,CAAA;IACvB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB,CAAA;AAEL,MAAM,MAAM,WAAW,GAAG;IACxB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAA;IACrC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,eAAe,EAAE,CAAA;CAC1B,CAAA;AAED,KAAK,YAAY,GAAG;IAClB,OAAO,EAAE,WAAW,CAAA;IACpB,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB,CAAA;AAcD,iBAAS,WAAW,CAAC,EACnB,OAAO,EACP,MAAc,EACd,WAAmB,GACpB,EAAE,YAAY,2CA2Xd;AAED,eAAO,MAAM,OAAO,yDAAoB,CAAA;AAExC,wBAAgB,eAAe,4CAiB9B"}
@@ -0,0 +1,250 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Brain, ChevronDown, Loader2 } from 'lucide-react';
4
+ import { memo, useEffect, useMemo, useState } from 'react';
5
+ import { cn } from '../../lib/utils';
6
+ import { Markdown } from '../markdown';
7
+ import { Collapsible, CollapsibleContent, CollapsibleTrigger, } from '../ui/collapsible';
8
+ import { ThinkingTimeline, ThinkingTimelineMarker, } from './thinking-timeline';
9
+ import { getToolHandler } from './tool-handlers';
10
+ import { AnimatePresence, motion } from 'framer-motion';
11
+ const DEFAULT_ACTIONS_LABEL = 'Thinking';
12
+ function PureMessage({ message, isLast = false, isStreaming = false, }) {
13
+ // Track open state for each thinking group independently
14
+ const [thinkingGroupStates, setThinkingGroupStates] = useState(new Map());
15
+ // Process parts chronologically, grouping only reasoning into thinking groups
16
+ // Inline tools (file ops, commands) are rendered directly
17
+ const { contentItems, hasFinalAssistantText } = useMemo(() => {
18
+ const items = [];
19
+ const state = {
20
+ currentThinkingGroup: null,
21
+ thinkingGroupIndex: 0,
22
+ hasText: false,
23
+ };
24
+ // Helper to close current thinking group
25
+ const closeThinkingGroup = () => {
26
+ if (state.currentThinkingGroup) {
27
+ items.push({
28
+ type: 'thinking',
29
+ id: state.currentThinkingGroup.id,
30
+ thinkingGroup: state.currentThinkingGroup,
31
+ });
32
+ state.currentThinkingGroup = null;
33
+ }
34
+ };
35
+ // Helper to ensure thinking group exists
36
+ const ensureThinkingGroup = () => {
37
+ if (!state.currentThinkingGroup) {
38
+ state.thinkingGroupIndex++;
39
+ state.currentThinkingGroup = {
40
+ id: `thinking-${message.id}-${state.thinkingGroupIndex}`,
41
+ timeline: [],
42
+ title: DEFAULT_ACTIONS_LABEL,
43
+ isStreaming: false,
44
+ };
45
+ }
46
+ return state.currentThinkingGroup;
47
+ };
48
+ // If no parts, use content as text
49
+ const parts = message.parts ?? [];
50
+ if (parts.length === 0 && message.content) {
51
+ return {
52
+ contentItems: [
53
+ {
54
+ type: 'text',
55
+ id: `message-${message.id}-content`,
56
+ textPart: { type: 'text', text: message.content },
57
+ },
58
+ ],
59
+ hasFinalAssistantText: true,
60
+ };
61
+ }
62
+ for (let index = 0; index < parts.length; index++) {
63
+ const part = parts[index];
64
+ const key = `message-${message.id}-part-${index}`;
65
+ // Handle tool calls
66
+ if (part.type === 'tool-invocation') {
67
+ const toolHandler = getToolHandler(part.toolName);
68
+ // Check if this tool should be rendered inline
69
+ if (toolHandler.inline) {
70
+ // Close any open thinking group first
71
+ closeThinkingGroup();
72
+ // Render inline tool
73
+ const isToolLoading = part.state === 'partial-call' ||
74
+ part.state === 'call' ||
75
+ part.state === 'pending';
76
+ const toolContent = isToolLoading
77
+ ? toolHandler.renderLoading?.(part.args) || (_jsx("div", { className: "text-muted-foreground text-xs", children: toolHandler.loadingLabel }))
78
+ : toolHandler.renderOutput(part.output, part.toolCallId || key);
79
+ items.push({
80
+ type: 'inline-tool',
81
+ id: key,
82
+ content: toolContent,
83
+ });
84
+ continue;
85
+ }
86
+ // Non-inline tools go into thinking group
87
+ const group = ensureThinkingGroup();
88
+ // Show loading state for tools
89
+ if (part.state === 'partial-call' ||
90
+ part.state === 'call' ||
91
+ part.state === 'pending') {
92
+ const toolLabel = toolHandler.loadingLabel;
93
+ group.title = toolLabel;
94
+ group.isStreaming = true;
95
+ group.timeline.push({
96
+ marker: ThinkingTimelineMarker.Loading,
97
+ content: (_jsx("div", { className: "px-2 py-1", children: _jsx("span", { className: "text-muted-foreground font-mono text-xs", children: toolLabel }) }, `${part.toolCallId || key}-loading`)),
98
+ });
99
+ continue;
100
+ }
101
+ // Show tool output
102
+ if (part.state === 'result' || part.state === 'output-available') {
103
+ group.timeline.push({
104
+ marker: toolHandler.marker ?? ThinkingTimelineMarker.Default,
105
+ content: toolHandler.renderOutput(part.output, part.toolCallId || key),
106
+ });
107
+ continue;
108
+ }
109
+ continue;
110
+ }
111
+ if (part.type === 'reasoning') {
112
+ const full = part.text ?? '';
113
+ const trimmedFull = full.trim();
114
+ if (trimmedFull.length === 0) {
115
+ continue;
116
+ }
117
+ const group = ensureThinkingGroup();
118
+ // Extract title from markdown **title** or use first line
119
+ const markdownTitleMatch = full.match(/\*\*([^*]+)\*\*/);
120
+ const candidateTitle = markdownTitleMatch?.[1];
121
+ const trimmed = trimmedFull;
122
+ const firstLine = trimmed.split(/\n+/)[0];
123
+ const extractedTitle = candidateTitle || firstLine?.slice(0, 50) || DEFAULT_ACTIONS_LABEL;
124
+ group.title = extractedTitle;
125
+ const body = candidateTitle
126
+ ? trimmed.replace(/\*\*[^*]+\*\*\s*/, '')
127
+ : trimmed;
128
+ group.timeline.push({
129
+ marker: ThinkingTimelineMarker.Default,
130
+ content: (_jsx("div", { className: "whitespace-pre-wrap px-2 py-1", children: body }, key)),
131
+ });
132
+ continue;
133
+ }
134
+ if (part.type === 'text') {
135
+ // Close current thinking group before text
136
+ closeThinkingGroup();
137
+ state.hasText = true;
138
+ items.push({
139
+ type: 'text',
140
+ id: key,
141
+ textPart: part,
142
+ });
143
+ }
144
+ }
145
+ // Close any remaining thinking group
146
+ closeThinkingGroup();
147
+ return {
148
+ contentItems: items,
149
+ hasFinalAssistantText: state.hasText,
150
+ };
151
+ }, [message.id, message.parts, message.content]);
152
+ // Determine if last thinking group is streaming
153
+ const lastThinkingGroup = contentItems
154
+ .filter((item) => item.type === 'thinking')
155
+ .map((item) => (item.type === 'thinking' ? item.thinkingGroup : null))
156
+ .filter((g) => g !== null)
157
+ .pop();
158
+ // Check if we're still streaming overall and waiting for text
159
+ const isStreamingOverall = isStreaming && isLast && !hasFinalAssistantText;
160
+ // For the last thinking group, also keep it open if we just finished streaming
161
+ // but text hasn't appeared yet (grace period for AI to start responding)
162
+ const shouldKeepLastGroupOpen = isLast && !hasFinalAssistantText && message.role === 'assistant';
163
+ // Auto-open/close reasoning groups based on streaming state
164
+ useEffect(() => {
165
+ setThinkingGroupStates((prevStates) => {
166
+ let hasChanges = false;
167
+ const nextStates = new Map(prevStates);
168
+ contentItems.forEach((item) => {
169
+ if (item.type === 'thinking' && item.thinkingGroup) {
170
+ const groupId = item.thinkingGroup.id;
171
+ const group = item.thinkingGroup;
172
+ const isLastGroup = lastThinkingGroup?.id === groupId;
173
+ const currentState = nextStates.get(groupId);
174
+ const shouldBeOpen = group.isStreaming ||
175
+ (isLastGroup && isStreamingOverall) ||
176
+ (isLastGroup && shouldKeepLastGroupOpen);
177
+ if (currentState) {
178
+ if (!currentState.userOpened) {
179
+ if (shouldBeOpen && currentState.isOpen !== true) {
180
+ nextStates.set(groupId, { ...currentState, isOpen: true });
181
+ hasChanges = true;
182
+ }
183
+ else if (!shouldBeOpen && currentState.isOpen !== false) {
184
+ nextStates.set(groupId, { ...currentState, isOpen: false });
185
+ hasChanges = true;
186
+ }
187
+ }
188
+ }
189
+ else {
190
+ nextStates.set(groupId, {
191
+ isOpen: shouldBeOpen,
192
+ userOpened: false,
193
+ });
194
+ hasChanges = true;
195
+ }
196
+ }
197
+ });
198
+ return hasChanges ? nextStates : prevStates;
199
+ });
200
+ }, [
201
+ contentItems,
202
+ isStreamingOverall,
203
+ lastThinkingGroup,
204
+ shouldKeepLastGroupOpen,
205
+ ]);
206
+ return (_jsx(AnimatePresence, { children: _jsx(motion.div, { "data-testid": `message-${message.role}`, className: "group/message w-full min-w-0 px-2", initial: { y: 5, opacity: 0 }, animate: { y: 0, opacity: 1 }, "data-role": message.role, children: _jsx("div", { className: cn('flex w-full min-w-0 items-start gap-4', message.role === 'user' && 'justify-end'), children: _jsx("div", { className: cn('mt-1 flex min-w-0 flex-col gap-2', message.role === 'user' ? 'max-w-[85%] items-end' : 'w-full'), children: contentItems.map((item) => {
207
+ if (item.type === 'thinking' &&
208
+ item.thinkingGroup &&
209
+ message.role === 'assistant') {
210
+ const group = item.thinkingGroup;
211
+ const groupState = thinkingGroupStates.get(group.id);
212
+ const isLastGroup = lastThinkingGroup?.id === group.id;
213
+ const isGroupStreaming = group.isStreaming || (isLastGroup && isStreamingOverall);
214
+ const shouldBeOpenByDefault = isGroupStreaming;
215
+ const isOpen = groupState?.isOpen ?? shouldBeOpenByDefault;
216
+ const titleForTrigger = hasFinalAssistantText && isLastGroup && !isGroupStreaming
217
+ ? DEFAULT_ACTIONS_LABEL
218
+ : group.title || DEFAULT_ACTIONS_LABEL;
219
+ return (_jsxs(Collapsible, { open: isOpen, onOpenChange: (open) => {
220
+ setThinkingGroupStates((prev) => {
221
+ const next = new Map(prev);
222
+ const current = next.get(group.id) ?? {
223
+ isOpen: false,
224
+ userOpened: false,
225
+ };
226
+ next.set(group.id, {
227
+ ...current,
228
+ isOpen: open,
229
+ userOpened: open ? true : current.userOpened,
230
+ });
231
+ return next;
232
+ });
233
+ }, className: "mb-2 w-full", "data-ai-reasoning": true, children: [_jsxs(CollapsibleTrigger, { className: cn('group flex max-w-full cursor-pointer items-center gap-2 rounded-md px-2 py-1 text-[11px] font-semibold uppercase tracking-wide transition-colors', 'text-muted-foreground hover:bg-accent hover:text-foreground min-w-0'), children: [_jsx(Brain, { className: cn('size-3.5 shrink-0 opacity-80', isGroupStreaming && 'animate-pulse') }), _jsx("span", { className: "flex-1 truncate", children: titleForTrigger }), _jsx(ChevronDown, { className: cn('size-3.5 shrink-0 transition-transform', 'group-data-[state=open]:rotate-180') })] }), _jsx(CollapsibleContent, { className: "text-muted-foreground min-w-0 overflow-hidden rounded-md px-[5px] py-2 font-mono text-xs leading-relaxed", children: _jsx(ThinkingTimeline, { items: group.timeline }) })] }, item.id));
234
+ }
235
+ if (item.type === 'inline-tool') {
236
+ return (_jsx("div", { className: "w-full min-w-0", children: item.content }, item.id));
237
+ }
238
+ if (item.type === 'text' && item.textPart) {
239
+ return (_jsx("div", { className: cn('flex flex-col gap-4', {
240
+ 'bg-secondary text-secondary-foreground w-fit rounded-2xl px-4 py-2.5': message.role === 'user',
241
+ }), children: _jsx(Markdown, { markdown: item.textPart.text, proseSize: "sm", className: cn('[&_.prose]:leading-relaxed [&_.prose]:text-current', '[&_.prose_pre]:bg-background/80 [&_.prose_code]:text-current', '[&_.prose_p:last-child]:mb-0 [&_.prose_p]:mb-2', message.role === 'user' &&
242
+ '[&_.prose_pre]:bg-secondary-foreground/20') }) }, item.id));
243
+ }
244
+ return null;
245
+ }) }) }) }) }));
246
+ }
247
+ export const Message = memo(PureMessage);
248
+ export function ThinkingMessage() {
249
+ return (_jsx(motion.div, { "data-testid": "message-assistant-loading", className: "group/message w-full px-2", initial: { y: 5, opacity: 0 }, animate: { y: 0, opacity: 1, transition: { delay: 0.5 } }, "data-role": "assistant", children: _jsxs("div", { className: "text-muted-foreground flex flex-row items-center gap-2 px-2", children: [_jsx(Loader2, { className: "size-4 shrink-0 animate-spin" }), _jsx("span", { className: "font-mono text-xs font-medium uppercase", children: "Thinking..." })] }) }));
250
+ }
@@ -0,0 +1,10 @@
1
+ import { type ChatMessage } from './chat-message';
2
+ type ChatStatus = 'ready' | 'submitted' | 'streaming' | 'error';
3
+ interface MessagesProps {
4
+ messages: ChatMessage[];
5
+ status: ChatStatus;
6
+ }
7
+ declare function PureMessages({ messages, status }: MessagesProps): import("react/jsx-runtime").JSX.Element;
8
+ export declare const Messages: import("react").MemoExoticComponent<typeof PureMessages>;
9
+ export {};
10
+ //# sourceMappingURL=chat-messages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat-messages.d.ts","sourceRoot":"","sources":["../../../src/components/chat/chat-messages.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,WAAW,EAA4B,MAAM,gBAAgB,CAAA;AAE3E,KAAK,UAAU,GAAG,OAAO,GAAG,WAAW,GAAG,WAAW,GAAG,OAAO,CAAA;AAE/D,UAAU,aAAa;IACrB,QAAQ,EAAE,WAAW,EAAE,CAAA;IACvB,MAAM,EAAE,UAAU,CAAA;CACnB;AAED,iBAAS,YAAY,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,aAAa,2CA2CxD;AAED,eAAO,MAAM,QAAQ,0DAAqB,CAAA"}
@@ -0,0 +1,30 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { memo } from 'react';
3
+ import { Message, ThinkingMessage } from './chat-message';
4
+ function PureMessages({ messages, status }) {
5
+ const lastMessage = messages[messages.length - 1];
6
+ const isThinking = (() => {
7
+ if (!lastMessage)
8
+ return false;
9
+ if (status !== 'submitted' && status !== 'streaming') {
10
+ return false;
11
+ }
12
+ if (lastMessage.role === 'user') {
13
+ return true;
14
+ }
15
+ if (lastMessage.role === 'assistant') {
16
+ const hasVisibleText = (lastMessage.parts ?? []).some((part) => {
17
+ return part.type === 'text' && part.text.trim().length > 0;
18
+ });
19
+ // Also check content fallback
20
+ if (!hasVisibleText && lastMessage.content?.trim()) {
21
+ return false;
22
+ }
23
+ return !hasVisibleText;
24
+ }
25
+ return false;
26
+ })();
27
+ const isStreaming = status === 'streaming' || status === 'submitted';
28
+ return (_jsxs(_Fragment, { children: [messages.map((message, index) => (_jsx(Message, { message: message, isLast: index === messages.length - 1, isStreaming: isStreaming }, message.id))), isThinking && _jsx(ThinkingMessage, {})] }));
29
+ }
30
+ export const Messages = memo(PureMessages);
@@ -0,0 +1,60 @@
1
+ import { type ChangeEvent, type FormEvent, type ReactNode } from 'react';
2
+ import type { ChatMessage } from './chat-message';
3
+ import { type ConversationMeta } from './conversation-history';
4
+ import { type ModelOption } from './model-selector';
5
+ import { type ReasoningEffortOption } from './reasoning-effort-selector';
6
+ type ChatStatus = 'ready' | 'submitted' | 'streaming' | 'error';
7
+ export interface ChatPanelProps {
8
+ /** Chat messages */
9
+ messages: ChatMessage[];
10
+ /** Current chat status */
11
+ status: ChatStatus;
12
+ /** Input value */
13
+ input: string;
14
+ /** Handle input change */
15
+ onInputChange: (e: ChangeEvent<HTMLTextAreaElement>) => void;
16
+ /** Handle form submit */
17
+ onSubmit: (e?: FormEvent<HTMLFormElement>) => void;
18
+ /** Handle stop generation */
19
+ onStop?: () => void;
20
+ /** Handle new chat */
21
+ onNewChat?: () => void;
22
+ /** Available models */
23
+ models: ModelOption[];
24
+ /** Selected model ID */
25
+ selectedModel: string;
26
+ /** Handle model change */
27
+ onModelChange: (modelId: string) => void;
28
+ /** Available reasoning effort options (varies by model vendor) */
29
+ reasoningEffortOptions?: ReasoningEffortOption[];
30
+ /** Selected reasoning effort */
31
+ selectedReasoningEffort?: string;
32
+ /** Handle reasoning effort change */
33
+ onReasoningEffortChange?: (effort: string) => void;
34
+ /** Conversation history */
35
+ conversations?: ConversationMeta[];
36
+ /** Current conversation ID */
37
+ currentConversationId?: string | null;
38
+ /** Handle conversation selection */
39
+ onSelectConversation?: (id: string) => void;
40
+ /** Handle conversation deletion */
41
+ onDeleteConversation?: (id: string) => void;
42
+ /** Placeholder text */
43
+ placeholder?: string;
44
+ /** Welcome message when no messages exist */
45
+ welcomeMessage?: ReactNode;
46
+ /** Whether the panel is expanded */
47
+ isExpanded: boolean;
48
+ /** Toggle expanded state */
49
+ onExpandedChange: (expanded: boolean) => void;
50
+ /** Custom class name */
51
+ className?: string;
52
+ /** Error from chat request */
53
+ error?: Error | null;
54
+ }
55
+ /**
56
+ * Floating chat panel with model selector
57
+ */
58
+ export declare function ChatPanel({ messages, status, input, onInputChange, onSubmit, onStop, onNewChat, models, selectedModel, onModelChange, reasoningEffortOptions, selectedReasoningEffort, onReasoningEffortChange, conversations, currentConversationId, onSelectConversation, onDeleteConversation, placeholder, welcomeMessage, isExpanded, onExpandedChange, className, error, }: ChatPanelProps): import("react/jsx-runtime").JSX.Element;
59
+ export {};
60
+ //# sourceMappingURL=chat-panel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat-panel.d.ts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