Spaces:
Running
Running
| """ | |
| 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", | |
| } | |