cloudflare
Version:
The official TypeScript library for the Cloudflare API
159 lines • 6.04 kB
JavaScript
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from "../../../core/resource.mjs";
import * as InstancesAPI from "./instances/instances.mjs";
import { BaseInstances, Instances, } from "./instances/instances.mjs";
import { V4PagePaginationArray, } from "../../../core/pagination.mjs";
import { path } from "../../../internal/utils/path.mjs";
export var BaseNamespaces = /* @__PURE__ */ (() => {
class BaseNamespaces extends 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(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(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(path `/accounts/${account_id}/ai-search/namespaces`, (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(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(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(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(path `/accounts/${account_id}/ai-search/namespaces/${name}/search`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
}
BaseNamespaces._key = Object.freeze([
'aiSearch',
'namespaces',
]);
return BaseNamespaces;
})();
export var Namespaces = /* @__PURE__ */ (() => {
class Namespaces extends BaseNamespaces {
constructor() {
super(...arguments);
this.instances = new InstancesAPI.Instances(this._client);
}
}
Namespaces.Instances = Instances;
Namespaces.BaseInstances = BaseInstances;
return Namespaces;
})();
//# sourceMappingURL=namespaces.mjs.map