@juspay/neurolink 10.8.3 → 10.8.5
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 +495 -476
- 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/types/errors.d.ts +5 -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/types/errors.d.ts +5 -0
- package/dist/utils/providerHealth.js +2 -1
- package/dist/utils/providerUtils.js +2 -1
- package/package.json +3 -1
|
@@ -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
|
*
|
|
@@ -11,13 +11,13 @@
|
|
|
11
11
|
import { randomUUID } from "node:crypto";
|
|
12
12
|
import { existsSync, readFileSync } from "node:fs";
|
|
13
13
|
import { extname } from "node:path";
|
|
14
|
-
import { DEFAULT_CONTEXT_GUARD_RATIO, DEFAULT_MAX_STEPS, DEFAULT_TOOL_MAX_RETRIES, DEFAULT_WRAPUP_TIME_LEAD_MS, } from "
|
|
15
|
-
import { logger } from "
|
|
16
|
-
import { resolveSamplingParams } from "
|
|
17
|
-
import { convertZodToJsonSchema, ensureNestedSchemaTypes, inlineJsonSchema, isZodSchema, normalizeJsonSchemaObject, } from "
|
|
18
|
-
import { createNativeThinkingConfig } from "
|
|
19
|
-
import { resolveLiveTool } from "
|
|
20
|
-
import { jsonSchema as aiJsonSchema, tool as createAISDKTool, } from "
|
|
14
|
+
import { DEFAULT_CONTEXT_GUARD_RATIO, DEFAULT_MAX_STEPS, DEFAULT_TOOL_MAX_RETRIES, DEFAULT_WRAPUP_TIME_LEAD_MS, } from "../../core/constants.js";
|
|
15
|
+
import { logger } from "../../utils/logger.js";
|
|
16
|
+
import { resolveSamplingParams } from "../../models/modelRegistry.js";
|
|
17
|
+
import { convertZodToJsonSchema, ensureNestedSchemaTypes, inlineJsonSchema, isZodSchema, normalizeJsonSchemaObject, } from "../../utils/schemaConversion.js";
|
|
18
|
+
import { createNativeThinkingConfig } from "../../utils/thinkingConfig.js";
|
|
19
|
+
import { resolveLiveTool } from "../../tools/toolDiscovery.js";
|
|
20
|
+
import { jsonSchema as aiJsonSchema, tool as createAISDKTool, } from "../../utils/tool.js";
|
|
21
21
|
// ── Functions ──
|
|
22
22
|
/** Stable, key-order-independent serialization of tool args for the dedup key. */
|
|
23
23
|
function stableStringifyForDedup(value) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { ZodType } from "zod";
|
|
2
|
-
import { AIProviderName } from "
|
|
3
|
-
import { BaseProvider } from "
|
|
4
|
-
import type { EnhancedGenerateResult, TextGenerationOptions, StreamOptions, StreamResult, VertexAnthropicMessage, ChatMessage, MinimalChatMessage } from "
|
|
5
|
-
import type { Schema, LanguageModel } from "
|
|
2
|
+
import { AIProviderName } from "../../constants/enums.js";
|
|
3
|
+
import { BaseProvider } from "../../core/baseProvider.js";
|
|
4
|
+
import type { EnhancedGenerateResult, TextGenerationOptions, StreamOptions, StreamResult, VertexAnthropicMessage, ChatMessage, MinimalChatMessage } from "../../types/index.js";
|
|
5
|
+
import type { Schema, LanguageModel } from "../../types/index.js";
|
|
6
6
|
export declare function buildAnthropicHistoryMessages(conversationMessages: Array<ChatMessage | MinimalChatMessage>): VertexAnthropicMessage[];
|
|
7
7
|
export declare function appendUserMessage(messages: VertexAnthropicMessage[], content: VertexAnthropicMessage["content"]): void;
|
|
8
8
|
/**
|
|
@@ -3,38 +3,38 @@
|
|
|
3
3
|
import fs from "fs";
|
|
4
4
|
import path from "path";
|
|
5
5
|
import os from "os";
|
|
6
|
-
import { ErrorCategory, ErrorSeverity, } from "
|
|
7
|
-
import { BaseProvider } from "
|
|
8
|
-
import { DEFAULT_GEMINI_STREAM_TIMEOUT_MS, DEFAULT_MAX_STEPS, DEFAULT_TOOL_EXECUTION_TIMEOUT_MS, DEFAULT_TOOL_MAX_RETRIES, GLOBAL_LOCATION_MODELS, IMAGE_GENERATION_MODELS, TOOL_STORAGE_TIMEOUT_MS, } from "
|
|
9
|
-
import { ModelConfigurationManager } from "
|
|
10
|
-
import { isSchemaComplexityError } from "
|
|
11
|
-
import { stringifyContentSafe } from "
|
|
12
|
-
import { createProxyFetch } from "
|
|
13
|
-
import { AuthenticationError, InvalidModelError, NetworkError, ProviderError, RateLimitError, } from "
|
|
14
|
-
import { ERROR_CODES, NeuroLinkError } from "
|
|
15
|
-
import { applyVertexAnthropicCacheBreakpoints } from "
|
|
16
|
-
import { FileDetector } from "
|
|
17
|
-
import { processUnifiedFilesArray } from "
|
|
18
|
-
import { logger } from "
|
|
19
|
-
import { hasRestrictedOutputLimit, RESTRICTED_OUTPUT_TOKEN_LIMIT, toVertexAnthropicModelId, } from "
|
|
20
|
-
import { detectImageMimeType } from "
|
|
21
|
-
import { resolveClaudeMaxTokens } from "
|
|
22
|
-
import { validateApiKey, createVertexProjectConfig, createGoogleAuthConfig, } from "
|
|
23
|
-
import { convertZodToJsonSchema, inlineJsonSchema, ensureNestedSchemaTypes, } from "
|
|
24
|
-
import { createNativeThinkingConfig } from "
|
|
25
|
-
import { TimeoutError, raceWithAbort, withTimeout, } from "
|
|
26
|
-
import { parseTimeout } from "
|
|
27
|
-
import { appendStepText, buildAbortedTurnMessage, buildContextCapMessage, buildToolLoopCapMessage, buildTurnStalledMessage, buildTurnTimeoutMessage, buildWrapupNudgeText, createContextGuard, createTextChannel, createTurnClock, extractThoughtSignature, isAbortError, mapGeminiFinishReason, prependConversationMessages, resolveTurnStopReason, DedupExecuteMap, } from "
|
|
28
|
-
import { getContextWindowSize } from "
|
|
29
|
-
import { resolveLiveTool } from "
|
|
30
|
-
import { ATTR, LANGFUSE_ATTR, spanJsonAttribute, tracers, withClientSpan, withClientStreamSpan, withSpan, } from "
|
|
6
|
+
import { ErrorCategory, ErrorSeverity, } from "../../constants/enums.js";
|
|
7
|
+
import { BaseProvider } from "../../core/baseProvider.js";
|
|
8
|
+
import { DEFAULT_GEMINI_STREAM_TIMEOUT_MS, DEFAULT_MAX_STEPS, DEFAULT_TOOL_EXECUTION_TIMEOUT_MS, DEFAULT_TOOL_MAX_RETRIES, GLOBAL_LOCATION_MODELS, IMAGE_GENERATION_MODELS, TOOL_STORAGE_TIMEOUT_MS, } from "../../core/constants.js";
|
|
9
|
+
import { ModelConfigurationManager } from "../../core/modelConfiguration.js";
|
|
10
|
+
import { isSchemaComplexityError } from "../../core/modules/structuredOutputPolicy.js";
|
|
11
|
+
import { stringifyContentSafe } from "../../utils/logSanitize.js";
|
|
12
|
+
import { createProxyFetch } from "../../proxy/proxyFetch.js";
|
|
13
|
+
import { AuthenticationError, InvalidModelError, NetworkError, ProviderError, RateLimitError, } from "../../types/index.js";
|
|
14
|
+
import { ERROR_CODES, NeuroLinkError } from "../../utils/errorHandling.js";
|
|
15
|
+
import { applyVertexAnthropicCacheBreakpoints } from "../../utils/anthropicCacheBreakpoints.js";
|
|
16
|
+
import { FileDetector } from "../../utils/fileDetector.js";
|
|
17
|
+
import { processUnifiedFilesArray } from "../../utils/messageBuilder.js";
|
|
18
|
+
import { logger } from "../../utils/logger.js";
|
|
19
|
+
import { hasRestrictedOutputLimit, RESTRICTED_OUTPUT_TOKEN_LIMIT, toVertexAnthropicModelId, } from "../../utils/modelDetection.js";
|
|
20
|
+
import { detectImageMimeType } from "../../utils/imageDetection.js";
|
|
21
|
+
import { resolveClaudeMaxTokens } from "../../utils/tokenLimits.js";
|
|
22
|
+
import { validateApiKey, createVertexProjectConfig, createGoogleAuthConfig, } from "../../utils/providerConfig.js";
|
|
23
|
+
import { convertZodToJsonSchema, inlineJsonSchema, ensureNestedSchemaTypes, } from "../../utils/schemaConversion.js";
|
|
24
|
+
import { createNativeThinkingConfig } from "../../utils/thinkingConfig.js";
|
|
25
|
+
import { TimeoutError, raceWithAbort, withTimeout, } from "../../utils/async/index.js";
|
|
26
|
+
import { parseTimeout } from "../../utils/timeout.js";
|
|
27
|
+
import { appendStepText, buildAbortedTurnMessage, buildContextCapMessage, buildToolLoopCapMessage, buildTurnStalledMessage, buildTurnTimeoutMessage, buildWrapupNudgeText, createContextGuard, createTextChannel, createTurnClock, extractThoughtSignature, isAbortError, mapGeminiFinishReason, prependConversationMessages, resolveTurnStopReason, DedupExecuteMap, } from "../googleNativeGemini3/index.js";
|
|
28
|
+
import { getContextWindowSize } from "../../constants/contextWindows.js";
|
|
29
|
+
import { resolveLiveTool } from "../../tools/toolDiscovery.js";
|
|
30
|
+
import { ATTR, LANGFUSE_ATTR, spanJsonAttribute, tracers, withClientSpan, withClientStreamSpan, withSpan, } from "../../telemetry/index.js";
|
|
31
31
|
import { SpanKind, SpanStatusCode, context as otelContext, trace as otelTrace, } from "@opentelemetry/api";
|
|
32
|
-
import { calculateCost } from "
|
|
33
|
-
import { transformToolExecutions } from "
|
|
34
|
-
import { resolveToolExecutionRecords } from "
|
|
35
|
-
import { resolveSamplingParams } from "
|
|
36
|
-
import { sanitizeAnthropicMessagesForTrace } from "
|
|
37
|
-
import { extractMcpToolErrorMessage, extractToolFailureText, } from "
|
|
32
|
+
import { calculateCost } from "../../utils/pricing.js";
|
|
33
|
+
import { transformToolExecutions } from "../../utils/transformationUtils.js";
|
|
34
|
+
import { resolveToolExecutionRecords } from "../../core/toolExecutionRecorder.js";
|
|
35
|
+
import { resolveSamplingParams } from "../../models/modelRegistry.js";
|
|
36
|
+
import { sanitizeAnthropicMessagesForTrace } from "../../utils/anthropicTraceSanitizer.js";
|
|
37
|
+
import { extractMcpToolErrorMessage, extractToolFailureText, } from "../../utils/mcpErrorText.js";
|
|
38
38
|
// Import proper types for multimodal message handling
|
|
39
39
|
// Dynamic import helper for native Anthropic Vertex SDK
|
|
40
40
|
let anthropicVertexModule = null;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const MAX_IMAGE_DOWNLOAD_BYTES: number;
|
|
2
|
+
export declare const streamTracer: import("@opentelemetry/api").Tracer;
|
|
3
|
+
export declare let cachedCredentialsPath: string | null;
|
|
4
|
+
export declare const VERTEX_MODEL_ALIASES: Record<string, string>;
|
|
5
|
+
export declare const setCachedCredentialsPath: (newPath: string | null) => void;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { trace } from "@opentelemetry/api";
|
|
2
|
+
export const MAX_IMAGE_DOWNLOAD_BYTES = 10 * 1024 * 1024;
|
|
3
|
+
export const streamTracer = trace.getTracer("neurolink.provider.vertex");
|
|
4
|
+
export let cachedCredentialsPath = null;
|
|
5
|
+
export const VERTEX_MODEL_ALIASES = {
|
|
6
|
+
// Claude 4.x shorthand aliases → versioned names
|
|
7
|
+
"claude-sonnet-4-5": "claude-sonnet-4-5@20250929",
|
|
8
|
+
"claude-opus-4-5": "claude-opus-4-5@20251124",
|
|
9
|
+
"claude-haiku-4-5": "claude-haiku-4-5@20251001",
|
|
10
|
+
"claude-sonnet-4": "claude-sonnet-4@20250514",
|
|
11
|
+
"claude-opus-4": "claude-opus-4@20250514",
|
|
12
|
+
"claude-opus-4-1": "claude-opus-4-1@20250805",
|
|
13
|
+
// Claude 3.x shorthand aliases → versioned names
|
|
14
|
+
"claude-3-7-sonnet": "claude-3-7-sonnet@20250219",
|
|
15
|
+
"claude-3-5-sonnet": "claude-3-5-sonnet-20241022",
|
|
16
|
+
"claude-3-5-haiku": "claude-3-5-haiku-20241022",
|
|
17
|
+
"claude-3-opus": "claude-3-opus-20240229",
|
|
18
|
+
"claude-3-sonnet": "claude-3-sonnet-20240229",
|
|
19
|
+
"claude-3-haiku": "claude-3-haiku-20240307",
|
|
20
|
+
// Gemini shorthand aliases
|
|
21
|
+
"gemini-3-pro": "gemini-3.1-pro-preview",
|
|
22
|
+
"gemini-3-flash": "gemini-3-flash-preview",
|
|
23
|
+
};
|
|
24
|
+
export const setCachedCredentialsPath = (newPath) => {
|
|
25
|
+
cachedCredentialsPath = newPath;
|
|
26
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type GoogleVertexAnthropicProviderSettings } from "@ai-sdk/google-vertex/anthropic";
|
|
2
|
+
import type { GoogleVertexProviderSettings } from "@ai-sdk/google-vertex";
|
|
3
|
+
import type { NeurolinkCredentials } from "../../types/index.js";
|
|
4
|
+
export declare function isPrivateOrLoopbackAddress(address: string): boolean;
|
|
5
|
+
export declare const hasAnthropicSupport: () => boolean;
|
|
6
|
+
export declare const getVertexProjectId: () => string;
|
|
7
|
+
export declare const getVertexLocation: () => string;
|
|
8
|
+
export declare const getDefaultVertexModel: () => string;
|
|
9
|
+
export declare const hasGoogleCredentials: () => boolean;
|
|
10
|
+
export declare const createVertexSettings: (region?: string, credentials?: NeurolinkCredentials["vertex"], modelName?: string) => Promise<GoogleVertexProviderSettings>;
|
|
11
|
+
export declare const createVertexAnthropicSettings: (region?: string, credentials?: NeurolinkCredentials["vertex"]) => Promise<GoogleVertexAnthropicProviderSettings>;
|
|
12
|
+
export declare const isAnthropicModel: (modelName: string) => boolean;
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import { createVertexAnthropic, } from "@ai-sdk/google-vertex/anthropic";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import os from "os";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import { logger } from "../../utils/logger.js";
|
|
6
|
+
import { createProxyFetch } from "../../proxy/proxyFetch.js";
|
|
7
|
+
import { createVertexProjectConfig, validateApiKey, } from "../../utils/providerConfig.js";
|
|
8
|
+
import { cachedCredentialsPath, setCachedCredentialsPath, } from "./constants.js";
|
|
9
|
+
export function isPrivateOrLoopbackAddress(address) {
|
|
10
|
+
const lower = address.toLowerCase();
|
|
11
|
+
// IPv4 loopback, unspecified, and private ranges
|
|
12
|
+
if (address.startsWith("127.") || address === "0.0.0.0") {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
if (address.startsWith("10.") || address.startsWith("192.168.")) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
if (/^172\.(1[6-9]|2\d|3[01])\./.test(address)) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
// IPv6 loopback, link-local, unique-local
|
|
22
|
+
if (address === "::1" ||
|
|
23
|
+
lower.startsWith("fe80:") ||
|
|
24
|
+
lower.startsWith("fc00:") ||
|
|
25
|
+
lower.startsWith("fd00:")) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
// Keep createVertexAnthropic import used by hasAnthropicSupport check above
|
|
31
|
+
export const hasAnthropicSupport = () => {
|
|
32
|
+
try {
|
|
33
|
+
// Verify the anthropic module is available
|
|
34
|
+
return typeof createVertexAnthropic === "function";
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
export const getVertexProjectId = () => {
|
|
41
|
+
return validateApiKey(createVertexProjectConfig());
|
|
42
|
+
};
|
|
43
|
+
export const getVertexLocation = () => {
|
|
44
|
+
return (process.env.GOOGLE_CLOUD_LOCATION ||
|
|
45
|
+
process.env.VERTEX_LOCATION ||
|
|
46
|
+
process.env.GOOGLE_VERTEX_LOCATION ||
|
|
47
|
+
"global");
|
|
48
|
+
};
|
|
49
|
+
import { resolveVertexLocation } from "./client.js";
|
|
50
|
+
export const getDefaultVertexModel = () => {
|
|
51
|
+
return process.env.VERTEX_MODEL || "gemini-2.5-flash";
|
|
52
|
+
};
|
|
53
|
+
export const hasGoogleCredentials = () => {
|
|
54
|
+
return !!(process.env.GOOGLE_APPLICATION_CREDENTIALS_NEUROLINK ||
|
|
55
|
+
process.env.GOOGLE_APPLICATION_CREDENTIALS ||
|
|
56
|
+
process.env.GOOGLE_SERVICE_ACCOUNT_KEY ||
|
|
57
|
+
(process.env.GOOGLE_AUTH_CLIENT_EMAIL &&
|
|
58
|
+
process.env.GOOGLE_AUTH_PRIVATE_KEY));
|
|
59
|
+
};
|
|
60
|
+
export const createVertexSettings = async (region, credentials, modelName) => {
|
|
61
|
+
const configuredLocation = credentials?.location || region || getVertexLocation();
|
|
62
|
+
const location = resolveVertexLocation(modelName, configuredLocation);
|
|
63
|
+
const project = credentials?.projectId || getVertexProjectId();
|
|
64
|
+
const baseSettings = {
|
|
65
|
+
project,
|
|
66
|
+
location,
|
|
67
|
+
fetch: createProxyFetch(),
|
|
68
|
+
};
|
|
69
|
+
// Special handling for global endpoint
|
|
70
|
+
if (location === "global") {
|
|
71
|
+
baseSettings.baseURL = `https://aiplatform.googleapis.com/v1/projects/${project}/locations/global/publishers/google`;
|
|
72
|
+
logger.debug("[GoogleVertexProvider] Using global endpoint", {
|
|
73
|
+
baseURL: baseSettings.baseURL,
|
|
74
|
+
location,
|
|
75
|
+
project,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
// ── Per-request credentials (highest priority) ──
|
|
79
|
+
if (credentials) {
|
|
80
|
+
if (credentials.apiKey) {
|
|
81
|
+
return { ...baseSettings, apiKey: credentials.apiKey };
|
|
82
|
+
}
|
|
83
|
+
const resolvedClientEmail = credentials.clientEmail ||
|
|
84
|
+
(credentials.serviceAccountKey
|
|
85
|
+
? JSON.parse(credentials.serviceAccountKey)
|
|
86
|
+
.client_email
|
|
87
|
+
: undefined);
|
|
88
|
+
const resolvedPrivateKey = credentials.privateKey ||
|
|
89
|
+
(credentials.serviceAccountKey
|
|
90
|
+
? JSON.parse(credentials.serviceAccountKey)
|
|
91
|
+
.private_key
|
|
92
|
+
: undefined);
|
|
93
|
+
if (resolvedClientEmail && resolvedPrivateKey) {
|
|
94
|
+
return {
|
|
95
|
+
...baseSettings,
|
|
96
|
+
googleAuthOptions: {
|
|
97
|
+
credentials: {
|
|
98
|
+
client_email: resolvedClientEmail,
|
|
99
|
+
private_key: resolvedPrivateKey.replace(/\\n/g, "\n"),
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// 🎯 OPTION 2: Create credentials file from environment variables at runtime
|
|
106
|
+
const requiredEnvVarsForFile = {
|
|
107
|
+
type: process.env.GOOGLE_AUTH_TYPE,
|
|
108
|
+
project_id: process.env.GOOGLE_AUTH_BREEZE_PROJECT_ID,
|
|
109
|
+
private_key: process.env.GOOGLE_AUTH_PRIVATE_KEY,
|
|
110
|
+
client_email: process.env.GOOGLE_AUTH_CLIENT_EMAIL,
|
|
111
|
+
client_id: process.env.GOOGLE_AUTH_CLIENT_ID,
|
|
112
|
+
auth_uri: process.env.GOOGLE_AUTH_AUTH_URI,
|
|
113
|
+
token_uri: process.env.GOOGLE_AUTH_TOKEN_URI,
|
|
114
|
+
auth_provider_x509_cert_url: process.env.GOOGLE_AUTH_AUTH_PROVIDER_CERT_URL,
|
|
115
|
+
client_x509_cert_url: process.env.GOOGLE_AUTH_CLIENT_CERT_URL,
|
|
116
|
+
universe_domain: process.env.GOOGLE_AUTH_UNIVERSE_DOMAIN,
|
|
117
|
+
};
|
|
118
|
+
if (requiredEnvVarsForFile.client_email &&
|
|
119
|
+
requiredEnvVarsForFile.private_key) {
|
|
120
|
+
// Return cached path if already written and still exists on disk
|
|
121
|
+
if (cachedCredentialsPath && fs.existsSync(cachedCredentialsPath)) {
|
|
122
|
+
process.env.GOOGLE_APPLICATION_CREDENTIALS = cachedCredentialsPath;
|
|
123
|
+
return baseSettings;
|
|
124
|
+
}
|
|
125
|
+
try {
|
|
126
|
+
const serviceAccountCredentials = {
|
|
127
|
+
type: requiredEnvVarsForFile.type || "service_account",
|
|
128
|
+
project_id: requiredEnvVarsForFile.project_id || getVertexProjectId(),
|
|
129
|
+
private_key: requiredEnvVarsForFile.private_key.replace(/\\n/g, "\n"),
|
|
130
|
+
client_email: requiredEnvVarsForFile.client_email,
|
|
131
|
+
client_id: requiredEnvVarsForFile.client_id || "",
|
|
132
|
+
auth_uri: requiredEnvVarsForFile.auth_uri ||
|
|
133
|
+
"https://accounts.google.com/o/oauth2/auth",
|
|
134
|
+
token_uri: requiredEnvVarsForFile.token_uri ||
|
|
135
|
+
"https://oauth2.googleapis.com/token",
|
|
136
|
+
auth_provider_x509_cert_url: requiredEnvVarsForFile.auth_provider_x509_cert_url ||
|
|
137
|
+
"https://www.googleapis.com/oauth2/v1/certs",
|
|
138
|
+
client_x509_cert_url: requiredEnvVarsForFile.client_x509_cert_url || "",
|
|
139
|
+
universe_domain: requiredEnvVarsForFile.universe_domain || "googleapis.com",
|
|
140
|
+
};
|
|
141
|
+
const tmpDir = os.tmpdir();
|
|
142
|
+
const credentialsFileName = `google-credentials-${Date.now()}-${Math.random().toString(36).substring(2, 11)}.json`;
|
|
143
|
+
const credentialsFilePath = path.join(tmpDir, credentialsFileName);
|
|
144
|
+
fs.writeFileSync(credentialsFilePath, JSON.stringify(serviceAccountCredentials, null, 2), { mode: 0o600 });
|
|
145
|
+
setCachedCredentialsPath(credentialsFilePath);
|
|
146
|
+
process.once("exit", () => {
|
|
147
|
+
try {
|
|
148
|
+
if (cachedCredentialsPath && fs.existsSync(cachedCredentialsPath)) {
|
|
149
|
+
fs.unlinkSync(cachedCredentialsPath);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
/* ignore cleanup errors */
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
process.env.GOOGLE_APPLICATION_CREDENTIALS = credentialsFilePath;
|
|
157
|
+
return baseSettings;
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
// Silent error handling for runtime credentials file creation
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
// 🎯 OPTION 1: Check for principal account authentication
|
|
164
|
+
if (process.env.GOOGLE_APPLICATION_CREDENTIALS_NEUROLINK) {
|
|
165
|
+
const credentialsPath = process.env.GOOGLE_APPLICATION_CREDENTIALS_NEUROLINK;
|
|
166
|
+
let fileExists;
|
|
167
|
+
try {
|
|
168
|
+
fileExists = fs.existsSync(credentialsPath);
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
fileExists = false;
|
|
172
|
+
}
|
|
173
|
+
if (fileExists) {
|
|
174
|
+
return baseSettings;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
if (process.env.GOOGLE_APPLICATION_CREDENTIALS) {
|
|
179
|
+
const credentialsPath = process.env.GOOGLE_APPLICATION_CREDENTIALS;
|
|
180
|
+
let fileExists;
|
|
181
|
+
try {
|
|
182
|
+
fileExists = fs.existsSync(credentialsPath);
|
|
183
|
+
}
|
|
184
|
+
catch {
|
|
185
|
+
fileExists = false;
|
|
186
|
+
}
|
|
187
|
+
if (fileExists) {
|
|
188
|
+
return baseSettings;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
const requiredEnvVars = {
|
|
193
|
+
type: process.env.GOOGLE_AUTH_TYPE,
|
|
194
|
+
project_id: process.env.GOOGLE_AUTH_BREEZE_PROJECT_ID,
|
|
195
|
+
private_key: process.env.GOOGLE_AUTH_PRIVATE_KEY,
|
|
196
|
+
client_email: process.env.GOOGLE_AUTH_CLIENT_EMAIL,
|
|
197
|
+
client_id: process.env.GOOGLE_AUTH_CLIENT_ID,
|
|
198
|
+
auth_uri: process.env.GOOGLE_AUTH_AUTH_URI,
|
|
199
|
+
token_uri: process.env.GOOGLE_AUTH_TOKEN_URI,
|
|
200
|
+
auth_provider_x509_cert_url: process.env.GOOGLE_AUTH_AUTH_PROVIDER_CERT_URL,
|
|
201
|
+
client_x509_cert_url: process.env.GOOGLE_AUTH_CLIENT_CERT_URL,
|
|
202
|
+
universe_domain: process.env.GOOGLE_AUTH_UNIVERSE_DOMAIN,
|
|
203
|
+
};
|
|
204
|
+
if (requiredEnvVars.client_email && requiredEnvVars.private_key) {
|
|
205
|
+
logger.debug("Using explicit service account credentials authentication", {
|
|
206
|
+
authMethod: "explicit_service_account_credentials",
|
|
207
|
+
hasType: !!requiredEnvVars.type,
|
|
208
|
+
hasProjectId: !!requiredEnvVars.project_id,
|
|
209
|
+
hasClientEmail: !!requiredEnvVars.client_email,
|
|
210
|
+
hasPrivateKey: !!requiredEnvVars.private_key,
|
|
211
|
+
hasClientId: !!requiredEnvVars.client_id,
|
|
212
|
+
hasAuthUri: !!requiredEnvVars.auth_uri,
|
|
213
|
+
hasTokenUri: !!requiredEnvVars.token_uri,
|
|
214
|
+
hasAuthProviderCertUrl: !!requiredEnvVars.auth_provider_x509_cert_url,
|
|
215
|
+
hasClientCertUrl: !!requiredEnvVars.client_x509_cert_url,
|
|
216
|
+
hasUniverseDomain: !!requiredEnvVars.universe_domain,
|
|
217
|
+
credentialsCompleteness: "using_individual_env_vars_as_fallback",
|
|
218
|
+
});
|
|
219
|
+
const serviceAccountCredentials = {
|
|
220
|
+
type: requiredEnvVars.type || "service_account",
|
|
221
|
+
project_id: requiredEnvVars.project_id || getVertexProjectId(),
|
|
222
|
+
private_key: requiredEnvVars.private_key.replace(/\\n/g, "\n"),
|
|
223
|
+
client_email: requiredEnvVars.client_email,
|
|
224
|
+
client_id: requiredEnvVars.client_id || "",
|
|
225
|
+
auth_uri: requiredEnvVars.auth_uri || "https://accounts.google.com/o/oauth2/auth",
|
|
226
|
+
token_uri: requiredEnvVars.token_uri || "https://oauth2.googleapis.com/token",
|
|
227
|
+
auth_provider_x509_cert_url: requiredEnvVars.auth_provider_x509_cert_url ||
|
|
228
|
+
"https://www.googleapis.com/oauth2/v1/certs",
|
|
229
|
+
client_x509_cert_url: requiredEnvVars.client_x509_cert_url || "",
|
|
230
|
+
universe_domain: requiredEnvVars.universe_domain || "googleapis.com",
|
|
231
|
+
};
|
|
232
|
+
return {
|
|
233
|
+
...baseSettings,
|
|
234
|
+
googleAuthOptions: {
|
|
235
|
+
credentials: serviceAccountCredentials,
|
|
236
|
+
},
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
logger.warn("No valid authentication found for Google Vertex AI", {
|
|
240
|
+
authMethod: "none",
|
|
241
|
+
authenticationAttempts: {
|
|
242
|
+
principalAccountFile: {
|
|
243
|
+
envVarSet: !!process.env.GOOGLE_APPLICATION_CREDENTIALS,
|
|
244
|
+
filePath: process.env.GOOGLE_APPLICATION_CREDENTIALS || "NOT_SET",
|
|
245
|
+
fileExists: false,
|
|
246
|
+
},
|
|
247
|
+
explicitCredentials: {
|
|
248
|
+
hasClientEmail: !!requiredEnvVars.client_email,
|
|
249
|
+
hasPrivateKey: !!requiredEnvVars.private_key,
|
|
250
|
+
hasProjectId: !!requiredEnvVars.project_id,
|
|
251
|
+
hasType: !!requiredEnvVars.type,
|
|
252
|
+
missingFields: Object.entries(requiredEnvVars)
|
|
253
|
+
.filter(([_key, value]) => !value)
|
|
254
|
+
.map(([key]) => key),
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
troubleshooting: [
|
|
258
|
+
"1. Ensure GOOGLE_APPLICATION_CREDENTIALS points to an existing file, OR",
|
|
259
|
+
"2. Set individual environment variables: GOOGLE_AUTH_CLIENT_EMAIL and GOOGLE_AUTH_PRIVATE_KEY",
|
|
260
|
+
],
|
|
261
|
+
});
|
|
262
|
+
return baseSettings;
|
|
263
|
+
};
|
|
264
|
+
export const createVertexAnthropicSettings = async (region, credentials) => {
|
|
265
|
+
const anthropicRegion = !region || region === "global" ? "us-east5" : region;
|
|
266
|
+
const anthropicCredentials = credentials?.location
|
|
267
|
+
? { ...credentials, location: anthropicRegion }
|
|
268
|
+
: credentials;
|
|
269
|
+
const baseVertexSettings = await createVertexSettings(anthropicRegion, anthropicCredentials);
|
|
270
|
+
return {
|
|
271
|
+
project: baseVertexSettings.project,
|
|
272
|
+
location: baseVertexSettings.location,
|
|
273
|
+
fetch: baseVertexSettings.fetch,
|
|
274
|
+
// The SDK's built-in retry honors Retry-After hints without any upper
|
|
275
|
+
// bound (a 429 with retry-after: 8549 sleeps 2.4h per retry, invisible
|
|
276
|
+
// to fallback orchestration). Retries are the orchestrator's job.
|
|
277
|
+
maxRetries: 0,
|
|
278
|
+
...(baseVertexSettings.apiKey && { apiKey: baseVertexSettings.apiKey }),
|
|
279
|
+
...(baseVertexSettings.googleAuthOptions && {
|
|
280
|
+
googleAuthOptions: baseVertexSettings.googleAuthOptions,
|
|
281
|
+
}),
|
|
282
|
+
};
|
|
283
|
+
};
|
|
284
|
+
export const isAnthropicModel = (modelName) => {
|
|
285
|
+
return modelName.toLowerCase().includes("claude");
|
|
286
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { AIProviderName } from "
|
|
2
|
-
import type { NeurolinkCredentials } from "
|
|
3
|
-
import { OpenAIChatCompletionsProvider } from "
|
|
1
|
+
import type { AIProviderName } from "../../constants/enums.js";
|
|
2
|
+
import type { NeurolinkCredentials } from "../../types/index.js";
|
|
3
|
+
import { OpenAIChatCompletionsProvider } from "../openaiChatCompletionsBase.js";
|
|
4
4
|
/**
|
|
5
5
|
* HuggingFace Provider — direct HTTP, no AI SDK.
|
|
6
6
|
*
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { AuthenticationError, InvalidModelError, NetworkError, ProviderError, RateLimitError, } from "
|
|
2
|
-
import { logger } from "
|
|
3
|
-
import { redactUrlCredentials } from "
|
|
4
|
-
import { createHuggingFaceConfig, getProviderModel, validateApiKey, } from "
|
|
5
|
-
import { TimeoutError } from "
|
|
6
|
-
import { OpenAIChatCompletionsProvider } from "
|
|
1
|
+
import { AuthenticationError, InvalidModelError, NetworkError, ProviderError, RateLimitError, } from "../../types/index.js";
|
|
2
|
+
import { logger } from "../../utils/logger.js";
|
|
3
|
+
import { redactUrlCredentials } from "../../utils/logSanitize.js";
|
|
4
|
+
import { createHuggingFaceConfig, getProviderModel, validateApiKey, } from "../../utils/providerConfig.js";
|
|
5
|
+
import { TimeoutError } from "../../utils/timeout.js";
|
|
6
|
+
import { OpenAIChatCompletionsProvider } from "../openaiChatCompletionsBase.js";
|
|
7
7
|
const HUGGINGFACE_DEFAULT_BASE_URL = "https://router.huggingface.co/v1";
|
|
8
8
|
const getHuggingFaceApiKey = () => validateApiKey(createHuggingFaceConfig());
|
|
9
9
|
const getDefaultHuggingFaceModel = () => getProviderModel("HUGGINGFACE_MODEL", "microsoft/DialoGPT-medium");
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createHuggingFaceConfig, getProviderModel, validateApiKey, } from "../../utils/providerConfig.js";
|
|
2
|
+
export const getHuggingFaceApiKey = () => {
|
|
3
|
+
return validateApiKey(createHuggingFaceConfig());
|
|
4
|
+
};
|
|
5
|
+
export const getDefaultHuggingFaceModel = () => {
|
|
6
|
+
return getProviderModel("HUGGINGFACE_MODEL", "microsoft/DialoGPT-medium");
|
|
7
|
+
};
|
|
@@ -2,20 +2,20 @@
|
|
|
2
2
|
* Provider exports for Vercel AI SDK integration
|
|
3
3
|
* This file centralizes all AI provider classes for easy import and usage
|
|
4
4
|
*/
|
|
5
|
-
export { GoogleVertexProvider as GoogleVertexAI } from "./googleVertex.js";
|
|
6
|
-
export { AmazonBedrockProvider as AmazonBedrock } from "./amazonBedrock.js";
|
|
5
|
+
export { GoogleVertexProvider as GoogleVertexAI } from "./googleVertex/index.js";
|
|
6
|
+
export { AmazonBedrockProvider as AmazonBedrock } from "./amazonBedrock/index.js";
|
|
7
7
|
export { AmazonSageMakerProvider as AmazonSageMaker } from "./amazonSagemaker.js";
|
|
8
|
-
export { OpenAIProvider as OpenAI } from "./openAI.js";
|
|
9
|
-
export { OpenAICompatibleProvider as OpenAICompatible } from "./openaiCompatible.js";
|
|
10
|
-
export { AnthropicProvider as AnthropicProvider } from "./anthropic.js";
|
|
8
|
+
export { OpenAIProvider as OpenAI } from "./openAI/index.js";
|
|
9
|
+
export { OpenAICompatibleProvider as OpenAICompatible } from "./openaiCompatible/index.js";
|
|
10
|
+
export { AnthropicProvider as AnthropicProvider } from "./anthropic/index.js";
|
|
11
11
|
export { AzureOpenAIProvider } from "./azureOpenai.js";
|
|
12
|
-
export { GoogleAIStudioProvider as GoogleAIStudio } from "./googleAiStudio.js";
|
|
13
|
-
export { HuggingFaceProvider as HuggingFace } from "./huggingFace.js";
|
|
14
|
-
export { OllamaProvider as Ollama } from "./ollama.js";
|
|
12
|
+
export { GoogleAIStudioProvider as GoogleAIStudio } from "./googleAiStudio/index.js";
|
|
13
|
+
export { HuggingFaceProvider as HuggingFace } from "./huggingFace/index.js";
|
|
14
|
+
export { OllamaProvider as Ollama } from "./ollama/index.js";
|
|
15
15
|
export { MistralProvider as MistralAI } from "./mistral.js";
|
|
16
|
-
export { LiteLLMProvider as LiteLLM } from "./litellm.js";
|
|
16
|
+
export { LiteLLMProvider as LiteLLM } from "./litellm/index.js";
|
|
17
17
|
export { DeepSeekProvider as DeepSeek } from "./deepseek.js";
|
|
18
|
-
export { NvidiaNimProvider as NvidiaNim } from "./nvidiaNim.js";
|
|
18
|
+
export { NvidiaNimProvider as NvidiaNim } from "./nvidiaNim/index.js";
|
|
19
19
|
export { LMStudioProvider as LMStudio } from "./lmStudio.js";
|
|
20
20
|
export { LlamaCppProvider as LlamaCpp } from "./llamaCpp.js";
|
|
21
21
|
export { XaiProvider as Xai } from "./xai.js";
|
package/dist/providers/index.js
CHANGED
|
@@ -2,20 +2,20 @@
|
|
|
2
2
|
* Provider exports for Vercel AI SDK integration
|
|
3
3
|
* This file centralizes all AI provider classes for easy import and usage
|
|
4
4
|
*/
|
|
5
|
-
export { GoogleVertexProvider as GoogleVertexAI } from "./googleVertex.js";
|
|
6
|
-
export { AmazonBedrockProvider as AmazonBedrock } from "./amazonBedrock.js";
|
|
5
|
+
export { GoogleVertexProvider as GoogleVertexAI } from "./googleVertex/index.js";
|
|
6
|
+
export { AmazonBedrockProvider as AmazonBedrock } from "./amazonBedrock/index.js";
|
|
7
7
|
export { AmazonSageMakerProvider as AmazonSageMaker } from "./amazonSagemaker.js";
|
|
8
|
-
export { OpenAIProvider as OpenAI } from "./openAI.js";
|
|
9
|
-
export { OpenAICompatibleProvider as OpenAICompatible } from "./openaiCompatible.js";
|
|
10
|
-
export { AnthropicProvider as AnthropicProvider } from "./anthropic.js";
|
|
8
|
+
export { OpenAIProvider as OpenAI } from "./openAI/index.js";
|
|
9
|
+
export { OpenAICompatibleProvider as OpenAICompatible } from "./openaiCompatible/index.js";
|
|
10
|
+
export { AnthropicProvider as AnthropicProvider } from "./anthropic/index.js";
|
|
11
11
|
export { AzureOpenAIProvider } from "./azureOpenai.js";
|
|
12
|
-
export { GoogleAIStudioProvider as GoogleAIStudio } from "./googleAiStudio.js";
|
|
13
|
-
export { HuggingFaceProvider as HuggingFace } from "./huggingFace.js";
|
|
14
|
-
export { OllamaProvider as Ollama } from "./ollama.js";
|
|
12
|
+
export { GoogleAIStudioProvider as GoogleAIStudio } from "./googleAiStudio/index.js";
|
|
13
|
+
export { HuggingFaceProvider as HuggingFace } from "./huggingFace/index.js";
|
|
14
|
+
export { OllamaProvider as Ollama } from "./ollama/index.js";
|
|
15
15
|
export { MistralProvider as MistralAI } from "./mistral.js";
|
|
16
|
-
export { LiteLLMProvider as LiteLLM } from "./litellm.js";
|
|
16
|
+
export { LiteLLMProvider as LiteLLM } from "./litellm/index.js";
|
|
17
17
|
export { DeepSeekProvider as DeepSeek } from "./deepseek.js";
|
|
18
|
-
export { NvidiaNimProvider as NvidiaNim } from "./nvidiaNim.js";
|
|
18
|
+
export { NvidiaNimProvider as NvidiaNim } from "./nvidiaNim/index.js";
|
|
19
19
|
export { LMStudioProvider as LMStudio } from "./lmStudio.js";
|
|
20
20
|
export { LlamaCppProvider as LlamaCpp } from "./llamaCpp.js";
|
|
21
21
|
export { XaiProvider as Xai } from "./xai.js";
|