fix: add ::uuid casts to all agent_sessions queries
PostgreSQL can't implicitly coerce text params to UUID columns. Add explicit ::uuid casts on id and project_id in all agent session routes (list, get, patch, stop, approve). Made-with: Cursor
This commit is contained in:
@@ -44,7 +44,7 @@ export async function POST(
|
|||||||
const rows = await query<{ data: Record<string, unknown> }>(
|
const rows = await query<{ data: Record<string, unknown> }>(
|
||||||
`SELECT p.data FROM fs_projects p
|
`SELECT p.data FROM fs_projects p
|
||||||
JOIN fs_users u ON u.id = p.user_id
|
JOIN fs_users u ON u.id = p.user_id
|
||||||
WHERE p.id = $1 AND u.data->>'email' = $2 LIMIT 1`,
|
WHERE p.id = $1::uuid AND u.data->>'email' = $2 LIMIT 1`,
|
||||||
[projectId, session.user.email]
|
[projectId, session.user.email]
|
||||||
);
|
);
|
||||||
if (rows.length === 0) {
|
if (rows.length === 0) {
|
||||||
@@ -59,7 +59,7 @@ export async function POST(
|
|||||||
|
|
||||||
// Find the session to get the appName (so we can find the right Coolify UUID)
|
// Find the session to get the appName (so we can find the right Coolify UUID)
|
||||||
const sessionRows = await query<{ app_name: string; status: string }>(
|
const sessionRows = await query<{ app_name: string; status: string }>(
|
||||||
`SELECT app_name, status FROM agent_sessions WHERE id = $1 AND project_id = $2 LIMIT 1`,
|
`SELECT app_name, status FROM agent_sessions WHERE id = $1::uuid AND project_id = $2::uuid LIMIT 1`,
|
||||||
[sessionId, projectId]
|
[sessionId, projectId]
|
||||||
);
|
);
|
||||||
if (sessionRows.length === 0) {
|
if (sessionRows.length === 0) {
|
||||||
@@ -109,7 +109,7 @@ export async function POST(
|
|||||||
`UPDATE agent_sessions
|
`UPDATE agent_sessions
|
||||||
SET status = 'approved', completed_at = COALESCE(completed_at, now()), updated_at = now(),
|
SET status = 'approved', completed_at = COALESCE(completed_at, now()), updated_at = now(),
|
||||||
output = output || $1::jsonb
|
output = output || $1::jsonb
|
||||||
WHERE id = $2`,
|
WHERE id = $2::uuid`,
|
||||||
[
|
[
|
||||||
JSON.stringify([{
|
JSON.stringify([{
|
||||||
ts: new Date().toISOString(),
|
ts: new Date().toISOString(),
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ export async function GET(
|
|||||||
FROM agent_sessions s
|
FROM agent_sessions s
|
||||||
JOIN fs_projects p ON p.id = s.project_id
|
JOIN fs_projects p ON p.id = s.project_id
|
||||||
JOIN fs_users u ON u.id = p.user_id
|
JOIN fs_users u ON u.id = p.user_id
|
||||||
WHERE s.id = $1 AND s.project_id = $2 AND u.data->>'email' = $3
|
WHERE s.id = $1::uuid AND s.project_id = $2::uuid AND u.data->>'email' = $3
|
||||||
LIMIT 1`,
|
LIMIT 1`,
|
||||||
[sessionId, projectId, session.user.email]
|
[sessionId, projectId, session.user.email]
|
||||||
);
|
);
|
||||||
@@ -110,7 +110,7 @@ export async function PATCH(
|
|||||||
|
|
||||||
values.push(sessionId);
|
values.push(sessionId);
|
||||||
await query(
|
await query(
|
||||||
`UPDATE agent_sessions SET ${updates.join(", ")} WHERE id = $${idx}`,
|
`UPDATE agent_sessions SET ${updates.join(", ")} WHERE id = $${idx}::uuid`,
|
||||||
values
|
values
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ export async function POST(
|
|||||||
`SELECT s.status FROM agent_sessions s
|
`SELECT s.status FROM agent_sessions s
|
||||||
JOIN fs_projects p ON p.id = s.project_id
|
JOIN fs_projects p ON p.id = s.project_id
|
||||||
JOIN fs_users u ON u.id = p.user_id
|
JOIN fs_users u ON u.id = p.user_id
|
||||||
WHERE s.id = $1 AND s.project_id = $2 AND u.data->>'email' = $3 LIMIT 1`,
|
WHERE s.id = $1::uuid AND s.project_id = $2::uuid AND u.data->>'email' = $3 LIMIT 1`,
|
||||||
[sessionId, projectId, session.user.email]
|
[sessionId, projectId, session.user.email]
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ export async function POST(
|
|||||||
`UPDATE agent_sessions
|
`UPDATE agent_sessions
|
||||||
SET status = 'stopped', completed_at = now(), updated_at = now(),
|
SET status = 'stopped', completed_at = now(), updated_at = now(),
|
||||||
output = output || '[{"ts": "now", "type": "info", "text": "Stopped by user."}]'::jsonb
|
output = output || '[{"ts": "now", "type": "info", "text": "Stopped by user."}]'::jsonb
|
||||||
WHERE id = $1`,
|
WHERE id = $1::uuid`,
|
||||||
[sessionId]
|
[sessionId]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ export async function POST(
|
|||||||
const owns = await query<{ id: string; data: Record<string, unknown> }>(
|
const owns = await query<{ id: string; data: Record<string, unknown> }>(
|
||||||
`SELECT p.id, p.data FROM fs_projects p
|
`SELECT p.id, p.data FROM fs_projects p
|
||||||
JOIN fs_users u ON u.id = p.user_id
|
JOIN fs_users u ON u.id = p.user_id
|
||||||
WHERE p.id = $1 AND u.data->>'email' = $2 LIMIT 1`,
|
WHERE p.id = $1::uuid AND u.data->>'email' = $2 LIMIT 1`,
|
||||||
[projectId, session.user.email]
|
[projectId, session.user.email]
|
||||||
);
|
);
|
||||||
if (owns.length === 0) {
|
if (owns.length === 0) {
|
||||||
@@ -81,7 +81,7 @@ export async function POST(
|
|||||||
// Create the session row
|
// Create the session row
|
||||||
const rows = await query<{ id: string }>(
|
const rows = await query<{ id: string }>(
|
||||||
`INSERT INTO agent_sessions (project_id, app_name, app_path, task, status, started_at)
|
`INSERT INTO agent_sessions (project_id, app_name, app_path, task, status, started_at)
|
||||||
VALUES ($1, $2, $3, $4, 'running', now())
|
VALUES ($1::uuid, $2, $3, $4, 'running', now())
|
||||||
RETURNING id`,
|
RETURNING id`,
|
||||||
[projectId, appName, appPath, task.trim()]
|
[projectId, appName, appPath, task.trim()]
|
||||||
);
|
);
|
||||||
@@ -114,7 +114,7 @@ export async function POST(
|
|||||||
'type', 'error',
|
'type', 'error',
|
||||||
'text', 'Agent runner service is not connected yet. Phase 2 implementation pending.'
|
'text', 'Agent runner service is not connected yet. Phase 2 implementation pending.'
|
||||||
))
|
))
|
||||||
WHERE id = $1`,
|
WHERE id = $1::uuid`,
|
||||||
[sessionId]
|
[sessionId]
|
||||||
).catch(() => {});
|
).catch(() => {});
|
||||||
});
|
});
|
||||||
@@ -159,7 +159,7 @@ export async function GET(
|
|||||||
FROM agent_sessions s
|
FROM agent_sessions s
|
||||||
JOIN fs_projects p ON p.id = s.project_id
|
JOIN fs_projects p ON p.id = s.project_id
|
||||||
JOIN fs_users u ON u.id = p.user_id
|
JOIN fs_users u ON u.id = p.user_id
|
||||||
WHERE s.project_id = $1 AND u.data->>'email' = $2
|
WHERE s.project_id = $1::uuid AND u.data->>'email' = $2
|
||||||
ORDER BY s.created_at DESC
|
ORDER BY s.created_at DESC
|
||||||
LIMIT 50`,
|
LIMIT 50`,
|
||||||
[projectId, session.user.email]
|
[projectId, session.user.email]
|
||||||
|
|||||||
Reference in New Issue
Block a user