File size: 2,412 Bytes
3b7f713
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
72
73
74
75
76
77
78
79
80
81
82
83
"""
GSD Integration — Jak GSD współpracuje z resztą aplikacji jako główny tryb

Ten plik zawiera funkcje do podłączania GSD Orchestratora do istniejących endpointów.
"""

from __future__ import annotations
import logging
from typing import Optional, Dict, Any

from .gsd_orchestrator import GrantforgeGSDOrchestrator
from .gsd_state import create_gsd_state

logger = logging.getLogger("gsd.integration")


def start_gsd_for_project(
    project_id: str,
    user_id: str,
    tenant_id: str,
    profile: Optional[Dict[str, Any]] = None,
    program_type: str = "",
) -> Dict[str, Any]:
    """
    Uruchamia GSD jako główny tryb dla nowo utworzonego projektu.

    Zwraca informacje o pierwszej fazie + ewentualne pytanie zatwierdzające.
    """
    logger.info(f"[GSD Integration] Start GSD dla projektu {project_id}")

    state = create_gsd_state(
        project_id=project_id,
        user_id=user_id,
        tenant_id=tenant_id,
        profile=profile or {},
    )

    # Dodajemy kontekst programu
    if program_type:
        state.gsd_blackboard["program_type"] = program_type

    orchestrator = GrantforgeGSDOrchestrator(state=state)

    # Uruchamiamy pierwszą fazę (Clarification) — to jest wejście do głównego trybu GSD
    orchestrator.run_phase("clarification")

    response = {
        "gsd_mode": True,
        "gsd_phase": state.gsd_phase,
        "project_id": project_id,
        "requires_user_confirmation": bool(state.pending_hitl),
    }

    if state.pending_hitl:
        response["hitl_question"] = {
            "id": state.pending_hitl.id,
            "title": state.pending_hitl.title,
            "question": state.pending_hitl.question,
            "options": state.pending_hitl.options,
            "risk_level": state.pending_hitl.risk_level,
        }
        logger.info(f"[GSD] Zwrócono pierwsze polskie pytanie zatwierdzające dla projektu {project_id}")

    return response


def resolve_gsd_hitl(
    project_id: str,
    hitl_id: str,
    decision: str,
    comment: str = "",
) -> Dict[str, Any]:
    """
    Rozwiązuje pytanie zatwierdzające i kontynuuje proces GSD.
    """
    # W pełnej wersji tutaj wczytujemy stan GSD z bazy / cache
    # Na razie zwracamy placeholder
    return {
        "status": "resolved",
        "message": "Pytanie zatwierdzające zapisane. Kontynuujemy proces GSD.",
        "next_phase": "matching",
    }