@acarmisc/backstage-plugin-litellm-backend 0.17.2 → 0.17.4
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 +68 -26
- package/dist/index.cjs.js.map +3 -3
- package/dist/plugin.d.ts +6 -0
- package/dist/plugin.js +13 -6
- package/dist/routes/bridge.js +36 -4
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -7983,20 +7983,20 @@ __export(index_exports, {
|
|
|
7983
7983
|
getOrProvisionUser: () => getOrProvisionUser,
|
|
7984
7984
|
getOrProvisionUserFromClaims: () => getOrProvisionUserFromClaims,
|
|
7985
7985
|
isTeamManagementEnabled: () => isTeamManagementEnabled,
|
|
7986
|
-
litellmAuditReadPermission: () =>
|
|
7987
|
-
litellmKeyCreatePermission: () =>
|
|
7988
|
-
litellmKeyManagePermission: () =>
|
|
7989
|
-
litellmKeyResetSpendPermission: () =>
|
|
7990
|
-
litellmKeyRevokePermission: () =>
|
|
7991
|
-
litellmKeyUnblockPermission: () =>
|
|
7992
|
-
litellmPermissions: () =>
|
|
7986
|
+
litellmAuditReadPermission: () => import_backstage_plugin_litellm_common11.litellmAuditReadPermission,
|
|
7987
|
+
litellmKeyCreatePermission: () => import_backstage_plugin_litellm_common11.litellmKeyCreatePermission,
|
|
7988
|
+
litellmKeyManagePermission: () => import_backstage_plugin_litellm_common11.litellmKeyManagePermission,
|
|
7989
|
+
litellmKeyResetSpendPermission: () => import_backstage_plugin_litellm_common11.litellmKeyResetSpendPermission,
|
|
7990
|
+
litellmKeyRevokePermission: () => import_backstage_plugin_litellm_common11.litellmKeyRevokePermission,
|
|
7991
|
+
litellmKeyUnblockPermission: () => import_backstage_plugin_litellm_common11.litellmKeyUnblockPermission,
|
|
7992
|
+
litellmPermissions: () => import_backstage_plugin_litellm_common11.litellmPermissions,
|
|
7993
7993
|
litellmPlugin: () => litellmPlugin,
|
|
7994
|
-
litellmTeamCreatePermission: () =>
|
|
7995
|
-
litellmTeamDeletePermission: () =>
|
|
7996
|
-
litellmTeamKnowledgebaseManagePermission: () =>
|
|
7997
|
-
litellmTeamManagePermission: () =>
|
|
7998
|
-
litellmTeamMcpManagePermission: () =>
|
|
7999
|
-
litellmTeamMembersManagePermission: () =>
|
|
7994
|
+
litellmTeamCreatePermission: () => import_backstage_plugin_litellm_common11.litellmTeamCreatePermission,
|
|
7995
|
+
litellmTeamDeletePermission: () => import_backstage_plugin_litellm_common11.litellmTeamDeletePermission,
|
|
7996
|
+
litellmTeamKnowledgebaseManagePermission: () => import_backstage_plugin_litellm_common11.litellmTeamKnowledgebaseManagePermission,
|
|
7997
|
+
litellmTeamManagePermission: () => import_backstage_plugin_litellm_common11.litellmTeamManagePermission,
|
|
7998
|
+
litellmTeamMcpManagePermission: () => import_backstage_plugin_litellm_common11.litellmTeamMcpManagePermission,
|
|
7999
|
+
litellmTeamMembersManagePermission: () => import_backstage_plugin_litellm_common11.litellmTeamMembersManagePermission,
|
|
8000
8000
|
newDefaultVerifier: () => newDefaultVerifier,
|
|
8001
8001
|
normalizeRequestTags: () => normalizeRequestTags,
|
|
8002
8002
|
provisionUser: () => provisionUser,
|
|
@@ -8979,7 +8979,7 @@ async function resolveUserRole(userEntityRef, roleConfigs, catalogClient, auth,
|
|
|
8979
8979
|
}
|
|
8980
8980
|
|
|
8981
8981
|
// src/router.ts
|
|
8982
|
-
var
|
|
8982
|
+
var import_backstage_plugin_litellm_common9 = require("@acarmisc/backstage-plugin-litellm-common");
|
|
8983
8983
|
|
|
8984
8984
|
// src/teamAdmin.ts
|
|
8985
8985
|
var import_plugin_permission_common = __toESM(require_index_cjs2());
|
|
@@ -12850,6 +12850,7 @@ async function bridgeGenerateKey(client, claims, provisioningEnabled, provisioni
|
|
|
12850
12850
|
|
|
12851
12851
|
// src/routes/bridge.ts
|
|
12852
12852
|
var import_backstage_plugin_litellm_common7 = require("@acarmisc/backstage-plugin-litellm-common");
|
|
12853
|
+
var import_backstage_plugin_litellm_common8 = require("@acarmisc/backstage-plugin-litellm-common");
|
|
12853
12854
|
function registerBridgeRoutes(router, ctx, bridgeOpts) {
|
|
12854
12855
|
const {
|
|
12855
12856
|
client,
|
|
@@ -12863,7 +12864,7 @@ function registerBridgeRoutes(router, ctx, bridgeOpts) {
|
|
|
12863
12864
|
keyValidationConfig
|
|
12864
12865
|
} = ctx;
|
|
12865
12866
|
const { config } = bridgeOpts;
|
|
12866
|
-
const generateKeyInputSchema = (0,
|
|
12867
|
+
const generateKeyInputSchema = (0, import_backstage_plugin_litellm_common8.createGenerateKeyInputSchema)(ctx.keyValidationConfig);
|
|
12867
12868
|
const bridgeCfg = readBridgeConfig(config);
|
|
12868
12869
|
const bridgeIdentity = {
|
|
12869
12870
|
userIdDomain,
|
|
@@ -12970,11 +12971,50 @@ function registerBridgeRoutes(router, ctx, bridgeOpts) {
|
|
|
12970
12971
|
handleBridgeError(error, res);
|
|
12971
12972
|
}
|
|
12972
12973
|
});
|
|
12974
|
+
router.get("/bridge/user/info", async (req, res) => {
|
|
12975
|
+
try {
|
|
12976
|
+
const claims = await requireClaims(req);
|
|
12977
|
+
const user = await getOrProvisionUserFromClaims(
|
|
12978
|
+
client,
|
|
12979
|
+
claims,
|
|
12980
|
+
provisioningEnabled,
|
|
12981
|
+
provisioningDefaults,
|
|
12982
|
+
logger,
|
|
12983
|
+
bridgeIdentity
|
|
12984
|
+
);
|
|
12985
|
+
res.json({ user_id: user.user_id, teams: user.teams ?? [] });
|
|
12986
|
+
} catch (error) {
|
|
12987
|
+
handleBridgeError(error, res);
|
|
12988
|
+
}
|
|
12989
|
+
});
|
|
12973
12990
|
router.get("/bridge/models", async (req, res) => {
|
|
12974
12991
|
try {
|
|
12975
|
-
await requireClaims(req);
|
|
12992
|
+
const claims = await requireClaims(req);
|
|
12993
|
+
const teamId = typeof req.query.team_id === "string" ? req.query.team_id : "";
|
|
12976
12994
|
const models = await client.listModels();
|
|
12977
|
-
|
|
12995
|
+
if (!teamId) {
|
|
12996
|
+
res.json(models);
|
|
12997
|
+
return;
|
|
12998
|
+
}
|
|
12999
|
+
const user = await getOrProvisionUserFromClaims(
|
|
13000
|
+
client,
|
|
13001
|
+
claims,
|
|
13002
|
+
provisioningEnabled,
|
|
13003
|
+
provisioningDefaults,
|
|
13004
|
+
logger,
|
|
13005
|
+
bridgeIdentity
|
|
13006
|
+
);
|
|
13007
|
+
if (!(user.teams ?? []).includes(teamId)) {
|
|
13008
|
+
res.status(403).json({ error: "Access denied: team is not one of your teams", team_id: teamId });
|
|
13009
|
+
return;
|
|
13010
|
+
}
|
|
13011
|
+
const team = await client.getTeamInfo(teamId);
|
|
13012
|
+
const allowed = team.models;
|
|
13013
|
+
if (!allowed || allowed.length === 0 || allowed.includes(import_backstage_plugin_litellm_common7.ALL_PROXY_MODELS)) {
|
|
13014
|
+
res.json(models);
|
|
13015
|
+
return;
|
|
13016
|
+
}
|
|
13017
|
+
res.json(models.filter((m) => (0, import_backstage_plugin_litellm_common7.isModelAllowed)(m, allowed)));
|
|
12978
13018
|
} catch (error) {
|
|
12979
13019
|
handleBridgeError(error, res);
|
|
12980
13020
|
}
|
|
@@ -13006,7 +13046,7 @@ async function createRouter(options) {
|
|
|
13006
13046
|
const keyMaxBudget = config.getOptionalNumber("litellm.keys.maxBudget") ?? 100;
|
|
13007
13047
|
const keyMaxTpm = config.getOptionalNumber("litellm.keys.maxTpm") ?? 1e5;
|
|
13008
13048
|
const keyMaxRpm = config.getOptionalNumber("litellm.keys.maxRpm") ?? 1e3;
|
|
13009
|
-
const keyAllowedDurations = config.getOptionalStringArray("litellm.keys.allowedDurations") ??
|
|
13049
|
+
const keyAllowedDurations = config.getOptionalStringArray("litellm.keys.allowedDurations") ?? import_backstage_plugin_litellm_common9.DEFAULT_KEY_DURATIONS;
|
|
13010
13050
|
const keyValidationConfig = {
|
|
13011
13051
|
maxBudget: keyMaxBudget,
|
|
13012
13052
|
maxTpm: keyMaxTpm,
|
|
@@ -13197,7 +13237,13 @@ async function createRouter(options) {
|
|
|
13197
13237
|
}
|
|
13198
13238
|
|
|
13199
13239
|
// src/plugin.ts
|
|
13200
|
-
var
|
|
13240
|
+
var import_backstage_plugin_litellm_common10 = require("@acarmisc/backstage-plugin-litellm-common");
|
|
13241
|
+
var BRIDGE_UNAUTHENTICATED_PATHS = [
|
|
13242
|
+
"/bridge/health",
|
|
13243
|
+
"/bridge/keys",
|
|
13244
|
+
"/bridge/models",
|
|
13245
|
+
"/bridge/user/info"
|
|
13246
|
+
];
|
|
13201
13247
|
var litellmPlugin = (0, import_backend_plugin_api.createBackendPlugin)({
|
|
13202
13248
|
pluginId: "litellm",
|
|
13203
13249
|
register(reg) {
|
|
@@ -13220,7 +13266,7 @@ var litellmPlugin = (0, import_backend_plugin_api.createBackendPlugin)({
|
|
|
13220
13266
|
permissions,
|
|
13221
13267
|
permissionsRegistry
|
|
13222
13268
|
}) {
|
|
13223
|
-
permissionsRegistry.addPermissions(
|
|
13269
|
+
permissionsRegistry.addPermissions(import_backstage_plugin_litellm_common10.litellmPermissions);
|
|
13224
13270
|
const router = await createRouter({
|
|
13225
13271
|
config,
|
|
13226
13272
|
logger,
|
|
@@ -13230,11 +13276,7 @@ var litellmPlugin = (0, import_backend_plugin_api.createBackendPlugin)({
|
|
|
13230
13276
|
});
|
|
13231
13277
|
httpRouter.use(router);
|
|
13232
13278
|
if (readBridgeConfig(config).enabled) {
|
|
13233
|
-
for (const path of
|
|
13234
|
-
"/bridge/health",
|
|
13235
|
-
"/bridge/keys",
|
|
13236
|
-
"/bridge/models"
|
|
13237
|
-
]) {
|
|
13279
|
+
for (const path of BRIDGE_UNAUTHENTICATED_PATHS) {
|
|
13238
13280
|
httpRouter.addAuthPolicy({ path, allow: "unauthenticated" });
|
|
13239
13281
|
}
|
|
13240
13282
|
}
|
|
@@ -13244,7 +13286,7 @@ var litellmPlugin = (0, import_backend_plugin_api.createBackendPlugin)({
|
|
|
13244
13286
|
});
|
|
13245
13287
|
|
|
13246
13288
|
// src/index.ts
|
|
13247
|
-
var
|
|
13289
|
+
var import_backstage_plugin_litellm_common11 = require("@acarmisc/backstage-plugin-litellm-common");
|
|
13248
13290
|
// Annotate the CommonJS export names for ESM import in node:
|
|
13249
13291
|
0 && (module.exports = {
|
|
13250
13292
|
KeycloakJWTVerifier,
|