api

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMinimumDocTokens = 10000

Variables

This section is empty.

Functions

func ValidateResourceURI

func ValidateResourceURI(uri, optionalType string) (*url.URL, error)

ValidateResourceURI validates a resource URI, and optionally checks that the provided type matches the host portion of the URI.

Types

type Client

type Client struct {
	HTTPClient *http.Client
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, logger *slog.Logger, httpClient *http.Client) (*Client, error)

New creates a new API client, with associated rate limiting and caching.

func (*Client) GetLibrary

func (c *Client) GetLibrary(ctx context.Context, resourceURI string) (library *Library, err error)

GetLibrary returns a library by its resource URI.

func (*Client) ListLibraries

func (c *Client) ListLibraries(ctx context.Context) (results []*Library, err error)

ListLibraries returns all known libraries.

func (*Client) ListTopLibraries

func (c *Client) ListTopLibraries(ctx context.Context, top int) (results []*Library, err error)

ListTopLibraries returns the top N libraries, sorted by TrustScore (if available), otherwise by Stars. Minimum number of results is 50, maximum is 1000.

func (*Client) SearchLibraries

func (c *Client) SearchLibraries(ctx context.Context, query string) (results []*SearchResult, err error)

SearchLibraries searches the Context7 API for libraries matching the given query. It returns a list of search results, sorted by relevance.

func (*Client) SearchLibraryDocsText

func (c *Client) SearchLibraryDocsText(
	ctx context.Context,
	resourceURI string,
	params *SearchLibraryDocsParams,
) (results string, err error)

SearchLibraryDocsText searches the Context7 API for library documentation text matching the given resource URI. Result is formatted as LLM-friendly text.

type Library

type Library struct {
	Settings *LibrarySettings `json:"settings"`
	Version  *LibraryVersion  `json:"version"`
}

func (*Library) GetResourceURI

func (l *Library) GetResourceURI() string

type LibrarySettings

type LibrarySettings struct {
	Branch         string   `json:"branch"`
	Description    string   `json:"description"`
	DocsRepoURL    string   `json:"docsRepoUrl"`
	ExcludeFolders []string `json:"excludeFolders"`
	Folders        []string `json:"folders"`
	Project        string   `json:"project"`
	Stars          int      `json:"stars"`
	Title          string   `json:"title"`
	TrustScore     float64  `json:"trustScore"`
}

type LibraryVersion

type LibraryVersion struct {
	LastUpdateDate time.Time `json:"lastUpdateDate"`
	TotalSnippets  int       `json:"totalSnippets"`
	TotalTokens    int       `json:"totalTokens"`
}

type Resource

type Resource interface {
	GetResourceURI() string
}

type SearchLibraryDocsParams

type SearchLibraryDocsParams struct {
	Topic   string   `json:"topic"`
	Tokens  int      `json:"tokens"`
	Folders []string `json:"folders"`
}

type SearchResp

type SearchResp struct {
	Results []*SearchResult `json:"results"`
}

type SearchResult

type SearchResult struct {
	ID            string    `json:"id"`
	Title         string    `json:"title"`
	Description   string    `json:"description"`
	LastUpdate    time.Time `json:"lastUpdateDate"`
	TotalTokens   int       `json:"totalTokens"`
	TotalSnippets int       `json:"totalSnippets"`
	Stars         int       `json:"stars"`
	TrustScore    float64   `json:"trustScore,omitempty"`
}

func (*SearchResult) GetResourceURI

func (s *SearchResult) GetResourceURI() string

Jump to

Keyboard shortcuts

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