ai.matey.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.
- package/LICENSE +21 -0
- package/dist/cjs/bridge.js +657 -0
- package/dist/cjs/bridge.js.map +1 -0
- package/dist/cjs/capability-inference.js +349 -0
- package/dist/cjs/capability-inference.js.map +1 -0
- package/dist/cjs/capability-matcher.js +216 -0
- package/dist/cjs/capability-matcher.js.map +1 -0
- package/dist/cjs/index.js +31 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/middleware-stack.js +256 -0
- package/dist/cjs/middleware-stack.js.map +1 -0
- package/dist/cjs/model-pricing.js +350 -0
- package/dist/cjs/model-pricing.js.map +1 -0
- package/dist/cjs/model-translation.js +171 -0
- package/dist/cjs/model-translation.js.map +1 -0
- package/dist/cjs/router.js +1388 -0
- package/dist/cjs/router.js.map +1 -0
- package/dist/esm/bridge.js +652 -0
- package/dist/esm/bridge.js.map +1 -0
- package/dist/esm/capability-inference.js +343 -0
- package/dist/esm/capability-inference.js.map +1 -0
- package/dist/esm/capability-matcher.js +210 -0
- package/dist/esm/capability-matcher.js.map +1 -0
- package/dist/esm/index.js +15 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/middleware-stack.js +250 -0
- package/dist/esm/middleware-stack.js.map +1 -0
- package/dist/esm/model-pricing.js +340 -0
- package/dist/esm/model-pricing.js.map +1 -0
- package/dist/esm/model-translation.js +163 -0
- package/dist/esm/model-translation.js.map +1 -0
- package/dist/esm/router.js +1383 -0
- package/dist/esm/router.js.map +1 -0
- package/dist/types/bridge.d.ts +254 -0
- package/dist/types/bridge.d.ts.map +1 -0
- package/dist/types/capability-inference.d.ts +35 -0
- package/dist/types/capability-inference.d.ts.map +1 -0
- package/dist/types/capability-matcher.d.ts +104 -0
- package/dist/types/capability-matcher.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/middleware-stack.d.ts +102 -0
- package/dist/types/middleware-stack.d.ts.map +1 -0
- package/dist/types/model-pricing.d.ts +81 -0
- package/dist/types/model-pricing.d.ts.map +1 -0
- package/dist/types/model-translation.d.ts +171 -0
- package/dist/types/model-translation.d.ts.map +1 -0
- package/dist/types/router.d.ts +287 -0
- package/dist/types/router.d.ts.map +1 -0
- package/package.json +70 -0
- package/readme.md +34 -0
|
@@ -0,0 +1,652 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bridge Implementation
|
|
3
|
+
*
|
|
4
|
+
* The Bridge connects frontend and backend adapters with middleware support.
|
|
5
|
+
* It's the main entry point for making requests through the universal adapter system.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import { BridgeEventType } from 'ai.matey.types';
|
|
10
|
+
import { MiddlewareStack, createMiddlewareContext, createStreamingMiddlewareContext, } from './middleware-stack.js';
|
|
11
|
+
import { AdapterError, ErrorCode, ValidationError } from 'ai.matey.errors';
|
|
12
|
+
import { validateIRChatRequest, createGenerateObject, createStreamObject } from 'ai.matey.utils';
|
|
13
|
+
// ============================================================================
|
|
14
|
+
// Bridge Implementation
|
|
15
|
+
// ============================================================================
|
|
16
|
+
/**
|
|
17
|
+
* Bridge connects frontend and backend adapters.
|
|
18
|
+
*
|
|
19
|
+
* @template TFrontend Frontend adapter type
|
|
20
|
+
*/
|
|
21
|
+
export class Bridge {
|
|
22
|
+
frontend;
|
|
23
|
+
backend;
|
|
24
|
+
config;
|
|
25
|
+
middlewareStack;
|
|
26
|
+
// Statistics tracking
|
|
27
|
+
_totalRequests = 0;
|
|
28
|
+
_successfulRequests = 0;
|
|
29
|
+
_failedRequests = 0;
|
|
30
|
+
_streamingRequests = 0;
|
|
31
|
+
_latencies = [];
|
|
32
|
+
static MAX_LATENCY_SAMPLES = 1000; // Prevent unbounded memory growth
|
|
33
|
+
_errorCounts = {};
|
|
34
|
+
_statsResetTimestamp = Date.now();
|
|
35
|
+
// Event listeners (stored for future event emission)
|
|
36
|
+
_eventListeners = new Map();
|
|
37
|
+
/**
|
|
38
|
+
* Create a new Bridge instance.
|
|
39
|
+
*
|
|
40
|
+
* @param frontend Frontend adapter
|
|
41
|
+
* @param backend Backend adapter
|
|
42
|
+
* @param config Bridge configuration
|
|
43
|
+
*/
|
|
44
|
+
constructor(frontend, backend, config = {}) {
|
|
45
|
+
this.frontend = frontend;
|
|
46
|
+
this.backend = backend;
|
|
47
|
+
this.config = {
|
|
48
|
+
debug: config.debug ?? false,
|
|
49
|
+
timeout: config.timeout ?? 30000,
|
|
50
|
+
retries: config.retries ?? 0,
|
|
51
|
+
autoRequestId: config.autoRequestId ?? true,
|
|
52
|
+
defaultModel: config.defaultModel,
|
|
53
|
+
routerConfig: config.routerConfig,
|
|
54
|
+
custom: config.custom,
|
|
55
|
+
};
|
|
56
|
+
this.middlewareStack = new MiddlewareStack();
|
|
57
|
+
}
|
|
58
|
+
// ==========================================================================
|
|
59
|
+
// Core Request Methods
|
|
60
|
+
// ==========================================================================
|
|
61
|
+
/**
|
|
62
|
+
* Execute a non-streaming chat completion request.
|
|
63
|
+
*/
|
|
64
|
+
async chat(request, options) {
|
|
65
|
+
const startTime = Date.now();
|
|
66
|
+
this._totalRequests++;
|
|
67
|
+
// Step 1: Convert frontend request to IR
|
|
68
|
+
const irRequest = await this.frontend.toIR(request);
|
|
69
|
+
// Step 2: Ensure metadata has requestId and timestamp
|
|
70
|
+
const enrichedRequest = this.enrichRequest(irRequest, options);
|
|
71
|
+
// Emit REQUEST_START event
|
|
72
|
+
this.emit({
|
|
73
|
+
type: BridgeEventType.REQUEST_START,
|
|
74
|
+
timestamp: Date.now(),
|
|
75
|
+
requestId: enrichedRequest.metadata.requestId,
|
|
76
|
+
request: enrichedRequest,
|
|
77
|
+
});
|
|
78
|
+
const maxAttempts = (this.config.retries ?? 0) + 1;
|
|
79
|
+
let lastError;
|
|
80
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
81
|
+
try {
|
|
82
|
+
// Step 3: Validate IR request
|
|
83
|
+
validateIRChatRequest(enrichedRequest, {
|
|
84
|
+
frontend: this.frontend.metadata.name,
|
|
85
|
+
});
|
|
86
|
+
// Step 4: Create middleware context
|
|
87
|
+
const context = createMiddlewareContext(enrichedRequest, this.config, options?.signal);
|
|
88
|
+
// Step 5: Execute middleware stack + backend
|
|
89
|
+
const irResponse = await this.middlewareStack.execute(context, async () => {
|
|
90
|
+
// Call backend adapter
|
|
91
|
+
return await this.backend.execute(enrichedRequest, options?.signal);
|
|
92
|
+
});
|
|
93
|
+
// Step 6: Enrich response with provenance
|
|
94
|
+
const enrichedResponse = this.enrichResponse(irResponse, enrichedRequest);
|
|
95
|
+
// Step 7: Convert IR response to frontend format
|
|
96
|
+
const frontendResponse = await this.frontend.fromIR(enrichedResponse);
|
|
97
|
+
// Track success
|
|
98
|
+
this._successfulRequests++;
|
|
99
|
+
const durationMs = Date.now() - startTime;
|
|
100
|
+
this.recordLatency(durationMs);
|
|
101
|
+
// Emit REQUEST_SUCCESS event
|
|
102
|
+
this.emit({
|
|
103
|
+
type: BridgeEventType.REQUEST_SUCCESS,
|
|
104
|
+
timestamp: Date.now(),
|
|
105
|
+
requestId: enrichedRequest.metadata.requestId,
|
|
106
|
+
request: enrichedRequest,
|
|
107
|
+
response: enrichedResponse,
|
|
108
|
+
durationMs,
|
|
109
|
+
});
|
|
110
|
+
return frontendResponse;
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
114
|
+
// Don't retry on non-retryable errors or if this is the last attempt
|
|
115
|
+
const isRetryable = error instanceof AdapterError ? error.isRetryable : true;
|
|
116
|
+
if (!isRetryable || attempt >= maxAttempts) {
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
// Wait before retrying (simple exponential backoff)
|
|
120
|
+
await this.delay(Math.min(1000 * Math.pow(2, attempt - 1), 10000));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// Track failure
|
|
124
|
+
this._failedRequests++;
|
|
125
|
+
const errorCode = lastError instanceof AdapterError ? lastError.code : 'UNKNOWN';
|
|
126
|
+
this._errorCounts[errorCode] = (this._errorCounts[errorCode] ?? 0) + 1;
|
|
127
|
+
// Emit REQUEST_ERROR event
|
|
128
|
+
this.emit({
|
|
129
|
+
type: BridgeEventType.REQUEST_ERROR,
|
|
130
|
+
timestamp: Date.now(),
|
|
131
|
+
requestId: enrichedRequest.metadata.requestId,
|
|
132
|
+
request: enrichedRequest,
|
|
133
|
+
error: lastError,
|
|
134
|
+
durationMs: Date.now() - startTime,
|
|
135
|
+
});
|
|
136
|
+
// Re-throw adapter errors, wrap others
|
|
137
|
+
// lastError is guaranteed to be defined here (we only reach this point if all retries failed)
|
|
138
|
+
if (!lastError) {
|
|
139
|
+
throw new Error('Bridge execution failed with no error information');
|
|
140
|
+
}
|
|
141
|
+
if (lastError instanceof AdapterError) {
|
|
142
|
+
throw lastError;
|
|
143
|
+
}
|
|
144
|
+
throw new AdapterError({
|
|
145
|
+
code: ErrorCode.INTERNAL_ERROR,
|
|
146
|
+
message: `Bridge execution failed: ${lastError.message}`,
|
|
147
|
+
isRetryable: false,
|
|
148
|
+
cause: lastError,
|
|
149
|
+
provenance: {},
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Execute a streaming chat completion request.
|
|
154
|
+
*/
|
|
155
|
+
async *chatStream(request, options) {
|
|
156
|
+
const startTime = Date.now();
|
|
157
|
+
this._totalRequests++;
|
|
158
|
+
this._streamingRequests++;
|
|
159
|
+
// Step 1: Convert frontend request to IR
|
|
160
|
+
const irRequest = await this.frontend.toIR(request);
|
|
161
|
+
// Step 2: Ensure streaming is enabled
|
|
162
|
+
const streamingRequest = {
|
|
163
|
+
...irRequest,
|
|
164
|
+
stream: true,
|
|
165
|
+
};
|
|
166
|
+
// Step 3: Ensure metadata has requestId and timestamp
|
|
167
|
+
const enrichedRequest = this.enrichRequest(streamingRequest, options);
|
|
168
|
+
// Emit STREAM_START event
|
|
169
|
+
this.emit({
|
|
170
|
+
type: BridgeEventType.STREAM_START,
|
|
171
|
+
timestamp: Date.now(),
|
|
172
|
+
requestId: enrichedRequest.metadata.requestId,
|
|
173
|
+
request: enrichedRequest,
|
|
174
|
+
});
|
|
175
|
+
try {
|
|
176
|
+
// Step 4: Validate IR request
|
|
177
|
+
validateIRChatRequest(enrichedRequest, {
|
|
178
|
+
frontend: this.frontend.metadata.name,
|
|
179
|
+
});
|
|
180
|
+
// Step 5: Create streaming middleware context
|
|
181
|
+
const context = createStreamingMiddlewareContext(enrichedRequest, this.config, options?.signal);
|
|
182
|
+
// Step 6: Execute middleware stack + backend
|
|
183
|
+
const irStream = await this.middlewareStack.executeStream(context, async () => {
|
|
184
|
+
// Call backend adapter streaming
|
|
185
|
+
return this.backend.executeStream(enrichedRequest, options?.signal);
|
|
186
|
+
});
|
|
187
|
+
// Step 7: Convert IR stream to frontend format
|
|
188
|
+
const frontendStream = this.frontend.fromIRStream(irStream);
|
|
189
|
+
// Step 8: Yield chunks to caller
|
|
190
|
+
let chunkSequence = 0;
|
|
191
|
+
for await (const chunk of frontendStream) {
|
|
192
|
+
chunkSequence++;
|
|
193
|
+
yield chunk;
|
|
194
|
+
}
|
|
195
|
+
// Track success (after stream completes)
|
|
196
|
+
this._successfulRequests++;
|
|
197
|
+
const durationMs = Date.now() - startTime;
|
|
198
|
+
this.recordLatency(durationMs);
|
|
199
|
+
// Emit STREAM_COMPLETE event
|
|
200
|
+
this.emit({
|
|
201
|
+
type: BridgeEventType.STREAM_COMPLETE,
|
|
202
|
+
timestamp: Date.now(),
|
|
203
|
+
requestId: enrichedRequest.metadata.requestId,
|
|
204
|
+
request: enrichedRequest,
|
|
205
|
+
chunkSequence,
|
|
206
|
+
durationMs,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
// Track failure
|
|
211
|
+
this._failedRequests++;
|
|
212
|
+
const errorCode = error instanceof AdapterError ? error.code : 'UNKNOWN';
|
|
213
|
+
this._errorCounts[errorCode] = (this._errorCounts[errorCode] ?? 0) + 1;
|
|
214
|
+
// Emit STREAM_ERROR event
|
|
215
|
+
this.emit({
|
|
216
|
+
type: BridgeEventType.STREAM_ERROR,
|
|
217
|
+
timestamp: Date.now(),
|
|
218
|
+
requestId: enrichedRequest.metadata.requestId,
|
|
219
|
+
request: enrichedRequest,
|
|
220
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
221
|
+
durationMs: Date.now() - startTime,
|
|
222
|
+
});
|
|
223
|
+
// Re-throw adapter errors, wrap others
|
|
224
|
+
if (error instanceof AdapterError) {
|
|
225
|
+
throw error;
|
|
226
|
+
}
|
|
227
|
+
throw new AdapterError({
|
|
228
|
+
code: ErrorCode.INTERNAL_ERROR,
|
|
229
|
+
message: `Bridge streaming failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
230
|
+
isRetryable: false,
|
|
231
|
+
cause: error instanceof Error ? error : undefined,
|
|
232
|
+
provenance: {},
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
// ==========================================================================
|
|
237
|
+
// Model Listing
|
|
238
|
+
// ==========================================================================
|
|
239
|
+
/**
|
|
240
|
+
* List available models from the backend.
|
|
241
|
+
*
|
|
242
|
+
* This delegates directly to the backend adapter's listModels() method.
|
|
243
|
+
* Useful for discovering available models before making requests.
|
|
244
|
+
*
|
|
245
|
+
* @param options Options for listing models (filtering, cache control)
|
|
246
|
+
* @returns List of available models, or null if backend doesn't support listing
|
|
247
|
+
*/
|
|
248
|
+
async listModels(options) {
|
|
249
|
+
if (!this.backend.listModels) {
|
|
250
|
+
return null; // Backend doesn't support model listing
|
|
251
|
+
}
|
|
252
|
+
return await this.backend.listModels(options);
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Check if a specific model is available from the backend.
|
|
256
|
+
*
|
|
257
|
+
* @param modelId Model identifier to check
|
|
258
|
+
* @returns true if model is available, false otherwise
|
|
259
|
+
*/
|
|
260
|
+
async hasModel(modelId) {
|
|
261
|
+
const result = await this.listModels();
|
|
262
|
+
if (!result) {
|
|
263
|
+
return true;
|
|
264
|
+
} // Can't check, assume available
|
|
265
|
+
return result.models.some((m) => m.id === modelId);
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Validate that a model is available (optional safety check).
|
|
269
|
+
*
|
|
270
|
+
* Note: This is an optional validation - the system doesn't automatically
|
|
271
|
+
* validate models since cross-provider translation is supported.
|
|
272
|
+
*
|
|
273
|
+
* @param modelId Model identifier to validate
|
|
274
|
+
* @throws {ValidationError} If model is not available
|
|
275
|
+
*/
|
|
276
|
+
async validateModel(modelId) {
|
|
277
|
+
const available = await this.hasModel(modelId);
|
|
278
|
+
if (!available) {
|
|
279
|
+
throw new ValidationError({
|
|
280
|
+
code: ErrorCode.UNSUPPORTED_MODEL,
|
|
281
|
+
message: `Model "${modelId}" is not available from backend "${this.backend.metadata.name}"`,
|
|
282
|
+
validationDetails: [
|
|
283
|
+
{
|
|
284
|
+
field: 'model',
|
|
285
|
+
value: modelId,
|
|
286
|
+
reason: `Model not available from backend "${this.backend.metadata.name}"`,
|
|
287
|
+
expected: 'Available model ID from backend',
|
|
288
|
+
},
|
|
289
|
+
],
|
|
290
|
+
provenance: {
|
|
291
|
+
frontend: this.frontend.metadata.name,
|
|
292
|
+
backend: this.backend.metadata.name,
|
|
293
|
+
},
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
// ==========================================================================
|
|
298
|
+
// Middleware Management
|
|
299
|
+
// ==========================================================================
|
|
300
|
+
/**
|
|
301
|
+
* Add middleware to the bridge's middleware stack.
|
|
302
|
+
*/
|
|
303
|
+
use(middleware) {
|
|
304
|
+
this.middlewareStack.use(middleware);
|
|
305
|
+
return this;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Remove middleware from the stack.
|
|
309
|
+
*
|
|
310
|
+
* @param middleware Middleware to remove
|
|
311
|
+
* @returns This bridge for chaining
|
|
312
|
+
*/
|
|
313
|
+
removeMiddleware(middleware) {
|
|
314
|
+
this.middlewareStack.remove(middleware);
|
|
315
|
+
return this;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Clear all middleware from the stack.
|
|
319
|
+
*/
|
|
320
|
+
clearMiddleware() {
|
|
321
|
+
this.middlewareStack.clear();
|
|
322
|
+
return this;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Get all middleware in the stack.
|
|
326
|
+
*/
|
|
327
|
+
getMiddleware() {
|
|
328
|
+
return this.middlewareStack.getMiddleware();
|
|
329
|
+
}
|
|
330
|
+
// ==========================================================================
|
|
331
|
+
// Event Handling
|
|
332
|
+
// ==========================================================================
|
|
333
|
+
/**
|
|
334
|
+
* Register an event listener.
|
|
335
|
+
*
|
|
336
|
+
* Note: Event emission is not yet implemented. Listeners are stored
|
|
337
|
+
* for future use when event emission is added.
|
|
338
|
+
*
|
|
339
|
+
* @param event Event type to listen for, or '*' for all events
|
|
340
|
+
* @param listener Callback function
|
|
341
|
+
*/
|
|
342
|
+
on(event, listener) {
|
|
343
|
+
const key = event;
|
|
344
|
+
if (!this._eventListeners.has(key)) {
|
|
345
|
+
this._eventListeners.set(key, new Set());
|
|
346
|
+
}
|
|
347
|
+
this._eventListeners.get(key).add(listener);
|
|
348
|
+
return this;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Remove an event listener.
|
|
352
|
+
*
|
|
353
|
+
* @param event Event type
|
|
354
|
+
* @param listener Callback function to remove
|
|
355
|
+
*/
|
|
356
|
+
off(event, listener) {
|
|
357
|
+
const key = event;
|
|
358
|
+
const listeners = this._eventListeners.get(key);
|
|
359
|
+
if (listeners) {
|
|
360
|
+
listeners.delete(listener);
|
|
361
|
+
}
|
|
362
|
+
return this;
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Register a one-time event listener.
|
|
366
|
+
*
|
|
367
|
+
* Note: Event emission is not yet implemented. Listeners are stored
|
|
368
|
+
* for future use when event emission is added.
|
|
369
|
+
*
|
|
370
|
+
* @param event Event type to listen for
|
|
371
|
+
* @param listener Callback function
|
|
372
|
+
*/
|
|
373
|
+
once(event, listener) {
|
|
374
|
+
const wrappedListener = (eventData) => {
|
|
375
|
+
this.off(event, wrappedListener);
|
|
376
|
+
return listener(eventData);
|
|
377
|
+
};
|
|
378
|
+
return this.on(event, wrappedListener);
|
|
379
|
+
}
|
|
380
|
+
// ==========================================================================
|
|
381
|
+
// Statistics & Monitoring
|
|
382
|
+
// ==========================================================================
|
|
383
|
+
/**
|
|
384
|
+
* Get runtime statistics for this bridge.
|
|
385
|
+
*
|
|
386
|
+
* @returns Bridge statistics including request counts, latencies, and error breakdown
|
|
387
|
+
*/
|
|
388
|
+
getStats() {
|
|
389
|
+
const sortedLatencies = [...this._latencies].sort((a, b) => a - b);
|
|
390
|
+
const len = sortedLatencies.length;
|
|
391
|
+
const getPercentile = (p) => {
|
|
392
|
+
if (len === 0) {
|
|
393
|
+
return 0;
|
|
394
|
+
}
|
|
395
|
+
const index = Math.ceil((p / 100) * len) - 1;
|
|
396
|
+
return sortedLatencies[Math.max(0, Math.min(index, len - 1))] ?? 0;
|
|
397
|
+
};
|
|
398
|
+
const avgLatency = len > 0 ? sortedLatencies.reduce((a, b) => a + b, 0) / len : 0;
|
|
399
|
+
return {
|
|
400
|
+
totalRequests: this._totalRequests,
|
|
401
|
+
successfulRequests: this._successfulRequests,
|
|
402
|
+
failedRequests: this._failedRequests,
|
|
403
|
+
successRate: this._totalRequests > 0 ? (this._successfulRequests / this._totalRequests) * 100 : 100,
|
|
404
|
+
streamingRequests: this._streamingRequests,
|
|
405
|
+
averageLatencyMs: Math.round(avgLatency),
|
|
406
|
+
p50LatencyMs: getPercentile(50),
|
|
407
|
+
p95LatencyMs: getPercentile(95),
|
|
408
|
+
p99LatencyMs: getPercentile(99),
|
|
409
|
+
backendUsage: {
|
|
410
|
+
[this.backend.metadata.name]: this._successfulRequests,
|
|
411
|
+
},
|
|
412
|
+
errorBreakdown: { ...this._errorCounts },
|
|
413
|
+
sinceTimestamp: this._statsResetTimestamp,
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Reset all statistics to zero.
|
|
418
|
+
*/
|
|
419
|
+
resetStats() {
|
|
420
|
+
this._totalRequests = 0;
|
|
421
|
+
this._successfulRequests = 0;
|
|
422
|
+
this._failedRequests = 0;
|
|
423
|
+
this._streamingRequests = 0;
|
|
424
|
+
this._latencies = [];
|
|
425
|
+
this._errorCounts = {};
|
|
426
|
+
this._statsResetTimestamp = Date.now();
|
|
427
|
+
}
|
|
428
|
+
// ==========================================================================
|
|
429
|
+
// Utility Methods
|
|
430
|
+
// ==========================================================================
|
|
431
|
+
/**
|
|
432
|
+
* Get router instance (returns null for basic Bridge).
|
|
433
|
+
*/
|
|
434
|
+
getRouter() {
|
|
435
|
+
return null;
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Check health of the backend.
|
|
439
|
+
*
|
|
440
|
+
* @returns true if backend is healthy, false otherwise
|
|
441
|
+
*/
|
|
442
|
+
async checkHealth() {
|
|
443
|
+
if (this.backend.healthCheck) {
|
|
444
|
+
return await this.backend.healthCheck();
|
|
445
|
+
}
|
|
446
|
+
return true; // Assume healthy if no health check is available
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Get a copy of the bridge configuration.
|
|
450
|
+
*
|
|
451
|
+
* @returns Readonly copy of the bridge configuration
|
|
452
|
+
*/
|
|
453
|
+
getConfig() {
|
|
454
|
+
return { ...this.config };
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Clone bridge with new configuration.
|
|
458
|
+
*/
|
|
459
|
+
clone(config) {
|
|
460
|
+
return new Bridge(this.frontend, this.backend, {
|
|
461
|
+
...this.config,
|
|
462
|
+
...config,
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Clean up resources.
|
|
467
|
+
*/
|
|
468
|
+
dispose() {
|
|
469
|
+
// Cleanup logic if needed
|
|
470
|
+
}
|
|
471
|
+
// ==========================================================================
|
|
472
|
+
// Private Helper Methods
|
|
473
|
+
// ==========================================================================
|
|
474
|
+
/**
|
|
475
|
+
* Enrich request with metadata (requestId, timestamp, provenance) and apply defaults.
|
|
476
|
+
*/
|
|
477
|
+
enrichRequest(request, options) {
|
|
478
|
+
// Always generate requestId if missing (frontend adapters should provide it)
|
|
479
|
+
const requestId = request.metadata?.requestId || this.generateRequestId();
|
|
480
|
+
const timestamp = request.metadata?.timestamp ?? Date.now();
|
|
481
|
+
// Apply default model if not specified in request
|
|
482
|
+
const model = request.parameters?.model ?? this.config.defaultModel;
|
|
483
|
+
return {
|
|
484
|
+
...request,
|
|
485
|
+
parameters: {
|
|
486
|
+
...request.parameters,
|
|
487
|
+
...(model && { model }),
|
|
488
|
+
},
|
|
489
|
+
metadata: {
|
|
490
|
+
...request.metadata,
|
|
491
|
+
requestId,
|
|
492
|
+
timestamp,
|
|
493
|
+
provenance: {
|
|
494
|
+
...request.metadata?.provenance,
|
|
495
|
+
frontend: this.frontend.metadata.name,
|
|
496
|
+
},
|
|
497
|
+
custom: {
|
|
498
|
+
...request.metadata?.custom,
|
|
499
|
+
...options?.metadata,
|
|
500
|
+
},
|
|
501
|
+
},
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Enrich response with provenance and timing.
|
|
506
|
+
*/
|
|
507
|
+
enrichResponse(response, request) {
|
|
508
|
+
return {
|
|
509
|
+
...response,
|
|
510
|
+
metadata: {
|
|
511
|
+
...response.metadata,
|
|
512
|
+
requestId: request.metadata.requestId,
|
|
513
|
+
provenance: {
|
|
514
|
+
...response.metadata.provenance,
|
|
515
|
+
frontend: this.frontend.metadata.name,
|
|
516
|
+
backend: this.backend.metadata.name,
|
|
517
|
+
},
|
|
518
|
+
},
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* Generate unique request ID.
|
|
523
|
+
*/
|
|
524
|
+
generateRequestId() {
|
|
525
|
+
// Use standard UUID v4 for request IDs
|
|
526
|
+
return crypto.randomUUID();
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Generate a structured object matching a Zod schema using an LLM.
|
|
530
|
+
*
|
|
531
|
+
* This method uses tool calling to extract structured data from the LLM response,
|
|
532
|
+
* validates it against the provided schema, and returns the typed object.
|
|
533
|
+
*
|
|
534
|
+
* @param options Configuration for object generation
|
|
535
|
+
* @returns Promise resolving to the generated and validated object
|
|
536
|
+
*
|
|
537
|
+
* @example
|
|
538
|
+
* ```typescript
|
|
539
|
+
* const UserSchema = z.object({
|
|
540
|
+
* name: z.string(),
|
|
541
|
+
* age: z.number(),
|
|
542
|
+
* email: z.string().email(),
|
|
543
|
+
* });
|
|
544
|
+
*
|
|
545
|
+
* const result = await bridge.generateObject({
|
|
546
|
+
* schema: UserSchema,
|
|
547
|
+
* prompt: 'Generate a user profile for Alice, age 30',
|
|
548
|
+
* model: 'gpt-4',
|
|
549
|
+
* });
|
|
550
|
+
*
|
|
551
|
+
* console.log(result.object); // { name: 'Alice', age: 30, email: '...' }
|
|
552
|
+
* ```
|
|
553
|
+
*/
|
|
554
|
+
generateObject = createGenerateObject(this);
|
|
555
|
+
/**
|
|
556
|
+
* Stream a structured object matching a Zod schema using an LLM.
|
|
557
|
+
*
|
|
558
|
+
* This method uses streaming tool calling to incrementally build up a structured
|
|
559
|
+
* object, yielding partial results as they become available.
|
|
560
|
+
*
|
|
561
|
+
* @param options Configuration for streaming object generation
|
|
562
|
+
* @returns Async generator yielding partial objects and returning the final validated object
|
|
563
|
+
*
|
|
564
|
+
* @example
|
|
565
|
+
* ```typescript
|
|
566
|
+
* const ArticleSchema = z.object({
|
|
567
|
+
* title: z.string(),
|
|
568
|
+
* content: z.string(),
|
|
569
|
+
* tags: z.array(z.string()),
|
|
570
|
+
* });
|
|
571
|
+
*
|
|
572
|
+
* const stream = bridge.streamObject({
|
|
573
|
+
* schema: ArticleSchema,
|
|
574
|
+
* prompt: 'Write a blog post about TypeScript',
|
|
575
|
+
* onPartial: (partial) => {
|
|
576
|
+
* console.log('Partial:', partial);
|
|
577
|
+
* },
|
|
578
|
+
* });
|
|
579
|
+
*
|
|
580
|
+
* for await (const partial of stream) {
|
|
581
|
+
* console.log('Progress:', partial);
|
|
582
|
+
* }
|
|
583
|
+
* ```
|
|
584
|
+
*/
|
|
585
|
+
streamObject = createStreamObject(this);
|
|
586
|
+
/**
|
|
587
|
+
* Emit an event to all registered listeners.
|
|
588
|
+
*
|
|
589
|
+
* @param event Event data to emit
|
|
590
|
+
*/
|
|
591
|
+
emit(event) {
|
|
592
|
+
// Emit to specific event type listeners
|
|
593
|
+
const specificListeners = this._eventListeners.get(event.type);
|
|
594
|
+
if (specificListeners) {
|
|
595
|
+
for (const listener of specificListeners) {
|
|
596
|
+
try {
|
|
597
|
+
void listener(event);
|
|
598
|
+
}
|
|
599
|
+
catch {
|
|
600
|
+
// Ignore listener errors to prevent breaking the chain
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
// Emit to wildcard listeners
|
|
605
|
+
const wildcardListeners = this._eventListeners.get('*');
|
|
606
|
+
if (wildcardListeners) {
|
|
607
|
+
for (const listener of wildcardListeners) {
|
|
608
|
+
try {
|
|
609
|
+
void listener(event);
|
|
610
|
+
}
|
|
611
|
+
catch {
|
|
612
|
+
// Ignore listener errors to prevent breaking the chain
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Record a latency sample, maintaining a rolling window to prevent unbounded memory growth.
|
|
619
|
+
*
|
|
620
|
+
* @param latencyMs Latency in milliseconds
|
|
621
|
+
*/
|
|
622
|
+
recordLatency(latencyMs) {
|
|
623
|
+
this._latencies.push(latencyMs);
|
|
624
|
+
// Maintain rolling window to prevent memory leak in long-running applications
|
|
625
|
+
if (this._latencies.length > Bridge.MAX_LATENCY_SAMPLES) {
|
|
626
|
+
this._latencies.shift();
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* Delay execution for a specified number of milliseconds.
|
|
631
|
+
*
|
|
632
|
+
* @param ms Milliseconds to delay
|
|
633
|
+
*/
|
|
634
|
+
delay(ms) {
|
|
635
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
// ============================================================================
|
|
639
|
+
// Factory Functions
|
|
640
|
+
// ============================================================================
|
|
641
|
+
/**
|
|
642
|
+
* Create a new Bridge instance.
|
|
643
|
+
*
|
|
644
|
+
* @param frontend Frontend adapter
|
|
645
|
+
* @param backend Backend adapter
|
|
646
|
+
* @param config Bridge configuration
|
|
647
|
+
* @returns Bridge instance
|
|
648
|
+
*/
|
|
649
|
+
export function createBridge(frontend, backend, config) {
|
|
650
|
+
return new Bridge(frontend, backend, config);
|
|
651
|
+
}
|
|
652
|
+
//# sourceMappingURL=bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../src/bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAoBH,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGjD,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,gCAAgC,GACjC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEjG,+EAA+E;AAC/E,wBAAwB;AACxB,+EAA+E;AAE/E;;;;GAIG;AACH,MAAM,OAAO,MAAM;IAGR,QAAQ,CAAY;IACpB,OAAO,CAAiB;IACxB,MAAM,CAA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