@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 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,38 +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 tokenResponse = await client.getAccessToken();
1181
- this.currentToken = tokenResponse.token ?? void 0;
1182
- const expiry = this.getExpiry(tokenResponse);
1183
- const fiveMinutes = 5 * 60 * 1e3;
1184
- this.tokenExpiry = expiry - fiveMinutes;
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
- }
1204
- } else {
1205
- console.warn("No expiry date found in response", tokenResponse.res?.data);
1175
+ const response = await client.getAccessToken();
1176
+ if (!response.token) {
1177
+ throw new Error("Failed to obtain access token");
1206
1178
  }
1207
- return expiry;
1179
+ return response.token;
1208
1180
  }
1209
1181
  };
1210
1182
 
@@ -6185,11 +6157,16 @@ var AxBalancer = class _AxBalancer {
6185
6157
  default:
6186
6158
  throw e;
6187
6159
  }
6188
- console.warn(`Service ${this.currentService.getName()} failed`);
6160
+ console.warn(
6161
+ `AxBalancer: Service ${this.currentService.getName()} failed`,
6162
+ e
6163
+ );
6189
6164
  if (!this.getNextService()) {
6190
6165
  throw e;
6191
6166
  }
6192
- console.warn(`Switching to service ${this.currentService.getName()}`);
6167
+ console.warn(
6168
+ `AxBalancer: Switching to service ${this.currentService.getName()}`
6169
+ );
6193
6170
  }
6194
6171
  }
6195
6172
  }