+
    i~C                       R t ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIHtH	t	H
t
HtHt ^ RIHt ^ RIHt ]]]]3,          t]]]P(                  ]]]	]].]3,          3,          ]
],          ]P*                  ]P,                  3,          t]	].]3,          tR R ltR R	 lt]P6                  ! R
R7       ! R R]P8                  4      4       tRR R llt ! R R]P>                  4      t  ! R R]P>                  4      t! ! R R]P>                  4      t"]P6                  ! R
R7       ! R R]4      4       t# ! R R]#4      t$ ! R R]4      t%]P6                  ! R
R7       ! R R]4      4       t&R# )aY  Classes that define arguments for populating ArgumentParser.

The argparse module's ArgumentParser.add_argument() takes several parameters and
is quite customizable. However this can lead to bugs where arguments do not
behave as expected.

For better ease-of-use and better testability, define a set of classes for the
types of flags used by LLM Magics.

Sample usage:

  str_flag = SingleValueFlagDef(name="title", required=True)
  enum_flag = EnumFlagDef(name="colors", required=True, enum_type=ColorsEnum)

  str_flag.add_argument_to_parser(my_parser)
  enum_flag.add_argument_to_parser(my_parser)
)annotationsN)AnyCallableSequenceTupleUnion)llmfn_inputs_source)llmfn_outputsc                    V ^8  d   QhRRRR/# )   x	type[Any]returnstr )formats   "x/Users/igloo/.openclaw/workspace/scratch/fb_ad_env/lib/python3.14/site-packages/google/generativeai/notebook/flag_def.py__annotate__r   ?   s      i C     c                T     V P                   #   \         d    \        T 4      u # i ; iN)__name__AttributeErrorr   r   s   &r   _get_type_namer   ?   s)    zz 1vs    ''c                    V ^8  d   QhRRRR/# )r   namer   r   r   )r   s   "r   r   r   F   s      c c r   c                ^    V '       g   \        R4      hV ^ ,          R8X  d   \        R4      hV # )z.Validation for long and short names for flags.zCannot be empty-zCannot start with dash)
ValueError)r   s   &r   _validate_flag_namer    F   s-    *++Aw#~122Kr   T)frozenc                      ] tR t^Ot$ RtR]R&   RtR]R&   RtR]R	&   ]t	R
]R&   Rt
R]R&   RtR]R&   RtR]R&   RtR]R&   ]P                  R R l4       t]P                  R R l4       tR R ltR R ltR tRtR# )FlagDefa  Abstract base class for flag definitions.

Attributes:
  name: Long name, e.g. "colors" will define the flag "--colors".
  required: Whether the flag must be provided on the command line.
  short_name: Optional short name.
  parse_type: The type that ArgumentParser should parse the command line
    argument to.
  dest_type: The type that the parsed value is converted to. This is used when
    we want ArgumentParser to parse as one type, then convert to a different
    type. E.g. for enums we parse as "str" then convert to the desired enum
    type in order to provide cleaner help messages.
  parse_to_dest_type_fn: If provided, this function will be used to convert
    the value from `parse_type` to `dest_type`. This can be used for
    validation as well.
  choices: If provided, limit the set of acceptable values to these choices.
  help_msg: If provided, adds help message when -h is used in the command
    line.
r   r   FboolrequiredN
str | None
short_nameztype[_PARSETYPES]
parse_typeztype[_DESTTYPES] | None	dest_typez_PARSEFN | Noneparse_to_dest_type_fnzlist[_PARSETYPES] | Nonechoiceshelp_msgc                    V ^8  d   QhRRRR/# r   parserargparse.ArgumentParserr   Noner   )r   s   "r   r   FlagDef.__annotate__r   s      -D  r   c                    R# )zAdds this flag as an argument to `parser`.

Child classes should implement this as a call to parser.add_argument()
with the appropriate parameters.

Args:
  parser: The parser to which this argument will be added.
Nr   )selfr/   s   &&r   add_argument_to_parserFlagDef.add_argument_to_parserq       r   c                   V ^8  d   QhRR/# r   r   r1   r   )r   s   "r   r   r2   }   s     = =4 =r   c                    R# )z.For child classes to do additional validation.Nr   r4   s   &r   _do_additional_validation!FlagDef._do_additional_validation|   r7   r   c                   V ^8  d   QhRR/# )r   r   ztype[_DESTTYPES]r   )r   s   "r   r   r2      s     M M 0 Mr   c                N    V P                   f   V P                  # V P                   # )z!Returns the final converted type.)r)   r(   r;   s   &r   _get_dest_typeFlagDef._get_dest_type   s    "&.."8tLdnnLr   c                   V ^8  d   QhRR/# )r   r   _PARSEFNr   )r   s   "r   r   r2      s      	r   c                    V P                   e   V P                   # V P                  4       pWP                  8X  d   R # V# )z;Returns a function to convert from parse_type to dest_type.c                    V # r   r   r   s   &r   <lambda>4FlagDef._get_parse_to_dest_type_fn.<locals>.<lambda>   s    Qr   )r*   r@   r(   )r4   r)   s   & r   _get_parse_to_dest_type_fn"FlagDef._get_parse_to_dest_type_fn   s@     %%1---'')	'r   c                	    \        V P                  4       V P                  e   \        V P                  4       V P                  4        R # r   )r    r   r'   r<   r;   s   &r   __post_init__FlagDef.__post_init__   s0    DII&??&0&&(r   r   )r   
__module____qualname____firstlineno____doc____annotations__r%   r'   r   r(   r)   r*   r+   r,   abcabstractmethodr5   r<   r@   rH   rK   __static_attributes__r   r   r   r#   r#   O   s    ( IHd!J
!$'J!')-I&--1?1(,G%,Hj  	= =M)r   r#   c          
     ,    V ^8  d   QhRRRRRRRRR	R/# )
r   	namespaceargparse.Namespacedestr   has_defaultr$   default_valuer   r   r   )r   s   "r   r   r      s:     5 5!5
5 5 	5
 
5r   c                X    \        W4      '       g   R# V'       g   R# \        W4      V8g  # )a  Returns true if `namespace.dest` is set to a non-default value.

Args:
  namespace: The Namespace that is populated by ArgumentParser.
  dest: The attribute in the Namespace to be populated.
  has_default: "None" is a valid default value so we use an additional
    `has_default` boolean to indicate that `default_value` is present.
  default_value: The default value to use when `has_default` is True.

Returns:
  Whether namespace.dest is set to something other than the default value.
FT)hasattrgetattr)rV   rX   rY   rZ   s   &&&&r   _has_non_default_valuer^      s*    $ 9## 9#}44r   c                  B   a  ] tR t^tRtR V 3R lltRR R lltRtV ;t# )_SingleValueStoreActionzyCustom Action for storing a value in an argparse.Namespace.

This action checks that the flag is specified at-most once.
c                    V ^8  d   QhRRRR/# r   r)   r   r*   rC   r   )r   s   "r   r   $_SingleValueStoreAction.__annotate__         
< 
< 	
<
  (
<r   c                	B   < \         SV `  ! W3/ VB  W0n        W@n        R # r   super__init__
_dest_type_parse_to_dest_type_fnr4   option_stringsrX   r)   r*   kwargs	__class__s   &&&&&,r   rh    _SingleValueStoreAction.__init__   "     	88#&;#r   c               (    V ^8  d   QhRRRRRRRR/# 	r   r/   r0   rV   rW   valueszstr | Sequence[Any] | Noneoption_stringr&   r   )r   s   "r   r   rc      s2     "7 "7'"7 &"7 +	"7
 ""7r   c                	   \        V\        4      '       g   \        V\        4      '       d   Q h\        VV P                  \        V R 4      \        V R 4      R7      '       d'   \        P                  ! V RP                  V4      4      h V P                  V^ ,          4      p\        YPP                  4      '       gA   \        RP                  \        T P                  4      \        \        T4      4      4      4      h\!        Y P                  T4       R#   \         dG   p\        P                  ! T RP                  T^ ,          \        \        T4      4      T4      4      hRp?ii ; i)defaultrY   rZ   Cannot set {} more than once!Error with value "{}", got {}: {}N+Converted to wrong type, expected {} got {})
isinstancer   bytesr^   rX   r\   r]   argparseArgumentErrorr   rj   	Exceptionr   typeri   RuntimeErrorsetattr)r4   r/   rV   rs   rt   converted_valuees   &&&&&  r   __call__ _SingleValueStoreAction.__call__   s)    fc**:fe3L3LLL!IIi0!$	2	
 
 ((/M/T/TUb/cdd	"99&)DO /??;;=DD"4??3"4#89  		99o6  	((3::6!9nUYZ[U\F]_`a 	s   	D E%AE  E%ri   rj   r   	r   rM   rN   rO   rP   rh   r   rT   __classcell__rn   s   @r   r`   r`      s    

< 
<"7 "7r   r`   c                  B   a  ] tR t^tRtR V 3R lltRR R lltRtV ;t# )_MultiValuesAppendActionzzCustom Action for appending values in an argparse.Namespace.

This action checks that the flag is specified at-most once.
c                    V ^8  d   QhRRRR/# rb   r   )r   s   "r   r   %_MultiValuesAppendAction.__annotate__   rd   r   c                	B   < \         SV `  ! W3/ VB  W0n        W@n        R # r   rf   rk   s   &&&&&,r   rh   !_MultiValuesAppendAction.__init__   rp   r   c               (    V ^8  d   QhRRRRRRRR/# rr   r   )r   s   "r   r   r      s2     #/ #/'#/ &#/ +	#/
 "#/r   c                	   \        V\        4      '       g   \        V\        4      '       d   Q h\        W P                  4      pV'       d'   \
        P                  ! V R P                  V4      4      hV F  p V P                  V4      p\        YpP                  4      '       g/   \        RP                  T P                  \        T4      4      4      hYu9   d'   \
        P                  ! T RP                  T4      4      hTP                  T4       K  	  R#   \         dG   p\
        P                  ! T RP                  T^ ,          \        \        T4      4      T4      4      hRp?ii ; i)rx   ry   Nrz   zDuplicate values "{}")r{   r   r|   r]   rX   r}   r~   r   rj   r   r   r   ri   r   append)	r4   r/   rV   rs   rt   
curr_valuevaluer   r   s	   &&&&&    r   r   !_MultiValuesAppendAction.__call__   s-    fc**:fe3L3LLLY		2
((/M/T/TUb/cddE"&"="=e"D o??"AHHo)> 
 ,,,T3J3Q3QRW3XYYo.)   ,,7>>q	>$q'#:A s   8DE& AE!!E&r   r   r   r   s   @r   r   r      s    

< 
<#/ #/r   r   c                  <   a  ] tR tRtRtV 3R ltRR R lltRtV ;t# )_BooleanValueStoreActioni%  zCustom Action for setting a boolean value in argparse.Namespace.

The boolean flag expects the default to be False and will set the value to
True.
This action checks that the flag is specified at-most once.
c                	*   < \         SV `  ! W3/ VB  R # r   )rg   rh   )r4   rl   rX   rm   rn   s   &&&,r   rh   !_BooleanValueStoreAction.__init__-  s     	88r   c               (    V ^8  d   QhRRRRRRRR/# rr   r   )r   s   "r   r   %_BooleanValueStoreAction.__annotate__5  s2     , ,', &, +	,
 ",r   c                	    \        VV P                  R RR7      '       d'   \        P                  ! V RP	                  V4      4      h\        W P                  R 4       R# )TFrw   rx   N)r^   rX   r}   r~   r   r   )r4   r/   rV   rs   rt   s   &&&&&r   r   !_BooleanValueStoreAction.__call__5  sQ     "II	
 
 ((/M/T/TUb/cdd	99d+r   r   r   r   r   s   @r   r   r   %  s    9, ,r   r   c                      ] tR tRt$ Rt ! R R]P                  4      t]P                  t	R]
R&   R R ltR	 R
 ltR R ltRtR# )SingleValueFlagDefiG  aO  Definition for a flag that takes a single value.

Sample usage:
  # This defines a flag that can be specified on the command line as:
  #   --count=10
  flag = SingleValueFlagDef(name="count", parse_type=int, required=True)
  flag.add_argument_to_parser(argument_parser)

Attributes:
  default_value: Default value for optional flags.
c                      ] tR tRtRtRtRtR# ) SingleValueFlagDef._DefaultValueiU  zSpecial value to represent "no value provided".

"None" can be used as a default value, so in order to differentiate between
"None" and "no value provided", create a special value for "no value
provided".
Nr   )r   rM   rN   rO   rP   NOT_SETrT   r   r   r   _DefaultValuer   U  s    	 r   r   z!_DESTTYPES | _DefaultValue | NonerZ   c                   V ^8  d   QhRR/# )r   r   r$   r   )r   s   "r   r   SingleValueFlagDef.__annotate__a  s     N ND Nr   c                P    V P                   \        P                  P                  8g  # )z2Returns whether `default_value` has been provided.)rZ   r   r   r   r;   s   &r   _has_default_value%SingleValueFlagDef._has_default_valuea  s     !!%7%E%E%M%MMMr   c                    V ^8  d   QhRRRR/# r.   r   )r   s   "r   r   r   e  s     
 
-D 
 
r   c                	   R V P                   ,           .pV P                  e   VRV P                  ,           .,          p/ pV P                  4       '       d   V P                  VR&   V P                  e   V P                  VR&   V P
                  e   V P
                  VR&   VP                  ! VR\        RV P                  RV P                  4       R	V P                  4       R
V P                  R^/VB  R# )--Nr   rv   r+   helpactionr   r)   r*   r%   nargs)r   r'   r   rZ   r+   r,   add_argumentr`   r(   r@   rH   r%   r4   r/   argsrm   s   &&  r   r5   )SingleValueFlagDef.add_argument_to_parsere  s    tyy !??&S4??*++D""$$ $ 2 2F9<<# $F9==$!]]F6N		
*		
 		
 ))+			

 #'"A"A"C		
 ]]		
 		
 		
r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r   }  s     
c 
c4 
cr   c                	j   V P                   '       d#   V P                  4       '       d   \        R 4      hM!V P                  4       '       g   \        R4      hV P                  4       '       dH   V P                  e8   \	        V P                  V P                  4       4      '       g   \        R4      hR# R# R# )z(Required flags cannot have default valuez(Optional flags must have a default valueNz>Default value must be of the same type as the destination type)r%   r   r   rZ   r{   r@   r;   s   &r   r<   ,SingleValueFlagDef._do_additional_validation}  s    ===&&(( !KLL ) **,, !KLL""$$););)Gd00$2E2E2GHH !abb I *H$r   r   N)r   rM   rN   rO   rP   enumEnumr   r   rZ   rQ   r   r5   r<   rT   r   r   r   r   r   G  sB    
		  8E7L7LM4LN
0
c 
cr   r   c                  2   a  ] tR tRtRtR V 3R lltRtV ;t# )EnumFlagDefi  a8  Definition for a flag that takes a value from an Enum.

Sample usage:
  # This defines a flag that can be specified on the command line as:
  #   --color=red
  flag = SingleValueFlagDef(name="color", enum_type=ColorsEnum,
                            required=True)
  flag.add_argument_to_parser(argument_parser)
c                   V ^8  d   QhRR/# )r   	enum_typeztype[enum.Enum]r   )r   s   "r   r   EnumFlagDef.__annotate__  s     * * *r   c               	  < \        V\        P                  4      '       g   \        R 4      hRV9   d   \	        R4      h\
        VR&   RV9   d   \	        R4      hWR&   RV9   d   VR,           F  p V! V4       K  	  MV Uu. uF  qDP                  NK  	  upVR&   \        SV `$  ! V/ VB  R#   \         d    \	        RP                  T4      4      Rhi ; iu upi )z "enum_type" must be of type Enumr(   z@Cannot set "parse_type" for EnumFlagDef; set "enum_type" insteadr)   z?Cannot set "dest_type" for EnumFlagDef; set "enum_type" insteadr+   z Invalid value in "choices": "{}"N)

issubclassr   r   	TypeErrorr   r   r   r   rg   rh   )r4   r   r   rm   r   rn   s   &$*, r   rh   EnumFlagDef.__init__  s    )TYY//>?? 6!_``"|& ^__'{I&&]aL ' 3< <)Q) <F9$)&) " ]$%G%N%Nq%QRX\\] !=s   2B/C/'Cr   )r   rM   rN   rO   rP   rh   rT   r   r   s   @r   r   r     s    * *r   r   c                  2    ] tR tRtRtR R ltR R ltRtR# )	MultiValuesFlagDefi  a  Definition for a flag that takes multiple values.

Sample usage:
  # This defines a flag that can be specified on the command line as:
  #   --colors=red green blue
  flag = MultiValuesFlagDef(name="colors", parse_type=str, required=True)
  flag.add_argument_to_parser(argument_parser)
c                    V ^8  d   QhRRRR/# r.   r   )r   s   "r   r   MultiValuesFlagDef.__annotate__  s     
 
-D 
 
r   c                	   R V P                   ,           .pV P                  e   VRV P                  ,           .,          p/ pV P                  e   V P                  VR&   V P                  e   V P                  VR&   VP                  ! VR\
        RV P                  RV P                  4       RV P                  4       R	V P                  R
. RR/VB  R# )r   Nr   r+   r   r   r   r)   r*   r%   rv   r   +)
r   r'   r+   r,   r   r   r(   r@   rH   r%   r   s   &&  r   r5   )MultiValuesFlagDef.add_argument_to_parser  s    tyy !??&S4??*++D<<# $F9==$!]]F6N
	
+
	
 
	
 ))+	
	

 #'"A"A"C
	
 ]]
	
 
	
 
	
 
	
r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r     s      4 r   c                	    R # r   r   r;   s   &r   r<   ,MultiValuesFlagDef._do_additional_validation  s    r   r   N)r   rM   rN   rO   rP   r5   r<   rT   r   r   r   r   r     s    
. r   r   c                  2    ] tR tRtRtR R ltR R ltRtR# )	BooleanFlagDefi  zDefinition for a Boolean flag.

A boolean flag is always optional with a default value of False. The flag does
not take any values. Specifying the flag on the commandline will set it to
True.
c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   BooleanFlagDef.__annotate__  s     I I4 Ir   c                	    V P                   e   \        R4      hV P                  e   \        R4      hV P                  e   \        R4      hR # )Nz*dest_type cannot be set for BooleanFlagDefz6parse_to_dest_type_fn cannot be set for BooleanFlagDefz(choices cannot be set for BooleanFlagDef)r)   r   r*   r+   r;   s   &r   r<   (BooleanFlagDef._do_additional_validation  sK    >>%IJJ%%1UVV<<#GHH $r   c                    V ^8  d   QhRRRR/# r.   r   )r   s   "r   r   r     s     
 
-D 
 
r   c                	   R V P                   ,           .pV P                  e   VRV P                  ,           .,          p/ pV P                  e   V P                  VR&   VP                  ! VR\        R\
        RRRRR	^ /VB  R# )
r   Nr   r   r   r   r%   Frv   r   )r   r'   r,   r   r   r$   r   s   &&  r   r5   %BooleanFlagDef.add_argument_to_parser  s    tyy !??&S4??*++D==$!]]F6N	
+	
 	
 		

 	
 	
 	
r   r   N)r   rM   rN   rO   rP   r<   r5   rT   r   r   r   r   r     s    I
 
r   r   )FN)'rP   
__future__r   rR   r}   dataclassesr   typingr   r   r   r   r    google.generativeai.notebook.libr   r	   r   intfloat_PARSETYPESr   LLMFnInputsSourceLLMFnOutputsSink
_DESTTYPESrC   r   r    	dataclassABCr#   r^   Actionr`   r   r   r   r   r   r   r   r   r   <module>r      su  " # 
    8 8 @ : CeO$ II	#xc
C(
()SM))""$
 [M:-. d#F)cgg F) $F)R5:47hoo 47n5/x 5/p,x ,D d#?c ?c $?cD"*$ "*J# #L d#!
W !
 $!
r   