the Stores
This commit is contained in:
@@ -39,6 +39,7 @@ from .operation_context import (
|
||||
)
|
||||
|
||||
from .runtime_dependencies import RuntimeDependencies, resolve_runtime_dependencies
|
||||
from .stores import WorkflowStores, file_workflow_stores
|
||||
|
||||
__all__ = [
|
||||
"DEFAULT_CALL_STEP_ID",
|
||||
@@ -78,4 +79,6 @@ __all__ = [
|
||||
"workflow_output_schema_for_authoring",
|
||||
"wrapper_hints_for_capability",
|
||||
"resolve_runtime_dependencies",
|
||||
"WorkflowStores",
|
||||
"file_workflow_stores",
|
||||
]
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
from wf_artifacts import (
|
||||
DraftWorkspaceStore,
|
||||
FileDraftWorkspaceStore,
|
||||
FileRunStore,
|
||||
FileWorkflowArtifactStore,
|
||||
RunStore,
|
||||
WorkflowArtifactStore,
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class WorkflowStores:
|
||||
"""Protocol-neutral persistence dependencies for workflow APIs."""
|
||||
|
||||
artifact_store: WorkflowArtifactStore
|
||||
draft_workspace_store: DraftWorkspaceStore
|
||||
run_store: RunStore
|
||||
|
||||
|
||||
def file_workflow_stores(root: str | Path) -> WorkflowStores:
|
||||
"""Create process-local file-backed workflow stores under one root."""
|
||||
store_root = Path(root)
|
||||
return WorkflowStores(
|
||||
artifact_store=FileWorkflowArtifactStore(store_root),
|
||||
draft_workspace_store=FileDraftWorkspaceStore(store_root),
|
||||
run_store=FileRunStore(store_root),
|
||||
)
|
||||
|
||||
|
||||
__all__ = ["WorkflowStores", "file_workflow_stores"]
|
||||
@@ -3,11 +3,7 @@ from __future__ import annotations
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from wf_artifacts import (
|
||||
FileDraftWorkspaceStore,
|
||||
FileRunStore,
|
||||
FileWorkflowArtifactStore,
|
||||
)
|
||||
from wf_api import file_workflow_stores
|
||||
|
||||
from ..control import BrokerConfigFile
|
||||
from ..models import BrokerConfig
|
||||
@@ -27,11 +23,12 @@ def load_broker_config(path: str | Path) -> BrokerConfig:
|
||||
def build_service_from_config(config: BrokerConfig) -> WfMcpService:
|
||||
"""Create a broker service with SDK adapters for configured connections."""
|
||||
runtime_factory = PersistentSessionFactory()
|
||||
workflow_stores = file_workflow_stores(config.store_root)
|
||||
service = WfMcpService(
|
||||
store=FileStore(config.store_root),
|
||||
artifact_store=FileWorkflowArtifactStore(config.store_root),
|
||||
draft_workspace_store=FileDraftWorkspaceStore(config.store_root),
|
||||
run_store=FileRunStore(config.store_root),
|
||||
artifact_store=workflow_stores.artifact_store,
|
||||
draft_workspace_store=workflow_stores.draft_workspace_store,
|
||||
run_store=workflow_stores.run_store,
|
||||
# Discovery can use short-lived SDK sessions. Workflow execution needs
|
||||
# a persistent runtime so stateful MCP servers keep session/page state
|
||||
# across sequential workflow nodes.
|
||||
|
||||
@@ -2,16 +2,12 @@ from __future__ import annotations
|
||||
|
||||
import time
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from wf_artifacts import (
|
||||
DraftWorkspaceStore,
|
||||
FileDraftWorkspaceStore,
|
||||
FileRunStore,
|
||||
FileWorkflowArtifactStore,
|
||||
RunStore,
|
||||
WorkflowArtifact,
|
||||
WorkflowArtifactCatalogEntry,
|
||||
@@ -68,12 +64,6 @@ from .builtins import builtin_sources
|
||||
from .specs import get_qualified_spec, qualify_spec
|
||||
|
||||
|
||||
def _store_root(store: Store) -> Path:
|
||||
"""Return the file root for stores that expose one, else use local default."""
|
||||
root = getattr(store, "root", None)
|
||||
return root if isinstance(root, Path) else Path(".wf_mcp_store")
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
class WfMcpService:
|
||||
store: Store
|
||||
@@ -89,15 +79,12 @@ class WfMcpService:
|
||||
tool_executor: ToolExecutor | None = None
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
"""Install broker-local system specs when enabled."""
|
||||
if self.artifact_store is None:
|
||||
self.artifact_store = FileWorkflowArtifactStore(_store_root(self.store))
|
||||
if self.draft_workspace_store is None:
|
||||
self.draft_workspace_store = FileDraftWorkspaceStore(
|
||||
_store_root(self.store)
|
||||
)
|
||||
if self.run_store is None:
|
||||
self.run_store = FileRunStore(_store_root(self.store))
|
||||
"""Install broker-local system specs when enabled.
|
||||
|
||||
Workflow stores are injected by entrypoint/config construction. This service
|
||||
must not guess workflow persistence from the MCP catalog/auth store because
|
||||
CLI, MCP, and future HTTP frontends may share or swap those stores.
|
||||
"""
|
||||
if self.include_builtin_specs:
|
||||
for source in builtin_sources().values():
|
||||
self.register_capability_source(source)
|
||||
|
||||
Reference in New Issue
Block a user