MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / streamImport

Function streamImport

apps/cli/src/import/stream-import.ts:87–152  ·  view source on GitHub ↗
(
  dbManager: DatabaseManager,
  filePath: string,
  options?: StreamImportOptions
)

Source from the content-addressed store, hash-verified

85 * with batched transactions, deferred indexes, and FTS.
86 */
87export async function streamImport(
88 dbManager: DatabaseManager,
89 filePath: string,
90 options?: StreamImportOptions
91): Promise<StreamImportResult> {
92 const { formatId, chatIndex, onProgress, sessionId } = options || {}
93
94 const formatOptions: Record<string, unknown> = {}
95 if (formatId) formatOptions.formatId = formatId
96 if (chatIndex !== undefined) formatOptions.chatIndex = chatIndex
97
98 const progressAdapter: ImportProgressCallback = onProgress
99 ? (progress) => {
100 let stage: StreamImportProgress['stage'] = 'parsing'
101 let pct = 0
102 switch (progress.stage) {
103 case 'detecting':
104 stage = 'detecting'
105 pct = 5
106 break
107 case 'parsing':
108 stage = 'parsing'
109 pct = Math.min(Math.round(progress.percentage * 0.7), 70)
110 break
111 case 'importing':
112 case 'saving':
113 stage = 'saving'
114 pct = 80
115 break
116 case 'done':
117 stage = 'done'
118 pct = 100
119 break
120 case 'error':
121 stage = 'error'
122 pct = 0
123 break
124 }
125 onProgress({
126 stage,
127 progress: pct,
128 message: progress.message || '',
129 bytesRead: progress.bytesRead,
130 totalBytes: progress.totalBytes,
131 messagesProcessed: progress.messagesProcessed,
132 })
133 }
134 : () => {}
135
136 const deps = buildStreamImportDeps(dbManager, progressAdapter)
137 const result = await streamingImport(filePath, deps, formatOptions, sessionId)
138 if (!result.success || !result.sessionId) return result
139
140 try {
141 dbManager.raiseCurrentChatDbCompatibilityGate()
142 } catch (error) {
143 deleteSessionDatabase(dbManager, result.sessionId)
144 return {

Callers 6

registerImportRoutesFunction · 0.90
importer.test.tsFile · 0.90
fullImportFileMethod · 0.90
registerMergeRoutesFunction · 0.50
cli.tsFile · 0.50
cliStreamImportFunction · 0.50

Calls 5

streamingImportFunction · 0.90
deleteSessionDatabaseFunction · 0.85
buildStreamImportDepsFunction · 0.70
onProgressFunction · 0.50

Tested by

no test coverage detected