@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,334 +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
|
-
async streamText(optionsOrPrompt, analysisSchema) {
|
|
127
|
-
const functionTag = "AmazonBedrock.streamText";
|
|
128
|
-
const provider = "bedrock";
|
|
129
|
-
let chunkCount = 0;
|
|
130
|
-
try {
|
|
131
|
-
// Parse parameters - support both string and options object
|
|
132
|
-
const options = typeof optionsOrPrompt === "string"
|
|
133
|
-
? { prompt: optionsOrPrompt }
|
|
134
|
-
: optionsOrPrompt;
|
|
135
|
-
const { prompt, temperature = 0.7, maxTokens = DEFAULT_MAX_TOKENS, systemPrompt = DEFAULT_SYSTEM_CONTEXT.systemPrompt, schema, timeout = getDefaultTimeout(provider, "stream"), } = options;
|
|
136
|
-
// Use schema from options or fallback parameter
|
|
137
|
-
const finalSchema = schema || analysisSchema;
|
|
138
|
-
logger.debug(`[${functionTag}] Stream request started`, {
|
|
139
|
-
provider,
|
|
140
|
-
modelName: this.modelName,
|
|
141
|
-
promptLength: prompt.length,
|
|
142
|
-
temperature,
|
|
143
|
-
maxTokens,
|
|
144
|
-
timeout,
|
|
145
|
-
});
|
|
146
|
-
// Create timeout controller if timeout is specified
|
|
147
|
-
const timeoutController = createTimeoutController(timeout, provider, "stream");
|
|
148
|
-
const streamOptions = {
|
|
149
|
-
model: this.model,
|
|
150
|
-
prompt: prompt,
|
|
151
|
-
system: systemPrompt,
|
|
152
|
-
temperature,
|
|
153
|
-
maxTokens,
|
|
154
|
-
// Add abort signal if available
|
|
155
|
-
...(timeoutController && {
|
|
156
|
-
abortSignal: timeoutController.controller.signal,
|
|
157
|
-
}),
|
|
158
|
-
onError: (event) => {
|
|
159
|
-
const error = event.error;
|
|
160
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
161
|
-
const errorStack = error instanceof Error ? error.stack : undefined;
|
|
162
|
-
logger.error(`[${functionTag}] Stream text error`, {
|
|
163
|
-
provider,
|
|
164
|
-
modelName: this.modelName,
|
|
165
|
-
region: getAWSRegion(),
|
|
166
|
-
error: errorMessage,
|
|
167
|
-
stack: errorStack,
|
|
168
|
-
promptLength: prompt.length,
|
|
169
|
-
chunkCount,
|
|
170
|
-
});
|
|
171
|
-
},
|
|
172
|
-
onFinish: (event) => {
|
|
173
|
-
logger.debug(`[${functionTag}] Stream text finished`, {
|
|
174
|
-
provider,
|
|
175
|
-
modelName: this.modelName,
|
|
176
|
-
region: getAWSRegion(),
|
|
177
|
-
finishReason: event.finishReason,
|
|
178
|
-
usage: event.usage,
|
|
179
|
-
totalChunks: chunkCount,
|
|
180
|
-
promptLength: prompt.length,
|
|
181
|
-
responseLength: event.text?.length || 0,
|
|
182
|
-
});
|
|
183
|
-
},
|
|
184
|
-
onChunk: (event) => {
|
|
185
|
-
chunkCount++;
|
|
186
|
-
logger.debug(`[${functionTag}] Stream text chunk`, {
|
|
187
|
-
provider,
|
|
188
|
-
modelName: this.modelName,
|
|
189
|
-
chunkNumber: chunkCount,
|
|
190
|
-
chunkLength: event.chunk.text?.length || 0,
|
|
191
|
-
chunkType: event.chunk.type,
|
|
192
|
-
});
|
|
193
|
-
},
|
|
194
|
-
};
|
|
195
|
-
if (finalSchema) {
|
|
196
|
-
streamOptions.experimental_output = Output.object({
|
|
197
|
-
schema: finalSchema,
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
// Direct streamText call - let the real error bubble up
|
|
201
|
-
const result = streamText(streamOptions);
|
|
202
|
-
logger.debug(`[${functionTag}] Stream text call successful`, {
|
|
203
|
-
provider,
|
|
204
|
-
modelName: this.modelName,
|
|
205
|
-
promptLength: prompt.length,
|
|
206
|
-
});
|
|
207
|
-
// For streaming, we can't clean up immediately, but the timeout will auto-clean
|
|
208
|
-
// The user should handle the stream and any timeout errors
|
|
209
|
-
return result;
|
|
210
|
-
}
|
|
211
|
-
catch (err) {
|
|
212
|
-
// Log timeout errors specifically
|
|
213
|
-
if (err instanceof TimeoutError) {
|
|
214
|
-
logger.error(`[${functionTag}] Timeout error`, {
|
|
215
|
-
provider,
|
|
216
|
-
modelName: this.modelName,
|
|
217
|
-
region: getAWSRegion(),
|
|
218
|
-
timeout: err.timeout,
|
|
219
|
-
message: err.message,
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
else {
|
|
223
|
-
logger.error(`[${functionTag}] Exception`, {
|
|
224
|
-
provider,
|
|
225
|
-
modelName: this.modelName,
|
|
226
|
-
region: getAWSRegion(),
|
|
227
|
-
message: "Error in streaming text",
|
|
228
|
-
err: String(err),
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
throw err; // Re-throw error to trigger fallback
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
async generateText(optionsOrPrompt, analysisSchema) {
|
|
235
|
-
const functionTag = "AmazonBedrock.generateText";
|
|
236
|
-
const provider = "bedrock";
|
|
237
|
-
const startTime = Date.now();
|
|
238
|
-
try {
|
|
239
|
-
// Parse parameters - support both string and options object
|
|
240
|
-
const options = typeof optionsOrPrompt === "string"
|
|
241
|
-
? { prompt: optionsOrPrompt }
|
|
242
|
-
: optionsOrPrompt;
|
|
243
|
-
const { prompt, temperature = 0.7, maxTokens = DEFAULT_MAX_TOKENS, systemPrompt = DEFAULT_SYSTEM_CONTEXT.systemPrompt, schema, timeout = getDefaultTimeout(provider, "generate"), } = options;
|
|
244
|
-
// Use schema from options or fallback parameter
|
|
245
|
-
const finalSchema = schema || analysisSchema;
|
|
246
|
-
logger.debug(`[${functionTag}] Generate text started`, {
|
|
247
|
-
provider,
|
|
248
|
-
modelName: this.modelName,
|
|
249
|
-
region: getAWSRegion(),
|
|
250
|
-
promptLength: prompt.length,
|
|
251
|
-
temperature,
|
|
252
|
-
maxTokens,
|
|
253
|
-
timeout,
|
|
254
|
-
});
|
|
255
|
-
// Create timeout controller if timeout is specified
|
|
256
|
-
const timeoutController = createTimeoutController(timeout, provider, "generate");
|
|
257
|
-
const generateOptions = {
|
|
258
|
-
model: this.model,
|
|
259
|
-
prompt: prompt,
|
|
260
|
-
system: systemPrompt,
|
|
261
|
-
temperature,
|
|
262
|
-
maxTokens,
|
|
263
|
-
// Add abort signal if available
|
|
264
|
-
...(timeoutController && {
|
|
265
|
-
abortSignal: timeoutController.controller.signal,
|
|
266
|
-
}),
|
|
267
|
-
};
|
|
268
|
-
if (finalSchema) {
|
|
269
|
-
generateOptions.experimental_output = Output.object({
|
|
270
|
-
schema: finalSchema,
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
try {
|
|
274
|
-
const result = await generateText(generateOptions);
|
|
275
|
-
// Clean up timeout if successful
|
|
276
|
-
timeoutController?.cleanup();
|
|
277
|
-
logger.debug(`[${functionTag}] Generate text completed`, {
|
|
278
|
-
provider,
|
|
279
|
-
modelName: this.modelName,
|
|
280
|
-
usage: result.usage,
|
|
281
|
-
finishReason: result.finishReason,
|
|
282
|
-
responseLength: result.text?.length || 0,
|
|
283
|
-
timeout,
|
|
284
|
-
});
|
|
285
|
-
// Add analytics if enabled
|
|
286
|
-
if (options.enableAnalytics) {
|
|
287
|
-
result.analytics = createAnalytics(provider, this.modelName, result, Date.now() - startTime, options.context);
|
|
288
|
-
}
|
|
289
|
-
// Add evaluation if enabled
|
|
290
|
-
if (options.enableEvaluation) {
|
|
291
|
-
result.evaluation = await evaluateResponse(prompt, result.text, options.context);
|
|
292
|
-
}
|
|
293
|
-
return result;
|
|
294
|
-
}
|
|
295
|
-
finally {
|
|
296
|
-
// Always cleanup timeout
|
|
297
|
-
timeoutController?.cleanup();
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
catch (err) {
|
|
301
|
-
// Log timeout errors specifically
|
|
302
|
-
if (err instanceof TimeoutError) {
|
|
303
|
-
logger.error(`[${functionTag}] Timeout error`, {
|
|
304
|
-
provider,
|
|
305
|
-
modelName: this.modelName,
|
|
306
|
-
region: getAWSRegion(),
|
|
307
|
-
timeout: err.timeout,
|
|
308
|
-
message: err.message,
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
else {
|
|
312
|
-
logger.error(`[${functionTag}] Exception`, {
|
|
313
|
-
provider,
|
|
314
|
-
modelName: this.modelName,
|
|
315
|
-
message: "Error in generating text",
|
|
316
|
-
err: String(err),
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
throw err; // Re-throw error to trigger fallback instead of returning null
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* Alias for generateText() - CLI-SDK consistency
|
|
324
|
-
*/
|
|
325
|
-
async generate(optionsOrPrompt, analysisSchema) {
|
|
326
|
-
return this.generateText(optionsOrPrompt, analysisSchema);
|
|
327
|
-
}
|
|
328
|
-
/**
|
|
329
|
-
* Short alias for generateText() - CLI-SDK consistency
|
|
330
|
-
*/
|
|
331
|
-
async gen(optionsOrPrompt, analysisSchema) {
|
|
332
|
-
return this.generateText(optionsOrPrompt, analysisSchema);
|
|
333
|
-
}
|
|
334
|
-
}
|
|
@@ -1,39 +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, StreamTextOptions, EnhancedGenerateTextResult } from "../core/types.js";
|
|
8
|
-
import { AIProviderName } from "../core/types.js";
|
|
9
|
-
export declare class AzureOpenAIProvider implements AIProvider {
|
|
10
|
-
readonly name: AIProviderName;
|
|
11
|
-
private apiKey;
|
|
12
|
-
private endpoint;
|
|
13
|
-
private deploymentId;
|
|
14
|
-
private apiVersion;
|
|
15
|
-
constructor();
|
|
16
|
-
private getApiKey;
|
|
17
|
-
private getEndpoint;
|
|
18
|
-
private getDeploymentId;
|
|
19
|
-
private getApiUrl;
|
|
20
|
-
private makeRequest;
|
|
21
|
-
generateText(optionsOrPrompt: TextGenerationOptions | string, schema?: any): Promise<any>;
|
|
22
|
-
streamText(optionsOrPrompt: StreamTextOptions | string, schema?: any): Promise<any>;
|
|
23
|
-
private createAsyncIterable;
|
|
24
|
-
generateTextStream(optionsOrPrompt: StreamTextOptions | string): AsyncGenerator<any, void, unknown>;
|
|
25
|
-
testConnection(): Promise<{
|
|
26
|
-
success: boolean;
|
|
27
|
-
error?: string;
|
|
28
|
-
responseTime?: number;
|
|
29
|
-
}>;
|
|
30
|
-
isConfigured(): boolean;
|
|
31
|
-
getRequiredConfig(): string[];
|
|
32
|
-
getOptionalConfig(): string[];
|
|
33
|
-
getModels(): string[];
|
|
34
|
-
supportsStreaming(): boolean;
|
|
35
|
-
supportsSchema(): boolean;
|
|
36
|
-
getCapabilities(): string[];
|
|
37
|
-
generate(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: any): Promise<EnhancedGenerateTextResult | null>;
|
|
38
|
-
gen(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: any): Promise<EnhancedGenerateTextResult | null>;
|
|
39
|
-
}
|