// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../../../core/resource'; import * as TasksAPI from './tasks'; 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 Tasks extends APIResource { /** * List async message tasks with filtering and pagination */ list( params: TaskListParams | null | undefined = {}, options?: RequestOptions, ): APIPromise { const { 'Accept-Language': acceptLanguage, 'X-Error-Format': xErrorFormat, ...query } = params ?? {}; return this._client.get('/v3/messages/tasks', { query, ...options, headers: buildHeaders([ { ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), }, options?.headers, ]), }); } /** * Cancel an ongoing async message task */ delete( taskID: string, params: TaskDeleteParams | null | undefined = {}, options?: RequestOptions, ): APIPromise { const { 'Accept-Language': acceptLanguage, 'X-Error-Format': xErrorFormat } = params ?? {}; return this._client.delete(path`/v3/messages/tasks/${taskID}`, { ...options, headers: buildHeaders([ { ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), }, options?.headers, ]), }); } } /** * Task status enumeration. */ export type TaskStatus = 'pending' | 'processing' | 'completed' | 'failed' | 'cancelled'; /** * Response model for task list. */ export interface TaskListResponse { tasks: Array; tasks_count: number; cursor?: string | null; } export namespace TaskListResponse { /** * Response model for a single task in list. */ export interface Task { assistant_message_id: string; created_at: string; /** * Task status enumeration. */ status: TasksAPI.TaskStatus; task_id: string; updated_at: string; user_message_id: string; cancelled_at?: string | null; chatbot_id?: string | null; completed_at?: string | null; conversation_id?: string | null; /** * Task metadata, e.g. is_regenerated, regenerated_message_id. */ metadata?: { [key: string]: unknown }; } } /** * Response model for task cancellation. */ export interface TaskDeleteResponse { cancelled_at: string; task_id: string; /** * Task status enumeration. */ status?: TaskStatus; } export interface TaskListParams { /** * Query param: Filter by chatbot ID */ chatbot_id?: string | null; /** * Query param: Filter by conversation ID */ conversation_id?: string | null; /** * Query param: Pagination cursor (ISO 8601 datetime string) */ cursor?: string | null; /** * Query param: Number of tasks per page (max 100) */ limit?: number | null; /** * Query param: Filter by task status(es) */ status?: 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 TaskDeleteParams { '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 declare namespace Tasks { export { type TaskStatus as TaskStatus, type TaskListResponse as TaskListResponse, type TaskDeleteResponse as TaskDeleteResponse, type TaskListParams as TaskListParams, type TaskDeleteParams as TaskDeleteParams, }; }