
    j                     |    S r SSKrSSKJr  SSKJr  SSKJr  SSKJr  S r	S r
S	 rS
 rS rS rS rS rS rS rg)z0Declarative hooks for `gcloud dialogflow agent`.    N)storage_util)log)
properties)filesc                     [         R                  R                  R                  R	                  5       nSR                  X5      $ )Nzprojects/{}/agent/sessions/{})r   VALUEScoreproject	GetOrFailformat)sessionr
   s     8lib/googlecloudsdk/command_lib/dialogflow/agent/hooks.pyAddSessionPrefixr      s3    ""**446'	(	/	/	AA    c                     UR                   R                  nUR                  S5      (       a  UR                  UR                  l        U$ UR                  S5      (       a  UR                  UR                  l        U$ )N
query_textquery_audio_file)*googleCloudDialogflowV2DetectIntentRequest
queryInputIsSpecifiedlanguagetextlanguageCodeaudioConfig)unused_instance_refargsrequestquery_inputs       r   SetQueryLanguager       sh    BBMM+	l##$(MMK! 
. *+++/==K(	.r   c                 B    [         R                  R                  S5        g )NzSuccessfully trained agent.)r   statusPrint)unused_responseunused_argss     r   LogTrainSuccessr%   )   s    **01r   c                 @    U R                  [        R                  5      $ N)
startswithr   GSUTIL_BUCKET_PREFIX)paths    r   IsBucketUrir+   -   s    	::	;;r   c                 z    UR                   n[        U5      (       a  [        R                  (       a	  SU0Ul        U$ )NagentUri)destinationr+   r   ValidateBucketUrl)googleCloudDialogflowV2ExportAgentRequest)r   r   r   dests       r   SetAgentUrir2   1   s2    			$<999CT8JG5	.r   c                 `   UR                   n[        U5      (       d  U R                  n[        S U 5       5      n[        R
                  " UR                  R                  5      n[        R                  " X%SS9  US:w  a.  [        R                  R                  SR                  U5      5        U $ )Nc              3   H   #    U  H  oR                   S :X  d  M  Uv   M     g7f)agentContentN)key).0props     r   	<genexpr>"SaveAgentToFile.<locals>.<genexpr><   s     N%$88~3M%s   "	"T)binary-zWrote agent to [{}].)r.   r+   additionalPropertiesnextbase64	b64decodevaluestring_valuer   WriteToFileOrStdoutr!   r"   r   )responser   r1   propsagent_contentagent_content_bins         r   SaveAgentToFilerH   8   s    			$	T		))EN%NNM(()<)<)I)IJDDAs{	jj-44T:;	/r   c                 (    UR                   (       a  gg)Nrestoreimport)replace_all)r   r   s     r   ChooseImportOrRestoreMethodrM   D   s    		r   c                 f    U R                  S5      (       a  SU 0$ S[        R                  " U 5      0$ )Nzgs://r-   r5   )r(   r   ReadBinaryFileContents)sources    r   _GetAgentRequestBodyrQ   J   s4    wE88@AAr   c                 n    [        UR                  5      nUR                  (       a  X2l        U$ X2l        U$ r'   )rQ   rP   rL   *googleCloudDialogflowV2RestoreAgentRequest)googleCloudDialogflowV2ImportAgentRequest)r   r   r   bodys       r   ModifyImportOrRestoreRequestrV   Q   s3    	dkk	*$	9=6 
. 9=5	.r   c                 H   UR                   nUR                  (       d  US:w  a/  [        R                  R	                  SR                  U5      5        O[        R                  R	                  S5        UR                  (       a  [        R                  R	                  S5        U $ )Nr<   z&Successfully imported agent from [{}].zSuccessfully imported agent.z Replaced all existing resources.)rP   async_r   r!   r"   r   rL   )rD   r   r*   s      r   LogImportSuccessrY   \   sk    	$	s{	jj?FFtLM	jj56	jj9:	/r   )__doc__r?   googlecloudsdk.api_lib.storager   googlecloudsdk.corer   r   googlecloudsdk.core.utilr   r   r   r%   r+   r2   rH   rM   rQ   rV   rY    r   r   <module>r_      sO     7  7 # * *B
2<	B	r   