@smythos/sdk
Version:
84 lines (83 loc) • 3.16 kB
TypeScript
import { Conversation, AccessCandidate } from '@smythos/sre';
import { EventEmitter } from 'events';
import { AgentData, ChatOptions, PromptOptions } from '../types/SDKTypes';
import { SDKObject } from '../Core/SDKObject.class';
import type { Agent } from '../Agent/Agent.class';
declare class ChatCommand {
private prompt;
private chat;
private options?;
private _conversation;
constructor(prompt: string, chat: Chat, options?: PromptOptions);
then(resolve: (value: string) => void, reject?: (reason: any) => void): Promise<void>;
private run;
/**
* Execute the chat command as a streaming response.
*
* **Available Events:**
* - `'data'` - Text chunk received from the agent
* - `'end'` - The agent has finished responding
* - `'error'` - The agent encountered an error
*
* @returns Promise that resolves to an EventEmitter for streaming updates
*
* @example
* ```typescript
* const chat = agent.chat('my_chat_id');
*
* const stream = await chat.prompt("Tell me a long story").stream();
* stream.on('data', (chunk) => process.stdout.write(chunk));
* stream.on('end', () => console.log('\nStory completed!'));
* stream.on('error', (err) => console.error('Error:', err));
* ```
*/
stream(): Promise<EventEmitter>;
}
export declare class Chat extends SDKObject {
private source?;
private _convOptions;
private _id;
_conversation: Conversation;
/**
* The SRE Conversation Manager instance that is used to handle the current chat conversation.
*/
get conversation(): Conversation;
private _curAgentModes;
get id(): string;
private _emptyData;
private _data;
get agentData(): any;
constructor(options: ChatOptions & {
candidate: AccessCandidate;
}, source?: Agent | Record<string, any>, _convOptions?: any);
private isValidPersistanceObject;
protected init(): Promise<void>;
/**
* 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
*
* @example
* ```typescript
* 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!'));
* ```
*
* @param prompt - The message or question to send to the chat
* @returns ChatCommand that can be executed or streamed
*/
prompt(prompt: string, options?: PromptOptions): ChatCommand;
}
export declare function prepareConversation(agentData: AgentData, options?: any): Promise<Conversation>;
export {};