feat: expose create artifact from plan over rpc
This commit is contained in:
@@ -6,6 +6,7 @@ from .errors import WorkflowRpcError
|
||||
from .models import (
|
||||
AdminEmptyParams,
|
||||
CallCapabilityParams,
|
||||
CreateArtifactFromPlanParams,
|
||||
CreateArtifactFromWorkspaceParams,
|
||||
CreateDraftFromCapabilityParams,
|
||||
CreateWrapperFromWorkspaceParams,
|
||||
@@ -36,6 +37,7 @@ from .models import (
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"CreateArtifactFromPlanParams",
|
||||
"CreateArtifactFromWorkspaceParams",
|
||||
"AdminEmptyParams",
|
||||
"CallCapabilityParams",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Sequence
|
||||
from typing import Any, Literal
|
||||
|
||||
from .base import RpcCaller
|
||||
@@ -46,3 +47,33 @@ class RpcArtifactClientMixin:
|
||||
"workflow.artifacts.delete",
|
||||
{"artifact_id": artifact_id, "version": version},
|
||||
)
|
||||
|
||||
async def create_artifact_from_plan(
|
||||
self: RpcCaller,
|
||||
*,
|
||||
artifact_id: str,
|
||||
version: int,
|
||||
title: str,
|
||||
plan: dict[str, Any],
|
||||
outcomes: Sequence[str],
|
||||
kind: Literal["workflow", "wrapper"] = "workflow",
|
||||
description: str | None = None,
|
||||
required_capabilities: dict[str, dict[str, Any]] | None = None,
|
||||
source_bindings: dict[str, str] | None = None,
|
||||
created_from_catalog_version: str | None = None,
|
||||
) -> dict[str, Any]:
|
||||
return await self._call(
|
||||
"workflow.artifacts.create_from_plan",
|
||||
{
|
||||
"artifact_id": artifact_id,
|
||||
"version": version,
|
||||
"title": title,
|
||||
"plan": plan,
|
||||
"outcomes": list(outcomes),
|
||||
"kind": kind,
|
||||
"description": description,
|
||||
"required_capabilities": required_capabilities,
|
||||
"source_bindings": source_bindings,
|
||||
"created_from_catalog_version": created_from_catalog_version,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -8,6 +8,7 @@ from wf_server import WorkflowServer
|
||||
|
||||
from ..errors import WorkflowRpcError, raise_workflow_rpc_error
|
||||
from ..models import (
|
||||
CreateArtifactFromPlanParams,
|
||||
DeleteArtifactParams,
|
||||
InspectArtifactParams,
|
||||
ListArtifactsParams,
|
||||
@@ -22,6 +23,29 @@ def register_methods(
|
||||
) -> None:
|
||||
"""Register artifact JSON-RPC methods."""
|
||||
|
||||
@entrypoint.method(
|
||||
name="workflow.artifacts.create_from_plan",
|
||||
errors=[WorkflowRpcError],
|
||||
)
|
||||
async def workflow_artifacts_create_from_plan(
|
||||
params: CreateArtifactFromPlanParams = RpcParams(),
|
||||
) -> dict[str, Any]:
|
||||
try:
|
||||
return await server.api.create_artifact_from_plan(
|
||||
artifact_id=params.artifact_id,
|
||||
version=params.version,
|
||||
title=params.title,
|
||||
plan=params.plan,
|
||||
outcomes=tuple(params.outcomes),
|
||||
kind=params.kind,
|
||||
description=params.description,
|
||||
required_capabilities=params.required_capabilities,
|
||||
source_bindings=params.source_bindings,
|
||||
created_from_catalog_version=params.created_from_catalog_version,
|
||||
)
|
||||
except (ValueError, KeyError, LookupError, FileNotFoundError) as exc:
|
||||
raise_workflow_rpc_error(exc)
|
||||
|
||||
@entrypoint.method(name="workflow.artifacts.save", errors=[WorkflowRpcError])
|
||||
async def workflow_artifacts_save(
|
||||
params: SaveArtifactParams = RpcParams(),
|
||||
|
||||
@@ -144,6 +144,19 @@ class CreateWrapperFromWorkspaceParams(RpcParamsModel):
|
||||
created_from_catalog_version: str | None = None
|
||||
|
||||
|
||||
class CreateArtifactFromPlanParams(RpcParamsModel):
|
||||
artifact_id: str = Field(min_length=1)
|
||||
version: int = Field(ge=1)
|
||||
title: str = Field(min_length=1)
|
||||
plan: dict[str, Any]
|
||||
outcomes: list[str]
|
||||
kind: Literal["workflow", "wrapper"] = "workflow"
|
||||
description: str | None = None
|
||||
required_capabilities: dict[str, dict[str, Any]] | None = None
|
||||
source_bindings: dict[str, str] | None = None
|
||||
created_from_catalog_version: str | None = None
|
||||
|
||||
|
||||
class ListArtifactsParams(RpcParamsModel):
|
||||
query: str | None = None
|
||||
kind: Literal["workflow", "wrapper"] | None = None
|
||||
|
||||
Reference in New Issue
Block a user