Allows Mistral byok to be used for Codestral#4000
Conversation
|
|
||
| const byokProviderKey = fimProvider === 'mistral' ? 'codestral' : 'inception'; | ||
| const byokProviderKeys: UserByokProviderId[] = | ||
| fimProvider === 'mistral' ? ['codestral', 'mistral'] : ['inception']; |
There was a problem hiding this comment.
WARNING: BYOK key priority not honoured — DB orderBy(created_at) overrides the ['codestral', 'mistral'] intent
getBYOKforUser/getBYOKforOrganization query with inArray(byok_api_keys.provider_id, providerIds) and orderBy(byok_api_keys.created_at). SQL's IN (…) clause does not preserve the input array order, so when a user has both a codestral key and a mistral key the DB returns them oldest-first.
userByok?.at(0) (line 237) then picks the oldest key regardless of which provider it is. If the mistral key was created before the codestral key, the codestral key is silently ignored and the user's Mistral La Plateforme key is used with api.mistral.ai — the correct endpoint for that key type, but the codestral key preference is lost.
To honour the priority ordering, consider re-sorting the returned entries client-side by their position in byokProviderKeys before calling .at(0):
const sorted = userByok?.slice().sort(
(a, b) => byokProviderKeys.indexOf(a.providerId) - byokProviderKeys.indexOf(b.providerId)
);
const userByokEntry = sorted?.at(0);Reply with @kilocode-bot fix it to have Kilo Code address this issue.
| return []; | ||
| } | ||
| if (isCodestralModel(modelId)) { | ||
| providers.splice(0, 0, 'codestral'); |
There was a problem hiding this comment.
SUGGESTION: Array.prototype.splice is mutating — prefer unshift or a spread
providers.splice(0, 0, 'codestral') works here because the array is local, but providers.unshift('codestral') is the conventional way to prepend in-place, and ['codestral', ...providers] (reassigning the const) makes the intent most readable. Neither change is required for correctness, but the current idiom is surprising to readers who expect splice for removal, not insertion at index 0.
Reply with @kilocode-bot fix it to have Kilo Code address this issue.
Code Review SummaryStatus: 2 Issues Found | Recommendation: Address before merge Executive SummaryThe Overview
Issue Details (click to expand)WARNING
SUGGESTION
Files Reviewed (4 files)
Fix these issues in Kilo Cloud Reviewed by claude-4.6-sonnet-20260217 · 905,544 tokens Review guidance: REVIEW.md from base branch |
No description provided.