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 { 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 DateControl. */ export interface DateControlProps 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. * * - Common validation functions are defined in the `DateControlValidations` namespace * which can be added directly to this prop. e.g.: * ``` * valid: DateControlValidations.FUTURE_DATE_ONLY, * ``` */ 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 like this by Tuesday". */ 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?: DateControlPromptProps; /** * Props to customize the reprompt fragments that will be added by * `this.renderAct()`. */ reprompts?: DateControlPromptProps; /** * Props to customize the relationship between the control and the * interaction model. */ interactionModel?: DateControlInteractionModelProps; /** * Props to configure input handling. */ inputHandling?: ControlInputHandlingProps; /** * Function that maps the DateControlState.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 declare type DateControlActionProps = { /** * 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 interface DateControlInteractionModelProps { /** * 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_date', '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?: DateControlActionProps; } /** * Reason codes for built-in validation rules. */ export declare enum DateValidationFailReasonCode { /** * The date must be in the past. */ PAST_DATE_ONLY = "pastDateOnly", /** * The date must be in the future. */ FUTURE_DATE_ONLY = "futureDateOnly" } /** * Built-in validation functions for use with DateControl */ export declare namespace DateControlValidations { /** * Validate that the date is in the past. * @param state - Control state * @param input - Input */ const PAST_DATE_ONLY: StateValidationFunction; /** * Validate that the date is in the future. * @param state - Control state * @param input - Input */ const FUTURE_DATE_ONLY: StateValidationFunction; } /** * Props to customize the prompt fragments that will be added by * `this.renderAct()`. */ export interface DateControlPromptProps { 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); valueDisaffirmed?: StringOrList | ((act: ValueDisconfirmedAct, input: ControlInput) => StringOrList); valueAffirmed?: StringOrList | ((act: ValueConfirmedAct, input: ControlInput) => StringOrList); } interface LastInitiativeState { /** * Tracks the last act initiated from the control. */ actName?: string; } /** * State tracked by a DateControl. */ export declare class DateControlState implements ControlState { /** * The value, an ISO date string. */ value: string; /** * 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 date from the user. * * Capabilities: * - Request a value * - Change a value * - Validate the value * - Confirm the value * - Infer the specific date for a partially specified date. * * Intents that can be handled: * - `GeneralControlIntent`: E.g. `"yes, update my birth date"` * - `AMAZON_DATE_ValueControlIntent`: E.g. "no change it to Tuesday". * - `AMAZON.YesIntent`, `AMAZON.NoIntent` */ export declare class DateControl extends Control implements InteractionModelContributor { state: DateControlState; private rawProps; private props; private handleFunc?; private initiativeFunc?; private log; constructor(props: DateControlProps); /** * Merges the user-provided props with the default props. * * Any property defined by the user-provided data overrides the defaults. */ static mergeWithDefaultProps(props: DateControlProps): DeepRequired; standardInputHandlers: ControlInputHandler[]; canHandle(input: ControlInput): Promise; private isSetWithValue; private handleSetWithValue; private isSetWithoutValue; private handleSetWithoutValue; /** * Test if the input is a valid change-action with a value provided. * * @param input - Input */ private isChangeWithValue; private handleChangeWithValue; /** * Test if the input is a valid change-action without a value provided. * * @param input - Input */ private isChangeWithoutValue; private handleChangeWithoutValue; /** * Test if the input is a DateControlIntent with just a date provided. * If we aren't asking a question it is assumed the user meant 'set value'. * @param input - Input */ private isBareValue; private handleBareValue; private isConfirmationAffirmed; private handleConfirmationAffirmed; private isConfirmationDisaffirmed; private handleConfirmationDisaffirmed; handle(input: ControlInput, resultBuilder: ControlResultBuilder): Promise; canTakeInitiative(input: ControlInput): Promise; takeInitiative(input: ControlInput, resultBuilder: ControlResultBuilder): Promise; private wantsToElicitValue; private elicitValue; askElicitationQuestion(input: ControlInput, resultBuilder: ControlResultBuilder, elicitationAction: string): void; validateAndAddActs(input: ControlInput, resultBuilder: ControlResultBuilder, elicitationAction: string): Promise; private wantsToConfirmValue; private confirmValue; private wantsToFixInvalidValue; private fixInvalidValue; /** * Directly set the value. * * @param value - Value, an ISO Date string */ setValue(value: string): void; /** * Clear the state of this control. */ clear(): void; renderAct(act: SystemAct, input: ControlInput, builder: ControlResponseBuilder): Promise; updateInteractionModel(generator: ControlInteractionModelGenerator, imData: ModelData): void; } export {}; //# sourceMappingURL=DateControl.d.ts.map