cloudflare
Version:
The official TypeScript library for the Cloudflare API
220 lines • 8.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Items = exports.BaseItems = void 0;
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
const resource_1 = require("../../../../core/resource.js");
const pagination_1 = require("../../../../core/pagination.js");
const headers_1 = require("../../../../internal/headers.js");
const uploads_1 = require("../../../../internal/uploads.js");
const path_1 = require("../../../../internal/utils/path.js");
var BaseItems = /* @__PURE__ */ (() => {
class BaseItems extends resource_1.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((0, path_1.path) `/accounts/${account_id}/ai-search/namespaces/${name}/instances/${id}/items`, (pagination_1.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((0, path_1.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((0, path_1.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((0, path_1.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((0, path_1.path) `/accounts/${account_id}/ai-search/namespaces/${name}/instances/${id}/items/${itemID}/download`, {
...options,
headers: (0, headers_1.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((0, path_1.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((0, path_1.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((0, path_1.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((0, path_1.path) `/accounts/${account_id}/ai-search/namespaces/${name}/instances/${id}/items`, (0, uploads_1.multipartFormRequestOptions)({ body: file, ...options }, this._client))._thenUnwrap((obj) => obj.result);
}
}
BaseItems._key = Object.freeze([
'aiSearch',
'namespaces',
'instances',
'items',
]);
return BaseItems;
})();
exports.BaseItems = BaseItems;
class Items extends BaseItems {
}
exports.Items = Items;
//# sourceMappingURL=items.js.map