@aiendpoint/fastify 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,45 @@
1
+ # @aiendpoint/fastify
2
+
3
+ Serve your `/ai` endpoint from Fastify in one line.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @aiendpoint/fastify
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import Fastify from 'fastify'
15
+ import aiendpoint from '@aiendpoint/fastify'
16
+
17
+ const app = Fastify()
18
+ app.register(aiendpoint, { spec: './ai.json' })
19
+
20
+ app.listen({ port: 3000 })
21
+ ```
22
+
23
+ That's it. `GET /ai` now serves your spec.
24
+
25
+ ## Options
26
+
27
+ ```ts
28
+ app.register(aiendpoint, {
29
+ spec: './ai.json', // path to spec file, or inline object
30
+ path: '/ai', // route path (default: '/ai')
31
+ maxAge: 3600, // Cache-Control max-age (default: 3600)
32
+ })
33
+ ```
34
+
35
+ ## Generate ai.json
36
+
37
+ ```bash
38
+ npx @aiendpoint/cli init --openapi https://your-api.com/openapi.json
39
+ ```
40
+
41
+ ## Links
42
+
43
+ - [AIEndpoint spec](https://aiendpoint.dev/docs)
44
+ - [@aiendpoint/cli](https://www.npmjs.com/package/@aiendpoint/cli)
45
+ - [GitHub](https://github.com/aiendpoint/platform)
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @aiendpoint/fastify - Serve /ai from Fastify in one line.
3
+ *
4
+ * Usage:
5
+ * import aiendpoint from '@aiendpoint/fastify'
6
+ * app.register(aiendpoint, { spec: './ai.json' })
7
+ *
8
+ * // or with inline spec:
9
+ * app.register(aiendpoint, { spec: { aiendpoint: '1.0', ... } })
10
+ */
11
+ import type { FastifyInstance, FastifyPluginOptions } from 'fastify';
12
+ interface AiEndpointOptions extends FastifyPluginOptions {
13
+ /** Path to ai.json file (relative to cwd) or inline spec object */
14
+ spec: string | Record<string, unknown>;
15
+ /** Route path (default: '/ai') */
16
+ path?: string;
17
+ /** Cache-Control max-age in seconds (default: 3600) */
18
+ maxAge?: number;
19
+ }
20
+ declare function aiendpointPlugin(app: FastifyInstance, opts: AiEndpointOptions): Promise<void>;
21
+ export default aiendpointPlugin;
22
+ export { aiendpointPlugin as aiendpoint };
package/dist/index.js ADDED
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @aiendpoint/fastify - Serve /ai from Fastify in one line.
3
+ *
4
+ * Usage:
5
+ * import aiendpoint from '@aiendpoint/fastify'
6
+ * app.register(aiendpoint, { spec: './ai.json' })
7
+ *
8
+ * // or with inline spec:
9
+ * app.register(aiendpoint, { spec: { aiendpoint: '1.0', ... } })
10
+ */
11
+ import { readFileSync } from 'node:fs';
12
+ import { resolve } from 'node:path';
13
+ async function aiendpointPlugin(app, opts) {
14
+ const { path: routePath = '/ai', maxAge = 3600 } = opts;
15
+ let specData;
16
+ if (typeof opts.spec === 'string') {
17
+ const specPath = resolve(process.cwd(), opts.spec);
18
+ const raw = readFileSync(specPath, 'utf-8');
19
+ specData = JSON.parse(raw);
20
+ }
21
+ else {
22
+ specData = opts.spec;
23
+ }
24
+ app.get(routePath, async (_req, reply) => {
25
+ reply
26
+ .header('Content-Type', 'application/json')
27
+ .header('Cache-Control', `public, max-age=${maxAge}`)
28
+ .send(specData);
29
+ });
30
+ }
31
+ export default aiendpointPlugin;
32
+ export { aiendpointPlugin as aiendpoint };
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAYnC,KAAK,UAAU,gBAAgB,CAAC,GAAoB,EAAE,IAAuB;IAC3E,MAAM,EAAE,IAAI,EAAE,SAAS,GAAG,KAAK,EAAE,MAAM,GAAG,IAAI,EAAE,GAAG,IAAI,CAAA;IAEvD,IAAI,QAAiC,CAAA;IAErC,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAClC,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAA;QAClD,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,IAAI,CAAC,IAAI,CAAA;IACtB,CAAC;IAED,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;QACvC,KAAK;aACF,MAAM,CAAC,cAAc,EAAE,kBAAkB,CAAC;aAC1C,MAAM,CAAC,eAAe,EAAE,mBAAmB,MAAM,EAAE,CAAC;aACpD,IAAI,CAAC,QAAQ,CAAC,CAAA;IACnB,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,eAAe,gBAAgB,CAAA;AAC/B,OAAO,EAAE,gBAAgB,IAAI,UAAU,EAAE,CAAA"}
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@aiendpoint/fastify",
3
+ "version": "0.1.0",
4
+ "description": "Serve your /ai endpoint from Fastify 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
+ "fastify",
23
+ "ai",
24
+ "api",
25
+ "plugin"
26
+ ],
27
+ "license": "Apache-2.0",
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "https://github.com/aiendpoint/platform",
31
+ "directory": "packages/fastify"
32
+ },
33
+ "homepage": "https://aiendpoint.dev",
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "peerDependencies": {
38
+ "fastify": ">=4"
39
+ },
40
+ "devDependencies": {
41
+ "@types/node": "^22.10.0",
42
+ "fastify": "^5.8.4",
43
+ "typescript": "^5.7.2"
44
+ }
45
+ }