@juspay/neurolink 2.0.0 → 2.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 +7 -0
- package/README.md +31 -5
- package/dist/cli/commands/config.d.ts +6 -6
- package/dist/cli/index.js +29 -30
- package/dist/core/types.d.ts +2 -0
- package/dist/lib/core/types.d.ts +2 -0
- package/dist/lib/neurolink.d.ts +2 -0
- package/dist/lib/neurolink.js +23 -2
- package/dist/lib/providers/agent-enhanced-provider.d.ts +1 -0
- package/dist/lib/providers/agent-enhanced-provider.js +59 -3
- package/dist/lib/providers/amazonBedrock.js +70 -24
- package/dist/lib/providers/anthropic.js +77 -15
- package/dist/lib/providers/azureOpenAI.js +77 -15
- package/dist/lib/providers/googleAIStudio.js +70 -26
- package/dist/lib/providers/googleVertexAI.js +70 -24
- package/dist/lib/providers/huggingFace.js +70 -26
- package/dist/lib/providers/mistralAI.js +70 -26
- package/dist/lib/providers/ollama.d.ts +1 -1
- package/dist/lib/providers/ollama.js +24 -10
- package/dist/lib/providers/openAI.js +67 -23
- package/dist/lib/providers/timeout-wrapper.d.ts +40 -0
- package/dist/lib/providers/timeout-wrapper.js +100 -0
- package/dist/lib/utils/timeout.d.ts +69 -0
- package/dist/lib/utils/timeout.js +130 -0
- package/dist/neurolink.d.ts +2 -0
- package/dist/neurolink.js +23 -2
- package/dist/providers/agent-enhanced-provider.d.ts +1 -0
- package/dist/providers/agent-enhanced-provider.js +59 -3
- package/dist/providers/amazonBedrock.js +70 -24
- package/dist/providers/anthropic.js +77 -15
- package/dist/providers/azureOpenAI.js +77 -15
- package/dist/providers/googleAIStudio.js +70 -26
- package/dist/providers/googleVertexAI.js +70 -24
- package/dist/providers/huggingFace.js +70 -26
- package/dist/providers/mistralAI.js +70 -26
- package/dist/providers/ollama.d.ts +1 -1
- package/dist/providers/ollama.js +24 -10
- package/dist/providers/openAI.js +67 -23
- package/dist/providers/timeout-wrapper.d.ts +40 -0
- package/dist/providers/timeout-wrapper.js +100 -0
- package/dist/utils/timeout.d.ts +69 -0
- package/dist/utils/timeout.js +130 -0
- package/package.json +1 -1
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Timeout utilities for NeuroLink
|
|
3
|
+
*
|
|
4
|
+
* Provides flexible timeout parsing and error handling for AI operations.
|
|
5
|
+
* Supports multiple time formats: milliseconds, seconds, minutes, hours.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Custom error class for timeout operations
|
|
9
|
+
*/
|
|
10
|
+
export class TimeoutError extends Error {
|
|
11
|
+
timeout;
|
|
12
|
+
provider;
|
|
13
|
+
operation;
|
|
14
|
+
constructor(message, timeout, provider, operation) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.timeout = timeout;
|
|
17
|
+
this.provider = provider;
|
|
18
|
+
this.operation = operation;
|
|
19
|
+
this.name = 'TimeoutError';
|
|
20
|
+
// Maintains proper stack trace for where error was thrown
|
|
21
|
+
if (typeof Error.captureStackTrace === 'function') {
|
|
22
|
+
Error.captureStackTrace(this, TimeoutError);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Parse timeout value from various formats
|
|
28
|
+
* @param timeout - Can be number (ms), string with unit, or undefined
|
|
29
|
+
* @returns Parsed timeout in milliseconds or undefined
|
|
30
|
+
* @throws Error if format is invalid
|
|
31
|
+
*
|
|
32
|
+
* Examples:
|
|
33
|
+
* - parseTimeout(5000) => 5000
|
|
34
|
+
* - parseTimeout('30s') => 30000
|
|
35
|
+
* - parseTimeout('2m') => 120000
|
|
36
|
+
* - parseTimeout('1.5h') => 5400000
|
|
37
|
+
* - parseTimeout(undefined) => undefined
|
|
38
|
+
*/
|
|
39
|
+
export function parseTimeout(timeout) {
|
|
40
|
+
if (timeout === undefined)
|
|
41
|
+
return undefined;
|
|
42
|
+
if (typeof timeout === 'number') {
|
|
43
|
+
if (timeout <= 0) {
|
|
44
|
+
throw new Error(`Timeout must be positive, got: ${timeout}`);
|
|
45
|
+
}
|
|
46
|
+
return timeout; // Assume milliseconds
|
|
47
|
+
}
|
|
48
|
+
if (typeof timeout === 'string') {
|
|
49
|
+
// Match number (including decimals) followed by optional unit
|
|
50
|
+
const match = timeout.match(/^(\d+(?:\.\d+)?)(ms|s|m|h)?$/);
|
|
51
|
+
if (!match) {
|
|
52
|
+
throw new Error(`Invalid timeout format: ${timeout}. Use formats like '30s', '2m', '500ms', or '1.5h'`);
|
|
53
|
+
}
|
|
54
|
+
const value = parseFloat(match[1]);
|
|
55
|
+
if (value <= 0) {
|
|
56
|
+
throw new Error(`Timeout must be positive, got: ${value}`);
|
|
57
|
+
}
|
|
58
|
+
const unit = match[2] || 'ms';
|
|
59
|
+
switch (unit) {
|
|
60
|
+
case 'ms': return value;
|
|
61
|
+
case 's': return value * 1000;
|
|
62
|
+
case 'm': return value * 60 * 1000;
|
|
63
|
+
case 'h': return value * 60 * 60 * 1000;
|
|
64
|
+
default: return value; // Should never reach here due to regex
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
throw new Error(`Invalid timeout type: ${typeof timeout}`);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Default timeout configurations for different providers and operations
|
|
71
|
+
*/
|
|
72
|
+
export const DEFAULT_TIMEOUTS = {
|
|
73
|
+
global: '30s', // Default for all providers
|
|
74
|
+
streaming: '2m', // Longer timeout for streaming operations
|
|
75
|
+
providers: {
|
|
76
|
+
openai: '30s', // OpenAI typically responds quickly
|
|
77
|
+
bedrock: '45s', // AWS can be slower, especially for cold starts
|
|
78
|
+
vertex: '60s', // Google Cloud can be slower
|
|
79
|
+
anthropic: '30s', // Direct Anthropic API is fast
|
|
80
|
+
azure: '30s', // Azure OpenAI similar to OpenAI
|
|
81
|
+
'google-ai': '30s', // Google AI Studio is fast
|
|
82
|
+
huggingface: '2m', // Open source models vary significantly
|
|
83
|
+
ollama: '5m', // Local models need more time, especially large ones
|
|
84
|
+
mistral: '45s' // Mistral AI moderate speed
|
|
85
|
+
},
|
|
86
|
+
tools: {
|
|
87
|
+
default: '10s', // Default timeout for MCP tool execution
|
|
88
|
+
filesystem: '5s', // File operations should be quick
|
|
89
|
+
network: '30s', // Network requests might take longer
|
|
90
|
+
computation: '2m' // Heavy computation tools need more time
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Get default timeout for a specific provider
|
|
95
|
+
* @param provider - Provider name
|
|
96
|
+
* @param operation - Operation type (generate or stream)
|
|
97
|
+
* @returns Default timeout string
|
|
98
|
+
*/
|
|
99
|
+
export function getDefaultTimeout(provider, operation = 'generate') {
|
|
100
|
+
if (operation === 'stream') {
|
|
101
|
+
return DEFAULT_TIMEOUTS.streaming;
|
|
102
|
+
}
|
|
103
|
+
const providerKey = provider.toLowerCase().replace('_', '-');
|
|
104
|
+
return DEFAULT_TIMEOUTS.providers[providerKey]
|
|
105
|
+
|| DEFAULT_TIMEOUTS.global;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Create a timeout promise that rejects after specified duration
|
|
109
|
+
* @param timeout - Timeout duration
|
|
110
|
+
* @param provider - Provider name for error message
|
|
111
|
+
* @param operation - Operation type for error message
|
|
112
|
+
* @returns Promise that rejects with TimeoutError
|
|
113
|
+
*/
|
|
114
|
+
export function createTimeoutPromise(timeout, provider, operation) {
|
|
115
|
+
const timeoutMs = parseTimeout(timeout);
|
|
116
|
+
if (!timeoutMs) {
|
|
117
|
+
return null; // No timeout
|
|
118
|
+
}
|
|
119
|
+
return new Promise((_, reject) => {
|
|
120
|
+
const timer = setTimeout(() => {
|
|
121
|
+
reject(new TimeoutError(`${provider} ${operation} operation timed out after ${timeout}`, timeoutMs, provider, operation));
|
|
122
|
+
}, timeoutMs);
|
|
123
|
+
// Unref the timer so it doesn't keep the process alive (Node.js only)
|
|
124
|
+
if (typeof timer === 'object' && timer && 'unref' in timer && typeof timer.unref === 'function') {
|
|
125
|
+
timer.unref();
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
// Re-export createTimeoutController from timeout-wrapper for convenience
|
|
130
|
+
export { createTimeoutController } from '../providers/timeout-wrapper.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juspay/neurolink",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Universal AI Development Platform with working MCP integration, multi-provider support, and professional CLI. Built-in tools operational, 58+ external MCP servers discoverable. Connect to filesystem, GitHub, database operations, and more. Build, test, and deploy AI applications with 9 major providers: OpenAI, Anthropic, Google AI, AWS Bedrock, Azure, Hugging Face, Ollama, and Mistral AI.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Juspay Technologies",
|