artifacts

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Cloudflare Artifacts

Cloudflare Artifacts

Artifacts is Git-compatible versioned storage: namespaces hold repositories, and each repository has a Git remote. Your knowledge of the Artifacts API may be outdated or missing. Prefer retrieval over pre-training: read the matching page below before writing code, and treat the docs and generated types as the source of truth over this skill.
Artifacts 是一种兼容 Git 的版本化存储:namespace 包含 repository,每个 repository 都有一个 Git remote。你对 Artifacts API 的了解可能已经过时或不完整。优先进行检索,而非依赖预训练知识:编写代码前,先阅读下方对应的页面;应将文档和生成的 types 视为事实来源,而不是本 skill。

Documentation

文档

TaskDocsCheck for
Understand the modelHow Artifacts works, Repositories, NamespacesWhat the binding, REST API, and Git protocol each do
Use Artifacts from a WorkerWorkers get started, Workers bindingBinding config, namespace and repository methods, return shapes, minimum Wrangler version
Develop and test locallyLocal developmentLocal simulator default,
remote
setting, Git and tool versions, where local repos persist and how to reset them
Write files from a Workerisomorphic-git example, Git protocolCommit and push flow, token format, in-memory filesystem
Issue and scope tokensAuthentication, ErrorsToken scopes and how each interface authenticates; the allowed TTL range is under
INVALID_TTL
Handle failuresErrorsError names, numeric codes, and what each means
Manage repos over HTTP or the CLIREST API, Wrangler commandsRoutes, authentication, CLI usage
Design for scale and safetyBest practices, LimitsRepo naming, forking from a baseline, token lifetimes, rate limits
React to pushes or import reposEvent subscriptions, Import repositoriesEvent shapes; retry on
409 Conflict
while an import finishes. Repository
status
values are under
list()
in the Workers binding reference
For the full page list, read Artifacts llms.txt.
任务文档检查内容
理解工作方式Artifacts 工作原理、Repositories、Namespacesbinding、REST API 和 Git protocol 各自负责什么
在 Worker 中使用 ArtifactsWorkers 快速入门、Workers bindingbinding 配置、namespace 和 repository 方法、返回结构、最低 Wrangler 版本
本地开发和测试本地开发本地 simulator 的默认设置、
remote
配置、Git 和工具版本、本地 repo 的持久化位置以及重置方式
从 Worker 写入文件isomorphic-git 示例、Git protocolcommit 和 push 流程、token 格式、内存文件系统
签发 token 并限定 scope身份认证、错误token scope 以及各 interface 的认证方式;允许的 TTL 范围列在
INVALID_TTL
下
处理错误错误错误名称、数字错误码及其含义
通过 HTTP 或 CLI 管理 repoREST API、Wrangler 命令route、身份认证、CLI 用法
面向规模与安全进行设计最佳实践、限制repo 命名规则、从 baseline fork、token 生命周期、rate limit
响应 push 或导入 repo事件订阅、导入 repositoryevent 结构;导入完成期间遇到
409 Conflict
时应重试。Workers binding reference 中的
list()
项列出了 repository
status
值
如需查看完整页面列表,请阅读 Artifacts llms.txt。

Find the binding types first

先查找 binding types

Run
npx wrangler types
after adding the Artifacts binding, then read the
Artifacts
,
ArtifactsRepo
, and
ArtifactsError
declarations in the generated
worker-configuration.d.ts
. They document every method, return shape, and error code for the installed Wrangler version, and work without network access. Do not guess method names or probe the binding at runtime.
添加 Artifacts binding 后,运行
npx wrangler types
,然后读取生成的
worker-configuration.d.ts
中的
Artifacts
、
ArtifactsRepo
和
ArtifactsError
声明。它们记录了已安装 Wrangler 版本中的每个方法、返回结构和错误码,并且无需网络访问即可使用。不要猜测方法名,也不要在运行时探测 binding。

Gotchas

易错点

Most of these follow from the Workers binding reference; the last two are general Git and application guidance. They are the usual causes of Workers that pass a manual test but fail in a fresh environment.
  • The binding doesn't write files or commits. It creates, imports, forks, and deletes repositories, manages tokens, and reads metadata, history, and files. To change files, commit with a Git client, such as isomorphic-git in a Worker, and push to the repository's remote with a
    write
    token.
  • Create the repository in code if the task needs it to exist.
    get()
    throws if the repository does not exist or is not ready yet, so check the error code before treating it as missing. Handle a missing repository by calling
    create()
    , and treat
    ALREADY_EXISTS
    from
    create()
    as a concurrent request winning the race. A new repository has no commits, so the first write initializes a working tree and pushes, rather than cloning.
  • Mint a short-lived token when you need to push.
    create()
    and
    import()
    return an initial token, but prefer not to keep it in module scope or rely on it for later pushes. Call
    repo.createToken("write", ttl)
    when you need to push, use its
    plaintext
    , keep the TTL short, and revoke it when done if appropriate. Best practices recommends short lifetimes and a fresh token for each agent session. Tokens end in an
    ?expires=<unix_seconds>
    suffix; do not assume a fixed prefix. Send the full string as a Bearer token, or only the part before
    ?expires=
    as the Basic auth password, as in the Git protocol reference.
  • Read metadata with
    repo.info()
    .
    get()
    returns a disposable capability, not metadata.
    info()
    performs a fresh lookup and returns
    ArtifactsRepoInfo
    ; read its field names, such as the remote URL and default branch, from the generated types. Declare handles with
    using
    so they are released before the request ends.
  • Match errors on their code, not message text. The codes, such as
    NOT_FOUND
    and
    ALREADY_EXISTS
    , are listed on Errors; check how the binding exposes them in the
    ArtifactsError
    declaration in
    worker-configuration.d.ts
    . Retry
    IMPORT_IN_PROGRESS
    and
    FORK_IN_PROGRESS
    briefly. Return a clear error for the rest.
  • Handle concurrent pushes (general Git guidance). Two writers can race on the same branch. Push without force, and on a rejected push fetch again, reapply the change, and retry.
  • Read current state from Artifacts (general application guidance). Read files and metadata through the binding or Git when a request needs them, instead of caching repository contents, tokens, or remote URLs in module scope or another store, unless the task asks for that. Cached copies go stale and are lost on restart.
以下大多数注意事项来自 Workers binding reference;最后两项是一般性的 Git 和应用指导。这些通常会导致 Worker 在手动测试中通过,却在新环境中失败。
  • binding 不会写入文件或 commit。 它负责创建、import、fork 和删除 repository,管理 token,并读取 metadata、history 和 files。要修改文件,请使用 Git client(例如在 Worker 中使用 isomorphic-git)创建 commit,并使用
    write
    token 将其 push 到 repository 的 remote。
  • 如果任务要求 repository 存在,就在代码中创建它。 如果 repository 尚不存在或尚未就绪,
    get()
    会抛出错误,因此不要在确认错误代码之前将其视为不存在。应通过调用
    create()
    处理 repository 不存在的问题;如果
    create()
    返回
    ALREADY_EXISTS
    ,则将其视为并发请求赢得了竞态。新建的 repository 不含 commit,因此首次写入需要初始化 working tree 并执行 push,而不是 clone。
  • 需要 push 时,请签发短期 token。
    create()
    和
    import()
    会返回一个初始 token,但最好不要将其保存在 module scope 中,也不要依赖它进行后续 push。需要在 push 时调用
    repo.createToken("write", ttl)
    ,使用其
    plaintext
    ,将 TTL 保持为较短时间,并在完成后视情况撤销。最佳实践建议使用较短的 token 生命周期,并为每个 Agent 会话使用新 token。Token 以
    ?expires=<unix_seconds>
    后缀结尾;不要假设其前缀固定。将完整字符串作为 Bearer token 发送,或者按照 Git protocol reference,仅将
    ?expires=
    之前的部分用作 Basic auth password。
  • 使用
    repo.info()
    读取 metadata。
    get()
    返回的是一次性 capability,而不是 metadata。
    info()
    会执行一次全新查询并返回
    ArtifactsRepoInfo
    ;应从生成的 types 中读取其字段名称,例如 remote URL 和 default branch。使用
    using
    声明 handle,以确保在请求结束前将其释放。
  • 根据错误码匹配错误,而不是错误消息文本。 诸如
    NOT_FOUND
    和
    ALREADY_EXISTS
    等代码列于错误;请检查 binding 如何在
    worker-configuration.d.ts
    的
    ArtifactsError
    声明中暴露这些代码。对
    IMPORT_IN_PROGRESS
    和
    FORK_IN_PROGRESS
    进行短暂重试,其余错误则返回明确的错误信息。
  • 处理并发 push(一般 Git 指导)。 两个 writer 可能在同一 branch 上发生竞态。不要使用 force 进行 push;如果 push 被拒绝,则再次 fetch、重新应用变更并重试。
  • 从 Artifacts 读取当前状态(一般应用指导)。 当请求需要文件或 metadata 时,应通过 binding 或 Git 读取,而不是将 repository 内容、token 或 remote URL 缓存在 module scope 或其他存储中,除非任务明确要求这样做。缓存副本会过时,并会在重启后丢失。

Verify

验证

Test the way a new deployment runs: start from a namespace without the repository, exercise every route, restart the Worker, and exercise them again. If you created repositories or tokens by hand while exploring, delete them first, or the code that creates them is never tested. With the local simulator and persistence on, repositories persist across dev-server restarts and are separate from deployed ones. Local development covers which dev tools use the simulator by default and how to reset it to start empty.
以新 deployment 的实际运行方式进行测试:从一个不含目标 repository 的 namespace 开始,逐一测试所有 route,重启 Worker 后再次测试。如果探索期间手动创建了 repository 或 token,请先删除它们,否则创建它们的代码就不会得到测试。启用本地 simulator 和 persistence 后,repository 会在 dev server 重启后继续保留,并且与已部署的 repository 相互独立。本地开发介绍了哪些开发工具默认使用 simulator,以及如何重置 simulator 以从空状态开始。

Skill feedback

Skill 反馈

If the user reports that this skill gave incorrect or outdated guidance, or is missing information, read references/skill-feedback.md.
如果用户反馈此 skill 提供了不正确或过时的指导,或者缺少信息,请阅读 references/skill-feedback.md。