MCPcopy Create free account
hub / github.com/vercel/examples / run_events

Function run_events

python/vibe-coding-ide/backend/src/api/agent.py:75–103  ·  view source on GitHub ↗
(run_id: str, token: str)

Source from the content-addressed store, hash-verified

73
74@router.get("/{run_id}/events")
75async def run_events(run_id: str, token: str):
76 oidc_token = await get_vercel_oidc_token()
77 token_payload = read_stream_token(token)
78 if token_payload.get("run_id") != run_id:
79 raise HTTPException(status_code=400, detail="Token does not match run id")
80 payload = await get_run_payload(run_id)
81 if payload is None:
82 # Gracefully end the stream with a run_failed event
83 async def missing_generator() -> AsyncGenerator[str, None]:
84 yield sse_format(
85 emit_event(run_id, "run_failed", error="Unknown or expired run id")
86 )
87
88 return StreamingResponse(missing_generator(), headers=SSE_HEADERS)
89
90 async def event_generator() -> AsyncGenerator[str, None]:
91 try:
92 async for chunk in run_agent_flow(payload, run_id, oidc_token=oidc_token):
93 yield chunk
94 except Exception as e:
95 logger.error("run_events[%s] error: %s", run_id, str(e))
96 logger.error(traceback.format_exc(limit=10))
97 tb = traceback.format_exc(limit=10)
98 yield sse_format(
99 emit_event(run_id, "run_log", data=f"stream exception: {str(e)}\n{tb}")
100 )
101 yield sse_format(emit_event(run_id, "run_failed", error=str(e)))
102
103 return StreamingResponse(event_generator(), headers=SSE_HEADERS)
104
105
106@router.get("/{run_id}/resume")

Callers

nothing calls this directly

Calls 5

read_stream_tokenFunction · 0.90
get_run_payloadFunction · 0.90
missing_generatorFunction · 0.85
event_generatorFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected