cloudflare
Version:
The official TypeScript library for the Cloudflare API
208 lines • 8.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Instances = exports.BaseInstances = 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 ItemsAPI = tslib_1.__importStar(require("./items.js"));
const items_1 = require("./items.js");
const JobsAPI = tslib_1.__importStar(require("./jobs.js"));
const jobs_1 = require("./jobs.js");
const pagination_1 = require("../../../../core/pagination.js");
const path_1 = require("../../../../internal/utils/path.js");
var BaseInstances = /* @__PURE__ */ (() => {
class BaseInstances extends resource_1.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((0, path_1.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((0, path_1.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((0, path_1.path) `/accounts/${account_id}/ai-search/namespaces/${name}/instances`, (pagination_1.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((0, path_1.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((0, path_1.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((0, path_1.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((0, path_1.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((0, path_1.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;
})();
exports.BaseInstances = BaseInstances;
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_1.Jobs;
Instances.BaseJobs = jobs_1.BaseJobs;
Instances.Items = items_1.Items;
Instances.BaseItems = items_1.BaseItems;
return Instances;
})();
exports.Instances = Instances;
//# sourceMappingURL=instances.js.map