UNPKG

7.74 kBTypeScriptView Raw
1/**
2 * Copyright (c) Microsoft Corporation. All rights reserved.
3 * Licensed under the MIT License.
4 */
5import * as BB from 'botbuilder';
6import { CLMemory } from './CLMemory';
7import { CLClient } from './CLClient';
8import * as CLM from '@conversationlearner/models';
9import { ReadOnlyClientMemoryManager, ClientMemoryManager } from './Memory/ClientMemoryManager';
10import { CLRecognizerResult } from './CLRecognizeResult';
11export declare enum SessionStartFlags {
12 NONE = 0,
13 IN_TEACH = 1,
14 IS_EDIT_CONTINUE = 2
15}
16export interface InternalCallback<T> extends CLM.Callback, ICallback<T> {
17}
18/**
19 * Processes messages received from the user. Called by the dialog system.
20 */
21export declare type EntityDetectionCallback = (text: string, memoryManager: ClientMemoryManager) => Promise<void>;
22/**
23 * Called at session start.
24 * Allows bot to set initial entities before conversation begins
25 */
26export declare type OnSessionStartCallback = (context: BB.TurnContext, memoryManager: ClientMemoryManager) => Promise<void>;
27/**
28 * Called when Session ends.
29 * If not implemented all entity values will be cleared.
30 * If implemented, developer may return a list of entities to preserve for the next session
31 * as well as store them in the Bot State
32 */
33export declare type OnSessionEndCallback = (context: BB.TurnContext, memoryManager: ClientMemoryManager, sessionEndState: CLM.SessionEndState, data: string | undefined) => Promise<string[] | void>;
34/**
35 * Called when the associated action in your bot is sent.
36 * Common use cases are to call external APIs to gather data and save into entities for usage later.
37 */
38export declare type LogicCallback<T> = (memoryManager: ClientMemoryManager, ...args: string[]) => Promise<T | void>;
39export declare const defaultLogicCallback: () => Promise<void>;
40/**
41 * Called when the associated action in your bot is sent AND during dialog replay.
42 * Common use cases are to construct text or card messages based on current entity values.
43 */
44export declare type RenderCallback<T> = (logicResult: T, memoryManager: ReadOnlyClientMemoryManager, ...args: string[]) => Promise<Partial<BB.Activity> | string>;
45export interface ICallbackInput<T> {
46 name: string;
47 logic?: LogicCallback<T>;
48 render?: RenderCallback<T>;
49}
50interface ICallback<T> {
51 name: string;
52 logic: LogicCallback<T>;
53 render: RenderCallback<T> | undefined;
54}
55declare enum ActionInputType {
56 LOGIC_ONLY = "LOGIC_ONLY",
57 RENDER_ONLY = "RENDER_ONLY",
58 LOGIC_AND_RENDER = "LOGIC_AND_RENDER"
59}
60interface IActionInputLogic {
61 type: ActionInputType.RENDER_ONLY;
62 logicResult: CLM.LogicResult | undefined;
63}
64interface IActionInputRenderOnly {
65 type: ActionInputType;
66}
67declare type IActionInput = IActionInputRenderOnly | IActionInputLogic;
68export interface IActionResult {
69 logicResult: CLM.LogicResult | undefined;
70 response: Partial<BB.Activity> | string | null;
71 replayError?: CLM.ReplayError;
72}
73export declare type CallbackMap = {
74 [name: string]: InternalCallback<any>;
75};
76export declare class CLRunner {
77 private static Runners;
78 private static UIRunner;
79 clClient: CLClient;
80 adapter: BB.BotAdapter | undefined;
81 private checksum;
82 private configModelId;
83 private maxTimeout;
84 callbacks: CallbackMap;
85 static Create(configModelId: string | undefined, maxTimeout: number | undefined, client: CLClient): CLRunner;
86 static GetRunnerForUI(appId?: string): CLRunner;
87 private constructor();
88 botChecksum(): string;
89 convertInternalCallbackToCallback: <T>(c: InternalCallback<T>) => CLM.Callback;
90 onTurn(turnContext: BB.TurnContext, next: (result: CLRecognizerResult | null) => Promise<void>): Promise<void>;
91 recognize(turnContext: BB.TurnContext, force?: boolean): Promise<CLRecognizerResult | null>;
92 InTrainingUI(turnContext: BB.TurnContext): Promise<boolean>;
93 BotStartSession(turnContext: BB.TurnContext): Promise<void>;
94 SetAdapter(adapter: BB.BotAdapter, conversationReference: Partial<BB.ConversationReference>): void;
95 private AddInput;
96 StartSessionAsync(clMemory: CLMemory, conversationId: string | null, appId: string, sessionStartFlags: SessionStartFlags, createParams: CLM.SessionCreateParams | CLM.CreateTeachParams): Promise<CLM.Teach | CLM.Session>;
97 private GetRunningApp;
98 EndSessionAsync(memory: CLMemory, sessionEndState: CLM.SessionEndState, data?: string): Promise<void>;
99 private ProcessInput;
100 private ProcessFormData;
101 private Score;
102 entityDetectionCallback: EntityDetectionCallback | undefined;
103 onSessionStartCallback: OnSessionStartCallback | undefined;
104 onSessionEndCallback: OnSessionEndCallback | undefined;
105 AddCallback<T>(callbackInput: ICallbackInput<T>): void;
106 private GetArguments;
107 private ProcessPredictedEntities;
108 CallEntityDetectionCallback(text: string, predictedEntities: CLM.PredictedEntity[], clMemory: CLMemory, allEntities: CLM.EntityBase[], skipEntityDetectionCallBack?: boolean): Promise<CLM.ScoreInput>;
109 private CreateMemoryManagerAsync;
110 private CreateReadOnlyMemoryManagerAsync;
111 private GetTurnContext;
112 protected CheckSessionStartCallback(clMemory: CLMemory, entities: CLM.EntityBase[]): Promise<void>;
113 protected CheckSessionEndCallback(clMemory: CLMemory, entities: CLM.EntityBase[], sessionEndState: CLM.SessionEndState, data?: string): Promise<void>;
114 TakeActionAsync(conversationReference: Partial<BB.ConversationReference>, clRecognizeResult: CLRecognizerResult, clData: CLM.CLChannelData | null): Promise<IActionResult>;
115 SendIntent(intent: CLRecognizerResult, clData?: CLM.CLChannelData | null): Promise<IActionResult | undefined>;
116 private SendMessage;
117 private GetRenderedArguments;
118 TakeAPIAction(apiAction: CLM.ApiAction, filledEntityMap: CLM.FilledEntityMap, clMemory: CLMemory, allEntities: CLM.EntityBase[], inTeach: boolean, actionInput: IActionInput): Promise<IActionResult>;
119 TakeTextAction(textAction: CLM.TextAction, filledEntityMap: CLM.FilledEntityMap): Promise<Partial<BB.Activity> | string>;
120 TakeCardAction(cardAction: CLM.CardAction, filledEntityMap: CLM.FilledEntityMap): Promise<Partial<BB.Activity> | string>;
121 private TakeSessionAction;
122 isActionAvailable(action: CLM.ActionBase, filledEntities: CLM.FilledEntity[]): boolean;
123 private CreateFilledEntityMap;
124 /**
125 * Identify any validation issues
126 * Missing Entities
127 * Missing Actions
128 * Unavailable Actions
129 */
130 DialogValidationErrors(trainDialog: CLM.TrainDialog, entities: CLM.EntityBase[], actions: CLM.ActionBase[]): string[];
131 /** Return a list of trainDialogs that are invalid for the given set of entities and actions */
132 validateTrainDialogs(appDefinition: CLM.AppDefinition): string[];
133 /** Populate prebuilt information in predicted entities given filled entity array */
134 private PopulatePrebuilts;
135 /**
136 * Provide empty FilledEntity for any missing entities so they can still be rendered
137 */
138 private PopulateMissingFilledEntities;
139 /**
140 * Initialize memory for replay
141 */
142 private InitReplayMemory;
143 /**
144 * Replay a TrainDialog, calling EntityDetection callback and API Logic,
145 * recalculating FilledEntities along the way
146 */
147 ReplayTrainDialogLogic(trainDialog: CLM.TrainDialog, clMemory: CLMemory, cleanse: boolean): Promise<CLM.TrainDialog>;
148 /**
149 * Get Activities generated by trainDialog.
150 * Return any errors in TrainDialog
151 * NOTE: Will set bot memory to state at end of history
152 */
153 GetHistory(trainDialog: CLM.TrainDialog, userName: string, userId: string, clMemory: CLMemory): Promise<CLM.TeachWithHistory | null>;
154 private RenderAPICard;
155 private RenderErrorCard;
156}
157export {};