refactor: add static source provider seam

This commit is contained in:
lda
2026-06-12 09:59:39 +07:00 Verified
parent dee95c89d2
commit bad3dbae0c
9 changed files with 148 additions and 17 deletions
+14 -14
View File
@@ -3,9 +3,9 @@ from __future__ import annotations
from pathlib import Path
from wf_config import FilesystemStoreConfig, PythonSourceConfig, WorkflowConfigFile
from wf_platform import CapabilitySource
from .context import WorkflowServer, build_local_static_workflow_server
from .sources import WorkflowSourceProvider, collect_static_sources
def _has_mcp_sources(config: WorkflowConfigFile) -> bool:
@@ -14,20 +14,20 @@ def _has_mcp_sources(config: WorkflowConfigFile) -> bool:
)
def _python_sources(config: WorkflowConfigFile) -> dict[str, CapabilitySource]:
from wf_sources_python import load_python_source
return {
source.id: load_python_source(
source_id=source.id,
path=source.path,
module=source.module,
registry=source.registry,
enabled=source.enabled,
)
def _static_source_providers(
config: WorkflowConfigFile,
) -> list[WorkflowSourceProvider]:
providers: list[WorkflowSourceProvider] = []
python_configs = [
source
for source in config.server.sources
if isinstance(source, PythonSourceConfig)
}
]
if python_configs:
from wf_sources_python import PythonSourceProvider
providers.append(PythonSourceProvider(python_configs))
return providers
def _build_mcp_workflow_server_from_workflow_config(
@@ -68,7 +68,7 @@ def build_workflow_server_from_workflow_config(
raise ValueError("wf-rpc-server currently requires filesystem store")
return build_local_static_workflow_server(
store.root,
extra_sources=_python_sources(config),
extra_sources=collect_static_sources(_static_source_providers(config)),
)
+48
View File
@@ -0,0 +1,48 @@
from __future__ import annotations
from collections.abc import Mapping, Sequence
from dataclasses import dataclass
from typing import Protocol
from wf_platform import CapabilitySource
class WorkflowSourceProvider(Protocol):
"""Static source inventory provider for server composition.
This seam is intentionally narrow: providers return workflow-facing
`CapabilitySource` objects. Runtime pools, admin/apply hooks, and live
health checks remain separate provider-specific concerns.
"""
def load_sources(self) -> Mapping[str, CapabilitySource]: ...
@dataclass(frozen=True, slots=True)
class StaticSourceProvider:
"""Adapter for already-materialized capability sources."""
sources: Mapping[str, CapabilitySource]
def load_sources(self) -> Mapping[str, CapabilitySource]:
return dict(self.sources)
def collect_static_sources(
providers: Sequence[WorkflowSourceProvider],
) -> dict[str, CapabilitySource]:
"""Merge static provider inventories while rejecting ambiguous source ids."""
collected: dict[str, CapabilitySource] = {}
for provider in providers:
for source_id, source in provider.load_sources().items():
if source_id in collected:
raise ValueError(f"duplicate workflow source ids: {[source_id]}")
collected[source_id] = source
return collected
__all__ = [
"StaticSourceProvider",
"WorkflowSourceProvider",
"collect_static_sources",
]