
    Lit              
       
   d dl mZ d dlZd dlZej                  j                  d       	 d dlmZ d Zedk(  r e        yy# e$ r; d dl	Z	d dl
Z
ej                  j                  d      ZdZddd	d
ZddedededefdZY Pw xY w)    )FastMCPNz!/mnt/e/genesis-system/mcp-servers)
call_modelOPENROUTER_API_KEYz-https://openrouter.ai/api/v1/chat/completionszdeepseek/deepseek-r1zmoonshot/kimi-k1.5-previewzminimax/minimax-01)deepseek-r1kimiminimax	model_keypromptsystem_promptreturnc                 n   t         syt        j                  | |       }dt          dd}|d|dd|dgd}	 t        j                  t
        ||	      }|j                          |j                         }|d
   d   d   d   S # t        $ r)}t        d|  d|        dt        |       cY d }~S d }~ww xY w)Nz$Error: OPENROUTER_API_KEY not found.zBearer zapplication/json)AuthorizationzContent-Typesystem)rolecontentuser)modelmessages)headersjsonchoicesr   messager   zError calling z: zError: )r   MODELSgetrequestspostOPENROUTER_URLraise_for_statusr   	Exceptionprintstr)	r	   r
   r   model_idr   dataresponseresultes	            3/mnt/e/genesis-system/scripts/swarm_orchestrator.pyr   r      s    !9::i3  ''9&:;.
 !m<F3
	&}}^W4PH%%']]_F)$Q'	29== 	&N9+Rs34SVH%%	&s   A	B 	B4B/)B4/B4c                     t        d       t        d       d} t        d|       }t        dd      5 }|j                  |       d d d        t        d       t        d       d	}t        d
|      }t        dd      5 }|j                  |       d d d        t        d       t        d       d}t        d|      }t        dd      5 }|j                  |       d d d        t        d       y # 1 sw Y   xY w# 1 sw Y   kxY w# 1 sw Y   -xY w)Nu)   --- 🚀 SWARM ARCHITECTURE INITIATED ---u%   
🧠 Agent DeepSeek R1 (Thinking)...a  
    Design a production-ready MVP for the 'Genesis Patent OS' (Powered by Sunaiva) in 1 hour.
    
    Core Components:
    1. 'patent_os_db' (Postgres): Schema for Immutable Audit Logs (Patent 4) and Risk Events (Patent 3).
    2. 'Sunaiva Shield Widget': A JavaScript widget for client websites that shows live validation status.
    3. API Integration: How to connect the existing FastAPI to Postgres.
    
    Constraints: 
    - Use SQLAlchemy for ORM.
    - Widget must be lightweight (vanilla JS).
    - API must be robust.
    r   z/docs/GENESIS PATENTS/SWARM_ARCHITECTURE_PLAN.mdwu    ✅ Architecture Plan Generated.u$   
💻 Agent Kimi (Coding Backend)...a  
    Based on the architecture plan (assume standard rigorous design):
    Write the `database.py` and `models.py` for `patent-os` using SQLAlchemy and Pydantic.
    
    Models needed:
    - AuditLog (id, timestamp, event_type, details, user_id, prev_hash, current_hash)
    - RiskAssessment (id, proposal_hash, risk_score, details)
    
    Output ONLY the python code for `models.py` and `database.py`.
    r   zmcp-servers/patent-os/models.pyu   ✅ Backend Models Generated.u*   
🎨 Agent MiniMax (Creative Frontend)...a  
    Create a beautiful, trustworthy 'Powered by Sunaiva' badge widget.
    
    Features:
    - HTML/CSS/JS in one file (or separate).
    - Shows 'Shield Active' status with a green pulsing dot.
    - Hover effect: '9-Layer Protection Active'.
    - Link to 'https://sunaiva.com/compliance'.
    
    Style: Professional, clean, banking-grade trust.
    Output the HTML/CSS/JS code.
    r   z.mcp-servers/patent-os/widget/shield_badge.htmlu   ✅ Frontend Widget Generated.)r    r   openwrite)	objectiveplanfbackend_taskbackend_codefrontend_taskfrontend_codes          r'   execute_swarm_planr3   7   s   	
56 

23I mY/D	?	E 		
,- 

12	L fl3L	/	5 		
)* 

78M y-8M	>	D 		
*+M " & s#   C+;C7D+C47D D__main__) )fastmcpr   ossyspathappendopenrouter_swarmr   ImportErrorr   loggingenvironr   r   r   r   r!   r3   __name__     r'   <module>rB      s     	 
 3 4,&+Z9,v z O  *& (<=DN .,'F&c &3 &s &C &!*&s   A =BB