@juspay/neurolink 3.0.1 → 4.1.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 +66 -6
- package/README.md +318 -27
- package/dist/agent/direct-tools.d.ts +6 -6
- package/dist/chat/client-utils.d.ts +92 -0
- package/dist/chat/client-utils.js +298 -0
- package/dist/chat/index.d.ts +27 -0
- package/dist/chat/index.js +41 -0
- package/dist/chat/session-storage.d.ts +77 -0
- package/dist/chat/session-storage.js +233 -0
- package/dist/chat/session.d.ts +95 -0
- package/dist/chat/session.js +257 -0
- package/dist/chat/sse-handler.d.ts +49 -0
- package/dist/chat/sse-handler.js +266 -0
- package/dist/chat/types.d.ts +73 -0
- package/dist/chat/types.js +5 -0
- package/dist/chat/websocket-chat-handler.d.ts +36 -0
- package/dist/chat/websocket-chat-handler.js +262 -0
- package/dist/cli/commands/config.js +12 -12
- package/dist/cli/commands/mcp.js +3 -4
- package/dist/cli/index.d.ts +0 -7
- package/dist/cli/index.js +247 -28
- package/dist/config/configManager.d.ts +60 -0
- package/dist/config/configManager.js +300 -0
- package/dist/config/types.d.ts +136 -0
- package/dist/config/types.js +43 -0
- package/dist/core/analytics.d.ts +23 -0
- package/dist/core/analytics.js +131 -0
- package/dist/core/constants.d.ts +41 -0
- package/dist/core/constants.js +50 -0
- package/dist/core/defaults.d.ts +18 -0
- package/dist/core/defaults.js +29 -0
- package/dist/core/evaluation-config.d.ts +29 -0
- package/dist/core/evaluation-config.js +144 -0
- package/dist/core/evaluation-providers.d.ts +30 -0
- package/dist/core/evaluation-providers.js +187 -0
- package/dist/core/evaluation.d.ts +117 -0
- package/dist/core/evaluation.js +528 -0
- package/dist/core/factory.js +33 -25
- package/dist/core/types.d.ts +165 -6
- package/dist/core/types.js +3 -4
- package/dist/index.d.ts +9 -4
- package/dist/index.js +25 -4
- package/dist/lib/agent/direct-tools.d.ts +6 -6
- package/dist/lib/chat/client-utils.d.ts +92 -0
- package/dist/lib/chat/client-utils.js +298 -0
- package/dist/lib/chat/index.d.ts +27 -0
- package/dist/lib/chat/index.js +41 -0
- package/dist/lib/chat/session-storage.d.ts +77 -0
- package/dist/lib/chat/session-storage.js +233 -0
- package/dist/lib/chat/session.d.ts +95 -0
- package/dist/lib/chat/session.js +257 -0
- package/dist/lib/chat/sse-handler.d.ts +49 -0
- package/dist/lib/chat/sse-handler.js +266 -0
- package/dist/lib/chat/types.d.ts +73 -0
- package/dist/lib/chat/types.js +5 -0
- package/dist/lib/chat/websocket-chat-handler.d.ts +36 -0
- package/dist/lib/chat/websocket-chat-handler.js +262 -0
- package/dist/lib/config/configManager.d.ts +60 -0
- package/dist/lib/config/configManager.js +300 -0
- package/dist/lib/config/types.d.ts +136 -0
- package/dist/lib/config/types.js +43 -0
- package/dist/lib/core/analytics.d.ts +23 -0
- package/dist/lib/core/analytics.js +131 -0
- package/dist/lib/core/constants.d.ts +41 -0
- package/dist/lib/core/constants.js +50 -0
- package/dist/lib/core/defaults.d.ts +18 -0
- package/dist/lib/core/defaults.js +29 -0
- package/dist/lib/core/evaluation-config.d.ts +29 -0
- package/dist/lib/core/evaluation-config.js +144 -0
- package/dist/lib/core/evaluation-providers.d.ts +30 -0
- package/dist/lib/core/evaluation-providers.js +187 -0
- package/dist/lib/core/evaluation.d.ts +117 -0
- package/dist/lib/core/evaluation.js +528 -0
- package/dist/lib/core/factory.js +33 -26
- package/dist/lib/core/types.d.ts +165 -6
- package/dist/lib/core/types.js +3 -4
- package/dist/lib/index.d.ts +9 -4
- package/dist/lib/index.js +25 -4
- package/dist/lib/mcp/contracts/mcpContract.d.ts +118 -0
- package/dist/lib/mcp/contracts/mcpContract.js +5 -0
- package/dist/lib/mcp/dynamic-chain-executor.d.ts +201 -0
- package/dist/lib/mcp/dynamic-chain-executor.js +489 -0
- package/dist/lib/mcp/dynamic-orchestrator.d.ts +109 -0
- package/dist/lib/mcp/dynamic-orchestrator.js +351 -0
- package/dist/lib/mcp/error-manager.d.ts +254 -0
- package/dist/lib/mcp/error-manager.js +501 -0
- package/dist/lib/mcp/error-recovery.d.ts +158 -0
- package/dist/lib/mcp/error-recovery.js +405 -0
- package/dist/lib/mcp/function-calling.js +11 -3
- package/dist/lib/mcp/health-monitor.d.ts +256 -0
- package/dist/lib/mcp/health-monitor.js +621 -0
- package/dist/lib/mcp/logging.js +5 -0
- package/dist/lib/mcp/neurolink-mcp-client.js +2 -1
- package/dist/lib/mcp/orchestrator.d.ts +136 -5
- package/dist/lib/mcp/orchestrator.js +332 -16
- package/dist/lib/mcp/registry.d.ts +71 -16
- package/dist/lib/mcp/registry.js +104 -6
- package/dist/lib/mcp/semaphore-manager.d.ts +137 -0
- package/dist/lib/mcp/semaphore-manager.js +329 -0
- 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 +5 -4
- package/dist/lib/mcp/session-manager.d.ts +186 -0
- package/dist/lib/mcp/session-manager.js +400 -0
- package/dist/lib/mcp/session-persistence.d.ts +93 -0
- package/dist/lib/mcp/session-persistence.js +298 -0
- package/dist/lib/mcp/tool-integration.js +1 -1
- package/dist/lib/mcp/tool-registry.d.ts +55 -34
- package/dist/lib/mcp/tool-registry.js +111 -97
- package/dist/lib/mcp/transport-manager.d.ts +153 -0
- package/dist/lib/mcp/transport-manager.js +330 -0
- package/dist/lib/mcp/unified-mcp.js +6 -1
- package/dist/lib/mcp/unified-registry.d.ts +54 -5
- package/dist/lib/mcp/unified-registry.js +139 -6
- package/dist/lib/neurolink.d.ts +101 -0
- package/dist/lib/neurolink.js +147 -1
- package/dist/lib/providers/agent-enhanced-provider.d.ts +11 -2
- package/dist/lib/providers/agent-enhanced-provider.js +86 -15
- package/dist/lib/providers/amazonBedrock.d.ts +9 -1
- package/dist/lib/providers/amazonBedrock.js +26 -2
- package/dist/lib/providers/analytics-helper.d.ts +53 -0
- package/dist/lib/providers/analytics-helper.js +151 -0
- package/dist/lib/providers/anthropic.d.ts +11 -1
- package/dist/lib/providers/anthropic.js +29 -4
- package/dist/lib/providers/azureOpenAI.d.ts +3 -1
- package/dist/lib/providers/azureOpenAI.js +28 -4
- package/dist/lib/providers/function-calling-provider.d.ts +9 -1
- package/dist/lib/providers/function-calling-provider.js +14 -1
- package/dist/lib/providers/googleAIStudio.d.ts +15 -1
- package/dist/lib/providers/googleAIStudio.js +32 -2
- package/dist/lib/providers/googleVertexAI.d.ts +9 -1
- package/dist/lib/providers/googleVertexAI.js +31 -2
- package/dist/lib/providers/huggingFace.d.ts +3 -1
- package/dist/lib/providers/huggingFace.js +26 -3
- package/dist/lib/providers/mcp-provider.d.ts +9 -1
- package/dist/lib/providers/mcp-provider.js +12 -0
- package/dist/lib/providers/mistralAI.d.ts +3 -1
- package/dist/lib/providers/mistralAI.js +25 -2
- package/dist/lib/providers/ollama.d.ts +3 -1
- package/dist/lib/providers/ollama.js +27 -4
- package/dist/lib/providers/openAI.d.ts +15 -1
- package/dist/lib/providers/openAI.js +32 -2
- package/dist/lib/proxy/proxy-fetch.js +8 -7
- package/dist/lib/services/streaming/streaming-manager.d.ts +29 -0
- package/dist/lib/services/streaming/streaming-manager.js +244 -0
- package/dist/lib/services/types.d.ts +155 -0
- package/dist/lib/services/types.js +2 -0
- package/dist/lib/services/websocket/websocket-server.d.ts +34 -0
- package/dist/lib/services/websocket/websocket-server.js +304 -0
- package/dist/lib/telemetry/index.d.ts +15 -0
- package/dist/lib/telemetry/index.js +22 -0
- package/dist/lib/telemetry/telemetry-service.d.ts +47 -0
- package/dist/lib/telemetry/telemetry-service.js +259 -0
- package/dist/lib/utils/streaming-utils.d.ts +67 -0
- package/dist/lib/utils/streaming-utils.js +201 -0
- package/dist/mcp/contracts/mcpContract.d.ts +118 -0
- package/dist/mcp/contracts/mcpContract.js +5 -0
- package/dist/mcp/dynamic-chain-executor.d.ts +201 -0
- package/dist/mcp/dynamic-chain-executor.js +489 -0
- package/dist/mcp/dynamic-orchestrator.d.ts +109 -0
- package/dist/mcp/dynamic-orchestrator.js +351 -0
- package/dist/mcp/error-manager.d.ts +254 -0
- package/dist/mcp/error-manager.js +501 -0
- package/dist/mcp/error-recovery.d.ts +158 -0
- package/dist/mcp/error-recovery.js +405 -0
- package/dist/mcp/function-calling.js +11 -3
- package/dist/mcp/health-monitor.d.ts +256 -0
- package/dist/mcp/health-monitor.js +621 -0
- package/dist/mcp/logging.js +5 -0
- package/dist/mcp/neurolink-mcp-client.js +2 -1
- package/dist/mcp/orchestrator.d.ts +136 -5
- package/dist/mcp/orchestrator.js +332 -16
- package/dist/mcp/plugins/core/neurolink-mcp.json +15 -15
- package/dist/mcp/registry.d.ts +71 -16
- package/dist/mcp/registry.js +104 -6
- package/dist/mcp/semaphore-manager.d.ts +137 -0
- package/dist/mcp/semaphore-manager.js +329 -0
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.d.ts +2 -2
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.js +5 -4
- package/dist/mcp/session-manager.d.ts +186 -0
- package/dist/mcp/session-manager.js +400 -0
- package/dist/mcp/session-persistence.d.ts +93 -0
- package/dist/mcp/session-persistence.js +299 -0
- package/dist/mcp/tool-integration.js +1 -1
- package/dist/mcp/tool-registry.d.ts +55 -34
- package/dist/mcp/tool-registry.js +111 -97
- package/dist/mcp/transport-manager.d.ts +153 -0
- package/dist/mcp/transport-manager.js +331 -0
- package/dist/mcp/unified-mcp.js +6 -1
- package/dist/mcp/unified-registry.d.ts +54 -5
- package/dist/mcp/unified-registry.js +139 -6
- package/dist/neurolink.d.ts +101 -0
- package/dist/neurolink.js +147 -1
- package/dist/providers/agent-enhanced-provider.d.ts +11 -2
- package/dist/providers/agent-enhanced-provider.js +86 -15
- package/dist/providers/amazonBedrock.d.ts +9 -1
- package/dist/providers/amazonBedrock.js +26 -2
- package/dist/providers/analytics-helper.d.ts +53 -0
- package/dist/providers/analytics-helper.js +151 -0
- package/dist/providers/anthropic.d.ts +11 -1
- package/dist/providers/anthropic.js +29 -4
- package/dist/providers/azureOpenAI.d.ts +3 -1
- package/dist/providers/azureOpenAI.js +29 -4
- package/dist/providers/function-calling-provider.d.ts +9 -1
- package/dist/providers/function-calling-provider.js +14 -1
- package/dist/providers/googleAIStudio.d.ts +15 -1
- package/dist/providers/googleAIStudio.js +32 -2
- package/dist/providers/googleVertexAI.d.ts +9 -1
- package/dist/providers/googleVertexAI.js +31 -2
- package/dist/providers/huggingFace.d.ts +3 -1
- package/dist/providers/huggingFace.js +26 -3
- package/dist/providers/mcp-provider.d.ts +9 -1
- package/dist/providers/mcp-provider.js +12 -0
- package/dist/providers/mistralAI.d.ts +3 -1
- package/dist/providers/mistralAI.js +25 -2
- package/dist/providers/ollama.d.ts +3 -1
- package/dist/providers/ollama.js +27 -4
- package/dist/providers/openAI.d.ts +15 -1
- package/dist/providers/openAI.js +33 -2
- package/dist/proxy/proxy-fetch.js +8 -7
- package/dist/services/streaming/streaming-manager.d.ts +29 -0
- package/dist/services/streaming/streaming-manager.js +244 -0
- package/dist/services/types.d.ts +155 -0
- package/dist/services/types.js +2 -0
- package/dist/services/websocket/websocket-server.d.ts +34 -0
- package/dist/services/websocket/websocket-server.js +304 -0
- package/dist/telemetry/index.d.ts +15 -0
- package/dist/telemetry/index.js +22 -0
- package/dist/telemetry/telemetry-service.d.ts +47 -0
- package/dist/telemetry/telemetry-service.js +261 -0
- package/dist/utils/streaming-utils.d.ts +67 -0
- package/dist/utils/streaming-utils.js +201 -0
- package/package.json +245 -228
|
@@ -7,9 +7,13 @@ import { google } from "@ai-sdk/google";
|
|
|
7
7
|
import { openai } from "@ai-sdk/openai";
|
|
8
8
|
import { anthropic } from "@ai-sdk/anthropic";
|
|
9
9
|
import { directAgentTools, getToolsForCategory, } from "../agent/direct-tools.js";
|
|
10
|
+
import { StreamingEnhancer, StreamingMonitor, } from "../utils/streaming-utils.js";
|
|
10
11
|
import { UnifiedMCPSystem } from "../mcp/unified-mcp.js";
|
|
11
12
|
import { mcpLogger } from "../mcp/logging.js";
|
|
12
13
|
import { parseTimeout } from "../utils/timeout.js";
|
|
14
|
+
import { evaluateResponse } from "../core/evaluation.js";
|
|
15
|
+
import { createAnalytics } from "../core/analytics.js";
|
|
16
|
+
import { logger } from "../utils/logger.js";
|
|
13
17
|
/**
|
|
14
18
|
* Agent-Enhanced Provider Class
|
|
15
19
|
* Provides AI generation with tool calling capabilities
|
|
@@ -18,6 +22,7 @@ import { parseTimeout } from "../utils/timeout.js";
|
|
|
18
22
|
export class AgentEnhancedProvider {
|
|
19
23
|
config;
|
|
20
24
|
model;
|
|
25
|
+
resolvedModelName = "default";
|
|
21
26
|
mcpSystem = null;
|
|
22
27
|
mcpInitialized = false;
|
|
23
28
|
mcpInitializing = false;
|
|
@@ -35,7 +40,7 @@ export class AgentEnhancedProvider {
|
|
|
35
40
|
},
|
|
36
41
|
...config,
|
|
37
42
|
};
|
|
38
|
-
// Initialize the AI model based on provider
|
|
43
|
+
// Initialize the AI model based on provider and store resolved model name
|
|
39
44
|
this.model = this.createModel();
|
|
40
45
|
// Initialize MCP registry if enabled
|
|
41
46
|
if (this.config.enableMCP) {
|
|
@@ -46,11 +51,16 @@ export class AgentEnhancedProvider {
|
|
|
46
51
|
const { provider, model } = this.config;
|
|
47
52
|
switch (provider) {
|
|
48
53
|
case "google-ai":
|
|
49
|
-
|
|
54
|
+
this.resolvedModelName =
|
|
55
|
+
model || process.env.GOOGLE_AI_MODEL || "gemini-2.5-flash";
|
|
56
|
+
return google(this.resolvedModelName);
|
|
50
57
|
case "openai":
|
|
51
|
-
|
|
58
|
+
this.resolvedModelName = model || process.env.OPENAI_MODEL || "gpt-4o";
|
|
59
|
+
return openai(this.resolvedModelName);
|
|
52
60
|
case "anthropic":
|
|
53
|
-
|
|
61
|
+
this.resolvedModelName =
|
|
62
|
+
model || process.env.ANTHROPIC_MODEL || "claude-3-5-sonnet-20241022";
|
|
63
|
+
return anthropic(this.resolvedModelName);
|
|
54
64
|
default:
|
|
55
65
|
throw new Error(`Unsupported provider: ${provider}`);
|
|
56
66
|
}
|
|
@@ -249,6 +259,7 @@ export class AgentEnhancedProvider {
|
|
|
249
259
|
return { ...directTools, ...mcpTools };
|
|
250
260
|
}
|
|
251
261
|
async generateText(optionsOrPrompt) {
|
|
262
|
+
const startTime = Date.now();
|
|
252
263
|
const options = typeof optionsOrPrompt === "string"
|
|
253
264
|
? { prompt: optionsOrPrompt }
|
|
254
265
|
: optionsOrPrompt;
|
|
@@ -352,6 +363,14 @@ export class AgentEnhancedProvider {
|
|
|
352
363
|
};
|
|
353
364
|
}
|
|
354
365
|
}
|
|
366
|
+
// Add analytics if enabled
|
|
367
|
+
if (options.enableAnalytics) {
|
|
368
|
+
result.analytics = createAnalytics(this.config.provider, this.resolvedModelName, result, Date.now() - startTime, options.context);
|
|
369
|
+
}
|
|
370
|
+
// Add evaluation if enabled
|
|
371
|
+
if (options.enableEvaluation) {
|
|
372
|
+
result.evaluation = await evaluateResponse(prompt, result.text, options.context);
|
|
373
|
+
}
|
|
355
374
|
// Return the full result - the AI SDK has already handled tool execution and integration
|
|
356
375
|
return result;
|
|
357
376
|
}
|
|
@@ -364,7 +383,15 @@ export class AgentEnhancedProvider {
|
|
|
364
383
|
const options = typeof optionsOrPrompt === "string"
|
|
365
384
|
? { prompt: optionsOrPrompt }
|
|
366
385
|
: optionsOrPrompt;
|
|
367
|
-
const { prompt, temperature = 0.7, maxTokens = 1000, systemPrompt, timeout,
|
|
386
|
+
const { prompt, temperature = 0.7, maxTokens = 1000, systemPrompt, timeout,
|
|
387
|
+
// Phase 2: Enhanced streaming options
|
|
388
|
+
enableProgressTracking, progressCallback, includeStreamingMetadata, streamingBufferSize, enableStreamingHeaders, customStreamingConfig, } = options;
|
|
389
|
+
// Phase 2.1: Setup streaming enhancements
|
|
390
|
+
const streamId = `agent_stream_${Date.now()}`;
|
|
391
|
+
const streamingConfig = StreamingEnhancer.createStreamingConfig(options);
|
|
392
|
+
if (enableProgressTracking) {
|
|
393
|
+
StreamingMonitor.registerStream(streamId);
|
|
394
|
+
}
|
|
368
395
|
// Get combined tools (direct + MCP) if enabled
|
|
369
396
|
const tools = this.config.enableTools ? await this.getCombinedTools() : {};
|
|
370
397
|
try {
|
|
@@ -388,6 +415,38 @@ export class AgentEnhancedProvider {
|
|
|
388
415
|
toolChoice: this.shouldForceToolUsage(prompt) ? "required" : "auto",
|
|
389
416
|
abortSignal, // Pass abort signal for timeout support
|
|
390
417
|
});
|
|
418
|
+
// Phase 2.1: Apply streaming enhancements if enabled
|
|
419
|
+
if (streamingConfig.progressTracking && result.textStream) {
|
|
420
|
+
const enhancedCallback = streamingConfig.callback
|
|
421
|
+
? (progress) => {
|
|
422
|
+
StreamingMonitor.updateStream(streamId, progress);
|
|
423
|
+
streamingConfig.callback(progress);
|
|
424
|
+
if (progress.phase === "complete") {
|
|
425
|
+
StreamingMonitor.completeStream(streamId);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
: undefined;
|
|
429
|
+
// Enhance the stream with progress tracking
|
|
430
|
+
const enhancedStream = StreamingEnhancer.addProgressTracking(result.textStream, enhancedCallback, { streamId, bufferSize: streamingConfig.bufferSize });
|
|
431
|
+
// Return enhanced result with tracking
|
|
432
|
+
return {
|
|
433
|
+
...result,
|
|
434
|
+
textStream: enhancedStream,
|
|
435
|
+
// Phase 2.1: Add streaming metadata
|
|
436
|
+
streamingMetadata: streamingConfig.metadata
|
|
437
|
+
? {
|
|
438
|
+
streamId,
|
|
439
|
+
provider: this.getProviderName(),
|
|
440
|
+
model: this.getModelName(),
|
|
441
|
+
enabledFeatures: {
|
|
442
|
+
progressTracking: true,
|
|
443
|
+
metadata: streamingConfig.metadata,
|
|
444
|
+
headers: streamingConfig.headers,
|
|
445
|
+
},
|
|
446
|
+
}
|
|
447
|
+
: undefined,
|
|
448
|
+
};
|
|
449
|
+
}
|
|
391
450
|
return result;
|
|
392
451
|
}
|
|
393
452
|
catch (error) {
|
|
@@ -440,7 +499,7 @@ export class AgentEnhancedProvider {
|
|
|
440
499
|
let successCount = 0;
|
|
441
500
|
for (const prompt of testPrompts) {
|
|
442
501
|
try {
|
|
443
|
-
|
|
502
|
+
logger.debug(`Testing: "${prompt}"`);
|
|
444
503
|
const result = await this.generateText(prompt);
|
|
445
504
|
if (!result) {
|
|
446
505
|
results.push({
|
|
@@ -448,7 +507,7 @@ export class AgentEnhancedProvider {
|
|
|
448
507
|
success: false,
|
|
449
508
|
error: "No result returned from generateText",
|
|
450
509
|
});
|
|
451
|
-
|
|
510
|
+
logger.warn(`❌ No result returned`);
|
|
452
511
|
continue;
|
|
453
512
|
}
|
|
454
513
|
const toolsCalled = result.toolCalls?.length || 0;
|
|
@@ -462,7 +521,7 @@ export class AgentEnhancedProvider {
|
|
|
462
521
|
toolsCalled,
|
|
463
522
|
response: result.text.substring(0, 100) + "...",
|
|
464
523
|
});
|
|
465
|
-
|
|
524
|
+
logger.debug(`✅ Tools called: ${toolsCalled}, Response: ${result.text.substring(0, 50)}...`);
|
|
466
525
|
}
|
|
467
526
|
catch (error) {
|
|
468
527
|
results.push({
|
|
@@ -470,7 +529,7 @@ export class AgentEnhancedProvider {
|
|
|
470
529
|
success: false,
|
|
471
530
|
error: error instanceof Error ? error.message : String(error),
|
|
472
531
|
});
|
|
473
|
-
|
|
532
|
+
logger.error(`❌ Error: ${error}`);
|
|
474
533
|
}
|
|
475
534
|
}
|
|
476
535
|
return {
|
|
@@ -505,6 +564,18 @@ export class AgentEnhancedProvider {
|
|
|
505
564
|
}
|
|
506
565
|
return providers;
|
|
507
566
|
}
|
|
567
|
+
/**
|
|
568
|
+
* Alias for generateText() - CLI-SDK consistency
|
|
569
|
+
*/
|
|
570
|
+
async generate(optionsOrPrompt, analysisSchema) {
|
|
571
|
+
return this.generateText(optionsOrPrompt);
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Short alias for generateText() - CLI-SDK consistency
|
|
575
|
+
*/
|
|
576
|
+
async gen(optionsOrPrompt, analysisSchema) {
|
|
577
|
+
return this.generateText(optionsOrPrompt);
|
|
578
|
+
}
|
|
508
579
|
}
|
|
509
580
|
/**
|
|
510
581
|
* Helper function to create agent provider
|
|
@@ -519,25 +590,25 @@ export function createAgentProvider(provider, options) {
|
|
|
519
590
|
* Test all available agent providers
|
|
520
591
|
*/
|
|
521
592
|
export async function testAllAgentProviders() {
|
|
522
|
-
|
|
593
|
+
logger.info("🧪 Testing All Agent Providers\n");
|
|
523
594
|
const providers = AgentEnhancedProvider.createMultiProviderAgents();
|
|
524
595
|
if (Object.keys(providers).length === 0) {
|
|
525
|
-
|
|
596
|
+
logger.warn("❌ No API keys found. Please configure at least one provider.");
|
|
526
597
|
return;
|
|
527
598
|
}
|
|
528
599
|
for (const [name, provider] of Object.entries(providers)) {
|
|
529
|
-
|
|
600
|
+
logger.info(`\n🔬 Testing ${name.toUpperCase()} Agent Provider:`);
|
|
530
601
|
try {
|
|
531
602
|
const testResult = await provider.testAgentCapabilities();
|
|
532
603
|
if (testResult.success) {
|
|
533
|
-
|
|
604
|
+
logger.info(`✅ ${name} agent provider working correctly`);
|
|
534
605
|
}
|
|
535
606
|
else {
|
|
536
|
-
|
|
607
|
+
logger.warn(`❌ ${name} agent provider failed tests`);
|
|
537
608
|
}
|
|
538
609
|
}
|
|
539
610
|
catch (error) {
|
|
540
|
-
|
|
611
|
+
logger.error(`❌ ${name} provider error:`, error);
|
|
541
612
|
}
|
|
542
613
|
}
|
|
543
614
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ZodType, ZodTypeDef } from "zod";
|
|
2
2
|
import { type StreamTextResult, type ToolSet, type Schema, type GenerateTextResult } from "ai";
|
|
3
|
-
import type { AIProvider, TextGenerationOptions, StreamTextOptions } from "../core/types.js";
|
|
3
|
+
import type { AIProvider, TextGenerationOptions, StreamTextOptions, EnhancedGenerateTextResult } from "../core/types.js";
|
|
4
4
|
export declare class AmazonBedrock implements AIProvider {
|
|
5
5
|
private modelName;
|
|
6
6
|
private model;
|
|
@@ -8,4 +8,12 @@ export declare class AmazonBedrock implements AIProvider {
|
|
|
8
8
|
constructor(modelName?: string | null);
|
|
9
9
|
streamText(optionsOrPrompt: StreamTextOptions | string, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<StreamTextResult<ToolSet, unknown> | null>;
|
|
10
10
|
generateText(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<GenerateTextResult<ToolSet, unknown> | null>;
|
|
11
|
+
/**
|
|
12
|
+
* Alias for generateText() - CLI-SDK consistency
|
|
13
|
+
*/
|
|
14
|
+
generate(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<EnhancedGenerateTextResult | null>;
|
|
15
|
+
/**
|
|
16
|
+
* Short alias for generateText() - CLI-SDK consistency
|
|
17
|
+
*/
|
|
18
|
+
gen(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<EnhancedGenerateTextResult | null>;
|
|
11
19
|
}
|
|
@@ -2,6 +2,9 @@ import { createAmazonBedrock } from "@ai-sdk/amazon-bedrock";
|
|
|
2
2
|
import { streamText, generateText, Output, } from "ai";
|
|
3
3
|
import { logger } from "../utils/logger.js";
|
|
4
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";
|
|
5
8
|
// Default system context
|
|
6
9
|
const DEFAULT_SYSTEM_CONTEXT = {
|
|
7
10
|
systemPrompt: "You are a helpful AI assistant.",
|
|
@@ -129,7 +132,7 @@ export class AmazonBedrock {
|
|
|
129
132
|
const options = typeof optionsOrPrompt === "string"
|
|
130
133
|
? { prompt: optionsOrPrompt }
|
|
131
134
|
: optionsOrPrompt;
|
|
132
|
-
const { prompt, temperature = 0.7, maxTokens =
|
|
135
|
+
const { prompt, temperature = 0.7, maxTokens = DEFAULT_MAX_TOKENS, systemPrompt = DEFAULT_SYSTEM_CONTEXT.systemPrompt, schema, timeout = getDefaultTimeout(provider, "stream"), } = options;
|
|
133
136
|
// Use schema from options or fallback parameter
|
|
134
137
|
const finalSchema = schema || analysisSchema;
|
|
135
138
|
logger.debug(`[${functionTag}] Stream request started`, {
|
|
@@ -231,12 +234,13 @@ export class AmazonBedrock {
|
|
|
231
234
|
async generateText(optionsOrPrompt, analysisSchema) {
|
|
232
235
|
const functionTag = "AmazonBedrock.generateText";
|
|
233
236
|
const provider = "bedrock";
|
|
237
|
+
const startTime = Date.now();
|
|
234
238
|
try {
|
|
235
239
|
// Parse parameters - support both string and options object
|
|
236
240
|
const options = typeof optionsOrPrompt === "string"
|
|
237
241
|
? { prompt: optionsOrPrompt }
|
|
238
242
|
: optionsOrPrompt;
|
|
239
|
-
const { prompt, temperature = 0.7, maxTokens =
|
|
243
|
+
const { prompt, temperature = 0.7, maxTokens = DEFAULT_MAX_TOKENS, systemPrompt = DEFAULT_SYSTEM_CONTEXT.systemPrompt, schema, timeout = getDefaultTimeout(provider, "generate"), } = options;
|
|
240
244
|
// Use schema from options or fallback parameter
|
|
241
245
|
const finalSchema = schema || analysisSchema;
|
|
242
246
|
logger.debug(`[${functionTag}] Generate text started`, {
|
|
@@ -278,6 +282,14 @@ export class AmazonBedrock {
|
|
|
278
282
|
responseLength: result.text?.length || 0,
|
|
279
283
|
timeout,
|
|
280
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
|
+
}
|
|
281
293
|
return result;
|
|
282
294
|
}
|
|
283
295
|
finally {
|
|
@@ -307,4 +319,16 @@ export class AmazonBedrock {
|
|
|
307
319
|
throw err; // Re-throw error to trigger fallback instead of returning null
|
|
308
320
|
}
|
|
309
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
|
+
}
|
|
310
334
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enhanced Analytics Helper for All Providers
|
|
3
|
+
* Ensures consistent analytics data format across providers
|
|
4
|
+
* Integrates with Universal Evaluation System
|
|
5
|
+
*/
|
|
6
|
+
export interface AnalyticsData {
|
|
7
|
+
provider: string;
|
|
8
|
+
model: string;
|
|
9
|
+
tokens: {
|
|
10
|
+
input: number;
|
|
11
|
+
output: number;
|
|
12
|
+
total: number;
|
|
13
|
+
};
|
|
14
|
+
cost?: number;
|
|
15
|
+
responseTime: number;
|
|
16
|
+
timestamp: string;
|
|
17
|
+
context?: Record<string, any>;
|
|
18
|
+
evaluation?: {
|
|
19
|
+
relevanceScore: number;
|
|
20
|
+
accuracyScore: number;
|
|
21
|
+
completenessScore: number;
|
|
22
|
+
overall: number;
|
|
23
|
+
evaluationProvider?: string;
|
|
24
|
+
evaluationTime?: number;
|
|
25
|
+
evaluationAttempt?: number;
|
|
26
|
+
};
|
|
27
|
+
costDetails?: {
|
|
28
|
+
inputCost: number;
|
|
29
|
+
outputCost: number;
|
|
30
|
+
evaluationCost?: number;
|
|
31
|
+
totalCost: number;
|
|
32
|
+
currency: string;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Create standardized analytics data from provider response
|
|
37
|
+
*/
|
|
38
|
+
export declare function createAnalytics(provider: string, model: string, result: any, responseTime: number, context?: Record<string, any>): AnalyticsData;
|
|
39
|
+
/**
|
|
40
|
+
* Create enhanced analytics data with accurate cost calculations (async version)
|
|
41
|
+
*/
|
|
42
|
+
export declare function createEnhancedAnalytics(provider: string, model: string, result: any, responseTime: number, context?: Record<string, any>): Promise<AnalyticsData>;
|
|
43
|
+
/**
|
|
44
|
+
* Calculate enhanced cost details using provider configurations
|
|
45
|
+
*/
|
|
46
|
+
export declare function calculateEnhancedCost(provider: string, inputTokens: number, outputTokens: number): Promise<{
|
|
47
|
+
costDetails: any;
|
|
48
|
+
estimatedCost: number;
|
|
49
|
+
}>;
|
|
50
|
+
/**
|
|
51
|
+
* Enhance analytics with evaluation data
|
|
52
|
+
*/
|
|
53
|
+
export declare function enhanceAnalyticsWithEvaluation(analytics: AnalyticsData, evaluationResult: any): AnalyticsData;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enhanced Analytics Helper for All Providers
|
|
3
|
+
* Ensures consistent analytics data format across providers
|
|
4
|
+
* Integrates with Universal Evaluation System
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Create standardized analytics data from provider response
|
|
8
|
+
*/
|
|
9
|
+
export function createAnalytics(provider, model, result, responseTime, context) {
|
|
10
|
+
// Handle different token usage formats across providers
|
|
11
|
+
const tokenUsage = result.usage || {};
|
|
12
|
+
// Standardize token field names across providers
|
|
13
|
+
const inputTokens = tokenUsage.promptTokens ||
|
|
14
|
+
tokenUsage.input_tokens ||
|
|
15
|
+
tokenUsage.inputTokens ||
|
|
16
|
+
0;
|
|
17
|
+
const outputTokens = tokenUsage.completionTokens ||
|
|
18
|
+
tokenUsage.output_tokens ||
|
|
19
|
+
tokenUsage.outputTokens ||
|
|
20
|
+
0;
|
|
21
|
+
const totalTokens = tokenUsage.totalTokens ||
|
|
22
|
+
tokenUsage.total_tokens ||
|
|
23
|
+
inputTokens + outputTokens ||
|
|
24
|
+
0;
|
|
25
|
+
// Simple cost estimation for synchronous use
|
|
26
|
+
const estimatedCost = totalTokens > 0 ? totalTokens * 0.00001 : 0;
|
|
27
|
+
return {
|
|
28
|
+
provider,
|
|
29
|
+
model,
|
|
30
|
+
tokens: {
|
|
31
|
+
input: inputTokens,
|
|
32
|
+
output: outputTokens,
|
|
33
|
+
total: totalTokens,
|
|
34
|
+
},
|
|
35
|
+
cost: estimatedCost,
|
|
36
|
+
responseTime,
|
|
37
|
+
timestamp: new Date().toISOString(),
|
|
38
|
+
context,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Create enhanced analytics data with accurate cost calculations (async version)
|
|
43
|
+
*/
|
|
44
|
+
export async function createEnhancedAnalytics(provider, model, result, responseTime, context) {
|
|
45
|
+
// Handle different token usage formats across providers
|
|
46
|
+
const tokenUsage = result.usage || {};
|
|
47
|
+
// Standardize token field names across providers
|
|
48
|
+
const inputTokens = tokenUsage.promptTokens ||
|
|
49
|
+
tokenUsage.input_tokens ||
|
|
50
|
+
tokenUsage.inputTokens ||
|
|
51
|
+
0;
|
|
52
|
+
const outputTokens = tokenUsage.completionTokens ||
|
|
53
|
+
tokenUsage.output_tokens ||
|
|
54
|
+
tokenUsage.outputTokens ||
|
|
55
|
+
0;
|
|
56
|
+
const totalTokens = tokenUsage.totalTokens ||
|
|
57
|
+
tokenUsage.total_tokens ||
|
|
58
|
+
inputTokens + outputTokens ||
|
|
59
|
+
0;
|
|
60
|
+
// Enhanced cost calculation using provider configuration
|
|
61
|
+
const { costDetails, estimatedCost } = await calculateEnhancedCost(provider, inputTokens, outputTokens);
|
|
62
|
+
return {
|
|
63
|
+
provider,
|
|
64
|
+
model,
|
|
65
|
+
tokens: {
|
|
66
|
+
input: inputTokens,
|
|
67
|
+
output: outputTokens,
|
|
68
|
+
total: totalTokens,
|
|
69
|
+
},
|
|
70
|
+
cost: estimatedCost,
|
|
71
|
+
responseTime,
|
|
72
|
+
timestamp: new Date().toISOString(),
|
|
73
|
+
context,
|
|
74
|
+
costDetails,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Calculate enhanced cost details using provider configurations
|
|
79
|
+
*/
|
|
80
|
+
export async function calculateEnhancedCost(provider, inputTokens, outputTokens) {
|
|
81
|
+
try {
|
|
82
|
+
// Import provider configuration dynamically
|
|
83
|
+
const { getProviderConfig } = await import("../core/evaluation-providers.js");
|
|
84
|
+
const providerConfig = getProviderConfig(provider);
|
|
85
|
+
if (!providerConfig?.costPerToken) {
|
|
86
|
+
// Fallback to rough estimation
|
|
87
|
+
const estimatedCost = (inputTokens + outputTokens) * 0.00001;
|
|
88
|
+
return {
|
|
89
|
+
costDetails: {
|
|
90
|
+
inputCost: inputTokens * 0.00001,
|
|
91
|
+
outputCost: outputTokens * 0.00001,
|
|
92
|
+
totalCost: estimatedCost,
|
|
93
|
+
currency: "USD",
|
|
94
|
+
},
|
|
95
|
+
estimatedCost,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
// Use accurate provider costs
|
|
99
|
+
const inputCost = inputTokens * providerConfig.costPerToken.input;
|
|
100
|
+
const outputCost = outputTokens * providerConfig.costPerToken.output;
|
|
101
|
+
const totalCost = inputCost + outputCost;
|
|
102
|
+
return {
|
|
103
|
+
costDetails: {
|
|
104
|
+
inputCost,
|
|
105
|
+
outputCost,
|
|
106
|
+
totalCost,
|
|
107
|
+
currency: "USD",
|
|
108
|
+
},
|
|
109
|
+
estimatedCost: totalCost,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
// Fallback on error
|
|
114
|
+
const estimatedCost = (inputTokens + outputTokens) * 0.00001;
|
|
115
|
+
return {
|
|
116
|
+
costDetails: {
|
|
117
|
+
inputCost: inputTokens * 0.00001,
|
|
118
|
+
outputCost: outputTokens * 0.00001,
|
|
119
|
+
totalCost: estimatedCost,
|
|
120
|
+
currency: "USD",
|
|
121
|
+
},
|
|
122
|
+
estimatedCost,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Enhance analytics with evaluation data
|
|
128
|
+
*/
|
|
129
|
+
export function enhanceAnalyticsWithEvaluation(analytics, evaluationResult) {
|
|
130
|
+
return {
|
|
131
|
+
...analytics,
|
|
132
|
+
evaluation: {
|
|
133
|
+
relevanceScore: evaluationResult.relevanceScore || 0,
|
|
134
|
+
accuracyScore: evaluationResult.accuracyScore || 0,
|
|
135
|
+
completenessScore: evaluationResult.completenessScore || 0,
|
|
136
|
+
overall: evaluationResult.overall || 0,
|
|
137
|
+
evaluationProvider: evaluationResult.evaluationProvider,
|
|
138
|
+
evaluationTime: evaluationResult.evaluationTime,
|
|
139
|
+
evaluationAttempt: evaluationResult.evaluationAttempt,
|
|
140
|
+
},
|
|
141
|
+
// Add evaluation cost if available
|
|
142
|
+
costDetails: analytics.costDetails
|
|
143
|
+
? {
|
|
144
|
+
...analytics.costDetails,
|
|
145
|
+
evaluationCost: evaluationResult.evaluationConfig?.costEstimate || 0,
|
|
146
|
+
totalCost: (analytics.costDetails.totalCost || 0) +
|
|
147
|
+
(evaluationResult.evaluationConfig?.costEstimate || 0),
|
|
148
|
+
}
|
|
149
|
+
: undefined,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
* Direct integration with Anthropic's Claude models via their native API.
|
|
5
5
|
* Supports Claude 3.5 Sonnet, Claude 3.5 Haiku, and Claude 3 Opus.
|
|
6
6
|
*/
|
|
7
|
-
import type { AIProvider, TextGenerationOptions, StreamTextOptions } from "../core/types.js";
|
|
7
|
+
import type { AIProvider, TextGenerationOptions, StreamTextOptions, EnhancedGenerateTextResult } from "../core/types.js";
|
|
8
|
+
import type { ZodType, ZodTypeDef } from "zod";
|
|
9
|
+
import type { Schema } from "ai";
|
|
8
10
|
import { AIProviderName } from "../core/types.js";
|
|
9
11
|
export declare class AnthropicProvider implements AIProvider {
|
|
10
12
|
readonly name: AIProviderName;
|
|
@@ -31,4 +33,12 @@ export declare class AnthropicProvider implements AIProvider {
|
|
|
31
33
|
supportsStreaming(): boolean;
|
|
32
34
|
supportsSchema(): boolean;
|
|
33
35
|
getCapabilities(): string[];
|
|
36
|
+
/**
|
|
37
|
+
* Alias for generateText() - CLI-SDK consistency
|
|
38
|
+
*/
|
|
39
|
+
generate(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<EnhancedGenerateTextResult | null>;
|
|
40
|
+
/**
|
|
41
|
+
* Short alias for generateText() - CLI-SDK consistency
|
|
42
|
+
*/
|
|
43
|
+
gen(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<EnhancedGenerateTextResult | null>;
|
|
34
44
|
}
|
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
import { AIProviderName } from "../core/types.js";
|
|
8
8
|
import { logger } from "../utils/logger.js";
|
|
9
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
|
+
import { createAnalytics } from "../core/analytics.js";
|
|
10
13
|
import { createProxyFetch } from "../proxy/proxy-fetch.js";
|
|
11
14
|
export class AnthropicProvider {
|
|
12
15
|
name = AIProviderName.ANTHROPIC;
|
|
@@ -58,12 +61,13 @@ export class AnthropicProvider {
|
|
|
58
61
|
async generateText(optionsOrPrompt, schema) {
|
|
59
62
|
const functionTag = "AnthropicProvider.generateText";
|
|
60
63
|
const provider = "anthropic";
|
|
64
|
+
const startTime = Date.now();
|
|
61
65
|
logger.debug(`[${functionTag}] Starting text generation`);
|
|
62
66
|
// Parse parameters with backward compatibility
|
|
63
67
|
const options = typeof optionsOrPrompt === "string"
|
|
64
68
|
? { prompt: optionsOrPrompt }
|
|
65
69
|
: optionsOrPrompt;
|
|
66
|
-
const { prompt, temperature = 0.7, maxTokens =
|
|
70
|
+
const { prompt, temperature = 0.7, maxTokens = DEFAULT_MAX_TOKENS, systemPrompt = "You are Claude, an AI assistant created by Anthropic. You are helpful, harmless, and honest.", timeout = getDefaultTimeout(provider, "generate"), enableAnalytics = false, enableEvaluation = false, context, } = options;
|
|
67
71
|
logger.debug(`[${functionTag}] Prompt: "${prompt.substring(0, 100)}...", Temperature: ${temperature}, Max tokens: ${maxTokens}, Timeout: ${timeout}`);
|
|
68
72
|
const requestBody = {
|
|
69
73
|
model: this.getModel(),
|
|
@@ -86,7 +90,7 @@ export class AnthropicProvider {
|
|
|
86
90
|
timeoutController?.cleanup();
|
|
87
91
|
logger.debug(`[${functionTag}] Success. Generated ${data.usage.output_tokens} tokens`);
|
|
88
92
|
const content = data.content.map((block) => block.text).join("");
|
|
89
|
-
|
|
93
|
+
const result = {
|
|
90
94
|
content,
|
|
91
95
|
provider: this.name,
|
|
92
96
|
model: data.model,
|
|
@@ -97,6 +101,15 @@ export class AnthropicProvider {
|
|
|
97
101
|
},
|
|
98
102
|
finishReason: data.stop_reason,
|
|
99
103
|
};
|
|
104
|
+
// Add analytics if enabled
|
|
105
|
+
if (options.enableAnalytics) {
|
|
106
|
+
result.analytics = createAnalytics(provider, this.defaultModel, result, Date.now() - startTime, options.context);
|
|
107
|
+
}
|
|
108
|
+
// Add evaluation if enabled
|
|
109
|
+
if (options.enableEvaluation) {
|
|
110
|
+
result.evaluation = await evaluateResponse(prompt, result.content, options.context);
|
|
111
|
+
}
|
|
112
|
+
return result;
|
|
100
113
|
}
|
|
101
114
|
catch (error) {
|
|
102
115
|
// Always cleanup timeout
|
|
@@ -133,7 +146,7 @@ export class AnthropicProvider {
|
|
|
133
146
|
const options = typeof optionsOrPrompt === "string"
|
|
134
147
|
? { prompt: optionsOrPrompt }
|
|
135
148
|
: optionsOrPrompt;
|
|
136
|
-
const { prompt, temperature = 0.7, maxTokens =
|
|
149
|
+
const { prompt, temperature = 0.7, maxTokens = DEFAULT_MAX_TOKENS, systemPrompt = "You are Claude, an AI assistant created by Anthropic. You are helpful, harmless, and honest.", timeout = getDefaultTimeout(provider, "stream"), } = options;
|
|
137
150
|
logger.debug(`[${functionTag}] Streaming prompt: "${prompt.substring(0, 100)}...", Timeout: ${timeout}`);
|
|
138
151
|
const requestBody = {
|
|
139
152
|
model: this.getModel(),
|
|
@@ -243,7 +256,7 @@ export class AnthropicProvider {
|
|
|
243
256
|
const options = typeof optionsOrPrompt === "string"
|
|
244
257
|
? { prompt: optionsOrPrompt }
|
|
245
258
|
: optionsOrPrompt;
|
|
246
|
-
const { prompt, temperature = 0.7, maxTokens =
|
|
259
|
+
const { prompt, temperature = 0.7, maxTokens = DEFAULT_MAX_TOKENS, systemPrompt = "You are Claude, an AI assistant created by Anthropic. You are helpful, harmless, and honest.", } = options;
|
|
247
260
|
logger.debug(`[AnthropicProvider.generateTextStream] Streaming prompt: "${prompt.substring(0, 100)}..."`);
|
|
248
261
|
const requestBody = {
|
|
249
262
|
model: this.getModel(),
|
|
@@ -377,4 +390,16 @@ export class AnthropicProvider {
|
|
|
377
390
|
"long-context", // Claude models support up to 200k tokens
|
|
378
391
|
];
|
|
379
392
|
}
|
|
393
|
+
/**
|
|
394
|
+
* Alias for generateText() - CLI-SDK consistency
|
|
395
|
+
*/
|
|
396
|
+
async generate(optionsOrPrompt, analysisSchema) {
|
|
397
|
+
return this.generateText(optionsOrPrompt, analysisSchema);
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Short alias for generateText() - CLI-SDK consistency
|
|
401
|
+
*/
|
|
402
|
+
async gen(optionsOrPrompt, analysisSchema) {
|
|
403
|
+
return this.generateText(optionsOrPrompt, analysisSchema);
|
|
404
|
+
}
|
|
380
405
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Enterprise-grade OpenAI integration through Microsoft Azure.
|
|
5
5
|
* Supports all OpenAI models with enhanced security and compliance.
|
|
6
6
|
*/
|
|
7
|
-
import type { AIProvider, TextGenerationOptions, StreamTextOptions } from "../core/types.js";
|
|
7
|
+
import type { AIProvider, TextGenerationOptions, StreamTextOptions, EnhancedGenerateTextResult } from "../core/types.js";
|
|
8
8
|
import { AIProviderName } from "../core/types.js";
|
|
9
9
|
export declare class AzureOpenAIProvider implements AIProvider {
|
|
10
10
|
readonly name: AIProviderName;
|
|
@@ -34,4 +34,6 @@ export declare class AzureOpenAIProvider implements AIProvider {
|
|
|
34
34
|
supportsStreaming(): boolean;
|
|
35
35
|
supportsSchema(): boolean;
|
|
36
36
|
getCapabilities(): string[];
|
|
37
|
+
generate(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: any): Promise<EnhancedGenerateTextResult | null>;
|
|
38
|
+
gen(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: any): Promise<EnhancedGenerateTextResult | null>;
|
|
37
39
|
}
|