Core API
ChatEngine implements IChatEngine and adds streaming helper methods.
Engine Construction
new ChatEngine(config?: ChatEngineConfig);export interface ChatEngineConfig {
readonly transport?: ITransport;
readonly storage?: IStorage;
readonly plugins?: ReadonlyArray<ChatPlugin>;
readonly middleware?: ReadonlyArray<Middleware>;
readonly sender?: Participant;
}Lifecycle
connect(): Promise<void>;
disconnect(): Promise<void>;Conversations
getConversation(id: string): Promise<Conversation | undefined>;
getConversations(query?: ConversationQuery): Promise<CursorPage<Conversation>>;
createConversation(params: CreateConversationParams): Promise<Conversation>;Messages
sendMessage(conversationId: string, content: MessageContent): Promise<Message>;
getMessages(query: MessageQuery): Promise<CursorPage<Message>>;
updateMessage(id: string, update: Partial<MessageContent>): Promise<Message>;
deleteMessage(id: string): Promise<void>;Events
on<E extends ChatEventType>(event: E, handler: ChatEventHandler<E>): Unsubscribe;
off<E extends ChatEventType>(event: E, handler: ChatEventHandler<E>): void;
on(event: `custom:${string}`, handler: (event: Record<string, unknown>) => void): Unsubscribe;
off(event: `custom:${string}`, handler: (event: Record<string, unknown>) => void): void;State
getConnectionState(): ConnectionState;
getConversationState(id: string): ConversationState;Plugins
use(plugin: ChatPlugin): void;Streaming Helpers
emitStreamStart(messageId: string, conversationId: string): void;
emitStreamChunk(messageId: string, chunk: string, accumulated: string): void;
emitStreamEnd(message: Message & { type: "ai" }): Promise<void>;
emitStreamError(messageId: string, conversationId: string, error: ChatError): void;