feat(plugin): add session options hook
This commit is contained in:
parent
1f2de535aa
commit
d927f6fa8d
18 changed files with 320 additions and 57 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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<
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue