* refactor: move Discord channel implementation to extensions/discord/src/ Move all Discord source files from src/discord/ to extensions/discord/src/, following the extension migration pattern. Source files in src/discord/ are replaced with re-export shims. Channel-plugin files from src/channels/plugins/*/discord* are similarly moved and shimmed. - Copy all .ts source files preserving subdirectory structure (monitor/, voice/) - Move channel-plugin files (actions, normalize, onboarding, outbound, status-issues) - Fix all relative imports to use correct paths from new location - Create re-export shims at original locations for backward compatibility - Delete test files from shim locations (tests live in extension now) - Update tsconfig.plugin-sdk.dts.json rootDir from "src" to "." to accommodate extension files outside src/ - Update write-plugin-sdk-entry-dts.ts to match new declaration output paths * fix: add importOriginal to thread-bindings session-meta mock for extensions test * style: fix formatting in thread-bindings lifecycle test
68 lines
1.9 KiB
TypeScript
68 lines
1.9 KiB
TypeScript
import type { EventEmitter } from "node:events";
|
|
import { logVerbose } from "../../../src/globals.js";
|
|
import type { RuntimeEnv } from "../../../src/runtime.js";
|
|
|
|
type GatewayEmitter = Pick<EventEmitter, "on" | "removeListener">;
|
|
|
|
const INFO_DEBUG_MARKERS = [
|
|
"WebSocket connection closed",
|
|
"Reconnecting with backoff",
|
|
"Attempting resume with backoff",
|
|
];
|
|
|
|
const shouldPromoteGatewayDebug = (message: string) =>
|
|
INFO_DEBUG_MARKERS.some((marker) => message.includes(marker));
|
|
|
|
const formatGatewayMetrics = (metrics: unknown) => {
|
|
if (metrics === null || metrics === undefined) {
|
|
return String(metrics);
|
|
}
|
|
if (typeof metrics === "string") {
|
|
return metrics;
|
|
}
|
|
if (typeof metrics === "number" || typeof metrics === "boolean" || typeof metrics === "bigint") {
|
|
return String(metrics);
|
|
}
|
|
try {
|
|
return JSON.stringify(metrics);
|
|
} catch {
|
|
return "[unserializable metrics]";
|
|
}
|
|
};
|
|
|
|
export function attachDiscordGatewayLogging(params: {
|
|
emitter?: GatewayEmitter;
|
|
runtime: RuntimeEnv;
|
|
}) {
|
|
const { emitter, runtime } = params;
|
|
if (!emitter) {
|
|
return () => {};
|
|
}
|
|
|
|
const onGatewayDebug = (msg: unknown) => {
|
|
const message = String(msg);
|
|
logVerbose(`discord gateway: ${message}`);
|
|
if (shouldPromoteGatewayDebug(message)) {
|
|
runtime.log?.(`discord gateway: ${message}`);
|
|
}
|
|
};
|
|
|
|
const onGatewayWarning = (warning: unknown) => {
|
|
logVerbose(`discord gateway warning: ${String(warning)}`);
|
|
};
|
|
|
|
const onGatewayMetrics = (metrics: unknown) => {
|
|
logVerbose(`discord gateway metrics: ${formatGatewayMetrics(metrics)}`);
|
|
};
|
|
|
|
emitter.on("debug", onGatewayDebug);
|
|
emitter.on("warning", onGatewayWarning);
|
|
emitter.on("metrics", onGatewayMetrics);
|
|
|
|
return () => {
|
|
emitter.removeListener("debug", onGatewayDebug);
|
|
emitter.removeListener("warning", onGatewayWarning);
|
|
emitter.removeListener("metrics", onGatewayMetrics);
|
|
};
|
|
}
|