()
| 657 | // --------------------------------------------------------------------------- |
| 658 | |
| 659 | async function main(): Promise<void> { |
| 660 | // Set stdin to raw binary mode |
| 661 | if (typeof process.stdin.setEncoding === "function") { |
| 662 | // Don't call setEncoding — we want raw bytes |
| 663 | } |
| 664 | process.stdin.resume(); |
| 665 | |
| 666 | while (true) { |
| 667 | let msg: JsonRpcRequest | null; |
| 668 | try { |
| 669 | msg = await readMessage(); |
| 670 | } catch { |
| 671 | break; // stdin closed or parse error |
| 672 | } |
| 673 | |
| 674 | if (msg === null) break; // EOF |
| 675 | |
| 676 | const { id, method, params } = msg; |
| 677 | |
| 678 | switch (method) { |
| 679 | case "initialize": |
| 680 | await handleInitialize(id, params as Parameters<typeof handleInitialize>[1]); |
| 681 | break; |
| 682 | case "hook.invoke": |
| 683 | await handleHookInvoke(id, params as Parameters<typeof handleHookInvoke>[1]); |
| 684 | break; |
| 685 | case "auth.authorize": |
| 686 | await handleAuthAuthorize(id, params as Parameters<typeof handleAuthAuthorize>[1]); |
| 687 | break; |
| 688 | case "auth.callback": |
| 689 | await handleAuthCallback(id, params as Parameters<typeof handleAuthCallback>[1]); |
| 690 | break; |
| 691 | case "auth.load": |
| 692 | await handleAuthLoad(id); |
| 693 | break; |
| 694 | case "auth.fetch": |
| 695 | await handleAuthFetch(id, params as Parameters<typeof handleAuthFetch>[1]); |
| 696 | break; |
| 697 | case "auth.fetch.stream": |
| 698 | await handleAuthFetchStream(id, params as Parameters<typeof handleAuthFetchStream>[1]); |
| 699 | break; |
| 700 | case "shutdown": |
| 701 | sendResult(id, {}); |
| 702 | process.exit(0); |
| 703 | default: |
| 704 | sendError(id, -32601, `Unknown method: ${method}`); |
| 705 | } |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | main().catch((err) => { |
| 710 | process.stderr.write(`plugin-host fatal: ${err}\n`); |
no test coverage detected