@seedcord/core 0.3.0 → 0.4.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/dist/{Bus-DcuUtOEL.mjs → Bus-BVwmKc-A.mjs} +51 -17
- package/dist/Bus-BVwmKc-A.mjs.map +1 -0
- package/dist/Pluggable-Cf5-WWmW.mjs +280 -0
- package/dist/Pluggable-Cf5-WWmW.mjs.map +1 -0
- package/dist/Pluggable-DFNUIlJM.d.mts +148 -0
- package/dist/{Plugin-Bkeqcjy6.mjs → Plugin-C6oMqWf8.mjs} +32 -7
- package/dist/Plugin-C6oMqWf8.mjs.map +1 -0
- package/dist/Plugin-CG9pWbPF.d.mts +193 -0
- package/dist/{cursor-DKKKUa_7.d.mts → cursor-BcRfmTSo.d.mts} +27 -140
- package/dist/{cursor-Cv1Ui6gZ.mjs → cursor-GBUYz3jk.mjs} +377 -176
- package/dist/cursor-GBUYz3jk.mjs.map +1 -0
- package/dist/{index-uBwh8r7x.d.mts → index-ZzdQafFv.d.mts} +2 -2
- package/dist/index.d.mts +132 -19
- package/dist/index.mjs +186 -19
- package/dist/index.mjs.map +1 -1
- package/dist/internal.index.d.mts +11 -4
- package/dist/internal.index.mjs +8 -455
- package/dist/internal.index.mjs.map +1 -1
- package/dist/node-internal.index.d.mts +10 -146
- package/dist/node-internal.index.mjs +43 -470
- package/dist/node-internal.index.mjs.map +1 -1
- package/dist/node.index.d.mts +2 -0
- package/dist/node.index.mjs +256 -0
- package/dist/node.index.mjs.map +1 -0
- package/dist/{Plugin-B6iRzm3g.d.mts → phases-F8yvPd60.d.mts} +111 -207
- package/dist/plugin.index.d.mts +2 -2
- package/dist/plugin.index.mjs +1 -1
- package/dist/publishDefault-D826XXDQ.mjs +14 -0
- package/dist/publishDefault-D826XXDQ.mjs.map +1 -0
- package/dist/{slashRouteLeaves-De1SxqnX.mjs → slashRouteLeaves-CbYRwqMY.mjs} +10 -2
- package/dist/slashRouteLeaves-CbYRwqMY.mjs.map +1 -0
- package/dist/subscribers-CGGQkUfM.mjs +139 -0
- package/dist/subscribers-CGGQkUfM.mjs.map +1 -0
- package/package.json +14 -8
- package/dist/Bus-DcuUtOEL.mjs.map +0 -1
- package/dist/Plugin-Bkeqcjy6.mjs.map +0 -1
- package/dist/cursor-Cv1Ui6gZ.mjs.map +0 -1
- package/dist/slashRouteLeaves-De1SxqnX.mjs.map +0 -1
- package/dist/subscribers-DuHg-bGT.mjs +0 -3
package/dist/internal.index.mjs
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { C as
|
|
2
|
-
import { A as
|
|
1
|
+
import { A as clearStore, C as InteractionMetadataKey, D as SubscribeMetadataKey, E as MiddlewareMetadataKey, M as contextMenuLeaves, O as WebhookUrlMetadataKey, S as GatedMetadataKey, T as InteractionRoutes, a as RegisterSubscriber, b as CommandMetadataKey, c as VerifyWebhooks, h as sendFlags, i as RegisterDefaults, j as guardedAccessor, k as accessorStore, m as deferFlags, n as busLoggerOf, o as RegisteredCount, p as ReportThrottle, s as UnregisterSubscriber, w as InteractionRouteKeys, x as EventMetadataKey, y as setBotColor } from "./Bus-BVwmKc-A.mjs";
|
|
2
|
+
import { A as translateSerializationError, B as interactionRoutesOf, C as NotInDm, E as OnCooldown, F as checkAckLegality, G as decodeComponentRoute, H as storeComponentRoute, I as sendTarget, J as prefixOf, N as reportedWrite, P as AckTrace, R as areRoutes, S as NotAllowed, T as NotOwner, U as storeInteractionRoute, V as selectMenuRouteOf, W as ComponentDefsKey, X as Notice, Y as NoticeCard, _ as GateNotice, b as MissingRole, d as pickNotice, f as discardCommits, g as runCommits, h as runCheck, k as serializeReply, n as pageCursor, q as decodeFor, r as Silence, s as PermissionNames, t as PAGE_MAX, v as HasDangerousPermissions, w as NotInGuild, x as NeedsAny, y as MissingPermissions, z as contextMenuRouteOf } from "./cursor-GBUYz3jk.mjs";
|
|
3
|
+
import { n as asError, t as PublishDefault } from "./publishDefault-D826XXDQ.mjs";
|
|
3
4
|
import { n as setDevChannel, t as getDevChannel } from "./devChannel-CQU7hq7Q.mjs";
|
|
4
|
-
import { t as slashRouteLeaves } from "./slashRouteLeaves-
|
|
5
|
+
import { n as isCommandClass, t as slashRouteLeaves } from "./slashRouteLeaves-CbYRwqMY.mjs";
|
|
5
6
|
import "reflect-metadata";
|
|
6
|
-
import {
|
|
7
|
-
import { SeedcordErrorCode, paint } from "@seedcord/errors";
|
|
7
|
+
import { paint } from "@seedcord/errors";
|
|
8
8
|
import { Logger } from "@seedcord/logger";
|
|
9
|
-
import { SeedcordError } from "@seedcord/errors/internal";
|
|
10
9
|
import { timestampFromSnowflake } from "@seedcord/utils";
|
|
11
10
|
import { Envapter } from "envapt";
|
|
12
11
|
|
|
@@ -56,7 +55,7 @@ async function runHandlerGates(handlerCtor, ctx, routeId, observe) {
|
|
|
56
55
|
//#region src/gates/slowGate.ts
|
|
57
56
|
const SLOW_GATE_MS = 750;
|
|
58
57
|
let gateLogger;
|
|
59
|
-
function logger$
|
|
58
|
+
function logger$1() {
|
|
60
59
|
gateLogger ??= new Logger("Gates", { channel: "gates" });
|
|
61
60
|
return gateLogger;
|
|
62
61
|
}
|
|
@@ -73,7 +72,7 @@ function slowGateMonitor() {
|
|
|
73
72
|
if (total < SLOW_GATE_MS) return;
|
|
74
73
|
const shares = readings.toSorted((a, b) => b.ms - a.ms).map((reading) => `${paint.sky.bold(reading.name)} ${paint.mute(`${Math.round(reading.ms)}ms`)}`);
|
|
75
74
|
const headline = `gates${routeId === null ? "" : ` for ${paint.sky.bold(routeId)}`} took ${paint.amber(`${Math.round(total)}ms`)} of the 3s ack budget`;
|
|
76
|
-
logger$
|
|
75
|
+
logger$1().utils.block(headline, shares, "warn", (text) => text);
|
|
77
76
|
}
|
|
78
77
|
};
|
|
79
78
|
}
|
|
@@ -125,452 +124,6 @@ var HmrManager = class {
|
|
|
125
124
|
}
|
|
126
125
|
};
|
|
127
126
|
|
|
128
|
-
//#endregion
|
|
129
|
-
//#region src/stops/asError.ts
|
|
130
|
-
/** @internal */
|
|
131
|
-
function asError(caught) {
|
|
132
|
-
return Error.isError(caught) ? caught : new Error(String(caught), { cause: caught });
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
//#endregion
|
|
136
|
-
//#region src/reply/ackLegality.ts
|
|
137
|
-
const showModalReason = {
|
|
138
|
-
reason: "this interaction was already acknowledged",
|
|
139
|
-
alternative: "showModal() must be the initial response."
|
|
140
|
-
};
|
|
141
|
-
function deferReason(what) {
|
|
142
|
-
return {
|
|
143
|
-
reason: `this interaction was already acknowledged with ${what}`,
|
|
144
|
-
alternative: "A deferral can only be the initial response."
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
const ILLEGAL = {
|
|
148
|
-
reply: {
|
|
149
|
-
"deferred-reply": {
|
|
150
|
-
reason: "this interaction was already deferred",
|
|
151
|
-
alternative: "Use edit() to fill the deferred reply or followUp() for a new message."
|
|
152
|
-
},
|
|
153
|
-
"deferred-update": {
|
|
154
|
-
reason: "this interaction was already acknowledged with a deferred update",
|
|
155
|
-
alternative: "Use followUp() for a new message."
|
|
156
|
-
},
|
|
157
|
-
replied: {
|
|
158
|
-
reason: "this interaction was already replied to",
|
|
159
|
-
alternative: "Use followUp() for a new message or edit() to rewrite the reply."
|
|
160
|
-
}
|
|
161
|
-
},
|
|
162
|
-
defer: {
|
|
163
|
-
"deferred-reply": deferReason("a deferred reply"),
|
|
164
|
-
"deferred-update": deferReason("a deferred update"),
|
|
165
|
-
replied: deferReason("a reply")
|
|
166
|
-
},
|
|
167
|
-
deferUpdate: {
|
|
168
|
-
"deferred-reply": deferReason("a deferred reply"),
|
|
169
|
-
"deferred-update": deferReason("a deferred update"),
|
|
170
|
-
replied: deferReason("a reply")
|
|
171
|
-
},
|
|
172
|
-
update: {
|
|
173
|
-
"deferred-reply": {
|
|
174
|
-
reason: "this interaction was deferred as a reply",
|
|
175
|
-
alternative: "The placeholder is yours via edit(). update() rewrites a source message."
|
|
176
|
-
},
|
|
177
|
-
replied: {
|
|
178
|
-
reason: "this interaction was already replied to",
|
|
179
|
-
alternative: "update() rewrites a source message. Use edit() or followUp() instead."
|
|
180
|
-
}
|
|
181
|
-
},
|
|
182
|
-
followUp: { unacked: {
|
|
183
|
-
reason: "this interaction has not been acknowledged yet",
|
|
184
|
-
alternative: "Ack first with reply() or defer()."
|
|
185
|
-
} },
|
|
186
|
-
edit: { unacked: {
|
|
187
|
-
reason: "nothing has been sent yet",
|
|
188
|
-
alternative: "Send with reply() or defer() first, then edit() rewrites it."
|
|
189
|
-
} },
|
|
190
|
-
delete: { unacked: {
|
|
191
|
-
reason: "nothing has been sent yet",
|
|
192
|
-
alternative: "Acknowledge first with reply() or defer(), then delete() removes it."
|
|
193
|
-
} },
|
|
194
|
-
showModal: {
|
|
195
|
-
"deferred-reply": showModalReason,
|
|
196
|
-
"deferred-update": showModalReason,
|
|
197
|
-
replied: showModalReason
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
const SEND_TARGET = {
|
|
201
|
-
unacked: "reply",
|
|
202
|
-
"deferred-reply": "edit",
|
|
203
|
-
"deferred-update": "followUp",
|
|
204
|
-
replied: "followUp"
|
|
205
|
-
};
|
|
206
|
-
function checkAckLegality(method, state, routeId, ackedBy) {
|
|
207
|
-
if (method === "send") return;
|
|
208
|
-
const illegal = ILLEGAL[method][state];
|
|
209
|
-
if (!illegal) return;
|
|
210
|
-
throw new SeedcordError(SeedcordErrorCode.ReplyIllegalAckState, [
|
|
211
|
-
method,
|
|
212
|
-
illegal.reason,
|
|
213
|
-
illegal.alternative,
|
|
214
|
-
routeId
|
|
215
|
-
], { cause: ackedBy });
|
|
216
|
-
}
|
|
217
|
-
function sendTarget(state) {
|
|
218
|
-
return SEND_TARGET[state];
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
//#endregion
|
|
222
|
-
//#region src/reply/AckTrace.ts
|
|
223
|
-
var AckTrace = class extends Error {
|
|
224
|
-
constructor(method) {
|
|
225
|
-
super(`${method}() acknowledged this interaction`);
|
|
226
|
-
this.name = "AckTrace";
|
|
227
|
-
}
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
//#endregion
|
|
231
|
-
//#region src/reply/responseReport.ts
|
|
232
|
-
let replyLogger;
|
|
233
|
-
function logger$1() {
|
|
234
|
-
replyLogger ??= new Logger("Reply", { channel: "interactions" });
|
|
235
|
-
return replyLogger;
|
|
236
|
-
}
|
|
237
|
-
/** @internal */
|
|
238
|
-
function publishResponse(telemetry, report) {
|
|
239
|
-
const durationMs = performance.now() - report.startedAt;
|
|
240
|
-
telemetry.bus[PublishDefault]("responseAttempted", {
|
|
241
|
-
routeId: report.routeId,
|
|
242
|
-
interactionId: telemetry.interactionId,
|
|
243
|
-
method: report.method,
|
|
244
|
-
outcome: report.outcome,
|
|
245
|
-
durationMs,
|
|
246
|
-
messageId: report.messageId,
|
|
247
|
-
...report.error && { error: report.error }
|
|
248
|
-
});
|
|
249
|
-
logger$1().trace(`${paint.sky.bold(report.routeId)} ${report.method} ${report.outcome} ${paint.mute("in")} ${Math.round(durationMs)}ms`);
|
|
250
|
-
}
|
|
251
|
-
async function reportedWrite(telemetry, routeId, method, write) {
|
|
252
|
-
const startedAt = performance.now();
|
|
253
|
-
const result = await attemptWrite(telemetry, routeId, method, startedAt, write);
|
|
254
|
-
publishResponse(telemetry, {
|
|
255
|
-
routeId,
|
|
256
|
-
method,
|
|
257
|
-
startedAt,
|
|
258
|
-
outcome: "sent",
|
|
259
|
-
messageId: null
|
|
260
|
-
});
|
|
261
|
-
return result;
|
|
262
|
-
}
|
|
263
|
-
async function attemptWrite(telemetry, routeId, method, startedAt, write) {
|
|
264
|
-
try {
|
|
265
|
-
return await write();
|
|
266
|
-
} catch (caught) {
|
|
267
|
-
publishResponse(telemetry, {
|
|
268
|
-
routeId,
|
|
269
|
-
method,
|
|
270
|
-
startedAt,
|
|
271
|
-
outcome: "failed",
|
|
272
|
-
messageId: null,
|
|
273
|
-
error: asError(caught)
|
|
274
|
-
});
|
|
275
|
-
throw caught;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
//#endregion
|
|
280
|
-
//#region src/reply/translateSerialization.ts
|
|
281
|
-
const MAX_DEPTH = 8;
|
|
282
|
-
const OPERATOR_WORD = {
|
|
283
|
-
"<=": "at most",
|
|
284
|
-
">=": "at least",
|
|
285
|
-
"<": "fewer than",
|
|
286
|
-
">": "more than"
|
|
287
|
-
};
|
|
288
|
-
const KIND_WORD = {
|
|
289
|
-
string: "a string",
|
|
290
|
-
number: "a number",
|
|
291
|
-
boolean: "a boolean",
|
|
292
|
-
bigint: "a bigint",
|
|
293
|
-
array: "a list",
|
|
294
|
-
tuple: "a list",
|
|
295
|
-
date: "a date",
|
|
296
|
-
object: "an object"
|
|
297
|
-
};
|
|
298
|
-
function asRecord(value) {
|
|
299
|
-
return typeof value === "object" && value !== null ? value : null;
|
|
300
|
-
}
|
|
301
|
-
function firstLine(message) {
|
|
302
|
-
if (typeof message !== "string") return "unknown validation failure";
|
|
303
|
-
return message.split("\n")[0] ?? message;
|
|
304
|
-
}
|
|
305
|
-
const GIVEN_PREVIEW_LIMIT = 40;
|
|
306
|
-
function gotPhrase(given) {
|
|
307
|
-
if (given === void 0) return "nothing";
|
|
308
|
-
if (given === null) return "null";
|
|
309
|
-
if (typeof given === "string") {
|
|
310
|
-
if (given.length === 0) return "an empty string";
|
|
311
|
-
if (given.length > GIVEN_PREVIEW_LIMIT) return `${given.length} characters`;
|
|
312
|
-
return JSON.stringify(given);
|
|
313
|
-
}
|
|
314
|
-
if (Array.isArray(given)) return given.length === 0 ? "an empty list" : `${given.length} items`;
|
|
315
|
-
if (typeof given === "number" || typeof given === "bigint" || typeof given === "boolean") return String(given);
|
|
316
|
-
if (typeof given === "object") return given.constructor?.name ?? "an object";
|
|
317
|
-
return typeof given;
|
|
318
|
-
}
|
|
319
|
-
function needPhrase(expected, given) {
|
|
320
|
-
const bounds = [...expected.matchAll(/expected(\.length)?\s*(<=|>=|<|>)\s*(\d+)/g)];
|
|
321
|
-
if (bounds.length === 0) return null;
|
|
322
|
-
return bounds.map(([, lengthPart, operator, limit]) => {
|
|
323
|
-
const word = OPERATOR_WORD[operator ?? ""] ?? operator ?? "";
|
|
324
|
-
if (!lengthPart) return `${word} ${limit}`;
|
|
325
|
-
const unit = typeof given === "string" ? "character" : "item";
|
|
326
|
-
return `${word} ${limit} ${Number(limit) === 1 ? unit : `${unit}s`}`;
|
|
327
|
-
}).join(" and ");
|
|
328
|
-
}
|
|
329
|
-
function instanceName(expected) {
|
|
330
|
-
if (typeof expected === "function" && expected.name) return expected.name;
|
|
331
|
-
return "specific class instance";
|
|
332
|
-
}
|
|
333
|
-
function describeLeaf(record) {
|
|
334
|
-
if (typeof record.constraint === "string") {
|
|
335
|
-
const need = typeof record.expected === "string" ? needPhrase(record.expected, record.given) : null;
|
|
336
|
-
if (need) return `need ${need}, got ${gotPhrase(record.given)}`;
|
|
337
|
-
return `${firstLine(record.message)}${"given" in record ? ` (got ${gotPhrase(record.given)})` : ""}`;
|
|
338
|
-
}
|
|
339
|
-
if (typeof record.expected === "function") return `need a ${instanceName(record.expected)}, got ${gotPhrase(record.given)}`;
|
|
340
|
-
if (typeof record.validator === "string") {
|
|
341
|
-
const kind = KIND_WORD[record.validator.replace(/^s\./, "").replace(/\(.*$/, "")];
|
|
342
|
-
if (kind) return `need ${kind}, got ${gotPhrase(record.given)}`;
|
|
343
|
-
return `${firstLine(record.message)}, got ${gotPhrase(record.given)}`;
|
|
344
|
-
}
|
|
345
|
-
return firstLine(record.message);
|
|
346
|
-
}
|
|
347
|
-
function describeUnion(branches, depth) {
|
|
348
|
-
const records = [];
|
|
349
|
-
for (const branch of branches) {
|
|
350
|
-
const record = asRecord(branch);
|
|
351
|
-
if (record) records.push(record);
|
|
352
|
-
}
|
|
353
|
-
const bounded = records.find((record) => typeof record.constraint === "string");
|
|
354
|
-
if (bounded) return describeLeaf(bounded);
|
|
355
|
-
const names = [];
|
|
356
|
-
let allInstances = records.length > 0;
|
|
357
|
-
for (const record of records) if (typeof record.expected === "function") names.push(instanceName(record.expected));
|
|
358
|
-
else allInstances = false;
|
|
359
|
-
if (allInstances) return `need a ${[...new Set(names)].join(" or ")}, got ${gotPhrase(records[0]?.given)}`;
|
|
360
|
-
return detailOf(branches[0], depth + 1);
|
|
361
|
-
}
|
|
362
|
-
function detailOf(value, depth) {
|
|
363
|
-
const record = asRecord(value);
|
|
364
|
-
if (!record || depth >= MAX_DEPTH) return firstLine(record?.message);
|
|
365
|
-
if (Array.isArray(record.errors) && record.errors.length > 0) {
|
|
366
|
-
const errors = record.errors;
|
|
367
|
-
const [first] = errors;
|
|
368
|
-
if (Array.isArray(first)) {
|
|
369
|
-
const [key, inner] = first;
|
|
370
|
-
return `${String(key)}: ${detailOf(inner, depth + 1)}`;
|
|
371
|
-
}
|
|
372
|
-
return describeUnion(errors, depth);
|
|
373
|
-
}
|
|
374
|
-
return describeLeaf(record);
|
|
375
|
-
}
|
|
376
|
-
function translateSerializationError(error, componentClass, index, routeId) {
|
|
377
|
-
const detail = detailOf(error, 0);
|
|
378
|
-
return new SeedcordError(SeedcordErrorCode.ReplyComponentSerialization, [
|
|
379
|
-
componentClass,
|
|
380
|
-
index,
|
|
381
|
-
detail,
|
|
382
|
-
routeId
|
|
383
|
-
], { cause: error });
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
//#endregion
|
|
387
|
-
//#region src/reply/serializeReply.ts
|
|
388
|
-
function serializeReply(response, routeId) {
|
|
389
|
-
if (typeof response === "string") try {
|
|
390
|
-
return { components: [new TextDisplayBuilder().setContent(response).toJSON()] };
|
|
391
|
-
} catch (error) {
|
|
392
|
-
throw translateSerializationError(error, "TextDisplayBuilder", 0, routeId);
|
|
393
|
-
}
|
|
394
|
-
return {
|
|
395
|
-
components: response.components.map((component, index) => {
|
|
396
|
-
try {
|
|
397
|
-
return component.toJSON();
|
|
398
|
-
} catch (error) {
|
|
399
|
-
const name = component.constructor?.name;
|
|
400
|
-
throw translateSerializationError(error, !name || name === "Object" ? "component" : name, index, routeId);
|
|
401
|
-
}
|
|
402
|
-
}),
|
|
403
|
-
...response.allowedMentions && { allowedMentions: response.allowedMentions },
|
|
404
|
-
...response.files && { files: response.files }
|
|
405
|
-
};
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
//#endregion
|
|
409
|
-
//#region src/reply/BaseReplySender.ts
|
|
410
|
-
/**
|
|
411
|
-
* Tracks acknowledgement state and throws a translated `SeedcordError` on an illegal verb before any
|
|
412
|
-
* transport call. Every verb runs the legality check, calls the transport's wire writer, then updates
|
|
413
|
-
* the state and the ack trace. Each transport binds `TMessage` to its own created-message type and
|
|
414
|
-
* supplies the writers.
|
|
415
|
-
*/
|
|
416
|
-
var BaseReplySender = class {
|
|
417
|
-
routeId;
|
|
418
|
-
telemetry;
|
|
419
|
-
state;
|
|
420
|
-
sent = /* @__PURE__ */ new Set();
|
|
421
|
-
ackedBy;
|
|
422
|
-
constructor(routeId, telemetry, initialState = "unacked") {
|
|
423
|
-
this.routeId = routeId;
|
|
424
|
-
this.telemetry = telemetry;
|
|
425
|
-
this.state = initialState;
|
|
426
|
-
}
|
|
427
|
-
report(method, startedAt, outcome, messageId) {
|
|
428
|
-
publishResponse(this.telemetry, {
|
|
429
|
-
routeId: this.routeId,
|
|
430
|
-
method,
|
|
431
|
-
startedAt,
|
|
432
|
-
outcome,
|
|
433
|
-
messageId
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
|
-
async attempt(method, startedAt, write) {
|
|
437
|
-
return await attemptWrite(this.telemetry, this.routeId, method, startedAt, write);
|
|
438
|
-
}
|
|
439
|
-
async reply(response, opts) {
|
|
440
|
-
this.checkLegality("reply");
|
|
441
|
-
const startedAt = performance.now();
|
|
442
|
-
const created = await this.attempt("reply", startedAt, () => this.writeReply(response, opts));
|
|
443
|
-
this.transition("reply", "replied");
|
|
444
|
-
const message = this.remember(this.requireMessage(created, "reply"));
|
|
445
|
-
this.report("reply", startedAt, "sent", message.id);
|
|
446
|
-
return message;
|
|
447
|
-
}
|
|
448
|
-
async defer(opts) {
|
|
449
|
-
this.checkLegality("defer");
|
|
450
|
-
const startedAt = performance.now();
|
|
451
|
-
await this.attempt("defer", startedAt, () => this.writeDefer(opts));
|
|
452
|
-
this.transition("defer", "deferred-reply");
|
|
453
|
-
this.report("defer", startedAt, "sent", null);
|
|
454
|
-
}
|
|
455
|
-
async deferUpdate() {
|
|
456
|
-
this.checkLegality("deferUpdate");
|
|
457
|
-
const startedAt = performance.now();
|
|
458
|
-
await this.attempt("deferUpdate", startedAt, () => this.writeDeferUpdate());
|
|
459
|
-
this.transition("deferUpdate", "deferred-update");
|
|
460
|
-
this.report("deferUpdate", startedAt, "sent", null);
|
|
461
|
-
}
|
|
462
|
-
/**
|
|
463
|
-
* After a deferUpdate the state stays deferred-update. Calling this again rewrites. The returned message
|
|
464
|
-
* is the source message, editable only through a bare `update` or `edit`. A targeted `edit` or `delete`
|
|
465
|
-
* of it throws the foreign-target error.
|
|
466
|
-
*/
|
|
467
|
-
async update(response) {
|
|
468
|
-
this.checkLegality("update");
|
|
469
|
-
const startedAt = performance.now();
|
|
470
|
-
if (this.state === "deferred-update") {
|
|
471
|
-
const edited = await this.attempt("update", startedAt, () => this.editOriginal(response));
|
|
472
|
-
this.report("update", startedAt, "sent", edited.id);
|
|
473
|
-
return edited;
|
|
474
|
-
}
|
|
475
|
-
const created = await this.attempt("update", startedAt, () => this.writeUpdate(response));
|
|
476
|
-
this.transition("update", "replied");
|
|
477
|
-
const message = this.remember(this.requireMessage(created, "update"));
|
|
478
|
-
this.report("update", startedAt, "sent", message.id);
|
|
479
|
-
return message;
|
|
480
|
-
}
|
|
481
|
-
async followUp(response, opts) {
|
|
482
|
-
this.checkLegality("followUp");
|
|
483
|
-
const startedAt = performance.now();
|
|
484
|
-
const created = await this.attempt("followUp", startedAt, () => this.writeFollowUp(response, opts));
|
|
485
|
-
const message = this.remember(created);
|
|
486
|
-
this.report("followUp", startedAt, "sent", message.id);
|
|
487
|
-
return message;
|
|
488
|
-
}
|
|
489
|
-
async edit(targetOrResponse, maybeResponse) {
|
|
490
|
-
this.checkLegality("edit");
|
|
491
|
-
const startedAt = performance.now();
|
|
492
|
-
if (maybeResponse === void 0) {
|
|
493
|
-
const edited = await this.attempt("edit", startedAt, () => this.editOriginal(targetOrResponse));
|
|
494
|
-
this.report("edit", startedAt, "sent", edited.id);
|
|
495
|
-
return edited;
|
|
496
|
-
}
|
|
497
|
-
const target = targetOrResponse;
|
|
498
|
-
if (!this.sent.has(target.id)) throw new SeedcordError(SeedcordErrorCode.ReplyForeignEditTarget, [
|
|
499
|
-
"edit",
|
|
500
|
-
target.id,
|
|
501
|
-
this.routeId
|
|
502
|
-
]);
|
|
503
|
-
const written = await this.attempt("edit", startedAt, () => this.writeEditTarget(target.id, maybeResponse));
|
|
504
|
-
const message = this.remember(written);
|
|
505
|
-
this.report("edit", startedAt, "sent", message.id);
|
|
506
|
-
return message;
|
|
507
|
-
}
|
|
508
|
-
async delete(target) {
|
|
509
|
-
this.checkLegality("delete");
|
|
510
|
-
const startedAt = performance.now();
|
|
511
|
-
if (target === void 0) {
|
|
512
|
-
await this.attempt("delete", startedAt, () => this.writeDeleteOriginal());
|
|
513
|
-
this.report("delete", startedAt, "sent", null);
|
|
514
|
-
return;
|
|
515
|
-
}
|
|
516
|
-
if (!this.sent.has(target.id)) throw new SeedcordError(SeedcordErrorCode.ReplyForeignEditTarget, [
|
|
517
|
-
"delete",
|
|
518
|
-
target.id,
|
|
519
|
-
this.routeId
|
|
520
|
-
]);
|
|
521
|
-
await this.attempt("delete", startedAt, () => this.writeDeleteTarget(target.id));
|
|
522
|
-
this.sent.delete(target.id);
|
|
523
|
-
this.report("delete", startedAt, "sent", null);
|
|
524
|
-
}
|
|
525
|
-
/** Routes to the verb the current ack state permits. Every state has a route, so the illegal-ack throw is unreachable. */
|
|
526
|
-
async send(response, opts) {
|
|
527
|
-
const target = sendTarget(this.state);
|
|
528
|
-
if (target === "reply") return await this.reply(response, opts);
|
|
529
|
-
if (target === "edit") return await this.edit(response);
|
|
530
|
-
return await this.followUp(response, opts);
|
|
531
|
-
}
|
|
532
|
-
/** Must be the initial response. */
|
|
533
|
-
async showModal(modal) {
|
|
534
|
-
this.checkLegality("showModal");
|
|
535
|
-
this.guardModalSource();
|
|
536
|
-
let data;
|
|
537
|
-
try {
|
|
538
|
-
data = modal.toJSON();
|
|
539
|
-
} catch (error) {
|
|
540
|
-
const name = modal.constructor?.name;
|
|
541
|
-
throw translateSerializationError(error, !name || name === "Object" ? "modal" : name, 0, this.routeId);
|
|
542
|
-
}
|
|
543
|
-
const startedAt = performance.now();
|
|
544
|
-
await this.attempt("showModal", startedAt, () => this.writeModal(data));
|
|
545
|
-
this.transition("showModal", "replied");
|
|
546
|
-
this.report("showModal", startedAt, "sent", null);
|
|
547
|
-
}
|
|
548
|
-
serialize(response) {
|
|
549
|
-
return serializeReply(response, this.routeId);
|
|
550
|
-
}
|
|
551
|
-
remember(created) {
|
|
552
|
-
this.sent.add(created.id);
|
|
553
|
-
return created;
|
|
554
|
-
}
|
|
555
|
-
requireMessage(created, method) {
|
|
556
|
-
if (!created) throw new SeedcordError(SeedcordErrorCode.ReplyCallbackMissingMessage, [method, this.routeId]);
|
|
557
|
-
return created;
|
|
558
|
-
}
|
|
559
|
-
async editOriginal(response) {
|
|
560
|
-
const edited = await this.writeEditOriginal(response);
|
|
561
|
-
if (this.state !== "deferred-update") this.remember(edited);
|
|
562
|
-
return edited;
|
|
563
|
-
}
|
|
564
|
-
checkLegality(method) {
|
|
565
|
-
checkAckLegality(method, this.state, this.routeId, this.ackedBy);
|
|
566
|
-
}
|
|
567
|
-
transition(method, state) {
|
|
568
|
-
this.state = state;
|
|
569
|
-
this.ackedBy = new AckTrace(method);
|
|
570
|
-
}
|
|
571
|
-
guardModalSource() {}
|
|
572
|
-
};
|
|
573
|
-
|
|
574
127
|
//#endregion
|
|
575
128
|
//#region src/dispatch/dispatchReport.ts
|
|
576
129
|
let dispatchLogger;
|
|
@@ -617,5 +170,5 @@ function reportDispatch(bus, report) {
|
|
|
617
170
|
}
|
|
618
171
|
|
|
619
172
|
//#endregion
|
|
620
|
-
export { AckTrace, AutocompleteRouteBrand,
|
|
173
|
+
export { AckTrace, AutocompleteRouteBrand, CommandMetadataKey, ComponentDefsBrand, ComponentDefsKey, ComponentKindBrand, ContextMenuKindBrand, ContextMenuNamesBrand, EventMetadataKey, GateNotice, GatedMetadataKey, HasDangerousPermissions, HmrManager, InteractionMetadataKey, InteractionRouteKeys, InteractionRoutes, MiddlewareMetadataKey, MissingPermissions, MissingRole, NeedsAny, NotAllowed, NotInDm, NotInGuild, NotOwner, NoticeCard, OnCooldown, PAGE_MAX, PermissionNames, PublishDefault, RegisterDefaults, RegisterSubscriber, RegisteredCount, ReportThrottle, SlashRouteBrand, SubscribeMetadataKey, UnregisterSubscriber, VerifyWebhooks, WebhookUrlMetadataKey, accessorStore, areRoutes, asError, busLoggerOf, checkAckLegality, clearStore, contextMenuLeaves, contextMenuRouteOf, decodeComponentRoute, decodeFor, deferFlags, getDevChannel, guardedAccessor, interactionRoutesOf, isCommandClass, isEmojiTuple, outcomeFor, pageCursor, pickNotice, prefixOf, queuedMsFor, reportDispatch, reportedWrite, routeIdOf, runGates, runHandlerGates, selectMenuRouteOf, sendFlags, sendTarget, serializeReply, setBotColor, setDevChannel, slashRouteLeaves, slowGateMonitor, storeComponentRoute, storeInteractionRoute, translateSerializationError, wrapHot };
|
|
621
174
|
//# sourceMappingURL=internal.index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.index.mjs","names":["logger","logger"],"sources":["../src/decorators/brands.ts","../src/gates/runGates.ts","../src/gates/slowGate.ts","../src/miscellaneous/emojiConfig.ts","../src/hmr/wrapHot.ts","../src/hmr/HmrManager.ts","../src/stops/asError.ts","../src/reply/ackLegality.ts","../src/reply/AckTrace.ts","../src/reply/responseReport.ts","../src/reply/translateSerialization.ts","../src/reply/serializeReply.ts","../src/reply/BaseReplySender.ts","../src/dispatch/dispatchReport.ts"],"sourcesContent":["// A handler base declares these so a route decorator can read what the handler is for. Nothing\n// assigns them at runtime.\n\nexport const SlashRouteBrand: unique symbol = Symbol('seedcord:brand:slashRoute');\nexport const AutocompleteRouteBrand: unique symbol = Symbol('seedcord:brand:autocompleteRoute');\nexport const ContextMenuKindBrand: unique symbol = Symbol('seedcord:brand:contextMenuKind');\nexport const ContextMenuNamesBrand: unique symbol = Symbol('seedcord:brand:contextMenuNames');\nexport const ComponentKindBrand: unique symbol = Symbol('seedcord:brand:componentKind');\nexport const ComponentDefsBrand: unique symbol = Symbol('seedcord:brand:componentDefs');\n","import 'reflect-metadata';\n\nimport { GatedMetadataKey, InteractionRouteKeys } from '#src/metadataKeys';\n\nimport { discardCommits, runCheck, runCommits } from './effects';\n\nimport type { Gate, GateContextBase } from './Gate';\n\n// a combinator (`and`/`or`) reports once under its joined name.\nexport type GateObserver = (gateName: string, elapsedMs: number) => void;\n\n// the stable id a route decorator stored, e.g. slash:daily or button:confirm. null for a plain event handler.\nexport function routeIdOf(handlerCtor: object): string | null {\n for (const [kind, key] of Object.entries(InteractionRouteKeys)) {\n // justified: getMetadata returns any, this key only ever stores the route/prefix string array\n const routes = Reflect.getMetadata(key, handlerCtor) as string[] | undefined;\n if (routes?.length) return `${kind}:${routes.join(',')}`;\n }\n return null;\n}\n\nasync function timedCheck(gate: Gate<GateContextBase>, ctx: GateContextBase, observe: GateObserver): Promise<void> {\n const start = performance.now();\n // finally so a refusing gate still reports\n try {\n await runCheck(gate, ctx);\n } finally {\n observe(gate.name, performance.now() - start);\n }\n}\n\n// the first refusal throws out to the dispatcher boundary. an effect gate's commit runs once the\n// whole set passes, and observe never times the commit phase.\nexport async function runGates(\n gates: readonly Gate<GateContextBase>[],\n ctx: GateContextBase,\n observe?: GateObserver\n): Promise<void> {\n try {\n for (const gate of gates) {\n await (observe ? timedCheck(gate, ctx, observe) : runCheck(gate, ctx));\n }\n await runCommits(ctx);\n } finally {\n discardCommits(ctx);\n }\n}\n\n// dispatchers call this before execute, inside the boundary, so a refusal renders or drops. an explicit\n// routeId is for manifest-driven handlers, which carry no route metadata to derive one from.\nexport async function runHandlerGates(\n handlerCtor: object,\n ctx: GateContextBase,\n routeId?: string,\n observe?: GateObserver\n): Promise<void> {\n // justified: getMetadata returns any, and this key only ever stores the @Gated gate array\n const gates = Reflect.getMetadata(GatedMetadataKey, handlerCtor) as readonly Gate<GateContextBase>[] | undefined;\n if (!gates) return;\n await runGates(gates, { ...ctx, routeId: routeId ?? routeIdOf(handlerCtor) }, observe);\n}\n","import { paint } from '@seedcord/errors';\nimport { Logger } from '@seedcord/logger';\nimport { Envapter } from 'envapt';\n\nimport type { GateObserver } from './runGates';\n\n// combined check time slower than this cuts into the 3s interaction-ack budget\nconst SLOW_GATE_MS = 750;\n\n// lazy because the logger reads the environment, which binds after this module loads\nlet gateLogger: Logger | undefined;\nfunction logger(): Logger {\n gateLogger ??= new Logger('Gates', { channel: 'gates' });\n return gateLogger;\n}\n\n/**\n * collects each gate check's elapsed time for one dispatch. `report` warns once when the checks sum\n * past the threshold, naming the total, the route, and each gate's share.\n */\nexport interface SlowGateMonitor {\n readonly observe: GateObserver;\n report(routeId: string | null): void;\n}\n\n// undefined in production, so timedCheck skips the clock there. read per call, the environment binds late\nexport function slowGateMonitor(): SlowGateMonitor | undefined {\n if (Envapter.isProduction) return undefined;\n const readings: { name: string; ms: number }[] = [];\n return {\n observe: (name, ms) => readings.push({ name, ms }),\n report(routeId) {\n const total = readings.reduce((sum, reading) => sum + reading.ms, 0);\n if (total < SLOW_GATE_MS) return;\n const shares = readings\n .toSorted((a, b) => b.ms - a.ms)\n .map((reading) => `${paint.sky.bold(reading.name)} ${paint.mute(`${Math.round(reading.ms)}ms`)}`);\n const route = routeId === null ? '' : ` for ${paint.sky.bold(routeId)}`;\n const headline = `gates${route} took ${paint.amber(`${Math.round(total)}ms`)} of the 3s ack budget`;\n logger().utils.block(headline, shares, 'warn', (text) => text);\n }\n };\n}\n","// narrows a configured emoji value to the [name, guildId] form\nexport function isEmojiTuple(value: unknown): value is readonly [string, string] {\n return Array.isArray(value) && value.length === 2 && typeof value[0] === 'string' && typeof value[1] === 'string';\n}\n","import type { DevChannel } from '@seedcord/types/internal';\n\n// the minimal raw-hot shape, satisfied by both vite's `import.meta.hot` and the CLI's `NormalizedHotChannel`.\ninterface RawHot {\n send(event: string, data?: unknown): void;\n on(event: string, cb: (data: unknown) => void): void;\n}\n\n/** @internal */\nexport function wrapHot<TSend, TRecv>(hot: RawHot): DevChannel<TSend, TRecv> {\n return {\n send: (event, data) => hot.send(event, data),\n // justified: RawHot types every payload as unknown, and the wire contract guarantees it matches TRecv[Key]\n on: (event, cb) => hot.on(event, cb as (data: unknown) => void)\n };\n}\n","// scoped here so import.meta.hot stays untyped in the rest of the package\n/// <reference types=\"vite/client\" />\nimport { paint } from '@seedcord/errors';\nimport { Logger } from '@seedcord/logger';\nimport { Envapter } from 'envapt';\n\nimport { setDevChannel } from './devChannel';\nimport { wrapHot } from './wrapHot';\n\nimport type { HmrAware, HmrUpdateEvent } from '@seedcord/types';\nimport type { SeedcordCliEvents, SeedcordFrameworkEvents } from '@seedcord/types/internal';\n\nexport class HmrManager {\n private readonly logger = new Logger('HMR', { channel: 'hmr' });\n private readonly listeners = new Set<HmrAware>();\n\n /** @internal */\n public init(): void {\n if (!import.meta.hot) return;\n // the only raw `import.meta.hot` read in the framework\n const channel = wrapHot<SeedcordFrameworkEvents, SeedcordCliEvents>(import.meta.hot);\n setDevChannel(channel);\n\n if (Envapter.isDevelopment || Envapter.isTest) {\n this.logger.debug('Enabled');\n channel.on('seedcord:hmr', (payload) => void this.handleUpdate(payload));\n }\n }\n\n /** @internal */\n public register(listener: HmrAware): void {\n this.listeners.add(listener);\n }\n\n private async handleUpdate(event: HmrUpdateEvent): Promise<void> {\n const promises = [...this.listeners].map(async (listener) => {\n try {\n await listener.onHmr(event);\n } catch (error) {\n this.logger.error(`Error handling HMR update in ${paint.sky.bold(listener.constructor.name)}`, error);\n }\n });\n\n await Promise.all(promises);\n }\n}\n","// dropping a non-Error throw would leave the user with no fault card, and every report payload declares an Error\n/** @internal */\nexport function asError(caught: unknown): Error {\n return Error.isError(caught) ? caught : new Error(String(caught), { cause: caught });\n}\n","import { SeedcordErrorCode } from '@seedcord/errors';\nimport { SeedcordError } from '@seedcord/errors/internal';\n\nimport type { AckTrace } from './AckTrace';\n\nexport type AckState = 'unacked' | 'deferred-reply' | 'deferred-update' | 'replied';\n\nexport type ReplyMethod =\n 'reply' | 'defer' | 'deferUpdate' | 'update' | 'followUp' | 'edit' | 'delete' | 'send' | 'showModal';\n\ninterface Illegal {\n // spliced into the message after \"was called when\"\n readonly reason: string;\n readonly alternative: string;\n}\n\nconst showModalReason: Illegal = {\n reason: 'this interaction was already acknowledged',\n alternative: 'showModal() must be the initial response.'\n};\n\nfunction deferReason(what: string): Illegal {\n return {\n reason: `this interaction was already acknowledged with ${what}`,\n alternative: 'A deferral can only be the initial response.'\n };\n}\n\n// a missing entry means legal in that state\nconst ILLEGAL: Record<Exclude<ReplyMethod, 'send'>, Partial<Record<AckState, Illegal>>> = {\n reply: {\n 'deferred-reply': {\n reason: 'this interaction was already deferred',\n alternative: 'Use edit() to fill the deferred reply or followUp() for a new message.'\n },\n 'deferred-update': {\n reason: 'this interaction was already acknowledged with a deferred update',\n alternative: 'Use followUp() for a new message.'\n },\n replied: {\n reason: 'this interaction was already replied to',\n alternative: 'Use followUp() for a new message or edit() to rewrite the reply.'\n }\n },\n defer: {\n 'deferred-reply': deferReason('a deferred reply'),\n 'deferred-update': deferReason('a deferred update'),\n replied: deferReason('a reply')\n },\n deferUpdate: {\n 'deferred-reply': deferReason('a deferred reply'),\n 'deferred-update': deferReason('a deferred update'),\n replied: deferReason('a reply')\n },\n update: {\n 'deferred-reply': {\n reason: 'this interaction was deferred as a reply',\n alternative: 'The placeholder is yours via edit(). update() rewrites a source message.'\n },\n replied: {\n reason: 'this interaction was already replied to',\n alternative: 'update() rewrites a source message. Use edit() or followUp() instead.'\n }\n },\n followUp: {\n unacked: {\n reason: 'this interaction has not been acknowledged yet',\n alternative: 'Ack first with reply() or defer().'\n }\n },\n edit: {\n unacked: {\n reason: 'nothing has been sent yet',\n alternative: 'Send with reply() or defer() first, then edit() rewrites it.'\n }\n },\n delete: {\n unacked: {\n reason: 'nothing has been sent yet',\n alternative: 'Acknowledge first with reply() or defer(), then delete() removes it.'\n }\n },\n showModal: {\n 'deferred-reply': showModalReason,\n 'deferred-update': showModalReason,\n replied: showModalReason\n }\n};\n\nconst SEND_TARGET: Record<AckState, 'reply' | 'edit' | 'followUp'> = {\n unacked: 'reply',\n 'deferred-reply': 'edit',\n 'deferred-update': 'followUp',\n replied: 'followUp'\n};\n\n// throws before any API call, and ackedBy becomes the throw cause with its stack pointing at the first ack\nexport function checkAckLegality(method: ReplyMethod, state: AckState, routeId: string, ackedBy?: AckTrace): void {\n if (method === 'send') return;\n const illegal = ILLEGAL[method][state];\n if (!illegal) return;\n throw new SeedcordError(\n SeedcordErrorCode.ReplyIllegalAckState,\n [method, illegal.reason, illegal.alternative, routeId],\n { cause: ackedBy }\n );\n}\n\nexport function sendTarget(state: AckState): 'reply' | 'edit' | 'followUp' {\n return SEND_TARGET[state];\n}\n","import type { ReplyMethod } from './ackLegality';\n\n// the first ack's stack, passed as the throw cause so a double-ack points to both lines\nexport class AckTrace extends Error {\n public constructor(method: ReplyMethod) {\n super(`${method}() acknowledged this interaction`);\n this.name = 'AckTrace';\n }\n}\n","import { paint } from '@seedcord/errors';\nimport { Logger } from '@seedcord/logger';\n\nimport { asError } from '#stops/asError';\nimport { PublishDefault } from '#subscribers/publishDefault';\n\nimport type { Bus } from '#subscribers/Bus';\nimport type { ResponseOutcome } from '#subscribers/types/Subscriptions';\nimport type { ReplyMethod } from './ackLegality';\n\nlet replyLogger: Logger | undefined;\nfunction logger(): Logger {\n replyLogger ??= new Logger('Reply', { channel: 'interactions' });\n return replyLogger;\n}\n\nexport interface ReplyTelemetry {\n readonly bus: Bus;\n readonly interactionId: string;\n}\n\n// the reply verbs plus the autocomplete choices callback, which runs outside the ack state machine\nexport type WriteMethod = ReplyMethod | 'respond';\n\nexport interface ResponseReport {\n readonly routeId: string;\n readonly method: WriteMethod;\n // performance.now() captured before the write began\n readonly startedAt: number;\n readonly outcome: ResponseOutcome;\n readonly messageId: string | null;\n readonly error?: Error;\n}\n\n/** @internal */\nexport function publishResponse(telemetry: ReplyTelemetry, report: ResponseReport): void {\n const durationMs = performance.now() - report.startedAt;\n telemetry.bus[PublishDefault]('responseAttempted', {\n routeId: report.routeId,\n interactionId: telemetry.interactionId,\n method: report.method,\n outcome: report.outcome,\n durationMs,\n messageId: report.messageId,\n ...(report.error && { error: report.error })\n });\n\n // after publish so a throwing sink doesn't reach the publish above\n logger().trace(\n `${paint.sky.bold(report.routeId)} ${report.method} ${report.outcome} ${paint.mute('in')} ${Math.round(durationMs)}ms`\n );\n}\n\nexport async function reportedWrite<Result>(\n telemetry: ReplyTelemetry,\n routeId: string,\n method: WriteMethod,\n write: () => Promise<Result>\n): Promise<Result> {\n const startedAt = performance.now();\n const result = await attemptWrite(telemetry, routeId, method, startedAt, write);\n publishResponse(telemetry, { routeId, method, startedAt, outcome: 'sent', messageId: null });\n return result;\n}\n\n// publishes the failed arm when write() throws, since the caller's success report sits after the write and a throw skips it\nexport async function attemptWrite<Result>(\n telemetry: ReplyTelemetry,\n routeId: string,\n method: WriteMethod,\n startedAt: number,\n write: () => Promise<Result>\n): Promise<Result> {\n try {\n return await write();\n } catch (caught) {\n const error = asError(caught);\n publishResponse(telemetry, { routeId, method, startedAt, outcome: 'failed', messageId: null, error });\n // rethrown raw\n throw caught;\n }\n}\n","import { SeedcordErrorCode } from '@seedcord/errors';\nimport { SeedcordError } from '@seedcord/errors/internal';\n\n// shapeshift aggregate errors nest, so the cap bounds the recursion\nconst MAX_DEPTH = 8;\n\ninterface ShapeshiftLike {\n readonly message?: unknown;\n readonly errors?: unknown;\n readonly constraint?: unknown;\n readonly validator?: unknown;\n readonly expected?: unknown;\n readonly given?: unknown;\n}\n\nconst OPERATOR_WORD: Record<string, string> = {\n '<=': 'at most',\n '>=': 'at least',\n '<': 'fewer than',\n '>': 'more than'\n};\n\nconst KIND_WORD: Record<string, string> = {\n string: 'a string',\n number: 'a number',\n boolean: 'a boolean',\n bigint: 'a bigint',\n array: 'a list',\n tuple: 'a list',\n date: 'a date',\n object: 'an object'\n};\n\nfunction asRecord(value: unknown): ShapeshiftLike | null {\n return typeof value === 'object' && value !== null ? value : null;\n}\n\nfunction firstLine(message: unknown): string {\n if (typeof message !== 'string') return 'unknown validation failure';\n return message.split('\\n')[0] ?? message;\n}\n\n// strings over this limit render as a character count\nconst GIVEN_PREVIEW_LIMIT = 40;\n\nfunction gotPhrase(given: unknown): string {\n if (given === undefined) return 'nothing';\n if (given === null) return 'null';\n if (typeof given === 'string') {\n if (given.length === 0) return 'an empty string';\n if (given.length > GIVEN_PREVIEW_LIMIT) return `${given.length} characters`;\n return JSON.stringify(given);\n }\n if (Array.isArray(given)) return given.length === 0 ? 'an empty list' : `${given.length} items`;\n if (typeof given === 'number' || typeof given === 'bigint' || typeof given === 'boolean') return String(given);\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- a null-prototype value has no constructor at runtime\n if (typeof given === 'object') return given.constructor?.name ?? 'an object';\n return typeof given;\n}\n\n// shapeshift constraint strings take the form 'expected.length >= 1' or 'expected <= 16777215'\nfunction needPhrase(expected: string, given: unknown): string | null {\n const bounds = [...expected.matchAll(/expected(\\.length)?\\s*(<=|>=|<|>)\\s*(\\d+)/g)];\n if (bounds.length === 0) return null;\n const phrases = bounds.map(([, lengthPart, operator, limit]) => {\n const word = OPERATOR_WORD[operator ?? ''] ?? operator ?? '';\n if (!lengthPart) return `${word} ${limit}`;\n const unit = typeof given === 'string' ? 'character' : 'item';\n return `${word} ${limit} ${Number(limit) === 1 ? unit : `${unit}s`}`;\n });\n return phrases.join(' and ');\n}\n\nfunction instanceName(expected: unknown): string {\n if (typeof expected === 'function' && expected.name) return expected.name;\n return 'specific class instance';\n}\n\nfunction describeLeaf(record: ShapeshiftLike): string {\n if (typeof record.constraint === 'string') {\n const need = typeof record.expected === 'string' ? needPhrase(record.expected, record.given) : null;\n if (need) return `need ${need}, got ${gotPhrase(record.given)}`;\n return `${firstLine(record.message)}${'given' in record ? ` (got ${gotPhrase(record.given)})` : ''}`;\n }\n if (typeof record.expected === 'function') {\n return `need a ${instanceName(record.expected)}, got ${gotPhrase(record.given)}`;\n }\n if (typeof record.validator === 'string') {\n const kind = KIND_WORD[record.validator.replace(/^s\\./, '').replace(/\\(.*$/, '')];\n if (kind) return `need ${kind}, got ${gotPhrase(record.given)}`;\n return `${firstLine(record.message)}, got ${gotPhrase(record.given)}`;\n }\n return firstLine(record.message);\n}\n\nfunction describeUnion(branches: unknown[], depth: number): string {\n const records: ShapeshiftLike[] = [];\n for (const branch of branches) {\n const record = asRecord(branch);\n if (record) records.push(record);\n }\n const bounded = records.find((record) => typeof record.constraint === 'string');\n if (bounded) return describeLeaf(bounded);\n\n const names: string[] = [];\n let allInstances = records.length > 0;\n for (const record of records) {\n if (typeof record.expected === 'function') names.push(instanceName(record.expected));\n else allInstances = false;\n }\n if (allInstances) {\n return `need a ${[...new Set(names)].join(' or ')}, got ${gotPhrase(records[0]?.given)}`;\n }\n return detailOf(branches[0], depth + 1);\n}\n\n// shapeshift nests errors as [key, inner] tuples\nfunction detailOf(value: unknown, depth: number): string {\n const record = asRecord(value);\n if (!record || depth >= MAX_DEPTH) return firstLine(record?.message);\n\n if (Array.isArray(record.errors) && record.errors.length > 0) {\n const errors = record.errors as unknown[];\n const [first] = errors;\n if (Array.isArray(first)) {\n const [key, inner] = first as [unknown, unknown];\n return `${String(key)}: ${detailOf(inner, depth + 1)}`;\n }\n return describeUnion(errors, depth);\n }\n\n return describeLeaf(record);\n}\n\n// a shapeshift throw becomes an actionable message with the cause kept, while anything else contributes its own message as the detail\nexport function translateSerializationError(\n error: unknown,\n componentClass: string,\n index: number,\n routeId: string\n): SeedcordError<SeedcordErrorCode.ReplyComponentSerialization> {\n const detail = detailOf(error, 0);\n return new SeedcordError(SeedcordErrorCode.ReplyComponentSerialization, [componentClass, index, detail, routeId], {\n cause: error\n });\n}\n","import { TextDisplayBuilder } from '@discordjs/builders';\n\nimport { translateSerializationError } from './translateSerialization';\n\nimport type { ReplyResponse } from '@seedcord/types';\nimport type { APIMessageTopLevelComponent } from 'discord-api-types/v10';\n\nexport interface SerializedReply<TNative = never> {\n readonly components: APIMessageTopLevelComponent[];\n readonly allowedMentions?: ReplyResponse['allowedMentions'];\n readonly files?: ReplyResponse<TNative>['files'];\n}\n\nexport function serializeReply<TNative>(\n response: ReplyResponse<TNative> | string,\n routeId: string\n): SerializedReply<TNative> {\n if (typeof response === 'string') {\n try {\n return { components: [new TextDisplayBuilder().setContent(response).toJSON()] };\n } catch (error) {\n throw translateSerializationError(error, 'TextDisplayBuilder', 0, routeId);\n }\n }\n\n const components = response.components.map((component, index) => {\n try {\n return component.toJSON();\n } catch (error) {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- a null-prototype value has no constructor at runtime\n const name = component.constructor?.name;\n throw translateSerializationError(error, !name || name === 'Object' ? 'component' : name, index, routeId);\n }\n });\n\n return {\n components,\n ...(response.allowedMentions && { allowedMentions: response.allowedMentions }),\n ...(response.files && { files: response.files })\n };\n}\n","import { SeedcordErrorCode } from '@seedcord/errors';\nimport { SeedcordError } from '@seedcord/errors/internal';\n\nimport { checkAckLegality, sendTarget } from './ackLegality';\nimport { AckTrace } from './AckTrace';\nimport { attemptWrite, publishResponse } from './responseReport';\nimport { serializeReply } from './serializeReply';\nimport { translateSerializationError } from './translateSerialization';\n\nimport type { ResponseOutcome } from '#subscribers/types/Subscriptions';\nimport type { AckState, ReplyMethod } from './ackLegality';\nimport type { ReplyTelemetry } from './responseReport';\nimport type { SerializedReply } from './serializeReply';\nimport type { DeferOpts, ReplyResponse, SendOpts } from '@seedcord/types';\nimport type { APIModalInteractionResponseCallbackData } from 'discord-api-types/v10';\n\n/** The shape djs modal builders emit from `toJSON()`. */\nexport interface ModalLike {\n toJSON(): APIModalInteractionResponseCallbackData;\n}\n\n/**\n * Tracks acknowledgement state and throws a translated `SeedcordError` on an illegal verb before any\n * transport call. Every verb runs the legality check, calls the transport's wire writer, then updates\n * the state and the ack trace. Each transport binds `TMessage` to its own created-message type and\n * supplies the writers.\n */\nexport abstract class BaseReplySender<TMessage extends { id: string }, TNative = never> {\n private state: AckState;\n // the only ids a targeted edit accepts\n private readonly sent = new Set<string>();\n // the cause carries the first ack's stack so a double-ack reports both lines\n private ackedBy?: AckTrace;\n\n protected constructor(\n protected readonly routeId: string,\n private readonly telemetry: ReplyTelemetry,\n initialState: AckState = 'unacked'\n ) {\n this.state = initialState;\n }\n\n private report(method: ReplyMethod, startedAt: number, outcome: ResponseOutcome, messageId: string | null): void {\n publishResponse(this.telemetry, { routeId: this.routeId, method, startedAt, outcome, messageId });\n }\n\n private async attempt<Result>(\n method: ReplyMethod,\n startedAt: number,\n write: () => Promise<Result>\n ): Promise<Result> {\n return await attemptWrite(this.telemetry, this.routeId, method, startedAt, write);\n }\n\n public async reply(response: ReplyResponse<TNative> | string, opts?: SendOpts): Promise<TMessage> {\n this.checkLegality('reply');\n const startedAt = performance.now();\n const created = await this.attempt('reply', startedAt, () => this.writeReply(response, opts));\n // the callback already acked discord, so record replied before the message guard can throw\n this.transition('reply', 'replied');\n const message = this.remember(this.requireMessage(created, 'reply'));\n this.report('reply', startedAt, 'sent', message.id);\n return message;\n }\n\n public async defer(opts?: DeferOpts): Promise<void> {\n this.checkLegality('defer');\n const startedAt = performance.now();\n await this.attempt('defer', startedAt, () => this.writeDefer(opts));\n this.transition('defer', 'deferred-reply');\n this.report('defer', startedAt, 'sent', null);\n }\n\n public async deferUpdate(): Promise<void> {\n this.checkLegality('deferUpdate');\n const startedAt = performance.now();\n await this.attempt('deferUpdate', startedAt, () => this.writeDeferUpdate());\n this.transition('deferUpdate', 'deferred-update');\n this.report('deferUpdate', startedAt, 'sent', null);\n }\n\n /**\n * After a deferUpdate the state stays deferred-update. Calling this again rewrites. The returned message\n * is the source message, editable only through a bare `update` or `edit`. A targeted `edit` or `delete`\n * of it throws the foreign-target error.\n */\n public async update(response: ReplyResponse<TNative> | string): Promise<TMessage> {\n this.checkLegality('update');\n const startedAt = performance.now();\n // in deferred-update the source message is @original and the ack-legality check above already passed\n if (this.state === 'deferred-update') {\n const edited = await this.attempt('update', startedAt, () => this.editOriginal(response));\n this.report('update', startedAt, 'sent', edited.id);\n return edited;\n }\n const created = await this.attempt('update', startedAt, () => this.writeUpdate(response));\n this.transition('update', 'replied');\n const message = this.remember(this.requireMessage(created, 'update'));\n this.report('update', startedAt, 'sent', message.id);\n return message;\n }\n\n public async followUp(response: ReplyResponse<TNative> | string, opts?: SendOpts): Promise<TMessage> {\n this.checkLegality('followUp');\n const startedAt = performance.now();\n const created = await this.attempt('followUp', startedAt, () => this.writeFollowUp(response, opts));\n const message = this.remember(created);\n this.report('followUp', startedAt, 'sent', message.id);\n return message;\n }\n\n public edit(response: ReplyResponse<TNative> | string): Promise<TMessage>;\n public edit(target: TMessage, response: ReplyResponse<TNative> | string): Promise<TMessage>;\n public async edit(\n targetOrResponse: TMessage | ReplyResponse<TNative> | string,\n maybeResponse?: ReplyResponse<TNative> | string\n ): Promise<TMessage> {\n this.checkLegality('edit');\n const startedAt = performance.now();\n if (maybeResponse === undefined) {\n // justified: the overloads narrow targetOrResponse to a response once maybeResponse is absent\n const edited = await this.attempt('edit', startedAt, () =>\n this.editOriginal(targetOrResponse as ReplyResponse<TNative> | string)\n );\n this.report('edit', startedAt, 'sent', edited.id);\n return edited;\n }\n // justified: the overloads narrow targetOrResponse to a target message once maybeResponse is defined\n const target = targetOrResponse as TMessage;\n if (!this.sent.has(target.id)) {\n throw new SeedcordError(SeedcordErrorCode.ReplyForeignEditTarget, ['edit', target.id, this.routeId]);\n }\n const written = await this.attempt('edit', startedAt, () => this.writeEditTarget(target.id, maybeResponse));\n const message = this.remember(written);\n this.report('edit', startedAt, 'sent', message.id);\n return message;\n }\n\n public delete(): Promise<void>;\n public delete(target: TMessage): Promise<void>;\n public async delete(target?: TMessage): Promise<void> {\n this.checkLegality('delete');\n const startedAt = performance.now();\n if (target === undefined) {\n await this.attempt('delete', startedAt, () => this.writeDeleteOriginal());\n this.report('delete', startedAt, 'sent', null);\n return;\n }\n if (!this.sent.has(target.id)) {\n throw new SeedcordError(SeedcordErrorCode.ReplyForeignEditTarget, ['delete', target.id, this.routeId]);\n }\n await this.attempt('delete', startedAt, () => this.writeDeleteTarget(target.id));\n // evict so a later targeted edit of this id throws foreign\n this.sent.delete(target.id);\n this.report('delete', startedAt, 'sent', null);\n }\n\n /** Routes to the verb the current ack state permits. Every state has a route, so the illegal-ack throw is unreachable. */\n public async send(response: ReplyResponse<TNative> | string, opts?: SendOpts): Promise<TMessage> {\n const target = sendTarget(this.state);\n if (target === 'reply') return await this.reply(response, opts);\n if (target === 'edit') return await this.edit(response);\n return await this.followUp(response, opts);\n }\n\n /** Must be the initial response. */\n public async showModal(modal: ModalLike): Promise<void> {\n this.checkLegality('showModal');\n this.guardModalSource();\n let data: APIModalInteractionResponseCallbackData;\n try {\n data = modal.toJSON();\n } catch (error) {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- a null-prototype modal has no constructor at runtime\n const name = modal.constructor?.name;\n throw translateSerializationError(error, !name || name === 'Object' ? 'modal' : name, 0, this.routeId);\n }\n const startedAt = performance.now();\n await this.attempt('showModal', startedAt, () => this.writeModal(data));\n this.transition('showModal', 'replied');\n this.report('showModal', startedAt, 'sent', null);\n }\n\n protected serialize(response: ReplyResponse<TNative> | string): SerializedReply<TNative> {\n return serializeReply(response, this.routeId);\n }\n\n protected remember(created: TMessage): TMessage {\n this.sent.add(created.id);\n return created;\n }\n\n // a with_response callback always returns the created message. this only trips if the wire says otherwise\n private requireMessage(created: TMessage | undefined, method: 'reply' | 'update'): TMessage {\n if (!created) throw new SeedcordError(SeedcordErrorCode.ReplyCallbackMissingMessage, [method, this.routeId]);\n return created;\n }\n\n private async editOriginal(response: ReplyResponse<TNative> | string): Promise<TMessage> {\n const edited = await this.writeEditOriginal(response);\n // after a deferUpdate the source message is @original, which this interaction did not send\n if (this.state !== 'deferred-update') this.remember(edited);\n return edited;\n }\n\n private checkLegality(method: ReplyMethod): void {\n checkAckLegality(method, this.state, this.routeId, this.ackedBy);\n }\n\n private transition(method: ReplyMethod, state: AckState): void {\n this.state = state;\n this.ackedBy = new AckTrace(method);\n }\n\n // gateway overrides this to reject a modal-submit source\n protected guardModalSource(): void {}\n\n protected abstract writeReply(\n response: ReplyResponse<TNative> | string,\n opts?: SendOpts\n ): Promise<TMessage | undefined>;\n protected abstract writeDefer(opts?: DeferOpts): Promise<void>;\n protected abstract writeDeferUpdate(): Promise<void>;\n protected abstract writeUpdate(response: ReplyResponse<TNative> | string): Promise<TMessage | undefined>;\n protected abstract writeFollowUp(response: ReplyResponse<TNative> | string, opts?: SendOpts): Promise<TMessage>;\n protected abstract writeEditOriginal(response: ReplyResponse<TNative> | string): Promise<TMessage>;\n protected abstract writeEditTarget(targetId: string, response: ReplyResponse<TNative> | string): Promise<TMessage>;\n protected abstract writeDeleteOriginal(): Promise<void>;\n protected abstract writeDeleteTarget(targetId: string): Promise<void>;\n protected abstract writeModal(data: APIModalInteractionResponseCallbackData): Promise<void>;\n}\n","import { paint } from '@seedcord/errors';\nimport { Logger } from '@seedcord/logger';\nimport { timestampFromSnowflake } from '@seedcord/utils';\n\nimport { Notice } from '#stops/Notice';\nimport { Silence } from '#stops/Silence';\nimport { PublishDefault } from '#subscribers/publishDefault';\n\nimport type { InteractionRoutes } from '#src/metadataKeys';\nimport type { Bus } from '#subscribers/Bus';\nimport type { DispatchOutcome } from '#subscribers/types/Subscriptions';\n\nlet dispatchLogger: Logger | undefined;\nfunction logger(): Logger {\n dispatchLogger ??= new Logger('Dispatch', { channel: 'interactions' });\n return dispatchLogger;\n}\n\n/**\n * Classifies a caught stop for `interactionDispatched` so a gate and a\n * handler label the same stop identically.\n *\n * @internal\n */\nexport function outcomeFor(caught: unknown): DispatchOutcome {\n if (caught instanceof Silence) return 'refused';\n if (caught instanceof Notice) return caught.report ? 'failed' : 'refused';\n return 'failed';\n}\n\n/** The values a dispatcher has once its handler chain settles. */\ninterface DispatchReport {\n readonly routeId: string;\n readonly interactionId: string;\n readonly kind: `${InteractionRoutes}`;\n readonly outcome: DispatchOutcome;\n /** True when no route matched and the unhandled default ran. */\n readonly fallback: boolean;\n /** `performance.now()` captured as the dispatch began. */\n readonly startedAt: number;\n /** {@link queuedMsFor} read at the same moment as `startedAt`. */\n readonly queuedMs: number;\n}\n\n/**\n * Discord's interaction creation to now, read from the snowflake. Called at dispatch entry, since\n * a later read would count the handler run into the queue time as well.\n *\n * @internal\n */\nexport function queuedMsFor(interactionId: string): number {\n // telemetry never breaks a dispatch, and BigInt() throws on a malformed id\n try {\n return Date.now() - timestampFromSnowflake(interactionId);\n } catch {\n return 0;\n }\n}\n\nexport function reportDispatch(bus: Bus, report: DispatchReport): void {\n const durationMs = performance.now() - report.startedAt;\n bus[PublishDefault]('interactionDispatched', {\n routeId: report.routeId,\n interactionId: report.interactionId,\n kind: report.kind,\n outcome: report.outcome,\n fallback: report.fallback,\n durationMs,\n queuedMs: report.queuedMs\n });\n\n // after publish so a throwing sink doesn't reach the publish above\n logger().trace(\n `${paint.sky.bold(report.routeId)} ${report.outcome} ${paint.mute('in')} ${Math.round(durationMs)}ms`\n );\n}\n"],"mappings":";;;;;;;;;;;;;AAGA,MAAa,kBAAiC,OAAO,2BAA2B;AAChF,MAAa,yBAAwC,OAAO,kCAAkC;AAC9F,MAAa,uBAAsC,OAAO,gCAAgC;AAC1F,MAAa,wBAAuC,OAAO,iCAAiC;AAC5F,MAAa,qBAAoC,OAAO,8BAA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B;EAC3D,KAAK,QAAQ;EACb,KAAK,UAAU,IAAI,SAAS,MAAM;CACtC;CAGA,AAAU,mBAAyB,CAAC;AAexC;;;;AC1NA,IAAI;AACJ,SAAS,SAAiB;CACtB,mBAAmB,IAAI,OAAO,YAAY,EAAE,SAAS,eAAe,CAAC;CACrE,OAAO;AACX;;;;;;;AAQA,SAAgB,WAAW,QAAkC;CACzD,IAAI,kBAAkB,SAAS,OAAO;CACtC,IAAI,kBAAkB,QAAQ,OAAO,OAAO,SAAS,WAAW;CAChE,OAAO;AACX;;;;;;;AAsBA,SAAgB,YAAY,eAA+B;CAEvD,IAAI;EACA,OAAO,KAAK,IAAI,IAAI,uBAAuB,aAAa;CAC5D,QAAQ;EACJ,OAAO;CACX;AACJ;AAEA,SAAgB,eAAe,KAAU,QAA8B;CACnE,MAAM,aAAa,YAAY,IAAI,IAAI,OAAO;CAC9C,IAAI,eAAe,CAAC,yBAAyB;EACzC,SAAS,OAAO;EAChB,eAAe,OAAO;EACtB,MAAM,OAAO;EACb,SAAS,OAAO;EAChB,UAAU,OAAO;EACjB;EACA,UAAU,OAAO;CACrB,CAAC;CAGD,OAAO,CAAC,CAAC,MACL,GAAG,MAAM,IAAI,KAAK,OAAO,OAAO,EAAE,GAAG,OAAO,QAAQ,GAAG,MAAM,KAAK,IAAI,EAAE,GAAG,KAAK,MAAM,UAAU,EAAE,GACtG;AACJ"}
|
|
1
|
+
{"version":3,"file":"internal.index.mjs","names":["logger"],"sources":["../src/decorators/brands.ts","../src/gates/runGates.ts","../src/gates/slowGate.ts","../src/miscellaneous/emojiConfig.ts","../src/hmr/wrapHot.ts","../src/hmr/HmrManager.ts","../src/dispatch/dispatchReport.ts"],"sourcesContent":["// A handler base declares these so a route decorator can read what the handler is for. Nothing\n// assigns them at runtime.\n\nexport const SlashRouteBrand: unique symbol = Symbol('seedcord:brand:slashRoute');\nexport const AutocompleteRouteBrand: unique symbol = Symbol('seedcord:brand:autocompleteRoute');\nexport const ContextMenuKindBrand: unique symbol = Symbol('seedcord:brand:contextMenuKind');\nexport const ContextMenuNamesBrand: unique symbol = Symbol('seedcord:brand:contextMenuNames');\nexport const ComponentKindBrand: unique symbol = Symbol('seedcord:brand:componentKind');\nexport const ComponentDefsBrand: unique symbol = Symbol('seedcord:brand:componentDefs');\n","import 'reflect-metadata';\n\nimport { GatedMetadataKey, InteractionRouteKeys } from '#src/metadataKeys';\n\nimport { discardCommits, runCheck, runCommits } from './effects';\n\nimport type { Gate, GateContextBase } from './Gate';\n\n// a combinator (`and`/`or`) reports once under its joined name.\nexport type GateObserver = (gateName: string, elapsedMs: number) => void;\n\n// the stable id a route decorator stored, e.g. slash:daily or button:confirm. null for a plain event handler.\nexport function routeIdOf(handlerCtor: object): string | null {\n for (const [kind, key] of Object.entries(InteractionRouteKeys)) {\n // justified: getMetadata returns any, this key only ever stores the route/prefix string array\n const routes = Reflect.getMetadata(key, handlerCtor) as string[] | undefined;\n if (routes?.length) return `${kind}:${routes.join(',')}`;\n }\n return null;\n}\n\nasync function timedCheck(gate: Gate<GateContextBase>, ctx: GateContextBase, observe: GateObserver): Promise<void> {\n const start = performance.now();\n // finally so a refusing gate still reports\n try {\n await runCheck(gate, ctx);\n } finally {\n observe(gate.name, performance.now() - start);\n }\n}\n\n// the first refusal throws out to the dispatcher boundary. an effect gate's commit runs once the\n// whole set passes, and observe never times the commit phase.\nexport async function runGates(\n gates: readonly Gate<GateContextBase>[],\n ctx: GateContextBase,\n observe?: GateObserver\n): Promise<void> {\n try {\n for (const gate of gates) {\n await (observe ? timedCheck(gate, ctx, observe) : runCheck(gate, ctx));\n }\n await runCommits(ctx);\n } finally {\n discardCommits(ctx);\n }\n}\n\n// dispatchers call this before execute, inside the boundary, so a refusal renders or drops. an explicit\n// routeId is for manifest-driven handlers, which carry no route metadata to derive one from.\nexport async function runHandlerGates(\n handlerCtor: object,\n ctx: GateContextBase,\n routeId?: string,\n observe?: GateObserver\n): Promise<void> {\n // justified: getMetadata returns any, and this key only ever stores the @Gated gate array\n const gates = Reflect.getMetadata(GatedMetadataKey, handlerCtor) as readonly Gate<GateContextBase>[] | undefined;\n if (!gates) return;\n await runGates(gates, { ...ctx, routeId: routeId ?? routeIdOf(handlerCtor) }, observe);\n}\n","import { paint } from '@seedcord/errors';\nimport { Logger } from '@seedcord/logger';\nimport { Envapter } from 'envapt';\n\nimport type { GateObserver } from './runGates';\n\n// combined check time slower than this cuts into the 3s interaction-ack budget\nconst SLOW_GATE_MS = 750;\n\n// lazy because the logger reads the environment, which binds after this module loads\nlet gateLogger: Logger | undefined;\nfunction logger(): Logger {\n gateLogger ??= new Logger('Gates', { channel: 'gates' });\n return gateLogger;\n}\n\n/**\n * collects each gate check's elapsed time for one dispatch. `report` warns once when the checks sum\n * past the threshold, naming the total, the route, and each gate's share.\n */\nexport interface SlowGateMonitor {\n readonly observe: GateObserver;\n report(routeId: string | null): void;\n}\n\n// undefined in production, so timedCheck skips the clock there. read per call, the environment binds late\nexport function slowGateMonitor(): SlowGateMonitor | undefined {\n if (Envapter.isProduction) return undefined;\n const readings: { name: string; ms: number }[] = [];\n return {\n observe: (name, ms) => readings.push({ name, ms }),\n report(routeId) {\n const total = readings.reduce((sum, reading) => sum + reading.ms, 0);\n if (total < SLOW_GATE_MS) return;\n const shares = readings\n .toSorted((a, b) => b.ms - a.ms)\n .map((reading) => `${paint.sky.bold(reading.name)} ${paint.mute(`${Math.round(reading.ms)}ms`)}`);\n const route = routeId === null ? '' : ` for ${paint.sky.bold(routeId)}`;\n const headline = `gates${route} took ${paint.amber(`${Math.round(total)}ms`)} of the 3s ack budget`;\n logger().utils.block(headline, shares, 'warn', (text) => text);\n }\n };\n}\n","// narrows a configured emoji value to the [name, guildId] form\nexport function isEmojiTuple(value: unknown): value is readonly [string, string] {\n return Array.isArray(value) && value.length === 2 && typeof value[0] === 'string' && typeof value[1] === 'string';\n}\n","import type { DevChannel } from '@seedcord/types/internal';\n\n// the minimal raw-hot shape, satisfied by both vite's `import.meta.hot` and the CLI's `NormalizedHotChannel`.\ninterface RawHot {\n send(event: string, data?: unknown): void;\n on(event: string, cb: (data: unknown) => void): void;\n}\n\n/** @internal */\nexport function wrapHot<TSend, TRecv>(hot: RawHot): DevChannel<TSend, TRecv> {\n return {\n send: (event, data) => hot.send(event, data),\n // justified: RawHot types every payload as unknown, and the wire contract guarantees it matches TRecv[Key]\n on: (event, cb) => hot.on(event, cb as (data: unknown) => void)\n };\n}\n","// scoped here so import.meta.hot stays untyped in the rest of the package\n/// <reference types=\"vite/client\" />\nimport { paint } from '@seedcord/errors';\nimport { Logger } from '@seedcord/logger';\nimport { Envapter } from 'envapt';\n\nimport { setDevChannel } from './devChannel';\nimport { wrapHot } from './wrapHot';\n\nimport type { HmrAware, HmrUpdateEvent } from '@seedcord/types';\nimport type { SeedcordCliEvents, SeedcordFrameworkEvents } from '@seedcord/types/internal';\n\nexport class HmrManager {\n private readonly logger = new Logger('HMR', { channel: 'hmr' });\n private readonly listeners = new Set<HmrAware>();\n\n /** @internal */\n public init(): void {\n if (!import.meta.hot) return;\n // the only raw `import.meta.hot` read in the framework\n const channel = wrapHot<SeedcordFrameworkEvents, SeedcordCliEvents>(import.meta.hot);\n setDevChannel(channel);\n\n if (Envapter.isDevelopment || Envapter.isTest) {\n this.logger.debug('Enabled');\n channel.on('seedcord:hmr', (payload) => void this.handleUpdate(payload));\n }\n }\n\n /** @internal */\n public register(listener: HmrAware): void {\n this.listeners.add(listener);\n }\n\n private async handleUpdate(event: HmrUpdateEvent): Promise<void> {\n const promises = [...this.listeners].map(async (listener) => {\n try {\n await listener.onHmr(event);\n } catch (error) {\n this.logger.error(`Error handling HMR update in ${paint.sky.bold(listener.constructor.name)}`, error);\n }\n });\n\n await Promise.all(promises);\n }\n}\n","import { paint } from '@seedcord/errors';\nimport { Logger } from '@seedcord/logger';\nimport { timestampFromSnowflake } from '@seedcord/utils';\n\nimport { Notice } from '#stops/Notice';\nimport { Silence } from '#stops/Silence';\nimport { PublishDefault } from '#subscribers/publishDefault';\n\nimport type { InteractionRoutes } from '#src/metadataKeys';\nimport type { Bus } from '#subscribers/Bus';\nimport type { DispatchOutcome } from '#subscribers/types/Subscriptions';\n\nlet dispatchLogger: Logger | undefined;\nfunction logger(): Logger {\n dispatchLogger ??= new Logger('Dispatch', { channel: 'interactions' });\n return dispatchLogger;\n}\n\n/**\n * Classifies a caught stop for `interactionDispatched` so a gate and a\n * handler label the same stop identically.\n *\n * @internal\n */\nexport function outcomeFor(caught: unknown): DispatchOutcome {\n if (caught instanceof Silence) return 'refused';\n if (caught instanceof Notice) return caught.report ? 'failed' : 'refused';\n return 'failed';\n}\n\n/** The values a dispatcher has once its handler chain settles. */\ninterface DispatchReport {\n readonly routeId: string;\n readonly interactionId: string;\n readonly kind: `${InteractionRoutes}`;\n readonly outcome: DispatchOutcome;\n /** True when no route matched and the unhandled default ran. */\n readonly fallback: boolean;\n /** `performance.now()` captured as the dispatch began. */\n readonly startedAt: number;\n /** {@link queuedMsFor} read at the same moment as `startedAt`. */\n readonly queuedMs: number;\n}\n\n/**\n * Discord's interaction creation to now, read from the snowflake. Called at dispatch entry, since\n * a later read would count the handler run into the queue time as well.\n *\n * @internal\n */\nexport function queuedMsFor(interactionId: string): number {\n // telemetry never breaks a dispatch, and BigInt() throws on a malformed id\n try {\n return Date.now() - timestampFromSnowflake(interactionId);\n } catch {\n return 0;\n }\n}\n\nexport function reportDispatch(bus: Bus, report: DispatchReport): void {\n const durationMs = performance.now() - report.startedAt;\n bus[PublishDefault]('interactionDispatched', {\n routeId: report.routeId,\n interactionId: report.interactionId,\n kind: report.kind,\n outcome: report.outcome,\n fallback: report.fallback,\n durationMs,\n queuedMs: report.queuedMs\n });\n\n // after publish so a throwing sink doesn't reach the publish above\n logger().trace(\n `${paint.sky.bold(report.routeId)} ${report.outcome} ${paint.mute('in')} ${Math.round(durationMs)}ms`\n );\n}\n"],"mappings":";;;;;;;;;;;;AAGA,MAAa,kBAAiC,OAAO,2BAA2B;AAChF,MAAa,yBAAwC,O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