/** * SMRT Form context for field registration and coordination */ import type { ControlConstraints, ControlExtensionContext, ControlInteractionRegistry, ControlKind, ControlOption, ControlRuntimeState, ControlSensitivity, ControlSubject, ControlValueValidationResult } from '@happyvertical/smrt-ui/forms'; /** * Field definition for form registration */ /** All supported form field types */ export type FormFieldType = 'text' | 'email' | 'datetime' | 'number' | 'address' | 'checkbox' | 'daterange' | 'measurement' | 'money' | 'phone' | 'select' | 'textarea'; export interface FieldDefinition { /** Field name (used as key for LLM extraction) */ name: string; /** Field type */ type: FormFieldType; /** Human-readable label */ label?: string; /** Description to help LLM understand field purpose */ description?: string; /** Set the field value */ setValue: (value: unknown) => void; /** Context-aware setter for hooks that need to issue another control command. */ setValueWithContext?: (value: unknown, context: ControlExtensionContext) => void | Promise; /** Get current field value */ getValue: () => unknown; /** * Convert an incoming intent into the final value shown for review/applied. * May throw when the value cannot be represented canonically by this field. */ prepareValue?: (value: unknown) => unknown; /** Validate/canonicalize a complete value edited in staged review. */ prepareReviewedValue?: (value: unknown) => unknown; /** * Convert a value extracted from speech into the field's canonical value. * May be asynchronous for controls that support natural-language parsing. */ prepareExtractedValue?: (value: unknown) => unknown | Promise; /** Optional richer interaction metadata and capabilities. */ controlId?: string; /** Immutable token identifying the DOM subtree owned by this field. */ ownerToken?: string; subject?: ControlSubject; interactionKind?: ControlKind; sensitivity?: ControlSensitivity; readable?: boolean; writable?: boolean; constraints?: ControlConstraints; /** Optional WebMCP schema override for structured field values. */ webMcpSchema?: Record; options?: ControlOption[]; unit?: string; /** Return true to affirm an accepted idempotent clear; false rejects it. */ clear?: ((context?: ControlExtensionContext) => void | Promise) | ((context?: ControlExtensionContext) => boolean | Promise); focus?: () => void; reveal?: () => void; highlight?: (durationMs?: number) => void; validate?: (context?: ControlExtensionContext) => boolean | Promise; validateValue?: (value: unknown, context?: ControlExtensionContext) => ControlValueValidationResult | Promise; getState?: () => ControlRuntimeState; } /** * SMRT Form context interface */ export interface SMRTFormContext { /** Current mode */ readonly mode: 'smrt' | 'default'; /** * Register a field with the form. New contexts return an identity-bound * disposer; legacy void-returning contexts remain supported. */ registerField: (field: FieldDefinition) => void | (() => void); /** Legacy name-based cleanup. Prefer the disposer returned by registerField. */ unregisterField: (name: string) => void; /** Get all registered fields schema (for LLM prompt) */ getFieldSchema: () => FieldDefinition[]; /** Whether form-level listening is active */ readonly isFormListening: boolean; /** Whether currently extracting from speech */ readonly isExtracting: boolean; /** Toggle form-level listening on/off */ toggleListening: () => void; /** Shared transport-neutral registry used by voice/chat/tutorial adapters. */ readonly interactionRegistry: ControlInteractionRegistry; readonly formId: string; } /** * Context key for SMRT form */ export declare const SMRT_FORM_KEY: unique symbol; /** * Set form context (used by SMRTForm) */ export declare function setFormContext(ctx: SMRTFormContext): void; /** * Get form context * @throws If called outside of SMRTForm */ export declare function getFormContext(): SMRTFormContext; /** * Try to get form context (returns null if not available) */ export declare function tryGetFormContext(): SMRTFormContext | null; //# sourceMappingURL=form-context.d.ts.map