mirror of
https://github.com/sst/opencode.git
synced 2025-12-23 10:11:41 +00:00
prompt_async: Allows to receive prompt and return immediately, start … (#4664)
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:
parent
3b2aa7e91d
commit
b1aaa8570e
3 changed files with 95 additions and 0 deletions
|
|
@ -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({
|
||||
|
|
|
|||
|
|
@ -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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue