Add todo list and session forking API endpoints

This commit is contained in:
Dax Raad
2025-10-06 18:51:57 -04:00
parent 9a0735de76
commit 6417edf998

View File

@@ -29,7 +29,9 @@ import { SessionPrompt } from "../session/prompt"
import { SessionCompaction } from "../session/compaction"
import { SessionRevert } from "../session/revert"
import { lazy } from "../util/lazy"
import { Todo } from "../session/todo"
import { InstanceBootstrap } from "../project/bootstrap"
import { Identifier } from "@/id/id"
const ERRORS = {
400: {
@@ -343,6 +345,34 @@ export namespace Server {
return c.json(session)
},
)
.get(
"/session/:id/todo",
describeRoute({
description: "Get the todo list for a session",
operationId: "session.todo",
responses: {
200: {
description: "Todo list",
content: {
"application/json": {
schema: resolver(Todo.Info.array()),
},
},
},
},
}),
validator(
"param",
z.object({
id: z.string().meta({ description: "Session ID" }),
}),
),
async (c) => {
const sessionID = c.req.valid("param").id
const todos = await Todo.get(sessionID)
return c.json(todos)
},
)
.post(
"/session",
describeRoute({
@@ -480,6 +510,36 @@ export namespace Server {
return c.json(true)
},
)
.post(
"/session/:id/fork",
describeRoute({
description: "Fork an existing session at a specific message",
operationId: "session.fork",
responses: {
200: {
description: "200",
content: {
"application/json": {
schema: resolver(Session.Info),
},
},
},
},
}),
validator(
"param",
z.object({
id: Identifier.schema("session").meta({ description: "Session ID" }),
}),
),
validator("json", Session.fork.schema.omit({ sessionID: true })),
async (c) => {
const sessionID = c.req.valid("param").id
const body = c.req.valid("json")
const result = await Session.fork({ ...body, sessionID })
return c.json(result)
},
)
.post(
"/session/:id/abort",
describeRoute({