feat(api): expose REST-only agent routes
Agent CI/CD / docker-image (push) Failing after 35s
Agent CI/CD / deploy-fallback-log (push) Successful in 1s

This commit is contained in:
2026-07-30 20:38:52 +08:00
parent 2415f75841
commit 94529cb141
29 changed files with 3525 additions and 378 deletions
+2 -11
View File
@@ -1,5 +1,4 @@
import { CliError, errorMessage } from "./errors.js";
import { requireNetwork, requireUsername } from "./runtime.js";
import { success } from "./output.js";
import type { RequestOptions, RuntimeContext } from "./types.js";
@@ -35,18 +34,10 @@ function appendParams(url: URL, params: Record<string, unknown> = {}): void {
}
}
function withNetworkParam(params: Record<string, unknown> | undefined, network: string): Record<string, unknown> {
if (params?.network !== undefined || params?.network_name !== undefined || params?.name !== undefined) return params ?? {};
return { ...(params ?? {}), network };
}
export async function requestJson(ctx: RuntimeContext, request: RequestOptions): Promise<[unknown, number]> {
const { method, path, params, body, requireAuth = true, requireProject = false, requireNetworkCtx = false, requireUsernameCtx = false } = request;
const network = requireNetworkCtx ? requireNetwork(ctx) : null;
if (requireUsernameCtx) requireUsername(ctx);
const { method, path, params, body, requireAuth = true, requireProject = false } = request;
const url = new URL(`/api/v1${path}`, ctx.server.replace(/\/+$/, ""));
const requestParams = network && (params !== undefined || body === undefined) ? withNetworkParam(params, network) : params;
appendParams(url, requestParams);
appendParams(url, params);
const started = performance.now();
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), ctx.timeout * 1000);