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(pipeline-studio): visual pipeline authoring page

nirholasea358d0bc327
diff --git a/pages/pipeline-studio.html b/pages/pipeline-studio.html
new file mode 100644
index 000000000..7e94a6679
--- /dev/null
+++ b/pages/pipeline-studio.html
@@ -0,0 +1,312 @@
+<!doctype html>
+<html lang="en" class="cookbook-page">
+ <head>
+ <script>/* three.ws theme boot: no-flash; runtime in /theme-switcher.js */(function(){try{var m=localStorage.getItem('twx_theme');var l=m==='auto'?(window.matchMedia&&window.matchMedia('(prefers-color-scheme: light)').matches):m==='light';document.documentElement.setAttribute('data-theme',l?'light':'dark');}catch(e){document.documentElement.setAttribute('data-theme','dark');}})();</script>
+ <meta charset="utf-8" />
+ <meta http-equiv="X-UA-Compatible" content="IE=edge" />
+ <title>three.ws: Pipeline Studio</title>
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+ <meta name="author" content="nirholas" />
+ <meta
+ name="description"
+ content="Run the whole 3D asset pipeline in your browser: generate a pack of models from prompts, render each one, gate them against a triangle and size budget, then export the manifest and the exact commands to reproduce the run locally. Free, keyless, no install."
+ />
+ <meta name="theme-color" content="#000000" />
+
+ <meta property="og:type" content="website" />
+ <meta property="og:site_name" content="three.ws" />
+ <meta property="og:title" content="three.ws: Pipeline Studio" />
+ <meta
+ property="og:description"
+ content="Generate, render, and quality-gate a whole pack of 3D models in the browser. Free and keyless, and it exports the CLI commands that reproduce the run."
+ />
+ <meta property="og:url" content="https://three.ws/cookbook/pipeline" />
+ <meta
+ property="og:image"
+ content="https://three.ws/api/page-og?s=learn&amp;t=Pipeline+Studio&amp;d=Generate%2C+render%2C+and+gate+a+pack+of+3D+models+in+the+browser&amp;p=%2Fcookbook%2Fpipeline"
+ />
+ <meta property="og:image:width" content="1200" />
+ <meta property="og:image:height" content="630" />
+
+ <meta name="twitter:card" content="summary_large_image" />
+ <meta name="twitter:title" content="three.ws: Pipeline Studio" />
+ <meta
+ name="twitter:description"
+ content="Generate, render, and quality-gate a whole pack of 3D models in the browser. Free and keyless, and it exports the CLI commands that reproduce the run."
+ />
+ <meta
+ name="twitter:image"
+ content="https://three.ws/api/page-og?s=learn&amp;t=Pipeline+Studio&amp;d=Generate%2C+render%2C+and+gate+a+pack+of+3D+models+in+the+browser&amp;p=%2Fcookbook%2Fpipeline"
+ />
+
+ <link rel="canonical" href="https://three.ws/cookbook/pipeline" />
+ <link rel="icon" href="/favicon.ico" sizes="any" />
+ <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
+ <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
+ <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
+ <link rel="apple-touch-icon" href="/apple-touch-icon.png" />
+ <link rel="manifest" href="/manifest.webmanifest" />
+ <link rel="stylesheet" href="/style.css" />
+ <link rel="stylesheet" href="/nav.css" />
+ <link rel="stylesheet" href="/footer.css" />
+ <link rel="stylesheet" href="/fonts/fonts.css" />
+ <link rel="stylesheet" href="/mobile.css" />
+ <link rel="stylesheet" href="/cookbook.css" />
+ <link rel="stylesheet" href="/pipeline-studio.css" />
+ <script defer src="/nav.js"></script>
+ <script defer src="/footer-newsletter.js"></script>
+ <script defer src="/pipeline-studio.js"></script>
+ </head>
+ <body>
+ <div class="cb-page">
+ <header><div id="nav-container"></div></header>
+
+ <main id="main-content">
+ <section class="cb-hero pl-hero">
+ <div class="cb-hero-inner">
+ <span class="cb-eyebrow"><a href="/cookbook">Cookbook</a> / Studio</span>
+ <h1>Pipeline Studio</h1>
+ <p>
+ The cookbook's four stages, running here instead of on your machine. Give it a
+ list of prompts and it generates every model on the free lane, renders each one,
+ inspects it against a budget you set, and hands you the manifest plus the exact
+ commands to reproduce the whole run locally.
+ </p>
+ <div class="cb-hero-meta">
+ <span>No API key</span>
+ <span>No install</span>
+ <span>Real <a href="/docs/3d-api">3D API</a>, real models</span>
+ </div>
+ </div>
+ </section>
+
+ <div class="pl-shell">
+ <!-- ── Controls ─────────────────────────────────────────────── -->
+ <form class="pl-rail" id="pl-form" novalidate>
+ <section class="pl-panel">
+ <h2 class="pl-panel-title">
+ <span class="pl-step">1</span> Prompts
+ <button
+ class="pl-hint"
+ type="button"
+ data-hint="The free lane is single-subject. &quot;a brass watering can&quot; works; &quot;a kitchen with a table and three chairs&quot; produces a blob. One object per line, with a material and a shape."
+ >
+ <span aria-hidden="true">?</span>
+ <span class="pl-sr">What makes a good prompt?</span>
+ </button>
+ </h2>
+ <p class="pl-panel-note">One object per line.</p>
+ <label class="pl-sr" for="pl-prompts">Prompts, one per line</label>
+ <textarea
+ id="pl-prompts"
+ name="prompts"
+ rows="5"
+ spellcheck="false"
+ aria-describedby="pl-prompt-count"
+ ></textarea>
+ <p class="pl-count" id="pl-prompt-count" aria-live="polite"></p>
+
+ <div class="pl-presets" role="group" aria-label="Load a preset pack">
+ <span class="pl-presets-label">Or load a pack:</span>
+ <div class="pl-preset-row" id="pl-presets"></div>
+ </div>
+ </section>
+
+ <section class="pl-panel">
+ <h2 class="pl-panel-title">
+ <span class="pl-step">2</span> Budget
+ <button
+ class="pl-hint"
+ type="button"
+ data-hint="The gate runs the same rules as asset_gate.py, so a verdict here is the verdict your CI will reach. Numbers that hurt a real user are failures; everything else is a note."
+ >
+ <span aria-hidden="true">?</span>
+ <span class="pl-sr">How is the budget applied?</span>
+ </button>
+ </h2>
+ <p class="pl-panel-note">The bar every model has to clear.</p>
+
+ <div class="pl-field">
+ <label for="pl-tri">Max triangles</label>
+ <input
+ id="pl-tri"
+ name="maxTriangles"
+ type="number"
+ min="100"
+ max="2000000"
+ step="1000"
+ value="100000"
+ inputmode="numeric"
+ />
+ </div>
+
+ <div class="pl-field">
+ <label for="pl-mb">Max size (MB)</label>
+ <input
+ id="pl-mb"
+ name="maxSizeMb"
+ type="number"
+ min="0.1"
+ max="64"
+ step="0.5"
+ value="8"
+ inputmode="decimal"
+ />
+ </div>
+
+ <div class="pl-field">
+ <label for="pl-mat">Max materials</label>
+ <input
+ id="pl-mat"
+ name="maxMaterials"
+ type="number"
+ min="0"
+ max="256"
+ step="1"
+ value="16"
+ inputmode="numeric"
+ />
+ </div>
+
+ <label class="pl-check">
+ <input id="pl-req-tex" name="requireTextures" type="checkbox" />
+ <span>Require textures</span>
+ <button
+ class="pl-hint"
+ type="button"
+ data-hint="Fails any model that ships no texture images. Leave this off unless your renderer genuinely cannot handle vertex-coloured geometry."
+ >
+ <span aria-hidden="true">?</span>
+ <span class="pl-sr">What does requiring textures do?</span>
+ </button>
+ </label>
+
+ <label class="pl-check">
+ <input id="pl-req-mat" name="requireMaterials" type="checkbox" />
+ <span>Require materials</span>
+ <button
+ class="pl-hint"
+ type="button"
+ data-hint="Zero materials is normally a note, not a failure: the draft lane often returns vertex-coloured geometry that renders in full colour with no material at all. Turn this on only if you need real PBR materials."
+ >
+ <span aria-hidden="true">?</span>
+ <span class="pl-sr">What does requiring materials do?</span>
+ </button>
+ </label>
+ </section>
+
+ <section class="pl-panel">
+ <h2 class="pl-panel-title">
+ <span class="pl-step">3</span> Run
+ <button
+ class="pl-hint"
+ type="button"
+ data-hint="Three at a time matches the cookbook's asset_pack.py. The free lane is a shared GPU pool, so twenty parallel jobs do not finish sooner, they queue behind each other and burn poll requests."
+ >
+ <span aria-hidden="true">?</span>
+ <span class="pl-sr">Why is concurrency capped?</span>
+ </button>
+ </h2>
+
+ <div class="pl-field">
+ <label for="pl-workers">Models at a time</label>
+ <input
+ id="pl-workers"
+ name="workers"
+ type="number"
+ min="1"
+ max="4"
+ step="1"
+ value="3"
+ inputmode="numeric"
+ />
+ </div>
+
+ <div class="pl-actions">
+ <button class="pl-btn primary" type="submit" id="pl-run">
+ Run pipeline
+ <kbd>&#8984;&#8629;</kbd>
+ </button>
+ <button class="pl-btn" type="button" id="pl-stop" hidden>Stop</button>
+ </div>
+ <p class="pl-eta" id="pl-eta"></p>
+ </section>
+
+ <section class="pl-panel pl-log-panel">
+ <h2 class="pl-panel-title">Run log</h2>
+ <ol class="pl-log" id="pl-log" aria-live="polite" aria-relevant="additions"></ol>
+ </section>
+ </form>
+
+ <!-- ── Results ──────────────────────────────────────────────── -->
+ <div class="pl-results">
+ <ol class="pl-stages" id="pl-stages">
+ <li data-stage="generate">
+ <span class="pl-stage-name">Generate</span>
+ <span class="pl-stage-num" data-count="generate">0</span>
+ </li>
+ <li data-stage="render">
+ <span class="pl-stage-name">Render</span>
+ <span class="pl-stage-num" data-count="render">0</span>
+ </li>
+ <li data-stage="gate">
+ <span class="pl-stage-name">Gate</span>
+ <span class="pl-stage-num" data-count="gate">0</span>
+ </li>
+ <li data-stage="export">
+ <span class="pl-stage-name">Export</span>
+ <span class="pl-stage-num" data-count="export">0</span>
+ </li>
+ </ol>
+
+ <div class="pl-verdict" id="pl-verdict" hidden></div>
+
+ <ul class="pl-grid" id="pl-grid"></ul>
+
+ <div class="pl-intro" id="pl-intro">
+ <h2>Nothing has run yet</h2>
+ <p>
+ The prompts on the left are already a working pack. Press
+ <strong>Run pipeline</strong> and watch four stages happen: every prompt becomes
+ a real GLB on the free lane, each model gets rendered to a still, each still gets
+ inspected against your budget, and the whole thing becomes a manifest you can
+ download.
+ </p>
+ <p class="pl-intro-time">
+ A pack of three takes roughly two minutes. Nothing is charged and nothing is
+ stored on your account, because there is no account.
+ </p>
+ </div>
+
+ <section class="pl-export" id="pl-export" hidden>
+ <h2>Take it with you</h2>
+ <p>
+ This run happened in a browser tab. The same pipeline as files on your machine,
+ with the budget you just set:
+ </p>
+ <div class="pl-export-actions">
+ <button class="pl-btn primary" type="button" id="pl-dl-manifest">
+ Download manifest.json
+ </button>
+ <button class="pl-btn" type="button" id="pl-dl-all">Download every GLB</button>
+ <button class="pl-btn" type="button" id="pl-share">Copy share link</button>
+ </div>
+ <h3>Reproduce it locally</h3>
+ <pre class="pl-code"><code id="pl-repro"></code></pre>
+ <button class="pl-btn subtle" type="button" id="pl-copy-repro">Copy commands</button>
+ <p class="pl-export-foot">
+ Both files come from the cookbook:
+ <a href="/cookbook/parallel-asset-pack">parallel asset pack</a> and
+ <a href="/cookbook/asset-quality-gate">the CI quality gate</a>.
+ </p>
+ </section>
+ </div>
+ </div>
+ </main>
+
+ <footer id="site-footer"></footer>
+ </div>
+
+ <div class="pl-tip" id="pl-tip" role="tooltip" hidden></div>
+ </body>
+</html>
diff --git a/public/pipeline-studio.css b/public/pipeline-studio.css
new file mode 100644
index 000000000..70b8d73e0
--- /dev/null
+++ b/public/pipeline-studio.css
@@ -0,0 +1,925 @@
+/*
+ * Pipeline Studio (/cookbook/playground).
+ *
+ * Layers on top of cookbook.css, which already owns the page shell, the sticky
+ * header and the hero. Everything below is expressed in tokens.css variables, so
+ * the light and dark themes both work with no per-theme block of its own.
+ */
+
+.pl-hero .cb-hero-inner p {
+ max-width: 62ch;
+}
+
+.pl-hero .cb-eyebrow a {
+ color: inherit;
+ text-decoration: none;
+ border-bottom: 1px solid var(--stroke-strong);
+}
+
+.pl-hero .cb-eyebrow a:hover {
+ color: var(--ink-bright);
+ border-bottom-color: var(--ink-bright);
+}
+
+/* ── Shell ─────────────────────────────────────────────────────────────── */
+
+.pl-shell {
+ flex: 1;
+ width: 100%;
+ max-width: 1320px;
+ margin: 0 auto;
+ padding: clamp(1.5rem, 4vh, 2.5rem) clamp(1.15rem, 4vw, 2rem) clamp(3rem, 8vh, 5rem);
+ display: grid;
+ grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
+ gap: clamp(1.25rem, 3vw, 2.25rem);
+ align-items: start;
+}
+
+@media (max-width: 960px) {
+ .pl-shell {
+ grid-template-columns: minmax(0, 1fr);
+ }
+}
+
+/* ── Control rail ──────────────────────────────────────────────────────── */
+
+.pl-rail {
+ display: flex;
+ flex-direction: column;
+ gap: 0.9rem;
+ position: sticky;
+ top: calc(var(--header-h) + 1rem);
+}
+
+@media (max-width: 960px) {
+ .pl-rail {
+ position: static;
+ }
+}
+
+.pl-panel {
+ background: var(--surface-1);
+ border: 1px solid var(--stroke);
+ border-radius: var(--radius-lg);
+ padding: 1rem 1.05rem 1.1rem;
+}
+
+.pl-panel-title {
+ display: flex;
+ align-items: center;
+ gap: 0.5rem;
+ margin: 0;
+ font-family: var(--font-display);
+ font-size: var(--text-ui);
+ font-weight: var(--weight-semibold);
+ letter-spacing: 0.01em;
+ color: var(--ink-bright);
+}
+
+.pl-step {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ width: 1.35rem;
+ height: 1.35rem;
+ border-radius: var(--radius-pill);
+ background: var(--surface-3);
+ border: 1px solid var(--stroke-strong);
+ font-size: var(--text-2xs);
+ font-variant-numeric: tabular-nums;
+ color: var(--ink-dim);
+}
+
+.pl-panel-note {
+ margin: 0.35rem 0 0.7rem;
+ font-size: var(--text-sm);
+ color: var(--ink-faint);
+ line-height: var(--leading-tight);
+}
+
+.pl-sr {
+ position: absolute;
+ width: 1px;
+ height: 1px;
+ padding: 0;
+ margin: -1px;
+ overflow: hidden;
+ clip: rect(0, 0, 0, 0);
+ white-space: nowrap;
+ border: 0;
+}
+
+/* ── Fields ────────────────────────────────────────────────────────────── */
+
+#pl-prompts {
+ width: 100%;
+ resize: vertical;
+ min-height: 6.5rem;
+ padding: 0.65rem 0.7rem;
+ background: var(--bg-0);
+ border: 1px solid var(--stroke-strong);
+ border-radius: var(--radius-md);
+ color: var(--ink);
+ font-family: var(--font-mono);
+ font-size: var(--text-md);
+ line-height: 1.7;
+ transition: border-color var(--duration-fast) var(--ease-standard);
+}
+
+#pl-prompts:hover {
+ border-color: var(--ink-dim);
+}
+
+#pl-prompts:focus-visible,
+.pl-field input:focus-visible {
+ outline: var(--focus-ring-width) solid var(--focus-ring-color);
+ outline-offset: 2px;
+ border-color: transparent;
+}
+
+.pl-count {
+ margin: 0.45rem 0 0;
+ font-size: var(--text-2xs);
+ color: var(--ink-dim);
+ font-variant-numeric: tabular-nums;
+}
+
+.pl-field {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 0.75rem;
+ margin-top: 0.55rem;
+}
+
+.pl-field label {
+ font-size: var(--text-sm);
+ color: var(--ink-faint);
+}
+
+.pl-field input {
+ width: 6.5rem;
+ padding: 0.4rem 0.55rem;
+ background: var(--bg-0);
+ border: 1px solid var(--stroke-strong);
+ border-radius: var(--radius-sm);
+ color: var(--ink);
+ font-family: var(--font-mono);
+ font-size: var(--text-md);
+ text-align: right;
+ font-variant-numeric: tabular-nums;
+ transition: border-color var(--duration-fast) var(--ease-standard);
+}
+
+.pl-field input:hover {
+ border-color: var(--ink-dim);
+}
+
+.pl-check {
+ display: flex;
+ align-items: center;
+ gap: 0.5rem;
+ margin-top: 0.6rem;
+ font-size: var(--text-sm);
+ color: var(--ink-faint);
+ cursor: pointer;
+}
+
+.pl-check input {
+ width: 1rem;
+ height: 1rem;
+ accent-color: var(--ink-bright);
+ cursor: pointer;
+}
+
+.pl-check:hover {
+ color: var(--ink);
+}
+
+/* ── Presets ───────────────────────────────────────────────────────────── */
+
+.pl-presets {
+ margin-top: 0.85rem;
+ padding-top: 0.85rem;
+ border-top: 1px solid var(--hairline);
+}
+
+.pl-presets-label {
+ display: block;
+ font-size: var(--text-2xs);
+ text-transform: uppercase;
+ letter-spacing: 0.08em;
+ color: var(--ink-dim);
+ margin-bottom: 0.5rem;
+}
+
+.pl-preset-row {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 0.35rem;
+}
+
+.pl-preset {
+ padding: 0.3rem 0.6rem;
+ background: var(--surface-2);
+ border: 1px solid var(--stroke);
+ border-radius: var(--radius-pill);
+ color: var(--ink-faint);
+ font-family: inherit;
+ font-size: var(--text-2xs);
+ cursor: pointer;
+ transition:
+ background var(--duration-fast) var(--ease-standard),
+ color var(--duration-fast) var(--ease-standard),
+ border-color var(--duration-fast) var(--ease-standard);
+}
+
+.pl-preset:hover {
+ background: var(--surface-3);
+ border-color: var(--stroke-strong);
+ color: var(--ink-bright);
+}
+
+.pl-preset:active {
+ transform: translateY(1px);
+}
+
+.pl-preset:focus-visible {
+ outline: var(--focus-ring-width) solid var(--focus-ring-color);
+ outline-offset: 2px;
+}
+
+/* ── Buttons ───────────────────────────────────────────────────────────── */
+
+.pl-btn {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ gap: 0.45rem;
+ padding: 0.5rem 0.85rem;
+ background: var(--surface-2);
+ border: 1px solid var(--stroke-strong);
+ border-radius: var(--radius-md);
+ color: var(--ink);
+ font-family: inherit;
+ font-size: var(--text-ui);
+ font-weight: var(--weight-medium);
+ text-decoration: none;
+ cursor: pointer;
+ transition:
+ background var(--duration-fast) var(--ease-standard),
+ border-color var(--duration-fast) var(--ease-standard),
+ transform var(--duration-instant) var(--ease-standard);
+}
+
+.pl-btn:hover {
+ background: var(--surface-3);
+ border-color: var(--ink-dim);
+ color: var(--ink-bright);
+}
+
+.pl-btn:active {
+ transform: translateY(1px);
+}
+
+.pl-btn:focus-visible {
+ outline: var(--focus-ring-width) solid var(--focus-ring-color);
+ outline-offset: 2px;
+}
+
+.pl-btn[disabled] {
+ opacity: 0.55;
+ cursor: progress;
+}
+
+.pl-btn.primary {
+ background: var(--ink-bright);
+ border-color: var(--ink-bright);
+ color: var(--bg-0);
+ font-weight: var(--weight-semibold);
+}
+
+.pl-btn.primary:hover {
+ background: var(--ink);
+ border-color: var(--ink);
+ color: var(--bg-0);
+}
+
+.pl-btn.subtle {
+ padding: 0.3rem 0.6rem;
+ font-size: var(--text-2xs);
+ background: transparent;
+ border-color: var(--stroke);
+ color: var(--ink-faint);
+}
+
+.pl-btn.subtle:hover {
+ background: var(--surface-2);
+ color: var(--ink-bright);
+}
+
+.pl-btn kbd {
+ font-family: var(--font-mono);
+ font-size: var(--text-2xs);
+ opacity: 0.7;
+ border: 0;
+ background: none;
+ padding: 0;
+}
+
+.pl-actions {
+ display: flex;
+ gap: 0.5rem;
+ margin-top: 0.9rem;
+}
+
+.pl-actions .pl-btn {
+ flex: 1;
+}
+
+.pl-eta {
+ margin: 0.6rem 0 0;
+ font-size: var(--text-2xs);
+ color: var(--ink-dim);
+ min-height: 1em;
+}
+
+/* ── Hint buttons and the tooltip ──────────────────────────────────────── */
+
+.pl-hint {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ width: 1.05rem;
+ height: 1.05rem;
+ flex: 0 0 auto;
+ margin-left: auto;
+ padding: 0;
+ background: var(--surface-3);
+ border: 1px solid var(--stroke-strong);
+ border-radius: var(--radius-pill);
+ color: var(--ink-dim);
+ font-family: inherit;
+ font-size: 0.6rem;
+ font-weight: var(--weight-semibold);
+ line-height: 1;
+ cursor: help;
+ transition:
+ background var(--duration-fast) var(--ease-standard),
+ color var(--duration-fast) var(--ease-standard);
+}
+
+.pl-check .pl-hint {
+ margin-left: 0;
+}
+
+.pl-hint:hover,
+.pl-hint[aria-expanded='true'] {
+ background: var(--ink-bright);
+ border-color: var(--ink-bright);
+ color: var(--bg-0);
+}
+
+.pl-hint:focus-visible {
+ outline: var(--focus-ring-width) solid var(--focus-ring-color);
+ outline-offset: 2px;
+}
+
+.pl-tip {
+ position: fixed;
+ z-index: 400;
+ padding: 0.6rem 0.7rem;
+ background: var(--bg-1);
+ border: 1px solid var(--stroke-strong);
+ border-radius: var(--radius-md);
+ box-shadow: var(--shadow-2);
+ color: var(--ink);
+ font-size: var(--text-sm);
+ line-height: var(--leading-tight);
+ pointer-events: none;
+ animation: pl-tip-in var(--duration-fast) var(--ease-out);
+}
+
+@keyframes pl-tip-in {
+ from {
+ opacity: 0;
+ transform: translateY(3px);
+ }
+ to {
+ opacity: 1;
+ transform: none;
+ }
+}
+
+/* ── Run log ───────────────────────────────────────────────────────────── */
+
+.pl-log-panel {
+ padding-bottom: 0.7rem;
+}
+
+.pl-log {
+ list-style: none;
+ margin: 0.6rem 0 0;
+ padding: 0;
+ max-height: 13rem;
+ overflow-y: auto;
+ font-family: var(--font-mono);
+ font-size: var(--text-2xs);
+ line-height: 1.65;
+ scrollbar-width: thin;
+}
+
+.pl-log li {
+ display: flex;
+ gap: 0.5rem;
+ padding: 0.15rem 0;
+ color: var(--ink-faint);
+ border-bottom: 1px solid var(--hairline);
+}
+
+.pl-log li:last-child {
+ border-bottom: 0;
+}
+
+.pl-log time {
+ flex: 0 0 auto;
+ color: var(--ink-dim);
+ font-variant-numeric: tabular-nums;
+}
+
+.pl-log li.is-ok span {
+ color: var(--success);
+}
+
+.pl-log li.is-fail span {
+ color: var(--danger);
+}
+
+.pl-log li.is-warn span {
+ color: var(--warn);
+}
+
+/* ── Stage rail ────────────────────────────────────────────────────────── */
+
+.pl-stages {
+ display: grid;
+ grid-template-columns: repeat(4, minmax(0, 1fr));
+ gap: 0.5rem;
+ list-style: none;
+ margin: 0 0 1rem;
+ padding: 0;
+ counter-reset: stage;
+}
+
+.pl-stages li {
+ display: flex;
+ flex-direction: column;
+ gap: 0.15rem;
+ padding: 0.6rem 0.7rem;
+ background: var(--surface-1);
+ border: 1px solid var(--stroke);
+ border-radius: var(--radius-md);
+ transition: border-color var(--duration-base) var(--ease-standard);
+}
+
+.pl-stages li[data-done='true'] {
+ border-color: color-mix(in srgb, var(--success) 45%, transparent);
+ background: color-mix(in srgb, var(--success) 7%, transparent);
+}
+
+.pl-stage-name {
+ font-size: var(--text-2xs);
+ text-transform: uppercase;
+ letter-spacing: 0.08em;
+ color: var(--ink-dim);
+}
+
+.pl-stage-num {
+ font-family: var(--font-mono);
+ font-size: var(--text-ui);
+ color: var(--ink-bright);
+ font-variant-numeric: tabular-nums;
+}
+
+/* ── Verdict banner ────────────────────────────────────────────────────── */
+
+.pl-verdict {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: baseline;
+ gap: 0.35rem 0.9rem;
+ margin-bottom: 1rem;
+ padding: 0.7rem 0.9rem;
+ border: 1px solid var(--stroke-strong);
+ border-radius: var(--radius-md);
+ background: var(--surface-1);
+ font-size: var(--text-sm);
+ color: var(--ink-faint);
+}
+
+.pl-verdict strong {
+ color: var(--ink-bright);
+ font-size: var(--text-ui);
+}
+
+.pl-verdict[data-tone='pass'] {
+ border-color: color-mix(in srgb, var(--success) 45%, transparent);
+ background: color-mix(in srgb, var(--success) 8%, transparent);
+}
+
+.pl-verdict[data-tone='fail'] {
+ border-color: color-mix(in srgb, var(--danger) 45%, transparent);
+ background: color-mix(in srgb, var(--danger) 8%, transparent);
+}
+
+.pl-verdict-exit {
+ font-family: var(--font-mono);
+ font-size: var(--text-2xs);
+ color: var(--danger);
+}
+
+/* ── Result cards ──────────────────────────────────────────────────────── */
+
+.pl-grid {
+ list-style: none;
+ margin: 0;
+ padding: 0;
+ display: grid;
+ grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
+ gap: 0.9rem;
+}
+
+.pl-card {
+ display: flex;
+ flex-direction: column;
+ background: var(--surface-1);
+ border: 1px solid var(--stroke);
+ border-radius: var(--radius-lg);
+ overflow: hidden;
+ transition:
+ border-color var(--duration-base) var(--ease-standard),
+ transform var(--duration-base) var(--ease-standard);
+ animation: pl-card-in var(--duration-base) var(--ease-emphasized);
+}
+
+@keyframes pl-card-in {
+ from {
+ opacity: 0;
+ transform: translateY(6px);
+ }
+ to {
+ opacity: 1;
+ transform: none;
+ }
+}
+
+.pl-card:hover {
+ border-color: var(--stroke-strong);
+}
+
+.pl-card[data-status='pass'] {
+ border-color: color-mix(in srgb, var(--success) 35%, transparent);
+}
+
+.pl-card[data-status='fail'],
+.pl-card[data-status='error'] {
+ border-color: color-mix(in srgb, var(--danger) 35%, transparent);
+}
+
+.pl-card-media {
+ position: relative;
+ aspect-ratio: 4 / 3;
+ background:
+ radial-gradient(circle at 50% 45%, var(--surface-2), transparent 70%),
+ var(--bg-0);
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ overflow: hidden;
+}
+
+.pl-card-media img {
+ width: 100%;
+ height: 100%;
+ object-fit: contain;
+ display: block;
+ animation: pl-fade-in var(--duration-slow) var(--ease-out);
+}
+
+@keyframes pl-fade-in {
+ from {
+ opacity: 0;
+ }
+ to {
+ opacity: 1;
+ }
+}
+
+.pl-media-empty {
+ font-size: var(--text-2xs);
+ color: var(--ink-dim);
+ text-transform: uppercase;
+ letter-spacing: 0.08em;
+}
+
+/* A skeleton, not a fake progress bar: it says "a picture belongs here and is
+ not here yet", and it stops the moment the real render lands. */
+.pl-shimmer {
+ position: absolute;
+ inset: 0;
+ background: linear-gradient(
+ 100deg,
+ transparent 20%,
+ var(--surface-2) 45%,
+ var(--surface-3) 50%,
+ var(--surface-2) 55%,
+ transparent 80%
+ );
+ background-size: 220% 100%;
+ animation: pl-shimmer 1.6s var(--ease-standard) infinite;
+}
+
+@keyframes pl-shimmer {
+ from {
+ background-position: 130% 0;
+ }
+ to {
+ background-position: -30% 0;
+ }
+}
+
+.pl-card-body {
+ display: flex;
+ flex-direction: column;
+ gap: 0.5rem;
+ padding: 0.75rem 0.85rem 0.85rem;
+ flex: 1;
+}
+
+.pl-card-head {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 0.5rem;
+}
+
+.pl-badge {
+ display: inline-flex;
+ align-items: center;
+ gap: 0.3rem;
+ padding: 0.15rem 0.5rem;
+ border-radius: var(--radius-pill);
+ background: var(--surface-3);
+ border: 1px solid var(--stroke);
+ font-size: var(--text-2xs);
+ text-transform: uppercase;
+ letter-spacing: 0.06em;
+ color: var(--ink-dim);
+}
+
+.pl-badge[data-status='pass'] {
+ color: var(--success);
+ border-color: color-mix(in srgb, var(--success) 45%, transparent);
+ background: color-mix(in srgb, var(--success) 12%, transparent);
+}
+
+.pl-badge[data-status='fail'],
+.pl-badge[data-status='error'] {
+ color: var(--danger);
+ border-color: color-mix(in srgb, var(--danger) 45%, transparent);
+ background: color-mix(in srgb, var(--danger) 12%, transparent);
+}
+
+.pl-badge[data-status='generating'],
+.pl-badge[data-status='rendering'],
+.pl-badge[data-status='inspecting'] {
+ color: var(--ink-bright);
+ border-color: var(--stroke-strong);
+}
+
+.pl-badge[data-status='generating']::before,
+.pl-badge[data-status='rendering']::before,
+.pl-badge[data-status='inspecting']::before {
+ content: '';
+ width: 5px;
+ height: 5px;
+ border-radius: 50%;
+ background: currentColor;
+ animation: pl-pulse 1.3s ease-in-out infinite;
+}
+
+@keyframes pl-pulse {
+ 0%,
+ 100% {
+ opacity: 0.3;
+ }
+ 50% {
+ opacity: 1;
+ }
+}
+
+.pl-elapsed {
+ font-family: var(--font-mono);
+ font-size: var(--text-2xs);
+ color: var(--ink-dim);
+ font-variant-numeric: tabular-nums;
+}
+
+.pl-card-prompt {
+ margin: 0;
+ font-size: var(--text-md);
+ line-height: var(--leading-tight);
+ color: var(--ink);
+}
+
+.pl-stats {
+ display: grid;
+ grid-template-columns: repeat(4, minmax(0, 1fr));
+ gap: 0.3rem;
+ margin: 0;
+ padding: 0.5rem 0;
+ border-top: 1px solid var(--hairline);
+ border-bottom: 1px solid var(--hairline);
+}
+
+.pl-stats div {
+ display: flex;
+ flex-direction: column-reverse;
+ gap: 0.1rem;
+ min-width: 0;
+}
+
+.pl-stats dt {
+ font-size: var(--text-2xs);
+ text-transform: uppercase;
+ letter-spacing: 0.06em;
+ color: var(--ink-dim);
+}
+
+.pl-stats dd {
+ margin: 0;
+ font-family: var(--font-mono);
+ font-size: var(--text-md);
+ color: var(--ink-bright);
+ font-variant-numeric: tabular-nums;
+ overflow-wrap: anywhere;
+}
+
+.pl-reasons {
+ list-style: none;
+ margin: 0;
+ padding: 0;
+ display: flex;
+ flex-direction: column;
+ gap: 0.3rem;
+ font-size: var(--text-2xs);
+ line-height: var(--leading-tight);
+}
+
+.pl-reasons li {
+ padding-left: 0.8rem;
+ position: relative;
+ color: var(--ink-faint);
+}
+
+.pl-reasons li::before {
+ position: absolute;
+ left: 0;
+ top: 0;
+}
+
+.pl-reasons li.is-fail::before {
+ content: '\00d7';
+ color: var(--danger);
+}
+
+.pl-reasons li.is-note::before {
+ content: '\2022';
+ color: var(--warn);
+}
+
+.pl-reasons code {
+ font-family: var(--font-mono);
+ font-size: 0.95em;
+ color: var(--ink);
+}
+
+.pl-pointer {
+ font-family: var(--font-mono);
+ color: var(--ink-dim);
+}
+
+.pl-card-actions {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 0.3rem;
+ margin-top: auto;
+ padding-top: 0.2rem;
+}
+
+/* ── Intro and export ──────────────────────────────────────────────────── */
+
+.pl-intro,
+.pl-export {
+ margin-top: 1.25rem;
+ padding: 1.25rem 1.35rem;
+ background: var(--surface-1);
+ border: 1px solid var(--stroke);
+ border-radius: var(--radius-lg);
+}
+
+.pl-intro h2,
+.pl-export h2 {
+ margin: 0 0 0.5rem;
+ font-family: var(--font-display);
+ font-size: var(--text-lg);
+ color: var(--ink-bright);
+}
+
+.pl-intro p,
+.pl-export p {
+ margin: 0 0 0.6rem;
+ max-width: 62ch;
+ font-size: var(--text-ui);
+ line-height: var(--leading-normal);
+ color: var(--ink-faint);
+}
+
+.pl-intro-time {
+ font-size: var(--text-sm) !important;
+ color: var(--ink-dim) !important;
+}
+
+.pl-export h3 {
+ margin: 1.1rem 0 0.5rem;
+ font-family: var(--font-display);
+ font-size: var(--text-ui);
+ color: var(--ink-bright);
+}
+
+.pl-export-actions {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 0.5rem;
+ margin-bottom: 0.5rem;
+}
+
+.pl-code {
+ margin: 0 0 0.6rem;
+ padding: 0.85rem 0.95rem;
+ background: var(--bg-0);
+ border: 1px solid var(--stroke);
+ border-radius: var(--radius-md);
+ overflow-x: auto;
+ font-family: var(--font-mono);
+ font-size: var(--text-sm);
+ line-height: 1.7;
+ color: var(--ink);
+ white-space: pre;
+ tab-size: 2;
+}
+
+.pl-export-foot {
+ margin-top: 0.9rem !important;
+ font-size: var(--text-sm) !important;
+}
+
+.pl-export-foot a,
+.pl-intro a {
+ color: var(--ink-bright);
+ text-decoration: underline;
+ text-underline-offset: 2px;
+ text-decoration-color: var(--stroke-strong);
+}
+
+.pl-export-foot a:hover,
+.pl-intro a:hover {
+ text-decoration-color: var(--ink-bright);
+}
+
+/* ── Motion preferences ────────────────────────────────────────────────── */
+
+@media (prefers-reduced-motion: reduce) {
+ .pl-card,
+ .pl-card-media img,
+ .pl-tip {
+ animation: none;
+ }
+
+ .pl-shimmer {
+ animation: none;
+ background: var(--surface-2);
+ }
+
+ .pl-badge[data-status='generating']::before,
+ .pl-badge[data-status='rendering']::before,
+ .pl-badge[data-status='inspecting']::before {
+ animation: none;
+ opacity: 0.8;
+ }
+
+ .pl-btn:active,
+ .pl-preset:active {
+ transform: none;
+ }
+}
diff --git a/public/pipeline-studio.js b/public/pipeline-studio.js
new file mode 100644
index 000000000..5aaa0349e
--- /dev/null
+++ b/public/pipeline-studio.js
@@ -0,0 +1,1170 @@
+/*
+ * Pipeline Studio (/cookbook/playground)
+ *
+ * The cookbook's four stages, executed in the browser against the real, free,
+ * keyless API:
+ *
+ * 1. generate POST /api/3d/generate (inline-done or queued + poll)
+ * 2. render GET /api/render/glb (headless chromium still)
+ * 3. gate GET /api/3d/inspect (stats + Khronos validator)
+ * 4. export manifest.json + the commands that reproduce the run locally
+ *
+ * The gate is a deliberate, line-by-line port of `evaluate()` in
+ * /cookbook/recipes/asset_gate.py. That is the whole point of this page: the
+ * verdict you see here has to be the verdict your CI reaches, or the preview is
+ * worse than useless. When one changes, change the other.
+ */
+(function () {
+ 'use strict';
+
+ /* ── Constants ─────────────────────────────────────────────────────── */
+
+ // Matches asset_pack.py's DEFAULT_WORKERS. The free lane is a shared GPU
+ // pool: more parallelism queues rather than finishes.
+ const DEFAULT_WORKERS = 3;
+ const MAX_WORKERS = 4;
+
+ // Poll cadence bounds, mirroring text_to_3d.py. The server sends a
+ // `retryAfter` hint on every queued response and we honour it inside these.
+ const MIN_POLL_MS = 2000;
+ const MAX_POLL_MS = 10000;
+
+ // A draft generation that has not landed in six minutes is not coming back.
+ const GENERATE_TIMEOUT_MS = 6 * 60 * 1000;
+ // A still is a chromium boot plus a render; a minute is generous.
+ const RENDER_TIMEOUT_MS = 60 * 1000;
+
+ const RENDER_W = 640;
+ const RENDER_H = 480;
+
+ const STORAGE_KEY = 'threews.pipeline-studio.v1';
+
+ // Packs that exercise different corners of the lane: soft organic shapes,
+ // hard-surface props, and one deliberately detailed set that tends to bust a
+ // tight triangle budget, so the gate has something to actually catch.
+ const PRESETS = [
+ {
+ name: 'Garden props',
+ prompts: [
+ 'a clay flower pot with a saucer',
+ 'a woven wicker basket',
+ 'a brass watering can',
+ ],
+ },
+ {
+ name: 'Desk objects',
+ prompts: [
+ 'a small ceramic teapot with a bamboo handle',
+ 'a stack of three hardcover books',
+ 'a copper desk lamp with a fabric shade',
+ ],
+ },
+ {
+ name: 'Game pickups',
+ prompts: [
+ 'a wooden treasure chest with iron bands',
+ 'a glowing blue health potion in a glass flask',
+ 'an iron key with an ornate bow',
+ ],
+ },
+ ];
+
+ const DEFAULT_BUDGET = {
+ maxTriangles: 100000,
+ minTriangles: 100,
+ maxSizeMb: 8,
+ maxMaterials: 16,
+ requireTextures: false,
+ requireMaterials: false,
+ };
+
+ /* ── Small helpers ─────────────────────────────────────────────────── */
+
+ const $ = (id) => document.getElementById(id);
+
+ function clamp(value, low, high) {
+ return Math.max(low, Math.min(high, value));
+ }
+
+ function escapeHtml(value) {
+ return String(value == null ? '' : value).replace(
+ /[&<>"']/g,
+ (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[c],
+ );
+ }
+
+ /* Byte-for-byte the same rule as slugify() in text_to_3d.py, so a model
+ downloaded here lands under the same filename the CLI would give it. */
+ function slugify(text, limit) {
+ const cap = limit || 48;
+ let slug = String(text)
+ .split('')
+ .map((c) => (/[a-z0-9]/i.test(c) ? c.toLowerCase() : '-'))
+ .join('');
+ slug = slug.replace(/^-+|-+$/g, '');
+ while (slug.indexOf('--') !== -1) slug = slug.replace(/--/g, '-');
+ return slug.slice(0, cap).replace(/^-+|-+$/g, '') || 'model';
+ }
+
+ /* asset_pack.py's unique_slugs: two prompts that collapse to the same slug
+ must not overwrite each other's file. */
+ function uniqueSlugs(prompts) {
+ const seen = Object.create(null);
+ return prompts.map((prompt) => {
+ const base = slugify(prompt);
+ seen[base] = (seen[base] || 0) + 1;
+ return seen[base] === 1 ? base : base + '-' + seen[base];
+ });
+ }
+
+ class Cancelled extends Error {
+ constructor() {
+ super('cancelled');
+ this.name = 'Cancelled';
+ }
+ }
+
+ function sleep(ms, signal) {
+ return new Promise((resolve, reject) => {
+ if (signal.aborted) return reject(new Cancelled());
+ const timer = setTimeout(() => {
+ signal.removeEventListener('abort', onAbort);
+ resolve();
+ }, ms);
+ function onAbort() {
+ clearTimeout(timer);
+ reject(new Cancelled());
+ }
+ signal.addEventListener('abort', onAbort, { once: true });
+ });
+ }
+
+ function formatDuration(ms) {
+ const s = Math.round(ms / 1000);
+ if (s < 60) return s + 's';
+ return Math.floor(s / 60) + 'm ' + String(s % 60).padStart(2, '0') + 's';
+ }
+
+ function formatInt(n) {
+ return Number(n || 0).toLocaleString('en-US');
+ }
+
+ function formatMb(bytes) {
+ return (Number(bytes || 0) / 1048576).toFixed(1);
+ }
+
+ /* ── Stage 1: generate ─────────────────────────────────────────────── */
+
+ async function readJson(response) {
+ const text = await response.text();
+ try {
+ return JSON.parse(text);
+ } catch (err) {
+ throw new Error('the API returned a non-JSON response (HTTP ' + response.status + ')');
+ }
+ }
+
+ function apiMessage(payload, fallback) {
+ return (
+ (payload && (payload.error_description || payload.message || payload.error)) || fallback
+ );
+ }
+
+ function pollDelay(payload, previous) {
+ const hint = Number(payload && payload.retryAfter);
+ if (!Number.isFinite(hint) || hint <= 0) return previous || MIN_POLL_MS;
+ return clamp(hint * 1000, MIN_POLL_MS, MAX_POLL_MS);
+ }
+
+ async function generate(prompt, signal, onQueued) {
+ const res = await fetch('/api/3d/generate', {
+ method: 'POST',
+ headers: { 'content-type': 'application/json', accept: 'application/json' },
+ body: JSON.stringify({ prompt: prompt }),
+ signal: signal,
+ });
+ const data = await readJson(res);
+ if (!res.ok) throw new Error(apiMessage(data, 'the 3D lane refused the job'));
+ if (data.status === 'done' && data.glbUrl) return data;
+ if (data.status === 'error') throw new Error(apiMessage(data, 'generation failed'));
+
+ const job = data.job;
+ if (!job) throw new Error('the API queued the job without returning a handle');
+
+ let delay = pollDelay(data, MIN_POLL_MS);
+ if (onQueued) onQueued(data.etaSeconds);
+
+ const deadline = Date.now() + GENERATE_TIMEOUT_MS;
+ while (Date.now() < deadline) {
+ await sleep(delay, signal);
+ const url =
+ '/api/3d/generate?job=' +
+ encodeURIComponent(job) +
+ '&title=' +
+ encodeURIComponent(prompt);
+ const pollRes = await fetch(url, { headers: { accept: 'application/json' }, signal: signal });
+ const polled = await readJson(pollRes);
+ if (!pollRes.ok) throw new Error(apiMessage(polled, 'the poll failed'));
+ if (polled.status === 'done' && polled.glbUrl) return polled;
+ if (polled.status === 'error') throw new Error(apiMessage(polled, 'generation failed'));
+ delay = pollDelay(polled, delay);
+ }
+ throw new Error('the job did not finish within ' + Math.round(GENERATE_TIMEOUT_MS / 60000) + ' minutes');
+ }
+
+ /* ── Stage 2: render ───────────────────────────────────────────────── */
+
+ function renderUrl(glbUrl) {
+ return (
+ '/api/render/glb?glbUrl=' +
+ encodeURIComponent(glbUrl) +
+ '&width=' +
+ RENDER_W +
+ '&height=' +
+ RENDER_H +
+ '&background=transparent'
+ );
+ }
+
+ /* Load the still through an Image so the card only ever shows a picture that
+ really decoded. The endpoint boots headless chromium, so onload here is
+ genuine evidence the render happened, not an optimistic guess. */
+ function renderStill(glbUrl, signal) {
+ return new Promise((resolve, reject) => {
+ if (signal.aborted) return reject(new Cancelled());
+ const url = renderUrl(glbUrl);
+ const img = new Image();
+ const timer = setTimeout(() => {
+ cleanup();
+ reject(new Error('the render did not finish in time'));
+ }, RENDER_TIMEOUT_MS);
+ function cleanup() {
+ clearTimeout(timer);
+ img.onload = null;
+ img.onerror = null;
+ signal.removeEventListener('abort', onAbort);
+ }
+ function onAbort() {
+ cleanup();
+ img.src = '';
+ reject(new Cancelled());
+ }
+ img.onload = () => {
+ cleanup();
+ resolve(url);
+ };
+ img.onerror = () => {
+ cleanup();
+ reject(new Error('the renderer could not draw this model'));
+ };
+ signal.addEventListener('abort', onAbort, { once: true });
+ img.decoding = 'async';
+ img.src = url;
+ });
+ }
+
+ /* ── Stage 3: gate ─────────────────────────────────────────────────── */
+
+ async function inspect(glbUrl, signal) {
+ const res = await fetch('/api/3d/inspect?url=' + encodeURIComponent(glbUrl), {
+ headers: { accept: 'application/json' },
+ signal: signal,
+ });
+ const data = await readJson(res);
+ if (!res.ok) throw new Error(apiMessage(data, 'the inspector could not read this model'));
+ return data;
+ }
+
+ /*
+ * Port of evaluate() in asset_gate.py. Same order, same wording, same split
+ * between a failure (something a user will feel) and an advisory (something
+ * worth a look). Keep the two in step.
+ */
+ function evaluate(payload, budget) {
+ const stats = payload.stats || {};
+ const validation = payload.validation || {};
+ const sizeBytes = Number(payload.sizeBytes || 0);
+ const failures = [];
+ const advisories = [];
+
+ if (!payload.valid) failures.push('the file is not a valid glTF/GLB container');
+
+ const errors = Number(validation.numErrors || 0);
+ if (errors) failures.push('glTF validator reported ' + errors + ' error(s)');
+
+ const triangles = Number(stats.triangles || 0);
+ if (triangles > budget.maxTriangles) {
+ failures.push(
+ formatInt(triangles) + ' triangles exceeds the budget of ' + formatInt(budget.maxTriangles),
+ );
+ }
+ if (triangles < budget.minTriangles) {
+ failures.push(
+ 'only ' +
+ formatInt(triangles) +
+ ' triangles: generation probably collapsed (minimum ' +
+ formatInt(budget.minTriangles) +
+ ')',
+ );
+ }
+
+ const sizeMb = sizeBytes / 1048576;
+ if (sizeMb > budget.maxSizeMb) {
+ failures.push(
+ sizeMb.toFixed(1) + ' MB exceeds the budget of ' + budget.maxSizeMb.toFixed(1) + ' MB',
+ );
+ }
+
+ const materials = Number(stats.materials || 0);
+ if (materials > budget.maxMaterials) {
+ failures.push(materials + ' materials exceeds the budget of ' + budget.maxMaterials);
+ }
+
+ const textures = Number(stats.textures || 0);
+ // Zero materials is not automatically broken: the draft lane routinely
+ // ships vertex-coloured geometry, which renders in full colour with no
+ // material at all. Only fail on it when the caller opted in.
+ if (materials === 0) {
+ if (budget.requireMaterials) {
+ failures.push('no materials, and "require materials" was set');
+ } else {
+ advisories.push(
+ 'no materials: likely vertex-coloured geometry, which renders in colour but ignores your lighting setup',
+ );
+ }
+ }
+ if (budget.requireTextures && textures === 0) {
+ failures.push('no textures, and "require textures" was set');
+ }
+
+ const warnings = Number(validation.numWarnings || 0);
+ if (warnings) advisories.push('glTF validator reported ' + warnings + ' warning(s)');
+ (payload.recommendations || []).forEach((rec) => {
+ if (['warn', 'warning', 'error'].indexOf(rec.severity) !== -1 && rec.issue) {
+ advisories.push(rec.issue);
+ }
+ });
+
+ return { passed: failures.length === 0, failures: failures, advisories: advisories };
+ }
+
+ /* ── Run state ─────────────────────────────────────────────────────── */
+
+ const state = {
+ items: [],
+ budget: Object.assign({}, DEFAULT_BUDGET),
+ workers: DEFAULT_WORKERS,
+ running: false,
+ startedAt: 0,
+ elapsedMs: 0,
+ controller: null,
+ };
+
+ const els = {};
+ let tickTimer = 0;
+
+ function cacheEls() {
+ [
+ 'pl-form',
+ 'pl-prompts',
+ 'pl-prompt-count',
+ 'pl-presets',
+ 'pl-tri',
+ 'pl-mb',
+ 'pl-mat',
+ 'pl-req-tex',
+ 'pl-req-mat',
+ 'pl-workers',
+ 'pl-run',
+ 'pl-stop',
+ 'pl-eta',
+ 'pl-log',
+ 'pl-grid',
+ 'pl-intro',
+ 'pl-stages',
+ 'pl-verdict',
+ 'pl-export',
+ 'pl-repro',
+ 'pl-dl-manifest',
+ 'pl-dl-all',
+ 'pl-share',
+ 'pl-copy-repro',
+ 'pl-tip',
+ ].forEach((id) => {
+ els[id.replace(/^pl-/, '').replace(/-([a-z])/g, (_, c) => c.toUpperCase())] = $(id);
+ });
+ }
+
+ function log(message, kind) {
+ const li = document.createElement('li');
+ if (kind) li.className = 'is-' + kind;
+ const time = new Date();
+ li.innerHTML =
+ '<time>' +
+ String(time.getHours()).padStart(2, '0') +
+ ':' +
+ String(time.getMinutes()).padStart(2, '0') +
+ ':' +
+ String(time.getSeconds()).padStart(2, '0') +
+ '</time><span>' +
+ escapeHtml(message) +
+ '</span>';
+ els.log.appendChild(li);
+ els.log.scrollTop = els.log.scrollHeight;
+ }
+
+ /* ── Rendering the results ─────────────────────────────────────────── */
+
+ const STATUS_LABEL = {
+ queued: 'Queued',
+ generating: 'Generating',
+ rendering: 'Rendering',
+ inspecting: 'Inspecting',
+ pass: 'Pass',
+ fail: 'Fail',
+ error: 'Error',
+ cancelled: 'Stopped',
+ };
+
+ function statsRow(item) {
+ if (!item.stats) return '';
+ const cells = [
+ [formatInt(item.stats.triangles), 'tris'],
+ [formatMb(item.sizeBytes), 'MB'],
+ [String(Number(item.stats.materials || 0)), 'mat'],
+ [String(Number(item.stats.textures || 0)), 'tex'],
+ ];
+ return (
+ '<dl class="pl-stats">' +
+ cells
+ .map(
+ (c) =>
+ '<div><dt>' + escapeHtml(c[1]) + '</dt><dd>' + escapeHtml(c[0]) + '</dd></div>',
+ )
+ .join('') +
+ '</dl>'
+ );
+ }
+
+ function reasonList(item) {
+ const rows = [];
+ (item.failures || []).forEach((f) => {
+ rows.push('<li class="is-fail">' + escapeHtml(f) + '</li>');
+ });
+ (item.issues || []).forEach((issue) => {
+ rows.push(
+ '<li class="is-fail"><code>' +
+ escapeHtml(issue.code) +
+ '</code> ' +
+ escapeHtml(issue.message) +
+ (issue.pointer ? ' <span class="pl-pointer">' + escapeHtml(issue.pointer) + '</span>' : '') +
+ '</li>',
+ );
+ });
+ (item.advisories || []).forEach((a) => {
+ rows.push('<li class="is-note">' + escapeHtml(a) + '</li>');
+ });
+ if (item.error) rows.push('<li class="is-fail">' + escapeHtml(item.error) + '</li>');
+ return rows.length ? '<ul class="pl-reasons">' + rows.join('') + '</ul>' : '';
+ }
+
+ function mediaFor(item) {
+ if (item.still) {
+ return (
+ '<img src="' +
+ escapeHtml(item.still) +
+ '" alt="Rendered still of ' +
+ escapeHtml(item.prompt) +
+ '" width="' +
+ RENDER_W +
+ '" height="' +
+ RENDER_H +
+ '" loading="lazy" decoding="async">'
+ );
+ }
+ if (item.status === 'error' || item.status === 'cancelled') {
+ return '<span class="pl-media-empty">no still</span>';
+ }
+ return '<span class="pl-shimmer" aria-hidden="true"></span>';
+ }
+
+ function actionsFor(item) {
+ if (!item.glbUrl) return '';
+ return (
+ '<div class="pl-card-actions">' +
+ '<a class="pl-btn subtle" href="' +
+ escapeHtml(item.viewerUrl || '/viewer?src=' + encodeURIComponent(item.glbUrl)) +
+ '" target="_blank" rel="noopener">View in 3D</a>' +
+ (item.arUrl
+ ? '<a class="pl-btn subtle" href="' +
+ escapeHtml(item.arUrl) +
+ '" target="_blank" rel="noopener">View in AR</a>'
+ : '') +
+ '<a class="pl-btn subtle" href="' +
+ escapeHtml(item.glbUrl) +
+ '" download="' +
+ escapeHtml(item.slug) +
+ '.glb">Download GLB</a>' +
+ '</div>'
+ );
+ }
+
+ function cardHtml(item) {
+ const busy = ['generating', 'rendering', 'inspecting'].indexOf(item.status) !== -1;
+ return (
+ '<li class="pl-card" data-status="' +
+ escapeHtml(item.status) +
+ '" data-id="' +
+ escapeHtml(item.id) +
+ '">' +
+ '<div class="pl-card-media">' +
+ mediaFor(item) +
+ '</div>' +
+ '<div class="pl-card-body">' +
+ '<div class="pl-card-head">' +
+ '<span class="pl-badge" data-status="' +
+ escapeHtml(item.status) +
+ '">' +
+ escapeHtml(STATUS_LABEL[item.status] || item.status) +
+ '</span>' +
+ '<span class="pl-elapsed" data-elapsed="' +
+ escapeHtml(item.id) +
+ '">' +
+ (item.ms ? formatDuration(item.ms) : busy ? '0s' : '') +
+ '</span>' +
+ '</div>' +
+ '<p class="pl-card-prompt">' +
+ escapeHtml(item.prompt) +
+ '</p>' +
+ statsRow(item) +
+ reasonList(item) +
+ actionsFor(item) +
+ '</div></li>'
+ );
+ }
+
+ function renderGrid() {
+ els.grid.innerHTML = state.items.map(cardHtml).join('');
+ els.intro.hidden = state.items.length > 0;
+ }
+
+ function patchCard(item) {
+ const existing = els.grid.querySelector('[data-id="' + item.id + '"]');
+ if (!existing) return renderGrid();
+ const holder = document.createElement('div');
+ holder.innerHTML = cardHtml(item);
+ existing.replaceWith(holder.firstElementChild);
+ }
+
+ function updateStages() {
+ const counts = {
+ generate: state.items.filter((i) => i.glbUrl).length,
+ render: state.items.filter((i) => i.still).length,
+ gate: state.items.filter((i) => i.stats).length,
+ export: state.items.filter((i) => i.status === 'pass').length,
+ };
+ Object.keys(counts).forEach((stage) => {
+ const el = els.stages.querySelector('[data-count="' + stage + '"]');
+ if (el) el.textContent = String(counts[stage]) + '/' + state.items.length;
+ });
+ els.stages.querySelectorAll('li').forEach((li) => {
+ const stage = li.dataset.stage;
+ const done = counts[stage] === state.items.length && state.items.length > 0;
+ li.dataset.done = done ? 'true' : 'false';
+ });
+ }
+
+ function updateVerdict() {
+ const done = state.items.filter((i) =>
+ ['pass', 'fail', 'error', 'cancelled'].includes(i.status),
+ );
+ if (!done.length) {
+ els.verdict.hidden = true;
+ return;
+ }
+ const passed = state.items.filter((i) => i.status === 'pass').length;
+ const failed = state.items.filter((i) => i.status === 'fail').length;
+ const broken = state.items.filter((i) => i.status === 'error').length;
+ const total = state.items.length;
+ const allDone = done.length === total && !state.running;
+ els.verdict.hidden = false;
+ els.verdict.dataset.tone = failed || broken ? 'fail' : allDone ? 'pass' : 'busy';
+ els.verdict.innerHTML =
+ '<strong>' +
+ passed +
+ ' of ' +
+ total +
+ ' passed the budget</strong>' +
+ (failed ? '<span>' + failed + ' over budget</span>' : '') +
+ (broken ? '<span>' + broken + ' could not be built</span>' : '') +
+ (state.elapsedMs ? '<span>' + formatDuration(state.elapsedMs) + '</span>' : '') +
+ (allDone && (failed || broken)
+ ? '<span class="pl-verdict-exit">a CI run would exit 1 here</span>'
+ : '');
+ }
+
+ /* One timer for every in-flight card, rather than one timer each. */
+ function startTicking() {
+ if (tickTimer) return;
+ tickTimer = setInterval(() => {
+ const now = Date.now();
+ let live = 0;
+ state.items.forEach((item) => {
+ if (!item.startedAt || item.ms) return;
+ live += 1;
+ const el = els.grid.querySelector('[data-elapsed="' + item.id + '"]');
+ if (el) el.textContent = formatDuration(now - item.startedAt);
+ });
+ if (state.running) {
+ state.elapsedMs = now - state.startedAt;
+ updateVerdict();
+ }
+ if (!live && !state.running) stopTicking();
+ }, 1000);
+ }
+
+ function stopTicking() {
+ if (!tickTimer) return;
+ clearInterval(tickTimer);
+ tickTimer = 0;
+ }
+
+ /* ── The run itself ────────────────────────────────────────────────── */
+
+ function readBudget() {
+ return {
+ maxTriangles: clamp(parseInt(els.tri.value, 10) || DEFAULT_BUDGET.maxTriangles, 100, 2000000),
+ minTriangles: DEFAULT_BUDGET.minTriangles,
+ maxSizeMb: clamp(parseFloat(els.mb.value) || DEFAULT_BUDGET.maxSizeMb, 0.1, 64),
+ maxMaterials: clamp(
+ parseInt(els.mat.value, 10) || DEFAULT_BUDGET.maxMaterials,
+ 0,
+ 256,
+ ),
+ requireTextures: els.reqTex.checked,
+ requireMaterials: els.reqMat.checked,
+ };
+ }
+
+ function readPrompts() {
+ return els.prompts.value
+ .split('\n')
+ .map((line) => line.trim())
+ .filter((line) => line && !line.startsWith('#'));
+ }
+
+ async function runOne(item, signal) {
+ item.startedAt = Date.now();
+ item.status = 'generating';
+ patchCard(item);
+ updateStages();
+
+ const built = await generate(item.prompt, signal, (eta) => {
+ log(
+ 'queued on the shared lane: ' +
+ item.prompt +
+ (eta ? ' (about ' + Math.round(eta) + 's)' : ''),
+ );
+ });
+ item.glbUrl = built.glbUrl;
+ item.viewerUrl = built.viewerUrl || '';
+ item.arUrl = built.arUrl || '';
+ item.creationId = built.creationId || '';
+ log('built: ' + item.prompt, 'ok');
+ item.status = 'rendering';
+ patchCard(item);
+ updateStages();
+
+ // A still that fails to draw is not a reason to lose the model, so the
+ // render is allowed to fail on its own and the run carries on to the gate.
+ try {
+ item.still = await renderStill(item.glbUrl, signal);
+ } catch (err) {
+ if (err instanceof Cancelled) throw err;
+ item.advisories = (item.advisories || []).concat(['still render failed: ' + err.message]);
+ log('no still for ' + item.prompt + ': ' + err.message, 'warn');
+ }
+ item.status = 'inspecting';
+ patchCard(item);
+ updateStages();
+
+ const report = await inspect(item.glbUrl, signal);
+ item.stats = report.stats || {};
+ item.sizeBytes = Number(report.sizeBytes || 0);
+ item.validation = report.validation || {};
+ item.issues = (report.validation && report.validation.issues) || [];
+ const verdict = evaluate(report, state.budget);
+ item.failures = verdict.failures;
+ item.advisories = (item.advisories || []).concat(verdict.advisories);
+ item.status = verdict.passed ? 'pass' : 'fail';
+ item.ms = Date.now() - item.startedAt;
+ log(
+ (verdict.passed ? 'passed: ' : 'FAILED the budget: ') +
+ item.prompt +
+ ' (' +
+ formatInt(item.stats.triangles) +
+ ' tris, ' +
+ formatMb(item.sizeBytes) +
+ ' MB)',
+ verdict.passed ? 'ok' : 'fail',
+ );
+ patchCard(item);
+ updateStages();
+ }
+
+ /* A fixed-size worker pool over a shared cursor: N runners pulling from one
+ queue keeps exactly N in flight without a barrier between items. */
+ async function pool(items, limit, signal) {
+ let cursor = 0;
+ const runner = async () => {
+ while (cursor < items.length) {
+ if (signal.aborted) return;
+ const item = items[cursor++];
+ try {
+ await runOne(item, signal);
+ } catch (err) {
+ item.ms = Date.now() - item.startedAt;
+ if (err instanceof Cancelled || signal.aborted) {
+ item.status = 'cancelled';
+ } else {
+ item.status = 'error';
+ item.error = err.message || String(err);
+ log('failed: ' + item.prompt + ': ' + item.error, 'fail');
+ }
+ patchCard(item);
+ updateStages();
+ }
+ }
+ };
+ await Promise.all(
+ Array.from({ length: Math.min(limit, items.length) }, () => runner()),
+ );
+ }
+
+ async function run() {
+ const prompts = readPrompts();
+ if (!prompts.length) {
+ log('add at least one prompt before running', 'fail');
+ els.prompts.focus();
+ return;
+ }
+
+ state.budget = readBudget();
+ state.workers = clamp(parseInt(els.workers.value, 10) || DEFAULT_WORKERS, 1, MAX_WORKERS);
+ const slugs = uniqueSlugs(prompts);
+ state.items = prompts.map((prompt, i) => ({
+ id: 'a' + i + '-' + slugs[i],
+ prompt: prompt,
+ slug: slugs[i],
+ status: 'queued',
+ startedAt: 0,
+ ms: 0,
+ advisories: [],
+ failures: [],
+ issues: [],
+ }));
+ state.running = true;
+ state.startedAt = Date.now();
+ state.elapsedMs = 0;
+ state.controller = new AbortController();
+
+ els.run.hidden = true;
+ els.stop.hidden = false;
+ els.export.hidden = true;
+ els.log.innerHTML = '';
+ renderGrid();
+ updateStages();
+ updateVerdict();
+ startTicking();
+ log(
+ 'running ' +
+ prompts.length +
+ ' prompt(s), ' +
+ state.workers +
+ ' at a time, budget ' +
+ formatInt(state.budget.maxTriangles) +
+ ' tris / ' +
+ state.budget.maxSizeMb +
+ ' MB',
+ );
+
+ try {
+ await pool(state.items, state.workers, state.controller.signal);
+ } finally {
+ state.running = false;
+ state.elapsedMs = Date.now() - state.startedAt;
+ els.run.hidden = false;
+ els.stop.hidden = true;
+ updateStages();
+ updateVerdict();
+ stopTicking();
+ const usable = state.items.filter((i) => i.glbUrl).length;
+ if (usable) {
+ els.export.hidden = false;
+ els.repro.textContent = reproCommands();
+ }
+ log(
+ 'run finished in ' +
+ formatDuration(state.elapsedMs) +
+ ': ' +
+ state.items.filter((i) => i.status === 'pass').length +
+ '/' +
+ state.items.length +
+ ' passed',
+ );
+ persist();
+ }
+ }
+
+ function stop() {
+ if (!state.controller) return;
+ state.controller.abort();
+ log('stopped by you; models already built are kept', 'warn');
+ }
+
+ /* ── Stage 4: export ───────────────────────────────────────────────── */
+
+ function manifest() {
+ return {
+ generator: 'three.ws cookbook / pipeline-studio',
+ api: 'https://three.ws/api/3d/generate',
+ tier: 'free draft',
+ seconds: Math.round(state.elapsedMs / 100) / 10,
+ budget: state.budget,
+ assets: state.items.map((item) => ({
+ prompt: item.prompt,
+ slug: item.slug,
+ ok: item.status === 'pass',
+ glb_url: item.glbUrl || '',
+ viewer_url: item.viewerUrl || '',
+ ar_url: item.arUrl || '',
+ still_url: item.still ? new URL(item.still, location.origin).href : '',
+ seconds: Math.round(item.ms / 100) / 10,
+ error: item.error || '',
+ warnings: item.advisories || [],
+ failures: item.failures || [],
+ stats: item.stats || null,
+ size_bytes: item.sizeBytes || 0,
+ validation: item.validation || null,
+ })),
+ };
+ }
+
+ function download(blob, filename) {
+ const url = URL.createObjectURL(blob);
+ const a = document.createElement('a');
+ a.href = url;
+ a.download = filename;
+ document.body.appendChild(a);
+ a.click();
+ a.remove();
+ setTimeout(() => URL.revokeObjectURL(url), 30000);
+ }
+
+ function reproCommands() {
+ const prompts = state.items.map((i) => i.prompt);
+ const b = state.budget;
+ const flags = [
+ '--max-triangles ' + b.maxTriangles,
+ '--max-size-mb ' + b.maxSizeMb,
+ '--max-materials ' + b.maxMaterials,
+ ];
+ if (b.requireTextures) flags.push('--require-textures');
+ if (b.requireMaterials) flags.push('--require-materials');
+ return [
+ '# 1. get the two recipes',
+ 'curl -O https://three.ws/cookbook/recipes/text_to_3d.py',
+ 'curl -O https://three.ws/cookbook/recipes/asset_pack.py',
+ 'curl -O https://three.ws/cookbook/recipes/asset_gate.py',
+ '',
+ '# 2. the prompts you just ran',
+ "cat > props.txt <<'EOF'",
+ prompts.join('\n'),
+ 'EOF',
+ '',
+ '# 3. build the pack (' + state.workers + ' at a time, same as this page)',
+ 'python3 asset_pack.py --prompts-file props.txt --out ./pack --workers ' + state.workers,
+ '',
+ '# 4. gate it with the budget you set above',
+ 'python3 asset_gate.py pack/models/*.glb ' + flags.join(' '),
+ ].join('\n');
+ }
+
+ async function downloadAll() {
+ const built = state.items.filter((i) => i.glbUrl);
+ if (!built.length) return;
+ els.dlAll.disabled = true;
+ const original = els.dlAll.textContent;
+ try {
+ for (let i = 0; i < built.length; i += 1) {
+ const item = built[i];
+ els.dlAll.textContent = 'Downloading ' + (i + 1) + ' of ' + built.length;
+ const res = await fetch(item.glbUrl);
+ if (!res.ok) {
+ log('could not download ' + item.slug + '.glb (HTTP ' + res.status + ')', 'fail');
+ continue;
+ }
+ download(await res.blob(), item.slug + '.glb');
+ }
+ log('downloaded ' + built.length + ' model(s)', 'ok');
+ } finally {
+ els.dlAll.disabled = false;
+ els.dlAll.textContent = original;
+ }
+ }
+
+ async function copyText(text, button, done) {
+ const original = button.textContent;
+ try {
+ await navigator.clipboard.writeText(text);
+ button.textContent = done;
+ } catch (err) {
+ button.textContent = 'Press Ctrl+C to copy';
+ log('the browser blocked clipboard access', 'warn');
+ }
+ setTimeout(() => {
+ button.textContent = original;
+ }, 1800);
+ }
+
+ function shareLink() {
+ const url = new URL(location.href);
+ url.search = '';
+ const b = state.budget;
+ url.searchParams.set('prompts', readPrompts().join('\n'));
+ url.searchParams.set('tri', String(b.maxTriangles));
+ url.searchParams.set('mb', String(b.maxSizeMb));
+ url.searchParams.set('mat', String(b.maxMaterials));
+ if (b.requireTextures) url.searchParams.set('tex', '1');
+ if (b.requireMaterials) url.searchParams.set('rmat', '1');
+ return url.href;
+ }
+
+ /* ── Persistence and links ─────────────────────────────────────────── */
+
+ function persist() {
+ try {
+ localStorage.setItem(
+ STORAGE_KEY,
+ JSON.stringify({
+ items: state.items,
+ budget: state.budget,
+ workers: state.workers,
+ elapsedMs: state.elapsedMs,
+ savedAt: Date.now(),
+ }),
+ );
+ } catch (err) {
+ /* A full or disabled localStorage must never break a finished run. */
+ }
+ }
+
+ function restore() {
+ let saved = null;
+ try {
+ saved = JSON.parse(localStorage.getItem(STORAGE_KEY) || 'null');
+ } catch (err) {
+ saved = null;
+ }
+ if (!saved || !Array.isArray(saved.items) || !saved.items.length) return false;
+ state.items = saved.items;
+ state.budget = Object.assign({}, DEFAULT_BUDGET, saved.budget || {});
+ state.workers = saved.workers || DEFAULT_WORKERS;
+ state.elapsedMs = saved.elapsedMs || 0;
+ renderGrid();
+ updateStages();
+ updateVerdict();
+ if (state.items.some((i) => i.glbUrl)) {
+ els.export.hidden = false;
+ els.repro.textContent = reproCommands();
+ }
+ log('restored your last run from this browser', 'ok');
+ return true;
+ }
+
+ function applyBudgetToForm(budget) {
+ els.tri.value = String(budget.maxTriangles);
+ els.mb.value = String(budget.maxSizeMb);
+ els.mat.value = String(budget.maxMaterials);
+ els.reqTex.checked = Boolean(budget.requireTextures);
+ els.reqMat.checked = Boolean(budget.requireMaterials);
+ }
+
+ function readUrlConfig() {
+ const q = new URL(location.href).searchParams;
+ const prompts = q.get('prompts');
+ if (prompts) els.prompts.value = prompts;
+ const budget = Object.assign({}, DEFAULT_BUDGET);
+ if (q.get('tri')) budget.maxTriangles = clamp(parseInt(q.get('tri'), 10) || 0, 100, 2000000);
+ if (q.get('mb')) budget.maxSizeMb = clamp(parseFloat(q.get('mb')) || 0, 0.1, 64);
+ if (q.get('mat')) budget.maxMaterials = clamp(parseInt(q.get('mat'), 10) || 0, 0, 256);
+ budget.requireTextures = q.get('tex') === '1';
+ budget.requireMaterials = q.get('rmat') === '1';
+ applyBudgetToForm(budget);
+ return Boolean(prompts);
+ }
+
+ /* ── Tooltips ──────────────────────────────────────────────────────── */
+
+ /*
+ * A real tooltip rather than a `title` attribute: keyboard reachable,
+ * announced through aria-describedby, dismissible with Escape, and readable
+ * long enough to explain a decision. Every hint on this page answers "why is
+ * this control here", which is the question a title attribute never gets to.
+ */
+ function initTooltips() {
+ const tip = els.tip;
+ tip.id = 'pl-tip';
+ let current = null;
+
+ function hide() {
+ if (!current) return;
+ current.setAttribute('aria-expanded', 'false');
+ current.removeAttribute('aria-describedby');
+ current = null;
+ tip.hidden = true;
+ }
+
+ function show(button) {
+ if (current === button) return;
+ hide();
+ current = button;
+ tip.textContent = button.dataset.hint || '';
+ tip.hidden = false;
+ button.setAttribute('aria-expanded', 'true');
+ button.setAttribute('aria-describedby', 'pl-tip');
+
+ const rect = button.getBoundingClientRect();
+ const width = Math.min(300, window.innerWidth - 24);
+ tip.style.width = width + 'px';
+ let left = rect.left + rect.width / 2 - width / 2;
+ left = clamp(left, 12, window.innerWidth - width - 12);
+ tip.style.left = left + 'px';
+ // Prefer above; flip below when the button sits near the top.
+ const height = tip.offsetHeight;
+ const above = rect.top - height - 10;
+ tip.style.top = (above > 8 ? above : rect.bottom + 10) + 'px';
+ tip.dataset.flipped = above > 8 ? 'false' : 'true';
+ }
+
+ document.querySelectorAll('.pl-hint').forEach((button) => {
+ button.setAttribute('aria-expanded', 'false');
+ button.addEventListener('mouseenter', () => show(button));
+ button.addEventListener('focus', () => show(button));
+ button.addEventListener('mouseleave', hide);
+ button.addEventListener('blur', hide);
+ button.addEventListener('click', (event) => {
+ event.preventDefault();
+ if (current === button) hide();
+ else show(button);
+ });
+ });
+
+ document.addEventListener('keydown', (event) => {
+ if (event.key === 'Escape') hide();
+ });
+ window.addEventListener('scroll', hide, { passive: true });
+ window.addEventListener('resize', hide);
+ }
+
+ /* ── Boot ──────────────────────────────────────────────────────────── */
+
+ function updatePromptCount() {
+ const n = readPrompts().length;
+ els.promptCount.textContent =
+ n === 0 ? 'No prompts yet' : n + (n === 1 ? ' prompt' : ' prompts') + ', about ' + estimate(n);
+ els.eta.textContent = n
+ ? 'Roughly ' + estimate(n) + ' at ' + (parseInt(els.workers.value, 10) || DEFAULT_WORKERS) + ' at a time.'
+ : '';
+ }
+
+ /* Honest arithmetic, not a promise: a draft takes 60 to 120 seconds on the
+ free lane, so a pack takes about ninety seconds per wave of workers. */
+ function estimate(count) {
+ const workers = clamp(parseInt(els.workers.value, 10) || DEFAULT_WORKERS, 1, MAX_WORKERS);
+ const waves = Math.ceil(count / workers);
+ return formatDuration(waves * 95000);
+ }
+
+ function initPresets() {
+ els.presets.innerHTML = PRESETS.map(
+ (p, i) =>
+ '<button class="pl-preset" type="button" data-preset="' +
+ i +
+ '">' +
+ escapeHtml(p.name) +
+ '</button>',
+ ).join('');
+ els.presets.addEventListener('click', (event) => {
+ const button = event.target.closest('[data-preset]');
+ if (!button) return;
+ els.prompts.value = PRESETS[Number(button.dataset.preset)].prompts.join('\n');
+ updatePromptCount();
+ els.prompts.focus();
+ });
+ }
+
+ function boot() {
+ cacheEls();
+ initPresets();
+ initTooltips();
+
+ // Arriving at an empty textarea is a step nobody needs: the page opens on a
+ // pack that already works, so the first action available is "Run".
+ const fromUrl = readUrlConfig();
+ if (!fromUrl) els.prompts.value = PRESETS[0].prompts.join('\n');
+ updatePromptCount();
+
+ els.prompts.addEventListener('input', updatePromptCount);
+ els.workers.addEventListener('input', updatePromptCount);
+ els.form.addEventListener('submit', (event) => {
+ event.preventDefault();
+ if (!state.running) run();
+ });
+ els.stop.addEventListener('click', stop);
+
+ els.dlManifest.addEventListener('click', () => {
+ download(
+ new Blob([JSON.stringify(manifest(), null, 2)], { type: 'application/json' }),
+ 'manifest.json',
+ );
+ log('saved manifest.json', 'ok');
+ });
+ els.dlAll.addEventListener('click', downloadAll);
+ els.share.addEventListener('click', () =>
+ copyText(shareLink(), els.share, 'Link copied'),
+ );
+ els.copyRepro.addEventListener('click', () =>
+ copyText(reproCommands(), els.copyRepro, 'Copied'),
+ );
+
+ // Cmd/Ctrl+Enter runs from anywhere on the page, Escape stops a live run.
+ document.addEventListener('keydown', (event) => {
+ if ((event.metaKey || event.ctrlKey) && event.key === 'Enter') {
+ event.preventDefault();
+ if (!state.running) run();
+ } else if (event.key === 'Escape' && state.running) {
+ stop();
+ }
+ });
+
+ window.addEventListener('beforeunload', (event) => {
+ if (!state.running) return;
+ event.preventDefault();
+ event.returnValue = '';
+ });
+
+ const restored = restore();
+ if (restored) applyBudgetToForm(state.budget);
+ else log('ready. Press Run pipeline, or Cmd+Enter.');
+ }
+
+ if (document.readyState === 'loading') {
+ document.addEventListener('DOMContentLoaded', boot);
+ } else {
+ boot();
+ }
+
+ // Exposed so the gate's parity with asset_gate.py can be asserted in tests.
+ window.PipelineStudio = { evaluate: evaluate, slugify: slugify, uniqueSlugs: uniqueSlugs };
+})();