o
    `iZ                     @  s2   d Z ddlmZ ddlmZmZ dZdddZdS )z
Live Bedrock checks for call analysis (Nova via Converse).

list_foundation_models succeeding does not mean InvokeModel/Converse works.
Use probe_nova_converse before trusting the integration.
    )annotations)AnyDictu  In AWS Console: Amazon Bedrock → Model access — enable Amazon Nova 2 Lite (or your chosen model). Then IAM: allow bedrock:InvokeModel and bedrock:Converse on the inference profile ARN in this region (e.g. arn:aws:bedrock:REGION:ACCOUNT:inference-profile/us.amazon.nova-2-lite-v1:0). Nova 2 Lite requires an inference profile id (us./eu./apac. prefix), not amazon.nova-2-lite-v1:0 alone.regionstraccess_key_idsecret_access_keymodel_idreturnDict[str, Any]c              
   C  s~  d|| dddd}|r|sd|d< d|d< |S z,ddl }dd	lm} |jd
| ||d}|j|dddigdgdddd d|d< |W S  |y } zR|jdi }	|	dd}
|	dt|}|
|d< ||d< |pkd }|
dkr{d|v r{t	|d< n|
dkrd|  d |d< n|
dkrd |d< nd|d< |W  Y d}~S d}~w t
y } zt||d< d!|d< |W  Y d}~S d}~ww )"z3Return ok=True if a minimal Converse call succeeds.FN)okr	   r   
error_codemessagehintzAWS credentials not setr   zISet AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY in dashboard-backend/.envr   r   )ClientErrorzbedrock-runtime)region_nameaws_access_key_idaws_secret_access_keyusertextzReply with the single word: ok)rolecontent   )	maxTokenstemperature)modelIdmessagesinferenceConfigTr   ErrorCode Messager   ValidationExceptionznot allowedAccessDeniedExceptionzzIAM denied InvokeModel/Converse. Attach a policy that allows these actions on this model or inference-profile resource in .ThrottlingExceptionzGBedrock throttled the request; retry later or request a quota increase.zQUnexpected error during Bedrock probe; check network and boto3/botocore versions.)boto3botocore.exceptionsr   clientconverseresponsegetr   lowerHINT_OPERATION_NOT_ALLOWED	Exception)r   r   r   r	   outr&   r   r(   excerrcodemsglow r5   </home/aiteam/pcaa-dev/dashboard-backend/bedrock_preflight.pyprobe_nova_converse   sl   

r7   N)
r   r   r   r   r   r   r	   r   r
   r   )__doc__
__future__r   typingr   r   r-   r7   r5   r5   r5   r6   <module>   s    