fix: Retry sends message with retry flag to avoid duplicate storage
Added retry:true flag to sendChatMessage input. Server skips storing the user message when retry is set. Frontend uses a dedicated retryLastMessage function that skips the optimistic message add.
This commit is contained in:
@@ -26,6 +26,7 @@ export function chatSessionProcedures(publicProcedure: ProcedureBuilder) {
|
||||
targetId: z.string().min(1),
|
||||
initiativeId: z.string().min(1),
|
||||
message: z.string().min(1),
|
||||
retry: z.boolean().optional(),
|
||||
provider: z.string().optional(),
|
||||
}))
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
@@ -49,18 +50,20 @@ export function chatSessionProcedures(publicProcedure: ProcedureBuilder) {
|
||||
});
|
||||
}
|
||||
|
||||
// Store user message
|
||||
await chatRepo.createMessage({
|
||||
chatSessionId: session.id,
|
||||
role: 'user',
|
||||
content: input.message,
|
||||
});
|
||||
// Store user message (skip on retry — message already exists)
|
||||
if (!input.retry) {
|
||||
await chatRepo.createMessage({
|
||||
chatSessionId: session.id,
|
||||
role: 'user',
|
||||
content: input.message,
|
||||
});
|
||||
|
||||
ctx.eventBus.emit({
|
||||
type: 'chat:message_created' as const,
|
||||
timestamp: new Date(),
|
||||
payload: { chatSessionId: session.id, role: 'user' as const },
|
||||
});
|
||||
ctx.eventBus.emit({
|
||||
type: 'chat:message_created' as const,
|
||||
timestamp: new Date(),
|
||||
payload: { chatSessionId: session.id, role: 'user' as const },
|
||||
});
|
||||
}
|
||||
|
||||
// Check if agent exists and is waiting for input
|
||||
if (session.agentId) {
|
||||
|
||||
Reference in New Issue
Block a user