fix(webui): preserve hero model preset on chat creation
This commit is contained in:
1 parent
b04aeeac0e
commit
3d40ed8f76
5 files changed
+43
-7
No files matched your search
+8
-2
@@ -1477,10 +1477,14 @@ function Shell({
|
|||||||
[activeChatId, activeChatRunning, activeKey, client, temporaryChatActive],
|
[activeChatId, activeChatRunning, activeKey, client, temporaryChatActive],
|
||||||
);
|
);
|
||||||
|
|
||||||
const onCreateChat = useCallback(async (workspaceScope?: WorkspaceScopePayload | null) => {
|
const onCreateChat = useCallback(async (
|
||||||
|
workspaceScope?: WorkspaceScopePayload | null,
|
||||||
|
_initialMessage?: string,
|
||||||
|
modelPreset?: string | null,
|
||||||
|
) => {
|
||||||
try {
|
try {
|
||||||
const scope = workspaceScope ?? activeWorkspaceScope;
|
const scope = workspaceScope ?? activeWorkspaceScope;
|
||||||
const chatId = await createChat(scope);
|
const chatId = await createChat(scope, modelPreset);
|
||||||
const key = `websocket:${chatId}`;
|
const key = `websocket:${chatId}`;
|
||||||
pendingCreatedSessionKeyRef.current = key;
|
pendingCreatedSessionKeyRef.current = key;
|
||||||
navigate({
|
navigate({
|
||||||
@@ -1509,6 +1513,7 @@ function Shell({
|
|||||||
async (
|
async (
|
||||||
workspaceScope?: WorkspaceScopePayload | null,
|
workspaceScope?: WorkspaceScopePayload | null,
|
||||||
initialMessage?: string,
|
initialMessage?: string,
|
||||||
|
modelPreset?: string | null,
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
const chatId = await client.newTemporaryChat();
|
const chatId = await client.newTemporaryChat();
|
||||||
@@ -1519,6 +1524,7 @@ function Shell({
|
|||||||
const nextSession: ChatSummary = {
|
const nextSession: ChatSummary = {
|
||||||
...session,
|
...session,
|
||||||
preview: initialMessage ?? "",
|
preview: initialMessage ?? "",
|
||||||
|
modelPreset: modelPreset ?? null,
|
||||||
...(restrictedScope ? { workspaceScope: restrictedScope } : {}),
|
...(restrictedScope ? { workspaceScope: restrictedScope } : {}),
|
||||||
};
|
};
|
||||||
setTemporarySessions((current) => ({
|
setTemporarySessions((current) => ({
|
||||||
|
|||||||
@@ -336,6 +336,7 @@ interface ThreadShellProps {
|
|||||||
onCreateChat?: (
|
onCreateChat?: (
|
||||||
workspaceScope?: WorkspaceScopePayload | null,
|
workspaceScope?: WorkspaceScopePayload | null,
|
||||||
initialMessage?: string,
|
initialMessage?: string,
|
||||||
|
modelPreset?: string | null,
|
||||||
) => Promise<string | null>;
|
) => Promise<string | null>;
|
||||||
onForkChat?: (sourceChatId: string, beforeUserIndex: number) => Promise<string | null>;
|
onForkChat?: (sourceChatId: string, beforeUserIndex: number) => Promise<string | null>;
|
||||||
onTurnEnd?: () => void;
|
onTurnEnd?: () => void;
|
||||||
@@ -1348,7 +1349,7 @@ export function ThreadShell({
|
|||||||
setBooting(true);
|
setBooting(true);
|
||||||
pendingFirstRef.current = { content, images, options: withWorkspaceScope(options) };
|
pendingFirstRef.current = { content, images, options: withWorkspaceScope(options) };
|
||||||
setPendingFirstTargetChatId(null);
|
setPendingFirstTargetChatId(null);
|
||||||
const newId = await onCreateChat?.(workspaceScope, content);
|
const newId = await onCreateChat?.(workspaceScope, content, localModelPreset);
|
||||||
if (!newId) {
|
if (!newId) {
|
||||||
pendingFirstRef.current = null;
|
pendingFirstRef.current = null;
|
||||||
setPendingFirstTargetChatId(null);
|
setPendingFirstTargetChatId(null);
|
||||||
|
|||||||
@@ -127,7 +127,10 @@ export function useSessions(): {
|
|||||||
loading: boolean;
|
loading: boolean;
|
||||||
error: string | null;
|
error: string | null;
|
||||||
refresh: () => Promise<void>;
|
refresh: () => Promise<void>;
|
||||||
createChat: (workspaceScope?: WorkspaceScopePayload | null) => Promise<string>;
|
createChat: (
|
||||||
|
workspaceScope?: WorkspaceScopePayload | null,
|
||||||
|
modelPreset?: string | null,
|
||||||
|
) => Promise<string>;
|
||||||
forkChat: (sourceChatId: string, beforeUserIndex: number, title?: string) => Promise<string>;
|
forkChat: (sourceChatId: string, beforeUserIndex: number, title?: string) => Promise<string>;
|
||||||
deleteChat: (
|
deleteChat: (
|
||||||
key: string,
|
key: string,
|
||||||
@@ -204,7 +207,10 @@ export function useSessions(): {
|
|||||||
};
|
};
|
||||||
}, [client, refresh]);
|
}, [client, refresh]);
|
||||||
|
|
||||||
const createChat = useCallback(async (workspaceScope?: WorkspaceScopePayload | null): Promise<string> => {
|
const createChat = useCallback(async (
|
||||||
|
workspaceScope?: WorkspaceScopePayload | null,
|
||||||
|
modelPreset?: string | null,
|
||||||
|
): Promise<string> => {
|
||||||
const chatId = await client.newChat(CHAT_CREATE_TIMEOUT_MS, workspaceScope);
|
const chatId = await client.newChat(CHAT_CREATE_TIMEOUT_MS, workspaceScope);
|
||||||
const key = `websocket:${chatId}`;
|
const key = `websocket:${chatId}`;
|
||||||
optimisticKeysRef.current.add(key);
|
optimisticKeysRef.current.add(key);
|
||||||
@@ -219,6 +225,7 @@ export function useSessions(): {
|
|||||||
updatedAt: new Date().toISOString(),
|
updatedAt: new Date().toISOString(),
|
||||||
title: "",
|
title: "",
|
||||||
preview: "",
|
preview: "",
|
||||||
|
modelPreset: modelPreset ?? null,
|
||||||
workspaceScope: workspaceScope ?? null,
|
workspaceScope: workspaceScope ?? null,
|
||||||
},
|
},
|
||||||
...prev.filter((s) => s.key !== key),
|
...prev.filter((s) => s.key !== key),
|
||||||
|
|||||||
@@ -1162,7 +1162,7 @@ describe("ThreadShell", () => {
|
|||||||
fireEvent.click(screen.getByRole("button", { name: "Send message" }));
|
fireEvent.click(screen.getByRole("button", { name: "Send message" }));
|
||||||
|
|
||||||
await waitFor(() => expect(onCreateChat).toHaveBeenCalledTimes(1));
|
await waitFor(() => expect(onCreateChat).toHaveBeenCalledTimes(1));
|
||||||
expect(onCreateChat).toHaveBeenCalledWith(null, "start for real");
|
expect(onCreateChat).toHaveBeenCalledWith(null, "start for real", null);
|
||||||
expect(onNewChat).not.toHaveBeenCalled();
|
expect(onNewChat).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1203,8 +1203,13 @@ describe("ThreadShell", () => {
|
|||||||
"chat-new",
|
"chat-new",
|
||||||
"/model fast",
|
"/model fast",
|
||||||
));
|
));
|
||||||
|
expect(onCreateChat).toHaveBeenCalledWith(null, "use the selected model", "fast");
|
||||||
|
|
||||||
rerender(view(session("chat-new")));
|
await act(async () => {
|
||||||
|
rerender(view(session("chat-new", "fast")));
|
||||||
|
});
|
||||||
|
expect(screen.getByTitle("fast · gpt-5.5 · OpenAI Codex")).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText("Default")).not.toBeInTheDocument();
|
||||||
expect(client.sendMessage).not.toHaveBeenCalled();
|
expect(client.sendMessage).not.toHaveBeenCalled();
|
||||||
|
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
|
|||||||
@@ -390,6 +390,23 @@ describe("useSessions", () => {
|
|||||||
expect(result.current.sessions[0]?.workspaceScope).toEqual(workspaceScope);
|
expect(result.current.sessions[0]?.workspaceScope).toEqual(workspaceScope);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("stores an optimistic model preset when creating a chat", async () => {
|
||||||
|
vi.mocked(api.listSessions).mockResolvedValue([]);
|
||||||
|
const client = fakeClient();
|
||||||
|
client.newChat.mockResolvedValue("chat-fast");
|
||||||
|
|
||||||
|
const { result } = renderHook(() => useSessions(), {
|
||||||
|
wrapper: wrap(client),
|
||||||
|
});
|
||||||
|
|
||||||
|
await waitFor(() => expect(result.current.loading).toBe(false));
|
||||||
|
await act(async () => {
|
||||||
|
await result.current.createChat(null, "fast");
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.current.sessions[0]?.modelPreset).toBe("fast");
|
||||||
|
});
|
||||||
|
|
||||||
it("passes through WebUI transcript user media as images and media", async () => {
|
it("passes through WebUI transcript user media as images and media", async () => {
|
||||||
vi.mocked(api.fetchWebuiThread).mockResolvedValue({
|
vi.mocked(api.fetchWebuiThread).mockResolvedValue({
|
||||||
schemaVersion: 3,
|
schemaVersion: 3,
|
||||||
|
|||||||
Reference in new issue
Block a user