Play Weksa speech artifacts in Discord voice

This commit is contained in:
Meta Vens 2026-06-12 18:16:09 +01:00
commit 0e0e1d3044
10 changed files with 857 additions and 2 deletions

View file

@ -111,6 +111,12 @@ const envSchema = z.object({
REPO_FACE_WEKSA_SPEECH_ENABLED: booleanFromEnv.default(false),
WEKSA_DAEMON_BASE_URL: z.string().url().default("http://127.0.0.1:8813"),
WEKSA_DAEMON_TIMEOUT_MS: z.coerce.number().int().positive().default(120000),
WEKSA_REPO_ROOT: z.string().min(1).default("E:/Projects/weksa"),
REPO_FACE_DISCORD_VOICE_ENABLED: booleanFromEnv.default(false),
REPO_FACE_DISCORD_VOICE_CHANNEL_ID: optionalNonEmptyString,
REPO_FACE_DISCORD_VOICE_OUTBOX_PATH: z.string().min(1).default(".voidbot/status/repo-face-voice-outbox.jsonl"),
REPO_FACE_DISCORD_VOICE_PLAYED_PATH: z.string().min(1).default(".voidbot/status/repo-face-voice-played.jsonl"),
REPO_FACE_DISCORD_VOICE_POLL_INTERVAL_MS: z.coerce.number().int().positive().default(5000),
BIFROST_ROOT: z.string().min(1).default("E:/Projects/Bifrost"),
BIFROST_DISCORD_CHANNEL_ID: optionalNonEmptyString,
REPO_FACE_HEARTBEATS_ENABLED: booleanFromEnv.default(false),
@ -190,6 +196,14 @@ export interface AppConfig {
enabled: boolean;
daemonBaseUrl: string;
timeoutMs: number;
repoRoot: string;
};
repoFaceDiscordVoice: {
enabled: boolean;
channelId?: string;
outboxPath: string;
playedPath: string;
pollIntervalMs: number;
};
bifrostRoot: string;
bifrostDiscordChannelId?: string;
@ -436,6 +450,14 @@ export function loadConfig(env: NodeJS.ProcessEnv = process.env): AppConfig {
enabled: parsed.REPO_FACE_WEKSA_SPEECH_ENABLED,
daemonBaseUrl: parsed.WEKSA_DAEMON_BASE_URL.replace(/\/+$/, ""),
timeoutMs: parsed.WEKSA_DAEMON_TIMEOUT_MS,
repoRoot: resolve(parsed.WEKSA_REPO_ROOT),
},
repoFaceDiscordVoice: {
enabled: parsed.REPO_FACE_DISCORD_VOICE_ENABLED,
channelId: parsed.REPO_FACE_DISCORD_VOICE_CHANNEL_ID,
outboxPath: resolve(parsed.REPO_FACE_DISCORD_VOICE_OUTBOX_PATH),
playedPath: resolve(parsed.REPO_FACE_DISCORD_VOICE_PLAYED_PATH),
pollIntervalMs: parsed.REPO_FACE_DISCORD_VOICE_POLL_INTERVAL_MS,
},
bifrostRoot: resolve(parsed.BIFROST_ROOT),
bifrostDiscordChannelId: parsed.BIFROST_DISCORD_CHANNEL_ID,

View file

@ -10,6 +10,7 @@ export * from "./repo-discord-identities";
export * from "./repo-face-heartbeat-queue";
export * from "./repo-face-initializer";
export * from "./repo-face-rest";
export * from "./repo-face-voice-outbox";
export * from "./situational-social-read";
export * from "./state-storage";
export * from "./style-pack-loader";

View file

@ -0,0 +1,104 @@
import { appendFile, mkdir, readFile } from "node:fs/promises";
import { dirname, resolve } from "node:path";
export interface RepoFaceVoiceOutboxEntry {
schemaVersion: "voidbot.repo_face_voice_outbox.v1";
id: string;
createdAt: string;
identityId: string;
displayName: string;
repoName: string;
textChannelId: string;
textMessageId: string;
replyToMessageId?: string;
contentPreview: string;
weksaRequestId?: string;
weksaReceiptArtifact?: string;
audioPath: string;
audioBytes?: number;
}
export async function appendRepoFaceVoiceOutboxEntry(
outboxPath: string,
entry: RepoFaceVoiceOutboxEntry,
): Promise<void> {
await mkdir(dirname(outboxPath), { recursive: true });
await appendFile(outboxPath, `${JSON.stringify(entry)}\n`, "utf8");
}
export async function loadRepoFaceVoiceOutboxEntries(
outboxPath: string,
): Promise<RepoFaceVoiceOutboxEntry[]> {
const content = await readFile(outboxPath, "utf8").catch((error: NodeJS.ErrnoException) => {
if (error.code === "ENOENT") {
return "";
}
throw error;
});
return content
.split(/\r?\n/)
.map((line) => line.trim())
.filter(Boolean)
.flatMap((line) => {
try {
const parsed = JSON.parse(line) as RepoFaceVoiceOutboxEntry;
return parsed.schemaVersion === "voidbot.repo_face_voice_outbox.v1" &&
typeof parsed.id === "string" &&
typeof parsed.audioPath === "string"
? [parsed]
: [];
} catch {
return [];
}
});
}
export async function appendRepoFaceVoicePlayedEntry(
playedPath: string,
entry: RepoFaceVoiceOutboxEntry,
): Promise<void> {
await mkdir(dirname(playedPath), { recursive: true });
await appendFile(
playedPath,
`${JSON.stringify({
schemaVersion: "voidbot.repo_face_voice_played.v1",
id: entry.id,
playedAt: new Date().toISOString(),
identityId: entry.identityId,
textMessageId: entry.textMessageId,
audioPath: entry.audioPath,
})}\n`,
"utf8",
);
}
export async function loadRepoFaceVoicePlayedIds(playedPath: string): Promise<Set<string>> {
const content = await readFile(playedPath, "utf8").catch((error: NodeJS.ErrnoException) => {
if (error.code === "ENOENT") {
return "";
}
throw error;
});
const ids = new Set<string>();
for (const line of content.split(/\r?\n/)) {
if (!line.trim()) {
continue;
}
try {
const parsed = JSON.parse(line) as { id?: string };
if (typeof parsed.id === "string") {
ids.add(parsed.id);
}
} catch {
continue;
}
}
return ids;
}
export function resolveWeksaArtifactPath(weksaRepoRoot: string, artifactPath: string | undefined): string | undefined {
if (!artifactPath) {
return undefined;
}
return resolve(weksaRepoRoot, artifactPath);
}