feat(dsl): filter out credential IDs from workflow and model configuration exports

feat/tool-plugin-oauth
Harry 7 months ago
parent 7de3436e6b
commit 6cb4a6f692

@ -575,17 +575,25 @@ class AppDslService:
raise ValueError("Missing draft workflow configuration, please check.") raise ValueError("Missing draft workflow configuration, please check.")
workflow_dict = workflow.to_dict(include_secret=include_secret) workflow_dict = workflow.to_dict(include_secret=include_secret)
# TODO: refactor: we need a better way to filter workspace related data from nodes
for node in workflow_dict.get("graph", {}).get("nodes", []): for node in workflow_dict.get("graph", {}).get("nodes", []):
if node.get("data", {}).get("type", "") == NodeType.KNOWLEDGE_RETRIEVAL.value: node_data = node.get("data", {})
dataset_ids = node["data"].get("dataset_ids", []) if not node_data:
node["data"]["dataset_ids"] = [ continue
data_type = node_data.get("type", "")
if data_type == NodeType.KNOWLEDGE_RETRIEVAL.value:
dataset_ids = node_data.get("dataset_ids", [])
node_data["dataset_ids"] = [
cls.encrypt_dataset_id(dataset_id=dataset_id, tenant_id=app_model.tenant_id) cls.encrypt_dataset_id(dataset_id=dataset_id, tenant_id=app_model.tenant_id)
for dataset_id in dataset_ids for dataset_id in dataset_ids
] ]
# filter credential id from tool node # filter credential id from tool node
if node.get("data", {}).get("type", "") == NodeType.TOOL.value: if not include_secret and data_type == NodeType.TOOL.value:
node["data"]["credential_id"] = None node_data.pop("credential_id", None)
# filter credential id from agent node
if not include_secret and data_type == NodeType.AGENT.value:
for tool in node_data.get("agent_parameters", {}).get("tools", {}).get("value", []):
tool.pop("credential_id", None)
export_data["workflow"] = workflow_dict export_data["workflow"] = workflow_dict
dependencies = cls._extract_dependencies_from_workflow(workflow) dependencies = cls._extract_dependencies_from_workflow(workflow)
@ -607,7 +615,15 @@ class AppDslService:
if not app_model_config: if not app_model_config:
raise ValueError("Missing app configuration, please check.") raise ValueError("Missing app configuration, please check.")
export_data["model_config"] = app_model_config.to_dict() model_config = app_model_config.to_dict()
# TODO: refactor: we need a better way to filter workspace related data from model config
# filter credential id from model config
for tool in model_config.get("agent_mode", {}).get("tools", []):
tool.pop("credential_id", None)
export_data["model_config"] = model_config
dependencies = cls._extract_dependencies_from_model_config(app_model_config.to_dict()) dependencies = cls._extract_dependencies_from_model_config(app_model_config.to_dict())
export_data["dependencies"] = [ export_data["dependencies"] = [
jsonable_encoder(d.model_dump()) jsonable_encoder(d.model_dump())

Loading…
Cancel
Save