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(recent): let clients drop archived topics from the recent feed (#21862)

Tsukiecfe0f31b4ac
diff --git a/apps/server/src/routers/lambda/recent.ts b/apps/server/src/routers/lambda/recent.ts
index a71c0d852fd..1708bfcd690 100644
--- a/apps/server/src/routers/lambda/recent.ts
+++ b/apps/server/src/routers/lambda/recent.ts
@@ -21,6 +21,7 @@ export const recentRouter = router({
.input(
z
.object({
+ excludeArchived: z.boolean().optional(),
limit: z.number().optional(),
/** Restrict a workspace feed to the viewer's own items (mine/team toggle). */
mineOnly: z.boolean().optional(),
@@ -44,6 +45,7 @@ export const recentRouter = router({
input?.withTopicPreview,
input?.mineOnly,
input?.sharedOnly,
+ input?.excludeArchived,
);
return items.map((item) => {
diff --git a/packages/database/src/models/__tests__/recent.test.ts b/packages/database/src/models/__tests__/recent.test.ts
index e316ef3da6c..24ae8d8f8ae 100644
--- a/packages/database/src/models/__tests__/recent.test.ts
+++ b/packages/database/src/models/__tests__/recent.test.ts
@@ -248,6 +248,52 @@ describe('RecentModel', () => {
expect(result.map((r) => r.id)).toEqual(['topic-chat']);
});
+ it('keeps archived topics unless excludeArchived is set', async () => {
+ await serverDB.insert(agents).values({ id: 'agent-inbox', userId, slug: 'inbox' });
+ await serverDB.insert(topics).values([
+ {
+ agentId: 'agent-inbox',
+ id: 'topic-active',
+ status: 'active',
+ updatedAt: minutesAgo(1),
+ userId,
+ },
+ { agentId: 'agent-inbox', id: 'topic-null', updatedAt: minutesAgo(2), userId },
+ {
+ agentId: 'agent-inbox',
+ id: 'topic-completed',
+ status: 'completed',
+ updatedAt: minutesAgo(3),
+ userId,
+ },
+ {
+ agentId: 'agent-inbox',
+ id: 'topic-archived',
+ status: 'archived',
+ updatedAt: minutesAgo(4),
+ userId,
+ },
+ {
+ agentId: 'agent-inbox',
+ id: 'topic-unread',
+ status: 'unread',
+ updatedAt: minutesAgo(5),
+ userId,
+ },
+ ]);
+
+ const all = await recentModel.queryRecent(10, ['topic']);
+ expect(all.map((r) => r.id)).toEqual([
+ 'topic-active',
+ 'topic-null',
+ 'topic-completed',
+ 'topic-archived',
+ ]);
+
+ const unarchived = await recentModel.queryRecent(10, ['topic'], false, false, false, true);
+ expect(unarchived.map((r) => r.id)).toEqual(['topic-active', 'topic-null']);
+ });
+
it('falls back to "Untitled Topic" when title is null', async () => {
await serverDB.insert(agents).values({ id: 'agent-inbox', userId, slug: 'inbox' });
await serverDB.insert(topics).values({
diff --git a/packages/database/src/models/recent.ts b/packages/database/src/models/recent.ts
index e8601691df7..3b6757fb78b 100644
--- a/packages/database/src/models/recent.ts
+++ b/packages/database/src/models/recent.ts
@@ -60,6 +60,7 @@ const TOOL_DOCUMENT_SOURCE_TYPES = ['agent', 'agent-signal', 'file', 'web'] as c
const TASK_FINAL_STATUSES = ['completed', 'canceled'];
const TOPIC_INBOX_STATUSES: ChatTopicStatus[] = ['running', 'unread'];
+const TOPIC_ARCHIVED_STATUSES: ChatTopicStatus[] = ['completed', 'archived'];
const LAST_MESSAGE_PREVIEW_LENGTH = 2000;
// A shared feed answers "what is the workspace working on", so a conversation
@@ -106,8 +107,13 @@ export class RecentModel {
* where every row is the owner's already.
*/
sharedOnly?: boolean,
+ // "Archive" in the UI writes `status: 'completed'`; off by default so Home keeps listing them.
+ excludeArchived?: boolean,
): Promise<RecentDbItem[]> => {
const scope = { userId: this.userId, workspaceId: this.workspaceId };
+ const excludedTopicStatuses = excludeArchived
+ ? [...TOPIC_INBOX_STATUSES, ...TOPIC_ARCHIVED_STATUSES]
+ : TOPIC_INBOX_STATUSES;
const requestedTypes = types ? new Set(types) : undefined;
// `tasks` uses `createdByUserId` instead of `userId`, so apply the
@@ -169,7 +175,7 @@ export class RecentModel {
),
),
or(isNull(topics.trigger), not(inArray(topics.trigger, SYSTEM_TOPIC_TRIGGERS))),
- or(isNull(topics.status), not(inArray(topics.status, TOPIC_INBOX_STATUSES))),
+ or(isNull(topics.status), not(inArray(topics.status, excludedTopicStatuses))),
),
);