fix agent runner archive on web

This commit is contained in:
Alec Koifman
2025-12-12 11:15:44 -05:00
parent 813ede2dde
commit fade47afdc
2 changed files with 53 additions and 12 deletions

View File

@@ -245,26 +245,44 @@ export function SessionManager({
// Archive session
const handleArchiveSession = async (sessionId: string) => {
const api = getElectronAPI();
if (!api?.sessions) return;
if (!api?.sessions) {
console.error("[SessionManager] Sessions API not available");
return;
}
const result = await api.sessions.archive(sessionId);
if (result.success) {
// If the archived session was currently selected, deselect it
if (currentSessionId === sessionId) {
onSelectSession(null);
try {
const result = await api.sessions.archive(sessionId);
if (result.success) {
// If the archived session was currently selected, deselect it
if (currentSessionId === sessionId) {
onSelectSession(null);
}
await loadSessions();
} else {
console.error("[SessionManager] Archive failed:", result.error);
}
await loadSessions();
} catch (error) {
console.error("[SessionManager] Archive error:", error);
}
};
// Unarchive session
const handleUnarchiveSession = async (sessionId: string) => {
const api = getElectronAPI();
if (!api?.sessions) return;
if (!api?.sessions) {
console.error("[SessionManager] Sessions API not available");
return;
}
const result = await api.sessions.unarchive(sessionId);
if (result.success) {
await loadSessions();
try {
const result = await api.sessions.unarchive(sessionId);
if (result.success) {
await loadSessions();
} else {
console.error("[SessionManager] Unarchive failed:", result.error);
}
} catch (error) {
console.error("[SessionManager] Unarchive error:", error);
}
};

View File

@@ -12,7 +12,30 @@ export function createSessionsRoutes(agentService: AgentService): Router {
router.get("/", async (req: Request, res: Response) => {
try {
const includeArchived = req.query.includeArchived === "true";
const sessions = await agentService.listSessions(includeArchived);
const sessionsRaw = await agentService.listSessions(includeArchived);
// Transform to match frontend SessionListItem interface
const sessions = await Promise.all(
sessionsRaw.map(async (s) => {
const messages = await agentService.loadSession(s.id);
const lastMessage = messages[messages.length - 1];
const preview = lastMessage?.content?.slice(0, 100) || "";
return {
id: s.id,
name: s.name,
projectPath: s.projectPath || s.workingDirectory,
workingDirectory: s.workingDirectory,
createdAt: s.createdAt,
updatedAt: s.updatedAt,
isArchived: s.archived || false,
tags: s.tags || [],
messageCount: messages.length,
preview,
};
})
);
res.json({ success: true, sessions });
} catch (error) {
const message = error instanceof Error ? error.message : "Unknown error";