fix: apply role labels to arbiter conversation context
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { getRecentChatMessages } from './db.js';
|
||||
import { formatMessages } from './router.js';
|
||||
import type { NewMessage } from './types.js';
|
||||
|
||||
export function buildArbiterContextPrompt(args: {
|
||||
chatJid: string;
|
||||
@@ -7,10 +8,19 @@ export function buildArbiterContextPrompt(args: {
|
||||
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 {
|
||||
chatJid,
|
||||
taskId,
|
||||
roundTripCount,
|
||||
timezone,
|
||||
recentTurnLimit = 20,
|
||||
} = args;
|
||||
|
||||
const recentMessages = getRecentChatMessages(chatJid, recentTurnLimit);
|
||||
const recentMessages =
|
||||
args.messages ?? getRecentChatMessages(chatJid, recentTurnLimit);
|
||||
const conversationContext = formatMessages(recentMessages, timezone);
|
||||
|
||||
return [
|
||||
|
||||
@@ -668,11 +668,16 @@ export function createMessageRuntime(deps: MessageRuntimeDeps): {
|
||||
);
|
||||
}
|
||||
|
||||
const arbiterMessages = labelPairedSenders(
|
||||
chatJid,
|
||||
getRecentChatMessages(chatJid, 20),
|
||||
);
|
||||
const arbiterPrompt = buildArbiterContextPrompt({
|
||||
chatJid,
|
||||
taskId: pendingReviewTask.id,
|
||||
roundTripCount: pendingReviewTask.round_trip_count,
|
||||
timezone: deps.timezone,
|
||||
messages: arbiterMessages,
|
||||
});
|
||||
|
||||
const { deliverySucceeded } = await executeTurn({
|
||||
@@ -840,11 +845,16 @@ export function createMessageRuntime(deps: MessageRuntimeDeps): {
|
||||
// Arbiter turns use a dedicated context prompt; regular turns use formatted messages.
|
||||
let prompt: string;
|
||||
if (useArbiterChannel && pendingTaskForChannel) {
|
||||
const arbiterMsgs = labelPairedSenders(
|
||||
chatJid,
|
||||
getRecentChatMessages(chatJid, 20),
|
||||
);
|
||||
prompt = buildArbiterContextPrompt({
|
||||
chatJid,
|
||||
taskId: pendingTaskForChannel.id,
|
||||
roundTripCount: pendingTaskForChannel.round_trip_count,
|
||||
timezone: deps.timezone,
|
||||
messages: arbiterMsgs,
|
||||
});
|
||||
} else {
|
||||
prompt = formatMessages(
|
||||
|
||||
Reference in New Issue
Block a user