feat(plugin): add session options hook

This commit is contained in:
Aiden Cline 2026-07-18 17:00:43 +00:00 committed by 𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴
commit d927f6fa8d
18 changed files with 320 additions and 57 deletions

View file

@ -92,6 +92,20 @@ yield *
)
```
Resolved generation and provider options are mutable before provider lowering:
```ts
yield *
ctx.session.hook("options", (event) =>
Effect.sync(() => {
event.generation.temperature = 0.2
event.generation.topP = 0.9
event.providerOptions.openai ??= {}
event.providerOptions.openai.reasoningEffort = "high"
}),
)
```
## Reloading A Domain
When data captured by a transform changes, reload the affected domain:

View file

@ -1,5 +1,5 @@
import type { SessionApi } from "@opencode-ai/client/effect/api"
import type { Message, SystemPart } from "@opencode-ai/ai"
import type { GenerationOptionsFields, Message, SystemPart } from "@opencode-ai/ai"
import type { Agent } from "@opencode-ai/schema/agent"
import type { Model } from "@opencode-ai/schema/model"
import type { Session } from "@opencode-ai/schema/session"
@ -15,8 +15,23 @@ export interface SessionContext {
tools: Record<string, { description: string; input: JsonSchema.JsonSchema }>
}
export type SessionGenerationOptions = {
-readonly [Key in keyof GenerationOptionsFields]: GenerationOptionsFields[Key]
}
export type SessionProviderOptions = Record<string, Record<string, unknown>>
export interface SessionOptions {
readonly sessionID: Session.ID
readonly agent: Agent.ID
readonly model: Model.Ref
generation: SessionGenerationOptions
providerOptions: SessionProviderOptions
}
export interface SessionHooks {
readonly context: SessionContext
readonly options: SessionOptions
}
export type SessionDomain = Pick<

View file

@ -94,6 +94,17 @@ await ctx.session.hook("context", (event) => {
})
```
Resolved generation and provider options are mutable before provider lowering:
```ts
await ctx.session.hook("options", (event) => {
event.generation.temperature = 0.2
event.generation.topP = 0.9
event.providerOptions.openai ??= {}
event.providerOptions.openai.reasoningEffort = "high"
})
```
Promise tools use plain object declarations with async executors:
```ts

View file

@ -1,5 +1,5 @@
import type { SessionApi } from "@opencode-ai/client/promise/api"
import type { Message, SystemPart } from "@opencode-ai/ai"
import type { GenerationOptionsFields, Message, SystemPart } from "@opencode-ai/ai"
import type { Agent } from "@opencode-ai/schema/agent"
import type { Model } from "@opencode-ai/schema/model"
import type { Session } from "@opencode-ai/schema/session"
@ -15,8 +15,23 @@ export interface SessionContext {
tools: Record<string, { description: string; input: JsonSchema.JsonSchema }>
}
export type SessionGenerationOptions = {
-readonly [Key in keyof GenerationOptionsFields]: GenerationOptionsFields[Key]
}
export type SessionProviderOptions = Record<string, Record<string, unknown>>
export interface SessionOptions {
readonly sessionID: Session.ID
readonly agent: Agent.ID
readonly model: Model.Ref
generation: SessionGenerationOptions
providerOptions: SessionProviderOptions
}
export interface SessionHooks {
readonly context: SessionContext
readonly options: SessionOptions
}
export type SessionDomain = Pick<