🤯 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.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
✨ feat(acceptance): link extension inbox rows to their Task and count deliveries (#23208)
Innei157c8aa61291
diff --git a/apps/server/src/router-hono/acceptance-review/__tests__/inbox.test.ts b/apps/server/src/router-hono/acceptance-review/__tests__/inbox.test.tsindex 926e97753ef..8df95ca0804 100644--- a/apps/server/src/router-hono/acceptance-review/__tests__/inbox.test.ts+++ b/apps/server/src/router-hono/acceptance-review/__tests__/inbox.test.ts@@ -76,7 +76,11 @@ const mark = (clientId: string, content: string, path = '/notebook') => ({const submitRound = async (userId: string,contents: string[],- delivery?: { status: string; verdicts?: ('failed' | 'passed' | 'uncertain')[] },+ delivery?: {+ status: string;+ taskInWorkspace?: boolean;+ verdicts?: ('failed' | 'passed' | 'uncertain')[];+ },) => {const review = await model.createDraft({ projectId, siteId: site.id, userId, workspaceId });const marks = [];@@ -92,6 +96,7 @@ const submitRound = async (instruction: 'review round',seq: 1,status: 'completed',+ workspaceId: delivery.taskInWorkspace ? workspaceId : undefined,});await model.linkTask(review.id, taskId);const [row] = await serverDB@@ -139,7 +144,44 @@ const submitRound = async (workspaceId,})),);- return { deliveryId: row.id, marks, reviewId: review.id, run };+ return {+ deliveryId: row.id,+ identifier: `T-${taskId.slice(0, 6)}`,+ marks,+ reviewId: review.id,+ run,+ };+};++const addRun = async (+ round: { deliveryId?: string; marks: { id: string }[] },+ roundIndex: number,+ verdicts: ('failed' | 'passed' | 'uncertain')[],+) => {+ const [run] = await serverDB+ .insert(verifyRuns)+ .values({+ acceptanceId: round.deliveryId!,+ plan: [],+ planConfirmedAt: new Date(),+ roundIndex,+ userId: memberId,+ workspaceId,+ })+ .returning();+ if (verdicts.length)+ await serverDB.insert(verifyCheckResults).values(+ verdicts.map((verdict, index) => ({+ checkItemId: round.marks[index].id,+ status: verdict === 'passed' ? ('passed' as const) : ('failed' as const),+ userId: memberId,+ verdict,+ verifierType: 'agent' as const,+ verifyRunId: run.id,+ workspaceId,+ })),+ );+ return run;};beforeEach(async () => {@@ -187,6 +229,7 @@ describe('GET /extension/inbox', () => {expect(body.items).toEqual([{deliveredAt: round.run!.updatedAt.toISOString(),+ delivery: 1,marks: 2,name: 'Cards are too tight',notPassed: 1,@@ -196,11 +239,71 @@ describe('GET /extension/inbox', () => {round: 1,site: { id: site.id, name: 'Marketing site' },submittedAt: expect.any(String),+ task: { identifier: round.identifier, path: `/task/${round.identifier}` },url: `${ORIGIN}/page-0`,},]);});+ it("links a workspace Task to its page under the workspace's slug", async () => {+ const round = await submitRound(memberId, ['Spacing'], {+ status: 'delivered',+ taskInWorkspace: true,+ verdicts: ['passed'],+ });++ const { body } = await inbox(memberId);++ expect(body.items[0].task).toEqual({+ identifier: round.identifier,+ path: `/${ownerId}/task/${round.identifier}`,+ });+ });++ it('links a running round to its Task but gives it no delivery number', async () => {+ const round = await submitRound(memberId, ['Spacing'], { status: 'verifying' });++ const { body } = await inbox(memberId);++ expect(body.items[0]).toMatchObject({+ phase: 'running',+ task: { identifier: round.identifier },+ });+ expect(body.items[0].delivery).toBeUndefined();+ });++ it('numbers a delivery after a send-back as the second one', async () => {+ const round = await submitRound(memberId, ['Spacing', 'Colour'], {+ status: 'delivered',+ verdicts: ['failed', 'passed'],+ });+ await addRun(round, 2, ['passed']);++ const { body } = await inbox(memberId);++ expect(body.items[0].delivery).toBe(2);+ });++ it('does not count a verify round that produced no result as a delivery', async () => {+ const round = await submitRound(memberId, ['Spacing'], {+ status: 'delivered',+ verdicts: ['passed'],+ });+ await addRun(round, 2, []);++ const { body } = await inbox(memberId);++ expect(body.items[0].delivery).toBe(1);+ });++ it('numbers a delivered round without any Agent result as the first delivery', async () => {+ await submitRound(memberId, ['Spacing'], { status: 'delivered' });++ const { body } = await inbox(memberId);++ expect(body.items[0].delivery).toBe(1);+ });+it('counts marks without an Agent result as not passed', async () => {await submitRound(memberId, ['a', 'b', 'c'], { status: 'delivered', verdicts: ['passed'] });@@ -217,15 +320,23 @@ describe('GET /extension/inbox', () => {expect(body.items).toHaveLength(1);expect(body.items[0]).toMatchObject({ marks: 1, notPassed: 1, passed: 0, phase: 'running' });expect(body.items[0].deliveredAt).toBeUndefined();+ expect(body.items[0].task).toBeUndefined();});- it('shows a delivery that will never deliver as failed', async () => {+ it('shows an errored delivery as failed', async () => {await submitRound(memberId, ['Spacing'], { status: 'errored' });++ const { body } = await inbox(memberId);++ expect(body.items.map((item: { phase: string }) => item.phase)).toEqual(['failed']);+ });++ it('shows a delivery the reviewer asked to change as running again', async () => {await submitRound(memberId, ['Colour'], { status: 'rejected' });const { body } = await inbox(memberId);- expect(body.items.map((item: { phase: string }) => item.phase)).toEqual(['failed', 'failed']);+ expect(body.items.map((item: { phase: string }) => item.phase)).toEqual(['running']);});it("leaves out accepted and closed rounds, drafts and other people's rounds", async () => {diff --git a/apps/server/src/router-hono/acceptance-review/inbox.ts b/apps/server/src/router-hono/acceptance-review/inbox.tsindex fdebb43bc82..5f13f21adba 100644--- a/apps/server/src/router-hono/acceptance-review/inbox.ts+++ b/apps/server/src/router-hono/acceptance-review/inbox.ts@@ -1,10 +1,18 @@import type { AcceptanceReview } from '@lobechat/types';-import { and, desc, eq, isNull, notInArray, or } from 'drizzle-orm';+import { and, countDistinct, desc, eq, isNull, notInArray, or } from 'drizzle-orm';import type { Context } from 'hono';import pMap from 'p-map';import { AcceptanceReviewModel } from '@/database/models/acceptanceReview';-import { acceptanceReviews, acceptances, projectSites, verifyRuns } from '@/database/schemas';+import {+ acceptanceReviews,+ acceptances,+ projectSites,+ tasks,+ verifyCheckResults,+ verifyRuns,+ workspaces,+} from '@/database/schemas';import type { LobeChatDatabase } from '@/database/type';import { resolveReviewAccess } from '@/server/services/acceptanceReview/access';import { projectReview } from '@/server/services/acceptanceReview/projection';@@ -14,7 +22,7 @@ import type { ReviewEnv } from './auth';const INBOX_LIMIT = 50;const CANDIDATE_LIMIT = 200;const IO_CONCURRENCY = 5;-const NEVER_DELIVERS = new Set(['errored', 'rejected']);+const NEVER_DELIVERS = new Set(['errored']);const FINISHED = new Set(['accepted', 'closed']);type InboxPhase = 'delivered' | 'failed' | 'running';@@ -29,6 +37,29 @@ const latestRunTime = async (db: LobeChatDatabase, acceptanceId: string) => {return run?.updatedAt.toISOString();};+// A send-back reruns the Task without recording a reject decision, so deliveries are counted from+// the verify rounds that produced a result: every run of the Task opens one.+const deliveryNumber = async (db: LobeChatDatabase, acceptanceId: string) => {+ const [row] = await db+ .select({ n: countDistinct(verifyRuns.id) })+ .from(verifyRuns)+ .innerJoin(verifyCheckResults, eq(verifyCheckResults.verifyRunId, verifyRuns.id))+ .where(eq(verifyRuns.acceptanceId, acceptanceId));+ return Math.max(Number(row?.n ?? 0), 1);+};++const taskLink = async (db: LobeChatDatabase, taskId: string) => {+ const [row] = await db+ .select({ identifier: tasks.identifier, slug: workspaces.slug })+ .from(tasks)+ .leftJoin(workspaces, eq(workspaces.id, tasks.workspaceId))+ .where(eq(tasks.id, taskId))+ .limit(1);+ if (!row?.identifier) return undefined;+ const path = `/task/${row.identifier}`;+ return { identifier: row.identifier, path: row.slug ? `/${row.slug}${path}` : path };+};+const createSiteLookup = (db: LobeChatDatabase, userId: string) => {const model = new AcceptanceReviewModel(db);const sites = new Map<string, Promise<{ name: string; order: string[] } | undefined>>();@@ -68,15 +99,18 @@ const describeRound = async (: projection.phase === 'delivered'? 'delivered': 'running';- const deliveredAt =- phase === 'delivered' && projection.deliveryId- ? await latestRunTime(db, projection.deliveryId)- : undefined;+ const delivered = phase === 'delivered' && projection.deliveryId;+ const [deliveredAt, delivery, task] = await Promise.all([+ delivered ? latestRunTime(db, projection.deliveryId!) : undefined,+ delivered ? deliveryNumber(db, projection.deliveryId!) : undefined,+ projection.task ? taskLink(db, projection.task.id) : undefined,+ ]);const first = marks[0];const index = site.order.indexOf(row.id);const passed = projection.counts.agentPassed;return {deliveredAt,+ delivery,marks: marks.length,name: first?.content ?? '',notPassed: marks.length - passed,@@ -86,6 +120,7 @@ const describeRound = async (round: index < 0 ? 0 : site.order.length - index,site: { id: row.siteId, name: site.name },submittedAt: (row.submittedAt ?? row.createdAt).toISOString(),+ task,url: first?.url ?? '',};};