xonecas.io
53129
Pa

PAT / commit e414817

feat: change thread settings

xonecas2025-12-18 e414817d6ca5abb365c2ce68516bbf8b2f330669 parent beca37c

24 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.

app/api/chat/route.ts+51−17
@@ -13,7 +13,8 @@ export async function POST(request: Request) {
1313 }
1414
1515 try {
16- // 1. Fetch thread to get its model
16+ // 1. Fetch thread to get its model and maxPromptLength settings
17+ // These thread-specific settings override any global settings
1718 const thread = await db
1819 .select()
1920 .from(threads)
@@ -22,8 +23,13 @@ export async function POST(request: Request) {
2223 if (thread.length === 0) {
2324 return NextResponse.json({ error: "Thread not found" }, { status: 404 });
2425 }
26+ // Use thread-specific model (stored in thread table)
2527 const threadModel = thread[0].model || "gpt-oss";
26- const threadMaxPromptLength = thread[0].maxPromptLength;
28+ // Use thread-specific maxPromptLength (stored in thread table, can be null, 1024, or 4096)
29+ // Type assertion ensures compatibility with fetchOllamaResponse which expects "none" | 1024 | 4096 | null
30+ // Note: null from database means "none" (no limit), which fetchOllamaResponse handles correctly
31+ const threadMaxPromptLength: "none" | 1024 | 4096 | null =
32+ thread[0].maxPromptLength === null ? null : (thread[0].maxPromptLength as 1024 | 4096);
2733
2834 // 2. Fetch previous messages from thread
2935 const previousMessages = await db
@@ -60,19 +66,20 @@ export async function POST(request: Request) {
6066 const encoder = new TextEncoder();
6167 const stream = new ReadableStream({
6268 async start(controller) {
63- try {
64- // Track if controller is closed to avoid double-close
65- let isControllerClosed = false;
66- const safeClose = () => {
67- if (!isControllerClosed) {
68- isControllerClosed = true;
69- try {
70- controller.close();
71- } catch (e) {
72- // Controller may already be closed, ignore
73- }
69+ // Track if controller is closed to avoid double-close
70+ let isControllerClosed = false;
71+ const safeClose = () => {
72+ if (!isControllerClosed) {
73+ isControllerClosed = true;
74+ try {
75+ controller.close();
76+ } catch (e) {
77+ // Controller may already be closed, ignore
7478 }
75- };
79+ }
80+ };
81+
82+ try {
7683
7784 // Check if already aborted
7885 if (signal.aborted) {
@@ -165,6 +172,8 @@ export async function POST(request: Request) {
165172 threadId: parseInt(threadId),
166173 role: "assistant",
167174 content: accumulatedContent,
175+ model: threadModel,
176+ maxPromptLength: threadMaxPromptLength, // null means "none" (no limit), otherwise 1024 or 4096
168177 createdAt: new Date(),
169178 generationTimeMs: null,
170179 toolCalls: allToolCalls.length > 0 ? JSON.stringify(allToolCalls) : null,
@@ -173,16 +182,36 @@ export async function POST(request: Request) {
173182 .update(threads)
174183 .set({ updatedAt: new Date() })
175184 .where(eq(threads.id, parseInt(threadId)));
185+
186+ // Send done message with metadata for aborted generation
187+ if (!isControllerClosed) {
188+ try {
189+ controller.enqueue(
190+ encoder.encode(
191+ `data: ${JSON.stringify({
192+ type: "done",
193+ answer: accumulatedContent,
194+ model: threadModel,
195+ maxPromptLength: threadMaxPromptLength
196+ })}\n\n`
197+ )
198+ );
199+ } catch (e) {
200+ // Controller may be closed, ignore
201+ }
202+ }
176203 }
177204 safeClose();
178205 return;
179206 }
180207
181- // 6. Store assistant message with generation time and tool calls
208+ // 6. Store assistant message with model, maxPromptLength, generation time and tool calls
182209 await db.insert(messages).values({
183210 threadId: parseInt(threadId),
184211 role: "assistant",
185212 content: accumulatedContent,
213+ model: threadModel,
214+ maxPromptLength: threadMaxPromptLength, // null means "none" (no limit), otherwise 1024 or 4096
186215 createdAt: new Date(),
187216 generationTimeMs,
188217 toolCalls: toolCalls ? JSON.stringify(toolCalls) : null,
@@ -194,12 +223,17 @@ export async function POST(request: Request) {
194223 .set({ updatedAt: new Date() })
195224 .where(eq(threads.id, parseInt(threadId)));
196225
197- // Send final message
226+ // Send final message with metadata
198227 if (!isControllerClosed) {
199228 try {
200229 controller.enqueue(
201230 encoder.encode(
202- `data: ${JSON.stringify({ type: "done", answer: accumulatedContent })}\n\n`
231+ `data: ${JSON.stringify({
232+ type: "done",
233+ answer: accumulatedContent,
234+ model: threadModel,
235+ maxPromptLength: threadMaxPromptLength
236+ })}\n\n`
203237 )
204238 );
205239 } catch (e) {
app/api/settings/route.ts+28−8
@@ -5,13 +5,14 @@ const SETTINGS_CACHE_KEY = "app_settings";
55
66 type Settings = {
77 maxPromptLength: "none" | 1024 | 4096;
8+ selectedModel?: string;
89 };
910
1011 export async function GET() {
1112 try {
1213 const settings = await getCache<Settings>(SETTINGS_CACHE_KEY);
1314 return NextResponse.json({
14- settings: settings || { maxPromptLength: "none" },
15+ settings: settings || { maxPromptLength: "none", selectedModel: "gpt-oss" },
1516 });
1617 } catch (error) {
1718 console.error("Get settings error", error);
@@ -21,17 +22,36 @@ export async function GET() {
2122
2223 export async function POST(request: Request) {
2324 try {
24- const { maxPromptLength } = await request.json();
25+ const { maxPromptLength, selectedModel } = await request.json();
2526
26- // Validate maxPromptLength
27- if (maxPromptLength !== "none" && maxPromptLength !== 1024 && maxPromptLength !== 4096) {
28- return NextResponse.json({ error: "Invalid maxPromptLength value" }, { status: 400 });
27+ const settings: Settings = {};
28+
29+ // Validate and set maxPromptLength if provided
30+ if (maxPromptLength !== undefined) {
31+ if (maxPromptLength !== "none" && maxPromptLength !== 1024 && maxPromptLength !== 4096) {
32+ return NextResponse.json({ error: "Invalid maxPromptLength value" }, { status: 400 });
33+ }
34+ settings.maxPromptLength = maxPromptLength;
35+ }
36+
37+ // Validate and set selectedModel if provided
38+ if (selectedModel !== undefined) {
39+ if (typeof selectedModel !== "string") {
40+ return NextResponse.json({ error: "Invalid selectedModel value" }, { status: 400 });
41+ }
42+ settings.selectedModel = selectedModel;
2943 }
3044
31- const settings: Settings = { maxPromptLength };
32- await setCache(SETTINGS_CACHE_KEY, settings);
45+ // Get existing settings and merge
46+ const existingSettings = await getCache<Settings>(SETTINGS_CACHE_KEY);
47+ const mergedSettings: Settings = {
48+ maxPromptLength: settings.maxPromptLength ?? existingSettings?.maxPromptLength ?? "none",
49+ selectedModel: settings.selectedModel ?? existingSettings?.selectedModel ?? "gpt-oss",
50+ };
51+
52+ await setCache(SETTINGS_CACHE_KEY, mergedSettings);
3353
34- return NextResponse.json({ settings });
54+ return NextResponse.json({ settings: mergedSettings });
3555 } catch (error) {
3656 console.error("Set settings error", error);
3757 return NextResponse.json({ error: "Failed to set settings" }, { status: 500 });
app/api/threads/[id]/route.ts+41−0
@@ -3,6 +3,47 @@ import { db } from "@/src/lib/db";
33 import { threads } from "@/src/lib/db/schema";
44 import { eq } from "drizzle-orm";
55
6+export async function PATCH(request: Request, { params }: { params: Promise<{ id: string }> }) {
7+ try {
8+ const { id } = await params;
9+ const threadId = parseInt(id);
10+ if (isNaN(threadId)) {
11+ return NextResponse.json({ error: "Invalid thread ID" }, { status: 400 });
12+ }
13+
14+ const body = await request.json();
15+ const { model, maxPromptLength } = body;
16+
17+ const updateData: { model?: string; maxPromptLength?: number | null; updatedAt?: Date } = {
18+ updatedAt: new Date(),
19+ };
20+
21+ if (model !== undefined) {
22+ updateData.model = model;
23+ }
24+
25+ if (maxPromptLength !== undefined) {
26+ updateData.maxPromptLength =
27+ maxPromptLength === "none" || maxPromptLength === null ? null : maxPromptLength;
28+ }
29+
30+ const updatedThread = await db
31+ .update(threads)
32+ .set(updateData)
33+ .where(eq(threads.id, threadId))
34+ .returning();
35+
36+ if (updatedThread.length === 0) {
37+ return NextResponse.json({ error: "Thread not found" }, { status: 404 });
38+ }
39+
40+ return NextResponse.json({ thread: updatedThread[0] });
41+ } catch (error) {
42+ console.error("Update thread error", error);
43+ return NextResponse.json({ error: "Failed to update thread" }, { status: 500 });
44+ }
45+}
46+
647 export async function DELETE(request: Request, { params }: { params: Promise<{ id: string }> }) {
748 try {
849 const { id } = await params;
app/page.tsx+31−11
@@ -5,8 +5,7 @@ import MessageInput, { type MessageInputRef } from "@/src/components/MessageInpu
55 import MessageList from "@/src/components/MessageList";
66 import NoThreadSelected from "@/src/components/NoThreadSelected";
77 import { useTheme } from "@/src/hooks/useTheme";
8-import { useModel } from "@/src/hooks/useModel";
9-import { useMaxPromptLength } from "@/src/hooks/useMaxPromptLength";
8+import { useModelSettings } from "@/src/hooks/useModelSettings";
109 import { useThreads } from "@/src/hooks/useThreads";
1110 import { useMessages } from "@/src/hooks/useMessages";
1211 import { useThreadSelection } from "@/src/hooks/useThreadSelection";
@@ -14,8 +13,8 @@ import "./highlight-theme.css";
1413
1514 export default function Home() {
1615 const { themeMode, handleThemeChange } = useTheme();
17- const { selectedModel, handleModelChange } = useModel();
18- const { maxPromptLength, handleMaxPromptLengthChange } = useMaxPromptLength();
16+ const { selectedModel, handleModelChange, maxPromptLength, handleMaxPromptLengthChange } =
17+ useModelSettings();
1918 const {
2019 threads,
2120 totalThreadCount,
@@ -23,6 +22,7 @@ export default function Home() {
2322 loadThreads,
2423 loadMoreThreads,
2524 createThread,
25+ updateThread,
2626 deleteThread,
2727 } = useThreads();
2828 const { currentThreadId, selectThread, deselectThread, messagesContainerRef } =
@@ -52,6 +52,20 @@ export default function Home() {
5252 }, 0);
5353 };
5454
55+ const handleThreadUpdate = async (
56+ threadId: number,
57+ updates: { model?: string; maxPromptLength?: "none" | 1024 | 4096 | null }
58+ ) => {
59+ try {
60+ await updateThread(threadId, updates);
61+ // Reload threads to ensure UI is in sync
62+ await loadThreads(8);
63+ } catch (error) {
64+ console.error("Failed to update thread", error);
65+ throw error;
66+ }
67+ };
68+
5569 const handleThreadDelete = async (threadId: number) => {
5670 try {
5771 await deleteThread(threadId);
@@ -62,6 +76,7 @@ export default function Home() {
6276 }
6377 } catch (error) {
6478 console.error("Failed to delete thread", error);
79+ throw error;
6580 }
6681 };
6782
@@ -89,14 +104,20 @@ export default function Home() {
89104 <div
90105 ref={messagesContainerRef}
91106 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 ${
92- isLoading && streamingMessageId !== null ? "pb-44" : "pb-40"
107+ isLoading && streamingMessageId !== null ? "pb-52" : "pb-48"
93108 }`}
94109 >
95110 <div
96111 className={`mx-auto flex min-h-full max-w-5xl flex-col gap-8 ${currentThreadId === null ? "justify-center" : "justify-end"}`}
97112 >
98113 {currentThreadId === null ? (
99- <NoThreadSelected threadCount={totalThreadCount} />
114+ <NoThreadSelected
115+ threadCount={totalThreadCount}
116+ selectedModel={selectedModel}
117+ onModelChange={handleModelChange}
118+ maxPromptLength={maxPromptLength}
119+ onMaxPromptLengthChange={handleMaxPromptLengthChange}
120+ />
100121 ) : (
101122 <MessageList
102123 messages={messages}
@@ -117,7 +138,10 @@ export default function Home() {
117138 isStreaming={isLoading && streamingMessageId !== null}
118139 onStop={stopGeneration}
119140 currentThreadId={currentThreadId}
120- currentThread={currentThreadId !== null ? threads.find((t) => t.id === currentThreadId) || null : null}
141+ currentThread={
142+ currentThreadId !== null ? threads.find((t) => t.id === currentThreadId) || null : null
143+ }
144+ onThreadUpdate={handleThreadUpdate}
121145 onThreadDelete={handleThreadDelete}
122146 />
123147 </div>
@@ -128,10 +152,6 @@ export default function Home() {
128152 onCreateNewThread={handleCreateNewThread}
129153 onThreadSelect={handleThreadSelect}
130154 onThemeChange={handleThemeChange}
131- selectedModel={selectedModel}
132- onModelChange={handleModelChange}
133- maxPromptLength={maxPromptLength}
134- onMaxPromptLengthChange={handleMaxPromptLengthChange}
135155 onLoadMore={loadMoreThreads}
136156 hasMoreThreads={hasMoreThreads}
137157 />
drizzle/0003_freezing_chimera.sql+1−0
@@ -0,0 +1 @@
1+ALTER TABLE "messages" ADD COLUMN "model" text;
drizzle/0004_regular_anthem.sql+1−0
@@ -0,0 +1 @@
1+ALTER TABLE "messages" ADD COLUMN "max_prompt_length" integer;
drizzle/meta/0003_snapshot.json+147−0
@@ -0,0 +1,147 @@
1+{
2+ "id": "f5c46391-5f06-4dd6-90db-b8e7c2810ae7",
3+ "prevId": "b62bd3e8-878e-4048-b9d6-eec4a4e68c3a",
4+ "version": "7",
5+ "dialect": "postgresql",
6+ "tables": {
7+ "public.messages": {
8+ "name": "messages",
9+ "schema": "",
10+ "columns": {
11+ "id": {
12+ "name": "id",
13+ "type": "serial",
14+ "primaryKey": true,
15+ "notNull": true
16+ },
17+ "thread_id": {
18+ "name": "thread_id",
19+ "type": "integer",
20+ "primaryKey": false,
21+ "notNull": true
22+ },
23+ "role": {
24+ "name": "role",
25+ "type": "text",
26+ "primaryKey": false,
27+ "notNull": true
28+ },
29+ "content": {
30+ "name": "content",
31+ "type": "text",
32+ "primaryKey": false,
33+ "notNull": true
34+ },
35+ "model": {
36+ "name": "model",
37+ "type": "text",
38+ "primaryKey": false,
39+ "notNull": false
40+ },
41+ "created_at": {
42+ "name": "created_at",
43+ "type": "timestamp with time zone",
44+ "primaryKey": false,
45+ "notNull": true,
46+ "default": "now()"
47+ },
48+ "generation_time_ms": {
49+ "name": "generation_time_ms",
50+ "type": "integer",
51+ "primaryKey": false,
52+ "notNull": false
53+ },
54+ "tool_calls": {
55+ "name": "tool_calls",
56+ "type": "text",
57+ "primaryKey": false,
58+ "notNull": false
59+ }
60+ },
61+ "indexes": {},
62+ "foreignKeys": {
63+ "messages_thread_id_threads_id_fk": {
64+ "name": "messages_thread_id_threads_id_fk",
65+ "tableFrom": "messages",
66+ "tableTo": "threads",
67+ "columnsFrom": [
68+ "thread_id"
69+ ],
70+ "columnsTo": [
71+ "id"
72+ ],
73+ "onDelete": "cascade",
74+ "onUpdate": "no action"
75+ }
76+ },
77+ "compositePrimaryKeys": {},
78+ "uniqueConstraints": {},
79+ "policies": {},
80+ "checkConstraints": {},
81+ "isRLSEnabled": false
82+ },
83+ "public.threads": {
84+ "name": "threads",
85+ "schema": "",
86+ "columns": {
87+ "id": {
88+ "name": "id",
89+ "type": "serial",
90+ "primaryKey": true,
91+ "notNull": true
92+ },
93+ "title": {
94+ "name": "title",
95+ "type": "text",
96+ "primaryKey": false,
97+ "notNull": false
98+ },
99+ "model": {
100+ "name": "model",
101+ "type": "text",
102+ "primaryKey": false,
103+ "notNull": true,
104+ "default": "'gpt-oss'"
105+ },
106+ "max_prompt_length": {
107+ "name": "max_prompt_length",
108+ "type": "integer",
109+ "primaryKey": false,
110+ "notNull": false
111+ },
112+ "created_at": {
113+ "name": "created_at",
114+ "type": "timestamp with time zone",
115+ "primaryKey": false,
116+ "notNull": true,
117+ "default": "now()"
118+ },
119+ "updated_at": {
120+ "name": "updated_at",
121+ "type": "timestamp with time zone",
122+ "primaryKey": false,
123+ "notNull": true,
124+ "default": "now()"
125+ }
126+ },
127+ "indexes": {},
128+ "foreignKeys": {},
129+ "compositePrimaryKeys": {},
130+ "uniqueConstraints": {},
131+ "policies": {},
132+ "checkConstraints": {},
133+ "isRLSEnabled": false
134+ }
135+ },
136+ "enums": {},
137+ "schemas": {},
138+ "sequences": {},
139+ "roles": {},
140+ "policies": {},
141+ "views": {},
142+ "_meta": {
143+ "columns": {},
144+ "schemas": {},
145+ "tables": {}
146+ }
147+}
drizzle/meta/0004_snapshot.json+153−0
@@ -0,0 +1,153 @@
1+{
2+ "id": "bc4cb2c1-be83-4071-9f0d-1acb6b257269",
3+ "prevId": "f5c46391-5f06-4dd6-90db-b8e7c2810ae7",
4+ "version": "7",
5+ "dialect": "postgresql",
6+ "tables": {
7+ "public.messages": {
8+ "name": "messages",
9+ "schema": "",
10+ "columns": {
11+ "id": {
12+ "name": "id",
13+ "type": "serial",
14+ "primaryKey": true,
15+ "notNull": true
16+ },
17+ "thread_id": {
18+ "name": "thread_id",
19+ "type": "integer",
20+ "primaryKey": false,
21+ "notNull": true
22+ },
23+ "role": {
24+ "name": "role",
25+ "type": "text",
26+ "primaryKey": false,
27+ "notNull": true
28+ },
29+ "content": {
30+ "name": "content",
31+ "type": "text",
32+ "primaryKey": false,
33+ "notNull": true
34+ },
35+ "model": {
36+ "name": "model",
37+ "type": "text",
38+ "primaryKey": false,
39+ "notNull": false
40+ },
41+ "max_prompt_length": {
42+ "name": "max_prompt_length",
43+ "type": "integer",
44+ "primaryKey": false,
45+ "notNull": false
46+ },
47+ "created_at": {
48+ "name": "created_at",
49+ "type": "timestamp with time zone",
50+ "primaryKey": false,
51+ "notNull": true,
52+ "default": "now()"
53+ },
54+ "generation_time_ms": {
55+ "name": "generation_time_ms",
56+ "type": "integer",
57+ "primaryKey": false,
58+ "notNull": false
59+ },
60+ "tool_calls": {
61+ "name": "tool_calls",
62+ "type": "text",
63+ "primaryKey": false,
64+ "notNull": false
65+ }
66+ },
67+ "indexes": {},
68+ "foreignKeys": {
69+ "messages_thread_id_threads_id_fk": {
70+ "name": "messages_thread_id_threads_id_fk",
71+ "tableFrom": "messages",
72+ "tableTo": "threads",
73+ "columnsFrom": [
74+ "thread_id"
75+ ],
76+ "columnsTo": [
77+ "id"
78+ ],
79+ "onDelete": "cascade",
80+ "onUpdate": "no action"
81+ }
82+ },
83+ "compositePrimaryKeys": {},
84+ "uniqueConstraints": {},
85+ "policies": {},
86+ "checkConstraints": {},
87+ "isRLSEnabled": false
88+ },
89+ "public.threads": {
90+ "name": "threads",
91+ "schema": "",
92+ "columns": {
93+ "id": {
94+ "name": "id",
95+ "type": "serial",
96+ "primaryKey": true,
97+ "notNull": true
98+ },
99+ "title": {
100+ "name": "title",
101+ "type": "text",
102+ "primaryKey": false,
103+ "notNull": false
104+ },
105+ "model": {
106+ "name": "model",
107+ "type": "text",
108+ "primaryKey": false,
109+ "notNull": true,
110+ "default": "'gpt-oss'"
111+ },
112+ "max_prompt_length": {
113+ "name": "max_prompt_length",
114+ "type": "integer",
115+ "primaryKey": false,
116+ "notNull": false
117+ },
118+ "created_at": {
119+ "name": "created_at",
120+ "type": "timestamp with time zone",
121+ "primaryKey": false,
122+ "notNull": true,
123+ "default": "now()"
124+ },
125+ "updated_at": {
126+ "name": "updated_at",
127+ "type": "timestamp with time zone",
128+ "primaryKey": false,
129+ "notNull": true,
130+ "default": "now()"
131+ }
132+ },
133+ "indexes": {},
134+ "foreignKeys": {},
135+ "compositePrimaryKeys": {},
136+ "uniqueConstraints": {},
137+ "policies": {},
138+ "checkConstraints": {},
139+ "isRLSEnabled": false
140+ }
141+ },
142+ "enums": {},
143+ "schemas": {},
144+ "sequences": {},
145+ "roles": {},
146+ "policies": {},
147+ "views": {},
148+ "_meta": {
149+ "columns": {},
150+ "schemas": {},
151+ "tables": {}
152+ }
153+}
drizzle/meta/_journal.json+14−0
@@ -22,6 +22,20 @@
2222 "when": 1766015192850,
2323 "tag": "0002_white_echo",
2424 "breakpoints": true
25+ },
26+ {
27+ "idx": 3,
28+ "version": "7",
29+ "when": 1766019835649,
30+ "tag": "0003_freezing_chimera",
31+ "breakpoints": true
32+ },
33+ {
34+ "idx": 4,
35+ "version": "7",
36+ "when": 1766021303746,
37+ "tag": "0004_regular_anthem",
38+ "breakpoints": true
2539 }
2640 ]
2741 }
src/components/MessageInput.tsx+11−7
@@ -4,7 +4,7 @@ import { useState, useRef, useImperativeHandle, forwardRef, useEffect } from "re
44 import PaperPlaneIcon from "@/src/components/icons/PaperPlaneIcon";
55 import PrimaryButton from "@/src/components/buttons/PrimaryButton";
66 import ThinkingNotification from "@/src/components/ThinkingNotification";
7-import DeleteThreadButton from "@/src/components/DeleteThreadButton";
7+import ThreadSettingsButton from "@/src/components/ThreadSettingsButton";
88 import type { Message } from "@/src/lib/db/schema";
99 import type { Thread } from "@/src/lib/db/schema";
1010
@@ -18,7 +18,11 @@ type MessageInputProps = {
1818 onStop?: () => void;
1919 currentThreadId: number | null;
2020 currentThread: Thread | null;
21- onThreadDelete?: (threadId: number) => void;
21+ onThreadUpdate?: (
22+ threadId: number,
23+ updates: { model?: string; maxPromptLength?: "none" | 1024 | 4096 | null }
24+ ) => Promise<void>;
25+ onThreadDelete?: (threadId: number) => Promise<void>;
2226 };
2327
2428 export type MessageInputRef = {
@@ -37,6 +41,7 @@ const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(
3741 onStop,
3842 currentThreadId,
3943 currentThread,
44+ onThreadUpdate,
4045 onThreadDelete,
4146 },
4247 ref
@@ -141,11 +146,11 @@ const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(
141146 <div className="flex-1">
142147 {isStreaming && onStop && <ThinkingNotification onStop={onStop} />}
143148 </div>
144- {currentThreadId !== null && currentThread && onThreadDelete && (
149+ {currentThreadId !== null && currentThread && onThreadUpdate && onThreadDelete && (
145150 <div className="flex-shrink-0">
146- <DeleteThreadButton
147- threadId={currentThreadId}
148- threadTitle={currentThread.title || `Thread ${currentThreadId}`}
151+ <ThreadSettingsButton
152+ thread={currentThread}
153+ onUpdateThread={onThreadUpdate}
149154 onDeleteThread={onThreadDelete}
150155 />
151156 </div>
@@ -166,7 +171,6 @@ const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(
166171 className="w-full resize-none overflow-y-auto bg-transparent p-4 pr-12 placeholder:italic placeholder:text-neutral-600 focus:outline-none disabled:cursor-not-allowed disabled:opacity-50 dark:placeholder:text-neutral-400"
167172 />
168173 <div className="absolute bottom-2 right-2 flex flex-col items-end gap-1">
169- <div className="text-xs text-neutral-600 dark:text-neutral-400">{modelName}</div>
170174 <PrimaryButton color="neutral" type="submit" disabled={isAnyLoading}>
171175 <PaperPlaneIcon
172176 className={`h-8 w-10 p-1.5 ${isAnyLoading ? "animate-spin-and-color-cycle" : ""}`}
src/components/MessageList/AssistantMessage.tsx+10−1
@@ -47,6 +47,11 @@ export default function AssistantMessage({ message, isStreaming = false }: Assis
4747 }
4848 };
4949
50+ const formatPromptSize = (maxPromptLength: number | null): string => {
51+ if (maxPromptLength === null) return "none";
52+ return `${maxPromptLength}`;
53+ };
54+
5055 const hasContent = message.content && message.content.trim() !== "";
5156
5257 return (
@@ -58,8 +63,12 @@ export default function AssistantMessage({ message, isStreaming = false }: Assis
5863 )}
5964 <div className="mt-4 text-xs text-neutral-600 dark:text-neutral-400">
6065 generated on {formatTimestamp(message.createdAt)}
66+ {message.model && <span className="ml-1">• model: {message.model}</span>}
67+ {message.maxPromptLength !== undefined && (
68+ <span className="ml-1">• prompt size: {formatPromptSize(message.maxPromptLength)}</span>
69+ )}
6170 {message.generationTimeMs && (
62- <span className="ml-1"> in {formatGenerationTime(message.generationTimeMs)}</span>
71+ <span className="ml-1">• in {formatGenerationTime(message.generationTimeMs)}</span>
6372 )}
6473 {formatToolCalls(message.toolCalls) && (
6574 <span className="ml-1">• tools: {formatToolCalls(message.toolCalls)}</span>
src/components/MessageList/DeleteMessageButton.tsx+1−1
@@ -22,7 +22,7 @@ export default function DeleteMessageButton({
2222
2323 return (
2424 <div className={`mt-2 ${align === "right" ? "flex justify-end" : ""}`}>
25- <div className="w-fit rounded-lg bg-neutral-300/80 px-3 py-1 dark:bg-neutral-800/80">
25+ <div className="w-fit">
2626 <SecondaryButton
2727 onClick={(e) => {
2828 e.preventDefault();
src/components/NoThreadSelected.tsx+86−1
@@ -4,10 +4,22 @@ import { useState, useEffect } from "react";
44
55 type NoThreadSelectedProps = {
66 threadCount: number;
7+ selectedModel: string;
8+ onModelChange: (model: string) => void;
9+ maxPromptLength: "none" | 1024 | 4096;
10+ onMaxPromptLengthChange: (value: "none" | 1024 | 4096) => void;
711 };
812
9-export default function NoThreadSelected({ threadCount }: NoThreadSelectedProps) {
13+export default function NoThreadSelected({
14+ threadCount,
15+ selectedModel,
16+ onModelChange,
17+ maxPromptLength,
18+ onMaxPromptLengthChange,
19+}: NoThreadSelectedProps) {
1020 const [currentTime, setCurrentTime] = useState<Date | null>(null);
21+ const [models, setModels] = useState<Array<{ name: string; model: string }>>([]);
22+ const [isLoadingModels, setIsLoadingModels] = useState(false);
1123
1224 useEffect(() => {
1325 // Set initial time only on client side to avoid hydration mismatch
@@ -19,6 +31,35 @@ export default function NoThreadSelected({ threadCount }: NoThreadSelectedProps)
1931 return () => clearInterval(timer);
2032 }, []);
2133
34+ useEffect(() => {
35+ setIsLoadingModels(true);
36+ fetch("/api/models")
37+ .then((res) => res.json())
38+ .then((data) => {
39+ const availableModels = data.models || [];
40+ setModels(availableModels);
41+
42+ // Validate selected model against available models
43+ if (availableModels.length > 0) {
44+ const modelExists = availableModels.some(
45+ (m: { name: string; model: string }) => m.model === selectedModel
46+ );
47+
48+ if (!modelExists) {
49+ // Selected model doesn't exist, fall back to first available
50+ const fallbackModel = availableModels[0].model;
51+ onModelChange(fallbackModel);
52+ }
53+ }
54+
55+ setIsLoadingModels(false);
56+ })
57+ .catch((error) => {
58+ console.error("Failed to load models", error);
59+ setIsLoadingModels(false);
60+ });
61+ }, [selectedModel, onModelChange]);
62+
2263 const formatTime = (date: Date): string => {
2364 return date.toLocaleString();
2465 };
@@ -35,6 +76,50 @@ export default function NoThreadSelected({ threadCount }: NoThreadSelectedProps)
3576 sidebar.
3677 </p>
3778 <hr className="border-neutral-300 dark:border-neutral-700" />
79+ <div className="flex flex-col gap-4">
80+ <div className="flex flex-col gap-2">
81+ <label className="text-sm font-medium text-neutral-600 dark:text-neutral-400">
82+ Model
83+ </label>
84+ <select
85+ value={selectedModel}
86+ onChange={(e) => onModelChange(e.target.value)}
87+ disabled={isLoadingModels}
88+ className="bg-neutral-100 px-3 py-2 text-neutral-800 focus:outline-none disabled:opacity-50 dark:bg-neutral-900 dark:text-neutral-200"
89+ >
90+ {isLoadingModels ? (
91+ <option>Loading models...</option>
92+ ) : models.length === 0 ? (
93+ <option>No models available</option>
94+ ) : (
95+ models.map((model) => (
96+ <option key={model.name} value={model.model}>
97+ {model.name}
98+ </option>
99+ ))
100+ )}
101+ </select>
102+ </div>
103+ <div className="flex flex-col gap-2">
104+ <label className="text-sm font-medium text-neutral-600 dark:text-neutral-400">
105+ Max Prompt Length
106+ </label>
107+ <select
108+ value={maxPromptLength}
109+ onChange={(e) =>
110+ onMaxPromptLengthChange(
111+ e.target.value === "none" ? "none" : (parseInt(e.target.value, 10) as 1024 | 4096)
112+ )
113+ }
114+ className="bg-neutral-100 px-3 py-2 text-neutral-800 focus:outline-none dark:bg-neutral-900 dark:text-neutral-200"
115+ >
116+ <option value="none">None</option>
117+ <option value="1024">1024</option>
118+ <option value="4096">4096</option>
119+ </select>
120+ </div>
121+ </div>
122+ <hr className="border-neutral-300 dark:border-neutral-700" />
38123 <p className="text-sm text-neutral-600 dark:text-neutral-400">
39124 {timeDisplay && (
40125 <>
src/components/SettingsModal.tsx+0−79
@@ -1,6 +1,5 @@
11 "use client";
22
3-import { useState, useEffect } from "react";
43 import Modal from "@/src/components/Modal";
54
65 type SettingsModalProps = {
@@ -8,10 +7,6 @@ type SettingsModalProps = {
87 onClose: () => void;
98 themeMode: "device" | "dark" | "light";
109 onThemeChange: (mode: "device" | "dark" | "light") => void;
11- selectedModel: string;
12- onModelChange: (model: string) => void;
13- maxPromptLength: "none" | 1024 | 4096;
14- onMaxPromptLengthChange: (value: "none" | 1024 | 4096) => void;
1510 };
1611
1712 export default function SettingsModal({
@@ -19,44 +14,7 @@ export default function SettingsModal({
1914 onClose,
2015 themeMode,
2116 onThemeChange,
22- selectedModel,
23- onModelChange,
24- maxPromptLength,
25- onMaxPromptLengthChange,
2617 }: SettingsModalProps) {
27- const [models, setModels] = useState<Array<{ name: string; model: string }>>([]);
28- const [isLoadingModels, setIsLoadingModels] = useState(false);
29-
30- useEffect(() => {
31- if (isOpen) {
32- setIsLoadingModels(true);
33- fetch("/api/models")
34- .then((res) => res.json())
35- .then((data) => {
36- const availableModels = data.models || [];
37- setModels(availableModels);
38-
39- // Validate selected model against available models
40- if (availableModels.length > 0) {
41- const modelExists = availableModels.some(
42- (m: { name: string; model: string }) => m.model === selectedModel
43- );
44-
45- if (!modelExists) {
46- // Selected model doesn't exist, fall back to first available
47- const fallbackModel = availableModels[0].model;
48- onModelChange(fallbackModel);
49- }
50- }
51-
52- setIsLoadingModels(false);
53- })
54- .catch((error) => {
55- console.error("Failed to load models", error);
56- setIsLoadingModels(false);
57- });
58- }
59- }, [isOpen, selectedModel, onModelChange]);
6018
6119 return (
6220 <Modal isOpen={isOpen} onClose={onClose}>
@@ -76,43 +34,6 @@ export default function SettingsModal({
7634 <option value="light">Light</option>
7735 </select>
7836 </div>
79- <div className="flex flex-col gap-2">
80- <label className="text-neutral-600 dark:text-neutral-400">Model</label>
81- <select
82- value={selectedModel}
83- onChange={(e) => onModelChange(e.target.value)}
84- disabled={isLoadingModels}
85- className="bg-neutral-100 px-3 py-1 text-neutral-800 focus:outline-none disabled:opacity-50 dark:bg-neutral-900 dark:text-neutral-200"
86- >
87- {isLoadingModels ? (
88- <option>Loading models...</option>
89- ) : models.length === 0 ? (
90- <option>No models available</option>
91- ) : (
92- models.map((model) => (
93- <option key={model.name} value={model.model}>
94- {model.name}
95- </option>
96- ))
97- )}
98- </select>
99- </div>
100- <div className="flex flex-col gap-2">
101- <label className="text-neutral-600 dark:text-neutral-400">Max Prompt Length</label>
102- <select
103- value={maxPromptLength}
104- onChange={(e) =>
105- onMaxPromptLengthChange(
106- e.target.value === "none" ? "none" : (parseInt(e.target.value, 10) as 1024 | 4096)
107- )
108- }
109- className="bg-neutral-100 px-3 py-1 text-neutral-800 focus:outline-none dark:bg-neutral-900 dark:text-neutral-200"
110- >
111- <option value="none">None</option>
112- <option value="1024">1024</option>
113- <option value="4096">4096</option>
114- </select>
115- </div>
11637 </div>
11738 </Modal>
11839 );
src/components/Sidebar.tsx+0−12
@@ -16,10 +16,6 @@ type SidebarProps = {
1616 onCreateNewThread: () => void;
1717 onThreadSelect: (threadId: number) => void;
1818 onThemeChange: (mode: "device" | "dark" | "light") => void;
19- selectedModel: string;
20- onModelChange: (model: string) => void;
21- maxPromptLength: "none" | 1024 | 4096;
22- onMaxPromptLengthChange: (value: "none" | 1024 | 4096) => void;
2319 onLoadMore: () => void;
2420 hasMoreThreads: boolean;
2521 };
@@ -31,10 +27,6 @@ export default function Sidebar({
3127 onCreateNewThread,
3228 onThreadSelect,
3329 onThemeChange,
34- selectedModel,
35- onModelChange,
36- maxPromptLength,
37- onMaxPromptLengthChange,
3830 onLoadMore,
3931 hasMoreThreads,
4032 }: SidebarProps) {
@@ -118,10 +110,6 @@ export default function Sidebar({
118110 onClose={() => setIsSettingsOpen(false)}
119111 themeMode={themeMode}
120112 onThemeChange={onThemeChange}
121- selectedModel={selectedModel}
122- onModelChange={onModelChange}
123- maxPromptLength={maxPromptLength}
Cut short: this commit's diff is over 1000 lines.
src/components/ThreadSettingsButton.tsx+47−0
Cut short: this commit's diff is over 1000 lines.
src/components/ThreadSettingsModal.tsx+194−0
Cut short: this commit's diff is over 1000 lines.
src/components/buttons/SecondaryButton.tsx+13−1
Cut short: this commit's diff is over 1000 lines.
src/hooks/useMaxPromptLength.ts+0−36
Cut short: this commit's diff is over 1000 lines.
src/hooks/useMessages.ts+8−2
Cut short: this commit's diff is over 1000 lines.
src/hooks/useModel.ts+0−53
Cut short: this commit's diff is over 1000 lines.
src/hooks/useModelSettings.ts+97−0
Cut short: this commit's diff is over 1000 lines.
src/hooks/useThreads.ts+29−1
Cut short: this commit's diff is over 1000 lines.
src/lib/db/schema.ts+2−0
Cut short: this commit's diff is over 1000 lines.