assignment-user-matcher 1.7.0 → 1.9.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 (42) hide show
  1. package/README.md +230 -14
  2. package/dist/index.d.ts +3 -2
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +5 -1
  5. package/dist/learning/auto-weights.d.ts +18 -8
  6. package/dist/learning/auto-weights.d.ts.map +1 -1
  7. package/dist/learning/auto-weights.js +120 -18
  8. package/dist/learning/features.d.ts +2 -2
  9. package/dist/learning/features.d.ts.map +1 -1
  10. package/dist/learning/features.js +10 -2
  11. package/dist/managers/LearningManager.d.ts +7 -0
  12. package/dist/managers/LearningManager.d.ts.map +1 -1
  13. package/dist/managers/LearningManager.js +85 -11
  14. package/dist/managers/WorkflowManager.d.ts +2 -0
  15. package/dist/managers/WorkflowManager.d.ts.map +1 -1
  16. package/dist/managers/WorkflowManager.js +3 -2
  17. package/dist/matcher.class.d.ts +121 -3
  18. package/dist/matcher.class.d.ts.map +1 -1
  19. package/dist/matcher.class.js +967 -16
  20. package/dist/queries/pagination.d.ts +5 -1
  21. package/dist/queries/pagination.d.ts.map +1 -1
  22. package/dist/queries/pagination.js +14 -3
  23. package/dist/schedule/policy.d.ts +35 -0
  24. package/dist/schedule/policy.d.ts.map +1 -0
  25. package/dist/schedule/policy.js +62 -0
  26. package/dist/scoring/match-score.d.ts +6 -0
  27. package/dist/scoring/match-score.d.ts.map +1 -1
  28. package/dist/scoring/match-score.js +15 -2
  29. package/dist/sla/policy.d.ts +49 -0
  30. package/dist/sla/policy.d.ts.map +1 -0
  31. package/dist/sla/policy.js +96 -0
  32. package/dist/tracing/decision-trace.d.ts.map +1 -1
  33. package/dist/tracing/decision-trace.js +4 -2
  34. package/dist/types/matcher.d.ts +422 -2
  35. package/dist/types/matcher.d.ts.map +1 -1
  36. package/dist/utils/keys.d.ts +10 -0
  37. package/dist/utils/keys.d.ts.map +1 -1
  38. package/dist/utils/keys.js +28 -0
  39. package/dist/validation/assignment-lint.d.ts +24 -0
  40. package/dist/validation/assignment-lint.d.ts.map +1 -0
  41. package/dist/validation/assignment-lint.js +132 -0
  42. package/package.json +2 -1
@@ -21,7 +21,9 @@ export interface AssignmentCounts {
21
21
  accepted: number;
22
22
  /** Assignments held out of matching by an exhausted escalation ladder */
23
23
  parked: number;
24
- /** queued + pending + accepted — parked items are counted separately */
24
+ /** Assignments held out of the queue by `schedule.notBefore` */
25
+ scheduled: number;
26
+ /** queued + pending + accepted — parked and scheduled items are counted separately */
25
27
  total: number;
26
28
  }
27
29
  export interface AssignmentKeys {
@@ -30,6 +32,8 @@ export interface AssignmentKeys {
30
32
  accepted: string;
31
33
  /** Optional parked store; omitted by callers that predate escalation policies */
32
34
  parked?: string;
35
+ /** Optional scheduled store; omitted by callers that predate schedule policies */
36
+ scheduled?: string;
33
37
  }
34
38
  /**
35
39
  * Get all assignments from all stores (queued, pending, accepted)
@@ -1 +1 @@
1
- {"version":3,"file":"pagination.d.ts","sourceRoot":"","sources":["../../src/queries/pagination.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEpE,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,SAAS,GAAG,UAAU,CAAC;AAEjE,MAAM,WAAW,iBAAiB;IAC9B,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,gBAAgB,GAAG,KAAK,CAAC;IAClC,YAAY,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,gBAAgB;IAC7B,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,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,gBAAgB,CAAC,CAiB3B;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CACnC,WAAW,EAAE,eAAe,EAC5B,IAAI,EAAE,cAAc,EACpB,EAAE,EAAE,MAAM,GACX,OAAO,CAAC,CAAC,UAAU,GAAG;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,IAAI,CAAC,CA4CrD;AAED;;GAEG;AACH,wBAAsB,wBAAwB,CAC1C,WAAW,EAAE,eAAe,EAC5B,IAAI,EAAE,cAAc,EACpB,GAAG,EAAE,MAAM,EAAE,GACd,OAAO,CAAC,UAAU,EAAE,CAAC,CA+BvB;AAED;;GAEG;AACH,wBAAsB,iCAAiC,CACnD,WAAW,EAAE,eAAe,EAC5B,IAAI,EAAE,cAAc,EACpB,OAAO,CAAC,EAAE,iBAAiB,GAC5B,OAAO,CAAC,gBAAgB,CAAC,CA2H3B"}
@@ -18,17 +18,19 @@ exports.getAllAssignmentsFromStores = getAllAssignmentsFromStores;
18
18
  * Get assignment counts by status
19
19
  */
20
20
  async function getAssignmentCountsFromStores(redisClient, keys) {
21
- const [queued, pending, accepted, parked] = await Promise.all([
21
+ const [queued, pending, accepted, parked, scheduled] = await Promise.all([
22
22
  redisClient.hLen(keys.queued),
23
23
  redisClient.hLen(keys.pending),
24
24
  redisClient.hLen(keys.accepted),
25
25
  keys.parked ? redisClient.hLen(keys.parked) : Promise.resolve(0),
26
+ keys.scheduled ? redisClient.hLen(keys.scheduled) : Promise.resolve(0),
26
27
  ]);
27
28
  return {
28
29
  queued,
29
30
  pending,
30
31
  accepted,
31
32
  parked,
33
+ scheduled,
32
34
  total: queued + pending + accepted,
33
35
  };
34
36
  }
@@ -57,8 +59,17 @@ async function getAssignmentById(redisClient, keys, id) {
57
59
  assignment._status = 'accepted';
58
60
  return assignment;
59
61
  }
60
- // Parked items are out of the matching universe but must never read as
61
- // "not found" — that would make an exhausted escalation look like data loss.
62
+ // Scheduled and parked items are out of the matching universe but must
63
+ // never read as "not found" — that would make a held assignment or an
64
+ // exhausted escalation look like data loss.
65
+ if (keys.scheduled) {
66
+ const scheduled = await redisClient.hGet(keys.scheduled, id);
67
+ if (scheduled) {
68
+ const assignment = JSON.parse(scheduled);
69
+ assignment._status = 'scheduled';
70
+ return assignment;
71
+ }
72
+ }
62
73
  if (keys.parked) {
63
74
  const parked = await redisClient.hGet(keys.parked, id);
64
75
  if (parked) {
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Schedule policy — pure logic.
3
+ *
4
+ * An assignment carries an optional `schedule` policy describing its offer
5
+ * window: `notBefore` holds it out of the queue entirely, `notAfter` expires
6
+ * it while still un-accepted. Everything here is deliberately side-effect
7
+ * free: `AssignmentMatcher` owns the Redis writes, this module owns the
8
+ * decisions.
9
+ *
10
+ * Escalation owns the response clock and SLA owns the post-accept contract;
11
+ * schedule owns the offer window. Acceptance ends its authority.
12
+ */
13
+ import type { SchedulePolicy } from '../types/matcher';
14
+ /** A policy with every optional field resolved. */
15
+ export interface NormalizedSchedulePolicy {
16
+ notBefore?: number;
17
+ notAfter?: number;
18
+ onMiss: 'park' | 'drop';
19
+ }
20
+ /**
21
+ * Resolve an assignment's schedule policy, or `null` when it has none (the
22
+ * overwhelming majority of assignments — callers use the null to stay on
23
+ * the untouched legacy path). A window with `notAfter <= notBefore` can
24
+ * never be satisfied, so the whole policy is treated as absent.
25
+ */
26
+ export declare function normalizeSchedulePolicy(policy: SchedulePolicy | undefined | null): NormalizedSchedulePolicy | null;
27
+ /**
28
+ * Same question, answered from the stored JSON without paying for a parse on
29
+ * the accept hot path. Assignments without a schedule — effectively all of
30
+ * them in a typical deployment — cost one `indexOf` and nothing else.
31
+ */
32
+ export declare function scheduleFromJson(json: string | null | undefined): NormalizedSchedulePolicy | null;
33
+ /** Whether the assignment must stay in the scheduled store at `now`. */
34
+ export declare function isHeld(policy: NormalizedSchedulePolicy, now: number): boolean;
35
+ //# sourceMappingURL=policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../src/schedule/policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAc,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEnE,mDAAmD;AACnD,MAAM,WAAW,wBAAwB;IACrC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;CAC3B;AAOD;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,cAAc,GAAG,SAAS,GAAG,IAAI,GAAG,wBAAwB,GAAG,IAAI,CAclH;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,wBAAwB,GAAG,IAAI,CAOjG;AAED,wEAAwE;AACxE,wBAAgB,MAAM,CAAC,MAAM,EAAE,wBAAwB,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAE7E"}
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ /**
3
+ * Schedule policy — pure logic.
4
+ *
5
+ * An assignment carries an optional `schedule` policy describing its offer
6
+ * window: `notBefore` holds it out of the queue entirely, `notAfter` expires
7
+ * it while still un-accepted. Everything here is deliberately side-effect
8
+ * free: `AssignmentMatcher` owns the Redis writes, this module owns the
9
+ * decisions.
10
+ *
11
+ * Escalation owns the response clock and SLA owns the post-accept contract;
12
+ * schedule owns the offer window. Acceptance ends its authority.
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.isHeld = exports.scheduleFromJson = exports.normalizeSchedulePolicy = void 0;
16
+ function epochMs(value) {
17
+ const n = Number(value);
18
+ return Number.isFinite(n) && n > 0 ? Math.floor(n) : undefined;
19
+ }
20
+ /**
21
+ * Resolve an assignment's schedule policy, or `null` when it has none (the
22
+ * overwhelming majority of assignments — callers use the null to stay on
23
+ * the untouched legacy path). A window with `notAfter <= notBefore` can
24
+ * never be satisfied, so the whole policy is treated as absent.
25
+ */
26
+ function normalizeSchedulePolicy(policy) {
27
+ if (!policy || typeof policy !== 'object')
28
+ return null;
29
+ const notBefore = epochMs(policy.notBefore);
30
+ const notAfter = epochMs(policy.notAfter);
31
+ if (notBefore === undefined && notAfter === undefined)
32
+ return null;
33
+ if (notBefore !== undefined && notAfter !== undefined && notAfter <= notBefore)
34
+ return null;
35
+ return {
36
+ notBefore,
37
+ notAfter,
38
+ onMiss: policy.onMiss === 'drop' ? 'drop' : 'park',
39
+ };
40
+ }
41
+ exports.normalizeSchedulePolicy = normalizeSchedulePolicy;
42
+ /**
43
+ * Same question, answered from the stored JSON without paying for a parse on
44
+ * the accept hot path. Assignments without a schedule — effectively all of
45
+ * them in a typical deployment — cost one `indexOf` and nothing else.
46
+ */
47
+ function scheduleFromJson(json) {
48
+ if (!json || json.indexOf('"schedule"') === -1)
49
+ return null;
50
+ try {
51
+ return normalizeSchedulePolicy(JSON.parse(json).schedule);
52
+ }
53
+ catch {
54
+ return null;
55
+ }
56
+ }
57
+ exports.scheduleFromJson = scheduleFromJson;
58
+ /** Whether the assignment must stay in the scheduled store at `now`. */
59
+ function isHeld(policy, now) {
60
+ return policy.notBefore !== undefined && policy.notBefore > now;
61
+ }
62
+ exports.isHeld = isHeld;
@@ -6,6 +6,12 @@ import type { User, MatchTraceReason } from '../types/matcher';
6
6
  * Check if a pattern matches a tag (supports wildcard patterns ending with *)
7
7
  */
8
8
  export declare function matchesPattern(pattern: string, tag: string): boolean;
9
+ /**
10
+ * Where a zero-weight veto came from: the learning layer's last sync, or an
11
+ * operator. Returns undefined for users with no learned weights at all, which
12
+ * keeps the trace shape unchanged for everyone not using the learning layer.
13
+ */
14
+ export declare function vetoSource(user: User, pattern: string): 'manual' | 'learned' | undefined;
9
15
  /**
10
16
  * Get the effective weight for a skill tag from user's routingWeights
11
17
  * Supports wildcard patterns (e.g., 'eng*' matches 'english')
@@ -1 +1 @@
1
- {"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EACV,cAAc,EAAE,MAAM,EACtB,kBAAkB,EAAE,MAAM,GAAG,MAAM,EACnC,qBAAqB,EAAE,OAAO,EAC9B,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACzC,qBAAqB,CA4EvB;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAGnE"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.calculateDefaultPriority = exports.explainMatchScore = exports.calculateMatchScore = exports.meetsSkillThresholds = exports.getEffectiveWeight = exports.matchesPattern = void 0;
3
+ exports.calculateDefaultPriority = exports.explainMatchScore = exports.calculateMatchScore = exports.meetsSkillThresholds = exports.getEffectiveWeight = exports.vetoSource = exports.matchesPattern = void 0;
4
4
  /**
5
5
  * Check if a pattern matches a tag (supports wildcard patterns ending with *)
6
6
  */
@@ -14,6 +14,18 @@ function matchesPattern(pattern, tag) {
14
14
  return false;
15
15
  }
16
16
  exports.matchesPattern = matchesPattern;
17
+ /**
18
+ * Where a zero-weight veto came from: the learning layer's last sync, or an
19
+ * operator. Returns undefined for users with no learned weights at all, which
20
+ * keeps the trace shape unchanged for everyone not using the learning layer.
21
+ */
22
+ function vetoSource(user, pattern) {
23
+ const learned = user.learnedRoutingWeights;
24
+ if (!learned)
25
+ return undefined;
26
+ return learned[pattern] === 0 ? 'learned' : 'manual';
27
+ }
28
+ exports.vetoSource = vetoSource;
17
29
  /**
18
30
  * Get the effective weight for a skill tag from user's routingWeights
19
31
  * Supports wildcard patterns (e.g., 'eng*' matches 'english')
@@ -149,7 +161,8 @@ function explainMatchScore(user, assignmentTags, assignmentPriority, enableDefau
149
161
  if (weight === 0) {
150
162
  for (const t of aTags) {
151
163
  if (matchesPattern(pattern, t)) {
152
- reasons.push({ kind: 'veto', tag: t, pattern });
164
+ const source = vetoSource(user, pattern);
165
+ reasons.push(source ? { kind: 'veto', tag: t, pattern, source } : { kind: 'veto', tag: t, pattern });
153
166
  vetoed = true;
154
167
  }
155
168
  }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * SLA policy — pure logic.
3
+ *
4
+ * An assignment carries an optional `sla` policy describing its service-level
5
+ * contract: completion deadline (from accept), freshness TTL (from first
6
+ * enqueue), and rejection budget. Everything here is deliberately
7
+ * side-effect free: `AssignmentMatcher` owns the Redis writes, this module
8
+ * owns the decisions.
9
+ *
10
+ * The response/acceptance side is owned by `EscalationPolicy`; SLA starts
11
+ * where escalation stops.
12
+ */
13
+ import type { Assignment, SlaPolicy } from '../types/matcher';
14
+ /** A policy with every optional field resolved. */
15
+ export interface NormalizedSlaPolicy {
16
+ completeWithinMs?: number;
17
+ expireAfterMs?: number;
18
+ maxRejections?: number;
19
+ onCompletionBreach: 'notify' | 'requeue' | 'fail' | 'park';
20
+ onMaxRejections: 'park' | 'fail' | 'keep';
21
+ onExpire: 'drop' | 'park';
22
+ }
23
+ /** Internal markers the matcher persists on the assignment JSON. */
24
+ export declare const SLA_ENQUEUED_AT_FIELD = "_enqueuedAt";
25
+ export declare const SLA_REJECTION_COUNT_FIELD = "_rejectionCount";
26
+ export declare const SLA_MATCHED_AT_FIELD = "_matchedAt";
27
+ export declare const SLA_ACCEPTED_AT_FIELD = "_acceptedAt";
28
+ export declare const SLA_ACCEPTED_BY_FIELD = "_acceptedBy";
29
+ /**
30
+ * Resolve an assignment's SLA policy, or `null` when it has none (the
31
+ * overwhelming majority of assignments — callers use the null to stay on
32
+ * the untouched legacy path).
33
+ */
34
+ export declare function normalizeSlaPolicy(policy: SlaPolicy | undefined | null): NormalizedSlaPolicy | null;
35
+ /**
36
+ * Same question, answered from the stored JSON without paying for a parse on
37
+ * the claim/accept hot path. Assignments without an SLA — effectively all of
38
+ * them in a typical deployment — cost one `indexOf` and nothing else.
39
+ */
40
+ export declare function slaFromJson(json: string | null | undefined): NormalizedSlaPolicy | null;
41
+ /** Current rejection count of an assignment (0 = never rejected). */
42
+ export declare function rejectionCountOf(assignment: Assignment): number;
43
+ /** Deadline score for the accepted-expiry zset. */
44
+ export declare function completionDeadlineScore(acceptedAt: number, policy: NormalizedSlaPolicy): number | null;
45
+ /** Deadline score for the TTL zset. */
46
+ export declare function slaExpiryScore(enqueuedAt: number, policy: NormalizedSlaPolicy): number | null;
47
+ /** Whether the rejection budget has been exhausted. */
48
+ export declare function rejectionBudgetExhausted(assignment: Assignment, policy: NormalizedSlaPolicy): boolean;
49
+ //# sourceMappingURL=policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../src/sla/policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE9D,mDAAmD;AACnD,MAAM,WAAW,mBAAmB;IAChC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,kBAAkB,EAAE,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;IAC3D,eAAe,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IAC1C,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;CAC7B;AAED,oEAAoE;AACpE,eAAO,MAAM,qBAAqB,gBAAgB,CAAC;AACnD,eAAO,MAAM,yBAAyB,oBAAoB,CAAC;AAC3D,eAAO,MAAM,oBAAoB,eAAe,CAAC;AACjD,eAAO,MAAM,qBAAqB,gBAAgB,CAAC;AACnD,eAAO,MAAM,qBAAqB,gBAAgB,CAAC;AAYnD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,IAAI,GAAG,mBAAmB,GAAG,IAAI,CAyBnG;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,mBAAmB,GAAG,IAAI,CAOvF;AAED,qEAAqE;AACrE,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAG/D;AAED,mDAAmD;AACnD,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,mBAAmB,GAAG,MAAM,GAAG,IAAI,CAEtG;AAED,uCAAuC;AACvC,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,mBAAmB,GAAG,MAAM,GAAG,IAAI,CAE7F;AAED,uDAAuD;AACvD,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAGrG"}
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ /**
3
+ * SLA policy — pure logic.
4
+ *
5
+ * An assignment carries an optional `sla` policy describing its service-level
6
+ * contract: completion deadline (from accept), freshness TTL (from first
7
+ * enqueue), and rejection budget. Everything here is deliberately
8
+ * side-effect free: `AssignmentMatcher` owns the Redis writes, this module
9
+ * owns the decisions.
10
+ *
11
+ * The response/acceptance side is owned by `EscalationPolicy`; SLA starts
12
+ * where escalation stops.
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.rejectionBudgetExhausted = exports.slaExpiryScore = exports.completionDeadlineScore = exports.rejectionCountOf = exports.slaFromJson = exports.normalizeSlaPolicy = exports.SLA_ACCEPTED_BY_FIELD = exports.SLA_ACCEPTED_AT_FIELD = exports.SLA_MATCHED_AT_FIELD = exports.SLA_REJECTION_COUNT_FIELD = exports.SLA_ENQUEUED_AT_FIELD = void 0;
16
+ /** Internal markers the matcher persists on the assignment JSON. */
17
+ exports.SLA_ENQUEUED_AT_FIELD = '_enqueuedAt';
18
+ exports.SLA_REJECTION_COUNT_FIELD = '_rejectionCount';
19
+ exports.SLA_MATCHED_AT_FIELD = '_matchedAt';
20
+ exports.SLA_ACCEPTED_AT_FIELD = '_acceptedAt';
21
+ exports.SLA_ACCEPTED_BY_FIELD = '_acceptedBy';
22
+ function positiveMs(value) {
23
+ const n = Number(value);
24
+ return Number.isFinite(n) && n > 0 ? n : undefined;
25
+ }
26
+ function nonNegativeInt(value) {
27
+ const n = Number(value);
28
+ return Number.isFinite(n) && n >= 0 ? Math.floor(n) : undefined;
29
+ }
30
+ /**
31
+ * Resolve an assignment's SLA policy, or `null` when it has none (the
32
+ * overwhelming majority of assignments — callers use the null to stay on
33
+ * the untouched legacy path).
34
+ */
35
+ function normalizeSlaPolicy(policy) {
36
+ if (!policy || typeof policy !== 'object')
37
+ return null;
38
+ const completeWithinMs = positiveMs(policy.completeWithinMs);
39
+ const expireAfterMs = positiveMs(policy.expireAfterMs);
40
+ const maxRejections = nonNegativeInt(policy.maxRejections);
41
+ if (completeWithinMs === undefined && expireAfterMs === undefined && maxRejections === undefined) {
42
+ return null;
43
+ }
44
+ return {
45
+ completeWithinMs,
46
+ expireAfterMs,
47
+ maxRejections,
48
+ onCompletionBreach: policy.onCompletionBreach === 'requeue' ||
49
+ policy.onCompletionBreach === 'fail' ||
50
+ policy.onCompletionBreach === 'park'
51
+ ? policy.onCompletionBreach
52
+ : 'notify',
53
+ onMaxRejections: policy.onMaxRejections === 'fail' || policy.onMaxRejections === 'keep' ? policy.onMaxRejections : 'park',
54
+ onExpire: policy.onExpire === 'park' ? 'park' : 'drop',
55
+ };
56
+ }
57
+ exports.normalizeSlaPolicy = normalizeSlaPolicy;
58
+ /**
59
+ * Same question, answered from the stored JSON without paying for a parse on
60
+ * the claim/accept hot path. Assignments without an SLA — effectively all of
61
+ * them in a typical deployment — cost one `indexOf` and nothing else.
62
+ */
63
+ function slaFromJson(json) {
64
+ if (!json || json.indexOf('"sla"') === -1)
65
+ return null;
66
+ try {
67
+ return normalizeSlaPolicy(JSON.parse(json).sla);
68
+ }
69
+ catch {
70
+ return null;
71
+ }
72
+ }
73
+ exports.slaFromJson = slaFromJson;
74
+ /** Current rejection count of an assignment (0 = never rejected). */
75
+ function rejectionCountOf(assignment) {
76
+ const raw = Number(assignment[exports.SLA_REJECTION_COUNT_FIELD]);
77
+ return Number.isFinite(raw) && raw > 0 ? Math.floor(raw) : 0;
78
+ }
79
+ exports.rejectionCountOf = rejectionCountOf;
80
+ /** Deadline score for the accepted-expiry zset. */
81
+ function completionDeadlineScore(acceptedAt, policy) {
82
+ return policy.completeWithinMs === undefined ? null : acceptedAt + policy.completeWithinMs;
83
+ }
84
+ exports.completionDeadlineScore = completionDeadlineScore;
85
+ /** Deadline score for the TTL zset. */
86
+ function slaExpiryScore(enqueuedAt, policy) {
87
+ return policy.expireAfterMs === undefined ? null : enqueuedAt + policy.expireAfterMs;
88
+ }
89
+ exports.slaExpiryScore = slaExpiryScore;
90
+ /** Whether the rejection budget has been exhausted. */
91
+ function rejectionBudgetExhausted(assignment, policy) {
92
+ if (policy.maxRejections === undefined)
93
+ return false;
94
+ return rejectionCountOf(assignment) >= policy.maxRejections;
95
+ }
96
+ exports.rejectionBudgetExhausted = rejectionBudgetExhausted;
@@ -1 +1 @@
1
- {"version":3,"file":"decision-trace.d.ts","sourceRoot":"","sources":["../../src/tracing/decision-trace.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE3H,gFAAgF;AAChF,MAAM,WAAW,eAAe;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,iBAAiB,EAAE,MAAM,CAAC;IAC1B,OAAO,EAAE,gBAAgB,EAAE,CAAC;CAC/B;AAED,0EAA0E;AAC1E,qBAAa,cAAc;IACvB,QAAQ,CAAC,YAAY;cAA2B,MAAM;qBAAe,eAAe,EAAE;OAAM;IAE5F,MAAM,CAAC,YAAY,EAAE,MAAM,EAA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+64,11 @@ function excludedCandidate(ctx, assignmentId, tags) {
64
64
  if (weights) {
65
65
  for (const [pattern, weight] of Object.entries(weights)) {
66
66
  if (weight === 0) {
67
+ const source = (0, match_score_1.vetoSource)(ctx.user, pattern);
67
68
  for (const tag of tags) {
68
- if ((0, match_score_1.matchesPattern)(pattern, tag))
69
- reasons.push({ kind: 'veto', tag, pattern });
69
+ if (!(0, match_score_1.matchesPattern)(pattern, tag))
70
+ continue;
71
+ reasons.push(source ? { kind: 'veto', tag, pattern, source } : { kind: 'veto', tag, pattern });
70
72
  }
71
73
  }
72
74
  }