# Class Chat

Base class for all SDK objects.

This class provides a base implementation for all SDK objects. It handles event emission, promise management, and initialization.

This object is used to ensure that an SRE instance is initialized, and if not, create one with default settings.

#### Hierarchy (View Summary)

- SDKObject
  - Chat

- Defined in src/LLM/Chat.class.ts:183

##### Index

### Constructors

constructor

### Properties

_conversation
_readyPromise
_streamLock

### Accessors

agentData
conversation
id
ready

### Methods

emit
init
initSignal
off
on
once
prompt
removeListener

## Constructors

### constructor

- new Chat(
  options: ChatOptions & { candidate: AccessCandidate },
  source?: Record<string, any> | Agent,
  _convOptions?: any,
  ): Chat

  #### Parameters

  - options: ChatOptions & { candidate: AccessCandidate }
  - `Optional` source: Record<string, any> | Agent
  - _convOptions: any = {}

  #### Returns Chat

  Overrides SDKObject.constructor

  - Defined in src/LLM/Chat.class.ts:213

## Properties

### _conversation

_conversation: Conversation

- Defined in src/LLM/Chat.class.ts:185

### `Protected`_readyPromise

_readyPromise: ControlledPromise<any>

Inherited from SDKObject._readyPromise

- Defined in src/Core/SDKObject.class.ts:17

### _streamLock

_streamLock: Promise<void> = ...

- Defined in src/LLM/Chat.class.ts:186

## Accessors

### agentData

- get agentData(): any

  #### Returns any

  - Defined in src/LLM/Chat.class.ts:210

### conversation

- get conversation(): Conversation

  The SRE Conversation Manager instance that is used to handle the current chat conversation.

  #### Returns Conversation

  - Defined in src/LLM/Chat.class.ts:190

### id

- get id(): string

  #### Returns string

  - Defined in src/LLM/Chat.class.ts:196

### ready

- get ready(): ControlledPromise<any>

  #### Returns ControlledPromise<any>

  Inherited from SDKObject.ready

  - Defined in src/Core/SDKObject.class.ts:19

## Methods

### emit

- emit(event: string, ...args: any[]): void

  #### Parameters

  - event: string
  - ...args: any[]

  #### Returns void

  Inherited from SDKObject.emit

  - Defined in src/Core/SDKObject.class.ts:45

### `Protected` init

- init(): Promise<void>

  #### Returns Promise<void>

  Overrides SDKObject.init

  - Defined in src/LLM/Chat.class.ts:254

### `Protected` initSignal

- initSignal(): Promise<void>

  #### Returns Promise<void>

  Inherited from SDKObject.initSignal

  - Defined in src/Core/SDKObject.class.ts:37

### off

- off(event: string, listener: (...args: any[]) => void): void

  #### Parameters

  - event: string
  - listener: (...args: any[]) => void

  #### Returns void

  Inherited from SDKObject.off

  - Defined in src/Core/SDKObject.class.ts:49

### on

- on(event: string, listener: (...args: any[]) => void): void

  #### Parameters

  - event: string
  - listener: (...args: any[]) => void

  #### Returns void

  Inherited from SDKObject.on

  - Defined in src/Core/SDKObject.class.ts:41

### once

- once(event: string, listener: (...args: any[]) => void): void

  #### Parameters

  - event: string
  - listener: (...args: any[]) => void

  #### Returns void

  Inherited from SDKObject.once

  - Defined in src/Core/SDKObject.class.ts:53

### prompt

- prompt(prompt: string, options?: PromptOptions): ChatCommand

  Send a prompt to the chat and get a response.

  The returned command can be executed in multiple ways:

  - Promise mode: `await chat.prompt("question")` - returns final result
  - Explicit execution: `await chat.prompt("question").run()` - same as above
  - Streaming mode: `await chat.prompt("question").stream()` - returns event emitter

  #### Parameters

  - prompt: string

    The message or question to send to the chat

  - `Optional` options: PromptOptions

  #### Returns ChatCommand

  ChatCommand that can be executed or streamed

  #### Example

      const chat = agent.chat('my_chat_id');

      // Simple prompt (promise mode)
      const answer = await chat.prompt("What is the capital of France?");

      // Streaming for long responses
      const stream = await chat.prompt("Write a detailed report").stream();
      stream.on('data', chunk => console.log(chunk));
      stream.on('end', () => console.log('Complete!'));

  - Defined in src/LLM/Chat.class.ts:285

### removeListener

- removeListener(event: string, listener: (...args: any[]) => void): void

  #### Parameters

  - event: string
  - listener: (...args: any[]) => void

  #### Returns void

  Inherited from SDKObject.removeListener

  - Defined in src/Core/SDKObject.class.ts:56