From 0b624cb3b175eb97878b9079982612c7b5ea1140 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Mon, 18 May 2026 00:50:47 +0100 Subject: [PATCH] Resolve persona avatar URLs --- .env.example | 4 ++++ apps/worker/src/mcp-server-discord.ts | 31 ++++++++++++++++++++++---- scripts/send-discord-message.mjs | 32 ++++++++++++++++++++++----- state/evidence.jsonl | 1 + 4 files changed, 58 insertions(+), 10 deletions(-) diff --git a/.env.example b/.env.example index 0dabfee..80bf3be 100644 --- a/.env.example +++ b/.env.example @@ -8,6 +8,10 @@ DISCORD_BOT_TRIGGER_ROLE_IDS= # needs Manage Webhooks in the target channel to create its own cached webhook. # DISCORD_PERSONA_WEBHOOK_URL_=https://discord.com/api/webhooks// DISCORD_PERSONA_WEBHOOK_URL= +# Optional default persona avatars. Per-persona keys use the uppercased +# persona name with non-alphanumeric characters replaced by underscores. +# DISCORD_PERSONA_AVATAR_URL_VOID=https://cdn.discordapp.com/avatars//.png?size=256 +DISCORD_PERSONA_AVATAR_URL= STATE_STORAGE_BACKEND=postgres DATABASE_DSN=postgres://voidbot:voidbot@localhost:5432/voidbot # Leave this as local_json until Qdrant is running and you've migrated the existing vectors. diff --git a/apps/worker/src/mcp-server-discord.ts b/apps/worker/src/mcp-server-discord.ts index f2cd8b4..2e77c51 100644 --- a/apps/worker/src/mcp-server-discord.ts +++ b/apps/worker/src/mcp-server-discord.ts @@ -366,9 +366,8 @@ function normalizePersonaOptions( options?: DiscordPersonaOptions, ): NormalizedDiscordPersonaOptions | undefined { const personaName = trimOptionalString(options?.personaName); - const personaAvatarUrl = trimOptionalString(options?.personaAvatarUrl); - if (!personaName && !personaAvatarUrl) { + if (!personaName && !trimOptionalString(options?.personaAvatarUrl)) { return undefined; } @@ -376,12 +375,36 @@ function normalizePersonaOptions( throw new Error("personaName is required when posting through the shared persona webhook pipe."); } + const normalizedPersonaName = personaName.slice(0, 80); + return { - personaName: personaName.slice(0, 80), - personaAvatarUrl, + personaName: normalizedPersonaName, + personaAvatarUrl: resolvePersonaAvatarUrl(options, normalizedPersonaName), }; } +function resolvePersonaAvatarUrl( + options: DiscordPersonaOptions | undefined, + personaName: string, +): string | undefined { + const explicitAvatarUrl = trimOptionalString(options?.personaAvatarUrl); + + if (explicitAvatarUrl) { + return explicitAvatarUrl; + } + + const personaKey = `DISCORD_PERSONA_AVATAR_URL_${toEnvKeySuffix(personaName)}`; + return trimOptionalString(process.env[personaKey]) ?? trimOptionalString(process.env.DISCORD_PERSONA_AVATAR_URL); +} + +function toEnvKeySuffix(value: string): string { + return value + .trim() + .toUpperCase() + .replace(/[^A-Z0-9]+/g, "_") + .replace(/^_+|_+$/g, ""); +} + function trimOptionalString(value?: string): string | undefined { return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined; } diff --git a/scripts/send-discord-message.mjs b/scripts/send-discord-message.mjs index 6d39f31..7bd548a 100644 --- a/scripts/send-discord-message.mjs +++ b/scripts/send-discord-message.mjs @@ -15,7 +15,7 @@ async function main() { const options = parseArgs(process.argv.slice(2)); const env = readLocalEnv(); const botToken = env.DISCORD_BOT_TOKEN?.trim(); - const persona = normalizePersonaOptions(options); + const persona = normalizePersonaOptions(options, env); if (!botToken) { throw new Error("DISCORD_BOT_TOKEN is required."); @@ -502,11 +502,10 @@ async function executePersonaWebhook( } } -function normalizePersonaOptions(options) { +function normalizePersonaOptions(options, env) { const personaName = trimOptionalString(options.personaName); - const personaAvatarUrl = trimOptionalString(options.personaAvatarUrl); - if (!personaName && !personaAvatarUrl) { + if (!personaName && !trimOptionalString(options.personaAvatarUrl)) { return undefined; } @@ -514,12 +513,33 @@ function normalizePersonaOptions(options) { throw new Error("personaName is required when using the shared persona webhook pipe."); } + const normalizedPersonaName = personaName.slice(0, 80); + return { - personaName: personaName.slice(0, 80), - personaAvatarUrl, + personaName: normalizedPersonaName, + personaAvatarUrl: resolvePersonaAvatarUrl(options, env, normalizedPersonaName), }; } +function resolvePersonaAvatarUrl(options, env, personaName) { + const explicitAvatarUrl = trimOptionalString(options.personaAvatarUrl); + + if (explicitAvatarUrl) { + return explicitAvatarUrl; + } + + const personaKey = `DISCORD_PERSONA_AVATAR_URL_${toEnvKeySuffix(personaName)}`; + return trimOptionalString(env[personaKey]) ?? trimOptionalString(env.DISCORD_PERSONA_AVATAR_URL); +} + +function toEnvKeySuffix(value) { + return value + .trim() + .toUpperCase() + .replace(/[^A-Z0-9]+/g, "_") + .replace(/^_+|_+$/g, ""); +} + function trimOptionalString(value) { return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined; } diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 164414d..9b51e14 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -126,3 +126,4 @@ {"ts":"2026-05-17T18:47:03Z","type":"implementation","status":"ok","note":"Closed the stranded-candidate speech gap. Metacrat's explicit channel permission was observed at 2026-05-17T18:15:24Z, but rumination queued the AquariumSynthHost draft as deferred with no delivery target, then nap skip left it unsent. The runner now treats deferred candidates as unresolved pressure, delivers existing queued candidates with delivery targets, and the stranded candidate was repaired to the permitted channel and posted with a typed receipt."} {"ts":"2026-05-17T19:15:56Z","type":"implementation","status":"ok","note":"Live-loop inspection complaints resolved: candidate speech receipts now link back to the spoken intervention, rumination report text is refreshed by the runner, watchdog Repixelizer SSH checks no longer hang indefinitely, and offsite sync recovered with a fresh remote archive."} {"ts":"2026-05-17T22:41:56Z","type":"implementation","status":"ok","note":"Persona webhook delivery now supports configured per-channel webhook URLs and preserves Discord failure details in the parent rumination runner; live probe confirms current #general blocker is Discord 403 Missing Permissions unless Manage Webhooks is granted or DISCORD_PERSONA_WEBHOOK_URL_113786069023064068 is configured."} +{"ts":"2026-05-17T23:50:11Z","type":"implementation","status":"ok","note":"Persona webhook delivery now resolves avatar URLs from per-persona env keys such as DISCORD_PERSONA_AVATAR_URL_VOID, falling back to DISCORD_PERSONA_AVATAR_URL; live Void probe used the bot's Discord CDN avatar without an explicit operation-level avatar URL."}