@elizaos/plugin-form 2.0.0-alpha.2 → 2.0.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @module actions/restore
3
+ * @description Action for restoring stashed form sessions
4
+ *
5
+ * ## Why an Action (Not Evaluator)
6
+ *
7
+ * The restore operation is unique among form intents because:
8
+ *
9
+ * 1. **Timing Matters**: The restored form context must be available
10
+ * to the agent BEFORE it generates a response. Evaluators run
11
+ * AFTER response generation.
12
+ *
13
+ * 2. **Preemption**: When user says "resume my form", the FORM_RESTORE
14
+ * action should preempt REPLY, generate its own response with the
15
+ * restored context, and let the agent continue naturally.
16
+ *
17
+ * 3. **Immediate Context**: After restore, the provider runs and gives
18
+ * the agent the restored form context for its response.
19
+ *
20
+ * ## Flow Comparison
21
+ *
22
+ * ### Other Intents (via Evaluator):
23
+ * ```
24
+ * Message → Provider (no context) → REPLY → Evaluator (updates state)
25
+ * ↓
26
+ * Next message has updated context
27
+ * ```
28
+ *
29
+ * ### Restore Intent (via Action):
30
+ * ```
31
+ * Message → FORM_RESTORE.validate() → true
32
+ * ↓
33
+ * FORM_RESTORE.handler() → Restore session → Generate response
34
+ * ↓
35
+ * Next message has restored context immediately
36
+ * ```
37
+ *
38
+ * ## Handling Multiple Stashed Forms
39
+ *
40
+ * If user has multiple stashed forms, this action restores the most recent.
41
+ * Future enhancement: Let user choose which form to restore.
42
+ *
43
+ * ## Conflicts with Active Forms
44
+ *
45
+ * If user has an active form in the current room and tries to restore,
46
+ * the action asks them to either continue or stash the current one.
47
+ */
48
+ import { type Action } from "@elizaos/core";
49
+ /**
50
+ * Form Restore Action
51
+ *
52
+ * Fast-path action for restoring stashed forms.
53
+ * Preempts REPLY to provide immediate restoration with summary.
54
+ *
55
+ * WHY action:
56
+ * - Needs to run BEFORE provider
57
+ * - Must generate immediate response
58
+ * - Context needed for next message
59
+ */
60
+ export declare const formRestoreAction: Action;
61
+ export default formRestoreAction;
62
+ //# sourceMappingURL=restore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"restore.d.ts","sourceRoot":"","sources":["../../src/actions/restore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAEH,OAAO,EACL,KAAK,MAAM,EASZ,MAAM,eAAe,CAAC;AAIvB;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,EAAE,MAkM/B,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
@@ -0,0 +1,320 @@
1
+ /**
2
+ * @module builder
3
+ * @description Fluent builder API for defining forms and controls
4
+ *
5
+ * ## Why a Builder API
6
+ *
7
+ * Form definitions can be verbose with many optional fields. The builder
8
+ * API provides:
9
+ *
10
+ * 1. **Type Safety**: Method chaining with TypeScript gives autocomplete
11
+ * 2. **Readability**: Intent is clear from method names
12
+ * 3. **Defaults**: Builder applies sensible defaults
13
+ * 4. **Validation**: Build-time checks for common mistakes
14
+ *
15
+ * ## Usage Examples
16
+ *
17
+ * ### Simple Form
18
+ *
19
+ * ```typescript
20
+ * const form = Form.create('contact')
21
+ * .name('Contact Form')
22
+ * .control(C.email('email').required())
23
+ * .control(C.text('message').required())
24
+ * .build();
25
+ * ```
26
+ *
27
+ * ### Complex Form
28
+ *
29
+ * ```typescript
30
+ * const registrationForm = Form.create('registration')
31
+ * .name('User Registration')
32
+ * .description('Create your account')
33
+ * .control(
34
+ * C.email('email')
35
+ * .required()
36
+ * .ask('What email should we use for your account?')
37
+ * .example('user@example.com')
38
+ * )
39
+ * .control(
40
+ * C.text('username')
41
+ * .required()
42
+ * .minLength(3)
43
+ * .maxLength(20)
44
+ * .pattern('^[a-z0-9_]+$')
45
+ * .ask('Choose a username (letters, numbers, underscore)')
46
+ * )
47
+ * .control(
48
+ * C.number('age')
49
+ * .min(13)
50
+ * .ask('How old are you?')
51
+ * )
52
+ * .onSubmit('handle_registration')
53
+ * .ttl({ minDays: 7, maxDays: 30 })
54
+ * .build();
55
+ * ```
56
+ *
57
+ * ### Custom Type
58
+ *
59
+ * ```typescript
60
+ * // Register custom type first
61
+ * FormService.registerType('solana_address', {
62
+ * validate: (v) => ({
63
+ * valid: /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(String(v)),
64
+ * error: 'Invalid Solana address'
65
+ * }),
66
+ * extractionPrompt: 'a Solana wallet address (Base58 encoded)'
67
+ * });
68
+ *
69
+ * // Use in form
70
+ * const form = Form.create('wallet')
71
+ * .control(
72
+ * C.field('walletAddress')
73
+ * .type('solana_address')
74
+ * .required()
75
+ * .label('Wallet Address')
76
+ * .ask('What is your Solana wallet address?')
77
+ * )
78
+ * .build();
79
+ * ```
80
+ *
81
+ * ## Shorthand Exports
82
+ *
83
+ * For convenience:
84
+ * - `Form` is an alias for `FormBuilder`
85
+ * - `C` is an alias for `ControlBuilder`
86
+ *
87
+ * This enables the concise syntax shown in examples.
88
+ */
89
+ import type { JsonValue } from "@elizaos/core";
90
+ import type { FormControl, FormControlOption, FormControlDependency, FormDefinition, FormDefinitionHooks } from "./types";
91
+ /**
92
+ * Fluent builder for FormControl.
93
+ *
94
+ * Create controls with readable, chainable syntax:
95
+ *
96
+ * ```typescript
97
+ * ControlBuilder.email('email').required().ask('What is your email?')
98
+ * ```
99
+ *
100
+ * All methods return `this` for chaining except `build()` which returns
101
+ * the final FormControl.
102
+ */
103
+ export declare class ControlBuilder {
104
+ /** Partial control being built */
105
+ private control;
106
+ /**
107
+ * Create a new ControlBuilder.
108
+ *
109
+ * @param key - The unique key for this control
110
+ */
111
+ constructor(key: string);
112
+ /** Create a generic field builder */
113
+ static field(key: string): ControlBuilder;
114
+ /** Create a text field */
115
+ static text(key: string): ControlBuilder;
116
+ /** Create an email field */
117
+ static email(key: string): ControlBuilder;
118
+ /** Create a number field */
119
+ static number(key: string): ControlBuilder;
120
+ /** Create a boolean (yes/no) field */
121
+ static boolean(key: string): ControlBuilder;
122
+ /** Create a select field with options */
123
+ static select(key: string, options: FormControlOption[]): ControlBuilder;
124
+ /** Create a date field */
125
+ static date(key: string): ControlBuilder;
126
+ /** Create a file upload field */
127
+ static file(key: string): ControlBuilder;
128
+ /** Set the field type */
129
+ type(type: string): this;
130
+ /** Mark field as required */
131
+ required(): this;
132
+ /** Mark field as optional (default) */
133
+ optional(): this;
134
+ /** Mark field as hidden (extract silently, never ask) */
135
+ hidden(): this;
136
+ /** Mark field as sensitive (don't echo value back) */
137
+ sensitive(): this;
138
+ /** Mark field as readonly (can't change after set) */
139
+ readonly(): this;
140
+ /** Mark field as accepting multiple values */
141
+ multiple(): this;
142
+ /** Set regex pattern for validation */
143
+ pattern(regex: string): this;
144
+ /** Set minimum value (for numbers) or minimum length (via minLength) */
145
+ min(n: number): this;
146
+ /** Set maximum value (for numbers) or maximum length (via maxLength) */
147
+ max(n: number): this;
148
+ /** Set minimum string length */
149
+ minLength(n: number): this;
150
+ /** Set maximum string length */
151
+ maxLength(n: number): this;
152
+ /** Set allowed values (enum) */
153
+ enum(values: string[]): this;
154
+ /** Set select options */
155
+ options(opts: FormControlOption[]): this;
156
+ /** Set human-readable label */
157
+ label(label: string): this;
158
+ /** Set custom prompt for asking this field */
159
+ ask(prompt: string): this;
160
+ /** Set description for LLM context */
161
+ description(desc: string): this;
162
+ /** Add extraction hints (keywords to look for) */
163
+ hint(...hints: string[]): this;
164
+ /** Set example value for "give me an example" */
165
+ example(value: string): this;
166
+ /** Set confidence threshold for auto-acceptance */
167
+ confirmThreshold(n: number): this;
168
+ /** Set accepted MIME types for file upload */
169
+ accept(mimeTypes: string[]): this;
170
+ /** Set maximum file size in bytes */
171
+ maxSize(bytes: number): this;
172
+ /** Set maximum number of files */
173
+ maxFiles(n: number): this;
174
+ /** Set roles that can see/fill this field */
175
+ roles(...roles: string[]): this;
176
+ /** Set default value */
177
+ default(value: JsonValue): this;
178
+ /** Set dependency on another field */
179
+ dependsOn(field: string, condition?: FormControlDependency["condition"], value?: JsonValue): this;
180
+ /** Set database column name (defaults to key) */
181
+ dbbind(columnName: string): this;
182
+ /** Set section name for grouping */
183
+ section(name: string): this;
184
+ /** Set display order within section */
185
+ order(n: number): this;
186
+ /** Set placeholder text */
187
+ placeholder(text: string): this;
188
+ /** Set help text */
189
+ helpText(text: string): this;
190
+ /** Set custom widget type */
191
+ widget(type: string): this;
192
+ /** Add localized text for a locale */
193
+ i18n(locale: string, translations: {
194
+ label?: string;
195
+ description?: string;
196
+ askPrompt?: string;
197
+ helpText?: string;
198
+ }): this;
199
+ /** Add custom metadata */
200
+ meta(key: string, value: JsonValue): this;
201
+ /**
202
+ * Build the final FormControl.
203
+ *
204
+ * Applies defaults and validates the control.
205
+ *
206
+ * @returns Complete FormControl object
207
+ */
208
+ build(): FormControl;
209
+ }
210
+ /**
211
+ * Fluent builder for FormDefinition.
212
+ *
213
+ * Create forms with readable, chainable syntax:
214
+ *
215
+ * ```typescript
216
+ * Form.create('contact')
217
+ * .name('Contact Form')
218
+ * .control(C.email('email').required())
219
+ * .onSubmit('handle_contact')
220
+ * .build();
221
+ * ```
222
+ */
223
+ export declare class FormBuilder {
224
+ /** Partial form being built */
225
+ private form;
226
+ /**
227
+ * Create a new FormBuilder.
228
+ *
229
+ * @param id - Unique form identifier
230
+ */
231
+ constructor(id: string);
232
+ /** Create a new form builder */
233
+ static create(id: string): FormBuilder;
234
+ /** Set form name */
235
+ name(name: string): this;
236
+ /** Set form description */
237
+ description(desc: string): this;
238
+ /** Set form version */
239
+ version(v: number): this;
240
+ /**
241
+ * Add a control to the form.
242
+ *
243
+ * Accepts either a ControlBuilder (calls .build()) or a FormControl.
244
+ */
245
+ control(builder: ControlBuilder | FormControl): this;
246
+ /** Add multiple controls */
247
+ controls(...builders: (ControlBuilder | FormControl)[]): this;
248
+ /** Add required text fields */
249
+ required(...keys: string[]): this;
250
+ /** Add optional text fields */
251
+ optional(...keys: string[]): this;
252
+ /** Set roles that can start this form */
253
+ roles(...roles: string[]): this;
254
+ /** Allow multiple submissions per user */
255
+ allowMultiple(): this;
256
+ /** Disable undo functionality */
257
+ noUndo(): this;
258
+ /** Disable skip functionality */
259
+ noSkip(): this;
260
+ /** Disable autofill */
261
+ noAutofill(): this;
262
+ /** Set maximum undo steps */
263
+ maxUndoSteps(n: number): this;
264
+ /** Configure TTL (time-to-live) settings */
265
+ ttl(config: {
266
+ minDays?: number;
267
+ maxDays?: number;
268
+ effortMultiplier?: number;
269
+ }): this;
270
+ /** Disable nudge messages */
271
+ noNudge(): this;
272
+ /** Set inactivity hours before nudge */
273
+ nudgeAfter(hours: number): this;
274
+ /** Set custom nudge message */
275
+ nudgeMessage(message: string): this;
276
+ /** Set task worker to call on session start */
277
+ onStart(workerName: string): this;
278
+ /** Set task worker to call on field change */
279
+ onFieldChange(workerName: string): this;
280
+ /** Set task worker to call when form is ready to submit */
281
+ onReady(workerName: string): this;
282
+ /** Set task worker to call on submission */
283
+ onSubmit(workerName: string): this;
284
+ /** Set task worker to call on cancellation */
285
+ onCancel(workerName: string): this;
286
+ /** Set task worker to call on expiration */
287
+ onExpire(workerName: string): this;
288
+ /** Set multiple hooks at once */
289
+ hooks(hooks: FormDefinitionHooks): this;
290
+ /** Enable debug mode (logs extraction reasoning) */
291
+ debug(): this;
292
+ /** Add localized form text */
293
+ i18n(locale: string, translations: {
294
+ name?: string;
295
+ description?: string;
296
+ }): this;
297
+ /** Add custom metadata */
298
+ meta(key: string, value: JsonValue): this;
299
+ /**
300
+ * Build the final FormDefinition.
301
+ *
302
+ * Applies defaults and validates the form.
303
+ *
304
+ * @returns Complete FormDefinition object
305
+ */
306
+ build(): FormDefinition;
307
+ }
308
+ /**
309
+ * Shorthand for FormBuilder.create
310
+ *
311
+ * Usage: `Form.create('myForm')...`
312
+ */
313
+ export declare const Form: typeof FormBuilder;
314
+ /**
315
+ * Shorthand for ControlBuilder factories
316
+ *
317
+ * Usage: `C.email('email').required()`
318
+ */
319
+ export declare const C: typeof ControlBuilder;
320
+ //# sourceMapp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C,+CAA+C;IAC/C,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAKjC,8CAA8C;IAC9C,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAKvC,2DAA2D;IAC3D,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAKjC,4CAA4C;IAC5C,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAKlC,8CAA8C;IAC9C,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAKlC,4CAA4C;IAC5C,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAKlC,iCAAiC;IACjC,KAAK,CAAC,KAAK,EAAE,mBAAmB,GAAG,IAAI;IAOvC,oDAAoD;IACpD,KAAK,IAAI,IAAI;IAOb,8BAA8B;IAC9B,IAAI,CACF,MAAM,EAAE,MAAM,EACd,YAAY,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GACpD,IAAI;IAOP,0BAA0B;IAC1B,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI;IAOzC;;;;;;OAMG;IACH,KAAK,IAAI,cAAc;CAUxB;AAMD;;;;GAIG;AACH,eAAO,MAAM,IAAI,oBAAc,CAAC;AAEhC;;;;GAIG;AACH,eAAO,MAAM,CAAC,uBAAiB,CAAC"}
@@ -0,0 +1,128 @@
1
+ /**
2
+ * @module builtins
3
+ * @description Built-in control types for the Form Plugin
4
+ *
5
+ * ## Overview
6
+ *
7
+ * This module defines the standard control types that are available out of the box:
8
+ * - text: Plain text strings
9
+ * - number: Numeric values (integers or decimals)
10
+ * - email: Email addresses with format validation
11
+ * - boolean: Yes/no, true/false values
12
+ * - select: Choice from predefined options
13
+ * - date: Date values in various formats
14
+ * - file: File uploads (handled specially)
15
+ *
16
+ * ## Why Built-in Types
17
+ *
18
+ * Built-in types provide:
19
+ * 1. **Consistent validation** across all forms - same rules everywhere
20
+ * 2. **Sensible defaults** for common field types - less configuration
21
+ * 3. **LLM extraction hints** optimized for each type - better extraction
22
+ * 4. **Override protection** to prevent accidental shadowing - safety first
23
+ *
24
+ * ## Architecture Decision: ControlType vs TypeHandler
25
+ *
26
+ * We use ControlType (not the legacy TypeHandler) because:
27
+ * - ControlType is the unified interface for all type categories
28
+ * - ControlType supports composite types (subcontrols)
29
+ * - ControlType supports external types (activate/confirm)
30
+ * - TypeHandler is legacy and maintained only for backwards compatibility
31
+ *
32
+ * ## Why These Specific Types
33
+ *
34
+ * | Type | Why Built-in |
35
+ * |------|--------------|
36
+ * | text | Most common field type, catch-all for strings |
37
+ * | number | Second most common, needs special parsing (commas, $) |
38
+ * | email | Critical for communication, has clear format rules |
39
+ * | boolean | Binary choice, many natural language forms (yes/no/true/false) |
40
+ * | select | Constrained choice, validation against options |
41
+ * | date | Complex parsing (many formats), needs normalization |
42
+ * | file | Special handling needed (size, type, storage) |
43
+ *
44
+ * ## Extending
45
+ *
46
+ * Plugins can register custom types via FormService.registerControlType().
47
+ * Built-in types can be overridden with { allowOverride: true } option,
48
+ * but this will log a warning.
49
+ *
50
+ * ## Usage
51
+ *
52
+ * Built-in types are automatically registered when FormService starts.
53
+ * You don't need to call registerBuiltinTypes() manually.
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * // Check if a type is built-in before overriding
58
+ * if (isBuiltinType('email')) {
59
+ * console.log('Warning: overriding built-in type');
60
+ * formService.registerControlType(myEmailType, { allowOverride: true });
61
+ * }
62
+ * ```
63
+ */
64
+ import type { ControlType } from "./types";
65
+ /**
66
+ * Array of all built-in control types.
67
+ *
68
+ * These are registered automatically when FormService starts.
69
+ * The order doesn't matter; they're looked up by id.
70
+ *
71
+ * WHY array + map:
72
+ * - Array allows easy iteration for registration
73
+ * - Map provides O(1) lookup for override checks
74
+ * - Both derived from same source ensures consistency
75
+ */
76
+ export declare const BUILTIN_TYPES: ControlType[];
77
+ /**
78
+ * Map of built-in types by id for quick lookup.
79
+ *
80
+ * WHY Map (not object):
81
+ * - Type-safe keys
82
+ * - O(1) lookup performance
83
+ * - Clear has/get semantics
84
+ */
85
+ export declare const BUILTIN_TYPE_MAP: Map<string, ControlType>;
86
+ /**
87
+ * Register all built-in types with a FormService instance.
88
+ *
89
+ * This is called automatically during FormService.start().
90
+ * You typically don't need to call this directly.
91
+ *
92
+ * WHY take a function (not FormService):
93
+ * - Avoids circular dependency (builtins.ts ↔ service.ts)
94
+ * - Service passes its registerControlType method
95
+ * - Clean separation of concerns
96
+ *
97
+ * @param registerFn - The FormService.registerControlType method
98
+ */
99
+ export declare function registerBuiltinTypes(registerFn: (type: ControlType, options?: {
100
+ allowOverride?: boolean;
101
+ }) => void): void;
102
+ /**
103
+ * Get a built-in type by id.
104
+ *
105
+ * This is a convenience for checking if a type is built-in
106
+ * before attempting to override it.
107
+ *
108
+ * WHY this exists:
109
+ * - Plugins may want to extend a built-in type
110
+ * - Checking before override allows informed decisions
111
+ * - Avoids accidental shadowing
112
+ *
113
+ * @param id - The type id to look up
114
+ * @returns The ControlType if found, undefined otherwise
115
+ */
116
+ export declare function getBuiltinType(id: string): ControlType | undefined;
117
+ /**
118
+ * Check if a type id is a built-in type.
119
+ *
120
+ * WHY boolean convenience:
121
+ * - Most callers just need yes/no answer
122
+ * - Cleaner than checking getBuiltinType() !== undefined
123
+ *
124
+ * @param id - The type id to check
125
+ * @returns true if the type is built-in
126
+ */
127
+ export declare function isBuiltinType(id: string): boolean;
128
+ //# sourceMappingURL=builtins.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builtins.d.ts","sourceRoot":"","sources":["../src/builtins.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAiC,MAAM,SAAS,CAAC;AA+a1E;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,EAAE,WAAW,EAQtC,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAErD,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,CACV,IAAI,EAAE,WAAW,EACjB,OAAO,CAAC,EAAE;IAAE,aAAa,CAAC,EAAE,OAAO,CAAA;CAAE,KAClC,IAAI,GACR,IAAI,CAIN;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAElE;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAEjD"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * @module defaults
3
+ * @description Default value application for forms and controls
4
+ *
5
+ * ## Purpose
6
+ *
7
+ * Form definitions can be quite minimal:
8
+ *
9
+ * ```typescript
10
+ * { id: 'contact', controls: [{ key: 'email' }] }
11
+ * ```
12
+ *
13
+ * This module fills in sensible defaults:
14
+ *
15
+ * ```typescript
16
+ * {
17
+ * id: 'contact',
18
+ * name: 'Contact', // Prettified from id
19
+ * version: 1, // Default version
20
+ * status: 'active', // Default status
21
+ * controls: [{
22
+ * key: 'email',
23
+ * label: 'Email', // Prettified from key
24
+ * type: 'text', // Default type
25
+ * required: false, // Default required
26
+ * confirmThreshold: 0.8, // Default confidence threshold
27
+ * }],
28
+ * ux: { ... }, // All UX defaults
29
+ * ttl: { ... }, // All TTL defaults
30
+ * nudge: { ... }, // All nudge defaults
31
+ * debug: false, // Default debug off
32
+ * }
33
+ * ```
34
+ *
35
+ * ## When Defaults Apply
36
+ *
37
+ * Defaults are applied:
38
+ *
39
+ * 1. **At Registration**: When a form is registered via FormService
40
+ * 2. **At Build**: When using FormBuilder.build()
41
+ *
42
+ * This ensures:
43
+ * - Minimal definitions work correctly
44
+ * - All optional fields have values
45
+ * - Code can rely on values being present
46
+ *
47
+ * ## Default Values Philosophy
48
+ *
49
+ * Default values were chosen to be:
50
+ *
51
+ * - **Safe**: Won't cause unexpected behavior
52
+ * - **User-Friendly**: Enable features users expect
53
+ * - **Minimal**: Don't add unnecessary restrictions
54
+ *
55
+ * For example:
56
+ * - TTL defaults are generous (14-90 days)
57
+ * - UX features are enabled by default
58
+ * - Required defaults to false (explicit opt-in)
59
+ */
60
+ import type { FormControl, FormDefinition } from "./types";
61
+ /**
62
+ * Apply defaults to a FormControl.
63
+ *
64
+ * Ensures all optional fields have values.
65
+ *
66
+ * @param control - Partial control to complete
67
+ * @returns Complete FormControl with all defaults applied
68
+ */
69
+ export declare function applyControlDefaults(control: Partial<FormControl>): FormControl;
70
+ /**
71
+ * Apply defaults to a FormDefinition.
72
+ *
73
+ * Ensures all optional fields have values and applies
74
+ * defaults to all controls.
75
+ *
76
+ * @param form - Partial form to complete
77
+ * @returns Complete FormDefinition with all defaults applied
78
+ */
79
+ export declare function applyFormDefaults(form: Partial<FormDefinition>): FormDefinition;
80
+ /**
81
+ * Convert snake_case or kebab-case to Title Case.
82
+ *
83
+ * Used to generate human-readable labels from field keys
84
+ * and form names from form IDs.
85
+ *
86
+ * @example
87
+ * prettify('first_name') // "First Name"
88
+ * prettify('email-address') // "Email Address"
89
+ * prettify('userId') // "UserId" (camelCase preserved)
90
+ *
91
+ * @param key - The key to prettify
92
+ * @returns Human-readable title case string
93
+ */
94
+ export declare function prettify(key: string): string;
95
+ //# sourceMappingURL=defaults.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAG3D;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,GAC5B,WAAW,CAmBb;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,OAAO,CAAC,cAAc,CAAC,GAC5B,cAAc,CAwDhB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAQ5C"}