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
- func AuthLoginURL(cliPort int) string
- func DeleteToken() error
- func LoadLastSync() time.Time
- func LoadToken() string
- func Login() error
- func SaveLastSync(t time.Time) error
- func SaveToken(token string) error
- func SlugFromRef(ref string) string
- func SyncPath() string
- func TokenPath() string
- type APIError
- type Client
- func (c *Client) CreateRecipe(markdown string) (*RecipeEntry, error)
- func (c *Client) DeleteRecipe(id string) error
- func (c *Client) GetRecipe(ref string) (*RecipeEntry, error)
- func (c *Client) GetRecipeRaw(ref string) (string, error)
- func (c *Client) IsLoggedIn() bool
- func (c *Client) ListRecipes(page, perPage int, author, query string) (*RecipeList, error)
- func (c *Client) Logout() error
- func (c *Client) Me() (*User, error)
- func (c *Client) SetBaseURL(u string)
- func (c *Client) UpdateRecipe(id, markdown string) (*RecipeEntry, error)
- func (c *Client) UploadPreferences(payload PreferenceUpload) (int, error)
- type PreferenceUpload
- type RecipeEntry
- type RecipeList
- type RunUpload
- type SessionUpload
- type User
Constants ¶
const ( BaseURL = "https://errata.app" APIPrefix = "/api/v1" )
Variables ¶
This section is empty.
Functions ¶
func AuthLoginURL ¶
AuthLoginURL returns the URL to open in a browser to start the OAuth flow.
func LoadLastSync ¶
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 ¶
SaveLastSync writes the sync timestamp to disk.
func SlugFromRef ¶
SlugFromRef extracts the slug (last path component) from an author/slug ref.
Types ¶
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 ¶
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 ¶
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 ¶
GetRecipeRaw fetches the raw markdown content of a recipe by ID or author/slug ref.
func (*Client) IsLoggedIn ¶
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) SetBaseURL ¶
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.