@@ -6,11 +6,7 @@ import {
66 getActiveWorkflowRecord ,
77} from '@sim/platform-authz/workflow'
88import { and , asc , eq , isNull , sql } from 'drizzle-orm'
9- import {
10- collectChatMcpServerIds ,
11- type PersistedMessage ,
12- stripToolResultOutput ,
13- } from '@/lib/copilot/chat/persisted-message'
9+ import { type PersistedMessage , stripToolResultOutput } from '@/lib/copilot/chat/persisted-message'
1410import {
1511 assertActiveWorkspaceAccess ,
1612 checkWorkspaceAccess ,
@@ -39,11 +35,6 @@ const copilotChatAuthColumns = {
3935 type : copilotChats . type ,
4036} as const
4137
42- const copilotChatContinuationColumns = {
43- ...copilotChatAuthColumns ,
44- title : copilotChats . title ,
45- } as const
46-
4738/**
4839 * Column set for chat-detail callers that need chat metadata. The conversation
4940 * transcript is no longer selected from `copilot_chats.messages` (JSONB) —
@@ -112,12 +103,6 @@ type CopilotChatAuthRow = Pick<
112103 'id' | 'userId' | 'workflowId' | 'workspaceId' | 'type'
113104>
114105
115- export type CopilotChatContinuationMetadata = CopilotChatAuthRow & {
116- title : string | null
117- hasMessages : boolean
118- mcpServerIds : string [ ]
119- }
120-
121106export type CopilotChatDetailRow = Pick <
122107 typeof copilotChats . $inferSelect ,
123108 | 'id'
@@ -196,57 +181,6 @@ export async function getAccessibleCopilotChatAuth(
196181 return authorizeCopilotChatRow ( chat , chatId , userId )
197182}
198183
199- /**
200- * Loads only the authorized metadata needed to continue a persisted chat. The
201- * one-row existence probe preserves first-turn title behavior, while the MCP
202- * query projects only user-message context arrays. Assistant/tool content is
203- * never loaded or normalized.
204- */
205- export async function getAccessibleCopilotChatContinuationMetadata (
206- chatId : string ,
207- userId : string
208- ) : Promise < CopilotChatContinuationMetadata | null > {
209- const [ chat ] = await db
210- . select ( copilotChatContinuationColumns )
211- . from ( copilotChats )
212- . where ( ownedLiveChatWhere ( chatId , userId ) )
213- . limit ( 1 )
214-
215- const authorized = await authorizeCopilotChatRow ( chat , chatId , userId )
216- if ( ! authorized ) return null
217-
218- const [ message ] = await db
219- . select ( { id : copilotMessages . id } )
220- . from ( copilotMessages )
221- . where ( and ( eq ( copilotMessages . chatId , chatId ) , isNull ( copilotMessages . deletedAt ) ) )
222- . limit ( 1 )
223-
224- if ( ! message ) return { ...authorized , hasMessages : false , mcpServerIds : [ ] }
225-
226- const contextRows = await db
227- . select ( { contexts : sql < unknown > `${ copilotMessages . content } -> 'contexts'` } )
228- . from ( copilotMessages )
229- . where (
230- and (
231- eq ( copilotMessages . chatId , chatId ) ,
232- eq ( copilotMessages . role , 'user' ) ,
233- isNull ( copilotMessages . deletedAt ) ,
234- sql `${ copilotMessages . content } ? 'contexts'`
235- )
236- )
237- . orderBy (
238- sql `${ copilotMessages . seq } asc nulls last` ,
239- asc ( copilotMessages . createdAt ) ,
240- asc ( copilotMessages . id )
241- )
242-
243- return {
244- ...authorized ,
245- hasMessages : true ,
246- mcpServerIds : collectChatMcpServerIds ( contextRows ) ,
247- }
248- }
249-
250184/**
251185 * Load a copilot chat row for the legacy chat detail endpoint, including the
252186 * transcript plus `model` and `config`. Drops `previewYaml`
0 commit comments