Skip to content

A platform for community discussion. Free, open, simple.

FIX: have ai to correctly use connection types and output index (#42579)

Joffrey JAFFEUX20d55bb76604
diff --git a/plugins/discourse-workflows/USE_CASES.md b/plugins/discourse-workflows/USE_CASES.md
index 724cbb84ff4..c1f0d61e822 100644
--- a/plugins/discourse-workflows/USE_CASES.md
+++ b/plugins/discourse-workflows/USE_CASES.md
@@ -61,7 +61,7 @@ For each run, record:
- Simple trust/text/category/staff checks should use `condition:filter`, not Code nodes. `condition:if` is for separate true/false branches.
- Trust level is only exposed as `$json.user.trust_level` on triggers with a user object (e.g. `trigger:post_created`); the post/topic payloads have no `trust_level`. When a trust-level check is needed but no `trust_level` field is in scope (topic-only triggers), resolve the cumulative `trust_level_N` automatic group and use `action:group` with `operation: check_membership` plus resolved `group_id` -- do not ask for clarification or add a Code node.
- Condition builder entries must use `leftValue` and `rightValue`; `left`/`right` will not execute correctly.
-- Connections leaving `condition:filter` or `condition:if` should use `connection_type: "true"` for the passing branch, not `main`.
+- Connections leaving `condition:filter` or `condition:if` use `connection_type: "main"`; select the passing branch with `output_index: 0` and the rejected branch with `output_index: 1`.
- Group membership checks should use `action:group` with `operation: check_membership` and the resolved `group_id` instead of Code nodes. Branch with `condition:if` on `$json.group_membership.in_group` when different member and non-member paths are needed.
- DM/personal-message notifications should use `action:send_personal_message` instead of chat or topic reply nodes.
- Forum `search`/`read` should not be used for node/schema discovery; use `workflow_node_catalog` and `workflow_validate_patch`.
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/ai/tools/workflow_validate_patch.rb b/plugins/discourse-workflows/lib/discourse_workflows/ai/tools/workflow_validate_patch.rb
index 7c603bca5f1..4b5f7c8242e 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/ai/tools/workflow_validate_patch.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/ai/tools/workflow_validate_patch.rb
@@ -153,10 +153,8 @@ module DiscourseWorkflows
def output_connection_types(node)
node_class =
DiscourseWorkflows::Registry.find_node_type(node["type"], version: node["typeVersion"])
- outputs = Array.wrap(node_class&.outputs(node["parameters"] || {}) || [:main])
- outputs.map do |output|
- output.respond_to?(:to_h) ? output.to_h.with_indifferent_access[:key].to_s : output.to_s
- end
+ ports = Array.wrap(node_class&.ports(node["parameters"] || {}) || [{ type: "main" }])
+ ports.map { |port| port[:type].to_s }.uniq
end
def incoming_connections(node_id, connection_records)
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/ai_workflow_author.rb b/plugins/discourse-workflows/lib/discourse_workflows/ai_workflow_author.rb
index ea00f43e20d..7fe6641ff45 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/ai_workflow_author.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/ai_workflow_author.rb
@@ -77,7 +77,7 @@ module DiscourseWorkflows
- remove_node: { op: "remove_node", node_id }
- add_connection: { op: "add_connection", from, to, output_index, input_index, connection_type }
- remove_connection: { op: "remove_connection", from, to, output_index, input_index }
- - In add_connection, use connection_type "main" for normal single-output nodes. For condition:filter and condition:if, connect the passing branch with connection_type "true"; use "false" only when the rejected/false branch should continue.
+ - In add_connection, use the output's numeric index to select a branch and use connection_type "main" for standard workflow ports. For condition:filter and condition:if, output_index 0 is the true/passing branch and output_index 1 is the false/rejected branch; connection_type remains "main" for both.
- If you update an existing node's parameters, also rename that node when its current name would no longer match the updated behavior. Keep edited node names aligned with the latest requested configuration; for example, when changing a wait node from one hour to two hours, include a rename_node operation such as "Wait 2 hours" in the same proposal.
- In add_node, node.credentials must be a JSON object. Use {} when no saved credential is selected, and do not copy the catalog's credential requirements array into node.credentials. Keep credentials as a sibling of parameters in node, never nested inside parameters.
- In add_node, prefer position as an object like { "x": 280, "y": 0 }. The server can normalize [x, y] arrays, but object positions are clearer.
diff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/ai/tools/workflow_validate_patch_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/ai/tools/workflow_validate_patch_spec.rb
index ba491c0c367..9f9a20d76b3 100644
--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/ai/tools/workflow_validate_patch_spec.rb
+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/ai/tools/workflow_validate_patch_spec.rb
@@ -307,7 +307,7 @@ RSpec.describe DiscourseWorkflows::Ai::Tools::WorkflowValidatePatch do
to: "dm-admin",
output_index: 0,
input_index: 0,
- connection_type: "true",
+ connection_type: "main",
},
]
@@ -649,7 +649,7 @@ RSpec.describe DiscourseWorkflows::Ai::Tools::WorkflowValidatePatch do
to: "log",
output_index: 0,
input_index: 0,
- connection_type: "main",
+ connection_type: "true",
},
]
@@ -657,7 +657,7 @@ RSpec.describe DiscourseWorkflows::Ai::Tools::WorkflowValidatePatch do
expect(result[:valid]).to eq(false)
expect(result[:graph_errors]).to contain_exactly(
- 'Filter posts output connection_type "main" is invalid for condition:filter. Use one of: true, false.',
+ 'Filter posts output connection_type "true" is invalid for condition:filter. Use one of: main.',
)
end