MCPcopy Create free account
hub / github.com/tiann/hapi / runnerPost

Function runnerPost

cli/src/runner/controlClient.ts:38–82  ·  view source on GitHub ↗
(path: string, body?: any)

Source from the content-addressed store, hash-verified

36}
37
38async function runnerPost(path: string, body?: any): Promise<{ error?: string } | any> {
39 const state = await readRunnerState();
40 if (!state?.httpPort) {
41 const errorMessage = 'No runner running, no state file found';
42 logger.debug(`[CONTROL CLIENT] ${errorMessage}`);
43 return {
44 error: errorMessage
45 };
46 }
47
48 if (!isProcessAlive(state.pid)) {
49 const errorMessage = 'Runner is not running, file is stale';
50 logger.debug(`[CONTROL CLIENT] ${errorMessage}`);
51 return {
52 error: errorMessage
53 };
54 }
55
56 try {
57 const timeout = process.env.HAPI_RUNNER_HTTP_TIMEOUT ? parseInt(process.env.HAPI_RUNNER_HTTP_TIMEOUT) : 10_000;
58 const response = await fetch(`http://127.0.0.1:${state.httpPort}${path}`, {
59 method: 'POST',
60 headers: { 'Content-Type': 'application/json' },
61 body: JSON.stringify(body || {}),
62 // Mostly increased for stress test
63 signal: AbortSignal.timeout(timeout)
64 });
65
66 if (!response.ok) {
67 const errorMessage = `Request failed: ${path}, HTTP ${response.status}`;
68 logger.debug(`[CONTROL CLIENT] ${errorMessage}`);
69 return {
70 error: errorMessage
71 };
72 }
73
74 return await response.json();
75 } catch (error) {
76 const errorMessage = `Request failed: ${path}, ${error instanceof Error ? error.message : 'Unknown error'}`;
77 logger.debug(`[CONTROL CLIENT] ${errorMessage}`);
78 return {
79 error: errorMessage
80 }
81 }
82}
83
84export async function notifyRunnerSessionStarted(
85 sessionId: string,

Callers 5

listRunnerSessionsFunction · 0.85
stopRunnerSessionFunction · 0.85
spawnRunnerSessionFunction · 0.85
stopRunnerHttpFunction · 0.85

Calls 3

readRunnerStateFunction · 0.90
isProcessAliveFunction · 0.90
debugMethod · 0.80

Tested by

no test coverage detected