import { Intent } from 'ask-sdk-model'; import { Control, ControlInputHandler, ControlInputHandlingProps, ControlProps, ControlState } from '../controls/Control'; import { ControlInput } from '../controls/ControlInput'; import { ControlResultBuilder } from '../controls/ControlResult'; import { ControlServicesProps } from '../controls/ControlServices'; import { ControlStateDiagramming } from '../controls/mixins/ControlStateDiagramming'; import { InteractionModelContributor } from '../controls/mixins/InteractionModelContributor'; import { StateValidationFunction } from '../controls/Validation'; import { ControlInteractionModelGenerator } from '../interactionModelGeneration/ControlInteractionModelGenerator'; import { ModelData } from '../interactionModelGeneration/ModelTypes'; import { ControlResponseBuilder } from '../responseGeneration/ControlResponseBuilder'; import { InvalidValueAct, ValueChangedAct, ValueConfirmedAct, ValueDisconfirmedAct, ValueSetAct } from '../systemActs/ContentActs'; import { ConfirmValueAct, RequestChangedValueAct, RequestValueAct } from '../systemActs/InitiativeActs'; import { SystemAct } from '../systemActs/SystemAct'; import { StringOrList } from '../utils/BasicTypes'; import { DeepRequired } from '../utils/DeepRequired'; /** * Props for a ValueControl. */ export interface ValueControlProps 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?: 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: 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?: ValueControlPromptProps; /** * Props to customize the reprompt fragments that will be added by * `this.renderAct()`. */ reprompts?: ValueControlPromptProps; /** * Props to customize the relationship between the control and the * interaction model. */ interactionModel?: ValueControlInteractionModelProps; /** * Props to configure input handling. */ inputHandling?: ControlInputHandlingProps; /** * Function that maps the ValueControlState.value to a corresponding rendered value * that will be presented to the user. * * Default: returns the value unchanged. */ valueRenderer?: (value: string, input: ControlInput) => string; /** * Props to customize services used by the control. */ services?: ControlServicesProps; } /** * 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 ValueControlActionProps { /** * 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[]; } /** * Props associated with the interaction model. */ export declare class ValueControlInteractionModelProps { /** * 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?: ValueControlActionProps; } /** * Props to customize the prompt fragments that will be added by * `this.renderAct()`. */ export declare class ValueControlPromptProps { valueSet?: StringOrList | ((act: ValueSetAct, input: ControlInput) => StringOrList); valueChanged?: StringOrList | ((act: ValueChangedAct, input: ControlInput) => StringOrList); invalidValue?: StringOrList | ((act: InvalidValueAct, input: ControlInput) => StringOrList); requestValue?: StringOrList | ((act: RequestValueAct, input: ControlInput) => StringOrList); requestChangedValue?: StringOrList | ((act: RequestChangedValueAct, input: ControlInput) => StringOrList); confirmValue?: StringOrList | ((act: ConfirmValueAct, input: ControlInput) => StringOrList); valueDisconfirmed?: StringOrList | ((act: ValueDisconfirmedAct, input: ControlInput) => StringOrList); valueConfirmed?: StringOrList | ((act: ValueConfirmedAct, input: ControlInput) => StringOrList); } interface LastInitiativeState { /** * Tracks the last act initiated from the control. */ actName?: string; } /** * State tracked by a ValueControl. */ export declare class ValueControlState implements ControlState { /** * The value. * * 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. */ value: string; /** * Tracks whether the value is an Entity Resolution match. */ erMatch?: boolean; /** * Tracks if the control is actively asking the user to set or change the value. */ elicitationAction?: string; /** * Tracks whether the value has been explicitly confirmed by the user. */ isValueConfirmed: boolean; /** * The previous value. */ previousValue?: string; /** * Tracks the last initiative act from the control */ lastInitiative: LastInitiativeState; } /** * A Control that obtains a single value from the user. * * The type of value to obtain is defined by `this.slotType`. * * Capabilities: * - Request a value * - Change a value * - Validate the value * - Confirm the value * * Intents that can be handled: * - `GeneralControlIntent`: E.g. `"yes, update my name"` * - `{ValueType}_ValueControlIntent`: E.g. "no change it to Elvis". * - `AMAZON.YesIntent`, `AMAZON.NoIntent` */ export declare class ValueControl extends Control implements InteractionModelContributor, ControlStateDiagramming { state: ValueControlState; private rawProps; private props; private handleFunc?; private initiativeFunc?; private log; constructor(props: ValueControlProps); /** * Merges the user-provided props with the default props. * * Any property defined by the user-provided data overrides the defaults. */ static mergeWithDefaultProps(props: ValueControlProps): 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 name to Bob" * * @param input - Input */ private isSetWithValue; /** * Handle an implicit or explicit "set" with a value provided. * * @param input - Input * @param resultBuilder - ResultBuilder */ private handleSetWithValue; /** * Determine if the input is an implicit or explicit "set" without a value. * * Example utterance: "Set my name" * * @param input - Input */ private isSetWithoutValue; /** * Handle an implicit or explicit "set" without a value. * * @param input - Input * @param resultBuilder - Result builder */ private handleSetWithoutValue; /** * Determine if the input is "change" with a value provided. * * Example utterance: "Change my name to bob" * * @param input - Input */ private isChangeWithValue; /** * Handle an implicit or explicit "change" with a value. * * @param input - Input * @param resultBuilder - Result builder */ private handleChangeWithValue; /** * Determine if the input is "change" without a value. * * Example utterance: "Change my name" * * @param input - Input */ private isChangeWithoutValue; /** * Handle an implicit or explicit "change" without a value. * * @param input - Input * @param resultBuilder - Result builder */ private handleChangeWithoutValue; /** * Determine if the input is a value without any further information. * * Example utterance: 'Bob' * * Behavior: * - If the control isn't actively asking a question, it assumes the user * meant "set \{value\}". * @param input - Input */ private isBareValue; /** * Handle a bare value. * * @param input - Input * @param resultBuilder - Result builder */ private handleBareValue; /** * Determine if the input is an affirmation to an explicit confirmation question. * * Example dialog: * - 'A: Did you say Bob?' * - 'U: Yes.' * * @param input - Input */ private isConfirmationAffirmed; /** * Handle an affirmation to an explicit confirmation question. * * @param input - Input * @param resultBuilder - Result builder */ private handleConfirmationAffirmed; /** * Determine if the input is an affirmation to an explicit confirmation question. * * Example dialog: * - 'A: Did you say Bob?' * - 'U: No.' * * @param input - Input */ private isConfirmationDisaffirmed; /** * Handle a disaffirmation to an explicit confirmation question. * * @param input - Input * @param resultBuilder - Result builder */ private handleConfirmationDisaffirmed; /** * Directly set the value. * * @param value - Value * @param erMatch - Whether the value is an ID defined for `this.slotType` * in the interaction model */ setValue(value: string, erMatch?: boolean): void; /** * Clear the state of this control. */ clear(): void; canTakeInitiative(input: ControlInput): Promise; takeInitiative(input: ControlInput, resultBuilder: ControlResultBuilder): Promise; /** * Perform validation checks and add appropriate acts to the result. * * @param input - Input * @param resultBuilder - Result builder * @param elicitationAction - The type of elicitation question that has been * asked. */ private validateAndAddActs; /** * Determine if the value needs to be explicitly confirmed * * @param input - Input */ private wantsToConfirmValue; /** * Ask the user to confirm the value. * * @param input - Input * @param resultBuilder - Result builder */ private confirmValue; /** * Determine if the value needs to obtain a new value because the current * one is invalid. * * @param input - Input */ private wantsToFixInvalidValue; /** * Ask the user to provide a new value because the current one is invalid. * * @param input - Input * @param resultBuilder - Result builder */ private fixInvalidValue; /** * Determine if the value should be elicited. * * @param input - Input */ private wantsToElicitValue; /** * Ask the user to provide a value. * * @param input - Input * @param resultBuilder - Result builder */ private elicitValue; /** * Add an elicitation act to the result. * * @param input - Input * @param resultBuilder - Result builder * @param elicitationAction - The style of elicitation to use. */ private askElicitationQuestion; stringifyStateForDiagram(): string; renderAct(act: SystemAct, input: ControlInput, builder: ControlResponseBuilder): Promise; updateInteractionModel(generator: ControlInteractionModelGenerator, imData: ModelData): void; /** * Creates an elicit-slot directive for the provided slotType. * * - The intent specified is a `{slotType}_ValueControlIntent` * - The slot specified is the `slotType` slot. * * @param slotType - Slot type * * PublicForTesting */ static generateSlotElicitationDetails(slotType: string): { intent: Intent; slotName: string; }; } export {}; //# sourceMappingURL=ValueControl.d.ts.map