Skip to content

The open source coding agent.

TypeScript

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

Shantur Rathoreb1aaa8570eab
diff --git a/packages/opencode/src/server/server.ts b/packages/opencode/src/server/server.ts
index fec174454c2..51240ae2e9b 100644
--- a/packages/opencode/src/server/server.ts
+++ b/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(
"/session/:id/command",
describeRoute({
diff --git a/packages/sdk/js/src/gen/sdk.gen.ts b/packages/sdk/js/src/gen/sdk.gen.ts
index dc224799017..afc9696f1fa 100644
--- a/packages/sdk/js/src/gen/sdk.gen.ts
+++ b/packages/sdk/js/src/gen/sdk.gen.ts
@@ -75,6 +75,9 @@ import type {
SessionMessageData,
SessionMessageResponses,
SessionMessageErrors,
+ SessionPromptAsyncData,
+ SessionPromptAsyncResponses,
+ SessionPromptAsyncErrors,
SessionCommandData,
SessionCommandResponses,
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
*/
diff --git a/packages/sdk/js/src/gen/types.gen.ts b/packages/sdk/js/src/gen/types.gen.ts
index 3ba41cc2390..fdb6dcd6434 100644
--- a/packages/sdk/js/src/gen/types.gen.ts
+++ b/packages/sdk/js/src/gen/types.gen.ts
@@ -2301,6 +2301,55 @@ export type 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 = {
body?: {
messageID?: string