feat: support resuming ongoing streams (#974)

This commit is contained in:
Jeremy 2025-05-01 12:36:52 -07:00 committed by GitHub
parent 45978c27a2
commit a3221fbcdc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 1005 additions and 47 deletions

View file

@ -26,6 +26,7 @@ import {
vote,
type DBMessage,
type Chat,
stream,
} from './schema';
import type { ArtifactKind } from '@/components/artifact';
import { generateUUID } from '../utils';
@ -100,6 +101,7 @@ export async function deleteChatById({ id }: { id: string }) {
try {
await db.delete(vote).where(eq(vote.chatId, id));
await db.delete(message).where(eq(message.chatId, id));
await db.delete(stream).where(eq(stream.chatId, id));
const [chatsDeleted] = await db
.delete(chat)
@ -470,3 +472,36 @@ export async function getMessageCountByUserId({
throw error;
}
}
export async function createStreamId({
streamId,
chatId,
}: {
streamId: string;
chatId: string;
}) {
try {
await db
.insert(stream)
.values({ id: streamId, chatId, createdAt: new Date() });
} catch (error) {
console.error('Failed to create stream id in database');
throw error;
}
}
export async function getStreamIdsByChatId({ chatId }: { chatId: string }) {
try {
const streamIds = await db
.select({ id: stream.id })
.from(stream)
.where(eq(stream.chatId, chatId))
.orderBy(desc(stream.createdAt))
.execute();
return streamIds.map(({ id }) => id);
} catch (error) {
console.error('Failed to get stream ids by chat id from database');
throw error;
}
}