Harden composite group product surfaces

This commit is contained in:
Heatherm Huang
2026-07-23 09:19:25 +08:00
parent ebc1028771
commit c8d1e2e16f
20 changed files with 570 additions and 45 deletions
+13 -5
View File
@@ -799,7 +799,7 @@ function togglePlatform(platform: GroupPlatform) {
}
function getGroupsForPlatform(platform: GroupPlatform): AdminGroup[] {
return allGroups.value.filter(g => g.platform === platform)
return allGroups.value.filter(g => g.platform === platform || g.platform === 'composite')
}
// ── Group helpers ──
@@ -1117,6 +1117,7 @@ function formToAPI(): { group_ids: number[], model_pricing: ChannelModelPricing[
})
}
}
const uniqueGroupIds = Array.from(new Set(group_ids))
// Collect web_search_emulation (only anthropic platform supports it)
// Always write the key so that disabling in the UI correctly sets platform to false,
@@ -1160,7 +1161,7 @@ function formToAPI(): { group_ids: number[], model_pricing: ChannelModelPricing[
delete featuresConfig.bedrock_cc_compat
}
return { group_ids, model_pricing, model_mapping, features_config: featuresConfig }
return { group_ids: uniqueGroupIds, model_pricing, model_mapping, features_config: featuresConfig }
}
function apiToForm(channel: Channel): PlatformSection[] {
@@ -1174,7 +1175,11 @@ function apiToForm(channel: Channel): PlatformSection[] {
const activePlatforms = new Set<GroupPlatform>()
for (const gid of channel.group_ids || []) {
const p = groupPlatformMap.get(gid)
if (p) activePlatforms.add(p)
if (p === 'composite') {
platformOrder.forEach(platform => activePlatforms.add(platform))
} else if (p) {
activePlatforms.add(p)
}
}
for (const p of channel.model_pricing || []) {
if (p.platform) activePlatforms.add(p.platform as GroupPlatform)
@@ -1188,7 +1193,10 @@ function apiToForm(channel: Channel): PlatformSection[] {
for (const platform of platformOrder) {
if (!activePlatforms.has(platform)) continue
const groupIds = (channel.group_ids || []).filter(gid => groupPlatformMap.get(gid) === platform)
const groupIds = (channel.group_ids || []).filter(gid => {
const groupPlatform = groupPlatformMap.get(gid)
return groupPlatform === platform || groupPlatform === 'composite'
})
const mapping = (channel.model_mapping || {})[platform] || {}
const pricing = (channel.model_pricing || [])
.filter(p => (p.platform || 'anthropic') === platform)
@@ -1364,7 +1372,7 @@ function distributeRulesToPlatforms(apiRules: AccountStatsPricingRule[]) {
const platforms = new Set<GroupPlatform>()
for (const gid of apiRule.group_ids || []) {
const p = groupPlatformMap.get(gid)
if (p) platforms.add(p)
if (p && p !== 'composite') platforms.add(p)
}
// If pricing has a platform field, use that as fallback
if (platforms.size === 0 && apiRule.pricing?.length > 0) {