Skip to content

Commit 7b09a9a

Browse files
Merge branch 'main' into bkellam/bump_ai_to_v5
2 parents af1667e + 163e558 commit 7b09a9a

File tree

4 files changed

+26
-24
lines changed

4 files changed

+26
-24
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Changed
1111
- Bumped AI SDK and associated packages version. [#417](https://github.com/sourcebot-dev/sourcebot/pull/417)
1212

13+
### Fixed
14+
- [ask sb] Fixed "413 content too large" error when starting a new chat with many repos selected. [#416](https://github.com/sourcebot-dev/sourcebot/pull/416)
15+
1316
## [4.6.1] - 2025-07-29
1417

1518
### Added

packages/web/src/app/[domain]/chat/[id]/components/chatThreadPanel.tsx

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
import { ResizablePanel } from '@/components/ui/resizable';
44
import { ChatThread } from '@/features/chat/components/chatThread';
5-
import { LanguageModelInfo, SBChatMessage, SearchScope, SET_CHAT_STATE_QUERY_PARAM, SetChatStatePayload } from '@/features/chat/types';
5+
import { LanguageModelInfo, SBChatMessage, SearchScope, SET_CHAT_STATE_SESSION_STORAGE_KEY, SetChatStatePayload } from '@/features/chat/types';
66
import { RepositoryQuery, SearchContextQuery } from '@/lib/types';
77
import { CreateUIMessage } from 'ai';
8-
import { useRouter, useSearchParams } from 'next/navigation';
98
import { useEffect, useState } from 'react';
109
import { useChatId } from '../../useChatId';
10+
import { useSessionStorage } from 'usehooks-ts';
1111

1212
interface ChatThreadPanelProps {
1313
languageModels: LanguageModelInfo[];
@@ -29,34 +29,29 @@ export const ChatThreadPanel = ({
2929
// @note: we are guaranteed to have a chatId because this component will only be
3030
// mounted when on a /chat/[id] route.
3131
const chatId = useChatId()!;
32-
const router = useRouter();
33-
const searchParams = useSearchParams();
3432
const [inputMessage, setInputMessage] = useState<CreateUIMessage<SBChatMessage> | undefined>(undefined);
33+
const [chatState, setChatState] = useSessionStorage<SetChatStatePayload | null>(SET_CHAT_STATE_SESSION_STORAGE_KEY, null);
3534

3635
// Use the last user's last message to determine what repos and contexts we should select by default.
3736
const lastUserMessage = messages.findLast((message) => message.role === "user");
3837
const defaultSelectedSearchScopes = lastUserMessage?.metadata?.selectedSearchScopes ?? [];
3938
const [selectedSearchScopes, setSelectedSearchScopes] = useState<SearchScope[]>(defaultSelectedSearchScopes);
4039

4140
useEffect(() => {
42-
const setChatState = searchParams.get(SET_CHAT_STATE_QUERY_PARAM);
43-
if (!setChatState) {
41+
if (!chatState) {
4442
return;
4543
}
4644

4745
try {
48-
const { inputMessage, selectedSearchScopes } = JSON.parse(setChatState) as SetChatStatePayload;
49-
setInputMessage(inputMessage);
50-
setSelectedSearchScopes(selectedSearchScopes);
46+
setInputMessage(chatState.inputMessage);
47+
setSelectedSearchScopes(chatState.selectedSearchScopes);
5148
} catch {
52-
console.error('Invalid message in URL');
49+
console.error('Invalid chat state in session storage');
50+
} finally {
51+
setChatState(null);
5352
}
5453

55-
// Remove the message from the URL
56-
const newSearchParams = new URLSearchParams(searchParams.toString());
57-
newSearchParams.delete(SET_CHAT_STATE_QUERY_PARAM);
58-
router.replace(`?${newSearchParams.toString()}`, { scroll: false });
59-
}, [searchParams, router]);
54+
}, [chatState, setChatState]);
6055

6156
return (
6257
<ResizablePanel

packages/web/src/features/chat/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ declare module 'slate' {
158158
/////////////////////////
159159

160160
// Misc //
161-
export const SET_CHAT_STATE_QUERY_PARAM = 'setChatState';
161+
export const SET_CHAT_STATE_SESSION_STORAGE_KEY = 'setChatState';
162162

163163
export type SetChatStatePayload = {
164164
inputMessage: CreateUIMessage<SBChatMessage>;

packages/web/src/features/chat/useCreateNewChatThread.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@ import { useRouter } from "next/navigation";
1010
import { createChat } from "./actions";
1111
import { isServiceError } from "@/lib/utils";
1212
import { createPathWithQueryParams } from "@/lib/utils";
13-
import { SearchScope, SET_CHAT_STATE_QUERY_PARAM, SetChatStatePayload } from "./types";
13+
import { SearchScope, SET_CHAT_STATE_SESSION_STORAGE_KEY, SetChatStatePayload } from "./types";
14+
import { useSessionStorage } from "usehooks-ts";
1415

1516
export const useCreateNewChatThread = () => {
1617
const domain = useDomain();
1718
const [isLoading, setIsLoading] = useState(false);
1819
const { toast } = useToast();
1920
const router = useRouter();
2021

22+
const [, setChatState] = useSessionStorage<SetChatStatePayload | null>(SET_CHAT_STATE_SESSION_STORAGE_KEY, null);
23+
24+
2125
const createNewChatThread = useCallback(async (children: Descendant[], selectedSearchScopes: SearchScope[]) => {
2226
const text = slateContentToString(children);
2327
const mentions = getAllMentionElements(children);
@@ -34,16 +38,16 @@ export const useCreateNewChatThread = () => {
3438
return;
3539
}
3640

37-
const url = createPathWithQueryParams(`/${domain}/chat/${response.id}`,
38-
[SET_CHAT_STATE_QUERY_PARAM, JSON.stringify({
39-
inputMessage,
40-
selectedSearchScopes,
41-
} satisfies SetChatStatePayload)],
42-
);
41+
setChatState({
42+
inputMessage,
43+
selectedSearchScopes,
44+
});
45+
46+
const url = createPathWithQueryParams(`/${domain}/chat/${response.id}`);
4347

4448
router.push(url);
4549
router.refresh();
46-
}, [domain, router, toast]);
50+
}, [domain, router, toast, setChatState]);
4751

4852
return {
4953
createNewChatThread,

0 commit comments

Comments
 (0)