@juspay/neurolink 7.7.1 → 7.9.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 +25 -2
- package/README.md +34 -2
- package/dist/cli/commands/config.d.ts +3 -3
- package/dist/cli/commands/sagemaker.d.ts +11 -0
- package/dist/cli/commands/sagemaker.js +778 -0
- package/dist/cli/factories/commandFactory.js +7 -2
- package/dist/cli/index.js +3 -0
- package/dist/cli/utils/interactiveSetup.js +28 -0
- package/dist/core/baseProvider.d.ts +2 -2
- package/dist/core/types.d.ts +16 -4
- package/dist/core/types.js +24 -3
- package/dist/factories/providerFactory.js +10 -1
- package/dist/factories/providerRegistry.js +6 -1
- package/dist/lib/core/baseProvider.d.ts +2 -2
- package/dist/lib/core/types.d.ts +16 -4
- package/dist/lib/core/types.js +24 -3
- package/dist/lib/factories/providerFactory.js +10 -1
- package/dist/lib/factories/providerRegistry.js +6 -1
- package/dist/lib/neurolink.d.ts +15 -0
- package/dist/lib/neurolink.js +73 -1
- package/dist/lib/providers/amazonSagemaker.d.ts +67 -0
- package/dist/lib/providers/amazonSagemaker.js +149 -0
- package/dist/lib/providers/googleVertex.d.ts +4 -0
- package/dist/lib/providers/googleVertex.js +44 -3
- package/dist/lib/providers/index.d.ts +4 -0
- package/dist/lib/providers/index.js +4 -0
- package/dist/lib/providers/sagemaker/adaptive-semaphore.d.ts +86 -0
- package/dist/lib/providers/sagemaker/adaptive-semaphore.js +212 -0
- package/dist/lib/providers/sagemaker/client.d.ts +156 -0
- package/dist/lib/providers/sagemaker/client.js +462 -0
- package/dist/lib/providers/sagemaker/config.d.ts +73 -0
- package/dist/lib/providers/sagemaker/config.js +308 -0
- package/dist/lib/providers/sagemaker/detection.d.ts +176 -0
- package/dist/lib/providers/sagemaker/detection.js +596 -0
- package/dist/lib/providers/sagemaker/diagnostics.d.ts +37 -0
- package/dist/lib/providers/sagemaker/diagnostics.js +137 -0
- package/dist/lib/providers/sagemaker/error-constants.d.ts +78 -0
- package/dist/lib/providers/sagemaker/error-constants.js +227 -0
- package/dist/lib/providers/sagemaker/errors.d.ts +83 -0
- package/dist/lib/providers/sagemaker/errors.js +216 -0
- package/dist/lib/providers/sagemaker/index.d.ts +35 -0
- package/dist/lib/providers/sagemaker/index.js +67 -0
- package/dist/lib/providers/sagemaker/language-model.d.ts +182 -0
- package/dist/lib/providers/sagemaker/language-model.js +755 -0
- package/dist/lib/providers/sagemaker/parsers.d.ts +136 -0
- package/dist/lib/providers/sagemaker/parsers.js +625 -0
- package/dist/lib/providers/sagemaker/streaming.d.ts +39 -0
- package/dist/lib/providers/sagemaker/streaming.js +320 -0
- package/dist/lib/providers/sagemaker/structured-parser.d.ts +117 -0
- package/dist/lib/providers/sagemaker/structured-parser.js +625 -0
- package/dist/lib/providers/sagemaker/types.d.ts +456 -0
- package/dist/lib/providers/sagemaker/types.js +7 -0
- package/dist/lib/sdk/toolRegistration.d.ts +1 -1
- package/dist/lib/sdk/toolRegistration.js +13 -5
- package/dist/lib/types/cli.d.ts +36 -1
- package/dist/lib/utils/providerHealth.js +19 -4
- package/dist/neurolink.d.ts +15 -0
- package/dist/neurolink.js +73 -1
- package/dist/providers/amazonSagemaker.d.ts +67 -0
- package/dist/providers/amazonSagemaker.js +149 -0
- package/dist/providers/googleVertex.d.ts +4 -0
- package/dist/providers/googleVertex.js +44 -3
- package/dist/providers/index.d.ts +4 -0
- package/dist/providers/index.js +4 -0
- package/dist/providers/sagemaker/adaptive-semaphore.d.ts +86 -0
- package/dist/providers/sagemaker/adaptive-semaphore.js +212 -0
- package/dist/providers/sagemaker/client.d.ts +156 -0
- package/dist/providers/sagemaker/client.js +462 -0
- package/dist/providers/sagemaker/config.d.ts +73 -0
- package/dist/providers/sagemaker/config.js +308 -0
- package/dist/providers/sagemaker/detection.d.ts +176 -0
- package/dist/providers/sagemaker/detection.js +596 -0
- package/dist/providers/sagemaker/diagnostics.d.ts +37 -0
- package/dist/providers/sagemaker/diagnostics.js +137 -0
- package/dist/providers/sagemaker/error-constants.d.ts +78 -0
- package/dist/providers/sagemaker/error-constants.js +227 -0
- package/dist/providers/sagemaker/errors.d.ts +83 -0
- package/dist/providers/sagemaker/errors.js +216 -0
- package/dist/providers/sagemaker/index.d.ts +35 -0
- package/dist/providers/sagemaker/index.js +67 -0
- package/dist/providers/sagemaker/language-model.d.ts +182 -0
- package/dist/providers/sagemaker/language-model.js +755 -0
- package/dist/providers/sagemaker/parsers.d.ts +136 -0
- package/dist/providers/sagemaker/parsers.js +625 -0
- package/dist/providers/sagemaker/streaming.d.ts +39 -0
- package/dist/providers/sagemaker/streaming.js +320 -0
- package/dist/providers/sagemaker/structured-parser.d.ts +117 -0
- package/dist/providers/sagemaker/structured-parser.js +625 -0
- package/dist/providers/sagemaker/types.d.ts +456 -0
- package/dist/providers/sagemaker/types.js +7 -0
- package/dist/sdk/toolRegistration.d.ts +1 -1
- package/dist/sdk/toolRegistration.js +13 -5
- package/dist/types/cli.d.ts +36 -1
- package/dist/utils/providerHealth.js +19 -4
- package/package.json +8 -2
package/dist/neurolink.js
CHANGED
|
@@ -26,15 +26,32 @@ import { validateTool, createMCPServerFromTools, } from "./sdk/toolRegistration.
|
|
|
26
26
|
import { processFactoryOptions, enhanceTextGenerationOptions, validateFactoryConfig, processStreamingFactoryOptions, createCleanStreamOptions, } from "./utils/factoryProcessing.js";
|
|
27
27
|
// Enhanced error handling imports
|
|
28
28
|
import { ErrorFactory, NeuroLinkError, withTimeout, withRetry, isRetriableError, logStructuredError, CircuitBreaker, } from "./utils/errorHandling.js";
|
|
29
|
+
import { EventEmitter } from "events";
|
|
29
30
|
// Core types imported from core/types.js
|
|
30
31
|
export class NeuroLink {
|
|
31
32
|
mcpInitialized = false;
|
|
33
|
+
emitter = new EventEmitter();
|
|
32
34
|
// Tool registration support
|
|
33
35
|
customTools = new Map();
|
|
34
36
|
inMemoryServers = new Map();
|
|
35
37
|
// Enhanced error handling support
|
|
36
38
|
toolCircuitBreakers = new Map();
|
|
37
39
|
toolExecutionMetrics = new Map();
|
|
40
|
+
/**
|
|
41
|
+
* Helper method to emit tool end event in a consistent way
|
|
42
|
+
* Used by executeTool in both success and error paths
|
|
43
|
+
* @param toolName - Name of the tool
|
|
44
|
+
* @param startTime - Timestamp when tool execution started
|
|
45
|
+
* @param success - Whether the tool execution was successful
|
|
46
|
+
*/
|
|
47
|
+
emitToolEndEvent(toolName, startTime, success) {
|
|
48
|
+
this.emitter.emit("tool:end", {
|
|
49
|
+
toolName,
|
|
50
|
+
responseTime: Date.now() - startTime,
|
|
51
|
+
success,
|
|
52
|
+
timestamp: Date.now(),
|
|
53
|
+
});
|
|
54
|
+
}
|
|
38
55
|
constructor() {
|
|
39
56
|
// SDK always disables manual MCP config for security
|
|
40
57
|
ProviderRegistry.setOptions({
|
|
@@ -91,7 +108,6 @@ export class NeuroLink {
|
|
|
91
108
|
* Replaces both generateText and legacy methods
|
|
92
109
|
*/
|
|
93
110
|
async generate(optionsOrPrompt) {
|
|
94
|
-
const startTime = Date.now();
|
|
95
111
|
// Convert string prompt to full options
|
|
96
112
|
const options = typeof optionsOrPrompt === "string"
|
|
97
113
|
? { input: { text: optionsOrPrompt } }
|
|
@@ -100,6 +116,12 @@ export class NeuroLink {
|
|
|
100
116
|
if (!options.input?.text || typeof options.input.text !== "string") {
|
|
101
117
|
throw new Error("Input text is required and must be a non-empty string");
|
|
102
118
|
}
|
|
119
|
+
const startTime = Date.now();
|
|
120
|
+
// Emit generation start event
|
|
121
|
+
this.emitter.emit("generation:start", {
|
|
122
|
+
provider: options.provider || "auto",
|
|
123
|
+
timestamp: startTime,
|
|
124
|
+
});
|
|
103
125
|
// Process factory configuration
|
|
104
126
|
const factoryResult = processFactoryOptions(options);
|
|
105
127
|
// Validate factory configuration if present
|
|
@@ -142,6 +164,13 @@ export class NeuroLink {
|
|
|
142
164
|
}
|
|
143
165
|
// Use redesigned generation logic
|
|
144
166
|
const textResult = await this.generateTextInternal(textOptions);
|
|
167
|
+
// Emit generation completion event
|
|
168
|
+
this.emitter.emit("generation:end", {
|
|
169
|
+
provider: textResult.provider,
|
|
170
|
+
responseTime: Date.now() - startTime,
|
|
171
|
+
toolsUsed: textResult.toolsUsed,
|
|
172
|
+
timestamp: Date.now(),
|
|
173
|
+
});
|
|
145
174
|
// Convert back to GenerateResult
|
|
146
175
|
const generateResult = {
|
|
147
176
|
content: textResult.content,
|
|
@@ -509,6 +538,11 @@ export class NeuroLink {
|
|
|
509
538
|
options.input.text.trim() === "") {
|
|
510
539
|
throw new Error("Stream options must include input.text as a non-empty string");
|
|
511
540
|
}
|
|
541
|
+
// Emit stream start event
|
|
542
|
+
this.emitter.emit("stream:start", {
|
|
543
|
+
provider: options.provider || "auto",
|
|
544
|
+
timestamp: startTime,
|
|
545
|
+
});
|
|
512
546
|
// Process factory configuration for streaming
|
|
513
547
|
const factoryResult = processFactoryOptions(options);
|
|
514
548
|
const streamingResult = processStreamingFactoryOptions(options);
|
|
@@ -576,6 +610,11 @@ export class NeuroLink {
|
|
|
576
610
|
responseTime,
|
|
577
611
|
provider: providerName,
|
|
578
612
|
});
|
|
613
|
+
// Emit stream completion event
|
|
614
|
+
this.emitter.emit("stream:end", {
|
|
615
|
+
provider: providerName,
|
|
616
|
+
responseTime,
|
|
617
|
+
});
|
|
579
618
|
// Convert to StreamResult format - Include analytics and evaluation from provider
|
|
580
619
|
return {
|
|
581
620
|
stream,
|
|
@@ -615,6 +654,12 @@ export class NeuroLink {
|
|
|
615
654
|
const cleanOptions = createCleanStreamOptions(enhancedOptions);
|
|
616
655
|
const streamResult = await provider.stream(cleanOptions);
|
|
617
656
|
const responseTime = Date.now() - startTime;
|
|
657
|
+
// Emit stream completion event for fallback
|
|
658
|
+
this.emitter.emit("stream:end", {
|
|
659
|
+
provider: providerName,
|
|
660
|
+
responseTime,
|
|
661
|
+
fallback: true,
|
|
662
|
+
});
|
|
618
663
|
return {
|
|
619
664
|
stream: streamResult.stream,
|
|
620
665
|
provider: providerName,
|
|
@@ -643,6 +688,13 @@ export class NeuroLink {
|
|
|
643
688
|
};
|
|
644
689
|
}
|
|
645
690
|
}
|
|
691
|
+
/**
|
|
692
|
+
* Get the EventEmitter to listen to NeuroLink events
|
|
693
|
+
* @returns EventEmitter instance
|
|
694
|
+
*/
|
|
695
|
+
getEventEmitter() {
|
|
696
|
+
return this.emitter;
|
|
697
|
+
}
|
|
646
698
|
// ========================================
|
|
647
699
|
// Tool Registration API
|
|
648
700
|
// ========================================
|
|
@@ -652,6 +704,11 @@ export class NeuroLink {
|
|
|
652
704
|
* @param tool - Tool configuration
|
|
653
705
|
*/
|
|
654
706
|
registerTool(name, tool) {
|
|
707
|
+
// Emit tool registration start event
|
|
708
|
+
this.emitter.emit("tools-register:start", {
|
|
709
|
+
toolName: name,
|
|
710
|
+
timestamp: Date.now(),
|
|
711
|
+
});
|
|
655
712
|
try {
|
|
656
713
|
// Validate tool configuration
|
|
657
714
|
validateTool(name, tool);
|
|
@@ -666,6 +723,12 @@ export class NeuroLink {
|
|
|
666
723
|
// Store as in-memory server
|
|
667
724
|
this.inMemoryServers.set(serverId, mcpServer);
|
|
668
725
|
logger.info(`Registered custom tool: ${name}`);
|
|
726
|
+
// Emit tool registration success event
|
|
727
|
+
this.emitter.emit("tools-register:end", {
|
|
728
|
+
toolName: name,
|
|
729
|
+
success: true,
|
|
730
|
+
timestamp: Date.now(),
|
|
731
|
+
});
|
|
669
732
|
}
|
|
670
733
|
catch (error) {
|
|
671
734
|
logger.error(`Failed to register tool ${name}:`, error);
|
|
@@ -758,6 +821,11 @@ export class NeuroLink {
|
|
|
758
821
|
async executeTool(toolName, params = {}, options) {
|
|
759
822
|
const functionTag = "NeuroLink.executeTool";
|
|
760
823
|
const executionStartTime = Date.now();
|
|
824
|
+
// Emit tool start event
|
|
825
|
+
this.emitter.emit("tool:start", {
|
|
826
|
+
toolName,
|
|
827
|
+
timestamp: executionStartTime,
|
|
828
|
+
});
|
|
761
829
|
// Set default options
|
|
762
830
|
const finalOptions = {
|
|
763
831
|
timeout: options?.timeout || 30000, // 30 second default timeout
|
|
@@ -832,6 +900,8 @@ export class NeuroLink {
|
|
|
832
900
|
memoryDelta,
|
|
833
901
|
circuitBreakerState: circuitBreaker.getState(),
|
|
834
902
|
});
|
|
903
|
+
// Emit tool end event using the helper method
|
|
904
|
+
this.emitToolEndEvent(toolName, executionStartTime, true);
|
|
835
905
|
return result;
|
|
836
906
|
}
|
|
837
907
|
catch (error) {
|
|
@@ -867,6 +937,8 @@ export class NeuroLink {
|
|
|
867
937
|
else {
|
|
868
938
|
structuredError = ErrorFactory.toolExecutionFailed(toolName, new Error(String(error)));
|
|
869
939
|
}
|
|
940
|
+
// Emit tool end event using the helper method
|
|
941
|
+
this.emitToolEndEvent(toolName, executionStartTime, false);
|
|
870
942
|
// Add execution context to structured error
|
|
871
943
|
structuredError = new NeuroLinkError({
|
|
872
944
|
...structuredError,
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Amazon SageMaker Provider Implementation (Simplified)
|
|
3
|
+
*
|
|
4
|
+
* This module provides a simplified SageMaker provider that extends BaseProvider
|
|
5
|
+
* and integrates with the NeuroLink ecosystem using existing patterns.
|
|
6
|
+
*/
|
|
7
|
+
import type { ZodType, ZodTypeDef } from "zod";
|
|
8
|
+
import type { Schema, LanguageModelV1 } from "ai";
|
|
9
|
+
import type { AIProviderName } from "../core/types.js";
|
|
10
|
+
import type { StreamOptions, StreamResult } from "../types/streamTypes.js";
|
|
11
|
+
import { BaseProvider } from "../core/baseProvider.js";
|
|
12
|
+
/**
|
|
13
|
+
* Amazon SageMaker Provider extending BaseProvider
|
|
14
|
+
*/
|
|
15
|
+
export declare class AmazonSageMakerProvider extends BaseProvider {
|
|
16
|
+
private sagemakerModel;
|
|
17
|
+
private sagemakerConfig;
|
|
18
|
+
private modelConfig;
|
|
19
|
+
constructor(modelName?: string, endpointName?: string);
|
|
20
|
+
protected getProviderName(): AIProviderName;
|
|
21
|
+
protected getDefaultModel(): string;
|
|
22
|
+
protected getAISDKModel(): LanguageModelV1;
|
|
23
|
+
protected executeStream(options: StreamOptions, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<StreamResult>;
|
|
24
|
+
protected handleProviderError(error: unknown): Error;
|
|
25
|
+
/**
|
|
26
|
+
* Get SageMaker-specific provider information
|
|
27
|
+
*/
|
|
28
|
+
getSageMakerInfo(): {
|
|
29
|
+
endpointName: string;
|
|
30
|
+
modelType: string;
|
|
31
|
+
region: string;
|
|
32
|
+
configured: boolean;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Test basic configuration
|
|
36
|
+
*/
|
|
37
|
+
testConnection(): Promise<{
|
|
38
|
+
connected: boolean;
|
|
39
|
+
error?: string;
|
|
40
|
+
}>;
|
|
41
|
+
/**
|
|
42
|
+
* Public method to get the AI SDK model for CLI and external usage
|
|
43
|
+
*/
|
|
44
|
+
getModel(): Promise<LanguageModelV1>;
|
|
45
|
+
/**
|
|
46
|
+
* Test connectivity to the SageMaker endpoint
|
|
47
|
+
*/
|
|
48
|
+
testConnectivity(): Promise<{
|
|
49
|
+
success: boolean;
|
|
50
|
+
error?: string;
|
|
51
|
+
}>;
|
|
52
|
+
/**
|
|
53
|
+
* Get model capabilities and information
|
|
54
|
+
*/
|
|
55
|
+
getModelCapabilities(): {
|
|
56
|
+
capabilities: {
|
|
57
|
+
streaming: boolean;
|
|
58
|
+
toolCalling: boolean;
|
|
59
|
+
structuredOutput: boolean;
|
|
60
|
+
batchInference: boolean;
|
|
61
|
+
supportedResponseFormats: string[];
|
|
62
|
+
supportedToolTypes: string[];
|
|
63
|
+
maxBatchSize: number;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export default AmazonSageMakerProvider;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Amazon SageMaker Provider Implementation (Simplified)
|
|
3
|
+
*
|
|
4
|
+
* This module provides a simplified SageMaker provider that extends BaseProvider
|
|
5
|
+
* and integrates with the NeuroLink ecosystem using existing patterns.
|
|
6
|
+
*/
|
|
7
|
+
import { BaseProvider } from "../core/baseProvider.js";
|
|
8
|
+
import { logger } from "../utils/logger.js";
|
|
9
|
+
// SageMaker-specific imports
|
|
10
|
+
import { getSageMakerConfig, getSageMakerModelConfig, getDefaultSageMakerEndpoint, getSageMakerModel, } from "./sagemaker/config.js";
|
|
11
|
+
import { handleSageMakerError, SageMakerError } from "./sagemaker/errors.js";
|
|
12
|
+
import { SageMakerLanguageModel } from "./sagemaker/language-model.js";
|
|
13
|
+
/**
|
|
14
|
+
* Amazon SageMaker Provider extending BaseProvider
|
|
15
|
+
*/
|
|
16
|
+
export class AmazonSageMakerProvider extends BaseProvider {
|
|
17
|
+
sagemakerModel;
|
|
18
|
+
sagemakerConfig;
|
|
19
|
+
modelConfig;
|
|
20
|
+
constructor(modelName, endpointName) {
|
|
21
|
+
super(modelName, "sagemaker");
|
|
22
|
+
try {
|
|
23
|
+
// Load and validate configuration
|
|
24
|
+
this.sagemakerConfig = getSageMakerConfig();
|
|
25
|
+
this.modelConfig = getSageMakerModelConfig(endpointName || getDefaultSageMakerEndpoint());
|
|
26
|
+
// Create the proper LanguageModel (v2) implementation
|
|
27
|
+
this.sagemakerModel = new SageMakerLanguageModel(this.modelName, this.sagemakerConfig, this.modelConfig);
|
|
28
|
+
logger.debug("Amazon SageMaker Provider initialized", {
|
|
29
|
+
modelName: this.modelName,
|
|
30
|
+
endpointName: this.modelConfig.endpointName,
|
|
31
|
+
region: this.sagemakerConfig.region,
|
|
32
|
+
provider: this.providerName,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
logger.error("Failed to initialize SageMaker provider", {
|
|
37
|
+
error: error instanceof Error ? error.message : String(error),
|
|
38
|
+
modelName,
|
|
39
|
+
endpointName,
|
|
40
|
+
});
|
|
41
|
+
throw handleSageMakerError(error);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
getProviderName() {
|
|
45
|
+
return "sagemaker";
|
|
46
|
+
}
|
|
47
|
+
getDefaultModel() {
|
|
48
|
+
return getSageMakerModel();
|
|
49
|
+
}
|
|
50
|
+
getAISDKModel() {
|
|
51
|
+
return this.sagemakerModel;
|
|
52
|
+
}
|
|
53
|
+
async executeStream(options, analysisSchema) {
|
|
54
|
+
try {
|
|
55
|
+
// For now, throw an error indicating this is not yet implemented
|
|
56
|
+
throw new SageMakerError("SageMaker streaming not yet fully implemented. Coming in next phase.", "MODEL_ERROR", 501, undefined, this.modelConfig.endpointName);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
throw this.handleProviderError(error);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
handleProviderError(error) {
|
|
63
|
+
if (error instanceof SageMakerError) {
|
|
64
|
+
return error;
|
|
65
|
+
}
|
|
66
|
+
if (error instanceof Error && error.name === "TimeoutError") {
|
|
67
|
+
return new SageMakerError(`SageMaker request timed out. Consider increasing timeout.`, "NETWORK_ERROR", 408, error, this.modelConfig.endpointName);
|
|
68
|
+
}
|
|
69
|
+
return handleSageMakerError(error, this.modelConfig.endpointName);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get SageMaker-specific provider information
|
|
73
|
+
*/
|
|
74
|
+
getSageMakerInfo() {
|
|
75
|
+
return {
|
|
76
|
+
endpointName: this.modelConfig.endpointName,
|
|
77
|
+
modelType: this.modelConfig.modelType || "custom",
|
|
78
|
+
region: this.sagemakerConfig.region,
|
|
79
|
+
configured: !!(this.sagemakerConfig.accessKeyId && this.sagemakerConfig.secretAccessKey),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Test basic configuration
|
|
84
|
+
*/
|
|
85
|
+
async testConnection() {
|
|
86
|
+
try {
|
|
87
|
+
// Basic validation test
|
|
88
|
+
if (!this.sagemakerConfig.accessKeyId ||
|
|
89
|
+
!this.sagemakerConfig.secretAccessKey) {
|
|
90
|
+
return {
|
|
91
|
+
connected: false,
|
|
92
|
+
error: "AWS credentials not configured",
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
if (!this.modelConfig.endpointName ||
|
|
96
|
+
this.modelConfig.endpointName === "default-endpoint") {
|
|
97
|
+
return {
|
|
98
|
+
connected: false,
|
|
99
|
+
error: "SageMaker endpoint not configured",
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
// For now, just return that configuration looks valid
|
|
103
|
+
return {
|
|
104
|
+
connected: true,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
return {
|
|
109
|
+
connected: false,
|
|
110
|
+
error: error instanceof Error ? error.message : String(error),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Public method to get the AI SDK model for CLI and external usage
|
|
116
|
+
*/
|
|
117
|
+
async getModel() {
|
|
118
|
+
return this.getAISDKModel();
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Test connectivity to the SageMaker endpoint
|
|
122
|
+
*/
|
|
123
|
+
async testConnectivity() {
|
|
124
|
+
const model = this.sagemakerModel;
|
|
125
|
+
return model.testConnectivity
|
|
126
|
+
? await model.testConnectivity()
|
|
127
|
+
: { success: false, error: "Test method not available" };
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Get model capabilities and information
|
|
131
|
+
*/
|
|
132
|
+
getModelCapabilities() {
|
|
133
|
+
const model = this.sagemakerModel;
|
|
134
|
+
return model.getModelCapabilities
|
|
135
|
+
? model.getModelCapabilities()
|
|
136
|
+
: {
|
|
137
|
+
capabilities: {
|
|
138
|
+
streaming: true,
|
|
139
|
+
toolCalling: true,
|
|
140
|
+
structuredOutput: true,
|
|
141
|
+
batchInference: true,
|
|
142
|
+
supportedResponseFormats: ["text", "json_object"],
|
|
143
|
+
supportedToolTypes: ["function"],
|
|
144
|
+
maxBatchSize: 10,
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
export default AmazonSageMakerProvider;
|
|
@@ -108,6 +108,10 @@ export declare class GoogleVertexProvider extends BaseProvider {
|
|
|
108
108
|
maxTokens: number;
|
|
109
109
|
};
|
|
110
110
|
};
|
|
111
|
+
/**
|
|
112
|
+
* Get model suggestions when a model is not found
|
|
113
|
+
*/
|
|
114
|
+
private getModelSuggestions;
|
|
111
115
|
}
|
|
112
116
|
export default GoogleVertexProvider;
|
|
113
117
|
export { GoogleVertexProvider as GoogleVertexAI };
|
|
@@ -40,9 +40,9 @@ const getVertexLocation = () => {
|
|
|
40
40
|
"us-central1");
|
|
41
41
|
};
|
|
42
42
|
const getDefaultVertexModel = () => {
|
|
43
|
-
// Use gemini-
|
|
43
|
+
// Use gemini-2.5-flash as default - latest and best price-performance model
|
|
44
44
|
// Override with VERTEX_MODEL environment variable if needed
|
|
45
|
-
return process.env.VERTEX_MODEL || "gemini-
|
|
45
|
+
return process.env.VERTEX_MODEL || "gemini-2.5-flash";
|
|
46
46
|
};
|
|
47
47
|
const hasGoogleCredentials = () => {
|
|
48
48
|
return !!(process.env.GOOGLE_APPLICATION_CREDENTIALS ||
|
|
@@ -276,7 +276,8 @@ export class GoogleVertexProvider extends BaseProvider {
|
|
|
276
276
|
return new Error(`❌ Google Vertex AI Permission Denied\n\nYour Google Cloud credentials don't have permission to access Vertex AI.\n\nRequired Steps:\n1. Ensure your service account has Vertex AI User role\n2. Check if Vertex AI API is enabled in your project\n3. Verify your project ID is correct\n4. Confirm your location/region has Vertex AI available`);
|
|
277
277
|
}
|
|
278
278
|
if (message.includes("NOT_FOUND")) {
|
|
279
|
-
|
|
279
|
+
const modelSuggestions = this.getModelSuggestions(this.modelName);
|
|
280
|
+
return new Error(`❌ Google Vertex AI Model Not Found\n\n${message}\n\nModel '${this.modelName}' is not available.\n\nSuggested alternatives:\n${modelSuggestions}\n\nTroubleshooting:\n1. Check model name spelling and format\n2. Verify model is available in your region (${this.location})\n3. Ensure your project has access to the model\n4. For Claude models, enable Anthropic integration in Google Cloud Console`);
|
|
280
281
|
}
|
|
281
282
|
if (message.includes("QUOTA_EXCEEDED")) {
|
|
282
283
|
return new Error(`❌ Google Vertex AI Quota Exceeded\n\n${message}\n\nSolutions:\n1. Check your Vertex AI quotas in Google Cloud Console\n2. Request quota increase if needed\n3. Try a different model or reduce request frequency\n4. Consider using a different region`);
|
|
@@ -520,6 +521,46 @@ export class GoogleVertexProvider extends BaseProvider {
|
|
|
520
521
|
},
|
|
521
522
|
};
|
|
522
523
|
}
|
|
524
|
+
/**
|
|
525
|
+
* Get model suggestions when a model is not found
|
|
526
|
+
*/
|
|
527
|
+
getModelSuggestions(requestedModel) {
|
|
528
|
+
const availableModels = {
|
|
529
|
+
google: [
|
|
530
|
+
"gemini-2.5-pro",
|
|
531
|
+
"gemini-2.5-flash",
|
|
532
|
+
"gemini-2.5-flash-lite",
|
|
533
|
+
"gemini-2.0-flash-001",
|
|
534
|
+
"gemini-1.5-pro",
|
|
535
|
+
"gemini-1.5-flash"
|
|
536
|
+
],
|
|
537
|
+
claude: [
|
|
538
|
+
"claude-sonnet-4@20250514",
|
|
539
|
+
"claude-opus-4@20250514",
|
|
540
|
+
"claude-3-5-sonnet-20241022",
|
|
541
|
+
"claude-3-5-haiku-20241022",
|
|
542
|
+
"claude-3-sonnet-20240229",
|
|
543
|
+
"claude-3-haiku-20240307",
|
|
544
|
+
"claude-3-opus-20240229",
|
|
545
|
+
],
|
|
546
|
+
};
|
|
547
|
+
let suggestions = "\n🤖 Google Models (always available):\n";
|
|
548
|
+
availableModels.google.forEach((model) => {
|
|
549
|
+
suggestions += ` • ${model}\n`;
|
|
550
|
+
});
|
|
551
|
+
suggestions += "\n🧠 Claude Models (requires Anthropic integration):\n";
|
|
552
|
+
availableModels.claude.forEach((model) => {
|
|
553
|
+
suggestions += ` • ${model}\n`;
|
|
554
|
+
});
|
|
555
|
+
// If the requested model looks like a Claude model, provide specific guidance
|
|
556
|
+
if (requestedModel && requestedModel.toLowerCase().includes("claude")) {
|
|
557
|
+
suggestions += `\n💡 Tip: "${requestedModel}" appears to be a Claude model.\n`;
|
|
558
|
+
suggestions +=
|
|
559
|
+
"Ensure Anthropic integration is enabled in your Google Cloud project.\n";
|
|
560
|
+
suggestions += "Try using an available Claude model from the list above.";
|
|
561
|
+
}
|
|
562
|
+
return suggestions;
|
|
563
|
+
}
|
|
523
564
|
}
|
|
524
565
|
export default GoogleVertexProvider;
|
|
525
566
|
// Re-export for compatibility
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export { GoogleVertexProvider as GoogleVertexAI } from "./googleVertex.js";
|
|
6
6
|
export { AmazonBedrockProvider as AmazonBedrock } from "./amazonBedrock.js";
|
|
7
|
+
export { AmazonSageMakerProvider as AmazonSageMaker } from "./amazonSagemaker.js";
|
|
7
8
|
export { OpenAIProvider as OpenAI } from "./openAI.js";
|
|
8
9
|
export { OpenAICompatibleProvider as OpenAICompatible } from "./openaiCompatible.js";
|
|
9
10
|
export { AnthropicProvider as AnthropicProvider } from "./anthropic.js";
|
|
@@ -12,6 +13,7 @@ export { GoogleAIStudioProvider as GoogleAIStudio } from "./googleAiStudio.js";
|
|
|
12
13
|
export { HuggingFaceProvider as HuggingFace } from "./huggingFace.js";
|
|
13
14
|
export { OllamaProvider as Ollama } from "./ollama.js";
|
|
14
15
|
export { MistralProvider as MistralAI } from "./mistral.js";
|
|
16
|
+
export { LiteLLMProvider as LiteLLM } from "./litellm.js";
|
|
15
17
|
export type { AIProvider } from "../core/types.js";
|
|
16
18
|
/**
|
|
17
19
|
* Provider registry for dynamic provider instantiation
|
|
@@ -19,6 +21,7 @@ export type { AIProvider } from "../core/types.js";
|
|
|
19
21
|
export declare const PROVIDERS: {
|
|
20
22
|
readonly vertex: "GoogleVertexAI";
|
|
21
23
|
readonly bedrock: "AmazonBedrock";
|
|
24
|
+
readonly sagemaker: "AmazonSageMaker";
|
|
22
25
|
readonly openai: "OpenAI";
|
|
23
26
|
readonly "openai-compatible": "OpenAICompatible";
|
|
24
27
|
readonly anthropic: "AnthropicProvider";
|
|
@@ -27,6 +30,7 @@ export declare const PROVIDERS: {
|
|
|
27
30
|
readonly huggingface: "HuggingFace";
|
|
28
31
|
readonly ollama: "Ollama";
|
|
29
32
|
readonly mistral: "MistralAI";
|
|
33
|
+
readonly litellm: "LiteLLM";
|
|
30
34
|
};
|
|
31
35
|
/**
|
|
32
36
|
* Type for valid provider names
|
package/dist/providers/index.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export { GoogleVertexProvider as GoogleVertexAI } from "./googleVertex.js";
|
|
6
6
|
export { AmazonBedrockProvider as AmazonBedrock } from "./amazonBedrock.js";
|
|
7
|
+
export { AmazonSageMakerProvider as AmazonSageMaker } from "./amazonSagemaker.js";
|
|
7
8
|
export { OpenAIProvider as OpenAI } from "./openAI.js";
|
|
8
9
|
export { OpenAICompatibleProvider as OpenAICompatible } from "./openaiCompatible.js";
|
|
9
10
|
export { AnthropicProvider as AnthropicProvider } from "./anthropic.js";
|
|
@@ -12,12 +13,14 @@ export { GoogleAIStudioProvider as GoogleAIStudio } from "./googleAiStudio.js";
|
|
|
12
13
|
export { HuggingFaceProvider as HuggingFace } from "./huggingFace.js";
|
|
13
14
|
export { OllamaProvider as Ollama } from "./ollama.js";
|
|
14
15
|
export { MistralProvider as MistralAI } from "./mistral.js";
|
|
16
|
+
export { LiteLLMProvider as LiteLLM } from "./litellm.js";
|
|
15
17
|
/**
|
|
16
18
|
* Provider registry for dynamic provider instantiation
|
|
17
19
|
*/
|
|
18
20
|
export const PROVIDERS = {
|
|
19
21
|
vertex: "GoogleVertexAI",
|
|
20
22
|
bedrock: "AmazonBedrock",
|
|
23
|
+
sagemaker: "AmazonSageMaker",
|
|
21
24
|
openai: "OpenAI",
|
|
22
25
|
"openai-compatible": "OpenAICompatible",
|
|
23
26
|
anthropic: "AnthropicProvider",
|
|
@@ -26,6 +29,7 @@ export const PROVIDERS = {
|
|
|
26
29
|
huggingface: "HuggingFace",
|
|
27
30
|
ollama: "Ollama",
|
|
28
31
|
mistral: "MistralAI",
|
|
32
|
+
litellm: "LiteLLM",
|
|
29
33
|
};
|
|
30
34
|
/**
|
|
31
35
|
* List of all available provider names
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adaptive Semaphore Utility
|
|
3
|
+
*
|
|
4
|
+
* Provides a sophisticated semaphore implementation with dynamic concurrency adjustment
|
|
5
|
+
* for optimal resource utilization and performance tuning based on response times and error rates.
|
|
6
|
+
*/
|
|
7
|
+
export interface AdaptiveSemaphoreConfig {
|
|
8
|
+
initialConcurrency: number;
|
|
9
|
+
maxConcurrency: number;
|
|
10
|
+
minConcurrency: number;
|
|
11
|
+
}
|
|
12
|
+
export interface AdaptiveSemaphoreMetrics {
|
|
13
|
+
activeRequests: number;
|
|
14
|
+
currentConcurrency: number;
|
|
15
|
+
completedCount: number;
|
|
16
|
+
errorCount: number;
|
|
17
|
+
averageResponseTime: number;
|
|
18
|
+
waitingCount: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Adaptive semaphore that automatically adjusts concurrency based on performance metrics
|
|
22
|
+
*/
|
|
23
|
+
export declare class AdaptiveSemaphore {
|
|
24
|
+
private count;
|
|
25
|
+
private waiters;
|
|
26
|
+
private currentConcurrency;
|
|
27
|
+
private activeRequests;
|
|
28
|
+
private completedCount;
|
|
29
|
+
private errorCount;
|
|
30
|
+
private responseTimes;
|
|
31
|
+
private readonly maxConcurrency;
|
|
32
|
+
private readonly minConcurrency;
|
|
33
|
+
constructor(config: AdaptiveSemaphoreConfig);
|
|
34
|
+
/**
|
|
35
|
+
* Acquire a semaphore permit, waiting if necessary
|
|
36
|
+
*/
|
|
37
|
+
acquire(): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Release a semaphore permit and wake up waiting requests
|
|
40
|
+
*/
|
|
41
|
+
release(): void;
|
|
42
|
+
/**
|
|
43
|
+
* Record successful completion with response time for adaptive adjustment
|
|
44
|
+
*/
|
|
45
|
+
recordSuccess(responseTimeMs: number): void;
|
|
46
|
+
/**
|
|
47
|
+
* Record error for adaptive adjustment
|
|
48
|
+
*/
|
|
49
|
+
recordError(responseTimeMs?: number): void;
|
|
50
|
+
/**
|
|
51
|
+
* Manually adjust concurrency level
|
|
52
|
+
*/
|
|
53
|
+
adjustConcurrency(newLimit: number): void;
|
|
54
|
+
/**
|
|
55
|
+
* Get current performance metrics
|
|
56
|
+
*/
|
|
57
|
+
getMetrics(): AdaptiveSemaphoreMetrics;
|
|
58
|
+
/**
|
|
59
|
+
* Reset metrics for new batch or session
|
|
60
|
+
*/
|
|
61
|
+
resetMetrics(): void;
|
|
62
|
+
/**
|
|
63
|
+
* Automatically adjust concurrency based on performance indicators
|
|
64
|
+
*/
|
|
65
|
+
private adjustConcurrencyBasedOnPerformance;
|
|
66
|
+
/**
|
|
67
|
+
* Check if semaphore is idle (no active or waiting requests)
|
|
68
|
+
*/
|
|
69
|
+
isIdle(): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Get current concurrency limit
|
|
72
|
+
*/
|
|
73
|
+
getCurrentConcurrency(): number;
|
|
74
|
+
/**
|
|
75
|
+
* Get number of active requests
|
|
76
|
+
*/
|
|
77
|
+
getActiveRequestCount(): number;
|
|
78
|
+
/**
|
|
79
|
+
* Get number of waiting requests
|
|
80
|
+
*/
|
|
81
|
+
getWaitingRequestCount(): number;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Factory function to create an adaptive semaphore with default configuration
|
|
85
|
+
*/
|
|
86
|
+
export declare function createAdaptiveSemaphore(initialConcurrency: number, maxConcurrency?: number, minConcurrency?: number): AdaptiveSemaphore;
|