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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@cognipeer/graph-builder

v0.1.0

Published

API-first text graph builder for JavaScript and TypeScript applications.

Downloads

80

Readme

Graph Builder

@cognipeer/graph-builder is an API-first TypeScript library for turning text sources into a queryable graph.

The package is built to be embedded inside other apps first. CLI and external adapters can be added later without changing the core API.

Install

npm install @cognipeer/graph-builder

Quick Start

import { graphBuilder } from "@cognipeer/graph-builder";

const result = await graphBuilder.fromTexts([
  {
    id: "docs/overview.md",
    path: "docs/overview.md",
    title: "Overview",
    text: "# Overview\n\nSee [Guide](guide.md)."
  },
  {
    id: "docs/guide.md",
    path: "guide.md",
    title: "Guide",
    text: "# Guide\n\nThis document explains the flow."
  }
]);

console.log(result.analysis.godNodes);
console.log(result.query.path("Overview", "Guide"));
console.log(result.artifacts.report);

Main API

  • graphBuilder(input, options?)
  • graphBuilder.build(input, options?)
  • graphBuilder.fromTexts(records, options?)
  • graphBuilder.fromProvider(provider, options?)
  • graphBuilder.fromChanges(previous, provider, cursor?, options?)
  • graphBuilder.updateGraph(previous, update, options?)
  • graphBuilder.loadGraph(jsonOrObject)
  • createGraphBuilder(config)

Provider Contract

Providers are the main extension surface.

import type { GraphBuilderProvider } from "@cognipeer/graph-builder";

const provider: GraphBuilderProvider<{ id: string }> = {
  name: "my-provider",
  async *list() {
    yield { id: "1" };
    yield { id: "2" };
  },
  async read(item) {
    return {
      id: item.id,
      title: `Record ${item.id}`,
      text: `# Record ${item.id}\n\nHello world.`
    };
  }
};

Providers can also expose changes(cursor) for cursor-based incremental updates:

const updated = await graphBuilder.fromChanges(previousResult, provider, "cursor-123");

console.log(updated.query.timeline());
console.log(updated.query.changes());

Local Path Shorthand

In Node runtimes, you can pass a path directly:

import { graphBuilder } from "@cognipeer/graph-builder";

const result = await graphBuilder("./docs");

This delegates to the local file provider from the ./node subpath.

Timeline and Change Tracking

Every graph now carries time-aware metadata:

  • graph.timeline records source-level added, updated, and removed events.
  • graph.snapshots records node, edge, source, and community counts over time.
  • graph.changes stores the latest diff when using updateGraph or fromChanges.
const updated = await graphBuilder.updateGraph(previous, {
  upsert: [{ id: "docs/guide.md", path: "docs/guide.md", text: "# Guide v2" }]
});

console.log(updated.query.timeline("docs/guide.md"));
console.log(updated.query.changes()?.summary);

Extraction Coverage

Graph Builder extracts Markdown structure, JS/TS script structure, imports, local calls, class/interface heritage, JSON schema fields, YAML schema fields, tags, links, and optional semantic LLM relationships.

Structured files such as .json, .yaml, and .yml produce schema_object, schema_array, and schema_field nodes so configuration and API-like documents can be queried alongside prose and code.

Artifacts and Node Output

Available artifact kinds:

["json", "report", "html", "wiki", "timeline", "manifest", "dot", "graphml", "cypher"]

In Node runtimes, the ./node subpath can write a full output directory:

import { buildGraphBuilderOutput } from "@cognipeer/graph-builder/node";

const { files } = await buildGraphBuilderOutput("./docs", {
  outDir: "graph-builder-out"
});

This writes graph.json, GRAPH_REPORT.md, graph.html, timeline.json, manifest.json, graph.dot, graph.graphml, graph.cypher, and wiki/*.md when those artifacts are requested.

Examples

  • npm run examples:from-texts
  • npm run examples:provider
  • npm run examples:path
  • npm run examples:llm
  • npm run examples:llm-mock

LLM Enrichment

Graph Builder can keep the deterministic extraction pipeline and then add an optional semantic LLM pass.

import { graphBuilder } from "@cognipeer/graph-builder";
import { createOpenAICompatibleEnricher } from "@cognipeer/graph-builder/adapters/openai-compatible";

const result = await graphBuilder.fromTexts(records, {
  semantic: {
    enricher: createOpenAICompatibleEnricher({
      apiKey: process.env.OPENAI_API_KEY!,
      model: "gpt-4.1-mini"
    })
  }
});

If you omit semantic, Graph Builder stays fully deterministic.

examples:llm expects a real OpenAI-compatible API key. examples:llm-mock uses a fake response so you can test the enrichment flow locally without network access.

Notes

  • Results are returned in memory by default.
  • File or cloud output should be an explicit caller decision.
  • The adapters/to-markdown subpath provides a wrapper for plugging in @cognipeer/to-markdown style converters.
  • The adapters/openai-compatible subpath provides an optional semantic enricher for OpenAI-compatible chat-completions APIs.
  • graph.html and other exports can be generated through the artifact API or the ./node output helpers.