test(pi): route resilience turns by latest user input
This commit is contained in:
@@ -405,8 +405,16 @@ function respondWithHoldingBashCall(response: ServerResponse, model: string): vo
|
|||||||
response.end('data: [DONE]\n\n');
|
response.end('data: [DONE]\n\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
function requestContains(body: Record<string, unknown>, marker: string): boolean {
|
function latestUserMessageContains(body: Record<string, unknown>, marker: string): boolean {
|
||||||
return JSON.stringify(body.messages ?? []).includes(marker);
|
if (!Array.isArray(body.messages)) return false;
|
||||||
|
for (let index = body.messages.length - 1; index >= 0; index -= 1) {
|
||||||
|
const message = body.messages[index];
|
||||||
|
if (!message || typeof message !== 'object' || Array.isArray(message)) continue;
|
||||||
|
const record = message as { role?: unknown; content?: unknown };
|
||||||
|
if (record.role !== 'user') continue;
|
||||||
|
return JSON.stringify(record.content ?? '').includes(marker);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function startLocalProofProvider(mode: ProofProviderMode): Promise<LocalProofProvider> {
|
async function startLocalProofProvider(mode: ProofProviderMode): Promise<LocalProofProvider> {
|
||||||
@@ -434,18 +442,26 @@ async function startLocalProofProvider(mode: ProofProviderMode): Promise<LocalPr
|
|||||||
else respondWithHoldingBashCall(response, model);
|
else respondWithHoldingBashCall(response, model);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (requestContains(body, 'RESILIENCE_TARGET_ACTIVE')) {
|
if (latestUserMessageContains(body, 'RESILIENCE_RECOVERED_TURN')) {
|
||||||
respondWithSubagentCall(response, model, 'coding');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (requestContains(body, 'RESILIENCE_RECOVERED_TURN')) {
|
|
||||||
respondWithText(response, model, 'RESILIENCE_RECOVERED_COMPLETE');
|
respondWithText(response, model, 'RESILIENCE_RECOVERED_COMPLETE');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (requestContains(body, 'RESILIENCE_SETTLED_BEFORE_CLOSE')) {
|
if (latestUserMessageContains(body, 'RESILIENCE_SETTLED_BEFORE_CLOSE')) {
|
||||||
respondWithText(response, model, 'RESILIENCE_SETTLED_COMPLETE');
|
respondWithText(response, model, 'RESILIENCE_SETTLED_COMPLETE');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (latestUserMessageContains(body, 'RESILIENCE_PROTOCOL_ACTIVE')) {
|
||||||
|
response.writeHead(200, { 'content-type': 'text/event-stream' });
|
||||||
|
writeChunk(response, model, { role: 'assistant', content: 'RESILIENCE_ACTIVE' }, null);
|
||||||
|
const entry = { role, response };
|
||||||
|
held.add(entry);
|
||||||
|
response.once('close', () => held.delete(entry));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (latestUserMessageContains(body, 'RESILIENCE_TARGET_ACTIVE')) {
|
||||||
|
respondWithSubagentCall(response, model, 'coding');
|
||||||
|
return;
|
||||||
|
}
|
||||||
response.writeHead(200, { 'content-type': 'text/event-stream' });
|
response.writeHead(200, { 'content-type': 'text/event-stream' });
|
||||||
writeChunk(response, model, { role: 'assistant', content: 'RESILIENCE_ACTIVE' }, null);
|
writeChunk(response, model, { role: 'assistant', content: 'RESILIENCE_ACTIVE' }, null);
|
||||||
const entry = { role, response };
|
const entry = { role, response };
|
||||||
|
|||||||
Reference in New Issue
Block a user