Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions drizzle/migrations/0007_create_prompt_generation_jobs.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- Migration 0007: Create missing prompt_generation_jobs table
-- This table was defined in schema.ts and migration 0002 but was never applied to production.

CREATE TABLE IF NOT EXISTS "prompt_generation_jobs" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"user_id" uuid NOT NULL,
"domain" text NOT NULL,
"status" text DEFAULT 'pending' NOT NULL,
"result_prompt" text,
"error_message" text,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "prompt_generation_jobs" ADD CONSTRAINT "prompt_generation_jobs_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action NOT VALID;
--> statement-breakpoint
ALTER TABLE "prompt_generation_jobs" VALIDATE CONSTRAINT "prompt_generation_jobs_user_id_fkey";
12 changes: 12 additions & 0 deletions drizzle/migrations/0008_allow_data_message_role.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- Migration 0008: Allow 'data' as a valid message role
-- The messages_role_check constraint currently only allows: user, assistant, system, tool
-- Internal context messages (drawing context, calendar notes) use role 'data'
-- This migration adds 'data' to the allowed values.
-- NOTE: updateDrawingContext and calendar.ts have been updated to use 'tool' instead of 'data'.
-- This migration is preventive: if any future code needs role 'data', it will be available.

ALTER TABLE "messages" DROP CONSTRAINT IF EXISTS "messages_role_check";
--> statement-breakpoint
ALTER TABLE "messages" ADD CONSTRAINT "messages_role_check" CHECK (role = ANY (ARRAY['user'::text, 'assistant'::text, 'system'::text, 'tool'::text, 'data'::text])) NOT VALID;
--> statement-breakpoint
ALTER TABLE "messages" VALIDATE CONSTRAINT "messages_role_check";
2 changes: 1 addition & 1 deletion lib/actions/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export async function saveNote(noteData: NewCalendarNote | CalendarNote): Promis
const calendarContextMessage: NewMessage = {
chatId: newNote.chatId,
userId: userId,
role: 'data',
role: 'tool',
content: JSON.stringify({
type: 'calendar_note',
note: newNote,
Expand Down
2 changes: 1 addition & 1 deletion lib/actions/chat-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export async function saveChat(chatData: NewChat, messagesData: Omit<NewMessage,
const messagesToInsert: typeof messages.$inferInsert[] = [];

for (const msg of messagesData) {
let id = msg.id;
let id = msg.id ?? crypto.randomUUID();

// If we've already seen this ID in this batch, generate a unique one
while (seenIds.has(id)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/actions/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export async function updateDrawingContext(chatId: string, contextData: { drawnF
const newDrawingMessage: DbNewMessage = {
userId: userId,
chatId: chatId,
role: 'data',
role: 'tool',
content: JSON.stringify(contextData),
createdAt: new Date(),
Comment on lines 235 to 240

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- lib/actions/chat.ts (around lines 220-260) ---'
sed -n '220,260p' lib/actions/chat.ts

echo
echo '--- app/actions.tsx (around lines 360-410) ---'
sed -n '360,410p' app/actions.tsx

echo
echo '--- search for tool-message handling and JSON.stringify usage ---'
rg -n "role:\s*'tool'|role === 'tool'|JSON\.stringify\(msg\.content\)|content:\s*JSON\.stringify|CoreMessage|tool" lib app -g '!**/dist/**' -g '!**/build/**'

Repository: QueueLab/QCX

Length of output: 14446


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- lib/actions/chat.ts (around lines 200-220) ---'
sed -n '200,220p' lib/actions/chat.ts

echo
echo '--- app/actions.tsx (around lines 150-180) ---'
sed -n '150,180p' app/actions.tsx

echo
echo '--- app/actions.tsx (around lines 660-710) ---'
sed -n '660,710p' app/actions.tsx

echo
echo '--- lib/types/index.ts (around lines 55-80) ---'
sed -n '55,80p' lib/types/index.ts

Repository: QueueLab/QCX

Length of output: 4245


Avoid double-stringifying the drawing-context tool payload. app/actions.tsx:377-388 stringifies every tool message again before sending it to researcher, so the JSON string saved in lib/actions/chat.ts becomes an escaped string instead of the original payload. Keep the existing string as-is for this path, or stringify in one place only.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/actions/chat.ts` around lines 235 - 240, The drawing-context tool payload
is being stringified twice between chat message creation and the researcher
path. Update the `newDrawingMessage` flow in `chat.ts` and the `tool` handling
in `app/actions.tsx` so the payload is serialized in only one place and passed
through unchanged everywhere else. Use the existing `DbNewMessage`,
`newDrawingMessage`, and `researcher` tool-message path to keep the stored
content as the original JSON string instead of an escaped string.

};
Expand Down