@anthropic-ai/sdk
Version:
The official TypeScript library for the Anthropic API
113 lines • 5.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Threads = void 0;
const tslib_1 = require("../../../../internal/tslib.js");
const resource_1 = require("../../../../core/resource.js");
const ThreadsEventsAPI = tslib_1.__importStar(require("./events.js"));
const events_1 = require("./events.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 Threads = /* @__PURE__ */ (() => {
class Threads extends resource_1.APIResource {
constructor() {
super(...arguments);
this.events = new ThreadsEventsAPI.Events(this._client);
}
/**
* Get Session Thread
*
* @example
* ```ts
* const betaManagedAgentsSessionThread =
* await client.beta.sessions.threads.retrieve(
* 'sthr_011CZkZVWa6oJjw1rgXZpnBt',
* { session_id: 'sesn_011CZkZAtmR3yMPDzynEDxu7' },
* );
* ```
*/
retrieve(threadID, params, options) {
const { session_id, betas, workspace_id } = params;
return this._client.get((0, path_1.path) `/v1/sessions/${session_id}/threads/${threadID}?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.threads.retrieve', options, {
route: '/v1/sessions/{session_id}/threads/{thread_id}',
attributes: { 'anthropic.session.id': session_id, 'anthropic.session.thread.id': threadID },
}),
});
}
/**
* List Session Threads
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const betaManagedAgentsSessionThread of client.beta.sessions.threads.list(
* 'sesn_011CZkZAtmR3yMPDzynEDxu7',
* )) {
* // ...
* }
* ```
*/
list(sessionID, params = {}, options) {
const { betas, workspace_id, ...query } = params ?? {};
return this._client.getAPIList((0, path_1.path) `/v1/sessions/${sessionID}/threads?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.threads.list', options, {
route: '/v1/sessions/{session_id}/threads',
queryParams: ['limit', 'page', 'statuses'],
attributes: { 'anthropic.session.id': sessionID },
}),
});
}
/**
* Archive Session Thread
*
* @example
* ```ts
* const betaManagedAgentsSessionThread =
* await client.beta.sessions.threads.archive(
* 'sthr_011CZkZVWa6oJjw1rgXZpnBt',
* { session_id: 'sesn_011CZkZAtmR3yMPDzynEDxu7' },
* );
* ```
*/
archive(threadID, params, options) {
const { session_id, betas, workspace_id } = params;
return this._client.post((0, path_1.path) `/v1/sessions/${session_id}/threads/${threadID}/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.sessions.threads.archive', options, {
route: '/v1/sessions/{session_id}/threads/{thread_id}/archive',
attributes: { 'anthropic.session.id': session_id, 'anthropic.session.thread.id': threadID },
}),
});
}
}
Threads.Events = events_1.Events;
return Threads;
})();
exports.Threads = Threads;
//# sourceMappingURL=threads.js.map