mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 09:40:43 +00:00
46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
import type { CodexAppServerStartOptions } from "./config.js";
|
|
import type {
|
|
CodexAppServerRequestMethod,
|
|
CodexAppServerRequestParams,
|
|
CodexAppServerRequestResult,
|
|
JsonValue,
|
|
} from "./protocol.js";
|
|
import { getSharedCodexAppServerClient } from "./shared-client.js";
|
|
import { withTimeout } from "./timeout.js";
|
|
|
|
export async function requestCodexAppServerJson<M extends CodexAppServerRequestMethod>(params: {
|
|
method: M;
|
|
requestParams: CodexAppServerRequestParams<M>;
|
|
timeoutMs?: number;
|
|
startOptions?: CodexAppServerStartOptions;
|
|
authProfileId?: string;
|
|
}): Promise<CodexAppServerRequestResult<M>>;
|
|
export async function requestCodexAppServerJson<T = JsonValue | undefined>(params: {
|
|
method: string;
|
|
requestParams?: unknown;
|
|
timeoutMs?: number;
|
|
startOptions?: CodexAppServerStartOptions;
|
|
authProfileId?: string;
|
|
}): Promise<T>;
|
|
export async function requestCodexAppServerJson<T = JsonValue | undefined>(params: {
|
|
method: string;
|
|
requestParams?: unknown;
|
|
timeoutMs?: number;
|
|
startOptions?: CodexAppServerStartOptions;
|
|
authProfileId?: string;
|
|
}): Promise<T> {
|
|
const timeoutMs = params.timeoutMs ?? 60_000;
|
|
return await withTimeout(
|
|
(async () => {
|
|
const client = await getSharedCodexAppServerClient({
|
|
startOptions: params.startOptions,
|
|
timeoutMs,
|
|
authProfileId: params.authProfileId,
|
|
});
|
|
return await client.request<T>(params.method, params.requestParams, { timeoutMs });
|
|
})(),
|
|
timeoutMs,
|
|
`codex app-server ${params.method} timed out`,
|
|
);
|
|
}
|