model picker
This commit is contained in:
12 files changed
+522
-19
No files matched your search
@@ -0,0 +1,10 @@
|
||||
- [ ] Folder picker for new projects
|
||||
- [ ] Projects should be persisted so they're still visible after closing
|
||||
- [ ] Remove model selection from project creation
|
||||
- [ ] First message vanishes when thread is created?? Awful ux
|
||||
- [ ] Show more clearly when thinking is happening
|
||||
|
||||
## Bigger overhauls
|
||||
|
||||
- [ ] Markdown rendering
|
||||
- [ ] Code block rendering
|
||||
@@ -5,6 +5,7 @@ import readline from "node:readline";
|
||||
|
||||
import type {
|
||||
ProviderEvent,
|
||||
ProviderModel,
|
||||
ProviderSendTurnInput,
|
||||
ProviderSession,
|
||||
ProviderSessionStartInput,
|
||||
@@ -197,7 +198,11 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
|
||||
throw new Error("Session is missing a thread id.");
|
||||
}
|
||||
|
||||
const response = await this.sendRequest(context, "turn/start", {
|
||||
const turnStartParams: {
|
||||
threadId: string;
|
||||
input: Array<{ type: "text"; text: string; text_elements: [] }>;
|
||||
model?: string;
|
||||
} = {
|
||||
threadId: context.session.threadId,
|
||||
input: [
|
||||
{
|
||||
@@ -206,7 +211,16 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
|
||||
text_elements: [],
|
||||
},
|
||||
],
|
||||
});
|
||||
};
|
||||
if (input.model) {
|
||||
turnStartParams.model = input.model;
|
||||
}
|
||||
|
||||
const response = await this.sendRequest(
|
||||
context,
|
||||
"turn/start",
|
||||
turnStartParams,
|
||||
);
|
||||
|
||||
const turn = this.readObject(this.readObject(response), "turn");
|
||||
const turnId = this.readString(turn, "id");
|
||||
@@ -225,6 +239,177 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
|
||||
};
|
||||
}
|
||||
|
||||
async listModels(cwd?: string): Promise<ProviderModel[]> {
|
||||
const child = spawn("codex", ["app-server"], {
|
||||
cwd,
|
||||
env: process.env,
|
||||
stdio: ["pipe", "pipe", "pipe"],
|
||||
});
|
||||
const output = readline.createInterface({ input: child.stdout });
|
||||
const pending = new Map<PendingRequestKey, PendingRequest>();
|
||||
let nextRequestId = 1;
|
||||
let exited = false;
|
||||
let exitError: Error | null = null;
|
||||
|
||||
const cleanup = () => {
|
||||
for (const request of pending.values()) {
|
||||
clearTimeout(request.timeout);
|
||||
}
|
||||
pending.clear();
|
||||
output.close();
|
||||
if (!child.killed) {
|
||||
child.kill();
|
||||
}
|
||||
};
|
||||
|
||||
const writeMessage = (message: unknown) => {
|
||||
if (!child.stdin.writable) {
|
||||
throw new Error("Cannot write to codex app-server stdin.");
|
||||
}
|
||||
child.stdin.write(`${JSON.stringify(message)}\n`);
|
||||
};
|
||||
|
||||
const sendRequest = async <TResponse>(
|
||||
method: string,
|
||||
params: unknown,
|
||||
timeoutMs = 20_000,
|
||||
): Promise<TResponse> => {
|
||||
if (exited) {
|
||||
throw (
|
||||
exitError ??
|
||||
new Error("codex app-server exited before request could be sent.")
|
||||
);
|
||||
}
|
||||
|
||||
const id = nextRequestId;
|
||||
nextRequestId += 1;
|
||||
|
||||
const result = await new Promise<unknown>((resolve, reject) => {
|
||||
const timeout = setTimeout(() => {
|
||||
pending.delete(String(id));
|
||||
reject(new Error(`Timed out waiting for ${method}.`));
|
||||
}, timeoutMs);
|
||||
|
||||
pending.set(String(id), {
|
||||
timeout,
|
||||
resolve,
|
||||
reject,
|
||||
method,
|
||||
});
|
||||
writeMessage({ id, method, params });
|
||||
});
|
||||
|
||||
return result as TResponse;
|
||||
};
|
||||
|
||||
output.on("line", (line) => {
|
||||
let parsed: unknown;
|
||||
try {
|
||||
parsed = JSON.parse(line);
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.isResponse(parsed)) {
|
||||
const key = String(parsed.id);
|
||||
const request = pending.get(key);
|
||||
if (!request) {
|
||||
return;
|
||||
}
|
||||
|
||||
clearTimeout(request.timeout);
|
||||
pending.delete(key);
|
||||
|
||||
if (parsed.error?.message) {
|
||||
request.reject(
|
||||
new Error(
|
||||
`${request.method} failed: ${String(parsed.error.message)}`,
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
request.resolve(parsed.result);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.isServerRequest(parsed)) {
|
||||
writeMessage({
|
||||
id: parsed.id,
|
||||
error: {
|
||||
code: -32601,
|
||||
message: `Unsupported server request: ${parsed.method}`,
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
child.on("error", (error) => {
|
||||
exited = true;
|
||||
exitError = error;
|
||||
for (const request of pending.values()) {
|
||||
clearTimeout(request.timeout);
|
||||
request.reject(error);
|
||||
}
|
||||
pending.clear();
|
||||
});
|
||||
|
||||
child.on("exit", (code, signal) => {
|
||||
exited = true;
|
||||
if (!exitError && code !== 0) {
|
||||
exitError = new Error(
|
||||
`codex app-server exited (code=${code ?? "null"}, signal=${signal ?? "null"}).`,
|
||||
);
|
||||
}
|
||||
for (const request of pending.values()) {
|
||||
clearTimeout(request.timeout);
|
||||
request.reject(
|
||||
exitError ??
|
||||
new Error("codex app-server exited before request completed."),
|
||||
);
|
||||
}
|
||||
pending.clear();
|
||||
});
|
||||
|
||||
try {
|
||||
await sendRequest("initialize", {
|
||||
clientInfo: {
|
||||
name: "codething_desktop",
|
||||
title: "CodeThing Desktop",
|
||||
version: "0.1.0",
|
||||
},
|
||||
capabilities: {
|
||||
experimentalApi: false,
|
||||
},
|
||||
});
|
||||
|
||||
writeMessage({ method: "initialized" });
|
||||
|
||||
const deduped = new Map<string, ProviderModel>();
|
||||
let cursor: string | null = null;
|
||||
|
||||
while (true) {
|
||||
const response = await sendRequest<unknown>("model/list", {
|
||||
cursor,
|
||||
limit: 100,
|
||||
});
|
||||
const parsed = this.parseModelListResponse(response);
|
||||
for (const model of parsed.models) {
|
||||
deduped.set(model.model, model);
|
||||
}
|
||||
|
||||
if (!parsed.nextCursor) {
|
||||
break;
|
||||
}
|
||||
cursor = parsed.nextCursor;
|
||||
}
|
||||
|
||||
return Array.from(deduped.values());
|
||||
} finally {
|
||||
cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
async interruptTurn(sessionId: string, turnId?: string): Promise<void> {
|
||||
const context = this.requireSession(sessionId);
|
||||
const effectiveTurnId = turnId ?? context.session.activeTurnId;
|
||||
@@ -622,6 +807,66 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
|
||||
};
|
||||
}
|
||||
|
||||
private parseModelListResponse(response: unknown): {
|
||||
models: ProviderModel[];
|
||||
nextCursor: string | null;
|
||||
} {
|
||||
const object = this.readObject(response);
|
||||
if (!object) {
|
||||
throw new Error("model/list response was not an object.");
|
||||
}
|
||||
|
||||
const data = object.data;
|
||||
if (!Array.isArray(data)) {
|
||||
throw new Error("model/list response missing data array.");
|
||||
}
|
||||
|
||||
const models: ProviderModel[] = [];
|
||||
for (const entry of data) {
|
||||
const item = this.readObject(entry);
|
||||
if (!item) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const model = this.readString(item, "model");
|
||||
if (!model) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const id = this.readString(item, "id") ?? model;
|
||||
const displayName = this.readString(item, "displayName") ?? model;
|
||||
const description = this.readString(item, "description");
|
||||
const isDefault =
|
||||
typeof item.isDefault === "boolean" ? item.isDefault : undefined;
|
||||
const rawUpgrade = item.upgrade;
|
||||
const upgrade =
|
||||
typeof rawUpgrade === "string"
|
||||
? rawUpgrade
|
||||
: rawUpgrade === null
|
||||
? null
|
||||
: undefined;
|
||||
|
||||
models.push({
|
||||
id,
|
||||
model,
|
||||
displayName,
|
||||
...(description ? { description } : {}),
|
||||
...(isDefault === undefined ? {} : { isDefault }),
|
||||
...(upgrade === undefined ? {} : { upgrade }),
|
||||
});
|
||||
}
|
||||
|
||||
const rawCursor = object.nextCursor;
|
||||
const nextCursor =
|
||||
typeof rawCursor === "string"
|
||||
? rawCursor
|
||||
: rawCursor === null || rawCursor === undefined
|
||||
? null
|
||||
: null;
|
||||
|
||||
return { models, nextCursor };
|
||||
}
|
||||
|
||||
private isServerRequest(value: unknown): value is JsonRpcRequest {
|
||||
if (!value || typeof value !== "object") {
|
||||
return false;
|
||||
|
||||
@@ -139,6 +139,15 @@ function registerIpcHandlers(): void {
|
||||
ipcMain.handle(IPC_CHANNELS.providerSessionList, async () => {
|
||||
return providerManager.listSessions();
|
||||
});
|
||||
|
||||
ipcMain.handle(
|
||||
IPC_CHANNELS.providerModelList,
|
||||
async (_event, payload: unknown) => {
|
||||
return providerManager.listModels(
|
||||
payload as Parameters<typeof providerManager.listModels>[0],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
async function runTerminalCommand(
|
||||
|
||||
@@ -41,6 +41,8 @@ const nativeApi: NativeApi = {
|
||||
stopSession: (input) =>
|
||||
ipcRenderer.invoke(IPC_CHANNELS.providerSessionStop, input),
|
||||
listSessions: () => ipcRenderer.invoke(IPC_CHANNELS.providerSessionList),
|
||||
listModels: (input) =>
|
||||
ipcRenderer.invoke(IPC_CHANNELS.providerModelList, input),
|
||||
onEvent: (callback) => {
|
||||
const listener = (_event: Electron.IpcRendererEvent, payload: unknown) =>
|
||||
callback(payload as Parameters<typeof callback>[0]);
|
||||
|
||||
@@ -3,12 +3,15 @@ import { EventEmitter } from "node:events";
|
||||
import {
|
||||
type ProviderEvent,
|
||||
type ProviderInterruptTurnInput,
|
||||
type ProviderListModelsInput,
|
||||
type ProviderModel,
|
||||
type ProviderSendTurnInput,
|
||||
type ProviderSession,
|
||||
type ProviderSessionStartInput,
|
||||
type ProviderStopSessionInput,
|
||||
type ProviderTurnStartResult,
|
||||
providerInterruptTurnInputSchema,
|
||||
providerListModelsInputSchema,
|
||||
providerSendTurnInputSchema,
|
||||
providerSessionStartInputSchema,
|
||||
providerStopSessionInputSchema,
|
||||
@@ -63,6 +66,17 @@ export class ProviderManager extends EventEmitter<ProviderManagerEvents> {
|
||||
return this.codex.listSessions();
|
||||
}
|
||||
|
||||
async listModels(
|
||||
raw: ProviderListModelsInput = {},
|
||||
): Promise<ProviderModel[]> {
|
||||
const input = providerListModelsInputSchema.parse(raw);
|
||||
if (input.provider !== "codex") {
|
||||
throw new Error(`Provider '${input.provider}' is not implemented yet.`);
|
||||
}
|
||||
|
||||
return this.codex.listModels(input.cwd);
|
||||
}
|
||||
|
||||
stopAll(): void {
|
||||
this.codex.stopAll();
|
||||
}
|
||||
|
||||
@@ -1,22 +1,54 @@
|
||||
import { type FormEvent, useEffect, useMemo, useRef, useState } from "react";
|
||||
import type { ProviderModel } from "@acme/contracts";
|
||||
import {
|
||||
type FormEvent,
|
||||
type KeyboardEvent,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
|
||||
import { derivePhase, formatTimestamp, readNativeApi } from "../session-logic";
|
||||
import { useStore } from "../store";
|
||||
|
||||
const DEFAULT_MODEL = "gpt-5.2-codex";
|
||||
|
||||
export default function ChatView() {
|
||||
const { state, dispatch } = useStore();
|
||||
const api = useMemo(() => readNativeApi(), []);
|
||||
const [prompt, setPrompt] = useState("");
|
||||
const [isSending, setIsSending] = useState(false);
|
||||
const [isConnecting, setIsConnecting] = useState(false);
|
||||
const [isModelMenuOpen, setIsModelMenuOpen] = useState(false);
|
||||
const [isLoadingModels, setIsLoadingModels] = useState(false);
|
||||
const [modelLoadError, setModelLoadError] = useState<string | null>(null);
|
||||
const [availableModels, setAvailableModels] = useState<ProviderModel[]>([]);
|
||||
const messagesEndRef = useRef<HTMLDivElement>(null);
|
||||
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
||||
const modelMenuRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const activeThread = state.threads.find((t) => t.id === state.activeThreadId);
|
||||
const activeProject = state.projects.find(
|
||||
(p) => p.id === activeThread?.projectId,
|
||||
);
|
||||
const selectedModel =
|
||||
activeThread?.model || activeProject?.model || DEFAULT_MODEL;
|
||||
const phase = derivePhase(activeThread?.session ?? null);
|
||||
const modelOptions = useMemo(() => {
|
||||
const deduped = new Map<string, ProviderModel>();
|
||||
for (const model of availableModels) {
|
||||
deduped.set(model.model, model);
|
||||
}
|
||||
if (!deduped.has(selectedModel)) {
|
||||
deduped.set(selectedModel, {
|
||||
id: selectedModel,
|
||||
model: selectedModel,
|
||||
displayName: selectedModel,
|
||||
description: "Current model for this thread.",
|
||||
});
|
||||
}
|
||||
return Array.from(deduped.values());
|
||||
}, [availableModels, selectedModel]);
|
||||
|
||||
// Auto-scroll on new messages
|
||||
const messageCount = activeThread?.messages.length ?? 0;
|
||||
@@ -34,6 +66,67 @@ export default function ChatView() {
|
||||
ta.style.height = `${Math.min(ta.scrollHeight, 200)}px`;
|
||||
}, [prompt]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isModelMenuOpen) return;
|
||||
|
||||
const handleClickOutside = (event: MouseEvent) => {
|
||||
if (!modelMenuRef.current) return;
|
||||
if (
|
||||
event.target instanceof Node &&
|
||||
!modelMenuRef.current.contains(event.target)
|
||||
) {
|
||||
setIsModelMenuOpen(false);
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener("mousedown", handleClickOutside);
|
||||
return () => {
|
||||
window.removeEventListener("mousedown", handleClickOutside);
|
||||
};
|
||||
}, [isModelMenuOpen]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!api || !state.activeThreadId) return;
|
||||
|
||||
let cancelled = false;
|
||||
|
||||
const loadModels = async () => {
|
||||
setIsLoadingModels(true);
|
||||
setModelLoadError(null);
|
||||
try {
|
||||
const models = await api.providers.listModels(
|
||||
activeProject?.cwd ? { cwd: activeProject.cwd } : undefined,
|
||||
);
|
||||
if (cancelled) return;
|
||||
|
||||
const sorted = [...models].sort((a, b) => {
|
||||
if ((a.isDefault ?? false) && !(b.isDefault ?? false)) return -1;
|
||||
if ((b.isDefault ?? false) && !(a.isDefault ?? false)) return 1;
|
||||
return a.displayName.localeCompare(b.displayName);
|
||||
});
|
||||
setAvailableModels(sorted);
|
||||
} catch (err) {
|
||||
if (cancelled) return;
|
||||
setAvailableModels([]);
|
||||
setModelLoadError(
|
||||
err instanceof Error
|
||||
? err.message
|
||||
: "Could not load available models from Codex.",
|
||||
);
|
||||
} finally {
|
||||
if (!cancelled) {
|
||||
setIsLoadingModels(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void loadModels();
|
||||
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [api, activeProject?.cwd, state.activeThreadId]);
|
||||
|
||||
const ensureSession = async (): Promise<boolean> => {
|
||||
if (!api || !activeThread || !activeProject) return false;
|
||||
if (activeThread.session && activeThread.session.status !== "closed")
|
||||
@@ -44,7 +137,7 @@ export default function ChatView() {
|
||||
const session = await api.providers.startSession({
|
||||
provider: "codex",
|
||||
cwd: activeProject.cwd || undefined,
|
||||
model: activeProject.model || undefined,
|
||||
model: selectedModel || undefined,
|
||||
});
|
||||
dispatch({
|
||||
type: "UPDATE_SESSION",
|
||||
@@ -105,7 +198,11 @@ export default function ChatView() {
|
||||
|
||||
setIsSending(true);
|
||||
try {
|
||||
await api.providers.sendTurn({ sessionId, input: trimmed });
|
||||
await api.providers.sendTurn({
|
||||
sessionId,
|
||||
input: trimmed,
|
||||
model: selectedModel || undefined,
|
||||
});
|
||||
} catch (err) {
|
||||
dispatch({
|
||||
type: "SET_ERROR",
|
||||
@@ -125,7 +222,17 @@ export default function ChatView() {
|
||||
});
|
||||
};
|
||||
|
||||
const onKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
||||
const onModelSelect = (model: string) => {
|
||||
if (!activeThread) return;
|
||||
dispatch({
|
||||
type: "SET_THREAD_MODEL",
|
||||
threadId: activeThread.id,
|
||||
model,
|
||||
});
|
||||
setIsModelMenuOpen(false);
|
||||
};
|
||||
|
||||
const onKeyDown = (e: KeyboardEvent<HTMLTextAreaElement>) => {
|
||||
if (e.key === "Enter" && !e.shiftKey) {
|
||||
e.preventDefault();
|
||||
void onSend(e as unknown as FormEvent);
|
||||
@@ -255,10 +362,10 @@ export default function ChatView() {
|
||||
onSubmit={onSend}
|
||||
className="mx-auto flex max-w-3xl items-end gap-2"
|
||||
>
|
||||
<div className="relative flex-1">
|
||||
<div className="flex-1 rounded-2xl border border-white/[0.1] bg-[#121214] px-3 py-3">
|
||||
<textarea
|
||||
ref={textareaRef}
|
||||
className="w-full resize-none rounded-xl border border-white/[0.1] bg-white/[0.04] px-4 py-3 pr-12 font-mono text-sm text-[#e0e0e0] placeholder:text-[#a0a0a0]/30 focus:border-white/20 focus:outline-none"
|
||||
className="w-full resize-none bg-transparent px-1 pb-1 font-mono text-sm text-[#e0e0e0] placeholder:text-[#a0a0a0]/30 focus:outline-none"
|
||||
rows={1}
|
||||
value={prompt}
|
||||
onChange={(e) => setPrompt(e.target.value)}
|
||||
@@ -270,11 +377,78 @@ export default function ChatView() {
|
||||
}
|
||||
disabled={isSending || isConnecting}
|
||||
/>
|
||||
{activeProject && (
|
||||
<span className="absolute right-3 bottom-2 text-[9px] text-[#a0a0a0]/25">
|
||||
{activeProject.model}
|
||||
</span>
|
||||
)}
|
||||
<div className="mt-2 flex items-center justify-between gap-2">
|
||||
<div className="relative" ref={modelMenuRef}>
|
||||
<button
|
||||
type="button"
|
||||
className="inline-flex items-center gap-2 rounded-full border border-white/[0.1] bg-white/[0.04] px-3 py-1.5 text-xs text-[#d8d8d8] transition-colors duration-150 hover:bg-white/[0.08]"
|
||||
onClick={() => setIsModelMenuOpen((open) => !open)}
|
||||
>
|
||||
<span className="max-w-[180px] truncate">
|
||||
{selectedModel}
|
||||
</span>
|
||||
<span className="text-[10px] text-[#a0a0a0]/70">▼</span>
|
||||
</button>
|
||||
{isModelMenuOpen && (
|
||||
<div className="absolute bottom-full left-0 z-20 mb-2 w-[340px] rounded-2xl border border-white/[0.1] bg-[#1b1b1d]/95 p-2 shadow-[0_16px_40px_rgba(0,0,0,0.55)] backdrop-blur">
|
||||
<p className="px-2 py-1 text-[11px] text-[#a0a0a0]/70">
|
||||
Select model
|
||||
</p>
|
||||
<div className="max-h-72 overflow-y-auto">
|
||||
{modelOptions.map((model) => {
|
||||
const isSelected = model.model === selectedModel;
|
||||
return (
|
||||
<button
|
||||
key={model.id}
|
||||
type="button"
|
||||
className={`mb-0.5 flex w-full items-start justify-between gap-2 rounded-xl px-2 py-2 text-left transition-colors duration-150 ${
|
||||
isSelected
|
||||
? "bg-white/[0.08] text-white"
|
||||
: "text-[#d4d4d4] hover:bg-white/[0.05]"
|
||||
}`}
|
||||
onClick={() => onModelSelect(model.model)}
|
||||
>
|
||||
<span className="min-w-0">
|
||||
<span className="block truncate text-sm">
|
||||
{model.displayName}
|
||||
</span>
|
||||
{model.description && (
|
||||
<span className="block pt-0.5 text-[10px] text-[#a0a0a0]/65">
|
||||
{model.description}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
<span
|
||||
className={`pt-0.5 text-sm ${
|
||||
isSelected ? "text-white" : "text-transparent"
|
||||
}`}
|
||||
>
|
||||
✓
|
||||
</span>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
{isLoadingModels && (
|
||||
<p className="px-2 pt-2 text-[10px] text-[#a0a0a0]/60">
|
||||
Refreshing available models...
|
||||
</p>
|
||||
)}
|
||||
{modelLoadError && (
|
||||
<p className="px-2 pt-2 text-[10px] text-amber-200/80">
|
||||
Could not load full model list from Codex:{" "}
|
||||
{modelLoadError}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{activeProject && (
|
||||
<span className="text-[10px] text-[#a0a0a0]/35">
|
||||
{activeProject.name}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{phase === "running" ? (
|
||||
<button
|
||||
|
||||
@@ -2,6 +2,8 @@ import { useState } from "react";
|
||||
import { useStore } from "../store";
|
||||
import type { Project } from "../types";
|
||||
|
||||
const DEFAULT_MODEL = "gpt-5.2-codex";
|
||||
|
||||
function formatRelativeTime(iso: string): string {
|
||||
const diff = Date.now() - new Date(iso).getTime();
|
||||
const minutes = Math.floor(diff / 60_000);
|
||||
@@ -16,7 +18,7 @@ export default function Sidebar() {
|
||||
const { state, dispatch } = useStore();
|
||||
const [addingProject, setAddingProject] = useState(false);
|
||||
const [newCwd, setNewCwd] = useState("");
|
||||
const [newModel, setNewModel] = useState("gpt-5.1-codex");
|
||||
const [newModel, setNewModel] = useState(DEFAULT_MODEL);
|
||||
|
||||
const handleAddProject = () => {
|
||||
const cwd = newCwd.trim();
|
||||
@@ -26,12 +28,12 @@ export default function Sidebar() {
|
||||
id: crypto.randomUUID(),
|
||||
name,
|
||||
cwd,
|
||||
model: newModel.trim() || "gpt-5.1-codex",
|
||||
model: newModel.trim() || DEFAULT_MODEL,
|
||||
expanded: true,
|
||||
};
|
||||
dispatch({ type: "ADD_PROJECT", project });
|
||||
setNewCwd("");
|
||||
setNewModel("gpt-5.1-codex");
|
||||
setNewModel(DEFAULT_MODEL);
|
||||
setAddingProject(false);
|
||||
};
|
||||
|
||||
@@ -42,6 +44,9 @@ export default function Sidebar() {
|
||||
id: crypto.randomUUID(),
|
||||
projectId,
|
||||
title: "New thread",
|
||||
model:
|
||||
state.projects.find((p) => p.id === projectId)?.model ??
|
||||
DEFAULT_MODEL,
|
||||
session: null,
|
||||
messages: [],
|
||||
events: [],
|
||||
@@ -183,7 +188,7 @@ export default function Sidebar() {
|
||||
/>
|
||||
<input
|
||||
className="mb-2 w-full rounded-md border border-white/[0.1] bg-white/[0.04] px-2 py-1.5 font-mono text-xs text-[#e0e0e0] placeholder:text-[#a0a0a0]/30 focus:border-white/30 focus:outline-none"
|
||||
placeholder="model (default: gpt-5.1-codex)"
|
||||
placeholder={`model (default: ${DEFAULT_MODEL})`}
|
||||
value={newModel}
|
||||
onChange={(e) => setNewModel(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
|
||||
@@ -27,7 +27,8 @@ type Action =
|
||||
| { type: "UPDATE_SESSION"; threadId: string; session: ProviderSession }
|
||||
| { type: "PUSH_USER_MESSAGE"; threadId: string; id: string; text: string }
|
||||
| { type: "SET_ERROR"; threadId: string; error: string | null }
|
||||
| { type: "SET_THREAD_TITLE"; threadId: string; title: string };
|
||||
| { type: "SET_THREAD_TITLE"; threadId: string; title: string }
|
||||
| { type: "SET_THREAD_MODEL"; threadId: string; model: string };
|
||||
|
||||
// ── State ────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -160,6 +161,15 @@ function reducer(state: AppState, action: Action): AppState {
|
||||
})),
|
||||
};
|
||||
|
||||
case "SET_THREAD_MODEL":
|
||||
return {
|
||||
...state,
|
||||
threads: updateThread(state.threads, action.threadId, (t) => ({
|
||||
...t,
|
||||
model: action.model,
|
||||
})),
|
||||
};
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ export interface Thread {
|
||||
id: string;
|
||||
projectId: string;
|
||||
title: string;
|
||||
model: string;
|
||||
session: ProviderSession | null;
|
||||
messages: ChatMessage[];
|
||||
events: ProviderEvent[];
|
||||
|
||||
@@ -2,6 +2,8 @@ import type { AgentConfig, AgentExit, OutputChunk } from "./agent";
|
||||
import type {
|
||||
ProviderEvent,
|
||||
ProviderInterruptTurnInput,
|
||||
ProviderListModelsInput,
|
||||
ProviderModel,
|
||||
ProviderSendTurnInput,
|
||||
ProviderSession,
|
||||
ProviderSessionStartInput,
|
||||
@@ -27,6 +29,7 @@ export const IPC_CHANNELS = {
|
||||
providerTurnInterrupt: "provider:turn:interrupt",
|
||||
providerSessionStop: "provider:session:stop",
|
||||
providerSessionList: "provider:session:list",
|
||||
providerModelList: "provider:model:list",
|
||||
providerEvent: "provider:event",
|
||||
} as const;
|
||||
|
||||
@@ -57,6 +60,7 @@ export interface NativeApi {
|
||||
interruptTurn: (input: ProviderInterruptTurnInput) => Promise<void>;
|
||||
stopSession: (input: ProviderStopSessionInput) => Promise<void>;
|
||||
listSessions: () => Promise<ProviderSession[]>;
|
||||
listModels: (input?: ProviderListModelsInput) => Promise<ProviderModel[]>;
|
||||
onEvent: (callback: (event: ProviderEvent) => void) => () => void;
|
||||
};
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
providerEventSchema,
|
||||
providerListModelsInputSchema,
|
||||
providerSendTurnInputSchema,
|
||||
providerSessionStartInputSchema,
|
||||
} from "./provider";
|
||||
@@ -16,12 +17,21 @@ describe("providerSessionStartInputSchema", () => {
|
||||
});
|
||||
|
||||
describe("providerSendTurnInputSchema", () => {
|
||||
it("trims input text", () => {
|
||||
it("trims input text and optional model", () => {
|
||||
const parsed = providerSendTurnInputSchema.parse({
|
||||
sessionId: "sess_1",
|
||||
input: " summarize this repo ",
|
||||
model: " gpt-5.2-codex ",
|
||||
});
|
||||
expect(parsed.input).toBe("summarize this repo");
|
||||
expect(parsed.model).toBe("gpt-5.2-codex");
|
||||
});
|
||||
});
|
||||
|
||||
describe("providerListModelsInputSchema", () => {
|
||||
it("defaults provider to codex", () => {
|
||||
const parsed = providerListModelsInputSchema.parse({});
|
||||
expect(parsed.provider).toBe("codex");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ export const providerSessionStartInputSchema = z.object({
|
||||
export const providerSendTurnInputSchema = z.object({
|
||||
sessionId: z.string().min(1),
|
||||
input: z.string().trim().min(1).max(120_000),
|
||||
model: z.string().trim().min(1).optional(),
|
||||
});
|
||||
|
||||
export const providerTurnStartResultSchema = z.object({
|
||||
@@ -63,6 +64,20 @@ export const providerStopSessionInputSchema = z.object({
|
||||
sessionId: z.string().min(1),
|
||||
});
|
||||
|
||||
export const providerModelSchema = z.object({
|
||||
id: z.string().min(1),
|
||||
model: z.string().min(1),
|
||||
displayName: z.string().min(1),
|
||||
description: z.string().min(1).optional(),
|
||||
isDefault: z.boolean().optional(),
|
||||
upgrade: z.string().min(1).nullable().optional(),
|
||||
});
|
||||
|
||||
export const providerListModelsInputSchema = z.object({
|
||||
provider: providerKindSchema.default("codex"),
|
||||
cwd: z.string().min(1).optional(),
|
||||
});
|
||||
|
||||
export const providerEventKindSchema = z.enum([
|
||||
"session",
|
||||
"notification",
|
||||
@@ -105,5 +120,9 @@ export type ProviderInterruptTurnInput = z.input<
|
||||
export type ProviderStopSessionInput = z.input<
|
||||
typeof providerStopSessionInputSchema
|
||||
>;
|
||||
export type ProviderModel = z.infer<typeof providerModelSchema>;
|
||||
export type ProviderListModelsInput = z.input<
|
||||
typeof providerListModelsInputSchema
|
||||
>;
|
||||
export type ProviderEventKind = z.infer<typeof providerEventKindSchema>;
|
||||
export type ProviderEvent = z.infer<typeof providerEventSchema>;
|
||||
Reference in new issue
Block a user