| 64 | }) |
| 65 | |
| 66 | export async function trigger< |
| 67 | Name extends Exclude<keyof Required<Hooks>, "auth" | "event" | "tool">, |
| 68 | Input = Parameters<Required<Hooks>[Name]>[0], |
| 69 | Output = Parameters<Required<Hooks>[Name]>[1], |
| 70 | >(name: Name, input: Input, output: Output): Promise<Output> { |
| 71 | if (!name) return output |
| 72 | for (const hook of await state().then((x) => x.hooks)) { |
| 73 | const fn = hook[name] |
| 74 | if (!fn) continue |
| 75 | // @ts-expect-error if you feel adventurous, please fix the typing, make sure to bump the try-counter if you |
| 76 | // give up. |
| 77 | // try-counter: 2 |
| 78 | await fn(input, output) |
| 79 | } |
| 80 | return output |
| 81 | } |
| 82 | |
| 83 | export async function list() { |
| 84 | return state().then((x) => x.hooks) |