AiHumanDraftEditor

Molecule

The AI's draft beside the human's text, diffed by words, with accept and reject per change and accept all, drawn with the same DOM as kui-react. The text stays the human's until they accept. A badge says the draft is AI-generated. Changes are marked by shape (strike and underline) and a number shown in both panels, and every button names its change. The server draws both panels as they read; a small idempotent script (`modules/ui/AiHumanDraftEditor/scripts/draft-editor.js`, inlined once per page after `draft-model.js` and `draft-view.js`) keeps the state in the browser: accept, reject, reconsider, keep mine, accept all, the edit toggle and its textarea, the hover and focus highlight and the polite announcements. React's callbacks are bubbling DOM events on the root: `kui:draft-accept-hunk` { hunk }, `kui:draft-reject-hunk` { hunk }, `kui:draft-accept-all`, `kui:draft-change` { value } and `kui:draft-rejected-change` { keys } (the last two are cancelable: call `preventDefault()` to refuse the change and answer with `KuiAiHumanDraftEditor.setValue(root, text)` / `setRejected(root, keys)`). A `rejected` local is controlled as in React; `defaultRejected` starts uncontrolled. `value` is applied by the script itself, where React's is always controlled.

Review changes

Preview

AI draft

AI-generated by model-a
We identified elevated errors on checkout caused by a payment gateway timeout. A fix is rolling out. Next update in 15 minutes.

Your text

We saw elevated errors on checkout. The payment gateway timed out. We are working on it.

4 changes pending

Accept or reject a change.

Code
<%- include('modules/ui/AiHumanDraftEditor', { aiDraft: draft, value: text, model: 'model-a' }) %>
<script>
  root.addEventListener('kui:draft-change', function (e) {
    // e.detail = { value }: the text after a change was accepted or the person typed (preventDefault() refuses it)
    save(e.detail.value);
  });
  root.addEventListener('kui:draft-rejected-change', function (e) { /* e.detail = { keys } */ });
</script>

Read only

Preview

AI draft

AI-generated
We identified elevated errors on checkout caused by a payment gateway timeout. A fix is rolling out. Next update in 15 minutes.

Your text

We saw elevated errors on checkout. The payment gateway timed out. We are working on it.

4 changes pending

Code
<%- include('modules/ui/AiHumanDraftEditor', { aiDraft: draft, value: text, readOnly: true }) %>
Source modules/ui/AiHumanDraftEditor.ejs