(
id: number,
params: { hook: string; input: unknown; output: unknown },
)
| 450 | } |
| 451 | |
| 452 | async function handleHookInvoke( |
| 453 | id: number, |
| 454 | params: { hook: string; input: unknown; output: unknown }, |
| 455 | ): Promise<void> { |
| 456 | const handler = pluginHooks[params.hook]; |
| 457 | if (typeof handler !== "function") { |
| 458 | sendError(id, -32601, `Hook not found: ${params.hook}`); |
| 459 | return; |
| 460 | } |
| 461 | |
| 462 | try { |
| 463 | // TS parity: `config` hooks mutate the first argument in-place. |
| 464 | // Use one shared object for both input/output so in-place edits are preserved. |
| 465 | if (params.hook === "config") { |
| 466 | const seed = |
| 467 | (params.output as UnknownRecord | null) ?? |
| 468 | (params.input as UnknownRecord | null) ?? |
| 469 | ({} as UnknownRecord); |
| 470 | const result = await handler(seed, seed); |
| 471 | sendResult(id, { output: result ?? seed }); |
| 472 | return; |
| 473 | } |
| 474 | |
| 475 | const result = await handler(params.input, params.output); |
| 476 | sendResult(id, { output: result ?? params.output }); |
| 477 | } catch (err: unknown) { |
| 478 | const msg = err instanceof Error ? err.message : String(err); |
| 479 | sendError(id, -32603, `Hook ${params.hook} failed: ${msg}`); |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | async function handleAuthAuthorize( |
| 484 | id: number, |
no test coverage detected