mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-21 17:54:23 +01:00
Add todo list and session forking API endpoints
This commit is contained in:
@@ -29,7 +29,9 @@ import { SessionPrompt } from "../session/prompt"
|
|||||||
import { SessionCompaction } from "../session/compaction"
|
import { SessionCompaction } from "../session/compaction"
|
||||||
import { SessionRevert } from "../session/revert"
|
import { SessionRevert } from "../session/revert"
|
||||||
import { lazy } from "../util/lazy"
|
import { lazy } from "../util/lazy"
|
||||||
|
import { Todo } from "../session/todo"
|
||||||
import { InstanceBootstrap } from "../project/bootstrap"
|
import { InstanceBootstrap } from "../project/bootstrap"
|
||||||
|
import { Identifier } from "@/id/id"
|
||||||
|
|
||||||
const ERRORS = {
|
const ERRORS = {
|
||||||
400: {
|
400: {
|
||||||
@@ -343,6 +345,34 @@ export namespace Server {
|
|||||||
return c.json(session)
|
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(
|
.post(
|
||||||
"/session",
|
"/session",
|
||||||
describeRoute({
|
describeRoute({
|
||||||
@@ -480,6 +510,36 @@ export namespace Server {
|
|||||||
return c.json(true)
|
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(
|
.post(
|
||||||
"/session/:id/abort",
|
"/session/:id/abort",
|
||||||
describeRoute({
|
describeRoute({
|
||||||
|
|||||||
Reference in New Issue
Block a user