Repository navigation
fix(gitlawb): add specialty validators for connection test — bypass /models probe - #2837
Conversation
…models probe GitLawB OpenGateway API (xiaomi-mimo compatible) does not expose a /models endpoint, causing validateOpenAILikeProvider to 404 on the initial probe and report 'Provider validation endpoint not supported'. Add specialty validators for both gitlawb and gitlawb-gmi that follow the same pattern as the existing xiaomi-mimo validator: skip GET /models, validate directly via POST /chat/completions with a minimal test message. Any 401/403 response means an invalid key; all other responses mean auth is OK. Fixes test-connection returning 404 for GitLawB providers.
|
Kilo Code Review could not run — your account is out of credits. Add credits or switch to a free model to enable reviews on this change. |
There was a problem hiding this comment.
Code Review
This pull request adds validation support for the gitlawb and gitlawb-gmi providers in src/lib/providers/validation.ts by bypassing the /models probe in favor of a /chat/completions request. The reviewer recommended refactoring the two new validators to eliminate code duplication by extracting a shared helper function. Additionally, the reviewer noted that unit tests must be added to cover these new validators, as required by Rule 9 of the Repository Style Guide when modifying production code.
| // Gitlawb Opengateway — Xiaomi MiMo compatible, same /models endpoint limitation. | ||
| // Bypass /models probe in favor of chat/completions, matching xiaomi-mimo's pattern. | ||
| gitlawb: async ({ apiKey, providerSpecificData }: any) => { | ||
| try { | ||
| const baseUrl = normalizeBaseUrl( | ||
| providerSpecificData?.baseUrl || "https://opengateway.gitlawb.com/v1/xiaomi-mimo" | ||
| ); | ||
| const chatUrl = `${baseUrl.replace(/\/chat\/completions$/, "")}/chat/completions`; | ||
| const res = await validationWrite( | ||
| chatUrl, | ||
| { | ||
| method: "POST", | ||
| headers: buildBearerHeaders(apiKey, providerSpecificData), | ||
| body: JSON.stringify({ | ||
| model: "mimo-v2.5-pro", | ||
| messages: [{ role: "user", content: "test" }], | ||
| max_tokens: 1, | ||
| }), | ||
| }, | ||
| isLocal | ||
| ); | ||
| if (res.status === 401 || res.status === 403) { | ||
| return { valid: false, error: "Invalid API key" }; | ||
| } | ||
| // Any non-auth response (200, 400, 422, 429) means auth passed | ||
| return { valid: true, error: null }; | ||
| } catch (error: any) { | ||
| return toValidationErrorResult(error); | ||
| } | ||
| }, | ||
| "gitlawb-gmi": async ({ apiKey, providerSpecificData }: any) => { | ||
| try { | ||
| const baseUrl = normalizeBaseUrl( | ||
| providerSpecificData?.baseUrl || "https://opengateway.gitlawb.com/v1/gmi-cloud" | ||
| ); | ||
| const chatUrl = `${baseUrl.replace(/\/chat\/completions$/, "")}/chat/completions`; | ||
| const res = await validationWrite( | ||
| chatUrl, | ||
| { | ||
| method: "POST", | ||
| headers: buildBearerHeaders(apiKey, providerSpecificData), | ||
| body: JSON.stringify({ | ||
| model: "XiaomiMiMo/MiMo-V2.5-Pro", | ||
| messages: [{ role: "user", content: "test" }], | ||
| max_tokens: 1, | ||
| }), | ||
| }, | ||
| isLocal | ||
| ); | ||
| if (res.status === 401 || res.status === 403) { | ||
| return { valid: false, error: "Invalid API key" }; | ||
| } | ||
| // Any non-auth response (200, 400, 422, 429) means auth passed | ||
| return { valid: true, error: null }; | ||
| } catch (error: any) { | ||
| return toValidationErrorResult(error); | ||
| } | ||
| }, |
There was a problem hiding this comment.
Code Duplication
The specialty validators for gitlawb and gitlawb-gmi are virtually identical, differing only in their default base URLs and model IDs. This duplication can be avoided by extracting a shared validation helper function using an inline IIFE. This improves maintainability and prevents future logic drift between the two providers.
// Gitlawb Opengateway — Xiaomi MiMo compatible, same /models endpoint limitation.
// Bypass /models probe in favor of chat/completions, matching xiaomi-mimo's pattern.
...(() => {
const validate = async ({ apiKey, providerSpecificData, defaultBaseUrl, model }: any) => {
try {
const baseUrl = normalizeBaseUrl(providerSpecificData?.baseUrl || defaultBaseUrl);
const chatUrl = `${baseUrl.replace(/\/chat\/completions$/, "")}/chat/completions`;
const res = await validationWrite(
chatUrl,
{
method: "POST",
headers: buildBearerHeaders(apiKey, providerSpecificData),
body: JSON.stringify({
model,
messages: [{ role: "user", content: "test" }],
max_tokens: 1,
}),
},
isLocal
);
if (res.status === 401 || res.status === 403) {
return { valid: false, error: "Invalid API key" };
}
return { valid: true, error: null };
} catch (error: any) {
return toValidationErrorResult(error);
}
};
return {
gitlawb: (args: any) =>
validate({
...args,
defaultBaseUrl: "https://opengateway.gitlawb.com/v1/xiaomi-mimo",
model: "mimo-v2.5-pro",
}),
"gitlawb-gmi": (args: any) =>
validate({
...args,
defaultBaseUrl: "https://opengateway.gitlawb.com/v1/gmi-cloud",
model: "XiaomiMiMo/MiMo-V2.5-Pro",
}),
};
})(),| }, | ||
| // Gitlawb Opengateway — Xiaomi MiMo compatible, same /models endpoint limitation. | ||
| // Bypass /models probe in favor of chat/completions, matching xiaomi-mimo's pattern. | ||
| gitlawb: async ({ apiKey, providerSpecificData }: any) => { |
There was a problem hiding this comment.
Missing Tests for Production Code Change
According to the Repository Style Guide (Rule 9), changing production code under src/ requires including tests. Please ensure that appropriate unit tests are added in the tests/ directory to cover these new specialty validators for gitlawb and gitlawb-gmi.
References
- Rule 9: Always include tests when changing production code (src/, open-sse/, electron/, bin/). (link)
…y validators Covers success, auth failure (401/403), non-auth acceptance (400/422/429), network errors, and custom baseUrl overrides for both providers.
…ble warning GitLawB's OpenGateway API does not expose a /models endpoint per provider-path. Previously the models route fell through to the generic fallback which returned static catalog models with the misleading 'API unavailable — using local catalog' warning. Now gitlawb and gitlawb-gmi are handled as static model providers (same pattern as reka and qwen OAuth) — models are served from the provider registry without any warning, since all registered models are functional via POST /chat/completions.
…docs path in test - Extract gitlawb/gitlawb-gmi validators into buildOpengatewayValidator factory - Fix dockerignore-docs-coverage test: update stale docs/AUTO-COMBO.md -> docs/routing/AUTO-COMBO.md
Hybrid approach: - gitlawb (xiaomi-mimo): dynamic /models endpoint → 356 models - gitlawb-gmi (gmi-cloud): 404 fallback → local catalog gracefully Mimics Gitlawb/openclaude's model-routing pattern
e73a2ea
into
diegosouzapw:release/v3.8.6
Problem
The GitLawB OpenGateway API (xiaomi-mimo compatible) returns 404 on connection test for both
gitlawbandgitlawb-gmiproviders. This causes the dashboard to show persistent "error" status for these connections even with valid API keys.Additionally, the models list endpoint showed a misleading
"API unavailable — using local catalog"warning for gitlawb providers, even though all registered models are fully functional viaPOST /chat/completions.Root Cause
Connection test
The generic
validateOpenAILikeProvidervalidation flow works in two stages:{baseUrl}/models(e.g.,https://opengateway.gitlawb.com/v1/xiaomi-mimo/models) — returns 404 because the OpenGateway API does not expose a models endpoint at that provider-path.Result:
validateProviderApiKeyreturns"Provider validation endpoint not supported", and the connection is permanently marked as "error" with a 404 diagnosis.Models list
Since
gitlawbandgitlawb-gmiare not inPROVIDER_MODELS_CONFIG, the models route fell through to the generic fallback which returns static catalog models with the warning"API unavailable — using local catalog". This warning is misleading — the models are fully functional.Changes
1. Connection test fix (src/lib/providers/validation.ts)
Add specialty validators for both
gitlawbandgitlawb-gmiin theSPECIALTY_VALIDATORSmap. These mirror the existingxiaomi-mimovalidator — since all three use the same underlying API format:/chat/completionswith a minimal test messagegitlawbhttps://opengateway.gitlawb.com/v1/xiaomi-mimomimo-v2.5-progitlawb-gmihttps://opengateway.gitlawb.com/v1/gmi-cloudXiaomiMiMo/MiMo-V2.5-Pro2. Models list fix (src/app/api/providers/[id]/models/route.ts)
Add
gitlawbandgitlawb-gmias static model providers (same pattern asrekaandqwenOAuth). Models are served from the provider registry without the misleading"API unavailable"warning, since all registered models are functional via the chat completions endpoint.3. Unit tests (tests/unit/provider-validation-specialty.test.ts)
Add 12 new tests covering both providers:
Testing
Connection test
Unit tests
Models list
Related
b83d1a0fc)