Move AI to Codex CLI + ChatGPT browser workers with a durable post queue
Text generation now runs through a PM2 automation worker (codex exec) and images through the ChatGPT Chrome extension, replacing the Anthropic API. generateStructured keeps its signature; results are Zod-validated on the web side and the worker is reached with a bearer secret. - AI image assistant in the post editor: editable prompt step, then image (square or 3:2 only, since Instagram rejects 2:3), stored via putBlob - Full-post queue (PostGenerationJob + migration): enqueue returns 202, FIFO claim under an advisory lock, heartbeat, stale-job failure, per-user request key, cancel while QUEUED; output is always a DRAFT with audit rows - Separate 10 images/page/day quota; text quota excludes images - Worker reports Codex usage-limit as 429 with a clear Thai message - Docs: AI-AUTOMATION.md, ARCHITECTURE/README/.env.example updated Known gap: the live FIFO queue check (scripts/check-post-queue.mjs) has not passed yet; the last run hit the Codex account usage limit. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -45,7 +45,6 @@ npm run dev # http://localhost:3000
|
||||
| `BLOB_READ_WRITE_TOKEN` | Vercel Blob สำหรับรูปโพสต์ |
|
||||
| `NEXT_PUBLIC_APP_URL` | URL ของระบบ (แสดง webhook URL ในหน้าเพจที่เชื่อม, ใช้สร้าง OAuth redirect URI) |
|
||||
| `GOOGLE_CLIENT_ID` / `GOOGLE_CLIENT_SECRET` | ไม่บังคับ — ปุ่ม "เข้าสู่ระบบด้วย Google" (ไม่ตั้ง = ซ่อนปุ่ม). ปุ่ม Facebook ใช้ `META_APP_ID` / `META_APP_SECRET` |
|
||||
| `ANTHROPIC_API_KEY` | ผู้ช่วย AI ผ่าน Claude API (เขียน caption, วางแผนสัปดาห์, ตรวจก่อนส่ง, ร่างคำตอบแชท, ร่างโปรไฟล์ร้าน) — ไม่ใส่ก็ใช้ระบบได้ แต่ปุ่ม AI จะแจ้งว่ายังไม่ได้ตั้งค่า |
|
||||
| `CODEX_BIN` | เฉพาะ analysis worker — path ของ Codex CLI ถ้าไม่อยู่ใน PATH (default `codex`) |
|
||||
| `CODEX_MODEL` / `ANALYSIS_TIMEOUT_MS` | ไม่บังคับ — เลือก model / timeout ต่องาน (default 10 นาที) |
|
||||
|
||||
@@ -83,3 +82,8 @@ npm run dev # http://localhost:3000
|
||||
|
||||
ตั้ง env ครบ → `npx prisma migrate deploy` กับ DB production → deploy. Cron อยู่ใน [vercel.json](vercel.json);
|
||||
`/api/cron/ig-publisher` รันทุก 10 นาที ต้องใช้ Vercel Pro (Hobby ทำ cron ได้วันละครั้ง) หรือ scheduler ภายนอกยิงพร้อม header `CRON_SECRET`
|
||||
|
||||
|
||||
## AI automation
|
||||
|
||||
เนื้อหาเรียก Codex CLI ส่วนภาพเปิดเว็บ ChatGPT ผ่าน browser profile แยก ตั้งค่า worker และ login ตาม [docs/AI-AUTOMATION.md](docs/AI-AUTOMATION.md)
|
||||
|
||||
Reference in New Issue
Block a user