use-values.ts


Overview

The use-values.ts file defines a custom React hook named useValues designed to extract and memoize a list of value keys associated with a specific tool in a graph-based agent system. It leverages a centralized graph state store to retrieve the currently selected node and tool identifiers, then finds upstream node information and its associated "MCP" (likely a domain-specific term) metadata to produce a list of relevant keys.

This hook is primarily used to provide reactive and efficient access to the keys of form data related to a selected tool on a selected node. It benefits components that need to render or manipulate these keys without duplicating graph traversal or lookup logic.


Exports

useValues()

Description

useValues is a React hook that returns an object containing an items array. This array consists of the keys from the tool-related form data found in the upstream node corresponding to the currently selected node and tool in the graph.

Parameters

This hook takes no parameters directly. Instead, it internally accesses the global graph state store to get:

Returns

{
  items: string[]
}

Usage Example

import { useValues } from './use-values';

function ToolValuesList() {
  const { items } = useValues();

  return (
    <ul>
      {items.length === 0 && <li>No values available</li>}
      {items.map((key) => (
        <li key={key}>{key}</li>
      ))}
    </ul>
  );
}

Implementation Details


Interaction with Other Parts of the System


Summary

use-values.ts encapsulates logic to retrieve and memoize a list of keys describing form data associated with a selected tool on a selected node in a graph. It abstracts away direct store interactions and graph traversals, providing a clean and efficient API for React components.


Mermaid Diagram

flowchart TD
    A[useValues Hook]
    A --> B[useGraphStore]
    B --> C{State}
    C -->|clickedNodeId| D[Node ID]
    C -->|clickedToolId| E[Tool ID]
    C -->|findUpstreamNodeById| F[Function]

    A --> G[findUpstreamNodeById(clickedNodeId)]
    G --> H[agentNode]

    A --> I[getAgentNodeMCP(agentNode)]
    I --> J[mcpList]

    J --> K[mcpList.find(entry where entry.mcp_id === clickedToolId)]
    K --> L[formData.tools or {}]

    L --> M{isEmpty(formData)}
    M -->|true| N[Return { items: [] }]
    M -->|false| O[Return { items: Object.keys(formData) }]

Notes


End of Documentation for use-values.ts