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

   ### Which Issue(s) This PR Fixes
   
   - Fixes #6826
   
   ### Brief Description
   
   A failed LLM runtime load on `/ai` was a toast and nothing else: 
`useLlmRuntime` reported it through `onError` 
(`web/src/pages/ai/hooks/useLlmRuntime.ts:123-127`) and left `config` null, 
while every explanation the composer has — the not-ready banner 
(`Composer.tsx:314`), the provider status and its tag (`:417`, `:427`) — is 
behind `llmConfig`. Sending needs `llmReady` (`Composer.tsx:254`), so after the 
toast faded the page showed a dead send button with no reason and no retry.
   
   The hook now keeps the failure (`error: string | null`, cleared by a 
successful load or when the runtime is disabled) and the page renders it above 
the composer as an error alert carrying the server's message plus a Retry that 
reloads the runtime — the treatment this page already gives its timeline load 
failure (`index.tsx:189-205`), the settings tab since #6550 
(`AiAssistantTab.tsx:171-172`) and the home page in #6082.
   
   User-visible behaviour: an operator whose runtime could not be read is told 
so on the page and can retry, instead of being left with a disabled composer 
that cannot be told apart from an unconfigured provider.
   
   ### How Did You Test This Change?
   
   ```
   $ ./wb test
   ✓   npx eslint src/pages/ai/__tests__/AiPage.test.tsx 
src/pages/ai/hooks/useLlmRuntime.test.ts src/pages/ai/hooks/useLlmRuntime.ts 
src/pages/ai/index.tsx
   ✓   npx prettier --check src/pages/ai/__tests__/AiPage.test.tsx 
src/pages/ai/hooks/useLlmRuntime.test.ts src/pages/ai/hooks/useLlmRuntime.ts 
src/pages/ai/index.tsx
   ✓   npx vitest related --run src/pages/ai/__tests__/AiPage.test.tsx 
src/pages/ai/hooks/useLlmRuntime.test.ts src/pages/ai/hooks/useLlmRuntime.ts 
src/pages/ai/index.tsx
   ✓   npx tsc -b
   ```
   
   `AiPage.test.tsx` gains a case per failure shape (an `Error` and a `{}` 
rejection, the pair the failed-timeline-load case already uses): the page must 
render the alert, keep the composer disabled, and clear the alert after Retry 
re-requests the runtime (`getLlmConfig` twice, `getLlmModels` once). 
`useLlmRuntime.test.ts` pins the hook state itself: `error` carries the failure 
message, the toast callback still fires, and a successful `reload()` clears 
both the error and `llmReady: false`.
   
   The new tests fail without the fix:
   
   ```
    FAIL  src/pages/ai/__tests__/AiPage.test.tsx > AiPage > offers recovery for 
a failed LLM runtime load: Error: runtime unavailable
    FAIL  src/pages/ai/__tests__/AiPage.test.tsx > AiPage > offers recovery for 
a failed LLM runtime load: {}
   TestingLibraryElementError: Unable to find role="alert"
   
    FAIL  src/pages/ai/hooks/useLlmRuntime.test.ts > useLlmRuntime > surfaces 
the failed load for the page and clears it on a successful reload
   AssertionError: expected undefined to be 'runtime unavailable' // Object.is 
equality
   
    Test Files  2 failed | 19 passed (21)
         Tests  3 failed | 267 passed (270)
   ```
   
   ```
   src/pages/ai/hooks/useLlmRuntime.test.ts(193,27): error TS2339: Property 
'error' does not exist on type 'UseLlmRuntimeResult'.
   src/pages/ai/hooks/useLlmRuntime.test.ts(203,27): error TS2339: Property 
'error' does not exist on type 'UseLlmRuntimeResult'.
   ```
   
   That run is the branch with the two product files reverted (`git stash push` 
of `useLlmRuntime.ts` and `index.tsx`) and the new cases kept: nothing 
announces the failure, so the page's only alert is missing and the hook exposes 
no state for it.
   
   ### Other consumers
   
   - This page's toast (`index.tsx:83`) is kept: it announces the failure when 
it happens, the new banner is what stays on the page. Both carry the page's 
existing `ai.runtimeLoadFailed` string, so the two cannot disagree.
   - The settings tab (`AiAssistantTab.tsx:171-172`, #6550) and the home page 
(#6082) are the other two surfaces of this failure and are already handled 
there; they use the `llm.loadFailed` wording instead. Those files are outside 
this change, and unifying the two strings is a translation-table change, not 
this fix.
   - `useLlmRuntime`'s other state and behaviour are unchanged: the monotonic 
request id still drops a superseded response (including a failed one, which is 
why `error` is only set for the current request), and `reload()` is still the 
same `load`.
   - No new UI text is introduced: both strings already exist under 
`web/src/i18n/`.
   
   ### Checklist
   
   - [x] One coherent change; unrelated modifications are not bundled in
   - [x] Commit subject follows Conventional Commits (`feat:` / `fix:` / 
`refactor:` / `chore:` / `docs:` / `perf:`)
   - [x] Tests added or updated for non-trivial changes, test methods named 
`...Test`
   - [ ] New UI text has both Chinese and English entries under `web/src/i18n/`
   - [ ] Architecture constraints stay green (`mvn test` runs the ArchUnit 
checks)
   - [ ] New source files carry the ASF license header
   - [ ] Documentation touched where behaviour changed (README / `docs/` / 
in-app help)
   


-- 
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