assets

package
v0.0.72 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProductAgentRun = "agent-run"
	ProductAgentPro = "agent-pro"

	KindFrontend = "frontend"
)

Product and kind constants used for cache paths and release archive names.

View Source
const EnvAssetBaseURL = "AGENT_PRO_ASSET_BASE_URL"

EnvAssetBaseURL is the environment variable for the default asset BaseURL.

Variables

This section is empty.

Functions

func AssetArchiveName

func AssetArchiveName(product, version, kind string) string

AssetArchiveName returns the release archive basename for a product/kind/version. Example: agent-pro_v0.0.70_frontend.tar.gz

func AssetCacheDir

func AssetCacheDir(product, version, kind string) (string, error)

AssetCacheDir returns the cache directory for a specific product/version/kind. Layout: {AssetCacheRoot}/{product}/{version}/{kind} Version is normalized to a leading "v".

func AssetCacheRoot

func AssetCacheRoot() (string, error)

AssetCacheRoot returns the root directory for downloaded SPA assets:

$XDG_CACHE_HOME/agent-pro/asset-cache

or, when XDG_CACHE_HOME is unset:

~/.cache/agent-pro/asset-cache

(via os.UserCacheDir).

func AssetReleaseNames

func AssetReleaseNames(version string) []string

AssetReleaseNames returns the frontend archive basenames for agent-run and agent-pro for the given version.

func AssetReleaseURLPath

func AssetReleaseURLPath(product, version, kind string) string

AssetReleaseURLPath returns the path segment after BaseURL for a release asset. Example: /v0.0.70/agent-pro_v0.0.70_frontend.tar.gz

func CacheComplete

func CacheComplete(product, version, kind string) bool

CacheComplete reports whether the on-disk SPA cache for product/version/kind looks like a real build: non-empty index.html and at least one non-empty file under assets/ (same idea as frontend DistComplete / spaDistComplete).

func ClientVersion

func ClientVersion() string

ClientVersion returns the embedded client/module version with a leading "v" (e.g. "v0.0.70"). The source of truth is VERSION.txt in this package; keep the root module VERSION.txt in sync.

func EnsureAsset

func EnsureAsset(ctx context.Context, product, version, kind string, cfg EnsureConfig) (string, error)

EnsureAsset ensures the SPA for product/version/kind is present and complete under the asset cache. If the cache is already complete, no network is used. Concurrent calls for the same key single-flight.

Archive URL:

{BaseURL}/v{version}/{product}_v{version}_{kind}.tar.gz

The archive root is the dist tree (index.html at archive root). Returns the cache directory path on success.

func NormalizeVersion

func NormalizeVersion(v string) string

NormalizeVersion trims whitespace and ensures a leading "v". Empty input yields empty string.

func ResolveBaseURL

func ResolveBaseURL(cfg EnsureConfig) string

ResolveBaseURL returns cfg.BaseURL or the AGENT_PRO_ASSET_BASE_URL env value.

func VersionNoPrefix

func VersionNoPrefix(v string) string

VersionNoPrefix returns the version without a leading "v"/"V".

func WriteAssetCache

func WriteAssetCache(product, version, kind string, src fs.FS) error

WriteAssetCache writes the contents of src (root = dist tree with index.html) into the cache directory for product/version/kind using atomic temp+rename.

Types

type EnsureConfig

type EnsureConfig struct {
	// BaseURL is the release asset host prefix, e.g. https://example.com/assets.
	// If empty, AGENT_PRO_ASSET_BASE_URL is used.
	BaseURL string
	// HTTPClient is optional; defaults to http.DefaultClient.
	HTTPClient *http.Client
}

EnsureConfig configures EnsureAsset downloads.

Jump to

Keyboard shortcuts

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