mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-20 09:14:22 +01:00
feat: add noReply parameter (#3433)
Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
ae62bc8b1f
commit
2e434a459a
@@ -94,6 +94,7 @@ export namespace SessionPrompt {
|
|||||||
})
|
})
|
||||||
.optional(),
|
.optional(),
|
||||||
agent: z.string().optional(),
|
agent: z.string().optional(),
|
||||||
|
noReply: z.boolean().optional(),
|
||||||
system: z.string().optional(),
|
system: z.string().optional(),
|
||||||
tools: z.record(z.string(), z.boolean()).optional(),
|
tools: z.record(z.string(), z.boolean()).optional(),
|
||||||
parts: z.array(
|
parts: z.array(
|
||||||
@@ -142,6 +143,11 @@ export namespace SessionPrompt {
|
|||||||
const userMsg = await createUserMessage(input)
|
const userMsg = await createUserMessage(input)
|
||||||
await Session.touch(input.sessionID)
|
await Session.touch(input.sessionID)
|
||||||
|
|
||||||
|
// Early return for context-only messages (no AI inference)
|
||||||
|
if (input.noReply) {
|
||||||
|
return userMsg
|
||||||
|
}
|
||||||
|
|
||||||
if (isBusy(input.sessionID)) {
|
if (isBusy(input.sessionID)) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const queue = state().queued.get(input.sessionID) ?? []
|
const queue = state().queued.get(input.sessionID) ?? []
|
||||||
|
|||||||
@@ -1894,6 +1894,7 @@ export type SessionPromptData = {
|
|||||||
modelID: string
|
modelID: string
|
||||||
}
|
}
|
||||||
agent?: string
|
agent?: string
|
||||||
|
noReply?: boolean
|
||||||
system?: string
|
system?: string
|
||||||
tools?: {
|
tools?: {
|
||||||
[key: string]: boolean
|
[key: string]: boolean
|
||||||
|
|||||||
@@ -210,7 +210,7 @@ const { providers, default: defaults } = await client.config.providers()
|
|||||||
### Sessions
|
### Sessions
|
||||||
|
|
||||||
| Method | Description | Notes |
|
| Method | Description | Notes |
|
||||||
| ---------------------------------------------------------- | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
|
| ---------------------------------------------------------- | ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| `session.list()` | List sessions | Returns <a href={typesUrl}><code>Session[]</code></a> |
|
| `session.list()` | List sessions | Returns <a href={typesUrl}><code>Session[]</code></a> |
|
||||||
| `session.get({ path })` | Get session | Returns <a href={typesUrl}><code>Session</code></a> |
|
| `session.get({ path })` | Get session | Returns <a href={typesUrl}><code>Session</code></a> |
|
||||||
| `session.children({ path })` | List child sessions | Returns <a href={typesUrl}><code>Session[]</code></a> |
|
| `session.children({ path })` | List child sessions | Returns <a href={typesUrl}><code>Session[]</code></a> |
|
||||||
@@ -224,7 +224,7 @@ const { providers, default: defaults } = await client.config.providers()
|
|||||||
| `session.summarize({ path, body })` | Summarize session | Returns `boolean` |
|
| `session.summarize({ path, body })` | Summarize session | Returns `boolean` |
|
||||||
| `session.messages({ path })` | List messages in a session | Returns `{ info: `<a href={typesUrl}><code>Message</code></a>`, parts: `<a href={typesUrl}><code>Part[]</code></a>`}[]` |
|
| `session.messages({ path })` | List messages in a session | Returns `{ info: `<a href={typesUrl}><code>Message</code></a>`, parts: `<a href={typesUrl}><code>Part[]</code></a>`}[]` |
|
||||||
| `session.message({ path })` | Get message details | Returns `{ info: `<a href={typesUrl}><code>Message</code></a>`, parts: `<a href={typesUrl}><code>Part[]</code></a>`}` |
|
| `session.message({ path })` | Get message details | Returns `{ info: `<a href={typesUrl}><code>Message</code></a>`, parts: `<a href={typesUrl}><code>Part[]</code></a>`}` |
|
||||||
| `session.prompt({ path, body })` | Send prompt message | Returns `{ info: `<a href={typesUrl}><code>AssistantMessage</code></a>`, parts: `<a href={typesUrl}><code>Part[]</code></a>`}` |
|
| `session.prompt({ path, body })` | Send prompt message | `body.noReply: true` returns UserMessage (context only). Default returns <a href={typesUrl}><code>AssistantMessage</code></a> with AI response |
|
||||||
| `session.command({ path, body })` | Send command to session | Returns `{ info: `<a href={typesUrl}><code>AssistantMessage</code></a>`, parts: `<a href={typesUrl}><code>Part[]</code></a>`}` |
|
| `session.command({ path, body })` | Send command to session | Returns `{ info: `<a href={typesUrl}><code>AssistantMessage</code></a>`, parts: `<a href={typesUrl}><code>Part[]</code></a>`}` |
|
||||||
| `session.shell({ path, body })` | Run a shell command | Returns <a href={typesUrl}><code>AssistantMessage</code></a> |
|
| `session.shell({ path, body })` | Run a shell command | Returns <a href={typesUrl}><code>AssistantMessage</code></a> |
|
||||||
| `session.revert({ path, body })` | Revert a message | Returns <a href={typesUrl}><code>Session</code></a> |
|
| `session.revert({ path, body })` | Revert a message | Returns <a href={typesUrl}><code>Session</code></a> |
|
||||||
@@ -251,6 +251,15 @@ const result = await client.session.prompt({
|
|||||||
parts: [{ type: "text", text: "Hello!" }],
|
parts: [{ type: "text", text: "Hello!" }],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Inject context without triggering AI response (useful for plugins)
|
||||||
|
await client.session.prompt({
|
||||||
|
path: { id: session.id },
|
||||||
|
body: {
|
||||||
|
noReply: true,
|
||||||
|
parts: [{ type: "text", text: "You are a helpful assistant." }],
|
||||||
|
},
|
||||||
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ The opencode server exposes the following APIs.
|
|||||||
### Sessions
|
### Sessions
|
||||||
|
|
||||||
| Method | Path | Description | Notes |
|
| Method | Path | Description | Notes |
|
||||||
| -------- | ---------------------------------------- | ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| -------- | ---------------------------------------- | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| `GET` | `/session` | List sessions | Returns <a href={typesUrl}><code>Session[]</code></a> |
|
| `GET` | `/session` | List sessions | Returns <a href={typesUrl}><code>Session[]</code></a> |
|
||||||
| `GET` | `/session/:id` | Get session | Returns <a href={typesUrl}><code>Session</code></a> |
|
| `GET` | `/session/:id` | Get session | Returns <a href={typesUrl}><code>Session</code></a> |
|
||||||
| `GET` | `/session/:id/children` | List child sessions | Returns <a href={typesUrl}><code>Session[]</code></a> |
|
| `GET` | `/session/:id/children` | List child sessions | Returns <a href={typesUrl}><code>Session[]</code></a> |
|
||||||
@@ -103,7 +103,7 @@ The opencode server exposes the following APIs.
|
|||||||
| `POST` | `/session/:id/summarize` | Summarize session | |
|
| `POST` | `/session/:id/summarize` | Summarize session | |
|
||||||
| `GET` | `/session/:id/message` | List messages in a session | Returns `{ info: `<a href={typesUrl}>Message</a>`, parts: `<a href={typesUrl}>Part[]</a>`}[]` |
|
| `GET` | `/session/:id/message` | List messages in a session | Returns `{ info: `<a href={typesUrl}>Message</a>`, parts: `<a href={typesUrl}>Part[]</a>`}[]` |
|
||||||
| `GET` | `/session/:id/message/:messageID` | Get message details | Returns `{ info: `<a href={typesUrl}>Message</a>`, parts: `<a href={typesUrl}>Part[]</a>`}` |
|
| `GET` | `/session/:id/message/:messageID` | Get message details | Returns `{ info: `<a href={typesUrl}>Message</a>`, parts: `<a href={typesUrl}>Part[]</a>`}` |
|
||||||
| `POST` | `/session/:id/message` | Send chat message | body matches [`ChatInput`](https://github.com/sst/opencode/blob/main/packages/opencode/src/session/index.ts#L358), returns <a href={typesUrl}><code>Message</code></a> |
|
| `POST` | `/session/:id/message` | Send chat message | body matches [`ChatInput`](https://github.com/sst/opencode/blob/main/packages/opencode/src/session/index.ts#L358). Optional `noReply: true` skips AI inference and returns UserMessage. Returns <a href={typesUrl}><code>Message</code></a> |
|
||||||
| `POST` | `/session/:id/shell` | Run a shell command | body matches [`CommandInput`](https://github.com/sst/opencode/blob/main/packages/opencode/src/session/index.ts#L1007), returns <a href={typesUrl}><code>Message</code></a> |
|
| `POST` | `/session/:id/shell` | Run a shell command | body matches [`CommandInput`](https://github.com/sst/opencode/blob/main/packages/opencode/src/session/index.ts#L1007), returns <a href={typesUrl}><code>Message</code></a> |
|
||||||
| `POST` | `/session/:id/revert` | Revert a message | body: `{ messageID }` |
|
| `POST` | `/session/:id/revert` | Revert a message | body: `{ messageID }` |
|
||||||
| `POST` | `/session/:id/unrevert` | Restore reverted messages | |
|
| `POST` | `/session/:id/unrevert` | Restore reverted messages | |
|
||||||
|
|||||||
Reference in New Issue
Block a user