refactor: trim discord monitor helper exports

This commit is contained in:
Peter Steinberger
2026-05-01 16:14:58 +01:00
parent bce729f6ab
commit b7fd104a8b
31 changed files with 43 additions and 53 deletions

View File

@@ -19,7 +19,7 @@ export type DiscordAllowList = {
names: Set<string>;
};
export type DiscordAllowListMatch = AllowlistMatch<"wildcard" | "id" | "name" | "tag">;
type DiscordAllowListMatch = AllowlistMatch<"wildcard" | "id" | "name" | "tag">;
const DISCORD_OWNER_ALLOWLIST_PREFIXES = ["discord:", "user:", "pk:"];
@@ -149,7 +149,7 @@ export function resolveDiscordAllowListMatch(params: {
return { allowed: false };
}
export function resolveDiscordUserAllowed(params: {
function resolveDiscordUserAllowed(params: {
allowList?: string[];
userId: string;
userName?: string;
@@ -500,7 +500,7 @@ export function resolveDiscordShouldRequireMention(params: {
return params.channelConfig?.requireMention ?? params.guildInfo?.requireMention ?? true;
}
export function isDiscordAutoThreadOwnedByBot(params: {
function isDiscordAutoThreadOwnedByBot(params: {
isThread: boolean;
channelConfig?: DiscordChannelConfigResolved | null;
botId?: string | null;

View File

@@ -21,7 +21,7 @@ const DEFAULT_MIN_UPDATE_INTERVAL_MS = 15_000;
const MIN_INTERVAL_MS = 5_000;
const MIN_UPDATE_INTERVAL_MS = 1_000;
export type DiscordAutoPresenceState = "healthy" | "degraded" | "exhausted";
type DiscordAutoPresenceState = "healthy" | "degraded" | "exhausted";
type ResolvedDiscordAutoPresenceConfig = {
enabled: boolean;
@@ -32,7 +32,7 @@ type ResolvedDiscordAutoPresenceConfig = {
exhaustedText?: string;
};
export type DiscordAutoPresenceDecision = {
type DiscordAutoPresenceDecision = {
state: DiscordAutoPresenceState;
unavailableReason?: AuthProfileFailureReason | null;
presence: UpdatePresenceData;
@@ -256,7 +256,7 @@ function stablePresenceSignature(payload: UpdatePresenceData): string {
});
}
export type DiscordAutoPresenceController = {
type DiscordAutoPresenceController = {
start: () => void;
stop: () => void;
refresh: () => void;

View File

@@ -28,7 +28,7 @@ function resolveDiscordChannelNumberPropertySafe(
return typeof value === "number" ? value : undefined;
}
export type DiscordChannelInfoSafe = {
type DiscordChannelInfoSafe = {
name?: string;
topic?: string;
type?: number;

View File

@@ -51,7 +51,7 @@ export function parseExecApprovalData(
};
}
export type ExecApprovalButtonContext = {
type ExecApprovalButtonContext = {
getApprovers: () => string[];
resolveApproval: (
approvalId: string,

View File

@@ -10,7 +10,7 @@ export type DiscordGatewayHandle = Pick<GatewayPlugin, "disconnect"> & {
type GatewaySocketListener = (...args: unknown[]) => void;
export type DiscordGatewaySocket = {
type DiscordGatewaySocket = {
on: (event: "close" | "error", listener: GatewaySocketListener) => unknown;
listeners: (event: "close" | "error") => GatewaySocketListener[];
removeListener: (event: "close" | "error", listener: GatewaySocketListener) => unknown;

View File

@@ -16,7 +16,7 @@ const MAX_DISCORD_GATEWAY_INFO_TIMEOUT_MS = 120_000;
const DISCORD_GATEWAY_INFO_TIMEOUT_ENV = "OPENCLAW_DISCORD_GATEWAY_INFO_TIMEOUT_MS";
const DISCORD_GATEWAY_METADATA_FALLBACK_LOG_INTERVAL_MS = 60_000;
export type DiscordGatewayMetadataResponse = Pick<Response, "ok" | "status" | "text">;
type DiscordGatewayMetadataResponse = Pick<Response, "ok" | "status" | "text">;
export type DiscordGatewayFetchInit = Record<string, unknown> & {
headers?: Record<string, string>;
};

View File

@@ -3,11 +3,7 @@ import { danger } from "openclaw/plugin-sdk/runtime-env";
import type { RuntimeEnv } from "openclaw/plugin-sdk/runtime-env";
import { formatErrorMessage } from "openclaw/plugin-sdk/ssrf-runtime";
export type DiscordGatewayEventType =
| "disallowed-intents"
| "fatal"
| "other"
| "reconnect-exhausted";
type DiscordGatewayEventType = "disallowed-intents" | "fatal" | "other" | "reconnect-exhausted";
export type DiscordGatewayEvent = {
type: DiscordGatewayEventType;

View File

@@ -9,7 +9,7 @@ import {
type DiscordGuildEntryResolved,
} from "./allow-list.js";
export type DiscordSupplementalContextSender = {
type DiscordSupplementalContextSender = {
id?: string;
name?: string;
tag?: string;

View File

@@ -14,15 +14,9 @@ type DiscordInboundJobRuntimeField =
| "threadBindings"
| "discordRestFetch";
export type DiscordInboundJobRuntime = Pick<
DiscordMessagePreflightContext,
DiscordInboundJobRuntimeField
>;
type DiscordInboundJobRuntime = Pick<DiscordMessagePreflightContext, DiscordInboundJobRuntimeField>;
export type DiscordInboundJobPayload = Omit<
DiscordMessagePreflightContext,
DiscordInboundJobRuntimeField
>;
type DiscordInboundJobPayload = Omit<DiscordMessagePreflightContext, DiscordInboundJobRuntimeField>;
export type DiscordInboundJob = {
queueKey: string;

View File

@@ -25,7 +25,7 @@ export function isBoundThreadBotSystemMessage(params: {
return DISCORD_BOUND_THREAD_SYSTEM_PREFIXES.some((prefix) => text.startsWith(prefix));
}
export type BoundThreadLookupRecordLike = {
type BoundThreadLookupRecordLike = {
webhookId?: string | null;
metadata?: {
webhookId?: string | null;

View File

@@ -6,7 +6,7 @@ import {
import type { DiscordMessagePreflightContext } from "./message-handler.preflight.types.js";
import type { DiscordChannelInfo } from "./message-utils.js";
export type DiscordPreflightThreadContext = {
type DiscordPreflightThreadContext = {
earlyThreadChannel: DiscordMessagePreflightContext["threadChannel"];
earlyThreadParentId?: string;
earlyThreadParentName?: string;

View File

@@ -11,7 +11,7 @@ import type { DiscordSenderIdentity } from "./sender-identity.js";
export type { DiscordSenderIdentity } from "./sender-identity.js";
import type { DiscordThreadChannel } from "./threading.js";
export type LoadedConfig = OpenClawConfig;
type LoadedConfig = OpenClawConfig;
export type RuntimeEnv = import("openclaw/plugin-sdk/runtime-env").RuntimeEnv;
export type DiscordMessageEvent = import("./listeners.js").DiscordMessageEvent;

View File

@@ -22,7 +22,7 @@ type DiscordMessageRunQueueParams = {
__testing?: DiscordMessageRunQueueTestingHooks;
};
export type DiscordMessageRunQueue = {
type DiscordMessageRunQueue = {
enqueue: (job: DiscordInboundJob) => void;
deactivate: () => void;
};

View File

@@ -4,7 +4,7 @@ import { resolveDiscordConversationIdentity } from "../conversation-identity.js"
import { type DiscordChannelConfigResolved, type DiscordGuildEntryResolved } from "./allow-list.js";
import { buildDiscordInboundAccessContext } from "./inbound-context.js";
export type BuildDiscordNativeCommandContextParams = {
type BuildDiscordNativeCommandContextParams = {
prompt: string;
commandArgs: CommandArgs;
sessionKey: string;

View File

@@ -15,13 +15,13 @@ import type { ThreadBindingManager } from "./thread-bindings.js";
type DiscordConfig = NonNullable<OpenClawConfig["channels"]>["discord"];
export type DiscordModelPickerSelectionCommand = {
type DiscordModelPickerSelectionCommand = {
prompt: string;
command: ChatCommandDefinition;
args?: CommandArgs;
};
export type DiscordModelPickerApplyResult =
type DiscordModelPickerApplyResult =
| { status: "success"; effectiveModelRef: string; noticeMessage: string }
| { status: "mismatch"; effectiveModelRef: string; noticeMessage: string }
| { status: "rejected"; noticeMessage: string }

View File

@@ -15,7 +15,7 @@ type ConfiguredBindingResolution = NonNullable<
NonNullable<ResolvedConfiguredBindingRoute>["bindingResolution"]
>;
export type DiscordNativeInteractionRouteState = {
type DiscordNativeInteractionRouteState = {
route: ResolvedAgentRoute;
effectiveRoute: ResolvedAgentRoute;
boundSessionKey?: string;

View File

@@ -7,7 +7,7 @@ type DiscordInteractionChannel = {
type?: ChannelType;
};
export type DiscordNativeInteractionChannelContext = {
type DiscordNativeInteractionChannelContext = {
channelType?: ChannelType;
isDirectMessage: boolean;
isGroupDm: boolean;

View File

@@ -2,7 +2,7 @@ import { logVerbose } from "openclaw/plugin-sdk/runtime-env";
import { summarizeStringEntries } from "openclaw/plugin-sdk/text-runtime";
import { formatThreadBindingDurationLabel } from "./thread-bindings.messages.js";
export function formatThreadBindingDurationForConfigLabel(durationMs: number): string {
function formatThreadBindingDurationForConfigLabel(durationMs: number): string {
const label = formatThreadBindingDurationLabel(durationMs);
return label === "disabled" ? "off" : label;
}

View File

@@ -5,7 +5,7 @@ import { RateLimitError } from "../internal/discord.js";
const DISCORD_DEPLOY_REJECTED_ENTRY_LIMIT = 3;
export type DiscordDeployErrorLike = {
type DiscordDeployErrorLike = {
status?: unknown;
statusCode?: unknown;
discordCode?: unknown;
@@ -19,7 +19,7 @@ export type DiscordDeployErrorLike = {
deployTimeoutMs?: unknown;
};
export type DiscordDeployRateLimitDetails = {
type DiscordDeployRateLimitDetails = {
status?: number;
retryAfterMs?: number;
scope?: string;

View File

@@ -117,7 +117,7 @@ function installDeployRestLogging(params: {
};
}
export async function deployDiscordCommands(params: {
async function deployDiscordCommands(params: {
client: Client;
runtime: RuntimeEnv;
enabled: boolean;

View File

@@ -1,7 +1,7 @@
import { isVerbose, type RuntimeEnv } from "openclaw/plugin-sdk/runtime-env";
import type { GatewayPlugin } from "../internal/gateway.js";
export function formatDiscordStartupGatewayState(gateway?: GatewayPlugin): string {
function formatDiscordStartupGatewayState(gateway?: GatewayPlugin): string {
if (!gateway) {
return "gateway=missing";
}

View File

@@ -54,7 +54,7 @@ function registerLatePlugin(client: Client, plugin: Plugin) {
}
}
export function createDiscordStatusReadyListener(params: {
function createDiscordStatusReadyListener(params: {
discordConfig: Parameters<typeof resolveDiscordPresenceUpdate>[0];
getAutoPresenceController: () => DiscordAutoPresenceController | null;
}): ReadyListener {

View File

@@ -2,7 +2,7 @@ import type { Guild, Message, User } from "../internal/discord.js";
import { resolveTimestampMs } from "./format.js";
import { resolveDiscordSenderIdentity } from "./sender-identity.js";
export type DiscordReplyContext = {
type DiscordReplyContext = {
id: string;
channelId: string;
sender: string;

View File

@@ -1,4 +1,4 @@
export type DiscordMonitorStatusPatch = {
type DiscordMonitorStatusPatch = {
connected?: boolean;
lastEventAt?: number | null;
lastTransportActivityAt?: number | null;

View File

@@ -61,7 +61,7 @@ function resolveEffectiveBindingExpiresAt(params: {
return inactivityExpiresAt ?? maxAgeExpiresAt;
}
export function toSessionBindingRecord(
function toSessionBindingRecord(
record: ThreadBindingRecord,
defaults: ThreadBindingDefaults,
): SessionBindingRecord {

View File

@@ -12,7 +12,7 @@ import {
} from "./message-utils.js";
import { resolveDiscordThreadParentInfo } from "./threading.js";
export type DiscordThreadLikeChannelContext = {
type DiscordThreadLikeChannelContext = {
channelType?: ChannelType;
isThreadChannel: boolean;
channelId: string;
@@ -25,7 +25,7 @@ export type DiscordThreadLikeChannelContext = {
channelInfo: DiscordChannelInfo | null;
};
export function isDiscordThreadChannelType(type: ChannelType | number | undefined): boolean {
function isDiscordThreadChannelType(type: ChannelType | number | undefined): boolean {
return (
type === ChannelType.PublicThread ||
type === ChannelType.PrivateThread ||

View File

@@ -28,12 +28,12 @@ export type DiscordThreadParentInfo = {
type?: ChannelType;
};
export type DiscordThreadStarterRestEmbed = {
type DiscordThreadStarterRestEmbed = {
title?: string | null;
description?: string | null;
};
export type DiscordThreadStarterRestSnapshotMessage = {
type DiscordThreadStarterRestSnapshotMessage = {
content?: string | null;
attachments?: APIAttachment[] | null;
embeds?: DiscordThreadStarterRestEmbed[] | null;

View File

@@ -1,11 +1,11 @@
import type { Readable } from "node:stream";
export type VoiceCaptureEntry = {
type VoiceCaptureEntry = {
generation: number;
stream: Readable;
};
export type VoiceCaptureFinalizeTimer = {
type VoiceCaptureFinalizeTimer = {
generation: number;
timer: ReturnType<typeof setTimeout>;
};

View File

@@ -14,7 +14,7 @@ export type VoiceReceiveRecoveryState = {
decryptRecoveryInFlight: boolean;
};
export type VoiceReceiveErrorAnalysis = {
type VoiceReceiveErrorAnalysis = {
message: string;
isAbortLike: boolean;
shouldAttemptPassthrough: boolean;
@@ -59,7 +59,7 @@ export function createVoiceReceiveRecoveryState(): VoiceReceiveRecoveryState {
};
}
export function isAbortLikeReceiveError(err: unknown): boolean {
function isAbortLikeReceiveError(err: unknown): boolean {
if (!err || typeof err !== "object") {
return false;
}

View File

@@ -4,7 +4,7 @@ import { formatDiscordUserTag } from "../monitor/format.js";
const SPEAKER_CONTEXT_CACHE_TTL_MS = 60_000;
export type VoiceSpeakerIdentity = {
type VoiceSpeakerIdentity = {
id: string;
label: string;
name?: string;
@@ -12,7 +12,7 @@ export type VoiceSpeakerIdentity = {
memberRoleIds: string[];
};
export type VoiceSpeakerContext = Omit<VoiceSpeakerIdentity, "memberRoleIds"> & {
type VoiceSpeakerContext = Omit<VoiceSpeakerIdentity, "memberRoleIds"> & {
senderIsOwner: boolean;
};

View File

@@ -11,7 +11,7 @@ import { normalizeOptionalString } from "openclaw/plugin-sdk/text-runtime";
import { getDiscordRuntime } from "../runtime.js";
import { sanitizeVoiceReplyTextForSpeech } from "./sanitize.js";
export type VoiceReplyAudioResult =
type VoiceReplyAudioResult =
| {
status: "ok";
audioPath: string;