Fix session migration: cache SDK sessions to localStorage for auto-import on native mode startup
Some checks failed
Release Binaries / release (push) Has been cancelled
Some checks failed
Release Binaries / release (push) Has been cancelled
This commit is contained in:
@@ -3,7 +3,7 @@ import type { Message } from "../types/message"
|
||||
|
||||
import { instances } from "./instances"
|
||||
import { nativeSessionApi } from "../lib/lite-mode"
|
||||
import { needsMigration, migrateSessionsToNative, markMigrated, getExistingSdkSessions } from "./session-migration"
|
||||
import { needsMigration, autoImportCachedSessions, markMigrated, cacheSDKSessions } from "./session-migration"
|
||||
import { preferences, setAgentModelPreference, getAgentModelPreference } from "./preferences"
|
||||
import { setSessionCompactionState } from "./session-compaction"
|
||||
import {
|
||||
@@ -390,23 +390,16 @@ async function fetchSessions(instanceId: string): Promise<void> {
|
||||
let responseData: any[] = []
|
||||
|
||||
if (isNative) {
|
||||
// Check if we need to migrate sessions from SDK mode
|
||||
// Auto-import cached SDK sessions on native mode startup
|
||||
if (needsMigration(instanceId)) {
|
||||
const existingSdkSessions = getExistingSdkSessions(instanceId)
|
||||
if (existingSdkSessions.length > 0) {
|
||||
log.info({ instanceId, count: existingSdkSessions.length }, "Migrating SDK sessions to native mode")
|
||||
const migrationData = existingSdkSessions.map(s => ({
|
||||
id: s.id,
|
||||
title: s.title,
|
||||
parentId: s.parentId,
|
||||
time: s.time,
|
||||
model: s.model,
|
||||
agent: s.agent
|
||||
}))
|
||||
const result = await migrateSessionsToNative(instanceId, migrationData)
|
||||
log.info({ instanceId, result }, "Migration completed")
|
||||
} else {
|
||||
markMigrated(instanceId)
|
||||
try {
|
||||
const result = await autoImportCachedSessions(instanceId)
|
||||
if (result.imported > 0) {
|
||||
log.info({ instanceId, result }, "Auto-imported SDK sessions to native mode")
|
||||
}
|
||||
} catch (error) {
|
||||
log.error({ instanceId, error }, "Failed to auto-import SDK sessions")
|
||||
markMigrated(instanceId) // Mark as migrated to prevent repeated failures
|
||||
}
|
||||
}
|
||||
|
||||
@@ -488,6 +481,12 @@ async function fetchSessions(instanceId: string): Promise<void> {
|
||||
return next
|
||||
})
|
||||
|
||||
// Cache SDK sessions to localStorage for later migration to native mode
|
||||
if (!isNative && sessionMap.size > 0) {
|
||||
cacheSDKSessions(instanceId, Array.from(sessionMap.values()))
|
||||
}
|
||||
|
||||
|
||||
setMessagesLoaded((prev) => {
|
||||
const next = new Map(prev)
|
||||
const loadedSet = next.get(instanceId)
|
||||
|
||||
Reference in New Issue
Block a user