mirror of
https://github.com/langgenius/dify.git
synced 2026-10-04 13:47:55 +08:00
copilot: CopilotContext Edit fields + serde defaults
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
8f39028fda
commit
f668959ece
3 files changed
+27
No files matched your search
@@ -237,6 +237,10 @@ class CopilotContext:
|
||||
resource_selection: dict[str, Any] = field(default_factory=dict)
|
||||
built_node_ids: list[str] = field(default_factory=list)
|
||||
|
||||
# -- Edit fields (Slice 3, additive) --
|
||||
edit_rules: dict[str, Any] = field(default_factory=dict)
|
||||
edit_target_node_ids: list[str] = field(default_factory=list)
|
||||
|
||||
|
||||
@dataclass(kw_only=True)
|
||||
class Action:
|
||||
|
||||
@@ -67,4 +67,6 @@ def context_from_dict(d: dict[str, Any]) -> CopilotContext:
|
||||
plan_version_tag=d.get("plan_version_tag", ""),
|
||||
resource_selection=dict(d.get("resource_selection") or {}),
|
||||
built_node_ids=list(d.get("built_node_ids") or []),
|
||||
edit_rules=dict(d.get("edit_rules") or {}),
|
||||
edit_target_node_ids=list(d.get("edit_target_node_ids") or []),
|
||||
)
|
||||
@@ -113,3 +113,24 @@ def test_context_from_dict_defaults_build_fields_when_absent():
|
||||
assert fc.goal_text == ""
|
||||
assert fc.requirements == {}
|
||||
assert fc.plan_items == []
|
||||
|
||||
|
||||
def test_context_roundtrip_preserves_edit_fields():
|
||||
from core.workflow_copilot.models import CopilotContext
|
||||
from services.workflow_copilot.serde import context_from_dict, context_to_dict
|
||||
|
||||
fc = CopilotContext(
|
||||
edit_rules={"risk_threshold": "high", "preserve_summary": True},
|
||||
edit_target_node_ids=["llm", "knowledge_retrieval"],
|
||||
)
|
||||
out = context_from_dict(context_to_dict(fc))
|
||||
assert out.edit_rules == {"risk_threshold": "high", "preserve_summary": True}
|
||||
assert out.edit_target_node_ids == ["llm", "knowledge_retrieval"]
|
||||
|
||||
|
||||
def test_context_from_dict_defaults_edit_fields_when_absent():
|
||||
from services.workflow_copilot.serde import context_from_dict
|
||||
|
||||
out = context_from_dict({}) # an older row with no edit_* keys
|
||||
assert out.edit_rules == {}
|
||||
assert out.edit_target_node_ids == []
|
||||
Reference in new issue
Block a user