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

43 lines
1.3 KiB
Python

"""Execution plan builder for runs domain."""
from __future__ import annotations
from copy import deepcopy
from dataclasses import dataclass
from typing import Any, Literal
from ..types import RunRecord, RunSpec
@dataclass(frozen=True)
class ExecutionPlan:
"""Normalized execution inputs derived from a run record and spec."""
record: RunRecord
graph_input: dict[str, Any]
runnable_config: dict[str, Any]
stream_modes: list[str]
stream_subgraphs: bool
interrupt_before: list[str] | Literal["*"] | None
interrupt_after: list[str] | Literal["*"] | None
class ExecutionPlanner:
"""Build executor-ready plans from public run specs."""
def build(self, record: RunRecord, spec: RunSpec) -> ExecutionPlan:
return ExecutionPlan(
record=record,
graph_input=self._normalize_graph_input(spec.input),
runnable_config=deepcopy(spec.runnable_config),
stream_modes=list(spec.stream_modes),
stream_subgraphs=spec.stream_subgraphs,
interrupt_before=spec.interrupt_before,
interrupt_after=spec.interrupt_after,
)
def _normalize_graph_input(self, raw_input: dict[str, Any] | None) -> dict[str, Any]:
if raw_input is None:
return {}
return deepcopy(raw_input)