Add automatic session migration when switching from SDK to Native mode
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,6 +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 { preferences, setAgentModelPreference, getAgentModelPreference } from "./preferences"
|
||||
import { setSessionCompactionState } from "./session-compaction"
|
||||
import {
|
||||
@@ -389,6 +390,26 @@ async function fetchSessions(instanceId: string): Promise<void> {
|
||||
let responseData: any[] = []
|
||||
|
||||
if (isNative) {
|
||||
// Check if we need to migrate sessions from SDK mode
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
const nativeSessions = await nativeSessionApi.listSessions(instanceId)
|
||||
responseData = nativeSessions.map(s => ({
|
||||
id: s.id,
|
||||
|
||||
Reference in New Issue
Block a user