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.

♻️ refactor: move RecentItem to shared types (#18898)

Arvin Xu792b73880dac
diff --git a/apps/server/src/routers/lambda/recent.ts b/apps/server/src/routers/lambda/recent.ts
index 7042af85c5d..67255779cb5 100644
--- a/apps/server/src/routers/lambda/recent.ts
+++ b/apps/server/src/routers/lambda/recent.ts
@@ -1,29 +1,11 @@
import { AGENT_CHAT_TOPIC_URL, GROUP_CHAT_TOPIC_URL } from '@lobechat/const';
-import type { TaskStatus } from '@lobechat/types';
+import type { ChatTopicMetadata, RecentItem } from '@lobechat/types';
import { z } from 'zod';
import { wsCompatProcedure } from '@/business/server/trpc-middlewares/workspaceAuth';
import { RecentModel } from '@/database/models/recent';
import { router } from '@/libs/trpc/lambda';
import { serverDatabase } from '@/libs/trpc/lambda/middleware';
-import type { ChatTopicMetadata } from '@/types/topic';
-
-export interface RecentItem {
- agentId?: string | null;
- description?: string | null;
- icon: string;
- id: string;
- lastAssistantMessage?: string | null;
- metadata?: ChatTopicMetadata;
- routePath: string;
- /** Task lifecycle status when `type === 'task'`; null for topic/document. */
- status: TaskStatus | null;
- title: string;
- type: 'topic' | 'document' | 'task';
- updatedAt: Date;
- /** The member who owns this item — for author attribution in workspace team views. */
- userId?: string;
-}
const recentProcedure = wsCompatProcedure.use(serverDatabase).use(async (opts) => {
const { ctx } = opts;
diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts
index 80e22fb753f..2d4899c06ba 100644
--- a/packages/types/src/index.ts
+++ b/packages/types/src/index.ts
@@ -40,6 +40,7 @@ export * from './notification';
export * from './plugins';
export * from './project';
export * from './rag';
+export * from './recent';
export * from './redis';
export * from './resourceTransfer';
export * from './search';
diff --git a/packages/types/src/recent.ts b/packages/types/src/recent.ts
new file mode 100644
index 00000000000..30cc6fb456f
--- /dev/null
+++ b/packages/types/src/recent.ts
@@ -0,0 +1,19 @@
+import type { TaskStatus } from './task';
+import type { ChatTopicMetadata } from './topic';
+
+export interface RecentItem {
+ agentId?: string | null;
+ description?: string | null;
+ icon: string;
+ id: string;
+ lastAssistantMessage?: string | null;
+ metadata?: ChatTopicMetadata;
+ routePath: string;
+ /** Task lifecycle status when `type === 'task'`; null for topic/document. */
+ status: TaskStatus | null;
+ title: string;
+ type: 'topic' | 'document' | 'task';
+ updatedAt: Date;
+ /** The member who owns this item — for author attribution in workspace team views. */
+ userId?: string;
+}
diff --git a/src/features/Home/HomeModeContent.tsx b/src/features/Home/HomeModeContent.tsx
index e80f166652c..47d22559faa 100644
--- a/src/features/Home/HomeModeContent.tsx
+++ b/src/features/Home/HomeModeContent.tsx
@@ -1,5 +1,5 @@
import { TASK_STATUSES } from '@lobechat/builtin-tool-task';
-import type { TaskStatus } from '@lobechat/types';
+import type { RecentItem, TaskStatus } from '@lobechat/types';
import { agentDisplayName } from '@lobechat/types';
import type { FlexboxProps } from '@lobehub/ui';
import { Flexbox, Icon, Skeleton } from '@lobehub/ui';
@@ -26,7 +26,6 @@ import WorkspaceLink from '@/features/Workspace/WorkspaceLink';
import { useClientDataSWR } from '@/libs/swr';
import { recentKeys } from '@/libs/swr/keys';
import { useCacheScope } from '@/libs/swr/useCacheScope';
-import { type RecentItem } from '@/server/routers/lambda/recent';
import { recentService } from '@/services/recent';
import { useBriefStore } from '@/store/brief';
import { briefListSelectors } from '@/store/brief/selectors';
diff --git a/src/features/Home/Recents/Item.tsx b/src/features/Home/Recents/Item.tsx
index fe495d02e64..8a923fe3af7 100644
--- a/src/features/Home/Recents/Item.tsx
+++ b/src/features/Home/Recents/Item.tsx
@@ -1,3 +1,4 @@
+import type { RecentItem } from '@lobechat/types';
import { DropdownMenu, Flexbox, Icon } from '@lobehub/ui';
import { ActionIcon } from '@lobehub/ui/base-ui';
import { cssVar } from 'antd-style';
@@ -11,7 +12,6 @@ import NavItem from '@/features/NavPanel/components/NavItem';
import { usePrefetchAgent } from '@/hooks/usePrefetchAgent';
import { usePrefetchPage } from '@/hooks/usePrefetchPage';
import { getPlatformIcon } from '@/routes/(main)/agent/channel/const';
-import { type RecentItem } from '@/server/routers/lambda/recent';
import { useRecentItemDropdownMenu } from './useDropdownMenu';
diff --git a/src/features/Home/Recents/useDropdownMenu.tsx b/src/features/Home/Recents/useDropdownMenu.tsx
index 222e218dc91..6f381f3340a 100644
--- a/src/features/Home/Recents/useDropdownMenu.tsx
+++ b/src/features/Home/Recents/useDropdownMenu.tsx
@@ -1,3 +1,4 @@
+import type { RecentItem } from '@lobechat/types';
import { type MenuProps } from '@lobehub/ui';
import { Icon } from '@lobehub/ui';
import { confirmModal } from '@lobehub/ui/base-ui';
@@ -10,7 +11,6 @@ import { useTaskTransferMenuItem } from '@/business/client/hooks/useTaskTransfer
import { confirmRemoveTopic } from '@/features/DeleteTopicConfirm';
import { usePermission } from '@/hooks/usePermission';
import type { NativeContextMenuItem } from '@/libs/contextMenu/types';
-import { type RecentItem } from '@/server/routers/lambda/recent';
import { documentService } from '@/services/document';
import { taskService } from '@/services/task';
import { topicService } from '@/services/topic';
diff --git a/src/services/recent/index.ts b/src/services/recent/index.ts
index e92575c7d9f..f203aa70e96 100644
--- a/src/services/recent/index.ts
+++ b/src/services/recent/index.ts
@@ -1,5 +1,6 @@
+import type { RecentItem } from '@lobechat/types';
+
import { lambdaClient } from '@/libs/trpc/client';
-import { type RecentItem } from '@/server/routers/lambda/recent';
export const RECENT_SIDEBAR_TYPES = [
'document',
diff --git a/src/store/home/slices/recent/action.test.ts b/src/store/home/slices/recent/action.test.ts
index 03497f3b03f..3dc7ef9fdf8 100644
--- a/src/store/home/slices/recent/action.test.ts
+++ b/src/store/home/slices/recent/action.test.ts
@@ -1,10 +1,10 @@
+import type { RecentItem } from '@lobechat/types';
import { act, renderHook } from '@testing-library/react';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import * as swr from '@/libs/swr';
import { recentKeys } from '@/libs/swr/keys';
import * as cacheScope from '@/libs/swr/useCacheScope';
-import { type RecentItem } from '@/server/routers/lambda/recent';
import { recentService } from '@/services/recent';
import { useHomeStore } from '@/store/home';
import { initialRecentState } from '@/store/home/slices/recent/initialState';
diff --git a/src/store/home/slices/recent/action.ts b/src/store/home/slices/recent/action.ts
index 37f02ca2bb6..8eb548ae218 100644
--- a/src/store/home/slices/recent/action.ts
+++ b/src/store/home/slices/recent/action.ts
@@ -1,10 +1,10 @@
+import type { RecentItem } from '@lobechat/types';
import isEqual from 'fast-deep-equal';
import { type SWRResponse } from 'swr';
import { mutate, useClientDataSWRWithSync } from '@/libs/swr';
import { recentKeys } from '@/libs/swr/keys';
import { getCacheScope } from '@/libs/swr/useCacheScope';
-import { type RecentItem } from '@/server/routers/lambda/recent';
import { RECENT_SIDEBAR_TYPES, recentService } from '@/services/recent';
import { type HomeStore } from '@/store/home/store';
import { type StoreSetter } from '@/store/types';
diff --git a/src/store/home/slices/recent/initialState.ts b/src/store/home/slices/recent/initialState.ts
index 196fdb0ccbe..dafaf8517e3 100644
--- a/src/store/home/slices/recent/initialState.ts
+++ b/src/store/home/slices/recent/initialState.ts
@@ -1,4 +1,4 @@
-import { type RecentItem } from '@/server/routers/lambda/recent';
+import type { RecentItem } from '@lobechat/types';
export interface RecentState {
allRecentsDrawerOpen: boolean;