@yak-io/nextjs 0.1.3 → 0.1.4

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 CHANGED
@@ -182,8 +182,6 @@ yak-nextjs generate-manifest --app-dir ./app --pages-dir ./pages
182
182
 
183
183
  During local development, routes are scanned directly from the filesystem—no setup needed. However, when you build your Next.js app for production, only the compiled `.next` output is included. Source files like `./src/app` are not present at runtime.
184
184
 
185
- To enable route scanning in production builds, generate a manifest at build time.
186
-
187
185
  ### Recommended setup
188
186
 
189
187
  Add a `prebuild` script to generate the manifest before Next.js builds:
@@ -197,9 +195,9 @@ Add a `prebuild` script to generate the manifest before Next.js builds:
197
195
  }
198
196
  ```
199
197
 
200
- That's it! The manifest is generated to `./public/yak-routes-manifest.json` and the handler automatically fetches it at runtime on serverless platforms like Vercel. No code changes needed.
198
+ That's it! The manifest is generated to `./src/yak-routes-manifest.json` and automatically bundled with your serverless function. No code changes needed in your API route.
201
199
 
202
- The handler automatically detects the deployment environment (Vercel via `VERCEL_URL`, Netlify via `URL`, or custom `NEXT_PUBLIC_BASE_URL`) and fetches the manifest from the public folder.
200
+ The manifest is placed in `./src/` so that Next.js file tracing includes it in the serverless bundle, making it available at runtime on platforms like Vercel.
203
201
 
204
202
  ### Alternative: explicit routes
205
203
 
@@ -11,7 +11,7 @@
11
11
  * Options:
12
12
  * --app-dir <path> Path to Next.js app directory (default: ./src/app)
13
13
  * --pages-dir <path> Path to Next.js pages directory (optional, scanned in addition to app-dir)
14
- * --output <path> Output file path (default: ./public/yak-routes-manifest.json)
14
+ * --output <path> Output file path (default: ./src/yak-routes-manifest.json)
15
15
  */
16
16
  export {};
17
17
  //# sourceMappingURL=generate-manifest.d.ts.map
@@ -11,7 +11,7 @@
11
11
  * Options:
12
12
  * --app-dir <path> Path to Next.js app directory (default: ./src/app)
13
13
  * --pages-dir <path> Path to Next.js pages directory (optional, scanned in addition to app-dir)
14
- * --output <path> Output file path (default: ./public/yak-routes-manifest.json)
14
+ * --output <path> Output file path (default: ./src/yak-routes-manifest.json)
15
15
  */
16
16
  import * as fs from "node:fs";
17
17
  import * as path from "node:path";
@@ -201,7 +201,8 @@ function parseArgs() {
201
201
  const args = process.argv.slice(2);
202
202
  let appDir = "./src/app";
203
203
  let pagesDir = undefined;
204
- let output = "./public/yak-routes-manifest.json";
204
+ // Default to ./src/ so the file is included in Next.js serverless bundle via file tracing
205
+ let output = "./src/yak-routes-manifest.json";
205
206
  let help = false;
206
207
  for (let i = 0; i < args.length; i++) {
207
208
  const arg = args[i];
@@ -238,7 +239,7 @@ Usage:
238
239
  Options:
239
240
  --app-dir <path> Path to Next.js app directory (default: ./src/app)
240
241
  --pages-dir <path> Path to Next.js pages directory (optional)
241
- --output <path> Output file path (default: ./public/yak-routes-manifest.json)
242
+ --output <path> Output file path (default: ./src/yak-routes-manifest.json)
242
243
  --help, -h Show this help message
243
244
 
244
245
  Examples:
@@ -3,6 +3,7 @@ import type { RouteSourceInput, ToolSourceInput, RouteInfo, RouteManifest, ToolM
3
3
  * Load a pre-built route manifest from disk (JSON file).
4
4
  *
5
5
  * This works in traditional Node.js deployments where the filesystem is available.
6
+ * For Vercel serverless, the manifest must be imported directly in your route file.
6
7
  *
7
8
  * Generate the manifest at build time using:
8
9
  * yak-nextjs generate-manifest
@@ -1 +1 @@
1
- {"version":3,"file":"createNextYakHandler.d.ts","sourceRoot":"","sources":["../../src/server/createNextYakHandler.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,SAAS,EACT,aAAa,EACb,YAAY,EACZ,YAAY,EACb,MAAM,2BAA2B,CAAC;AAiBnC;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI,CAgB7E;AAgED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,EAAE,CAe7D;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AAE,eAAe,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,OAAO,CAAC,YAAY,CAAC,CAAC;CACxC,CAAC;AAEF,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,0BAA0B,wCAK5E;AAED,MAAM,MAAM,yBAAyB,GAAG;IACtC,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,OAAO,CAAC,YAAY,CAAC,CAAC;IACvC,WAAW,EAAE,YAAY,CAAC;CAC3B,CAAC;AAEF,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,yBAAyB,uCAW1E"}
@@ -5,19 +5,22 @@ import { scanRoutes } from "./scan-routes.js";
5
5
  /**
6
6
  * Default paths to check for pre-built route manifests (JSON files).
7
7
  * These are read via fs.readFileSync at runtime.
8
+ *
9
+ * Priority:
10
+ * 1. ./src/yak-routes-manifest.json - Default output, bundled by Next.js file tracing
11
+ * 2. ./yak-routes-manifest.json - Root fallback
12
+ * 3. ./public/yak-routes-manifest.json - Legacy location (doesn't work on Vercel serverless)
8
13
  */
9
14
  const DEFAULT_MANIFEST_PATHS = [
10
- "./public/yak-routes-manifest.json",
15
+ "./src/yak-routes-manifest.json",
11
16
  "./yak-routes-manifest.json",
17
+ "./public/yak-routes-manifest.json",
12
18
  ];
13
- /**
14
- * Public URL path where the manifest is served from (when in public/).
15
- */
16
- const PUBLIC_MANIFEST_URL = "/yak-routes-manifest.json";
17
19
  /**
18
20
  * Load a pre-built route manifest from disk (JSON file).
19
21
  *
20
22
  * This works in traditional Node.js deployments where the filesystem is available.
23
+ * For Vercel serverless, the manifest must be imported directly in your route file.
21
24
  *
22
25
  * Generate the manifest at build time using:
23
26
  * yak-nextjs generate-manifest
@@ -41,59 +44,6 @@ export function loadRouteManifest(manifestPath) {
41
44
  }
42
45
  return null;
43
46
  }
44
- /**
45
- * Fetch the route manifest from the public URL.
46
- * Used in serverless environments where filesystem access is not available.
47
- */
48
- async function fetchRouteManifest() {
49
- // Try to determine the base URL for fetching
50
- const baseUrl = getBaseUrl();
51
- if (!baseUrl) {
52
- return null;
53
- }
54
- try {
55
- const url = new URL(PUBLIC_MANIFEST_URL, baseUrl);
56
- const response = await fetch(url.toString(), {
57
- headers: { "Accept": "application/json" },
58
- cache: "no-store",
59
- });
60
- if (!response.ok) {
61
- return null;
62
- }
63
- const manifest = await response.json();
64
- if (manifest?.routes) {
65
- return manifest;
66
- }
67
- }
68
- catch {
69
- // Fetch failed
70
- }
71
- return null;
72
- }
73
- /**
74
- * Get the base URL for the current deployment.
75
- * Supports Vercel, Netlify, and custom configurations.
76
- */
77
- function getBaseUrl() {
78
- // Vercel provides VERCEL_URL (without protocol)
79
- if (process.env.VERCEL_URL) {
80
- const protocol = process.env.VERCEL_ENV === "development" ? "http" : "https";
81
- return `${protocol}://${process.env.VERCEL_URL}`;
82
- }
83
- // Netlify provides URL
84
- if (process.env.URL) {
85
- return process.env.URL;
86
- }
87
- // Custom base URL
88
- if (process.env.NEXT_PUBLIC_BASE_URL) {
89
- return process.env.NEXT_PUBLIC_BASE_URL;
90
- }
91
- // For local development
92
- if (process.env.NODE_ENV === "development") {
93
- return "http://localhost:3000";
94
- }
95
- return null;
96
- }
97
47
  /**
98
48
  * Load routes from a pre-built manifest.
99
49
  * Throws if manifest is not found.
@@ -138,22 +88,14 @@ async function tryLoadRoutes(appDir) {
138
88
  if (manifest) {
139
89
  return manifest.routes;
140
90
  }
141
- // Try fetching from public URL (works on Vercel/serverless)
142
- const fetchedManifest = await fetchRouteManifest();
143
- if (fetchedManifest) {
144
- return fetchedManifest.routes;
145
- }
146
91
  // Neither source nor manifest available - provide helpful error
147
- throw new Error(`App directory not found: ${targetDir}\n\n` +
148
- `This typically happens in production (Vercel, etc.) where source files aren't deployed.\n\n` +
149
- `Solutions:\n` +
150
- `1. Generate a route manifest at build time (recommended):\n` +
151
- ` Add to package.json: "prebuild": "yak-nextjs generate-manifest"\n` +
152
- ` The manifest will be placed in public/ and automatically loaded.\n\n` +
153
- `2. Provide routes explicitly:\n` +
154
- ` createNextYakHandler({ routes: [{ path: "/", title: "Home" }, ...] })\n\n` +
155
- `3. Use getRoutes callback:\n` +
156
- ` createNextYakHandler({ getRoutes: async () => [...] })`);
92
+ throw new Error(`Route manifest not found.\n\n` +
93
+ `Generate the manifest at build time by adding to package.json:\n` +
94
+ ` "prebuild": "yak-nextjs generate-manifest"\n\n` +
95
+ `The manifest will be created at ./src/yak-routes-manifest.json and automatically\n` +
96
+ `bundled with your serverless function.\n\n` +
97
+ `Alternatively, provide routes explicitly:\n` +
98
+ ` createNextYakHandler({ routes: [{ path: "/", title: "Home" }] })`);
157
99
  }
158
100
  function resolveRouteSources(config) {
159
101
  if (config.routes) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yak-io/nextjs",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Next.js SDK for embedding yak chatbot with route manifest generation",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE",