Fix Native Mode Sessions: implemented fork, revert, and sync for native sessions
This commit is contained in:
@@ -200,6 +200,54 @@ export class NativeSessionManager {
|
||||
return true
|
||||
}
|
||||
|
||||
async forkSession(workspaceId: string, sessionId: string): Promise<Session> {
|
||||
const store = await this.loadStore(workspaceId)
|
||||
const original = store.sessions[sessionId]
|
||||
if (!original) throw new Error(`Session not found: ${sessionId}`)
|
||||
|
||||
const now = Date.now()
|
||||
const forked: Session = {
|
||||
...original,
|
||||
id: ulid(),
|
||||
title: original.title ? `${original.title} (fork)` : "Forked Session",
|
||||
parentId: original.parentId || original.id,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
messageIds: [...original.messageIds], // Shallow copy of message IDs
|
||||
}
|
||||
|
||||
store.sessions[forked.id] = forked
|
||||
await this.saveStore(workspaceId)
|
||||
return forked
|
||||
}
|
||||
|
||||
async revert(workspaceId: string, sessionId: string, messageId?: string): Promise<Session> {
|
||||
const store = await this.loadStore(workspaceId)
|
||||
const session = store.sessions[sessionId]
|
||||
if (!session) throw new Error(`Session not found: ${sessionId}`)
|
||||
|
||||
if (!messageId) {
|
||||
// Revert last message
|
||||
if (session.messageIds.length > 0) {
|
||||
const lastId = session.messageIds.pop()
|
||||
if (lastId) delete store.messages[lastId]
|
||||
}
|
||||
} else {
|
||||
// Revert to specific message
|
||||
const index = session.messageIds.indexOf(messageId)
|
||||
if (index !== -1) {
|
||||
const toDelete = session.messageIds.splice(index + 1)
|
||||
for (const id of toDelete) {
|
||||
delete store.messages[id]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
session.updatedAt = Date.now()
|
||||
await this.saveStore(workspaceId)
|
||||
return session
|
||||
}
|
||||
|
||||
// Message operations
|
||||
|
||||
async getSessionMessages(workspaceId: string, sessionId: string): Promise<SessionMessage[]> {
|
||||
|
||||
Reference in New Issue
Block a user