@galaar/agentecho-nextjs
v0.1.0
Published
AgentECHO Next.js - Next.js adapter for @galaar/agentecho-core with proxy.ts integration
Readme
@galaar/agentecho-nextjs
Next.js adapter for AgentECHO. Integrates with proxy.ts / middleware.ts for fire-and-forget event tracking.
Installation
pnpm add @galaar/agentecho-nextjsUsage
Create proxy.ts in your project root:
import { createAgentECHO } from '@galaar/agentecho-nextjs';
import { NextRequest, NextFetchEvent, NextResponse } from 'next/server';
const tracker = createAgentECHO({
ingestUrl: process.env.AGENTECHO_INGEST_URL!,
keyId: process.env.AGENTECHO_KEY_ID!,
hmacSecret: process.env.AGENTECHO_HMAC_SECRET!,
});
export function proxy(req: NextRequest, event: NextFetchEvent) {
tracker.capture(req, event);
return NextResponse.next();
}
export const config = {
matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
};Configuration
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| ingestUrl | string | — | Backend endpoint URL |
| keyId | string | — | Key identifier |
| hmacSecret | string | — | HMAC secret |
| sampleRate | number | 0.1 | Sample rate (0-1) |
| timeout | number | 3000 | Timeout (ms) |
| debug | boolean | false | Debug logging |
| excludePaths | string[] | [] | Additional paths to exclude |
Captured Data
Automatically extracted from each request:
method— HTTP methodpathname— Request pathsearch— Query stringip— Client IP (fromx-real-ip,x-forwarded-for, orcf-connecting-ip)userAgent— User agentreferer— Referer header
Default Excluded Paths
/_next/static/*/_next/image/*/favicon.ico/robots.txt/sitemap.xml/manifest.json/apple-touch-icon*.png
Custom Exclusions
const tracker = createAgentECHO({
// ...
excludePaths: ['/admin', '/health'],
});Exports
import {
createAgentECHO, // Main factory
extractRequestData, // Extract data from NextRequest
extractIpAddress, // Extract IP from headers
shouldCapture, // Check if path should be captured
} from '@galaar/agentecho-nextjs';Compatibility
- Next.js 15+ (
middleware.ts) - Next.js 16+ (
proxy.ts)
License
MIT
