
    i                     2   d dl mZ d dlmZmZmZmZ d dlmZm	Z	m
Z
mZmZ d dl  G d de      Z G d de      Z G d	 d
e      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Zg dZy)    )annotations)ListOptionalDictAny)	BaseModelField
ConfigDictfield_validatormodel_validator)*c                     e Zd ZU dZ edd      ZdZded<   dZded<   dZ	d	ed
<   dZ
ded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   d$d Z edd!"      d#        Zy)%
ActionItemzKExactly one of the fields must be populated to specify the concrete action.T)exclude_nonepopulate_by_nameNzOptional[NoParamsAction]donezOptional[InputTextAction]
input_textzOptional[OpenAppAction]open_appzOptional[AppleScriptAction]run_apple_scriptzOptional[PressAction]HotkeyzOptional[PressCombinedAction]multi_HotkeyzOptional[RightClickPixel]RightSinglezOptional[LeftClickPixel]ClickzOptional[DragAction]DragzOptional[MoveToAction]
move_mousezOptional[ScrollUpAction]	scroll_upzOptional[ScrollDownAction]scroll_downzOptional[RecordAction]record_infowaitc                    | j                  d      }dj                  d |j                         D              }| j                  j                   d| dS )NTr   , c              3  0   K   | ]  \  }}| d |  yw=N .0kvs      J/Users/mibo/.openclaw/workspace/data/TuriX-CUA/src/agent/structured_llm.py	<genexpr>z&ActionItem.__repr__.<locals>.<genexpr>   !     I8H1!AaU|8H   ()
model_dumpjoinitems	__class____name__selfnon_none
field_strss      r+   __repr__zActionItem.__repr__   K    ???5YYI8HII
..))*!J<q99    beforemodec                <    |dk(  s|i S t        |t              si S |S )N )
isinstancedict)clsr*   s     r+   fix_empty_stringzActionItem.fix_empty_string    s&    7aiI!T"Ir=   returnstr)r6   
__module____qualname____doc__r
   model_configr   __annotations__r   r   r   r   r   r   r   r   r   r   r   r   r   r;   r   rF   r&   r=   r+   r   r   	   s    U4$GL%)D
"),0J)0(,H%,4818$(F!(26L/6-1K*1&*E#*!%D
%)-J&-*.I'..2K+2*.K'.%)D
"):
 V(+ ,r=   r   c                  J    e Zd ZU  edd      Zded<    edd      Zded<   y)	Analysis.zFDetailed analysis of how the current state matches the expected state.descriptionrI   analysisz>Selected Skill step for this moment (quote exactly) or 'None'.	sop_checkN)r6   rJ   rK   r	   rS   rN   rT   r&   r=   r+   rP   rP   ,   s&    #+stHct3,lmIsmr=   rP   c                  h    e Zd ZU  edd      Zded<    edd      Zded<    edd      Zded	<   y
)CurrentState.z)Success/Failed (based on step completion)rQ   rI   step_evaluatezDescribe what you want user to do or No (No if nothing to ask for comfirmation. If something is unclear, ask the user for confirmation, like ask the user to login, or comfirm preference.)	ask_humanz}Actionable goal based on current state (screenshots/memory) and any Selected Skills; adapt skill steps to the current screen.	next_goalN)r6   rJ   rK   r	   rW   rN   rX   rY   r&   r=   r+   rV   rV   0   sJ    s0[\M3\3  -j  kIs  k3  -l  mIs  mr=   rV   c                  ,    e Zd ZU  edd      Zded<   y)ReadFilesRequest.z Recorded info filenames to read.rQ   	List[str]filesN)r6   rJ   rK   r	   r]   rN   r&   r=   r+   r[   r[   5   s    S.PQE9Qr=   r[   c                  v    e Zd ZU  edd      Zded<    edd      Zded<   ddZedd	       Z	edd
       Z
y)MemoryOutput.z+Brief summary to remember for future steps.rQ   rI   summaryz0Filename to store the pre-summarization context.	file_namec                    | j                  d      }dj                  d |j                         D              }| j                  j                   d| dS )NTr!   r"   c              3  0   K   | ]  \  }}| d |  ywr$   r&   r'   s      r+   r,   z(MemoryOutput.__repr__.<locals>.<genexpr>B   r-   r.   r/   r0   r1   r7   s      r+   r;   zMemoryOutput.__repr__@   r<   r=   c                (    | j                  dd      S z
        Returns a JSON-formatted string representation of the instance,
        allowing access via the `.content` attribute.
        Tr   exclude_unsetmodel_dump_jsonr8   s    r+   contentzMemoryOutput.contentE        ##T#JJr=   c                (    | j                  dd      S z
        Returns the dictionary representation of the instance,
        facilitating direct access to structured data.
        Trf   r2   rj   s    r+   parsedzMemoryOutput.parsedM        DEEr=   NrG   rH   zDict[str, Any])r6   rJ   rK   r	   r`   rN   ra   r;   propertyrk   rp   r&   r=   r+   r_   r_   <   sW    *WXGSX3,^_Is_:
 K K F Fr=   r_   c                      e Zd ZU dZdZded<   dZded<   dZded<    ed	
      dd       Z	ddZ
edd       Zedd       Zy)BrainOutputu   Schema for the agent's per‑step output.

    - ``action``: list of actions the agent should perform in order. Multiple actions
      are allowed in a single step.
    - ``current_state``: diagnostic information that supervisors/evaluators can use.
    NzOptional[Analysis]rS   zOptional[CurrentState]current_statezOptional[ReadFilesRequest]
read_filesafterr?   c                    | j                   r%| j                  s| j                  rt        d      | S | j                  r| j                  st        d      | S )Nz=Read-files output must not include analysis or current_state.zIanalysis and current_state are required when read_files is not requested.)rw   rS   rv   
ValueErrorrj   s    r+   validate_outputzBrainOutput.validate_output`   sM    ??}} 2 2 !`aa  MMd&8&8 !lmmr=   c                    | j                  d      }dj                  d |j                         D              }| j                  j                   d| dS )NTr!   r"   c              3  0   K   | ]  \  }}| d |  ywr$   r&   r'   s      r+   r,   z'BrainOutput.__repr__.<locals>.<genexpr>l   r-   r.   r/   r0   r1   r7   s      r+   r;   zBrainOutput.__repr__j   r<   r=   c                (    | j                  dd      S re   rh   rj   s    r+   rk   zBrainOutput.contento   rl   r=   c                (    | j                  dd      S rn   ro   rj   s    r+   rp   zBrainOutput.parsedw   rq   r=   )rH   z'BrainOutput'rG   rr   )r6   rJ   rK   rL   rS   rN   rv   rw   r   r{   r;   rs   rk   rp   r&   r=   r+   ru   ru   U   sr     $(H ',0M)0-1J*1'" #:
 K K F Fr=   ru   c                  \    e Zd ZU  edddd      Zded<   ddZedd	       Zedd
       Z	y)ActorOutput.r   
   z+Ordered list of 0-10 actions for this step.)	min_items	max_itemsrR   zList[ActionItem]actionc                    | j                  d      }dj                  d |j                         D              }| j                  j                   d| dS )NTr!   r"   c              3  0   K   | ]  \  }}| d |  ywr$   r&   r'   s      r+   r,   z'ActorOutput.__repr__.<locals>.<genexpr>   r-   r.   r/   r0   r1   r7   s      r+   r;   zActorOutput.__repr__   r<   r=   c                (    | j                  dd      S re   rh   rj   s    r+   rk   zActorOutput.content   rl   r=   c                (    | j                  dd      S rn   ro   rj   s    r+   rp   zActorOutput.parsed   rq   r=   NrG   rr   )
r6   rJ   rK   r	   r   rN   r;   rs   rk   rp   r&   r=   r+   r   r      sQ    $A	 F :
 K K F Fr=   r   c                  T    e Zd ZU  edd      Zded<   ded<    edd	      Zded
<   y)Step.z
^Step \d+$)patternrI   step_idOptional[str]rR   z3Relevant search info for this step or empty string.rQ   important_search_infoN)r6   rJ   rK   r	   r   rN   r   r&   r=   r+   r   r      s,    m4GS4!&s8m!n3nr=   r   c                  J    e Zd ZU  edd      Zded<    edd      Zded<   y)IterationInfo.   )geintcurrent_iterationtotal_iterationsN)r6   rJ   rK   r	   r   rN   r   r&   r=   r+   r   r      s&    "31-s-!#!,c,r=   r   c                      e Zd ZU ded<    edd      Zded<    eed	      Zd
ed<    edd      Zded<    eddd      Z	ded<   e
dd       Zy)PlannerOutputr   iteration_info.z5Concise summary of the most relevant search findings.rQ   rI   search_summaryz:Planner-selected skills by name. Empty list if none apply.)default_factoryrR   r\   selected_skillsNz5High-level plan in natural language without step IDs.)defaultrR   r   natural_language_planr   z?Ordered high-level plan objects, each must start with 'Step N'.)r   rR   z
List[Step]step_by_step_planc           	        g }| j                   r|j                  d| j                           | j                  r-|j                  ddj                  | j                                | j                  r,|j                  d       |j                  | j                         | j
                  D ]@  }|j                  xs d}|j                  |j                   d|j                   d| d       B d	j                  |      S )
NzSearch summary: zSelected skills: r"   zPlan:rB   z: z
 (search: r0   
)	r   appendr   r3   r   r   r   r   rR   )r8   linesstepinfos       r+   rk   zPlannerOutput.content   s    LL+D,?,?+@ABLL,TYYt7K7K-L,MNO%%LL!LL334**D--3DLLDLL>D,<,<+=ZvQOP + yyr=   rG   )r6   rJ   rK   rN   r	   r   listr   r   r   rs   rk   r&   r=   r+   r   r      s{    !!1hiNCi!&P"OY  ,1K,=  %*#U%z 
    r=   r   )ru   r   r   r_   N)
__future__r   typingr   r   r   r   pydanticr   r	   r
   r   r   src.controller.viewsr   rP   rV   r[   r_   ru   r   r   r   r   __all__r&   r=   r+   <module>r      s    " , , S S "
 Fny nm9 m
Ry RF9 F2(F) (FTF) F:o9 o
-I - I  @r=   