@higher.archi/boe 1.0.8 → 1.0.10
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/core/errors.d.ts +48 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +63 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +6 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/memory/working-memory.d.ts +2 -2
- package/dist/core/memory/working-memory.d.ts.map +1 -1
- package/dist/core/memory/working-memory.interface.d.ts +2 -2
- package/dist/core/memory/working-memory.interface.d.ts.map +1 -1
- package/dist/core/memory/working-memory.js +2 -2
- package/dist/core/memory/working-memory.js.map +1 -1
- package/dist/core/types/fact.d.ts +4 -4
- package/dist/core/types/fact.d.ts.map +1 -1
- package/dist/core/types/rule.d.ts +1 -0
- package/dist/core/types/rule.d.ts.map +1 -1
- package/dist/engines/backward/compiler.js +1 -1
- package/dist/engines/backward/compiler.js.map +1 -1
- package/dist/engines/backward/engine.d.ts +2 -2
- package/dist/engines/backward/engine.d.ts.map +1 -1
- package/dist/engines/backward/engine.js.map +1 -1
- package/dist/engines/bayesian/compiler.d.ts.map +1 -1
- package/dist/engines/bayesian/compiler.js +7 -7
- package/dist/engines/bayesian/compiler.js.map +1 -1
- package/dist/engines/bayesian/engine.d.ts +2 -2
- package/dist/engines/bayesian/engine.d.ts.map +1 -1
- package/dist/engines/bayesian/engine.js.map +1 -1
- package/dist/engines/bayesian/strategy.d.ts.map +1 -1
- package/dist/engines/bayesian/strategy.js +5 -5
- package/dist/engines/bayesian/strategy.js.map +1 -1
- package/dist/engines/constraint/compiler.d.ts.map +1 -1
- package/dist/engines/constraint/compiler.js +10 -10
- package/dist/engines/constraint/compiler.js.map +1 -1
- package/dist/engines/constraint/engine.d.ts +2 -2
- package/dist/engines/constraint/engine.d.ts.map +1 -1
- package/dist/engines/constraint/engine.js.map +1 -1
- package/dist/engines/defeasible/compiler.js +1 -1
- package/dist/engines/defeasible/compiler.js.map +1 -1
- package/dist/engines/defeasible/engine.d.ts +2 -2
- package/dist/engines/defeasible/engine.d.ts.map +1 -1
- package/dist/engines/defeasible/engine.js.map +1 -1
- package/dist/engines/expert/compiler.d.ts.map +1 -1
- package/dist/engines/expert/compiler.js +6 -6
- package/dist/engines/expert/compiler.js.map +1 -1
- package/dist/engines/expert/engine.d.ts +2 -2
- package/dist/engines/expert/engine.d.ts.map +1 -1
- package/dist/engines/expert/engine.js.map +1 -1
- package/dist/engines/forward/compiler.d.ts.map +1 -1
- package/dist/engines/forward/compiler.js +4 -4
- package/dist/engines/forward/compiler.js.map +1 -1
- package/dist/engines/forward/engine.d.ts +2 -2
- package/dist/engines/forward/engine.d.ts.map +1 -1
- package/dist/engines/forward/engine.js.map +1 -1
- package/dist/engines/forward/strategy.d.ts.map +1 -1
- package/dist/engines/forward/strategy.js +4 -4
- package/dist/engines/forward/strategy.js.map +1 -1
- package/dist/engines/fuzzy/compiler.js +1 -1
- package/dist/engines/fuzzy/compiler.js.map +1 -1
- package/dist/engines/fuzzy/engine.d.ts +2 -2
- package/dist/engines/fuzzy/engine.d.ts.map +1 -1
- package/dist/engines/fuzzy/engine.js.map +1 -1
- package/dist/engines/fuzzy/strategy.d.ts.map +1 -1
- package/dist/engines/fuzzy/strategy.js +8 -8
- package/dist/engines/fuzzy/strategy.js.map +1 -1
- package/dist/engines/monte-carlo/compiler.d.ts.map +1 -1
- package/dist/engines/monte-carlo/compiler.js +8 -8
- package/dist/engines/monte-carlo/compiler.js.map +1 -1
- package/dist/engines/monte-carlo/engine.d.ts +2 -2
- package/dist/engines/monte-carlo/engine.d.ts.map +1 -1
- package/dist/engines/monte-carlo/engine.js.map +1 -1
- package/dist/engines/monte-carlo/strategy.js +1 -1
- package/dist/engines/monte-carlo/strategy.js.map +1 -1
- package/dist/engines/pricing/compiler.d.ts.map +1 -1
- package/dist/engines/pricing/compiler.js +9 -9
- package/dist/engines/pricing/compiler.js.map +1 -1
- package/dist/engines/pricing/strategy.js +7 -6
- package/dist/engines/pricing/strategy.js.map +1 -1
- package/dist/engines/pricing/types.d.ts +2 -0
- package/dist/engines/pricing/types.d.ts.map +1 -1
- package/dist/engines/scoring/compiler.d.ts.map +1 -1
- package/dist/engines/scoring/compiler.js +8 -6
- package/dist/engines/scoring/compiler.js.map +1 -1
- package/dist/engines/scoring/engine.d.ts +2 -2
- package/dist/engines/scoring/engine.d.ts.map +1 -1
- package/dist/engines/scoring/engine.js.map +1 -1
- package/dist/engines/scoring/index.d.ts +1 -1
- package/dist/engines/scoring/index.d.ts.map +1 -1
- package/dist/engines/scoring/index.js +4 -1
- package/dist/engines/scoring/index.js.map +1 -1
- package/dist/engines/scoring/strategy.d.ts.map +1 -1
- package/dist/engines/scoring/strategy.js +28 -2
- package/dist/engines/scoring/strategy.js.map +1 -1
- package/dist/engines/scoring/types.d.ts +43 -4
- package/dist/engines/scoring/types.d.ts.map +1 -1
- package/dist/engines/scoring/types.js +19 -0
- package/dist/engines/scoring/types.js.map +1 -1
- package/dist/engines/sequential/compiler.d.ts.map +1 -1
- package/dist/engines/sequential/compiler.js +4 -4
- package/dist/engines/sequential/compiler.js.map +1 -1
- package/dist/engines/sequential/engine.d.ts +2 -2
- package/dist/engines/sequential/engine.d.ts.map +1 -1
- package/dist/engines/sequential/engine.js.map +1 -1
- package/dist/engines/sequential/strategy.js +1 -1
- package/dist/engines/sequential/strategy.js.map +1 -1
- package/dist/engines/state-machine/compiler.js +4 -4
- package/dist/engines/state-machine/compiler.js.map +1 -1
- package/dist/engines/state-machine/strategy.d.ts.map +1 -1
- package/dist/engines/state-machine/strategy.js +2 -1
- package/dist/engines/state-machine/strategy.js.map +1 -1
- package/dist/engines/utility/compiler.d.ts.map +1 -1
- package/dist/engines/utility/compiler.js +7 -7
- package/dist/engines/utility/compiler.js.map +1 -1
- package/dist/engines/utility/engine.d.ts +2 -2
- package/dist/engines/utility/engine.d.ts.map +1 -1
- package/dist/engines/utility/engine.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/core/errors.ts +69 -0
- package/src/core/index.ts +4 -0
- package/src/core/memory/working-memory.interface.ts +2 -2
- package/src/core/memory/working-memory.ts +12 -12
- package/src/core/types/fact.ts +4 -4
- package/src/core/types/rule.ts +1 -0
- package/src/engines/backward/compiler.ts +1 -1
- package/src/engines/backward/engine.ts +2 -2
- package/src/engines/bayesian/compiler.ts +9 -8
- package/src/engines/bayesian/engine.ts +2 -2
- package/src/engines/bayesian/strategy.ts +7 -6
- package/src/engines/constraint/compiler.ts +12 -11
- package/src/engines/constraint/engine.ts +2 -2
- package/src/engines/defeasible/compiler.ts +1 -1
- package/src/engines/defeasible/engine.ts +2 -2
- package/src/engines/expert/compiler.ts +8 -7
- package/src/engines/expert/engine.ts +2 -2
- package/src/engines/forward/compiler.ts +6 -5
- package/src/engines/forward/engine.ts +2 -2
- package/src/engines/forward/strategy.ts +6 -5
- package/src/engines/fuzzy/compiler.ts +1 -1
- package/src/engines/fuzzy/engine.ts +2 -2
- package/src/engines/fuzzy/strategy.ts +9 -9
- package/src/engines/monte-carlo/compiler.ts +10 -9
- package/src/engines/monte-carlo/engine.ts +2 -2
- package/src/engines/monte-carlo/strategy.ts +2 -2
- package/src/engines/pricing/compiler.ts +11 -10
- package/src/engines/pricing/strategy.ts +7 -7
- package/src/engines/pricing/types.ts +2 -0
- package/src/engines/scoring/compiler.ts +10 -7
- package/src/engines/scoring/engine.ts +2 -2
- package/src/engines/scoring/index.ts +5 -1
- package/src/engines/scoring/strategy.ts +36 -3
- package/src/engines/scoring/types.ts +49 -4
- package/src/engines/sequential/compiler.ts +6 -5
- package/src/engines/sequential/engine.ts +2 -2
- package/src/engines/sequential/strategy.ts +2 -2
- package/src/engines/state-machine/compiler.ts +5 -5
- package/src/engines/state-machine/strategy.ts +3 -1
- package/src/engines/utility/compiler.ts +9 -8
- package/src/engines/utility/engine.ts +2 -2
- package/src/index.ts +9 -1
|
@@ -52,7 +52,7 @@ export class SequentialEngine implements IRuleEngine<CompiledSequentialRuleSet,
|
|
|
52
52
|
// IWorkingMemory Implementation
|
|
53
53
|
// ========================================
|
|
54
54
|
|
|
55
|
-
add(input: FactInput): Fact {
|
|
55
|
+
add<T = Record<string, any>>(input: FactInput<T>): Fact<T> {
|
|
56
56
|
return this.wm.add(input);
|
|
57
57
|
}
|
|
58
58
|
|
|
@@ -60,7 +60,7 @@ export class SequentialEngine implements IRuleEngine<CompiledSequentialRuleSet,
|
|
|
60
60
|
return this.wm.remove(factId);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
update(input: FactInput): Fact {
|
|
63
|
+
update<T = Record<string, any>>(input: FactInput<T>): Fact<T> {
|
|
64
64
|
return this.wm.update(input);
|
|
65
65
|
}
|
|
66
66
|
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* and executes the first matching rule only.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { match } from '../../core';
|
|
8
|
+
import { match, RuntimeError } from '../../core';
|
|
9
9
|
import { IWorkingMemory } from '../../core/memory';
|
|
10
10
|
|
|
11
11
|
import {
|
|
@@ -93,7 +93,7 @@ export class SequentialStrategy {
|
|
|
93
93
|
if ('call' in item) {
|
|
94
94
|
const handler = actions[item.call];
|
|
95
95
|
if (!handler) {
|
|
96
|
-
throw new
|
|
96
|
+
throw new RuntimeError(`Action not found: ${item.call}`);
|
|
97
97
|
}
|
|
98
98
|
handler(activation.facts, wm);
|
|
99
99
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Compiles state machine definitions into an optimized format for execution.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { compileCondition } from '../../core';
|
|
7
|
+
import { compileCondition, CompilationError } from '../../core';
|
|
8
8
|
|
|
9
9
|
import {
|
|
10
10
|
StateMachineDefinition,
|
|
@@ -70,7 +70,7 @@ function compileAction(action: StateMachineActionItem): CompiledStateMachineActi
|
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
throw new
|
|
73
|
+
throw new CompilationError(`Unknown action format: ${JSON.stringify(action)}`);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
function compileActions(actions?: StateMachineActionItem[]): CompiledStateMachineAction[] {
|
|
@@ -160,7 +160,7 @@ function buildStateMap(
|
|
|
160
160
|
function validateStateMachine(definition: StateMachineDefinition): void {
|
|
161
161
|
// Check initial state exists
|
|
162
162
|
if (!definition.states[definition.initial]) {
|
|
163
|
-
throw new
|
|
163
|
+
throw new CompilationError(`Initial state '${definition.initial}' does not exist`);
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
// Validate all transition targets exist
|
|
@@ -201,7 +201,7 @@ function validateStateMachine(definition: StateMachineDefinition): void {
|
|
|
201
201
|
const targetExists = possibleTargets.some(t => allStateNames.has(t));
|
|
202
202
|
|
|
203
203
|
if (!targetExists && !allStateNames.has(target)) {
|
|
204
|
-
throw new
|
|
204
|
+
throw new CompilationError(
|
|
205
205
|
`Invalid transition target '${transition.target}' from state '${fullName}'`
|
|
206
206
|
);
|
|
207
207
|
}
|
|
@@ -209,7 +209,7 @@ function validateStateMachine(definition: StateMachineDefinition): void {
|
|
|
209
209
|
|
|
210
210
|
// Validate compound state has initial
|
|
211
211
|
if (state.states && !state.initial) {
|
|
212
|
-
throw new
|
|
212
|
+
throw new CompilationError(`Compound state '${fullName}' must have an 'initial' property`);
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
// Recursively validate nested states
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
* Each instance tracks its own state, context, and history.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import { RuntimeError } from '../../core';
|
|
9
|
+
|
|
8
10
|
import {
|
|
9
11
|
CompiledStateMachineDefinition,
|
|
10
12
|
CompiledStateDefinition,
|
|
@@ -557,7 +559,7 @@ class StateMachineInstance implements IStateMachineInstance {
|
|
|
557
559
|
);
|
|
558
560
|
executed.push(`call:${action.handler}`);
|
|
559
561
|
} else if (this.definition.config.strict) {
|
|
560
|
-
throw new
|
|
562
|
+
throw new RuntimeError(`Action handler not found: ${action.handler}`);
|
|
561
563
|
}
|
|
562
564
|
}
|
|
563
565
|
break;
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
import {
|
|
6
6
|
compileCondition,
|
|
7
7
|
normalizeShape,
|
|
8
|
-
Condition
|
|
8
|
+
Condition,
|
|
9
|
+
CompilationError
|
|
9
10
|
} from '../../core';
|
|
10
11
|
|
|
11
12
|
import {
|
|
@@ -88,7 +89,7 @@ function resolveWeight(weight: number | string): number {
|
|
|
88
89
|
if (isSemanticPriority(weight)) {
|
|
89
90
|
return SEMANTIC_PRIORITY_VALUES[weight];
|
|
90
91
|
}
|
|
91
|
-
throw new
|
|
92
|
+
throw new CompilationError(`Invalid weight value: ${weight}. Must be a number (0-1) or SemanticPriority`);
|
|
92
93
|
}
|
|
93
94
|
|
|
94
95
|
/**
|
|
@@ -100,7 +101,7 @@ function compileCriterion(criterion: UtilityCriterion): CompiledUtilityCriterion
|
|
|
100
101
|
|
|
101
102
|
// For numeric weights, validate 0-1 range (semantic weights use different scale)
|
|
102
103
|
if (typeof criterion.weight === 'number' && (numericWeight < 0 || numericWeight > 1)) {
|
|
103
|
-
throw new
|
|
104
|
+
throw new CompilationError(`Numeric criterion weight must be between 0 and 1, got ${numericWeight} for "${criterion.id}"`);
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
return {
|
|
@@ -119,7 +120,7 @@ function normalizeWeights(criteria: CompiledUtilityCriterion[]): void {
|
|
|
119
120
|
const totalWeight = criteria.reduce((sum, c) => sum + c.weight, 0);
|
|
120
121
|
|
|
121
122
|
if (totalWeight === 0) {
|
|
122
|
-
throw new
|
|
123
|
+
throw new CompilationError('At least one criterion must have a non-zero weight');
|
|
123
124
|
}
|
|
124
125
|
|
|
125
126
|
for (const criterion of criteria) {
|
|
@@ -158,7 +159,7 @@ export function compileUtilityRule(rule: UtilityRule, index: number = 0): Compil
|
|
|
158
159
|
export function compileUtilityRuleSet(ruleSet: UtilityRuleSet): CompiledUtilityRuleSet {
|
|
159
160
|
// Validate criteria
|
|
160
161
|
if (!ruleSet.criteria || ruleSet.criteria.length === 0) {
|
|
161
|
-
throw new
|
|
162
|
+
throw new CompilationError('UtilityRuleSet must have at least one criterion');
|
|
162
163
|
}
|
|
163
164
|
|
|
164
165
|
// Check if any criteria use semantic weights
|
|
@@ -176,7 +177,7 @@ export function compileUtilityRuleSet(ruleSet: UtilityRuleSet): CompiledUtilityR
|
|
|
176
177
|
// Numeric weights: validate they sum to ~1.0, then normalize for precision
|
|
177
178
|
const totalWeight = compiledCriteria.reduce((sum, c) => sum + c.weight, 0);
|
|
178
179
|
if (Math.abs(totalWeight - 1.0) > 0.01) {
|
|
179
|
-
throw new
|
|
180
|
+
throw new CompilationError(`Criterion weights must sum to 1.0, got ${totalWeight.toFixed(4)}`);
|
|
180
181
|
}
|
|
181
182
|
// Normalize for floating point precision
|
|
182
183
|
normalizeWeights(compiledCriteria);
|
|
@@ -186,7 +187,7 @@ export function compileUtilityRuleSet(ruleSet: UtilityRuleSet): CompiledUtilityR
|
|
|
186
187
|
const criterionIds = new Set(compiledCriteria.map(c => c.id));
|
|
187
188
|
for (const rule of ruleSet.rules) {
|
|
188
189
|
if (!criterionIds.has(rule.criterion)) {
|
|
189
|
-
throw new
|
|
190
|
+
throw new CompilationError(`Rule "${rule.id}" references unknown criterion "${rule.criterion}"`);
|
|
190
191
|
}
|
|
191
192
|
}
|
|
192
193
|
|
|
@@ -202,7 +203,7 @@ export function compileUtilityRuleSet(ruleSet: UtilityRuleSet): CompiledUtilityR
|
|
|
202
203
|
mode: 'utility',
|
|
203
204
|
schema: ruleSet.shape ? normalizeShape(ruleSet.shape) : { type: 'object' },
|
|
204
205
|
criteria: compiledCriteria,
|
|
205
|
-
rules: ruleSet.rules.map((rule, index) => compileUtilityRule(rule, index)),
|
|
206
|
+
rules: ruleSet.rules.filter(r => !r.disabled).map((rule, index) => compileUtilityRule(rule, index)),
|
|
206
207
|
config
|
|
207
208
|
};
|
|
208
209
|
}
|
|
@@ -81,7 +81,7 @@ export class UtilityEngine implements IRuleEngine<CompiledUtilityRuleSet, Utilit
|
|
|
81
81
|
// IWorkingMemory Implementation
|
|
82
82
|
// ========================================
|
|
83
83
|
|
|
84
|
-
add(input: FactInput): Fact {
|
|
84
|
+
add<T = Record<string, any>>(input: FactInput<T>): Fact<T> {
|
|
85
85
|
return this.wm.add(input);
|
|
86
86
|
}
|
|
87
87
|
|
|
@@ -89,7 +89,7 @@ export class UtilityEngine implements IRuleEngine<CompiledUtilityRuleSet, Utilit
|
|
|
89
89
|
return this.wm.remove(factId);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
update(input: FactInput): Fact {
|
|
92
|
+
update<T = Record<string, any>>(input: FactInput<T>): Fact<T> {
|
|
93
93
|
return this.wm.update(input);
|
|
94
94
|
}
|
|
95
95
|
|
package/src/index.ts
CHANGED
|
@@ -81,7 +81,8 @@ export type {
|
|
|
81
81
|
export {
|
|
82
82
|
ScoringStrategy,
|
|
83
83
|
compileScoringRuleSet,
|
|
84
|
-
scoringStrategy
|
|
84
|
+
scoringStrategy,
|
|
85
|
+
createScoreFunction
|
|
85
86
|
} from './engines/scoring';
|
|
86
87
|
export type {
|
|
87
88
|
ScoringRule,
|
|
@@ -90,11 +91,14 @@ export type {
|
|
|
90
91
|
CompiledScoringRuleSet,
|
|
91
92
|
ScoringOptions,
|
|
92
93
|
ScoringResult,
|
|
94
|
+
ScoreFunction,
|
|
93
95
|
ScoreFunctionRegistry,
|
|
94
96
|
ScoringMethod,
|
|
95
97
|
OutputBounds,
|
|
96
98
|
ScoringCategory,
|
|
97
99
|
CategoryResult,
|
|
100
|
+
ConfidenceConfig,
|
|
101
|
+
ConfidenceBreakdown,
|
|
98
102
|
OverrideEffect,
|
|
99
103
|
OverrideDefinition,
|
|
100
104
|
ForceTierOverride,
|
|
@@ -375,6 +379,10 @@ export type {
|
|
|
375
379
|
|
|
376
380
|
export { soundex, nysiis, caverphone2, cosineSimilarity } from './functions';
|
|
377
381
|
|
|
382
|
+
// Typed Errors (re-exported from core for convenience)
|
|
383
|
+
export { BOEError, CompilationError, RuntimeError } from './core/errors';
|
|
384
|
+
export type { ErrorContext } from './core/errors';
|
|
385
|
+
|
|
378
386
|
// Temporal Decay (re-exported from core for convenience)
|
|
379
387
|
export {
|
|
380
388
|
calculateDecayMultiplier,
|