@@ -11,12 +11,16 @@ type ThreadSettingsModalProps = {
1111 isOpen: boolean;
1212 onClose: () => void;
1313 thread: Thread | null;
14- onUpdateThread: (
14+ onUpdateThread?: (
1515 threadId: number,
1616 updates: { model?: string; maxPromptLength?: "none" | 1024 | 4096 | null }
1717 ) => Promise<void>;
18- onDeleteThread: (threadId: number) => Promise<void>;
18+ onDeleteThread?: (threadId: number) => Promise<void>;
1919 onError?: (error: string) => void;
20+ initialModel?: string;
21+ initialMaxPromptLength?: "none" | 1024 | 4096;
22+ onModelChange?: (model: string) => void;
23+ onMaxPromptLengthChange?: (value: "none" | 1024 | 4096) => void;
2024 };
2125
2226 export default function ThreadSettingsModal({
@@ -26,6 +30,10 @@ export default function ThreadSettingsModal({
2630 onUpdateThread,
2731 onDeleteThread,
2832 onError,
33+ initialModel,
34+ initialMaxPromptLength,
35+ onModelChange,
36+ onMaxPromptLengthChange,
2937 }: ThreadSettingsModalProps) {
3038 const [models, setModels] = useState<Array<{ name: string; model: string }>>([]);
3139 const [isLoadingModels, setIsLoadingModels] = useState(false);
@@ -33,6 +41,7 @@ export default function ThreadSettingsModal({
3341 const [maxPromptLength, setMaxPromptLength] = useState<"none" | 1024 | 4096 | null>("none");
3442 const [isSaving, setIsSaving] = useState(false);
3543 const [isDeleting, setIsDeleting] = useState(false);
44+ const isNewThread = thread === null;
3645
3746 // Load models when modal opens
3847 useEffect(() => {
@@ -64,18 +73,34 @@ export default function ThreadSettingsModal({
6473 }
6574 }, [isOpen, onError]);
6675
67- // Load thread settings when thread changes
76+ // Load thread settings when thread changes or when modal opens for new thread
6877 useEffect(() => {
6978 if (thread) {
7079 setSelectedModel(thread.model || "gpt-oss");
7180 setMaxPromptLength(
7281 thread.maxPromptLength === null ? "none" : (thread.maxPromptLength as 1024 | 4096)
7382 );
83+ } else if (isOpen && isNewThread) {
84+ // For new thread, use initial values or defaults
85+ setSelectedModel(initialModel || "gpt-oss");
86+ setMaxPromptLength(initialMaxPromptLength || "none");
7487 }
75- }, [thread]);
88+ }, [thread, isOpen, isNewThread, initialModel, initialMaxPromptLength]);
7689
7790 const handleSave = async () => {
78- if (!thread) return;
91+ if (isNewThread) {
92+ // For new thread, just update the parent's state
93+ if (onModelChange) {
94+ onModelChange(selectedModel);
95+ }
96+ if (onMaxPromptLengthChange && maxPromptLength !== null) {
97+ onMaxPromptLengthChange(maxPromptLength === "none" ? "none" : maxPromptLength);
98+ }
99+ onClose();
100+ return;
101+ }
102+
103+ if (!thread || !onUpdateThread) return;
79104
80105 const hasChanges =
81106 selectedModel !== (thread.model || "gpt-oss") ||
@@ -105,7 +130,7 @@ export default function ThreadSettingsModal({
105130 };
106131
107132 const handleDelete = async () => {
108- if (!thread) return;
133+ if (!thread || !onDeleteThread) return;
109134
110135 setIsDeleting(true);
111136 try {
@@ -120,17 +145,17 @@ export default function ThreadSettingsModal({
120145 }
121146 };
122147
123- if (!thread) {
124- return null;
125- }
126-
127- const threadTitle = thread.title || `Thread ${thread.id}`;
148+ const threadTitle = thread ? (thread.title || `Thread ${thread.id}`) : null;
128149
129150 return (
130151 <Modal isOpen={isOpen} onClose={onClose}>
131152 <div className="flex flex-col gap-4">
132- <h2 className="text-xl font-semibold">Thread Settings</h2>
133- <p className="text-sm text-neutral-600 dark:text-neutral-400">{threadTitle}</p>
153+ <h2 className="text-xl font-semibold">
154+ {isNewThread ? "New Thread Settings" : "Thread Settings"}
155+ </h2>
156+ {threadTitle && (
157+ <p className="text-sm text-neutral-600 dark:text-neutral-400">{threadTitle}</p>
158+ )}
134159
135160 <div className="flex flex-col gap-4">
136161 <div className="flex flex-col gap-2">
@@ -141,7 +166,7 @@ export default function ThreadSettingsModal({
141166 value={selectedModel}
142167 onChange={(e) => setSelectedModel(e.target.value)}
143168 disabled={isLoadingModels}
144- 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"
169+ className="bg-white px-3 py-2 text-neutral-800 focus:outline-none disabled:opacity-50 dark:bg-neutral-950 dark:text-neutral-200"
145170 >
146171 {isLoadingModels ? (
147172 <option>Loading models...</option>
@@ -168,7 +193,7 @@ export default function ThreadSettingsModal({
168193 e.target.value === "none" ? "none" : (parseInt(e.target.value, 10) as 1024 | 4096)
169194 )
170195 }
171- className="bg-neutral-100 px-3 py-2 text-neutral-800 focus:outline-none dark:bg-neutral-900 dark:text-neutral-200"
196+ className="bg-white px-3 py-2 text-neutral-800 focus:outline-none dark:bg-neutral-950 dark:text-neutral-200"
172197 >
173198 <option value="none">None</option>
174199 <option value="1024">1024</option>
@@ -178,28 +203,32 @@ export default function ThreadSettingsModal({
178203 </div>
179204
180205 <div className="flex justify-between gap-2 border-t border-neutral-300 pt-4 dark:border-neutral-700">
181- <SecondaryButton
182- onClick={(e) => {
183- e.preventDefault();
184- if (!isDeleting && !isSaving) {
185- handleDelete();
186- }
187- }}
188- className={isDeleting || isSaving ? "cursor-not-allowed opacity-50" : ""}
189- >
190- <TrashIcon className="h-4 w-4" />
191- {isDeleting ? "Deleting..." : "Delete Thread"}
192- </SecondaryButton>
206+ {!isNewThread && onDeleteThread && (
207+ <SecondaryButton
208+ onClick={(e) => {
209+ e.preventDefault();
210+ if (!isDeleting && !isSaving) {
211+ handleDelete();
212+ }
213+ }}
214+ className={isDeleting || isSaving ? "cursor-not-allowed opacity-50" : ""}
215+ >
216+ <TrashIcon className="h-4 w-4" />
217+ {isDeleting ? "Deleting..." : "Delete Thread"}
218+ </SecondaryButton>
219+ )}
220+ {isNewThread && <div />}
193221 <div className="flex gap-2">
194- <PrimaryButton
222+ <SecondaryButton
195223 onClick={(e) => {
196224 e.preventDefault();
197225 handleSave();
198226 }}
199227 disabled={isSaving || isDeleting}
228+ color="neutral"
200229 >
201230 {isSaving ? "Saving..." : "Save"}
202- </PrimaryButton>
231+ </SecondaryButton>
203232 </div>
204233 </div>
205234 </div>