-
-
Notifications
You must be signed in to change notification settings - Fork 89
RG-T117 Chatbox fixes #451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,6 +121,8 @@ public async Task<ChatbotDepartmentConfig> SaveConfigAsync(ChatbotDepartmentConf | |
| else | ||
| config.LlmApiKey = _encryptionService.Encrypt(newPlaintextLlmKey); | ||
|
|
||
| ValidateColumnLengths(config); | ||
|
|
||
| if (existing == null) | ||
| { | ||
| config.Id = Guid.NewGuid().ToString("N"); | ||
|
|
@@ -151,6 +153,26 @@ public async Task InvalidateCacheAsync(int departmentId) | |
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Guards against SQL truncation (error 8152) by validating string fields against the | ||
| /// ChatbotDepartmentConfigs column sizes (M0068/M0070) before hitting the database. | ||
| /// LlmApiKey is checked post-encryption since the ciphertext is what gets stored. | ||
| /// </summary> | ||
| private static void ValidateColumnLengths(ChatbotDepartmentConfig config) | ||
| { | ||
| if (config.AllowedPlatforms != null && config.AllowedPlatforms.Length > 500) | ||
| throw new ArgumentException("AllowedPlatforms cannot exceed 500 characters.", nameof(config)); | ||
|
|
||
| if (config.LlmApiEndpoint != null && config.LlmApiEndpoint.Length > 500) | ||
| throw new ArgumentException("LlmApiEndpoint cannot exceed 500 characters.", nameof(config)); | ||
|
|
||
| if (config.LlmModelName != null && config.LlmModelName.Length > 200) | ||
| throw new ArgumentException("LlmModelName cannot exceed 200 characters.", nameof(config)); | ||
|
|
||
| if (config.LlmApiKey != null && config.LlmApiKey.Length > 1000) | ||
| throw new ArgumentException("Encrypted LlmApiKey cannot exceed 1000 characters; supply a shorter API key.", nameof(config)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win Map configuration validation failures to HTTP 400.
Use a typed validation exception or a shared validation result. Map it to 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| private static string CacheKey(int departmentId) => $"ChatbotDeptConfig_{departmentId}"; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,6 +55,14 @@ public async Task<IActionResult> Index(ChatbotSettingsModel model, CancellationT | |
| if (!await _authorizationService.CanUserModifyDepartmentAsync(UserId, DepartmentId)) | ||
| return Unauthorized(); | ||
|
|
||
| if (!ModelState.IsValid) | ||
| { | ||
| var existing = await _chatbotConfigService.GetConfigAsync(DepartmentId); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unguarded async operation occurs because the awaited call to Kody rule violation: Handle async operations with proper error handling Prompt for LLMTalk to Kody by mentioning @kody Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unguarded external call on line 60 leaves Kody rule violation: Add try-catch blocks for external calls Prompt for LLMTalk to Kody by mentioning @kody Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction. |
||
| model.HasLlmApiKey = !string.IsNullOrWhiteSpace(existing?.LlmApiKey); | ||
| model.LlmApiKey = null; | ||
| return View(model); | ||
| } | ||
|
|
||
| try | ||
| { | ||
| var config = new ChatbotDepartmentConfig | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Magic number obscures the inline column-size limit of 500, violating Rule [9] by breaking explicit schema contracts. Extract this literal to a private const (e.g.,
MaxAllowedPlatformsLength) for the length check and error message, and apply the same fix toCallsController.cs:1710and lines 166, 169, and 172 ofChatbotDepartmentConfigService.cs.Kody rule violation: Replace magic numbers with named constants
Prompt for LLM
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.