mirror of
https://github.com/langgenius/dify.git
synced 2026-05-03 17:08:03 +08:00
feat(api): expose workflow_run_id in human_input extra contents
This commit is contained in:
@ -1,74 +1,46 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping, Sequence
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any, TypeAlias
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
from core.workflow.nodes.human_input.entities import FormInput, UserAction
|
||||
from models.execution_extra_content import ExecutionContentType
|
||||
|
||||
|
||||
@dataclass(frozen=True, kw_only=True)
|
||||
class HumanInputFormDefinition:
|
||||
class HumanInputFormDefinition(BaseModel):
|
||||
model_config = ConfigDict(frozen=True)
|
||||
|
||||
form_id: str
|
||||
node_id: str
|
||||
node_title: str
|
||||
form_content: str
|
||||
inputs: Sequence[FormInput] = field(default_factory=list)
|
||||
actions: Sequence[UserAction] = field(default_factory=list)
|
||||
inputs: Sequence[FormInput] = Field(default_factory=list)
|
||||
actions: Sequence[UserAction] = Field(default_factory=list)
|
||||
display_in_ui: bool = False
|
||||
form_token: str | None = None
|
||||
resolved_placeholder_values: Mapping[str, Any] = field(default_factory=dict)
|
||||
|
||||
def to_dict(self) -> dict[str, Any]:
|
||||
return {
|
||||
"form_id": self.form_id,
|
||||
"node_id": self.node_id,
|
||||
"node_title": self.node_title,
|
||||
"form_content": self.form_content,
|
||||
"inputs": [item.model_dump(mode="json") for item in self.inputs],
|
||||
"actions": [item.model_dump(mode="json") for item in self.actions],
|
||||
"display_in_ui": self.display_in_ui,
|
||||
"form_token": self.form_token,
|
||||
"resolved_placeholder_values": self.resolved_placeholder_values,
|
||||
}
|
||||
resolved_placeholder_values: Mapping[str, Any] = Field(default_factory=dict)
|
||||
|
||||
|
||||
@dataclass(frozen=True, kw_only=True)
|
||||
class HumanInputFormSubmissionData:
|
||||
class HumanInputFormSubmissionData(BaseModel):
|
||||
model_config = ConfigDict(frozen=True)
|
||||
|
||||
node_id: str
|
||||
node_title: str
|
||||
rendered_content: str
|
||||
action_id: str
|
||||
action_text: str
|
||||
|
||||
def to_dict(self) -> dict[str, Any]:
|
||||
return {
|
||||
"node_id": self.node_id,
|
||||
"node_title": self.node_title,
|
||||
"rendered_content": self.rendered_content,
|
||||
"action_id": self.action_id,
|
||||
"action_text": self.action_text,
|
||||
}
|
||||
|
||||
class HumanInputContent(BaseModel):
|
||||
model_config = ConfigDict(frozen=True)
|
||||
|
||||
@dataclass(frozen=True, kw_only=True)
|
||||
class HumanInputContent:
|
||||
workflow_run_id: str
|
||||
submitted: bool
|
||||
form_definition: HumanInputFormDefinition | None = None
|
||||
form_submission_data: HumanInputFormSubmissionData | None = None
|
||||
type: ExecutionContentType = field(default=ExecutionContentType.HUMAN_INPUT, init=False)
|
||||
|
||||
def to_dict(self) -> dict[str, Any]:
|
||||
payload: dict[str, Any] = {
|
||||
"type": self.type.value,
|
||||
"submitted": self.submitted,
|
||||
}
|
||||
if self.form_definition is not None:
|
||||
payload["form_definition"] = self.form_definition.to_dict()
|
||||
if self.form_submission_data is not None:
|
||||
payload["form_submission_data"] = self.form_submission_data.to_dict()
|
||||
return payload
|
||||
type: ExecutionContentType = Field(default=ExecutionContentType.HUMAN_INPUT)
|
||||
|
||||
|
||||
ExecutionExtraContentDomainModel: TypeAlias = HumanInputContent
|
||||
|
||||
Reference in New Issue
Block a user