@node-llm/core 1.8.0 → 1.9.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/dist/aliases.d.ts +3 -0
- package/dist/aliases.d.ts.map +1 -1
- package/dist/aliases.js +3 -0
- package/dist/chat/Chat.d.ts +7 -3
- package/dist/chat/Chat.d.ts.map +1 -1
- package/dist/chat/Chat.js +15 -3
- package/dist/chat/ChatResponse.d.ts +24 -3
- package/dist/chat/ChatResponse.d.ts.map +1 -1
- package/dist/chat/ChatResponse.js +72 -5
- package/dist/chat/ChatStream.d.ts.map +1 -1
- package/dist/chat/ChatStream.js +13 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +9 -7
- package/dist/constants.d.ts +6 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +6 -0
- package/dist/errors/index.d.ts +20 -2
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +31 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/models/ModelRegistry.d.ts.map +1 -1
- package/dist/models/ModelRegistry.js +4 -2
- package/dist/models/PricingRegistry.js +3 -3
- package/dist/models/{models.js → models.json} +8331 -7603
- package/dist/providers/anthropic/AnthropicProvider.d.ts.map +1 -1
- package/dist/providers/anthropic/AnthropicProvider.js +2 -1
- package/dist/providers/anthropic/Chat.d.ts.map +1 -1
- package/dist/providers/anthropic/Chat.js +2 -1
- package/dist/providers/anthropic/Errors.d.ts.map +1 -1
- package/dist/providers/anthropic/Errors.js +15 -1
- package/dist/providers/anthropic/Streaming.d.ts.map +1 -1
- package/dist/providers/anthropic/Streaming.js +19 -3
- package/dist/providers/bedrock/Chat.d.ts.map +1 -1
- package/dist/providers/bedrock/Chat.js +2 -20
- package/dist/providers/bedrock/Errors.d.ts +2 -0
- package/dist/providers/bedrock/Errors.d.ts.map +1 -0
- package/dist/providers/bedrock/Errors.js +51 -0
- package/dist/providers/bedrock/Streaming.d.ts.map +1 -1
- package/dist/providers/bedrock/Streaming.js +2 -3
- package/dist/providers/deepseek/Chat.d.ts.map +1 -1
- package/dist/providers/deepseek/Chat.js +2 -2
- package/dist/providers/deepseek/DeepSeekProvider.d.ts.map +1 -1
- package/dist/providers/deepseek/DeepSeekProvider.js +2 -1
- package/dist/providers/deepseek/Errors.d.ts +2 -0
- package/dist/providers/deepseek/Errors.d.ts.map +1 -0
- package/dist/providers/deepseek/Errors.js +45 -0
- package/dist/providers/deepseek/Streaming.d.ts.map +1 -1
- package/dist/providers/deepseek/Streaming.js +13 -2
- package/dist/providers/gemini/Errors.d.ts.map +1 -1
- package/dist/providers/gemini/Errors.js +13 -1
- package/dist/providers/gemini/GeminiProvider.d.ts.map +1 -1
- package/dist/providers/gemini/GeminiProvider.js +2 -1
- package/dist/providers/ollama/OllamaProvider.d.ts.map +1 -1
- package/dist/providers/ollama/OllamaProvider.js +2 -2
- package/dist/providers/openai/Errors.d.ts.map +1 -1
- package/dist/providers/openai/Errors.js +31 -5
- package/dist/providers/openai/OpenAIProvider.d.ts.map +1 -1
- package/dist/providers/openai/OpenAIProvider.js +2 -1
- package/dist/providers/openai/Streaming.d.ts.map +1 -1
- package/dist/providers/openai/Streaming.js +10 -0
- package/dist/providers/openrouter/OpenRouterProvider.d.ts.map +1 -1
- package/dist/providers/openrouter/OpenRouterProvider.js +2 -1
- package/dist/providers/registry.d.ts +3 -0
- package/dist/providers/registry.d.ts.map +1 -1
- package/dist/providers/registry.js +10 -2
- package/dist/utils/json.d.ts +6 -0
- package/dist/utils/json.d.ts.map +1 -0
- package/dist/utils/json.js +43 -0
- package/package.json +1 -1
- package/dist/models/models.d.ts +0 -572
- package/dist/models/models.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnthropicProvider.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/AnthropicProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,Y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AAC,SAAS,EAAE,CAAC;CAKzC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BaseProvider } from "../BaseProvider.js";
|
|
2
|
+
import { DEFAULT_ANTHROPIC_BASE_URL } from "../../constants.js";
|
|
2
3
|
import { Capabilities } from "./Capabilities.js";
|
|
3
4
|
import { AnthropicChat } from "./Chat.js";
|
|
4
5
|
import { AnthropicStreaming } from "./Streaming.js";
|
|
@@ -24,7 +25,7 @@ export class AnthropicProvider extends BaseProvider {
|
|
|
24
25
|
constructor(options) {
|
|
25
26
|
super();
|
|
26
27
|
this.options = options;
|
|
27
|
-
this.baseUrl = options.baseUrl ??
|
|
28
|
+
this.baseUrl = options.baseUrl ?? DEFAULT_ANTHROPIC_BASE_URL;
|
|
28
29
|
this.chatHandler = new AnthropicChat(this.baseUrl, options.apiKey);
|
|
29
30
|
this.streamHandler = new AnthropicStreaming(this.baseUrl, options.apiKey);
|
|
30
31
|
this.modelsHandler = new AnthropicModels(this.baseUrl, options.apiKey);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/Chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAkB,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/Chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAkB,MAAM,gBAAgB,CAAC;AAW3E,qBAAa,aAAa;IAEtB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM;IAG3B,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;CA0J3D"}
|
|
@@ -4,6 +4,7 @@ import { ModelRegistry } from "../../models/ModelRegistry.js";
|
|
|
4
4
|
import { logger } from "../../utils/logger.js";
|
|
5
5
|
import { fetchWithTimeout } from "../../utils/fetch.js";
|
|
6
6
|
import { formatSystemPrompt, formatMessages } from "./Utils.js";
|
|
7
|
+
import { DEFAULT_MAX_TOKENS } from "../../constants.js";
|
|
7
8
|
export class AnthropicChat {
|
|
8
9
|
baseUrl;
|
|
9
10
|
apiKey;
|
|
@@ -13,7 +14,7 @@ export class AnthropicChat {
|
|
|
13
14
|
}
|
|
14
15
|
async execute(request) {
|
|
15
16
|
const model = request.model;
|
|
16
|
-
const maxTokens = request.max_tokens || Capabilities.getMaxOutputTokens(model) ||
|
|
17
|
+
const maxTokens = request.max_tokens || Capabilities.getMaxOutputTokens(model) || DEFAULT_MAX_TOKENS;
|
|
17
18
|
const systemPrompt = formatSystemPrompt(request.messages);
|
|
18
19
|
const messages = formatMessages(request.messages);
|
|
19
20
|
let system = systemPrompt;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Errors.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/Errors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Errors.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/Errors.ts"],"names":[],"mappings":"AAaA,wBAAsB,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAwD9F"}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { BadRequestError, AuthenticationError, RateLimitError, ServerError, ServiceUnavailableError, APIError } from "../../errors/index.js";
|
|
1
|
+
import { BadRequestError, ContextWindowExceededError, InsufficientQuotaError, InvalidModelError, NotFoundError, AuthenticationError, RateLimitError, ServerError, ServiceUnavailableError, APIError } from "../../errors/index.js";
|
|
2
2
|
export async function handleAnthropicError(response, modelId) {
|
|
3
3
|
const status = response.status;
|
|
4
4
|
let body;
|
|
5
5
|
let message = `Anthropic error (${status})`;
|
|
6
|
+
let errorType;
|
|
6
7
|
try {
|
|
7
8
|
body = await response.json();
|
|
8
9
|
if (body && typeof body === "object" && "error" in body) {
|
|
9
10
|
const err = body.error;
|
|
10
11
|
if (err && err.message) {
|
|
11
12
|
message = err.message;
|
|
13
|
+
errorType = err.type;
|
|
12
14
|
}
|
|
13
15
|
}
|
|
14
16
|
}
|
|
@@ -18,12 +20,24 @@ export async function handleAnthropicError(response, modelId) {
|
|
|
18
20
|
}
|
|
19
21
|
const provider = "anthropic";
|
|
20
22
|
if (status === 400) {
|
|
23
|
+
if (message.includes("prompt is too long") || message.includes("context_length")) {
|
|
24
|
+
throw new ContextWindowExceededError(message, body, provider, modelId);
|
|
25
|
+
}
|
|
21
26
|
throw new BadRequestError(message, body, provider, modelId);
|
|
22
27
|
}
|
|
23
28
|
if (status === 401 || status === 403) {
|
|
24
29
|
throw new AuthenticationError(message, status, body, provider);
|
|
25
30
|
}
|
|
31
|
+
if (status === 404) {
|
|
32
|
+
if (message.includes("model") || errorType === "not_found_error") {
|
|
33
|
+
throw new InvalidModelError(message, body, provider, modelId);
|
|
34
|
+
}
|
|
35
|
+
throw new NotFoundError(message, status, body, provider, modelId);
|
|
36
|
+
}
|
|
26
37
|
if (status === 429) {
|
|
38
|
+
if (message.includes("quota") || message.includes("credit")) {
|
|
39
|
+
throw new InsufficientQuotaError(message, body, provider, modelId);
|
|
40
|
+
}
|
|
27
41
|
throw new RateLimitError(message, body, provider, modelId);
|
|
28
42
|
}
|
|
29
43
|
if (status === 502 || status === 503 || status === 529) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/Streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/Streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AASxD,qBAAa,kBAAkB;IAE3B,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM;IAG1B,OAAO,CAAC,OAAO,EAAE,WAAW,EAAE,UAAU,CAAC,EAAE,eAAe,GAAG,cAAc,CAAC,SAAS,CAAC;CA0O9F"}
|
|
@@ -3,6 +3,7 @@ import { handleAnthropicError } from "./Errors.js";
|
|
|
3
3
|
import { formatSystemPrompt, formatMessages } from "./Utils.js";
|
|
4
4
|
import { logger } from "../../utils/logger.js";
|
|
5
5
|
import { fetchWithTimeout } from "../../utils/fetch.js";
|
|
6
|
+
import { DEFAULT_MAX_TOKENS } from "../../constants.js";
|
|
6
7
|
export class AnthropicStreaming {
|
|
7
8
|
baseUrl;
|
|
8
9
|
apiKey;
|
|
@@ -13,7 +14,7 @@ export class AnthropicStreaming {
|
|
|
13
14
|
async *execute(request, controller) {
|
|
14
15
|
const abortController = controller || new AbortController();
|
|
15
16
|
const model = request.model;
|
|
16
|
-
const maxTokens = request.max_tokens || Capabilities.getMaxOutputTokens(model) ||
|
|
17
|
+
const maxTokens = request.max_tokens || Capabilities.getMaxOutputTokens(model) || DEFAULT_MAX_TOKENS;
|
|
17
18
|
const systemPrompt = formatSystemPrompt(request.messages);
|
|
18
19
|
const messages = formatMessages(request.messages);
|
|
19
20
|
let system = systemPrompt;
|
|
@@ -156,10 +157,25 @@ export class AnthropicStreaming {
|
|
|
156
157
|
// Block finished
|
|
157
158
|
}
|
|
158
159
|
else if (eventType === "message_start") {
|
|
159
|
-
|
|
160
|
+
if (data.message?.usage) {
|
|
161
|
+
const usage = {
|
|
162
|
+
input_tokens: data.message.usage.input_tokens,
|
|
163
|
+
output_tokens: data.message.usage.output_tokens,
|
|
164
|
+
total_tokens: data.message.usage.input_tokens + data.message.usage.output_tokens
|
|
165
|
+
};
|
|
166
|
+
yield { content: "", usage };
|
|
167
|
+
}
|
|
160
168
|
}
|
|
161
169
|
else if (eventType === "message_delta") {
|
|
162
|
-
// Update usage
|
|
170
|
+
// Update usage
|
|
171
|
+
if (data.usage) {
|
|
172
|
+
const usage = {
|
|
173
|
+
input_tokens: 0, // Delta usually only contains output
|
|
174
|
+
output_tokens: data.usage.output_tokens,
|
|
175
|
+
total_tokens: data.usage.output_tokens
|
|
176
|
+
};
|
|
177
|
+
yield { content: "", usage };
|
|
178
|
+
}
|
|
163
179
|
if (data.delta?.stop_reason === "end_turn" && toolCallsMap.size > 0) {
|
|
164
180
|
// Yield accumulated tool calls
|
|
165
181
|
const toolCalls = Array.from(toolCallsMap.values()).map((tc) => ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/providers/bedrock/Chat.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAS,MAAM,gBAAgB,CAAC;AAElE,OAAO,EAAE,aAAa,EAA6C,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/providers/bedrock/Chat.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAS,MAAM,gBAAgB,CAAC;AAElE,OAAO,EAAE,aAAa,EAA6C,MAAM,aAAa,CAAC;AAavF,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IACvC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqB;IAC9C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,MAAM,EAAE,aAAa;IAMjC;;OAEG;IACG,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IAwD1D;;OAEG;IACH,OAAO,CAAC,YAAY;IA6CpB;;OAEG;IACH,OAAO,CAAC,aAAa;CAiDtB"}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { validateBedrockConfig, getBedrockEndpoint } from "./config.js";
|
|
7
7
|
import { buildConverseRequest } from "./mapper.js";
|
|
8
8
|
import { signRequest } from "../../utils/AwsSigV4.js";
|
|
9
|
+
import { handleBedrockError } from "./Errors.js";
|
|
9
10
|
import { ModelRegistry } from "../../models/ModelRegistry.js";
|
|
10
11
|
import { fetchWithTimeout } from "../../utils/fetch.js";
|
|
11
12
|
import { logger } from "../../utils/logger.js";
|
|
@@ -52,26 +53,7 @@ export class BedrockChat {
|
|
|
52
53
|
body: bodyJson
|
|
53
54
|
}, request.requestTimeout ?? this.config.requestTimeout);
|
|
54
55
|
if (!response.ok) {
|
|
55
|
-
|
|
56
|
-
logger.logResponse("Bedrock", response.status, response.statusText, errorText);
|
|
57
|
-
let message = errorText;
|
|
58
|
-
// Improve clarity for known AWS errors
|
|
59
|
-
if (errorText.includes("INVALID_PAYMENT_INSTRUMENT")) {
|
|
60
|
-
message =
|
|
61
|
-
"Billing setup incomplete for AWS Marketplace models. Ensure a credit card is set as default payment method.";
|
|
62
|
-
}
|
|
63
|
-
else if (errorText.includes("AccessDeniedException") &&
|
|
64
|
-
errorText.includes("model access")) {
|
|
65
|
-
message =
|
|
66
|
-
"Access denied for this model. Ensure you have requested and been granted access in the AWS Bedrock console (Model Access section).";
|
|
67
|
-
}
|
|
68
|
-
else if (errorText.includes("ThrottlingException")) {
|
|
69
|
-
message = "Bedrock API throttling. Too many requests. Please retry with backoff.";
|
|
70
|
-
}
|
|
71
|
-
else if (errorText.includes("ValidationException")) {
|
|
72
|
-
message = `Bedrock validation error: ${errorText}`;
|
|
73
|
-
}
|
|
74
|
-
throw new Error(`Bedrock API error (${response.status}): ${message}`);
|
|
56
|
+
await handleBedrockError(response, modelId);
|
|
75
57
|
}
|
|
76
58
|
const json = (await response.json());
|
|
77
59
|
logger.logResponse("Bedrock", response.status, response.statusText, json);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Errors.d.ts","sourceRoot":"","sources":["../../../src/providers/bedrock/Errors.ts"],"names":[],"mappings":"AAcA,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAmE5F"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { BadRequestError, ContextWindowExceededError, InsufficientQuotaError, InvalidModelError, AuthenticationError, RateLimitError, ServerError, ServiceUnavailableError, APIError, ForbiddenError } from "../../errors/index.js";
|
|
2
|
+
export async function handleBedrockError(response, modelId) {
|
|
3
|
+
const status = response.status;
|
|
4
|
+
const errorText = await response.text();
|
|
5
|
+
let message = errorText;
|
|
6
|
+
let body;
|
|
7
|
+
try {
|
|
8
|
+
body = JSON.parse(errorText);
|
|
9
|
+
message = body.message || errorText;
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
body = errorText;
|
|
13
|
+
}
|
|
14
|
+
const provider = "bedrock";
|
|
15
|
+
// Throttling
|
|
16
|
+
if (status === 429 || message.includes("ThrottlingException")) {
|
|
17
|
+
throw new RateLimitError(message, body, provider, modelId);
|
|
18
|
+
}
|
|
19
|
+
// Auth / Access
|
|
20
|
+
if (status === 401) {
|
|
21
|
+
throw new AuthenticationError(message, status, body, provider);
|
|
22
|
+
}
|
|
23
|
+
if (status === 403 || message.includes("AccessDeniedException")) {
|
|
24
|
+
if (message.includes("model access")) {
|
|
25
|
+
throw new ForbiddenError(`Access denied for model ${modelId}. Ensure you have requested access in the AWS Bedrock console.`, body, provider);
|
|
26
|
+
}
|
|
27
|
+
throw new ForbiddenError(message, body, provider);
|
|
28
|
+
}
|
|
29
|
+
// Not Found
|
|
30
|
+
if (status === 404 || message.includes("ResourceNotFoundException")) {
|
|
31
|
+
throw new InvalidModelError(message, body, provider, modelId);
|
|
32
|
+
}
|
|
33
|
+
// Bad Request
|
|
34
|
+
if (status === 400 || message.includes("ValidationException")) {
|
|
35
|
+
if (message.includes("context length") || message.includes("too many tokens")) {
|
|
36
|
+
throw new ContextWindowExceededError(message, body, provider, modelId);
|
|
37
|
+
}
|
|
38
|
+
throw new BadRequestError(message, body, provider, modelId);
|
|
39
|
+
}
|
|
40
|
+
// Payment
|
|
41
|
+
if (message.includes("INVALID_PAYMENT_INSTRUMENT")) {
|
|
42
|
+
throw new InsufficientQuotaError("Billing setup incomplete for AWS Marketplace models. Ensure a credit card is set as default payment method.", body, provider, modelId);
|
|
43
|
+
}
|
|
44
|
+
if (status >= 500) {
|
|
45
|
+
if (status === 502 || status === 503) {
|
|
46
|
+
throw new ServiceUnavailableError(message, status, body, provider, modelId);
|
|
47
|
+
}
|
|
48
|
+
throw new ServerError(message, status, body, provider, modelId);
|
|
49
|
+
}
|
|
50
|
+
throw new APIError(message, status, body, provider, modelId);
|
|
51
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/bedrock/Streaming.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,SAAS,EAAS,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,aAAa,EAA6C,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/bedrock/Streaming.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,SAAS,EAAS,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,aAAa,EAA6C,MAAM,aAAa,CAAC;AAQvF,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IACvC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqB;IAC9C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,MAAM,EAAE,aAAa;IAM1B,OAAO,CAAC,OAAO,EAAE,WAAW,EAAE,UAAU,CAAC,EAAE,eAAe,GAAG,cAAc,CAAC,SAAS,CAAC;IA4H7F;;OAEG;IACH,OAAO,CAAC,UAAU;IAyGlB,OAAO,CAAC,YAAY;CAsCrB"}
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { validateBedrockConfig, getBedrockEndpoint } from "./config.js";
|
|
8
8
|
import { signRequest } from "../../utils/AwsSigV4.js";
|
|
9
9
|
import { fetchWithTimeout } from "../../utils/fetch.js";
|
|
10
|
+
import { handleBedrockError } from "./Errors.js";
|
|
10
11
|
import { logger } from "../../utils/logger.js";
|
|
11
12
|
import { buildConverseRequest } from "./mapper.js";
|
|
12
13
|
import { ModelRegistry } from "../../models/ModelRegistry.js";
|
|
@@ -50,9 +51,7 @@ export class BedrockStreaming {
|
|
|
50
51
|
signal
|
|
51
52
|
}, request.requestTimeout ?? this.config.requestTimeout);
|
|
52
53
|
if (!response.ok) {
|
|
53
|
-
|
|
54
|
-
logger.logResponse("Bedrock", response.status, response.statusText, errorText);
|
|
55
|
-
throw new Error(`Bedrock Streaming Error (${response.status}): ${errorText}`);
|
|
54
|
+
await handleBedrockError(response, modelId);
|
|
56
55
|
}
|
|
57
56
|
if (!response.body) {
|
|
58
57
|
throw new Error("No response body from Bedrock streaming");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/providers/deepseek/Chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAS,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/providers/deepseek/Chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAS,MAAM,gBAAgB,CAAC;AAiClE,qBAAa,YAAY;IAErB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM;IAG3B,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;CAmH3D"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ModelRegistry } from "../../models/ModelRegistry.js";
|
|
2
2
|
import { logger } from "../../utils/logger.js";
|
|
3
|
+
import { handleDeepSeekError } from "./Errors.js";
|
|
3
4
|
import { mapSystemMessages } from "../utils.js";
|
|
4
5
|
import { fetchWithTimeout } from "../../utils/fetch.js";
|
|
5
6
|
export class DeepSeekChat {
|
|
@@ -63,8 +64,7 @@ export class DeepSeekChat {
|
|
|
63
64
|
body: JSON.stringify(body)
|
|
64
65
|
}, requestTimeout);
|
|
65
66
|
if (!response.ok) {
|
|
66
|
-
|
|
67
|
-
throw new Error(`DeepSeek API error: ${response.status} - ${errorText}`);
|
|
67
|
+
await handleDeepSeekError(response, model);
|
|
68
68
|
}
|
|
69
69
|
const json = (await response.json());
|
|
70
70
|
logger.logResponse("DeepSeek", response.status, response.statusText, json);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeepSeekProvider.d.ts","sourceRoot":"","sources":["../../../src/providers/deepseek/DeepSeekProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3F,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"DeepSeekProvider.d.ts","sourceRoot":"","sources":["../../../src/providers/deepseek/DeepSeekProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3F,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAOlD,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,gBAAiB,SAAQ,YAAa,YAAW,QAAQ;IAmBxD,OAAO,CAAC,QAAQ,CAAC,OAAO;IAlBpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAe;IAC3C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAoB;IACrD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAiB;IAExC,YAAY;gCACO,MAAM;+BACP,MAAM;0CACK,MAAM;oCACZ,MAAM;yCACD,MAAM;uCACR,MAAM;oCACT,MAAM;mCACP,MAAM;wCACD,MAAM;kCACZ,MAAM;MAChC;gBAE2B,OAAO,EAAE,uBAAuB;IAQtD,OAAO,IAAI,MAAM;IAIjB,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAOxC,SAAS,CAAC,YAAY,IAAI,MAAM;IAIhB,YAAY,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM;IAIjD,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IAIhD,MAAM,CAAC,OAAO,EAAE,WAAW,GAAG,cAAc,CAAC,SAAS,CAAC;IAIxD,UAAU,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;CAKzC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BaseProvider } from "../BaseProvider.js";
|
|
2
|
+
import { DEFAULT_DEEPSEEK_BASE_URL } from "../../constants.js";
|
|
2
3
|
import { DeepSeekChat } from "./Chat.js";
|
|
3
4
|
import { DeepSeekModels } from "./Models.js";
|
|
4
5
|
import { DeepSeekStreaming } from "./Streaming.js";
|
|
@@ -24,7 +25,7 @@ export class DeepSeekProvider extends BaseProvider {
|
|
|
24
25
|
constructor(options) {
|
|
25
26
|
super();
|
|
26
27
|
this.options = options;
|
|
27
|
-
this.baseUrl = options.baseUrl ??
|
|
28
|
+
this.baseUrl = options.baseUrl ?? DEFAULT_DEEPSEEK_BASE_URL;
|
|
28
29
|
this.chatHandler = new DeepSeekChat(this.baseUrl, options.apiKey);
|
|
29
30
|
this.streamingHandler = new DeepSeekStreaming(this.baseUrl, options.apiKey);
|
|
30
31
|
this.modelsHandler = new DeepSeekModels(this.baseUrl, options.apiKey);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Errors.d.ts","sourceRoot":"","sources":["../../../src/providers/deepseek/Errors.ts"],"names":[],"mappings":"AAaA,wBAAsB,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAkD5F"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { BadRequestError, ContextWindowExceededError, InsufficientQuotaError, InvalidModelError, NotFoundError, AuthenticationError, RateLimitError, ServerError, APIError } from "../../errors/index.js";
|
|
2
|
+
export async function handleDeepSeekError(response, model) {
|
|
3
|
+
const status = response.status;
|
|
4
|
+
let body;
|
|
5
|
+
let message = `DeepSeek error (${status})`;
|
|
6
|
+
try {
|
|
7
|
+
body = await response.json();
|
|
8
|
+
if (body && typeof body === "object" && "error" in body) {
|
|
9
|
+
const err = body.error;
|
|
10
|
+
if (err && err.message) {
|
|
11
|
+
message = err.message;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
body = await response.text().catch(() => "Unknown error");
|
|
17
|
+
message = `DeepSeek error (${status}): ${body}`;
|
|
18
|
+
}
|
|
19
|
+
const provider = "deepseek";
|
|
20
|
+
if (status === 400) {
|
|
21
|
+
if (message.includes("context") || message.includes("length") || message.includes("tokens")) {
|
|
22
|
+
throw new ContextWindowExceededError(message, body, provider, model);
|
|
23
|
+
}
|
|
24
|
+
throw new BadRequestError(message, body, provider, model);
|
|
25
|
+
}
|
|
26
|
+
if (status === 401 || status === 403) {
|
|
27
|
+
throw new AuthenticationError(message, status, body, provider);
|
|
28
|
+
}
|
|
29
|
+
if (status === 404) {
|
|
30
|
+
if (message.includes("model")) {
|
|
31
|
+
throw new InvalidModelError(message, body, provider, model);
|
|
32
|
+
}
|
|
33
|
+
throw new NotFoundError(message, status, body, provider, model);
|
|
34
|
+
}
|
|
35
|
+
if (status === 402 || status === 429) {
|
|
36
|
+
if (message.includes("quota") || message.includes("balance") || message.includes("credit")) {
|
|
37
|
+
throw new InsufficientQuotaError(message, body, provider, model);
|
|
38
|
+
}
|
|
39
|
+
throw new RateLimitError(message, body, provider, model);
|
|
40
|
+
}
|
|
41
|
+
if (status >= 500) {
|
|
42
|
+
throw new ServerError(message, status, body, provider, model);
|
|
43
|
+
}
|
|
44
|
+
throw new APIError(message, status, body, provider, model);
|
|
45
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/deepseek/Streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/deepseek/Streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAOxD,qBAAa,iBAAiB;IAE1B,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM;IAG1B,OAAO,CAAC,OAAO,EAAE,WAAW,EAAE,UAAU,CAAC,EAAE,eAAe,GAAG,cAAc,CAAC,SAAS,CAAC;CA8L9F"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { APIError } from "../../errors/index.js";
|
|
2
2
|
import { logger } from "../../utils/logger.js";
|
|
3
|
+
import { handleDeepSeekError } from "./Errors.js";
|
|
3
4
|
import { mapSystemMessages } from "../utils.js";
|
|
4
5
|
import { fetchWithTimeout } from "../../utils/fetch.js";
|
|
5
6
|
export class DeepSeekStreaming {
|
|
@@ -25,6 +26,8 @@ export class DeepSeekStreaming {
|
|
|
25
26
|
body.tools = tools;
|
|
26
27
|
if (response_format)
|
|
27
28
|
body.response_format = response_format;
|
|
29
|
+
// DeepSeek (and most OpenAI compatible) supports include_usage
|
|
30
|
+
body.stream_options = { include_usage: true };
|
|
28
31
|
let done = false;
|
|
29
32
|
// Track tool calls being built across chunks
|
|
30
33
|
const toolCallsMap = new Map();
|
|
@@ -42,8 +45,7 @@ export class DeepSeekStreaming {
|
|
|
42
45
|
signal: abortController.signal
|
|
43
46
|
}, requestTimeout);
|
|
44
47
|
if (!response.ok) {
|
|
45
|
-
|
|
46
|
-
throw new Error(`DeepSeek API error: ${response.status} - ${errorText}`);
|
|
48
|
+
await handleDeepSeekError(response, model);
|
|
47
49
|
}
|
|
48
50
|
logger.debug("DeepSeek streaming started", {
|
|
49
51
|
status: response.status,
|
|
@@ -131,6 +133,15 @@ export class DeepSeekStreaming {
|
|
|
131
133
|
}
|
|
132
134
|
}
|
|
133
135
|
}
|
|
136
|
+
// Handle usage
|
|
137
|
+
if (json.usage) {
|
|
138
|
+
const usage = {
|
|
139
|
+
input_tokens: json.usage.prompt_tokens,
|
|
140
|
+
output_tokens: json.usage.completion_tokens,
|
|
141
|
+
total_tokens: json.usage.total_tokens
|
|
142
|
+
};
|
|
143
|
+
yield { content: "", usage };
|
|
144
|
+
}
|
|
134
145
|
}
|
|
135
146
|
catch (e) {
|
|
136
147
|
// Re-throw APIError
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Errors.d.ts","sourceRoot":"","sources":["../../../src/providers/gemini/Errors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Errors.d.ts","sourceRoot":"","sources":["../../../src/providers/gemini/Errors.ts"],"names":[],"mappings":"AAaA,wBAAsB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAuD1F"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BadRequestError, AuthenticationError, RateLimitError, ServerError, ServiceUnavailableError, APIError } from "../../errors/index.js";
|
|
1
|
+
import { BadRequestError, ContextWindowExceededError, InsufficientQuotaError, InvalidModelError, NotFoundError, AuthenticationError, RateLimitError, ServerError, ServiceUnavailableError, APIError } from "../../errors/index.js";
|
|
2
2
|
export async function handleGeminiError(response, model) {
|
|
3
3
|
const status = response.status;
|
|
4
4
|
let body;
|
|
@@ -19,12 +19,24 @@ export async function handleGeminiError(response, model) {
|
|
|
19
19
|
}
|
|
20
20
|
const provider = "gemini";
|
|
21
21
|
if (status === 400) {
|
|
22
|
+
if (message.includes("limit") || message.includes("context") || message.includes("token")) {
|
|
23
|
+
throw new ContextWindowExceededError(message, body, provider, model);
|
|
24
|
+
}
|
|
22
25
|
throw new BadRequestError(message, body, provider, model);
|
|
23
26
|
}
|
|
24
27
|
if (status === 401 || status === 403) {
|
|
25
28
|
throw new AuthenticationError(message, status, body, provider);
|
|
26
29
|
}
|
|
30
|
+
if (status === 404) {
|
|
31
|
+
if (message.includes("model")) {
|
|
32
|
+
throw new InvalidModelError(message, body, provider, model);
|
|
33
|
+
}
|
|
34
|
+
throw new NotFoundError(message, status, body, provider, model);
|
|
35
|
+
}
|
|
27
36
|
if (status === 429) {
|
|
37
|
+
if (message.includes("quota")) {
|
|
38
|
+
throw new InsufficientQuotaError(message, body, provider, model);
|
|
39
|
+
}
|
|
28
40
|
throw new RateLimitError(message, body, provider, model);
|
|
29
41
|
}
|
|
30
42
|
if (status === 502 || status === 503 || status === 504) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GeminiProvider.d.ts","sourceRoot":"","sources":["../../../src/providers/gemini/GeminiProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,Q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B,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAMxC,SAAS,CAAC,YAAY,IAAI,MAAM;IAIhB,YAAY,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM;IAIjD,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IAIhD,MAAM,CAAC,OAAO,EAAE,WAAW,GAAG,cAAc,CAAC,SAAS,CAAC;IAIxD,UAAU,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAIlC,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;IAIpD,KAAK,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAI5D,UAAU,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAKhF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BaseProvider } from "../BaseProvider.js";
|
|
2
|
+
import { DEFAULT_GEMINI_BASE_URL } from "../../constants.js";
|
|
2
3
|
import { Capabilities } from "./Capabilities.js";
|
|
3
4
|
import { GeminiChat } from "./Chat.js";
|
|
4
5
|
import { GeminiStreaming } from "./Streaming.js";
|
|
@@ -30,7 +31,7 @@ export class GeminiProvider extends BaseProvider {
|
|
|
30
31
|
constructor(options) {
|
|
31
32
|
super();
|
|
32
33
|
this.options = options;
|
|
33
|
-
this.baseUrl = options.baseUrl ??
|
|
34
|
+
this.baseUrl = options.baseUrl ?? DEFAULT_GEMINI_BASE_URL;
|
|
34
35
|
this.chatHandler = new GeminiChat(this.baseUrl, options.apiKey);
|
|
35
36
|
this.streamingHandler = new GeminiStreaming(this.baseUrl, options.apiKey);
|
|
36
37
|
this.modelsHandler = new GeminiModels(this.baseUrl, options.apiKey);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OllamaProvider.d.ts","sourceRoot":"","sources":["../../../src/providers/ollama/OllamaProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"OllamaProvider.d.ts","sourceRoot":"","sources":["../../../src/providers/ollama/OllamaProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAO7D,MAAM,WAAW,qBAAqB;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,cAAe,SAAQ,cAAc;gBACpC,OAAO,GAAE,qBAA0B;IA2B/C,SAAS,CAAC,YAAY,IAAI,MAAM;IAIhB,YAAY,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM;CAGxD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { OpenAIProvider } from "../openai/OpenAIProvider.js";
|
|
2
|
-
import {
|
|
2
|
+
import { DEFAULT_OLLAMA_BASE_URL } from "../../constants.js";
|
|
3
3
|
import { OllamaModels } from "./Models.js";
|
|
4
4
|
import { OllamaEmbedding } from "./Embedding.js";
|
|
5
5
|
import { OllamaCapabilities } from "./Capabilities.js";
|
|
@@ -7,7 +7,7 @@ export class OllamaProvider extends OpenAIProvider {
|
|
|
7
7
|
constructor(options = {}) {
|
|
8
8
|
super({
|
|
9
9
|
apiKey: "ollama",
|
|
10
|
-
baseUrl: options.baseUrl ||
|
|
10
|
+
baseUrl: options.baseUrl || DEFAULT_OLLAMA_BASE_URL
|
|
11
11
|
});
|
|
12
12
|
// Override handlers with Ollama-specific ones
|
|
13
13
|
this.modelsHandler = new OllamaModels(this.baseUrl, this.options.apiKey);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Errors.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Errors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Errors.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Errors.ts"],"names":[],"mappings":"AAaA,wBAAsB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAmE1F"}
|
|
@@ -1,14 +1,26 @@
|
|
|
1
|
-
import { BadRequestError, AuthenticationError, RateLimitError, ServerError, ServiceUnavailableError, APIError } from "../../errors/index.js";
|
|
1
|
+
import { BadRequestError, ContextWindowExceededError, InsufficientQuotaError, InvalidModelError, NotFoundError, AuthenticationError, RateLimitError, ServerError, ServiceUnavailableError, APIError } from "../../errors/index.js";
|
|
2
2
|
export async function handleOpenAIError(response, model) {
|
|
3
3
|
const status = response.status;
|
|
4
4
|
let body;
|
|
5
5
|
let message = `OpenAI error (${status})`;
|
|
6
|
+
let code;
|
|
6
7
|
try {
|
|
7
8
|
body = await response.json();
|
|
8
|
-
if (body && typeof body === "object"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
if (body && typeof body === "object") {
|
|
10
|
+
if ("error" in body) {
|
|
11
|
+
const err = body.error;
|
|
12
|
+
if (typeof err === "string") {
|
|
13
|
+
message = err;
|
|
14
|
+
}
|
|
15
|
+
else if (err && typeof err === "object") {
|
|
16
|
+
if (err.message)
|
|
17
|
+
message = err.message;
|
|
18
|
+
if (err.code)
|
|
19
|
+
code = err.code;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
else if ("message" in body) {
|
|
23
|
+
message = body.message;
|
|
12
24
|
}
|
|
13
25
|
}
|
|
14
26
|
}
|
|
@@ -19,12 +31,26 @@ export async function handleOpenAIError(response, model) {
|
|
|
19
31
|
}
|
|
20
32
|
const provider = "openai";
|
|
21
33
|
if (status === 400) {
|
|
34
|
+
if (code === "context_length_exceeded" ||
|
|
35
|
+
message.includes("context length") ||
|
|
36
|
+
message.includes("too many tokens")) {
|
|
37
|
+
throw new ContextWindowExceededError(message, body, provider, model);
|
|
38
|
+
}
|
|
22
39
|
throw new BadRequestError(message, body, provider, model);
|
|
23
40
|
}
|
|
24
41
|
if (status === 401 || status === 403) {
|
|
25
42
|
throw new AuthenticationError(message, status, body, provider);
|
|
26
43
|
}
|
|
44
|
+
if (status === 404) {
|
|
45
|
+
if (code === "model_not_found") {
|
|
46
|
+
throw new InvalidModelError(message, body, provider, model);
|
|
47
|
+
}
|
|
48
|
+
throw new NotFoundError(message, status, body, provider, model);
|
|
49
|
+
}
|
|
27
50
|
if (status === 429) {
|
|
51
|
+
if (code === "insufficient_quota") {
|
|
52
|
+
throw new InsufficientQuotaError(message, body, provider, model);
|
|
53
|
+
}
|
|
28
54
|
throw new RateLimitError(message, body, provider, model);
|
|
29
55
|
}
|
|
30
56
|
if (status === 502 || status === 503) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenAIProvider.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/OpenAIProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,SAAS,EACT,SAAS,EACT,YAAY,EACZ,aAAa,EACb,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"OpenAIProvider.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/OpenAIProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,SAAS,EACT,SAAS,EACT,YAAY,EACZ,aAAa,EACb,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGlD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC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M,CAAC,OAAO,EAAE,WAAW,GAAG,cAAc,CAAC,SAAS,CAAC;IAIxD,UAAU,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAIlC,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;IAIpD,UAAU,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAIzE,QAAQ,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAIjE,KAAK,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;CAGnE"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BaseProvider } from "../BaseProvider.js";
|
|
2
|
+
import { DEFAULT_OPENAI_BASE_URL } from "../../constants.js";
|
|
2
3
|
import { Capabilities } from "./Capabilities.js";
|
|
3
4
|
import { OpenAIChat } from "./Chat.js";
|
|
4
5
|
import { OpenAIStreaming } from "./Streaming.js";
|
|
@@ -32,7 +33,7 @@ export class OpenAIProvider extends BaseProvider {
|
|
|
32
33
|
constructor(options) {
|
|
33
34
|
super();
|
|
34
35
|
this.options = options;
|
|
35
|
-
this.baseUrl = options.baseUrl ??
|
|
36
|
+
this.baseUrl = options.baseUrl ?? DEFAULT_OPENAI_BASE_URL;
|
|
36
37
|
this.chatHandler = new OpenAIChat(this, options.apiKey);
|
|
37
38
|
this.streamingHandler = new OpenAIStreaming(this, options.apiKey);
|
|
38
39
|
this.modelsHandler = new OpenAIModels(this.baseUrl, options.apiKey);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAQxD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,qBAAa,eAAe;IAIxB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAGd,aAAa,EAAE,cAAc,GAAG,MAAM,EACtC,MAAM,EAAE,MAAM;IAK1B,OAAO,CAAC,OAAO,EAAE,WAAW,EAAE,UAAU,CAAC,EAAE,eAAe,GAAG,cAAc,CAAC,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAQxD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,qBAAa,eAAe;IAIxB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAGd,aAAa,EAAE,cAAc,GAAG,MAAM,EACtC,MAAM,EAAE,MAAM;IAK1B,OAAO,CAAC,OAAO,EAAE,WAAW,EAAE,UAAU,CAAC,EAAE,eAAe,GAAG,cAAc,CAAC,SAAS,CAAC;CAgN9F"}
|