
    i                       S SK Jr  S SKrS SKJr  S SK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JrJrJr  S SKJrJr  S S	KJ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  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,  S SK-J.r.J/r/J0r0J1r1J2r2J3r3  S SK4J5r5  S SK6J7r7J8r8J9r9J:r:J;r;J<r<J=r=J>r>J?r?  S SK@JArAJBrBJCrCJDrD  S SKEJFrF  S SKGJHrH  S SKIJJrK  SSKLJMrM  S SKNJOrOJPrPJQrQ  \R                  " 5       rS " S S5      rT\ " S  S!5      5       rU " S" S#\V5      rW\ " S$ S%5      5       rX\YS&:X  a  S SKZrZ\ZR                  " S'S(9r\\\R                  S)\^S*S+S,9  \\R                  5       r`\T" 5       ra\aR                  5       rc\d" \`R                  S-5       rf\R                  " \cS.\fS/9  SSS5        \h" S0\`R                   35        gg! , (       d  f       N%= f)1    )annotationsN)asynccontextmanager)	dataclass)version)Path)AnyAsyncGeneratorCallable	Awaitable)datetimetimezone)instrument_tags)	Starlette)HTTPException)
Middleware)CORSMiddleware)Request)JSONResponseStreamingResponse)Route)SchemaGenerator)StaticFiles)ContextWorkflow)EventInternalDispatchEvent
StartEvent	StepStateStepStateChanged	StopEvent)WorkflowHandler)	CancelHandlerResponseHandlerDataHandlersListResponseHealthResponseSendEventResponseWorkflowEventsListResponseWorkflowGraphResponseWorkflowSchemaResponseis_status_completed)AbstractWorkflowStoreHandlerQueryPersistentHandlerStatus)MemoryWorkflowStore)
RunResultT)_nanoid   )_extract_workflow_structure)EventValidationErrorEventEnvelopeWithMetadataEventEnvelopec                     \ rS rSrSSSS/S.     S"S jjr S#       S$S jjrS%S jr\S&S	 j5       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 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  S0         S1S jjr        S2S jrS3S jrS4S  jrS!r g)5WorkflowServerG   Ng      ?   )
middlewareworkflow_storepersistence_backoffc                 ^  0 T l         0 T l        0 T l        0 T l        0 T l        Ub  UO	[        5       T l        [        [        5      R                  S-  T l
        [        U5      T l        U=(       d    [        [        SS/S/SS9/T l        [!        ST R"                  S/S9[!        S	T R$                  S
/S9[!        ST R&                  S
/S9[!        ST R(                  S/S9[!        ST R*                  S/S9[!        ST R,                  S/S9[!        ST R.                  S
/S9[!        ST R0                  S/S9[!        ST R2                  S/S9[!        ST R4                  S/S9[!        ST R6                  S
/S9[!        ST R8                  S/S9[!        ST R:                  S/S9/T l        [>        SU 4S jj5       n[A        T R<                  T R                  US9T l!        T RB                  RE                  S[G        T R                  SS9SS9  g )Nstaticz.**T)allow_origin_regexallow_methodsallow_headersallow_credentialsz
/workflowsGET)methodsz/workflows/{name}/runPOSTz/workflows/{name}/run-nowaitz/workflows/{name}/schemaz/results/{handler_id}z/events/{handler_id}z/healthz	/handlersz/handlers/{handler_id}z/handlers/{handler_id}/cancelz /workflows/{name}/representationz/workflows/{name}/eventsc                  >#    TR                  5        IS h  vN   S 7v   S S S 5      IS h  vN   g  N N! , IS h  vN  (       d  f       g = f7fN)contextmanager)appselfs    Q/home/james-whalen/.local/lib/python3.13/site-packages/workflows/server/server.pylifespan)WorkflowServer.__init__.<locals>.lifespan   s,     **,, -,,,,,s:   A3A7A5AAAA A
A)routesr;   rN   /)	directoryhtmlui)rK   name)rK   r   returnzAsyncGenerator[None, None])$
_workflows_additional_events	_contexts	_handlers_resultsr/   _workflow_storer   __file__parent_assets_pathlist_persistence_backoffr   r   _middlewarer   _list_workflows_run_workflow_run_workflow_nowait_get_events_schema_get_workflow_result_stream_events_post_event_health_check_get_handlers_get_workflow_handler_cancel_handler_get_workflow_representation_list_workflow_events_routesr   r   rK   mountr   )rL   r;   r<   r=   rN   s   `    rM   __init__WorkflowServer.__init__H   s^    02GI-/68/1,8N>Q>S 	 !N11H<$()<$=!% 	
#'"e"e"&	*
 $$
 '""
 .))
 *''
 '))
 &##
 &  
 ""
 ""
 (**
 /$$
 211
 ***{B
H 
	 
	 <<''
 	[4+<+<4Ht 	 	
    c                D    X R                   U'   Ub  X0R                  U'   g g rI   )rW   rX   )rL   rU   workflowadditional_eventss       rM   add_workflowWorkflowServer.add_workflow   s)     !)(,=##D) )rt   c                x  #    U R                   R                  [        S/[        U R                  R                  5       5      S95      I Sh  vN nU Hn  nU R                  UR                     n U R                  [        UR                  US9UR                  [        R                  " X2R                  S9S9I Sh  vN   Mp     U $  Nz N! [         a  n[        R                  SUR                   SUR                   S	U 35         [         R"                  " [$        R&                  5      nU R                   R)                  [+        UR                  UR                  S
UR,                  [/        U5      SUR0                  UUUR                  S9
5      I Sh  vN    O! [         a     Of = f SnAGM`  SnAff = f7f)zPResumes previously running workflows, if they were not complete at last shutdownrunning	status_inworkflow_name_inNrU   rv   rv   data)rv   
handler_idcontextzFailed to resume handler z for workflow z: failed
r   workflow_namestatusrun_iderrorresult
started_at
updated_atcompleted_atctx)r\   queryr,   r`   rW   keysr   _start_workflow_NamedWorkflowr   r   	from_dictr   	Exceptionloggerr   r   nowr   utcupdater-   r   strr   )rL   handlers
persistentrv   er   s         rM   startWorkflowServer.start   s    --33$+T__=Q=Q=S8T
 

 #Jz'?'?@H**+'55  *44#--xnnU +    #F Q
  /
0E0E/FnU_UmUmTnnpqrpst",,x||4C..55)'1'<'<*4*B*B#+#-#4#4"%a&#''1'<'<'*), *   ! /s   A	F:C"F:/AC
;C<C
 F:C


F72F2BFFFF2
F(%F2'F((F2+F:2F77F:c                  #    U R                  5       I Sh  vN    U 7v   U R                  5       I Sh  vN   g N# N! U R                  5       I Sh  vN    f = f7f)z9Use this server as a context manager to start and stop itNr   stoprL   s    rM   rJ   WorkflowServer.contextmanager   sH      jjl	J))+	 	 $))+s<   A:A> A<AAAAAAc                  #    [         R                  S[        U R                  5       S35        [        R
                  " [        U R                  R                  5       5       Vs/ s H  oR                  U5      PM     sn6 I S h  vN   U R                  R                  5         U R                  R                  5         g s  snf  N>7f)Nz*Shutting down Workflow server. Cancelling z
 handlers.)r   infolenrZ   asynciogatherr`   values_close_handlerclearr[   rL   handlers     rM   r   WorkflowServer.stop   s     8T^^9L8MZX	
 nn:>t~~?T?T?V:WX:Ww!!'*:WX
 	
 	
 	 Y	
s   A"C$B?>CC?Cc           
     "  #    U=(       d    0 n[         R                  " U R                  4XS.UD6n[         R                  " U5      n[        R                  SU SU UR                  SS5       35        UR                  5       I Sh  vN   g N7f)zRun the server.)hostportz#Starting Workflow server at http://:	root_pathrQ   N)uvicornConfigrK   Serverr   r   getserve)rL   r   r   uvicorn_configconfigservers         rM   r   WorkflowServer.serve  s|      (-2QtQ.Q'1$q~?Q?QR]_b?c>de	
 llns   BBBBc                <   U R                   n[        SS[        S5      S.SSSS0SSS	0S
.SS	0SS	0S.SS/S.SSS	0SS	0S	SS.S	/ SQS.S	SS.S	SSS.S	SSS.S	SS.SSS0SS0/S.S.	/ SQS.SSSSS0S
.0S/S.S.0S.5      nUR                  UR                  5      $ ) Nz3.0.0zWorkflows APIzllama-index-workflows)titler   schemasobjecttypearraystring)r   items)valuetypesr   qualified_namer   )r   
propertiesrequiredT)r   nullable)r{   	completedr   	cancelled)r   enumz	date-time)r   format)r   r   r   zWorkflow result valuez$refz.#/components/schemas/EventEnvelopeWithMetadatanull)descriptiononeOf	r   r   r   r   r   r   r   r   r   )r   r   r   r   r   z#/components/schemas/Handler)r5   HandlerHandlersList)openapir   
components)rK   r   r   
get_schemarP   )rL   rK   gens      rM   openapi_schemaWorkflowServer.openapi_schema  sQ   hh",&'>?
 $,*0();29VXDV)W)/(:3982D	+ *1&(9	6 %-/5x.@28(1C3;*N,4-&+" 8@;.W,4.904/" -5.9041"
 3;)M3J -34d)* *0(8	.&+"3"+F)K+$Z %- *,3.46T-U-"+ *4	)oA CJL
\ ~~cjj))rt   c                J   #    [        [        SS9R                  5       5      $ 7f)aR  
---
summary: Health check
description: Returns the server health status.
responses:
  200:
    description: Successful health check
    content:
      application/json:
        schema:
          type: object
          properties:
            status:
              type: string
              example: healthy
          required: [status]
healthyr   )r   r%   
model_dump)rL   requests     rM   rj   WorkflowServer._health_checki  s      $ N)<GGIJJs   !#c                j   #    [        U R                  R                  5       5      n[        SU05      $ 7f)as  
---
summary: List workflows
description: Returns the list of registered workflow names.
responses:
  200:
    description: List of workflows
    content:
      application/json:
        schema:
          type: object
          properties:
            workflows:
              type: array
              items:
                type: string
          required: [workflows]
	workflows)r`   rW   r   r   )rL   r   workflow_namess      rM   rc   WorkflowServer._list_workflows}  s.     & doo2245[.9::s   13c                  #    SUR                   ;  a
  [        SSS9eUR                   S   nX R                  ;  a  [        SSU S3S9eU R                  U   R                  nU R                  R                  U/ 5      nU(       a  UR                  U5        / nU H"  nUR                  UR                  5       5        M$     [        [        US9R                  5       5      $ 7f)	aL  
---
summary: List workflow events
description: Returns the list of registered workflow event schemas.
parameters:
  - in: path
    name: name
    required: true
    schema:
      type: string
    description: Registered workflow name.
responses:
  200:
    description: List of workflow event schemas
    content:
      application/json:
        schema:
          type: object
          properties:
            events:
              type: array
              description: List of workflow event JSON schemas
              items:
                type: object
          required: [events]
rU     zname param is required)status_codedetail  z
Workflow 'z' not found)events)path_paramsr   rW   r   rX   r   extendappendmodel_json_schemar   r'   r   )rL   r   rU   r   rw   
event_objsevents          rM   ro   $WorkflowServer._list_workflow_events  s     6 ,,,C8PQQ""6*&C*TF+8VWW&-- 3377bAMM+,
Ee5578  6jITTVWWs   CC c                J  #    U R                  U5      nU R                  XR                  UR                  5      I Sh  vN u  p4nUb&  UR                  R                  R                  U5      nOSn U R                  [        UR                  UR                  S9UUUS9I Sh  vN nUR                  n UI Sh  vN   Sn	UR                  b   UR                  I Sh  vN   U R                  U5      I Sh  vN   [        UR                  5       R!                  5       U	S	9$  N N Nk! [         a#  n
Sn	[        R                  SU
 3SS9   Sn
A
NSn
A
ff = f Ny! [         a     Nf = f Nr! [         a+  n
Sn	[        R                  SU
 3SS9  [#        SU
 3U	S
9eSn
A
ff = f7f)ap  
---
summary: Run workflow (wait)
description: |
  Runs the specified workflow synchronously and returns the final result.
  The request body may include an optional serialized start event, an optional
  context object, and optional keyword arguments passed to the workflow run.
parameters:
  - in: path
    name: name
    required: true
    schema:
      type: string
    description: Registered workflow name.
requestBody:
  required: false
  content:
    application/json:
      schema:
        type: object
        properties:
          start_event:
            type: object
            description: 'Plain JSON object representing the start event (e.g., {"message": "..."}).'
          context:
            type: object
            description: Serialized workflow Context.
          handler_id:
            type: string
            description: Workflow handler identifier to continue from a previous completed run.
          kwargs:
            type: object
            description: Additional keyword arguments for the workflow.
responses:
  200:
    description: Workflow completed successfully
    content:
      application/json:
        schema:
          $ref: '#/components/schemas/Handler'
  400:
    description: Invalid start_event payload
  404:
    description: Workflow or handler identifier not found
  500:
    description: Error running workflow or invalid request body
Nr   rv   r   r   start_event     zError running workflow: Texc_infor   r   r   )_extract_workflow_extract_run_paramsrv   rU   start_event_classmodel_validater   r   run_handlerr   r   r   taskr   r   to_response_modelr   r   )rL   r   rv   r   r   r   input_evwrapperr   r   r   s              rM   rd   WorkflowServer._run_workflow  s    ` ))'2151I1I&&2
 ,
(j "((::II+VHH	 00'X]]XEVEVW%$	 1  G ))GL ||'!,,&&
 %%g...))+668f A,
  L7s;dKL
 '   /
  	FLL3A37$LG1!56 	s   ;F#D!2F#11E+ "D##E+ 4D' 9D%:D'  E+ E EE "E+ 6E)7)E+  F##E+ %D' '
E1E
E+ EE+ E 
E&#E+ %E&&E+ +
F 5&FF  F#c                |  #    U R                  U5      n UR                  R                  R                  5       n UR                  R                  R                  5       n[        [        X5S9R                  5       5      $ ! [         a  n[        SU 3SS9eSnAff = f! [         a  n[        SU 3SS9eSnAff = f7f)ak  
---
summary: Get JSON schema for start event
description: |
  Gets the JSON schema of the start and stop events from the specified workflow and returns it under "start" (start event) and "stop" (stop event)
parameters:
  - in: path
    name: name
    required: true
    schema:
      type: string
    description: Registered workflow name.
requestBody:
  required: false
responses:
  200:
    description: JSON schema successfully retrieved for start event
    content:
      application/json:
        schema:
          type: object
          properties:
            start:
              description: JSON schema for the start event
            stop:
              description: JSON schema for the stop event
          required: [start, stop]
  404:
    description: Workflow not found
  500:
    description: Error while getting the JSON schema for the start or stop event
z2Error getting schema of start event for workflow: r   r   Nz1Error getting schema of stop event for workflow: r   )
r   rv   r   r   r   r   stop_event_classr   r)   r   )rL   r   rv   start_event_schemar   stop_event_schemas         rM   rf   !WorkflowServer._get_events_schema  s     B ))'2	!)!2!2!D!D!V!V!X	 ( 1 1 B B T T V "(jl
 	
  	KA3O 	  	J1#N 	sE   B<$A> $B  B<>
BBBB<
B9'B44B99B<c                   #    U R                  U5      n [        UR                  5      n[        [        UR                  5       S9R                  5       5      $ ! [         a  n[	        SU 3SS9eSnAff = f7f)a  
---
summary: Get the representation of the workflow
description: |
  Get the representation of the workflow as a directed graph in JSON format
parameters:
  - in: path
    name: name
    required: true
    schema:
      type: string
    description: Registered workflow name.
requestBody:
  required: false
responses:
  200:
    description: JSON representation successfully retrieved
    content:
      application/json:
        schema:
          type: object
          properties:
            graph:
              description: the elements of the JSON representation of the workflow
          required: [graph]
  404:
    description: Workflow not found
  500:
    description: Error while getting JSON workflow representation
z2Error while getting JSON workflow representation: r   r   N)graph)	r   r3   rv   r   r   r   r(   r  r   )rL   r   rv   workflow_graphr   s        rM   rn   +WorkflowServer._get_workflow_representationR  s     > ))'2	89J9JKN !(H(H(JKVVX
 	
  	KA3O 	s'   A7A .A7
A4"A//A44A7c                  #    U R                  U5      nU R                  XR                  UR                  5      I Sh  vN u  p4nUb&  UR                  R                  R                  U5      nOSn U R                  [        UR                  UR                  S9UUUS9I Sh  vN n[        UR                  5       R                  5       5      $  N N-! [         a  n[        SU 3SS9eSnAff = f7f)a  
---
summary: Run workflow (no-wait)
description: |
  Starts the specified workflow asynchronously and returns a handler identifier
  which can be used to query results or stream events.
parameters:
  - in: path
    name: name
    required: true
    schema:
      type: string
    description: Registered workflow name.
requestBody:
  required: false
  content:
    application/json:
      schema:
        type: object
        properties:
          start_event:
            type: object
            description: 'Plain JSON object representing the start event (e.g., {"message": "..."}).'
          context:
            type: object
            description: Serialized workflow Context.
          handler_id:
            type: string
            description: Workflow handler identifier to continue from a previous completed run.
          kwargs:
            type: object
            description: Additional keyword arguments for the workflow.
responses:
  200:
    description: Workflow started
    content:
      application/json:
        schema:
          $ref: '#/components/schemas/Handler'
  400:
    description: Invalid start_event payload
  404:
    description: Workflow or handler identifier not found
Nr   r   zInitial persistence failed: r   r   )r   r   rv   rU   r   r   r   r   r   r   r   r  r   )	rL   r   rv   r   r   r   r  r  r   s	            rM   re   #WorkflowServer._run_workflow_nowait}  s     Z ))'2151I1I&&2
 ,
(j "((::II+VHH	 00'X]]XEVEVW%$	 1  G G557BBDEE+,
  	5aS9s 	sE   ;C1C2C111C "C#C '(C1C 
C.C))C..C1c                  #    U R                   R                  U5      nUcV  U R                  R                  [	        U/S95      I S h  vN nU(       d
  [        SSS9eUS   n[        R                  U5      $ UR                  R                  5       (       a2  UR                  b%   UR                  I S h  vN   UR                  5       $ UR                  5       $  N N&! [         a     UR                  5       $ f = f7f)Nhandler_id_inHandler not foundr   r   r   )rZ   r   r\   r   r,   r   _WorkflowHandlerhandler_data_from_persistentr   doner   r   r  )rL   r   r  foundexistings        rM   _load_handlerWorkflowServer._load_handler  s     ..$$Z0?..44J<8 E #+>CPPQxH#@@JJ""''))gll.F!,,&&
 ,,..7,,.. '  ,,..	sI   AC;CAC;$C 3C4C 8!C;C 
C8&C;7C88C;c                  #    UR                   S   nU(       d
  [        SSS9eU R                  U5      I Sh  vN nUR                  S;   a  SOUR                  S:X  a  S	OS
nUR	                  5       nUR
                  (       d  SUS'   OZUR
                  R                  nUS:X  a%  UR
                  R                  R                  S5      OUR
                  R                  US'   [        XTS9$  N7f)a  
---
summary: Get workflow result (deprecated)
description: |
  Deprecated. Use GET /handlers/{handler_id} instead. Returns the final result of an asynchronously started workflow, if available.
parameters:
  - in: path
    name: handler_id
    required: true
    schema:
      type: string
    description: Workflow run identifier returned from the no-wait run endpoint.
deprecated: true
responses:
  200:
    description: Result is available
    content:
      application/json:
        schema:
          type: object
  202:
    description: Result not ready yet
    content:
      application/json:
        schema:
          type: object
  404:
    description: Handler not found
  500:
    description: Error computing result
    content:
      text/plain:
        schema:
          type: string
r   Handler ID is requiredr   r   Nr{      r   r   r   r   zworkflows.events.StopEventr   )
r   r   r  r   r   r   r   r   r   r   )rL   r   r   handler_datar   response_modelr   s          rM   rg   #WorkflowServer._get_workflow_result  s     H ((6
'?SQQ!//
;; ""i/  ""k1  	 &002 ""'+N8$&&55D 77 ##))--h7!((.. 8$
 N??) <s   5C.C,B5C.c                   #    UR                   S   nU(       d
  [        SSS9eU R                  U5      I Sh  vN nUR                  S;   a  SOUR                  S:X  a  S	OS
n[	        UR                  5       US9$  NB7f)a  
---
summary: Get workflow handler
description: Returns the final result of an asynchronously started workflow, if available
parameters:
  - in: path
    name: handler_id
    required: true
    schema:
      type: string
    description: Workflow run identifier returned from the no-wait run endpoint.
responses:
  200:
    description: Result is available
    content:
      application/json:
        schema:
          $ref: '#/components/schemas/Handler'
  202:
    description: Result not ready yet
    content:
      application/json:
        schema:
          $ref: '#/components/schemas/Handler'
  404:
    description: Handler not found
  500:
    description: Error computing result
    content:
      text/plain:
        schema:
          type: string
r   r  r   r   Nr{   r  r   r   r   r   )r   r   r  r   r   r   )rL   r   r   r  r   s        rM   rl   $WorkflowServer._get_workflow_handler  s     D ((6
'?SQQ!//
;; ""i/  ""k1  	 L3356JJ <s   5A<A:AA<c                D  ^
^^^#    UR                   S   nUR                  R                  SS5      R                  5       nUR                  R                  SS5      R                  5       S:H  mUR                  R                  SS5      R                  5       S:H  mUR                  R                  SS5      R                  5       S:H  m [	        U5      nU R                  R                  U5      nUc[  U R                  R                  [        U/S95      I Sh  vN nU(       a  US   R                  nUS;   a
  [        SSS9e[        SSS9eUR                  R                  5       (       a6  UR                  b)  UR                  R                  5       (       a
  [        SSS9eT(       a  SOSn UR!                  US9I Sh  vN m
SU
UUU4S jjn	[%        U	" U5      US9$ ! [
         a    [        S	U S
3SS9ef = f N N=! ["         a  n[        SU S3SS9UeSnAff = f7f)a	  
---
summary: Stream workflow events
description: |
  Streams events produced by a workflow execution. Events are emitted as
  newline-delimited JSON by default, or as Server-Sent Events when `sse=true`.
  Event data is returned as an envelope that preserves backward-compatible fields
  and adds metadata for type-safety on the client:
  {
    "value": <pydantic serialized value>,
    "types": [<class names from MRO excluding the event class and base Event>],
    "type": <class name>,
    "qualified_name": <python module path + class name>,
  }

  Event queue is mutable. Elements are added to the queue by the workflow handler, and removed by any consumer of the queue.
  The queue is protected by a lock that is acquired by the consumer, so only one consumer of the queue at a time is allowed.

parameters:
  - in: path
    name: handler_id
    required: true
    schema:
      type: string
    description: Identifier returned from the no-wait run endpoint.
  - in: query
    name: sse
    required: false
    schema:
      type: boolean
      default: true
    description: If false, as NDJSON instead of Server-Sent Events.
  - in: query
    name: include_internal
    required: false
    schema:
      type: boolean
      default: false
    description: If true, include internal workflow events (e.g., step state changes).
  - in: query
    name: acquire_timeout
    required: false
    schema:
      type: number
      default: 1
    description: Timeout for acquiring the lock to iterate over the events.
  - in: query
    name: include_qualified_name
    required: false
    schema:
      type: boolean
      default: true
    description: If true, include the qualified name of the event in the response body.
responses:
  200:
    description: Streaming started
    content:
      text/event-stream:
        schema:
          type: object
          description: Server-Sent Events stream of event data.
          properties:
            value:
              type: object
              description: The event value.
            type:
              type: string
              description: The class name of the event.
            types:
              type: array
              description: Superclass names from MRO (excluding the event class and base Event).
              items:
                type: string
            qualified_name:
              type: string
              description: The qualified name of the event.
          required: [value, type]
  404:
    description: Handler not found
r   acquire_timeout1include_internalfalsetrueinclude_qualified_namessezInvalid acquire_timeout: ''r   r   Nr  r   >   r   r   r   zHandler is completed   r  r   ztext/event-streamzapplication/x-ndjsontimeout#No lock available to acquire after 	s timeout  c               &  >#    T  S h  vN nT(       d  [        U[        5      (       a  M'  [        R                  " UTS9nUR	                  5       nT(       a
  SU S37v   OU S37v   [
        R                  " S5      I S h  vN   M   N N
 g 7f)N)r)  zdata: z


r   )
isinstancer   r5   
from_eventmodel_dump_jsonr   sleep)r   r   envelopepayload	generatorr&  r)  r*  s       rM   event_stream3WorkflowServer._stream_events.<locals>.event_stream  s     ( 'e'Ju>S,T,T4??2H #224"7)400$IR.(mmA&&&' '  )s8   BBBBA6BBBBBB)
media_type)r   r  rV   zAsyncGenerator[str, None])r   query_paramsr   lowerfloat
ValueErrorr   rZ   r\   r   r,   r   queueemptyr   r  acquire_events_streamNoLockAvailabler   )rL   r   r   r.  r   	persistedr   r=  r   r;  r:  r&  r)  r*  s             @@@@rM   rh   WorkflowServer._stream_eventsD  s.    b ((6
&&**+<cBHHJ  $$%7AGGIVS 	   $$%=vFLLNRXX 	 ""&&uf5;;=G	GnG ..$$Z0?"2288J<8 I "1,,AA'/ESVWW':LL==  W\\%=',,BSBSBUBU  '=3OO -0(5K
	%;;G;LLI	' 	'  !g!6:NNa  	3G9A>C 	$ M 	<WIYO 	sb   CH G AH G;BH -G? ?G= G? H G88H =G? ?
H	HHH c                B  ^#    S
U4S jjnU" S5      nU" S5      n1 SknUb#  [        [        U5      R                  U5      5      OSnU R                  R	                  [        XdS95      I Sh  vN nU Vs/ s H  n[        UR                  UR                  UR                  UR                  UR                  (       a  UR                  R                  5       OSUR                  (       a  UR                  R                  5       OSUR                  (       a  UR                  R                  5       OSUR                  UR                   (       a   ["        R$                  " UR                   5      OSS9	PM     n	n['        [)        U	S	9R+                  5       5      $  GN*s  snf 7f)as  
---
summary: Get handlers
description: Returns workflow handlers, optionally filtered by query parameters.
parameters:
  - in: query
    name: status
    required: false
    schema:
      type: array
      items:
        type: string
        enum: [running, completed, failed, cancelled]
    style: form
    explode: true
    description: |
      Filter by handler status. Can be provided multiple times (e.g., status=running&status=failed)
  - in: query
    name: workflow_name
    required: false
    schema:
      type: array
      items:
        type: string
    style: form
    explode: true
    description: |
      Filter by workflow name. Can be provided multiple times (e.g., workflow_name=test&workflow_name=other)
responses:
  200:
    description: List of handlers
    content:
      application/json:
        schema:
          $ref: '#/components/schemas/HandlersList'
c                2  > [        TR                  R                  U 5      5      nU(       d'  TR                  R                  U 5      =(       d    SnU/nU Vs/ s H)  o3R	                  5       (       d  M  UR	                  5       PM+     nnU(       d  g U$ s  snf )N )r`   r>  getlistr   strip)
param_namer   singler   r   s       rM   _parse_list_param7WorkflowServer._get_handlers.<locals>._parse_list_param  sv    '..66zBCF --11*=C 17I;;=mekkmFIM Js   B4Br   r   >   r   r{   r   r   Nr|   rJ  r   )r   )rM  r   rV   zlist[str] | None)r`   setintersectionr\   r   r,   r#   r   r   r   r   r   	isoformatr   r   r   r   r5   r5  r   r$   r   )
rL   r   rO  status_valuesr~   allowed_status_valuesr}   persistent_handlershr   s
    `        rM   rk   WorkflowServer._get_handlers  sV    L		 *(3,_=.
 ( *+88GH 	 %)$8$8$>$>9P%
 
" )
 ) <<ooxxxx78||1<<11378||1<<113;<>>Q^^557tgg88 1;;AHHE ) 	 
  0%@KKMNN'

s%   A*F-F.F6C?F5#FFc                ,  #    UR                   S   nU R                  R                  U5      nUb$  [        UR                  5      (       a
  [        SSS9eUc`  U R                  U5      I Sh  vN n[        UR                  5      (       a
  [        SSS9e[        R                  SU S35        [        SSS9eUR                  nUR                  nUc
  [        S	S
S9e UR                  5       I Sh  vN nUR                  S5      nUR                  S5      n	U(       d
  [        SSS9e [        R                  " XR                  UR                  5      5      n
 UR'                  XS9  [)        [+        SS9R-                  5       5      $  GN N! [          a  n[        [#        U5      SS9eSnAf[$         a  n[        SU 3SS9eSnAff = f! [$         a  n[        SU 3SS9eSnAff = f! [
         a    e [$         a  n[        SU 3S
S9eSnAff = f7f)aX  
---
summary: Send event to workflow
description: Sends an event to a running workflow's context.
parameters:
  - in: path
    name: handler_id
    required: true
    schema:
      type: string
    description: Workflow handler identifier.
requestBody:
  required: true
  content:
    application/json:
      schema:
        type: object
        properties:
          event:
            description: Serialized event. Accepts object or JSON-encoded string for backward compatibility.
            oneOf:
              - type: string
                description: JSON string of the event envelope or value.
                examples:
                  - '{"type": "ExternalEvent", "value": {"response": "hi"}}'
              - type: object
                properties:
                  type:
                    type: string
                    description: The class name of the event.
                  value:
                    type: object
                    description: The event value object (preferred over data).
                additionalProperties: true
          step:
            type: string
            description: Optional target step name. If not provided, event is sent to all steps.
        required: [event]
responses:
  200:
    description: Event sent successfully
    content:
      application/json:
        schema:
          type: object
          properties:
            status:
              type: string
              enum: [sent]
          required: [status]
  400:
    description: Invalid event data
  404:
    description: Handler not found
  409:
    description: Workflow already completed
r   NzWorkflow already completedr1  r   zHandler z is running but not in memory.zHandler expiredzContext not availabler   r   stepzEvent data is requiredr   zFailed to deserialize event: )rZ  zFailed to send event: sentr   zError processing request: )r   rZ   r   r*   r   r   r  r   warningr   r   jsonr6   parse_event_registryr   r4   r   r   
send_eventr   r&   r   )rL   r   r   r  r  r   r   body	event_strrZ  r   r   s               rM   ri   WorkflowServer._post_event*  s%    t ((6
 ..$$Z0#6w~~#F#F'CQTUU?!%!3!3J!??L"<#6#677#7S  *5STU#+<#NN%% kk;'>CPP$	 'D)I88F#D#+CQTUU	%++33G4I4IJu0   1 @ K K MNNa @( ( ( D#3q6sCC #:1#>C   #3A37S   	 	3A37S 	s   A)H+F,A0HG+ 0F17G+ )/F G (G+ HG+ 
G	F**G	7GG		G+ 
G(G##G((G+ +H?HHHc                  #    UR                   S   nUR                  R                  SS5      R                  5       S:H  nU R                  R                  U5      nUc  U(       d
  [        SSS9eUb  U R                  U5      I Sh  vN   U(       a;  U R                  R                  [        U/S	95      I Sh  vN nUS
:X  a
  [        SSS9e[        [        U(       a  SOSS9R                  5       5      $  No N?7f)as  
---
summary: Stop and delete handler
description: |
  Stops a running workflow handler by cancelling its tasks. Optionally removes the
  handler from the persistence store if purge=true.
parameters:
  - in: path
    name: handler_id
    required: true
    schema:
      type: string
    description: Workflow handler identifier.
  - in: query
    name: purge
    required: false
    schema:
      type: boolean
      default: false
    description: If true, also deletes the handler from the store, otherwise updates the status to cancelled.
responses:
  200:
    description: Handler cancelled and deleted or cancelled only
    content:
      application/json:
        schema:
          type: object
          properties:
            status:
              type: string
              enum: [deleted, cancelled]
          required: [status]
  404:
    description: Handler not found
r   purger'  r(  Nr  r   r   r  r   deletedr   r   )r   r>  r   r?  rZ   r   r   r\   deleter,   r   r"   r   )rL   r   r   re  r  	n_deleteds         rM   rm   WorkflowServer._cancel_handler  s     H ((6
$$((':@@BfL..$$Z0?5':LL %%g... "2299J<8 I A~#+>CPP!$)y{jl
 	
 /s$   BC9C51C97C78>C97C9c                    SUR                   ;  a
  [        SSS9eUR                   S   nX R                  ;  a
  [        SSS9e[        X R                  U   S9$ )NrU   z'name' parameter missingr   r   zWorkflow not foundr   r   )r   r   rW   r   )rL   r   rU   s      rM   r    WorkflowServer._extract_workflow  sZ    ,,,'AsSS""6*&';MM4//$2GHHrt   c                  #      UR                  5       I S h  vN nUR                  S5      nUR                  S0 5      nUR                  SU5      nUR                  S5      n	S n
Ubd   [        R
                  " UU R                  U5      UR                  S9n
U
b1  [        XR                  5      (       d  [        S
UR                   3SS9eS nU(       a  [        R                  " X&S9nOrU	(       ak  U R                  R                  [        U	/U/S/S95      I S h  vN n[        U5      S:X  a
  [        SSS9e[        R                  " X,S   R                  5      nU	=(       d
    [!        5       n	XU	4$  GN[! [         a  n[        SU 3SS9eS nAff = f! [         a  n[        S	U 3SS9eS nAff = f N! [         a    e [         a  n[        SU 3SS9eS nAff = f7f)NzInvalid JSON body: r   r   r   kwargsr   r   )explicit_eventz$Validation error for 'start_event': z#Start event must be an instance of r   r   )r  r~   r}   r   r  r   zError processing request body: r   )r]  r   r   r   r6   r^  r_  r   r4  r   r   r\   r   r,   r   r   nanoid)rL   r   rv   r   ra  r   context_data
run_kwargsstart_event_datar   r   r   persisted_handlerss                rM   r   "WorkflowServer._extract_run_params  s    ;	W$\\^+  88I.L(B/J#xxzB,/J K+"/"5"5(,,];'/'A'A#K *:!;!;4 4 (!DXE_E_D`a$'  G!++XQ+/+?+?+E+E '1l*7#.-, &" )*a/'/BPSTT!++H6K6O6OP#/vxJ*55c , W#-@+DRUVVW" ! '!EaSI$' $&  	 	8<# 	s   GE6 E3E6 AF6 )/F BF6 F4AF6 2G3E6 6
F FFF6 
F1F,,F11F6 6G
GGGc                   #    [        SU05         UR                  R                  UUS9nU R                  X!R                  U5      I Sh  vN nUsSSS5        $  N! , (       d  f       g= f7f)z6Start a workflow and return a wrapper for the handler.r   )r   r   N)r   rv   run_run_workflow_handlerrU   )rL   rv   r   r   r   r   r  s          rM   r   WorkflowServer._start_workflow/  so      lJ78''++' , G !66MM7 G  98
 98s.   A-:A
AA
A-A
A*&A-c                z  ^ ^#    [         R                  " 5       n[        R                  " [        R
                  5      n[        UUS[         R                  " 5       TUUUST R                  T R                  S9nUR                  5       I Sh  vN   UT R                  T'   SUU 4S jjnUR                  US9  U$  N-7f)z@
Creates a wrapper for the handler and starts streaming events.
N)r   rB  r   consumer_mutexr   r   r   r   r   r\   ra   c                 ~   >#    TR                   R                  T S 5        TR                  R                  T S 5        g 7frI   )rZ   popr[   )r   rL   s   rM   	on_finish7WorkflowServer._run_workflow_handler.<locals>.on_finish\  s.     NNz40MMj$/s   :=r}  rV   None)r   Queuer   r   r   r   r  Lockr\   ra   
checkpointrZ   start_streaming)rL   r   r   r   rB  r   r  r}  s   ``      rM   rw  $WorkflowServer._run_workflow_handlerA  s      '.mmo\\(,,/
""<<>!'!! 00!%!:!:
   """%,z"	0 	0 	)4 	#s   BB;B9.B;c                  #    UR                   R                  5       (       d>   UR                   R                  5          UR                   R	                  5       I Sh  vN   UR
                  b  UR
                  I Sh  vN   U R                  R                  UR                  S5        U R                  R                  UR                  S5        g! [         a     Nf = f N! [         a     Nf = f Ns7f)zClose and cleanup a handler.N)
r   r  cancelr   
cancel_runr   rZ   r|  r   r[   r   s     rM   r   WorkflowServer._close_handlerd  s      ""''))##**,))44666 <<#,,7--t4',,d3   7  sd    C2C C  CC   C2<C0=AC2
CC2CC2C   
C-*C2,C--C2c                    U R                   U   R                   Vs0 s H  o"R                  U_M     nnUR                  U R                  R                  US 5      =(       d    /  Vs0 s H  nUR                  U_M     sn5        U$ s  snf s  snf rI   )rW   r   __name__r   rX   r   )rL   r   r   r   s       rM   r_  WorkflowServer._event_registryw  s    (,(F(M(MN(M1Q(MN 0044]DIOROOA 

AO	
  Os   B&B)rX   r_   rY   rZ   rb   ra   r[   rp   r\   rW   rK   )r;   zlist[Middleware] | Noner<   zAbstractWorkflowStore | Noner=   list[float]rI   )rU   r   rv   r   rw   zlist[type[Event]] | NonerV   r  )rV   z'WorkflowServer')rV   z&AsyncGenerator['WorkflowServer', None]r  )	localhostP   N)r   r   r   intr   zdict[str, Any] | NonerV   r  )rV   dict)r   r   rV   r   )r   r   rV   r#   )r   r   rV   r   )r   r   rV   r   )r   r   rv   r   r   r   rV   z-tuple[Context | None, StartEvent | None, str])NN)
rv   r   r   r   r   zStartEvent | Noner   zContext | NonerV   r  )r   r   r   r   r   r!   rV   r  )r   r  rV   r  )r   r   rV   zdict[str, type[Event]])!r  
__module____qualname____firstlineno__rr   rx   r   r   rJ   r   r   r   rj   rc   ro   rd   rf   rn   re   r  rg   rl   rh   rk   ri   rm   r   r   r   rw  r   r_  __static_attributes__ rt   rM   r8   r8   G   s    /37;,/8o
 ,o
 5	o
 )o
j 7;	>> > 4	>
 
>*X    04	  .	
 
"P*lK(;,+XZYv5
n)
VCFJ/(<@|.K`LO\VOpxt<
BI>>*2>CF>	6>H *."&   '	
   
$!!.1!<K!	!F4&rt   r8   c                  F   \ rS rSr% SrS\S'   S\S'   S\S'   S	\S
'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   SrS\S'   S'S jrS(S jrS)S jr	S*S jr
\S+S j5       r\S,S j5       r\S-S  j5       r\S.S! j5       rS/S" jrS/S# jr S0   S1S$ jjrS0S1S% jjrS&rg)2r  i  zvA wrapper around a handler: WorkflowHandler. Necessary to monitor and dispatch events from the handler's stream_eventsr!   r   zasyncio.Queue[Event]rB  zasyncio.Task[None] | Noner   zasyncio.Lockrz  r   r   r   r   r   r   zdatetime | Noner   r+   r\   r  ra   Nz$Callable[[], Awaitable[None]] | None
_on_finishc                   [         R                  " [        R                  5      U l        U R
                  S;   a  U R                  U l        [        U R                  U R                  U R
                  U R                  R                  U R                  U R                  U R                  U R                  U R                  U R                  R                  (       a$  U R                  R                  R!                  5       O0 S9
nU$ )zDPersist the current handler state immediately to the workflow store.)r   r   r   r   )r   r   r   r   r   r   r   r-   r   r   r   r   r   r   r   r   to_dictrL   r   s     rM   _as_persistent_WorkflowHandler._as_persistent  s    ",,x||4;;>> $D&,,;;##****;;**262B2B2F2F  $$,,.B

 rt   c                V   #    U R                   R                  U5      I S h  vN   g  N7frI   )r\   r   r  s     rM   persist_WorkflowHandler.persist  s     ""))*555s   )')c           	       #    [        U R                  5      n U R                  5       n  U R                  U5      I Sh  vN   g! [         a*  n[        R                  SU R                   SU 3SS9  e SnAff = f N<! [         a  nU(       a  UR                  S5      OSnUcN  [        R                  SU R                   S3SS9   U R                  R                  5         e ! [         a     e f = f[        R                  SU R                   SU S	U 35        [        R                  " U5      I Sh  vN     SnAOSnAff = fGM   7f)
zBPersist with retry/backoff; cancel handler when retries exhausted.zFailed to checkpoint handler zV to persistent state. Is there non-serializable state in an event or the state store? Tr   Nr   z* after final attempt. Failing the handler.z. Retrying in z
 seconds: )r`   ra   r  r   r   r   r   r  r|  r   r  r   r7  )rL   backoffsr   r   backoffs        rM   r  _WorkflowHandler.checkpoint  sd    112	,,.J -ll:...  	LL//@  AW  XY  WZ  [   	 / --5(,,q/4?LL77HHrs!% ! 
((//1  %  3DOO3DNSZR[[efgehi mmG,,,!-	 s   E
A E
A> A< A> E

A9%A44A99E
<A> >
E?D?C#"D?#
C0-D?/C00AD?4D75D?:E
?EE
c                   [        U R                  U R                  U R                  R                  U R
                  U R                  R                  5       U R                  R                  5       U R                  b  U R                  R                  5       OSU R                  U R                  b"  [        R                  " U R                  5      S9	$ SS9	$ )z.Convert runtime handler to API response model.Nr   )r#   r   r   r   r   r   r   rS  r   r   r   r   r5   r5  r   s    rM   r  "_WorkflowHandler.to_response_model  s    ,,##**;;002002  , **446**{{& -77D
 	
 
 	
rt   c                0   [        U R                  U R                  U R                  U R                  U R
                  b  U R
                  R                  5       O1[        R                  " [        R                  5      R                  5       U R                  b  U R                  R                  5       OS U R                  b  U R                  R                  5       OS U R                  U R                  b"  [        R                   " U R                  5      S9	$ S S9	$ )Nr   )r#   r   r   r   r   r   rS  r   r   r   r   r   r   r   r   r5   r5  )r   s    rM   r  -_WorkflowHandler.handler_data_from_persistent  s    !,,$22$$$$$$0 ",,668hll+557$$0 ",,668&&2 $00::<""  , -77
8I8IJ
 	
" #
 	
rt   c                    U R                   R                  5       (       d  gU R                   R                  5       (       a  gU R                   R                  5       nUb  gg)z7Get the current status by inspecting the handler state.r{   r   r   r   )r   r  r   	exceptionrL   excs     rM   r   _WorkflowHandler.status  sS     $$&&%%''((*?rt   c                    U R                   R                  5       (       d  g  U R                   R                  5       nUb  [        U5      $ S $ ! [        R                   a     g f = frI   )r   r  r  r   CancelledErrorr   r  s     rM   r   _WorkflowHandler.error  sb    $$&&	"",,.C ?s3x44 %% 		s   A A#"A#c                    U R                   R                  5       (       d  g  U R                   R                  5       $ ! [        R                   a     g [
         a     g f = frI   )r   r  get_stop_eventr   r  r   r   s    rM   r   _WorkflowHandler.result  sW    $$&&	##2244%% 	 		s   < A	AAc                T    [         R                  " U R                  US95      U l        g)z;Start streaming events from the handler and managing state.r  N)r   create_taskrh   r   )rL   r}  s     rM   r   _WorkflowHandler.start_streaming  s"    ''(;(;i(;(PQ	rt   c                  #    [        SU R                  05         U R                  5       I Sh  vN   Xl        U R                  R                  SS9  Sh  vN n[        U[        5      (       a  UR                  [        R                  :X  a  U R                  R                  (       a$  U R                  R                  R                  5       OSnUc%  [        R                  SU R                   S35        M  U R                  5       I Sh  vN   U R                  R!                  U5        M   N N N%
  U R                  I Sh  vN    Os! ["        R$                   a&    [        R'                  SU R                   S35         O:[(         a.  n[        R+                  SU R                   S	U 3SS
9   SnAOSnAff = fU R                  5       I Sh  vN    SSS5        g! , (       d  f       g= f7f)zHInternal method that streams events, updates status, and persists state.r   NT)expose_internalz"Context state is None for handler z. This is not expected.zWorkflow run z was cancelledz	 failed! r   )r   r   r  r  r   stream_eventsr4  r   
step_stater   NOT_RUNNINGr   r  r   r\  rB  
put_nowaitr   r  r   r   r   )rL   r}  r   stater   s        rM   rh   _WorkflowHandler._stream_events  s    lDOO<=//###'O#//==d=S -eu&677((I,A,AA ;?:J:J:N:N((,,446TX  }@@QQhi !//+++

%%e,# $- ,  T"	&&&&)) MmDOO+<NKL #DOO#4IaSAD  
 //###? >==s   G0GD,#GD2D.D2B0G
D0"G.D20G2G4E
EE
	G
7F:G	F:$F50G5F::GGG	G0
G-)G0c                   #     [         R                  " U R                  R                  5       US9I Sh  vN   U R                  US9$  N! [         R                   a    [        SU S35      ef = f7f)zP
Acquires the lock to iterate over the events, and returns generator of events.
r-  Nr/  r0  )r   wait_forrz  acquireTimeoutErrorrE  _iter_events)rL   r.  s     rM   rD  &_WorkflowHandler.acquire_events_streamB  sx     	""4#6#6#>#>#@'RRR
    11 S## 	!5gYiH 	s+   A10A
 AA
 A1A
 
$A..A1c                 #     U R                   R                  5       (       a.  U R                  Gb|  U R                  R                  5       (       Gd\  / nU R                   R                  5       (       dJ  UR	                  U R                   R                  5       5        U R                   R                  5       (       d  MJ  U H  nU7v   M
     [        R                  " U R                   R                  5       5      nU R                  n[        R                  " Ub  XE1OU1[        R                  S9I Sh  vN u  pgXF;   a  UI Sh  vN 7v   OUR                  5         OQU R                   R                  5       (       d  GM-  U R                  b"  U R                  R                  5       (       d  GM\  U R                  b7  U R                  R                  5       (       a  U R                  5       I Sh  vN   U R                  R                  5         g N N N#! U R                  b8  U R                  R                  5       (       a  U R                  5       I Sh  vN    U R                  R                  5         f = f7f)z
Converts the queue to an async generator while the workflow is still running, and there are still events.
For better or worse, multiple consumers will compete for events
N)return_when)rB  rC  r   r  r   
get_nowaitr   r  r   waitFIRST_COMPLETEDr  r  r   rz  release)rL   r.  available_eventsr   queue_get_tasktask_waitabler  pendings           rM   r  _WorkflowHandler._iter_eventsP  s    	*jj&&((		%diinn.>.>#% ****,,$++DJJ,A,A,CD ****,,-EK .6=6I6IJJNN$7 !%		&-ll$0 $3() ' 7 7	' ! ") ..."))+- jj&&((		%diinn.>.>. *t/?/?/D/D/F/Foo''''')! / ( *t/?/?/D/D/F/Foo''''')sm   I6B6H <A5H 1H2H H8H >,H -?I6,H-I6H H I6A I3I I33I6)r  r   r   r   )rV   r-   )r   r-   rV   r  r  )rV   r#   )r   r-   rV   r#   )rV   r.   )rV   z
str | None)rV   zStopEvent | None)r}  zCallable[[], Awaitable[None]]rV   r  )r2   )r.  r@  rV   zAsyncGenerator[Event, None])r  r  r  r  __doc____annotations__r  r  r  r  r  staticmethodr  propertyr   r   r   r  rh   rD  r  r  r  rt   rM   r  r    s     A  
##   O!! +*%%7;J4;(6-B
$ 
 
*   5 5  R!$H  !22	$2"* "*rt   r  c                      \ rS rSrSrSrg)rE  iu  z;Raised when no lock is available to acquire after a timeoutr  N)r  r  r  r  r  r  r  rt   rM   rE  rE  u  s    Ert   rE  c                  *    \ rS rSr% S\S'   S\S'   Srg)r   i{  r   rU   r   rv   r  N)r  r  r  r  r  r  r  rt   rM   r   r   {  s    
Irt   r   __main__zGenerate OpenAPI schema)r   z--outputzopenapi.jsonzOutput file path)r   defaulthelpw   )indentfpzOpenAPI schema written to )i
__future__r   r   
contextlibr   dataclassesr   r]  loggingimportlib.metadatar   pathlibr   typingr   r	   r
   r   r   r   &llama_index_instrumentation.dispatcherr   r   starlette.applicationsr   starlette.exceptionsr   starlette.middlewarer   starlette.middleware.corsr   starlette.requestsr   starlette.responsesr   r   starlette.routingr   starlette.schemasr   starlette.staticfilesr   r   r   r   workflows.eventsr   r   r   r   r   r    workflows.handlerr!   workflows.protocolr"   r#   r$   r%   r&   r'   r(   r)   r*   (workflows.server.abstract_workflow_storer+   r,   r-   r.   &workflows.server.memory_workflow_storer/   workflows.typesr0   workflows.utilsr1   ro  representation_utilsr3   &workflows.protocol.serializable_eventsr4   r5   r6   	getLoggerr   r8   r  r   rE  r   r  argparseArgumentParserparseradd_argumentr   
parse_argsargsr   r   dict_schemaopenoutputfdumpprintr  rt   rM   <module>r     s   #  * !   &  ; ; ' B  , . + 4 & ? # - - '  .
 
 
  G & . =  
			x xv) o* o* o*d	i 	   
 z$$1JKF
n;M   DF'')K	dkk3	1		+aA. 
 	&t{{m
45  
 	s   F??
G