call capability result!

This commit is contained in:
lda
2026-05-19 04:19:05 +07:00 Verified
parent 50fc6e3670
commit edbe8c4d84
7 changed files with 123 additions and 6 deletions
+29 -1
View File
@@ -19,7 +19,13 @@ from wf_artifacts import (
validate_workflow_draft,
validate_deployment_dependencies,
)
from wf_platform import CapabilityRef, NodeSpecInventory, hash_json_schema, page_items
from wf_platform import (
CapabilityRef,
CapabilitySource,
NodeSpecInventory,
hash_json_schema,
page_items,
)
from wf_authoring import build_async_registry
from wf_core import RuntimeContext
@@ -118,8 +124,15 @@ class WorkflowSurfaceHandlers:
result = await handler(payload, RuntimeContext(current_node_id=spec.name))
return {
"qualified_name": spec.name,
"source_id": _source_id_for_capability(
self.service.capability_sources,
spec.name,
),
"kind": "node_spec",
"deployment_id": None,
"outcome": result["outcome"],
"output": result["output"],
"diagnostics": [],
}
def _wrapper_artifact_for_capability_name(
@@ -176,8 +189,12 @@ class WorkflowSurfaceHandlers:
)
return {
"qualified_name": _artifact_capability_id(artifact),
"source_id": "workflow",
"kind": "wrapper_artifact",
"deployment_id": deployment_id,
"outcome": run.status.value,
"output": run.output,
"diagnostics": [],
}
async def save_artifact(self, artifact: dict[str, Any]) -> dict[str, Any]:
@@ -566,6 +583,17 @@ def _schema_field_names(schema: dict[str, Any]) -> list[str]:
return sorted(str(name) for name in properties)
def _source_id_for_capability(
sources: dict[str, CapabilitySource],
qualified_name: str,
) -> str | None:
"""Return the source that currently owns one workflow capability."""
for source in sources.values():
if qualified_name in source.capabilities.node_specs:
return source.id
return None
def _capability_name(qualified_name: str) -> str | None:
"""Return the local name of one qualified capability ref if it is valid."""
try:
+34
View File
@@ -0,0 +1,34 @@
from __future__ import annotations
from typing import Any, Literal
from pydantic import BaseModel, Field
class CallCapabilityResult(BaseModel):
"""Inspector-visible response contract for testing one workflow capability."""
qualified_name: str = Field(description="Capability name that was executed.")
source_id: str | None = Field(
default=None,
description="Capability source that owned the executed node spec.",
)
kind: Literal["node_spec", "wrapper_artifact"] = Field(
description=(
"Indicates whether this call executed a live NodeSpec or a saved "
"wrapper artifact."
)
)
deployment_id: str | None = Field(
default=None,
description="Deployment used to resolve logical bindings, if any.",
)
outcome: str = Field(description="Workflow outcome returned by the capability.")
output: dict[str, Any] | None = Field(
default=None,
description="Normalized workflow-facing output payload.",
)
diagnostics: list[dict[str, Any]] = Field(
default_factory=list,
description="Structured diagnostics. Empty for successful calls.",
)
+8 -5
View File
@@ -9,6 +9,7 @@ from wf_artifacts.models import RequiredCapability
from wf_mcp.broker.service import WfMcpService
from .handlers import WorkflowSurfaceHandlers
from .models import CallCapabilityResult
def register_workflow_tools(server: FastMCP[Any], service: WfMcpService) -> None:
@@ -62,11 +63,13 @@ def register_workflow_tools(server: FastMCP[Any], service: WfMcpService) -> None
qualified_name: str,
payload: dict[str, Any],
deployment_id: str | None = None,
) -> dict[str, Any]:
return await handlers.call_capability(
qualified_name=qualified_name,
payload=payload,
deployment_id=deployment_id,
) -> CallCapabilityResult:
return CallCapabilityResult.model_validate(
await handlers.call_capability(
qualified_name=qualified_name,
payload=payload,
deployment_id=deployment_id,
)
)
@server.tool(