Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 32 additions & 27 deletions src/poly/handlers/sync_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,36 @@ def _read_flows_from_projection(

for step_id, step in flow_data.get("steps", {}).get("entities", {}).items():
local_resource_id = f"{flow_data['name']}_{step_id}"
is_function_step = step.get("type") == "function_step"
conditions = [
Condition(
resource_id=condition_data["id"],
name=condition_data["config"]["value"]["details"]["label"],
condition_type=condition_data["config"]["$case"],
description=condition_data["config"]["value"]["details"].get(
"description", ""
),
required_entities=condition_data["config"]["value"]["details"].get(
"requiredEntities", []
),
child_step=condition_data["config"]["value"].get("childStepId", ""),
step_id=step_id,
flow_id=flow_id,
ingress=condition_data["config"]["value"]["details"].get(
"ingressPosition", "top"
),
position=condition_data["config"]["value"]["details"].get(
"position", {"x": 0.0, "y": 0.0}
),
exit_flow_position=condition_data["config"]["value"].get(
"exitFlowPosition", None
),
parent_is_no_code_step=not is_function_step,
)
for condition_data in step.get("conditions", [])
]

if step.get("type") == "function_step":
if is_function_step:
function = step.get("function", {})
resources.setdefault(FunctionStep, {})[local_resource_id] = FunctionStep(
resource_id=local_resource_id,
Expand All @@ -547,6 +575,7 @@ def _read_flows_from_projection(
),
parameters=[],
function_id=function.get("id", ""),
conditions=conditions,
)
continue

Expand Down Expand Up @@ -592,32 +621,7 @@ def _read_flows_from_projection(
flow_id=flow_id,
),
prompt=step.get("prompt", ""),
conditions=[
Condition(
resource_id=condition_data["id"],
name=condition_data["config"]["value"]["details"]["label"],
condition_type=condition_data["config"]["$case"],
description=condition_data["config"]["value"]["details"].get(
"description", ""
),
required_entities=condition_data["config"]["value"]["details"].get(
"requiredEntities", []
),
child_step=condition_data["config"]["value"].get("childStepId", ""),
step_id=step_id,
flow_id=flow_id,
ingress=condition_data["config"]["value"]["details"].get(
"ingressPosition", "top"
),
position=condition_data["config"]["value"]["details"].get(
"position", {"x": 0.0, "y": 0.0}
),
exit_flow_position=condition_data["config"]["value"].get(
"exitFlowPosition", None
),
)
for condition_data in step.get("conditions", [])
],
conditions=conditions,
position=step.get("position"),
extracted_entities=extracted_entities,
)
Expand Down Expand Up @@ -1041,6 +1045,7 @@ def _read_languages_from_projection(
# If variable references will change, we should update the variable first so
# it isn't pruned by the backend.
Variable,
Condition,
]

def queue_resources(
Expand Down
12 changes: 12 additions & 0 deletions src/poly/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,16 @@ def _clean_resources_before_push(
)
post_push_deleted_resources.setdefault(FlowStep, {})[dummy.resource_id] = dummy

# The backend auto-creates conditions from goto_step() calls in function step
# code. To avoid duplicate condition labels, create new FunctionSteps with stub
# code, let our explicit conditions be created, then update with the real code.
for resource_id, resource in list(new_resources.get(FunctionStep, {}).items()):
if isinstance(resource, FunctionStep) and resource.conditions:
stub = copy.deepcopy(resource)
stub.code = f"def {resource.name}(conv: Conversation, flow: Flow):\n pass\n"
new_resources[FunctionStep][resource_id] = stub
updated_resources.setdefault(FunctionStep, {})[resource_id] = resource

# Deleting flow config deletes all its steps/functions, so we don't need to
for flow_config_id in deleted_resources.get(FlowConfig, {}):
for resource_type in [FlowStep, Function, FunctionStep]:
Expand Down Expand Up @@ -2082,6 +2092,7 @@ def read_local_resource(
additional_kwargs["known_function_id"] = None
additional_kwargs["known_position"] = None
additional_kwargs["known_latency_control"] = {}
additional_kwargs["known_conditions"] = []

if original_resource:
if not isinstance(original_resource, FunctionStep):
Expand All @@ -2091,6 +2102,7 @@ def read_local_resource(
additional_kwargs["known_function_id"] = original_resource.function_id
additional_kwargs["known_position"] = original_resource.position
additional_kwargs["known_latency_control"] = original_resource.latency_control
additional_kwargs["known_conditions"] = original_resource.conditions

try:
resource = resource_class.read_local_resource(
Expand Down
Loading
Loading