mirror of
https://github.com/langgenius/dify.git
synced 2026-10-04 13:47:55 +08:00
refactor(api): isolate trial app and workflow detail previews (#42659)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
6f61401a91
commit
2da0db7df5
21 files changed
+2536
-491
No files matched your search
@@ -0,0 +1,33 @@
|
||||
"""Load persisted workflow environment variables without requiring an ORM model."""
|
||||
|
||||
import json
|
||||
from typing import cast
|
||||
|
||||
from core.helper import encrypter
|
||||
from core.workflow.llm_environment_variable import LLMEnvironmentVariable
|
||||
from factories import variable_factory
|
||||
from graphon.variables import FloatVariable, IntegerVariable, SecretVariable, StringVariable, VariableBase
|
||||
|
||||
|
||||
def load_environment_variables(
|
||||
*, tenant_id: str | None, serialized_variables: str | None
|
||||
) -> list[StringVariable | IntegerVariable | FloatVariable | SecretVariable | LLMEnvironmentVariable]:
|
||||
# Use the workflow owner to avoid relying on request user in background threads.
|
||||
if not tenant_id:
|
||||
return []
|
||||
|
||||
variables = cast(dict[str, dict[str, object]], json.loads(serialized_variables or "{}"))
|
||||
results = [variable_factory.build_environment_variable_from_mapping(value) for value in variables.values()]
|
||||
|
||||
def decrypt_func(
|
||||
var: VariableBase,
|
||||
) -> StringVariable | IntegerVariable | FloatVariable | SecretVariable | LLMEnvironmentVariable:
|
||||
match var:
|
||||
case SecretVariable():
|
||||
return var.model_copy(update={"value": encrypter.decrypt_token(tenant_id=tenant_id, token=var.value)})
|
||||
case StringVariable() | IntegerVariable() | FloatVariable() | LLMEnvironmentVariable():
|
||||
return var
|
||||
case _:
|
||||
raise AssertionError(f"Unexpected variable type for environment variable: {type(var)}")
|
||||
|
||||
return [decrypt_func(var) for var in results]
|
||||
Reference in new issue
Block a user