Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

refactor(api): migrate remaining RESTX models to Pydantic (#40399)

Asuka Minato4724779fe2f7
diff --git a/api/controllers/console/app/workflow.py b/api/controllers/console/app/workflow.py
index 0597a4c2222..34755e98e7c 100644
--- a/api/controllers/console/app/workflow.py
+++ b/api/controllers/console/app/workflow.py
@@ -5,7 +5,7 @@ from datetime import datetime
from typing import Any, NotRequired, Self, TypedDict
from flask import abort, request
-from flask_restx import Resource, fields
+from flask_restx import Resource
from pydantic import (
AliasChoices,
BaseModel,
@@ -1698,14 +1698,7 @@ class DraftWorkflowTriggerRunApi(Resource):
@console_ns.doc("poll_draft_workflow_trigger_run")
@console_ns.doc(description="Poll for trigger events and execute full workflow when event arrives")
@console_ns.doc(params={"app_id": "Application ID"})
- @console_ns.expect(
- console_ns.model(
- "DraftWorkflowTriggerRunRequest",
- {
- "node_id": fields.String(required=True, description="Node ID"),
- },
- )
- )
+ @console_ns.expect(console_ns.models[DraftWorkflowTriggerRunPayload.__name__])
@console_ns.response(
200,
"Trigger event received and workflow executed successfully",
diff --git a/api/controllers/console/app/workflow_draft_variable.py b/api/controllers/console/app/workflow_draft_variable.py
index 32deabfae19..8b4841ed00d 100644
--- a/api/controllers/console/app/workflow_draft_variable.py
+++ b/api/controllers/console/app/workflow_draft_variable.py
@@ -1,11 +1,11 @@
import logging
from collections.abc import Callable
from functools import wraps
-from typing import Any, Concatenate, Self, TypedDict, override
+from typing import Any, Concatenate, Self
from uuid import UUID
from flask import Response
-from flask_restx import Resource, fields, marshal, marshal_with
+from flask_restx import Resource
from pydantic import BaseModel, ConfigDict, Field, model_validator
from sqlalchemy.orm import sessionmaker
@@ -35,10 +35,15 @@ from factories import variable_factory
from factories.file_factory import build_from_mapping, build_from_mappings
from factories.variable_factory import build_segment_with_type
from fields.base import ResponseModel
-from graphon.file import helpers as file_helpers
-from graphon.variables.segment_group import SegmentGroup
-from graphon.variables.segments import ArrayFileSegment, FileSegment, Segment
+from fields.workflow_draft_variable_fields import (
+ WorkflowDraftVariableFullContentResponse,
+ WorkflowDraftVariableListResponse,
+ WorkflowDraftVariableListWithoutValueResponse,
+ WorkflowDraftVariableResponse,
+ WorkflowDraftVariableWithoutValueResponse,
+)
from graphon.variables.types import SegmentType
+from libs.helper import dump_response
from libs.login import login_required
from models import Account, App, AppMode
from models.workflow import WorkflowDraftVariable
@@ -49,28 +54,6 @@ logger = logging.getLogger(__name__)
_file_access_controller = DatabaseFileAccessController()
-class OpaqueRawField(fields.Raw):
- @override
- def schema(self) -> dict[str, object]:
- return {"type": "object"}
-
-
-class JsonValueRawField(fields.Raw):
- @override
- def schema(self) -> dict[str, object]:
- return {
- "anyOf": [
- {"type": "string"},
- {"type": "integer"},
- {"type": "number"},
- {"type": "boolean"},
- {"type": "object", "additionalProperties": True},
- {"type": "array", "items": {}},
- {"type": "null"},
- ]
- }
-
-
class WorkflowDraftVariableListQuery(BaseModel):
page: int = Field(default=1, ge=1, le=100_000, description="Page number")
limit: int = Field(default=20, ge=1, le=100, description="Items per page")
@@ -169,63 +152,14 @@ register_schema_models(
EnvironmentVariableUpdatePayload,
)
register_response_schema_models(console_ns, SimpleResultResponse, EnvironmentVariableListResponse)
-
-
-def _convert_values_to_json_serializable_object(value: Segment):
- match value:
- case FileSegment():
- return value.value.model_dump()
- case ArrayFileSegment():
- return [i.model_dump() for i in value.value]
- case SegmentGroup():
- return [_convert_values_to_json_serializable_object(i) for i in value.value]
- case _:
- return value.value
-
-
-def _serialize_var_value(variable: WorkflowDraftVariable):
- value = variable.get_value()
- # create a copy of the value to avoid affecting the model cache.
- value = value.model_copy(deep=True)
- # Refresh the url signature before returning it to client.
- match value:
- case FileSegment():
- file = value.value
- file.remote_url = file.generate_url()
- case ArrayFileSegment():
- files = value.value
- for file in files:
- file.remote_url = file.generate_url()
- return _convert_values_to_json_serializable_object(value)
-
-
-def _serialize_variable_type(workflow_draft_var: WorkflowDraftVariable) -> str:
- value_type = workflow_draft_var.value_type
- return str(value_type.exposed_type())
-
-
-class FullContentDict(TypedDict):
- size_bytes: int | None
- value_type: str
- length: int | None
- download_url: str
-
-
-def _serialize_full_content(variable: WorkflowDraftVariable) -> FullContentDict | None:
- """Serialize full_content information for large variables."""
- if not variable.is_truncated():
- return None
-
- variable_file = variable.variable_file
- assert variable_file is not None
-
- result: FullContentDict = {
- "size_bytes": variable_file.size,
- "value_type": str(variable_file.value_type.exposed_type()),
- "length": variable_file.length,
- "download_url": file_helpers.get_signed_file_url(variable_file.upload_file_id, as_attachment=True),
- }
- return result
+register_response_schema_models(
+ console_ns,
+ WorkflowDraftVariableFullContentResponse,
+ WorkflowDraftVariableWithoutValueResponse,
+ WorkflowDraftVariableResponse,
+ WorkflowDraftVariableListWithoutValueResponse,
+ WorkflowDraftVariableListResponse,
+)
def ensure_variable_access(
@@ -241,85 +175,6 @@ def ensure_variable_access(
return variable
-_WORKFLOW_DRAFT_VARIABLE_WITHOUT_VALUE_FIELDS = {
- "id": fields.String,
- "type": fields.String(attribute=lambda model: model.get_variable_type()),
- "name": fields.String,
- "description": fields.String,
- "selector": fields.List(fields.String, attribute=lambda model: model.get_selector()),
- "value_type": fields.String(attribute=_serialize_variable_type),
- "edited": fields.Boolean(attribute=lambda model: model.edited),
- "visible": fields.Boolean,
- "is_truncated": fields.Boolean(attribute=lambda model: model.file_id is not None),
-}
-
-_WORKFLOW_DRAFT_VARIABLE_FIELDS = {
- **_WORKFLOW_DRAFT_VARIABLE_WITHOUT_VALUE_FIELDS,
- "value": JsonValueRawField(attribute=_serialize_var_value),
- "full_content": OpaqueRawField(attribute=_serialize_full_content),
-}
-
-_WORKFLOW_DRAFT_ENV_VARIABLE_FIELDS = {
- "id": fields.String,
- "type": fields.String(attribute=lambda _: "env"),
- "name": fields.String,
- "description": fields.String,
- "selector": fields.List(fields.String, attribute=lambda model: model.get_selector()),
- "value_type": fields.String(attribute=_serialize_variable_type),
- "edited": fields.Boolean(attribute=lambda model: model.edited),
- "visible": fields.Boolean,
-}
-
-_WORKFLOW_DRAFT_ENV_VARIABLE_LIST_FIELDS = {
- "items": fields.List(fields.Nested(_WORKFLOW_DRAFT_ENV_VARIABLE_FIELDS)),
-}
-
-
-def _get_items(var_list: WorkflowDraftVariableList) -> list[WorkflowDraftVariable]:
- return var_list.variables
-
-
-_WORKFLOW_DRAFT_VARIABLE_LIST_WITHOUT_VALUE_FIELDS = {
- "items": fields.List(fields.Nested(_WORKFLOW_DRAFT_VARIABLE_WITHOUT_VALUE_FIELDS), attribute=_get_items),
- "total": fields.Integer,
-}
-
-_WORKFLOW_DRAFT_VARIABLE_LIST_FIELDS = {
- "items": fields.List(fields.Nested(_WORKFLOW_DRAFT_VARIABLE_FIELDS), attribute=_get_items),
-}
-
-# Register models for flask_restx to avoid dict type issues in Swagger
-workflow_draft_variable_without_value_model = console_ns.model(
- "WorkflowDraftVariableWithoutValue", _WORKFLOW_DRAFT_VARIABLE_WITHOUT_VALUE_FIELDS
-)
-
-workflow_draft_variable_model = console_ns.model("WorkflowDraftVariable", _WORKFLOW_DRAFT_VARIABLE_FIELDS)
-
-workflow_draft_env_variable_model = console_ns.model("WorkflowDraftEnvVariable", _WORKFLOW_DRAFT_ENV_VARIABLE_FIELDS)
-
-workflow_draft_env_variable_list_fields_copy = _WORKFLOW_DRAFT_ENV_VARIABLE_LIST_FIELDS.copy()
-workflow_draft_env_variable_list_fields_copy["items"] = fields.List(fields.Nested(workflow_draft_env_variable_model))
-workflow_draft_env_variable_list_model = console_ns.model(
- "WorkflowDraftEnvVariableList", workflow_draft_env_variable_list_fields_copy
-)
-
-workflow_draft_variable_list_without_value_fields_copy = _WORKFLOW_DRAFT_VARIABLE_LIST_WITHOUT_VALUE_FIELDS.copy()
-workflow_draft_variable_list_without_value_fields_copy["items"] = fields.List(
- fields.Nested(workflow_draft_variable_without_value_model), attribute=_get_items
-)
-workflow_draft_variable_list_without_value_model = console_ns.model(
- "WorkflowDraftVariableListWithoutValue", workflow_draft_variable_list_without_value_fields_copy
-)
-
-workflow_draft_variable_list_fields_copy = _WORKFLOW_DRAFT_VARIABLE_LIST_FIELDS.copy()
-workflow_draft_variable_list_fields_copy["items"] = fields.List(
- fields.Nested(workflow_draft_variable_model), attribute=_get_items
-)
-workflow_draft_variable_list_model = console_ns.model(
- "WorkflowDraftVariableList", workflow_draft_variable_list_fields_copy
-)
-
-
def _api_prerequisite[T, **P, R](
f: Callable[Concatenate[T, Account, P], R],
) -> Callable[Concatenate[T, P], R | Response]:
@@ -355,10 +210,11 @@ class WorkflowVariableCollectionApi(Resource):
@console_ns.doc(params={"app_id": "Application ID"})
@console_ns.doc(params={"page": "Page number (1-100000)", "limit": "Number of items per page (1-100)"})
@console_ns.response(
- 200, "Workflow variables retrieved successfully", workflow_draft_variable_list_without_value_model
+ 200,
+ "Workflow variables retrieved successfully",
+ console_ns.models[WorkflowDraftVariableListWithoutValueResponse.__name__],
)
@_api_prerequisite
- @marshal_with(workflow_draft_variable_list_without_value_model)
@rbac_permission_required(RBACCheck(RBACPermission.APP_VIEW_LAYOUT, PlainApp()))
@model_validate(WorkflowDraftVariableListQuery)
def get(self, req_data: WorkflowDraftVariableListQuery, current_user: Account, app_model: App):
@@ -384,7 +240,7 @@ class WorkflowVariableCollectionApi(Resource):
user_id=current_user.id,
)
- return workflow_vars
+ return dump_response(WorkflowDraftVariableListWithoutValueResponse, workflow_vars)
@console_ns.doc("delete_workflow_variables")
@console_ns.doc(description="Delete all draft workflow variables")
@@ -421,9 +277,12 @@ class NodeVariableCollectionApi(Resource):
@console_ns.doc("get_node_variables")
@console_ns.doc(description="Get variables for a specific node")
@console_ns.doc(params={"app_id": "Application ID", "node_id": "Node ID"})
- @console_ns.response(200, "Node variables retrieved successfully", workflow_draft_variable_list_model)
+ @console_ns.response(
+ 200,
+ "Node variables retrieved successfully",
+ console_ns.models[WorkflowDraftVariableListResponse.__name__],
+ )
@_api_prerequisite
- @marshal_with(workflow_draft_variable_list_model)
@rbac_permission_required(RBACCheck(RBACPermission.APP_VIEW_LAYOUT, PlainApp()))
def get(self, current_user: Account, app_model: App, node_id: str):
validate_node_id(node_id)
@@ -433,7 +292,7 @@ class NodeVariableCollectionApi(Resource):
)
node_vars = draft_var_srv.list_node_variables(app_model.id, node_id, user_id=current_user.id)
- return node_vars
+ return dump_response(WorkflowDraftVariableListResponse, node_vars)
@console_ns.doc("delete_node_variables")
@console_ns.doc(description="Delete all variables for a specific node")
@@ -455,10 +314,13 @@ class VariableApi(Resource):
@console_ns.doc("get_variable")
@console_ns.doc(description="Get a specific workflow variable")
@console_ns.doc(params={"app_id": "Application ID", "variable_id": "Variable ID"})
- @console_ns.response(200, "Variable retrieved successfully", workflow_draft_variable_model)
+ @console_ns.response(
+ 200,
+ "Variable retrieved successfully",
+ console_ns.models[WorkflowDraftVariableResponse.__name__],
+ )
@console_ns.response(404, "Variable not found")
@_api_prerequisite
- @marshal_with(workflow_draft_variable_model)
@rbac_permission_required(RBACCheck(RBACPermission.APP_VIEW_LAYOUT, PlainApp()))
def get(self, current_user: Account, app_model: App, variable_id: UUID):
draft_var_srv = WorkflowDraftVariableService(
@@ -471,15 +333,18 @@ class VariableApi(Resource):
variable_id=variable_id_str,
current_user_id=current_user.id,
)
- return variable
+ return dump_response(WorkflowDraftVariableResponse, variable)
@console_ns.doc("update_variable")
@console_ns.doc(description="Update a workflow variable")
@console_ns.expect(console_ns.models[WorkflowDraftVariableUpdatePayload.__name__])
- @console_ns.response(200, "Variable updated successfully", workflow_draft_variable_model)
+ @console_ns.response(
+ 200,
+ "Variable updated successfully",
+ console_ns.models[WorkflowDraftVariableResponse.__name__],
+ )
@console_ns.response(404, "Variable not found")
@_api_prerequisite
- @marshal_with(workflow_draft_variable_model)
@model_validate(WorkflowDraftVariableUpdatePayload)
def patch(
self,
@@ -524,7 +389,7 @@ class VariableApi(Resource):
new_name = req_data.name
raw_value = req_data.value
if new_name is None and raw_value is None:
- return variable
+ return dump_response(WorkflowDraftVariableResponse, variable)
new_value = None
if raw_value is not None:
@@ -552,7 +417,7 @@ class VariableApi(Resource):
new_value = build_segment_with_type(variable.value_type, raw_value)
draft_var_srv.update_variable(variable, name=new_name, value=new_value)
db.session.commit()
- return variable
+ return dump_response(WorkflowDraftVariableResponse, variable)
@console_ns.doc("delete_variable")
@console_ns.doc(description="Delete a workflow variable")
@@ -580,7 +445,11 @@ class VariableResetApi(Resource):
@console_ns.doc("reset_variable")
@console_ns.doc(description="Reset a workflow variable to its default value")
@console_ns.doc(params={"app_id": "Application ID", "variable_id": "Variable ID"})
- @console_ns.response(200, "Variable reset successfully", workflow_draft_variable_model)
+ @console_ns.response(
+ 200,
+ "Variable reset successfully",
+ console_ns.models[WorkflowDraftVariableResponse.__name__],
+ )
@console_ns.response(204, "Variable reset (no content)")
@console_ns.response(404, "Variable not found")
@_api_prerequisite
@@ -607,8 +476,7 @@ class VariableResetApi(Resource):
db.session.commit()
if resetted is None:
return Response("", 204)
- else:
- return marshal(resetted, workflow_draft_variable_model)
+ return dump_response(WorkflowDraftVariableResponse, resetted)
def _get_variable_list(app_model: App, node_id: str, current_user_id: str) -> WorkflowDraftVariableList:
@@ -634,10 +502,13 @@ class ConversationVariableCollectionApi(Resource):
@console_ns.doc("get_conversation_variables")
@console_ns.doc(description="Get conversation variables for workflow")
@console_ns.doc(params={"app_id": "Application ID"})
- @console_ns.response(200, "Conversation variables retrieved successfully", workflow_draft_variable_list_model)
+ @console_ns.response(
+ 200,
+ "Conversation variables retrieved successfully",
+ console_ns.models[WorkflowDraftVariableListResponse.__name__],
+ )
@console_ns.response(404, "Draft workflow not found")
@_api_prerequisite
- @marshal_with(workflow_draft_variable_list_model)
@rbac_permission_required(RBACCheck(RBACPermission.APP_VIEW_LAYOUT, PlainApp()))
def get(self, current_user: Account, app_model: App):
# NOTE(QuantumGhost): Prefill conversation variables into the draft variables table
@@ -649,7 +520,10 @@ class ConversationVariableCollectionApi(Resource):
draft_var_srv = WorkflowDraftVariableService(db.session())
draft_var_srv.prefill_conversation_variable_default_values(draft_workflow, user_id=current_user.id)
db.session.commit()
- return _get_variable_list(app_model, CONVERSATION_VARIABLE_NODE_ID, current_user.id)
+ return dump_response(
+ WorkflowDraftVariableListResponse,
+ _get_variable_list(app_model, CONVERSATION_VARIABLE_NODE_ID, current_user.id),
+ )
@console_ns.expect(console_ns.models[ConversationVariableUpdatePayload.__name__])
@console_ns.doc("update_conversation_variables")
@@ -694,12 +568,18 @@ class SystemVariableCollectionApi(Resource):
@console_ns.doc("get_system_variables")
@console_ns.doc(description="Get system variables for workflow")
@console_ns.doc(params={"app_id": "Application ID"})
- @console_ns.response(200, "System variables retrieved successfully", workflow_draft_variable_list_model)
+ @console_ns.response(
+ 200,
+ "System variables retrieved successfully",
+ console_ns.models[WorkflowDraftVariableListResponse.__name__],
+ )
@_api_prerequisite
- @marshal_with(workflow_draft_variable_list_model)
@rbac_permission_required(RBACCheck(RBACPermission.APP_VIEW_LAYOUT, PlainApp()))
def get(self, current_user: Account, app_model: App):
- return _get_variable_list(app_model, SYSTEM_VARIABLE_NODE_ID, current_user.id)
+ return dump_response(
+ WorkflowDraftVariableListResponse,
+ _get_variable_list(app_model, SYSTEM_VARIABLE_NODE_ID, current_user.id),
+ )
@console_ns.route("/apps/<uuid:app_id>/workflows/draft/environment-variables")
diff --git a/api/controllers/console/datasets/rag_pipeline/rag_pipeline_draft_variable.py b/api/controllers/console/datasets/rag_pipeline/rag_pipeline_draft_variable.py
index b6953cd0696..336eab18c5d 100644
--- a/api/controllers/console/datasets/rag_pipeline/rag_pipeline_draft_variable.py
+++ b/api/controllers/console/datasets/rag_pipeline/rag_pipeline_draft_variable.py
@@ -5,7 +5,7 @@ from typing import Any, Concatenate, NoReturn
from uuid import UUID
from flask import Response
-from flask_restx import Resource, marshal, marshal_with
+from flask_restx import Resource
from pydantic import BaseModel, Field
from sqlalchemy.orm import sessionmaker
@@ -17,12 +17,8 @@ from controllers.console.app.error import (
DraftWorkflowNotExist,
)
from controllers.console.app.workflow_draft_variable import (
- _WORKFLOW_DRAFT_VARIABLE_FIELDS, # type: ignore[private-usage]
EnvironmentVariableListResponse,
ensure_variable_access,
- workflow_draft_variable_list_model,
- workflow_draft_variable_list_without_value_model,
- workflow_draft_variable_model,
)
from controllers.console.datasets.wraps import get_rag_pipeline
from controllers.console.wraps import (
@@ -40,7 +36,13 @@ from core.workflow.variable_prefixes import CONVERSATION_VARIABLE_NODE_ID, SYSTE
from extensions.ext_database import db
from factories.file_factory import build_from_mapping, build_from_mappings
from factories.variable_factory import build_segment_with_type
+from fields.workflow_draft_variable_fields import (
+ WorkflowDraftVariableListResponse,
+ WorkflowDraftVariableListWithoutValueResponse,
+ WorkflowDraftVariableResponse,
+)
from graphon.variables.types import SegmentType
+from libs.helper import dump_response
from libs.login import login_required
from models import Account
from models.dataset import Pipeline
@@ -97,10 +99,9 @@ class RagPipelineVariableCollectionApi(Resource):
@console_ns.response(
200,
"Workflow variables retrieved successfully",
- workflow_draft_variable_list_without_value_model,
+ console_ns.models[WorkflowDraftVariableListWithoutValueResponse.__name__],
)
@_api_prerequisite
- @marshal_with(workflow_draft_variable_list_without_value_model)
@model_validate(PaginationQuery)
def get(self, req_data: PaginationQuery, current_user: Account, pipeline: Pipeline):
"""
@@ -125,7 +126,7 @@ class RagPipelineVariableCollectionApi(Resource):
user_id=current_user.id,
)
- return workflow_vars
+ return dump_response(WorkflowDraftVariableListWithoutValueResponse, workflow_vars)
@console_ns.response(204, "Workflow variables deleted successfully")
@_api_prerequisite
@@ -158,9 +159,12 @@ def validate_node_id(node_id: str) -> NoReturn | None:
@console_ns.route("/rag/pipelines/<uuid:pipeline_id>/workflows/draft/nodes/<string:node_id>/variables")
class RagPipelineNodeVariableCollectionApi(Resource):
- @console_ns.response(200, "Node variables retrieved successfully", workflow_draft_variable_list_model)
+ @console_ns.response(
+ 200,
+ "Node variables retrieved successfully",
+ console_ns.models[WorkflowDraftVariableListResponse.__name__],
+ )
@_api_prerequisite
- @marshal_with(workflow_draft_variable_list_model)
def get(self, current_user: Account, pipeline: Pipeline, node_id: str):
validate_node_id(node_id)
with sessionmaker(bind=db.engine, expire_on_commit=False).begin() as session:
@@ -169,7 +173,7 @@ class RagPipelineNodeVariableCollectionApi(Resource):
)
node_vars = draft_var_srv.list_node_variables(pipeline.id, node_id, user_id=current_user.id)
- return node_vars
+ return dump_response(WorkflowDraftVariableListResponse, node_vars)
@console_ns.response(204, "Node variables deleted successfully")
@_api_prerequisite
@@ -186,9 +190,12 @@ class RagPipelineVariableApi(Resource):
_PATCH_NAME_FIELD = "name"
_PATCH_VALUE_FIELD = "value"
- @console_ns.response(200, "Variable retrieved successfully", workflow_draft_variable_model)
+ @console_ns.response(
+ 200,
+ "Variable retrieved successfully",
+ console_ns.models[WorkflowDraftVariableResponse.__name__],
+ )
@_api_prerequisite
- @marshal_with(workflow_draft_variable_model)
def get(self, current_user: Account, pipeline: Pipeline, variable_id: UUID):
draft_var_srv = WorkflowDraftVariableService(
session=db.session(),
@@ -200,11 +207,14 @@ class RagPipelineVariableApi(Resource):
variable_id=variable_id_str,
current_user_id=current_user.id,
)
- return variable
+ return dump_response(WorkflowDraftVariableResponse, variable)
- @console_ns.response(200, "Variable updated successfully", workflow_draft_variable_model)
+ @console_ns.response(
+ 200,
+ "Variable updated successfully",
+ console_ns.models[WorkflowDraftVariableResponse.__name__],
+ )
@_api_prerequisite
- @marshal_with(workflow_draft_variable_model)
@console_ns.expect(console_ns.models[WorkflowDraftVariablePatchPayload.__name__])
@model_validate(WorkflowDraftVariablePatchPayload)
def patch(
@@ -251,7 +261,7 @@ class RagPipelineVariableApi(Resource):
new_name = args.get(self._PATCH_NAME_FIELD, None)
raw_value = args.get(self._PATCH_VALUE_FIELD, None)
if new_name is None and raw_value is None:
- return variable
+ return dump_response(WorkflowDraftVariableResponse, variable)
new_value = None
if raw_value is not None:
@@ -279,7 +289,7 @@ class RagPipelineVariableApi(Resource):
new_value = build_segment_with_type(variable.value_type, raw_value)
draft_var_srv.update_variable(variable, name=new_name, value=new_value)
db.session.commit()
- return variable
+ return dump_response(WorkflowDraftVariableResponse, variable)
@console_ns.response(204, "Variable deleted successfully")
@_api_prerequisite
@@ -301,7 +311,11 @@ class RagPipelineVariableApi(Resource):
@console_ns.route("/rag/pipelines/<uuid:pipeline_id>/workflows/draft/variables/<uuid:variable_id>/reset")
class RagPipelineVariableResetApi(Resource):
- @console_ns.response(200, "Variable reset successfully", workflow_draft_variable_model)
+ @console_ns.response(
+ 200,
+ "Variable reset successfully",
+ console_ns.models[WorkflowDraftVariableResponse.__name__],
+ )
@console_ns.response(204, "Variable reset (no content)")
@_api_prerequisite
def put(self, current_user: Account, pipeline: Pipeline, variable_id: UUID):
@@ -327,8 +341,7 @@ class RagPipelineVariableResetApi(Resource):
db.session.commit()
if resetted is None:
return Response("", 204)
- else:
- return marshal(resetted, _WORKFLOW_DRAFT_VARIABLE_FIELDS)
+ return dump_response(WorkflowDraftVariableResponse, resetted)
def _get_variable_list(pipeline: Pipeline, node_id: str, current_user_id: str) -> WorkflowDraftVariableList:
@@ -347,11 +360,17 @@ def _get_variable_list(pipeline: Pipeline, node_id: str, current_user_id: str) -
@console_ns.route("/rag/pipelines/<uuid:pipeline_id>/workflows/draft/system-variables")
class RagPipelineSystemVariableCollectionApi(Resource):
- @console_ns.response(200, "System variables retrieved successfully", workflow_draft_variable_list_model)
+ @console_ns.response(
+ 200,
+ "System variables retrieved successfully",
+ console_ns.models[WorkflowDraftVariableListResponse.__name__],
+ )
@_api_prerequisite
- @marshal_with(workflow_draft_variable_list_model)
def get(self, current_user: Account, pipeline: Pipeline):
- return _get_variable_list(pipeline, SYSTEM_VARIABLE_NODE_ID, current_user.id)
+ return dump_response(
+ WorkflowDraftVariableListResponse,
+ _get_variable_list(pipeline, SYSTEM_VARIABLE_NODE_ID, current_user.id),
+ )
@console_ns.route("/rag/pipelines/<uuid:pipeline_id>/workflows/draft/environment-variables")
diff --git a/api/controllers/console/snippets/snippet_workflow_draft_variable.py b/api/controllers/console/snippets/snippet_workflow_draft_variable.py
index 725c168ea60..ebf456edf5c 100644
--- a/api/controllers/console/snippets/snippet_workflow_draft_variable.py
+++ b/api/controllers/console/snippets/snippet_workflow_draft_variable.py
@@ -15,7 +15,7 @@ from functools import wraps
from typing import Any, Concatenate
from flask import Response, request
-from flask_restx import Resource, marshal, marshal_with
+from flask_restx import Resource
from sqlalchemy.orm import Session, sessionmaker
from controllers.common.errors import InvalidArgumentError, NotFoundError
@@ -28,9 +28,6 @@ from controllers.console.app.workflow_draft_variable import (
WorkflowDraftVariableUpdatePayload,
ensure_variable_access,
validate_node_id,
- workflow_draft_variable_list_model,
- workflow_draft_variable_list_without_value_model,
- workflow_draft_variable_model,
)
from controllers.console.snippets.snippet_workflow import get_snippet
from controllers.console.wraps import (
@@ -46,7 +43,13 @@ from core.workflow.variable_prefixes import CONVERSATION_VARIABLE_NODE_ID, SYSTE
from extensions.ext_database import db
from factories.file_factory import build_from_mapping, build_from_mappings
from factories.variable_factory import build_segment_with_type
+from fields.workflow_draft_variable_fields import (
+ WorkflowDraftVariableListResponse,
+ WorkflowDraftVariableListWithoutValueResponse,
+ WorkflowDraftVariableResponse,
+)
from graphon.variables.types import SegmentType
+from libs.helper import dump_response
from libs.login import login_required
from models import Account
from models.snippet import CustomizedSnippet
@@ -100,11 +103,10 @@ class SnippetWorkflowVariableCollectionApi(Resource):
@console_ns.response(
200,
"Workflow variables retrieved successfully",
- workflow_draft_variable_list_without_value_model,
+ console_ns.models[WorkflowDraftVariableListWithoutValueResponse.__name__],
)
@_snippet_draft_var_prerequisite
- @marshal_with(workflow_draft_variable_list_without_value_model)
- def get(self, current_user: Account, snippet: CustomizedSnippet) -> WorkflowDraftVariableList:
+ def get(self, current_user: Account, snippet: CustomizedSnippet) -> dict[str, Any]:
args = WorkflowDraftVariableListQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore
snippet_service = _snippet_service()
@@ -121,7 +123,7 @@ class SnippetWorkflowVariableCollectionApi(Resource):
exclude_node_ids=_SNIPPET_EXCLUDED_DRAFT_VARIABLE_NODE_IDS,
)
- return workflow_vars
+ return dump_response(WorkflowDraftVariableListWithoutValueResponse, workflow_vars)
@console_ns.doc("delete_snippet_workflow_variables")
@console_ns.doc(description="Delete all draft workflow variables for the current user (snippet scope)")
@@ -138,16 +140,19 @@ class SnippetWorkflowVariableCollectionApi(Resource):
class SnippetNodeVariableCollectionApi(Resource):
@console_ns.doc("get_snippet_node_variables")
@console_ns.doc(description="Get variables for a specific node (snippet draft workflow)")
- @console_ns.response(200, "Node variables retrieved successfully", workflow_draft_variable_list_model)
+ @console_ns.response(
+ 200,
+ "Node variables retrieved successfully",
+ console_ns.models[WorkflowDraftVariableListResponse.__name__],
+ )
@_snippet_draft_var_prerequisite
- @marshal_with(workflow_draft_variable_list_model)
- def get(self, current_user: Account, snippet: CustomizedSnippet, node_id: str) -> WorkflowDraftVariableList:
+ def get(self, current_user: Account, snippet: CustomizedSnippet, node_id: str) -> dict[str, Any]:
validate_node_id(node_id)
with Session(bind=db.engine, expire_on_commit=False) as session:
draft_var_srv = WorkflowDraftVariableService(session=session)
node_vars = draft_var_srv.list_node_variables(snippet.id, node_id, user_id=current_user.id)
- return node_vars
+ return dump_response(WorkflowDraftVariableListResponse, node_vars)
@console_ns.doc("delete_snippet_node_variables")
@console_ns.doc(description="Delete all variables for a specific node (snippet draft workflow)")
@@ -165,11 +170,14 @@ class SnippetNodeVariableCollectionApi(Resource):
class SnippetVariableApi(Resource):
@console_ns.doc("get_snippet_workflow_variable")
@console_ns.doc(description="Get a specific draft workflow variable (snippet scope)")
- @console_ns.response(200, "Variable retrieved successfully", workflow_draft_variable_model)
+ @console_ns.response(
+ 200,
+ "Variable retrieved successfully",
+ console_ns.models[WorkflowDraftVariableResponse.__name__],
+ )
@console_ns.response(404, "Variable not found")
@_snippet_draft_var_prerequisite
- @marshal_with(workflow_draft_variable_model)
- def get(self, current_user: Account, snippet: CustomizedSnippet, variable_id: str) -> WorkflowDraftVariable:
+ def get(self, current_user: Account, snippet: CustomizedSnippet, variable_id: str) -> dict[str, Any]:
draft_var_srv = WorkflowDraftVariableService(session=db.session())
variable = ensure_variable_access(
variable=draft_var_srv.get_variable(variable_id=variable_id),
@@ -178,15 +186,18 @@ class SnippetVariableApi(Resource):
current_user_id=current_user.id,
)
_ensure_snippet_draft_variable_row_allowed(variable=variable, variable_id=variable_id)
- return variable
+ return dump_response(WorkflowDraftVariableResponse, variable)
@console_ns.doc("update_snippet_workflow_variable")
@console_ns.doc(description="Update a draft workflow variable (snippet scope)")
@console_ns.expect(console_ns.models[WorkflowDraftVariableUpdatePayload.__name__])
- @console_ns.response(200, "Variable updated successfully", workflow_draft_variable_model)
+ @console_ns.response(
+ 200,
+ "Variable updated successfully",
+ console_ns.models[WorkflowDraftVariableResponse.__name__],
+ )
@console_ns.response(404, "Variable not found")
@_snippet_draft_var_prerequisite
- @marshal_with(workflow_draft_variable_model)
@model_validate(WorkflowDraftVariableUpdatePayload)
def patch(
self,
@@ -194,7 +205,7 @@ class SnippetVariableApi(Resource):
current_user: Account,
snippet: CustomizedSnippet,
variable_id: str,
- ) -> WorkflowDraftVariable:
+ ) -> dict[str, Any]:
draft_var_srv = WorkflowDraftVariableService(session=db.session())
variable = ensure_variable_access(
@@ -208,7 +219,7 @@ class SnippetVariableApi(Resource):
new_name = req_data.name
raw_value = req_data.value
if new_name is None and raw_value is None:
- return variable
+ return dump_response(WorkflowDraftVariableResponse, variable)
new_value = None
if raw_value is not None:
@@ -233,7 +244,7 @@ class SnippetVariableApi(Resource):
new_value = build_segment_with_type(variable.value_type, raw_value)
draft_var_srv.update_variable(variable, name=new_name, value=new_value)
db.session.commit()
- return variable
+ return dump_response(WorkflowDraftVariableResponse, variable)
@console_ns.doc("delete_snippet_workflow_variable")
@console_ns.doc(description="Delete a draft workflow variable (snippet scope)")
@@ -258,7 +269,11 @@ class SnippetVariableApi(Resource):
class SnippetVariableResetApi(Resource):
@console_ns.doc("reset_snippet_workflow_variable")
@console_ns.doc(description="Reset a draft workflow variable to its default value (snippet scope)")
- @console_ns.response(200, "Variable reset successfully", workflow_draft_variable_model)
+ @console_ns.response(
+ 200,
+ "Variable reset successfully",
+ console_ns.models[WorkflowDraftVariableResponse.__name__],
+ )
@console_ns.response(204, "Variable reset (no content)")
@console_ns.response(404, "Variable not found")
@_snippet_draft_var_prerequisite
@@ -282,7 +297,7 @@ class SnippetVariableResetApi(Resource):
db.session.commit()
if resetted is None:
return Response("", 204)
- return marshal(resetted, workflow_draft_variable_model)
+ return dump_response(WorkflowDraftVariableResponse, resetted)
@console_ns.route("/snippets/<uuid:snippet_id>/workflows/draft/conversation-variables")
@@ -291,11 +306,14 @@ class SnippetConversationVariableCollectionApi(Resource):
@console_ns.doc(
description="Conversation variables are not used in snippet workflows; returns an empty list for API parity"
)
- @console_ns.response(200, "Conversation variables retrieved successfully", workflow_draft_variable_list_model)
+ @console_ns.response(
+ 200,
+ "Conversation variables retrieved successfully",
+ console_ns.models[WorkflowDraftVariableListResponse.__name__],
+ )
@_snippet_draft_var_prerequisite
- @marshal_with(workflow_draft_variable_list_model)
- def get(self, _current_user: Account, snippet: CustomizedSnippet) -> WorkflowDraftVariableList:
- return WorkflowDraftVariableList(variables=[])
+ def get(self, _current_user: Account, snippet: CustomizedSnippet) -> dict[str, Any]:
+ return dump_response(WorkflowDraftVariableListResponse, WorkflowDraftVariableList(variables=[]))
@console_ns.route("/snippets/<uuid:snippet_id>/workflows/draft/system-variables")
@@ -304,11 +322,14 @@ class SnippetSystemVariableCollectionApi(Resource):
@console_ns.doc(
description="System variables are not used in snippet workflows; returns an empty list for API parity"
)
- @console_ns.response(200, "System variables retrieved successfully", workflow_draft_variable_list_model)
+ @console_ns.response(
+ 200,
+ "System variables retrieved successfully",
+ console_ns.models[WorkflowDraftVariableListResponse.__name__],
+ )
@_snippet_draft_var_prerequisite
- @marshal_with(workflow_draft_variable_list_model)
- def get(self, _current_user: Account, snippet: CustomizedSnippet) -> WorkflowDraftVariableList:
- return WorkflowDraftVariableList(variables=[])
+ def get(self, _current_user: Account, snippet: CustomizedSnippet) -> dict[str, Any]:
+ return dump_response(WorkflowDraftVariableListResponse, WorkflowDraftVariableList(variables=[]))
@console_ns.route("/snippets/<uuid:snippet_id>/workflows/draft/environment-variables")
diff --git a/api/fields/workflow_draft_variable_fields.py b/api/fields/workflow_draft_variable_fields.py
new file mode 100644
index 00000000000..354082edc19
--- /dev/null
+++ b/api/fields/workflow_draft_variable_fields.py
@@ -0,0 +1,137 @@
+from __future__ import annotations
+
+from typing import Any, override
+
+from pydantic import model_validator
+
+from fields.base import ResponseModel
+from graphon.file import helpers as file_helpers
+from graphon.variables.segment_group import SegmentGroup
+from graphon.variables.segments import ArrayFileSegment, FileSegment, Segment
+from models.workflow import WorkflowDraftVariable
+
+type JSONValue = str | int | float | bool | dict[str, "JSONValue"] | list["JSONValue"] | None
+
+
+def _convert_values_to_json_serializable_object(value: Segment) -> JSONValue:
+ match value:
+ case FileSegment():
+ return value.value.model_dump()
+ case ArrayFileSegment():
+ return [item.model_dump() for item in value.value]
+ case SegmentGroup():
+ return [_convert_values_to_json_serializable_object(item) for item in value.value]
+ case _:
+ return value.value
+
+
+def _serialize_var_value(variable: WorkflowDraftVariable) -> JSONValue:
+ value = variable.get_value()
+ # Create a copy to avoid mutating the model's cached deserialized value.
+ value = value.model_copy(deep=True)
+ # Refresh URL signatures immediately before returning file values to the client.
+ match value:
+ case FileSegment():
+ value.value.remote_url = value.value.generate_url()
+ case ArrayFileSegment():
+ for file in value.value:
+ file.remote_url = file.generate_url()
+ return _convert_values_to_json_serializable_object(value)
+
+
+class WorkflowDraftVariableFullContentResponse(ResponseModel):
+ size_bytes: int | None
+ value_type: str
+ length: int | None
+ download_url: str
+
+
+def _serialize_full_content(
+ variable: WorkflowDraftVariable,
+) -> WorkflowDraftVariableFullContentResponse | None:
+ """Serialize metadata for a variable whose complete value was offloaded."""
+ if not variable.is_truncated():
+ return None
+
+ variable_file = variable.variable_file
+ assert variable_file is not None
+
+ return WorkflowDraftVariableFullContentResponse(
+ size_bytes=variable_file.size,
+ value_type=str(variable_file.value_type.exposed_type()),
+ length=variable_file.length,
+ download_url=file_helpers.get_signed_file_url(variable_file.upload_file_id, as_attachment=True),
+ )
+
+
+def _serialize_without_value(variable: WorkflowDraftVariable) -> dict[str, Any]:
+ return {
+ "id": variable.id,
+ "type": str(variable.get_variable_type()),
+ "name": variable.name,
+ "description": variable.description,
+ "selector": variable.get_selector(),
+ "value_type": str(variable.value_type.exposed_type()),
+ "edited": variable.edited,
+ "visible": variable.visible,
+ "is_truncated": variable.is_truncated(),
+ }
+
+
+class WorkflowDraftVariableWithoutValueResponse(ResponseModel):
+ id: str
+ type: str
+ name: str
+ description: str
+ selector: list[str]
+ value_type: str
+ edited: bool
+ visible: bool
+ is_truncated: bool
+
+ @model_validator(mode="before")
+ @classmethod
+ def _from_workflow_draft_variable(cls, value: Any) -> Any:
+ if isinstance(value, WorkflowDraftVariable):
+ return _serialize_without_value(value)
+ return value
+
+
+class WorkflowDraftVariableResponse(WorkflowDraftVariableWithoutValueResponse):
+ value: JSONValue
+ full_content: WorkflowDraftVariableFullContentResponse | None
+
+ @model_validator(mode="before")
+ @classmethod
+ @override
+ def _from_workflow_draft_variable(cls, value: Any) -> Any:
+ if isinstance(value, WorkflowDraftVariable):
+ return {
+ **_serialize_without_value(value),
+ "value": _serialize_var_value(value),
+ "full_content": _serialize_full_content(value),
+ }
+ return value
+
+
+class WorkflowDraftVariableListWithoutValueResponse(ResponseModel):
+ items: list[WorkflowDraftVariableWithoutValueResponse]
+ total: int | None
+
+ @model_validator(mode="before")
+ @classmethod
+ def _from_workflow_draft_variable_list(cls, value: Any) -> Any:
+ if hasattr(value, "variables") and hasattr(value, "total"):
+ return {"items": value.variables, "total": value.total}
+ return value
+
+
+class WorkflowDraftVariableListResponse(ResponseModel):
+ items: list[WorkflowDraftVariableResponse]
+
+ @model_validator(mode="before")
+ @classmethod
+ def _from_workflow_draft_variable_list(cls, value: Any) -> Any:
+ if hasattr(value, "variables"):
+ return {"items": value.variables}
+ return value
diff --git a/api/fields/workflow_run_fields.py b/api/fields/workflow_run_fields.py
index 34c43138b73..55caa4893f9 100644
--- a/api/fields/workflow_run_fields.py
+++ b/api/fields/workflow_run_fields.py
@@ -1,42 +1,23 @@
"""Workflow run response schemas for console APIs.
-Most workflow-run endpoints should document and serialize responses with the
-Pydantic models in this module. The remaining Flask-RESTX field dictionaries are
-kept only for workflow app-log endpoints that still build legacy log models.
+Workflow-run endpoints should document and serialize responses with the
+Pydantic models in this module.
"""
from __future__ import annotations
from dataclasses import dataclass
from datetime import datetime
+from enum import Enum
from typing import Any
-from flask_restx import Namespace, fields
from pydantic import AliasChoices, Field, field_validator
from sqlalchemy.orm import Session
from fields.base import ResponseModel
from fields.end_user_fields import SimpleEndUser
from fields.member_fields import SimpleAccount
-from libs.helper import TimestampField, to_timestamp
-
-workflow_run_for_log_fields = {
- "id": fields.String,
- "version": fields.String,
- "status": fields.String,
- "triggered_from": fields.String,
- "error": fields.String,
- "elapsed_time": fields.Float,
- "total_tokens": fields.Integer,
- "total_steps": fields.Integer,
- "created_at": TimestampField,
- "finished_at": TimestampField,
- "exceptions_count": fields.Integer,
-}
-
-
-def build_workflow_run_for_log_model(api_or_ns: Namespace):
- return api_or_ns.model("WorkflowRunForLog", workflow_run_for_log_fields)
+from libs.helper import to_timestamp
class WorkflowRunForLogResponse(ResponseModel):
@@ -65,6 +46,21 @@ class WorkflowRunForLogResponse(ResponseModel):
return to_timestamp(value)
+class WorkflowRunForArchivedLogResponse(ResponseModel):
+ id: str
+ status: str | None = None
+ triggered_from: str | None = None
+ elapsed_time: float | None = None
+ total_tokens: int | None = None
+
+ @field_validator("status", mode="before")
+ @classmethod
+ def _normalize_status(cls, value: Any) -> str | None:
+ if value is None or isinstance(value, str):
+ return value
+ return str(value.value if isinstance(value, Enum) else value)
+
+
class WorkflowRunForListResponse(ResponseModel):
id: str
version: str | None = None
diff --git a/api/openapi/markdown/console-openapi.md b/api/openapi/markdown/console-openapi.md
index 216419ee6f2..ba29e5160aa 100644
--- a/api/openapi/markdown/console-openapi.md
+++ b/api/openapi/markdown/console-openapi.md
@@ -3886,7 +3886,7 @@ Get conversation variables for workflow
| Code | Description | Schema |
| ---- | ----------- | ------ |
-| 200 | Conversation variables retrieved successfully | **application/json**: [WorkflowDraftVariableList](#workflowdraftvariablelist)<br> |
+| 200 | Conversation variables retrieved successfully | **application/json**: [WorkflowDraftVariableListResponse](#workflowdraftvariablelistresponse)<br> |
| 404 | Draft workflow not found | |
### [POST] /apps/{app_id}/workflows/draft/conversation-variables
@@ -4309,7 +4309,7 @@ Get variables for a specific node
| Code | Description | Schema |
| ---- | ----------- | ------ |
-| 200 | Node variables retrieved successfully | **application/json**: [WorkflowDraftVariableList](#workflowdraftvariablelist)<br> |
+| 200 | Node variables retrieved successfully | **application/json**: [WorkflowDraftVariableListResponse](#workflowdraftvariablelistresponse)<br> |
### [POST] /apps/{app_id}/workflows/draft/run
**Run draft workflow**
@@ -4417,7 +4417,7 @@ Get system variables for workflow
| Code | Description | Schema |
| ---- | ----------- | ------ |
-| 200 | System variables retrieved successfully | **application/json**: [WorkflowDraftVariableList](#workflowdraftvariablelist)<br> |
+| 200 | System variables retrieved successfully | **application/json**: [WorkflowDraftVariableListResponse](#workflowdraftvariablelistresponse)<br> |
### [POST] /apps/{app_id}/workflows/draft/trigger/run
**Poll for trigger events and execute full workflow when event arrives**
@@ -4432,7 +4432,7 @@ Get system variables for workflow
| Required | Schema |
| -------- | ------ |
-| Yes | **application/json**: [DraftWorkflowTriggerRunRequest](#draftworkflowtriggerrunrequest)<br> |
+| Yes | **application/json**: [DraftWorkflowTriggerRunPayload](#draftworkflowtriggerrunpayload)<br> |
#### Responses
@@ -4497,7 +4497,7 @@ Get draft workflow variables
| Code | Description | Schema |
| ---- | ----------- | ------ |
-| 200 | Workflow variables retrieved successfully | **application/json**: [WorkflowDraftVariableListWithoutValue](#workflowdraftvariablelistwithoutvalue)<br> |
+| 200 | Workflow variables retrieved successfully | **application/json**: [WorkflowDraftVariableListWithoutValueResponse](#workflowdraftvariablelistwithoutvalueresponse)<br> |
### [DELETE] /apps/{app_id}/workflows/draft/variables/{variable_id}
Delete a workflow variable
@@ -4530,7 +4530,7 @@ Get a specific workflow variable
| Code | Description | Schema |
| ---- | ----------- | ------ |
-| 200 | Variable retrieved successfully | **application/json**: [WorkflowDraftVariable](#workflowdraftvariable)<br> |
+| 200 | Variable retrieved successfully | **application/json**: [WorkflowDraftVariableResponse](#workflowdraftvariableresponse)<br> |
| 404 | Variable not found | |
### [PATCH] /apps/{app_id}/workflows/draft/variables/{variable_id}
@@ -4553,7 +4553,7 @@ Update a workflow variable
| Code | Description | Schema |
| ---- | ----------- | ------ |
-| 200 | Variable updated successfully | **application/json**: [WorkflowDraftVariable](#workflowdraftvariable)<br> |
+| 200 | Variable updated successfully | **application/json**: [WorkflowDraftVariableResponse](#workflowdraftvariableresponse)<br> |
| 404 | Variable not found | |
### [PUT] /apps/{app_id}/workflows/draft/variables/{variable_id}/reset
@@ -4570,7 +4570,7 @@ Reset a workflow variable to its default value
| Code | Description | Schema |
| ---- | ----------- | ------ |
-| 200 | Variable reset successfully | **application/json**: [WorkflowDraftVariable](#workflowdraftvariable)<br> |
+| 200 | Variable reset successfully | **application/json**: [WorkflowDraftVariableResponse](#workflowdraftvariableresponse)<br> |
| 204 | Variable reset (no content) | |
| 404 | Variable not found | |
@@ -8041,7 +8041,7 @@ Update account-level Step-by-step Tour state
| Code | Description | Schema |
| ---- | ----------- | ------ |
-| 200 | Node variables retrieved successfully | **application/json**: [WorkflowDraftVariableList](#workflowdraftvariablelist)<br> |
+| 200 | Node variables retrieved successfully | **application/json**: [WorkflowDraftVariableListResponse](#workflowdraftvariablelistresponse)<br> |
### [GET] /rag/pipelines/{pipeline_id}/workflows/draft/pre-processing/parameters
**Get first step parameters of rag pipeline**
@@ -8107,7 +8107,7 @@ Update account-level Step-by-step Tour state
| Code | Description | Schema |
| ---- | ----------- | ------ |
-| 200 | System variables retrieved successfully | **application/json**: [WorkflowDraftVariableList](#workflowdraftvariablelist)<br> |
+| 200 | System variables retrieved successfully | **application/json**: [WorkflowDraftVariableListResponse](#workflowdraftvariablelistresponse)<br> |
### [DELETE] /rag/pipelines/{pipeline_id}/workflows/draft/variables
#### Parameters
@@ -8137,7 +8137,7 @@ Update account-level Step-by-step Tour state
| Code | Description | Schema |
| ---- | ----------- | ------ |
-| 200 | Workflow variables retrieved successfully | **application/json**: [WorkflowDraftVariableListWithoutValue](#workflowdraftvariablelistwithoutvalue)<br> |
+| 200 | Workflow variables retrieved successfully | **application/json**: [WorkflowDraftVariableListWithoutValueResponse](#workflowdraftvariablelistwithoutvalueresponse)<br> |
### [DELETE] /rag/pipelines/{pipeline_id}/workflows/draft/variables/{variable_id}
#### Parameters
@@ -8165,7 +8165,7 @@ Update account-level Step-by-step Tour state
| Code | Description | Schema |
| ---- | ----------- | ------ |
-| 200 | Variable retrieved successfully | **application/json**: [WorkflowDraftVariable](#workflowdraftvariable)<br> |
+| 200 | Variable retrieved successfully | **application/json**: [WorkflowDraftVariableResponse](#workflowdraftvariableresponse)<br> |
### [PATCH] /rag/pipelines/{pipeline_id}/workflows/draft/variables/{variable_id}
#### Parameters
@@ -8179,7 +8179,7 @@ Update account-level Step-by-step Tour state
| Code | Description | Schema |
| ---- | ----------- | ------ |
-| 200 | Variable updated successfully | **application/json**: [WorkflowDraftVariable](#workflowdraftvariable)<br> |
+| 200 | Variable updated successfully | **application/json**: [WorkflowDraftVariableResponse](#workflowdraftvariableresponse)<br> |
### [PUT] /rag/pipelines/{pipeline_id}/workflows/draft/variables/{variable_id}/reset
#### Parameters
@@ -8193,7 +8193,7 @@ Update account-level Step-by-step Tour state
| Code | Description | Schema |
| ---- | ----------- | ------ |
-| 200 | Variable reset successfully | **application/json**: [WorkflowDraftVariable](#workflowdraftvariable)<br> |
+| 200 | Variable reset successfully | **application/json**: [WorkflowDraftVariableResponse](#workflowdraftvariableresponse)<br> |
| 204 | Variable reset (no content) | |
### [GET] /rag/pipelines/{pipeline_id}/workflows/publish
@@ -8651,7 +8651,7 @@ Conversation variables are not used in snippet workflows; returns an empty list
| Code | Description | Schema |
| ---- | ----------- | ------ |
-| 200 | Conversation variables retrieved successfully | **application/json**: [WorkflowDraftVariableList](#workflowdraftvariablelist)<br> |
+| 200 | Conversation variables retrieved successfully | **application/json**: [WorkflowDraftVariableListResponse](#workflowdraftvariablelistresponse)<br> |
### [GET] /snippets/{snippet_id}/workflows/draft/environment-variables
Get environment variables from snippet draft workflow graph
@@ -8930,7 +8930,7 @@ Get variables for a specific node (snippet draft workflow)
| Code | Description | Schema |
| ---- | ----------- | ------ |
-| 200 | Node variables retrieved successfully | **application/json**: [WorkflowDraftVariableList](#workflowdraftvariablelist)<br> |
+| 200 | Node variables retrieved successfully | **application/json**: [WorkflowDraftVariableListResponse](#workflowdraftvariablelistresponse)<br> |
### [POST] /snippets/{snippet_id}/workflows/draft/run
**Run draft workflow for snippet**
@@ -8970,7 +8970,7 @@ System variables are not used in snippet workflows; returns an empty list for AP
| Code | Description | Schema |
| ---- | ----------- | ------ |
-| 200 | System variables retrieved successfully | **application/json**: [WorkflowDraftVariableList](#workflowdraftvariablelist)<br> |
+| 200 | System variables retrieved successfully | **application/json**: [WorkflowDraftVariableListResponse](#workflowdraftvariablelistresponse)<br> |
### [DELETE] /snippets/{snippet_id}/workflows/draft/variables
Delete all draft workflow variables for the current user (snippet scope)
@@ -9002,7 +9002,7 @@ List draft workflow variables without values (paginated, snippet scope)
| Code | Description | Schema |
| ---- | ----------- | ------ |
-| 200 | Workflow variables retrieved successfully | **application/json**: [WorkflowDraftVariableListWithoutValue](#workflowdraftvariablelistwithoutvalue)<br> |
+| 200 | Workflow variables retrieved successfully | **application/json**: [WorkflowDraftVariableListWithoutValueResponse](#workflowdraftvariablelistwithoutvalueresponse)<br> |
### [DELETE] /snippets/{snippet_id}/workflows/draft/variables/{variable_id}
Delete a draft workflow variable (snippet scope)
@@ -9035,7 +9035,7 @@ Get a specific draft workflow variable (snippet scope)
| Code | Description | Schema |
| ---- | ----------- | ------ |
-| 200 | Variable retrieved successfully | **application/json**: [WorkflowDraftVariable](#workflowdraftvariable)<br> |
+| 200 | Variable retrieved successfully | **application/json**: [WorkflowDraftVariableResponse](#workflowdraftvariableresponse)<br> |
| 404 | Variable not found | |
### [PATCH] /snippets/{snippet_id}/workflows/draft/variables/{variable_id}
@@ -9058,7 +9058,7 @@ Update a draft workflow variable (snippet scope)
| Code | Description | Schema |
| ---- | ----------- | ------ |
-| 200 | Variable updated successfully | **application/json**: [WorkflowDraftVariable](#workflowdraftvariable)<br> |
+| 200 | Variable updated successfully | **application/json**: [WorkflowDraftVariableResponse](#workflowdraftvariableresponse)<br> |
| 404 | Variable not found | |
### [PUT] /snippets/{snippet_id}/workflows/draft/variables/{variable_id}/reset
@@ -9075,7 +9075,7 @@ Reset a draft workflow variable to its default value (snippet scope)
| Code | Description | Schema |
| ---- | ----------- | ------ |
-| 200 | Variable reset successfully | **application/json**: [WorkflowDraftVariable](#workflowdraftvariable)<br> |
+| 200 | Variable reset successfully | **application/json**: [WorkflowDraftVariableResponse](#workflowdraftvariableresponse)<br> |
| 204 | Variable reset (no content) | |
| 404 | Variable not found | |
@@ -17925,12 +17925,6 @@ Request payload for bulk downloading documents as a zip archive.
| ---- | ---- | ----------- | -------- |
| node_id | string | | Yes |
-#### DraftWorkflowTriggerRunRequest
-
-| Name | Type | Description | Required |
-| ---- | ---- | ----------- | -------- |
-| node_id | string | Node ID | Yes |
-
#### DslImportWarning
Portable DSL reference that could not be restored in the target workspace.
@@ -24257,67 +24251,57 @@ How a workflow node is bound to an Agent.
| ---- | ---- | ----------- | -------- |
| data | [ [WorkflowDailyTokenCostStatisticItem](#workflowdailytokencoststatisticitem) ] | | Yes |
-#### WorkflowDraftEnvVariable
+#### WorkflowDraftVariableFullContentResponse
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
-| description | string | | No |
-| edited | boolean | | No |
-| id | string | | No |
-| name | string | | No |
-| selector | [ string ] | | No |
-| type | string | | No |
-| value_type | string | | No |
-| visible | boolean | | No |
-
-#### WorkflowDraftEnvVariableList
-
-| Name | Type | Description | Required |
-| ---- | ---- | ----------- | -------- |
-| items | [ [WorkflowDraftEnvVariable](#workflowdraftenvvariable) ] | | No |
+| download_url | string | | Yes |
+| length | integer | | Yes |
+| size_bytes | integer | | Yes |
+| value_type | string | | Yes |
-#### WorkflowDraftVariable
+#### WorkflowDraftVariableListQuery
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
-| description | string | | No |
-| edited | boolean | | No |
-| full_content | object | | No |
-| id | string | | No |
-| is_truncated | boolean | | No |
-| name | string | | No |
-| selector | [ string ] | | No |
-| type | string | | No |
-| value | string<br>integer<br>number<br>boolean<br>object<br>[ object ] | | No |
-| value_type | string | | No |
-| visible | boolean | | No |
+| limit | integer, <br>**Default:** 20 | Items per page | No |
+| page | integer, <br>**Default:** 1 | Page number | No |
-#### WorkflowDraftVariableList
+#### WorkflowDraftVariableListResponse
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
-| items | [ [WorkflowDraftVariable](#workflowdraftvariable) ] | | No |
+| items | [ [WorkflowDraftVariableResponse](#workflowdraftvariableresponse) ] | | Yes |
-#### WorkflowDraftVariableListQuery
+#### WorkflowDraftVariableListWithoutValueResponse
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
-| limit | integer, <br>**Default:** 20 | Items per page | No |
-| page | integer, <br>**Default:** 1 | Page number | No |
+| items | [ [WorkflowDraftVariableWithoutValueResponse](#workflowdraftvariablewithoutvalueresponse) ] | | Yes |
+| total | integer | | Yes |
-#### WorkflowDraftVariableListWithoutValue
+#### WorkflowDraftVariablePatchPayload
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
-| items | [ [WorkflowDraftVariableWithoutValue](#workflowdraftvariablewithoutvalue) ] | | No |
-| total | integer | | No |
+| name | string | | No |
+| value | | | No |
-#### WorkflowDraftVariablePatchPayload
+#### WorkflowDraftVariableResponse
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
-| name | string | | No |
-| value | | | No |
+| description | string | | Yes |
+| edited | boolean | | Yes |
+| full_content | [WorkflowDraftVariableFullContentResponse](#workflowdraftvariablefullcontentresponse) | | Yes |
+| id | string | | Yes |
+| is_truncated | boolean | | Yes |
+| name | string | | Yes |
+| selector | [ string ] | | Yes |
+| type | string | | Yes |
+| value | [JSONValue](#jsonvalue) | | Yes |
+| value_type | string | | Yes |
+| visible | boolean | | Yes |
#### WorkflowDraftVariableUpdatePayload
@@ -24326,19 +24310,19 @@ How a workflow node is bound to an Agent.
| name | string | Variable name | No |
| value | | Variable value | No |
-#### WorkflowDraftVariableWithoutValue
+#### WorkflowDraftVariableWithoutValueResponse
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
-| description | string | | No |
-| edited | boolean | | No |
-| id | string | | No |
-| is_truncated | boolean | | No |
-| name | string | | No |
-| selector | [ string ] | | No |
-| type | string | | No |
-| value_type | string | | No |
-| visible | boolean | | No |
+| description | string | | Yes |
+| edited | boolean | | Yes |
+| id | string | | Yes |
+| is_truncated | boolean | | Yes |
+| name | string | | Yes |
+| selector | [ string ] | | Yes |
+| type | string | | Yes |
+| value_type | string | | Yes |
+| visible | boolean | | Yes |
#### WorkflowEnvironmentVariableResponse
diff --git a/api/tests/unit_tests/commands/test_generate_swagger_specs.py b/api/tests/unit_tests/commands/test_generate_swagger_specs.py
index 34147acde8e..855397b7c45 100644
--- a/api/tests/unit_tests/commands/test_generate_swagger_specs.py
+++ b/api/tests/unit_tests/commands/test_generate_swagger_specs.py
@@ -730,6 +730,25 @@ def test_generate_specs_include_console_contract_shapes_for_schema_migration(tmp
"#/components/schemas/SyncDraftWorkflowResponse"
)
assert sync_draft_workflow["properties"]["updated_at"]["type"] == "integer"
+ trigger_run_request = _request_schema(paths["/apps/{app_id}/workflows/draft/trigger/run"]["post"])
+ assert trigger_run_request["$ref"] == "#/components/schemas/DraftWorkflowTriggerRunPayload"
+ assert "DraftWorkflowTriggerRunRequest" not in schemas
+
+ draft_variable_list_ref = "#/components/schemas/WorkflowDraftVariableListWithoutValueResponse"
+ for path in (
+ "/apps/{app_id}/workflows/draft/variables",
+ "/snippets/{snippet_id}/workflows/draft/variables",
+ "/rag/pipelines/{pipeline_id}/workflows/draft/variables",
+ ):
+ assert _response_schema(paths[path]["get"])["$ref"] == draft_variable_list_ref
+ assert schemas["WorkflowDraftVariableListResponse"]["properties"]["items"]["items"]["$ref"] == (
+ "#/components/schemas/WorkflowDraftVariableResponse"
+ )
+ full_content = schemas["WorkflowDraftVariableFullContentResponse"]
+ assert set(full_content["properties"]) == {"size_bytes", "value_type", "length", "download_url"}
+ assert "WorkflowDraftVariable" not in schemas
+ assert "WorkflowDraftVariableList" not in schemas
+ assert "WorkflowDraftVariableWithoutValue" not in schemas
tool_icon_schema = schemas["ExploreAppMetaResponse"]["properties"]["tool_icons"]["additionalProperties"]
assert {"type": "string"} in tool_icon_schema["anyOf"]
assert {"additionalProperties": True, "type": "object"} in tool_icon_schema["anyOf"]
diff --git a/api/tests/unit_tests/controllers/console/app/workflow_draft_variables_test.py b/api/tests/unit_tests/controllers/console/app/workflow_draft_variables_test.py
index 62fa82e3397..709ae1e72a4 100644
--- a/api/tests/unit_tests/controllers/console/app/workflow_draft_variables_test.py
+++ b/api/tests/unit_tests/controllers/console/app/workflow_draft_variables_test.py
@@ -4,19 +4,19 @@ from typing import Any, NamedTuple
from unittest.mock import patch
import pytest
-from flask_restx import marshal
-from controllers.console.app.workflow_draft_variable import (
- _WORKFLOW_DRAFT_VARIABLE_FIELDS,
- _WORKFLOW_DRAFT_VARIABLE_LIST_FIELDS,
- _WORKFLOW_DRAFT_VARIABLE_LIST_WITHOUT_VALUE_FIELDS,
- _WORKFLOW_DRAFT_VARIABLE_WITHOUT_VALUE_FIELDS,
- _serialize_full_content,
-)
from core.workflow.variable_prefixes import CONVERSATION_VARIABLE_NODE_ID, SYSTEM_VARIABLE_NODE_ID
from factories.variable_factory import build_segment
+from fields.workflow_draft_variable_fields import (
+ WorkflowDraftVariableListResponse,
+ WorkflowDraftVariableListWithoutValueResponse,
+ WorkflowDraftVariableResponse,
+ WorkflowDraftVariableWithoutValueResponse,
+ _serialize_full_content,
+)
from graphon.variables.types import SegmentType
from libs.datetime_utils import naive_utc_now
+from libs.helper import dump_response
from libs.uuid_utils import uuidv7
from models.workflow import WorkflowDraftVariable, WorkflowDraftVariableFile
from services.workflow_draft_variable_service import WorkflowDraftVariableList
@@ -43,7 +43,7 @@ class TestWorkflowDraftVariableFields:
)
# Mock the file helpers
- with patch("controllers.console.app.workflow_draft_variable.file_helpers", autospec=True) as mock_file_helpers:
+ with patch("fields.workflow_draft_variable_fields.file_helpers", autospec=True) as mock_file_helpers:
mock_file_helpers.get_signed_file_url.return_value = "http://example.com/signed-url"
# Call the function
@@ -51,11 +51,10 @@ class TestWorkflowDraftVariableFields:
# Verify it returns the expected structure
assert result is not None
- assert result["size_bytes"] == 100000
- assert result["length"] == 50
- assert result["value_type"] == "object"
- assert "download_url" in result
- assert result["download_url"] == "http://example.com/signed-url"
+ assert result.size_bytes == 100000
+ assert result.length == 50
+ assert result.value_type == "object"
+ assert result.download_url == "http://example.com/signed-url"
# Verify it used the pre-loaded relationships (no database queries)
mock_file_helpers.get_signed_file_url.assert_called_once_with("test-upload-file-id", as_attachment=True)
@@ -99,11 +98,11 @@ class TestWorkflowDraftVariableFields:
}
)
- assert marshal(conv_var, _WORKFLOW_DRAFT_VARIABLE_WITHOUT_VALUE_FIELDS) == expected_without_value
+ assert dump_response(WorkflowDraftVariableWithoutValueResponse, conv_var) == expected_without_value
expected_with_value = expected_without_value.copy()
expected_with_value["value"] = 1
expected_with_value["full_content"] = None
- assert marshal(conv_var, _WORKFLOW_DRAFT_VARIABLE_FIELDS) == expected_with_value
+ assert dump_response(WorkflowDraftVariableResponse, conv_var) == expected_with_value
def test_create_sys_variable(self):
sys_var = WorkflowDraftVariable.new_sys_variable(
@@ -131,11 +130,11 @@ class TestWorkflowDraftVariableFields:
"is_truncated": False,
}
)
- assert marshal(sys_var, _WORKFLOW_DRAFT_VARIABLE_WITHOUT_VALUE_FIELDS) == expected_without_value
+ assert dump_response(WorkflowDraftVariableWithoutValueResponse, sys_var) == expected_without_value
expected_with_value = expected_without_value.copy()
expected_with_value["value"] = "a"
expected_with_value["full_content"] = None
- assert marshal(sys_var, _WORKFLOW_DRAFT_VARIABLE_FIELDS) == expected_with_value
+ assert dump_response(WorkflowDraftVariableResponse, sys_var) == expected_with_value
def test_node_variable(self):
node_var = WorkflowDraftVariable.new_node_variable(
@@ -164,11 +163,11 @@ class TestWorkflowDraftVariableFields:
}
)
- assert marshal(node_var, _WORKFLOW_DRAFT_VARIABLE_WITHOUT_VALUE_FIELDS) == expected_without_value
+ assert dump_response(WorkflowDraftVariableWithoutValueResponse, node_var) == expected_without_value
expected_with_value = expected_without_value.copy()
expected_with_value["value"] = [1, "a"]
expected_with_value["full_content"] = None
- assert marshal(node_var, _WORKFLOW_DRAFT_VARIABLE_FIELDS) == expected_with_value
+ assert dump_response(WorkflowDraftVariableResponse, node_var) == expected_with_value
def test_node_variable_with_file(self):
node_var = WorkflowDraftVariable.new_node_variable(
@@ -209,9 +208,9 @@ class TestWorkflowDraftVariableFields:
}
)
- with patch("controllers.console.app.workflow_draft_variable.file_helpers", autospec=True) as mock_file_helpers:
+ with patch("fields.workflow_draft_variable_fields.file_helpers", autospec=True) as mock_file_helpers:
mock_file_helpers.get_signed_file_url.return_value = "http://example.com/signed-url"
- assert marshal(node_var, _WORKFLOW_DRAFT_VARIABLE_WITHOUT_VALUE_FIELDS) == expected_without_value
+ assert dump_response(WorkflowDraftVariableWithoutValueResponse, node_var) == expected_without_value
expected_with_value = expected_without_value.copy()
expected_with_value["value"] = [1, "a"]
expected_with_value["full_content"] = {
@@ -220,7 +219,7 @@ class TestWorkflowDraftVariableFields:
"length": 10,
"download_url": "http://example.com/signed-url",
}
- assert marshal(node_var, _WORKFLOW_DRAFT_VARIABLE_FIELDS) == expected_with_value
+ assert dump_response(WorkflowDraftVariableResponse, node_var) == expected_with_value
class TestWorkflowDraftVariableList:
@@ -297,7 +296,7 @@ class TestWorkflowDraftVariableList:
]
for idx, case in enumerate(cases, 1):
- assert marshal(case.var_list, _WORKFLOW_DRAFT_VARIABLE_LIST_WITHOUT_VALUE_FIELDS) == case.expected, (
+ assert dump_response(WorkflowDraftVariableListWithoutValueResponse, case.var_list) == case.expected, (
f"Test case {idx} failed, {case.name=}"
)
@@ -306,7 +305,7 @@ def test_workflow_node_variables_fields():
conv_var = WorkflowDraftVariable.new_conversation_variable(
app_id=_TEST_APP_ID, name="conv_var", value=build_segment(1)
)
- resp = marshal(WorkflowDraftVariableList(variables=[conv_var]), _WORKFLOW_DRAFT_VARIABLE_LIST_FIELDS)
+ resp = dump_response(WorkflowDraftVariableListResponse, WorkflowDraftVariableList(variables=[conv_var]))
assert isinstance(resp, dict)
assert len(resp["items"]) == 1
item_dict = resp["items"][0]
@@ -340,7 +339,7 @@ def test_workflow_file_variable_with_signed_url():
)
# Marshal the variable using the API fields
- resp = marshal(WorkflowDraftVariableList(variables=[file_var]), _WORKFLOW_DRAFT_VARIABLE_LIST_FIELDS)
+ resp = dump_response(WorkflowDraftVariableListResponse, WorkflowDraftVariableList(variables=[file_var]))
# Verify the response structure
assert isinstance(resp, dict)
@@ -396,7 +395,7 @@ def test_workflow_file_variable_remote_url():
)
# Marshal the variable using the API fields
- resp = marshal(WorkflowDraftVariableList(variables=[file_var]), _WORKFLOW_DRAFT_VARIABLE_LIST_FIELDS)
+ resp = dump_response(WorkflowDraftVariableListResponse, WorkflowDraftVariableList(variables=[file_var]))
# Verify the response structure
assert isinstance(resp, dict)
diff --git a/api/tests/unit_tests/controllers/console/datasets/rag_pipeline/test_rag_pipeline_draft_variable.py b/api/tests/unit_tests/controllers/console/datasets/rag_pipeline/test_rag_pipeline_draft_variable.py
index 581adaafe37..33ff6a39a81 100644
--- a/api/tests/unit_tests/controllers/console/datasets/rag_pipeline/test_rag_pipeline_draft_variable.py
+++ b/api/tests/unit_tests/controllers/console/datasets/rag_pipeline/test_rag_pipeline_draft_variable.py
@@ -121,9 +121,9 @@ class TestRagPipelineVariableCollectionApi:
rag_srv = MagicMock()
rag_srv.is_workflow_exist.return_value = True
- # IMPORTANT: RESTX expects .variables
var_list = MagicMock()
var_list.variables = []
+ var_list.total = None
draft_srv = MagicMock()
draft_srv.list_variables_without_values.return_value = var_list
@@ -143,7 +143,7 @@ class TestRagPipelineVariableCollectionApi:
):
result = method(api, PaginationQuery(page=1, limit=10), editor_user, pipeline)
- assert result is var_list
+ assert result == {"items": [], "total": None}
draft_srv.list_variables_without_values.assert_called_once_with(
app_id="p1",
page=1,
@@ -212,7 +212,7 @@ class TestRagPipelineNodeVariableCollectionApi:
):
result = method(api, editor_user, pipeline, "node1")
- assert result is var_list
+ assert result == {"items": []}
srv.list_node_variables.assert_called_once_with("p1", "node1", user_id="account-1")
def test_get_node_variables_invalid_node(self, app: Flask, editor_user):
@@ -376,7 +376,7 @@ class TestRagPipelineVariableResetApi:
return_value=srv,
),
patch(
- "controllers.console.datasets.rag_pipeline.rag_pipeline_draft_variable.marshal",
+ "controllers.console.datasets.rag_pipeline.rag_pipeline_draft_variable.dump_response",
return_value={"id": "v1"},
),
):
@@ -409,7 +409,7 @@ class TestSystemAndEnvironmentVariablesApi:
):
result = method(api, editor_user, pipeline)
- assert result is var_list
+ assert result == {"items": []}
srv.list_system_variables.assert_called_once_with("p1", user_id="account-1")
def test_environment_variables_success(self, app: Flask, editor_user):
diff --git a/api/tests/unit_tests/controllers/console/snippets/test_snippet_workflow_draft_variable.py b/api/tests/unit_tests/controllers/console/snippets/test_snippet_workflow_draft_variable.py
index 258c86e53bd..3d7d8900c94 100644
--- a/api/tests/unit_tests/controllers/console/snippets/test_snippet_workflow_draft_variable.py
+++ b/api/tests/unit_tests/controllers/console/snippets/test_snippet_workflow_draft_variable.py
@@ -14,7 +14,6 @@ from graphon.variables import StringSegment
from graphon.variables.types import SegmentType
from models.account import Account, AccountStatus
from models.workflow import WorkflowDraftVariable, WorkflowDraftVariableFile
-from services.workflow_draft_variable_service import WorkflowDraftVariableList
pytestmark = [
pytest.mark.usefixtures("sqlite_session"),
@@ -140,7 +139,7 @@ def test_conversation_variables_returns_empty_list(app: Flask) -> None:
with app.test_request_context("/"):
result = handler(api, _make_account(), snippet=SimpleNamespace(id="snippet-1"))
- assert result == WorkflowDraftVariableList(variables=[])
+ assert result == {"items": []}
def test_system_variables_returns_empty_list(app: Flask) -> None:
@@ -150,7 +149,7 @@ def test_system_variables_returns_empty_list(app: Flask) -> None:
with app.test_request_context("/"):
result = handler(api, _make_account(), snippet=SimpleNamespace(id="snippet-1"))
- assert result == WorkflowDraftVariableList(variables=[])
+ assert result == {"items": []}
def test_delete_variable_collection_deletes_only_current_user_variables(
@@ -209,7 +208,7 @@ def test_node_variable_collection_get_lists_persisted_node_variables(
with app.test_request_context("/"):
result = handler(api, _make_account(), snippet=SimpleNamespace(id="snippet-1"), node_id="llm-1")
- assert [variable.id for variable in result.variables] == [matching.id]
+ assert [variable["id"] for variable in result["items"]] == [matching.id]
assert controller_sessions().get_bind() is not None
@@ -263,8 +262,7 @@ def test_variable_patch_returns_persisted_variable_without_committing_when_no_ch
finally:
event.remove(session, "after_commit", record_commit)
- assert result.id == variable.id
- assert result.app_id == "snippet-1"
+ assert result["id"] == variable.id
assert commits == []
assert session.in_transaction()
diff --git a/packages/contracts/generated/api/console/apps/types.gen.ts b/packages/contracts/generated/api/console/apps/types.gen.ts
index 5899611953a..fa685709fe4 100644
--- a/packages/contracts/generated/api/console/apps/types.gen.ts
+++ b/packages/contracts/generated/api/console/apps/types.gen.ts
@@ -939,8 +939,8 @@ export type SyncDraftWorkflowResponse = {
updated_at: number
}
-export type WorkflowDraftVariableList = {
- items?: Array<WorkflowDraftVariable>
+export type WorkflowDraftVariableListResponse = {
+ items: Array<WorkflowDraftVariableResponse>
}
export type ConversationVariableUpdatePayload = {
@@ -1113,7 +1113,7 @@ export type OutputPreviewView = {
value?: unknown
}
-export type DraftWorkflowTriggerRunRequest = {
+export type DraftWorkflowTriggerRunPayload = {
node_id: string
}
@@ -1121,34 +1121,23 @@ export type DraftWorkflowTriggerRunAllPayload = {
node_ids: Array<string>
}
-export type WorkflowDraftVariableListWithoutValue = {
- items?: Array<WorkflowDraftVariableWithoutValue>
- total?: number
+export type WorkflowDraftVariableListWithoutValueResponse = {
+ items: Array<WorkflowDraftVariableWithoutValueResponse>
+ total: number | null
}
-export type WorkflowDraftVariable = {
- description?: string
- edited?: boolean
- full_content?: {
- [key: string]: unknown
- }
- id?: string
- is_truncated?: boolean
- name?: string
- selector?: Array<string>
- type?: string
- value?:
- | string
- | number
- | number
- | boolean
- | {
- [key: string]: unknown
- }
- | Array<unknown>
- | null
- value_type?: string
- visible?: boolean
+export type WorkflowDraftVariableResponse = {
+ description: string
+ edited: boolean
+ full_content: WorkflowDraftVariableFullContentResponse | null
+ id: string
+ is_truncated: boolean
+ name: string
+ selector: Array<string>
+ type: string
+ value: JsonValue
+ value_type: string
+ visible: boolean
}
export type WorkflowDraftVariableUpdatePayload = {
@@ -2069,16 +2058,23 @@ export type NodeOutputStatus =
export type DeclaredOutputType = 'array' | 'boolean' | 'file' | 'number' | 'object' | 'string'
-export type WorkflowDraftVariableWithoutValue = {
- description?: string
- edited?: boolean
- id?: string
- is_truncated?: boolean
- name?: string
- selector?: Array<string>
- type?: string
- value_type?: string
- visible?: boolean
+export type WorkflowDraftVariableWithoutValueResponse = {
+ description: string
+ edited: boolean
+ id: string
+ is_truncated: boolean
+ name: string
+ selector: Array<string>
+ type: string
+ value_type: string
+ visible: boolean
+}
+
+export type WorkflowDraftVariableFullContentResponse = {
+ download_url: string
+ length: number | null
+ size_bytes: number | null
+ value_type: string
}
export type ModelConfigPartial = {
@@ -5682,7 +5678,7 @@ export type GetAppsByAppIdWorkflowsDraftConversationVariablesErrors = {
}
export type GetAppsByAppIdWorkflowsDraftConversationVariablesResponses = {
- 200: WorkflowDraftVariableList
+ 200: WorkflowDraftVariableListResponse
}
export type GetAppsByAppIdWorkflowsDraftConversationVariablesResponse =
@@ -6066,7 +6062,7 @@ export type GetAppsByAppIdWorkflowsDraftNodesByNodeIdVariablesData = {
}
export type GetAppsByAppIdWorkflowsDraftNodesByNodeIdVariablesResponses = {
- 200: WorkflowDraftVariableList
+ 200: WorkflowDraftVariableListResponse
}
export type GetAppsByAppIdWorkflowsDraftNodesByNodeIdVariablesResponse =
@@ -6190,14 +6186,14 @@ export type GetAppsByAppIdWorkflowsDraftSystemVariablesData = {
}
export type GetAppsByAppIdWorkflowsDraftSystemVariablesResponses = {
- 200: WorkflowDraftVariableList
+ 200: WorkflowDraftVariableListResponse
}
export type GetAppsByAppIdWorkflowsDraftSystemVariablesResponse =
GetAppsByAppIdWorkflowsDraftSystemVariablesResponses[keyof GetAppsByAppIdWorkflowsDraftSystemVariablesResponses]
export type PostAppsByAppIdWorkflowsDraftTriggerRunData = {
- body: DraftWorkflowTriggerRunRequest
+ body: DraftWorkflowTriggerRunPayload
path: {
app_id: string
}
@@ -6267,7 +6263,7 @@ export type GetAppsByAppIdWorkflowsDraftVariablesData = {
}
export type GetAppsByAppIdWorkflowsDraftVariablesResponses = {
- 200: WorkflowDraftVariableListWithoutValue
+ 200: WorkflowDraftVariableListWithoutValueResponse
}
export type GetAppsByAppIdWorkflowsDraftVariablesResponse =
@@ -6309,7 +6305,7 @@ export type GetAppsByAppIdWorkflowsDraftVariablesByVariableIdErrors = {
}
export type GetAppsByAppIdWorkflowsDraftVariablesByVariableIdResponses = {
- 200: WorkflowDraftVariable
+ 200: WorkflowDraftVariableResponse
}
export type GetAppsByAppIdWorkflowsDraftVariablesByVariableIdResponse =
@@ -6330,7 +6326,7 @@ export type PatchAppsByAppIdWorkflowsDraftVariablesByVariableIdErrors = {
}
export type PatchAppsByAppIdWorkflowsDraftVariablesByVariableIdResponses = {
- 200: WorkflowDraftVariable
+ 200: WorkflowDraftVariableResponse
}
export type PatchAppsByAppIdWorkflowsDraftVariablesByVariableIdResponse =
@@ -6351,7 +6347,7 @@ export type PutAppsByAppIdWorkflowsDraftVariablesByVariableIdResetErrors = {
}
export type PutAppsByAppIdWorkflowsDraftVariablesByVariableIdResetResponses = {
- 200: WorkflowDraftVariable
+ 200: WorkflowDraftVariableResponse
204: void
}
diff --git a/packages/contracts/generated/api/console/apps/zod.gen.ts b/packages/contracts/generated/api/console/apps/zod.gen.ts
index 3f556df7381..a29b6c275de 100644
--- a/packages/contracts/generated/api/console/apps/zod.gen.ts
+++ b/packages/contracts/generated/api/console/apps/zod.gen.ts
@@ -642,7 +642,10 @@ export const zDraftWorkflowRunPayload = z.object({
*/
export const zEventStreamResponse = z.string()
-export const zDraftWorkflowTriggerRunRequest = z.object({
+/**
+ * DraftWorkflowTriggerRunPayload
+ */
+export const zDraftWorkflowTriggerRunPayload = z.object({
node_id: z.string(),
})
@@ -653,33 +656,6 @@ export const zDraftWorkflowTriggerRunAllPayload = z.object({
node_ids: z.array(z.string()),
})
-export const zWorkflowDraftVariable = z.object({
- description: z.string().optional(),
- edited: z.boolean().optional(),
- full_content: z.record(z.string(), z.unknown()).optional(),
- id: z.string().optional(),
- is_truncated: z.boolean().optional(),
- name: z.string().optional(),
- selector: z.array(z.string()).optional(),
- type: z.string().optional(),
- value: z
- .union([
- z.string(),
- z.int(),
- z.number(),
- z.boolean(),
- z.record(z.string(), z.unknown()),
- z.array(z.unknown()),
- ])
- .nullish(),
- value_type: z.string().optional(),
- visible: z.boolean().optional(),
-})
-
-export const zWorkflowDraftVariableList = z.object({
- items: z.array(zWorkflowDraftVariable).optional(),
-})
-
/**
* WorkflowDraftVariableUpdatePayload
*/
@@ -2130,21 +2106,61 @@ export const zOutputPreviewView = z.object({
value: z.unknown().optional(),
})
-export const zWorkflowDraftVariableWithoutValue = z.object({
- description: z.string().optional(),
- edited: z.boolean().optional(),
- id: z.string().optional(),
- is_truncated: z.boolean().optional(),
- name: z.string().optional(),
- selector: z.array(z.string()).optional(),
- type: z.string().optional(),
- value_type: z.string().optional(),
- visible: z.boolean().optional(),
+/**
+ * WorkflowDraftVariableWithoutValueResponse
+ */
+export const zWorkflowDraftVariableWithoutValueResponse = z.object({
+ description: z.string(),
+ edited: z.boolean(),
+ id: z.string(),
+ is_truncated: z.boolean(),
+ name: z.string(),
+ selector: z.array(z.string()),
+ type: z.string(),
+ value_type: z.string(),
+ visible: z.boolean(),
})
-export const zWorkflowDraftVariableListWithoutValue = z.object({
- items: z.array(zWorkflowDraftVariableWithoutValue).optional(),
- total: z.int().optional(),
+/**
+ * WorkflowDraftVariableListWithoutValueResponse
+ */
+export const zWorkflowDraftVariableListWithoutValueResponse = z.object({
+ items: z.array(zWorkflowDraftVariableWithoutValueResponse),
+ total: z.int().nullable(),
+})
+
+/**
+ * WorkflowDraftVariableFullContentResponse
+ */
+export const zWorkflowDraftVariableFullContentResponse = z.object({
+ download_url: z.string(),
+ length: z.int().nullable(),
+ size_bytes: z.int().nullable(),
+ value_type: z.string(),
+})
+
+/**
+ * WorkflowDraftVariableResponse
+ */
+export const zWorkflowDraftVariableResponse = z.object({
+ description: z.string(),
+ edited: z.boolean(),
+ full_content: zWorkflowDraftVariableFullContentResponse.nullable(),
+ id: z.string(),
+ is_truncated: z.boolean(),
+ name: z.string(),
+ selector: z.array(z.string()),
+ type: z.string(),
+ value: zJsonValue,
+ value_type: z.string(),
+ visible: z.boolean(),
+})
+
+/**
+ * WorkflowDraftVariableListResponse
+ */
+export const zWorkflowDraftVariableListResponse = z.object({
+ items: z.array(zWorkflowDraftVariableResponse),
})
/**
@@ -5810,7 +5826,8 @@ export const zGetAppsByAppIdWorkflowsDraftConversationVariablesPath = z.object({
/**
* Conversation variables retrieved successfully
*/
-export const zGetAppsByAppIdWorkflowsDraftConversationVariablesResponse = zWorkflowDraftVariableList
+export const zGetAppsByAppIdWorkflowsDraftConversationVariablesResponse =
+ zWorkflowDraftVariableListResponse
export const zPostAppsByAppIdWorkflowsDraftConversationVariablesBody =
zConversationVariableUpdatePayload
@@ -6071,7 +6088,7 @@ export const zGetAppsByAppIdWorkflowsDraftNodesByNodeIdVariablesPath = z.object(
* Node variables retrieved successfully
*/
export const zGetAppsByAppIdWorkflowsDraftNodesByNodeIdVariablesResponse =
- zWorkflowDraftVariableList
+ zWorkflowDraftVariableListResponse
export const zPostAppsByAppIdWorkflowsDraftRunBody = zDraftWorkflowRunPayload
@@ -6137,9 +6154,10 @@ export const zGetAppsByAppIdWorkflowsDraftSystemVariablesPath = z.object({
/**
* System variables retrieved successfully
*/
-export const zGetAppsByAppIdWorkflowsDraftSystemVariablesResponse = zWorkflowDraftVariableList
+export const zGetAppsByAppIdWorkflowsDraftSystemVariablesResponse =
+ zWorkflowDraftVariableListResponse
-export const zPostAppsByAppIdWorkflowsDraftTriggerRunBody = zDraftWorkflowTriggerRunRequest
+export const zPostAppsByAppIdWorkflowsDraftTriggerRunBody = zDraftWorkflowTriggerRunPayload
export const zPostAppsByAppIdWorkflowsDraftTriggerRunPath = z.object({
app_id: z.uuid(),
@@ -6182,7 +6200,8 @@ export const zGetAppsByAppIdWorkflowsDraftVariablesQuery = z.object({
/**
* Workflow variables retrieved successfully
*/
-export const zGetAppsByAppIdWorkflowsDraftVariablesResponse = zWorkflowDraftVariableListWithoutValue
+export const zGetAppsByAppIdWorkflowsDraftVariablesResponse =
+ zWorkflowDraftVariableListWithoutValueResponse
export const zDeleteAppsByAppIdWorkflowsDraftVariablesByVariableIdPath = z.object({
app_id: z.uuid(),
@@ -6202,7 +6221,8 @@ export const zGetAppsByAppIdWorkflowsDraftVariablesByVariableIdPath = z.object({
/**
* Variable retrieved successfully
*/
-export const zGetAppsByAppIdWorkflowsDraftVariablesByVariableIdResponse = zWorkflowDraftVariable
+export const zGetAppsByAppIdWorkflowsDraftVariablesByVariableIdResponse =
+ zWorkflowDraftVariableResponse
export const zPatchAppsByAppIdWorkflowsDraftVariablesByVariableIdBody =
zWorkflowDraftVariableUpdatePayload
@@ -6215,7 +6235,8 @@ export const zPatchAppsByAppIdWorkflowsDraftVariablesByVariableIdPath = z.object
/**
* Variable updated successfully
*/
-export const zPatchAppsByAppIdWorkflowsDraftVariablesByVariableIdResponse = zWorkflowDraftVariable
+export const zPatchAppsByAppIdWorkflowsDraftVariablesByVariableIdResponse =
+ zWorkflowDraftVariableResponse
export const zPutAppsByAppIdWorkflowsDraftVariablesByVariableIdResetPath = z.object({
app_id: z.uuid(),
@@ -6223,7 +6244,7 @@ export const zPutAppsByAppIdWorkflowsDraftVariablesByVariableIdResetPath = z.obj
})
export const zPutAppsByAppIdWorkflowsDraftVariablesByVariableIdResetResponse = z.union([
- zWorkflowDraftVariable,
+ zWorkflowDraftVariableResponse,
z.void(),
])
diff --git a/packages/contracts/generated/api/console/rag/types.gen.ts b/packages/contracts/generated/api/console/rag/types.gen.ts
index c5ea18e56b1..87466ed4840 100644
--- a/packages/contracts/generated/api/console/rag/types.gen.ts
+++ b/packages/contracts/generated/api/console/rag/types.gen.ts
@@ -237,8 +237,8 @@ export type NodeRunRequiredPayload = {
}
}
-export type WorkflowDraftVariableList = {
- items?: Array<WorkflowDraftVariable>
+export type WorkflowDraftVariableListResponse = {
+ items: Array<WorkflowDraftVariableResponse>
}
export type RagPipelineStepParametersResponse = {
@@ -256,34 +256,23 @@ export type DraftWorkflowRunPayload = {
start_node_id: string
}
-export type WorkflowDraftVariableListWithoutValue = {
- items?: Array<WorkflowDraftVariableWithoutValue>
- total?: number
+export type WorkflowDraftVariableListWithoutValueResponse = {
+ items: Array<WorkflowDraftVariableWithoutValueResponse>
+ total: number | null
}
-export type WorkflowDraftVariable = {
- description?: string
- edited?: boolean
- full_content?: {
- [key: string]: unknown
- }
- id?: string
- is_truncated?: boolean
- name?: string
- selector?: Array<string>
- type?: string
- value?:
- | string
- | number
- | number
- | boolean
- | {
- [key: string]: unknown
- }
- | Array<unknown>
- | null
- value_type?: string
- visible?: boolean
+export type WorkflowDraftVariableResponse = {
+ description: string
+ edited: boolean
+ full_content: WorkflowDraftVariableFullContentResponse | null
+ id: string
+ is_truncated: boolean
+ name: string
+ selector: Array<string>
+ type: string
+ value: JsonValue
+ value_type: string
+ visible: boolean
}
export type RagPipelineWorkflowPublishResponse = {
@@ -463,18 +452,36 @@ export type EnvironmentVariableItemResponse = {
visible: boolean
}
-export type WorkflowDraftVariableWithoutValue = {
- description?: string
- edited?: boolean
- id?: string
- is_truncated?: boolean
- name?: string
- selector?: Array<string>
- type?: string
- value_type?: string
- visible?: boolean
+export type WorkflowDraftVariableWithoutValueResponse = {
+ description: string
+ edited: boolean
+ id: string
+ is_truncated: boolean
+ name: string
+ selector: Array<string>
+ type: string
+ value_type: string
+ visible: boolean
}
+export type WorkflowDraftVariableFullContentResponse = {
+ download_url: string
+ length: number | null
+ size_bytes: number | null
+ value_type: string
+}
+
+export type JsonValue =
+ | string
+ | number
+ | number
+ | boolean
+ | {
+ [key: string]: unknown
+ }
+ | Array<unknown>
+ | null
+
export type DatasetRerankingModelResponse = {
reranking_model_name?: string | null
reranking_provider_name?: string | null
@@ -1096,7 +1103,7 @@ export type GetRagPipelinesByPipelineIdWorkflowsDraftNodesByNodeIdVariablesData
}
export type GetRagPipelinesByPipelineIdWorkflowsDraftNodesByNodeIdVariablesResponses = {
- 200: WorkflowDraftVariableList
+ 200: WorkflowDraftVariableListResponse
}
export type GetRagPipelinesByPipelineIdWorkflowsDraftNodesByNodeIdVariablesResponse =
@@ -1164,7 +1171,7 @@ export type GetRagPipelinesByPipelineIdWorkflowsDraftSystemVariablesData = {
}
export type GetRagPipelinesByPipelineIdWorkflowsDraftSystemVariablesResponses = {
- 200: WorkflowDraftVariableList
+ 200: WorkflowDraftVariableListResponse
}
export type GetRagPipelinesByPipelineIdWorkflowsDraftSystemVariablesResponse =
@@ -1199,7 +1206,7 @@ export type GetRagPipelinesByPipelineIdWorkflowsDraftVariablesData = {
}
export type GetRagPipelinesByPipelineIdWorkflowsDraftVariablesResponses = {
- 200: WorkflowDraftVariableListWithoutValue
+ 200: WorkflowDraftVariableListWithoutValueResponse
}
export type GetRagPipelinesByPipelineIdWorkflowsDraftVariablesResponse =
@@ -1233,7 +1240,7 @@ export type GetRagPipelinesByPipelineIdWorkflowsDraftVariablesByVariableIdData =
}
export type GetRagPipelinesByPipelineIdWorkflowsDraftVariablesByVariableIdResponses = {
- 200: WorkflowDraftVariable
+ 200: WorkflowDraftVariableResponse
}
export type GetRagPipelinesByPipelineIdWorkflowsDraftVariablesByVariableIdResponse =
@@ -1250,7 +1257,7 @@ export type PatchRagPipelinesByPipelineIdWorkflowsDraftVariablesByVariableIdData
}
export type PatchRagPipelinesByPipelineIdWorkflowsDraftVariablesByVariableIdResponses = {
- 200: WorkflowDraftVariable
+ 200: WorkflowDraftVariableResponse
}
export type PatchRagPipelinesByPipelineIdWorkflowsDraftVariablesByVariableIdResponse =
@@ -1267,7 +1274,7 @@ export type PutRagPipelinesByPipelineIdWorkflowsDraftVariablesByVariableIdResetD
}
export type PutRagPipelinesByPipelineIdWorkflowsDraftVariablesByVariableIdResetResponses = {
- 200: WorkflowDraftVariable
+ 200: WorkflowDraftVariableResponse
204: void
}
diff --git a/packages/contracts/generated/api/console/rag/zod.gen.ts b/packages/contracts/generated/api/console/rag/zod.gen.ts
index 36e185707f8..4d9790ed43a 100644
--- a/packages/contracts/generated/api/console/rag/zod.gen.ts
+++ b/packages/contracts/generated/api/console/rag/zod.gen.ts
@@ -126,33 +126,6 @@ export const zDraftWorkflowRunPayload = z.object({
start_node_id: z.string(),
})
-export const zWorkflowDraftVariable = z.object({
- description: z.string().optional(),
- edited: z.boolean().optional(),
- full_content: z.record(z.string(), z.unknown()).optional(),
- id: z.string().optional(),
- is_truncated: z.boolean().optional(),
- name: z.string().optional(),
- selector: z.array(z.string()).optional(),
- type: z.string().optional(),
- value: z
- .union([
- z.string(),
- z.int(),
- z.number(),
- z.boolean(),
- z.record(z.string(), z.unknown()),
- z.array(z.unknown()),
- ])
- .nullish(),
- value_type: z.string().optional(),
- visible: z.boolean().optional(),
-})
-
-export const zWorkflowDraftVariableList = z.object({
- items: z.array(zWorkflowDraftVariable).optional(),
-})
-
/**
* RagPipelineWorkflowPublishResponse
*/
@@ -488,21 +461,72 @@ export const zEnvironmentVariableListResponse = z.object({
items: z.array(zEnvironmentVariableItemResponse),
})
-export const zWorkflowDraftVariableWithoutValue = z.object({
- description: z.string().optional(),
- edited: z.boolean().optional(),
- id: z.string().optional(),
- is_truncated: z.boolean().optional(),
- name: z.string().optional(),
- selector: z.array(z.string()).optional(),
- type: z.string().optional(),
- value_type: z.string().optional(),
- visible: z.boolean().optional(),
+/**
+ * WorkflowDraftVariableWithoutValueResponse
+ */
+export const zWorkflowDraftVariableWithoutValueResponse = z.object({
+ description: z.string(),
+ edited: z.boolean(),
+ id: z.string(),
+ is_truncated: z.boolean(),
+ name: z.string(),
+ selector: z.array(z.string()),
+ type: z.string(),
+ value_type: z.string(),
+ visible: z.boolean(),
+})
+
+/**
+ * WorkflowDraftVariableListWithoutValueResponse
+ */
+export const zWorkflowDraftVariableListWithoutValueResponse = z.object({
+ items: z.array(zWorkflowDraftVariableWithoutValueResponse),
+ total: z.int().nullable(),
+})
+
+/**
+ * WorkflowDraftVariableFullContentResponse
+ */
+export const zWorkflowDraftVariableFullContentResponse = z.object({
+ download_url: z.string(),
+ length: z.int().nullable(),
+ size_bytes: z.int().nullable(),
+ value_type: z.string(),
+})
+
+export const zJsonValue = z
+ .union([
+ z.string(),
+ z.int(),
+ z.number(),
+ z.boolean(),
+ z.record(z.string(), z.unknown()),
+ z.array(z.unknown()),
+ ])
+ .nullable()
+
+/**
+ * WorkflowDraftVariableResponse
+ */
+export const zWorkflowDraftVariableResponse = z.object({
+ description: z.string(),
+ edited: z.boolean(),
+ full_content: zWorkflowDraftVariableFullContentResponse.nullable(),
+ id: z.string(),
+ is_truncated: z.boolean(),
+ name: z.string(),
+ selector: z.array(z.string()),
+ type: z.string(),
+ value: zJsonValue,
+ value_type: z.string(),
+ visible: z.boolean(),
})
-export const zWorkflowDraftVariableListWithoutValue = z.object({
- items: z.array(zWorkflowDraftVariableWithoutValue).optional(),
- total: z.int().optional(),
+/**
+ * WorkflowDraftVariableListResponse
+ */
+export const zWorkflowDraftVariableListResponse = z.object({
+ items: z.array(zWorkflowDraftVariableResponse),
})
/**
@@ -995,7 +1019,7 @@ export const zGetRagPipelinesByPipelineIdWorkflowsDraftNodesByNodeIdVariablesPat
* Node variables retrieved successfully
*/
export const zGetRagPipelinesByPipelineIdWorkflowsDraftNodesByNodeIdVariablesResponse =
- zWorkflowDraftVariableList
+ zWorkflowDraftVariableListResponse
export const zGetRagPipelinesByPipelineIdWorkflowsDraftPreProcessingParametersPath = z.object({
pipeline_id: z.uuid(),
@@ -1044,7 +1068,7 @@ export const zGetRagPipelinesByPipelineIdWorkflowsDraftSystemVariablesPath = z.o
* System variables retrieved successfully
*/
export const zGetRagPipelinesByPipelineIdWorkflowsDraftSystemVariablesResponse =
- zWorkflowDraftVariableList
+ zWorkflowDraftVariableListResponse
export const zDeleteRagPipelinesByPipelineIdWorkflowsDraftVariablesPath = z.object({
pipeline_id: z.uuid(),
@@ -1068,7 +1092,7 @@ export const zGetRagPipelinesByPipelineIdWorkflowsDraftVariablesQuery = z.object
* Workflow variables retrieved successfully
*/
export const zGetRagPipelinesByPipelineIdWorkflowsDraftVariablesResponse =
- zWorkflowDraftVariableListWithoutValue
+ zWorkflowDraftVariableListWithoutValueResponse
export const zDeleteRagPipelinesByPipelineIdWorkflowsDraftVariablesByVariableIdPath = z.object({
pipeline_id: z.uuid(),
@@ -1089,7 +1113,7 @@ export const zGetRagPipelinesByPipelineIdWorkflowsDraftVariablesByVariableIdPath
* Variable retrieved successfully
*/
export const zGetRagPipelinesByPipelineIdWorkflowsDraftVariablesByVariableIdResponse =
- zWorkflowDraftVariable
+ zWorkflowDraftVariableResponse
export const zPatchRagPipelinesByPipelineIdWorkflowsDraftVariablesByVariableIdPath = z.object({
pipeline_id: z.uuid(),
@@ -1100,7 +1124,7 @@ export const zPatchRagPipelinesByPipelineIdWorkflowsDraftVariablesByVariableIdPa
* Variable updated successfully
*/
export const zPatchRagPipelinesByPipelineIdWorkflowsDraftVariablesByVariableIdResponse =
- zWorkflowDraftVariable
+ zWorkflowDraftVariableResponse
export const zPutRagPipelinesByPipelineIdWorkflowsDraftVariablesByVariableIdResetPath = z.object({
pipeline_id: z.uuid(),
@@ -1108,7 +1132,7 @@ export const zPutRagPipelinesByPipelineIdWorkflowsDraftVariablesByVariableIdRese
})
export const zPutRagPipelinesByPipelineIdWorkflowsDraftVariablesByVariableIdResetResponse = z.union(
- [zWorkflowDraftVariable, z.void()],
+ [zWorkflowDraftVariableResponse, z.void()],
)
export const zGetRagPipelinesByPipelineIdWorkflowsPublishPath = z.object({
diff --git a/packages/contracts/generated/api/console/snippets/types.gen.ts b/packages/contracts/generated/api/console/snippets/types.gen.ts
index da4479f95e4..f6cab945bcb 100644
--- a/packages/contracts/generated/api/console/snippets/types.gen.ts
+++ b/packages/contracts/generated/api/console/snippets/types.gen.ts
@@ -97,8 +97,8 @@ export type SnippetDraftConfigResponse = {
parallel_depth_limit: number
}
-export type WorkflowDraftVariableList = {
- items?: Array<WorkflowDraftVariable>
+export type WorkflowDraftVariableListResponse = {
+ items: Array<WorkflowDraftVariableResponse>
}
export type EnvironmentVariableListResponse = {
@@ -232,34 +232,23 @@ export type SnippetDraftRunPayload = {
}
}
-export type WorkflowDraftVariableListWithoutValue = {
- items?: Array<WorkflowDraftVariableWithoutValue>
- total?: number
+export type WorkflowDraftVariableListWithoutValueResponse = {
+ items: Array<WorkflowDraftVariableWithoutValueResponse>
+ total: number | null
}
-export type WorkflowDraftVariable = {
- description?: string
- edited?: boolean
- full_content?: {
- [key: string]: unknown
- }
- id?: string
- is_truncated?: boolean
- name?: string
- selector?: Array<string>
- type?: string
- value?:
- | string
- | number
- | number
- | boolean
- | {
- [key: string]: unknown
- }
- | Array<unknown>
- | null
- value_type?: string
- visible?: boolean
+export type WorkflowDraftVariableResponse = {
+ description: string
+ edited: boolean
+ full_content: WorkflowDraftVariableFullContentResponse | null
+ id: string
+ is_truncated: boolean
+ name: string
+ selector: Array<string>
+ type: string
+ value: JsonValue
+ value_type: string
+ visible: boolean
}
export type WorkflowDraftVariableUpdatePayload = {
@@ -536,16 +525,23 @@ export type ComposerValidationWarningResponse = {
surface?: string | null
}
-export type WorkflowDraftVariableWithoutValue = {
- description?: string
- edited?: boolean
- id?: string
- is_truncated?: boolean
- name?: string
- selector?: Array<string>
- type?: string
- value_type?: string
- visible?: boolean
+export type WorkflowDraftVariableWithoutValueResponse = {
+ description: string
+ edited: boolean
+ id: string
+ is_truncated: boolean
+ name: string
+ selector: Array<string>
+ type: string
+ value_type: string
+ visible: boolean
+}
+
+export type WorkflowDraftVariableFullContentResponse = {
+ download_url: string
+ length: number | null
+ size_bytes: number | null
+ value_type: string
}
export type AgentScope = 'roster' | 'workflow_only'
@@ -1296,7 +1292,7 @@ export type GetSnippetsBySnippetIdWorkflowsDraftConversationVariablesData = {
}
export type GetSnippetsBySnippetIdWorkflowsDraftConversationVariablesResponses = {
- 200: WorkflowDraftVariableList
+ 200: WorkflowDraftVariableListResponse
}
export type GetSnippetsBySnippetIdWorkflowsDraftConversationVariablesResponse =
@@ -1556,7 +1552,7 @@ export type GetSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdVariablesData = {
}
export type GetSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdVariablesResponses = {
- 200: WorkflowDraftVariableList
+ 200: WorkflowDraftVariableListResponse
}
export type GetSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdVariablesResponse =
@@ -1592,7 +1588,7 @@ export type GetSnippetsBySnippetIdWorkflowsDraftSystemVariablesData = {
}
export type GetSnippetsBySnippetIdWorkflowsDraftSystemVariablesResponses = {
- 200: WorkflowDraftVariableList
+ 200: WorkflowDraftVariableListResponse
}
export type GetSnippetsBySnippetIdWorkflowsDraftSystemVariablesResponse =
@@ -1627,7 +1623,7 @@ export type GetSnippetsBySnippetIdWorkflowsDraftVariablesData = {
}
export type GetSnippetsBySnippetIdWorkflowsDraftVariablesResponses = {
- 200: WorkflowDraftVariableListWithoutValue
+ 200: WorkflowDraftVariableListWithoutValueResponse
}
export type GetSnippetsBySnippetIdWorkflowsDraftVariablesResponse =
@@ -1669,7 +1665,7 @@ export type GetSnippetsBySnippetIdWorkflowsDraftVariablesByVariableIdErrors = {
}
export type GetSnippetsBySnippetIdWorkflowsDraftVariablesByVariableIdResponses = {
- 200: WorkflowDraftVariable
+ 200: WorkflowDraftVariableResponse
}
export type GetSnippetsBySnippetIdWorkflowsDraftVariablesByVariableIdResponse =
@@ -1690,7 +1686,7 @@ export type PatchSnippetsBySnippetIdWorkflowsDraftVariablesByVariableIdErrors =
}
export type PatchSnippetsBySnippetIdWorkflowsDraftVariablesByVariableIdResponses = {
- 200: WorkflowDraftVariable
+ 200: WorkflowDraftVariableResponse
}
export type PatchSnippetsBySnippetIdWorkflowsDraftVariablesByVariableIdResponse =
@@ -1711,7 +1707,7 @@ export type PutSnippetsBySnippetIdWorkflowsDraftVariablesByVariableIdResetErrors
}
export type PutSnippetsBySnippetIdWorkflowsDraftVariablesByVariableIdResetResponses = {
- 200: WorkflowDraftVariable
+ 200: WorkflowDraftVariableResponse
204: void
}
diff --git a/packages/contracts/generated/api/console/snippets/zod.gen.ts b/packages/contracts/generated/api/console/snippets/zod.gen.ts
index 65ac302b2ae..66440e07f5c 100644
--- a/packages/contracts/generated/api/console/snippets/zod.gen.ts
+++ b/packages/contracts/generated/api/console/snippets/zod.gen.ts
@@ -90,33 +90,6 @@ export const zSnippetDraftRunPayload = z.object({
inputs: z.record(z.string(), z.unknown()),
})
-export const zWorkflowDraftVariable = z.object({
- description: z.string().optional(),
- edited: z.boolean().optional(),
- full_content: z.record(z.string(), z.unknown()).optional(),
- id: z.string().optional(),
- is_truncated: z.boolean().optional(),
- name: z.string().optional(),
- selector: z.array(z.string()).optional(),
- type: z.string().optional(),
- value: z
- .union([
- z.string(),
- z.int(),
- z.number(),
- z.boolean(),
- z.record(z.string(), z.unknown()),
- z.array(z.unknown()),
- ])
- .nullish(),
- value_type: z.string().optional(),
- visible: z.boolean().optional(),
-})
-
-export const zWorkflowDraftVariableList = z.object({
- items: z.array(zWorkflowDraftVariable).optional(),
-})
-
/**
* WorkflowDraftVariableUpdatePayload
*/
@@ -495,21 +468,61 @@ export const zComposerValidationFindingsResponse = z.object({
warnings: z.array(zComposerValidationWarningResponse).optional(),
})
-export const zWorkflowDraftVariableWithoutValue = z.object({
- description: z.string().optional(),
- edited: z.boolean().optional(),
- id: z.string().optional(),
- is_truncated: z.boolean().optional(),
- name: z.string().optional(),
- selector: z.array(z.string()).optional(),
- type: z.string().optional(),
- value_type: z.string().optional(),
- visible: z.boolean().optional(),
+/**
+ * WorkflowDraftVariableWithoutValueResponse
+ */
+export const zWorkflowDraftVariableWithoutValueResponse = z.object({
+ description: z.string(),
+ edited: z.boolean(),
+ id: z.string(),
+ is_truncated: z.boolean(),
+ name: z.string(),
+ selector: z.array(z.string()),
+ type: z.string(),
+ value_type: z.string(),
+ visible: z.boolean(),
})
-export const zWorkflowDraftVariableListWithoutValue = z.object({
- items: z.array(zWorkflowDraftVariableWithoutValue).optional(),
- total: z.int().optional(),
+/**
+ * WorkflowDraftVariableListWithoutValueResponse
+ */
+export const zWorkflowDraftVariableListWithoutValueResponse = z.object({
+ items: z.array(zWorkflowDraftVariableWithoutValueResponse),
+ total: z.int().nullable(),
+})
+
+/**
+ * WorkflowDraftVariableFullContentResponse
+ */
+export const zWorkflowDraftVariableFullContentResponse = z.object({
+ download_url: z.string(),
+ length: z.int().nullable(),
+ size_bytes: z.int().nullable(),
+ value_type: z.string(),
+})
+
+/**
+ * WorkflowDraftVariableResponse
+ */
+export const zWorkflowDraftVariableResponse = z.object({
+ description: z.string(),
+ edited: z.boolean(),
+ full_content: zWorkflowDraftVariableFullContentResponse.nullable(),
+ id: z.string(),
+ is_truncated: z.boolean(),
+ name: z.string(),
+ selector: z.array(z.string()),
+ type: z.string(),
+ value: zJsonValue,
+ value_type: z.string(),
+ visible: z.boolean(),
+})
+
+/**
+ * WorkflowDraftVariableListResponse
+ */
+export const zWorkflowDraftVariableListResponse = z.object({
+ items: z.array(zWorkflowDraftVariableResponse),
})
/**
@@ -1692,7 +1705,7 @@ export const zGetSnippetsBySnippetIdWorkflowsDraftConversationVariablesPath = z.
* Conversation variables retrieved successfully
*/
export const zGetSnippetsBySnippetIdWorkflowsDraftConversationVariablesResponse =
- zWorkflowDraftVariableList
+ zWorkflowDraftVariableListResponse
export const zGetSnippetsBySnippetIdWorkflowsDraftEnvironmentVariablesPath = z.object({
snippet_id: z.uuid(),
@@ -1876,7 +1889,7 @@ export const zGetSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdVariablesPath = z
* Node variables retrieved successfully
*/
export const zGetSnippetsBySnippetIdWorkflowsDraftNodesByNodeIdVariablesResponse =
- zWorkflowDraftVariableList
+ zWorkflowDraftVariableListResponse
export const zPostSnippetsBySnippetIdWorkflowsDraftRunBody = zSnippetDraftRunPayload
@@ -1897,7 +1910,7 @@ export const zGetSnippetsBySnippetIdWorkflowsDraftSystemVariablesPath = z.object
* System variables retrieved successfully
*/
export const zGetSnippetsBySnippetIdWorkflowsDraftSystemVariablesResponse =
- zWorkflowDraftVariableList
+ zWorkflowDraftVariableListResponse
export const zDeleteSnippetsBySnippetIdWorkflowsDraftVariablesPath = z.object({
snippet_id: z.uuid(),
@@ -1921,7 +1934,7 @@ export const zGetSnippetsBySnippetIdWorkflowsDraftVariablesQuery = z.object({
* Workflow variables retrieved successfully
*/
export const zGetSnippetsBySnippetIdWorkflowsDraftVariablesResponse =
- zWorkflowDraftVariableListWithoutValue
+ zWorkflowDraftVariableListWithoutValueResponse
export const zDeleteSnippetsBySnippetIdWorkflowsDraftVariablesByVariableIdPath = z.object({
snippet_id: z.uuid(),
@@ -1942,7 +1955,7 @@ export const zGetSnippetsBySnippetIdWorkflowsDraftVariablesByVariableIdPath = z.
* Variable retrieved successfully
*/
export const zGetSnippetsBySnippetIdWorkflowsDraftVariablesByVariableIdResponse =
- zWorkflowDraftVariable
+ zWorkflowDraftVariableResponse
export const zPatchSnippetsBySnippetIdWorkflowsDraftVariablesByVariableIdBody =
zWorkflowDraftVariableUpdatePayload
@@ -1956,7 +1969,7 @@ export const zPatchSnippetsBySnippetIdWorkflowsDraftVariablesByVariableIdPath =
* Variable updated successfully
*/
export const zPatchSnippetsBySnippetIdWorkflowsDraftVariablesByVariableIdResponse =
- zWorkflowDraftVariable
+ zWorkflowDraftVariableResponse
export const zPutSnippetsBySnippetIdWorkflowsDraftVariablesByVariableIdResetPath = z.object({
snippet_id: z.uuid(),
@@ -1964,7 +1977,7 @@ export const zPutSnippetsBySnippetIdWorkflowsDraftVariablesByVariableIdResetPath
})
export const zPutSnippetsBySnippetIdWorkflowsDraftVariablesByVariableIdResetResponse = z.union([
- zWorkflowDraftVariable,
+ zWorkflowDraftVariableResponse,
z.void(),
])