fix(auto-reply): preserve OpenRouter @preset model directives (#23769)

* Auto-reply: preserve OpenRouter @preset model directives

* Changelog: move OpenRouter preset fix into 2026.2.22 unreleased
This commit is contained in:
Vincent Koc
2026-02-22 12:46:04 -05:00
committed by GitHub
parent 91944ede4c
commit 24fd8cbdc8
3 changed files with 26 additions and 6 deletions

View File

@@ -36,6 +36,20 @@ describe("extractModelDirective", () => {
expect(result.rawProfile).toBe("myprofile");
});
it("keeps OpenRouter preset paths that include @ in the model name", () => {
const result = extractModelDirective("/model openrouter/@preset/kimi-2-5");
expect(result.hasDirective).toBe(true);
expect(result.rawModel).toBe("openrouter/@preset/kimi-2-5");
expect(result.rawProfile).toBeUndefined();
});
it("still allows profile overrides after OpenRouter preset paths", () => {
const result = extractModelDirective("/model openrouter/@preset/kimi-2-5@work");
expect(result.hasDirective).toBe(true);
expect(result.rawModel).toBe("openrouter/@preset/kimi-2-5");
expect(result.rawProfile).toBe("work");
});
it("returns no directive for plain text", () => {
const result = extractModelDirective("hello world");
expect(result.hasDirective).toBe(false);

View File

@@ -33,10 +33,16 @@ export function extractModelDirective(
let rawModel = raw;
let rawProfile: string | undefined;
if (raw?.includes("@")) {
const parts = raw.split("@");
rawModel = parts[0]?.trim();
rawProfile = parts.slice(1).join("@").trim() || undefined;
if (raw) {
const atIndex = raw.lastIndexOf("@");
if (atIndex > 0) {
const candidateModel = raw.slice(0, atIndex).trim();
const candidateProfile = raw.slice(atIndex + 1).trim();
if (candidateModel && candidateProfile && !candidateProfile.includes("/")) {
rawModel = candidateModel;
rawProfile = candidateProfile;
}
}
}
const cleaned = match ? body.replace(match[0], " ").replace(/\s+/g, " ").trim() : body.trim();