@ax-llm/ax 10.0.44 → 10.0.46
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/index.cjs +11 -34
- package/index.cjs.map +1 -1
- package/index.js +11 -34
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1057,8 +1057,6 @@ import { GoogleAuth } from "google-auth-library";
|
|
|
1057
1057
|
var GoogleVertexAuth = class {
|
|
1058
1058
|
auth;
|
|
1059
1059
|
client;
|
|
1060
|
-
currentToken;
|
|
1061
|
-
tokenExpiry;
|
|
1062
1060
|
constructor(config = {}) {
|
|
1063
1061
|
this.auth = new GoogleAuth({
|
|
1064
1062
|
scopes: ["https://www.googleapis.com/auth/cloud-platform"],
|
|
@@ -1072,38 +1070,12 @@ var GoogleVertexAuth = class {
|
|
|
1072
1070
|
return this.client;
|
|
1073
1071
|
}
|
|
1074
1072
|
async getAccessToken() {
|
|
1075
|
-
if (this.currentToken && this.tokenExpiry && Date.now() < this.tokenExpiry) {
|
|
1076
|
-
return this.currentToken;
|
|
1077
|
-
}
|
|
1078
1073
|
const client = await this.getAuthenticatedClient();
|
|
1079
|
-
const
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
const fiveMinutes = 5 * 60 * 1e3;
|
|
1083
|
-
this.tokenExpiry = expiry - fiveMinutes;
|
|
1084
|
-
return this.currentToken;
|
|
1085
|
-
}
|
|
1086
|
-
/**
|
|
1087
|
-
* Get the expiry date from the token response.
|
|
1088
|
-
*/
|
|
1089
|
-
getExpiry(tokenResponse) {
|
|
1090
|
-
const oneHour = 3600 * 1e3;
|
|
1091
|
-
let expiry = Date.now() + oneHour;
|
|
1092
|
-
let responseExpiry = tokenResponse.res?.data?.expiry_date;
|
|
1093
|
-
if (responseExpiry) {
|
|
1094
|
-
if (typeof responseExpiry === "number") {
|
|
1095
|
-
expiry = responseExpiry;
|
|
1096
|
-
} else if (responseExpiry instanceof Date) {
|
|
1097
|
-
expiry = responseExpiry.getTime();
|
|
1098
|
-
} else if (typeof responseExpiry === "string") {
|
|
1099
|
-
expiry = new Date(responseExpiry).getTime();
|
|
1100
|
-
} else {
|
|
1101
|
-
console.warn("Unknown expiry type", responseExpiry);
|
|
1102
|
-
}
|
|
1103
|
-
} else {
|
|
1104
|
-
console.warn("No expiry date found in response", tokenResponse.res?.data);
|
|
1074
|
+
const response = await client.getAccessToken();
|
|
1075
|
+
if (!response.token) {
|
|
1076
|
+
throw new Error("Failed to obtain access token");
|
|
1105
1077
|
}
|
|
1106
|
-
return
|
|
1078
|
+
return response.token;
|
|
1107
1079
|
}
|
|
1108
1080
|
};
|
|
1109
1081
|
|
|
@@ -6084,11 +6056,16 @@ var AxBalancer = class _AxBalancer {
|
|
|
6084
6056
|
default:
|
|
6085
6057
|
throw e;
|
|
6086
6058
|
}
|
|
6087
|
-
console.warn(
|
|
6059
|
+
console.warn(
|
|
6060
|
+
`AxBalancer: Service ${this.currentService.getName()} failed`,
|
|
6061
|
+
e
|
|
6062
|
+
);
|
|
6088
6063
|
if (!this.getNextService()) {
|
|
6089
6064
|
throw e;
|
|
6090
6065
|
}
|
|
6091
|
-
console.warn(
|
|
6066
|
+
console.warn(
|
|
6067
|
+
`AxBalancer: Switching to service ${this.currentService.getName()}`
|
|
6068
|
+
);
|
|
6092
6069
|
}
|
|
6093
6070
|
}
|
|
6094
6071
|
}
|