assignment-user-matcher 1.16.0 → 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 (166) hide show
  1. package/README.md +312 -20
  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/consecutive.d.ts +10 -0
  90. package/dist/scheduling/constraints/consecutive.d.ts.map +1 -1
  91. package/dist/scheduling/constraints/consecutive.js +64 -1
  92. package/dist/scheduling/constraints/contract.d.ts.map +1 -1
  93. package/dist/scheduling/constraints/contract.js +12 -3
  94. package/dist/scheduling/constraints/employee-scope.d.ts.map +1 -1
  95. package/dist/scheduling/constraints/employee-scope.js +10 -2
  96. package/dist/scheduling/constraints/group-composition.js +2 -2
  97. package/dist/scheduling/constraints/min-staffing.d.ts.map +1 -1
  98. package/dist/scheduling/constraints/min-staffing.js +51 -8
  99. package/dist/scheduling/constraints/rolling-hours.d.ts.map +1 -1
  100. package/dist/scheduling/constraints/rolling-hours.js +29 -4
  101. package/dist/scheduling/constraints/support.d.ts +4 -8
  102. package/dist/scheduling/constraints/support.d.ts.map +1 -1
  103. package/dist/scheduling/constraints/support.js +23 -2
  104. package/dist/scheduling/constraints/weekly-rest.d.ts +28 -0
  105. package/dist/scheduling/constraints/weekly-rest.d.ts.map +1 -1
  106. package/dist/scheduling/constraints/weekly-rest.js +108 -21
  107. package/dist/scheduling/engine/construction.d.ts.map +1 -1
  108. package/dist/scheduling/engine/construction.js +56 -7
  109. package/dist/scheduling/engine/objective.d.ts +0 -1
  110. package/dist/scheduling/engine/objective.d.ts.map +1 -1
  111. package/dist/scheduling/engine/objective.js +65 -6
  112. package/dist/scheduling/engine/search.d.ts +4 -0
  113. package/dist/scheduling/engine/search.d.ts.map +1 -1
  114. package/dist/scheduling/engine/search.js +2 -1
  115. package/dist/scheduling/engine/state.d.ts +14 -0
  116. package/dist/scheduling/engine/state.d.ts.map +1 -1
  117. package/dist/scheduling/engine/state.js +7 -0
  118. package/dist/scheduling/engine/timeline.d.ts +23 -1
  119. package/dist/scheduling/engine/timeline.d.ts.map +1 -1
  120. package/dist/scheduling/engine/timeline.js +85 -27
  121. package/dist/scheduling/engine/verdicts.d.ts +40 -1
  122. package/dist/scheduling/engine/verdicts.d.ts.map +1 -1
  123. package/dist/scheduling/engine/verdicts.js +177 -17
  124. package/dist/scheduling/index.d.ts +3 -2
  125. package/dist/scheduling/index.d.ts.map +1 -1
  126. package/dist/scheduling/index.js +7 -1
  127. package/dist/scheduling/model.d.ts +8 -4
  128. package/dist/scheduling/model.d.ts.map +1 -1
  129. package/dist/scheduling/model.js +239 -23
  130. package/dist/scheduling/operations.d.ts +174 -2
  131. package/dist/scheduling/operations.d.ts.map +1 -1
  132. package/dist/scheduling/operations.js +558 -21
  133. package/dist/scheduling/preference-report.d.ts +15 -0
  134. package/dist/scheduling/preference-report.d.ts.map +1 -0
  135. package/dist/scheduling/preference-report.js +111 -0
  136. package/dist/scheduling/preferences.d.ts +30 -0
  137. package/dist/scheduling/preferences.d.ts.map +1 -0
  138. package/dist/scheduling/preferences.js +85 -0
  139. package/dist/scheduling/resilience.d.ts +46 -0
  140. package/dist/scheduling/resilience.d.ts.map +1 -0
  141. package/dist/scheduling/resilience.js +45 -0
  142. package/dist/scheduling/scheduler.class.d.ts +12 -1
  143. package/dist/scheduling/scheduler.class.d.ts.map +1 -1
  144. package/dist/scheduling/scheduler.class.js +28 -4
  145. package/dist/scheduling/sites.d.ts +1 -1
  146. package/dist/scheduling/sites.d.ts.map +1 -1
  147. package/dist/scheduling/sites.js +34 -1
  148. package/dist/scheduling/time.d.ts +28 -6
  149. package/dist/scheduling/time.d.ts.map +1 -1
  150. package/dist/scheduling/time.js +59 -17
  151. package/dist/scheduling/types.d.ts +247 -7
  152. package/dist/scheduling/types.d.ts.map +1 -1
  153. package/dist/scoring/fair-arbitration.d.ts.map +1 -1
  154. package/dist/scoring/fair-arbitration.js +2 -1
  155. package/dist/tracing/decision-trace.d.ts +5 -0
  156. package/dist/tracing/decision-trace.d.ts.map +1 -1
  157. package/dist/tracing/decision-trace.js +3 -0
  158. package/dist/types/matcher.d.ts +369 -2
  159. package/dist/types/matcher.d.ts.map +1 -1
  160. package/dist/updates/assignment-update.d.ts +93 -0
  161. package/dist/updates/assignment-update.d.ts.map +1 -0
  162. package/dist/updates/assignment-update.js +91 -0
  163. package/dist/utils/keys.d.ts +10 -0
  164. package/dist/utils/keys.d.ts.map +1 -1
  165. package/dist/utils/keys.js +43 -0
  166. package/package.json +25 -3
@@ -0,0 +1,11 @@
1
+ /** Small numeric helpers the forecasting module shares. Pure, allocation-light. */
2
+ export declare function clamp(value: number, min: number, max: number): number;
3
+ /** Quantile of an unsorted sample by linear interpolation (type 7); NaN for an empty one. */
4
+ export declare function quantile(values: readonly number[], p: number): number;
5
+ /** Quantile of an already ascending sample. */
6
+ export declare function quantileSorted(sorted: readonly number[], p: number): number;
7
+ export declare function median(values: readonly number[]): number;
8
+ export declare function mean(values: readonly number[]): number;
9
+ /** Round to a fixed number of decimals, so stored forecasts stay small and stable. */
10
+ export declare function round(value: number, decimals?: number): number;
11
+ //# sourceMappingURL=stats.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stats.d.ts","sourceRoot":"","sources":["../../src/forecasting/stats.ts"],"names":[],"mappings":"AAAA,mFAAmF;AAEnF,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAErE;AAED,6FAA6F;AAC7F,wBAAgB,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAIrE;AAED,+CAA+C;AAC/C,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAM3E;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAExD;AAED,wBAAgB,IAAI,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAKtD;AAED,sFAAsF;AACtF,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,SAAI,GAAG,MAAM,CAGzD"}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ /** Small numeric helpers the forecasting module shares. Pure, allocation-light. */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.round = exports.mean = exports.median = exports.quantileSorted = exports.quantile = exports.clamp = void 0;
5
+ function clamp(value, min, max) {
6
+ return Math.min(max, Math.max(min, value));
7
+ }
8
+ exports.clamp = clamp;
9
+ /** Quantile of an unsorted sample by linear interpolation (type 7); NaN for an empty one. */
10
+ function quantile(values, p) {
11
+ if (values.length === 0)
12
+ return Number.NaN;
13
+ const sorted = [...values].sort((a, b) => a - b);
14
+ return quantileSorted(sorted, p);
15
+ }
16
+ exports.quantile = quantile;
17
+ /** Quantile of an already ascending sample. */
18
+ function quantileSorted(sorted, p) {
19
+ if (sorted.length === 0)
20
+ return Number.NaN;
21
+ const at = clamp(p, 0, 1) * (sorted.length - 1);
22
+ const lo = Math.floor(at);
23
+ const hi = Math.ceil(at);
24
+ return sorted[lo] + (sorted[hi] - sorted[lo]) * (at - lo);
25
+ }
26
+ exports.quantileSorted = quantileSorted;
27
+ function median(values) {
28
+ return quantile(values, 0.5);
29
+ }
30
+ exports.median = median;
31
+ function mean(values) {
32
+ if (values.length === 0)
33
+ return Number.NaN;
34
+ let sum = 0;
35
+ for (const v of values)
36
+ sum += v;
37
+ return sum / values.length;
38
+ }
39
+ exports.mean = mean;
40
+ /** Round to a fixed number of decimals, so stored forecasts stay small and stable. */
41
+ function round(value, decimals = 2) {
42
+ const f = 10 ** decimals;
43
+ return Math.round(value * f) / f;
44
+ }
45
+ exports.round = round;
@@ -0,0 +1,299 @@
1
+ /**
2
+ * Public types of the forecasting module: work volume per series and the
3
+ * aggregate staffing it takes. Nothing here describes a person — a series is a
4
+ * tag, a site or an imported volume, and a pool member is a declared skill
5
+ * profile with a head count.
6
+ */
7
+ /** One UTC clock hour of history. `at` is the epoch ms of the hour's start. */
8
+ export interface HourlyPoint {
9
+ at: number;
10
+ value: number;
11
+ }
12
+ /** One UTC calendar day of history (`YYYY-MM-DD`). */
13
+ export interface DailyPoint {
14
+ date: string;
15
+ value: number;
16
+ }
17
+ /** A series' history. Missing hours and days read as zero once the series has started. */
18
+ export interface SeriesHistory {
19
+ series: string;
20
+ /** Recent hourly history (the platform keeps 16 weeks). Drives the hour-of-week shape and the nowcast. */
21
+ hourly: HourlyPoint[];
22
+ /** Long daily history (the platform keeps 3 years). Drives level, trend, the yearly factor and effects. */
23
+ daily: DailyPoint[];
24
+ }
25
+ /**
26
+ * A dated occurrence of something that moves volume: a sale, a campaign, a
27
+ * closure, a public holiday. Past occurrences are divided out of history and
28
+ * teach the effect; future ones are multiplied back on.
29
+ */
30
+ export interface KnownOccurrence {
31
+ /** Links occurrences across years (`winter-sale`); holidays use `holiday:<name>`. */
32
+ label: string;
33
+ /** `sale` | `campaign` | `launch` | `season` | `closure` | `holiday` | anything a planner types. */
34
+ kind: string;
35
+ /** Inclusive local dates. */
36
+ from: string;
37
+ to: string;
38
+ /** The planner's own estimate, in percent, used when history has nothing for this label. */
39
+ planned?: {
40
+ likely: number;
41
+ low?: number;
42
+ high?: number;
43
+ };
44
+ /** The place is shut: the forecast is zero, whatever history says. */
45
+ closed?: boolean;
46
+ }
47
+ /** Where an effect's numbers came from, strongest first. */
48
+ export type EffectSource = 'label' | 'planned' | 'kind' | 'default';
49
+ /** What an occurrence does to volume, learned or stated. Factors multiply the baseline. */
50
+ export interface LearnedEffect {
51
+ label: string;
52
+ kind: string;
53
+ source: EffectSource;
54
+ /** Past occurrences it was learned from (0 for planned/default). */
55
+ occurrences: number;
56
+ /** Mean factor over the occurrence's days. */
57
+ size: number;
58
+ /** Low and high factor over the occurrence's days (range across past occurrences, or planned low/high). */
59
+ low: number;
60
+ high: number;
61
+ /** Factor per day of the occurrence relative to `size` (day 1 = index 0); the last value repeats. */
62
+ shape: number[];
63
+ /** Factor per day after the occurrence ends (index 0 = the first day after); empty when none was seen. */
64
+ knockOn: number[];
65
+ }
66
+ /** Why an hour's number is what it is. `likely = base × trend × season × holiday × Π events × nowcast`. */
67
+ export interface HourComponents {
68
+ /** The current weekly level spread over this hour of the week, in the series' units. */
69
+ base: number;
70
+ /** Damped trend from the current week to this hour's week, as a factor. */
71
+ trend: number;
72
+ /** Yearly factor for this week (1 without ≥ 56 weeks of history). */
73
+ season: number;
74
+ /** Public-holiday factor (1 on an ordinary day). */
75
+ holiday: number;
76
+ /** Every event touching this hour, with its factor (including knock-on days). */
77
+ events: Array<{
78
+ label: string;
79
+ factor: number;
80
+ }>;
81
+ /** Today's actual/expected rescale, fading to 1 over 72 hours. */
82
+ nowcast: number;
83
+ }
84
+ export interface HourForecast {
85
+ at: number;
86
+ low: number;
87
+ likely: number;
88
+ high: number;
89
+ components: HourComponents;
90
+ }
91
+ export interface WeekForecast {
92
+ /** Local date of the week's Monday. */
93
+ weekStart: string;
94
+ low: number;
95
+ likely: number;
96
+ high: number;
97
+ season: number;
98
+ /** Labels of the events touching the week. */
99
+ events: string[];
100
+ }
101
+ export type LeadBucket = '24h' | '72h' | '7d' | '28d';
102
+ export interface ForecastAccuracy {
103
+ /**
104
+ * Weighted absolute percentage error by lead, from rolling-origin backtests, on local-day totals (UTC days
105
+ * of the daily table for a series without hourly history); null without enough history.
106
+ */
107
+ wape: Record<LeadBucket, number | null>;
108
+ /** Backtest origins that could be judged (0 when the ranges were borrowed). */
109
+ origins: number;
110
+ /**
111
+ * Where the ranges came from: this series' own backtests, the total
112
+ * series' (a small series outside the busiest few is not backtested — its
113
+ * ranges are the total's, never narrower than its own counting noise), or
114
+ * the defaults when neither had enough history.
115
+ */
116
+ rangesFrom: 'own' | 'total' | 'default';
117
+ /**
118
+ * True when any reason other than `no-hourly-shape` applies: under 4 weeks of history, a 72-hour WAPE
119
+ * above 35 %, or a first-time event in the horizon. A missing hourly shape is reported in `reasons`
120
+ * but does not by itself make the forecast low confidence — its day and week totals are as sound as
121
+ * any; only its hours are an even spread (see `SeriesForecast.hasHourlyShape`).
122
+ */
123
+ lowConfidence: boolean;
124
+ /** `short-history`, `high-error`, `first-time-event:<label>`, `no-hourly-shape`. */
125
+ reasons: string[];
126
+ }
127
+ export interface SeriesForecast {
128
+ series: string;
129
+ /** Epoch ms of local midnight on the day `now` falls in: the first hour. */
130
+ from: number;
131
+ hours: HourForecast[];
132
+ weeks: WeekForecast[];
133
+ accuracy: ForecastAccuracy;
134
+ /** Whether a yearly factor was used (≥ 56 weeks of daily history). */
135
+ yearly: boolean;
136
+ /** Complete weeks of daily history the level was fitted on. */
137
+ historyWeeks: number;
138
+ /**
139
+ * Whether the hour-of-day pattern was read from hourly history. False for a series with only daily
140
+ * history: its `hours` are the day total spread evenly over the day (1/24 each), not a pattern, so
141
+ * hourly need read off them is wrong at both ends of the day. Convert such a series' day total with
142
+ * `coverPersonHours` instead of reading its hours through `coverNeed`.
143
+ */
144
+ hasHourlyShape: boolean;
145
+ /** Every effect the forecast used or learned, by label. */
146
+ effects: LearnedEffect[];
147
+ }
148
+ /** A run of days far outside what the model expected, for the "What was this?" inbox. */
149
+ export interface SpikeSpan {
150
+ /** Inclusive UTC dates (the daily history's grain). */
151
+ from: string;
152
+ to: string;
153
+ direction: 'up' | 'down';
154
+ /** Actual minus expected over the span, in the series' units. */
155
+ excess: number;
156
+ /** Largest actual/expected day ratio in the span (smallest for a dip). */
157
+ peakRatio: number;
158
+ /** Which series moved, largest share first (at most five). */
159
+ bySeries: Array<{
160
+ series: string;
161
+ excess: number;
162
+ share: number;
163
+ }>;
164
+ }
165
+ export interface ForecastWorkspaceInput {
166
+ /** IANA zone the hour-of-week pattern and the occurrences' dates are read in. */
167
+ timeZone: string;
168
+ /** "As of", epoch ms. Nothing at or after it is read as history. */
169
+ now: number;
170
+ series: SeriesHistory[];
171
+ occurrences?: KnownOccurrence[];
172
+ /** Hourly horizon from local midnight today; default 672 (28 days). */
173
+ horizonHours?: number;
174
+ /** Weekly horizon from this week's Monday; default 26. */
175
+ horizonWeeks?: number;
176
+ /** Rolling-origin backtests per series; default 6. */
177
+ backtestOrigins?: number;
178
+ /** The series spikes are found on and the others decompose; default `'*'`. */
179
+ totalSeries?: string;
180
+ /** How many series besides the total get their own backtests (the busiest by the last 28 days); default 10. */
181
+ backtestSeries?: number;
182
+ }
183
+ export interface ForecastWorkspaceResult {
184
+ series: SeriesForecast[];
185
+ spikes: SpikeSpan[];
186
+ ms: number;
187
+ }
188
+ /**
189
+ * A distribution given by its quantiles at evenly spaced probabilities,
190
+ * `q[0]` = minimum (p0) … `q[n-1]` = maximum (p100). At least two points,
191
+ * non-decreasing. Sampled by inverse CDF with linear interpolation.
192
+ */
193
+ export interface QuantileDistribution {
194
+ q: number[];
195
+ }
196
+ /** How one kind of work behaves, as measured. Never about a person. */
197
+ export interface TagProfile {
198
+ tag: string;
199
+ /** Time a task is in someone's hands, ms. */
200
+ handleMs: QuantileDistribution;
201
+ /** How long queued work waits before it is cancelled or expires, ms; absent = nobody leaves. */
202
+ patienceMs?: QuantileDistribution | null;
203
+ /** Tasks one person works at once on this tag; default 1. */
204
+ concurrency?: number;
205
+ /** The task priority this tag's work usually carries; default 0. */
206
+ priority?: number;
207
+ /** Picked up within this wait counts as served, ms. */
208
+ targetWaitMs: number;
209
+ /**
210
+ * Share of arrivals that must be picked up within `targetWaitMs`, 0–1. A task that gives up waiting
211
+ * counts as not served, also when it gives up before the target wait.
212
+ */
213
+ targetShare: number;
214
+ }
215
+ /**
216
+ * A declared skill profile and how many people have it: routing tags (suffix
217
+ * wildcards as the router reads them) and declared routing weights. Never
218
+ * learned weights, never anybody's measured speed.
219
+ */
220
+ export interface PoolMember {
221
+ tags: string[];
222
+ weights?: Record<string, number>;
223
+ count: number;
224
+ }
225
+ /** One interval's expected arrivals per tag. */
226
+ export interface StaffingInterval {
227
+ startMs: number;
228
+ arrivals: Record<string, number>;
229
+ }
230
+ export interface StaffingOptions {
231
+ /**
232
+ * Most simulation seeds per interval; default 20. After 8, an interval stops drawing more once every
233
+ * tag's pooled service level near the answer is known to ±0.01 (95 %).
234
+ */
235
+ seeds?: number;
236
+ /** Base seed; default 1. Same inputs + seed = same answer. */
237
+ seed?: number;
238
+ /** Gamma shape k of the arrival-rate noise around the forecast (larger = closer to Poisson); default 20. */
239
+ overdispersion?: number;
240
+ /** Share of on-shift time not spent on the queue, 0–0.9. */
241
+ shrinkage: number;
242
+ /** Interval length, minutes; default 60. */
243
+ intervalMinutes?: number;
244
+ /**
245
+ * Stop simulating after this many ms of wall time; remaining intervals come back `method: 'skipped'`
246
+ * (an interval whose load an earlier one already simulated is still answered from the memo). Checked
247
+ * before each interval's simulation and before each solve of a backlog re-read; a solve in progress is
248
+ * never interrupted, so a run can overshoot by one interval's simulation.
249
+ */
250
+ budgetMs?: number;
251
+ /**
252
+ * Relative grid arrivals are rounded to before simulating (memo key); default 0.05. Not used when the
253
+ * intervals are chained (a tag's target is ≥ 15 min or ≥ 2 mean handle times): back-to-back intervals
254
+ * are then simulated in sequence with the queue carried over, and never share a simulation.
255
+ */
256
+ quantizeStep?: number;
257
+ /** The most people the search will try; default 500. */
258
+ maxPeople?: number;
259
+ }
260
+ export interface Range {
261
+ low: number;
262
+ likely: number;
263
+ high: number;
264
+ }
265
+ export interface IntervalNeed {
266
+ startMs: number;
267
+ /**
268
+ * People working the queue (after shrinkage is removed). `likely` meets the target on average, allowing
269
+ * for forecast error: the fewest people whose share served in time, over all seeds (rate-noised draws)
270
+ * together, meets the target. `low` / `high` are the p10 / p90 of each seed's own answer.
271
+ */
272
+ productive: Range;
273
+ /** People to have on shift: productive ÷ (1 − shrinkage), rounded up. */
274
+ onShift: Range;
275
+ /** Share served within target per tag at the likely head count, over all seeds together. */
276
+ serviceByTag: Record<string, number>;
277
+ /** Tags with arrivals nobody in the pool can take: left out of the search. */
278
+ uncovered: string[];
279
+ /** The Erlang A head count the search started from. */
280
+ erlangSeed: number;
281
+ /** `simulation`, `none` (no arrivals) or `skipped` (over the time budget). */
282
+ method: 'simulation' | 'none' | 'skipped';
283
+ /** The search hit `maxPeople` without meeting the target. */
284
+ capped: boolean;
285
+ /**
286
+ * The likely team needs more people of some declared profile than the pool has: the extra heads are
287
+ * people to hire (or borrow) with that profile's skills.
288
+ */
289
+ exceedsPool: boolean;
290
+ }
291
+ export interface StaffingResult {
292
+ intervals: IntervalNeed[];
293
+ ms: number;
294
+ /** Seeds drawn: simulated loads × seeds (memo hits draw none). */
295
+ simulations: number;
296
+ cacheHits: number;
297
+ incomplete: boolean;
298
+ }
299
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/forecasting/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,+EAA+E;AAC/E,MAAM,WAAW,WAAW;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,sDAAsD;AACtD,MAAM,WAAW,UAAU;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,0FAA0F;AAC1F,MAAM,WAAW,aAAa;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,0GAA0G;IAC1G,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,2GAA2G;IAC3G,KAAK,EAAE,UAAU,EAAE,CAAC;CACvB;AAED;;;;GAIG;AACH,MAA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E,OAAO,EAAE,KAAK,CAAC;IACf,4FAA4F;IAC5F,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,8EAA8E;IAC9E,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,uDAAuD;IACvD,UAAU,EAAE,MAAM,CAAC;IACnB,8EAA8E;IAC9E,MAAM,EAAE,YAAY,GAAG,MAAM,GAAG,SAAS,CAAC;IAC1C,6DAA6D;IAC7D,MAAM,EAAE,OAAO,CAAC;IAChB;;;OAGG;IACH,WAAW,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,cAAc;IAC3B,SAAS,EAAE,YAAY,EAAE,CAAC;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,kEAAkE;IAClE,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC;CACvB"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ /**
3
+ * Public types of the forecasting module: work volume per series and the
4
+ * aggregate staffing it takes. Nothing here describes a person — a series is a
5
+ * tag, a site or an imported volume, and a pool member is a declared skill
6
+ * profile with a head count.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
package/dist/index.d.ts CHANGED
@@ -1,13 +1,14 @@
1
1
  import AssignmentMatcher from './matcher.class';
2
- export type { Assignment, MatcherOptions, options, Stats, QueueStats, UserLoadInfo, User, GeoMatchResult, GeoMatchingFunction, ReliabilityMetrics, AssignmentStatus, FairnessMode, FairnessConfig, MatchTraceReason, MatchCandidateTrace, MatchDecisionTrace, MatchDecisionMode, MatchExplanation, MatchPreview, MatchPreviewInput, DecisionTraceQuery, AssignmentLifecycleEvent, EscalationPolicy, EscalationSweepResult, CompletionDeadlineSweepResult, SlaExpirySweepResult, SlaPolicy, SlaStats, SchedulePolicy, ScheduleSweepResult, RecurrencePolicy, RecurringAssignment, RecurringAssignmentRecord, RecurrenceSweepResult, RetentionSweepResult, CompletedAssignmentPage, AssignmentLintIssue, AssignmentLintContext, AssignmentReadinessReport, QueueAuditOptions, QueueAuditEntry, QueueAuditReport, MaintenanceOptions, MaintenanceReport, UserStatusFilter, UserQueryOptions, UserSummary, UserQueryResult, ActiveAssignmentInfo, } from './matcher.class';
2
+ export type { Assignment, MatcherOptions, options, Stats, QueueStats, UserLoadInfo, LaneStat, LaneStatsOptions, LaneStatsReport, WaitDistribution, User, GeoMatchResult, GeoMatchingFunction, ReliabilityMetrics, AssignmentStatus, FairnessMode, FairnessConfig, MatchTraceReason, MatchCandidateTrace, MatchDecisionTrace, MatchDecisionMode, MatchExplanation, MatchPreview, MatchPreviewInput, DecisionTraceQuery, AssignmentLifecycleEvent, EscalationPolicy, EscalationSweepResult, CompletionDeadlineSweepResult, SlaExpirySweepResult, SlaPolicy, SlaStats, SchedulePolicy, ScheduleSweepResult, RecurrencePolicy, RecurringAssignment, RecurringAssignmentRecord, RecurrenceSweepResult, RetentionSweepResult, CompletedAssignmentPage, AssignmentLintIssue, AssignmentLintContext, AssignmentReadinessReport, QueueAuditOptions, QueueAuditEntry, QueueAuditReport, MaintenanceOptions, MaintenanceReport, TimeSlot, SlotAvailability, SlotBooking, SlotBookingRefusal, SlotCandidate, BookingSweepResult, UserStatusFilter, UserQueryOptions, UserSummary, UserQueryResult, ActiveAssignmentInfo, } from './matcher.class';
3
3
  export { lintAssignment, userCoversTag } from './validation/assignment-lint';
4
4
  export type { WorkflowDefinition, WorkflowDefinitionInput, WorkflowDefinitionSummary, WorkflowInstance, WorkflowInstanceStatus, WorkflowStep, WorkflowRouting, WorkflowTargetUser, WorkflowMachineTask, WorkflowExternalTask, WorkflowTaskType, WorkflowEvent, WorkflowEventType, AssignmentResult, ParallelBranchState, DeadLetterEntry, AuditEntry, CircuitBreakerState, WorkflowInstanceWithSnapshot, WorkflowInstanceQuery, WorkflowInstancePage, WorkflowTransition, LearningOutcome, LearningRewards, LearningFeatures, LearningAssignmentContext, LearningFeatureExtractor, LearningDecisionRecord, LearningEpisodeRecord, LearningSignals, LearningSample, LearningStats, LearningTagStat, LearningRewardTarget, LearningTargetsOptions, LearningPrediction, LearningRewardAccounting, LearningUpdateMode, LearningExplorationPolicy, LearningDecisionContext, LearningFeatureContext, LearningWorkerPerformance, AutoWeightExplanation, AutoRoutingWeightsOptions, AutoRoutingWeightsPolicy, PendingAssignmentInfo, WorkflowEngineMetrics, MachineTaskHandler, WorkflowHost, PaginationOptions, PaginationResult, AssignmentCounts, } from './matcher.class';
5
+ export type { AssignmentUpdate, UpdatableStatus, UpdateAssignmentResult } from './updates/assignment-update';
5
6
  export { explainMatchScore, type MatchScoreExplanation } from './scoring/match-score';
6
7
  export { extractMatchFeatures, cosineSimilarity } from './learning/features';
7
8
  export { synthesizeRoutingWeights, explainRoutingWeights, DEFAULT_AUTO_WEIGHTS_OPTIONS } from './learning/auto-weights';
8
9
  export { epsilonGreedySelect, greedySelect } from './learning/policy';
9
10
  export type { PolicyChoice, EpsilonGreedyOptions } from './learning/policy';
10
- export { ShiftScheduler, solveSchedule, ScheduleValidationError, DEFAULT_MIN_REST_MINUTES, PeriodClock, expandShiftInstances, checkCompliance, explainCandidate, repairSchedule, rankCandidates, diagnoseInfeasibility, hours, days, weeklyAverageOver, DEFAULT_CONTRACT_HOURS_WEIGHT, contractedPeriodMinutes, fullTimeWeeklyMinutes, resolveContractedWeeklyMinutes, type AssignmentPair, type AvailabilityRule, type BreakRule, type ClockRange, type ClockRangeConfig, type ComplianceReport, type ConsecutiveRule, type ConstraintOptions, type ConstraintViolation, type DailyRestRule, type Disruption, type DutyClassification, type DutyQuota, type Employee, type EmployeeContract, type ContractHoursRule, type ContractHoursSummary, type EmployeeCost, type EmployeeProtection, type EngagementRule, type FairnessRule, type HistoricalAssignment, type InfeasibilityReport, type LedgerEntry, type MinuteRange, type ModelContext, type NightVolumeQuota, type NightWorkRule, type NoticeRule, type ObjectiveWeights, type OvertimeRule, type PersonTimeline, type Qualification, type RepairCandidate, type RepairResult, type RestDayRule, type RollingAverage, type RuleVerdict, type ScheduleInput, type ScheduleProvenance, type ScheduleResult, type ScheduledAssignment, type SchedulingConstraint, type SearchState, type Severity, type ShiftInstance, type ShiftTemplate, type ShiftDemandOverride, type Site, type SiteIndex, type TimeOffEntry, type TimelineEntry, type TimelineIndex, type WeeklyRestRule, type WorkingTimeLimits, type WorkingTimeRules, } from './scheduling';
11
+ export { ShiftScheduler, solveSchedule, ScheduleValidationError, DEFAULT_MIN_REST_MINUTES, PeriodClock, expandShiftInstances, checkCompliance, explainCandidate, repairSchedule, rankCandidates, rankShiftsFor, assessShiftResilience, resilienceTier, rankSwapPartners, checkSwap, diagnoseInfeasibility, hours, days, weeklyAverageOver, DEFAULT_CONTRACT_HOURS_WEIGHT, contractedPeriodMinutes, fullTimeWeeklyMinutes, resolveContractedWeeklyMinutes, type AssignmentPair, type AvailabilityRule, type BreakRule, type ClockRange, type ClockRangeConfig, type ComplianceReport, type ConsecutiveRule, type ConstraintOptions, type ConstraintViolation, type DailyRestRule, type Disruption, type DutyClassification, type DutyQuota, type Employee, type EmployeeContract, type ContractHoursRule, type ContractHoursSummary, type EmployeeCost, type EmployeePreferenceReport, type EmployeeProtection, type EngagementRule, type FairnessRule, type HistoricalAssignment, type InfeasibilityReport, type TagCover, type ResilienceOptions, type ResilienceTier, type ShiftResilience, type SkillResilience, type LedgerEntry, type MinuteRange, type ModelContext, type NightVolumeQuota, type NightWorkRule, type NoticeRule, type ObjectiveWeights, type OvertimeRule, type PersonTimeline, type PreferenceObjective, type PreferenceRuleOutcome, type Qualification, type RepairCandidate, type RepairResult, type SwapPartner, type SwapPartnerOptions, type SwapTrade, type SwapCheck, type RestDayRule, type RollingAverage, type RuleVerdict, type ScheduleInput, type ScheduleProvenance, type ScheduleResult, type SearchProgress, type ScheduledAssignment, type SchedulingConstraint, type SearchState, type Severity, type ShiftInstance, type ShiftTemplate, type TagRequirement, type ShiftDemandOverride, type Site, type SiteIndex, type TimeOffEntry, type TimelineEntry, type TimelineIndex, type WeeklyRestRule, type WorkingTimeLimits, type WorkingTimeRules, } from './scheduling';
11
12
  export { WorkflowBuilder, WorkflowStepBuilder, workflow, linearWorkflow, approvalWorkflow } from './workflow-builder';
12
13
  export { normalizeWorkflowDefinition, validateWorkflowDefinition } from './workflow-validation';
13
14
  export * from './utils/cidr';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,iBAAiB,CAAC;AAEhD,YAAY,EACR,UAAU,EACV,cAAc,EACd,OAAO,EACP,KAAK,EACL,UAAU,EACV,YAAY,EACZ,IAAI,EACJ,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,wBAAwB,EACxB,gBAAgB,EAChB,qBAAqB,EACrB,6BAA6B,EAC7B,oBAAoB,EACpB,SAAS,EACT,QAAQ,EACR,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACnB,yBAAyB,EACzB,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,EACvB,mBAAmB,EACnB,qBAAqB,EACrB,yBAAyB,EACzB,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,oBAAoB,GACvB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAG7E,YAAY,EACR,kBAAkB,EAClB,uBAAuB,EACvB,yBAAyB,EACzB,gBAAgB,EAChB,sBAAsB,EACtB,YAAY,EACZ,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,gBAAgB,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AC7B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAE,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAExF,OAAO,EAAE,iBAAiB,EAAE,CAAC;AAC7B,eAAe,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,iBAAiB,CAAC;AAEhD,YAAY,EACR,UAAU,EACV,cAAc,EACd,OAAO,EACP,KAAK,EACL,UAAU,EACV,YAAY,EACZ,QAAQ,EACR,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,IAAI,EACJ,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,wBAAwB,EACxB,gBAAgB,EAChB,qBAAqB,EACrB,6BAA6B,EAC7B,oBAAoB,EACpB,SAAS,EACT,QAAQ,EACR,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACnB,yBAAyB,EACzB,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,EACvB,mBAAmB,EACnB,qBAAqB,EACrB,yBAAyB,EACzB,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,QAAQ,EACR,gBAAgB,EAChB,WAAW,EACX,kBAAkB,EAClB,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,oBAAoB,GACvB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAG7E,YAAY,EACR,kBAAkB,EAClB,uBAAuB,EACvB,yBAAyB,EACzB,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K,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,IAAI,EACT,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,GACxB,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,QAAQ,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtH,OAAO,EAAE,2BAA2B,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAGhG,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAE,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAExF,OAAO,EAAE,iBAAiB,EAAE,CAAC;AAC7B,eAAe,iBAAiB,CAAC"}
package/dist/index.js CHANGED
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.AssignmentMatcher = exports.createKeyBuilders = exports.validateWorkflowDefinition = exports.normalizeWorkflowDefinition = exports.approvalWorkflow = exports.linearWorkflow = exports.workflow = exports.WorkflowStepBuilder = exports.WorkflowBuilder = exports.resolveContractedWeeklyMinutes = exports.fullTimeWeeklyMinutes = exports.contractedPeriodMinutes = exports.DEFAULT_CONTRACT_HOURS_WEIGHT = exports.weeklyAverageOver = exports.days = exports.hours = exports.diagnoseInfeasibility = exports.rankCandidates = exports.repairSchedule = exports.explainCandidate = exports.checkCompliance = exports.expandShiftInstances = exports.PeriodClock = exports.DEFAULT_MIN_REST_MINUTES = exports.ScheduleValidationError = exports.solveSchedule = exports.ShiftScheduler = exports.greedySelect = exports.epsilonGreedySelect = exports.DEFAULT_AUTO_WEIGHTS_OPTIONS = exports.explainRoutingWeights = exports.synthesizeRoutingWeights = exports.cosineSimilarity = exports.extractMatchFeatures = exports.explainMatchScore = exports.userCoversTag = exports.lintAssignment = void 0;
20
+ exports.AssignmentMatcher = exports.createKeyBuilders = exports.validateWorkflowDefinition = exports.normalizeWorkflowDefinition = exports.approvalWorkflow = exports.linearWorkflow = exports.workflow = exports.WorkflowStepBuilder = exports.WorkflowBuilder = exports.resolveContractedWeeklyMinutes = exports.fullTimeWeeklyMinutes = exports.contractedPeriodMinutes = exports.DEFAULT_CONTRACT_HOURS_WEIGHT = exports.weeklyAverageOver = exports.days = exports.hours = exports.diagnoseInfeasibility = exports.checkSwap = exports.rankSwapPartners = exports.resilienceTier = exports.assessShiftResilience = exports.rankShiftsFor = exports.rankCandidates = exports.repairSchedule = exports.explainCandidate = exports.checkCompliance = exports.expandShiftInstances = exports.PeriodClock = exports.DEFAULT_MIN_REST_MINUTES = exports.ScheduleValidationError = exports.solveSchedule = exports.ShiftScheduler = exports.greedySelect = exports.epsilonGreedySelect = exports.DEFAULT_AUTO_WEIGHTS_OPTIONS = exports.explainRoutingWeights = exports.synthesizeRoutingWeights = exports.cosineSimilarity = exports.extractMatchFeatures = exports.explainMatchScore = exports.userCoversTag = exports.lintAssignment = void 0;
21
21
  const matcher_class_1 = __importDefault(require("./matcher.class"));
22
22
  exports.AssignmentMatcher = matcher_class_1.default;
23
23
  // Pre-flight lint (pure, Redis-free) — usable host-side before addAssignment
@@ -56,6 +56,13 @@ Object.defineProperty(exports, "checkCompliance", { enumerable: true, get: funct
56
56
  Object.defineProperty(exports, "explainCandidate", { enumerable: true, get: function () { return scheduling_1.explainCandidate; } });
57
57
  Object.defineProperty(exports, "repairSchedule", { enumerable: true, get: function () { return scheduling_1.repairSchedule; } });
58
58
  Object.defineProperty(exports, "rankCandidates", { enumerable: true, get: function () { return scheduling_1.rankCandidates; } });
59
+ Object.defineProperty(exports, "rankShiftsFor", { enumerable: true, get: function () { return scheduling_1.rankShiftsFor; } });
60
+ // Capacity radar: is each shift short, and who could step in?
61
+ Object.defineProperty(exports, "assessShiftResilience", { enumerable: true, get: function () { return scheduling_1.assessShiftResilience; } });
62
+ Object.defineProperty(exports, "resilienceTier", { enumerable: true, get: function () { return scheduling_1.resilienceTier; } });
63
+ // Hand-overs and trades between two workers, judged both ways.
64
+ Object.defineProperty(exports, "rankSwapPartners", { enumerable: true, get: function () { return scheduling_1.rankSwapPartners; } });
65
+ Object.defineProperty(exports, "checkSwap", { enumerable: true, get: function () { return scheduling_1.checkSwap; } });
59
66
  Object.defineProperty(exports, "diagnoseInfeasibility", { enumerable: true, get: function () { return scheduling_1.diagnoseInfeasibility; } });
60
67
  // Rule-authoring arithmetic (weekly-average → rolling-window-total, etc.)
61
68
  Object.defineProperty(exports, "hours", { enumerable: true, get: function () { return scheduling_1.hours; } });
@@ -26,10 +26,7 @@
26
26
  * Pure module: no Redis access, O(number of tags) per call.
27
27
  */
28
28
  import type { AutoRoutingWeightsOptions, AutoWeightExplanation, LearningTagStat } from '../types/matcher';
29
- type OptionalAutoWeightsKeys = 'priorWeight' | 'maxDeltaPerSync' | 'decayHalfLifeMs' | 'rng' | 'priorVariance' | 'vetoCooldownMs' | 'totalAttempts';
30
- export declare const DEFAULT_AUTO_WEIGHTS_OPTIONS: Required<Omit<AutoRoutingWeightsOptions, OptionalAutoWeightsKeys>> & {
31
- priorWeight: number;
32
- };
29
+ export declare const DEFAULT_AUTO_WEIGHTS_OPTIONS: Required<Pick<AutoRoutingWeightsOptions, 'minSamples' | 'vetoThreshold' | 'maxWeight' | 'explorationBonus' | 'priorWeight' | 'policy' | 'confidenceZ' | 'minTotalSamples' | 'minSamplesForVeto' | 'terminalOnlyTagStats' | 'rewardModel' | 'rewardRange' | 'priorStrength'>>;
33
30
  /**
34
31
  * Synthesize a routingWeights map from per-tag reward statistics.
35
32
  *
@@ -51,5 +48,4 @@ export declare function synthesizeRoutingWeights(stats: LearningTagStat[], optio
51
48
  * function with the explanations dropped.
52
49
  */
53
50
  export declare function explainRoutingWeights(stats: LearningTagStat[], options?: AutoRoutingWeightsOptions, knownTags?: string[], existingWeights?: Record<string, number>, now?: number): AutoWeightExplanation[];
54
- export {};
55
51
  //# sourceMappingURL=auto-weights.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"auto-weights.d.ts","sourceRoot":"","sources":["../../src/learning/auto-weights.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,KAAK,EACR,yBAAyB,EAEzB,qBAAqB,EACrB,eAAe,EAClB,MAAM,kBAAkB,CAAC;AAE1B,KAAK,uBAAuB,GACtB,aAAa,GACb,iBAAiB,GACjB,iBAAiB,GACjB,KAAK,GACL,eAAe,GACf,gBAAgB,GAChB,eAAe,CAAC;AAEtB,eAAO,MAAM,4BAA4B,EAAE,QAAQ,CAAC,IAAI,CAAC,yBAAyB,EAAE,uBAAuB,CAAC,CAAC,GAAG;IAC5G,WAAW,EAAE,MAAM,CAAC;CAevB,CAAC;AAsQF;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CACpC,KAAK,EAAE,eAAe,EAAE,EACxB,OAAO,CAAC,EAAE,yBAAyB,EACnC,SAAS,CAAC,EAAE,MAAM,EAAE,EACpB,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACzC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAMxB;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACjC,KAAK,EAAE,eAAe,EAAE,EACxB,OAAO,CAAC,EAAE,yBAAyB,EACnC,SAAS,CAAC,EAAE,MAAM,EAAE,EACpB,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACxC,GAAG,GAAE,MAAmB,GACzB,qBAAqB,EAAE,CA2FzB"}
1
+ {"version":3,"file":"auto-weights.d.ts","sourceRoot":"","sources":["../../src/learning/auto-weights.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,KAAK,EACR,yBAAyB,EAEzB,qBAAqB,EACrB,eAAe,EAClB,MAAM,kBAAkB,CAAC;AAW1B,eAAO,MAAM,4BAA4B,EAAE,QAAQ,CAC/C,IAAI,CACA,yBAAyB,EACvB,YAAY,GACZ,eAAe,GACf,WAAW,GACX,kBAAkB,GAClB,aAAa,GACb,QAAQ,GACR,aAAa,GACb,iBAAiB,GACjB,mBAAmB,GACnB,sBAAsB,GACtB,aAAa,GACb,aAAa,GACb,eAAe,CACpB,CAeJ,CAAC;AAkQF;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CACpC,KAAK,EAAE,eAAe,EAAE,EACxB,OAAO,CAAC,EAAE,yBAAyB,EACnC,SAAS,CAAC,EAAE,MAAM,EAAE,EACpB,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACzC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAMxB;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACjC,KAAK,EAAE,eAAe,EAAE,EACxB,OAAO,CAAC,EAAE,yBAAyB,EACnC,SAAS,CAAC,EAAE,MAAM,EAAE,EACpB,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACxC,GAAG,GAAE,MAAmB,GACzB,qBAAqB,EAAE,CA2FzB"}
@@ -46,9 +46,6 @@ function resolveOptions(options) {
46
46
  rng: options?.rng ?? Math.random,
47
47
  };
48
48
  }
49
- function isManualTag(tag, existingWeights) {
50
- return !!existingWeights && tag in existingWeights;
51
- }
52
49
  /**
53
50
  * Evidence backing a tag, in independent attempts.
54
51
  *
@@ -0,0 +1,84 @@
1
+ -- book-slot.lua
2
+ -- Atomically reserve one worker's time for one slotted assignment.
3
+ --
4
+ -- Checking for a clash and then writing the booking is not safe: two sweeps
5
+ -- booking two different tasks into one worker's 14:00 both pass the check and
6
+ -- both write. The whole decision therefore happens inside one script.
7
+ --
8
+ -- KEYS[1] = bookings hash (assignmentId -> JSON booking record)
9
+ -- KEYS[2] = booking spans hash (assignmentId -> "<startAt>:<endAt>")
10
+ -- KEYS[3] = this user's bookings (zset of assignmentId scored by startAt)
11
+ --
12
+ -- ARGV[1] = assignment id
13
+ -- ARGV[2] = startAt (epoch ms)
14
+ -- ARGV[3] = endAt (epoch ms, exclusive)
15
+ -- ARGV[4] = lookback ms -- how far back the overlap probe reaches. Bounds the
16
+ -- range read: any booking starting earlier than startAt - lookback
17
+ -- cannot still be running, given the longest slot the caller allows.
18
+ -- ARGV[5] = the booking record to store (JSON)
19
+ --
20
+ -- Returns:
21
+ -- {'booked'}
22
+ -- {'already-booked', holderUserId}
23
+ -- {'clash', clashingAssignmentId}
24
+
25
+ local bookings_key = KEYS[1]
26
+ local spans_key = KEYS[2]
27
+ local user_key = KEYS[3]
28
+
29
+ local assignment_id = ARGV[1]
30
+ local start_at = tonumber(ARGV[2])
31
+ local end_at = tonumber(ARGV[3])
32
+ local lookback = tonumber(ARGV[4])
33
+ local record = ARGV[5]
34
+
35
+ -- The bookings hash is the single index answering "who holds this", so its
36
+ -- presence is the claim gate: a second booker finds it taken.
37
+ local existing = redis.call('HGET', bookings_key, assignment_id)
38
+ if existing then
39
+ local ok, decoded = pcall(cjson.decode, existing)
40
+ local holder = ''
41
+ if ok and decoded and decoded.userId then
42
+ holder = decoded.userId
43
+ end
44
+ return {'already-booked', holder}
45
+ end
46
+
47
+ -- Every booking that could still be running when this one starts: it must
48
+ -- begin before this slot ends, and no earlier than the lookback bound. The
49
+ -- upper bound is exclusive, so a booking starting exactly at end_at -- the
50
+ -- back-to-back case -- is never even considered.
51
+ -- Bounds go to Redis as strings. Concatenating a Lua number would format it
52
+ -- with %.14g, and an epoch in milliseconds is 13 digits: correct today by one
53
+ -- digit of margin, which is not a margin. The exclusive upper bound is the
54
+ -- caller's own string; the lower bound is the one value that has to be
55
+ -- computed, so it is printed without an exponent.
56
+ local lower = start_at - lookback
57
+ if lower < 0 then
58
+ lower = 0
59
+ end
60
+ local candidates = redis.call('ZRANGEBYSCORE', user_key, string.format('%.0f', lower), '(' .. ARGV[3])
61
+
62
+ for i = 1, #candidates do
63
+ local candidate = candidates[i]
64
+ if candidate ~= assignment_id then
65
+ local span = redis.call('HGET', spans_key, candidate)
66
+ if span then
67
+ local sep = string.find(span, ':', 1, true)
68
+ if sep then
69
+ local candidate_end = tonumber(string.sub(span, sep + 1))
70
+ -- Half-open intervals: a job ending at 15:00 and one starting
71
+ -- at 15:00 are an ordinary working day, not a clash.
72
+ if candidate_end and candidate_end > start_at then
73
+ return {'clash', candidate}
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+ redis.call('HSET', bookings_key, assignment_id, record)
81
+ redis.call('HSET', spans_key, assignment_id, ARGV[2] .. ':' .. ARGV[3])
82
+ redis.call('ZADD', user_key, ARGV[2], assignment_id)
83
+
84
+ return {'booked'}
@@ -0,0 +1,47 @@
1
+ -- claim-queued.lua
2
+ -- Claim queued assignments for one worker, atomically with everything that
3
+ -- makes the claim true: the pending record, its response deadline, its owner
4
+ -- and (when learning is on) the decision context.
5
+ --
6
+ -- The HDEL on the queued hash is the claim gate — only one caller ever gets 1
7
+ -- back for an id. Done as its own round trip, the assignment was then in no
8
+ -- store at all until the pending write landed: a concurrent read (cancel, GET,
9
+ -- explain) answered "not found" for live work, and a crash in that gap lost the
10
+ -- assignment outright. Here the gate and the move are one step.
11
+ --
12
+ -- KEYS[1] = queued assignments hash
13
+ -- KEYS[2] = pending assignments hash
14
+ -- KEYS[3] = pending expiry zset (score = response deadline)
15
+ -- KEYS[4] = assignment owner hash (assignmentId -> userId)
16
+ -- KEYS[5] = learning stats hash
17
+ --
18
+ -- ARGV[1] = the worker's user id
19
+ -- ARGV[2] = decision TTL in ms
20
+ -- then seven fields per assignment:
21
+ -- id, pending JSON, deadline (epoch ms), decision key ('' = no decision),
22
+ -- decision JSON, decision pointer key, decision id
23
+ --
24
+ -- Returns one integer per assignment, in order: 1 won, 0 lost.
25
+
26
+ local won = {}
27
+ local decisions = 0
28
+ for i = 3, #ARGV, 7 do
29
+ local id = ARGV[i]
30
+ if redis.call('HDEL', KEYS[1], id) == 1 then
31
+ redis.call('HSET', KEYS[2], id, ARGV[i + 1])
32
+ redis.call('ZADD', KEYS[3], ARGV[i + 2], id)
33
+ redis.call('HSET', KEYS[4], id, ARGV[1])
34
+ if ARGV[i + 3] ~= '' then
35
+ redis.call('SET', ARGV[i + 3], ARGV[i + 4], 'PX', ARGV[2])
36
+ redis.call('SET', ARGV[i + 5], ARGV[i + 6], 'PX', ARGV[2])
37
+ decisions = decisions + 1
38
+ end
39
+ won[#won + 1] = 1
40
+ else
41
+ won[#won + 1] = 0
42
+ end
43
+ end
44
+ if decisions > 0 then
45
+ redis.call('HINCRBY', KEYS[5], 'decisions', decisions)
46
+ end
47
+ return won