Skip to content

Conversation

@Sg312
Copy link
Contributor

@Sg312 Sg312 commented Dec 23, 2025

Summary

Add tools to access block outputs and upstream references

Type of Change

  • New feature

Testing

Manual

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 Dec 23, 2025

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

1 Skipped Deployment
Project Deployment Review Updated (UTC)
docs Skipped Skipped Dec 23, 2025 8:03am

@Sg312 Sg312 changed the base branch from main to staging December 23, 2025 07:43
@Sg312
Copy link
Contributor Author

Sg312 commented Dec 23, 2025

@greptile

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 23, 2025

Greptile Summary

This PR adds two new copilot tools that enable the AI assistant to introspect workflow structure and block relationships. The get_block_outputs tool retrieves outputs for specific blocks or all blocks in a workflow, while the get_block_upstream_references tool analyzes workflow graph connections to determine which block outputs and variables are accessible to each block based on upstream dependencies.

Key Changes:

  • Created shared utility functions in block-output-utils.ts for computing block outputs, handling subflow logic, and managing workflow context
  • Implemented GetBlockOutputsClientTool to retrieve block outputs with special handling for loops, parallels, evaluators, and variables blocks
  • Implemented GetBlockUpstreamReferencesClientTool with graph traversal logic using BlockPathCalculator to find accessible upstream blocks
  • Added proper Zod schemas for input validation and output type safety
  • Registered both tools in the copilot registry and store with appropriate metadata and SSE schemas

Issues Found:

  • Unused variables normalizedBlockName, insideSubflowOutputs, and outsideSubflowOutputs in get-block-outputs.ts:93-96

Confidence Score: 4/5

  • This PR is safe to merge with minor cleanup needed
  • The implementation is well-structured with proper error handling, type safety, and integration into existing patterns. The only issue is unused variables that should be removed for code cleanliness. The logic correctly handles complex workflow scenarios including loops, parallels, and graph traversal.
  • apps/sim/lib/copilot/tools/client/workflow/get-block-outputs.ts requires minor cleanup to remove unused variables

Important Files Changed

Filename Overview
apps/sim/lib/copilot/tools/client/workflow/block-output-utils.ts new utility file with functions to compute block outputs, merge sub-blocks, and handle workflow context
apps/sim/lib/copilot/tools/client/workflow/get-block-outputs.ts new client tool to retrieve block outputs with proper error handling, has unused variables on lines 93-96
apps/sim/lib/copilot/tools/client/workflow/get-block-upstream-references.ts new client tool to retrieve upstream references for blocks with graph traversal logic

Sequence Diagram

sequenceDiagram
    participant Copilot
    participant GetBlockOutputsTool
    participant GetUpstreamRefsTool
    participant WorkflowRegistry
    participant WorkflowStore
    participant SubBlockStore
    participant VariablesStore
    participant BlockPathCalculator

    Note over Copilot,BlockPathCalculator: Get Block Outputs Flow
    Copilot->>GetBlockOutputsTool: execute(blockIds?)
    GetBlockOutputsTool->>WorkflowRegistry: getState()
    WorkflowRegistry-->>GetBlockOutputsTool: activeWorkflowId
    GetBlockOutputsTool->>WorkflowStore: getState()
    WorkflowStore-->>GetBlockOutputsTool: blocks, loops, parallels
    GetBlockOutputsTool->>SubBlockStore: getWorkflowSubBlockValues(workflowId)
    SubBlockStore-->>GetBlockOutputsTool: subBlockValues
    
    loop For each block
        GetBlockOutputsTool->>GetBlockOutputsTool: computeBlockOutputPaths(block, ctx)
        GetBlockOutputsTool->>GetBlockOutputsTool: formatOutputsWithPrefix(paths, blockName)
    end
    
    GetBlockOutputsTool->>VariablesStore: getWorkflowVariables(workflowId)
    VariablesStore-->>GetBlockOutputsTool: variables
    GetBlockOutputsTool-->>Copilot: {blocks: [...], variables: [...]}

    Note over Copilot,BlockPathCalculator: Get Upstream References Flow
    Copilot->>GetUpstreamRefsTool: execute(blockIds)
    GetUpstreamRefsTool->>WorkflowRegistry: getState()
    WorkflowRegistry-->>GetUpstreamRefsTool: activeWorkflowId
    GetUpstreamRefsTool->>WorkflowStore: getState()
    WorkflowStore-->>GetUpstreamRefsTool: blocks, edges, loops, parallels
    GetUpstreamRefsTool->>SubBlockStore: getWorkflowSubBlockValues(workflowId)
    SubBlockStore-->>GetUpstreamRefsTool: subBlockValues
    
    loop For each blockId
        GetUpstreamRefsTool->>BlockPathCalculator: findAllPathNodes(edges, blockId)
        BlockPathCalculator-->>GetUpstreamRefsTool: ancestorIds
        GetUpstreamRefsTool->>GetUpstreamRefsTool: determine containing loops/parallels
        GetUpstreamRefsTool->>GetUpstreamRefsTool: build accessibleBlocks with outputs
    end
    
    GetUpstreamRefsTool->>VariablesStore: getWorkflowVariables(workflowId)
    VariablesStore-->>GetUpstreamRefsTool: variables
    GetUpstreamRefsTool-->>Copilot: {results: [{blockId, accessibleBlocks, variables}]}
Loading

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.

6 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@Sg312 Sg312 merged commit 3100daa into staging Dec 23, 2025
10 checks passed
@waleedlatif1 waleedlatif1 deleted the feat/copilot-reference-tags branch December 23, 2025 08:27
waleedlatif1 pushed a commit that referenced this pull request Dec 23, 2025
…ces (#2546)

* Add copilot references tools

* Minor fixes

* Omit vars field in block outputs when id is provided
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.

2 participants