artifacts
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCloudflare 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
文档
| Task | Docs | Check for |
|---|---|---|
| Understand the model | How Artifacts works, Repositories, Namespaces | What the binding, REST API, and Git protocol each do |
| Use Artifacts from a Worker | Workers get started, Workers binding | Binding config, namespace and repository methods, return shapes, minimum Wrangler version |
| Develop and test locally | Local development | Local simulator default, |
| Write files from a Worker | isomorphic-git example, Git protocol | Commit and push flow, token format, in-memory filesystem |
| Issue and scope tokens | Authentication, Errors | Token scopes and how each interface authenticates; the allowed TTL range is under |
| Handle failures | Errors | Error names, numeric codes, and what each means |
| Manage repos over HTTP or the CLI | REST API, Wrangler commands | Routes, authentication, CLI usage |
| Design for scale and safety | Best practices, Limits | Repo naming, forking from a baseline, token lifetimes, rate limits |
| React to pushes or import repos | Event subscriptions, Import repositories | Event shapes; retry on |
For the full page list, read Artifacts llms.txt.
| 任务 | 文档 | 检查内容 |
|---|---|---|
| 理解工作方式 | Artifacts 工作原理、Repositories、Namespaces | binding、REST API 和 Git protocol 各自负责什么 |
| 在 Worker 中使用 Artifacts | Workers 快速入门、Workers binding | binding 配置、namespace 和 repository 方法、返回结构、最低 Wrangler 版本 |
| 本地开发和测试 | 本地开发 | 本地 simulator 的默认设置、 |
| 从 Worker 写入文件 | isomorphic-git 示例、Git protocol | commit 和 push 流程、token 格式、内存文件系统 |
| 签发 token 并限定 scope | 身份认证、错误 | token scope 以及各 interface 的认证方式;允许的 TTL 范围列在 |
| 处理错误 | 错误 | 错误名称、数字错误码及其含义 |
| 通过 HTTP 或 CLI 管理 repo | REST API、Wrangler 命令 | route、身份认证、CLI 用法 |
| 面向规模与安全进行设计 | 最佳实践、限制 | repo 命名规则、从 baseline fork、token 生命周期、rate limit |
| 响应 push 或导入 repo | 事件订阅、导入 repository | event 结构;导入完成期间遇到 |
如需查看完整页面列表,请阅读 Artifacts llms.txt。
Find the binding types first
先查找 binding types
Run after adding the Artifacts binding, then read the , , and declarations in the generated . 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.
npx wrangler typesArtifactsArtifactsRepoArtifactsErrorworker-configuration.d.ts添加 Artifacts binding 后,运行 ,然后读取生成的 中的 、 和 声明。它们记录了已安装 Wrangler 版本中的每个方法、返回结构和错误码,并且无需网络访问即可使用。不要猜测方法名,也不要在运行时探测 binding。
npx wrangler typesworker-configuration.d.tsArtifactsArtifactsRepoArtifactsErrorGotchas
易错点
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 token.
write - Create the repository in code if the task needs it to exist. 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
get(), and treatcreate()fromALREADY_EXISTSas 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.create() - Mint a short-lived token when you need to push. and
create()return an initial token, but prefer not to keep it in module scope or rely on it for later pushes. Callimport()when you need to push, use itsrepo.createToken("write", ttl), 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 anplaintextsuffix; do not assume a fixed prefix. Send the full string as a Bearer token, or only the part before?expires=<unix_seconds>as the Basic auth password, as in the Git protocol reference.?expires= - Read metadata with .
repo.info()returns a disposable capability, not metadata.get()performs a fresh lookup and returnsinfo(); read its field names, such as the remote URL and default branch, from the generated types. Declare handles withArtifactsRepoInfoso they are released before the request ends.using - Match errors on their code, not message text. The codes, such as and
NOT_FOUND, are listed on Errors; check how the binding exposes them in theALREADY_EXISTSdeclaration inArtifactsError. Retryworker-configuration.d.tsandIMPORT_IN_PROGRESSbriefly. Return a clear error for the rest.FORK_IN_PROGRESS - 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,并使用 token 将其 push 到 repository 的 remote。
write - 如果任务要求 repository 存在,就在代码中创建它。 如果 repository 尚不存在或尚未就绪,会抛出错误,因此不要在确认错误代码之前将其视为不存在。应通过调用
get()处理 repository 不存在的问题;如果create()返回create(),则将其视为并发请求赢得了竞态。新建的 repository 不含 commit,因此首次写入需要初始化 working tree 并执行 push,而不是 clone。ALREADY_EXISTS - 需要 push 时,请签发短期 token。 和
create()会返回一个初始 token,但最好不要将其保存在 module scope 中,也不要依赖它进行后续 push。需要在 push 时调用import(),使用其repo.createToken("write", ttl),将 TTL 保持为较短时间,并在完成后视情况撤销。最佳实践建议使用较短的 token 生命周期,并为每个 Agent 会话使用新 token。Token 以plaintext后缀结尾;不要假设其前缀固定。将完整字符串作为 Bearer token 发送,或者按照 Git protocol reference,仅将?expires=<unix_seconds>之前的部分用作 Basic auth password。?expires= - 使用 读取 metadata。
repo.info()返回的是一次性 capability,而不是 metadata。get()会执行一次全新查询并返回info();应从生成的 types 中读取其字段名称,例如 remote URL 和 default branch。使用ArtifactsRepoInfo声明 handle,以确保在请求结束前将其释放。using - 根据错误码匹配错误,而不是错误消息文本。 诸如 和
NOT_FOUND等代码列于错误;请检查 binding 如何在ALREADY_EXISTS的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。