Fix membase json - #1391
Conversation
Refit 8's default serializer adds ObjectToInferredTypesConverter, so Dictionary<string, object?> response values arrive as string/double/Dictionary instead of JsonElement, silently emptying every consumer that does TryGetValue<JsonElement> (GraphBuilder, query_flow_graph, similarity search result parsing). Register the client with plain Web JsonSerializerOptions. Also fail with a clear message in ProviderHelper when no LlmProviders entry exists for the requested model instead of a NullReferenceException. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…t-serializer-fix Fix Membase Refit client deserializing graph values as inferred types
PR Summary by QodoFix Membase Refit JSON deserialization and improve missing-model error
AI Description
Diagram
High-Level Assessment
Files changed (3)
|
Code Review by Qodo
1. Whitespace API key bypass
|
| if (settings == null && string.IsNullOrEmpty(apiKey)) | ||
| { | ||
| throw new InvalidOperationException($"No LLM model settings found for '{provider}.{model}'. Register the model under LlmProviders (appsettings/user secrets) or pass an api key."); | ||
| } |
There was a problem hiding this comment.
1. Whitespace api key bypass 🐞 Bug ≡ Correctness
ProviderHelper.GetClient checks string.IsNullOrEmpty(apiKey), so a whitespace-only apiKey bypasses the new missing-settings guard and is still used to construct ApiKeyCredential. This can override a valid configured settings.ApiKey and cause late authentication failures instead of the intended clear configuration error.
Agent Prompt
### Issue description
`ProviderHelper.GetClient` currently treats whitespace-only `apiKey` values as present because it uses `string.IsNullOrEmpty(apiKey)`. This allows invalid keys (e.g., `" "`) to bypass the new guard and also overrides a valid configured `settings.ApiKey`, producing confusing downstream authentication failures.
### Issue Context
This was introduced with the new early validation logic added to `GetClient`.
### Fix Focus Areas
- src/Plugins/BotSharp.Plugin.OpenAI/Providers/ProviderHelper.cs[8-19]
### Suggested fix
- Normalize the candidate key and validate the *effective* key:
- Use `string.IsNullOrWhiteSpace(apiKey)` (and optionally `apiKey = apiKey?.Trim()`)
- Select `effectiveApiKey = !string.IsNullOrWhiteSpace(apiKey) ? apiKey.Trim() : settings?.ApiKey`
- Throw if `string.IsNullOrWhiteSpace(effectiveApiKey)`
- Construct `ApiKeyCredential(effectiveApiKey)`
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
No description provided.