import { HandlerInput } from 'ask-sdk-core'; import { Resource } from 'i18next'; import { Control } from '../controls/Control'; import { ControlInteractionModelGenerator } from '../interactionModelGeneration/ControlInteractionModelGenerator'; import { ControlResponseBuilder } from '../responseGeneration/ControlResponseBuilder'; import { SystemAct } from '../systemActs/SystemAct'; import { ControlInput } from './ControlInput'; import { ControlResult } from './ControlResult'; import { ControlServicesProps } from './ControlServices'; import { IControl } from './interfaces/IControl'; import { IControlManager } from './interfaces/IControlManager'; import { ILogger } from './interfaces/ILogger'; import { InputModality, ResponseStyle, InputModalityEvaluator, ResponseStyleEvaluator } from '../modality/ModalityEvaluation'; /** * Properties for creating a ControlManager instance. */ export interface ControlManagerProps { /** * The locale to use when looking up i18n strings. */ locale?: string; /** * Overrides to built-in localized content and/or content for additional locales. * * Default: The defaults are defined in `src/commonControls/LanguageStrings.ts` and * provides en-US strings for all the builtin controls. * * Usage: * - to override a default string in en-US for all instances of a built-in control, * add the override here using the same structure as shown in `LanguageStrings.ts` * - to add content for a new locale, add a new block of content like 'en-US' and * configure all strings for each builtin control type that you require. Also configure * `ControlManagerProps.locale` to refer to the new locale. * * TODO: finish localizing all strings, */ i18nResources?: Resource; /** * The services props used to set global configuration * to be used across all Controls. */ services?: ControlServicesProps; /** * Overrides the built-in function for determining how a user responded to a * request. * * Default: The default is defined in `src/modlity/ModalityEvaluation.ts` */ inputModalityEvaluator?: InputModalityEvaluator; /** * Overrides the built-in function for determining how the next turn should be * presented to a user. * * Default: The default is defined in `src/modlity/ModalityEvaluation.ts` */ responseStyleEvaluator?: ResponseStyleEvaluator; } /** * Defines the high-level functionality for a skill built with Controls. * * Each skill that uses controls should define a concrete sub-class that * implements `createControlTree` and optionally overrides other methods. * * Summary: * * createControlTree() creates a hierarchy of controls that cooperatively * manage the skill behavior. * * The methods on the root control will be called to process the user's * input and to generate system initiative. * * * render() is the entry-point for the render-phase. * * High-level overrides and multi-act rendering should be performed by * `controlManager.render()`. The default is to render each act one-by-one * by calling `control.renderAct(act)`. This builds up a result by * concatenation of response fragments which is sufficient in many cases. * * * The `ControlResult` contains a list of SystemActs that describe *what* * should be communicated to the user but generally should not describe *how* * to present it. * * * `handleInternalError` provides an entry-point for custom handling of * internal errors. * * * `buildInteractionModel` provides an entry-point for building the * Control-specific aspects of skill's Interaction Model. * * Internationalization and Localization * * Controls themselves are location-agnostic. They consume abstract inputs * (Intents, etc) and produce abstract outputs (SystemActs) * * * Mapping localized input to abstract inputs is the role of NLU and the * necessary information is stored in the Interaction Model. * * The ControlManager props includes a bag of localization data that is used * during interaction-model building for a given locale. * * The framework ships with a default set of interaction model data for * en-US. * * * Mapping abstract output to physical output (prompts, APL strings) etc is * the role of the rendering phase. This information is part of the skill * definition but can be located in various places: either in a monolithic * render() function, or scattered around the various Controls and Acts. */ export declare abstract class ControlManager implements IControlManager { /** * Default key name used to store control state data between turns. */ static DEFAULT_CONTROL_STATE_ATTRIBUTE_KEY: string; /** * The custom props provided during construction */ rawProps?: ControlManagerProps; /** * The complete props used during construction. */ props: Readonly>; /** * The logger implementation. */ log: ILogger; /** * Configured function for determining how a user responded to a * request. */ inputModalityEvaluator: InputModalityEvaluator; /** * Configured function for determining how the next turn should be * presented to a user. */ responseStyleEvaluator: ResponseStyleEvaluator; /** * Creates an instance of a Control Manager. * @param props - props */ constructor(props?: ControlManagerProps); /** * Merges the user-provided props with the default props. * * Any property defined by the user-provided data overrides the defaults. */ static mergeWithDefaultProps(props: ControlManagerProps | undefined): Required; /** * Creates a tree of controls to handle state management and dialog * decisions for the skill. * * Usage: * - Each control in the tree can and should be created with empty state. * * - In advanced scenarios the tree shape may change as the skill session * progresses. Dynamic controls should be rebuilt during * `ControlManager.reestablishControlStates()`. * * @returns A `Control`, typically a `ContainerControl`, that is the root of a tree. */ abstract createControlTree(): Control; /** * Reestablish the state of all controls. * * Purpose: * - On the second and subsequent turns this method reestablishes the state * of controls from saved/serialized information. * - This method should also reestablish any dynamic controls (controls that * are added at runtime, rather than being statically created by `createControlTree`) * * Notes: * - To keep serialized state to a minimum, and due to the lack of * object-aware serialization in Javascript, re-creation of the complete * control tree occurs in two phases: * 1. Build the static control tree as in the very first turn. * 2. Reattach state and rebuild the dynamic portions of the control tree. * - This approach keeps the props and state of controls separate and keeps * the common cases as simple as possible. */ reestablishControlStates(rootControl: IControl, stateMap: { [key: string]: any; }): void; /** * Transforms the information in ControlResult into user-facing content * (prompts and APL). * * Default: The default rendering strategy renders each `SystemAct` in turn * by calling `act.control.render(act)`. This strategy leads to * prompts that are a concatenation of the prompt-fragment for each * `SystemAct`. * * Usage: * * In many situations rendering the acts one-by-one is sufficient as the * concatenation of prompt fragments leads to usable prompts. For * example * * ```js * [ValueSetAct(ageCtrl, 5), RequestValueAct(nameCtrl)] * ``` * may be rendered sequentially to produce: * * ```js * -> 'OK, 5. What is your name?" * ``` * * * For more complex situations, override this method and implement a * custom rendering strategy. Often the solution will be to implement * some special cases and otherwise fallback to the default by calling * super.render() or by directly calling * `ControlManager.renderActsOneByOne()`. * */ render(result: ControlResult, input: ControlInput, controlResponseBuilder: ControlResponseBuilder): Promise; /** * Handles an internal error. * * This is intended for logging, reporting and perhaps mentioning the * situation to the user. The user session will be automatically closed. * * Default: The error object is converted into an object with enumerable * properties and logged at logLevel=error * @param input - Input * @param error - Error * @param responseBuilder - Response builder */ handleInternalError(input: ControlInput | undefined, error: any, responseBuilder: ControlResponseBuilder): void; /** * Builds interaction model content required by the Control tree. * * Usage: * - The imDataMap has 'en-US' modelData registered by default * - The developer may configure and register additional `imDataMap` * instances to support additional locales * * * If imDataMap doesn't have data for the requested locale a * `LocaleNotSupportedError` will be thrown * * @param generator - Interaction Model Generator */ buildInteractionModel(generator: ControlInteractionModelGenerator): void; /** * Load the control state map from durable storage. * * Default: loads from Session Attributes. */ loadControlStateMap(handlerInput: HandlerInput): Promise<{ [key: string]: any; }>; /** * Saves the control state map for use in subsequent turns of this session. * * Default: saves to the Session Attributes. */ saveControlStateMap(state: any, handlerInput: HandlerInput): Promise; /** * Retrieves a specific attribute in the state map of this session. * @param attributeKey - Attribute to retrieve * @param handlerInput - Input for the current turn * @returns The value of the attribute, or undefined if not present. */ static getStateAttribute(attributeKey: string, handlerInput: HandlerInput): any; /** * Modifies a specific attribute in the state map of this session. * @param attributeKey - Attribute to modify * @param value - New value for the attribute being modified * @param handlerInput - Input for the current turn */ static setStateAttribute(attributeKey: string, value: any, handlerInput: HandlerInput): void; static saveControlStateToSessionAttributes(state: any, handlerInput: HandlerInput, attributeKey: string): void; static loadControlStateMapFromSessionAttributes(handlerInput: HandlerInput, attributeKey: string): { [key: string]: any; }; evaluateInputModality(handlerInput: HandlerInput): InputModality; evaluateResponseStyle(handlerInput: HandlerInput, history: InputModality[]): ResponseStyle; } /** * Render each of the acts, one-by-one. * * * @param systemActs - The system acts to render * @param input - Input * @param responseBuilder - Response builder. */ export declare function renderActsInSequence(systemActs: SystemAct[], input: ControlInput, controlResponseBuilder: ControlResponseBuilder): Promise; /** * Initializes the internationalization system (i18next). * * This loads data for the specified local from the resources. * * @param locale - The locale to specialize to. * @param resources - Resources for all supported locales. */ export declare function i18nInit(locale: string, resources: Resource): void; /** * Format the Control state map for logging. * * @param state - Control state map */ export declare function formatStateObjectForLogging(state: { [key: string]: any; }): string; /** * Format the context information for logging. * * @param context - Session context information in addition to that provided by Alexa Service. */ export declare function formatContextObjectForLogging(context: { [key: string]: any; }): string; //# sourceMappingURL=ControlManager.d.ts.map