@higher.archi/boe 1.0.8 → 1.0.9
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/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/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/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/defeasible/compiler.js +1 -1
- package/dist/engines/defeasible/compiler.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/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/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/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/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 +7 -6
- package/dist/engines/scoring/compiler.js.map +1 -1
- package/dist/engines/scoring/strategy.d.ts.map +1 -1
- package/dist/engines/scoring/strategy.js +2 -2
- package/dist/engines/scoring/strategy.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/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/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- 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/types/rule.ts +1 -0
- package/src/engines/backward/compiler.ts +1 -1
- package/src/engines/bayesian/compiler.ts +9 -8
- package/src/engines/bayesian/strategy.ts +7 -6
- package/src/engines/constraint/compiler.ts +12 -11
- package/src/engines/defeasible/compiler.ts +1 -1
- package/src/engines/expert/compiler.ts +8 -7
- package/src/engines/forward/compiler.ts +6 -5
- package/src/engines/forward/strategy.ts +6 -5
- package/src/engines/fuzzy/compiler.ts +1 -1
- package/src/engines/fuzzy/strategy.ts +9 -9
- package/src/engines/monte-carlo/compiler.ts +10 -9
- 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 +9 -7
- package/src/engines/scoring/strategy.ts +4 -3
- package/src/engines/sequential/compiler.ts +6 -5
- 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/index.ts +4 -0
|
@@ -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
|
}
|
package/src/index.ts
CHANGED
|
@@ -375,6 +375,10 @@ export type {
|
|
|
375
375
|
|
|
376
376
|
export { soundex, nysiis, caverphone2, cosineSimilarity } from './functions';
|
|
377
377
|
|
|
378
|
+
// Typed Errors (re-exported from core for convenience)
|
|
379
|
+
export { BOEError, CompilationError, RuntimeError } from './core/errors';
|
|
380
|
+
export type { ErrorContext } from './core/errors';
|
|
381
|
+
|
|
378
382
|
// Temporal Decay (re-exported from core for convenience)
|
|
379
383
|
export {
|
|
380
384
|
calculateDecayMultiplier,
|