ai.matey.http 0.2.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/dist/cjs/deno/adapter.js +173 -0
- package/dist/cjs/deno/adapter.js.map +1 -0
- package/dist/cjs/deno/handler.js +78 -0
- package/dist/cjs/deno/handler.js.map +1 -0
- package/dist/cjs/deno/index.js +26 -0
- package/dist/cjs/deno/index.js.map +1 -0
- package/dist/cjs/express/adapter.js +150 -0
- package/dist/cjs/express/adapter.js.map +1 -0
- package/dist/cjs/express/index.js +26 -0
- package/dist/cjs/express/index.js.map +1 -0
- package/dist/cjs/express/middleware.js +63 -0
- package/dist/cjs/express/middleware.js.map +1 -0
- package/dist/cjs/fastify/adapter.js +149 -0
- package/dist/cjs/fastify/adapter.js.map +1 -0
- package/dist/cjs/fastify/handler.js +54 -0
- package/dist/cjs/fastify/handler.js.map +1 -0
- package/dist/cjs/fastify/index.js +26 -0
- package/dist/cjs/fastify/index.js.map +1 -0
- package/dist/cjs/hono/adapter.js +172 -0
- package/dist/cjs/hono/adapter.js.map +1 -0
- package/dist/cjs/hono/index.js +26 -0
- package/dist/cjs/hono/index.js.map +1 -0
- package/dist/cjs/hono/middleware.js +75 -0
- package/dist/cjs/hono/middleware.js.map +1 -0
- package/dist/cjs/index.js +37 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/koa/adapter.js +153 -0
- package/dist/cjs/koa/adapter.js.map +1 -0
- package/dist/cjs/koa/index.js +26 -0
- package/dist/cjs/koa/index.js.map +1 -0
- package/dist/cjs/koa/middleware.js +58 -0
- package/dist/cjs/koa/middleware.js.map +1 -0
- package/dist/cjs/node/adapter.js +170 -0
- package/dist/cjs/node/adapter.js.map +1 -0
- package/dist/cjs/node/index.js +26 -0
- package/dist/cjs/node/index.js.map +1 -0
- package/dist/cjs/node/listener.js +98 -0
- package/dist/cjs/node/listener.js.map +1 -0
- package/dist/esm/deno/adapter.js +168 -0
- package/dist/esm/deno/adapter.js.map +1 -0
- package/dist/esm/deno/handler.js +75 -0
- package/dist/esm/deno/handler.js.map +1 -0
- package/dist/esm/deno/index.js +10 -0
- package/dist/esm/deno/index.js.map +1 -0
- package/dist/esm/express/adapter.js +145 -0
- package/dist/esm/express/adapter.js.map +1 -0
- package/dist/esm/express/index.js +10 -0
- package/dist/esm/express/index.js.map +1 -0
- package/dist/esm/express/middleware.js +60 -0
- package/dist/esm/express/middleware.js.map +1 -0
- package/dist/esm/fastify/adapter.js +144 -0
- package/dist/esm/fastify/adapter.js.map +1 -0
- package/dist/esm/fastify/handler.js +51 -0
- package/dist/esm/fastify/handler.js.map +1 -0
- package/dist/esm/fastify/index.js +10 -0
- package/dist/esm/fastify/index.js.map +1 -0
- package/dist/esm/hono/adapter.js +167 -0
- package/dist/esm/hono/adapter.js.map +1 -0
- package/dist/esm/hono/index.js +10 -0
- package/dist/esm/hono/index.js.map +1 -0
- package/dist/esm/hono/middleware.js +72 -0
- package/dist/esm/hono/middleware.js.map +1 -0
- package/dist/esm/index.js +21 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/koa/adapter.js +148 -0
- package/dist/esm/koa/adapter.js.map +1 -0
- package/dist/esm/koa/index.js +10 -0
- package/dist/esm/koa/index.js.map +1 -0
- package/dist/esm/koa/middleware.js +55 -0
- package/dist/esm/koa/middleware.js.map +1 -0
- package/dist/esm/node/adapter.js +165 -0
- package/dist/esm/node/adapter.js.map +1 -0
- package/dist/esm/node/index.js +10 -0
- package/dist/esm/node/index.js.map +1 -0
- package/dist/esm/node/listener.js +92 -0
- package/dist/esm/node/listener.js.map +1 -0
- package/dist/types/deno/adapter.d.ts +56 -0
- package/dist/types/deno/adapter.d.ts.map +1 -0
- package/dist/types/deno/handler.d.ts +38 -0
- package/dist/types/deno/handler.d.ts.map +1 -0
- package/dist/types/deno/index.d.ts +10 -0
- package/dist/types/deno/index.d.ts.map +1 -0
- package/dist/types/express/adapter.d.ts +46 -0
- package/dist/types/express/adapter.d.ts.map +1 -0
- package/dist/types/express/index.d.ts +10 -0
- package/dist/types/express/index.d.ts.map +1 -0
- package/dist/types/express/middleware.d.ts +39 -0
- package/dist/types/express/middleware.d.ts.map +1 -0
- package/dist/types/fastify/adapter.d.ts +46 -0
- package/dist/types/fastify/adapter.d.ts.map +1 -0
- package/dist/types/fastify/handler.d.ts +36 -0
- package/dist/types/fastify/handler.d.ts.map +1 -0
- package/dist/types/fastify/index.d.ts +10 -0
- package/dist/types/fastify/index.d.ts.map +1 -0
- package/dist/types/hono/adapter.d.ts +47 -0
- package/dist/types/hono/adapter.d.ts.map +1 -0
- package/dist/types/hono/index.d.ts +10 -0
- package/dist/types/hono/index.d.ts.map +1 -0
- package/dist/types/hono/middleware.d.ts +36 -0
- package/dist/types/hono/middleware.d.ts.map +1 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/koa/adapter.d.ts +46 -0
- package/dist/types/koa/adapter.d.ts.map +1 -0
- package/dist/types/koa/index.d.ts +10 -0
- package/dist/types/koa/index.d.ts.map +1 -0
- package/dist/types/koa/middleware.d.ts +40 -0
- package/dist/types/koa/middleware.d.ts.map +1 -0
- package/dist/types/node/adapter.d.ts +57 -0
- package/dist/types/node/adapter.d.ts.map +1 -0
- package/dist/types/node/index.d.ts +10 -0
- package/dist/types/node/index.d.ts.map +1 -0
- package/dist/types/node/listener.d.ts +51 -0
- package/dist/types/node/listener.d.ts.map +1 -0
- package/package.json +160 -0
- package/readme.md +93 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/hono/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1E;;GAEG;AACH,qBAAa,kBAAmB,YAAW,cAAc;IAC3C,OAAO,CAAC,CAAC;gBAAD,CAAC,EAAE,OAAO;IAE9B,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,GAAG,IAAI,MAAM,CAEhB;IAED,IAAI,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CASpC;IAED,IAAI,IAAI,IAAI,GAAG,CAId;IAED,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAI/C;IAED,IAAI,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAY9C;IAED,IAAI,EAAE,IAAI,MAAM,GAAG,SAAS,CAc3B;IAED;;OAEG;IACH,IAAI,GAAG,IAAI,OAAO,CAEjB;CACF;AAED;;GAEG;AACH,qBAAa,mBAAoB,YAAW,eAAe;IAK7C,OAAO,CAAC,CAAC;IAJrB,OAAO,CAAC,WAAW,CAAe;IAClC,OAAO,CAAC,QAAQ,CAAkC;IAClD,OAAO,CAAC,KAAK,CAAkB;gBAEX,CAAC,EAAE,OAAO;IAE9B,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAM1B,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAMzC,IAAI,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;IAgCrB,MAAM,CAAC,SAAS,EAAE,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE,SAAS,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IA8CtE,UAAU,IAAI,OAAO;IAIrB;;OAEG;IACH,IAAI,GAAG,IAAI,OAAO,CAEjB;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hono/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hono Middleware
|
|
3
|
+
*
|
|
4
|
+
* HTTP request middleware for Hono that uses the core handler.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import type { MiddlewareHandler } from 'hono';
|
|
9
|
+
import type { Bridge } from 'ai.matey.core';
|
|
10
|
+
import type { HTTPListenerOptions } from 'ai.matey.http.core';
|
|
11
|
+
/**
|
|
12
|
+
* Create Hono middleware for handling AI chat requests
|
|
13
|
+
*
|
|
14
|
+
* @param bridge - Bridge instance
|
|
15
|
+
* @param options - HTTP listener options
|
|
16
|
+
* @returns Hono middleware function
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { Hono } from 'hono';
|
|
21
|
+
* import { HonoMiddleware } from 'ai.matey.http/hono';
|
|
22
|
+
*
|
|
23
|
+
* const app = new Hono();
|
|
24
|
+
* const bridge = new Bridge(frontend, backend);
|
|
25
|
+
*
|
|
26
|
+
* // Add AI chat middleware
|
|
27
|
+
* app.post('/v1/messages', HonoMiddleware(bridge, {
|
|
28
|
+
* cors: true,
|
|
29
|
+
* streaming: true,
|
|
30
|
+
* }));
|
|
31
|
+
*
|
|
32
|
+
* export default app;
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function HonoMiddleware(bridge: Bridge, options?: HTTPListenerOptions): MiddlewareHandler;
|
|
36
|
+
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../../src/hono/middleware.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAW,iBAAiB,EAAE,MAAM,MAAM,CAAC;AACvD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAI9D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,mBAAwB,GAChC,iBAAiB,CAyCnB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Matey HTTP Adapters
|
|
3
|
+
*
|
|
4
|
+
* Consolidated package containing HTTP framework adapters.
|
|
5
|
+
* Each adapter provides integration with a specific HTTP framework.
|
|
6
|
+
*
|
|
7
|
+
* @module ai.matey.http
|
|
8
|
+
*/
|
|
9
|
+
export * from './express/index.js';
|
|
10
|
+
export * from './fastify/index.js';
|
|
11
|
+
export * from './hono/index.js';
|
|
12
|
+
export * from './koa/index.js';
|
|
13
|
+
export * from './node/index.js';
|
|
14
|
+
export * from './deno/index.js';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,cAAc,oBAAoB,CAAC;AAGnC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,iBAAiB,CAAC;AAGhC,cAAc,gBAAgB,CAAC;AAG/B,cAAc,iBAAiB,CAAC;AAGhC,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Koa HTTP Adapter
|
|
3
|
+
*
|
|
4
|
+
* Converts Koa Context to GenericRequest/GenericResponse
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import type { Context } from 'koa';
|
|
9
|
+
import type { GenericRequest, GenericResponse } from 'ai.matey.http.core';
|
|
10
|
+
/**
|
|
11
|
+
* Adapter that converts Koa Context to GenericRequest
|
|
12
|
+
*/
|
|
13
|
+
export declare class KoaRequestAdapter implements GenericRequest {
|
|
14
|
+
private ctx;
|
|
15
|
+
constructor(ctx: Context);
|
|
16
|
+
get method(): string;
|
|
17
|
+
get url(): string;
|
|
18
|
+
get headers(): Record<string, string>;
|
|
19
|
+
get body(): any;
|
|
20
|
+
get params(): Record<string, string> | undefined;
|
|
21
|
+
get query(): Record<string, string> | undefined;
|
|
22
|
+
get ip(): string | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Get the underlying Koa context object
|
|
25
|
+
*/
|
|
26
|
+
get raw(): Context;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Adapter that converts GenericResponse methods to Koa Context
|
|
30
|
+
*/
|
|
31
|
+
export declare class KoaResponseAdapter implements GenericResponse {
|
|
32
|
+
private ctx;
|
|
33
|
+
private _statusCode;
|
|
34
|
+
private _headersSent;
|
|
35
|
+
constructor(ctx: Context);
|
|
36
|
+
status(code: number): void;
|
|
37
|
+
header(name: string, value: string): void;
|
|
38
|
+
send(data: any): void;
|
|
39
|
+
stream(generator: AsyncGenerator<any, void, undefined>): Promise<void>;
|
|
40
|
+
isWritable(): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Get the underlying Koa context object
|
|
43
|
+
*/
|
|
44
|
+
get raw(): Context;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/koa/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACnC,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAG1E;;GAEG;AACH,qBAAa,iBAAkB,YAAW,cAAc;IAC1C,OAAO,CAAC,GAAG;gBAAH,GAAG,EAAE,OAAO;IAEhC,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,GAAG,IAAI,MAAM,CAEhB;IAED,IAAI,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAYpC;IAED,IAAI,IAAI,IAAI,GAAG,CAGd;IAED,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAG/C;IAED,IAAI,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAe9C;IAED,IAAI,EAAE,IAAI,MAAM,GAAG,SAAS,CAG3B;IAED;;OAEG;IACH,IAAI,GAAG,IAAI,OAAO,CAEjB;CACF;AAED;;GAEG;AACH,qBAAa,kBAAmB,YAAW,eAAe;IAI5C,OAAO,CAAC,GAAG;IAHvB,OAAO,CAAC,WAAW,CAAe;IAClC,OAAO,CAAC,YAAY,CAAkB;gBAElB,GAAG,EAAE,OAAO;IAEhC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAO1B,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAMzC,IAAI,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;IAkBf,MAAM,CAAC,SAAS,EAAE,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE,SAAS,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAwC5E,UAAU,IAAI,OAAO;IAIrB;;OAEG;IACH,IAAI,GAAG,IAAI,OAAO,CAEjB;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/koa/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Koa Middleware
|
|
3
|
+
*
|
|
4
|
+
* HTTP request middleware for Koa that uses the core handler.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import type { Context, Next } from 'koa';
|
|
9
|
+
import type { Bridge } from 'ai.matey.core';
|
|
10
|
+
import type { HTTPListenerOptions } from 'ai.matey.http.core';
|
|
11
|
+
/**
|
|
12
|
+
* Create Koa middleware for handling AI chat requests
|
|
13
|
+
*
|
|
14
|
+
* @param bridge - Bridge instance
|
|
15
|
+
* @param options - HTTP listener options
|
|
16
|
+
* @returns Koa middleware function
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import Koa from 'koa';
|
|
21
|
+
* import bodyParser from 'koa-bodyparser';
|
|
22
|
+
* import { KoaMiddleware } from 'ai.matey.http/koa';
|
|
23
|
+
*
|
|
24
|
+
* const app = new Koa();
|
|
25
|
+
* const bridge = new Bridge(frontend, backend);
|
|
26
|
+
*
|
|
27
|
+
* // Use body parser middleware first
|
|
28
|
+
* app.use(bodyParser());
|
|
29
|
+
*
|
|
30
|
+
* // Add AI chat middleware
|
|
31
|
+
* app.use(KoaMiddleware(bridge, {
|
|
32
|
+
* cors: true,
|
|
33
|
+
* streaming: true,
|
|
34
|
+
* }));
|
|
35
|
+
*
|
|
36
|
+
* app.listen(3000);
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function KoaMiddleware(bridge: Bridge, options?: HTTPListenerOptions): (ctx: Context, next: Next) => Promise<void>;
|
|
40
|
+
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../../src/koa/middleware.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AACzC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAI9D;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,mBAAwB,GAChC,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAmB7C"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js HTTP Adapter
|
|
3
|
+
*
|
|
4
|
+
* Converts Node.js IncomingMessage/ServerResponse to GenericRequest/GenericResponse
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import type { IncomingMessage, ServerResponse } from 'http';
|
|
9
|
+
import type { GenericRequest, GenericResponse } from 'ai.matey.http.core';
|
|
10
|
+
/**
|
|
11
|
+
* Adapter that converts Node.js IncomingMessage to GenericRequest
|
|
12
|
+
*/
|
|
13
|
+
export declare class NodeRequestAdapter implements GenericRequest {
|
|
14
|
+
private req;
|
|
15
|
+
private maxBodySize;
|
|
16
|
+
private _parsed;
|
|
17
|
+
private _parsePromise;
|
|
18
|
+
constructor(req: IncomingMessage, maxBodySize?: number);
|
|
19
|
+
/**
|
|
20
|
+
* Parse the request body if not already parsed
|
|
21
|
+
*/
|
|
22
|
+
private ensureParsed;
|
|
23
|
+
get method(): string;
|
|
24
|
+
get url(): string;
|
|
25
|
+
get headers(): Record<string, string>;
|
|
26
|
+
get body(): any;
|
|
27
|
+
get params(): Record<string, string> | undefined;
|
|
28
|
+
get query(): Record<string, string> | undefined;
|
|
29
|
+
get ip(): string | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Get the underlying Node.js request object
|
|
32
|
+
*/
|
|
33
|
+
get raw(): IncomingMessage;
|
|
34
|
+
/**
|
|
35
|
+
* Parse the request body (called by core handler before accessing body)
|
|
36
|
+
*/
|
|
37
|
+
parse(): Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Adapter that converts GenericResponse methods to Node.js ServerResponse
|
|
41
|
+
*/
|
|
42
|
+
export declare class NodeResponseAdapter implements GenericResponse {
|
|
43
|
+
private res;
|
|
44
|
+
private _statusCode;
|
|
45
|
+
private _headersSent;
|
|
46
|
+
constructor(res: ServerResponse);
|
|
47
|
+
status(code: number): void;
|
|
48
|
+
header(name: string, value: string): void;
|
|
49
|
+
send(data: any): void;
|
|
50
|
+
stream(generator: AsyncGenerator<any, void, undefined>): Promise<void>;
|
|
51
|
+
isWritable(): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Get the underlying Node.js response object
|
|
54
|
+
*/
|
|
55
|
+
get raw(): ServerResponse;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/node/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAS1E;;GAEG;AACH,qBAAa,kBAAmB,YAAW,cAAc;IAKrD,OAAO,CAAC,GAAG;IACX,OAAO,CAAC,WAAW;IALrB,OAAO,CAAC,OAAO,CAAyD;IACxE,OAAO,CAAC,aAAa,CAA8B;gBAGzC,GAAG,EAAE,eAAe,EACpB,WAAW,GAAE,MAAyB;IAGhD;;OAEG;YACW,YAAY;IAkB1B,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,GAAG,IAAI,MAAM,CAEhB;IAED,IAAI,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAYpC;IAED,IAAI,IAAI,IAAI,GAAG,CAGd;IAED,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAG/C;IAED,IAAI,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAE9C;IAED,IAAI,EAAE,IAAI,MAAM,GAAG,SAAS,CAc3B;IAED;;OAEG;IACH,IAAI,GAAG,IAAI,eAAe,CAEzB;IAED;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B;AAED;;GAEG;AACH,qBAAa,mBAAoB,YAAW,eAAe;IAI7C,OAAO,CAAC,GAAG;IAHvB,OAAO,CAAC,WAAW,CAAe;IAClC,OAAO,CAAC,YAAY,CAAkB;gBAElB,GAAG,EAAE,cAAc;IAEvC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAO1B,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAMzC,IAAI,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;IAgBf,MAAM,CAAC,SAAS,EAAE,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE,SAAS,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAkC5E,UAAU,IAAI,OAAO;IAIrB;;OAEG;IACH,IAAI,GAAG,IAAI,cAAc,CAExB;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/node/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js HTTP Listener
|
|
3
|
+
*
|
|
4
|
+
* HTTP request handler for Node.js http.Server that uses the core handler.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import type { Bridge } from 'ai.matey.core';
|
|
9
|
+
import type { HTTPListenerOptions, HTTPRequestHandler } from 'ai.matey.http.core';
|
|
10
|
+
/**
|
|
11
|
+
* Create Node.js HTTP request handler
|
|
12
|
+
*
|
|
13
|
+
* @param bridge - Bridge instance
|
|
14
|
+
* @param options - HTTP listener options
|
|
15
|
+
* @returns HTTP request handler function
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { createServer } from 'http';
|
|
20
|
+
* import { NodeHTTPListener } from 'ai.matey.http/node';
|
|
21
|
+
*
|
|
22
|
+
* const bridge = new Bridge(frontend, backend);
|
|
23
|
+
*
|
|
24
|
+
* const server = createServer(
|
|
25
|
+
* NodeHTTPListener(bridge, {
|
|
26
|
+
* cors: true,
|
|
27
|
+
* streaming: true,
|
|
28
|
+
* })
|
|
29
|
+
* );
|
|
30
|
+
*
|
|
31
|
+
* server.listen(3000);
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function NodeHTTPListener(bridge: Bridge, options?: HTTPListenerOptions): HTTPRequestHandler;
|
|
35
|
+
/**
|
|
36
|
+
* Create simple HTTP listener without advanced features
|
|
37
|
+
*/
|
|
38
|
+
export declare function createSimpleListener(bridge: Bridge): HTTPRequestHandler;
|
|
39
|
+
/**
|
|
40
|
+
* Create HTTP listener with logging enabled
|
|
41
|
+
*/
|
|
42
|
+
export declare function createLoggingListener(bridge: Bridge, log?: (message: string, ...args: any[]) => void): HTTPRequestHandler;
|
|
43
|
+
/**
|
|
44
|
+
* Create HTTP listener with auth and rate limiting
|
|
45
|
+
*/
|
|
46
|
+
export declare function createSecureListener(bridge: Bridge, options: {
|
|
47
|
+
validateAuth: NonNullable<HTTPListenerOptions['validateAuth']>;
|
|
48
|
+
rateLimit?: HTTPListenerOptions['rateLimit'];
|
|
49
|
+
cors?: HTTPListenerOptions['cors'];
|
|
50
|
+
}): HTTPRequestHandler;
|
|
51
|
+
//# sourceMappingURL=listener.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listener.d.ts","sourceRoot":"","sources":["../../../src/node/listener.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAIlF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,mBAAwB,GAChC,kBAAkB,CA+BpB;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,kBAAkB,CAMvE;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAC9C,kBAAkB,CAOpB;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE;IACP,YAAY,EAAE,WAAW,CAAC,mBAAmB,CAAC,cAAc,CAAC,CAAC,CAAC;IAC/D,SAAS,CAAC,EAAE,mBAAmB,CAAC,WAAW,CAAC,CAAC;IAC7C,IAAI,CAAC,EAAE,mBAAmB,CAAC,MAAM,CAAC,CAAC;CACpC,GACA,kBAAkB,CAOpB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ai.matey.http",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "HTTP framework adapters for AI Matey - Universal AI Adapter System",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/cjs/index.js",
|
|
7
|
+
"module": "./dist/esm/index.js",
|
|
8
|
+
"types": "./dist/types/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/types/index.d.ts",
|
|
13
|
+
"default": "./dist/esm/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/types/index.d.ts",
|
|
17
|
+
"default": "./dist/cjs/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"./express": {
|
|
21
|
+
"import": {
|
|
22
|
+
"types": "./dist/types/express/index.d.ts",
|
|
23
|
+
"default": "./dist/esm/express/index.js"
|
|
24
|
+
},
|
|
25
|
+
"require": {
|
|
26
|
+
"types": "./dist/types/express/index.d.ts",
|
|
27
|
+
"default": "./dist/cjs/express/index.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"./fastify": {
|
|
31
|
+
"import": {
|
|
32
|
+
"types": "./dist/types/fastify/index.d.ts",
|
|
33
|
+
"default": "./dist/esm/fastify/index.js"
|
|
34
|
+
},
|
|
35
|
+
"require": {
|
|
36
|
+
"types": "./dist/types/fastify/index.d.ts",
|
|
37
|
+
"default": "./dist/cjs/fastify/index.js"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"./hono": {
|
|
41
|
+
"import": {
|
|
42
|
+
"types": "./dist/types/hono/index.d.ts",
|
|
43
|
+
"default": "./dist/esm/hono/index.js"
|
|
44
|
+
},
|
|
45
|
+
"require": {
|
|
46
|
+
"types": "./dist/types/hono/index.d.ts",
|
|
47
|
+
"default": "./dist/cjs/hono/index.js"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"./koa": {
|
|
51
|
+
"import": {
|
|
52
|
+
"types": "./dist/types/koa/index.d.ts",
|
|
53
|
+
"default": "./dist/esm/koa/index.js"
|
|
54
|
+
},
|
|
55
|
+
"require": {
|
|
56
|
+
"types": "./dist/types/koa/index.d.ts",
|
|
57
|
+
"default": "./dist/cjs/koa/index.js"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"./node": {
|
|
61
|
+
"import": {
|
|
62
|
+
"types": "./dist/types/node/index.d.ts",
|
|
63
|
+
"default": "./dist/esm/node/index.js"
|
|
64
|
+
},
|
|
65
|
+
"require": {
|
|
66
|
+
"types": "./dist/types/node/index.d.ts",
|
|
67
|
+
"default": "./dist/cjs/node/index.js"
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"./deno": {
|
|
71
|
+
"import": {
|
|
72
|
+
"types": "./dist/types/deno/index.d.ts",
|
|
73
|
+
"default": "./dist/esm/deno/index.js"
|
|
74
|
+
},
|
|
75
|
+
"require": {
|
|
76
|
+
"types": "./dist/types/deno/index.d.ts",
|
|
77
|
+
"default": "./dist/cjs/deno/index.js"
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
"files": [
|
|
82
|
+
"dist",
|
|
83
|
+
"readme.md",
|
|
84
|
+
"CHANGELOG.md",
|
|
85
|
+
"LICENSE"
|
|
86
|
+
],
|
|
87
|
+
"scripts": {
|
|
88
|
+
"build": "npm run build:esm && npm run build:cjs && npm run build:types",
|
|
89
|
+
"build:esm": "tsc -p tsconfig.esm.json",
|
|
90
|
+
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
91
|
+
"build:types": "tsc -p tsconfig.types.json",
|
|
92
|
+
"clean": "rm -rf dist",
|
|
93
|
+
"typecheck": "tsc --noEmit",
|
|
94
|
+
"lint": "eslint src --ext .ts",
|
|
95
|
+
"lint:fix": "eslint src --ext .ts --fix",
|
|
96
|
+
"test": "vitest run",
|
|
97
|
+
"test:watch": "vitest"
|
|
98
|
+
},
|
|
99
|
+
"dependencies": {
|
|
100
|
+
"ai.matey.types": "*",
|
|
101
|
+
"ai.matey.core": "*",
|
|
102
|
+
"ai.matey.http.core": "*"
|
|
103
|
+
},
|
|
104
|
+
"peerDependencies": {
|
|
105
|
+
"express": "^4.0.0 || ^5.0.0",
|
|
106
|
+
"fastify": "^4.0.0 || ^5.0.0",
|
|
107
|
+
"hono": "^3.0.0 || ^4.0.0",
|
|
108
|
+
"koa": "^2.0.0"
|
|
109
|
+
},
|
|
110
|
+
"peerDependenciesMeta": {
|
|
111
|
+
"express": {
|
|
112
|
+
"optional": true
|
|
113
|
+
},
|
|
114
|
+
"fastify": {
|
|
115
|
+
"optional": true
|
|
116
|
+
},
|
|
117
|
+
"hono": {
|
|
118
|
+
"optional": true
|
|
119
|
+
},
|
|
120
|
+
"koa": {
|
|
121
|
+
"optional": true
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
"devDependencies": {
|
|
125
|
+
"ai.matey.testing": "*",
|
|
126
|
+
"@types/express": "^5.0.3",
|
|
127
|
+
"@types/koa": "^3.0.0",
|
|
128
|
+
"@types/node": "^24.7.2",
|
|
129
|
+
"express": "^5.1.0",
|
|
130
|
+
"fastify": "^5.6.1",
|
|
131
|
+
"hono": "^4.9.12",
|
|
132
|
+
"typescript": "^5.9.3",
|
|
133
|
+
"vitest": "^3.2.4"
|
|
134
|
+
},
|
|
135
|
+
"keywords": [
|
|
136
|
+
"ai",
|
|
137
|
+
"llm",
|
|
138
|
+
"http",
|
|
139
|
+
"express",
|
|
140
|
+
"fastify",
|
|
141
|
+
"hono",
|
|
142
|
+
"koa",
|
|
143
|
+
"adapter",
|
|
144
|
+
"ai-matey"
|
|
145
|
+
],
|
|
146
|
+
"author": "AI Matey",
|
|
147
|
+
"license": "MIT",
|
|
148
|
+
"homepage": "https://github.com/johnhenry/ai.matey#readme",
|
|
149
|
+
"bugs": {
|
|
150
|
+
"url": "https://github.com/johnhenry/ai.matey/issues"
|
|
151
|
+
},
|
|
152
|
+
"repository": {
|
|
153
|
+
"type": "git",
|
|
154
|
+
"url": "git+https://github.com/johnhenry/ai.matey.git",
|
|
155
|
+
"directory": "packages/http"
|
|
156
|
+
},
|
|
157
|
+
"engines": {
|
|
158
|
+
"node": ">=18.0.0"
|
|
159
|
+
}
|
|
160
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# ai.matey.http
|
|
2
|
+
|
|
3
|
+
HTTP framework adapters for AI Matey - Universal AI Adapter System.
|
|
4
|
+
|
|
5
|
+
Part of the [ai.matey](https://github.com/johnhenry/ai.matey) monorepo.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install ai.matey.http
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
This package provides HTTP framework integrations for serving AI Matey bridges as API endpoints. Supports multiple popular Node.js and edge frameworks.
|
|
16
|
+
|
|
17
|
+
## Included Adapters
|
|
18
|
+
|
|
19
|
+
- **Express** - Express.js middleware
|
|
20
|
+
- **Fastify** - Fastify handler
|
|
21
|
+
- **Hono** - Hono middleware (works on edge)
|
|
22
|
+
- **Koa** - Koa middleware
|
|
23
|
+
- **Node** - Native Node.js HTTP handler
|
|
24
|
+
- **Deno** - Deno HTTP handler
|
|
25
|
+
|
|
26
|
+
For core HTTP utilities (auth, CORS, rate limiting), see [`ai.matey.http-core`](https://www.npmjs.com/package/ai.matey.http-core).
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
### Express
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import express from 'express';
|
|
34
|
+
import { ExpressMiddleware } from 'ai.matey.http';
|
|
35
|
+
import { Bridge } from 'ai.matey.core';
|
|
36
|
+
|
|
37
|
+
const app = express();
|
|
38
|
+
const bridge = new Bridge({ frontend, backend });
|
|
39
|
+
|
|
40
|
+
const middleware = new ExpressMiddleware({ bridge });
|
|
41
|
+
app.post('/v1/chat/completions', middleware.handler());
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Fastify
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import Fastify from 'fastify';
|
|
48
|
+
import { FastifyHandler } from 'ai.matey.http';
|
|
49
|
+
|
|
50
|
+
const fastify = Fastify();
|
|
51
|
+
const handler = new FastifyHandler({ bridge });
|
|
52
|
+
|
|
53
|
+
fastify.post('/v1/chat/completions', handler.handler());
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Hono
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import { Hono } from 'hono';
|
|
60
|
+
import { HonoMiddleware } from 'ai.matey.http';
|
|
61
|
+
|
|
62
|
+
const app = new Hono();
|
|
63
|
+
const middleware = new HonoMiddleware({ bridge });
|
|
64
|
+
|
|
65
|
+
app.post('/v1/chat/completions', middleware.handler());
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Node.js Native HTTP
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
import http from 'http';
|
|
72
|
+
import { NodeHTTPListener } from 'ai.matey.http';
|
|
73
|
+
|
|
74
|
+
const listener = new NodeHTTPListener({ bridge });
|
|
75
|
+
const server = http.createServer(listener.handler());
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Deno
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
import { DenoHandler } from 'ai.matey.http';
|
|
82
|
+
|
|
83
|
+
const handler = new DenoHandler({ bridge });
|
|
84
|
+
Deno.serve(handler.handler());
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## API Reference
|
|
88
|
+
|
|
89
|
+
See the TypeScript definitions for detailed API documentation.
|
|
90
|
+
|
|
91
|
+
## License
|
|
92
|
+
|
|
93
|
+
MIT - see [LICENSE](./LICENSE) for details.
|