Help us shape the future of Go! Take the 2026 Go Developer Survey

resourcelibrary

package
v1.1.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KindSkill  = "skill"
	KindPlugin = "plugin"

	// 与现有安装器相同的上限。云端资源库不能另定一套更大的包。
	SkillArchiveLimit  int64 = 128 << 20
	PluginArchiveLimit int64 = 64 << 20
	SkillExtractLimit  int64 = 128 << 20
	PluginExtractLimit int64 = 256 << 20
	MaxPackageFiles          = 10000
)
View Source
const (
	ActionExportPrepare  = "export_prepare"
	ActionExportUpload   = "export_upload"
	ActionInstallPrepare = "install_prepare"
	ActionInstallCommit  = "install_commit"
	OperationInstall     = "install"
	OperationUpdate      = "update"

	// ChallengeTTL 是用户在 Cloud 上确认后回到设备的短窗口。过期必须重新预检。
	ChallengeTTL = 2 * time.Minute
)

Variables

This section is empty.

Functions

func AuthorizeCloudDownload

func AuthorizeCloudDownload(endpoint, rawURL string) (string, error)

AuthorizeCloudDownload 确认候选包 URL 属于当前已配对的 Nexus 原点。 其他云、本机、链路本地和私网地址都拒绝。调用方随后只能用配对 endpoint 上的 Device Token 去下载。

func AuthorizeCloudUpload

func AuthorizeCloudUpload(endpoint, rawURL string) (string, error)

AuthorizeCloudUpload 确认上传 URL 是同一配对原点上的资源库传输路由。 ticket 由 Cloud 绑定 node、kind 和预期摘要;设备只校验原点、公网地址和路径形状。

func FetchPackage

func FetchPackage(ctx context.Context, endpoint, token, rawURL, destination string, maxBytes int64) (string, error)

FetchPackage 用资源包专用客户端下载候选 ZIP。 重定向不跟随。Device Token 只出现在发往配对域名的请求里,连接地址是拨号时重新校验过的公网 IP。

func InspectArchive

func InspectArchive(archivePath, kind string) error

InspectArchive 在把候选 ZIP 交给原生安装器之前拒绝明显危险的包。 扩展名白名单只用于导出;入站包仍由 Skill/Plugin 安装器决定能不能安装, 这里负责路径穿越、符号链接、特殊文件、私钥文件名、文件数和解压大小。

func UploadPackage

func UploadPackage(ctx context.Context, endpoint, token, rawURL, archivePath string, size int64) error

UploadPackage 用已配对 Device Token 把暂存 ZIP 流式 PUT 到资源库传输路由。 正文来自文件,不先读入内存;Content-Length 使用调用方核对过的大小。3xx 不跟随。

Types

type Deps

type Deps struct {
	Now             func() time.Time
	Identity        func() (DeviceIdentity, error)
	Lookup          func(kind, name string) (string, error)
	SkillValidate   func(context.Context, string, string) (SkillPreview, error)
	SkillInstall    func(context.Context, string, string) (SkillCommit, error)
	PluginValidate  func(context.Context, string) (PluginPreview, error)
	PluginInstall   func(context.Context, string, string) (PluginCommit, error)
	PluginUpdate    func(context.Context, string, string) (PluginCommit, error)
	PluginInstalled func(string) (bool, error)
	Fetch           func(context.Context, string, string, string, string, int64) (string, error)
	Upload          func(context.Context, string, string, string, string, int64) error
}

Deps 把网络和原生安装器留在资源库外面。资源库负责确认、摘要和一次性挑战。

type DeviceIdentity

type DeviceIdentity struct {
	Endpoint    string
	NodeID      string
	DeviceToken string
}

DeviceIdentity 只保留资源库需要的配对身份。Device Token 不得进入响应。

type Error

type Error struct {
	Code     string
	Message  string
	Category string
}

Error 是资源库控制面的失败。Category 与 Runtime API 的 validation / not_found 对齐。

func (*Error) Error

func (e *Error) Error() string

type Export

type Export struct {
	Files         []FileEntry
	Warnings      []string
	Size          int64
	ArchiveDigest string
	ContentDigest string
}

Export 是一份只含可移植源码快照的 ZIP 摘要。本地绝对路径不会出现在结果里。

func ExportDirectory

func ExportDirectory(root, kind, destination string) (Export, error)

ExportDirectory 把一个已安装的受管目录打成 ZIP。 白名单按递归路径生效:不在可移植快照里的文件会让整个导出失败,而不是静默丢弃。

type FileEntry

type FileEntry struct {
	Path string `json:"path"`
	Size int64  `json:"size"`
}

type PluginCommit

type PluginCommit struct {
	Name          string
	Version       string
	PackageDigest string
	Changed       bool
}

type PluginPreview

type PluginPreview struct {
	Valid         bool
	Name          string
	Version       string
	Description   string
	PackageDigest string
	ReviewToken   string
	Skills        any // 原生 SkillComponent 只通过 JSON 公开审查摘要,不引入安装器依赖
	MCP           any // MCPReview 已移除环境变量值,仅含名称和配置摘要
	Executables   []string
	Warnings      []string
	Issues        []string
	Format        string
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

func New

func New(root string, deps Deps) (*Service, error)

func (*Service) Handle

func (s *Service) Handle(ctx context.Context, method string, body []byte) (map[string]any, error)

type SkillCommit

type SkillCommit struct {
	Name          string
	ContentDigest string
	Changed       bool
}

type SkillPreview

type SkillPreview struct {
	Valid         bool
	Name          string
	SourceDigest  string
	ContentDigest string
	Issues        []string
}

Jump to

Keyboard shortcuts

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