@ax-llm/ax 10.0.45 → 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 +4 -30
- package/index.cjs.map +1 -1
- package/index.js +4 -30
- 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,36 +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 tenMinutes = 10 * 60 * 1e3;
|
|
1083
|
-
this.tokenExpiry = expiry - tenMinutes;
|
|
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
|
-
}
|
|
1074
|
+
const response = await client.getAccessToken();
|
|
1075
|
+
if (!response.token) {
|
|
1076
|
+
throw new Error("Failed to obtain access token");
|
|
1103
1077
|
}
|
|
1104
|
-
return
|
|
1078
|
+
return response.token;
|
|
1105
1079
|
}
|
|
1106
1080
|
};
|
|
1107
1081
|
|