@juspay/neurolink 5.0.0 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -7
- package/README.md +160 -172
- package/dist/agent/direct-tools.d.ts +6 -6
- package/dist/chat/sse-handler.js +5 -4
- package/dist/chat/websocket-chat-handler.js +9 -9
- package/dist/cli/commands/config.d.ts +3 -3
- package/dist/cli/commands/mcp.js +9 -8
- package/dist/cli/commands/ollama.js +3 -3
- package/dist/cli/factories/command-factory.d.ts +18 -0
- package/dist/cli/factories/command-factory.js +183 -0
- package/dist/cli/index.js +105 -157
- package/dist/cli/utils/interactive-setup.js +2 -2
- package/dist/core/base-provider.d.ts +423 -0
- package/dist/core/base-provider.js +365 -0
- package/dist/core/constants.d.ts +1 -1
- package/dist/core/constants.js +1 -1
- package/dist/core/dynamic-models.d.ts +6 -6
- package/dist/core/evaluation.d.ts +19 -80
- package/dist/core/evaluation.js +185 -484
- package/dist/core/factory.d.ts +3 -3
- package/dist/core/factory.js +31 -91
- package/dist/core/service-registry.d.ts +47 -0
- package/dist/core/service-registry.js +112 -0
- package/dist/core/types.d.ts +49 -49
- package/dist/core/types.js +1 -0
- package/dist/factories/compatibility-factory.d.ts +20 -0
- package/dist/factories/compatibility-factory.js +69 -0
- package/dist/factories/provider-factory.d.ts +72 -0
- package/dist/factories/provider-factory.js +144 -0
- package/dist/factories/provider-generate-factory.d.ts +20 -0
- package/dist/factories/provider-generate-factory.js +87 -0
- package/dist/factories/provider-registry.d.ts +38 -0
- package/dist/factories/provider-registry.js +107 -0
- package/dist/index.d.ts +8 -5
- package/dist/index.js +5 -5
- package/dist/lib/agent/direct-tools.d.ts +6 -6
- package/dist/lib/chat/sse-handler.js +5 -4
- package/dist/lib/chat/websocket-chat-handler.js +9 -9
- package/dist/lib/core/base-provider.d.ts +423 -0
- package/dist/lib/core/base-provider.js +365 -0
- package/dist/lib/core/constants.d.ts +1 -1
- package/dist/lib/core/constants.js +1 -1
- package/dist/lib/core/dynamic-models.d.ts +6 -6
- package/dist/lib/core/evaluation.d.ts +19 -80
- package/dist/lib/core/evaluation.js +185 -484
- package/dist/lib/core/factory.d.ts +3 -3
- package/dist/lib/core/factory.js +30 -91
- package/dist/lib/core/service-registry.d.ts +47 -0
- package/dist/lib/core/service-registry.js +112 -0
- package/dist/lib/core/types.d.ts +49 -49
- package/dist/lib/core/types.js +1 -0
- package/dist/lib/factories/compatibility-factory.d.ts +20 -0
- package/dist/lib/factories/compatibility-factory.js +69 -0
- package/dist/lib/factories/provider-factory.d.ts +72 -0
- package/dist/lib/factories/provider-factory.js +144 -0
- package/dist/lib/factories/provider-generate-factory.d.ts +20 -0
- package/dist/lib/factories/provider-generate-factory.js +87 -0
- package/dist/lib/factories/provider-registry.d.ts +38 -0
- package/dist/lib/factories/provider-registry.js +107 -0
- package/dist/lib/index.d.ts +8 -5
- package/dist/lib/index.js +5 -5
- package/dist/lib/mcp/client.js +5 -5
- package/dist/lib/mcp/config.js +28 -3
- package/dist/lib/mcp/dynamic-orchestrator.js +8 -8
- package/dist/lib/mcp/external-client.js +2 -2
- package/dist/lib/mcp/factory.d.ts +1 -1
- package/dist/lib/mcp/factory.js +1 -1
- package/dist/lib/mcp/function-calling.js +1 -1
- package/dist/lib/mcp/initialize-tools.d.ts +1 -1
- package/dist/lib/mcp/initialize-tools.js +45 -1
- package/dist/lib/mcp/initialize.js +16 -6
- package/dist/lib/mcp/neurolink-mcp-client.js +10 -10
- package/dist/lib/mcp/orchestrator.js +4 -4
- package/dist/lib/mcp/servers/agent/direct-tools-server.d.ts +8 -0
- package/dist/lib/mcp/servers/agent/direct-tools-server.js +109 -0
- package/dist/lib/mcp/servers/ai-providers/ai-analysis-tools.js +10 -10
- package/dist/lib/mcp/servers/ai-providers/ai-core-server.js +8 -6
- package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.d.ts +2 -2
- package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.js +16 -16
- package/dist/lib/mcp/unified-registry.d.ts +4 -0
- package/dist/lib/mcp/unified-registry.js +42 -9
- package/dist/lib/neurolink.d.ts +161 -174
- package/dist/lib/neurolink.js +723 -397
- package/dist/lib/providers/amazon-bedrock.d.ts +32 -0
- package/dist/lib/providers/amazon-bedrock.js +143 -0
- package/dist/lib/providers/analytics-helper.js +7 -4
- package/dist/lib/providers/anthropic-baseprovider.d.ts +23 -0
- package/dist/lib/providers/anthropic-baseprovider.js +114 -0
- package/dist/lib/providers/anthropic.d.ts +19 -39
- package/dist/lib/providers/anthropic.js +84 -378
- package/dist/lib/providers/azure-openai.d.ts +20 -0
- package/dist/lib/providers/azure-openai.js +89 -0
- package/dist/lib/providers/function-calling-provider.d.ts +14 -12
- package/dist/lib/providers/function-calling-provider.js +114 -64
- package/dist/lib/providers/google-ai-studio.d.ts +23 -0
- package/dist/lib/providers/google-ai-studio.js +107 -0
- package/dist/lib/providers/google-vertex.d.ts +47 -0
- package/dist/lib/providers/google-vertex.js +205 -0
- package/dist/lib/providers/huggingFace.d.ts +33 -27
- package/dist/lib/providers/huggingFace.js +103 -400
- package/dist/lib/providers/index.d.ts +9 -9
- package/dist/lib/providers/index.js +9 -9
- package/dist/lib/providers/mcp-provider.d.ts +13 -8
- package/dist/lib/providers/mcp-provider.js +63 -18
- package/dist/lib/providers/mistral.d.ts +42 -0
- package/dist/lib/providers/mistral.js +160 -0
- package/dist/lib/providers/ollama.d.ts +52 -35
- package/dist/lib/providers/ollama.js +297 -477
- package/dist/lib/providers/openAI.d.ts +21 -21
- package/dist/lib/providers/openAI.js +81 -245
- package/dist/lib/sdk/tool-extension.d.ts +181 -0
- package/dist/lib/sdk/tool-extension.js +283 -0
- package/dist/lib/sdk/tool-registration.d.ts +95 -0
- package/dist/lib/sdk/tool-registration.js +167 -0
- package/dist/lib/types/generate-types.d.ts +80 -0
- package/dist/lib/types/generate-types.js +1 -0
- package/dist/lib/types/mcp-types.d.ts +116 -0
- package/dist/lib/types/mcp-types.js +5 -0
- package/dist/lib/types/stream-types.d.ts +95 -0
- package/dist/lib/types/stream-types.js +1 -0
- package/dist/lib/types/universal-provider-options.d.ts +87 -0
- package/dist/lib/types/universal-provider-options.js +53 -0
- package/dist/lib/utils/providerUtils-fixed.js +1 -1
- package/dist/lib/utils/streaming-utils.d.ts +14 -2
- package/dist/lib/utils/streaming-utils.js +0 -3
- package/dist/mcp/client.js +5 -5
- package/dist/mcp/config.js +28 -3
- package/dist/mcp/dynamic-orchestrator.js +8 -8
- package/dist/mcp/external-client.js +2 -2
- package/dist/mcp/factory.d.ts +1 -1
- package/dist/mcp/factory.js +1 -1
- package/dist/mcp/function-calling.js +1 -1
- package/dist/mcp/initialize-tools.d.ts +1 -1
- package/dist/mcp/initialize-tools.js +45 -1
- package/dist/mcp/initialize.js +16 -6
- package/dist/mcp/neurolink-mcp-client.js +10 -10
- package/dist/mcp/orchestrator.js +4 -4
- package/dist/mcp/servers/agent/direct-tools-server.d.ts +8 -0
- package/dist/mcp/servers/agent/direct-tools-server.js +109 -0
- package/dist/mcp/servers/ai-providers/ai-analysis-tools.js +10 -10
- package/dist/mcp/servers/ai-providers/ai-core-server.js +8 -6
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.d.ts +2 -2
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.js +16 -16
- package/dist/mcp/unified-registry.d.ts +4 -0
- package/dist/mcp/unified-registry.js +42 -9
- package/dist/neurolink.d.ts +161 -174
- package/dist/neurolink.js +723 -397
- package/dist/providers/amazon-bedrock.d.ts +32 -0
- package/dist/providers/amazon-bedrock.js +143 -0
- package/dist/providers/analytics-helper.js +7 -4
- package/dist/providers/anthropic-baseprovider.d.ts +23 -0
- package/dist/providers/anthropic-baseprovider.js +114 -0
- package/dist/providers/anthropic.d.ts +19 -39
- package/dist/providers/anthropic.js +83 -377
- package/dist/providers/azure-openai.d.ts +20 -0
- package/dist/providers/azure-openai.js +89 -0
- package/dist/providers/function-calling-provider.d.ts +14 -12
- package/dist/providers/function-calling-provider.js +114 -64
- package/dist/providers/google-ai-studio.d.ts +23 -0
- package/dist/providers/google-ai-studio.js +108 -0
- package/dist/providers/google-vertex.d.ts +47 -0
- package/dist/providers/google-vertex.js +205 -0
- package/dist/providers/huggingFace.d.ts +33 -27
- package/dist/providers/huggingFace.js +102 -399
- package/dist/providers/index.d.ts +9 -9
- package/dist/providers/index.js +9 -9
- package/dist/providers/mcp-provider.d.ts +13 -8
- package/dist/providers/mcp-provider.js +63 -18
- package/dist/providers/mistral.d.ts +42 -0
- package/dist/providers/mistral.js +160 -0
- package/dist/providers/ollama.d.ts +52 -35
- package/dist/providers/ollama.js +297 -476
- package/dist/providers/openAI.d.ts +21 -21
- package/dist/providers/openAI.js +81 -246
- package/dist/sdk/tool-extension.d.ts +181 -0
- package/dist/sdk/tool-extension.js +283 -0
- package/dist/sdk/tool-registration.d.ts +95 -0
- package/dist/sdk/tool-registration.js +168 -0
- package/dist/types/generate-types.d.ts +80 -0
- package/dist/types/generate-types.js +1 -0
- package/dist/types/mcp-types.d.ts +116 -0
- package/dist/types/mcp-types.js +5 -0
- package/dist/types/stream-types.d.ts +95 -0
- package/dist/types/stream-types.js +1 -0
- package/dist/types/universal-provider-options.d.ts +87 -0
- package/dist/types/universal-provider-options.js +53 -0
- package/dist/utils/providerUtils-fixed.js +1 -1
- package/dist/utils/streaming-utils.d.ts +14 -2
- package/dist/utils/streaming-utils.js +0 -3
- package/package.json +15 -10
- package/dist/lib/providers/agent-enhanced-provider.d.ts +0 -89
- package/dist/lib/providers/agent-enhanced-provider.js +0 -614
- package/dist/lib/providers/amazonBedrock.d.ts +0 -19
- package/dist/lib/providers/amazonBedrock.js +0 -334
- package/dist/lib/providers/azureOpenAI.d.ts +0 -39
- package/dist/lib/providers/azureOpenAI.js +0 -436
- package/dist/lib/providers/googleAIStudio.d.ts +0 -49
- package/dist/lib/providers/googleAIStudio.js +0 -333
- package/dist/lib/providers/googleVertexAI.d.ts +0 -38
- package/dist/lib/providers/googleVertexAI.js +0 -519
- package/dist/lib/providers/mistralAI.d.ts +0 -34
- package/dist/lib/providers/mistralAI.js +0 -294
- package/dist/providers/agent-enhanced-provider.d.ts +0 -89
- package/dist/providers/agent-enhanced-provider.js +0 -614
- package/dist/providers/amazonBedrock.d.ts +0 -19
- package/dist/providers/amazonBedrock.js +0 -334
- package/dist/providers/azureOpenAI.d.ts +0 -39
- package/dist/providers/azureOpenAI.js +0 -437
- package/dist/providers/googleAIStudio.d.ts +0 -49
- package/dist/providers/googleAIStudio.js +0 -333
- package/dist/providers/googleVertexAI.d.ts +0 -38
- package/dist/providers/googleVertexAI.js +0 -519
- package/dist/providers/mistralAI.d.ts +0 -34
- package/dist/providers/mistralAI.js +0 -294
|
@@ -1,333 +0,0 @@
|
|
|
1
|
-
import { createGoogleGenerativeAI } from "@ai-sdk/google";
|
|
2
|
-
import { streamText, generateText, Output, } from "ai";
|
|
3
|
-
import { logger } from "../utils/logger.js";
|
|
4
|
-
import { createTimeoutController, TimeoutError, getDefaultTimeout, } from "../utils/timeout.js";
|
|
5
|
-
import { DEFAULT_MAX_TOKENS } from "../core/constants.js";
|
|
6
|
-
import { createProxyFetch } from "../proxy/proxy-fetch.js";
|
|
7
|
-
import { evaluateResponse } from "../core/evaluation.js";
|
|
8
|
-
// CRITICAL: Setup environment variables early for AI SDK compatibility
|
|
9
|
-
// The AI SDK specifically looks for GOOGLE_GENERATIVE_AI_API_KEY
|
|
10
|
-
// We need to ensure this is set before any AI SDK operations
|
|
11
|
-
if (!process.env.GOOGLE_GENERATIVE_AI_API_KEY &&
|
|
12
|
-
process.env.GOOGLE_AI_API_KEY) {
|
|
13
|
-
process.env.GOOGLE_GENERATIVE_AI_API_KEY = process.env.GOOGLE_AI_API_KEY;
|
|
14
|
-
}
|
|
15
|
-
// Default system context
|
|
16
|
-
const DEFAULT_SYSTEM_CONTEXT = {
|
|
17
|
-
systemPrompt: "You are a helpful AI assistant.",
|
|
18
|
-
};
|
|
19
|
-
// Configuration helpers
|
|
20
|
-
const getGoogleAIApiKey = () => {
|
|
21
|
-
// Check for both possible environment variables
|
|
22
|
-
const apiKey = process.env.GOOGLE_AI_API_KEY || process.env.GOOGLE_GENERATIVE_AI_API_KEY;
|
|
23
|
-
if (!apiKey) {
|
|
24
|
-
throw new Error("GOOGLE_AI_API_KEY or GOOGLE_GENERATIVE_AI_API_KEY environment variable is not set");
|
|
25
|
-
}
|
|
26
|
-
// Ensure GOOGLE_GENERATIVE_AI_API_KEY is set for @ai-sdk/google compatibility
|
|
27
|
-
// The AI SDK specifically looks for this variable name
|
|
28
|
-
if (!process.env.GOOGLE_GENERATIVE_AI_API_KEY &&
|
|
29
|
-
process.env.GOOGLE_AI_API_KEY) {
|
|
30
|
-
process.env.GOOGLE_GENERATIVE_AI_API_KEY = process.env.GOOGLE_AI_API_KEY;
|
|
31
|
-
}
|
|
32
|
-
return apiKey;
|
|
33
|
-
};
|
|
34
|
-
const getGoogleAIModelId = () => {
|
|
35
|
-
return process.env.GOOGLE_AI_MODEL || "gemini-2.5-pro";
|
|
36
|
-
};
|
|
37
|
-
const hasValidAuth = () => {
|
|
38
|
-
return !!(process.env.GOOGLE_AI_API_KEY || process.env.GOOGLE_GENERATIVE_AI_API_KEY);
|
|
39
|
-
};
|
|
40
|
-
// Lazy initialization cache
|
|
41
|
-
let _google = null;
|
|
42
|
-
function getGoogleInstance() {
|
|
43
|
-
if (!_google) {
|
|
44
|
-
const apiKey = getGoogleAIApiKey();
|
|
45
|
-
const proxyFetch = createProxyFetch();
|
|
46
|
-
_google = createGoogleGenerativeAI({
|
|
47
|
-
apiKey: apiKey,
|
|
48
|
-
fetch: proxyFetch,
|
|
49
|
-
headers: {
|
|
50
|
-
"X-Powered-By": "NeuroLink",
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
return _google;
|
|
55
|
-
}
|
|
56
|
-
// Google AI Studio class with enhanced error handling
|
|
57
|
-
export class GoogleAIStudio {
|
|
58
|
-
modelName;
|
|
59
|
-
/**
|
|
60
|
-
* Initializes a new instance of GoogleAIStudio
|
|
61
|
-
* @param modelName - Optional model name to override the default from config
|
|
62
|
-
*/
|
|
63
|
-
constructor(modelName) {
|
|
64
|
-
const functionTag = "GoogleAIStudio.constructor";
|
|
65
|
-
this.modelName = modelName || getGoogleAIModelId();
|
|
66
|
-
try {
|
|
67
|
-
logger.debug(`[${functionTag}] Initialization started`, {
|
|
68
|
-
modelName: this.modelName,
|
|
69
|
-
hasApiKey: hasValidAuth(),
|
|
70
|
-
});
|
|
71
|
-
logger.debug(`[${functionTag}] Initialization completed`, {
|
|
72
|
-
modelName: this.modelName,
|
|
73
|
-
success: true,
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
catch (err) {
|
|
77
|
-
logger.error(`[${functionTag}] Initialization failed`, {
|
|
78
|
-
message: "Error in initializing Google AI Studio",
|
|
79
|
-
modelName: this.modelName,
|
|
80
|
-
error: err instanceof Error ? err.message : String(err),
|
|
81
|
-
stack: err instanceof Error ? err.stack : undefined,
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Gets the appropriate model instance
|
|
87
|
-
* Made public to support FunctionCallingProvider integration
|
|
88
|
-
*/
|
|
89
|
-
getModel() {
|
|
90
|
-
logger.debug("GoogleAIStudio.getModel - Google AI model selected", {
|
|
91
|
-
modelName: this.modelName,
|
|
92
|
-
});
|
|
93
|
-
const google = getGoogleInstance();
|
|
94
|
-
return google(this.modelName);
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Expose model property for FunctionCallingProvider
|
|
98
|
-
* This allows the enhanced provider to access the underlying model
|
|
99
|
-
*/
|
|
100
|
-
get model() {
|
|
101
|
-
return this.getModel();
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Processes text using streaming approach with enhanced error handling callbacks
|
|
105
|
-
* @param prompt - The input text prompt to analyze
|
|
106
|
-
* @param analysisSchema - Optional Zod schema or Schema object for output validation
|
|
107
|
-
* @returns Promise resolving to StreamTextResult or null if operation fails
|
|
108
|
-
*/
|
|
109
|
-
async streamText(optionsOrPrompt, analysisSchema) {
|
|
110
|
-
const functionTag = "GoogleAIStudio.streamText";
|
|
111
|
-
const provider = "google-ai";
|
|
112
|
-
let chunkCount = 0;
|
|
113
|
-
try {
|
|
114
|
-
// Parse parameters - support both string and options object
|
|
115
|
-
const options = typeof optionsOrPrompt === "string"
|
|
116
|
-
? { prompt: optionsOrPrompt }
|
|
117
|
-
: optionsOrPrompt;
|
|
118
|
-
const { prompt, temperature = 0.7, maxTokens = DEFAULT_MAX_TOKENS, systemPrompt = DEFAULT_SYSTEM_CONTEXT.systemPrompt, schema, tools, timeout = getDefaultTimeout(provider, "stream"), } = options;
|
|
119
|
-
// Use schema from options or fallback parameter
|
|
120
|
-
const finalSchema = schema || analysisSchema;
|
|
121
|
-
logger.debug(`[${functionTag}] Stream request started`, {
|
|
122
|
-
provider,
|
|
123
|
-
modelName: this.modelName,
|
|
124
|
-
promptLength: prompt.length,
|
|
125
|
-
temperature,
|
|
126
|
-
maxTokens,
|
|
127
|
-
hasSchema: !!finalSchema,
|
|
128
|
-
hasTools: !!tools,
|
|
129
|
-
toolCount: tools ? Object.keys(tools).length : 0,
|
|
130
|
-
timeout,
|
|
131
|
-
});
|
|
132
|
-
const model = this.getModel();
|
|
133
|
-
// Create timeout controller if timeout is specified
|
|
134
|
-
const timeoutController = createTimeoutController(timeout, provider, "stream");
|
|
135
|
-
const streamOptions = {
|
|
136
|
-
model: model,
|
|
137
|
-
prompt: prompt,
|
|
138
|
-
system: systemPrompt,
|
|
139
|
-
temperature,
|
|
140
|
-
maxTokens,
|
|
141
|
-
...(tools && { tools }), // Add tools if provided
|
|
142
|
-
// Add abort signal if available
|
|
143
|
-
...(timeoutController && {
|
|
144
|
-
abortSignal: timeoutController.controller.signal,
|
|
145
|
-
}),
|
|
146
|
-
onError: (event) => {
|
|
147
|
-
const error = event.error;
|
|
148
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
149
|
-
const errorStack = error instanceof Error ? error.stack : undefined;
|
|
150
|
-
logger.error(`[${functionTag}] Stream text error`, {
|
|
151
|
-
provider,
|
|
152
|
-
modelName: this.modelName,
|
|
153
|
-
error: errorMessage,
|
|
154
|
-
stack: errorStack,
|
|
155
|
-
promptLength: prompt.length,
|
|
156
|
-
chunkCount,
|
|
157
|
-
});
|
|
158
|
-
},
|
|
159
|
-
onFinish: (event) => {
|
|
160
|
-
logger.debug(`[${functionTag}] Stream text finished`, {
|
|
161
|
-
provider,
|
|
162
|
-
modelName: this.modelName,
|
|
163
|
-
finishReason: event.finishReason,
|
|
164
|
-
usage: event.usage,
|
|
165
|
-
totalChunks: chunkCount,
|
|
166
|
-
promptLength: prompt.length,
|
|
167
|
-
responseLength: event.text?.length || 0,
|
|
168
|
-
});
|
|
169
|
-
},
|
|
170
|
-
onChunk: (event) => {
|
|
171
|
-
chunkCount++;
|
|
172
|
-
logger.debug(`[${functionTag}] Stream text chunk`, {
|
|
173
|
-
provider,
|
|
174
|
-
modelName: this.modelName,
|
|
175
|
-
chunkNumber: chunkCount,
|
|
176
|
-
chunkLength: event.chunk.text?.length || 0,
|
|
177
|
-
chunkType: event.chunk.type,
|
|
178
|
-
});
|
|
179
|
-
},
|
|
180
|
-
};
|
|
181
|
-
if (analysisSchema) {
|
|
182
|
-
streamOptions.experimental_output = Output.object({
|
|
183
|
-
schema: analysisSchema,
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
const result = streamText(streamOptions);
|
|
187
|
-
// For streaming, we can't clean up immediately, but the timeout will auto-clean
|
|
188
|
-
// The user should handle the stream and any timeout errors
|
|
189
|
-
return result;
|
|
190
|
-
}
|
|
191
|
-
catch (err) {
|
|
192
|
-
// Log timeout errors specifically
|
|
193
|
-
if (err instanceof TimeoutError) {
|
|
194
|
-
logger.error(`[${functionTag}] Timeout error`, {
|
|
195
|
-
provider,
|
|
196
|
-
modelName: this.modelName,
|
|
197
|
-
timeout: err.timeout,
|
|
198
|
-
message: err.message,
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
else {
|
|
202
|
-
logger.error(`[${functionTag}] Exception`, {
|
|
203
|
-
provider,
|
|
204
|
-
modelName: this.modelName,
|
|
205
|
-
message: "Error in streaming text",
|
|
206
|
-
err: String(err),
|
|
207
|
-
promptLength: typeof optionsOrPrompt === "string"
|
|
208
|
-
? optionsOrPrompt.length
|
|
209
|
-
: optionsOrPrompt.prompt.length,
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
throw err; // Re-throw error to trigger fallback
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Processes text using non-streaming approach with optional schema validation
|
|
217
|
-
* @param prompt - The input text prompt to analyze
|
|
218
|
-
* @param analysisSchema - Optional Zod schema or Schema object for output validation
|
|
219
|
-
* @returns Promise resolving to GenerateTextResult or null if operation fails
|
|
220
|
-
*/
|
|
221
|
-
async generateText(optionsOrPrompt, analysisSchema) {
|
|
222
|
-
const functionTag = "GoogleAIStudio.generateText";
|
|
223
|
-
const provider = "google-ai";
|
|
224
|
-
const startTime = Date.now();
|
|
225
|
-
try {
|
|
226
|
-
// Parse parameters - support both string and options object
|
|
227
|
-
const options = typeof optionsOrPrompt === "string"
|
|
228
|
-
? { prompt: optionsOrPrompt }
|
|
229
|
-
: optionsOrPrompt;
|
|
230
|
-
const { prompt, temperature = 0.7, maxTokens = DEFAULT_MAX_TOKENS, systemPrompt = DEFAULT_SYSTEM_CONTEXT.systemPrompt, schema, tools, timeout = getDefaultTimeout(provider, "generate"), } = options;
|
|
231
|
-
// Use schema from options or fallback parameter
|
|
232
|
-
const finalSchema = schema || analysisSchema;
|
|
233
|
-
logger.debug(`[${functionTag}] Generate request started`, {
|
|
234
|
-
provider,
|
|
235
|
-
modelName: this.modelName,
|
|
236
|
-
promptLength: prompt.length,
|
|
237
|
-
temperature,
|
|
238
|
-
maxTokens,
|
|
239
|
-
hasTools: !!tools,
|
|
240
|
-
toolCount: tools ? Object.keys(tools).length : 0,
|
|
241
|
-
timeout,
|
|
242
|
-
});
|
|
243
|
-
const model = this.getModel();
|
|
244
|
-
// Create timeout controller if timeout is specified
|
|
245
|
-
const timeoutController = createTimeoutController(timeout, provider, "generate");
|
|
246
|
-
const generateOptions = {
|
|
247
|
-
model: model,
|
|
248
|
-
prompt: prompt,
|
|
249
|
-
system: systemPrompt,
|
|
250
|
-
temperature,
|
|
251
|
-
maxTokens,
|
|
252
|
-
...(tools && {
|
|
253
|
-
tools,
|
|
254
|
-
maxSteps: 5, // Allow multiple steps for tool execution and response generation
|
|
255
|
-
}), // Add tools if provided
|
|
256
|
-
// Add abort signal if available
|
|
257
|
-
...(timeoutController && {
|
|
258
|
-
abortSignal: timeoutController.controller.signal,
|
|
259
|
-
}),
|
|
260
|
-
};
|
|
261
|
-
if (finalSchema) {
|
|
262
|
-
generateOptions.experimental_output = Output.object({
|
|
263
|
-
schema: finalSchema,
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
try {
|
|
267
|
-
const result = await generateText(generateOptions);
|
|
268
|
-
// Clean up timeout if successful
|
|
269
|
-
timeoutController?.cleanup();
|
|
270
|
-
logger.debug(`[${functionTag}] Generate text completed`, {
|
|
271
|
-
provider,
|
|
272
|
-
modelName: this.modelName,
|
|
273
|
-
usage: result.usage,
|
|
274
|
-
finishReason: result.finishReason,
|
|
275
|
-
responseLength: result.text?.length || 0,
|
|
276
|
-
timeout,
|
|
277
|
-
});
|
|
278
|
-
// Add analytics if enabled
|
|
279
|
-
if (options.enableAnalytics) {
|
|
280
|
-
const { createAnalytics } = await import("./analytics-helper.js");
|
|
281
|
-
result.analytics = createAnalytics(provider, this.modelName, result, Date.now() - startTime, options.context);
|
|
282
|
-
}
|
|
283
|
-
// Add evaluation if enabled
|
|
284
|
-
if (options.enableEvaluation) {
|
|
285
|
-
result.evaluation = await evaluateResponse(prompt, result.text, options.context, options.evaluationDomain, options.toolUsageContext, options.conversationHistory);
|
|
286
|
-
}
|
|
287
|
-
return result;
|
|
288
|
-
}
|
|
289
|
-
finally {
|
|
290
|
-
// Always cleanup timeout
|
|
291
|
-
timeoutController?.cleanup();
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
catch (err) {
|
|
295
|
-
// Log timeout errors specifically
|
|
296
|
-
if (err instanceof TimeoutError) {
|
|
297
|
-
logger.error(`[${functionTag}] Timeout error`, {
|
|
298
|
-
provider,
|
|
299
|
-
modelName: this.modelName,
|
|
300
|
-
timeout: err.timeout,
|
|
301
|
-
message: err.message,
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
else {
|
|
305
|
-
logger.error(`[${functionTag}] Exception`, {
|
|
306
|
-
provider,
|
|
307
|
-
modelName: this.modelName,
|
|
308
|
-
message: "Error in generating text",
|
|
309
|
-
err: String(err),
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
throw err; // Re-throw error to trigger fallback
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* Alias for generateText() - CLI-SDK consistency
|
|
317
|
-
* @param optionsOrPrompt - TextGenerationOptions object or prompt string
|
|
318
|
-
* @param analysisSchema - Optional schema for output validation
|
|
319
|
-
* @returns Promise resolving to GenerateTextResult or null
|
|
320
|
-
*/
|
|
321
|
-
async generate(optionsOrPrompt, analysisSchema) {
|
|
322
|
-
return this.generateText(optionsOrPrompt, analysisSchema);
|
|
323
|
-
}
|
|
324
|
-
/**
|
|
325
|
-
* Short alias for generateText() - CLI-SDK consistency
|
|
326
|
-
* @param optionsOrPrompt - TextGenerationOptions object or prompt string
|
|
327
|
-
* @param analysisSchema - Optional schema for output validation
|
|
328
|
-
* @returns Promise resolving to GenerateTextResult or null
|
|
329
|
-
*/
|
|
330
|
-
async gen(optionsOrPrompt, analysisSchema) {
|
|
331
|
-
return this.generateText(optionsOrPrompt, analysisSchema);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { ZodType, ZodTypeDef } from "zod";
|
|
2
|
-
import { type StreamTextResult, type ToolSet, type Schema, type GenerateTextResult } from "ai";
|
|
3
|
-
import type { AIProvider, TextGenerationOptions, StreamTextOptions, EnhancedGenerateTextResult } from "../core/types.js";
|
|
4
|
-
export declare class GoogleVertexAI implements AIProvider {
|
|
5
|
-
private modelName;
|
|
6
|
-
/**
|
|
7
|
-
* Initializes a new instance of GoogleVertexAI
|
|
8
|
-
* @param modelName - Optional model name to override the default from config
|
|
9
|
-
*/
|
|
10
|
-
constructor(modelName?: string | null);
|
|
11
|
-
/**
|
|
12
|
-
* Gets the appropriate model instance (Google or Anthropic)
|
|
13
|
-
* @private
|
|
14
|
-
*/
|
|
15
|
-
private getModel;
|
|
16
|
-
/**
|
|
17
|
-
* Processes text using streaming approach with enhanced error handling callbacks
|
|
18
|
-
* @param prompt - The input text prompt to analyze
|
|
19
|
-
* @param analysisSchema - Optional Zod schema or Schema object for output validation
|
|
20
|
-
* @returns Promise resolving to StreamTextResult or null if operation fails
|
|
21
|
-
*/
|
|
22
|
-
streamText(optionsOrPrompt: StreamTextOptions | string, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<StreamTextResult<ToolSet, unknown> | null>;
|
|
23
|
-
/**
|
|
24
|
-
* Processes text using non-streaming approach with optional schema validation
|
|
25
|
-
* @param prompt - The input text prompt to analyze
|
|
26
|
-
* @param analysisSchema - Optional Zod schema or Schema object for output validation
|
|
27
|
-
* @returns Promise resolving to GenerateTextResult or null if operation fails
|
|
28
|
-
*/
|
|
29
|
-
generateText(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<GenerateTextResult<ToolSet, unknown> | null>;
|
|
30
|
-
/**
|
|
31
|
-
* Alias for generateText() - CLI-SDK consistency
|
|
32
|
-
*/
|
|
33
|
-
generate(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<EnhancedGenerateTextResult | null>;
|
|
34
|
-
/**
|
|
35
|
-
* Short alias for generateText() - CLI-SDK consistency
|
|
36
|
-
*/
|
|
37
|
-
gen(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<EnhancedGenerateTextResult | null>;
|
|
38
|
-
}
|