MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / isServerHealthy

Function isServerHealthy

apps/kimi-code/src/cli/sub/server/shared.ts:151–168  ·  view source on GitHub ↗
(origin: string, timeoutMs: number)

Source from the content-addressed store, hash-verified

149
150/** Single probe of `/api/v1/healthz`. Returns true if the response envelope reports `code: 0`. */
151export async function isServerHealthy(origin: string, timeoutMs: number): Promise<boolean> {
152 const controller = new AbortController();
153 const timeout = setTimeout(() => {
154 controller.abort();
155 }, timeoutMs);
156 try {
157 const response = await fetch(`${origin}/api/v1/healthz`, {
158 signal: controller.signal,
159 });
160 if (!response.ok) return false;
161 const body = (await response.json()) as { code?: unknown };
162 return body.code === 0;
163 } catch {
164 return false;
165 } finally {
166 clearTimeout(timeout);
167 }
168}
169
170/** Poll `/api/v1/healthz` until it reports healthy or `timeoutMs` elapses. */
171export async function waitForServerHealthy(origin: string, timeoutMs: number): Promise<boolean> {

Callers 3

ensureDaemonFunction · 0.90
handlePsCommandFunction · 0.90
waitForServerHealthyFunction · 0.85

Calls 2

jsonMethod · 0.80
abortMethod · 0.65

Tested by

no test coverage detected