import { Intent } from 'ask-sdk-model'; import { ModelData, StringOrList } from '../..'; import { Control, ControlInitiativeHandler, ControlInputHandler, ControlInputHandlingProps, ControlProps, ControlState } from '../../controls/Control'; import { ControlInput } from '../../controls/ControlInput'; import { ControlResultBuilder } from '../../controls/ControlResult'; import { ControlServicesProps } from '../../controls/ControlServices'; import { InteractionModelContributor } from '../../controls/mixins/InteractionModelContributor'; import { ControlInteractionModelGenerator } from '../../interactionModelGeneration/ControlInteractionModelGenerator'; import { ResponseStyleEvaluator } from '../../modality/ModalityEvaluation'; import { ControlResponseBuilder } from '../../responseGeneration/ControlResponseBuilder'; import { InvalidRemoveValueAct, InvalidValueAct, ValueAddedAct, ValueClearedAct, ValueConfirmedAct, ValueRemovedAct } from '../../systemActs/ContentActs'; import { ConfirmValueAct, RequestRemovedValueByListAct, RequestValueByListAct, SuggestActionAct } from '../../systemActs/InitiativeActs'; import { SystemAct } from '../../systemActs/SystemAct'; import { DeepRequired } from '../../utils/DeepRequired'; export declare type MultiValueValidationFailure = { /** * A code representing what validation failed. */ reasonCode?: string; /** * A rendered prompt fragment that can be directly included in the `Response`. */ renderedReason: string; /** * A list of values which fails validation. */ invalidValues: string[]; }; /** * Props for a ListControl. */ export interface MultiValueListControlProps extends ControlProps { /** * Unique identifier for control instance */ id: string; /** * Slot type for the value that this control collects. * * Usage: * - The slot type defines the set of expected value items. * - NLU will, on occasion, accept novel slot value and mark them as * ER_NO_MATCH. If you only want to accept values that are explicitly * defined add a validation function to test `this.state.erMatch` */ slotType: string; /** * Function(s) that determine if the value is valid. * * Default: `true`, i.e. any value is valid. * * Usage: * - Validation functions return either `true` or a `ValidationResult` to * describe what validation failed. */ validation?: SlotValidationFunction | SlotValidationFunction[]; /** * List of slot-value IDs that will be presented to the user as a list. */ listItemIDs: string[] | ((input: ControlInput) => string[]); /** * The maximum number of items spoken per turn. */ pageSize?: number; /** * Determines if the Control must obtain a value. * * - If `true` the Control will take initiative to elicit a value. * - If `false` the Control will not take initiative to elicit a value, but the user * can provide one if they wish, e.g. "U: My favorite color is blue". */ required?: boolean | ((input: ControlInput) => boolean); /** * Whether the Control has to obtain explicit confirmation of the value. * * If `true`: * - the Control will take initiative to explicitly confirm the value with a yes/no * question. */ confirmationRequired?: boolean | ((input: ControlInput) => boolean); /** * Props to customize the prompt fragments that will be added by * `this.renderAct()`. */ prompts?: MultiValueListControlPromptProps; /** * Props to customize the reprompt fragments that will be added by * `this.renderAct()`. */ reprompts?: MultiValueListControlPromptProps; /** * Props to customize the relationship between the control and the * interaction model. */ interactionModel?: MultiValueListControlInteractionModelProps; /** * Props to configure input handling. */ inputHandling?: ControlInputHandlingProps; /** * Function that maps the MultiValueListControlState.value to rendered value that * will be presented to the user as a list. * * Default: returns the value unchanged. */ valueRenderer?: (value: string[], input: ControlInput) => string[]; /** * Props to customize the APL generated by this control. */ apl?: MultiValueListControlAPLProps; /** * Props to customize services used by the control. */ services?: ControlServicesProps; /** * Function that determines the preferred response style based on input * and input modality history. * * Default: Function always returns indeterminate response style, which * causes the decision to be deferred to the function configured in ControlManager. */ responseStyleEvaluator?: ResponseStyleEvaluator; } /** * ListControl validation function */ export declare type SlotValidationFunction = (values: MultiValueListStateValue[], input: ControlInput) => true | MultiValueValidationFailure | Promise; export declare type AplContent = { document: { [key: string]: any; }; dataSource: { [key: string]: any; }; }; export declare type AplContentFunc = (control: MultiValueListControl, input: ControlInput) => AplContent; export declare type AplDocumentPropNewStyle = AplContent | AplContentFunc; export declare type AplRenderComponentFunc = (control: MultiValueListControl, props: MultiValueListAPLComponentProps, input: ControlInput, resultBuilder: ControlResponseBuilder) => { [key: string]: any; }; /** * Mapping of action slot values to the capability that this control supports. * * Behavior: * - This control will not handle an input if the action-slot is filled with an * value whose ID is not associated with a capability. */ export interface MultiValueListControlActionProps { /** * Action slot value IDs that are associated with the "add value/s" capability. * * Default ['builtin_add', 'builtin_select'] */ add?: string[]; /** * Action slot value IDs that are associated with the "remove value" capability. * * Default ['builtin_remove', 'builtin_delete', 'builtin_ignore'] */ remove?: string[]; /** * Action slot value IDs that are associated with the "clear/empty value/s" capability. */ clear?: string[]; } /** * Props associated with the interaction model. */ export declare class MultiValueListControlInteractionModelProps { /** * Target-slot values associated with this Control. * * Targets associate utterances to a control. For example, if the user says * "change the time", it is parsed as a `GeneralControlIntent` with slot * values `action = change` and `target = time`. Only controls that are * registered with the `time` target should offer to handle this intent. * * Default: `['builtin_it']` * * Usage: * - If this prop is defined, it replaces the default; it is not additive * the defaults. To add an additional target to the defaults, copy the * defaults and amend. * - A control can be associated with many target-slot-values, eg ['date', * 'startDate', 'eventStartDate', 'vacationStart'] * - It is a good idea to associate with general targets (e.g. date) and * also with specific targets (e.g. vacationStart) so that the user can * say either general or specific things. e.g. 'change the date to * Tuesday', or 'I want my vacation to start on Tuesday'. * - The association does not have to be exclusive, and general target slot * values will often be associated with many controls. In situations where * there is ambiguity about what the user is referring to, the parent * controls must resolve the confusion. * - The 'builtin_*' IDs are associated with default interaction model data * (which can be extended as desired). Any other IDs will require a full * definition of the allowed synonyms in the interaction model. * * Control behavior: * - A control will not handle an input that mentions a target that is not * registered by this prop. * */ targets?: string[]; /** * Action slot-values associated to the control's capabilities. * * Default: * ``` * { * set: ['builtin_set', 'builtin_select'], * change: ['builtin_set'] * } * ``` * * Action slot-values associate utterances to a control. For example, if the * user says "change the time", it is parsed as a `GeneralControlIntent` * with slot values `action = change` and `target = time`. Only controls * that are registered with the `change` action should offer to handle this * intent. * * Usage: * - This allows users to refer to an action using more domain-appropriate * words. For example, a user might like to say 'show two items' rather * that 'set item count to two'. To achieve this, include the * slot-value-id 'show' in the list associated with the 'set' capability * and ensure the interaction-model includes an action slot value with * id=show and appropriate synonyms. * - The 'builtin_*' IDs are associated with default interaction model data * (which can be extended as desired). Any other IDs will require a full * definition of the allowed synonyms in the interaction model. */ actions?: MultiValueListControlActionProps; /*** * Additional properties to resolve utterance conflicts caused by the * configured slot type. * * Purpose: * - use these props in situations where the configured slotType has * values/synonyms that cause utterance conflicts. Most commonly, this * arises when the list control is managing a slotType with values such * as 'yes' and 'no' that conflict with Amazon.YesIntent & Amazon.NoIntent. */ slotValueConflictExtensions?: { /** * Slot type that is a copy of the main slot type, with problematic values * removed. * * Purpose: * - During interaction-model-generation, the `filteredSlotType` is used * in sample-utterances that would cause conflicts if the regular * slotType was used. * * Example: * - if the list is managing a SlotType `ExtendedBoolean` with values * `yes | no | maybe`, create and register a filtered SlotType * `ExtendedBooleanFiltered` that has only the `maybe` value. * - during interaction model generation, the risky utterance shapes * will used `ExtendedBooleanFiltered` whereas non-risky utterance shapes * will use `ExtendedBoolean`. */ filteredSlotType: string; /** * Function that maps an intent to a valueId for props.slotValue. * * Purpose: * * Some simple utterances intended for this control will be * interpreted as intents that are unknown to this control. This * function allows mapping of them. * * Example: * * if the list is managing a SlotType `ExtendedBoolean` with values * `yes | no | maybe` and filteredSlotType has been configured * correctly then a user-utterance of 'U: yes' will be interpreted as * an `AMAZON.YesIntent`. To ensure that intent is correctly * processed, declare an intentToValueMapper that maps * `AMAZON.YesIntent -> 'yes'`. The built-in logic of the ListControl * will thus treat AMAZON.YesIntent as the value 'yes', assuming that the * control is not actively asking a yes/no question. */ intentToValueMapper: (intent: Intent) => string | undefined; }; } /** * Props to customize the prompt fragments that will be added by * `this.renderAct()`. */ export declare class MultiValueListControlPromptProps { invalidValue?: StringOrList | ((act: InvalidValueAct, input: ControlInput) => StringOrList); invalidRemoveValue?: StringOrList | ((act: InvalidRemoveValueAct, input: ControlInput) => StringOrList); requestValue?: StringOrList | ((act: RequestValueByListAct, input: ControlInput) => StringOrList); requestRemovedValue?: StringOrList | ((act: RequestRemovedValueByListAct, input: ControlInput) => StringOrList); confirmValue?: StringOrList | ((act: ConfirmValueAct, input: ControlInput) => StringOrList); valueConfirmed?: StringOrList | ((act: ValueConfirmedAct, input: ControlInput) => StringOrList); valueAdded?: StringOrList | ((act: ValueAddedAct, input: ControlInput) => StringOrList); valueRemoved?: StringOrList | ((act: ValueRemovedAct, input: ControlInput) => StringOrList); valueCleared?: StringOrList | ((act: ValueClearedAct, input: ControlInput) => StringOrList); suggestAction?: StringOrList | ((act: SuggestActionAct, input: ControlInput) => StringOrList); } /** * Props associated with the APL produced by ListControl. */ export declare class MultiValueListControlAPLProps { /** * Determines if APL should be produced. * * Default: true */ enabled?: boolean | ((input: ControlInput) => boolean); /** * Custom APL to request value from list of choices. */ requestValue?: AplDocumentPropNewStyle; /** * Determines the APL Component rendering mode. * * Usage: * * 1) Use pre-defined built-ins under MultiValueListControlComponentAPLBuiltIns.* namespace which provides both default * implementations and customization of props(MultiValueListAPLComponentProps) to render an APL component. * * e.g renderComponent: MultiValueListControlComponentAPLBuiltIns.DualTextListRender.default --- Default Implementation * renderComponent: MultiValueListControlComponentAPLBuiltIns.DualTextListRender.default.of(props: MultiValueListAPLComponentProps) --- Override few properties * * 2) Provide a custom function which returns an APL component. * * * Default: MultiValueListControlComponentAPLBuiltIns.DualTextListRender.default */ renderComponent?: AplRenderComponentFunc; } export declare type MultiValueListStateValue = { /** * Track the slot value. */ id: string; /** * Tracks whether the value is an Entity Resolution match. * * If `erMatch = true` the value is a slot value ID for the slot type `this.slotType`. * If `erMatch = false` the value may be an arbitrary string. */ erMatch: boolean; }; interface LastInitiativeState { /** * Tracks the last act initiated from the control. */ actName?: string; /** * A list of values which are used in last initiative act. */ valueIds?: string[]; } export interface MultiValueListAPLComponentProps { /** * Function that maps the MultiValueListControlState.value to rendered value that * will be presented to the user as a list. * * Default: returns the value unchanged. */ valueRenderer?: (value: string[], input: ControlInput) => string[]; } /** * State tracked by a ListControl. */ export declare class MultiValueListControlState implements ControlState { /** * The list of values as [ (id1, erMatch), (id2, erMatch) ] */ value: MultiValueListStateValue[]; /** * Tracks the most recent elicitation action. * * Note: this isn't cleared immediate after user provides a value as the * value maybe be invalid and has to be re-elicited. Use * state.lastInitiative to test if the most recent turn was a direct elicitation. */ elicitationAction?: string; /** * Index of the page of items most recently spoken. */ spokenItemsPageIndex?: number; /** * The previous value. */ previousValue?: string[]; /** * Tracks the last initiative act from the control */ lastInitiative: LastInitiativeState; /** * Tracks if the control state values are confirmed */ confirmed?: boolean; } /** * A Control that obtains multiple values from the user by presenting a list of * available options using voice and/or APL. * * The type of value to obtain is defined by `this.slotType`. * * Capabilities: * - Request a value or list of values * - Remove a value or list of values * - Validate the value/values * - Confirm the values * - Speak the first few options * - Show all the options on APL enabled devices * - Selection of a value using a spoken ordinal, e.g. "The first one". * - Selection of a value using touch screen. * * Intents that can be handled: * - `GeneralControlIntent`: E.g. `"no, clear all names"` * - `{ValueType}_ValueControlIntent`: E.g. "add Elvis, May and Max". * - `AMAZON.YesIntent`, `AMAZON.NoIntent` * * APL events that can be handled: * - touch events indicating selection of an item on screen. * * Limitations: * - This control is not compatible with the `AMAZON.SearchQuery` slot type. */ export declare class MultiValueListControl extends Control implements InteractionModelContributor { state: MultiValueListControlState; private rawProps; private props; private handleFunc?; private initiativeFunc?; private log; constructor(props: MultiValueListControlProps); /** * Merges the user-provided props with the default props. * * Any property defined by the user-provided data overrides the defaults. */ static mergeWithDefaultProps(props: MultiValueListControlProps): DeepRequired; standardInputHandlers: ControlInputHandler[]; canHandle(input: ControlInput): Promise; handle(input: ControlInput, resultBuilder: ControlResultBuilder): Promise; private isAddWithValue; private handleAddWithValue; private isRemoveWithValue; private handleRemoveWithValue; private isConfirmationAffirmed; private handleConfirmationAffirmed; private isConfirmationDisaffirmed; private handleConfirmationDisaffirmed; private isSelectChoiceByTouch; private handleSelectChoiceByTouch; private addItem; private toggleItemChoiceSelection; private isRemoveChoiceByTouch; private handleRemoveChoiceByTouch; private removeItem; private decrementItemCount; private isClearValue; private handleClearValue; private isSelectDoneByTouch; private handleSelectDoneByTouch; /** * Add the value to state of this control. * * @param value - Value */ addValue(value: MultiValueListStateValue): void; /** * Clear the state of this control. */ clear(): void; standardInitiativeHandlers: ControlInitiativeHandler[]; canTakeInitiative(input: ControlInput): Promise; takeInitiative(input: ControlInput, resultBuilder: ControlResultBuilder): Promise; private wantsToConfirmValue; private confirmValue; private wantsToElicitValue; private elicitValue; private validate; private askElicitationQuestion; stringifyStateForDiagram(): string; getChoicesList(input: ControlInput): string[]; private getChoicesFromActivePage; private getPageIndex; renderAct(act: SystemAct, input: ControlInput, builder: ControlResponseBuilder): Promise; renderAPLComponent(input: ControlInput, resultBuilder: ControlResponseBuilder): Promise<{ [key: string]: any; }>; updateInteractionModel(generator: ControlInteractionModelGenerator, imData: ModelData): void; getTargetIds(): string[]; private evaluateRenderedValue; getSlotIds(): string[]; private getSlotTypes; private getFeedBackTypes; private getSlotValues; private evaluateAPLPropNewStyle; private addStandardAPL; } export {}; //# sourceMappingURL=MultiValueListControl.d.ts.map