summaryrefslogtreecommitdiff
path: root/frontend/src/store
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/store')
-rw-r--r--frontend/src/store/flowStore.ts48
1 files changed, 28 insertions, 20 deletions
diff --git a/frontend/src/store/flowStore.ts b/frontend/src/store/flowStore.ts
index 636113d..49a8ece 100644
--- a/frontend/src/store/flowStore.ts
+++ b/frontend/src/store/flowStore.ts
@@ -188,19 +188,24 @@ const useFlowStore = create<FlowState>((set, get) => ({
findNonOverlappingPosition: (baseX: number, baseY: number) => {
const { nodes } = get();
- const nodeWidth = 220;
- const nodeHeight = 80;
- const padding = 10;
+ // Estimate larger dimensions to be safe, considering dynamic handles
+ const nodeWidth = 300;
+ const nodeHeight = 200;
+ const padding = 20;
let x = baseX;
let y = baseY;
let attempts = 0;
- const maxAttempts = 30;
+ const maxAttempts = 100; // Increase attempts
const isOverlapping = (testX: number, testY: number) => {
return nodes.some(node => {
+ // Use the same estimated dimensions for existing nodes too
+ // Ideally we would know their actual dimensions, but this is a safe approximation
const nodeX = node.position.x;
const nodeY = node.position.y;
+
+ // Check for overlap
return !(testX + nodeWidth + padding < nodeX ||
testX > nodeX + nodeWidth + padding ||
testY + nodeHeight + padding < nodeY ||
@@ -208,11 +213,13 @@ const useFlowStore = create<FlowState>((set, get) => ({
});
};
- // Try positions in a tighter spiral pattern
+ // Try positions in a spiral pattern
while (isOverlapping(x, y) && attempts < maxAttempts) {
attempts++;
- const angle = attempts * 0.7;
- const radius = 30 + attempts * 15;
+ // Spiral parameters
+ const angle = attempts * 0.5; // Slower rotation
+ const radius = 50 + attempts * 30; // Faster expansion
+
x = baseX + Math.cos(angle) * radius;
y = baseY + Math.sin(angle) * radius;
}
@@ -1082,12 +1089,15 @@ const useFlowStore = create<FlowState>((set, get) => ({
}
// Create new node to the right
- const newNodeId = `node_${Date.now()}`;
- const newPos = {
- x: fromNode.position.x + 300,
- y: fromNode.position.y
- };
+ // Use findNonOverlappingPosition to avoid collision, starting from the ideal position
+ const idealX = fromNode.position.x + 300;
+ const idealY = fromNode.position.y;
+
+ // Check if ideal position overlaps
+ const { findNonOverlappingPosition } = get();
+ const newPos = findNonOverlappingPosition(idealX, idealY);
+ const newNodeId = `node_${Date.now()}`;
const newNode: LLMNode = {
id: newNodeId,
type: 'llmNode',
@@ -1615,24 +1625,22 @@ const useFlowStore = create<FlowState>((set, get) => ({
// A. Pass-through traces (append history) - only if there's a downstream edge
uniqueIncoming.forEach(t => {
- // When a trace passes through a node and gets modified, it effectively becomes a NEW branch of that trace.
- // We must append the current node ID to the trace ID to distinguish branches.
- // e.g. Trace "root" -> passes Node A -> becomes "root_A"
- // If it passes Node B -> becomes "root_B"
- // Downstream Node D can then distinguish "root_A" from "root_B".
+ // SIMPLIFICATION: Keep the same Trace ID for pass-through traces.
+ // This ensures A-B-C appears as a single continuous trace with the same ID.
+ // Only branch/fork traces get new IDs.
- const newTraceId = `${t.id}_${node.id}`;
+ const passThroughId = t.id;
// Only create pass-through if there's actually a downstream edge using it
const hasDownstreamEdge = updatedEdges.some(e =>
e.source === node.id &&
- (e.sourceHandle === `trace-${newTraceId}` || e.sourceHandle === `trace-${t.id}`)
+ (e.sourceHandle === `trace-${passThroughId}`)
);
if (hasDownstreamEdge) {
myOutgoingTraces.push({
...t,
- id: newTraceId,
+ id: passThroughId,
// Keep original sourceNodeId - this is a pass-through, not originated here
sourceNodeId: t.sourceNodeId,
messages: [...t.messages, ...myResponseMsg]