UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

165 lines • 6.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Namespaces = exports.BaseNamespaces = void 0; const tslib_1 = require("../../../internal/tslib.js"); // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. const resource_1 = require("../../../core/resource.js"); const InstancesAPI = tslib_1.__importStar(require("./instances/instances.js")); const instances_1 = require("./instances/instances.js"); const pagination_1 = require("../../../core/pagination.js"); const path_1 = require("../../../internal/utils/path.js"); var BaseNamespaces = /* @__PURE__ */ (() => { class BaseNamespaces extends resource_1.APIResource { /** * Create a namespace for organizing AI Search instances. * * @example * ```ts * const namespace = await client.aiSearch.namespaces.create({ * account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22', * name: 'name', * }); * ``` */ create(params, options) { const { account_id, ...body } = params; return this._client.post((0, path_1.path) `/accounts/${account_id}/ai-search/namespaces`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Update the description and/or the public endpoint configuration of an existing * namespace. The default namespace's description cannot be modified, but its * public endpoint can. * * @example * ```ts * const namespace = await client.aiSearch.namespaces.update( * 'production', * { account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22' }, * ); * ``` */ update(name, params, options) { const { account_id, ...body } = params; return this._client.put((0, path_1.path) `/accounts/${account_id}/ai-search/namespaces/${name}`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * List namespaces in the account, including their descriptions and creation times. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const namespaceListResponse of client.aiSearch.namespaces.list( * { account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22' }, * )) { * // ... * } * ``` */ list(params, options) { const { account_id, ...query } = params; return this._client.getAPIList((0, path_1.path) `/accounts/${account_id}/ai-search/namespaces`, (pagination_1.V4PagePaginationArray), { query, ...options }); } /** * Permanently delete a namespace. The namespace must be empty (no instances), and * the default namespace cannot be deleted. * * @example * ```ts * const namespace = await client.aiSearch.namespaces.delete( * 'production', * { account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22' }, * ); * ``` */ delete(name, params, options) { const { account_id } = params; return this._client.delete((0, path_1.path) `/accounts/${account_id}/ai-search/namespaces/${name}`, options)._thenUnwrap((obj) => obj.result); } /** * Performs a chat completion request against multiple AI Search instances in * parallel, merging retrieved content as context for generating a response. * * @example * ```ts * const response = * await client.aiSearch.namespaces.chatCompletions( * 'my-namespace', * { * account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22', * ai_search_options: { instance_ids: ['my-ai-search'] }, * messages: [{ content: 'string', role: 'system' }], * }, * ); * ``` */ chatCompletions(name, params, options) { const { account_id, ...body } = params; return this._client.post((0, path_1.path) `/accounts/${account_id}/ai-search/namespaces/${name}/chat/completions`, { body, ...options, }); } /** * Retrieve a namespace and its description. * * @example * ```ts * const response = await client.aiSearch.namespaces.read( * 'production', * { account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22' }, * ); * ``` */ read(name, params, options) { const { account_id } = params; return this._client.get((0, path_1.path) `/accounts/${account_id}/ai-search/namespaces/${name}`, options)._thenUnwrap((obj) => obj.result); } /** * Performs a semantic search query against multiple AI Search instances in * parallel, merging the retrieved results into a single ranked response. * * @example * ```ts * const response = await client.aiSearch.namespaces.search( * 'my-namespace', * { * account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22', * ai_search_options: { instance_ids: ['my-ai-search'] }, * }, * ); * ``` */ search(name, params, options) { const { account_id, ...body } = params; return this._client.post((0, path_1.path) `/accounts/${account_id}/ai-search/namespaces/${name}/search`, { body, ...options, })._thenUnwrap((obj) => obj.result); } } BaseNamespaces._key = Object.freeze([ 'aiSearch', 'namespaces', ]); return BaseNamespaces; })(); exports.BaseNamespaces = BaseNamespaces; var Namespaces = /* @__PURE__ */ (() => { class Namespaces extends BaseNamespaces { constructor() { super(...arguments); this.instances = new InstancesAPI.Instances(this._client); } } Namespaces.Instances = instances_1.Instances; Namespaces.BaseInstances = instances_1.BaseInstances; return Namespaces; })(); exports.Namespaces = Namespaces; //# sourceMappingURL=namespaces.js.map