@juspay/neurolink 5.1.0 → 5.3.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 +21 -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 +63 -8
- package/dist/cli/index.js +87 -140
- package/dist/core/base-provider.d.ts +423 -0
- package/dist/core/base-provider.js +376 -0
- package/dist/core/constants.d.ts +2 -1
- package/dist/core/constants.js +2 -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 +376 -0
- package/dist/lib/core/constants.d.ts +2 -1
- package/dist/lib/core/constants.js +2 -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/client.d.ts +1 -0
- package/dist/lib/mcp/client.js +1 -0
- package/dist/lib/mcp/config.js +28 -3
- package/dist/lib/mcp/context-manager.d.ts +1 -0
- package/dist/lib/mcp/context-manager.js +8 -4
- package/dist/lib/mcp/function-calling.d.ts +13 -0
- package/dist/lib/mcp/function-calling.js +134 -35
- 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.d.ts +1 -0
- package/dist/lib/mcp/neurolink-mcp-client.js +21 -5
- 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/function-calling-provider.d.ts +64 -2
- package/dist/lib/providers/function-calling-provider.js +208 -9
- 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 +24 -5
- 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/services/streaming/streaming-manager.js +11 -10
- package/dist/lib/services/websocket/websocket-server.js +12 -11
- package/dist/lib/telemetry/telemetry-service.js +8 -7
- 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/client.d.ts +1 -0
- package/dist/mcp/client.js +1 -0
- package/dist/mcp/config.js +28 -3
- package/dist/mcp/context-manager.d.ts +1 -0
- package/dist/mcp/context-manager.js +8 -4
- package/dist/mcp/function-calling.d.ts +13 -0
- package/dist/mcp/function-calling.js +134 -35
- 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.d.ts +1 -0
- package/dist/mcp/neurolink-mcp-client.js +21 -5
- 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/function-calling-provider.d.ts +64 -2
- package/dist/providers/function-calling-provider.js +208 -9
- 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 +24 -5
- 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/services/streaming/streaming-manager.js +11 -10
- package/dist/services/websocket/websocket-server.js +12 -11
- package/dist/telemetry/telemetry-service.js +8 -7
- 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 +12 -5
- 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,347 +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 { AIProviderName } from "../core/types.js";
|
|
8
|
-
import { logger } from "../utils/logger.js";
|
|
9
|
-
import { createTimeoutController, TimeoutError, getDefaultTimeout, } from "../utils/timeout.js";
|
|
10
|
-
import { DEFAULT_MAX_TOKENS } from "../core/constants.js";
|
|
11
|
-
import { evaluateResponse } from "../core/evaluation.js";
|
|
12
|
-
export class AzureOpenAIProvider {
|
|
13
|
-
name = AIProviderName.AZURE;
|
|
14
|
-
apiKey;
|
|
15
|
-
endpoint;
|
|
16
|
-
deploymentId;
|
|
17
|
-
apiVersion;
|
|
18
|
-
constructor() {
|
|
19
|
-
this.apiKey = this.getApiKey();
|
|
20
|
-
this.endpoint = this.getEndpoint();
|
|
21
|
-
this.deploymentId = this.getDeploymentId();
|
|
22
|
-
this.apiVersion =
|
|
23
|
-
process.env.AZURE_OPENAI_API_VERSION || "2024-02-15-preview";
|
|
24
|
-
logger.debug(`[AzureOpenAIProvider] Initialized with endpoint: ${this.endpoint}, deployment: ${this.deploymentId}`);
|
|
25
|
-
}
|
|
26
|
-
getApiKey() {
|
|
27
|
-
const apiKey = process.env.AZURE_OPENAI_API_KEY;
|
|
28
|
-
if (!apiKey) {
|
|
29
|
-
throw new Error("AZURE_OPENAI_API_KEY environment variable is required");
|
|
30
|
-
}
|
|
31
|
-
return apiKey;
|
|
32
|
-
}
|
|
33
|
-
getEndpoint() {
|
|
34
|
-
const endpoint = process.env.AZURE_OPENAI_ENDPOINT;
|
|
35
|
-
if (!endpoint) {
|
|
36
|
-
throw new Error("AZURE_OPENAI_ENDPOINT environment variable is required");
|
|
37
|
-
}
|
|
38
|
-
return endpoint.replace(/\/$/, ""); // Remove trailing slash
|
|
39
|
-
}
|
|
40
|
-
getDeploymentId() {
|
|
41
|
-
const deploymentId = process.env.AZURE_OPENAI_DEPLOYMENT_ID;
|
|
42
|
-
if (!deploymentId) {
|
|
43
|
-
throw new Error("AZURE_OPENAI_DEPLOYMENT_ID environment variable is required");
|
|
44
|
-
}
|
|
45
|
-
return deploymentId;
|
|
46
|
-
}
|
|
47
|
-
getApiUrl(stream = false) {
|
|
48
|
-
return `${this.endpoint}/openai/deployments/${this.deploymentId}/chat/completions?api-version=${this.apiVersion}`;
|
|
49
|
-
}
|
|
50
|
-
async makeRequest(body, stream = false, signal) {
|
|
51
|
-
const url = this.getApiUrl(stream);
|
|
52
|
-
const headers = {
|
|
53
|
-
"Content-Type": "application/json",
|
|
54
|
-
"api-key": this.apiKey,
|
|
55
|
-
};
|
|
56
|
-
logger.debug(`[AzureOpenAIProvider.makeRequest] ${stream ? "Streaming" : "Non-streaming"} request to deployment: ${this.deploymentId}`);
|
|
57
|
-
logger.debug(`[AzureOpenAIProvider.makeRequest] Max tokens: ${body.max_tokens || "default"}, Temperature: ${body.temperature || "default"}`);
|
|
58
|
-
const response = await fetch(url, {
|
|
59
|
-
method: "POST",
|
|
60
|
-
headers,
|
|
61
|
-
body: JSON.stringify(body),
|
|
62
|
-
signal, // Add abort signal for timeout support
|
|
63
|
-
});
|
|
64
|
-
if (!response.ok) {
|
|
65
|
-
const errorText = await response.text();
|
|
66
|
-
logger.error(`[AzureOpenAIProvider.makeRequest] API error ${response.status}: ${errorText}`);
|
|
67
|
-
throw new Error(`Azure OpenAI API error ${response.status}: ${errorText}`);
|
|
68
|
-
}
|
|
69
|
-
return response;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* PRIMARY METHOD: Stream content using AI (recommended for new code)
|
|
73
|
-
* Future-ready for multi-modal capabilities with current text focus
|
|
74
|
-
*/
|
|
75
|
-
async stream(optionsOrPrompt, analysisSchema) {
|
|
76
|
-
const functionTag = "AzureOpenAIProvider.stream";
|
|
77
|
-
const startTime = Date.now();
|
|
78
|
-
// Parse parameters - support both string and options object
|
|
79
|
-
const options = typeof optionsOrPrompt === "string"
|
|
80
|
-
? { input: { text: optionsOrPrompt } }
|
|
81
|
-
: optionsOrPrompt;
|
|
82
|
-
// Validate input
|
|
83
|
-
if (!options?.input?.text ||
|
|
84
|
-
typeof options.input.text !== "string" ||
|
|
85
|
-
options.input.text.trim() === "") {
|
|
86
|
-
throw new Error("Stream options must include input.text as a non-empty string");
|
|
87
|
-
}
|
|
88
|
-
// Convert StreamOptions for internal use
|
|
89
|
-
const convertedOptions = {
|
|
90
|
-
prompt: options.input.text,
|
|
91
|
-
provider: options.provider,
|
|
92
|
-
model: options.model,
|
|
93
|
-
temperature: options.temperature,
|
|
94
|
-
maxTokens: options.maxTokens,
|
|
95
|
-
systemPrompt: options.systemPrompt,
|
|
96
|
-
timeout: options.timeout,
|
|
97
|
-
};
|
|
98
|
-
// Prepare Azure OpenAI messages
|
|
99
|
-
const messages = [];
|
|
100
|
-
if (convertedOptions.systemPrompt) {
|
|
101
|
-
messages.push({
|
|
102
|
-
role: "system",
|
|
103
|
-
content: convertedOptions.systemPrompt,
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
messages.push({
|
|
107
|
-
role: "user",
|
|
108
|
-
content: convertedOptions.prompt,
|
|
109
|
-
});
|
|
110
|
-
const requestBody = {
|
|
111
|
-
messages,
|
|
112
|
-
temperature: convertedOptions.temperature ?? 0.7,
|
|
113
|
-
max_tokens: convertedOptions.maxTokens ?? DEFAULT_MAX_TOKENS,
|
|
114
|
-
stream: true,
|
|
115
|
-
};
|
|
116
|
-
// Create timeout controller if timeout is specified
|
|
117
|
-
const timeoutController = createTimeoutController(convertedOptions.timeout, this.name, "stream");
|
|
118
|
-
try {
|
|
119
|
-
const response = await this.makeRequest(requestBody, true, timeoutController?.controller.signal);
|
|
120
|
-
// Clean up timeout if successful
|
|
121
|
-
timeoutController?.cleanup();
|
|
122
|
-
// Return an async iterable for streaming chunks
|
|
123
|
-
const streamIterable = this.createAsyncIterable(response.body, timeoutController?.controller.signal);
|
|
124
|
-
// Compose the StreamResult object
|
|
125
|
-
return {
|
|
126
|
-
stream: streamIterable,
|
|
127
|
-
provider: this.name,
|
|
128
|
-
model: convertedOptions.model,
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
catch (error) {
|
|
132
|
-
timeoutController?.cleanup();
|
|
133
|
-
throw error;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
async generate(optionsOrPrompt, schema) {
|
|
137
|
-
const functionTag = "AzureOpenAIProvider.generate";
|
|
138
|
-
const provider = "azure";
|
|
139
|
-
const startTime = Date.now();
|
|
140
|
-
logger.debug(`[${functionTag}] Starting text generation`);
|
|
141
|
-
// Parse parameters with backward compatibility
|
|
142
|
-
const options = typeof optionsOrPrompt === "string"
|
|
143
|
-
? { prompt: optionsOrPrompt }
|
|
144
|
-
: optionsOrPrompt;
|
|
145
|
-
const { prompt, temperature = 0.7, maxTokens = DEFAULT_MAX_TOKENS, systemPrompt = "You are a helpful AI assistant.", timeout = getDefaultTimeout(provider, "generate"), } = options;
|
|
146
|
-
logger.debug(`[${functionTag}] Prompt: "${prompt.substring(0, 100)}...", Temperature: ${temperature}, Max tokens: ${maxTokens}, Timeout: ${timeout}`);
|
|
147
|
-
const messages = [];
|
|
148
|
-
if (systemPrompt) {
|
|
149
|
-
messages.push({
|
|
150
|
-
role: "system",
|
|
151
|
-
content: systemPrompt,
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
messages.push({
|
|
155
|
-
role: "user",
|
|
156
|
-
content: prompt,
|
|
157
|
-
});
|
|
158
|
-
const requestBody = {
|
|
159
|
-
messages,
|
|
160
|
-
temperature,
|
|
161
|
-
max_tokens: maxTokens,
|
|
162
|
-
};
|
|
163
|
-
// Create timeout controller if timeout is specified
|
|
164
|
-
const timeoutController = createTimeoutController(timeout, provider, "generate");
|
|
165
|
-
try {
|
|
166
|
-
const response = await this.makeRequest(requestBody, false, timeoutController?.controller.signal);
|
|
167
|
-
const data = await response.json();
|
|
168
|
-
// Clean up timeout if successful
|
|
169
|
-
timeoutController?.cleanup();
|
|
170
|
-
logger.debug(`[${functionTag}] Success. Generated ${data.usage.completion_tokens} tokens`);
|
|
171
|
-
const content = data.choices[0]?.message?.content || "";
|
|
172
|
-
const result = {
|
|
173
|
-
content,
|
|
174
|
-
provider: this.name,
|
|
175
|
-
model: data.model,
|
|
176
|
-
usage: {
|
|
177
|
-
promptTokens: data.usage.prompt_tokens,
|
|
178
|
-
completionTokens: data.usage.completion_tokens,
|
|
179
|
-
totalTokens: data.usage.total_tokens,
|
|
180
|
-
},
|
|
181
|
-
finishReason: data.choices[0]?.finish_reason || "stop",
|
|
182
|
-
};
|
|
183
|
-
// Add analytics if enabled
|
|
184
|
-
if (options.enableAnalytics) {
|
|
185
|
-
result.analytics = {
|
|
186
|
-
provider: this.name,
|
|
187
|
-
model: data.model,
|
|
188
|
-
tokens: result.usage,
|
|
189
|
-
responseTime: Date.now() - startTime,
|
|
190
|
-
context: options.context,
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
// Add evaluation if enabled
|
|
194
|
-
if (options.enableEvaluation) {
|
|
195
|
-
result.evaluation = await evaluateResponse(options.prompt, content, options.context);
|
|
196
|
-
}
|
|
197
|
-
return result;
|
|
198
|
-
}
|
|
199
|
-
catch (error) {
|
|
200
|
-
// Always cleanup timeout
|
|
201
|
-
timeoutController?.cleanup();
|
|
202
|
-
// Log timeout errors specifically
|
|
203
|
-
if (error instanceof TimeoutError) {
|
|
204
|
-
logger.error(`[${functionTag}] Timeout error`, {
|
|
205
|
-
provider,
|
|
206
|
-
timeout: error.timeout,
|
|
207
|
-
message: error.message,
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
else if (error?.name === "AbortError") {
|
|
211
|
-
// Convert AbortError to TimeoutError
|
|
212
|
-
const timeoutError = new TimeoutError(`${provider} generate operation timed out after ${timeout}`, timeoutController?.timeoutMs || 0, provider, "generate");
|
|
213
|
-
logger.error(`[${functionTag}] Timeout error`, {
|
|
214
|
-
provider,
|
|
215
|
-
timeout: timeoutController?.timeoutMs,
|
|
216
|
-
message: timeoutError.message,
|
|
217
|
-
});
|
|
218
|
-
throw timeoutError;
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
221
|
-
logger.error(`[${functionTag}] Error:`, error);
|
|
222
|
-
}
|
|
223
|
-
throw error;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
async *createAsyncIterable(body, signal) {
|
|
227
|
-
const reader = body.getReader();
|
|
228
|
-
const decoder = new TextDecoder();
|
|
229
|
-
let buffer = "";
|
|
230
|
-
try {
|
|
231
|
-
while (true) {
|
|
232
|
-
// Check if aborted
|
|
233
|
-
if (signal?.aborted) {
|
|
234
|
-
throw new Error("AbortError");
|
|
235
|
-
}
|
|
236
|
-
const { done, value } = await reader.read();
|
|
237
|
-
if (done) {
|
|
238
|
-
break;
|
|
239
|
-
}
|
|
240
|
-
buffer += decoder.decode(value, { stream: true });
|
|
241
|
-
const lines = buffer.split("\n");
|
|
242
|
-
buffer = lines.pop() || "";
|
|
243
|
-
for (const line of lines) {
|
|
244
|
-
if (line.trim() === "") {
|
|
245
|
-
continue;
|
|
246
|
-
}
|
|
247
|
-
if (line.startsWith("data: ")) {
|
|
248
|
-
const data = line.slice(6);
|
|
249
|
-
if (data.trim() === "[DONE]") {
|
|
250
|
-
continue;
|
|
251
|
-
}
|
|
252
|
-
try {
|
|
253
|
-
const chunk = JSON.parse(data);
|
|
254
|
-
// Extract text content from chunk
|
|
255
|
-
if (chunk.choices?.[0]?.delta?.content) {
|
|
256
|
-
yield { content: chunk.choices[0].delta.content };
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
catch (parseError) {
|
|
260
|
-
logger.warn("[AzureOpenAIProvider.createAsyncIterable] Failed to parse chunk:", parseError);
|
|
261
|
-
continue;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
finally {
|
|
268
|
-
reader.releaseLock();
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
async testConnection() {
|
|
272
|
-
logger.debug("[AzureOpenAIProvider.testConnection] Testing connection to Azure OpenAI");
|
|
273
|
-
const startTime = Date.now();
|
|
274
|
-
try {
|
|
275
|
-
await this.generate({
|
|
276
|
-
prompt: "Hello",
|
|
277
|
-
maxTokens: 5,
|
|
278
|
-
});
|
|
279
|
-
const responseTime = Date.now() - startTime;
|
|
280
|
-
logger.debug(`[AzureOpenAIProvider.testConnection] Connection test successful (${responseTime}ms)`);
|
|
281
|
-
return {
|
|
282
|
-
success: true,
|
|
283
|
-
responseTime,
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
catch (error) {
|
|
287
|
-
const responseTime = Date.now() - startTime;
|
|
288
|
-
logger.error(`[AzureOpenAIProvider.testConnection] Connection test failed (${responseTime}ms):`, error);
|
|
289
|
-
return {
|
|
290
|
-
success: false,
|
|
291
|
-
error: error instanceof Error ? error.message : "Unknown error",
|
|
292
|
-
responseTime,
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
isConfigured() {
|
|
297
|
-
try {
|
|
298
|
-
this.getApiKey();
|
|
299
|
-
this.getEndpoint();
|
|
300
|
-
this.getDeploymentId();
|
|
301
|
-
return true;
|
|
302
|
-
}
|
|
303
|
-
catch {
|
|
304
|
-
return false;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
getRequiredConfig() {
|
|
308
|
-
return [
|
|
309
|
-
"AZURE_OPENAI_API_KEY",
|
|
310
|
-
"AZURE_OPENAI_ENDPOINT",
|
|
311
|
-
"AZURE_OPENAI_DEPLOYMENT_ID",
|
|
312
|
-
];
|
|
313
|
-
}
|
|
314
|
-
getOptionalConfig() {
|
|
315
|
-
return ["AZURE_OPENAI_API_VERSION"];
|
|
316
|
-
}
|
|
317
|
-
getModels() {
|
|
318
|
-
return [
|
|
319
|
-
"gpt-4",
|
|
320
|
-
"gpt-4-turbo",
|
|
321
|
-
"gpt-4-32k",
|
|
322
|
-
"gpt-35-turbo",
|
|
323
|
-
"gpt-35-turbo-16k",
|
|
324
|
-
];
|
|
325
|
-
}
|
|
326
|
-
supportsStreaming() {
|
|
327
|
-
return true;
|
|
328
|
-
}
|
|
329
|
-
supportsSchema() {
|
|
330
|
-
return true; // Azure OpenAI supports JSON mode and function calling
|
|
331
|
-
}
|
|
332
|
-
getCapabilities() {
|
|
333
|
-
return [
|
|
334
|
-
"text-generation",
|
|
335
|
-
"streaming",
|
|
336
|
-
"conversation",
|
|
337
|
-
"system-prompts",
|
|
338
|
-
"json-mode",
|
|
339
|
-
"function-calling",
|
|
340
|
-
"enterprise-security",
|
|
341
|
-
"content-filtering",
|
|
342
|
-
];
|
|
343
|
-
}
|
|
344
|
-
async gen(optionsOrPrompt, analysisSchema) {
|
|
345
|
-
return this.generate(optionsOrPrompt, analysisSchema);
|
|
346
|
-
}
|
|
347
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { ZodType, ZodTypeDef } from "zod";
|
|
2
|
-
import { type Schema, type LanguageModelV1 } from "ai";
|
|
3
|
-
import type { GenerateResult } from "../types/generate-types.js";
|
|
4
|
-
import type { StreamOptions, StreamResult } from "../types/stream-types.js";
|
|
5
|
-
import type { AIProvider, TextGenerationOptions, EnhancedGenerateResult } from "../core/types.js";
|
|
6
|
-
export declare class GoogleAIStudio implements AIProvider {
|
|
7
|
-
private modelName;
|
|
8
|
-
/**
|
|
9
|
-
* Initializes a new instance of GoogleAIStudio
|
|
10
|
-
* @param modelName - Optional model name to override the default from config
|
|
11
|
-
*/
|
|
12
|
-
constructor(modelName?: string | null);
|
|
13
|
-
/**
|
|
14
|
-
* Gets the appropriate model instance
|
|
15
|
-
* Made public to support FunctionCallingProvider integration
|
|
16
|
-
*/
|
|
17
|
-
getModel(): LanguageModelV1;
|
|
18
|
-
/**
|
|
19
|
-
* Expose model property for FunctionCallingProvider
|
|
20
|
-
* This allows the enhanced provider to access the underlying model
|
|
21
|
-
*/
|
|
22
|
-
get model(): LanguageModelV1;
|
|
23
|
-
/**
|
|
24
|
-
* PRIMARY METHOD: Stream content using AI (recommended for new code)
|
|
25
|
-
* Future-ready for multi-modal capabilities with current text focus
|
|
26
|
-
*/
|
|
27
|
-
stream(optionsOrPrompt: StreamOptions | string, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<StreamResult>;
|
|
28
|
-
/**
|
|
29
|
-
* Processes text using non-streaming approach with optional schema validation
|
|
30
|
-
* @param prompt - The input text prompt to analyze
|
|
31
|
-
* @param analysisSchema - Optional Zod schema or Schema object for output validation
|
|
32
|
-
* @returns Promise resolving to GenerateResult or null if operation fails
|
|
33
|
-
*/
|
|
34
|
-
generate(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<GenerateResult>;
|
|
35
|
-
/**
|
|
36
|
-
* Short alias for generate() - CLI-SDK consistency
|
|
37
|
-
* @param optionsOrPrompt - TextGenerationOptions object or prompt string
|
|
38
|
-
* @param analysisSchema - Optional schema for output validation
|
|
39
|
-
* @returns Promise resolving to GenerateResult or null
|
|
40
|
-
*/
|
|
41
|
-
gen(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<EnhancedGenerateResult | null>;
|
|
42
|
-
}
|