@tangle-network/sandbox-ui 0.2.0
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 +68 -0
- package/dist/auth.d.ts +57 -0
- package/dist/auth.js +14 -0
- package/dist/branding-DCi5VEik.d.ts +13 -0
- package/dist/button-BidTtuRS.d.ts +15 -0
- package/dist/chat.d.ts +121 -0
- package/dist/chat.js +25 -0
- package/dist/chunk-2UHPE5T7.js +201 -0
- package/dist/chunk-4EIWPJMJ.js +545 -0
- package/dist/chunk-6MQIDUPA.js +502 -0
- package/dist/chunk-B26TQ7SA.js +47 -0
- package/dist/chunk-E6FS7R4X.js +109 -0
- package/dist/chunk-GRYHFH5O.js +110 -0
- package/dist/chunk-HMND7JPA.js +868 -0
- package/dist/chunk-HRMUF35V.js +19 -0
- package/dist/chunk-HYEAX3DC.js +822 -0
- package/dist/chunk-KMXV7DDX.js +174 -0
- package/dist/chunk-KYY2X6LY.js +318 -0
- package/dist/chunk-L6ZDH5F4.js +334 -0
- package/dist/chunk-LTFK464G.js +103 -0
- package/dist/chunk-M34OA6PQ.js +233 -0
- package/dist/chunk-M6VLC32S.js +219 -0
- package/dist/chunk-MCGKDCOR.js +173 -0
- package/dist/chunk-NI2EI43H.js +294 -0
- package/dist/chunk-OU4TRNQZ.js +173 -0
- package/dist/chunk-QD4QE5P5.js +40 -0
- package/dist/chunk-QSQBDR3N.js +180 -0
- package/dist/chunk-RQHJBTEU.js +10 -0
- package/dist/chunk-U62G5TS7.js +472 -0
- package/dist/chunk-ZOL2TR5M.js +475 -0
- package/dist/dashboard.d.ts +111 -0
- package/dist/dashboard.js +26 -0
- package/dist/editor.d.ts +196 -0
- package/dist/editor.js +713 -0
- package/dist/expanded-tool-detail-OkXGqTHe.d.ts +52 -0
- package/dist/files.d.ts +66 -0
- package/dist/files.js +11 -0
- package/dist/hooks.d.ts +22 -0
- package/dist/hooks.js +107 -0
- package/dist/index.d.ts +107 -0
- package/dist/index.js +551 -0
- package/dist/markdown.d.ts +55 -0
- package/dist/markdown.js +17 -0
- package/dist/pages.d.ts +89 -0
- package/dist/pages.js +1181 -0
- package/dist/parts-CyGkM6Fp.d.ts +50 -0
- package/dist/primitives.d.ts +189 -0
- package/dist/primitives.js +161 -0
- package/dist/run-CtFZ6s-D.d.ts +41 -0
- package/dist/run.d.ts +14 -0
- package/dist/run.js +29 -0
- package/dist/sidecar-CFU2W9j1.d.ts +8 -0
- package/dist/stores.d.ts +28 -0
- package/dist/stores.js +49 -0
- package/dist/terminal.d.ts +44 -0
- package/dist/terminal.js +160 -0
- package/dist/tool-call-feed-D5Ume-Pt.d.ts +66 -0
- package/dist/tool-display-BvsVW_Ur.d.ts +32 -0
- package/dist/types.d.ts +6 -0
- package/dist/types.js +0 -0
- package/dist/usage-chart-DINgSVL5.d.ts +60 -0
- package/dist/use-sidecar-auth-Bb0-w3lX.d.ts +339 -0
- package/dist/utils.d.ts +28 -0
- package/dist/utils.js +28 -0
- package/dist/workspace.d.ts +113 -0
- package/dist/workspace.js +15 -0
- package/package.json +174 -0
- package/src/styles/globals.css +230 -0
- package/src/styles/tokens.css +73 -0
- package/tailwind.config.cjs +99 -0
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useAutoScroll,
|
|
3
|
+
useRunCollapseState,
|
|
4
|
+
useRunGroups
|
|
5
|
+
} from "./chunk-KMXV7DDX.js";
|
|
6
|
+
import {
|
|
7
|
+
RunGroup
|
|
8
|
+
} from "./chunk-6MQIDUPA.js";
|
|
9
|
+
import {
|
|
10
|
+
Markdown
|
|
11
|
+
} from "./chunk-LTFK464G.js";
|
|
12
|
+
import {
|
|
13
|
+
SimpleMarkdown
|
|
14
|
+
} from "./chunk-M34OA6PQ.js";
|
|
15
|
+
import {
|
|
16
|
+
cn
|
|
17
|
+
} from "./chunk-RQHJBTEU.js";
|
|
18
|
+
|
|
19
|
+
// src/chat/chat-message.tsx
|
|
20
|
+
import { User, Bot } from "lucide-react";
|
|
21
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
22
|
+
function ChatMessage({
|
|
23
|
+
role,
|
|
24
|
+
content,
|
|
25
|
+
toolCalls,
|
|
26
|
+
isStreaming,
|
|
27
|
+
timestamp,
|
|
28
|
+
className
|
|
29
|
+
}) {
|
|
30
|
+
const isUser = role === "user";
|
|
31
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("flex gap-3 px-4 py-3", className), children: [
|
|
32
|
+
/* @__PURE__ */ jsx(
|
|
33
|
+
"div",
|
|
34
|
+
{
|
|
35
|
+
className: cn(
|
|
36
|
+
"w-7 h-7 rounded-lg shrink-0 flex items-center justify-center mt-0.5",
|
|
37
|
+
isUser ? "bg-[var(--brand-cool)]/15 text-[var(--brand-cool)]" : "bg-[var(--brand-glow)]/15 text-[var(--brand-glow)]"
|
|
38
|
+
),
|
|
39
|
+
children: isUser ? /* @__PURE__ */ jsx(User, { className: "h-4 w-4" }) : /* @__PURE__ */ jsx(Bot, { className: "h-4 w-4" })
|
|
40
|
+
}
|
|
41
|
+
),
|
|
42
|
+
/* @__PURE__ */ jsxs("div", { className: "flex-1 min-w-0 space-y-1", children: [
|
|
43
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
44
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs font-semibold text-[var(--text-secondary)]", children: isUser ? "You" : "Agent" }),
|
|
45
|
+
timestamp && /* @__PURE__ */ jsx("span", { className: "text-xs text-[var(--text-muted)]", children: formatTime(timestamp) })
|
|
46
|
+
] }),
|
|
47
|
+
isUser ? /* @__PURE__ */ jsx("div", { className: "text-[var(--text-primary)] text-sm whitespace-pre-wrap leading-relaxed", children: content }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
48
|
+
content && /* @__PURE__ */ jsx(SimpleMarkdown, { content }),
|
|
49
|
+
isStreaming && /* @__PURE__ */ jsx("span", { className: "inline-block w-2 h-4 bg-[var(--brand-cool)] animate-pulse rounded-sm ml-0.5 align-text-bottom" })
|
|
50
|
+
] }),
|
|
51
|
+
toolCalls
|
|
52
|
+
] })
|
|
53
|
+
] });
|
|
54
|
+
}
|
|
55
|
+
function formatTime(date) {
|
|
56
|
+
return date.toLocaleTimeString(void 0, {
|
|
57
|
+
hour: "numeric",
|
|
58
|
+
minute: "2-digit"
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/chat/chat-message-list.tsx
|
|
63
|
+
import { useRef, useEffect, useState } from "react";
|
|
64
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
65
|
+
function ChatMessageList({
|
|
66
|
+
messages,
|
|
67
|
+
renderAfter,
|
|
68
|
+
emptyState,
|
|
69
|
+
isThinking,
|
|
70
|
+
className
|
|
71
|
+
}) {
|
|
72
|
+
const containerRef = useRef(null);
|
|
73
|
+
const endRef = useRef(null);
|
|
74
|
+
const [isNearBottom, setIsNearBottom] = useState(true);
|
|
75
|
+
const handleScroll = () => {
|
|
76
|
+
const el = containerRef.current;
|
|
77
|
+
if (!el) return;
|
|
78
|
+
const threshold = 100;
|
|
79
|
+
const nearBottom = el.scrollHeight - el.scrollTop - el.clientHeight < threshold;
|
|
80
|
+
setIsNearBottom(nearBottom);
|
|
81
|
+
};
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
if (isNearBottom) {
|
|
84
|
+
endRef.current?.scrollIntoView({ behavior: "smooth" });
|
|
85
|
+
}
|
|
86
|
+
}, [messages, isThinking, isNearBottom]);
|
|
87
|
+
if (messages.length === 0 && emptyState) {
|
|
88
|
+
return /* @__PURE__ */ jsx2("div", { className: cn("flex-1 flex items-center justify-center p-8", className), children: emptyState });
|
|
89
|
+
}
|
|
90
|
+
return /* @__PURE__ */ jsx2(
|
|
91
|
+
"div",
|
|
92
|
+
{
|
|
93
|
+
ref: containerRef,
|
|
94
|
+
onScroll: handleScroll,
|
|
95
|
+
className: cn("flex-1 overflow-y-auto", className),
|
|
96
|
+
children: /* @__PURE__ */ jsxs2("div", { className: "max-w-3xl mx-auto py-4", children: [
|
|
97
|
+
messages.map((msg, i) => /* @__PURE__ */ jsxs2("div", { children: [
|
|
98
|
+
/* @__PURE__ */ jsx2(
|
|
99
|
+
ChatMessage,
|
|
100
|
+
{
|
|
101
|
+
role: msg.role,
|
|
102
|
+
content: msg.content,
|
|
103
|
+
toolCalls: msg.toolCalls,
|
|
104
|
+
isStreaming: msg.isStreaming,
|
|
105
|
+
timestamp: msg.timestamp
|
|
106
|
+
}
|
|
107
|
+
),
|
|
108
|
+
renderAfter?.(msg, i)
|
|
109
|
+
] }, msg.id)),
|
|
110
|
+
isThinking && /* @__PURE__ */ jsx2(ThinkingIndicator, {}),
|
|
111
|
+
/* @__PURE__ */ jsx2("div", { ref: endRef })
|
|
112
|
+
] })
|
|
113
|
+
}
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
function ThinkingIndicator({ className }) {
|
|
117
|
+
const [elapsed, setElapsed] = useState(0);
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
const interval = setInterval(() => setElapsed((e) => e + 1), 1e3);
|
|
120
|
+
return () => clearInterval(interval);
|
|
121
|
+
}, []);
|
|
122
|
+
return /* @__PURE__ */ jsxs2("div", { className: cn("flex gap-3 px-4 py-3", className), children: [
|
|
123
|
+
/* @__PURE__ */ jsx2("div", { className: "w-7 h-7 rounded-lg shrink-0 flex items-center justify-center mt-0.5 bg-[var(--brand-glow)]/15 text-[var(--brand-glow)]", children: /* @__PURE__ */ jsxs2("div", { className: "flex gap-0.5", children: [
|
|
124
|
+
/* @__PURE__ */ jsx2("span", { className: "w-1.5 h-1.5 rounded-full bg-current animate-bounce", style: { animationDelay: "0ms" } }),
|
|
125
|
+
/* @__PURE__ */ jsx2("span", { className: "w-1.5 h-1.5 rounded-full bg-current animate-bounce", style: { animationDelay: "150ms" } }),
|
|
126
|
+
/* @__PURE__ */ jsx2("span", { className: "w-1.5 h-1.5 rounded-full bg-current animate-bounce", style: { animationDelay: "300ms" } })
|
|
127
|
+
] }) }),
|
|
128
|
+
/* @__PURE__ */ jsxs2("div", { className: "flex items-center gap-2", children: [
|
|
129
|
+
/* @__PURE__ */ jsx2("span", { className: "text-sm text-[var(--text-muted)]", children: elapsed < 10 ? "Thinking..." : elapsed < 60 ? "Thinking deeply..." : "Still working..." }),
|
|
130
|
+
elapsed > 5 && /* @__PURE__ */ jsxs2("span", { className: "text-xs text-[var(--text-muted)] tabular-nums", children: [
|
|
131
|
+
elapsed,
|
|
132
|
+
"s"
|
|
133
|
+
] })
|
|
134
|
+
] })
|
|
135
|
+
] });
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// src/chat/chat-input.tsx
|
|
139
|
+
import { useState as useState2, useRef as useRef2, useCallback } from "react";
|
|
140
|
+
import { Send, Square, Paperclip, X } from "lucide-react";
|
|
141
|
+
import { Fragment as Fragment2, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
142
|
+
function ChatInput({
|
|
143
|
+
onSend,
|
|
144
|
+
onCancel,
|
|
145
|
+
isStreaming,
|
|
146
|
+
disabled,
|
|
147
|
+
placeholder = "Ask about your taxes, build a model, or give instructions...",
|
|
148
|
+
modelLabel,
|
|
149
|
+
onModelClick,
|
|
150
|
+
pendingFiles = [],
|
|
151
|
+
onRemoveFile,
|
|
152
|
+
onAttach,
|
|
153
|
+
className
|
|
154
|
+
}) {
|
|
155
|
+
const [value, setValue] = useState2("");
|
|
156
|
+
const textareaRef = useRef2(null);
|
|
157
|
+
const fileInputRef = useRef2(null);
|
|
158
|
+
const handleSend = useCallback(() => {
|
|
159
|
+
const trimmed = value.trim();
|
|
160
|
+
if (!trimmed || isStreaming || disabled) return;
|
|
161
|
+
onSend(trimmed);
|
|
162
|
+
setValue("");
|
|
163
|
+
if (textareaRef.current) {
|
|
164
|
+
textareaRef.current.style.height = "auto";
|
|
165
|
+
}
|
|
166
|
+
}, [value, isStreaming, disabled, onSend]);
|
|
167
|
+
const handleKeyDown = (e) => {
|
|
168
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
|
169
|
+
e.preventDefault();
|
|
170
|
+
handleSend();
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
const handleChange = (e) => {
|
|
174
|
+
setValue(e.target.value);
|
|
175
|
+
const el = e.target;
|
|
176
|
+
el.style.height = "auto";
|
|
177
|
+
el.style.height = `${Math.min(el.scrollHeight, 160)}px`;
|
|
178
|
+
};
|
|
179
|
+
const handleAttachClick = () => {
|
|
180
|
+
fileInputRef.current?.click();
|
|
181
|
+
};
|
|
182
|
+
const handleFileChange = (e) => {
|
|
183
|
+
if (e.target.files?.length) {
|
|
184
|
+
onAttach?.(e.target.files);
|
|
185
|
+
e.target.value = "";
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
return /* @__PURE__ */ jsxs3("div", { className: cn("px-4 py-3", className), children: [
|
|
189
|
+
pendingFiles.length > 0 && /* @__PURE__ */ jsx3("div", { className: "flex flex-wrap gap-1.5 mb-2", children: pendingFiles.map((f) => /* @__PURE__ */ jsxs3(
|
|
190
|
+
"span",
|
|
191
|
+
{
|
|
192
|
+
className: cn(
|
|
193
|
+
"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-[var(--radius-full)] text-xs",
|
|
194
|
+
"bg-[var(--bg-input)] border border-[var(--border-subtle)]",
|
|
195
|
+
f.status === "error" && "border-[var(--code-error)]/30 text-[var(--code-error)]",
|
|
196
|
+
f.status !== "error" && "text-[var(--text-secondary)]"
|
|
197
|
+
),
|
|
198
|
+
children: [
|
|
199
|
+
/* @__PURE__ */ jsx3("span", { className: "truncate max-w-[150px]", children: f.name }),
|
|
200
|
+
f.status === "uploading" && /* @__PURE__ */ jsx3("span", { className: "w-3 h-3 border-2 border-[var(--brand-cool)] border-t-transparent rounded-full animate-spin" }),
|
|
201
|
+
onRemoveFile && /* @__PURE__ */ jsx3(
|
|
202
|
+
"button",
|
|
203
|
+
{
|
|
204
|
+
onClick: () => onRemoveFile(f.id),
|
|
205
|
+
className: "hover:text-[var(--text-primary)] transition-colors",
|
|
206
|
+
children: /* @__PURE__ */ jsx3(X, { className: "h-3 w-3" })
|
|
207
|
+
}
|
|
208
|
+
)
|
|
209
|
+
]
|
|
210
|
+
},
|
|
211
|
+
f.id
|
|
212
|
+
)) }),
|
|
213
|
+
/* @__PURE__ */ jsxs3("div", { className: "flex items-end gap-2 bg-[var(--bg-card)] border border-[var(--border-default)] rounded-[var(--radius-lg)] px-3 py-2 focus-within:border-[var(--border-accent)] transition-colors", children: [
|
|
214
|
+
onAttach && /* @__PURE__ */ jsxs3(Fragment2, { children: [
|
|
215
|
+
/* @__PURE__ */ jsx3(
|
|
216
|
+
"button",
|
|
217
|
+
{
|
|
218
|
+
onClick: handleAttachClick,
|
|
219
|
+
disabled: isStreaming,
|
|
220
|
+
className: "p-1.5 rounded-[var(--radius-sm)] hover:bg-[var(--bg-hover)] text-[var(--text-muted)] hover:text-[var(--text-secondary)] transition-colors disabled:opacity-50 shrink-0 mb-0.5",
|
|
221
|
+
children: /* @__PURE__ */ jsx3(Paperclip, { className: "h-4 w-4" })
|
|
222
|
+
}
|
|
223
|
+
),
|
|
224
|
+
/* @__PURE__ */ jsx3(
|
|
225
|
+
"input",
|
|
226
|
+
{
|
|
227
|
+
ref: fileInputRef,
|
|
228
|
+
type: "file",
|
|
229
|
+
multiple: true,
|
|
230
|
+
className: "hidden",
|
|
231
|
+
onChange: handleFileChange,
|
|
232
|
+
accept: ".pdf,.csv,.xlsx,.xls,.jpg,.jpeg,.png,.gif,.txt,.json,.yaml,.yml"
|
|
233
|
+
}
|
|
234
|
+
)
|
|
235
|
+
] }),
|
|
236
|
+
/* @__PURE__ */ jsx3(
|
|
237
|
+
"textarea",
|
|
238
|
+
{
|
|
239
|
+
ref: textareaRef,
|
|
240
|
+
value,
|
|
241
|
+
onChange: handleChange,
|
|
242
|
+
onKeyDown: handleKeyDown,
|
|
243
|
+
placeholder,
|
|
244
|
+
disabled: isStreaming || disabled,
|
|
245
|
+
rows: 1,
|
|
246
|
+
className: "flex-1 bg-transparent text-[var(--text-primary)] text-sm placeholder:text-[var(--text-muted)] resize-none outline-none min-h-[24px] max-h-[160px] leading-relaxed disabled:opacity-50"
|
|
247
|
+
}
|
|
248
|
+
),
|
|
249
|
+
isStreaming ? /* @__PURE__ */ jsx3(
|
|
250
|
+
"button",
|
|
251
|
+
{
|
|
252
|
+
onClick: onCancel,
|
|
253
|
+
className: "p-1.5 rounded-[var(--radius-sm)] bg-[var(--code-error)]/15 hover:bg-[var(--code-error)]/25 text-[var(--code-error)] transition-colors shrink-0 mb-0.5",
|
|
254
|
+
children: /* @__PURE__ */ jsx3(Square, { className: "h-4 w-4" })
|
|
255
|
+
}
|
|
256
|
+
) : /* @__PURE__ */ jsx3(
|
|
257
|
+
"button",
|
|
258
|
+
{
|
|
259
|
+
onClick: handleSend,
|
|
260
|
+
disabled: !value.trim() || disabled,
|
|
261
|
+
className: "p-1.5 rounded-[var(--radius-sm)] bg-[var(--brand-cool)]/15 hover:bg-[var(--brand-cool)]/25 text-[var(--brand-cool)] transition-colors disabled:opacity-30 shrink-0 mb-0.5",
|
|
262
|
+
children: /* @__PURE__ */ jsx3(Send, { className: "h-4 w-4" })
|
|
263
|
+
}
|
|
264
|
+
)
|
|
265
|
+
] }),
|
|
266
|
+
/* @__PURE__ */ jsxs3("div", { className: "flex items-center justify-between mt-1.5 px-1", children: [
|
|
267
|
+
/* @__PURE__ */ jsx3("div", { className: "flex items-center gap-2", children: modelLabel && /* @__PURE__ */ jsxs3(
|
|
268
|
+
"button",
|
|
269
|
+
{
|
|
270
|
+
onClick: onModelClick,
|
|
271
|
+
className: "inline-flex items-center gap-1 px-2 py-0.5 rounded-[var(--radius-full)] border border-[var(--border-subtle)] text-xs text-[var(--text-muted)] hover:border-[var(--border-accent)] hover:text-[var(--text-secondary)] transition-colors",
|
|
272
|
+
children: [
|
|
273
|
+
/* @__PURE__ */ jsx3("span", { className: "w-1.5 h-1.5 rounded-full bg-[var(--code-success)]" }),
|
|
274
|
+
modelLabel
|
|
275
|
+
]
|
|
276
|
+
}
|
|
277
|
+
) }),
|
|
278
|
+
/* @__PURE__ */ jsxs3("span", { className: "text-xs text-[var(--text-muted)]", children: [
|
|
279
|
+
/* @__PURE__ */ jsx3("kbd", { className: "px-1 py-0.5 bg-[var(--bg-input)] rounded border border-[var(--border-subtle)] text-[10px]", children: "Cmd" }),
|
|
280
|
+
/* @__PURE__ */ jsx3("kbd", { className: "px-1 py-0.5 bg-[var(--bg-input)] rounded border border-[var(--border-subtle)] text-[10px] ml-0.5", children: "L" }),
|
|
281
|
+
/* @__PURE__ */ jsx3("span", { className: "ml-1", children: "to focus" })
|
|
282
|
+
] })
|
|
283
|
+
] })
|
|
284
|
+
] });
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// src/chat/user-message.tsx
|
|
288
|
+
import { memo } from "react";
|
|
289
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
290
|
+
var UserMessage = memo(({ message, parts }) => {
|
|
291
|
+
const textContent = parts.filter((p) => p.type === "text").map((p) => p.text).join("\n");
|
|
292
|
+
if (!textContent.trim()) return null;
|
|
293
|
+
return /* @__PURE__ */ jsx4("div", { className: "flex justify-end", children: /* @__PURE__ */ jsx4("div", { className: "max-w-[85%] rounded-2xl rounded-br-md px-4 py-2.5 bg-blue-600/10 dark:bg-blue-600/20 border border-blue-500/15 dark:border-blue-500/20", children: /* @__PURE__ */ jsx4("div", { className: "text-sm text-neutral-900 dark:text-neutral-100", children: /* @__PURE__ */ jsx4(Markdown, { children: textContent }) }) }) });
|
|
294
|
+
});
|
|
295
|
+
UserMessage.displayName = "UserMessage";
|
|
296
|
+
|
|
297
|
+
// src/chat/message-list.tsx
|
|
298
|
+
import { memo as memo2 } from "react";
|
|
299
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
300
|
+
var MessageList = memo2(
|
|
301
|
+
({
|
|
302
|
+
groups,
|
|
303
|
+
partMap,
|
|
304
|
+
isCollapsed,
|
|
305
|
+
onToggleCollapse,
|
|
306
|
+
branding,
|
|
307
|
+
renderToolDetail
|
|
308
|
+
}) => {
|
|
309
|
+
return /* @__PURE__ */ jsx5("div", { className: "space-y-3", children: groups.map((group) => {
|
|
310
|
+
if (group.type === "user") {
|
|
311
|
+
return /* @__PURE__ */ jsx5(
|
|
312
|
+
UserMessage,
|
|
313
|
+
{
|
|
314
|
+
message: group.message,
|
|
315
|
+
parts: partMap[group.message.id] ?? []
|
|
316
|
+
},
|
|
317
|
+
group.message.id
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
return /* @__PURE__ */ jsx5(
|
|
321
|
+
RunGroup,
|
|
322
|
+
{
|
|
323
|
+
run: group.run,
|
|
324
|
+
partMap,
|
|
325
|
+
collapsed: isCollapsed(group.run.id),
|
|
326
|
+
onToggle: () => onToggleCollapse(group.run.id),
|
|
327
|
+
branding,
|
|
328
|
+
renderToolDetail
|
|
329
|
+
},
|
|
330
|
+
group.run.id
|
|
331
|
+
);
|
|
332
|
+
}) });
|
|
333
|
+
}
|
|
334
|
+
);
|
|
335
|
+
MessageList.displayName = "MessageList";
|
|
336
|
+
|
|
337
|
+
// src/chat/chat-container.tsx
|
|
338
|
+
import {
|
|
339
|
+
memo as memo3,
|
|
340
|
+
useCallback as useCallback2,
|
|
341
|
+
useRef as useRef3,
|
|
342
|
+
useState as useState3
|
|
343
|
+
} from "react";
|
|
344
|
+
import { ArrowDown, SendHorizonal } from "lucide-react";
|
|
345
|
+
import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
346
|
+
var ChatContainer = memo3(
|
|
347
|
+
({
|
|
348
|
+
messages,
|
|
349
|
+
partMap,
|
|
350
|
+
isStreaming,
|
|
351
|
+
onSend,
|
|
352
|
+
branding,
|
|
353
|
+
placeholder = "Type a message...",
|
|
354
|
+
className,
|
|
355
|
+
hideInput = false,
|
|
356
|
+
renderToolDetail
|
|
357
|
+
}) => {
|
|
358
|
+
const [inputValue, setInputValue] = useState3("");
|
|
359
|
+
const scrollRef = useRef3(null);
|
|
360
|
+
const inputRef = useRef3(null);
|
|
361
|
+
const groups = useRunGroups({ messages, partMap, isStreaming });
|
|
362
|
+
const runs = groups.filter((g) => g.type === "run").map((g) => g.run);
|
|
363
|
+
const { isCollapsed, toggleCollapse } = useRunCollapseState(runs);
|
|
364
|
+
const { isAtBottom, scrollToBottom } = useAutoScroll(scrollRef, [
|
|
365
|
+
messages,
|
|
366
|
+
partMap,
|
|
367
|
+
isStreaming
|
|
368
|
+
]);
|
|
369
|
+
const handleSubmit = useCallback2(
|
|
370
|
+
(e) => {
|
|
371
|
+
e?.preventDefault();
|
|
372
|
+
const text = inputValue.trim();
|
|
373
|
+
if (!text || !onSend) return;
|
|
374
|
+
onSend(text);
|
|
375
|
+
setInputValue("");
|
|
376
|
+
inputRef.current?.focus();
|
|
377
|
+
},
|
|
378
|
+
[inputValue, onSend]
|
|
379
|
+
);
|
|
380
|
+
const handleKeyDown = useCallback2(
|
|
381
|
+
(e) => {
|
|
382
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
|
383
|
+
e.preventDefault();
|
|
384
|
+
handleSubmit();
|
|
385
|
+
}
|
|
386
|
+
},
|
|
387
|
+
[handleSubmit]
|
|
388
|
+
);
|
|
389
|
+
return /* @__PURE__ */ jsxs4("div", { className: cn("flex flex-col h-full", className), children: [
|
|
390
|
+
/* @__PURE__ */ jsx6("div", { ref: scrollRef, className: "flex-1 overflow-y-auto px-4 py-4", children: messages.length === 0 ? /* @__PURE__ */ jsx6("div", { className: "flex items-center justify-center h-full text-sm text-neutral-400 dark:text-neutral-500", children: "No messages yet" }) : /* @__PURE__ */ jsx6(
|
|
391
|
+
MessageList,
|
|
392
|
+
{
|
|
393
|
+
groups,
|
|
394
|
+
partMap,
|
|
395
|
+
isCollapsed,
|
|
396
|
+
onToggleCollapse: toggleCollapse,
|
|
397
|
+
branding,
|
|
398
|
+
renderToolDetail
|
|
399
|
+
}
|
|
400
|
+
) }),
|
|
401
|
+
!isAtBottom && /* @__PURE__ */ jsx6("div", { className: "flex justify-center -mt-10 relative z-10", children: /* @__PURE__ */ jsxs4(
|
|
402
|
+
"button",
|
|
403
|
+
{
|
|
404
|
+
onClick: scrollToBottom,
|
|
405
|
+
className: cn(
|
|
406
|
+
"flex items-center gap-1.5 px-3 py-1.5 rounded-full",
|
|
407
|
+
"bg-white dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 shadow-lg",
|
|
408
|
+
"text-xs text-neutral-600 dark:text-neutral-300 hover:bg-neutral-50 dark:hover:bg-neutral-700 transition-colors"
|
|
409
|
+
),
|
|
410
|
+
children: [
|
|
411
|
+
/* @__PURE__ */ jsx6(ArrowDown, { className: "w-3 h-3" }),
|
|
412
|
+
"Scroll to bottom"
|
|
413
|
+
]
|
|
414
|
+
}
|
|
415
|
+
) }),
|
|
416
|
+
!hideInput && onSend && /* @__PURE__ */ jsx6(
|
|
417
|
+
"form",
|
|
418
|
+
{
|
|
419
|
+
onSubmit: handleSubmit,
|
|
420
|
+
className: "shrink-0 border-t border-neutral-200/50 dark:border-neutral-700/50 p-3",
|
|
421
|
+
children: /* @__PURE__ */ jsxs4("div", { className: "flex items-end gap-2", children: [
|
|
422
|
+
/* @__PURE__ */ jsx6(
|
|
423
|
+
"textarea",
|
|
424
|
+
{
|
|
425
|
+
ref: inputRef,
|
|
426
|
+
value: inputValue,
|
|
427
|
+
onChange: (e) => setInputValue(e.target.value),
|
|
428
|
+
onKeyDown: handleKeyDown,
|
|
429
|
+
placeholder,
|
|
430
|
+
rows: 1,
|
|
431
|
+
disabled: isStreaming,
|
|
432
|
+
className: cn(
|
|
433
|
+
"flex-1 resize-none rounded-lg px-3 py-2",
|
|
434
|
+
"bg-neutral-50/60 dark:bg-neutral-800/60 border border-neutral-200/50 dark:border-neutral-700/50",
|
|
435
|
+
"text-sm text-neutral-900 dark:text-neutral-100 placeholder:text-neutral-400 dark:placeholder:text-neutral-500",
|
|
436
|
+
"focus:outline-none focus:border-blue-500/50",
|
|
437
|
+
"disabled:opacity-50 disabled:cursor-not-allowed",
|
|
438
|
+
"max-h-32"
|
|
439
|
+
),
|
|
440
|
+
style: { minHeight: "2.5rem" }
|
|
441
|
+
}
|
|
442
|
+
),
|
|
443
|
+
/* @__PURE__ */ jsx6(
|
|
444
|
+
"button",
|
|
445
|
+
{
|
|
446
|
+
type: "submit",
|
|
447
|
+
disabled: isStreaming || !inputValue.trim(),
|
|
448
|
+
className: cn(
|
|
449
|
+
"flex items-center justify-center w-9 h-9 rounded-lg",
|
|
450
|
+
"bg-blue-600 hover:bg-blue-500 transition-colors",
|
|
451
|
+
"disabled:opacity-30 disabled:cursor-not-allowed"
|
|
452
|
+
),
|
|
453
|
+
children: /* @__PURE__ */ jsx6(SendHorizonal, { className: "w-4 h-4 text-white" })
|
|
454
|
+
}
|
|
455
|
+
)
|
|
456
|
+
] })
|
|
457
|
+
}
|
|
458
|
+
)
|
|
459
|
+
] });
|
|
460
|
+
}
|
|
461
|
+
);
|
|
462
|
+
ChatContainer.displayName = "ChatContainer";
|
|
463
|
+
|
|
464
|
+
export {
|
|
465
|
+
ChatMessage,
|
|
466
|
+
ChatMessageList,
|
|
467
|
+
ThinkingIndicator,
|
|
468
|
+
ChatInput,
|
|
469
|
+
UserMessage,
|
|
470
|
+
MessageList,
|
|
471
|
+
ChatContainer
|
|
472
|
+
};
|