@sparkleideas/providers 3.0.0-alpha.6-patch.26 → 3.0.0-alpha.6-patch.27
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/dist/anthropic-provider.d.ts +26 -0
- package/dist/anthropic-provider.d.ts.map +1 -0
- package/dist/anthropic-provider.js +513 -0
- package/dist/base-provider.d.ts +174 -0
- package/dist/base-provider.d.ts.map +1 -0
- package/dist/base-provider.js +636 -0
- package/dist/cohere-provider.d.ts +26 -0
- package/dist/cohere-provider.d.ts.map +1 -0
- package/dist/cohere-provider.js +501 -0
- package/dist/google-provider.d.ts +25 -0
- package/dist/google-provider.d.ts.map +1 -0
- package/dist/google-provider.js +498 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +62 -0
- package/dist/ollama-provider.d.ts +26 -0
- package/dist/ollama-provider.d.ts.map +1 -0
- package/dist/ollama-provider.js +489 -0
- package/dist/openai-provider.d.ts +26 -0
- package/dist/openai-provider.d.ts.map +1 -0
- package/dist/openai-provider.js +543 -0
- package/dist/provider-manager.d.ts +117 -0
- package/dist/provider-manager.d.ts.map +1 -0
- package/dist/provider-manager.js +712 -0
- package/dist/ruvector-provider.d.ts +65 -0
- package/dist/ruvector-provider.d.ts.map +1 -0
- package/dist/ruvector-provider.js +813 -0
- package/dist/types.d.ts +280 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +108 -0
- package/package.json +1 -1
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V3 LLM Provider Types
|
|
3
|
+
*
|
|
4
|
+
* Unified type system for all LLM providers with enhanced
|
|
5
|
+
* cost tracking, model capabilities, and error handling.
|
|
6
|
+
*
|
|
7
|
+
* @module @sparkleideas/providers/types
|
|
8
|
+
*/
|
|
9
|
+
import { EventEmitter } from 'events';
|
|
10
|
+
export type LLMProvider = 'anthropic' | 'openai' | 'google' | 'cohere' | 'ollama' | 'ruvector' | 'openrouter' | 'litellm' | 'custom';
|
|
11
|
+
export type LLMModel = 'claude-3-5-sonnet-20241022' | 'claude-3-5-sonnet-latest' | 'claude-3-opus-20240229' | 'claude-3-sonnet-20240229' | 'claude-3-haiku-20240307' | 'gpt-4o' | 'gpt-4o-mini' | 'gpt-4-turbo' | 'gpt-4' | 'gpt-3.5-turbo' | 'o1-preview' | 'o1-mini' | 'o3-mini' | 'gemini-2.0-flash' | 'gemini-1.5-pro' | 'gemini-1.5-flash' | 'gemini-pro' | 'command-r-plus' | 'command-r' | 'command-light' | 'command' | 'llama3.2' | 'llama3.1' | 'mistral' | 'mixtral' | 'codellama' | 'phi-4' | 'deepseek-coder' | 'custom-model' | string;
|
|
12
|
+
export interface LLMMessage {
|
|
13
|
+
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
14
|
+
content: string | LLMContentPart[];
|
|
15
|
+
name?: string;
|
|
16
|
+
toolCallId?: string;
|
|
17
|
+
toolCalls?: LLMToolCall[];
|
|
18
|
+
}
|
|
19
|
+
export interface LLMContentPart {
|
|
20
|
+
type: 'text' | 'image' | 'audio';
|
|
21
|
+
text?: string;
|
|
22
|
+
imageUrl?: string;
|
|
23
|
+
imageBase64?: string;
|
|
24
|
+
audioUrl?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface LLMToolCall {
|
|
27
|
+
id: string;
|
|
28
|
+
type: 'function';
|
|
29
|
+
function: {
|
|
30
|
+
name: string;
|
|
31
|
+
arguments: string;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export interface LLMTool {
|
|
35
|
+
type: 'function';
|
|
36
|
+
function: {
|
|
37
|
+
name: string;
|
|
38
|
+
description: string;
|
|
39
|
+
parameters: {
|
|
40
|
+
type: 'object';
|
|
41
|
+
properties: Record<string, unknown>;
|
|
42
|
+
required?: string[];
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export interface LLMProviderConfig {
|
|
47
|
+
provider: LLMProvider;
|
|
48
|
+
apiKey?: string;
|
|
49
|
+
apiUrl?: string;
|
|
50
|
+
model: LLMModel;
|
|
51
|
+
temperature?: number;
|
|
52
|
+
maxTokens?: number;
|
|
53
|
+
topP?: number;
|
|
54
|
+
topK?: number;
|
|
55
|
+
frequencyPenalty?: number;
|
|
56
|
+
presencePenalty?: number;
|
|
57
|
+
stopSequences?: string[];
|
|
58
|
+
providerOptions?: Record<string, unknown>;
|
|
59
|
+
timeout?: number;
|
|
60
|
+
retryAttempts?: number;
|
|
61
|
+
retryDelay?: number;
|
|
62
|
+
enableStreaming?: boolean;
|
|
63
|
+
enableCaching?: boolean;
|
|
64
|
+
cacheTimeout?: number;
|
|
65
|
+
enableCostOptimization?: boolean;
|
|
66
|
+
maxCostPerRequest?: number;
|
|
67
|
+
fallbackModels?: LLMModel[];
|
|
68
|
+
}
|
|
69
|
+
export interface LLMRequest {
|
|
70
|
+
messages: LLMMessage[];
|
|
71
|
+
model?: LLMModel;
|
|
72
|
+
temperature?: number;
|
|
73
|
+
maxTokens?: number;
|
|
74
|
+
topP?: number;
|
|
75
|
+
topK?: number;
|
|
76
|
+
frequencyPenalty?: number;
|
|
77
|
+
presencePenalty?: number;
|
|
78
|
+
stopSequences?: string[];
|
|
79
|
+
stream?: boolean;
|
|
80
|
+
tools?: LLMTool[];
|
|
81
|
+
toolChoice?: 'auto' | 'none' | 'required' | {
|
|
82
|
+
type: 'function';
|
|
83
|
+
function: {
|
|
84
|
+
name: string;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
providerOptions?: Record<string, unknown>;
|
|
88
|
+
costConstraints?: {
|
|
89
|
+
maxCost?: number;
|
|
90
|
+
preferredModels?: LLMModel[];
|
|
91
|
+
};
|
|
92
|
+
requestId?: string;
|
|
93
|
+
metadata?: Record<string, unknown>;
|
|
94
|
+
}
|
|
95
|
+
export interface LLMResponse {
|
|
96
|
+
id: string;
|
|
97
|
+
model: LLMModel;
|
|
98
|
+
provider: LLMProvider;
|
|
99
|
+
content: string;
|
|
100
|
+
toolCalls?: LLMToolCall[];
|
|
101
|
+
usage: {
|
|
102
|
+
promptTokens: number;
|
|
103
|
+
completionTokens: number;
|
|
104
|
+
totalTokens: number;
|
|
105
|
+
};
|
|
106
|
+
cost?: {
|
|
107
|
+
promptCost: number;
|
|
108
|
+
completionCost: number;
|
|
109
|
+
totalCost: number;
|
|
110
|
+
currency: string;
|
|
111
|
+
};
|
|
112
|
+
latency?: number;
|
|
113
|
+
finishReason?: 'stop' | 'length' | 'tool_calls' | 'content_filter';
|
|
114
|
+
metadata?: Record<string, unknown>;
|
|
115
|
+
}
|
|
116
|
+
export interface LLMStreamEvent {
|
|
117
|
+
type: 'content' | 'tool_call' | 'error' | 'done';
|
|
118
|
+
delta?: {
|
|
119
|
+
content?: string;
|
|
120
|
+
toolCall?: Partial<LLMToolCall>;
|
|
121
|
+
};
|
|
122
|
+
error?: Error;
|
|
123
|
+
usage?: LLMResponse['usage'];
|
|
124
|
+
cost?: LLMResponse['cost'];
|
|
125
|
+
}
|
|
126
|
+
export interface ProviderCapabilities {
|
|
127
|
+
supportedModels: LLMModel[];
|
|
128
|
+
maxContextLength: Record<string, number>;
|
|
129
|
+
maxOutputTokens: Record<string, number>;
|
|
130
|
+
supportsStreaming: boolean;
|
|
131
|
+
supportsToolCalling: boolean;
|
|
132
|
+
supportsSystemMessages: boolean;
|
|
133
|
+
supportsVision: boolean;
|
|
134
|
+
supportsAudio: boolean;
|
|
135
|
+
supportsFineTuning: boolean;
|
|
136
|
+
supportsEmbeddings: boolean;
|
|
137
|
+
supportsBatching: boolean;
|
|
138
|
+
rateLimit?: {
|
|
139
|
+
requestsPerMinute: number;
|
|
140
|
+
tokensPerMinute: number;
|
|
141
|
+
concurrentRequests: number;
|
|
142
|
+
};
|
|
143
|
+
pricing: Record<string, {
|
|
144
|
+
promptCostPer1k: number;
|
|
145
|
+
completionCostPer1k: number;
|
|
146
|
+
currency: string;
|
|
147
|
+
}>;
|
|
148
|
+
}
|
|
149
|
+
export declare class LLMProviderError extends Error {
|
|
150
|
+
code: string;
|
|
151
|
+
provider: LLMProvider;
|
|
152
|
+
statusCode?: number;
|
|
153
|
+
retryable: boolean;
|
|
154
|
+
details?: unknown;
|
|
155
|
+
constructor(message: string, code: string, provider: LLMProvider, statusCode?: number, retryable?: boolean, details?: unknown);
|
|
156
|
+
}
|
|
157
|
+
export declare class RateLimitError extends LLMProviderError {
|
|
158
|
+
retryAfter?: number;
|
|
159
|
+
constructor(message: string, provider: LLMProvider, retryAfter?: number, details?: unknown);
|
|
160
|
+
}
|
|
161
|
+
export declare class AuthenticationError extends LLMProviderError {
|
|
162
|
+
constructor(message: string, provider: LLMProvider, details?: unknown);
|
|
163
|
+
}
|
|
164
|
+
export declare class ModelNotFoundError extends LLMProviderError {
|
|
165
|
+
constructor(model: string, provider: LLMProvider, details?: unknown);
|
|
166
|
+
}
|
|
167
|
+
export declare class ProviderUnavailableError extends LLMProviderError {
|
|
168
|
+
constructor(provider: LLMProvider, details?: unknown);
|
|
169
|
+
}
|
|
170
|
+
export interface ILLMProvider extends EventEmitter {
|
|
171
|
+
readonly name: LLMProvider;
|
|
172
|
+
readonly capabilities: ProviderCapabilities;
|
|
173
|
+
config: LLMProviderConfig;
|
|
174
|
+
initialize(): Promise<void>;
|
|
175
|
+
complete(request: LLMRequest): Promise<LLMResponse>;
|
|
176
|
+
streamComplete(request: LLMRequest): AsyncIterable<LLMStreamEvent>;
|
|
177
|
+
listModels(): Promise<LLMModel[]>;
|
|
178
|
+
getModelInfo(model: LLMModel): Promise<ModelInfo>;
|
|
179
|
+
validateModel(model: LLMModel): boolean;
|
|
180
|
+
healthCheck(): Promise<HealthCheckResult>;
|
|
181
|
+
getStatus(): ProviderStatus;
|
|
182
|
+
estimateCost(request: LLMRequest): Promise<CostEstimate>;
|
|
183
|
+
getUsage(period?: UsagePeriod): Promise<UsageStats>;
|
|
184
|
+
destroy(): void;
|
|
185
|
+
}
|
|
186
|
+
export interface ModelInfo {
|
|
187
|
+
model: LLMModel;
|
|
188
|
+
name: string;
|
|
189
|
+
description: string;
|
|
190
|
+
contextLength: number;
|
|
191
|
+
maxOutputTokens: number;
|
|
192
|
+
supportedFeatures: string[];
|
|
193
|
+
pricing?: {
|
|
194
|
+
promptCostPer1k: number;
|
|
195
|
+
completionCostPer1k: number;
|
|
196
|
+
currency: string;
|
|
197
|
+
};
|
|
198
|
+
deprecated?: boolean;
|
|
199
|
+
recommendedReplacement?: LLMModel;
|
|
200
|
+
}
|
|
201
|
+
export interface HealthCheckResult {
|
|
202
|
+
healthy: boolean;
|
|
203
|
+
latency?: number;
|
|
204
|
+
error?: string;
|
|
205
|
+
timestamp: Date;
|
|
206
|
+
details?: Record<string, unknown>;
|
|
207
|
+
}
|
|
208
|
+
export interface ProviderStatus {
|
|
209
|
+
available: boolean;
|
|
210
|
+
currentLoad: number;
|
|
211
|
+
queueLength: number;
|
|
212
|
+
activeRequests: number;
|
|
213
|
+
rateLimitRemaining?: number;
|
|
214
|
+
rateLimitReset?: Date;
|
|
215
|
+
}
|
|
216
|
+
export interface CostEstimate {
|
|
217
|
+
estimatedPromptTokens: number;
|
|
218
|
+
estimatedCompletionTokens: number;
|
|
219
|
+
estimatedTotalTokens: number;
|
|
220
|
+
estimatedCost: {
|
|
221
|
+
prompt: number;
|
|
222
|
+
completion: number;
|
|
223
|
+
total: number;
|
|
224
|
+
currency: string;
|
|
225
|
+
};
|
|
226
|
+
confidence: number;
|
|
227
|
+
}
|
|
228
|
+
export interface UsageStats {
|
|
229
|
+
period: {
|
|
230
|
+
start: Date;
|
|
231
|
+
end: Date;
|
|
232
|
+
};
|
|
233
|
+
requests: number;
|
|
234
|
+
tokens: {
|
|
235
|
+
prompt: number;
|
|
236
|
+
completion: number;
|
|
237
|
+
total: number;
|
|
238
|
+
};
|
|
239
|
+
cost: {
|
|
240
|
+
prompt: number;
|
|
241
|
+
completion: number;
|
|
242
|
+
total: number;
|
|
243
|
+
currency: string;
|
|
244
|
+
};
|
|
245
|
+
errors: number;
|
|
246
|
+
averageLatency: number;
|
|
247
|
+
modelBreakdown: Record<string, {
|
|
248
|
+
requests: number;
|
|
249
|
+
tokens: number;
|
|
250
|
+
cost: number;
|
|
251
|
+
}>;
|
|
252
|
+
}
|
|
253
|
+
export type UsagePeriod = 'hour' | 'day' | 'week' | 'month' | 'all';
|
|
254
|
+
export type LoadBalancingStrategy = 'round-robin' | 'least-loaded' | 'latency-based' | 'cost-based';
|
|
255
|
+
export interface ProviderManagerConfig {
|
|
256
|
+
providers: LLMProviderConfig[];
|
|
257
|
+
defaultProvider?: LLMProvider;
|
|
258
|
+
loadBalancing?: {
|
|
259
|
+
enabled: boolean;
|
|
260
|
+
strategy: LoadBalancingStrategy;
|
|
261
|
+
};
|
|
262
|
+
fallback?: {
|
|
263
|
+
enabled: boolean;
|
|
264
|
+
maxAttempts: number;
|
|
265
|
+
};
|
|
266
|
+
cache?: {
|
|
267
|
+
enabled: boolean;
|
|
268
|
+
ttl: number;
|
|
269
|
+
maxSize: number;
|
|
270
|
+
};
|
|
271
|
+
costOptimization?: {
|
|
272
|
+
enabled: boolean;
|
|
273
|
+
maxCostPerRequest?: number;
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
export declare function isLLMResponse(obj: unknown): obj is LLMResponse;
|
|
277
|
+
export declare function isLLMStreamEvent(obj: unknown): obj is LLMStreamEvent;
|
|
278
|
+
export declare function isLLMProviderError(error: unknown): error is LLMProviderError;
|
|
279
|
+
export declare function isRateLimitError(error: unknown): error is RateLimitError;
|
|
280
|
+
//# 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,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAItC,MAAM,MAAM,WAAW,GACnB,WAAW,GACX,QAAQ,GACR,QAAQ,GACR,QAA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,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,iBAAiB,EAAE,CAAC;IAC/B,eAAe,CAAC,EAAE,WAAW,CAAC;IAC9B,aAAa,CAAC,EAAE;QACd,OAAO,EAAE,OAAO,CAAC;QACjB,QAAQ,EAAE,qBAAqB,CAAC;KACjC,CAAC;IACF,QAAQ,CAAC,EAAE;QACT,OAAO,EAAE,OAAO,CAAC;QACjB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;IACF,KAAK,CAAC,EAAE;QACN,OAAO,EAAE,OAAO,CAAC;QACjB,GAAG,EAAE,MAAM,CAAC;QACZ,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,gBAAgB,CAAC,EAAE;QACjB,OAAO,EAAE,OAAO,CAAC;QACjB,iBAAiB,CAAC,EAAE,MAAM,CAAC;KAC5B,CAAC;CACH;AAID,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,WAAW,CAQ9D;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,cAAc,CAOpE;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,gBAAgB,CAE5E;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAExE"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* V3 LLM Provider Types
|
|
4
|
+
*
|
|
5
|
+
* Unified type system for all LLM providers with enhanced
|
|
6
|
+
* cost tracking, model capabilities, and error handling.
|
|
7
|
+
*
|
|
8
|
+
* @module @sparkleideas/providers/types
|
|
9
|
+
*/
|
|
10
|
+
var __extends = (this && this.__extends) || (function () {
|
|
11
|
+
var extendStatics = function (d, b) {
|
|
12
|
+
extendStatics = Object.setPrototypeOf ||
|
|
13
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
14
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
15
|
+
return extendStatics(d, b);
|
|
16
|
+
};
|
|
17
|
+
return function (d, b) {
|
|
18
|
+
if (typeof b !== "function" && b !== null)
|
|
19
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
20
|
+
extendStatics(d, b);
|
|
21
|
+
function __() { this.constructor = d; }
|
|
22
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
23
|
+
};
|
|
24
|
+
})();
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.ProviderUnavailableError = exports.ModelNotFoundError = exports.AuthenticationError = exports.RateLimitError = exports.LLMProviderError = void 0;
|
|
27
|
+
exports.isLLMResponse = isLLMResponse;
|
|
28
|
+
exports.isLLMStreamEvent = isLLMStreamEvent;
|
|
29
|
+
exports.isLLMProviderError = isLLMProviderError;
|
|
30
|
+
exports.isRateLimitError = isRateLimitError;
|
|
31
|
+
// ===== ERROR TYPES =====
|
|
32
|
+
var LLMProviderError = /** @class */ (function (_super) {
|
|
33
|
+
__extends(LLMProviderError, _super);
|
|
34
|
+
function LLMProviderError(message, code, provider, statusCode, retryable, details) {
|
|
35
|
+
if (retryable === void 0) { retryable = true; }
|
|
36
|
+
var _this = _super.call(this, message) || this;
|
|
37
|
+
_this.code = code;
|
|
38
|
+
_this.provider = provider;
|
|
39
|
+
_this.statusCode = statusCode;
|
|
40
|
+
_this.retryable = retryable;
|
|
41
|
+
_this.details = details;
|
|
42
|
+
_this.name = 'LLMProviderError';
|
|
43
|
+
return _this;
|
|
44
|
+
}
|
|
45
|
+
return LLMProviderError;
|
|
46
|
+
}(Error));
|
|
47
|
+
exports.LLMProviderError = LLMProviderError;
|
|
48
|
+
var RateLimitError = /** @class */ (function (_super) {
|
|
49
|
+
__extends(RateLimitError, _super);
|
|
50
|
+
function RateLimitError(message, provider, retryAfter, details) {
|
|
51
|
+
var _this = _super.call(this, message, 'RATE_LIMIT', provider, 429, true, details) || this;
|
|
52
|
+
_this.retryAfter = retryAfter;
|
|
53
|
+
_this.name = 'RateLimitError';
|
|
54
|
+
return _this;
|
|
55
|
+
}
|
|
56
|
+
return RateLimitError;
|
|
57
|
+
}(LLMProviderError));
|
|
58
|
+
exports.RateLimitError = RateLimitError;
|
|
59
|
+
var AuthenticationError = /** @class */ (function (_super) {
|
|
60
|
+
__extends(AuthenticationError, _super);
|
|
61
|
+
function AuthenticationError(message, provider, details) {
|
|
62
|
+
var _this = _super.call(this, message, 'AUTHENTICATION', provider, 401, false, details) || this;
|
|
63
|
+
_this.name = 'AuthenticationError';
|
|
64
|
+
return _this;
|
|
65
|
+
}
|
|
66
|
+
return AuthenticationError;
|
|
67
|
+
}(LLMProviderError));
|
|
68
|
+
exports.AuthenticationError = AuthenticationError;
|
|
69
|
+
var ModelNotFoundError = /** @class */ (function (_super) {
|
|
70
|
+
__extends(ModelNotFoundError, _super);
|
|
71
|
+
function ModelNotFoundError(model, provider, details) {
|
|
72
|
+
var _this = _super.call(this, "Model ".concat(model, " not found"), 'MODEL_NOT_FOUND', provider, 404, false, details) || this;
|
|
73
|
+
_this.name = 'ModelNotFoundError';
|
|
74
|
+
return _this;
|
|
75
|
+
}
|
|
76
|
+
return ModelNotFoundError;
|
|
77
|
+
}(LLMProviderError));
|
|
78
|
+
exports.ModelNotFoundError = ModelNotFoundError;
|
|
79
|
+
var ProviderUnavailableError = /** @class */ (function (_super) {
|
|
80
|
+
__extends(ProviderUnavailableError, _super);
|
|
81
|
+
function ProviderUnavailableError(provider, details) {
|
|
82
|
+
var _this = _super.call(this, "Provider ".concat(provider, " is unavailable"), 'PROVIDER_UNAVAILABLE', provider, 503, true, details) || this;
|
|
83
|
+
_this.name = 'ProviderUnavailableError';
|
|
84
|
+
return _this;
|
|
85
|
+
}
|
|
86
|
+
return ProviderUnavailableError;
|
|
87
|
+
}(LLMProviderError));
|
|
88
|
+
exports.ProviderUnavailableError = ProviderUnavailableError;
|
|
89
|
+
// ===== TYPE GUARDS =====
|
|
90
|
+
function isLLMResponse(obj) {
|
|
91
|
+
return (typeof obj === 'object' &&
|
|
92
|
+
obj !== null &&
|
|
93
|
+
'id' in obj &&
|
|
94
|
+
'content' in obj &&
|
|
95
|
+
'provider' in obj);
|
|
96
|
+
}
|
|
97
|
+
function isLLMStreamEvent(obj) {
|
|
98
|
+
return (typeof obj === 'object' &&
|
|
99
|
+
obj !== null &&
|
|
100
|
+
'type' in obj &&
|
|
101
|
+
['content', 'tool_call', 'error', 'done'].includes(obj.type));
|
|
102
|
+
}
|
|
103
|
+
function isLLMProviderError(error) {
|
|
104
|
+
return error instanceof LLMProviderError;
|
|
105
|
+
}
|
|
106
|
+
function isRateLimitError(error) {
|
|
107
|
+
return error instanceof RateLimitError;
|
|
108
|
+
}
|