@higher.archi/boe 1.0.28 → 1.0.30
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/engines/decay/engine.d.ts +32 -1
- package/dist/engines/decay/engine.d.ts.map +1 -1
- package/dist/engines/decay/engine.js +69 -0
- package/dist/engines/decay/engine.js.map +1 -1
- package/dist/engines/decay/index.d.ts +1 -1
- package/dist/engines/decay/index.d.ts.map +1 -1
- package/dist/engines/decay/index.js.map +1 -1
- package/dist/engines/decay/strategy.d.ts +4 -2
- package/dist/engines/decay/strategy.d.ts.map +1 -1
- package/dist/engines/decay/strategy.js +24 -0
- package/dist/engines/decay/strategy.js.map +1 -1
- package/dist/engines/decay/types.d.ts +9 -0
- package/dist/engines/decay/types.d.ts.map +1 -1
- package/dist/engines/loyalty/compiler.d.ts +11 -0
- package/dist/engines/loyalty/compiler.d.ts.map +1 -0
- package/dist/engines/loyalty/compiler.js +144 -0
- package/dist/engines/loyalty/compiler.js.map +1 -0
- package/dist/engines/loyalty/engine.d.ts +76 -0
- package/dist/engines/loyalty/engine.d.ts.map +1 -0
- package/dist/engines/loyalty/engine.js +132 -0
- package/dist/engines/loyalty/engine.js.map +1 -0
- package/dist/engines/loyalty/index.d.ts +8 -0
- package/dist/engines/loyalty/index.d.ts.map +1 -0
- package/dist/engines/loyalty/index.js +17 -0
- package/dist/engines/loyalty/index.js.map +1 -0
- package/dist/engines/loyalty/strategy.d.ts +35 -0
- package/dist/engines/loyalty/strategy.d.ts.map +1 -0
- package/dist/engines/loyalty/strategy.js +405 -0
- package/dist/engines/loyalty/strategy.js.map +1 -0
- package/dist/engines/loyalty/types.d.ts +190 -0
- package/dist/engines/loyalty/types.d.ts.map +1 -0
- package/dist/engines/loyalty/types.js +11 -0
- package/dist/engines/loyalty/types.js.map +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/engines/decay/engine.ts +93 -1
- package/src/engines/decay/index.ts +2 -1
- package/src/engines/decay/strategy.ts +33 -0
- package/src/engines/decay/types.ts +10 -0
- package/src/engines/loyalty/compiler.ts +174 -0
- package/src/engines/loyalty/engine.ts +174 -0
- package/src/engines/loyalty/index.ts +43 -0
- package/src/engines/loyalty/strategy.ts +532 -0
- package/src/engines/loyalty/types.ts +252 -0
- package/src/index.ts +39 -1
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loyalty Engine Types
|
|
3
|
+
*
|
|
4
|
+
* Point ledger engine that manages earning rules with category multipliers,
|
|
5
|
+
* point transactions (earn/redeem/transfer/expire), tier-qualified balances,
|
|
6
|
+
* and promotion stacking. Unlike other BOE engines, the Loyalty engine
|
|
7
|
+
* maintains running balance state across operations.
|
|
8
|
+
*/
|
|
9
|
+
import type { Condition } from '../../core/types/condition';
|
|
10
|
+
/** Loyalty strategy to use */
|
|
11
|
+
export type LoyaltyStrategy = 'earning' | 'redemption' | 'tier-evaluation';
|
|
12
|
+
/** Point transaction type */
|
|
13
|
+
export type PointTransactionType = 'earn' | 'redeem' | 'expire' | 'transfer' | 'adjust';
|
|
14
|
+
/** Member tier status */
|
|
15
|
+
export type TierStatus = 'qualified' | 'at-risk' | 'downgrade-pending' | 'locked';
|
|
16
|
+
/** Qualifying metric for tier evaluation */
|
|
17
|
+
export type QualifyingMetric = 'points-earned' | 'qualifying-spend' | 'qualifying-nights' | 'qualifying-flights';
|
|
18
|
+
/** Evaluation period for tier assessment */
|
|
19
|
+
export type EvaluationPeriod = 'rolling-12-months' | 'calendar-year' | 'custom';
|
|
20
|
+
/** An earning rule that maps activities to points */
|
|
21
|
+
export type EarningRule = {
|
|
22
|
+
id: string;
|
|
23
|
+
name?: string;
|
|
24
|
+
category?: string;
|
|
25
|
+
baseRate: number;
|
|
26
|
+
multiplier?: number;
|
|
27
|
+
conditions?: Condition[];
|
|
28
|
+
bonusPoints?: number;
|
|
29
|
+
promotionId?: string;
|
|
30
|
+
};
|
|
31
|
+
/** A redemption option specifying how points can be spent */
|
|
32
|
+
export type RedemptionOption = {
|
|
33
|
+
id: string;
|
|
34
|
+
name?: string;
|
|
35
|
+
type: string;
|
|
36
|
+
pointsRequired: number;
|
|
37
|
+
value: number;
|
|
38
|
+
unit?: string;
|
|
39
|
+
conditions?: Condition[];
|
|
40
|
+
};
|
|
41
|
+
/** A tier definition with qualifying thresholds and benefits */
|
|
42
|
+
export type LoyaltyTierDefinition = {
|
|
43
|
+
id: string;
|
|
44
|
+
name: string;
|
|
45
|
+
qualifyingThreshold: number;
|
|
46
|
+
qualifyingMetric: QualifyingMetric;
|
|
47
|
+
benefits: string[];
|
|
48
|
+
multiplierBonus?: number;
|
|
49
|
+
retentionThreshold?: number;
|
|
50
|
+
};
|
|
51
|
+
/** A promotion rule that stacks multipliers or bonus points */
|
|
52
|
+
export type PromotionRule = {
|
|
53
|
+
id: string;
|
|
54
|
+
name?: string;
|
|
55
|
+
multiplier?: number;
|
|
56
|
+
bonusPoints?: number;
|
|
57
|
+
categories?: string[];
|
|
58
|
+
startDate?: string;
|
|
59
|
+
endDate?: string;
|
|
60
|
+
};
|
|
61
|
+
/** Expiration policy for points */
|
|
62
|
+
export type ExpirationPolicy = {
|
|
63
|
+
inactivityDays?: number;
|
|
64
|
+
absoluteMonths?: number;
|
|
65
|
+
graceDays?: number;
|
|
66
|
+
};
|
|
67
|
+
/** A single point transaction record */
|
|
68
|
+
export type PointTransaction = {
|
|
69
|
+
id: string;
|
|
70
|
+
memberId: string;
|
|
71
|
+
type: PointTransactionType;
|
|
72
|
+
points: number;
|
|
73
|
+
category?: string;
|
|
74
|
+
ruleId?: string;
|
|
75
|
+
timestamp: string;
|
|
76
|
+
metadata?: Record<string, any>;
|
|
77
|
+
};
|
|
78
|
+
/** Running balance for a member */
|
|
79
|
+
export type MemberBalance = {
|
|
80
|
+
memberId: string;
|
|
81
|
+
totalEarned: number;
|
|
82
|
+
totalRedeemed: number;
|
|
83
|
+
totalExpired: number;
|
|
84
|
+
currentBalance: number;
|
|
85
|
+
qualifyingPoints: number;
|
|
86
|
+
currentTier?: string;
|
|
87
|
+
tierQualifiedAt?: string;
|
|
88
|
+
};
|
|
89
|
+
type LoyaltyRuleSetBase = {
|
|
90
|
+
id: string;
|
|
91
|
+
name?: string;
|
|
92
|
+
mode: 'loyalty';
|
|
93
|
+
tiers?: LoyaltyTierDefinition[];
|
|
94
|
+
expirationPolicy?: ExpirationPolicy;
|
|
95
|
+
promotions?: PromotionRule[];
|
|
96
|
+
};
|
|
97
|
+
/** Earning strategy: compute points earned from purchase/activity events */
|
|
98
|
+
export type EarningRuleSet = LoyaltyRuleSetBase & {
|
|
99
|
+
strategy: 'earning';
|
|
100
|
+
earningRules: EarningRule[];
|
|
101
|
+
defaultRate?: number;
|
|
102
|
+
};
|
|
103
|
+
/** Redemption strategy: process point redemption requests */
|
|
104
|
+
export type RedemptionRuleSet = LoyaltyRuleSetBase & {
|
|
105
|
+
strategy: 'redemption';
|
|
106
|
+
redemptionOptions: RedemptionOption[];
|
|
107
|
+
};
|
|
108
|
+
/** Tier evaluation strategy: evaluate members against tier thresholds */
|
|
109
|
+
export type TierEvaluationRuleSet = LoyaltyRuleSetBase & {
|
|
110
|
+
strategy: 'tier-evaluation';
|
|
111
|
+
evaluationPeriod?: EvaluationPeriod;
|
|
112
|
+
tiers: LoyaltyTierDefinition[];
|
|
113
|
+
};
|
|
114
|
+
export type LoyaltyRuleSet = EarningRuleSet | RedemptionRuleSet | TierEvaluationRuleSet;
|
|
115
|
+
type CompiledLoyaltyRuleSetBase = {
|
|
116
|
+
id: string;
|
|
117
|
+
name?: string;
|
|
118
|
+
mode: 'loyalty';
|
|
119
|
+
tiers: LoyaltyTierDefinition[];
|
|
120
|
+
expirationPolicy: ExpirationPolicy;
|
|
121
|
+
promotions: PromotionRule[];
|
|
122
|
+
};
|
|
123
|
+
export type CompiledEarningRuleSet = CompiledLoyaltyRuleSetBase & {
|
|
124
|
+
strategy: 'earning';
|
|
125
|
+
earningRules: EarningRule[];
|
|
126
|
+
defaultRate: number;
|
|
127
|
+
};
|
|
128
|
+
export type CompiledRedemptionRuleSet = CompiledLoyaltyRuleSetBase & {
|
|
129
|
+
strategy: 'redemption';
|
|
130
|
+
redemptionOptions: RedemptionOption[];
|
|
131
|
+
};
|
|
132
|
+
export type CompiledTierEvaluationRuleSet = CompiledLoyaltyRuleSetBase & {
|
|
133
|
+
strategy: 'tier-evaluation';
|
|
134
|
+
evaluationPeriod: EvaluationPeriod;
|
|
135
|
+
tiers: LoyaltyTierDefinition[];
|
|
136
|
+
};
|
|
137
|
+
export type CompiledLoyaltyRuleSet = CompiledEarningRuleSet | CompiledRedemptionRuleSet | CompiledTierEvaluationRuleSet;
|
|
138
|
+
/** Result from earning strategy execution */
|
|
139
|
+
export type EarningResult = {
|
|
140
|
+
memberId: string;
|
|
141
|
+
transactions: PointTransaction[];
|
|
142
|
+
pointsEarned: number;
|
|
143
|
+
bonusPointsEarned: number;
|
|
144
|
+
promotionsApplied: string[];
|
|
145
|
+
newBalance: number;
|
|
146
|
+
executionTimeMs: number;
|
|
147
|
+
};
|
|
148
|
+
/** Result from redemption strategy execution */
|
|
149
|
+
export type RedemptionResult = {
|
|
150
|
+
memberId: string;
|
|
151
|
+
redemption: PointTransaction;
|
|
152
|
+
pointsRedeemed: number;
|
|
153
|
+
redemptionValue: number;
|
|
154
|
+
remainingBalance: number;
|
|
155
|
+
executionTimeMs: number;
|
|
156
|
+
};
|
|
157
|
+
/** Per-member tier evaluation result */
|
|
158
|
+
export type MemberTierResult = {
|
|
159
|
+
memberId: string;
|
|
160
|
+
currentTier: string;
|
|
161
|
+
previousTier?: string;
|
|
162
|
+
qualifyingPoints: number;
|
|
163
|
+
nextTierThreshold?: number;
|
|
164
|
+
pointsToNextTier?: number;
|
|
165
|
+
status: TierStatus;
|
|
166
|
+
benefits: string[];
|
|
167
|
+
};
|
|
168
|
+
/** Result from tier-evaluation strategy execution */
|
|
169
|
+
export type TierEvaluationResult = {
|
|
170
|
+
members: MemberTierResult[];
|
|
171
|
+
tierDistribution: Record<string, number>;
|
|
172
|
+
executionTimeMs: number;
|
|
173
|
+
};
|
|
174
|
+
/** Union of all loyalty results */
|
|
175
|
+
export type LoyaltyResult = EarningResult | RedemptionResult | TierEvaluationResult;
|
|
176
|
+
/** Options for earning execution */
|
|
177
|
+
export type LoyaltyOptions = {
|
|
178
|
+
asOf?: Date;
|
|
179
|
+
};
|
|
180
|
+
/** Result from ingest() -- streaming earning with running balance */
|
|
181
|
+
export type LoyaltyIngestResult = {
|
|
182
|
+
memberId: string;
|
|
183
|
+
pointsEarned: number;
|
|
184
|
+
bonusPointsEarned: number;
|
|
185
|
+
promotionsApplied: string[];
|
|
186
|
+
newBalance: number;
|
|
187
|
+
transactions: PointTransaction[];
|
|
188
|
+
};
|
|
189
|
+
export {};
|
|
190
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/engines/loyalty/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAM5D,8BAA8B;AAC9B,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,YAAY,GAAG,iBAAiB,CAAC;AAE3E,6BAA6B;AAC7B,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,UAAU,GAAG,QAAQ,CAAC;AAExF,yBAAyB;AACzB,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG,SAAS,GAAG,mBAAmB,GAAG,QAAQ,CAAC;AAElF,4CAA4C;AAC5C,MAAM,MAAM,gBAAgB,GAAG,eAAe,GAAG,kBAAkB,GAAG,mBAAmB,GAAG,oBAAoB,CAAC;AAEjH,4CAA4C;AAC5C,MAAM,MAAM,gBAAgB,GAAG,mBAAm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AG;IAC3B,IAAI,CAAC,EAAE,IAAI,CAAC;CACb,CAAC;AAEF,qEAAqE;AACrE,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,gBAAgB,EAAE,CAAC;CAClC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Loyalty Engine Types
|
|
4
|
+
*
|
|
5
|
+
* Point ledger engine that manages earning rules with category multipliers,
|
|
6
|
+
* point transactions (earn/redeem/transfer/expire), tier-qualified balances,
|
|
7
|
+
* and promotion stacking. Unlike other BOE engines, the Loyalty engine
|
|
8
|
+
* maintains running balance state across operations.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/engines/loyalty/types.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG"}
|
package/dist/index.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export { EnsembleEngine } from './engines/ensemble';
|
|
|
28
28
|
export { SentimentEngine } from './engines/sentiment';
|
|
29
29
|
export { NegotiationEngine } from './engines/negotiation';
|
|
30
30
|
export { DecayEngine } from './engines/decay';
|
|
31
|
+
export { LoyaltyEngine } from './engines/loyalty';
|
|
31
32
|
export * from './core';
|
|
32
33
|
export { ForwardChainingStrategy, compileForwardRuleSet, compileForwardRule, forwardStrategy } from './engines/forward';
|
|
33
34
|
export type { ForwardRule, ForwardRuleSet, ForwardConfig, CompiledForwardRuleSet, CompiledForwardRule, ForwardOptions, ForwardResult, ActionRegistry, ActionHandler } from './engines/forward';
|
|
@@ -67,7 +68,9 @@ export type { SentimentStrategy, SentimentLabel, SentimentLexicon, CompiledSenti
|
|
|
67
68
|
export { NegotiationExecutor, compileNegotiationRuleSet, negotiationStrategy } from './engines/negotiation';
|
|
68
69
|
export type { NegotiationStrategy, ConcessionStyle, DealOutcome, DimensionDirection, NegotiationDimension, PartyPosition, PartyProfile, ValueFunction, CompiledValueFunction, CompiledPartyProfile, ZopaAnalysisConfig, ConcessionPlanningConfig, PackageOptimizationConfig, ZopaAnalysisRuleSet, ConcessionPlanningRuleSet, PackageOptimizationRuleSet, NegotiationRuleSet, CompiledZopaAnalysisRuleSet, CompiledConcessionPlanningRuleSet, CompiledPackageOptimizationRuleSet, CompiledNegotiationRuleSet, ZopaRange, ConcessionStep, PackageCandidate, NegotiationResult, NegotiationOptions } from './engines/negotiation';
|
|
69
70
|
export { DecayExecutor, compileDecayRuleSet, decayStrategy, URGENCY_THRESHOLDS, resolveUrgencyTier } from './engines/decay';
|
|
70
|
-
export type { DecayStrategy, UrgencyTier, ReEngagementEffect, DecayAggregation, DecayDimension, CompiledDecayDimension, ReEngagementRule, SingleDimensionDecayRuleSet, MultiDimensionDecayRuleSet, EventDrivenDecayRuleSet, DecayRuleSet, CompiledSingleDimensionDecayRuleSet, CompiledMultiDimensionDecayRuleSet, CompiledEventDrivenDecayRuleSet, CompiledDecayRuleSet, DimensionDecayResult, ReEngagementEvent, EntityDecayResult, DecayResult, DecayOptions } from './engines/decay';
|
|
71
|
+
export type { DecayStrategy, UrgencyTier, ReEngagementEffect, DecayAggregation, DecayDimension, CompiledDecayDimension, ReEngagementRule, SingleDimensionDecayRuleSet, MultiDimensionDecayRuleSet, EventDrivenDecayRuleSet, DecayRuleSet, CompiledSingleDimensionDecayRuleSet, CompiledMultiDimensionDecayRuleSet, CompiledEventDrivenDecayRuleSet, CompiledDecayRuleSet, DimensionDecayResult, ReEngagementEvent, EntityDecayResult, DecayResult, DecayOptions, DecayIngestResult } from './engines/decay';
|
|
72
|
+
export { LoyaltyExecutor, compileLoyaltyRuleSet, loyaltyStrategy } from './engines/loyalty';
|
|
73
|
+
export type { LoyaltyStrategy, PointTransactionType, TierStatus, QualifyingMetric, EvaluationPeriod, EarningRule, RedemptionOption, LoyaltyTierDefinition, PromotionRule, ExpirationPolicy, PointTransaction, MemberBalance, EarningRuleSet, RedemptionRuleSet, TierEvaluationRuleSet, LoyaltyRuleSet, CompiledEarningRuleSet, CompiledRedemptionRuleSet, CompiledTierEvaluationRuleSet, CompiledLoyaltyRuleSet, EarningResult, RedemptionResult, MemberTierResult, TierEvaluationResult, LoyaltyResult, LoyaltyOptions, LoyaltyIngestResult } from './engines/loyalty';
|
|
71
74
|
export { soundex, nysiis, caverphone2, cosineSimilarity } from './functions';
|
|
72
75
|
export { BOEError, CompilationError, RuntimeError } from './core/errors';
|
|
73
76
|
export type { ErrorContext } from './core/errors';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAOH,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,aAAa,EA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,EACb,cAAc,EACd,mBAAmB,EACpB,MAAM,mBAAmB,CAAC;AAM3B,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAG7E,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACzE,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAGlD,OAAO,EACL,wBAAwB,EACxB,qBAAqB,EACtB,MAAM,yBAAyB,CAAC;AACjC,YAAY,EACV,UAAU,EACV,aAAa,EACb,WAAW,EACX,SAAS,EACV,MAAM,yBAAyB,CAAC;AAMjC,cAAc,UAAU,CAAC;AAMzB,cAAc,aAAa,CAAC;AAM5B,cAAc,WAAW,CAAC;AAM1B,cAAc,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -29,9 +29,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
29
29
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
30
30
|
};
|
|
31
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
-
exports.
|
|
33
|
-
exports.
|
|
34
|
-
exports.resolveDecayTimestamp = exports.calculateDecayMultiplier = exports.RuntimeError = exports.CompilationError = exports.BOEError = exports.cosineSimilarity = exports.caverphone2 = exports.nysiis = exports.soundex = exports.resolveUrgencyTier = exports.URGENCY_THRESHOLDS = exports.decayStrategy = exports.compileDecayRuleSet = exports.DecayExecutor = exports.negotiationStrategy = exports.compileNegotiationRuleSet = exports.NegotiationExecutor = exports.resolveSentimentLabel = exports.SENTIMENT_DEFAULTS = exports.sentimentStrategy = exports.compileSentimentRuleSet = exports.SentimentExecutor = exports.resolveTrendDirection = exports.resolveConfidenceBracket = exports.isHorizonPreset = exports.isSmoothingPreset = exports.HORIZON_PRESET_VALUES = exports.SMOOTHING_PRESET_VALUES = exports.predictionStrategy = exports.compilePredictionRuleSet = exports.PredictionExecutor = void 0;
|
|
32
|
+
exports.ConstraintStrategy = exports.stateMachineStrategy = exports.compileStateMachineDefinition = exports.compileStateMachine = exports.StateMachineStrategy = exports.monteCarloStrategy = exports.compileMonteCarloRuleSet = exports.MonteCarloStrategy = exports.SEMANTIC_LIKELIHOODS = exports.parseLikelihood = exports.bayesianStrategy = exports.compileBayesianRule = exports.compileBayesianRuleSet = exports.BayesianStrategy = exports.autoAdjustCoverage = exports.analyzeCoverage = exports.compileFuzzyVariable = exports.fuzzyStrategy = exports.compileFuzzyRuleSet = exports.FuzzyStrategy = exports.sequentialStrategy = exports.compileSequentialRuleSet = exports.SequentialStrategy = exports.createScoreFunction = exports.scoringStrategy = exports.compileScoringRuleSet = exports.ScoringStrategy = exports.backwardStrategy = exports.compileBackwardRuleSet = exports.BackwardChainingStrategy = exports.forwardStrategy = exports.compileForwardRule = exports.compileForwardRuleSet = exports.ForwardChainingStrategy = exports.LoyaltyEngine = exports.DecayEngine = exports.NegotiationEngine = exports.SentimentEngine = exports.EnsembleEngine = exports.PricingEngine = exports.UtilityEngine = exports.ConstraintEngine = exports.StateMachineEngine = exports.MonteCarloEngine = exports.BayesianEngine = exports.FuzzyEngine = exports.SequentialEngine = exports.ScoringEngine = exports.BackwardEngine = exports.ForwardEngine = void 0;
|
|
33
|
+
exports.resolveMovement = exports.resolvePercentileLabel = exports.isKFactorPreset = exports.K_FACTOR_VALUES = exports.rankingStrategy = exports.compileRankingRuleSet = exports.RankingExecutor = exports.RankingEngine = exports.scoringMember = exports.expertMember = exports.monteCarloMember = exports.fuzzyMember = exports.bayesianMember = exports.summarizeEnsemble = exports.ensembleStrategy = exports.compileEnsembleRuleSet = exports.EnsembleStrategy = exports.getCurrencyInfo = exports.CURRENCIES = exports.applyMinMax = exports.calculateDiscount = exports.round = exports.formatPercent = exports.formatNumber = exports.formatCurrency = exports.calculateVolume = exports.calculateGraduated = exports.calculateFlat = exports.pricingEngine = exports.pricingStrategy = exports.compilePricingRule = exports.compilePricingRuleSet = exports.PricingStrategy = exports.buildAvailableRefs = exports.hasInterpolation = exports.interpolate = exports.compileTemplate = exports.expertStrategy = exports.compileExpertRuleSet = exports.ExpertStrategy = exports.ExpertEngine = exports.compileDefeasibleRuleSet = exports.DefeasibleEngine = exports.utilityStrategy = exports.compileUtilityRule = exports.compileUtilityRuleSet = exports.UtilityStrategy = exports.SEMANTIC_WEIGHTS = exports.constraintStrategy = exports.compileConstraintRuleSet = void 0;
|
|
34
|
+
exports.resolveDecayTimestamp = exports.calculateDecayMultiplier = exports.RuntimeError = exports.CompilationError = exports.BOEError = exports.cosineSimilarity = exports.caverphone2 = exports.nysiis = exports.soundex = exports.loyaltyStrategy = exports.compileLoyaltyRuleSet = exports.LoyaltyExecutor = exports.resolveUrgencyTier = exports.URGENCY_THRESHOLDS = exports.decayStrategy = exports.compileDecayRuleSet = exports.DecayExecutor = exports.negotiationStrategy = exports.compileNegotiationRuleSet = exports.NegotiationExecutor = exports.resolveSentimentLabel = exports.SENTIMENT_DEFAULTS = exports.sentimentStrategy = exports.compileSentimentRuleSet = exports.SentimentExecutor = exports.resolveTrendDirection = exports.resolveConfidenceBracket = exports.isHorizonPreset = exports.isSmoothingPreset = exports.HORIZON_PRESET_VALUES = exports.SMOOTHING_PRESET_VALUES = exports.predictionStrategy = exports.compilePredictionRuleSet = exports.PredictionExecutor = exports.PredictionEngine = void 0;
|
|
35
35
|
// ========================================
|
|
36
36
|
// Engines
|
|
37
37
|
// ========================================
|
|
@@ -66,6 +66,8 @@ var negotiation_1 = require("./engines/negotiation");
|
|
|
66
66
|
Object.defineProperty(exports, "NegotiationEngine", { enumerable: true, get: function () { return negotiation_1.NegotiationEngine; } });
|
|
67
67
|
var decay_1 = require("./engines/decay");
|
|
68
68
|
Object.defineProperty(exports, "DecayEngine", { enumerable: true, get: function () { return decay_1.DecayEngine; } });
|
|
69
|
+
var loyalty_1 = require("./engines/loyalty");
|
|
70
|
+
Object.defineProperty(exports, "LoyaltyEngine", { enumerable: true, get: function () { return loyalty_1.LoyaltyEngine; } });
|
|
69
71
|
// ========================================
|
|
70
72
|
// Core Types & Utilities
|
|
71
73
|
// ========================================
|
|
@@ -223,6 +225,11 @@ Object.defineProperty(exports, "compileDecayRuleSet", { enumerable: true, get: f
|
|
|
223
225
|
Object.defineProperty(exports, "decayStrategy", { enumerable: true, get: function () { return decay_2.decayStrategy; } });
|
|
224
226
|
Object.defineProperty(exports, "URGENCY_THRESHOLDS", { enumerable: true, get: function () { return decay_2.URGENCY_THRESHOLDS; } });
|
|
225
227
|
Object.defineProperty(exports, "resolveUrgencyTier", { enumerable: true, get: function () { return decay_2.resolveUrgencyTier; } });
|
|
228
|
+
// Loyalty
|
|
229
|
+
var loyalty_2 = require("./engines/loyalty");
|
|
230
|
+
Object.defineProperty(exports, "LoyaltyExecutor", { enumerable: true, get: function () { return loyalty_2.LoyaltyExecutor; } });
|
|
231
|
+
Object.defineProperty(exports, "compileLoyaltyRuleSet", { enumerable: true, get: function () { return loyalty_2.compileLoyaltyRuleSet; } });
|
|
232
|
+
Object.defineProperty(exports, "loyaltyStrategy", { enumerable: true, get: function () { return loyalty_2.loyaltyStrategy; } });
|
|
226
233
|
// ========================================
|
|
227
234
|
// Utility Functions (from old modules, re-exported for convenience)
|
|
228
235
|
// ========================================
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;;AAEH,2CAA2C;AAC3C,UAAU;AACV,2CAA2C;AAE3C,iEAAiE;AACjE,6CAAkD;AAAzC,wGAAA,aAAa,OAAA;AACtB,+CAAoD;AAA3C,0GAAA,cAAc,OAAA;AACvB,6CAAkD;AAAzC,wGAAA,aAAa,OAAA;AACtB,mDAAwD;AAA/C,8GAAA,gBAAgB,OAAA;AACzB,yCAA8C;AAArC,oGAAA,WAAW,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AAA,eAAe,OAAA;AAgCjB,2CAA2C;AAC3C,oEAAoE;AACpE,2CAA2C;AAE3C,yCAA6E;AAApE,oGAAA,OAAO,OAAA;AAAE,mGAAA,MAAM,OAAA;AAAE,wGAAA,WAAW,OAAA;AAAE,6GAAA,gBAAgB,OAAA;AAEvD,uDAAuD;AACvD,wCAAyE;AAAhE,kGAAA,QAAQ,OAAA;AAAE,0GAAA,gBAAgB,OAAA;AAAE,sGAAA,YAAY,OAAA;AAGjD,yDAAyD;AACzD,iDAGiC;AAF/B,iHAAA,wBAAwB,OAAA;AACxB,8GAAA,qBAAqB,OAAA;AASvB,2CAA2C;AAC3C,wCAAwC;AACxC,2CAA2C;AAE3C,2CAAyB;AAEzB,2CAA2C;AAC3C,iDAAiD;AACjD,2CAA2C;AAE3C,8CAA4B;AAE5B,2CAA2C;AAC3C,uCAAuC;AACvC,2CAA2C;AAE3C,4CAA0B;AAE1B,2CAA2C;AAC3C,8CAA8C;AAC9C,2CAA2C;AAE3C,8CAA4B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@higher.archi/boe",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.30",
|
|
4
4
|
"description": "A multi-strategy rule engine supporting forward chaining, backward chaining, scoring, sequential, fuzzy logic, and Bayesian inference",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -26,14 +26,26 @@ import {
|
|
|
26
26
|
import type {
|
|
27
27
|
CompiledDecayRuleSet,
|
|
28
28
|
DecayOptions,
|
|
29
|
-
DecayResult
|
|
29
|
+
DecayResult,
|
|
30
|
+
DecayIngestResult,
|
|
31
|
+
UrgencyTier
|
|
30
32
|
} from './types';
|
|
31
33
|
|
|
32
34
|
import { DecayExecutor } from './strategy';
|
|
33
35
|
|
|
36
|
+
/** Internal accumulator for streaming ingest */
|
|
37
|
+
type DecayStreamState = {
|
|
38
|
+
ruleSetId: string;
|
|
39
|
+
freshnessSum: number;
|
|
40
|
+
count: number;
|
|
41
|
+
tierDistribution: Record<UrgencyTier, number>;
|
|
42
|
+
lastResult: DecayResult | null;
|
|
43
|
+
};
|
|
44
|
+
|
|
34
45
|
export class DecayEngine {
|
|
35
46
|
private wm: WorkingMemory;
|
|
36
47
|
private strategy: DecayExecutor;
|
|
48
|
+
private _stream: DecayStreamState | null = null;
|
|
37
49
|
|
|
38
50
|
constructor(workingMemory?: WorkingMemory) {
|
|
39
51
|
this.wm = workingMemory ?? new WorkingMemory();
|
|
@@ -109,6 +121,86 @@ export class DecayEngine {
|
|
|
109
121
|
return this.strategy.run(ruleSet, this.wm, options);
|
|
110
122
|
}
|
|
111
123
|
|
|
124
|
+
// ========================================
|
|
125
|
+
// Streaming Ingest
|
|
126
|
+
// ========================================
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Score a single entity incrementally without touching working memory.
|
|
130
|
+
*
|
|
131
|
+
* Each call computes the entity's freshness, updates a running accumulator
|
|
132
|
+
* (tier distribution, average freshness), and returns both the individual
|
|
133
|
+
* result and the aggregate. The compiled ruleset must stay the same across
|
|
134
|
+
* calls (matched by id). Call `resetStream()` to start a new stream.
|
|
135
|
+
*
|
|
136
|
+
* Note: event-driven re-engagement requires facts in working memory,
|
|
137
|
+
* so ingest() uses multi-dimension scoring without re-engagement events.
|
|
138
|
+
*
|
|
139
|
+
* @param entityData - The entity's data object (same shape as fact.data)
|
|
140
|
+
* @param ruleSet - Compiled decay ruleset
|
|
141
|
+
* @param asOf - Reference time (default: now)
|
|
142
|
+
* @returns DecayIngestResult with entity-level and aggregate stats
|
|
143
|
+
*/
|
|
144
|
+
ingest(
|
|
145
|
+
entityData: Record<string, any>,
|
|
146
|
+
ruleSet: CompiledDecayRuleSet,
|
|
147
|
+
asOf: Date = new Date()
|
|
148
|
+
): DecayIngestResult {
|
|
149
|
+
if (!this._stream || this._stream.ruleSetId !== ruleSet.id) {
|
|
150
|
+
this._stream = {
|
|
151
|
+
ruleSetId: ruleSet.id,
|
|
152
|
+
freshnessSum: 0,
|
|
153
|
+
count: 0,
|
|
154
|
+
tierDistribution: { critical: 0, high: 0, medium: 0, low: 0, stale: 0 },
|
|
155
|
+
lastResult: null
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Build a temporary fact for the executor
|
|
160
|
+
const tempFact: Fact = {
|
|
161
|
+
id: entityData[ruleSet.entityIdField] ?? `ingest:${this._stream.count + 1}`,
|
|
162
|
+
type: ruleSet.entityType,
|
|
163
|
+
data: entityData
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const entityResult = this.strategy.scoreEntity(tempFact, ruleSet, asOf);
|
|
167
|
+
|
|
168
|
+
// Update accumulator
|
|
169
|
+
const s = this._stream;
|
|
170
|
+
s.freshnessSum += entityResult.compositeFreshness;
|
|
171
|
+
s.count++;
|
|
172
|
+
s.tierDistribution[entityResult.urgencyTier]++;
|
|
173
|
+
|
|
174
|
+
const averageFreshness = Math.round((s.freshnessSum / s.count) * 10000) / 10000;
|
|
175
|
+
|
|
176
|
+
return {
|
|
177
|
+
...entityResult,
|
|
178
|
+
tierDistribution: { ...s.tierDistribution },
|
|
179
|
+
averageFreshness,
|
|
180
|
+
totalIngested: s.count
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Get the current streaming aggregate without ingesting a new entity.
|
|
186
|
+
* Returns null if no entities have been ingested yet.
|
|
187
|
+
*/
|
|
188
|
+
getStreamResult(): { tierDistribution: Record<UrgencyTier, number>; averageFreshness: number; totalIngested: number } | null {
|
|
189
|
+
if (!this._stream || this._stream.count === 0) return null;
|
|
190
|
+
return {
|
|
191
|
+
tierDistribution: { ...this._stream.tierDistribution },
|
|
192
|
+
averageFreshness: Math.round((this._stream.freshnessSum / this._stream.count) * 10000) / 10000,
|
|
193
|
+
totalIngested: this._stream.count
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Reset the streaming accumulator. Does not affect working memory.
|
|
199
|
+
*/
|
|
200
|
+
resetStream(): void {
|
|
201
|
+
this._stream = null;
|
|
202
|
+
}
|
|
203
|
+
|
|
112
204
|
// ========================================
|
|
113
205
|
// Utility Methods
|
|
114
206
|
// ========================================
|
|
@@ -30,6 +30,39 @@ import { resolveUrgencyTier } from './types';
|
|
|
30
30
|
const MS_PER_DAY = 86_400_000;
|
|
31
31
|
|
|
32
32
|
export class DecayExecutor {
|
|
33
|
+
/** Score a single entity fact directly (no WorkingMemory scan) */
|
|
34
|
+
scoreEntity(
|
|
35
|
+
fact: Fact,
|
|
36
|
+
ruleSet: CompiledDecayRuleSet,
|
|
37
|
+
asOf: Date = new Date()
|
|
38
|
+
): EntityDecayResult {
|
|
39
|
+
const entityId = resolveEntityId(fact, ruleSet.entityIdField);
|
|
40
|
+
|
|
41
|
+
if (ruleSet.strategy === 'single-dimension') {
|
|
42
|
+
const dimResult = computeDimensionDecay(fact, ruleSet.dimension, asOf);
|
|
43
|
+
return {
|
|
44
|
+
entityId,
|
|
45
|
+
compositeFreshness: dimResult.freshnessScore,
|
|
46
|
+
urgencyTier: resolveUrgencyTier(dimResult.freshnessScore, ruleSet.urgencyThresholds),
|
|
47
|
+
dimensions: [dimResult]
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// multi-dimension or event-driven (without WM-based re-engagement events)
|
|
52
|
+
const dimensions = ruleSet.strategy === 'event-driven' ? ruleSet.dimensions : ruleSet.dimensions;
|
|
53
|
+
const aggregation = ruleSet.aggregation;
|
|
54
|
+
|
|
55
|
+
const dimResults = dimensions.map(dim => computeDimensionDecay(fact, dim, asOf));
|
|
56
|
+
const compositeFreshness = aggregateFreshness(dimResults, dimensions, aggregation);
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
entityId,
|
|
60
|
+
compositeFreshness,
|
|
61
|
+
urgencyTier: resolveUrgencyTier(compositeFreshness, ruleSet.urgencyThresholds),
|
|
62
|
+
dimensions: dimResults
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
33
66
|
run(
|
|
34
67
|
ruleSet: CompiledDecayRuleSet,
|
|
35
68
|
wm: IWorkingMemory,
|
|
@@ -219,3 +219,13 @@ export type DecayOptions = {
|
|
|
219
219
|
asOf?: Date;
|
|
220
220
|
onEntity?: (entity: EntityDecayResult) => void;
|
|
221
221
|
};
|
|
222
|
+
|
|
223
|
+
/** Result from ingest() -- includes individual entity result and running aggregate */
|
|
224
|
+
export type DecayIngestResult = EntityDecayResult & {
|
|
225
|
+
/** Running tier distribution across all ingested entities */
|
|
226
|
+
tierDistribution: Record<UrgencyTier, number>;
|
|
227
|
+
/** Running average freshness across all ingested entities */
|
|
228
|
+
averageFreshness: number;
|
|
229
|
+
/** Total number of entities ingested so far */
|
|
230
|
+
totalIngested: number;
|
|
231
|
+
};
|