@elizaos/plugin-form 2.0.0-alpha.1 → 2.0.0-alpha.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.
@@ -1,91 +0,0 @@
1
- /**
2
- * @module evaluators/extractor
3
- * @description Form evaluator for field extraction and intent handling
4
- *
5
- * ## Role in Form Plugin
6
- *
7
- * The evaluator is the "brain" of the form plugin. It runs AFTER
8
- * each user message and:
9
- *
10
- * 1. Detects user intent (submit, cancel, undo, etc.)
11
- * 2. Extracts field values from natural language
12
- * 3. Updates session state accordingly
13
- * 4. Triggers lifecycle transitions
14
- * 5. **Emits events** for widgets and other listeners
15
- *
16
- * ## Event Emission
17
- *
18
- * The evaluator emits standardized events as it processes messages:
19
- *
20
- * - `FORM_FIELD_EXTRACTED`: Value extracted for a simple field
21
- * - `FORM_SUBFIELD_UPDATED`: Value extracted for a composite subfield
22
- * - `FORM_SUBCONTROLS_FILLED`: All subcontrols of composite type filled
23
- * - `FORM_EXTERNAL_ACTIVATED`: External type activated
24
- *
25
- * Widgets DON'T parse messages - they react to these events.
26
- * This keeps parsing logic centralized in the evaluator.
27
- *
28
- * ## Processing Flow
29
- *
30
- * ```
31
- * User Message → Evaluator.validate() → Should we run?
32
- * ↓ Yes
33
- * Evaluator.handler() →
34
- * ↓
35
- * quickIntentDetect() → Fast path for English
36
- * ↓ No match
37
- * llmIntentAndExtract() → LLM fallback
38
- * ↓
39
- * Handle intent (submit, stash, cancel, undo, etc.)
40
- * ↓
41
- * Process extractions (update fields OR subfields)
42
- * ↓
43
- * Emit events (FORM_FIELD_EXTRACTED, etc.)
44
- * ↓
45
- * Check composite types → Activate if all subfields filled
46
- * ↓
47
- * Save session
48
- * ```
49
- *
50
- * ## Why Evaluator (Not Action)
51
- *
52
- * We use an evaluator because:
53
- *
54
- * 1. **Runs Always**: Evaluators run on every message, not just when
55
- * explicitly invoked. Form extraction should happen automatically.
56
- *
57
- * 2. **Post-Processing**: Evaluators run after actions, allowing the
58
- * provider to set context and REPLY action to generate response.
59
- *
60
- * 3. **No Response Generation**: Evaluators don't generate responses,
61
- * they just update state. The agent (REPLY) handles responses.
62
- *
63
- * ## Intent Handling
64
- *
65
- * Different intents are handled differently:
66
- *
67
- * - **Lifecycle** (submit, stash, cancel): Change session status
68
- * - **UX** (undo, skip, autofill): Modify session without status change
69
- * - **Info** (explain, example, progress): No state change, just context
70
- * - **Data** (fill_form): Extract and update field values
71
- *
72
- * ## FORM_RESTORE Exception
73
- *
74
- * The 'restore' intent is handled by FORM_RESTORE action, not here.
75
- * This is because restore needs to happen BEFORE the provider runs,
76
- * so the agent has the restored form context for its response.
77
- */
78
- import type { Evaluator } from "@elizaos/core";
79
- /**
80
- * Form Evaluator
81
- *
82
- * Runs after each message to:
83
- * 1. Detect user intent (fast path for English, LLM fallback for other languages)
84
- * 2. Extract field values from natural language
85
- * 3. Handle lifecycle intents (submit, stash, cancel)
86
- * 4. Handle UX intents (undo, skip, explain, example, progress, autofill)
87
- * 5. Update session state
88
- */
89
- export declare const formEvaluator: Evaluator;
90
- export default formEvaluator;
91
- //# sourceMappingURL=extractor.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"extractor.d.ts","sourceRoot":"","sources":["../../src/evaluators/extractor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4EG;AAEH,OAAO,KAAK,EAGV,SAAS,EAMV,MAAM,eAAe,CAAC;AAavB;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,EAAE,SA+N3B,CAAC;AA2UF,eAAe,aAAa,CAAC"}
@@ -1,105 +0,0 @@
1
- /**
2
- * @module extraction
3
- * @description LLM-based field extraction from natural language
4
- *
5
- * ## Design Philosophy
6
- *
7
- * Unlike traditional forms where users fill in specific fields, agent-native
8
- * forms let users provide information naturally. The user might say:
9
- *
10
- * "I'm John, 25 years old, and my email is john@example.com"
11
- *
12
- * This module extracts: { name: "John", age: 25, email: "john@example.com" }
13
- *
14
- * ## Why LLM Extraction
15
- *
16
- * 1. **Natural Language**: Users don't think in form fields
17
- * 2. **Babble Support**: One message can fill multiple fields
18
- * 3. **Correction Handling**: "Actually, my name is Jon not John"
19
- * 4. **Ambiguity Resolution**: LLM can ask for clarification
20
- *
21
- * ## Extraction Flow
22
- *
23
- * 1. Build a prompt with field definitions and user message
24
- * 2. Ask LLM to extract values and assess confidence
25
- * 3. Parse LLM's structured response
26
- * 4. Validate extracted values against control rules
27
- * 5. Return results with confidence scores
28
- *
29
- * ## Confidence Scores
30
- *
31
- * Each extraction has a confidence score (0-1):
32
- * - 0.9-1.0: High confidence, auto-accept
33
- * - 0.7-0.9: Medium confidence, might auto-accept
34
- * - 0.5-0.7: Low confidence, ask for confirmation
35
- * - 0.0-0.5: Very low, probably wrong
36
- *
37
- * The threshold is configurable per-field (FormControl.confirmThreshold).
38
- *
39
- * ## Bundled Intent + Extraction
40
- *
41
- * We detect intent AND extract values in a single LLM call because:
42
- * - Reduces latency (one call vs two)
43
- * - Context helps with both tasks
44
- * - Intent affects what to extract
45
- */
46
- import type { IAgentRuntime, JsonValue } from "@elizaos/core";
47
- import type { FormControl, FormDefinition, ExtractionResult, IntentResult } from "./types";
48
- import type { TemplateValues } from "./template";
49
- /**
50
- * Extract field values and detect intent from user message using LLM.
51
- *
52
- * This is the main extraction function called by the evaluator.
53
- * It combines intent detection with field extraction in a single call.
54
- *
55
- * WHY single call:
56
- * - LLM calls are expensive (latency and cost)
57
- * - Intent and extraction share context
58
- * - More accurate when done together
59
- *
60
- * @param runtime - Agent runtime for model access
61
- * @param text - User message text
62
- * @param form - Form definition for context
63
- * @param controls - Fields to extract
64
- * @returns Intent result with extractions
65
- */
66
- export declare function llmIntentAndExtract(runtime: IAgentRuntime, text: string, form: FormDefinition, controls: FormControl[], templateValues?: TemplateValues): Promise<IntentResult>;
67
- /**
68
- * Extract a specific field value from user message.
69
- *
70
- * Used when asking for a specific field and expecting direct answer.
71
- * Simpler prompt than full intent+extraction.
72
- *
73
- * WHY separate function:
74
- * - When context is clear, full extraction is overkill
75
- * - "What's your email?" -> "john@example.com" is simple
76
- * - Faster, more focused extraction
77
- *
78
- * @param runtime - Agent runtime for model access
79
- * @param text - User message text
80
- * @param control - The field to extract
81
- * @param debug - Enable debug logging
82
- * @returns Extraction result or null if not found
83
- */
84
- export declare function extractSingleField(runtime: IAgentRuntime, text: string, control: FormControl, debug?: boolean, templateValues?: TemplateValues): Promise<ExtractionResult | null>;
85
- /**
86
- * Detect if user is correcting a previous value.
87
- *
88
- * Looks for patterns like:
89
- * - "Actually, my name is Jon not John"
90
- * - "Sorry, I meant jon@gmail.com"
91
- * - "Change my age to 26"
92
- *
93
- * WHY separate from main extraction:
94
- * - Correction detection needs current values as context
95
- * - More focused prompt for better accuracy
96
- * - Can be skipped if no values exist
97
- *
98
- * @param runtime - Agent runtime for model access
99
- * @param text - User message text
100
- * @param currentValues - Currently filled values
101
- * @param controls - Field definitions
102
- * @returns Array of corrections (empty if no corrections)
103
- */
104
- export declare function detectCorrection(runtime: IAgentRuntime, text: string, currentValues: Record<string, JsonValue>, controls: FormControl[], templateValues?: TemplateValues): Promise<ExtractionResult[]>;
105
- //# sourceMappingURL=extraction.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"extraction.d.ts","sourceRoot":"","sources":["../src/extraction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE9D,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,YAAY,EAEb,MAAM,SAAS,CAAC;AAGjB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AA2CjD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,mBAAmB,C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