spring-projects / spring-ai

An Application Framework for AI Engineering
https://docs.spring.io/spring-ai/reference/index.html
Apache License 2.0
3.32k stars 850 forks source link

Refactor: Centralize event type checks into utility method #1765

Open cowboysj opened 2 days ago

cowboysj commented 2 days ago

Issue

1764

Changes

Simplified and Improved Code Readability

Added a new isInvalidEvent method to centralize common null checks and type validation logic. Refactored isToolUseStart and isToolUseFinish methods to remove redundant code and improve clarity. Improved Maintainability

By separating shared logic into the isInvalidEvent method, future changes to EventType handling or related logic will require minimal updates.

Why This Change Was Made

  1. To reduce code duplication and improve readability and maintainability.
  2. To make the logic more robust and easier to extend in the future by centralizing common checks.