@aiendpoint/next 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/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # @aiendpoint/next
2
+
3
+ Serve your `/ai` endpoint from Next.js App Router in one line.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @aiendpoint/next
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ Create `app/ai/route.ts`:
14
+
15
+ ```ts
16
+ import { aiendpoint } from '@aiendpoint/next'
17
+
18
+ export const GET = aiendpoint({ spec: './ai.json' })
19
+ ```
20
+
21
+ That's it. Your service now has a `/ai` endpoint.
22
+
23
+ ## Options
24
+
25
+ ```ts
26
+ aiendpoint({
27
+ spec: './ai.json', // path to spec file, or inline object
28
+ maxAge: 3600, // Cache-Control max-age (default: 3600)
29
+ })
30
+ ```
31
+
32
+ ## Generate ai.json
33
+
34
+ ```bash
35
+ npx @aiendpoint/cli init --openapi https://your-api.com/openapi.json
36
+ ```
37
+
38
+ ## Links
39
+
40
+ - [AIEndpoint spec](https://aiendpoint.dev/docs)
41
+ - [@aiendpoint/cli](https://www.npmjs.com/package/@aiendpoint/cli)
42
+ - [GitHub](https://github.com/aiendpoint/platform)
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @aiendpoint/next - Serve /ai from Next.js App Router in one line.
3
+ *
4
+ * Usage:
5
+ * // app/ai/route.ts
6
+ * import { aiendpoint } from '@aiendpoint/next'
7
+ * export const GET = aiendpoint({ spec: './ai.json' })
8
+ *
9
+ * // or with inline spec:
10
+ * export const GET = aiendpoint({ spec: { aiendpoint: '1.0', ... } })
11
+ */
12
+ import { NextResponse } from 'next/server';
13
+ interface AiEndpointOptions {
14
+ /** Path to ai.json file (relative to project root) or inline spec object */
15
+ spec: string | Record<string, unknown>;
16
+ /** Cache-Control max-age in seconds (default: 3600) */
17
+ maxAge?: number;
18
+ }
19
+ export declare function aiendpoint(options: AiEndpointOptions): () => Promise<NextResponse<Record<string, unknown>>>;
20
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @aiendpoint/next - Serve /ai from Next.js App Router in one line.
3
+ *
4
+ * Usage:
5
+ * // app/ai/route.ts
6
+ * import { aiendpoint } from '@aiendpoint/next'
7
+ * export const GET = aiendpoint({ spec: './ai.json' })
8
+ *
9
+ * // or with inline spec:
10
+ * export const GET = aiendpoint({ spec: { aiendpoint: '1.0', ... } })
11
+ */
12
+ import { readFileSync } from 'node:fs';
13
+ import { resolve } from 'node:path';
14
+ import { NextResponse } from 'next/server';
15
+ export function aiendpoint(options) {
16
+ const { maxAge = 3600 } = options;
17
+ let specData;
18
+ if (typeof options.spec === 'string') {
19
+ const specPath = resolve(process.cwd(), options.spec);
20
+ const raw = readFileSync(specPath, 'utf-8');
21
+ specData = JSON.parse(raw);
22
+ }
23
+ else {
24
+ specData = options.spec;
25
+ }
26
+ return async function GET() {
27
+ return NextResponse.json(specData, {
28
+ headers: {
29
+ 'Cache-Control': `public, max-age=${maxAge}`,
30
+ },
31
+ });
32
+ };
33
+ }
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAS1C,MAAM,UAAU,UAAU,CAAC,OAA0B;IACnD,MAAM,EAAE,MAAM,GAAG,IAAI,EAAE,GAAG,OAAO,CAAA;IAEjC,IAAI,QAAiC,CAAA;IAErC,IAAI,OAAO,OAAO,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACrC,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;QACrD,MAAM,GAAG,GAAG,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;QAC3C,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC5B,CAAC;SAAM,CAAC;QACN,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAA;IACzB,CAAC;IAED,OAAO,KAAK,UAAU,GAAG;QACvB,OAAO,YAAY,CAAC,IAAI,CAAC,QAAQ,EAAE;YACjC,OAAO,EAAE;gBACP,eAAe,EAAE,mBAAmB,MAAM,EAAE;aAC7C;SACF,CAAC,CAAA;IACJ,CAAC,CAAA;AACH,CAAC"}
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@aiendpoint/next",
3
+ "version": "0.1.0",
4
+ "description": "Serve your /ai endpoint from Next.js App Router in one line",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist",
10
+ "README.md"
11
+ ],
12
+ "scripts": {
13
+ "build": "tsc",
14
+ "clean": "rm -rf dist",
15
+ "prepublishOnly": "npm run build"
16
+ },
17
+ "engines": {
18
+ "node": ">=18"
19
+ },
20
+ "keywords": [
21
+ "aiendpoint",
22
+ "nextjs",
23
+ "next",
24
+ "ai",
25
+ "api",
26
+ "middleware"
27
+ ],
28
+ "license": "Apache-2.0",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "https://github.com/aiendpoint/platform",
32
+ "directory": "packages/next"
33
+ },
34
+ "homepage": "https://aiendpoint.dev",
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "peerDependencies": {
39
+ "next": ">=14"
40
+ },
41
+ "devDependencies": {
42
+ "@types/node": "^22.10.0",
43
+ "next": "^16.0.0",
44
+ "typescript": "^5.7.2"
45
+ }
46
+ }