mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-06-15 15:24:06 +00:00
fix: allow slower webui chat creation
This commit is contained in:
parent
8dac6b2889
commit
369237f6a8
@ -19,6 +19,7 @@ import type {
|
|||||||
const EMPTY_MESSAGES: UIMessage[] = [];
|
const EMPTY_MESSAGES: UIMessage[] = [];
|
||||||
const INITIAL_HISTORY_PAGE_LIMIT = 160;
|
const INITIAL_HISTORY_PAGE_LIMIT = 160;
|
||||||
const OLDER_HISTORY_PAGE_LIMIT = 120;
|
const OLDER_HISTORY_PAGE_LIMIT = 120;
|
||||||
|
const CHAT_CREATE_TIMEOUT_MS = 60_000;
|
||||||
|
|
||||||
function persistedMessagesToUi(messages: UIMessage[]): UIMessage[] {
|
function persistedMessagesToUi(messages: UIMessage[]): UIMessage[] {
|
||||||
return messages.map((m, idx) => ({
|
return messages.map((m, idx) => ({
|
||||||
@ -86,7 +87,7 @@ export function useSessions(): {
|
|||||||
}, [client, refresh]);
|
}, [client, refresh]);
|
||||||
|
|
||||||
const createChat = useCallback(async (workspaceScope?: WorkspaceScopePayload | null): Promise<string> => {
|
const createChat = useCallback(async (workspaceScope?: WorkspaceScopePayload | null): Promise<string> => {
|
||||||
const chatId = await client.newChat(5_000, 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);
|
||||||
// Optimistic insert; a subsequent refresh will replace it with the
|
// Optimistic insert; a subsequent refresh will replace it with the
|
||||||
@ -112,7 +113,12 @@ export function useSessions(): {
|
|||||||
beforeUserIndex: number,
|
beforeUserIndex: number,
|
||||||
title?: string,
|
title?: string,
|
||||||
): Promise<string> => {
|
): Promise<string> => {
|
||||||
const chatId = await client.forkChat(sourceChatId, beforeUserIndex, title);
|
const chatId = await client.forkChat(
|
||||||
|
sourceChatId,
|
||||||
|
beforeUserIndex,
|
||||||
|
title,
|
||||||
|
CHAT_CREATE_TIMEOUT_MS,
|
||||||
|
);
|
||||||
const key = `websocket:${chatId}`;
|
const key = `websocket:${chatId}`;
|
||||||
optimisticKeysRef.current.add(key);
|
optimisticKeysRef.current.add(key);
|
||||||
setSessions((prev) => [
|
setSessions((prev) => [
|
||||||
|
|||||||
@ -219,7 +219,7 @@ describe("useSessions", () => {
|
|||||||
await result.current.createChat();
|
await result.current.createChat();
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(client.newChat).toHaveBeenCalledWith(5000, undefined);
|
expect(client.newChat).toHaveBeenCalledWith(60_000, undefined);
|
||||||
expect(result.current.sessions.map((s) => s.key)).toEqual(["websocket:chat-new"]);
|
expect(result.current.sessions.map((s) => s.key)).toEqual(["websocket:chat-new"]);
|
||||||
|
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
@ -258,7 +258,7 @@ describe("useSessions", () => {
|
|||||||
await result.current.createChat(workspaceScope);
|
await result.current.createChat(workspaceScope);
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(client.newChat).toHaveBeenCalledWith(5000, workspaceScope);
|
expect(client.newChat).toHaveBeenCalledWith(60_000, workspaceScope);
|
||||||
expect(result.current.sessions[0]?.workspaceScope).toEqual(workspaceScope);
|
expect(result.current.sessions[0]?.workspaceScope).toEqual(workspaceScope);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user