@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.cjs
CHANGED
|
@@ -1158,8 +1158,6 @@ var import_google_auth_library = require("google-auth-library");
|
|
|
1158
1158
|
var GoogleVertexAuth = class {
|
|
1159
1159
|
auth;
|
|
1160
1160
|
client;
|
|
1161
|
-
currentToken;
|
|
1162
|
-
tokenExpiry;
|
|
1163
1161
|
constructor(config = {}) {
|
|
1164
1162
|
this.auth = new import_google_auth_library.GoogleAuth({
|
|
1165
1163
|
scopes: ["https://www.googleapis.com/auth/cloud-platform"],
|
|
@@ -1173,36 +1171,12 @@ var GoogleVertexAuth = class {
|
|
|
1173
1171
|
return this.client;
|
|
1174
1172
|
}
|
|
1175
1173
|
async getAccessToken() {
|
|
1176
|
-
if (this.currentToken && this.tokenExpiry && Date.now() < this.tokenExpiry) {
|
|
1177
|
-
return this.currentToken;
|
|
1178
|
-
}
|
|
1179
1174
|
const client = await this.getAuthenticatedClient();
|
|
1180
|
-
const
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
const tenMinutes = 10 * 60 * 1e3;
|
|
1184
|
-
this.tokenExpiry = expiry - tenMinutes;
|
|
1185
|
-
return this.currentToken;
|
|
1186
|
-
}
|
|
1187
|
-
/**
|
|
1188
|
-
* Get the expiry date from the token response.
|
|
1189
|
-
*/
|
|
1190
|
-
getExpiry(tokenResponse) {
|
|
1191
|
-
const oneHour = 3600 * 1e3;
|
|
1192
|
-
let expiry = Date.now() + oneHour;
|
|
1193
|
-
let responseExpiry = tokenResponse.res?.data?.expiry_date;
|
|
1194
|
-
if (responseExpiry) {
|
|
1195
|
-
if (typeof responseExpiry === "number") {
|
|
1196
|
-
expiry = responseExpiry;
|
|
1197
|
-
} else if (responseExpiry instanceof Date) {
|
|
1198
|
-
expiry = responseExpiry.getTime();
|
|
1199
|
-
} else if (typeof responseExpiry === "string") {
|
|
1200
|
-
expiry = new Date(responseExpiry).getTime();
|
|
1201
|
-
} else {
|
|
1202
|
-
console.warn("Unknown expiry type", responseExpiry);
|
|
1203
|
-
}
|
|
1175
|
+
const response = await client.getAccessToken();
|
|
1176
|
+
if (!response.token) {
|
|
1177
|
+
throw new Error("Failed to obtain access token");
|
|
1204
1178
|
}
|
|
1205
|
-
return
|
|
1179
|
+
return response.token;
|
|
1206
1180
|
}
|
|
1207
1181
|
};
|
|
1208
1182
|
|