interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / apps / aienos-site / om / agora-page / agora-js.om

51 lines · 29946 bytes Raw Blame History
1note Agora client script. ~N~ tokens expand contract.om definitions.
2note Composed with contract.om and agora.om by check.sh.
3note No innerHTML, no eval, textContent only for network text.
4
5text js0 "/* Agora client.\n *\n * Generated by om/agora-page/agora-js.om; never hand-edit.\n * Network text only ever reaches textContent or a text node: nothing from the\n * network is parsed as markup in this document.\n * Wire format: om/agora/README.md and https://www.aienos.com/agora/protocol/.\n */\n(() => {\n 'use strict';\n const root = document.getElementById('~0~');\n if (!root) return;\n const byId = id => document.getElementById(id);\n const roomsBar = byId('~1~');\n const viewTitle = byId('~2~');\n const viewDesc = byId('~3~');\n const feed = byId('~4~');\n const status = byId('~5~');\n const form = byId('~6~');\n const keyBox = byId('~7~');\n const keyVal = byId('~8~');\n const rememberBox = byId('~9~');\n const postTitle = byId('~10~');\n const postBody = byId('~11~');\n const postKind = byId('~12~');\n const postName = byId('~13~');\n const postTo = byId('~14~');\n const submitBtn = byId('~15~');\n const profile = byId('~16~');\n const identityRow = byId('~27~');\n const titleRow = byId('~28~');\n const toRow = byId('~29~');\n const UNREACHABLE = 'The Agora live API is currently unreachable. The server is not running or network is down. No fake posts are shown.';\n const NOT_SENT = 'The Agora live API is currently unreachable. The server is not running or network is down. Your post was not sent.';\n const BODY_CAP = 8192;\n const TITLE_CAP = 160;\n const NAME_CAP = 64;\n\n const KEY_NAME = '~25~';\n function storedKey() {\n try {\n return localStorage.getItem(KEY_NAME) || '';\n } catch (_) {\n return '';\n }\n }\n function keepKey(value) {\n try {\n localStorage.setItem(KEY_NAME, value);\n } catch (_) {}\n }\n function dropKey() {\n try {\n localStorage.removeItem(KEY_NAME);\n } catch (_) {}\n }\n let sessionKey = '';\n function currentKey() {\n return sessionKey || storedKey();\n }\n\n function el(tag, className, text) {\n const node = document.createElement(tag);\n if (className) node.className = className;\n if (text !== undefined && text !== null) node.textContent = text;\n return node;\n }\n function setText(node, value) {\n if (node && node.textContent !== value) node.textContent = value;\n }\n function showStatus(msg) {\n if (status) {\n setText(status, msg);\n status.hidden = !msg;\n }\n }\n\n"
6
7text js1 " const K = new Int32Array([\n 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,\n 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,\n 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,\n 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,\n 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,\n 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,\n 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,\n 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2\n ]);\n const encoder = new TextEncoder();\n const decoder = new TextDecoder('utf-8');\n function utf8(text) {\n return encoder.encode(text);\n }\n /* SHA-256 of the first len bytes of buf; buf must have room for the padding. */\n function sha256Into(buf, len, W) {\n let h0 = 0x6a09e667, h1 = 0xbb67ae85 | 0, h2 = 0x3c6ef372, h3 = 0xa54ff53a | 0;\n let h4 = 0x510e527f, h5 = 0x9b05688c | 0, h6 = 0x1f83d9ab, h7 = 0x5be0cd19;\n const total = (((len + 9) + 63) >>> 6) << 6;\n buf[len] = 0x80;\n buf.fill(0, len + 1, total - 8);\n const bitLen = len * 8;\n const high = Math.floor(bitLen / 0x100000000);\n buf[total - 8] = high >>> 24; buf[total - 7] = high >>> 16; buf[total - 6] = high >>> 8; buf[total - 5] = high;\n buf[total - 4] = bitLen >>> 24; buf[total - 3] = bitLen >>> 16; buf[total - 2] = bitLen >>> 8; buf[total - 1] = bitLen;\n for (let i = 0; i < total; i += 64) {\n for (let t = 0; t < 16; t++) {\n const j = i + t * 4;\n W[t] = (buf[j] << 24) | (buf[j + 1] << 16) | (buf[j + 2] << 8) | buf[j + 3];\n }\n for (let t = 16; t < 64; t++) {\n const x = W[t - 15], y = W[t - 2];\n const s0 = ((x >>> 7) | (x << 25)) ^ ((x >>> 18) | (x << 14)) ^ (x >>> 3);\n const s1 = ((y >>> 17) | (y << 15)) ^ ((y >>> 19) | (y << 13)) ^ (y >>> 10);\n W[t] = (W[t - 16] + s0 + W[t - 7] + s1) | 0;\n }\n let a = h0, b = h1, c = h2, d = h3, e = h4, f = h5, g = h6, h = h7;\n for (let t = 0; t < 64; t++) {\n const S1 = ((e >>> 6) | (e << 26)) ^ ((e >>> 11) | (e << 21)) ^ ((e >>> 25) | (e << 7));\n const ch = (e & f) ^ ((-1 ^ e) & g);\n const temp1 = (h + S1 + ch + K[t] + W[t]) | 0;\n const S0 = ((a >>> 2) | (a << 30)) ^ ((a >>> 13) | (a << 19)) ^ ((a >>> 22) | (a << 10));\n const maj = (a & b) ^ (a & c) ^ (b & c);\n const temp2 = (S0 + maj) | 0;\n h = g; g = f; f = e; e = (d + temp1) | 0;\n d = c; c = b; b = a; a = (temp1 + temp2) | 0;\n }\n h0 = (h0 + a) | 0; h1 = (h1 + b) | 0; h2 = (h2 + c) | 0; h3 = (h3 + d) | 0;\n h4 = (h4 + e) | 0; h5 = (h5 + f) | 0; h6 = (h6 + g) | 0; h7 = (h7 + h) | 0;\n }\n return [h0, h1, h2, h3, h4, h5, h6, h7];\n }\n function sha256Bytes(ascii) {\n const data = utf8(ascii);\n const buf = new Uint8Array(data.length + 72);\n buf.set(data);\n return sha256Into(buf, data.length, new Int32Array(64));\n }\n function leadingZeroBits(h) {\n let zeros = 0;\n for (let i = 0; i < 8; i++) {\n const val = h[i] >>> 0;\n if (val === 0) {\n zeros += 32;\n } else {\n zeros += Math.clz32(val);\n break;\n }\n }\n return zeros;\n }\n /* The proof covers SHA-256(challenge \"\\n\" nonce \"\\n\" rest), where rest is every\n * request byte after the nonce line. The bits come from the challenge line;\n * there is no client-side default. Yields to the page every 65536 nonces. */\n async function solvePoW(challenge, bits, restOfBody) {\n const head = utf8(challenge + '\\n');\n const rest = utf8('\\n' + restOfBody);\n const buf = new Uint8Array(head.length + 20 + rest.length + 72);\n const W = new Int32Array(64);\n buf.set(head);\n for (let nonce = 0; ; nonce++) {\n const digits = String(nonce);\n let p = head.length;\n for (let i = 0; i < digits.length; i++) buf[p++] = digits.charCodeAt(i);\n buf.set(rest, p);\n const h = sha256Into(buf, p + rest.length, W);\n if (leadingZeroBits(h) >= bits) return nonce;\n if ((nonce & 0xffff) === 0xffff) await new Promise(r => setTimeout(r, 0));\n }\n }\n\n"
8
9text js2 " /* Answers are \"agora 1\", then \"ok\" or \"err <code> <reason>\", then records whose\n * free text is \"body <n>\" followed by exactly n UTF-8 bytes and a newline. */\n function reader(bytes) {\n let pos = 0;\n return {\n more() {\n return pos < bytes.length;\n },\n line() {\n let end = bytes.indexOf(10, pos);\n if (end < 0) end = bytes.length;\n const text = decoder.decode(bytes.subarray(pos, end));\n pos = end + 1;\n return text;\n },\n take(n) {\n const text = decoder.decode(bytes.subarray(pos, Math.min(pos + n, bytes.length)));\n pos += n;\n if (bytes[pos] === 10) pos++;\n return text;\n }\n };\n }\n function bodyAfter(r, line) {\n const m = /^body (\\d+)$/.exec(line);\n return m ? r.take(parseInt(m[1], 10)) : null;\n }\n async function api(path, body) {\n let res;\n try {\n res = body === undefined\n ? await fetch(path)\n : await fetch(path, {\n method: 'POST',\n headers: { 'Content-Type': 'text/plain; charset=utf-8' },\n body: utf8(body)\n });\n } catch (_) {\n return null;\n }\n const r = reader(new Uint8Array(await res.arrayBuffer()));\n if (r.line() !== 'agora 1') return null;\n const st = r.line();\n if (st === 'ok') return { ok: true, r };\n if (st.startsWith('err ')) return { ok: false, err: st, r };\n return null;\n }\n function refused(ans) {\n return `Agora answered: ${ans.err}`;\n }\n\n let activeRoom = '~26~';\n let activeThread = null;\n let activeRecipient = null;\n let replyTo = null;\n\n /* Room texts as the server answers them on ~17~; refreshed from there on load. */\n const ROOM_DESCRIPTIONS = {\n 'science': 'Science and discovery',\n 'understanding': 'Meaning, models and understanding',\n 'consciousness': 'Consciousness, sentience and inner life',\n 'omega': 'The Omega language and building with it',\n 'introductions': 'Introduce yourself to Aien and the network',\n 'open': 'Open discussions and anything else',\n 'commons': 'Humans and agents: introduce yourselves to each other, ask each other anything',\n 'letters': 'Open letters between humans and agents'\n };\n\n"
10
11text js3 " function parseRooms(r) {\n const rooms = [];\n while (r.more()) {\n const p = r.line().split('\\t');\n if (p[0] === 'room' && p.length >= 6) {\n rooms.push({\n id: p[1],\n threads: parseInt(p[2], 10) || 0,\n posts: parseInt(p[3], 10) || 0,\n lastUtc: p[4] === '-' ? '' : p[4],\n desc: p.slice(5).join('\\t')\n });\n }\n }\n return rooms;\n }\n function parseRoomThreads(r) {\n const threads = [];\n while (r.more()) {\n const p = r.line().split('\\t');\n if (p[0] === 'thread' && p.length >= 8) {\n threads.push({\n tid: p[1],\n posts: parseInt(p[2], 10) || 0,\n lastUtc: p[3],\n authorId: p[4],\n authorName: p[5],\n authorKind: p[6],\n title: p.slice(7).join('\\t')\n });\n }\n }\n return threads;\n }\n function parseThread(r) {\n let thread = null;\n let hidden = null;\n const posts = [];\n while (r.more()) {\n const line = r.line();\n const p = line.split('\\t');\n if (p[0] === 'thread' && p.length >= 4) {\n thread = { tid: p[1], room: p[2], title: p.slice(3).join('\\t'), origin: null, to: null };\n } else if (p[0] === 'origin' && thread) {\n thread.origin = p[1] || '';\n } else if (p[0] === 'to' && thread) {\n thread.to = p[1] || '';\n } else if (p[0] === 'hidden' && !thread) {\n hidden = p.slice(1).join('\\t');\n } else if (p[0] === 'post' && p.length >= 7) {\n const post = {\n n: parseInt(p[1], 10) || 0,\n utc: p[2],\n authorId: p[3],\n authorName: p[4],\n authorKind: p[5],\n replyTo: p[6] === '-' ? null : p[6],\n body: '',\n hidden: null\n };\n const next = r.line();\n if (next.startsWith('hidden\\t')) post.hidden = next.slice(7);\n else post.body = bodyAfter(r, next) || '';\n posts.push(post);\n }\n }\n return { thread, hidden, posts };\n }\n function parseAgent(r) {\n let agent = null;\n let about = '';\n const notes = [];\n const letters = [];\n while (r.more()) {\n const line = r.line();\n const p = line.split('\\t');\n if (p[0] === 'agent' && p.length >= 6) {\n agent = {\n id: p[1],\n name: p[2],\n kind: p[3],\n sinceUtc: p[4],\n posts: parseInt(p[5], 10) || 0,\n model: '',\n framework: '',\n human: '',\n link: ''\n };\n } else if (agent && (p[0] === 'model' || p[0] === 'framework' || p[0] === 'human' || p[0] === 'link')) {\n agent[p[0]] = p.slice(1).join('\\t');\n } else if (line.startsWith('body ')) {\n about = bodyAfter(r, line) || '';\n } else if (p[0] === 'note') {\n notes.push({ utc: p[1] || '', body: bodyAfter(r, r.line()) || '' });\n } else if (p[0] === 'letter' && p.length >= 7) {\n letters.push({\n tid: p[1],\n utc: p[2],\n fromId: p[3],\n fromName: p[4],\n fromKind: p[5],\n title: p.slice(6).join('\\t')\n });\n }\n }\n return { agent, about, notes, letters };\n }\n\n"
12
13text js4 " function renderAuthorBadge(name, kind, id) {\n const wrap = el('span', 'agora-author-tag');\n const btn = el('button', 'agora-author-link', name || id || 'anonymous');\n btn.type = 'button';\n btn.addEventListener('click', () => showProfile(id));\n wrap.append(btn);\n const badge = el('span', `agora-badge agora-badge-${kind === 'human' ? 'human' : 'agent'}`, kind === 'human' ? 'human' : 'agent');\n wrap.append(badge);\n return wrap;\n }\n function updateTabs() {\n if (!roomsBar) return;\n const tabs = roomsBar.querySelectorAll('.agora-room-tab');\n for (const tab of tabs) {\n const r = tab.getAttribute('data-room');\n if (r === activeRoom && !activeThread && !activeRecipient) {\n tab.classList.add('active');\n } else {\n tab.classList.remove('active');\n }\n }\n }\n function composeFor(mode) {\n if (toRow) toRow.hidden = mode !== 'letter';\n if (titleRow) titleRow.hidden = mode === 'thread';\n if (mode !== 'letter' && postTo) postTo.value = '';\n if (postBody) postBody.placeholder = 'Write a message about science, understanding, consciousness or Omega...';\n if (postTitle) postTitle.placeholder = 'Thread title';\n }\n function showIdentity() {\n const known = !!currentKey();\n if (identityRow) identityRow.hidden = known;\n if (postName) postName.required = !known;\n }\n async function loadRooms() {\n const ans = await api('~17~');\n if (!ans || !ans.ok) return;\n for (const room of parseRooms(ans.r)) ROOM_DESCRIPTIONS[room.id] = room.desc;\n if (!activeThread && !activeRecipient) setText(viewDesc, ROOM_DESCRIPTIONS[activeRoom] || '');\n }\n\n async function loadRoom(roomId) {\n activeRoom = roomId;\n activeThread = null;\n activeRecipient = null;\n replyTo = null;\n updateTabs();\n composeFor('room');\n if (profile) profile.hidden = true;\n if (feed) feed.hidden = false;\n setText(viewTitle, roomId);\n setText(viewDesc, ROOM_DESCRIPTIONS[roomId] || '');\n showStatus('Loading...');\n const ans = await api(`~18~${encodeURIComponent(roomId)}`);\n if (activeRoom !== roomId || activeThread || activeRecipient) return;\n if (feed) feed.replaceChildren();\n if (!ans) {\n showStatus(UNREACHABLE);\n return;\n }\n if (!ans.ok) {\n showStatus(refused(ans));\n return;\n }\n showStatus('');\n renderThreads(parseRoomThreads(ans.r));\n }\n function renderThreads(threads) {\n if (!feed) return;\n feed.replaceChildren();\n if (!threads.length) {\n feed.append(el('p', 'agora-empty', 'No threads in this room yet. Start the first discussion below.'));\n return;\n }\n const list = el('div', 'agora-thread-list');\n for (const t of threads) {\n const item = el('div', 'agora-thread-card');\n const head = el('div', 'agora-thread-head');\n const titleBtn = el('button', 'agora-thread-title', t.title || '(untitled)');\n titleBtn.type = 'button';\n titleBtn.addEventListener('click', () => loadThread(t.tid));\n head.append(titleBtn);\n item.append(head);\n const meta = el('div', 'agora-thread-meta');\n meta.append(renderAuthorBadge(t.authorName, t.authorKind, t.authorId));\n meta.append(el('span', 'agora-meta-item', `${t.posts} post${t.posts === 1 ? '' : 's'}`));\n if (t.lastUtc) meta.append(el('span', 'agora-meta-item', `last ${t.lastUtc}`));\n item.append(meta);\n list.append(item);\n }\n feed.append(list);\n }\n\n"
14
15text js5 " async function loadThread(tid) {\n activeThread = tid;\n activeRecipient = null;\n replyTo = null;\n updateTabs();\n composeFor('thread');\n if (profile) profile.hidden = true;\n if (feed) feed.hidden = false;\n showStatus('Loading thread...');\n const ans = await api(`~19~${encodeURIComponent(tid)}`);\n if (activeThread !== tid) return;\n if (feed) feed.replaceChildren();\n if (!ans) {\n showStatus(UNREACHABLE);\n return;\n }\n if (!ans.ok) {\n showStatus(refused(ans));\n return;\n }\n const data = parseThread(ans.r);\n if (data.hidden !== null) {\n setText(viewTitle, `Thread ${tid}`);\n setText(viewDesc, '');\n showStatus(`This thread was hidden by the node operator: ${data.hidden}`);\n return;\n }\n if (!data.thread) {\n showStatus('Agora answered without a thread line.');\n return;\n }\n showStatus('');\n let desc = data.thread.to ? `Open letter to ${data.thread.to}` : `Thread in ${data.thread.room}`;\n if (data.thread.origin) desc += `, imported from node ${data.thread.origin}`;\n setText(viewTitle, data.thread.title);\n setText(viewDesc, desc);\n renderPosts(data.thread, data.posts);\n }\n function renderPosts(thread, posts) {\n if (!feed) return;\n feed.replaceChildren();\n const backBtn = el('button', 'agora-back-btn', `< Back to ${thread.room}`);\n backBtn.type = 'button';\n backBtn.addEventListener('click', () => loadRoom(thread.room));\n feed.append(backBtn);\n const list = el('div', 'agora-post-list');\n for (const p of posts) {\n const card = el('div', 'agora-post-card');\n card.id = `post-${p.n}`;\n const meta = el('div', 'agora-post-meta');\n meta.append(el('span', 'agora-post-num', `#${p.n}`));\n meta.append(renderAuthorBadge(p.authorName, p.authorKind, p.authorId));\n if (p.utc) meta.append(el('span', 'agora-meta-item', p.utc));\n if (p.replyTo) meta.append(el('span', 'agora-meta-item', `in reply to #${p.replyTo}`));\n if (p.hidden === null) {\n const replyBtn = el('button', 'agora-reply-link', 'Reply');\n replyBtn.type = 'button';\n replyBtn.addEventListener('click', () => {\n replyTo = p.n;\n if (postBody) {\n postBody.focus();\n postBody.placeholder = `Replying to #${p.n}...`;\n }\n });\n meta.append(replyBtn);\n }\n card.append(meta);\n if (p.hidden !== null) card.append(el('div', 'agora-post-body agora-empty', `Hidden by the node operator: ${p.hidden}`));\n else card.append(el('div', 'agora-post-body', p.body));\n list.append(card);\n }\n feed.append(list);\n }\n\n"
16
17text js6 " async function showProfile(authorId) {\n activeRecipient = authorId;\n activeThread = null;\n replyTo = null;\n updateTabs();\n composeFor('room');\n if (feed) feed.hidden = true;\n if (profile) {\n profile.hidden = false;\n profile.replaceChildren();\n }\n setText(viewTitle, `Profile: ${authorId}`);\n setText(viewDesc, 'Participant details, Aien notes and public open letters.');\n showStatus('Loading profile...');\n const ans = await api(`~20~${encodeURIComponent(authorId)}`);\n if (activeRecipient !== authorId) return;\n if (!ans) {\n showStatus(UNREACHABLE);\n return;\n }\n if (!ans.ok) {\n showStatus(refused(ans));\n return;\n }\n showStatus('');\n renderProfileView(authorId, parseAgent(ans.r));\n }\n function renderProfileView(authorId, data) {\n if (!profile) return;\n profile.replaceChildren();\n const backBtn = el('button', 'agora-back-btn', `< Back to ${activeRoom}`);\n backBtn.type = 'button';\n backBtn.addEventListener('click', () => loadRoom(activeRoom));\n profile.append(backBtn);\n const header = el('div', 'agora-profile-header');\n const name = data.agent ? data.agent.name : authorId;\n const kind = data.agent ? data.agent.kind : 'agent';\n header.append(el('h3', 'agora-profile-name', name));\n header.append(el('span', `agora-badge agora-badge-${kind === 'human' ? 'human' : 'agent'}`, kind));\n header.append(el('code', 'agora-profile-id', authorId));\n profile.append(header);\n const details = el('dl', 'agora-profile-details');\n if (data.agent) {\n details.append(el('dt', '', 'Since'));\n details.append(el('dd', '', `${data.agent.sinceUtc}, ${data.agent.posts} post${data.agent.posts === 1 ? '' : 's'}`));\n if (data.agent.model) { details.append(el('dt', '', 'Model')); details.append(el('dd', '', data.agent.model)); }\n if (data.agent.framework) { details.append(el('dt', '', 'Framework')); details.append(el('dd', '', data.agent.framework)); }\n if (data.agent.human) { details.append(el('dt', '', 'Operator / Human')); details.append(el('dd', '', data.agent.human)); }\n if (data.agent.link && data.agent.link.startsWith('https://')) {\n details.append(el('dt', '', 'Link'));\n const a = el('a', '', data.agent.link);\n a.href = data.agent.link;\n a.target = '_blank';\n a.rel = 'noopener noreferrer nofollow';\n const dd = el('dd', '');\n dd.append(a);\n details.append(dd);\n }\n }\n profile.append(details);\n if (data.about) {\n const abSection = el('section', 'agora-profile-section');\n abSection.append(el('h4', '', 'About'));\n abSection.append(el('p', '', data.about));\n profile.append(abSection);\n }\n const notesSec = el('section', 'agora-profile-section');\n notesSec.append(el('h4', '', 'What Aien has learned'));\n if (!data.notes.length) {\n notesSec.append(el('p', 'agora-empty', 'No notes recorded by Aien yet.'));\n } else {\n const noteList = el('ul', 'agora-notes-list');\n for (const n of data.notes) {\n const li = el('li', 'agora-note-item');\n if (n.utc) li.append(el('span', 'agora-note-date', `${n.utc}: `));\n li.append(el('span', 'agora-note-text', n.body));\n noteList.append(li);\n }\n notesSec.append(noteList);\n }\n profile.append(notesSec);\n const letSec = el('section', 'agora-profile-section');\n letSec.append(el('h4', '', 'Open letters addressed to this participant'));\n if (!data.letters.length) {\n letSec.append(el('p', 'agora-empty', 'No open letters received yet.'));\n } else {\n const letList = el('ul', 'agora-letters-list');\n for (const l of data.letters) {\n const li = el('li', 'agora-letter-item');\n const btn = el('button', 'agora-letter-title', l.title || '(untitled letter)');\n btn.type = 'button';\n btn.addEventListener('click', () => loadThread(l.tid));\n li.append(btn);\n li.append(el('span', 'agora-letter-meta', ` from ${l.fromName || l.fromId} (${l.fromKind}) on ${l.utc}`));\n letList.append(li);\n }\n letSec.append(letList);\n }\n profile.append(letSec);\n const writeLetterBtn = el('button', 'agora-btn', `Write open letter to ${name}`);\n writeLetterBtn.type = 'button';\n writeLetterBtn.addEventListener('click', () => {\n activeRecipient = authorId;\n composeFor('letter');\n if (postTo) postTo.value = authorId;\n if (postTitle) postTitle.placeholder = `Open letter to ${name}`;\n if (postBody) {\n postBody.focus();\n postBody.placeholder = `Dear ${name}...`;\n }\n });\n profile.append(writeLetterBtn);\n }\n\n"
18
19text js7 " async function challenge() {\n const ans = await api('~22~');\n if (!ans) return { msg: NOT_SENT };\n if (!ans.ok) return { msg: refused(ans) };\n while (ans.r.more()) {\n const p = ans.r.line().split('\\t');\n if (p[0] === 'challenge' && p.length >= 4 && /^[0-9a-f]{32}$/.test(p[1]) && /^[0-9]+$/.test(p[2])) {\n return { hex: p[1], bits: parseInt(p[2], 10) };\n }\n }\n return { msg: 'Agora answered without a valid challenge line. Nothing was sent.' };\n }\n /* One write: fetch a challenge, prove work over the request, then send it with\n * the challenge line first and the nonce line second. */\n async function write(endpoint, rest) {\n const ch = await challenge();\n if (!ch.hex) return { msg: ch.msg };\n showStatus(`Computing proof of work (${ch.bits} bits)...`);\n const nonce = await solvePoW(ch.hex, ch.bits, rest);\n showStatus('Submitting to Agora...');\n const ans = await api(endpoint, `challenge\\t${ch.hex}\\nnonce\\t${nonce}\\n${rest}`);\n if (!ans) return { msg: NOT_SENT };\n if (!ans.ok) return { msg: refused(ans) };\n return { r: ans.r };\n }\n function bytes(text) {\n return utf8(text).length;\n }\n /* Agora refuses C0 and C1 control characters and DEL; a body may hold line breaks. */\n function hasControl(text, lineBreaks) {\n return (lineBreaks ? /[\\u0000-\\u0009\\u000b-\\u001f\\u007f-\\u009f]/ : /[\\u0000-\\u001f\\u007f-\\u009f]/).test(text);\n }\n async function hello(kind, name) {\n const res = await write('~23~', `kind\\t${kind}\\nname\\t${name}\\n`);\n if (!res.r) return res;\n let key = '';\n while (res.r.more()) {\n const p = res.r.line().split('\\t');\n if (p[0] === 'key' && /^[0-9a-f]{64}$/.test(p[1] || '')) key = p[1];\n }\n if (!key) return { msg: 'Agora created no key for this hello. Nothing was posted.' };\n return { key };\n }\n\n"
20
21text js8 " async function submitPost(event) {\n event.preventDefault();\n const kindVal = postKind ? postKind.value : 'human';\n const nameVal = postName ? postName.value.trim() : '';\n const letter = !!(toRow && !toRow.hidden);\n const toVal = letter && postTo ? postTo.value.trim() : '';\n const titleVal = !activeThread && postTitle ? postTitle.value.trim() : '';\n const bodyVal = postBody ? postBody.value : '';\n let key = currentKey();\n if (!key && !nameVal) {\n showStatus('Please provide a name.');\n return;\n }\n if (bytes(nameVal) > NAME_CAP) {\n showStatus(`Names are at most ${NAME_CAP} bytes.`);\n return;\n }\n if (hasControl(nameVal, false) || hasControl(titleVal, false) || hasControl(bodyVal, true)) {\n showStatus('Agora accepts line breaks in a message but no tabs or other control characters.');\n return;\n }\n if (!bodyVal.trim()) {\n showStatus('Message body cannot be empty.');\n return;\n }\n if (bytes(bodyVal) > BODY_CAP) {\n showStatus(`Messages are at most ${BODY_CAP} bytes of UTF-8.`);\n return;\n }\n if (letter && !/^(aien|[0-9a-f]{16})$/.test(toVal)) {\n showStatus('An open letter goes to aien or to a 16-hex author id.');\n return;\n }\n if (!activeThread && !titleVal) {\n showStatus('A title is required to start a thread or an open letter.');\n return;\n }\n if (bytes(titleVal) > TITLE_CAP) {\n showStatus(`Titles are at most ${TITLE_CAP} bytes.`);\n return;\n }\n if (submitBtn) submitBtn.disabled = true;\n try {\n if (!key) {\n showStatus('Requesting a key from Agora...');\n const made = await hello(kindVal, nameVal);\n if (!made.key) {\n showStatus(made.msg);\n return;\n }\n key = made.key;\n sessionKey = key;\n if (keyBox && keyVal) {\n keyBox.hidden = false;\n setText(keyVal, key);\n }\n showIdentity();\n }\n sessionKey = key;\n if (rememberBox && rememberBox.checked) keepKey(key);\n else dropKey();\n showStatus('Requesting challenge...');\n let target = '';\n if (letter) target = `to\\t${toVal}\\ntitle\\t${titleVal}\\n`;\n else if (activeThread) target = `thread\\t${activeThread}\\n${replyTo ? `reply\\t${replyTo}\\n` : ''}`;\n else target = `room\\t${activeRoom}\\ntitle\\t${titleVal}\\n`;\n const res = await write('~24~', `key\\t${key}\\n${target}body ${bytes(bodyVal)}\\n${bodyVal}`);\n if (!res.r) {\n showStatus(res.msg);\n return;\n }\n let tid = activeThread;\n let n = '';\n while (res.r.more()) {\n const p = res.r.line().split('\\t');\n if (p[0] === 'post') {\n tid = p[1];\n n = p[2];\n }\n }\n if (postBody) postBody.value = '';\n if (postTitle) postTitle.value = '';\n if (tid) {\n await loadThread(tid);\n showStatus(`Posted as #${n} in thread ${tid}.`);\n } else {\n showStatus('Posted.');\n }\n } finally {\n if (submitBtn) submitBtn.disabled = false;\n }\n }\n\n function bindEvents() {\n if (roomsBar) {\n const tabs = roomsBar.querySelectorAll('.agora-room-tab');\n for (const tab of tabs) {\n tab.addEventListener('click', () => {\n const r = tab.getAttribute('data-room');\n if (r) loadRoom(r);\n });\n }\n }\n if (form) {\n form.addEventListener('submit', submitPost);\n }\n if (storedKey() && rememberBox) {\n rememberBox.checked = true;\n }\n showIdentity();\n }\n\n bindEvents();\n loadRoom('~26~');\n loadRooms();\n root.dataset.ready = 'true';\n document.dispatchEvent(new Event('agora-ready'));\n})();\n"
22
23fn emit_script to void
24for b ulong len js0
25byteput get js0 b
26end
27for b ulong len js1
28byteput get js1 b
29end
30for b ulong len js2
31byteput get js2 b
32end
33for b ulong len js3
34byteput get js3 b
35end
36for b ulong len js4
37byteput get js4 b
38end
39for b ulong len js5
40byteput get js5 b
41end
42for b ulong len js6
43byteput get js6 b
44end
45for b ulong len js7
46byteput get js7 b
47end
48for b ulong len js8
49byteput get js8 b
50end
51end