Selaa lähdekoodia

chore: generate

opencode-agent[bot] 3 kuukautta sitten
vanhempi
commit
f70afbea34

+ 16 - 14
packages/opencode/src/server/routes/instance/httpapi/handlers/v2/message.ts

@@ -42,21 +42,23 @@ export const messageHandlers = HttpApiBuilder.group(InstanceHttpApi, "v2.message
           catch: () => new InvalidCursorError({ message: "Invalid cursor" }),
         })
         const order = decoded?.order ?? ctx.query.order ?? "desc"
-        const messages = yield* session.messages({
-          sessionID: ctx.params.sessionID,
-          limit: ctx.query.limit ?? DefaultMessagesLimit,
-          order,
-          cursor: decoded ? { id: decoded.id, time: decoded.time, direction: decoded.direction } : undefined,
-        }).pipe(
-          Effect.catchTag("Session.NotFoundError", (error) =>
-            Effect.fail(
-              new SessionNotFoundError({
-                sessionID: error.sessionID,
-                message: `Session not found: ${error.sessionID}`,
-              }),
+        const messages = yield* session
+          .messages({
+            sessionID: ctx.params.sessionID,
+            limit: ctx.query.limit ?? DefaultMessagesLimit,
+            order,
+            cursor: decoded ? { id: decoded.id, time: decoded.time, direction: decoded.direction } : undefined,
+          })
+          .pipe(
+            Effect.catchTag("Session.NotFoundError", (error) =>
+              Effect.fail(
+                new SessionNotFoundError({
+                  sessionID: error.sessionID,
+                  message: `Session not found: ${error.sessionID}`,
+                }),
+              ),
             ),
-          ),
-        )
+          )
         const first = messages[0]
         const last = messages.at(-1)
         return {

+ 39 - 43
packages/opencode/src/server/routes/instance/httpapi/handlers/v2/session.ts

@@ -133,27 +133,12 @@ export const sessionHandlers = HttpApiBuilder.group(InstanceHttpApi, "v2.session
       .handle(
         "prompt",
         Effect.fn(function* (ctx) {
-          return yield* session.prompt({
-            sessionID: ctx.params.sessionID,
-            prompt: ctx.payload.prompt,
-            delivery: ctx.payload.delivery ?? SessionV2.DefaultDelivery,
-          }).pipe(
-            Effect.catchTag("Session.NotFoundError", (error) =>
-              Effect.fail(
-                new SessionNotFoundError({
-                  sessionID: error.sessionID,
-                  message: `Session not found: ${error.sessionID}`,
-                }),
-              ),
-            ),
-          )
-        }),
-      )
-      .handle(
-        "compact",
-        Effect.fn(function* (ctx) {
-          yield* session
-            .compact(ctx.params.sessionID)
+          return yield* session
+            .prompt({
+              sessionID: ctx.params.sessionID,
+              prompt: ctx.payload.prompt,
+              delivery: ctx.payload.delivery ?? SessionV2.DefaultDelivery,
+            })
             .pipe(
               Effect.catchTag("Session.NotFoundError", (error) =>
                 Effect.fail(
@@ -164,42 +149,53 @@ export const sessionHandlers = HttpApiBuilder.group(InstanceHttpApi, "v2.session
                 ),
               ),
             )
+        }),
+      )
+      .handle(
+        "compact",
+        Effect.fn(function* (ctx) {
+          yield* session.compact(ctx.params.sessionID).pipe(
+            Effect.catchTag("Session.NotFoundError", (error) =>
+              Effect.fail(
+                new SessionNotFoundError({
+                  sessionID: error.sessionID,
+                  message: `Session not found: ${error.sessionID}`,
+                }),
+              ),
+            ),
+          )
           return HttpApiSchema.NoContent.make()
         }),
       )
       .handle(
         "wait",
         Effect.fn(function* (ctx) {
-          yield* session
-            .wait(ctx.params.sessionID)
-            .pipe(
-              Effect.catchTag("Session.NotFoundError", (error) =>
-                Effect.fail(
-                  new SessionNotFoundError({
-                    sessionID: error.sessionID,
-                    message: `Session not found: ${error.sessionID}`,
-                  }),
-                ),
+          yield* session.wait(ctx.params.sessionID).pipe(
+            Effect.catchTag("Session.NotFoundError", (error) =>
+              Effect.fail(
+                new SessionNotFoundError({
+                  sessionID: error.sessionID,
+                  message: `Session not found: ${error.sessionID}`,
+                }),
               ),
-            )
+            ),
+          )
           return HttpApiSchema.NoContent.make()
         }),
       )
       .handle(
         "context",
         Effect.fn(function* (ctx) {
-          return yield* session
-            .context(ctx.params.sessionID)
-            .pipe(
-              Effect.catchTag("Session.NotFoundError", (error) =>
-                Effect.fail(
-                  new SessionNotFoundError({
-                    sessionID: error.sessionID,
-                    message: `Session not found: ${error.sessionID}`,
-                  }),
-                ),
+          return yield* session.context(ctx.params.sessionID).pipe(
+            Effect.catchTag("Session.NotFoundError", (error) =>
+              Effect.fail(
+                new SessionNotFoundError({
+                  sessionID: error.sessionID,
+                  message: `Session not found: ${error.sessionID}`,
+                }),
               ),
-            )
+            ),
+          )
         }),
       )
   }),

+ 26 - 0
packages/sdk/js/src/v2/gen/types.gen.ts

@@ -1823,6 +1823,12 @@ export type UnauthorizedError = {
   message: string
 }
 
+export type SessionNotFoundError = {
+  _tag: "SessionNotFoundError"
+  sessionID: string
+  message: string
+}
+
 export type V2SessionMessagesResponse = {
   items: Array<SessionMessage>
   cursor: {
@@ -7174,6 +7180,10 @@ export type V2SessionPromptErrors = {
    * UnauthorizedError
    */
   401: UnauthorizedError
+  /**
+   * SessionNotFoundError
+   */
+  404: SessionNotFoundError
 }
 
 export type V2SessionPromptError = V2SessionPromptErrors[keyof V2SessionPromptErrors]
@@ -7208,6 +7218,10 @@ export type V2SessionCompactErrors = {
    * UnauthorizedError
    */
   401: UnauthorizedError
+  /**
+   * SessionNotFoundError
+   */
+  404: SessionNotFoundError
 }
 
 export type V2SessionCompactError = V2SessionCompactErrors[keyof V2SessionCompactErrors]
@@ -7242,6 +7256,10 @@ export type V2SessionWaitErrors = {
    * UnauthorizedError
    */
   401: UnauthorizedError
+  /**
+   * SessionNotFoundError
+   */
+  404: SessionNotFoundError
 }
 
 export type V2SessionWaitError = V2SessionWaitErrors[keyof V2SessionWaitErrors]
@@ -7276,6 +7294,10 @@ export type V2SessionContextErrors = {
    * UnauthorizedError
    */
   401: UnauthorizedError
+  /**
+   * SessionNotFoundError
+   */
+  404: SessionNotFoundError
 }
 
 export type V2SessionContextError = V2SessionContextErrors[keyof V2SessionContextErrors]
@@ -7316,6 +7338,10 @@ export type V2SessionMessagesErrors = {
    * UnauthorizedError
    */
   401: UnauthorizedError
+  /**
+   * SessionNotFoundError
+   */
+  404: SessionNotFoundError
 }
 
 export type V2SessionMessagesError = V2SessionMessagesErrors[keyof V2SessionMessagesErrors]

+ 67 - 0
packages/sdk/openapi.json

@@ -8217,6 +8217,16 @@
                 }
               }
             }
+          },
+          "404": {
+            "description": "SessionNotFoundError",
+            "content": {
+              "application/json": {
+                "schema": {
+                  "$ref": "#/components/schemas/SessionNotFoundError"
+                }
+              }
+            }
           }
         },
         "description": "Create a v2 session message and queue it for the agent loop.",
@@ -8303,6 +8313,16 @@
                 }
               }
             }
+          },
+          "404": {
+            "description": "SessionNotFoundError",
+            "content": {
+              "application/json": {
+                "schema": {
+                  "$ref": "#/components/schemas/SessionNotFoundError"
+                }
+              }
+            }
           }
         },
         "description": "Compact a v2 session conversation.",
@@ -8370,6 +8390,16 @@
                 }
               }
             }
+          },
+          "404": {
+            "description": "SessionNotFoundError",
+            "content": {
+              "application/json": {
+                "schema": {
+                  "$ref": "#/components/schemas/SessionNotFoundError"
+                }
+              }
+            }
           }
         },
         "description": "Wait for a v2 session agent loop to become idle.",
@@ -8447,6 +8477,16 @@
                 }
               }
             }
+          },
+          "404": {
+            "description": "SessionNotFoundError",
+            "content": {
+              "application/json": {
+                "schema": {
+                  "$ref": "#/components/schemas/SessionNotFoundError"
+                }
+              }
+            }
           }
         },
         "description": "Retrieve the active context messages for a v2 session (all messages after the last compaction).",
@@ -8554,6 +8594,16 @@
                 }
               }
             }
+          },
+          "404": {
+            "description": "SessionNotFoundError",
+            "content": {
+              "application/json": {
+                "schema": {
+                  "$ref": "#/components/schemas/SessionNotFoundError"
+                }
+              }
+            }
           }
         },
         "description": "Retrieve projected v2 messages for a session. Items keep the requested order across pages; use cursor.next or cursor.previous to move through the ordered timeline.",
@@ -15618,6 +15668,23 @@
         "required": ["_tag", "message"],
         "additionalProperties": false
       },
+      "SessionNotFoundError": {
+        "type": "object",
+        "properties": {
+          "_tag": {
+            "type": "string",
+            "enum": ["SessionNotFoundError"]
+          },
+          "sessionID": {
+            "type": "string"
+          },
+          "message": {
+            "type": "string"
+          }
+        },
+        "required": ["_tag", "sessionID", "message"],
+        "additionalProperties": false
+      },
       "V2SessionMessagesResponse": {
         "type": "object",
         "properties": {