@chatwarden/core 0.1.7 → 0.1.8
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 +124 -4
- package/dist/src/ai/case.d.ts +3 -3
- package/dist/src/ai/case.d.ts.map +1 -1
- package/dist/src/ai/case.js +1 -1
- package/dist/src/ai/case.js.map +1 -1
- package/dist/src/ai/hash.d.ts +3 -1
- package/dist/src/ai/hash.d.ts.map +1 -1
- package/dist/src/ai/hash.js +5 -2
- package/dist/src/ai/hash.js.map +1 -1
- package/dist/src/ai/prompt.d.ts +6 -2
- package/dist/src/ai/prompt.d.ts.map +1 -1
- package/dist/src/ai/prompt.js +11 -0
- package/dist/src/ai/prompt.js.map +1 -1
- package/dist/src/ai/service.d.ts +5 -1
- package/dist/src/ai/service.d.ts.map +1 -1
- package/dist/src/ai/service.js +2 -0
- package/dist/src/ai/service.js.map +1 -1
- package/dist/src/ai/types.d.ts +18 -2
- package/dist/src/ai/types.d.ts.map +1 -1
- package/dist/src/ai/types.js +2 -2
- package/dist/src/ai/types.js.map +1 -1
- package/dist/src/ai/worker.d.ts +3 -1
- package/dist/src/ai/worker.d.ts.map +1 -1
- package/dist/src/ai/worker.js +10 -3
- package/dist/src/ai/worker.js.map +1 -1
- package/dist/src/chat.d.ts +39 -1
- package/dist/src/chat.d.ts.map +1 -1
- package/dist/src/chat.js +85 -6
- package/dist/src/chat.js.map +1 -1
- package/dist/src/chatwarden.d.ts +68 -1
- package/dist/src/chatwarden.d.ts.map +1 -1
- package/dist/src/chatwarden.js +119 -5
- package/dist/src/chatwarden.js.map +1 -1
- package/dist/src/documents.d.ts +1 -1
- package/dist/src/documents.d.ts.map +1 -1
- package/dist/src/documents.js +3 -1
- package/dist/src/documents.js.map +1 -1
- package/dist/src/freeze.d.ts +3 -0
- package/dist/src/freeze.d.ts.map +1 -0
- package/dist/src/freeze.js +10 -0
- package/dist/src/freeze.js.map +1 -0
- package/dist/src/index.d.ts +13 -6
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +7 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/ladder.d.ts +28 -0
- package/dist/src/ladder.d.ts.map +1 -1
- package/dist/src/ladder.js +37 -1
- package/dist/src/ladder.js.map +1 -1
- package/dist/src/pace.d.ts +66 -0
- package/dist/src/pace.d.ts.map +1 -0
- package/dist/src/pace.js +111 -0
- package/dist/src/pace.js.map +1 -0
- package/dist/src/pacing.d.ts +63 -0
- package/dist/src/pacing.d.ts.map +1 -0
- package/dist/src/pacing.js +198 -0
- package/dist/src/pacing.js.map +1 -0
- package/dist/src/policy.d.ts +57 -1
- package/dist/src/policy.d.ts.map +1 -1
- package/dist/src/policy.js +67 -4
- package/dist/src/policy.js.map +1 -1
- package/dist/src/profile.d.ts +35 -8
- package/dist/src/profile.d.ts.map +1 -1
- package/dist/src/profile.js +57 -25
- package/dist/src/profile.js.map +1 -1
- package/dist/src/profileError.d.ts +10 -0
- package/dist/src/profileError.d.ts.map +1 -0
- package/dist/src/profileError.js +17 -0
- package/dist/src/profileError.js.map +1 -0
- package/dist/src/retention.d.ts +9 -0
- package/dist/src/retention.d.ts.map +1 -1
- package/dist/src/retention.js +10 -1
- package/dist/src/retention.js.map +1 -1
- package/dist/src/signalCounts.d.ts +37 -0
- package/dist/src/signalCounts.d.ts.map +1 -0
- package/dist/src/signalCounts.js +117 -0
- package/dist/src/signalCounts.js.map +1 -0
- package/dist/src/signalInert.d.ts +10 -0
- package/dist/src/signalInert.d.ts.map +1 -0
- package/dist/src/signalInert.js +28 -0
- package/dist/src/signalInert.js.map +1 -0
- package/dist/src/signalService.d.ts +101 -0
- package/dist/src/signalService.d.ts.map +1 -0
- package/dist/src/signalService.js +383 -0
- package/dist/src/signalService.js.map +1 -0
- package/dist/src/signals.d.ts +186 -0
- package/dist/src/signals.d.ts.map +1 -0
- package/dist/src/signals.js +361 -0
- package/dist/src/signals.js.map +1 -0
- package/dist/src/subjects.d.ts +2 -0
- package/dist/src/subjects.d.ts.map +1 -1
- package/dist/src/subjects.js +4 -0
- package/dist/src/subjects.js.map +1 -1
- package/dist/src/team.d.ts +27 -0
- package/dist/src/team.d.ts.map +1 -1
- package/dist/src/team.js +92 -4
- package/dist/src/team.js.map +1 -1
- package/dist/src/types.d.ts +56 -1
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js.map +1 -1
- package/package.json +2 -2
- package/src/ai/case.ts +4 -4
- package/src/ai/hash.ts +5 -2
- package/src/ai/prompt.ts +16 -1
- package/src/ai/service.ts +8 -2
- package/src/ai/types.ts +19 -2
- package/src/ai/worker.ts +12 -4
- package/src/chat.ts +109 -8
- package/src/chatwarden.ts +184 -7
- package/src/documents.ts +5 -3
- package/src/freeze.ts +8 -0
- package/src/index.ts +41 -3
- package/src/ladder.ts +59 -1
- package/src/pace.ts +139 -0
- package/src/pacing.ts +242 -0
- package/src/policy.ts +107 -7
- package/src/profile.ts +83 -25
- package/src/profileError.ts +17 -0
- package/src/retention.ts +17 -1
- package/src/signalCounts.ts +133 -0
- package/src/signalInert.ts +31 -0
- package/src/signalService.ts +406 -0
- package/src/signals.ts +489 -0
- package/src/subjects.ts +5 -0
- package/src/team.ts +93 -5
- package/src/types.ts +65 -1
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
import { randomId, sha256Hex } from './crypto.js';
|
|
2
|
+
import { errorClass, safeWarn, ThrottledWarn } from './log.js';
|
|
3
|
+
import { countSignals, evaluateThreshold } from './signalCounts.js';
|
|
4
|
+
import { BUILTIN_SIGNAL_KINDS, SIGNAL_WINDOW_DAYS_MAX } from './signals.js';
|
|
5
|
+
// The signal service behind `cw.signals`: record (guarded), count, and the reads the feeds make. A signal never acts; this only keeps rows
|
|
6
|
+
// and counts them. Everything here is fenced: `record` returns false and the readers return empty, never throw. Logs carry event names and
|
|
7
|
+
// reason codes (and an error class), never a subject, a `by`, a room, a kind id or a label.
|
|
8
|
+
const DAY_MS = 86_400_000;
|
|
9
|
+
const MIN_MS = 60_000;
|
|
10
|
+
/** How far ahead of the clock a record may be dated. */
|
|
11
|
+
const AHEAD_MS = 5 * MIN_MS;
|
|
12
|
+
/** The window `counts` uses when it is not given one. */
|
|
13
|
+
const DEFAULT_WINDOW_DAYS = 30;
|
|
14
|
+
/** The most people one `boosted` call reads. */
|
|
15
|
+
const BOOSTED_MAX = 1000;
|
|
16
|
+
const ROOM_ID = /^[A-Za-z0-9_.:-]{1,64}$/;
|
|
17
|
+
const SUBJECT_ID_MAX = 128;
|
|
18
|
+
/** The longest connection detail (client key, account id, IP) a record may carry: longer is not a real one, and it would be hashed. */
|
|
19
|
+
const DETAIL_MAX = 512;
|
|
20
|
+
/** How long a player's account age is remembered, and for how many players. */
|
|
21
|
+
const AGE_MEMO_MS = MIN_MS;
|
|
22
|
+
const AGE_MEMO_MAX = 256;
|
|
23
|
+
/** Is this a room id a signal may carry (1 to 64 of A-Z a-z 0-9 _ . : -)? */
|
|
24
|
+
export const isSignalRoomId = (v) => typeof v === 'string' && v.length <= 64 && ROOM_ID.test(v);
|
|
25
|
+
/**
|
|
26
|
+
* The room id a flood row carries: the id itself when the signal rules accept it, else a stable `h` plus 16 hex digits of its SHA-256 (so a
|
|
27
|
+
* game whose room ids hold a space or run long still gets one source per room, and only the digest is stored). Undefined for no room.
|
|
28
|
+
*/
|
|
29
|
+
export const floodRoomId = (v) => (typeof v !== 'string' || v === '' ? undefined : isSignalRoomId(v) ? v : `h${sha256Hex(v).slice(0, 16)}`);
|
|
30
|
+
/** Thrown inside `record` to end it with a reason; never leaves the service. */
|
|
31
|
+
class Refusal extends Error {
|
|
32
|
+
reason;
|
|
33
|
+
detail;
|
|
34
|
+
constructor(reason, detail) {
|
|
35
|
+
super(reason);
|
|
36
|
+
this.reason = reason;
|
|
37
|
+
this.detail = detail;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** An own, defined field of a plain object, or undefined. */
|
|
41
|
+
function field(o, key) {
|
|
42
|
+
return Object.hasOwn(o, key) ? o[key] : undefined;
|
|
43
|
+
}
|
|
44
|
+
function isPlainObject(v) {
|
|
45
|
+
if (typeof v !== 'object' || v === null || Array.isArray(v))
|
|
46
|
+
return false;
|
|
47
|
+
const proto = Object.getPrototypeOf(v);
|
|
48
|
+
return proto === Object.prototype || proto === null;
|
|
49
|
+
}
|
|
50
|
+
export class SignalService {
|
|
51
|
+
deps;
|
|
52
|
+
/** One throttle per refusal reason, so a burst of `malformed` cannot hide a `store_failed` for a minute. */
|
|
53
|
+
refusedWarn = new Map();
|
|
54
|
+
readWarn;
|
|
55
|
+
ageWarn;
|
|
56
|
+
unsupportedLogged = false;
|
|
57
|
+
/** The account age the game's hook gave for a player, and when (see `accountFactor`). */
|
|
58
|
+
ageMemo = new Map();
|
|
59
|
+
constructor(deps) {
|
|
60
|
+
this.deps = deps;
|
|
61
|
+
this.readWarn = new ThrottledWarn(deps.logger, deps.clock);
|
|
62
|
+
this.ageWarn = new ThrottledWarn(deps.logger, deps.clock);
|
|
63
|
+
}
|
|
64
|
+
/** Does the store keep signals (the three methods)? */
|
|
65
|
+
get supported() {
|
|
66
|
+
const s = this.deps.store;
|
|
67
|
+
return typeof s.insertSignal === 'function' && typeof s.listSignalSources === 'function' && typeof s.purgeSignals === 'function';
|
|
68
|
+
}
|
|
69
|
+
/** The store cannot keep signals: said once per kit, as the AI does for its own optional methods. */
|
|
70
|
+
unsupported() {
|
|
71
|
+
if (this.unsupportedLogged)
|
|
72
|
+
return;
|
|
73
|
+
this.unsupportedLogged = true;
|
|
74
|
+
safeWarn(this.deps.logger, 'chatwarden.signals_store_unsupported');
|
|
75
|
+
}
|
|
76
|
+
// --- record ---------------------------------------------------------------------------------------------------
|
|
77
|
+
/** Record one signal. Synchronous, fenced, never throws: false for any refusal (logged by reason code, at most once a minute). */
|
|
78
|
+
record(input) {
|
|
79
|
+
return this.guarded(input, false);
|
|
80
|
+
}
|
|
81
|
+
/** `record`'s body. `quietCapped`: the cap refusing is the designed answer (a second flood trip the same day), so it is not logged. */
|
|
82
|
+
guarded(input, quietCapped) {
|
|
83
|
+
try {
|
|
84
|
+
if (!this.supported) {
|
|
85
|
+
this.unsupported();
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
return this.recordRow(input);
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
const reason = err instanceof Refusal ? err.reason : 'malformed';
|
|
92
|
+
if (quietCapped && reason === 'capped')
|
|
93
|
+
return false;
|
|
94
|
+
try {
|
|
95
|
+
let throttle = this.refusedWarn.get(reason);
|
|
96
|
+
if (throttle === undefined)
|
|
97
|
+
this.refusedWarn.set(reason, (throttle = new ThrottledWarn(this.deps.logger, this.deps.clock)));
|
|
98
|
+
throttle.warn('chatwarden.signal_refused', err instanceof Refusal && err.detail !== undefined ? { reason, error: err.detail } : { reason });
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
// The log must never change the answer.
|
|
102
|
+
}
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
flood(subject, roomId) {
|
|
107
|
+
const room = floodRoomId(roomId);
|
|
108
|
+
this.guarded({ kind: 'flood_triggered', subject, ...(room === undefined ? {} : { roomId: room }) }, true);
|
|
109
|
+
}
|
|
110
|
+
recordRow(input) {
|
|
111
|
+
if (!isPlainObject(input))
|
|
112
|
+
throw new Refusal('malformed');
|
|
113
|
+
const { kinds, guards } = this.deps.settings();
|
|
114
|
+
const kindId = field(input, 'kind');
|
|
115
|
+
if (typeof kindId !== 'string')
|
|
116
|
+
throw new Refusal('malformed');
|
|
117
|
+
if (!Object.hasOwn(kinds, kindId))
|
|
118
|
+
throw new Refusal('undeclared');
|
|
119
|
+
const spec = kinds[kindId];
|
|
120
|
+
// null is "left out" for the optional fields a game fills from a maybe-null variable: by, roomId and at.
|
|
121
|
+
const given = (key) => field(input, key) ?? undefined;
|
|
122
|
+
const roomId = given('roomId');
|
|
123
|
+
if (roomId !== undefined && !isSignalRoomId(roomId))
|
|
124
|
+
throw new Refusal('malformed');
|
|
125
|
+
const now = this.deps.clock.now();
|
|
126
|
+
const givenAt = given('at');
|
|
127
|
+
if (givenAt !== undefined && !(typeof givenAt === 'number' && Number.isFinite(givenAt)))
|
|
128
|
+
throw new Refusal('malformed');
|
|
129
|
+
const at = givenAt ?? now;
|
|
130
|
+
if (at > now + AHEAD_MS || at < now - this.deps.signalsMs())
|
|
131
|
+
throw new Refusal('time');
|
|
132
|
+
const givenWeight = field(input, 'weight');
|
|
133
|
+
if (givenWeight !== undefined && !(typeof givenWeight === 'number' && Number.isFinite(givenWeight) && givenWeight >= 0 && givenWeight <= 10)) {
|
|
134
|
+
throw new Refusal('malformed');
|
|
135
|
+
}
|
|
136
|
+
const subject = this.party(field(input, 'subject'));
|
|
137
|
+
const rawBy = given('by');
|
|
138
|
+
const by = rawBy === undefined ? null : this.party(rawBy);
|
|
139
|
+
if (by !== null && by === subject)
|
|
140
|
+
throw new Refusal('self');
|
|
141
|
+
const weight = (givenWeight ?? spec.weight) * this.accountFactor(by, guards.newAccount);
|
|
142
|
+
const sourceKey = by !== null ? `b:${by}` : roomId !== undefined ? `r:${roomId}` : `d:${new Date(at).toISOString().slice(0, 10)}`;
|
|
143
|
+
const wrote = this.insert({
|
|
144
|
+
id: randomId(16),
|
|
145
|
+
kind: kindId,
|
|
146
|
+
subject,
|
|
147
|
+
sourceKey,
|
|
148
|
+
bySubject: by,
|
|
149
|
+
roomId: roomId ?? null,
|
|
150
|
+
at,
|
|
151
|
+
weight,
|
|
152
|
+
capBucket: Math.floor(at / guards.perByWindowMs),
|
|
153
|
+
});
|
|
154
|
+
if (!wrote)
|
|
155
|
+
throw new Refusal('capped');
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
insert(row) {
|
|
159
|
+
try {
|
|
160
|
+
return this.deps.store.insertSignal?.(row) ?? false;
|
|
161
|
+
}
|
|
162
|
+
catch (err) {
|
|
163
|
+
throw new Refusal('store_failed', errorClass(err));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/** The canonical person a party names: a subject id the index knows, or a connection details object FOUND (never created). */
|
|
167
|
+
party(p) {
|
|
168
|
+
if (typeof p === 'string') {
|
|
169
|
+
if (p === '' || p.length > SUBJECT_ID_MAX || !this.deps.subjects.knows(p))
|
|
170
|
+
throw new Refusal('unknown_subject');
|
|
171
|
+
return this.deps.subjects.canonical(p);
|
|
172
|
+
}
|
|
173
|
+
if (!isPlainObject(p))
|
|
174
|
+
throw new Refusal('malformed');
|
|
175
|
+
const who = {};
|
|
176
|
+
for (const key of ['clientKey', 'accountId']) {
|
|
177
|
+
const v = field(p, key);
|
|
178
|
+
if (v === undefined)
|
|
179
|
+
continue;
|
|
180
|
+
if (typeof v !== 'string' || v.length > DETAIL_MAX)
|
|
181
|
+
throw new Refusal('malformed');
|
|
182
|
+
who[key] = v;
|
|
183
|
+
}
|
|
184
|
+
const ip = field(p, 'ip');
|
|
185
|
+
if (ip !== undefined && ip !== null) {
|
|
186
|
+
if (typeof ip !== 'string' || ip.length > DETAIL_MAX)
|
|
187
|
+
throw new Refusal('malformed');
|
|
188
|
+
who.ip = ip;
|
|
189
|
+
}
|
|
190
|
+
const found = this.deps.personOf(who);
|
|
191
|
+
if (found === null)
|
|
192
|
+
throw new Refusal('unknown_subject');
|
|
193
|
+
return this.deps.subjects.canonical(found);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* The new-account factor for `by`: the guard's factor only when the game supplied the hook, it returned an age for the player's
|
|
197
|
+
* account ids, and the age is below `belowDays`; else 1. A hook that throws is unknown (logged by class). Computed once, at record time.
|
|
198
|
+
*/
|
|
199
|
+
accountFactor(by, rule) {
|
|
200
|
+
const hook = this.deps.accountAgeDays;
|
|
201
|
+
if (rule === null || hook === undefined || by === null)
|
|
202
|
+
return 1;
|
|
203
|
+
const accounts = this.deps.subjects.identifiersOf(by).accounts;
|
|
204
|
+
if (accounts.length === 0)
|
|
205
|
+
return 1;
|
|
206
|
+
// The game's hook is often a lookup: a player recording over and over is asked once a minute, not on every record.
|
|
207
|
+
const now = this.deps.clock.now();
|
|
208
|
+
const known = this.ageMemo.get(by);
|
|
209
|
+
let age;
|
|
210
|
+
if (known !== undefined && now >= known.at && now - known.at < AGE_MEMO_MS)
|
|
211
|
+
age = known.age;
|
|
212
|
+
else {
|
|
213
|
+
try {
|
|
214
|
+
age = hook(accounts);
|
|
215
|
+
}
|
|
216
|
+
catch (err) {
|
|
217
|
+
this.ageWarn.warn('chatwarden.signal_age_failed', { error: errorClass(err) });
|
|
218
|
+
return 1;
|
|
219
|
+
}
|
|
220
|
+
this.ageMemo.delete(by);
|
|
221
|
+
this.ageMemo.set(by, { age, at: now });
|
|
222
|
+
if (this.ageMemo.size > AGE_MEMO_MAX)
|
|
223
|
+
this.ageMemo.delete(this.ageMemo.keys().next().value);
|
|
224
|
+
}
|
|
225
|
+
return typeof age === 'number' && Number.isFinite(age) && age >= 0 && age < rule.belowDays ? rule.factor : 1;
|
|
226
|
+
}
|
|
227
|
+
/** A read that failed (a store fault) answers empty; it is said once a minute, by the error's class only. Never throws. */
|
|
228
|
+
readFailed(err) {
|
|
229
|
+
try {
|
|
230
|
+
this.readWarn.warn('chatwarden.signal_read_failed', { error: errorClass(err) });
|
|
231
|
+
}
|
|
232
|
+
catch {
|
|
233
|
+
// The log must never change the answer.
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
// --- reads ----------------------------------------------------------------------------------------------------
|
|
237
|
+
/** The declared kinds, built-ins included. */
|
|
238
|
+
kinds() {
|
|
239
|
+
const { kinds } = this.deps.settings();
|
|
240
|
+
return Object.keys(kinds).map((kind) => {
|
|
241
|
+
const k = kinds[kind];
|
|
242
|
+
return { kind, label: k.label, polarity: k.polarity, weight: k.weight, builtin: Object.hasOwn(BUILTIN_SIGNAL_KINDS, kind) };
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
/** The counts for a person (aliases folded): one entry per requested kind with a counted source. Never throws; a store failure reads []. */
|
|
246
|
+
counts(subject, opts) {
|
|
247
|
+
try {
|
|
248
|
+
if (!this.supported)
|
|
249
|
+
return [];
|
|
250
|
+
const windowDays = this.windowOf(opts?.windowDays);
|
|
251
|
+
const asked = opts?.kinds;
|
|
252
|
+
const kinds = this.kindsFor(Array.isArray(asked) ? asked : undefined);
|
|
253
|
+
return this.countFor(subject, windowDays, kinds);
|
|
254
|
+
}
|
|
255
|
+
catch (err) {
|
|
256
|
+
this.readFailed(err);
|
|
257
|
+
return [];
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
windowOf(asked) {
|
|
261
|
+
const cap = Math.max(1, Math.min(SIGNAL_WINDOW_DAYS_MAX, Math.floor(this.deps.signalsMs() / DAY_MS)));
|
|
262
|
+
if (typeof asked !== 'number' || !Number.isFinite(asked) || asked < 1)
|
|
263
|
+
return Math.min(DEFAULT_WINDOW_DAYS, cap);
|
|
264
|
+
return Math.min(Math.floor(asked), cap);
|
|
265
|
+
}
|
|
266
|
+
/** The declared kinds (all, or those named, in declared order) as the counting context wants them. */
|
|
267
|
+
kindsFor(only) {
|
|
268
|
+
const { kinds } = this.deps.settings();
|
|
269
|
+
const out = {};
|
|
270
|
+
for (const id of Object.keys(kinds)) {
|
|
271
|
+
if (only !== undefined && !only.includes(id))
|
|
272
|
+
continue;
|
|
273
|
+
Object.defineProperty(out, id, { value: { label: kinds[id].label, polarity: kinds[id].polarity }, enumerable: true, configurable: true, writable: true });
|
|
274
|
+
}
|
|
275
|
+
return out;
|
|
276
|
+
}
|
|
277
|
+
countFor(subject, windowDays, kinds) {
|
|
278
|
+
if (typeof subject !== 'string' || subject === '')
|
|
279
|
+
return [];
|
|
280
|
+
const { subjects, store, clock } = this.deps;
|
|
281
|
+
const rows = store.listSignalSources?.(subjects.aliasesOf(subject), clock.now() - windowDays * DAY_MS) ?? [];
|
|
282
|
+
return countSignals(rows, { kinds, canonical: (s) => subjects.canonical(s), windowDays });
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Who of these people meets `feeds.queue`, as canonical ids: one grouped store read for all of them. Empty (and no store read) when the
|
|
286
|
+
* feed is off. Never throws.
|
|
287
|
+
*/
|
|
288
|
+
boosted(people) {
|
|
289
|
+
try {
|
|
290
|
+
const queue = this.deps.settings().feeds.queue;
|
|
291
|
+
if (queue === undefined || !this.supported || !Array.isArray(people))
|
|
292
|
+
return new Set();
|
|
293
|
+
const { subjects, store, clock } = this.deps;
|
|
294
|
+
const canon = [...new Set(people.filter((p) => typeof p === 'string' && p !== '').slice(0, BOOSTED_MAX).map((p) => subjects.canonical(p)))];
|
|
295
|
+
if (canon.length === 0)
|
|
296
|
+
return new Set();
|
|
297
|
+
const ofAlias = new Map();
|
|
298
|
+
for (const person of canon)
|
|
299
|
+
for (const alias of subjects.aliasesOf(person))
|
|
300
|
+
ofAlias.set(alias, person);
|
|
301
|
+
const rows = store.listSignalSources?.([...ofAlias.keys()], clock.now() - queue.windowDays * DAY_MS) ?? [];
|
|
302
|
+
const byPerson = new Map();
|
|
303
|
+
for (const row of rows) {
|
|
304
|
+
const person = ofAlias.get(row.subject);
|
|
305
|
+
if (person === undefined)
|
|
306
|
+
continue;
|
|
307
|
+
const list = byPerson.get(person);
|
|
308
|
+
if (list === undefined)
|
|
309
|
+
byPerson.set(person, [row]);
|
|
310
|
+
else
|
|
311
|
+
list.push(row);
|
|
312
|
+
}
|
|
313
|
+
const kinds = this.kindsFor(undefined);
|
|
314
|
+
const out = new Set();
|
|
315
|
+
for (const [person, list] of byPerson) {
|
|
316
|
+
if (evaluateThreshold(list, { kinds, canonical: (s) => subjects.canonical(s) }, queue).met)
|
|
317
|
+
out.add(person);
|
|
318
|
+
}
|
|
319
|
+
return out;
|
|
320
|
+
}
|
|
321
|
+
catch (err) {
|
|
322
|
+
this.readFailed(err);
|
|
323
|
+
return new Set();
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* The ladder rules (`feeds.ladder`) this person meets, for `suggest`: each as its id, effect and the sentence ("Muted by other players:
|
|
328
|
+
* 5 players in 14 days"). Rows are read once per distinct window. `[]` (and no store read) when the feed is off. Never throws.
|
|
329
|
+
*/
|
|
330
|
+
ladderHits(subject) {
|
|
331
|
+
try {
|
|
332
|
+
const { feeds, kinds } = this.deps.settings();
|
|
333
|
+
const rules = feeds.ladder;
|
|
334
|
+
if (rules === undefined || rules.length === 0 || !this.supported || typeof subject !== 'string' || subject === '')
|
|
335
|
+
return [];
|
|
336
|
+
const { subjects, store, clock } = this.deps;
|
|
337
|
+
const aliases = subjects.aliasesOf(subject);
|
|
338
|
+
const ctxKinds = this.kindsFor(undefined);
|
|
339
|
+
const byWindow = new Map();
|
|
340
|
+
const hits = [];
|
|
341
|
+
for (const rule of rules) {
|
|
342
|
+
let rows = byWindow.get(rule.windowDays);
|
|
343
|
+
if (rows === undefined) {
|
|
344
|
+
rows = store.listSignalSources?.(aliases, clock.now() - rule.windowDays * DAY_MS) ?? [];
|
|
345
|
+
byWindow.set(rule.windowDays, rows);
|
|
346
|
+
}
|
|
347
|
+
const res = evaluateThreshold(rows, { kinds: ctxKinds, canonical: (s) => subjects.canonical(s) }, rule);
|
|
348
|
+
if (!res.met)
|
|
349
|
+
continue;
|
|
350
|
+
const labels = rule.kinds.map((k) => kinds[k]?.label ?? k).join(', ');
|
|
351
|
+
const players = `${res.distinct} player${res.distinct === 1 ? '' : 's'}`;
|
|
352
|
+
const days = `${rule.windowDays} day${rule.windowDays === 1 ? '' : 's'}`;
|
|
353
|
+
hits.push({ id: rule.id, effect: rule.effect, text: `${labels}: ${players} in ${days}` });
|
|
354
|
+
}
|
|
355
|
+
return hits;
|
|
356
|
+
}
|
|
357
|
+
catch (err) {
|
|
358
|
+
this.readFailed(err);
|
|
359
|
+
return [];
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
/** The lines the Person page record shows: the `feeds.record` kinds and window. `[]` (and no store read) when the feed is off. Never throws. */
|
|
363
|
+
forRecord(subject) {
|
|
364
|
+
return this.forFeed(subject, this.deps.settings().feeds.record);
|
|
365
|
+
}
|
|
366
|
+
/** The counts the AI read may be shown: the `feeds.ai` kinds and window. `[]` (and no store read) when the feed is off. Never throws. */
|
|
367
|
+
forAi(subject) {
|
|
368
|
+
return this.forFeed(subject, this.deps.settings().feeds.ai);
|
|
369
|
+
}
|
|
370
|
+
forFeed(subject, feed) {
|
|
371
|
+
try {
|
|
372
|
+
if (feed === undefined || !this.supported)
|
|
373
|
+
return [];
|
|
374
|
+
const kinds = this.kindsFor(feed.kinds === '*' ? undefined : feed.kinds);
|
|
375
|
+
return this.countFor(subject, this.windowOf(feed.windowDays), kinds);
|
|
376
|
+
}
|
|
377
|
+
catch (err) {
|
|
378
|
+
this.readFailed(err);
|
|
379
|
+
return [];
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
//# sourceMappingURL=signalService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signalService.js","sourceRoot":"","sources":["../../src/signalService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE/D,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAK5E,2IAA2I;AAC3I,2IAA2I;AAC3I,4FAA4F;AAE5F,MAAM,MAAM,GAAG,UAAU,CAAC;AAC1B,MAAM,MAAM,GAAG,MAAM,CAAC;AACtB,wDAAwD;AACxD,MAAM,QAAQ,GAAG,CAAC,GAAG,MAAM,CAAC;AAC5B,yDAAyD;AACzD,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAC/B,gDAAgD;AAChD,MAAM,WAAW,GAAG,IAAI,CAAC;AACzB,MAAM,OAAO,GAAG,yBAAyB,CAAC;A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,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;YACrB,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import type { RawWho, SubjectId } from './types.js';
|
|
2
|
+
export type SignalPolarity = 'negative' | 'positive';
|
|
3
|
+
/**
|
|
4
|
+
* One kind a game declares. The key in `kinds` is the id the game passes to `record`.
|
|
5
|
+
* @experimental
|
|
6
|
+
*/
|
|
7
|
+
export interface SignalKindSpec {
|
|
8
|
+
/** What staff read: "Muted by other players". Plain text, 1 to 60 characters, no markup. Also the label the AI feed sends. */
|
|
9
|
+
label: string;
|
|
10
|
+
polarity: SignalPolarity;
|
|
11
|
+
/** Default weight of one source, 0 to 10, default 1. A record may override it per call. */
|
|
12
|
+
weight?: number;
|
|
13
|
+
}
|
|
14
|
+
/** @experimental */
|
|
15
|
+
export interface SignalGuards {
|
|
16
|
+
/**
|
|
17
|
+
* At most one row per (kind, subject, source) per this many ms. Default 86 400 000 (one day). 60 000 to 30 days. The cap is a calendar bucket
|
|
18
|
+
* (`floor(at / perByWindowMs)`), not a rolling window: two rows a millisecond apart across a bucket edge both insert, and changing this later
|
|
19
|
+
* re-buckets the rows already stored.
|
|
20
|
+
*/
|
|
21
|
+
perByWindowMs?: number;
|
|
22
|
+
/** Used ONLY when the adopter supplies `signals.accountAgeDays` to createChatwarden. Default: not set (no weighting). */
|
|
23
|
+
newAccount?: {
|
|
24
|
+
belowDays: number;
|
|
25
|
+
factor: number;
|
|
26
|
+
} | null;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* One threshold, over distinct sources, in a window.
|
|
30
|
+
* @experimental
|
|
31
|
+
*/
|
|
32
|
+
export interface SignalThreshold {
|
|
33
|
+
/** Declared kinds, 1 to 8. */
|
|
34
|
+
kinds: string[];
|
|
35
|
+
/** 1 to 50 distinct sources with weight above 0. */
|
|
36
|
+
minDistinct: number;
|
|
37
|
+
/** 1 to 90, and not above retention.signalsMs. */
|
|
38
|
+
windowDays: number;
|
|
39
|
+
/** The sum of those sources' weights must also reach this. */
|
|
40
|
+
minWeight?: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The feeds. Absent means that feed is off.
|
|
44
|
+
* @experimental
|
|
45
|
+
*/
|
|
46
|
+
export interface SignalFeeds {
|
|
47
|
+
/** Lines on the Person page record. `'*'` means every declared kind. */
|
|
48
|
+
record?: {
|
|
49
|
+
kinds: string[] | '*';
|
|
50
|
+
windowDays: number;
|
|
51
|
+
};
|
|
52
|
+
/** Queue ordering: a person who meets the threshold ranks ahead of older ordinary cases, capped. Negative kinds only. */
|
|
53
|
+
queue?: SignalThreshold;
|
|
54
|
+
/** The ladder. `note` adds a sentence to the suggestion; `raise` moves it up one step. `raise` takes negative kinds only. */
|
|
55
|
+
ladder?: Array<SignalThreshold & {
|
|
56
|
+
id: string;
|
|
57
|
+
effect: 'note' | 'raise';
|
|
58
|
+
}>;
|
|
59
|
+
/** The AI read's case context. */
|
|
60
|
+
ai?: {
|
|
61
|
+
kinds: string[] | '*';
|
|
62
|
+
windowDays: number;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/** @experimental */
|
|
66
|
+
export interface SignalSettings {
|
|
67
|
+
/** Code only. */
|
|
68
|
+
kinds?: Record<string, SignalKindSpec>;
|
|
69
|
+
/** Code only. */
|
|
70
|
+
guards?: SignalGuards;
|
|
71
|
+
/** Editable in the hub. */
|
|
72
|
+
feeds?: SignalFeeds;
|
|
73
|
+
}
|
|
74
|
+
/** The kind with every field filled in. */
|
|
75
|
+
export interface ResolvedSignalKind {
|
|
76
|
+
label: string;
|
|
77
|
+
polarity: SignalPolarity;
|
|
78
|
+
weight: number;
|
|
79
|
+
}
|
|
80
|
+
/** The guards with every field filled in; `newAccount` is null when not set. */
|
|
81
|
+
export interface ResolvedSignalGuards {
|
|
82
|
+
perByWindowMs: number;
|
|
83
|
+
newAccount: {
|
|
84
|
+
belowDays: number;
|
|
85
|
+
factor: number;
|
|
86
|
+
} | null;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* What the kit reads: the declared kinds merged over the built-ins, the guards filled in, the feeds as given. Look kinds up with
|
|
90
|
+
* {@link kindSpecOf}, never with `kinds[id]`.
|
|
91
|
+
* @experimental
|
|
92
|
+
*/
|
|
93
|
+
export interface ResolvedSignals {
|
|
94
|
+
kinds: Readonly<Record<string, ResolvedSignalKind>>;
|
|
95
|
+
guards: ResolvedSignalGuards;
|
|
96
|
+
feeds: SignalFeeds;
|
|
97
|
+
}
|
|
98
|
+
/** Who a signal is about or from: a staff-side subject id (`cw.rooms.subjectAt`), or the raw identity the game already passes to the doors. */
|
|
99
|
+
export type SignalParty = SubjectId | RawWho;
|
|
100
|
+
/** @experimental */
|
|
101
|
+
export interface SignalInput {
|
|
102
|
+
/** A declared kind (or a built-in). */
|
|
103
|
+
kind: string;
|
|
104
|
+
/** Whom it is about. */
|
|
105
|
+
subject: SignalParty;
|
|
106
|
+
/** Who produced it (the player who muted, the player who left). Omit (or `null`) for a source the game itself is, such as a timeout. */
|
|
107
|
+
by?: SignalParty | null;
|
|
108
|
+
/** The game's own room id: 1 to 64 characters of A-Z a-z 0-9 _ . : - . Not player text. `null` is the same as leaving it out. */
|
|
109
|
+
roomId?: string | null;
|
|
110
|
+
/** When it happened, epoch ms. Default: now (also for `null`). Not more than 5 minutes ahead, not older than retention.signalsMs. */
|
|
111
|
+
at?: number | null;
|
|
112
|
+
/** Overrides the kind's default weight for this one record. 0 to 10. */
|
|
113
|
+
weight?: number;
|
|
114
|
+
}
|
|
115
|
+
/** @experimental */
|
|
116
|
+
export interface SignalCount {
|
|
117
|
+
kind: string;
|
|
118
|
+
label: string;
|
|
119
|
+
polarity: SignalPolarity;
|
|
120
|
+
/** Distinct sources with weight above 0 in the window. */
|
|
121
|
+
distinct: number;
|
|
122
|
+
/** The sum of those sources' weights. */
|
|
123
|
+
weight: number;
|
|
124
|
+
windowDays: number;
|
|
125
|
+
firstAt: number;
|
|
126
|
+
lastAt: number;
|
|
127
|
+
}
|
|
128
|
+
/** @experimental */
|
|
129
|
+
export interface SignalKindView {
|
|
130
|
+
kind: string;
|
|
131
|
+
label: string;
|
|
132
|
+
polarity: SignalPolarity;
|
|
133
|
+
weight: number;
|
|
134
|
+
builtin: boolean;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Kinds the kit declares itself. An adopter may relabel or re-weight one by declaring the same key; the polarity must stay negative.
|
|
138
|
+
* @experimental
|
|
139
|
+
*/
|
|
140
|
+
export declare const BUILTIN_SIGNAL_KINDS: Readonly<Record<'flood_triggered', Readonly<SignalKindSpec>>>;
|
|
141
|
+
/** A kind id: a lower-case slug. */
|
|
142
|
+
export declare const SIGNAL_KIND_PATTERN: RegExp;
|
|
143
|
+
/** The most kinds a game may declare. */
|
|
144
|
+
export declare const SIGNAL_KINDS_MAX = 40;
|
|
145
|
+
/** The longest window a feed may name, in days. */
|
|
146
|
+
export declare const SIGNAL_WINDOW_DAYS_MAX = 90;
|
|
147
|
+
/** The feeds, in the order a settings screen lists them. */
|
|
148
|
+
export declare const SIGNAL_FEED_NAMES: readonly string[];
|
|
149
|
+
/**
|
|
150
|
+
* The declared spec of a kind, from the kinds `resolveSignals` returned, or undefined. Reads own properties only, so `constructor`,
|
|
151
|
+
* `toString` and `__proto__` are never found unless a game declared them.
|
|
152
|
+
*/
|
|
153
|
+
export declare function kindSpecOf(kinds: Readonly<Record<string, ResolvedSignalKind>>, id: string): ResolvedSignalKind | undefined;
|
|
154
|
+
/**
|
|
155
|
+
* Check the feeds against the declared `kinds` and `opts.signalsMs` (the retention of signal rows, ms), throwing {@link ProfileError}
|
|
156
|
+
* whose path starts with `path` (`path.queue.kinds[0]`). A feed names declared kinds only; `queue` and a `raise` rule name negative
|
|
157
|
+
* kinds only; a count and a window are in range; a window is not longer than `signalsMs` (rows older than that are gone) or 90 days.
|
|
158
|
+
* @experimental
|
|
159
|
+
*/
|
|
160
|
+
export declare function checkSignalFeeds(feeds: SignalFeeds | undefined, kinds: Readonly<Record<string, ResolvedSignalKind>>, opts: {
|
|
161
|
+
signalsMs: number;
|
|
162
|
+
}, path: string): void;
|
|
163
|
+
/** Why a stored feed was dropped: a code, never a value. */
|
|
164
|
+
export type SignalDropReason = 'unknown_feed' | 'unknown_kind' | 'positive_kind' | 'window' | 'invalid';
|
|
165
|
+
/**
|
|
166
|
+
* The feeds minus anything that can no longer be used: a feed (or a ladder rule) naming a kind the code stopped declaring, a positive
|
|
167
|
+
* kind where only negative ones are allowed, a window longer than `opts.signalsMs` or 90 days, or any other shape the checks refuse.
|
|
168
|
+
* Applied to a STORED layer at start-up, so one stale feed is dropped on its own and the rest of the layer (the ladder edits too) stays
|
|
169
|
+
* in force. Never throws: garbage in gives `{}`. `opts.onDrop` is told the name of each feed that lost something, once per feed, with
|
|
170
|
+
* the reason code of the first thing lost (a name that is not one of the four feeds is passed as it was stored, with `unknown_feed`: do
|
|
171
|
+
* not log it). The result passes {@link checkSignalFeeds}.
|
|
172
|
+
* @experimental
|
|
173
|
+
*/
|
|
174
|
+
export declare function pruneSignalFeeds(feeds: unknown, kinds: Readonly<Record<string, ResolvedSignalKind>>, opts: {
|
|
175
|
+
signalsMs: number;
|
|
176
|
+
onDrop?: (feed: string, reason: SignalDropReason) => void;
|
|
177
|
+
}): SignalFeeds;
|
|
178
|
+
/**
|
|
179
|
+
* Validate the `signals` section and fill it in: the declared kinds merged over the built-ins, the guards with their defaults, the
|
|
180
|
+
* feeds as given. Throws {@link ProfileError} naming the field (`signals.kinds.x.label`), never echoing the value. The feeds are
|
|
181
|
+
* checked against the declared kinds and the 90 day cap here; the cross-check with `retention.signalsMs` is {@link checkSignalFeeds}'s
|
|
182
|
+
* job, called where the retention is known. The result shares nothing with the input, and resolving it again gives the same value.
|
|
183
|
+
* @experimental
|
|
184
|
+
*/
|
|
185
|
+
export declare function resolveSignals(input: SignalSettings | undefined, path?: string): ResolvedSignals;
|
|
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