KB-1DA8 rev 2
IU Agent Front-Door Context
2 min read Revision 2
iuagentcontextfn_iu_savefn_iu_commentnotification
IU Agent Front-Door Context
AI/Agent: hướng dẫn hệ thống Information Unit. Không cần nhớ quy trình.
Tạo hoặc sửa nội dung
SELECT fn_iu_save('địa-chỉ', 'nội dung', 'actor');
- Địa chỉ mới → phiên bản 1 chính thức.
- Địa chỉ đã có → nháp chờ duyệt (policy=require_review).
- Nội dung giống → no_change.
fn_iu_save(addr, body, actor, title, reason, 'draft')→ luôn nháp.
Góp ý
SELECT fn_iu_comment('địa-chỉ', 'actor', 'comment', 'general', 'agent', '{}'::jsonb);
Tự do, không phê duyệt.
Phê duyệt nháp (reviewer)
SELECT fn_iu_apply_edit_draft('draft-id', 'reviewer', 'ghi chú');
Kiểm tra hộp thư (notification)
-- Có gì mới chưa đọc?
SELECT * FROM fn_iu_unread('actor');
-- Lọc theo stream: 'comment', 'review', 'update'
SELECT * FROM fn_iu_unread('actor', 'review');
-- Đánh dấu đã xem
SELECT fn_iu_mark_read(ARRAY['event-id-1','event-id-2']::uuid[], 'actor');
-- Bảng tổng hợp: ai đọc gì, ai chưa đọc
SELECT * FROM fn_iu_notification_board('actor');
Read-state semantics
- Per-actor: GPT đọc rồi chỉ ẩn với GPT. Opus/User chưa đọc vẫn thấy.
- Implicit self-read: Opus tạo event → Opus mặc nhiên đã đọc, không cần báo lại.
- read_status_source:
implicit_self(tự tạo) |explicit_read(đã mark) |unread(chưa đọc). - latest_readers: board trả danh sách 5 actor gần nhất đã đọc.
- Actionable board: draft đã applied/stale thì ẩn khỏi review inbox. History vẫn lưu.
UI boundary
PG là source of truth. Directus expose PG. Nuxt chỉ đọc từ Directus qua existing assembled screens/components. Không thêm Nuxt business logic. Không kết nối PG trực tiếp từ Nuxt.
Quy tắc
- KHÔNG ghi trực tiếp vào information_unit / unit_version.
- Nháp chưa apply ≠ bản chính.
- Mọi status trả về có guidance + next_action.
- Actor nên ổn định: gpt, opus, agent:codex, reviewer:gpt, user:huyen.
- Rollback policy phải qua reviewed pack. Không raw UPDATE.
- Hermes production chưa bật.