prompt_async: Allows to receive prompt and return immediately, start … (#4664)
Some checks are pending
deploy / deploy (push) Waiting to run
format / format (push) Waiting to run
snapshot / publish (push) Waiting to run
test / test (push) Waiting to run
Update Nix Hashes / update (push) Waiting to run

Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
This commit is contained in:
Shantur Rathore 2025-11-25 05:52:57 +00:00 committed by GitHub
parent 3b2aa7e91d
commit b1aaa8570e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 95 additions and 0 deletions

View file

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

View file

@ -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
*/

View file

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