@acarmisc/backstage-plugin-litellm-backend 0.11.0 → 0.11.1

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.js CHANGED
@@ -10827,6 +10827,25 @@ function validateTeamPatchInput(input, cfg) {
10827
10827
 
10828
10828
  // src/router.ts
10829
10829
  var teamCreateInFlight = /* @__PURE__ */ new Map();
10830
+ var TEAM_FETCH_RETRY_DELAYS_MS = [100, 300, 900];
10831
+ function isRetryableTeamFetchError(err) {
10832
+ if (err instanceof LiteLLMUpstreamError) {
10833
+ return err.status >= 500;
10834
+ }
10835
+ return true;
10836
+ }
10837
+ async function withTeamFetchRetry(fn, delaysMs = TEAM_FETCH_RETRY_DELAYS_MS) {
10838
+ for (let attempt = 0; ; attempt++) {
10839
+ try {
10840
+ return await fn();
10841
+ } catch (err) {
10842
+ if (attempt >= delaysMs.length || !isRetryableTeamFetchError(err)) {
10843
+ throw err;
10844
+ }
10845
+ await new Promise((resolve) => setTimeout(resolve, delaysMs[attempt]));
10846
+ }
10847
+ }
10848
+ }
10830
10849
  async function createRouter(options) {
10831
10850
  const { config, logger, auth, discovery, permissions } = options;
10832
10851
  const baseUrl = config.getString("litellm.baseUrl");
@@ -11260,8 +11279,8 @@ async function createRouter(options) {
11260
11279
  }
11261
11280
  const teams = await Promise.all(
11262
11281
  userInfo.teams.map(
11263
- (teamId) => client.getTeamInfo(teamId).catch((err) => {
11264
- logger.warn(`Failed to fetch team ${teamId}: ${err.message}`);
11282
+ (teamId) => withTeamFetchRetry(() => client.getTeamInfo(teamId)).catch((err) => {
11283
+ logger.warn(`Failed to fetch team ${teamId} after retries: ${err.message}`);
11265
11284
  return null;
11266
11285
  })
11267
11286
  )
@@ -11494,7 +11513,7 @@ async function createRouter(options) {
11494
11513
  }
11495
11514
  let existing;
11496
11515
  try {
11497
- existing = await client.getTeamInfo(teamId);
11516
+ existing = await withTeamFetchRetry(() => client.getTeamInfo(teamId));
11498
11517
  } catch (err) {
11499
11518
  if (err instanceof LiteLLMUpstreamError && err.status === 404) {
11500
11519
  res.status(404).json({ error: "Team not found" });
@@ -11608,7 +11627,7 @@ async function createRouter(options) {
11608
11627
  member: litellmUserId,
11609
11628
  owningGroup
11610
11629
  });
11611
- const updated = await client.getTeamInfo(teamId);
11630
+ const updated = await withTeamFetchRetry(() => client.getTeamInfo(teamId));
11612
11631
  res.json(updated);
11613
11632
  } catch (err) {
11614
11633
  sendTeamError(err, res);
@@ -11639,7 +11658,7 @@ async function createRouter(options) {
11639
11658
  member: litellmUserId,
11640
11659
  owningGroup
11641
11660
  });
11642
- const updated = await client.getTeamInfo(teamId);
11661
+ const updated = await withTeamFetchRetry(() => client.getTeamInfo(teamId));
11643
11662
  res.json(updated);
11644
11663
  } catch (err) {
11645
11664
  sendTeamError(err, res);