File size: 1,549 Bytes
4fb906a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Code entity document — represents a class, function, or method extracted from source."""

from enum import StrEnum
from typing import Any

from beanie import PydanticObjectId
from pydantic import Field

from app.models.base import BaseDocument


class EntityType(StrEnum):
    """Type of code entity extracted by the Architecture Agent."""

    CLASS = "class"
    FUNCTION = "function"
    METHOD = "method"
    INTERFACE = "interface"
    MODULE = "module"
    ENDPOINT = "endpoint"
    DATABASE_TABLE = "database_table"


class CodeEntity(BaseDocument):
    """A structural element extracted from source code via AST parsing.



    Used to populate the Knowledge Graph and provide fine-grained

    retrieval context for agents.

    """

    project_id: PydanticObjectId
    file_id: PydanticObjectId
    entity_type: EntityType
    name: str
    qualified_name: str = Field(default="", description="Fully qualified name (e.g., module.Class.method)")
    start_line: int = 0
    end_line: int = 0
    parameters: list[str] = Field(default_factory=list)
    return_type: str = ""
    docstring: str = ""
    dependencies: list[str] = Field(default_factory=list, description="Names of entities this calls/imports")
    metadata: dict[str, Any] = Field(default_factory=dict)

    class Settings:
        name = "code_entities"
        use_state_management = True
        indexes = [
            "project_id",
            "file_id",
            [("project_id", 1), ("entity_type", 1)],
        ]