api

package
v0.1.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package api provides the HTTP client and base request primitives for the Supermodel API. It handles authentication headers, idempotency keys, error parsing, and response decoding.

This is a shared kernel package. It must contain no business logic. Slice packages under internal/ may import it freely.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is an authenticated Supermodel API client.

func New

func New(cfg *config.Config) *Client

New returns a Client configured from cfg.

func (*Client) Analyze

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

Analyze uploads a repository ZIP and runs the full analysis pipeline, returning the DisplayGraphResponse.

func (*Client) DisplayGraph

func (c *Client) DisplayGraph(ctx context.Context, repoID, idempotencyKey string) (*Graph, error)

DisplayGraph fetches the composed display graph for an already-analyzed repo.

type Error

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

Error represents a non-2xx response from the API.

func (*Error) Error

func (e *Error) Error() string

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 unified response type for /v1/supermodel and /v1/repos/{id}/graph/display. The API serialises relationships as either "edges" or "relationships" depending on the endpoint; Rels() unifies both.

func (*Graph) NodeByID

func (g *Graph) NodeByID(id string) (Node, bool)

NodeByID returns the node with the given ID, if present.

func (*Graph) NodesByLabel

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

NodesByLabel returns all nodes that carry the given 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 repoId from graph metadata, or "".

type Node

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

Node represents a graph node returned by the Supermodel API.

func (Node) HasLabel

func (n Node) HasLabel(label string) bool

HasLabel reports whether the node carries the given label.

func (Node) Prop

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

Prop returns the first non-empty string value from the node's properties.

type Relationship

type Relationship struct {
	ID         string         `json:"id"`
	Type       string         `json:"type"`
	StartNode  string         `json:"startNode"`
	EndNode    string         `json:"endNode"`
	Properties map[string]any `json:"properties,omitempty"`
}

Relationship is a directed edge between two graph nodes.

Jump to

Keyboard shortcuts

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