Skip to content

Commit 03558dc

Browse files
fix(openrouter): Fusion prompt corrupts boundary emoji in model IDs (#104433)
Co-authored-by: Vincent Koc <[email protected]>
1 parent 1879980 commit 03558dc

2 files changed

Lines changed: 50 additions & 13 deletions

File tree

‎extensions/openrouter/index.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,40 @@ describe("openrouter provider hooks", () => {
281281
expect(contribution?.dynamicSuffix).toContain("Final Fusion model: google/gemini-3.5-flash.");
282282
});
283283

284+
it("keeps bounded Fusion model IDs on valid UTF-16 boundaries", async () => {
285+
const provider = await registerSingleProviderPlugin(openrouterPlugin);
286+
const boundaryModelId = `${"a".repeat(255)}😀tail`;
287+
const contribution = provider.resolveSystemPromptContribution?.({
288+
provider: "openrouter",
289+
modelId: "openrouter/fusion",
290+
promptMode: "full",
291+
config: {
292+
agents: {
293+
defaults: {
294+
models: {
295+
"openrouter/fusion": {
296+
params: {
297+
extraBody: {
298+
plugins: [
299+
{
300+
id: "fusion",
301+
analysis_models: [boundaryModelId],
302+
model: boundaryModelId,
303+
},
304+
],
305+
},
306+
},
307+
},
308+
},
309+
},
310+
},
311+
},
312+
} as never);
313+
314+
expect(contribution?.dynamicSuffix).toContain(`Analysis models: ${"a".repeat(255)}.`);
315+
expect(contribution?.dynamicSuffix).toContain(`Final Fusion model: ${"a".repeat(255)}.`);
316+
});
317+
284318
it("describes Fusion config from the canonical OpenRouter model key", async () => {
285319
const provider = await registerSingleProviderPlugin(openrouterPlugin);
286320
const contribution = provider.resolveSystemPromptContribution?.({

‎extensions/openrouter/index.ts‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
getOpenRouterModelCapabilities,
1616
loadOpenRouterModelCapabilities,
1717
} from "openclaw/plugin-sdk/provider-stream-family";
18+
import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
1819
import { buildOpenRouterImageGenerationProvider } from "./image-generation-provider.js";
1920
import { openrouterMediaUnderstandingProvider } from "./media-understanding-provider.js";
2021
import { isOpenRouterMistralModelId, normalizeOpenRouterApiModelId } from "./models.js";
@@ -99,19 +100,21 @@ function sanitizePromptModelId(value: unknown): string | undefined {
99100
if (typeof value !== "string") {
100101
return undefined;
101102
}
102-
const normalized = Array.from(value)
103-
.filter((char) => {
104-
const codePoint = char.codePointAt(0) ?? 0;
105-
return (
106-
codePoint > 0x1f &&
107-
(codePoint < 0x7f || codePoint > 0x9f) &&
108-
codePoint !== 0x2028 &&
109-
codePoint !== 0x2029
110-
);
111-
})
112-
.join("")
113-
.trim()
114-
.slice(0, MAX_PROMPT_MODEL_ID_DISPLAY_CHARS);
103+
const normalized = truncateUtf16Safe(
104+
Array.from(value)
105+
.filter((char) => {
106+
const codePoint = char.codePointAt(0) ?? 0;
107+
return (
108+
codePoint > 0x1f &&
109+
(codePoint < 0x7f || codePoint > 0x9f) &&
110+
codePoint !== 0x2028 &&
111+
codePoint !== 0x2029
112+
);
113+
})
114+
.join("")
115+
.trim(),
116+
MAX_PROMPT_MODEL_ID_DISPLAY_CHARS,
117+
);
115118
return normalized || undefined;
116119
}
117120

0 commit comments

Comments
 (0)