(home: string = KIMI_CODE_HOME)
| 5 | import { listSessions, readSessionDetail } from '../lib/session-store'; |
| 6 | |
| 7 | export function sessionsRoute(home: string = KIMI_CODE_HOME): Hono { |
| 8 | const r = new Hono(); |
| 9 | r.get('/', async (c) => { |
| 10 | const sessions = await listSessions(home); |
| 11 | return c.json({ sessions }); |
| 12 | }); |
| 13 | r.delete('/:id', async (c) => { |
| 14 | const id = c.req.param('id'); |
| 15 | const all = await listSessions(home); |
| 16 | const target = all.find((s) => s.sessionId === id); |
| 17 | if (!target) return c.json({ error: 'session not found', code: 'NOT_FOUND' }, 404); |
| 18 | await rm(target.sessionDir, { recursive: true, force: true }); |
| 19 | return c.json({ sessionId: id, deleted: true }); |
| 20 | }); |
| 21 | // Open the session directory in the OS file manager. The folder is |
| 22 | // opened on the SERVER host — only meaningful when vis runs locally. |
| 23 | r.post('/:id/reveal', async (c) => { |
| 24 | const id = c.req.param('id'); |
| 25 | const detail = await readSessionDetail(home, id); |
| 26 | if (!detail) return c.json({ error: 'session not found', code: 'NOT_FOUND' }, 404); |
| 27 | try { |
| 28 | await revealInOs(detail.sessionDir); |
| 29 | return c.json({ sessionId: id, opened: detail.sessionDir }); |
| 30 | } catch (err) { |
| 31 | return c.json( |
| 32 | { error: `failed to open: ${(err as Error).message}`, code: 'READ_ERROR' }, |
| 33 | 500, |
| 34 | ); |
| 35 | } |
| 36 | }); |
| 37 | return r; |
| 38 | } |
no test coverage detected