feat(plugin): add session request hook
This commit is contained in:
parent
ad8e6b1fb6
commit
0e864b223f
21 changed files with 284 additions and 56 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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<
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"> & {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue