Skip to content

Commit fe941f8

Browse files
committed
perf(copilot): narrow getAccessibleCopilotChat projection
1 parent 1afa881 commit fe941f8

1 file changed

Lines changed: 24 additions & 7 deletions

File tree

apps/sim/lib/copilot/chat/lifecycle.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,19 @@ const copilotChatDetailColumns = {
5151
updatedAt: copilotChats.updatedAt,
5252
} as const
5353

54+
/**
55+
* Column set for the legacy copilot chat detail endpoint. Extends
56+
* `copilotChatDetailColumns` with `model`, `planArtifact`, and `config` — the
57+
* fields the legacy `transformChat` response shape includes. Still drops
58+
* `previewYaml` (JSONB), `pinned`, and `lastSeenAt`.
59+
*/
60+
const copilotChatLegacyDetailColumns = {
61+
...copilotChatDetailColumns,
62+
model: copilotChats.model,
63+
planArtifact: copilotChats.planArtifact,
64+
config: copilotChats.config,
65+
} as const
66+
5467
type CopilotChatAuthRow = Pick<
5568
typeof copilotChats.$inferSelect,
5669
'id' | 'userId' | 'workflowId' | 'workspaceId' | 'type'
@@ -71,6 +84,9 @@ export type CopilotChatDetailRow = Pick<
7184
| 'updatedAt'
7285
>
7386

87+
export type CopilotChatLegacyDetailRow = CopilotChatDetailRow &
88+
Pick<typeof copilotChats.$inferSelect, 'model' | 'planArtifact' | 'config'>
89+
7490
async function authorizeCopilotChatRow<T extends CopilotChatAuthRow>(
7591
chat: T | undefined,
7692
chatId: string,
@@ -130,15 +146,16 @@ export async function getAccessibleCopilotChatAuth(
130146
}
131147

132148
/**
133-
* Load the full copilot chat row after authorization. Use this only when the
134-
* caller actually consumes copilot-only TOAST-able columns (`previewYaml`,
135-
* `planArtifact`, `config`) or other extended metadata — for example the
136-
* legacy copilot chat detail endpoint. Mothership chats and other consumers
137-
* that only need the transcript should prefer `getAccessibleCopilotChatWithMessages`.
149+
* Load a copilot chat row for the legacy chat detail endpoint, including the
150+
* transcript plus `model`, `planArtifact`, and `config`. Drops `previewYaml`
151+
* (JSONB), `pinned`, and `lastSeenAt` — none of which the endpoint returns.
138152
*/
139-
export async function getAccessibleCopilotChat(chatId: string, userId: string) {
153+
export async function getAccessibleCopilotChat(
154+
chatId: string,
155+
userId: string
156+
): Promise<CopilotChatLegacyDetailRow | null> {
140157
const [chat] = await db
141-
.select()
158+
.select(copilotChatLegacyDetailColumns)
142159
.from(copilotChats)
143160
.where(and(eq(copilotChats.id, chatId), eq(copilotChats.userId, userId)))
144161
.limit(1)

0 commit comments

Comments
 (0)