Documentation
¶
Overview ¶
Package maskrec keeps the record of what masking swapped for placeholders before a request went to a vendor, for Settings → Privacy to show: which kinds, found by which finder, going to whom.
A value itself is never written down. A record holds each value's placeholder, its kind, its finder, and a hint (its first character or a key's prefix, and its length). The value behind a placeholder is known only to the masker's memory while magpie runs (gwmw.Teller.Value), and the text around it as the vendor saw it is kept in memory only, for the latest records.
A day is a file of its own, one request a line, under ~/.config/magpie/masking, kept keepDays days and keepBytes in all.
Index ¶
Constants ¶
const SentMax = sentMax
SentMax is the longest request a record keeps as sent; a longer one is kept as nothing, so a caller need not copy it.
Variables ¶
Dir is where the days are kept.
Functions ¶
func Clear ¶ added in v0.1.1593
func Clear() error
Clear deletes every record kept: each day's file, and what memory has of them (their snips, the requests' text). A day goes whole, never rewritten, so nothing is left half-cleared for a reader; a request still going is written to a new day's file once it is done. A day that can't be removed stays, and is named in the error. What a placeholder stood for is the masker's, in memory alone, and stays there for the answers still to come.
Types ¶
type Day ¶
type Day struct {
Day string `json:"day"`
Requests int `json:"requests"`
N int `json:"n"` // values swapped, each place counted
Distinct int `json:"distinct"` // different values
}
Day is one day's count.
type Filter ¶
Filter narrows List: by kind (one, or several split by commas), by finder, by agent or provider, "" is any; Blocked keeps only the requests masking held back.
type Record ¶
type Record struct {
Key int64 `json:"key"` // unique, later records larger
Time time.Time `json:"t"`
Route int64 `json:"route,omitempty"` // its route in the trace, where it has one
What string `json:"what"` // chat, search, image, video, embeddings, audio, count
Agent string `json:"agent,omitempty"`
Session string `json:"session,omitempty"`
Provider string `json:"provider,omitempty"`
Model string `json:"model,omitempty"`
N int `json:"n"` // values swapped, each place counted
Values []Value `json:"values,omitempty"`
// Blocked: the request was held back, sent to no one, for a value
// of a kind the user set to block
Blocked bool `json:"blocked,omitempty"`
// Snips: by placeholder, the text around its first place as the
// vendor saw it; in memory only
Snips map[string]string `json:"snips,omitempty"`
// Took is how long masking the request took, in microseconds
Took int64 `json:"took,omitempty"`
// Back: by placeholder, the places the answer had it put back; in
// memory only, told once the answer is done (Restored)
Back map[string]int `json:"back,omitempty"`
// Sent is the request as the vendor got it; in memory only, for the
// latest keepSent, and never in a list (SentOf)
Sent string `json:"-"`
}
Record is one request's masking.
func Add ¶
Add records r, its Values made from hits as they came: one for each placeholder, counted. It returns r as recorded. Errors are swallowed: keeping the record must never break a request.
func Hold ¶ added in v0.1.1574
Hold is Add for a request whose provider isn't known yet: a group's member that fails passes it to the next, so the one it is planned for may never get it (Max You and Linka on Discord: the records named the group's first member, which no request had reached). r is in memory at once, for its route's badge and the answer's Restored, and goes on disk, where the summary counts it, once done is told the provider and model that had it last ("" keeps r's). Only done's first call counts.
type Seen ¶
type Seen struct {
Placeholder string `json:"p"`
Kind string `json:"kind"`
By string `json:"by"`
Head string `json:"head,omitempty"`
Len int `json:"len"`
N int `json:"n"`
Requests int `json:"requests"`
Last time.Time `json:"last"`
}
Seen is one different value, as the record has it.
type Summary ¶
type Summary struct {
Days []Day `json:"days"` // oldest first, each day of them
Requests int `json:"requests"`
N int `json:"n"`
Distinct int `json:"distinct"`
Warned int `json:"warned,omitempty"` // places a value went as written, the user told
Blocked int `json:"blocked,omitempty"` // requests held back
Hours [24]int `json:"hours"` // places, by the hour of the day
Kinds []Count `json:"kinds"`
By map[string]int `json:"by"` // different values by the finder that found each
Agents []Count `json:"agents"`
Providers []Count `json:"providers"`
Values []Seen `json:"values"` // the most masked first, at most topValues
Since string `json:"since,omitempty"`
}
Summary is what masking did over some days.
type Value ¶
type Value struct {
Placeholder string `json:"p"`
Kind string `json:"k"`
By string `json:"b"` // the finder: rule, yours, word, model or known
Head string `json:"h,omitempty"` // its first character, or a key's prefix
Len int `json:"l"` // its length in characters
N int `json:"n"` // the places the request had it
// Action: "" masked, "warn" sent as written (the user asked to be
// told only), "block" masked and the request held back
Action string `json:"a,omitempty"`
}
Value is one value a request had masked, as often as it had it.