import { resolveLivePluginConfigObject } from "openclaw/plugin-sdk/config-runtime"; import { normalizeOptionalString } from "openclaw/plugin-sdk/text-runtime"; import {
definePluginEntry,
fetchWithSsrFGuard,
ssrfPolicyFromDangerouslyAllowPrivateNetwork,
type OpenClawConfig,
type OpenClawPluginApi,
} from "./api.js";
type ThreadOwnershipConfig = {
forwarderUrl?: string;
abTestChannels?: string[];
};
type AgentEntry = NonNullable<NonNullable<OpenClawConfig["agents"]>["list"]>[number];
type ThreadOwnershipMessageSendingResult = { cancel: true } | undefined;
// In-memory set of {channel}:{thread} keys where this agent was @-mentioned. // Entries expire after 5 minutes. const mentionedThreads = new Map<string, number>(); const MENTION_TTL_MS = 5 * 60 * 1000;
function isThreadOwnershipConfig(value: unknown): value is ThreadOwnershipConfig { return value !== null && typeof value === "object";
}
function resolveThreadToken(value: unknown): string { returntypeof value === "string" || typeof value === "number" ? String(value) : "";
}
function escapeRegExp(value: string): string { return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
function resolveSlackConversationId(value: unknown): string { const raw = normalizeOptionalString(value) ?? ""; if (!raw) { return"";
} const trimmed = raw.trim(); const match = /^(?:slack:)?channel:(.+)$/i.exec(trimmed); const resolved = match?.[1]?.trim() || trimmed; return /^[CDGUW][A-Z0-9]+$/i.test(resolved) ? resolved.toUpperCase() : resolved;
}
function cleanExpiredMentions(): void { const now = Date.now(); for (const [key, ts] of mentionedThreads) { if (now - ts > MENTION_TTL_MS) {
mentionedThreads.delete(key);
}
}
}
function containsAgentNameMention(text: string, agentName: string): boolean { const trimmedName = agentName.trim(); if (!trimmedName) { returnfalse;
} returnnew RegExp(`(^|[^\\w])@${escapeRegExp(trimmedName)}(?=$|[^\\w])`, "i").test(text);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.