use-get-begin-query.tsx


Overview

The file use-get-begin-query.tsx provides a collection of React hooks and utility functions designed to manage, build, and query the data inputs and outputs associated with the "Begin" node in a visual flow-based agent system. It primarily facilitates the extraction, transformation, and presentation of input/output variables and query parameters tied to the initial node of a flow graph.

Key functionalities include:

The file heavily interacts with the global graph store (useGraphStore), the agent form context (AgentFormContext), and external hooks such as useFetchAgent to access DSL globals.


Detailed Explanations

Imports and Dependencies


Key Constants and Types


Hooks and Functions

1. useSelectBeginNodeDataInputs()

2. useIsTaskMode()

3. useGetBeginNodeDataQuery()

4. useGetBeginNodeDataInputs()

5. useGetBeginNodeDataQueryIsSafe()

6. filterAllUpstreamNodeIds(edges: Edge[], nodeIds: string[])

7. buildOutputOptions(outputs: Record<string, any>, nodeId?, parentLabel?, icon?)

8. useBuildNodeOutputOptions(nodeId?: string)

9. useBuildBeginVariableOptions()

10. useBuildVariableOptions(nodeId?: string, parentId?: string)

11. useBuildQueryVariableOptions(n?: RAGFlowNodeType)

12. useBuildComponentIdOptions(nodeId?: string, parentId?: string)

13. useBuildComponentIdAndBeginOptions(nodeId?: string, parentId?: string)

14. useGetComponentLabelByValue(nodeId: string)

15. useGetVariableLabelByValue(nodeId: string)


Important Implementation Details and Algorithms


Interaction with Other Parts of the System


Usage Example

import React from 'react';
import { useGetBeginNodeDataInputs, useBuildVariableOptions } from './use-get-begin-query';

function BeginNodeInputsDisplay() {
  const inputs = useGetBeginNodeDataInputs();
  const variableOptions = useBuildVariableOptions('currentNodeId', 'parentNodeId');

  return (
    <div>
      <h3>Begin Node Inputs</h3>
      <ul>
        {inputs.map(input => (
          <li key={input.key}>{input.name} ({input.type})</li>
        ))}
      </ul>

      <h3>Variable Options</h3>
      <select>
        {variableOptions.map(group => (
          <optgroup label={typeof group.label === 'string' ? group.label : 'Variables'} key={group.label?.toString()}>
            {group.options.map(option => (
              <option key={option.value} value={option.value}>{option.label}</option>
            ))}
          </optgroup>
        ))}
      </select>
    </div>
  );
}

Visual Diagram

flowchart TD
  subgraph GraphStore
    G[getNode, nodes, edges]
  end

  subgraph BeginNodeHooks
    A[useSelectBeginNodeDataInputs]
    B[useIsTaskMode]
    C[useGetBeginNodeDataQuery]
    D[useGetBeginNodeDataInputs]
    E[useGetBeginNodeDataQueryIsSafe]
  end

  subgraph OptionBuilders
    F[useBuildNodeOutputOptions]
    G1[useBuildBeginVariableOptions]
    H[useBuildVariableOptions]
    I[useBuildQueryVariableOptions]
    J[useBuildComponentIdOptions]
    K[useBuildComponentIdAndBeginOptions]
  end

  subgraph LabelGetters
    L[useGetComponentLabelByValue]
    M[useGetVariableLabelByValue]
  end

  subgraph Utils
    N[filterAllUpstreamNodeIds]
    O[buildOutputOptions]
    P[transferToVariableType]
  end

  G -->|used by| A
  G -->|used by| B
  G -->|used by| C
  G -->|used by| D
  G -->|used by| E
  
  A -->|inputs| G1
  G -->|provides nodes, edges| F
  F -->|calls| N
  F -->|calls| O
  G1 -->|calls| P
  
  H -->|combines| G1
  H -->|combines| F
  H -->|combines| J
  
  I -->|extends| H
  I -->|uses| useFetchAgent
  
  K -->|combines| G1
  K -->|combines| J
  
  L -->|uses| K
  M -->|uses| I

Summary

The use-get-begin-query.tsx file is a vital utility and hook collection that supports the flow-based agent's Begin node data handling and variable option management. It bridges the graph data model with UI components by providing structured, memoized, and context-sensitive variable and output options, ensuring the frontend forms and selectors remain consistent, performant, and intuitive.

This file exemplifies best practices in React hook design, recursive graph traversal, and integration of external context data into complex UI state management.