Skip to content

Commit 51ed4db

Browse files
committed
fix(dashboard-agent-db): require a role on the messages the append-once queries accept
1 parent 3583403 commit 51ed4db

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

apps/webapp/test/dashboardAgentTranscriptStore.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ function textMessage(id: string, text = id) {
7575
return { id, role: "assistant" as const, parts: [{ type: "text", text }] };
7676
}
7777

78+
// Compile-time: the insert reads `role` off the body and throws without one, so a
79+
// message that satisfies the signature must never be able to lack it.
80+
() => {
81+
// @ts-expect-error a message with no role is not appendable
82+
void appendChatMessageOnceByChatId(agentDb, { chatId: "chat_x", message: { id: "m1" } });
83+
};
84+
7885
function toolMessage(id: string, state: "input-available" | "output-available") {
7986
return {
8087
id,

internal-packages/dashboard-agent-db/src/queries.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ export async function appendChatMessageOnce(
545545
chatId: string;
546546
userId: string;
547547
organizationId?: string;
548-
message: { id: string };
548+
message: { id: string; role: string };
549549
}
550550
): Promise<boolean> {
551551
return appendOneMessage(db, {
@@ -564,7 +564,7 @@ export async function appendChatMessageOnce(
564564
*/
565565
export async function appendChatMessageOnceByChatId(
566566
db: DashboardAgentDbOrTx,
567-
params: { chatId: string; message: { id: string } }
567+
params: { chatId: string; message: { id: string; role: string } }
568568
): Promise<boolean> {
569569
return appendOneMessage(db, { chatId: params.chatId, message: params.message, scope: [] });
570570
}

0 commit comments

Comments
 (0)