This is an automated email from the ASF dual-hosted git repository.
lizhimins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git
The following commit(s) were added to refs/heads/master by this push:
new 9367f6687 fix(home): report a failed assistant config load instead of
a dead input (#6082)
9367f6687 is described below
commit 9367f66875c5788a010c3eb840620ff0cf39cb59
Author: Apulupie <[email protected]>
AuthorDate: Fri Nov 27 12:55:32 2026 +0800
fix(home): report a failed assistant config load instead of a dead input
(#6082)
---
web/src/pages/home/__tests__/HomePage.test.tsx | 27 ++++++++++++++++++++
web/src/pages/home/index.tsx | 34 +++++++++++++++++++++++---
2 files changed, 58 insertions(+), 3 deletions(-)
diff --git a/web/src/pages/home/__tests__/HomePage.test.tsx
b/web/src/pages/home/__tests__/HomePage.test.tsx
index f1017e9d9..9b8ca9e98 100644
--- a/web/src/pages/home/__tests__/HomePage.test.tsx
+++ b/web/src/pages/home/__tests__/HomePage.test.tsx
@@ -205,6 +205,33 @@ describe('HomePage LLM models', () => {
state: { historyIntent: 'open' },
});
});
+
+ it('says the assistant configuration could not be loaded instead of leaving
the input dead', async () => {
+ llmApiMocks.getLlmConfig.mockRejectedValueOnce(new Error('offline'));
+ const user = userEvent.setup();
+ renderHome();
+
+ // The composer only explains a missing configuration when it has one, so
a failed load
+ // would otherwise leave the box disabled with no reason and no way to
retry.
+ expect(await screen.findByText('加载AI配置失败')).toBeInTheDocument();
+ const input = screen.getByPlaceholderText('向 RocketMQ Bot 提问,全程加密、安全、可信');
+ await user.type(input, '查看集群状态{enter}');
+ expect(navigateMock).not.toHaveBeenCalled();
+
+ await user.click(screen.getByRole('button', { name: /重\s*试/ }));
+
+ await waitFor(() =>
expect(llmApiMocks.getLlmConfig).toHaveBeenCalledTimes(2));
+ await waitFor(() =>
expect(screen.queryByText('加载AI配置失败')).not.toBeInTheDocument());
+ expect(await
screen.findByTestId('ai-provider-status')).toBeInTheDocument();
+
+ await user.clear(input);
+ await user.type(input, '查看集群状态{enter}');
+ await waitFor(() => {
+ expect(navigateMock).toHaveBeenCalledWith('/ai', {
+ state: expect.objectContaining({ prompt: '查看集群状态' }),
+ });
+ });
+ });
});
describe('HomePage footer', () => {
diff --git a/web/src/pages/home/index.tsx b/web/src/pages/home/index.tsx
index c834b7e94..e1ad9c93b 100644
--- a/web/src/pages/home/index.tsx
+++ b/web/src/pages/home/index.tsx
@@ -17,7 +17,7 @@
import { useState, useRef, useEffect, useCallback } from 'react';
import { useNavigate } from 'react-router-dom';
-import { ConfigProvider, theme, App } from 'antd';
+import { Alert, Button, ConfigProvider, theme, App } from 'antd';
import {
Stethoscope,
ChatCircleDots,
@@ -89,6 +89,8 @@ const HomePage = () => {
const [promoteOn, setPromoteOn] = useState(false);
const [inputValue, setInputValue] = useState('');
const [llmConfig, setLlmConfig] = useState<LlmConfig | null>(null);
+ const [llmConfigLoadFailed, setLlmConfigLoadFailed] = useState(false);
+ const [llmConfigReloadNonce, setLlmConfigReloadNonce] = useState(0);
const [indicatorStyle, setIndicatorStyle] = useState({ width: 83, left: 6 });
const modeBarRef = useRef<HTMLDivElement>(null);
const navigate = useNavigate();
@@ -115,9 +117,18 @@ const HomePage = () => {
);
return;
}
- const config = await getLlmConfig().catch(() => null);
+ let config: LlmConfig | null = null;
+ let loadFailed = false;
+ try {
+ config = await getLlmConfig();
+ } catch {
+ // Storing the failure as "no config" left the composer silent: it
disables sending
+ // whenever the config is not ready, but only explains itself when a
config is present.
+ loadFailed = true;
+ }
if (cancelled) return;
setLlmConfig(config);
+ setLlmConfigLoadFailed(loadFailed);
const configuredModel = config?.model?.trim() ?? '';
const values = Array.from(
@@ -143,7 +154,7 @@ const HomePage = () => {
return () => {
cancelled = true;
};
- }, []);
+ }, [llmConfigReloadNonce]);
/* ─── Mode switch handler ─── */
const handleModeSwitch = useCallback((key: string, btn: HTMLButtonElement)
=> {
@@ -408,6 +419,23 @@ const HomePage = () => {
</div>
</div>
+ {llmConfigLoadFailed && (
+ <Alert
+ type="error"
+ showIcon
+ message={t('llm.loadFailed')}
+ action={
+ <Button
+ size="small"
+ onClick={() => setLlmConfigReloadNonce((nonce) => nonce
+ 1)}
+ >
+ {t('common.retry')}
+ </Button>
+ }
+ style={{ marginBottom: 12 }}
+ />
+ )}
+
{/* Main Input Box — the SAME Composer component as the AI page,
so the input
panel has one source of truth; home-specific bits are props.
*/}
<Composer