api

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package api provides an HTTP client for the errata.app backend API. It handles authentication (GitHub OAuth token), recipe CRUD, and user info.

Index

Constants

View Source
const (
	BaseURL   = "https://errata.app"
	APIPrefix = "/api/v1"
)

Variables

This section is empty.

Functions

func AuthLoginURL

func AuthLoginURL(cliPort int) string

AuthLoginURL returns the URL to open in a browser to start the OAuth flow.

func DeleteToken

func DeleteToken() error

DeleteToken removes the stored auth token.

func LoadLastSync

func LoadLastSync() time.Time

LoadLastSync reads the last-sync timestamp from disk. Returns zero time if the file does not exist or is unreadable.

func LoadToken

func LoadToken() string

LoadToken reads the stored auth token from disk. Returns empty string if not found or unreadable.

func Login

func Login() error

Login runs the interactive OAuth login flow: 1. Starts a local HTTP server on an available port 2. Opens the browser to the errata.app OAuth page 3. Waits for the callback with the token 4. Saves the token to disk

func SaveLastSync

func SaveLastSync(t time.Time) error

SaveLastSync writes the sync timestamp to disk.

func SaveToken

func SaveToken(token string) error

SaveToken writes the auth token to disk.

func SlugFromRef

func SlugFromRef(ref string) string

SlugFromRef extracts the slug (last path component) from an author/slug ref.

func SyncPath

func SyncPath() string

SyncPath returns the path to the last-sync watermark file.

func TokenPath

func TokenPath() string

TokenPath returns the path to the stored GitHub auth token.

Types

type APIError

type APIError struct {
	StatusCode int
	Message    string
}

APIError is returned on non-2xx responses.

func (*APIError) Error

func (e *APIError) Error() string

type Client

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

Client is the errata.app API client.

func NewClient

func NewClient() *Client

NewClient creates a client using the locally stored token.

func NewClientWithToken

func NewClientWithToken(token string) *Client

NewClientWithToken creates a client with an explicit token.

func (*Client) CreateRecipe

func (c *Client) CreateRecipe(markdown string) (*RecipeEntry, error)

CreateRecipe uploads raw markdown content as a new recipe.

func (*Client) DeleteRecipe

func (c *Client) DeleteRecipe(id string) error

DeleteRecipe deletes a recipe by ID.

func (*Client) GetRecipe

func (c *Client) GetRecipe(ref string) (*RecipeEntry, error)

GetRecipe fetches a single recipe by ID or author/slug ref.

func (*Client) GetRecipeRaw

func (c *Client) GetRecipeRaw(ref string) (string, error)

GetRecipeRaw fetches the raw markdown content of a recipe by ID or author/slug ref.

func (*Client) IsLoggedIn

func (c *Client) IsLoggedIn() bool

IsLoggedIn returns true if a token is available.

func (*Client) ListRecipes

func (c *Client) ListRecipes(page, perPage int, author, query string) (*RecipeList, error)

ListRecipes fetches paginated recipes with optional filters.

func (*Client) Logout

func (c *Client) Logout() error

Logout invalidates the current token on the server and deletes it locally.

func (*Client) Me

func (c *Client) Me() (*User, error)

Me returns the authenticated user.

func (*Client) SetBaseURL

func (c *Client) SetBaseURL(u string)

SetBaseURL overrides the API base URL (for testing).

func (*Client) UpdateRecipe

func (c *Client) UpdateRecipe(id, markdown string) (*RecipeEntry, error)

UpdateRecipe replaces a recipe's content by ID.

func (*Client) UploadPreferences

func (c *Client) UploadPreferences(payload PreferenceUpload) (int, error)

UploadPreferences uploads redacted preference data. Returns the number of runs the server accepted.

type PreferenceUpload

type PreferenceUpload struct {
	Sessions []SessionUpload `json:"sessions"`
}

PreferenceUpload is the bulk upload request body for POST /preferences.

type RecipeEntry

type RecipeEntry struct {
	ID             string         `json:"id"`
	Name           string         `json:"name"`
	Slug           string         `json:"slug"`
	AuthorID       string         `json:"author_id"`
	Content        string         `json:"content"`
	ContentHash    string         `json:"content_hash"`
	Metadata       map[string]any `json:"metadata"`
	ParserVersion  int            `json:"parser_version"`
	CreatedAt      string         `json:"created_at"`
	UpdatedAt      string         `json:"updated_at"`
	AuthorUsername string         `json:"author_username"`
}

RecipeEntry represents a recipe from the backend API.

func (*RecipeEntry) Ref

func (r *RecipeEntry) Ref() string

Ref returns the author/slug reference string for this recipe.

type RecipeList

type RecipeList struct {
	Recipes []RecipeEntry `json:"recipes"`
	Total   int           `json:"total"`
	Page    int           `json:"page"`
	PerPage int           `json:"per_page"`
}

RecipeList is the paginated response from GET /recipes.

type RunUpload

type RunUpload struct {
	Timestamp           time.Time                 `json:"timestamp"`
	PromptHash          string                    `json:"prompt_hash"`
	Models              []string                  `json:"models"`
	Selected            string                    `json:"selected,omitempty"`
	Rating              string                    `json:"rating,omitempty"`
	Type                string                    `json:"type,omitempty"`
	LatenciesMS         map[string]int64          `json:"latencies_ms,omitempty"`
	CostsUSD            map[string]float64        `json:"costs_usd,omitempty"`
	InputTokens         map[string]int64          `json:"input_tokens,omitempty"`
	OutputTokens        map[string]int64          `json:"output_tokens,omitempty"`
	ToolCalls           map[string]map[string]int `json:"tool_calls,omitempty"`
	ProposedWritesCount map[string]int            `json:"proposed_writes_count,omitempty"`
	ConfigHash          string                    `json:"config_hash,omitempty"`
}

RunUpload is a redacted run summary for upload. Sensitive fields (PromptPreview, AppliedFiles, Note) are excluded.

type SessionUpload

type SessionUpload struct {
	ID           string      `json:"id"`
	CreatedAt    time.Time   `json:"created_at"`
	LastActiveAt time.Time   `json:"last_active_at"`
	Models       []string    `json:"models,omitempty"`
	PromptCount  int         `json:"prompt_count"`
	ConfigHash   string      `json:"config_hash,omitempty"`
	RecipeName   string      `json:"recipe_name,omitempty"`
	Runs         []RunUpload `json:"runs"`
}

SessionUpload is a redacted session metadata record for upload. Sensitive fields (FirstPrompt, LastPrompt) are excluded.

type User

type User struct {
	ID          string `json:"id"`
	Username    string `json:"username"`
	DisplayName string `json:"display_name"`
	AvatarURL   string `json:"avatar_url"`
}

User represents the authenticated user from GET /auth/me.

Jump to

Keyboard shortcuts

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