@juspay/neurolink 5.1.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 +15 -9
- package/README.md +123 -126
- package/dist/agent/direct-tools.d.ts +6 -6
- package/dist/cli/commands/config.d.ts +3 -3
- package/dist/cli/commands/mcp.js +8 -7
- package/dist/cli/factories/command-factory.d.ts +4 -0
- package/dist/cli/factories/command-factory.js +57 -3
- package/dist/cli/index.js +87 -140
- 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 +8 -1
- package/dist/factories/compatibility-factory.js +1 -1
- package/dist/factories/provider-factory.d.ts +72 -0
- package/dist/factories/provider-factory.js +144 -0
- package/dist/factories/provider-registry.d.ts +38 -0
- package/dist/factories/provider-registry.js +107 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +2 -4
- package/dist/lib/agent/direct-tools.d.ts +6 -6
- 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 +8 -1
- package/dist/lib/factories/compatibility-factory.js +1 -1
- package/dist/lib/factories/provider-factory.d.ts +72 -0
- package/dist/lib/factories/provider-factory.js +144 -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 +4 -3
- package/dist/lib/index.js +2 -4
- package/dist/lib/mcp/config.js +28 -3
- 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/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-core-server.js +3 -1
- package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.d.ts +2 -2
- 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 +156 -117
- package/dist/lib/neurolink.js +619 -404
- 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 -43
- package/dist/lib/providers/anthropic.js +82 -306
- package/dist/lib/providers/azure-openai.d.ts +20 -0
- package/dist/lib/providers/azure-openai.js +89 -0
- 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 +32 -25
- package/dist/lib/providers/huggingFace.js +97 -431
- package/dist/lib/providers/index.d.ts +9 -9
- package/dist/lib/providers/index.js +9 -9
- package/dist/lib/providers/mcp-provider.js +4 -0
- 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 -36
- package/dist/lib/providers/ollama.js +297 -520
- package/dist/lib/providers/openAI.d.ts +19 -18
- package/dist/lib/providers/openAI.js +76 -275
- 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 +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 +30 -18
- package/dist/lib/types/universal-provider-options.d.ts +87 -0
- package/dist/lib/types/universal-provider-options.js +53 -0
- package/dist/mcp/config.js +28 -3
- 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/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-core-server.js +3 -1
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.d.ts +2 -2
- package/dist/mcp/unified-registry.d.ts +4 -0
- package/dist/mcp/unified-registry.js +42 -9
- package/dist/neurolink.d.ts +156 -117
- package/dist/neurolink.js +619 -404
- 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 -43
- package/dist/providers/anthropic.js +81 -305
- package/dist/providers/azure-openai.d.ts +20 -0
- package/dist/providers/azure-openai.js +89 -0
- 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 +32 -25
- package/dist/providers/huggingFace.js +96 -430
- package/dist/providers/index.d.ts +9 -9
- package/dist/providers/index.js +9 -9
- package/dist/providers/mcp-provider.js +4 -0
- package/dist/providers/mistral.d.ts +42 -0
- package/dist/providers/mistral.js +160 -0
- package/dist/providers/ollama.d.ts +52 -36
- package/dist/providers/ollama.js +297 -519
- package/dist/providers/openAI.d.ts +19 -18
- package/dist/providers/openAI.js +76 -276
- 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 +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 +30 -18
- package/dist/types/universal-provider-options.d.ts +87 -0
- package/dist/types/universal-provider-options.js +53 -0
- package/package.json +15 -10
- package/dist/lib/providers/agent-enhanced-provider.d.ts +0 -93
- package/dist/lib/providers/agent-enhanced-provider.js +0 -605
- package/dist/lib/providers/amazonBedrock.d.ts +0 -28
- package/dist/lib/providers/amazonBedrock.js +0 -364
- package/dist/lib/providers/azureOpenAI.d.ts +0 -42
- package/dist/lib/providers/azureOpenAI.js +0 -347
- package/dist/lib/providers/googleAIStudio.d.ts +0 -42
- package/dist/lib/providers/googleAIStudio.js +0 -364
- package/dist/lib/providers/googleVertexAI.d.ts +0 -34
- package/dist/lib/providers/googleVertexAI.js +0 -547
- package/dist/lib/providers/mistralAI.d.ts +0 -37
- package/dist/lib/providers/mistralAI.js +0 -325
- package/dist/providers/agent-enhanced-provider.d.ts +0 -93
- package/dist/providers/agent-enhanced-provider.js +0 -606
- package/dist/providers/amazonBedrock.d.ts +0 -28
- package/dist/providers/amazonBedrock.js +0 -364
- package/dist/providers/azureOpenAI.d.ts +0 -42
- package/dist/providers/azureOpenAI.js +0 -348
- package/dist/providers/googleAIStudio.d.ts +0 -42
- package/dist/providers/googleAIStudio.js +0 -364
- package/dist/providers/googleVertexAI.d.ts +0 -34
- package/dist/providers/googleVertexAI.js +0 -547
- package/dist/providers/mistralAI.d.ts +0 -37
- package/dist/providers/mistralAI.js +0 -325
|
@@ -1,364 +0,0 @@
|
|
|
1
|
-
import { createAmazonBedrock } from "@ai-sdk/amazon-bedrock";
|
|
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 { evaluateResponse } from "../core/evaluation.js";
|
|
7
|
-
import { createAnalytics } from "../core/analytics.js";
|
|
8
|
-
// Default system context
|
|
9
|
-
const DEFAULT_SYSTEM_CONTEXT = {
|
|
10
|
-
systemPrompt: "You are a helpful AI assistant.",
|
|
11
|
-
};
|
|
12
|
-
// Configuration helpers
|
|
13
|
-
const getBedrockModelId = () => {
|
|
14
|
-
return (process.env.BEDROCK_MODEL ||
|
|
15
|
-
process.env.BEDROCK_MODEL_ID ||
|
|
16
|
-
"arn:aws:bedrock:us-east-2:225681119357:inference-profile/us.anthropic.claude-3-7-sonnet-20250219-v1:0");
|
|
17
|
-
};
|
|
18
|
-
const getAWSAccessKeyId = () => {
|
|
19
|
-
const keyId = process.env.AWS_ACCESS_KEY_ID;
|
|
20
|
-
if (!keyId) {
|
|
21
|
-
throw new Error("AWS_ACCESS_KEY_ID environment variable is not set");
|
|
22
|
-
}
|
|
23
|
-
return keyId;
|
|
24
|
-
};
|
|
25
|
-
const getAWSSecretAccessKey = () => {
|
|
26
|
-
const secretKey = process.env.AWS_SECRET_ACCESS_KEY;
|
|
27
|
-
if (!secretKey) {
|
|
28
|
-
throw new Error("AWS_SECRET_ACCESS_KEY environment variable is not set");
|
|
29
|
-
}
|
|
30
|
-
return secretKey;
|
|
31
|
-
};
|
|
32
|
-
const getAWSRegion = () => {
|
|
33
|
-
return process.env.AWS_REGION || "us-east-2";
|
|
34
|
-
};
|
|
35
|
-
const getAWSSessionToken = () => {
|
|
36
|
-
return process.env.AWS_SESSION_TOKEN;
|
|
37
|
-
};
|
|
38
|
-
const getAppEnvironment = () => {
|
|
39
|
-
return process.env.PUBLIC_APP_ENVIRONMENT || "dev";
|
|
40
|
-
};
|
|
41
|
-
// Amazon Bedrock class with enhanced error handling using createAmazonBedrock
|
|
42
|
-
export class AmazonBedrock {
|
|
43
|
-
modelName;
|
|
44
|
-
model;
|
|
45
|
-
bedrock;
|
|
46
|
-
constructor(modelName) {
|
|
47
|
-
const functionTag = "AmazonBedrock.constructor";
|
|
48
|
-
this.modelName = modelName || getBedrockModelId();
|
|
49
|
-
try {
|
|
50
|
-
logger.debug(`[${functionTag}] Function called`, {
|
|
51
|
-
modelName: this.modelName,
|
|
52
|
-
envBedrockModel: process.env.BEDROCK_MODEL,
|
|
53
|
-
envBedrockModelId: process.env.BEDROCK_MODEL_ID,
|
|
54
|
-
fallbackModel: "arn:aws:bedrock:us-east-2:225681119357:inference-profile/us.anthropic.claude-3-7-sonnet-20250219-v1:0",
|
|
55
|
-
});
|
|
56
|
-
// Configure AWS credentials for custom Bedrock instance
|
|
57
|
-
const awsConfig = {
|
|
58
|
-
accessKeyId: getAWSAccessKeyId(),
|
|
59
|
-
secretAccessKey: getAWSSecretAccessKey(),
|
|
60
|
-
region: getAWSRegion(),
|
|
61
|
-
};
|
|
62
|
-
logger.debug(`[${functionTag}] AWS config validation`, {
|
|
63
|
-
hasAccessKeyId: !!awsConfig.accessKeyId,
|
|
64
|
-
hasSecretAccessKey: !!awsConfig.secretAccessKey,
|
|
65
|
-
region: awsConfig.region || "MISSING",
|
|
66
|
-
accessKeyIdLength: awsConfig.accessKeyId?.length || 0,
|
|
67
|
-
hasSessionToken: !!process.env.AWS_SESSION_TOKEN,
|
|
68
|
-
});
|
|
69
|
-
// Add session token for development environment
|
|
70
|
-
if (getAppEnvironment() === "dev") {
|
|
71
|
-
const sessionToken = getAWSSessionToken();
|
|
72
|
-
if (sessionToken) {
|
|
73
|
-
awsConfig.sessionToken = sessionToken;
|
|
74
|
-
logger.debug(`[${functionTag}] Session token added`, {
|
|
75
|
-
environment: "dev",
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
logger.warn(`[${functionTag}] Session token missing`, {
|
|
80
|
-
environment: "dev",
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
logger.debug(`[${functionTag}] AWS config created`, {
|
|
85
|
-
region: awsConfig.region,
|
|
86
|
-
hasSessionToken: !!awsConfig.sessionToken,
|
|
87
|
-
});
|
|
88
|
-
logger.debug(`[${functionTag}] Bedrock provider creating`, {
|
|
89
|
-
modelName: this.modelName,
|
|
90
|
-
});
|
|
91
|
-
// Create custom Bedrock provider instance with environment-based configuration
|
|
92
|
-
this.bedrock = createAmazonBedrock(awsConfig);
|
|
93
|
-
logger.debug(`[${functionTag}] Bedrock provider initialized`, {
|
|
94
|
-
modelName: this.modelName,
|
|
95
|
-
});
|
|
96
|
-
logger.debug(`[${functionTag}] Model instance creating`, {
|
|
97
|
-
modelName: this.modelName,
|
|
98
|
-
});
|
|
99
|
-
this.model = this.bedrock(this.modelName);
|
|
100
|
-
logger.debug(`[${functionTag}] Model instance created`, {
|
|
101
|
-
modelName: this.modelName,
|
|
102
|
-
});
|
|
103
|
-
logger.debug(`[${functionTag}] Function result`, {
|
|
104
|
-
modelName: this.modelName,
|
|
105
|
-
region: awsConfig.region,
|
|
106
|
-
hasSessionToken: !!awsConfig.sessionToken,
|
|
107
|
-
success: true,
|
|
108
|
-
});
|
|
109
|
-
logger.debug(`[${functionTag}] Initialization completed`, {
|
|
110
|
-
modelName: this.modelName,
|
|
111
|
-
region: awsConfig.region,
|
|
112
|
-
hasSessionToken: !!awsConfig.sessionToken,
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
catch (err) {
|
|
116
|
-
logger.error(`[${functionTag}] Initialization failed`, {
|
|
117
|
-
message: "Error in initializing Amazon Bedrock",
|
|
118
|
-
modelName: this.modelName,
|
|
119
|
-
region: getAWSRegion(),
|
|
120
|
-
error: err instanceof Error ? err.message : String(err),
|
|
121
|
-
stack: err instanceof Error ? err.stack : undefined,
|
|
122
|
-
});
|
|
123
|
-
throw err;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* LEGACY METHOD: Use stream() instead for new code
|
|
128
|
-
* @deprecated Use stream() method instead
|
|
129
|
-
*/
|
|
130
|
-
/**
|
|
131
|
-
* PRIMARY METHOD: Stream content using AI (recommended for new code)
|
|
132
|
-
* Future-ready for multi-modal capabilities with current text focus
|
|
133
|
-
*/
|
|
134
|
-
async stream(optionsOrPrompt, analysisSchema) {
|
|
135
|
-
const functionTag = "AmazonBedrock.stream";
|
|
136
|
-
const provider = "bedrock";
|
|
137
|
-
let chunkCount = 0;
|
|
138
|
-
const startTime = Date.now();
|
|
139
|
-
try {
|
|
140
|
-
// Parse parameters - support both string and options object
|
|
141
|
-
const options = typeof optionsOrPrompt === "string"
|
|
142
|
-
? { input: { text: optionsOrPrompt } }
|
|
143
|
-
: optionsOrPrompt;
|
|
144
|
-
// Validate input
|
|
145
|
-
if (!options?.input?.text ||
|
|
146
|
-
typeof options.input.text !== "string" ||
|
|
147
|
-
options.input.text.trim() === "") {
|
|
148
|
-
throw new Error("Stream options must include input.text as a non-empty string");
|
|
149
|
-
}
|
|
150
|
-
// Extract prompt and other parameters
|
|
151
|
-
const { prompt = options.input.text, temperature = 0.7, maxTokens = DEFAULT_MAX_TOKENS, systemPrompt = DEFAULT_SYSTEM_CONTEXT.systemPrompt, schema, timeout = getDefaultTimeout(provider, "stream"), } = options;
|
|
152
|
-
// Use schema from options or fallback parameter
|
|
153
|
-
const finalSchema = schema || analysisSchema;
|
|
154
|
-
logger.debug(`[${functionTag}] Stream request started`, {
|
|
155
|
-
provider,
|
|
156
|
-
modelName: this.modelName,
|
|
157
|
-
promptLength: prompt?.length || 0,
|
|
158
|
-
temperature,
|
|
159
|
-
maxTokens,
|
|
160
|
-
timeout,
|
|
161
|
-
});
|
|
162
|
-
// Create timeout controller if timeout is specified
|
|
163
|
-
const timeoutController = createTimeoutController(timeout, provider, "stream");
|
|
164
|
-
const streamOptions = {
|
|
165
|
-
model: this.model,
|
|
166
|
-
prompt: prompt,
|
|
167
|
-
system: systemPrompt,
|
|
168
|
-
temperature,
|
|
169
|
-
maxTokens,
|
|
170
|
-
// Add abort signal if available
|
|
171
|
-
...(timeoutController && {
|
|
172
|
-
abortSignal: timeoutController.controller.signal,
|
|
173
|
-
}),
|
|
174
|
-
onError: (event) => {
|
|
175
|
-
const error = event.error;
|
|
176
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
177
|
-
const errorStack = error instanceof Error ? error.stack : undefined;
|
|
178
|
-
logger.debug(`[${functionTag}] Stream error`, {
|
|
179
|
-
provider,
|
|
180
|
-
modelName: this.modelName,
|
|
181
|
-
error: errorMessage,
|
|
182
|
-
stack: errorStack,
|
|
183
|
-
promptLength: prompt.length,
|
|
184
|
-
chunkCount,
|
|
185
|
-
});
|
|
186
|
-
},
|
|
187
|
-
onFinish: (event) => {
|
|
188
|
-
logger.debug(`[${functionTag}] Stream finished`, {
|
|
189
|
-
provider,
|
|
190
|
-
modelName: this.modelName,
|
|
191
|
-
finishReason: event.finishReason,
|
|
192
|
-
usage: event.usage,
|
|
193
|
-
totalChunks: chunkCount,
|
|
194
|
-
promptLength: prompt.length,
|
|
195
|
-
responseLength: event.text?.length || 0,
|
|
196
|
-
});
|
|
197
|
-
},
|
|
198
|
-
onChunk: (event) => {
|
|
199
|
-
chunkCount++;
|
|
200
|
-
logger.debug(`[${functionTag}] Stream chunk`, {
|
|
201
|
-
provider,
|
|
202
|
-
modelName: this.modelName,
|
|
203
|
-
chunkNumber: chunkCount,
|
|
204
|
-
chunkLength: event.chunk.text?.length || 0,
|
|
205
|
-
chunkType: event.chunk.type,
|
|
206
|
-
});
|
|
207
|
-
},
|
|
208
|
-
};
|
|
209
|
-
if (finalSchema) {
|
|
210
|
-
streamOptions.experimental_output = Output.object({
|
|
211
|
-
schema: finalSchema,
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
const result = streamText(streamOptions);
|
|
215
|
-
logger.debug(`[${functionTag}] Stream request completed`, {
|
|
216
|
-
provider,
|
|
217
|
-
modelName: this.modelName,
|
|
218
|
-
});
|
|
219
|
-
// Convert to StreamResult format
|
|
220
|
-
return {
|
|
221
|
-
stream: (async function* () {
|
|
222
|
-
for await (const chunk of result.textStream) {
|
|
223
|
-
yield { content: chunk };
|
|
224
|
-
}
|
|
225
|
-
})(),
|
|
226
|
-
provider: "bedrock",
|
|
227
|
-
model: this.modelName,
|
|
228
|
-
metadata: {
|
|
229
|
-
streamId: `bedrock-${Date.now()}`,
|
|
230
|
-
startTime,
|
|
231
|
-
},
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
catch (err) {
|
|
235
|
-
// Log timeout errors specifically
|
|
236
|
-
if (err instanceof TimeoutError) {
|
|
237
|
-
logger.debug(`[${functionTag}] Timeout error`, {
|
|
238
|
-
provider,
|
|
239
|
-
modelName: this.modelName,
|
|
240
|
-
timeout: err.timeout,
|
|
241
|
-
message: err.message,
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
else {
|
|
245
|
-
logger.debug(`[${functionTag}] Exception`, {
|
|
246
|
-
provider,
|
|
247
|
-
modelName: this.modelName,
|
|
248
|
-
message: "Error in streaming content",
|
|
249
|
-
err: String(err),
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
throw err; // Re-throw error to trigger fallback
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
async generate(optionsOrPrompt, analysisSchema) {
|
|
256
|
-
const functionTag = "AmazonBedrock.generate";
|
|
257
|
-
const provider = "bedrock";
|
|
258
|
-
const startTime = Date.now();
|
|
259
|
-
try {
|
|
260
|
-
// Parse parameters - support both string and options object
|
|
261
|
-
const options = typeof optionsOrPrompt === "string"
|
|
262
|
-
? { prompt: optionsOrPrompt }
|
|
263
|
-
: optionsOrPrompt;
|
|
264
|
-
const { prompt, temperature = 0.7, maxTokens = DEFAULT_MAX_TOKENS, systemPrompt = DEFAULT_SYSTEM_CONTEXT.systemPrompt, schema, timeout = getDefaultTimeout(provider, "generate"), } = options;
|
|
265
|
-
// Use schema from options or fallback parameter
|
|
266
|
-
const finalSchema = schema || analysisSchema;
|
|
267
|
-
logger.debug(`[${functionTag}] Generate text started`, {
|
|
268
|
-
provider,
|
|
269
|
-
modelName: this.modelName,
|
|
270
|
-
region: getAWSRegion(),
|
|
271
|
-
promptLength: prompt.length,
|
|
272
|
-
temperature,
|
|
273
|
-
maxTokens,
|
|
274
|
-
timeout,
|
|
275
|
-
});
|
|
276
|
-
// Create timeout controller if timeout is specified
|
|
277
|
-
const timeoutController = createTimeoutController(timeout, provider, "generate");
|
|
278
|
-
const generateOptions = {
|
|
279
|
-
model: this.model,
|
|
280
|
-
prompt: prompt,
|
|
281
|
-
system: systemPrompt,
|
|
282
|
-
temperature,
|
|
283
|
-
maxTokens,
|
|
284
|
-
// Add abort signal if available
|
|
285
|
-
...(timeoutController && {
|
|
286
|
-
abortSignal: timeoutController.controller.signal,
|
|
287
|
-
}),
|
|
288
|
-
};
|
|
289
|
-
if (finalSchema) {
|
|
290
|
-
generateOptions.experimental_output = Output.object({
|
|
291
|
-
schema: finalSchema,
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
try {
|
|
295
|
-
const result = await generateText(generateOptions);
|
|
296
|
-
// Clean up timeout if successful
|
|
297
|
-
timeoutController?.cleanup();
|
|
298
|
-
logger.debug(`[${functionTag}] Generate text completed`, {
|
|
299
|
-
provider,
|
|
300
|
-
modelName: this.modelName,
|
|
301
|
-
usage: result.usage,
|
|
302
|
-
finishReason: result.finishReason,
|
|
303
|
-
responseLength: result.text?.length || 0,
|
|
304
|
-
timeout,
|
|
305
|
-
});
|
|
306
|
-
// Add analytics if enabled
|
|
307
|
-
if (options.enableAnalytics) {
|
|
308
|
-
result.analytics = createAnalytics(provider, this.modelName, result, Date.now() - startTime, options.context);
|
|
309
|
-
}
|
|
310
|
-
// Add evaluation if enabled
|
|
311
|
-
if (options.enableEvaluation) {
|
|
312
|
-
result.evaluation = await evaluateResponse(prompt, result.text, options.context);
|
|
313
|
-
}
|
|
314
|
-
return {
|
|
315
|
-
content: result.text,
|
|
316
|
-
provider: "bedrock",
|
|
317
|
-
model: this.modelName || "claude-3-sonnet",
|
|
318
|
-
usage: result.usage
|
|
319
|
-
? {
|
|
320
|
-
inputTokens: result.usage.promptTokens,
|
|
321
|
-
outputTokens: result.usage.completionTokens,
|
|
322
|
-
totalTokens: result.usage.totalTokens,
|
|
323
|
-
}
|
|
324
|
-
: undefined,
|
|
325
|
-
responseTime: 0,
|
|
326
|
-
};
|
|
327
|
-
}
|
|
328
|
-
finally {
|
|
329
|
-
// Always cleanup timeout
|
|
330
|
-
timeoutController?.cleanup();
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
catch (err) {
|
|
334
|
-
// Log timeout errors specifically
|
|
335
|
-
if (err instanceof TimeoutError) {
|
|
336
|
-
logger.error(`[${functionTag}] Timeout error`, {
|
|
337
|
-
provider,
|
|
338
|
-
modelName: this.modelName,
|
|
339
|
-
region: getAWSRegion(),
|
|
340
|
-
timeout: err.timeout,
|
|
341
|
-
message: err.message,
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
else {
|
|
345
|
-
logger.error(`[${functionTag}] Exception`, {
|
|
346
|
-
provider,
|
|
347
|
-
modelName: this.modelName,
|
|
348
|
-
message: "Error in generating text",
|
|
349
|
-
err: String(err),
|
|
350
|
-
});
|
|
351
|
-
}
|
|
352
|
-
throw err; // Re-throw error to trigger fallback instead of returning null
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
/**
|
|
356
|
-
* Alias for generate() - CLI-SDK consistency
|
|
357
|
-
*/
|
|
358
|
-
/**
|
|
359
|
-
* Short alias for generate() - CLI-SDK consistency
|
|
360
|
-
*/
|
|
361
|
-
async gen(optionsOrPrompt, analysisSchema) {
|
|
362
|
-
return this.generate(optionsOrPrompt, analysisSchema);
|
|
363
|
-
}
|
|
364
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Azure OpenAI Provider
|
|
3
|
-
*
|
|
4
|
-
* Enterprise-grade OpenAI integration through Microsoft Azure.
|
|
5
|
-
* Supports all OpenAI models with enhanced security and compliance.
|
|
6
|
-
*/
|
|
7
|
-
import type { AIProvider, TextGenerationOptions, EnhancedGenerateResult } from "../core/types.js";
|
|
8
|
-
import type { StreamOptions, StreamResult } from "../types/stream-types.js";
|
|
9
|
-
import { AIProviderName } from "../core/types.js";
|
|
10
|
-
export declare class AzureOpenAIProvider implements AIProvider {
|
|
11
|
-
readonly name: AIProviderName;
|
|
12
|
-
private apiKey;
|
|
13
|
-
private endpoint;
|
|
14
|
-
private deploymentId;
|
|
15
|
-
private apiVersion;
|
|
16
|
-
constructor();
|
|
17
|
-
private getApiKey;
|
|
18
|
-
private getEndpoint;
|
|
19
|
-
private getDeploymentId;
|
|
20
|
-
private getApiUrl;
|
|
21
|
-
private makeRequest;
|
|
22
|
-
/**
|
|
23
|
-
* PRIMARY METHOD: Stream content using AI (recommended for new code)
|
|
24
|
-
* Future-ready for multi-modal capabilities with current text focus
|
|
25
|
-
*/
|
|
26
|
-
stream(optionsOrPrompt: StreamOptions | string, analysisSchema?: any): Promise<StreamResult>;
|
|
27
|
-
generate(optionsOrPrompt: TextGenerationOptions | string, schema?: any): Promise<any>;
|
|
28
|
-
private createAsyncIterable;
|
|
29
|
-
testConnection(): Promise<{
|
|
30
|
-
success: boolean;
|
|
31
|
-
error?: string;
|
|
32
|
-
responseTime?: number;
|
|
33
|
-
}>;
|
|
34
|
-
isConfigured(): boolean;
|
|
35
|
-
getRequiredConfig(): string[];
|
|
36
|
-
getOptionalConfig(): string[];
|
|
37
|
-
getModels(): string[];
|
|
38
|
-
supportsStreaming(): boolean;
|
|
39
|
-
supportsSchema(): boolean;
|
|
40
|
-
getCapabilities(): string[];
|
|
41
|
-
gen(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: any): Promise<EnhancedGenerateResult | null>;
|
|
42
|
-
}
|