@castlekit/castle 0.1.6 → 0.3.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 (70) hide show
  1. package/LICENSE +21 -0
  2. package/drizzle.config.ts +7 -0
  3. package/install.sh +20 -1
  4. package/next.config.ts +1 -0
  5. package/package.json +35 -3
  6. package/src/app/api/avatars/[id]/route.ts +57 -7
  7. package/src/app/api/openclaw/agents/route.ts +7 -1
  8. package/src/app/api/openclaw/agents/status/route.ts +55 -0
  9. package/src/app/api/openclaw/chat/attachments/route.ts +230 -0
  10. package/src/app/api/openclaw/chat/channels/route.ts +217 -0
  11. package/src/app/api/openclaw/chat/route.ts +283 -0
  12. package/src/app/api/openclaw/chat/search/route.ts +150 -0
  13. package/src/app/api/openclaw/chat/storage/route.ts +75 -0
  14. package/src/app/api/openclaw/config/route.ts +2 -0
  15. package/src/app/api/openclaw/events/route.ts +23 -8
  16. package/src/app/api/openclaw/logs/route.ts +17 -3
  17. package/src/app/api/openclaw/ping/route.ts +5 -0
  18. package/src/app/api/openclaw/restart/route.ts +6 -1
  19. package/src/app/api/openclaw/session/context/route.ts +163 -0
  20. package/src/app/api/openclaw/session/status/route.ts +210 -0
  21. package/src/app/api/openclaw/sessions/route.ts +2 -0
  22. package/src/app/api/settings/avatar/route.ts +190 -0
  23. package/src/app/api/settings/route.ts +88 -0
  24. package/src/app/chat/[channelId]/error-boundary.tsx +64 -0
  25. package/src/app/chat/[channelId]/page.tsx +385 -0
  26. package/src/app/chat/layout.tsx +96 -0
  27. package/src/app/chat/page.tsx +52 -0
  28. package/src/app/globals.css +99 -2
  29. package/src/app/layout.tsx +7 -1
  30. package/src/app/page.tsx +59 -25
  31. package/src/app/settings/page.tsx +300 -0
  32. package/src/components/chat/agent-mention-popup.tsx +89 -0
  33. package/src/components/chat/archived-channels.tsx +190 -0
  34. package/src/components/chat/channel-list.tsx +140 -0
  35. package/src/components/chat/chat-input.tsx +328 -0
  36. package/src/components/chat/create-channel-dialog.tsx +171 -0
  37. package/src/components/chat/markdown-content.tsx +205 -0
  38. package/src/components/chat/message-bubble.tsx +168 -0
  39. package/src/components/chat/message-list.tsx +666 -0
  40. package/src/components/chat/message-queue.tsx +68 -0
  41. package/src/components/chat/session-divider.tsx +61 -0
  42. package/src/components/chat/session-stats-panel.tsx +444 -0
  43. package/src/components/chat/storage-indicator.tsx +76 -0
  44. package/src/components/layout/sidebar.tsx +126 -45
  45. package/src/components/layout/user-menu.tsx +29 -4
  46. package/src/components/providers/presence-provider.tsx +8 -0
  47. package/src/components/providers/search-provider.tsx +110 -0
  48. package/src/components/search/search-dialog.tsx +269 -0
  49. package/src/components/ui/avatar.tsx +11 -9
  50. package/src/components/ui/dialog.tsx +10 -4
  51. package/src/components/ui/tooltip.tsx +25 -8
  52. package/src/components/ui/twemoji-text.tsx +37 -0
  53. package/src/lib/api-security.ts +125 -0
  54. package/src/lib/date-utils.ts +79 -0
  55. package/src/lib/db/index.ts +652 -0
  56. package/src/lib/db/queries.ts +1144 -0
  57. package/src/lib/db/schema.ts +164 -0
  58. package/src/lib/gateway-connection.ts +24 -3
  59. package/src/lib/hooks/use-agent-status.ts +251 -0
  60. package/src/lib/hooks/use-chat.ts +753 -0
  61. package/src/lib/hooks/use-compaction-events.ts +132 -0
  62. package/src/lib/hooks/use-context-boundary.ts +82 -0
  63. package/src/lib/hooks/use-openclaw.ts +122 -100
  64. package/src/lib/hooks/use-search.ts +114 -0
  65. package/src/lib/hooks/use-session-stats.ts +60 -0
  66. package/src/lib/hooks/use-user-settings.ts +46 -0
  67. package/src/lib/sse-singleton.ts +184 -0
  68. package/src/lib/types/chat.ts +202 -0
  69. package/src/lib/types/search.ts +60 -0
  70. package/src/middleware.ts +52 -0
@@ -0,0 +1,385 @@
1
+ "use client";
2
+
3
+ import { use, useState, useEffect, useCallback, useRef } from "react";
4
+ import { useSearchParams } from "next/navigation";
5
+ import { WifiOff, X, AlertCircle, Zap } from "lucide-react";
6
+ import { cn } from "@/lib/utils";
7
+ import { useOpenClaw } from "@/lib/hooks/use-openclaw";
8
+ import { useChat } from "@/lib/hooks/use-chat";
9
+ import { useSessionStats } from "@/lib/hooks/use-session-stats";
10
+ import { useCompactionEvents } from "@/lib/hooks/use-compaction-events";
11
+ import { useContextBoundary } from "@/lib/hooks/use-context-boundary";
12
+ import { useUserSettings } from "@/lib/hooks/use-user-settings";
13
+ import { MessageList } from "@/components/chat/message-list";
14
+ import { ChatInput } from "@/components/chat/chat-input";
15
+ import { SessionStatsIndicator } from "@/components/chat/session-stats-panel";
16
+ import { SearchTrigger } from "@/components/providers/search-provider";
17
+ import { ChatErrorBoundary } from "./error-boundary";
18
+ import type { AgentInfo } from "@/components/chat/agent-mention-popup";
19
+
20
+ interface ChannelPageProps {
21
+ params: Promise<{ channelId: string }>;
22
+ }
23
+
24
+ // Module-level flag: once any channel has rendered real content, subsequent
25
+ // channel switches use a smooth opacity transition instead of the skeleton.
26
+ // NOTE: This persists for the entire browser session and never resets.
27
+ // If Castle ever supports logout or multi-user, this will need a reset mechanism.
28
+ let hasEverRendered = false;
29
+
30
+ // ---------------------------------------------------------------------------
31
+ // Skeleton loader — Facebook-style placeholder while data loads
32
+ // ---------------------------------------------------------------------------
33
+ const LINE_WIDTHS = ["80%", "60%", "40%", "75%", "55%", "85%", "45%", "70%", "50%"];
34
+
35
+ function SkeletonMessage({ lines = 2, short = false, offset = 0 }: { lines?: number; short?: boolean; offset?: number }) {
36
+ return (
37
+ <div className="flex gap-3 mb-[4px]">
38
+ <div className="skeleton w-9 h-9 rounded-full shrink-0 mt-0.5" />
39
+ <div className="flex flex-col gap-1.5 flex-1">
40
+ <div className="flex items-center gap-2">
41
+ <div className={cn("skeleton h-3.5", short ? "w-16" : "w-24")} />
42
+ <div className="skeleton h-3 w-14" />
43
+ </div>
44
+ {Array.from({ length: lines }).map((_, i) => (
45
+ <div
46
+ key={i}
47
+ className="skeleton h-3.5"
48
+ style={{ width: LINE_WIDTHS[(offset + i) % LINE_WIDTHS.length] }}
49
+ />
50
+ ))}
51
+ </div>
52
+ </div>
53
+ );
54
+ }
55
+
56
+ function ChatSkeleton() {
57
+ return (
58
+ <div className="flex-1 flex flex-col h-full overflow-hidden">
59
+ {/* Header skeleton */}
60
+ <div className="py-4 border-b border-border shrink-0 min-h-[83px] flex items-center">
61
+ <div>
62
+ <div className="skeleton h-5 w-40 mb-1.5" />
63
+ <div className="skeleton h-3.5 w-28" />
64
+ </div>
65
+ </div>
66
+
67
+ {/* Messages skeleton */}
68
+ <div className="flex-1 overflow-hidden py-[20px] pr-[20px] flex flex-col justify-end">
69
+ <div className="flex flex-col gap-6">
70
+ <SkeletonMessage lines={3} offset={0} />
71
+ <SkeletonMessage lines={1} short offset={3} />
72
+ <SkeletonMessage lines={2} offset={4} />
73
+ <SkeletonMessage lines={1} short offset={6} />
74
+ <SkeletonMessage lines={2} offset={7} />
75
+ <SkeletonMessage lines={3} offset={1} />
76
+ <SkeletonMessage lines={1} short offset={5} />
77
+ </div>
78
+ </div>
79
+
80
+ {/* Real input, just disabled while loading */}
81
+ <div className="shrink-0">
82
+ <ChatInput
83
+ onSend={() => Promise.resolve()}
84
+ onAbort={() => Promise.resolve()}
85
+ sending={false}
86
+ streaming={false}
87
+ disabled
88
+ agents={[]}
89
+ channelId=""
90
+ />
91
+ </div>
92
+ </div>
93
+ );
94
+ }
95
+
96
+ function ChannelChatContent({ channelId }: { channelId: string }) {
97
+ // Read ?m= param for scroll-to-message from search results.
98
+ // useSearchParams() is reactive — it updates when the query string
99
+ // changes, even for same-channel navigation (e.g. clicking two
100
+ // different search results in the same channel).
101
+ const searchParams = useSearchParams();
102
+ const highlightMessageId = searchParams.get("m") || undefined;
103
+ const { agents, isConnected, isLoading: gatewayLoading, agentsLoading } = useOpenClaw();
104
+ const [channelName, setChannelName] = useState<string | null>(null);
105
+ const [channelAgentIds, setChannelAgentIds] = useState<string[]>([]);
106
+ const [channelCreatedAt, setChannelCreatedAt] = useState<number | null>(null);
107
+ const [channelArchived, setChannelArchived] = useState(false);
108
+ const { displayName, avatarUrl: userAvatar, isLoading: userSettingsLoading } = useUserSettings();
109
+
110
+ // Mark this channel as last accessed and fetch channel info
111
+ useEffect(() => {
112
+ // Touch (mark as last accessed)
113
+ fetch("/api/openclaw/chat/channels", {
114
+ method: "POST",
115
+ headers: { "Content-Type": "application/json" },
116
+ body: JSON.stringify({ action: "touch", id: channelId }),
117
+ }).catch(() => {});
118
+
119
+ // Fetch channel details for the name and agents.
120
+ // Try active channels first, then archived if not found.
121
+ // Falls back to channelId as name if both fail (prevents stuck loading).
122
+ fetch("/api/openclaw/chat/channels")
123
+ .then((r) => r.json())
124
+ .then((data) => {
125
+ const ch = (data.channels || []).find(
126
+ (c: { id: string; name: string; agents?: string[] }) =>
127
+ c.id === channelId
128
+ );
129
+ if (ch) {
130
+ setChannelName(ch.name);
131
+ setChannelAgentIds(ch.agents || []);
132
+ setChannelCreatedAt(ch.createdAt ?? null);
133
+ setChannelArchived(false);
134
+ } else {
135
+ // Channel not in active list — check archived channels
136
+ return fetch("/api/openclaw/chat/channels?archived=1")
137
+ .then((r) => r.json())
138
+ .then((archived) => {
139
+ const archivedCh = (archived.channels || []).find(
140
+ (c: { id: string; name: string; agents?: string[] }) =>
141
+ c.id === channelId
142
+ );
143
+ if (archivedCh) {
144
+ setChannelName(archivedCh.name);
145
+ setChannelAgentIds(archivedCh.agents || []);
146
+ setChannelCreatedAt(archivedCh.createdAt ?? null);
147
+ setChannelArchived(true);
148
+ } else {
149
+ // Channel not found anywhere — use ID as fallback name
150
+ setChannelName("Chat");
151
+ }
152
+ });
153
+ }
154
+ })
155
+ .catch(() => {
156
+ // Network error — fall back so page doesn't stay stuck
157
+ setChannelName("Chat");
158
+ });
159
+ }, [channelId]);
160
+
161
+ // Map agents to the AgentInfo format used by chat components
162
+ const chatAgents: AgentInfo[] = agents.map((a) => ({
163
+ id: a.id,
164
+ name: a.name,
165
+ avatar: a.avatar,
166
+ }));
167
+
168
+ // Get default agent (first in list)
169
+ const defaultAgentId = agents[0]?.id;
170
+
171
+ const {
172
+ messages,
173
+ isLoading,
174
+ hasMore,
175
+ loadMore,
176
+ loadingMore,
177
+ hasMoreAfter,
178
+ loadNewer,
179
+ loadingNewer,
180
+ streamingMessages,
181
+ isStreaming,
182
+ currentSessionKey,
183
+ sendMessage,
184
+ abortResponse,
185
+ sending,
186
+ sendError,
187
+ clearSendError,
188
+ } = useChat({ channelId, defaultAgentId, anchorMessageId: highlightMessageId });
189
+
190
+ const { stats, isLoading: statsLoading, refresh: refreshStats } = useSessionStats({
191
+ sessionKey: currentSessionKey,
192
+ });
193
+
194
+ const { boundaryMessageId, refresh: refreshBoundary } = useContextBoundary({
195
+ sessionKey: currentSessionKey,
196
+ channelId,
197
+ });
198
+
199
+ const { isCompacting, showBanner: showCompactionBanner, dismissBanner, compactionCount: liveCompactionCount } = useCompactionEvents({
200
+ sessionKey: currentSessionKey,
201
+ onCompactionComplete: () => {
202
+ refreshStats();
203
+ refreshBoundary();
204
+ },
205
+ });
206
+
207
+ // Ref to the navigate-between-messages function exposed by MessageList
208
+ const navigateRef = useRef<((direction: "up" | "down") => void) | null>(null);
209
+
210
+ // Handle Shift+ArrowUp/Down to navigate between messages
211
+ const handleNavigate = useCallback((direction: "up" | "down") => {
212
+ navigateRef.current?.(direction);
213
+ }, []);
214
+
215
+ // Don't render until channel name, agents, and user settings have all loaded.
216
+ const channelReady = channelName !== null && !agentsLoading && !userSettingsLoading;
217
+
218
+ // First cold load → skeleton. If agents/user are already cached (e.g.
219
+ // navigated from dashboard) or we've rendered before, use opacity transition.
220
+ const dataAlreadyCached = !agentsLoading && !userSettingsLoading;
221
+ if (channelReady) hasEverRendered = true;
222
+
223
+ if (!channelReady && !hasEverRendered && !dataAlreadyCached) {
224
+ return <ChatSkeleton />;
225
+ }
226
+
227
+ return (
228
+ <div className="flex-1 flex flex-col h-full overflow-hidden">
229
+ {/* Channel header — always visible, never fades */}
230
+ <div className="pt-[7px] pb-[30px] border-b border-border shrink-0">
231
+ <div className="flex items-center justify-between gap-4">
232
+ {/* Left: channel name + participants */}
233
+ <div className="min-w-0 min-h-[45px]">
234
+ {channelName ? (
235
+ <>
236
+ <h2 className="text-lg font-semibold text-foreground leading-tight">
237
+ {channelName}
238
+ {channelArchived && (
239
+ <span className="ml-2 text-sm font-normal text-foreground-secondary">(Archived)</span>
240
+ )}
241
+ </h2>
242
+ {(displayName || channelAgentIds.length > 0) && agents.length > 0 && (
243
+ <p className="text-sm text-foreground-secondary mt-0.5">
244
+ with{" "}
245
+ {(() => {
246
+ const names = [
247
+ displayName,
248
+ ...channelAgentIds.map(
249
+ (id) => agents.find((a) => a.id === id)?.name || id
250
+ ),
251
+ ].filter(Boolean);
252
+ if (names.length <= 2) return names.join(" & ");
253
+ return names.slice(0, -1).join(", ") + " & " + names[names.length - 1];
254
+ })()}
255
+ </p>
256
+ )}
257
+ </>
258
+ ) : (
259
+ <>
260
+ <div className="skeleton h-5 w-40 rounded mb-1.5" />
261
+ <div className="skeleton h-3.5 w-28 rounded" />
262
+ </>
263
+ )}
264
+ </div>
265
+ {/* Right: session stats + search */}
266
+ <div className="flex items-center gap-5 shrink-0">
267
+ <SessionStatsIndicator
268
+ stats={stats}
269
+ isLoading={statsLoading}
270
+ isCompacting={isCompacting}
271
+ liveCompactionCount={liveCompactionCount}
272
+ />
273
+ <SearchTrigger />
274
+ </div>
275
+ </div>
276
+ </div>
277
+
278
+ {/* Content area */}
279
+ {!channelReady ? (
280
+ /* Skeleton messages while loading */
281
+ <div className="flex-1 overflow-hidden py-[20px] pr-[20px] flex flex-col justify-end">
282
+ <div className="flex flex-col gap-6">
283
+ <SkeletonMessage lines={3} offset={0} />
284
+ <SkeletonMessage lines={1} short offset={3} />
285
+ <SkeletonMessage lines={2} offset={4} />
286
+ <SkeletonMessage lines={1} short offset={6} />
287
+ <SkeletonMessage lines={2} offset={7} />
288
+ <SkeletonMessage lines={3} offset={1} />
289
+ </div>
290
+ </div>
291
+ ) : (
292
+ <div className="flex-1 flex flex-col overflow-hidden">
293
+
294
+ {/* Connection warning banner — sticky */}
295
+ {!isConnected && !gatewayLoading && (
296
+ <div className="px-4 py-2 bg-error/10 border-b border-error/20 flex items-center gap-2 text-sm text-error shrink-0">
297
+ <WifiOff className="h-4 w-4" />
298
+ <span>Gateway disconnected. Reconnecting...</span>
299
+ </div>
300
+ )}
301
+
302
+ {/* Compaction banner */}
303
+ {showCompactionBanner && (
304
+ <div className="px-4 py-2 bg-yellow-500/10 border-b border-yellow-500/20 flex items-center justify-between text-sm text-yellow-600 dark:text-yellow-400 shrink-0">
305
+ <div className="flex items-center gap-2">
306
+ <Zap className="h-4 w-4" />
307
+ <span>Context compacted — older messages have been summarized</span>
308
+ </div>
309
+ <button
310
+ onClick={dismissBanner}
311
+ className="p-1 hover:bg-yellow-500/20 rounded"
312
+ >
313
+ <X className="h-3 w-3" />
314
+ </button>
315
+ </div>
316
+ )}
317
+
318
+ {/* Messages — this is the ONLY scrollable area */}
319
+ <MessageList
320
+ messages={messages}
321
+ loading={isLoading}
322
+ loadingMore={loadingMore}
323
+ hasMore={hasMore}
324
+ agents={chatAgents}
325
+ userAvatar={userAvatar}
326
+ streamingMessages={streamingMessages}
327
+ onLoadMore={loadMore}
328
+ hasMoreAfter={hasMoreAfter}
329
+ onLoadNewer={loadNewer}
330
+ loadingNewer={loadingNewer}
331
+ channelId={channelId}
332
+ channelName={channelName}
333
+ channelCreatedAt={channelCreatedAt}
334
+ highlightMessageId={highlightMessageId}
335
+ navigateRef={navigateRef}
336
+ compactionBoundaryMessageId={boundaryMessageId}
337
+ compactionCount={stats?.compactions ?? 0}
338
+ />
339
+
340
+ {/* Error toast — sticky above input */}
341
+ {sendError && (
342
+ <div className="mx-4 mb-2 px-4 py-2 rounded-lg bg-error/10 border border-error/20 flex items-center justify-between shrink-0">
343
+ <div className="flex items-center gap-2 text-sm text-error">
344
+ <AlertCircle className="h-4 w-4 shrink-0" />
345
+ <span>{sendError}</span>
346
+ </div>
347
+ <button
348
+ onClick={clearSendError}
349
+ className="p-1 hover:bg-error/20 rounded"
350
+ >
351
+ <X className="h-3 w-3 text-error" />
352
+ </button>
353
+ </div>
354
+ )}
355
+
356
+ </div>
357
+ )}
358
+
359
+ {/* Input — always visible, disabled until channel is ready */}
360
+ <div className="shrink-0">
361
+ <ChatInput
362
+ onSend={sendMessage}
363
+ onAbort={abortResponse}
364
+ sending={sending}
365
+ streaming={isStreaming}
366
+ disabled={!channelReady || (!isConnected && !gatewayLoading)}
367
+ agents={chatAgents}
368
+ defaultAgentId={defaultAgentId}
369
+ channelId={channelId}
370
+ onNavigate={handleNavigate}
371
+ />
372
+ </div>
373
+ </div>
374
+ );
375
+ }
376
+
377
+ export default function ChannelPage({ params }: ChannelPageProps) {
378
+ const { channelId } = use(params);
379
+
380
+ return (
381
+ <ChatErrorBoundary>
382
+ <ChannelChatContent channelId={channelId} />
383
+ </ChatErrorBoundary>
384
+ );
385
+ }
@@ -0,0 +1,96 @@
1
+ "use client";
2
+
3
+ import { useState } from "react";
4
+ import { Plus, Archive } from "lucide-react";
5
+ import { Sidebar } from "@/components/layout/sidebar";
6
+
7
+ import { ChannelList } from "@/components/chat/channel-list";
8
+ import { ArchivedChannels } from "@/components/chat/archived-channels";
9
+ import { CreateChannelDialog } from "@/components/chat/create-channel-dialog";
10
+ import { useParams, useRouter } from "next/navigation";
11
+ import type { Channel } from "@/lib/types/chat";
12
+
13
+ export default function ChatLayout({
14
+ children,
15
+ }: {
16
+ children: React.ReactNode;
17
+ }) {
18
+ const params = useParams();
19
+ const router = useRouter();
20
+ const channelId = params?.channelId as string | undefined;
21
+ const [showCreate, setShowCreate] = useState(false);
22
+ const [showArchived, setShowArchived] = useState(false);
23
+ const [newChannel, setNewChannel] = useState<Channel | null>(null);
24
+
25
+ const handleChannelCreated = (channel: Channel) => {
26
+ setNewChannel(channel);
27
+ setShowCreate(false);
28
+ router.push(`/chat/${channel.id}`);
29
+ };
30
+
31
+ return (
32
+ <div className="h-screen overflow-hidden bg-background">
33
+ <Sidebar variant="solid" />
34
+
35
+ <div className="h-screen ml-[80px] flex py-[20px]">
36
+ {/* Channel sidebar — floating glass panel, aligned with sidebar pill */}
37
+ <div className="w-[290px] shrink-0 px-[25px]">
38
+ <div className="h-full panel flex flex-col">
39
+ <div className="pl-4 pr-3 py-3 flex items-center justify-between shrink-0 border-b border-border">
40
+ <h2 className="text-sm font-semibold text-foreground">
41
+ Channels
42
+ </h2>
43
+ <button
44
+ onClick={() => setShowCreate(true)}
45
+ title="New channel"
46
+ className="flex items-center justify-center h-7 w-7 rounded-[var(--radius-sm)] bg-accent text-white hover:bg-accent/90 transition-colors cursor-pointer"
47
+ >
48
+ <Plus className="h-4 w-4 stroke-[2.5]" />
49
+ </button>
50
+ </div>
51
+ <div className="flex-1 overflow-y-auto px-3 py-3">
52
+ <ChannelList
53
+ activeChannelId={channelId}
54
+ showCreateDialog={showCreate}
55
+ onCreateDialogChange={setShowCreate}
56
+ newChannel={newChannel}
57
+ />
58
+ </div>
59
+ <div className="shrink-0 px-3 pb-3">
60
+ <button
61
+ onClick={() => setShowArchived(true)}
62
+ className="flex items-center justify-center gap-2 w-full px-2 py-2 text-xs text-foreground-secondary hover:text-foreground transition-colors cursor-pointer rounded-[var(--radius-sm)] hover:bg-surface-hover"
63
+ >
64
+ <Archive className="h-3.5 w-3.5" />
65
+ Archived channels
66
+ </button>
67
+ </div>
68
+ </div>
69
+ </div>
70
+
71
+ {/* Main content — fills remaining space, aligned with floating boxes */}
72
+ <div className="flex-1 min-w-0 h-full overflow-hidden pr-[20px] flex flex-col">
73
+ {children}
74
+ </div>
75
+ </div>
76
+
77
+ {/* Create channel dialog — rendered at layout root, outside glass panel */}
78
+ <CreateChannelDialog
79
+ open={showCreate}
80
+ onOpenChange={setShowCreate}
81
+ onCreated={handleChannelCreated}
82
+ />
83
+
84
+ {/* Archived channels dialog */}
85
+ <ArchivedChannels
86
+ open={showArchived}
87
+ onOpenChange={setShowArchived}
88
+ onRestored={(channel) => {
89
+ setNewChannel(channel);
90
+ setShowArchived(false);
91
+ router.push(`/chat/${channel.id}`);
92
+ }}
93
+ />
94
+ </div>
95
+ );
96
+ }
@@ -0,0 +1,52 @@
1
+ "use client";
2
+
3
+ import { useEffect, useState } from "react";
4
+ import { useRouter } from "next/navigation";
5
+ import { MessageCircle, Loader2 } from "lucide-react";
6
+
7
+ export default function ChatPage() {
8
+ const router = useRouter();
9
+ const [checking, setChecking] = useState(true);
10
+
11
+ useEffect(() => {
12
+ // Ask the DB for the last accessed channel
13
+ fetch("/api/openclaw/chat/channels?last=1")
14
+ .then((res) => (res.ok ? res.json() : null))
15
+ .then((data) => {
16
+ if (data?.channelId) {
17
+ router.replace(`/chat/${data.channelId}`);
18
+ return;
19
+ }
20
+ // No last accessed — try the most recent channel
21
+ return fetch("/api/openclaw/chat/channels")
22
+ .then((res) => (res.ok ? res.json() : null))
23
+ .then((chData) => {
24
+ const channels = chData?.channels;
25
+ if (channels && channels.length > 0) {
26
+ router.replace(`/chat/${channels[0].id}`);
27
+ } else {
28
+ setChecking(false);
29
+ }
30
+ });
31
+ })
32
+ .catch(() => setChecking(false));
33
+ }, [router]);
34
+
35
+ if (checking) {
36
+ return <div className="flex-1" />;
37
+ }
38
+
39
+ return (
40
+ <div className="flex-1 flex items-center justify-center">
41
+ <div className="text-center space-y-3">
42
+ <MessageCircle className="h-12 w-12 mx-auto text-foreground-secondary/30" />
43
+ <div>
44
+ <h2 className="text-lg font-semibold text-foreground">Welcome to Chat</h2>
45
+ <p className="text-sm text-foreground-secondary mt-1">
46
+ Select a channel from the sidebar or create a new one to start chatting.
47
+ </p>
48
+ </div>
49
+ </div>
50
+ </div>
51
+ );
52
+ }
@@ -86,8 +86,8 @@
86
86
  --border: #35353d;
87
87
  --border-hover: #45454d;
88
88
 
89
- --foreground: #fafafa;
90
- --foreground-secondary: #a1a1aa;
89
+ --foreground: #d1d2d3;
90
+ --foreground-secondary: #9a9b9e;
91
91
  --foreground-muted: #71717a;
92
92
 
93
93
  --accent: #3b82f6;
@@ -186,6 +186,43 @@ body {
186
186
  overscroll-behavior: none;
187
187
  }
188
188
 
189
+ /* Twemoji — inline emoji images matching text size exactly.
190
+ Sized to 1em so the img is no taller than a capital letter,
191
+ preventing any line-height expansion. */
192
+ img.emoji {
193
+ display: inline;
194
+ height: 1em;
195
+ width: 1em;
196
+ margin: 0 0.05em;
197
+ vertical-align: -0.1em;
198
+ }
199
+
200
+ /* Custom scrollbar — overlay style, just the thumb, no track */
201
+ /* WebKit (Chrome, Safari, Edge) */
202
+ ::-webkit-scrollbar {
203
+ width: 6px;
204
+ background: none;
205
+ }
206
+ ::-webkit-scrollbar-track {
207
+ background: none;
208
+ }
209
+ ::-webkit-scrollbar-thumb {
210
+ background: rgba(255, 255, 255, 0.2);
211
+ border-radius: 3px;
212
+ }
213
+ ::-webkit-scrollbar-thumb:hover {
214
+ background: rgba(255, 255, 255, 0.35);
215
+ }
216
+ ::-webkit-scrollbar-corner {
217
+ background: none;
218
+ }
219
+
220
+ /* Firefox */
221
+ * {
222
+ scrollbar-width: thin;
223
+ scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
224
+ }
225
+
189
226
  /* ============================================
190
227
  Reusable Component Patterns
191
228
  ============================================ */
@@ -221,6 +258,21 @@ body {
221
258
  @apply cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50;
222
259
  }
223
260
 
261
+ /* Panel — standard container style matching dashboard cards (bg-surface, bordered, rounded).
262
+ Use for sidebars, floating panels, content sections. */
263
+ .panel {
264
+ @apply rounded-[var(--radius-md)] bg-surface border border-border;
265
+ }
266
+
267
+ /* Selectable list — compact spacing for checkbox/radio lists, nav lists, etc.
268
+ Apply .selectable-list to the container; .selectable-list-item to each row. */
269
+ .selectable-list {
270
+ @apply space-y-0.5;
271
+ }
272
+ .selectable-list-item {
273
+ @apply flex items-center gap-2.5 px-2 py-1.5 rounded-[var(--radius-sm)] hover:bg-surface-hover cursor-pointer text-sm;
274
+ }
275
+
224
276
  /* Input base - shared input/select/textarea styles */
225
277
  .input-base {
226
278
  @apply h-11 w-full rounded-[var(--radius-sm)] border px-3 py-2 text-sm text-foreground transition-all;
@@ -284,3 +336,48 @@ body {
284
336
  transform: scale(1);
285
337
  }
286
338
  }
339
+
340
+ /* Search result highlight flash */
341
+ @keyframes highlight-flash {
342
+ 0% {
343
+ background-color: oklch(from var(--color-accent) l c h / 0.15);
344
+ }
345
+ 100% {
346
+ background-color: transparent;
347
+ }
348
+ }
349
+ .animate-highlight-flash {
350
+ animation: highlight-flash 2s ease-out;
351
+ }
352
+
353
+ /* Typing indicator dot bounce */
354
+ @keyframes dot-bounce {
355
+ 0%, 80%, 100% {
356
+ transform: translateY(0);
357
+ }
358
+ 40% {
359
+ transform: translateY(-5px);
360
+ }
361
+ }
362
+
363
+ /* Skeleton shimmer */
364
+ @keyframes shimmer {
365
+ 0% {
366
+ background-position: -200% 0;
367
+ }
368
+ 100% {
369
+ background-position: 200% 0;
370
+ }
371
+ }
372
+ .skeleton {
373
+ background: linear-gradient(
374
+ 90deg,
375
+ oklch(from var(--color-foreground) l c h / 0.06) 25%,
376
+ oklch(from var(--color-foreground) l c h / 0.12) 50%,
377
+ oklch(from var(--color-foreground) l c h / 0.06) 75%
378
+ );
379
+ background-size: 200% 100%;
380
+ animation: shimmer 1.5s ease-in-out infinite;
381
+ border-radius: 4px;
382
+ }
383
+
@@ -1,6 +1,8 @@
1
1
  import type { Metadata } from "next";
2
2
  import { Geist, Geist_Mono } from "next/font/google";
3
3
  import { ThemeProvider } from "next-themes";
4
+ import { PresenceProvider } from "@/components/providers/presence-provider";
5
+ import { SearchProvider } from "@/components/providers/search-provider";
4
6
  import "./globals.css";
5
7
 
6
8
  const geistSans = Geist({
@@ -34,7 +36,11 @@ export default function RootLayout({
34
36
  enableSystem={false}
35
37
  disableTransitionOnChange
36
38
  >
37
- {children}
39
+ <PresenceProvider>
40
+ <SearchProvider>
41
+ {children}
42
+ </SearchProvider>
43
+ </PresenceProvider>
38
44
  </ThemeProvider>
39
45
  </body>
40
46
  </html>