feat(models): add Claude Sonnet 5 models and honor user_selected_model (#8)

Perplexity's /rest/models/config now exposes claude50sonnet and
claude50sonnetthinking. Add both to KNOWN_MODELS with the official
labels from the config.

The stream's display_model can report "turbo" even when the requested
model was honored, so prefer user_selected_model when present and not
"turbo" so tool metadata reflects the model actually used.

Closes #7

Co-authored-by: Ivan Pereira <183991+ivanrvpereira@users.noreply.github.com>
This commit is contained in:
Ivan Pereira
2026-07-16 15:40:59 +01:00
committed by GitHub
co-authored by Ivan Pereira
parent 97aab3e9b9
commit 9f5c87c1c4
4 changed files with 42 additions and 1 deletions
+32
View File
@@ -279,6 +279,38 @@ describe("searchPerplexity", () => {
expect(textResult.answer).toBe("text fallback");
});
test("prefers user_selected_model over display_model unless it is turbo", async () => {
globalThis.fetch = (async () =>
createSseResponse([
{
status: "COMPLETED",
final: true,
text: "answer",
display_model: "turbo",
user_selected_model: "claude50sonnetthinking",
sources_list: [{ title: "S", url: "https://example.com" }],
},
])) as unknown as typeof fetch;
const preferred = await searchPerplexity({ query: "q", model: "claude50sonnetthinking" }, "jwt");
expect(preferred.displayModel).toBe("claude50sonnetthinking");
globalThis.fetch = (async () =>
createSseResponse([
{
status: "COMPLETED",
final: true,
text: "answer",
display_model: "pplx_pro_upgraded",
user_selected_model: "turbo",
sources_list: [{ title: "S", url: "https://example.com" }],
},
])) as unknown as typeof fetch;
const fallback = await searchPerplexity({ query: "q", model: "pplx_pro_upgraded" }, "jwt");
expect(fallback.displayModel).toBe("pplx_pro_upgraded");
});
test("returns EMPTY error when response has no answer and no sources", async () => {
globalThis.fetch = (async () =>
createSseResponse([{ status: "COMPLETED", final: true }])) as unknown as typeof fetch;