@elizaos/plugin-form 2.0.0-alpha.1 → 2.0.0-alpha.11
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/chunk-4B5QLNVA.js +187 -0
- package/dist/chunk-ARWZY3NX.js +284 -0
- package/dist/chunk-R4VBS2YK.js +1597 -0
- package/dist/chunk-TBCL2ILB.js +172 -0
- package/dist/chunk-WY4WK3HD.js +57 -0
- package/dist/chunk-XHECCAUT.js +544 -0
- package/dist/chunk-YTWANJ3R.js +64 -0
- package/dist/context-MHPFYZZ2.js +9 -0
- package/dist/extractor-UWASKXKD.js +11 -0
- package/dist/index.d.ts +3057 -19
- package/dist/index.js +428 -2826
- package/dist/restore-S7JLME4H.js +9 -0
- package/dist/service-TCCXKV3T.js +7 -0
- package/package.json +33 -23
- package/LICENSE +0 -21
- package/README.md +0 -846
- 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/index.js.map +0 -30
- package/dist/intent.d.ts +0 -116
- package/dist/intent.d.ts.map +0 -1
- package/dist/providers/context.d.ts +0 -69
- package/dist/providers/context.d.ts.map +0 -1
- package/dist/service.d.ts +0 -417
- 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 -1214
- package/dist/types.d.ts.map +0 -1
- package/dist/validation.d.ts +0 -156
- package/dist/validation.d.ts.map +0 -1
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import {
|
|
2
|
+
quickIntentDetect
|
|
3
|
+
} from "./chunk-YTWANJ3R.js";
|
|
4
|
+
|
|
5
|
+
// src/actions/restore.ts
|
|
6
|
+
import {
|
|
7
|
+
logger
|
|
8
|
+
} from "@elizaos/core";
|
|
9
|
+
var formRestoreAction = {
|
|
10
|
+
name: "FORM_RESTORE",
|
|
11
|
+
similes: ["RESUME_FORM", "CONTINUE_FORM"],
|
|
12
|
+
description: "Restore a previously stashed form session",
|
|
13
|
+
/**
|
|
14
|
+
* Validate: Only trigger for restore intent with stashed sessions.
|
|
15
|
+
*
|
|
16
|
+
* Fast path: Uses quickIntentDetect for English keywords.
|
|
17
|
+
* Evaluator handles non-English via LLM.
|
|
18
|
+
*
|
|
19
|
+
* @returns true if action should run
|
|
20
|
+
*/
|
|
21
|
+
validate: async (runtime, message, _state) => {
|
|
22
|
+
try {
|
|
23
|
+
const text = message.content?.text || "";
|
|
24
|
+
const intent = quickIntentDetect(text);
|
|
25
|
+
if (intent !== "restore") {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
const formService = runtime.getService("FORM");
|
|
29
|
+
if (!formService) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
const entityId = message.entityId;
|
|
33
|
+
if (!entityId) return false;
|
|
34
|
+
const stashed = await formService.getStashedSessions(entityId);
|
|
35
|
+
return stashed.length > 0;
|
|
36
|
+
} catch (error) {
|
|
37
|
+
logger.error("[FormRestoreAction] Validation error:", String(error));
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
/**
|
|
42
|
+
* Handler: Restore the most recent stashed session.
|
|
43
|
+
*
|
|
44
|
+
* 1. Check for conflicts (active session in room)
|
|
45
|
+
* 2. Restore the session
|
|
46
|
+
* 3. Generate summary response
|
|
47
|
+
*
|
|
48
|
+
* @returns ActionResult with success status and session data
|
|
49
|
+
*/
|
|
50
|
+
handler: async (runtime, message, _state, _options, callback) => {
|
|
51
|
+
try {
|
|
52
|
+
const formService = runtime.getService("FORM");
|
|
53
|
+
if (!formService) {
|
|
54
|
+
await callback?.({
|
|
55
|
+
text: "Sorry, I couldn't find the form service."
|
|
56
|
+
});
|
|
57
|
+
return { success: false };
|
|
58
|
+
}
|
|
59
|
+
const entityId = message.entityId;
|
|
60
|
+
const roomId = message.roomId;
|
|
61
|
+
if (!entityId || !roomId) {
|
|
62
|
+
await callback?.({
|
|
63
|
+
text: "Sorry, I couldn't identify you."
|
|
64
|
+
});
|
|
65
|
+
return { success: false };
|
|
66
|
+
}
|
|
67
|
+
const existing = await formService.getActiveSession(entityId, roomId);
|
|
68
|
+
if (existing) {
|
|
69
|
+
const form2 = formService.getForm(existing.formId);
|
|
70
|
+
await callback?.({
|
|
71
|
+
text: `You already have an active form: "${form2?.name || existing.formId}". Would you like to continue with that one, or should I save it and restore your other form?`
|
|
72
|
+
});
|
|
73
|
+
return { success: false };
|
|
74
|
+
}
|
|
75
|
+
const stashed = await formService.getStashedSessions(entityId);
|
|
76
|
+
if (stashed.length === 0) {
|
|
77
|
+
await callback?.({
|
|
78
|
+
text: "You don't have any saved forms to resume."
|
|
79
|
+
});
|
|
80
|
+
return { success: false };
|
|
81
|
+
}
|
|
82
|
+
const sessionToRestore = stashed.sort((a, b) => b.updatedAt - a.updatedAt)[0];
|
|
83
|
+
const session = await formService.restore(sessionToRestore.id, entityId);
|
|
84
|
+
const form = formService.getForm(session.formId);
|
|
85
|
+
const context = formService.getSessionContext(session);
|
|
86
|
+
let responseText = `I've restored your "${form?.name || session.formId}" form. `;
|
|
87
|
+
responseText += `You're ${context.progress}% complete. `;
|
|
88
|
+
if (context.filledFields.length > 0) {
|
|
89
|
+
responseText += `
|
|
90
|
+
|
|
91
|
+
Here's what I have so far:
|
|
92
|
+
`;
|
|
93
|
+
for (const field of context.filledFields) {
|
|
94
|
+
responseText += `\u2022 ${field.label}: ${field.displayValue}
|
|
95
|
+
`;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (context.nextField) {
|
|
99
|
+
responseText += `
|
|
100
|
+
Let's continue with ${context.nextField.label}.`;
|
|
101
|
+
if (context.nextField.askPrompt) {
|
|
102
|
+
responseText += ` ${context.nextField.askPrompt}`;
|
|
103
|
+
}
|
|
104
|
+
} else if (context.status === "ready") {
|
|
105
|
+
responseText += `
|
|
106
|
+
Everything looks complete! Ready to submit?`;
|
|
107
|
+
}
|
|
108
|
+
await callback?.({
|
|
109
|
+
text: responseText
|
|
110
|
+
});
|
|
111
|
+
return {
|
|
112
|
+
success: true,
|
|
113
|
+
data: {
|
|
114
|
+
sessionId: session.id,
|
|
115
|
+
formId: session.formId,
|
|
116
|
+
progress: context.progress
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
} catch (error) {
|
|
120
|
+
logger.error("[FormRestoreAction] Handler error:", String(error));
|
|
121
|
+
await callback?.({
|
|
122
|
+
text: "Sorry, I couldn't restore your form. Please try again."
|
|
123
|
+
});
|
|
124
|
+
return { success: false };
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
// Example conversations for training/documentation
|
|
128
|
+
examples: [
|
|
129
|
+
[
|
|
130
|
+
{
|
|
131
|
+
name: "{{user1}}",
|
|
132
|
+
content: { text: "Resume my form" }
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
name: "{{agentName}}",
|
|
136
|
+
content: {
|
|
137
|
+
text: "I've restored your form. Let's continue where you left off."
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
],
|
|
141
|
+
[
|
|
142
|
+
{
|
|
143
|
+
name: "{{user1}}",
|
|
144
|
+
content: { text: "Continue with my registration" }
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
name: "{{agentName}}",
|
|
148
|
+
content: {
|
|
149
|
+
text: "I've restored your Registration form. You're 60% complete."
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
],
|
|
153
|
+
[
|
|
154
|
+
{
|
|
155
|
+
name: "{{user1}}",
|
|
156
|
+
content: { text: "Pick up where I left off" }
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
name: "{{agentName}}",
|
|
160
|
+
content: {
|
|
161
|
+
text: "I've restored your form. Here's what you have so far..."
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
]
|
|
165
|
+
]
|
|
166
|
+
};
|
|
167
|
+
var restore_default = formRestoreAction;
|
|
168
|
+
|
|
169
|
+
export {
|
|
170
|
+
formRestoreAction,
|
|
171
|
+
restore_default
|
|
172
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// src/template.ts
|
|
2
|
+
var TEMPLATE_PATTERN = /\{\{\s*([a-zA-Z0-9_.-]+)\s*\}\}/g;
|
|
3
|
+
function buildTemplateValues(session) {
|
|
4
|
+
const values = {};
|
|
5
|
+
for (const [key, state] of Object.entries(session.fields)) {
|
|
6
|
+
const value = state.value;
|
|
7
|
+
if (typeof value === "string") {
|
|
8
|
+
values[key] = value;
|
|
9
|
+
} else if (typeof value === "number" || typeof value === "boolean") {
|
|
10
|
+
values[key] = String(value);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
const context = session.context;
|
|
14
|
+
if (context && typeof context === "object" && !Array.isArray(context)) {
|
|
15
|
+
for (const [key, value] of Object.entries(context)) {
|
|
16
|
+
if (typeof value === "string") {
|
|
17
|
+
values[key] = value;
|
|
18
|
+
} else if (typeof value === "number" || typeof value === "boolean") {
|
|
19
|
+
values[key] = String(value);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return values;
|
|
24
|
+
}
|
|
25
|
+
function renderTemplate(template, values) {
|
|
26
|
+
if (!template) {
|
|
27
|
+
return template;
|
|
28
|
+
}
|
|
29
|
+
return template.replace(TEMPLATE_PATTERN, (match, key) => {
|
|
30
|
+
const replacement = values[key];
|
|
31
|
+
return replacement !== void 0 ? replacement : match;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function resolveControlTemplates(control, values) {
|
|
35
|
+
const resolvedOptions = control.options?.map((option) => ({
|
|
36
|
+
...option,
|
|
37
|
+
label: renderTemplate(option.label, values) ?? option.label,
|
|
38
|
+
description: renderTemplate(option.description, values)
|
|
39
|
+
}));
|
|
40
|
+
const resolvedFields = control.fields?.map((field) => resolveControlTemplates(field, values));
|
|
41
|
+
return {
|
|
42
|
+
...control,
|
|
43
|
+
label: renderTemplate(control.label, values) ?? control.label,
|
|
44
|
+
description: renderTemplate(control.description, values),
|
|
45
|
+
askPrompt: renderTemplate(control.askPrompt, values),
|
|
46
|
+
example: renderTemplate(control.example, values),
|
|
47
|
+
extractHints: control.extractHints?.map((hint) => renderTemplate(hint, values) ?? hint),
|
|
48
|
+
options: resolvedOptions,
|
|
49
|
+
fields: resolvedFields ?? control.fields
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export {
|
|
54
|
+
buildTemplateValues,
|
|
55
|
+
renderTemplate,
|
|
56
|
+
resolveControlTemplates
|
|
57
|
+
};
|