| 155 | const sdks = new Map<string, SDK>() |
| 156 | |
| 157 | const register = <Event>( |
| 158 | hooks: () => ((event: Event) => Effect.Effect<void> | void)[], |
| 159 | update: (hooks: ((event: Event) => Effect.Effect<void> | void)[]) => void, |
| 160 | ) => |
| 161 | Effect.fn("AISDK.hook")(function* (callback: (event: Event) => Effect.Effect<void> | void) { |
| 162 | const scope = yield* Scope.Scope |
| 163 | let active = true |
| 164 | update([...hooks(), callback]) |
| 165 | const dispose = Effect.sync(() => { |
| 166 | if (!active) return |
| 167 | active = false |
| 168 | update(hooks().filter((item) => item !== callback)) |
| 169 | }) |
| 170 | yield* Scope.addFinalizer(scope, dispose) |
| 171 | return { dispose } |
| 172 | }) |
| 173 | |
| 174 | const run = Effect.fnUntraced(function* <Event>( |
| 175 | hooks: readonly ((event: Event) => Effect.Effect<void> | void)[], |