[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-cloudflare--moltworker":3,"tool-cloudflare--moltworker":64},[4,17,27,35,48,56],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":16},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,3,"2026-04-05T11:01:52",[13,14,15],"开发框架","图像","Agent","ready",{"id":18,"name":19,"github_repo":20,"description_zh":21,"stars":22,"difficulty_score":23,"last_commit_at":24,"category_tags":25,"status":16},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",138956,2,"2026-04-05T11:33:21",[13,15,26],"语言模型",{"id":28,"name":29,"github_repo":30,"description_zh":31,"stars":32,"difficulty_score":23,"last_commit_at":33,"category_tags":34,"status":16},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",107662,"2026-04-03T11:11:01",[13,14,15],{"id":36,"name":37,"github_repo":38,"description_zh":39,"stars":40,"difficulty_score":23,"last_commit_at":41,"category_tags":42,"status":16},2268,"ML-For-Beginners","microsoft\u002FML-For-Beginners","ML-For-Beginners 是由微软推出的一套系统化机器学习入门课程，旨在帮助零基础用户轻松掌握经典机器学习知识。这套课程将学习路径规划为 12 周，包含 26 节精炼课程和 52 道配套测验，内容涵盖从基础概念到实际应用的完整流程，有效解决了初学者面对庞大知识体系时无从下手、缺乏结构化指导的痛点。\n\n无论是希望转型的开发者、需要补充算法背景的研究人员，还是对人工智能充满好奇的普通爱好者，都能从中受益。课程不仅提供了清晰的理论讲解，还强调动手实践，让用户在循序渐进中建立扎实的技能基础。其独特的亮点在于强大的多语言支持，通过自动化机制提供了包括简体中文在内的 50 多种语言版本，极大地降低了全球不同背景用户的学习门槛。此外，项目采用开源协作模式，社区活跃且内容持续更新，确保学习者能获取前沿且准确的技术资讯。如果你正寻找一条清晰、友好且专业的机器学习入门之路，ML-For-Beginners 将是理想的起点。",84991,"2026-04-05T10:45:23",[14,43,44,45,15,46,26,13,47],"数据工具","视频","插件","其他","音频",{"id":49,"name":50,"github_repo":51,"description_zh":52,"stars":53,"difficulty_score":10,"last_commit_at":54,"category_tags":55,"status":16},3128,"ragflow","infiniflow\u002Fragflow","RAGFlow 是一款领先的开源检索增强生成（RAG）引擎，旨在为大语言模型构建更精准、可靠的上下文层。它巧妙地将前沿的 RAG 技术与智能体（Agent）能力相结合，不仅支持从各类文档中高效提取知识，还能让模型基于这些知识进行逻辑推理和任务执行。\n\n在大模型应用中，幻觉问题和知识滞后是常见痛点。RAGFlow 通过深度解析复杂文档结构（如表格、图表及混合排版），显著提升了信息检索的准确度，从而有效减少模型“胡编乱造”的现象，确保回答既有据可依又具备时效性。其内置的智能体机制更进一步，使系统不仅能回答问题，还能自主规划步骤解决复杂问题。\n\n这款工具特别适合开发者、企业技术团队以及 AI 研究人员使用。无论是希望快速搭建私有知识库问答系统，还是致力于探索大模型在垂直领域落地的创新者，都能从中受益。RAGFlow 提供了可视化的工作流编排界面和灵活的 API 接口，既降低了非算法背景用户的上手门槛，也满足了专业开发者对系统深度定制的需求。作为基于 Apache 2.0 协议开源的项目，它正成为连接通用大模型与行业专有知识之间的重要桥梁。",77062,"2026-04-04T04:44:48",[15,14,13,26,46],{"id":57,"name":58,"github_repo":59,"description_zh":60,"stars":61,"difficulty_score":10,"last_commit_at":62,"category_tags":63,"status":16},2181,"OpenHands","OpenHands\u002FOpenHands","OpenHands 是一个专注于 AI 驱动开发的开源平台，旨在让智能体（Agent）像人类开发者一样理解、编写和调试代码。它解决了传统编程中重复性劳动多、环境配置复杂以及人机协作效率低等痛点，通过自动化流程显著提升开发速度。\n\n无论是希望提升编码效率的软件工程师、探索智能体技术的研究人员，还是需要快速原型验证的技术团队，都能从中受益。OpenHands 提供了灵活多样的使用方式：既可以通过命令行（CLI）或本地图形界面在个人电脑上轻松上手，体验类似 Devin 的流畅交互；也能利用其强大的 Python SDK 自定义智能体逻辑，甚至在云端大规模部署上千个智能体并行工作。\n\n其核心技术亮点在于模块化的软件智能体 SDK，这不仅构成了平台的引擎，还支持高度可组合的开发模式。此外，OpenHands 在 SWE-bench 基准测试中取得了 77.6% 的优异成绩，证明了其解决真实世界软件工程问题的能力。平台还具备完善的企业级功能，支持与 Slack、Jira 等工具集成，并提供细粒度的权限管理，适合从个人开发者到大型企业的各类用户场景。",70612,"2026-04-05T11:12:22",[26,15,13,45],{"id":65,"github_repo":66,"name":67,"description_en":68,"description_zh":69,"ai_summary_zh":70,"readme_en":71,"readme_zh":72,"quickstart_zh":73,"use_case_zh":74,"hero_image_url":75,"owner_login":76,"owner_name":77,"owner_avatar_url":78,"owner_bio":79,"owner_company":80,"owner_location":80,"owner_email":80,"owner_twitter":80,"owner_website":81,"owner_url":82,"languages":83,"stars":112,"forks":113,"last_commit_at":114,"license":115,"difficulty_score":116,"env_os":79,"env_gpu":117,"env_ram":118,"env_deps":119,"category_tags":122,"github_topics":123,"view_count":10,"oss_zip_url":80,"oss_zip_packed_at":80,"status":16,"created_at":126,"updated_at":127,"faqs":128,"releases":179},944,"cloudflare\u002Fmoltworker","moltworker","Run OpenClaw, (formerly Moltbot, formerly Clawdbot) on Cloudflare Workers","moltworker 是一个让你在 Cloudflare 边缘网络上轻松部署个人 AI 助手 OpenClaw 的开源方案。OpenClaw 原名 Moltbot\u002FClawdbot，是一款支持多平台接入的智能助手，可以通过 Telegram、Discord、Slack 等渠道与你交互，并具备网页控制界面、设备安全配对、持久化对话记录和可扩展的 AI 技能系统。\n\n这个方案主要解决了自托管 AI 助手的运维负担问题。传统部署需要自己维护服务器、处理网络配置和持续运行成本，而 moltworker 利用 Cloudflare Sandbox 容器技术，让你无需管理基础设施即可获得一个随时在线的个人助手，还支持可选的 R2 存储来实现数据持久化。\n\nmoltworker 适合有一定技术基础的开发者和高级用户，特别是那些希望拥有私有化 AI 助手、同时又不想折腾服务器运维的人群。由于需要 Cloudflare Workers 付费计划（5 美元\u002F月起）并承担容器运行费用，它更适合愿意为此支付约 30-50 元\u002F月成本的用户。通过配置自动休眠策略，实际开销可以进一步降低。\n\n技术亮点在于将完整的","moltworker 是一个让你在 Cloudflare 边缘网络上轻松部署个人 AI 助手 OpenClaw 的开源方案。OpenClaw 原名 Moltbot\u002FClawdbot，是一款支持多平台接入的智能助手，可以通过 Telegram、Discord、Slack 等渠道与你交互，并具备网页控制界面、设备安全配对、持久化对话记录和可扩展的 AI 技能系统。\n\n这个方案主要解决了自托管 AI 助手的运维负担问题。传统部署需要自己维护服务器、处理网络配置和持续运行成本，而 moltworker 利用 Cloudflare Sandbox 容器技术，让你无需管理基础设施即可获得一个随时在线的个人助手，还支持可选的 R2 存储来实现数据持久化。\n\nmoltworker 适合有一定技术基础的开发者和高级用户，特别是那些希望拥有私有化 AI 助手、同时又不想折腾服务器运维的人群。由于需要 Cloudflare Workers 付费计划（5 美元\u002F月起）并承担容器运行费用，它更适合愿意为此支付约 30-50 元\u002F月成本的用户。通过配置自动休眠策略，实际开销可以进一步降低。\n\n技术亮点在于将完整的 OpenClaw 运行时打包进 Cloudflare 的边缘容器环境，实现了 Serverless 架构下的长期运行能力，同时集成了 Cloudflare Access 认证、浏览器渲染、AI Gateway 等原生能力，形成了一套端到端的托管方案。","# OpenClaw on Cloudflare Workers\n\nRun [OpenClaw](https:\u002F\u002Fgithub.com\u002Fopenclaw\u002Fopenclaw) (formerly Moltbot, formerly Clawdbot) personal AI assistant in a [Cloudflare Sandbox](https:\u002F\u002Fdevelopers.cloudflare.com\u002Fsandbox\u002F).\n\n![moltworker architecture](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcloudflare_moltworker_readme_3589a974783b.png)\n\n> **Experimental:** This is a proof of concept demonstrating that OpenClaw can run in Cloudflare Sandbox. It is not officially supported and may break without notice. Use at your own risk.\n\n[![Deploy to Cloudflare](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcloudflare_moltworker_readme_588fab17561f.png)](https:\u002F\u002Fdeploy.workers.cloudflare.com\u002F?url=https:\u002F\u002Fgithub.com\u002Fcloudflare\u002Fmoltworker)\n\n## Requirements\n\n- [Workers Paid plan](https:\u002F\u002Fwww.cloudflare.com\u002Fplans\u002Fdeveloper-platform\u002F) ($5 USD\u002Fmonth) — required for Cloudflare Sandbox containers. Running the container incurs additional compute costs; see [Container Cost Estimate](#container-cost-estimate) below for details.\n- [Anthropic API key](https:\u002F\u002Fconsole.anthropic.com\u002F) — for Claude access, or you can use AI Gateway's [Unified Billing](https:\u002F\u002Fdevelopers.cloudflare.com\u002Fai-gateway\u002Ffeatures\u002Funified-billing\u002F)\n\nThe following Cloudflare features used by this project have free tiers:\n- Cloudflare Access (authentication)\n- Browser Rendering (for browser navigation)\n- AI Gateway (optional, for API routing\u002Fanalytics)\n- R2 Storage (optional, for persistence)\n\n## Container Cost Estimate\n\nThis project uses a `standard-1` Cloudflare Container instance (1\u002F2 vCPU, 4 GiB memory, 8 GB disk). Below are approximate monthly costs assuming the container runs 24\u002F7, based on [Cloudflare Containers pricing](https:\u002F\u002Fdevelopers.cloudflare.com\u002Fcontainers\u002Fpricing\u002F):\n\n| Resource | Provisioned | Monthly Usage | Included Free | Overage | Approx. Cost |\n|----------|-------------|---------------|---------------|---------|--------------|\n| Memory | 4 GiB | 2,920 GiB-hrs | 25 GiB-hrs | 2,895 GiB-hrs | ~$26\u002Fmo |\n| CPU (at ~10% utilization) | 1\u002F2 vCPU | ~2,190 vCPU-min | 375 vCPU-min | ~1,815 vCPU-min | ~$2\u002Fmo |\n| Disk | 8 GB | 5,840 GB-hrs | 200 GB-hrs | 5,640 GB-hrs | ~$1.50\u002Fmo |\n| Workers Paid plan | | | | | $5\u002Fmo |\n| **Total** | | | | | **~$34.50\u002Fmo** |\n\nNotes:\n- CPU is billed on **active usage only**, not provisioned capacity. The 10% utilization estimate is a rough baseline for a lightly-used personal assistant; your actual cost will vary with usage.\n- Memory and disk are billed on **provisioned capacity** for the full time the container is running.\n- To reduce costs, configure `SANDBOX_SLEEP_AFTER` (e.g., `10m`) so the container sleeps when idle. A container that only runs 4 hours\u002Fday would cost roughly ~$5-6\u002Fmo in compute on top of the $5 plan fee.\n- Network egress, Workers\u002FDurable Objects requests, and logs are additional but typically minimal for personal use.\n- See the [instance types table](https:\u002F\u002Fdevelopers.cloudflare.com\u002Fcontainers\u002Fpricing\u002F) for other options (e.g., `lite` at 256 MiB\u002F$0.50\u002Fmo memory or `standard-4` at 12 GiB for heavier workloads).\n\n## What is OpenClaw?\n\n[OpenClaw](https:\u002F\u002Fgithub.com\u002Fopenclaw\u002Fopenclaw) (formerly Moltbot, formerly Clawdbot) is a personal AI assistant with a gateway architecture that connects to multiple chat platforms. Key features:\n\n- **Control UI** - Web-based chat interface at the gateway\n- **Multi-channel support** - Telegram, Discord, Slack\n- **Device pairing** - Secure DM authentication requiring explicit approval\n- **Persistent conversations** - Chat history and context across sessions\n- **Agent runtime** - Extensible AI capabilities with workspace and skills\n\nThis project packages OpenClaw to run in a [Cloudflare Sandbox](https:\u002F\u002Fdevelopers.cloudflare.com\u002Fsandbox\u002F) container, providing a fully managed, always-on deployment without needing to self-host. Optional R2 storage enables persistence across container restarts.\n\n## Architecture\n\n![moltworker architecture](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcloudflare_moltworker_readme_594b02ba05ad.png)\n\n## Quick Start\n\n_Cloudflare Sandboxes are available on the [Workers Paid plan](https:\u002F\u002Fdash.cloudflare.com\u002F?to=\u002F:account\u002Fworkers\u002Fplans)._\n\n```bash\n# Install dependencies\nnpm install\n\n# Set your API key (direct Anthropic access)\nnpx wrangler secret put ANTHROPIC_API_KEY\n\n# Or use Cloudflare AI Gateway instead (see \"Optional: Cloudflare AI Gateway\" below)\n# npx wrangler secret put CLOUDFLARE_AI_GATEWAY_API_KEY\n# npx wrangler secret put CF_AI_GATEWAY_ACCOUNT_ID\n# npx wrangler secret put CF_AI_GATEWAY_GATEWAY_ID\n\n# Generate and set a gateway token (required for remote access)\n# Save this token - you'll need it to access the Control UI\nexport MOLTBOT_GATEWAY_TOKEN=$(openssl rand -hex 32)\necho \"Your gateway token: $MOLTBOT_GATEWAY_TOKEN\"\necho \"$MOLTBOT_GATEWAY_TOKEN\" | npx wrangler secret put MOLTBOT_GATEWAY_TOKEN\n\n# Deploy\nnpm run deploy\n```\n\nAfter deploying, open the Control UI with your token:\n\n```\nhttps:\u002F\u002Fyour-worker.workers.dev\u002F?token=YOUR_GATEWAY_TOKEN\n```\n\nReplace `your-worker` with your actual worker subdomain and `YOUR_GATEWAY_TOKEN` with the token you generated above.\n\n**Note:** The first request may take 1-2 minutes while the container starts.\n\n> **Important:** You will not be able to use the Control UI until you complete the following steps. You MUST:\n> 1. [Set up Cloudflare Access](#setting-up-the-admin-ui) to protect the admin UI\n> 2. [Pair your device](#device-pairing) via the admin UI at `\u002F_admin\u002F`\n\nYou'll also likely want to [enable R2 storage](#persistent-storage-r2) so your paired devices and conversation history persist across container restarts (optional but recommended).\n\n## Setting Up the Admin UI\n\nTo use the admin UI at `\u002F_admin\u002F` for device management, you need to:\n1. Enable Cloudflare Access on your worker\n2. Set the Access secrets so the worker can validate JWTs\n\n### 1. Enable Cloudflare Access on workers.dev\n\nThe easiest way to protect your worker is using the built-in Cloudflare Access integration for workers.dev:\n\n1. Go to the [Workers & Pages dashboard](https:\u002F\u002Fdash.cloudflare.com\u002F?to=\u002F:account\u002Fworkers-and-pages)\n2. Select your Worker (e.g., `moltbot-sandbox`)\n3. In **Settings**, under **Domains & Routes**, in the `workers.dev` row, click the meatballs menu (`...`)\n4. Click **Enable Cloudflare Access**\n5. Copy the values shown in the dialog (you'll need the AUD tag later). **Note:** The \"Manage Cloudflare Access\" link in the dialog may 404 — ignore it.\n6. To configure who can access, go to **Zero Trust** in the Cloudflare dashboard sidebar → **Access** → **Applications**, and find your worker's application:\n   - Add your email address to the allow list\n   - Or configure other identity providers (Google, GitHub, etc.)\n7. Copy the **Application Audience (AUD)** tag from the Access application settings. This will be your `CF_ACCESS_AUD` in Step 2 below\n\n### 2. Set Access Secrets\n\nAfter enabling Cloudflare Access, set the secrets so the worker can validate JWTs:\n\n```bash\n# Your Cloudflare Access team domain (e.g., \"myteam.cloudflareaccess.com\")\nnpx wrangler secret put CF_ACCESS_TEAM_DOMAIN\n\n# The Application Audience (AUD) tag from your Access application that you copied in the step above\nnpx wrangler secret put CF_ACCESS_AUD\n```\n\nYou can find your team domain in the [Zero Trust Dashboard](https:\u002F\u002Fone.dash.cloudflare.com\u002F) under **Settings** > **Custom Pages** (it's the subdomain before `.cloudflareaccess.com`).\n\n### 3. Redeploy\n\n```bash\nnpm run deploy\n```\n\nNow visit `\u002F_admin\u002F` and you'll be prompted to authenticate via Cloudflare Access before accessing the admin UI.\n\n### Alternative: Manual Access Application\n\nIf you prefer more control, you can manually create an Access application:\n\n1. Go to [Cloudflare Zero Trust Dashboard](https:\u002F\u002Fone.dash.cloudflare.com\u002F)\n2. Navigate to **Access** > **Applications**\n3. Create a new **Self-hosted** application\n4. Set the application domain to your Worker URL (e.g., `moltbot-sandbox.your-subdomain.workers.dev`)\n5. Add paths to protect: `\u002F_admin\u002F*`, `\u002Fapi\u002F*`, `\u002Fdebug\u002F*`\n6. Configure your desired identity providers (e.g., email OTP, Google, GitHub)\n7. Copy the **Application Audience (AUD)** tag and set the secrets as shown above\n\n### Local Development\n\nFor local development, create a `.dev.vars` file with:\n\n```bash\nDEV_MODE=true               # Skip Cloudflare Access auth + bypass device pairing\nDEBUG_ROUTES=true           # Enable \u002Fdebug\u002F* routes (optional)\n```\n\n## Authentication\n\nBy default, moltbot uses **device pairing** for authentication. When a new device (browser, CLI, etc.) connects, it must be approved via the admin UI at `\u002F_admin\u002F`.\n\n### Device Pairing\n\n1. A device connects to the gateway\n2. The connection is held pending until approved\n3. An admin approves the device via `\u002F_admin\u002F`\n4. The device is now paired and can connect freely\n\nThis is the most secure option as it requires explicit approval for each device.\n\n### Gateway Token (Required)\n\nA gateway token is required to access the Control UI when hosted remotely. Pass it as a query parameter:\n\n```\nhttps:\u002F\u002Fyour-worker.workers.dev\u002F?token=YOUR_TOKEN\nwss:\u002F\u002Fyour-worker.workers.dev\u002Fws?token=YOUR_TOKEN\n```\n\n**Note:** Even with a valid token, new devices still require approval via the admin UI at `\u002F_admin\u002F` (see Device Pairing above).\n\nFor local development only, set `DEV_MODE=true` in `.dev.vars` to skip Cloudflare Access authentication and enable `allowInsecureAuth` (bypasses device pairing entirely).\n\n## Persistent Storage (R2)\n\nBy default, moltbot data (configs, paired devices, conversation history) is lost when the container restarts. To enable persistent storage across sessions, configure R2:\n\n### 1. Create R2 API Token\n\n1. Go to **R2** > **Overview** in the [Cloudflare Dashboard](https:\u002F\u002Fdash.cloudflare.com\u002F)\n2. Click **Manage R2 API Tokens**\n3. Create a new token with **Object Read & Write** permissions\n4. Select the `moltbot-data` bucket (created automatically on first deploy)\n5. Copy the **Access Key ID** and **Secret Access Key**\n\n### 2. Set Secrets\n\n```bash\n# R2 Access Key ID\nnpx wrangler secret put R2_ACCESS_KEY_ID\n\n# R2 Secret Access Key\nnpx wrangler secret put R2_SECRET_ACCESS_KEY\n\n# Your Cloudflare Account ID\nnpx wrangler secret put CF_ACCOUNT_ID\n```\n\nTo find your Account ID: Go to the [Cloudflare Dashboard](https:\u002F\u002Fdash.cloudflare.com\u002F), click the three dots menu next to your account name, and select \"Copy Account ID\".\n\n### How It Works\n\nR2 storage uses a backup\u002Frestore approach for simplicity:\n\n**On container startup:**\n- If R2 is mounted and contains backup data, it's restored to the moltbot config directory\n- OpenClaw uses its default paths (no special configuration needed)\n\n**During operation:**\n- A cron job runs every 5 minutes to sync the moltbot config to R2\n- You can also trigger a manual backup from the admin UI at `\u002F_admin\u002F`\n\n**In the admin UI:**\n- When R2 is configured, you'll see \"Last backup: [timestamp]\"\n- Click \"Backup Now\" to trigger an immediate sync\n\nWithout R2 credentials, moltbot still works but uses ephemeral storage (data lost on container restart).\n\n## Container Lifecycle\n\nBy default, the sandbox container stays alive indefinitely (`SANDBOX_SLEEP_AFTER=never`). This is recommended because cold starts take 1-2 minutes.\n\nTo reduce costs for infrequently used deployments, you can configure the container to sleep after a period of inactivity:\n\n```bash\nnpx wrangler secret put SANDBOX_SLEEP_AFTER\n# Enter: 10m (or 1h, 30m, etc.)\n```\n\nWhen the container sleeps, the next request will trigger a cold start. If you have R2 storage configured, your paired devices and data will persist across restarts.\n\n## Admin UI\n\n![admin ui](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcloudflare_moltworker_readme_bed86f46648d.png)\n\nAccess the admin UI at `\u002F_admin\u002F` to:\n- **R2 Storage Status** - Shows if R2 is configured, last backup time, and a \"Backup Now\" button\n- **Restart Gateway** - Kill and restart the moltbot gateway process\n- **Device Pairing** - View pending requests, approve devices individually or all at once, view paired devices\n\nThe admin UI requires Cloudflare Access authentication (or `DEV_MODE=true` for local development).\n\n## Debug Endpoints\n\nDebug endpoints are available at `\u002Fdebug\u002F*` when enabled (requires `DEBUG_ROUTES=true` and Cloudflare Access):\n\n- `GET \u002Fdebug\u002Fprocesses` - List all container processes\n- `GET \u002Fdebug\u002Flogs?id=\u003Cprocess_id>` - Get logs for a specific process\n- `GET \u002Fdebug\u002Fversion` - Get container and moltbot version info\n\n## Optional: Chat Channels\n\n### Telegram\n\n```bash\nnpx wrangler secret put TELEGRAM_BOT_TOKEN\nnpm run deploy\n```\n\n### Discord\n\n```bash\nnpx wrangler secret put DISCORD_BOT_TOKEN\nnpm run deploy\n```\n\n### Slack\n\n```bash\nnpx wrangler secret put SLACK_BOT_TOKEN\nnpx wrangler secret put SLACK_APP_TOKEN\nnpm run deploy\n```\n\n## Optional: Browser Automation (CDP)\n\nThis worker includes a Chrome DevTools Protocol (CDP) shim that enables browser automation capabilities. This allows OpenClaw to control a headless browser for tasks like web scraping, screenshots, and automated testing.\n\n### Setup\n\n1. Set a shared secret for authentication:\n\n```bash\nnpx wrangler secret put CDP_SECRET\n# Enter a secure random string\n```\n\n2. Set your worker's public URL:\n\n```bash\nnpx wrangler secret put WORKER_URL\n# Enter: https:\u002F\u002Fyour-worker.workers.dev\n```\n\n3. Redeploy:\n\n```bash\nnpm run deploy\n```\n\n### Endpoints\n\n| Endpoint | Description |\n|----------|-------------|\n| `GET \u002Fcdp\u002Fjson\u002Fversion` | Browser version information |\n| `GET \u002Fcdp\u002Fjson\u002Flist` | List available browser targets |\n| `GET \u002Fcdp\u002Fjson\u002Fnew` | Create a new browser target |\n| `WS \u002Fcdp\u002Fdevtools\u002Fbrowser\u002F{id}` | WebSocket connection for CDP commands |\n\nAll endpoints require authentication via the `?secret=\u003CCDP_SECRET>` query parameter.\n\n## Built-in Skills\n\nThe container includes pre-installed skills in `\u002Froot\u002Fclawd\u002Fskills\u002F`:\n\n### cloudflare-browser\n\nBrowser automation via the CDP shim. Requires `CDP_SECRET` and `WORKER_URL` to be set (see [Browser Automation](#optional-browser-automation-cdp) above).\n\n**Scripts:**\n- `screenshot.js` - Capture a screenshot of a URL\n- `video.js` - Create a video from multiple URLs\n- `cdp-client.js` - Reusable CDP client library\n\n**Usage:**\n```bash\n# Screenshot\nnode \u002Froot\u002Fclawd\u002Fskills\u002Fcloudflare-browser\u002Fscripts\u002Fscreenshot.js https:\u002F\u002Fexample.com output.png\n\n# Video from multiple URLs\nnode \u002Froot\u002Fclawd\u002Fskills\u002Fcloudflare-browser\u002Fscripts\u002Fvideo.js \"https:\u002F\u002Fsite1.com,https:\u002F\u002Fsite2.com\" output.mp4 --scroll\n```\n\nSee `skills\u002Fcloudflare-browser\u002FSKILL.md` for full documentation.\n\n## Optional: Cloudflare AI Gateway\n\nYou can route API requests through [Cloudflare AI Gateway](https:\u002F\u002Fdevelopers.cloudflare.com\u002Fai-gateway\u002F) for caching, rate limiting, analytics, and cost tracking. OpenClaw has native support for Cloudflare AI Gateway as a first-class provider.\n\nAI Gateway acts as a proxy between OpenClaw and your AI provider (e.g., Anthropic). Requests are sent to `https:\u002F\u002Fgateway.ai.cloudflare.com\u002Fv1\u002F{account_id}\u002F{gateway_id}\u002Fanthropic` instead of directly to `api.anthropic.com`, giving you Cloudflare's analytics, caching, and rate limiting. You still need a provider API key (e.g., your Anthropic API key) — the gateway forwards it to the upstream provider.\n\n### Setup\n\n1. Create an AI Gateway in the [AI Gateway section](https:\u002F\u002Fdash.cloudflare.com\u002F?to=\u002F:account\u002Fai\u002Fai-gateway\u002Fcreate-gateway) of the Cloudflare Dashboard.\n2. Set the three required secrets:\n\n```bash\n# Your AI provider's API key (e.g., your Anthropic API key).\n# This is passed through the gateway to the upstream provider.\nnpx wrangler secret put CLOUDFLARE_AI_GATEWAY_API_KEY\n\n# Your Cloudflare account ID\nnpx wrangler secret put CF_AI_GATEWAY_ACCOUNT_ID\n\n# Your AI Gateway ID (from the gateway overview page)\nnpx wrangler secret put CF_AI_GATEWAY_GATEWAY_ID\n```\n\nAll three are required. OpenClaw constructs the gateway URL from the account ID and gateway ID, and passes the API key to the upstream provider through the gateway.\n\n3. Redeploy:\n\n```bash\nnpm run deploy\n```\n\nWhen Cloudflare AI Gateway is configured, it takes precedence over direct `ANTHROPIC_API_KEY` or `OPENAI_API_KEY`.\n\n### Choosing a Model\n\nBy default, AI Gateway uses Anthropic's Claude Sonnet 4.5. To use a different model or provider, set `CF_AI_GATEWAY_MODEL` with the format `provider\u002Fmodel-id`:\n\n```bash\nnpx wrangler secret put CF_AI_GATEWAY_MODEL\n# Enter: workers-ai\u002F@cf\u002Fmeta\u002Fllama-3.3-70b-instruct-fp8-fast\n```\n\nThis works with any [AI Gateway provider](https:\u002F\u002Fdevelopers.cloudflare.com\u002Fai-gateway\u002Fusage\u002Fproviders\u002F):\n\n| Provider | Example `CF_AI_GATEWAY_MODEL` value | API key is... |\n|----------|-------------------------------------|---------------|\n| Workers AI | `workers-ai\u002F@cf\u002Fmeta\u002Fllama-3.3-70b-instruct-fp8-fast` | Cloudflare API token |\n| OpenAI | `openai\u002Fgpt-4o` | OpenAI API key |\n| Anthropic | `anthropic\u002Fclaude-sonnet-4-5` | Anthropic API key |\n| Groq | `groq\u002Fllama-3.3-70b` | Groq API key |\n\n**Note:** `CLOUDFLARE_AI_GATEWAY_API_KEY` must match the provider you're using — it's your provider's API key, forwarded through the gateway. You can only use one provider at a time through the gateway. For multiple providers, use direct keys (`ANTHROPIC_API_KEY`, `OPENAI_API_KEY`) alongside the gateway config.\n\n#### Workers AI with Unified Billing\n\nWith [Unified Billing](https:\u002F\u002Fdevelopers.cloudflare.com\u002Fai-gateway\u002Ffeatures\u002Funified-billing\u002F), you can use Workers AI models without a separate provider API key — Cloudflare bills you directly. Set `CLOUDFLARE_AI_GATEWAY_API_KEY` to your [AI Gateway authentication token](https:\u002F\u002Fdevelopers.cloudflare.com\u002Fai-gateway\u002Fconfiguration\u002Fauthentication\u002F) (the `cf-aig-authorization` token).\n\n### Legacy AI Gateway Configuration\n\nThe previous `AI_GATEWAY_API_KEY` + `AI_GATEWAY_BASE_URL` approach is still supported for backward compatibility but is deprecated in favor of the native configuration above.\n\n## All Secrets Reference\n\n| Secret | Required | Description |\n|--------|----------|-------------|\n| `CLOUDFLARE_AI_GATEWAY_API_KEY` | Yes* | Your AI provider's API key, passed through the gateway (e.g., your Anthropic API key). Requires `CF_AI_GATEWAY_ACCOUNT_ID` and `CF_AI_GATEWAY_GATEWAY_ID` |\n| `CF_AI_GATEWAY_ACCOUNT_ID` | Yes* | Your Cloudflare account ID (used to construct the gateway URL) |\n| `CF_AI_GATEWAY_GATEWAY_ID` | Yes* | Your AI Gateway ID (used to construct the gateway URL) |\n| `CF_AI_GATEWAY_MODEL` | No | Override default model: `provider\u002Fmodel-id` (e.g. `workers-ai\u002F@cf\u002Fmeta\u002Fllama-3.3-70b-instruct-fp8-fast`). See [Choosing a Model](#choosing-a-model) |\n| `ANTHROPIC_API_KEY` | Yes* | Direct Anthropic API key (alternative to AI Gateway) |\n| `ANTHROPIC_BASE_URL` | No | Direct Anthropic API base URL |\n| `OPENAI_API_KEY` | No | OpenAI API key (alternative provider) |\n| `AI_GATEWAY_API_KEY` | No | Legacy AI Gateway API key (deprecated, use `CLOUDFLARE_AI_GATEWAY_API_KEY` instead) |\n| `AI_GATEWAY_BASE_URL` | No | Legacy AI Gateway endpoint URL (deprecated) |\n| `CF_ACCESS_TEAM_DOMAIN` | Yes* | Cloudflare Access team domain (required for admin UI) |\n| `CF_ACCESS_AUD` | Yes* | Cloudflare Access application audience (required for admin UI) |\n| `MOLTBOT_GATEWAY_TOKEN` | Yes | Gateway token for authentication (pass via `?token=` query param) |\n| `DEV_MODE` | No | Set to `true` to skip CF Access auth + device pairing (local dev only) |\n| `DEBUG_ROUTES` | No | Set to `true` to enable `\u002Fdebug\u002F*` routes |\n| `SANDBOX_SLEEP_AFTER` | No | Container sleep timeout: `never` (default) or duration like `10m`, `1h` |\n| `R2_ACCESS_KEY_ID` | No | R2 access key for persistent storage |\n| `R2_SECRET_ACCESS_KEY` | No | R2 secret key for persistent storage |\n| `CF_ACCOUNT_ID` | No | Cloudflare account ID (required for R2 storage) |\n| `TELEGRAM_BOT_TOKEN` | No | Telegram bot token |\n| `TELEGRAM_DM_POLICY` | No | Telegram DM policy: `pairing` (default) or `open` |\n| `DISCORD_BOT_TOKEN` | No | Discord bot token |\n| `DISCORD_DM_POLICY` | No | Discord DM policy: `pairing` (default) or `open` |\n| `SLACK_BOT_TOKEN` | No | Slack bot token |\n| `SLACK_APP_TOKEN` | No | Slack app token |\n| `CDP_SECRET` | No | Shared secret for CDP endpoint authentication (see [Browser Automation](#optional-browser-automation-cdp)) |\n| `WORKER_URL` | No | Public URL of the worker (required for CDP) |\n\n## Security Considerations\n\n### Authentication Layers\n\nOpenClaw in Cloudflare Sandbox uses multiple authentication layers:\n\n1. **Cloudflare Access** - Protects admin routes (`\u002F_admin\u002F`, `\u002Fapi\u002F*`, `\u002Fdebug\u002F*`). Only authenticated users can manage devices.\n\n2. **Gateway Token** - Required to access the Control UI. Pass via `?token=` query parameter. Keep this secret.\n\n3. **Device Pairing** - Each device (browser, CLI, chat platform DM) must be explicitly approved via the admin UI before it can interact with the assistant. This is the default \"pairing\" DM policy.\n\n## Troubleshooting\n\n**`npm run dev` fails with an `Unauthorized` error:** You need to enable Cloudflare Containers in the [Containers dashboard](https:\u002F\u002Fdash.cloudflare.com\u002F?to=\u002F:account\u002Fworkers\u002Fcontainers)\n\n**Gateway fails to start:** Check `npx wrangler secret list` and `npx wrangler tail`\n\n**Config changes not working:** Edit the `# Build cache bust:` comment in `Dockerfile` and redeploy\n\n**Slow first request:** Cold starts take 1-2 minutes. Subsequent requests are faster.\n\n**R2 not mounting:** Check that all three R2 secrets are set (`R2_ACCESS_KEY_ID`, `R2_SECRET_ACCESS_KEY`, `CF_ACCOUNT_ID`). Note: R2 mounting only works in production, not with `wrangler dev`.\n\n**Access denied on admin routes:** Ensure `CF_ACCESS_TEAM_DOMAIN` and `CF_ACCESS_AUD` are set, and that your Cloudflare Access application is configured correctly.\n\n**Devices not appearing in admin UI:** Device list commands take 10-15 seconds due to WebSocket connection overhead. Wait and refresh.\n\n**WebSocket issues in local development:** `wrangler dev` has known limitations with WebSocket proxying through the sandbox. HTTP requests work but WebSocket connections may fail. Deploy to Cloudflare for full functionality.\n\n## Known Issues\n\n### Windows: Gateway fails to start with exit code 126 (permission denied)\n\nOn Windows, Git may check out shell scripts with CRLF line endings instead of LF. This causes `start-openclaw.sh` to fail with exit code 126 inside the Linux container. Ensure your repository uses LF line endings — configure Git with `git config --global core.autocrlf input` or add a `.gitattributes` file with `* text=auto eol=lf`. See [#64](https:\u002F\u002Fgithub.com\u002Fcloudflare\u002Fmoltworker\u002Fissues\u002F64) for details.\n\n## Links\n\n- [OpenClaw](https:\u002F\u002Fgithub.com\u002Fopenclaw\u002Fopenclaw)\n- [OpenClaw Docs](https:\u002F\u002Fdocs.openclaw.ai\u002F)\n- [Cloudflare Sandbox Docs](https:\u002F\u002Fdevelopers.cloudflare.com\u002Fsandbox\u002F)\n- [Cloudflare Access Docs](https:\u002F\u002Fdevelopers.cloudflare.com\u002Fcloudflare-one\u002Fpolicies\u002Faccess\u002F)\n","# 在 Cloudflare Workers 上运行 OpenClaw\n\n在 [Cloudflare Sandbox](https:\u002F\u002Fdevelopers.cloudflare.com\u002Fsandbox\u002F) 中运行 [OpenClaw](https:\u002F\u002Fgithub.com\u002Fopenclaw\u002Fopenclaw)（前身为 Moltbot，前身为 Clawdbot）个人 AI 助手。\n\n![moltworker 架构](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcloudflare_moltworker_readme_3589a974783b.png)\n\n> **实验性：** 这是一个概念验证，演示 OpenClaw 可以在 Cloudflare Sandbox 中运行。这不是官方支持的方案，可能会在没有通知的情况下失效。请自行承担使用风险。\n\n[![部署到 Cloudflare](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcloudflare_moltworker_readme_588fab17561f.png)](https:\u002F\u002Fdeploy.workers.cloudflare.com\u002F?url=https:\u002F\u002Fgithub.com\u002Fcloudflare\u002Fmoltworker)\n\n## 要求\n\n- [Workers 付费计划](https:\u002F\u002Fwww.cloudflare.com\u002Fplans\u002Fdeveloper-platform\u002F)（每月 5 美元）—— 运行 Cloudflare Sandbox 容器所需。运行容器会产生额外的计算费用，详见下方的[容器成本估算](#容器成本估算)。\n- [Anthropic API 密钥](https:\u002F\u002Fconsole.anthropic.com\u002F) —— 用于访问 Claude，或者可以使用 AI Gateway 的[统一计费](https:\u002F\u002Fdevelopers.cloudflare.com\u002Fai-gateway\u002Ffeatures\u002Funified-billing\u002F)\n\n本项目使用的以下 Cloudflare 功能有免费层级：\n- Cloudflare Access（身份验证）\n- Browser Rendering（浏览器导航）\n- AI Gateway（可选，用于 API 路由\u002F分析）\n- R2 Storage（可选，用于持久化存储）\n\n## 容器成本估算\n\n本项目使用 `standard-1` Cloudflare Container 实例（1\u002F2 vCPU、4 GiB 内存、8 GB 磁盘）。以下是假设容器 24\u002F7 运行的每月大致费用，基于 [Cloudflare Containers 定价](https:\u002F\u002Fdevelopers.cloudflare.com\u002Fcontainers\u002Fpricing\u002F)：\n\n| 资源 | 配置规格 | 每月使用量 | 免费包含额度 | 超额用量 | 大致费用 |\n|----------|-------------|---------------|---------------|---------|--------------|\n| 内存 | 4 GiB | 2,920 GiB-小时 | 25 GiB-小时 | 2,895 GiB-小时 | ~$26\u002F月 |\n| CPU（约 10% 利用率） | 1\u002F2 vCPU | ~2,190 vCPU-分钟 | 375 vCPU-分钟 | ~1,815 vCPU-分钟 | ~$2\u002F月 |\n| 磁盘 | 8 GB | 5,840 GB-小时 | 200 GB-小时 | 5,640 GB-小时 | ~$1.50\u002F月 |\n| Workers 付费计划 | | | | | $5\u002F月 |\n| **总计** | | | | | **~$34.50\u002F月** |\n\n注意：\n- CPU 按**实际活跃使用量**计费，而非配置容量。10% 利用率估算是一个轻度使用个人助手的粗略基准；您的实际费用会因使用量而异。\n- 内存和磁盘按容器运行期间的**配置容量**计费。\n- 如需降低成本，可配置 `SANDBOX_SLEEP_AFTER`（例如 `10m`），使容器在空闲时进入休眠状态。每天仅运行 4 小时的容器，计算费用约为每月 5-6 美元，加上 5 美元的计划费用。\n- 网络出站流量、Workers\u002FDurable Objects 请求和日志会产生额外费用，但个人使用通常很少。\n- 参见[实例类型表格](https:\u002F\u002Fdevelopers.cloudflare.com\u002Fcontainers\u002Fpricing\u002F)了解其他选项（例如 `lite` 256 MiB 内存\u002F$0.50\u002F月，或 `standard-4` 12 GiB 用于更重的工作负载）。\n\n## OpenClaw 是什么？\n\n[OpenClaw](https:\u002F\u002Fgithub.com\u002Fopenclaw\u002Fopenclaw)（前身为 Moltbot，前身为 Clawdbot）是一个具有网关架构的个人 AI 助手，可连接多个聊天平台。主要功能：\n\n- **控制界面（Control UI）** - 网关处的基于 Web 的聊天界面\n- **多渠道支持** - Telegram、Discord、Slack\n- **设备配对（Device pairing）** - 需要明确批准的安全私信（DM）身份验证\n- **持久对话（Persistent conversations）** - 跨会话的聊天历史和上下文\n- **代理运行时（Agent runtime）** - 具有工作空间和技能的可扩展 AI 能力\n\n本项目将 OpenClaw 打包以在 [Cloudflare Sandbox](https:\u002F\u002Fdevelopers.cloudflare.com\u002Fsandbox\u002F) 容器中运行，提供完全托管、始终在线的部署，无需自行托管。可选的 R2 存储支持在容器重启后保持持久化。\n\n## 架构\n\n![moltworker 架构](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcloudflare_moltworker_readme_594b02ba05ad.png)\n\n## 快速开始\n\n_Cloudflare Sandboxes 在 [Workers 付费计划](https:\u002F\u002Fdash.cloudflare.com\u002F?to=\u002F:account\u002Fworkers\u002Fplans) 上可用。_\n\n```bash\n# 安装依赖\nnpm install\n\n# 设置您的 API 密钥（直接 Anthropic 访问）\nnpx wrangler secret put ANTHROPIC_API_KEY\n\n# 或者使用 Cloudflare AI Gateway（参见下方的\"可选：Cloudflare AI Gateway\"）\n# npx wrangler secret put CLOUDFLARE_AI_GATEWAY_API_KEY\n# npx wrangler secret put CF_AI_GATEWAY_ACCOUNT_ID\n# npx wrangler secret put CF_AI_GATEWAY_GATEWAY_ID\n\n# 生成并设置网关令牌（远程访问所需）\n# 保存此令牌 - 您需要它来访问控制界面\nexport MOLTBOT_GATEWAY_TOKEN=$(openssl rand -hex 32)\necho \"Your gateway token: $MOLTBOT_GATEWAY_TOKEN\"\necho \"$MOLTBOT_GATEWAY_TOKEN\" | npx wrangler secret put MOLTBOT_GATEWAY_TOKEN\n\n# 部署\nnpm run deploy\n```\n\n部署后，使用您的令牌打开控制界面：\n\n```\nhttps:\u002F\u002Fyour-worker.workers.dev\u002F?token=YOUR_GATEWAY_TOKEN\n```\n\n将 `your-worker` 替换为您的实际 worker 子域名，将 `YOUR_GATEWAY_TOKEN` 替换为您上面生成的令牌。\n\n**注意：** 首次请求可能需要 1-2 分钟，因为容器正在启动。\n\n> **重要：** 在完成以下步骤之前，您将无法使用控制界面。您必须：\n> 1. [设置 Cloudflare Access](#设置管理界面) 以保护管理界面\n> 2. 通过 `\u002F_admin\u002F` 的管理界面[配对您的设备](#设备配对)\n\n您可能还需要[启用 R2 存储](#持久化存储-r2)，以便您的配对设备和对话历史在容器重启后保持持久化（可选但推荐）。\n\n## 设置管理界面\n\n要使用 `\u002F_admin\u002F` 的管理界面进行设备管理，您需要：\n1. 在您的 worker 上启用 Cloudflare Access\n2. 设置 Access 密钥，以便 worker 可以验证 JWT\n\n### 1. 在 workers.dev 上启用 Cloudflare Access\n\n保护 worker 的最简单方式是使用 workers.dev 内置的 Cloudflare Access 集成：\n\n1. 前往 [Workers & Pages 仪表板](https:\u002F\u002Fdash.cloudflare.com\u002F?to=\u002F:account\u002Fworkers-and-pages)\n2. 选择您的 Worker（例如 `moltbot-sandbox`）\n3. 在**设置**中，**域名和路由**下，在 `workers.dev` 行点击更多操作菜单（`...`）\n4. 点击**启用 Cloudflare Access**\n5. 复制对话框中显示的值（稍后需要 AUD 标签）。**注意：** 对话框中的\"管理 Cloudflare Access\"链接可能会 404 — 请忽略。\n6. 要配置谁可以访问，请前往 Cloudflare 仪表板侧边栏的 **Zero Trust** → **Access** → **应用程序**，找到您 worker 的应用程序：\n   - 将您的电子邮件地址添加到允许列表\n   - 或配置其他身份提供商（Google、GitHub 等）\n7. 从 Access 应用程序设置中复制**应用程序受众（AUD）**标签。这将是您下方第 2 步中的 `CF_ACCESS_AUD`\n\n### 2. 设置 Access 密钥\n\n启用 Cloudflare Access 后，设置密钥以便 worker 可以验证 JWT：\n\n```bash\n# 您的 Cloudflare Access 团队域名（例如 \"myteam.cloudflareaccess.com\"）\nnpx wrangler secret put CF_ACCESS_TEAM_DOMAIN\n```\n\n# 您在上述步骤中复制的 Access 应用程序的 Application Audience (AUD) 标签（应用程序受众标识）\nnpx wrangler secret put CF_ACCESS_AUD\n```\n\n您可以在 [Zero Trust 仪表板](https:\u002F\u002Fone.dash.cloudflare.com\u002F) 的 **Settings** > **Custom Pages** 下找到您的团队域名（即 `.cloudflareaccess.com` 之前的子域名）。\n\n### 3. 重新部署\n\n```bash\nnpm run deploy\n```\n\n现在访问 `\u002F_admin\u002F`，系统会提示您通过 Cloudflare Access 进行身份验证，然后才能进入管理界面。\n\n### 替代方案：手动创建 Access 应用程序\n\n如果您希望获得更多控制权，可以手动创建 Access 应用程序：\n\n1. 前往 [Cloudflare Zero Trust 仪表板](https:\u002F\u002Fone.dash.cloudflare.com\u002F)\n2. 导航至 **Access** > **Applications**\n3. 创建一个新的 **Self-hosted**（自托管）应用程序\n4. 将应用程序域名设置为您的 Worker URL（例如 `moltbot-sandbox.your-subdomain.workers.dev`）\n5. 添加需要保护的路径：`\u002F_admin\u002F*`、`\u002Fapi\u002F*`、`\u002Fdebug\u002F*`\n6. 配置您需要的身份提供商（例如邮件 OTP、Google、GitHub）\n7. 复制 **Application Audience (AUD)** 标签，并按照上述方式设置密钥\n\n## 本地开发\n\n对于本地开发，请创建 `.dev.vars` 文件，内容如下：\n\n```bash\nDEV_MODE=true               # 跳过 Cloudflare Access 认证 + 绕过设备配对\nDEBUG_ROUTES=true           # 启用 \u002Fdebug\u002F* 路由（可选）\n```\n\n## 身份验证\n\n默认情况下，moltbot 使用**设备配对**（device pairing）进行身份验证。当新设备（浏览器、CLI 等）连接时，必须通过 `\u002F_admin\u002F` 的管理界面进行批准。\n\n### 设备配对\n\n1. 设备连接到网关\n2. 连接处于挂起状态，等待批准\n3. 管理员通过 `\u002F_admin\u002F` 批准该设备\n4. 设备现已配对，可以自由连接\n\n这是最安全的选项，因为每个设备都需要显式批准。\n\n### 网关令牌（必需）\n\n当远程托管时，需要网关令牌才能访问控制界面。请将其作为查询参数传递：\n\n```\nhttps:\u002F\u002Fyour-worker.workers.dev\u002F?token=YOUR_TOKEN\nwss:\u002F\u002Fyour-worker.workers.dev\u002Fws?token=YOUR_TOKEN\n```\n\n**注意：** 即使有有效的令牌，新设备仍然需要通过 `\u002F_admin\u002F` 的管理界面进行批准（参见上述设备配对部分）。\n\n仅用于本地开发时，在 `.dev.vars` 中设置 `DEV_MODE=true` 以跳过 Cloudflare Access 认证，并启用 `allowInsecureAuth`（完全绕过设备配对）。\n\n## 持久化存储（R2）\n\n默认情况下，moltbot 的数据（配置、配对设备、对话历史）会在容器重启时丢失。要启用跨会话的持久化存储，请配置 R2：\n\n### 1. 创建 R2 API 令牌\n\n1. 在 [Cloudflare 仪表板](https:\u002F\u002Fdash.cloudflare.com\u002F) 中前往 **R2** > **Overview**\n2. 点击 **Manage R2 API Tokens**\n3. 创建一个具有 **Object Read & Write**（对象读写）权限的新令牌\n4. 选择 `moltbot-data` 存储桶（首次部署时自动创建）\n5. 复制 **Access Key ID** 和 **Secret Access Key**\n\n### 2. 设置密钥\n\n```bash\n# R2 Access Key ID\nnpx wrangler secret put R2_ACCESS_KEY_ID\n\n# R2 Secret Access Key\nnpx wrangler secret put R2_SECRET_ACCESS_KEY\n\n# 您的 Cloudflare Account ID\nnpx wrangler secret put CF_ACCOUNT_ID\n```\n\n查找 Account ID 的方法：前往 [Cloudflare 仪表板](https:\u002F\u002Fdash.cloudflare.com\u002F)，点击账户名称旁边的三点菜单，然后选择 \"Copy Account ID\"。\n\n### 工作原理\n\nR2 存储采用备份\u002F恢复方式以简化操作：\n\n**容器启动时：**\n- 如果已挂载 R2 且包含备份数据，则会将其恢复到 moltbot 配置目录\n- OpenClaw 使用其默认路径（无需特殊配置）\n\n**运行期间：**\n- 每 5 分钟运行一次定时任务，将 moltbot 配置同步到 R2\n- 您也可以通过 `\u002F_admin\u002F` 的管理界面触发手动备份\n\n**在管理界面中：**\n- 配置 R2 后，您将看到 \"Last backup: [timestamp]\"\n- 点击 \"Backup Now\" 可触发立即同步\n\n如果没有 R2 凭证，moltbot 仍可运行，但使用临时存储（容器重启时数据丢失）。\n\n## 容器生命周期\n\n默认情况下，沙盒容器会无限期保持运行（`SANDBOX_SLEEP_AFTER=never`）。这是推荐设置，因为冷启动需要 1-2 分钟。\n\n为了降低不常用部署的成本，您可以配置容器在一段时间不活动后进入休眠：\n\n```bash\nnpx wrangler secret put SANDBOX_SLEEP_AFTER\n# 输入：10m（或 1h、30m 等）\n```\n\n当容器休眠后，下一个请求将触发冷启动。如果您已配置 R2 存储，配对的设备和数据将在重启后保留。\n\n## 管理界面\n\n![管理界面](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcloudflare_moltworker_readme_bed86f46648d.png)\n\n访问 `\u002F_admin\u002F` 的管理界面可以：\n- **R2 存储状态** - 显示 R2 是否已配置、上次备份时间，以及 \"Backup Now\" 按钮\n- **重启网关** - 终止并重启 moltbot 网关进程\n- **设备配对** - 查看待处理请求、单独或批量批准设备、查看已配对设备\n\n管理界面需要 Cloudflare Access 认证（本地开发时为 `DEV_MODE=true`）。\n\n## 调试端点\n\n启用后（需要 `DEBUG_ROUTES=true` 和 Cloudflare Access），可在 `\u002Fdebug\u002F*` 使用调试端点：\n\n- `GET \u002Fdebug\u002Fprocesses` - 列出所有容器进程\n- `GET \u002Fdebug\u002Flogs?id=\u003Cprocess_id>` - 获取特定进程的日志\n- `GET \u002Fdebug\u002Fversion` - 获取容器和 moltbot 版本信息\n\n## 可选：聊天频道\n\n### Telegram\n\n```bash\nnpx wrangler secret put TELEGRAM_BOT_TOKEN\nnpm run deploy\n```\n\n### Discord\n\n```bash\nnpx wrangler secret put DISCORD_BOT_TOKEN\nnpm run deploy\n```\n\n### Slack\n\n```bash\nnpx wrangler secret put SLACK_BOT_TOKEN\nnpx wrangler secret put SLACK_APP_TOKEN\nnpm run deploy\n```\n\n## 可选：浏览器自动化（CDP）\n\n此 Worker 包含 Chrome DevTools Protocol (CDP) 垫片，可实现浏览器自动化功能。这使得 OpenClaw 能够控制无头浏览器，执行网页抓取、截图和自动化测试等任务。\n\n### 设置\n\n1. 设置共享密钥用于身份验证：\n\n```bash\nnpx wrangler secret put CDP_SECRET\n# 输入一个安全的随机字符串\n```\n\n2. 设置 Worker 的公共 URL：\n\n```bash\nnpx wrangler secret put WORKER_URL\n# 输入：https:\u002F\u002Fyour-worker.workers.dev\n```\n\n3. 重新部署：\n\n```bash\nnpm run deploy\n```\n\n### 端点\n\n| 端点 | 描述 |\n|----------|-------------|\n| `GET \u002Fcdp\u002Fjson\u002Fversion` | 浏览器版本信息 |\n| `GET \u002Fcdp\u002Fjson\u002Flist` | 列出可用的浏览器目标 |\n| `GET \u002Fcdp\u002Fjson\u002Fnew` | 创建新的浏览器目标 |\n| `WS \u002Fcdp\u002Fdevtools\u002Fbrowser\u002F{id}` | 用于 CDP 命令的 WebSocket 连接 |\n\n所有端点都需要通过 `?secret=\u003CCDP_SECRET>` 查询参数进行身份验证。\n\n## 内置技能\n\n容器在 `\u002Froot\u002Fclawd\u002Fskills\u002F` 中包含预安装的技能：\n\n### cloudflare-browser\n\n通过 CDP（Chrome DevTools Protocol，Chrome 开发者工具协议）shim 实现浏览器自动化。需要设置 `CDP_SECRET` 和 `WORKER_URL`（详见上方的 [浏览器自动化](#optional-browser-automation-cdp)）。\n\n**脚本：**\n- `screenshot.js` - 捕获 URL 的屏幕截图\n- `video.js` - 从多个 URL 创建视频\n- `cdp-client.js` - 可复用的 CDP 客户端库\n\n**使用方法：**\n```bash\n# 屏幕截图\nnode \u002Froot\u002Fclawd\u002Fskills\u002Fcloudflare-browser\u002Fscripts\u002Fscreenshot.js https:\u002F\u002Fexample.com output.png\n\n# 从多个 URL 生成视频\nnode \u002Froot\u002Fclawd\u002Fskills\u002Fcloudflare-browser\u002Fscripts\u002Fvideo.js \"https:\u002F\u002Fsite1.com,https:\u002F\u002Fsite2.com\" output.mp4 --scroll\n```\n\n完整文档请参见 `skills\u002Fcloudflare-browser\u002FSKILL.md`。\n\n## 可选：Cloudflare AI Gateway\n\n你可以通过 [Cloudflare AI Gateway](https:\u002F\u002Fdevelopers.cloudflare.com\u002Fai-gateway\u002F) 路由 API 请求，以实现缓存、速率限制、分析和成本追踪。OpenClaw 原生支持 Cloudflare AI Gateway，将其作为一等公民（first-class）提供商。\n\nAI Gateway 作为 OpenClaw 与你的 AI 提供商（如 Anthropic）之间的代理。请求会被发送到 `https:\u002F\u002Fgateway.ai.cloudflare.com\u002Fv1\u002F{account_id}\u002F{gateway_id}\u002Fanthropic`，而不是直接发送到 `api.anthropic.com`，从而获得 Cloudflare 的分析、缓存和速率限制功能。你仍然需要提供商的 API 密钥（例如你的 Anthropic API 密钥）——网关会将其转发给上游提供商。\n\n### 设置\n\n1. 在 Cloudflare Dashboard 的 [AI Gateway 板块](https:\u002F\u002Fdash.cloudflare.com\u002F?to=\u002F:account\u002Fai\u002Fai-gateway\u002Fcreate-gateway) 创建一个 AI Gateway。\n2. 设置三个必需的密钥：\n\n```bash\n# 你的 AI 提供商的 API 密钥（例如你的 Anthropic API 密钥）。\n# 该密钥会通过网关传递给上游提供商。\nnpx wrangler secret put CLOUDFLARE_AI_GATEWAY_API_KEY\n\n# 你的 Cloudflare 账户 ID\nnpx wrangler secret put CF_AI_GATEWAY_ACCOUNT_ID\n\n# 你的 AI Gateway ID（来自网关概览页面）\nnpx wrangler secret put CF_AI_GATEWAY_GATEWAY_ID\n```\n\n这三个密钥都是必需的。OpenClaw 使用账户 ID 和网关 ID 构建网关 URL，并通过网关将 API 密钥传递给上游提供商。\n\n3. 重新部署：\n\n```bash\nnpm run deploy\n```\n\n配置 Cloudflare AI Gateway 后，它会优先于直接使用 `ANTHROPIC_API_KEY` 或 `OPENAI_API_KEY`。\n\n### 选择模型\n\n默认情况下，AI Gateway 使用 Anthropic 的 Claude Sonnet 4.5。要使用不同的模型或提供商，请使用 `provider\u002Fmodel-id` 格式设置 `CF_AI_GATEWAY_MODEL`：\n\n```bash\nnpx wrangler secret put CF_AI_GATEWAY_MODEL\n# 输入：workers-ai\u002F@cf\u002Fmeta\u002Fllama-3.3-70b-instruct-fp8-fast\n```\n\n这适用于任何 [AI Gateway 提供商](https:\u002F\u002Fdevelopers.cloudflare.com\u002Fai-gateway\u002Fusage\u002Fproviders\u002F)：\n\n| 提供商 | `CF_AI_GATEWAY_MODEL` 示例值 | API 密钥说明 |\n|----------|-------------------------------------|---------------|\n| Workers AI | `workers-ai\u002F@cf\u002Fmeta\u002Fllama-3.3-70b-instruct-fp8-fast` | Cloudflare API token |\n| OpenAI | `openai\u002Fgpt-4o` | OpenAI API key |\n| Anthropic | `anthropic\u002Fclaude-sonnet-4-5` | Anthropic API key |\n| Groq | `groq\u002Fllama-3.3-70b` | Groq API key |\n\n**注意：** `CLOUDFLARE_AI_GATEWAY_API_KEY` 必须与你使用的提供商匹配——它是你的提供商 API 密钥，通过网关转发。你一次只能通过网关使用一个提供商。如需使用多个提供商，请同时使用直接密钥（`ANTHROPIC_API_KEY`、`OPENAI_API_KEY`）和网关配置。\n\n#### 统一计费（Unified Billing）下的 Workers AI\n\n使用 [统一计费](https:\u002F\u002Fdevelopers.cloudflare.com\u002Fai-gateway\u002Ffeatures\u002Funified-billing\u002F)，你可以无需单独的提供商 API 密钥即可使用 Workers AI 模型——Cloudflare 直接向你计费。将 `CLOUDFLARE_AI_GATEWAY_API_KEY` 设置为你的 [AI Gateway 认证令牌](https:\u002F\u002Fdevelopers.cloudflare.com\u002Fai-gateway\u002Fconfiguration\u002Fauthentication\u002F)（即 `cf-aig-authorization` 令牌）。\n\n### 旧版 AI Gateway 配置\n\n之前的 `AI_GATEWAY_API_KEY` + `AI_GATEWAY_BASE_URL` 方式仍支持向后兼容，但已弃用，建议使用上述原生配置。\n\n## 所有密钥参考\n\n| 密钥 | 是否必需 | 说明 |\n|--------|----------|-------------|\n| `CLOUDFLARE_AI_GATEWAY_API_KEY` | 是* | 你的 AI 提供商 API 密钥，通过网关传递（例如你的 Anthropic API 密钥）。需要 `CF_AI_GATEWAY_ACCOUNT_ID` 和 `CF_AI_GATEWAY_GATEWAY_ID` |\n| `CF_AI_GATEWAY_ACCOUNT_ID` | 是* | 你的 Cloudflare 账户 ID（用于构建网关 URL） |\n| `CF_AI_GATEWAY_GATEWAY_ID` | 是* | 你的 AI Gateway ID（用于构建网关 URL） |\n| `CF_AI_GATEWAY_MODEL` | 否 | 覆盖默认模型：`provider\u002Fmodel-id`（例如 `workers-ai\u002F@cf\u002Fmeta\u002Fllama-3.3-70b-instruct-fp8-fast`）。参见 [选择模型](#choosing-a-model) |\n| `ANTHROPIC_API_KEY` | 是* | 直接 Anthropic API 密钥（AI Gateway 的替代方案） |\n| `ANTHROPIC_BASE_URL` | 否 | 直接 Anthropic API 基础 URL |\n| `OPENAI_API_KEY` | 否 | OpenAI API 密钥（替代提供商） |\n| `AI_GATEWAY_API_KEY` | 否 | 旧版 AI Gateway API 密钥（已弃用，请改用 `CLOUDFLARE_AI_GATEWAY_API_KEY`） |\n| `AI_GATEWAY_BASE_URL` | 否 | 旧版 AI Gateway 端点 URL（已弃用） |\n| `CF_ACCESS_TEAM_DOMAIN` | 是* | Cloudflare Access 团队域名（管理后台必需） |\n| `CF_ACCESS_AUD` | 是* | Cloudflare Access 应用受众（管理后台必需） |\n| `MOLTBOT_GATEWAY_TOKEN` | 是 | 用于认证的网关令牌（通过 `?token=` 查询参数传递） |\n| `DEV_MODE` | 否 | 设置为 `true` 以跳过 CF Access 认证和设备配对（仅本地开发） |\n| `DEBUG_ROUTES` | 否 | 设置为 `true` 以启用 `\u002Fdebug\u002F*` 路由 |\n| `SANDBOX_SLEEP_AFTER` | 否 | 容器休眠超时：`never`（默认）或时长如 `10m`、`1h` |\n| `R2_ACCESS_KEY_ID` | 否 | R2 持久化存储的访问密钥 ID |\n| `R2_SECRET_ACCESS_KEY` | 否 | R2 持久化存储的密钥 |\n| `CF_ACCOUNT_ID` | 否 | Cloudflare 账户 ID（R2 存储必需） |\n| `TELEGRAM_BOT_TOKEN` | 否 | Telegram 机器人令牌 |\n| `TELEGRAM_DM_POLICY` | 否 | Telegram DM 策略：`pairing`（默认）或 `open` |\n| `DISCORD_BOT_TOKEN` | 否 | Discord 机器人令牌 |\n| `DISCORD_DM_POLICY` | 否 | Discord DM 策略：`pairing`（默认）或 `open` |\n| `SLACK_BOT_TOKEN` | 否 | Slack 机器人令牌 |\n| `SLACK_APP_TOKEN` | 否 | Slack 应用令牌 |\n| `CDP_SECRET` | 否 | CDP 端点认证的共享密钥（参见 [浏览器自动化](#optional-browser-automation-cdp)） |\n| `WORKER_URL` | 否 | Worker 的公开 URL（CDP 必需） |\n\n## 安全注意事项\n\n### 认证层\n\nCloudflare Sandbox 中的 OpenClaw 使用多层认证：\n\n1. **Cloudflare Access** - 保护管理路由（`\u002F_admin\u002F`、`\u002Fapi\u002F*`、`\u002Fdebug\u002F*`）。只有认证用户才能管理设备。\n\n2. **网关令牌** - 访问控制界面必需。通过 `?token=` 查询参数传递。请妥善保管。\n\n3. **设备配对** - 每个设备（浏览器、CLI、聊天平台私信）必须先在管理后台明确批准，才能与助手交互。这是默认的\"配对\"私信策略。\n\n## 故障排查\n\n**`npm run dev` 失败并显示 `Unauthorized` 错误：** 你需要在 [Containers 控制台](https:\u002F\u002Fdash.cloudflare.com\u002F?to=\u002F:account\u002Fworkers\u002Fcontainers) 中启用 Cloudflare Containers\n\n**Gateway 启动失败：** 检查 `npx wrangler secret list` 和 `npx wrangler tail`\n\n**配置更改未生效：** 编辑 `Dockerfile` 中的 `# Build cache bust:` 注释并重新部署\n\n**首次请求缓慢：** 冷启动（Cold start）需要 1-2 分钟，后续请求会更快\n\n**R2 未挂载：** 检查是否已设置全部三个 R2 密钥（`R2_ACCESS_KEY_ID`、`R2_SECRET_ACCESS_KEY`、`CF_ACCOUNT_ID`）。注意：R2 挂载仅在生产环境中有效，`wrangler dev` 不支持\n\n**管理路由访问被拒绝：** 确保已设置 `CF_ACCESS_TEAM_DOMAIN` 和 `CF_ACCESS_AUD`，并且你的 Cloudflare Access 应用配置正确\n\n**管理界面中设备未显示：** 由于 WebSocket 连接开销，设备列表命令需要 10-15 秒，请等待后刷新\n\n**本地开发中的 WebSocket 问题：** `wrangler dev` 在通过沙盒代理 WebSocket 时存在已知限制。HTTP 请求可以正常工作，但 WebSocket 连接可能会失败。部署到 Cloudflare 以获得完整功能\n\n## 已知问题\n\n### Windows：Gateway 启动失败，退出代码 126（权限被拒绝）\n\n在 Windows 上，Git 可能会以 CRLF 换行符而非 LF 检出 shell 脚本。这会导致 `start-openclaw.sh` 在 Linux 容器内以退出代码 126 失败。确保你的仓库使用 LF 换行符——使用 `git config --global core.autocrlf input` 配置 Git，或在 `.gitattributes` 文件中添加 `* text=auto eol=lf`。详见 [#64](https:\u002F\u002Fgithub.com\u002Fcloudflare\u002Fmoltworker\u002Fissues\u002F64)\n\n## 相关链接\n\n- [OpenClaw](https:\u002F\u002Fgithub.com\u002Fopenclaw\u002Fopenclaw)\n- [OpenClaw 文档](https:\u002F\u002Fdocs.openclaw.ai\u002F)\n- [Cloudflare Sandbox 文档](https:\u002F\u002Fdevelopers.cloudflare.com\u002Fsandbox\u002F)\n- [Cloudflare Access 文档](https:\u002F\u002Fdevelopers.cloudflare.com\u002Fcloudflare-one\u002Fpolicies\u002Faccess\u002F)","# moltworker 快速上手指南\n\n在 Cloudflare Workers 上部署 OpenClaw 个人 AI 助手。\n\n## 环境准备\n\n### 系统要求\n- **Cloudflare Workers 付费计划**（$5\u002F月）：必需，用于 Cloudflare Sandbox 容器\n- **Anthropic API Key**：用于 Claude 访问，或使用 AI Gateway 统一计费\n\n### 前置依赖\n- Node.js 和 npm\n- Wrangler CLI（`npm install -g wrangler`）\n\n### 预估费用\n- **基础费用**：$5\u002F月（Workers 付费计划）\n- **容器运行**：约 $30\u002F月（`standard-1` 配置 24\u002F7 运行）\n- **省钱方案**：设置 `SANDBOX_SLEEP_AFTER=10m`，仅运行 4 小时\u002F天约 $5-6\u002F月\n\n## 安装步骤\n\n### 1. 克隆项目并安装依赖\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Fcloudflare\u002Fmoltworker.git\ncd moltworker\nnpm install\n```\n\n### 2. 配置 API 密钥\n\n**方式一：直接使用 Anthropic**\n```bash\nnpx wrangler secret put ANTHROPIC_API_KEY\n# 输入你的 Anthropic API Key\n```\n\n**方式二：使用 Cloudflare AI Gateway（推荐国内用户）**\n```bash\nnpx wrangler secret put CLOUDFLARE_AI_GATEWAY_API_KEY\nnpx wrangler secret put CF_AI_GATEWAY_ACCOUNT_ID\nnpx wrangler secret put CF_AI_GATEWAY_GATEWAY_ID\n```\n\n### 3. 生成网关访问令牌\n\n```bash\nexport MOLTBOT_GATEWAY_TOKEN=$(openssl rand -hex 32)\necho \"Your gateway token: $MOLTBOT_GATEWAY_TOKEN\"\necho \"$MOLTBOT_GATEWAY_TOKEN\" | npx wrangler secret put MOLTBOT_GATEWAY_TOKEN\n```\n\n**务必保存此令牌**，用于访问 Control UI。\n\n### 4. 配置 Cloudflare Access（必需）\n\n#### 启用 Access 保护\n1. 进入 [Workers & Pages 控制台](https:\u002F\u002Fdash.cloudflare.com\u002F?to=\u002F:account\u002Fworkers-and-pages)\n2. 选择你的 Worker → **Settings** → **Domains & Routes**\n3. 在 `workers.dev` 行点击 `...` → **Enable Cloudflare Access**\n4. 前往 **Zero Trust** → **Access** → **Applications**，添加允许访问的邮箱\n\n#### 设置 Access 密钥\n```bash\n# 你的团队域名，如 myteam.cloudflareaccess.com\nnpx wrangler secret put CF_ACCESS_TEAM_DOMAIN\n\n# 从 Access 应用设置复制的 AUD 标签\nnpx wrangler secret put CF_ACCESS_AUD\n```\n\n### 5. 配置 R2 持久化存储（推荐）\n\n```bash\n# 在 R2 控制台创建 API Token（Object Read & Write 权限）\nnpx wrangler secret put R2_ACCESS_KEY_ID\nnpx wrangler secret put R2_SECRET_ACCESS_KEY\nnpx wrangler secret put CF_ACCOUNT_ID\n```\n\n### 6. 部署\n\n```bash\nnpm run deploy\n```\n\n## 基本使用\n\n### 访问 Control UI\n\n```\nhttps:\u002F\u002Fyour-worker.workers.dev\u002F?token=YOUR_GATEWAY_TOKEN\n```\n\n- 替换 `your-worker` 为你的 Worker 子域名\n- 替换 `YOUR_GATEWAY_TOKEN` 为步骤 3 生成的令牌\n- **首次访问需等待 1-2 分钟**容器冷启动\n\n### 设备配对流程\n\n1. 用浏览器访问 Control UI\n2. 设备进入等待批准状态\n3. 管理员访问 `https:\u002F\u002Fyour-worker.workers.dev\u002F_admin\u002F`\n4. 通过 Cloudflare Access 认证后，在 Admin UI 中批准设备\n5. 设备获得访问权限，对话历史自动保存\n\n### 本地开发\n\n创建 `.dev.vars` 文件跳过认证：\n\n```bash\nDEV_MODE=true\nDEBUG_ROUTES=true\n```\n\n```bash\nnpm run dev\n```\n\n### 常用管理操作\n\n| 操作 | 路径 |\n|------|------|\n| 设备管理 | `\u002F_admin\u002F` |\n| 立即备份到 R2 | Admin UI 点击 \"Backup Now\" |\n| 重启网关 | Admin UI 点击 \"Restart Gateway\" |\n| 调试端点 | `\u002Fdebug\u002F*`（需 `DEBUG_ROUTES=true`） |\n\n### 容器休眠配置（省钱）\n\n```bash\nnpx wrangler secret put SANDBOX_SLEEP_AFTER\n# 输入: 10m 或 1h 等，空闲后自动休眠\n```\n\n> 注意：休眠后下次请求需 1-2 分钟冷启动，R2 配置可确保数据不丢失。","一位独立开发者运营着一个小型跨境电商社群，需要为 200 多名付费会员提供 7×24 小时的智能客服支持，同时管理多个渠道的咨询消息。\n\n### 没有 moltworker 时\n\n- **服务器运维负担重**：租用 VPS 部署 OpenClaw，每月需花费 $20-40，还要手动处理系统更新、SSL 证书续期、突发流量扩容等琐事\n- **多平台消息割裂**：Telegram、Discord、Slack 的消息分散在不同后台，客服需要频繁切换界面，容易漏回消息或重复回复\n- **夜间服务断层**：自建服务器无法弹性休眠，为覆盖夜间咨询只能 24 小时开机，低峰期空转浪费资源\n- **数据持久化风险**：容器重启后聊天记录丢失，会员的历史上下文无法继承，体验断层\n\n### 使用 moltworker 后\n\n- **零运维托管**：一键部署到 Cloudflare Workers，无需关心服务器、网络、证书，开发者专注业务而非基础设施\n- **统一网关管理**：OpenClaw 作为中央网关聚合所有渠道消息，一个 Web 界面处理全平台对话，效率提升明显\n- **智能休眠降本**：配置 `SANDBOX_SLEEP_AFTER=10m` 后，夜间无咨询时自动休眠，月成本从 $34 降至约 $10，按需计费\n- **R2 持久化存储**：聊天记录自动落盘到 Cloudflare R2，容器重启后会员对话上下文无缝衔接，服务连续性有保障\n\nmoltworker 让个人开发者用一杯咖啡的价格，获得了企业级的 AI 客服托管能力。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcloudflare_moltworker_bed86f46.png","cloudflare","Cloudflare","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fcloudflare_e3c846c2.jpg","",null,"https:\u002F\u002Fwww.cloudflare.com","https:\u002F\u002Fgithub.com\u002Fcloudflare",[84,88,92,96,100,104,108],{"name":85,"color":86,"percentage":87},"TypeScript","#3178c6",72.7,{"name":89,"color":90,"percentage":91},"Shell","#89e051",13.4,{"name":93,"color":94,"percentage":95},"JavaScript","#f1e05a",4.7,{"name":97,"color":98,"percentage":99},"HTML","#e34c26",4.2,{"name":101,"color":102,"percentage":103},"CSS","#663399",3.1,{"name":105,"color":106,"percentage":107},"HCL","#844FBA",1,{"name":109,"color":110,"percentage":111},"Dockerfile","#384d54",0.9,9798,1782,"2026-04-05T10:14:55","Apache-2.0",4,"未说明","4 GiB（容器配置）",{"notes":120,"python":117,"dependencies":121},"该工具运行在 Cloudflare Sandbox 容器中，无需本地操作系统或硬件配置。需要 Cloudflare Workers Paid 计划（$5\u002F月），使用 standard-1 容器实例（1\u002F2 vCPU、4 GiB 内存、8 GB 磁盘）。需要 Anthropic API 密钥或 Cloudflare AI Gateway 访问 Claude。可选 R2 存储用于数据持久化。容器默认保持运行状态，可通过 SANDBOX_SLEEP_AFTER 配置空闲休眠以降低成本。",[],[15],[124,125],"ai-agents","cloudflare-workers","2026-03-27T02:49:30.150509","2026-04-06T06:44:32.361996",[129,134,139,144,149,154,159,164,169,174],{"id":130,"question_zh":131,"answer_zh":132,"source_url":133},4154,"如何解决 \"disconnected (1008): Invalid or missing token\" 错误？","当在 Cloudflare Workers 上部署 Moltworker 并使用 Cloudflare AI Gateway 时，出现此错误通常是因为认证模式配置不正确。\n\n**解决方案：**\n将 AI Gateway 的认证模式从 token auth 改为 **trusted-proxy auth**。当使用 Cloudflare Worker 这类身份感知代理时，Worker 会注入 `x-forwarded-user: email@example.com`（来自 CF Access JWT），AI Gateway 会信任此头部，无需额外 token。\n\n具体配置：\n- 在 AI Gateway 设置中启用 trusted-proxy 认证模式\n- 确保 Worker 正确传递 `x-forwarded-user` 头部\n- 不需要在 URL 中添加 `?token=` 参数","https:\u002F\u002Fgithub.com\u002Fcloudflare\u002Fmoltworker\u002Fissues\u002F58",{"id":135,"question_zh":136,"answer_zh":137,"source_url":138},4155,"如何配置 Workers AI 作为模型？","目前原生支持 Cloudflare AI Gateway 已内置，可通过环境变量配置：\n\n**环境变量设置：**\n```\nCLOUDFLARE_AI_GATEWAY_API_KEY=your_api_key\nCF_AI_GATEWAY_ACCOUNT_ID=your_account_id\nCF_AI_GATEWAY_GATEWAY_ID=your_gateway_id\n```\n\n**使用 Workers AI 模型的变通方案：**\n修改 `start-moltbot.sh` 中的 OpenAI 配置部分，使用 OpenAI 兼容端点：\n\n```javascript\nconfig.models.providers.openai = {\n    baseUrl: 'https:\u002F\u002Fgateway.ai.cloudflare.com\u002Fv1\u002F{account_id}\u002F{gateway_id}\u002Fworkers-ai\u002Fv1',\n    api: 'openai-completions',\n    models: [\n        { id: '@cf\u002Fmeta\u002Fllama-3.3-70b-instruct-fp8-fast', name: 'Llama 3.3 70B', contextWindow: 24000 },\n        { id: '@cf\u002Fmeta\u002Fllama-4-scout-17b-16e-instruct', name: 'Llama 4 Scout 17B', contextWindow: 131000 },\n        { id: '@cf\u002Fmeta\u002Fllama-3.1-8b-instruct-fast', name: 'Llama 3.1 8b', contextWindow: 128000 }\n    ]\n};\n```\n\n注意：通过 AI Gateway 使用 Workers AI 模型时，模型 ID 需要包含 `@cf\u002F` 前缀。","https:\u002F\u002Fgithub.com\u002Fcloudflare\u002Fmoltworker\u002Fissues\u002F140",{"id":140,"question_zh":141,"answer_zh":142,"source_url":143},4156,"如何解决 \"Failed to mount R2 bucket\" 错误？","错误信息 \"Mount path '\u002Fdata\u002Fmoltbot' is already in use by bucket 'moltbot-data'\" 通常是因为 R2 bucket 名称不匹配或配置问题。\n\n**解决方案：**\n\n1. **创建正确的 bucket 名称**\n   需要创建一个名为 `moltbot-data` 的 R2 bucket，这是默认配置使用的名称。\n\n2. **使用自定义 bucket 名称**\n   如果需要使用其他名称，修改 `moltworker\u002Fsrc\u002Fconfig.ts` 中的配置：\n   ```typescript\n   \u002F\u002F 第15行附近\n   R2_BUCKET_NAME: 'your-custom-bucket-name'\n   ```\n\n3. **重新部署**\n   修改配置后需要重新部署 Worker 才能生效。\n\n注意：使用 \"Deploy to Cloudflare\" 按钮部署时，确保在初始配置中正确设置 R2 bucket。","https:\u002F\u002Fgithub.com\u002Fcloudflare\u002Fmoltworker\u002Fissues\u002F72",{"id":145,"question_zh":146,"answer_zh":147,"source_url":148},4157,"运行 Moltworker 24\u002F7 一个月的实际成本是多少？","在 Cloudflare Workers Paid 计划（5美元\u002F月）下运行 Moltworker 24\u002F7 的实际成本约为 **5美元\u002F月**，前提是保持默认的最小沙箱配置。\n\n**成本计算详情：**\n\nWorkers Paid 计划包含 **400,000 GB-秒\u002F月** 的 Durable Object 计算额度。\n\nDurable Object 按 128 MB 增量计费（最小计费单位）：\n- 最小沙箱配置：0.128 GB\n- 24\u002F7 运行一个月：0.128 GB × 24h × 30天 × 3600秒 ≈ **331,776 GB-秒\u002F月**\n\n这完全在 400,000 GB-秒的免费额度内，因此不会产生额外计算费用。\n\n**注意事项：**\n- 确保沙箱保持在最小 128 MB 配置\n- 避免在 Durable Object 中保存或创建大文件，否则会按实际使用内存计费\n- 容器定价与 Workers 计划分开，但默认沙箱使用 Durable Object 而非容器\n\n参考文档：https:\u002F\u002Fdevelopers.cloudflare.com\u002Fworkers\u002Fplatform\u002Fpricing\u002F#compute-billing","https:\u002F\u002Fgithub.com\u002Fcloudflare\u002Fmoltworker\u002Fissues\u002F76",{"id":150,"question_zh":151,"answer_zh":152,"source_url":153},4158,"Claude Max 订阅用户如何使用 `CLAUDE_CODE_OAUTH_TOKEN`？","Claude Max 订阅用户可以使用 `claude get-token` 命令生成长期有效的 OAuth token。\n\n**使用方法：**\n\n1. **获取 Token**\n   在本地安装 Claude CLI 后运行：\n   ```bash\n   claude get-token\n   ```\n\n2. **配置环境变量**\n   将获取的 token 设置为环境变量：\n   ```\n   CLAUDE_CODE_OAUTH_TOKEN=your_oauth_token\n   ```\n\n3. **部署配置**\n   在 Cloudflare Workers 的 \"Variables and Secrets\" 中添加该密钥，然后重新部署。\n\n此方式比使用 API key 更适合长期运行，避免了频繁更换密钥的问题。","https:\u002F\u002Fgithub.com\u002Fcloudflare\u002Fmoltworker\u002Fissues\u002F34",{"id":155,"question_zh":156,"answer_zh":157,"source_url":158},4159,"如何修复 \"Cannot find package '@anthropic-ai\u002Fclaude-code'\" 错误？","此错误发生在部署阶段，原因是构建过程中无法找到或正确安装 `@anthropic-ai\u002Fclaude-code` 包。\n\n**解决方案：**\n\n1. **检查 package.json**\n   确保依赖项正确声明：\n   ```json\n   {\n     \"dependencies\": {\n       \"@anthropic-ai\u002Fclaude-code\": \"latest\"\n     }\n   }\n   ```\n\n2. **使用 npm 而非 yarn（推荐）**\n   在 `wrangler.toml` 或构建配置中指定使用 npm：\n   ```toml\n   [build]\n   command = \"npm install && npm run build\"\n   ```\n\n3. **锁定版本（更稳定）**\n   避免使用 `latest` 标签，指定具体版本号：\n   ```json\n   \"@anthropic-ai\u002Fclaude-code\": \"0.2.14\"\n   ```\n\n4. **清理构建缓存**\n   如果之前部署失败，尝试在 Cloudflare Dashboard 中清除构建缓存后重新部署。","https:\u002F\u002Fgithub.com\u002Fcloudflare\u002Fmoltworker\u002Fissues\u002F45",{"id":160,"question_zh":161,"answer_zh":162,"source_url":163},4160,"Discord 机器人没有响应或显示 \"This interaction failed\" 怎么办？","Discord 机器人无响应通常由以下原因导致：\n\n**排查步骤：**\n\n1. **验证 Discord Token**\n   - 确认 `DISCORD_TOKEN` 环境变量已正确设置\n   - 检查 token 是否过期，必要时在 Discord Developer Portal 重新生成\n\n2. **检查 Bot 权限**\n   - 确保 bot 具有 `Send Messages`、`Read Message History`、`Use Slash Commands` 等必要权限\n   - 在 Discord Developer Portal > OAuth2 > URL Generator 中重新生成邀请链接，包含 `bot` 和 `applications.commands` 作用域\n\n3. **验证 Gateway Intents**\n   在 Discord Developer Portal > Bot 页面启用以下 Intent：\n   - `MESSAGE CONTENT INTENT`（读取消息内容）\n   - `SERVER MEMBERS INTENT`（获取成员信息）\n\n4. **检查 Worker 日志**\n   在 Cloudflare Dashboard > Workers & Pages > 你的 Worker > Logs 中查看具体错误信息\n\n5. **重新注册命令**\n   如果斜杠命令不显示，可能需要触发命令重新注册：\n   - 临时发送 `!sync` 消息（如果配置了前缀命令）\n   - 或重新部署 Worker","https:\u002F\u002Fgithub.com\u002Fcloudflare\u002Fmoltworker\u002Fissues\u002F23",{"id":165,"question_zh":166,"answer_zh":167,"source_url":168},4161,"如何配置多个 AI 模型提供商（如同时启用 OpenAI 和 Anthropic）？","Moltworker 支持通过配置文件或环境变量配置多个模型提供商。\n\n**通过环境变量配置：**\n\n```bash\n# 主要提供商\nOPENAI_API_KEY=sk-xxx\nANTHROPIC_API_KEY=sk-ant-xxx\n\n# 可选：Workers AI\nCLOUDFLARE_AI_GATEWAY_API_KEY=xxx\nCF_AI_GATEWAY_ACCOUNT_ID=xxx\nCF_AI_GATEWAY_GATEWAY_ID=xxx\n```\n\n**通过 R2 配置文件配置：**\n\n上传 `config.json` 到 R2 bucket：\n```json\n{\n  \"models\": {\n    \"mode\": \"merge\",\n    \"providers\": {\n      \"openai\": {\n        \"apiKey\": \"${OPENAI_API_KEY}\",\n        \"models\": [\n          { \"id\": \"gpt-4o\", \"name\": \"GPT-4o\" },\n          { \"id\": \"gpt-4o-mini\", \"name\": \"GPT-4o Mini\" }\n        ]\n      },\n      \"anthropic\": {\n        \"apiKey\": \"${ANTHROPIC_API_KEY}\",\n        \"models\": [\n          { \"id\": \"claude-3-5-sonnet-20241022\", \"name\": \"Claude 3.5 Sonnet\" }\n        ]\n      }\n    }\n  }\n}\n```\n\n**切换模型：**\n在对话中使用 `@模型名` 或 `\u002Fmodel` 命令切换，如 `@GPT-4o` 或 `@Claude 3.5 Sonnet`。","https:\u002F\u002Fgithub.com\u002Fcloudflare\u002Fmoltworker\u002Fissues\u002F67",{"id":170,"question_zh":171,"answer_zh":172,"source_url":173},4162,"如何备份和恢复 Moltworker 的数据？","Moltworker 使用 R2 bucket 进行数据持久化和备份。\n\n**自动备份：**\n- 数据自动保存到配置的 R2 bucket（默认 `moltbot-data`）\n- 对话历史、配置文件等都会自动同步\n\n**手动备份：**\n1. 访问 Cloudflare Dashboard > R2\n2. 找到你的 bucket（如 `moltbot-data`）\n3. 选择需要备份的对象，点击 Download 或批量导出\n\n**恢复数据：**\n1. 在新部署中配置相同的 `R2_BUCKET_NAME`\n2. 确保新 Worker 有该 bucket 的访问权限\n3. 数据会自动从 R2 加载\n\n**迁移到新账户：**\n```bash\n# 使用 rclone 或 AWS CLI 复制 bucket 内容\nrclone copy r2:old-bucket r2:new-bucket\n```\n\n注意：Durable Object 的状态是临时的，重启后会从 R2 重新加载配置，因此关键数据务必保存到 R2。","https:\u002F\u002Fgithub.com\u002Fcloudflare\u002Fmoltworker\u002Fissues\u002F89",{"id":175,"question_zh":176,"answer_zh":177,"source_url":178},4163,"如何调试和查看 Moltworker 的运行日志？","排查 Moltworker 问题需要查看多个位置的日志：\n\n**1. Cloudflare Workers 日志（实时）**\n```bash\n# 使用 wrangler CLI 实时查看日志\nnpx wrangler tail\n\n# 或使用 Cloudflare Dashboard\n# Workers & Pages > 你的 Worker > Logs > Real-time logs\n```\n\n**2. 沙箱\u002F容器日志**\n在 Durable Object 中运行的代码日志会显示在 Workers 日志中，查找 `console.log` 输出。\n\n**3. 启用详细日志**\n设置环境变量：\n```\nLOG_LEVEL=debug\n```\n\n**4. Discord 端调试**\n- 检查 Discord Developer Portal > Bot > 最近的错误\n- 使用 Discord 的 \"Test in Guild\" 功能验证命令\n\n**5. 常见问题排查：**\n| 现象 | 检查位置 |\n|------|---------|\n| 机器人不响应 | Workers 日志中的启动错误 |\n| 命令不显示 | Discord 权限和 Intent 设置 |\n| AI 无响应 | 模型提供商 API key 和额度 |\n| 数据丢失 | R2 bucket 权限和挂载状态 |\n\n**6. 本地调试（高级）**\n```bash\n# 本地运行 Worker 模拟器\nnpx wrangler dev --local\n```","https:\u002F\u002Fgithub.com\u002Fcloudflare\u002Fmoltworker\u002Fissues\u002F112",[]]