@elizaos/plugin-form 2.0.0-alpha.9 → 2.0.3-beta.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Shaw Walters and elizaOS Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,134 @@
1
+ # @elizaos/plugin-form
2
+
3
+ Conversational forms for Eliza agents. Define structured data-collection workflows; the agent extracts values from natural conversation, tracks completion, and delivers a typed `FormSubmission` when all required fields are filled.
4
+
5
+ ## What it does
6
+
7
+ - **Defines forms** — a `FormDefinition` describes the fields to collect (`FormControl[]`), lifecycle hooks, TTL settings, and UX rules (undo, skip, autofill).
8
+ - **Tracks sessions** — one `FormSession` per user per room. Sessions survive topic changes and can be stashed and resumed later.
9
+ - **Extracts field values via LLM** — the post-turn evaluator detects user intent and pulls values from conversational messages, handling uncertain extractions with a confirm step.
10
+ - **Supports composite and external control types** — composite types (e.g. address) have subfields that must all fill before the parent is complete; external types (e.g. payment) await asynchronous confirmation from another service before marking the field filled.
11
+ - **Effort-aware retention** — session TTL scales with how long the user has invested (default 14–90 days).
12
+
13
+ ## Capabilities added to an Eliza agent
14
+
15
+ | Capability | How |
16
+ |---|---|
17
+ | FORM\_CONTEXT provider | Injects current form progress into every agent turn — filled/missing fields, uncertain extractions, pending external fields, and a single action directive |
18
+ | FORM action | `action=restore` rehydrates the most recent stashed form before the agent responds. **Not auto-registered** — import `formAction` from `@elizaos/plugin-form` and add it to your consuming plugin's `actions` array to activate it. |
19
+ | Form evaluator | Post-turn: detects submit / stash / cancel / undo / skip / autofill / fill\_form intents and updates session state |
20
+ | FormService | Singleton service: register forms and custom control types, start/manage sessions, submit, stash, restore |
21
+
22
+ ## Installation
23
+
24
+ Add the plugin to your agent character config:
25
+
26
+ ```json
27
+ {
28
+ "plugins": ["@elizaos/plugin-form"],
29
+ "features": {
30
+ "form": true
31
+ }
32
+ }
33
+ ```
34
+
35
+ The plugin auto-enables when `config.features.form` is truthy (`true`, or an object whose `enabled` is not `false`). No environment variables are required.
36
+
37
+ ## Built-in field types
38
+
39
+ `text`, `number`, `email`, `boolean`, `select`, `date`, `file`
40
+
41
+ Custom types are registered at runtime via `FormService.registerControlType()`.
42
+
43
+ ## Registering a form (consuming plugin example)
44
+
45
+ ```typescript
46
+ import type { FormDefinition } from '@elizaos/plugin-form';
47
+
48
+ const onboardingForm: FormDefinition = {
49
+ id: 'onboard',
50
+ name: 'Onboarding',
51
+ controls: [
52
+ { key: 'name', label: 'Full Name', type: 'text', required: true },
53
+ { key: 'email', label: 'Email', type: 'email', required: true },
54
+ { key: 'role', label: 'Role', type: 'select', required: false,
55
+ options: [{ value: 'dev', label: 'Developer' }, { value: 'pm', label: 'Product' }] },
56
+ ],
57
+ hooks: { onSubmit: 'handle_onboarding_submission' },
58
+ };
59
+
60
+ // In your plugin's start() or action handler:
61
+ const formService = runtime.getService('FORM');
62
+ formService.registerForm(onboardingForm);
63
+ await formService.startSession('onboard', entityId, roomId);
64
+ ```
65
+
66
+ Register a task worker to handle the submission:
67
+
68
+ ```typescript
69
+ runtime.registerTaskWorker({
70
+ name: 'handle_onboarding_submission',
71
+ execute: async (runtime, { submission }) => {
72
+ // submission.values, submission.mappedValues, submission.entityId, etc.
73
+ },
74
+ });
75
+ ```
76
+
77
+ ## Registering a custom control type
78
+
79
+ ```typescript
80
+ // Simple type
81
+ formService.registerControlType({
82
+ id: 'phone',
83
+ validate: (v) => ({ valid: /^\+?[\d\s-]{10,}$/.test(String(v)) }),
84
+ extractionPrompt: 'a phone number with country code',
85
+ });
86
+
87
+ // External type (async confirmation required)
88
+ formService.registerControlType({
89
+ id: 'payment',
90
+ getSubControls: () => [
91
+ { key: 'amount', type: 'number', label: 'Amount', required: true },
92
+ { key: 'currency', type: 'select', label: 'Currency', required: true,
93
+ options: [{ value: 'SOL', label: 'SOL' }, { value: 'USDC', label: 'USDC' }] },
94
+ ],
95
+ activate: async (ctx) => {
96
+ // Return instructions and a reference for matching the external event
97
+ return { instructions: 'Send funds to ...', reference: 'memo-xyz', address: '...' };
98
+ },
99
+ });
100
+ ```
101
+
102
+ When all subfields are filled the evaluator automatically calls `activateExternalField()`. Your service calls `formService.confirmExternalField(sessionId, entityId, field, value, externalData)` when confirmation arrives.
103
+
104
+ ## FormDefinition reference (key fields)
105
+
106
+ | Field | Type | Default | Description |
107
+ |---|---|---|---|
108
+ | `id` | string | required | Unique form identifier |
109
+ | `name` | string | required | Human-readable name |
110
+ | `controls` | FormControl[] | required | Fields to collect |
111
+ | `status` | `draft\|active\|deprecated` | `active` | Draft forms cannot be started |
112
+ | `allowMultiple` | boolean | `false` | Allow multiple submissions per user |
113
+ | `hooks.onStart/onSubmit/onCancel/onReady/onFieldChange/onExpire` | string | — | Task worker names |
114
+ | `ttl.minDays` / `ttl.maxDays` | number | 14 / 90 | Retention bounds |
115
+ | `ttl.effortMultiplier` | number | 0.5 | Extra days per minute of interaction |
116
+ | `ux.allowUndo` / `allowSkip` / `allowAutofill` | boolean | all `true` | UX feature flags |
117
+ | `nudge.afterInactiveHours` / `maxNudges` | number | 48 / 3 | Stale-session nudge config |
118
+
119
+ ## FormControl reference (key fields)
120
+
121
+ | Field | Type | Description |
122
+ |---|---|---|
123
+ | `key` | string | Unique within form; used in `values` map |
124
+ | `label` | string | Human-readable name |
125
+ | `type` | string | `text`, `number`, `email`, `boolean`, `select`, `date`, `file`, or custom |
126
+ | `required` | boolean | Form cannot submit without this field |
127
+ | `sensitive` | boolean | Value masked in agent context |
128
+ | `hidden` | boolean | Extract silently, never ask directly |
129
+ | `askPrompt` | string | Custom agent prompt for this field |
130
+ | `extractHints` | string[] | Keywords to improve LLM extraction accuracy |
131
+ | `confirmThreshold` | number | Confidence below this triggers confirmation (default 0.8) |
132
+ | `dependsOn` | FormControlDependency | Conditional display based on another field's value |
133
+ | `dbbind` | string | Column name for `mappedValues` in submission |
134
+ | `options` | FormControlOption[] | For `select` type |
package/auto-enable.ts ADDED
@@ -0,0 +1,24 @@
1
+ // Auto-enable check for @elizaos/plugin-form.
2
+ //
3
+ // Plugin manifest entry-point — referenced by package.json's
4
+ // `elizaos.plugin.autoEnableModule`. Keep this module light: env reads only,
5
+ // no service init, no transitive imports of the full plugin runtime. The
6
+ // auto-enable engine loads dozens of these per boot.
7
+ import type { PluginAutoEnableContext } from "@elizaos/core";
8
+
9
+ function isFeatureEnabled(
10
+ config: PluginAutoEnableContext["config"],
11
+ key: string,
12
+ ): boolean {
13
+ const f = (config?.features as Record<string, unknown> | undefined)?.[key];
14
+ if (f === true) return true;
15
+ if (f && typeof f === "object" && f !== null) {
16
+ return (f as Record<string, unknown>).enabled !== false;
17
+ }
18
+ return false;
19
+ }
20
+
21
+ /** Enable when `config.features.form` is truthy / not explicitly disabled. */
22
+ export function shouldEnable(ctx: PluginAutoEnableContext): boolean {
23
+ return isFeatureEnabled(ctx.config, "form");
24
+ }
package/package.json CHANGED
@@ -1,60 +1,74 @@
1
1
  {
2
2
  "name": "@elizaos/plugin-form",
3
- "description": "Guardrails for agent-guided user journeys - forms as agent guidance rails for ElizaOS",
4
- "version": "2.0.0-alpha.9",
3
+ "version": "2.0.3-beta.2",
5
4
  "type": "module",
6
- "main": "dist/index.js",
7
- "module": "dist/index.js",
8
- "types": "dist/index.d.ts",
9
- "packageType": "plugin",
10
- "platform": "node",
11
- "license": "MIT",
12
- "author": "Odilitime",
13
- "keywords": [
14
- "plugin",
15
- "elizaos",
16
- "form",
17
- "conversational",
18
- "data-collection"
19
- ],
20
- "repository": {
21
- "type": "git",
22
- "url": "https://github.com/elizaos/elizaos"
23
- },
5
+ "description": "Eliza plugin-form: conversational forms as guardrails for guided user journeys.",
6
+ "main": "./dist/index.js",
24
7
  "exports": {
25
8
  "./package.json": "./package.json",
26
9
  ".": {
27
10
  "types": "./dist/index.d.ts",
11
+ "eliza-source": {
12
+ "types": "./src/index.ts",
13
+ "import": "./src/index.ts",
14
+ "default": "./src/index.ts"
15
+ },
28
16
  "import": "./dist/index.js",
29
17
  "default": "./dist/index.js"
18
+ },
19
+ "./*.css": "./dist/*.css",
20
+ "./*": {
21
+ "types": "./dist/*.d.ts",
22
+ "eliza-source": {
23
+ "types": "./src/*.ts",
24
+ "import": "./src/*.ts",
25
+ "default": "./src/*.ts"
26
+ },
27
+ "import": "./dist/*.js",
28
+ "default": "./dist/*.js"
29
+ }
30
+ },
31
+ "dependencies": {
32
+ "@elizaos/core": "2.0.3-beta.2",
33
+ "uuid": "^14.0.0"
34
+ },
35
+ "agentConfig": {
36
+ "pluginType": "elizaos:plugin:1.0.0",
37
+ "pluginParameters": {},
38
+ "description": "Conversational forms for structured data collection."
39
+ },
40
+ "elizaos": {
41
+ "app": {
42
+ "heroImage": "assets/hero.png"
43
+ },
44
+ "plugin": {
45
+ "autoEnableModule": "./auto-enable.ts",
46
+ "capabilities": [
47
+ "forms"
48
+ ]
30
49
  }
31
50
  },
51
+ "publishConfig": {
52
+ "access": "public"
53
+ },
54
+ "types": "./dist/index.d.ts",
55
+ "scripts": {
56
+ "build": "bun run build:js && bun run build:types",
57
+ "clean": "rm -rf dist",
58
+ "test": "vitest run --config vitest.config.ts",
59
+ "typecheck": "tsgo --noEmit -p tsconfig.json",
60
+ "build:js": "tsup --config ../tsup.plugin-packages.shared.ts",
61
+ "build:types": "tsc --noCheck -p tsconfig.build.json"
62
+ },
32
63
  "files": [
33
64
  "dist",
34
- "README.md",
35
- "package.json"
65
+ "auto-enable.ts"
36
66
  ],
37
- "peerDependencies": {
38
- "@elizaos/core": "2.0.0-alpha.3"
39
- },
40
67
  "devDependencies": {
41
- "@biomejs/biome": "^2.3.11",
42
68
  "@types/node": "^25.0.3",
43
- "typescript": "^5.9.3"
69
+ "tsup": "^8.5.1",
70
+ "typescript": "^6.0.3",
71
+ "vitest": "^4.0.18"
44
72
  },
45
- "scripts": {
46
- "build": "bun run build.ts",
47
- "build:ts": "bun run build.ts",
48
- "dev": "bun --hot build.ts",
49
- "test": "vitest run || echo 'TypeScript tests skipped - no tests found'",
50
- "typecheck": "tsc --noEmit",
51
- "lint": "bunx @biomejs/biome check --write --unsafe .",
52
- "lint:check": "bunx @biomejs/biome check .",
53
- "clean": "rm -rf dist .turbo",
54
- "format": "bunx @biomejs/biome format --write .",
55
- "format:check": "bunx @biomejs/biome format ."
56
- },
57
- "publishConfig": {
58
- "access": "public"
59
- }
73
+ "gitHead": "82fe0f44215954c2417328203f5bd6510985c1fc"
60
74
  }
package/dist/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from "./index";
2
- export { default } from "./index";