File size: 2,259 Bytes
8904f7b
 
 
 
 
 
 
 
 
 
 
 
 
994a04c
 
 
 
 
 
 
8904f7b
 
 
 
 
 
 
994a04c
 
 
 
 
 
 
8904f7b
 
 
 
 
 
994a04c
 
 
 
 
 
8904f7b
 
 
 
 
 
 
 
994a04c
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""Repository Knowledge Graph data models.

Defines Pydantic structures for the Knowledge Graph nodes, edges, and summaries.
"""

from typing import Dict, List, Any
from pydantic import BaseModel, Field


class KnowledgeGraphNode(BaseModel):
    """A single semantic entity/node in the Repository Knowledge Graph."""

    id: str = Field(..., description="Unique stable node identifier.")
    type: str = Field(
        ...,
        description="Entity type: repository | directory | file | symbol | component | health | compliance.",
    )
    properties: Dict[str, Any] = Field(
        default_factory=dict, description="Metadata properties of the entity."
    )


class KnowledgeGraphEdge(BaseModel):
    """A directed semantic relationship between two nodes in the graph."""

    source: str = Field(..., description="Source stable node ID.")
    target: str = Field(..., description="Target stable node ID.")
    type: str = Field(
        ...,
        description="Relationship type: CONTAINS | DECLARES | IMPORTS | CALLS | HAS_HEALTH | HAS_COMPLIANCE.",
    )
    properties: Dict[str, Any] = Field(
        default_factory=dict, description="Metadata properties of the relationship."
    )


class KnowledgeGraph(BaseModel):
    """The fully composed read-only view of the Repository Knowledge Graph."""

    repository_name: str = Field(..., description="owner/repo identifier.")
    nodes: List[KnowledgeGraphNode] = Field(
        default_factory=list, description="All semantic nodes."
    )
    edges: List[KnowledgeGraphEdge] = Field(
        default_factory=list, description="All semantic edges."
    )


class KnowledgeGraphSummary(BaseModel):
    """Lightweight summary version of the Repository Knowledge Graph for stats and dashboards."""

    repository_name: str = Field(..., description="owner/repo identifier.")
    nodes_count: int = Field(..., description="Total count of nodes in the graph.")
    edges_count: int = Field(..., description="Total count of edges in the graph.")
    node_types_breakdown: Dict[str, int] = Field(
        ..., description="Breakdown of nodes count by entity type."
    )
    edge_types_breakdown: Dict[str, int] = Field(
        ..., description="Breakdown of edges count by relationship type."
    )