-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathask.html
More file actions
479 lines (428 loc) · 20.9 KB
/
Copy pathask.html
File metadata and controls
479 lines (428 loc) · 20.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Ask — AES Research</title>
<meta name="description" content="Try the AES Research Q&A agent — answers grounded in the published essays and skills, with citations.">
<link rel="canonical" href="https://aesresearch.ai/ask.html">
<meta property="og:type" content="website">
<meta property="og:site_name" content="AES Research">
<meta property="og:title" content="Ask — AES Research">
<meta property="og:description" content="Try the AES Research Q&A agent — answers grounded in the published essays and skills, with citations.">
<meta property="og:url" content="https://aesresearch.ai/ask.html">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Ask — AES Research">
<meta name="twitter:description" content="Try the AES Research Q&A agent — answers grounded in the published essays and skills, with citations.">
<meta name="tdm-reservation" content="1">
<meta name="robots" content="noai, noimageai">
<link rel="stylesheet" href="style.css">
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'><rect width='32' height='32' rx='7' fill='%231a4a8a'/><text x='16' y='23' font-family='Georgia,serif' font-size='21' font-weight='700' fill='%23ffffff' text-anchor='middle'>A</text></svg>">
</head>
<body>
<div class="page">
<nav class="nav" aria-label="Breadcrumb"><a href="index.html">← AES Research</a></nav>
<main>
<h1 id="ask">Ask</h1>
<p><em>Try the AES Research Q&A agent — answers grounded in the published essays and skills, with citations.</em></p>
<hr>
<p>The AES Research Q&A agent is a lightweight interface to the ideas in the writing here. Ask it to explain a concept from the essays, walk through a pattern, compare approaches, or help you figure out whether a particular architecture applies to your situation. Every answer cites the source essay or skill it draws from.</p>
<p>What the agent is good at: questions about the specific patterns documented here — two-tier memory, skeptic membranes, attention routing, context-window discipline, the maturity model, the geometry-of-calibration framing. It reads the published corpus and cites from it.</p>
<p>What the agent is not: it doesn’t have access to the internet, your codebase, or any live data. It won’t act on your behalf. It’s a read-only interface to a fixed corpus. For questions that go deeper than what the essays cover — architecture reviews, bespoke analysis, extended back-and-forth — use the “Send to research agent” button. That fires Daniel’s research agent, which writes a thorough response and sends it to Daniel for review. You’ll get a response within a few business days.</p>
<hr>
<div class="ask-widget">
<form class="ask-form" id="ask-form" novalidate>
<label class="honeypot" aria-hidden="true">
Leave this field empty
<input type="text" name="company_url" id="ask-honeypot" tabindex="-1" autocomplete="off">
</label>
<div class="ask-field">
<label for="ask-input" class="ask-label">Your question</label>
<textarea
id="ask-input"
class="ask-textarea"
name="message"
rows="4"
maxlength="2000"
placeholder="e.g. How does the two-tier memory index prevent context bloat?"
required
></textarea>
<div class="ask-charcount"><span id="ask-charcount">0</span> / 2000</div>
</div>
<!-- Cloudflare Turnstile widget -->
<div class="cf-turnstile" data-sitekey="0x4AAAAAADDznW5kWs34FNOD" id="ask-turnstile"></div>
<div class="ask-buttons">
<button type="submit" id="ask-submit" class="ask-submit-button">Ask</button>
<button type="button" id="ask-deep-trigger" class="ask-deep-button">Send to research agent →</button>
</div>
</form>
<!-- Deep-ask overlay — prompts for visitor email before firing -->
<div id="ask-deep-overlay" class="ask-deep-overlay" style="display:none" aria-modal="true" role="dialog">
<div class="ask-deep-dialog">
<p class="ask-deep-dialog-title">Send to research agent</p>
<p class="ask-deep-dialog-body">Daniel's research agent will write a thorough answer drawing on the full corpus. Daniel reviews responses personally before they go out — you'll hear back within a few business days.</p>
<label for="ask-deep-email" class="ask-label">Your email <span class="ask-optional">(optional — to be CC'd after review)</span></label>
<input type="email" id="ask-deep-email" class="ask-deep-email-input" placeholder="you@example.com" maxlength="200">
<div class="ask-deep-dialog-buttons">
<button type="button" id="ask-deep-confirm" class="ask-submit-button">Send request</button>
<button type="button" id="ask-deep-cancel" class="ask-deep-cancel-button">Cancel</button>
</div>
</div>
</div>
<!-- Conversation transcript -->
<div id="ask-transcript" class="ask-transcript" aria-live="polite" aria-atomic="false"></div>
<!-- Status message -->
<div id="ask-status" class="ask-status" role="status" aria-live="polite"></div>
</div>
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
<script>
(function () {
'use strict';
// ---------------------------------------------------------------------------
// Config
// ---------------------------------------------------------------------------
const API_BASE = 'https://api.aesresearch.ai';
const ASK_ENDPOINT = API_BASE + '/ask';
const ASK_DEEP_ENDPOINT = API_BASE + '/ask-deep';
const TIMEOUT_MS = 45000; // SSE may take longer than a JSON round-trip
// ---------------------------------------------------------------------------
// State
// ---------------------------------------------------------------------------
let sessionId = '';
let conversationHistory = []; // [{role, content}]
let abortController = null;
function generateSessionId() {
if (typeof crypto !== 'undefined' && crypto.randomUUID) return crypto.randomUUID();
return 'sess-' + Math.random().toString(36).slice(2) + Date.now().toString(36);
}
// ---------------------------------------------------------------------------
// DOM refs
// ---------------------------------------------------------------------------
const form = document.getElementById('ask-form');
const textarea = document.getElementById('ask-input');
const charCount = document.getElementById('ask-charcount');
const submitBtn = document.getElementById('ask-submit');
const deepTrigger = document.getElementById('ask-deep-trigger');
const deepOverlay = document.getElementById('ask-deep-overlay');
const deepEmailInput = document.getElementById('ask-deep-email');
const deepConfirmBtn = document.getElementById('ask-deep-confirm');
const deepCancelBtn = document.getElementById('ask-deep-cancel');
const transcript = document.getElementById('ask-transcript');
const statusEl = document.getElementById('ask-status');
const honeypot = document.getElementById('ask-honeypot');
// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------
function setStatus(msg, isError) {
statusEl.textContent = msg;
statusEl.className = 'ask-status' + (isError ? ' ask-status-error' : '');
}
function clearStatus() {
statusEl.textContent = '';
statusEl.className = 'ask-status';
}
function getTurnstileToken() {
if (typeof turnstile === 'undefined') return '';
try { return turnstile.getResponse(document.getElementById('ask-turnstile')); } catch { return ''; }
}
function resetTurnstile() {
if (typeof turnstile !== 'undefined') {
try { turnstile.reset(document.getElementById('ask-turnstile')); } catch {}
}
}
function setFormBusy(busy) {
submitBtn.disabled = busy;
deepTrigger.disabled = busy;
textarea.disabled = busy;
submitBtn.textContent = busy ? 'Asking…' : 'Ask';
}
// Append a turn block to the transcript
function appendTurn(role, html) {
const div = document.createElement('div');
div.className = role === 'user' ? 'ask-message-user' : 'ask-message-agent';
div.innerHTML = html;
transcript.appendChild(div);
div.scrollIntoView({ behavior: 'smooth', block: 'start' });
return div;
}
// Append a citation pill after an agent turn
function appendCitation(container, essay, snippet) {
const pill = document.createElement('span');
pill.className = 'ask-citation';
pill.title = snippet || essay;
pill.textContent = '📄 ' + essay;
let citationsRow = container.querySelector('.ask-citation-row');
if (!citationsRow) {
citationsRow = document.createElement('div');
citationsRow.className = 'ask-citation-row';
container.appendChild(citationsRow);
}
citationsRow.appendChild(pill);
}
// Minimal markdown-to-HTML: bold, italic, inline code, line breaks.
// Full markdown is not needed; the agent output is prose, not complex docs.
function minimalMarkdown(text) {
return text
// Quotes are escaped here, with the angle brackets, because `url` below is
// concatenated into an href="..." attribute. Without this a '"' in a
// destination closes the attribute and everything after it becomes further
// attributes — including event handlers. The Worker's egress sanitizer is the
// control that stops attacker bytes reaching this function at all; this escape
// is the second, renderer-side reason the same payload cannot execute.
.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
.replace(/"/g, '"').replace(/'/g, ''')
// [label](url) → link, but only to this site (root-relative, anchor,
// dot-relative, or aesresearch.ai) or mailto:. Agent output can hallucinate
// URLs, so any other target — external domains, protocol-relative //host,
// javascript:/data: — renders as the plain label, never a clickable link.
// label + url are already HTML-escaped above.
.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, function (m, label, url) {
var safe = /^\/(?!\/)/.test(url) || /^#/.test(url) || /^\.{1,2}\//.test(url)
|| /^mailto:/i.test(url) || /^https?:\/\/(www\.)?aesresearch\.ai([/?#]|$)/i.test(url);
return safe ? '<a href="' + url + '" rel="noopener">' + label + '</a>' : label;
})
.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>')
.replace(/\*(.+?)\*/g, '<em>$1</em>')
.replace(/`([^`]+)`/g, '<code>$1</code>')
.replace(/\n\n/g, '</p><p>')
.replace(/\n/g, '<br>');
}
// ---------------------------------------------------------------------------
// /ask — SSE streaming
// ---------------------------------------------------------------------------
async function submitQuestion(message) {
if (!sessionId) sessionId = generateSessionId();
// Append user turn
appendTurn('user', minimalMarkdown(message));
// Append empty agent turn that we'll fill as deltas arrive
const agentTurn = appendTurn('agent', '');
let agentText = '';
setFormBusy(true);
clearStatus();
abortController = new AbortController();
const timeoutId = setTimeout(() => abortController.abort(), TIMEOUT_MS);
let ok = false;
try {
const payload = {
session_id: sessionId,
message: message,
history: conversationHistory.slice(-10),
cf_turnstile_token: getTurnstileToken(),
};
const resp = await fetch(ASK_ENDPOINT, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
signal: abortController.signal,
});
if (!resp.ok) {
const err = await resp.json().catch(() => ({}));
const httpErr = new Error(err.error || 'Request failed (' + resp.status + ')');
httpErr.status = resp.status;
throw httpErr;
}
// SSE reader
const reader = resp.body.getReader();
const decoder = new TextDecoder();
let sseBuffer = '';
while (true) {
const { value, done } = await reader.read();
if (done) break;
sseBuffer += decoder.decode(value, { stream: true });
let idx;
while ((idx = sseBuffer.indexOf('\n\n')) !== -1) {
const frame = sseBuffer.slice(0, idx);
sseBuffer = sseBuffer.slice(idx + 2);
let eventName = 'message';
let dataStr = '';
for (const line of frame.split('\n')) {
if (line.startsWith('event:')) eventName = line.slice(6).trim();
else if (line.startsWith('data:')) dataStr = line.slice(5).trim();
}
if (!dataStr) continue;
let data;
try { data = JSON.parse(dataStr); } catch { continue; }
if (eventName === 'delta') {
agentText += data.text || '';
agentTurn.innerHTML = '<p>' + minimalMarkdown(agentText) + '</p>';
} else if (eventName === 'citation') {
appendCitation(agentTurn, data.essay, data.snippet);
} else if (eventName === 'escalate') {
const note = document.createElement('div');
note.className = 'ask-escalate-note';
note.innerHTML = 'This question is outside the corpus scope'
+ (data.reason ? ' (' + minimalMarkdown(data.reason) + ')' : '') + '. '
+ 'Try the <button class="ask-escalate-deep-btn" type="button">research agent</button> for a thorough response.';
note.querySelector('.ask-escalate-deep-btn').addEventListener('click', openDeepOverlay);
agentTurn.appendChild(note);
} else if (eventName === 'done') {
ok = true;
// Save to history
conversationHistory.push({ role: 'user', content: message });
conversationHistory.push({ role: 'assistant', content: agentText });
if (conversationHistory.length > 20) conversationHistory = conversationHistory.slice(-20);
} else if (eventName === 'error') {
throw new Error(data.message || 'Stream error');
}
}
}
if (!ok) {
// Stream closed without done event — still treat as success if we got text
if (agentText) {
conversationHistory.push({ role: 'user', content: message });
conversationHistory.push({ role: 'assistant', content: agentText });
}
}
} catch (e) {
if (e.name === 'AbortError') {
setStatus('Request timed out. Please try again.', true);
} else if ((e.status && e.status >= 500) || e.name === 'TypeError') {
// Backend down (5xx) or network failure — honest offline notice, not a raw error.
setStatus('The Q&A agent is temporarily offline while its backend is restored. The essays cover the core patterns in the meantime, and the contact page reaches Daniel directly.', true);
} else {
setStatus(e.message || 'Something went wrong. Please try again.', true);
}
if (!agentText) agentTurn.remove();
} finally {
clearTimeout(timeoutId);
abortController = null;
setFormBusy(false);
resetTurnstile();
}
}
// ---------------------------------------------------------------------------
// /ask-deep — async Routine fire
// ---------------------------------------------------------------------------
function openDeepOverlay() {
deepOverlay.style.display = '';
deepEmailInput.focus();
}
async function fireDeepRequest(requestedByEmail) {
if (!sessionId) sessionId = generateSessionId();
const message = textarea.value.trim();
if (!message) {
setStatus('Enter a question first, then click "Send to research agent".', true);
return;
}
deepConfirmBtn.disabled = true;
deepConfirmBtn.textContent = 'Sending…';
clearStatus();
try {
const payload = {
session_id: sessionId,
message: message,
history: conversationHistory.slice(-10),
requested_by_email: requestedByEmail,
cf_turnstile_token: getTurnstileToken(),
};
const abortCtrl = new AbortController();
const tid = setTimeout(() => abortCtrl.abort(), 15000);
const resp = await fetch(ASK_DEEP_ENDPOINT, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
signal: abortCtrl.signal,
});
clearTimeout(tid);
if (!resp.ok) {
const err = await resp.json().catch(() => ({}));
const httpErr = new Error(err.error || 'Request failed (' + resp.status + ')');
httpErr.status = resp.status;
throw httpErr;
}
const data = await resp.json().catch(() => ({}));
if (!data.ok) throw new Error(data.error || 'Failed to queue request');
deepOverlay.style.display = 'none';
appendTurn('agent',
'<p><strong>Sent to research agent.</strong> Daniel reviews these personally; '
+ 'you\'ll get a response within a few business days.'
+ (requestedByEmail ? ' We have your email.' : '') + '</p>');
resetTurnstile();
} catch (e) {
if (e.name === 'AbortError') {
setStatus('Request timed out. Please try again.', true);
} else if ((e.status && e.status >= 500) || e.name === 'TypeError') {
setStatus('The research-agent dispatch is temporarily offline. The contact page is the reliable path in the meantime.', true);
} else {
setStatus(e.message || 'Something went wrong. Please try again.', true);
}
} finally {
deepConfirmBtn.disabled = false;
deepConfirmBtn.textContent = 'Send request';
}
}
// ---------------------------------------------------------------------------
// Event wiring
// ---------------------------------------------------------------------------
textarea.addEventListener('input', function () {
charCount.textContent = textarea.value.length;
});
form.addEventListener('submit', function (e) {
e.preventDefault();
if (honeypot && honeypot.value) return; // bot trap
const message = textarea.value.trim();
if (!message) { setStatus('Please enter a question.', true); return; }
submitQuestion(message);
textarea.value = '';
charCount.textContent = '0';
});
deepTrigger.addEventListener('click', function () {
if (honeypot && honeypot.value) return;
openDeepOverlay();
});
deepConfirmBtn.addEventListener('click', function () {
const email = deepEmailInput.value.trim();
fireDeepRequest(email);
});
deepCancelBtn.addEventListener('click', function () {
deepOverlay.style.display = 'none';
});
// Close overlay on backdrop click
deepOverlay.addEventListener('click', function (e) {
if (e.target === deepOverlay) deepOverlay.style.display = 'none';
});
// Close overlay on Escape
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape' && deepOverlay.style.display !== 'none') {
deepOverlay.style.display = 'none';
}
});
})();
</script>
<!--
CSS classes used by this page (add to style.css in a follow-up pass):
.ask-widget — outer container for the form + transcript
.ask-form — the question form
.ask-field — label + textarea wrapper
.ask-label — field label
.ask-textarea — question textarea
.ask-charcount — character count row below textarea
.ask-buttons — flex row holding the two buttons
.ask-submit-button — primary "Ask" button (and "Send request" in dialog)
.ask-deep-button — secondary "Send to research agent" button
.ask-transcript — scrollable conversation area
.ask-message-user — a user turn in the transcript
.ask-message-agent — an agent turn in the transcript
.ask-citation-row — flex row of citation pills below an agent turn
.ask-citation — a single citation pill (essay name, hover = snippet)
.ask-escalate-note — inline note when agent emits <escalate/>
.ask-escalate-deep-btn — inline text-button inside escalate note
.ask-status — status / error message below the form
.ask-status-error — modifier: red text for errors
.ask-optional — muted secondary text (e.g., "optional" label hint)
.ask-deep-overlay — full-screen semi-transparent overlay for deep-ask dialog
.ask-deep-dialog — the dialog box inside the overlay
.ask-deep-dialog-title — dialog heading
.ask-deep-dialog-body — dialog explanatory paragraph
.ask-deep-email-input — email input inside the dialog
.ask-deep-dialog-buttons — flex row holding confirm + cancel buttons
.ask-deep-cancel-button — cancel button inside the dialog
-->
</main>
<footer>
<p>AES Research · Applied Emergent Sciences · Houston · 2026</p>
<p class="footer-legal">Written works licensed <a href="https://creativecommons.org/licenses/by-sa/4.0/">CC BY-SA 4.0</a> · code licensed separately · <a href="license.html">Licensing & citation</a></p>
</footer>
</div>
</body>
</html>