Documentation
¶
Overview ¶
Package libshare shares the Library's rules and sets of instructions on usemagpie.ai (site/libshares.js): a link anyone can open, and the Rules and Instructions markets, the ones shared there publicly, which the Library's Rules and Instructions tabs open.
What goes out is the rule's name, the files it is for and its text, or the set's name and text: never the agents it is given to, a file of the user's own it is kept in, or anything else of the library. Text holding what looks like a key or token is refused (redact.Scrub). The user shares, never an agent, and nothing is sent by itself but the ids of the shared items imported here (Report, with the usage stats).
shared-library.json, in magpie's folder and readable by the user alone, keeps the link of each item the user shared and the token that updates it or takes it down (usemagpie.ai keeps the token only hashed), and the link each imported item came from.
Index ¶
- Constants
- Variables
- func Forget(kind string, names []string) error
- func Imported(key string, page Page) error
- func Key(kind, name string) string
- func Like(ctx context.Context, install, id string, on bool) (int, error)
- func LinkID(text string) (kind, id string)
- func Renamed(kind, old, name string) error
- func Report(ctx context.Context, install string) error
- func Unpublish(ctx context.Context, kind, name string) error
- func ValidID(id string) bool
- type Card
- type From
- type InstrItem
- type Item
- type Market
- type Meta
- type Mine
- type Page
- type Retired
- type RuleItem
- type State
Constants ¶
const ( Rules = "rules" Instructions = "instructions" )
The kinds shared, as usemagpie.ai's paths name them.
Variables ¶
var ErrGone = errors.New("this was taken down on usemagpie.ai")
ErrGone is a shared item usemagpie.ai doesn't have: taken down by its author, or on a report.
var ErrOff = errors.New("sharing is off here")
ErrOff is sharing with no site to share on (a test that named none).
var ErrSecret = errors.New("the text holds what looks like a key or token: take it out before sharing")
ErrSecret is text that holds what looks like a key or token.
var Site = func() string { if s := os.Getenv("MAGPIE_SHARE_SITE"); s != "" { return strings.TrimRight(s, "/") } if testing.Testing() { return "" } return "https://usemagpie.ai" }
Site is where they are shared. MAGPIE_SHARE_SITE moves it, as it moves shared groups and artifacts, and a test names its own: a test never reaches the real site.
Functions ¶
func Forget ¶
Forget is what removing rules or sets leaves behind: where they came from is dropped, and the links they were shared at are set aside (Retired), so one made later under the same name shares at a link of its own. Nothing is written when none is recorded.
func Like ¶
Like likes shared item id, or unlikes it, from install (this computer's random id, stats.InstallID): its likes after.
func LinkID ¶
LinkID is the kind and id of the shared item in text: a link to its page (https://usemagpie.ai/r/<id> for a rule, /i/<id> for instructions) or a magpie://rule?id=<id> or magpie://instructions?id= link; "" for anything else.
func Renamed ¶
Renamed carries what is recorded of a rule or set from its old name to its new one: the link it is shared at, and where it came from.
func Report ¶
Report tells usemagpie.ai the shared items imported here that are still here, from install, for the markets' counts: with the usage stats, and never when the user turned those off.
Types ¶
type Card ¶
type Card struct {
ID string `json:"id"`
URL string `json:"url"`
Title string `json:"title"`
Description string `json:"description,omitempty"`
Author string `json:"author,omitempty"`
Version int `json:"version"`
Updated int64 `json:"updated,omitempty"`
Name string `json:"name,omitempty"`
Paths []string `json:"paths,omitempty"`
Excerpt string `json:"excerpt,omitempty"`
Chars int `json:"chars,omitempty"`
Uses int `json:"uses,omitempty"`
Likes int `json:"likes,omitempty"`
Mine bool `json:"mine,omitempty"`
Imported string `json:"imported,omitempty"`
Liked bool `json:"liked,omitempty"`
}
Card is an item in a market.
type From ¶
type From struct {
ID string `json:"id"`
Version int `json:"version"`
Title string `json:"title,omitempty"`
At time.Time `json:"at"`
}
From is the shared item one here was imported from.
type Item ¶
type Item struct {
Magpie string `json:"magpie"` // "rule" or "instructions"
Version int `json:"version"`
Rule *RuleItem `json:"rule,omitempty"`
Instructions *InstrItem `json:"instructions,omitempty"`
}
Item is a rule or a set of instructions as it is shared: the body usemagpie.ai keeps.
type Meta ¶
type Meta struct {
Title string `json:"title"`
Description string `json:"description,omitempty"`
Author string `json:"author,omitempty"`
// Public lists it in the market; unlisted, only its link opens it
Public bool `json:"public"`
}
Meta is what the user says of an item they share.
type Mine ¶
type Mine struct {
Meta
ID string `json:"id"` // on usemagpie.ai
URL string `json:"url"`
Token string `json:"token,omitempty"`
Version int `json:"version"`
At time.Time `json:"at"`
}
Mine is an item the user shared.
type Page ¶
type Page struct {
ID string `json:"id"`
URL string `json:"url"`
Kind string `json:"kind"`
Title string `json:"title"`
Description string `json:"description,omitempty"`
Author string `json:"author,omitempty"`
Public bool `json:"public"`
Version int `json:"version"`
Updated int64 `json:"updated,omitempty"`
Item Item `json:"item"`
Uses int `json:"uses,omitempty"`
Likes int `json:"likes,omitempty"`
// Liked here, and Imported: the key of the item here imported from
// it (filled in by Fetch, not the site)
Liked bool `json:"liked,omitempty"`
Imported string `json:"imported,omitempty"`
Mine bool `json:"mine,omitempty"`
// Free: for a rule, a name it can be added under here, its own or
// its own with -2, -3… (filled in by the page's API)
Free string `json:"free,omitempty"`
}
Page is a shared item as usemagpie.ai has it.
type Retired ¶
Retired is the link an item removed from the library was shared at: kept with its token, so it is never lost, while one made later under the same name shares at a link of its own. The link stays up.
type RuleItem ¶
type RuleItem struct {
Name string `json:"name"`
Paths []string `json:"paths,omitempty"`
Body string `json:"body"`
}
RuleItem is a rule shared.