///
import * as events from 'events';
import ValueCategory from './value-category';
import { PlatformData, Message, RDL } from './protocol';
import { EntityMap } from '../utils/entity-utils';
import type Engine from '../engine';
import { DialogueSerializer, DialogueTurn } from "../dataset-tools/parsers";
import AppExecutor from '../engine/apps/app_executor';
export interface ConversationOptions {
nluServerUrl?: string;
nlgServerUrl?: string;
anonymous?: boolean;
debug?: boolean;
rng?: () => number;
contextResetTimeout?: number;
showWelcome?: boolean;
log?: boolean;
dialogueFlags?: Record;
useConfidence?: boolean;
faqModels?: Record;
}
interface Statistics {
hit(key: string): void;
}
export interface ConversationDelegate {
setHypothesis(hyp: string): Promise;
setExpected(expect: string | null, ctx: {
code: string[];
entities: EntityMap;
}): Promise;
addMessage(msg: Message): Promise;
destroy(): void;
}
export interface ConversationState {
dialogueState: Record;
lastMessageId: number;
recording: boolean;
}
/**
* A single session of conversation in Genie.
*
* This object is responsible for maintaining the history of the conversation
* to support clients reconnecting to the same conversation later, as well
* as tracking connected clients and inactivity timeouts.
*/
export default class Conversation extends events.EventEmitter {
private _engine;
private _conversationId;
private _locale;
_: (x: string) => string;
private _stats;
private _options;
private _debug;
private _dialogueFlags;
rng: () => number;
private _loop;
private _expecting;
private _context;
private _started;
private _delegates;
private _history;
private _lastMessageId;
private _contextResetTimeout;
private _contextResetTimeoutSec;
private _recording;
private _log;
private readonly _conversationStateDB;
constructor(engine: Engine, conversationId: string, options?: ConversationOptions);
get isAnonymous(): boolean;
get id(): string;
get engine(): Engine;
get stats(): Statistics;
get inRecordingMode(): boolean;
get dialogueFlags(): Record;
startRecording(): Promise;
endRecording(): Promise;
notify(app: AppExecutor, outputType: string, outputValue: Record): void;
notifyError(app: AppExecutor, error: Error): void;
setExpected(expecting: ValueCategory | null, context: {
code: string[];
entities: EntityMap;
}): void;
start(state?: ConversationState): Promise;
stop(): Promise;
private _resetInactivityTimeout;
addOutput(out: ConversationDelegate, replayHistory?: boolean): Promise;
removeOutput(out: ConversationDelegate): void;
private _callDelegate;
private _callDelegates;
setHypothesis(hypothesis: string): Promise;
sendAskSpecial(): Promise;
/**
* Add a message to the conversation history.
*
* This method is exported to inject conversation history from outside.
*/
addMessage(msg: Message): Promise;
private _saveState;
/**
* Extract the state from the conversation.
*
* This method is provided to save and restore the conversation state,
* and transfer the conversation state between engines.
*/
getState(): ConversationState;
handleCommand(command: string, platformData?: PlatformData): Promise;
handleParsedCommand(root: any, title?: string, platformData?: PlatformData): Promise;
handleThingTalk(program: string, platformData?: PlatformData): Promise;
sendReply(message: string, icon: string | null): Promise;
sendMedia(mediaType: 'picture' | 'audio' | 'video', url: string, alt: string | undefined, icon: string | null): Promise;
sendRDL(rdl: RDL, icon: string | null): Promise;
sendSoundEffect(name: string, exclusive: boolean | undefined, icon: string | null): Promise;
sendChoice(idx: number, title: string): Promise;
sendButton(title: string, json: string): Promise;
sendLink(title: string, url: string, state: ConversationState): Promise;
sendNewProgram(program: {
uniqueId: string;
name: string;
code: string;
results: Array>;
errors: string[];
icon: string | null;
}): Promise;
dialogueFinished(): Promise;
turnFinished(): Promise;
voteLast(vote: 'up' | 'down'): Promise;
commentLast(comment: string): Promise;
updateLog(field: Exclude, value: string): void;
readLog(): DialogueSerializer;
}
export {};