ai.matey.types 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/adapters.js +16 -0
- package/dist/cjs/adapters.js.map +1 -0
- package/dist/cjs/bridge.js +32 -0
- package/dist/cjs/bridge.js.map +1 -0
- package/dist/cjs/errors.js +121 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/index.js +44 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/ir.js +17 -0
- package/dist/cjs/ir.js.map +1 -0
- package/dist/cjs/middleware.js +11 -0
- package/dist/cjs/middleware.js.map +1 -0
- package/dist/cjs/model-runner.js +11 -0
- package/dist/cjs/model-runner.js.map +1 -0
- package/dist/cjs/model-translation.js +10 -0
- package/dist/cjs/model-translation.js.map +1 -0
- package/dist/cjs/models.js +11 -0
- package/dist/cjs/models.js.map +1 -0
- package/dist/cjs/router.js +93 -0
- package/dist/cjs/router.js.map +1 -0
- package/dist/cjs/streaming.js +28 -0
- package/dist/cjs/streaming.js.map +1 -0
- package/dist/esm/adapters.js +15 -0
- package/dist/esm/adapters.js.map +1 -0
- package/dist/esm/bridge.js +29 -0
- package/dist/esm/bridge.js.map +1 -0
- package/dist/esm/errors.js +118 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/index.js +28 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/ir.js +16 -0
- package/dist/esm/ir.js.map +1 -0
- package/dist/esm/middleware.js +10 -0
- package/dist/esm/middleware.js.map +1 -0
- package/dist/esm/model-runner.js +10 -0
- package/dist/esm/model-runner.js.map +1 -0
- package/dist/esm/model-translation.js +9 -0
- package/dist/esm/model-translation.js.map +1 -0
- package/dist/esm/models.js +10 -0
- package/dist/esm/models.js.map +1 -0
- package/dist/esm/router.js +90 -0
- package/dist/esm/router.js.map +1 -0
- package/dist/esm/streaming.js +25 -0
- package/dist/esm/streaming.js.map +1 -0
- package/dist/types/adapters.d.ts +377 -0
- package/dist/types/adapters.d.ts.map +1 -0
- package/dist/types/bridge.d.ts +290 -0
- package/dist/types/bridge.d.ts.map +1 -0
- package/dist/types/errors.d.ts +380 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/index.d.ts +18 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/ir.d.ts +820 -0
- package/dist/types/ir.d.ts.map +1 -0
- package/dist/types/middleware.d.ts +256 -0
- package/dist/types/middleware.d.ts.map +1 -0
- package/dist/types/model-runner.d.ts +344 -0
- package/dist/types/model-runner.d.ts.map +1 -0
- package/dist/types/model-translation.d.ts +76 -0
- package/dist/types/model-translation.d.ts.map +1 -0
- package/dist/types/models.d.ts +160 -0
- package/dist/types/models.d.ts.map +1 -0
- package/dist/types/router.d.ts +526 -0
- package/dist/types/router.d.ts.map +1 -0
- package/dist/types/streaming.d.ts +96 -0
- package/dist/types/streaming.d.ts.map +1 -0
- package/package.json +64 -0
- package/readme.md +84 -0
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bridge Types and Interfaces
|
|
3
|
+
*
|
|
4
|
+
* The Bridge is the primary developer-facing API for the Universal AI Adapter System.
|
|
5
|
+
* It connects a frontend adapter to one or more backend adapters, with embedded
|
|
6
|
+
* router and middleware stack for orchestration and cross-cutting concerns.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import type { FrontendAdapter, BackendAdapter, InferFrontendRequest, InferFrontendResponse, InferFrontendStreamChunk } from './adapters.js';
|
|
11
|
+
import type { Router, RouterConfig } from './router.js';
|
|
12
|
+
import type { Middleware } from './middleware.js';
|
|
13
|
+
import type { IRChatRequest, IRChatResponse } from './ir.js';
|
|
14
|
+
/**
|
|
15
|
+
* Configuration options for Bridge.
|
|
16
|
+
*/
|
|
17
|
+
export interface BridgeConfig {
|
|
18
|
+
/**
|
|
19
|
+
* Enable debug mode with detailed logging.
|
|
20
|
+
* @default false
|
|
21
|
+
*/
|
|
22
|
+
readonly debug?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Global timeout for requests in milliseconds.
|
|
25
|
+
* @default 30000
|
|
26
|
+
*/
|
|
27
|
+
readonly timeout?: number;
|
|
28
|
+
/**
|
|
29
|
+
* Maximum retries for transient failures.
|
|
30
|
+
* @default 0
|
|
31
|
+
*/
|
|
32
|
+
readonly retries?: number;
|
|
33
|
+
/**
|
|
34
|
+
* Default model to use if not specified in request.
|
|
35
|
+
*/
|
|
36
|
+
readonly defaultModel?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Router configuration (if using router as backend).
|
|
39
|
+
*/
|
|
40
|
+
readonly routerConfig?: Partial<RouterConfig>;
|
|
41
|
+
/**
|
|
42
|
+
* Automatically add request ID to metadata if not present.
|
|
43
|
+
* @default true
|
|
44
|
+
*/
|
|
45
|
+
readonly autoRequestId?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Custom configuration options.
|
|
48
|
+
*/
|
|
49
|
+
readonly custom?: Record<string, unknown>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Per-request options for overriding defaults.
|
|
53
|
+
*/
|
|
54
|
+
export interface RequestOptions {
|
|
55
|
+
/**
|
|
56
|
+
* Request timeout in milliseconds.
|
|
57
|
+
*/
|
|
58
|
+
readonly timeout?: number;
|
|
59
|
+
/**
|
|
60
|
+
* AbortSignal for request cancellation.
|
|
61
|
+
*/
|
|
62
|
+
readonly signal?: AbortSignal;
|
|
63
|
+
/**
|
|
64
|
+
* Preferred backend identifier (for router).
|
|
65
|
+
*/
|
|
66
|
+
readonly backend?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Additional metadata to attach to request.
|
|
69
|
+
*/
|
|
70
|
+
readonly metadata?: Record<string, unknown>;
|
|
71
|
+
/**
|
|
72
|
+
* Skip middleware execution for this request.
|
|
73
|
+
* @default false
|
|
74
|
+
*/
|
|
75
|
+
readonly skipMiddleware?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Custom request options.
|
|
78
|
+
*/
|
|
79
|
+
readonly custom?: Record<string, unknown>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Event types emitted by Bridge.
|
|
83
|
+
*/
|
|
84
|
+
export declare const BridgeEventType: {
|
|
85
|
+
readonly REQUEST_START: "request:start";
|
|
86
|
+
readonly REQUEST_SUCCESS: "request:success";
|
|
87
|
+
readonly REQUEST_ERROR: "request:error";
|
|
88
|
+
readonly REQUEST_CANCELLED: "request:cancelled";
|
|
89
|
+
readonly STREAM_START: "stream:start";
|
|
90
|
+
readonly STREAM_CHUNK: "stream:chunk";
|
|
91
|
+
readonly STREAM_COMPLETE: "stream:complete";
|
|
92
|
+
readonly STREAM_ERROR: "stream:error";
|
|
93
|
+
readonly BACKEND_SELECTED: "backend:selected";
|
|
94
|
+
readonly BACKEND_FAILOVER: "backend:failover";
|
|
95
|
+
readonly MIDDLEWARE_EXECUTED: "middleware:executed";
|
|
96
|
+
};
|
|
97
|
+
export type BridgeEventType = (typeof BridgeEventType)[keyof typeof BridgeEventType];
|
|
98
|
+
/**
|
|
99
|
+
* Base event interface.
|
|
100
|
+
*/
|
|
101
|
+
export interface BridgeEvent {
|
|
102
|
+
readonly type: BridgeEventType;
|
|
103
|
+
readonly timestamp: number;
|
|
104
|
+
readonly requestId?: string;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Request event with request details.
|
|
108
|
+
*/
|
|
109
|
+
export interface RequestEvent extends BridgeEvent {
|
|
110
|
+
readonly type: typeof BridgeEventType.REQUEST_START | typeof BridgeEventType.REQUEST_SUCCESS | typeof BridgeEventType.REQUEST_ERROR | typeof BridgeEventType.REQUEST_CANCELLED;
|
|
111
|
+
readonly request: IRChatRequest;
|
|
112
|
+
readonly response?: IRChatResponse;
|
|
113
|
+
readonly error?: Error;
|
|
114
|
+
readonly durationMs?: number;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Stream event with stream details.
|
|
118
|
+
*/
|
|
119
|
+
export interface StreamEvent extends BridgeEvent {
|
|
120
|
+
readonly type: typeof BridgeEventType.STREAM_START | typeof BridgeEventType.STREAM_CHUNK | typeof BridgeEventType.STREAM_COMPLETE | typeof BridgeEventType.STREAM_ERROR;
|
|
121
|
+
readonly request: IRChatRequest;
|
|
122
|
+
readonly chunkSequence?: number;
|
|
123
|
+
readonly error?: Error;
|
|
124
|
+
readonly durationMs?: number;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Backend event with backend details.
|
|
128
|
+
*/
|
|
129
|
+
export interface BackendEvent extends BridgeEvent {
|
|
130
|
+
readonly type: typeof BridgeEventType.BACKEND_SELECTED | typeof BridgeEventType.BACKEND_FAILOVER;
|
|
131
|
+
readonly backend: string;
|
|
132
|
+
readonly previousBackend?: string;
|
|
133
|
+
readonly reason?: string;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Middleware event with middleware details.
|
|
137
|
+
*/
|
|
138
|
+
export interface MiddlewareEvent extends BridgeEvent {
|
|
139
|
+
readonly type: typeof BridgeEventType.MIDDLEWARE_EXECUTED;
|
|
140
|
+
readonly middlewareName: string;
|
|
141
|
+
readonly durationMs: number;
|
|
142
|
+
readonly phase: 'request' | 'response';
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Union of all event types.
|
|
146
|
+
*/
|
|
147
|
+
export type BridgeEventData = RequestEvent | StreamEvent | BackendEvent | MiddlewareEvent;
|
|
148
|
+
/**
|
|
149
|
+
* Event listener function.
|
|
150
|
+
*/
|
|
151
|
+
export type BridgeEventListener = (event: BridgeEventData) => void | Promise<void>;
|
|
152
|
+
/**
|
|
153
|
+
* Runtime statistics collected by Bridge.
|
|
154
|
+
*/
|
|
155
|
+
export interface BridgeStats {
|
|
156
|
+
/**
|
|
157
|
+
* Total requests processed.
|
|
158
|
+
*/
|
|
159
|
+
readonly totalRequests: number;
|
|
160
|
+
/**
|
|
161
|
+
* Successful requests.
|
|
162
|
+
*/
|
|
163
|
+
readonly successfulRequests: number;
|
|
164
|
+
/**
|
|
165
|
+
* Failed requests.
|
|
166
|
+
*/
|
|
167
|
+
readonly failedRequests: number;
|
|
168
|
+
/**
|
|
169
|
+
* Success rate (0-100).
|
|
170
|
+
*/
|
|
171
|
+
readonly successRate: number;
|
|
172
|
+
/**
|
|
173
|
+
* Total streaming requests.
|
|
174
|
+
*/
|
|
175
|
+
readonly streamingRequests: number;
|
|
176
|
+
/**
|
|
177
|
+
* Average request latency in milliseconds.
|
|
178
|
+
*/
|
|
179
|
+
readonly averageLatencyMs: number;
|
|
180
|
+
/**
|
|
181
|
+
* P50 latency in milliseconds.
|
|
182
|
+
*/
|
|
183
|
+
readonly p50LatencyMs: number;
|
|
184
|
+
/**
|
|
185
|
+
* P95 latency in milliseconds.
|
|
186
|
+
*/
|
|
187
|
+
readonly p95LatencyMs: number;
|
|
188
|
+
/**
|
|
189
|
+
* P99 latency in milliseconds.
|
|
190
|
+
*/
|
|
191
|
+
readonly p99LatencyMs: number;
|
|
192
|
+
/**
|
|
193
|
+
* Backend usage breakdown (backend name → request count).
|
|
194
|
+
*/
|
|
195
|
+
readonly backendUsage: Record<string, number>;
|
|
196
|
+
/**
|
|
197
|
+
* Error breakdown (error code → count).
|
|
198
|
+
*/
|
|
199
|
+
readonly errorBreakdown: Record<string, number>;
|
|
200
|
+
/**
|
|
201
|
+
* When statistics were last reset.
|
|
202
|
+
*/
|
|
203
|
+
readonly sinceTimestamp: number;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* The Bridge connects frontend and backend adapters with routing and middleware.
|
|
207
|
+
*
|
|
208
|
+
* @template TFrontend Frontend adapter type
|
|
209
|
+
*/
|
|
210
|
+
export interface Bridge<TFrontend extends FrontendAdapter = FrontendAdapter> {
|
|
211
|
+
/**
|
|
212
|
+
* Frontend adapter for this bridge.
|
|
213
|
+
*/
|
|
214
|
+
readonly frontend: TFrontend;
|
|
215
|
+
/**
|
|
216
|
+
* Backend adapter or router.
|
|
217
|
+
*/
|
|
218
|
+
readonly backend: BackendAdapter | Router;
|
|
219
|
+
/**
|
|
220
|
+
* Bridge configuration.
|
|
221
|
+
*/
|
|
222
|
+
readonly config: BridgeConfig;
|
|
223
|
+
/**
|
|
224
|
+
* Execute a non-streaming chat completion request.
|
|
225
|
+
*/
|
|
226
|
+
chat(request: InferFrontendRequest<TFrontend>, options?: RequestOptions): Promise<InferFrontendResponse<TFrontend>>;
|
|
227
|
+
/**
|
|
228
|
+
* Execute a streaming chat completion request.
|
|
229
|
+
*/
|
|
230
|
+
chatStream(request: InferFrontendRequest<TFrontend>, options?: RequestOptions): AsyncGenerator<InferFrontendStreamChunk<TFrontend>, void, undefined>;
|
|
231
|
+
/**
|
|
232
|
+
* Add middleware to the bridge's middleware stack.
|
|
233
|
+
*/
|
|
234
|
+
use(middleware: Middleware): Bridge<TFrontend>;
|
|
235
|
+
/**
|
|
236
|
+
* Remove middleware from the stack.
|
|
237
|
+
*/
|
|
238
|
+
removeMiddleware(middleware: Middleware): Bridge<TFrontend>;
|
|
239
|
+
/**
|
|
240
|
+
* Clear all middleware from the stack.
|
|
241
|
+
*/
|
|
242
|
+
clearMiddleware(): Bridge<TFrontend>;
|
|
243
|
+
/**
|
|
244
|
+
* Get all middleware in the stack.
|
|
245
|
+
*/
|
|
246
|
+
getMiddleware(): readonly Middleware[];
|
|
247
|
+
/**
|
|
248
|
+
* Register event listener.
|
|
249
|
+
*/
|
|
250
|
+
on(event: BridgeEventType | '*', listener: BridgeEventListener): Bridge<TFrontend>;
|
|
251
|
+
/**
|
|
252
|
+
* Unregister event listener.
|
|
253
|
+
*/
|
|
254
|
+
off(event: BridgeEventType | '*', listener: BridgeEventListener): Bridge<TFrontend>;
|
|
255
|
+
/**
|
|
256
|
+
* Register one-time event listener.
|
|
257
|
+
*/
|
|
258
|
+
once(event: BridgeEventType, listener: BridgeEventListener): Bridge<TFrontend>;
|
|
259
|
+
/**
|
|
260
|
+
* Get runtime statistics.
|
|
261
|
+
*/
|
|
262
|
+
getStats(): BridgeStats;
|
|
263
|
+
/**
|
|
264
|
+
* Reset statistics.
|
|
265
|
+
*/
|
|
266
|
+
resetStats(): void;
|
|
267
|
+
/**
|
|
268
|
+
* Get router instance (if backend is a router).
|
|
269
|
+
*/
|
|
270
|
+
getRouter(): Router | null;
|
|
271
|
+
/**
|
|
272
|
+
* Clone bridge with new configuration.
|
|
273
|
+
*/
|
|
274
|
+
clone(config: Partial<BridgeConfig>): Bridge<TFrontend>;
|
|
275
|
+
/**
|
|
276
|
+
* Clean up resources.
|
|
277
|
+
*/
|
|
278
|
+
dispose(): void;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Bridge builder for fluent API.
|
|
282
|
+
*/
|
|
283
|
+
export interface BridgeBuilder<TFrontend extends FrontendAdapter = FrontendAdapter> {
|
|
284
|
+
withFrontend<T extends FrontendAdapter>(frontend: T): BridgeBuilder<T>;
|
|
285
|
+
withBackend(backend: BackendAdapter | Router): BridgeBuilder<TFrontend>;
|
|
286
|
+
withConfig(config: Partial<BridgeConfig>): BridgeBuilder<TFrontend>;
|
|
287
|
+
withMiddleware(middleware: Middleware): BridgeBuilder<TFrontend>;
|
|
288
|
+
build(): Bridge<TFrontend>;
|
|
289
|
+
}
|
|
290
|
+
//# sourceMappingURL=bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../../src/bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,oBAAoB,EACpB,qBAAqB,EACrB,wBAAwB,EACzB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE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mB,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;IAM/E;;OAEG;IACH,QAAQ,IAAI,WAAW,CAAC;IAExB;;OAEG;IACH,UAAU,IAAI,IAAI,CAAC;IAMnB;;OAEG;IACH,SAAS,IAAI,MAAM,GAAG,IAAI,CAAC;IAE3B;;OAEG;IACH,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;IAExD;;OAEG;IACH,OAAO,IAAI,IAAI,CAAC;CACjB;AAMD;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,SAAS,SAAS,eAAe,GAAG,eAAe;IAChF,YAAY,CAAC,CAAC,SAAS,eAAe,EAAE,QAAQ,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;IACvE,WAAW,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;IACxE,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;IACpE,cAAc,CAAC,UAAU,EAAE,UAAU,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;IACjE,KAAK,IAAI,MAAM,CAAC,SAAS,CAAC,CAAC;CAC5B"}
|
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error Types and Codes
|
|
3
|
+
*
|
|
4
|
+
* Normalized error handling across all AI providers. Provider-specific errors
|
|
5
|
+
* are translated to universal error types with actionable context.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import type { IRChatRequest, IRChatResponse } from './ir.js';
|
|
10
|
+
/**
|
|
11
|
+
* Universal error codes covering all adapter failure modes.
|
|
12
|
+
*/
|
|
13
|
+
export declare const ErrorCode: {
|
|
14
|
+
readonly INVALID_API_KEY: "INVALID_API_KEY";
|
|
15
|
+
readonly MISSING_API_KEY: "MISSING_API_KEY";
|
|
16
|
+
readonly EXPIRED_API_KEY: "EXPIRED_API_KEY";
|
|
17
|
+
readonly INSUFFICIENT_PERMISSIONS: "INSUFFICIENT_PERMISSIONS";
|
|
18
|
+
readonly QUOTA_EXCEEDED: "QUOTA_EXCEEDED";
|
|
19
|
+
readonly RATE_LIMIT_EXCEEDED: "RATE_LIMIT_EXCEEDED";
|
|
20
|
+
readonly INVALID_REQUEST: "INVALID_REQUEST";
|
|
21
|
+
readonly INVALID_MESSAGE_FORMAT: "INVALID_MESSAGE_FORMAT";
|
|
22
|
+
readonly INVALID_PARAMETERS: "INVALID_PARAMETERS";
|
|
23
|
+
readonly UNSUPPORTED_MODEL: "UNSUPPORTED_MODEL";
|
|
24
|
+
readonly UNSUPPORTED_FEATURE: "UNSUPPORTED_FEATURE";
|
|
25
|
+
readonly CONTEXT_LENGTH_EXCEEDED: "CONTEXT_LENGTH_EXCEEDED";
|
|
26
|
+
readonly PROVIDER_ERROR: "PROVIDER_ERROR";
|
|
27
|
+
readonly PROVIDER_UNAVAILABLE: "PROVIDER_UNAVAILABLE";
|
|
28
|
+
readonly PROVIDER_TIMEOUT: "PROVIDER_TIMEOUT";
|
|
29
|
+
readonly PROVIDER_OVERLOADED: "PROVIDER_OVERLOADED";
|
|
30
|
+
readonly ADAPTER_CONVERSION_ERROR: "ADAPTER_CONVERSION_ERROR";
|
|
31
|
+
readonly ADAPTER_VALIDATION_ERROR: "ADAPTER_VALIDATION_ERROR";
|
|
32
|
+
readonly UNSUPPORTED_CONVERSION: "UNSUPPORTED_CONVERSION";
|
|
33
|
+
readonly SEMANTIC_DRIFT_ERROR: "SEMANTIC_DRIFT_ERROR";
|
|
34
|
+
readonly NETWORK_ERROR: "NETWORK_ERROR";
|
|
35
|
+
readonly CONNECTION_TIMEOUT: "CONNECTION_TIMEOUT";
|
|
36
|
+
readonly DNS_RESOLUTION_FAILED: "DNS_RESOLUTION_FAILED";
|
|
37
|
+
readonly STREAM_ERROR: "STREAM_ERROR";
|
|
38
|
+
readonly STREAM_INTERRUPTED: "STREAM_INTERRUPTED";
|
|
39
|
+
readonly STREAM_PARSE_ERROR: "STREAM_PARSE_ERROR";
|
|
40
|
+
readonly STREAM_CANCELLED: "STREAM_CANCELLED";
|
|
41
|
+
readonly NO_BACKEND_AVAILABLE: "NO_BACKEND_AVAILABLE";
|
|
42
|
+
readonly ROUTING_FAILED: "ROUTING_FAILED";
|
|
43
|
+
readonly ALL_BACKENDS_FAILED: "ALL_BACKENDS_FAILED";
|
|
44
|
+
readonly MIDDLEWARE_ERROR: "MIDDLEWARE_ERROR";
|
|
45
|
+
readonly UNKNOWN_ERROR: "UNKNOWN_ERROR";
|
|
46
|
+
readonly INTERNAL_ERROR: "INTERNAL_ERROR";
|
|
47
|
+
};
|
|
48
|
+
export type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode];
|
|
49
|
+
/**
|
|
50
|
+
* Groups error codes into categories for easier handling.
|
|
51
|
+
*/
|
|
52
|
+
export declare const ErrorCategory: {
|
|
53
|
+
readonly AUTHENTICATION: "authentication";
|
|
54
|
+
readonly AUTHORIZATION: "authorization";
|
|
55
|
+
readonly RATE_LIMIT: "rate_limit";
|
|
56
|
+
readonly VALIDATION: "validation";
|
|
57
|
+
readonly PROVIDER: "provider";
|
|
58
|
+
readonly ADAPTER: "adapter";
|
|
59
|
+
readonly NETWORK: "network";
|
|
60
|
+
readonly STREAMING: "streaming";
|
|
61
|
+
readonly ROUTING: "routing";
|
|
62
|
+
readonly MIDDLEWARE: "middleware";
|
|
63
|
+
readonly UNKNOWN: "unknown";
|
|
64
|
+
};
|
|
65
|
+
export type ErrorCategory = (typeof ErrorCategory)[keyof typeof ErrorCategory];
|
|
66
|
+
/**
|
|
67
|
+
* Maps error codes to their categories.
|
|
68
|
+
*/
|
|
69
|
+
export declare const ERROR_CODE_CATEGORIES: Record<ErrorCode, ErrorCategory>;
|
|
70
|
+
/**
|
|
71
|
+
* Context about where an error occurred in the adapter chain.
|
|
72
|
+
*/
|
|
73
|
+
export interface ErrorProvenance {
|
|
74
|
+
/**
|
|
75
|
+
* Frontend adapter that initiated the request.
|
|
76
|
+
*/
|
|
77
|
+
readonly frontend?: string;
|
|
78
|
+
/**
|
|
79
|
+
* Backend adapter that was processing the request.
|
|
80
|
+
*/
|
|
81
|
+
readonly backend?: string;
|
|
82
|
+
/**
|
|
83
|
+
* Middleware layer where error occurred (if applicable).
|
|
84
|
+
*/
|
|
85
|
+
readonly middleware?: string;
|
|
86
|
+
/**
|
|
87
|
+
* Router that was handling the request (if applicable).
|
|
88
|
+
*/
|
|
89
|
+
readonly router?: string;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* HTTP status code and additional HTTP context.
|
|
93
|
+
*/
|
|
94
|
+
export interface HttpErrorContext {
|
|
95
|
+
readonly statusCode: number;
|
|
96
|
+
readonly statusText?: string;
|
|
97
|
+
readonly headers?: Record<string, string>;
|
|
98
|
+
readonly responseBody?: unknown;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Provider-specific error information.
|
|
102
|
+
*/
|
|
103
|
+
export interface ProviderErrorDetails {
|
|
104
|
+
/**
|
|
105
|
+
* Original error code from provider.
|
|
106
|
+
*/
|
|
107
|
+
readonly providerCode?: string;
|
|
108
|
+
/**
|
|
109
|
+
* Original error message from provider.
|
|
110
|
+
*/
|
|
111
|
+
readonly providerMessage?: string;
|
|
112
|
+
/**
|
|
113
|
+
* Provider name (openai, anthropic, gemini, etc.).
|
|
114
|
+
*/
|
|
115
|
+
readonly provider: string;
|
|
116
|
+
/**
|
|
117
|
+
* Provider-specific error data.
|
|
118
|
+
*/
|
|
119
|
+
readonly providerData?: Record<string, unknown>;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Validation error details.
|
|
123
|
+
*/
|
|
124
|
+
export interface ValidationErrorDetails {
|
|
125
|
+
/**
|
|
126
|
+
* Field or parameter that failed validation.
|
|
127
|
+
*/
|
|
128
|
+
readonly field: string;
|
|
129
|
+
/**
|
|
130
|
+
* Value that failed validation.
|
|
131
|
+
*/
|
|
132
|
+
readonly value: unknown;
|
|
133
|
+
/**
|
|
134
|
+
* Why validation failed.
|
|
135
|
+
*/
|
|
136
|
+
readonly reason: string;
|
|
137
|
+
/**
|
|
138
|
+
* Expected format or constraint.
|
|
139
|
+
*/
|
|
140
|
+
readonly expected?: string;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Rate limit error details.
|
|
144
|
+
*/
|
|
145
|
+
export interface RateLimitErrorDetails {
|
|
146
|
+
/**
|
|
147
|
+
* Time until rate limit resets (milliseconds).
|
|
148
|
+
*/
|
|
149
|
+
readonly retryAfter?: number;
|
|
150
|
+
/**
|
|
151
|
+
* Rate limit ceiling (requests per period).
|
|
152
|
+
*/
|
|
153
|
+
readonly limit?: number;
|
|
154
|
+
/**
|
|
155
|
+
* Remaining requests in current period.
|
|
156
|
+
*/
|
|
157
|
+
readonly remaining?: number;
|
|
158
|
+
/**
|
|
159
|
+
* When limit resets (ISO timestamp).
|
|
160
|
+
*/
|
|
161
|
+
readonly resetAt?: string;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Base error constructor options.
|
|
165
|
+
*/
|
|
166
|
+
export interface BaseErrorOptions {
|
|
167
|
+
readonly code: ErrorCode;
|
|
168
|
+
readonly message: string;
|
|
169
|
+
readonly isRetryable?: boolean;
|
|
170
|
+
readonly provenance?: ErrorProvenance;
|
|
171
|
+
readonly cause?: Error;
|
|
172
|
+
readonly irState?: {
|
|
173
|
+
readonly request?: Partial<IRChatRequest>;
|
|
174
|
+
readonly response?: Partial<IRChatResponse>;
|
|
175
|
+
};
|
|
176
|
+
readonly details?: Record<string, unknown>;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Authentication error constructor options.
|
|
180
|
+
*/
|
|
181
|
+
export interface AuthenticationErrorOptions {
|
|
182
|
+
readonly code: typeof ErrorCode.INVALID_API_KEY | typeof ErrorCode.MISSING_API_KEY | typeof ErrorCode.EXPIRED_API_KEY;
|
|
183
|
+
readonly message: string;
|
|
184
|
+
readonly provenance?: ErrorProvenance;
|
|
185
|
+
readonly cause?: Error;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Authorization error constructor options.
|
|
189
|
+
*/
|
|
190
|
+
export interface AuthorizationErrorOptions {
|
|
191
|
+
readonly code: typeof ErrorCode.INSUFFICIENT_PERMISSIONS | typeof ErrorCode.QUOTA_EXCEEDED;
|
|
192
|
+
readonly message: string;
|
|
193
|
+
readonly provenance?: ErrorProvenance;
|
|
194
|
+
readonly cause?: Error;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Rate limit error constructor options.
|
|
198
|
+
*/
|
|
199
|
+
export interface RateLimitErrorOptions {
|
|
200
|
+
readonly message: string;
|
|
201
|
+
readonly provenance?: ErrorProvenance;
|
|
202
|
+
readonly cause?: Error;
|
|
203
|
+
readonly rateLimitDetails?: RateLimitErrorDetails;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Validation error constructor options.
|
|
207
|
+
*/
|
|
208
|
+
export interface ValidationErrorOptions {
|
|
209
|
+
readonly code: typeof ErrorCode.INVALID_REQUEST | typeof ErrorCode.INVALID_MESSAGE_FORMAT | typeof ErrorCode.INVALID_PARAMETERS | typeof ErrorCode.UNSUPPORTED_MODEL | typeof ErrorCode.UNSUPPORTED_FEATURE | typeof ErrorCode.CONTEXT_LENGTH_EXCEEDED;
|
|
210
|
+
readonly message: string;
|
|
211
|
+
readonly validationDetails: ValidationErrorDetails[];
|
|
212
|
+
readonly provenance?: ErrorProvenance;
|
|
213
|
+
readonly irState?: {
|
|
214
|
+
readonly request?: Partial<IRChatRequest>;
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Provider error constructor options.
|
|
219
|
+
*/
|
|
220
|
+
export interface ProviderErrorOptions {
|
|
221
|
+
readonly code: typeof ErrorCode.PROVIDER_ERROR | typeof ErrorCode.PROVIDER_UNAVAILABLE | typeof ErrorCode.PROVIDER_TIMEOUT | typeof ErrorCode.PROVIDER_OVERLOADED;
|
|
222
|
+
readonly message: string;
|
|
223
|
+
readonly isRetryable?: boolean;
|
|
224
|
+
readonly provenance?: ErrorProvenance;
|
|
225
|
+
readonly cause?: Error;
|
|
226
|
+
readonly providerDetails?: ProviderErrorDetails;
|
|
227
|
+
readonly httpContext?: HttpErrorContext;
|
|
228
|
+
readonly irState?: {
|
|
229
|
+
readonly request?: Partial<IRChatRequest>;
|
|
230
|
+
readonly response?: Partial<IRChatResponse>;
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Adapter conversion error constructor options.
|
|
235
|
+
*/
|
|
236
|
+
export interface AdapterConversionErrorOptions {
|
|
237
|
+
readonly code: typeof ErrorCode.ADAPTER_CONVERSION_ERROR | typeof ErrorCode.ADAPTER_VALIDATION_ERROR | typeof ErrorCode.UNSUPPORTED_CONVERSION | typeof ErrorCode.SEMANTIC_DRIFT_ERROR;
|
|
238
|
+
readonly message: string;
|
|
239
|
+
readonly provenance?: ErrorProvenance;
|
|
240
|
+
readonly cause?: Error;
|
|
241
|
+
readonly irState?: {
|
|
242
|
+
readonly request?: Partial<IRChatRequest>;
|
|
243
|
+
readonly response?: Partial<IRChatResponse>;
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Network error constructor options.
|
|
248
|
+
*/
|
|
249
|
+
export interface NetworkErrorOptions {
|
|
250
|
+
readonly code: typeof ErrorCode.NETWORK_ERROR | typeof ErrorCode.CONNECTION_TIMEOUT | typeof ErrorCode.DNS_RESOLUTION_FAILED;
|
|
251
|
+
readonly message: string;
|
|
252
|
+
readonly provenance?: ErrorProvenance;
|
|
253
|
+
readonly cause?: Error;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Stream error constructor options.
|
|
257
|
+
*/
|
|
258
|
+
export interface StreamErrorOptions {
|
|
259
|
+
readonly code: typeof ErrorCode.STREAM_ERROR | typeof ErrorCode.STREAM_INTERRUPTED | typeof ErrorCode.STREAM_PARSE_ERROR | typeof ErrorCode.STREAM_CANCELLED;
|
|
260
|
+
readonly message: string;
|
|
261
|
+
readonly provenance?: ErrorProvenance;
|
|
262
|
+
readonly cause?: Error;
|
|
263
|
+
readonly irState?: {
|
|
264
|
+
readonly request?: Partial<IRChatRequest>;
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Router error constructor options.
|
|
269
|
+
*/
|
|
270
|
+
export interface RouterErrorOptions {
|
|
271
|
+
readonly code: typeof ErrorCode.NO_BACKEND_AVAILABLE | typeof ErrorCode.ROUTING_FAILED | typeof ErrorCode.ALL_BACKENDS_FAILED;
|
|
272
|
+
readonly message: string;
|
|
273
|
+
readonly provenance?: ErrorProvenance;
|
|
274
|
+
readonly cause?: Error;
|
|
275
|
+
readonly attemptedBackends?: string[];
|
|
276
|
+
readonly irState?: {
|
|
277
|
+
readonly request?: Partial<IRChatRequest>;
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Middleware error constructor options.
|
|
282
|
+
*/
|
|
283
|
+
export interface MiddlewareErrorOptions {
|
|
284
|
+
readonly message: string;
|
|
285
|
+
readonly middlewareName?: string;
|
|
286
|
+
readonly provenance?: ErrorProvenance;
|
|
287
|
+
readonly cause?: Error;
|
|
288
|
+
readonly irState?: {
|
|
289
|
+
readonly request?: Partial<IRChatRequest>;
|
|
290
|
+
readonly response?: Partial<IRChatResponse>;
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Base error class interface.
|
|
295
|
+
*/
|
|
296
|
+
export interface AdapterError extends Error {
|
|
297
|
+
readonly code: ErrorCode;
|
|
298
|
+
readonly category: ErrorCategory;
|
|
299
|
+
readonly isRetryable: boolean;
|
|
300
|
+
readonly provenance: ErrorProvenance;
|
|
301
|
+
readonly cause?: Error;
|
|
302
|
+
readonly irState?: {
|
|
303
|
+
readonly request?: Partial<IRChatRequest>;
|
|
304
|
+
readonly response?: Partial<IRChatResponse>;
|
|
305
|
+
};
|
|
306
|
+
readonly details?: Record<string, unknown>;
|
|
307
|
+
readonly timestamp: number;
|
|
308
|
+
isCategory(category: ErrorCategory): boolean;
|
|
309
|
+
toJSON(): Record<string, unknown>;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Authentication error interface.
|
|
313
|
+
*/
|
|
314
|
+
export interface AuthenticationError extends AdapterError {
|
|
315
|
+
readonly name: 'AuthenticationError';
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Authorization error interface.
|
|
319
|
+
*/
|
|
320
|
+
export interface AuthorizationError extends AdapterError {
|
|
321
|
+
readonly name: 'AuthorizationError';
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Rate limit error interface.
|
|
325
|
+
*/
|
|
326
|
+
export interface RateLimitError extends AdapterError {
|
|
327
|
+
readonly name: 'RateLimitError';
|
|
328
|
+
readonly retryAfter?: number;
|
|
329
|
+
readonly limit?: number;
|
|
330
|
+
readonly remaining?: number;
|
|
331
|
+
readonly resetAt?: string;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Validation error interface.
|
|
335
|
+
*/
|
|
336
|
+
export interface ValidationError extends AdapterError {
|
|
337
|
+
readonly name: 'ValidationError';
|
|
338
|
+
readonly validationDetails: ValidationErrorDetails[];
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Provider error interface.
|
|
342
|
+
*/
|
|
343
|
+
export interface ProviderError extends AdapterError {
|
|
344
|
+
readonly name: 'ProviderError';
|
|
345
|
+
readonly providerDetails?: ProviderErrorDetails;
|
|
346
|
+
readonly httpContext?: HttpErrorContext;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Adapter conversion error interface.
|
|
350
|
+
*/
|
|
351
|
+
export interface AdapterConversionError extends AdapterError {
|
|
352
|
+
readonly name: 'AdapterConversionError';
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Network error interface.
|
|
356
|
+
*/
|
|
357
|
+
export interface NetworkError extends AdapterError {
|
|
358
|
+
readonly name: 'NetworkError';
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Stream error interface.
|
|
362
|
+
*/
|
|
363
|
+
export interface StreamError extends AdapterError {
|
|
364
|
+
readonly name: 'StreamError';
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Router error interface.
|
|
368
|
+
*/
|
|
369
|
+
export interface RouterError extends AdapterError {
|
|
370
|
+
readonly name: 'RouterError';
|
|
371
|
+
readonly attemptedBackends?: string[];
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Middleware error interface.
|
|
375
|
+
*/
|
|
376
|
+
export interface MiddlewareError extends AdapterError {
|
|
377
|
+
readonly name: 'MiddlewareError';
|
|
378
|
+
readonly middlewareName?: string;
|
|
379
|
+
}
|
|
380
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAM7D;;GAEG;AACH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuDZ,CAAC;AAEX,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,OAAO,SAAS,CAAC,CAAC;AAMnE;;GAEG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;CAYhB,CAAC;AAEX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,OAAO,aAAa,CAAC,CAAC;AAE/E;;GAEG;AACH,eAAO,MAAM,qBAAqB,EAAE,MAAM,CA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