import { getRecentChatMessages } from './db.js';
import { formatMessages } from './router.js';
import type { NewMessage } from './types.js';
export function buildArbiterContextPrompt(args: {
chatJid: string;
taskId: string;
roundTripCount: number;
timezone: string;
recentTurnLimit?: number;
/** Pre-labeled messages. If provided, skips DB fetch. */
messages?: NewMessage[];
}): string {
const {
chatJid,
taskId,
roundTripCount,
timezone,
recentTurnLimit = 20,
} = args;
const recentMessages =
args.messages ?? getRecentChatMessages(chatJid, recentTurnLimit);
const conversationContext = formatMessages(recentMessages, timezone);
return [
``,
`${taskId}`,
`${roundTripCount}`,
`Deadlock detected: owner and reviewer exchanged ${roundTripCount} rounds without resolution`,
``,
``,
``,
conversationContext,
``,
``,
`Review the conversation above and render your verdict.`,
].join('\n');
}