wm

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package wm is the application layer shared by the CLI and the MCP server, so both expose identical semantics, safety checks and output shapes.

Index

Constants

View Source
const (
	StateIndexed      = "indexed"
	StateNotIndexed   = "not_indexed"
	StateError        = "error"
	StateRedirect     = "redirect"
	StateNotFound     = "not_found"
	StateNoData       = "no_data"
	StateForbidden    = "forbidden"
	StateFailed       = "failed"
	StateNotAttempted = "not_attempted"
)

Page states reported by document lookups.

View Source
const (
	ReindexSubmitted    = "submitted"
	ReindexFailed       = "failed"
	ReindexNotAttempted = "not_attempted"
	ReindexPlanned      = "planned"
)

Reindex item statuses.

View Source
const (
	SeverityOK       = "ok"
	SeverityInfo     = "info"
	SeverityWarning  = "warning"
	SeverityCritical = "critical"
)

Finding severities, ordered from least to most serious.

View Source
const DefaultURLLimit = 100

DefaultURLLimit caps URLs per category unless the caller asks otherwise. The API returns up to 1,000 per category, too much for an agent's context window.

Variables

View Source
var UntrustedDocumentFields = []string{"title", "meta", "openGraphData", "responseHeaders"}

UntrustedDocumentFields lists response fields copied from third-party pages. They may contain text written to manipulate an agent reading them.

Functions

func CheckBulk

func CheckBulk(n int, confirmed, dryRun bool) error

CheckBulk requires explicit confirmation for writes touching several URLs. szwm never prompts, because a prompt would hang a non-interactive agent.

func CleanURLs

func CleanURLs(raw []string) ([]string, error)

CleanURLs validates everything up front and removes duplicates. Failing before the first call keeps a typo from burning half of a batch's quota.

func ParseLast

func ParseLast(v string, now time.Time) (string, error)

ParseLast converts a relative window such as 30d or 8w into a start date.

func ReadOnlyError

func ReadOnlyError() *apperr.Error

ReadOnlyError is returned when a write is blocked.

func SeverityRank

func SeverityRank(s string) int

SeverityRank orders severities; unknown values rank below everything.

func SiteFromWebserver added in v0.2.0

func SiteFromWebserver(v string) string

SiteFromWebserver converts the API's reversed form, such as com.example.!443, into a host name such as example.com.

func SiteOf added in v0.2.0

func SiteOf(ctx context.Context, c *api.Client) (string, error)

SiteOf is Site for a bare client, used to check a key before it is saved.

func ValidateURL

func ValidateURL(raw string) (string, error)

ValidateURL checks that raw is an absolute http(s) page URL.

Types

type BatchSummary

type BatchSummary struct {
	Total  int            `json:"total"`
	OK     int            `json:"ok"`
	Failed int            `json:"failed"`
	States map[string]int `json:"states"`
}

BatchSummary aggregates a lookup batch.

type DocumentBatch

type DocumentBatch struct {
	Summary BatchSummary   `json:"summary"`
	Items   []DocumentItem `json:"items"`
}

DocumentBatch is the data of a multi-URL lookup.

type DocumentItem

type DocumentItem struct {
	URL          string        `json:"url"`
	OK           bool          `json:"ok"`
	State        string        `json:"state"`
	DownloadedAt string        `json:"downloaded_at,omitempty"`
	IndexedAt    string        `json:"indexed_at,omitempty"`
	Document     any           `json:"document,omitempty"`
	Error        *apperr.Error `json:"error,omitempty"`
}

DocumentItem is one page's lookup result.

type Finding

type Finding struct {
	Code     string  `json:"code"`
	Severity string  `json:"severity"`
	Message  string  `json:"message"`
	Metric   string  `json:"metric,omitempty"`
	Value    float64 `json:"value,omitempty"`
}

Finding is one deterministic observation with a stable code.

type MetricChange

type MetricChange struct {
	From    int64    `json:"from"`
	To      int64    `json:"to"`
	Delta   int64    `json:"delta"`
	Percent *float64 `json:"percent,omitempty"`
}

MetricChange compares a metric between two days.

type ReindexData

type ReindexData struct {
	DryRun           bool            `json:"dry_run"`
	Summary          ReindexSummary  `json:"summary"`
	Items            []ReindexItem   `json:"items"`
	Quota            ratelimit.Quota `json:"quota"`
	EstimatedSeconds int             `json:"estimated_seconds"`
}

ReindexData is the data of a reindex run or plan.

type ReindexItem

type ReindexItem struct {
	URL    string        `json:"url"`
	Status string        `json:"status"`
	Reason string        `json:"reason,omitempty"`
	Error  *apperr.Error `json:"error,omitempty"`
}

ReindexItem is the result for one URL.

type ReindexOptions

type ReindexOptions struct {
	URLs        []string
	DryRun      bool
	IgnoreQuota bool
	OnItem      func(ReindexItem)
}

ReindexOptions control a run.

type ReindexSummary

type ReindexSummary struct {
	Total        int `json:"total"`
	Submitted    int `json:"submitted"`
	Failed       int `json:"failed"`
	NotAttempted int `json:"not_attempted"`
	Planned      int `json:"planned,omitempty"`
}

ReindexSummary aggregates a run.

type Report

type Report struct {
	Severity    string             `json:"severity"`
	Site        string             `json:"site,omitempty"`
	GeneratedAt string             `json:"generated_at"`
	DataRelease string             `json:"data_release,omitempty"`
	Totals      map[string]int64   `json:"totals"`
	Ratios      map[string]float64 `json:"ratios"`
	Trend       *Trend             `json:"trend,omitempty"`
	Findings    []Finding          `json:"findings"`
	ErrorSample []any              `json:"error_sample,omitempty"`
}

Report is the site health summary.

func Evaluate

func Evaluate(web map[string]any, release string, windowDays int, now time.Time) Report

Evaluate turns a decoded /web response into a Report.

type Result

type Result struct {
	Data      any
	Raw       []byte
	Hints     []string
	Warnings  []string
	Untrusted []string
	Truncated bool
	// Err marks a failure that still produced data, such as a partial batch.
	Err *apperr.Error
}

Result is the outcome of an operation.

type Service

type Service struct {
	API      *api.Client
	Ledger   *ratelimit.Ledger
	ReadOnly bool
	Now      func() time.Time
}

Service executes Webmaster operations.

func (*Service) CheckDocuments

func (s *Service) CheckDocuments(ctx context.Context, urls []string, brief bool, onItem func(DocumentItem)) (Result, error)

CheckDocuments looks up many URLs sequentially, pacing itself through the limiter. A page Seznam does not know is a valid answer, not a failure; only transport, auth and access problems fail an item. onItem runs as each result arrives so a killed process still leaves partial output.

func (*Service) DatabaseInfo

func (s *Service) DatabaseInfo(ctx context.Context) (Result, error)

DatabaseInfo returns the release time of the data behind the API.

func (*Service) Document

func (s *Service) Document(ctx context.Context, rawURL string, brief bool) (Result, error)

Document wraps GET /web/document for one URL.

func (*Service) Documents

func (s *Service) Documents(ctx context.Context, o ViewOptions) (Result, error)

Documents wraps GET /web/documents.

func (*Service) History

func (s *Service) History(ctx context.Context, from, to string) (Result, error)

History wraps GET /web/documents-history. Dates are YYYY-MM-DD or empty.

func (*Service) Overview

func (s *Service) Overview(ctx context.Context, o ViewOptions) (Result, error)

Overview wraps GET /web.

func (*Service) Reindex

func (s *Service) Reindex(ctx context.Context, o ReindexOptions) (Result, error)

Reindex wraps POST /web/document/reindex. URLs must already be cleaned.

The URL list is cut to the estimated remaining quota before the first call, and each success is recorded immediately, so an interrupted batch leaves the ledger correct. Anything left over is reported as not_attempted with a reason, which makes resuming the next day a mechanical step.

func (*Service) Report

func (s *Service) Report(ctx context.Context, windowDays int) (Result, error)

Report fetches /web and /database-info and evaluates the site. It uses two requests, and the rules are pure so they can be tested without a network.

func (*Service) Site added in v0.2.0

func (s *Service) Site(ctx context.Context) (string, error)

Site returns the host name of the site the key belongs to. It returns "" when the key is accepted but the site has no data yet.

type Trend

type Trend struct {
	From    string                  `json:"from"`
	To      string                  `json:"to"`
	Metrics map[string]MetricChange `json:"metrics"`
}

Trend compares the newest history row with one about window days older.

type ViewOptions

type ViewOptions struct {
	CountsOnly bool
	Limit      int // URLs per category; 0 means all
	Categories []string
	HistoryDay int // keep only the newest N history rows; 0 means all
}

ViewOptions shape URL-bearing responses.

Jump to

Keyboard shortcuts

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