fix(providers): Cloudflare Workers AI discovery uses model names, not UUIDs (#4259) - #4282
Conversation
… UUIDs (#4259) Cloudflare's /ai/models/search returns { id: "<uuid>", name: "@cf/..." } where name is the callable slug and id is an internal UUID. The cloudflare-ai discovery config passed the raw objects through (parseResponse: data.result), so buildResponse used id (the UUID) as the model id — the dashboard/import listed UUIDs instead of @cf/... model names. Map each result's name -> id (mirrors the gemini/huggingface/ clarifai parseResponse normalizers in the same map); falls through to the local catalog on error so import never breaks. TDD: tests/unit/cloudflare-models-uuid-4259.test.ts (RED on UUID ids -> GREEN on slugs). Closes #4259
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
Code Review
This pull request resolves issue #4259 by updating the Cloudflare Workers AI model discovery logic to map the human-usable model name (slug) as the model ID instead of the internal UUID, ensuring the dashboard displays callable model IDs. It also adds a comprehensive unit test to verify this behavior. The reviewer recommended using Array.isArray to safely validate the API response structure before mapping, preventing potential runtime errors if the response is malformed.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| parseResponse: (data) => | ||
| (data.result || []) | ||
| .map((model: any) => { |
There was a problem hiding this comment.
If the Cloudflare API returns an unexpected response where data.result is not an array (for example, an error payload or an empty object), (data.result || []) will evaluate to that non-array value. Calling .map() on it will then throw a TypeError, causing a hard 500 error instead of gracefully falling back to the local catalog. Using Array.isArray ensures the code is robust against unexpected API responses.
| parseResponse: (data) => | |
| (data.result || []) | |
| .map((model: any) => { | |
| parseResponse: (data) => | |
| (Array.isArray(data?.result) ? data.result : []) | |
| .map((model: any) => { |
… UUIDs (diegosouzapw#4259) (diegosouzapw#4282) Cloudflare's /ai/models/search returns { id: "<uuid>", name: "@cf/..." } where name is the callable slug and id is an internal UUID. The cloudflare-ai discovery config passed the raw objects through (parseResponse: data.result), so buildResponse used id (the UUID) as the model id — the dashboard/import listed UUIDs instead of @cf/... model names. Map each result's name -> id (mirrors the gemini/huggingface/ clarifai parseResponse normalizers in the same map); falls through to the local catalog on error so import never breaks. TDD: tests/unit/cloudflare-models-uuid-4259.test.ts (RED on UUID ids -> GREEN on slugs). Closes diegosouzapw#4259
Closes #4259
Problem
Importing a Cloudflare Workers AI key listed models with internal UUID identifiers (e.g.
429b9e8b-d99e-44de-91ad-706cf8183658) instead of their usable slugs (@cf/meta/llama-3.1-8b-instruct). Reported by @FerLuisxd.Root cause
Cloudflare's
/ai/models/searchreturns objects shaped{ id: "<uuid>", name: "@cf/..." }—nameis the callable model slug,idis an internal UUID. Thecloudflare-aientry inPROVIDER_MODELS_CONFIGusedparseResponse: (data) => data.result || [], passing the raw objects straight through. DownstreambuildResponsemapsid: m.id, so the UUID became the model id surfaced in the dashboard/import.Fix
cloudflare-aiparseResponsenow maps each result'sname→ id (and keepsname/description), mirroring thegemini/huggingface/clarifainormalizers already in the same config map. Entries without anameare dropped; on upstream error the route still falls back to the local catalog, so import never breaks.Test (TDD, Hard Rule #18)
tests/unit/cloudflare-models-uuid-4259.test.ts— mocks the Cloudflare/ai/models/searchresponse and asserts the discovered model ids are the@cf/...slugs, never the UUIDs. RED before the fix (ids were the UUIDs) → GREEN after.Validation
node --test tests/unit/cloudflare-models-uuid-4259.test.ts✅provider-models-route.test.ts+executor-cloudflare-ai.test.ts+ new test: 63/63 ✅typecheck:core✅ ·eslint(route) 0 errors ✅ ·check:file-size✅ (route.ts 2538→2554, baseline bumped with_rebaseline_2026_06_19_4259_cloudflare_uuid_models)