@van1s1mys/ai-router-plugin-next 1.0.0 → 1.1.0
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/README.md +70 -0
- package/dist/index.cjs +0 -1
- package/dist/index.js +0 -1
- package/package.json +41 -41
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# @van1s1mys/ai-router-plugin-next
|
|
2
|
+
|
|
3
|
+
Next.js plugin for [@van1s1mys/ai-router](https://www.npmjs.com/package/@van1s1mys/ai-router) — wraps the webpack plugin with Next.js-specific defaults.
|
|
4
|
+
|
|
5
|
+
Auto-scans `app/`, `pages/`, `src/app/`, `src/pages/` and excludes Next.js internals (layouts, loading states, API routes, etc.).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @van1s1mys/ai-router @van1s1mys/ai-router-plugin-next
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Setup
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
// next.config.ts
|
|
17
|
+
import { withAiRouter } from '@van1s1mys/ai-router-plugin-next';
|
|
18
|
+
|
|
19
|
+
export default withAiRouter({
|
|
20
|
+
// your Next.js config
|
|
21
|
+
});
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
// app/providers.tsx
|
|
26
|
+
import { SmartRouter } from '@van1s1mys/ai-router';
|
|
27
|
+
import { routes } from 'virtual:ai-router';
|
|
28
|
+
|
|
29
|
+
const router = new SmartRouter({ routes });
|
|
30
|
+
await router.ready;
|
|
31
|
+
|
|
32
|
+
const result = await router.search('how much does it cost?');
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Options
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
withAiRouter(nextConfig, {
|
|
39
|
+
// Override scan directories
|
|
40
|
+
dirs: ['src/app'],
|
|
41
|
+
|
|
42
|
+
// Additional exclusions (merged with Next.js defaults)
|
|
43
|
+
exclude: ['admin/'],
|
|
44
|
+
|
|
45
|
+
// Manual routes merged with scanned ones
|
|
46
|
+
routes: [
|
|
47
|
+
{ path: '/pricing', title: 'Pricing', description: 'cost, plans, billing' },
|
|
48
|
+
],
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Default exclusions
|
|
53
|
+
|
|
54
|
+
The plugin automatically excludes Next.js internal files:
|
|
55
|
+
|
|
56
|
+
`_app`, `_document`, `_error`, `layout`, `loading`, `error`, `not-found`, `template`, `default`, `icon`, `apple-icon`, `opengraph-image`, `twitter-image`, `sitemap`, `robots`, `manifest`, `middleware`, `instrumentation`, `global-error`, `route`, `__tests__`, `.test.`, `.spec.`, `api/`
|
|
57
|
+
|
|
58
|
+
## Route annotations
|
|
59
|
+
|
|
60
|
+
Add `@ai-route` comments to page files for richer metadata:
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
// @ai-route title="Pricing" description="plans, cost, billing, subscription"
|
|
64
|
+
|
|
65
|
+
export default function PricingPage() { ... }
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## License
|
|
69
|
+
|
|
70
|
+
[MIT](../../LICENSE) © [IvanMalkS](https://github.com/IvanMalkS)
|
package/dist/index.cjs
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@van1s1mys/ai-router-plugin-next",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Next.js plugin for ai-router — auto-scan app/pages dirs and generate route config",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "./dist/index.cjs",
|
|
7
|
-
"module": "./dist/index.js",
|
|
8
|
-
"types": "./dist/index.d.ts",
|
|
9
|
-
"exports": {
|
|
10
|
-
".": {
|
|
11
|
-
"import": {
|
|
12
|
-
"types": "./dist/index.d.ts",
|
|
13
|
-
"default": "./dist/index.js"
|
|
14
|
-
},
|
|
15
|
-
"require": {
|
|
16
|
-
"types": "./dist/index.d.cts",
|
|
17
|
-
"default": "./dist/index.cjs"
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
"files": [
|
|
22
|
-
"dist"
|
|
23
|
-
],
|
|
24
|
-
"scripts": {
|
|
25
|
-
"build": "tsup",
|
|
26
|
-
"dev": "tsup --watch"
|
|
27
|
-
},
|
|
28
|
-
"keywords": [
|
|
29
|
-
"next",
|
|
30
|
-
"nextjs",
|
|
31
|
-
"ai-router"
|
|
32
|
-
],
|
|
33
|
-
"license": "MIT",
|
|
34
|
-
"dependencies": {
|
|
35
|
-
"@ai-router/shared": "workspace:*",
|
|
36
|
-
"@van1s1mys/ai-router-plugin-webpack": "workspace:*"
|
|
37
|
-
},
|
|
38
|
-
"peerDependencies": {
|
|
39
|
-
"next": ">=13.0.0"
|
|
40
|
-
}
|
|
41
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@van1s1mys/ai-router-plugin-next",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Next.js plugin for ai-router — auto-scan app/pages dirs and generate route config",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsup",
|
|
26
|
+
"dev": "tsup --watch"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"next",
|
|
30
|
+
"nextjs",
|
|
31
|
+
"ai-router"
|
|
32
|
+
],
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@ai-router/shared": "workspace:*",
|
|
36
|
+
"@van1s1mys/ai-router-plugin-webpack": "workspace:*"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"next": ">=13.0.0"
|
|
40
|
+
}
|
|
41
|
+
}
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Next.js plugin for ai-router.\n *\n * Wraps the webpack plugin with Next.js-specific defaults —\n * automatically scans `app/`, `pages/`, `src/app/`, and `src/pages/`\n * while excluding Next.js internal files (layouts, loading states, API routes, etc.).\n *\n * @example\n * ```js\n * // next.config.js\n * const { withAiRouter } = require('ai-router-plugin-next');\n *\n * module.exports = withAiRouter({\n * // your Next.js config\n * });\n * ```\n *\n * ```ts\n * // app/providers.tsx\n * import { routes } from 'virtual:ai-router';\n * import { SmartRouter } from 'ai-router';\n *\n * const router = new SmartRouter({ routes });\n * ```\n *\n * @module\n */\n\nimport { AiRouterPlugin } from '@van1s1mys/ai-router-plugin-webpack';\nimport type { PluginOptions } from '@ai-router/shared';\n\nexport type { PluginOptions } from '@ai-router/shared';\n\n/** Minimal webpack config shape used by Next.js. */\ninterface WebpackConfig {\n plugins?: { apply(compiler: unknown): void }[];\n [key: string]: unknown;\n}\n\n/** Minimal Next.js `webpack()` context. */\ninterface WebpackContext {\n dev: boolean;\n isServer: boolean;\n [key: string]: unknown;\n}\n\n/**\n * Next.js configuration object.\n * Accepts any Next.js config property plus an optional `webpack` function.\n */\ninterface NextConfig {\n webpack?: (config: WebpackConfig, context: WebpackContext) => WebpackConfig;\n [key: string]: unknown;\n}\n\n/**\n * Wraps a Next.js config with ai-router route scanning.\n *\n * Injects the {@link AiRouterPlugin} into the webpack config with\n * sensible defaults for Next.js projects. Auto-detects standard\n * directory conventions (`app/`, `pages/`, `src/app/`, `src/pages/`)\n * and excludes framework internals.\n *\n * @param nextConfig - Your existing Next.js configuration.\n * @param options - Override scan directories, exclusions, or provide manual routes.\n * Defaults are merged, not replaced.\n * @returns A new Next.js config with the ai-router webpack plugin applied.\n *\n * @example\n * ```js\n * // Basic usage — auto-detects app/ and pages/ directories\n * module.exports = withAiRouter({});\n * ```\n *\n * @example\n * ```js\n * // With manual route overrides\n * module.exports = withAiRouter(nextConfig, {\n * routes: [\n * { path: '/pricing', title: 'Pricing', description: 'cost, plans, billing' },\n * ],\n * });\n * ```\n *\n * @example\n * ```js\n * // Custom directories only\n * module.exports = withAiRouter(nextConfig, {\n * dirs: ['src/app'],\n * });\n * ```\n */\nexport function withAiRouter(nextConfig: NextConfig = {}, options?: PluginOptions): NextConfig {\n const pluginOptions: PluginOptions = {\n dirs: ['app', 'pages', 'src/app', 'src/pages'],\n exclude: [\n // Next.js internal files\n '_app',\n '_document',\n '_error',\n 'layout',\n 'loading',\n 'error',\n 'not-found',\n 'template',\n 'default',\n 'icon',\n 'apple-icon',\n 'opengraph-image',\n 'twitter-image',\n 'sitemap',\n 'robots',\n 'manifest',\n 'middleware',\n 'instrumentation',\n 'global-error',\n 'route', // API routes\n '__tests__',\n '.test.',\n '.spec.',\n 'api/', // API directory\n ],\n ...options,\n };\n\n return {\n ...nextConfig,\n webpack(config: WebpackConfig, context: WebpackContext) {\n config.plugins = config.plugins || [];\n config.plugins.push(new AiRouterPlugin(pluginOptions));\n\n if (typeof nextConfig.webpack === 'function') {\n return nextConfig.webpack(config, context);\n }\n\n return config;\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA4BA,sCAA+B;AAgExB,SAAS,aAAa,aAAyB,CAAC,GAAG,SAAqC;AAC7F,QAAM,gBAA+B;AAAA,IACnC,MAAM,CAAC,OAAO,SAAS,WAAW,WAAW;AAAA,IAC7C,SAAS;AAAA;AAAA,MAEP;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAAA,IACF;AAAA,IACA,GAAG;AAAA,EACL;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,QAAQ,QAAuB,SAAyB;AACtD,aAAO,UAAU,OAAO,WAAW,CAAC;AACpC,aAAO,QAAQ,KAAK,IAAI,+CAAe,aAAa,CAAC;AAErD,UAAI,OAAO,WAAW,YAAY,YAAY;AAC5C,eAAO,WAAW,QAAQ,QAAQ,OAAO;AAAA,MAC3C;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":[]}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Next.js plugin for ai-router.\n *\n * Wraps the webpack plugin with Next.js-specific defaults —\n * automatically scans `app/`, `pages/`, `src/app/`, and `src/pages/`\n * while excluding Next.js internal files (layouts, loading states, API routes, etc.).\n *\n * @example\n * ```js\n * // next.config.js\n * const { withAiRouter } = require('ai-router-plugin-next');\n *\n * module.exports = withAiRouter({\n * // your Next.js config\n * });\n * ```\n *\n * ```ts\n * // app/providers.tsx\n * import { routes } from 'virtual:ai-router';\n * import { SmartRouter } from 'ai-router';\n *\n * const router = new SmartRouter({ routes });\n * ```\n *\n * @module\n */\n\nimport { AiRouterPlugin } from '@van1s1mys/ai-router-plugin-webpack';\nimport type { PluginOptions } from '@ai-router/shared';\n\nexport type { PluginOptions } from '@ai-router/shared';\n\n/** Minimal webpack config shape used by Next.js. */\ninterface WebpackConfig {\n plugins?: { apply(compiler: unknown): void }[];\n [key: string]: unknown;\n}\n\n/** Minimal Next.js `webpack()` context. */\ninterface WebpackContext {\n dev: boolean;\n isServer: boolean;\n [key: string]: unknown;\n}\n\n/**\n * Next.js configuration object.\n * Accepts any Next.js config property plus an optional `webpack` function.\n */\ninterface NextConfig {\n webpack?: (config: WebpackConfig, context: WebpackContext) => WebpackConfig;\n [key: string]: unknown;\n}\n\n/**\n * Wraps a Next.js config with ai-router route scanning.\n *\n * Injects the {@link AiRouterPlugin} into the webpack config with\n * sensible defaults for Next.js projects. Auto-detects standard\n * directory conventions (`app/`, `pages/`, `src/app/`, `src/pages/`)\n * and excludes framework internals.\n *\n * @param nextConfig - Your existing Next.js configuration.\n * @param options - Override scan directories, exclusions, or provide manual routes.\n * Defaults are merged, not replaced.\n * @returns A new Next.js config with the ai-router webpack plugin applied.\n *\n * @example\n * ```js\n * // Basic usage — auto-detects app/ and pages/ directories\n * module.exports = withAiRouter({});\n * ```\n *\n * @example\n * ```js\n * // With manual route overrides\n * module.exports = withAiRouter(nextConfig, {\n * routes: [\n * { path: '/pricing', title: 'Pricing', description: 'cost, plans, billing' },\n * ],\n * });\n * ```\n *\n * @example\n * ```js\n * // Custom directories only\n * module.exports = withAiRouter(nextConfig, {\n * dirs: ['src/app'],\n * });\n * ```\n */\nexport function withAiRouter(nextConfig: NextConfig = {}, options?: PluginOptions): NextConfig {\n const pluginOptions: PluginOptions = {\n dirs: ['app', 'pages', 'src/app', 'src/pages'],\n exclude: [\n // Next.js internal files\n '_app',\n '_document',\n '_error',\n 'layout',\n 'loading',\n 'error',\n 'not-found',\n 'template',\n 'default',\n 'icon',\n 'apple-icon',\n 'opengraph-image',\n 'twitter-image',\n 'sitemap',\n 'robots',\n 'manifest',\n 'middleware',\n 'instrumentation',\n 'global-error',\n 'route', // API routes\n '__tests__',\n '.test.',\n '.spec.',\n 'api/', // API directory\n ],\n ...options,\n };\n\n return {\n ...nextConfig,\n webpack(config: WebpackConfig, context: WebpackContext) {\n config.plugins = config.plugins || [];\n config.plugins.push(new AiRouterPlugin(pluginOptions));\n\n if (typeof nextConfig.webpack === 'function') {\n return nextConfig.webpack(config, context);\n }\n\n return config;\n },\n };\n}\n"],"mappings":";AA4BA,SAAS,sBAAsB;AAgExB,SAAS,aAAa,aAAyB,CAAC,GAAG,SAAqC;AAC7F,QAAM,gBAA+B;AAAA,IACnC,MAAM,CAAC,OAAO,SAAS,WAAW,WAAW;AAAA,IAC7C,SAAS;AAAA;AAAA,MAEP;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAAA,IACF;AAAA,IACA,GAAG;AAAA,EACL;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,QAAQ,QAAuB,SAAyB;AACtD,aAAO,UAAU,OAAO,WAAW,CAAC;AACpC,aAAO,QAAQ,KAAK,IAAI,eAAe,aAAa,CAAC;AAErD,UAAI,OAAO,WAAW,YAAY,YAAY;AAC5C,eAAO,WAAW,QAAQ,QAAQ,OAAO;AAAA,MAC3C;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":[]}
|