ó
    Ñ]j]  ã                   ó8  • S SK r S SKrS SKrS SKJr  S SKJrJrJrJ	r	J
r
Jr  S SKJrJr  S SK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Jr  S S	KJr  S S
KJr  S SKJ r   S SK!J"r"J#r#J$r$  S SK%J&r&  S SK'J(r(  SSK)J*r*  S\4S jr+ " S S\"5      r, " S S\5      r-S\4S jr.S\4S jr/S\4S jr0S\4S jr1S\4S jr2S\4S jr3S\4S jr4S\4S jr5S \4S! jr6S\4S" jr7S\4S# jr8S\4S$ jr9S\4S% jr:S\4S& jr;\\\-S4   r<S \S'\-S(\4S) jr=S\4S* jr>S\4S+ jr?g),é    N)ÚStringIO)ÚListÚOptionalÚUnionÚTupleÚClassVarÚAny)ÚCallableÚ	Generator)ÚBuffer)ÚKeyPressEvent)Únamed_commands)ÚAutoSuggestFromHistoryÚ
Suggestion)ÚDocument)ÚHistory)ÚPromptSession)Ú	ProcessorÚTransformationÚTransformationInput)Úget_ipython)Úgenerate_tokensé   )Úpass_throughÚdocumentc                 ó4   • U R                   U R                     $ ©N)ÚlinesÚcursor_position_row)r   s    Úd/home/mande/repo/quber/.venv/lib/python3.13/site-packages/IPython/terminal/shortcuts/auto_suggest.pyÚ
_get_queryr!      s   € Ø�>‰>˜(×6Ñ6Ñ7Ð7ó    c                   óV   • \ rS rSr% SrSr\\   \S'   SS\	SS4S jjr
S	\S\4S
 jrSrg)ÚAppendAutoSuggestionInAnyLineé!   a±  
Append the auto suggestion to lines other than the last (appending to the
last line is natively supported by the prompt toolkit).

This has a private `_debug` attribute that can be set to True to display
debug information as virtual suggestion on the end of any line. You can do
so with:

    >>> from IPython.terminal.shortcuts.auto_suggest import AppendAutoSuggestionInAnyLine
    >>> AppendAutoSuggestionInAnyLine._debug = True

FÚ_debugÚstyleÚreturnNc                 ó   • Xl         g r   ©r'   )Úselfr'   s     r    Ú__init__Ú&AppendAutoSuggestionInAnyLine.__init__1   s   € Ø�
r"   Útic                 óæ  ^ ^• TR                   R                  S-
  nTR                  U:H  nU U4S jnTR                   R                  S:X  a  U" S5      $ TR                   R                  U:X  a  U(       a  U" S5      $ TR                  TR                   R                  :  a  U" S5      $ TR                  R
                  nUR                  (       a  TR                   R                  (       d  U" S5      $ TR                  TR                   R                  -
  nUR                  R                  R                  5       n[        U5      S:X  a  U" S5      $ [        R                  S	:  aÝ  [        U5      S:”  ab  [        R                  S	:  aN  TR                  TR                   R                  :X  a  [        TR                  S
/-   S9$ [        TR                  S9$ [        U5      S:X  aJ  TR                  TR                   R                  :X  a&  [        TR                  T R                  US   4/-   S9$ [        TR                  S9$ US:X  a(  US   n[        TR                  T R                  U4/-   S9$ U(       Ga  U[        U5      :  a*  S[        U5      U-
   S3n[        T R                  U4/5      $ [        U5      n	[!        [        U5      5       HJ  n
TR#                  X*-
  5      nSR%                  S U 5       5      R'                  5       nU(       a    O	U	S-  n	ML     U	(       a  [        T R                  SU	 S34/5      $ [        TR#                  U[        U5      -
  S-   5      T R(                  (       a  T R                  S4/-   5      $ / -   5      $ U[        U5      :  a  Xv   n[        T R                  U4/5      $ TR                  [        U5      -
  S-   n[        TR#                  U5      5      $ )aƒ  
 Apply transformation to the line that is currently being edited.

 This is a variation of the original implementation in prompt toolkit
 that allows to not only append suggestions to any line, but also to show
 multi-line suggestions.

 As transformation are applied on a line-by-line basis; we need to trick
 a bit, and elide any line that is after the line we are currently
 editing, until we run out of completions. We cannot shift the existing
 lines

 There are multiple cases to handle:

 The completions ends before the end of the buffer:
     We can resume showing the normal line, and say that some code may
     be hidden.

The completions ends at the end of the buffer
     We can just say that some code may be hidden.

 And separately:

 The completions ends beyond the end of the buffer
     We need to both say that some code may be hidden, and that some
     lines are not shown.

r   c                 óv   >• [        TR                  TR                  TR                  (       a  SU -   OS4/-   S9$ )NÚ Ú ©Ú	fragments)r   r4   r'   r&   )Útextr+   r.   s    €€r    Ú<lambda>ÚDAppendAutoSuggestionInAnyLine.apply_transformation.<locals>.<lambda>T   s/   ø€ œNØ—l‘l t§z¡zÀÇÇ°3¸²:ÐRTÐ&UÐ%VÑVò
r"   znoop:onelineznoop:last line and cursorznoop:before cursorznoop:not eolr   znoop: no suggestions)é   r   é1   )ÚredzD(Cannot show multiline suggestion; requires prompt_toolkit > 3.0.49)r3   u   â€¦ rest of suggestion (z lines) and code hiddenr2   c              3   ó*   #   • U  H	  oS    v •  M     g7f)r   N© )Ú.0Úls     r    Ú	<genexpr>ÚEAppendAutoSuggestionInAnyLine.apply_transformation.<locals>.<genexpr>‹   s   é € Ð.ª2 a˜qžTª2ùs   ‚u   â€¦ z line(s) hiddenzshift-last-line)r   Ú
line_countÚlinenor   Úbuffer_controlÚbufferÚ
suggestionÚis_cursor_at_the_end_of_liner5   Ú
splitlinesÚlenÚprompt_toolkitÚVERSIONr   r4   r'   ÚrangeÚget_lineÚjoinÚstripr&   )r+   r.   Úlast_line_numberÚis_last_lineÚnooprD   ÚdeltaÚsuggestionsrE   Ún_elidedÚiÚllÚelÚshifts   ``            r    Úapply_transformationÚ2AppendAutoSuggestionInAnyLine.apply_transformation4   sƒ  ù€ ð: Ÿ;™;×1Ñ1°AÑ5ÐØ—y‘yÐ$4Ñ4ˆõ
ˆð �;‰;×!Ñ! QÓ&Ù˜Ó'Ð'Ø�;‰;×*Ñ*Ð.>Ó>Æ<áÐ3Ó4Ð4ð �9‰9�r—{‘{×6Ñ6Ó6ÙÐ,Ó-Ð-à×"Ñ"×)Ñ)ˆØ× × ¨¯©×(P×(PÙ˜Ó'Ð'à—	‘	˜BŸK™K×;Ñ;Ñ;ˆØ×'Ñ'×,Ñ,×7Ñ7Ó9ˆäˆ{Ó˜qÓ ÙÐ.Ó/Ð/ä×!Ñ! JÓ.Ü�;Ó !Ó#¬×(>Ñ(>ÀÓ(KØ—9‘9 §¡× ?Ñ ?Ó?Ü)Ø"$§,¡,ððñ#ñð ô *°B·L±LÑAÐAÜ�[Ó! QÓ&Ø—9‘9 §¡× ?Ñ ?Ó?Ü)Ø"$§,¡,°4·:±:¸{È1¹~Ð2NÐ1OÑ"Oñð ô "¨B¯L©LÑ9Ð9à�A‹:Ø$ Q™ˆJÜ!¨B¯L©L¸T¿Z¹ZÈÐ<TÐ;UÑ,UÑVÐVßØ”s˜;Ó'Ó'Ø7¼¸KÓ8HÈ5Ñ8PÐ7QÐQhÐi�
Ü%¨¯
©
°JÐ'?Ð&@ÓAÐAä˜;Ó'ˆHÜœ3˜{Ó+Ö,�Ø—[‘[Ð!1Ñ!5Ó6�Ø—W‘WÑ.©2Ó.Ó.×4Ñ4Ó6�ÞÙà ‘M’Hñ -ö Ü%¨¯
©
°d¸8¸*ÀOÐ4TÐ'UÐ&VÓWÐWä%Ø—K‘KÐ 0´3°{Ó3CÑ CÀaÑ GÓHØ<@¿K¿K˜Ÿ™Ð%6Ð7Ð8ñQóð àMOñQóð ð
 ”S˜Ó%Ó%Ø$Ñ+ˆJÜ! D§J¡J°
Ð#;Ð"<Ó=Ð=à—I‘I¤ KÓ 0Ñ0°1Ñ4ˆEÜ! "§+¡+¨eÓ"4Ó5Ð5r"   r*   )zclass:auto-suggestion)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r&   r   ÚboolÚ__annotations__Ústrr,   r   r   rY   Ú__static_attributes__r<   r"   r    r$   r$   !   sA   ‡ ñð #€FˆH�T‰NÓ"ñ˜cð Àõ ði6Ð':ð i6¸~÷ i6r"   r$   c                   óÔ  ^ • \ rS rSr% Sr\\S'   \\   \S'   Sr	\
R                  S-  \S'   \S-  \S'   \S-  \S'   S	 r\\S
'   U 4S jrS\SS4S jrS%S jrS\SS4S jrS\S\S\\   4S jrS%S jrS\S\S\S\S\\\\4   SS4   4
S jrS\S\S\S\\\\4   SS4   4S jr S\S\S\4S jr!S\S\S\SS4S jr"S\S\S\SS4S jr#S%S  jr$\%S! 5       r&S%S" jr'S\4S# jr(S$r)U =r*$ )&ÚNavigableAutoSuggestFromHistoryé    zÑ
A subclass of AutoSuggestFromHistory that allow navigation to next/previous
suggestion from history. To do so it remembers the current position, but it
state need to carefully be cleared on the right events.
Ú
skip_linesÚ_connected_appsNÚ	_llm_taskÚ_init_llm_providerÚ_llm_provider_instancec                 ó   • g)NÚwrongr<   )r+   Úxs     r    r6   Ú(NavigableAutoSuggestFromHistory.<lambda>´   s   € ¨gr"   Ú_llm_prefixerc                 óh   >• [         TU ]  5         SU l        / U l        S U l        S U l        SU l        g ©Nr   )Úsuperr,   rg   rh   rk   rj   Ú_request_number)r+   Ú	__class__s    €r    r,   Ú(NavigableAutoSuggestFromHistory.__init__¶   s5   ø€ Ü‰ÑÔØˆŒØ!ˆÔØ&*ˆÔ#Ø"&ˆÔØ ˆÕr"   Ú_r(   c                 ó   • SU l         g rr   )rg   )r+   rw   s     r    Úreset_history_positionÚ6NavigableAutoSuggestFromHistory.reset_history_position¾   s	   € Øˆ�r"   c                 ó¬   • U R                  5         U R                   H4  nUR                  R                  nUR	                  U R
                  5        M6     g r   )Ú_cancel_running_llm_taskrh   Údefault_bufferÚon_text_insertÚremove_handlerry   )r+   Úpt_appÚtext_insert_events      r    Ú
disconnectÚ*NavigableAutoSuggestFromHistory.disconnectÁ   sD   € Ø×%Ñ%Ô'Ø×*Ô*ˆFØ &× 5Ñ 5× DÑ DÐØ×,Ñ,¨T×-HÑ-HÖIò +r"   r€   c                 óö   • U R                   R                  U5        UR                  R                  R	                  U R
                  5        UR                  R                  R	                  U R                  5        g r   )rh   Úappendr}   r~   Úadd_handlerry   Úon_cursor_position_changedÚ_dismiss)r+   r€   s     r    ÚconnectÚ'NavigableAutoSuggestFromHistory.connectÇ   sV   € Ø×Ñ×#Ñ# FÔ+ð 	×Ñ×,Ñ,×8Ñ8¸×9TÑ9TÔUØ×Ñ×8Ñ8×DÑDÀTÇ]Á]ÕSr"   rD   r   c                 ó¸   • [        U5      nUR                  5       (       a:  U R                  X0R                  UR                  5       H  u  pE[        U5      s  $    g r   )r!   rN   Ú_find_next_matchrg   Úhistoryr   )r+   rD   r   r5   rE   rw   s         r    Úget_suggestionÚ.NavigableAutoSuggestFromHistory.get_suggestionÎ   sO   € ô ˜(Ó#ˆà�:‰:�<‰<Ø!%×!6Ñ!6Ø—o‘o v§~¡~ö"‘�
ô " *Ó-Ò-ñ"ð
 r"   c                 ó2   • U R                  5         S Ul        g r   )r|   rE   )r+   rD   ÚargsÚkwargss       r    rˆ   Ú(NavigableAutoSuggestFromHistory._dismissÛ   s   € Ø×%Ñ%Ô'Ø ˆÕr"   r5   r�   Úpreviousc              #   ój  #   • Sn[        [        UR                  5       5      5       H‡  n[        UR                  5       5       Hg  nUS-  nU(       d  XR:  a  M  UR	                  U5      (       a*  [        U5      [        U5      :”  a  U[        U5      S U4v •  U(       d  M_  XR:¼  d  Mf      g   M‰     g7f)a»  
text : str
    Text content to find a match for, the user cursor is most of the
    time at the end of this text.
skip_lines : float
    number of items to skip in the search, this is used to indicate how
    far in the list the user has navigated by pressing up or down.
    The float type is used as the base value is +inf
history : History
    prompt_toolkit History instance to fetch previous entries from.
previous : bool
    Direction of the search, whether we are looking previous match
    (True), or next match (False).

Yields
------
Tuple with:
str:
    current suggestion.
float:
    will actually yield only ints, which is passed back via skip_lines,
    which may be a +inf (float)


éÿÿÿÿr   N)ÚreversedÚlistÚget_stringsrG   Ú
startswithrH   )r+   r5   rg   r�   r”   Úline_numberÚstringÚlines           r    Ú_find_matchÚ+NavigableAutoSuggestFromHistory._find_matchß   s™   é € ð8 ˆÜœt G×$7Ñ$7Ó$9Ó:Ö;ˆFÜ  ×!2Ñ!2Ó!4Ö5�Ø˜qÑ �Þ KÓ$<Ùð —?‘? 4×(Ñ(¬S°«Y¼¸T»Ó-BØœs 4›y˜{Ð+¨[Ð8Ò8ß�8 Õ 9Úó 6ò <ùs   ‚BB3Â"B3Â)
B3c                 ó$   • U R                  XUSS9$ )NF©r”   )rž   ©r+   r5   rg   r�   s       r    rŒ   Ú0NavigableAutoSuggestFromHistory._find_next_match  s   € ð ×Ñ °'ÀEÐÐJÐJr"   c                 óH   • [        [        U R                  XUSS95      5      $ )NTr¡   )r—   r˜   rž   r¢   s       r    Ú_find_previous_matchÚ4NavigableAutoSuggestFromHistory._find_previous_match  s)   € ÜÜ�×!Ñ! $°GÀdÐ!ÐKÓLó
ð 	
r"   ÚqueryÚ
other_thanc                 óœ   • U R                  5         U R                  XR                  U5       H  u  pEX-   U:w  d  M  XPl          g    SU l        g rr   )r|   rŒ   rg   ©r+   r§   r¨   r�   rE   r›   s         r    ÚupÚ"NavigableAutoSuggestFromHistory.up  sM   € Ø×%Ñ%Ô'Ø'+×'<Ñ'<Ø—?‘? Gö(
Ñ#ˆJð Ñ! ZÕ/Ø"-”Ùñ(
ð  ˆD�Or"   c                 óø   • U R                  5         U R                  XR                  U5       H  u  pEX-   U:w  d  M  XPl          g    U R                  U[        S5      U5       H  u  pEX-   U:w  d  M  XPl          g    g )NÚInf)r|   r¥   rg   Úfloatrª   s         r    ÚdownÚ$NavigableAutoSuggestFromHistory.down#  s~   € Ø×%Ñ%Ô'Ø'+×'@Ñ'@Ø—?‘? Gö(
Ñ#ˆJð Ñ! ZÕ/Ø"-”Ùñ(
ð ,0×+DÑ+DØ”u˜U“| Wö,Ñ'�
ð Ñ%¨Õ3Ø&1”OÙò,r"   c                 óú   • U R                   bn  U R                   R                  5       (       a  SU l         gU R                   R                  5       nU(       a  SU l         U(       d  [        R                  " S5        ggg)zM
Try to cancel the currently running llm_task if exists, and set it to None.
Nz@LLM task not cancelled, does your provider support cancellation?)ri   ÚdoneÚcancelÚwarningsÚwarn)r+   Ú	cancelleds     r    r|   Ú8NavigableAutoSuggestFromHistory._cancel_running_llm_task4  sc   € ð �>‰>Ñ%Ø�~‰~×"Ñ"×$Ñ$Ø!%�”ØØŸ™×-Ñ-Ó/ˆIÞØ!%�”ÞÜ—’ØVõð ð &r"   c                 ó€   • U R                   c&  U R                  (       a  U R                  5       U l         U R                   $ )z†Lazy-initialized instance of the LLM provider.

Do not use in the constructor, as `_init_llm_provider` can trigger slow side-effects.
)rk   rj   )r+   s    r    Ú_llm_providerÚ-NavigableAutoSuggestFromHistory._llm_providerD  s5   € ð ×&Ñ&Ñ.°4×3J×3JØ*.×*AÑ*AÓ*CˆDÔ'Ø×*Ñ*Ð*r"   c              ƒ   óX  ^ #   •  SSK nT R                  (       d  [        R                  " S5        gUc  [        R                  " S5        T R                  5         U 4S jn[        R                  " U" U5      5      T l        T R                  I Sh  v•N   g! [         a    Sn N›f = f N7f)z‹
This will ask the current llm provider a suggestion for the current buffer.

If there is a currently running llm task, it will cancel it.
r   Nú5No LLM provider found, cannot trigger LLM completionsz;LLM Completion requires `jupyter_ai_magics` to be installedc              “   ó´   >#   •  TR                  U 5      I Sh  v•N   g N! [         a*  n[        5       R                  R	                  SU5        e SnAff = f7f)zi
This catches and log any errors, as otherwise this is just
lost in the void of the future running task.
Nzerror %s)Ú_trigger_llm_coreÚ	Exceptionr   ÚlogÚerror)rD   Úer+   s     €r    Úerror_catcherÚCNavigableAutoSuggestFromHistory._trigger_llm.<locals>.error_catchera  sI   øé € ð
Ø×,Ñ,¨VÓ4×4Ó4øÜó Ü“×!Ñ!×'Ñ'¨
°AÔ6Øûðüs0   ƒA…! ™š! žAŸ! ¡
A«%AÁAÁA)	Újupyter_ai_magicsÚModuleNotFoundErrorrº   rµ   r¶   r|   ÚasyncioÚcreate_taskri   )r+   rD   rÆ   rÄ   s   `   r    Ú_trigger_llmÚ,NavigableAutoSuggestFromHistory._trigger_llmN  s�   øé € ð	%Û$ð ×!×!Ü�MŠMÐQÔRØØÑ$Ü�MŠMÐWÔXà×%Ñ%Ô'õ		ô !×,Ò,©]¸6Ó-BÓCˆŒØ�n‰n×Ñøô/ #ó 	%Ø $Òð	%úñ. 	ùs4   ƒB*…B ‰BB*ÂB(ÂB*ÂB%Â"B*Â$B%Â%B*c              ƒ   óf  #   •  SSK Js  Jn  U(       d  [	        S5      eU R
                  (       d  [	        S5      eUR                  R                  R                  nU R                  U5      n[        5       R                  R                  SU5        U =R                  S-  sl        U R                  nUR                  UXAR                  R                   -   UR                  R"                  SSSS	SS
9nU R
                  R%                  U5        Sh  v•N nU R                  U:w  a    g['        XrR(                  5      (       a{  [+        UR,                  R.                  5      S:”  a  [	        S5      e[1        UR,                  R.                  S   R2                  5      Ul        UR6                  R9                  5         M°  ['        XrR:                  5      (       d  MÌ  [1        UR<                  R2                  5      Ul        UR6                  R9                  5         GM  ! [         a    Sn GNf = f GN
 g7f)aÎ  
This is the core of the current llm request.

Here we build a compatible `InlineCompletionRequest` and ask the llm
provider to stream it's response back to us iteratively setting it as
the suggestion on the current buffer.

Unlike with JupyterAi, as we do not have multiple cells, the cell id
is always set to `None`.

We set the prefix to the current cell content, but could also insert the
rest of the history or even just the non-fail history.

In the same way, we do not have cell id.

LLM provider may return multiple suggestion stream, but for the time
being we only support one.

Here we make the assumption that the provider will have
stream_inline_completions, I'm not sure it is the case for all
providers.
r   Nzjupyter-ai is not installedr½   z
prefix: %sr   ztext/x-pythonTÚpython)ÚnumberÚprefixÚsuffixÚmimeÚstreamÚpathÚlanguageÚcell_idzBTerminal IPython cannot deal with multiple LLM suggestions at once)Újupyter_ai.completions.modelsÚcompletionsÚmodelsrÇ   Ú
ValueErrorrº   r�   ÚshellÚhistory_managerrp   r   rÁ   Údebugrt   ÚInlineCompletionRequestr   Útext_before_cursorÚtext_after_cursorÚstream_inline_completionsÚ
isinstanceÚInlineCompletionReplyrH   r˜   Úitemsr   Ú
insertTextrE   Úon_suggestion_setÚfireÚInlineCompletionStreamChunkÚresponse)r+   rD   Ú
jai_modelsÚhmrÏ   Úrequest_numberÚrequestÚreply_and_chunkss           r    r¿   Ú1NavigableAutoSuggestFromHistory._trigger_llm_corep  sä  é € ð.	ß>Ð>ö ÜÐ:Ó;Ð;à×!×!ÜÐTÓUÐUà�^‰^×!Ñ!×1Ñ1ˆØ×#Ñ# BÓ'ˆÜ‹×Ñ×Ñ ¨fÔ5à×Ò Ñ!ÕØ×-Ñ-ˆà×4Ñ4Ø!ØŸO™O×>Ñ>Ñ>Ø—?‘?×4Ñ4Ø ØØØØð 5ð 	
ˆð '+×&8Ñ&8×&RÑ&RØô'
÷ 	0Ð"ð ×#Ñ# ~Ó5áÜÐ*×,LÑ,L×MÑMÜÐ'×,Ñ,×2Ñ2Ó3°aÓ7Ü$Ø\óð ô %/Ø$×)Ñ)×/Ñ/°Ñ2×=Ñ=ó%�Ô!ð ×(Ñ(×-Ñ-Ö/ÜÐ,×.TÑ.T×UÓUÜ$.Ð/?×/HÑ/H×/SÑ/SÓ$T�Ô!Ø×(Ñ(×-Ñ-×/øôY #ó 	Ø‹Jð	úò6	0ð '
ð$ 	ùsT   ‚H1„	H �C?H1ÄH/ÄH,ÄH/ÄC H1ÇAH1ÈH)È%H1È(H)È)H1È,H/È/H1)rh   rj   rk   ri   rt   rg   )r(   N)+r[   r\   r]   r^   r_   Úintra   r˜   r   ri   rÈ   ÚTaskr
   r	   rp   r,   r   ry   r‚   r‰   r   r   r   rŽ   rˆ   rb   r¯   r   r`   r   r   rž   rŒ   r¥   r«   r°   r|   Úpropertyrº   rÊ   r¿   rc   Ú__classcell__)ru   s   @r    re   re       s»  ø‡ ñð ƒOØ˜-Ñ(Ó(ð
 &*€Iˆw�|‰|˜dÑ"Ó)ð ! 4™Ó'à $™JÓ&Ù5€M�8Ó5õ!ð¨ð °4ô ôJðT˜mð T°ô TðØðØ(0ðà	�*Ñ	ôô!ð'Øð'Ø%*ð'Ø5<ð'ØHLð'à	�5˜˜e˜Ñ$ d¨DÐ0Ñ	1ô'ðRKØðKØ%*ðKØ5<ðKà	�5˜˜e˜Ñ$ d¨DÐ0Ñ	1ôKð

¨ð 
¸%ð 
È'ô 
ð
 ˜ð  ¨ð  °wð  À4ô  ð"˜#ð ¨3ð ¸ð ÀTô ô"ð  ñ+ó ð+ô ðDF¨f÷ Fò Fr"   re   Úeventc              ƒ   ó~  #   • Sn[        5       R                  n[        U[        5      (       d  gU R                  R
                  n[        SXR                  -
  UR                  -   5      n[        U5       H  nU R                  R                  SSSS9  M      UR                  U R                  5      I Sh  v•N   g N7f)z÷
Ask the AutoSuggester from history to delegate to ask an LLM for completion

This will first make sure that the current buffer have _MIN_LINES (7)
available lines to insert the LLM completion

Provisional as of 8.32, may change without warnings

é   Nr   Ú
F)Úmove_cursorÚ
fire_event)r   Úauto_suggestrá   re   Úcurrent_bufferr   ÚmaxrA   r   rK   Úinsert_textrÊ   )ró   Ú
_MIN_LINESÚproviderÚdocÚlines_to_insertrw   s         r    Úllm_autosuggestionr  ¹  sŸ   é € ð €JÜ‹}×)Ñ)€HÜ�hÔ ?×@Ñ@ØØ
×
Ñ
×
'Ñ
'€CÜ˜!˜Z¯.©.Ñ8¸3×;RÑ;RÑRÓS€OÜ�?Ö#ˆØ×Ñ×(Ñ(¨¸5ÈUÐ(ÓSñ $ð ×
Ñ
 × 4Ñ 4Ó
5×5Ó5ùs   ‚B3B=Â5B;Â6B=c                 ó^  • U R                   nUR                  nUR                  UR                  S nUR	                  S5      nUS   R                  5       nUR                  nUb3  UR                  (       a"  US:X  a  UR                  UR                  5        g[        R                  " U 5        g)z,Apply autosuggestion or jump to end of line.Nrö   r   r2   )
rú   r   r5   Úcursor_positionÚsplitrN   rE   rü   ÚncÚend_of_line)ró   rD   ÚdÚafter_cursorr   Úend_of_current_linerE   s          r    Úaccept_or_jump_to_endr
  Ï  sŒ   € à×!Ñ!€FØ�‰€AØ—6‘6˜!×+Ñ+Ð-Ð.€LØ×Ñ˜tÓ$€EØ ™(Ÿ.™.Ó*ÐØ×"Ñ"€JØÑ Z§_§_Ð;NÐRTÓ;TØ×Ñ˜:Ÿ?™?Õ+ä
�Š�uÕr"   c                 ó¦   • U R                   nUR                  nU(       a  UR                  UR                  5        g[        R
                  " U 5        g)zAccept autosuggestionN)rú   rE   rü   r5   r  Úforward_char)ró   rD   rE   s      r    Úacceptr  Ý  s9   € à×!Ñ!€FØ×"Ñ"€JÞØ×Ñ˜:Ÿ?™?Õ+ä
�Š˜Õr"   c                 ó*   • U R                   nSUl        g)zDiscard autosuggestionN)rú   rE   )ró   rD   s     r    Údiscardr  ç  s   € à×!Ñ!€FØ€FÕr"   c                 óö   • U R                   nUR                  nU(       aD  [        R                  " SUR                  5      nUR                  [        S U 5       S5      5        g[        R                  " U 5        g)z#Fill partial autosuggestion by wordz(\S+\s+)c              3   ó6   #   • U  H  o(       d  M  Uv •  M     g 7fr   r<   )r=   rn   s     r    r?   Úaccept_word.<locals>.<genexpr>ó  s   é € Ð 3ªA q³§¡ªAùs   ‚
�	r2   N)	rú   rE   Úrer  r5   rü   Únextr  Úforward_word)ró   rD   rE   Úts       r    Úaccept_wordr  í  sV   € à×!Ñ!€FØ×"Ñ"€JÞÜ�HŠH�[ *§/¡/Ó2ˆØ×Ñœ4Ñ 3©AÓ 3°RÓ8Õ9ä
�Š˜Õr"   c                 ó¤   • U R                   nUR                  nU(       a1  UR                  (       a  UR                  UR                  S   5        ggg)z(Fill partial autosuggestion by characterr   N)rú   rE   r5   rü   )ró   ÚbrE   s      r    Úaccept_characterr  ø  s;   € à×Ñ€AØ—‘€JÞ�j—o—oØ	�‰�j—o‘o aÑ(Õ)ð &€zr"   c                 óž   • U R                   nUR                  nUR                  nU(       a"  UR                  UR                  5        X!l        gg)z.Accept autosuggestion and keep cursor in placeN)rú   r  rE   rü   r5   )ró   rD   Úold_positionrE   s       r    Úaccept_and_keep_cursorr     sC   € à×!Ñ!€FØ×)Ñ)€LØ×"Ñ"€JÞØ×Ñ˜:Ÿ?™?Ô+Ø!-Õð r"   c                 óF   • [        U 5        [        R                  " U 5        g)z3Accept autosuggestion and move cursor left in placeN)r  r  Úbackward_char©ró   s    r    Úaccept_and_move_cursor_leftr!  
  s   € ä˜5Ô!Ü×Ò�UÕr"   rD   c                 ó~   • U R                   (       a,  U R                   R                  X R                  5      nXl        g g r   )rù   rŽ   r   rE   )rD   rE   s     r    Ú_update_hintr#    s0   € Ø××Ø×(Ñ(×7Ñ7¸ÇÁÓPˆ
Ø&Õð r"   c                 óZ   • [         R                  " U 5        [        U R                  5        g)z4Resume autosuggestions after deleting last characterN)r  Úbackward_delete_charr#  rú   r   s    r    Úbackspace_and_resume_hintr&    s   € ä×Ò˜EÔ"Ü�×%Ñ%Õ&r"   c                 óZ   • [         R                  " U 5        [        U R                  5        g)zResume autosuggestionsN)r   Úreplyr#  rú   r   s    r    Úresume_hintingr)    s    € ä×Ò�uÔô �×%Ñ%Õ&r"   c                 ód   • U R                   nUR                  U R                  S9  [        U5        g)zGo up and update hint©ÚcountN)rú   Úauto_upÚargr#  ©ró   rú   s     r    Úup_and_update_hintr0  $  s*   € à×)Ñ)€Nà×Ñ §¡ÐÑ+Ü�Õ r"   c                 ód   • U R                   nUR                  U R                  S9  [        U5        g)zGo down and update hintr+  N)rú   Ú	auto_downr.  r#  r/  s     r    Údown_and_update_hintr3  ,  s*   € à×)Ñ)€Nà×Ñ 5§9¡9ÐÑ-Ü�Õ r"   c                 ó\  • U R                   nUR                  nU(       Gav  [        UR                  5      nX2R                  -   n/ SQnS/nSn[        [        U5      R                  5       HØ  nUR                  [        R                  :X  a  [        U5      n	O!UR                  US   [        US   5      5      n	UR                  USU	 5        US   n
U
R                  U5      (       d  M  US:X  a?  [        U
5      [        U5      :”  a'  U
[        U5      S US'   UR                  U
5        US-  nUS   XW'   US:X  a    O	US-  nMÚ     US   (       aF  US   nUS   (       a  [        US   5      S:X  a  US   nU[        U5      S nUR                  U5        g[         R"                  " U 5        g)	z$Fill partial autosuggestion by token)NNNr2   r   r   r–   Né   éþÿÿÿ)rú   rE   r!   r   r5   r   r   ÚreadlineÚtypeÚtokenizeÚNEWLINErH   Úindexr…   rš   rü   r  r  )ró   r  rE   rÏ   r5   ÚtokensÚ
substringsrU   Útokenr;  Útokenized_so_farrü   Ú	to_inserts                r    Úaccept_tokenrA  4  s‚  € à×Ñ€AØ—‘€JçÜ˜AŸJ™JÓ'ˆØŸ™Ñ'ˆâ&8ˆØ�Tˆ
Øˆä$¤X¨d£^×%<Ñ%<Ö=ˆEØ�z‰zœX×-Ñ-Ó-Ü˜D›	‘àŸ
™
 5¨¡8¬S°¸B±Ó-@ÓA�Ø×Ñ˜d 6 E˜lÔ+Ø)¨"™~ÐØ×*Ñ*¨6×2Ó2Ø˜“6œcÐ"2Ó3´c¸&³kÓAØ 0´°V³°Ð ?�F˜1‘IØ×%Ñ%Ð&6Ô7Ø˜‘F�AØ! !™H�‘	Ø˜“6ÙØ�Q‘’ñ >ð" �!�9à$ R™.ˆKØ�a�yœS ¨¡›^¨qÓ0Ø(¨™n�Ø#¤C¨£K MÐ2ˆIØ�M‰M˜)Ô$Øä‡O‚O�EÕr"   rþ   Údirection_methodc                 óÖ   • U R                   nU(       d  g[        U R                  5      nXCR                  -   nU" XEU R                  S9  UR                  X R                  5      nX`l         g)a  
We skip most recent history entry (in either direction) if it equals the
current autosuggestion because if user cycles when auto-suggestion is shown
they most likely want something else than what was suggested (otherwise
they would have accepted the suggestion).
N)r§   r¨   r�   )rE   r!   r   r5   r�   rŽ   )rD   rþ   rB  rE   r§   ÚcurrentÚnew_suggestions          r    Ú_swap_autosuggestionrF  a  sW   € ð ×"Ñ"€JÞØä�v—‘Ó'€EØ—o‘oÑ%€Gá˜5¸f¿n¹nÒMà×,Ñ,¨V·_±_ÓE€NØ&Õr"   c                 ó–   • [        5       nUR                  n[        U[        5      (       d  g[	        U R
                  X"R                  S9$ )z%Get next autosuggestion from history.N©rD   rþ   rB  )r   rù   rá   re   rF  rú   r«   ©ró   rÚ   rþ   s      r    Úswap_autosuggestion_uprJ  y  sA   € ä‹M€EØ×!Ñ!€Hä�hÔ ?×@Ñ@ØäØ×#Ñ#¨hÏÉñð r"   c                 ó˜   • [        5       nUR                  n[        U[        5      (       d  g[	        U R
                  UUR                  S9$ )z)Get previous autosuggestion from history.NrH  )r   rù   rá   re   rF  rú   r°   rI  s      r    Úswap_autosuggestion_downrL  †  sE   € ä‹M€EØ×!Ñ!€Hä�hÔ ?×@Ñ@ØäØ×#Ñ#ØØ!Ÿ™ñð r"   )@r  rÈ   r9  Úior   Útypingr   r   r   r   r   r	   Úcollections.abcr
   r   rµ   rI   Úprompt_toolkit.bufferr   Úprompt_toolkit.key_bindingr   Ú#prompt_toolkit.key_binding.bindingsr   r  Úprompt_toolkit.auto_suggestr   r   Úprompt_toolkit.documentr   Úprompt_toolkit.historyr   Úprompt_toolkit.shortcutsr   Ú prompt_toolkit.layout.processorsr   r   r   ÚIPython.core.getipythonr   ÚIPython.utils.tokenutilr   Úfiltersr   r!   r$   re   r  r
  r  r  r  r  r  r!  r#  r&  r)  r0  r3  rA  ÚProviderrF  rJ  rL  r<   r"   r    Ú<module>r\     sj  ðÛ 	Û Û Ý ß >× >ß /Û ã Ý (Ý 4Ý Dß JÝ ,Ý *Ý 2÷ñ õ 0Ý 3å !ð8˜ô 8ô|6 Iô |6ô~VÐ&<ô Vðr6 Mô 6ð, ô ð�-ô ð�=ô ð�}ô ð*˜Mô *ð. -ô .ð }ô ð'˜ô 'ð' ]ô 'ð'˜-ô 'ð!˜mô !ð! ô !ð'˜ô 'ðT Ð'Ð)HÈ$ÐNÑO€ð'Øð'à-ð'ð ô'ð0
 -ô 
ð Mõ r"   