docs

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 18 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 docs reads Costfluent's public documentation for the docs tools: it fetches the portal's llms-full.txt, every listed page in both languages, splits it into pages and their sections, and searches them in process. Nothing a caller asks leaves the process: the one request it makes is for that file, from the one origin a Source is built with.

Index

Constants

View Source
const (
	DefaultLimit = 5
	MaxLimit     = 10
)

Search bounds: results by default and at most, and the longest excerpt in characters.

View Source
const DefaultPageBytes = 24_000

DefaultPageBytes is how much of a page's markdown get_doc_page returns before it cuts the rest at a section and says so.

View Source
const MaxQueryTerms = 32

MaxQueryTerms is the most distinct words, stop words aside, a query may search for. Each term costs an index walk and a check against every body word of each excerpt, and the hosted server takes queries up to its 1 MiB body cap on a CPU every organization shares: unbounded, one query of 200,000 distinct words held a core for over a minute. 32 is far past any real question; raised much higher, one call's work grows back toward that, and lowered, a long question an assistant passes verbatim is refused.

View Source
const Origin = "https://docs.costfluent.com"

Origin is where the docs are read from: the public portal, never a URL a caller passes. The dev portal sits behind a sign-in, so dev servers read this one too.

Variables

View Source
var ErrNoWords = errors.New("the query holds no word to search for; ask in words, such as \"budget alerts terraform\"")

ErrNoWords is a query that holds no word to search for.

View Source
var ErrTooManyWords = fmt.Errorf("the query holds more than %d distinct words; ask in a few words, such as \"budget alerts terraform\"", MaxQueryTerms)

ErrTooManyWords is a query of more distinct words than MaxQueryTerms.

View Source
var Languages = []string{"en", "de"}

Languages the portal is written in; the first is the default.

View Source
var Shared = sync.OnceValue(func() *Source { return NewSource(Config{}) })

Shared is the process's Source for Origin, so every server a process builds, one per request in the hosted mode, reads one index.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Origin is the docs origin, https://host with no path; tests point it at their own server.
	Origin    string
	Transport http.RoundTripper
	Now       func() time.Time
	// UserAgent names the server that reads the docs.
	UserAgent string
}

Config builds a Source. Its zero value reads Origin with its own transport and the wall clock.

type Document

type Document struct {
	Title       string
	Description string
	// Path is the page's path on the docs origin, "/developers/terraform" or "/de/connect/azure".
	Path string
	// Language is "de" for a page under /de, else "en".
	Language string
	// Markdown is the page as llms-full.txt carries it, from its own top heading on.
	Markdown string
	Sections []Section
}

Document is one listed docs page.

func Parse

func Parse(text string) ([]Document, error)

Parse splits llms-full.txt into its pages. A file with no page that names its URL is malformed, whatever else it holds: an empty body, a login or error page in HTML, a changed framing.

func (*Document) Text

func (d *Document) Text(s Section) string

Text is the section's markdown, its heading line included.

type Hit

type Hit struct {
	Title   string `json:"title" jsonschema:"the page's title"`
	Heading string `json:"heading" jsonschema:"the section's heading"`
	URL     string `json:"url" jsonschema:"the section on the docs site; get_doc_page reads it"`
	Excerpt string `json:"excerpt" jsonschema:"the section's text around the first word that matched"`
}

Hit is one section search_docs returns.

type Index

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

Index is every page of one llms-full.txt, searchable per language.

func NewIndex

func NewIndex(origin string, docs []Document) *Index

NewIndex indexes docs, whose URLs are on origin.

func (*Index) Page

func (ix *Index) Page(ref string, maxBytes int) (*Page, error)

Page returns the page ref names, a URL on the index's origin or a path: ".md", a trailing slash and a query are ignored, and a fragment selects that section. It never fetches ref: the page is looked up in the index, so an unlisted page or another host is refused rather than read. The markdown is cut at the last whole section within maxBytes; a section longer than that alone is cut at a line.

func (*Index) Pages

func (ix *Index) Pages() int

Pages is how many pages the index holds.

func (*Index) Search

func (ix *Index) Search(query, language string, limit int) ([]Hit, error)

Search ranks language's sections for query and returns the best limit, at most two of a page.

type Page

type Page struct {
	Title       string `json:"title" jsonschema:"the page's title"`
	URL         string `json:"url" jsonschema:"the page, or the section asked for, on the docs site"`
	Description string `json:"description,omitempty" jsonschema:"the page's summary"`
	Markdown    string `json:"markdown" jsonschema:"the page's text, or the section's"`
	// Truncated says the markdown stops before the end; Sections names what follows.
	Truncated bool         `` /* 153-byte string literal not displayed */
	Sections  []SectionRef `json:"sections" jsonschema:"every section of the page, in order"`
}

Page is a docs page as get_doc_page returns it.

type Section

type Section struct {
	Level   int
	Heading string
	// Anchor is the heading's id on the rendered page, empty for the lede.
	Anchor string
	// Start and End are the section's byte offsets in the page's Markdown.
	Start, End int
}

Section is a part of a page: its lede before the first "## " heading (Level 1, no Anchor), or a "## " or "### " heading and what follows it up to the next of either.

type SectionRef

type SectionRef struct {
	Heading string `json:"heading"`
	URL     string `json:"url"`
}

SectionRef names a section of a page and where it is.

type Source

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

Source holds one process's index of the docs: fetched on the first call that needs it, fresh for an hour, then revalidated with the validators the origin sent. A failed refresh keeps the index it has and tries again a minute later; with no index yet the failure is the caller's error.

func NewSource

func NewSource(c Config) *Source

NewSource returns a Source for c.

func (*Source) Index

func (s *Source) Index(ctx context.Context) (*Index, error)

Index returns the docs index, fetching or revalidating it when it is due. Concurrent callers wait for one fetch.

func (*Source) Origin

func (s *Source) Origin() string

Origin is the origin s reads.

type UnavailableError

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

UnavailableError is a docs index that could not be read. It wraps no transport error, so a caller that reports a failure to reach the Public API by its type never takes it for one.

func (*UnavailableError) Error

func (e *UnavailableError) Error() string

Jump to

Keyboard shortcuts

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