withPeam

Next.js configuration wrapper for Peam integration

Overview

Wraps your Next.js config to enable Peam content extraction during build. It sets configuration for the adapter, search store, and output file tracing, which are consumed by createChat and the route handler.

Type Definition

import type { NextConfig } from 'next';
import type { SearchStoreConfig } from 'peam/search';

export interface PeamConfig {
  /**
   * Search store configuration
   * @default { type: 'fileBased', config: { indexPath: '.peam/index.json' } }
   */
  searchStore?: SearchStoreConfig;

  /**
   * Auto-discover robots.txt when true, use a custom path when string, or false to disable
   * @default undefined
   */
  robotsTxt?: string | boolean;

  /**
   * Array of wildcard patterns to exclude from indexing
   * @default []
   */
  exclude?: string[];
}

export declare function withPeam(peamConfig?: PeamConfig): (nextConfig?: NextConfig) => NextConfig;

Usage Examples

Basic Usage

// next.config.ts
import withPeam from '@peam-ai/next';

const nextConfig = {
  // your Next.js config
};

export default withPeam()(nextConfig);

With Custom Index Path

// next.config.ts
import withPeam from '@peam-ai/next';

const nextConfig = {
  // your Next.js config
};

export default withPeam({
  searchStore: {
    type: 'fileBased',
    config: {
      indexPath: 'public/.peam/index.json',
    },
  },
})(nextConfig);

CommonJS (JavaScript)

// next.config.js
const withPeam = require('@peam-ai/next');

module.exports = withPeam()({
  // your Next.js config
});

With Existing Next.js Plugins

// next.config.ts
import withPeam from '@peam-ai/next';
import withBundleAnalyzer from '@next/bundle-analyzer';

const nextConfig = {
  // your Next.js config
};

// Compose multiple config wrappers
export default withPeam()(
  withBundleAnalyzer({
    enabled: process.env.ANALYZE === 'true',
  })(nextConfig)
);

Configuration Options

searchStore

Controls how the search index is stored during the build process.

Currently, the only supported store type is fileBased.

const peamConfig: PeamConfig = {
  searchStore: {
    type: 'fileBased',
    config: {
      indexPath: '.peam/index.json',
    },
  },
};

robotsTxt

Controls robots.txt filtering. When true, Peam auto-discovers robots.txt in your project. When a string, it uses that path. If false, robots filtering is disabled.

const peamConfig: PeamConfig = {
  robotsTxt: 'custom/robots.txt',
};

exclude

Wildcard patterns to exclude from indexing.

const peamConfig: PeamConfig = {
  exclude: ['/admin/**', '/api/*', '/private-*'],
};

How It Works

The withPeam function enhances your Next.js configuration by:

  1. Adding a Build Adapter: For Next.js 15+, configures the adapter to extract content during build
  2. Configuring File Tracing: Adds output file tracing for the search index
  3. Creating Stub Index: Creates an empty index file in production if missing

Requirements

  • Next.js 15+: The adapter feature requires Next.js 15 or higher
  • For Next.js 14, use the postbuild CLI approach (see Next.js guide)

Deployment

When deploying to Vercel or other platforms, the withPeam configuration ensures that:

  • The search index is properly traced and included in the deployment
  • The index is accessible to your API routes at runtime
  • File paths are correctly resolved in serverless environments

See Also