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,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js HTTP Adapter
|
|
3
|
+
*
|
|
4
|
+
* Converts Node.js IncomingMessage/ServerResponse to GenericRequest/GenericResponse
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import { parseRequest, sendSSEHeaders, sendSSEChunk, sendSSEDone, sendJSON, } from 'ai.matey.http.core';
|
|
9
|
+
/**
|
|
10
|
+
* Adapter that converts Node.js IncomingMessage to GenericRequest
|
|
11
|
+
*/
|
|
12
|
+
export class NodeRequestAdapter {
|
|
13
|
+
req;
|
|
14
|
+
maxBodySize;
|
|
15
|
+
_parsed = null;
|
|
16
|
+
_parsePromise = null;
|
|
17
|
+
constructor(req, maxBodySize = 10 * 1024 * 1024) {
|
|
18
|
+
this.req = req;
|
|
19
|
+
this.maxBodySize = maxBodySize;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Parse the request body if not already parsed
|
|
23
|
+
*/
|
|
24
|
+
async ensureParsed() {
|
|
25
|
+
if (this._parsed) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
// Avoid multiple simultaneous parse calls
|
|
29
|
+
if (this._parsePromise) {
|
|
30
|
+
await this._parsePromise;
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
this._parsePromise = (async () => {
|
|
34
|
+
this._parsed = await parseRequest(this.req, this.maxBodySize);
|
|
35
|
+
})();
|
|
36
|
+
await this._parsePromise;
|
|
37
|
+
}
|
|
38
|
+
get method() {
|
|
39
|
+
return this.req.method || 'GET';
|
|
40
|
+
}
|
|
41
|
+
get url() {
|
|
42
|
+
return this.req.url || '/';
|
|
43
|
+
}
|
|
44
|
+
get headers() {
|
|
45
|
+
const headers = {};
|
|
46
|
+
for (const [key, value] of Object.entries(this.req.headers)) {
|
|
47
|
+
if (typeof value === 'string') {
|
|
48
|
+
headers[key.toLowerCase()] = value;
|
|
49
|
+
}
|
|
50
|
+
else if (Array.isArray(value)) {
|
|
51
|
+
headers[key.toLowerCase()] = value.join(', ');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return headers;
|
|
55
|
+
}
|
|
56
|
+
get body() {
|
|
57
|
+
// Return parsed body if available, null otherwise
|
|
58
|
+
return this._parsed?.body ?? null;
|
|
59
|
+
}
|
|
60
|
+
get params() {
|
|
61
|
+
// ParsedRequest doesn't have params, so return undefined
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
get query() {
|
|
65
|
+
return this._parsed?.query;
|
|
66
|
+
}
|
|
67
|
+
get ip() {
|
|
68
|
+
// Try various sources for IP address
|
|
69
|
+
const forwarded = this.req.headers['x-forwarded-for'];
|
|
70
|
+
if (typeof forwarded === 'string') {
|
|
71
|
+
return forwarded.split(',')[0]?.trim();
|
|
72
|
+
}
|
|
73
|
+
const realIp = this.req.headers['x-real-ip'];
|
|
74
|
+
if (typeof realIp === 'string') {
|
|
75
|
+
return realIp;
|
|
76
|
+
}
|
|
77
|
+
const socket = this.req.socket;
|
|
78
|
+
return socket?.remoteAddress;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Get the underlying Node.js request object
|
|
82
|
+
*/
|
|
83
|
+
get raw() {
|
|
84
|
+
return this.req;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Parse the request body (called by core handler before accessing body)
|
|
88
|
+
*/
|
|
89
|
+
async parse() {
|
|
90
|
+
await this.ensureParsed();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Adapter that converts GenericResponse methods to Node.js ServerResponse
|
|
95
|
+
*/
|
|
96
|
+
export class NodeResponseAdapter {
|
|
97
|
+
res;
|
|
98
|
+
_statusCode = 200;
|
|
99
|
+
_headersSent = false;
|
|
100
|
+
constructor(res) {
|
|
101
|
+
this.res = res;
|
|
102
|
+
}
|
|
103
|
+
status(code) {
|
|
104
|
+
this._statusCode = code;
|
|
105
|
+
if (!this._headersSent) {
|
|
106
|
+
this.res.statusCode = code;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
header(name, value) {
|
|
110
|
+
if (!this._headersSent) {
|
|
111
|
+
this.res.setHeader(name, value);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
send(data) {
|
|
115
|
+
if (!this.isWritable()) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
this._headersSent = true;
|
|
119
|
+
// Handle empty string (e.g., for CORS preflight 204 responses)
|
|
120
|
+
if (data === '') {
|
|
121
|
+
this.res.end();
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
sendJSON(this.res, data, this._statusCode);
|
|
125
|
+
}
|
|
126
|
+
async stream(generator) {
|
|
127
|
+
if (!this.isWritable()) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
this._headersSent = true;
|
|
131
|
+
// Set SSE headers
|
|
132
|
+
sendSSEHeaders(this.res, {});
|
|
133
|
+
try {
|
|
134
|
+
// Stream chunks
|
|
135
|
+
for await (const chunk of generator) {
|
|
136
|
+
if (!this.isWritable()) {
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
sendSSEChunk(this.res, chunk);
|
|
140
|
+
}
|
|
141
|
+
// Send done marker
|
|
142
|
+
if (this.isWritable()) {
|
|
143
|
+
sendSSEDone(this.res);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
// If error occurs during streaming, we can't change status code
|
|
148
|
+
// Just log and close
|
|
149
|
+
console.error('Streaming error:', error);
|
|
150
|
+
if (this.isWritable()) {
|
|
151
|
+
this.res.end();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
isWritable() {
|
|
156
|
+
return this.res.writable && !this.res.headersSent;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Get the underlying Node.js response object
|
|
160
|
+
*/
|
|
161
|
+
get raw() {
|
|
162
|
+
return this.res;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../../src/node/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,EACL,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,WAAW,EACX,QAAQ,GACT,MAAM,oBAAoB,CAAC;AA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AI,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YAChC,CAAC;YAED,mBAAmB;YACnB,IAAI,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC;gBACtB,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACxB,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,gEAAgE;YAChE,qBAAqB;YACrB,OAAO,CAAC,KAAK,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;YAEzC,IAAI,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC;gBACtB,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;YACjB,CAAC;QACH,CAAC;IACH,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC;IACpD,CAAC;IAED;;OAEG;IACH,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/node/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
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 { CoreHTTPHandler } from 'ai.matey.http.core';
|
|
9
|
+
import { NodeRequestAdapter, NodeResponseAdapter } from './adapter.js';
|
|
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 function NodeHTTPListener(bridge, options = {}) {
|
|
35
|
+
// Create core handler with all business logic
|
|
36
|
+
// Extract cors option to normalize it
|
|
37
|
+
const { cors, ...restOptions } = options;
|
|
38
|
+
const coreHandler = new CoreHTTPHandler({
|
|
39
|
+
bridge,
|
|
40
|
+
cors: cors === false || cors === undefined ? undefined : cors === true ? {} : cors,
|
|
41
|
+
...restOptions, // HTTPListenerOptions types are compatible with CoreHandlerOptions at runtime
|
|
42
|
+
});
|
|
43
|
+
// Get max body size for adapter
|
|
44
|
+
const maxBodySize = options.maxBodySize ?? 10 * 1024 * 1024;
|
|
45
|
+
// Return Node.js request handler
|
|
46
|
+
return async (req, res) => {
|
|
47
|
+
// Set timeout if configured
|
|
48
|
+
const timeout = options.timeout ?? 30000;
|
|
49
|
+
req.setTimeout?.(timeout);
|
|
50
|
+
res.setTimeout?.(timeout);
|
|
51
|
+
// Create adapters
|
|
52
|
+
const genericReq = new NodeRequestAdapter(req, maxBodySize);
|
|
53
|
+
const genericRes = new NodeResponseAdapter(res);
|
|
54
|
+
// Parse request body before passing to core handler
|
|
55
|
+
await genericReq.parse();
|
|
56
|
+
// Handle request through core handler
|
|
57
|
+
await coreHandler.handle(genericReq, genericRes);
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Create simple HTTP listener without advanced features
|
|
62
|
+
*/
|
|
63
|
+
export function createSimpleListener(bridge) {
|
|
64
|
+
return NodeHTTPListener(bridge, {
|
|
65
|
+
cors: true,
|
|
66
|
+
streaming: true,
|
|
67
|
+
logging: false,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Create HTTP listener with logging enabled
|
|
72
|
+
*/
|
|
73
|
+
export function createLoggingListener(bridge, log) {
|
|
74
|
+
return NodeHTTPListener(bridge, {
|
|
75
|
+
cors: true,
|
|
76
|
+
streaming: true,
|
|
77
|
+
logging: true,
|
|
78
|
+
log,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Create HTTP listener with auth and rate limiting
|
|
83
|
+
*/
|
|
84
|
+
export function createSecureListener(bridge, options) {
|
|
85
|
+
return NodeHTTPListener(bridge, {
|
|
86
|
+
validateAuth: options.validateAuth,
|
|
87
|
+
rateLimit: options.rateLimit,
|
|
88
|
+
cors: options.cors ?? true,
|
|
89
|
+
streaming: true,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=listener.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listener.js","sourceRoot":"","sources":["../../../src/node/listener.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,gBAAgB,CAC9B,MAAc,EACd,UAA+B,EAAE;IAEjC,8CAA8C;IAC9C,sCAAsC;IACtC,MAAM,EAAE,IAAI,EAAE,GAAG,WAAW,EAAE,GAAG,OAAO,CAAC;IAEzC,MAAM,WAAW,GAAG,IAAI,eAAe,CAAC;QACtC,MAAM;QACN,IAAI,EAAE,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,SAAS,CAAC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C;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAc,EACd,OAIC;IAED,OAAO,gBAAgB,CAAC,MAAM,EAAE;QAC9B,YAAY,EAAE,OAAO,CAAC,YAAY;QAClC,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,IAAI;QAC1B,SAAS,EAAE,IAAI;KAChB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deno HTTP Adapter
|
|
3
|
+
*
|
|
4
|
+
* Converts Deno Request/Response to GenericRequest/GenericResponse
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import type { GenericRequest, GenericResponse } from 'ai.matey.http.core';
|
|
9
|
+
/**
|
|
10
|
+
* Adapter that converts Deno Request to GenericRequest
|
|
11
|
+
*/
|
|
12
|
+
export declare class DenoRequestAdapter implements GenericRequest {
|
|
13
|
+
private request;
|
|
14
|
+
private connInfo?;
|
|
15
|
+
private _body;
|
|
16
|
+
constructor(request: Request, connInfo?: {
|
|
17
|
+
remoteAddr?: {
|
|
18
|
+
hostname?: string;
|
|
19
|
+
};
|
|
20
|
+
} | undefined);
|
|
21
|
+
get method(): string;
|
|
22
|
+
get url(): string;
|
|
23
|
+
get headers(): Record<string, string>;
|
|
24
|
+
get body(): any;
|
|
25
|
+
get params(): Record<string, string> | undefined;
|
|
26
|
+
get query(): Record<string, string> | undefined;
|
|
27
|
+
get ip(): string | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Set the parsed body (must be called before passing to handler)
|
|
30
|
+
*/
|
|
31
|
+
setBody(body: any): void;
|
|
32
|
+
/**
|
|
33
|
+
* Get the underlying Deno request object
|
|
34
|
+
*/
|
|
35
|
+
get raw(): Request;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Adapter that converts GenericResponse methods to Deno Response
|
|
39
|
+
*/
|
|
40
|
+
export declare class DenoResponseAdapter implements GenericResponse {
|
|
41
|
+
private _statusCode;
|
|
42
|
+
private _headers;
|
|
43
|
+
private _sent;
|
|
44
|
+
private _response;
|
|
45
|
+
constructor();
|
|
46
|
+
status(code: number): void;
|
|
47
|
+
header(name: string, value: string): void;
|
|
48
|
+
send(data: any): void;
|
|
49
|
+
stream(generator: AsyncGenerator<any, void, undefined>): Promise<void>;
|
|
50
|
+
isWritable(): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Get the generated Response object
|
|
53
|
+
*/
|
|
54
|
+
getResponse(): Response;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/deno/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1E;;GAEG;AACH,qBAAa,kBAAmB,YAAW,cAAc;IAIrD,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,QAAQ,CAAC;IAJnB,OAAO,CAAC,KAAK,CAAa;gBAGhB,OAAO,EAAE,OAAO,EAChB,QAAQ,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE;YAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,YAAA;IAG3D,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,GAAG,IAAI,MAAM,CAEhB;IAED,IAAI,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAQpC;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,CAU9C;IAED,IAAI,EAAE,IAAI,MAAM,GAAG,SAAS,CAiB3B;IAED;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;IAIxB;;OAEG;IACH,IAAI,GAAG,IAAI,OAAO,CAEjB;CACF;AAED;;GAEG;AACH,qBAAa,mBAAoB,YAAW,eAAe;IACzD,OAAO,CAAC,WAAW,CAAe;IAClC,OAAO,CAAC,QAAQ,CAA0B;IAC1C,OAAO,CAAC,KAAK,CAAkB;IAC/B,OAAO,CAAC,SAAS,CAAyB;;IAI1C,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;IA6BrB,MAAM,CAAC,SAAS,EAAE,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE,SAAS,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAyCtE,UAAU,IAAI,OAAO;IAIrB;;OAEG;IACH,WAAW,IAAI,QAAQ;CAOxB"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deno Handler
|
|
3
|
+
*
|
|
4
|
+
* HTTP request handler for Deno that uses the core handler.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import type { Bridge } from 'ai.matey.core';
|
|
9
|
+
import type { HTTPListenerOptions } from 'ai.matey.http.core';
|
|
10
|
+
/**
|
|
11
|
+
* Create Deno HTTP handler for handling AI chat requests
|
|
12
|
+
*
|
|
13
|
+
* @param bridge - Bridge instance
|
|
14
|
+
* @param options - HTTP listener options
|
|
15
|
+
* @returns Deno HTTP handler function
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { DenoHandler } from 'ai.matey.http/deno';
|
|
20
|
+
*
|
|
21
|
+
* const bridge = new Bridge(frontend, backend);
|
|
22
|
+
*
|
|
23
|
+
* // Create handler
|
|
24
|
+
* const handler = DenoHandler(bridge, {
|
|
25
|
+
* cors: true,
|
|
26
|
+
* streaming: true,
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // Use with Deno.serve
|
|
30
|
+
* Deno.serve({ port: 3000 }, handler);
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function DenoHandler(bridge: Bridge, options?: HTTPListenerOptions): (request: Request, connInfo?: {
|
|
34
|
+
remoteAddr?: {
|
|
35
|
+
hostname?: string;
|
|
36
|
+
};
|
|
37
|
+
}) => Promise<Response>;
|
|
38
|
+
//# sourceMappingURL=handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/deno/handler.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAI9D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,mBAAwB,GAChC,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE;IAAE,UAAU,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,KAAK,OAAO,CAAC,QAAQ,CAAC,CAiD5F"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/deno/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Express HTTP Adapter
|
|
3
|
+
*
|
|
4
|
+
* Converts Express Request/Response to GenericRequest/GenericResponse
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import type { Request, Response } from 'express';
|
|
9
|
+
import type { GenericRequest, GenericResponse } from 'ai.matey.http.core';
|
|
10
|
+
/**
|
|
11
|
+
* Adapter that converts Express Request to GenericRequest
|
|
12
|
+
*/
|
|
13
|
+
export declare class ExpressRequestAdapter implements GenericRequest {
|
|
14
|
+
private req;
|
|
15
|
+
constructor(req: Request);
|
|
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 Express request object
|
|
25
|
+
*/
|
|
26
|
+
get raw(): Request;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Adapter that converts GenericResponse methods to Express Response
|
|
30
|
+
*/
|
|
31
|
+
export declare class ExpressResponseAdapter implements GenericResponse {
|
|
32
|
+
private res;
|
|
33
|
+
private _statusCode;
|
|
34
|
+
private _headersSent;
|
|
35
|
+
constructor(res: Response);
|
|
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 Express response object
|
|
43
|
+
*/
|
|
44
|
+
get raw(): Response;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/express/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACjD,O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AMG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Express Middleware
|
|
3
|
+
*
|
|
4
|
+
* HTTP request middleware for Express that uses the core handler.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import type { Request, Response, NextFunction } from 'express';
|
|
9
|
+
import type { Bridge } from 'ai.matey.core';
|
|
10
|
+
import type { HTTPListenerOptions } from 'ai.matey.http.core';
|
|
11
|
+
/**
|
|
12
|
+
* Create Express middleware for handling AI chat requests
|
|
13
|
+
*
|
|
14
|
+
* @param bridge - Bridge instance
|
|
15
|
+
* @param options - HTTP listener options
|
|
16
|
+
* @returns Express middleware function
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import express from 'express';
|
|
21
|
+
* import { ExpressMiddleware } from 'ai.matey.http/express';
|
|
22
|
+
*
|
|
23
|
+
* const app = express();
|
|
24
|
+
* const bridge = new Bridge(frontend, backend);
|
|
25
|
+
*
|
|
26
|
+
* // Use body parser middleware first
|
|
27
|
+
* app.use(express.json());
|
|
28
|
+
*
|
|
29
|
+
* // Add AI chat middleware
|
|
30
|
+
* app.use('/v1/messages', ExpressMiddleware(bridge, {
|
|
31
|
+
* cors: true,
|
|
32
|
+
* streaming: true,
|
|
33
|
+
* }));
|
|
34
|
+
*
|
|
35
|
+
* app.listen(3000);
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function ExpressMiddleware(bridge: Bridge, options?: HTTPListenerOptions): (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
39
|
+
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../../src/express/middleware.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAI9D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,mBAAwB,GAChC,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,CAwBpE"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fastify HTTP Adapter
|
|
3
|
+
*
|
|
4
|
+
* Converts Fastify Request/Reply to GenericRequest/GenericResponse
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import type { FastifyRequest, FastifyReply } from 'fastify';
|
|
9
|
+
import type { GenericRequest, GenericResponse } from 'ai.matey.http.core';
|
|
10
|
+
/**
|
|
11
|
+
* Adapter that converts Fastify Request to GenericRequest
|
|
12
|
+
*/
|
|
13
|
+
export declare class FastifyRequestAdapter implements GenericRequest {
|
|
14
|
+
private request;
|
|
15
|
+
constructor(request: FastifyRequest);
|
|
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 Fastify request object
|
|
25
|
+
*/
|
|
26
|
+
get raw(): FastifyRequest;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Adapter that converts GenericResponse methods to Fastify Reply
|
|
30
|
+
*/
|
|
31
|
+
export declare class FastifyResponseAdapter implements GenericResponse {
|
|
32
|
+
private reply;
|
|
33
|
+
private _statusCode;
|
|
34
|
+
private _headersSent;
|
|
35
|
+
constructor(reply: FastifyReply);
|
|
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 Fastify reply object
|
|
43
|
+
*/
|
|
44
|
+
get raw(): FastifyReply;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/fastify/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAG1E;;GAEG;AACH,qBAAa,qBAAsB,YAAW,cAAc;IAC9C,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,cAAc;IAE3C,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,CAE/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,cAAc,CAExB;CACF;AAED;;GAEG;AACH,qBAAa,sBAAuB,YAAW,eAAe;IAIhD,OAAO,CAAC,KAAK;IAHzB,OAAO,CAAC,WAAW,CAAe;IAClC,OAAO,CAAC,YAAY,CAAkB;gBAElB,KAAK,EAAE,YAAY;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;IAiBf,MAAM,CAAC,SAAS,EAAE,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE,SAAS,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAqC5E,UAAU,IAAI,OAAO;IAIrB;;OAEG;IACH,IAAI,GAAG,IAAI,YAAY,CAEtB;CACF"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fastify Handler
|
|
3
|
+
*
|
|
4
|
+
* HTTP request handler for Fastify that uses the core handler.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import type { FastifyRequest, FastifyReply } from 'fastify';
|
|
9
|
+
import type { Bridge } from 'ai.matey.core';
|
|
10
|
+
import type { HTTPListenerOptions } from 'ai.matey.http.core';
|
|
11
|
+
/**
|
|
12
|
+
* Create Fastify route handler for handling AI chat requests
|
|
13
|
+
*
|
|
14
|
+
* @param bridge - Bridge instance
|
|
15
|
+
* @param options - HTTP listener options
|
|
16
|
+
* @returns Fastify route handler function
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import Fastify from 'fastify';
|
|
21
|
+
* import { FastifyHandler } from 'ai.matey.http/fastify';
|
|
22
|
+
*
|
|
23
|
+
* const fastify = Fastify();
|
|
24
|
+
* const bridge = new Bridge(frontend, backend);
|
|
25
|
+
*
|
|
26
|
+
* // Add AI chat route
|
|
27
|
+
* fastify.post('/v1/messages', FastifyHandler(bridge, {
|
|
28
|
+
* cors: true,
|
|
29
|
+
* streaming: true,
|
|
30
|
+
* }));
|
|
31
|
+
*
|
|
32
|
+
* fastify.listen({ port: 3000 });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function FastifyHandler(bridge: Bridge, options?: HTTPListenerOptions): (request: FastifyRequest, reply: FastifyReply) => Promise<void>;
|
|
36
|
+
//# sourceMappingURL=handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/fastify/handler.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5D,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,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,CAmBjE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fastify/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hono HTTP Adapter
|
|
3
|
+
*
|
|
4
|
+
* Converts Hono Context to GenericRequest/GenericResponse
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import type { Context } from 'hono';
|
|
9
|
+
import type { GenericRequest, GenericResponse } from 'ai.matey.http.core';
|
|
10
|
+
/**
|
|
11
|
+
* Adapter that converts Hono Context to GenericRequest
|
|
12
|
+
*/
|
|
13
|
+
export declare class HonoRequestAdapter implements GenericRequest {
|
|
14
|
+
private c;
|
|
15
|
+
constructor(c: 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 Hono context object
|
|
25
|
+
*/
|
|
26
|
+
get raw(): Context;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Adapter that converts GenericResponse methods to Hono Context
|
|
30
|
+
*/
|
|
31
|
+
export declare class HonoResponseAdapter implements GenericResponse {
|
|
32
|
+
private c;
|
|
33
|
+
private _statusCode;
|
|
34
|
+
private _headers;
|
|
35
|
+
private _sent;
|
|
36
|
+
constructor(c: Context);
|
|
37
|
+
status(code: number): void;
|
|
38
|
+
header(name: string, value: string): void;
|
|
39
|
+
send(data: any): void;
|
|
40
|
+
stream(generator: AsyncGenerator<any, void, undefined>): Promise<void>;
|
|
41
|
+
isWritable(): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Get the underlying Hono context object
|
|
44
|
+
*/
|
|
45
|
+
get raw(): Context;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=adapter.d.ts.map
|