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(agent-doc): graduate the floating chat panel out of labs (#16978)

Arvin Xua9e0dacba181
diff --git a/locales/ar/labs.json b/locales/ar/labs.json
index 8ba11aa7d99..999a6c9dcc0 100644
--- a/locales/ar/labs.json
+++ b/locales/ar/labs.json
@@ -1,6 +1,4 @@
{
- "features.agentDocumentFloatingChatPanel.desc": "عرض لوحة الدردشة العائمة في معاينة مستند الوكيل فقط عند تمكين هذه الميزة التجريبية.",
- "features.agentDocumentFloatingChatPanel.title": "لوحة الدردشة العائمة لمستند الوكيل",
"features.agentSelfIteration.desc": "السماح للمساعد بالتفكير الذاتي، وبناء الوعي الذاتي، والاستمرار في التطوير عبر المحاولات والتفاعلات المتواصلة.",
"features.agentSelfIteration.title": "التكرار الذاتي للوكيل",
"features.assistantMessageGroup.desc": "تجميع رسائل الوكيل ونتائج استدعاء الأدوات معًا للعرض",
diff --git a/locales/bg-BG/labs.json b/locales/bg-BG/labs.json
index 766dcc01858..0eb26803957 100644
--- a/locales/bg-BG/labs.json
+++ b/locales/bg-BG/labs.json
@@ -1,6 +1,4 @@
{
- "features.agentDocumentFloatingChatPanel.desc": "Показване на плаващия чат панел в прегледа на документи на агент само когато тази лабораторна функция е активирана.",
- "features.agentDocumentFloatingChatPanel.title": "Плаващ чат панел за документи на агент",
"features.agentSelfIteration.desc": "Позволява на асистента да разсъждава, да изгражда самосъзнание и да извършва непрекъснати подобрения чрез последователни опити и взаимодействия.",
"features.agentSelfIteration.title": "Само-итерация на агента",
"features.assistantMessageGroup.desc": "Групиране на съобщенията от агента и резултатите от извикванията на инструменти заедно за показване",
diff --git a/locales/de-DE/labs.json b/locales/de-DE/labs.json
index 05fdf3730ce..0eccb71c8d3 100644
--- a/locales/de-DE/labs.json
+++ b/locales/de-DE/labs.json
@@ -1,6 +1,4 @@
{
- "features.agentDocumentFloatingChatPanel.desc": "Zeigen Sie das schwebende Chat-Panel in der Dokumentvorschau des Agenten nur an, wenn diese Lab-Funktion aktiviert ist.",
- "features.agentDocumentFloatingChatPanel.title": "Schwebendes Chat-Panel für Agentendokumente",
"features.agentSelfIteration.desc": "Ermöglicht dem Assistenten, zu reflektieren, Selbstwahrnehmung aufzubauen und sich durch fortlaufende Versuche und Interaktionen kontinuierlich weiterzuentwickeln.",
"features.agentSelfIteration.title": "Agenten-Selbstiteration",
"features.assistantMessageGroup.desc": "Agenten-Nachrichten und deren Tool-Ergebnisse gemeinsam anzeigen",
diff --git a/locales/en-US/labs.json b/locales/en-US/labs.json
index 3c254e4d07f..63238bccb6a 100644
--- a/locales/en-US/labs.json
+++ b/locales/en-US/labs.json
@@ -1,6 +1,4 @@
{
- "features.agentDocumentFloatingChatPanel.desc": "Show the floating chat panel in agent document preview only when this lab feature is enabled.",
- "features.agentDocumentFloatingChatPanel.title": "Agent Document Floating Chat Panel",
"features.agentGraphConfig.desc": "Show graph runtime configuration in an agent profile advanced settings.",
"features.agentGraphConfig.title": "Agent Graph Runtime Configuration",
"features.agentSelfIteration.desc": "Allow the agent to reflect, build self-awareness, and continuously iterate through ongoing attempts and interactions.",
diff --git a/locales/es-ES/labs.json b/locales/es-ES/labs.json
index e4c5f45b572..e0fc40a24dd 100644
--- a/locales/es-ES/labs.json
+++ b/locales/es-ES/labs.json
@@ -1,6 +1,4 @@
{
- "features.agentDocumentFloatingChatPanel.desc": "Mostrar el panel de chat flotante en la vista previa del documento del agente solo cuando esta función experimental esté habilitada.",
- "features.agentDocumentFloatingChatPanel.title": "Panel de Chat Flotante del Documento del Agente",
"features.agentSelfIteration.desc": "Permite que el asistente reflexione, desarrolle autoconsciencia y realice iteraciones continuas a lo largo de intentos e interacciones.",
"features.agentSelfIteration.title": "Autoiteración del agente",
"features.assistantMessageGroup.desc": "Agrupa los mensajes del agente y los resultados de sus herramientas para mostrarlos juntos",
diff --git a/locales/fa-IR/labs.json b/locales/fa-IR/labs.json
index 976e1b29052..2d5ca97c887 100644
--- a/locales/fa-IR/labs.json
+++ b/locales/fa-IR/labs.json
@@ -1,6 +1,4 @@
{
- "features.agentDocumentFloatingChatPanel.desc": "نمایش پنل چت شناور در پیش‌نمایش سند نماینده تنها زمانی که این ویژگی آزمایشی فعال باشد.",
- "features.agentDocumentFloatingChatPanel.title": "پنل چت شناور سند نماینده",
"features.agentSelfIteration.desc": "به دستیار امکان می‌دهد درباره عملکرد خود تأمل کند، خودآگاهی ایجاد کند و از طریق تلاش‌ها و تعاملات مداوم به طور پیوسته بهبود یابد.",
"features.agentSelfIteration.title": "خود‌تکراری عامل",
"features.assistantMessageGroup.desc": "نمایش گروهی پیام‌های عامل و نتایج ابزارهای فراخوانی‌شده به‌صورت یکجا",
diff --git a/locales/fr-FR/labs.json b/locales/fr-FR/labs.json
index 005729eb7e2..b168859fa20 100644
--- a/locales/fr-FR/labs.json
+++ b/locales/fr-FR/labs.json
@@ -1,6 +1,4 @@
{
- "features.agentDocumentFloatingChatPanel.desc": "Afficher le panneau de chat flottant dans l'aperçu du document de l'agent uniquement lorsque cette fonctionnalité expérimentale est activée.",
- "features.agentDocumentFloatingChatPanel.title": "Panneau de Chat Flottant pour Document d'Agent",
"features.agentSelfIteration.desc": "Permet à l’assistant de réfléchir, de développer une conscience de soi et d’itérer en continu à travers des tentatives et des interactions successives.",
"features.agentSelfIteration.title": "Auto‑itération de l’agent",
"features.assistantMessageGroup.desc": "Regroupez les messages de l'agent et les résultats de leurs appels d'outils pour les afficher ensemble",
diff --git a/locales/it-IT/labs.json b/locales/it-IT/labs.json
index 2e491ea7fc3..b5f26dade12 100644
--- a/locales/it-IT/labs.json
+++ b/locales/it-IT/labs.json
@@ -1,6 +1,4 @@
{
- "features.agentDocumentFloatingChatPanel.desc": "Mostra il pannello di chat flottante nell'anteprima del documento dell'agente solo quando questa funzione di laboratorio è abilitata.",
- "features.agentDocumentFloatingChatPanel.title": "Pannello di Chat Flottante per Documenti Agente",
"features.agentSelfIteration.desc": "Consenti all'assistente di riflettere, sviluppare autoconsapevolezza e iterare continuamente attraverso tentativi e interazioni continui.",
"features.agentSelfIteration.title": "Auto-iterazione dell'agente",
"features.assistantMessageGroup.desc": "Raggruppa i messaggi dell'agente e i risultati delle chiamate agli strumenti per una visualizzazione unificata",
diff --git a/locales/ja-JP/labs.json b/locales/ja-JP/labs.json
index 3e368439dc7..96b69c7a50d 100644
--- a/locales/ja-JP/labs.json
+++ b/locales/ja-JP/labs.json
@@ -1,6 +1,4 @@
{
- "features.agentDocumentFloatingChatPanel.desc": "このラボ機能が有効になっている場合にのみ、エージェントドキュメントプレビューで浮動チャットパネルを表示します。",
- "features.agentDocumentFloatingChatPanel.title": "エージェントドキュメント浮動チャットパネル",
"features.agentSelfIteration.desc": "アシスタントが振り返りを行い、自己認識を深め、継続的な試行と対話を通じて自律的に改善を重ねられるようにします。",
"features.agentSelfIteration.title": "エージェントの自己反復",
"features.assistantMessageGroup.desc": "アシスタントのメッセージとそのツール呼び出し結果をグループ化して表示します",
diff --git a/locales/ko-KR/labs.json b/locales/ko-KR/labs.json
index d349e32144a..755a5bc3446 100644
--- a/locales/ko-KR/labs.json
+++ b/locales/ko-KR/labs.json
@@ -1,6 +1,4 @@
{
- "features.agentDocumentFloatingChatPanel.desc": "이 실험실 기능이 활성화된 경우에만 에이전트 문서 미리보기에서 떠 있는 채팅 패널을 표시합니다.",
- "features.agentDocumentFloatingChatPanel.title": "에이전트 문서 떠 있는 채팅 패널",
"features.agentSelfIteration.desc": "어시스턴트가 스스로를 성찰하고 자기 인식을 구축하며, 지속적인 시도와 상호작용을 통해 계속해서 발전할 수 있도록 합니다.",
"features.agentSelfIteration.title": "에이전트 자기 반복",
"features.assistantMessageGroup.desc": "도우미 메시지와 해당 도구 호출 결과를 그룹으로 묶어 표시합니다",
diff --git a/locales/nl-NL/labs.json b/locales/nl-NL/labs.json
index 2761c61391c..2e20f981628 100644
--- a/locales/nl-NL/labs.json
+++ b/locales/nl-NL/labs.json
@@ -1,6 +1,4 @@
{
- "features.agentDocumentFloatingChatPanel.desc": "Toon het zwevende chatpaneel in de documentvoorvertoning van de agent alleen wanneer deze labfunctie is ingeschakeld.",
- "features.agentDocumentFloatingChatPanel.title": "Zwevend Chatpaneel voor Agentdocumenten",
"features.agentSelfIteration.desc": "De assistent kan hierdoor reflecteren, zelfinzicht opbouwen en zich continu blijven verbeteren via aanhoudende pogingen en interacties.",
"features.agentSelfIteration.title": "Agent-zelfiteratie",
"features.assistantMessageGroup.desc": "Groepeer berichten van de agent en de resultaten van hun tool-aanroepen samen voor weergave",
diff --git a/locales/pl-PL/labs.json b/locales/pl-PL/labs.json
index d1252271a6d..dd9a8a14e7c 100644
--- a/locales/pl-PL/labs.json
+++ b/locales/pl-PL/labs.json
@@ -1,6 +1,4 @@
{
- "features.agentDocumentFloatingChatPanel.desc": "Pokaż pływający panel czatu w podglądzie dokumentu agenta tylko wtedy, gdy ta funkcja laboratoryjna jest włączona.",
- "features.agentDocumentFloatingChatPanel.title": "Pływający Panel Czatu Dokumentu Agenta",
"features.agentSelfIteration.desc": "Pozwala asystentowi na refleksję, budowanie samoświadomości oraz ciągłe doskonalenie poprzez kolejne próby i interakcje.",
"features.agentSelfIteration.title": "Samoiteracja agenta",
"features.assistantMessageGroup.desc": "Grupuj wiadomości agenta i wyniki wywołań narzędzi razem do wyświetlenia",
diff --git a/locales/pt-BR/labs.json b/locales/pt-BR/labs.json
index 8b5232f15df..72a47489e95 100644
--- a/locales/pt-BR/labs.json
+++ b/locales/pt-BR/labs.json
@@ -1,6 +1,4 @@
{
- "features.agentDocumentFloatingChatPanel.desc": "Exibir o painel de chat flutuante na visualização de documentos do agente apenas quando este recurso experimental estiver habilitado.",
- "features.agentDocumentFloatingChatPanel.title": "Painel de Chat Flutuante de Documentos do Agente",
"features.agentSelfIteration.desc": "Permite que o assistente reflita, desenvolva autoconsciência e faça iterações contínuas por meio de tentativas e interações contínuas.",
"features.agentSelfIteration.title": "Autoiteração do Agente",
"features.assistantMessageGroup.desc": "Agrupe mensagens do agente e os resultados das chamadas de ferramentas para exibição conjunta",
diff --git a/locales/ru-RU/labs.json b/locales/ru-RU/labs.json
index 17d41ae150d..271313d62ab 100644
--- a/locales/ru-RU/labs.json
+++ b/locales/ru-RU/labs.json
@@ -1,6 +1,4 @@
{
- "features.agentDocumentFloatingChatPanel.desc": "Показывать плавающую панель чата в предварительном просмотре документа агента только при включении этой экспериментальной функции.",
- "features.agentDocumentFloatingChatPanel.title": "Плавающая панель чата документа агента",
"features.agentSelfIteration.desc": "Позволяет помощнику проводить самоанализ, формировать самосознание и постоянно совершенствоваться через непрерывные попытки и взаимодействия.",
"features.agentSelfIteration.title": "Самоитерация агента",
"features.assistantMessageGroup.desc": "Группируйте сообщения агента и результаты вызова инструментов для совместного отображения",
diff --git a/locales/tr-TR/labs.json b/locales/tr-TR/labs.json
index b17c5024a9b..72aaeb94b8d 100644
--- a/locales/tr-TR/labs.json
+++ b/locales/tr-TR/labs.json
@@ -1,6 +1,4 @@
{
- "features.agentDocumentFloatingChatPanel.desc": "Yalnızca bu laboratuvar özelliği etkinleştirildiğinde, ajan belge önizlemesinde yüzer sohbet panelini göster.",
- "features.agentDocumentFloatingChatPanel.title": "Ajan Belgesi Yüzer Sohbet Paneli",
"features.agentSelfIteration.desc": "Asistanın düşünmesini, öz farkındalık geliştirmesini ve devam eden denemeler ile etkileşimler boyunca sürekli yineleme yapmasını sağlar.",
"features.agentSelfIteration.title": "Aracının Kendi Kendine Yinelemesi",
"features.assistantMessageGroup.desc": "Temsilci mesajlarını ve bunlara ait araç çağrısı sonuçlarını birlikte gruplayarak görüntüleyin",
diff --git a/locales/vi-VN/labs.json b/locales/vi-VN/labs.json
index c51ad4a2d4a..9ababf045b9 100644
--- a/locales/vi-VN/labs.json
+++ b/locales/vi-VN/labs.json
@@ -1,6 +1,4 @@
{
- "features.agentDocumentFloatingChatPanel.desc": "Hiển thị bảng trò chuyện nổi trong chế độ xem trước tài liệu của đại lý chỉ khi tính năng thử nghiệm này được bật.",
- "features.agentDocumentFloatingChatPanel.title": "Bảng Trò Chuyện Nổi Tài Liệu Đại Lý",
"features.agentSelfIteration.desc": "Cho phép trợ lý tự phản tư, xây dựng khả năng tự nhận thức và liên tục cải thiện thông qua các nỗ lực và tương tác đang diễn ra.",
"features.agentSelfIteration.title": "Tự lặp của tác nhân",
"features.assistantMessageGroup.desc": "Nhóm các tin nhắn của tác nhân và kết quả gọi công cụ lại với nhau để hiển thị",
diff --git a/locales/zh-CN/labs.json b/locales/zh-CN/labs.json
index 27512aab172..5f0b20e5672 100644
--- a/locales/zh-CN/labs.json
+++ b/locales/zh-CN/labs.json
@@ -1,6 +1,4 @@
{
- "features.agentDocumentFloatingChatPanel.desc": "仅当启用此实验功能时,在代理文档预览中显示浮动聊天面板。",
- "features.agentDocumentFloatingChatPanel.title": "代理文档浮动聊天面板",
"features.agentGraphConfig.desc": "在助理档案的进阶设置中显示 Graph 运行时配置。",
"features.agentGraphConfig.title": "Agent Graph 运行时配置",
"features.agentSelfIteration.desc": "允许助理自我反思、自我感知,并在持续的尝试与交互中不断自我迭代。",
diff --git a/locales/zh-TW/labs.json b/locales/zh-TW/labs.json
index 25b23319d99..4aad02ec02f 100644
--- a/locales/zh-TW/labs.json
+++ b/locales/zh-TW/labs.json
@@ -1,6 +1,4 @@
{
- "features.agentDocumentFloatingChatPanel.desc": "僅在啟用此實驗功能時,於代理文件預覽中顯示浮動聊天面板。",
- "features.agentDocumentFloatingChatPanel.title": "代理文件浮動聊天面板",
"features.agentSelfIteration.desc": "允許助理進行反思、建立自我認知,並透過持續的嘗試與互動不斷迭代提升。",
"features.agentSelfIteration.title": "代理自我迭代",
"features.assistantMessageGroup.desc": "將助手訊息及其工具調用結果彙整成群組顯示",
diff --git a/packages/const/src/user.ts b/packages/const/src/user.ts
index 1db47e6a5c3..ce4436a043b 100644
--- a/packages/const/src/user.ts
+++ b/packages/const/src/user.ts
@@ -13,7 +13,6 @@ export const DEFAULT_PREFERENCE: UserPreference = {
topic: true,
},
lab: {
- enableAgentDocumentFloatingChatPanel: false,
enableAgentGraphConfig: false,
enableAgentSelfIteration: false,
enableFleet: false,
diff --git a/packages/locales/src/default/labs.ts b/packages/locales/src/default/labs.ts
index a6b294224c1..801fd18a8f8 100644
--- a/packages/locales/src/default/labs.ts
+++ b/packages/locales/src/default/labs.ts
@@ -1,7 +1,4 @@
export default {
- 'features.agentDocumentFloatingChatPanel.desc':
- 'Show the floating chat panel in agent document preview only when this lab feature is enabled.',
- 'features.agentDocumentFloatingChatPanel.title': 'Agent Document Floating Chat Panel',
'features.agentGraphConfig.desc':
'Show graph runtime configuration in an agent profile advanced settings.',
'features.agentGraphConfig.title': 'Agent Graph Runtime Configuration',
diff --git a/packages/types/src/user/preference.ts b/packages/types/src/user/preference.ts
index e5d1d42c2c1..f765ec6636d 100644
--- a/packages/types/src/user/preference.ts
+++ b/packages/types/src/user/preference.ts
@@ -46,10 +46,6 @@ export const UserLabSchema = z.object({
* enable agent self-iteration feedback capture and policy execution
*/
enableAgentSelfIteration: z.boolean().optional(),
- /**
- * enable the floating chat panel in agent document preview
- */
- enableAgentDocumentFloatingChatPanel: z.boolean().optional(),
/**
* enable the Fleet view (side-by-side running-task dashboard)
*/
diff --git a/src/features/AgentDocumentPage/index.test.tsx b/src/features/AgentDocumentPage/index.test.tsx
index 1edb6e9238e..3e81843275b 100644
--- a/src/features/AgentDocumentPage/index.test.tsx
+++ b/src/features/AgentDocumentPage/index.test.tsx
@@ -68,8 +68,18 @@ const docChatTopicState = vi.hoisted(() => ({
topicId: 'doc-topic-1' as string | undefined,
},
}));
+// Record the params so a test can assert the lookup never fires for a doc this
+// agent doesn't own — `getOrCreateChatTopic` would answer NOT_FOUND.
+const docChatTopicCalls = vi.hoisted(() => ({ current: [] as Record<string, unknown>[] }));
vi.mock('@/features/FloatingChatPanel/useDocumentChatTopic', () => ({
- useDocumentChatTopic: () => docChatTopicState.current,
+ // Mirror the real hook's `enabled` gate: with either id missing it never fetches,
+ // so it can only ever return `topicId: undefined`.
+ useDocumentChatTopic: (params: Record<string, unknown>) => {
+ docChatTopicCalls.current.push(params);
+ if (!params.agentId || !params.documentId)
+ return { error: undefined, isLoading: false, topicId: undefined };
+ return docChatTopicState.current;
+ },
}));
const panelProps = vi.hoisted(() => ({
@@ -83,25 +93,8 @@ vi.mock('@/features/FloatingChatPanel', () => ({
},
}));
-const mockUserState = vi.hoisted(() => ({
- current: {
- preference: { lab: { enableAgentDocumentFloatingChatPanel: false } },
- },
-}));
-vi.mock('@/store/user', () => ({
- useUserStore: (selector: any) => selector(mockUserState.current),
-}));
-
-vi.mock('@/store/user/selectors', () => ({
- labPreferSelectors: {
- enableAgentDocumentFloatingChatPanel: (s: any) =>
- s.preference.lab.enableAgentDocumentFloatingChatPanel,
- },
-}));
-
describe('AgentDocumentPage', () => {
beforeEach(() => {
- mockUserState.current.preference.lab.enableAgentDocumentFloatingChatPanel = false;
agentDocumentItemState.current = {
error: undefined,
isNotFound: false,
@@ -116,6 +109,7 @@ describe('AgentDocumentPage', () => {
};
headerProps.current = undefined;
panelProps.current = undefined;
+ docChatTopicCalls.current = [];
navigateMock.mockClear();
});
@@ -151,13 +145,7 @@ describe('AgentDocumentPage', () => {
expect(headerProps.current).toMatchObject({ itemError });
});
- it('does not render FloatingChatPanel when the lab feature is disabled', () => {
- render(<AgentDocumentPage documentId="docs_abc" />);
- expect(screen.queryByTestId('floating-chat-panel')).toBeNull();
- });
-
it('renders FloatingChatPanel anchored on the URL agent + doc-scoped topic', () => {
- mockUserState.current.preference.lab.enableAgentDocumentFloatingChatPanel = true;
render(<AgentDocumentPage documentId="docs_abc" />);
const container = screen.getByTestId('wide-screen-container');
@@ -172,9 +160,33 @@ describe('AgentDocumentPage', () => {
});
it('skips the panel until the doc-anchored topic id resolves', () => {
- mockUserState.current.preference.lab.enableAgentDocumentFloatingChatPanel = true;
docChatTopicState.current = { error: undefined, isLoading: true, topicId: undefined };
render(<AgentDocumentPage documentId="docs_abc" />);
expect(screen.queryByTestId('floating-chat-panel')).toBeNull();
});
+
+ // `item` comes from this agent's own document list, so it doubles as the
+ // ownership proof `getOrCreateChatTopic` requires. Until it resolves, looking up
+ // the topic could only produce a NOT_FOUND.
+ it('does not look up the doc topic before the agent is known to own the document', () => {
+ agentDocumentItemState.current = { ...agentDocumentItemState.current, item: undefined };
+
+ render(<AgentDocumentPage documentId="docs_abc" />);
+
+ expect(screen.queryByTestId('floating-chat-panel')).toBeNull();
+ expect(docChatTopicCalls.current.length).toBeGreaterThan(0);
+ for (const call of docChatTopicCalls.current) {
+ expect(call.agentId).toBeUndefined();
+ expect(call.documentId).toBeUndefined();
+ }
+ });
+
+ it('looks up the doc topic once the document is resolved on this agent', () => {
+ render(<AgentDocumentPage documentId="docs_abc" />);
+
+ expect(docChatTopicCalls.current.at(-1)).toMatchObject({
+ agentId: 'agent-from-url',
+ documentId: 'docs_abc',
+ });
+ });
});
diff --git a/src/features/AgentDocumentPage/index.tsx b/src/features/AgentDocumentPage/index.tsx
index 4f876023ca1..e8d4becc084 100644
--- a/src/features/AgentDocumentPage/index.tsx
+++ b/src/features/AgentDocumentPage/index.tsx
@@ -9,8 +9,6 @@ import { useDocumentChatTopic } from '@/features/FloatingChatPanel/useDocumentCh
import { PageEditor } from '@/features/PageEditor';
import WideScreenContainer from '@/features/WideScreenContainer';
import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';
-import { useUserStore } from '@/store/user';
-import { labPreferSelectors } from '@/store/user/selectors';
import Header from './Header';
import { buildAgentDocumentsPath } from './navigation';
@@ -40,16 +38,17 @@ const AgentDocumentPage = memo<AgentDocumentPageProps>(({ documentId }) => {
skillBundle,
} = useAgentDocumentItem(agentId, documentId);
- const enableFloatingChatPanel = useUserStore(
- labPreferSelectors.enableAgentDocumentFloatingChatPanel,
- );
// The route owns the agent — `useChatStore.activeAgentId` can be a different
// agent (the user's main chat context). Pulling that one would 404 the
// doc-anchored topic lookup whenever the active agent doesn't own this doc.
const chatAgentId = agentId;
+ // `item` is resolved out of *this agent's* document list, so its presence is the
+ // ownership proof `getOrCreateChatTopic` demands. Waiting for it keeps a bad deep
+ // link from firing a guaranteed-NOT_FOUND lookup before the redirect kicks in.
+ const ownsDocument = !!item;
const { topicId: docChatTopicId } = useDocumentChatTopic({
- agentId: enableFloatingChatPanel ? chatAgentId : undefined,
- documentId: enableFloatingChatPanel ? documentId : undefined,
+ agentId: ownsDocument ? chatAgentId : undefined,
+ documentId: ownsDocument ? documentId : undefined,
});
const backToChat = useCallback(
@@ -122,7 +121,7 @@ const AgentDocumentPage = memo<AgentDocumentPageProps>(({ documentId }) => {
onTitleChange={() => mutate()}
/>
</Flexbox>
- {enableFloatingChatPanel && chatAgentId && docChatTopicId && (
+ {chatAgentId && docChatTopicId && (
<WideScreenContainer>
<FloatingChatPanel
agentDocumentId={item?.id}
diff --git a/src/features/Portal/Document/Body.test.tsx b/src/features/Portal/Document/Body.test.tsx
index ae3cf7273bb..ac4dc9c9c83 100644
--- a/src/features/Portal/Document/Body.test.tsx
+++ b/src/features/Portal/Document/Body.test.tsx
@@ -95,8 +95,18 @@ const docChatTopicState = vi.hoisted(() => ({
topicId: 'doc-topic-1' as string | undefined,
},
}));
+// Record the params so a test can assert the topic lookup never fires — passing
+// `undefined` is what keeps `getOrCreateChatTopic` from hitting the network.
+const docChatTopicCalls = vi.hoisted(() => ({ current: [] as Record<string, unknown>[] }));
vi.mock('@/features/FloatingChatPanel/useDocumentChatTopic', () => ({
- useDocumentChatTopic: () => docChatTopicState.current,
+ // Mirror the real hook's `enabled` gate: with either id missing it never fetches,
+ // so it can only ever return `topicId: undefined`.
+ useDocumentChatTopic: (params: Record<string, unknown>) => {
+ docChatTopicCalls.current.push(params);
+ if (!params.agentId || !params.documentId)
+ return { error: undefined, isLoading: false, topicId: undefined };
+ return docChatTopicState.current;
+ },
}));
const mockChatState = vi.hoisted(() => ({
@@ -104,7 +114,7 @@ const mockChatState = vi.hoisted(() => ({
activeTopicId: 'topic-1',
portalStack: [
{
- agentDocumentId: 'agent-document-1',
+ agentDocumentId: 'agent-document-1' as string | undefined,
documentId: 'document-1',
type: 'document',
},
@@ -118,7 +128,7 @@ vi.mock('@/store/chat', () => ({
const mockAgentState = vi.hoisted(() => ({
current: {
- activeAgentId: 'agent-1',
+ activeAgentId: 'agent-1' as string | undefined,
},
}));
@@ -140,26 +150,13 @@ vi.mock('@/store/document', () => ({
useDocumentStore: (selector: any) => selector(mockDocumentState.current),
}));
-const mockUserState = vi.hoisted(() => ({
- current: {
- preference: {
- lab: {
- enableAgentDocumentFloatingChatPanel: false,
- },
- },
- },
-}));
-
-vi.mock('@/store/user', () => ({
- useUserStore: (selector: any) => selector(mockUserState.current),
-}));
-
describe('DocumentBody', () => {
beforeEach(() => {
mockAgentState.current.activeAgentId = 'agent-1';
- mockUserState.current.preference.lab.enableAgentDocumentFloatingChatPanel = false;
+ mockChatState.current.portalStack[0].agentDocumentId = 'agent-document-1';
mockDocumentMeta.current = { content: '', filename: 'doc.md' };
mockUpdateDocument.mockClear();
+ docChatTopicCalls.current = [];
docChatTopicState.current = {
error: undefined,
isLoading: false,
@@ -172,27 +169,51 @@ describe('DocumentBody', () => {
vi.useRealTimers();
});
- it('does not render FloatingChatPanel when the lab feature is disabled', () => {
+ it('renders FloatingChatPanel once the doc topic resolves', () => {
+ render(<DocumentBody />);
+
+ expect(screen.getByTestId('floating-chat-panel')).toBeDefined();
+ });
+
+ it('holds the panel until the doc-anchored topic id resolves', () => {
+ docChatTopicState.current = { error: undefined, isLoading: true, topicId: undefined };
+
render(<DocumentBody />);
expect(screen.queryByTestId('floating-chat-panel')).toBeNull();
});
- it('renders FloatingChatPanel when the lab feature is enabled and the doc topic resolves', () => {
- mockUserState.current.preference.lab.enableAgentDocumentFloatingChatPanel = true;
+ it('does not render FloatingChatPanel without an active agent', () => {
+ mockAgentState.current.activeAgentId = undefined;
render(<DocumentBody />);
- expect(screen.getByTestId('floating-chat-panel')).toBeDefined();
+ expect(screen.queryByTestId('floating-chat-panel')).toBeNull();
});
- it('holds the panel until the doc-anchored topic id resolves', () => {
- mockUserState.current.preference.lab.enableAgentDocumentFloatingChatPanel = true;
- docChatTopicState.current = { error: undefined, isLoading: true, topicId: undefined };
+ // A plain notebook document is opened as `openDocument(document.id)` — no
+ // agentDocumentId. It has no `agent_documents` row, so `getOrCreateChatTopic`
+ // would throw NOT_FOUND. The panel must not render *and* must not look up a topic.
+ it('does not render FloatingChatPanel for a plain document with no agentDocumentId', () => {
+ mockChatState.current.portalStack[0].agentDocumentId = undefined;
render(<DocumentBody />);
expect(screen.queryByTestId('floating-chat-panel')).toBeNull();
+ expect(docChatTopicCalls.current.length).toBeGreaterThan(0);
+ for (const call of docChatTopicCalls.current) {
+ expect(call.agentId).toBeUndefined();
+ expect(call.documentId).toBeUndefined();
+ }
+ });
+
+ it('looks up the doc topic for an agent document', () => {
+ render(<DocumentBody />);
+
+ expect(docChatTopicCalls.current.at(-1)).toMatchObject({
+ agentId: 'agent-1',
+ documentId: 'document-1',
+ });
});
it('renders highlight editor for non-markdown files', () => {
diff --git a/src/features/Portal/Document/Body.tsx b/src/features/Portal/Document/Body.tsx
index 6d0b316db95..6a6c4de03cb 100644
--- a/src/features/Portal/Document/Body.tsx
+++ b/src/features/Portal/Document/Body.tsx
@@ -18,8 +18,6 @@ import { portalKeys } from '@/libs/swr/keys';
import { documentService } from '@/services/document';
import { useAgentStore } from '@/store/agent';
import { useDocumentStore } from '@/store/document';
-import { useUserStore } from '@/store/user';
-import { labPreferSelectors } from '@/store/user/selectors';
import { getDocumentRenderMode } from '@/utils/documentRenderMode';
import {
getSkillMarkdownMetadataError,
@@ -324,10 +322,11 @@ const DocumentBody = memo(() => {
const agentDocumentId = useResolvedAgentDocumentId();
const fullPage = useDocumentViewFullPage();
const activeAgentId = useAgentStore((s) => s.activeAgentId);
- const enableFloatingChatPanel = useUserStore(
- labPreferSelectors.enableAgentDocumentFloatingChatPanel,
- );
- const panelEligible = !fullPage && enableFloatingChatPanel && !!activeAgentId && !!documentId;
+ // `agentDocumentId` is what marks this as an *agent* document: only the agent-doc
+ // openers pass it. The notebook opens plain topic documents with the id alone, and
+ // `getOrCreateChatTopic` throws NOT_FOUND on those (no `agent_documents` row), so
+ // the panel — and its topic lookup — must stay out of the way there.
+ const panelEligible = !fullPage && !!activeAgentId && !!documentId && !!agentDocumentId;
const { topicId: docChatTopicId } = useDocumentChatTopic({
agentId: panelEligible ? activeAgentId : undefined,
documentId: panelEligible ? documentId : undefined,
diff --git a/src/routes/(main)/settings/advanced/index.test.tsx b/src/routes/(main)/settings/advanced/index.test.tsx
index caf8b0f5e59..11c5ca66185 100644
--- a/src/routes/(main)/settings/advanced/index.test.tsx
+++ b/src/routes/(main)/settings/advanced/index.test.tsx
@@ -106,18 +106,6 @@ describe('Advanced settings page', () => {
expect(screen.getByText('tab.advanced.appUpdates.title')).toBeDefined();
});
- it('renders the agent document floating chat panel lab toggle', () => {
- useUserStore.setState({
- isUserStateInit: true,
- setSettings: vi.fn(),
- updateLab: vi.fn(),
- });
-
- render(<Page />, { wrapper: createWrapper() });
-
- expect(screen.getByText('features.agentDocumentFloatingChatPanel.title')).toBeDefined();
- });
-
it('renders the message text selection actions lab toggle', () => {
useUserStore.setState({
isUserStateInit: true,
diff --git a/src/routes/(main)/settings/advanced/index.tsx b/src/routes/(main)/settings/advanced/index.tsx
index 07c8e94a261..99782faa38f 100644
--- a/src/routes/(main)/settings/advanced/index.tsx
+++ b/src/routes/(main)/settings/advanced/index.tsx
@@ -48,7 +48,6 @@ const Page = memo(() => {
const [
isPreferenceInit,
- enableAgentDocumentFloatingChatPanel,
enableAgentGraphConfig,
enableInputMarkdown,
enablePlatformAgent,
@@ -59,7 +58,6 @@ const Page = memo(() => {
updateLab,
] = useUserStore((s) => [
preferenceSelectors.isPreferenceInit(s),
- labPreferSelectors.enableAgentDocumentFloatingChatPanel(s),
labPreferSelectors.enableAgentGraphConfig(s),
labPreferSelectors.enableInputMarkdown(s),
labPreferSelectors.enablePlatformAgent(s),
@@ -161,19 +159,6 @@ const Page = memo(() => {
};
const labItems: FormItemProps[] = [
- {
- children: (
- <Switch
- checked={enableAgentDocumentFloatingChatPanel}
- loading={!isPreferenceInit}
- onChange={(checked) => updateLab({ enableAgentDocumentFloatingChatPanel: checked })}
- />
- ),
- className: styles.labItem,
- desc: tLabs('features.agentDocumentFloatingChatPanel.desc'),
- label: tLabs('features.agentDocumentFloatingChatPanel.title'),
- minWidth: undefined,
- },
{
children: (
<Switch
diff --git a/src/store/user/slices/preference/selectors.test.ts b/src/store/user/slices/preference/selectors.test.ts
index 427a91f1410..bb70ba9129f 100644
--- a/src/store/user/slices/preference/selectors.test.ts
+++ b/src/store/user/slices/preference/selectors.test.ts
@@ -68,18 +68,6 @@ describe('preferenceSelectors', () => {
});
describe('labPreferSelectors', () => {
- it('returns false for agent document floating chat panel by default', () => {
- store.preference.lab = undefined;
-
- expect(labPreferSelectors.enableAgentDocumentFloatingChatPanel(store)).toBe(false);
- });
-
- it('returns the configured agent document floating chat panel preference', () => {
- store.preference.lab = { enableAgentDocumentFloatingChatPanel: true };
-
- expect(labPreferSelectors.enableAgentDocumentFloatingChatPanel(store)).toBe(true);
- });
-
it('returns false for message text selection actions by default', () => {
store.preference.lab = undefined;
diff --git a/src/store/user/slices/preference/selectors/labPrefer.ts b/src/store/user/slices/preference/selectors/labPrefer.ts
index 6ee0be165d7..02dfee1e695 100644
--- a/src/store/user/slices/preference/selectors/labPrefer.ts
+++ b/src/store/user/slices/preference/selectors/labPrefer.ts
@@ -3,10 +3,6 @@ import { DEFAULT_PREFERENCE } from '@lobechat/const';
import { type UserState } from '@/store/user/initialState';
export const labPreferSelectors = {
- enableAgentDocumentFloatingChatPanel: (s: UserState): boolean =>
- s.preference.lab?.enableAgentDocumentFloatingChatPanel ??
- DEFAULT_PREFERENCE.lab?.enableAgentDocumentFloatingChatPanel ??
- false,
enableAgentGraphConfig: (s: UserState): boolean =>
s.preference.lab?.enableAgentGraphConfig ??
DEFAULT_PREFERENCE.lab?.enableAgentGraphConfig ??