{"openapi":"3.0.3","info":{"title":"MBU Buddhist AI API","version":"1.0.0-demo","description":"API ของระบบแชตบอตปัญญาประดิษฐ์เฉพาะทางพระพุทธศาสนา (Demo) — ทุก response เป็น JSON { ok, data | error: { code, message } } ยกเว้น SSE"},"servers":[{"url":"https://0.0.0.0:3020"}],"tags":[{"name":"System"},{"name":"Documents"},{"name":"Auth"},{"name":"Chat"},{"name":"Privacy"},{"name":"Admin — Users"},{"name":"Admin — Privacy Requests"},{"name":"Admin — Audit Log"},{"name":"Admin — AI Config"},{"name":"Admin — Prompts"},{"name":"Admin — Guardrails"},{"name":"Admin — Unavailable"},{"name":"Admin — Pricing"},{"name":"Admin — Maintenance"},{"name":"Admin — Knowledge Base"},{"name":"Admin — Evaluation Datasets"},{"name":"Admin — Evaluation Runs"},{"name":"Admin — Evaluation Reports"},{"name":"Admin — Dashboard"},{"name":"Admin — Alerts"},{"name":"Admin — Ops"}],"paths":{"/api/health":{"get":{"tags":["System"],"summary":"สถานะระบบ: version, uptime, db, index","description":"สิทธิ์: ไม่ต้องเข้าสู่ระบบ","parameters":[],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"}}}},"/api/status":{"get":{"tags":["System"],"summary":"โหมด Unavailable + ข้อความ + สัดส่วนโทเคนที่ใช้","description":"สิทธิ์: ไม่ต้องเข้าสู่ระบบ","parameters":[],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"}}}},"/api/openapi.json":{"get":{"tags":["System"],"summary":"เอกสาร OpenAPI 3.0 ของระบบ","description":"สิทธิ์: ไม่ต้องเข้าสู่ระบบ","parameters":[],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"}}}},"/api/csrf":{"get":{"tags":["System"],"summary":"ออก CSRF token (double-submit cookie)","description":"สิทธิ์: ไม่ต้องเข้าสู่ระบบ","parameters":[],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"}}}},"/api/documents":{"get":{"tags":["Documents"],"summary":"รายการเอกสารส่งมอบ","description":"สิทธิ์: ไม่ต้องเข้าสู่ระบบ","parameters":[],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"}}}},"/api/documents/{slug}":{"get":{"tags":["Documents"],"summary":"เนื้อหา markdown ของเอกสาร (?download=1 เพื่อดาวน์โหลด)","description":"สิทธิ์: ไม่ต้องเข้าสู่ระบบ","parameters":[{"name":"slug","in":"path","required":true,"schema":{"type":"string"}},{"name":"download","in":"query","required":false,"description":"1 (optional)","schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"}}}},"/api/auth/register":{"post":{"tags":["Auth"],"summary":"สมัครสมาชิก (เก็บเฉพาะอีเมล ชื่อแสดง รหัสผ่าน + ความยินยอม)","description":"สิทธิ์: ไม่ต้องเข้าสู่ระบบ · ต้องส่ง header x-csrf-token","parameters":[{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"email":{"description":"string (email)"},"password":{"description":"string ≥8 (ตัวอักษร+ตัวเลข)"},"displayName":{"description":"string"},"consent":{"description":"true"}}}}}},"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"}}}},"/api/auth/login":{"post":{"tags":["Auth"],"summary":"เข้าสู่ระบบ (ล็อกเมื่อผิด 5 ครั้ง/15 นาที)","description":"สิทธิ์: ไม่ต้องเข้าสู่ระบบ · ต้องส่ง header x-csrf-token","parameters":[{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"email":{"description":"string"},"password":{"description":"string"}}}}}},"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"}}}},"/api/auth/logout":{"post":{"tags":["Auth"],"summary":"ออกจากระบบ","description":"สิทธิ์: ผู้ใช้ที่เข้าสู่ระบบ · ต้องส่ง header x-csrf-token","parameters":[{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/auth/oauth/{provider}/start":{"get":{"tags":["Auth"],"summary":"เริ่ม OAuth 2.0 Authorization Code (google | facebook | mock)","description":"สิทธิ์: ไม่ต้องเข้าสู่ระบบ","parameters":[{"name":"provider","in":"path","required":true,"schema":{"type":"string"}},{"name":"locale","in":"query","required":false,"description":"th|en","schema":{"type":"string"}},{"name":"as","in":"query","required":false,"description":"google|facebook (mock เท่านั้น)","schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"}}}},"/api/auth/oauth/{provider}/callback":{"get":{"tags":["Auth"],"summary":"รับ code → token → profile → เข้าสู่ระบบ","description":"สิทธิ์: ไม่ต้องเข้าสู่ระบบ","parameters":[{"name":"provider","in":"path","required":true,"schema":{"type":"string"}},{"name":"code","in":"query","required":false,"description":"string","schema":{"type":"string"}},{"name":"state","in":"query","required":false,"description":"string","schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"}}}},"/api/auth/oauth-status":{"get":{"tags":["Auth"],"summary":"provider ที่ตั้งค่าแล้ว + โหมด mock","description":"สิทธิ์: ไม่ต้องเข้าสู่ระบบ","parameters":[],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"}}}},"/api/mock-oauth/token":{"post":{"tags":["Auth"],"summary":"Token endpoint ของ Mock OAuth Provider","description":"สิทธิ์: ไม่ต้องเข้าสู่ระบบ · ต้องส่ง header x-csrf-token","parameters":[{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"code":{"description":"string"},"code_verifier":{"description":"string"},"redirect_uri":{"description":"string"},"client_id":{"description":"string"},"client_secret":{"description":"string"}}}}}},"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"}}}},"/api/mock-oauth/userinfo":{"get":{"tags":["Auth"],"summary":"Userinfo endpoint ของ Mock OAuth Provider","description":"สิทธิ์: ไม่ต้องเข้าสู่ระบบ","parameters":[],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"}}}},"/api/me":{"get":{"tags":["Auth"],"summary":"โปรไฟล์ผู้ใช้ปัจจุบัน","description":"สิทธิ์: ผู้ใช้ที่เข้าสู่ระบบ","parameters":[],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]},"patch":{"tags":["Auth"],"summary":"แก้ชื่อแสดง","description":"สิทธิ์: ผู้ใช้ที่เข้าสู่ระบบ · ต้องส่ง header x-csrf-token","parameters":[{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"displayName":{"description":"string"}}}}}},"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/chat/qa":{"post":{"tags":["Chat"],"summary":"ถาม-ตอบ (SSE: references, delta, refusal, done, error)","description":"สิทธิ์: ผู้ใช้ที่เข้าสู่ระบบ · ต้องส่ง header x-csrf-token","parameters":[{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"conversationId":{"description":"uuid (optional)"},"question":{"description":"string"},"locale":{"description":"th|en"}}}}}},"responses":{"200":{"description":"Server-Sent Events","content":{"text/event-stream":{"schema":{"type":"string"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/chat/dhamma-talk":{"post":{"tags":["Chat"],"summary":"Dhamma Talk แบบ Artifact (SSE) — เฉพาะบัญชีที่ได้รับสิทธิ์","description":"สิทธิ์: ผู้ใช้ที่เข้าสู่ระบบ · ต้องส่ง header x-csrf-token","parameters":[{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"conversationId":{"description":"uuid (optional)"},"prompt":{"description":"string"},"artifactMd":{"description":"string (optional)"},"locale":{"description":"th|en"}}}}}},"responses":{"200":{"description":"Server-Sent Events","content":{"text/event-stream":{"schema":{"type":"string"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/conversations":{"get":{"tags":["Chat"],"summary":"รายการบทสนทนาของตนเอง","description":"สิทธิ์: ผู้ใช้ที่เข้าสู่ระบบ","parameters":[{"name":"mode","in":"query","required":false,"description":"QA|DHAMMA_TALK","schema":{"type":"string"}},{"name":"page","in":"query","required":false,"description":"number","schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/conversations/{id}":{"get":{"tags":["Chat"],"summary":"ข้อความ + อ้างอิงของบทสนทนา (เฉพาะเจ้าของ)","description":"สิทธิ์: ผู้ใช้ที่เข้าสู่ระบบ","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]},"patch":{"tags":["Chat"],"summary":"เปลี่ยนชื่อ / บันทึก artifact ที่แก้ไข","description":"สิทธิ์: ผู้ใช้ที่เข้าสู่ระบบ · ต้องส่ง header x-csrf-token","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"title":{"description":"string (optional)"},"artifactMd":{"description":"string (optional)"}}}}}},"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]},"delete":{"tags":["Chat"],"summary":"ลบบทสนทนา","description":"สิทธิ์: ผู้ใช้ที่เข้าสู่ระบบ · ต้องส่ง header x-csrf-token","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/chunks/{id}":{"get":{"tags":["Chat"],"summary":"เนื้อหาเต็ม + metadata ของข้อความอ้างอิง","description":"สิทธิ์: ผู้ใช้ที่เข้าสู่ระบบ","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/messages/{id}/feedback":{"post":{"tags":["Chat"],"summary":"ให้ข้อเสนอแนะ 👍/👎","description":"สิทธิ์: ผู้ใช้ที่เข้าสู่ระบบ · ต้องส่ง header x-csrf-token","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"value":{"description":"1 | -1"},"comment":{"description":"string (optional)"}}}}}},"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/privacy/export":{"get":{"tags":["Privacy"],"summary":"สำเนาข้อมูลของตนเอง (profile, conversations+messages, feedback, tokenUsage) — TOR 14.4","description":"สิทธิ์: ผู้ใช้ที่เข้าสู่ระบบ","parameters":[{"name":"download","in":"query","required":false,"description":"1 = ส่งเป็นไฟล์แนบ (content-disposition: attachment)","schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/privacy/requests":{"post":{"tags":["Privacy"],"summary":"ยื่นคำขอใช้สิทธิเจ้าของข้อมูล (ขอสำเนา / ขอลบ / ถอนความยินยอม)","description":"สิทธิ์: ผู้ใช้ที่เข้าสู่ระบบ · ต้องส่ง header x-csrf-token","parameters":[{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"type":{"description":"access_copy | erase | withdraw_consent"},"note":{"description":"string (ไม่บังคับ, ≤ 1000)"}}}}}},"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]},"get":{"tags":["Privacy"],"summary":"ประวัติคำขอของตนเอง","description":"สิทธิ์: ผู้ใช้ที่เข้าสู่ระบบ","parameters":[],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/users":{"get":{"tags":["Admin — Users"],"summary":"ค้นหา/กรองผู้ใช้ (อีเมล/ชื่อถอดรหัสแล้ว) หน้าละ 20","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[{"name":"q","in":"query","required":false,"description":"อีเมล (exact ผ่าน emailHash) หรือบางส่วนของอีเมล/ชื่อ","schema":{"type":"string"}},{"name":"role","in":"query","required":false,"description":"SUPER_ADMIN | ADMIN | GENERAL_USER","schema":{"type":"string"}},{"name":"status","in":"query","required":false,"description":"active | suspended | deleted","schema":{"type":"string"}},{"name":"page","in":"query","required":false,"description":"เลขหน้า (เริ่ม 1)","schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/users/{id}":{"get":{"tags":["Admin — Users"],"summary":"รายละเอียดผู้ใช้ + จำนวนบทสนทนา/feedback/คำขอ PDPA","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]},"patch":{"tags":["Admin — Users"],"summary":"แก้ role (เฉพาะ SUPER_ADMIN) / status / dhammaTalkEnabled / displayName + audit before/after","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"role":{"description":"SUPER_ADMIN | ADMIN | GENERAL_USER (เฉพาะ SUPER_ADMIN เปลี่ยนได้)"},"status":{"description":"active | suspended"},"dhammaTalkEnabled":{"description":"boolean"},"displayName":{"description":"string (1–80)"}}}}}},"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]},"delete":{"tags":["Admin — Users"],"summary":"ลบผู้ใช้แบบ soft delete (status = deleted, deletedAt) + audit","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/users/{id}/conversations":{"get":{"tags":["Admin — Users"],"summary":"รายการบทสนทนาของผู้ใช้ / ข้อความในบทสนทนา — ทุกครั้งบันทึก audit conversation_accessed","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"conversationId","in":"query","required":false,"description":"ระบุเพื่ออ่านข้อความของบทสนทนานั้น","schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/privacy-requests":{"get":{"tags":["Admin — Privacy Requests"],"summary":"รายการคำขอ PDPA ทั้งหมด","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[{"name":"status","in":"query","required":false,"description":"pending | completed | rejected","schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]},"post":{"tags":["Admin — Privacy Requests"],"summary":"ผู้ดูแลสร้างคำขอ PDPA แทนผู้ใช้","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"userId":{"description":"string"},"type":{"description":"access_copy | erase | withdraw_consent"},"note":{"description":"string (ไม่บังคับ)"}}}}}},"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/privacy-requests/{id}/complete":{"post":{"tags":["Admin — Privacy Requests"],"summary":"ดำเนินการคำขอ: access_copy → สร้างไฟล์ JSON, erase → ลบบทสนทนา + anonymize, withdraw_consent → ระงับบัญชี; หรือปฏิเสธ","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"action":{"description":"complete (ค่าเริ่มต้น) | reject"},"note":{"description":"string (ไม่บังคับ)"}}}}}},"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/audit-log":{"get":{"tags":["Admin — Audit Log"],"summary":"ค้น/กรอง Audit Log (หน้าละ 50)","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[{"name":"q","in":"query","required":false,"description":"ค้นใน targetId / eventType / ip / before / after","schema":{"type":"string"}},{"name":"eventType","in":"query","required":false,"description":"ชนิดเหตุการณ์ (ตรงตัว)","schema":{"type":"string"}},{"name":"actor","in":"query","required":false,"description":"actorId หรืออีเมลผู้กระทำ","schema":{"type":"string"}},{"name":"from","in":"query","required":false,"description":"YYYY-MM-DD หรือ ISO datetime","schema":{"type":"string"}},{"name":"to","in":"query","required":false,"description":"YYYY-MM-DD หรือ ISO datetime","schema":{"type":"string"}},{"name":"page","in":"query","required":false,"description":"เลขหน้า (เริ่ม 1)","schema":{"type":"string"}},{"name":"pageSize","in":"query","required":false,"description":"จำนวนต่อหน้า (ค่าเริ่มต้น 50, สูงสุด 1000 สำหรับมุมมองพิมพ์)","schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/audit-log/export":{"get":{"tags":["Admin — Audit Log"],"summary":"ส่งออก Audit Log เป็น CSV (UTF-8 BOM) ด้วยตัวกรองเดียวกัน","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[{"name":"q","in":"query","required":false,"description":"ค้นใน targetId / eventType / ip / before / after","schema":{"type":"string"}},{"name":"eventType","in":"query","required":false,"description":"ชนิดเหตุการณ์ (ตรงตัว)","schema":{"type":"string"}},{"name":"actor","in":"query","required":false,"description":"actorId หรืออีเมลผู้กระทำ","schema":{"type":"string"}},{"name":"from","in":"query","required":false,"description":"YYYY-MM-DD หรือ ISO datetime","schema":{"type":"string"}},{"name":"to","in":"query","required":false,"description":"YYYY-MM-DD หรือ ISO datetime","schema":{"type":"string"}},{"name":"format","in":"query","required":false,"description":"csv","schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/audit-log/verify":{"get":{"tags":["Admin — Audit Log"],"summary":"ตรวจความสมบูรณ์ของ hash chain → { valid, brokenAtSeq, checked }","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/ai-config":{"get":{"tags":["Admin — AI Config"],"summary":"ค่า AI config ทั้งชุด + ค่าตั้งต้น + กลุ่ม + provider ที่รองรับ (ไม่ส่งค่า API key)","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]},"put":{"tags":["Admin — AI Config"],"summary":"แก้ค่าบางส่วน (key → value) มีผลทันทีไม่ต้อง deploy; สร้าง ConfigSnapshot ก่อนเขียน + audit","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"<key>":{"description":"ค่าใหม่ของ key ตามข้อ 7.2 เช่น \"tokens.maxPerPromptQa\": 8000 (ไม่รับ key ที่ไม่รู้จัก)"}}}}}},"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/ai-config/snapshots":{"get":{"tags":["Admin — AI Config"],"summary":"ConfigSnapshot ล่าสุด 30 รายการ + diff ย่อเทียบค่าปัจจุบัน","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[{"name":"scope","in":"query","required":false,"description":"ai-config | guardrails | unavailable | pricing (optional)","schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/ai-config/revert/{snapshotId}":{"post":{"tags":["Admin — AI Config"],"summary":"ย้อนค่ากลับตาม snapshot (สร้าง snapshot ของค่าปัจจุบันก่อน + audit)","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"snapshotId","in":"path","required":true,"schema":{"type":"string"}},{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/ai-config/models":{"get":{"tags":["Admin — AI Config"],"summary":"provider/model ที่ adapter รองรับ + configured flag","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/ai-config/test-llm":{"post":{"tags":["Admin — AI Config"],"summary":"ทดสอบเรียก LLM ตาม config ปัจจุบัน → { ok, provider, model, text, latencyMs, usage } หรือ { ok:false, error }","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/prompts":{"get":{"tags":["Admin — Prompts"],"summary":"รายการ prompt key + เวอร์ชันที่ active + จำนวนเวอร์ชัน","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/prompts/{key}":{"get":{"tags":["Admin — Prompts"],"summary":"ทุกเวอร์ชันของ prompt key (ใหม่ → เก่า)","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[{"name":"key","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]},"post":{"tags":["Admin — Prompts"],"summary":"สร้างเวอร์ชันใหม่ (max+1) — ไม่แก้เวอร์ชันเดิม; audit prompt_changed","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"key","in":"path","required":true,"schema":{"type":"string"}},{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"content":{"description":"string"},"changelog":{"description":"string (optional)"},"activate":{"description":"boolean (optional)"}}}}}},"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/prompts/{key}/activate/{version}":{"post":{"tags":["Admin — Prompts"],"summary":"ตั้งเวอร์ชัน active (rollback = activate เวอร์ชันเก่า); audit prompt_changed","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"key","in":"path","required":true,"schema":{"type":"string"}},{"name":"version","in":"path","required":true,"schema":{"type":"string"}},{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/prompts/{key}/diff":{"get":{"tags":["Admin — Prompts"],"summary":"line diff ระหว่าง 2 เวอร์ชัน: lines = [{ type: add|del|same, text }]","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[{"name":"key","in":"path","required":true,"schema":{"type":"string"}},{"name":"from","in":"query","required":false,"description":"number (version)","schema":{"type":"string"}},{"name":"to","in":"query","required":false,"description":"number (version)","schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/guardrails":{"get":{"tags":["Admin — Guardrails"],"summary":"รายการหัวข้อ/รูปแบบ guardrail","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[{"name":"kind","in":"query","required":false,"description":"scope_allow | refuse_sensitive | injection_pattern | yes_no_pattern (optional)","schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]},"post":{"tags":["Admin — Guardrails"],"summary":"เพิ่มหัวข้อ/รูปแบบ (ตรวจ regex /.../flags; snapshot + audit)","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"kind":{"description":"scope_allow | refuse_sensitive | injection_pattern | yes_no_pattern"},"key":{"description":"string (optional)"},"labelTh":{"description":"string"},"labelEn":{"description":"string"},"patterns":{"description":"string[] (คำสำคัญ หรือ /regex/flags)"},"refusalMsgTh":{"description":"string (optional)"},"refusalMsgEn":{"description":"string (optional)"},"enabled":{"description":"boolean (default true)"},"sortOrder":{"description":"number (optional)"}}}}}},"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/guardrails/{id}":{"patch":{"tags":["Admin — Guardrails"],"summary":"แก้ไขหัวข้อ/เปิด-ปิด (snapshot + audit)","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"kind":{"description":"string (optional)"},"key":{"description":"string (optional)"},"labelTh":{"description":"string (optional)"},"labelEn":{"description":"string (optional)"},"patterns":{"description":"string[] (optional)"},"refusalMsgTh":{"description":"string (optional)"},"refusalMsgEn":{"description":"string (optional)"},"enabled":{"description":"boolean (optional)"},"sortOrder":{"description":"number (optional)"}}}}}},"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]},"delete":{"tags":["Admin — Guardrails"],"summary":"ลบหัวข้อ (snapshot + audit)","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/guardrails/test":{"post":{"tags":["Admin — Guardrails"],"summary":"ทดสอบข้อความกับกฎที่เปิดใช้ (ผล rule-based; ระบบจริงใช้ LLM classifier เพิ่ม)","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"text":{"description":"string"},"locale":{"description":"th|en (optional)"}}}}}},"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/unavailable-mode":{"get":{"tags":["Admin — Unavailable"],"summary":"สถานะโหมด Unavailable + ข้อความ + โทเคน 24 ชม. เทียบเพดาน","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]},"put":{"tags":["Admin — Unavailable"],"summary":"เปิด/ปิดโหมด Unavailable, แก้ข้อความ, ล้างสถานะ auto (snapshot + audit)","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"enabled":{"description":"boolean (optional)"},"messageTh":{"description":"string (optional)"},"messageEn":{"description":"string (optional)"},"clearAuto":{"description":"boolean (optional)"}}}}}},"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/pricing":{"get":{"tags":["Admin — Pricing"],"summary":"อัตราค่าโทเคนต่อ provider/model","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]},"post":{"tags":["Admin — Pricing"],"summary":"เพิ่มอัตรา (provider+model ซ้ำ → 409; snapshot + audit)","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"provider":{"description":"string"},"model":{"description":"string"},"inputPerMillion":{"description":"number"},"thinkingPerMillion":{"description":"number (default 0)"},"outputPerMillion":{"description":"number"},"currency":{"description":"string (ISO 4217, default THB)"}}}}}},"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/pricing/{id}":{"patch":{"tags":["Admin — Pricing"],"summary":"แก้อัตรา (snapshot + audit)","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"provider":{"description":"string (optional)"},"model":{"description":"string (optional)"},"inputPerMillion":{"description":"number (optional)"},"thinkingPerMillion":{"description":"number (optional)"},"outputPerMillion":{"description":"number (optional)"},"currency":{"description":"string (optional)"}}}}}},"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]},"delete":{"tags":["Admin — Pricing"],"summary":"ลบอัตรา (snapshot + audit)","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/maintenance/purge-conversations":{"post":{"tags":["Admin — Maintenance"],"summary":"ลบบทสนทนาที่เกิน retention.conversationDays ทันที → { deleted, retentionDays }","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/knowledge-base":{"get":{"tags":["Admin — Knowledge Base"],"summary":"รายการเอกสารองค์ความรู้ (ค่าเริ่มต้นไม่รวมที่ลบแล้ว): title, docType, edition, pitaka, volume, mbuVolume, abbreviation, chunkCount, precedenceScore, status, sourceType, sanitizedLines, updatedAt","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[{"name":"q","in":"query","required":false,"description":"ค้นชื่อ/ตัวย่อ/สูตร (optional)","schema":{"type":"string"}},{"name":"docType","in":"query","required":false,"description":"tipitaka|atthakatha|tika|contemporary|teacher_dhamma (optional)","schema":{"type":"string"}},{"name":"status","in":"query","required":false,"description":"pending|indexed|failed|deleted|all (optional)","schema":{"type":"string"}},{"name":"page","in":"query","required":false,"description":"number (default 1)","schema":{"type":"string"}},{"name":"pageSize","in":"query","required":false,"description":"number ≤200 (default 25)","schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/knowledge-base/upload":{"post":{"tags":["Admin — Knowledge Base"],"summary":"อัปโหลดเอกสาร (multipart/form-data: file = pdf/txt/md/xml/docx ≤20MB + metadata) → KnowledgeDocument (pending) + IngestionJob ชนิด ingest; ตอบ { document, jobId }","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"file":{"description":"binary (multipart) — .pdf .txt .md .xml (TEI) .docx ≤ 20MB"},"title":{"description":"string"},"docType":{"description":"tipitaka|atthakatha|tika|contemporary|teacher_dhamma"},"edition":{"description":"string (optional)"},"pitaka":{"description":"vinaya|sutta|abhidhamma (optional)"},"nikaya":{"description":"string (optional)"},"sutta":{"description":"string (optional)"},"volume":{"description":"int (optional)"},"mbuVolume":{"description":"int 1–91 (optional)"},"abbreviation":{"description":"string (optional)"},"precedenceScore":{"description":"number 0–2 (optional; ค่าเริ่มต้นตาม docType)"},"sourceNote":{"description":"string (optional)"}}}}}},"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/knowledge-base/{id}":{"get":{"tags":["Admin — Knowledge Base"],"summary":"metadata ของเอกสาร + ที่มา (sourceNote/sourceUrl) + งานนำเข้าล่าสุดของเอกสาร","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]},"patch":{"tags":["Admin — Knowledge Base"],"summary":"แก้ metadata / precedenceScore (0–2) แล้วอัปเดตดัชนีใน memory ทันที (บันทึก audit before/after)","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"title":{"description":"string (optional)"},"docType":{"description":"enum (optional)"},"edition":{"description":"string|null"},"pitaka":{"description":"vinaya|sutta|abhidhamma|null"},"nikaya":{"description":"string|null"},"sutta":{"description":"string|null"},"volume":{"description":"int|null"},"mbuVolume":{"description":"int 1–91|null"},"abbreviation":{"description":"string|null"},"precedenceScore":{"description":"number 0–2"},"sourceNote":{"description":"string|null"},"sourceUrl":{"description":"string|null"},"paliAliases":{"description":"string|null (คั่นด้วย |)"}}}}}},"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]},"delete":{"tags":["Admin — Knowledge Base"],"summary":"ลบเอกสาร = งานชนิด delete (สถานะ deleted + ถอดออกจากดัชนีค้นหา); ตอบ { jobId }","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/knowledge-base/{id}/chunks":{"get":{"tags":["Admin — Knowledge Base"],"summary":"chunks ของเอกสาร: ordinal, heading, เล่ม/ข้อ/หน้า, tokenCount, oversized, content","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"page","in":"query","required":false,"description":"number (default 1)","schema":{"type":"string"}},{"name":"pageSize","in":"query","required":false,"description":"number ≤100 (default 20)","schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/knowledge-base/reindex":{"post":{"tags":["Admin — Knowledge Base"],"summary":"ทำดัชนีซ้ำจากไฟล์ต้นฉบับ: ระบุ documentIds = reindex_selected, ไม่ระบุ = reindex_all; ตอบ { jobId }","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"documentIds":{"description":"string[] (optional — ว่าง = ทุกเอกสารที่มีไฟล์ต้นฉบับ)"}}}}}},"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/knowledge-base/jobs":{"get":{"tags":["Admin — Knowledge Base"],"summary":"งานนำเข้า/ทำดัชนี 50 รายการล่าสุด พร้อมจำนวนสำเร็จ/ล้มเหลว","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/knowledge-base/jobs/{id}":{"get":{"tags":["Admin — Knowledge Base"],"summary":"รายละเอียดงาน: items (stage, status, errorMsg, chunkCount, durationMs, fileName, เอกสาร) + รายการที่ล้มเหลว","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/knowledge-base/jobs/{id}/retry-failed":{"post":{"tags":["Admin — Knowledge Base"],"summary":"รันซ้ำเฉพาะ item ที่ล้มเหลวของงาน","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/knowledge-base/coverage":{"get":{"tags":["Admin — Knowledge Base"],"summary":"ความครอบคลุมเทียบ TOR ภาคผนวก ข (มมร. 91 เล่ม: เล่มที่มีข้อมูล, %) + สถิติเอกสาร/chunks ตาม docType/ปิฎก/ฉบับ + เล่มฉบับหลวงที่มี","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/evaluation/datasets":{"get":{"tags":["Admin — Evaluation Datasets"],"summary":"รายการชุดทดสอบ: จำนวนข้อ, version, เกณฑ์ขั้นต่ำ, ค่ารับประกัน, expectedCount, run ล่าสุดที่เสร็จ และ run ที่กำลังทำงาน","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]},"post":{"tags":["Admin — Evaluation Datasets"],"summary":"สร้างชุดทดสอบ (รหัสไม่ซ้ำ → 409)","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"description":"string"},"kind":{"description":"accuracy | judge | retrieval | guardrail"},"benchmarkCode":{"description":"string (A–Z, 0–9, -, _)"},"threshold":{"description":"number (0–1 หรือ 0–3 สำหรับ judge)"},"guaranteed":{"description":"number (ไม่บังคับ — ค่าเริ่มต้น = threshold)"},"expectedCount":{"description":"number"}}}}}},"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/evaluation/datasets/{id}":{"get":{"tags":["Admin — Evaluation Datasets"],"summary":"รายละเอียดชุดทดสอบ","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]},"patch":{"tags":["Admin — Evaluation Datasets"],"summary":"แก้ชื่อ / เกณฑ์ขั้นต่ำ / ค่ารับประกัน (สำเนาไปที่ config eval.guaranteed) / expectedCount + audit","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"description":"string"},"threshold":{"description":"number"},"guaranteed":{"description":"number"},"expectedCount":{"description":"number"}}}}}},"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]},"delete":{"tags":["Admin — Evaluation Datasets"],"summary":"ลบชุดทดสอบ — ได้เฉพาะชุดที่ยังไม่มี run (409 DATASET_HAS_RUNS)","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/evaluation/datasets/{id}/items":{"get":{"tags":["Admin — Evaluation Datasets"],"summary":"รายการข้อทดสอบ (หน้าละ 50)","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"page","in":"query","required":false,"description":"เลขหน้า (เริ่ม 1)","schema":{"type":"string"}},{"name":"q","in":"query","required":false,"description":"ค้นในคำถาม / เฉลย / level","schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]},"post":{"tags":["Admin — Evaluation Datasets"],"summary":"เพิ่มข้อทดสอบ → dataset.version + 1 (ก.5.2.4)","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"ordinal":{"description":"number (ไม่บังคับ — ค่าเริ่มต้น = ข้อถัดไป)"},"question":{"description":"string"},"choices":{"description":"string[] | null (ปรนัย)"},"expectedAnswer":{"description":"string | null (เฉลย: label ตัวเลือก หรือข้อความ)"},"expectedRefs":{"description":"(string | { volume, item })[] | null (Recall@5: chunkId, \"เล่ม/ข้อ\" หรือคู่ volume/item)"},"expectRefusal":{"description":"boolean (guardrail)"},"level":{"description":"string | null (ตรี | โท | เอก หรือประเภทการโจมตี)"}}}}}},"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/evaluation/datasets/{id}/items/{itemId}":{"patch":{"tags":["Admin — Evaluation Datasets"],"summary":"แก้ไขข้อทดสอบ → dataset.version + 1","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"itemId","in":"path","required":true,"schema":{"type":"string"}},{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"ordinal":{"description":"number (ไม่บังคับ — ค่าเริ่มต้น = ข้อถัดไป)"},"question":{"description":"string"},"choices":{"description":"string[] | null (ปรนัย)"},"expectedAnswer":{"description":"string | null (เฉลย: label ตัวเลือก หรือข้อความ)"},"expectedRefs":{"description":"(string | { volume, item })[] | null (Recall@5: chunkId, \"เล่ม/ข้อ\" หรือคู่ volume/item)"},"expectRefusal":{"description":"boolean (guardrail)"},"level":{"description":"string | null (ตรี | โท | เอก หรือประเภทการโจมตี)"}}}}}},"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]},"delete":{"tags":["Admin — Evaluation Datasets"],"summary":"ลบข้อทดสอบ (พร้อมผลรายข้อของ run เก่าที่อ้างถึง) → dataset.version + 1","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"itemId","in":"path","required":true,"schema":{"type":"string"}},{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/evaluation/datasets/{id}/items/import":{"post":{"tags":["Admin — Evaluation Datasets"],"summary":"นำเข้าข้อทดสอบจาก CSV (multipart `file` + `mode` หรือ JSON) หัวตาราง ordinal,question,choices,expected_answer,expected_refs,expect_refusal,level → dataset.version + 1","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"csv":{"description":"string (เนื้อหา CSV)"},"mode":{"description":"append (ค่าเริ่มต้น) | replace"}}}}}},"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/evaluation/datasets/{id}/items/template":{"get":{"tags":["Admin — Evaluation Datasets"],"summary":"ดาวน์โหลดแม่แบบ CSV (หัวตาราง + ตัวอย่าง 1 แถวตามชนิดชุด)","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/evaluation/runs":{"post":{"tags":["Admin — Evaluation Runs"],"summary":"สั่งประเมิน 1 ชุดแบบ async — บันทึก prompt version + dataset version + audit evaluation_run","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"datasetId":{"description":"string"},"label":{"description":"baseline | acceptance | adhoc (ค่าเริ่มต้น adhoc)"},"qaPromptVersion":{"description":"number (ไม่บังคับ — ใช้ qa-persona เวอร์ชันที่ระบุแทนเวอร์ชัน active)"}}}}}},"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]},"get":{"tags":["Admin — Evaluation Runs"],"summary":"รายการ run (หน้าละ 20) พร้อมความคืบหน้า = ผลรายข้อที่บันทึกแล้ว / จำนวนข้อ","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[{"name":"datasetId","in":"query","required":false,"description":"กรองตามชุดทดสอบ","schema":{"type":"string"}},{"name":"page","in":"query","required":false,"description":"เลขหน้า (เริ่ม 1)","schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/evaluation/runs/{id}":{"get":{"tags":["Admin — Evaluation Runs"],"summary":"สรุป run (ชุด/เวอร์ชัน, prompt, model, judge, คะแนน, ผ่านเกณฑ์ TOR และค่ารับประกัน) + ผลรายข้อ","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"onlyFailed","in":"query","required":false,"description":"1 = เฉพาะข้อที่ไม่ผ่าน","schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/evaluation/compare":{"get":{"tags":["Admin — Evaluation Runs"],"summary":"เปรียบเทียบ 2 รอบของชุดเดียวกัน: เวอร์ชัน prompt/ชุด/โมเดล + ผลรายข้อ (จับคู่ด้วยเลขข้อ) + delta (400 ถ้าคนละชุด)","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[{"name":"runA","in":"query","required":false,"description":"run id รอบที่ 1","schema":{"type":"string"}},{"name":"runB","in":"query","required":false,"description":"run id รอบที่ 2","schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/evaluation/thresholds":{"get":{"tags":["Admin — Evaluation Reports"],"summary":"ตาราง benchmark 7 ชุด: เกณฑ์ขั้นต่ำ TOR, ค่ารับประกัน, คะแนนล่าสุด, ผ่าน/ไม่ผ่าน (ก.5.3, 16.2)","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/evaluation/security-report":{"post":{"tags":["Admin — Evaluation Reports"],"summary":"รัน GR-1 + GR-2 + ชุด Prompt Injection ภายใน (สร้างชุด INJ ให้ถ้ายังไม่มี) แบบ async → { status: running, runs }","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]},"get":{"tags":["Admin — Evaluation Reports"],"summary":"ผลล่าสุดของรายงาน AI Security: อัตราการป้องกันต่อชุดและต่อประเภทการโจมตี เทียบเกณฑ์ 80% + รายการที่ไม่ผ่าน","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/evaluation/export":{"post":{"tags":["Admin — Evaluation Reports"],"summary":"สร้างรายงาน markdown จาก run จริงและเขียนลง docs/deliverables (baseline-evaluation-report.md / guardrail-security-report.md)","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"report":{"description":"baseline | guardrail"}}}}}},"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/dashboard/usage":{"get":{"tags":["Admin — Dashboard"],"summary":"Dashboard การใช้งาน: บัญชีทั้งหมด/ใหม่, DAU, MAU, sessions, queries, เฉลี่ยคำถามต่อบทสนทนา แยก QA/Dhamma Talk + series รายวัน + ช่วงก่อนหน้า","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[{"name":"range","in":"query","required":false,"description":"day|week|month|year|custom (ค่าเริ่มต้น week)","schema":{"type":"string"}},{"name":"from","in":"query","required":false,"description":"YYYY-MM-DD (เมื่อ range=custom)","schema":{"type":"string"}},{"name":"to","in":"query","required":false,"description":"YYYY-MM-DD (เมื่อ range=custom)","schema":{"type":"string"}},{"name":"compare","in":"query","required":false,"description":"1 = เทียบช่วงก่อนหน้าที่ยาวเท่ากัน (+ % delta)","schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/dashboard/tokens":{"get":{"tags":["Admin — Dashboard"],"summary":"Dashboard โทเคน: input/thinking/output รายวัน (รายเดือนเมื่อ range=year) เทียบเพดาน, เฉลี่ยต่อคำถาม/บทสนทนาเทียบเป้า 10k/50k, ค่าใช้จ่ายประมาณการ (อัตราปัจจุบัน), Top 10 ผู้ใช้, ยอด 24 ชม.","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[{"name":"range","in":"query","required":false,"description":"day|week|month|year|custom (ค่าเริ่มต้น week)","schema":{"type":"string"}},{"name":"from","in":"query","required":false,"description":"YYYY-MM-DD (เมื่อ range=custom)","schema":{"type":"string"}},{"name":"to","in":"query","required":false,"description":"YYYY-MM-DD (เมื่อ range=custom)","schema":{"type":"string"}},{"name":"compare","in":"query","required":false,"description":"1 = เทียบช่วงก่อนหน้าที่ยาวเท่ากัน (+ % delta)","schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/dashboard/feedback":{"get":{"tags":["Admin — Dashboard"],"summary":"Dashboard ข้อเสนอแนะ: จำนวน 👍/👎, สัดส่วน, series รายวัน","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[{"name":"range","in":"query","required":false,"description":"day|week|month|year|custom (ค่าเริ่มต้น week)","schema":{"type":"string"}},{"name":"from","in":"query","required":false,"description":"YYYY-MM-DD (เมื่อ range=custom)","schema":{"type":"string"}},{"name":"to","in":"query","required":false,"description":"YYYY-MM-DD (เมื่อ range=custom)","schema":{"type":"string"}},{"name":"compare","in":"query","required":false,"description":"1 = เทียบช่วงก่อนหน้าที่ยาวเท่ากัน (+ % delta)","schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/alerts":{"get":{"tags":["Admin — Alerts"],"summary":"ประวัติการแจ้งเตือน (AlertEmailLog)","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[{"name":"type","in":"query","required":false,"description":"threshold_tokens|threshold_cost|auto_unavailable|error_rate|ingestion_failed|system","schema":{"type":"string"}},{"name":"page","in":"query","required":false,"description":"number (หน้าละ 20)","schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/alerts/test":{"post":{"tags":["Admin — Alerts"],"summary":"ส่งการแจ้งเตือนทดสอบ (type system)","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/defect-log":{"get":{"tags":["Admin — Ops"],"summary":"รายการ Defect + สรุป (High/Critical คงค้าง, เกินกำหนด)","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[{"name":"severity","in":"query","required":false,"description":"critical|high|medium|low","schema":{"type":"string"}},{"name":"status","in":"query","required":false,"description":"open|in_progress|resolved|closed","schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]},"post":{"tags":["Admin — Ops"],"summary":"บันทึก Defect — คำนวณ slaHours (critical/high 24, medium 48, low 80 ชม.ทำการ) และ slaDeadline","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"module":{"description":"string"},"description":{"description":"string"},"severity":{"description":"critical|high|medium|low"},"reportedAt":{"description":"ISO datetime (optional; เวลาที่มหาวิทยาลัยแจ้ง)"},"reportedBy":{"description":"string (optional)"},"assignedTo":{"description":"string (optional)"},"foundInPhase":{"description":"string (optional)"}}}}}},"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/defect-log/{id}":{"get":{"tags":["Admin — Ops"],"summary":"รายละเอียด Defect","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]},"patch":{"tags":["Admin — Ops"],"summary":"เปลี่ยนสถานะ/แก้ไข Defect (resolved ของ high/critical ต้องมี resolutionNote; confirm → confirmedAt, overdueHours, penaltyEstimate)","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"status":{"description":"open|in_progress|resolved|closed (optional)"},"resolutionNote":{"description":"string (optional; บันทึกการแก้ไข + มาตรการป้องกันซ้ำ)"},"assignedTo":{"description":"string (optional)"},"severity":{"description":"critical|high|medium|low (optional)"},"module":{"description":"string (optional)"},"description":{"description":"string (optional)"},"foundInPhase":{"description":"string (optional)"},"confirm":{"description":"true = มหาวิทยาลัยยืนยันผล (optional)"}}}}}},"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/defect-log/export":{"get":{"tags":["Admin — Ops"],"summary":"ส่งออก Defect Log เป็น CSV","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[{"name":"format","in":"query","required":false,"description":"csv","schema":{"type":"string"}},{"name":"severity","in":"query","required":false,"description":"critical|high|medium|low","schema":{"type":"string"}},{"name":"status","in":"query","required":false,"description":"open|in_progress|resolved|closed","schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/sla-report":{"get":{"tags":["Admin — Ops"],"summary":"รายงาน SLA: Availability, latency p50/p95, TTFT p95, error rate เทียบเกณฑ์ TOR 12.1–12.2 + Defect เทียบ SLA","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[{"name":"range","in":"query","required":false,"description":"current-session|month","schema":{"type":"string"}},{"name":"month","in":"query","required":false,"description":"YYYY-MM (เมื่อ range=month; ค่าเริ่มต้น = เดือนปัจจุบัน)","schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/sla-report/export":{"get":{"tags":["Admin — Ops"],"summary":"รายงาน SLA รายเดือน (markdown) + เขียน docs/deliverables/sla-monthly-report.md","description":"สิทธิ์: ADMIN หรือ SUPER_ADMIN (+ IP allowlist)","parameters":[{"name":"range","in":"query","required":false,"description":"current-session|month","schema":{"type":"string"}},{"name":"month","in":"query","required":false,"description":"YYYY-MM (เมื่อ range=month; ค่าเริ่มต้น = เดือนปัจจุบัน)","schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/data-destruction":{"get":{"tags":["Admin — Ops"],"summary":"จำนวนข้อมูลที่จะถูกลบต่อ scope (ไม่ลบจริง)","description":"สิทธิ์: SUPER_ADMIN เท่านั้น (+ IP allowlist)","parameters":[],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]},"post":{"tags":["Admin — Ops"],"summary":"ลบ/ทำลายข้อมูลตาม scope + ออกหนังสือรับรอง (AuditLog ไม่ถูกลบ)","description":"สิทธิ์: SUPER_ADMIN เท่านั้น (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"confirmText":{"description":"\"ยืนยันการลบ\""},"scopes":{"description":"(\"uploads\"|\"conversations\"|\"tokenUsage\"|\"evaluationResults\"|\"users\")[]"}}}}}},"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}},"/api/admin/backup":{"get":{"tags":["Admin — Ops"],"summary":"รายการไฟล์สำรอง + คำสั่งกู้คืนที่ต้องรันเอง","description":"สิทธิ์: SUPER_ADMIN เท่านั้น (+ IP allowlist)","parameters":[],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]},"post":{"tags":["Admin — Ops"],"summary":"สร้างไฟล์สำรองฐานข้อมูล (scripts/backup-db.sh)","description":"สิทธิ์: SUPER_ADMIN เท่านั้น (+ IP allowlist) · ต้องส่ง header x-csrf-token","parameters":[{"name":"x-csrf-token","in":"header","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"สำเร็จ","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Ok"}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"}},"security":[{"sessionCookie":[]}]}}},"components":{"securitySchemes":{"sessionCookie":{"type":"apiKey","in":"cookie","name":"mbu_session"}},"schemas":{"Ok":{"type":"object","properties":{"ok":{"type":"boolean","example":true},"data":{}}},"Error":{"type":"object","properties":{"ok":{"type":"boolean","example":false},"error":{"type":"object","properties":{"code":{"type":"string"},"message":{"type":"string"}}}}}},"responses":{"Error":{"description":"ข้อผิดพลาด","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}}