UNPKG

@anthropic-ai/sdk

Version:
170 lines • 6.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Agents = void 0; const tslib_1 = require("../../../internal/tslib.js"); const resource_1 = require("../../../core/resource.js"); const VersionsAPI = tslib_1.__importStar(require("./versions.js")); const versions_1 = require("./versions.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 Agents = /* @__PURE__ */ (() => { class Agents extends resource_1.APIResource { constructor() { super(...arguments); this.versions = new VersionsAPI.Versions(this._client); } /** * Create Agent * * @example * ```ts * const betaManagedAgentsAgent = * await client.beta.agents.create({ * model: 'claude-opus-5-5', * name: 'My First Agent', * }); * ``` */ create(params, options) { const { betas, workspace_id, ...body } = params; return this._client.post('/v1/agents?beta=true', { 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, ]), __span: (0, tracing_1.startApiCallSpan)(this._client, 'anthropic.agents.create', options, { route: '/v1/agents', createdIDAttribute: 'gen_ai.agent.id', }), }); } /** * Get Agent * * @example * ```ts * const betaManagedAgentsAgent = * await client.beta.agents.retrieve( * 'agent_011CZkYpogX7uDKUyvBTophP', * ); * ``` */ retrieve(agentID, params = {}, options) { const { betas, workspace_id, ...query } = params ?? {}; return this._client.get((0, path_1.path) `/v1/agents/${agentID}?beta=true`, { 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, ]), __span: (0, tracing_1.startApiCallSpan)(this._client, 'anthropic.agents.retrieve', options, { route: '/v1/agents/{agent_id}', queryParams: ['version'], attributes: { 'gen_ai.agent.id': agentID }, }), }); } /** * Update Agent * * @example * ```ts * const betaManagedAgentsAgent = * await client.beta.agents.update( * 'agent_011CZkYpogX7uDKUyvBTophP', * { description: 'updated' }, * ); * ``` */ update(agentID, params, options) { const { betas, workspace_id, ...body } = params; return this._client.post((0, path_1.path) `/v1/agents/${agentID}?beta=true`, { 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, ]), __span: (0, tracing_1.startApiCallSpan)(this._client, 'anthropic.agents.update', options, { route: '/v1/agents/{agent_id}', attributes: { 'gen_ai.agent.id': agentID }, }), }); } /** * List Agents * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const betaManagedAgentsAgent of client.beta.agents.list()) { * // ... * } * ``` */ list(params = {}, options) { const { betas, workspace_id, ...query } = params ?? {}; return this._client.getAPIList('/v1/agents?beta=true', (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, ]), __span: (0, tracing_1.startApiCallSpan)(this._client, 'anthropic.agents.list', options, { route: '/v1/agents', queryParams: ['created_at[gte]', 'created_at[lte]', 'include_archived', 'limit', 'page'], }), }); } /** * Archive Agent * * @example * ```ts * const betaManagedAgentsAgent = * await client.beta.agents.archive( * 'agent_011CZkYpogX7uDKUyvBTophP', * ); * ``` */ archive(agentID, params = {}, options) { const { betas, workspace_id } = params ?? {}; return this._client.post((0, path_1.path) `/v1/agents/${agentID}/archive?beta=true`, { ...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, ]), __span: (0, tracing_1.startApiCallSpan)(this._client, 'anthropic.agents.archive', options, { route: '/v1/agents/{agent_id}/archive', attributes: { 'gen_ai.agent.id': agentID }, }), }); } } Agents.Versions = versions_1.Versions; return Agents; })(); exports.Agents = Agents; //# sourceMappingURL=agents.js.map