+
    UTjR                        R t ^ RIHt ^ RIt^ RIt^ RIt^ RItR.tR tR R lt	R R lt
R	 R
 ltR R ltR R ltR R ltR# )u  Google Drive logic for the shared jarvis-tools MCP service (Railway).

Same guarantees as the in-process Mac version, but creds come from ENV so it
runs headless on Railway and is reachable by every device:
  DRIVE_SA_JSON    the service-account key JSON (whole file, as one env var)
  DRIVE_FOLDER_ID  the "Jarvis Drive" folder id

A service account has no Drive of its own, so it only sees folders Ahmed shared
with it. Every op below is ALSO folder-jailed to DRIVE_FOLDER_ID as defence in
depth — nothing outside the shared folder is ever touched.

Note: only content ops are exposed remotely (list/read/write/delete). Local
file upload/download live in the Mac in-process tool — a remote server has no
access to a caller's local filesystem.
)annotationsNz%https://www.googleapis.com/auth/drivec                     ^ RI Hp  ^ RIHp \        P
                  ! \        P                  R,          4      pV P                  P                  V\        R7      pV! RRVRR7      # )	    )service_account)buildDRIVE_SA_JSON)scopesdrivev3F)credentialscache_discovery)google.oauth2r   googleapiclient.discoveryr   jsonloadsosenvironCredentialsfrom_service_account_info_SCOPES)r   r   infocredss       drive.py_servicer      sQ    -/::bjj12D''AAW B E$E5II    c                   V ^8  d   QhRR/#    returnstr )formats   "r   __annotate__r"   #   s     ) )C )r   c                 0    \         P                  R ,          # )DRIVE_FOLDER_ID)r   r   r    r   r   
_folder_idr%   #   s    ::'((r   c                    V ^8  d   QhRRRR/# )r   refr   r   zdict | Noner    )r!   s   "r   r"   r"   '   s     ' 's '{ 'r   c                   \        V4      P                  4       pV'       g   R# \        4       p V P                  4       P	                  VRR7      P                  4       pY#P	                  R4      ;'       g    . 9   d   V# R#   \         d     Mi ; iRT RT R2pT P                  4       P                  TRRR	7      P                  4       P	                  R
. 4      pT'       d
   T^ ,          # R# )uC   Find a file by id or name — ONLY inside the shared folder (jail).Nzid,name,mimeType,parents)fileIdfieldsparents'z)' in parents and trashed=false and name='r	   zfiles(id,name,mimeType))qspacesr*   files)r   stripr%   r/   getexecute	Exceptionlist)svcr'   fidfr-   r/   s   &&    r   _resolver8   '   s    
c(..
C
,CIIKOO9  ;;B79 	
EE),223q== 
C59#a@AIIKq#<  %giGR(8 
 58&$&s   AB 6B ?B BBc                   V ^8  d   QhRR/# r   r    )r!   s   "r   r"   r"   :   s     I IC Ir   c                    \        4       p R \        4        R2pV P                  4       P                  VRRRR7      P	                  4       P                  R. 4      pV'       g   R# . pV Fm  pVP                  R4      pV'       d   \        V4      R	,           R
2MRpVP                  RVR,           RV RVR,          R,           RVR,           R2	4       Ko  	  \        V4       R2RP                  V4      ,           # )r,   z' in parents and trashed=falser	   zmodifiedTime descz)files(id,name,mimeType,size,modifiedTime))r-   r.   orderByr*   r/   z(The shared Jarvis Drive folder is empty.sizei   KBu   —z- namez  (z, modifiedTime:N
   Nz) [id id]z file(s) in Jarvis Drive:

)
r   r%   r/   r4   r2   r1   intappendlenjoin)r5   r-   r/   linesr7   szs         r   
list_filesrJ   :   s    
*C
JL>78AIIK
G%8:  
 ')CC$ 
 9EUU6]%'Bb!Ur!F)Ct2a.?.D-E FdG9A' 	( 
 %j\45		%8HHHr   c                    V ^8  d   QhRRRR/# r   r'   r   r   r    )r!   s   "r   r"   r"   L   s     # #3 #3 #r   c                0   \        4       p\        W4      pV'       g   R # VP                  RR4      pVP                  R4      '       d8   VP	                  4       P                  VR,          RR7      P                  4       pM5VP	                  4       P                  VR,          R7      P                  4       p\        V\        4      '       d   VP                  RR	4      M
\        V4      pVR
,          \        V4      R8  d   RMR,           pVR,           RV 2# )/No such file in the shared Jarvis Drive folder.mimeType zapplication/vnd.google-appsrA   
text/plain)r)   rO   )r)   utf-8ignore:Ni@  Ni@  u    …[truncated]r>   z:
)r   r8   r1   
startswithr/   exportr2   	get_media
isinstancebytesdecoder   rF   )r'   r5   r7   mimedatabodysnips   &      r   	read_filer^   L   s    
*CA@55R D455yy{!!4<!HPPRyy{$$AdG$4<<>-7e-D-D4;;w)#d)D;s4y4/?+RHDi[D6""r   c               $    V ^8  d   QhRRRRRR/# )r   r>   r   contentr   r    )r!   s   "r   r"   r"   [   s!     ? ?S ?3 ?3 ?r   c                   ^ RI Hp \        V 4      P                  4       p V '       g   R# \	        4       p\
        P                  ! V 4      ^ ,          ;'       g    RpV! \        P                  ! \        V4      P                  R4      4      VRR7      p\        W04      pV'       d]   VP                  R4      V 8X  dG   VP                  4       P                  VR,          VR	7      P                  4        R
V  RVR,           R2# RV R\        4       ./pVP                  4       P!                  WuRR7      P                  4       pRV  RVR,           R2# )r   )MediaIoBaseUploadzwrite failed: need a file name.rQ   rR   F)mimetype	resumabler>   rA   )r)   
media_bodyzupdated z in Jarvis Drive (id z).r+   )r\   re   r*   zcreated )googleapiclient.httprb   r   r0   r   	mimetypes
guess_typeioBytesIOencoder8   r1   r/   updater2   r%   create)	r>   r`   rb   r5   rZ   mediaexistingmetaouts	   &&       r   
write_filerr   [   s   6t9??D0
*C%a(88LDbjjW)<)<W)EF&*e=E"HHLL(D0		(4.UCKKM$4Xd^4DBGGD)jl^4D
))+

$

F
N
N
PCdV0T2>>r   c                    V ^8  d   QhRRRR/# rL   r    )r!   s   "r   r"   r"   m   s     5 5S 5S 5r   c                    \        4       p\        W4      pV'       g   R # VP                  4       P                  VR,          RR/R7      P	                  4        RVR,           R2# )rN   rA   trashedT)r)   r\   zDeleted r>   z from Jarvis Drive.)r   r8   r/   rl   r2   )r'   r5   r7   s   &  r   delete_filerv   m   sX    
*CA@IIKagY,=>FFHai[ 344r   )__doc__
__future__r   ri   r   rg   r   r   r   r%   r8   rJ   r^   rr   rv   r    r   r   <module>ry      sH    # 	   	2
3J)'&I$#?$5r   