Kris20030907 opened a new pull request, #523:
URL: https://github.com/apache/rocketmq-dashboard/pull/523

   ## What is the purpose of the change
   
   - Fixes #508
   
   ## Problem
   
   AI chat streaming uses `fetch` because the shared Axios client does not 
support
   the streaming response. This separate request path currently differs from the
   rest of the Studio API client in several ways:
   
   1. It calls the hard-coded `/api/ai/chat` URL instead of respecting
      `VITE_API_BASE_URL`.
   2. It sends `Authorization: Bearer ` even when no token is stored. A strict
      gateway or authentication middleware can reject this malformed credential.
   3. It discards the structured error message returned by the backend or 
gateway
      and only reports the HTTP status text.
   
   On the response side, the stub LLM gateway builds SSE JSON data with string
   concatenation. Messages containing JSON special characters such as quotes,
   backslashes, or line breaks can therefore produce invalid JSON.
   
   The frontend contract for `/api/ai/execute` also differs from its backend DTO
   and response VO. The frontend sends `message` and `tools` and expects
   `toolCalls`, while the backend accepts `command`, `prompt`, `context`, and
   `conversationId` and returns `success` and `result`. Calling the frontend 
helper
   therefore sends a null backend command and exposes a response shape that the
   server never returns.
   
   ## Reproduction
   
   ### Custom API endpoint
   
   1. Build the web application with
      `VITE_API_BASE_URL=https://api.example.test/custom-api`.
   2. Send an AI chat message.
   3. Observe that the request is sent to `/api/ai/chat` on the frontend origin
      instead of `https://api.example.test/custom-api/ai/chat`.
   
   ### Request and error handling
   
   1. Use Studio without a stored login token and send an AI chat message.
   2. Observe the empty `Authorization: Bearer ` request header.
   3. Return a JSON error such as:
   
      ```json
      {"code":502,"message":"LLM provider unavailable","data":null}
      ```
   
   4. Observe that the UI reports only the generic HTTP status text.
   
   ### SSE response encoding
   
   1. Send a message containing a quote or backslash to the current stub 
gateway.
   2. Inspect the emitted `data:` field.
   3. Observe that the special character is inserted into JSON without escaping.
   
   ### AI command contract
   
   1. Call the frontend `executeAiCommand` helper with its declared request 
type.
   2. Inspect the `/api/ai/execute` request and response.
   3. Observe that the frontend and backend use different request and response
      field names.
   
   ## Expected behavior
   
   AI chat streaming should follow the same API gateway contract as other Studio
   requests:
   
   - Use the configured API base URL.
   - Send the bearer header only when a token exists.
   - Preserve useful backend or gateway error messages.
   - Emit valid JSON SSE data for arbitrary message text.
   - Keep the `/api/ai/execute` TypeScript contract aligned with the backend DTO
     and response VO.
   
   ## Proposed change
   
   - Build the streaming endpoint from `API_BASE_URL`.
   - Reuse the shared token storage key and conditionally add the bearer header.
   - Read a structured `message` from failed HTTP responses, with the HTTP 
status
     as a fallback.
   - Serialize stub SSE payloads with Jackson instead of string concatenation.
   - Align the AI command request and result types with `AiCommandDTO` and
     `AiExecuteResultVO`.
   - Document the committed SSE event and AI command contracts.
   - Add focused frontend and backend regression tests.
   
   ## Scope
   
   This issue covers only the existing `/api/ai/chat` and `/api/ai/execute`
   request and response gateway contracts. It does not change SSE framing, the 
AI
   page UI, LLM settings, authentication lifecycle, or any third-party provider
   streaming protocol.
   
   ## Acceptance criteria
   
   - AI chat calls `${API_BASE_URL}/ai/chat`.
   - The default `/api` configuration continues to call `/api/ai/chat`.
   - A custom absolute URL or API prefix is respected.
   - Requests without a stored token omit the `Authorization` header.
   - Structured HTTP error messages are exposed to the caller.
   - Stub SSE payloads remain valid JSON when messages contain special 
characters.
   - AI command request and response types match the committed backend contract.
   - Existing AI stream tests continue to pass.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to