Unify typed agent transport and shared state

This commit is contained in:
Meta Vens 2026-07-15 20:23:41 +01:00
commit c4376ee129
23 changed files with 1434 additions and 538 deletions

View file

@ -12,7 +12,7 @@ export function buildVoidMcpServerConfig(workspaceRoot: string): CodexMcpServerC
cwd: workspaceRoot,
env: {
VOIDBOT_WORKSPACE_ROOT: workspaceRoot,
...(process.env.ODIN_BASE_URL ? { ODIN_BASE_URL: process.env.ODIN_BASE_URL } : {}),
...(process.env.ODIN_CULTMESH_STORE ? { ODIN_CULTMESH_STORE: process.env.ODIN_CULTMESH_STORE } : {}),
},
};
}

View file

@ -11,6 +11,7 @@ export * from "./repo-face-heartbeat-queue";
export * from "./repo-face-response-pressure";
export * from "./repo-face-initializer";
export * from "./repo-face-rest";
export * from "./repo-face-shared-documents";
export * from "./repo-face-voice-presence";
export * from "./repo-face-voice-outbox";
export * from "./situational-social-read";

View file

@ -0,0 +1,112 @@
import { resolve } from "node:path";
import {
CultCache,
SingleFileMessagePackBackingStore,
defineDocumentRegistry,
defineDocumentType,
} from "cultcache-ts";
import { z } from "zod";
const nonEmpty = z.string().trim().min(1);
const documentSchema = z.object({
documentId: nonEmpty.max(120),
title: nonEmpty.max(240),
body: z.string().max(20_000),
version: z.number().int().positive(),
createdBy: nonEmpty.max(120),
createdAt: nonEmpty,
updatedBy: nonEmpty.max(120),
updatedAt: nonEmpty,
}).strict();
export type RepoFaceSharedDocument = z.infer<typeof documentSchema>;
const documentDefinition = defineDocumentType({
type: "voidbot.repo_face.shared_document",
schema: documentSchema,
name: "documentId",
});
const registry = defineDocumentRegistry(documentDefinition);
export function resolveRepoFaceSharedDocumentsPath(storageRoot: string): string {
return resolve(storageRoot, "private", "repo-face-shared-documents.cc");
}
export async function listRepoFaceSharedDocuments(canonicalPath: string): Promise<RepoFaceSharedDocument[]> {
const cache = createCache(canonicalPath);
await cache.pullAllBackingStores();
return cache.getAll(documentDefinition).sort((left, right) => left.documentId.localeCompare(right.documentId));
}
export async function createRepoFaceSharedDocument(input: {
canonicalPath: string;
documentId: string;
title: string;
body: string;
actorId: string;
now?: string;
}): Promise<RepoFaceSharedDocument> {
const documentId = normalizeDocumentId(input.documentId);
const cache = createCache(input.canonicalPath);
await cache.pullAllBackingStores();
if (cache.get(documentDefinition, documentId)) {
throw new Error(`Shared document "${documentId}" already exists; update it instead.`);
}
const now = input.now ?? new Date().toISOString();
const document = documentSchema.parse({
documentId,
title: input.title,
body: input.body,
version: 1,
createdBy: input.actorId,
createdAt: now,
updatedBy: input.actorId,
updatedAt: now,
});
return cache.put(documentDefinition, documentId, document);
}
export async function updateRepoFaceSharedDocument(input: {
canonicalPath: string;
documentId: string;
title?: string;
body: string;
expectedVersion: number;
actorId: string;
now?: string;
}): Promise<RepoFaceSharedDocument> {
const documentId = normalizeDocumentId(input.documentId);
const cache = createCache(input.canonicalPath);
await cache.pullAllBackingStores();
const existing = cache.get(documentDefinition, documentId);
if (!existing) {
throw new Error(`Shared document "${documentId}" does not exist; create it first.`);
}
if (existing.version !== input.expectedVersion) {
throw new Error(
`Shared document "${documentId}" is at version ${existing.version}, not expected version ${input.expectedVersion}.`,
);
}
const document = documentSchema.parse({
...existing,
title: input.title ?? existing.title,
body: input.body,
version: existing.version + 1,
updatedBy: input.actorId,
updatedAt: input.now ?? new Date().toISOString(),
});
return cache.put(documentDefinition, documentId, document);
}
function createCache(canonicalPath: string): CultCache {
return CultCache.builder()
.withRegistry(registry)
.withGenericStore(new SingleFileMessagePackBackingStore(resolve(canonicalPath)))
.build();
}
function normalizeDocumentId(value: string): string {
const normalized = value.trim().toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "");
return nonEmpty.max(120).parse(normalized);
}

View file

@ -1,5 +1,6 @@
export interface WeksaSpeechClientOptions {
baseUrl: string;
commandUri: string;
repoRoot: string;
timeoutMs: number;
}
@ -42,69 +43,23 @@ export interface WeksaMimoReceipt {
}
export class WeksaSpeechClient {
private readonly baseUrl: string;
private readonly commandUri: string;
private readonly repoRoot: string;
private readonly timeoutMs: number;
constructor(options: WeksaSpeechClientOptions) {
this.baseUrl = options.baseUrl.replace(/\/+$/, "");
this.commandUri = options.commandUri;
this.repoRoot = options.repoRoot;
this.timeoutMs = options.timeoutMs;
}
async renderRepoFaceSpeech(input: WeksaRepoFaceSpeechInput): Promise<WeksaMimoReceipt> {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
try {
const response = await fetch(`${this.baseUrl}/speech-provider/mimo/voicedesign`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
signal: controller.signal,
body: JSON.stringify({
request_id: input.requestId ?? buildRequestId(input),
persona_state_path: input.personaStatePath,
speaker_agent_id: input.identityId,
thought_text: input.content,
spoken_text: input.content,
scene: input.scene ?? `Discord channel ${input.channelId}`,
addressee: input.addressee ?? "Discord room",
intent: input.content,
performance_register: input.performanceRegister ?? {
label: `${input.displayName} Discord voice`,
medium: "Discord voice channel playback",
delivery_archetype: `${input.displayName} speaks an approved VoidBot SAY line`,
},
delivery_controls: input.deliveryControls ?? [
"Discord-room conversational delivery",
"preserve the approved text exactly",
`repo Face for ${input.repoName}`,
],
forbidden_traits: input.forbiddenTraits ?? [
"generic assistant voice",
"rewriting source meaning",
"changing the approved Discord text",
],
voice_design_prompt: input.voiceDesignPrompt,
private_interpretation: input.privateInterpretation ??
"VoidBot already approved this SAY line for public text delivery; Weksa is only projecting it into spoken audio.",
intended_effect: input.intendedEffect ??
"Make the approved public Discord line audible without changing its meaning.",
}),
});
const text = await response.text();
if (!response.ok) {
throw new Error(`Weksa speech request failed with ${response.status}: ${text}`);
}
return JSON.parse(text) as WeksaMimoReceipt;
} catch (error) {
if (error instanceof Error && error.name === "AbortError") {
throw new Error(`Weksa speech request timed out after ${this.timeoutMs}ms.`);
}
throw error;
} finally {
clearTimeout(timeout);
}
const requestId = input.requestId ?? buildRequestId(input);
void this.repoRoot;
void this.timeoutMs;
throw new Error(
`Weksa speech command ${requestId} requires CultMesh command document publication to ${this.commandUri}; the legacy direct sender has been removed.`,
);
}
}