
    i'                    0   S SK Jr  S SKJrJrJr  S SKJrJrJ	r	  S SK
JrJrJrJrJr  S SKJr   " S S\5      r " S S	\5      r " S
 S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r\\   rg)    )annotations)
dict_items	dict_keysdict_values)AnyTypeOptional)	BaseModel
ConfigDictFieldPrivateAttrmodel_serializer)Enumc                    ^  \ rS rSr% Sr\" SS9r\" \S9r	S\
S'   SU 4S jjrSU 4S	 jjrSU 4S
 jjrSS jrSS jrSS S jjrS!S jrS"S jrS#S jrS$S jrS%S jrS&S jrS'S jrS(S jr\" SS9S)S j5       rSrU =r$ )*DictLikeModel   a  
Base Pydantic model class that mimics a dict interface for dynamic fields.

Known, typed fields behave like regular Pydantic attributes. Any extra
keyword arguments are stored in an internal dict and can be accessed through
both attribute and mapping semantics. This hybrid model enables flexible
event payloads while preserving validation for declared fields.

PrivateAttr:
    _data (dict[str, Any]): Underlying Python dict for dynamic fields.
T)arbitrary_types_allowed)default_factorydict[str, Any]_datac                j  > 0 n0 n0 nUR                  5        H=  u  pVXPR                  R                  ;   a  XbU'   M$  XPR                  ;   a  XcU'   M9  XdU'   M?     [        T	U ]  " S0 UD6  UR                  5        H  u  px[        T	U ]  Xx5        M     U(       a  U R                  R                  U5        gg)zK
__init__.

NOTE: fields and private_attrs are pulled from params by name.
N )	items	__class__model_fields__private_attributes__super__init____setattr__r   update)
selfparamsfieldsprivate_attrsdatakvprivate_attrvaluer   s
            J/home/james-whalen/.local/lib/python3.13/site-packages/workflows/events.pyr   DictLikeModel.__init__#   s     LLNDANN///q	111#$a Q # 	"6"#0#6#6#8LG4 $9JJd#     c                   > XR                   ;   d  XR                  R                  ;   a  [        TU ]  U5      $ XR
                  ;  a&  [        SU R                  R                   SU S35      eU R
                  U   $ )N'z' object has no attribute ')r   r   r   r   __getattr__r   AttributeError__name__)r!   _DictLikeModel__namer   s     r*   r/   DictLikeModel.__getattr__:   sv    1114447&v..ZZ'$//00KF8STU  ::f%%r,   c                   > XR                   ;   d  XR                  R                  ;   a  [        TU ]  X5        g U R
                  R                  X5        g N)r   r   r   r   r   r   __setitem__)r!   namer)   r   s      r*   r   DictLikeModel.__setattr__G   s=    ...$..:U:U2UG,JJ""4/r,   c                     U R                   U   $ r5   r   r!   keys     r*   __getitem__DictLikeModel.__getitem__M   s    zz#r,   c                     X R                   U'   g r5   r:   )r!   r<   r)   s      r*   r6   DictLikeModel.__setitem__P   s    

3r,   c                8    U R                   R                  X5      $ r5   )r   get)r!   r<   defaults      r*   rB   DictLikeModel.getS   s    zz~~c++r,   c                    XR                   ;   $ r5   r:   r;   s     r*   __contains__DictLikeModel.__contains__V   s    jj  r,   c                6    U R                   R                  5       $ r5   )r   keysr!   s    r*   rI   DictLikeModel.keysY   s    zz  r,   c                6    U R                   R                  5       $ r5   )r   valuesrJ   s    r*   rM   DictLikeModel.values\   s    zz  ""r,   c                6    U R                   R                  5       $ r5   )r   r   rJ   s    r*   r   DictLikeModel.items_   s    zz!!r,   c                ,    [        U R                  5      $ r5   )lenr   rJ   s    r*   __len__DictLikeModel.__len__b   s    4::r,   c                ,    [        U R                  5      $ r5   )iterr   rJ   s    r*   __iter__DictLikeModel.__iter__e   s    DJJr,   c                    U R                   $ r5   r:   )r!   argskwargss      r*   to_dictDictLikeModel.to_dicth   s    zzr,   c                    g)z.Make test `if event:` pass on Event instances.Tr   rJ   s    r*   __bool__DictLikeModel.__bool__k   s    r,   wrapmodec                V    U" U 5      nU R                   (       a  U R                   US'   U$ )Nr   r:   r!   handlerr%   s      r*   custom_model_dumpDictLikeModel.custom_model_dumpo   s$    t}:: JJDMr,   r   r"   r   )r2   strreturnr   )r7   rj   r)   r   rk   None)r<   rj   rk   r   )r<   rj   r)   r   rk   rl   r5   )r<   rj   rC   r   rk   r   )r<   rj   rk   bool)rk   z'dict_keys[str, Any]')rk   z'dict_values[str, Any]')rk   z'dict_items[str, Any]')rk   intrk   r   )rZ   r   r[   r   rk   r   )rk   rm   rf   r   rk   r   )r1   
__module____qualname____firstlineno____doc__r   model_configr   dictr   __annotations__r   r/   r   r=   r6   rB   rF   rI   rM   r   rS   rW   r\   r_   r   rg   __static_attributes____classcell__r   s   @r*   r   r      s    
 d;L'=E>=$.&0 ,!!#"  6" #r,   r   c                  0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )Eventx   af  
Base class for all workflow events.

Events are light-weight, serializable payloads passed between steps.
They support both attribute and mapping access to dynamic fields.

Examples:
    Subclassing with typed fields:

    ```python
    from pydantic import Field

    class CustomEv(Event):
        score: int = Field(ge=0)

    e = CustomEv(score=10)
    print(e.score)
    ```

See Also:
    - [StartEvent][workflows.events.StartEvent]
    - [StopEvent][workflows.events.StopEvent]
    - [InputRequiredEvent][workflows.events.InputRequiredEvent]
    - [HumanResponseEvent][workflows.events.HumanResponseEvent]
c                &   > [         TU ]  " S0 UD6  g )Nr   r   r   )r!   r"   r   s     r*   r   Event.__init__   s    "6"r,   r   ri   )r1   rq   rr   rs   rt   r   rx   ry   rz   s   @r*   r|   r|   x   s    4# #r,   r|   c                      \ rS rSrSrSrg)
StartEvent   z9Implicit entry event sent to kick off a `Workflow.run()`.r   Nr1   rq   rr   rs   rt   rx   r   r,   r*   r   r      s    Cr,   r   c                     ^  \ rS rSr% Sr\" SS9rS\S'   SSU 4S jjjrSS jr	\
SS	 j5       r\" S
S9SS j5       rSS jrSS jrSrU =r$ )	StopEvent   aC  Terminal event that signals the workflow has completed.

The `result` property contains the return value of the workflow run. When a
custom stop event subclass is used, the workflow result is that event
instance itself.

Examples:
    ```python
    # default stop event: result holds the value
    return StopEvent(result={"answer": 42})
    ```

    Subclassing to provide a custom result:

    ```python
    class MyStopEv(StopEvent):
        pass

    @step
    async def my_step(self, ctx: Context, ev: StartEvent) -> MyStopEv:
        return MyStopEv(result={"answer": 42})
N)rC   r   _resultc                *   > [         TU ]  " SSU0UD6  g )Nr   r   r   )r!   resultr[   r   s      r*   r   StopEvent.__init__   s    2262r,   c                    U R                   $ )zBThis can be overridden by subclasses to return the desired result.r   rJ   s    r*   _get_resultStopEvent._get_result   s    ||r,   c                "    U R                  5       $ r5   )r   rJ   s    r*   r   StopEvent.result   s    !!r,   ra   rb   c                N    U" U 5      nU R                   b  U R                   US'   U$ )Nr   r   re   s      r*   rg   StopEvent.custom_model_dump   s'    t}<<#!\\DNr,   c                    0 U R                   EU R                  5       EnUR                  " 5        VVs/ s H  u  p#U SU< 3PM     nnnSR                  U5      nU R                  R
                   SU S3$ s  snnf )N=z, ())r   
model_dumpr   joinr   r1   )r!   r   r&   r'   partsdict_strs         r*   __repr__StopEvent.__repr__   sx    8

8doo&78
*4*:*:*<=*<$!A3au*<=99U#..))*!H:Q77 >s   A7c                ,    [        U R                  5      $ r5   )rj   r   rJ   s    r*   __str__StopEvent.__str__   s    4<<  r,   r   r5   )r   r   r[   r   rk   rl   ro   rp   )rk   rj   )r1   rq   rr   rs   rt   r   r   rw   r   r   propertyr   r   rg   r   r   rx   ry   rz   s   @r*   r   r      sd    . t,GS,3 3 " " 6" #8! !r,   r   c                      \ rS rSrSrSrg)InputRequiredEvent   a  Emitted when human input is required to proceed.

Automatically written to the event stream if returned from a step.

If returned from a step, it does not need to be consumed by other steps and will pass validation.
It's expected that the caller will respond to this event and send back a [HumanResponseEvent][workflows.events.HumanResponseEvent].

Use this directly or subclass it.

Typical flow: a step returns `InputRequiredEvent`, callers consume it from
the stream and send back a [HumanResponseEvent][workflows.events.HumanResponseEvent].

Examples:
    ```python
    from workflows.events import InputRequiredEvent, HumanResponseEvent

    class HITLWorkflow(Workflow):
        @step
        async def my_step(self, ev: StartEvent) -> InputRequiredEvent:
            return InputRequiredEvent(prefix="What's your name? ")

        @step
        async def my_step(self, ev: HumanResponseEvent) -> StopEvent:
            return StopEvent(result=ev.response)
    ```
r   Nr   r   r,   r*   r   r      s    r,   r   c                      \ rS rSrSrSrg)HumanResponseEvent   a3  Carries a human's response for a prior input request.

If consumed by a step and not returned by another, it will still pass validation.

Examples:
    ```python
    from workflows.events import InputRequiredEvent, HumanResponseEvent

    class HITLWorkflow(Workflow):
        @step
        async def my_step(self, ev: StartEvent) -> InputRequiredEvent:
            return InputRequiredEvent(prefix="What's your name? ")

        @step
        async def my_step(self, ev: HumanResponseEvent) -> StopEvent:
            return StopEvent(result=ev.response)
    ```
r   Nr   r   r,   r*   r   r      s    r,   r   c                      \ rS rSrSrSrg)InternalDispatchEventi  a  
InternalDispatchEvent is a special event type that exposes processes running inside workflow, even if the user did not explicitly expose them by setting, e.g., `ctx.write_event_to_stream(`.

Examples:
    ```python
    wf = ExampleWorkflow()
    handler = wf.run(message="Hello, who are you?")

    async for ev in handler.stream_event(expose_internal=True):
        if isinstance(ev, InternalDispatchEvent):
            print(type(ev), ev)
    ```
r   Nr   r   r,   r*   r   r     s     	r,   r   c                       \ rS rSrSrSrSrSrg)	StepStatei  	preparingrunningnot_runningr   N)r1   rq   rr   rs   	PREPARINGRUNNINGNOT_RUNNINGrx   r   r,   r*   r   r     s    IGKr,   r   c                      \ rS rSr% Sr\" SS9rS\S'   \" SS9rS\S	'   \" S
S9r	S\S'   \" SS9r
S\S'   \" SSS9rS\S'   Srg)StepStateChangedi!  a  
StepStateChanged is a special event type that exposes internal changes in the state of the event, including whether the step is running or in progress, what worker it is running on and what events it takes as input and output, as well as changes in the workflow state.

Attributes:
    name (str): Name of the step
    step_state (StepState): State of the step ("running", "not_running", "in_progress", "not_in_progress", "exited")
    worker_id (str): ID of the worker that the step is running on
    input_event_name (str): Name of the input event
    output_event_name (Optional[str]): Name of the output event
    context_state (dict[str, Any]): Snapshot of the current workflow state
zName of the step)descriptionrj   r7   zXState of the step ('running', 'not_running', 'in_progress', 'not_in_progress', 'exited')r   
step_statez,ID of the worker that the step is running on	worker_idzName of the input eventinput_event_namezName of the output eventN)r   rC   zOptional[str]output_event_namer   )r1   rq   rr   rs   rt   r   r7   rw   r   r   r   r   rx   r   r,   r*   r   r   !  sg    
 "45D#5!nJ	  'UVIsV!.GHcH',.(} r,   r   N)
__future__r   _collections_abcr   r   r   typingr   r   r	   pydanticr
   r   r   r   r   enumr   r   r|   r   r   r   r   r   r   r   	EventTyper   r,   r*   <module>r      s    # ? ? & &  bI bJ#M #>D D6! 6!r : *	E 	$   , 0 K	r,   