Open sourcing#33
Conversation
|
Caution Review failedThe pull request is closed. """ WalkthroughThis change introduces stricter environment variable checks at startup, refactors agent initialization and tool execution logic, deletes custom tool and SmartLead helper modules, and applies formatting corrections to prompt text. The code now enforces configuration requirements, centralizes error handling and logging, and removes previously defined custom tools and API helpers. Changes
Sequence Diagram(s)sequenceDiagram
participant Startup
participant EnvVars
participant Logger
participant Process
Startup->>EnvVars: Check required variables (AGENTUITY_PROJECT_KEY, ATTIO_AUTH_TOKEN, etc.)
alt Variable missing
EnvVars->>Logger: Log error (red)
EnvVars->>Process: Exit with failure code
else All present
EnvVars->>Startup: Continue startup
end
sequenceDiagram
participant Request
participant Agent
participant Anthropic
participant Composio
participant Logger
Request->>Agent: Incoming request
Agent->>Anthropic: Generate message (main model)
Agent->>Composio: Execute tool calls (using env user ID)
Agent->>Logger: Log events/errors
Agent->>Request: Return response
Estimated code review effort🎯 4 (Complex) | ⏱️ ~35 minutes Possibly related PRs
Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
index.ts (1)
27-98: Consider making some environment variables optional based on feature usage.All environment variables are enforced as mandatory at startup. This approach requires all services to be configured even if some features might not be used. Consider implementing conditional checks based on enabled features or documenting which variables are truly required vs optional.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
index.ts(2 hunks)lib/agent.ts(9 hunks)src/agents/clerk-agent/tools.ts(0 hunks)src/agents/smartlead-agent/index.ts(2 hunks)src/agents/smartlead-agent/smartlead-helpers.ts(0 hunks)
💤 Files with no reviewable changes (2)
- src/agents/smartlead-agent/smartlead-helpers.ts
- src/agents/clerk-agent/tools.ts
🧰 Additional context used
📓 Path-based instructions (2)
**/src/agents/**/index.ts
📄 CodeRabbit Inference Engine (.cursor/rules/agent.mdc)
**/src/agents/**/index.ts: Prefer loading types from the node modules package@agentuity/sdkin the node_modules folder
The file should export a default function
Prefer naming the default function Agent or the name of the Agent based on the context of the Agent description
All code should be in Typescript format
Use the provided logger from theAgentContextinterface such asctx.logger.info("my message: %s", "hello")
Files:
src/agents/smartlead-agent/index.ts
src/agents/**/*.ts
📄 CodeRabbit Inference Engine (.cursor/rules/sdk.mdc)
src/agents/**/*.ts: Use TypeScript for better type safety and IDE support
Import types from@agentuity/sdk
Use structured error handling with try/catch blocks
Leverage the provided logger for consistent logging
Use the storage APIs for persisting data
Files:
src/agents/smartlead-agent/index.ts
🧠 Learnings (4)
📓 Common learnings
Learnt from: mcongrove
PR: agentuity/app#544
File: web/src/components/screens/deploy/ProjectSetupScreen.tsx:232-242
Timestamp: 2025-06-09T22:56:13.989Z
Learning: Environment variable secret detection logic should be centralized in utility functions rather than duplicated across components for better maintainability and consistency.
Learnt from: CR
PR: agentuity/examples#0
File: agents/Startup_News_Scraper/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-07-17T13:38:58.657Z
Learning: Applies to agents/Startup_News_Scraper/**/src/agents/**/index.ts : Prefer naming the default function Agent or the name of the Agent based on the context of the Agent description
Learnt from: CR
PR: agentuity/examples#0
File: agents/tavily_agent/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-07-17T13:40:30.298Z
Learning: Applies to agents/tavily_agent/agents/**/*.py : Use the AgentContext class and its properties (logger, kv, vector, get_agent, tracer, sdkVersion, devmode, orgId, projectId) to access agent context and capabilities
Learnt from: CR
PR: agentuity/examples#0
File: frameworks/pydantic/basic/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-06-23T17:16:30.899Z
Learning: When writing agent code in 'agents/**/*.py', prefer importing types such as AgentRequest, AgentResponse, and AgentContext from the 'agentuity' package to ensure compatibility and consistency.
index.ts (19)
Learnt from: CR
PR: agentuity/examples#0
File: agents/Startup_News_Scraper/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-07-17T13:38:58.657Z
Learning: Applies to agents/Startup_News_Scraper//src/agents//index.ts : All code should be in Typescript format
Learnt from: CR
PR: agentuity/examples#0
File: frameworks/mastra/basic/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-06-23T17:15:21.314Z
Learning: For best practices in Agentuity SDK projects, use TypeScript for type safety, import types from @agentuity/sdk, use structured error handling with try/catch, leverage the provided logger, use storage APIs for data persistence, and consider agent communication for complex workflows.
Learnt from: CR
PR: agentuity/examples#0
File: agentuity/sdk-js/streaming/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-07-17T13:40:37.445Z
Learning: Applies to agentuity/sdk-js/streaming//src/agents//index.ts : All code should be in Typescript format
Learnt from: CR
PR: agentuity/examples#0
File: frameworks/mastra/basic/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-06-23T17:15:12.561Z
Learning: In Agentuity AI Agent files (**/src/agents/**/index.ts), import types such as AgentRequest, AgentResponse, and AgentContext from the @agentuity/sdk package to ensure type safety and consistency.
Learnt from: CR
PR: agentuity/examples#0
File: frameworks/langgraph/basic/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-06-23T17:14:39.393Z
Learning: In Agentuity AI Agent files (**/src/agents/**/index.ts), import types such as AgentRequest, AgentResponse, and AgentContext from the @agentuity/sdk package to ensure type safety and consistency.
Learnt from: CR
PR: agentuity/examples#0
File: agents/Startup_News_Scraper/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-07-17T13:39:11.850Z
Learning: Applies to agents/Startup_News_Scraper/src/agents/**/*.ts : Import types from @agentuity/sdk
Learnt from: CR
PR: agentuity/examples#0
File: frameworks/mastra/basic/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-06-23T17:15:12.561Z
Learning: In Agentuity AI Agent files (**/src/agents/**/index.ts), always use the provided logger from the AgentContext interface (e.g., ctx.logger.info(...)) for logging, rather than custom or external logging solutions.
Learnt from: CR
PR: agentuity/examples#0
File: frameworks/langgraph/basic/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-06-23T17:14:39.393Z
Learning: In Agentuity AI Agent files (**/src/agents/**/index.ts), always use the provided logger from the AgentContext interface (e.g., ctx.logger.info(...)) for logging, rather than custom or external logging solutions.
Learnt from: CR
PR: agentuity/examples#0
File: agents/composio/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-07-17T13:39:37.133Z
Learning: Applies to agents/composio//src/agents//index.ts : All code should be in Typescript format
Learnt from: CR
PR: agentuity/examples#0
File: agents/Startup_News_Scraper/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-07-17T13:38:58.657Z
Learning: Applies to agents/Startup_News_Scraper//src/agents//index.ts : Prefer loading types from the node modules package @agentuity/sdk in the node_modules folder
Learnt from: CR
PR: agentuity/collider#0
File: projects/collider-node/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-06-24T15:42:21.297Z
Learning: Agent files for Agentuity should export a default async function, typically named Agent or contextually named after the Agent, which receives AgentRequest, AgentResponse, and AgentContext as parameters.
Learnt from: CR
PR: agentuity/examples#0
File: frameworks/vercel/basic/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-06-23T17:16:49.315Z
Learning: When writing an Agent in TypeScript for Agentuity, always use the types provided by the @agentuity/sdk package for AgentRequest, AgentResponse, and AgentContext to ensure type safety and compatibility.
Learnt from: CR
PR: agentuity/examples#0
File: frameworks/openai/from-oai-typescript/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-06-23T17:15:59.829Z
Learning: In Agent files for Agentuity, always export a default function, preferably named 'Agent' or contextually after the Agent, to ensure consistency and clarity.
Learnt from: CR
PR: agentuity/examples#0
File: frameworks/vercel/basic/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-06-23T17:16:58.079Z
Learning: Import types from @agentuity/sdk to ensure consistency and leverage type definitions.
Learnt from: CR
PR: agentuity/examples#0
File: frameworks/openai/from-oai/.cursor/rules/agentuity.mdc:0-0
Timestamp: 2025-06-23T17:16:16.519Z
Learning: The Agentuity configuration file (agentuity.yaml) is reserved for configuring the AI Agent project and should not be edited or suggested for edits during code review.
Learnt from: CR
PR: agentuity/examples#0
File: agentuity/sdk-js/streaming/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-07-17T13:40:37.445Z
Learning: Applies to agentuity/sdk-js/streaming//src/agents//index.ts : Prefer naming the default function Agent or the name of the Agent based on the context of the Agent description
Learnt from: jhaynie
PR: agentuity/cli#313
File: cmd/cloud.go:852-853
Timestamp: 2025-05-22T18:27:10.386Z
Learning: In the agentuity CLI codebase, there's a specific error handling pattern: errsystem is used exclusively for unexpected system errors, while expected error conditions use tui.ShowWarning() and direct os.Exit(1) calls.
Learnt from: CR
PR: agentuity/collider#0
File: projects/collider-node/.cursor/rules/agentuity.mdc:0-0
Timestamp: 2025-06-24T15:42:23.807Z
Learning: The file 'agentuity.yaml' is used to configure the Agentuity AI Agent project and should not be edited or suggested for edits.
Learnt from: CR
PR: agentuity/examples#0
File: frameworks/langchain/basic/.cursor/rules/agentuity.mdc:0-0
Timestamp: 2025-06-23T17:14:18.092Z
Learning: The file 'agentuity.yaml' is used to configure the Agentuity AI Agent project and should not be edited or suggested for edits.
src/agents/smartlead-agent/index.ts (10)
Learnt from: CR
PR: agentuity/docs#0
File: agent-docs/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-07-23T12:40:34.834Z
Learning: Applies to agent-docs/src/agents/**/*.ts : Consider agent communication for complex workflows
Learnt from: CR
PR: agentuity/examples#0
File: agents/deep-research-js/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-07-17T13:40:05.817Z
Learning: Applies to agents/deep-research-js/src/agents/**/*.ts : Consider agent communication for complex workflows
Learnt from: CR
PR: agentuity/examples#0
File: agentuity/sdk-js/streaming/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-07-17T13:40:37.445Z
Learning: Applies to agentuity/sdk-js/streaming//src/agents//index.ts : All code should be in Typescript format
Learnt from: CR
PR: agentuity/examples#0
File: agents/agent-riza/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-07-17T13:39:31.143Z
Learning: Applies to agents/agent-riza/src/agents/**/*.ts : Consider agent communication (e.g., response.handoff, context.getAgent) for complex workflows
Learnt from: CR
PR: agentuity/docs#0
File: agent-docs/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-07-23T12:40:22.412Z
Learning: Applies to agent-docs//src/agents//index.ts : All code should be in Typescript format
Learnt from: CR
PR: agentuity/examples#0
File: agents/deep-research-js/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-07-17T13:39:55.775Z
Learning: Applies to agents/deep-research-js//src/agents//index.ts : All code should be in Typescript format
Learnt from: CR
PR: agentuity/examples#0
File: agents/composio/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-07-17T13:39:37.133Z
Learning: Applies to agents/composio//src/agents//index.ts : All code should be in Typescript format
Learnt from: CR
PR: agentuity/examples#0
File: agents/Startup_News_Scraper/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-07-17T13:38:58.657Z
Learning: Applies to agents/Startup_News_Scraper//src/agents//index.ts : All code should be in Typescript format
Learnt from: CR
PR: agentuity/fuse-infra#0
File: .cursor/rules/agent.mdc:0-0
Timestamp: 2025-07-08T16:50:51.612Z
Learning: Applies to /src/agents//index.ts : All code should be in Typescript format
Learnt from: CR
PR: agentuity/agent-crm#0
File: .cursor/rules/agent.mdc:0-0
Timestamp: 2025-07-18T15:32:21.381Z
Learning: Applies to /src/agents//index.ts : All code should be in Typescript format
lib/agent.ts (23)
Learnt from: CR
PR: agentuity/examples#0
File: agents/agent-riza/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-07-17T13:39:31.143Z
Learning: Applies to agents/agent-riza/src/agents/**/*.ts : Consider agent communication (e.g., response.handoff, context.getAgent) for complex workflows
Learnt from: CR
PR: agentuity/examples#0
File: agents/composio/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-07-17T13:39:37.133Z
Learning: Applies to agents/composio//src/agents//index.ts : Prefer naming the default function Agent or the name of the Agent based on the context of the Agent description
Learnt from: CR
PR: agentuity/examples#0
File: agents/deep-research-js/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-07-17T13:40:05.817Z
Learning: Applies to agents/deep-research-js/src/agents/**/*.ts : Consider agent communication for complex workflows
Learnt from: CR
PR: agentuity/docs#0
File: agent-docs/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-07-23T12:40:34.834Z
Learning: Applies to agent-docs/src/agents/**/*.ts : Consider agent communication for complex workflows
Learnt from: CR
PR: agentuity/examples#0
File: frameworks/vercel/basic/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-06-23T17:16:49.315Z
Learning: When writing an Agent in TypeScript for Agentuity, always use the types provided by the @agentuity/sdk package for AgentRequest, AgentResponse, and AgentContext to ensure type safety and compatibility.
Learnt from: CR
PR: agentuity/examples#0
File: frameworks/mastra/basic/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-06-23T17:15:12.561Z
Learning: In Agentuity AI Agent files (**/src/agents/**/index.ts), always use the provided logger from the AgentContext interface (e.g., ctx.logger.info(...)) for logging, rather than custom or external logging solutions.
Learnt from: CR
PR: agentuity/examples#0
File: frameworks/langgraph/basic/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-06-23T17:14:39.393Z
Learning: In Agentuity AI Agent files (**/src/agents/**/index.ts), always use the provided logger from the AgentContext interface (e.g., ctx.logger.info(...)) for logging, rather than custom or external logging solutions.
Learnt from: CR
PR: agentuity/examples#0
File: agentuity/sdk-js/streaming/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-07-17T13:40:37.445Z
Learning: Applies to agentuity/sdk-js/streaming//src/agents//index.ts : Prefer naming the default function Agent or the name of the Agent based on the context of the Agent description
Learnt from: CR
PR: agentuity/examples#0
File: frameworks/langgraph/basic/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-06-23T17:14:39.393Z
Learning: In Agentuity AI Agent files (**/src/agents/**/index.ts), import types such as AgentRequest, AgentResponse, and AgentContext from the @agentuity/sdk package to ensure type safety and consistency.
Learnt from: CR
PR: agentuity/examples#0
File: frameworks/mastra/basic/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-06-23T17:15:12.561Z
Learning: In Agentuity AI Agent files (**/src/agents/**/index.ts), import types such as AgentRequest, AgentResponse, and AgentContext from the @agentuity/sdk package to ensure type safety and consistency.
Learnt from: CR
PR: agentuity/collider#0
File: projects/collider-node/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-06-24T15:42:32.504Z
Learning: The Agentuity JavaScript SDK provides core interfaces such as AgentHandler, AgentRequest, AgentResponse, and AgentContext for building AI agents in TypeScript/JavaScript.
Learnt from: CR
PR: agentuity/examples#0
File: frameworks/langgraph/basic/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-06-23T17:14:46.802Z
Learning: The Agentuity JavaScript SDK provides core interfaces such as AgentHandler, AgentRequest, AgentResponse, and AgentContext for building AI agents in TypeScript or JavaScript.
Learnt from: CR
PR: agentuity/examples#0
File: agents/composio/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-07-17T13:39:44.988Z
Learning: Applies to agents/composio/src/agents/**/*.ts : Import types from @agentuity/sdk
Learnt from: CR
PR: agentuity/examples#0
File: frameworks/vercel/basic/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-06-23T17:16:58.079Z
Learning: Import types from @agentuity/sdk to ensure consistency and leverage type definitions.
Learnt from: CR
PR: agentuity/collider#0
File: projects/collider-node/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-06-24T15:42:21.297Z
Learning: Agent files for Agentuity should export a default async function, typically named Agent or contextually named after the Agent, which receives AgentRequest, AgentResponse, and AgentContext as parameters.
Learnt from: CR
PR: agentuity/examples#0
File: frameworks/mastra/basic/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-06-23T17:15:21.314Z
Learning: For best practices in Agentuity SDK projects, use TypeScript for type safety, import types from @agentuity/sdk, use structured error handling with try/catch, leverage the provided logger, use storage APIs for data persistence, and consider agent communication for complex workflows.
Learnt from: CR
PR: agentuity/examples#0
File: patterns/llmAsJury/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-06-23T17:17:19.027Z
Learning: Import types from @agentuity/sdk to ensure consistency and type safety.
Learnt from: CR
PR: agentuity/examples#0
File: frameworks/vercel/basic/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-06-23T17:16:58.079Z
Learning: In the Agentuity JavaScript SDK, the main handler for an agent should implement the AgentHandler type: (request: AgentRequest, response: AgentResponse, context: AgentContext) => Promise.
Learnt from: CR
PR: agentuity/examples#0
File: patterns/llmAsJury/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-06-23T17:17:19.027Z
Learning: In the Agentuity JavaScript SDK, the main handler for an agent should implement the AgentHandler type: (request: AgentRequest, response: AgentResponse, context: AgentContext) => Promise.
Learnt from: CR
PR: agentuity/examples#0
File: frameworks/openai/from-oai-typescript/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-06-23T17:16:08.480Z
Learning: In the Agentuity JavaScript SDK, the main handler for an agent should implement the AgentHandler type: (request: AgentRequest, response: AgentResponse, context: AgentContext) => Promise.
Learnt from: CR
PR: agentuity/examples#0
File: frameworks/mastra/basic/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-06-23T17:15:21.314Z
Learning: In the Agentuity JavaScript SDK, the main handler for an agent should implement the AgentHandler type: a function that takes (request: AgentRequest, response: AgentResponse, context: AgentContext) and returns a Promise of AgentResponseType.
Learnt from: CR
PR: agentuity/examples#0
File: frameworks/mastra/basic/.cursor/rules/sdk.mdc:0-0
Timestamp: 2025-06-23T17:15:21.314Z
Learning: The AgentRequest interface in the Agentuity SDK provides methods for accessing trigger type, metadata, and request payload in various formats (JSON, text, ArrayBuffer, typed object).
Learnt from: CR
PR: agentuity/examples#0
File: frameworks/langgraph/basic/.cursor/rules/agent.mdc:0-0
Timestamp: 2025-06-23T17:14:39.393Z
Learning: In Agentuity AI Agent files (**/src/agents/**/index.ts), the default export should be an async function that handles the agent logic, typically accepting parameters (req: AgentRequest, resp: AgentResponse, ctx: AgentContext).
🔇 Additional comments (4)
src/agents/smartlead-agent/index.ts (1)
31-37: LGTM! Formatting improvements enhance readability.The JSON structure formatting corrections improve the clarity of the tool call examples in the prompt, making them properly nested and easier to understand.
Also applies to: 51-57, 59-65, 68-72, 74-85, 87-94, 97-100, 104-106, 118-121
lib/agent.ts (3)
6-11: Excellent refactoring improvements!The changes improve the code quality:
- Module-level client initialization avoids repeated instantiation
- Explicit environment variable validation with clear error messages
- Specific tool list instead of filtering improves clarity and potentially performance
Also applies to: 40-44, 45-54
125-125: Great improvement in logging and observability!Replacing console.log with context logger ensures proper log aggregation and follows the Agentuity SDK best practices.
Also applies to: 173-177, 182-185, 193-193, 216-216, 257-257
203-290: Well-structured separation of custom and composio tool execution!The refactored logic clearly separates custom tool execution from composio tools, with proper error handling for each. The merging strategy for mixed tool results is clean and maintainable.
| const payload = await req.data.json(); | ||
| if ( | ||
| verifyWebhook && | ||
| !verifyWebhook(JSON.stringify(payload), req, resp, ctx) | ||
| ) { |
There was a problem hiding this comment.
💡 Verification agent
🧩 Analysis chain
Verify webhook signature validation compatibility.
The change from raw body to parsed JSON might break webhook signature validation if the verifier expects the exact raw body bytes for HMAC verification. Many webhook providers (like Stripe) require the raw body for signature validation.
🏁 Script executed:
#!/bin/bash
# Check if any webhook verifiers in the codebase use signature validation
rg -A 10 "verifyWebhook|signature|hmac" --type tsLength of output: 2057
Ensure webhook signature verifiers receive the unaltered raw body
The handler currently parses the JSON and then re-serializes it for verifyWebhook, which will break HMAC checks (e.g. Stripe’s constructEvent) that require the exact raw payload bytes. Update the code to read the raw text first, pass it directly into verifyWebhook, then parse it for further processing.
Example diff:
- const payload = await req.data.json();
- if (
- verifyWebhook &&
- !verifyWebhook(JSON.stringify(payload), req, resp, ctx)
- ) {
+ const rawBody = await req.data.text();
+ const payload = JSON.parse(rawBody);
+ if (
+ verifyWebhook &&
+ !verifyWebhook(rawBody, req, resp, ctx)
+ ) {
return resp.json({
success: false,
error: "Webhook verification failed.",
});Areas to address:
- lib/agent.ts (lines 29–33): switch from
json()/stringifytotext()/JSON.parse - src/agents/stripe-agent/index.ts: ensure your
verifyWebhookimplementation (currently commented out) accepts and uses the raw body for HMAC verification
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const payload = await req.data.json(); | |
| if ( | |
| verifyWebhook && | |
| !verifyWebhook(JSON.stringify(payload), req, resp, ctx) | |
| ) { | |
| // Read the raw body for signature verification | |
| const rawBody = await req.data.text(); | |
| const payload = JSON.parse(rawBody); | |
| if ( | |
| verifyWebhook && | |
| !verifyWebhook(rawBody, req, resp, ctx) | |
| ) { | |
| return resp.json({ | |
| success: false, | |
| error: "Webhook verification failed.", | |
| }); | |
| } |
🤖 Prompt for AI Agents
In lib/agent.ts around lines 29 to 33, the code currently parses the request
body as JSON and then re-serializes it for verifyWebhook, which breaks HMAC
verification. Change the code to first read the raw request body as text, pass
this raw text directly to verifyWebhook, and then parse the text with JSON.parse
for further processing. This ensures the webhook signature verifier receives the
exact unaltered payload it requires.
Summary by CodeRabbit
Bug Fixes
Refactor
Style
Chores