// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from "../../../resource.js"; import { isRequestOptions } from "../../../core.js"; import * as Core from "../../../core.js"; import * as WorkspacesAPI from "../workspaces.js"; import { Page, type PageParams } from "../../../pagination.js"; export class Messages extends APIResource { /** * Add new message(s) to a session. */ create( workspaceId: string, sessionId: string, body: MessageCreateParams, options?: Core.RequestOptions, ): Core.APIPromise { return this._client.post(`/v2/workspaces/${workspaceId}/sessions/${sessionId}/messages`, { body, ...options, }); } /** * Update the metadata of a message. * * This will overwrite any existing metadata for the message. */ update( workspaceId: string, sessionId: string, messageId: string, body: MessageUpdateParams, options?: Core.RequestOptions, ): Core.APIPromise { return this._client.put(`/v2/workspaces/${workspaceId}/sessions/${sessionId}/messages/${messageId}`, { body, ...options, }); } /** * Get all messages for a Session with optional filters. Results are paginated. */ list( workspaceId: string, sessionId: string, params?: MessageListParams, options?: Core.RequestOptions, ): Core.PagePromise; list( workspaceId: string, sessionId: string, options?: Core.RequestOptions, ): Core.PagePromise; list( workspaceId: string, sessionId: string, params: MessageListParams | Core.RequestOptions = {}, options?: Core.RequestOptions, ): Core.PagePromise { if (isRequestOptions(params)) { return this.list(workspaceId, sessionId, {}, params); } const { page, reverse, size, ...body } = params; return this._client.getAPIList( `/v2/workspaces/${workspaceId}/sessions/${sessionId}/messages/list`, MessagesPage, { query: { page, reverse, size }, body, method: 'post', ...options }, ); } /** * Get a single message by ID from a Session. */ get( workspaceId: string, sessionId: string, messageId: string, options?: Core.RequestOptions, ): Core.APIPromise { return this._client.get( `/v2/workspaces/${workspaceId}/sessions/${sessionId}/messages/${messageId}`, options, ); } /** * Create messages from uploaded files. Files are converted to text and split into * multiple messages. */ upload( workspaceId: string, sessionId: string, body: MessageUploadParams, options?: Core.RequestOptions, ): Core.APIPromise { return this._client.post( `/v2/workspaces/${workspaceId}/sessions/${sessionId}/messages/upload`, Core.multipartFormRequestOptions({ body, ...options }), ); } } export class MessagesPage extends Page {} export interface Message { id: string; content: string; created_at: string; peer_id: string; session_id: string; token_count: number; workspace_id: string; metadata?: { [key: string]: unknown }; } export interface MessageCreate { content: string; peer_id: string; /** * The set of options that can be in a message DB-level configuration dictionary. * * All fields are optional. Message-level configuration overrides all other * configurations. */ configuration?: MessageCreate.Configuration | null; created_at?: string | null; metadata?: { [key: string]: unknown } | null; } export namespace MessageCreate { /** * The set of options that can be in a message DB-level configuration dictionary. * * All fields are optional. Message-level configuration overrides all other * configurations. */ export interface Configuration { /** * Configuration for reasoning functionality. */ reasoning?: WorkspacesAPI.ReasoningConfiguration | null; } } export type MessageCreateResponse = Array; export type MessageUploadResponse = Array; export interface MessageCreateParams { messages: Array; } export interface MessageUpdateParams { metadata?: { [key: string]: unknown } | null; } export interface MessageListParams extends PageParams { /** * Query param: Whether to reverse the order of results */ reverse?: boolean | null; /** * Body param: */ filters?: { [key: string]: unknown } | null; } export interface MessageUploadParams { file: Core.Uploadable; peer_id: string; configuration?: string | null; created_at?: string | null; metadata?: string | null; } Messages.MessagesPage = MessagesPage; export declare namespace Messages { export { type Message as Message, type MessageCreate as MessageCreate, type MessageCreateResponse as MessageCreateResponse, type MessageUploadResponse as MessageUploadResponse, MessagesPage as MessagesPage, type MessageCreateParams as MessageCreateParams, type MessageUpdateParams as MessageUpdateParams, type MessageListParams as MessageListParams, type MessageUploadParams as MessageUploadParams, }; }