supermodel

package
v0.6.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package supermodel is the public Go SDK for the Supermodel API.

Other Go programs can import this package to embed Supermodel graph analysis without shelling out to the CLI binary.

Usage:

import "github.com/supermodeltools/cli/pkg/supermodel"

client := supermodel.NewClient("your-api-key")
graph, err := client.Analyze(ctx, "/path/to/repo")
if err != nil {
    log.Fatal(err)
}
fmt.Println("files:", len(graph.NodesByLabel("File")))

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	StatusCode int    `json:"-"`
	Code       string `json:"code"`
	Message    string `json:"message"`
}

APIError is returned for non-2xx responses.

func (*APIError) Error

func (e *APIError) Error() string

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client calls the Supermodel API.

func NewClient

func NewClient(apiKey string, opts ...Option) *Client

NewClient returns a Client authenticated with apiKey.

func (*Client) Analyze

func (c *Client) Analyze(ctx context.Context, repoPath string) (*Graph, error)

Analyze archives repoPath and runs the full Supermodel analysis pipeline.

func (*Client) AnalyzeZip

func (c *Client) AnalyzeZip(ctx context.Context, zipPath, idempotencyKey string) (*Graph, error)

AnalyzeZip uploads a pre-built ZIP to the Supermodel API and polls until the async job completes, returning the resulting Graph. idempotencyKey must be unique per logical request.

type Graph

type Graph struct {
	Nodes         []Node         `json:"nodes"`
	Edges         []Relationship `json:"edges"`
	Relationships []Relationship `json:"relationships"`
	Metadata      map[string]any `json:"metadata,omitempty"`
}

Graph is the result of a Supermodel analysis.

func (*Graph) NodesByLabel

func (g *Graph) NodesByLabel(label string) []Node

NodesByLabel returns all nodes that carry label.

func (*Graph) Rels

func (g *Graph) Rels() []Relationship

Rels returns all relationships regardless of which JSON field they came from.

func (*Graph) RepoID

func (g *Graph) RepoID() string

RepoID returns the repository ID from graph metadata.

type Node

type Node struct {
	ID         string         `json:"id"`
	Labels     []string       `json:"labels"`
	Properties map[string]any `json:"properties"`
}

Node is a node in the Supermodel graph.

func (Node) HasLabel

func (n Node) HasLabel(label string) bool

HasLabel reports whether the node carries label.

func (Node) Prop

func (n Node) Prop(keys ...string) string

Prop returns the first non-empty string property for the given keys.

type Option

type Option func(*Client)

Option configures a Client.

func WithBaseURL

func WithBaseURL(u string) Option

WithBaseURL overrides the default API base URL.

func WithHTTPClient

func WithHTTPClient(h *http.Client) Option

WithHTTPClient substitutes a custom HTTP client (useful for testing).

type Relationship

type Relationship struct {
	ID        string `json:"id"`
	Type      string `json:"type"`
	StartNode string `json:"startNode"`
	EndNode   string `json:"endNode"`
}

Relationship is a directed edge between two nodes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL