// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../../../core/resource'; 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 { /** * List Performance Insights conversations for the current user. * * @example * ```ts * await client.v1.performanceInsights.conversations.list(); * ``` */ list(params: ConversationListParams | null | undefined = {}, options?: RequestOptions): APIPromise { const { 'x-user-id': xUserID, 'x-group-ids': xGroupIDs, ...query } = params ?? {}; return this._client.get('/api/v1/performance-insights/sessions', { query, ...options, headers: buildHeaders([ { Accept: '*/*', ...(xUserID != null ? { 'x-user-id': xUserID } : undefined), ...(xGroupIDs != null ? { 'x-group-ids': xGroupIDs } : undefined), }, options?.headers, ]), }); } /** * Create a new Performance Insights conversation. * * @example * ```ts * await client.v1.performanceInsights.conversations.create(); * ``` */ create( params: ConversationCreateParams | null | undefined = {}, options?: RequestOptions, ): APIPromise { const { 'x-group-ids': xGroupIDs, 'x-user-id': xUserID, ...body } = params ?? {}; return this._client.post('/api/v1/performance-insights/sessions/create', { body, ...options, headers: buildHeaders([ { Accept: '*/*', ...(xGroupIDs != null ? { 'x-group-ids': xGroupIDs } : undefined), ...(xUserID != null ? { 'x-user-id': xUserID } : undefined), }, options?.headers, ]), }); } /** * Retrieve a single conversation with its full message history. * * @example * ```ts * await client.v1.performanceInsights.conversations.retrieve('sessionId'); * ``` */ retrieve( sessionID: string, params: ConversationRetrieveParams | null | undefined = {}, options?: RequestOptions, ): APIPromise { const { 'x-group-ids': xGroupIDs, 'x-user-id': xUserID } = params ?? {}; return this._client.get(path`/api/v1/performance-insights/session/${sessionID}`, { ...options, headers: buildHeaders([ { Accept: '*/*', ...(xGroupIDs != null ? { 'x-group-ids': xGroupIDs } : undefined), ...(xUserID != null ? { 'x-user-id': xUserID } : undefined), }, options?.headers, ]), }); } /** * Push messages to a conversation. Creates the conversation if it does not exist. * * @example * ```ts * await client.v1.performanceInsights.conversations.pushMessages('sessionId', { * messages: [], * }); * ``` */ pushMessages( sessionID: string, params: ConversationPushMessagesParams, options?: RequestOptions, ): APIPromise { const { 'x-group-ids': xGroupIDs, 'x-user-id': xUserID, ...body } = params; return this._client.put(path`/api/v1/performance-insights/session/${sessionID}/messages`, { body, ...options, headers: buildHeaders([ { Accept: '*/*', ...(xGroupIDs != null ? { 'x-group-ids': xGroupIDs } : undefined), ...(xUserID != null ? { 'x-user-id': xUserID } : undefined), }, options?.headers, ]), }); } /** * Rename a conversation. * * @example * ```ts * await client.v1.performanceInsights.conversations.rename('sessionId', { * title: 'New title', * }); * ``` */ rename(sessionID: string, params: ConversationRenameParams, options?: RequestOptions): APIPromise { const { 'x-group-ids': xGroupIDs, 'x-user-id': xUserID, ...body } = params; return this._client.patch(path`/api/v1/performance-insights/session/${sessionID}/title`, { body, ...options, headers: buildHeaders([ { Accept: '*/*', ...(xGroupIDs != null ? { 'x-group-ids': xGroupIDs } : undefined), ...(xUserID != null ? { 'x-user-id': xUserID } : undefined), }, options?.headers, ]), }); } /** * Export a single conversation's prompts as CSV. * * @example * ```ts * const csv = await client.v1.performanceInsights.conversations.exportPrompts('sessionId'); * ``` */ exportPrompts( sessionID: string, params: ConversationExportPromptsParams | null | undefined = {}, options?: RequestOptions, ): APIPromise { const { 'x-user-id': xUserID } = params ?? {}; return this._client.get(path`/api/v1/performance-insights/session/${sessionID}/export`, { ...options, headers: buildHeaders([ { Accept: 'text/csv', ...(xUserID != null ? { 'x-user-id': xUserID } : undefined), }, options?.headers, ]), }); } /** * Delete a conversation. * * @example * ```ts * await client.v1.performanceInsights.conversations.delete('sessionId'); * ``` */ delete( sessionID: string, params: ConversationDeleteParams | null | undefined = {}, options?: RequestOptions, ): APIPromise { const { 'x-group-ids': xGroupIDs, 'x-user-id': xUserID } = params ?? {}; return this._client.delete(path`/api/v1/performance-insights/session/${sessionID}`, { ...options, headers: buildHeaders([ { Accept: '*/*', ...(xGroupIDs != null ? { 'x-group-ids': xGroupIDs } : undefined), ...(xUserID != null ? { 'x-user-id': xUserID } : undefined), }, options?.headers, ]), }); } } export interface ConversationListParams { /** * Query param: Maximum number of conversations to return (default 50) */ limit?: string; /** * Header param: Group IDs header (comma-separated) to scope sessions by group */ 'x-group-ids'?: string; /** * Header param: User ID header (used when authenticating via API key) */ 'x-user-id'?: string; } export interface ConversationCreateParams { /** * Body param: Custom session ID. Auto-generated if omitted. */ sessionId?: string; /** * Body param: Conversation title (default "New Chat") */ title?: string; /** * Body param: User ID for tracking (used when authenticating via API key) */ userId?: string; /** * Header param: Group IDs header (comma-separated) to scope sessions by group */ 'x-group-ids'?: string; /** * Header param: User ID header (used when authenticating via API key) */ 'x-user-id'?: string; } export interface ConversationRetrieveParams { /** * Header param: Group IDs header (comma-separated) to scope sessions by group */ 'x-group-ids'?: string; /** * Header param: User ID header (used when authenticating via API key) */ 'x-user-id'?: string; } export interface ConversationPushMessagesParams { /** * Body param: Array of AI SDK UIMessage objects to persist */ messages: unknown; /** * Body param: Update the conversation title */ title?: string; /** * Body param: User ID for tracking (used when authenticating via API key) */ userId?: string; /** * Header param: Group IDs header (comma-separated) to scope sessions by group */ 'x-group-ids'?: string; /** * Header param: User ID header (used when authenticating via API key) */ 'x-user-id'?: string; } export interface ConversationRenameParams { /** * Body param: New conversation title */ title: string; /** * Header param: Group IDs header (comma-separated) to scope sessions by group */ 'x-group-ids'?: string; /** * Header param: User ID header (used when authenticating via API key) */ 'x-user-id'?: string; } export interface ConversationDeleteParams { /** * Header param: Group IDs header (comma-separated) to scope sessions by group */ 'x-group-ids'?: string; /** * Header param: User ID header (used when authenticating via API key) */ 'x-user-id'?: string; } export interface ConversationExportPromptsParams { /** * Header param: User ID header (used when authenticating via API key) */ 'x-user-id'?: string; } export declare namespace Conversations { export { type ConversationListParams as ConversationListParams, type ConversationCreateParams as ConversationCreateParams, type ConversationRetrieveParams as ConversationRetrieveParams, type ConversationPushMessagesParams as ConversationPushMessagesParams, type ConversationRenameParams as ConversationRenameParams, type ConversationDeleteParams as ConversationDeleteParams, type ConversationExportPromptsParams as ConversationExportPromptsParams, }; }