// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../../core/resource'; import * as DocumentsAPI from './documents'; import { DocumentUpdateParams, DocumentUpdateResponse, Documents } from './documents'; import * as MessagesAPI from './messages'; import { MessageListParams, MessageListResponse, Messages } from './messages'; import * as ShareAPI from './share'; import { Share, ShareCreateOrUpdateParams, ShareListParams, SharedConversation } from './share'; import * as SharedAPI from './shared'; import { Conversation, GetSharedConversation, Shared, SharedCloneParams, SharedCloneResponse, SharedDeleteParams, SharedDeleteResponse, SharedListParams, SharedListResponse, SharedRetrieveParams, } from './shared'; import * as TitleAPI from './title'; import { Title, TitleGenerateParams, TitleGenerateResponse } from './title'; import { APIPromise } from '../../core/api-promise'; import { buildHeaders } from '../../internal/headers'; import { RequestOptions } from '../../internal/request-options'; import { path } from '../../internal/utils/path'; export class Conversations extends APIResource { messages: MessagesAPI.Messages = new MessagesAPI.Messages(this._client); documents: DocumentsAPI.Documents = new DocumentsAPI.Documents(this._client); title: TitleAPI.Title = new TitleAPI.Title(this._client); share: ShareAPI.Share = new ShareAPI.Share(this._client); shared: SharedAPI.Shared = new SharedAPI.Shared(this._client); /** * Create a new conversation with optional title. */ create(params: ConversationCreateParams, options?: RequestOptions): APIPromise { const { 'Accept-Language': acceptLanguage, 'X-Error-Format': xErrorFormat, ...body } = params; return this._client.post('/conversations', { body, ...options, headers: buildHeaders([ { 'Content-Type': 'application/x-www-form-urlencoded', ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), }, options?.headers, ]), }); } /** * Rename an existing conversation with a new title. */ update( conversationID: string, params: ConversationUpdateParams, options?: RequestOptions, ): APIPromise { const { 'Accept-Language': acceptLanguage, 'X-Error-Format': xErrorFormat, ...body } = params; return this._client.patch(path`/conversations/${conversationID}`, { body, ...options, headers: buildHeaders([ { 'Content-Type': 'application/x-www-form-urlencoded', ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), }, options?.headers, ]), }); } /** * Get all conversations of current user, optionally filtered by a search query and * chatbot_id. */ list( params: ConversationListParams | null | undefined = {}, options?: RequestOptions, ): APIPromise { const { 'Accept-Language': acceptLanguage, 'If-None-Match': ifNoneMatch, 'X-Error-Format': xErrorFormat, ...query } = params ?? {}; return this._client.get('/conversations', { query, ...options, headers: buildHeaders([ { ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(ifNoneMatch != null ? { 'If-None-Match': ifNoneMatch } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), }, options?.headers, ]), }); } /** * Delete a specific conversation by ID and remove any associated attachments and * vector DB documents. */ delete( conversationID: string, params: ConversationDeleteParams | null | undefined = {}, options?: RequestOptions, ): APIPromise { const { 'Accept-Language': acceptLanguage, 'X-Error-Format': xErrorFormat } = params ?? {}; return this._client.delete(path`/conversations/${conversationID}`, { ...options, headers: buildHeaders([ { ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), }, options?.headers, ]), }); } /** * Branch a conversation by cloning a message path from last_message_id back to * root. */ branchHistory( conversationID: string, params: ConversationBranchHistoryParams, options?: RequestOptions, ): APIPromise { const { 'Accept-Language': acceptLanguage, 'X-Error-Format': xErrorFormat, ...body } = params; return this._client.post(path`/conversations/${conversationID}/branch-history`, { body, ...options, headers: buildHeaders([ { ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), }, options?.headers, ]), }); } /** * Delete multiple conversations matching the specified criteria, including * user_id, chatbot_id and optional conversation_ids. */ deleteMultiple( params: ConversationDeleteMultipleParams, options?: RequestOptions, ): APIPromise { const { 'Accept-Language': acceptLanguage, 'X-Error-Format': xErrorFormat, ...body } = params; return this._client.post('/conversations/delete', { body, ...options, headers: buildHeaders([ { ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), }, options?.headers, ]), }); } /** * Estimate remaining context window (tokens) for a model, optionally using stored * conversation history and/or a next user query. */ remainingContextWindow( params: ConversationRemainingContextWindowParams, options?: RequestOptions, ): APIPromise { const { 'Accept-Language': acceptLanguage, 'X-Error-Format': xErrorFormat, ...body } = params; return this._client.post('/conversations/remaining-context-window', { body, ...options, headers: buildHeaders([ { ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), }, options?.headers, ]), }); } } /** * Response model for creating a conversation. * * Attributes: conversation (Conversation): The created conversation details. */ export interface CreateConversation { /** * Conversation model. * * Attributes: id (str): The conversation ID. user*id (str): The user ID. title * (str | None): The conversation title. created_time (datetime): The creation * time. updated_time (datetime): The last update time. is_active (bool): Whether * the conversation is active. chatbot_id (str): The chatbot ID. is_anonymized * (bool): Whether the conversation is anonymized. deanonymized_mapping (dict[str, * str]): Mapping of anonymized to original values. first_matching_message_id (str * | None): First message ID that matches search query. first_matching_message (str * | None): First message that matches search query. metadata* (dict[str, Any] | * None): Additional metadata for the conversation. digital_employee_id (str | * None): The active Digital Employee's local id, or None if no Digital Employee is * active on this conversation. de_activated_at (datetime | None): When the active * Digital Employee became active. */ conversation: SharedAPI.Conversation; } /** * Response model for getting all conversations. * * Attributes: conversations (list[Conversation]): List of conversations. cursor * (Optional[str]): A cursor for pagination, if applicable. conversations_count * (int): The total count of conversations. */ export interface ConversationListResponse { conversations: Array; conversations_count: number; cursor?: string | null; } export type ConversationDeleteResponse = { [key: string]: unknown }; /** * Response model for branching a conversation. * * Attributes: new_conversation_id (str): The ID of the new conversation containing * the branched messages. new_parent_id (str): The ID of the new parent message * (mapped from last_message_id). old_conversation_id (str): The ID of the source * conversation that was branched from. */ export interface ConversationBranchHistoryResponse { /** * The ID of the new conversation containing the branched messages */ new_conversation_id: string; /** * The ID of the new parent message (mapped from last_message_id) */ new_parent_id: string; /** * The ID of the source conversation that was branched from */ old_conversation_id: string; } export type ConversationDeleteMultipleResponse = { [key: string]: unknown }; /** * Response model for remaining context window (token budget) estimation. * * Attributes: total_token (int): Estimated input tokens plus configured buffers. * max_token (int): Maximum input token budget for the model. remaining_token * (int): Approximate tokens remaining for new input. remaining_chars (int): * Approximate character capacity derived from remaining_token. usage_percent * (float): Estimated share of max_token used by input estimate and reserves. */ export interface ConversationRemainingContextWindowResponse { /** * Maximum input token budget for the model */ max_token: number; /** * Approximate remaining characters */ remaining_chars: number; /** * Approximate remaining tokens for new input */ remaining_token: number; /** * Estimated tokens used including buffers */ total_token: number; /** * Estimated usage as a percentage of max_token */ usage_percent: number; } export interface ConversationCreateParams { /** * Body param */ chatbot_id: string; /** * Body param */ user_id: string; /** * Body param */ metadata_?: string | null; /** * Body param */ model_name?: string; /** * Body param */ title?: string | null; /** * Header param */ 'Accept-Language'?: string; /** * Header param: Set to `structured` to receive errors in the structured envelope. * Omit it to keep the legacy error body. */ 'X-Error-Format'?: string; } export interface ConversationUpdateParams { /** * Body param */ title: string; /** * Header param */ 'Accept-Language'?: string; /** * Header param: Set to `structured` to receive errors in the structured envelope. * Omit it to keep the legacy error body. */ 'X-Error-Format'?: string; } export interface ConversationListParams { /** * Query param: Chatbot id for conversation */ chatbot_id?: string; /** * Query param: Pointer to keep track of the last fetched conversations */ cursor?: string | null; /** * Query param: Number of conversations to return per request (1-100) */ limit?: number; /** * Query param: Search query for conversation title or message content */ query?: string; /** * Header param */ 'Accept-Language'?: string; /** * Header param */ 'If-None-Match'?: string; /** * Header param: Set to `structured` to receive errors in the structured envelope. * Omit it to keep the legacy error body. */ 'X-Error-Format'?: string; } export interface ConversationDeleteParams { 'Accept-Language'?: string; /** * Set to `structured` to receive errors in the structured envelope. Omit it to * keep the legacy error body. */ 'X-Error-Format'?: string; } export interface ConversationBranchHistoryParams { /** * Body param: The ID of the assistant message (cannot be empty) */ last_message_id: string; /** * Body param */ new_conversation_id?: string | null; /** * Header param */ 'Accept-Language'?: string; /** * Header param: Set to `structured` to receive errors in the structured envelope. * Omit it to keep the legacy error body. */ 'X-Error-Format'?: string; } export interface ConversationDeleteMultipleParams { /** * Body param */ chatbot_id: string; /** * Body param */ user_id: string; /** * Body param */ conversation_ids?: Array | null; /** * Header param */ 'Accept-Language'?: string; /** * Header param: Set to `structured` to receive errors in the structured envelope. * Omit it to keep the legacy error body. */ 'X-Error-Format'?: string; } export interface ConversationRemainingContextWindowParams { /** * Body param: Model name used for token estimation (e.g. openai/gpt-4o-mini). */ model_name: string; /** * Body param: Conversation to load history from. Omit for a standalone estimate * (no stored history). */ conversation_id?: string | null; /** * Body param: Optional next user message to include in the token estimate. */ user_query?: string | null; /** * Header param */ 'Accept-Language'?: string; /** * Header param: Set to `structured` to receive errors in the structured envelope. * Omit it to keep the legacy error body. */ 'X-Error-Format'?: string; } Conversations.Messages = Messages; Conversations.Documents = Documents; Conversations.Title = Title; Conversations.Share = Share; Conversations.Shared = Shared; export declare namespace Conversations { export { type CreateConversation as CreateConversation, type ConversationListResponse as ConversationListResponse, type ConversationDeleteResponse as ConversationDeleteResponse, type ConversationBranchHistoryResponse as ConversationBranchHistoryResponse, type ConversationDeleteMultipleResponse as ConversationDeleteMultipleResponse, type ConversationRemainingContextWindowResponse as ConversationRemainingContextWindowResponse, type ConversationCreateParams as ConversationCreateParams, type ConversationUpdateParams as ConversationUpdateParams, type ConversationListParams as ConversationListParams, type ConversationDeleteParams as ConversationDeleteParams, type ConversationBranchHistoryParams as ConversationBranchHistoryParams, type ConversationDeleteMultipleParams as ConversationDeleteMultipleParams, type ConversationRemainingContextWindowParams as ConversationRemainingContextWindowParams, }; export { Messages as Messages, type MessageListResponse as MessageListResponse, type MessageListParams as MessageListParams, }; export { Documents as Documents, type DocumentUpdateResponse as DocumentUpdateResponse, type DocumentUpdateParams as DocumentUpdateParams, }; export { Title as Title, type TitleGenerateResponse as TitleGenerateResponse, type TitleGenerateParams as TitleGenerateParams, }; export { Share as Share, type SharedConversation as SharedConversation, type ShareListParams as ShareListParams, type ShareCreateOrUpdateParams as ShareCreateOrUpdateParams, }; export { Shared as Shared, type Conversation as Conversation, type GetSharedConversation as GetSharedConversation, type SharedListResponse as SharedListResponse, type SharedDeleteResponse as SharedDeleteResponse, type SharedCloneResponse as SharedCloneResponse, type SharedRetrieveParams as SharedRetrieveParams, type SharedListParams as SharedListParams, type SharedDeleteParams as SharedDeleteParams, type SharedCloneParams as SharedCloneParams, }; }