npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

json-schema-to-diagram

v1.0.1

Published

Generate Mermaid diagrams from JSON schemas e.g., for function calling tools.

Downloads

280

Readme

json-schema-to-diagram

🧜‍♀️ Generate Mermaid diagrams from JSON schemas of e.g., function calling tools.

This is a simple tool that uses OpenAI's LLM to generate a Mermaid diagram from a JSON schema of tools. It can be used to visualize your agentic architecture through a diagram that shows all your tools and their parameters.

You can for example use this tool to generate a diagram and append it to your README.md or use it in your project's documentation.

Example Diagram

Here's how a Mermaid diagram generated from a JSON schema of OpenAI function calling tools looks like:

flowchart LR
    A["Data Tools"]
    A --> |"Retrieve real-time stock market data for a company"| B["**getStockData**"]
    B --> C["companySymbol"]
    A --> |"Upload user-specific data to a storage system"| D["**uploadData**"]
    D --> E["data<br>userId"]
    A --> |"Extract the transcript of a YouTube video"| F["**getYouTubeTranscript**"]
    F --> G["videoId"]
    A --> |"Perform web crawling to gather relevant information"| H["**crawlWebsite**"]
    H --> I["url"]

    J["Communication Tools"]
    J --> |"Send an automated email to the desired recipient"| K["**sendEmail**"]
    K --> L["recipient<br>subject<br>body"]
    J --> |"Take a screenshot of the current application window"| M["**takeScreenshot**"]
    M --> N["windowId"]

    O["Development Tools"]
    O --> |"Create a React component based on the given specifications"| P["**generateReactComponent**"]
    P --> Q["specifications"]
    O --> |"Develop comprehensive documentation for a codebase"| R["**generateCodeDocumentation**"]
    R --> S["codebaseId"]
    O --> |"Write a unit test for a specified function"| T["**generateUnitTest**"]
    T --> U["functionName"]
    O --> |"Create an integration test for a module"| V["**generateIntegrationTest**"]
    V --> W["moduleId"]

Install

npm install --save-dev json-schema-to-diagram

Usage

  1. Add a start and end marker to your README.md file.
## Function Calling Tools - Diagram

<!-- MERMAID_DIAGRAM_START -->
<!-- MERMAID_DIAGRAM_END -->
  1. Get the JSON schema of your function calling tools and generate the diagram by calling jsonSchemaToDiagram with the jsonSchema option.
import jsonSchemaToDiagram from "json-schema-to-diagram";

const TOOLS = {
  // JSON schema of your function calling tools
  // For example your OpenAI function calling tools
};

// Append the diagram to your README.md file
(async () => {
  try {
    await jsonSchemaToDiagram({
      filePath: "./README.md",
      jsonSchema: TOOLS,
    });
  } catch (error) {
    console.error("Error appending diagram:", error);
    process.exit(1);
  }
})();

API

generateDiagram(options)

options.filePath

Type: string

The path to the file to update (default: ./README.md).

options.startMarker

Type: string

The start marker of the diagram in the file (default: <!-- MERMAID_DIAGRAM_START -->).

options.endMarker

Type: string

The end marker of the diagram in the file (default: <!-- MERMAID_DIAGRAM_END -->).

options.systemPrompt

Type: string

The system prompt for the LLM (default: You are a helpful assistant that generates mermaid diagrams based on a JSON schema of tools.).

options.model

Type: Model

The LLM model to use (default: openai("gpt-4o")). This uses ai under the hood.

options.jsonSchema

Type: string

The JSON schema of the tools.