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