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.

chore(capture): retire duplicate camera module

nirholas989620b907e2
diff --git a/prompts/archive/final-integration/06-camera-capture-resolution.md b/prompts/archive/final-integration/06-camera-capture-resolution.md
new file mode 100644
index 000000000..deedc5bd9
--- /dev/null
+++ b/prompts/archive/final-integration/06-camera-capture-resolution.md
@@ -0,0 +1,97 @@
+# 06 — Camera Capture Module: Resolve or Retire
+
+## Context
+
+[src/camera-capture.js](../../src/camera-capture.js) (321 LOC) is a substantial, well-written module for in-browser camera preview + photo capture. It was shipped by sprint-100 prompt 04 to power the selfie-to-agent flow. But the selfie pipeline landed with **a different module** — [src/selfie-capture.js](../../src/selfie-capture.js) — and `camera-capture.js` now has zero import sites.
+
+This orphan is a liability: 321 LOC of code that must be maintained, imports `./camera-capture.css`, and ships in the bundle (even if tree-shaken, tool-chain incidents can resurrect it). Worse, two capture modules existing side-by-side is confusing for future contributors.
+
+Your job: resolve the duplication. Either **delete** `camera-capture.js` cleanly, or **consolidate** both modules into one canonical implementation used by the selfie pipeline.
+
+## Goal
+
+Pick one of these two paths and execute it fully:
+
+### Path A — Delete (recommended if selfie-capture.js is sufficient)
+
+1. Read both files. Confirm `src/selfie-capture.js` covers every user-visible feature of `src/camera-capture.js`. If not, do not choose this path; fall through to Path B.
+2. Delete `src/camera-capture.js` and `src/camera-capture.css`.
+3. `git grep -n "camera-capture"` → every hit should be in a comment, doc, or gone. Remove stale references.
+4. Update any docs that reference camera-capture (check `docs/`, `specs/`, `.github/skills/`).
+
+### Path B — Consolidate
+
+1. Identify the richer/better module. Likely `camera-capture.js` (has a cleaner `CameraCapture` class, SSR guard, aspect config).
+2. Move its API into `src/selfie-capture.js` under the existing public surface the selfie pipeline expects, or vice versa — pick whichever disrupts fewer callers.
+3. Delete the retired file + its CSS.
+4. Verify `src/selfie-pipeline.js` still works end-to-end.
+
+Either path: **only one camera capture module must exist at the end.**
+
+## Files you own
+
+Edit / delete:
+- `src/camera-capture.js`
+- `src/camera-capture.css`
+- `src/selfie-capture.js` (only if you choose Path B and need to merge APIs)
+- Any doc that currently references `camera-capture` — surgical fixes only.
+
+## Files read-only
+
+- `src/selfie-capture.js` (Path A) — verify feature parity before deletion.
+- `src/selfie-pipeline.js` — understand how captures get consumed.
+- `public/create/**` — any pages that invoke the selfie flow.
+- `src/avatar-creator.js` — adjacent capture surface, do not edit.
+
+## Feature parity checklist (Path A decision gate)
+
+Before deleting `camera-capture.js`, confirm `selfie-capture.js` supports ALL of:
+
+- [ ] Preview video element mounted into a caller-supplied container.
+- [ ] Photo capture returning a `Blob` with `{ width, height, mimeType }` metadata.
+- [ ] Cancel/dispose that releases the media stream.
+- [ ] SSR-safe import (no `navigator` access at module top level).
+- [ ] Configurable aspect ratio.
+- [ ] Graceful fallback when `getUserMedia` is unavailable (browser denies permission, iOS Safari quirks, etc.).
+- [ ] CSS scoped to its own namespace; no global leakage.
+
+If any box is unchecked, either close the gap in `selfie-capture.js` as part of Path A (keep the delete) or switch to Path B.
+
+## Technical requirements
+
+- Keep ESM, tabs, 4-wide, single quotes.
+- Run Prettier.
+- `git grep -n "camera-capture"` returns zero code references at the end (docs/CHANGELOG references are fine as historical notes).
+- `npm run build` succeeds with one less module in the bundle (or identical bundle if Path B just swapped names).
+
+## Deliverables checklist
+
+- [ ] Decision documented at top of your report: Path A or Path B + why.
+- [ ] Feature parity table checked off (Path A) or migration diff summarized (Path B).
+- [ ] Exactly one camera capture module exists after you finish.
+- [ ] Every import site still resolves.
+- [ ] No dangling CSS.
+- [ ] Prettier pass.
+
+## Acceptance
+
+- `git grep -n "from.*camera-capture" src/ public/` returns zero hits (Path A) or one canonical import site (Path B).
+- `node --check` passes on every remaining capture-related JS file.
+- `npm run build` succeeds.
+- Manual smoke at the create/selfie page: camera permission prompt still appears; capture still produces a usable blob that flows into the rest of the pipeline.
+
+## Report + archive
+
+Post the report block from `00-README.md`. Include:
+- Path taken (A or B).
+- Feature parity gaps found (if any) and how you closed them.
+- Files deleted.
+- Bundle size delta from `npm run build` before/after.
+
+Then:
+
+```bash
+git mv prompts/final-integration/06-camera-capture-resolution.md prompts/archive/final-integration/06-camera-capture-resolution.md
+```
+
+Commit: `chore(capture): retire duplicate camera module` (Path A) or `refactor(capture): consolidate selfie + camera capture` (Path B).
diff --git a/src/camera-capture.css b/src/camera-capture.css
deleted file mode 100644
index 538b5a015..000000000
--- a/src/camera-capture.css
+++ /dev/null
@@ -1,147 +0,0 @@
-.camera-capture-root {
- position: relative;
- width: 100%;
- height: 100%;
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- background: #0a0a0a;
- color: #fff;
- font-family: system-ui, sans-serif;
- overflow: hidden;
-}
-
-.camera-capture-root .cc-preview-wrap {
- position: relative;
- width: min(100%, 480px);
- aspect-ratio: 1 / 1;
- border-radius: 12px;
- overflow: hidden;
- background: #111;
- box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.08);
-}
-
-.camera-capture-root video.cc-video,
-.camera-capture-root img.cc-snapshot {
- width: 100%;
- height: 100%;
- object-fit: cover;
- display: block;
-}
-
-.camera-capture-root video.cc-video {
- transform: scaleX(-1); /* mirror for selfie UX */
-}
-
-.camera-capture-root .cc-controls {
- display: flex;
- align-items: center;
- gap: 16px;
- margin-top: 20px;
- flex-wrap: wrap;
- justify-content: center;
-}
-
-.camera-capture-root button {
- cursor: pointer;
- border: none;
- font-size: 15px;
- border-radius: 999px;
- padding: 10px 24px;
- font-weight: 600;
- transition: opacity 0.15s, transform 0.1s;
-}
-
-.camera-capture-root button:active {
- transform: scale(0.96);
- opacity: 0.85;
-}
-
-.camera-capture-root .cc-btn-capture {
- width: 64px;
- height: 64px;
- padding: 0;
- border-radius: 50%;
- background: #fff;
- box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.25);
- flex-shrink: 0;
-}
-
-.camera-capture-root .cc-btn-capture::after {
- content: '';
- display: block;
- width: 48px;
- height: 48px;
- border-radius: 50%;
- background: #e0e0e0;
- margin: auto;
-}
-
-.camera-capture-root .cc-btn-switch {
- background: rgba(255, 255, 255, 0.12);
- color: #fff;
- font-size: 20px;
- width: 44px;
- height: 44px;
- padding: 0;
- border-radius: 50%;
-}
-
-.camera-capture-root .cc-btn-use {
- background: #4f8ef7;
- color: #fff;
-}
-
-.camera-capture-root .cc-btn-retake {
- background: rgba(255, 255, 255, 0.12);
- color: #fff;
-}
-
-.camera-capture-root .cc-link-upload {
- margin-top: 10px;
- font-size: 13px;
- color: rgba(255, 255, 255, 0.45);
- cursor: pointer;
- text-decoration: underline;
- background: none;
- border: none;
- padding: 4px 8px;
- border-radius: 4px;
-}
-
-.camera-capture-root .cc-link-upload:hover {
- color: rgba(255, 255, 255, 0.75);
-}
-
-.camera-capture-root .cc-fallback {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: 12px;
- padding: 32px;
- text-align: center;
-}
-
-.camera-capture-root .cc-fallback p {
- font-size: 14px;
- color: rgba(255, 255, 255, 0.55);
- margin: 0;
- max-width: 280px;
- line-height: 1.5;
-}
-
-.camera-capture-root .cc-btn-file-pick {
- background: #4f8ef7;
- color: #fff;
-}
-
-.camera-capture-root .cc-hidden-input {
- display: none;
-}
-
-.camera-capture-root .cc-error {
- font-size: 13px;
- color: #ff6b6b;
- margin-top: 8px;
-}
diff --git a/src/camera-capture.js b/src/camera-capture.js
deleted file mode 100644
index 542e2f31d..000000000
--- a/src/camera-capture.js
+++ /dev/null
@@ -1,321 +0,0 @@
-import './camera-capture.css';
-
-// Guard SSR environments — module must be importable without a DOM.
-const _hasNav = typeof navigator !== 'undefined';
-
-export class CameraCapture {
- /**
- * @param {object} opts
- * @param {HTMLElement} opts.container
- * @param {(blob: Blob, meta: {width:number, height:number, mimeType:string}) => void} opts.onCapture
- * @param {() => void} [opts.onCancel]
- * @param {number} [opts.aspect]
- */
- constructor({ container, onCapture, onCancel, aspect = 1 }) {
- this._container = container;
- this._onCapture = onCapture;
- this._onCancel = onCancel ?? (() => {});
- this._aspect = aspect;
-
- this._stream = null;
- this._facingMode = 'user';
- this._root = null;
- this._video = null;
- this._canvas = null;
- this._snapshot = null; // current preview blob URL
- this._stopped = false;
- this._abortCtrl = new AbortController();
- }
-
- async start() {
- if (this._stopped) return;
-
- this._root = document.createElement('div');
- this._root.className = 'camera-capture-root';
- this._container.appendChild(this._root);
-
- if (!_hasNav || !navigator.mediaDevices?.getUserMedia) {
- this._renderFallback('Camera not available in this browser.');
- return;
- }
-
- try {
- await this._startStream();
- this._renderLive();
- } catch (err) {
- const msg =
- err.name === 'NotAllowedError' || err.name === 'PermissionDeniedError'
- ? 'Camera permission denied.'
- : 'Could not access camera.';
- this._renderFallback(msg);
- }
- }
-
- stop() {
- if (this._stopped) return;
- this._stopped = true;
- this._abortCtrl.abort();
- this._releaseStream();
- if (this._snapshot) {
- URL.revokeObjectURL(this._snapshot);
- this._snapshot = null;
- }
- if (this._root && this._root.parentNode) {
- this._root.parentNode.removeChild(this._root);
- }
- this._root = null;
- }
-
- // ── private ────────────────────────────────────────────────────────────
-
- async _startStream() {
- this._releaseStream();
- this._stream = await navigator.mediaDevices.getUserMedia({
- video: {
- facingMode: this._facingMode,
- width: { ideal: 1280 },
- height: { ideal: 1280 },
- },
- });
- }
-
- _releaseStream() {
- if (this._stream) {
- for (const track of this._stream.getTracks()) track.stop();
- this._stream = null;
- }
- if (this._video) {
- this._video.srcObject = null;
- }
- }
-
- _listen(el, event, handler) {
- el.addEventListener(event, handler, { signal: this._abortCtrl.signal });
- }
-
- // ── live view ──────────────────────────────────────────────────────────
-
- _renderLive() {
- this._root.innerHTML = '';
-
- const wrap = document.createElement('div');
- wrap.className = 'cc-preview-wrap';
-
- const video = document.createElement('video');
- video.className = 'cc-video';
- video.autoplay = true;
- video.muted = true;
- video.setAttribute('playsinline', ''); // iOS Safari requires this attribute
- video.setAttribute('webkit-playsinline', ''); // older Safari compat
- video.srcObject = this._stream;
- this._video = video;
-
- wrap.appendChild(video);
- this._root.appendChild(wrap);
-
- const controls = document.createElement('div');
- controls.className = 'cc-controls';
-
- // Switch-camera button — only useful on mobile (multiple cameras)
- const btnSwitch = document.createElement('button');
- btnSwitch.className = 'cc-btn-switch';
- btnSwitch.title = 'Switch camera';
- btnSwitch.textContent = '⇄';
- this._listen(btnSwitch, 'click', () => this._switchCamera());
-
- const btnCapture = document.createElement('button');
- btnCapture.className = 'cc-btn-capture';
- btnCapture.setAttribute('aria-label', 'Capture photo');
- this._listen(btnCapture, 'click', () => this._capture());
-
- // Spacer so layout is symmetric around the large button
- const spacer = document.createElement('div');
- spacer.style.width = '44px';
-
- controls.appendChild(btnSwitch);
- controls.appendChild(btnCapture);
- controls.appendChild(spacer);
- this._root.appendChild(controls);
-
- const uploadLink = document.createElement('button');
- uploadLink.className = 'cc-link-upload';
- uploadLink.textContent = 'Use upload instead';
- this._listen(uploadLink, 'click', () => {
- this._releaseStream();
- this._renderFallback(null);
- });
- this._root.appendChild(uploadLink);
- }
-
- async _switchCamera() {
- this._facingMode = this._facingMode === 'user' ? 'environment' : 'user';
- try {
- await this._startStream();
- if (this._video) this._video.srcObject = this._stream;
- } catch (_) {
- // revert if the back camera isn't available
- this._facingMode = this._facingMode === 'user' ? 'environment' : 'user';
- }
- }
-
- _capture() {
- if (!this._video || !this._stream) return;
-
- const v = this._video;
- const side = Math.min(v.videoWidth || 1280, v.videoHeight || 1280);
- const ox = ((v.videoWidth || side) - side) / 2;
- const oy = ((v.videoHeight || side) - side) / 2;
-
- const canvas = document.createElement('canvas');
- canvas.width = side;
- canvas.height = side;
- const ctx = canvas.getContext('2d');
-
- // Mirror to match the CSS transform on the live preview
- ctx.save();
- ctx.translate(side, 0);
- ctx.scale(-1, 1);
- ctx.drawImage(v, ox, oy, side, side, 0, 0, side, side);
- ctx.restore();
-
- this._canvas = canvas;
-
- canvas.toBlob(
- (blob) => {
- if (!blob || this._stopped) return;
- this._renderPreview(blob, side, side);
- },
- 'image/jpeg',
- 0.92,
- );
- }
-
- // ── preview (post-capture) ─────────────────────────────────────────────
-
- _renderPreview(blob, width, height) {
- if (this._snapshot) URL.revokeObjectURL(this._snapshot);
- this._snapshot = URL.createObjectURL(blob);
-
- this._root.innerHTML = '';
-
- const wrap = document.createElement('div');
- wrap.className = 'cc-preview-wrap';
-
- const img = document.createElement('img');
- img.className = 'cc-snapshot';
- img.src = this._snapshot;
- img.alt = 'Captured photo preview';
- wrap.appendChild(img);
- this._root.appendChild(wrap);
-
- const controls = document.createElement('div');
- controls.className = 'cc-controls';
-
- const btnRetake = document.createElement('button');
- btnRetake.className = 'cc-btn-retake';
- btnRetake.textContent = 'Retake';
- this._listen(btnRetake, 'click', async () => {
- try {
- await this._startStream();
- this._renderLive();
- } catch (err) {
- this._renderFallback('Could not restart camera.');
- }
- });
-
- const btnUse = document.createElement('button');
- btnUse.className = 'cc-btn-use';
- btnUse.textContent = 'Use this photo';
- this._listen(btnUse, 'click', () => {
- this._releaseStream();
- this._onCapture(blob, { width, height, mimeType: 'image/jpeg' });
- });
-
- controls.appendChild(btnRetake);
- controls.appendChild(btnUse);
- this._root.appendChild(controls);
- }
-
- // ── file-upload fallback ───────────────────────────────────────────────
-
- _renderFallback(reason) {
- this._root.innerHTML = '';
-
- const wrap = document.createElement('div');
- wrap.className = 'cc-fallback';
-
- if (reason) {
- const err = document.createElement('p');
- err.className = 'cc-error';
- err.textContent = reason;
- wrap.appendChild(err);
- }
-
- const p = document.createElement('p');
- p.textContent = 'Choose a photo from your device to continue.';
- wrap.appendChild(p);
-
- const input = document.createElement('input');
- input.type = 'file';
- input.accept = 'image/*';
- input.setAttribute('capture', 'user');
- input.className = 'cc-hidden-input';
-
- const btnPick = document.createElement('button');
- btnPick.className = 'cc-btn-file-pick';
- btnPick.textContent = 'Choose photo';
- this._listen(btnPick, 'click', () => input.click());
-
- this._listen(input, 'change', () => {
- const file = input.files?.[0];
- if (!file) return;
- this._handleFileBlob(file);
- });
-
- wrap.appendChild(btnPick);
- wrap.appendChild(input);
-
- const cancelBtn = document.createElement('button');
- cancelBtn.className = 'cc-link-upload';
- cancelBtn.textContent = 'Cancel';
- this._listen(cancelBtn, 'click', () => {
- this.stop();
- this._onCancel();
- });
- wrap.appendChild(cancelBtn);
-
- this._root.appendChild(wrap);
- }
-
- _handleFileBlob(file) {
- const url = URL.createObjectURL(file);
- const img = new Image();
- img.onload = () => {
- const side = Math.min(img.naturalWidth, img.naturalHeight);
- const ox = (img.naturalWidth - side) / 2;
- const oy = (img.naturalHeight - side) / 2;
-
- const canvas = document.createElement('canvas');
- canvas.width = side;
- canvas.height = side;
- const ctx = canvas.getContext('2d');
- ctx.drawImage(img, ox, oy, side, side, 0, 0, side, side);
- URL.revokeObjectURL(url);
-
- canvas.toBlob(
- (blob) => {
- if (!blob || this._stopped) return;
- this._onCapture(blob, {
- width: side,
- height: side,
- mimeType: 'image/jpeg',
- });
- },
- 'image/jpeg',
- 0.92,
- );
- };
- img.onerror = () => URL.revokeObjectURL(url);
- img.src = url;
- }
-}