UNPKG

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