Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,9 @@ export function isValidModelId(value: string): boolean {
return (
modelId.length > 0 &&
modelId.length <= 120 &&
/^[A-Za-z0-9][A-Za-z0-9._:/@+-]*$/u.test(modelId) &&
// Leading @ for Cloudflare Workers AI ids (@cf/...); interior @ for
// Vertex AI @-versioned ids (e.g. claude-sonnet-4-5@20250929).
/^[@A-Za-z0-9][A-Za-z0-9._:/@+-]*$/u.test(modelId) &&
!modelId.includes("://")
);
}
Expand Down
11 changes: 9 additions & 2 deletions test/constants.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ describe("isValidModelId", () => {
expect(isValidModelId("nvidia/nemotron-3-super-120b-a12b")).toBe(true);
});

test("accepts Cloudflare Workers AI model ids with leading '@'", () => {
expect(isValidModelId("@cf/meta/llama-3-8b-instruct")).toBe(true);
expect(isValidModelId("@cf/moonshotai/kimi-k2.7-code")).toBe(true);
expect(isValidModelId("@cf/qwen/qwen1.5-14b-chat-awq")).toBe(true);
});

test("rejects empty, whitespace-only, and over-long ids", () => {
expect(isValidModelId("")).toBe(false);
expect(isValidModelId(" ")).toBe(false);
Expand All @@ -53,10 +59,11 @@ describe("isValidModelId", () => {
expect(isValidModelId("claude-haiku-4-5@20251001")).toBe(true);
});

test("rejects ids starting with a non-alphanumeric character", () => {
test("rejects ids starting with a disallowed non-alphanumeric character", () => {
expect(isValidModelId("-leading-dash")).toBe(false);
expect(isValidModelId("/leading-slash")).toBe(false);
expect(isValidModelId("@leading-at")).toBe(false);
// A leading "@" is intentionally allowed for Cloudflare Workers AI ids
// (covered above), so it is not rejected here.
});

test("normalizeModelId trims surrounding whitespace", () => {
Expand Down