فهرست منبع

Add todo list and session forking API endpoints

Dax Raad 4 ماه پیش
والد
کامیت
6417edf998
1فایلهای تغییر یافته به همراه60 افزوده شده و 0 حذف شده
  1. 60 0
      packages/opencode/src/server/server.ts

+ 60 - 0
packages/opencode/src/server/server.ts

@@ -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({