feat(shipping-notice): 增强订单抽取功能,添加进度事件和诊断运行管理,优化数据模型和访问控制
This commit is contained in:
1 parent
ce26d6d0c4
commit
c4095b08da
175 files changed
+13064
-1814
No files matched your search
@@ -14,6 +14,7 @@ from app import db
|
||||
from app.core.errors import ConflictError, NotFoundError, ValidationError
|
||||
from app.models import Agent, AgentRuntimeBinding
|
||||
from app.services.agent_registry.catalog import get_catalog_entry
|
||||
from app.services.agent_registry.resolver import resolve_effective_role
|
||||
|
||||
|
||||
def _capability_definition(owner: Agent, capability_code: str) -> dict[str, Any]:
|
||||
@@ -36,7 +37,13 @@ def _normalize_config(raw: Any) -> dict[str, Any]:
|
||||
raw = {}
|
||||
if not isinstance(raw, dict):
|
||||
raise ValidationError('config must be an object', code='AGENT.RUNTIME_BINDING_CONFIG_INVALID')
|
||||
unknown = set(raw) - {'timeout_seconds', 'max_attempts'}
|
||||
unknown = set(raw) - {
|
||||
'timeout_seconds', 'max_attempts', 'unit_concurrency',
|
||||
'unit_max_attempts', 'unit_retry_backoff_ms',
|
||||
'max_model_units', 'provider_max_concurrency',
|
||||
'circuit_failure_threshold', 'circuit_cooldown_seconds',
|
||||
'auto_create_enabled',
|
||||
}
|
||||
if unknown:
|
||||
raise ValidationError(
|
||||
'Unsupported runtime binding config keys',
|
||||
@@ -46,9 +53,17 @@ def _normalize_config(raw: Any) -> dict[str, Any]:
|
||||
try:
|
||||
timeout_seconds = int(raw.get('timeout_seconds', 900))
|
||||
max_attempts = int(raw.get('max_attempts', 3))
|
||||
unit_concurrency = int(raw.get('unit_concurrency', 2))
|
||||
unit_max_attempts = int(raw.get('unit_max_attempts', 2))
|
||||
unit_retry_backoff_ms = int(raw.get('unit_retry_backoff_ms', 500))
|
||||
max_model_units = int(raw.get('max_model_units', 20))
|
||||
provider_max_concurrency = int(raw.get('provider_max_concurrency', 4))
|
||||
circuit_failure_threshold = int(raw.get('circuit_failure_threshold', 5))
|
||||
circuit_cooldown_seconds = int(raw.get('circuit_cooldown_seconds', 60))
|
||||
auto_create_enabled = raw.get('auto_create_enabled', False)
|
||||
except (TypeError, ValueError) as exc:
|
||||
raise ValidationError(
|
||||
'Runtime binding timeout/max_attempts must be integers',
|
||||
'Runtime binding execution settings must be integers',
|
||||
code='AGENT.RUNTIME_BINDING_CONFIG_INVALID',
|
||||
) from exc
|
||||
if not 30 <= timeout_seconds <= 3600 or not 1 <= max_attempts <= 10:
|
||||
@@ -56,7 +71,34 @@ def _normalize_config(raw: Any) -> dict[str, Any]:
|
||||
'Runtime binding config is outside allowed limits',
|
||||
code='AGENT.RUNTIME_BINDING_CONFIG_INVALID',
|
||||
)
|
||||
return {'timeout_seconds': timeout_seconds, 'max_attempts': max_attempts}
|
||||
if not 2 <= unit_concurrency <= 4 or not 1 <= unit_max_attempts <= 3:
|
||||
raise ValidationError(
|
||||
'Runtime binding unit concurrency/attempts are outside allowed limits',
|
||||
code='AGENT.RUNTIME_BINDING_CONFIG_INVALID',
|
||||
)
|
||||
if not 100 <= unit_retry_backoff_ms <= 5000:
|
||||
raise ValidationError(
|
||||
'Runtime binding unit retry backoff is outside allowed limits',
|
||||
code='AGENT.RUNTIME_BINDING_CONFIG_INVALID',
|
||||
)
|
||||
if not 1 <= max_model_units <= 100 or not 1 <= provider_max_concurrency <= 20:
|
||||
raise ValidationError('Runtime binding provider budget is outside allowed limits', code='AGENT.RUNTIME_BINDING_CONFIG_INVALID')
|
||||
if not 2 <= circuit_failure_threshold <= 20 or not 10 <= circuit_cooldown_seconds <= 600:
|
||||
raise ValidationError('Runtime binding circuit settings are outside allowed limits', code='AGENT.RUNTIME_BINDING_CONFIG_INVALID')
|
||||
if not isinstance(auto_create_enabled, bool):
|
||||
raise ValidationError('Runtime binding auto-create gate must be boolean', code='AGENT.RUNTIME_BINDING_CONFIG_INVALID')
|
||||
return {
|
||||
'timeout_seconds': timeout_seconds,
|
||||
'max_attempts': max_attempts,
|
||||
'unit_concurrency': unit_concurrency,
|
||||
'unit_max_attempts': unit_max_attempts,
|
||||
'unit_retry_backoff_ms': unit_retry_backoff_ms,
|
||||
'max_model_units': max_model_units,
|
||||
'provider_max_concurrency': provider_max_concurrency,
|
||||
'circuit_failure_threshold': circuit_failure_threshold,
|
||||
'circuit_cooldown_seconds': circuit_cooldown_seconds,
|
||||
'auto_create_enabled': auto_create_enabled,
|
||||
}
|
||||
|
||||
|
||||
def _validate_provider(provider: Agent, definition: dict[str, Any]) -> None:
|
||||
@@ -64,6 +106,7 @@ def _validate_provider(provider: Agent, definition: dict[str, Any]) -> None:
|
||||
allowed_providers = set(definition.get('allowed_runtime_providers') or [])
|
||||
allowed_app_types = set(definition.get('allowed_dify_app_types') or [])
|
||||
allowed_exposure = set(definition.get('allowed_exposure_modes') or [])
|
||||
allowed_roles = set(definition.get('allowed_effective_roles') or [])
|
||||
if not provider.is_active:
|
||||
raise ConflictError('Runtime provider is disabled', code='AGENT.RUNTIME_PROVIDER_DISABLED')
|
||||
if allowed_providers and provider.runtime_provider not in allowed_providers:
|
||||
@@ -72,6 +115,8 @@ def _validate_provider(provider: Agent, definition: dict[str, Any]) -> None:
|
||||
raise ValidationError('Dify application type is invalid', code='AGENT.RUNTIME_PROVIDER_INVALID')
|
||||
if allowed_exposure and provider.exposure_mode not in allowed_exposure:
|
||||
raise ValidationError('Runtime provider exposure mode is invalid', code='AGENT.RUNTIME_PROVIDER_INVALID')
|
||||
if allowed_roles and resolve_effective_role(provider) not in allowed_roles:
|
||||
raise ValidationError('Runtime provider role is invalid', code='AGENT.RUNTIME_PROVIDER_INVALID')
|
||||
if provider.runtime_provider in {'dify', 'hybrid'} and (
|
||||
not str(provider.dify_app_id or '').strip()
|
||||
or not str(provider.dify_api_key or '').strip()
|
||||
|
||||
Reference in new issue
Block a user