Skip to content

feat(auto-layout): local auto layout#1144

Merged
emir-karabeg merged 1 commit intostagingfrom
feat/local-auto-layout
Aug 27, 2025
Merged

feat(auto-layout): local auto layout#1144
emir-karabeg merged 1 commit intostagingfrom
feat/local-auto-layout

Conversation

@emir-karabeg
Copy link
Collaborator

@emir-karabeg emir-karabeg commented Aug 27, 2025

Summary

Adds local auto layout for control-bar auto-layout that looks at the workflow block store for smart layouts.

Type of Change

  • New feature

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Aug 27, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
sim Ready Ready Preview Comment Aug 27, 2025 1:18am
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Aug 27, 2025 1:18am

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Summary

This PR introduces a local auto-layout feature that replaces server-side API calls with a client-side implementation for workflow positioning. The main changes involve:

  1. New local auto-layout implementation (local-auto-layout.ts) - A comprehensive graph-based positioning algorithm featuring topological sorting, barycentric crossing minimization, intelligent layout direction detection, and proper container node handling

  2. Control bar integration - Modified the control bar to use applyLocalAutoLayoutAndUpdateStore instead of the server-side applyAutoLayoutAndUpdateStore function

  3. Shared configuration - Exported DEFAULT_AUTO_LAYOUT_OPTIONS from the existing auto-layout utility with reduced spacing values (horizontal: 500→250, vertical: 400→200, layer: 700→350) to enable consistent defaults between remote and local implementations

The local implementation maintains the same interface as the server-side version while providing immediate visual feedback without network round-trips. It includes sophisticated features like cycle detection in topological sorting, optimistic updates with rollback capability on errors, and extensive logging for debugging. The algorithm handles complex scenarios including container nodes with relative positioning for children and intelligent viewport-based positioning.

This change aligns with the project's goal of improving user experience by eliminating network latency for auto-layout operations while maintaining full compatibility with existing workflow structures.

PR Description Notes:

  • The PR template is incomplete with placeholder text and no actual description of changes
  • Missing issue reference, testing details, and type of change selection
  • No screenshots provided despite this being a visual UI feature

Confidence score: 3/5

  • This PR introduces complex layout logic that may have edge cases with large workflows or unusual node configurations
  • Score reflects concerns about hardcoded viewport assumptions, potential performance issues, and complex position calculations that could fail in edge cases
  • Pay close attention to the new local-auto-layout.ts file, particularly the position calculation logic and container node handling

3 files reviewed, 2 comments

Edit Code Review Bot Settings | Greptile

Comment on lines +88 to +101
layoutOptions as {
strategy: 'smart' | 'hierarchical' | 'layered' | 'force-directed'
direction: 'horizontal' | 'vertical' | 'auto'
spacing: {
horizontal: number
vertical: number
layer: number
}
alignment: 'start' | 'center' | 'end'
padding: {
x: number
y: number
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Complex type assertion could be avoided with better interface design

Context Used: Context - Avoid using type assertions to 'any' in TypeScript. Instead, ensure proper type definitions are used to maintain type safety. (link)

Comment on lines +486 to +499
// Handle container node children positioning
Object.entries(layoutedBlocks).forEach(([blockId, block]) => {
if (block.data?.parentId) {
const parent = layoutedBlocks[block.data.parentId]
if (parent) {
// Adjust child position relative to parent with padding
const padding = 50
block.position = {
x: parent.position.x + padding,
y: parent.position.y + padding + 50, // Extra top padding for container header
}
}
}
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Container positioning logic modifies the block object directly, which could cause unintended side effects since it's a reference to the original object

Suggested change
// Handle container node children positioning
Object.entries(layoutedBlocks).forEach(([blockId, block]) => {
if (block.data?.parentId) {
const parent = layoutedBlocks[block.data.parentId]
if (parent) {
// Adjust child position relative to parent with padding
const padding = 50
block.position = {
x: parent.position.x + padding,
y: parent.position.y + padding + 50, // Extra top padding for container header
}
}
}
})
// Handle container node children positioning
Object.entries(layoutedBlocks).forEach(([blockId, block]) => {
if (block.data?.parentId) {
const parent = layoutedBlocks[block.data.parentId]
if (parent) {
// Adjust child position relative to parent with padding
const padding = 50
layoutedBlocks[blockId] = {
...block,
position: {
x: parent.position.x + padding,
y: parent.position.y + padding + 50, // Extra top padding for container header
}
}
}
}
})

@emir-karabeg emir-karabeg changed the title feat: local auto layout feat(auto-layout): local auto layout Aug 27, 2025
@emir-karabeg emir-karabeg merged commit 973a5c6 into staging Aug 27, 2025
5 checks passed
@emir-karabeg emir-karabeg deleted the feat/local-auto-layout branch August 27, 2025 02:03
waleedlatif1 pushed a commit that referenced this pull request Aug 27, 2025
waleedlatif1 added a commit that referenced this pull request Aug 27, 2025
…is for queueing docs in kb (#1143)

* improvement(kb): created knowledge, chunks, tags services and use redis for queueing docs in kb

* moved directories around

* cleanup

* bulk create docuemnt records after upload is completed

* fix(copilot): send api key to sim agent (#1142)

* Fix api key auth

* Lint

* ack PR comments

* added sort by functionality for headers in kb table

* updated

* test fallback from redis, fix styling

* cleanup copilot, fixed tooltips

* feat: local auto layout (#1144)

* feat: added llms.txt and robots.txt (#1145)

* fix(condition-block): edges not following blocks, duplicate issues (#1146)

* fix(condition-block): edges not following blocks, duplicate issues

* add subblock update to setActiveWorkflow

* Update apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/components/sub-block/components/condition-input.tsx

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

---------

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* fix dependency array

* fix(copilot-cleanup): support azure blob upload in copilot, remove dead code & consolidate other copilot files (#1147)

* cleanup

* support azure blob image upload

* imports cleanup

* PR comments

* ack PR comments

* fix key validation

* improvement(forwarding+excel): added forwarding and improve excel read (#1136)

* added forwarding for outlook

* lint

* improved excel sheet read

* addressed greptile

* fixed bodytext getting truncated

* fixed any type

* added html func

---------

Co-authored-by: Adam Gough <adamgough@Mac.attlocal.net>

* revert agent const

* update docs

---------

Co-authored-by: Siddharth Ganesan <33737564+Sg312@users.noreply.github.com>
Co-authored-by: Emir Karabeg <78010029+emir-karabeg@users.noreply.github.com>
Co-authored-by: Vikhyath Mondreti <vikhyathvikku@gmail.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: Vikhyath Mondreti <vikhyath@simstudio.ai>
Co-authored-by: Adam Gough <77861281+aadamgough@users.noreply.github.com>
Co-authored-by: Adam Gough <adamgough@Mac.attlocal.net>
arenadeveloper02 pushed a commit to arenadeveloper02/p2-sim that referenced this pull request Sep 19, 2025
arenadeveloper02 pushed a commit to arenadeveloper02/p2-sim that referenced this pull request Sep 19, 2025
…is for queueing docs in kb (simstudioai#1143)

* improvement(kb): created knowledge, chunks, tags services and use redis for queueing docs in kb

* moved directories around

* cleanup

* bulk create docuemnt records after upload is completed

* fix(copilot): send api key to sim agent (simstudioai#1142)

* Fix api key auth

* Lint

* ack PR comments

* added sort by functionality for headers in kb table

* updated

* test fallback from redis, fix styling

* cleanup copilot, fixed tooltips

* feat: local auto layout (simstudioai#1144)

* feat: added llms.txt and robots.txt (simstudioai#1145)

* fix(condition-block): edges not following blocks, duplicate issues (simstudioai#1146)

* fix(condition-block): edges not following blocks, duplicate issues

* add subblock update to setActiveWorkflow

* Update apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/components/sub-block/components/condition-input.tsx

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

---------

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* fix dependency array

* fix(copilot-cleanup): support azure blob upload in copilot, remove dead code & consolidate other copilot files (simstudioai#1147)

* cleanup

* support azure blob image upload

* imports cleanup

* PR comments

* ack PR comments

* fix key validation

* improvement(forwarding+excel): added forwarding and improve excel read (simstudioai#1136)

* added forwarding for outlook

* lint

* improved excel sheet read

* addressed greptile

* fixed bodytext getting truncated

* fixed any type

* added html func

---------

Co-authored-by: Adam Gough <adamgough@Mac.attlocal.net>

* revert agent const

* update docs

---------

Co-authored-by: Siddharth Ganesan <33737564+Sg312@users.noreply.github.com>
Co-authored-by: Emir Karabeg <78010029+emir-karabeg@users.noreply.github.com>
Co-authored-by: Vikhyath Mondreti <vikhyathvikku@gmail.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: Vikhyath Mondreti <vikhyath@simstudio.ai>
Co-authored-by: Adam Gough <77861281+aadamgough@users.noreply.github.com>
Co-authored-by: Adam Gough <adamgough@Mac.attlocal.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant