Skip to content

Port agent PRs to GO - 4 - #16652

Merged
yuzhichang merged 2 commits into
infiniflow:mainfrom
qinling0210:port_to_go
Jul 6, 2026
Merged

yuzhichang merged 2 commits into
infiniflow:mainfrom
qinling0210:port_to_go

Conversation

@qinling0210

@qinling0210 qinling0210 commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Port

#15399
#16469
#16640

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 6, 2026
@qinling0210 qinling0210 self-assigned this Jul 6, 2026
@coderabbitai

coderabbitai Bot commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds shared attachment preview/download helpers and route wiring, updates document preview URL/header handling, and relaxes LLM thinking input forwarding with matching test updates.

Changes

Attachment preview feature

Layer / File(s) Summary
Content-type and header utilities
internal/utility/file.go
Adds content-type normalization, filename sanitization, attachment content-type resolution, preview/download response header helpers, and preview path construction.
Attachment streaming handlers and route
internal/handler/agent_attachment.go, internal/router/agent_routes.go
Adds shared attachment request parsing and streaming, refactors download and preview handlers to use the shared path, and registers GET /attachments/:attachment_id/preview.
Preview URL generation and document preview headers
internal/agent/component/docs_generator.go, internal/handler/document.go
DocsGenerator computes and returns preview_url and documents it in Outputs(), and GetDocumentPreview delegates header construction to the shared preview helper.

LLM thinking input handling

Layer / File(s) Summary
Thinking override handling
internal/agent/component/llm.go
Updates mergeLLMParam so non-empty, non-"default" thinking values are forwarded into LLMParam.Thinking.
Thinking round-trip test updates
internal/agent/component/llm_test.go
Adjusts the TestLLM_ThinkingFieldRoundTrip comments and cases to match the new forwarding behavior for empty, default, and arbitrary thinking values.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

  • infiniflow/ragflow#15399: Implements the same agent attachment preview flow with matching preview URL generation and shared header handling.

Suggested labels: 💞 feature

Suggested reviewers: yuzhichang

Poem

A rabbit hops through headers new,
Preview or download — pick your view!
One URL springs for files to see,
And thinking modes now roam more free.
🐇📄

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description only says "Port" and links two PRs, so it misses the required summary and background context. Add a brief Summary explaining what was ported, why it matters, and any key context from the linked PRs.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the main change: porting agent PRs to Go in the fourth batch.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
internal/utility/file.go (1)

379-410: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Keep 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

📥 Commits

Reviewing files that changed from the base of the PR and between 358152f and 71a110d.

📒 Files selected for processing (5)
  • internal/agent/component/docs_generator.go
  • internal/handler/agent_attachment.go
  • internal/handler/document.go
  • internal/router/agent_routes.go
  • internal/utility/file.go

Comment thread internal/utility/file.go Resolved
Comment thread internal/utility/file.go Resolved
Comment thread internal/utility/file.go Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
internal/agent/component/llm_test.go (1)

232-239: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Case 3 comment mentions "empty / missing" but only tests missing key.

Consider adding a sub-case with "thinking": "" to explicitly exercise the v != "" 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

📥 Commits

Reviewing files that changed from the base of the PR and between 71a110d and 26feeb1.

📒 Files selected for processing (7)
  • internal/agent/component/docs_generator.go
  • internal/agent/component/llm.go
  • internal/agent/component/llm_test.go
  • internal/handler/agent_attachment.go
  • internal/handler/document.go
  • internal/router/agent_routes.go
  • internal/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

@yuzhichang yuzhichang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jul 6, 2026
@yuzhichang
yuzhichang merged commit 3d2f60c into infiniflow:main Jul 6, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants