fixes global
This commit is contained in:
1 parent
13dc4f39c8
commit
cad0f6aebe
64 files changed
+10379
-254
No files matched your search
@@ -0,0 +1,75 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from dataclasses import dataclass, asdict, field
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
|
||||
def _iso_now() -> str:
|
||||
return datetime.utcnow().isoformat()
|
||||
|
||||
|
||||
@dataclass
|
||||
class ValidationResult:
|
||||
"""
|
||||
Результат валидации контента/чанков.
|
||||
"""
|
||||
ok: bool
|
||||
reason: Optional[str] = None
|
||||
details: Dict[str, Any] = field(default_factory=dict)
|
||||
timestamp: str = field(default_factory=_iso_now)
|
||||
|
||||
def to_dict(self) -> Dict[str, Any]:
|
||||
return asdict(self)
|
||||
|
||||
def to_json(self) -> str:
|
||||
return json.dumps(self.to_dict(), ensure_ascii=False, sort_keys=True)
|
||||
|
||||
|
||||
@dataclass
|
||||
class ContentSignature:
|
||||
"""
|
||||
Информация о подписи контента/объекта.
|
||||
"""
|
||||
signature: Optional[str]
|
||||
public_key_hex: Optional[str]
|
||||
algorithm: str = "ed25519"
|
||||
|
||||
def to_dict(self) -> Dict[str, Any]:
|
||||
return asdict(self)
|
||||
|
||||
|
||||
@dataclass
|
||||
class TrustScore:
|
||||
"""
|
||||
Итоговый скор доверия (0.0 - 1.0)
|
||||
"""
|
||||
node_id: str
|
||||
score: float
|
||||
updated_at: str = field(default_factory=_iso_now)
|
||||
reason: Optional[str] = None
|
||||
|
||||
def to_dict(self) -> Dict[str, Any]:
|
||||
d = asdict(self)
|
||||
# Нормализация диапазона
|
||||
d["score"] = max(0.0, min(1.0, float(d["score"])))
|
||||
return d
|
||||
|
||||
|
||||
@dataclass
|
||||
class NodeTrust:
|
||||
"""
|
||||
Состояние доверия к ноде.
|
||||
"""
|
||||
node_id: str
|
||||
score: float = 0.5
|
||||
blacklisted: bool = False
|
||||
manual_override: bool = False
|
||||
note: Optional[str] = None
|
||||
updated_at: str = field(default_factory=_iso_now)
|
||||
|
||||
def to_dict(self) -> Dict[str, Any]:
|
||||
d = asdict(self)
|
||||
d["score"] = max(0.0, min(1.0, float(d["score"])))
|
||||
return d
|
||||
Reference in new issue
Block a user