This is an automated email from the ASF dual-hosted git repository.
lizhimins pushed a commit to branch rocketmq-studio
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git
The following commit(s) were added to refs/heads/rocketmq-studio by this push:
new bebafa36 [ISSUE #1613] Tolerate unavailable storage in AI chat (#1623)
bebafa36 is described below
commit bebafa3610e2491a8edddcff976efe8424510336
Author: 0 <[email protected]>
AuthorDate: Tue Aug 11 20:31:16 2026 +0800
[ISSUE #1613] Tolerate unavailable storage in AI chat (#1623)
---
web/src/api/ai.test.ts | 19 +++++++++++++++++++
web/src/api/ai.ts | 4 +++-
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/web/src/api/ai.test.ts b/web/src/api/ai.test.ts
index b01a7cb9..4475931d 100644
--- a/web/src/api/ai.test.ts
+++ b/web/src/api/ai.test.ts
@@ -57,6 +57,25 @@ describe('AI API', () => {
});
describe('chatStream (SSE)', () => {
+ it('continues without auth when browser storage is unavailable', async ()
=> {
+ vi.mocked(localStorage.getItem).mockImplementation(() => {
+ throw new DOMException('storage disabled', 'SecurityError');
+ });
+ const fetchMock = vi.fn().mockResolvedValue(streamResponse(['data:
[DONE]\n\n']));
+ vi.stubGlobal('fetch', fetchMock);
+
+ await expect(
+ chatStream({ message: 'hello', mode: 'chat', model: 'stub' }, vi.fn()),
+ ).resolves.toBeUndefined();
+
+ expect(fetchMock).toHaveBeenCalledWith(
+ '/api/ai/chat',
+ expect.objectContaining({
+ headers: { 'Content-Type': 'application/json' },
+ }),
+ );
+ });
+
it('reassembles an event split across network chunks', async () => {
vi.stubGlobal(
'fetch',
diff --git a/web/src/api/ai.ts b/web/src/api/ai.ts
index 541cc310..399538d6 100644
--- a/web/src/api/ai.ts
+++ b/web/src/api/ai.ts
@@ -16,6 +16,7 @@
*/
import client from './client';
+import { readAuthSession } from '../stores/authStorage';
// ─── Types ──────────────────────────────────────────────────────
export interface McpTool {
@@ -158,11 +159,12 @@ export async function chatStream(
signal?: AbortSignal,
onEnhance?: (prompt: string) => void,
) {
+ const token = readAuthSession().token;
const response = await fetch('/api/ai/chat', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
- Authorization: `Bearer ${localStorage.getItem('token') || ''}`,
+ ...(token ? { Authorization: `Bearer ${token}` } : {}),
},
body: JSON.stringify(data),
signal,