From 66c86bac0d57eb89ef863d5e331e42fb12ef3847 Mon Sep 17 00:00:00 2001 From: Brad Harris Date: Sat, 22 Aug 2026 03:06:18 -0600 Subject: [PATCH] Derive the web AgentMessage type from the server's message row Last sub-item of the server<->web wire-type duplication cluster found by the 2026-08-14 audit. apps/web/src/hooks/use-agent-messages.ts hand-restated the nine fields of the message row that apps/server/src/messages/store.ts already declares as StoredMessage. The web copy now derives from it. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01CBimqehbS1VmatsnaL1VvQ --- apps/web/src/hooks/use-agent-messages.ts | 27 ++++++++++++++---------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/apps/web/src/hooks/use-agent-messages.ts b/apps/web/src/hooks/use-agent-messages.ts index eefe984c..c48fe991 100644 --- a/apps/web/src/hooks/use-agent-messages.ts +++ b/apps/web/src/hooks/use-agent-messages.ts @@ -1,18 +1,23 @@ import { useCallback } from "react"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; + +// The message shape is defined once on the server and imported type-only — +// esbuild erases this import, so nothing from the server reaches the web +// bundle. +import type { StoredMessage } from "../../../server/src/messages/store"; + import { api } from "@/lib/api"; -export type AgentMessage = { - id: string; - senderAgentId: string; - recipientAgentId: string; - senderName: string; - recipientName: string; - content: string; - delivered: boolean; - readAt: string | null; - createdAt: string; -}; +/** + * Wire shape of a message row. GET /api/v1/agents/:id/messages returns + * `MessageStore.listForAgent()` verbatim, but the /api/v1/history detail query + * projects the same row without the repo-root columns and reuses this type, so + * those two fields are omitted rather than aliased through. + */ +export type AgentMessage = Omit< + StoredMessage, + "senderRepoRoot" | "recipientRepoRoot" +>; type MessagesPayload = { messages: AgentMessage[];