@peam-ai/next 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +6 -11
- package/dist/index.d.ts +6 -11
- package/dist/index.js +28 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +29 -30
- package/dist/index.mjs.map +1 -1
- package/dist/peam.adapter.js +44 -114
- package/dist/peam.adapter.js.map +1 -1
- package/dist/route.d.mts +14 -2
- package/dist/route.d.ts +14 -2
- package/dist/route.js +23 -14
- package/dist/route.js.map +1 -1
- package/dist/route.mjs +25 -17
- package/dist/route.mjs.map +1 -1
- package/package.json +5 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,24 +1,19 @@
|
|
|
1
1
|
import { NextConfig } from 'next';
|
|
2
|
-
import {
|
|
2
|
+
import { SearchStoreConfig } from 'peam/search';
|
|
3
3
|
|
|
4
4
|
interface PeamConfig {
|
|
5
5
|
/**
|
|
6
|
-
* Search
|
|
6
|
+
* Search store configuration
|
|
7
7
|
* @default { type: 'fileBased', config: { indexPath: '.peam/index.json' } }
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
searchStore?: SearchStoreConfig;
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*/
|
|
14
|
-
respectRobotsTxt?: boolean;
|
|
15
|
-
/**
|
|
16
|
-
* Path to a custom robots.txt file relative to the project root
|
|
17
|
-
* If not specified, the adapter will look for static or dynamic robots.txt files in standard locations
|
|
11
|
+
* Path to a custom robots.txt file or false to disable robots.txt filtering
|
|
12
|
+
* If undefined, the adapter will look for static or dynamic robots.txt files in standard locations
|
|
18
13
|
* @example 'custom/robots.txt' or 'config/production-robots.txt'
|
|
19
14
|
* @default undefined
|
|
20
15
|
*/
|
|
21
|
-
|
|
16
|
+
robotsTxt?: string | boolean;
|
|
22
17
|
/**
|
|
23
18
|
* Array of wildcard patterns to exclude from indexing
|
|
24
19
|
* Supports * (matches any characters except /), ** (matches any characters including /), and ? (single character)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,24 +1,19 @@
|
|
|
1
1
|
import { NextConfig } from 'next';
|
|
2
|
-
import {
|
|
2
|
+
import { SearchStoreConfig } from 'peam/search';
|
|
3
3
|
|
|
4
4
|
interface PeamConfig {
|
|
5
5
|
/**
|
|
6
|
-
* Search
|
|
6
|
+
* Search store configuration
|
|
7
7
|
* @default { type: 'fileBased', config: { indexPath: '.peam/index.json' } }
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
searchStore?: SearchStoreConfig;
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*/
|
|
14
|
-
respectRobotsTxt?: boolean;
|
|
15
|
-
/**
|
|
16
|
-
* Path to a custom robots.txt file relative to the project root
|
|
17
|
-
* If not specified, the adapter will look for static or dynamic robots.txt files in standard locations
|
|
11
|
+
* Path to a custom robots.txt file or false to disable robots.txt filtering
|
|
12
|
+
* If undefined, the adapter will look for static or dynamic robots.txt files in standard locations
|
|
18
13
|
* @example 'custom/robots.txt' or 'config/production-robots.txt'
|
|
19
14
|
* @default undefined
|
|
20
15
|
*/
|
|
21
|
-
|
|
16
|
+
robotsTxt?: string | boolean;
|
|
22
17
|
/**
|
|
23
18
|
* Array of wildcard patterns to exclude from indexing
|
|
24
19
|
* Supports * (matches any characters except /), ** (matches any characters including /), and ? (single character)
|
package/dist/index.js
CHANGED
|
@@ -27,24 +27,20 @@ var path__namespace = /*#__PURE__*/_interopNamespace(path);
|
|
|
27
27
|
|
|
28
28
|
// src/withPeam.ts
|
|
29
29
|
var defaultConfig = {
|
|
30
|
-
|
|
30
|
+
searchStore: {
|
|
31
31
|
type: "fileBased",
|
|
32
32
|
config: { indexPath: ".peam/index.json" }
|
|
33
33
|
},
|
|
34
|
-
respectRobotsTxt: true,
|
|
35
34
|
exclude: []
|
|
36
35
|
};
|
|
37
36
|
function setNextConfig(nextConfig, peamConfig) {
|
|
38
|
-
var _a, _b, _c, _d, _e, _f;
|
|
39
37
|
const envVars = {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
PEAM_EXCLUDE: (_f = JSON.stringify(peamConfig == null ? void 0 : peamConfig.exclude)) != null ? _f : JSON.stringify(defaultConfig.exclude),
|
|
44
|
-
PEAM_ROBOTS_TXT_PATH: ""
|
|
38
|
+
PEAM_SEARCH_STORE: JSON.stringify((peamConfig == null ? void 0 : peamConfig.searchStore) ? peamConfig.searchStore : defaultConfig.searchStore),
|
|
39
|
+
PEAM_EXCLUDE: JSON.stringify((peamConfig == null ? void 0 : peamConfig.exclude) ? peamConfig.exclude : defaultConfig.exclude),
|
|
40
|
+
PEAM_ROBOTS_TXT: ""
|
|
45
41
|
};
|
|
46
|
-
if (peamConfig == null ? void 0 : peamConfig.
|
|
47
|
-
envVars.
|
|
42
|
+
if ((peamConfig == null ? void 0 : peamConfig.robotsTxt) !== void 0) {
|
|
43
|
+
envVars.PEAM_ROBOTS_TXT = String(peamConfig.robotsTxt);
|
|
48
44
|
}
|
|
49
45
|
Object.assign(process.env, envVars);
|
|
50
46
|
nextConfig.env = {
|
|
@@ -53,24 +49,26 @@ function setNextConfig(nextConfig, peamConfig) {
|
|
|
53
49
|
};
|
|
54
50
|
}
|
|
55
51
|
var getConfig = () => {
|
|
56
|
-
if (!process.env.
|
|
52
|
+
if (!process.env.PEAM_SEARCH_STORE) {
|
|
57
53
|
throw new Error(
|
|
58
54
|
"Peam configuration not found. Make sure withPeam() is properly configured in your next.config file."
|
|
59
55
|
);
|
|
60
56
|
}
|
|
61
|
-
const
|
|
62
|
-
type: process.env.PEAM_SEARCH_EXPORTER_TYPE,
|
|
63
|
-
config: JSON.parse(process.env.PEAM_SEARCH_EXPORTER_CONFIG)
|
|
64
|
-
};
|
|
57
|
+
const searchStoreConfig = JSON.parse(process.env.PEAM_SEARCH_STORE);
|
|
65
58
|
const resolvedConfig = {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
robotsTxtPath: process.env.PEAM_ROBOTS_TXT_PATH || void 0,
|
|
59
|
+
searchStore: searchStoreConfig,
|
|
60
|
+
searchIndexStore: search.createStoreFromConfig(searchStoreConfig),
|
|
61
|
+
robotsTxt: parseRobotsTxtEnv(process.env.PEAM_ROBOTS_TXT),
|
|
70
62
|
exclude: process.env.PEAM_EXCLUDE ? JSON.parse(process.env.PEAM_EXCLUDE) : []
|
|
71
63
|
};
|
|
72
64
|
return resolvedConfig;
|
|
73
65
|
};
|
|
66
|
+
function parseRobotsTxtEnv(value) {
|
|
67
|
+
if (value === void 0 || value === "") return void 0;
|
|
68
|
+
if (value === "false") return false;
|
|
69
|
+
if (value === "true") return true;
|
|
70
|
+
return value;
|
|
71
|
+
}
|
|
74
72
|
|
|
75
73
|
// src/withPeam.ts
|
|
76
74
|
var require2 = module$1.createRequire(process.cwd() + "/");
|
|
@@ -92,20 +90,20 @@ function addStubIndex() {
|
|
|
92
90
|
return;
|
|
93
91
|
}
|
|
94
92
|
const config = getConfig();
|
|
95
|
-
if (((_a = config.
|
|
93
|
+
if (((_a = config.searchStore) == null ? void 0 : _a.type) !== "fileBased") {
|
|
96
94
|
return;
|
|
97
95
|
}
|
|
98
96
|
const stubData = { keys: [], data: {} };
|
|
99
|
-
(_c = (_b = config.
|
|
97
|
+
(_c = (_b = config.searchIndexStore).exportSync) == null ? void 0 : _c.call(_b, stubData, { override: false });
|
|
100
98
|
} catch (error) {
|
|
101
99
|
log.error("Failed to create stub index:", error);
|
|
102
100
|
}
|
|
103
101
|
}
|
|
104
102
|
function addAdapter(config) {
|
|
105
103
|
const nextVersion = getNextVersion();
|
|
106
|
-
if (!nextVersion || nextVersion.major <
|
|
104
|
+
if (!nextVersion || nextVersion.major < 15) {
|
|
107
105
|
log.warn(
|
|
108
|
-
"Peam adapter requires Next.js
|
|
106
|
+
"Peam adapter requires Next.js 15 or higher, skipping adapter configuration. Make sure the postbuild script is set up correctly, See more here: https://peam.ai/docs."
|
|
109
107
|
);
|
|
110
108
|
return config;
|
|
111
109
|
}
|
|
@@ -118,14 +116,15 @@ function addAdapter(config) {
|
|
|
118
116
|
};
|
|
119
117
|
}
|
|
120
118
|
function addOutputFileTracing(nextConfig) {
|
|
121
|
-
var _a, _b, _c;
|
|
119
|
+
var _a, _b, _c, _d;
|
|
122
120
|
const peamConfig = getConfig();
|
|
123
|
-
if (((_a = peamConfig.
|
|
121
|
+
if (((_a = peamConfig.searchStore) == null ? void 0 : _a.type) !== "fileBased") {
|
|
124
122
|
return nextConfig;
|
|
125
123
|
}
|
|
126
124
|
nextConfig = { ...nextConfig };
|
|
127
|
-
const
|
|
128
|
-
const
|
|
125
|
+
const storeConfig = peamConfig.searchStore.config;
|
|
126
|
+
const indexPath = (_b = storeConfig.indexPath) != null ? _b : ".peam/index.json";
|
|
127
|
+
const indexDir = path__namespace.dirname(indexPath);
|
|
129
128
|
const tracingConfig = {
|
|
130
129
|
"/api/peam": [`./${indexDir}/**/*`]
|
|
131
130
|
};
|
|
@@ -144,7 +143,7 @@ function addOutputFileTracing(nextConfig) {
|
|
|
144
143
|
...tracingConfig
|
|
145
144
|
}
|
|
146
145
|
});
|
|
147
|
-
const existingRootTracing = (
|
|
146
|
+
const existingRootTracing = (_c = nextConfig.outputFileTracingIncludes) != null ? _c : {};
|
|
148
147
|
Object.assign(nextConfig, {
|
|
149
148
|
outputFileTracingIncludes: {
|
|
150
149
|
...existingRootTracing,
|
|
@@ -163,7 +162,7 @@ function addOutputFileTracing(nextConfig) {
|
|
|
163
162
|
}
|
|
164
163
|
});
|
|
165
164
|
} else {
|
|
166
|
-
const existingTracing = (
|
|
165
|
+
const existingTracing = (_d = nextConfig.outputFileTracingIncludes) != null ? _d : {};
|
|
167
166
|
Object.assign(nextConfig, {
|
|
168
167
|
outputFileTracingIncludes: {
|
|
169
168
|
...existingTracing,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/config.ts","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A,QACzB,GAAG,eAAA;AAAA,QACH,GAAG;AAAA;AACL,KACD,CAAA;AAAA,EACH;AAEA,EAAA,OAAO,UAAA;AACT;AAyBO,SAAS,SAAS,UAAA,EAAyB;AAChD,EAAA,OAAO,SAAU,UAAA,GAAyB,EAAC,EAAe;AACxD,IAAA,aAAA,CAAc,YAAY,UAAU,CAAA;AACpC,IAAA,YAAA,EAAa;AAEb,IAAA,IAAI,iBAAA,GAAgC,EAAE,GAAG,UAAA,EAAW;AACpD,IAAA,iBAAA,GAAoB,WAAW,iBAAiB,CAAA;AAChD,IAAA,iBAAA,GAAoB,qBAAqB,iBAAiB,CAAA;AAE1D,IAAA,OAAO,iBAAA;AAAA,EACT,CAAA;AACF;;;AC5KA,IAAO,aAAA,GAAQ","file":"index.js","sourcesContent":["import { NextConfig } from 'next';\nimport { createExporterFromConfig, type SearchExporterConfig, type SearchIndexExporter } from 'peam/search';\n\nexport interface PeamConfig {\n /**\n * Search exporter configuration\n * @default { type: 'fileBased', config: { indexPath: '.peam/index.json' } }\n */\n searchExporter?: SearchExporterConfig;\n /**\n * Whether to respect robots.txt rules when indexing pages\n * @default true\n */\n respectRobotsTxt?: boolean;\n /**\n * Path to a custom robots.txt file relative to the project root\n * If not specified, the adapter will look for static or dynamic robots.txt files in standard locations\n * @example 'custom/robots.txt' or 'config/production-robots.txt'\n * @default undefined\n */\n robotsTxtPath?: string;\n /**\n * Array of wildcard patterns to exclude from indexing\n * Supports * (matches any characters except /), ** (matches any characters including /), and ? (single character)\n * @example ['/admin/**', '/api/*', '/private-*']\n * @default []\n */\n exclude?: string[];\n}\n\nexport type ResolvedPeamAdapterConfig = Required<Omit<PeamConfig, 'robotsTxtPath'>> & {\n robotsTxtPath?: string;\n searchIndexExporter: SearchIndexExporter;\n};\n\nconst defaultConfig = {\n searchExporter: {\n type: 'fileBased' as const,\n config: { indexPath: '.peam/index.json' },\n },\n respectRobotsTxt: true,\n robotsTxtPath: undefined,\n exclude: [],\n} satisfies PeamConfig;\n\nexport function setNextConfig(nextConfig: NextConfig, peamConfig?: PeamConfig): void {\n const envVars = {\n PEAM_SEARCH_EXPORTER_TYPE: peamConfig?.searchExporter?.type ?? defaultConfig.searchExporter.type,\n PEAM_SEARCH_EXPORTER_CONFIG:\n JSON.stringify(peamConfig?.searchExporter?.config) ?? JSON.stringify(defaultConfig.searchExporter.config),\n PEAM_RESPECT_ROBOTS_TXT: String(peamConfig?.respectRobotsTxt ?? defaultConfig.respectRobotsTxt),\n PEAM_EXCLUDE: JSON.stringify(peamConfig?.exclude) ?? JSON.stringify(defaultConfig.exclude),\n PEAM_ROBOTS_TXT_PATH: '',\n };\n\n if (peamConfig?.robotsTxtPath) {\n envVars.PEAM_ROBOTS_TXT_PATH = String(peamConfig.robotsTxtPath);\n }\n\n // Set build time vars\n Object.assign(process.env, envVars);\n\n // Set runtime vars\n nextConfig.env = {\n ...nextConfig.env,\n ...envVars,\n };\n}\n\nexport const getConfig = (): ResolvedPeamAdapterConfig => {\n if (!process.env.PEAM_SEARCH_EXPORTER_TYPE || !process.env.PEAM_SEARCH_EXPORTER_CONFIG) {\n throw new Error(\n 'Peam configuration not found. Make sure withPeam() is properly configured in your next.config file.'\n );\n }\n\n const searchExporterConfig: SearchExporterConfig = {\n type: process.env.PEAM_SEARCH_EXPORTER_TYPE as SearchExporterConfig['type'],\n config: JSON.parse(process.env.PEAM_SEARCH_EXPORTER_CONFIG),\n };\n\n const resolvedConfig = {\n searchExporter: searchExporterConfig,\n searchIndexExporter: createExporterFromConfig(searchExporterConfig),\n respectRobotsTxt: process.env.PEAM_RESPECT_ROBOTS_TXT === 'true',\n robotsTxtPath: process.env.PEAM_ROBOTS_TXT_PATH || undefined,\n exclude: process.env.PEAM_EXCLUDE ? JSON.parse(process.env.PEAM_EXCLUDE) : [],\n };\n\n return resolvedConfig;\n};\n","import type { NextConfig } from 'next';\nimport { createRequire } from 'node:module';\nimport * as path from 'path';\nimport { loggers } from 'peam/logger';\nimport { getConfig, PeamConfig, setNextConfig } from './config';\n\nconst require = createRequire(process.cwd() + '/');\nconst log = loggers.next;\nconst isProd = process.env.NODE_ENV === 'production';\n\nfunction getNextVersion(): { major: number; minor: number } | undefined {\n try {\n const [major, minor] = require('next/package.json').version.split('.', 2).map(Number);\n\n return { major, minor };\n } catch (error) {\n log.error('Could not resolve Next.js version.', error);\n return undefined;\n }\n}\n\nfunction addStubIndex() {\n try {\n if (!isProd) {\n return;\n }\n\n const config = getConfig();\n\n if (config.searchExporter?.type !== 'fileBased') {\n return;\n }\n\n const stubData = { keys: [], data: {} };\n config.searchIndexExporter.exportSync?.(stubData, { override: false });\n } catch (error) {\n log.error('Failed to create stub index:', error);\n }\n}\n\nfunction addAdapter(config: NextConfig): NextConfig {\n const nextVersion = getNextVersion();\n\n if (!nextVersion || nextVersion.major < 16) {\n log.warn(\n 'Peam adapter requires Next.js 16 or higher, skipping adapter configuration. Make sure the postbuild script is set up correctly, See more here: https://peam.ai/docs.'\n );\n return config;\n }\n\n return {\n ...config,\n experimental: {\n ...config.experimental,\n adapterPath: require.resolve(path.join(__dirname, 'peam.adapter.js')),\n },\n };\n}\n\nfunction addOutputFileTracing(nextConfig: NextConfig): NextConfig {\n const peamConfig = getConfig();\n\n if (peamConfig.searchExporter?.type !== 'fileBased') {\n return nextConfig;\n }\n\n nextConfig = { ...nextConfig };\n\n const exporterConfig = peamConfig.searchExporter.config;\n const indexDir = path.dirname(exporterConfig.indexPath);\n const tracingConfig = {\n '/api/peam': [`./${indexDir}/**/*`],\n };\n\n const nextVersion = getNextVersion();\n\n if (!nextVersion) {\n log.warn(\n 'Could not determine Next.js version. Adding outputFileTracingIncludes to both experimental and root config.'\n );\n\n // Add to experimental (for Next.js 14.x)\n const existingExperimentalTracing =\n typeof nextConfig.experimental === 'object' && 'outputFileTracingIncludes' in nextConfig.experimental\n ? nextConfig.experimental.outputFileTracingIncludes\n : undefined;\n\n if (!nextConfig.experimental) {\n nextConfig.experimental = {};\n }\n\n Object.assign(nextConfig.experimental, {\n outputFileTracingIncludes: {\n ...(existingExperimentalTracing || {}),\n ...tracingConfig,\n },\n });\n\n // Add to root (for Next.js 15+)\n const existingRootTracing = nextConfig.outputFileTracingIncludes ?? {};\n\n Object.assign(nextConfig, {\n outputFileTracingIncludes: {\n ...existingRootTracing,\n ...tracingConfig,\n },\n });\n } else if (nextVersion.major < 15) {\n // For Next.js 14.x, add outputFileTracingIncludes in experimental\n const existingTracing =\n typeof nextConfig.experimental === 'object' && 'outputFileTracingIncludes' in nextConfig.experimental\n ? nextConfig.experimental.outputFileTracingIncludes\n : undefined;\n\n if (!nextConfig.experimental) {\n nextConfig.experimental = {};\n }\n\n Object.assign(nextConfig.experimental, {\n outputFileTracingIncludes: {\n ...(existingTracing || {}),\n ...tracingConfig,\n },\n });\n } else {\n // For Next.js 15+, add outputFileTracingIncludes at root\n const existingTracing = nextConfig.outputFileTracingIncludes ?? {};\n\n Object.assign(nextConfig, {\n outputFileTracingIncludes: {\n ...existingTracing,\n ...tracingConfig,\n },\n });\n }\n\n return nextConfig;\n}\n\n/**\n * Wraps Next.js config to enable Peam content extraction during build.\n *\n * @example\n * ```typescript\n * // next.config.ts\n * import withPeam from '@peam-ai/next';\n *\n * export default withPeam()({\n * // your Next.js config\n * });\n * ```\n *\n * Or with `require()`:\n * ```javascript\n * // next.config.js\n * const withPeam = require('@peam-ai/next');\n *\n * module.exports = withPeam()({\n * // your Next.js config\n * });\n * ```\n */\nexport function withPeam(peamConfig?: PeamConfig) {\n return function (nextConfig: NextConfig = {}): NextConfig {\n setNextConfig(nextConfig, peamConfig);\n addStubIndex();\n\n let updatedNextConfig: NextConfig = { ...nextConfig };\n updatedNextConfig = addAdapter(updatedNextConfig);\n updatedNextConfig = addOutputFileTracing(updatedNextConfig);\n\n return updatedNextConfig;\n };\n}\n\nexport default withPeam;\n","import { withPeam } from './withPeam';\nexport default withPeam;\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/config.ts","../src/withPeam.ts","../src/index.ts"],"names":["createSto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import { NextConfig } from 'next';\nimport { createStoreFromConfig, type SearchIndexStore, type SearchStoreConfig } from 'peam/search';\n\nexport interface PeamConfig {\n /**\n * Search store configuration\n * @default { type: 'fileBased', config: { indexPath: '.peam/index.json' } }\n */\n searchStore?: SearchStoreConfig;\n\n /**\n * Path to a custom robots.txt file or false to disable robots.txt filtering\n * If undefined, the adapter will look for static or dynamic robots.txt files in standard locations\n * @example 'custom/robots.txt' or 'config/production-robots.txt'\n * @default undefined\n */\n robotsTxt?: string | boolean;\n\n /**\n * Array of wildcard patterns to exclude from indexing\n * Supports * (matches any characters except /), ** (matches any characters including /), and ? (single character)\n * @example ['/admin/**', '/api/*', '/private-*']\n * @default []\n */\n exclude?: string[];\n}\n\nexport type ResolvedPeamAdapterConfig = Required<Omit<PeamConfig, 'robotsTxt'>> & {\n robotsTxt?: string | boolean;\n searchIndexStore: SearchIndexStore;\n};\n\nconst defaultConfig = {\n searchStore: {\n type: 'fileBased' as const,\n config: { indexPath: '.peam/index.json' },\n },\n robotsTxt: undefined,\n exclude: [],\n} satisfies PeamConfig;\n\nexport function setNextConfig(nextConfig: NextConfig, peamConfig?: PeamConfig): void {\n const envVars = {\n PEAM_SEARCH_STORE: JSON.stringify(peamConfig?.searchStore ? peamConfig.searchStore : defaultConfig.searchStore),\n PEAM_EXCLUDE: JSON.stringify(peamConfig?.exclude ? peamConfig.exclude : defaultConfig.exclude),\n PEAM_ROBOTS_TXT: '',\n };\n\n if (peamConfig?.robotsTxt !== undefined) {\n envVars.PEAM_ROBOTS_TXT = String(peamConfig.robotsTxt);\n }\n\n // Set build time vars\n Object.assign(process.env, envVars);\n\n // Set runtime vars\n nextConfig.env = {\n ...nextConfig.env,\n ...envVars,\n };\n}\n\nexport const getConfig = (): ResolvedPeamAdapterConfig => {\n if (!process.env.PEAM_SEARCH_STORE) {\n throw new Error(\n 'Peam configuration not found. Make sure withPeam() is properly configured in your next.config file.'\n );\n }\n\n const searchStoreConfig: SearchStoreConfig = JSON.parse(process.env.PEAM_SEARCH_STORE);\n\n const resolvedConfig = {\n searchStore: searchStoreConfig,\n searchIndexStore: createStoreFromConfig(searchStoreConfig),\n robotsTxt: parseRobotsTxtEnv(process.env.PEAM_ROBOTS_TXT),\n exclude: process.env.PEAM_EXCLUDE ? JSON.parse(process.env.PEAM_EXCLUDE) : [],\n };\n\n return resolvedConfig;\n};\n\nfunction parseRobotsTxtEnv(value: string | undefined): string | boolean | undefined {\n if (value === undefined || value === '') return undefined;\n if (value === 'false') return false;\n if (value === 'true') return true;\n return value;\n}\n","import type { NextConfig } from 'next';\nimport { createRequire } from 'node:module';\nimport * as path from 'path';\nimport { loggers } from 'peam/logger';\nimport { getConfig, PeamConfig, setNextConfig } from './config';\n\nconst require = createRequire(process.cwd() + '/');\nconst log = loggers.next;\nconst isProd = process.env.NODE_ENV === 'production';\n\nfunction getNextVersion(): { major: number; minor: number } | undefined {\n try {\n const [major, minor] = require('next/package.json').version.split('.', 2).map(Number);\n\n return { major, minor };\n } catch (error) {\n log.error('Could not resolve Next.js version.', error);\n return undefined;\n }\n}\n\nfunction addStubIndex() {\n try {\n if (!isProd) {\n return;\n }\n\n const config = getConfig();\n\n if (config.searchStore?.type !== 'fileBased') {\n return;\n }\n\n const stubData = { keys: [], data: {} };\n config.searchIndexStore.exportSync?.(stubData, { override: false });\n } catch (error) {\n log.error('Failed to create stub index:', error);\n }\n}\n\nfunction addAdapter(config: NextConfig): NextConfig {\n const nextVersion = getNextVersion();\n\n if (!nextVersion || nextVersion.major < 15) {\n log.warn(\n 'Peam adapter requires Next.js 15 or higher, skipping adapter configuration. Make sure the postbuild script is set up correctly, See more here: https://peam.ai/docs.'\n );\n return config;\n }\n\n return {\n ...config,\n experimental: {\n ...config.experimental,\n adapterPath: require.resolve(path.join(__dirname, 'peam.adapter.js')),\n },\n };\n}\n\nfunction addOutputFileTracing(nextConfig: NextConfig): NextConfig {\n const peamConfig = getConfig();\n\n if (peamConfig.searchStore?.type !== 'fileBased') {\n return nextConfig;\n }\n\n nextConfig = { ...nextConfig };\n\n const storeConfig = peamConfig.searchStore.config;\n const indexPath = storeConfig.indexPath ?? '.peam/index.json';\n const indexDir = path.dirname(indexPath);\n const tracingConfig = {\n '/api/peam': [`./${indexDir}/**/*`],\n };\n\n const nextVersion = getNextVersion();\n\n if (!nextVersion) {\n log.warn(\n 'Could not determine Next.js version. Adding outputFileTracingIncludes to both experimental and root config.'\n );\n\n // Add to experimental (for Next.js 14.x)\n const existingExperimentalTracing =\n typeof nextConfig.experimental === 'object' && 'outputFileTracingIncludes' in nextConfig.experimental\n ? nextConfig.experimental.outputFileTracingIncludes\n : undefined;\n\n if (!nextConfig.experimental) {\n nextConfig.experimental = {};\n }\n\n Object.assign(nextConfig.experimental, {\n outputFileTracingIncludes: {\n ...(existingExperimentalTracing || {}),\n ...tracingConfig,\n },\n });\n\n // Add to root (for Next.js 15+)\n const existingRootTracing = nextConfig.outputFileTracingIncludes ?? {};\n\n Object.assign(nextConfig, {\n outputFileTracingIncludes: {\n ...existingRootTracing,\n ...tracingConfig,\n },\n });\n } else if (nextVersion.major < 15) {\n // For Next.js 14.x, add outputFileTracingIncludes in experimental\n const existingTracing =\n typeof nextConfig.experimental === 'object' && 'outputFileTracingIncludes' in nextConfig.experimental\n ? nextConfig.experimental.outputFileTracingIncludes\n : undefined;\n\n if (!nextConfig.experimental) {\n nextConfig.experimental = {};\n }\n\n Object.assign(nextConfig.experimental, {\n outputFileTracingIncludes: {\n ...(existingTracing || {}),\n ...tracingConfig,\n },\n });\n } else {\n // For Next.js 15+, add outputFileTracingIncludes at root\n const existingTracing = nextConfig.outputFileTracingIncludes ?? {};\n\n Object.assign(nextConfig, {\n outputFileTracingIncludes: {\n ...existingTracing,\n ...tracingConfig,\n },\n });\n }\n\n return nextConfig;\n}\n\n/**\n * Wraps Next.js config to enable Peam content extraction during build.\n *\n * @example\n * ```typescript\n * // next.config.ts\n * import withPeam from '@peam-ai/next';\n *\n * export default withPeam()({\n * // your Next.js config\n * });\n * ```\n *\n * Or with `require()`:\n * ```javascript\n * // next.config.js\n * const withPeam = require('@peam-ai/next');\n *\n * module.exports = withPeam()({\n * // your Next.js config\n * });\n * ```\n */\nexport function withPeam(peamConfig?: PeamConfig) {\n return function (nextConfig: NextConfig = {}): NextConfig {\n setNextConfig(nextConfig, peamConfig);\n addStubIndex();\n\n let updatedNextConfig: NextConfig = { ...nextConfig };\n updatedNextConfig = addAdapter(updatedNextConfig);\n updatedNextConfig = addOutputFileTracing(updatedNextConfig);\n\n return updatedNextConfig;\n };\n}\n\nexport default withPeam;\n","import { withPeam } from './withPeam';\nexport default withPeam;\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,28 +1,24 @@
|
|
|
1
1
|
import { createRequire } from 'module';
|
|
2
2
|
import * as path from 'path';
|
|
3
3
|
import { loggers } from 'peam/logger';
|
|
4
|
-
import {
|
|
4
|
+
import { createStoreFromConfig } from 'peam/search';
|
|
5
5
|
|
|
6
6
|
// src/withPeam.ts
|
|
7
7
|
var defaultConfig = {
|
|
8
|
-
|
|
8
|
+
searchStore: {
|
|
9
9
|
type: "fileBased",
|
|
10
10
|
config: { indexPath: ".peam/index.json" }
|
|
11
11
|
},
|
|
12
|
-
respectRobotsTxt: true,
|
|
13
12
|
exclude: []
|
|
14
13
|
};
|
|
15
14
|
function setNextConfig(nextConfig, peamConfig) {
|
|
16
|
-
var _a, _b, _c, _d, _e, _f;
|
|
17
15
|
const envVars = {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
PEAM_EXCLUDE: (_f = JSON.stringify(peamConfig == null ? void 0 : peamConfig.exclude)) != null ? _f : JSON.stringify(defaultConfig.exclude),
|
|
22
|
-
PEAM_ROBOTS_TXT_PATH: ""
|
|
16
|
+
PEAM_SEARCH_STORE: JSON.stringify((peamConfig == null ? void 0 : peamConfig.searchStore) ? peamConfig.searchStore : defaultConfig.searchStore),
|
|
17
|
+
PEAM_EXCLUDE: JSON.stringify((peamConfig == null ? void 0 : peamConfig.exclude) ? peamConfig.exclude : defaultConfig.exclude),
|
|
18
|
+
PEAM_ROBOTS_TXT: ""
|
|
23
19
|
};
|
|
24
|
-
if (peamConfig == null ? void 0 : peamConfig.
|
|
25
|
-
envVars.
|
|
20
|
+
if ((peamConfig == null ? void 0 : peamConfig.robotsTxt) !== void 0) {
|
|
21
|
+
envVars.PEAM_ROBOTS_TXT = String(peamConfig.robotsTxt);
|
|
26
22
|
}
|
|
27
23
|
Object.assign(process.env, envVars);
|
|
28
24
|
nextConfig.env = {
|
|
@@ -31,24 +27,26 @@ function setNextConfig(nextConfig, peamConfig) {
|
|
|
31
27
|
};
|
|
32
28
|
}
|
|
33
29
|
var getConfig = () => {
|
|
34
|
-
if (!process.env.
|
|
30
|
+
if (!process.env.PEAM_SEARCH_STORE) {
|
|
35
31
|
throw new Error(
|
|
36
32
|
"Peam configuration not found. Make sure withPeam() is properly configured in your next.config file."
|
|
37
33
|
);
|
|
38
34
|
}
|
|
39
|
-
const
|
|
40
|
-
type: process.env.PEAM_SEARCH_EXPORTER_TYPE,
|
|
41
|
-
config: JSON.parse(process.env.PEAM_SEARCH_EXPORTER_CONFIG)
|
|
42
|
-
};
|
|
35
|
+
const searchStoreConfig = JSON.parse(process.env.PEAM_SEARCH_STORE);
|
|
43
36
|
const resolvedConfig = {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
robotsTxtPath: process.env.PEAM_ROBOTS_TXT_PATH || void 0,
|
|
37
|
+
searchStore: searchStoreConfig,
|
|
38
|
+
searchIndexStore: createStoreFromConfig(searchStoreConfig),
|
|
39
|
+
robotsTxt: parseRobotsTxtEnv(process.env.PEAM_ROBOTS_TXT),
|
|
48
40
|
exclude: process.env.PEAM_EXCLUDE ? JSON.parse(process.env.PEAM_EXCLUDE) : []
|
|
49
41
|
};
|
|
50
42
|
return resolvedConfig;
|
|
51
43
|
};
|
|
44
|
+
function parseRobotsTxtEnv(value) {
|
|
45
|
+
if (value === void 0 || value === "") return void 0;
|
|
46
|
+
if (value === "false") return false;
|
|
47
|
+
if (value === "true") return true;
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
52
50
|
|
|
53
51
|
// src/withPeam.ts
|
|
54
52
|
var require2 = createRequire(process.cwd() + "/");
|
|
@@ -70,20 +68,20 @@ function addStubIndex() {
|
|
|
70
68
|
return;
|
|
71
69
|
}
|
|
72
70
|
const config = getConfig();
|
|
73
|
-
if (((_a = config.
|
|
71
|
+
if (((_a = config.searchStore) == null ? void 0 : _a.type) !== "fileBased") {
|
|
74
72
|
return;
|
|
75
73
|
}
|
|
76
74
|
const stubData = { keys: [], data: {} };
|
|
77
|
-
(_c = (_b = config.
|
|
75
|
+
(_c = (_b = config.searchIndexStore).exportSync) == null ? void 0 : _c.call(_b, stubData, { override: false });
|
|
78
76
|
} catch (error) {
|
|
79
77
|
log.error("Failed to create stub index:", error);
|
|
80
78
|
}
|
|
81
79
|
}
|
|
82
80
|
function addAdapter(config) {
|
|
83
81
|
const nextVersion = getNextVersion();
|
|
84
|
-
if (!nextVersion || nextVersion.major <
|
|
82
|
+
if (!nextVersion || nextVersion.major < 15) {
|
|
85
83
|
log.warn(
|
|
86
|
-
"Peam adapter requires Next.js
|
|
84
|
+
"Peam adapter requires Next.js 15 or higher, skipping adapter configuration. Make sure the postbuild script is set up correctly, See more here: https://peam.ai/docs."
|
|
87
85
|
);
|
|
88
86
|
return config;
|
|
89
87
|
}
|
|
@@ -96,14 +94,15 @@ function addAdapter(config) {
|
|
|
96
94
|
};
|
|
97
95
|
}
|
|
98
96
|
function addOutputFileTracing(nextConfig) {
|
|
99
|
-
var _a, _b, _c;
|
|
97
|
+
var _a, _b, _c, _d;
|
|
100
98
|
const peamConfig = getConfig();
|
|
101
|
-
if (((_a = peamConfig.
|
|
99
|
+
if (((_a = peamConfig.searchStore) == null ? void 0 : _a.type) !== "fileBased") {
|
|
102
100
|
return nextConfig;
|
|
103
101
|
}
|
|
104
102
|
nextConfig = { ...nextConfig };
|
|
105
|
-
const
|
|
106
|
-
const
|
|
103
|
+
const storeConfig = peamConfig.searchStore.config;
|
|
104
|
+
const indexPath = (_b = storeConfig.indexPath) != null ? _b : ".peam/index.json";
|
|
105
|
+
const indexDir = path.dirname(indexPath);
|
|
107
106
|
const tracingConfig = {
|
|
108
107
|
"/api/peam": [`./${indexDir}/**/*`]
|
|
109
108
|
};
|
|
@@ -122,7 +121,7 @@ function addOutputFileTracing(nextConfig) {
|
|
|
122
121
|
...tracingConfig
|
|
123
122
|
}
|
|
124
123
|
});
|
|
125
|
-
const existingRootTracing = (
|
|
124
|
+
const existingRootTracing = (_c = nextConfig.outputFileTracingIncludes) != null ? _c : {};
|
|
126
125
|
Object.assign(nextConfig, {
|
|
127
126
|
outputFileTracingIncludes: {
|
|
128
127
|
...existingRootTracing,
|
|
@@ -141,7 +140,7 @@ function addOutputFileTracing(nextConfig) {
|
|
|
141
140
|
}
|
|
142
141
|
});
|
|
143
142
|
} else {
|
|
144
|
-
const existingTracing = (
|
|
143
|
+
const existingTracing = (_d = nextConfig.outputFileTracingIncludes) != null ? _d : {};
|
|
145
144
|
Object.assign(nextConfig, {
|
|
146
145
|
outputFileTracingIncludes: {
|
|
147
146
|
...existingTracing,
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/config.ts","../src/withPeam.ts","../src/index.ts"],"names":["require"],"mappings":";;;;;;AAmCA,IAAM,aAAA,GAAgB;AAAA,EACpB,cAAA,EAAgB;AAAA,IACd,IAAA,EAAM,WAAA;AAAA,IACN,MAAA,EAAQ,EAAE,SAAA,EAAW,kBAAA;AAAmB,GAC1C;AAAA,EACA,gBAAA,EAAkB,IAAA;AAAA,EAElB,SAAS;AACX,CAAA;AAEO,SAAS,aAAA,CAAc,YAAwB,UAAA,EAA+B;AA7CrF,EAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA;AA8CE,EAAA,MAAM,O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O,aAAA,GAAQ","file":"index.mjs","sourcesContent":["import { NextConfig } from 'next';\nimport { createExporterFromConfig, type SearchExporterConfig, type SearchIndexExporter } from 'peam/search';\n\nexport interface PeamConfig {\n /**\n * Search exporter configuration\n * @default { type: 'fileBased', config: { indexPath: '.peam/index.json' } }\n */\n searchExporter?: SearchExporterConfig;\n /**\n * Whether to respect robots.txt rules when indexing pages\n * @default true\n */\n respectRobotsTxt?: boolean;\n /**\n * Path to a custom robots.txt file relative to the project root\n * If not specified, the adapter will look for static or dynamic robots.txt files in standard locations\n * @example 'custom/robots.txt' or 'config/production-robots.txt'\n * @default undefined\n */\n robotsTxtPath?: string;\n /**\n * Array of wildcard patterns to exclude from indexing\n * Supports * (matches any characters except /), ** (matches any characters including /), and ? (single character)\n * @example ['/admin/**', '/api/*', '/private-*']\n * @default []\n */\n exclude?: string[];\n}\n\nexport type ResolvedPeamAdapterConfig = Required<Omit<PeamConfig, 'robotsTxtPath'>> & {\n robotsTxtPath?: string;\n searchIndexExporter: SearchIndexExporter;\n};\n\nconst defaultConfig = {\n searchExporter: {\n type: 'fileBased' as const,\n config: { indexPath: '.peam/index.json' },\n },\n respectRobotsTxt: true,\n robotsTxtPath: undefined,\n exclude: [],\n} satisfies PeamConfig;\n\nexport function setNextConfig(nextConfig: NextConfig, peamConfig?: PeamConfig): void {\n const envVars = {\n PEAM_SEARCH_EXPORTER_TYPE: peamConfig?.searchExporter?.type ?? defaultConfig.searchExporter.type,\n PEAM_SEARCH_EXPORTER_CONFIG:\n JSON.stringify(peamConfig?.searchExporter?.config) ?? JSON.stringify(defaultConfig.searchExporter.config),\n PEAM_RESPECT_ROBOTS_TXT: String(peamConfig?.respectRobotsTxt ?? defaultConfig.respectRobotsTxt),\n PEAM_EXCLUDE: JSON.stringify(peamConfig?.exclude) ?? JSON.stringify(defaultConfig.exclude),\n PEAM_ROBOTS_TXT_PATH: '',\n };\n\n if (peamConfig?.robotsTxtPath) {\n envVars.PEAM_ROBOTS_TXT_PATH = String(peamConfig.robotsTxtPath);\n }\n\n // Set build time vars\n Object.assign(process.env, envVars);\n\n // Set runtime vars\n nextConfig.env = {\n ...nextConfig.env,\n ...envVars,\n };\n}\n\nexport const getConfig = (): ResolvedPeamAdapterConfig => {\n if (!process.env.PEAM_SEARCH_EXPORTER_TYPE || !process.env.PEAM_SEARCH_EXPORTER_CONFIG) {\n throw new Error(\n 'Peam configuration not found. Make sure withPeam() is properly configured in your next.config file.'\n );\n }\n\n const searchExporterConfig: SearchExporterConfig = {\n type: process.env.PEAM_SEARCH_EXPORTER_TYPE as SearchExporterConfig['type'],\n config: JSON.parse(process.env.PEAM_SEARCH_EXPORTER_CONFIG),\n };\n\n const resolvedConfig = {\n searchExporter: searchExporterConfig,\n searchIndexExporter: createExporterFromConfig(searchExporterConfig),\n respectRobotsTxt: process.env.PEAM_RESPECT_ROBOTS_TXT === 'true',\n robotsTxtPath: process.env.PEAM_ROBOTS_TXT_PATH || undefined,\n exclude: process.env.PEAM_EXCLUDE ? JSON.parse(process.env.PEAM_EXCLUDE) : [],\n };\n\n return resolvedConfig;\n};\n","import type { NextConfig } from 'next';\nimport { createRequire } from 'node:module';\nimport * as path from 'path';\nimport { loggers } from 'peam/logger';\nimport { getConfig, PeamConfig, setNextConfig } from './config';\n\nconst require = createRequire(process.cwd() + '/');\nconst log = loggers.next;\nconst isProd = process.env.NODE_ENV === 'production';\n\nfunction getNextVersion(): { major: number; minor: number } | undefined {\n try {\n const [major, minor] = require('next/package.json').version.split('.', 2).map(Number);\n\n return { major, minor };\n } catch (error) {\n log.error('Could not resolve Next.js version.', error);\n return undefined;\n }\n}\n\nfunction addStubIndex() {\n try {\n if (!isProd) {\n return;\n }\n\n const config = getConfig();\n\n if (config.searchExporter?.type !== 'fileBased') {\n return;\n }\n\n const stubData = { keys: [], data: {} };\n config.searchIndexExporter.exportSync?.(stubData, { override: false });\n } catch (error) {\n log.error('Failed to create stub index:', error);\n }\n}\n\nfunction addAdapter(config: NextConfig): NextConfig {\n const nextVersion = getNextVersion();\n\n if (!nextVersion || nextVersion.major < 16) {\n log.warn(\n 'Peam adapter requires Next.js 16 or higher, skipping adapter configuration. Make sure the postbuild script is set up correctly, See more here: https://peam.ai/docs.'\n );\n return config;\n }\n\n return {\n ...config,\n experimental: {\n ...config.experimental,\n adapterPath: require.resolve(path.join(__dirname, 'peam.adapter.js')),\n },\n };\n}\n\nfunction addOutputFileTracing(nextConfig: NextConfig): NextConfig {\n const peamConfig = getConfig();\n\n if (peamConfig.searchExporter?.type !== 'fileBased') {\n return nextConfig;\n }\n\n nextConfig = { ...nextConfig };\n\n const exporterConfig = peamConfig.searchExporter.config;\n const indexDir = path.dirname(exporterConfig.indexPath);\n const tracingConfig = {\n '/api/peam': [`./${indexDir}/**/*`],\n };\n\n const nextVersion = getNextVersion();\n\n if (!nextVersion) {\n log.warn(\n 'Could not determine Next.js version. Adding outputFileTracingIncludes to both experimental and root config.'\n );\n\n // Add to experimental (for Next.js 14.x)\n const existingExperimentalTracing =\n typeof nextConfig.experimental === 'object' && 'outputFileTracingIncludes' in nextConfig.experimental\n ? nextConfig.experimental.outputFileTracingIncludes\n : undefined;\n\n if (!nextConfig.experimental) {\n nextConfig.experimental = {};\n }\n\n Object.assign(nextConfig.experimental, {\n outputFileTracingIncludes: {\n ...(existingExperimentalTracing || {}),\n ...tracingConfig,\n },\n });\n\n // Add to root (for Next.js 15+)\n const existingRootTracing = nextConfig.outputFileTracingIncludes ?? {};\n\n Object.assign(nextConfig, {\n outputFileTracingIncludes: {\n ...existingRootTracing,\n ...tracingConfig,\n },\n });\n } else if (nextVersion.major < 15) {\n // For Next.js 14.x, add outputFileTracingIncludes in experimental\n const existingTracing =\n typeof nextConfig.experimental === 'object' && 'outputFileTracingIncludes' in nextConfig.experimental\n ? nextConfig.experimental.outputFileTracingIncludes\n : undefined;\n\n if (!nextConfig.experimental) {\n nextConfig.experimental = {};\n }\n\n Object.assign(nextConfig.experimental, {\n outputFileTracingIncludes: {\n ...(existingTracing || {}),\n ...tracingConfig,\n },\n });\n } else {\n // For Next.js 15+, add outputFileTracingIncludes at root\n const existingTracing = nextConfig.outputFileTracingIncludes ?? {};\n\n Object.assign(nextConfig, {\n outputFileTracingIncludes: {\n ...existingTracing,\n ...tracingConfig,\n },\n });\n }\n\n return nextConfig;\n}\n\n/**\n * Wraps Next.js config to enable Peam content extraction during build.\n *\n * @example\n * ```typescript\n * // next.config.ts\n * import withPeam from '@peam-ai/next';\n *\n * export default withPeam()({\n * // your Next.js config\n * });\n * ```\n *\n * Or with `require()`:\n * ```javascript\n * // next.config.js\n * const withPeam = require('@peam-ai/next');\n *\n * module.exports = withPeam()({\n * // your Next.js config\n * });\n * ```\n */\nexport function withPeam(peamConfig?: PeamConfig) {\n return function (nextConfig: NextConfig = {}): NextConfig {\n setNextConfig(nextConfig, peamConfig);\n addStubIndex();\n\n let updatedNextConfig: NextConfig = { ...nextConfig };\n updatedNextConfig = addAdapter(updatedNextConfig);\n updatedNextConfig = addOutputFileTracing(updatedNextConfig);\n\n return updatedNextConfig;\n };\n}\n\nexport default withPeam;\n","import { withPeam } from './withPeam';\nexport default withPeam;\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/config.ts","../src/withPeam.ts","../src/index.ts"],"names":["require"],"mappings":";;;;;;AAgCA,IAAM,aAAA,GAAgB;AAAA,EACpB,WAAA,EAAa;AAAA,IACX,IAAA,EAAM,WAAA;AAAA,IACN,MAAA,EAAQ,EAAE,SAAA,EAAW,kBAAA;AAAmB,GAC1C;AAAA,EAEA,SAAS;AACX,CAAA;AAEO,SAAS,aAAA,CAAc,YAAwB,UAAA,EAA+B;AACnF,EAAA,MAAM,OAAA,GAAU;AAAA,IACd,iBAAA,EAAmB,KAAK,SAAA,CAAA,CAAU,UAAA,IAAA,IAAA,GAAA,MAAA,GAAA,UAAA,CAAY,eAAc,UAAA,CAAW,WAAA,GAAc,cAAc,WAAW,CAAA;AAAA,IAC9G,YAAA,EAAc,KAAK,SAAA,CAAA,CAAU,UAA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;AACL,KACD,CAAA;AAAA,EACH,CAAA,MAAO;AAEL,IAAA,MAAM,eAAA,GAAA,CAAkB,EAAA,GAAA,UAAA,CAAW,yBAAA,KAAX,IAAA,GAAA,EAAA,GAAwC,EAAC;AAEjE,IAAA,MAAA,CAAO,OAAO,UAAA,EAAY;AAAA,MACxB,yBAAA,EAA2B;AAAA,QACzB,GAAG,eAAA;AAAA,QACH,GAAG;AAAA;AACL,KACD,CAAA;AAAA,EACH;AAEA,EAAA,OAAO,UAAA;AACT;AAyBO,SAAS,SAAS,UAAA,EAAyB;AAChD,EAAA,OAAO,SAAU,UAAA,GAAyB,EAAC,EAAe;AACxD,IAAA,aAAA,CAAc,YAAY,UAAU,CAAA;AACpC,IAAA,YAAA,EAAa;AAEb,IAAA,IAAI,iBAAA,GAAgC,EAAE,GAAG,UAAA,EAAW;AACpD,IAAA,iBAAA,GAAoB,WAAW,iBAAiB,CAAA;AAChD,IAAA,iBAAA,GAAoB,qBAAqB,iBAAiB,CAAA;AAE1D,IAAA,OAAO,iBAAA;AAAA,EACT,CAAA;AACF;;;AC7KA,IAAO,aAAA,GAAQ","file":"index.mjs","sourcesContent":["import { NextConfig } from 'next';\nimport { createStoreFromConfig, type SearchIndexStore, type SearchStoreConfig } from 'peam/search';\n\nexport interface PeamConfig {\n /**\n * Search store configuration\n * @default { type: 'fileBased', config: { indexPath: '.peam/index.json' } }\n */\n searchStore?: SearchStoreConfig;\n\n /**\n * Path to a custom robots.txt file or false to disable robots.txt filtering\n * If undefined, the adapter will look for static or dynamic robots.txt files in standard locations\n * @example 'custom/robots.txt' or 'config/production-robots.txt'\n * @default undefined\n */\n robotsTxt?: string | boolean;\n\n /**\n * Array of wildcard patterns to exclude from indexing\n * Supports * (matches any characters except /), ** (matches any characters including /), and ? (single character)\n * @example ['/admin/**', '/api/*', '/private-*']\n * @default []\n */\n exclude?: string[];\n}\n\nexport type ResolvedPeamAdapterConfig = Required<Omit<PeamConfig, 'robotsTxt'>> & {\n robotsTxt?: string | boolean;\n searchIndexStore: SearchIndexStore;\n};\n\nconst defaultConfig = {\n searchStore: {\n type: 'fileBased' as const,\n config: { indexPath: '.peam/index.json' },\n },\n robotsTxt: undefined,\n exclude: [],\n} satisfies PeamConfig;\n\nexport function setNextConfig(nextConfig: NextConfig, peamConfig?: PeamConfig): void {\n const envVars = {\n PEAM_SEARCH_STORE: JSON.stringify(peamConfig?.searchStore ? peamConfig.searchStore : defaultConfig.searchStore),\n PEAM_EXCLUDE: JSON.stringify(peamConfig?.exclude ? peamConfig.exclude : defaultConfig.exclude),\n PEAM_ROBOTS_TXT: '',\n };\n\n if (peamConfig?.robotsTxt !== undefined) {\n envVars.PEAM_ROBOTS_TXT = String(peamConfig.robotsTxt);\n }\n\n // Set build time vars\n Object.assign(process.env, envVars);\n\n // Set runtime vars\n nextConfig.env = {\n ...nextConfig.env,\n ...envVars,\n };\n}\n\nexport const getConfig = (): ResolvedPeamAdapterConfig => {\n if (!process.env.PEAM_SEARCH_STORE) {\n throw new Error(\n 'Peam configuration not found. Make sure withPeam() is properly configured in your next.config file.'\n );\n }\n\n const searchStoreConfig: SearchStoreConfig = JSON.parse(process.env.PEAM_SEARCH_STORE);\n\n const resolvedConfig = {\n searchStore: searchStoreConfig,\n searchIndexStore: createStoreFromConfig(searchStoreConfig),\n robotsTxt: parseRobotsTxtEnv(process.env.PEAM_ROBOTS_TXT),\n exclude: process.env.PEAM_EXCLUDE ? JSON.parse(process.env.PEAM_EXCLUDE) : [],\n };\n\n return resolvedConfig;\n};\n\nfunction parseRobotsTxtEnv(value: string | undefined): string | boolean | undefined {\n if (value === undefined || value === '') return undefined;\n if (value === 'false') return false;\n if (value === 'true') return true;\n return value;\n}\n","import type { NextConfig } from 'next';\nimport { createRequire } from 'node:module';\nimport * as path from 'path';\nimport { loggers } from 'peam/logger';\nimport { getConfig, PeamConfig, setNextConfig } from './config';\n\nconst require = createRequire(process.cwd() + '/');\nconst log = loggers.next;\nconst isProd = process.env.NODE_ENV === 'production';\n\nfunction getNextVersion(): { major: number; minor: number } | undefined {\n try {\n const [major, minor] = require('next/package.json').version.split('.', 2).map(Number);\n\n return { major, minor };\n } catch (error) {\n log.error('Could not resolve Next.js version.', error);\n return undefined;\n }\n}\n\nfunction addStubIndex() {\n try {\n if (!isProd) {\n return;\n }\n\n const config = getConfig();\n\n if (config.searchStore?.type !== 'fileBased') {\n return;\n }\n\n const stubData = { keys: [], data: {} };\n config.searchIndexStore.exportSync?.(stubData, { override: false });\n } catch (error) {\n log.error('Failed to create stub index:', error);\n }\n}\n\nfunction addAdapter(config: NextConfig): NextConfig {\n const nextVersion = getNextVersion();\n\n if (!nextVersion || nextVersion.major < 15) {\n log.warn(\n 'Peam adapter requires Next.js 15 or higher, skipping adapter configuration. Make sure the postbuild script is set up correctly, See more here: https://peam.ai/docs.'\n );\n return config;\n }\n\n return {\n ...config,\n experimental: {\n ...config.experimental,\n adapterPath: require.resolve(path.join(__dirname, 'peam.adapter.js')),\n },\n };\n}\n\nfunction addOutputFileTracing(nextConfig: NextConfig): NextConfig {\n const peamConfig = getConfig();\n\n if (peamConfig.searchStore?.type !== 'fileBased') {\n return nextConfig;\n }\n\n nextConfig = { ...nextConfig };\n\n const storeConfig = peamConfig.searchStore.config;\n const indexPath = storeConfig.indexPath ?? '.peam/index.json';\n const indexDir = path.dirname(indexPath);\n const tracingConfig = {\n '/api/peam': [`./${indexDir}/**/*`],\n };\n\n const nextVersion = getNextVersion();\n\n if (!nextVersion) {\n log.warn(\n 'Could not determine Next.js version. Adding outputFileTracingIncludes to both experimental and root config.'\n );\n\n // Add to experimental (for Next.js 14.x)\n const existingExperimentalTracing =\n typeof nextConfig.experimental === 'object' && 'outputFileTracingIncludes' in nextConfig.experimental\n ? nextConfig.experimental.outputFileTracingIncludes\n : undefined;\n\n if (!nextConfig.experimental) {\n nextConfig.experimental = {};\n }\n\n Object.assign(nextConfig.experimental, {\n outputFileTracingIncludes: {\n ...(existingExperimentalTracing || {}),\n ...tracingConfig,\n },\n });\n\n // Add to root (for Next.js 15+)\n const existingRootTracing = nextConfig.outputFileTracingIncludes ?? {};\n\n Object.assign(nextConfig, {\n outputFileTracingIncludes: {\n ...existingRootTracing,\n ...tracingConfig,\n },\n });\n } else if (nextVersion.major < 15) {\n // For Next.js 14.x, add outputFileTracingIncludes in experimental\n const existingTracing =\n typeof nextConfig.experimental === 'object' && 'outputFileTracingIncludes' in nextConfig.experimental\n ? nextConfig.experimental.outputFileTracingIncludes\n : undefined;\n\n if (!nextConfig.experimental) {\n nextConfig.experimental = {};\n }\n\n Object.assign(nextConfig.experimental, {\n outputFileTracingIncludes: {\n ...(existingTracing || {}),\n ...tracingConfig,\n },\n });\n } else {\n // For Next.js 15+, add outputFileTracingIncludes at root\n const existingTracing = nextConfig.outputFileTracingIncludes ?? {};\n\n Object.assign(nextConfig, {\n outputFileTracingIncludes: {\n ...existingTracing,\n ...tracingConfig,\n },\n });\n }\n\n return nextConfig;\n}\n\n/**\n * Wraps Next.js config to enable Peam content extraction during build.\n *\n * @example\n * ```typescript\n * // next.config.ts\n * import withPeam from '@peam-ai/next';\n *\n * export default withPeam()({\n * // your Next.js config\n * });\n * ```\n *\n * Or with `require()`:\n * ```javascript\n * // next.config.js\n * const withPeam = require('@peam-ai/next');\n *\n * module.exports = withPeam()({\n * // your Next.js config\n * });\n * ```\n */\nexport function withPeam(peamConfig?: PeamConfig) {\n return function (nextConfig: NextConfig = {}): NextConfig {\n setNextConfig(nextConfig, peamConfig);\n addStubIndex();\n\n let updatedNextConfig: NextConfig = { ...nextConfig };\n updatedNextConfig = addAdapter(updatedNextConfig);\n updatedNextConfig = addOutputFileTracing(updatedNextConfig);\n\n return updatedNextConfig;\n };\n}\n\nexport default withPeam;\n","import { withPeam } from './withPeam';\nexport default withPeam;\n"]}
|
package/dist/peam.adapter.js
CHANGED
|
@@ -1,149 +1,79 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var builder = require('peam/builder');
|
|
4
4
|
var logger = require('peam/logger');
|
|
5
|
-
var parser = require('peam/parser');
|
|
6
5
|
var search = require('peam/search');
|
|
7
6
|
|
|
8
7
|
// src/adapter.ts
|
|
9
8
|
var log = logger.loggers.adapter;
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
if ((_a = prerender.fallback) == null ? void 0 : _a.filePath) {
|
|
17
|
-
const content = fs.readFileSync(prerender.fallback.filePath, "utf-8");
|
|
18
|
-
return content;
|
|
19
|
-
}
|
|
20
|
-
} catch (error) {
|
|
21
|
-
log.error("Error extracting robots from prerender:", error);
|
|
22
|
-
}
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
function loadRobotsTxt(projectDir, prerenders, robotsTxtPath) {
|
|
26
|
-
try {
|
|
27
|
-
let robotsContent = null;
|
|
28
|
-
let foundPath = null;
|
|
29
|
-
if (prerenders && prerenders.length > 0) {
|
|
30
|
-
for (const prerender of prerenders) {
|
|
31
|
-
const content = extractRobotsFromPrerender(prerender);
|
|
32
|
-
if (content) {
|
|
33
|
-
log.debug("Found dynamic robots.txt from prerenders");
|
|
34
|
-
robotsContent = content;
|
|
35
|
-
foundPath = prerender.pathname;
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
if (!robotsContent) {
|
|
41
|
-
const searchPaths = ["public/robots.txt", "app/robots.txt", "src/app/robots.txt"];
|
|
42
|
-
const result = parser.loadRobotsTxt(projectDir, searchPaths, robotsTxtPath);
|
|
43
|
-
if (result) {
|
|
44
|
-
log.debug("Loaded robots.txt from:", result.path);
|
|
45
|
-
return result;
|
|
46
|
-
}
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
return {
|
|
50
|
-
parser: parser.createRobotsParser(robotsContent),
|
|
51
|
-
path: foundPath || ""
|
|
52
|
-
};
|
|
53
|
-
} catch (error) {
|
|
54
|
-
log.error("Error loading robots.txt:", error);
|
|
55
|
-
return null;
|
|
9
|
+
function normalizePrerenders(outputs) {
|
|
10
|
+
if ("prerenders" in outputs) {
|
|
11
|
+
return outputs.prerenders.map((prerender) => ({
|
|
12
|
+
pathname: prerender.pathname,
|
|
13
|
+
fallback: prerender.fallback
|
|
14
|
+
}));
|
|
56
15
|
}
|
|
16
|
+
return outputs.map((prerender) => ({
|
|
17
|
+
pathname: prerender.pathname,
|
|
18
|
+
fallback: prerender.fallback
|
|
19
|
+
}));
|
|
57
20
|
}
|
|
58
21
|
function createPeamAdapter(config) {
|
|
59
22
|
return {
|
|
60
23
|
name: "peam-adapter",
|
|
61
24
|
async onBuildComplete(ctx) {
|
|
62
|
-
var _a, _b;
|
|
63
25
|
log.debug("Extracting page content via adapter");
|
|
64
26
|
const outputs = ctx.outputs;
|
|
65
|
-
let prerenders;
|
|
66
|
-
if (Array.isArray(outputs)) {
|
|
67
|
-
prerenders = outputs.filter((output) => output.type === "PRERENDER");
|
|
68
|
-
} else {
|
|
69
|
-
prerenders = outputs.prerenders || [];
|
|
70
|
-
}
|
|
71
|
-
log.debug("Total prerenders:", prerenders.length);
|
|
72
27
|
const projectDir = ctx.projectDir || process.cwd();
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
if (fallbackFilePath == null ? void 0 : fallbackFilePath.endsWith("/.html")) {
|
|
85
|
-
fallbackFilePath = fallbackFilePath.replace("/.html", "/index.html");
|
|
86
|
-
}
|
|
87
|
-
const filterResult = parser.shouldIncludePath(
|
|
88
|
-
pathname,
|
|
89
|
-
(_b = robotsResult == null ? void 0 : robotsResult.parser) != null ? _b : null,
|
|
90
|
-
config.exclude,
|
|
91
|
-
config.respectRobotsTxt
|
|
92
|
-
);
|
|
93
|
-
if (!filterResult.included) {
|
|
94
|
-
if (filterResult.reason === "robots-txt") {
|
|
95
|
-
log.debug("Path excluded by robots.txt:", pathname);
|
|
96
|
-
} else if (filterResult.reason === "exclude-pattern") {
|
|
97
|
-
log.debug("Path excluded by user pattern:", pathname);
|
|
28
|
+
const prerenders = normalizePrerenders(outputs);
|
|
29
|
+
const pipeline = builder.SearchIndexBuilder.fromConfigs(
|
|
30
|
+
[
|
|
31
|
+
{
|
|
32
|
+
type: "prerender",
|
|
33
|
+
config: {
|
|
34
|
+
prerenders,
|
|
35
|
+
projectDir
|
|
36
|
+
}
|
|
98
37
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const html = fs.readFileSync(fallbackFilePath, "utf-8");
|
|
104
|
-
const structuredPage = parser.parseHTML(html);
|
|
105
|
-
if (!structuredPage) {
|
|
106
|
-
log.warn("No content extracted from", pathname);
|
|
107
|
-
continue;
|
|
108
|
-
}
|
|
109
|
-
log.debug("Successfully extracted content from", pathname);
|
|
110
|
-
pages.push({
|
|
111
|
-
path: pathname,
|
|
112
|
-
htmlFile: fallbackFilePath.replace(projectDir + "/", ""),
|
|
113
|
-
structuredPage,
|
|
114
|
-
type: "page"
|
|
115
|
-
});
|
|
116
|
-
} catch (error) {
|
|
117
|
-
log.error("Error processing", pathname, error);
|
|
38
|
+
],
|
|
39
|
+
{
|
|
40
|
+
robotsTxt: config.robotsTxt,
|
|
41
|
+
exclude: config.exclude
|
|
118
42
|
}
|
|
43
|
+
);
|
|
44
|
+
log.debug("Building search index from prerender outputs...");
|
|
45
|
+
const searchIndexData = await pipeline.build(new search.TextBasedSearchEngine());
|
|
46
|
+
if (!searchIndexData) {
|
|
47
|
+
log.warn("No search index data generated");
|
|
48
|
+
return;
|
|
119
49
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
log.debug("Saved search index via exporter");
|
|
124
|
-
log.debug("Extraction complete with total pages:", pages.length);
|
|
50
|
+
await config.searchIndexStore.export(searchIndexData);
|
|
51
|
+
log.debug("Saved search index via store");
|
|
52
|
+
log.debug("Extraction complete with total keys:", searchIndexData.keys.length);
|
|
125
53
|
}
|
|
126
54
|
};
|
|
127
55
|
}
|
|
128
56
|
var getConfig = () => {
|
|
129
|
-
if (!process.env.
|
|
57
|
+
if (!process.env.PEAM_SEARCH_STORE) {
|
|
130
58
|
throw new Error(
|
|
131
59
|
"Peam configuration not found. Make sure withPeam() is properly configured in your next.config file."
|
|
132
60
|
);
|
|
133
61
|
}
|
|
134
|
-
const
|
|
135
|
-
type: process.env.PEAM_SEARCH_EXPORTER_TYPE,
|
|
136
|
-
config: JSON.parse(process.env.PEAM_SEARCH_EXPORTER_CONFIG)
|
|
137
|
-
};
|
|
62
|
+
const searchStoreConfig = JSON.parse(process.env.PEAM_SEARCH_STORE);
|
|
138
63
|
const resolvedConfig = {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
robotsTxtPath: process.env.PEAM_ROBOTS_TXT_PATH || void 0,
|
|
64
|
+
searchStore: searchStoreConfig,
|
|
65
|
+
searchIndexStore: search.createStoreFromConfig(searchStoreConfig),
|
|
66
|
+
robotsTxt: parseRobotsTxtEnv(process.env.PEAM_ROBOTS_TXT),
|
|
143
67
|
exclude: process.env.PEAM_EXCLUDE ? JSON.parse(process.env.PEAM_EXCLUDE) : []
|
|
144
68
|
};
|
|
145
69
|
return resolvedConfig;
|
|
146
70
|
};
|
|
71
|
+
function parseRobotsTxtEnv(value) {
|
|
72
|
+
if (value === void 0 || value === "") return void 0;
|
|
73
|
+
if (value === "false") return false;
|
|
74
|
+
if (value === "true") return true;
|
|
75
|
+
return value;
|
|
76
|
+
}
|
|
147
77
|
|
|
148
78
|
// src/peam.adapter.ts
|
|
149
79
|
var peam_adapter_default = createPeamAdapter(getConfig());
|
package/dist/peam.adapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/adapter.ts","../src/config.ts","../src/peam.adapter.ts"],"names":["loggers","readFileSync","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A,IACjD,IAAA,EAAM,QAAQ,GAAA,CAAI,yBAAA;AAAA,IAClB,MAAA,EAAQ,IAAA,CAAK,KAAA,CAAM,OAAA,CAAQ,IAAI,2BAA2B;AAAA,GAC5D;AAEA,EAAA,MAAM,cAAA,GAAiB;AAAA,IACrB,cAAA,EAAgB,oBAAA;AAAA,IAChB,mBAAA,EAAqBC,gCAAyB,oBAAoB,CAAA;AAAA,IAClE,gBAAA,EAAkB,OAAA,CAAQ,GAAA,CAAI,uBAAA,KAA4B,MAAA;AAAA,IAC1D,aAAA,EAAe,OAAA,CAAQ,GAAA,CAAI,oBAAA,IAAwB,MAAA;AAAA,IACnD,OAAA,EAAS,OAAA,CAAQ,GAAA,CAAI,YAAA,GAAe,IAAA,CAAK,MAAM,OAAA,CAAQ,GAAA,CAAI,YAAY,CAAA,GAAI;AAAC,GAC9E;AAEA,EAAA,OAAO,cAAA;AACT,CAAA;;;ACvFA,IAAO,oBAAA,GAAQ,iBAAA,CAAkB,SAAA,EAAW","file":"peam.adapter.js","sourcesContent":["import { readFileSync } from 'fs';\nimport type { NextAdapter } from 'next';\nimport { loggers } from 'peam/logger';\nimport {\n loadRobotsTxt as baseLoadRobotsTxt,\n createRobotsParser,\n parseHTML,\n shouldIncludePath,\n type RobotsTxtResult,\n type StructuredPage,\n} from 'peam/parser';\nimport { buildSearchIndex } from 'peam/search';\nimport { type ResolvedPeamAdapterConfig } from './config';\n\nconst log = loggers.adapter;\n\ninterface PrerenderOutput {\n pathname: string;\n fallback?: {\n filePath: string;\n };\n}\n\ninterface NextJS15Output extends PrerenderOutput {\n type: string;\n}\n\ninterface NextJS16Outputs {\n prerenders: Array<PrerenderOutput>;\n}\n\nfunction extractRobotsFromPrerender(prerender: PrerenderOutput): string | null {\n try {\n if (prerender.pathname !== '/robots.txt') {\n return null;\n }\n\n if (prerender.fallback?.filePath) {\n const content = readFileSync(prerender.fallback.filePath, 'utf-8');\n return content;\n }\n } catch (error) {\n log.error('Error extracting robots from prerender:', error);\n }\n\n return null;\n}\n\nfunction loadRobotsTxt(\n projectDir: string,\n prerenders: PrerenderOutput[],\n robotsTxtPath?: string\n): RobotsTxtResult | null {\n try {\n let robotsContent: string | null = null;\n let foundPath: string | null = null;\n\n if (prerenders && prerenders.length > 0) {\n for (const prerender of prerenders) {\n const content = extractRobotsFromPrerender(prerender);\n if (content) {\n log.debug('Found dynamic robots.txt from prerenders');\n robotsContent = content;\n foundPath = prerender.pathname;\n break;\n }\n }\n }\n\n if (!robotsContent) {\n const searchPaths = ['public/robots.txt', 'app/robots.txt', 'src/app/robots.txt'];\n const result = baseLoadRobotsTxt(projectDir, searchPaths, robotsTxtPath);\n if (result) {\n log.debug('Loaded robots.txt from:', result.path);\n return result;\n }\n return null;\n }\n\n return {\n parser: createRobotsParser(robotsContent),\n path: foundPath || '',\n };\n } catch (error) {\n log.error('Error loading robots.txt:', error);\n return null;\n }\n}\n\nexport function createPeamAdapter(config: ResolvedPeamAdapterConfig): NextAdapter {\n return {\n name: 'peam-adapter',\n\n async onBuildComplete(ctx) {\n log.debug('Extracting page content via adapter');\n\n const outputs = ctx.outputs as NextJS15Output[] | NextJS16Outputs;\n let prerenders: PrerenderOutput[];\n\n if (Array.isArray(outputs)) {\n prerenders = outputs.filter((output: NextJS15Output) => output.type === 'PRERENDER');\n } else {\n prerenders = outputs.prerenders || [];\n }\n\n log.debug('Total prerenders:', prerenders.length);\n\n const projectDir = ctx.projectDir || process.cwd();\n\n const robotsResult = config.respectRobotsTxt ? loadRobotsTxt(projectDir, prerenders, config.robotsTxtPath) : null;\n\n if (robotsResult) {\n log.debug('Using robots.txt from:', robotsResult.path);\n }\n\n const pages: Array<{\n path: string;\n htmlFile: string;\n structuredPage: StructuredPage;\n type: string;\n runtime?: string;\n }> = [];\n\n for (const prerender of prerenders) {\n const pathname = prerender.pathname;\n let fallbackFilePath = prerender.fallback?.filePath;\n\n if (!fallbackFilePath) {\n continue;\n }\n\n // Fix for Next.js 15\n if (fallbackFilePath?.endsWith('/.html')) {\n fallbackFilePath = fallbackFilePath.replace('/.html', '/index.html');\n }\n\n const filterResult = shouldIncludePath(\n pathname,\n robotsResult?.parser ?? null,\n config.exclude,\n config.respectRobotsTxt\n );\n\n if (!filterResult.included) {\n if (filterResult.reason === 'robots-txt') {\n log.debug('Path excluded by robots.txt:', pathname);\n } else if (filterResult.reason === 'exclude-pattern') {\n log.debug('Path excluded by user pattern:', pathname);\n }\n continue;\n }\n\n try {\n log.debug('Reading HTML from:', fallbackFilePath);\n\n const html = readFileSync(fallbackFilePath, 'utf-8');\n const structuredPage = parseHTML(html);\n\n if (!structuredPage) {\n log.warn('No content extracted from', pathname);\n continue;\n }\n\n log.debug('Successfully extracted content from', pathname);\n pages.push({\n path: pathname,\n htmlFile: fallbackFilePath.replace(projectDir + '/', ''),\n structuredPage,\n type: 'page',\n });\n } catch (error) {\n log.error('Error processing', pathname, error);\n }\n }\n\n log.debug('Creating search index...');\n const searchIndexData = await buildSearchIndex(pages);\n\n // Use the exporter to save the search index\n await config.searchIndexExporter.export(searchIndexData);\n\n log.debug('Saved search index via exporter');\n log.debug('Extraction complete with total pages:', pages.length);\n },\n };\n}\n","import { NextConfig } from 'next';\nimport { createExporterFromConfig, type SearchExporterConfig, type SearchIndexExporter } from 'peam/search';\n\nexport interface PeamConfig {\n /**\n * Search exporter configuration\n * @default { type: 'fileBased', config: { indexPath: '.peam/index.json' } }\n */\n searchExporter?: SearchExporterConfig;\n /**\n * Whether to respect robots.txt rules when indexing pages\n * @default true\n */\n respectRobotsTxt?: boolean;\n /**\n * Path to a custom robots.txt file relative to the project root\n * If not specified, the adapter will look for static or dynamic robots.txt files in standard locations\n * @example 'custom/robots.txt' or 'config/production-robots.txt'\n * @default undefined\n */\n robotsTxtPath?: string;\n /**\n * Array of wildcard patterns to exclude from indexing\n * Supports * (matches any characters except /), ** (matches any characters including /), and ? (single character)\n * @example ['/admin/**', '/api/*', '/private-*']\n * @default []\n */\n exclude?: string[];\n}\n\nexport type ResolvedPeamAdapterConfig = Required<Omit<PeamConfig, 'robotsTxtPath'>> & {\n robotsTxtPath?: string;\n searchIndexExporter: SearchIndexExporter;\n};\n\nconst defaultConfig = {\n searchExporter: {\n type: 'fileBased' as const,\n config: { indexPath: '.peam/index.json' },\n },\n respectRobotsTxt: true,\n robotsTxtPath: undefined,\n exclude: [],\n} satisfies PeamConfig;\n\nexport function setNextConfig(nextConfig: NextConfig, peamConfig?: PeamConfig): void {\n const envVars = {\n PEAM_SEARCH_EXPORTER_TYPE: peamConfig?.searchExporter?.type ?? defaultConfig.searchExporter.type,\n PEAM_SEARCH_EXPORTER_CONFIG:\n JSON.stringify(peamConfig?.searchExporter?.config) ?? JSON.stringify(defaultConfig.searchExporter.config),\n PEAM_RESPECT_ROBOTS_TXT: String(peamConfig?.respectRobotsTxt ?? defaultConfig.respectRobotsTxt),\n PEAM_EXCLUDE: JSON.stringify(peamConfig?.exclude) ?? JSON.stringify(defaultConfig.exclude),\n PEAM_ROBOTS_TXT_PATH: '',\n };\n\n if (peamConfig?.robotsTxtPath) {\n envVars.PEAM_ROBOTS_TXT_PATH = String(peamConfig.robotsTxtPath);\n }\n\n // Set build time vars\n Object.assign(process.env, envVars);\n\n // Set runtime vars\n nextConfig.env = {\n ...nextConfig.env,\n ...envVars,\n };\n}\n\nexport const getConfig = (): ResolvedPeamAdapterConfig => {\n if (!process.env.PEAM_SEARCH_EXPORTER_TYPE || !process.env.PEAM_SEARCH_EXPORTER_CONFIG) {\n throw new Error(\n 'Peam configuration not found. Make sure withPeam() is properly configured in your next.config file.'\n );\n }\n\n const searchExporterConfig: SearchExporterConfig = {\n type: process.env.PEAM_SEARCH_EXPORTER_TYPE as SearchExporterConfig['type'],\n config: JSON.parse(process.env.PEAM_SEARCH_EXPORTER_CONFIG),\n };\n\n const resolvedConfig = {\n searchExporter: searchExporterConfig,\n searchIndexExporter: createExporterFromConfig(searchExporterConfig),\n respectRobotsTxt: process.env.PEAM_RESPECT_ROBOTS_TXT === 'true',\n robotsTxtPath: process.env.PEAM_ROBOTS_TXT_PATH || undefined,\n exclude: process.env.PEAM_EXCLUDE ? JSON.parse(process.env.PEAM_EXCLUDE) : [],\n };\n\n return resolvedConfig;\n};\n","import { createPeamAdapter } from './adapter';\nimport { getConfig } from './config';\n\nexport default createPeamAdapter(getConfig());\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/adapter.ts","../src/config.ts","../src/peam.adapter.ts"],"names":["loggers","SearchIndexBuilder","TextBasedSearchEngine","createStoreFromConfig"],"mappings":";;;;;;;AAMA,IAAM,MAAMA,cAAA,CAAQ,OAAA;AAoBpB,SAAS,oBAAoB,OAAA,EAA6C;AAExE,EAAA,IAAI,gBAAgB,OAAA,EAAS;AAC3B,IAAA,OAAO,OAAA,CAAQ,UAAA,CAAW,GAAA,CAAI,CAAC,SAAA,MAAe;AAAA,MAC5C,UAAU,SAAA,CAAU,QAAA;AAAA,MACpB,UAAU,SAAA,CAAU;AAAA,KACtB,CAAE,CAAA;AAAA,EACJ;AAGA,EAAA,OAAQ,OAAA,CAA6B,GAAA,CAAI,CAAC,SAAA,MAAe;AAAA,IACvD,UAAU,SAAA,CAAU,QAAA;AAAA,IACpB,UAAU,SAAA,CAAU;AAAA,GACtB,CAAE,CAAA;AACJ;AAEO,SAAS,kBAAkB,MAAA,EAAgD;AAChF,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,cAAA;AAAA,IAEN,MAAM,gBAAgB,GAAA,EAAK;AACzB,MAAA,GAAA,CAAI,MAAM,qCAAqC,CAAA;AAE/C,MAAA,MAAM,UAAU,GAAA,CAAI,OAAA;AACpB,MAAA,MAAM,UAAA,GAAa,GAAA,CAAI,UAAA,IAAc,OAAA,CAAQ,GAAA,EAAI;AACjD,MAAA,MAAM,UAAA,GAAa,oBAAoB,OAAO,CAAA;AAE9C,MAAA,MAAM,WAAWC,0BAAA,CAAmB,WAAA;AAAA,QAClC;AAAA,UACE;AAAA,YACE,IAAA,EAAM,WAAA;AAAA,YACN,MAAA,EAA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EAAyD;AAClF,EAAA,IAAI,KAAA,KAAU,MAAA,IAAa,KAAA,KAAU,EAAA,EAAI,OAAO,MAAA;AAChD,EAAA,IAAI,KAAA,KAAU,SAAS,OAAO,KAAA;AAC9B,EAAA,IAAI,KAAA,KAAU,QAAQ,OAAO,IAAA;AAC7B,EAAA,OAAO,KAAA;AACT;;;ACnFA,IAAO,oBAAA,GAAQ,iBAAA,CAAkB,SAAA,EAAW","file":"peam.adapter.js","sourcesContent":["import type { NextAdapter } from 'next';\nimport { SearchIndexBuilder } from 'peam/builder';\nimport { loggers } from 'peam/logger';\nimport { TextBasedSearchEngine } from 'peam/search';\nimport { type ResolvedPeamAdapterConfig } from './config';\n\nconst log = loggers.adapter;\n\ninterface PrerenderOutput {\n pathname: string;\n fallback?: {\n filePath: string;\n };\n}\n\ninterface NextJS15Output extends PrerenderOutput {\n type: string;\n}\n\ninterface NextJS16Outputs {\n prerenders: Array<PrerenderOutput>;\n}\n\n/**\n * Normalize Next.js outputs into PrerenderPage array\n */\nfunction normalizePrerenders(outputs: NextJS15Output[] | NextJS16Outputs) {\n // Next.js 16+ format (outputs is an object with prerenders array)\n if ('prerenders' in outputs) {\n return outputs.prerenders.map((prerender) => ({\n pathname: prerender.pathname,\n fallback: prerender.fallback,\n }));\n }\n\n // Next.js 15 format (outputs is an array)\n return (outputs as NextJS15Output[]).map((prerender) => ({\n pathname: prerender.pathname,\n fallback: prerender.fallback,\n }));\n}\n\nexport function createPeamAdapter(config: ResolvedPeamAdapterConfig): NextAdapter {\n return {\n name: 'peam-adapter',\n\n async onBuildComplete(ctx) {\n log.debug('Extracting page content via adapter');\n\n const outputs = ctx.outputs as NextJS15Output[] | NextJS16Outputs;\n const projectDir = ctx.projectDir || process.cwd();\n const prerenders = normalizePrerenders(outputs);\n\n const pipeline = SearchIndexBuilder.fromConfigs(\n [\n {\n type: 'prerender',\n config: {\n prerenders,\n projectDir,\n },\n },\n ],\n {\n robotsTxt: config.robotsTxt,\n exclude: config.exclude,\n }\n );\n\n log.debug('Building search index from prerender outputs...');\n\n // TODO: this is creating unnecessary coupling between builder and search, can we fix it?\n const searchIndexData = await pipeline.build(new TextBasedSearchEngine());\n\n if (!searchIndexData) {\n log.warn('No search index data generated');\n return;\n }\n\n await config.searchIndexStore.export(searchIndexData);\n\n log.debug('Saved search index via store');\n log.debug('Extraction complete with total keys:', searchIndexData.keys.length);\n },\n };\n}\n","import { NextConfig } from 'next';\nimport { createStoreFromConfig, type SearchIndexStore, type SearchStoreConfig } from 'peam/search';\n\nexport interface PeamConfig {\n /**\n * Search store configuration\n * @default { type: 'fileBased', config: { indexPath: '.peam/index.json' } }\n */\n searchStore?: SearchStoreConfig;\n\n /**\n * Path to a custom robots.txt file or false to disable robots.txt filtering\n * If undefined, the adapter will look for static or dynamic robots.txt files in standard locations\n * @example 'custom/robots.txt' or 'config/production-robots.txt'\n * @default undefined\n */\n robotsTxt?: string | boolean;\n\n /**\n * Array of wildcard patterns to exclude from indexing\n * Supports * (matches any characters except /), ** (matches any characters including /), and ? (single character)\n * @example ['/admin/**', '/api/*', '/private-*']\n * @default []\n */\n exclude?: string[];\n}\n\nexport type ResolvedPeamAdapterConfig = Required<Omit<PeamConfig, 'robotsTxt'>> & {\n robotsTxt?: string | boolean;\n searchIndexStore: SearchIndexStore;\n};\n\nconst defaultConfig = {\n searchStore: {\n type: 'fileBased' as const,\n config: { indexPath: '.peam/index.json' },\n },\n robotsTxt: undefined,\n exclude: [],\n} satisfies PeamConfig;\n\nexport function setNextConfig(nextConfig: NextConfig, peamConfig?: PeamConfig): void {\n const envVars = {\n PEAM_SEARCH_STORE: JSON.stringify(peamConfig?.searchStore ? peamConfig.searchStore : defaultConfig.searchStore),\n PEAM_EXCLUDE: JSON.stringify(peamConfig?.exclude ? peamConfig.exclude : defaultConfig.exclude),\n PEAM_ROBOTS_TXT: '',\n };\n\n if (peamConfig?.robotsTxt !== undefined) {\n envVars.PEAM_ROBOTS_TXT = String(peamConfig.robotsTxt);\n }\n\n // Set build time vars\n Object.assign(process.env, envVars);\n\n // Set runtime vars\n nextConfig.env = {\n ...nextConfig.env,\n ...envVars,\n };\n}\n\nexport const getConfig = (): ResolvedPeamAdapterConfig => {\n if (!process.env.PEAM_SEARCH_STORE) {\n throw new Error(\n 'Peam configuration not found. Make sure withPeam() is properly configured in your next.config file.'\n );\n }\n\n const searchStoreConfig: SearchStoreConfig = JSON.parse(process.env.PEAM_SEARCH_STORE);\n\n const resolvedConfig = {\n searchStore: searchStoreConfig,\n searchIndexStore: createStoreFromConfig(searchStoreConfig),\n robotsTxt: parseRobotsTxtEnv(process.env.PEAM_ROBOTS_TXT),\n exclude: process.env.PEAM_EXCLUDE ? JSON.parse(process.env.PEAM_EXCLUDE) : [],\n };\n\n return resolvedConfig;\n};\n\nfunction parseRobotsTxtEnv(value: string | undefined): string | boolean | undefined {\n if (value === undefined || value === '') return undefined;\n if (value === 'false') return false;\n if (value === 'true') return true;\n return value;\n}\n","import { createPeamAdapter } from './adapter';\nimport { getConfig } from './config';\n\nexport default createPeamAdapter(getConfig());\n"]}
|
package/dist/route.d.mts
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import { ChatRuntimeOptions, DefaultChatRuntime } from 'peam/server';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
declare function createChat(options?: ChatRuntimeOptions): DefaultChatRuntime;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Default POST handler using GPT-4o.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* export { POST } from '@peam-ai/next/route';
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
declare const POST: (request: Request) => Promise<Response>;
|
|
14
|
+
|
|
15
|
+
export { POST, createChat };
|
package/dist/route.d.ts
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import { ChatRuntimeOptions, DefaultChatRuntime } from 'peam/server';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
declare function createChat(options?: ChatRuntimeOptions): DefaultChatRuntime;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Default POST handler using GPT-4o.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* export { POST } from '@peam-ai/next/route';
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
declare const POST: (request: Request) => Promise<Response>;
|
|
14
|
+
|
|
15
|
+
export { POST, createChat };
|
package/dist/route.js
CHANGED
|
@@ -3,33 +3,42 @@
|
|
|
3
3
|
var server = require('peam/server');
|
|
4
4
|
var search = require('peam/search');
|
|
5
5
|
|
|
6
|
-
// src/
|
|
6
|
+
// src/createChat.ts
|
|
7
7
|
var getConfig = () => {
|
|
8
|
-
if (!process.env.
|
|
8
|
+
if (!process.env.PEAM_SEARCH_STORE) {
|
|
9
9
|
throw new Error(
|
|
10
10
|
"Peam configuration not found. Make sure withPeam() is properly configured in your next.config file."
|
|
11
11
|
);
|
|
12
12
|
}
|
|
13
|
-
const
|
|
14
|
-
type: process.env.PEAM_SEARCH_EXPORTER_TYPE,
|
|
15
|
-
config: JSON.parse(process.env.PEAM_SEARCH_EXPORTER_CONFIG)
|
|
16
|
-
};
|
|
13
|
+
const searchStoreConfig = JSON.parse(process.env.PEAM_SEARCH_STORE);
|
|
17
14
|
const resolvedConfig = {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
robotsTxtPath: process.env.PEAM_ROBOTS_TXT_PATH || void 0,
|
|
15
|
+
searchStore: searchStoreConfig,
|
|
16
|
+
searchIndexStore: search.createStoreFromConfig(searchStoreConfig),
|
|
17
|
+
robotsTxt: parseRobotsTxtEnv(process.env.PEAM_ROBOTS_TXT),
|
|
22
18
|
exclude: process.env.PEAM_EXCLUDE ? JSON.parse(process.env.PEAM_EXCLUDE) : []
|
|
23
19
|
};
|
|
24
20
|
return resolvedConfig;
|
|
25
21
|
};
|
|
22
|
+
function parseRobotsTxtEnv(value) {
|
|
23
|
+
if (value === void 0 || value === "") return void 0;
|
|
24
|
+
if (value === "false") return false;
|
|
25
|
+
if (value === "true") return true;
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// src/createChat.ts
|
|
30
|
+
function createChat(options = {}) {
|
|
31
|
+
const config = getConfig();
|
|
32
|
+
return server.createChat({
|
|
33
|
+
searchIndexStore: config.searchIndexStore,
|
|
34
|
+
...options
|
|
35
|
+
});
|
|
36
|
+
}
|
|
26
37
|
|
|
27
38
|
// src/route.ts
|
|
28
|
-
var
|
|
29
|
-
var POST = server.createHandler({
|
|
30
|
-
searchIndexExporter: config.searchIndexExporter
|
|
31
|
-
});
|
|
39
|
+
var POST = createChat().handler;
|
|
32
40
|
|
|
33
41
|
exports.POST = POST;
|
|
42
|
+
exports.createChat = createChat;
|
|
34
43
|
//# sourceMappingURL=route.js.map
|
|
35
44
|
//# sourceMappingURL=route.js.map
|
package/dist/route.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/config.ts","../src/route.ts"],"names":["
|
|
1
|
+
{"version":3,"sources":["../src/config.ts","../src/createChat.ts","../src/route.ts"],"names":["createStoreFromConfig","createServerChat"],"mappings":";;;;;;AA8DO,IAAM,YAAY,MAAiC;AACxD,EAAA,IAAI,CAAC,OAAA,CAAQ,GAAA,CAAI,iBAAA,EAAmB;AAClC,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AAEA,EAAA,MAAM,iBAAA,GAAuC,IAAA,CAAK,KAAA,CAAM,OAAA,CAAQ,IAAI,iBAAiB,CAAA;AAErF,EAAA,MAAM,cAAA,GAAiB;AAAA,IACrB,WAAA,EAAa,iBAAA;AAAA,IACb,gBAAA,EAAkBA,6BAAsB,iBAAiB,CAAA;AAAA,IACzD,SAAA,EAAW,iBAAA,CAAkB,OAAA,CAAQ,GAAA,CAAI,eAAe,CAAA;AAAA,IACxD,OAAA,EAAS,OAAA,CAAQ,GAAA,CAAI,YAAA,GAAe,IAAA,CAAK,MAAM,OAAA,CAAQ,GAAA,CAAI,YAAY,CAAA,GAAI;AAAC,GAC9E;AAEA,EAAA,OAAO,cAAA;AACT,CAAA;AAEA,SAAS,kBAAkB,KAAA,EAAyD;AAClF,EAAA,IAAI,KAAA,KAAU,MAAA,IAAa,KAAA,KAAU,EAAA,EAAI,OAAO,MAAA;AAChD,EAAA,IAAI,KAAA,KAAU,SAAS,OAAO,KAAA;AAC9B,EAAA,IAAI,KAAA,KAAU,QAAQ,OAAO,IAAA;AAC7B,EAAA,OAAO,KAAA;AACT;;;ACnFO,SAAS,UAAA,CAAW,OAAA,GAA8B,EAAC,EAAuB;AAC/E,EAAA,MAAM,SAAS,SAAA,EAAU;AAEzB,EAAA,OAAOC,iBAAA,CAAiB;AAAA,IACtB,kBAAkB,MAAA,CAAO,gBAAA;AAAA,IACzB,GAAG;AAAA,GACJ,CAAA;AACH;;;ACCO,IAAM,IAAA,GAAO,YAAW,CAAE","file":"route.js","sourcesContent":["import { NextConfig } from 'next';\nimport { createStoreFromConfig, type SearchIndexStore, type SearchStoreConfig } from 'peam/search';\n\nexport interface PeamConfig {\n /**\n * Search store configuration\n * @default { type: 'fileBased', config: { indexPath: '.peam/index.json' } }\n */\n searchStore?: SearchStoreConfig;\n\n /**\n * Path to a custom robots.txt file or false to disable robots.txt filtering\n * If undefined, the adapter will look for static or dynamic robots.txt files in standard locations\n * @example 'custom/robots.txt' or 'config/production-robots.txt'\n * @default undefined\n */\n robotsTxt?: string | boolean;\n\n /**\n * Array of wildcard patterns to exclude from indexing\n * Supports * (matches any characters except /), ** (matches any characters including /), and ? (single character)\n * @example ['/admin/**', '/api/*', '/private-*']\n * @default []\n */\n exclude?: string[];\n}\n\nexport type ResolvedPeamAdapterConfig = Required<Omit<PeamConfig, 'robotsTxt'>> & {\n robotsTxt?: string | boolean;\n searchIndexStore: SearchIndexStore;\n};\n\nconst defaultConfig = {\n searchStore: {\n type: 'fileBased' as const,\n config: { indexPath: '.peam/index.json' },\n },\n robotsTxt: undefined,\n exclude: [],\n} satisfies PeamConfig;\n\nexport function setNextConfig(nextConfig: NextConfig, peamConfig?: PeamConfig): void {\n const envVars = {\n PEAM_SEARCH_STORE: JSON.stringify(peamConfig?.searchStore ? peamConfig.searchStore : defaultConfig.searchStore),\n PEAM_EXCLUDE: JSON.stringify(peamConfig?.exclude ? peamConfig.exclude : defaultConfig.exclude),\n PEAM_ROBOTS_TXT: '',\n };\n\n if (peamConfig?.robotsTxt !== undefined) {\n envVars.PEAM_ROBOTS_TXT = String(peamConfig.robotsTxt);\n }\n\n // Set build time vars\n Object.assign(process.env, envVars);\n\n // Set runtime vars\n nextConfig.env = {\n ...nextConfig.env,\n ...envVars,\n };\n}\n\nexport const getConfig = (): ResolvedPeamAdapterConfig => {\n if (!process.env.PEAM_SEARCH_STORE) {\n throw new Error(\n 'Peam configuration not found. Make sure withPeam() is properly configured in your next.config file.'\n );\n }\n\n const searchStoreConfig: SearchStoreConfig = JSON.parse(process.env.PEAM_SEARCH_STORE);\n\n const resolvedConfig = {\n searchStore: searchStoreConfig,\n searchIndexStore: createStoreFromConfig(searchStoreConfig),\n robotsTxt: parseRobotsTxtEnv(process.env.PEAM_ROBOTS_TXT),\n exclude: process.env.PEAM_EXCLUDE ? JSON.parse(process.env.PEAM_EXCLUDE) : [],\n };\n\n return resolvedConfig;\n};\n\nfunction parseRobotsTxtEnv(value: string | undefined): string | boolean | undefined {\n if (value === undefined || value === '') return undefined;\n if (value === 'false') return false;\n if (value === 'true') return true;\n return value;\n}\n","import { createChat as createServerChat, type ChatRuntimeOptions, type DefaultChatRuntime } from 'peam/server';\nimport { getConfig } from './config';\n\nexport function createChat(options: ChatRuntimeOptions = {}): DefaultChatRuntime {\n const config = getConfig();\n\n return createServerChat({\n searchIndexStore: config.searchIndexStore,\n ...options,\n });\n}\n","export { createChat } from './createChat';\nimport { createChat } from './createChat';\n\n/**\n * Default POST handler using GPT-4o.\n *\n * @example\n * ```typescript\n * export { POST } from '@peam-ai/next/route';\n * ```\n */\nexport const POST = createChat().handler;\n"]}
|
package/dist/route.mjs
CHANGED
|
@@ -1,33 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { createChat as createChat$1 } from 'peam/server';
|
|
2
|
+
import { createStoreFromConfig } from 'peam/search';
|
|
3
3
|
|
|
4
|
-
// src/
|
|
4
|
+
// src/createChat.ts
|
|
5
5
|
var getConfig = () => {
|
|
6
|
-
if (!process.env.
|
|
6
|
+
if (!process.env.PEAM_SEARCH_STORE) {
|
|
7
7
|
throw new Error(
|
|
8
8
|
"Peam configuration not found. Make sure withPeam() is properly configured in your next.config file."
|
|
9
9
|
);
|
|
10
10
|
}
|
|
11
|
-
const
|
|
12
|
-
type: process.env.PEAM_SEARCH_EXPORTER_TYPE,
|
|
13
|
-
config: JSON.parse(process.env.PEAM_SEARCH_EXPORTER_CONFIG)
|
|
14
|
-
};
|
|
11
|
+
const searchStoreConfig = JSON.parse(process.env.PEAM_SEARCH_STORE);
|
|
15
12
|
const resolvedConfig = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
robotsTxtPath: process.env.PEAM_ROBOTS_TXT_PATH || void 0,
|
|
13
|
+
searchStore: searchStoreConfig,
|
|
14
|
+
searchIndexStore: createStoreFromConfig(searchStoreConfig),
|
|
15
|
+
robotsTxt: parseRobotsTxtEnv(process.env.PEAM_ROBOTS_TXT),
|
|
20
16
|
exclude: process.env.PEAM_EXCLUDE ? JSON.parse(process.env.PEAM_EXCLUDE) : []
|
|
21
17
|
};
|
|
22
18
|
return resolvedConfig;
|
|
23
19
|
};
|
|
20
|
+
function parseRobotsTxtEnv(value) {
|
|
21
|
+
if (value === void 0 || value === "") return void 0;
|
|
22
|
+
if (value === "false") return false;
|
|
23
|
+
if (value === "true") return true;
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/createChat.ts
|
|
28
|
+
function createChat(options = {}) {
|
|
29
|
+
const config = getConfig();
|
|
30
|
+
return createChat$1({
|
|
31
|
+
searchIndexStore: config.searchIndexStore,
|
|
32
|
+
...options
|
|
33
|
+
});
|
|
34
|
+
}
|
|
24
35
|
|
|
25
36
|
// src/route.ts
|
|
26
|
-
var
|
|
27
|
-
var POST = createHandler({
|
|
28
|
-
searchIndexExporter: config.searchIndexExporter
|
|
29
|
-
});
|
|
37
|
+
var POST = createChat().handler;
|
|
30
38
|
|
|
31
|
-
export { POST };
|
|
39
|
+
export { POST, createChat };
|
|
32
40
|
//# sourceMappingURL=route.mjs.map
|
|
33
41
|
//# sourceMappingURL=route.mjs.map
|
package/dist/route.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/config.ts","../src/route.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"sources":["../src/config.ts","../src/createChat.ts","../src/route.ts"],"names":["createServerChat"],"mappings":";;;;AA8DO,IAAM,YAAY,MAAiC;AACxD,EAAA,IAAI,CAAC,OAAA,CAAQ,GAAA,CAAI,iBAAA,EAAmB;AAClC,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AAEA,EAAA,MAAM,iBAAA,GAAuC,IAAA,CAAK,KAAA,CAAM,OAAA,CAAQ,IAAI,iBAAiB,CAAA;AAErF,EAAA,MAAM,cAAA,GAAiB;AAAA,IACrB,WAAA,EAAa,iBAAA;AAAA,IACb,gBAAA,EAAkB,sBAAsB,iBAAiB,CAAA;AAAA,IACzD,SAAA,EAAW,iBAAA,CAAkB,OAAA,CAAQ,GAAA,CAAI,eAAe,CAAA;AAAA,IACxD,OAAA,EAAS,OAAA,CAAQ,GAAA,CAAI,YAAA,GAAe,IAAA,CAAK,MAAM,OAAA,CAAQ,GAAA,CAAI,YAAY,CAAA,GAAI;AAAC,GAC9E;AAEA,EAAA,OAAO,cAAA;AACT,CAAA;AAEA,SAAS,kBAAkB,KAAA,EAAyD;AAClF,EAAA,IAAI,KAAA,KAAU,MAAA,IAAa,KAAA,KAAU,EAAA,EAAI,OAAO,MAAA;AAChD,EAAA,IAAI,KAAA,KAAU,SAAS,OAAO,KAAA;AAC9B,EAAA,IAAI,KAAA,KAAU,QAAQ,OAAO,IAAA;AAC7B,EAAA,OAAO,KAAA;AACT;;;ACnFO,SAAS,UAAA,CAAW,OAAA,GAA8B,EAAC,EAAuB;AAC/E,EAAA,MAAM,SAAS,SAAA,EAAU;AAEzB,EAAA,OAAOA,YAAA,CAAiB;AAAA,IACtB,kBAAkB,MAAA,CAAO,gBAAA;AAAA,IACzB,GAAG;AAAA,GACJ,CAAA;AACH;;;ACCO,IAAM,IAAA,GAAO,YAAW,CAAE","file":"route.mjs","sourcesContent":["import { NextConfig } from 'next';\nimport { createStoreFromConfig, type SearchIndexStore, type SearchStoreConfig } from 'peam/search';\n\nexport interface PeamConfig {\n /**\n * Search store configuration\n * @default { type: 'fileBased', config: { indexPath: '.peam/index.json' } }\n */\n searchStore?: SearchStoreConfig;\n\n /**\n * Path to a custom robots.txt file or false to disable robots.txt filtering\n * If undefined, the adapter will look for static or dynamic robots.txt files in standard locations\n * @example 'custom/robots.txt' or 'config/production-robots.txt'\n * @default undefined\n */\n robotsTxt?: string | boolean;\n\n /**\n * Array of wildcard patterns to exclude from indexing\n * Supports * (matches any characters except /), ** (matches any characters including /), and ? (single character)\n * @example ['/admin/**', '/api/*', '/private-*']\n * @default []\n */\n exclude?: string[];\n}\n\nexport type ResolvedPeamAdapterConfig = Required<Omit<PeamConfig, 'robotsTxt'>> & {\n robotsTxt?: string | boolean;\n searchIndexStore: SearchIndexStore;\n};\n\nconst defaultConfig = {\n searchStore: {\n type: 'fileBased' as const,\n config: { indexPath: '.peam/index.json' },\n },\n robotsTxt: undefined,\n exclude: [],\n} satisfies PeamConfig;\n\nexport function setNextConfig(nextConfig: NextConfig, peamConfig?: PeamConfig): void {\n const envVars = {\n PEAM_SEARCH_STORE: JSON.stringify(peamConfig?.searchStore ? peamConfig.searchStore : defaultConfig.searchStore),\n PEAM_EXCLUDE: JSON.stringify(peamConfig?.exclude ? peamConfig.exclude : defaultConfig.exclude),\n PEAM_ROBOTS_TXT: '',\n };\n\n if (peamConfig?.robotsTxt !== undefined) {\n envVars.PEAM_ROBOTS_TXT = String(peamConfig.robotsTxt);\n }\n\n // Set build time vars\n Object.assign(process.env, envVars);\n\n // Set runtime vars\n nextConfig.env = {\n ...nextConfig.env,\n ...envVars,\n };\n}\n\nexport const getConfig = (): ResolvedPeamAdapterConfig => {\n if (!process.env.PEAM_SEARCH_STORE) {\n throw new Error(\n 'Peam configuration not found. Make sure withPeam() is properly configured in your next.config file.'\n );\n }\n\n const searchStoreConfig: SearchStoreConfig = JSON.parse(process.env.PEAM_SEARCH_STORE);\n\n const resolvedConfig = {\n searchStore: searchStoreConfig,\n searchIndexStore: createStoreFromConfig(searchStoreConfig),\n robotsTxt: parseRobotsTxtEnv(process.env.PEAM_ROBOTS_TXT),\n exclude: process.env.PEAM_EXCLUDE ? JSON.parse(process.env.PEAM_EXCLUDE) : [],\n };\n\n return resolvedConfig;\n};\n\nfunction parseRobotsTxtEnv(value: string | undefined): string | boolean | undefined {\n if (value === undefined || value === '') return undefined;\n if (value === 'false') return false;\n if (value === 'true') return true;\n return value;\n}\n","import { createChat as createServerChat, type ChatRuntimeOptions, type DefaultChatRuntime } from 'peam/server';\nimport { getConfig } from './config';\n\nexport function createChat(options: ChatRuntimeOptions = {}): DefaultChatRuntime {\n const config = getConfig();\n\n return createServerChat({\n searchIndexStore: config.searchIndexStore,\n ...options,\n });\n}\n","export { createChat } from './createChat';\nimport { createChat } from './createChat';\n\n/**\n * Default POST handler using GPT-4o.\n *\n * @example\n * ```typescript\n * export { POST } from '@peam-ai/next/route';\n * ```\n */\nexport const POST = createChat().handler;\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peam-ai/next",
|
|
3
3
|
"description": "Peam Next.js integration",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.8",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -43,17 +43,18 @@
|
|
|
43
43
|
"next": ">=14.0.0"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"peam": "0.1.
|
|
46
|
+
"peam": "0.1.5"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"next": ">=14.0.0"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
52
|
"build": "tsup",
|
|
53
|
+
"build:watch": "tsup --watch",
|
|
53
54
|
"clean": "rm -rf dist",
|
|
54
|
-
"
|
|
55
|
+
"format": "prettier --write \"src/**/*.ts*\"",
|
|
55
56
|
"test:lint": "eslint \"src/**/*.ts*\"",
|
|
56
|
-
"test:
|
|
57
|
+
"test:format": "prettier --check \"src/**/*.ts*\"",
|
|
57
58
|
"test:unit": "vitest run"
|
|
58
59
|
}
|
|
59
60
|
}
|