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.
- package/README.md +312 -20
- package/dist/escalation/policy.d.ts +11 -0
- package/dist/escalation/policy.d.ts.map +1 -1
- package/dist/escalation/policy.js +22 -1
- package/dist/forecasting/backtest.d.ts +52 -0
- package/dist/forecasting/backtest.d.ts.map +1 -0
- package/dist/forecasting/backtest.js +195 -0
- package/dist/forecasting/calendar.d.ts +44 -0
- package/dist/forecasting/calendar.d.ts.map +1 -0
- package/dist/forecasting/calendar.js +85 -0
- package/dist/forecasting/cover.d.ts +69 -0
- package/dist/forecasting/cover.d.ts.map +1 -0
- package/dist/forecasting/cover.js +103 -0
- package/dist/forecasting/days.d.ts +17 -0
- package/dist/forecasting/days.d.ts.map +1 -0
- package/dist/forecasting/days.js +35 -0
- package/dist/forecasting/distributions.d.ts +31 -0
- package/dist/forecasting/distributions.d.ts.map +1 -0
- package/dist/forecasting/distributions.js +154 -0
- package/dist/forecasting/effects.d.ts +88 -0
- package/dist/forecasting/effects.d.ts.map +1 -0
- package/dist/forecasting/effects.js +303 -0
- package/dist/forecasting/erlang.d.ts +31 -0
- package/dist/forecasting/erlang.d.ts.map +1 -0
- package/dist/forecasting/erlang.js +86 -0
- package/dist/forecasting/forecast.d.ts +7 -0
- package/dist/forecasting/forecast.d.ts.map +1 -0
- package/dist/forecasting/forecast.js +221 -0
- package/dist/forecasting/index.d.ts +18 -0
- package/dist/forecasting/index.d.ts.map +1 -0
- package/dist/forecasting/index.js +54 -0
- package/dist/forecasting/model.d.ts +145 -0
- package/dist/forecasting/model.d.ts.map +1 -0
- package/dist/forecasting/model.js +583 -0
- package/dist/forecasting/nowcast.d.ts +26 -0
- package/dist/forecasting/nowcast.d.ts.map +1 -0
- package/dist/forecasting/nowcast.js +92 -0
- package/dist/forecasting/simulation.d.ts +91 -0
- package/dist/forecasting/simulation.d.ts.map +1 -0
- package/dist/forecasting/simulation.js +478 -0
- package/dist/forecasting/spikes.d.ts +6 -0
- package/dist/forecasting/spikes.d.ts.map +1 -0
- package/dist/forecasting/spikes.js +73 -0
- package/dist/forecasting/staffing.d.ts +64 -0
- package/dist/forecasting/staffing.d.ts.map +1 -0
- package/dist/forecasting/staffing.js +765 -0
- package/dist/forecasting/stats.d.ts +11 -0
- package/dist/forecasting/stats.d.ts.map +1 -0
- package/dist/forecasting/stats.js +45 -0
- package/dist/forecasting/types.d.ts +299 -0
- package/dist/forecasting/types.d.ts.map +1 -0
- package/dist/forecasting/types.js +8 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/learning/auto-weights.d.ts +1 -5
- package/dist/learning/auto-weights.d.ts.map +1 -1
- package/dist/learning/auto-weights.js +0 -3
- package/dist/lua/book-slot.lua +84 -0
- package/dist/lua/claim-queued.lua +47 -0
- package/dist/managers/DecisionTraceManager.d.ts +15 -0
- package/dist/managers/DecisionTraceManager.d.ts.map +1 -1
- package/dist/managers/DecisionTraceManager.js +117 -11
- package/dist/managers/LearningManager.d.ts +12 -0
- package/dist/managers/LearningManager.d.ts.map +1 -1
- package/dist/managers/LearningManager.js +21 -7
- package/dist/managers/ReliabilityManager.d.ts +1 -2
- package/dist/managers/ReliabilityManager.d.ts.map +1 -1
- package/dist/managers/ReliabilityManager.js +1 -1
- package/dist/managers/TelemetryManager.d.ts.map +1 -1
- package/dist/managers/TelemetryManager.js +9 -3
- package/dist/managers/WorkflowManager.d.ts.map +1 -1
- package/dist/managers/WorkflowManager.js +3 -4
- package/dist/matcher.class.d.ts +319 -4
- package/dist/matcher.class.d.ts.map +1 -1
- package/dist/matcher.class.js +1428 -102
- package/dist/queries/lane-stats.d.ts +51 -0
- package/dist/queries/lane-stats.d.ts.map +1 -0
- package/dist/queries/lane-stats.js +78 -0
- package/dist/schedule/recurrence.d.ts +11 -0
- package/dist/schedule/recurrence.d.ts.map +1 -1
- package/dist/schedule/recurrence.js +19 -2
- package/dist/schedule/slot.d.ts +60 -0
- package/dist/schedule/slot.d.ts.map +1 -0
- package/dist/schedule/slot.js +86 -0
- package/dist/scheduling/constraints/availability.d.ts +2 -14
- package/dist/scheduling/constraints/availability.d.ts.map +1 -1
- package/dist/scheduling/constraints/availability.js +14 -15
- package/dist/scheduling/constraints/consecutive.d.ts +10 -0
- package/dist/scheduling/constraints/consecutive.d.ts.map +1 -1
- package/dist/scheduling/constraints/consecutive.js +64 -1
- package/dist/scheduling/constraints/contract.d.ts.map +1 -1
- package/dist/scheduling/constraints/contract.js +12 -3
- package/dist/scheduling/constraints/employee-scope.d.ts.map +1 -1
- package/dist/scheduling/constraints/employee-scope.js +10 -2
- package/dist/scheduling/constraints/group-composition.js +2 -2
- package/dist/scheduling/constraints/min-staffing.d.ts.map +1 -1
- package/dist/scheduling/constraints/min-staffing.js +51 -8
- package/dist/scheduling/constraints/rolling-hours.d.ts.map +1 -1
- package/dist/scheduling/constraints/rolling-hours.js +29 -4
- package/dist/scheduling/constraints/support.d.ts +4 -8
- package/dist/scheduling/constraints/support.d.ts.map +1 -1
- package/dist/scheduling/constraints/support.js +23 -2
- package/dist/scheduling/constraints/weekly-rest.d.ts +28 -0
- package/dist/scheduling/constraints/weekly-rest.d.ts.map +1 -1
- package/dist/scheduling/constraints/weekly-rest.js +108 -21
- package/dist/scheduling/engine/construction.d.ts.map +1 -1
- package/dist/scheduling/engine/construction.js +56 -7
- package/dist/scheduling/engine/objective.d.ts +0 -1
- package/dist/scheduling/engine/objective.d.ts.map +1 -1
- package/dist/scheduling/engine/objective.js +65 -6
- package/dist/scheduling/engine/search.d.ts +4 -0
- package/dist/scheduling/engine/search.d.ts.map +1 -1
- package/dist/scheduling/engine/search.js +2 -1
- package/dist/scheduling/engine/state.d.ts +14 -0
- package/dist/scheduling/engine/state.d.ts.map +1 -1
- package/dist/scheduling/engine/state.js +7 -0
- package/dist/scheduling/engine/timeline.d.ts +23 -1
- package/dist/scheduling/engine/timeline.d.ts.map +1 -1
- package/dist/scheduling/engine/timeline.js +85 -27
- package/dist/scheduling/engine/verdicts.d.ts +40 -1
- package/dist/scheduling/engine/verdicts.d.ts.map +1 -1
- package/dist/scheduling/engine/verdicts.js +177 -17
- package/dist/scheduling/index.d.ts +3 -2
- package/dist/scheduling/index.d.ts.map +1 -1
- package/dist/scheduling/index.js +7 -1
- package/dist/scheduling/model.d.ts +8 -4
- package/dist/scheduling/model.d.ts.map +1 -1
- package/dist/scheduling/model.js +239 -23
- package/dist/scheduling/operations.d.ts +174 -2
- package/dist/scheduling/operations.d.ts.map +1 -1
- package/dist/scheduling/operations.js +558 -21
- package/dist/scheduling/preference-report.d.ts +15 -0
- package/dist/scheduling/preference-report.d.ts.map +1 -0
- package/dist/scheduling/preference-report.js +111 -0
- package/dist/scheduling/preferences.d.ts +30 -0
- package/dist/scheduling/preferences.d.ts.map +1 -0
- package/dist/scheduling/preferences.js +85 -0
- package/dist/scheduling/resilience.d.ts +46 -0
- package/dist/scheduling/resilience.d.ts.map +1 -0
- package/dist/scheduling/resilience.js +45 -0
- package/dist/scheduling/scheduler.class.d.ts +12 -1
- package/dist/scheduling/scheduler.class.d.ts.map +1 -1
- package/dist/scheduling/scheduler.class.js +28 -4
- package/dist/scheduling/sites.d.ts +1 -1
- package/dist/scheduling/sites.d.ts.map +1 -1
- package/dist/scheduling/sites.js +34 -1
- package/dist/scheduling/time.d.ts +28 -6
- package/dist/scheduling/time.d.ts.map +1 -1
- package/dist/scheduling/time.js +59 -17
- package/dist/scheduling/types.d.ts +247 -7
- package/dist/scheduling/types.d.ts.map +1 -1
- package/dist/scoring/fair-arbitration.d.ts.map +1 -1
- package/dist/scoring/fair-arbitration.js +2 -1
- package/dist/tracing/decision-trace.d.ts +5 -0
- package/dist/tracing/decision-trace.d.ts.map +1 -1
- package/dist/tracing/decision-trace.js +3 -0
- package/dist/types/matcher.d.ts +369 -2
- package/dist/types/matcher.d.ts.map +1 -1
- package/dist/updates/assignment-update.d.ts +93 -0
- package/dist/updates/assignment-update.d.ts.map +1 -0
- package/dist/updates/assignment-update.js +91 -0
- package/dist/utils/keys.d.ts +10 -0
- package/dist/utils/keys.d.ts.map +1 -1
- package/dist/utils/keys.js +43 -0
- package/package.json +25 -3
|
@@ -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;
|
package/dist/utils/keys.d.ts
CHANGED
|
@@ -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;
|
package/dist/utils/keys.d.ts.map
CHANGED
|
@@ -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;+
|
|
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"}
|
package/dist/utils/keys.js
CHANGED
|
@@ -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.
|
|
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,20 @@
|
|
|
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
|
-
"
|
|
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",
|
|
60
|
+
"lint": "eslint . --cache --cache-location node_modules/.cache/eslint/.eslintcache",
|
|
61
|
+
"lint:ci": "eslint . --quiet --cache --cache-location node_modules/.cache/eslint/.eslintcache",
|
|
62
|
+
"lint:fix": "eslint . --fix",
|
|
63
|
+
"check": "pnpm run lint:ci",
|
|
47
64
|
"prettier": "prettier --write .",
|
|
48
65
|
"build": "rimraf dist && tsc && mkdir -p dist/lua && cp src/lua/*.lua dist/lua/",
|
|
49
66
|
"prepublishOnly": "pnpm run build",
|
|
@@ -57,11 +74,15 @@
|
|
|
57
74
|
"tabWidth": 4
|
|
58
75
|
},
|
|
59
76
|
"devDependencies": {
|
|
77
|
+
"@eslint/js": "^9.39.5",
|
|
60
78
|
"@types/chai": "4.3.20",
|
|
61
79
|
"@types/mocha": "10.0.10",
|
|
62
80
|
"@types/node": "18.19.103",
|
|
63
81
|
"@types/sinon": "10.0.20",
|
|
64
82
|
"chai": "4.5.0",
|
|
83
|
+
"eslint": "^9.39.5",
|
|
84
|
+
"eslint-plugin-import-x": "^4.17.1",
|
|
85
|
+
"globals": "^17.12.0",
|
|
65
86
|
"mocha": "10.8.2",
|
|
66
87
|
"nyc": "15.1.0",
|
|
67
88
|
"prettier": "3.5.3",
|
|
@@ -70,7 +91,8 @@
|
|
|
70
91
|
"ts-node": "10.9.2",
|
|
71
92
|
"typedoc": "^0.25.0",
|
|
72
93
|
"typedoc-plugin-markdown": "3.17.1",
|
|
73
|
-
"typescript": "4.9.5"
|
|
94
|
+
"typescript": "4.9.5",
|
|
95
|
+
"typescript-eslint": "^8.69.0"
|
|
74
96
|
},
|
|
75
97
|
"packageManager": "pnpm@10.14.0+sha512.ad27a79641b49c3e481a16a805baa71817a04bbe06a38d17e60e2eaee83f6a146c6a688125f5792e48dd5ba30e7da52a5cda4c3992b9ccf333f9ce223af84748"
|
|
76
98
|
}
|