@gullabs/google 0.8.1 → 0.8.3

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/index.cjs CHANGED
@@ -70,6 +70,34 @@ function isGeminiCapacityError(err) {
70
70
  }
71
71
  return CAPACITY_PATTERNS.some((pattern) => pattern.test(message));
72
72
  }
73
+ var GOOGLE_TRANSPORT_ERROR_PATTERN = /fetch failed|connection error|econnreset|econnrefused|etimedout|eai_again|epipe|socket hang up/i;
74
+ function matchesGoogleTransportSignature(err) {
75
+ if (!(err instanceof Error)) return false;
76
+ if (GOOGLE_TRANSPORT_ERROR_PATTERN.test(err.message)) return true;
77
+ const code = err.code;
78
+ return typeof code === "string" && GOOGLE_TRANSPORT_ERROR_PATTERN.test(code);
79
+ }
80
+ function isGoogleTransportError(rawErr) {
81
+ if (matchesGoogleTransportSignature(rawErr)) return true;
82
+ if (rawErr instanceof Error) {
83
+ const cause = rawErr.cause;
84
+ if (matchesGoogleTransportSignature(cause)) return true;
85
+ }
86
+ return false;
87
+ }
88
+ function classifyGoogleError(rawErr, extra) {
89
+ const base = core.classifyError(rawErr);
90
+ const reclassifyAsTransport = base.kind === "unknown" && isGoogleTransportError(rawErr);
91
+ return new core.LlmError(base.message, {
92
+ kind: reclassifyAsTransport ? "server" : base.kind,
93
+ retryable: reclassifyAsTransport ? true : base.retryable,
94
+ ...base.httpStatus !== void 0 ? { httpStatus: base.httpStatus } : {},
95
+ ...base.retryAfterMs !== void 0 ? { retryAfterMs: base.retryAfterMs } : {},
96
+ provider: "google",
97
+ cause: base.cause ?? rawErr,
98
+ ...extra?.servedServiceTier !== void 0 ? { servedServiceTier: extra.servedServiceTier } : {}
99
+ });
100
+ }
73
101
 
74
102
  // src/adapter.ts
75
103
  var ALLOWED_GOOGLE_PROVIDER_OPTION_KEYS = /* @__PURE__ */ new Set([
@@ -579,16 +607,10 @@ function geminiAdapter(opts) {
579
607
  try {
580
608
  response = await dispatch();
581
609
  } catch (rawErr) {
582
- const classified = core.classifyError(rawErr);
583
- const typed = new core.LlmError(classified.message, {
584
- kind: classified.kind,
585
- retryable: classified.retryable,
586
- ...classified.httpStatus !== void 0 ? { httpStatus: classified.httpStatus } : {},
587
- ...classified.retryAfterMs !== void 0 ? { retryAfterMs: classified.retryAfterMs } : {},
588
- provider: "google",
589
- cause: classified.cause ?? rawErr,
590
- ...servedServiceTier !== void 0 ? { servedServiceTier } : {}
591
- });
610
+ const typed = classifyGoogleError(
611
+ rawErr,
612
+ servedServiceTier !== void 0 ? { servedServiceTier } : void 0
613
+ );
592
614
  if (config.serviceTier === "flex" && googleProviderConfig.flexFallback !== false && isGeminiCapacityError(typed)) {
593
615
  config.serviceTier = "standard";
594
616
  servedServiceTier = "standard";
@@ -601,16 +623,7 @@ function geminiAdapter(opts) {
601
623
  try {
602
624
  response = await dispatch();
603
625
  } catch (fallbackRawErr) {
604
- const fallbackClassified = core.classifyError(fallbackRawErr);
605
- throw new core.LlmError(fallbackClassified.message, {
606
- kind: fallbackClassified.kind,
607
- retryable: fallbackClassified.retryable,
608
- ...fallbackClassified.httpStatus !== void 0 ? { httpStatus: fallbackClassified.httpStatus } : {},
609
- ...fallbackClassified.retryAfterMs !== void 0 ? { retryAfterMs: fallbackClassified.retryAfterMs } : {},
610
- provider: "google",
611
- cause: fallbackClassified.cause ?? fallbackRawErr,
612
- servedServiceTier: "standard"
613
- });
626
+ throw classifyGoogleError(fallbackRawErr, { servedServiceTier: "standard" });
614
627
  }
615
628
  } else {
616
629
  throw typed;
@@ -730,16 +743,7 @@ function geminiAdapter(opts) {
730
743
  raw: response
731
744
  };
732
745
  } catch (rawErr) {
733
- if (rawErr instanceof core.LlmError) throw rawErr;
734
- const classified = core.classifyError(rawErr);
735
- throw new core.LlmError(classified.message, {
736
- kind: classified.kind,
737
- retryable: classified.retryable,
738
- ...classified.httpStatus !== void 0 ? { httpStatus: classified.httpStatus } : {},
739
- ...classified.retryAfterMs !== void 0 ? { retryAfterMs: classified.retryAfterMs } : {},
740
- provider: "google",
741
- cause: classified.cause ?? rawErr
742
- });
746
+ throw classifyGoogleError(rawErr);
743
747
  }
744
748
  }
745
749
  };