@lobehub/chat 1.97.0 → 1.97.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/README.md +90 -32
  3. package/README.zh-CN.md +90 -34
  4. package/changelog/v1.json +18 -0
  5. package/docs/usage/features/desktop.mdx +53 -0
  6. package/docs/usage/features/desktop.zh-CN.mdx +49 -0
  7. package/docs/usage/features/mcp-market.mdx +26 -0
  8. package/docs/usage/features/mcp-market.zh-CN.mdx +22 -0
  9. package/docs/usage/features/mcp.mdx +58 -0
  10. package/docs/usage/features/mcp.zh-CN.mdx +54 -0
  11. package/docs/usage/features/search.mdx +56 -0
  12. package/docs/usage/features/search.zh-CN.mdx +52 -0
  13. package/package.json +3 -2
  14. package/src/app/(backend)/trpc/async/[trpc]/route.ts +4 -2
  15. package/src/app/[variants]/(main)/chat/(workspace)/_layout/Desktop/index.tsx +2 -0
  16. package/src/app/[variants]/(main)/chat/(workspace)/_layout/Mobile/index.tsx +2 -0
  17. package/src/app/[variants]/(main)/chat/@session/features/SessionListContent/List/index.tsx +35 -2
  18. package/src/components/Analytics/LobeAnalyticsProvider.tsx +68 -0
  19. package/src/components/Analytics/LobeAnalyticsProviderWrapper.tsx +23 -0
  20. package/src/components/Analytics/MainInterfaceTracker.tsx +52 -0
  21. package/src/components/Analytics/index.tsx +0 -8
  22. package/src/const/analytics.ts +3 -0
  23. package/src/database/schemas/relations.ts +44 -0
  24. package/src/features/AgentSetting/store/action.ts +26 -1
  25. package/src/features/ChatInput/useSend.ts +29 -1
  26. package/src/features/User/UserLoginOrSignup/Community.tsx +14 -1
  27. package/src/layout/GlobalProvider/Locale.tsx +2 -1
  28. package/src/layout/GlobalProvider/index.tsx +4 -1
  29. package/src/libs/analytics/index.ts +25 -0
  30. package/src/locales/create.ts +8 -3
  31. package/src/server/routers/async/caller.ts +2 -2
  32. package/src/server/services/user/index.test.ts +8 -0
  33. package/src/server/services/user/index.ts +18 -0
  34. package/src/store/session/slices/session/action.ts +28 -2
  35. package/src/store/user/slices/common/action.ts +9 -2
  36. package/src/utils/locale.ts +16 -1
  37. package/tests/setup.ts +11 -0
@@ -0,0 +1,53 @@
1
+ ---
2
+ title: LobeChat Desktop Application
3
+ description: >-
4
+ Experience the full power of LobeChat without browser limitations. A
5
+ lightweight, focused, and always-ready desktop app offering a dedicated
6
+ environment and optimal performance.
7
+ tags:
8
+ - Desktop Application
9
+ - Native App
10
+ - Performance Optimization
11
+ - Dedicated Environment
12
+ - Offline Use
13
+ - System Integration
14
+ - User Experience
15
+ ---
16
+
17
+ # Desktop Application
18
+
19
+ <Image alt={'Desktop Application'} borderless cover src={'https://github.com/user-attachments/assets/a7bac8d3-ea96-4000-bb39-fadc9b610f96'}> />
20
+
21
+ **Peak Performance, Zero Distractions**
22
+
23
+ Unlock the full LobeChat experience without the constraints of a browser — lightweight, focused, and always ready. Our desktop application provides a dedicated environment for your AI interactions, ensuring optimal performance with minimal distractions.
24
+
25
+ Enjoy faster response times, better resource management, and a more stable connection to your AI assistant. The desktop app is designed for users who demand the best performance from their AI tools.
26
+
27
+ ## Why Choose the Desktop Application
28
+
29
+ ### 🚀 Superior Performance
30
+
31
+ <Callout type={'tip'}>
32
+ The desktop app delivers faster response times and a smoother user experience compared to the browser version.
33
+ </Callout>
34
+
35
+ - **Dedicated Process**: Runs independently, free from browser limitations
36
+ - **Memory Optimization**: More efficient memory management and resource allocation
37
+ - **GPU Acceleration**: Fully leverages hardware acceleration capabilities
38
+ - **Low Latency**: Reduces network delays and page load times
39
+
40
+ ### 🎯 Focused Experience
41
+
42
+ - **Distraction-Free Environment**: Eliminates interruptions from browser tabs, bookmarks bar, and more
43
+ - **Full-Screen Mode**: Supports immersive, full-screen usage
44
+ - **Quick Launch**: Auto-start on boot, ready whenever you are
45
+ - **Keyboard Shortcuts**: Extensive shortcut support to boost productivity
46
+
47
+ ### 🔒 Secure and Reliable
48
+
49
+ - **Local Storage**: Data securely stored locally for enhanced privacy
50
+ - **Offline Capability**: Partial functionality available offline
51
+ - **Automatic Updates**: Always up to date without manual intervention
52
+ - **Data Backup**: Comprehensive data backup and recovery features
53
+
@@ -0,0 +1,49 @@
1
+ ---
2
+ title: LobeChat 桌面应用
3
+ description: 获得完整的 LobeChat 体验,摆脱浏览器限制。轻量级、专注且随时就绪的桌面应用,提供专用环境和最佳性能。
4
+ tags:
5
+ - 桌面应用
6
+ - 原生应用
7
+ - 性能优化
8
+ - 专用环境
9
+ - 离线使用
10
+ - 系统集成
11
+ - 用户体验
12
+ ---
13
+
14
+ # 桌面应用
15
+
16
+ <Image alt={'桌面应用'} borderless cover src={'https://github.com/user-attachments/assets/a7bac8d3-ea96-4000-bb39-fadc9b610f96'} />
17
+
18
+ **巅峰性能,零干扰**
19
+
20
+ 获得完整的 LobeChat 体验,摆脱浏览器限制 —— 轻量级、专注且随时就绪。我们的桌面应用程序为你的 AI 交互提供专用环境,确保最佳性能和最小干扰。
21
+
22
+ 体验更快的响应时间、更好的资源管理和与 AI 助手的更稳定连接。桌面应用专为要求 AI 工具最佳性能的用户设计。
23
+
24
+ ## 为什么选择桌面应用
25
+
26
+ ### 🚀 卓越性能
27
+
28
+ <Callout type={'tip'}>
29
+ 桌面应用提供比浏览器版本更快的响应速度和更流畅的用户体验。
30
+ </Callout>
31
+
32
+ - **专用进程**:独立运行,不受浏览器限制
33
+ - **内存优化**:更高效的内存管理和资源分配
34
+ - **GPU 加速**:充分利用硬件加速能力
35
+ - **低延迟**:减少网络延迟和页面加载时间
36
+
37
+ ### 🎯 专注体验
38
+
39
+ - **无干扰环境**:摆脱浏览器标签页、书签栏等干扰
40
+ - **全屏模式**:支持全屏和沉浸式体验
41
+ - **快速启动**:开机自启动,随时可用
42
+ - **键盘快捷键**:丰富的快捷键支持,提高操作效率
43
+
44
+ ### 🔒 安全可靠
45
+
46
+ - **本地存储**:数据安全存储在本地,隐私保护更好
47
+ - **离线能力**:部分功能支持离线使用
48
+ - **自动更新**:无需手动更新,始终保持最新版本
49
+ - **数据备份**:完整的数据备份和恢复功能
@@ -0,0 +1,26 @@
1
+ ---
2
+ title: 'MCP Marketplace - Discover, Connect, Expand'
3
+ description: >-
4
+ Browse the ever-growing MCP plugin library to effortlessly enhance your AI
5
+ capabilities and streamline workflows. Explore the MCP Marketplace to find
6
+ curated collections of integrations.
7
+ tags:
8
+ - MCP Marketplace
9
+ - Plugin Library
10
+ - Integrations
11
+ - Extensions
12
+ - Workflows
13
+ - Community
14
+ - Developers
15
+ ---
16
+
17
+ # MCP Marketplace
18
+
19
+ <Image alt={'MCP Marketplace'} borderless cover src={'https://github.com/user-attachments/assets/bb114f9f-24c5-4000-a984-c10d187da5a0'}> />
20
+
21
+ **Discover, Connect, Expand**
22
+
23
+ Browse the ever-growing MCP plugin library to effortlessly enhance your AI capabilities and streamline your workflows. Visit [lobehub.com/mcp](https://lobehub.com/mcp) to explore the MCP Marketplace, featuring curated collections of integrations that empower your AI to collaborate seamlessly with a variety of tools and services.
24
+
25
+ From productivity tools to development environments, discover new ways to extend AI’s reach and efficiency. Connect with the community to find the perfect plugin tailored to your specific needs.
26
+
@@ -0,0 +1,22 @@
1
+ ---
2
+ title: MCP 市场 - 发现、连接、扩展
3
+ description: 浏览不断增长的 MCP 插件库,轻松扩展你的 AI 能力并简化工作流程。探索 MCP 市场,发现精选的集成集合。
4
+ tags:
5
+ - MCP 市场
6
+ - 插件库
7
+ - 集成
8
+ - 扩展
9
+ - 工作流程
10
+ - 社区
11
+ - 开发者
12
+ ---
13
+
14
+ # MCP 市场
15
+
16
+ <Image alt={'MCP 市场'} borderless cover src={'https://github.com/user-attachments/assets/bb114f9f-24c5-4000-a984-c10d187da5a0'} />
17
+
18
+ **发现、连接、扩展**
19
+
20
+ 浏览不断增长的 MCP 插件库,轻松扩展你的 AI 能力并简化工作流程。访问 [lobehub.com/mcp](https://lobehub.com/mcp) 探索 MCP 市场,提供精选的集成集合,增强你的 AI 与各种工具和服务协作的能力。
21
+
22
+ 从生产力工具到开发环境,发现扩展 AI 覆盖范围和效率的新方式。与社区连接,找到满足特定需求的完美插件。
@@ -0,0 +1,58 @@
1
+ ---
2
+ title: MCP Plugin One-Click Installation - Seamlessly Connect AI with the World
3
+ description: >-
4
+ Unlock the full potential of AI through the MCP (Model Context Protocol)
5
+ plugin system, enabling smooth, secure, and dynamic interactions with external
6
+ tools, data sources, and services.
7
+ tags:
8
+ - MCP
9
+ - Model Context Protocol
10
+ - Plugin System
11
+ - One-Click Installation
12
+ - Tool Integration
13
+ - Workflow
14
+ - External Services
15
+ ---
16
+
17
+ # MCP Plugin One-Click Installation
18
+
19
+ <Image alt={'MCP Plugin One-Click Installation'} borderless cover src={'https://github.com/user-attachments/assets/1be85d36-3975-4413-931f-27e05e440995'}> />
20
+
21
+ **Seamlessly Connect Your AI with the World**
22
+
23
+ Unlock the full potential of your AI by enabling smooth, secure, and dynamic interactions with external tools, data sources, and services. The MCP (Model Context Protocol)-based plugin system breaks down barriers between AI and the digital ecosystem, delivering unprecedented connectivity and functionality.
24
+
25
+ Transform conversations into powerful workflows by connecting databases, APIs, file systems, and more. Experience an AI Agent that truly understands and interacts with your world.
26
+
27
+ ## What is MCP (Model Context Protocol)?
28
+
29
+ MCP (Model Context Protocol) is an open protocol standard that provides AI models with a standardized way to access and interact with external resources. Through MCP, AI assistants can:
30
+
31
+ - 🔗 **Secure Connections**: Establish secure links with various tools and services
32
+ - 🔄 **Dynamic Interaction**: Retrieve and update external data in real time
33
+ - 🛡️ **Permission Control**: Manage access rights with fine-grained precision
34
+ - 📊 **Context Awareness**: Maintain rich conversational context information
35
+
36
+ ## Key Features
37
+
38
+ ### 🚀 One-Click Installation Experience
39
+
40
+ <Callout type={'tip'}>
41
+ No complicated setup required—installing and configuring MCP plugins takes just a few clicks.
42
+ </Callout>
43
+
44
+ - **Rapid Deployment**: From discovery to use in under one minute
45
+ - **Automatic Configuration**: The system handles connection and permission settings automatically
46
+ - **Instant Activation**: Ready to use in conversations immediately after installation
47
+
48
+ ### 🔌 Extensive Connectivity
49
+
50
+ MCP plugins support connections to a wide variety of external resources:
51
+
52
+ - **Databases**: MySQL, PostgreSQL, MongoDB, and more
53
+ - **API Services**: REST APIs, GraphQL, WebSocket
54
+ - **File Systems**: Local files, cloud storage, version control
55
+ - **Development Tools**: GitHub, GitLab, Jira, Slack
56
+ - **Office Suites**: Google Workspace, Microsoft 365
57
+ - **Professional Tools**: Docker, Kubernetes, Jenkins
58
+
@@ -0,0 +1,54 @@
1
+ ---
2
+ title: MCP 插件一键安装 - 无缝连接 AI 与世界
3
+ description: 通过 MCP(模型上下文协议)插件系统,释放 AI 的全部潜力,实现与外部工具、数据源和服务的平滑、安全和动态交互。
4
+ tags:
5
+ - MCP
6
+ - 模型上下文协议
7
+ - 插件系统
8
+ - 一键安装
9
+ - 工具集成
10
+ - 工作流程
11
+ - 外部服务
12
+ ---
13
+
14
+ # MCP 插件一键安装
15
+
16
+ <Image alt={'MCP 插件一键安装'} borderless cover src={'https://github.com/user-attachments/assets/1be85d36-3975-4413-931f-27e05e440995'} />
17
+
18
+ **无缝连接你的 AI 与世界**
19
+
20
+ 通过启用与外部工具、数据源和服务的平滑、安全和动态交互,释放你的 AI 的全部潜力。基于 MCP(模型上下文协议)的插件系统打破了 AI 与数字生态系统之间的壁垒,实现了前所未有的连接性和功能性。
21
+
22
+ 将对话转化为强大的工作流程,连接数据库、API、文件系统等。体验真正理解并与你的世界互动的 AI Agent。
23
+
24
+ ## 什么是 MCP(模型上下文协议)?
25
+
26
+ MCP(Model Context Protocol)是一个开放的协议标准,它为 AI 模型提供了一个标准化的方式来访问和交互外部资源。通过 MCP,AI 助手可以:
27
+
28
+ - 🔗 **安全连接**:与各种工具和服务建立安全的连接
29
+ - 🔄 **动态交互**:实时获取和更新外部数据
30
+ - 🛡️ **权限控制**:精细化的访问权限管理
31
+ - 📊 **上下文感知**:维护丰富的对话上下文信息
32
+
33
+ ## 主要特性
34
+
35
+ ### 🚀 一键式安装体验
36
+
37
+ <Callout type={'tip'}>
38
+ 无需复杂的配置过程,只需几次点击即可完成 MCP 插件的安装和配置。
39
+ </Callout>
40
+
41
+ - **快速部署**:从发现到使用,整个过程不超过 1 分钟
42
+ - **自动配置**:系统自动处理连接和权限设置
43
+ - **即时生效**:安装完成后立即可在对话中使用
44
+
45
+ ### 🔌 广泛的连接能力
46
+
47
+ MCP 插件支持连接各种类型的外部资源:
48
+
49
+ - **数据库**:MySQL、PostgreSQL、MongoDB 等
50
+ - **API 服务**:REST API、GraphQL、WebSocket
51
+ - **文件系统**:本地文件、云存储、版本控制
52
+ - **开发工具**:GitHub、GitLab、Jira、Slack
53
+ - **办公软件**:Google Workspace、Microsoft 365
54
+ - **专业工具**:Docker、Kubernetes、Jenkins
@@ -0,0 +1,56 @@
1
+ ---
2
+ title: 'Intelligent Connected Search - Online Knowledge, On Demand'
3
+ description: >-
4
+ Stay synchronized with the world through real-time online access. Obtain the
5
+ latest information, verify facts, and explore current events without leaving
6
+ the conversation.
7
+ tags:
8
+ - Connected Search
9
+ - Real-time Information
10
+ - Search Engines
11
+ - Information Retrieval
12
+ - Fact Verification
13
+ - Real-time Data
14
+ - Knowledge Updates
15
+ ---
16
+
17
+ # Intelligent Connected Search
18
+
19
+ <Image alt={'Intelligent Connected Search'} borderless cover src={'https://github.com/user-attachments/assets/cfdc48ac-b5f8-4a00-acee-db8f2eba09ad'}> />
20
+
21
+ **Online Knowledge, On Demand**
22
+
23
+ Stay in sync with the world through real-time online access — news, data, trends, and more. Keep your information up to date and access the latest available data, enabling your AI to provide accurate and current responses.
24
+
25
+ Access real-time information, verify facts, and explore ongoing events without leaving the conversation. Your AI becomes a gateway to the world’s knowledge, always up-to-date and comprehensive.
26
+
27
+ ## Features Overview
28
+
29
+ ### 🌐 Real-Time Information Access
30
+
31
+ <Callout type={'tip'}>
32
+ Intelligent Connected Search empowers AI to access the latest internet information, ensuring accuracy and timeliness in responses.
33
+ </Callout>
34
+
35
+ - **Breaking News**: Get the latest news reports and event updates
36
+ - **Market Data**: Real-time stock prices, exchange rates, cryptocurrency values
37
+ - **Weather Information**: Global weather forecasts and meteorological data
38
+ - **Traffic Conditions**: Live traffic updates and road status
39
+ - **Sports Events**: Match results, schedules, and statistics
40
+
41
+ ### 🔍 Multi-Source Search Engines
42
+
43
+ Supports multiple search engines to ensure comprehensive and accurate information:
44
+
45
+ - **Google**: The world’s largest search engine
46
+ - **Bing**: Microsoft’s search engine
47
+ - **DuckDuckGo**: Privacy-focused search engine
48
+
49
+ ### 📊 Structured Data Retrieval
50
+
51
+ - **Academic Papers**: Access academic databases and journals
52
+ - **Technical Documentation**: Obtain the latest technical documents and API references
53
+ - **Statistical Data**: Government statistics, survey reports, market research
54
+ - **Product Information**: Product details and reviews from e-commerce platforms
55
+ - **Laws and Regulations**: Latest legal texts and policy interpretations
56
+
@@ -0,0 +1,52 @@
1
+ ---
2
+ title: 智能联网搜索 - 在线知识,按需获取
3
+ description: 通过实时联网访问,你的 AI 与世界保持同步。获取最新信息,验证事实,探索当前事件,无需离开对话。
4
+ tags:
5
+ - 联网搜索
6
+ - 实时信息
7
+ - 搜索引擎
8
+ - 信息获取
9
+ - 事实验证
10
+ - 实时数据
11
+ - 知识更新
12
+ ---
13
+
14
+ # 智能联网搜索
15
+
16
+ <Image alt={'智能联网搜索'} borderless cover src={'https://github.com/user-attachments/assets/cfdc48ac-b5f8-4a00-acee-db8f2eba09ad'} />
17
+
18
+ **在线知识,按需获取**
19
+
20
+ 通过实时联网访问,你的 AI 与世界保持同步 —— 新闻、数据、趋势等。保持信息更新,获取最新可用信息,使你的 AI 能够提供准确和最新的回复。
21
+
22
+ 访问实时信息,验证事实,探索当前事件,无需离开对话。你的 AI 成为通向世界知识的门户,始终保持最新和全面。
23
+
24
+ ## 功能概述
25
+
26
+ ### 🌐 实时信息获取
27
+
28
+ <Callout type={'tip'}>
29
+ 智能联网搜索让 AI 能够访问最新的互联网信息,确保回答的准确性和时效性。
30
+ </Callout>
31
+
32
+ - **实时新闻**:获取最新的新闻报道和事件动态
33
+ - **市场数据**:实时股价、汇率、加密货币价格
34
+ - **天气信息**:全球天气预报和气象数据
35
+ - **交通状况**:实时路况和交通信息
36
+ - **体育赛事**:比赛结果、赛程和统计数据
37
+
38
+ ### 🔍 多源搜索引擎
39
+
40
+ 支持多个搜索引擎,确保信息的全面性和准确性:
41
+
42
+ - **Google**:全球最大的搜索引擎
43
+ - **Bing**:Microsoft 搜索引擎
44
+ - **DuckDuckGo**:注重隐私的搜索引擎
45
+
46
+ ### 📊 结构化数据获取
47
+
48
+ - **学术论文**:访问学术数据库和期刊
49
+ - **技术文档**:获取最新的技术文档和 API 资料
50
+ - **统计数据**:政府统计、调查报告、市场研究
51
+ - **产品信息**:电商平台的产品详情和评价
52
+ - **法律法规**:最新的法律条文和政策解读
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "1.97.0",
3
+ "version": "1.97.2",
4
4
  "description": "Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.",
5
5
  "keywords": [
6
6
  "framework",
@@ -144,6 +144,7 @@
144
144
  "@lobechat/electron-server-ipc": "workspace:*",
145
145
  "@lobechat/file-loaders": "workspace:*",
146
146
  "@lobechat/web-crawler": "workspace:*",
147
+ "@lobehub/analytics": "^1.5.1",
147
148
  "@lobehub/charts": "^2.0.0",
148
149
  "@lobehub/chat-plugin-sdk": "^1.32.4",
149
150
  "@lobehub/chat-plugins-gateway": "^1.9.0",
@@ -280,7 +281,7 @@
280
281
  "@commitlint/cli": "^19.8.1",
281
282
  "@edge-runtime/vm": "^5.0.0",
282
283
  "@huggingface/tasks": "^0.15.9",
283
- "@lobehub/i18n-cli": "^1.23.0",
284
+ "@lobehub/i18n-cli": "^1.25.1",
284
285
  "@lobehub/lint": "^1.26.2",
285
286
  "@lobehub/market-types": "^1.11.2",
286
287
  "@lobehub/seo-cli": "^1.6.0",
@@ -5,10 +5,12 @@ import { pino } from '@/libs/logger';
5
5
  import { createAsyncRouteContext } from '@/libs/trpc/async/context';
6
6
  import { asyncRouter } from '@/server/routers/async';
7
7
 
8
- export const maxDuration = 60;
9
-
10
8
  const handler = (req: NextRequest) =>
11
9
  fetchRequestHandler({
10
+ // 避免请求之间互相影响
11
+ // https://github.com/lobehub/lobe-chat/discussions/7442#discussioncomment-13658563
12
+ allowBatching: false,
13
+
12
14
  /**
13
15
  * @link https://trpc.io/docs/v11/context
14
16
  */
@@ -1,6 +1,7 @@
1
1
  import { Suspense } from 'react';
2
2
  import { Flexbox } from 'react-layout-kit';
3
3
 
4
+ import MainInterfaceTracker from '@/components/Analytics/MainInterfaceTracker';
4
5
  import BrandTextLoading from '@/components/Loading/BrandTextLoading';
5
6
 
6
7
  import { LayoutProps } from '../type';
@@ -31,6 +32,7 @@ const Layout = ({ children, topic, conversation, portal }: LayoutProps) => {
31
32
  </Portal>
32
33
  <TopicPanel>{topic}</TopicPanel>
33
34
  </Flexbox>
35
+ <MainInterfaceTracker />
34
36
  </>
35
37
  );
36
38
  };
@@ -1,3 +1,4 @@
1
+ import MainInterfaceTracker from '@/components/Analytics/MainInterfaceTracker';
1
2
  import MobileContentLayout from '@/components/server/MobileNavLayout';
2
3
 
3
4
  import { LayoutProps } from '../type';
@@ -13,6 +14,7 @@ const Layout = ({ children, topic, conversation, portal }: LayoutProps) => {
13
14
  </MobileContentLayout>
14
15
  <TopicModal>{topic}</TopicModal>
15
16
  {portal}
17
+ <MainInterfaceTracker />
16
18
  </>
17
19
  );
18
20
  };
@@ -1,3 +1,4 @@
1
+ import { useAnalytics } from '@lobehub/analytics/react';
1
2
  import { Empty } from 'antd';
2
3
  import { createStyles } from 'antd-style';
3
4
  import Link from 'next/link';
@@ -9,8 +10,10 @@ import LazyLoad from 'react-lazy-load';
9
10
  import { SESSION_CHAT_URL } from '@/const/url';
10
11
  import { useSwitchSession } from '@/hooks/useSwitchSession';
11
12
  import { featureFlagsSelectors, useServerConfigStore } from '@/store/serverConfig';
12
- import { useSessionStore } from '@/store/session';
13
- import { sessionSelectors } from '@/store/session/selectors';
13
+ import { getSessionStoreState, useSessionStore } from '@/store/session';
14
+ import { sessionGroupSelectors, sessionSelectors } from '@/store/session/selectors';
15
+ import { getUserStoreState } from '@/store/user';
16
+ import { userProfileSelectors } from '@/store/user/selectors';
14
17
  import { LobeAgentSession } from '@/types/session';
15
18
 
16
19
  import SkeletonList from '../../SkeletonList';
@@ -29,6 +32,7 @@ interface SessionListProps {
29
32
  }
30
33
  const SessionList = memo<SessionListProps>(({ dataSource, groupId, showAddButton = true }) => {
31
34
  const { t } = useTranslation('chat');
35
+ const { analytics } = useAnalytics();
32
36
  const { styles } = useStyles();
33
37
 
34
38
  const isInit = useSessionStore(sessionSelectors.isSessionListInit);
@@ -49,6 +53,35 @@ const SessionList = memo<SessionListProps>(({ dataSource, groupId, showAddButton
49
53
  onClick={(e) => {
50
54
  e.preventDefault();
51
55
  switchSession(id);
56
+
57
+ // Enhanced analytics tracking
58
+ if (analytics) {
59
+ const userStore = getUserStoreState();
60
+ const sessionStore = getSessionStoreState();
61
+
62
+ const userId = userProfileSelectors.userId(userStore);
63
+ const session = sessionSelectors.getSessionById(id)(sessionStore);
64
+
65
+ if (session) {
66
+ const sessionGroupId = session.group || 'default';
67
+ const group = sessionGroupSelectors.getGroupById(sessionGroupId)(sessionStore);
68
+ const groupName =
69
+ group?.name || (sessionGroupId === 'default' ? 'Default' : 'Unknown');
70
+
71
+ analytics?.track({
72
+ name: 'switch_session',
73
+ properties: {
74
+ assistant_name: session.meta?.title || 'Untitled Agent',
75
+ assistant_tags: session.meta?.tags || [],
76
+ group_id: sessionGroupId,
77
+ group_name: groupName,
78
+ session_id: id,
79
+ spm: 'homepage.chat.session_list_item.click',
80
+ user_id: userId || 'anonymous',
81
+ },
82
+ });
83
+ }
84
+ }
52
85
  }}
53
86
  >
54
87
  <SessionItem id={id} />
@@ -0,0 +1,68 @@
1
+ 'use client';
2
+
3
+ import { createSingletonAnalytics } from '@lobehub/analytics';
4
+ import { AnalyticsProvider } from '@lobehub/analytics/react';
5
+ import { ReactNode, memo, useMemo } from 'react';
6
+
7
+ import { BUSINESS_LINE } from '@/const/analytics';
8
+ import { isDesktop } from '@/const/version';
9
+ import { isDev } from '@/utils/env';
10
+
11
+ type Props = {
12
+ children: ReactNode;
13
+ debugPosthog: boolean;
14
+ posthogEnabled: boolean;
15
+ posthogHost: string;
16
+ posthogToken: string;
17
+ };
18
+
19
+ let analyticsInstance: ReturnType<typeof createSingletonAnalytics> | null = null;
20
+
21
+ export const LobeAnalyticsProvider = memo(
22
+ ({ children, posthogHost, posthogToken, posthogEnabled, debugPosthog }: Props) => {
23
+ const analytics = useMemo(() => {
24
+ if (analyticsInstance) {
25
+ return analyticsInstance;
26
+ }
27
+
28
+ analyticsInstance = createSingletonAnalytics({
29
+ business: BUSINESS_LINE,
30
+ debug: isDev,
31
+ providers: {
32
+ posthog: {
33
+ debug: debugPosthog,
34
+ enabled: posthogEnabled,
35
+ host: posthogHost,
36
+ key: posthogToken,
37
+ person_profiles: 'always',
38
+ },
39
+ },
40
+ });
41
+
42
+ return analyticsInstance;
43
+ }, []);
44
+
45
+ if (!analytics) return children;
46
+
47
+ return (
48
+ <AnalyticsProvider
49
+ client={analytics}
50
+ onInitializeSuccess={() => {
51
+ analyticsInstance?.setGlobalContext({
52
+ platform: isDesktop ? 'desktop' : 'web',
53
+ });
54
+
55
+ analyticsInstance
56
+ ?.getProvider('posthog')
57
+ ?.getNativeInstance()
58
+ ?.register({
59
+ platform: isDesktop ? 'desktop' : 'web',
60
+ });
61
+ }}
62
+ >
63
+ {children}
64
+ </AnalyticsProvider>
65
+ );
66
+ },
67
+ () => true,
68
+ );
@@ -0,0 +1,23 @@
1
+ import { ReactNode, memo } from 'react';
2
+
3
+ import { LobeAnalyticsProvider } from '@/components/Analytics/LobeAnalyticsProvider';
4
+ import { analyticsEnv } from '@/config/analytics';
5
+
6
+ type Props = {
7
+ children: ReactNode;
8
+ };
9
+
10
+ export const LobeAnalyticsProviderWrapper = memo<Props>(({ children }) => {
11
+ return (
12
+ <LobeAnalyticsProvider
13
+ debugPosthog={analyticsEnv.DEBUG_POSTHOG_ANALYTICS}
14
+ posthogEnabled={analyticsEnv.ENABLED_POSTHOG_ANALYTICS}
15
+ posthogHost={analyticsEnv.POSTHOG_HOST}
16
+ posthogToken={analyticsEnv.POSTHOG_KEY ?? ''}
17
+ >
18
+ {children}
19
+ </LobeAnalyticsProvider>
20
+ );
21
+ });
22
+
23
+ LobeAnalyticsProviderWrapper.displayName = 'LobeAnalyticsProviderWrapper';
@@ -0,0 +1,52 @@
1
+ 'use client';
2
+
3
+ import { useAnalytics } from '@lobehub/analytics/react';
4
+ import { memo, useCallback, useEffect } from 'react';
5
+
6
+ import { getChatStoreState } from '@/store/chat';
7
+ import { chatSelectors } from '@/store/chat/slices/message/selectors';
8
+ import { useGlobalStore } from '@/store/global';
9
+ import { systemStatusSelectors } from '@/store/global/selectors';
10
+ import { getSessionStoreState } from '@/store/session';
11
+ import { sessionSelectors } from '@/store/session/selectors';
12
+
13
+ const MainInterfaceTracker = memo(() => {
14
+ const { analytics } = useAnalytics();
15
+
16
+ const getMainInterfaceAnalyticsData = useCallback(() => {
17
+ const currentSession = sessionSelectors.currentSession(getSessionStoreState());
18
+ const activeSessionId = currentSession?.id;
19
+ const defaultSessions = sessionSelectors.defaultSessions(getSessionStoreState());
20
+ const showChatSideBar = systemStatusSelectors.showChatSideBar(useGlobalStore.getState());
21
+ const messages = chatSelectors.activeBaseChats(getChatStoreState());
22
+ return {
23
+ active_assistant: activeSessionId === 'inbox' ? null : currentSession?.meta?.title || null,
24
+ has_chat_history: messages.length > 0,
25
+ session_id: activeSessionId ? activeSessionId : 'inbox',
26
+ sidebar_state: showChatSideBar ? 'expanded' : 'collapsed',
27
+ visible_assistants_count: defaultSessions.length,
28
+ };
29
+ }, []);
30
+
31
+ useEffect(() => {
32
+ if (!analytics) return;
33
+
34
+ const timer = setTimeout(() => {
35
+ analytics.track({
36
+ name: 'main_page_view',
37
+ properties: {
38
+ ...getMainInterfaceAnalyticsData(),
39
+ spm: 'main_page.interface.view',
40
+ },
41
+ });
42
+ }, 1000);
43
+
44
+ return () => clearTimeout(timer);
45
+ }, [analytics, getMainInterfaceAnalyticsData]);
46
+
47
+ return null;
48
+ });
49
+
50
+ MainInterfaceTracker.displayName = 'MainInterfaceTracker';
51
+
52
+ export default MainInterfaceTracker;