Skip to content

Conversation

@aadamgough
Copy link
Contributor

Summary

Right now, we can only index into an 2d array with a function block. Variables for <array.values[0][0]> don't resolve in a non-function block—only <array.values[0]> does. This allows users to index into <array.values[0][0]>. Added strict regex to prevent "[" to be treated as index if <array.values[0][0]> would contain "[".

Type of Change

  • Other: improvement

Testing

See video

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)

Screenshots/Videos

Screen.Recording.2025-09-13.at.1.04.02.PM.mov

@vercel
Copy link

vercel bot commented Sep 13, 2025

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

Project Deployment Preview Comments Updated (UTC)
sim Ready Ready Preview Comment Sep 15, 2025 10:06pm
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Sep 15, 2025 10:06pm

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 enhances the variable resolver in the sim executor to support 2D array indexing in variable references. Previously, users could only access single-level array elements like <array.values[0]> in non-function blocks, but nested array access like <array.values[0][0]> required writing custom function blocks.

The implementation adds two key components:

  1. Enhanced Pattern Detection: A new regex pattern /^(?:[^[]+(?:\[\d+\])+|(?:\[\d+\])+)$/ validates proper array indexing syntax and prevents false matches on bracket characters that might legitimately exist within array values.

  2. Iterative Resolution Logic: A new private method resolvePartWithIndices handles the sequential application of multiple array indices, extracting property names, validating array types, checking bounds, and applying each index in order.

This change integrates seamlessly with the existing resolver system in apps/sim/executor/resolver/resolver.ts, extending the resolveVariablePart method's capabilities while maintaining backward compatibility. The enhancement allows users to access deeply nested array structures directly in workflow configurations without requiring custom function blocks, making the system more user-friendly for common data access patterns.

Confidence score: 4/5

  • This PR is safe to merge with minimal risk as it extends existing functionality without breaking changes
  • Score reflects well-structured implementation with proper validation and backward compatibility
  • Pay close attention to the regex pattern and bounds checking logic in the new resolvePartWithIndices method

1 file reviewed, no comments

Edit Code Review Bot Settings | Greptile

@vercel vercel bot temporarily deployed to Preview – docs September 15, 2025 22:02 Inactive
@waleedlatif1 waleedlatif1 merged commit ba21d27 into staging Sep 15, 2025
6 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/array-index branch September 15, 2025 22:43
arenadeveloper02 pushed a commit to arenadeveloper02/p2-sim that referenced this pull request Sep 19, 2025
…ai#1328)

* resolved variables for 2d arrays

* added tests

---------

Co-authored-by: Adam Gough <adamgough@Mac.attlocal.net>
Co-authored-by: waleedlatif1 <walif6@gmail.com>
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.

3 participants