fix(perplexity-web): preserve system contract on follow-up requests (#12443)

* fix(perplexity-web): preserve system contract on follow-up requests

* fix(perplexity-web): preserve search hint on follow-up requests
This commit is contained in:
tanveer-arch
2026-09-18 19:58:28 +05:30
committed by GitHub
parent 6d0dc5a50c
commit 51227ccd85
2 changed files with 35 additions and 1 deletions

View File

@@ -408,7 +408,12 @@ function searchHintEnabled(): boolean {
}
export function buildQuery(parsed: ParsedMessages, followUpUuid: string | null): string {
if (followUpUuid) return parsed.currentMsg;
if (followUpUuid) {
const sys = parsed.systemMsg.trim();
const hint = searchHintEnabled() ? `\n\n${SEARCH_HINT}` : "";
const contract = sys ? `${sys}${hint}` : "";
return contract ? `${contract}\n\n${parsed.currentMsg}` : parsed.currentMsg;
}
const obj: Record<string, unknown> = {};
if (parsed.systemMsg.trim()) {

View File

@@ -0,0 +1,29 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { buildQuery } from "../../open-sse/executors/perplexity-web/protocol.ts";
test("PR #3: buildQuery preserves system contract on follow-up requests", () => {
const parsed = {
systemMsg: "You are an expert coder. <tool>contract</tool>",
history: [],
currentMsg: "How do I reverse a string in JS?"
};
// Turn 1: followUpUuid is null
const turn1Raw = buildQuery(parsed, null);
const turn1Obj = JSON.parse(turn1Raw);
assert.ok(turn1Obj.instructions !== undefined, "Turn 1 JSON should contain instructions");
assert.equal(turn1Obj.instructions[0], "You are an expert coder. <tool>contract</tool>");
// Turn 2: follow-up request
const parsedTurn2 = {
systemMsg: "You are an expert coder. <tool>contract</tool>",
history: [{ role: "user", content: "How do I reverse a string in JS?" }, { role: "assistant", content: "Use .reverse()" }],
currentMsg: "What about Python?"
};
const turn2Output = buildQuery(parsedTurn2, "abc-123");
// Since we append systemMsg to currentMsg for follow-ups (Approach B)
assert.ok(turn2Output.includes("<tool>contract</tool>"), "Follow-up query should preserve the tool contract");
assert.ok(turn2Output.includes("What about Python?"), "Follow-up query should include the current message");
});