rayhpeng 9d0a42c1fb refactor(runtime): restructure runs module with new execution architecture
Major refactoring of deerflow/runtime/:
- runs/callbacks/ - new callback system (builder, events, title, tokens)
- runs/internal/ - execution internals (executor, supervisor, stream_logic, registry)
- runs/internal/execution/ - execution artifacts and events handling
- runs/facade.py - high-level run facade
- runs/observer.py - run observation protocol
- runs/types.py - type definitions
- runs/store/ - simplified store interfaces (create, delete, query, event)

Refactor stream_bridge/:
- Replace old providers with contract.py and exceptions.py
- Remove async_provider.py, base.py, memory.py

Add documentation:
- README.md and README_zh.md for runtime module

Remove deprecated:
- manager.py moved to internal/
- worker.py, schemas.py
- user_context.py

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-22 11:28:01 +08:00

46 lines
1.2 KiB
Python

"""Lifecycle event helpers for run execution."""
from __future__ import annotations
from datetime import UTC, datetime
from typing import Any
from ...observer import LifecycleEventType, RunLifecycleEvent, RunObserver
class RunEventEmitter:
"""Build and dispatch lifecycle events for a single run."""
def __init__(
self,
*,
run_id: str,
thread_id: str,
observer: RunObserver,
) -> None:
self._run_id = run_id
self._thread_id = thread_id
self._observer = observer
self._sequence = 0
@property
def sequence(self) -> int:
return self._sequence
async def emit(
self,
event_type: LifecycleEventType,
payload: dict[str, Any] | None = None,
) -> None:
self._sequence += 1
event = RunLifecycleEvent(
event_id=f"{self._run_id}:{event_type.value}:{self._sequence}",
event_type=event_type,
run_id=self._run_id,
thread_id=self._thread_id,
sequence=self._sequence,
occurred_at=datetime.now(UTC),
payload=payload or {},
)
await self._observer.on_event(event)