Skip to content

@sqlrooms/ai / cleanupPendingAnalysisResults

Function: cleanupPendingAnalysisResults()

cleanupPendingAnalysisResults(session): object

Cleans up pending analysis results from interrupted conversations and restores them with proper IDs from actual user messages. This handles the case where a page refresh occurred during an active analysis, leaving orphaned "pending" results.

Should be called once when loading persisted session data, not in migrations.

Parameters

ParameterTypeDescription
session{ id: string; name: string; modelProvider: string; model: string; customModelName?: string; baseUrl?: string; analysisResults: object[]; createdAt?: Date; uiMessages: object[]; toolAdditionalData?: Record<string, unknown>; messagesRevision: number; }The session to clean up
session.idstring-
session.namestring-
session.modelProviderstring-
session.modelstring-
session.customModelName?string-
session.baseUrl?string-
session.analysisResultsobject[]-
session.createdAt?Date-
session.uiMessagesobject[]-
session.toolAdditionalData?Record<string, unknown>-
session.messagesRevisionnumber-

Returns

object

The cleaned session with restored analysis results

NameType
idstring
namestring
modelProviderstring
modelstring
customModelName?string
baseUrl?string
analysisResultsobject[]
createdAt?Date
uiMessagesobject[]
toolAdditionalData?Record<string, unknown>
messagesRevisionnumber