feat(platform): close AI expense value loop
Add tenant-safe value, telemetry, connector, commercial, and production-readiness foundations.
This commit is contained in:
@@ -13,6 +13,7 @@ from app.core.agent_enums import (
|
||||
)
|
||||
from app.core.logging import get_logger
|
||||
from app.models.agent_asset import AgentAsset
|
||||
from app.services.agent_asset_access import platform_asset_statement
|
||||
from app.services.agent_asset_rule_library import AgentAssetRuleLibraryManager
|
||||
from app.services.agent_asset_spreadsheet import (
|
||||
RISK_RULES_LIBRARY,
|
||||
@@ -325,7 +326,14 @@ class AgentFoundationRiskRuleMixin:
|
||||
|
||||
def sync_platform_risk_rules_from_library(self) -> int:
|
||||
|
||||
existing_codes = set(self.db.scalars(select(AgentAsset.code)).all())
|
||||
existing_codes = set(
|
||||
self.db.scalars(
|
||||
select(AgentAsset.code).where(
|
||||
AgentAsset.scope == "platform",
|
||||
AgentAsset.tenant_id == "platform",
|
||||
)
|
||||
).all()
|
||||
)
|
||||
|
||||
before_count = len(existing_codes)
|
||||
|
||||
@@ -339,7 +347,14 @@ class AgentFoundationRiskRuleMixin:
|
||||
|
||||
self.db.flush()
|
||||
|
||||
after_codes = set(self.db.scalars(select(AgentAsset.code)).all())
|
||||
after_codes = set(
|
||||
self.db.scalars(
|
||||
select(AgentAsset.code).where(
|
||||
AgentAsset.scope == "platform",
|
||||
AgentAsset.tenant_id == "platform",
|
||||
)
|
||||
).all()
|
||||
)
|
||||
|
||||
synced = max(len(after_codes) - before_count, 0)
|
||||
|
||||
@@ -361,7 +376,9 @@ class AgentFoundationRiskRuleMixin:
|
||||
|
||||
def _hide_stale_demo_risk_rules(self, manifest_codes: set[str]) -> None:
|
||||
assets = self.db.scalars(
|
||||
select(AgentAsset).where(AgentAsset.asset_type == AgentAssetType.RULE.value)
|
||||
platform_asset_statement().where(
|
||||
AgentAsset.asset_type == AgentAssetType.RULE.value
|
||||
)
|
||||
).all()
|
||||
for asset in assets:
|
||||
config = asset.config_json if isinstance(asset.config_json, dict) else {}
|
||||
@@ -400,7 +417,9 @@ class AgentFoundationRiskRuleMixin:
|
||||
|
||||
scenario_json = self._platform_risk_scenario_json(manifest)
|
||||
|
||||
asset = self.db.scalar(select(AgentAsset).where(AgentAsset.code == rule_code))
|
||||
asset = self.db.scalar(
|
||||
platform_asset_statement().where(AgentAsset.code == rule_code)
|
||||
)
|
||||
|
||||
if asset is None and rule_code not in existing_codes:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user