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.

๐Ÿ› fix: trim brief / task-template fetch overhead on home (#14516)

YuTengjing4721d14a81a1
diff --git a/packages/database/src/models/__tests__/brief.test.ts b/packages/database/src/models/__tests__/brief.test.ts
index 5c2b572f863..71ef4954b3c 100644
--- a/packages/database/src/models/__tests__/brief.test.ts
+++ b/packages/database/src/models/__tests__/brief.test.ts
@@ -2,7 +2,7 @@
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { getTestDB } from '../../core/getTestDB';
-import { users } from '../../schemas';
+import { agents, tasks, users } from '../../schemas';
import type { LobeChatDatabase } from '../../type';
import { BriefModel } from '../brief';
@@ -121,10 +121,15 @@ describe('BriefModel', () => {
});
});
- describe('listUnresolved', () => {
- it('should return unresolved briefs sorted by priority', async () => {
+ describe('listUnresolvedEnriched', () => {
+ it('should return unresolved briefs sorted by priority and exclude resolved ones', async () => {
const model = new BriefModel(serverDB, userId);
- await model.create({ priority: 'info', summary: 'Low', title: 'Info', type: 'result' });
+ const b1 = await model.create({
+ priority: 'info',
+ summary: 'Low',
+ title: 'Info',
+ type: 'result',
+ });
await model.create({
priority: 'urgent',
summary: 'High',
@@ -137,23 +142,91 @@ describe('BriefModel', () => {
title: 'Normal',
type: 'insight',
});
+ await model.resolve(b1.id);
- const unresolved = await model.listUnresolved();
- expect(unresolved).toHaveLength(3);
- expect(unresolved[0].priority).toBe('urgent');
- expect(unresolved[1].priority).toBe('normal');
- expect(unresolved[2].priority).toBe('info');
+ const rows = await model.listUnresolvedEnriched();
+ expect(rows).toHaveLength(2);
+ expect(rows[0].brief.priority).toBe('urgent');
+ expect(rows[1].brief.priority).toBe('normal');
});
- it('should exclude resolved briefs', async () => {
+ it('should join the producing agent and parent task status in one query', async () => {
+ await serverDB.insert(agents).values({
+ avatar: '๐Ÿค–',
+ backgroundColor: '#fff',
+ id: 'agent-x',
+ title: 'Agent X',
+ userId,
+ });
+ await serverDB.insert(tasks).values({
+ createdByUserId: userId,
+ id: 'task-x',
+ identifier: 'TASK-X',
+ instruction: 'do work',
+ name: 'Task X',
+ seq: 1,
+ status: 'paused',
+ });
+
const model = new BriefModel(serverDB, userId);
- const b1 = await model.create({ summary: 'A', title: 'Brief 1', type: 'result' });
- await model.create({ summary: 'B', title: 'Brief 2', type: 'result' });
+ await model.create({
+ agentId: 'agent-x',
+ priority: 'urgent',
+ summary: 'Has agent + task',
+ taskId: 'task-x',
+ title: 'Joined',
+ type: 'decision',
+ });
+ await model.create({
+ priority: 'info',
+ summary: 'Bare brief',
+ title: 'No agent',
+ type: 'insight',
+ });
- await model.resolve(b1.id);
+ const rows = await model.listUnresolvedEnriched();
+ expect(rows).toHaveLength(2);
+
+ const joined = rows.find((r) => r.brief.title === 'Joined')!;
+ expect(joined.agentRowId).toBe('agent-x');
+ expect(joined.agentAvatar).toBe('๐Ÿค–');
+ expect(joined.agentTitle).toBe('Agent X');
+ expect(joined.taskStatus).toBe('paused');
+
+ const bare = rows.find((r) => r.brief.title === 'No agent')!;
+ expect(bare.agentRowId).toBeNull();
+ expect(bare.taskStatus).toBeNull();
+ });
+
+ it('should still return briefs whose producing agent has been deleted', async () => {
+ const model = new BriefModel(serverDB, userId);
+ // agentId points at a row that doesn't exist โ€” LEFT JOIN should keep
+ // the brief and surface null agent fields rather than dropping it.
+ await model.create({
+ agentId: 'agent-ghost',
+ summary: 'Producer gone',
+ title: 'Ghost',
+ type: 'result',
+ });
+
+ const rows = await model.listUnresolvedEnriched();
+ expect(rows).toHaveLength(1);
+ expect(rows[0].brief.title).toBe('Ghost');
+ expect(rows[0].agentRowId).toBeNull();
+ expect(rows[0].agentAvatar).toBeNull();
+ });
+
+ it('should respect the default cap of 20 and a caller-provided limit', async () => {
+ const model = new BriefModel(serverDB, userId);
+ for (let i = 0; i < 25; i++) {
+ await model.create({ summary: `S${i}`, title: `Brief ${i}`, type: 'insight' });
+ }
+
+ const capped = await model.listUnresolvedEnriched();
+ expect(capped).toHaveLength(20);
- const unresolved = await model.listUnresolved();
- expect(unresolved).toHaveLength(1);
+ const trimmed = await model.listUnresolvedEnriched({ limit: 3 });
+ expect(trimmed).toHaveLength(3);
});
});
diff --git a/packages/database/src/models/brief.ts b/packages/database/src/models/brief.ts
index 2f7749b4242..9a91b3e7a16 100644
--- a/packages/database/src/models/brief.ts
+++ b/packages/database/src/models/brief.ts
@@ -1,9 +1,19 @@
import { and, desc, eq, isNull, notInArray, sql } from 'drizzle-orm';
+import { agents } from '../schemas/agent';
import type { BriefItem, NewBrief } from '../schemas/task';
-import { briefs } from '../schemas/task';
+import { briefs, tasks } from '../schemas/task';
import type { LobeChatDatabase } from '../type';
+export interface UnresolvedBriefRow {
+ agentAvatar: string | null;
+ agentBackgroundColor: string | null;
+ agentRowId: string | null;
+ agentTitle: string | null;
+ brief: BriefItem;
+ taskStatus: string | null;
+}
+
export class BriefModel {
private readonly userId: string;
private readonly db: LobeChatDatabase;
@@ -60,11 +70,26 @@ export class BriefModel {
return { briefs: items, total: Number(countResult[0].count) };
}
- // For Daily Brief homepage โ€” unresolved briefs sorted by priority
- async listUnresolved(): Promise<BriefItem[]> {
+ /**
+ * Home Daily Brief feed: unresolved briefs sorted by priority, joined
+ * with the producing agent + parent task in a single SQL. Capped at 20
+ * so heavy-inbox users don't pay the full enrich cost on every home
+ * render โ€” the rest is reachable via the task list page.
+ */
+ async listUnresolvedEnriched(options?: { limit?: number }): Promise<UnresolvedBriefRow[]> {
+ const { limit = 20 } = options ?? {};
return this.db
- .select()
+ .select({
+ agentAvatar: agents.avatar,
+ agentBackgroundColor: agents.backgroundColor,
+ agentRowId: agents.id,
+ agentTitle: agents.title,
+ brief: briefs,
+ taskStatus: tasks.status,
+ })
.from(briefs)
+ .leftJoin(agents, eq(briefs.agentId, agents.id))
+ .leftJoin(tasks, eq(briefs.taskId, tasks.id))
.where(and(eq(briefs.userId, this.userId), isNull(briefs.resolvedAt)))
.orderBy(
sql`CASE
@@ -73,7 +98,8 @@ export class BriefModel {
ELSE 2
END`,
desc(briefs.createdAt),
- );
+ )
+ .limit(limit);
}
async findByTaskId(taskId: string): Promise<BriefItem[]> {
diff --git a/src/features/RecommendTaskTemplates/useResolvedInterestKeys.ts b/src/features/RecommendTaskTemplates/useResolvedInterestKeys.ts
index 309f2822374..810eb8dd669 100644
--- a/src/features/RecommendTaskTemplates/useResolvedInterestKeys.ts
+++ b/src/features/RecommendTaskTemplates/useResolvedInterestKeys.ts
@@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next';
import { INTEREST_AREAS } from '@/routes/onboarding/config';
import { useUserStore } from '@/store/user';
import { userProfileSelectors } from '@/store/user/selectors';
+import { authSelectors } from '@/store/user/slices/auth/selectors';
/**
* onboarding stores localized labels in `user.interests` (e.g. "ๅ†…ๅฎนๅˆ›ไฝœ",
@@ -13,18 +14,23 @@ import { userProfileSelectors } from '@/store/user/selectors';
* canonical keys). Unresolved entries are lowercased passthroughs โ€” server
* treats them as non-matching.
*
- * Returns `null` while the onboarding namespace is still loading (it's lazy-
- * loaded, not in the startup bundle). Without this gate, the first render
- * would resolve all localized labels to passthrough strings, fire an SWR
- * request with the wrong keys, and get back a fallback list โ€” then re-fire
- * once the namespace lands. Callers should keep SWR disabled while null.
+ * Returns `null` while either:
+ * - the user store hasn't finished hydrating (`interests` is `[]` until then,
+ * which would fire an SWR request with empty keys and immediately re-fire
+ * once the real interests land โ€” wasted round trip), or
+ * - the onboarding namespace is still loading (lazy-loaded, not in startup
+ * bundle; without this gate localized labels resolve to passthrough strings
+ * on first render and re-resolve correctly after the namespace lands).
+ *
+ * Callers should keep SWR disabled while null.
*/
export const useResolvedInterestKeys = (): string[] | null => {
+ const isUserLoaded = useUserStore(authSelectors.isLoaded);
const userInterests = useUserStore(userProfileSelectors.interests);
const { t, ready } = useTranslation('onboarding');
return useMemo(() => {
- if (!ready) return null;
+ if (!isUserLoaded || !ready) return null;
const labelToKey = new Map<string, string>();
for (const area of INTEREST_AREAS) {
labelToKey.set(area.key, area.key);
@@ -35,5 +41,5 @@ export const useResolvedInterestKeys = (): string[] | null => {
const k = raw.trim().toLowerCase();
return labelToKey.get(k) ?? k;
});
- }, [userInterests, t, ready]);
+ }, [isUserLoaded, userInterests, t, ready]);
};
diff --git a/src/server/routers/lambda/brief.ts b/src/server/routers/lambda/brief.ts
index c3b9443a939..7d728275461 100644
--- a/src/server/routers/lambda/brief.ts
+++ b/src/server/routers/lambda/brief.ts
@@ -134,7 +134,6 @@ export const briefRouter = router({
try {
const service = new BriefService(ctx.serverDB, ctx.userId);
const data = await service.listUnresolved();
-
return { data, success: true };
} catch (error) {
console.error('[brief:listUnresolved]', error);
diff --git a/src/server/services/brief/index.test.ts b/src/server/services/brief/index.test.ts
index 72b79fa41c4..5e77749752e 100644
--- a/src/server/services/brief/index.test.ts
+++ b/src/server/services/brief/index.test.ts
@@ -38,6 +38,7 @@ describe('BriefService', () => {
const mockBriefModel = {
list: vi.fn(),
listUnresolved: vi.fn(),
+ listUnresolvedEnriched: vi.fn(),
resolve: vi.fn(),
};
@@ -101,7 +102,7 @@ describe('BriefService', () => {
{ avatar: '๐Ÿ”ง', backgroundColor: null, id: 'agent-c', title: 'Agent C' },
]);
- const result = await service.enrichBriefsWithAgents(briefs);
+ const result = await service.enrichBriefsWithAgents(briefs, { includeTreeAgents: true });
expect(result[0].agent).toEqual({
avatar: '๐Ÿค–',
@@ -191,7 +192,7 @@ describe('BriefService', () => {
},
]);
- const result = await service.enrichBriefsWithAgents(briefs);
+ const result = await service.enrichBriefsWithAgents(briefs, { includeTreeAgents: true });
expect(result[0].agents).toEqual([
{
@@ -224,10 +225,106 @@ describe('BriefService', () => {
{ avatar: '๐Ÿง ', backgroundColor: '#fff', id: 'agent-b', title: 'Agent B' },
]);
- const result = await service.enrichBriefsWithAgents(briefs);
+ const result = await service.enrichBriefsWithAgents(briefs, { includeTreeAgents: true });
expect(result[0].agents.map((agent) => agent.id)).toEqual(['agent-a', 'agent-b']);
});
+
+ it('should default to skipping the task-tree CTE and return empty agents[]', async () => {
+ const service = new BriefService(db, userId);
+
+ const briefs = [
+ { agentId: 'agent-a', id: 'b1', taskId: 'task-1', title: 'Brief 1' },
+ ] as any[];
+
+ mockTaskModel.findByIds.mockResolvedValue([{ id: 'task-1', status: 'scheduled' }]);
+ mockAgentModel.getAgentAvatarsByIds.mockResolvedValue([
+ { avatar: '๐Ÿค–', backgroundColor: null, id: 'agent-a', title: 'Agent A' },
+ ]);
+
+ const result = await service.enrichBriefsWithAgents(briefs);
+
+ expect(result[0].agent).toEqual({
+ avatar: '๐Ÿค–',
+ backgroundColor: null,
+ id: 'agent-a',
+ title: 'Agent A',
+ });
+ expect(result[0].taskStatus).toBe('scheduled');
+ expect(result[0].agents).toEqual([]);
+ expect(mockTaskModel.getTreeAgentIdsForTaskIds).not.toHaveBeenCalled();
+ // direct-agent ids are passed straight through, no need to wait on the CTE.
+ expect(mockAgentModel.getAgentAvatarsByIds).toHaveBeenCalledWith(['agent-a']);
+ });
+ });
+
+ describe('enrichBriefAgentOnly', () => {
+ it('should return briefs with null agent when no agentIds and skip db calls', async () => {
+ const service = new BriefService(db, userId);
+
+ const briefs = [
+ { agentId: null, id: 'b1', taskId: 'task-1', title: 'Brief 1' },
+ { agentId: null, id: 'b2', taskId: null, title: 'Brief 2' },
+ ] as any[];
+
+ const result = await service.enrichBriefAgentOnly(briefs);
+
+ expect(result).toHaveLength(2);
+ expect(result[0].agent).toBeNull();
+ expect(result[1].agent).toBeNull();
+ expect(mockAgentModel.getAgentAvatarsByIds).not.toHaveBeenCalled();
+ expect(mockTaskModel.findByIds).not.toHaveBeenCalled();
+ expect(mockTaskModel.getTreeAgentIdsForTaskIds).not.toHaveBeenCalled();
+ });
+
+ it('should attach the direct producing agent without calling task tree CTE', async () => {
+ const service = new BriefService(db, userId);
+
+ const briefs = [
+ { agentId: 'agent-a', id: 'b1', taskId: 'task-1', title: 'Brief 1' },
+ { agentId: 'agent-b', id: 'b2', taskId: 'task-2', title: 'Brief 2' },
+ ] as any[];
+
+ mockAgentModel.getAgentAvatarsByIds.mockResolvedValue([
+ { avatar: '๐Ÿค–', backgroundColor: null, id: 'agent-a', title: 'Agent A' },
+ { avatar: '๐Ÿ”ง', backgroundColor: null, id: 'agent-b', title: 'Agent B' },
+ ]);
+
+ const result = await service.enrichBriefAgentOnly(briefs);
+
+ expect(result[0].agent).toEqual({
+ avatar: '๐Ÿค–',
+ backgroundColor: null,
+ id: 'agent-a',
+ title: 'Agent A',
+ });
+ expect(result[1].agent).toEqual({
+ avatar: '๐Ÿ”ง',
+ backgroundColor: null,
+ id: 'agent-b',
+ title: 'Agent B',
+ });
+ expect(mockAgentModel.getAgentAvatarsByIds).toHaveBeenCalledWith(
+ expect.arrayContaining(['agent-a', 'agent-b']),
+ );
+ expect(mockTaskModel.findByIds).not.toHaveBeenCalled();
+ expect(mockTaskModel.getTreeAgentIdsForTaskIds).not.toHaveBeenCalled();
+ });
+
+ it('should leave agent null when the producing agent has been deleted', async () => {
+ const service = new BriefService(db, userId);
+
+ const briefs = [
+ { agentId: 'agent-gone', id: 'b1', taskId: 'task-1', title: 'Brief' },
+ ] as any[];
+
+ mockAgentModel.getAgentAvatarsByIds.mockResolvedValue([]);
+
+ const result = await service.enrichBriefAgentOnly(briefs);
+
+ expect(result[0].agent).toBeNull();
+ expect(mockAgentModel.getAgentAvatarsByIds).toHaveBeenCalledWith(['agent-gone']);
+ });
});
describe('list', () => {
@@ -249,18 +346,47 @@ describe('BriefService', () => {
});
describe('listUnresolved', () => {
- it('should return enriched unresolved briefs', async () => {
+ it('should map joined rows into BriefWithAgent without re-fetching', async () => {
const service = new BriefService(db, userId);
- mockBriefModel.listUnresolved.mockResolvedValue([
- { agentId: null, id: 'b1', taskId: null, title: 'Unresolved' },
+ mockBriefModel.listUnresolvedEnriched.mockResolvedValue([
+ {
+ agentAvatar: null,
+ agentBackgroundColor: null,
+ agentRowId: null,
+ agentTitle: null,
+ brief: { agentId: null, id: 'b1', taskId: null, title: 'Solo' },
+ taskStatus: null,
+ },
+ {
+ agentAvatar: '๐Ÿค–',
+ agentBackgroundColor: '#fff',
+ agentRowId: 'agent-a',
+ agentTitle: 'Agent A',
+ brief: { agentId: 'agent-a', id: 'b2', taskId: 'task-1', title: 'With Task' },
+ taskStatus: 'scheduled',
+ },
]);
const result = await service.listUnresolved();
- expect(result).toHaveLength(1);
- expect(result[0].agent).toBeNull();
- expect(mockBriefModel.listUnresolved).toHaveBeenCalled();
+ expect(result).toHaveLength(2);
+ expect(result[0]).toMatchObject({
+ agent: null,
+ agents: [],
+ id: 'b1',
+ taskStatus: null,
+ });
+ expect(result[1]).toMatchObject({
+ agent: { avatar: '๐Ÿค–', backgroundColor: '#fff', id: 'agent-a', title: 'Agent A' },
+ agents: [],
+ id: 'b2',
+ taskStatus: 'scheduled',
+ });
+ // No follow-up enrichment SQLs.
+ expect(mockTaskModel.findByIds).not.toHaveBeenCalled();
+ expect(mockTaskModel.getTreeAgentIdsForTaskIds).not.toHaveBeenCalled();
+ expect(mockAgentModel.getAgentAvatarsByIds).not.toHaveBeenCalled();
});
});
diff --git a/src/server/services/brief/index.ts b/src/server/services/brief/index.ts
index 4b1cb99c387..0e3a9ea35b9 100644
--- a/src/server/services/brief/index.ts
+++ b/src/server/services/brief/index.ts
@@ -37,7 +37,49 @@ export class BriefService {
this.taskModel = new TaskModel(db, userId);
}
- async enrichBriefsWithAgents(briefs: BriefItem[]): Promise<BriefWithAgent[]> {
+ /**
+ * Lightweight enrich for callers that only need the direct producing agent
+ * (e.g. task detail, where the surrounding payload already covers task tree
+ * + status). Skips the recursive task-tree CTE and `taskFindByIds` round
+ * trip used by {@link enrichBriefsWithAgents}.
+ */
+ async enrichBriefAgentOnly(
+ briefs: BriefItem[],
+ ): Promise<(BriefItem & { agent: AgentAvatarInfo | null })[]> {
+ const directAgentIds = [
+ ...new Set(briefs.map((b) => b.agentId).filter((id): id is string => !!id)),
+ ];
+ if (directAgentIds.length === 0) {
+ return briefs.map((brief) => ({ ...brief, agent: null }));
+ }
+
+ const agentList = await this.agentModel.getAgentAvatarsByIds(directAgentIds);
+ const agentMap: Record<string, AgentAvatarInfo> = Object.fromEntries(
+ agentList.map((a) => [a.id, a]),
+ );
+
+ return briefs.map((brief) => ({
+ ...brief,
+ agent: brief.agentId ? (agentMap[brief.agentId] ?? null) : null,
+ }));
+ }
+
+ /**
+ * Enrich briefs with the producing agent + parent task status (always),
+ * plus optionally the full task-tree agent roster (`agents[]`).
+ *
+ * `includeTreeAgents` defaults to `false` because no current consumer
+ * renders `brief.agents[]` โ€” `BriefCard` only uses `brief.agent`. Skipping
+ * the recursive task-tree CTE turns the previous waterfall (CTE, then
+ * `getAgentAvatars` once tree ids are known) into two truly parallel SQLs
+ * (`taskFindByIds` + `getAgentAvatars` over direct agents only). Pass
+ * `true` if a future caller actually needs the tree roster.
+ */
+ async enrichBriefsWithAgents(
+ briefs: BriefItem[],
+ options: { includeTreeAgents?: boolean } = {},
+ ): Promise<BriefWithAgent[]> {
+ const { includeTreeAgents = false } = options;
const taskIds = [...new Set(briefs.map((b) => b.taskId).filter((id): id is string => !!id))];
const directAgentIds = [
...new Set(briefs.map((b) => b.agentId).filter((id): id is string => !!id)),
@@ -46,19 +88,21 @@ export class BriefService {
return briefs.map((brief) => ({ ...brief, agent: null, agents: [], taskStatus: null }));
}
- const emptyTreeAgentIdsByTaskId: Record<string, string[]> = {};
- const [taskRows, treeAgentIdsByTaskId] = await Promise.all([
+ const treeAgentIdsByTaskId =
+ includeTreeAgents && taskIds.length > 0
+ ? await this.taskModel.getTreeAgentIdsForTaskIds(taskIds)
+ : ({} as Record<string, string[]>);
+ const allAgentIds = [
+ ...new Set([...directAgentIds, ...Object.values(treeAgentIdsByTaskId).flat()]),
+ ];
+
+ const [taskRows, agentList] = await Promise.all([
taskIds.length > 0 ? this.taskModel.findByIds(taskIds) : Promise.resolve([]),
- taskIds.length > 0
- ? this.taskModel.getTreeAgentIdsForTaskIds(taskIds)
- : Promise.resolve(emptyTreeAgentIdsByTaskId),
+ allAgentIds.length > 0
+ ? this.agentModel.getAgentAvatarsByIds(allAgentIds)
+ : Promise.resolve([]),
]);
- const agentIds = [
- ...new Set([...directAgentIds, ...Object.values(treeAgentIdsByTaskId).flat()]),
- ];
- const agentList =
- agentIds.length > 0 ? await this.agentModel.getAgentAvatarsByIds(agentIds) : [];
const taskStatusMap = Object.fromEntries(
taskRows.map((t) => [t.id, (t.status as TaskStatus) ?? null]),
);
@@ -67,22 +111,24 @@ export class BriefService {
);
return briefs.map((brief) => {
- const briefAgentIds = new Set<string>();
- if (brief.agentId) {
- briefAgentIds.add(brief.agentId);
- }
- if (brief.taskId) {
- for (const agentId of treeAgentIdsByTaskId[brief.taskId] ?? []) {
- briefAgentIds.add(agentId);
+ let agents: AgentAvatarInfo[] = [];
+ if (includeTreeAgents) {
+ const briefAgentIds = new Set<string>();
+ if (brief.agentId) briefAgentIds.add(brief.agentId);
+ if (brief.taskId) {
+ for (const agentId of treeAgentIdsByTaskId[brief.taskId] ?? []) {
+ briefAgentIds.add(agentId);
+ }
}
+ agents = [...briefAgentIds]
+ .map((agentId) => agentMap[agentId])
+ .filter((agent): agent is AgentAvatarInfo => Boolean(agent));
}
return {
...brief,
agent: brief.agentId ? (agentMap[brief.agentId] ?? null) : null,
- agents: [...briefAgentIds]
- .map((agentId) => agentMap[agentId])
- .filter((agent): agent is AgentAvatarInfo => Boolean(agent)),
+ agents,
taskStatus: brief.taskId ? (taskStatusMap[brief.taskId] ?? null) : null,
};
});
@@ -94,9 +140,28 @@ export class BriefService {
return { briefs: data, total: result.total };
}
- async listUnresolved() {
- const items = await this.briefModel.listUnresolved();
- return this.enrichBriefsWithAgents(items);
+ /**
+ * Home Daily Brief feed. Uses the JOIN-based model query so the producing
+ * agent + parent task status come back in a single round trip โ€” no
+ * separate enrichment pass.
+ */
+ async listUnresolved(): Promise<BriefWithAgent[]> {
+ const rows = await this.briefModel.listUnresolvedEnriched();
+ return rows.map(
+ ({ brief, agentRowId, agentAvatar, agentBackgroundColor, agentTitle, taskStatus }) => ({
+ ...brief,
+ agent: agentRowId
+ ? {
+ avatar: agentAvatar,
+ backgroundColor: agentBackgroundColor,
+ id: agentRowId,
+ title: agentTitle,
+ }
+ : null,
+ agents: [],
+ taskStatus: (taskStatus as TaskStatus) ?? null,
+ }),
+ );
}
/**
diff --git a/src/server/services/task/index.test.ts b/src/server/services/task/index.test.ts
index 29ad725b565..aaf0dc46102 100644
--- a/src/server/services/task/index.test.ts
+++ b/src/server/services/task/index.test.ts
@@ -1123,7 +1123,7 @@ describe('TaskService', () => {
// Force the brief enrichment path to reject without breaking the
// sibling resolveAuthors call (which shares the agent model mock).
const enrichSpy = vi
- .spyOn(BriefService.prototype, 'enrichBriefsWithAgents')
+ .spyOn(BriefService.prototype, 'enrichBriefAgentOnly')
.mockRejectedValueOnce(new Error('DB error'));
const service = new TaskService(db, userId);
diff --git a/src/server/services/task/index.ts b/src/server/services/task/index.ts
index 87f55c89358..3d5df37443c 100644
--- a/src/server/services/task/index.ts
+++ b/src/server/services/task/index.ts
@@ -195,7 +195,7 @@ export class TaskService {
const [authorMap, enrichedBriefs] = await Promise.all([
this.resolveAuthors(agentIds, userIds),
this.briefService
- .enrichBriefsWithAgents(briefs)
+ .enrichBriefAgentOnly(briefs)
.catch(() => briefs.map((b) => ({ ...b, agent: null }))),
]);