@anthropic-ai/sdk
Version:
The official TypeScript library for the Anthropic API
169 lines • 6.84 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Resources = void 0;
const resource_1 = require("../../../core/resource.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");
class Resources extends resource_1.APIResource {
/**
* Get Session Resource
*
* @example
* ```ts
* const resource =
* await client.beta.sessions.resources.retrieve(
* 'sesrsc_011CZkZBJq5dWxk9fVLNcPht',
* { session_id: 'sesn_011CZkZAtmR3yMPDzynEDxu7' },
* );
* ```
*/
retrieve(resourceID, params, options) {
const { session_id, betas, workspace_id } = params;
return this._client.get((0, path_1.path) `/v1/sessions/${session_id}/resources/${resourceID}?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.sessions.resources.retrieve', options, {
route: '/v1/sessions/{session_id}/resources/{resource_id}',
attributes: { 'anthropic.session.id': session_id, 'anthropic.session.resource.id': resourceID },
}),
});
}
/**
* Update Session Resource
*
* @example
* ```ts
* const resource =
* await client.beta.sessions.resources.update(
* 'sesrsc_011CZkZBJq5dWxk9fVLNcPht',
* {
* session_id: 'sesn_011CZkZAtmR3yMPDzynEDxu7',
* authorization_token: 'ghp_exampletoken',
* },
* );
* ```
*/
update(resourceID, params, options) {
const { session_id, betas, workspace_id, ...body } = params;
return this._client.post((0, path_1.path) `/v1/sessions/${session_id}/resources/${resourceID}?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.sessions.resources.update', options, {
route: '/v1/sessions/{session_id}/resources/{resource_id}',
attributes: { 'anthropic.session.id': session_id, 'anthropic.session.resource.id': resourceID },
}),
});
}
/**
* List Session Resources
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const betaManagedAgentsSessionResource of client.beta.sessions.resources.list(
* 'sesn_011CZkZAtmR3yMPDzynEDxu7',
* )) {
* // ...
* }
* ```
*/
list(sessionID, params = {}, options) {
const { betas, workspace_id, ...query } = params ?? {};
return this._client.getAPIList((0, path_1.path) `/v1/sessions/${sessionID}/resources?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.sessions.resources.list', options, {
route: '/v1/sessions/{session_id}/resources',
queryParams: ['limit', 'page'],
attributes: { 'anthropic.session.id': sessionID },
}),
});
}
/**
* Delete Session Resource
*
* @example
* ```ts
* const betaManagedAgentsDeleteSessionResource =
* await client.beta.sessions.resources.delete(
* 'sesrsc_011CZkZBJq5dWxk9fVLNcPht',
* { session_id: 'sesn_011CZkZAtmR3yMPDzynEDxu7' },
* );
* ```
*/
delete(resourceID, params, options) {
const { session_id, betas, workspace_id } = params;
return this._client.delete((0, path_1.path) `/v1/sessions/${session_id}/resources/${resourceID}?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.sessions.resources.delete', options, {
route: '/v1/sessions/{session_id}/resources/{resource_id}',
attributes: { 'anthropic.session.id': session_id, 'anthropic.session.resource.id': resourceID },
}),
});
}
/**
* Add Session Resource
*
* @example
* ```ts
* const betaManagedAgentsFileResource =
* await client.beta.sessions.resources.add(
* 'sesn_011CZkZAtmR3yMPDzynEDxu7',
* {
* file_id: 'file_011CNha8iCJcU1wXNR6q4V8w',
* type: 'file',
* },
* );
* ```
*/
add(sessionID, params, options) {
const { betas, workspace_id, ...body } = params;
return this._client.post((0, path_1.path) `/v1/sessions/${sessionID}/resources?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.sessions.resources.add', options, {
route: '/v1/sessions/{session_id}/resources',
attributes: { 'anthropic.session.id': sessionID },
createdIDAttribute: 'anthropic.session.resource.id',
}),
});
}
}
exports.Resources = Resources;
//# sourceMappingURL=resources.js.map