ai.matey.http.core 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.
Files changed (75) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/auth.js +173 -0
  3. package/dist/cjs/auth.js.map +1 -0
  4. package/dist/cjs/cors.js +140 -0
  5. package/dist/cjs/cors.js.map +1 -0
  6. package/dist/cjs/error-handler.js +147 -0
  7. package/dist/cjs/error-handler.js.map +1 -0
  8. package/dist/cjs/handler.js +335 -0
  9. package/dist/cjs/handler.js.map +1 -0
  10. package/dist/cjs/health.js +218 -0
  11. package/dist/cjs/health.js.map +1 -0
  12. package/dist/cjs/index.js +83 -0
  13. package/dist/cjs/index.js.map +1 -0
  14. package/dist/cjs/rate-limiter.js +163 -0
  15. package/dist/cjs/rate-limiter.js.map +1 -0
  16. package/dist/cjs/request-parser.js +141 -0
  17. package/dist/cjs/request-parser.js.map +1 -0
  18. package/dist/cjs/response-formatter.js +218 -0
  19. package/dist/cjs/response-formatter.js.map +1 -0
  20. package/dist/cjs/route-matcher.js +178 -0
  21. package/dist/cjs/route-matcher.js.map +1 -0
  22. package/dist/cjs/streaming-handler.js +120 -0
  23. package/dist/cjs/streaming-handler.js.map +1 -0
  24. package/dist/cjs/types.js +11 -0
  25. package/dist/cjs/types.js.map +1 -0
  26. package/dist/esm/auth.js +163 -0
  27. package/dist/esm/auth.js.map +1 -0
  28. package/dist/esm/cors.js +134 -0
  29. package/dist/esm/cors.js.map +1 -0
  30. package/dist/esm/error-handler.js +137 -0
  31. package/dist/esm/error-handler.js.map +1 -0
  32. package/dist/esm/handler.js +331 -0
  33. package/dist/esm/handler.js.map +1 -0
  34. package/dist/esm/health.js +210 -0
  35. package/dist/esm/health.js.map +1 -0
  36. package/dist/esm/index.js +30 -0
  37. package/dist/esm/index.js.map +1 -0
  38. package/dist/esm/rate-limiter.js +156 -0
  39. package/dist/esm/rate-limiter.js.map +1 -0
  40. package/dist/esm/request-parser.js +136 -0
  41. package/dist/esm/request-parser.js.map +1 -0
  42. package/dist/esm/response-formatter.js +206 -0
  43. package/dist/esm/response-formatter.js.map +1 -0
  44. package/dist/esm/route-matcher.js +171 -0
  45. package/dist/esm/route-matcher.js.map +1 -0
  46. package/dist/esm/streaming-handler.js +112 -0
  47. package/dist/esm/streaming-handler.js.map +1 -0
  48. package/dist/esm/types.js +10 -0
  49. package/dist/esm/types.js.map +1 -0
  50. package/dist/types/auth.d.ts +37 -0
  51. package/dist/types/auth.d.ts.map +1 -0
  52. package/dist/types/cors.d.ts +26 -0
  53. package/dist/types/cors.d.ts.map +1 -0
  54. package/dist/types/error-handler.d.ts +38 -0
  55. package/dist/types/error-handler.d.ts.map +1 -0
  56. package/dist/types/handler.d.ts +45 -0
  57. package/dist/types/handler.d.ts.map +1 -0
  58. package/dist/types/health.d.ts +164 -0
  59. package/dist/types/health.d.ts.map +1 -0
  60. package/dist/types/index.d.ts +21 -0
  61. package/dist/types/index.d.ts.map +1 -0
  62. package/dist/types/rate-limiter.d.ts +56 -0
  63. package/dist/types/rate-limiter.d.ts.map +1 -0
  64. package/dist/types/request-parser.d.ts +22 -0
  65. package/dist/types/request-parser.d.ts.map +1 -0
  66. package/dist/types/response-formatter.d.ts +49 -0
  67. package/dist/types/response-formatter.d.ts.map +1 -0
  68. package/dist/types/route-matcher.d.ts +45 -0
  69. package/dist/types/route-matcher.d.ts.map +1 -0
  70. package/dist/types/streaming-handler.d.ts +40 -0
  71. package/dist/types/streaming-handler.d.ts.map +1 -0
  72. package/dist/types/types.d.ts +398 -0
  73. package/dist/types/types.d.ts.map +1 -0
  74. package/package.json +73 -0
  75. package/readme.md +60 -0
@@ -0,0 +1,398 @@
1
+ /**
2
+ * HTTP Core Types
3
+ *
4
+ * Unified type definitions for the HTTP adapter system.
5
+ * These types allow us to write core logic once and adapt it to any framework.
6
+ *
7
+ * @module
8
+ */
9
+ import type { IncomingMessage, ServerResponse } from 'http';
10
+ import type { Bridge } from 'ai.matey.core';
11
+ import type { FrontendAdapter } from 'ai.matey.types';
12
+ /**
13
+ * CORS configuration options
14
+ */
15
+ export interface CORSOptions {
16
+ /**
17
+ * Allowed origins (default: '*')
18
+ */
19
+ origin?: string | string[] | ((origin: string) => boolean);
20
+ /**
21
+ * Allowed HTTP methods (default: 'GET, POST, OPTIONS')
22
+ */
23
+ methods?: string | string[];
24
+ /**
25
+ * Allowed headers (default: 'Content-Type, Authorization')
26
+ */
27
+ allowedHeaders?: string | string[];
28
+ /**
29
+ * Exposed headers
30
+ */
31
+ exposedHeaders?: string | string[];
32
+ /**
33
+ * Allow credentials (default: true)
34
+ */
35
+ credentials?: boolean;
36
+ /**
37
+ * Max age for preflight cache in seconds (default: 86400)
38
+ */
39
+ maxAge?: number;
40
+ }
41
+ /**
42
+ * Route matching configuration
43
+ */
44
+ export interface RouteConfig {
45
+ /**
46
+ * Path pattern to match (supports simple wildcards)
47
+ * Examples: '/v1/chat/completions', '/v1/messages', '/v1/*'
48
+ */
49
+ path: string;
50
+ /**
51
+ * HTTP methods to match (default: ['POST'])
52
+ */
53
+ methods?: string[];
54
+ /**
55
+ * Frontend adapter to use for this route
56
+ */
57
+ frontend: FrontendAdapter;
58
+ /**
59
+ * Optional bridge to use (overrides default)
60
+ */
61
+ bridge?: Bridge;
62
+ }
63
+ /**
64
+ * Matched route information
65
+ */
66
+ export interface MatchedRoute {
67
+ /**
68
+ * Route configuration
69
+ */
70
+ config: RouteConfig;
71
+ /**
72
+ * Path parameters (if any)
73
+ */
74
+ params: Record<string, string>;
75
+ }
76
+ /**
77
+ * Generic HTTP request interface (framework-agnostic)
78
+ */
79
+ export interface GenericRequest {
80
+ /**
81
+ * HTTP method (GET, POST, etc.)
82
+ */
83
+ method: string;
84
+ /**
85
+ * Full request URL
86
+ */
87
+ url: string;
88
+ /**
89
+ * Request headers (normalized to lowercase keys)
90
+ */
91
+ headers: Record<string, string>;
92
+ /**
93
+ * Parsed request body (null if not yet parsed)
94
+ */
95
+ body: any;
96
+ /**
97
+ * URL parameters (e.g., /users/:id -> { id: '123' })
98
+ */
99
+ params?: Record<string, string>;
100
+ /**
101
+ * Query string parameters
102
+ */
103
+ query?: Record<string, string>;
104
+ /**
105
+ * Client IP address
106
+ */
107
+ ip?: string;
108
+ }
109
+ /**
110
+ * Generic HTTP response interface (framework-agnostic)
111
+ */
112
+ export interface GenericResponse {
113
+ /**
114
+ * Set HTTP status code
115
+ */
116
+ status(code: number): void;
117
+ /**
118
+ * Set response header
119
+ */
120
+ header(name: string, value: string): void;
121
+ /**
122
+ * Send JSON response
123
+ */
124
+ send(data: any): void;
125
+ /**
126
+ * Send streaming response (SSE)
127
+ */
128
+ stream(generator: AsyncGenerator<any, void, undefined>): Promise<void>;
129
+ /**
130
+ * Check if response is writable
131
+ */
132
+ isWritable(): boolean;
133
+ }
134
+ /**
135
+ * Parsed HTTP request (after body parsing)
136
+ */
137
+ export interface ParsedGenericRequest extends GenericRequest {
138
+ /**
139
+ * Parsed request body (guaranteed to be parsed)
140
+ */
141
+ body: any;
142
+ /**
143
+ * Whether streaming is requested
144
+ */
145
+ stream?: boolean;
146
+ }
147
+ /**
148
+ * Auth validator for generic requests
149
+ */
150
+ export type GenericAuthValidator = (req: GenericRequest) => boolean | Promise<boolean>;
151
+ /**
152
+ * Error handler for generic requests/responses
153
+ */
154
+ export type GenericErrorHandler = (error: Error, req: GenericRequest, res: GenericResponse) => void | Promise<void>;
155
+ /**
156
+ * Rate limit key generator for generic requests
157
+ */
158
+ export type GenericRateLimitKeyGenerator = (req: GenericRequest) => string;
159
+ /**
160
+ * Rate limit handler for generic requests/responses
161
+ */
162
+ export type GenericRateLimitHandler = (req: GenericRequest, res: GenericResponse, retryAfter: number) => void | Promise<void>;
163
+ /**
164
+ * Generic rate limit options
165
+ */
166
+ export interface GenericRateLimitOptions {
167
+ /**
168
+ * Maximum number of requests per window
169
+ */
170
+ max: number;
171
+ /**
172
+ * Time window in milliseconds (default: 60000 = 1 minute)
173
+ */
174
+ windowMs?: number;
175
+ /**
176
+ * Generate rate limit key from request (default: IP address)
177
+ */
178
+ keyGenerator?: GenericRateLimitKeyGenerator;
179
+ /**
180
+ * Handler called when rate limit exceeded
181
+ */
182
+ handler?: GenericRateLimitHandler;
183
+ /**
184
+ * Skip rate limiting for certain requests
185
+ */
186
+ skip?: (req: GenericRequest) => boolean | Promise<boolean>;
187
+ /**
188
+ * Custom headers to include in rate limit responses
189
+ */
190
+ headers?: boolean;
191
+ }
192
+ /**
193
+ * Core handler options
194
+ */
195
+ export interface CoreHandlerOptions {
196
+ /**
197
+ * Bridge instance connecting frontend and backend adapters
198
+ */
199
+ bridge: Bridge;
200
+ /**
201
+ * CORS configuration
202
+ */
203
+ cors?: CORSOptions;
204
+ /**
205
+ * Authentication validator
206
+ */
207
+ validateAuth?: GenericAuthValidator;
208
+ /**
209
+ * Error handler
210
+ */
211
+ onError?: GenericErrorHandler;
212
+ /**
213
+ * Custom response headers
214
+ */
215
+ headers?: Record<string, string>;
216
+ /**
217
+ * Request timeout in milliseconds
218
+ */
219
+ timeout?: number;
220
+ /**
221
+ * Path prefix for all routes
222
+ */
223
+ pathPrefix?: string;
224
+ /**
225
+ * Rate limiting configuration
226
+ */
227
+ rateLimit?: GenericRateLimitOptions;
228
+ /**
229
+ * Route configurations for multi-endpoint support
230
+ */
231
+ routes?: RouteConfig[];
232
+ /**
233
+ * Enable request/response logging
234
+ */
235
+ logging?: boolean;
236
+ /**
237
+ * Log function
238
+ */
239
+ log?: (message: string, ...args: any[]) => void;
240
+ /**
241
+ * Maximum request body size in bytes
242
+ */
243
+ maxBodySize?: number;
244
+ /**
245
+ * Enable streaming support
246
+ */
247
+ streaming?: boolean;
248
+ }
249
+ /**
250
+ * HTTP request handler compatible with Node.js http.createServer
251
+ */
252
+ export type HTTPRequestHandler = (req: IncomingMessage, res: ServerResponse) => Promise<void>;
253
+ /**
254
+ * Auth validator function (Node.js-specific)
255
+ * @deprecated Use GenericAuthValidator for framework-agnostic code
256
+ */
257
+ export type AuthValidator = (req: IncomingMessage) => boolean | Promise<boolean>;
258
+ /**
259
+ * Error handler function (Node.js-specific)
260
+ * @deprecated Use GenericErrorHandler for framework-agnostic code
261
+ */
262
+ export type ErrorHandler = (error: Error, req: IncomingMessage, res: ServerResponse) => void | Promise<void>;
263
+ /**
264
+ * Rate limit key generator (Node.js-specific)
265
+ * @deprecated Use GenericRateLimitKeyGenerator for framework-agnostic code
266
+ */
267
+ export type RateLimitKeyGenerator = (req: IncomingMessage) => string;
268
+ /**
269
+ * Rate limit handler (called when limit exceeded) (Node.js-specific)
270
+ * @deprecated Use GenericRateLimitHandler for framework-agnostic code
271
+ */
272
+ export type RateLimitHandler = (req: IncomingMessage, res: ServerResponse, retryAfter: number) => void | Promise<void>;
273
+ /**
274
+ * Rate limiting configuration (Node.js-specific)
275
+ */
276
+ export interface RateLimitOptions {
277
+ /**
278
+ * Maximum number of requests per window
279
+ */
280
+ max: number;
281
+ /**
282
+ * Time window in milliseconds (default: 60000 = 1 minute)
283
+ */
284
+ windowMs?: number;
285
+ /**
286
+ * Generate rate limit key from request (default: IP address)
287
+ */
288
+ keyGenerator?: RateLimitKeyGenerator;
289
+ /**
290
+ * Handler called when rate limit exceeded
291
+ */
292
+ handler?: RateLimitHandler;
293
+ /**
294
+ * Skip rate limiting for certain requests
295
+ */
296
+ skip?: (req: IncomingMessage) => boolean | Promise<boolean>;
297
+ /**
298
+ * Custom headers to include in rate limit responses
299
+ */
300
+ headers?: boolean;
301
+ }
302
+ /**
303
+ * HTTP listener configuration options
304
+ * Supports both Node.js-specific and generic types for framework compatibility
305
+ */
306
+ export interface HTTPListenerOptions {
307
+ /**
308
+ * CORS configuration (default: enabled with sensible defaults)
309
+ */
310
+ cors?: boolean | CORSOptions;
311
+ /**
312
+ * Authentication validator (accepts both Node.js and generic types)
313
+ */
314
+ validateAuth?: AuthValidator | GenericAuthValidator;
315
+ /**
316
+ * Error handler (accepts both Node.js and generic types)
317
+ */
318
+ onError?: ErrorHandler | GenericErrorHandler;
319
+ /**
320
+ * Custom response headers
321
+ */
322
+ headers?: Record<string, string>;
323
+ /**
324
+ * Request timeout in milliseconds (default: 30000)
325
+ */
326
+ timeout?: number;
327
+ /**
328
+ * Path prefix for all routes (e.g., '/v1')
329
+ */
330
+ pathPrefix?: string;
331
+ /**
332
+ * Rate limiting configuration (accepts both Node.js and generic types)
333
+ */
334
+ rateLimit?: RateLimitOptions | GenericRateLimitOptions;
335
+ /**
336
+ * Route configurations for multi-endpoint support
337
+ */
338
+ routes?: RouteConfig[];
339
+ /**
340
+ * Enable request/response logging (default: false)
341
+ */
342
+ logging?: boolean;
343
+ /**
344
+ * Log function (default: console.log)
345
+ */
346
+ log?: (message: string, ...args: any[]) => void;
347
+ /**
348
+ * Maximum request body size in bytes (default: 10MB)
349
+ */
350
+ maxBodySize?: number;
351
+ /**
352
+ * Enable streaming support (default: true)
353
+ */
354
+ streaming?: boolean;
355
+ }
356
+ /**
357
+ * Parsed HTTP request
358
+ */
359
+ export interface ParsedRequest {
360
+ /**
361
+ * Request body (parsed JSON)
362
+ */
363
+ body: any;
364
+ /**
365
+ * Request headers
366
+ */
367
+ headers: Record<string, string>;
368
+ /**
369
+ * Request path (without query string)
370
+ */
371
+ path: string;
372
+ /**
373
+ * HTTP method
374
+ */
375
+ method: string;
376
+ /**
377
+ * Query parameters
378
+ */
379
+ query: Record<string, string>;
380
+ /**
381
+ * Whether streaming is requested
382
+ */
383
+ stream?: boolean;
384
+ }
385
+ /**
386
+ * Rate limit state
387
+ */
388
+ export interface RateLimitState {
389
+ /**
390
+ * Number of requests in current window
391
+ */
392
+ count: number;
393
+ /**
394
+ * Window start timestamp
395
+ */
396
+ resetTime: number;
397
+ }
398
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAA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"version": "0.2.0",
4
+ "description": "Framework-agnostic HTTP core utilities for AI Matey",
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
+ },
21
+ "files": [
22
+ "dist",
23
+ "readme.md",
24
+ "CHANGELOG.md",
25
+ "LICENSE"
26
+ ],
27
+ "scripts": {
28
+ "build": "npm run build:esm && npm run build:cjs && npm run build:types",
29
+ "build:esm": "tsc -p tsconfig.esm.json",
30
+ "build:cjs": "tsc -p tsconfig.cjs.json",
31
+ "build:types": "tsc -p tsconfig.types.json",
32
+ "clean": "rm -rf dist",
33
+ "typecheck": "tsc --noEmit",
34
+ "lint": "eslint src --ext .ts",
35
+ "lint:fix": "eslint src --ext .ts --fix",
36
+ "test": "vitest run",
37
+ "test:watch": "vitest"
38
+ },
39
+ "dependencies": {
40
+ "ai.matey.types": "*",
41
+ "ai.matey.errors": "*",
42
+ "ai.matey.core": "*"
43
+ },
44
+ "devDependencies": {
45
+ "ai.matey.testing": "*",
46
+ "@types/node": "^24.7.2",
47
+ "typescript": "^5.9.3",
48
+ "vitest": "^3.2.4"
49
+ },
50
+ "keywords": [
51
+ "ai",
52
+ "llm",
53
+ "http",
54
+ "server",
55
+ "adapter",
56
+ "framework-agnostic",
57
+ "ai-matey"
58
+ ],
59
+ "author": "AI Matey",
60
+ "license": "MIT",
61
+ "homepage": "https://github.com/johnhenry/ai.matey#readme",
62
+ "bugs": {
63
+ "url": "https://github.com/johnhenry/ai.matey/issues"
64
+ },
65
+ "repository": {
66
+ "type": "git",
67
+ "url": "git+https://github.com/johnhenry/ai.matey.git",
68
+ "directory": "packages/http.core"
69
+ },
70
+ "engines": {
71
+ "node": ">=18.0.0"
72
+ }
73
+ }
package/readme.md ADDED
@@ -0,0 +1,60 @@
1
+ # ai.matey.http.core
2
+
3
+ Core HTTP utilities shared across integrations
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.core
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ```typescript
16
+ import { createCorsMiddleware } from 'ai.matey.http.core';
17
+ import { Bridge } from 'ai.matey.core';
18
+ import { OpenAIFrontendAdapter } from 'ai.matey.frontend/openai';
19
+ import { OpenAIBackendAdapter } from 'ai.matey.backend/openai';
20
+
21
+ const bridge = new Bridge(
22
+ new OpenAIFrontendAdapter(),
23
+ new OpenAIBackendAdapter({ apiKey: process.env.OPENAI_API_KEY })
24
+ );
25
+
26
+ const handler = createCorsMiddleware(bridge, {
27
+ streaming: true,
28
+ timeout: 30000,
29
+ });
30
+
31
+ // Use with your Core server
32
+ ```
33
+
34
+ ## API Reference
35
+
36
+ ### createCorsMiddleware
37
+
38
+ Creates an HTTP handler for Core.
39
+
40
+ ```typescript
41
+ createCorsMiddleware(bridge: Bridge, options?: HandlerOptions): Handler
42
+ ```
43
+
44
+ #### Options
45
+
46
+ | Option | Type | Default | Description |
47
+ |--------|------|---------|-------------|
48
+ | `streaming` | `boolean` | `true` | Enable streaming responses |
49
+ | `timeout` | `number` | `30000` | Request timeout in milliseconds |
50
+ | `cors` | `boolean` | `false` | Enable CORS headers |
51
+
52
+ ## Exports
53
+
54
+ - `createCorsMiddleware`
55
+ - `validateApiKey`
56
+ - `parseRequestBody`
57
+
58
+ ## License
59
+
60
+ MIT - see [LICENSE](./LICENSE) for details.