1 |
|
2 |
|
3 |
|
4 |
|
5 | import * as BB from 'botbuilder';
|
6 | import { CLMemory } from './CLMemory';
|
7 | import { CLClient } from './CLClient';
|
8 | import * as CLM from '@conversationlearner/models';
|
9 | import { ReadOnlyClientMemoryManager, ClientMemoryManager } from './Memory/ClientMemoryManager';
|
10 | import { CLRecognizerResult } from './CLRecognizeResult';
|
11 | export declare enum SessionStartFlags {
|
12 | NONE = 0,
|
13 | IN_TEACH = 1,
|
14 | IS_EDIT_CONTINUE = 2
|
15 | }
|
16 | export interface InternalCallback<T> extends CLM.Callback, ICallback<T> {
|
17 | }
|
18 |
|
19 |
|
20 |
|
21 | export declare type EntityDetectionCallback = (text: string, memoryManager: ClientMemoryManager) => Promise<void>;
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | export declare type OnSessionStartCallback = (context: BB.TurnContext, memoryManager: ClientMemoryManager) => Promise<void>;
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | export declare type OnSessionEndCallback = (context: BB.TurnContext, memoryManager: ClientMemoryManager, sessionEndState: CLM.SessionEndState, data: string | undefined) => Promise<string[] | void>;
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | export declare type LogicCallback<T> = (memoryManager: ClientMemoryManager, ...args: string[]) => Promise<T | void>;
|
39 | export declare const defaultLogicCallback: () => Promise<void>;
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | export declare type RenderCallback<T> = (logicResult: T, memoryManager: ReadOnlyClientMemoryManager, ...args: string[]) => Promise<Partial<BB.Activity> | string>;
|
45 | export interface ICallbackInput<T> {
|
46 | name: string;
|
47 | logic?: LogicCallback<T>;
|
48 | render?: RenderCallback<T>;
|
49 | }
|
50 | interface ICallback<T> {
|
51 | name: string;
|
52 | logic: LogicCallback<T>;
|
53 | render: RenderCallback<T> | undefined;
|
54 | }
|
55 | declare enum ActionInputType {
|
56 | LOGIC_ONLY = "LOGIC_ONLY",
|
57 | RENDER_ONLY = "RENDER_ONLY",
|
58 | LOGIC_AND_RENDER = "LOGIC_AND_RENDER"
|
59 | }
|
60 | interface IActionInputLogic {
|
61 | type: ActionInputType.RENDER_ONLY;
|
62 | logicResult: CLM.LogicResult | undefined;
|
63 | }
|
64 | interface IActionInputRenderOnly {
|
65 | type: ActionInputType;
|
66 | }
|
67 | declare type IActionInput = IActionInputRenderOnly | IActionInputLogic;
|
68 | export interface IActionResult {
|
69 | logicResult: CLM.LogicResult | undefined;
|
70 | response: Partial<BB.Activity> | string | null;
|
71 | replayError?: CLM.ReplayError;
|
72 | }
|
73 | export declare type CallbackMap = {
|
74 | [name: string]: InternalCallback<any>;
|
75 | };
|
76 | export 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 | }
|
157 | export {};
|