Просмотр исходного кода

prompt_async: Allows to receive prompt and return immediately, start … (#4664)

Co-authored-by: Aiden Cline <[email protected]>
Co-authored-by: Aiden Cline <[email protected]>
Shantur Rathore 2 месяцев назад
Родитель
Сommit
b1aaa8570e

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

@@ -979,6 +979,35 @@ export namespace Server {
           })
           })
         },
         },
       )
       )
+      .post(
+        "/session/:id/prompt_async",
+        describeRoute({
+          description: "Create and send a new message to a session, start if needed and return immediately",
+          operationId: "session.prompt_async",
+          responses: {
+            204: {
+              description: "Prompt accepted",
+            },
+            ...errors(400, 404),
+          },
+        }),
+        validator(
+          "param",
+          z.object({
+            id: z.string().meta({ description: "Session ID" }),
+          }),
+        ),
+        validator("json", SessionPrompt.PromptInput.omit({ sessionID: true })),
+        async (c) => {
+          c.status(204)
+          c.header("Content-Type", "application/json")
+          return stream(c, async (stream) => {
+            const sessionID = c.req.valid("param").id
+            const body = c.req.valid("json")
+            SessionPrompt.prompt({ ...body, sessionID })
+          })
+        },
+      )
       .post(
       .post(
         "/session/:id/command",
         "/session/:id/command",
         describeRoute({
         describeRoute({

+ 17 - 0
packages/sdk/js/src/gen/sdk.gen.ts

@@ -75,6 +75,9 @@ import type {
   SessionMessageData,
   SessionMessageData,
   SessionMessageResponses,
   SessionMessageResponses,
   SessionMessageErrors,
   SessionMessageErrors,
+  SessionPromptAsyncData,
+  SessionPromptAsyncResponses,
+  SessionPromptAsyncErrors,
   SessionCommandData,
   SessionCommandData,
   SessionCommandResponses,
   SessionCommandResponses,
   SessionCommandErrors,
   SessionCommandErrors,
@@ -513,6 +516,20 @@ class Session extends _HeyApiClient {
     })
     })
   }
   }
 
 
+  /**
+   * Create and send a new message to a session, start if needed and return immediately
+   */
+  public promptAsync<ThrowOnError extends boolean = false>(options: Options<SessionPromptAsyncData, ThrowOnError>) {
+    return (options.client ?? this._client).post<SessionPromptAsyncResponses, SessionPromptAsyncErrors, ThrowOnError>({
+      url: "/session/{id}/prompt_async",
+      ...options,
+      headers: {
+        "Content-Type": "application/json",
+        ...options.headers,
+      },
+    })
+  }
+
   /**
   /**
    * Send a new command to a session
    * Send a new command to a session
    */
    */

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

@@ -2301,6 +2301,55 @@ export type SessionMessageResponses = {
 
 
 export type SessionMessageResponse = SessionMessageResponses[keyof SessionMessageResponses]
 export type SessionMessageResponse = SessionMessageResponses[keyof SessionMessageResponses]
 
 
+export type SessionPromptAsyncData = {
+  body?: {
+    messageID?: string
+    model?: {
+      providerID: string
+      modelID: string
+    }
+    agent?: string
+    noReply?: boolean
+    system?: string
+    tools?: {
+      [key: string]: boolean
+    }
+    parts: Array<TextPartInput | FilePartInput | AgentPartInput | SubtaskPartInput>
+  }
+  path: {
+    /**
+     * Session ID
+     */
+    id: string
+  }
+  query?: {
+    directory?: string
+  }
+  url: "/session/{id}/prompt_async"
+}
+
+export type SessionPromptAsyncErrors = {
+  /**
+   * Bad request
+   */
+  400: BadRequestError
+  /**
+   * Not found
+   */
+  404: NotFoundError
+}
+
+export type SessionPromptAsyncError = SessionPromptAsyncErrors[keyof SessionPromptAsyncErrors]
+
+export type SessionPromptAsyncResponses = {
+  /**
+   * Prompt accepted
+   */
+  204: void
+}
+
+export type SessionPromptAsyncResponse = SessionPromptAsyncResponses[keyof SessionPromptAsyncResponses]
+
 export type SessionCommandData = {
 export type SessionCommandData = {
   body?: {
   body?: {
     messageID?: string
     messageID?: string