/** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ import * as BB from 'botbuilder'; import { CLMemory } from './CLMemory'; import { CLClient } from './CLClient'; import * as CLM from '@conversationlearner/models'; import { ReadOnlyClientMemoryManager, ClientMemoryManager } from './Memory/ClientMemoryManager'; import { CLRecognizerResult } from './CLRecognizeResult'; export declare enum SessionStartFlags { NONE = 0, IN_TEACH = 1, IS_EDIT_CONTINUE = 2 } export interface InternalCallback extends CLM.Callback, ICallback { } /** * Processes messages received from the user. Called by the dialog system. */ export declare type EntityDetectionCallback = (text: string, memoryManager: ClientMemoryManager) => Promise; /** * Called at session start. * Allows bot to set initial entities before conversation begins */ export declare type OnSessionStartCallback = (context: BB.TurnContext, memoryManager: ClientMemoryManager) => Promise; /** * Called when Session ends. * If not implemented all entity values will be cleared. * If implemented, developer may return a list of entities to preserve for the next session * as well as store them in the Bot State */ export declare type OnSessionEndCallback = (context: BB.TurnContext, memoryManager: ClientMemoryManager, sessionEndState: CLM.SessionEndState, data: string | undefined) => Promise; /** * Called when the associated action in your bot is sent. * Common use cases are to call external APIs to gather data and save into entities for usage later. */ export declare type LogicCallback = (memoryManager: ClientMemoryManager, ...args: string[]) => Promise; export declare const defaultLogicCallback: () => Promise; /** * Called when the associated action in your bot is sent AND during dialog replay. * Common use cases are to construct text or card messages based on current entity values. */ export declare type RenderCallback = (logicResult: T, memoryManager: ReadOnlyClientMemoryManager, ...args: string[]) => Promise | string>; export interface ICallbackInput { name: string; logic?: LogicCallback; render?: RenderCallback; } interface ICallback { name: string; logic: LogicCallback; render: RenderCallback | undefined; } declare enum ActionInputType { LOGIC_ONLY = "LOGIC_ONLY", RENDER_ONLY = "RENDER_ONLY", LOGIC_AND_RENDER = "LOGIC_AND_RENDER" } interface IActionInputLogic { type: ActionInputType.RENDER_ONLY; logicResult: CLM.LogicResult | undefined; } interface IActionInputRenderOnly { type: ActionInputType; } declare type IActionInput = IActionInputRenderOnly | IActionInputLogic; export interface IActionResult { logicResult: CLM.LogicResult | undefined; response: Partial | string | null; replayError?: CLM.ReplayError; } export declare type CallbackMap = { [name: string]: InternalCallback; }; export declare class CLRunner { private static Runners; private static UIRunner; clClient: CLClient; adapter: BB.BotAdapter | undefined; private checksum; private configModelId; private maxTimeout; callbacks: CallbackMap; static Create(configModelId: string | undefined, maxTimeout: number | undefined, client: CLClient): CLRunner; static GetRunnerForUI(appId?: string): CLRunner; private constructor(); botChecksum(): string; convertInternalCallbackToCallback: (c: InternalCallback) => CLM.Callback; onTurn(turnContext: BB.TurnContext, next: (result: CLRecognizerResult | null) => Promise): Promise; recognize(turnContext: BB.TurnContext, force?: boolean): Promise; InTrainingUI(turnContext: BB.TurnContext): Promise; BotStartSession(turnContext: BB.TurnContext): Promise; SetAdapter(adapter: BB.BotAdapter, conversationReference: Partial): void; private AddInput; StartSessionAsync(clMemory: CLMemory, conversationId: string | null, appId: string, sessionStartFlags: SessionStartFlags, createParams: CLM.SessionCreateParams | CLM.CreateTeachParams): Promise; private GetRunningApp; EndSessionAsync(memory: CLMemory, sessionEndState: CLM.SessionEndState, data?: string): Promise; private ProcessInput; private ProcessFormData; private Score; entityDetectionCallback: EntityDetectionCallback | undefined; onSessionStartCallback: OnSessionStartCallback | undefined; onSessionEndCallback: OnSessionEndCallback | undefined; AddCallback(callbackInput: ICallbackInput): void; private GetArguments; private ProcessPredictedEntities; CallEntityDetectionCallback(text: string, predictedEntities: CLM.PredictedEntity[], clMemory: CLMemory, allEntities: CLM.EntityBase[], skipEntityDetectionCallBack?: boolean): Promise; private CreateMemoryManagerAsync; private CreateReadOnlyMemoryManagerAsync; private GetTurnContext; protected CheckSessionStartCallback(clMemory: CLMemory, entities: CLM.EntityBase[]): Promise; protected CheckSessionEndCallback(clMemory: CLMemory, entities: CLM.EntityBase[], sessionEndState: CLM.SessionEndState, data?: string): Promise; TakeActionAsync(conversationReference: Partial, clRecognizeResult: CLRecognizerResult, clData: CLM.CLChannelData | null): Promise; SendIntent(intent: CLRecognizerResult, clData?: CLM.CLChannelData | null): Promise; private SendMessage; private GetRenderedArguments; TakeAPIAction(apiAction: CLM.ApiAction, filledEntityMap: CLM.FilledEntityMap, clMemory: CLMemory, allEntities: CLM.EntityBase[], inTeach: boolean, actionInput: IActionInput): Promise; TakeTextAction(textAction: CLM.TextAction, filledEntityMap: CLM.FilledEntityMap): Promise | string>; TakeCardAction(cardAction: CLM.CardAction, filledEntityMap: CLM.FilledEntityMap): Promise | string>; private TakeSessionAction; isActionAvailable(action: CLM.ActionBase, filledEntities: CLM.FilledEntity[]): boolean; private CreateFilledEntityMap; /** * Identify any validation issues * Missing Entities * Missing Actions * Unavailable Actions */ DialogValidationErrors(trainDialog: CLM.TrainDialog, entities: CLM.EntityBase[], actions: CLM.ActionBase[]): string[]; /** Return a list of trainDialogs that are invalid for the given set of entities and actions */ validateTrainDialogs(appDefinition: CLM.AppDefinition): string[]; /** Populate prebuilt information in predicted entities given filled entity array */ private PopulatePrebuilts; /** * Provide empty FilledEntity for any missing entities so they can still be rendered */ private PopulateMissingFilledEntities; /** * Initialize memory for replay */ private InitReplayMemory; /** * Replay a TrainDialog, calling EntityDetection callback and API Logic, * recalculating FilledEntities along the way */ ReplayTrainDialogLogic(trainDialog: CLM.TrainDialog, clMemory: CLMemory, cleanse: boolean): Promise; /** * Get Activities generated by trainDialog. * Return any errors in TrainDialog * NOTE: Will set bot memory to state at end of history */ GetHistory(trainDialog: CLM.TrainDialog, userName: string, userId: string, clMemory: CLMemory): Promise; private RenderAPICard; private RenderErrorCard; } export {};