Queue repo Face rumination jobs
This commit is contained in:
parent
ed36561c8d
commit
32b96ce575
14 changed files with 465 additions and 5 deletions
|
|
@ -322,7 +322,7 @@ async function processJob(job: JobRecord): Promise<void> {
|
|||
return;
|
||||
}
|
||||
|
||||
if (job.command === "repo-identity-mention") {
|
||||
if (job.command === "repo-identity-mention" || job.command === "repo-face-rumination") {
|
||||
await jobQueue.completeJobDirect(job.id, finalResponse);
|
||||
await deliverOwnerNotifications(job, response.notifications ?? []);
|
||||
await auditLog.record({
|
||||
|
|
@ -333,10 +333,10 @@ async function processJob(job: JobRecord): Promise<void> {
|
|||
details: {
|
||||
summary: response.summary,
|
||||
autoPosted: false,
|
||||
reason: "repo_identity_must_post_through_mcp",
|
||||
reason: `${job.command}_must_post_through_mcp`,
|
||||
},
|
||||
});
|
||||
console.log(`Completed repo identity mention job ${job.id}.`);
|
||||
console.log(`Completed ${job.command} job ${job.id}.`);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,15 @@ export const postRepoIdentityMessageInputSchema = {
|
|||
replyToMessageId: z.string().min(1).optional(),
|
||||
};
|
||||
|
||||
export const repoFaceStateInputSchema = {
|
||||
identity: z.string().min(1),
|
||||
};
|
||||
|
||||
export const applyRepoFaceStateOperationInputSchema = {
|
||||
identity: z.string().min(1),
|
||||
operation: z.record(z.unknown()),
|
||||
};
|
||||
|
||||
export const searchSourcesInputSchema = {
|
||||
query: z.string().min(1).max(240),
|
||||
limit: z.number().int().min(1).max(MAX_RETRIEVAL_RESULT_LIMIT).optional(),
|
||||
|
|
@ -87,6 +96,15 @@ export interface PostRepoIdentityMessageArgs {
|
|||
replyToMessageId?: string;
|
||||
}
|
||||
|
||||
export interface RepoFaceStateArgs {
|
||||
identity: string;
|
||||
}
|
||||
|
||||
export interface ApplyRepoFaceStateOperationArgs {
|
||||
identity: string;
|
||||
operation: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export interface ListIndexedReposArgs {
|
||||
[key: string]: never;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,9 +4,13 @@ import { type CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|||
import { DEFAULT_RETRIEVAL_RESULT_LIMIT } from "@voidbot/shared";
|
||||
import { searchHistoryWithArchiveFallback } from "@voidbot/rag";
|
||||
import {
|
||||
applyVoidSelfStateOperation,
|
||||
buildVoidSelfStateContext,
|
||||
findRepoDiscordIdentity,
|
||||
isRepoDiscordIdentityAllowedInChannel,
|
||||
loadRepoDiscordIdentityRegistry,
|
||||
loadVoidSelfStateTypedDocuments,
|
||||
resolveRepoFaceStatePath,
|
||||
} from "@voidbot/core";
|
||||
|
||||
import { type VoidbotMcpContext } from "./mcp-server-context";
|
||||
|
|
@ -15,18 +19,22 @@ import {
|
|||
type ListIndexedReposArgs,
|
||||
type MessageContextArgs,
|
||||
type NotifyOwnerArgs,
|
||||
type ApplyRepoFaceStateOperationArgs,
|
||||
type PostDiscordMessageArgs,
|
||||
type PostRepoIdentityMessageArgs,
|
||||
type RepoFaceStateArgs,
|
||||
type SearchHistoryArgs,
|
||||
type SearchSourcesArgs,
|
||||
type SourceContextArgs,
|
||||
formatArchivedMessage,
|
||||
formatHistoryResults,
|
||||
formatSourceResults,
|
||||
applyRepoFaceStateOperationInputSchema,
|
||||
messageContextInputSchema,
|
||||
notifyOwnerInputSchema,
|
||||
postDiscordMessageInputSchema,
|
||||
postRepoIdentityMessageInputSchema,
|
||||
repoFaceStateInputSchema,
|
||||
renderJsonBlock,
|
||||
searchHistoryInputSchema,
|
||||
searchSourcesInputSchema,
|
||||
|
|
@ -527,6 +535,99 @@ export function registerVoidbotTools(
|
|||
},
|
||||
);
|
||||
|
||||
server.registerTool(
|
||||
"read_repo_face_state",
|
||||
{
|
||||
title: "Read Repo Face State",
|
||||
description:
|
||||
"Read the typed persistent Face state for a registered repo identity. Face state uses the same typed operation machinery as Void, but the state file belongs to the repo identity.",
|
||||
inputSchema: repoFaceStateInputSchema,
|
||||
annotations: READ_ONLY_ANNOTATIONS,
|
||||
},
|
||||
async (input: RepoFaceStateArgs): Promise<CallToolResult> => {
|
||||
const resolved = await resolveRepoIdentityForTool(context, input.identity);
|
||||
|
||||
if (!resolved.identity) {
|
||||
return resolved.error;
|
||||
}
|
||||
|
||||
const typedState = await loadVoidSelfStateTypedDocuments({
|
||||
canonicalPath: resolved.faceStatePath,
|
||||
});
|
||||
const rendered = buildVoidSelfStateContext(typedState, {
|
||||
sourcePath: resolved.faceStatePath,
|
||||
});
|
||||
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: renderJsonBlock({
|
||||
identity: identityForToolResult(resolved.identity),
|
||||
faceStatePath: resolved.faceStatePath,
|
||||
summary: rendered.summary,
|
||||
typedState,
|
||||
}),
|
||||
},
|
||||
],
|
||||
structuredContent: {
|
||||
identity: identityForToolResult(resolved.identity),
|
||||
faceStatePath: resolved.faceStatePath,
|
||||
summary: rendered.summary,
|
||||
typedState,
|
||||
},
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
server.registerTool(
|
||||
"apply_repo_face_state_operation",
|
||||
{
|
||||
title: "Apply Repo Face State Operation",
|
||||
description:
|
||||
"Apply one typed state operation to a registered repo identity's Face state. Use this for Face memory, incubation, agency pressure, candidate interventions, and receipts; do not edit the Face state file directly.",
|
||||
inputSchema: applyRepoFaceStateOperationInputSchema,
|
||||
annotations: {
|
||||
readOnlyHint: false,
|
||||
destructiveHint: false,
|
||||
idempotentHint: false,
|
||||
openWorldHint: false,
|
||||
},
|
||||
},
|
||||
async (input: ApplyRepoFaceStateOperationArgs): Promise<CallToolResult> => {
|
||||
const resolved = await resolveRepoIdentityForTool(context, input.identity);
|
||||
|
||||
if (!resolved.identity) {
|
||||
return resolved.error;
|
||||
}
|
||||
|
||||
const result = await applyVoidSelfStateOperation(
|
||||
{ canonicalPath: resolved.faceStatePath },
|
||||
input.operation,
|
||||
);
|
||||
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: renderJsonBlock({
|
||||
applied: true,
|
||||
identity: identityForToolResult(resolved.identity),
|
||||
faceStatePath: resolved.faceStatePath,
|
||||
result,
|
||||
}),
|
||||
},
|
||||
],
|
||||
structuredContent: {
|
||||
applied: true,
|
||||
identity: identityForToolResult(resolved.identity),
|
||||
faceStatePath: resolved.faceStatePath,
|
||||
result,
|
||||
},
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
server.registerTool(
|
||||
"notify_owner",
|
||||
{
|
||||
|
|
@ -578,3 +679,56 @@ export function registerVoidbotTools(
|
|||
},
|
||||
);
|
||||
}
|
||||
|
||||
async function resolveRepoIdentityForTool(
|
||||
context: VoidbotMcpContext,
|
||||
identitySelector: string,
|
||||
): Promise<
|
||||
| {
|
||||
identity: NonNullable<ReturnType<typeof findRepoDiscordIdentity>>;
|
||||
faceStatePath: string;
|
||||
}
|
||||
| {
|
||||
identity?: undefined;
|
||||
error: CallToolResult;
|
||||
}
|
||||
> {
|
||||
const registry = await loadRepoDiscordIdentityRegistry(
|
||||
context.config.repoDiscordIdentitiesPath,
|
||||
);
|
||||
const identity = findRepoDiscordIdentity(registry, identitySelector);
|
||||
|
||||
if (!identity) {
|
||||
return {
|
||||
error: {
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: `No registered repo Discord identity matched "${identitySelector}".`,
|
||||
},
|
||||
],
|
||||
structuredContent: {
|
||||
found: false,
|
||||
reason: "unknown_identity",
|
||||
identity: identitySelector,
|
||||
},
|
||||
isError: true,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
identity,
|
||||
faceStatePath: resolveRepoFaceStatePath(identity, context.config.storageRoot),
|
||||
};
|
||||
}
|
||||
|
||||
function identityForToolResult(identity: NonNullable<ReturnType<typeof findRepoDiscordIdentity>>) {
|
||||
return {
|
||||
id: identity.id,
|
||||
repoName: identity.repoName,
|
||||
displayName: identity.displayName,
|
||||
roleId: identity.roleId ?? null,
|
||||
mention: identity.roleId ? `<@&${identity.roleId}>` : null,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue