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 ¶
const ( DefaultLimit = 5 MaxLimit = 10 )
Search bounds: results by default and at most, and the longest excerpt in characters.
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.
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.
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 ¶
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.
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.
var Languages = []string{"en", "de"}
Languages the portal is written in; the first is the default.
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.
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 (*Index) Page ¶
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.
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 ¶
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.
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