File size: 2,228 Bytes
c29f1fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
62
63
64
65
66
67
68
69
70
71
"""Response schemas for the multi-domain analysis platform."""

from __future__ import annotations

from typing import Dict, List, Literal

from pydantic import BaseModel, Field


DomainType = Literal["dsa", "data_science", "ml_dl", "web", "general"]
Severity = Literal["low", "medium", "high"]


class AnalysisIssue(BaseModel):
    """One detected issue or risk in the code snippet."""

    title: str
    severity: Severity
    description: str
    line_hint: int | None = None


class StaticAnalysisSummary(BaseModel):
    """Language-agnostic static-analysis signals."""

    syntax_valid: bool
    syntax_error: str = ""
    cyclomatic_complexity: int = Field(..., ge=1)
    line_count: int = Field(..., ge=0)
    max_loop_depth: int = Field(..., ge=0)
    time_complexity: str = "Unknown"
    space_complexity: str = "Unknown"
    detected_imports: List[str] = Field(default_factory=list)
    code_smells: List[str] = Field(default_factory=list)


class DomainAnalysis(BaseModel):
    """Domain-specific analysis payload returned by an analyzer."""

    domain: DomainType
    domain_score: float = Field(..., ge=0.0, le=1.0)
    issues: List[AnalysisIssue] = Field(default_factory=list)
    suggestions: List[str] = Field(default_factory=list)
    highlights: Dict[str, float | str] = Field(default_factory=dict)


class ScoreBreakdown(BaseModel):
    """Reward inputs and final normalized score."""

    ml_score: float = Field(..., ge=0.0, le=1.0)
    domain_score: float = Field(..., ge=0.0, le=1.0)
    lint_score: float = Field(..., ge=0.0, le=1.0)
    complexity_penalty: float = Field(..., ge=0.0, le=1.0)
    reward: float = Field(..., ge=0.0, le=1.0)


class AnalyzeCodeResponse(BaseModel):
    """Top-level structured output for API and UI consumers."""

    detected_domain: DomainType
    domain_confidences: Dict[str, float]
    score_breakdown: ScoreBreakdown
    static_analysis: StaticAnalysisSummary
    domain_analysis: DomainAnalysis
    improvement_plan: List[str] = Field(default_factory=list)
    model_backend: str
    model_id: str
    summary: str
    context_window: str = ""
    analysis_time_ms: float = Field(..., ge=0.0)