UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

215 lines • 8.21 kB
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from "../../../../core/resource.mjs"; import { V4PagePaginationArray, } from "../../../../core/pagination.mjs"; import { buildHeaders } from "../../../../internal/headers.mjs"; import { multipartFormRequestOptions } from "../../../../internal/uploads.mjs"; import { path } from "../../../../internal/utils/path.mjs"; export var BaseItems = /* @__PURE__ */ (() => { class BaseItems extends APIResource { /** * Lists indexed items in an AI Search instance. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const itemListResponse of client.aiSearch.namespaces.instances.items.list( * 'my-ai-search', * { * account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22', * name: 'my-namespace', * }, * )) { * // ... * } * ``` */ list(id, params, options) { const { account_id, name, ...query } = params; return this._client.getAPIList(path `/accounts/${account_id}/ai-search/namespaces/${name}/instances/${id}/items`, (V4PagePaginationArray), { query, ...options }); } /** * Deletes a file from a managed AI Search instance and removes its indexed data. * * @example * ```ts * const item = * await client.aiSearch.namespaces.instances.items.delete( * 'item_id', * { * account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22', * name: 'my-namespace', * id: 'my-ai-search', * }, * ); * ``` */ delete(itemID, params, options) { const { account_id, name, id } = params; return this._client.delete(path `/accounts/${account_id}/ai-search/namespaces/${name}/instances/${id}/items/${itemID}`, options)._thenUnwrap((obj) => obj.result); } /** * Lists chunks for a specific item in an AI Search instance, including their text * content. * * @example * ```ts * const response = * await client.aiSearch.namespaces.instances.items.chunks( * 'item_id', * { * account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22', * name: 'my-namespace', * id: 'my-ai-search', * }, * ); * ``` */ chunks(itemID, params, options) { const { account_id, name, id, ...query } = params; return this._client.get(path `/accounts/${account_id}/ai-search/namespaces/${name}/instances/${id}/items/${itemID}/chunks`, { query, ...options })._thenUnwrap((obj) => obj.result); } /** * Creates or updates an indexed item in an AI Search instance. * * @example * ```ts * const response = * await client.aiSearch.namespaces.instances.items.createOrUpdate( * 'my-ai-search', * { * account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22', * name: 'my-namespace', * key: 'key', * next_action: 'INDEX', * }, * ); * ``` */ createOrUpdate(id, params, options) { const { account_id, name, ...body } = params; return this._client.put(path `/accounts/${account_id}/ai-search/namespaces/${name}/instances/${id}/items`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Downloads the raw file content for a specific item from the managed AI Search * instance storage. * * @example * ```ts * const response = * await client.aiSearch.namespaces.instances.items.download( * 'item_id', * { * account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22', * name: 'my-namespace', * id: 'my-ai-search', * }, * ); * * const content = await response.blob(); * console.log(content); * ``` */ download(itemID, params, options) { const { account_id, name, id } = params; return this._client.get(path `/accounts/${account_id}/ai-search/namespaces/${name}/instances/${id}/items/${itemID}/download`, { ...options, headers: buildHeaders([{ Accept: 'application/octet-stream' }, options?.headers]), __binaryResponse: true, }); } /** * Retrieves a specific indexed item from an AI Search instance. * * @example * ```ts * const item = * await client.aiSearch.namespaces.instances.items.get( * 'item_id', * { * account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22', * name: 'my-namespace', * id: 'my-ai-search', * }, * ); * ``` */ get(itemID, params, options) { const { account_id, name, id } = params; return this._client.get(path `/accounts/${account_id}/ai-search/namespaces/${name}/instances/${id}/items/${itemID}`, options)._thenUnwrap((obj) => obj.result); } /** * Lists processing logs for a specific item in an AI Search instance. * * @example * ```ts * const response = * await client.aiSearch.namespaces.instances.items.logs( * 'item_id', * { * account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22', * name: 'my-namespace', * id: 'my-ai-search', * }, * ); * ``` */ logs(itemID, params, options) { const { account_id, name, id, ...query } = params; return this._client.get(path `/accounts/${account_id}/ai-search/namespaces/${name}/instances/${id}/items/${itemID}/logs`, { query, ...options })._thenUnwrap((obj) => obj.result); } /** * Syncs an item to an AI Search instance index. * * @example * ```ts * const response = * await client.aiSearch.namespaces.instances.items.sync( * 'item_id', * { * account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22', * name: 'my-namespace', * id: 'my-ai-search', * next_action: 'INDEX', * }, * ); * ``` */ sync(itemID, params, options) { const { account_id, name, id, ...body } = params; return this._client.patch(path `/accounts/${account_id}/ai-search/namespaces/${name}/instances/${id}/items/${itemID}`, { body, ...options })._thenUnwrap((obj) => obj.result); } /** * Uploads a file to a managed AI Search instance via multipart/form-data. * * @example * ```ts * const response = * await client.aiSearch.namespaces.instances.items.upload( * 'my-ai-search', * { * account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22', * name: 'my-namespace', * file: { file: fs.createReadStream('path/to/file') }, * }, * ); * ``` */ upload(id, params, options) { const { account_id, name, file } = params; return this._client.post(path `/accounts/${account_id}/ai-search/namespaces/${name}/instances/${id}/items`, multipartFormRequestOptions({ body: file, ...options }, this._client))._thenUnwrap((obj) => obj.result); } } BaseItems._key = Object.freeze([ 'aiSearch', 'namespaces', 'instances', 'items', ]); return BaseItems; })(); export class Items extends BaseItems { } //# sourceMappingURL=items.mjs.map