rule-based-chat 1.0.0-beta.0

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.
Files changed (35) hide show
  1. package/dist/index.cjs +2 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.mjs +2 -0
  4. package/dist/index.mjs.map +1 -0
  5. package/dist/index.umd.js +2 -0
  6. package/dist/index.umd.js.map +1 -0
  7. package/dist/types/conversation/ConversationManager.d.ts +82 -0
  8. package/dist/types/conversation/ConversationManager.d.ts.map +1 -0
  9. package/dist/types/conversation/index.d.ts +2 -0
  10. package/dist/types/conversation/index.d.ts.map +1 -0
  11. package/dist/types/engine/ChatEngine.d.ts +185 -0
  12. package/dist/types/engine/ChatEngine.d.ts.map +1 -0
  13. package/dist/types/engine/ConditionEvaluator.d.ts +106 -0
  14. package/dist/types/engine/ConditionEvaluator.d.ts.map +1 -0
  15. package/dist/types/engine/EventEmitter.d.ts +62 -0
  16. package/dist/types/engine/EventEmitter.d.ts.map +1 -0
  17. package/dist/types/engine/TemplateEngine.d.ts +42 -0
  18. package/dist/types/engine/TemplateEngine.d.ts.map +1 -0
  19. package/dist/types/engine/index.d.ts +5 -0
  20. package/dist/types/engine/index.d.ts.map +1 -0
  21. package/dist/types/index.d.ts +9 -0
  22. package/dist/types/index.d.ts.map +1 -0
  23. package/dist/types/rules/RuleProcessor.d.ts +118 -0
  24. package/dist/types/rules/RuleProcessor.d.ts.map +1 -0
  25. package/dist/types/rules/index.d.ts +2 -0
  26. package/dist/types/rules/index.d.ts.map +1 -0
  27. package/dist/types/storage/MemoryStorage.d.ts +50 -0
  28. package/dist/types/storage/MemoryStorage.d.ts.map +1 -0
  29. package/dist/types/storage/StorageAdapter.d.ts +39 -0
  30. package/dist/types/storage/StorageAdapter.d.ts.map +1 -0
  31. package/dist/types/storage/index.d.ts +3 -0
  32. package/dist/types/storage/index.d.ts.map +1 -0
  33. package/dist/types/types/index.d.ts +353 -0
  34. package/dist/types/types/index.d.ts.map +1 -0
  35. package/package.json +37 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChatEngine.d.ts","sourceRoot":"","sources":["../../../src/engine/ChatEngine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAE1E,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,OAAO,KAAK,EACV,YAAY,EAAE,gBAAgB,EAAE,aAAa,EAAE,0BAA0B,EACzE,gBAAgB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,iBAAiB,EAC1E,iBAAiB,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAoB,gBAAgB,EAC3F,UAAU,EAAE,iBAAiB,EAAE,gBAAgB,EAChD,MAAM,UAAU,CAAC;AAElB;;GAEG;AACH,MAAM,WAAW,wBAAyB,SAAQ,gBAAgB;IAChE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,eAAe,CAAC,EAAE,YAAY,EAAE,CAAC;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,iBAAiB,CAAC;IACzB,SAAS,EAAE,gBAAgB,CAAC;IAC5B,gBAAgB,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,YAAY,EAAE,CAAC;CAClC;AAED;;;;GAIG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,KAAK,CAAgC;IAC7C,OAAO,CAAC,cAAc,CAA6B;IACnD,OAAO,CAAC,mBAAmB,CAAsB;IACjD,OAAO,CAAC,OAAO,CAAiB;IAChC,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,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AAS,EAAE,CAAC,EACZ,OAAO,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,GACxB,IAAI;IAIP,eAAe,IAAI,YAAY;IAI/B,iBAAiB,IAAI,cAAc;IAInC,qBAAqB,IAAI,kBAAkB;IAI3C,UAAU,IAAI,cAAc;IAI5B,sBAAsB,IAAI,mBAAmB;IAI7C;;OAEG;IACH,OAAO,CAAC,GAAG;CAKZ"}
@@ -0,0 +1,106 @@
1
+ import { AnswerOption, ConditionEvaluatorFunction, ConversationNode, ConversationState, DisplayConditions } from '../types';
2
+ /**
3
+ * ConditionEvaluator handles the evaluation of display conditions
4
+ * for options, messages, and nodes
5
+ */
6
+ export declare class ConditionEvaluator {
7
+ private customEvaluators;
8
+ private enableLogging;
9
+ constructor(customEvaluators?: Record<string, ConditionEvaluatorFunction>, enableLogging?: boolean);
10
+ /**
11
+ * Filter options based on their display conditions
12
+ * Returns only options that should be displayed
13
+ */
14
+ filterOptions(options: AnswerOption[], state: ConversationState): Promise<AnswerOption[]>;
15
+ /**
16
+ * Get the appropriate message for a node based on conditions
17
+ * Returns the conditional message if conditions match, otherwise the default message
18
+ */
19
+ getConditionalMessage(node: ConversationNode, state: ConversationState): Promise<string>;
20
+ /**
21
+ * Check if a node should be displayed based on its conditions
22
+ */
23
+ shouldDisplayNode(node: ConversationNode, state: ConversationState): Promise<boolean>;
24
+ /**
25
+ * Evaluate display conditions
26
+ * Supports single condition, array of conditions (AND), or condition groups
27
+ */
28
+ evaluateConditions(conditions: DisplayConditions, state: ConversationState): Promise<boolean>;
29
+ /**
30
+ * Evaluate a condition group with AND/OR logic
31
+ */
32
+ private evaluateConditionGroup;
33
+ /**
34
+ * Evaluate a single display condition
35
+ */
36
+ private evaluateSingleCondition;
37
+ /**
38
+ * Get the value from the specified source
39
+ */
40
+ private getSourceValue;
41
+ /**
42
+ * Get value from a previous answer
43
+ */
44
+ private getAnswerValue;
45
+ /**
46
+ * Get the most recent answer for a given node ID
47
+ */
48
+ private getMostRecentAnswer;
49
+ /**
50
+ * Get value from conversation context
51
+ */
52
+ private getContextValue;
53
+ /**
54
+ * Get value from conversation state
55
+ */
56
+ private getStateValue;
57
+ /**
58
+ * Get value from metadata
59
+ */
60
+ private getMetadataValue;
61
+ /**
62
+ * Evaluate a custom condition using registered evaluator
63
+ */
64
+ private evaluateCustomCondition;
65
+ /**
66
+ * Compare two values using the specified operator
67
+ */
68
+ private compareValues;
69
+ /**
70
+ * Normalize a value for comparison
71
+ */
72
+ private normalizeValue;
73
+ /**
74
+ * Check if actual contains expected
75
+ */
76
+ private checkContains;
77
+ /**
78
+ * Compare numeric values
79
+ */
80
+ private compareNumeric;
81
+ /**
82
+ * Type guard for single condition
83
+ */
84
+ private isSingleCondition;
85
+ /**
86
+ * Type guard for condition group
87
+ */
88
+ private isConditionGroup;
89
+ /**
90
+ * Register a custom condition evaluator
91
+ */
92
+ registerEvaluator(name: string, evaluator: ConditionEvaluatorFunction): void;
93
+ /**
94
+ * Unregister a custom condition evaluator
95
+ */
96
+ unregisterEvaluator(name: string): boolean;
97
+ /**
98
+ * Get all registered evaluator names
99
+ */
100
+ getRegisteredEvaluators(): string[];
101
+ /**
102
+ * Internal logging helper
103
+ */
104
+ private log;
105
+ }
106
+ //# sourceMappingURL=ConditionEvaluator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConditionEvaluator.d.ts","sourceRoot":"","sources":["../../../src/engine/ConditionEvaluator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,0BAA0B,EAAkB,gBAAgB,EACpF,iBAAiB,EAAoB,iBAAiB,EAAc,MAAM,UAAU,CAAC;AAEzF;;;GAGG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,gBAAgB,CAA6C;IACrE,OAAO,CAAC,aAAa,CAAU;gBAG7B,gBAAgB,GAAE,MAAM,CAAC,MAAM,EAAE,0BAA0B,CAAM,EACjE,aAAa,GAAE,OAAe;IAMhC;;;OAGG;IACG,aAAa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0,0 +1,62 @@
1
+ import { ChatEventPayloadMap, ChatEventType, EventHandler, EventHandlers } from '../types';
2
+ /**
3
+ * EventEmitter handles the hooks/events system for the ChatEngine
4
+ * Allows subscribing to and emitting events throughout the conversation lifecycle
5
+ */
6
+ export declare class EventEmitter {
7
+ private handlers;
8
+ private enableLogging;
9
+ constructor(initialHandlers?: EventHandlers, enableLogging?: boolean);
10
+ /**
11
+ * Register multiple event handlers from a configuration object
12
+ */
13
+ registerHandlers(handlers: EventHandlers): void;
14
+ /**
15
+ * Subscribe to an event
16
+ * @param eventType - The type of event to listen for
17
+ * @param handler - The function to call when the event is emitted
18
+ * @returns A function to unsubscribe the handler
19
+ */
20
+ on<T extends ChatEventType>(eventType: T, handler: EventHandler<T>): () => void;
21
+ /**
22
+ * Subscribe to an event for a single emission only
23
+ * @param eventType - The type of event to listen for
24
+ * @param handler - The function to call when the event is emitted
25
+ * @returns A function to unsubscribe the handler
26
+ */
27
+ once<T extends ChatEventType>(eventType: T, handler: EventHandler<T>): () => void;
28
+ /**
29
+ * Unsubscribe from an event
30
+ * @param eventType - The type of event to unsubscribe from
31
+ * @param handler - The specific handler to remove (if not provided, removes all handlers)
32
+ */
33
+ off<T extends ChatEventType>(eventType: T, handler?: EventHandler<T>): void;
34
+ /**
35
+ * Emit an event to all registered handlers
36
+ * @param eventType - The type of event to emit
37
+ * @param payload - The data to pass to handlers
38
+ * @returns For onBeforeTransition, returns false if any handler returns false (cancels transition)
39
+ */
40
+ emit<T extends ChatEventType>(eventType: T, payload: ChatEventPayloadMap[T]): Promise<boolean>;
41
+ /**
42
+ * Check if there are any handlers registered for an event type
43
+ */
44
+ hasHandlers(eventType: ChatEventType): boolean;
45
+ /**
46
+ * Get the number of handlers registered for an event type
47
+ */
48
+ handlerCount(eventType: ChatEventType): number;
49
+ /**
50
+ * Get all registered event types
51
+ */
52
+ getRegisteredEvents(): ChatEventType[];
53
+ /**
54
+ * Remove all handlers for all events
55
+ */
56
+ removeAllHandlers(): void;
57
+ /**
58
+ * Internal logging helper
59
+ */
60
+ private log;
61
+ }
62
+ //# sourceMappingURL=EventEmitter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EventEmitter.d.ts","sourceRoot":"","sources":["../../../src/engine/EventEmitter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEhG;;;GAGG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAoD;IACpE,OAAO,CAAC,aAAa,CAAU;gBAEnB,eAAe,CAAC,EAAE,aAAa,EAAE,aAAa,GAAE,OAAe;IAU3E;;OAEG;IACH,gBAAgB,CAAC,QAAQ,EAAE,aAAa,GAAG,IAAI;IA6B/C;;;;;OAKG;IACH,EAAE,CAAC,CAAC,SAAS,aAAa,EACxB,SAAS,EAAE,CAAC,EACZ,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GACvB,MAAM,IAAI;IAgBb;;;;;OAKG;IACH,IAAI,CAAC,CAAC,SAAS,aAAa,EAC1B,SAAS,EAAE,CAAC,EACZ,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GACvB,MAAM,IAAI;IASb;;;;OAIG;IACH,GAAG,CAAC,CAAC,SAAS,aAAa,EACzB,SAAS,EAAE,CAAC,EACZ,OAAO,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,GACxB,IAAI;IAuBP;;;;;OAKG;IACG,IAAI,CAAC,CAAC,SAAS,aAAa,EAChC,SAAS,EAAE,CAAC,EACZ,OAAO,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAC9B,OAAO,CAAC,OAAO,CAAC;IAwCnB;;OAEG;IACH,WAAW,CAAC,SAAS,EAAE,aAAa,GAAG,OAAO;IAK9C;;OAEG;IACH,YAAY,CAAC,SAAS,EAAE,aAAa,GAAG,MAAM;IAI9C;;OAEG;IACH,mBAAmB,IAAI,aAAa,EAAE;IAItC;;OAEG;IACH,iBAAiB,IAAI,IAAI;IAKzB;;OAEG;IACH,OAAO,CAAC,GAAG;CAKZ"}
@@ -0,0 +1,42 @@
1
+ import { ConversationNode, ConversationState, VariableResolver } from '../types';
2
+ /**
3
+ * TemplateEngine handles variable substitution in messages
4
+ * Supports {{variableName}} syntax with built-in and custom resolvers
5
+ */
6
+ export declare class TemplateEngine {
7
+ private customResolvers;
8
+ constructor(customResolvers?: Record<string, VariableResolver>);
9
+ /**
10
+ * Process a message template and replace all variables
11
+ */
12
+ processTemplate(template: string, state: ConversationState, node: ConversationNode): Promise<string>;
13
+ /**
14
+ * Resolve a variable to its value
15
+ */
16
+ private resolveVariable;
17
+ /**
18
+ * Built-in variable resolvers
19
+ */
20
+ private resolveBuiltIn;
21
+ /**
22
+ * Get the most recent answer for a given node ID
23
+ */
24
+ private getMostRecentAnswer;
25
+ /**
26
+ * Get a nested value from an object using dot notation
27
+ */
28
+ private getNestedValue;
29
+ /**
30
+ * Format a value for display in a message
31
+ */
32
+ private formatValue;
33
+ /**
34
+ * Register a custom resolver at runtime
35
+ */
36
+ registerResolver(name: string, resolver: VariableResolver): void;
37
+ /**
38
+ * Check if a message contains template variables
39
+ */
40
+ hasVariables(message: string): boolean;
41
+ }
42
+ //# sourceMappingURL=TemplateEngine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TemplateEngine.d.ts","sourceRoot":"","sources":["../../../src/engine/TemplateEngine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAc,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAElG;;;GAGG;AACH,qBAAa,cAAc;IACvB,OAAO,CAAC,eAAe,CAAmC;gBAE9C,eAAe,GAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAM;IAIlE;;OAEG;IACG,eAAe,CACjB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,iBAAiB,EACxB,IAAI,EAAE,gBAAgB,GACvB,OAAO,CAAC,MAAM,CAAC;IAoBlB;;OAEG;YACW,eAAe;IAwB7B;;OAEG;IACH,OAAO,CAAC,cAAc;IA+DtB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAa3B;;OAEG;IACH,OAAO,CAAC,cAAc;IA2BtB;;OAEG;IACH,OAAO,CAAC,WAAW;IAOnB;;OAEG;IACH,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,gBAAgB,GAAG,IAAI;IAIhE;;OAEG;IACH,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;CAGzC"}
@@ -0,0 +1,5 @@
1
+ export { ChatEngine } from './ChatEngine';
2
+ export { TemplateEngine } from './TemplateEngine';
3
+ export { EventEmitter } from './EventEmitter';
4
+ export { ConditionEvaluator } from './ConditionEvaluator';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/engine/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Chatbot Core - A rule-based chatbot engine
3
+ */
4
+ export { ChatEngine, TemplateEngine, EventEmitter, ConditionEvaluator } from './engine';
5
+ export { ConversationManager } from './conversation';
6
+ export { RuleProcessor } from './rules';
7
+ export { StorageAdapter, MemoryStorage } from './storage';
8
+ export type { AnswerOption, MessageType, ConversationNode, TransitionRule, RuleCondition, ConversationFlow, UserAnswer, ConversationMessage, ConversationState, ProcessingResult, ChatEngineConfig, ValidatorFunction, EvaluatorFunction, MessageProcessor, VariableResolver, ChatEventType, BaseEventPayload, ConversationStartPayload, ConversationEndPayload, BeforeTransitionPayload, AfterTransitionPayload, AnswerRecordedPayload, ValidationErrorPayload, ConversationPausedPayload, ConversationResumedPayload, ConversationResetPayload, ErrorPayload, ChatEventPayloadMap, EventHandler, EventHandlers, ConditionOperator, ConditionSource, DisplayCondition, ConditionGroup, DisplayConditions, ConditionalMessage, ConditionEvaluatorFunction, GotoAction, GotoResult, NodeAction, ConversationNodeActions, IStorageAdapter, } from './types';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAGxF,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAGrD,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGxC,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAG1D,YAAY,EAEV,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,gBAAgB,EAGhB,UAAU,EACV,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAGhB,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAGhB,aAAa,EACb,gBAAgB,EAChB,wBAAwB,EACxB,sBAAsB,EACtB,uBAAuB,EACvB,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,EACtB,yBAAyB,EACzB,0BAA0B,EAC1B,wBAAwB,EACxB,YAAY,EACZ,mBAAmB,EACnB,YAAY,EACZ,aAAa,EAGb,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,0BAA0B,EAG1B,UAAU,EACV,UAAU,EACV,UAAU,EACV,uBAAuB,EAGvB,eAAe,GAChB,MAAM,SAAS,CAAC"}
@@ -0,0 +1,118 @@
1
+ import { ConversationFlow, ConversationNode, ConversationState, EvaluatorFunction, RuleCondition, UserAnswer } from '../types';
2
+ /**
3
+ * RuleProcessor handles the evaluation of transition rules
4
+ * and determines the next node in the conversation flow
5
+ *
6
+ * Supports:
7
+ * - AND/OR condition logic
8
+ * - Nested conditions
9
+ * - Context and state-based conditions
10
+ * - Custom evaluators
11
+ */
12
+ export declare class RuleProcessor {
13
+ private flow;
14
+ private customEvaluators;
15
+ private enableLogging;
16
+ constructor(flow: ConversationFlow, customEvaluators?: Record<string, EvaluatorFunction>, enableLogging?: boolean);
17
+ /**
18
+ * Get a node by its ID
19
+ */
20
+ getNode(nodeId: string): ConversationNode | null;
21
+ /**
22
+ * Get the starting node of the flow
23
+ */
24
+ getStartNode(): ConversationNode | null;
25
+ /**
26
+ * Check if a node exists in the flow
27
+ */
28
+ nodeExists(nodeId: string): boolean;
29
+ /**
30
+ * Get all node IDs in the flow
31
+ */
32
+ getAllNodeIds(): string[];
33
+ /**
34
+ * Determine the next node based on the current node and user's answer
35
+ */
36
+ getNextNode(currentNodeId: string, answer: UserAnswer, state: ConversationState): ConversationNode | null;
37
+ /**
38
+ * Evaluate if a transition's conditions are met
39
+ */
40
+ private evaluateTransition;
41
+ /**
42
+ * Evaluate a single condition (supports nested conditions)
43
+ */
44
+ evaluateCondition(condition: RuleCondition, answer: UserAnswer, state: ConversationState): boolean;
45
+ /**
46
+ * Evaluate nested conditions with AND/OR logic
47
+ */
48
+ private evaluateNestedConditions;
49
+ /**
50
+ * Evaluate a simple (non-nested) condition
51
+ */
52
+ private evaluateSimpleCondition;
53
+ /**
54
+ * Extract the value based on field type
55
+ */
56
+ private getFieldValue;
57
+ /**
58
+ * Get a value from the conversation context (supports dot notation)
59
+ */
60
+ private getNestedValue;
61
+ /**
62
+ * Get a value from the conversation state
63
+ */
64
+ private getStateValue;
65
+ /**
66
+ * Compare values using the specified operator
67
+ */
68
+ private compareValues;
69
+ /**
70
+ * Normalize a value for comparison (lowercase strings)
71
+ */
72
+ private normalizeValue;
73
+ /**
74
+ * Check if actual contains expected
75
+ */
76
+ private checkContains;
77
+ /**
78
+ * Compare numeric values
79
+ */
80
+ private compareNumeric;
81
+ /**
82
+ * Validate that all node references in transitions exist
83
+ */
84
+ validateFlow(): {
85
+ valid: boolean;
86
+ errors: string[];
87
+ };
88
+ /**
89
+ * Validate conditions recursively
90
+ */
91
+ private validateConditions;
92
+ /**
93
+ * Get all possible next nodes from a given node (for debugging/visualization)
94
+ */
95
+ getPossibleNextNodes(nodeId: string): ConversationNode[];
96
+ /**
97
+ * Evaluate a set of conditions without an answer (for node actions)
98
+ * Uses state and context only
99
+ */
100
+ evaluateConditionsWithoutAnswer(conditions: RuleCondition[], state: ConversationState, logic?: 'and' | 'or'): boolean;
101
+ /**
102
+ * Register a custom evaluator at runtime
103
+ */
104
+ registerEvaluator(name: string, evaluator: EvaluatorFunction): void;
105
+ /**
106
+ * Update the conversation flow
107
+ */
108
+ setFlow(flow: ConversationFlow): void;
109
+ /**
110
+ * Get the current flow
111
+ */
112
+ getFlow(): ConversationFlow;
113
+ /**
114
+ * Internal logging helper
115
+ */
116
+ private log;
117
+ }
118
+ //# sourceMappingURL=RuleProcessor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RuleProcessor.d.ts","sourceRoot":"","sources":["../../../src/rules/RuleProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,aAAa,EAAkB,UAAU,EAAE,MAAM,UAAU,CAAC;AAEpJ;;;;;;;;;GASG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,IAAI,CAAmB;IAC/B,OAAO,CAAC,gBAAgB,CAAoC;IAC5D,OAAO,CAAC,aAAa,CAAU;gBAG7B,IAAI,EAAE,gBAAgB,EACtB,gBAAgB,GAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAM,EACxD,aAAa,GAAE,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ACH,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,iBAAiB,GAAG,IAAI;IAInE;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI;IAIrC;;OAEG;IACH,OAAO,IAAI,gBAAgB;IAI3B;;OAEG;IACH,OAAO,CAAC,GAAG;CAKZ"}
@@ -0,0 +1,2 @@
1
+ export { RuleProcessor } from './RuleProcessor';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/rules/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,50 @@
1
+ import { ConversationState } from '../types';
2
+ import { StorageAdapter } from './StorageAdapter';
3
+ /**
4
+ * In-memory storage adapter
5
+ * Useful for development, testing, and single-instance deployments
6
+ *
7
+ * Note: Data is lost when the process restarts
8
+ */
9
+ export declare class MemoryStorage extends StorageAdapter {
10
+ private store;
11
+ private maxSize;
12
+ /**
13
+ * Create a new MemoryStorage instance
14
+ * @param maxSize - Maximum number of conversations to store (0 = unlimited)
15
+ */
16
+ constructor(maxSize?: number);
17
+ /**
18
+ * Retrieve a conversation state by ID
19
+ */
20
+ get(conversationId: string): Promise<ConversationState | null>;
21
+ /**
22
+ * Save or update a conversation state
23
+ */
24
+ save(state: ConversationState): Promise<void>;
25
+ /**
26
+ * Delete a conversation state
27
+ */
28
+ delete(conversationId: string): Promise<void>;
29
+ /**
30
+ * Check if a conversation exists
31
+ */
32
+ exists(conversationId: string): Promise<boolean>;
33
+ /**
34
+ * Get the current number of stored conversations
35
+ */
36
+ getSize(): number;
37
+ /**
38
+ * Clear all stored conversations
39
+ */
40
+ clear(): void;
41
+ /**
42
+ * Get all conversation IDs (useful for debugging)
43
+ */
44
+ getAllIds(): string[];
45
+ /**
46
+ * Find the oldest conversation entry based on updatedAt
47
+ */
48
+ private findOldestEntry;
49
+ }
50
+ //# sourceMappingURL=MemoryStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MemoryStorage.d.ts","sourceRoot":"","sources":["../../../src/storage/MemoryStorage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD;;;;;GAKG;AACH,qBAAa,aAAc,SAAQ,cAAc;IAC/C,OAAO,CAAC,KAAK,CAAiC;IAC9C,OAAO,CAAC,OAAO,CAAS;IAExB;;;OAGG;gBACS,OAAO,GAAE,MAAU;IAM/B;;OAEG;IACG,GAAG,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;IAWpE;;OAEG;IACG,IAAI,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBnD;;OAEG;IACG,MAAM,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAInD;;OAEG;IACG,MAAM,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAItD;;OAEG;IACH,OAAO,IAAI,MAAM;IAIjB;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,SAAS,IAAI,MAAM,EAAE;IAIrB;;OAEG;IACH,OAAO,CAAC,eAAe;CAcxB"}
@@ -0,0 +1,39 @@
1
+ import { ConversationState, IStorageAdapter } from '../types';
2
+ /**
3
+ * Abstract base class for storage adapters
4
+ * Extend this class to create custom storage implementations
5
+ */
6
+ export declare abstract class StorageAdapter implements IStorageAdapter {
7
+ /**
8
+ * Retrieve a conversation state by ID
9
+ * @param conversationId - Unique conversation identifier
10
+ * @returns The conversation state or null if not found
11
+ */
12
+ abstract get(conversationId: string): Promise<ConversationState | null>;
13
+ /**
14
+ * Save or update a conversation state
15
+ * @param state - The conversation state to save
16
+ */
17
+ abstract save(state: ConversationState): Promise<void>;
18
+ /**
19
+ * Delete a conversation state
20
+ * @param conversationId - Unique conversation identifier
21
+ */
22
+ abstract delete(conversationId: string): Promise<void>;
23
+ /**
24
+ * Check if a conversation exists
25
+ * @param conversationId - Unique conversation identifier
26
+ * @returns True if the conversation exists
27
+ */
28
+ abstract exists(conversationId: string): Promise<boolean>;
29
+ /**
30
+ * Helper method to create a deep copy of state
31
+ * Useful for preventing mutation issues
32
+ */
33
+ protected deepCopy<T>(obj: T): T;
34
+ /**
35
+ * Helper method to validate conversation state structure
36
+ */
37
+ protected validateState(state: ConversationState): boolean;
38
+ }
39
+ //# sourceMappingURL=StorageAdapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StorageAdapter.d.ts","sourceRoot":"","sources":["../../../src/storage/StorageAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEnE;;;GAGG;AACH,8BAAsB,cAAe,YAAW,eAAe;IAC7D;;;;OAIG;IACH,QAAQ,CAAC,GAAG,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;IAEvE;;;OAGG;IACH,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAEtD;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAEtD;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAEzD;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC;IAIhC;;OAEG;IACH,SAAS,CAAC,aAAa,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO;CAY3D"}
@@ -0,0 +1,3 @@
1
+ export { StorageAdapter } from './StorageAdapter';
2
+ export { MemoryStorage } from './MemoryStorage';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/storage/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}