mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-12 20:35:24 +00:00
fix(ask_sb): Fix '413 content too large' error (#416)
This commit is contained in:
parent
77593a92a4
commit
163e558b9a
4 changed files with 26 additions and 24 deletions
|
|
@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- [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)
|
||||||
|
|
||||||
## [4.6.1] - 2025-07-29
|
## [4.6.1] - 2025-07-29
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,12 @@
|
||||||
|
|
||||||
import { ResizablePanel } from '@/components/ui/resizable';
|
import { ResizablePanel } from '@/components/ui/resizable';
|
||||||
import { ChatThread } from '@/features/chat/components/chatThread';
|
import { ChatThread } from '@/features/chat/components/chatThread';
|
||||||
import { LanguageModelInfo, SBChatMessage, SearchScope, SET_CHAT_STATE_QUERY_PARAM, SetChatStatePayload } from '@/features/chat/types';
|
import { LanguageModelInfo, SBChatMessage, SearchScope, SET_CHAT_STATE_SESSION_STORAGE_KEY, SetChatStatePayload } from '@/features/chat/types';
|
||||||
import { RepositoryQuery, SearchContextQuery } from '@/lib/types';
|
import { RepositoryQuery, SearchContextQuery } from '@/lib/types';
|
||||||
import { CreateUIMessage } from 'ai';
|
import { CreateUIMessage } from 'ai';
|
||||||
import { useRouter, useSearchParams } from 'next/navigation';
|
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useChatId } from '../../useChatId';
|
import { useChatId } from '../../useChatId';
|
||||||
|
import { useSessionStorage } from 'usehooks-ts';
|
||||||
|
|
||||||
interface ChatThreadPanelProps {
|
interface ChatThreadPanelProps {
|
||||||
languageModels: LanguageModelInfo[];
|
languageModels: LanguageModelInfo[];
|
||||||
|
|
@ -29,9 +29,8 @@ export const ChatThreadPanel = ({
|
||||||
// @note: we are guaranteed to have a chatId because this component will only be
|
// @note: we are guaranteed to have a chatId because this component will only be
|
||||||
// mounted when on a /chat/[id] route.
|
// mounted when on a /chat/[id] route.
|
||||||
const chatId = useChatId()!;
|
const chatId = useChatId()!;
|
||||||
const router = useRouter();
|
|
||||||
const searchParams = useSearchParams();
|
|
||||||
const [inputMessage, setInputMessage] = useState<CreateUIMessage<SBChatMessage> | undefined>(undefined);
|
const [inputMessage, setInputMessage] = useState<CreateUIMessage<SBChatMessage> | undefined>(undefined);
|
||||||
|
const [chatState, setChatState] = useSessionStorage<SetChatStatePayload | null>(SET_CHAT_STATE_SESSION_STORAGE_KEY, null);
|
||||||
|
|
||||||
// Use the last user's last message to determine what repos and contexts we should select by default.
|
// Use the last user's last message to determine what repos and contexts we should select by default.
|
||||||
const lastUserMessage = messages.findLast((message) => message.role === "user");
|
const lastUserMessage = messages.findLast((message) => message.role === "user");
|
||||||
|
|
@ -39,24 +38,20 @@ export const ChatThreadPanel = ({
|
||||||
const [selectedSearchScopes, setSelectedSearchScopes] = useState<SearchScope[]>(defaultSelectedSearchScopes);
|
const [selectedSearchScopes, setSelectedSearchScopes] = useState<SearchScope[]>(defaultSelectedSearchScopes);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const setChatState = searchParams.get(SET_CHAT_STATE_QUERY_PARAM);
|
if (!chatState) {
|
||||||
if (!setChatState) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { inputMessage, selectedSearchScopes } = JSON.parse(setChatState) as SetChatStatePayload;
|
setInputMessage(chatState.inputMessage);
|
||||||
setInputMessage(inputMessage);
|
setSelectedSearchScopes(chatState.selectedSearchScopes);
|
||||||
setSelectedSearchScopes(selectedSearchScopes);
|
|
||||||
} catch {
|
} catch {
|
||||||
console.error('Invalid message in URL');
|
console.error('Invalid chat state in session storage');
|
||||||
|
} finally {
|
||||||
|
setChatState(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the message from the URL
|
}, [chatState, setChatState]);
|
||||||
const newSearchParams = new URLSearchParams(searchParams.toString());
|
|
||||||
newSearchParams.delete(SET_CHAT_STATE_QUERY_PARAM);
|
|
||||||
router.replace(`?${newSearchParams.toString()}`, { scroll: false });
|
|
||||||
}, [searchParams, router]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ResizablePanel
|
<ResizablePanel
|
||||||
|
|
|
||||||
|
|
@ -158,7 +158,7 @@ declare module 'slate' {
|
||||||
/////////////////////////
|
/////////////////////////
|
||||||
|
|
||||||
// Misc //
|
// Misc //
|
||||||
export const SET_CHAT_STATE_QUERY_PARAM = 'setChatState';
|
export const SET_CHAT_STATE_SESSION_STORAGE_KEY = 'setChatState';
|
||||||
|
|
||||||
export type SetChatStatePayload = {
|
export type SetChatStatePayload = {
|
||||||
inputMessage: CreateUIMessage<SBChatMessage>;
|
inputMessage: CreateUIMessage<SBChatMessage>;
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,8 @@ import { useRouter } from "next/navigation";
|
||||||
import { createChat } from "./actions";
|
import { createChat } from "./actions";
|
||||||
import { isServiceError } from "@/lib/utils";
|
import { isServiceError } from "@/lib/utils";
|
||||||
import { createPathWithQueryParams } from "@/lib/utils";
|
import { createPathWithQueryParams } from "@/lib/utils";
|
||||||
import { SearchScope, SET_CHAT_STATE_QUERY_PARAM, SetChatStatePayload } from "./types";
|
import { SearchScope, SET_CHAT_STATE_SESSION_STORAGE_KEY, SetChatStatePayload } from "./types";
|
||||||
|
import { useSessionStorage } from "usehooks-ts";
|
||||||
|
|
||||||
export const useCreateNewChatThread = () => {
|
export const useCreateNewChatThread = () => {
|
||||||
const domain = useDomain();
|
const domain = useDomain();
|
||||||
|
|
@ -18,6 +19,9 @@ export const useCreateNewChatThread = () => {
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
|
const [, setChatState] = useSessionStorage<SetChatStatePayload | null>(SET_CHAT_STATE_SESSION_STORAGE_KEY, null);
|
||||||
|
|
||||||
|
|
||||||
const createNewChatThread = useCallback(async (children: Descendant[], selectedSearchScopes: SearchScope[]) => {
|
const createNewChatThread = useCallback(async (children: Descendant[], selectedSearchScopes: SearchScope[]) => {
|
||||||
const text = slateContentToString(children);
|
const text = slateContentToString(children);
|
||||||
const mentions = getAllMentionElements(children);
|
const mentions = getAllMentionElements(children);
|
||||||
|
|
@ -34,16 +38,16 @@ export const useCreateNewChatThread = () => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = createPathWithQueryParams(`/${domain}/chat/${response.id}`,
|
setChatState({
|
||||||
[SET_CHAT_STATE_QUERY_PARAM, JSON.stringify({
|
|
||||||
inputMessage,
|
inputMessage,
|
||||||
selectedSearchScopes,
|
selectedSearchScopes,
|
||||||
} satisfies SetChatStatePayload)],
|
});
|
||||||
);
|
|
||||||
|
const url = createPathWithQueryParams(`/${domain}/chat/${response.id}`);
|
||||||
|
|
||||||
router.push(url);
|
router.push(url);
|
||||||
router.refresh();
|
router.refresh();
|
||||||
}, [domain, router, toast]);
|
}, [domain, router, toast, setChatState]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
createNewChatThread,
|
createNewChatThread,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue