fix: support setting visibility on initial chat creation (#975)

This commit is contained in:
Jeremy 2025-05-01 17:47:48 -07:00 committed by GitHub
parent a3221fbcdc
commit 575c12503c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 158 additions and 32 deletions

View file

@ -49,7 +49,8 @@ export async function POST(request: Request) {
}
try {
const { id, message, selectedChatModel } = requestBody;
const { id, message, selectedChatModel, selectedVisibilityType } =
requestBody;
const session = await auth();
@ -80,7 +81,12 @@ export async function POST(request: Request) {
message,
});
await saveChat({ id, userId: session.user.id, title });
await saveChat({
id,
userId: session.user.id,
title,
visibility: selectedVisibilityType,
});
} else {
if (chat.userId !== session.user.id) {
return new Response('Forbidden', { status: 403 });
@ -236,7 +242,7 @@ export async function GET(request: Request) {
return new Response('Not found', { status: 404 });
}
if (chat.userId !== session.user.id) {
if (chat.visibility === 'private' && chat.userId !== session.user.id) {
return new Response('Forbidden', { status: 403 });
}

View file

@ -24,6 +24,7 @@ export const postRequestBodySchema = z.object({
.optional(),
}),
selectedChatModel: z.enum(['chat-model', 'chat-model-reasoning']),
selectedVisibilityType: z.enum(['public', 'private']),
});
export type PostRequestBody = z.infer<typeof postRequestBodySchema>;