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

Method sendRequest

cli/src/codex/codexAppServerClient.ts:278–350  ·  view source on GitHub ↗
(
        method: string,
        params?: unknown,
        options?: { signal?: AbortSignal; timeoutMs?: number }
    )

Source from the content-addressed store, hash-verified

276 }
277
278 private async sendRequest(
279 method: string,
280 params?: unknown,
281 options?: { signal?: AbortSignal; timeoutMs?: number }
282 ): Promise<unknown> {
283 if (!this.connected) {
284 await this.connect();
285 }
286
287 const id = this.nextId++;
288 const payload: JsonRpcLiteRequest = {
289 id,
290 method,
291 params
292 };
293
294 const timeoutMs = options?.timeoutMs ?? CodexAppServerClient.DEFAULT_TIMEOUT_MS;
295
296 return new Promise((resolve, reject) => {
297 let timeout: ReturnType<typeof setTimeout> | null = null;
298 let aborted = false;
299
300 const cleanup = () => {
301 if (timeout) {
302 clearTimeout(timeout);
303 }
304 if (options?.signal) {
305 options.signal.removeEventListener('abort', onAbort);
306 }
307 };
308
309 const onAbort = () => {
310 if (aborted) return;
311 aborted = true;
312 this.pending.delete(id);
313 cleanup();
314 reject(createAbortError());
315 };
316
317 if (options?.signal) {
318 if (options.signal.aborted) {
319 onAbort();
320 return;
321 }
322 options.signal.addEventListener('abort', onAbort, { once: true });
323 }
324
325 if (Number.isFinite(timeoutMs)) {
326 timeout = setTimeout(() => {
327 if (this.pending.has(id)) {
328 this.pending.delete(id);
329 cleanup();
330 reject(new Error(`Codex app-server request '${method}' timed out after ${timeoutMs}ms`));
331 }
332 }, timeoutMs);
333 timeout.unref();
334 }
335

Callers 12

initializeMethod · 0.95
listModelsMethod · 0.95
startThreadMethod · 0.95
resumeThreadMethod · 0.95
startTurnMethod · 0.95
interruptTurnMethod · 0.95
compactThreadMethod · 0.95
setThreadGoalMethod · 0.95
getThreadGoalMethod · 0.95
clearThreadGoalMethod · 0.95

Calls 3

connectMethod · 0.95
writePayloadMethod · 0.95
cleanupFunction · 0.50

Tested by

no test coverage detected