The open-source agent harness - the runtime layer that turns an LLM into a working agent.
// This file was auto-generated by Fern from our API Definition.
import type { BaseClientOptions, BaseRequestOptions } from "../../../../BaseClient.js";
import { type NormalizedClientOptionsWithAuth, normalizeClientOptionsWithAuth } from "../../../../BaseClient.js";
import { mergeHeaders } from "../../../../core/headers.js";
import * as core from "../../../../core/index.js";
import { mergeAdditionalBodyParameters } from "../../../../core/requestBody.js";
import { handleNonStatusCodeError } from "../../../../errors/handleNonStatusCodeError.js";
import * as errors from "../../../../errors/index.js";
import * as serializers from "../../../../serialization/index.js";
import * as TrueForge from "../../../index.js";
import { AgentsClient } from "../resources/agents/client/Client.js";
import { MetricsClient } from "../resources/metrics/client/Client.js";
import { SandboxEnvironmentsClient } from "../resources/sandboxEnvironments/client/Client.js";
import { SchedulesClient } from "../resources/schedules/client/Client.js";
import { SessionsClient } from "../resources/sessions/client/Client.js";
export declare namespace InternalClient {
export type Options = BaseClientOptions;
export interface RequestOptions extends BaseRequestOptions {}
}
export class InternalClient {
protected readonly _options: NormalizedClientOptionsWithAuth<InternalClient.Options>;
protected _metrics: MetricsClient | undefined;
protected _sandboxEnvironments: SandboxEnvironmentsClient | undefined;
protected _schedules: SchedulesClient | undefined;
protected _sessions: SessionsClient | undefined;
protected _agents: AgentsClient | undefined;
constructor(options: InternalClient.Options) {
this._options = normalizeClientOptionsWithAuth(options);
}
public get metrics(): MetricsClient {
return (this._metrics ??= new MetricsClient(this._options));
}
public get sandboxEnvironments(): SandboxEnvironmentsClient {
return (this._sandboxEnvironments ??= new SandboxEnvironmentsClient(this._options));
}
public get schedules(): SchedulesClient {
return (this._schedules ??= new SchedulesClient(this._options));
}
public get sessions(): SessionsClient {
return (this._sessions ??= new SessionsClient(this._options));
}
public get agents(): AgentsClient {
return (this._agents ??= new AgentsClient(this._options));
}
/**
* Return granted actions for the requested resources.
*
* @param {TrueForge.ListPermissionsRequest} request
* @param {InternalClient.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link TrueForge.BadRequestError}
* @throws {@link TrueForge.UnauthorizedError}
* @throws {@link errors.TrueForgeError}
* @throws {@link errors.TrueForgeTimeoutError}
*
* @example
* await client.internal.listPermissions({
* resourceIds: ["resource_ids"],
* resourceType: "agent"
* })
*/
public listPermissions(
request: TrueForge.ListPermissionsRequest,
requestOptions?: InternalClient.RequestOptions,
): core.HttpResponsePromise<TrueForge.ListPermissionsResponse> {
return core.HttpResponsePromise.fromPromise(this.__listPermissions(request, requestOptions));
}
private async __listPermissions(
request: TrueForge.ListPermissionsRequest,
requestOptions?: InternalClient.RequestOptions,
): Promise<core.WithRawResponse<TrueForge.ListPermissionsResponse>> {
const _authRequest: core.AuthRequest = await this._options.authProvider.getAuthRequest();
const _headers: core.Fetcher.Args["headers"] = mergeHeaders(
_authRequest.headers,
this._options?.headers,
requestOptions?.headers,
);
const _response = await (this._options.fetcher ?? core.fetcher)({
url: core.url.join(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)),
"api/internal/list-permissions",
),
method: "POST",
headers: _headers,
contentType: "application/json",
queryString: core.url.queryBuilder().mergeAdditional(requestOptions?.queryParams).build(),
requestType: "json",
body: mergeAdditionalBodyParameters(
serializers.ListPermissionsRequest.jsonOrThrow(request, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
omitUndefined: true,
}),
requestOptions?.additionalBodyParameters,
),
timeoutMs: (requestOptions?.timeoutInSeconds ?? this._options?.timeoutInSeconds ?? 60) * 1000,
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
abortSignal: requestOptions?.abortSignal,
fetchFn: this._options?.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return {
data: serializers.ListPermissionsResponse.parseOrThrow(_response.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
skipValidation: true,
breadcrumbsPrefix: ["response"],
}),
rawResponse: _response.rawResponse,
};
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 400:
throw new TrueForge.BadRequestError(
serializers.RequestErrorResponse.parseOrThrow(_response.error.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
skipValidation: true,
breadcrumbsPrefix: ["response"],
}),
_response.rawResponse,
);
case 401:
throw new TrueForge.UnauthorizedError(
serializers.RequestErrorResponse.parseOrThrow(_response.error.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
skipValidation: true,
breadcrumbsPrefix: ["response"],
}),
_response.rawResponse,
);
default:
throw new errors.TrueForgeError({
statusCode: _response.error.statusCode,
body: _response.error.body,
rawResponse: _response.rawResponse,
});
}
}
return handleNonStatusCodeError(
_response.error,
_response.rawResponse,
"POST",
"/api/internal/list-permissions",
);
}
}