@@ -38,7 +38,7 @@ export interface PersistedFileAttachment {
3838 size : number
3939}
4040
41- interface PersistedMessageContext {
41+ export interface PersistedMessageContext {
4242 kind : string
4343 label : string
4444 workflowId ?: string
@@ -87,6 +87,30 @@ function copyTextSelection(
8787 }
8888}
8989
90+ /** The one field-wise copy of a message context, shared by every write, read and display path. */
91+ export function copyPersistedMessageContext ( c : PersistedMessageContext ) : PersistedMessageContext {
92+ return {
93+ kind : c . kind ,
94+ label : c . label ,
95+ ...( c . workflowId ? { workflowId : c . workflowId } : { } ) ,
96+ ...( c . knowledgeId ? { knowledgeId : c . knowledgeId } : { } ) ,
97+ ...( c . tableId ? { tableId : c . tableId } : { } ) ,
98+ ...( c . viewId ? { viewId : c . viewId } : { } ) ,
99+ ...( c . fileId ? { fileId : c . fileId } : { } ) ,
100+ ...( c . dashboardId ? { dashboardId : c . dashboardId } : { } ) ,
101+ ...( c . folderId ? { folderId : c . folderId } : { } ) ,
102+ ...( c . chatId ? { chatId : c . chatId } : { } ) ,
103+ ...( c . blockType ? { blockType : c . blockType } : { } ) ,
104+ ...( c . skillId ? { skillId : c . skillId } : { } ) ,
105+ ...( c . serverId ? { serverId : c . serverId } : { } ) ,
106+ ...( c . fileName ? { fileName : c . fileName } : { } ) ,
107+ ...( c . tableName ? { tableName : c . tableName } : { } ) ,
108+ ...( c . tabId ? { tabId : c . tabId } : { } ) ,
109+ ...( c . terminalId ? { terminalId : c . terminalId } : { } ) ,
110+ ...( c . selection ? { selection : copyTextSelection ( c . selection ) } : { } ) ,
111+ }
112+ }
113+
90114export interface PersistedMessage {
91115 id : string
92116 role : 'user' | 'assistant'
@@ -464,26 +488,7 @@ export function buildPersistedUserMessage(params: UserMessageParams): PersistedM
464488 }
465489
466490 if ( params . contexts && params . contexts . length > 0 ) {
467- message . contexts = params . contexts . map ( ( c ) => ( {
468- kind : c . kind ,
469- label : c . label ,
470- ...( c . workflowId ? { workflowId : c . workflowId } : { } ) ,
471- ...( c . knowledgeId ? { knowledgeId : c . knowledgeId } : { } ) ,
472- ...( c . tableId ? { tableId : c . tableId } : { } ) ,
473- ...( c . viewId ? { viewId : c . viewId } : { } ) ,
474- ...( c . fileId ? { fileId : c . fileId } : { } ) ,
475- ...( c . dashboardId ? { dashboardId : c . dashboardId } : { } ) ,
476- ...( c . folderId ? { folderId : c . folderId } : { } ) ,
477- ...( c . chatId ? { chatId : c . chatId } : { } ) ,
478- ...( c . blockType ? { blockType : c . blockType } : { } ) ,
479- ...( c . skillId ? { skillId : c . skillId } : { } ) ,
480- ...( c . serverId ? { serverId : c . serverId } : { } ) ,
481- ...( c . fileName ? { fileName : c . fileName } : { } ) ,
482- ...( c . tableName ? { tableName : c . tableName } : { } ) ,
483- ...( c . tabId ? { tabId : c . tabId } : { } ) ,
484- ...( c . terminalId ? { terminalId : c . terminalId } : { } ) ,
485- ...( c . selection ? { selection : copyTextSelection ( c . selection ) } : { } ) ,
486- } ) )
491+ message . contexts = params . contexts . map ( copyPersistedMessageContext )
487492 }
488493
489494 return message
@@ -816,26 +821,7 @@ export function normalizeMessage(raw: Record<string, unknown>): PersistedMessage
816821
817822 const rawContexts = raw . contexts as PersistedMessageContext [ ] | undefined
818823 if ( Array . isArray ( rawContexts ) && rawContexts . length > 0 ) {
819- msg . contexts = rawContexts . map ( ( c ) => ( {
820- kind : c . kind ,
821- label : c . label ,
822- ...( c . workflowId ? { workflowId : c . workflowId } : { } ) ,
823- ...( c . knowledgeId ? { knowledgeId : c . knowledgeId } : { } ) ,
824- ...( c . tableId ? { tableId : c . tableId } : { } ) ,
825- ...( c . viewId ? { viewId : c . viewId } : { } ) ,
826- ...( c . fileId ? { fileId : c . fileId } : { } ) ,
827- ...( c . dashboardId ? { dashboardId : c . dashboardId } : { } ) ,
828- ...( c . folderId ? { folderId : c . folderId } : { } ) ,
829- ...( c . chatId ? { chatId : c . chatId } : { } ) ,
830- ...( c . blockType ? { blockType : c . blockType } : { } ) ,
831- ...( c . skillId ? { skillId : c . skillId } : { } ) ,
832- ...( c . serverId ? { serverId : c . serverId } : { } ) ,
833- ...( c . fileName ? { fileName : c . fileName } : { } ) ,
834- ...( c . tableName ? { tableName : c . tableName } : { } ) ,
835- ...( c . tabId ? { tabId : c . tabId } : { } ) ,
836- ...( c . terminalId ? { terminalId : c . terminalId } : { } ) ,
837- ...( c . selection ? { selection : copyTextSelection ( c . selection ) } : { } ) ,
838- } ) )
824+ msg . contexts = rawContexts . map ( copyPersistedMessageContext )
839825 }
840826
841827 return msg
0 commit comments