Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✨ feat(conversation): add a support action slot to the chat error card (#20978)

LiJiancdd40c1a0e8f
diff --git a/locales/en-US/common.json b/locales/en-US/common.json
index 1a13bb93638..91d1843193d 100644
--- a/locales/en-US/common.json
+++ b/locales/en-US/common.json
@@ -433,6 +433,7 @@
"supportAgent.starter.feedback": "I want to report a problem or suggest a feature",
"supportAgent.starter.modelError": "A model call failed. How do I troubleshoot it?",
"supportAgent.title": "Lobe Support",
+ "supportAgent.troubleshoot.question": "This message failed. Please help me troubleshoot it.",
"supportAgent.welcome": "Hi, I'm the Lobe support assistant. Ask me how something works, tell me what went wrong, or leave feedback for the team. I'm an AI, so double-check anything important.",
"supportAgent.working": "Looking into it…",
"switch": "Switch",
diff --git a/locales/en-US/error.json b/locales/en-US/error.json
index 338011563da..31144abafe2 100644
--- a/locales/en-US/error.json
+++ b/locales/en-US/error.json
@@ -151,6 +151,7 @@
"unknownError.sharedTitle": "Unable to generate this answer",
"unknownError.title": "Oops, the request took a nap",
"unknownError.traceIdLabel": "Trace ID:",
+ "unknownError.troubleshoot": "Troubleshoot",
"unlock.addProxyUrl": "Add OpenAI proxy URL (optional)",
"unlock.apiKey.description": "Enter your {{name}} API Key to start the session",
"unlock.apiKey.imageGenerationDescription": "Enter your {{name}} API Key to start generating",
diff --git a/locales/zh-CN/common.json b/locales/zh-CN/common.json
index a50189c776c..4c236c61c74 100644
--- a/locales/zh-CN/common.json
+++ b/locales/zh-CN/common.json
@@ -433,6 +433,7 @@
"supportAgent.starter.feedback": "我想反馈一个问题或提个建议",
"supportAgent.starter.modelError": "模型调用报错了,该怎么排查?",
"supportAgent.title": "Lobe 答疑助手",
+ "supportAgent.troubleshoot.question": "这条消息报错了,帮我排查一下",
"supportAgent.welcome": "你好,我是 Lobe 答疑助手。功能怎么用、哪里报错了、想给团队提建议,都可以直接告诉我。我是 AI,重要信息请再核实一下。",
"supportAgent.working": "正在查找相关信息…",
"switch": "切换",
diff --git a/locales/zh-CN/error.json b/locales/zh-CN/error.json
index 7a40b7dd020..9a1607e6956 100644
--- a/locales/zh-CN/error.json
+++ b/locales/zh-CN/error.json
@@ -151,6 +151,7 @@
"unknownError.sharedTitle": "无法生成这条回答",
"unknownError.title": "糟糕,请求打了个盹",
"unknownError.traceIdLabel": "追踪 ID:",
+ "unknownError.troubleshoot": "一键排查",
"unlock.addProxyUrl": "添加 OpenAI 代理地址(可选)",
"unlock.apiKey.description": "输入你的 {{name}} API Key,即可开始会话",
"unlock.apiKey.imageGenerationDescription": "输入你的 {{name}} API Key,即可开始生成",
diff --git a/packages/locales/src/default/common.ts b/packages/locales/src/default/common.ts
index 9dae41bbdcb..320b984233f 100644
--- a/packages/locales/src/default/common.ts
+++ b/packages/locales/src/default/common.ts
@@ -53,6 +53,7 @@ export default {
'Current topic is not saved, please save it first to use subtopic feature',
'forkRequiresSavedTopic': 'Current topic is not saved. Save it first to fork a new topic',
'forkTopic': 'Continue in new topic',
+ 'supportAgent.troubleshoot.question': 'This message failed. Please help me troubleshoot it.',
'viewExecutionDetails': 'View execution details',
'cancel': 'Cancel',
'changelog': 'Changelog',
diff --git a/packages/locales/src/default/error.ts b/packages/locales/src/default/error.ts
index 5e8b712b5e2..bcb29ff44de 100644
--- a/packages/locales/src/default/error.ts
+++ b/packages/locales/src/default/error.ts
@@ -220,6 +220,7 @@ export default {
'This workspace is frozen by an admin and cannot run requests. Please contact the workspace owner to resolve the issue.',
'response.WorkspaceFrozenByRiskControl':
'This workspace was auto-frozen by risk control and cannot run requests. Please contact support to review the status.',
+ 'unknownError.troubleshoot': 'Troubleshoot',
'workspaceBillingInactive.bannerHint': 'Click for details',
'workspaceBillingInactive.bannerTitle': 'Workspace subscription inactive',
'workspaceBillingInactive.confirm': 'Got it',
diff --git a/src/business/client/features/ChatErrorSupportAction/index.tsx b/src/business/client/features/ChatErrorSupportAction/index.tsx
new file mode 100644
index 00000000000..339c2be23e4
--- /dev/null
+++ b/src/business/client/features/ChatErrorSupportAction/index.tsx
@@ -0,0 +1,20 @@
+import type { ChatMessageError } from '@lobechat/types';
+
+/**
+ * Everything the error card knows about the failed message, handed to a
+ * deployment that can act on it (for example by opening a support channel).
+ */
+export interface ChatErrorSupportActionProps {
+ agentId?: string;
+ error?: ChatMessageError | null;
+ groupId?: string;
+ messageId: string;
+ model?: string;
+ provider?: string;
+ threadId?: string;
+ topicId?: string;
+ traceId?: string;
+}
+
+/** Rendered beside the error card's retry button. Nothing by default. */
+export const ChatErrorSupportAction = (_props: ChatErrorSupportActionProps) => null;
diff --git a/src/features/Conversation/Error/TraceIdError.tsx b/src/features/Conversation/Error/TraceIdError.tsx
index 40ced037059..af4e0a0a2f1 100644
--- a/src/features/Conversation/Error/TraceIdError.tsx
+++ b/src/features/Conversation/Error/TraceIdError.tsx
@@ -1,5 +1,6 @@
import { SOCIAL_URL } from '@lobechat/business-const';
-import { copyToClipboard, Icon } from '@lobehub/ui';
+import type { ChatMessageError } from '@lobechat/types';
+import { copyToClipboard, Flexbox, Icon } from '@lobehub/ui';
import { Button, toast } from '@lobehub/ui/base-ui';
import { DiscordIcon } from '@lobehub/ui/icons';
import { cssVar } from 'antd-style';
@@ -7,101 +8,121 @@ import { AlertTriangle, Copy, RotateCw } from 'lucide-react';
import { memo, useCallback } from 'react';
import { useTranslation } from 'react-i18next';
+import { ChatErrorSupportAction } from '@/business/client/features/ChatErrorSupportAction';
import BaseErrorForm from '@/features/Conversation/Error/BaseErrorForm';
+import { useConversationStore } from '@/features/Conversation/store';
+import { useFailedMessage } from './useFailedMessage';
import { useRetryParentMessage } from './useRetryParentMessage';
interface TraceIdErrorProps {
+ error?: ChatMessageError | null;
id: string;
onRetry?: () => Promise<void> | void;
showRetry?: boolean;
traceId?: string;
}
-const TraceIdError = memo<TraceIdErrorProps>(({ id, onRetry, showRetry = true, traceId }) => {
- const { t } = useTranslation('error');
- const { disabled, loading, retryParentMessage } = useRetryParentMessage(id);
+const TraceIdError = memo<TraceIdErrorProps>(
+ ({ error, id, onRetry, showRetry = true, traceId }) => {
+ const { t } = useTranslation('error');
+ const { disabled, loading, retryParentMessage } = useRetryParentMessage(id);
+ const context = useConversationStore((s) => s.context);
+ const message = useFailedMessage(id);
- const handleCopyTraceId = useCallback(async () => {
- if (!traceId) return;
+ const handleCopyTraceId = useCallback(async () => {
+ if (!traceId) return;
- try {
- await copyToClipboard(traceId);
- toast.success(t('unknownError.copyTraceId'));
- } catch {
- /* noop */
- }
- }, [t, traceId]);
+ try {
+ await copyToClipboard(traceId);
+ toast.success(t('unknownError.copyTraceId'));
+ } catch {
+ /* noop */
+ }
+ }, [t, traceId]);
- const handleRetry = useCallback(() => {
- if (onRetry) {
- void onRetry();
- return;
- }
+ const handleRetry = useCallback(() => {
+ if (onRetry) {
+ void onRetry();
+ return;
+ }
- void retryParentMessage();
- }, [onRetry, retryParentMessage]);
+ void retryParentMessage();
+ }, [onRetry, retryParentMessage]);
- return (
- <BaseErrorForm
- avatar={<Icon icon={AlertTriangle} size={24} />}
- title={t(showRetry ? 'unknownError.title' : 'unknownError.sharedTitle')}
- action={
- showRetry ? (
- <Button
- disabled={!onRetry && disabled}
- icon={<Icon icon={RotateCw} />}
- loading={!onRetry && loading}
- size={'small'}
- type={'primary'}
- onClick={handleRetry}
- >
- {t('unknownError.retry')}
- </Button>
- ) : undefined
- }
- desc={
- <span>
- {t(showRetry ? 'unknownError.desc' : 'unknownError.sharedDesc')}{' '}
- <a
- href={SOCIAL_URL.discord}
- rel="noopener noreferrer"
- target="_blank"
- style={{
- alignItems: 'center',
- color: '#5865F2',
- display: 'inline-flex',
- gap: 2,
- verticalAlign: 'middle',
- }}
- >
- <Icon icon={DiscordIcon} size={14} />
- Discord
- </a>
- {traceId && (
- <>
- {' · '}
- {t('unknownError.traceIdLabel')}{' '}
- <code
- title={t('unknownError.copyTraceIdTooltip')}
- style={{
- cursor: 'pointer',
- opacity: 0.65,
- textDecoration: 'underline dashed',
- textDecorationColor: cssVar.colorTextQuaternary,
- textUnderlineOffset: 3,
- }}
- onClick={handleCopyTraceId}
+ return (
+ <BaseErrorForm
+ avatar={<Icon icon={AlertTriangle} size={24} />}
+ title={t(showRetry ? 'unknownError.title' : 'unknownError.sharedTitle')}
+ action={
+ showRetry ? (
+ <Flexbox horizontal gap={8}>
+ <ChatErrorSupportAction
+ agentId={context.agentId}
+ error={error ?? message?.error}
+ groupId={context.groupId ?? undefined}
+ messageId={id}
+ model={message?.model ?? undefined}
+ provider={message?.provider ?? undefined}
+ threadId={context.threadId ?? undefined}
+ topicId={context.topicId ?? undefined}
+ traceId={traceId}
+ />
+ <Button
+ disabled={!onRetry && disabled}
+ icon={<Icon icon={RotateCw} />}
+ loading={!onRetry && loading}
+ type={'primary'}
+ onClick={handleRetry}
>
- {traceId}
- <Icon icon={Copy} size={11} style={{ marginLeft: 3, verticalAlign: 'middle' }} />
- </code>
- </>
- )}
- </span>
- }
- />
- );
-});
+ {t('unknownError.retry')}
+ </Button>
+ </Flexbox>
+ ) : undefined
+ }
+ desc={
+ <span>
+ {t(showRetry ? 'unknownError.desc' : 'unknownError.sharedDesc')}{' '}
+ <a
+ href={SOCIAL_URL.discord}
+ rel="noopener noreferrer"
+ target="_blank"
+ style={{
+ alignItems: 'center',
+ color: '#5865F2',
+ display: 'inline-flex',
+ gap: 2,
+ verticalAlign: 'middle',
+ }}
+ >
+ <Icon icon={DiscordIcon} size={14} />
+ Discord
+ </a>
+ {traceId && (
+ <>
+ {' · '}
+ {t('unknownError.traceIdLabel')}{' '}
+ <code
+ title={t('unknownError.copyTraceIdTooltip')}
+ style={{
+ cursor: 'pointer',
+ opacity: 0.65,
+ textDecoration: 'underline dashed',
+ textDecorationColor: cssVar.colorTextQuaternary,
+ textUnderlineOffset: 3,
+ }}
+ onClick={handleCopyTraceId}
+ >
+ {traceId}
+ <Icon icon={Copy} size={11} style={{ marginLeft: 3, verticalAlign: 'middle' }} />
+ </code>
+ </>
+ )}
+ </span>
+ }
+ />
+ );
+ },
+);
export default TraceIdError;
diff --git a/src/features/Conversation/Error/index.tsx b/src/features/Conversation/Error/index.tsx
index 56691cad9df..718dda405af 100644
--- a/src/features/Conversation/Error/index.tsx
+++ b/src/features/Conversation/Error/index.tsx
@@ -572,6 +572,7 @@ const ErrorMessageExtra = memo<ErrorExtraProps>(
return (
<TraceIdError
+ error={error}
id={data.id}
showRetry={!isSharedTopic}
traceId={traceId}
diff --git a/src/features/Conversation/Error/useFailedMessage.test.ts b/src/features/Conversation/Error/useFailedMessage.test.ts
new file mode 100644
index 00000000000..a957b81c6db
--- /dev/null
+++ b/src/features/Conversation/Error/useFailedMessage.test.ts
@@ -0,0 +1,54 @@
+import { renderHook } from '@testing-library/react';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+import { dataSelectors } from '@/features/Conversation/store/slices/data/selectors';
+
+import { useFailedMessage } from './useFailedMessage';
+
+const storeMock = vi.hoisted(() => ({ state: {} as Record<string, unknown> }));
+
+vi.mock('@/features/Conversation/store', () => ({
+ dataSelectors,
+ useConversationStore: (selector: (state: Record<string, unknown>) => unknown) =>
+ selector(storeMock.state),
+}));
+
+const blockError = { message: 'upstream timed out', type: 'InternalServerError' };
+
+describe('useFailedMessage', () => {
+ beforeEach(() => {
+ storeMock.state = {
+ // An assistant group shows up as one top-level row; its failed step is a child block.
+ dbMessages: [
+ {
+ error: blockError,
+ id: 'msg_block',
+ model: 'gpt-x',
+ provider: 'openai',
+ role: 'assistant',
+ },
+ ],
+ displayMessages: [
+ { children: [{ id: 'msg_block' }], id: 'msg_group', role: 'assistantGroup' },
+ ],
+ };
+ });
+
+ it('resolves a failed block inside an assistant group', () => {
+ const { result } = renderHook(() => useFailedMessage('msg_block'));
+
+ expect(result.current).toMatchObject({
+ error: blockError,
+ model: 'gpt-x',
+ provider: 'openai',
+ });
+ });
+
+ it('falls back to display messages that have no stored row', () => {
+ storeMock.state.displayMessages = [{ id: 'msg_member', model: 'gpt-y', role: 'assistant' }];
+
+ const { result } = renderHook(() => useFailedMessage('msg_member'));
+
+ expect(result.current).toMatchObject({ model: 'gpt-y' });
+ });
+});
diff --git a/src/features/Conversation/Error/useFailedMessage.ts b/src/features/Conversation/Error/useFailedMessage.ts
new file mode 100644
index 00000000000..a8bd1db89ba
--- /dev/null
+++ b/src/features/Conversation/Error/useFailedMessage.ts
@@ -0,0 +1,11 @@
+import { dataSelectors, useConversationStore } from '@/features/Conversation/store';
+
+/**
+ * The stored row behind an error card. Inside an assistant group the card's `id` is a
+ * child block, which is not a top-level display message; its persisted row still
+ * carries the error, model and provider.
+ */
+export const useFailedMessage = (id: string) =>
+ useConversationStore(
+ (s) => dataSelectors.getDbMessageById(id)(s) ?? dataSelectors.getDisplayMessageById(id)(s),
+ );