Consume Epiphany operator deliveries safely

This commit is contained in:
Meta Vens 2026-07-19 13:17:51 +01:00
commit a21d173ec0
11 changed files with 480 additions and 4 deletions

View file

@ -24,6 +24,7 @@ import {
loadFaceIdentityRegistry,
queueRepoFaceMention,
exportPersonaFeedbackObservation,
registerEpiphanyOperatorInteraction,
submitEpiphanyOperatorRequest,
type RepoDiscordIdentity,
stripRepoIdentityTextAddress,
@ -66,6 +67,7 @@ import {
} from "./discord-bot-handlers";
import { maybeMirrorOwnerAquariumMessageAsMetameVoice } from "./metame-owner-voice-bridge";
import { startRepoFaceVoicePlayback } from "./repo-face-voice-playback";
import { startEpiphanyOperatorDeliveryConsumer } from "./epiphany-operator-delivery-consumer";
import {
buildActorFromInteraction,
buildActorFromMessage,
@ -342,6 +344,15 @@ export async function startBot(): Promise<void> {
console.log(`VoidBot connected as ${readyClient.user.tag}.`);
await maybeRegisterCommands(config.botToken!, config.applicationId, config.developmentGuildId);
startRepoFaceVoicePlayback(readyClient, config.repoFaceDiscordVoice);
startEpiphanyOperatorDeliveryConsumer({
applicationId: readyClient.application.id,
requestStorePath: config.bifrostEpiphanyOperatorRequestStorePath,
deliveryStorePath: config.bifrostEpiphanyOperatorDeliveryStorePath,
checkpointStorePath: config.epiphanyOperatorDeliveryCheckpointStorePath,
bifrostRoot: config.bifrostRoot,
cultlibRoot: process.env.VOIDBOT_CULTLIB_ROOT,
pollIntervalMs: config.epiphanyOperatorDeliveryPollIntervalMs,
});
});
client.on(Events.MessageCreate, async (message) => {
@ -582,6 +593,26 @@ export async function startBot(): Promise<void> {
);
break;
}
const issuedAt = new Date().toISOString();
await registerEpiphanyOperatorInteraction(
{
requestId: interaction.id,
applicationId: interaction.applicationId,
interactionToken: interaction.token,
guildId: interaction.guildId,
channelId: interaction.channelId,
registeredAt: issuedAt,
},
{
checkpointStorePath: config.epiphanyOperatorDeliveryCheckpointStorePath,
bifrostRoot: config.bifrostRoot,
cultlibRoot: process.env.VOIDBOT_CULTLIB_ROOT,
},
);
await replyEphemeral(
interaction,
`Epiphany operator request \`${interaction.id}\` is pending Bifrost admission. This request grants no Mind, Hands, release, deployment, or local execution authority.`,
);
const request = await submitEpiphanyOperatorRequest(
{
interactionId: interaction.id,
@ -589,6 +620,7 @@ export async function startBot(): Promise<void> {
guildId: interaction.guildId,
channelId: interaction.channelId,
command: epiphanyOperatorCommandFromInteraction(interaction),
issuedAt,
},
{
storePath: config.bifrostEpiphanyOperatorRequestStorePath,
@ -597,10 +629,7 @@ export async function startBot(): Promise<void> {
producerRuntimeId: "voidbot-yggdrasil",
},
);
await replyEphemeral(
interaction,
`Epiphany operator request \`${request.requestId}\` is pending Bifrost admission. This request grants no Mind, Hands, release, deployment, or local execution authority.`,
);
if (request.requestId !== interaction.id) throw new Error("Epiphany request identity changed after interaction registration.");
break;
}
case "ask":

View file

@ -0,0 +1,48 @@
import { consumeEpiphanyOperatorDeliveries } from "@voidbot/core";
export interface EpiphanyOperatorDeliveryConsumerConfig {
applicationId: string;
requestStorePath: string;
deliveryStorePath: string;
checkpointStorePath: string;
bifrostRoot: string;
cultlibRoot?: string;
pollIntervalMs: number;
}
export function startEpiphanyOperatorDeliveryConsumer(config: EpiphanyOperatorDeliveryConsumerConfig): void {
let running = false;
const pulse = async (): Promise<void> => {
if (running) return;
running = true;
try {
const result = await consumeEpiphanyOperatorDeliveries(
{
requestStorePath: config.requestStorePath,
deliveryStorePath: config.deliveryStorePath,
checkpointStorePath: config.checkpointStorePath,
bifrostRoot: config.bifrostRoot,
cultlibRoot: config.cultlibRoot,
},
async (applicationId, interactionToken, content) => {
if (applicationId !== config.applicationId) throw new Error("interaction application binding mismatch");
const response = await fetch(
`https://discord.com/api/v10/webhooks/${encodeURIComponent(applicationId)}/${encodeURIComponent(interactionToken)}/messages/@original`,
{
method: "PATCH",
headers: { "content-type": "application/json" },
body: JSON.stringify({ content }),
},
);
if (!response.ok) throw new Error(`Discord interaction edit failed with HTTP ${response.status}`);
},
);
if (result.failed > 0) console.error("Epiphany operator delivery pulse retained failures for retry:", result);
} catch (error) {
console.error("Epiphany operator delivery pulse failed without acknowledging deliveries:", error);
} finally { running = false; }
};
void pulse();
const timer = setInterval(() => void pulse(), config.pollIntervalMs);
timer.unref?.();
}