feat(plugin): restore ai request hook
This commit is contained in:
parent
b95a5dc259
commit
f2f5eb6f16
19 changed files with 261 additions and 10 deletions
|
|
@ -80,14 +80,16 @@ yield *
|
|||
|
||||
Hooks run sequentially in registration order. Later hooks observe mutations made by earlier hooks.
|
||||
|
||||
Session request context is mutable immediately before provider dispatch:
|
||||
AI request context is mutable immediately before provider dispatch:
|
||||
|
||||
```ts
|
||||
yield *
|
||||
ctx.session.hook("request", (event) => {
|
||||
event.tools.read.description = "Read a file using narrow line ranges."
|
||||
delete event.tools.write
|
||||
})
|
||||
ctx.ai.hook("request", (event) =>
|
||||
Effect.sync(() => {
|
||||
event.tools.read.description = "Read a file using narrow line ranges."
|
||||
delete event.tools.write
|
||||
}),
|
||||
)
|
||||
```
|
||||
|
||||
## Reloading A Domain
|
||||
|
|
|
|||
23
packages/plugin/src/v2/effect/ai.ts
Normal file
23
packages/plugin/src/v2/effect/ai.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import type { 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"
|
||||
import type { JsonSchema } from "effect"
|
||||
import type { Hooks } from "./registration.js"
|
||||
|
||||
export interface AIRequest {
|
||||
readonly sessionID: Session.ID
|
||||
readonly agent: Agent.ID
|
||||
readonly model: Model.Ref
|
||||
system: Array<SystemPart>
|
||||
messages: Array<Message>
|
||||
tools: Record<string, { description: string; input: JsonSchema.JsonSchema }>
|
||||
}
|
||||
|
||||
export interface AIHooks {
|
||||
readonly request: AIRequest
|
||||
}
|
||||
|
||||
export interface AIDomain {
|
||||
readonly hook: Hooks<AIHooks>
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ import type { PluginApi } from "@opencode-ai/client/effect/api"
|
|||
import type { Effect, Scope } from "effect"
|
||||
import type { PluginOptions } from "../options.js"
|
||||
import type { AgentDomain } from "./agent.js"
|
||||
import type { AIDomain } from "./ai.js"
|
||||
import type { AISDKDomain } from "./aisdk.js"
|
||||
import type { CatalogDomain } from "./catalog.js"
|
||||
import type { CommandDomain } from "./command.js"
|
||||
|
|
@ -15,6 +16,7 @@ import type { ToolDomain } from "./tool.js"
|
|||
export interface Context {
|
||||
readonly options: PluginOptions
|
||||
readonly agent: AgentDomain
|
||||
readonly ai: AIDomain
|
||||
readonly aisdk: AISDKDomain
|
||||
readonly catalog: CatalogDomain
|
||||
readonly command: CommandDomain
|
||||
|
|
|
|||
|
|
@ -85,10 +85,10 @@ await ctx.aisdk.hook("language", (event) => {
|
|||
})
|
||||
```
|
||||
|
||||
Session request context is mutable immediately before provider dispatch:
|
||||
AI request context is mutable immediately before provider dispatch:
|
||||
|
||||
```ts
|
||||
await ctx.session.hook("request", (event) => {
|
||||
await ctx.ai.hook("request", (event) => {
|
||||
event.tools.read.description = "Read a file using narrow line ranges."
|
||||
delete event.tools.write
|
||||
})
|
||||
|
|
|
|||
23
packages/plugin/src/v2/promise/ai.ts
Normal file
23
packages/plugin/src/v2/promise/ai.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import type { 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"
|
||||
import type { JsonSchema } from "effect"
|
||||
import type { Hooks } from "./registration.js"
|
||||
|
||||
export interface AIRequest {
|
||||
readonly sessionID: Session.ID
|
||||
readonly agent: Agent.ID
|
||||
readonly model: Model.Ref
|
||||
system: Array<SystemPart>
|
||||
messages: Array<Message>
|
||||
tools: Record<string, { description: string; input: JsonSchema.JsonSchema }>
|
||||
}
|
||||
|
||||
export interface AIHooks {
|
||||
readonly request: AIRequest
|
||||
}
|
||||
|
||||
export interface AIDomain {
|
||||
readonly hook: Hooks<AIHooks>
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
import type { PluginApi } from "@opencode-ai/client/promise/api"
|
||||
import type { PluginOptions } from "../options.js"
|
||||
import type { AgentDomain } from "./agent.js"
|
||||
import type { AIDomain } from "./ai.js"
|
||||
import type { AISDKDomain } from "./aisdk.js"
|
||||
import type { CatalogDomain } from "./catalog.js"
|
||||
import type { CommandDomain } from "./command.js"
|
||||
|
|
@ -14,6 +15,7 @@ import type { ToolDomain } from "./tool.js"
|
|||
export interface Context {
|
||||
readonly options: PluginOptions
|
||||
readonly agent: AgentDomain
|
||||
readonly ai: AIDomain
|
||||
readonly aisdk: AISDKDomain
|
||||
readonly catalog: CatalogDomain
|
||||
readonly command: CommandDomain
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue