(opts: { json?: boolean })
| 52 | } |
| 53 | |
| 54 | async function handlePsCommand(opts: { json?: boolean }): Promise<void> { |
| 55 | const lock = getLiveLock(); |
| 56 | if (!lock) { |
| 57 | throw new Error( |
| 58 | 'No running Kimi server. Start one with `kimi server run` or `kimi web`.', |
| 59 | ); |
| 60 | } |
| 61 | |
| 62 | const origin = serverOrigin(lockConnectHost(lock), lock.port); |
| 63 | if (!(await isServerHealthy(origin, HEALTH_TIMEOUT_MS))) { |
| 64 | throw new Error(`Kimi server at ${origin} is not responding.`); |
| 65 | } |
| 66 | |
| 67 | // The `/api/v1/connections` route is gated by bearer auth (M5.1). Read the |
| 68 | // persistent token; a clear error here means the server has never been |
| 69 | // started (no token file yet) or the token file was removed. |
| 70 | const token = resolveServerToken(getDataDir()); |
| 71 | const connections = await fetchConnections(origin, token); |
| 72 | |
| 73 | if (opts.json) { |
| 74 | process.stdout.write(`${JSON.stringify(connections, null, 2)}\n`); |
| 75 | return; |
| 76 | } |
| 77 | process.stdout.write(formatTable(connections)); |
| 78 | } |
| 79 | |
| 80 | async function fetchConnections(origin: string, token: string): Promise<ConnectionInfo[]> { |
| 81 | const controller = new AbortController(); |
no test coverage detected