Skip to content

feat: detect if nuxt is run by an agent#394

Open
atinux wants to merge 1 commit intomainfrom
feat/agent-detection
Open

feat: detect if nuxt is run by an agent#394
atinux wants to merge 1 commit intomainfrom
feat/agent-detection

Conversation

@atinux
Copy link
Member

@atinux atinux commented Feb 11, 2026

❓ Type of change

  • 👌 Enhancement (improving an existing functionality)

📚 Description

Add isAgent and agentName to better understand how many people use Nuxt from agents.

@atinux atinux requested a review from danielroe as a code owner February 11, 2026 12:07
@coderabbitai
Copy link

coderabbitai bot commented Feb 11, 2026

📝 Walkthrough

Walkthrough

This pull request adds agent detection capabilities to the application. A new runtime dependency "@vercel/detect-agent" is introduced in package.json. The Context interface in src/types.ts is expanded with two new fields: isAgent (boolean) and agentName (string | null). In src/context.ts, the determineAgent function from the new dependency is integrated into the createContext function to populate these fields. The telemetry module (src/telemetry.ts) is updated to include these new fields in its public context payload. Test assertions in src/e2e.spec.ts are updated to validate the presence and types of these new fields.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The PR title accurately and concisely summarizes the main change: detecting when Nuxt is run by an agent.
Description check ✅ Passed The description clearly relates to the changeset by explaining the addition of isAgent and agentName properties for detecting agent usage.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/agent-detection

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


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

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/context.ts (1)

35-52: ⚠️ Potential issue | 🟠 Major

Wrap determineAgent() in a try/catch to prevent telemetry failures.

determineAgent() is an external call that could throw (e.g., unexpected environment, library bug). Since agent detection is non-critical, a failure here should not break context creation and, by extension, all telemetry reporting.

🛡️ Proposed fix
-  const agent = await determineAgent()
+  let isAgent = false
+  let agentName: string | null = null
+  try {
+    const agent = await determineAgent()
+    isAgent = agent.isAgent
+    agentName = agent.isAgent ? agent.agent.name : null
+  }
+  catch {
+    // Ignore agent detection failures
+  }

   return {
     nuxt,
     seed,
     git,
     projectHash,
     projectSession,
     nuxtVersion,
     nuxtMajorVersion,
     isEdge,
     cli: getCLI(),
     nodeVersion,
     os: os.type().toLocaleLowerCase(),
     environment: getEnv(),
     packageManager: packageManager || 'unknown',
-    isAgent: agent.isAgent,
-    agentName: agent.isAgent ? agent.agent.name : null,
+    isAgent,
+    agentName,
     concent: options.consent,
   }

@atinux
Copy link
Member Author

atinux commented Feb 11, 2026

To respond to coderabbit, try/catch is not needed as the only thing capable to fail on the detect-agent is already within a try/catch: https://github.com/vercel/vercel/blob/main/packages/detect-agent/src/index.ts

@danielroe
Copy link
Member

linking unjs/std-env#179

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.

2 participants