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