// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../../../../core/resource'; import * as KnowledgeBasesAPI from './knowledge-bases'; import { AgentDocumentsCursor } from './knowledge-bases'; import { APIPromise } from '../../../../core/api-promise'; import { Cursor, type CursorParams, PagePromise } from '../../../../core/pagination'; import { buildHeaders } from '../../../../internal/headers'; import { RequestOptions } from '../../../../internal/request-options'; import { path } from '../../../../internal/utils/path'; export class Documents extends APIResource { /** * Add a document to a knowledge base. The document will be automatically processed * for RAG. * * @example * ```ts * const document = * await client.senders.agent.knowledgeBases.documents.create( * 'kbId', * { * senderId: 'senderId', * content: * 'Our return policy allows returns within 30 days of purchase...', * title: 'Return Policy', * }, * ); * ``` */ create( kbID: string, params: DocumentCreateParams, options?: RequestOptions, ): APIPromise { const { senderId, ...body } = params; return this._client.post(path`/v1/senders/${senderId}/agent/knowledge-bases/${kbID}/documents`, { body, ...options, }); } /** * List documents in a knowledge base. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const agentDocument of client.senders.agent.knowledgeBases.documents.list( * 'kbId', * { senderId: 'senderId' }, * )) { * // ... * } * ``` */ list( kbID: string, params: DocumentListParams, options?: RequestOptions, ): PagePromise { const { senderId, ...query } = params; return this._client.getAPIList( path`/v1/senders/${senderId}/agent/knowledge-bases/${kbID}/documents`, Cursor, { query, ...options }, ); } /** * Delete a document from a knowledge base. * * @example * ```ts * await client.senders.agent.knowledgeBases.documents.delete( * 'docId', * { senderId: 'senderId', kbId: 'kbId' }, * ); * ``` */ delete(docID: string, params: DocumentDeleteParams, options?: RequestOptions): APIPromise { const { senderId, kbId } = params; return this._client.delete( path`/v1/senders/${senderId}/agent/knowledge-bases/${kbId}/documents/${docID}`, { ...options, headers: buildHeaders([{ Accept: '*/*' }, options?.headers]) }, ); } /** * Get a single document from a knowledge base. * * @example * ```ts * const response = * await client.senders.agent.knowledgeBases.documents.retrieveDocument( * 'docId', * { senderId: 'senderId', kbId: 'kbId' }, * ); * ``` */ retrieveDocument( docID: string, params: DocumentRetrieveDocumentParams, options?: RequestOptions, ): APIPromise { const { senderId, kbId } = params; return this._client.get( path`/v1/senders/${senderId}/agent/knowledge-bases/${kbId}/documents/${docID}`, options, ); } /** * Update a document's title or content. Updating content reprocesses the document * for RAG. * * @example * ```ts * const response = * await client.senders.agent.knowledgeBases.documents.updateDocument( * 'docId', * { senderId: 'senderId', kbId: 'kbId' }, * ); * ``` */ updateDocument( docID: string, params: DocumentUpdateDocumentParams, options?: RequestOptions, ): APIPromise { const { senderId, kbId, ...body } = params; return this._client.patch( path`/v1/senders/${senderId}/agent/knowledge-bases/${kbId}/documents/${docID}`, { body, ...options }, ); } } export interface DocumentCreateResponse { document: KnowledgeBasesAPI.AgentDocument; } export interface DocumentRetrieveDocumentResponse { document: KnowledgeBasesAPI.AgentDocument; } export interface DocumentUpdateDocumentResponse { document: KnowledgeBasesAPI.AgentDocument; } export interface DocumentCreateParams { /** * Path param */ senderId: string; /** * Body param */ content: string; /** * Body param */ title: string; } export interface DocumentListParams extends CursorParams { /** * Path param */ senderId: string; } export interface DocumentDeleteParams { senderId: string; kbId: string; } export interface DocumentRetrieveDocumentParams { senderId: string; kbId: string; } export interface DocumentUpdateDocumentParams { /** * Path param */ senderId: string; /** * Path param */ kbId: string; /** * Body param */ content?: string; /** * Body param */ title?: string; } export declare namespace Documents { export { type DocumentCreateResponse as DocumentCreateResponse, type DocumentRetrieveDocumentResponse as DocumentRetrieveDocumentResponse, type DocumentUpdateDocumentResponse as DocumentUpdateDocumentResponse, type DocumentCreateParams as DocumentCreateParams, type DocumentListParams as DocumentListParams, type DocumentDeleteParams as DocumentDeleteParams, type DocumentRetrieveDocumentParams as DocumentRetrieveDocumentParams, type DocumentUpdateDocumentParams as DocumentUpdateDocumentParams, }; } export { type AgentDocumentsCursor };