@anthropic-ai/sdk
Version:
The official TypeScript library for the Anthropic API
302 lines • 13.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Environments = exports.BetaEnvironmentNotFoundError = exports.BetaEnvironmentUpdateDisabledError = exports.BetaEnvironmentCreateDisabledError = exports.BetaInvalidMetadataError = exports.BetaInvalidConfigTypeChangeError = exports.BetaEnvironmentArchivedError = void 0;
const tslib_1 = require("../../../internal/tslib.js");
const resource_1 = require("../../../core/resource.js");
const WorkAPI = tslib_1.__importStar(require("./work.js"));
const work_1 = require("./work.js");
const error_1 = require("../../../core/error.js");
const pagination_1 = require("../../../core/pagination.js");
const headers_1 = require("../../../internal/headers.js");
const tracing_1 = require("../../../internal/tracing.js");
const path_1 = require("../../../internal/utils/path.js");
var BetaEnvironmentArchivedError = /* @__PURE__ */ (() => {
/**
* The environment is archived, so it cannot be updated.
*/
class BetaEnvironmentArchivedError extends error_1.BadRequestError {
}
/** @internal */
BetaEnvironmentArchivedError._errorName = 'BetaEnvironmentArchivedError';
return BetaEnvironmentArchivedError;
})();
exports.BetaEnvironmentArchivedError = BetaEnvironmentArchivedError;
var BetaInvalidConfigTypeChangeError = /* @__PURE__ */ (() => {
/**
* `config.type` differs from the environment's stored type, which cannot change
* after creation.
*/
class BetaInvalidConfigTypeChangeError extends error_1.BadRequestError {
}
/** @internal */
BetaInvalidConfigTypeChangeError._errorName = 'BetaInvalidConfigTypeChangeError';
return BetaInvalidConfigTypeChangeError;
})();
exports.BetaInvalidConfigTypeChangeError = BetaInvalidConfigTypeChangeError;
var BetaInvalidMetadataError = /* @__PURE__ */ (() => {
/**
* `metadata` has too many keys, a key or value that is too long, or a reserved
* key. The message names each problem.
*/
class BetaInvalidMetadataError extends error_1.BadRequestError {
}
/** @internal */
BetaInvalidMetadataError._errorName = 'BetaInvalidMetadataError';
return BetaInvalidMetadataError;
})();
exports.BetaInvalidMetadataError = BetaInvalidMetadataError;
var BetaEnvironmentCreateDisabledError = /* @__PURE__ */ (() => {
/**
* Anthropic has turned off creating environments for this organization. Existing
* environments still work.
*/
class BetaEnvironmentCreateDisabledError extends error_1.PermissionDeniedError {
}
/** @internal */
BetaEnvironmentCreateDisabledError._errorName = 'BetaEnvironmentCreateDisabledError';
return BetaEnvironmentCreateDisabledError;
})();
exports.BetaEnvironmentCreateDisabledError = BetaEnvironmentCreateDisabledError;
var BetaEnvironmentUpdateDisabledError = /* @__PURE__ */ (() => {
/**
* Anthropic has turned off updating environments for this organization. Existing
* environments still work as they are.
*/
class BetaEnvironmentUpdateDisabledError extends error_1.PermissionDeniedError {
}
/** @internal */
BetaEnvironmentUpdateDisabledError._errorName = 'BetaEnvironmentUpdateDisabledError';
return BetaEnvironmentUpdateDisabledError;
})();
exports.BetaEnvironmentUpdateDisabledError = BetaEnvironmentUpdateDisabledError;
var BetaEnvironmentNotFoundError = /* @__PURE__ */ (() => {
/**
* `settings.environment_id` names no Environment within the organization's reach.
*/
class BetaEnvironmentNotFoundError extends error_1.NotFoundError {
}
/** @internal */
BetaEnvironmentNotFoundError._errorName = 'BetaEnvironmentNotFoundError';
return BetaEnvironmentNotFoundError;
})();
exports.BetaEnvironmentNotFoundError = BetaEnvironmentNotFoundError;
var Environments = /* @__PURE__ */ (() => {
class Environments extends resource_1.APIResource {
constructor() {
super(...arguments);
this.work = new WorkAPI.Work(this._client);
}
/**
* Create a new environment with the specified configuration.
*
* @throws {ClaudeCodeKeyCreatorNotMemberError}
* @throws {OrganizationOnHoldError}
* @throws {BetaEnvironmentCreateDisabledError}
*
* @example
* ```ts
* const betaEnvironment =
* await client.beta.environments.create({
* name: 'python-data-analysis',
* });
* ```
*/
create(params, options) {
const { betas, workspace_id, ...body } = params;
return this._client.post('/v1/environments', {
body,
...options,
headers: (0, headers_1.buildHeaders)([
{
'anthropic-beta': [...(betas ?? []), 'managed-agents-2026-04-01'].toString(),
...(workspace_id != null ? { 'anthropic-workspace-id': workspace_id } : undefined),
},
options?.headers,
]),
__qualifiers: { beta: 'true' },
__span: (0, tracing_1.startApiCallSpan)(this._client, 'anthropic.environments.create', options, {
route: '/v1/environments',
createdIDAttribute: 'anthropic.environment.id',
}),
});
}
/**
* Retrieve a specific environment by ID.
*
* @throws {ClaudeCodeKeyCreatorNotMemberError}
* @throws {OrganizationOnHoldError}
*
* @example
* ```ts
* const betaEnvironment =
* await client.beta.environments.retrieve(
* 'env_011CZkZ9X2dpNyB7HsEFoRfW',
* );
* ```
*/
retrieve(environmentID, params = {}, options) {
const { betas, workspace_id } = params ?? {};
return this._client.get((0, path_1.path) `/v1/environments/${environmentID}`, {
...options,
headers: (0, headers_1.buildHeaders)([
{
'anthropic-beta': [...(betas ?? []), 'managed-agents-2026-04-01'].toString(),
...(workspace_id != null ? { 'anthropic-workspace-id': workspace_id } : undefined),
},
options?.headers,
]),
__qualifiers: { beta: 'true' },
__span: (0, tracing_1.startApiCallSpan)(this._client, 'anthropic.environments.retrieve', options, {
route: '/v1/environments/{environment_id}',
attributes: { 'anthropic.environment.id': environmentID },
}),
});
}
/**
* Update an existing environment's configuration.
*
* @throws {ClaudeCodeKeyCreatorNotMemberError}
* @throws {BetaEnvironmentArchivedError}
* @throws {BetaInvalidConfigTypeChangeError}
* @throws {OrganizationOnHoldError}
* @throws {BetaEnvironmentUpdateDisabledError}
*
* @example
* ```ts
* const betaEnvironment =
* await client.beta.environments.update(
* 'env_011CZkZ9X2dpNyB7HsEFoRfW',
* {},
* );
* ```
*/
update(environmentID, params, options) {
const { betas, workspace_id, ...body } = params;
return this._client.post((0, path_1.path) `/v1/environments/${environmentID}`, {
body,
...options,
headers: (0, headers_1.buildHeaders)([
{
'anthropic-beta': [...(betas ?? []), 'managed-agents-2026-04-01'].toString(),
...(workspace_id != null ? { 'anthropic-workspace-id': workspace_id } : undefined),
},
options?.headers,
]),
__qualifiers: { beta: 'true' },
__span: (0, tracing_1.startApiCallSpan)(this._client, 'anthropic.environments.update', options, {
route: '/v1/environments/{environment_id}',
attributes: { 'anthropic.environment.id': environmentID },
}),
});
}
/**
* List environments with pagination support.
*
* @throws {ClaudeCodeKeyCreatorNotMemberError}
* @throws {OrganizationOnHoldError}
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const betaEnvironment of client.beta.environments.list()) {
* // ...
* }
* ```
*/
list(params = {}, options) {
const { betas, workspace_id, ...query } = params ?? {};
return this._client.getAPIList('/v1/environments', (pagination_1.PageCursor), {
query,
...options,
headers: (0, headers_1.buildHeaders)([
{
'anthropic-beta': [...(betas ?? []), 'managed-agents-2026-04-01'].toString(),
...(workspace_id != null ? { 'anthropic-workspace-id': workspace_id } : undefined),
},
options?.headers,
]),
__qualifiers: { beta: 'true' },
__span: (0, tracing_1.startApiCallSpan)(this._client, 'anthropic.environments.list', options, {
route: '/v1/environments',
queryParams: ['include_archived', 'limit', 'page'],
}),
});
}
/**
* Delete an environment by ID. Returns a confirmation of the deletion.
*
* @throws {ClaudeCodeKeyCreatorNotMemberError}
* @throws {OrganizationOnHoldError}
*
* @example
* ```ts
* const betaEnvironmentDeleteResponse =
* await client.beta.environments.delete(
* 'env_011CZkZ9X2dpNyB7HsEFoRfW',
* );
* ```
*/
delete(environmentID, params = {}, options) {
const { betas, workspace_id } = params ?? {};
return this._client.delete((0, path_1.path) `/v1/environments/${environmentID}`, {
...options,
headers: (0, headers_1.buildHeaders)([
{
'anthropic-beta': [...(betas ?? []), 'managed-agents-2026-04-01'].toString(),
...(workspace_id != null ? { 'anthropic-workspace-id': workspace_id } : undefined),
},
options?.headers,
]),
__qualifiers: { beta: 'true' },
__span: (0, tracing_1.startApiCallSpan)(this._client, 'anthropic.environments.delete', options, {
route: '/v1/environments/{environment_id}',
attributes: { 'anthropic.environment.id': environmentID },
}),
});
}
/**
* Archive an environment by ID. Archived environments cannot be used to create new
* sessions.
*
* @throws {ClaudeCodeKeyCreatorNotMemberError}
* @throws {OrganizationOnHoldError}
*
* @example
* ```ts
* const betaEnvironment =
* await client.beta.environments.archive(
* 'env_011CZkZ9X2dpNyB7HsEFoRfW',
* );
* ```
*/
archive(environmentID, params = {}, options) {
const { betas, workspace_id } = params ?? {};
return this._client.post((0, path_1.path) `/v1/environments/${environmentID}/archive`, {
...options,
headers: (0, headers_1.buildHeaders)([
{
'anthropic-beta': [...(betas ?? []), 'managed-agents-2026-04-01'].toString(),
...(workspace_id != null ? { 'anthropic-workspace-id': workspace_id } : undefined),
},
options?.headers,
]),
__qualifiers: { beta: 'true' },
__span: (0, tracing_1.startApiCallSpan)(this._client, 'anthropic.environments.archive', options, {
route: '/v1/environments/{environment_id}/archive',
attributes: { 'anthropic.environment.id': environmentID },
}),
});
}
}
Environments.BetaEnvironmentArchivedError = BetaEnvironmentArchivedError;
Environments.BetaInvalidConfigTypeChangeError = BetaInvalidConfigTypeChangeError;
Environments.BetaInvalidMetadataError = BetaInvalidMetadataError;
Environments.BetaEnvironmentCreateDisabledError = BetaEnvironmentCreateDisabledError;
Environments.BetaEnvironmentUpdateDisabledError = BetaEnvironmentUpdateDisabledError;
Environments.BetaEnvironmentNotFoundError = BetaEnvironmentNotFoundError;
Environments.Work = work_1.Work;
Environments.BetaHeartbeatPreconditionFailedError = work_1.BetaHeartbeatPreconditionFailedError;
return Environments;
})();
exports.Environments = Environments;
//# sourceMappingURL=environments.js.map