feat(plugin): add session request hook

This commit is contained in:
Aiden Cline 2026-07-17 00:23:48 -05:00 committed by 𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴
commit 518d64d684
5 changed files with 92 additions and 1 deletions

View file

@ -218,6 +218,37 @@ describe("fromPromise", () => {
}),
)
it.effect("forwards session request hooks", () =>
Effect.gen(function* () {
const plugin = yield* PluginV2.Service
const hooks = yield* PluginHooks.Service
const host = yield* PluginHost.make(plugin)
yield* PluginPromise.fromPromise(
Plugin.define({
id: "promise-session-request",
setup: async (ctx) => {
await ctx.session.hook("request", (event) => {
event.headers["x-plugin"] = "promise"
delete event.body.max_output_tokens
})
},
}),
).effect(host)
const event: SessionHooks["request"] = {
sessionID: SessionV2.ID.make("ses_promise_session_request"),
agent: AgentV2.ID.make("build"),
model: Model.Ref.make({ providerID: Provider.ID.make("test"), id: Model.ID.make("model") }),
headers: {},
body: { max_output_tokens: 1024 },
}
yield* hooks.trigger("session", "request", event)
expect(event.headers).toEqual({ "x-plugin": "promise" })
expect(event.body).toEqual({})
}),
)
it.effect("disposes a hook registration on request", () =>
Effect.gen(function* () {
const agents = yield* AgentV2.Service