@townco/gui-template 0.1.27 → 0.1.29

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/src/ChatView.tsx DELETED
@@ -1,429 +0,0 @@
1
- import { createLogger } from "@townco/core";
2
- import type { AcpClient } from "@townco/ui";
3
- import {
4
- useChatMessages,
5
- useChatSession,
6
- useChatStore,
7
- useToolCalls,
8
- } from "@townco/ui/core";
9
- import {
10
- ChatEmptyState,
11
- ChatHeader,
12
- ChatInputActions,
13
- ChatInputAttachment,
14
- ChatInputCommandMenu,
15
- ChatInputField,
16
- ChatInputRoot,
17
- ChatInputSubmit,
18
- ChatInputToolbar,
19
- ChatInputVoiceInput,
20
- ChatLayout,
21
- type CommandMenuItem,
22
- cn,
23
- FilesTabContent,
24
- Message,
25
- MessageContent,
26
- PanelTabsHeader,
27
- type SourceItem,
28
- SourcesTabContent,
29
- Tabs,
30
- TabsContent,
31
- type TodoItem,
32
- TodoTabContent,
33
- } from "@townco/ui/gui";
34
- import {
35
- ArrowUp,
36
- ChevronUp,
37
- Code,
38
- PanelRight,
39
- Settings,
40
- Sparkles,
41
- } from "lucide-react";
42
- import { useEffect, useState } from "react";
43
-
44
- const logger = createLogger("gui");
45
-
46
- export interface ChatViewProps {
47
- client: AcpClient | null;
48
- initialSessionId?: string | null;
49
- }
50
-
51
- // Mobile header component that uses ChatHeader context
52
- function MobileHeader({ agentName }: { agentName: string }) {
53
- const { isExpanded, setIsExpanded } = ChatHeader.useChatHeaderContext();
54
-
55
- return (
56
- <div className="flex lg:hidden items-center gap-2 flex-1">
57
- <div className="flex items-center gap-2 flex-1">
58
- <h1 className="text-[20px] font-semibold leading-[1.2] tracking-[-0.4px] text-foreground">
59
- {agentName}
60
- </h1>
61
- <div className="flex items-center justify-center shrink-0">
62
- <ChevronUp className="size-4 rotate-180 text-muted-foreground" />
63
- </div>
64
- </div>
65
- <button
66
- type="button"
67
- className="flex items-center justify-center shrink-0 cursor-pointer"
68
- aria-label="Toggle menu"
69
- onClick={() => setIsExpanded(!isExpanded)}
70
- >
71
- <PanelRight className="size-4 text-muted-foreground" />
72
- </button>
73
- </div>
74
- );
75
- }
76
-
77
- // Header component that uses ChatLayout context (must be inside ChatLayout.Root)
78
- function AppChatHeader({
79
- agentName,
80
- todos,
81
- sources,
82
- showHeader,
83
- }: {
84
- agentName: string;
85
- todos: TodoItem[];
86
- sources: SourceItem[];
87
- showHeader: boolean;
88
- }) {
89
- const { panelSize, setPanelSize } = ChatLayout.useChatLayoutContext();
90
-
91
- return (
92
- <ChatHeader.Root
93
- className={cn(
94
- "border-b border-border bg-card relative lg:p-0",
95
- "[border-bottom-width:0.5px]",
96
- )}
97
- >
98
- {/* Desktop view: 64px height, padding 20px vertical, 24px left, 16px right */}
99
- <div className="hidden lg:flex items-center gap-2 w-full h-16 py-5 pl-6 pr-4">
100
- {showHeader && (
101
- <div className="flex items-center gap-2 flex-1">
102
- <h1 className="text-[20px] font-semibold leading-[1.2] tracking-[-0.4px] text-foreground">
103
- {agentName}
104
- </h1>
105
- <div className="flex items-center justify-center shrink-0">
106
- <ChevronUp className="size-4 rotate-180 text-muted-foreground" />
107
- </div>
108
- </div>
109
- )}
110
- {!showHeader && <div className="flex-1" />}
111
- <button
112
- type="button"
113
- className="flex items-center justify-center shrink-0 cursor-pointer"
114
- aria-label="Toggle sidebar"
115
- onClick={() => {
116
- setPanelSize(panelSize === "hidden" ? "small" : "hidden");
117
- }}
118
- >
119
- <PanelRight className="size-4 text-muted-foreground" />
120
- </button>
121
- </div>
122
-
123
- {/* Mobile view: always show full header with agent name */}
124
- <MobileHeader agentName={agentName} />
125
-
126
- {/* Expandable Panel for Mobile - always available */}
127
- <ChatHeader.ExpandablePanel
128
- className={cn(
129
- "pt-6 pb-8 px-6",
130
- "border-b border-border bg-card",
131
- "shadow-[0_4px_16px_0_rgba(0,0,0,0.04)]",
132
- "[border-bottom-width:0.5px]",
133
- )}
134
- >
135
- <Tabs defaultValue="todo" className="w-full">
136
- <PanelTabsHeader
137
- showIcons={true}
138
- visibleTabs={["todo", "files", "sources"]}
139
- variant="default"
140
- />
141
- <TabsContent value="todo" className="mt-4">
142
- <TodoTabContent todos={todos} />
143
- </TabsContent>
144
- <TabsContent value="files" className="mt-4">
145
- <FilesTabContent />
146
- </TabsContent>
147
- <TabsContent value="sources" className="mt-4">
148
- <SourcesTabContent sources={sources} />
149
- </TabsContent>
150
- </Tabs>
151
- </ChatHeader.ExpandablePanel>
152
- </ChatHeader.Root>
153
- );
154
- }
155
-
156
- export function ChatView({ client, initialSessionId }: ChatViewProps) {
157
- // Use shared hooks from @townco/ui/core
158
- const { connectionStatus, connect, sessionId } = useChatSession(
159
- client,
160
- initialSessionId,
161
- );
162
- const { messages } = useChatMessages(client);
163
- useToolCalls(client); // Still need to subscribe to tool call events
164
- const error = useChatStore((state) => state.error);
165
- const [agentName, setAgentName] = useState<string>("Agent");
166
- const [isLargeScreen, setIsLargeScreen] = useState(
167
- typeof window !== "undefined" ? window.innerWidth >= 1024 : true,
168
- );
169
-
170
- // Log connection status changes
171
- useEffect(() => {
172
- logger.debug("Connection status changed", { status: connectionStatus });
173
-
174
- if (connectionStatus === "error" && error) {
175
- logger.error("Connection error occurred", { error });
176
- }
177
- }, [connectionStatus, error]);
178
-
179
- // Get agent name from session metadata
180
- useEffect(() => {
181
- if (client && sessionId) {
182
- const session = client.getCurrentSession();
183
- if (session?.metadata?.agentName) {
184
- setAgentName(session.metadata.agentName);
185
- }
186
- }
187
- }, [client, sessionId]);
188
-
189
- // Monitor screen size changes and update isLargeScreen state
190
- useEffect(() => {
191
- const mediaQuery = window.matchMedia("(min-width: 1024px)");
192
-
193
- const handleChange = (e: MediaQueryListEvent) => {
194
- setIsLargeScreen(e.matches);
195
- };
196
-
197
- // Set initial value
198
- setIsLargeScreen(mediaQuery.matches);
199
-
200
- // Listen for changes
201
- mediaQuery.addEventListener("change", handleChange);
202
-
203
- return () => {
204
- mediaQuery.removeEventListener("change", handleChange);
205
- };
206
- }, []);
207
-
208
- // TODO: Replace with useChatStore((state) => state.todos) when todos are added to the store
209
- const todos: TodoItem[] = [];
210
-
211
- // Dummy sources data based on Figma design
212
- const sources: SourceItem[] = [
213
- {
214
- id: "1",
215
- title: "Boeing Scores Early Wins at Dubai Airshow",
216
- sourceName: "Reuters",
217
- url: "https://www.reuters.com/markets/companies/BA.N",
218
- snippet:
219
- "DUBAI, Nov 17 (Reuters) - Boeing (BA.N), opens new tab took centre stage at day one of the Dubai Airshow on Monday, booking a $38 billion order from host carrier Emirates and clinching more deals with African carriers, while China displayed its C919 in the Middle East for the first time.",
220
- favicon: "https://www.google.com/s2/favicons?domain=reuters.com&sz=32",
221
- },
222
- {
223
- id: "2",
224
- title: "Boeing's Sustainable Aviation Goals Take Flight",
225
- sourceName: "Forbes",
226
- url: "https://www.forbes.com",
227
- snippet:
228
- "SEATTLE, Nov 18 (Reuters) - Boeing is making headway towards its sustainability targets, unveiling plans for a new eco-friendly aircraft design aimed at reducing emissions by 50% by 2030.",
229
- favicon: "https://www.google.com/s2/favicons?domain=forbes.com&sz=32",
230
- },
231
- {
232
- id: "3",
233
- title: "Boeing Faces Increased Competition in Global Aviation Market",
234
- sourceName: "Reuters",
235
- url: "https://www.reuters.com",
236
- snippet:
237
- "CHICAGO, Nov 19 (Reuters) - As the global aviation industry rebounds post-pandemic, Boeing is grappling with intensified competition from rival manufacturers, particularly in the Asian market.",
238
- favicon: "https://www.google.com/s2/favicons?domain=reuters.com&sz=32",
239
- },
240
- {
241
- id: "4",
242
- title: "Boeing's Starliner Successfully Completes Orbital Test Flight",
243
- sourceName: "The Verge",
244
- url: "https://www.theverge.com",
245
- snippet:
246
- "NASA, Nov 20 (Reuters) - Boeing's CST-100 Starliner spacecraft achieves a significant milestone, successfully completing its orbital test flight, paving the way for future crewed missions to the International Space Station.",
247
- favicon: "https://www.google.com/s2/favicons?domain=theverge.com&sz=32",
248
- },
249
- ];
250
-
251
- // Command menu items for chat input
252
- const commandMenuItems: CommandMenuItem[] = [
253
- {
254
- id: "model-sonnet",
255
- label: "Use Sonnet 4.5",
256
- description: "Switch to Claude Sonnet 4.5 model",
257
- icon: <Sparkles className="h-4 w-4" />,
258
- category: "model",
259
- onSelect: () => {
260
- logger.info("User selected Sonnet 4.5 model");
261
- },
262
- },
263
- {
264
- id: "model-opus",
265
- label: "Use Opus",
266
- description: "Switch to Claude Opus model",
267
- icon: <Sparkles className="h-4 w-4" />,
268
- category: "model",
269
- onSelect: () => {
270
- logger.info("User selected Opus model");
271
- },
272
- },
273
- {
274
- id: "settings",
275
- label: "Open Settings",
276
- description: "Configure chat preferences",
277
- icon: <Settings className="h-4 w-4" />,
278
- category: "action",
279
- onSelect: () => {
280
- logger.info("User opened settings");
281
- },
282
- },
283
- {
284
- id: "code-mode",
285
- label: "Code Mode",
286
- description: "Enable code-focused responses",
287
- icon: <Code className="h-4 w-4" />,
288
- category: "mode",
289
- onSelect: () => {
290
- logger.info("User enabled code mode");
291
- },
292
- },
293
- ];
294
-
295
- return (
296
- <ChatLayout.Root defaultPanelSize="hidden" defaultActiveTab="todo">
297
- {/* Main: Vertical container for Messages + Footer */}
298
- <ChatLayout.Main>
299
- {/* Top Row */}
300
- <AppChatHeader
301
- agentName={agentName}
302
- todos={todos}
303
- sources={sources}
304
- showHeader={messages.length > 0}
305
- />
306
-
307
- {/* Connection Error Banner */}
308
- {connectionStatus === "error" && error && (
309
- <div className="border-b border-destructive/20 bg-destructive/10 px-6 py-4">
310
- <div className="flex items-start justify-between gap-4">
311
- <div className="flex-1">
312
- <h3 className="mb-1 text-sm font-semibold text-destructive">
313
- Connection Error
314
- </h3>
315
- <p className="whitespace-pre-line text-sm text-foreground">
316
- {error}
317
- </p>
318
- </div>
319
- <button
320
- type="button"
321
- onClick={connect}
322
- className="rounded-lg bg-destructive px-4 py-2 text-sm font-medium text-destructive-foreground transition-colors hover:bg-destructive-hover"
323
- >
324
- Retry
325
- </button>
326
- </div>
327
- </div>
328
- )}
329
-
330
- {/* Body: Container for Messages + Footer + Toaster */}
331
- <ChatLayout.Body>
332
- {/* Messages: Scrollable message area */}
333
- <ChatLayout.Messages className={messages.length > 0 ? "pt-4" : ""}>
334
- {messages.length === 0 ? (
335
- <div className="flex flex-1 items-center px-4">
336
- <ChatEmptyState
337
- title={agentName}
338
- description="This agent can help you with your tasks. Start a conversation by typing a message below."
339
- suggestedPrompts={[
340
- "Help me debug this code",
341
- "Explain how this works",
342
- "Create a new feature",
343
- "Review my changes",
344
- ]}
345
- onPromptClick={(prompt) => {
346
- // TODO: Implement prompt click handler
347
- logger.info("Prompt clicked", { prompt });
348
- }}
349
- />
350
- </div>
351
- ) : (
352
- <div className="flex flex-col gap-4 px-4">
353
- {messages.map((message, index) => (
354
- <Message
355
- key={message.id}
356
- message={message}
357
- isLastMessage={index === messages.length - 1}
358
- >
359
- <MessageContent
360
- message={message}
361
- thinkingDisplayStyle="collapsible"
362
- />
363
- </Message>
364
- ))}
365
- </div>
366
- )}
367
- </ChatLayout.Messages>
368
-
369
- {/* Footer: Input area */}
370
- <ChatLayout.Footer>
371
- <ChatInputRoot client={client}>
372
- <ChatInputCommandMenu commands={commandMenuItems} />
373
- <ChatInputField
374
- placeholder="Type a message or / for commands..."
375
- autoFocus
376
- />
377
- <ChatInputToolbar>
378
- <div className="flex items-center gap-1">
379
- <ChatInputActions />
380
- <ChatInputAttachment />
381
- </div>
382
- <div className="flex items-center gap-1">
383
- <ChatInputVoiceInput />
384
- <ChatInputSubmit>
385
- <ArrowUp className="size-4" />
386
- </ChatInputSubmit>
387
- </div>
388
- </ChatInputToolbar>
389
- </ChatInputRoot>
390
- </ChatLayout.Footer>
391
- </ChatLayout.Body>
392
- </ChatLayout.Main>
393
-
394
- {/* Aside: Right side panel - only render on large screens */}
395
- {isLargeScreen && (
396
- <ChatLayout.Aside breakpoint="lg">
397
- <Tabs defaultValue="todo" className="flex flex-col h-full">
398
- {/* Desktop sidebar header (64px) */}
399
- <div
400
- className={cn(
401
- "border-b border-border bg-card",
402
- "px-6 py-2 h-16",
403
- "flex items-center",
404
- "[border-bottom-width:0.5px]",
405
- )}
406
- >
407
- <PanelTabsHeader
408
- showIcons={true}
409
- visibleTabs={["todo", "files", "sources"]}
410
- variant="compact"
411
- />
412
- </div>
413
-
414
- {/* Desktop sidebar content */}
415
- <TabsContent value="todo" className="flex-1 p-4 mt-0">
416
- <TodoTabContent todos={todos} />
417
- </TabsContent>
418
- <TabsContent value="files" className="flex-1 p-4 mt-0">
419
- <FilesTabContent />
420
- </TabsContent>
421
- <TabsContent value="sources" className="flex-1 p-4 mt-0">
422
- <SourcesTabContent sources={sources} />
423
- </TabsContent>
424
- </Tabs>
425
- </ChatLayout.Aside>
426
- )}
427
- </ChatLayout.Root>
428
- );
429
- }