@elizaos/plugin-form 2.0.0-alpha.3 → 2.0.0-alpha.4
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.
- package/dist/index.d.ts +2 -174
- package/dist/{node/index.node.js → index.js} +463 -373
- package/dist/index.js.map +30 -0
- package/package.json +4 -2
- package/dist/actions/restore.d.ts +0 -62
- package/dist/actions/restore.d.ts.map +0 -1
- package/dist/builder.d.ts +0 -320
- package/dist/builder.d.ts.map +0 -1
- package/dist/builtins.d.ts +0 -128
- package/dist/builtins.d.ts.map +0 -1
- package/dist/defaults.d.ts +0 -95
- package/dist/defaults.d.ts.map +0 -1
- package/dist/evaluators/extractor.d.ts +0 -91
- package/dist/evaluators/extractor.d.ts.map +0 -1
- package/dist/extraction.d.ts +0 -105
- package/dist/extraction.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/intent.d.ts +0 -116
- package/dist/intent.d.ts.map +0 -1
- package/dist/node/index.node.js.map +0 -29
- package/dist/providers/context.d.ts +0 -69
- package/dist/providers/context.d.ts.map +0 -1
- package/dist/service.d.ts +0 -407
- package/dist/service.d.ts.map +0 -1
- package/dist/storage.d.ts +0 -228
- package/dist/storage.d.ts.map +0 -1
- package/dist/tasks/nudge.d.ts +0 -89
- package/dist/tasks/nudge.d.ts.map +0 -1
- package/dist/template.d.ts +0 -10
- package/dist/template.d.ts.map +0 -1
- package/dist/ttl.d.ts +0 -144
- package/dist/ttl.d.ts.map +0 -1
- package/dist/types.d.ts +0 -1186
- package/dist/types.d.ts.map +0 -1
- package/dist/validation.d.ts +0 -177
- package/dist/validation.d.ts.map +0 -1
package/dist/storage.d.ts
DELETED
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module storage
|
|
3
|
-
* @description Component-based persistence for form data
|
|
4
|
-
*
|
|
5
|
-
* ## Design Rationale
|
|
6
|
-
*
|
|
7
|
-
* Form data is stored using ElizaOS's Component system because:
|
|
8
|
-
*
|
|
9
|
-
* 1. **Entity-Scoped**: Components belong to entities (users).
|
|
10
|
-
* This naturally scopes form data per-user.
|
|
11
|
-
*
|
|
12
|
-
* 2. **Typed Storage**: Component type field allows different kinds
|
|
13
|
-
* of form data (sessions, submissions, autofill).
|
|
14
|
-
*
|
|
15
|
-
* 3. **No Custom Schema**: Uses existing ElizaOS infrastructure,
|
|
16
|
-
* no need to create database tables.
|
|
17
|
-
*
|
|
18
|
-
* 4. **Room Scoping**: Component type includes roomId for session
|
|
19
|
-
* isolation across rooms.
|
|
20
|
-
*
|
|
21
|
-
* ## Storage Strategy
|
|
22
|
-
*
|
|
23
|
-
* ### Sessions
|
|
24
|
-
* - Stored as components with type: `form_session:{roomId}`
|
|
25
|
-
* - One active session per user per room
|
|
26
|
-
* - Scoping ensures different rooms have different contexts
|
|
27
|
-
*
|
|
28
|
-
* ### Submissions
|
|
29
|
-
* - Stored as components with type: `form_submission:{formId}:{submissionId}`
|
|
30
|
-
* - Immutable records of completed forms
|
|
31
|
-
* - Multiple submissions per user (if form allows)
|
|
32
|
-
*
|
|
33
|
-
* ### Autofill
|
|
34
|
-
* - Stored as components with type: `form_autofill:{formId}`
|
|
35
|
-
* - One autofill record per user per form
|
|
36
|
-
* - Updated on each submission
|
|
37
|
-
*
|
|
38
|
-
* ## Limitations
|
|
39
|
-
*
|
|
40
|
-
* The current implementation has limitations:
|
|
41
|
-
*
|
|
42
|
-
* 1. **No Cross-Entity Queries**: Can't efficiently find all stale
|
|
43
|
-
* sessions across all users. This affects nudge system.
|
|
44
|
-
*
|
|
45
|
-
* 2. **No Indexes**: Component queries are sequential scans.
|
|
46
|
-
* For high-volume usage, consider database-level optimizations.
|
|
47
|
-
*
|
|
48
|
-
* These are acceptable for v1 but noted for future improvement.
|
|
49
|
-
*/
|
|
50
|
-
import type { IAgentRuntime, JsonValue, UUID } from "@elizaos/core";
|
|
51
|
-
import type { FormSession, FormSubmission, FormAutofillData } from "./types";
|
|
52
|
-
/**
|
|
53
|
-
* Get active form session for entity in a specific room.
|
|
54
|
-
*
|
|
55
|
-
* WHY room-scoped:
|
|
56
|
-
* - User might chat in multiple rooms simultaneously
|
|
57
|
-
* - Each room conversation should have its own form context
|
|
58
|
-
* - Discord DM form shouldn't interfere with Telegram form
|
|
59
|
-
*
|
|
60
|
-
* WHY active/ready filter:
|
|
61
|
-
* - Stashed, submitted, cancelled, expired sessions are not "active"
|
|
62
|
-
* - User would need to restore stashed sessions
|
|
63
|
-
*
|
|
64
|
-
* @param runtime - Agent runtime for database access
|
|
65
|
-
* @param entityId - User's entity ID
|
|
66
|
-
* @param roomId - The room to check for active session
|
|
67
|
-
* @returns Active session or null if none
|
|
68
|
-
*/
|
|
69
|
-
export declare function getActiveSession(runtime: IAgentRuntime, entityId: UUID, roomId: UUID): Promise<FormSession | null>;
|
|
70
|
-
/**
|
|
71
|
-
* Get all active sessions for an entity (across all rooms).
|
|
72
|
-
*
|
|
73
|
-
* WHY this exists:
|
|
74
|
-
* - For "you have forms in progress" notifications
|
|
75
|
-
* - For session management UI
|
|
76
|
-
* - Not commonly used in normal flow
|
|
77
|
-
*
|
|
78
|
-
* @param runtime - Agent runtime for database access
|
|
79
|
-
* @param entityId - User's entity ID
|
|
80
|
-
* @returns Array of active sessions (may be empty)
|
|
81
|
-
*/
|
|
82
|
-
export declare function getAllActiveSessions(runtime: IAgentRuntime, entityId: UUID): Promise<FormSession[]>;
|
|
83
|
-
/**
|
|
84
|
-
* Get stashed sessions for an entity.
|
|
85
|
-
*
|
|
86
|
-
* WHY stashed is separate from active:
|
|
87
|
-
* - Stashed sessions are "saved for later"
|
|
88
|
-
* - User must explicitly restore them
|
|
89
|
-
* - Different UX from active sessions
|
|
90
|
-
*
|
|
91
|
-
* @param runtime - Agent runtime for database access
|
|
92
|
-
* @param entityId - User's entity ID
|
|
93
|
-
* @returns Array of stashed sessions (may be empty)
|
|
94
|
-
*/
|
|
95
|
-
export declare function getStashedSessions(runtime: IAgentRuntime, entityId: UUID): Promise<FormSession[]>;
|
|
96
|
-
/**
|
|
97
|
-
* Get a session by ID.
|
|
98
|
-
*
|
|
99
|
-
* WHY by ID:
|
|
100
|
-
* - Needed for operations on specific session
|
|
101
|
-
* - Session ID is stable across room changes
|
|
102
|
-
* - Used by stash/restore when session roomId changes
|
|
103
|
-
*
|
|
104
|
-
* @param runtime - Agent runtime for database access
|
|
105
|
-
* @param entityId - User's entity ID
|
|
106
|
-
* @param sessionId - The session ID to find
|
|
107
|
-
* @returns The session or null if not found
|
|
108
|
-
*/
|
|
109
|
-
export declare function getSessionById(runtime: IAgentRuntime, entityId: UUID, sessionId: string): Promise<FormSession | null>;
|
|
110
|
-
/**
|
|
111
|
-
* Save a form session.
|
|
112
|
-
*
|
|
113
|
-
* Creates new component if none exists, updates otherwise.
|
|
114
|
-
*
|
|
115
|
-
* WHY upsert pattern:
|
|
116
|
-
* - Session is created once, updated many times
|
|
117
|
-
* - Single function handles both cases
|
|
118
|
-
* - Avoids race conditions
|
|
119
|
-
*
|
|
120
|
-
* @param runtime - Agent runtime for database access
|
|
121
|
-
* @param session - Session to save
|
|
122
|
-
*/
|
|
123
|
-
export declare function saveSession(runtime: IAgentRuntime, session: FormSession): Promise<void>;
|
|
124
|
-
/**
|
|
125
|
-
* Delete a session.
|
|
126
|
-
*
|
|
127
|
-
* WHY delete:
|
|
128
|
-
* - Cleanup after submission/cancellation/expiry
|
|
129
|
-
* - Frees up storage
|
|
130
|
-
* - Note: Usually we just change status instead of deleting
|
|
131
|
-
*
|
|
132
|
-
* @param runtime - Agent runtime for database access
|
|
133
|
-
* @param session - Session to delete
|
|
134
|
-
*/
|
|
135
|
-
export declare function deleteSession(runtime: IAgentRuntime, session: FormSession): Promise<void>;
|
|
136
|
-
/**
|
|
137
|
-
* Save a form submission.
|
|
138
|
-
*
|
|
139
|
-
* Submissions are immutable records. Always creates new component.
|
|
140
|
-
*
|
|
141
|
-
* WHY new component per submission:
|
|
142
|
-
* - Submissions are immutable
|
|
143
|
-
* - Multiple submissions allowed (if form permits)
|
|
144
|
-
* - Historical record keeping
|
|
145
|
-
*
|
|
146
|
-
* @param runtime - Agent runtime for database access
|
|
147
|
-
* @param submission - Submission to save
|
|
148
|
-
*/
|
|
149
|
-
export declare function saveSubmission(runtime: IAgentRuntime, submission: FormSubmission): Promise<void>;
|
|
150
|
-
/**
|
|
151
|
-
* Get submissions for an entity, optionally filtered by form ID.
|
|
152
|
-
*
|
|
153
|
-
* WHY optional formId:
|
|
154
|
-
* - List all submissions: no formId
|
|
155
|
-
* - List submissions for specific form: with formId
|
|
156
|
-
*
|
|
157
|
-
* @param runtime - Agent runtime for database access
|
|
158
|
-
* @param entityId - User's entity ID
|
|
159
|
-
* @param formId - Optional form ID filter
|
|
160
|
-
* @returns Array of submissions, newest first
|
|
161
|
-
*/
|
|
162
|
-
export declare function getSubmissions(runtime: IAgentRuntime, entityId: UUID, formId?: string): Promise<FormSubmission[]>;
|
|
163
|
-
/**
|
|
164
|
-
* Get a specific submission by ID.
|
|
165
|
-
*
|
|
166
|
-
* @param runtime - Agent runtime for database access
|
|
167
|
-
* @param entityId - User's entity ID
|
|
168
|
-
* @param submissionId - The submission ID to find
|
|
169
|
-
* @returns The submission or null if not found
|
|
170
|
-
*/
|
|
171
|
-
export declare function getSubmissionById(runtime: IAgentRuntime, entityId: UUID, submissionId: string): Promise<FormSubmission | null>;
|
|
172
|
-
/**
|
|
173
|
-
* Get autofill data for a user's form.
|
|
174
|
-
*
|
|
175
|
-
* WHY autofill:
|
|
176
|
-
* - Users filling repeat forms want saved values
|
|
177
|
-
* - Reduces friction for common fields (name, email, address)
|
|
178
|
-
*
|
|
179
|
-
* @param runtime - Agent runtime for database access
|
|
180
|
-
* @param entityId - User's entity ID
|
|
181
|
-
* @param formId - Form definition ID
|
|
182
|
-
* @returns Autofill data or null if none saved
|
|
183
|
-
*/
|
|
184
|
-
export declare function getAutofillData(runtime: IAgentRuntime, entityId: UUID, formId: string): Promise<FormAutofillData | null>;
|
|
185
|
-
/**
|
|
186
|
-
* Save autofill data for a user's form.
|
|
187
|
-
*
|
|
188
|
-
* Overwrites existing autofill data for the form.
|
|
189
|
-
*
|
|
190
|
-
* WHY overwrite:
|
|
191
|
-
* - Most recent submission has most current data
|
|
192
|
-
* - User's email might have changed
|
|
193
|
-
* - Only one autofill record per form needed
|
|
194
|
-
*
|
|
195
|
-
* @param runtime - Agent runtime for database access
|
|
196
|
-
* @param entityId - User's entity ID
|
|
197
|
-
* @param formId - Form definition ID
|
|
198
|
-
* @param values - Field values to save for autofill
|
|
199
|
-
*/
|
|
200
|
-
export declare function saveAutofillData(runtime: IAgentRuntime, entityId: UUID, formId: string, values: Record<string, JsonValue>): Promise<void>;
|
|
201
|
-
/**
|
|
202
|
-
* Get all stale sessions (for nudge system).
|
|
203
|
-
*
|
|
204
|
-
* LIMITATION: This requires iterating over all entities, which is not
|
|
205
|
-
* efficient with current ElizaOS component system. In production,
|
|
206
|
-
* this would need a database-level query.
|
|
207
|
-
*
|
|
208
|
-
* WHY this is here:
|
|
209
|
-
* - Documents the need for this functionality
|
|
210
|
-
* - Placeholder for future implementation
|
|
211
|
-
* - Nudge system can call this when entity context is available
|
|
212
|
-
*
|
|
213
|
-
* @param runtime - Agent runtime for database access
|
|
214
|
-
* @param afterInactiveMs - Inactivity threshold in milliseconds
|
|
215
|
-
* @returns Array of stale sessions (currently returns empty array)
|
|
216
|
-
*/
|
|
217
|
-
export declare function getStaleSessions(runtime: IAgentRuntime, afterInactiveMs: number): Promise<FormSession[]>;
|
|
218
|
-
/**
|
|
219
|
-
* Get sessions expiring within a time window.
|
|
220
|
-
*
|
|
221
|
-
* Same limitation as getStaleSessions.
|
|
222
|
-
*
|
|
223
|
-
* @param runtime - Agent runtime for database access
|
|
224
|
-
* @param withinMs - Time window in milliseconds
|
|
225
|
-
* @returns Array of expiring sessions (currently returns empty array)
|
|
226
|
-
*/
|
|
227
|
-
export declare function getExpiringSessions(runtime: IAgentRuntime, withinMs: number): Promise<FormSession[]>;
|
|
228
|
-
//# sourceMappingURL=storage.d.ts.map
|
package/dist/storage.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AAEH,OAAO,KAAK,EAAa,aAAa,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE/E,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AA0D7E;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,aAAa,EACtB,QAAQ,EAAE,IAAI,EACd,MAAM,EAAE,IAAI,GACX,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAkB7B;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,aAAa,EACtB,QAAQ,EAAE,IAAI,GACb,OAAO,CAAC,WAAW,EAAE,CAAC,CAiBxB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,aAAa,EACtB,QAAQ,EAAE,IAAI,GACb,OAAO,CAAC,WAAW,EAAE,CAAC,CAgBxB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,aAAa,EACtB,QAAQ,EAAE,IAAI,EACd,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAe7B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE,aAAa,EACtB,OAAO,EAAE,WAAW,GACnB,OAAO,CAAC,IAAI,CAAC,CAyBf;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,aAAa,EACtB,OAAO,EAAE,WAAW,GACnB,OAAO,CAAC,IAAI,CAAC,CAOf;AAMD;;;;;;;;;;;;GAYG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,aAAa,EACtB,UAAU,EAAE,cAAc,GACzB,OAAO,CAAC,IAAI,CAAC,CAmBf;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,aAAa,EACtB,QAAQ,EAAE,IAAI,EACd,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,cAAc,EAAE,CAAC,CAqB3B;AAED;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,aAAa,EACtB,QAAQ,EAAE,IAAI,EACd,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAehC;AAMD;;;;;;;;;;;GAWG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,aAAa,EACtB,QAAQ,EAAE,IAAI,EACd,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAOlC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,aAAa,EACtB,QAAQ,EAAE,IAAI,EACd,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAChC,OAAO,CAAC,IAAI,CAAC,CA6Bf;AAMD;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,aAAa,EACtB,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,WAAW,EAAE,CAAC,CAWxB;AAED;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,aAAa,EACtB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,WAAW,EAAE,CAAC,CAKxB"}
|
package/dist/tasks/nudge.d.ts
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module tasks/nudge
|
|
3
|
-
* @description Background task for nudging stale form sessions
|
|
4
|
-
*
|
|
5
|
-
* ## Purpose
|
|
6
|
-
*
|
|
7
|
-
* Users start forms and forget about them. The nudge system sends
|
|
8
|
-
* gentle reminders:
|
|
9
|
-
*
|
|
10
|
-
* 1. **Stale Sessions**: "You have an unfinished registration form..."
|
|
11
|
-
* 2. **Expiring Sessions**: "Your form will expire in 24 hours..."
|
|
12
|
-
* 3. **Expired Sessions**: Mark as expired, trigger onExpire hook
|
|
13
|
-
*
|
|
14
|
-
* ## Architecture
|
|
15
|
-
*
|
|
16
|
-
* The nudge system has two components:
|
|
17
|
-
*
|
|
18
|
-
* ### 1. Task Worker (formNudgeWorker)
|
|
19
|
-
*
|
|
20
|
-
* A background task that periodically checks for stale sessions.
|
|
21
|
-
*
|
|
22
|
-
* **Limitation**: The current ElizaOS component system doesn't support
|
|
23
|
-
* efficient cross-entity queries. The worker needs to know which entities
|
|
24
|
-
* to check.
|
|
25
|
-
*
|
|
26
|
-
* ### 2. Per-Entity Processing (processEntityNudges)
|
|
27
|
-
*
|
|
28
|
-
* Called with a specific entity ID to process that user's sessions.
|
|
29
|
-
* This can be triggered:
|
|
30
|
-
* - After any form interaction (opportunistic)
|
|
31
|
-
* - By a scheduled job with known entity IDs
|
|
32
|
-
* - By admin action
|
|
33
|
-
*
|
|
34
|
-
* ## Nudge Rules
|
|
35
|
-
*
|
|
36
|
-
* 1. Only nudge stashed sessions (not active ones)
|
|
37
|
-
* 2. Wait configurable hours before first nudge (default: 48)
|
|
38
|
-
* 3. Maximum nudges per session (default: 3)
|
|
39
|
-
* 4. At least 24 hours between nudges
|
|
40
|
-
*
|
|
41
|
-
* ## Expiration Warnings
|
|
42
|
-
*
|
|
43
|
-
* Before a session expires, we warn the user:
|
|
44
|
-
* - 24 hours before expiration
|
|
45
|
-
* - Only warn once per session (expirationWarned flag)
|
|
46
|
-
*
|
|
47
|
-
* ## Sending Messages
|
|
48
|
-
*
|
|
49
|
-
* The nudge system uses `runtime.sendMessageToRoom` if available.
|
|
50
|
-
* Not all runtimes support this - it's a best-effort feature.
|
|
51
|
-
*
|
|
52
|
-
* ## Future Improvements
|
|
53
|
-
*
|
|
54
|
-
* 1. Database-level query for stale sessions
|
|
55
|
-
* 2. Integration with notification system
|
|
56
|
-
* 3. User preferences for nudge frequency
|
|
57
|
-
*/
|
|
58
|
-
import type { IAgentRuntime, TaskWorker } from "@elizaos/core";
|
|
59
|
-
/**
|
|
60
|
-
* Nudge Task Worker
|
|
61
|
-
*
|
|
62
|
-
* Periodically checks for stale form sessions and:
|
|
63
|
-
* 1. Sends nudge messages for inactive sessions
|
|
64
|
-
* 2. Sends expiration warnings for sessions about to expire
|
|
65
|
-
* 3. Cleans up expired sessions
|
|
66
|
-
*
|
|
67
|
-
* WHY a task worker:
|
|
68
|
-
* - Runs independently of user interaction
|
|
69
|
-
* - Can be scheduled to run periodically
|
|
70
|
-
* - Handles multiple entities efficiently
|
|
71
|
-
*/
|
|
72
|
-
export declare const formNudgeWorker: TaskWorker;
|
|
73
|
-
/**
|
|
74
|
-
* Process nudges and expirations for a specific entity.
|
|
75
|
-
*
|
|
76
|
-
* This function can be called when we have an entity context.
|
|
77
|
-
* For example, it could be triggered after any form interaction.
|
|
78
|
-
*
|
|
79
|
-
* WHY separate function:
|
|
80
|
-
* - Can be called opportunistically
|
|
81
|
-
* - Avoids cross-entity query limitation
|
|
82
|
-
* - Easy to test with specific entity
|
|
83
|
-
*
|
|
84
|
-
* @param runtime - Agent runtime for service access
|
|
85
|
-
* @param entityId - The entity to process
|
|
86
|
-
*/
|
|
87
|
-
export declare function processEntityNudges(runtime: IAgentRuntime, entityId: string): Promise<void>;
|
|
88
|
-
export default formNudgeWorker;
|
|
89
|
-
//# sourceMappingURL=nudge.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nudge.d.ts","sourceRoot":"","sources":["../../src/tasks/nudge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAK/D;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,eAAe,EAAE,UA4C7B,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,aAAa,EACtB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CA+Df;AAoED,eAAe,eAAe,CAAC"}
|
package/dist/template.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module template
|
|
3
|
-
* @description Simple template resolution for form-controlled prompts
|
|
4
|
-
*/
|
|
5
|
-
import type { FormControl, FormSession } from "./types";
|
|
6
|
-
export type TemplateValues = Record<string, string>;
|
|
7
|
-
export declare function buildTemplateValues(session: FormSession): TemplateValues;
|
|
8
|
-
export declare function renderTemplate(template: string | undefined, values: TemplateValues): string | undefined;
|
|
9
|
-
export declare function resolveControlTemplates(control: FormControl, values: TemplateValues): FormControl;
|
|
10
|
-
//# sourceMappingURL=template.d.ts.map
|
package/dist/template.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../src/template.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAExD,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAIpD,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,WAAW,GAAG,cAAc,CAwBxE;AAED,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,MAAM,EAAE,cAAc,GACrB,MAAM,GAAG,SAAS,CASpB;AAED,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,WAAW,EACpB,MAAM,EAAE,cAAc,GACrB,WAAW,CAuBb"}
|
package/dist/ttl.d.ts
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module ttl
|
|
3
|
-
* @description Smart TTL (Time-To-Live) management for form sessions
|
|
4
|
-
*
|
|
5
|
-
* ## Design Philosophy
|
|
6
|
-
*
|
|
7
|
-
* Traditional form systems delete abandoned forms after a fixed time.
|
|
8
|
-
* This fails users who invest significant effort:
|
|
9
|
-
*
|
|
10
|
-
* - User A: Opens form, immediately abandons → 24h retention is fine
|
|
11
|
-
* - User B: Spends 2 hours filling complex form → 24h retention loses their work!
|
|
12
|
-
*
|
|
13
|
-
* ## Effort-Based TTL
|
|
14
|
-
*
|
|
15
|
-
* This module calculates TTL based on user effort:
|
|
16
|
-
*
|
|
17
|
-
* ```
|
|
18
|
-
* TTL = clamp(minDays, effortDays, maxDays)
|
|
19
|
-
*
|
|
20
|
-
* where:
|
|
21
|
-
* effortDays = minutesSpent * effortMultiplier
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* Default values:
|
|
25
|
-
* - minDays: 14 (two weeks minimum)
|
|
26
|
-
* - maxDays: 90 (three months maximum)
|
|
27
|
-
* - effortMultiplier: 0.5 (10 minutes = 5 extra days)
|
|
28
|
-
*
|
|
29
|
-
* ## Examples
|
|
30
|
-
*
|
|
31
|
-
* | Time Spent | Extra Days | Total TTL |
|
|
32
|
-
* |------------|------------|-----------|
|
|
33
|
-
* | 0 min | 0 | 14 days |
|
|
34
|
-
* | 10 min | 5 | 14 days |
|
|
35
|
-
* | 30 min | 15 | 15 days |
|
|
36
|
-
* | 2 hours | 60 | 60 days |
|
|
37
|
-
* | 4 hours | 120 | 90 days |
|
|
38
|
-
*
|
|
39
|
-
* ## Nudge System
|
|
40
|
-
*
|
|
41
|
-
* The nudge system sends reminders for stale forms:
|
|
42
|
-
*
|
|
43
|
-
* 1. After 48 hours of inactivity (configurable)
|
|
44
|
-
* 2. Maximum 3 nudges (configurable)
|
|
45
|
-
* 3. At least 24 hours between nudges
|
|
46
|
-
*
|
|
47
|
-
* ## Expiration Warnings
|
|
48
|
-
*
|
|
49
|
-
* Before a session expires, we warn the user:
|
|
50
|
-
*
|
|
51
|
-
* - 24 hours before expiration
|
|
52
|
-
* - "Your form will expire in 1 day. Say 'resume' to keep working."
|
|
53
|
-
*
|
|
54
|
-
* This gives users a chance to save their work.
|
|
55
|
-
*/
|
|
56
|
-
import type { FormDefinition, FormSession } from "./types";
|
|
57
|
-
/**
|
|
58
|
-
* Calculate TTL based on user effort.
|
|
59
|
-
*
|
|
60
|
-
* The more time a user spends on a form, the longer we keep it.
|
|
61
|
-
* This prevents losing significant work while still cleaning up abandoned forms.
|
|
62
|
-
*
|
|
63
|
-
* WHY effort-based:
|
|
64
|
-
* - Respects user investment
|
|
65
|
-
* - Automatic cleanup of abandoned forms
|
|
66
|
-
* - No manual expiration management needed
|
|
67
|
-
*
|
|
68
|
-
* @param session - Current session with effort tracking
|
|
69
|
-
* @param form - Form definition with TTL configuration
|
|
70
|
-
* @returns Expiration timestamp (milliseconds since epoch)
|
|
71
|
-
*/
|
|
72
|
-
export declare function calculateTTL(session: FormSession, form?: FormDefinition): number;
|
|
73
|
-
/**
|
|
74
|
-
* Check if session should be nudged.
|
|
75
|
-
*
|
|
76
|
-
* Nudges are gentle reminders for stashed or inactive forms.
|
|
77
|
-
*
|
|
78
|
-
* WHY nudge:
|
|
79
|
-
* - Users forget about forms they started
|
|
80
|
-
* - Gentle reminders increase completion
|
|
81
|
-
* - But too many nudges are annoying
|
|
82
|
-
*
|
|
83
|
-
* @param session - Session to check
|
|
84
|
-
* @param form - Form definition with nudge configuration
|
|
85
|
-
* @returns true if a nudge should be sent
|
|
86
|
-
*/
|
|
87
|
-
export declare function shouldNudge(session: FormSession, form?: FormDefinition): boolean;
|
|
88
|
-
/**
|
|
89
|
-
* Check if session is expiring soon.
|
|
90
|
-
*
|
|
91
|
-
* Used to send expiration warnings before session is deleted.
|
|
92
|
-
*
|
|
93
|
-
* @param session - Session to check
|
|
94
|
-
* @param withinMs - Time window in milliseconds
|
|
95
|
-
* @returns true if session expires within the window
|
|
96
|
-
*/
|
|
97
|
-
export declare function isExpiringSoon(session: FormSession, withinMs: number): boolean;
|
|
98
|
-
/**
|
|
99
|
-
* Check if session has expired.
|
|
100
|
-
*
|
|
101
|
-
* @param session - Session to check
|
|
102
|
-
* @returns true if session has passed its expiration time
|
|
103
|
-
*/
|
|
104
|
-
export declare function isExpired(session: FormSession): boolean;
|
|
105
|
-
/**
|
|
106
|
-
* Check if we should confirm before canceling.
|
|
107
|
-
*
|
|
108
|
-
* High-effort sessions deserve a confirmation before abandonment.
|
|
109
|
-
*
|
|
110
|
-
* WHY confirm:
|
|
111
|
-
* - Prevent accidental loss of significant work
|
|
112
|
-
* - "Are you sure?" for forms user invested in
|
|
113
|
-
*
|
|
114
|
-
* @param session - Session to check
|
|
115
|
-
* @returns true if cancel should require confirmation
|
|
116
|
-
*/
|
|
117
|
-
export declare function shouldConfirmCancel(session: FormSession): boolean;
|
|
118
|
-
/**
|
|
119
|
-
* Format remaining time for user display.
|
|
120
|
-
*
|
|
121
|
-
* Produces human-readable strings like:
|
|
122
|
-
* - "14 days"
|
|
123
|
-
* - "3 hours"
|
|
124
|
-
* - "45 minutes"
|
|
125
|
-
* - "expired"
|
|
126
|
-
*
|
|
127
|
-
* @param session - Session to format
|
|
128
|
-
* @returns Human-readable time remaining
|
|
129
|
-
*/
|
|
130
|
-
export declare function formatTimeRemaining(session: FormSession): string;
|
|
131
|
-
/**
|
|
132
|
-
* Format effort for user display.
|
|
133
|
-
*
|
|
134
|
-
* Produces human-readable strings like:
|
|
135
|
-
* - "just started"
|
|
136
|
-
* - "5 minutes"
|
|
137
|
-
* - "2 hours"
|
|
138
|
-
* - "1h 30m"
|
|
139
|
-
*
|
|
140
|
-
* @param session - Session to format
|
|
141
|
-
* @returns Human-readable effort description
|
|
142
|
-
*/
|
|
143
|
-
export declare function formatEffort(session: FormSession): string;
|
|
144
|
-
//# sourceMappingURL=ttl.d.ts.map
|
package/dist/ttl.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ttl.d.ts","sourceRoot":"","sources":["../src/ttl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAG3D;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,WAAW,EACpB,IAAI,CAAC,EAAE,cAAc,GACpB,MAAM,CAwBR;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,WAAW,EACpB,IAAI,CAAC,EAAE,cAAc,GACpB,OAAO,CAsCT;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,WAAW,EACpB,QAAQ,EAAE,MAAM,GACf,OAAO,CAET;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAEvD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAKjE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,CAuBhE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,CAmBzD"}
|