perf(copilot): narrow getAccessibleCopilotChat projection (#4720)

This commit is contained in:
Waleed
2026-05-22 08:35:39 -07:00
committed by GitHub
parent 1afa8815c2
commit 1631b36b38
+24 -7
View File
@@ -51,6 +51,19 @@ const copilotChatDetailColumns = {
updatedAt: copilotChats.updatedAt,
} as const
/**
* Column set for the legacy copilot chat detail endpoint. Extends
* `copilotChatDetailColumns` with `model`, `planArtifact`, and `config` — the
* fields the legacy `transformChat` response shape includes. Still drops
* `previewYaml` (JSONB), `pinned`, and `lastSeenAt`.
*/
const copilotChatLegacyDetailColumns = {
...copilotChatDetailColumns,
model: copilotChats.model,
planArtifact: copilotChats.planArtifact,
config: copilotChats.config,
} as const
type CopilotChatAuthRow = Pick<
typeof copilotChats.$inferSelect,
'id' | 'userId' | 'workflowId' | 'workspaceId' | 'type'
@@ -71,6 +84,9 @@ export type CopilotChatDetailRow = Pick<
| 'updatedAt'
>
export type CopilotChatLegacyDetailRow = CopilotChatDetailRow &
Pick<typeof copilotChats.$inferSelect, 'model' | 'planArtifact' | 'config'>
async function authorizeCopilotChatRow<T extends CopilotChatAuthRow>(
chat: T | undefined,
chatId: string,
@@ -130,15 +146,16 @@ export async function getAccessibleCopilotChatAuth(
}
/**
* Load the full copilot chat row after authorization. Use this only when the
* caller actually consumes copilot-only TOAST-able columns (`previewYaml`,
* `planArtifact`, `config`) or other extended metadata — for example the
* legacy copilot chat detail endpoint. Mothership chats and other consumers
* that only need the transcript should prefer `getAccessibleCopilotChatWithMessages`.
* Load a copilot chat row for the legacy chat detail endpoint, including the
* transcript plus `model`, `planArtifact`, and `config`. Drops `previewYaml`
* (JSONB), `pinned`, and `lastSeenAt` — none of which the endpoint returns.
*/
export async function getAccessibleCopilotChat(chatId: string, userId: string) {
export async function getAccessibleCopilotChat(
chatId: string,
userId: string
): Promise<CopilotChatLegacyDetailRow | null> {
const [chat] = await db
.select()
.select(copilotChatLegacyDetailColumns)
.from(copilotChats)
.where(and(eq(copilotChats.id, chatId), eq(copilotChats.userId, userId)))
.limit(1)