artifact

package
v0.1.4739 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 27 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 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

View Source
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
)
View Source
const MaxShared = 32 << 20

MaxShared is the most a shared version's files hold together, as usemagpie.ai takes (site/shares.js MAX_BYTES).

View Source
const Page = "index.html"

Page is the name a version's page is kept and served under.

Variables

View Source
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")
)
View Source
var Dir = func() string { return appdir.Join(appdir.Config(), "artifacts") }

Dir is the folder artifacts are kept in; a variable for tests.

View Source
var ErrSharedGone = errors.New("its shared link was taken down on usemagpie.ai")

ErrSharedGone is a shared link usemagpie.ai took down on its side (a page reported): the artifact isn't shared any more.

View Source
var ShareSite = func() string {
	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

func CleanPath(p string) (string, error)

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

func Delete(id string) error

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 PageTitle

func PageTitle(page []byte) string

PageTitle is the text of the page's <title>, "" when it has none.

func Served

func Served(page []byte) []byte

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.

func Unshare

func Unshare(ctx context.Context, id string) error

Unshare takes the artifact's shared link down; one not shared, or taken down on usemagpie.ai already, is done.

func ValidID

func ValidID(id string) bool

ValidID is whether id is one an artifact can have.

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

func File(id string, n int, name string) (string, *Artifact, error)

File is where version n's (0: the newest) file name is on disk; name "" or Page is the page.

func Get

func Get(id string) (*Artifact, error)

Get is the artifact id.

func List

func List() ([]*Artifact, error)

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

func PublishPage(p Publish) (*Artifact, error)

PublishPage writes a new artifact, or a new version of one.

func (*Artifact) Latest

func (a *Artifact) Latest() *Version

Latest is the newest version.

func (*Artifact) Version

func (a *Artifact) Version(n int) *Version

Version is version n, nil when there is none; 0 is the newest.

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 {
	ID    string `json:"id"`
	URL   string `json:"url"`
	Token string `json:"token"`
	// Version is the artifact's version the link shows
	Version int       `json:"version"`
	At      time.Time `json:"at"`
}

Share is an artifact's shared link, as share.json keeps it.

func ShareLatest

func ShareLatest(ctx context.Context, id string) (*Share, error)

ShareLatest shares the artifact's newest version: at a new link, or, shared already, at its link in place of the version it showed.

func Shared

func Shared(id string) (*Share, error)

Shared is the artifact id's shared link, or nil when it isn't shared.

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.

Jump to

Keyboard shortcuts

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