@defai.digital/automatosx 11.3.3 → 11.3.4

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/dist/mcp/index.js CHANGED
@@ -2012,251 +2012,148 @@ function isRateLimitError(error, providerName) {
2012
2012
  function isLimitError(error, providerName) {
2013
2013
  return isQuotaError(error, providerName) || isRateLimitError(error, providerName);
2014
2014
  }
2015
- var PROVIDER_ERROR_PATTERNS, GENERIC_ERROR_PATTERNS;
2015
+ var GEMINI_PATTERNS, CLAUDE_PATTERNS, OPENAI_PATTERNS, AX_CLI_PATTERNS, PROVIDER_ERROR_PATTERNS, GENERIC_ERROR_PATTERNS;
2016
2016
  var init_error_patterns = __esm({
2017
2017
  "src/providers/error-patterns.ts"() {
2018
2018
  init_esm_shims();
2019
+ GEMINI_PATTERNS = {
2020
+ quota: [
2021
+ "RESOURCE_EXHAUSTED",
2022
+ "resource_exhausted",
2023
+ "quotaExceeded",
2024
+ "quota exceeded",
2025
+ "quota limit reached",
2026
+ "daily quota exceeded",
2027
+ "monthly quota exceeded",
2028
+ "insufficient quota"
2029
+ ],
2030
+ rateLimit: [
2031
+ "RATE_LIMIT_EXCEEDED",
2032
+ "rate_limit_exceeded",
2033
+ "rate limit exceeded",
2034
+ "too many requests",
2035
+ "requests per minute exceeded",
2036
+ "requests per day exceeded"
2037
+ ],
2038
+ statusCodes: [429],
2039
+ // Too Many Requests
2040
+ errorCodes: [
2041
+ "RESOURCE_EXHAUSTED",
2042
+ "RATE_LIMIT_EXCEEDED",
2043
+ "QUOTA_EXCEEDED"
2044
+ ]
2045
+ };
2046
+ CLAUDE_PATTERNS = {
2047
+ quota: [
2048
+ "insufficient_quota",
2049
+ "quota_exceeded",
2050
+ "quota exceeded",
2051
+ "credit limit reached",
2052
+ "usage limit exceeded",
2053
+ "monthly quota exceeded"
2054
+ ],
2055
+ rateLimit: [
2056
+ "rate_limit_error",
2057
+ "rate limit exceeded",
2058
+ "overloaded_error",
2059
+ "overloaded",
2060
+ "too many requests",
2061
+ "requests per minute exceeded"
2062
+ ],
2063
+ statusCodes: [429, 529],
2064
+ // Too Many Requests, Overloaded
2065
+ errorCodes: [
2066
+ "rate_limit_error",
2067
+ "overloaded_error",
2068
+ "insufficient_quota"
2069
+ ]
2070
+ };
2071
+ OPENAI_PATTERNS = {
2072
+ quota: [
2073
+ "insufficient_quota",
2074
+ "quota_exceeded",
2075
+ "quota exceeded",
2076
+ "billing hard limit reached",
2077
+ "usage limit exceeded",
2078
+ "monthly quota exceeded",
2079
+ "credit limit reached"
2080
+ ],
2081
+ rateLimit: [
2082
+ "rate_limit_exceeded",
2083
+ "rate limit exceeded",
2084
+ "too_many_requests",
2085
+ "too many requests",
2086
+ "requests per minute exceeded",
2087
+ "tokens per minute exceeded",
2088
+ "rate limit reached"
2089
+ ],
2090
+ statusCodes: [429],
2091
+ // Too Many Requests
2092
+ errorCodes: [
2093
+ "insufficient_quota",
2094
+ "rate_limit_exceeded",
2095
+ "quota_exceeded",
2096
+ "billing_hard_limit_reached"
2097
+ ]
2098
+ };
2099
+ AX_CLI_PATTERNS = {
2100
+ quota: [
2101
+ // GLM patterns
2102
+ "quota exceeded",
2103
+ "quota limit reached",
2104
+ "insufficient quota",
2105
+ // OpenAI patterns (via ax-cli)
2106
+ "insufficient_quota",
2107
+ "quota_exceeded",
2108
+ "billing hard limit reached",
2109
+ "usage limit exceeded",
2110
+ "monthly quota exceeded",
2111
+ "credit limit reached",
2112
+ // Generic patterns
2113
+ "daily quota exceeded",
2114
+ "api quota exceeded"
2115
+ ],
2116
+ rateLimit: [
2117
+ // Common patterns
2118
+ "rate_limit_exceeded",
2119
+ "rate limit exceeded",
2120
+ "too_many_requests",
2121
+ "too many requests",
2122
+ "requests per minute exceeded",
2123
+ "tokens per minute exceeded",
2124
+ "rate limit reached",
2125
+ // Anthropic patterns (via ax-cli)
2126
+ "rate_limit_error",
2127
+ "overloaded_error",
2128
+ "overloaded",
2129
+ // xAI/Grok patterns
2130
+ "throttled",
2131
+ "request throttled"
2132
+ ],
2133
+ statusCodes: [429, 529],
2134
+ errorCodes: [
2135
+ "insufficient_quota",
2136
+ "rate_limit_exceeded",
2137
+ "quota_exceeded",
2138
+ "rate_limit_error",
2139
+ "overloaded_error",
2140
+ "RATE_LIMIT_EXCEEDED",
2141
+ "QUOTA_EXCEEDED"
2142
+ ]
2143
+ };
2019
2144
  PROVIDER_ERROR_PATTERNS = {
2020
- /**
2021
- * Google Gemini Error Patterns
2022
- *
2023
- * Gemini uses gRPC-style error codes and returns structured errors.
2024
- * Common quota errors include RESOURCE_EXHAUSTED and quotaExceeded.
2025
- */
2026
- gemini: {
2027
- quota: [
2028
- "RESOURCE_EXHAUSTED",
2029
- "resource_exhausted",
2030
- "quotaExceeded",
2031
- "quota exceeded",
2032
- "quota limit reached",
2033
- "daily quota exceeded",
2034
- "monthly quota exceeded",
2035
- "insufficient quota"
2036
- ],
2037
- rateLimit: [
2038
- "RATE_LIMIT_EXCEEDED",
2039
- "rate_limit_exceeded",
2040
- "rate limit exceeded",
2041
- "too many requests",
2042
- "requests per minute exceeded",
2043
- "requests per day exceeded"
2044
- ],
2045
- statusCodes: [429],
2046
- // Too Many Requests
2047
- errorCodes: [
2048
- "RESOURCE_EXHAUSTED",
2049
- "RATE_LIMIT_EXCEEDED",
2050
- "QUOTA_EXCEEDED"
2051
- ]
2052
- },
2053
- /**
2054
- * Anthropic Claude Error Patterns
2055
- *
2056
- * Claude returns different error types for rate limiting vs overload.
2057
- * Status 529 indicates temporary overload, 429 indicates rate limiting.
2058
- */
2059
- claude: {
2060
- quota: [
2061
- "insufficient_quota",
2062
- "quota_exceeded",
2063
- "quota exceeded",
2064
- "credit limit reached",
2065
- "usage limit exceeded",
2066
- "monthly quota exceeded"
2067
- ],
2068
- rateLimit: [
2069
- "rate_limit_error",
2070
- "rate limit exceeded",
2071
- "overloaded_error",
2072
- "overloaded",
2073
- "too many requests",
2074
- "requests per minute exceeded"
2075
- ],
2076
- statusCodes: [429, 529],
2077
- // Too Many Requests, Overloaded
2078
- errorCodes: [
2079
- "rate_limit_error",
2080
- "overloaded_error",
2081
- "insufficient_quota"
2082
- ]
2083
- },
2084
- /**
2085
- * OpenAI Error Patterns
2086
- *
2087
- * OpenAI provides detailed error messages for different types of limits.
2088
- * Distinguishes between quota exhaustion and rate limiting.
2089
- */
2090
- openai: {
2091
- quota: [
2092
- "insufficient_quota",
2093
- "quota_exceeded",
2094
- "quota exceeded",
2095
- "billing hard limit reached",
2096
- "usage limit exceeded",
2097
- "monthly quota exceeded",
2098
- "credit limit reached"
2099
- ],
2100
- rateLimit: [
2101
- "rate_limit_exceeded",
2102
- "rate limit exceeded",
2103
- "too_many_requests",
2104
- "too many requests",
2105
- "requests per minute exceeded",
2106
- "tokens per minute exceeded",
2107
- "rate limit reached"
2108
- ],
2109
- statusCodes: [429],
2110
- // Too Many Requests
2111
- errorCodes: [
2112
- "insufficient_quota",
2113
- "rate_limit_exceeded",
2114
- "quota_exceeded",
2115
- "billing_hard_limit_reached"
2116
- ]
2117
- },
2118
- /**
2119
- * Claude Code Provider (extension of Claude patterns)
2120
- */
2121
- "claude-code": {
2122
- quota: [
2123
- "insufficient_quota",
2124
- "quota_exceeded",
2125
- "quota exceeded",
2126
- "credit limit reached",
2127
- "usage limit exceeded",
2128
- "monthly quota exceeded"
2129
- ],
2130
- rateLimit: [
2131
- "rate_limit_error",
2132
- "rate limit exceeded",
2133
- "overloaded_error",
2134
- "overloaded",
2135
- "too many requests",
2136
- "requests per minute exceeded"
2137
- ],
2138
- statusCodes: [429, 529],
2139
- errorCodes: [
2140
- "rate_limit_error",
2141
- "overloaded_error",
2142
- "insufficient_quota"
2143
- ]
2144
- },
2145
- /**
2146
- * Gemini CLI Provider (same patterns as Gemini)
2147
- */
2148
- "gemini-cli": {
2149
- quota: [
2150
- "RESOURCE_EXHAUSTED",
2151
- "resource_exhausted",
2152
- "quotaExceeded",
2153
- "quota exceeded",
2154
- "quota limit reached",
2155
- "daily quota exceeded",
2156
- "monthly quota exceeded",
2157
- "insufficient quota"
2158
- ],
2159
- rateLimit: [
2160
- "RATE_LIMIT_EXCEEDED",
2161
- "rate_limit_exceeded",
2162
- "rate limit exceeded",
2163
- "too many requests",
2164
- "requests per minute exceeded",
2165
- "requests per day exceeded"
2166
- ],
2167
- statusCodes: [429],
2168
- errorCodes: [
2169
- "RESOURCE_EXHAUSTED",
2170
- "RATE_LIMIT_EXCEEDED",
2171
- "QUOTA_EXCEEDED"
2172
- ]
2173
- },
2174
- /**
2175
- * Codex CLI Provider (same patterns as OpenAI)
2176
- */
2177
- codex: {
2178
- quota: [
2179
- "insufficient_quota",
2180
- "quota_exceeded",
2181
- "quota exceeded",
2182
- "billing hard limit reached",
2183
- "usage limit exceeded",
2184
- "monthly quota exceeded",
2185
- "credit limit reached"
2186
- ],
2187
- rateLimit: [
2188
- "rate_limit_exceeded",
2189
- "rate limit exceeded",
2190
- "too_many_requests",
2191
- "too many requests",
2192
- "requests per minute exceeded",
2193
- "tokens per minute exceeded",
2194
- "rate limit reached"
2195
- ],
2196
- statusCodes: [429],
2197
- errorCodes: [
2198
- "insufficient_quota",
2199
- "rate_limit_exceeded",
2200
- "quota_exceeded",
2201
- "billing_hard_limit_reached"
2202
- ]
2203
- },
2204
- /**
2205
- * ax-cli Provider Error Patterns (v9.2.0)
2206
- *
2207
- * ax-cli is a multi-model provider supporting GLM, xAI, OpenAI, Anthropic, Ollama, etc.
2208
- * BUG FIX: Added missing patterns - previously fell back to generic patterns which
2209
- * may miss provider-specific errors from the underlying model providers.
2210
- *
2211
- * Combines patterns from all supported backends since ax-cli proxies to them.
2212
- */
2213
- "ax-cli": {
2214
- quota: [
2215
- // GLM patterns
2216
- "quota exceeded",
2217
- "quota limit reached",
2218
- "insufficient quota",
2219
- // OpenAI patterns (via ax-cli)
2220
- "insufficient_quota",
2221
- "quota_exceeded",
2222
- "billing hard limit reached",
2223
- "usage limit exceeded",
2224
- "monthly quota exceeded",
2225
- "credit limit reached",
2226
- // Anthropic patterns (via ax-cli)
2227
- "credit limit reached",
2228
- // Generic patterns
2229
- "daily quota exceeded",
2230
- "api quota exceeded"
2231
- ],
2232
- rateLimit: [
2233
- // Common patterns
2234
- "rate_limit_exceeded",
2235
- "rate limit exceeded",
2236
- "too_many_requests",
2237
- "too many requests",
2238
- "requests per minute exceeded",
2239
- "tokens per minute exceeded",
2240
- "rate limit reached",
2241
- // Anthropic patterns (via ax-cli)
2242
- "rate_limit_error",
2243
- "overloaded_error",
2244
- "overloaded",
2245
- // xAI/Grok patterns
2246
- "throttled",
2247
- "request throttled"
2248
- ],
2249
- statusCodes: [429, 529],
2250
- errorCodes: [
2251
- "insufficient_quota",
2252
- "rate_limit_exceeded",
2253
- "quota_exceeded",
2254
- "rate_limit_error",
2255
- "overloaded_error",
2256
- "RATE_LIMIT_EXCEEDED",
2257
- "QUOTA_EXCEEDED"
2258
- ]
2259
- }
2145
+ // Primary providers
2146
+ gemini: GEMINI_PATTERNS,
2147
+ claude: CLAUDE_PATTERNS,
2148
+ codex: OPENAI_PATTERNS,
2149
+ "ax-cli": AX_CLI_PATTERNS,
2150
+ // Aliases - reference same patterns to avoid duplication
2151
+ "gemini-cli": GEMINI_PATTERNS,
2152
+ // Alias for gemini
2153
+ "claude-code": CLAUDE_PATTERNS,
2154
+ // Alias for claude
2155
+ "openai": OPENAI_PATTERNS
2156
+ // Alias for codex (same underlying API)
2260
2157
  };
2261
2158
  GENERIC_ERROR_PATTERNS = {
2262
2159
  quota: [
@@ -2639,9 +2536,14 @@ var init_base_provider = __esm({
2639
2536
  });
2640
2537
  child.kill("SIGTERM");
2641
2538
  forceKillTimer = setTimeout(() => {
2642
- if (child.pid && !child.killed) {
2643
- logger.warn("Force killing child process", { pid: child.pid });
2644
- child.kill("SIGKILL");
2539
+ if (child.pid) {
2540
+ try {
2541
+ process.kill(child.pid, 0);
2542
+ logger.warn("Force killing child process", { pid: child.pid });
2543
+ child.kill("SIGKILL");
2544
+ } catch {
2545
+ logger.debug("Process already exited before SIGKILL", { pid: child.pid });
2546
+ }
2645
2547
  }
2646
2548
  }, _BaseProvider.SIGKILL_ESCALATION_MS);
2647
2549
  }
@@ -2822,9 +2724,14 @@ var init_base_provider = __esm({
2822
2724
  });
2823
2725
  child.kill("SIGTERM");
2824
2726
  forceKillTimer = setTimeout(() => {
2825
- if (child.pid && !child.killed) {
2826
- logger.warn("Force killing child process", { pid: child.pid });
2827
- child.kill("SIGKILL");
2727
+ if (child.pid) {
2728
+ try {
2729
+ process.kill(child.pid, 0);
2730
+ logger.warn("Force killing child process", { pid: child.pid });
2731
+ child.kill("SIGKILL");
2732
+ } catch {
2733
+ logger.debug("Process already exited before SIGKILL", { pid: child.pid });
2734
+ }
2828
2735
  }
2829
2736
  }, _BaseProvider.SIGKILL_ESCALATION_MS);
2830
2737
  }
@@ -4103,12 +4010,20 @@ var init_openai_provider = __esm({
4103
4010
  OpenAIProvider = class extends BaseProvider {
4104
4011
  hybridAdapter = null;
4105
4012
  providerConfig;
4013
+ /** BUG FIX: Track pending initialization to prevent race condition where
4014
+ * concurrent execute() calls could each trigger initializeHybridAdapter() */
4015
+ initializationPromise = null;
4016
+ /** BUG FIX: Track destroyed state to prevent use-after-destroy race condition */
4017
+ isDestroyed = false;
4106
4018
  constructor(config) {
4107
4019
  super(config);
4108
4020
  this.providerConfig = config;
4109
4021
  logger.debug("[OpenAI/Codex] Initialized", { mode: config.mode || "auto" });
4110
4022
  }
4111
4023
  async execute(request) {
4024
+ if (this.isDestroyed) {
4025
+ throw new Error("OpenAIProvider has been destroyed and cannot execute requests");
4026
+ }
4112
4027
  if (process.env.AX_MOCK_PROVIDERS === "true") {
4113
4028
  return {
4114
4029
  content: this.getMockResponse(),
@@ -4119,9 +4034,7 @@ var init_openai_provider = __esm({
4119
4034
  };
4120
4035
  }
4121
4036
  const startTime = Date.now();
4122
- if (!this.hybridAdapter) {
4123
- this.initializeHybridAdapter();
4124
- }
4037
+ await this.ensureInitialized();
4125
4038
  try {
4126
4039
  const result = await this.hybridAdapter.execute(
4127
4040
  request.prompt,
@@ -4146,7 +4059,30 @@ var init_openai_provider = __esm({
4146
4059
  throw this.handleError(error);
4147
4060
  }
4148
4061
  }
4149
- initializeHybridAdapter() {
4062
+ /**
4063
+ * BUG FIX: Ensure adapter is initialized exactly once, even with concurrent calls.
4064
+ * Uses a promise-based lock pattern to prevent race conditions where multiple
4065
+ * execute() calls could each trigger initializeHybridAdapter().
4066
+ */
4067
+ async ensureInitialized() {
4068
+ if (this.hybridAdapter) {
4069
+ return;
4070
+ }
4071
+ if (this.initializationPromise) {
4072
+ await this.initializationPromise;
4073
+ return;
4074
+ }
4075
+ this.initializationPromise = this.initializeHybridAdapter();
4076
+ try {
4077
+ await this.initializationPromise;
4078
+ } finally {
4079
+ this.initializationPromise = null;
4080
+ }
4081
+ }
4082
+ async initializeHybridAdapter() {
4083
+ if (this.hybridAdapter) {
4084
+ return;
4085
+ }
4150
4086
  const options = {
4151
4087
  mode: this.providerConfig.mode || "auto",
4152
4088
  cli: {
@@ -4184,6 +4120,7 @@ var init_openai_provider = __esm({
4184
4120
  this.hybridAdapter?.switchToCliMode();
4185
4121
  }
4186
4122
  async destroy() {
4123
+ this.isDestroyed = true;
4187
4124
  if (this.hybridAdapter) {
4188
4125
  await this.hybridAdapter.destroy();
4189
4126
  this.hybridAdapter = null;
@@ -18203,13 +18140,17 @@ init_logger();
18203
18140
  // src/providers/mcp/mcp-client.ts
18204
18141
  init_esm_shims();
18205
18142
  init_logger();
18206
- var McpClient = class extends EventEmitter {
18143
+ var McpClient = class _McpClient extends EventEmitter {
18207
18144
  config;
18208
18145
  process = null;
18209
18146
  readline = null;
18210
18147
  state;
18211
18148
  pendingRequests = /* @__PURE__ */ new Map();
18212
18149
  nextRequestId = 1;
18150
+ /** BUG FIX: Maximum request ID before wraparound to prevent Number precision loss.
18151
+ * JavaScript loses integer precision after Number.MAX_SAFE_INTEGER (2^53 - 1).
18152
+ * Using 1 billion as a safe wraparound point - still unique within any realistic session. */
18153
+ static MAX_REQUEST_ID = 1e9;
18213
18154
  serverInfo = null;
18214
18155
  constructor(config) {
18215
18156
  super();
@@ -18399,6 +18340,9 @@ var McpClient = class extends EventEmitter {
18399
18340
  throw new Error("MCP client not connected");
18400
18341
  }
18401
18342
  const id = this.nextRequestId++;
18343
+ if (this.nextRequestId > _McpClient.MAX_REQUEST_ID) {
18344
+ this.nextRequestId = 1;
18345
+ }
18402
18346
  const request = {
18403
18347
  jsonrpc: "2.0",
18404
18348
  id,
@@ -18729,10 +18673,13 @@ var McpClientPool = class extends EventEmitter {
18729
18673
  } else {
18730
18674
  this.removeFromPool(pool, pooledClient);
18731
18675
  this.emitEvent("connection_closed", provider, { reason: "connection_died" });
18676
+ pool.pendingConnections++;
18732
18677
  this.createConnection(provider).then((newClient) => {
18733
18678
  pool.clients.push(this.createPooledClient(newClient));
18734
18679
  waiter.resolve(newClient);
18735
- }).catch(waiter.reject);
18680
+ }).catch(waiter.reject).finally(() => {
18681
+ pool.pendingConnections--;
18682
+ });
18736
18683
  }
18737
18684
  }
18738
18685
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defai.digital/automatosx",
3
- "version": "11.3.3",
3
+ "version": "11.3.4",
4
4
  "description": "Provider-agnostic AI orchestration platform with 20+ specialized agents, persistent memory, and multi-provider routing for Claude Code, Gemini CLI, Codex CLI, and ax-cli",
5
5
  "type": "module",
6
6
  "publishConfig": {