refactor: group rpc transport client and methods

This commit is contained in:
lda
2026-06-08 21:44:41 +07:00 Verified
parent 7582c1d6fb
commit c39d361873
25 changed files with 104 additions and 114 deletions
+79
View File
@@ -0,0 +1,79 @@
from __future__ import annotations
from typing import Any
import fastapi_jsonrpc as jsonrpc
from wf_server import WorkflowServer
from ..errors import WorkflowRpcError, raise_workflow_rpc_error
from ..models import (
InspectRunParams,
ReadRunTraceParams,
ResumeRunParams,
StartRunParams,
)
from ..params import RpcParams
def register_methods(
entrypoint: jsonrpc.Entrypoint,
server: WorkflowServer,
) -> None:
"""Register run lifecycle JSON-RPC methods."""
@entrypoint.method(name="workflow.runs.start", errors=[WorkflowRpcError])
async def workflow_runs_start(
params: StartRunParams = RpcParams(),
) -> dict[str, Any]:
try:
return await server.api.run_deployment(
deployment_id=params.deployment_id,
workflow_input=params.workflow_input,
trace_range=(
params.trace_range.to_api_trace_range()
if params.trace_range is not None
else None
),
)
except (ValueError, KeyError, LookupError, FileNotFoundError) as exc:
raise_workflow_rpc_error(exc)
@entrypoint.method(name="workflow.runs.inspect", errors=[WorkflowRpcError])
async def workflow_runs_inspect(
params: InspectRunParams = RpcParams(),
) -> dict[str, Any]:
try:
return await server.api.inspect_run(run_id=params.run_id)
except (ValueError, KeyError, LookupError, FileNotFoundError) as exc:
raise_workflow_rpc_error(exc)
@entrypoint.method(name="workflow.runs.trace", errors=[WorkflowRpcError])
async def workflow_runs_trace(
params: ReadRunTraceParams = RpcParams(),
) -> dict[str, Any]:
try:
return await server.api.read_run_trace(
run_id=params.run_id,
trace_range=params.trace_range.to_api_trace_range(),
)
except (ValueError, KeyError, LookupError, FileNotFoundError) as exc:
raise_workflow_rpc_error(exc)
@entrypoint.method(name="workflow.runs.resume", errors=[WorkflowRpcError])
async def workflow_runs_resume(
params: ResumeRunParams = RpcParams(),
) -> dict[str, Any]:
try:
return await server.api.resume_run(
run_id=params.run_id,
resume_payload=params.resume_payload,
resume_outcome=params.resume_outcome,
trace_range=(
params.trace_range.to_api_trace_range()
if params.trace_range is not None
else None
),
)
except (ValueError, KeyError, LookupError, FileNotFoundError) as exc:
raise_workflow_rpc_error(exc)