# withPeam



# 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](/docs/api-reference/next/create-chat) and the [route handler](/docs/api-reference/next/route).

## Type Definition

```ts
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

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

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

export default withPeam()(nextConfig);
```

### With Custom Index Path

```ts
// 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)

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

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

### With Existing Next.js Plugins

```ts
// 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`.

```ts
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.

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

### exclude

Wildcard patterns to exclude from indexing.

```ts
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](/docs/getting-started/next))

## 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

* [Next.js guide](/docs/getting-started/next)
* [createChat](/docs/api-reference/next/create-chat)
* [route](/docs/api-reference/next/route)
* [Next.js Configuration](https://nextjs.org/docs/app/api-reference/next-config-js)


## Sitemap
[Overview of all docs pages](/sitemap.md)
