
    i:                     h    d Z ddlZddlmZ ddlmZmZmZ ddlm	Z	m
Z
mZmZ ddlmZ  G d d      Zy)	zCHelpers for building initial task inputs with optional attachments.    N)Path)ListSequenceUnion)MessageMessageBlockMessageBlockTypeMessageRole)AttachmentStorec            	       p    e Zd ZdZdefdZdedee   deee	e
   f   fdZededee   de	e
   fd	       Zy
)TaskInputBuilderz?Builds task input payloads that optionally include attachments.attachment_storec                     || _         y )N)r   )selfr   s     =/Users/bowang/.openclaw/workspace/ChatDev/utils/task_input.py__init__zTaskInputBuilder.__init__   s
     0    promptattachment_pathsreturnc                    |s|S g }|D ]  }t        |      j                         }|j                         st        d|       t	        j
                  t        |            \  }}| j                  j                  |t        j                  |      |j                  |ddt        |      d      }|j                  |j                                 | j                  ||      S )NzAttachment not found: user_uploadcli_attachment)sourceoriginoriginal_path)kinddisplay_name	mime_typeextra)r   
expanduserexistsFileNotFoundError	mimetypes
guess_typestrr   register_filer	   from_mime_typenameappendas_message_blockbuild_from_blocks)	r   r   r   blocksraw_path	file_pathr   _records	            r   build_from_file_pathsz&TaskInputBuilder.build_from_file_paths   s    
  M%'(HX113I##%'*@(LMM$//I?LIq**88%44Y?&^^#+.%(^ 9 
F MM&1134! )$ %%ff55r   r-   c                     g }| r$|j                  t        j                  |              |j                  |       |s$|j                  t        j                  d             t	        t
        j                  |ddi      gS )N r   TASK)rolecontentmetadata)r*   r   
text_blockextendr   r
   USER)r   r-   final_blockss      r   r,   z"TaskInputBuilder.build_from_blocks/   ss    +- 7 7 ?@F# 7 7 ;< %%$"F+
 	
r   N)__name__
__module____qualname____doc__r   r   r&   r   r   r   r   r2   staticmethodr   r,    r   r   r   r      sv    I1 166 #3-6 
sDM!	"	6< 
# 
x/E 
$w- 
 
r   r   )r@   r$   pathlibr   typingr   r   r   entity.messagesr   r   r	   r
   utils.attachmentsr   r   rB   r   r   <module>rG      s'    I   ( ( P P -2
 2
r   