@aihu/adapter-vercel 0.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/LICENSE +21 -0
- package/README.md +32 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Fellwork
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# @aihu/adapter-vercel
|
|
2
|
+
|
|
3
|
+
> Vercel deployment adapter for @aihu/app.
|
|
4
|
+
|
|
5
|
+
Part of the [aihu](https://github.com/fellwork/aihu) framework — agentic discovery and interaction, for human purpose.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @aihu/adapter-vercel
|
|
11
|
+
# or
|
|
12
|
+
bun add @aihu/adapter-vercel
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
// vite.config.ts
|
|
19
|
+
import { defineConfig } from 'vite';
|
|
20
|
+
import { aihu } from '@aihu/app';
|
|
21
|
+
import vercel from '@aihu/adapter-vercel';
|
|
22
|
+
|
|
23
|
+
export default defineConfig({ plugins: [aihu({ adapter: vercel() })] });
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Status
|
|
27
|
+
|
|
28
|
+
Early access (`0.1.x`). API may evolve before v1.1 GA. See the [v1.1 roadmap](https://github.com/fellwork/aihu/tree/main/docs/roadmap) for stability commitments.
|
|
29
|
+
|
|
30
|
+
## License
|
|
31
|
+
|
|
32
|
+
MIT — see [LICENSE](https://github.com/fellwork/aihu/blob/main/LICENSE).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { AihuAdapter } from "@aihu/app";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
interface VercelAdapterOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Edge Function runtime.
|
|
7
|
+
* - 'edge': Vercel Edge Runtime (V8 isolates, global deployment) — default
|
|
8
|
+
* - 'serverless': Node.js serverless function (regional)
|
|
9
|
+
*/
|
|
10
|
+
runtime?: 'edge' | 'serverless';
|
|
11
|
+
/**
|
|
12
|
+
* Vercel Build Output API output directory.
|
|
13
|
+
* Default: '.vercel/output' (relative to project root)
|
|
14
|
+
*/
|
|
15
|
+
outputDir?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Node.js version for serverless runtime.
|
|
18
|
+
* Only used when runtime === 'serverless'.
|
|
19
|
+
* Default: 'nodejs18.x'
|
|
20
|
+
*/
|
|
21
|
+
nodeVersion?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Vercel adapter for aihu (Build Output API v3).
|
|
25
|
+
*
|
|
26
|
+
* Copies static assets to `.vercel/output/static/`, writes an Edge or
|
|
27
|
+
* Serverless function entry, and emits the `config.json` routes manifest.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* // aihu.config.ts
|
|
31
|
+
* import { defineConfig } from '@aihu/app'
|
|
32
|
+
* import { vercel } from '@aihu/adapter-vercel'
|
|
33
|
+
*
|
|
34
|
+
* export default defineConfig({
|
|
35
|
+
* adapter: vercel(),
|
|
36
|
+
* })
|
|
37
|
+
*/
|
|
38
|
+
declare function vercel(options?: VercelAdapterOptions): AihuAdapter;
|
|
39
|
+
//#endregion
|
|
40
|
+
export { VercelAdapterOptions, vercel };
|
|
41
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;UAIiB,oBAAA;;AAAjB;;;;EAME,OAAA;EAKA;;;;EAAA,SAAA;EA8FoB;;;;;EAxFpB,WAAA;AAAA;;;;;;;;;;;;;;;;iBAwFc,MAAA,CAAO,OAAA,GAAU,oBAAA,GAAuB,WAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import{cp as e,mkdir as t,rm as n}from"node:fs/promises";import{join as r,resolve as i}from"node:path";function a(){return[`// AUTO-GENERATED by @aihu/adapter-vercel — do not edit`,`// Vercel Edge Function entry — SPA mode`,`//`,`// In SPA mode (V0), this function handles /api/** routes only.`,`// All page requests are served by Vercel CDN from static/index.html.`,`// For SSR mode, upgrade to @aihu/adapter-vercel with ssr: true (V1+).`,``,`export default async function handler(request) {`,` const url = new URL(request.url)`,` if (!url.pathname.startsWith('/api/')) {`,` return new Response('Not Found', { status: 404 })`,` }`,` return new Response('API route not implemented', { status: 501 })`,`}`,``,`export const config = { runtime: 'edge' }`].join(`
|
|
2
|
+
`)+`
|
|
3
|
+
`}function o(){return[`// AUTO-GENERATED by @aihu/adapter-vercel — do not edit`,`// Vercel Serverless Function entry — SPA mode`,``,`export default async function handler(request, response) {`,` const host = request.headers.host ?? "localhost"`," const url = new URL(request.url, `https://${host}`)",` if (!url.pathname.startsWith('/api/')) {`,` response.status(404).send("Not Found")`,` return`,` }`,` response.status(501).send("API route not implemented")`,`}`].join(`
|
|
4
|
+
`)+`
|
|
5
|
+
`}function s(e,t){return e===`edge`?JSON.stringify({runtime:`edge`,entrypoint:`index.js`},null,2)+`
|
|
6
|
+
`:JSON.stringify({runtime:t,handler:`index.js`,maxDuration:10},null,2)+`
|
|
7
|
+
`}function c(){return JSON.stringify({version:3,routes:[{src:`^/assets/(.*)$`,headers:{"cache-control":`public, max-age=31536000, immutable`},continue:!0},{src:`^/api/(.*)$`,dest:`/index.func`},{src:`^/(.*)$`,dest:`/static/index.html`}]},null,2)+`
|
|
8
|
+
`}function l(l){return{name:`vercel`,async adapt(u){let d=l?.runtime??`edge`,f=l?.nodeVersion??`nodejs18.x`,p=i(u.root,l?.outputDir??`.vercel/output`);await n(p,{recursive:!0,force:!0}),await t(p,{recursive:!0});let m=r(p,`static`);await t(m,{recursive:!0}),await e(u.outDir,m,{recursive:!0,force:!0}),console.log(`[@aihu/adapter-vercel] Copied static assets → ${m}`);let h=r(p,`functions`,`index.func`);await t(h,{recursive:!0});let g=d===`edge`?a():o();await u.writeFile(r(h,`index.js`),g);let _=s(d,f);await u.writeFile(r(h,`.vc-config.json`),_),console.log(`[@aihu/adapter-vercel] Wrote function entry (${d} runtime) → ${h}`);let v=c();await u.writeFile(r(p,`config.json`),v),console.log(`[@aihu/adapter-vercel] Build complete → ${p}`),console.log(`[@aihu/adapter-vercel] Deploy with: vercel deploy --prebuilt`)}}}export{l as vercel};
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["resolvePath"],"sources":["../src/index.ts"],"sourcesContent":["import { cp, mkdir, rm } from 'node:fs/promises'\nimport { join, resolve as resolvePath } from 'node:path'\nimport type { AdapterContext, AihuAdapter } from '@aihu/app'\n\nexport interface VercelAdapterOptions {\n /**\n * Edge Function runtime.\n * - 'edge': Vercel Edge Runtime (V8 isolates, global deployment) — default\n * - 'serverless': Node.js serverless function (regional)\n */\n runtime?: 'edge' | 'serverless'\n /**\n * Vercel Build Output API output directory.\n * Default: '.vercel/output' (relative to project root)\n */\n outputDir?: string\n /**\n * Node.js version for serverless runtime.\n * Only used when runtime === 'serverless'.\n * Default: 'nodejs18.x'\n */\n nodeVersion?: string\n}\n\nfunction generateEdgeFunctionEntry(): string {\n return (\n [\n '// AUTO-GENERATED by @aihu/adapter-vercel — do not edit',\n '// Vercel Edge Function entry — SPA mode',\n '//',\n '// In SPA mode (V0), this function handles /api/** routes only.',\n '// All page requests are served by Vercel CDN from static/index.html.',\n '// For SSR mode, upgrade to @aihu/adapter-vercel with ssr: true (V1+).',\n '',\n 'export default async function handler(request) {',\n ' const url = new URL(request.url)',\n \" if (!url.pathname.startsWith('/api/')) {\",\n \" return new Response('Not Found', { status: 404 })\",\n ' }',\n \" return new Response('API route not implemented', { status: 501 })\",\n '}',\n '',\n \"export const config = { runtime: 'edge' }\",\n ].join('\\n') + '\\n'\n )\n}\n\nfunction generateServerlessFunctionEntry(): string {\n return (\n [\n '// AUTO-GENERATED by @aihu/adapter-vercel — do not edit',\n '// Vercel Serverless Function entry — SPA mode',\n '',\n 'export default async function handler(request, response) {',\n ' const host = request.headers.host ?? \"localhost\"',\n ' const url = new URL(request.url, `https://${host}`)',\n \" if (!url.pathname.startsWith('/api/')) {\",\n ' response.status(404).send(\"Not Found\")',\n ' return',\n ' }',\n ' response.status(501).send(\"API route not implemented\")',\n '}',\n ].join('\\n') + '\\n'\n )\n}\n\nfunction generateVcConfig(runtime: 'edge' | 'serverless', nodeVersion: string): string {\n if (runtime === 'edge') {\n return JSON.stringify({ runtime: 'edge', entrypoint: 'index.js' }, null, 2) + '\\n'\n }\n return (\n JSON.stringify({ runtime: nodeVersion, handler: 'index.js', maxDuration: 10 }, null, 2) + '\\n'\n )\n}\n\nfunction generateConfigJson(): string {\n const routes = [\n {\n src: '^/assets/(.*)$',\n headers: { 'cache-control': 'public, max-age=31536000, immutable' },\n continue: true,\n },\n {\n src: '^/api/(.*)$',\n dest: '/index.func',\n },\n {\n src: '^/(.*)$',\n dest: '/static/index.html',\n },\n ]\n return JSON.stringify({ version: 3, routes }, null, 2) + '\\n'\n}\n\n/**\n * Vercel adapter for aihu (Build Output API v3).\n *\n * Copies static assets to `.vercel/output/static/`, writes an Edge or\n * Serverless function entry, and emits the `config.json` routes manifest.\n *\n * @example\n * // aihu.config.ts\n * import { defineConfig } from '@aihu/app'\n * import { vercel } from '@aihu/adapter-vercel'\n *\n * export default defineConfig({\n * adapter: vercel(),\n * })\n */\nexport function vercel(options?: VercelAdapterOptions): AihuAdapter {\n return {\n name: 'vercel',\n\n async adapt(context: AdapterContext): Promise<void> {\n const runtime = options?.runtime ?? 'edge'\n const nodeVersion = options?.nodeVersion ?? 'nodejs18.x'\n const outputDir = resolvePath(context.root, options?.outputDir ?? '.vercel/output')\n\n // Step 1 — Clean output directory (prevents stale files from prior builds)\n await rm(outputDir, { recursive: true, force: true })\n await mkdir(outputDir, { recursive: true })\n\n // Step 2 — Copy static assets from Vite outDir → .vercel/output/static/\n const staticDir = join(outputDir, 'static')\n await mkdir(staticDir, { recursive: true })\n await cp(context.outDir, staticDir, { recursive: true, force: true })\n console.log(`[@aihu/adapter-vercel] Copied static assets → ${staticDir}`)\n\n // Step 3 — Write Edge/Serverless function entry\n const funcDir = join(outputDir, 'functions', 'index.func')\n await mkdir(funcDir, { recursive: true })\n\n const entryContent =\n runtime === 'edge' ? generateEdgeFunctionEntry() : generateServerlessFunctionEntry()\n await context.writeFile(join(funcDir, 'index.js'), entryContent)\n\n // Step 4 — Write .vc-config.json\n const vcConfig = generateVcConfig(runtime, nodeVersion)\n await context.writeFile(join(funcDir, '.vc-config.json'), vcConfig)\n console.log(`[@aihu/adapter-vercel] Wrote function entry (${runtime} runtime) → ${funcDir}`)\n\n // Step 5 — Write config.json (Build Output API v3 routes)\n const configJson = generateConfigJson()\n await context.writeFile(join(outputDir, 'config.json'), configJson)\n\n console.log(`[@aihu/adapter-vercel] Build complete → ${outputDir}`)\n console.log(`[@aihu/adapter-vercel] Deploy with: vercel deploy --prebuilt`)\n },\n }\n}\n"],"mappings":"uGAwBA,SAAS,GAAoC,CAC3C,MACE,CACE,0DACA,2CACA,KACA,kEACA,wEACA,yEACA,GACA,mDACA,qCACA,6CACA,wDACA,MACA,sEACA,IACA,GACA,4CACD,CAAC,KAAK;EAAK,CAAG;EAInB,SAAS,GAA0C,CACjD,MACE,CACE,0DACA,iDACA,GACA,6DACA,qDACA,wDACA,6CACA,6CACA,aACA,MACA,2DACA,IACD,CAAC,KAAK;EAAK,CAAG;EAInB,SAAS,EAAiB,EAAgC,EAA6B,CAIrF,OAHI,IAAY,OACP,KAAK,UAAU,CAAE,QAAS,OAAQ,WAAY,WAAY,CAAE,KAAM,EAAE,CAAG;EAG9E,KAAK,UAAU,CAAE,QAAS,EAAa,QAAS,WAAY,YAAa,GAAI,CAAE,KAAM,EAAE,CAAG;EAI9F,SAAS,GAA6B,CAgBpC,OAAO,KAAK,UAAU,CAAE,QAAS,EAAG,OAAA,CAdlC,CACE,IAAK,iBACL,QAAS,CAAE,gBAAiB,sCAAuC,CACnE,SAAU,GACX,CACD,CACE,IAAK,cACL,KAAM,cACP,CACD,CACE,IAAK,UACL,KAAM,qBACP,CAEuC,CAAE,CAAE,KAAM,EAAE,CAAG;EAkB3D,SAAgB,EAAO,EAA6C,CAClE,MAAO,CACL,KAAM,SAEN,MAAM,MAAM,EAAwC,CAClD,IAAM,EAAU,GAAS,SAAW,OAC9B,EAAc,GAAS,aAAe,aACtC,EAAYA,EAAY,EAAQ,KAAM,GAAS,WAAa,iBAAiB,CAGnF,MAAM,EAAG,EAAW,CAAE,UAAW,GAAM,MAAO,GAAM,CAAC,CACrD,MAAM,EAAM,EAAW,CAAE,UAAW,GAAM,CAAC,CAG3C,IAAM,EAAY,EAAK,EAAW,SAAS,CAC3C,MAAM,EAAM,EAAW,CAAE,UAAW,GAAM,CAAC,CAC3C,MAAM,EAAG,EAAQ,OAAQ,EAAW,CAAE,UAAW,GAAM,MAAO,GAAM,CAAC,CACrE,QAAQ,IAAI,iDAAiD,IAAY,CAGzE,IAAM,EAAU,EAAK,EAAW,YAAa,aAAa,CAC1D,MAAM,EAAM,EAAS,CAAE,UAAW,GAAM,CAAC,CAEzC,IAAM,EACJ,IAAY,OAAS,GAA2B,CAAG,GAAiC,CACtF,MAAM,EAAQ,UAAU,EAAK,EAAS,WAAW,CAAE,EAAa,CAGhE,IAAM,EAAW,EAAiB,EAAS,EAAY,CACvD,MAAM,EAAQ,UAAU,EAAK,EAAS,kBAAkB,CAAE,EAAS,CACnE,QAAQ,IAAI,gDAAgD,EAAQ,cAAc,IAAU,CAG5F,IAAM,EAAa,GAAoB,CACvC,MAAM,EAAQ,UAAU,EAAK,EAAW,cAAc,CAAE,EAAW,CAEnE,QAAQ,IAAI,2CAA2C,IAAY,CACnE,QAAQ,IAAI,+DAA+D,EAE9E"}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aihu/adapter-vercel",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "rolldown -c",
|
|
23
|
+
"typecheck": "tsc --noEmit",
|
|
24
|
+
"test": "vitest run",
|
|
25
|
+
"prepublishOnly": "bun run build"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"@aihu/app": "workspace:*",
|
|
29
|
+
"vite": ">=5.0.0"
|
|
30
|
+
},
|
|
31
|
+
"description": "Vercel deployment adapter for @aihu/app.",
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/fellwork/aihu.git",
|
|
35
|
+
"directory": "packages/adapter-vercel"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/fellwork/aihu/tree/main/packages/adapter-vercel#readme",
|
|
38
|
+
"bugs": "https://github.com/fellwork/aihu/issues",
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
}
|
|
42
|
+
}
|