fix: 支持 AgentRun render-only REST 入口 (#170)
Co-authored-by: AgentRun Codex <agentrun-codex@users.noreply.github.com>
This commit is contained in:
+11
-3
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user