Skip to content

feat(chat): migrate agent templates calls to dedicated api#1745

Closed
arpitgupta1214 wants to merge 1 commit into
testfrom
feat/migrate-agent-templates
Closed

feat(chat): migrate agent templates calls to dedicated api#1745
arpitgupta1214 wants to merge 1 commit into
testfrom
feat/migrate-agent-templates

Conversation

@arpitgupta1214
Copy link
Copy Markdown
Collaborator

@arpitgupta1214 arpitgupta1214 commented May 9, 2026

Cuts over the 6 agent-templates / agent-creator callers to the dedicated api endpoints (recoupable/api#543) with Bearer auth and snake_case bodies. The list response now embeds creator info per row, so AgentCreator no longer fires a per-card lookup. Deletes the orphaned local routes and supabase helpers.

Test plan

  • Sign in to the chat preview, open the Agents tab, verify the list loads and creator badges render from the embedded creator block (not from a /api/agent-creator fetch)
  • Create a private template with shared emails, edit it, favorite + unfavorite, then delete — all against the api preview from recoupable/api#543
  • Verify a non-creator gets a server-side 403 on edit / delete

🤖 Generated with Claude Code


Summary by cubic

Migrate Agents templates to the dedicated API with Bearer auth and snake_case bodies, removing local routes and Supabase helpers. The list now embeds a creator object per template, eliminating extra per-card fetches and speeding up the Agents tab.

  • New Features

    • All CRUD and favorite actions use dedicated endpoints with Bearer auth from @privy-io/react-auth
    • List response embeds creator; AgentCreator renders from agent.creator
    • Request/response bodies use snake_case (e.g., is_private, share_emails)
  • Refactors

    • Removed local routes (app/api/agent-templates/*, app/api/agent-creator) and unused Supabase helpers
    • Switched to fetchAgentTemplates(accessToken) and getClientApiBaseUrl
    • Replaced creatorId props with creator objects across components
    • Query loading gated on Privy authentication

Written for commit 01d05c0. Summary will update on new commits.

Cuts over the 6 agent-templates / agent-creator callers to the new
dedicated api endpoints with Bearer auth and snake_case bodies. The
GET list now embeds the creator block per row, so AgentCreator no
longer fires a per-card fetch.

Deletes the orphaned local routes (app/api/agent-templates/,
app/api/agent-creator/) and their backing supabase helpers
(lib/supabase/agent_templates/), plus admin.ts/getAccountById.ts/
getAccountDetailsByEmails.ts where no other callers remain.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
chat Ready Ready Preview May 9, 2026 5:41pm

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 9, 2026

Warning

Rate limit exceeded

@arpitgupta1214 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 9 minutes and 25 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 424159d5-4cae-4609-885a-73254640f61f

📥 Commits

Reviewing files that changed from the base of the PR and between 9e94db1 and 01d05c0.

⛔ Files ignored due to path filters (1)
  • types/AgentTemplates.ts is excluded by none and included by none
📒 Files selected for processing (42)
  • app/api/agent-creator/route.ts
  • app/api/agent-templates/favorites/route.ts
  • app/api/agent-templates/route.ts
  • components/Agents/AgentCard.tsx
  • components/Agents/AgentCreator.tsx
  • components/Agents/AgentDeleteButton.tsx
  • components/Agents/AgentEditDialog.tsx
  • components/Agents/AgentHeart.tsx
  • components/Agents/AgentPreviewDialog.tsx
  • components/Agents/AgentTags.tsx
  • components/Agents/Agents.tsx
  • components/Agents/AgentsSkeleton.tsx
  • components/Agents/CreateAgentDialog.tsx
  • components/Agents/CreateAgentForm.tsx
  • components/Agents/EmailShareInput.tsx
  • components/Agents/ExistingSharedEmailsList.tsx
  • components/Agents/PrivacySection.tsx
  • components/Agents/SubmitButton.tsx
  • components/Agents/TagSelector.tsx
  • components/Agents/useAgentCard.ts
  • components/Agents/useAgentData.ts
  • components/Agents/useAgentToggleFavorite.ts
  • lib/admin.ts
  • lib/agent-templates/fetchAgentTemplates.ts
  • lib/supabase/account_emails/getAccountDetailsByEmails.ts
  • lib/supabase/agent_templates/addAgentTemplateFavorite.ts
  • lib/supabase/agent_templates/createAgentTemplate.ts
  • lib/supabase/agent_templates/createAgentTemplateShares.ts
  • lib/supabase/agent_templates/deleteAgentTemplate.ts
  • lib/supabase/agent_templates/deleteAgentTemplateShares.ts
  • lib/supabase/agent_templates/getAgentTemplateSharesByTemplateIds.ts
  • lib/supabase/agent_templates/getAgentTemplates.ts
  • lib/supabase/agent_templates/getSharedEmailsForTemplates.ts
  • lib/supabase/agent_templates/getSharedTemplatesForUser.ts
  • lib/supabase/agent_templates/getUserAccessibleTemplates.ts
  • lib/supabase/agent_templates/getUserTemplateFavorites.ts
  • lib/supabase/agent_templates/insertAgentTemplateShares.ts
  • lib/supabase/agent_templates/listAgentTemplatesForUser.ts
  • lib/supabase/agent_templates/removeAgentTemplateFavorite.ts
  • lib/supabase/agent_templates/updateAgentTemplate.ts
  • lib/supabase/agent_templates/updateAgentTemplateShares.ts
  • lib/supabase/agent_templates/verifyAgentTemplateOwner.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/migrate-agent-templates

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 43 files

Confidence score: 4/5

  • This PR is likely safe to merge with minimal risk, since the reported issue is moderate (5/10) and limited to one error-handling path.
  • In components/Agents/AgentEditDialog.tsx, calling res.json() before checking response status can throw on non-JSON error bodies, which may mask the original API failure and surface a less helpful error to users.
  • Pay close attention to components/Agents/AgentEditDialog.tsx - ensure status/error handling happens before JSON parsing so API failures are reported reliably.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="components/Agents/AgentEditDialog.tsx">

<violation number="1" location="components/Agents/AgentEditDialog.tsx:67">
P2: `res.json()` is called unconditionally before error-status handling, which can throw on non-JSON responses and mask the real API failure.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment on lines +67 to +69
const data = await res.json();
if (!res.ok || data.status === "error") {
throw new Error(data.error || "Failed to update template");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: res.json() is called unconditionally before error-status handling, which can throw on non-JSON responses and mask the real API failure.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At components/Agents/AgentEditDialog.tsx, line 67:

<comment>`res.json()` is called unconditionally before error-status handling, which can throw on non-JSON responses and mask the real API failure.</comment>

<file context>
@@ -35,26 +38,37 @@ const AgentEditDialog: React.FC<AgentEditDialogProps> = ({ agent }) => {
+          }),
+        },
+      );
+      const data = await res.json();
+      if (!res.ok || data.status === "error") {
+        throw new Error(data.error || "Failed to update template");
</file context>
Suggested change
const data = await res.json();
if (!res.ok || data.status === "error") {
throw new Error(data.error || "Failed to update template");
const data = await res.json().catch(() => null);
if (!res.ok || data?.status === "error") {
throw new Error(data?.error || "Failed to update template");
}

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 01d05c0500

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines 34 to 36
if (!res.ok) {
throw new Error("Failed to toggle favorite");
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Validate favorite response payload before treating as success

The new favorite toggle call only checks res.ok, but this migration’s API contract uses a { status: "success" | "error" } payload (see ToggleFavoriteResponse and the other migrated agent-template calls that check data.status === "error"). If /favorite returns HTTP 200 with status: "error" (a pattern already handled elsewhere in this repo), this path will incorrectly show a success toast and refresh the list as if the mutation succeeded.

Useful? React with 👍 / 👎.

@arpitgupta1214
Copy link
Copy Markdown
Collaborator Author

Closing — chat repo deprecated; cutover no longer needed. api#543 and docs#199 remain valid for the new surface.

@arpitgupta1214 arpitgupta1214 deleted the feat/migrate-agent-templates branch May 11, 2026 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant