cache

package
v0.1.23 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package cache 提供 Skill 包的 storage-go 缓存能力。

Server 端在 GetSkillDetail 时异步生成标准化 zip,写入 storage-go, 并将 URI 回写到 DB 的 leros_skill_marketplace_item.package_storage_path。 Worker/CLI 安装时优先从该缓存读取,失败回退远程拉取。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CacheChineseDocument

func CacheChineseDocument(ctx context.Context, st storage.Storage, bucket string,
	db *gorm.DB, source, skillID, version, packageURI string,
	bundle *fetch.SkillBundle, translateFn ChineseWriter)

CacheChineseDocument 写入 SKILL.zh-CN.md 到 storage,与 package.zip 同级。 当 SKILL.md body 的 CJK 比率 >= 0.6 时,直接使用原内容作为中文版。 否则通过 translator 调用 LLM 翻译后写入。 写库时同步更新 translated_description、author。 内部错误只记录 warning。

func CacheChineseDocumentWithContent

func CacheChineseDocumentWithContent(ctx context.Context, st storage.Storage, bucket string,
	db *gorm.DB, source, skillID, version, packageURI string,
	chineseContent string, zhDescription string)

CacheChineseDocumentWithContent 使用已有的翻译内容写入 SKILL.zh-CN.md。 与 CacheChineseDocument 不同,该方法跳过 LLM 翻译,直接使用 preTranslatedContent。

func CachePackage

func CachePackage(ctx context.Context, st storage.Storage, bucket string,
	db *gorm.DB, source, skillID, version string, bundle *fetch.SkillBundle) string

CachePackage 写入缓存:生成 zip → PutObject → 回写 DB。 内部错误只记录 warning,不影响调用方。 返回写入的 storage URI,写入失败或提前返回时返回空字符串。

func ExtractSkillMDFromZip

func ExtractSkillMDFromZip(rawZip []byte) string

ExtractSkillMDFromZip 从 zip 字节中提取完整的 SKILL.md 内容(含 frontmatter)。 用于翻译时需要完整原始内容。

func GenerateSkillZip

func GenerateSkillZip(content []byte, files map[string][]byte) ([]byte, error)

GenerateSkillZip 从 SkillBundle 生成标准 zip 字节。 zip 根目录包含 SKILL.md,支持文件保持在原相对路径。

func ParseChineseCacheKeyFromPackageURI

func ParseChineseCacheKeyFromPackageURI(packageURI string) (string, error)

ParseChineseCacheKeyFromPackageURI 从 package.zip 的 storage-go URI 推导出同目录下 SKILL.zh-CN.md 的 object key。例如:

s3://bucket/skills/marketplace/ClawHub/foo/1.0.0/skill/package.zip
→ skills/marketplace/ClawHub/foo/1.0.0/skill/SKILL.zh-CN.md

func ReadChineseDocumentFromStorage

func ReadChineseDocumentFromStorage(ctx context.Context, st storage.Storage, packageURI string) (body string, description string, err error)

ReadChineseDocumentFromStorage 从 storage 读取 SKILL.zh-CN.md 内容并去 frontmatter。 文件不存在或读取失败时返回空字符串(调用方据此回退)。

func ReadPackageFromStorage

func ReadPackageFromStorage(ctx context.Context, st storage.Storage, uri string) (skillMDBody string, files []string, rawZip []byte, err error)

ReadPackageFromStorage 从 storage 读取标准 zip,返回去 frontmatter 的 SKILL.md body 和文件列表。 uri 是 storage-go URI(如 "s3://bucket/skills/marketplace/...")。 返回: skillMDBody(不含 frontmatter)、files(含 SKILL.md)、rawZip(原始 zip 字节)、error

func SkillCacheKey

func SkillCacheKey(source, skillID, version string) string

SkillCacheKey 生成统一的 storage-go object key。 格式: skills/marketplace/{source}/{skill_id}/{version}/skill/package.zip

func SkillChineseCacheKey

func SkillChineseCacheKey(source, skillID, version string) string

SkillChineseCacheKey 生成 SKILL.zh-CN.md 的 storage-go object key。 与 package.zip 同级,格式: skills/marketplace/{source}/{skill_id}/{version}/skill/SKILL.zh-CN.md

Types

type ChineseWriter

type ChineseWriter func(ctx context.Context, content string) (string, string, error)

ChineseWriter 提供写出 SKILL.zh-CN.md 的能力,供 CachePackage 的调用方使用。 定义为接口避免 cache 包对 service 层的依赖。

Jump to

Keyboard shortcuts

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