mirror of
https://github.com/langgenius/dify.git
synced 2026-05-09 21:28:25 +08:00
update node params && VariablePool instantiation
This commit is contained in:
parent
11c52e90f6
commit
9acd149469
@ -175,7 +175,7 @@ class AdvancedChatAppRunner(WorkflowBasedAppRunner):
|
||||
|
||||
# Create a variable pool.
|
||||
# init variable pool
|
||||
variable_pool = VariablePool()
|
||||
variable_pool = VariablePool.from_bootstrap()
|
||||
add_variables_to_pool(
|
||||
variable_pool,
|
||||
build_bootstrap_variables(
|
||||
|
||||
@ -144,7 +144,7 @@ class PipelineRunner(WorkflowBasedAppRunner):
|
||||
)
|
||||
)
|
||||
|
||||
variable_pool = VariablePool()
|
||||
variable_pool = VariablePool.from_bootstrap()
|
||||
add_variables_to_pool(
|
||||
variable_pool,
|
||||
build_bootstrap_variables(
|
||||
|
||||
@ -106,7 +106,7 @@ class WorkflowAppRunner(WorkflowBasedAppRunner):
|
||||
workflow_id=app_config.workflow_id,
|
||||
workflow_execution_id=self.application_generate_entity.workflow_execution_id,
|
||||
)
|
||||
variable_pool = VariablePool()
|
||||
variable_pool = VariablePool.from_bootstrap()
|
||||
add_variables_to_pool(
|
||||
variable_pool,
|
||||
build_bootstrap_variables(
|
||||
|
||||
@ -188,7 +188,7 @@ class WorkflowBasedAppRunner:
|
||||
ValueError: If neither single_iteration_run nor single_loop_run is specified
|
||||
"""
|
||||
# Create initial runtime state with variable pool containing environment variables
|
||||
variable_pool = VariablePool()
|
||||
variable_pool = VariablePool.from_bootstrap()
|
||||
add_variables_to_pool(
|
||||
variable_pool,
|
||||
build_bootstrap_variables(
|
||||
|
||||
@ -33,7 +33,7 @@ from graphon.model_runtime.entities.provider_entities import (
|
||||
)
|
||||
from graphon.model_runtime.model_providers.base.ai_model import AIModel
|
||||
from graphon.model_runtime.model_providers.model_provider_factory import ModelProviderFactory
|
||||
from graphon.model_runtime.runtime import ModelRuntime
|
||||
from graphon.model_runtime import ModelRuntime
|
||||
from libs.datetime_utils import naive_utc_now
|
||||
from models.engine import db
|
||||
from models.enums import CredentialSourceType
|
||||
|
||||
@ -20,7 +20,7 @@ from graphon.model_runtime.entities.model_entities import AIModelEntity, ModelTy
|
||||
from graphon.model_runtime.entities.provider_entities import ProviderEntity
|
||||
from graphon.model_runtime.entities.rerank_entities import MultimodalRerankInput, RerankResult
|
||||
from graphon.model_runtime.entities.text_embedding_entities import EmbeddingInputType, EmbeddingResult
|
||||
from graphon.model_runtime.runtime import ModelRuntime
|
||||
from graphon.model_runtime import ModelRuntime
|
||||
from models.provider_ids import ModelProviderID
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -56,7 +56,7 @@ from models.provider_ids import ModelProviderID
|
||||
from services.feature_service import FeatureService
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from graphon.model_runtime.runtime import ModelRuntime
|
||||
from graphon.model_runtime import ModelRuntime
|
||||
|
||||
_credentials_adapter: TypeAdapter[dict[str, Any]] = TypeAdapter(dict[str, Any])
|
||||
|
||||
|
||||
@ -442,7 +442,7 @@ class DifyNodeFactory(NodeFactory):
|
||||
node_init_kwargs = node_init_kwargs_factories.get(node_type, lambda: {})()
|
||||
return node_class(
|
||||
node_id=node_id,
|
||||
config=resolved_node_data,
|
||||
data=resolved_node_data,
|
||||
graph_init_params=self.graph_init_params,
|
||||
graph_runtime_state=self.graph_runtime_state,
|
||||
**node_init_kwargs,
|
||||
|
||||
@ -32,14 +32,14 @@ class KnowledgeIndexNode(Node[KnowledgeIndexNodeData]):
|
||||
def __init__(
|
||||
self,
|
||||
node_id: str,
|
||||
config: KnowledgeIndexNodeData,
|
||||
data: KnowledgeIndexNodeData,
|
||||
*,
|
||||
graph_init_params: "GraphInitParams",
|
||||
graph_runtime_state: "GraphRuntimeState",
|
||||
) -> None:
|
||||
super().__init__(
|
||||
node_id=node_id,
|
||||
config=config,
|
||||
data=data,
|
||||
graph_init_params=graph_init_params,
|
||||
graph_runtime_state=graph_runtime_state,
|
||||
)
|
||||
|
||||
@ -71,14 +71,14 @@ class KnowledgeRetrievalNode(LLMUsageTrackingMixin, Node[KnowledgeRetrievalNodeD
|
||||
def __init__(
|
||||
self,
|
||||
node_id: str,
|
||||
config: KnowledgeRetrievalNodeData,
|
||||
data: KnowledgeRetrievalNodeData,
|
||||
*,
|
||||
graph_init_params: "GraphInitParams",
|
||||
graph_runtime_state: "GraphRuntimeState",
|
||||
) -> None:
|
||||
super().__init__(
|
||||
node_id=node_id,
|
||||
config=config,
|
||||
data=data,
|
||||
graph_init_params=graph_init_params,
|
||||
graph_runtime_state=graph_runtime_state,
|
||||
)
|
||||
|
||||
@ -411,7 +411,7 @@ class WorkflowEntry:
|
||||
raise ValueError(f"Node class not found for node type {node_type}")
|
||||
|
||||
# init variable pool
|
||||
variable_pool = VariablePool()
|
||||
variable_pool = VariablePool.from_bootstrap()
|
||||
add_variables_to_pool(variable_pool, default_system_variables())
|
||||
|
||||
# init graph context and runtime state
|
||||
|
||||
@ -45,7 +45,7 @@ dependencies = [
|
||||
|
||||
# Emerging: newer and fast-moving, use compatible pins
|
||||
"fastopenapi[flask]~=0.7.0",
|
||||
"graphon~=0.2.2",
|
||||
"graphon~=0.3.0",
|
||||
"httpx-sse~=0.4.0",
|
||||
"json-repair~=0.59.4",
|
||||
]
|
||||
|
||||
@ -88,7 +88,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _build_seeded_variable_pool(variables: Sequence[Variable]) -> VariablePool:
|
||||
variable_pool = VariablePool()
|
||||
variable_pool = VariablePool.from_bootstrap()
|
||||
add_variables_to_pool(variable_pool, variables)
|
||||
return variable_pool
|
||||
|
||||
|
||||
@ -877,7 +877,7 @@ class WorkflowService:
|
||||
)
|
||||
|
||||
else:
|
||||
variable_pool = VariablePool()
|
||||
variable_pool = VariablePool.from_bootstrap()
|
||||
add_variables_to_pool(
|
||||
variable_pool,
|
||||
build_bootstrap_variables(
|
||||
@ -1251,7 +1251,7 @@ class WorkflowService:
|
||||
node_data = HumanInputNode.validate_node_data(adapt_human_input_node_data_for_graph(node_config["data"]))
|
||||
node = HumanInputNode(
|
||||
node_id=node_config["id"],
|
||||
config=node_data,
|
||||
data=node_data,
|
||||
graph_init_params=graph_init_params,
|
||||
graph_runtime_state=graph_runtime_state,
|
||||
runtime=DifyHumanInputNodeRuntime(run_context),
|
||||
@ -1271,7 +1271,7 @@ class WorkflowService:
|
||||
draft_var_srv = WorkflowDraftVariableService(session)
|
||||
draft_var_srv.prefill_conversation_variable_default_values(workflow, user_id=user_id)
|
||||
|
||||
variable_pool = VariablePool()
|
||||
variable_pool = VariablePool.from_bootstrap()
|
||||
add_variables_to_pool(
|
||||
variable_pool,
|
||||
build_bootstrap_variables(
|
||||
@ -1659,7 +1659,7 @@ def _setup_variable_pool(
|
||||
system_variable = default_system_variables()
|
||||
|
||||
# init variable pool
|
||||
variable_pool = VariablePool()
|
||||
variable_pool = VariablePool.from_bootstrap()
|
||||
add_variables_to_pool(
|
||||
variable_pool,
|
||||
build_bootstrap_variables(
|
||||
|
||||
@ -45,7 +45,7 @@ def init_code_node(code_config: dict):
|
||||
)
|
||||
|
||||
# construct variable pool
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=build_system_variables(user_id="aaa", files=[]),
|
||||
user_inputs={},
|
||||
environment_variables=[],
|
||||
|
||||
@ -55,7 +55,7 @@ def init_http_node(config: dict):
|
||||
)
|
||||
|
||||
# construct variable pool
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=build_system_variables(user_id="aaa", files=[]),
|
||||
user_inputs={},
|
||||
environment_variables=[],
|
||||
@ -204,7 +204,7 @@ def test_custom_auth_with_empty_api_key_raises_error(setup_http_mock):
|
||||
from graphon.runtime import VariablePool
|
||||
|
||||
# Create variable pool
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=build_system_variables(user_id="test", files=[]),
|
||||
user_inputs={},
|
||||
environment_variables=[],
|
||||
@ -702,7 +702,7 @@ def test_nested_object_variable_selector(setup_http_mock):
|
||||
)
|
||||
|
||||
# Create independent variable pool for this test only
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=build_system_variables(user_id="aaa", files=[]),
|
||||
user_inputs={},
|
||||
environment_variables=[],
|
||||
|
||||
@ -53,7 +53,7 @@ def init_llm_node(config: dict) -> LLMNode:
|
||||
)
|
||||
|
||||
# construct variable pool
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=build_system_variables(
|
||||
user_id="aaa",
|
||||
app_id=app_id,
|
||||
@ -77,7 +77,7 @@ def init_llm_node(config: dict) -> LLMNode:
|
||||
|
||||
node = LLMNode(
|
||||
node_id=str(uuid.uuid4()),
|
||||
config=LLMNodeData.model_validate(config["data"]),
|
||||
data=LLMNodeData.model_validate(config["data"]),
|
||||
graph_init_params=init_params,
|
||||
graph_runtime_state=graph_runtime_state,
|
||||
credentials_provider=MagicMock(spec=CredentialsProvider),
|
||||
|
||||
@ -56,7 +56,7 @@ def init_parameter_extractor_node(config: dict, memory=None):
|
||||
)
|
||||
|
||||
# construct variable pool
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=build_system_variables(
|
||||
user_id="aaa", files=[], query="what's the weather in SF", conversation_id="abababa"
|
||||
),
|
||||
|
||||
@ -66,7 +66,7 @@ def test_execute_template_transform():
|
||||
)
|
||||
|
||||
# construct variable pool
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=build_system_variables(user_id="aaa", files=[]),
|
||||
user_inputs={},
|
||||
environment_variables=[],
|
||||
|
||||
@ -41,7 +41,7 @@ def init_tool_node(config: dict):
|
||||
)
|
||||
|
||||
# construct variable pool
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=build_system_variables(user_id="aaa", files=[]),
|
||||
user_inputs={},
|
||||
environment_variables=[],
|
||||
|
||||
@ -210,7 +210,9 @@ class TestPauseStatePersistenceLayerTestContainers:
|
||||
execution_id = workflow_run_id or getattr(self, "test_workflow_run_id", None) or str(uuid.uuid4())
|
||||
|
||||
# Create variable pool
|
||||
variable_pool = VariablePool(system_variables=build_system_variables(workflow_execution_id=execution_id))
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=build_system_variables(workflow_execution_id=execution_id),
|
||||
)
|
||||
if variables:
|
||||
for (node_id, var_key), value in variables.items():
|
||||
variable_pool.add([node_id, var_key], value)
|
||||
|
||||
@ -66,7 +66,7 @@ def _mock_form_repository_with_submission(action_id: str) -> HumanInputFormRepos
|
||||
|
||||
|
||||
def _build_runtime_state(workflow_execution_id: str, app_id: str, workflow_id: str, user_id: str) -> GraphRuntimeState:
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=build_system_variables(
|
||||
workflow_execution_id=workflow_execution_id,
|
||||
app_id=app_id,
|
||||
|
||||
@ -186,7 +186,7 @@ class TestEmailDeliveryTestHandler:
|
||||
handler = EmailDeliveryTestHandler(session_factory=MagicMock())
|
||||
handler._resolve_recipients = MagicMock(return_value=["test@example.com"])
|
||||
|
||||
variable_pool = VariablePool()
|
||||
variable_pool = VariablePool.from_bootstrap()
|
||||
context = DeliveryTestContext(
|
||||
tenant_id="t1",
|
||||
app_id="a1",
|
||||
|
||||
@ -177,7 +177,7 @@ def test_dispatch_human_input_email_task_integration(monkeypatch: pytest.MonkeyP
|
||||
workflow_run_id = str(uuid.uuid4())
|
||||
workflow_id = str(uuid.uuid4())
|
||||
app_id = str(uuid.uuid4())
|
||||
variable_pool = VariablePool()
|
||||
variable_pool = VariablePool.from_bootstrap()
|
||||
variable_pool.add(["node1", "value"], "OK")
|
||||
_create_workflow_pause_state(
|
||||
db_session_with_containers,
|
||||
|
||||
@ -236,7 +236,7 @@ def _build_resumption_context(task_id: str) -> WorkflowResumptionContext:
|
||||
call_depth=0,
|
||||
workflow_execution_id="run-1",
|
||||
)
|
||||
runtime_state = GraphRuntimeState(variable_pool=VariablePool(), start_at=0.0)
|
||||
runtime_state = GraphRuntimeState(variable_pool=VariablePool.from_bootstrap(), start_at=0.0)
|
||||
runtime_state.register_paused_node("node-1")
|
||||
runtime_state.outputs = {"result": "value"}
|
||||
wrapper = _WorkflowGenerateEntityWrapper(entity=generate_entity)
|
||||
|
||||
@ -132,7 +132,7 @@ class TestAdvancedChatGenerateTaskPipeline:
|
||||
pipeline._task_state.answer = "partial answer"
|
||||
pipeline._workflow_run_id = "run-id"
|
||||
pipeline._graph_runtime_state = GraphRuntimeState(
|
||||
variable_pool=VariablePool(system_variables=build_system_variables(workflow_execution_id="run-id")),
|
||||
variable_pool=VariablePool.from_bootstrap(system_variables=build_system_variables(workflow_execution_id="run-id")),
|
||||
start_at=0.0,
|
||||
total_tokens=7,
|
||||
node_run_steps=3,
|
||||
@ -372,7 +372,7 @@ class TestAdvancedChatGenerateTaskPipeline:
|
||||
pipeline = _make_pipeline()
|
||||
pipeline._workflow_run_id = "run-id"
|
||||
pipeline._graph_runtime_state = GraphRuntimeState(
|
||||
variable_pool=VariablePool(system_variables=build_system_variables(workflow_execution_id="run-id")),
|
||||
variable_pool=VariablePool.from_bootstrap(system_variables=build_system_variables(workflow_execution_id="run-id")),
|
||||
start_at=0.0,
|
||||
)
|
||||
pipeline._workflow_response_converter.workflow_finish_to_stream_response = lambda **kwargs: "finish"
|
||||
@ -583,7 +583,7 @@ class TestAdvancedChatGenerateTaskPipeline:
|
||||
self.items = items
|
||||
|
||||
graph_runtime_state = GraphRuntimeState(
|
||||
variable_pool=VariablePool(system_variables=build_system_variables(workflow_execution_id="run-id")),
|
||||
variable_pool=VariablePool.from_bootstrap(system_variables=build_system_variables(workflow_execution_id="run-id")),
|
||||
start_at=0.0,
|
||||
)
|
||||
|
||||
@ -617,7 +617,7 @@ class TestAdvancedChatGenerateTaskPipeline:
|
||||
def test_handle_message_end_event_applies_output_moderation(self, monkeypatch):
|
||||
pipeline = _make_pipeline()
|
||||
pipeline._graph_runtime_state = GraphRuntimeState(
|
||||
variable_pool=VariablePool(system_variables=build_system_variables(workflow_execution_id="run-id")),
|
||||
variable_pool=VariablePool.from_bootstrap(system_variables=build_system_variables(workflow_execution_id="run-id")),
|
||||
start_at=0.0,
|
||||
)
|
||||
pipeline._base_task_pipeline.handle_output_moderation_when_task_finished = lambda answer: "safe"
|
||||
|
||||
@ -9,7 +9,7 @@ from graphon.runtime import GraphRuntimeState, VariablePool
|
||||
|
||||
|
||||
def _make_state(workflow_run_id: str | None) -> GraphRuntimeState:
|
||||
variable_pool = VariablePool()
|
||||
variable_pool = VariablePool.from_bootstrap()
|
||||
add_variables_to_pool(variable_pool, build_system_variables(workflow_execution_id=workflow_run_id))
|
||||
return GraphRuntimeState(variable_pool=variable_pool, start_at=0.0)
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ def _build_converter():
|
||||
workflow_id="wf-1",
|
||||
workflow_execution_id="run-1",
|
||||
)
|
||||
runtime_state = GraphRuntimeState(variable_pool=VariablePool(), start_at=0.0)
|
||||
runtime_state = GraphRuntimeState(variable_pool=VariablePool.from_bootstrap(), start_at=0.0)
|
||||
app_entity = SimpleNamespace(
|
||||
task_id="task-1",
|
||||
app_config=SimpleNamespace(app_id="app-1", tenant_id="tenant-1"),
|
||||
|
||||
@ -16,7 +16,7 @@ def _build_converter() -> WorkflowResponseConverter:
|
||||
workflow_id="wf-1",
|
||||
workflow_execution_id="run-1",
|
||||
)
|
||||
runtime_state = GraphRuntimeState(variable_pool=VariablePool(), start_at=0.0)
|
||||
runtime_state = GraphRuntimeState(variable_pool=VariablePool.from_bootstrap(), start_at=0.0)
|
||||
app_entity = SimpleNamespace(
|
||||
task_id="task-1",
|
||||
app_config=SimpleNamespace(app_id="app-1", tenant_id="tenant-1"),
|
||||
|
||||
@ -271,7 +271,8 @@ def test_run_normal_path_builds_graph(mocker):
|
||||
def add(self, selector, value):
|
||||
return None
|
||||
|
||||
mocker.patch.object(module, "VariablePool", return_value=FakeVariablePool())
|
||||
fake_pool = FakeVariablePool()
|
||||
mocker.patch("graphon.runtime.VariablePool.from_bootstrap", return_value=fake_pool)
|
||||
|
||||
workflow_entry = MagicMock()
|
||||
workflow_entry.graph_engine = MagicMock()
|
||||
|
||||
@ -58,7 +58,7 @@ class _StubToolNode(Node[_StubToolNodeData]):
|
||||
def __init__(
|
||||
self,
|
||||
node_id: str,
|
||||
config: _StubToolNodeData,
|
||||
data: _StubToolNodeData,
|
||||
*,
|
||||
graph_init_params,
|
||||
graph_runtime_state,
|
||||
@ -66,7 +66,7 @@ class _StubToolNode(Node[_StubToolNodeData]):
|
||||
) -> None:
|
||||
super().__init__(
|
||||
node_id=node_id,
|
||||
config=config,
|
||||
data=data,
|
||||
graph_init_params=graph_init_params,
|
||||
graph_runtime_state=graph_runtime_state,
|
||||
)
|
||||
@ -167,7 +167,7 @@ def _build_graph(runtime_state: GraphRuntimeState, *, pause_on: str | None) -> G
|
||||
|
||||
|
||||
def _build_runtime_state(run_id: str) -> GraphRuntimeState:
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=build_system_variables(user_id="user", app_id="app", workflow_id="workflow"),
|
||||
user_inputs={},
|
||||
conversation_variables=[],
|
||||
|
||||
@ -54,7 +54,7 @@ class TestWorkflowBasedAppRunner:
|
||||
runner = WorkflowBasedAppRunner(queue_manager=SimpleNamespace(), app_id="app")
|
||||
|
||||
runtime_state = GraphRuntimeState(
|
||||
variable_pool=VariablePool(system_variables=default_system_variables()),
|
||||
variable_pool=VariablePool.from_bootstrap(system_variables=default_system_variables()),
|
||||
start_at=0.0,
|
||||
)
|
||||
|
||||
@ -93,7 +93,7 @@ class TestWorkflowBasedAppRunner:
|
||||
def test_get_graph_and_variable_pool_for_single_node_run(self, monkeypatch):
|
||||
runner = WorkflowBasedAppRunner(queue_manager=SimpleNamespace(), app_id="app")
|
||||
graph_runtime_state = GraphRuntimeState(
|
||||
variable_pool=VariablePool(system_variables=default_system_variables()),
|
||||
variable_pool=VariablePool.from_bootstrap(system_variables=default_system_variables()),
|
||||
start_at=0.0,
|
||||
)
|
||||
|
||||
@ -162,7 +162,7 @@ class TestWorkflowBasedAppRunner:
|
||||
app_id="app",
|
||||
)
|
||||
graph_runtime_state = GraphRuntimeState(
|
||||
variable_pool=VariablePool(system_variables=default_system_variables()),
|
||||
variable_pool=VariablePool.from_bootstrap(system_variables=default_system_variables()),
|
||||
start_at=0.0,
|
||||
)
|
||||
|
||||
@ -241,7 +241,7 @@ class TestWorkflowBasedAppRunner:
|
||||
|
||||
runner = WorkflowBasedAppRunner(queue_manager=_QueueManager(), app_id="app")
|
||||
graph_runtime_state = GraphRuntimeState(
|
||||
variable_pool=VariablePool(system_variables=default_system_variables()),
|
||||
variable_pool=VariablePool.from_bootstrap(system_variables=default_system_variables()),
|
||||
start_at=0.0,
|
||||
)
|
||||
graph_runtime_state.register_paused_node("node-1")
|
||||
@ -284,7 +284,7 @@ class TestWorkflowBasedAppRunner:
|
||||
|
||||
runner = WorkflowBasedAppRunner(queue_manager=_QueueManager(), app_id="app")
|
||||
graph_runtime_state = GraphRuntimeState(
|
||||
variable_pool=VariablePool(system_variables=default_system_variables()),
|
||||
variable_pool=VariablePool.from_bootstrap(system_variables=default_system_variables()),
|
||||
start_at=0.0,
|
||||
)
|
||||
workflow_entry = SimpleNamespace(graph_engine=SimpleNamespace(graph_runtime_state=graph_runtime_state))
|
||||
@ -423,7 +423,7 @@ class TestWorkflowBasedAppRunner:
|
||||
|
||||
runner = WorkflowBasedAppRunner(queue_manager=_QueueManager(), app_id="app")
|
||||
graph_runtime_state = GraphRuntimeState(
|
||||
variable_pool=VariablePool(system_variables=default_system_variables()),
|
||||
variable_pool=VariablePool.from_bootstrap(system_variables=default_system_variables()),
|
||||
start_at=0.0,
|
||||
)
|
||||
workflow_entry = SimpleNamespace(graph_engine=SimpleNamespace(graph_runtime_state=graph_runtime_state))
|
||||
|
||||
@ -16,7 +16,7 @@ from models.workflow import Workflow
|
||||
|
||||
|
||||
def _make_graph_state():
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=default_system_variables(),
|
||||
user_inputs={},
|
||||
environment_variables=[],
|
||||
|
||||
@ -95,7 +95,7 @@ class TestWorkflowGenerateTaskPipeline:
|
||||
def test_to_blocking_response_falls_back_to_human_input_required_when_pause_event_missing(self):
|
||||
pipeline = _make_pipeline()
|
||||
pipeline._graph_runtime_state = GraphRuntimeState(
|
||||
variable_pool=VariablePool(system_variables=build_system_variables(workflow_execution_id="run-id")),
|
||||
variable_pool=VariablePool.from_bootstrap(system_variables=build_system_variables(workflow_execution_id="run-id")),
|
||||
start_at=0.0,
|
||||
total_tokens=5,
|
||||
node_run_steps=2,
|
||||
@ -283,7 +283,7 @@ class TestWorkflowGenerateTaskPipeline:
|
||||
pipeline = _make_pipeline()
|
||||
pipeline._workflow_execution_id = "run-id"
|
||||
pipeline._graph_runtime_state = GraphRuntimeState(
|
||||
variable_pool=VariablePool(system_variables=build_system_variables(workflow_execution_id="run-id")),
|
||||
variable_pool=VariablePool.from_bootstrap(system_variables=build_system_variables(workflow_execution_id="run-id")),
|
||||
start_at=0.0,
|
||||
)
|
||||
pipeline._workflow_response_converter.workflow_finish_to_stream_response = lambda **kwargs: "finish"
|
||||
@ -725,7 +725,7 @@ class TestWorkflowGenerateTaskPipeline:
|
||||
pipeline = _make_pipeline()
|
||||
pipeline._workflow_execution_id = "run-id"
|
||||
pipeline._graph_runtime_state = GraphRuntimeState(
|
||||
variable_pool=VariablePool(system_variables=build_system_variables(workflow_execution_id="run-id")),
|
||||
variable_pool=VariablePool.from_bootstrap(system_variables=build_system_variables(workflow_execution_id="run-id")),
|
||||
start_at=0.0,
|
||||
)
|
||||
|
||||
@ -753,7 +753,7 @@ class TestWorkflowGenerateTaskPipeline:
|
||||
pipeline = _make_pipeline()
|
||||
pipeline._workflow_execution_id = "run-id"
|
||||
pipeline._graph_runtime_state = GraphRuntimeState(
|
||||
variable_pool=VariablePool(system_variables=build_system_variables(workflow_execution_id="run-id")),
|
||||
variable_pool=VariablePool.from_bootstrap(system_variables=build_system_variables(workflow_execution_id="run-id")),
|
||||
start_at=0.0,
|
||||
)
|
||||
pipeline._handle_ping_event = lambda event, **kwargs: iter(["ping"])
|
||||
@ -769,7 +769,7 @@ class TestWorkflowGenerateTaskPipeline:
|
||||
def test_process_stream_response_main_match_paths_and_cleanup(self):
|
||||
pipeline = _make_pipeline()
|
||||
pipeline._graph_runtime_state = GraphRuntimeState(
|
||||
variable_pool=VariablePool(system_variables=build_system_variables(workflow_execution_id="run-id")),
|
||||
variable_pool=VariablePool.from_bootstrap(system_variables=build_system_variables(workflow_execution_id="run-id")),
|
||||
start_at=0.0,
|
||||
)
|
||||
pipeline._base_task_pipeline.queue_manager.listen = lambda: iter(
|
||||
|
||||
@ -21,7 +21,7 @@ class TestTriggerPostLayer:
|
||||
)
|
||||
runtime_state = SimpleNamespace(
|
||||
outputs={"answer": "ok"},
|
||||
variable_pool=VariablePool(system_variables=build_system_variables(workflow_execution_id="run-1")),
|
||||
variable_pool=VariablePool.from_bootstrap(system_variables=build_system_variables(workflow_execution_id="run-1")),
|
||||
total_tokens=12,
|
||||
)
|
||||
|
||||
@ -60,7 +60,7 @@ class TestTriggerPostLayer:
|
||||
def test_on_event_handles_missing_trigger_log(self):
|
||||
runtime_state = SimpleNamespace(
|
||||
outputs={},
|
||||
variable_pool=VariablePool(system_variables=build_system_variables(workflow_execution_id="run-1")),
|
||||
variable_pool=VariablePool.from_bootstrap(system_variables=build_system_variables(workflow_execution_id="run-1")),
|
||||
total_tokens=0,
|
||||
)
|
||||
|
||||
@ -91,7 +91,7 @@ class TestTriggerPostLayer:
|
||||
def test_on_event_ignores_non_status_events(self):
|
||||
runtime_state = SimpleNamespace(
|
||||
outputs={},
|
||||
variable_pool=VariablePool(system_variables=build_system_variables(workflow_execution_id="run-1")),
|
||||
variable_pool=VariablePool.from_bootstrap(system_variables=build_system_variables(workflow_execution_id="run-1")),
|
||||
total_tokens=0,
|
||||
)
|
||||
|
||||
|
||||
@ -8,9 +8,9 @@ from graphon.enums import BuiltinNodeTypes
|
||||
|
||||
|
||||
class DummyNode:
|
||||
def __init__(self, *, node_id, config, graph_init_params, graph_runtime_state, **kwargs):
|
||||
def __init__(self, *, node_id, data, graph_init_params, graph_runtime_state, **kwargs):
|
||||
self.id = node_id
|
||||
self.config = config
|
||||
self.data = data
|
||||
self.graph_init_params = graph_init_params
|
||||
self.graph_runtime_state = graph_runtime_state
|
||||
self.kwargs = kwargs
|
||||
|
||||
@ -60,7 +60,7 @@ def _make_layer(
|
||||
workflow_execution_id="run-id",
|
||||
conversation_id="conv-id",
|
||||
)
|
||||
runtime_state = GraphRuntimeState(variable_pool=VariablePool(system_variables=system_variables), start_at=0.0)
|
||||
runtime_state = GraphRuntimeState(variable_pool=VariablePool.from_bootstrap(system_variables=system_variables), start_at=0.0)
|
||||
read_only_state = ReadOnlyGraphRuntimeStateWrapper(runtime_state)
|
||||
|
||||
application_generate_entity = WorkflowAppGenerateEntity.model_construct(
|
||||
|
||||
@ -142,8 +142,7 @@ def test_model_provider_factory_get_provider_schema_delegates_to_provider_lookup
|
||||
|
||||
def test_model_provider_factory_raises_for_unknown_provider() -> None:
|
||||
factory = ModelProviderFactory(
|
||||
model_runtime=_FakeModelRuntime(
|
||||
[
|
||||
model_runtime=_FakeModelRuntime([
|
||||
_build_provider(
|
||||
provider="langgenius/openai/openai",
|
||||
provider_name="openai",
|
||||
@ -258,8 +257,7 @@ def test_model_provider_factory_validates_provider_credentials() -> None:
|
||||
|
||||
def test_model_provider_factory_provider_credentials_validate_requires_schema() -> None:
|
||||
factory = ModelProviderFactory(
|
||||
model_runtime=_FakeModelRuntime(
|
||||
[
|
||||
model_runtime=_FakeModelRuntime([
|
||||
_build_provider(
|
||||
provider="langgenius/openai/openai",
|
||||
provider_name="openai",
|
||||
@ -314,8 +312,7 @@ def test_model_provider_factory_validates_model_credentials() -> None:
|
||||
|
||||
def test_model_provider_factory_model_credentials_validate_requires_schema() -> None:
|
||||
factory = ModelProviderFactory(
|
||||
model_runtime=_FakeModelRuntime(
|
||||
[
|
||||
model_runtime=_FakeModelRuntime([
|
||||
_build_provider(
|
||||
provider="langgenius/openai/openai",
|
||||
provider_name="openai",
|
||||
@ -387,8 +384,7 @@ def test_model_provider_factory_builds_model_type_instances(
|
||||
expected_type: type[object],
|
||||
) -> None:
|
||||
factory = ModelProviderFactory(
|
||||
model_runtime=_FakeModelRuntime(
|
||||
[
|
||||
model_runtime=_FakeModelRuntime([
|
||||
_build_provider(
|
||||
provider="langgenius/openai/openai",
|
||||
provider_name="openai",
|
||||
@ -405,8 +401,7 @@ def test_model_provider_factory_builds_model_type_instances(
|
||||
|
||||
def test_model_provider_factory_rejects_unsupported_model_type() -> None:
|
||||
factory = ModelProviderFactory(
|
||||
model_runtime=_FakeModelRuntime(
|
||||
[
|
||||
model_runtime=_FakeModelRuntime([
|
||||
_build_provider(
|
||||
provider="langgenius/openai/openai",
|
||||
provider_name="openai",
|
||||
|
||||
@ -76,7 +76,7 @@ def _build_variable_pool(
|
||||
system_variables: list[Variable] | None = None,
|
||||
environment_variables: list[Variable] | None = None,
|
||||
) -> VariablePool:
|
||||
variable_pool = VariablePool()
|
||||
variable_pool = VariablePool.from_bootstrap()
|
||||
add_variables_to_pool(
|
||||
variable_pool,
|
||||
build_bootstrap_variables(
|
||||
|
||||
@ -96,7 +96,7 @@ class MockNodeFactory(DifyNodeFactory):
|
||||
if node_type == BuiltinNodeTypes.CODE:
|
||||
mock_instance = mock_class(
|
||||
node_id=node_id,
|
||||
config=resolved_node_data,
|
||||
data=resolved_node_data,
|
||||
graph_init_params=self.graph_init_params,
|
||||
graph_runtime_state=self.graph_runtime_state,
|
||||
mock_config=self.mock_config,
|
||||
@ -106,7 +106,7 @@ class MockNodeFactory(DifyNodeFactory):
|
||||
elif node_type == BuiltinNodeTypes.HTTP_REQUEST:
|
||||
mock_instance = mock_class(
|
||||
node_id=node_id,
|
||||
config=resolved_node_data,
|
||||
data=resolved_node_data,
|
||||
graph_init_params=self.graph_init_params,
|
||||
graph_runtime_state=self.graph_runtime_state,
|
||||
mock_config=self.mock_config,
|
||||
@ -122,7 +122,7 @@ class MockNodeFactory(DifyNodeFactory):
|
||||
}:
|
||||
mock_instance = mock_class(
|
||||
node_id=node_id,
|
||||
config=resolved_node_data,
|
||||
data=resolved_node_data,
|
||||
graph_init_params=self.graph_init_params,
|
||||
graph_runtime_state=self.graph_runtime_state,
|
||||
mock_config=self.mock_config,
|
||||
@ -132,7 +132,7 @@ class MockNodeFactory(DifyNodeFactory):
|
||||
else:
|
||||
mock_instance = mock_class(
|
||||
node_id=node_id,
|
||||
config=resolved_node_data,
|
||||
data=resolved_node_data,
|
||||
graph_init_params=self.graph_init_params,
|
||||
graph_runtime_state=self.graph_runtime_state,
|
||||
mock_config=self.mock_config,
|
||||
|
||||
@ -56,7 +56,7 @@ class MockNodeMixin:
|
||||
def __init__(
|
||||
self,
|
||||
node_id: str,
|
||||
config: Any,
|
||||
data: Any,
|
||||
*,
|
||||
graph_init_params: "GraphInitParams",
|
||||
graph_runtime_state: "GraphRuntimeState",
|
||||
@ -98,7 +98,7 @@ class MockNodeMixin:
|
||||
|
||||
super().__init__(
|
||||
node_id=node_id,
|
||||
config=config,
|
||||
data=data,
|
||||
graph_init_params=graph_init_params,
|
||||
graph_runtime_state=graph_runtime_state,
|
||||
**kwargs,
|
||||
|
||||
@ -111,7 +111,7 @@ class StaticRepo(HumanInputFormRepository):
|
||||
|
||||
|
||||
def _build_runtime_state() -> GraphRuntimeState:
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=build_system_variables(
|
||||
user_id="user",
|
||||
app_id="app",
|
||||
@ -140,7 +140,7 @@ def _build_graph(runtime_state: GraphRuntimeState, repo: HumanInputFormRepositor
|
||||
start_config = {"id": "start", "data": StartNodeData(title="Start", variables=[]).model_dump()}
|
||||
start_node = StartNode(
|
||||
node_id=start_config["id"],
|
||||
config=StartNodeData(title="Start", variables=[]),
|
||||
data=StartNodeData(title="Start", variables=[]),
|
||||
graph_init_params=graph_init_params,
|
||||
graph_runtime_state=runtime_state,
|
||||
)
|
||||
@ -155,7 +155,7 @@ def _build_graph(runtime_state: GraphRuntimeState, repo: HumanInputFormRepositor
|
||||
human_a_config = {"id": "human_a", "data": human_data.model_dump()}
|
||||
human_a = HumanInputNode(
|
||||
node_id=human_a_config["id"],
|
||||
config=human_data,
|
||||
data=human_data,
|
||||
graph_init_params=graph_init_params,
|
||||
graph_runtime_state=runtime_state,
|
||||
form_repository=repo,
|
||||
@ -165,7 +165,7 @@ def _build_graph(runtime_state: GraphRuntimeState, repo: HumanInputFormRepositor
|
||||
human_b_config = {"id": "human_b", "data": human_data.model_dump()}
|
||||
human_b = HumanInputNode(
|
||||
node_id=human_b_config["id"],
|
||||
config=human_data,
|
||||
data=human_data,
|
||||
graph_init_params=graph_init_params,
|
||||
graph_runtime_state=runtime_state,
|
||||
form_repository=repo,
|
||||
@ -183,7 +183,7 @@ def _build_graph(runtime_state: GraphRuntimeState, repo: HumanInputFormRepositor
|
||||
end_config = {"id": "end", "data": end_data.model_dump()}
|
||||
end_node = EndNode(
|
||||
node_id=end_config["id"],
|
||||
config=end_data,
|
||||
data=end_data,
|
||||
graph_init_params=graph_init_params,
|
||||
graph_runtime_state=runtime_state,
|
||||
)
|
||||
|
||||
@ -250,7 +250,7 @@ class WorkflowRunner:
|
||||
conversation_variables.append(var)
|
||||
|
||||
root_node_id = get_default_root_node_id(graph_config)
|
||||
variable_pool = VariablePool()
|
||||
variable_pool = VariablePool.from_bootstrap()
|
||||
add_variables_to_pool(
|
||||
variable_pool,
|
||||
build_bootstrap_variables(
|
||||
|
||||
@ -48,7 +48,7 @@ def test_execute_answer():
|
||||
)
|
||||
|
||||
# construct variable pool
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=build_system_variables(user_id="aaa", files=[]),
|
||||
user_inputs={},
|
||||
environment_variables=[],
|
||||
@ -71,7 +71,7 @@ def test_execute_answer():
|
||||
node_id=str(uuid.uuid4()),
|
||||
graph_init_params=init_params,
|
||||
graph_runtime_state=graph_runtime_state,
|
||||
config=AnswerNodeData(
|
||||
data=AnswerNodeData(
|
||||
title="123",
|
||||
type="answer",
|
||||
answer="Today's weather is {{#start.weather#}}\n{{#llm.text#}}\n{{img}}\nFin.",
|
||||
|
||||
@ -79,7 +79,7 @@ def test_datasource_node_delegates_to_manager_stream(mocker):
|
||||
|
||||
node = DatasourceNode(
|
||||
node_id="n",
|
||||
config=DatasourceNodeData(
|
||||
data=DatasourceNodeData(
|
||||
type="datasource",
|
||||
version="1",
|
||||
title="Datasource",
|
||||
|
||||
@ -29,7 +29,7 @@ HTTP_REQUEST_CONFIG = HttpRequestNodeConfig(
|
||||
|
||||
def test_executor_with_json_body_and_number_variable():
|
||||
# Prepare the variable pool
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=default_system_variables(),
|
||||
user_inputs={},
|
||||
)
|
||||
@ -85,7 +85,7 @@ def test_executor_with_json_body_and_number_variable():
|
||||
|
||||
def test_executor_with_json_body_and_object_variable():
|
||||
# Prepare the variable pool
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=default_system_variables(),
|
||||
user_inputs={},
|
||||
)
|
||||
@ -143,7 +143,7 @@ def test_executor_with_json_body_and_object_variable():
|
||||
|
||||
def test_executor_with_json_body_and_nested_object_variable():
|
||||
# Prepare the variable pool
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=default_system_variables(),
|
||||
user_inputs={},
|
||||
)
|
||||
@ -201,7 +201,7 @@ def test_executor_with_json_body_and_nested_object_variable():
|
||||
|
||||
|
||||
def test_extract_selectors_from_template_with_newline():
|
||||
variable_pool = VariablePool(system_variables=default_system_variables())
|
||||
variable_pool = VariablePool.from_bootstrap(system_variables=default_system_variables())
|
||||
variable_pool.add(("node_id", "custom_query"), "line1\nline2")
|
||||
node_data = HttpRequestNodeData(
|
||||
title="Test JSON Body with Nested Object Variable",
|
||||
@ -230,7 +230,7 @@ def test_extract_selectors_from_template_with_newline():
|
||||
|
||||
def test_executor_with_form_data():
|
||||
# Prepare the variable pool
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=default_system_variables(),
|
||||
user_inputs={},
|
||||
)
|
||||
@ -320,7 +320,7 @@ def test_init_headers():
|
||||
node_data=node_data,
|
||||
timeout=timeout,
|
||||
http_request_config=HTTP_REQUEST_CONFIG,
|
||||
variable_pool=VariablePool(system_variables=default_system_variables()),
|
||||
variable_pool=VariablePool.from_bootstrap(system_variables=default_system_variables()),
|
||||
http_client=ssrf_proxy,
|
||||
file_manager=file_manager,
|
||||
)
|
||||
@ -357,7 +357,7 @@ def test_init_params():
|
||||
node_data=node_data,
|
||||
timeout=timeout,
|
||||
http_request_config=HTTP_REQUEST_CONFIG,
|
||||
variable_pool=VariablePool(system_variables=default_system_variables()),
|
||||
variable_pool=VariablePool.from_bootstrap(system_variables=default_system_variables()),
|
||||
http_client=ssrf_proxy,
|
||||
file_manager=file_manager,
|
||||
)
|
||||
@ -390,7 +390,7 @@ def test_init_params():
|
||||
|
||||
def test_empty_api_key_raises_error_bearer():
|
||||
"""Test that empty API key raises AuthorizationConfigError for bearer auth."""
|
||||
variable_pool = VariablePool(system_variables=default_system_variables())
|
||||
variable_pool = VariablePool.from_bootstrap(system_variables=default_system_variables())
|
||||
node_data = HttpRequestNodeData(
|
||||
title="test",
|
||||
method="get",
|
||||
@ -417,7 +417,7 @@ def test_empty_api_key_raises_error_bearer():
|
||||
|
||||
def test_empty_api_key_raises_error_basic():
|
||||
"""Test that empty API key raises AuthorizationConfigError for basic auth."""
|
||||
variable_pool = VariablePool(system_variables=default_system_variables())
|
||||
variable_pool = VariablePool.from_bootstrap(system_variables=default_system_variables())
|
||||
node_data = HttpRequestNodeData(
|
||||
title="test",
|
||||
method="get",
|
||||
@ -444,7 +444,7 @@ def test_empty_api_key_raises_error_basic():
|
||||
|
||||
def test_empty_api_key_raises_error_custom():
|
||||
"""Test that empty API key raises AuthorizationConfigError for custom auth."""
|
||||
variable_pool = VariablePool(system_variables=default_system_variables())
|
||||
variable_pool = VariablePool.from_bootstrap(system_variables=default_system_variables())
|
||||
node_data = HttpRequestNodeData(
|
||||
title="test",
|
||||
method="get",
|
||||
@ -471,7 +471,7 @@ def test_empty_api_key_raises_error_custom():
|
||||
|
||||
def test_whitespace_only_api_key_raises_error():
|
||||
"""Test that whitespace-only API key raises AuthorizationConfigError."""
|
||||
variable_pool = VariablePool(system_variables=default_system_variables())
|
||||
variable_pool = VariablePool.from_bootstrap(system_variables=default_system_variables())
|
||||
node_data = HttpRequestNodeData(
|
||||
title="test",
|
||||
method="get",
|
||||
@ -498,7 +498,7 @@ def test_whitespace_only_api_key_raises_error():
|
||||
|
||||
def test_valid_api_key_works():
|
||||
"""Test that valid API key works correctly for bearer auth."""
|
||||
variable_pool = VariablePool(system_variables=default_system_variables())
|
||||
variable_pool = VariablePool.from_bootstrap(system_variables=default_system_variables())
|
||||
node_data = HttpRequestNodeData(
|
||||
title="test",
|
||||
method="get",
|
||||
@ -536,7 +536,7 @@ def test_executor_with_json_body_and_unquoted_uuid_variable():
|
||||
# UUID that triggers the json_repair truncation bug
|
||||
test_uuid = "57eeeeb1-450b-482c-81b9-4be77e95dee2"
|
||||
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=default_system_variables(),
|
||||
user_inputs={},
|
||||
)
|
||||
@ -583,7 +583,7 @@ def test_executor_with_json_body_and_unquoted_uuid_with_newlines():
|
||||
"""
|
||||
test_uuid = "57eeeeb1-450b-482c-81b9-4be77e95dee2"
|
||||
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=default_system_variables(),
|
||||
user_inputs={},
|
||||
)
|
||||
@ -624,7 +624,7 @@ def test_executor_with_json_body_and_unquoted_uuid_with_newlines():
|
||||
|
||||
def test_executor_with_json_body_preserves_numbers_and_strings():
|
||||
"""Test that numbers are preserved and string values are properly quoted."""
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=default_system_variables(),
|
||||
user_inputs={},
|
||||
)
|
||||
|
||||
@ -110,12 +110,12 @@ def _build_http_node(
|
||||
call_depth=0,
|
||||
)
|
||||
graph_runtime_state = GraphRuntimeState(
|
||||
variable_pool=VariablePool(system_variables=build_system_variables(user_id="user", files=[]), user_inputs={}),
|
||||
variable_pool=VariablePool.from_bootstrap(system_variables=build_system_variables(user_id="user", files=[]), user_inputs={}),
|
||||
start_at=time.perf_counter(),
|
||||
)
|
||||
return HttpRequestNode(
|
||||
node_id="http-node",
|
||||
config=HttpRequestNodeData.model_validate(node_data),
|
||||
data=HttpRequestNodeData.model_validate(node_data),
|
||||
graph_init_params=graph_init_params,
|
||||
graph_runtime_state=graph_runtime_state,
|
||||
http_request_config=HTTP_REQUEST_CONFIG,
|
||||
|
||||
@ -8,7 +8,7 @@ def test_render_body_template_replaces_variable_values():
|
||||
subject="Subject",
|
||||
body="Hello {{#node1.value#}} {{#url#}}",
|
||||
)
|
||||
variable_pool = VariablePool()
|
||||
variable_pool = VariablePool.from_bootstrap()
|
||||
variable_pool.add(["node1", "value"], "World")
|
||||
|
||||
result = config.render_body_template(body=config.body, url="https://example.com", variable_pool=variable_pool)
|
||||
|
||||
@ -149,7 +149,7 @@ def _build_human_input_node(
|
||||
)
|
||||
return HumanInputNode(
|
||||
node_id=node_id,
|
||||
config=typed_node_data,
|
||||
data=typed_node_data,
|
||||
graph_init_params=graph_init_params,
|
||||
graph_runtime_state=graph_runtime_state,
|
||||
runtime=runtime,
|
||||
@ -427,7 +427,7 @@ class TestHumanInputNodeVariableResolution:
|
||||
"""Tests for resolving variable-based defaults in HumanInputNode."""
|
||||
|
||||
def test_resolves_variable_defaults(self):
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=build_system_variables(
|
||||
user_id="user",
|
||||
app_id="app",
|
||||
@ -504,7 +504,7 @@ class TestHumanInputNodeVariableResolution:
|
||||
assert params.resolved_default_values == expected_values
|
||||
|
||||
def test_debugger_falls_back_to_recipient_token_when_webapp_disabled(self):
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=build_system_variables(
|
||||
user_id="user",
|
||||
app_id="app",
|
||||
@ -565,7 +565,7 @@ class TestHumanInputNodeVariableResolution:
|
||||
assert not hasattr(pause_event.reason, "form_token")
|
||||
|
||||
def test_webapp_runtime_keeps_form_visible_in_ui_when_webapp_delivery_is_enabled(self):
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=build_system_variables(
|
||||
user_id="user",
|
||||
app_id="app",
|
||||
@ -631,7 +631,7 @@ class TestHumanInputNodeVariableResolution:
|
||||
assert params.display_in_ui is True
|
||||
|
||||
def test_debugger_debug_mode_overrides_email_recipients(self):
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=build_system_variables(
|
||||
user_id="user-123",
|
||||
app_id="app",
|
||||
@ -748,7 +748,7 @@ class TestHumanInputNodeRenderedContent:
|
||||
"""Tests for rendering submitted content."""
|
||||
|
||||
def test_replaces_outputs_placeholders_after_submission(self):
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=build_system_variables(
|
||||
user_id="user",
|
||||
app_id="app",
|
||||
|
||||
@ -40,7 +40,7 @@ def _create_human_input_node(
|
||||
)
|
||||
return HumanInputNode(
|
||||
node_id=config["id"],
|
||||
config=node_data,
|
||||
data=node_data,
|
||||
graph_init_params=graph_init_params,
|
||||
graph_runtime_state=graph_runtime_state,
|
||||
form_repository=repo,
|
||||
@ -51,7 +51,7 @@ def _create_human_input_node(
|
||||
def _build_node(form_content: str = "Please enter your name:\n\n{{#$output.name#}}") -> HumanInputNode:
|
||||
system_variables = default_system_variables()
|
||||
graph_runtime_state = GraphRuntimeState(
|
||||
variable_pool=VariablePool(system_variables=system_variables, user_inputs={}, environment_variables=[]),
|
||||
variable_pool=VariablePool.from_bootstrap(system_variables=system_variables, user_inputs={}, environment_variables=[]),
|
||||
start_at=0.0,
|
||||
)
|
||||
graph_init_params = GraphInitParams(
|
||||
@ -114,7 +114,7 @@ def _build_node(form_content: str = "Please enter your name:\n\n{{#$output.name#
|
||||
def _build_timeout_node() -> HumanInputNode:
|
||||
system_variables = default_system_variables()
|
||||
graph_runtime_state = GraphRuntimeState(
|
||||
variable_pool=VariablePool(system_variables=system_variables, user_inputs={}, environment_variables=[]),
|
||||
variable_pool=VariablePool.from_bootstrap(system_variables=system_variables, user_inputs={}, environment_variables=[]),
|
||||
start_at=0.0,
|
||||
)
|
||||
graph_init_params = GraphInitParams(
|
||||
|
||||
@ -32,7 +32,7 @@ class _MissingGraphBuilder:
|
||||
|
||||
def _build_runtime_state() -> GraphRuntimeState:
|
||||
return GraphRuntimeState(
|
||||
variable_pool=VariablePool(system_variables=default_system_variables(), user_inputs={}),
|
||||
variable_pool=VariablePool.from_bootstrap(system_variables=default_system_variables(), user_inputs={}),
|
||||
start_at=0.0,
|
||||
)
|
||||
|
||||
@ -46,7 +46,7 @@ def _build_iteration_node(
|
||||
init_params = build_test_graph_init_params(graph_config=graph_config)
|
||||
return IterationNode(
|
||||
node_id="iteration-node",
|
||||
config=IterationNodeData(
|
||||
data=IterationNodeData(
|
||||
type="iteration",
|
||||
title="Iteration",
|
||||
iterator_selector=["start", "items"],
|
||||
|
||||
@ -40,7 +40,7 @@ def mock_graph_init_params():
|
||||
@pytest.fixture
|
||||
def mock_graph_runtime_state():
|
||||
"""Create mock GraphRuntimeState."""
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=build_system_variables(user_id=str(uuid.uuid4()), files=[]),
|
||||
user_inputs={},
|
||||
environment_variables=[],
|
||||
@ -102,7 +102,7 @@ def _build_node(
|
||||
) -> KnowledgeIndexNode:
|
||||
return KnowledgeIndexNode(
|
||||
node_id=node_id,
|
||||
config=(
|
||||
data=(
|
||||
node_data
|
||||
if isinstance(node_data, KnowledgeIndexNodeData)
|
||||
else KnowledgeIndexNodeData.model_validate(node_data)
|
||||
|
||||
@ -46,7 +46,7 @@ def mock_graph_init_params():
|
||||
@pytest.fixture
|
||||
def mock_graph_runtime_state():
|
||||
"""Create mock GraphRuntimeState."""
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=build_system_variables(user_id=str(uuid.uuid4()), files=[]),
|
||||
user_inputs={},
|
||||
environment_variables=[],
|
||||
@ -117,7 +117,7 @@ class TestKnowledgeRetrievalNode:
|
||||
# Act
|
||||
node = KnowledgeRetrievalNode(
|
||||
node_id=node_id,
|
||||
config=KnowledgeRetrievalNodeData.model_validate(config["data"]),
|
||||
data=KnowledgeRetrievalNodeData.model_validate(config["data"]),
|
||||
graph_init_params=mock_graph_init_params,
|
||||
graph_runtime_state=mock_graph_runtime_state,
|
||||
)
|
||||
@ -146,7 +146,7 @@ class TestKnowledgeRetrievalNode:
|
||||
|
||||
node = KnowledgeRetrievalNode(
|
||||
node_id=node_id,
|
||||
config=KnowledgeRetrievalNodeData.model_validate(config["data"]),
|
||||
data=KnowledgeRetrievalNodeData.model_validate(config["data"]),
|
||||
graph_init_params=mock_graph_init_params,
|
||||
graph_runtime_state=mock_graph_runtime_state,
|
||||
)
|
||||
@ -205,7 +205,7 @@ class TestKnowledgeRetrievalNode:
|
||||
|
||||
node = KnowledgeRetrievalNode(
|
||||
node_id=node_id,
|
||||
config=KnowledgeRetrievalNodeData.model_validate(config["data"]),
|
||||
data=KnowledgeRetrievalNodeData.model_validate(config["data"]),
|
||||
graph_init_params=mock_graph_init_params,
|
||||
graph_runtime_state=mock_graph_runtime_state,
|
||||
)
|
||||
@ -249,7 +249,7 @@ class TestKnowledgeRetrievalNode:
|
||||
|
||||
node = KnowledgeRetrievalNode(
|
||||
node_id=node_id,
|
||||
config=KnowledgeRetrievalNodeData.model_validate(config["data"]),
|
||||
data=KnowledgeRetrievalNodeData.model_validate(config["data"]),
|
||||
graph_init_params=mock_graph_init_params,
|
||||
graph_runtime_state=mock_graph_runtime_state,
|
||||
)
|
||||
@ -285,7 +285,7 @@ class TestKnowledgeRetrievalNode:
|
||||
|
||||
node = KnowledgeRetrievalNode(
|
||||
node_id=node_id,
|
||||
config=KnowledgeRetrievalNodeData.model_validate(config["data"]),
|
||||
data=KnowledgeRetrievalNodeData.model_validate(config["data"]),
|
||||
graph_init_params=mock_graph_init_params,
|
||||
graph_runtime_state=mock_graph_runtime_state,
|
||||
)
|
||||
@ -320,7 +320,7 @@ class TestKnowledgeRetrievalNode:
|
||||
|
||||
node = KnowledgeRetrievalNode(
|
||||
node_id=node_id,
|
||||
config=KnowledgeRetrievalNodeData.model_validate(config["data"]),
|
||||
data=KnowledgeRetrievalNodeData.model_validate(config["data"]),
|
||||
graph_init_params=mock_graph_init_params,
|
||||
graph_runtime_state=mock_graph_runtime_state,
|
||||
)
|
||||
@ -361,7 +361,7 @@ class TestKnowledgeRetrievalNode:
|
||||
|
||||
node = KnowledgeRetrievalNode(
|
||||
node_id=node_id,
|
||||
config=KnowledgeRetrievalNodeData.model_validate(config["data"]),
|
||||
data=KnowledgeRetrievalNodeData.model_validate(config["data"]),
|
||||
graph_init_params=mock_graph_init_params,
|
||||
graph_runtime_state=mock_graph_runtime_state,
|
||||
)
|
||||
@ -400,7 +400,7 @@ class TestKnowledgeRetrievalNode:
|
||||
|
||||
node = KnowledgeRetrievalNode(
|
||||
node_id=node_id,
|
||||
config=KnowledgeRetrievalNodeData.model_validate(config["data"]),
|
||||
data=KnowledgeRetrievalNodeData.model_validate(config["data"]),
|
||||
graph_init_params=mock_graph_init_params,
|
||||
graph_runtime_state=mock_graph_runtime_state,
|
||||
)
|
||||
@ -481,7 +481,7 @@ class TestFetchDatasetRetriever:
|
||||
|
||||
node = KnowledgeRetrievalNode(
|
||||
node_id=node_id,
|
||||
config=KnowledgeRetrievalNodeData.model_validate(config["data"]),
|
||||
data=KnowledgeRetrievalNodeData.model_validate(config["data"]),
|
||||
graph_init_params=mock_graph_init_params,
|
||||
graph_runtime_state=mock_graph_runtime_state,
|
||||
)
|
||||
@ -518,7 +518,7 @@ class TestFetchDatasetRetriever:
|
||||
|
||||
node = KnowledgeRetrievalNode(
|
||||
node_id=node_id,
|
||||
config=KnowledgeRetrievalNodeData.model_validate(config["data"]),
|
||||
data=KnowledgeRetrievalNodeData.model_validate(config["data"]),
|
||||
graph_init_params=mock_graph_init_params,
|
||||
graph_runtime_state=mock_graph_runtime_state,
|
||||
)
|
||||
@ -573,7 +573,7 @@ class TestFetchDatasetRetriever:
|
||||
|
||||
node = KnowledgeRetrievalNode(
|
||||
node_id=node_id,
|
||||
config=KnowledgeRetrievalNodeData.model_validate(config["data"]),
|
||||
data=KnowledgeRetrievalNodeData.model_validate(config["data"]),
|
||||
graph_init_params=mock_graph_init_params,
|
||||
graph_runtime_state=mock_graph_runtime_state,
|
||||
)
|
||||
@ -621,7 +621,7 @@ class TestFetchDatasetRetriever:
|
||||
|
||||
node = KnowledgeRetrievalNode(
|
||||
node_id=node_id,
|
||||
config=KnowledgeRetrievalNodeData.model_validate(config["data"]),
|
||||
data=KnowledgeRetrievalNodeData.model_validate(config["data"]),
|
||||
graph_init_params=mock_graph_init_params,
|
||||
graph_runtime_state=mock_graph_runtime_state,
|
||||
)
|
||||
@ -682,7 +682,7 @@ class TestFetchDatasetRetriever:
|
||||
config = {"id": node_id, "data": node_data.model_dump()}
|
||||
node = KnowledgeRetrievalNode(
|
||||
node_id=node_id,
|
||||
config=KnowledgeRetrievalNodeData.model_validate(config["data"]),
|
||||
data=KnowledgeRetrievalNodeData.model_validate(config["data"]),
|
||||
graph_init_params=mock_graph_init_params,
|
||||
graph_runtime_state=mock_graph_runtime_state,
|
||||
)
|
||||
|
||||
@ -187,7 +187,7 @@ def graph_init_params() -> GraphInitParams:
|
||||
|
||||
@pytest.fixture
|
||||
def graph_runtime_state() -> GraphRuntimeState:
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=default_system_variables(),
|
||||
user_inputs={},
|
||||
)
|
||||
@ -208,7 +208,7 @@ def llm_node(
|
||||
http_client = mock.MagicMock()
|
||||
node = LLMNode(
|
||||
node_id="1",
|
||||
config=llm_node_data,
|
||||
data=llm_node_data,
|
||||
graph_init_params=graph_init_params,
|
||||
graph_runtime_state=graph_runtime_state,
|
||||
credentials_provider=mock_credentials_provider,
|
||||
@ -1173,7 +1173,7 @@ def llm_node_for_multimodal(llm_node_data, graph_init_params, graph_runtime_stat
|
||||
http_client = mock.MagicMock()
|
||||
node = LLMNode(
|
||||
node_id="1",
|
||||
config=llm_node_data,
|
||||
data=llm_node_data,
|
||||
graph_init_params=graph_init_params,
|
||||
graph_runtime_state=graph_runtime_state,
|
||||
credentials_provider=mock_credentials_provider,
|
||||
|
||||
@ -28,7 +28,7 @@ def _build_template_transform_node(
|
||||
)
|
||||
return TemplateTransformNode(
|
||||
node_id=node_id,
|
||||
config=typed_node_data,
|
||||
data=typed_node_data,
|
||||
graph_init_params=graph_init_params,
|
||||
graph_runtime_state=graph_runtime_state,
|
||||
**kwargs,
|
||||
|
||||
@ -39,7 +39,7 @@ def mock_graph_runtime_state():
|
||||
def test_node_uses_default_max_output_length_when_not_overridden(graph_init_params, mock_graph_runtime_state):
|
||||
node = TemplateTransformNode(
|
||||
node_id="test_node",
|
||||
config=TemplateTransformNodeData(
|
||||
data=TemplateTransformNodeData(
|
||||
title="Template Transform",
|
||||
type="template-transform",
|
||||
variables=[],
|
||||
|
||||
@ -35,7 +35,7 @@ def _build_context(graph_config: Mapping[str, object]) -> tuple[GraphInitParams,
|
||||
invoke_from="debugger",
|
||||
)
|
||||
runtime_state = GraphRuntimeState(
|
||||
variable_pool=VariablePool(system_variables=build_system_variables(user_id="user", files=[]), user_inputs={}),
|
||||
variable_pool=VariablePool.from_bootstrap(system_variables=build_system_variables(user_id="user", files=[]), user_inputs={}),
|
||||
start_at=0.0,
|
||||
)
|
||||
return init_params, runtime_state
|
||||
@ -62,7 +62,7 @@ def test_node_hydrates_data_during_initialization():
|
||||
|
||||
node = _SampleNode(
|
||||
node_id="node-1",
|
||||
config=_build_node_data(),
|
||||
data=_build_node_data(),
|
||||
graph_init_params=init_params,
|
||||
graph_runtime_state=runtime_state,
|
||||
)
|
||||
@ -82,13 +82,13 @@ def test_node_accepts_invoke_from_enum():
|
||||
invoke_from=InvokeFrom.DEBUGGER,
|
||||
)
|
||||
runtime_state = GraphRuntimeState(
|
||||
variable_pool=VariablePool(system_variables=build_system_variables(user_id="user", files=[]), user_inputs={}),
|
||||
variable_pool=VariablePool.from_bootstrap(system_variables=build_system_variables(user_id="user", files=[]), user_inputs={}),
|
||||
start_at=0.0,
|
||||
)
|
||||
|
||||
node = _SampleNode(
|
||||
node_id="node-1",
|
||||
config=_build_node_data(),
|
||||
data=_build_node_data(),
|
||||
graph_init_params=init_params,
|
||||
graph_runtime_state=runtime_state,
|
||||
)
|
||||
@ -140,7 +140,7 @@ def test_node_hydration_preserves_compatibility_extra_fields():
|
||||
|
||||
node = _SampleNode(
|
||||
node_id="node-1",
|
||||
config=node_config["data"],
|
||||
data=node_config["data"],
|
||||
graph_init_params=init_params,
|
||||
graph_runtime_state=runtime_state,
|
||||
)
|
||||
|
||||
@ -49,7 +49,7 @@ def document_extractor_node(graph_init_params):
|
||||
http_client = Mock()
|
||||
node = DocumentExtractorNode(
|
||||
node_id="test_node_id",
|
||||
config=node_data,
|
||||
data=node_data,
|
||||
graph_init_params=graph_init_params,
|
||||
graph_runtime_state=Mock(),
|
||||
http_client=http_client,
|
||||
|
||||
@ -29,7 +29,7 @@ def _build_if_else_node(
|
||||
node_id=str(uuid.uuid4()),
|
||||
graph_init_params=init_params,
|
||||
graph_runtime_state=graph_runtime_state,
|
||||
config=node_data if isinstance(node_data, IfElseNodeData) else IfElseNodeData.model_validate(node_data),
|
||||
data=node_data if isinstance(node_data, IfElseNodeData) else IfElseNodeData.model_validate(node_data),
|
||||
)
|
||||
|
||||
|
||||
@ -48,7 +48,7 @@ def test_execute_if_else_result_true():
|
||||
)
|
||||
|
||||
# construct variable pool
|
||||
pool = VariablePool(system_variables=build_system_variables(user_id="aaa", files=[]), user_inputs={})
|
||||
pool = VariablePool.from_bootstrap(system_variables=build_system_variables(user_id="aaa", files=[]), user_inputs={})
|
||||
pool.add(["start", "array_contains"], ["ab", "def"])
|
||||
pool.add(["start", "array_not_contains"], ["ac", "def"])
|
||||
pool.add(["start", "contains"], "cabcde")
|
||||
@ -148,7 +148,7 @@ def test_execute_if_else_result_false():
|
||||
)
|
||||
|
||||
# construct variable pool
|
||||
pool = VariablePool(
|
||||
pool = VariablePool.from_bootstrap(
|
||||
system_variables=build_system_variables(user_id="aaa", files=[]),
|
||||
user_inputs={},
|
||||
environment_variables=[],
|
||||
@ -305,7 +305,7 @@ def test_execute_if_else_boolean_conditions(condition: Condition):
|
||||
)
|
||||
|
||||
# construct variable pool with boolean values
|
||||
pool = VariablePool(
|
||||
pool = VariablePool.from_bootstrap(
|
||||
system_variables=build_system_variables(files=[], user_id="aaa"),
|
||||
)
|
||||
pool.add(["start", "bool_true"], True)
|
||||
@ -359,7 +359,7 @@ def test_execute_if_else_boolean_false_conditions():
|
||||
)
|
||||
|
||||
# construct variable pool with boolean values
|
||||
pool = VariablePool(
|
||||
pool = VariablePool.from_bootstrap(
|
||||
system_variables=build_system_variables(files=[], user_id="aaa"),
|
||||
)
|
||||
pool.add(["start", "bool_true"], True)
|
||||
@ -424,7 +424,7 @@ def test_execute_if_else_boolean_cases_structure():
|
||||
)
|
||||
|
||||
# construct variable pool with boolean values
|
||||
pool = VariablePool(
|
||||
pool = VariablePool.from_bootstrap(
|
||||
system_variables=build_system_variables(files=[], user_id="aaa"),
|
||||
)
|
||||
pool.add(["start", "bool_true"], True)
|
||||
|
||||
@ -22,7 +22,7 @@ from graphon.variables import ArrayFileSegment
|
||||
def _build_list_operator_node(node_data: ListOperatorNodeData, graph_init_params) -> ListOperatorNode:
|
||||
return ListOperatorNode(
|
||||
node_id="test_node_id",
|
||||
config=node_data,
|
||||
data=node_data,
|
||||
graph_init_params=graph_init_params,
|
||||
graph_runtime_state=MagicMock(),
|
||||
)
|
||||
|
||||
@ -31,7 +31,7 @@ def make_start_node(user_inputs, variables):
|
||||
|
||||
return StartNode(
|
||||
node_id="start",
|
||||
config=node_data,
|
||||
data=node_data,
|
||||
graph_init_params=build_test_graph_init_params(
|
||||
workflow_id="wf",
|
||||
graph_config={},
|
||||
@ -260,7 +260,7 @@ def test_start_node_outputs_full_variable_pool_snapshot():
|
||||
graph_runtime_state = GraphRuntimeState(variable_pool=variable_pool, start_at=time.perf_counter())
|
||||
node = StartNode(
|
||||
node_id="start",
|
||||
config=node_data,
|
||||
data=node_data,
|
||||
graph_init_params=build_test_graph_init_params(
|
||||
workflow_id="wf",
|
||||
graph_config={},
|
||||
|
||||
@ -99,7 +99,7 @@ def tool_node(monkeypatch) -> ToolNode:
|
||||
call_depth=0,
|
||||
)
|
||||
|
||||
variable_pool = VariablePool(system_variables=build_system_variables(user_id="user-id"))
|
||||
variable_pool = VariablePool.from_bootstrap(system_variables=build_system_variables(user_id="user-id"))
|
||||
graph_runtime_state = GraphRuntimeState(variable_pool=variable_pool, start_at=0.0)
|
||||
|
||||
config = graph_config["nodes"][0]
|
||||
@ -110,7 +110,7 @@ def tool_node(monkeypatch) -> ToolNode:
|
||||
|
||||
node = ToolNode(
|
||||
node_id="node-instance",
|
||||
config=ToolNodeData.model_validate(config["data"]),
|
||||
data=ToolNodeData.model_validate(config["data"]),
|
||||
graph_init_params=init_params,
|
||||
graph_runtime_state=graph_runtime_state,
|
||||
tool_file_manager_factory=tool_file_manager_factory,
|
||||
|
||||
@ -44,7 +44,7 @@ def test_trigger_event_node_run_populates_trigger_info_metadata() -> None:
|
||||
init_params, runtime_state = _build_context(graph_config={})
|
||||
node = TriggerEventNode(
|
||||
node_id="node-1",
|
||||
config=_build_node_data(),
|
||||
data=_build_node_data(),
|
||||
graph_init_params=init_params,
|
||||
graph_runtime_state=runtime_state,
|
||||
)
|
||||
|
||||
@ -52,7 +52,7 @@ def create_webhook_node(
|
||||
|
||||
node = TriggerWebhookNode(
|
||||
node_id="webhook-node-1",
|
||||
config=webhook_data,
|
||||
data=webhook_data,
|
||||
graph_init_params=graph_init_params,
|
||||
graph_runtime_state=runtime_state,
|
||||
)
|
||||
|
||||
@ -44,7 +44,7 @@ def create_webhook_node(webhook_data: WebhookData, variable_pool: VariablePool)
|
||||
)
|
||||
node = TriggerWebhookNode(
|
||||
node_id="1",
|
||||
config=webhook_data,
|
||||
data=webhook_data,
|
||||
graph_init_params=graph_init_params,
|
||||
graph_runtime_state=runtime_state,
|
||||
)
|
||||
|
||||
@ -464,7 +464,7 @@ class TestDifyNodeFactoryCreateNode:
|
||||
matched_node_class.assert_called_once()
|
||||
kwargs = matched_node_class.call_args.kwargs
|
||||
assert kwargs["node_id"] == "node-id"
|
||||
_assert_typed_node_config(kwargs["config"], node_id="node-id", node_type=BuiltinNodeTypes.START, version="9")
|
||||
_assert_typed_node_config(kwargs["data"], node_id="node-id", node_type=BuiltinNodeTypes.START, version="9")
|
||||
assert kwargs["graph_init_params"] is sentinel.graph_init_params
|
||||
assert kwargs["graph_runtime_state"] is factory.graph_runtime_state
|
||||
latest_node_class.assert_not_called()
|
||||
@ -484,7 +484,7 @@ class TestDifyNodeFactoryCreateNode:
|
||||
latest_node_class.assert_called_once()
|
||||
kwargs = latest_node_class.call_args.kwargs
|
||||
assert kwargs["node_id"] == "node-id"
|
||||
_assert_typed_node_config(kwargs["config"], node_id="node-id", node_type=BuiltinNodeTypes.START, version="9")
|
||||
_assert_typed_node_config(kwargs["data"], node_id="node-id", node_type=BuiltinNodeTypes.START, version="9")
|
||||
assert kwargs["graph_init_params"] is sentinel.graph_init_params
|
||||
assert kwargs["graph_runtime_state"] is factory.graph_runtime_state
|
||||
|
||||
@ -522,7 +522,7 @@ class TestDifyNodeFactoryCreateNode:
|
||||
assert result is created_node
|
||||
kwargs = constructor.call_args.kwargs
|
||||
assert kwargs["node_id"] == "node-id"
|
||||
_assert_typed_node_config(kwargs["config"], node_id="node-id", node_type=node_type)
|
||||
_assert_typed_node_config(kwargs["data"], node_id="node-id", node_type=node_type)
|
||||
assert kwargs["graph_init_params"] is sentinel.graph_init_params
|
||||
assert kwargs["graph_runtime_state"] is factory.graph_runtime_state
|
||||
|
||||
@ -623,7 +623,7 @@ class TestDifyNodeFactoryCreateNode:
|
||||
|
||||
constructor_kwargs = constructor.call_args.kwargs
|
||||
assert constructor_kwargs["node_id"] == "node-id"
|
||||
_assert_typed_node_config(constructor_kwargs["config"], node_id="node-id", node_type=node_type)
|
||||
_assert_typed_node_config(constructor_kwargs["data"], node_id="node-id", node_type=node_type)
|
||||
assert constructor_kwargs["graph_init_params"] is sentinel.graph_init_params
|
||||
assert constructor_kwargs["graph_runtime_state"] is factory.graph_runtime_state
|
||||
assert constructor_kwargs["credentials_provider"] is sentinel.credentials_provider
|
||||
|
||||
@ -41,7 +41,7 @@ from models.utils.file_input_compat import rebuild_serialized_graph_files_withou
|
||||
|
||||
@pytest.fixture
|
||||
def pool():
|
||||
variable_pool = VariablePool()
|
||||
variable_pool = VariablePool.from_bootstrap()
|
||||
add_variables_to_pool(
|
||||
variable_pool,
|
||||
build_system_variables(
|
||||
@ -82,7 +82,7 @@ def test_get_file_attribute(pool, file):
|
||||
|
||||
class TestVariablePool:
|
||||
def test_constructor(self):
|
||||
pool = VariablePool()
|
||||
pool = VariablePool.from_bootstrap()
|
||||
assert pool.variable_dictionary == defaultdict(dict)
|
||||
|
||||
complex_system_vars = build_system_variables(
|
||||
@ -110,7 +110,7 @@ class TestVariablePool:
|
||||
assert pool.get([CONVERSATION_VARIABLE_NODE_ID, "conv_var_1"]) is not None
|
||||
|
||||
def test_constructor_loads_legacy_bootstrap_kwargs(self):
|
||||
pool = VariablePool(
|
||||
pool = VariablePool.from_bootstrap(
|
||||
system_variables=build_system_variables(user_id="test_user_id"),
|
||||
environment_variables=[StringVariable(name="env_var", value="env-value")],
|
||||
conversation_variables=[StringVariable(name="conv_var", value="conv-value")],
|
||||
@ -139,7 +139,7 @@ class TestVariablePool:
|
||||
conversation_id="test_conv_id",
|
||||
dialogue_count=5,
|
||||
)
|
||||
pool = VariablePool()
|
||||
pool = VariablePool.from_bootstrap()
|
||||
add_variables_to_pool(pool, sys_var)
|
||||
system_values = system_variables_to_mapping(sys_var)
|
||||
|
||||
@ -259,7 +259,7 @@ class TestVariablePoolSerialization:
|
||||
}
|
||||
|
||||
# Create VariablePool
|
||||
pool = VariablePool()
|
||||
pool = VariablePool.from_bootstrap()
|
||||
add_variables_to_pool(pool, system_vars)
|
||||
add_variables_to_pool(pool, env_vars)
|
||||
add_variables_to_pool(pool, conv_vars)
|
||||
@ -302,7 +302,7 @@ class TestVariablePoolSerialization:
|
||||
conversation_id="test_conv_id",
|
||||
dialogue_count=5,
|
||||
)
|
||||
pool = VariablePool()
|
||||
pool = VariablePool.from_bootstrap()
|
||||
add_variables_to_pool(pool, sys_vars)
|
||||
json = pool.model_dump_json()
|
||||
pool2 = VariablePool.model_validate_json(json)
|
||||
@ -437,7 +437,7 @@ class TestVariablePoolSerialization:
|
||||
|
||||
|
||||
def test_get_attr():
|
||||
vp = VariablePool()
|
||||
vp = VariablePool.from_bootstrap()
|
||||
value = {"output": StringSegment(value="hello")}
|
||||
|
||||
vp.add(["node", "name"], value)
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import sys
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
@ -55,7 +56,7 @@ class TestWorkflowEntry:
|
||||
def test_mapping_user_inputs_to_variable_pool_with_system_variables(self):
|
||||
"""Test mapping system variables from user inputs to variable pool."""
|
||||
# Initialize variable pool with system variables
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=build_system_variables(
|
||||
user_id="test_user_id",
|
||||
app_id="test_app_id",
|
||||
@ -128,7 +129,7 @@ class TestWorkflowEntry:
|
||||
return NodeConfigDictAdapter.validate_python(node_config)
|
||||
|
||||
workflow = StubWorkflow()
|
||||
variable_pool = VariablePool(system_variables=default_system_variables(), user_inputs={})
|
||||
variable_pool = VariablePool.from_bootstrap(system_variables=default_system_variables(), user_inputs={})
|
||||
expected_limits = CodeNodeLimits(
|
||||
max_string_length=dify_config.CODE_MAX_STRING_LENGTH,
|
||||
max_number=dify_config.CODE_MAX_NUMBER,
|
||||
@ -157,7 +158,7 @@ class TestWorkflowEntry:
|
||||
"""Test mapping environment variables from user inputs to variable pool."""
|
||||
# Initialize variable pool with environment variables
|
||||
env_var = StringVariable(name="API_KEY", value="existing_key")
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=default_system_variables(),
|
||||
environment_variables=[env_var],
|
||||
user_inputs={},
|
||||
@ -198,7 +199,7 @@ class TestWorkflowEntry:
|
||||
"""Test mapping conversation variables from user inputs to variable pool."""
|
||||
# Initialize variable pool with conversation variables
|
||||
conv_var = StringVariable(name="last_message", value="Hello")
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=default_system_variables(),
|
||||
conversation_variables=[conv_var],
|
||||
user_inputs={},
|
||||
@ -239,7 +240,7 @@ class TestWorkflowEntry:
|
||||
def test_mapping_user_inputs_to_variable_pool_with_regular_variables(self):
|
||||
"""Test mapping regular node variables from user inputs to variable pool."""
|
||||
# Initialize empty variable pool
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=default_system_variables(),
|
||||
user_inputs={},
|
||||
)
|
||||
@ -281,7 +282,7 @@ class TestWorkflowEntry:
|
||||
|
||||
def test_mapping_user_inputs_with_file_handling(self):
|
||||
"""Test mapping file inputs from user inputs to variable pool."""
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=default_system_variables(),
|
||||
user_inputs={},
|
||||
)
|
||||
@ -340,7 +341,7 @@ class TestWorkflowEntry:
|
||||
|
||||
def test_mapping_user_inputs_missing_variable_error(self):
|
||||
"""Test that mapping raises error when required variable is missing."""
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=default_system_variables(),
|
||||
user_inputs={},
|
||||
)
|
||||
@ -366,7 +367,7 @@ class TestWorkflowEntry:
|
||||
|
||||
def test_mapping_user_inputs_with_alternative_key_format(self):
|
||||
"""Test mapping with alternative key format (without node prefix)."""
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=default_system_variables(),
|
||||
user_inputs={},
|
||||
)
|
||||
@ -396,7 +397,7 @@ class TestWorkflowEntry:
|
||||
|
||||
def test_mapping_user_inputs_with_complex_selectors(self):
|
||||
"""Test mapping with complex node variable keys."""
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=default_system_variables(),
|
||||
user_inputs={},
|
||||
)
|
||||
@ -432,7 +433,7 @@ class TestWorkflowEntry:
|
||||
|
||||
def test_mapping_user_inputs_invalid_node_variable(self):
|
||||
"""Test that mapping handles invalid node variable format."""
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=default_system_variables(),
|
||||
user_inputs={},
|
||||
)
|
||||
@ -463,7 +464,7 @@ class TestWorkflowEntry:
|
||||
env_var = StringVariable(name="API_KEY", value="existing_key")
|
||||
conv_var = StringVariable(name="session_id", value="session123")
|
||||
|
||||
variable_pool = VariablePool(
|
||||
variable_pool = VariablePool.from_bootstrap(
|
||||
system_variables=build_system_variables(
|
||||
user_id="test_user",
|
||||
app_id="test_app",
|
||||
|
||||
@ -165,7 +165,7 @@ class TestWorkflowChildEngineBuilder:
|
||||
_ = graph_config
|
||||
node = node_cls(
|
||||
node_id=root_node_id,
|
||||
config=BaseNodeData(
|
||||
data=BaseNodeData(
|
||||
type=node_cls.node_type,
|
||||
title="Child Model",
|
||||
),
|
||||
@ -334,7 +334,7 @@ class TestWorkflowEntrySingleStepRun:
|
||||
def extract_variable_selector_to_variable_mapping(**_kwargs):
|
||||
return {}
|
||||
|
||||
variable_pool = VariablePool(system_variables=default_system_variables(), user_inputs={})
|
||||
variable_pool = VariablePool.from_bootstrap(system_variables=default_system_variables(), user_inputs={})
|
||||
variable_loader = MagicMock()
|
||||
variable_loader.load_variables.return_value = [
|
||||
StringVariable(
|
||||
@ -644,7 +644,7 @@ class TestWorkflowEntryHelpers:
|
||||
|
||||
with (
|
||||
patch.object(workflow_entry, "default_system_variables", return_value=sentinel.system_variables),
|
||||
patch.object(workflow_entry, "VariablePool", return_value=sentinel.variable_pool) as variable_pool_cls,
|
||||
patch("graphon.runtime.VariablePool.from_bootstrap", return_value=sentinel.variable_pool) as variable_pool_cls,
|
||||
patch.object(workflow_entry, "add_variables_to_pool") as add_variables_to_pool,
|
||||
patch.object(
|
||||
workflow_entry, "DifyGraphInitContext", return_value=sentinel.graph_init_context
|
||||
@ -732,7 +732,7 @@ class TestWorkflowEntryHelpers:
|
||||
|
||||
with (
|
||||
patch.object(workflow_entry, "default_system_variables", return_value=sentinel.system_variables),
|
||||
patch.object(workflow_entry, "VariablePool", return_value=sentinel.variable_pool),
|
||||
patch("graphon.runtime.VariablePool.from_bootstrap", return_value=sentinel.variable_pool),
|
||||
patch.object(workflow_entry, "add_variables_to_pool"),
|
||||
patch.object(workflow_entry, "DifyGraphInitContext", return_value=sentinel.graph_init_context),
|
||||
patch.object(workflow_entry, "GraphRuntimeState", return_value=sentinel.graph_runtime_state),
|
||||
|
||||
@ -2103,7 +2103,7 @@ class TestSetupVariablePool:
|
||||
|
||||
# Act
|
||||
with (
|
||||
patch("services.workflow_service.VariablePool") as MockPool,
|
||||
patch("services.workflow_service.VariablePool.from_bootstrap") as mock_pool_from_bootstrap,
|
||||
patch("services.workflow_service.build_system_variables") as mock_build_system_variables,
|
||||
patch("services.workflow_service.build_bootstrap_variables") as mock_build_bootstrap_variables,
|
||||
patch("services.workflow_service.add_variables_to_pool") as mock_add_variables_to_pool,
|
||||
@ -2122,14 +2122,14 @@ class TestSetupVariablePool:
|
||||
)
|
||||
|
||||
# Assert — start nodes should build bootstrap variables and attach node inputs.
|
||||
MockPool.assert_called_once_with()
|
||||
mock_pool_from_bootstrap.assert_called_once_with()
|
||||
mock_build_system_variables.assert_called_once()
|
||||
mock_add_variables_to_pool.assert_called_once_with(
|
||||
MockPool.return_value,
|
||||
mock_pool_from_bootstrap.return_value,
|
||||
mock_build_bootstrap_variables.return_value,
|
||||
)
|
||||
mock_add_node_inputs_to_pool.assert_called_once_with(
|
||||
MockPool.return_value,
|
||||
mock_pool_from_bootstrap.return_value,
|
||||
node_id="start-node",
|
||||
inputs={"k": "v"},
|
||||
)
|
||||
@ -2142,7 +2142,7 @@ class TestSetupVariablePool:
|
||||
|
||||
# Act
|
||||
with (
|
||||
patch("services.workflow_service.VariablePool") as MockPool,
|
||||
patch("services.workflow_service.VariablePool.from_bootstrap") as mock_pool_from_bootstrap,
|
||||
patch("services.workflow_service.default_system_variables") as mock_default_system_variables,
|
||||
patch("services.workflow_service.build_bootstrap_variables") as mock_build_bootstrap_variables,
|
||||
patch("services.workflow_service.add_variables_to_pool") as mock_add_variables_to_pool,
|
||||
@ -2162,9 +2162,9 @@ class TestSetupVariablePool:
|
||||
|
||||
# Assert — default system variables should be used and node inputs should not be added.
|
||||
mock_default_system_variables.assert_called_once()
|
||||
MockPool.assert_called_once_with()
|
||||
mock_pool_from_bootstrap.assert_called_once_with()
|
||||
mock_add_variables_to_pool.assert_called_once_with(
|
||||
MockPool.return_value,
|
||||
mock_pool_from_bootstrap.return_value,
|
||||
mock_build_bootstrap_variables.return_value,
|
||||
)
|
||||
mock_add_node_inputs_to_pool.assert_not_called()
|
||||
@ -2180,7 +2180,7 @@ class TestSetupVariablePool:
|
||||
|
||||
# Act
|
||||
with (
|
||||
patch("services.workflow_service.VariablePool") as MockPool,
|
||||
patch("services.workflow_service.VariablePool.from_bootstrap") as mock_pool_from_bootstrap,
|
||||
patch("services.workflow_service.build_system_variables") as mock_build_system_variables,
|
||||
patch("services.workflow_service.build_bootstrap_variables"),
|
||||
patch("services.workflow_service.add_variables_to_pool"),
|
||||
@ -2199,7 +2199,7 @@ class TestSetupVariablePool:
|
||||
)
|
||||
|
||||
# Assert — chatflow system variables should include query, conversation_id and dialogue_count.
|
||||
MockPool.assert_called_once_with()
|
||||
mock_pool_from_bootstrap.assert_called_once_with()
|
||||
system_variable_values = mock_build_system_variables.call_args.args[0]
|
||||
assert system_variable_values["query"] == "what is AI?"
|
||||
assert system_variable_values["conversation_id"] == "conv-abc"
|
||||
@ -2513,7 +2513,7 @@ class TestWorkflowServiceDraftExecution:
|
||||
patch("services.workflow_service.db"),
|
||||
patch("services.workflow_service.Session"),
|
||||
patch("services.workflow_service.WorkflowDraftVariableService"),
|
||||
patch("services.workflow_service.VariablePool") as mock_pool_cls,
|
||||
patch("services.workflow_service.VariablePool.from_bootstrap") as mock_pool_cls,
|
||||
patch("services.workflow_service.default_system_variables") as mock_default_system_variables,
|
||||
patch("services.workflow_service.build_bootstrap_variables") as mock_build_bootstrap_variables,
|
||||
patch("services.workflow_service.add_variables_to_pool") as mock_add_variables_to_pool,
|
||||
@ -2737,7 +2737,7 @@ class TestWorkflowServiceHumanInputOperations:
|
||||
patch("services.workflow_service.db"),
|
||||
patch("services.workflow_service.Session"),
|
||||
patch("services.workflow_service.WorkflowDraftVariableService"),
|
||||
patch("services.workflow_service.VariablePool") as mock_pool_cls,
|
||||
patch("services.workflow_service.VariablePool.from_bootstrap") as mock_pool_cls,
|
||||
patch("services.workflow_service.DraftVarLoader"),
|
||||
patch("services.workflow_service.HumanInputNode.extract_variable_selector_to_variable_mapping"),
|
||||
patch("services.workflow_service.load_into_variable_pool"),
|
||||
|
||||
@ -124,7 +124,7 @@ def _build_resumption_context(task_id: str) -> WorkflowResumptionContext:
|
||||
call_depth=0,
|
||||
workflow_execution_id="run-1",
|
||||
)
|
||||
runtime_state = GraphRuntimeState(variable_pool=VariablePool(), start_at=0.0)
|
||||
runtime_state = GraphRuntimeState(variable_pool=VariablePool.from_bootstrap(), start_at=0.0)
|
||||
runtime_state.register_paused_node("node-1")
|
||||
runtime_state.outputs = {"result": "value"}
|
||||
wrapper = _WorkflowGenerateEntityWrapper(entity=generate_entity)
|
||||
@ -230,7 +230,7 @@ def _build_resumption_context_additional(task_id: str) -> WorkflowResumptionCont
|
||||
call_depth=0,
|
||||
workflow_execution_id="run-1",
|
||||
)
|
||||
runtime_state = GraphRuntimeState(variable_pool=VariablePool(), start_at=0.0)
|
||||
runtime_state = GraphRuntimeState(variable_pool=VariablePool.from_bootstrap(), start_at=0.0)
|
||||
runtime_state.outputs = {"answer": "ok"}
|
||||
wrapper = _WorkflowGenerateEntityWrapper(entity=generate_entity)
|
||||
return WorkflowResumptionContext(
|
||||
|
||||
@ -67,7 +67,7 @@ def _build_resumption_context(task_id: str) -> WorkflowResumptionContext:
|
||||
call_depth=0,
|
||||
workflow_execution_id="run-1",
|
||||
)
|
||||
runtime_state = GraphRuntimeState(variable_pool=VariablePool(), start_at=0.0)
|
||||
runtime_state = GraphRuntimeState(variable_pool=VariablePool.from_bootstrap(), start_at=0.0)
|
||||
runtime_state.outputs = {"answer": "ok"}
|
||||
wrapper = _WorkflowGenerateEntityWrapper(entity=generate_entity)
|
||||
return WorkflowResumptionContext(
|
||||
|
||||
@ -102,7 +102,7 @@ def test_dispatch_human_input_email_task_replaces_body_variables(monkeypatch: py
|
||||
recipients=[task_module._EmailRecipient(email="user@example.com", token="token-1")],
|
||||
)
|
||||
|
||||
variable_pool = task_module.VariablePool()
|
||||
variable_pool = task_module.VariablePool.from_bootstrap()
|
||||
variable_pool.add(["node1", "value"], "OK")
|
||||
|
||||
monkeypatch.setattr(task_module, "mail", mail)
|
||||
|
||||
@ -62,7 +62,7 @@ def build_test_variable_pool(
|
||||
node_id: str | None = None,
|
||||
inputs: Mapping[str, Any] | None = None,
|
||||
) -> VariablePool:
|
||||
variable_pool = VariablePool()
|
||||
variable_pool = VariablePool.from_bootstrap()
|
||||
add_variables_to_pool(variable_pool, variables)
|
||||
if node_id is not None and inputs is not None:
|
||||
add_node_inputs_to_pool(variable_pool, node_id=node_id, inputs=inputs)
|
||||
|
||||
8
api/uv.lock
generated
8
api/uv.lock
generated
@ -1594,7 +1594,7 @@ requires-dist = [
|
||||
{ name = "gmpy2", specifier = ">=2.3.0" },
|
||||
{ name = "google-api-python-client", specifier = ">=2.194.0" },
|
||||
{ name = "google-cloud-aiplatform", specifier = ">=1.148.1,<2.0.0" },
|
||||
{ name = "graphon", specifier = "~=0.2.2" },
|
||||
{ name = "graphon", specifier = "~=0.3.0" },
|
||||
{ name = "gunicorn", specifier = ">=25.3.0" },
|
||||
{ name = "httpx", extras = ["socks"], specifier = ">=0.28.1,<1.0.0" },
|
||||
{ name = "httpx-sse", specifier = "~=0.4.0" },
|
||||
@ -2937,7 +2937,7 @@ httpx = [
|
||||
|
||||
[[package]]
|
||||
name = "graphon"
|
||||
version = "0.2.2"
|
||||
version = "0.3.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "charset-normalizer" },
|
||||
@ -2958,9 +2958,9 @@ dependencies = [
|
||||
{ name = "unstructured", extra = ["docx", "epub", "md", "ppt", "pptx"] },
|
||||
{ name = "webvtt-py" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/08/50/e745a79c5f742f88f6011a1f7c9ba2c2f9cc1beedd982f0b192f1ab8c748/graphon-0.2.2.tar.gz", hash = "sha256:141f0de536171850f1af6f738dc66f0285aadd3c097f1dad2a038636789e0aa5", size = 236360, upload-time = "2026-04-17T08:52:28.047Z" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/bf/62/83593d6e7a139ff124711ea05882cadca7065c11a38763aa9360d7e76804/graphon-0.3.0.tar.gz", hash = "sha256:cd38f842ae3dcfa956428b952efbe2a3ea9c1581446647142accbbdeb638b876", size = 241176, upload-time = "2026-04-21T15:18:48.291Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/de/89/a6340afdaf5169d17a318e00fc685fb67ed99baa602c2cbbbf6af6a76096/graphon-0.2.2-py3-none-any.whl", hash = "sha256:754e544d08779138f99eac6547ab08559463680e2c76488b05e1c978210392b4", size = 340808, upload-time = "2026-04-17T08:52:26.5Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/b3/f7/81ee8f0368aa6a2d47f97fecc5d4a12865c987906798cbddd0e3b8387f33/graphon-0.3.0-py3-none-any.whl", hash = "sha256:9cca45ebab2a79fd4d04432f55b5b962e9e4f34fa037cc20fee7f18ec80eaa5d", size = 348486, upload-time = "2026-04-21T15:18:46.737Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user