Complete Page Setup: HTML Markup, Cell Registry & Edge Stream Wiring
Live <ai-prompt> tags in public/index.html, cell/pin/IVM configuration from
public/lib/cell-engine.js and public/lib/ai-prompt-element.js, and
POST /api/cell-run streaming in public/app.js and src/worker.ts.
<!-- 1. Page HTML Setup (public/index.html) -->
<input id="studio-product" value="EdgeCell Studio v2" />
<input id="studio-audience" value="Platform & AI systems engineers" />
<select id="studio-tone"><option value="direct architectural">direct architectural</option></select>
<output id="matrix"></output>
<ai-prompt
id="cell-brief"
label="Executive Brief"
watch="#studio-product, #studio-audience, #studio-budget, #studio-tone, #matrix"
mode="auto"
policy="switch"
prompt="Write an Executive Launch Brief.
Product: {{studio-product}}
Audience: {{studio-audience}}
Budget: {{studio-budget}}
Tone: {{studio-tone}}
Feature Matrix: {{matrix}}"
></ai-prompt>
<script type="module" src="/app.js"></script>
// 2. Cell, Pinning & IVM Schema Config (public/lib/ai-prompt-element.js + public/lib/cell-engine.js)
static observedAttributes = ['watch', 'policy', 'mode', 'debounce', 'prompt', 'model', 'system', 'frozen'];
engine.registerCell({
id: 'cell-brief',
label: 'Executive Brief',
template: this.#resolvePromptTemplate(),
deps: ['studio-product', 'studio-audience', 'studio-budget', 'studio-tone', 'matrix'],
mode: 'auto', // 'auto' | 'debounce' | 'manual' | 'frozen'
policy: 'switch', // 'switch' | 'exhaust' | 'concat'
debounceMs: 350,
model: 'worker-edge',
pinned: false, pinnedValue: '', baseHash: '', candidateValue: '', candidateHash: '',
});
// Content-addressed cache key + KeyedCollectionIVM row signature:
const hash = hashPromptConfig(resolvedPrompt, { mode: cell.mode, policy: cell.policy, model: cell.model });
const rowHash = hashPromptConfig(`row(${orderedFields}) ctx(${orderedContext})`, { kind: 'ivm-row', collectionId: 'matrix' });
// 3. Page Bootstrap & /api/cell-run Edge Wiring (public/app.js + src/worker.ts)
const cache = new PromptCache();
const engine = new CellGraphEngine({ runner: unifiedRunner, cache });
const collection = new KeyedCollectionIVM({ id: 'matrix', cache, rowRunner });
engine.attachCollection(collection);
AiPromptElement.setDefaultEngine(engine);
for (const el of document.querySelectorAll('ai-prompt')) el.connectEngine(engine, document);
await engine.evaluateAll();
// unifiedRunner falls back from LanguageModel to POST /api/cell-run NDJSON with AbortSignal:
const response = await fetch('/api/cell-run', {
method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ cellId: ctx.cellId, resolvedPrompt: ctx.prompt, hash: ctx.hash, mode, policy }),
signal: ctx.signal,
});
// src/worker.ts: if (url.pathname === '/api/cell-run') return await handleCellRun(request);
What disappears
Hidden JavaScript closure graphs, manual removeEventListener teardown tracking, duplicate inference calls on undo or revert, and silent overwrites of pinned human edits.
What becomes explicit
Inspectable watch selector edges, recalculation gates (auto, debounce, manual, frozen), concurrency policies (switch, exhaust, concat), fnv1a64 cache hits, and keepPinned/acceptCandidate/mergeCandidate conflict resolution.
Platform gaps remaining
HTML has no native <ai-prompt> element or declarative dependency scheduler; Custom Elements must implement AbortController listener lifecycles, PromptCache memoization, and Worker NDJSON adapters in userland JavaScript.