@juspay/neurolink 11.1.0 → 11.2.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.
Files changed (43) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/browser/neurolink.min.js +367 -367
  3. package/dist/cli/commands/setup.d.ts +4 -1
  4. package/dist/cli/commands/setup.js +44 -14
  5. package/dist/constants/networkErrorCodes.d.ts +14 -0
  6. package/dist/constants/networkErrorCodes.js +21 -0
  7. package/dist/factories/providerDescriptors.js +13 -3
  8. package/dist/lib/constants/networkErrorCodes.d.ts +14 -0
  9. package/dist/lib/constants/networkErrorCodes.js +22 -0
  10. package/dist/lib/factories/providerDescriptors.js +13 -3
  11. package/dist/lib/processors/base/BaseFileProcessor.d.ts +17 -0
  12. package/dist/lib/processors/base/BaseFileProcessor.js +40 -0
  13. package/dist/lib/processors/document/OpenDocumentProcessor.js +12 -2
  14. package/dist/lib/providers/configuredOpenAICompat.d.ts +24 -0
  15. package/dist/lib/providers/configuredOpenAICompat.js +60 -0
  16. package/dist/lib/providers/openaiCompatCatalog.d.ts +24 -0
  17. package/dist/lib/providers/openaiCompatCatalog.js +272 -0
  18. package/dist/lib/proxy/proxyFetch.js +1 -9
  19. package/dist/lib/types/cli.d.ts +2 -0
  20. package/dist/lib/types/providers.d.ts +116 -2
  21. package/dist/lib/utils/errorClassifier.js +100 -11
  22. package/dist/lib/utils/providerConfig.d.ts +39 -1
  23. package/dist/lib/utils/providerConfig.js +83 -0
  24. package/dist/lib/utils/providerHealth.d.ts +30 -24
  25. package/dist/lib/utils/providerHealth.js +42 -41
  26. package/dist/lib/utils/providerUtils.js +2 -2
  27. package/dist/processors/base/BaseFileProcessor.d.ts +17 -0
  28. package/dist/processors/base/BaseFileProcessor.js +40 -0
  29. package/dist/processors/document/OpenDocumentProcessor.js +12 -2
  30. package/dist/providers/configuredOpenAICompat.d.ts +24 -0
  31. package/dist/providers/configuredOpenAICompat.js +59 -0
  32. package/dist/providers/openaiCompatCatalog.d.ts +24 -0
  33. package/dist/providers/openaiCompatCatalog.js +271 -0
  34. package/dist/proxy/proxyFetch.js +1 -9
  35. package/dist/types/cli.d.ts +2 -0
  36. package/dist/types/providers.d.ts +116 -2
  37. package/dist/utils/errorClassifier.js +100 -11
  38. package/dist/utils/providerConfig.d.ts +39 -1
  39. package/dist/utils/providerConfig.js +83 -0
  40. package/dist/utils/providerHealth.d.ts +30 -24
  41. package/dist/utils/providerHealth.js +42 -41
  42. package/dist/utils/providerUtils.js +2 -2
  43. package/package.json +2 -1
@@ -185,6 +185,29 @@ export function getProviderModel(envVar, defaultModel) {
185
185
  export function hasProviderCredentials(envVars) {
186
186
  return envVars.some((envVar) => !!process.env[envVar]);
187
187
  }
188
+ /**
189
+ * Evaluates a `ProviderDescriptor.envVars.extraRequiredFallbacks`-shaped
190
+ * list against an env-var source. Each entry is either a single env var
191
+ * name (satisfied on its own) or a nested array of names that must ALL be
192
+ * present together (e.g. Vertex's GOOGLE_AUTH_CLIENT_EMAIL +
193
+ * GOOGLE_AUTH_PRIVATE_KEY pair, which is only valid auth as a pair).
194
+ * Returns true when at least one entry is satisfied. The single evaluation
195
+ * site for this shape — every consumer (providerUtils.ts, providerHealth.ts,
196
+ * setup.ts, environmentManager.ts) must call this instead of re-deriving the
197
+ * same `.some()`/`.every()` logic, so they can't drift out of sync with each
198
+ * other or with the real auth gate (hasGoogleCredentials()).
199
+ * @param env Explicit env-var source (`process.env`, or a parsed .env file) —
200
+ * never hardcoded, so callers checking a file's contents (not the live
201
+ * process env) can reuse this too.
202
+ */
203
+ export function satisfiesFallbacks(fallbacks, env) {
204
+ if (!fallbacks) {
205
+ return false;
206
+ }
207
+ return fallbacks.some((entry) => typeof entry === "string"
208
+ ? !!env[entry]
209
+ : entry.every((name) => !!env[name]));
210
+ }
188
211
  // =============================================================================
189
212
  // PROVIDER-SPECIFIC CONFIGURATION CREATORS
190
213
  // =============================================================================
@@ -1277,4 +1300,64 @@ export function describeAnthropicConfig() {
1277
1300
  lines.push(`Priority Access: ${config.limits.priorityAccess ? "Yes" : "No"}`);
1278
1301
  return lines.join("\n");
1279
1302
  }
1303
+ /**
1304
+ * Resolves the {apiKey, baseURL} pair for a config-driven OpenAI-compatible
1305
+ * catalog entry (see OpenAICompatCatalogEntry in types/providers.ts).
1306
+ *
1307
+ * Extracted from the identical 6-line precedence block that was copy-pasted
1308
+ * across groq.ts, xai.ts, togetherAi.ts, fireworks.ts, perplexity.ts, and
1309
+ * mistral.ts, plus Cloudflare's accountId-computed-baseURL variant.
1310
+ *
1311
+ * Precedence (matches every ported subclass's original behavior exactly):
1312
+ * apiKey: credentials.apiKey (trimmed, non-blank) > env var > throw
1313
+ * baseURL: credentials.baseURL (trimmed, non-blank)
1314
+ * > env var (if entry.baseURLEnvVar is set, trimmed, non-blank)
1315
+ * > entry.defaultBaseURL
1316
+ * baseURL (computedBaseURL entries, e.g. Cloudflare):
1317
+ * credentials.baseURL > computedBaseURL.build(accountId), where
1318
+ * accountId = credentials.accountId (trimmed) > env var (trimmed)
1319
+ * > throw computedBaseURL.missingValueMessage
1320
+ */
1321
+ export function resolveOpenAICompatConfig(entry, credentials) {
1322
+ const overrideApiKey = credentials?.apiKey?.trim();
1323
+ const apiKey = overrideApiKey && overrideApiKey.length > 0
1324
+ ? overrideApiKey
1325
+ : validateApiKey(entry.configOptions);
1326
+ if (entry.computedBaseURL) {
1327
+ const { envVar, missingValueMessage, build } = entry.computedBaseURL;
1328
+ // An explicit base URL is checked first and trimmed the same way the
1329
+ // static branch trims it. It makes the account id irrelevant — there is
1330
+ // nothing left to build — so demanding one anyway would reject a fully
1331
+ // specified override.
1332
+ const overrideComputedBaseURL = credentials?.baseURL?.trim();
1333
+ if (overrideComputedBaseURL && overrideComputedBaseURL.length > 0) {
1334
+ return { apiKey, baseURL: overrideComputedBaseURL };
1335
+ }
1336
+ const extraValue = (credentials?.accountId ??
1337
+ process.env[envVar] ??
1338
+ "").trim();
1339
+ if (!extraValue) {
1340
+ throw new Error(missingValueMessage);
1341
+ }
1342
+ return { apiKey, baseURL: build(extraValue) };
1343
+ }
1344
+ const overrideBaseURL = credentials?.baseURL?.trim();
1345
+ const envBaseURL = entry.baseURLEnvVar
1346
+ ? process.env[entry.baseURLEnvVar]?.trim()
1347
+ : undefined;
1348
+ const baseURL = (overrideBaseURL && overrideBaseURL.length > 0
1349
+ ? overrideBaseURL
1350
+ : undefined) ??
1351
+ (envBaseURL && envBaseURL.length > 0 ? envBaseURL : undefined) ??
1352
+ entry.defaultBaseURL;
1353
+ if (!baseURL) {
1354
+ // Reachable only for an entry that sets neither defaultBaseURL nor
1355
+ // computedBaseURL. Returning "" instead would hand the SDK an empty base
1356
+ // URL and surface as a confusing request failure far from the cause.
1357
+ throw new Error(`${entry.providerName}: no base URL. Set one in credentials` +
1358
+ (entry.baseURLEnvVar ? `, set ${entry.baseURLEnvVar}` : "") +
1359
+ `, or give the catalog entry a defaultBaseURL.`);
1360
+ }
1361
+ return { apiKey, baseURL };
1362
+ }
1280
1363
  //# sourceMappingURL=providerConfig.js.map
@@ -36,27 +36,25 @@ export declare class ProviderHealthChecker {
36
36
  */
37
37
  private static checkModelAvailability;
38
38
  /**
39
- * Providers whose credential model can't be reduced to "every one of
40
- * these exact env vars must be literally set" — the check in
41
- * checkEnvironmentConfiguration() below ANDs every entry in the
42
- * returned list together, which can't express Vertex's file-OR-
43
- * individual-creds-OR-service-account auth, Bedrock's AWS SDK default
44
- * provider chain (profile / IAM role, no env vars at all), or
45
- * LiteLLM's documented zero-config local proxy. Their real requirement
46
- * is validated by checkProviderSpecificConfig()'s dedicated per-provider
47
- * checks instead matches the original hand-written switch's
48
- * deliberate `return []` for exactly these three. Naively deriving
49
- * [apiKey, ...extraRequired] from the descriptor here (as for the other
50
- * 27 providers) would make checkEnvironmentConfiguration() push a false
51
- * "missing environment variables" issue and therefore isHealthy=false
52
- * — for legitimate fallback-based Vertex auth, AWS_PROFILE/IAM-role
53
- * Bedrock auth, and unauthenticated local LiteLLM proxies. See
54
- * hasProviderEnvVars() in providerUtils.ts for the equivalent OR-aware
55
- * check used for auto-select gating.
56
- */
57
- private static readonly ENV_CHECK_DELEGATED_TO_SPECIFIC_CONFIG;
58
- /**
59
- * Get required environment variables for a provider
39
+ * Get required environment variables for a provider.
40
+ *
41
+ * Returns `[]` for providers with `descriptor.credentialsResolvedExternally
42
+ * === true` (Vertex, Bedrock, LiteLLM) the check in
43
+ * checkEnvironmentConfiguration() below ANDs every entry in the returned
44
+ * list together, which can't express Vertex's file-OR-individual-creds-
45
+ * OR-service-account auth, Bedrock's AWS SDK default provider chain
46
+ * (profile / IAM role, no env vars at all), or LiteLLM's documented
47
+ * zero-config local proxy. Their real requirement is validated by
48
+ * checkProviderSpecificConfig()'s dedicated per-provider checks instead.
49
+ * Naively deriving [apiKey, ...extraRequired] from the descriptor for
50
+ * these three (as for the other 27 providers) would make
51
+ * checkEnvironmentConfiguration() push a false "missing environment
52
+ * variables" issue and therefore isHealthy=false for legitimate
53
+ * fallback-based Vertex auth, AWS_PROFILE/IAM-role Bedrock auth, and
54
+ * unauthenticated local LiteLLM proxies. See hasProviderEnvVars() in
55
+ * providerUtils.ts for the equivalent OR-aware check used for
56
+ * auto-select gating. See `ProviderDescriptor.credentialsResolvedExternally`
57
+ * (types/providers.ts) for the field's full documentation.
60
58
  */
61
59
  static getRequiredEnvironmentVariables(providerName: string): string[];
62
60
  /**
@@ -107,9 +105,17 @@ export declare class ProviderHealthChecker {
107
105
  */
108
106
  private static checkGoogleApplicationCredentials;
109
107
  /**
110
- * Check individual Google credentials
111
- */
112
- private static checkIndividualGoogleCredentials;
108
+ * Check Vertex's non-file auth fallbacks (GOOGLE_APPLICATION_CREDENTIALS_
109
+ * NEUROLINK, GOOGLE_SERVICE_ACCOUNT_KEY, or the GOOGLE_AUTH_CLIENT_EMAIL +
110
+ * GOOGLE_AUTH_PRIVATE_KEY pair) via the descriptor's extraRequiredFallbacks
111
+ * instead of a hand-maintained env-var list, so this stays in sync with
112
+ * the real gating logic (hasGoogleCredentials()) the same way
113
+ * checkApiKeyValidity()'s vertex branch does. The previous hand-rolled
114
+ * version only recognized GOOGLE_SERVICE_ACCOUNT_KEY or the email+key
115
+ * pair — missing GOOGLE_APPLICATION_CREDENTIALS_NEUROLINK, the
116
+ * descriptor's documented first-priority fallback.
117
+ */
118
+ private static checkExtraRequiredFallbackCredentials;
113
119
  /**
114
120
  * Check AWS Bedrock configuration
115
121
  */
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import { logger } from "./logger.js";
6
6
  import { AIProviderName, OpenAIModels, GoogleAIModels, AnthropicModels, BedrockModels, } from "../constants/enums.js";
7
- import { PROJECT_ID_FORMAT } from "./providerConfig.js";
7
+ import { PROJECT_ID_FORMAT, satisfiesFallbacks } from "./providerConfig.js";
8
8
  import { basename } from "path";
9
9
  import { createProxyFetch } from "../proxy/proxyFetch.js";
10
10
  import { DEFAULT_OLLAMA_MODEL } from "../providers/ollama/constants.js";
@@ -194,7 +194,7 @@ export class ProviderHealthChecker {
194
194
  const descriptor = ProviderFactory.getDescriptor(AIProviderName.VERTEX);
195
195
  const { extraRequired, extraRequiredFallbacks } = descriptor?.envVars ?? {};
196
196
  const hasValidAuth = (extraRequired ?? []).every((v) => !!process.env[v]) ||
197
- (extraRequiredFallbacks ?? []).some((v) => !!process.env[v]);
197
+ satisfiesFallbacks(extraRequiredFallbacks, process.env);
198
198
  logger.debug("Vertex auth final result", { hasValidAuth });
199
199
  if (hasValidAuth) {
200
200
  healthStatus.hasApiKey = true;
@@ -342,46 +342,40 @@ export class ProviderHealthChecker {
342
342
  }
343
343
  }
344
344
  /**
345
- * Providers whose credential model can't be reduced to "every one of
346
- * these exact env vars must be literally set" — the check in
347
- * checkEnvironmentConfiguration() below ANDs every entry in the
348
- * returned list together, which can't express Vertex's file-OR-
349
- * individual-creds-OR-service-account auth, Bedrock's AWS SDK default
350
- * provider chain (profile / IAM role, no env vars at all), or
351
- * LiteLLM's documented zero-config local proxy. Their real requirement
352
- * is validated by checkProviderSpecificConfig()'s dedicated per-provider
353
- * checks instead matches the original hand-written switch's
354
- * deliberate `return []` for exactly these three. Naively deriving
355
- * [apiKey, ...extraRequired] from the descriptor here (as for the other
356
- * 27 providers) would make checkEnvironmentConfiguration() push a false
357
- * "missing environment variables" issue and therefore isHealthy=false
358
- * — for legitimate fallback-based Vertex auth, AWS_PROFILE/IAM-role
359
- * Bedrock auth, and unauthenticated local LiteLLM proxies. See
360
- * hasProviderEnvVars() in providerUtils.ts for the equivalent OR-aware
361
- * check used for auto-select gating.
362
- */
363
- static ENV_CHECK_DELEGATED_TO_SPECIFIC_CONFIG = new Set([
364
- AIProviderName.VERTEX,
365
- AIProviderName.BEDROCK,
366
- AIProviderName.LITELLM,
367
- ]);
368
- /**
369
- * Get required environment variables for a provider
345
+ * Get required environment variables for a provider.
346
+ *
347
+ * Returns `[]` for providers with `descriptor.credentialsResolvedExternally
348
+ * === true` (Vertex, Bedrock, LiteLLM) the check in
349
+ * checkEnvironmentConfiguration() below ANDs every entry in the returned
350
+ * list together, which can't express Vertex's file-OR-individual-creds-
351
+ * OR-service-account auth, Bedrock's AWS SDK default provider chain
352
+ * (profile / IAM role, no env vars at all), or LiteLLM's documented
353
+ * zero-config local proxy. Their real requirement is validated by
354
+ * checkProviderSpecificConfig()'s dedicated per-provider checks instead.
355
+ * Naively deriving [apiKey, ...extraRequired] from the descriptor for
356
+ * these three (as for the other 27 providers) would make
357
+ * checkEnvironmentConfiguration() push a false "missing environment
358
+ * variables" issue and therefore isHealthy=false for legitimate
359
+ * fallback-based Vertex auth, AWS_PROFILE/IAM-role Bedrock auth, and
360
+ * unauthenticated local LiteLLM proxies. See hasProviderEnvVars() in
361
+ * providerUtils.ts for the equivalent OR-aware check used for
362
+ * auto-select gating. See `ProviderDescriptor.credentialsResolvedExternally`
363
+ * (types/providers.ts) for the field's full documentation.
370
364
  */
371
365
  static getRequiredEnvironmentVariables(providerName) {
372
- // Resolve the descriptor FIRST so the delegation-Set check below is
373
- // keyed on the canonical, alias-resolved `descriptor.name` — not the
374
- // raw, possibly-aliased `providerName` argument. Checking the raw
375
- // input here would let documented aliases (e.g. "googleVertex" for
366
+ // Resolve the descriptor FIRST so the field check below is keyed on
367
+ // the canonical, alias-resolved `descriptor.credentialsResolvedExternally`
368
+ // — not the raw, possibly-aliased `providerName` argument. Checking the
369
+ // raw input here would let documented aliases (e.g. "googleVertex" for
376
370
  // vertex, "aws" for bedrock) skip the delegation and fall through to
377
371
  // the naive [apiKey, ...extraRequired] derivation below, reproducing
378
372
  // the exact false "missing environment variables" regression this
379
- // Set exists to prevent.
373
+ // field exists to prevent.
380
374
  const descriptor = ProviderFactory.getDescriptor(providerName);
381
375
  if (!descriptor) {
382
376
  return [];
383
377
  }
384
- if (this.ENV_CHECK_DELEGATED_TO_SPECIFIC_CONFIG.has(descriptor.name)) {
378
+ if (descriptor.credentialsResolvedExternally) {
385
379
  return [];
386
380
  }
387
381
  const { apiKey, extraRequired } = descriptor.envVars;
@@ -518,11 +512,11 @@ export class ProviderHealthChecker {
518
512
  hasValidAuth = await this.checkGoogleApplicationCredentials(healthStatus);
519
513
  }
520
514
  if (!hasValidAuth) {
521
- hasValidAuth = this.checkIndividualGoogleCredentials(healthStatus);
515
+ hasValidAuth = this.checkExtraRequiredFallbackCredentials(healthStatus);
522
516
  }
523
517
  if (!hasValidAuth) {
524
518
  healthStatus.configurationIssues.push("Google Cloud authentication not configured or credentials file missing");
525
- healthStatus.recommendations.push("Set either GOOGLE_APPLICATION_CREDENTIALS (valid file path), GOOGLE_SERVICE_ACCOUNT_KEY (base64), or both GOOGLE_AUTH_CLIENT_EMAIL and GOOGLE_AUTH_PRIVATE_KEY");
519
+ healthStatus.recommendations.push("Set either GOOGLE_APPLICATION_CREDENTIALS (valid file path), GOOGLE_APPLICATION_CREDENTIALS_NEUROLINK, GOOGLE_SERVICE_ACCOUNT_KEY (base64), or both GOOGLE_AUTH_CLIENT_EMAIL and GOOGLE_AUTH_PRIVATE_KEY");
526
520
  }
527
521
  return hasValidAuth;
528
522
  }
@@ -554,13 +548,20 @@ export class ProviderHealthChecker {
554
548
  }
555
549
  }
556
550
  /**
557
- * Check individual Google credentials
551
+ * Check Vertex's non-file auth fallbacks (GOOGLE_APPLICATION_CREDENTIALS_
552
+ * NEUROLINK, GOOGLE_SERVICE_ACCOUNT_KEY, or the GOOGLE_AUTH_CLIENT_EMAIL +
553
+ * GOOGLE_AUTH_PRIVATE_KEY pair) via the descriptor's extraRequiredFallbacks
554
+ * instead of a hand-maintained env-var list, so this stays in sync with
555
+ * the real gating logic (hasGoogleCredentials()) the same way
556
+ * checkApiKeyValidity()'s vertex branch does. The previous hand-rolled
557
+ * version only recognized GOOGLE_SERVICE_ACCOUNT_KEY or the email+key
558
+ * pair — missing GOOGLE_APPLICATION_CREDENTIALS_NEUROLINK, the
559
+ * descriptor's documented first-priority fallback.
558
560
  */
559
- static checkIndividualGoogleCredentials(healthStatus) {
560
- const hasServiceAccountKey = !!process.env.GOOGLE_SERVICE_ACCOUNT_KEY;
561
- const hasIndividualCredentials = !!(process.env.GOOGLE_AUTH_CLIENT_EMAIL &&
562
- process.env.GOOGLE_AUTH_PRIVATE_KEY);
563
- if (hasServiceAccountKey || hasIndividualCredentials) {
561
+ static checkExtraRequiredFallbackCredentials(healthStatus) {
562
+ const descriptor = ProviderFactory.getDescriptor(AIProviderName.VERTEX);
563
+ const hasValidAuth = satisfiesFallbacks(descriptor?.envVars.extraRequiredFallbacks, process.env);
564
+ if (hasValidAuth) {
564
565
  healthStatus.hasApiKey = true;
565
566
  return true;
566
567
  }
@@ -6,7 +6,7 @@ import { AIProviderFactory } from "../core/factory.js";
6
6
  import { logger } from "./logger.js";
7
7
  import { AIProviderName } from "../constants/enums.js";
8
8
  import { ProviderHealthChecker } from "./providerHealth.js";
9
- import { API_KEY_FORMATS, API_KEY_LENGTHS, PROJECT_ID_FORMAT, } from "./providerConfig.js";
9
+ import { API_KEY_FORMATS, API_KEY_LENGTHS, PROJECT_ID_FORMAT, satisfiesFallbacks, } from "./providerConfig.js";
10
10
  import { DEFAULT_OLLAMA_MODEL } from "../providers/ollama/constants.js";
11
11
  import { ProviderFactory } from "../factories/providerFactory.js";
12
12
  import { PROVIDER_DESCRIPTORS } from "../factories/providerDescriptors.js";
@@ -340,7 +340,7 @@ export function hasProviderEnvVars(provider) {
340
340
  return false;
341
341
  }
342
342
  return ((extraRequired ?? []).every((v) => !!process.env[v]) ||
343
- (extraRequiredFallbacks ?? []).some((v) => !!process.env[v]));
343
+ satisfiesFallbacks(extraRequiredFallbacks, process.env));
344
344
  }
345
345
  /**
346
346
  * Get available provider names
@@ -45,6 +45,23 @@
45
45
  */
46
46
  import { FileErrorCode } from "../errors/index.js";
47
47
  import type { BatchProcessingSummary, FileInfo, FileProcessingError, ProcessorFileProcessingResult, FileProcessorConfig, ProcessorOperationResult, ProcessedFileBase, ProcessOptions } from "../../types/index.js";
48
+ /**
49
+ * Marker on the error raised when a processor refuses content for exceeding
50
+ * the size limit *after* the download — a ZIP entry that expands past the
51
+ * bound, say.
52
+ *
53
+ * Separate from DOWNLOAD_TOO_LARGE because the two fire at different stages,
54
+ * but it exists for the same reason. Without it a bound that fires reaches
55
+ * `buildProcessedResultWithResult` as a plain Error and becomes
56
+ * PROCESSING_FAILED, which is `retryable: true` — so a caller retries a
57
+ * deterministic refusal three times and gets the identical answer each time.
58
+ * FILE_TOO_LARGE is `retryable: false`, which is the truth about this failure.
59
+ */
60
+ export declare const CONTENT_TOO_LARGE_CODE = "CONTENT_TOO_LARGE";
61
+ /** An error that a processor's own size bound was exceeded. */
62
+ export declare function contentTooLargeError(message: string): Error;
63
+ /** Whether `error` is a processor size bound firing rather than a fault. */
64
+ export declare function isContentTooLarge(error: unknown): boolean;
48
65
  /**
49
66
  * Abstract base class for file processors.
50
67
  * Provides common download, validation, and error handling functionality.
@@ -72,6 +72,29 @@ function downloadTooLargeError(maxSizeMB, typeName) {
72
72
  function isDownloadTooLarge(error) {
73
73
  return (error?.code === DOWNLOAD_TOO_LARGE_CODE);
74
74
  }
75
+ /**
76
+ * Marker on the error raised when a processor refuses content for exceeding
77
+ * the size limit *after* the download — a ZIP entry that expands past the
78
+ * bound, say.
79
+ *
80
+ * Separate from DOWNLOAD_TOO_LARGE because the two fire at different stages,
81
+ * but it exists for the same reason. Without it a bound that fires reaches
82
+ * `buildProcessedResultWithResult` as a plain Error and becomes
83
+ * PROCESSING_FAILED, which is `retryable: true` — so a caller retries a
84
+ * deterministic refusal three times and gets the identical answer each time.
85
+ * FILE_TOO_LARGE is `retryable: false`, which is the truth about this failure.
86
+ */
87
+ export const CONTENT_TOO_LARGE_CODE = "CONTENT_TOO_LARGE";
88
+ /** An error that a processor's own size bound was exceeded. */
89
+ export function contentTooLargeError(message) {
90
+ const error = new Error(message);
91
+ error.code = CONTENT_TOO_LARGE_CODE;
92
+ return error;
93
+ }
94
+ /** Whether `error` is a processor size bound firing rather than a fault. */
95
+ export function isContentTooLarge(error) {
96
+ return (error?.code === CONTENT_TOO_LARGE_CODE);
97
+ }
75
98
  /** Node's signal that a zlib output bound was reached. */
76
99
  function isBufferTooLargeError(error) {
77
100
  return (error?.code === "ERR_BUFFER_TOO_LARGE");
@@ -360,6 +383,23 @@ export class BaseFileProcessor {
360
383
  return { success: true, data: result };
361
384
  }
362
385
  catch (error) {
386
+ // A size bound firing is a verdict, not a fault: PROCESSING_FAILED is
387
+ // retryable, and re-running a decompression that will hit the same
388
+ // ceiling is the one thing worth not doing three times.
389
+ if (isContentTooLarge(error)) {
390
+ return {
391
+ success: false,
392
+ // Same detail keys as the other FILE_TOO_LARGE sites, so anything
393
+ // reading them does not have to special-case where the verdict came
394
+ // from. `sizeMB` is absent on purpose: the decompressed size is the
395
+ // number this bound exists to never find out.
396
+ error: this.createError(FileErrorCode.FILE_TOO_LARGE, {
397
+ maxMB: this.config.maxSizeMB,
398
+ type: this.config.fileTypeName,
399
+ reason: error instanceof Error ? error.message : undefined,
400
+ }),
401
+ };
402
+ }
363
403
  return {
364
404
  success: false,
365
405
  error: this.createError(FileErrorCode.PROCESSING_FAILED, { fileType: this.config.fileTypeName }, error instanceof Error ? error : undefined),
@@ -8,7 +8,7 @@
8
8
  */
9
9
  import { createRequire } from "node:module";
10
10
  import * as zlib from "node:zlib";
11
- import { BaseFileProcessor } from "../base/BaseFileProcessor.js";
11
+ import { BaseFileProcessor, contentTooLargeError, isContentTooLarge, } from "../base/BaseFileProcessor.js";
12
12
  import { readZipEntryWithinLimit } from "../archive/zipEntryReader.js";
13
13
  import { SIZE_LIMITS } from "../config/index.js";
14
14
  const require = createRequire(import.meta.url);
@@ -71,7 +71,10 @@ export class OpenDocumentProcessor extends BaseFileProcessor {
71
71
  // `maxSizeMB` only ever saw the compressed archive on the way in.
72
72
  const read = readZipEntryWithinLimit(contentEntry, SIZE_LIMITS.DOCUMENT_MAX_MB * 1024 * 1024, zlib);
73
73
  if (read.status === "too-large") {
74
- throw new Error(`content.xml exceeds the ${SIZE_LIMITS.DOCUMENT_MAX_MB}MB limit for OpenDocument content`);
74
+ // Coded, so the bound surfaces as FILE_TOO_LARGE (not retryable)
75
+ // rather than PROCESSING_FAILED (retryable). The file will be
76
+ // exactly as oversized on the next attempt.
77
+ throw contentTooLargeError(`content.xml in "${this.getFilename(fileInfo)}" exceeds the ${SIZE_LIMITS.DOCUMENT_MAX_MB}MB limit for OpenDocument content`);
75
78
  }
76
79
  if (read.status !== "ok") {
77
80
  throw new Error("content.xml could not be read from the archive");
@@ -93,6 +96,13 @@ export class OpenDocumentProcessor extends BaseFileProcessor {
93
96
  }
94
97
  }
95
98
  catch (error) {
99
+ // A size verdict passes through intact. Re-wrapping it as a plain Error
100
+ // drops the code, and the base class then reports PROCESSING_FAILED —
101
+ // which is retryable, so the caller would refetch and decompress a file
102
+ // guaranteed to be exactly as oversized.
103
+ if (isContentTooLarge(error)) {
104
+ throw error;
105
+ }
96
106
  const message = error instanceof Error ? error.message : "Unknown error";
97
107
  throw new Error(`Failed to extract OpenDocument content: ${message}`, {
98
108
  cause: error,
@@ -0,0 +1,24 @@
1
+ import type { AIProviderName } from "../constants/enums.js";
2
+ import type { OpenAICompatCatalogEntry, OpenAICompatCredentials } from "../types/index.js";
3
+ import { OpenAIChatCompletionsProvider } from "./openaiChatCompletionsBase.js";
4
+ /**
5
+ * Generic OpenAI-compatible provider driven entirely by an
6
+ * OpenAICompatCatalogEntry. Replaces a hand-written subclass for any
7
+ * provider whose only differences from its siblings are credentials, base
8
+ * URL, model defaults, and error-classification rules — see
9
+ * OPENAI_COMPAT_CATALOG in openaiCompatCatalog.ts for the entries.
10
+ *
11
+ * If a provider needs a real hook override (adjustRequestBody,
12
+ * adjustBodyAfter400, getChatCompletionsURL, getAuthHeaders,
13
+ * suppressResponseFormatWithTools, ...) it does NOT belong in the catalog —
14
+ * write a dedicated subclass instead (see deepseek.ts, azureOpenai.ts).
15
+ */
16
+ export declare class ConfiguredOpenAICompatProvider extends OpenAIChatCompletionsProvider {
17
+ private readonly entry;
18
+ constructor(entry: OpenAICompatCatalogEntry, modelName?: string, sdk?: unknown, credentials?: OpenAICompatCredentials);
19
+ protected getProviderName(): AIProviderName;
20
+ protected getDefaultModel(): string;
21
+ protected getFallbackModelName(): string;
22
+ protected getFallbackModels(): string[];
23
+ protected formatProviderError(error: unknown): Error;
24
+ }
@@ -0,0 +1,59 @@
1
+ import { logger } from "../utils/logger.js";
2
+ import { redactUrlCredentials } from "../utils/logSanitize.js";
3
+ import { getProviderModel, resolveOpenAICompatConfig, } from "../utils/providerConfig.js";
4
+ import { classifyProviderError } from "../utils/errorClassifier.js";
5
+ import { OpenAIChatCompletionsProvider } from "./openaiChatCompletionsBase.js";
6
+ /**
7
+ * Generic OpenAI-compatible provider driven entirely by an
8
+ * OpenAICompatCatalogEntry. Replaces a hand-written subclass for any
9
+ * provider whose only differences from its siblings are credentials, base
10
+ * URL, model defaults, and error-classification rules — see
11
+ * OPENAI_COMPAT_CATALOG in openaiCompatCatalog.ts for the entries.
12
+ *
13
+ * If a provider needs a real hook override (adjustRequestBody,
14
+ * adjustBodyAfter400, getChatCompletionsURL, getAuthHeaders,
15
+ * suppressResponseFormatWithTools, ...) it does NOT belong in the catalog —
16
+ * write a dedicated subclass instead (see deepseek.ts, azureOpenai.ts).
17
+ */
18
+ export class ConfiguredOpenAICompatProvider extends OpenAIChatCompletionsProvider {
19
+ entry;
20
+ constructor(entry, modelName, sdk, credentials) {
21
+ const { apiKey, baseURL } = resolveOpenAICompatConfig(entry, credentials);
22
+ // BaseProvider's constructor calls `this.getDefaultModel()` /
23
+ // `this.getProviderName()` synchronously inside `super()`, before this
24
+ // class's own constructor body (or field initializers) ever run — so
25
+ // `this.entry` is not yet assigned at that point and those overrides
26
+ // would read `undefined.modelEnvVar`. `entry.providerName` is always
27
+ // defined, so passing it straight through makes the base constructor's
28
+ // `providerName || this.getProviderName()` short-circuit; resolving the
29
+ // model up front and always passing a truthy `modelName` does the same
30
+ // for `getDefaultModel()`. Both overrides remain correct for any call
31
+ // made after construction, once `this.entry` is set below.
32
+ const resolvedModelName = modelName || getProviderModel(entry.modelEnvVar, entry.defaultModel);
33
+ super(entry.providerName, resolvedModelName, sdk, { baseURL, apiKey });
34
+ this.entry = entry;
35
+ logger.debug(`${entry.configOptions.providerName} Provider initialized`, {
36
+ modelName: this.modelName,
37
+ providerName: this.providerName,
38
+ baseURL: redactUrlCredentials(this.config.baseURL),
39
+ });
40
+ }
41
+ getProviderName() {
42
+ return this.entry.providerName;
43
+ }
44
+ getDefaultModel() {
45
+ return getProviderModel(this.entry.modelEnvVar, this.entry.defaultModel);
46
+ }
47
+ getFallbackModelName() {
48
+ return this.entry.fallbackModelName;
49
+ }
50
+ getFallbackModels() {
51
+ return this.entry.fallbackModels;
52
+ }
53
+ formatProviderError(error) {
54
+ // classifyProviderError handles TimeoutError internally (always maps
55
+ // to NetworkError, ahead of any rule table) — no local pre-check
56
+ // needed or wanted here; see this task's design note.
57
+ return classifyProviderError(error, this.entry.errorRules, this.entry.providerName, this.modelName);
58
+ }
59
+ }
@@ -0,0 +1,24 @@
1
+ import type { OpenAICompatCatalogEntry } from "../types/index.js";
2
+ /**
3
+ * Config-driven catalog of the 7 zero-quirk OpenAI-compatible providers.
4
+ * Each entry fully replaces what used to be a hand-written
5
+ * OpenAIChatCompletionsProvider subclass — see ConfiguredOpenAICompatProvider
6
+ * for the class that reads these entries, and providerRegistry.ts for the
7
+ * registration loop that consumes this array.
8
+ *
9
+ * `errorRules` mirrors each provider's LIVE `formatProviderError` rule array
10
+ * (post plan-07/wave-2 migration), not the original hand-rolled ladder these
11
+ * providers had when plan 05 was first drafted: every provider below now
12
+ * keeps only its bespoke rule(s) — auth, plus Groq's model_decommissioned and
13
+ * xAI's insufficient_quota — before spreading the SAME exported
14
+ * `DEFAULT_ERROR_RULES` constant that the live subclasses spread (never an
15
+ * inlined copy, so this catalog cannot drift from that table independently).
16
+ * See plan-05/progress.md Ruling R4 for the full rationale.
17
+ *
18
+ * To add a new zero-quirk OpenAI-compatible provider: add one entry here.
19
+ * Do NOT add a provider here if it needs any hook override beyond the 3
20
+ * mandatory ones (getProviderName/getDefaultModel/formatProviderError) —
21
+ * write a dedicated subclass instead (see deepseek.ts, azureOpenai.ts, and
22
+ * Task 14's docs task for the deciding criteria).
23
+ */
24
+ export declare const OPENAI_COMPAT_CATALOG: readonly OpenAICompatCatalogEntry[];