Repository navigation
Port agent PRs to GO - 4 - #16652
Port agent PRs to GO - 4#16652
Conversation
📝 WalkthroughWalkthroughAdds shared attachment preview/download helpers and route wiring, updates document preview URL/header handling, and relaxes LLM thinking input forwarding with matching test updates. ChangesAttachment preview feature
LLM thinking input handling
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
internal/utility/file.go (1)
379-410: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winKeep the filename when forcing attachment.
Forced attachment responses currently drop the sanitized filename, so dangerous-but-downloadable files like HTML/SVG/XML lose their useful download name.
Proposed fix
func SetPreviewFileResponseHeaders(h http.Header, contentType, ext, filename string) { if contentType != "" { h.Set("Content-Type", contentType) } + safe := SanitizeContentDispositionFilename(filename) if ShouldForceAttachment(ext, contentType) { - h.Set("Content-Disposition", "attachment") + h.Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, safe)) h.Set("X-Content-Type-Options", "nosniff") } else { - safe := SanitizeContentDispositionFilename(filename) h.Set("Content-Disposition", fmt.Sprintf(`inline; filename="%s"`, safe)) } } @@ if ShouldForceAttachment(ext, contentType) { h.Set("X-Content-Type-Options", "nosniff") - h.Set("Content-Disposition", "attachment") + safe := SanitizeContentDispositionFilename(filename) + h.Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, safe)) return }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/utility/file.go` around lines 379 - 410, SetPreviewFileResponseHeaders and SetDownloadFileResponseHeaders currently drop the sanitized filename when ShouldForceAttachment triggers, so forced-attachment responses only send a bare attachment disposition. Update both paths to preserve the filename by using the sanitized value from SanitizeContentDispositionFilename in the Content-Disposition header even when falling back to attachment, while still keeping nosniff for the forced-attachment case.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/utility/file.go`:
- Around line 272-288: The MIME normalization in stripContentTypeParams
currently only trims when a semicolon is present, so plain values like "
text/html " are not normalized and ShouldForceAttachment may miss matches.
Update stripContentTypeParams to always trim surrounding whitespace, then remove
any ";" parameters if present, and keep ShouldForceAttachment using its
normalizedType result so content-type lookups are consistent for both
parameterized and non-parameterized inputs.
- Around line 319-336: The filename sanitizer in file.go still allows DEL
(0x7f), so update the control-character cleanup in the sanitization logic to
remove it as well. Adjust the regex in the filename sanitization path after the
strings.ReplaceAll steps, and ensure the helper that builds the sanitized
filename strips both ASCII control characters and DEL before returning the value
used for Content-Disposition.
- Around line 357-368: The MIME reverse-lookup in the file utility is
overwriting an explicit caller-provided extension, which can bypass
extension-based safety checks. Update the logic in the file parsing flow around
stripContentTypeParams, CONTENT_TYPE_MAP, and the ext assignment so that reverse
lookup only fills ext when it was not already provided, while still normalizing
contentType from mime_type. Keep the explicit ext value intact in the branch
that handles mimeType.
---
Nitpick comments:
In `@internal/utility/file.go`:
- Around line 379-410: SetPreviewFileResponseHeaders and
SetDownloadFileResponseHeaders currently drop the sanitized filename when
ShouldForceAttachment triggers, so forced-attachment responses only send a bare
attachment disposition. Update both paths to preserve the filename by using the
sanitized value from SanitizeContentDispositionFilename in the
Content-Disposition header even when falling back to attachment, while still
keeping nosniff for the forced-attachment case.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 04e7055d-125a-4d5f-b275-07933045a198
📒 Files selected for processing (5)
internal/agent/component/docs_generator.gointernal/handler/agent_attachment.gointernal/handler/document.gointernal/router/agent_routes.gointernal/utility/file.go
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/agent/component/llm_test.go (1)
232-239: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueCase 3 comment mentions "empty / missing" but only tests missing key.
Consider adding a sub-case with
"thinking": ""to explicitly exercise thev != ""branch, since the comment implies both are covered.Optional addition to Case 3
if defaulted.Thinking != "" { t.Errorf("Thinking = %q, want empty (system default)", defaulted.Thinking) } + + explicitEmpty := mergeLLMParam(LLMParam{}, map[string]any{ + "thinking": "", + "model_id": "glm-4.6", + "user_prompt": "u", + }) + if explicitEmpty.Thinking != "" { + t.Errorf("Thinking = %q, want empty (explicit empty string)", explicitEmpty.Thinking) + }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/agent/component/llm_test.go` around lines 232 - 239, Update the Case 3 test in mergeLLMParam to cover both “missing” and explicit empty input for the thinking field. Keep the existing missing-key assertion, and add a sub-case with thinking set to an empty string so the v != "" branch is exercised and verified to still yield an empty LLMParam.Thinking. Use mergeLLMParam and the Thinking field to locate the test.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@internal/agent/component/llm_test.go`:
- Around line 232-239: Update the Case 3 test in mergeLLMParam to cover both
“missing” and explicit empty input for the thinking field. Keep the existing
missing-key assertion, and add a sub-case with thinking set to an empty string
so the v != "" branch is exercised and verified to still yield an empty
LLMParam.Thinking. Use mergeLLMParam and the Thinking field to locate the test.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d115c9dd-e353-46a2-9822-077335032565
📒 Files selected for processing (7)
internal/agent/component/docs_generator.gointernal/agent/component/llm.gointernal/agent/component/llm_test.gointernal/handler/agent_attachment.gointernal/handler/document.gointernal/router/agent_routes.gointernal/utility/file.go
🚧 Files skipped from review as they are similar to previous changes (4)
- internal/router/agent_routes.go
- internal/agent/component/docs_generator.go
- internal/handler/document.go
- internal/utility/file.go
Summary
Port
#15399
#16469
#16640