assignment-user-matcher 1.16.1 → 1.22.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 (153) hide show
  1. package/README.md +290 -8
  2. package/dist/escalation/policy.d.ts +11 -0
  3. package/dist/escalation/policy.d.ts.map +1 -1
  4. package/dist/escalation/policy.js +22 -1
  5. package/dist/forecasting/backtest.d.ts +52 -0
  6. package/dist/forecasting/backtest.d.ts.map +1 -0
  7. package/dist/forecasting/backtest.js +195 -0
  8. package/dist/forecasting/calendar.d.ts +44 -0
  9. package/dist/forecasting/calendar.d.ts.map +1 -0
  10. package/dist/forecasting/calendar.js +85 -0
  11. package/dist/forecasting/cover.d.ts +69 -0
  12. package/dist/forecasting/cover.d.ts.map +1 -0
  13. package/dist/forecasting/cover.js +103 -0
  14. package/dist/forecasting/days.d.ts +17 -0
  15. package/dist/forecasting/days.d.ts.map +1 -0
  16. package/dist/forecasting/days.js +35 -0
  17. package/dist/forecasting/distributions.d.ts +31 -0
  18. package/dist/forecasting/distributions.d.ts.map +1 -0
  19. package/dist/forecasting/distributions.js +154 -0
  20. package/dist/forecasting/effects.d.ts +88 -0
  21. package/dist/forecasting/effects.d.ts.map +1 -0
  22. package/dist/forecasting/effects.js +303 -0
  23. package/dist/forecasting/erlang.d.ts +31 -0
  24. package/dist/forecasting/erlang.d.ts.map +1 -0
  25. package/dist/forecasting/erlang.js +86 -0
  26. package/dist/forecasting/forecast.d.ts +7 -0
  27. package/dist/forecasting/forecast.d.ts.map +1 -0
  28. package/dist/forecasting/forecast.js +221 -0
  29. package/dist/forecasting/index.d.ts +18 -0
  30. package/dist/forecasting/index.d.ts.map +1 -0
  31. package/dist/forecasting/index.js +54 -0
  32. package/dist/forecasting/model.d.ts +145 -0
  33. package/dist/forecasting/model.d.ts.map +1 -0
  34. package/dist/forecasting/model.js +583 -0
  35. package/dist/forecasting/nowcast.d.ts +26 -0
  36. package/dist/forecasting/nowcast.d.ts.map +1 -0
  37. package/dist/forecasting/nowcast.js +92 -0
  38. package/dist/forecasting/simulation.d.ts +91 -0
  39. package/dist/forecasting/simulation.d.ts.map +1 -0
  40. package/dist/forecasting/simulation.js +478 -0
  41. package/dist/forecasting/spikes.d.ts +6 -0
  42. package/dist/forecasting/spikes.d.ts.map +1 -0
  43. package/dist/forecasting/spikes.js +73 -0
  44. package/dist/forecasting/staffing.d.ts +64 -0
  45. package/dist/forecasting/staffing.d.ts.map +1 -0
  46. package/dist/forecasting/staffing.js +765 -0
  47. package/dist/forecasting/stats.d.ts +11 -0
  48. package/dist/forecasting/stats.d.ts.map +1 -0
  49. package/dist/forecasting/stats.js +45 -0
  50. package/dist/forecasting/types.d.ts +299 -0
  51. package/dist/forecasting/types.d.ts.map +1 -0
  52. package/dist/forecasting/types.js +8 -0
  53. package/dist/index.d.ts +3 -2
  54. package/dist/index.d.ts.map +1 -1
  55. package/dist/index.js +8 -1
  56. package/dist/learning/auto-weights.d.ts +1 -5
  57. package/dist/learning/auto-weights.d.ts.map +1 -1
  58. package/dist/learning/auto-weights.js +0 -3
  59. package/dist/lua/book-slot.lua +84 -0
  60. package/dist/lua/claim-queued.lua +47 -0
  61. package/dist/managers/DecisionTraceManager.d.ts +15 -0
  62. package/dist/managers/DecisionTraceManager.d.ts.map +1 -1
  63. package/dist/managers/DecisionTraceManager.js +117 -11
  64. package/dist/managers/LearningManager.d.ts +12 -0
  65. package/dist/managers/LearningManager.d.ts.map +1 -1
  66. package/dist/managers/LearningManager.js +21 -7
  67. package/dist/managers/ReliabilityManager.d.ts +1 -2
  68. package/dist/managers/ReliabilityManager.d.ts.map +1 -1
  69. package/dist/managers/ReliabilityManager.js +1 -1
  70. package/dist/managers/TelemetryManager.d.ts.map +1 -1
  71. package/dist/managers/TelemetryManager.js +9 -3
  72. package/dist/managers/WorkflowManager.d.ts.map +1 -1
  73. package/dist/managers/WorkflowManager.js +3 -4
  74. package/dist/matcher.class.d.ts +319 -4
  75. package/dist/matcher.class.d.ts.map +1 -1
  76. package/dist/matcher.class.js +1428 -102
  77. package/dist/queries/lane-stats.d.ts +51 -0
  78. package/dist/queries/lane-stats.d.ts.map +1 -0
  79. package/dist/queries/lane-stats.js +78 -0
  80. package/dist/schedule/recurrence.d.ts +11 -0
  81. package/dist/schedule/recurrence.d.ts.map +1 -1
  82. package/dist/schedule/recurrence.js +19 -2
  83. package/dist/schedule/slot.d.ts +60 -0
  84. package/dist/schedule/slot.d.ts.map +1 -0
  85. package/dist/schedule/slot.js +86 -0
  86. package/dist/scheduling/constraints/availability.d.ts +2 -14
  87. package/dist/scheduling/constraints/availability.d.ts.map +1 -1
  88. package/dist/scheduling/constraints/availability.js +14 -15
  89. package/dist/scheduling/constraints/employee-scope.d.ts.map +1 -1
  90. package/dist/scheduling/constraints/employee-scope.js +10 -2
  91. package/dist/scheduling/constraints/support.d.ts +4 -8
  92. package/dist/scheduling/constraints/support.d.ts.map +1 -1
  93. package/dist/scheduling/constraints/support.js +23 -2
  94. package/dist/scheduling/constraints/weekly-rest.d.ts +28 -0
  95. package/dist/scheduling/constraints/weekly-rest.d.ts.map +1 -1
  96. package/dist/scheduling/constraints/weekly-rest.js +108 -21
  97. package/dist/scheduling/engine/construction.d.ts.map +1 -1
  98. package/dist/scheduling/engine/construction.js +33 -4
  99. package/dist/scheduling/engine/objective.d.ts +0 -1
  100. package/dist/scheduling/engine/objective.d.ts.map +1 -1
  101. package/dist/scheduling/engine/objective.js +45 -3
  102. package/dist/scheduling/engine/search.d.ts +4 -0
  103. package/dist/scheduling/engine/search.d.ts.map +1 -1
  104. package/dist/scheduling/engine/search.js +2 -1
  105. package/dist/scheduling/engine/state.d.ts +14 -0
  106. package/dist/scheduling/engine/state.d.ts.map +1 -1
  107. package/dist/scheduling/engine/state.js +7 -0
  108. package/dist/scheduling/engine/timeline.d.ts +9 -1
  109. package/dist/scheduling/engine/timeline.d.ts.map +1 -1
  110. package/dist/scheduling/engine/timeline.js +52 -27
  111. package/dist/scheduling/engine/verdicts.d.ts +40 -1
  112. package/dist/scheduling/engine/verdicts.d.ts.map +1 -1
  113. package/dist/scheduling/engine/verdicts.js +177 -17
  114. package/dist/scheduling/index.d.ts +3 -2
  115. package/dist/scheduling/index.d.ts.map +1 -1
  116. package/dist/scheduling/index.js +7 -1
  117. package/dist/scheduling/model.d.ts +2 -3
  118. package/dist/scheduling/model.d.ts.map +1 -1
  119. package/dist/scheduling/model.js +30 -12
  120. package/dist/scheduling/operations.d.ts +174 -2
  121. package/dist/scheduling/operations.d.ts.map +1 -1
  122. package/dist/scheduling/operations.js +513 -15
  123. package/dist/scheduling/preference-report.d.ts +15 -0
  124. package/dist/scheduling/preference-report.d.ts.map +1 -0
  125. package/dist/scheduling/preference-report.js +111 -0
  126. package/dist/scheduling/preferences.d.ts +30 -0
  127. package/dist/scheduling/preferences.d.ts.map +1 -0
  128. package/dist/scheduling/preferences.js +85 -0
  129. package/dist/scheduling/resilience.d.ts +46 -0
  130. package/dist/scheduling/resilience.d.ts.map +1 -0
  131. package/dist/scheduling/resilience.js +45 -0
  132. package/dist/scheduling/scheduler.class.d.ts +12 -1
  133. package/dist/scheduling/scheduler.class.d.ts.map +1 -1
  134. package/dist/scheduling/scheduler.class.js +28 -4
  135. package/dist/scheduling/time.d.ts +28 -6
  136. package/dist/scheduling/time.d.ts.map +1 -1
  137. package/dist/scheduling/time.js +59 -17
  138. package/dist/scheduling/types.d.ts +107 -1
  139. package/dist/scheduling/types.d.ts.map +1 -1
  140. package/dist/scoring/fair-arbitration.d.ts.map +1 -1
  141. package/dist/scoring/fair-arbitration.js +2 -1
  142. package/dist/tracing/decision-trace.d.ts +5 -0
  143. package/dist/tracing/decision-trace.d.ts.map +1 -1
  144. package/dist/tracing/decision-trace.js +3 -0
  145. package/dist/types/matcher.d.ts +369 -2
  146. package/dist/types/matcher.d.ts.map +1 -1
  147. package/dist/updates/assignment-update.d.ts +93 -0
  148. package/dist/updates/assignment-update.d.ts.map +1 -0
  149. package/dist/updates/assignment-update.js +91 -0
  150. package/dist/utils/keys.d.ts +10 -0
  151. package/dist/utils/keys.d.ts.map +1 -1
  152. package/dist/utils/keys.js +43 -0
  153. package/package.json +15 -2
@@ -0,0 +1,93 @@
1
+ import type { Assignment } from '../types/matcher';
2
+ /**
3
+ * Editing a task that is already in flight.
4
+ *
5
+ * Everything here is pure: what a patch actually changes, which per-tag
6
+ * indexes have to move as a result, and whether the person currently holding
7
+ * the task can still hold it. The Redis writes live in the matcher; the
8
+ * decisions live here, because "did the tags change" and "is the owner still
9
+ * eligible" are exactly the two questions a wrong answer to would silently
10
+ * redistribute somebody's work — or silently fail to.
11
+ */
12
+ /**
13
+ * The fields of a stored assignment an operator may edit after creation.
14
+ *
15
+ * Deliberately narrow. `tags` and `priority` are routing — changing them
16
+ * changes who should have the task, which is what makes this more than a
17
+ * metadata write. `title` and `meta` are description, carried on the record so
18
+ * a list view can render a row without a second store. Everything else about
19
+ * an assignment (its escalation ladder, its SLA, its offer window, its vetoes)
20
+ * is a policy chosen when the work was created and is not patched piecemeal —
21
+ * same reasoning as `resolvePolicy` on the platform side.
22
+ *
23
+ * A field left `undefined` is untouched; `title` and `meta` accept `null` to
24
+ * clear them, which is why they are not simply optional.
25
+ */
26
+ export interface AssignmentUpdate {
27
+ tags?: string[];
28
+ priority?: number;
29
+ title?: string | null;
30
+ meta?: Record<string, unknown> | null;
31
+ }
32
+ /** Which stores an assignment can be edited in. Terminal states are not editable. */
33
+ export type UpdatableStatus = 'queued' | 'pending' | 'accepted' | 'parked' | 'scheduled';
34
+ export interface UpdateAssignmentResult {
35
+ id: string;
36
+ /** Where the task ended up — `queued` when a retag sent it back for rematching. */
37
+ status: UpdatableStatus;
38
+ tags: string[];
39
+ priority: number | undefined;
40
+ /** Whether the edit pulled the task off its owner and put it back in the queue. */
41
+ requeued: boolean;
42
+ /** Who held it before the edit, whether or not they kept it. */
43
+ previousOwnerId: string | null;
44
+ }
45
+ /**
46
+ * Tidy a patch's tag list without changing what any tag *is*.
47
+ *
48
+ * Surrounding whitespace is stripped, empties dropped and duplicates folded —
49
+ * all of which leave the tag's identity alone. Case is deliberately not folded:
50
+ * creation indexes tags verbatim (`enqueueAssignment`), users carry them
51
+ * verbatim (`addUser`) and matching compares them exactly, so an edit that
52
+ * lowercased would open a second routing universe that only edits enter. In it,
53
+ * re-stating `Plumbing` reads as a tag change, scores the holder against
54
+ * `plumbing` — a tag they do not have — and takes their work away for an edit
55
+ * that changed nothing.
56
+ */
57
+ export declare function normalizeUpdateTags(tags: string[]): string[];
58
+ export interface TagIndexDiff {
59
+ /** Per-tag sorted sets the assignment must be added to. */
60
+ added: string[];
61
+ /** Per-tag sorted sets it must be removed from. */
62
+ removed: string[];
63
+ /** Every tag it should be indexed under afterwards (the `default` tag included). */
64
+ indexTags: string[];
65
+ /** The value of the `assignment:<id>:tags` hash field afterwards. */
66
+ tagsCsv: string;
67
+ /** False when the patch leaves the routing tags exactly as they were. */
68
+ changed: boolean;
69
+ }
70
+ /**
71
+ * What moving from one tag set to another costs in index writes.
72
+ *
73
+ * The `default` tag is folded in here rather than at the call site because it
74
+ * is an index-level fact, not a property of the task: `enableDefaultMatching`
75
+ * puts every assignment in one shared set, and a retag that forgot it would
76
+ * evict a task from the default pool without anybody asking.
77
+ */
78
+ export declare function diffTagIndexes(oldTags: string[], newTags: string[], enableDefaultMatching: boolean): TagIndexDiff;
79
+ /** Apply a patch to a stored record, leaving untouched fields byte-identical. */
80
+ export declare function applyUpdate(assignment: Assignment, patch: AssignmentUpdate, normalizedTags?: string[]): Assignment;
81
+ /**
82
+ * An acceptance consumes the offer window.
83
+ *
84
+ * `schedule.notAfter` means "somebody must take this by T", and somebody did.
85
+ * When accepted work goes back into the pool — a retag that takes it off its
86
+ * holder, or a supervisor moving it to a different worker — re-arming an
87
+ * elapsed window would have the next sweep park or drop it as a missed offer,
88
+ * which is a verdict about an offer nobody answered. Dropping the field from
89
+ * the record (rather than only from the index) keeps every later requeue of
90
+ * the same record agreeing with this.
91
+ */
92
+ export declare function consumeOfferWindow(record: Record<string, any>): void;
93
+ //# sourceMappingURL=assignment-update.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assignment-update.d.ts","sourceRoot":"","sources":["../../src/updates/assignment-update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;;;;;;;;GASG;AAEH;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,gBAAgB;IAC7B,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;CACzC;AAED,qFAAqF;AACrF,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,SAAS,GAAG,UAAU,GAAG,QAAQ,GAAG,WAAW,CAAC;AAEzF,MAAM,WAAW,sBAAsB;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,mFAAmF;IACnF,MAAM,EAAE,eAAe,CAAC;IACxB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,mFAAmF;IACnF,QAAQ,EAAE,OAAO,CAAC;IAClB,gEAAgE;IAChE,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CAClC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAO5D;AAED,MAAM,WAAW,YAAY;IACzB,2DAA2D;IAC3D,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,mDAAmD;IACnD,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,oFAAoF;IACpF,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,qEAAqE;IACrE,OAAO,EAAE,MAAM,CAAC;IAChB,yEAAyE;IACzE,OAAO,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,qBAAqB,EAAE,OAAO,GAAG,YAAY,CAajH;AAED,iFAAiF;AACjF,wBAAgB,WAAW,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,gBAAgB,EAAE,cAAc,CAAC,EAAE,MAAM,EAAE,GAAG,UAAU,CAalH;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAOpE"}
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.consumeOfferWindow = exports.applyUpdate = exports.diffTagIndexes = exports.normalizeUpdateTags = void 0;
4
+ /**
5
+ * Tidy a patch's tag list without changing what any tag *is*.
6
+ *
7
+ * Surrounding whitespace is stripped, empties dropped and duplicates folded —
8
+ * all of which leave the tag's identity alone. Case is deliberately not folded:
9
+ * creation indexes tags verbatim (`enqueueAssignment`), users carry them
10
+ * verbatim (`addUser`) and matching compares them exactly, so an edit that
11
+ * lowercased would open a second routing universe that only edits enter. In it,
12
+ * re-stating `Plumbing` reads as a tag change, scores the holder against
13
+ * `plumbing` — a tag they do not have — and takes their work away for an edit
14
+ * that changed nothing.
15
+ */
16
+ function normalizeUpdateTags(tags) {
17
+ const seen = new Set();
18
+ for (const raw of tags) {
19
+ const tag = String(raw).trim();
20
+ if (tag.length > 0)
21
+ seen.add(tag);
22
+ }
23
+ return [...seen];
24
+ }
25
+ exports.normalizeUpdateTags = normalizeUpdateTags;
26
+ /**
27
+ * What moving from one tag set to another costs in index writes.
28
+ *
29
+ * The `default` tag is folded in here rather than at the call site because it
30
+ * is an index-level fact, not a property of the task: `enableDefaultMatching`
31
+ * puts every assignment in one shared set, and a retag that forgot it would
32
+ * evict a task from the default pool without anybody asking.
33
+ */
34
+ function diffTagIndexes(oldTags, newTags, enableDefaultMatching) {
35
+ const withDefault = (tags) => (enableDefaultMatching ? [...tags, 'default'] : [...tags]);
36
+ const before = new Set(withDefault(oldTags));
37
+ const indexTags = withDefault(newTags);
38
+ const after = new Set(indexTags);
39
+ return {
40
+ added: indexTags.filter((tag) => !before.has(tag)),
41
+ removed: [...before].filter((tag) => !after.has(tag)),
42
+ indexTags,
43
+ tagsCsv: indexTags.join(','),
44
+ changed: before.size !== after.size || [...after].some((tag) => !before.has(tag)),
45
+ };
46
+ }
47
+ exports.diffTagIndexes = diffTagIndexes;
48
+ /** Apply a patch to a stored record, leaving untouched fields byte-identical. */
49
+ function applyUpdate(assignment, patch, normalizedTags) {
50
+ const next = { ...assignment };
51
+ if (patch.tags !== undefined)
52
+ next.tags = normalizedTags ?? normalizeUpdateTags(patch.tags);
53
+ if (patch.priority !== undefined)
54
+ next.priority = patch.priority;
55
+ if (patch.title !== undefined) {
56
+ if (patch.title === null)
57
+ delete next.title;
58
+ else
59
+ next.title = patch.title;
60
+ }
61
+ if (patch.meta !== undefined) {
62
+ if (patch.meta === null)
63
+ delete next.meta;
64
+ else
65
+ next.meta = patch.meta;
66
+ }
67
+ return next;
68
+ }
69
+ exports.applyUpdate = applyUpdate;
70
+ /**
71
+ * An acceptance consumes the offer window.
72
+ *
73
+ * `schedule.notAfter` means "somebody must take this by T", and somebody did.
74
+ * When accepted work goes back into the pool — a retag that takes it off its
75
+ * holder, or a supervisor moving it to a different worker — re-arming an
76
+ * elapsed window would have the next sweep park or drop it as a missed offer,
77
+ * which is a verdict about an offer nobody answered. Dropping the field from
78
+ * the record (rather than only from the index) keeps every later requeue of
79
+ * the same record agreeing with this.
80
+ */
81
+ function consumeOfferWindow(record) {
82
+ const schedule = record.schedule;
83
+ if (schedule && typeof schedule === 'object' && schedule.notAfter !== undefined) {
84
+ const { notAfter: _notAfter, ...rest } = schedule;
85
+ if (Object.keys(rest).length > 0)
86
+ record.schedule = rest;
87
+ else
88
+ delete record.schedule;
89
+ }
90
+ }
91
+ exports.consumeOfferWindow = consumeOfferWindow;
@@ -13,10 +13,12 @@ export declare function createKeyBuilders(config: RedisKeyConfig): {
13
13
  userAssignments: (userId: string) => string;
14
14
  userRejected: (userId: string) => string;
15
15
  userVetoed: (userId: string) => string;
16
+ userOfferCooldown: (userId: string) => string;
16
17
  userWindowGrants: (userId: string) => string;
17
18
  userActivity: () => string;
18
19
  pausedUsers: () => string;
19
20
  userAcceptedAssignments: (userId: string) => string;
21
+ acceptedAssignmentOwner: () => string;
20
22
  assignments: () => string;
21
23
  assignmentsRef: () => string;
22
24
  assignmentsGeo: () => string;
@@ -32,6 +34,10 @@ export declare function createKeyBuilders(config: RedisKeyConfig): {
32
34
  scheduledAssignments: () => string;
33
35
  scheduledActivateAt: () => string;
34
36
  scheduleNotAfter: () => string;
37
+ slotBookings: () => string;
38
+ bookingSpans: () => string;
39
+ userBookings: (userId: string) => string;
40
+ slotBookingDueAt: () => string;
35
41
  recurringAssignments: () => string;
36
42
  recurringDueAt: () => string;
37
43
  acceptedAssignmentsExpiry: () => string;
@@ -55,6 +61,10 @@ export declare function createKeyBuilders(config: RedisKeyConfig): {
55
61
  completedAssignmentsAt: () => string;
56
62
  completedRetentionIndexed: () => string;
57
63
  decisionTraces: () => string;
64
+ /** Stream ids of one assignment's traces, newest first; kept in step with the capped stream. */
65
+ decisionTraceIndex: (assignmentId: string) => string;
66
+ /** First stream id written with an index; anything older predates it and is found by scanning. */
67
+ decisionTraceIndexedSince: () => string;
58
68
  eventStream: () => string;
59
69
  eventStreamDeadLetter: () => string;
60
70
  learningModel: () => string;
@@ -1 +1 @@
1
- {"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../src/utils/keys.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,cAAc;IAC3B,MAAM,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,cAAc;;8BAMtB,MAAM;2BACT,MAAM;yBACR,MAAM;+BACA,MAAM;;;sCAQC,MAAM;;;;6BAMf,MAAM;yBACV,MAAM;2BACJ,MAAM;;;;;;;;;;;;;;;uBAqDV,MAAM;;0BAIH,MAAM;iCAGC,MAAM;8BACT,MAAM;4BACR,MAAM;;6BAIL,MAAM;;2BAER,MAAM;sCACK,MAAM;2CACD,MAAM;;;;;;;;;;mCAoCd,MAAM;kCACP,MAAM;4CAEI,MAAM;2CAGP,MAAM;kCAGf,MAAM;;;;oCAOJ,MAAM;qCACL,MAAM;sCACL,MAAM;gCACZ,MAAM;sCAIA,MAAM;sCAGN,MAAM;mCAIT,MAAM;kCAEP,MAAM;sCAGF,MAAM;;;;;8BASd,MAAM;+BACL,MAAM;;qCAEA,MAAM,UAAU,MAAM;;;;;;;EAQ9D;AAED,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC"}
1
+ {"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../src/utils/keys.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,cAAc;IAC3B,MAAM,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,cAAc;;8BAMtB,MAAM;2BACT,MAAM;yBACR,MAAM;gCAQC,MAAM;+BACP,MAAM;;;sCAQC,MAAM;;;;;6BAgBf,MAAM;yBACV,MAAM;2BACJ,MAAM;;;;;;;;;;;;2BAiDN,MAAM;;;;;;;uBA2BV,MAAM;;0BAIH,MAAM;iCAGC,MAAM;8BACT,MAAM;4BACR,MAAM;;6BAIL,MAAM;;2BAER,MAAM;sCACK,MAAM;2CACD,MAAM;;;;;;;IAyB7C,gGAAgG;uCAC7D,MAAM;IACzC,kGAAkG;;;;;mCAanE,MAAM;kCACP,MAAM;4CAEI,MAAM;2CAGP,MAAM;kCAGf,MAAM;;;;oCAOJ,MAAM;qCACL,MAAM;sCACL,MAAM;gCACZ,MAAM;sCAIA,MAAM;sCAGN,MAAM;mCAIT,MAAM;kCAEP,MAAM;sCAGF,MAAM;;;;;8BASd,MAAM;+BACL,MAAM;;qCAEA,MAAM,UAAU,MAAM;;;;;;;EAQ9D;AAED,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC"}
@@ -16,6 +16,14 @@ function createKeyBuilders(config) {
16
16
  userAssignments: (userId) => `${prefix}user:${userId}:assignments`,
17
17
  userRejected: (userId) => `${prefix}user:${userId}:rejected`,
18
18
  userVetoed: (userId) => `${prefix}user:${userId}:vetoed`,
19
+ // Offers this user let lapse, resting before they can be made again:
20
+ // a zset of RAW assignment ids scored by the epoch ms the rest ends.
21
+ // Subtracted from candidate discovery exactly like the rejected set.
22
+ // Elapsed entries are pruned on every write and every read, an empty
23
+ // zset deletes itself, and removeUser drops the key; there is no key
24
+ // TTL, because one set from a short cooldown would cut a longer one
25
+ // short. Lifetime is therefore the rejected set's, not a timer's.
26
+ userOfferCooldown: (userId) => `${prefix}user:${userId}:offer-cooldown`,
19
27
  userWindowGrants: (userId) => `${prefix}user:${userId}:window-grants`,
20
28
  userActivity: () => `${prefix}users:activity`,
21
29
  pausedUsers: () => `${prefix}users:paused`,
@@ -25,6 +33,15 @@ function createKeyBuilders(config) {
25
33
  // member orphaned by a missed removal is filtered against the global
26
34
  // acceptedAssignments hash on read and self-healed with a zRem.
27
35
  userAcceptedAssignments: (userId) => `${prefix}user:${userId}:accepted`,
36
+ // Who holds each accepted assignment: hash of assignmentId -> userId,
37
+ // written in the accept transaction. Acceptance deletes the pending
38
+ // owner hash, and only SLA-bearing records carry an `_acceptedBy`
39
+ // stamp (the byte-identical rule forbids stamping the rest), so
40
+ // without this there is no index answering "who accepted this" for an
41
+ // ordinary assignment. Every accept overwrites its own entry, so an
42
+ // entry orphaned by a missed removal is never read: the accepted hash
43
+ // is the gate, and a record absent from it is nobody's.
44
+ acceptedAssignmentOwner: () => `${prefix}assignments:accepted:owner`,
28
45
  // Assignment keys
29
46
  assignments: () => `${prefix}assignments`,
30
47
  assignmentsRef: () => `${prefix}assignments:ref`,
@@ -59,6 +76,28 @@ function createKeyBuilders(config) {
59
76
  // holds one score per member and an assignment can carry both
60
77
  // sla.expireAfterMs and schedule.notAfter.
61
78
  scheduleNotAfter: () => `${prefix}assignments:schedule:notAfter`,
79
+ // Slot / booking keys
80
+ // Who is reserved for each slotted assignment: hash id -> JSON
81
+ // SlotBooking. Its presence is the claim gate (see book-slot.lua), so
82
+ // this is the single index answering "is this booked, and by whom".
83
+ // The row is written when the reservation is made and cleared only on
84
+ // hand-back or a terminal transition -- NOT at activation: "this
85
+ // person's 14:00 is spoken for" stays true while they are doing the
86
+ // work, and keeping it means the overlap rule protects in-flight
87
+ // appointments too.
88
+ slotBookings: () => `${prefix}assignments:bookings`,
89
+ // Span index backing the overlap probe: id -> "<startAt>:<endAt>".
90
+ // Separate from the record above because the probe reads it for every
91
+ // candidate in the window and must not pay for a JSON decode each time.
92
+ bookingSpans: () => `${prefix}assignments:bookings:spans`,
93
+ // One worker's calendar: zset of assignment ids scored by slot start.
94
+ // Backs both the overlap probe (a bounded range read) and the
95
+ // worker-facing calendar query.
96
+ userBookings: (userId) => `${prefix}user:${userId}:bookings`,
97
+ // Booking sweep index: slotted assignment id scored by the epoch ms at
98
+ // which it may be booked (slot.startAt - bookAheadMs). One-shot zRem
99
+ // claims, like scheduledActivateAt.
100
+ slotBookingDueAt: () => `${prefix}assignments:bookings:dueAt`,
62
101
  // Recurrence keys
63
102
  // Standing recurring templates: raw JSON records ({template, nextAt,
64
103
  // occurrences}). Never matchable themselves — the recurrence sweep
@@ -116,6 +155,10 @@ function createKeyBuilders(config) {
116
155
  completedRetentionIndexed: () => `${prefix}assignments:completed:retention-indexed`,
117
156
  // Decision trace stream (auditable routing decisions)
118
157
  decisionTraces: () => `${prefix}decisions:traces`,
158
+ /** Stream ids of one assignment's traces, newest first; kept in step with the capped stream. */
159
+ decisionTraceIndex: (assignmentId) => `${prefix}decisions:traces:by-assignment:${assignmentId}`,
160
+ /** First stream id written with an index; anything older predates it and is found by scanning. */
161
+ decisionTraceIndexedSince: () => `${prefix}decisions:traces:indexed-since`,
119
162
  // Redis Streams keys
120
163
  eventStream: () => `${prefix}events:stream`,
121
164
  eventStreamDeadLetter: () => `${prefix}events:deadletter`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assignment-user-matcher",
3
- "version": "1.16.1",
3
+ "version": "1.22.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/ViljarVoidula/assignment-user-matcher"
@@ -22,12 +22,20 @@
22
22
  "types": "./dist/scheduling/index.d.ts",
23
23
  "require": "./dist/scheduling/index.js",
24
24
  "import": "./dist/scheduling/index.js"
25
+ },
26
+ "./forecasting": {
27
+ "types": "./dist/forecasting/index.d.ts",
28
+ "require": "./dist/forecasting/index.js",
29
+ "import": "./dist/forecasting/index.js"
25
30
  }
26
31
  },
27
32
  "typesVersions": {
28
33
  "*": {
29
34
  "scheduling": [
30
35
  "dist/scheduling/index.d.ts"
36
+ ],
37
+ "forecasting": [
38
+ "dist/forecasting/index.d.ts"
31
39
  ]
32
40
  }
33
41
  },
@@ -39,11 +47,16 @@
39
47
  },
40
48
  "scripts": {
41
49
  "test": "nyc mocha tests/ --recursive --extension .ts --exit",
50
+ "test:focused": "mocha --no-config --require ts-node/register --extension ts --exit",
51
+ "claude:usage": "python3 scripts/claude/claude-usage.py",
42
52
  "benchmark:learning": "ts-node benchmark-learning.ts",
43
53
  "benchmark:weights": "ts-node benchmark-weights.ts",
44
54
  "benchmark:scenarios": "ts-node benchmark-learning-scenarios.ts",
45
55
  "benchmark:scheduling": "ts-node benchmark-scheduling.ts",
46
- "build:docs": "npx typedoc --plugin typedoc-plugin-markdown",
56
+ "benchmark:scheduling:complex": "ts-node --transpile-only benchmark-scheduling-complex.ts",
57
+ "benchmark:forecast": "ts-node --transpile-only scripts/forecast-benchmark.ts",
58
+ "benchmark:staffing": "ts-node --transpile-only scripts/staffing-benchmark.ts",
59
+ "build:docs": "typedoc --plugin typedoc-plugin-markdown",
47
60
  "lint": "eslint . --cache --cache-location node_modules/.cache/eslint/.eslintcache",
48
61
  "lint:ci": "eslint . --quiet --cache --cache-location node_modules/.cache/eslint/.eslintcache",
49
62
  "lint:fix": "eslint . --fix",