Skip to content
Closed
39 changes: 33 additions & 6 deletions app/api/agent-creator/route.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,45 @@
import getAccountById from "@/lib/supabase/accounts/getAccountById";
import { ADMIN_EMAILS } from "@/lib/admin";
import { NextRequest } from "next/server";
import { NextRequest, NextResponse } from "next/server";
import { NEW_API_BASE_URL } from "@/lib/consts";

export const runtime = "edge";

const SUNSET_DAYS = 90;

function getDeprecationHeaders(): Record<string, string> {
const sunsetDate = new Date();
sunsetDate.setDate(sunsetDate.getDate() + SUNSET_DAYS);

return {
Deprecation: "true",
Sunset: sunsetDate.toUTCString(),
Link: `<${NEW_API_BASE_URL}/api/agent-creator>; rel="deprecation"`,
};
Comment on lines +8 to +18
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Sunset date should be fixed, not recomputed per request.
As written, every request pushes the Sunset date out by 90 days, so the window never truly closes and clients get inconsistent timelines. Use a fixed date (env or constant) computed once.

💡 Proposed fix (example)
-const SUNSET_DAYS = 90;
+const SUNSET_DAYS = 90;
+const DEPRECATION_DATE = new Date("2026-01-16T00:00:00Z"); // set to actual deprecation start
+const SUNSET_DATE = new Date(DEPRECATION_DATE);
+SUNSET_DATE.setDate(SUNSET_DATE.getDate() + SUNSET_DAYS);

 function getDeprecationHeaders(): Record<string, string> {
-  const sunsetDate = new Date();
-  sunsetDate.setDate(sunsetDate.getDate() + SUNSET_DAYS);
-
   return {
-    Deprecation: "true",
-    Sunset: sunsetDate.toUTCString(),
+    Deprecation: DEPRECATION_DATE.toUTCString(),
+    Sunset: SUNSET_DATE.toUTCString(),
     Link: `<${NEW_API_BASE_URL}/api/agent-creator>; rel="deprecation"`,
   };
 }
🤖 Prompt for AI Agents
In `@app/api/agent-creator/route.ts` around lines 8 - 18, The current
getDeprecationHeaders function recomputes sunsetDate per request (using
SUNSET_DAYS), so the window never closes; change to compute a single fixed
sunset timestamp at module initialization or read a fixed date from an env var
and use that value in getDeprecationHeaders. Initialize a module‑level constant
(e.g., FIXED_SUNSET_DATE or SUNSET_TIMESTAMP) once using NEW_API_BASE_URL and
SUNSET_DAYS or process.env.DEPRECATION_SUNSET, then have getDeprecationHeaders
return Deprecation, Sunset: FIXED_SUNSET_DATE.toUTCString(), and Link using
NEW_API_BASE_URL. Ensure the fixed value is computed only once, not per call.

}

/**
* @deprecated This endpoint is deprecated. Use recoup-api directly at recoup-api.vercel.app/api/agent-creator
*/
export async function GET(req: NextRequest) {
const deprecationHeaders = getDeprecationHeaders();
const creatorId = req.nextUrl.searchParams.get("creatorId");

if (!creatorId) {
return Response.json({ message: "Missing creatorId" }, { status: 400 });
return NextResponse.json(
{ message: "Missing creatorId" },
{ status: 400, headers: deprecationHeaders },
);
}

try {
const account = await getAccountById(creatorId);

if (!account) {
return Response.json({ message: "Creator not found" }, { status: 404 });
return NextResponse.json(
{ message: "Creator not found" },
{ status: 404, headers: deprecationHeaders },
);
}

const info = Array.isArray(account.account_info)
Expand All @@ -26,19 +50,22 @@ export async function GET(req: NextRequest) {
: null;
const isAdmin = !!email && ADMIN_EMAILS.includes(email);

return Response.json(
return NextResponse.json(
{
creator: {
name: account.name || null,
image: info?.image || null,
is_admin: isAdmin,
},
},
{ status: 200 },
{ status: 200, headers: deprecationHeaders },
);
} catch (e) {
const message = e instanceof Error ? e.message : "failed";
return Response.json({ message }, { status: 400 });
return NextResponse.json(
{ message },
{ status: 400, headers: deprecationHeaders },
);
}
}

Expand Down
34 changes: 31 additions & 3 deletions app/api/agent-templates/favorites/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,37 @@ import { NextResponse } from "next/server";
import { addAgentTemplateFavorite } from "@/lib/supabase/agent_templates/addAgentTemplateFavorite";
import { removeAgentTemplateFavorite } from "@/lib/supabase/agent_templates/removeAgentTemplateFavorite";
import type { ToggleFavoriteRequest, ToggleFavoriteResponse } from "@/types/AgentTemplates";
import { NEW_API_BASE_URL } from "@/lib/consts";

export const runtime = "edge";

const SUNSET_DAYS = 90;

function getDeprecationHeaders(): Record<string, string> {
const sunsetDate = new Date();
sunsetDate.setDate(sunsetDate.getDate() + SUNSET_DAYS);

return {
Deprecation: "true",
Sunset: sunsetDate.toUTCString(),
Link: `<${NEW_API_BASE_URL}/api/agent-templates/favorites>; rel="deprecation"`,
};
}

/**
* @deprecated This endpoint is deprecated. Use recoup-api directly at recoup-api.vercel.app/api/agent-templates/favorites
*/
export async function POST(request: Request) {
const deprecationHeaders = getDeprecationHeaders();

try {
const { templateId, userId, isFavourite }: ToggleFavoriteRequest = await request.json();

if (!templateId || !userId) {
return NextResponse.json({ error: "Missing templateId or userId" }, { status: 400 });
return NextResponse.json(
{ error: "Missing templateId or userId" },
{ status: 400, headers: deprecationHeaders }
);
}

if (isFavourite) {
Expand All @@ -19,10 +41,16 @@ export async function POST(request: Request) {
await removeAgentTemplateFavorite(templateId, userId);
}

return NextResponse.json({ success: true } as ToggleFavoriteResponse);
return NextResponse.json(
{ success: true } as ToggleFavoriteResponse,
{ headers: deprecationHeaders }
);
} catch (error) {
console.error("Error toggling favourite:", error);
return NextResponse.json({ error: "Failed to toggle favourite" } as ToggleFavoriteResponse, { status: 500 });
return NextResponse.json(
{ error: "Failed to toggle favourite" } as ToggleFavoriteResponse,
{ status: 500, headers: deprecationHeaders }
);
}
}

Expand Down
23 changes: 21 additions & 2 deletions app/api/agent-templates/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,29 @@ import { updateAgentTemplate } from "@/lib/supabase/agent_templates/updateAgentT
import { deleteAgentTemplate } from "@/lib/supabase/agent_templates/deleteAgentTemplate";
import { verifyAgentTemplateOwner } from "@/lib/supabase/agent_templates/verifyAgentTemplateOwner";
import { getSharedEmailsForTemplates } from "@/lib/supabase/agent_templates/getSharedEmailsForTemplates";
import { NEW_API_BASE_URL } from "@/lib/consts";

export const runtime = "edge";

const SUNSET_DAYS = 90;

function getDeprecationHeaders(): Record<string, string> {
const sunsetDate = new Date();
sunsetDate.setDate(sunsetDate.getDate() + SUNSET_DAYS);

return {
Deprecation: "true",
Sunset: sunsetDate.toUTCString(),
Link: `<${NEW_API_BASE_URL}/api/agent-templates>; rel="deprecation"`,
};
Comment on lines +13 to +23
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Sunset date is recalculated per request (rolling window).

Sunset is derived from new Date() on every request, so the header always stays ~90 days ahead and never reaches a fixed deprecation deadline. If the intent is a real 90‑day window, freeze the sunset date (constant or config) and reuse it for every response.

🧭 Suggested fix (use a fixed sunset date)
-const SUNSET_DAYS = 90;
+const SUNSET_DATE = new Date("2026-04-16T00:00:00Z"); // set to planned sunset date

 function getDeprecationHeaders(): Record<string, string> {
-  const sunsetDate = new Date();
-  sunsetDate.setDate(sunsetDate.getDate() + SUNSET_DAYS);
-
   return {
     Deprecation: "true",
-    Sunset: sunsetDate.toUTCString(),
+    Sunset: SUNSET_DATE.toUTCString(),
     Link: `<${NEW_API_BASE_URL}/api/agent-templates>; rel="deprecation"`,
   };
 }
🤖 Prompt for AI Agents
In `@app/api/agent-templates/route.ts` around lines 13 - 23, The Sunset header is
being recalculated on every request inside getDeprecationHeaders using new
Date(), producing a rolling 90-day window; instead compute a single fixed sunset
date once (at module initialization or from configuration/env) and reuse it for
every response. Replace the per-request calculation in getDeprecationHeaders
with a constant (e.g., SUNSET_DATE or DEPRECATION_SUNSET) derived from
SUNSET_DAYS at module load or read a fixed date from config, and return
sunsetDate.toUTCString() from that constant while keeping Deprecation and Link
as-is (referencing getDeprecationHeaders, SUNSET_DAYS, and NEW_API_BASE_URL).

}

/**
* @deprecated This endpoint is deprecated. Use recoup-api directly at recoup-api.vercel.app/api/agent-templates
*/
export async function GET(request: Request) {
const deprecationHeaders = getDeprecationHeaders();

try {
const { searchParams } = new URL(request.url);
const userId = searchParams.get("userId");
Expand All @@ -32,10 +51,10 @@ export async function GET(request: Request) {
shared_emails: template.is_private ? (sharedEmails[template.id] || []) : []
}));

return NextResponse.json(templatesWithEmails);
return NextResponse.json(templatesWithEmails, { headers: deprecationHeaders });
} catch (error) {
console.error('Error fetching agent templates:', error);
return NextResponse.json({ error: 'Failed to fetch templates' }, { status: 500 });
return NextResponse.json({ error: 'Failed to fetch templates' }, { status: 500, headers: deprecationHeaders });
}
}

Expand Down
25 changes: 22 additions & 3 deletions app/api/agents/route.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,44 @@
import { NextRequest, NextResponse } from "next/server";
import { getArtistAgents } from "@/lib/supabase/getArtistAgents";
import { NEW_API_BASE_URL } from "@/lib/consts";

const SUNSET_DAYS = 90;

function getDeprecationHeaders(): Record<string, string> {
const sunsetDate = new Date();
sunsetDate.setDate(sunsetDate.getDate() + SUNSET_DAYS);

return {
Deprecation: "true",
Sunset: sunsetDate.toUTCString(),
Link: `<${NEW_API_BASE_URL}/api/artist-agents>; rel="deprecation"`,
};
}

/**
* @deprecated This endpoint is deprecated. Use recoup-api directly at recoup-api.vercel.app/api/artist-agents
*/
export async function GET(request: NextRequest) {
const deprecationHeaders = getDeprecationHeaders();

const { searchParams } = new URL(request.url);
const socialIds = searchParams.getAll("socialId");

if (!socialIds.length) {
return NextResponse.json(
{ error: "At least one Social ID is required" },
{ status: 400 },
{ status: 400, headers: deprecationHeaders },
);
}

try {
const agents = await getArtistAgents(socialIds);
return NextResponse.json(agents);
return NextResponse.json(agents, { headers: deprecationHeaders });
} catch (error) {
console.error("Error fetching segments:", error);
return NextResponse.json(
{ error: "Failed to fetch segments" },
{ status: 500 },
{ status: 500, headers: deprecationHeaders },
Comment on lines +5 to +41
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Sunset date is recalculated per request (rolling window).

Same issue here: computing new Date() inside the helper keeps the Sunset header perpetually 90 days out. Use a fixed sunset date (constant or config) that reflects the planned removal date.

🤖 Prompt for AI Agents
In `@app/api/agents/route.ts` around lines 5 - 41, The helper
getDeprecationHeaders currently computes a rolling sunset date using SUNSET_DAYS
and new Date() which makes the Sunset header always 90 days in the future;
instead define a fixed sunset constant (e.g., DEPRECATION_SUNSET or
FIXED_SUNSET_ISO) representing the planned removal date and use that constant in
getDeprecationHeaders (replace the dynamic sunsetDate logic), keeping the other
headers (Deprecation, Link with NEW_API_BASE_URL) intact so the Sunset header is
stable across requests.

);
}
}
Expand Down
23 changes: 20 additions & 3 deletions app/api/ai/models/route.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
import { getAvailableModels } from "@/lib/ai/getAvailableModels";
import { NEW_API_BASE_URL } from "@/lib/consts";

const SUNSET_DAYS = 90;

function getDeprecationHeaders(): Record<string, string> {
const sunsetDate = new Date();
sunsetDate.setDate(sunsetDate.getDate() + SUNSET_DAYS);

return {
Deprecation: "true",
Sunset: sunsetDate.toUTCString(),
Link: `<${NEW_API_BASE_URL}/api/ai/models>; rel="deprecation"`,
};
}
Comment on lines +4 to +15
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Sunset date is sliding here too—should be fixed.
Recomputing the Sunset date on every request keeps pushing the deadline forward, which defeats the 90‑day sunset intent.

💡 Proposed fix (example)
-const SUNSET_DAYS = 90;
+const SUNSET_DAYS = 90;
+const DEPRECATION_DATE = new Date("2026-01-16T00:00:00Z"); // set to actual deprecation start
+const SUNSET_DATE = new Date(DEPRECATION_DATE);
+SUNSET_DATE.setDate(SUNSET_DATE.getDate() + SUNSET_DAYS);

 function getDeprecationHeaders(): Record<string, string> {
-  const sunsetDate = new Date();
-  sunsetDate.setDate(sunsetDate.getDate() + SUNSET_DAYS);
-
   return {
-    Deprecation: "true",
-    Sunset: sunsetDate.toUTCString(),
+    Deprecation: DEPRECATION_DATE.toUTCString(),
+    Sunset: SUNSET_DATE.toUTCString(),
     Link: `<${NEW_API_BASE_URL}/api/ai/models>; rel="deprecation"`,
   };
 }
🤖 Prompt for AI Agents
In `@app/api/ai/models/route.ts` around lines 4 - 15, The Sunset date is being
recomputed on every call to getDeprecationHeaders(), causing the deadline to
slide; instead compute the sunset once at module load and reuse it. Create a
module-level constant (e.g., SUNSET_DATE or PRECOMPUTED_SUNSET) by instantiating
new Date() and adding SUNSET_DAYS once, convert it to UTC string once (e.g.,
SUNSET_DATE_UTC) and have getDeprecationHeaders() return headers using that
constant (keeping Deprecation, Sunset, and Link with NEW_API_BASE_URL) so the
90‑day window remains fixed.


/**
* GET /api/ai/models
*
* @deprecated This endpoint is deprecated. Use recoup-api directly at recoup-api.vercel.app/api/ai/models
*
* Server-side endpoint that proxies `getAvailableModels()` so that the
* client can fetch model metadata without requiring server-side imports
* of `@ai-sdk/gateway`.
*/
export async function GET() {
const deprecationHeaders = getDeprecationHeaders();

try {
const models = await getAvailableModels();
return Response.json({ models });
return Response.json({ models }, { headers: deprecationHeaders });
} catch (error) {
console.error("/api/ai/models error", error);
const message = error instanceof Error ? error.message : "failed";
return Response.json({ message }, { status: 500 });
return Response.json({ message }, { status: 500, headers: deprecationHeaders });
}
}

Expand Down
74 changes: 0 additions & 74 deletions app/api/browser/act/route.ts

This file was deleted.

Loading
Loading