feat(action): direct accept/reject buttons — no mirror tab needed, Extension /api/action endpoint

This commit is contained in:
2026-03-08 01:32:29 +09:00
parent 8568985e7a
commit 79c2b1b6d9
7 changed files with 83 additions and 23 deletions

View File

@@ -314,12 +314,34 @@ class ChatPanel {
for (const btn of (msg.buttons || [])) {
const el = document.createElement('button');
el.className = 'msg-action-btn msg-action-primary';
el.className = btn.variant === 'danger' ? 'msg-action-btn msg-action-danger' : 'msg-action-btn msg-action-primary';
el.textContent = btn.label || btn;
el.style.cursor = 'pointer';
// action 기반 처리
if (btn.action === 'switch_mirror') {
// api_call: 직접 API 호출 (승인/거절 등)
if (btn.action === 'api_call' && btn.endpoint) {
el.addEventListener('click', async () => {
el.disabled = true;
el.textContent = '처리 중...';
try {
const res = await fetch(btn.endpoint, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(btn.body || {}),
});
if (res.ok) {
el.textContent = '✓ 완료';
// 모든 형제 버튼 비활성화
div.querySelectorAll('button').forEach(b => { b.disabled = true; });
} else {
const err = await res.json().catch(() => ({}));
el.textContent = `실패: ${err.error || res.status}`;
}
} catch (e) {
el.textContent = `오류: ${e.message}`;
}
});
} else if (btn.action === 'switch_mirror') {
el.addEventListener('click', () => {
document.getElementById('tabMirror')?.click();
});