UNPKG

@anthropic-ai/sdk

Version:
170 lines • 6.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Dreams = void 0; const resource_1 = require("../../core/resource.js"); const pagination_1 = require("../../core/pagination.js"); const headers_1 = require("../../internal/headers.js"); const path_1 = require("../../internal/utils/path.js"); class Dreams extends resource_1.APIResource { /** * Start an asynchronous job that uses past sessions to produce a reorganized * version of a memory store and get back the dream to poll for the result. * * By default the dream writes its result to a new memory store and doesn't change * the input memory store. The response has `status` set to `pending` and an empty * `outputs` array. Poll the dream until `status` is `completed`, `failed`, or * `canceled`. * * See the * [Dreams guide](https://platform.claude.com/docs/en/managed-agents/dreams#create-a-dream) * to learn more about creating dreams. * * @example * ```ts * const betaDream = await client.beta.dreams.create({ * inputs: [{ memory_store_id: 'x', type: 'memory_store' }], * model: 'string', * }); * ``` */ create(params, options) { const { betas, workspace_id, ...body } = params; return this._client.post('/v1/dreams?beta=true', { body, ...options, headers: (0, headers_1.buildHeaders)([ { 'anthropic-beta': [...(betas ?? []), 'dreaming-2026-04-21'].toString(), ...(workspace_id != null ? { 'anthropic-workspace-id': workspace_id } : undefined), }, options?.headers, ]), }); } /** * Get a dream by ID to check its status, output memory store, and token usage. * * Archived dreams are returned too. * * See the * [Dreams guide](https://platform.claude.com/docs/en/managed-agents/dreams#track-progress) * for how to poll a dream and what each status means. * * @example * ```ts * const betaDream = await client.beta.dreams.retrieve( * 'dream_id', * ); * ``` */ retrieve(dreamID, params = {}, options) { const { betas, workspace_id } = params ?? {}; return this._client.get((0, path_1.path) `/v1/dreams/${dreamID}?beta=true`, { ...options, headers: (0, headers_1.buildHeaders)([ { 'anthropic-beta': [...(betas ?? []), 'dreaming-2026-04-21'].toString(), ...(workspace_id != null ? { 'anthropic-workspace-id': workspace_id } : undefined), }, options?.headers, ]), }); } /** * List the dreams in the workspace, newest first. * * Archived dreams are left out unless `include_archived` is `true`. * * See the * [Dreams guide](https://platform.claude.com/docs/en/managed-agents/dreams#list-dreams) * for how to page through dreams. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const betaDream of client.beta.dreams.list()) { * // ... * } * ``` */ list(params = {}, options) { const { betas, workspace_id, ...query } = params ?? {}; return this._client.getAPIList('/v1/dreams?beta=true', (pagination_1.PageCursor), { query, ...options, headers: (0, headers_1.buildHeaders)([ { 'anthropic-beta': [...(betas ?? []), 'dreaming-2026-04-21'].toString(), ...(workspace_id != null ? { 'anthropic-workspace-id': workspace_id } : undefined), }, options?.headers, ]), }); } /** * Hide a `completed`, `failed`, or `canceled` dream from the default list of * dreams. * * Archiving a `pending` or `running` dream returns a 400 error, so cancel it * first. Archiving an archived dream returns it unchanged. An archived dream can * still be fetched by ID. Archiving can't be undone. * * See the * [Dreams guide](https://platform.claude.com/docs/en/managed-agents/dreams#archive-a-dream) * to learn more about archiving dreams. * * @example * ```ts * const betaDream = await client.beta.dreams.archive( * 'dream_id', * ); * ``` */ archive(dreamID, params = {}, options) { const { betas, workspace_id } = params ?? {}; return this._client.post((0, path_1.path) `/v1/dreams/${dreamID}/archive?beta=true`, { ...options, headers: (0, headers_1.buildHeaders)([ { 'anthropic-beta': [...(betas ?? []), 'dreaming-2026-04-21'].toString(), ...(workspace_id != null ? { 'anthropic-workspace-id': workspace_id } : undefined), }, options?.headers, ]), }); } /** * Stop a `pending` or `running` dream. * * The response shows `status` as `canceled`, unless the dream reached `completed` * or `failed` first. `usage` can keep changing after the response. Canceling a * `canceled` dream returns it unchanged. Canceling a `completed` or `failed` dream * returns a 400 error. * * See the * [Dreams guide](https://platform.claude.com/docs/en/managed-agents/dreams#cancel-a-dream) * to learn more about canceling dreams. * * @example * ```ts * const betaDream = await client.beta.dreams.cancel( * 'dream_id', * ); * ``` */ cancel(dreamID, params = {}, options) { const { betas, workspace_id } = params ?? {}; return this._client.post((0, path_1.path) `/v1/dreams/${dreamID}/cancel?beta=true`, { ...options, headers: (0, headers_1.buildHeaders)([ { 'anthropic-beta': [...(betas ?? []), 'dreaming-2026-04-21'].toString(), ...(workspace_id != null ? { 'anthropic-workspace-id': workspace_id } : undefined), }, options?.headers, ]), }); } } exports.Dreams = Dreams; //# sourceMappingURL=dreams.js.map