cloudflare
Version:
The official TypeScript library for the Cloudflare API
202 lines • 7.72 kB
JavaScript
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from "../../../../core/resource.mjs";
import * as ItemsAPI from "./items.mjs";
import { BaseItems, Items, } from "./items.mjs";
import * as JobsAPI from "./jobs.mjs";
import { BaseJobs, Jobs, } from "./jobs.mjs";
import { V4PagePaginationArray, } from "../../../../core/pagination.mjs";
import { path } from "../../../../internal/utils/path.mjs";
export var BaseInstances = /* @__PURE__ */ (() => {
class BaseInstances extends APIResource {
/**
* Create a new AI Search instance with the given configuration. If type is omitted
* or null, a non-blank HTTP(S) source infers web-crawler and an existing R2 bucket
* source infers r2. A missing or blank source without a type creates a managed
* upload-only instance. Search for Agents instances require the default namespace.
*
* @example
* ```ts
* const instance =
* await client.aiSearch.namespaces.instances.create(
* 'my-namespace',
* {
* account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22',
* id: 'my-ai-search',
* },
* );
* ```
*/
create(name, params, options) {
const { account_id, ...body } = params;
return this._client.post(path `/accounts/${account_id}/ai-search/namespaces/${name}/instances`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Update an AI Search instance. Submitting Search for Agents metadata requires the
* default namespace; omitting or removing it is allowed elsewhere. Submit Search
* for Agents metadata and restrictive or unknown public endpoint changes or custom
* domains in separate PUT requests, even when resubmitting unchanged metadata.
*
* @example
* ```ts
* const instance =
* await client.aiSearch.namespaces.instances.update(
* 'my-ai-search',
* {
* account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22',
* name: 'my-namespace',
* },
* );
* ```
*/
update(id, params, options) {
const { account_id, name, ...body } = params;
return this._client.put(path `/accounts/${account_id}/ai-search/namespaces/${name}/instances/${id}`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* List all AI Search instances in the account.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const instanceListResponse of client.aiSearch.namespaces.instances.list(
* 'my-namespace',
* { account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22' },
* )) {
* // ...
* }
* ```
*/
list(name, params, options) {
const { account_id, ...query } = params;
return this._client.getAPIList(path `/accounts/${account_id}/ai-search/namespaces/${name}/instances`, (V4PagePaginationArray), { query, ...options });
}
/**
* Permanently delete an AI Search instance and all its indexed data.
*
* @example
* ```ts
* const instance =
* await client.aiSearch.namespaces.instances.delete(
* 'my-ai-search',
* {
* account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22',
* name: 'my-namespace',
* },
* );
* ```
*/
delete(id, params, options) {
const { account_id, name } = params;
return this._client.delete(path `/accounts/${account_id}/ai-search/namespaces/${name}/instances/${id}`, options)._thenUnwrap((obj) => obj.result);
}
/**
* Performs a chat completion request against an AI Search instance, using indexed
* content as context for generating responses.
*
* @example
* ```ts
* const response =
* await client.aiSearch.namespaces.instances.chatCompletions(
* 'my-ai-search',
* {
* account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22',
* name: 'my-namespace',
* messages: [{ content: 'string', role: 'system' }],
* },
* );
* ```
*/
chatCompletions(id, params, options) {
const { account_id, name, ...body } = params;
return this._client.post(path `/accounts/${account_id}/ai-search/namespaces/${name}/instances/${id}/chat/completions`, { body, ...options });
}
/**
* Retrieve the configuration and status of an AI Search instance.
*
* @example
* ```ts
* const response =
* await client.aiSearch.namespaces.instances.read(
* 'my-ai-search',
* {
* account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22',
* name: 'my-namespace',
* },
* );
* ```
*/
read(id, params, options) {
const { account_id, name } = params;
return this._client.get(path `/accounts/${account_id}/ai-search/namespaces/${name}/instances/${id}`, options)._thenUnwrap((obj) => obj.result);
}
/**
* Executes a semantic search query against an AI Search instance to find relevant
* indexed content.
*
* @example
* ```ts
* const response =
* await client.aiSearch.namespaces.instances.search(
* 'my-ai-search',
* {
* account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22',
* name: 'my-namespace',
* },
* );
* ```
*/
search(id, params, options) {
const { account_id, name, ...body } = params;
return this._client.post(path `/accounts/${account_id}/ai-search/namespaces/${name}/instances/${id}/search`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Retrieve usage and indexing statistics for an AI Search instance.
*
* @example
* ```ts
* const response =
* await client.aiSearch.namespaces.instances.stats(
* 'my-ai-search',
* {
* account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22',
* name: 'my-namespace',
* },
* );
* ```
*/
stats(id, params, options) {
const { account_id, name } = params;
return this._client.get(path `/accounts/${account_id}/ai-search/namespaces/${name}/instances/${id}/stats`, options)._thenUnwrap((obj) => obj.result);
}
}
BaseInstances._key = Object.freeze([
'aiSearch',
'namespaces',
'instances',
]);
return BaseInstances;
})();
export var Instances = /* @__PURE__ */ (() => {
class Instances extends BaseInstances {
constructor() {
super(...arguments);
this.jobs = new JobsAPI.Jobs(this._client);
this.items = new ItemsAPI.Items(this._client);
}
}
Instances.Jobs = Jobs;
Instances.BaseJobs = BaseJobs;
Instances.Items = Items;
Instances.BaseItems = BaseItems;
return Instances;
})();
//# sourceMappingURL=instances.mjs.map