Add multimodal image inputs to Face turns

This commit is contained in:
Meta Vens 2026-05-24 03:28:40 +01:00
commit c430e709fd
12 changed files with 281 additions and 16 deletions

View file

@ -3,6 +3,7 @@ import {
type ContextBundle,
type GuildContext,
type InteractionMemoryProfile,
type PromptImageAttachment,
type RetrievalResult,
type SituationalSocialRead,
type SourceGroundingHint,
@ -16,6 +17,7 @@ export interface BuildContextInput {
actor: Actor;
guildContext: GuildContext;
recentMessages?: SourceMessage[];
imageAttachments?: PromptImageAttachment[];
retrieval?: RetrievalResult[];
interactionMemory?: InteractionMemoryProfile;
situationalSocialRead?: SituationalSocialRead;
@ -31,6 +33,7 @@ export class ContextBuilder {
actor: input.actor,
guildContext: input.guildContext,
recentMessages: input.recentMessages ?? [],
imageAttachments: input.imageAttachments,
retrieval: input.retrieval ?? [],
interactionMemory: input.interactionMemory,
situationalSocialRead: input.situationalSocialRead,

View file

@ -415,6 +415,7 @@ export class OwnerCodexProvider implements ProviderAdapter {
timeoutMs: this.options.timeoutMs,
workingDirectory: this.options.workingDirectory,
prompt: input.prompt,
imagePaths: collectCodexImagePaths(input.request.contextBundle),
mcpServers: input.command === "repo-face-rumination"
? restrictMcpServersToRepoFaceExploration(this.options.mcpServers ?? [])
: this.options.mcpServers ?? [],
@ -436,11 +437,19 @@ export class OwnerCodexProvider implements ProviderAdapter {
timeoutMs: this.options.timeoutMs,
workingDirectory: this.options.workingDirectory,
prompt: input.prompt,
imagePaths: collectCodexImagePaths(input.request.contextBundle),
mcpServers: this.options.mcpServers ?? [],
});
}
}
function collectCodexImagePaths(contextBundle: ProviderRequest["contextBundle"]): string[] {
return (contextBundle.imageAttachments ?? [])
.map((attachment) => attachment.localPath)
.filter((localPath): localPath is string => typeof localPath === "string" && localPath.trim().length > 0)
.slice(0, 8);
}
function getStringOption(value: unknown): string | undefined {
return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
}

View file

@ -34,7 +34,7 @@ export function buildDiscordReplyPrompt(
? context.recentMessages
.map(
(message) =>
`- [${message.timestamp}] ${message.authorName}: ${message.content}`,
`- [${message.timestamp}] ${message.authorName}: ${message.content}${renderAttachmentSuffix(message)}`,
)
.join("\n")
: "- No recent messages captured.";
@ -116,7 +116,7 @@ export function renderMarkdownBundle(context: ContextBundle): string {
? context.recentMessages
.map(
(message) =>
`- [${message.timestamp}] ${message.authorName} (${message.authorId}): ${message.content}`,
`- [${message.timestamp}] ${message.authorName} (${message.authorId}): ${message.content}${renderAttachmentSuffix(message)}`,
)
.join("\n")
: "- No recent messages captured.";
@ -183,6 +183,20 @@ export function renderMarkdownBundle(context: ContextBundle): string {
].join("\n");
}
function renderAttachmentSuffix(message: ContextBundle["recentMessages"][number]): string {
const attachments = message.attachments ?? [];
if (attachments.length === 0) {
return "";
}
return ` [media: ${attachments.map((attachment) => {
const kind = attachment.kind === "image" ? "image" : "attachment";
const name = attachment.filename ?? attachment.id ?? "unnamed";
const dimensions = attachment.width && attachment.height ? ` ${attachment.width}x${attachment.height}` : "";
const local = attachment.localPath ? ` local=${attachment.localPath}` : "";
return `${kind} ${name}${dimensions}${local}`;
}).join("; ")}]`;
}
function renderVoidSelfState(context: ContextBundle): string {
if (!context.voidSelfState) {
return "- No private persistent self-state was attached.";

View file

@ -47,6 +47,7 @@ export async function runCodexExec(input: {
timeoutMs: number;
workingDirectory: string;
prompt: string;
imagePaths?: string[];
mcpServers: CodexMcpServerConfig[];
}): Promise<CodexRunResult> {
return new Promise<CodexRunResult>((resolve) => {
@ -62,6 +63,7 @@ export async function runCodexExec(input: {
"-c",
`model_reasoning_effort=${JSON.stringify(input.reasoningEffort)}`,
...buildMcpConfigArguments(input.mcpServers),
...buildImageArguments(input.imagePaths ?? []),
"--json",
"--skip-git-repo-check",
"-s",
@ -226,6 +228,19 @@ export async function runCodexExec(input: {
});
}
function buildImageArguments(imagePaths: string[]): string[] {
const args: string[] = [];
const seen = new Set<string>();
for (const imagePath of imagePaths) {
if (seen.has(imagePath)) {
continue;
}
seen.add(imagePath);
args.push("--image", imagePath);
}
return args;
}
export function normalizeDiscordReply(stdout: string): NormalizedDiscordReply {
const messages: string[] = [];

View file

@ -127,6 +127,7 @@ export function buildRequestPayload(
stylePack: request.contextBundle.stylePack,
voidSelfState: request.contextBundle.voidSelfState,
recentMessages: request.contextBundle.recentMessages,
imageAttachments: request.contextBundle.imageAttachments ?? [],
retrieval: request.contextBundle.retrieval,
options: request.options ?? {},
};

View file

@ -78,6 +78,28 @@ export interface SourceMessage {
content: string;
timestamp: string;
isBot?: boolean;
attachments?: SourceMessageAttachment[];
}
export interface SourceMessageAttachment {
id?: string;
filename?: string;
contentType?: string;
url?: string;
proxyUrl?: string;
size?: number;
width?: number;
height?: number;
localPath?: string;
kind: "image" | "other";
}
export interface PromptImageAttachment {
messageId: string;
authorName: string;
filename?: string;
contentType?: string;
localPath: string;
}
export interface RetrievalResult {
@ -434,6 +456,7 @@ export interface ContextBundle {
actor: Actor;
guildContext: GuildContext;
recentMessages: SourceMessage[];
imageAttachments?: PromptImageAttachment[];
retrieval: RetrievalResult[];
interactionMemory?: InteractionMemoryProfile;
situationalSocialRead?: SituationalSocialRead;