(chatId: string)
| 75 | * pipeline is unchanged. |
| 76 | */ |
| 77 | export async function loadCopilotChatMessages(chatId: string): Promise<PersistedMessage[]> { |
| 78 | const rows = await db |
| 79 | .select({ content: copilotMessages.content }) |
| 80 | .from(copilotMessages) |
| 81 | .where(and(eq(copilotMessages.chatId, chatId), isNull(copilotMessages.deletedAt))) |
| 82 | .orderBy( |
| 83 | sql`${copilotMessages.seq} asc nulls last`, |
| 84 | asc(copilotMessages.createdAt), |
| 85 | asc(copilotMessages.id) |
| 86 | ) |
| 87 | // Also strip on read: rows written before the backfill still carry outputs. |
| 88 | return rows.map((row) => stripToolResultOutput(row.content as PersistedMessage)) |
| 89 | } |
| 90 | |
| 91 | type CopilotChatAuthRow = Pick< |
| 92 | typeof copilotChats.$inferSelect, |
no test coverage detected