Extract Persona turn actuator
This commit is contained in:
parent
7a0b49b3ed
commit
a7ac9b51e9
7 changed files with 113 additions and 34 deletions
|
|
@ -9,7 +9,6 @@ import { dirname, resolve } from "node:path";
|
|||
import { loadConfig } from "@voidbot/config";
|
||||
import {
|
||||
buildEpiphanyIdentityRegistry,
|
||||
ContextBuilder,
|
||||
createStateStorage,
|
||||
getRepoFaceSourceRepoName,
|
||||
getRepoDiscordIdentityAllowedChannelIds,
|
||||
|
|
@ -73,8 +72,7 @@ import {
|
|||
readBifrostGovernanceDigest,
|
||||
type BifrostGovernanceDigest,
|
||||
} from "../apps/persona-scheduler/dist/bifrost-governance-source.js";
|
||||
|
||||
const HEARTBEAT_COMMAND = "repo-face-rumination";
|
||||
import { submitPersonaTurn } from "../apps/persona-scheduler/dist/turn-actuator.js";
|
||||
|
||||
interface RepoFaceChannelPlan {
|
||||
primaryChannelId?: string;
|
||||
|
|
@ -410,7 +408,6 @@ async function queueRepoFaceTurn(input: {
|
|||
return { created: false, failureReason: "No CTB turn channel is configured for this Persona." };
|
||||
}
|
||||
|
||||
const contextBuilder = new ContextBuilder();
|
||||
const recentMessages = await fetchRecentDiscordMessages({
|
||||
botToken: input.config.botToken,
|
||||
channelId,
|
||||
|
|
@ -482,43 +479,23 @@ async function queueRepoFaceTurn(input: {
|
|||
pendingMentions: input.pendingMentions,
|
||||
});
|
||||
const repoFaceConversationFocus = repoFaceConversationThreads[0];
|
||||
const contextBundle = contextBuilder.build({
|
||||
prompt,
|
||||
actor: {
|
||||
id: "voidbot-agent-turn",
|
||||
displayName: "VoidBot Agent Turn",
|
||||
isAdmin: true,
|
||||
isBot: true,
|
||||
},
|
||||
guildContext: {
|
||||
channelId,
|
||||
},
|
||||
recentMessages,
|
||||
repoFaceConversationFocus,
|
||||
repoFaceConversationThreads,
|
||||
imageAttachments,
|
||||
retrieval: [],
|
||||
voidSelfState: undefined,
|
||||
});
|
||||
const requestMessageId = `agent-turn:${identity.id}:${input.queuedAt}`;
|
||||
const result = await input.storage.jobQueue.createJob({
|
||||
command: HEARTBEAT_COMMAND,
|
||||
const result = await submitPersonaTurn({
|
||||
jobQueue: input.storage.jobQueue,
|
||||
provider: input.config.repoFaceHeartbeats.provider,
|
||||
runApprovalRequired: false,
|
||||
postApprovalRequired: false,
|
||||
requester: contextBundle.actor,
|
||||
guildContext: contextBundle.guildContext,
|
||||
identityId: identity.id,
|
||||
queuedAt: input.queuedAt,
|
||||
channelId,
|
||||
prompt,
|
||||
contextBundle,
|
||||
outputChannelId: channelId,
|
||||
requestMessageId,
|
||||
initialState: "approved",
|
||||
recentMessages,
|
||||
conversationFocus: repoFaceConversationFocus,
|
||||
conversationThreads: repoFaceConversationThreads,
|
||||
imageAttachments,
|
||||
});
|
||||
|
||||
return {
|
||||
created: result.created,
|
||||
activeJobId: result.job.id,
|
||||
requestMessageId,
|
||||
activeJobId: result.activeJobId,
|
||||
requestMessageId: result.requestMessageId,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,10 @@ import { join } from "node:path";
|
|||
import {
|
||||
queueAgentHeartbeatMention,
|
||||
readRepoFaceMentionInbox,
|
||||
type CreateJobInput,
|
||||
type JobQueue,
|
||||
} from "@voidbot/core";
|
||||
import type { JobRecord } from "@voidbot/shared";
|
||||
|
||||
import {
|
||||
advanceInitiativeClockFromWallClock,
|
||||
|
|
@ -43,6 +46,7 @@ import {
|
|||
fetchRecentDiscordMessages,
|
||||
} from "../apps/persona-scheduler/dist/turn-context-source.js";
|
||||
import { readBifrostGovernanceDigest } from "../apps/persona-scheduler/dist/bifrost-governance-source.js";
|
||||
import { submitPersonaTurn } from "../apps/persona-scheduler/dist/turn-actuator.js";
|
||||
|
||||
function participant(identityId: string, nextTurnAt: number): InitiativeParticipant {
|
||||
return {
|
||||
|
|
@ -343,6 +347,34 @@ const malformedBifrostDigest = await readBifrostGovernanceDigest({
|
|||
assert.equal(malformedBifrostDigest.topics[0].id, "bifrost-digest-parse-error", "malformed provider output becomes an explicit typed error topic");
|
||||
assert.equal(malformedBifrostDigest.generatedAt, "2026-07-15T21:00:00.000Z", "provider failure witnesses use the caller's observation clock");
|
||||
|
||||
const submittedJobs: CreateJobInput[] = [];
|
||||
const turnReceipt = await submitPersonaTurn({
|
||||
jobQueue: {
|
||||
async createJob(input) {
|
||||
submittedJobs.push(input);
|
||||
return { created: true, job: { id: "job-1" } as JobRecord };
|
||||
},
|
||||
} satisfies Pick<JobQueue, "createJob">,
|
||||
provider: "owner_codex",
|
||||
identityId: "nibu",
|
||||
queuedAt: "2026-07-15T21:03:00.000Z",
|
||||
channelId: "aquarium",
|
||||
prompt: "Persona prompt",
|
||||
recentMessages: contextMessages,
|
||||
conversationFocus: { channelId: "aquarium", reason: "latest_human_message", isCurrentRoom: true },
|
||||
conversationThreads: [],
|
||||
imageAttachments: [],
|
||||
});
|
||||
assert.deepEqual(turnReceipt, {
|
||||
created: true,
|
||||
activeJobId: "job-1",
|
||||
requestMessageId: "agent-turn:nibu:2026-07-15T21:03:00.000Z",
|
||||
}, "the turn actuator returns only its queue receipt");
|
||||
assert.equal(submittedJobs[0].command, "repo-face-rumination", "the actuator owns the worker command contract");
|
||||
assert.equal(submittedJobs[0].initialState, "approved", "Persona turns enter the canonical queue through one approval policy");
|
||||
assert.equal(submittedJobs[0].contextBundle.recentMessages.length, 2, "the actuator lowers supplied evidence into the worker context bundle");
|
||||
assert.equal(submittedJobs[0].requester.id, "voidbot-agent-turn", "the actuator owns the worker-facing actor identity");
|
||||
|
||||
const stateDirectory = await mkdtemp(join(tmpdir(), "voidbot-persona-scheduler-"));
|
||||
try {
|
||||
const statePath = join(stateDirectory, "scheduler.json");
|
||||
|
|
|
|||
Loading…
Reference in a new issue