feat(plugin): add session request hook

This commit is contained in:
Aiden Cline 2026-07-16 17:48:21 +00:00 committed by 𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴
commit 0e864b223f
21 changed files with 284 additions and 56 deletions

View file

@ -92,6 +92,19 @@ yield *
)
```
The serialized provider request is also mutable before it is sent:
```ts
yield *
ctx.session.hook("request", (event) =>
Effect.sync(() => {
event.request = new Request(event.request, {
headers: new Headers([...event.request.headers, ["x-plugin", "enabled"]]),
})
}),
)
```
## Reloading A Domain
When data captured by a transform changes, reload the affected domain:

View file

@ -15,8 +15,14 @@ export interface SessionContext {
tools: Record<string, { description: string; input: JsonSchema.JsonSchema }>
}
export interface SessionRequest {
readonly sessionID: Session.ID
request: Request
}
export interface SessionHooks {
readonly context: SessionContext
readonly request: SessionRequest
}
export type SessionDomain = Pick<

View file

@ -94,6 +94,16 @@ await ctx.session.hook("context", (event) => {
})
```
The serialized provider request is also mutable before it is sent:
```ts
await ctx.session.hook("request", (event) => {
event.request = new Request(event.request, {
headers: new Headers([...event.request.headers, ["x-plugin", "enabled"]]),
})
})
```
Promise tools use plain object declarations with async executors:
```ts

View file

@ -15,8 +15,14 @@ export interface SessionContext {
tools: Record<string, { description: string; input: JsonSchema.JsonSchema }>
}
export interface SessionRequest {
readonly sessionID: Session.ID
request: Request
}
export interface SessionHooks {
readonly context: SessionContext
readonly request: SessionRequest
}
export type SessionDomain = Pick<SessionApi, "create" | "get" | "prompt" | "command" | "synthetic" | "interrupt"> & {