Skip to content

ConversationMethods

Methods interface that will be added to conversation objects

Properties

Property Modifier Type Description
exchanges readonly ConversationExchangeServiceModel Scoped exchange operations for this conversation

Methods

delete()

delete(): Promise<RawConversationGetResponse>

Deletes this conversation

Returns

Promise<RawConversationGetResponse>

Promise resolving to the deletion response


endSession()

endSession(): void

Ends the active session for this conversation

Sends a session end event and cleans up the session resources.

Returns

void

Example

// End the session when done
conversation.endSession();

getSession()

getSession(): undefined | SessionStream

Gets the active session for this conversation

Returns

undefined | SessionStream

The session helper if active, undefined otherwise

Example

const session = conversation.getSession();
if (session) {
  // Session already started — safe to send exchanges directly
  const exchange = session.startExchange();
  exchange.sendMessageWithContentPart({ data: 'Hello!' });
}

startSession()

startSession(options?: ConversationSessionOptions): SessionStream

Starts a real-time chat session for this conversation

Creates a WebSocket session and returns a SessionStream for sending and receiving messages in real-time.

Parameters

Parameter Type Description
options? ConversationSessionOptions Optional session options

Returns

SessionStream

SessionStream for managing the session

Example

const conversation = await conversationalAgent.conversations.create(agentId, folderId);

// Start a real-time session
const session = conversation.startSession();

// Listen for responses using helper methods
session.onExchangeStart((exchange) => {
  exchange.onMessageStart((message) => {
    // Filter for assistant messages
    if (message.isAssistant) {
      message.onContentPartStart((part) => {
        // Handle text content
        if (part.isMarkdown) {
          part.onChunk((chunk) => console.log(chunk.data));
        }
      });
    }
  });
});

// Wait for session to be ready, then send a message
session.onSessionStarted(() => {
  const exchange = session.startExchange();
  exchange.sendMessageWithContentPart({ data: 'Hello!' });
});

update()

update(options: ConversationUpdateOptions): Promise<ConversationGetResponse>

Updates this conversation

Parameters

Parameter Type Description
options ConversationUpdateOptions Fields to update

Returns

Promise<ConversationGetResponse>

Promise resolving to the updated conversation


uploadAttachment()

uploadAttachment(file: File): Promise<ConversationAttachmentUploadResponse>

Uploads a file attachment to this conversation

Parameters

Parameter Type Description
file File The file to upload

Returns

Promise<ConversationAttachmentUploadResponse>

Promise resolving to attachment metadata with URI ConversationAttachmentUploadResponse

Example

const attachment = await conversation.uploadAttachment(file);
console.log(`Uploaded: ${attachment.uri}`);