@juspay/neurolink 10.8.4 → 10.8.6
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/CHANGELOG.md +8 -0
- package/dist/browser/neurolink.min.js +497 -478
- package/dist/factories/providerRegistry.js +11 -11
- package/dist/lib/factories/providerRegistry.js +11 -11
- package/dist/lib/providers/{amazonBedrock.d.ts → amazonBedrock/client.d.ts} +4 -4
- package/dist/{providers/amazonBedrock.js → lib/providers/amazonBedrock/client.js} +15 -18
- package/dist/lib/providers/amazonBedrock/constants.d.ts +1 -0
- package/dist/lib/providers/amazonBedrock/constants.js +3 -0
- package/dist/lib/providers/amazonBedrock/index.d.ts +3 -0
- package/dist/lib/providers/amazonBedrock/index.js +4 -0
- package/dist/lib/providers/amazonBedrock/utils.d.ts +1 -0
- package/dist/lib/providers/amazonBedrock/utils.js +4 -0
- package/dist/{providers/anthropic.d.ts → lib/providers/anthropic/client.d.ts} +6 -21
- package/dist/{providers/anthropic.js → lib/providers/anthropic/client.js} +28 -45
- package/dist/lib/providers/anthropic/constants.d.ts +4 -0
- package/dist/lib/providers/anthropic/constants.js +9 -0
- package/dist/lib/providers/anthropic/index.d.ts +3 -0
- package/dist/lib/providers/anthropic/index.js +4 -0
- package/dist/lib/providers/anthropic/utils.d.ts +7 -0
- package/dist/lib/providers/anthropic/utils.js +150 -0
- package/dist/lib/providers/{googleAiStudio.d.ts → googleAiStudio/client.d.ts} +4 -4
- package/dist/{providers/googleAiStudio.js → lib/providers/googleAiStudio/client.js} +16 -15
- package/dist/lib/providers/googleAiStudio/index.d.ts +2 -0
- package/dist/lib/providers/googleAiStudio/index.js +3 -0
- package/dist/lib/providers/googleAiStudio/utils.d.ts +2 -0
- package/dist/lib/providers/googleAiStudio/utils.js +19 -0
- package/dist/lib/providers/googleNativeGemini3/constants.d.ts +1 -0
- package/dist/lib/providers/googleNativeGemini3/constants.js +2 -0
- package/dist/lib/providers/googleNativeGemini3/index.d.ts +2 -0
- package/dist/lib/providers/googleNativeGemini3/index.js +3 -0
- package/dist/lib/providers/{googleNativeGemini3.d.ts → googleNativeGemini3/utils.d.ts} +2 -2
- package/dist/lib/providers/{googleNativeGemini3.js → googleNativeGemini3/utils.js} +8 -8
- package/dist/{providers/googleVertex.d.ts → lib/providers/googleVertex/client.d.ts} +4 -4
- package/dist/lib/providers/{googleVertex.js → googleVertex/client.js} +32 -32
- package/dist/lib/providers/googleVertex/constants.d.ts +5 -0
- package/dist/lib/providers/googleVertex/constants.js +27 -0
- package/dist/lib/providers/googleVertex/index.d.ts +3 -0
- package/dist/lib/providers/googleVertex/index.js +4 -0
- package/dist/lib/providers/googleVertex/utils.d.ts +12 -0
- package/dist/lib/providers/googleVertex/utils.js +287 -0
- package/dist/lib/providers/{huggingFace.d.ts → huggingFace/client.d.ts} +3 -3
- package/dist/lib/providers/{huggingFace.js → huggingFace/client.js} +7 -7
- package/dist/lib/providers/huggingFace/index.d.ts +2 -0
- package/dist/lib/providers/huggingFace/index.js +3 -0
- package/dist/lib/providers/huggingFace/utils.d.ts +2 -0
- package/dist/lib/providers/huggingFace/utils.js +8 -0
- package/dist/lib/providers/index.d.ts +10 -10
- package/dist/lib/providers/index.js +10 -10
- package/dist/{providers/litellm.d.ts → lib/providers/litellm/client.d.ts} +3 -3
- package/dist/lib/providers/{litellm.js → litellm/client.js} +13 -13
- package/dist/lib/providers/litellm/constants.d.ts +1 -0
- package/dist/lib/providers/litellm/constants.js +3 -0
- package/dist/lib/providers/litellm/index.d.ts +3 -0
- package/dist/lib/providers/litellm/index.js +4 -0
- package/dist/lib/providers/litellm/utils.d.ts +5 -0
- package/dist/lib/providers/litellm/utils.js +11 -0
- package/dist/{providers/nvidiaNim.d.ts → lib/providers/nvidiaNim/client.d.ts} +3 -3
- package/dist/lib/providers/{nvidiaNim.js → nvidiaNim/client.js} +8 -8
- package/dist/lib/providers/nvidiaNim/constants.d.ts +1 -0
- package/dist/lib/providers/nvidiaNim/constants.js +2 -0
- package/dist/lib/providers/nvidiaNim/index.d.ts +3 -0
- package/dist/lib/providers/nvidiaNim/index.js +4 -0
- package/dist/lib/providers/nvidiaNim/utils.d.ts +9 -0
- package/dist/lib/providers/nvidiaNim/utils.js +101 -0
- package/dist/{providers/ollama.d.ts → lib/providers/ollama/client.d.ts} +3 -3
- package/dist/{providers/ollama.js → lib/providers/ollama/client.js} +10 -13
- package/dist/lib/providers/ollama/constants.d.ts +4 -0
- package/dist/lib/providers/ollama/constants.js +6 -0
- package/dist/lib/providers/ollama/index.d.ts +3 -0
- package/dist/lib/providers/ollama/index.js +4 -0
- package/dist/lib/providers/ollama/utils.d.ts +8 -0
- package/dist/lib/providers/ollama/utils.js +43 -0
- package/dist/lib/providers/{openAI.d.ts → openAI/client.d.ts} +3 -3
- package/dist/lib/providers/{openAI.js → openAI/client.js} +13 -13
- package/dist/lib/providers/openAI/constants.d.ts +1 -0
- package/dist/lib/providers/openAI/constants.js +3 -0
- package/dist/lib/providers/openAI/index.d.ts +3 -0
- package/dist/lib/providers/openAI/index.js +4 -0
- package/dist/lib/providers/openAI/utils.d.ts +2 -0
- package/dist/lib/providers/openAI/utils.js +8 -0
- package/dist/lib/providers/{openRouter.d.ts → openRouter/client.d.ts} +3 -3
- package/dist/{providers/openRouter.js → lib/providers/openRouter/client.js} +13 -29
- package/dist/lib/providers/openRouter/constants.d.ts +1 -0
- package/dist/lib/providers/openRouter/constants.js +2 -0
- package/dist/lib/providers/openRouter/index.d.ts +3 -0
- package/dist/lib/providers/openRouter/index.js +4 -0
- package/dist/lib/providers/openRouter/utils.d.ts +3 -0
- package/dist/lib/providers/openRouter/utils.js +18 -0
- package/dist/lib/providers/{openaiCompatible.d.ts → openaiCompatible/client.d.ts} +2 -2
- package/dist/{providers/openaiCompatible.js → lib/providers/openaiCompatible/client.js} +8 -22
- package/dist/lib/providers/openaiCompatible/constants.d.ts +1 -0
- package/dist/lib/providers/openaiCompatible/constants.js +2 -0
- package/dist/lib/providers/openaiCompatible/index.d.ts +3 -0
- package/dist/lib/providers/openaiCompatible/index.js +4 -0
- package/dist/lib/providers/openaiCompatible/utils.d.ts +5 -0
- package/dist/lib/providers/openaiCompatible/utils.js +17 -0
- package/dist/lib/proxy/modelRouter.d.ts +10 -0
- package/dist/lib/proxy/modelRouter.js +17 -0
- package/dist/lib/proxy/proxyConfig.js +46 -0
- package/dist/lib/proxy/routingPolicy.d.ts +4 -2
- package/dist/lib/proxy/routingPolicy.js +8 -5
- package/dist/lib/proxy/runtimeConfig.js +2 -0
- package/dist/lib/server/routes/claudeProxyRoutes.d.ts +52 -1
- package/dist/lib/server/routes/claudeProxyRoutes.js +467 -221
- package/dist/lib/server/routes/openaiProxyRoutes.js +1 -1
- package/dist/lib/types/errors.d.ts +5 -0
- package/dist/lib/types/proxy.d.ts +24 -0
- package/dist/lib/types/subscription.d.ts +4 -0
- package/dist/lib/utils/providerHealth.js +2 -1
- package/dist/lib/utils/providerUtils.js +2 -1
- package/dist/providers/{amazonBedrock.d.ts → amazonBedrock/client.d.ts} +4 -4
- package/dist/{lib/providers/amazonBedrock.js → providers/amazonBedrock/client.js} +14 -19
- package/dist/providers/amazonBedrock/constants.d.ts +1 -0
- package/dist/providers/amazonBedrock/constants.js +2 -0
- package/dist/providers/amazonBedrock/index.d.ts +3 -0
- package/dist/providers/amazonBedrock/index.js +3 -0
- package/dist/providers/amazonBedrock/utils.d.ts +1 -0
- package/dist/providers/amazonBedrock/utils.js +3 -0
- package/dist/{lib/providers/anthropic.d.ts → providers/anthropic/client.d.ts} +6 -21
- package/dist/{lib/providers/anthropic.js → providers/anthropic/client.js} +27 -46
- package/dist/providers/anthropic/constants.d.ts +4 -0
- package/dist/providers/anthropic/constants.js +8 -0
- package/dist/providers/anthropic/index.d.ts +3 -0
- package/dist/providers/anthropic/index.js +3 -0
- package/dist/providers/anthropic/utils.d.ts +7 -0
- package/dist/providers/anthropic/utils.js +149 -0
- package/dist/providers/{googleAiStudio.d.ts → googleAiStudio/client.d.ts} +4 -4
- package/dist/{lib/providers/googleAiStudio.js → providers/googleAiStudio/client.js} +15 -16
- package/dist/providers/googleAiStudio/index.d.ts +2 -0
- package/dist/providers/googleAiStudio/index.js +2 -0
- package/dist/providers/googleAiStudio/utils.d.ts +2 -0
- package/dist/providers/googleAiStudio/utils.js +18 -0
- package/dist/providers/googleNativeGemini3/constants.d.ts +1 -0
- package/dist/providers/googleNativeGemini3/constants.js +1 -0
- package/dist/providers/googleNativeGemini3/index.d.ts +2 -0
- package/dist/providers/googleNativeGemini3/index.js +2 -0
- package/dist/providers/{googleNativeGemini3.d.ts → googleNativeGemini3/utils.d.ts} +2 -2
- package/dist/providers/{googleNativeGemini3.js → googleNativeGemini3/utils.js} +7 -7
- package/dist/{lib/providers/googleVertex.d.ts → providers/googleVertex/client.d.ts} +4 -4
- package/dist/providers/{googleVertex.js → googleVertex/client.js} +31 -31
- package/dist/providers/googleVertex/constants.d.ts +5 -0
- package/dist/providers/googleVertex/constants.js +26 -0
- package/dist/providers/googleVertex/index.d.ts +3 -0
- package/dist/providers/googleVertex/index.js +3 -0
- package/dist/providers/googleVertex/utils.d.ts +12 -0
- package/dist/providers/googleVertex/utils.js +286 -0
- package/dist/providers/{huggingFace.d.ts → huggingFace/client.d.ts} +3 -3
- package/dist/providers/{huggingFace.js → huggingFace/client.js} +6 -6
- package/dist/providers/huggingFace/index.d.ts +2 -0
- package/dist/providers/huggingFace/index.js +2 -0
- package/dist/providers/huggingFace/utils.d.ts +2 -0
- package/dist/providers/huggingFace/utils.js +7 -0
- package/dist/providers/index.d.ts +10 -10
- package/dist/providers/index.js +10 -10
- package/dist/{lib/providers/litellm.d.ts → providers/litellm/client.d.ts} +3 -3
- package/dist/providers/{litellm.js → litellm/client.js} +12 -12
- package/dist/providers/litellm/constants.d.ts +1 -0
- package/dist/providers/litellm/constants.js +2 -0
- package/dist/providers/litellm/index.d.ts +3 -0
- package/dist/providers/litellm/index.js +3 -0
- package/dist/providers/litellm/utils.d.ts +5 -0
- package/dist/providers/litellm/utils.js +10 -0
- package/dist/{lib/providers/nvidiaNim.d.ts → providers/nvidiaNim/client.d.ts} +3 -3
- package/dist/providers/{nvidiaNim.js → nvidiaNim/client.js} +7 -7
- package/dist/providers/nvidiaNim/constants.d.ts +1 -0
- package/dist/providers/nvidiaNim/constants.js +1 -0
- package/dist/providers/nvidiaNim/index.d.ts +3 -0
- package/dist/providers/nvidiaNim/index.js +3 -0
- package/dist/providers/nvidiaNim/utils.d.ts +9 -0
- package/dist/providers/nvidiaNim/utils.js +100 -0
- package/dist/{lib/providers/ollama.d.ts → providers/ollama/client.d.ts} +3 -3
- package/dist/{lib/providers/ollama.js → providers/ollama/client.js} +9 -14
- package/dist/providers/ollama/constants.d.ts +4 -0
- package/dist/providers/ollama/constants.js +5 -0
- package/dist/providers/ollama/index.d.ts +3 -0
- package/dist/providers/ollama/index.js +3 -0
- package/dist/providers/ollama/utils.d.ts +8 -0
- package/dist/providers/ollama/utils.js +42 -0
- package/dist/providers/{openAI.d.ts → openAI/client.d.ts} +3 -3
- package/dist/providers/{openAI.js → openAI/client.js} +12 -12
- package/dist/providers/openAI/constants.d.ts +1 -0
- package/dist/providers/openAI/constants.js +2 -0
- package/dist/providers/openAI/index.d.ts +3 -0
- package/dist/providers/openAI/index.js +3 -0
- package/dist/providers/openAI/utils.d.ts +2 -0
- package/dist/providers/openAI/utils.js +7 -0
- package/dist/providers/{openRouter.d.ts → openRouter/client.d.ts} +3 -3
- package/dist/{lib/providers/openRouter.js → providers/openRouter/client.js} +12 -30
- package/dist/providers/openRouter/constants.d.ts +1 -0
- package/dist/providers/openRouter/constants.js +1 -0
- package/dist/providers/openRouter/index.d.ts +3 -0
- package/dist/providers/openRouter/index.js +3 -0
- package/dist/providers/openRouter/utils.d.ts +3 -0
- package/dist/providers/openRouter/utils.js +17 -0
- package/dist/providers/{openaiCompatible.d.ts → openaiCompatible/client.d.ts} +2 -2
- package/dist/{lib/providers/openaiCompatible.js → providers/openaiCompatible/client.js} +7 -23
- package/dist/providers/openaiCompatible/constants.d.ts +1 -0
- package/dist/providers/openaiCompatible/constants.js +1 -0
- package/dist/providers/openaiCompatible/index.d.ts +3 -0
- package/dist/providers/openaiCompatible/index.js +3 -0
- package/dist/providers/openaiCompatible/utils.d.ts +5 -0
- package/dist/providers/openaiCompatible/utils.js +16 -0
- package/dist/proxy/modelRouter.d.ts +10 -0
- package/dist/proxy/modelRouter.js +17 -0
- package/dist/proxy/proxyConfig.js +46 -0
- package/dist/proxy/routingPolicy.d.ts +4 -2
- package/dist/proxy/routingPolicy.js +8 -5
- package/dist/proxy/runtimeConfig.js +2 -0
- package/dist/server/routes/claudeProxyRoutes.d.ts +52 -1
- package/dist/server/routes/claudeProxyRoutes.js +467 -221
- package/dist/server/routes/openaiProxyRoutes.js +1 -1
- package/dist/types/errors.d.ts +5 -0
- package/dist/types/proxy.d.ts +24 -0
- package/dist/types/subscription.d.ts +4 -0
- package/dist/utils/providerHealth.js +2 -1
- package/dist/utils/providerUtils.js +2 -1
- package/package.json +3 -1
|
@@ -321,7 +321,7 @@ export function createOpenAIProxyRoutes(modelRouter, basePath = "", loopbackPort
|
|
|
321
321
|
model: targetModel,
|
|
322
322
|
}, requestModelRouter?.getFallbackChain() ?? [], body.model,
|
|
323
323
|
// The classifier only reads fields present on both types.
|
|
324
|
-
adapted);
|
|
324
|
+
adapted, requestModelRouter?.isAutoFallbackEnabled?.() ?? false);
|
|
325
325
|
const attempts = plan.attempts;
|
|
326
326
|
// --- Optional tracing ---
|
|
327
327
|
let tracer;
|
|
@@ -12,6 +12,11 @@ export declare class ProviderError extends BaseError {
|
|
|
12
12
|
provider?: string | undefined;
|
|
13
13
|
constructor(message: string, provider?: string | undefined);
|
|
14
14
|
}
|
|
15
|
+
export type OllamaHttpError = ProviderError & {
|
|
16
|
+
statusCode?: number;
|
|
17
|
+
statusText?: string;
|
|
18
|
+
responseBody?: string;
|
|
19
|
+
};
|
|
15
20
|
/**
|
|
16
21
|
* Thrown for authentication-related errors, such as invalid or missing API keys.
|
|
17
22
|
*/
|
|
@@ -29,6 +29,8 @@ export type ModelRouterInterface = {
|
|
|
29
29
|
resolve(requestedModel: string): RouteResult;
|
|
30
30
|
isClaudeTarget(requestedModel: string): boolean;
|
|
31
31
|
getFallbackChain(): FallbackEntry[];
|
|
32
|
+
isAutoFallbackEnabled?(): boolean;
|
|
33
|
+
getMaxInflightPerAccount?(): number;
|
|
32
34
|
getModelMappings?: () => ModelMapping[];
|
|
33
35
|
getPassthroughModels?: () => string[];
|
|
34
36
|
};
|
|
@@ -639,6 +641,27 @@ export type AnthropicSuccessResult = {
|
|
|
639
641
|
};
|
|
640
642
|
} | {
|
|
641
643
|
response: Response | unknown;
|
|
644
|
+
holdsAccountAdmission?: boolean;
|
|
645
|
+
};
|
|
646
|
+
/** A release handle for one in-flight request admitted to an OAuth account. */
|
|
647
|
+
export type AccountAdmissionLease = {
|
|
648
|
+
release(): void;
|
|
649
|
+
};
|
|
650
|
+
/** A cancellable queued request for per-account admission capacity. */
|
|
651
|
+
export type QueuedAccountAdmission = {
|
|
652
|
+
accountKey: string;
|
|
653
|
+
promise: Promise<AccountAdmissionLease>;
|
|
654
|
+
cancel(): void;
|
|
655
|
+
};
|
|
656
|
+
/** One queued request waiting for per-account admission capacity. */
|
|
657
|
+
export type AccountAdmissionWaiter = {
|
|
658
|
+
capacity: number;
|
|
659
|
+
resolve: (lease: AccountAdmissionLease) => void;
|
|
660
|
+
};
|
|
661
|
+
/** In-process request admission state for an OAuth account. */
|
|
662
|
+
export type AccountAdmissionState = {
|
|
663
|
+
active: number;
|
|
664
|
+
waiters: AccountAdmissionWaiter[];
|
|
642
665
|
};
|
|
643
666
|
/** Result of buffering only enough upstream SSE to make a retry-safe decision. */
|
|
644
667
|
export type AnthropicStreamPreflightResult = {
|
|
@@ -669,6 +692,7 @@ export type ParsedSSEBuffer = {
|
|
|
669
692
|
};
|
|
670
693
|
export type AnthropicAuthRetryResult = {
|
|
671
694
|
response?: Response | unknown;
|
|
695
|
+
holdsAccountAdmission?: boolean;
|
|
672
696
|
continueLoop: boolean;
|
|
673
697
|
lastError: unknown;
|
|
674
698
|
authFailureMessage: string | null;
|
|
@@ -908,6 +908,10 @@ export type ProxyRoutingConfig = {
|
|
|
908
908
|
strategy: "round-robin" | "fill-first";
|
|
909
909
|
modelMappings: ModelMapping[];
|
|
910
910
|
fallbackChain: FallbackEntry[];
|
|
911
|
+
/** Permit a last-resort provider chosen by the translation layer. Disabled by default. */
|
|
912
|
+
autoFallback?: boolean;
|
|
913
|
+
/** Maximum in-flight upstream requests per OAuth account. Defaults to two. */
|
|
914
|
+
maxInflightPerAccount?: number;
|
|
911
915
|
passthroughModels?: string[];
|
|
912
916
|
/** Enable quota-aware fill-first account ordering. Defaults to true. */
|
|
913
917
|
quotaRouting?: boolean;
|
|
@@ -7,6 +7,7 @@ import { AIProviderName, OpenAIModels, GoogleAIModels, AnthropicModels, BedrockM
|
|
|
7
7
|
import { API_KEY_LENGTHS, PROJECT_ID_FORMAT } from "./providerConfig.js";
|
|
8
8
|
import { basename } from "path";
|
|
9
9
|
import { createProxyFetch } from "../proxy/proxyFetch.js";
|
|
10
|
+
import { DEFAULT_OLLAMA_MODEL } from "../providers/ollama/constants.js";
|
|
10
11
|
export class ProviderHealthChecker {
|
|
11
12
|
static healthCache = new Map();
|
|
12
13
|
static DEFAULT_TIMEOUT = 5000; // 5 seconds
|
|
@@ -690,7 +691,7 @@ export class ProviderHealthChecker {
|
|
|
690
691
|
return new URL("/api/tags", this.getOllamaBaseUrl()).toString();
|
|
691
692
|
}
|
|
692
693
|
static getConfiguredOllamaModel() {
|
|
693
|
-
return process.env.OLLAMA_MODEL ||
|
|
694
|
+
return process.env.OLLAMA_MODEL || DEFAULT_OLLAMA_MODEL;
|
|
694
695
|
}
|
|
695
696
|
static async fetchJsonWithTimeout(url, options = {}) {
|
|
696
697
|
const controller = new AbortController();
|
|
@@ -7,6 +7,7 @@ import { logger } from "./logger.js";
|
|
|
7
7
|
import { AIProviderName } from "../constants/enums.js";
|
|
8
8
|
import { ProviderHealthChecker } from "./providerHealth.js";
|
|
9
9
|
import { API_KEY_FORMATS, API_KEY_LENGTHS, PROJECT_ID_FORMAT, } from "./providerConfig.js";
|
|
10
|
+
import { DEFAULT_OLLAMA_MODEL } from "../providers/ollama/constants.js";
|
|
10
11
|
/**
|
|
11
12
|
* Get the best available provider based on real-time availability checks
|
|
12
13
|
* Enhanced version consolidated from providerUtils-fixed.ts
|
|
@@ -107,7 +108,7 @@ async function isProviderAvailable(providerName) {
|
|
|
107
108
|
return availability.available;
|
|
108
109
|
}
|
|
109
110
|
if (providerName === "ollama") {
|
|
110
|
-
const availability = await ProviderHealthChecker.checkFallbackProviderAvailability(AIProviderName.OLLAMA, process.env.OLLAMA_MODEL ||
|
|
111
|
+
const availability = await ProviderHealthChecker.checkFallbackProviderAvailability(AIProviderName.OLLAMA, process.env.OLLAMA_MODEL || DEFAULT_OLLAMA_MODEL);
|
|
111
112
|
return availability.available;
|
|
112
113
|
}
|
|
113
114
|
try {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BedrockRuntimeClient } from "@aws-sdk/client-bedrock-runtime";
|
|
2
|
-
import type { AIProviderName } from "
|
|
3
|
-
import { BaseProvider } from "
|
|
4
|
-
import type { NeuroLink } from "
|
|
5
|
-
import type { StreamOptions, StreamResult, EnhancedGenerateResult, TextGenerationOptions } from "
|
|
2
|
+
import type { AIProviderName } from "../../constants/enums.js";
|
|
3
|
+
import { BaseProvider } from "../../core/baseProvider.js";
|
|
4
|
+
import type { NeuroLink } from "../../neurolink.js";
|
|
5
|
+
import type { StreamOptions, StreamResult, EnhancedGenerateResult, TextGenerationOptions } from "../../types/index.js";
|
|
6
6
|
export declare class AmazonBedrockProvider extends BaseProvider {
|
|
7
7
|
private bedrockClient;
|
|
8
8
|
private conversationHistory;
|
|
@@ -1,24 +1,20 @@
|
|
|
1
|
-
async function loadBedrockControl() {
|
|
2
|
-
return await import(/* @vite-ignore */ "@aws-sdk/client-bedrock");
|
|
3
|
-
}
|
|
4
1
|
import { BedrockRuntimeClient, ConverseCommand, ConverseStreamCommand, ImageFormat, } from "@aws-sdk/client-bedrock-runtime";
|
|
5
2
|
import path from "path";
|
|
6
|
-
import { createAnalytics } from "
|
|
7
|
-
import { BaseProvider } from "
|
|
8
|
-
import { DEFAULT_MAX_STEPS } from "
|
|
9
|
-
import { AuthenticationError, ProviderError, RateLimitError, } from "
|
|
10
|
-
import { isAbortError, withTimeout } from "
|
|
11
|
-
import { emitToolEndFromStepFinish } from "
|
|
12
|
-
import { logger } from "
|
|
13
|
-
import { resolveSamplingParams } from "
|
|
14
|
-
import { calculateCost } from "
|
|
15
|
-
import { buildMultimodalMessagesArray } from "
|
|
16
|
-
import { buildMultimodalOptions } from "
|
|
17
|
-
import { convertZodToJsonSchema } from "
|
|
3
|
+
import { createAnalytics } from "../../core/analytics.js";
|
|
4
|
+
import { BaseProvider } from "../../core/baseProvider.js";
|
|
5
|
+
import { DEFAULT_MAX_STEPS } from "../../core/constants.js";
|
|
6
|
+
import { AuthenticationError, ProviderError, RateLimitError, } from "../../types/index.js";
|
|
7
|
+
import { isAbortError, withTimeout } from "../../utils/errorHandling.js";
|
|
8
|
+
import { emitToolEndFromStepFinish } from "../../utils/toolEndEmitter.js";
|
|
9
|
+
import { logger } from "../../utils/logger.js";
|
|
10
|
+
import { resolveSamplingParams } from "../../models/modelRegistry.js";
|
|
11
|
+
import { calculateCost } from "../../utils/pricing.js";
|
|
12
|
+
import { buildMultimodalMessagesArray } from "../../utils/messageBuilder.js";
|
|
13
|
+
import { buildMultimodalOptions } from "../../utils/multimodalOptionsBuilder.js";
|
|
14
|
+
import { convertZodToJsonSchema } from "../../utils/schemaConversion.js";
|
|
18
15
|
import { SpanKind, SpanStatusCode } from "@opentelemetry/api";
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
-
// Bedrock-specific types now imported from ../types/providerSpecific.js
|
|
16
|
+
import { bedrockTracer } from "./constants.js";
|
|
17
|
+
import { loadBedrockControl } from "./utils.js";
|
|
22
18
|
export class AmazonBedrockProvider extends BaseProvider {
|
|
23
19
|
bedrockClient;
|
|
24
20
|
conversationHistory = [];
|
|
@@ -1826,4 +1822,3 @@ export class AmazonBedrockProvider extends BaseProvider {
|
|
|
1826
1822
|
}
|
|
1827
1823
|
}
|
|
1828
1824
|
}
|
|
1829
|
-
//# sourceMappingURL=amazonBedrock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const bedrockTracer: import("@opentelemetry/api").Tracer;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function loadBedrockControl(): Promise<typeof import("@aws-sdk/client-bedrock")>;
|
|
@@ -1,21 +1,7 @@
|
|
|
1
|
-
import { type AIProviderName } from "
|
|
2
|
-
import { BaseProvider } from "
|
|
3
|
-
import type { AnthropicProviderConfig, StreamOptions, StreamResult, ValidationSchema, EnhancedGenerateResult, TextGenerationOptions, AnthropicAuthMethod, AnthropicResponseMetadata, ClaudeSubscriptionTier, ClaudeUsageInfo } from "
|
|
4
|
-
import type { LanguageModel } from "
|
|
5
|
-
/**
|
|
6
|
-
* Beta headers for Claude Code integration.
|
|
7
|
-
* These enable experimental features:
|
|
8
|
-
* - claude-code-20250219: Claude Code specific features
|
|
9
|
-
* - fine-grained-tool-streaming-2025-05-14: Fine-grained tool streaming
|
|
10
|
-
*
|
|
11
|
-
* Note: interleaved-thinking-2025-05-14 was removed — it was claude-3-7-sonnet
|
|
12
|
-
* specific and causes invalid_request_error (HTTP 400) on claude-4 models
|
|
13
|
-
* (claude-opus-4-6, claude-sonnet-4-6) which handle thinking via the
|
|
14
|
-
* `thinking` request body parameter instead.
|
|
15
|
-
*/
|
|
16
|
-
declare const ANTHROPIC_BETA_HEADERS: {
|
|
17
|
-
"anthropic-beta": string;
|
|
18
|
-
};
|
|
1
|
+
import { type AIProviderName } from "../../constants/enums.js";
|
|
2
|
+
import { BaseProvider } from "../../core/baseProvider.js";
|
|
3
|
+
import type { AnthropicProviderConfig, StreamOptions, StreamResult, ValidationSchema, EnhancedGenerateResult, TextGenerationOptions, AnthropicAuthMethod, AnthropicResponseMetadata, ClaudeSubscriptionTier, ClaudeUsageInfo } from "../../types/index.js";
|
|
4
|
+
import type { LanguageModel } from "../../types/index.js";
|
|
19
5
|
/**
|
|
20
6
|
* Anthropic Provider v2 - BaseProvider Implementation
|
|
21
7
|
* Enhanced with OAuth support, subscription tiers, and beta headers for Claude Code integration.
|
|
@@ -91,7 +77,7 @@ export declare class AnthropicProvider extends BaseProvider {
|
|
|
91
77
|
*
|
|
92
78
|
* @returns The model capabilities or undefined if not found
|
|
93
79
|
*/
|
|
94
|
-
getModelCapabilities(): import("
|
|
80
|
+
getModelCapabilities(): import("../../index.js").AnthropicModelMetadata | undefined;
|
|
95
81
|
/**
|
|
96
82
|
* Get the current subscription tier.
|
|
97
83
|
* @returns The detected or configured subscription tier
|
|
@@ -145,5 +131,4 @@ export declare class AnthropicProvider extends BaseProvider {
|
|
|
145
131
|
isAvailable(): Promise<boolean>;
|
|
146
132
|
getModel(): LanguageModel;
|
|
147
133
|
}
|
|
148
|
-
export { getModelCapabilities, getRecommendedModelForTier, isModelAvailableForTier, ModelAccessError, } from "
|
|
149
|
-
export { ANTHROPIC_BETA_HEADERS };
|
|
134
|
+
export { getModelCapabilities, getRecommendedModelForTier, isModelAvailableForTier, ModelAccessError, } from "../../models/anthropicModels.js";
|
|
@@ -3,48 +3,32 @@ import { SpanKind, trace } from "@opentelemetry/api";
|
|
|
3
3
|
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync, } from "fs";
|
|
4
4
|
import { homedir } from "os";
|
|
5
5
|
import { join } from "path";
|
|
6
|
-
import { ANTHROPIC_TOKEN_URL, CLAUDE_CLI_USER_AGENT, CLAUDE_CODE_CLIENT_ID, CLAUDE_CODE_OAUTH_BETAS, } from "
|
|
7
|
-
import { AnthropicModels, TOKEN_EXPIRY_BUFFER_MS, } from "
|
|
8
|
-
import { BaseProvider } from "
|
|
9
|
-
import { DEFAULT_MAX_STEPS } from "
|
|
10
|
-
import { streamAnalyticsCollector } from "
|
|
11
|
-
import { getModelCapabilities, getRecommendedModelForTier, isModelAvailableForTier, } from "
|
|
12
|
-
import { createOAuthFetch } from "
|
|
13
|
-
import { createProxyFetch } from "
|
|
14
|
-
import { AuthenticationError, NetworkError, ProviderError, RateLimitError, } from "
|
|
15
|
-
import { logger } from "
|
|
16
|
-
import { redactUrlCredentials } from "
|
|
17
|
-
import { ANTHROPIC_MAX_CACHE_BREAKPOINTS, applyAnthropicHistoryCacheBreakpoints, countAnthropicCacheMarkers, } from "
|
|
18
|
-
import { calculateCost } from "
|
|
19
|
-
import { resolveDeferredTool } from "
|
|
20
|
-
import { createAnthropicConfig, getProviderModel, validateApiKey, } from "
|
|
21
|
-
import { composeAbortSignals, createTimeoutController, mergeAbortSignals, TimeoutError, } from "
|
|
22
|
-
import { resolveToolChoice } from "
|
|
23
|
-
import { emitToolEndFromStepFinish } from "
|
|
24
|
-
import { NoOutputGeneratedError } from "
|
|
25
|
-
import { buildNoOutputSentinel, stampNoOutputSpan, } from "
|
|
26
|
-
import { convertZodToJsonSchema } from "
|
|
27
|
-
import { resolveClaudeMaxTokens } from "
|
|
28
|
-
import { toAnthropicImageBlock, fileToAnthropicBlock, } from "
|
|
29
|
-
import { resolveSamplingParams } from "
|
|
30
|
-
import { createChunkQueue, createDeferredAnalytics, stringifyToolInput, } from "
|
|
31
|
-
|
|
32
|
-
* Beta headers for Claude Code integration.
|
|
33
|
-
* These enable experimental features:
|
|
34
|
-
* - claude-code-20250219: Claude Code specific features
|
|
35
|
-
* - fine-grained-tool-streaming-2025-05-14: Fine-grained tool streaming
|
|
36
|
-
*
|
|
37
|
-
* Note: interleaved-thinking-2025-05-14 was removed — it was claude-3-7-sonnet
|
|
38
|
-
* specific and causes invalid_request_error (HTTP 400) on claude-4 models
|
|
39
|
-
* (claude-opus-4-6, claude-sonnet-4-6) which handle thinking via the
|
|
40
|
-
* `thinking` request body parameter instead.
|
|
41
|
-
*/
|
|
42
|
-
const ANTHROPIC_BETA_HEADERS = {
|
|
43
|
-
"anthropic-beta": [
|
|
44
|
-
"claude-code-20250219",
|
|
45
|
-
"fine-grained-tool-streaming-2025-05-14",
|
|
46
|
-
].join(","),
|
|
47
|
-
};
|
|
6
|
+
import { ANTHROPIC_TOKEN_URL, CLAUDE_CLI_USER_AGENT, CLAUDE_CODE_CLIENT_ID, CLAUDE_CODE_OAUTH_BETAS, } from "../../auth/anthropicOAuth.js";
|
|
7
|
+
import { AnthropicModels, TOKEN_EXPIRY_BUFFER_MS, } from "../../constants/enums.js";
|
|
8
|
+
import { BaseProvider } from "../../core/baseProvider.js";
|
|
9
|
+
import { DEFAULT_MAX_STEPS } from "../../core/constants.js";
|
|
10
|
+
import { streamAnalyticsCollector } from "../../core/streamAnalytics.js";
|
|
11
|
+
import { getModelCapabilities, getRecommendedModelForTier, isModelAvailableForTier, } from "../../models/anthropicModels.js";
|
|
12
|
+
import { createOAuthFetch } from "../../proxy/oauthFetch.js";
|
|
13
|
+
import { createProxyFetch } from "../../proxy/proxyFetch.js";
|
|
14
|
+
import { AuthenticationError, NetworkError, ProviderError, RateLimitError, } from "../../types/index.js";
|
|
15
|
+
import { logger } from "../../utils/logger.js";
|
|
16
|
+
import { redactUrlCredentials } from "../../utils/logSanitize.js";
|
|
17
|
+
import { ANTHROPIC_MAX_CACHE_BREAKPOINTS, applyAnthropicHistoryCacheBreakpoints, countAnthropicCacheMarkers, } from "../../utils/anthropicCacheBreakpoints.js";
|
|
18
|
+
import { calculateCost } from "../../utils/pricing.js";
|
|
19
|
+
import { resolveDeferredTool } from "../../tools/toolDiscovery.js";
|
|
20
|
+
import { createAnthropicConfig, getProviderModel, validateApiKey, } from "../../utils/providerConfig.js";
|
|
21
|
+
import { composeAbortSignals, createTimeoutController, mergeAbortSignals, TimeoutError, } from "../../utils/timeout.js";
|
|
22
|
+
import { resolveToolChoice } from "../../utils/toolChoice.js";
|
|
23
|
+
import { emitToolEndFromStepFinish } from "../../utils/toolEndEmitter.js";
|
|
24
|
+
import { NoOutputGeneratedError } from "../../utils/generationErrors.js";
|
|
25
|
+
import { buildNoOutputSentinel, stampNoOutputSpan, } from "../../utils/noOutputSentinel.js";
|
|
26
|
+
import { convertZodToJsonSchema } from "../../utils/schemaConversion.js";
|
|
27
|
+
import { resolveClaudeMaxTokens } from "../../utils/tokenLimits.js";
|
|
28
|
+
import { toAnthropicImageBlock, fileToAnthropicBlock, } from "../anthropicImageBlocks.js";
|
|
29
|
+
import { resolveSamplingParams } from "../../models/modelRegistry.js";
|
|
30
|
+
import { createChunkQueue, createDeferredAnalytics, stringifyToolInput, } from "../openaiChatCompletionsClient.js";
|
|
31
|
+
import { ANTHROPIC_BETA_HEADERS } from "./constants.js";
|
|
48
32
|
// AnthropicProviderConfig is imported from types/providers.ts
|
|
49
33
|
// Re-export for backward compatibility
|
|
50
34
|
// Configuration helpers - now using consolidated utility
|
|
@@ -1805,7 +1789,4 @@ export class AnthropicProvider extends BaseProvider {
|
|
|
1805
1789
|
}
|
|
1806
1790
|
}
|
|
1807
1791
|
// Re-export types and utilities for convenience
|
|
1808
|
-
export { getModelCapabilities, getRecommendedModelForTier, isModelAvailableForTier, ModelAccessError, } from "
|
|
1809
|
-
// Export beta headers constant for external use
|
|
1810
|
-
export { ANTHROPIC_BETA_HEADERS };
|
|
1811
|
-
//# sourceMappingURL=anthropic.js.map
|
|
1792
|
+
export { getModelCapabilities, getRecommendedModelForTier, isModelAvailableForTier, ModelAccessError, } from "../../models/anthropicModels.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { trace } from "@opentelemetry/api";
|
|
2
|
+
export const ANTHROPIC_BETA_HEADERS = {
|
|
3
|
+
"anthropic-beta": [
|
|
4
|
+
"claude-code-20250219",
|
|
5
|
+
"fine-grained-tool-streaming-2025-05-14",
|
|
6
|
+
].join(","),
|
|
7
|
+
};
|
|
8
|
+
export const streamTracer = trace.getTracer("neurolink.provider.anthropic");
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AnthropicAuthMethod, AnthropicRateLimitInfo, ClaudeSubscriptionTier, OAuthToken } from "../../types/index.js";
|
|
2
|
+
export declare const getAnthropicApiKey: () => string;
|
|
3
|
+
export declare const getDefaultAnthropicModel: () => string;
|
|
4
|
+
export declare const getOAuthToken: () => OAuthToken | null;
|
|
5
|
+
export declare const detectSubscriptionTier: (oauthToken: OAuthToken | null) => ClaudeSubscriptionTier;
|
|
6
|
+
export declare const detectAuthMethod: (oauthToken: OAuthToken | null) => AnthropicAuthMethod;
|
|
7
|
+
export declare const parseRateLimitHeaders: (headers: Headers | Record<string, string>) => AnthropicRateLimitInfo;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "fs";
|
|
2
|
+
import { homedir } from "os";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
import { AnthropicModels } from "../../constants/enums.js";
|
|
5
|
+
import { logger } from "../../utils/logger.js";
|
|
6
|
+
import { createAnthropicConfig, getProviderModel, validateApiKey, } from "../../utils/providerConfig.js";
|
|
7
|
+
export const getAnthropicApiKey = () => {
|
|
8
|
+
return validateApiKey(createAnthropicConfig());
|
|
9
|
+
};
|
|
10
|
+
export const getDefaultAnthropicModel = () => {
|
|
11
|
+
return getProviderModel("ANTHROPIC_MODEL", AnthropicModels.CLAUDE_SONNET_4_6);
|
|
12
|
+
};
|
|
13
|
+
export const getOAuthToken = () => {
|
|
14
|
+
// First, check stored credentials file (highest priority)
|
|
15
|
+
try {
|
|
16
|
+
const credentialsPath = join(homedir(), ".neurolink", "anthropic-credentials.json");
|
|
17
|
+
if (existsSync(credentialsPath)) {
|
|
18
|
+
const credentialsContent = readFileSync(credentialsPath, "utf-8");
|
|
19
|
+
const credentials = JSON.parse(credentialsContent);
|
|
20
|
+
if (credentials.type === "oauth" && credentials.oauth?.accessToken) {
|
|
21
|
+
logger.debug("[AnthropicProvider] Using OAuth token from stored credentials file");
|
|
22
|
+
return credentials.oauth;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
logger.debug("[AnthropicProvider] Failed to read stored credentials:", error);
|
|
28
|
+
}
|
|
29
|
+
// Fallback to environment variables
|
|
30
|
+
const tokenString = process.env.ANTHROPIC_OAUTH_TOKEN || process.env.CLAUDE_OAUTH_TOKEN;
|
|
31
|
+
if (!tokenString) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
// Try to parse as JSON (for full token object with refresh token and expiry)
|
|
35
|
+
try {
|
|
36
|
+
const parsed = JSON.parse(tokenString);
|
|
37
|
+
if (typeof parsed === "object" && parsed.accessToken) {
|
|
38
|
+
return parsed;
|
|
39
|
+
}
|
|
40
|
+
// If it's a simple string in JSON, use it as access token
|
|
41
|
+
if (typeof parsed === "string") {
|
|
42
|
+
return { accessToken: parsed };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
// Not JSON, treat as plain access token string
|
|
47
|
+
}
|
|
48
|
+
// Treat as plain access token string
|
|
49
|
+
return { accessToken: tokenString };
|
|
50
|
+
};
|
|
51
|
+
export const detectSubscriptionTier = (oauthToken) => {
|
|
52
|
+
// Check explicit environment variable first
|
|
53
|
+
const envTier = process.env.ANTHROPIC_SUBSCRIPTION_TIER?.toLowerCase();
|
|
54
|
+
if (envTier) {
|
|
55
|
+
const validTiers = [
|
|
56
|
+
"free",
|
|
57
|
+
"pro",
|
|
58
|
+
"max",
|
|
59
|
+
"max_5",
|
|
60
|
+
"max_20",
|
|
61
|
+
"api",
|
|
62
|
+
];
|
|
63
|
+
if (validTiers.includes(envTier)) {
|
|
64
|
+
logger.debug("[detectSubscriptionTier] Using environment override", {
|
|
65
|
+
tier: envTier,
|
|
66
|
+
});
|
|
67
|
+
return envTier;
|
|
68
|
+
}
|
|
69
|
+
logger.warn("[detectSubscriptionTier] Invalid ANTHROPIC_SUBSCRIPTION_TIER", {
|
|
70
|
+
value: envTier,
|
|
71
|
+
validTiers,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
// If using OAuth, default to 'pro' (most common subscription tier)
|
|
75
|
+
if (oauthToken) {
|
|
76
|
+
// Check if token scopes indicate tier (future-proofing)
|
|
77
|
+
const scopes = oauthToken.scopes ?? [];
|
|
78
|
+
let detectedTier = "pro";
|
|
79
|
+
if (scopes.includes("max_20")) {
|
|
80
|
+
detectedTier = "max_20";
|
|
81
|
+
}
|
|
82
|
+
else if (scopes.includes("max_5")) {
|
|
83
|
+
detectedTier = "max_5";
|
|
84
|
+
}
|
|
85
|
+
else if (scopes.includes("max")) {
|
|
86
|
+
detectedTier = "max";
|
|
87
|
+
}
|
|
88
|
+
logger.debug("[detectSubscriptionTier] Detected from OAuth token", {
|
|
89
|
+
tier: detectedTier,
|
|
90
|
+
scopes,
|
|
91
|
+
});
|
|
92
|
+
return detectedTier;
|
|
93
|
+
}
|
|
94
|
+
// Default to 'api' for API key authentication
|
|
95
|
+
logger.debug("[detectSubscriptionTier] No OAuth token, defaulting to API tier");
|
|
96
|
+
return "api";
|
|
97
|
+
};
|
|
98
|
+
export const detectAuthMethod = (oauthToken) => {
|
|
99
|
+
// Explicit env var takes highest precedence — allows forcing api_key mode
|
|
100
|
+
// even when OAuth credentials exist (e.g., when using a proxy that handles auth)
|
|
101
|
+
const explicit = process.env.ANTHROPIC_AUTH_METHOD?.toLowerCase();
|
|
102
|
+
if (explicit === "api_key" || explicit === "apikey") {
|
|
103
|
+
logger.debug("[detectAuthMethod] Forced to api_key by ANTHROPIC_AUTH_METHOD env var");
|
|
104
|
+
return "api_key";
|
|
105
|
+
}
|
|
106
|
+
if (explicit === "oauth") {
|
|
107
|
+
if (oauthToken) {
|
|
108
|
+
logger.debug("[detectAuthMethod] Forced to oauth by ANTHROPIC_AUTH_METHOD env var");
|
|
109
|
+
return "oauth";
|
|
110
|
+
}
|
|
111
|
+
logger.warn("[detectAuthMethod] ANTHROPIC_AUTH_METHOD=oauth but no OAuth token found; falling through to auto-detection");
|
|
112
|
+
}
|
|
113
|
+
else if (explicit) {
|
|
114
|
+
logger.warn("[detectAuthMethod] Unrecognized ANTHROPIC_AUTH_METHOD value; falling through to auto-detection", {
|
|
115
|
+
value: explicit,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
// Auto-detect: OAuth takes precedence if available
|
|
119
|
+
const method = oauthToken ? "oauth" : "api_key";
|
|
120
|
+
logger.debug("[detectAuthMethod] Auth method resolved", {
|
|
121
|
+
method,
|
|
122
|
+
hasOAuthToken: !!oauthToken,
|
|
123
|
+
});
|
|
124
|
+
return method;
|
|
125
|
+
};
|
|
126
|
+
export const parseRateLimitHeaders = (headers) => {
|
|
127
|
+
const getHeader = (name) => {
|
|
128
|
+
if (headers instanceof Headers) {
|
|
129
|
+
return headers.get(name);
|
|
130
|
+
}
|
|
131
|
+
return headers[name] || headers[name.toLowerCase()] || null;
|
|
132
|
+
};
|
|
133
|
+
const parseNumber = (value) => {
|
|
134
|
+
if (!value) {
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
const num = parseInt(value, 10);
|
|
138
|
+
return isNaN(num) ? undefined : num;
|
|
139
|
+
};
|
|
140
|
+
return {
|
|
141
|
+
requestsLimit: parseNumber(getHeader("anthropic-ratelimit-requests-limit")),
|
|
142
|
+
requestsRemaining: parseNumber(getHeader("anthropic-ratelimit-requests-remaining")),
|
|
143
|
+
requestsReset: getHeader("anthropic-ratelimit-requests-reset") || undefined,
|
|
144
|
+
tokensLimit: parseNumber(getHeader("anthropic-ratelimit-tokens-limit")),
|
|
145
|
+
tokensRemaining: parseNumber(getHeader("anthropic-ratelimit-tokens-remaining")),
|
|
146
|
+
tokensReset: getHeader("anthropic-ratelimit-tokens-reset") || undefined,
|
|
147
|
+
retryAfter: parseNumber(getHeader("retry-after")),
|
|
148
|
+
};
|
|
149
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { type AIProviderName } from "
|
|
2
|
-
import { BaseProvider } from "
|
|
3
|
-
import type { ZodUnknownSchema, EnhancedGenerateResult, TextGenerationOptions, StreamOptions, StreamResult } from "
|
|
4
|
-
import type { LanguageModel, Schema } from "
|
|
1
|
+
import { type AIProviderName } from "../../constants/enums.js";
|
|
2
|
+
import { BaseProvider } from "../../core/baseProvider.js";
|
|
3
|
+
import type { ZodUnknownSchema, EnhancedGenerateResult, TextGenerationOptions, StreamOptions, StreamResult } from "../../types/index.js";
|
|
4
|
+
import type { LanguageModel, Schema } from "../../types/index.js";
|
|
5
5
|
/**
|
|
6
6
|
* Google AI Studio provider implementation using BaseProvider
|
|
7
7
|
* Migrated from original GoogleAIStudio class to new factory pattern
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { ErrorCategory, ErrorSeverity, GoogleAIModels, } from "
|
|
2
|
-
import { BaseProvider } from "
|
|
3
|
-
import { IMAGE_GENERATION_MODELS, TOOL_STORAGE_TIMEOUT_MS, } from "
|
|
4
|
-
import { processUnifiedFilesArray } from "
|
|
5
|
-
import { ATTR, tracers, withClientSpan, withClientStreamSpan, withSpan, } from "
|
|
6
|
-
import { AuthenticationError, InvalidModelError, NetworkError, ProviderError, RateLimitError, } from "
|
|
7
|
-
import { ERROR_CODES, NeuroLinkError } from "
|
|
8
|
-
import { logger } from "
|
|
9
|
-
import { composeAbortSignals, createTimeoutController, TimeoutError, } from "
|
|
10
|
-
import { withTimeout } from "
|
|
11
|
-
import { estimateTokens } from "
|
|
12
|
-
import { transformToolExecutions } from "
|
|
13
|
-
import { resolveToolExecutionRecords } from "
|
|
14
|
-
import { buildGeminiResponseSchema, buildNativeConfig, buildNativeToolDeclarations, collectStreamChunks, collectStreamChunksIncremental, computeMaxSteps, createTextChannel, buildUserPartsWithMultimodal, executeNativeToolCalls, extractTextFromParts, extractThoughtSignature, handleMaxStepsTermination, prependConversationMessages, pushModelResponseToHistory, refreshNativeToolDeclarations, DedupExecuteMap, } from "
|
|
15
|
-
import { createProxyFetch } from "
|
|
1
|
+
import { ErrorCategory, ErrorSeverity, GoogleAIModels, } from "../../constants/enums.js";
|
|
2
|
+
import { BaseProvider } from "../../core/baseProvider.js";
|
|
3
|
+
import { IMAGE_GENERATION_MODELS, TOOL_STORAGE_TIMEOUT_MS, } from "../../core/constants.js";
|
|
4
|
+
import { processUnifiedFilesArray } from "../../utils/messageBuilder.js";
|
|
5
|
+
import { ATTR, tracers, withClientSpan, withClientStreamSpan, withSpan, } from "../../telemetry/index.js";
|
|
6
|
+
import { AuthenticationError, InvalidModelError, NetworkError, ProviderError, RateLimitError, } from "../../types/index.js";
|
|
7
|
+
import { ERROR_CODES, NeuroLinkError } from "../../utils/errorHandling.js";
|
|
8
|
+
import { logger } from "../../utils/logger.js";
|
|
9
|
+
import { composeAbortSignals, createTimeoutController, TimeoutError, } from "../../utils/timeout.js";
|
|
10
|
+
import { withTimeout } from "../../utils/async/index.js";
|
|
11
|
+
import { estimateTokens } from "../../utils/tokenEstimation.js";
|
|
12
|
+
import { transformToolExecutions } from "../../utils/transformationUtils.js";
|
|
13
|
+
import { resolveToolExecutionRecords } from "../../core/toolExecutionRecorder.js";
|
|
14
|
+
import { buildGeminiResponseSchema, buildNativeConfig, buildNativeToolDeclarations, collectStreamChunks, collectStreamChunksIncremental, computeMaxSteps, createTextChannel, buildUserPartsWithMultimodal, executeNativeToolCalls, extractTextFromParts, extractThoughtSignature, handleMaxStepsTermination, prependConversationMessages, pushModelResponseToHistory, refreshNativeToolDeclarations, DedupExecuteMap, } from "../googleNativeGemini3/index.js";
|
|
15
|
+
import { createProxyFetch } from "../../proxy/proxyFetch.js";
|
|
16
16
|
// Google AI Live API types now imported from ../types/providerSpecific.js
|
|
17
17
|
// Import proper types for multimodal message handling
|
|
18
18
|
// Create Google GenAI client
|
|
@@ -1442,4 +1442,3 @@ export class GoogleAIStudioProvider extends BaseProvider {
|
|
|
1442
1442
|
}
|
|
1443
1443
|
}
|
|
1444
1444
|
export default GoogleAIStudioProvider;
|
|
1445
|
-
//# sourceMappingURL=googleAiStudio.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ErrorCategory, ErrorSeverity } from "../../constants/enums.js";
|
|
2
|
+
import { ERROR_CODES, NeuroLinkError } from "../../utils/errorHandling.js";
|
|
3
|
+
export async function createGoogleGenAIClient(apiKey) {
|
|
4
|
+
const mod = await import("@google/genai");
|
|
5
|
+
const ctor = mod.GoogleGenAI;
|
|
6
|
+
if (!ctor) {
|
|
7
|
+
throw new NeuroLinkError({
|
|
8
|
+
code: ERROR_CODES.INVALID_CONFIGURATION,
|
|
9
|
+
message: "@google/genai does not export GoogleGenAI",
|
|
10
|
+
category: ErrorCategory.CONFIGURATION,
|
|
11
|
+
severity: ErrorSeverity.CRITICAL,
|
|
12
|
+
retriable: false,
|
|
13
|
+
context: { module: "@google/genai", expectedExport: "GoogleGenAI" },
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
const Ctor = ctor;
|
|
17
|
+
return new Ctor({ apiKey });
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const GEMINI3_NATIVE_MAX_STEPS = 100;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const GEMINI3_NATIVE_MAX_STEPS = 100;
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
* This module extracts the functions that are duplicated between the two
|
|
9
9
|
* providers so they can share a single implementation.
|
|
10
10
|
*/
|
|
11
|
-
import type { GenerateStopReason, ThinkingConfig, ChatMessage, CollectedChunkResult, MinimalChatMessage, NativeFunctionCall, NativeFunctionResponse, NativeToolDeclarationsResult, NativeToolsConfig, TextChannel, VertexNativePart, GeminiMultimodalInput } from "
|
|
12
|
-
import type { Tool } from "
|
|
11
|
+
import type { GenerateStopReason, ThinkingConfig, ChatMessage, CollectedChunkResult, MinimalChatMessage, NativeFunctionCall, NativeFunctionResponse, NativeToolDeclarationsResult, NativeToolsConfig, TextChannel, VertexNativePart, GeminiMultimodalInput } from "../../types/index.js";
|
|
12
|
+
import type { Tool } from "../../types/index.js";
|
|
13
13
|
/**
|
|
14
14
|
* A per-turn tool execute map that deduplicates identical tool calls.
|
|
15
15
|
*
|