MCPcopy Create free account
hub / github.com/dot-agent/nextpy / process

Function process

nextpy/app.py:880–935  ·  view source on GitHub ↗

Process an event. Args: app: The app to process the event for. event: The event to process. sid: The Socket.IO session id. headers: The client headers. client_ip: The client_ip. Yields: The state updates after processing the event.

(
    app: App, event: Event, sid: str, headers: Dict, client_ip: str
)

Source from the content-addressed store, hash-verified

878
879
880async def process(
881 app: App, event: Event, sid: str, headers: Dict, client_ip: str
882) -> AsyncIterator[StateUpdate]:
883 """Process an event.
884
885 Args:
886 app: The app to process the event for.
887 event: The event to process.
888 sid: The Socket.IO session id.
889 headers: The client headers.
890 client_ip: The client_ip.
891
892 Yields:
893 The state updates after processing the event.
894 """
895 # Add request data to the state.
896 router_data = event.router_data
897 router_data.update(
898 {
899 constants.RouteVar.QUERY: format.format_query_params(event.router_data),
900 constants.RouteVar.CLIENT_TOKEN: event.token,
901 constants.RouteVar.SESSION_ID: sid,
902 constants.RouteVar.HEADERS: headers,
903 constants.RouteVar.CLIENT_IP: client_ip,
904 }
905 )
906 # Get the state for the session exclusively.
907 async with app.state_manager.modify_state(event.token) as state:
908 # re-assign only when the value is different
909 if state.router_data != router_data:
910 # assignment will recurse into substates and force recalculation of
911 # dependent ComputedVar (dynamic route variables)
912 state.router_data = router_data
913 state.router = RouterData(router_data)
914
915 # Preprocess the event.
916 update = await app.preprocess(state, event)
917
918 # If there was an update, yield it.
919 if update is not None:
920 yield update
921
922 # Only process the event if there is no update.
923 else:
924 if app._process_background(state, event) is not None:
925 # `final=True` allows the frontend send more events immediately.
926 yield StateUpdate(final=True)
927 return
928
929 # Process the event synchronously.
930 async for update in state._process(event):
931 # Postprocess the event.
932 update = await app.postprocess(state, event, update)
933
934 # Yield the update.
935 yield update
936
937

Callers 3

test_process_eventsFunction · 0.90
on_eventMethod · 0.85

Calls 8

RouterDataClass · 0.90
StateUpdateClass · 0.90
_process_backgroundMethod · 0.80
_processMethod · 0.80
updateMethod · 0.45
modify_stateMethod · 0.45
preprocessMethod · 0.45
postprocessMethod · 0.45