fix: 支持 AgentRun render-only REST 入口 (#170)

Co-authored-by: AgentRun Codex <agentrun-codex@users.noreply.github.com>
This commit is contained in:
Lyon
2026-06-11 15:39:52 +08:00
committed by GitHub
parent 83a303959e
commit 8cf6534bec
12 changed files with 338 additions and 12 deletions
+11 -3
View File
@@ -1,8 +1,13 @@
import type { JsonRecord, JsonValue } from "../common/types.js";
import { AgentRunError } from "../common/errors.js";
import { managerAuthorizationHeader, managerClientAuthConfigFromEnv } from "./auth.js";
export interface ManagerClientOptions {
apiKey?: string | null;
}
export class ManagerClient {
constructor(readonly baseUrl: string) {}
constructor(readonly baseUrl: string, readonly options: ManagerClientOptions = {}) {}
async get(path: string): Promise<JsonValue> {
return this.request("GET", path);
@@ -25,9 +30,12 @@ export class ManagerClient {
}
private async request(method: string, path: string, body?: JsonValue): Promise<JsonValue> {
const init: RequestInit = { method };
const headers: Record<string, string> = {};
const authHeader = managerAuthorizationHeader(this.options.apiKey === undefined ? managerClientAuthConfigFromEnv().apiKey : this.options.apiKey);
if (authHeader) headers.authorization = authHeader;
const init: RequestInit = { method, headers };
if (body !== undefined) {
init.headers = { "content-type": "application/json" };
headers["content-type"] = "application/json";
init.body = JSON.stringify(body);
}
const response = await fetch(new URL(path, this.baseUrl), init);