Skip to content

agentaily-feedback (Worker)

@agentaily/feedback-widget 的共享后端。接收一条反馈提交,通过 GitHub REST API 在 agentaily/agentaily 里开一个 GitHub PR(一份 reviews/<ts>.md 笔记)。 是一个独立的 Cloudflare Worker(与 apps/publish 平级);无 D1 —— 它只跟 GitHub 通信。

Flow

POST /,body 为 { site, url?, route?, comment, selector?, screenshot? }

  1. GET /repos/{owner}/{repo}/git/ref/heads/{base} —— 读取 base SHA
  2. POST …/git/refs —— 创建分支 feedback/<ts>
  3. PUT …/contents/reviews/<ts>.md —— 写入笔记(UTF-8 base64)
  4. POST …/pulls —— 开 PR

{ ok: true, url, number, branch, path }

  • CORS:只放行 agentaily.com / *.agentaily.com / agentaily.pages.dev(及预览)/ localhost (可通过 ALLOWED_ORIGINS 变量扩展)。不在白名单内的浏览器 origin 返回 403
  • GET / 是健康检查:{ ok, service, configured }(configured = token 是否已设置)。
  • 未设 GITHUB_TOKEN → 明确返回 503(绝不 500 崩溃)。body 非法 → 400。GitHub API 失败 → 502(带 step)。

Config

wrangler.toml[vars]:GITHUB_OWNER / GITHUB_REPO / BASE_BRANCH(默认 agentaily/agentaily/main), 可选 ALLOWED_ORIGINS

GITHUB_TOKEN 是一个运行时 secret —— 一个限定到 agentaily/agentailyfine-grained PAT,授予 Contents: write + Pull requests: write。绝不提交它。

Local dev

bash
pnpm --filter @agentaily/feedback exec wrangler dev --port 8790
curl http://127.0.0.1:8790                       # health
curl -X POST http://127.0.0.1:8790 -H 'content-type: application/json' \
     -d '{"site":"chatapp","comment":"hi","url":"http://localhost"}'   # → 503 until a token is set
# to actually open a PR locally, drop a token in apps/feedback/.dev.vars (gitignored):
#   GITHUB_TOKEN = "github_pat_xxx"

通过 apps/web/.env.local 把 widget 指向它:VITE_FEEDBACK_ENDPOINT=http://127.0.0.1:8790

Deploy

bash
pnpm --filter @agentaily/feedback deploy                              # wrangler deploy
pnpm --filter @agentaily/feedback exec wrangler secret put GITHUB_TOKEN   # set the PAT ONCE

尚未接入 CD(与 apps/publish 一样)—— 在配好账号 / secret 之前,部署是一个手动步骤。 见 OPERATIONS.md

Test

bash
pnpm --filter @agentaily/feedback test   # vitest (node) — CORS allowlist + GitHub REST orchestration (fetch stubbed)