import { DeepRequired, ModelData } 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 { StateValidationFunction } from '../../controls/Validation'; import { ControlInteractionModelGenerator } from '../../interactionModelGeneration/ControlInteractionModelGenerator'; import { ResponseStyleEvaluator } from '../../modality/ModalityEvaluation'; import { ControlResponseBuilder } from '../../responseGeneration/ControlResponseBuilder'; import { InvalidValueAct, ValueChangedAct, ValueClearedAct, ValueConfirmedAct, ValueDisconfirmedAct, ValueSetAct } from '../../systemActs/ContentActs'; import { ConfirmValueAct, InitiativeAct, RequestValueAct, SuggestValueAct } from '../../systemActs/InitiativeActs'; import { SystemAct } from '../../systemActs/SystemAct'; import { StringOrList } from '../../utils/BasicTypes'; /** * Props for a NumberControl. */ export interface NumberControlProps extends ControlProps { /** * Unique identifier for control instance */ id: 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?: StateValidationFunction | Array>; /** * 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: I would three of those". */ required?: boolean | ((input: ControlInput) => boolean); /** * Props to customize the prompt fragments that will be added by `this.renderAct()`. */ prompts?: NumberControlPromptsProps; /** * Props to customize the reprompt fragments that will be added by `this.renderAct()`. */ reprompts?: NumberControlPromptsProps; /** * 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. * * Default: false * * Usage: * * 1) Use pre-defined built-ins under NumberControlBuiltIns.* namespace which provides few * default implementations. * * e.g: NumberControlBuiltIns.confirmMostLikelyMisunderstandingInputs returns `true` whenever * an input has a most-likely misunderstanding value defined on the function * NumberControlBuiltIns.defaultMostLikelyMisunderstandingFunc. */ confirmationRequired?: boolean | ((state: NumberControlState, input: ControlInput) => boolean); /** * Function that returns the single most likely misunderstanding for a given value, or undefined if none is known. * * Default: `NumberControlBuiltIns.defaultMostLikelyMisunderstandingFunc(value)` * * Control behavior: * - If the user disaffirms a value the most likely misunderstood value is suggested to the user. * e.g: * * A: What number? * U: Fourteen * A: Was the fourteen? * U: No * A: My mistake. Did you perhaps say forty? * U: Yes * A: Great. 40. */ mostLikelyMisunderstanding?: (value: number, input: ControlInput) => number | undefined; /** * Props to customize the relationship between the control and the * interaction model. */ interactionModel?: NumberControlInteractionModelProps; /** * Props to configure input handling. */ inputHandling?: ControlInputHandlingProps; /** * Props to customize the APL generated by this control. */ apl?: NumberControlAPLProps; /** * Function that maps the NumberControlState.value to rendered value that * will be presented to the user as a list. * * Default: returns the value unchanged in string format. */ valueRenderer?: (value: number, input: ControlInput) => string; /** * 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; } /** * 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 declare type NumberControlActionProps = { /** * Action slot value IDs that are associated with the "set value" capability. * * Default: ['builtin_set'] */ set?: string[]; /** * Action slot value IDs that are associated with the "change value" capability. * * Default ['builtin_change'] */ change?: string[]; /** * Action slot value IDs that are associated with the "clear value" capability. * * Default ['builtin_clear', builtin_remove'] */ clear?: string[]; }; /** * Props associated with the interaction model. */ export interface NumberControlInteractionModelProps { /** * 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 to * 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. * * 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?: NumberControlActionProps; } /** * Props to customize the prompt fragments that will be added by `this.renderAct()`. */ export interface NumberControlPromptsProps { requestValue?: StringOrList | ((act: RequestValueAct, input: ControlInput) => StringOrList); valueSet?: StringOrList | ((act: ValueSetAct, input: ControlInput) => StringOrList); valueChanged?: StringOrList | ((act: ValueChangedAct, input: ControlInput) => StringOrList); confirmValue?: StringOrList | ((act: ConfirmValueAct, input: ControlInput) => StringOrList); valueConfirmed?: StringOrList | ((act: ValueConfirmedAct, input: ControlInput) => StringOrList); valueDisconfirmed?: StringOrList | ((act: ValueDisconfirmedAct, input: ControlInput) => StringOrList); valueCleared?: StringOrList | ((act: ValueClearedAct, input: ControlInput) => StringOrList); invalidValue?: StringOrList | ((act: InvalidValueAct, input: ControlInput) => StringOrList); suggestValue?: StringOrList | ((act: SuggestValueAct, input: ControlInput) => StringOrList); } export declare type AplContent = { document: { [key: string]: any; }; dataSource: { [key: string]: any; }; }; export declare type AplContentFunc = (control: NumberControl, input: ControlInput) => AplContent | Promise; export declare type AplDocumentPropNewStyle = AplContent | AplContentFunc; export declare type NumberControlAplRenderComponentFunc = (control: NumberControl, props: NumberControlAPLComponentProps, input: ControlInput, resultBuilder: ControlResponseBuilder) => { [key: string]: any; }; /** * Props associated with the APL produced by NumberControl. */ export declare class NumberControlAPLProps { /** * Determines if APL should be produced. * * Default: true */ enabled?: boolean | ((input: ControlInput) => boolean); /** * Defines the APL to use when requesting a value. */ requestValue?: AplDocumentPropNewStyle; /** * Tracks the text to be displayed for invalid input values. */ validationFailedMessage?: string | ((value?: number) => string); /** * Determines the APL Component rendering mode. * * Usage: * * 1) Use pre-defined built-ins under ListControlComponentAPLBuiltIns.* namespace which provides both default * implementations and customization of props(NumberControlAPLComponentProps) to render an APL component. * * e.g renderComponent: NumberControlAPLComponentBuiltIns.ModalKeyPadRender.default --- Default Implementation * renderComponent: NumberControlAPLComponentBuiltIns.ModalKeyPadRender.default.of(props: NumberControlAPLComponentProps) --- Override few properties * * 2) Provide a custom function which returns an APL component. * * Default: NumberControlAPLComponentBuiltIns.ModalKeyPadRender.default */ renderComponent?: NumberControlAplRenderComponentFunc; } /** * Tracks the last act initiated from the control. */ interface LastInitiativeState { /** * Control act name. */ actName?: string; } /** * Props to customize NumberControl APLComponent rendering. */ export interface NumberControlAPLComponentProps { /** * Tracks the text to be displayed for invalid input values * when control renders APL in Component Mode. */ validationFailedMessage?: string | ((value?: number) => string); /** * Function that maps the NumberControlState.value to rendered value that * will be presented to the user. * * Default: returns the value unchanged */ valueRenderer?: (value: number, input: ControlInput) => string; } /** * State tracked by a NumberControl. */ export declare class NumberControlState implements ControlState { /** * The value, an integer. */ value: number; /** * Tracks whether the value has been explicitly confirmed by the user. */ confirmed?: boolean; /** * Tracks the last initiative act from the control */ lastInitiative: LastInitiativeState; /** * 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; } /** * A Control that obtains a single integer from the user. * * Capabilities: * - Request a value * - Change a value * - Validate the value * - Confirm the value * - Suggest a value, if the user disconfirms and we know a good alternative to suggest. * * Intents that can be handled: * - `GeneralControlIntent`: E.g. `"yes, update my age"` * - `AMAZON_NUMBER_ValueControlIntent`: E.g. "no change it to three". * - `AMAZON.YesIntent`, `AMAZON.NoIntent` * * APL events that can be handled: * - touch events indicating number value input. */ export declare class NumberControl extends Control implements InteractionModelContributor { state: NumberControlState; private rawProps; private props; private handleFunc?; private initiativeFunc?; private log; constructor(props: NumberControlProps); /** * Merges the user-provided props with the default props. * * Any property defined by the user-provided data overrides the defaults. */ static mergeWithDefaultProps(props: NumberControlProps): DeepRequired; standardInputHandlers: ControlInputHandler[]; canHandle(input: ControlInput): Promise; handle(input: ControlInput, resultBuilder: ControlResultBuilder): Promise; /** * Determine if the input is an implicit or explicit "set" with a value provided. * * Example utterance: "Set my age to six" * * @param input - Input */ private isSetWithValue; /** * Handle an implicit or explicit "set" with a value provided. * * @param input - Input * @param resultBuilder - ResultBuilder */ private handleSetWithValue; private isSetWithoutValue; private handleSetWithoutValue; private isChangeWithValue; private handleChangeWithValue; private isChangeWithoutValue; private handleChangeWithoutValue; private isBareValue; private handleBareValue; private isConfirmationAffirmed; private handleConfirmationAffirmed; private isSuggestionAccepted; private handleSuggestionAccepted; private isConfirmationDisaffirmed; private handleConfirmationDisaffirmed; private isAffirmWithValue; private handleAffirmWithValue; private isDisaffirmWithValue; private handleDisaffirmWithValue; private isClearValue; private handleClearValue; private isSelectChoiceByTouch; private handleSelectChoiceByTouch; validateAndAddCommonFeedbackActs(input: ControlInput, resultBuilder: ControlResultBuilder, elicitationAction: string): Promise; private askElicitationQuestion; addInitiativeAct(initiativeAct: InitiativeAct, resultBuilder: ControlResultBuilder): void; isConfirmationRequired(input: ControlInput): boolean; private confirmValue; standardInitiativeHandlers: ControlInitiativeHandler[]; canTakeInitiative(input: ControlInput): Promise; takeInitiative(input: ControlInput, resultBuilder: ControlResultBuilder): Promise; private wantsToElicitValue; private elicitValue; private wantsToRequestReplacementForInvalidValue; private requestReplacementForInvalidValue; private wantsToConfirmValue; renderAct(act: SystemAct, input: ControlInput, builder: ControlResponseBuilder): Promise; private addStandardAPL; updateInteractionModel(generator: ControlInteractionModelGenerator, imData: ModelData): void; /** * Directly set the value. * * @param value - Value, either an integer or a string that can be parsed as a integer. */ setValue(value: string | number): void; /** * Clear the state of this control. */ clear(): void; renderAPLComponent(input: ControlInput, resultBuilder: ControlResponseBuilder): Promise<{ [key: string]: any; }>; private getSuggestionForMisunderstoodValue; private evaluateAPLPropNewStyle; evaluateAPLValidationFailedMessage(prop: string | ((value?: number) => string), input: ControlInput): Promise; } export {}; //# sourceMappingURL=NumberControl.d.ts.map