add the thing formally

This commit is contained in:
lda
2026-05-07 05:50:05 +07:00 Verified
parent d479af7e67
commit fa1aa58b3c
6 changed files with 67 additions and 36 deletions
+23 -1
View File
@@ -1,7 +1,7 @@
from __future__ import annotations
from dataclasses import dataclass
from typing import Generic, TypeVar
from typing import Generic, TypeVar, overload
from pydantic import BaseModel
@@ -14,3 +14,25 @@ class NodeReturn(Generic[OutputT_co]):
outcome: str
output: OutputT_co
class Nothing(BaseModel):
"""Empty output model for nodes that only choose an outcome."""
@overload
def outcome(name: str) -> NodeReturn[Nothing]: ...
@overload
def outcome(name: str, output: OutputT_co) -> NodeReturn[OutputT_co]: ...
def outcome(
name: str,
output: OutputT_co | None = None,
) -> NodeReturn[OutputT_co] | NodeReturn[Nothing]:
"""Create a node result with an optional output model."""
if output is None:
return NodeReturn(outcome=name, output=Nothing())
return NodeReturn(outcome=name, output=output)