paired: preserve prior owner and reviewer finals across superseded tasks
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
getLastHumanMessageContent,
|
||||
getLatestPreviousPairedTaskForChat,
|
||||
getPairedTurnOutputs,
|
||||
getRecentChatMessages,
|
||||
} from './db.js';
|
||||
@@ -10,6 +11,7 @@ import {
|
||||
buildOwnerPendingPrompt,
|
||||
buildPairedTurnPrompt,
|
||||
buildReviewerPendingPrompt,
|
||||
type PriorTaskPromptContext,
|
||||
} from './message-runtime-prompts.js';
|
||||
import {
|
||||
requeuePendingPairedTurn,
|
||||
@@ -32,6 +34,7 @@ import type {
|
||||
NewMessage,
|
||||
PairedTask,
|
||||
PairedRoomRole,
|
||||
PairedTurnOutput,
|
||||
PairedTurnReservationIntentKind,
|
||||
RegisteredGroup,
|
||||
} from './types.js';
|
||||
@@ -115,6 +118,7 @@ export function buildPendingPairedTurn(args: {
|
||||
const cursor = lastRaw?.seq ?? lastRaw?.timestamp ?? null;
|
||||
const taskStatus = task.status;
|
||||
const turnOutputs = getPairedTurnOutputs(task.id);
|
||||
const priorTaskContext = resolvePriorTaskPromptContext(chatJid, task, turnOutputs);
|
||||
const lastTurnOutput = turnOutputs[turnOutputs.length - 1];
|
||||
const nextTurnAction = resolveNextTurnAction({
|
||||
taskStatus,
|
||||
@@ -131,6 +135,7 @@ export function buildPendingPairedTurn(args: {
|
||||
turnOutputs,
|
||||
recentHumanMessages,
|
||||
lastHumanMessage,
|
||||
priorTaskContext,
|
||||
}),
|
||||
channel: resolveChannel(taskStatus),
|
||||
cursor,
|
||||
@@ -182,6 +187,7 @@ export function buildPendingPairedTurn(args: {
|
||||
turnOutputs,
|
||||
recentHumanMessages,
|
||||
lastHumanMessage,
|
||||
priorTaskContext,
|
||||
}),
|
||||
channel: resolveChannel(taskStatus),
|
||||
cursor,
|
||||
@@ -195,6 +201,38 @@ export function buildPendingPairedTurn(args: {
|
||||
return null;
|
||||
}
|
||||
|
||||
function resolvePriorTaskPromptContext(
|
||||
chatJid: string,
|
||||
task: PairedTask,
|
||||
turnOutputs: PairedTurnOutput[],
|
||||
): PriorTaskPromptContext | null {
|
||||
if (turnOutputs.length > 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const previousTask = getLatestPreviousPairedTaskForChat(chatJid, task.id);
|
||||
if (!previousTask || previousTask.status !== 'completed') {
|
||||
return null;
|
||||
}
|
||||
|
||||
const previousOutputs = getPairedTurnOutputs(previousTask.id);
|
||||
const ownerFinal = [...previousOutputs]
|
||||
.reverse()
|
||||
.find((output) => output.role === 'owner')?.output_text;
|
||||
const reviewerFinal = [...previousOutputs]
|
||||
.reverse()
|
||||
.find((output) => output.role === 'reviewer')?.output_text;
|
||||
|
||||
if (!ownerFinal && !reviewerFinal) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
ownerFinal: ownerFinal ?? null,
|
||||
reviewerFinal: reviewerFinal ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
export async function executePendingPairedTurn(args: {
|
||||
pendingTurn: Exclude<PendingPairedTurn, null>;
|
||||
chatJid: string;
|
||||
|
||||
Reference in New Issue
Block a user