feat: expose source admin over rpc and cli

This commit is contained in:
lda
2026-06-03 21:49:13 +07:00 Verified
parent 24ca91afb1
commit f0d0cffa17
15 changed files with 246 additions and 22 deletions
+12 -1
View File
@@ -4,7 +4,17 @@ from typing import Annotated
import typer
from .commands import artifacts, caps, deployments, docs, drafts, explain, runs, schema
from .commands import (
artifacts,
caps,
deployments,
docs,
drafts,
explain,
runs,
schema,
sources,
)
from .context import CliTyperState
app = typer.Typer(
@@ -51,6 +61,7 @@ app.add_typer(drafts.app, name="draft")
app.add_typer(artifacts.app, name="artifact")
app.add_typer(deployments.app, name="deploy")
app.add_typer(runs.app, name="run")
app.add_typer(sources.app, name="source")
app.add_typer(docs.app, name="docs")
app.add_typer(schema.app, name="schema")
app.command("explain")(explain.explain_command)
+52
View File
@@ -0,0 +1,52 @@
from __future__ import annotations
import asyncio
from typing import Annotated
import typer
from wf_cli.context import load_cli_context_from_typer
from wf_cli.formats import ListOutputFormat, emit_list_payload
from wf_cli.io import emit_json
app = typer.Typer(
name="source",
help="List and inspect workflow capability sources.",
no_args_is_help=True,
)
@app.command("list")
def list_sources(
ctx: typer.Context,
cursor: Annotated[
str | None, typer.Option("--cursor", help="Pagination cursor.")
] = None,
limit: Annotated[
int, typer.Option("--limit", min=1, max=100, help="Maximum rows.")
] = 50,
output_format: Annotated[
ListOutputFormat, typer.Option("--format", help="Output format.")
] = ListOutputFormat.JSON,
) -> None:
"""List compact workflow source summaries."""
context = load_cli_context_from_typer(ctx)
payload = asyncio.run(context.source_admin.list_sources(cursor=cursor, limit=limit))
emit_list_payload(
payload,
collection_key="sources",
output_format=output_format,
id_field="id",
summary_fields=("kind", "enabled", "description"),
)
@app.command("inspect")
def inspect_source(
ctx: typer.Context,
source_id: Annotated[str, typer.Argument(help="Workflow source id.")],
) -> None:
"""Inspect one workflow source inventory."""
context = load_cli_context_from_typer(ctx)
payload = asyncio.run(context.source_admin.inspect_source(source_id=source_id))
emit_json(payload)
+28 -16
View File
@@ -8,7 +8,12 @@ from collections.abc import Mapping
import typer
from pydantic import ValidationError
from wf_api import WorkflowApi, WorkflowApiSurface
from wf_api import (
WorkflowApi,
WorkflowApiSurface,
WorkflowSourceAdminApi,
WorkflowSourceAdminSurface,
)
from wf_config import (
FilesystemStoreConfig,
LocalTargetConfig,
@@ -29,6 +34,7 @@ class CliContext:
config_path: Path
service: WfMcpService | None
handlers: WorkflowApiSurface
source_admin: WorkflowSourceAdminSurface
@dataclass(frozen=True)
@@ -98,16 +104,18 @@ def load_cli_context(
if rpc_url is not None:
_validate_rpc_url(rpc_url)
client = RpcWorkflowApiClient(
url=rpc_url,
timeout_seconds=_rpc_timeout_from_optional_config(
resolved_config_path,
override=rpc_timeout_seconds,
),
)
return CliContext(
config_path=resolved_config_path,
service=None,
handlers=RpcWorkflowApiClient(
url=rpc_url,
timeout_seconds=_rpc_timeout_from_optional_config(
resolved_config_path,
override=rpc_timeout_seconds,
),
),
handlers=client,
source_admin=client,
)
if _is_legacy_mcp_config(resolved_config_path):
@@ -117,6 +125,7 @@ def load_cli_context(
config_path=resolved_config_path,
service=service,
handlers=WorkflowApi(context_from_service(service)),
source_admin=WorkflowSourceAdminApi(context_from_service(service)),
)
config = load_workflow_config(resolved_config_path)
@@ -130,19 +139,22 @@ def load_cli_context(
config_path=resolved_config_path,
service=None,
handlers=server.api,
source_admin=server.source_admin,
)
if isinstance(target, RpcHttpTargetConfig):
client = RpcWorkflowApiClient(
url=str(target.url),
timeout_seconds=(
rpc_timeout_seconds
if rpc_timeout_seconds is not None
else target.timeout_seconds
),
)
return CliContext(
config_path=resolved_config_path,
service=None,
handlers=RpcWorkflowApiClient(
url=str(target.url),
timeout_seconds=(
rpc_timeout_seconds
if rpc_timeout_seconds is not None
else target.timeout_seconds
),
),
handlers=client,
source_admin=client,
)
raise ValueError(f"unsupported workflow target {target!r}")