✨ feat(vscode): 会话管理支持导入已 /rename 的命名会话
This commit is contained in:
@@ -12,6 +12,12 @@ import type { ManagedSessionsData } from '../types'
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import { onMessage, postMessage } from '../lib/vscode'
|
||||
|
||||
export interface ImportableNamedSession {
|
||||
id: string
|
||||
name: string
|
||||
mtimeMs: number
|
||||
}
|
||||
|
||||
export interface UseManagedSessionsResult {
|
||||
managedSessions: ManagedSessionsData
|
||||
createManagedSession: (profilePath: string, name?: string, prompt?: string) => void
|
||||
@@ -19,15 +25,25 @@ export interface UseManagedSessionsResult {
|
||||
resumeManagedSession: (id: string) => void
|
||||
deleteManagedSession: (id: string) => void
|
||||
closeManagedSessionTab: (id: string) => void
|
||||
listImportableNamedSessions: () => void
|
||||
importNamedSession: (sessionId: string, name: string) => void
|
||||
importableSessions: ImportableNamedSession[]
|
||||
importableLoading: boolean
|
||||
}
|
||||
|
||||
export function useManagedSessions(): UseManagedSessionsResult {
|
||||
const [managedSessions, setManagedSessions] = useState<ManagedSessionsData>({ sessions: [] })
|
||||
const [importableSessions, setImportableSessions] = useState<ImportableNamedSession[]>([])
|
||||
const [importableLoading, setImportableLoading] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
const cleanup = onMessage((msg) => {
|
||||
if (msg.type === 'managed-sessions/show')
|
||||
setManagedSessions(msg.data)
|
||||
if (msg.type === 'managed-sessions/importable') {
|
||||
setImportableSessions(msg.sessions)
|
||||
setImportableLoading(false)
|
||||
}
|
||||
})
|
||||
postMessage({ type: 'managed-sessions/get' })
|
||||
return cleanup
|
||||
@@ -53,6 +69,16 @@ export function useManagedSessions(): UseManagedSessionsResult {
|
||||
postMessage({ type: 'managed-sessions/close-tab', sessionId: id })
|
||||
}, [])
|
||||
|
||||
const listImportableNamedSessions = useCallback((): void => {
|
||||
setImportableLoading(true)
|
||||
setImportableSessions([])
|
||||
postMessage({ type: 'managed-sessions/list-importable' })
|
||||
}, [])
|
||||
|
||||
const importNamedSession = useCallback((sessionId: string, name: string): void => {
|
||||
postMessage({ type: 'managed-sessions/import', sessionId, name })
|
||||
}, [])
|
||||
|
||||
return {
|
||||
managedSessions,
|
||||
createManagedSession,
|
||||
@@ -60,5 +86,9 @@ export function useManagedSessions(): UseManagedSessionsResult {
|
||||
resumeManagedSession,
|
||||
deleteManagedSession,
|
||||
closeManagedSessionTab,
|
||||
listImportableNamedSessions,
|
||||
importNamedSession,
|
||||
importableSessions,
|
||||
importableLoading,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user