mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-10-24 09:25:21 +08:00
feat(cloud): enforce signed workspace subscription resource limits
This commit is contained in:
@@ -685,7 +685,9 @@ class BotService:
|
||||
"""Create bot"""
|
||||
workspace_uuid = require_workspace_uuid(context)
|
||||
# Check limitation
|
||||
limitation = self.ap.instance_config.data.get('system', {}).get('limitation', {})
|
||||
from .workspace_limits import workspace_limits
|
||||
|
||||
limitation = await workspace_limits(self.ap, workspace_uuid)
|
||||
max_bots = limitation.get('max_bots', -1)
|
||||
if max_bots >= 0:
|
||||
existing_bots = await self.get_bots(context)
|
||||
|
||||
@@ -56,9 +56,9 @@ class KnowledgeService:
|
||||
require_workspace_uuid(context)
|
||||
# In new architecture, we delegate entirely to RAGManager which uses plugins.
|
||||
# Legacy internal KB creation is removed.
|
||||
limitation = (
|
||||
getattr(getattr(self.ap, 'instance_config', None), 'data', {}).get('system', {}).get('limitation', {})
|
||||
)
|
||||
from .workspace_limits import workspace_limits
|
||||
|
||||
limitation = await workspace_limits(self.ap, require_workspace_uuid(context))
|
||||
max_knowledge_bases = limitation.get('max_knowledge_bases', -1)
|
||||
if max_knowledge_bases >= 0:
|
||||
knowledge_bases = await self.ap.rag_mgr.get_all_knowledge_base_details(context)
|
||||
|
||||
@@ -212,7 +212,9 @@ class MCPService:
|
||||
# stdio MCP even though Box Runtime itself remains available.
|
||||
require_stdio_mcp_enabled(self.ap, server_data)
|
||||
|
||||
limitation = self.ap.instance_config.data.get('system', {}).get('limitation', {})
|
||||
from .workspace_limits import workspace_limits
|
||||
|
||||
limitation = await workspace_limits(self.ap, workspace_uuid)
|
||||
max_extensions = limitation.get('max_extensions', -1)
|
||||
if max_extensions >= 0:
|
||||
mcp_count_result = await self.ap.persistence_mgr.execute_async(
|
||||
|
||||
@@ -173,7 +173,9 @@ class PipelineService:
|
||||
if 'config' in pipeline_data:
|
||||
RunnerConfigResolver.validate_pipeline_config(pipeline_data['config'])
|
||||
# Check limitation
|
||||
limitation = self.ap.instance_config.data.get('system', {}).get('limitation', {})
|
||||
from .workspace_limits import workspace_limits
|
||||
|
||||
limitation = await workspace_limits(self.ap, workspace_uuid)
|
||||
max_pipelines = limitation.get('max_pipelines', -1)
|
||||
if max_pipelines >= 0:
|
||||
existing_pipelines = await self.get_pipelines(context)
|
||||
@@ -290,7 +292,9 @@ class PipelineService:
|
||||
"""Copy a pipeline with all its configurations"""
|
||||
workspace_uuid = require_workspace_uuid(context)
|
||||
# Check limitation
|
||||
limitation = self.ap.instance_config.data.get('system', {}).get('limitation', {})
|
||||
from .workspace_limits import workspace_limits
|
||||
|
||||
limitation = await workspace_limits(self.ap, workspace_uuid)
|
||||
max_pipelines = limitation.get('max_pipelines', -1)
|
||||
if max_pipelines >= 0:
|
||||
existing_pipelines = await self.get_pipelines(context)
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
"""Resolve resource limits at the Workspace service boundary."""
|
||||
|
||||
from ....cloud.entitlements import EntitlementUnavailableError
|
||||
|
||||
LIMIT_KEYS = {
|
||||
'max_bots': 'bots.max',
|
||||
'max_pipelines': 'pipelines.max',
|
||||
'max_extensions': 'plugins.max',
|
||||
'max_knowledge_bases': 'knowledge_bases.max',
|
||||
}
|
||||
|
||||
|
||||
async def workspace_limits(ap, workspace_uuid: str, *, minimum_revision: int = 0) -> dict[str, int]:
|
||||
if getattr(getattr(ap, 'deployment', None), 'mode', None) != 'cloud':
|
||||
return dict(ap.instance_config.data.get('system', {}).get('limitation', {}))
|
||||
resolver = getattr(ap, 'entitlement_resolver', None)
|
||||
if resolver is None:
|
||||
raise EntitlementUnavailableError('Workspace entitlement resolver is unavailable')
|
||||
snapshot = await resolver.resolve(workspace_uuid, minimum_revision=minimum_revision)
|
||||
return {config_key: snapshot.limit(limit_key) for config_key, limit_key in LIMIT_KEYS.items()}
|
||||
Reference in New Issue
Block a user