fix: archive session

This commit is contained in:
weishu
2026-01-03 10:31:54 +08:00
parent d87250aff2
commit bc602ff5ea
7 changed files with 51 additions and 5 deletions
+1
View File
@@ -58,6 +58,7 @@ export class AgentSessionBase<Mode> {
this.keepAliveInterval = setInterval(() => {
this.client.keepAlive(this.thinking, this.mode, this.getKeepAliveRuntime());
}, 2000);
}
onThinkingChange = (thinking: boolean) => {
+5
View File
@@ -728,6 +728,11 @@ export class SyncEngine {
await this.sessionRpc(sessionId, 'abort', { reason: 'User aborted via Telegram Bot' })
}
async archiveSession(sessionId: string): Promise<void> {
await this.sessionRpc(sessionId, 'killSession', {})
this.handleSessionEnd({ sid: sessionId, time: Date.now() })
}
async switchSession(sessionId: string, to: 'remote' | 'local'): Promise<void> {
await this.sessionRpc(sessionId, 'switch', { to })
}
+15
View File
@@ -132,6 +132,21 @@ export function createSessionsRoutes(getSyncEngine: () => SyncEngine | null): Ho
return c.json({ ok: true })
})
app.post('/sessions/:id/archive', async (c) => {
const engine = requireSyncEngine(c, getSyncEngine)
if (engine instanceof Response) {
return engine
}
const sessionResult = requireSessionFromParam(c, engine, { requireActive: true })
if (sessionResult instanceof Response) {
return sessionResult
}
await engine.archiveSession(sessionResult.sessionId)
return c.json({ ok: true })
})
app.post('/sessions/:id/switch', async (c) => {
const engine = requireSyncEngine(c, getSyncEngine)
if (engine instanceof Response) {
+7
View File
@@ -239,6 +239,13 @@ export class ApiClient {
})
}
async archiveSession(sessionId: string): Promise<void> {
await this.request(`/api/sessions/${encodeURIComponent(sessionId)}/archive`, {
method: 'POST',
body: JSON.stringify({})
})
}
async switchSession(sessionId: string): Promise<void> {
await this.request(`/api/sessions/${encodeURIComponent(sessionId)}/switch`, {
method: 'POST',
+2 -2
View File
@@ -74,7 +74,7 @@ export function SessionHeader(props: {
const [archiveOpen, setArchiveOpen] = useState(false)
const [deleteOpen, setDeleteOpen] = useState(false)
const { abortSession, renameSession, deleteSession, isPending } = useSessionActions(api, session.id)
const { archiveSession, renameSession, deleteSession, isPending } = useSessionActions(api, session.id)
const handleDelete = async () => {
await deleteSession()
@@ -168,7 +168,7 @@ export function SessionHeader(props: {
description={`Are you sure you want to archive "${title}"? This will disconnect the active session.`}
confirmLabel="Archive"
confirmingLabel="Archiving..."
onConfirm={abortSession}
onConfirm={archiveSession}
isPending={isPending}
destructive
/>
+2 -2
View File
@@ -177,7 +177,7 @@ function SessionItem(props: {
const [archiveOpen, setArchiveOpen] = useState(false)
const [deleteOpen, setDeleteOpen] = useState(false)
const { abortSession, renameSession, deleteSession, isPending } = useSessionActions(api, s.id)
const { archiveSession, renameSession, deleteSession, isPending } = useSessionActions(api, s.id)
const longPressHandlers = useLongPress({
onLongPress: () => {
@@ -273,7 +273,7 @@ function SessionItem(props: {
description={`Are you sure you want to archive "${sessionName}"? This will disconnect the active session.`}
confirmLabel="Archive"
confirmingLabel="Archiving..."
onConfirm={abortSession}
onConfirm={archiveSession}
isPending={isPending}
destructive
/>
+19 -1
View File
@@ -22,6 +22,7 @@ function toModelMode(mode: ModelMode): ModelModeValue {
export function useSessionActions(api: ApiClient | null, sessionId: string | null): {
abortSession: () => Promise<void>
archiveSession: () => Promise<void>
switchSession: () => Promise<void>
setPermissionMode: (mode: PermissionMode) => Promise<void>
setModelMode: (mode: ModelMode) => Promise<void>
@@ -47,6 +48,16 @@ export function useSessionActions(api: ApiClient | null, sessionId: string | nul
onSuccess: () => void invalidateSession(),
})
const archiveMutation = useMutation({
mutationFn: async () => {
if (!api || !sessionId) {
throw new Error('Session unavailable')
}
await api.archiveSession(sessionId)
},
onSuccess: () => void invalidateSession(),
})
const switchMutation = useMutation({
mutationFn: async () => {
if (!api || !sessionId) {
@@ -104,11 +115,18 @@ export function useSessionActions(api: ApiClient | null, sessionId: string | nul
return {
abortSession: abortMutation.mutateAsync,
archiveSession: archiveMutation.mutateAsync,
switchSession: switchMutation.mutateAsync,
setPermissionMode: permissionMutation.mutateAsync,
setModelMode: modelMutation.mutateAsync,
renameSession: renameMutation.mutateAsync,
deleteSession: deleteMutation.mutateAsync,
isPending: abortMutation.isPending || switchMutation.isPending || permissionMutation.isPending || modelMutation.isPending || renameMutation.isPending || deleteMutation.isPending,
isPending: abortMutation.isPending
|| archiveMutation.isPending
|| switchMutation.isPending
|| permissionMutation.isPending
|| modelMutation.isPending
|| renameMutation.isPending
|| deleteMutation.isPending,
}
}