feat(plugin): add dispose hook (#29493)

This commit is contained in:
Aiden Cline 2026-05-26 21:21:53 -05:00 committed by GitHub
parent a78605f8ea
commit 519d344470
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 0 deletions

View file

@ -244,6 +244,20 @@ export const layer = Layer.effect(
}).pipe(Effect.ignore)
}
yield* Effect.addFinalizer(() =>
Effect.forEach(
hooks,
(hook) =>
Effect.tryPromise({
try: () => Promise.resolve(hook.dispose?.()),
catch: (error) => {
log.error("plugin dispose hook failed", { error })
},
}).pipe(Effect.ignore),
{ discard: true },
),
)
// Subscribe to bus events, fiber interrupted when scope closes
yield* (yield* bus.subscribeAll()).pipe(
Stream.runForEach((input) =>

View file

@ -220,6 +220,7 @@ export type ProviderHook = {
export type AuthOuathResult = AuthOAuthResult
export interface Hooks {
dispose?: () => Promise<void>
event?: (input: { event: Event }) => Promise<void>
config?: (input: Config) => Promise<void>
tool?: {