Documentation
¶
Overview ¶
Package artifact keeps Magpie Artifacts: pages an agent makes for the user to look at or use (a report, a chart, a small app), kept on this computer with every version, and served by the gateway at /a/<id>/.
Claude Code's own Artifact tool keeps its pages with the claude.ai account that made them, so a page made before magpie switched the Claude account doesn't open under the next one. These are magpie's, whichever account or agent made them.
An artifact is a folder under Dir named by its id, a random, unguessable name: meta.json says what it is and lists its versions, and v<N>/ holds version N's files, the page as index.html beside the files it uses. A version is written whole into a folder of its own and never changed after; a publish that leaves a file out keeps the one before (linked, or copied where links can't be made).
Index ¶
Constants ¶
const ( // MaxPage is the most a page may hold, MaxFile a file beside it, and // MaxVersion a version's files together (the page included) MaxPage = 16 << 20 MaxFile = 16 << 20 MaxVersion = 64 << 20 // MaxFiles is the most files a version holds besides its page MaxFiles = 255 )
MaxShared is the most a shared version's files hold together, as usemagpie.ai takes (site/shares.js MAX_BYTES).
const Page = "index.html"
Page is the name a version's page is kept and served under.
Variables ¶
var ( ErrNotFound = errors.New("no such artifact") // ErrConflict: the artifact has a version newer than the one the // publish was built on ErrConflict = errors.New("the artifact has a newer version than the one read") )
Dir is the folder artifacts are kept in; a variable for tests.
ErrSharedGone is a shared link usemagpie.ai took down on its side (a page reported): the artifact isn't shared any more.
if s := os.Getenv("MAGPIE_SHARE_SITE"); s != "" { return strings.TrimRight(s, "/") } if testing.Testing() { return "" } return "https://usemagpie.ai" }
ShareSite is where artifacts are shared. MAGPIE_SHARE_SITE moves it, and a test names its own: a test never shares on the real site.
Functions ¶
func CleanPath ¶
CleanPath is a published path as kept: forward slashes, relative, nothing that climbs out or names the page; an error says why not.
func Delete ¶
Delete takes the artifact and every version of it away, its shared link first: one that can't be taken down keeps the artifact, so its token isn't lost with it.
func Served ¶
Served is the page as a browser is given it: one written as a fragment, with no doctype, is put in a document of its own with a charset, a viewport and the base styles a page without them lacks, so it doesn't render in quirks mode with the browser's defaults. A page with its doctype is given as written.
Types ¶
type Artifact ¶
type Artifact struct {
ID string `json:"id"`
Title string `json:"title"`
Description string `json:"description,omitempty"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
Versions []Version `json:"versions"`
}
Artifact is one artifact as meta.json keeps it.
func File ¶
File is where version n's (0: the newest) file name is on disk; name "" or Page is the page.
func List ¶
List is every artifact, the most recently updated first. One whose meta.json can't be read is left out, and said in the error beside the rest.
func PublishPage ¶
PublishPage writes a new artifact, or a new version of one.
type Publish ¶
type Publish struct {
ID string
Title string // used when the page has no <title> of its own
Description string
Label string
Agent string
// Page is the page itself; on an update nil keeps the one before
Page []byte
// Files are the files beside the page, by published path; on an
// update the files left out are kept, and a nil value removes one
Files map[string][]byte
// Base, when set, is the version the publisher last read: a publish
// over a newer one is refused (ErrConflict)
Base int
}
Publish is what a publish asks for. With ID empty a new artifact is made; with it, the artifact gets a new version.
type Share ¶
type Share struct {
// Version is the artifact's version the link shows
}
Share is an artifact's shared link, as share.json keeps it.
func ShareLatest ¶
ShareLatest shares the artifact's newest version: at a new link, or, shared already, at its link in place of the version it showed.
type Version ¶
type Version struct {
N int `json:"n"`
At time.Time `json:"at"`
Label string `json:"label,omitempty"`
// Agent is who published it, as the gateway knew the caller
Agent string `json:"agent,omitempty"`
// Files are the version's files besides the page, by published path
Files []string `json:"files,omitempty"`
Size int64 `json:"size"`
}
Version is one publish of an artifact.