get end node support in builder and drafts
This commit is contained in:
@@ -8,6 +8,7 @@ from .api import (
|
||||
from .models import (
|
||||
DraftChooseClause,
|
||||
DraftChooseStep,
|
||||
DraftEndStep,
|
||||
DraftForeachStep,
|
||||
DraftInterruptStep,
|
||||
DraftJoinStep,
|
||||
@@ -22,6 +23,7 @@ __all__ = [
|
||||
"DraftDiagnostic",
|
||||
"DraftChooseClause",
|
||||
"DraftChooseStep",
|
||||
"DraftEndStep",
|
||||
"DraftForeachStep",
|
||||
"DraftInterruptStep",
|
||||
"DraftJoinStep",
|
||||
|
||||
@@ -7,6 +7,7 @@ from wf_core.paths import GraphSourcePath
|
||||
|
||||
from .models import (
|
||||
DraftChooseStep,
|
||||
DraftEndStep,
|
||||
DraftForeachStep,
|
||||
DraftInterruptStep,
|
||||
DraftJoinStep,
|
||||
@@ -29,6 +30,7 @@ def build_workflow_from_draft(draft: WorkflowDraft) -> Workflow:
|
||||
input_schema=draft.input_schema,
|
||||
state_schema=draft.state_schema,
|
||||
output_schema=draft.output_schema,
|
||||
outcomes=draft.outcomes,
|
||||
)
|
||||
step_refs = {
|
||||
step_id: _add_step(builder, step_id, step)
|
||||
@@ -72,6 +74,8 @@ def _add_step(builder: WorkflowBuilder, step_id: str, step: DraftStep):
|
||||
node = JoinNode(id=step_id, type="join")
|
||||
builder.nodes.append(node)
|
||||
return node
|
||||
if isinstance(step, DraftEndStep):
|
||||
return builder.end(step.end.outcome, id=step_id)
|
||||
if isinstance(step, DraftWhenStep):
|
||||
return builder.when(
|
||||
step.when.if_,
|
||||
|
||||
@@ -20,6 +20,7 @@ STEP_KIND_KEYS = frozenset(
|
||||
"foreach",
|
||||
"interrupt",
|
||||
"join",
|
||||
"end",
|
||||
"when",
|
||||
"choose",
|
||||
"match",
|
||||
@@ -191,6 +192,26 @@ class DraftJoinStep(BaseModel):
|
||||
join: JsonObject = Field(default_factory=dict)
|
||||
|
||||
|
||||
class DraftEndPayload(BaseModel):
|
||||
"""Payload for one explicit workflow terminal outcome."""
|
||||
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
|
||||
outcome: str = Field(default="ok", min_length=1)
|
||||
|
||||
|
||||
class DraftEndStep(BaseModel):
|
||||
"""Draft step that lowers to core `EndNode`.
|
||||
|
||||
Route to this step when the workflow should finish with a non-`ok` public
|
||||
outcome. Routing directly to `__end__` remains the shorthand for `ok`.
|
||||
"""
|
||||
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
|
||||
end: DraftEndPayload = Field(default_factory=DraftEndPayload)
|
||||
|
||||
|
||||
class DraftWhenPayload(BaseModel):
|
||||
"""Payload for one boolean draft decision."""
|
||||
|
||||
@@ -267,6 +288,7 @@ DraftStep = (
|
||||
| DraftForeachStep
|
||||
| DraftInterruptStep
|
||||
| DraftJoinStep
|
||||
| DraftEndStep
|
||||
| DraftWhenStep
|
||||
| DraftChooseStep
|
||||
| DraftMatchStep
|
||||
@@ -285,6 +307,7 @@ class WorkflowDraft(BaseModel):
|
||||
input_schema: JsonObject
|
||||
state_schema: JsonObject
|
||||
output_schema: JsonObject
|
||||
outcomes: list[str] = Field(default_factory=lambda: ["ok"], min_length=1)
|
||||
output: list[InputBinding] = Field(default_factory=list)
|
||||
start: str
|
||||
steps: dict[str, DraftStep]
|
||||
|
||||
Reference in New Issue
Block a user