feat: validate composite input schemas

This commit is contained in:
lda
2026-08-13 17:01:56 +07:00 Verified
parent b216521f47
commit fa22a1a6f7
9 changed files with 1314 additions and 8 deletions
+11 -5
View File
@@ -2,7 +2,7 @@ from __future__ import annotations
from typing import Any
from pydantic import BaseModel
from pydantic import BaseModel, Field
from wf_authoring.nodes import NodeReturn, node
@@ -13,6 +13,12 @@ class SequenceInput(BaseModel):
items: list[Any]
class NonEmptySequenceInput(BaseModel):
"""Input model for operations that require at least one item."""
items: list[Any] = Field(min_length=1)
class ItemOutput(BaseModel):
"""Output model for ops that return a selected item."""
@@ -73,11 +79,11 @@ class ValuesOutput(BaseModel):
@node(
name="authoring.first_item",
input_model=SequenceInput,
input_model=NonEmptySequenceInput,
output_model=ItemOutput,
description="Select the first item from a non-empty sequence.",
)
def first_item(input: SequenceInput) -> ItemOutput:
def first_item(input: NonEmptySequenceInput) -> ItemOutput:
"""Select the first item from a non-empty sequence."""
if not input.items:
raise ValueError("first_item requires at least one item")
@@ -111,11 +117,11 @@ def first_item_maybe(input: SequenceInput) -> NodeReturn[MaybeItemOutput]:
@node(
name="authoring.last_item",
input_model=SequenceInput,
input_model=NonEmptySequenceInput,
output_model=ItemOutput,
description="Select the last item from a non-empty sequence.",
)
def last_item(input: SequenceInput) -> ItemOutput:
def last_item(input: NonEmptySequenceInput) -> ItemOutput:
"""Select the last item from a non-empty sequence."""
if not input.items:
raise ValueError("last_item requires at least one item")