browserapi

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package browserapi exposes one initialized CodeGrapher repository through a versioned, authenticated, read-only HTTP API for browser consumers.

Index

Constants

View Source
const BasePath = "/codegrapher/v1"

Variables

View Source
var DefaultAllowedOrigins = []string{"https://codegrapher.com", "https://codegrapher.dev"}

Functions

func GenerateCredential

func GenerateCredential() (string, error)

GenerateCredential returns a cryptographically random browser bearer token.

Types

type Config

type Config struct {
	Token          string
	AllowedOrigins []string
	Limits         Limits
	ServerVersion  string
	Freshness      func() freshness.Status
}

type ErrorResponse

type ErrorResponse struct {
	Code      string `json:"code"`
	Message   string `json:"message"`
	RequestID string `json:"requestId"`
}

type FileResponse

type FileResponse struct {
	RepositoryID string    `json:"repositoryId"`
	Revision     string    `json:"revision"`
	Path         string    `json:"path"`
	Language     string    `json:"language"`
	Size         int64     `json:"size"`
	LineCount    int       `json:"lineCount"`
	ContentHash  string    `json:"contentHash"`
	Content      string    `json:"content"`
	Freshness    Freshness `json:"freshness"`
}

type Freshness

type Freshness struct {
	State              string     `json:"state"`
	IndexedAt          *time.Time `json:"indexedAt,omitempty"`
	LastSuccessfulSync *time.Time `json:"lastSuccessfulSync,omitempty"`
	LastError          string     `json:"lastError,omitempty"`
}

type GraphEdge

type GraphEdge struct {
	SourceID string `json:"sourceId"`
	TargetID string `json:"targetId"`
	Kind     string `json:"kind"`
	Line     int    `json:"line,omitempty"`
	Column   int    `json:"column,omitempty"`
}

type GraphResponse

type GraphResponse struct {
	RepositoryID string      `json:"repositoryId"`
	Revision     string      `json:"revision"`
	RootSymbolID string      `json:"rootSymbolId"`
	Direction    string      `json:"direction"`
	Depth        int         `json:"depth"`
	MaxNodes     int         `json:"maxNodes"`
	MaxEdges     int         `json:"maxEdges"`
	Nodes        []Symbol    `json:"nodes"`
	Edges        []GraphEdge `json:"edges"`
	Truncated    bool        `json:"truncated"`
	Freshness    Freshness   `json:"freshness"`
}

type Limits

type Limits struct {
	MaxTreeEntries   int `json:"maxTreeEntries"`
	MaxFileBytes     int `json:"maxFileBytes"`
	MaxSearchResults int `json:"maxSearchResults"`
	MaxGraphDepth    int `json:"maxGraphDepth"`
	MaxGraphNodes    int `json:"maxGraphNodes"`
	MaxGraphEdges    int `json:"maxGraphEdges"`
}

func DefaultLimits

func DefaultLimits() Limits

type Repository

type Repository struct {
	ID          string    `json:"id"`
	Label       string    `json:"label"`
	Remote      string    `json:"remote,omitempty"`
	Branch      string    `json:"branch,omitempty"`
	HeadCommit  string    `json:"headCommit,omitempty"`
	Revision    string    `json:"revision"`
	Freshness   Freshness `json:"freshness"`
	FileCount   int       `json:"fileCount"`
	SymbolCount int       `json:"symbolCount"`
	EdgeCount   int       `json:"edgeCount"`
}

type SearchResponse

type SearchResponse struct {
	RepositoryID string         `json:"repositoryId"`
	Revision     string         `json:"revision"`
	Query        string         `json:"query"`
	Results      []SearchResult `json:"results"`
	Limit        int            `json:"limit"`
	Truncated    bool           `json:"truncated"`
	Freshness    Freshness      `json:"freshness"`
}

type SearchResult

type SearchResult struct {
	Score  float64 `json:"score"`
	Symbol Symbol  `json:"symbol"`
}

type Server

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

func New

func New(idx *indexer.Indexer, config Config) (*Server, error)

func (*Server) Handler

func (s *Server) Handler() http.Handler

func (*Server) RepositoryID

func (s *Server) RepositoryID() string

func (*Server) Revision

func (s *Server) Revision() (string, error)

func (*Server) Serve

func (s *Server) Serve(ctx context.Context, listener net.Listener) error

type SourceRange

type SourceRange struct {
	StartLine   int `json:"startLine"`
	EndLine     int `json:"endLine"`
	StartColumn int `json:"startColumn"`
	EndColumn   int `json:"endColumn"`
}

type StatusResponse

type StatusResponse struct {
	APIVersion      string    `json:"apiVersion"`
	ServerVersion   string    `json:"serverVersion"`
	Capabilities    []string  `json:"capabilities"`
	RepositoryCount int       `json:"repositoryCount"`
	Freshness       Freshness `json:"freshness"`
	Limits          Limits    `json:"limits"`
}

type Symbol

type Symbol struct {
	ID            string      `json:"id"`
	Kind          string      `json:"kind"`
	Name          string      `json:"name"`
	QualifiedName string      `json:"qualifiedName"`
	FilePath      string      `json:"filePath"`
	Language      string      `json:"language"`
	Range         SourceRange `json:"range"`
	Signature     string      `json:"signature,omitempty"`
	Docstring     string      `json:"docstring,omitempty"`
	Visibility    *string     `json:"visibility,omitempty"`
	Exported      bool        `json:"exported"`
}

type SymbolResponse

type SymbolResponse struct {
	RepositoryID string    `json:"repositoryId"`
	Revision     string    `json:"revision"`
	Symbol       Symbol    `json:"symbol"`
	Freshness    Freshness `json:"freshness"`
}

type TreeEntry

type TreeEntry struct {
	Name        string `json:"name"`
	Path        string `json:"path"`
	Kind        string `json:"kind"`
	Size        int64  `json:"size,omitempty"`
	Language    string `json:"language,omitempty"`
	ContentHash string `json:"contentHash,omitempty"`
}

type TreeResponse

type TreeResponse struct {
	RepositoryID string      `json:"repositoryId"`
	Revision     string      `json:"revision"`
	Path         string      `json:"path"`
	Entries      []TreeEntry `json:"entries"`
	Limit        int         `json:"limit"`
	Truncated    bool        `json:"truncated"`
	Freshness    Freshness   `json:"freshness"`
}

Jump to

Keyboard shortcuts

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