fix: support setting visibility on initial chat creation (#975)
This commit is contained in:
parent
a3221fbcdc
commit
575c12503c
15 changed files with 158 additions and 32 deletions
|
|
@ -17,26 +17,32 @@ import { getChatHistoryPaginationKey } from './sidebar-history';
|
|||
import { toast } from './toast';
|
||||
import type { Session } from 'next-auth';
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
import { useChatVisibility } from '@/hooks/use-chat-visibility';
|
||||
|
||||
export function Chat({
|
||||
id,
|
||||
initialMessages,
|
||||
selectedChatModel,
|
||||
selectedVisibilityType,
|
||||
initialChatModel,
|
||||
initialVisibilityType,
|
||||
isReadonly,
|
||||
session,
|
||||
autoResume,
|
||||
}: {
|
||||
id: string;
|
||||
initialMessages: Array<UIMessage>;
|
||||
selectedChatModel: string;
|
||||
selectedVisibilityType: VisibilityType;
|
||||
initialChatModel: string;
|
||||
initialVisibilityType: VisibilityType;
|
||||
isReadonly: boolean;
|
||||
session: Session;
|
||||
autoResume: boolean;
|
||||
}) {
|
||||
const { mutate } = useSWRConfig();
|
||||
|
||||
const { visibilityType } = useChatVisibility({
|
||||
chatId: id,
|
||||
initialVisibilityType,
|
||||
});
|
||||
|
||||
const {
|
||||
messages,
|
||||
setMessages,
|
||||
|
|
@ -57,7 +63,8 @@ export function Chat({
|
|||
experimental_prepareRequestBody: (body) => ({
|
||||
id,
|
||||
message: body.messages.at(-1),
|
||||
selectedChatModel,
|
||||
selectedChatModel: initialChatModel,
|
||||
selectedVisibilityType: visibilityType,
|
||||
}),
|
||||
onFinish: () => {
|
||||
mutate(unstable_serialize(getChatHistoryPaginationKey));
|
||||
|
|
@ -109,8 +116,8 @@ export function Chat({
|
|||
<div className="flex flex-col min-w-0 h-dvh bg-background">
|
||||
<ChatHeader
|
||||
chatId={id}
|
||||
selectedModelId={selectedChatModel}
|
||||
selectedVisibilityType={selectedVisibilityType}
|
||||
selectedModelId={initialChatModel}
|
||||
selectedVisibilityType={initialVisibilityType}
|
||||
isReadonly={isReadonly}
|
||||
session={session}
|
||||
/>
|
||||
|
|
@ -140,6 +147,7 @@ export function Chat({
|
|||
messages={messages}
|
||||
setMessages={setMessages}
|
||||
append={append}
|
||||
selectedVisibilityType={visibilityType}
|
||||
/>
|
||||
)}
|
||||
</form>
|
||||
|
|
@ -160,6 +168,7 @@ export function Chat({
|
|||
reload={reload}
|
||||
votes={votes}
|
||||
isReadonly={isReadonly}
|
||||
selectedVisibilityType={visibilityType}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue