mirror of
https://github.com/langgenius/dify.git
synced 2026-06-10 18:24:09 +08:00
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
34f3591d4c
commit
28cc3fc10d
@ -923,31 +923,33 @@ class WorkflowGenerator:
|
||||
@classmethod
|
||||
def _rewrite_refs_in_data(cls, value: Any, id_map: dict[str, str]) -> None:
|
||||
"""Recursive sibling of ``_collect_refs_in_data`` that does rewrites."""
|
||||
if isinstance(value, dict):
|
||||
for k, v in list(value.items()):
|
||||
if k in cls._ID_FIELDS and isinstance(v, str):
|
||||
# Direct id field — apply the longest matching prefix
|
||||
# (handles ``"nodeKstart"`` where ``nodeK`` is the
|
||||
# container's old id).
|
||||
for old, new in sorted(id_map.items(), key=lambda kv: -len(kv[0])):
|
||||
if old in v:
|
||||
value[k] = v.replace(old, new)
|
||||
v = value[k]
|
||||
if isinstance(v, str):
|
||||
rewritten = cls._LENIENT_VAR_REF_RE.sub(lambda m: cls._rewrite_var_ref(m, id_map), v)
|
||||
if rewritten != v:
|
||||
value[k] = rewritten
|
||||
elif isinstance(v, list) and len(v) == 2 and all(isinstance(x, str) for x in v) and v[0] in id_map:
|
||||
# 2-element ``["node-id", "var"]`` selector list.
|
||||
value[k] = [id_map[v[0]], v[1]]
|
||||
else:
|
||||
cls._rewrite_refs_in_data(v, id_map)
|
||||
elif isinstance(value, list):
|
||||
for item in value:
|
||||
cls._rewrite_refs_in_data(item, id_map)
|
||||
match value:
|
||||
case dict():
|
||||
for k, v in list(value.items()):
|
||||
if k in cls._ID_FIELDS and isinstance(v, str):
|
||||
# Direct id field — apply the longest matching prefix
|
||||
# (handles ``"nodeKstart"`` where ``nodeK`` is the
|
||||
# container's old id).
|
||||
for old, new in sorted(id_map.items(), key=lambda kv: -len(kv[0])):
|
||||
if old in v:
|
||||
value[k] = v.replace(old, new)
|
||||
v = value[k]
|
||||
match v:
|
||||
case str():
|
||||
rewritten = cls._LENIENT_VAR_REF_RE.sub(lambda m: cls._rewrite_var_ref(m, id_map), v)
|
||||
if rewritten != v:
|
||||
value[k] = rewritten
|
||||
case [str(v0), str(v1)] if v0 in id_map:
|
||||
# 2-element ``["node-id", "var"]`` selector list.
|
||||
value[k] = [id_map[v0], v1]
|
||||
case _:
|
||||
cls._rewrite_refs_in_data(v, id_map)
|
||||
case list():
|
||||
for item in value:
|
||||
cls._rewrite_refs_in_data(item, id_map)
|
||||
|
||||
@classmethod
|
||||
def _rewrite_var_ref(cls, m: "re.Match[str]", id_map: dict[str, str]) -> str:
|
||||
def _rewrite_var_ref(cls, m: re.Match[str], id_map: dict[str, str]) -> str:
|
||||
node_id = m.group(1)
|
||||
rest = m.group(2)
|
||||
new_id = id_map.get(node_id, node_id)
|
||||
|
||||
@ -87,24 +87,26 @@ def _dict_to_workflow_node_execution_model(data: dict[str, Any]) -> WorkflowNode
|
||||
|
||||
# Handle datetime fields
|
||||
created_at = data.get("created_at")
|
||||
if created_at:
|
||||
if isinstance(created_at, str):
|
||||
match created_at:
|
||||
case None:
|
||||
# Provide default created_at if missing
|
||||
model.created_at = datetime.now()
|
||||
case str():
|
||||
model.created_at = datetime.fromisoformat(created_at)
|
||||
elif isinstance(created_at, (int, float)):
|
||||
case int() | float():
|
||||
model.created_at = datetime.fromtimestamp(created_at)
|
||||
else:
|
||||
case _:
|
||||
model.created_at = created_at
|
||||
else:
|
||||
# Provide default created_at if missing
|
||||
model.created_at = datetime.now()
|
||||
|
||||
finished_at = data.get("finished_at")
|
||||
if finished_at:
|
||||
if isinstance(finished_at, str):
|
||||
match finished_at:
|
||||
case None:
|
||||
...
|
||||
case str():
|
||||
model.finished_at = datetime.fromisoformat(finished_at)
|
||||
elif isinstance(finished_at, (int, float)):
|
||||
case int() | float():
|
||||
model.finished_at = datetime.fromtimestamp(finished_at)
|
||||
else:
|
||||
case _:
|
||||
model.finished_at = finished_at
|
||||
|
||||
return model
|
||||
|
||||
@ -456,16 +456,17 @@ class ToolTransformService:
|
||||
if depth >= ToolTransformService._MCP_SCHEMA_TYPE_RESOLUTION_MAX_DEPTH:
|
||||
return "string"
|
||||
prop_type = prop.get("type")
|
||||
if isinstance(prop_type, list):
|
||||
non_null_types = [type_name for type_name in prop_type if type_name != "null"]
|
||||
if non_null_types:
|
||||
return non_null_types[0]
|
||||
if prop_type:
|
||||
return "string"
|
||||
elif isinstance(prop_type, str):
|
||||
if prop_type == "null":
|
||||
return "string"
|
||||
return prop_type
|
||||
match prop_type:
|
||||
case list():
|
||||
non_null_types = [type_name for type_name in prop_type if type_name != "null"]
|
||||
if non_null_types:
|
||||
return non_null_types[0]
|
||||
if prop_type:
|
||||
return "string"
|
||||
case str():
|
||||
if prop_type == "null":
|
||||
return "string"
|
||||
return prop_type
|
||||
|
||||
for union_key in ("anyOf", "oneOf"):
|
||||
union_schemas = prop.get(union_key)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user