Coverage for app / services / network / graph.py: 100%

25 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-10-31 11:21 +0000

1"""The node-and-edge shape both network views answer with.""" 

2 

3from __future__ import annotations 

4 

5from dataclasses import dataclass, field 

6from typing import Any 

7 

8 

9@dataclass 

10class NetworkNode: 

11 #: ``<kind>:<resource id>`` — unique across kinds, stable across reads. 

12 id: str 

13 #: agent, repository, knowledge, memory, conversation or memory_entry. 

14 kind: str 

15 label: str 

16 #: The resource the node stands for, so the UI can link to it. None for a 

17 #: node that is not a resource of its own (an agent's memory store). 

18 ref_id: str | None = None 

19 #: Kind-specific figures: counts, source type, flags, timestamps. 

20 meta: dict[str, Any] = field(default_factory=dict) 

21 

22 

23@dataclass 

24class NetworkEdge: 

25 source: str 

26 target: str 

27 #: grant (agent → repository), member (repository → source), memory 

28 #: (agent → its memory), conversation (agent → conversation) or entry 

29 #: (conversation → memory entry). 

30 kind: str 

31 

32 

33@dataclass 

34class Network: 

35 nodes: list[NetworkNode] = field(default_factory=list) 

36 edges: list[NetworkEdge] = field(default_factory=list) 

37 summary: dict[str, Any] = field(default_factory=dict) 

38 truncated: bool = False 

39 

40 

41def node_id(kind: str, ref: object) -> str: 

42 return f"{kind}:{ref}" 

43 

44 

45def appearance(row: Any) -> dict[str, Any]: 

46 """How a resource node is drawn: its own icon and accent, and its flags.""" 

47 return { 

48 "icon": getattr(row, "icon", None), 

49 "accent": getattr(row, "accent", None), 

50 "is_ai_generated": bool(getattr(row, "is_ai_generated", False)), 

51 "is_system": getattr(row, "is_system", False) is True, 

52 }