Skip to content

refactor: routing logic moved from frontend to backend#765

Merged
Avijit-Microsoft merged 3 commits intodevfrom
rc-psl-routing
Mar 12, 2026
Merged

refactor: routing logic moved from frontend to backend#765
Avijit-Microsoft merged 3 commits intodevfrom
rc-psl-routing

Conversation

@Ragini-Microsoft
Copy link
Collaborator

Purpose

This pull request refactors the frontend API layer and introduces a new backend routing service to centralize and standardize message intent detection and routing logic. The changes simplify the frontend API surface, unify message handling, and move previously frontend-based routing logic into a dedicated backend service. Additionally, the backend is now better equipped for intent-based message processing, and related tests have been updated accordingly.

Frontend API Refactor and Unification:

  • Consolidated multiple frontend API functions (parseBrief, confirmBrief, selectProducts, streamChat, etc.) into a single sendMessage function for sending messages/actions to the /api/chat endpoint, and introduced a unified MessageRequest/MessageResponse type. This streamlines the frontend-backend communication and reduces duplicated logic. [1] [2]
  • Updated the streamGenerateContent and content generation polling functions to use a single GenerateRequest payload, improving consistency and maintainability.
  • Added a new pollTaskStatus function to poll for task completion (including image regeneration), replacing the previous streaming implementation for image regeneration.

Backend Routing Service Introduction:

  • Added a new routing_service.py module that encapsulates message classification and intent detection logic. This service mirrors and replaces the routing previously done in the frontend and provides a clear, testable interface for determining user intent based on message content and conversation state.

Test Updates:

  • Updated tests to use the new unified /api/chat endpoint and to check for correct intent routing (e.g., PARSE_BRIEF intent for title generation). Adjusted mocks and assertions to match the new backend logic and API surface. [1] [2] [3] [4]

These changes collectively modernize the codebase by centralizing routing logic, simplifying the frontend API, and improving maintainability and testability.

Most important changes:

Frontend API Refactor:

  • Unified multiple message-related API calls into a single sendMessage function and introduced MessageRequest/MessageResponse types, simplifying frontend-backend communication. [1] [2]
  • Changed content generation and polling functions to use a standardized GenerateRequest payload and added pollTaskStatus for task polling. [1] [2]

Backend Routing Service:

  • Introduced routing_service.py, a backend service for message intent classification and routing, moving logic from the frontend to the backend for better maintainability and testability.

Test Adjustments:

  • Updated tests to use the new /api/chat endpoint, reflecting the new routing and intent detection logic, and adjusted mocks accordingly. [1] [2] [3] [4]

Does this introduce a breaking change?

  • Yes
  • No

Golden Path Validation

  • I have tested the primary workflows (the "golden path") to ensure they function correctly without errors.

Deployment Validation

  • I have validated the deployment process successfully and all services are running as expected with this change.

@Avijit-Microsoft Avijit-Microsoft merged commit 721884f into dev Mar 12, 2026
5 checks passed
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