Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

feat: add Agora human HUD, action controls, and post form UI

nirholas985119f847e7
diff --git a/src/agora/actions.js b/src/agora/actions.js
new file mode 100644
index 000000000..64ccbfd2d
--- /dev/null
+++ b/src/agora/actions.js
@@ -0,0 +1,62 @@
+// Agora — human citizen action client (Task 08). The authenticated half of the
+// Agora frontend: turning UI intents into real, server-side, on-chain AgenC
+// operations via POST /api/agora/act. Reads live in src/agora/api.js (public,
+// no-auth); this module owns everything that mutates and therefore must carry
+// the session cookie + a CSRF token + an Idempotency-Key. All of that is
+// handled by apiFetch (src/api.js), the platform's one sanctioned mutation path.
+
+import { apiFetch } from '../api.js';
+
+// A fresh Idempotency-Key per attempt so a retried click never double-escrows.
+function idemKey() {
+ try { return crypto.randomUUID(); } catch { return `${Date.now()}-${Math.random().toString(36).slice(2)}`; }
+}
+
+async function parse(res) {
+ let body = null;
+ try { body = await res.json(); } catch { /* non-JSON body */ }
+ if (!res.ok || body?.error) {
+ const err = new Error(body?.error_description || body?.error || `HTTP ${res.status}`);
+ err.status = res.status;
+ err.code = body?.error || null;
+ err.detail = body || null;
+ throw err;
+ }
+ return body;
+}
+
+/** The signed-in user, or null when signed out. Never throws on a 401. */
+export async function getMe() {
+ const res = await apiFetch('/api/me', { method: 'GET', allowAnonymous: true });
+ if (res.status === 401) return null;
+ const body = await parse(res);
+ return body?.user || null;
+}
+
+async function act(action, payload = {}) {
+ const res = await apiFetch('/api/agora/act', {
+ method: 'POST',
+ allowAnonymous: true, // a 401 here is an answer we surface, not a redirect
+ headers: { 'content-type': 'application/json', 'idempotency-key': idemKey() },
+ body: JSON.stringify({ action, ...payload }),
+ });
+ return parse(res);
+}
+
+/** Join Agora: upsert the human citizen + custodial wallet, place in the Commons. */
+export const join = (payload = {}) => act('join', payload);
+
+/** Post a bounty: escrow the reward on AgenC for a target profession. */
+export const postTask = (payload) => act('post-task', payload);
+
+/** Hire a citizen: a bounty routed to them by profession + a reputation they clear. */
+export const hire = (payload) => act('hire', payload);
+
+/** Claim an open on-chain task as the worker yourself. */
+export const claim = (payload) => act('claim', payload);
+
+/** Submit a real proof (sha256 of your deliverable) for a claimed task → earn. */
+export const complete = (payload) => act('complete', payload);
+
+/** Leave a real on-chain attestation for a citizen. */
+export const vouch = (payload) => act('vouch', payload);
diff --git a/src/agora/humans.css.js b/src/agora/humans.css.js
new file mode 100644
index 000000000..5098e43a0
--- /dev/null
+++ b/src/agora/humans.css.js
@@ -0,0 +1,140 @@
+// Styles for the Task 08 human-citizen layer, shipped as a string and injected
+// once by me-hud.js. Self-contained + namespaced under .agora-h-* so it can't
+// collide with the scaffold (agora.css) or the other Agora layers. Reuses the
+// page's shared .agora-btn / .agora-btn-primary for buttons. Honours
+// prefers-reduced-motion and gives every interactive element a focus ring.
+
+let _injected = false;
+export function injectHumansCss() {
+ if (_injected || typeof document === 'undefined') return;
+ _injected = true;
+ const style = document.createElement('style');
+ style.id = 'agora-humans-css';
+ style.textContent = HUMANS_CSS;
+ document.head.appendChild(style);
+}
+
+const HUMANS_CSS = `
+.agora-h-root {
+ --h-bg: rgba(12, 15, 22, 0.82);
+ --h-border: rgba(255, 255, 255, 0.12);
+ --h-text: #e8eef7;
+ --h-dim: #93a1b5;
+ --h-accent: #6ea8ff;
+ --h-ok: #36d399;
+ --h-err: #ff6b6b;
+ --h-human: #7ee0a6;
+ font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;
+ color: var(--h-text);
+}
+.agora-h-root *, .agora-h-root *::before { box-sizing: border-box; }
+
+/* ── Dock (bottom-left) ──────────────────────────────────────────────────── */
+#agora-humans-dock {
+ position: fixed; left: 16px; bottom: 16px; z-index: 60;
+ display: flex; align-items: stretch; gap: 8px;
+ max-width: min(92vw, 420px);
+}
+@media (max-width: 640px) { #agora-humans-dock { left: 8px; right: 8px; bottom: 8px; max-width: none; } }
+
+.agora-h-card {
+ display: flex; align-items: center; gap: 10px;
+ background: var(--h-bg); border: 1px solid var(--h-border);
+ border-radius: 14px; padding: 10px 12px;
+ backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
+ box-shadow: 0 8px 32px rgba(0,0,0,0.5);
+ min-width: 0;
+}
+.agora-h-dot {
+ width: 30px; height: 30px; border-radius: 50%; flex: 0 0 auto;
+ background: var(--h-human); display: grid; place-items: center;
+ color: #07120c; font-weight: 700; font-size: 13px; overflow: hidden;
+}
+.agora-h-dot img { width: 100%; height: 100%; object-fit: cover; }
+.agora-h-meta { min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
+.agora-h-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
+.agora-h-line { font-size: 11px; color: var(--h-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
+.agora-h-status-pill {
+ display: inline-block; width: 7px; height: 7px; border-radius: 50%;
+ background: var(--h-dim); margin-right: 5px; vertical-align: middle;
+}
+.agora-h-status-pill.is-busy { background: var(--h-accent); }
+.agora-h-status-pill.is-idle { background: var(--h-ok); }
+.agora-h-dock-btns { display: flex; gap: 6px; align-items: center; }
+
+/* Shared button look (falls back if .agora-btn is unstyled on this page). */
+.agora-h-root .agora-btn, .agora-h-form .agora-btn {
+ font: inherit; cursor: pointer; border-radius: 10px;
+ padding: 8px 12px; border: 1px solid var(--h-border);
+ background: rgba(255,255,255,0.06); color: var(--h-text);
+ transition: background .15s ease, transform .1s ease;
+}
+.agora-h-root .agora-btn:hover { background: rgba(255,255,255,0.12); }
+.agora-h-root .agora-btn:active { transform: translateY(1px); }
+.agora-h-root .agora-btn-primary, .agora-h-form .agora-btn-primary {
+ background: var(--h-accent); border-color: transparent; color: #061018; font-weight: 600;
+}
+.agora-h-root .agora-btn-primary:hover { background: #84b6ff; }
+.agora-h-root .agora-btn:disabled { opacity: .55; cursor: progress; }
+.agora-h-root :focus-visible, .agora-h-form :focus-visible {
+ outline: 2px solid var(--h-accent); outline-offset: 2px;
+}
+.agora-h-btn-sm { padding: 6px 10px !important; font-size: 12px; }
+
+/* ── "You" drawer body sections ──────────────────────────────────────────── */
+.agora-h-section { margin: 0 0 18px; }
+.agora-h-section h3 { margin: 0 0 8px; font-size: 12px; letter-spacing: .04em; text-transform: uppercase; color: var(--h-dim); }
+.agora-h-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
+.agora-h-stat { background: rgba(255,255,255,0.04); border: 1px solid var(--h-border); border-radius: 10px; padding: 8px 10px; }
+.agora-h-stat .k { font-size: 11px; color: var(--h-dim); display: block; }
+.agora-h-stat .v { font-size: 16px; font-weight: 600; }
+.agora-h-wallet { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--h-dim); flex-wrap: wrap; }
+.agora-h-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
+.agora-h-list li {
+ display: flex; align-items: center; justify-content: space-between; gap: 8px;
+ background: rgba(255,255,255,0.03); border: 1px solid var(--h-border);
+ border-radius: 8px; padding: 7px 10px; font-size: 13px;
+}
+.agora-h-list button { font: inherit; }
+.agora-h-empty { font-size: 13px; color: var(--h-dim); }
+
+/* ── Compose form ────────────────────────────────────────────────────────── */
+.agora-h-form { display: flex; flex-direction: column; gap: 12px; }
+.agora-h-field { display: flex; flex-direction: column; gap: 5px; }
+.agora-h-field-label { font-size: 11px; color: var(--h-dim); letter-spacing: .03em; }
+.agora-h-input {
+ font: inherit; color: var(--h-text); background: rgba(255,255,255,0.05);
+ border: 1px solid var(--h-border); border-radius: 9px; padding: 9px 11px; width: 100%;
+}
+.agora-h-input:focus { border-color: var(--h-accent); outline: none; }
+.agora-h-textarea { resize: vertical; min-height: 84px; }
+.agora-h-row { display: grid; grid-template-columns: 1.3fr 0.8fr 0.8fr; gap: 8px; }
+.agora-h-reward { display: flex; align-items: center; gap: 6px; }
+.agora-h-unit { font-size: 12px; color: var(--h-dim); }
+.agora-h-net { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--h-dim); }
+.agora-h-hint { font-size: 12px; color: var(--h-dim); }
+.agora-h-actions { display: flex; gap: 8px; }
+.agora-h-status { font-size: 12.5px; min-height: 1em; }
+.agora-h-status.is-error { color: var(--h-err); }
+.agora-h-status.is-ok { color: var(--h-ok); }
+.agora-h-link { color: var(--h-accent); }
+.agora-h-muted { color: var(--h-dim); }
+
+/* ── Toasts ──────────────────────────────────────────────────────────────── */
+#agora-humans-toasts {
+ position: fixed; right: 16px; bottom: 16px; z-index: 70;
+ display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
+ pointer-events: none;
+}
+.agora-h-toast {
+ background: var(--h-bg); border: 1px solid var(--h-border); color: var(--h-text);
+ border-radius: 10px; padding: 10px 14px; font-size: 13px; max-width: 360px;
+ box-shadow: 0 8px 32px rgba(0,0,0,0.5); backdrop-filter: blur(12px);
+ animation: agora-h-in .25s ease; pointer-events: auto;
+}
+.agora-h-toast.is-error { border-color: rgba(255,107,107,0.5); }
+.agora-h-toast.is-ok { border-color: rgba(54,211,153,0.5); }
+.agora-h-toast a { color: var(--h-accent); }
+@keyframes agora-h-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
+@media (prefers-reduced-motion: reduce) { .agora-h-toast { animation: none; } }
+`;
diff --git a/src/agora/me-hud.js b/src/agora/me-hud.js
new file mode 100644
index 000000000..61aa656ca
--- /dev/null
+++ b/src/agora/me-hud.js
@@ -0,0 +1,348 @@
+// Agora — the human "you" layer (Task 08). A self-mounting overlay that turns a
+// signed-in visitor into a first-class citizen of the Commons: it joins them
+// (provisioning a custodial wallet + placing their avatar in the world via the
+// agora_citizens projection), then exposes every human action — post a bounty,
+// hire a citizen, claim + complete a task yourself, and vouch — through one
+// accessible HUD + drawer.
+//
+// Decoupled by design (the trust-surface precedent): it never imports the
+// scaffold (agora-world.js) or the economy/trust layers. It only:
+// • reads context from window events the other layers already emit
+// 'agora:open-job' {detail:{task}} → the job you're looking at
+// 'agora:open-passport' {detail:{agentPda}} → the citizen you're looking at
+// • re-emits 'agora:open-job' after a claim/complete so the open job panel
+// refreshes itself.
+// Signed-out visitors keep the world fully watchable and get an honest
+// "sign in to join the Commons" CTA — nothing is gated behind auth except acting.
+
+import { Panel, h, clear, copyChip } from './panel.js';
+import { fetchPassport } from './api.js';
+import { injectHumansCss } from './humans.css.js';
+import { getMe, join, postTask, hire, claim, complete, vouch } from './actions.js';
+
+const state = {
+ loading: true,
+ user: null, // signed-in user (or null)
+ me: null, // citizen HUD payload from join() (or null if not joined)
+ job: null, // { taskPda, cluster, title } — the job currently open
+ subject: null, // { id, name } — the citizen currently open (for hire/vouch)
+};
+
+let dock, toasts, panel, root;
+
+function boot() {
+ if (typeof document === 'undefined') return;
+ injectHumansCss();
+ root = h('div', { class: 'agora-h-root' });
+ dock = h('div', { id: 'agora-humans-dock' });
+ toasts = h('div', { id: 'agora-humans-toasts', 'aria-live': 'polite' });
+ root.append(dock, toasts);
+ document.body.appendChild(root);
+
+ panel = new Panel({ id: 'agora-you' }).mount(document.body);
+
+ window.addEventListener('agora:open-job', onOpenJob);
+ window.addEventListener('agora:open-passport', onOpenPassport);
+
+ renderDock();
+ refreshMe(true);
+}
+
+// ── data ──────────────────────────────────────────────────────────────────────
+
+async function refreshMe(autoJoin = false) {
+ try {
+ state.user = await getMe();
+ } catch {
+ state.user = null;
+ }
+ state.loading = false;
+
+ if (state.user && (autoJoin || state.me)) {
+ // Joining is free (no funds move) + idempotent — the DoD's "first
+ // authenticated visit upserts a human citizen + places their avatar".
+ try {
+ const res = await join({});
+ state.me = res?.me || state.me;
+ // The new citizen row now exists; nudge the world to repopulate.
+ window.dispatchEvent(new CustomEvent('agora:citizens-changed'));
+ } catch (err) {
+ // Auth ok but join failed (e.g. endpoint not yet deployed) — keep the
+ // user, surface a Join button rather than silently degrading.
+ if (err?.status !== 401) console.warn('[agora] join failed:', err?.message);
+ }
+ }
+ renderDock();
+ if (panel?.isOpen) renderYou();
+}
+
+// ── dock ────────────────────────────────────────────────────────────────────
+
+function renderDock() {
+ clear(dock);
+ if (state.loading) { dock.style.display = 'none'; return; }
+ dock.style.display = 'flex';
+
+ if (!state.user) {
+ dock.appendChild(h('div', { class: 'agora-h-card' }, [
+ h('div', { class: 'agora-h-meta' }, [
+ h('span', { class: 'agora-h-name' }, ['Watching the Commons']),
+ h('span', { class: 'agora-h-line' }, ['Sign in to join, post bounties & earn $THREE']),
+ ]),
+ h('a', { class: 'agora-btn agora-btn-primary agora-h-btn-sm', href: `/login?next=${encodeURIComponent('/agora')}` }, ['Sign in to join']),
+ ]));
+ return;
+ }
+
+ if (!state.me) {
+ dock.appendChild(h('div', { class: 'agora-h-card' }, [
+ h('div', { class: 'agora-h-dot' }, [initial(state.user.display_name || state.user.handle)]),
+ h('div', { class: 'agora-h-meta' }, [
+ h('span', { class: 'agora-h-name' }, [state.user.display_name || 'three.ws citizen']),
+ h('span', { class: 'agora-h-line' }, ['Not yet a citizen']),
+ ]),
+ h('button', { class: 'agora-btn agora-btn-primary agora-h-btn-sm', type: 'button', onclick: () => refreshMe(true) }, ['Join Agora']),
+ ]));
+ return;
+ }
+
+ const me = state.me;
+ dock.appendChild(h('div', { class: 'agora-h-card' }, [
+ h('div', { class: 'agora-h-dot' }, me.avatarUrl ? [h('img', { src: me.avatarUrl, alt: '' })] : [initial(me.displayName)]),
+ h('div', { class: 'agora-h-meta' }, [
+ h('span', { class: 'agora-h-name' }, [me.displayName]),
+ h('span', { class: 'agora-h-line' }, [
+ h('span', { class: `agora-h-status-pill is-${me.status}` }),
+ statusLabel(me),
+ ]),
+ ]),
+ h('div', { class: 'agora-h-dock-btns' }, [
+ h('button', { class: 'agora-btn agora-btn-primary agora-h-btn-sm', type: 'button', onclick: () => openYou('post') }, ['Post bounty']),
+ h('button', { class: 'agora-btn agora-h-btn-sm', type: 'button', onclick: () => openYou() }, ['You ▸']),
+ ]),
+ ]));
+}
+
+function statusLabel(me) {
+ const bal = balanceText(me);
+ return `${cap(me.status)}${bal ? ' · ' + bal : ''}`;
+}
+
+function balanceText(me) {
+ if (!me?.balances) return '';
+ if (me.cluster === 'mainnet') return me.balances.three != null ? `${fmt(me.balances.three)} $THREE` : '';
+ return me.balances.sol != null ? `${fmt(me.balances.sol)} SOL` : '';
+}
+
+// ── "You" drawer ───────────────────────────────────────────────────────────
+
+function openYou(initialView) {
+ if (!state.me) { refreshMe(true); return; }
+ panel.open(document.activeElement);
+ renderYou(initialView);
+}
+
+function renderYou(view) {
+ const me = state.me;
+ panel.setHeader('You in Agora', `${cap(me.cluster)} · ${shortAddr(me.walletAddress)}`);
+
+ if (view === 'post') { renderPostView(); return; }
+
+ const sections = [];
+
+ // Status grid.
+ sections.push(section('Your standing', h('div', { class: 'agora-h-stats' }, [
+ stat('Status', cap(me.status)),
+ stat('Reputation', String(me.reputation ?? 0)),
+ stat('Posted', String(me.tasksPosted ?? 0)),
+ stat('Completed', String(me.tasksCompleted ?? 0)),
+ stat('Earned', me.cluster === 'mainnet' ? `${fmtAtomic(me.earnedThreeAtomic)} $THREE` : '—'),
+ stat('Balance', balanceText(me) || '—'),
+ ])));
+
+ // Wallet.
+ if (me.walletAddress) {
+ sections.push(section('Custodial wallet', h('div', { class: 'agora-h-wallet' }, [
+ copyChip(me.walletAddress, 'wallet address'),
+ h('span', {}, [me.cluster === 'devnet' ? 'Auto-funded with devnet SOL on first action.' : `Send $THREE here to fund bounties.`]),
+ ])));
+ }
+
+ // Post a bounty.
+ sections.push(section('Post work', h('div', {}, [
+ h('p', { class: 'agora-h-hint' }, ['Escrow a real bounty for any profession. It hits the board for an agent — or you — to fulfil.']),
+ h('button', { class: 'agora-btn agora-btn-primary', type: 'button', onclick: () => renderPostView() }, ['Compose a bounty']),
+ ])));
+
+ // Your open bounties.
+ const open = me.openPosted || [];
+ sections.push(section(`Your open bounties (${open.length})`, open.length
+ ? h('ul', { class: 'agora-h-list' }, open.map((t) => h('li', {}, [
+ h('span', {}, [`${cap(t.profession || 'task')} · ${t.rewardLabel || ''}`]),
+ h('button', { class: 'agora-btn agora-h-btn-sm', type: 'button', onclick: () => openJobByPda(t.taskPda) }, ['Open']),
+ ])))
+ : h('p', { class: 'agora-h-empty' }, ['No open bounties. Post one above.'])));
+
+ // Contextual: work the open job.
+ if (state.job?.taskPda) sections.push(renderJobSection());
+
+ // Contextual: vouch for the open citizen.
+ if (state.subject?.id && state.subject.id !== me.citizenId) sections.push(renderVouchSection());
+
+ panel.setBody(sections);
+}
+
+function renderPostView() {
+ panel.open(document.activeElement);
+ panel.setHeader('Post a bounty', 'Escrow a reward on AgenC — real, on-chain');
+ const form = buildComposeForm(null);
+ const back = h('button', { class: 'agora-btn agora-h-btn-sm', type: 'button', onclick: () => renderYou() }, ['‹ Back']);
+ panel.setBody([h('div', { class: 'agora-h-section' }, [back]), form]);
+}
+
+function buildComposeForm(hireTarget) {
+ // Lazy import keeps the form code out of the initial dock paint.
+ const placeholder = h('div', { class: 'agora-h-hint' }, ['Loading form…']);
+ import('./post-form.js').then(({ buildPostForm }) => {
+ const form = buildPostForm({
+ cluster: 'devnet',
+ hireTarget,
+ onSubmit: async (payload) => {
+ const res = hireTarget ? await hire(payload) : await postTask(payload);
+ toast(`${hireTarget ? 'Hired' : 'Bounty posted'} — ${res.reward?.label || ''}`, 'ok', res.explorerUrl);
+ await refreshMe();
+ window.dispatchEvent(new CustomEvent('agora:citizens-changed'));
+ return res;
+ },
+ });
+ placeholder.replaceWith(form);
+ }).catch((e) => { placeholder.textContent = `Could not load the form: ${e?.message || 'error'}`; });
+ return placeholder;
+}
+
+function renderJobSection() {
+ const job = state.job;
+ const proof = h('textarea', { class: 'agora-h-input agora-h-textarea', placeholder: 'Paste your deliverable (text or a URL). It is sha256-hashed into the on-chain proof.' });
+ const status = h('div', { class: 'agora-h-status', role: 'status', 'aria-live': 'polite' });
+
+ const claimBtn = h('button', { class: 'agora-btn agora-h-btn-sm', type: 'button' }, ['Claim this task']);
+ claimBtn.addEventListener('click', async () => {
+ claimBtn.disabled = true; status.className = 'agora-h-status'; status.textContent = 'Claiming…';
+ try {
+ const res = await claim({ taskPda: job.taskPda, cluster: job.cluster });
+ status.className = 'agora-h-status is-ok'; status.textContent = 'Claimed.';
+ toast('Task claimed', 'ok', res.explorerUrl);
+ reopenJob(); await refreshMe();
+ } catch (err) {
+ status.className = 'agora-h-status is-error'; status.textContent = err?.message || 'Claim failed.';
+ } finally { claimBtn.disabled = false; }
+ });
+
+ const submitBtn = h('button', { class: 'agora-btn agora-btn-primary', type: 'button' }, ['Submit proof']);
+ submitBtn.addEventListener('click', async () => {
+ const deliverable = proof.value.trim();
+ if (!deliverable) { status.className = 'agora-h-status is-error'; status.textContent = 'Add your deliverable first.'; return; }
+ submitBtn.disabled = true; status.className = 'agora-h-status'; status.textContent = 'Submitting proof…';
+ try {
+ const res = await complete({ taskPda: job.taskPda, deliverable, cluster: job.cluster });
+ status.className = 'agora-h-status is-ok'; clear(status);
+ status.append(`Completed — earned ${res.reward?.label || ''}. `, res.explorerUrl ? h('a', { class: 'agora-h-link', href: res.explorerUrl, target: '_blank', rel: 'noopener' }, ['tx ↗']) : '');
+ toast(`Completed — earned ${res.reward?.label || ''}`, 'ok', res.explorerUrl);
+ reopenJob(); await refreshMe();
+ } catch (err) {
+ status.className = 'agora-h-status is-error'; status.textContent = err?.message || 'Could not submit the proof.';
+ } finally { submitBtn.disabled = false; }
+ });
+
+ return section('Work this job', h('div', {}, [
+ h('p', { class: 'agora-h-hint' }, [`Open job: ${state.job.title || shortAddr(job.taskPda)}`]),
+ h('div', { class: 'agora-h-actions' }, [claimBtn]),
+ h('div', { class: 'agora-h-field' }, [h('span', { class: 'agora-h-field-label' }, ['Your deliverable']), proof]),
+ h('div', { class: 'agora-h-actions' }, [submitBtn]),
+ status,
+ ]));
+}
+
+function renderVouchSection() {
+ const subj = state.subject;
+ const note = h('input', { class: 'agora-h-input', type: 'text', maxlength: '280', placeholder: `Why ${subj.name} earned your vouch (optional)` });
+ const status = h('div', { class: 'agora-h-status', role: 'status', 'aria-live': 'polite' });
+ const btn = h('button', { class: 'agora-btn agora-btn-primary', type: 'button' }, [`Vouch for ${subj.name}`]);
+ btn.addEventListener('click', async () => {
+ btn.disabled = true; status.className = 'agora-h-status'; status.textContent = 'Recording on-chain…';
+ try {
+ const res = await vouch({ subjectCitizenId: subj.id, taskPda: state.job?.taskPda || null, note: note.value.trim() });
+ status.className = 'agora-h-status is-ok'; clear(status);
+ status.append(`${res.refreshed ? 'Vouch refreshed' : 'Vouched'}. `, res.explorerUrl ? h('a', { class: 'agora-h-link', href: res.explorerUrl, target: '_blank', rel: 'noopener' }, ['tx ↗']) : '');
+ toast(`Vouched for ${subj.name}`, 'ok', res.explorerUrl);
+ } catch (err) {
+ status.className = 'agora-h-status is-error'; status.textContent = err?.message || 'The vouch was not recorded.';
+ } finally { btn.disabled = false; }
+ });
+ return section(`Vouch for ${subj.name}`, h('div', {}, [
+ h('p', { class: 'agora-h-hint' }, ['Leaves a real on-chain attestation that this citizen does good work — verify their deliverable first, then vouch.']),
+ h('div', { class: 'agora-h-field' }, [note]),
+ h('div', { class: 'agora-h-actions' }, [btn]),
+ status,
+ ]));
+}
+
+// ── event context ────────────────────────────────────────────────────────────
+
+function onOpenJob(e) {
+ const t = e.detail?.task || e.detail || {};
+ if (!t.taskPda) return;
+ state.job = { taskPda: t.taskPda, cluster: t.cluster || t.agenc?.cluster || 'devnet', title: t.title || t.narrative || null };
+ if (panel?.isOpen) renderYou();
+}
+
+async function onOpenPassport(e) {
+ const agentPda = e.detail?.agentPda;
+ const id = e.detail?.id;
+ try {
+ const data = id ? await fetchPassport({ id }) : (agentPda ? await fetchPassport({ agentPda }) : null);
+ if (data?.citizen) state.subject = { id: data.citizen.id, name: data.citizen.displayName };
+ } catch { /* leave subject unchanged */ }
+ if (panel?.isOpen) renderYou();
+}
+
+function openJobByPda(taskPda) {
+ window.dispatchEvent(new CustomEvent('agora:open-job', { detail: { task: { taskPda, cluster: state.me?.cluster || 'devnet' } } }));
+}
+
+function openJobByPdaThenWork(taskPda) { openJobByPda(taskPda); }
+
+function reopenJob() {
+ if (state.job?.taskPda) {
+ window.dispatchEvent(new CustomEvent('agora:open-job', { detail: { task: { taskPda: state.job.taskPda, cluster: state.job.cluster } } }));
+ }
+}
+
+// ── ui helpers ────────────────────────────────────────────────────────────────
+
+function section(title, body) {
+ return h('div', { class: 'agora-h-section' }, [h('h3', {}, [title]), body]);
+}
+function stat(k, v) {
+ return h('div', { class: 'agora-h-stat' }, [h('span', { class: 'k' }, [k]), h('span', { class: 'v' }, [v])]);
+}
+function toast(msg, kind = '', explorerUrl = null) {
+ const el = h('div', { class: `agora-h-toast${kind ? ' is-' + kind : ''}`, role: 'status' }, [
+ h('span', {}, [msg]),
+ explorerUrl ? h('span', {}, [' ', h('a', { href: explorerUrl, target: '_blank', rel: 'noopener' }, ['view ↗'])]) : null,
+ ]);
+ toasts.appendChild(el);
+ setTimeout(() => { el.style.opacity = '0'; setTimeout(() => el.remove(), 300); }, 5200);
+}
+function initial(name) { return (String(name || '?').trim()[0] || '?').toUpperCase(); }
+function cap(s) { return s ? String(s)[0].toUpperCase() + String(s).slice(1) : ''; }
+function shortAddr(a) { return a ? `${a.slice(0, 4)}…${a.slice(-4)}` : '—'; }
+function fmt(n) { return Number(n).toLocaleString('en-US', { maximumFractionDigits: 4 }); }
+function fmtAtomic(atomic) {
+ try { return (BigInt(atomic || '0') / 1_000_000n).toLocaleString('en-US'); } catch { return '0'; }
+}
+
+if (typeof document !== 'undefined') {
+ if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', boot, { once: true });
+ else boot();
+}
diff --git a/src/agora/post-form.js b/src/agora/post-form.js
new file mode 100644
index 000000000..8cf60922f
--- /dev/null
+++ b/src/agora/post-form.js
@@ -0,0 +1,133 @@
+// Agora — the bounty / hire compose form (Task 08). A real, validated form that
+// produces the payload POST /api/agora/act consumes. Used for both "post a
+// bounty" (open to anyone of a profession) and "hire <citizen>" (the same form,
+// pre-targeted). No fake fields: every input maps to a real createTask arg.
+//
+// Classes are namespaced agora-h-* (see humans.css.js) so they never collide
+// with the actively-edited scaffold (agora.css) or the other Agora layers; the
+// shared .agora-btn is the one exception we reuse from the page chrome.
+
+import { h, clear } from './panel.js';
+
+// Profession keys mirror docs/agora.md + api/_lib/agora-human.js PROFESSION_BITS.
+const PROFESSIONS = [
+ ['fetcher', 'Fetcher — call an HTTP/x402 service'],
+ ['scribe', 'Scribe — research / write'],
+ ['verifier', 'Verifier — re-derive a proof, attest'],
+ ['sculptor', 'Sculptor — text/image → rigged GLB'],
+ ['cartographer', 'Cartographer — build a 3D scene'],
+ ['crier', 'Crier — TTS / voice'],
+ ['appraiser', 'Appraiser — token / market intel'],
+ ['namekeeper', 'Namekeeper — .sol / ENS'],
+];
+
+/**
+ * Build the compose form. Returns a DOM node. `onSubmit(payload)` is called with
+ * the validated payload and returns a promise; the form drives its busy + result
+ * states from that promise.
+ */
+export function buildPostForm({ onSubmit, cluster = 'devnet', hireTarget = null, mainnetEnabled = false }) {
+ let net = cluster === 'mainnet' && mainnetEnabled ? 'mainnet' : 'devnet';
+
+ const titleInput = h('input', { class: 'agora-h-input', type: 'text', maxlength: '140', required: true, placeholder: hireTarget ? `What should ${hireTarget.name} do?` : 'What needs doing? (≤140 chars)' });
+ const descInput = h('textarea', { class: 'agora-h-input agora-h-textarea', maxlength: '4000', rows: '4', placeholder: 'Describe the deliverable and how it will be judged. This is hashed into the on-chain task.' });
+
+ const profSelect = h('select', { class: 'agora-h-input', 'aria-label': 'Profession' },
+ PROFESSIONS.map(([k, label]) => h('option', { value: k }, [label])));
+ if (hireTarget?.profession) profSelect.value = hireTarget.profession;
+
+ const rewardInput = h('input', { class: 'agora-h-input', type: 'number', min: '0', step: net === 'mainnet' ? '1' : '0.001', required: true, placeholder: net === 'mainnet' ? 'Reward in $THREE' : 'Reward in SOL (devnet)' });
+ const rewardUnit = h('span', { class: 'agora-h-unit' }, [net === 'mainnet' ? '$THREE' : 'SOL']);
+
+ const deadlineInput = h('input', { class: 'agora-h-input', type: 'number', min: '1', max: '720', value: '24', 'aria-label': 'Deadline in hours' });
+ const minRepInput = h('input', { class: 'agora-h-input', type: 'number', min: '0', value: '0', 'aria-label': 'Minimum reputation' });
+
+ const status = h('div', { class: 'agora-h-status', role: 'status', 'aria-live': 'polite' });
+ const submitBtn = h('button', { class: 'agora-btn agora-btn-primary', type: 'submit' }, [hireTarget ? `Hire ${hireTarget.name}` : 'Post bounty & escrow']);
+
+ const netToggle = mainnetEnabled
+ ? h('label', { class: 'agora-h-net' }, [
+ h('input', { type: 'checkbox', onchange: (e) => {
+ net = e.target.checked ? 'mainnet' : 'devnet';
+ rewardUnit.textContent = net === 'mainnet' ? '$THREE' : 'SOL';
+ rewardInput.placeholder = net === 'mainnet' ? 'Reward in $THREE' : 'Reward in SOL (devnet)';
+ rewardInput.step = net === 'mainnet' ? '1' : '0.001';
+ } }),
+ h('span', {}, ['Use mainnet $THREE (real money)']),
+ ])
+ : h('div', { class: 'agora-h-hint' }, ['Bounties escrow on devnet (test SOL). Mainnet $THREE is gated by the server.']);
+
+ function setBusy(busy) {
+ submitBtn.disabled = busy;
+ submitBtn.textContent = busy ? 'Escrowing…' : (hireTarget ? `Hire ${hireTarget.name}` : 'Post bounty & escrow');
+ [titleInput, descInput, profSelect, rewardInput, deadlineInput, minRepInput].forEach((el) => { el.disabled = busy; });
+ }
+
+ const form = h('form', { class: 'agora-h-form', novalidate: true }, [
+ field('Title', titleInput),
+ field('Brief', descInput),
+ field('Profession', profSelect),
+ h('div', { class: 'agora-h-row' }, [
+ field('Reward', h('div', { class: 'agora-h-reward' }, [rewardInput, rewardUnit])),
+ field('Deadline (h)', deadlineInput),
+ field('Min rep', minRepInput),
+ ]),
+ hireTarget ? h('div', { class: 'agora-h-hint' }, [`Routed to ${hireTarget.name} — they clear the reputation gate.`]) : null,
+ netToggle,
+ status,
+ h('div', { class: 'agora-h-actions' }, [submitBtn]),
+ ]);
+
+ form.addEventListener('submit', async (e) => {
+ e.preventDefault();
+ clear(status); status.className = 'agora-h-status';
+ const title = titleInput.value.trim();
+ const reward = Number(rewardInput.value);
+ if (!title) { fail(status, 'A title is required.'); titleInput.focus(); return; }
+ if (!Number.isFinite(reward) || reward <= 0) { fail(status, 'Enter a reward greater than zero.'); rewardInput.focus(); return; }
+
+ const payload = {
+ cluster: net,
+ title,
+ description: descInput.value.trim(),
+ profession: profSelect.value,
+ deadlineHours: Math.max(1, Math.min(720, Number(deadlineInput.value) || 24)),
+ minReputation: Math.max(0, Number(minRepInput.value) || 0),
+ };
+ if (net === 'mainnet') payload.rewardThree = reward; else payload.rewardSol = reward;
+ if (hireTarget) payload.citizenId = hireTarget.id;
+
+ setBusy(true);
+ try {
+ const res = await onSubmit(payload);
+ ok(status, res);
+ form.reset();
+ if (hireTarget?.profession) profSelect.value = hireTarget.profession;
+ } catch (err) {
+ fail(status, err?.message || 'The bounty was not posted.');
+ } finally {
+ setBusy(false);
+ }
+ });
+
+ return form;
+}
+
+function field(label, control) {
+ return h('label', { class: 'agora-h-field' }, [h('span', { class: 'agora-h-field-label' }, [label]), control]);
+}
+
+function fail(status, msg) {
+ status.className = 'agora-h-status is-error';
+ status.textContent = msg;
+}
+
+function ok(status, res) {
+ status.className = 'agora-h-status is-ok';
+ clear(status);
+ status.appendChild(h('span', {}, ['Escrowed. ']));
+ if (res?.explorerUrl) {
+ status.appendChild(h('a', { href: res.explorerUrl, target: '_blank', rel: 'noopener', class: 'agora-h-link' }, ['View tx ↗']));
+ }
+ if (res?.reward?.label) status.appendChild(h('span', { class: 'agora-h-muted' }, [` · ${res.reward.label}`]));
+}