Skip to content

refactor(provider): extract helpers from normalizeMessages#31599

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

refactor(provider): extract helpers from normalizeMessages#31599
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. 👍

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants