Skip to content

refactor(provider): extract helpers from normalizeMessages - #31599

Closed
szzhoujiarui-sketch wants to merge 4 commits into
anomalyco:devfrom
szzhoujiarui-sketch:refactor/transform-normalize-messages
Closed

szzhoujiarui-sketch wants to merge 4 commits into
anomalyco:devfrom
szzhoujiarui-sketch:refactor/transform-normalize-messages

Conversation

@szzhoujiarui-sketch

@szzhoujiarui-sketch szzhoujiarui-sketch commented Jun 10, 2026

Copy link
Copy Markdown
  • Extract shouldKeepContentPart, filterEmptyContentParts for Anthropic/Bedrock
  • Extract scrubToolCallIds for Claude and Mistral tool call ID scrubbing
  • Extract addDeepseekReasoning for Deepseek reasoning injection
  • Extract extractInterleavedReasoning for interleaved models
  • Extract sanitizeMessage and sanitizeToolResultOutput for message cleanup
  • Remove TODO comment, add step-by-step comments in main function
  • Net reduction: 34 lines (182 insertions, 216 deletions)

Issue for this PR

Closes #

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Refactors the normalizeMessages function to improve readability and maintainability.

  • Extracts 6 helper functions for provider-specific logic
  • Removes duplicate Anthropic/Bedrock empty content filtering code
  • Adds step-by-step comments documenting the transformation pipeline
  • Net reduction: 34 lines (182 insertions, 216 deletions)
  • No behavioral changes, all existing tests pass

If you paste a large clearly AI generated description here your PR may be IGNORED or CLOSED!

How did you verify your code works?

  • Ran all existing tests: bun test test/provider/transform.test.ts → 259 pass, 0 fail
  • Typecheck passes: bun typecheck
  • No behavioral changes verified by test results

Screenshots / recordings

If this is a UI change, please include a screenshot or recording.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

If you do not follow this template your PR will be automatically rejected.

- Extract shouldKeepContentPart, filterEmptyContentParts for Anthropic/Bedrock
- Extract scrubToolCallIds for Claude and Mistral tool call ID scrubbing
- Extract addDeepseekReasoning for Deepseek reasoning injection
- Extract extractInterleavedReasoning for interleaved models
- Extract sanitizeMessage and sanitizeToolResultOutput for message cleanup
- Remove TODO comment, add step-by-step comments in main function
- Net reduction: 34 lines (182 insertions, 216 deletions)
Co-authored-by: monkeycode-ai <monkeycode-ai@chaitin.com>
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Jun 10, 2026
@szzhoujiarui-sketch

Copy link
Copy Markdown
Author

Refactors the normalizeMessages function in packages/opencode/src/provider/transform.ts to improve readability and maintainability.

  • Extracts 6 helper functions for provider-specific logic
  • Removes duplicate Anthropic/Bedrock empty content filtering code
  • Adds step-by-step comments documenting the transformation pipeline
  • Net reduction: 34 lines (182 insertions, 216 deletions)
  • No behavioral changes, all existing tests pass
  • Ran all existing tests: bun test test/provider/transform.test.ts → 259 pass, 0 fail
  • Typecheck passes: bun typecheck
  • No behavioral changes verified by test results

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Jun 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants