xonecas.io
53129
Pa

PAT / commit 05b7cd7

feat: throw away vibe coded frontend, make new one

xonecas2025-12-21 05b7cd786cc9c17420f1db90dd56ee68158b0e7c parent a5e3b30

79 files changed

This diff is too big to show in full. The first 1000 lines are below, and every file is listed with its counts.

AGENTS.md+1−1
@@ -28,7 +28,7 @@
2828
2929 ### Code Organization
3030
31-- Use path aliases: `@/` for root imports (e.g., `@/src/components/...`).
31+- Always use absolute paths in import using path aliases: `@/` for root imports (e.g., `@/src/components/...`).
3232 - Follow modular structure: `src/components/`, `src/hooks/`, `src/lib/`, `app/api/`.
3333 - Keep files focused - one main export per file when possible.
3434
app/api/chat/route.ts+0−100
@@ -1,100 +0,0 @@
1-import { NextResponse } from "next/server";
2-import type { MaxPromptLength } from "@/src/lib/ollama/types";
3-import type { Message } from "ollama";
4-import { db } from "@/src/lib/db";
5-import { messages, threads } from "@/src/lib/db/schema";
6-import { eq, asc } from "drizzle-orm";
7-import { streamAssistantResponse } from "@/src/lib/ollama/chat";
8-import { debug } from "@/src/lib/debug";
9-
10-/**
11- * Type guard to validate MaxPromptLength values.
12- */
13-function isValidMaxPromptLength(value: unknown): value is MaxPromptLength {
14- return value === null || value === "none" || value === 1024 || value === 4096;
15-}
16-
17-export async function POST(request: Request) {
18- const { message, threadId: threadIdRaw } = await request.json();
19- const signal = request.signal;
20-
21- if (typeof message !== "string" || !message.trim()) {
22- return NextResponse.json({ error: "message is required" }, { status: 400 });
23- }
24-
25- if (!threadIdRaw) {
26- return NextResponse.json({ error: "threadId is required" }, { status: 400 });
27- }
28-
29- const threadId: number = Number(threadIdRaw);
30- if (isNaN(threadId)) {
31- return NextResponse.json({ error: "Invalid threadId" }, { status: 400 });
32- }
33-
34- try {
35- // 1. Fetch thread to get its model and maxPromptLength settings
36- // These thread-specific settings override any global settings
37- const thread = await db.select().from(threads).where(eq(threads.id, threadId)).limit(1);
38- if (thread.length === 0) {
39- return NextResponse.json({ error: "Thread not found" }, { status: 404 });
40- }
41- // Use thread-specific settings (stored in thread table)
42- const threadModel = thread[0].model;
43- // Note: null from database means "none" (no limit), which OllamaChat handles correctly
44- // Validate maxPromptLength before use to prevent runtime errors from invalid database values
45- const rawMaxPromptLength = thread[0].maxPromptLength;
46- const threadMaxPromptLength: MaxPromptLength = isValidMaxPromptLength(rawMaxPromptLength)
47- ? rawMaxPromptLength
48- : null;
49-
50- // 2. Fetch previous messages from thread
51- const previousMessages = await db
52- .select()
53- .from(messages)
54- .where(eq(messages.threadId, threadId))
55- .orderBy(asc(messages.createdAt));
56-
57- // 3. Store user message
58- await db.insert(messages).values({
59- threadId: threadId,
60- role: "user",
61- content: message,
62- createdAt: new Date(),
63- });
64-
65- // 4. Build messages array for Ollama
66- const ollamaMessages: Message[] = previousMessages.map((msg) => ({
67- role: msg.role as Message["role"],
68- content: msg.content,
69- }));
70-
71- // Add the new user message
72- ollamaMessages.push({
73- role: "user",
74- content: message,
75- });
76-
77- // 5. Stream assistant response
78- const stream = streamAssistantResponse({
79- ollamaMessages,
80- threadId,
81- threadModel,
82- threadMaxPromptLength,
83- signal,
84- });
85-
86- return new Response(stream, {
87- headers: {
88- "Content-Type": "text/event-stream",
89- "Cache-Control": "no-cache",
90- Connection: "keep-alive",
91- },
92- });
93- } catch (err) {
94- debug(
95- `[Chat API] Error processing message:`,
96- err instanceof Error ? err.message : "Unknown error"
97- );
98- return NextResponse.json({ answer: "Sorry, something went wrong." }, { status: 500 });
99- }
100-}
app/api/threads/[id]/messages/route.ts+33−0
@@ -3,6 +3,8 @@ import { db } from "@/src/lib/db";
33 import { messages } from "@/src/lib/db/schema";
44 import { eq, asc, and, inArray } from "drizzle-orm";
55 import { debug } from "@/src/lib/debug";
6+import { createMessage } from "@/src/lib/messages";
7+import { generateResponse } from "@/src/lib/chat";
68
79 export async function GET(request: Request, { params }: { params: Promise<{ id: string }> }) {
810 let threadId: number | null = null;
@@ -42,3 +44,34 @@ export async function GET(request: Request, { params }: { params: Promise<{ id:
4244 return NextResponse.json({ error: "Failed to get messages" }, { status: 500 });
4345 }
4446 }
47+
48+export async function POST(request: Request, { params }: { params: Promise<{ id: string }> }) {
49+ let threadId: number | null = null;
50+ try {
51+ const { id } = await params;
52+ threadId = parseInt(id);
53+ if (isNaN(threadId)) {
54+ return NextResponse.json({ error: "Invalid thread ID" }, { status: 400 });
55+ }
56+
57+ const body = await request.json();
58+ const { message } = body;
59+
60+ if (typeof message !== "string" || !message.trim()) {
61+ return NextResponse.json({ error: "message is required" }, { status: 400 });
62+ }
63+
64+ await createMessage(message, "user", threadId);
65+
66+ // Generate a response from the model.
67+ await generateResponse(threadId);
68+
69+ return NextResponse.json({ message: message });
70+ } catch (err) {
71+ debug(
72+ `[Messages API] Error creating message for thread ${threadId ?? "unknown"}:`,
73+ err instanceof Error ? err.message : "Unknown error"
74+ );
75+ return NextResponse.json({ error: "Failed to create message" }, { status: 500 });
76+ }
77+}
app/api/threads/[id]/route.ts+0−62
@@ -4,68 +4,6 @@ import { threads } from "@/src/lib/db/schema";
44 import { eq } from "drizzle-orm";
55 import { debug } from "@/src/lib/debug";
66
7-export async function PATCH(request: Request, { params }: { params: Promise<{ id: string }> }) {
8- let threadId: number | null = null;
9- try {
10- const { id } = await params;
11- threadId = parseInt(id);
12- if (isNaN(threadId)) {
13- return NextResponse.json({ error: "Invalid thread ID" }, { status: 400 });
14- }
15-
16- const body = await request.json();
17- const { model, maxPromptLength, title, userPrompt } = body;
18-
19- // Reject userPrompt updates - it can only be set at thread creation
20- if (userPrompt !== undefined) {
21- return NextResponse.json(
22- { error: "User prompt can only be set when creating a new thread" },
23- { status: 400 }
24- );
25- }
26-
27- const updateData: {
28- model?: string;
29- maxPromptLength?: number | null;
30- title?: string;
31- updatedAt?: Date;
32- } = {
33- updatedAt: new Date(),
34- };
35-
36- if (model !== undefined) {
37- updateData.model = model;
38- }
39-
40- if (maxPromptLength !== undefined) {
41- updateData.maxPromptLength =
42- maxPromptLength === "none" || maxPromptLength === null ? null : maxPromptLength;
43- }
44-
45- if (title !== undefined) {
46- updateData.title = title;
47- }
48-
49- const updatedThread = await db
50- .update(threads)
51- .set(updateData)
52- .where(eq(threads.id, threadId))
53- .returning();
54-
55- if (updatedThread.length === 0) {
56- return NextResponse.json({ error: "Thread not found" }, { status: 404 });
57- }
58-
59- return NextResponse.json({ thread: updatedThread[0] });
60- } catch (err) {
61- debug(
62- `[Threads API] Error updating thread ${threadId ?? "unknown"}:`,
63- err instanceof Error ? err.message : "Unknown error"
64- );
65- return NextResponse.json({ error: "Failed to update thread" }, { status: 500 });
66- }
67-}
68-
697 export async function DELETE(request: Request, { params }: { params: Promise<{ id: string }> }) {
708 let threadId: number | null = null;
719 try {
app/api/threads/route.ts+14−45
@@ -1,59 +1,28 @@
11 import { NextResponse } from "next/server";
22 import { db } from "@/src/lib/db";
3-import { threads, messages } from "@/src/lib/db/schema";
3+import { threads } from "@/src/lib/db/schema";
44 import { desc, count } from "drizzle-orm";
5-import { generateSystemPrompt } from "@/src/lib/ollama/chat/system-prompt";
65 import { debug } from "@/src/lib/debug";
6+import { createThread } from "@/src/lib/threads";
77
88 export async function POST(request: Request) {
99 try {
10- const { title, model, maxPromptLength, userPrompt, time, timezone } = await request.json();
10+ const { userMessage, model, maxPromptLength, userPrompt, time, timezone } =
11+ await request.json();
1112
12- // Validate required parameters
13- if (!model || typeof model !== "string") {
14- return NextResponse.json({ error: "model is required" }, { status: 400 });
13+ if (!model || !userMessage) {
14+ return NextResponse.json({ error: "Model and user message are required" }, { status: 400 });
1515 }
16- if (maxPromptLength === undefined) {
17- return NextResponse.json({ error: "maxPromptLength is required" }, { status: 400 });
18- }
19-
20- const newThread = await db
21- .insert(threads)
22- .values({
23- title: title,
24- model: model,
25- maxPromptLength:
26- maxPromptLength === "none" || maxPromptLength === null ? null : maxPromptLength,
27- userPrompt: userPrompt || null,
28- createdAt: new Date(),
29- updatedAt: new Date(),
30- })
31- .returning();
32-
33- const threadId = newThread[0].id;
3416
35- // Generate system prompt
36- const systemPrompt = generateSystemPrompt({
17+ const thread = await createThread(
18+ userMessage,
19+ model,
20+ maxPromptLength,
21+ userPrompt,
3722 time,
38- timezone,
39- userPrompt: userPrompt || null,
40- });
41-
42- // Insert system message with guidelines
43- const systemMessage = await db
44- .insert(messages)
45- .values({
46- threadId,
47- role: "system",
48- content: systemPrompt,
49- createdAt: new Date(),
50- })
51- .returning({ id: messages.id, content: messages.content, createdAt: messages.createdAt });
52-
53- return NextResponse.json({
54- thread: newThread[0],
55- systemMessage: systemMessage[0],
56- });
23+ timezone
24+ );
25+ return NextResponse.json({ thread });
5726 } catch (err) {
5827 debug(
5928 `[Threads API] Error creating thread:`,
app/highlight-theme.css+2−88
@@ -1,44 +1,21 @@
11 /* Custom highlight.js theme using grayscale colors */
22
3-/* Reset code block inheritance */
4-.prose pre,
5-.prose pre code {
6- color: inherit;
7-}
8-
9-/* Inline code - no background */
10-.prose code:not(pre code) {
11- color: inherit;
12- background: transparent;
13-}
14-
153 /* Light mode - code blocks only */
16-.prose pre {
4+pre:has(.hljs) {
175 background: #e7e5e4; /* neutral-200 */
186 padding: 0.5rem;
197 }
208
21-.prose .hljs,
22-.prose pre code.hljs,
23-.prose pre .hljs,
24-pre code.hljs,
25-pre .hljs,
269 .hljs {
27- background: transparent;
2810 color: #292524; /* neutral-800 */
2911 }
3012
31-.prose .hljs-comment,
32-.prose .hljs-quote,
3313 .hljs-comment,
3414 .hljs-quote {
3515 color: #78716c; /* neutral-500 */
3616 font-style: italic;
3717 }
3818
39-.prose .hljs-keyword,
40-.prose .hljs-selector-tag,
41-.prose .hljs-subst,
4219 .hljs-keyword,
4320 .hljs-selector-tag,
4421 .hljs-subst {
@@ -46,11 +23,6 @@ pre .hljs,
4623 font-weight: 600;
4724 }
4825
49-.prose .hljs-number,
50-.prose .hljs-literal,
51-.prose .hljs-variable,
52-.prose .hljs-template-variable,
53-.prose .hljs-tag .hljs-attr,
5426 .hljs-number,
5527 .hljs-literal,
5628 .hljs-variable,
@@ -59,16 +31,11 @@ pre .hljs,
5931 color: #57534e; /* neutral-600 */
6032 }
6133
62-.prose .hljs-string,
63-.prose .hljs-doctag,
6434 .hljs-string,
6535 .hljs-doctag {
6636 color: #44403c; /* neutral-700 */
6737 }
6838
69-.prose .hljs-title,
70-.prose .hljs-section,
71-.prose .hljs-selector-id,
7239 .hljs-title,
7340 .hljs-section,
7441 .hljs-selector-id {
@@ -76,17 +43,12 @@ pre .hljs,
7643 font-weight: 600;
7744 }
7845
79-.prose .hljs-type,
80-.prose .hljs-class .hljs-title,
8146 .hljs-type,
8247 .hljs-class .hljs-title {
8348 color: #292524; /* neutral-800 */
8449 font-weight: 500;
8550 }
8651
87-.prose .hljs-tag,
88-.prose .hljs-name,
89-.prose .hljs-attribute,
9052 .hljs-tag,
9153 .hljs-name,
9254 .hljs-attribute {
@@ -94,29 +56,22 @@ pre .hljs,
9456 font-weight: normal;
9557 }
9658
97-.prose .hljs-regexp,
98-.prose .hljs-link,
9959 .hljs-regexp,
10060 .hljs-link {
10161 color: #44403c; /* neutral-700 */
10262 }
10363
104-.prose .hljs-symbol,
105-.prose .hljs-bullet,
10664 .hljs-symbol,
10765 .hljs-bullet {
10866 color: #57534e; /* neutral-600 */
10967 }
11068
111-.prose .hljs-built_in,
112-.prose .hljs-builtin-name,
11369 .hljs-built_in,
11470 .hljs-builtin-name {
11571 color: #292524; /* neutral-800 */
11672 font-weight: 500;
11773 }
11874
119-.prose .hljs-meta,
12075 .hljs-meta {
12176 color: #78716c; /* neutral-500 */
12277 }
@@ -138,43 +93,24 @@ pre .hljs,
13893 }
13994
14095 /* Dark mode */
141-.dark .prose pre,
142-.dark .prose pre code {
143- color: inherit;
144-}
14596
14697 /* Inline code - no background */
147-.dark .prose code:not(pre code) {
148- color: inherit;
149- background: transparent;
150-}
15198
152-.dark .prose pre {
99+.dark pre:has(.hljs) {
153100 background: #0c0a09; /* neutral-950 */
154101 padding: 0.5rem;
155102 }
156103
157-.dark .prose .hljs,
158-.dark .prose pre code.hljs,
159-.dark .prose pre .hljs,
160-.dark pre code.hljs,
161-.dark pre .hljs,
162104 .dark .hljs {
163- background: transparent;
164105 color: #e7e5e4; /* neutral-200 */
165106 }
166107
167-.dark .prose .hljs-comment,
168-.dark .prose .hljs-quote,
169108 .dark .hljs-comment,
170109 .dark .hljs-quote {
171110 color: #a8a29e; /* neutral-400 */
172111 font-style: italic;
173112 }
174113
175-.dark .prose .hljs-keyword,
176-.dark .prose .hljs-selector-tag,
177-.dark .prose .hljs-subst,
178114 .dark .hljs-keyword,
179115 .dark .hljs-selector-tag,
180116 .dark .hljs-subst {
@@ -182,11 +118,6 @@ pre .hljs,
182118 font-weight: 600;
183119 }
184120
185-.dark .prose .hljs-number,
186-.dark .prose .hljs-literal,
187-.dark .prose .hljs-variable,
188-.dark .prose .hljs-template-variable,
189-.dark .prose .hljs-tag .hljs-attr,
190121 .dark .hljs-number,
191122 .dark .hljs-literal,
192123 .dark .hljs-variable,
@@ -195,16 +126,11 @@ pre .hljs,
195126 color: #d4d4d4; /* neutral-300 */
196127 }
197128
198-.dark .prose .hljs-string,
199-.dark .prose .hljs-doctag,
200129 .dark .hljs-string,
201130 .dark .hljs-doctag {
202131 color: #d6d3d1; /* neutral-300 */
203132 }
204133
205-.dark .prose .hljs-title,
206-.dark .prose .hljs-section,
207-.dark .prose .hljs-selector-id,
208134 .dark .hljs-title,
209135 .dark .hljs-section,
210136 .dark .hljs-selector-id {
@@ -212,17 +138,12 @@ pre .hljs,
212138 font-weight: 600;
213139 }
214140
215-.dark .prose .hljs-type,
216-.dark .prose .hljs-class .hljs-title,
217141 .dark .hljs-type,
218142 .dark .hljs-class .hljs-title {
219143 color: #e7e5e4; /* neutral-200 */
220144 font-weight: 500;
221145 }
222146
223-.dark .prose .hljs-tag,
224-.dark .prose .hljs-name,
225-.dark .prose .hljs-attribute,
226147 .dark .hljs-tag,
227148 .dark .hljs-name,
228149 .dark .hljs-attribute {
@@ -230,29 +151,22 @@ pre .hljs,
230151 font-weight: normal;
231152 }
232153
233-.dark .prose .hljs-regexp,
234-.dark .prose .hljs-link,
235154 .dark .hljs-regexp,
236155 .dark .hljs-link {
237156 color: #d6d3d1; /* neutral-300 */
238157 }
239158
240-.dark .prose .hljs-symbol,
241-.dark .prose .hljs-bullet,
242159 .dark .hljs-symbol,
243160 .dark .hljs-bullet {
244161 color: #d4d4d4; /* neutral-300 */
245162 }
246163
247-.dark .prose .hljs-built_in,
248-.dark .prose .hljs-builtin-name,
249164 .dark .hljs-built_in,
250165 .dark .hljs-builtin-name {
251166 color: #e7e5e4; /* neutral-200 */
252167 font-weight: 500;
253168 }
254169
255-.dark .prose .hljs-meta,
256170 .dark .hljs-meta {
257171 color: #a8a29e; /* neutral-400 */
258172 }
app/layout.tsx+1−0
@@ -1,5 +1,6 @@
11 import { Montserrat } from "next/font/google";
22 import "./globals.css";
3+import "./highlight-theme.css";
34
45 const montserrat = Montserrat({
56 weight: ["400", "700"],
app/page.tsx+6−210
@@ -1,216 +1,12 @@
11 "use client";
2-import { useRef, useMemo, useCallback, useEffect } from "react";
3-import Sidebar from "@/src/components/Sidebar";
4-import MessageInput, { type MessageInputRef } from "@/src/components/MessageInput";
5-import MessageList from "@/src/components/MessageList";
6-import NoThreadSelected from "@/src/components/NoThreadSelected";
7-import { useTheme } from "@/src/hooks/useTheme";
8-import { useThreads } from "@/src/hooks/useThreads";
9-import { useMessages } from "@/src/hooks/useMessages";
10-import { useThreadSelection } from "@/src/hooks/useThreadSelection";
11-import { useLocalStorage } from "@/src/hooks/useLocalStorage";
12-import { useModelValidation } from "@/src/hooks/useModelValidation";
13-import { useErrorWithAutoDismiss } from "@/src/hooks/useErrorWithAutoDismiss";
14-import { getErrorMessage } from "@/src/lib/errors";
15-import "./highlight-theme.css";
162
17-export default function Home() {
18- const [error, setError] = useErrorWithAutoDismiss();
19- const { themeMode, handleThemeChange } = useTheme();
20- const [selectedModel, setSelectedModel] = useLocalStorage<string>("selectedModel", "gpt-oss");
21- const [maxPromptLength, setMaxPromptLength] = useLocalStorage<"none" | 1024 | 4096>(
22- "maxPromptLength",
23- "none"
24- );
25- const [newThreadUserPrompt, setNewThreadUserPrompt] = useLocalStorage<string>(
26- "newThreadUserPrompt",
27- ""
28- );
29-
30- useModelValidation(selectedModel, setSelectedModel);
31-
32- const { currentThreadId, selectThread, deselectThread, messagesContainerRef } =
33- useThreadSelection();
34-
35- const clearMessagesRef = useRef<(() => void) | undefined>(undefined);
36-
37- const {
38- threads,
39- totalThreadCount,
40- hasMoreThreads,
41- loadThreads,
42- loadMoreThreads,
43- createThread,
44- updateThread,
45- handleThreadSelect,
46- handleThreadUpdate,
47- handleThreadDelete,
48- } = useThreads({
49- selectThread,
50- deselectThread,
51- clearMessagesRef,
52- currentThreadId,
53- setError,
54- });
55-
56- const {
57- messages,
58- isLoading,
59- isLoadingMessages,
60- streamingMessageId,
61- sendMessage,
62- clearMessages,
63- stopGeneration,
64- deleteMessage: deleteMessageInternal,
65- } = useMessages(currentThreadId, setError, async (threadId: number, title: string) => {
66- await updateThread(threadId, { title }, setError);
67- await loadThreads(8, setError);
68- });
69-
70- useEffect(() => {
71- clearMessagesRef.current = clearMessages;
72- }, [clearMessages]);
73- const messageInputRef = useRef<MessageInputRef>(null);
74-
75- const handleModelChange = useCallback(
76- (model: string) => {
77- setSelectedModel(model);
78- },
79- [setSelectedModel]
80- );
81-
82- const handleMaxPromptLengthChange = useCallback(
83- (value: "none" | 1024 | 4096) => {
84- setMaxPromptLength(value);
85- },
86- [setMaxPromptLength]
87- );
88-
89- const handleNewThreadUserPromptChange = useCallback(
90- (userPrompt: string) => {
91- setNewThreadUserPrompt(userPrompt);
92- },
93- [setNewThreadUserPrompt]
94- );
95-
96- const handleDeleteMessage = useCallback(
97- (messageId: number, threadId: number) => {
98- deleteMessageInternal(messageId, threadId, setError);
99- },
100- [deleteMessageInternal, setError]
101- );
102-
103- const handleCreateNewThread = useCallback(() => {
104- deselectThread();
105- clearMessages();
106- setError(null);
107- setTimeout(() => {
108- messageInputRef.current?.focus();
109- }, 0);
110- }, [deselectThread, clearMessages, setError]);
111-
112- const handleSendMessage = useCallback(
113- async (message: string) => {
114- setError(null);
115- try {
116- await sendMessage(
117- message,
118- currentThreadId,
119- (title, firstMessage) =>
120- createThread(
121- selectedModel,
122- maxPromptLength,
123- title,
124- firstMessage,
125- newThreadUserPrompt,
126- setError
127- ),
128- selectThread,
129- () => loadThreads(8, setError),
130- setError
131- );
132- } catch (error) {
133- setError(getErrorMessage(error));
134- }
135- },
136- [
137- sendMessage,
138- currentThreadId,
139- createThread,
140- selectedModel,
141- maxPromptLength,
142- newThreadUserPrompt,
143- selectThread,
144- loadThreads,
145- setError,
146- ]
147- );
148-
149- const currentThread = useMemo(
150- () => (currentThreadId !== null ? threads.find((t) => t.id === currentThreadId) || null : null),
151- [currentThreadId, threads]
152- );
153-
154- const handleLoadMore = useCallback(() => {
155- void loadMoreThreads(8, setError);
156- }, [loadMoreThreads, setError]);
3+import App from "@/src/components/App";
4+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
1575
6+export default function Home() {
1587 return (
159- <div className="flex h-screen bg-neutral-100 text-neutral-800 dark:bg-neutral-950 dark:text-neutral-200">
160- <div className="relative flex min-w-0 flex-1 flex-col">
161- <div
162- ref={messagesContainerRef}
163- className={`flex-1 overflow-y-auto overflow-x-hidden bg-neutral-100 p-4 text-neutral-900 dark:bg-neutral-900 dark:text-neutral-100 ${
164- isLoading && streamingMessageId !== null ? "pb-52" : "pb-48"
165- }`}
166- >
167- <div
168- className={`mx-auto flex min-h-full max-w-5xl flex-col gap-8 ${currentThreadId === null ? "justify-center" : "justify-end"}`}
169- >
170- {currentThreadId === null ? (
171- <NoThreadSelected />
172- ) : (
173- <MessageList
174- messages={messages}
175- threadId={currentThreadId}
176- onDeleteMessage={handleDeleteMessage}
177- />
178- )}
179- </div>
180- </div>
181- <MessageInput
182- ref={messageInputRef}
183- isLoading={isLoading}
184- isLoadingMessages={isLoadingMessages}
185- messages={messages}
186- onSubmit={handleSendMessage}
187- isStreaming={isLoading && streamingMessageId !== null}
188- onStop={stopGeneration}
189- error={error}
190- currentThreadId={currentThreadId}
191- currentThread={currentThread}
192- onThreadUpdate={handleThreadUpdate}
193- onThreadDelete={handleThreadDelete}
194- onError={setError}
195- newThreadModel={selectedModel}
196- newThreadMaxPromptLength={maxPromptLength}
197- newThreadUserPrompt={newThreadUserPrompt}
198- onNewThreadModelChange={handleModelChange}
199- onNewThreadMaxPromptLengthChange={handleMaxPromptLengthChange}
200- onNewThreadUserPromptChange={handleNewThreadUserPromptChange}
201- />
202- </div>
203- <Sidebar
204- threads={threads}
205- currentThreadId={currentThreadId}
206- themeMode={themeMode}
207- onCreateNewThread={handleCreateNewThread}
208- onThreadSelect={handleThreadSelect}
209- onThemeChange={handleThemeChange}
210- onLoadMore={handleLoadMore}
211- hasMoreThreads={hasMoreThreads}
212- totalThreadCount={totalThreadCount}
213- />
214- </div>
8+ <QueryClientProvider client={new QueryClient()}>
9+ <App />
10+ </QueryClientProvider>
21511 );
21612 }
package-lock.json+45−530
@@ -10,6 +10,7 @@
1010 "dependencies": {
1111 "@googleapis/customsearch": "^7.0.1",
1212 "@tailwindcss/typography": "^0.5.19",
13+ "@tanstack/react-query": "^5.90.12",
1314 "autoprefixer": "^10.4.17",
1415 "drizzle-kit": "^0.31.8",
1516 "drizzle-orm": "^0.45.1",
@@ -29,6 +30,7 @@
2930 "typescript": "^5.4.2"
3031 },
3132 "devDependencies": {
33+ "@tanstack/eslint-plugin-query": "^5.91.2",
3234 "@types/node": "^20.19.27",
3335 "@types/react": "^18.2.55",
3436 "@types/react-dom": "^18.2.19",
@@ -37,7 +39,6 @@
3739 "eslint-config-next": "^16.0.10",
3840 "eslint-config-prettier": "^10.1.8",
3941 "husky": "^9.1.7",
40- "lint-staged": "^16.2.7",
4142 "prettier": "^3.2.5",
4243 "prettier-plugin-tailwindcss": "^0.5.11",
4344 "vitest": "^4.0.16"
@@ -2569,6 +2570,49 @@
25692570 "node": ">=4"
25702571 }
25712572 },
2573+ "node_modules/@tanstack/eslint-plugin-query": {
2574+ "version": "5.91.2",
2575+ "resolved": "https://registry.npmjs.org/@tanstack/eslint-plugin-query/-/eslint-plugin-query-5.91.2.tgz",
2576+ "integrity": "sha512-UPeWKl/Acu1IuuHJlsN+eITUHqAaa9/04geHHPedY8siVarSaWprY0SVMKrkpKfk5ehRT7+/MZ5QwWuEtkWrFw==",
2577+ "dev": true,
2578+ "license": "MIT",
2579+ "dependencies": {
2580+ "@typescript-eslint/utils": "^8.44.1"
2581+ },
2582+ "funding": {
2583+ "type": "github",
2584+ "url": "https://github.com/sponsors/tannerlinsley"
2585+ },
2586+ "peerDependencies": {
2587+ "eslint": "^8.57.0 || ^9.0.0"
2588+ }
2589+ },
2590+ "node_modules/@tanstack/query-core": {
2591+ "version": "5.90.12",
2592+ "resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-5.90.12.tgz",
2593+ "integrity": "sha512-T1/8t5DhV/SisWjDnaiU2drl6ySvsHj1bHBCWNXd+/T+Hh1cf6JodyEYMd5sgwm+b/mETT4EV3H+zCVczCU5hg==",
2594+ "license": "MIT",
2595+ "funding": {
2596+ "type": "github",
2597+ "url": "https://github.com/sponsors/tannerlinsley"
2598+ }
2599+ },
2600+ "node_modules/@tanstack/react-query": {
2601+ "version": "5.90.12",
2602+ "resolved": "https://registry.npmjs.org/@tanstack/react-query/-/react-query-5.90.12.tgz",
2603+ "integrity": "sha512-graRZspg7EoEaw0a8faiUASCyJrqjKPdqJ9EwuDRUF9mEYJ1YPczI9H+/agJ0mOJkPCJDk0lsz5QTrLZ/jQ2rg==",
2604+ "license": "MIT",
2605+ "dependencies": {
2606+ "@tanstack/query-core": "5.90.12"
2607+ },
2608+ "funding": {
2609+ "type": "github",
2610+ "url": "https://github.com/sponsors/tannerlinsley"
2611+ },
2612+ "peerDependencies": {
2613+ "react": "^18 || ^19"
2614+ }
2615+ },
25722616 "node_modules/@tybys/wasm-util": {
25732617 "version": "0.10.1",
25742618 "resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.1.tgz",
@@ -3428,22 +3472,6 @@
34283472 "url": "https://github.com/sponsors/epoberezkin"
34293473 }
34303474 },
3431- "node_modules/ansi-escapes": {
3432- "version": "7.2.0",
3433- "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-7.2.0.tgz",
3434- "integrity": "sha512-g6LhBsl+GBPRWGWsBtutpzBYuIIdBkLEvad5C/va/74Db018+5TZiyA26cZJAr3Rft5lprVqOIPxf5Vid6tqAw==",
3435- "dev": true,
3436- "license": "MIT",
3437- "dependencies": {
3438- "environment": "^1.0.0"
3439- },
3440- "engines": {
3441- "node": ">=18"
3442- },
3443- "funding": {
3444- "url": "https://github.com/sponsors/sindresorhus"
3445- }
3446- },
34473475 "node_modules/ansi-regex": {
34483476 "version": "5.0.1",
34493477 "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
@@ -4103,85 +4131,6 @@
41034131 "node": ">= 6"
41044132 }
41054133 },
4106- "node_modules/cli-cursor": {
4107- "version": "5.0.0",
4108- "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-5.0.0.tgz",
4109- "integrity": "sha512-aCj4O5wKyszjMmDT4tZj93kxyydN/K5zPWSCe6/0AV/AA1pqe5ZBIw0a2ZfPQV7lL5/yb5HsUreJ6UFAF1tEQw==",
4110- "dev": true,
4111- "license": "MIT",
4112- "dependencies": {
4113- "restore-cursor": "^5.0.0"
4114- },
4115- "engines": {
4116- "node": ">=18"
4117- },
4118- "funding": {
4119- "url": "https://github.com/sponsors/sindresorhus"
4120- }
4121- },
4122- "node_modules/cli-truncate": {
4123- "version": "5.1.1",
4124- "resolved": "https://registry.npmjs.org/cli-truncate/-/cli-truncate-5.1.1.tgz",
4125- "integrity": "sha512-SroPvNHxUnk+vIW/dOSfNqdy1sPEFkrTk6TUtqLCnBlo3N7TNYYkzzN7uSD6+jVjrdO4+p8nH7JzH6cIvUem6A==",
4126- "dev": true,
4127- "license": "MIT",
4128- "dependencies": {
4129- "slice-ansi": "^7.1.0",
4130- "string-width": "^8.0.0"
4131- },
4132- "engines": {
4133- "node": ">=20"
4134- },
4135- "funding": {
4136- "url": "https://github.com/sponsors/sindresorhus"
4137- }
4138- },
4139- "node_modules/cli-truncate/node_modules/ansi-regex": {
4140- "version": "6.2.2",
4141- "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.2.2.tgz",
4142- "integrity": "sha512-Bq3SmSpyFHaWjPk8If9yc6svM8c56dB5BAtW4Qbw5jHTwwXXcTLoRMkpDJp6VL0XzlWaCHTXrkFURMYmD0sLqg==",
4143- "dev": true,
4144- "license": "MIT",
4145- "engines": {
4146- "node": ">=12"
4147- },
4148- "funding": {
4149- "url": "https://github.com/chalk/ansi-regex?sponsor=1"
4150- }
4151- },
4152- "node_modules/cli-truncate/node_modules/string-width": {
4153- "version": "8.1.0",
4154- "resolved": "https://registry.npmjs.org/string-width/-/string-width-8.1.0.tgz",
4155- "integrity": "sha512-Kxl3KJGb/gxkaUMOjRsQ8IrXiGW75O4E3RPjFIINOVH8AMl2SQ/yWdTzWwF3FevIX9LcMAjJW+GRwAlAbTSXdg==",
4156- "dev": true,
4157- "license": "MIT",
4158- "dependencies": {
4159- "get-east-asian-width": "^1.3.0",
4160- "strip-ansi": "^7.1.0"
4161- },
4162- "engines": {
4163- "node": ">=20"
4164- },
4165- "funding": {
4166- "url": "https://github.com/sponsors/sindresorhus"
4167- }
4168- },
4169- "node_modules/cli-truncate/node_modules/strip-ansi": {
4170- "version": "7.1.2",
4171- "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.2.tgz",
4172- "integrity": "sha512-gmBGslpoQJtgnMAvOVqGZpEz9dyoKTCzy2nfz/n8aIFhN/jCE/rCmcxabB6jOOHV+0WNnylOxaxBQPSvcWklhA==",
4173- "dev": true,
4174- "license": "MIT",
4175- "dependencies": {
4176- "ansi-regex": "^6.0.1"
4177- },
4178- "engines": {
4179- "node": ">=12"
4180- },
4181- "funding": {
4182- "url": "https://github.com/chalk/strip-ansi?sponsor=1"
4183- }
4184- },
41854134 "node_modules/client-only": {
41864135 "version": "0.0.1",
41874136 "resolved": "https://registry.npmjs.org/client-only/-/client-only-0.0.1.tgz",
@@ -4215,13 +4164,6 @@
42154164 "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
42164165 "license": "MIT"
42174166 },
4218- "node_modules/colorette": {
4219- "version": "2.0.20",
4220- "resolved": "https://registry.npmjs.org/colorette/-/colorette-2.0.20.tgz",
4221- "integrity": "sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w==",
4222- "dev": true,
4223- "license": "MIT"
4224- },
42254167 "node_modules/comma-separated-tokens": {
42264168 "version": "2.0.3",
42274169 "resolved": "https://registry.npmjs.org/comma-separated-tokens/-/comma-separated-tokens-2.0.3.tgz",
@@ -4664,19 +4606,6 @@
46644606 "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==",
46654607 "license": "MIT"
46664608 },
4667- "node_modules/environment": {
4668- "version": "1.1.0",
4669- "resolved": "https://registry.npmjs.org/environment/-/environment-1.1.0.tgz",
4670- "integrity": "sha512-xUtoPkMggbz0MPyPiIWr1Kp4aeWJjDZ6SMvURhimjdZgsRuDplF5/s9hcgGhyXMhs+6vpnuoiZ2kFiu3FMnS8Q==",
4671- "dev": true,
4672- "license": "MIT",
4673- "engines": {
4674- "node": ">=18"
4675- },
4676- "funding": {
4677- "url": "https://github.com/sponsors/sindresorhus"
4678- }
4679- },
46804609 "node_modules/es-abstract": {
46814610 "version": "1.24.1",
46824611 "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.24.1.tgz",
@@ -5465,13 +5394,6 @@
54655394 "node": ">=0.10.0"
54665395 }
54675396 },
5468- "node_modules/eventemitter3": {
5469- "version": "5.0.1",
5470- "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.1.tgz",
5471- "integrity": "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==",
5472- "dev": true,
5473- "license": "MIT"
5474- },
Cut short: this commit's diff is over 1000 lines.
package.json+3−0
Cut short: this commit's diff is over 1000 lines.
src/components/App.tsx+83−0
Cut short: this commit's diff is over 1000 lines.
src/components/Button.tsx+13−8
Cut short: this commit's diff is over 1000 lines.
src/components/ErrorNotification.tsx+0−16
Cut short: this commit's diff is over 1000 lines.
src/components/MessageEditor.tsx+94−0
Cut short: this commit's diff is over 1000 lines.
src/components/MessageInput.tsx+0−171
Cut short: this commit's diff is over 1000 lines.
src/components/MessageList.tsx+146−0
Cut short: this commit's diff is over 1000 lines.
src/components/MessageList/AssistantMessage.tsx+0−43
Cut short: this commit's diff is over 1000 lines.
src/components/MessageList/DeleteMessageButton.tsx+0−39
Cut short: this commit's diff is over 1000 lines.
src/components/MessageList/MessageFooter.tsx+0−41
Cut short: this commit's diff is over 1000 lines.
src/components/MessageList/SystemMessage.tsx+0−22
Cut short: this commit's diff is over 1000 lines.
src/components/MessageList/ToolMessage.tsx+0−22
Cut short: this commit's diff is over 1000 lines.
src/components/MessageList/UserMessage.tsx+0−52
Cut short: this commit's diff is over 1000 lines.
src/components/MessageList/index.tsx+0−70
Cut short: this commit's diff is over 1000 lines.
src/components/Notification.tsx+0−19
Cut short: this commit's diff is over 1000 lines.
src/components/SettingsForm.tsx+115−0
Cut short: this commit's diff is over 1000 lines.
src/components/SettingsModal.tsx+0−79
Cut short: this commit's diff is over 1000 lines.
src/components/Sidebar.tsx+61−107
Cut short: this commit's diff is over 1000 lines.
src/components/Switch.tsx+56−0
Cut short: this commit's diff is over 1000 lines.
src/components/ThinkingNotification.tsx+0−33
Cut short: this commit's diff is over 1000 lines.
src/components/ThreadSettingsButton.tsx+0−72
Cut short: this commit's diff is over 1000 lines.
src/components/ThreadSettingsForm.tsx+0−94
Cut short: this commit's diff is over 1000 lines.
src/components/ThreadSettingsModal.tsx+0−190
Cut short: this commit's diff is over 1000 lines.
src/components/Welcome.tsx+9−3
Cut short: this commit's diff is over 1000 lines.
src/components/buttons/PrimaryButton.tsx+0−65
Cut short: this commit's diff is over 1000 lines.
src/hooks/api/useModels.ts+24−0
Cut short: this commit's diff is over 1000 lines.
src/hooks/api/useNewThread.ts+31−0
Cut short: this commit's diff is over 1000 lines.
src/hooks/api/useNewThreadMessage.ts+25−0
Cut short: this commit's diff is over 1000 lines.
src/hooks/api/useThreadMessages.ts+30−0
Cut short: this commit's diff is over 1000 lines.
src/hooks/api/useThreads.ts+35−0
Cut short: this commit's diff is over 1000 lines.
src/hooks/useErrorWithAutoDismiss.ts+0−25
Cut short: this commit's diff is over 1000 lines.
src/hooks/useFetch.ts+0−59
Cut short: this commit's diff is over 1000 lines.
src/hooks/useLocalStorage.ts+0−76
Cut short: this commit's diff is over 1000 lines.
src/hooks/useMessageDisplaySettings.ts+0−24
Cut short: this commit's diff is over 1000 lines.
src/hooks/useMessageHistory.ts+0−61
Cut short: this commit's diff is over 1000 lines.
src/hooks/useMessages.ts+0−362
Cut short: this commit's diff is over 1000 lines.
src/hooks/useModelValidation.ts+0−30
Cut short: this commit's diff is over 1000 lines.
src/hooks/useModels.ts+0−50
Cut short: this commit's diff is over 1000 lines.
src/hooks/useTheme.ts+4−7
Cut short: this commit's diff is over 1000 lines.
src/hooks/useThreadSelection.ts+0−51
Cut short: this commit's diff is over 1000 lines.
src/hooks/useThreads.ts+0−264
Cut short: this commit's diff is over 1000 lines.
src/lib/chat.ts+86−0
Cut short: this commit's diff is over 1000 lines.
src/lib/errors.ts+0−32
Cut short: this commit's diff is over 1000 lines.
src/lib/format-message-metadata.ts+0−41
Cut short: this commit's diff is over 1000 lines.
src/lib/format-timestamp.ts+0−9
Cut short: this commit's diff is over 1000 lines.
src/lib/message-helpers.ts+0−116
Cut short: this commit's diff is over 1000 lines.
src/lib/messages.ts+15−0
Cut short: this commit's diff is over 1000 lines.
src/lib/ollama/chat/abort-handler.ts+0−27
Cut short: this commit's diff is over 1000 lines.
src/lib/ollama/chat/assistant-response.ts+0−143
Cut short: this commit's diff is over 1000 lines.
src/lib/ollama/chat/index.ts+0−6
Cut short: this commit's diff is over 1000 lines.
src/lib/ollama/chat/message-persistence.ts+0−134
Cut short: this commit's diff is over 1000 lines.
src/lib/ollama/chat/ollama-chat.ts+0−207
Cut short: this commit's diff is over 1000 lines.
src/lib/ollama/chat/stream-controller.ts+0−38
Cut short: this commit's diff is over 1000 lines.
src/lib/ollama/chat/system-prompt.ts+0−67
Cut short: this commit's diff is over 1000 lines.
src/lib/ollama/index.ts+0−8
Cut short: this commit's diff is over 1000 lines.
src/lib/ollama/models.ts+0−18
Cut short: this commit's diff is over 1000 lines.
src/lib/ollama/title.ts+0−72
Cut short: this commit's diff is over 1000 lines.
src/lib/ollama/tools/index.ts+0−6
Cut short: this commit's diff is over 1000 lines.
src/lib/ollama/tools/tool-runner.ts+0−145
Cut short: this commit's diff is over 1000 lines.
src/lib/ollama/types.ts+0−21
Cut short: this commit's diff is over 1000 lines.
src/lib/parse-message-stream.ts+0−114
Cut short: this commit's diff is over 1000 lines.
src/lib/threads.ts+169−0
Cut short: this commit's diff is over 1000 lines.
src/lib/tools/duckduckgo.ts+2−4
Cut short: this commit's diff is over 1000 lines.
src/lib/tools/fetchpage.ts+2−9
Cut short: this commit's diff is over 1000 lines.
src/lib/tools/index.ts+31−0
Cut short: this commit's diff is over 1000 lines.
src/lib/tools/weather.ts+2−4
Cut short: this commit's diff is over 1000 lines.
src/lib/tools/websearch.ts+2−2
Cut short: this commit's diff is over 1000 lines.
src/tests/lib/ollama/chat/assistant-response.test.ts+0−262
Cut short: this commit's diff is over 1000 lines.
src/tests/lib/ollama/chat/ollama-chat.test.ts+0−245
Cut short: this commit's diff is over 1000 lines.
tsconfig.json+2−9
Cut short: this commit's diff is over 1000 lines.