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(plugins): implement plugin marketplace features including installation, search, and category management

nirholas88547dabc350
diff --git a/public/marketplace.css b/public/marketplace.css
index 86abe76ef..4fff72c77 100644
--- a/public/marketplace.css
+++ b/public/marketplace.css
@@ -818,3 +818,294 @@ body.market-page {
background: var(--mk-panel-3, #e5e7eb);
color: var(--mk-text-3);
}
+
+/* ── Plugin marketplace ───────────────────────────────────────────────────── */
+
+.plugins-topbar {
+ flex-direction: column;
+ align-items: stretch;
+ gap: 10px;
+}
+
+.plugins-header-row {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 12px;
+}
+
+.plugin-add-url-btn {
+ background: transparent;
+ border: 1px solid var(--mk-border-2);
+ color: var(--mk-text-2);
+ border-radius: 8px;
+ padding: 7px 14px;
+ font-size: 13px;
+ font-weight: 500;
+ cursor: pointer;
+ transition: border-color 0.15s, color 0.15s;
+}
+
+.plugin-add-url-btn:hover {
+ border-color: var(--mk-accent);
+ color: var(--mk-accent);
+}
+
+#plugin-search {
+ width: 100%;
+ background: var(--mk-panel);
+ border: 1px solid var(--mk-border);
+ border-radius: 8px;
+ padding: 9px 12px;
+ color: var(--mk-text);
+ font-size: 14px;
+ font-family: inherit;
+ outline: none;
+ box-sizing: border-box;
+}
+
+#plugin-search:focus {
+ border-color: var(--mk-border-2);
+}
+
+.plugin-grid {
+ display: grid;
+ grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
+ gap: 14px;
+ padding: 4px 0 80px;
+ align-content: start;
+}
+
+.plugin-card {
+ background: var(--mk-panel);
+ border: 1px solid var(--mk-border);
+ border-radius: var(--mk-radius);
+ padding: 16px;
+ display: flex;
+ flex-direction: column;
+ gap: 10px;
+ transition: border-color 0.15s;
+}
+
+.plugin-card:hover {
+ border-color: var(--mk-border-2);
+}
+
+.plugin-card .head {
+ display: flex;
+ align-items: center;
+ gap: 12px;
+}
+
+.plugin-card .avatar {
+ width: 38px;
+ height: 38px;
+ border-radius: 10px;
+ background: var(--mk-panel-2);
+ display: grid;
+ place-items: center;
+ font-size: 18px;
+ font-weight: 600;
+ flex-shrink: 0;
+ color: var(--mk-text-2);
+}
+
+.plugin-card .title {
+ font-weight: 600;
+ font-size: 14px;
+ color: var(--mk-text);
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+}
+
+.plugin-card .author {
+ font-size: 12px;
+ color: var(--mk-text-3);
+ margin-top: 2px;
+}
+
+.plugin-card .desc {
+ font-size: 13px;
+ color: var(--mk-text-2);
+ line-height: 1.5;
+ flex: 1;
+ display: -webkit-box;
+ -webkit-line-clamp: 2;
+ -webkit-box-orient: vertical;
+ overflow: hidden;
+}
+
+.plugin-tags {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 5px;
+}
+
+.tag-pill {
+ background: var(--mk-panel-2);
+ border-radius: 5px;
+ padding: 2px 7px;
+ font-size: 11px;
+ color: var(--mk-text-3);
+}
+
+.plugin-card-footer {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 8px;
+ margin-top: 2px;
+}
+
+.plugin-install-btn {
+ background: var(--mk-accent);
+ color: #0a0a0a;
+ border: 0;
+ border-radius: 8px;
+ padding: 7px 14px;
+ font-size: 12px;
+ font-weight: 600;
+ cursor: pointer;
+ transition: opacity 0.15s;
+ white-space: nowrap;
+}
+
+.plugin-install-btn:hover {
+ opacity: 0.85;
+}
+
+.plugin-install-btn.installed {
+ background: #1a2e1a;
+ color: #4ade80;
+ border: 1px solid #166534;
+}
+
+/* ── Add by URL modal ──────────────────────���──────────────────────────────── */
+
+.plugin-modal-overlay {
+ position: fixed;
+ inset: 0;
+ background: rgba(0, 0, 0, 0.7);
+ display: grid;
+ place-items: center;
+ z-index: 1000;
+ padding: 20px;
+ backdrop-filter: blur(4px);
+}
+
+.plugin-modal {
+ background: var(--mk-panel);
+ border: 1px solid var(--mk-border-2);
+ border-radius: 16px;
+ padding: 28px;
+ width: 100%;
+ max-width: 460px;
+ display: flex;
+ flex-direction: column;
+ gap: 14px;
+}
+
+.plugin-modal h3 {
+ margin: 0;
+ font-size: 16px;
+ font-weight: 600;
+ color: var(--mk-text);
+}
+
+.plugin-modal-hint {
+ margin: 0;
+ font-size: 13px;
+ color: var(--mk-text-2);
+ line-height: 1.6;
+}
+
+.plugin-modal-hint code {
+ background: var(--mk-panel-2);
+ border-radius: 4px;
+ padding: 1px 5px;
+ font-size: 12px;
+}
+
+.plugin-url-input {
+ background: var(--mk-panel-2);
+ border: 1px solid var(--mk-border-2);
+ border-radius: 8px;
+ padding: 10px 12px;
+ color: var(--mk-text);
+ font-size: 13px;
+ font-family: monospace;
+ outline: none;
+ width: 100%;
+ box-sizing: border-box;
+}
+
+.plugin-url-input:focus {
+ border-color: var(--mk-accent);
+}
+
+.plugin-url-error {
+ font-size: 13px;
+ color: #f87171;
+ padding: 8px 10px;
+ background: rgba(239, 68, 68, 0.08);
+ border-radius: 6px;
+}
+
+.plugin-modal-preview {
+ background: var(--mk-panel-2);
+ border: 1px solid var(--mk-border);
+ border-radius: 10px;
+ padding: 14px;
+ display: flex;
+ flex-direction: column;
+ gap: 8px;
+}
+
+.plugin-preview-head {
+ display: flex;
+ align-items: baseline;
+ gap: 8px;
+}
+
+.plugin-preview-head strong {
+ font-size: 14px;
+ color: var(--mk-text);
+}
+
+.plugin-preview-desc {
+ font-size: 13px;
+ color: var(--mk-text-2);
+ line-height: 1.5;
+}
+
+.plugin-modal-actions {
+ display: flex;
+ justify-content: flex-end;
+ gap: 10px;
+ margin-top: 4px;
+}
+
+.plugin-modal-btn {
+ background: var(--mk-panel-2);
+ border: 1px solid var(--mk-border);
+ color: var(--mk-text-2);
+ border-radius: 8px;
+ padding: 9px 18px;
+ font-size: 13px;
+ font-weight: 500;
+ cursor: pointer;
+ font-family: inherit;
+}
+
+.plugin-modal-btn-primary {
+ background: var(--mk-accent);
+ color: #0a0a0a;
+ border: 0;
+ font-weight: 600;
+}
+
+.plugin-modal-btn:disabled {
+ opacity: 0.5;
+ cursor: not-allowed;
+}
diff --git a/src/agent-avatar.js b/src/agent-avatar.js
index df713ce74..0e5400e38 100644
--- a/src/agent-avatar.js
+++ b/src/agent-avatar.js
@@ -198,6 +198,10 @@ export class AgentAvatar {
// Listeners stored so we can detach later
this._listeners = [];
+ // Spatial audio
+ this._tts = null;
+ this._positionalAudio = null;
+
this._tickBound = this._tickEmotion.bind(this);
this._onMouseMove = this._handleMouseMove.bind(this);
this._onKeyFollowDown = this._handleKeyPress.bind(this);
@@ -213,6 +217,9 @@ export class AgentAvatar {
// Build the morph mesh cache once instead of traversing every frame
this._buildMorphCache();
+ // Wire spatial audio to the loaded avatar
+ this._initSpatialAudio();
+
// Hook into the viewer's per-frame loop
if (!this.viewer._afterAnimateHooks) this.viewer._afterAnimateHooks = [];
this.viewer._afterAnimateHooks.push(this._tickBound);
@@ -271,6 +278,11 @@ export class AgentAvatar {
this._idle?.dispose();
this._idle = null;
// END:IDLE_LOOP_DISPOSE
+ if (this._positionalAudio) {
+ try { this._positionalAudio.disconnect(); } catch {}
+ this._positionalAudio.parent?.remove(this._positionalAudio);
+ this._positionalAudio = null;
+ }
}
// ── Public API ────────────────────────────────────────────────────────────
@@ -359,6 +371,18 @@ export class AgentAvatar {
}
}
+ /**
+ * Bind a TTS instance so spatial audio can be wired through it.
+ * Call before or after attach() — both orderings are handled.
+ * @param {import('./runtime/speech.js').ElevenLabsTTS|null} tts
+ */
+ setTTS(tts) {
+ this._tts = tts;
+ if (this._positionalAudio && tts instanceof ElevenLabsTTS) {
+ tts.setPositionalAudio(this._positionalAudio);
+ }
+ }
+
/** Set a world-space point for the avatar to look toward */
setLookTarget(worldPos) {
this._lookTarget = worldPos ? worldPos.clone() : null;
@@ -369,6 +393,26 @@ export class AgentAvatar {
return { ...this._emotion };
}
+ // ── Spatial Audio ─────────────────────────────────────────────────────────
+
+ _initSpatialAudio() {
+ if (!this.viewer.audioListener) return;
+ if (this._positionalAudio) {
+ this._positionalAudio.parent?.remove(this._positionalAudio);
+ }
+ this._positionalAudio = new PositionalAudio(this.viewer.audioListener);
+ this._positionalAudio.setRefDistance(1.5);
+ this._positionalAudio.setRolloffFactor(1.0);
+ this._positionalAudio.setDistanceModel('inverse');
+
+ const anchor = this._findHeadBone() ?? this.viewer.content;
+ if (anchor) anchor.add(this._positionalAudio);
+
+ if (this._tts instanceof ElevenLabsTTS) {
+ this._tts.setPositionalAudio(this._positionalAudio);
+ }
+ }
+
// ── Protocol Handlers ─────────────────────────────────────────────────────
_onSpeak(action) {
diff --git a/src/marketplace.js b/src/marketplace.js
index 81b19fd5d..c84dc6336 100644
--- a/src/marketplace.js
+++ b/src/marketplace.js
@@ -476,3 +476,311 @@ function init() {
}
init();
+
+// ── Plugin Marketplace ────────────────────────────────────────────────────────
+
+const PLUGIN_API = '/api/plugins';
+const PLUGIN_STORAGE_KEY = 'installed_plugins_v1';
+
+const pluginState = {
+ category: null,
+ q: '',
+ cursor: null,
+ items: [],
+ loading: false,
+ loaded: false,
+};
+
+function getInstalledIds() {
+ try {
+ const raw = localStorage.getItem(PLUGIN_STORAGE_KEY);
+ if (!raw) return new Set();
+ return new Set(JSON.parse(raw).map((p) => p.identifier));
+ } catch {
+ return new Set();
+ }
+}
+
+function saveInstalled(manifest) {
+ try {
+ const raw = localStorage.getItem(PLUGIN_STORAGE_KEY);
+ const arr = raw ? JSON.parse(raw) : [];
+ const idx = arr.findIndex((p) => p.identifier === manifest.identifier);
+ if (idx >= 0) arr[idx] = manifest;
+ else arr.push(manifest);
+ localStorage.setItem(PLUGIN_STORAGE_KEY, JSON.stringify(arr));
+ } catch {
+ // storage full
+ }
+}
+
+function removeInstalled(identifier) {
+ try {
+ const raw = localStorage.getItem(PLUGIN_STORAGE_KEY);
+ if (!raw) return;
+ const arr = JSON.parse(raw).filter((p) => p.identifier !== identifier);
+ localStorage.setItem(PLUGIN_STORAGE_KEY, JSON.stringify(arr));
+ } catch {}
+}
+
+function togglePluginInstall(manifest) {
+ const installed = getInstalledIds();
+ if (installed.has(manifest.identifier)) {
+ removeInstalled(manifest.identifier);
+ } else {
+ saveInstalled(manifest);
+ // fire-and-forget counter update if plugin has a DB id
+ if (manifest.id) {
+ fetch(`${PLUGIN_API}/${manifest.id}/install`, { method: 'POST' }).catch(() => {});
+ }
+ }
+ renderPluginGrid();
+}
+
+async function loadPluginCategories() {
+ try {
+ const r = await fetch(`${PLUGIN_API}/categories`);
+ const j = await r.json();
+ renderPluginCats(j?.data?.categories || []);
+ } catch {
+ // non-fatal
+ }
+}
+
+function renderPluginCats(cats) {
+ const el = $('plugin-cats');
+ if (!el) return;
+ const all = [{ slug: null, label: 'All', count: null }, ...cats.map((c) => ({
+ slug: c.slug,
+ label: c.slug.charAt(0).toUpperCase() + c.slug.slice(1),
+ count: c.count,
+ }))];
+ el.innerHTML = all.map((c) => {
+ const active = pluginState.category === c.slug;
+ return `<div class="cat-row${active ? ' active' : ''}" data-cat="${c.slug ?? ''}">
+ <span>${escapeHtml(c.label)}</span>
+ ${c.count != null ? `<span class="count">${c.count}</span>` : ''}
+ </div>`;
+ }).join('');
+ el.querySelectorAll('.cat-row').forEach((row) => {
+ row.addEventListener('click', () => {
+ pluginState.category = row.dataset.cat || null;
+ el.querySelectorAll('.cat-row').forEach((r) => r.classList.remove('active'));
+ row.classList.add('active');
+ loadPlugins(true);
+ });
+ });
+}
+
+async function loadPlugins(reset = false) {
+ if (pluginState.loading) return;
+ pluginState.loading = true;
+ if (reset) {
+ pluginState.items = [];
+ pluginState.cursor = null;
+ const grid = $('plugin-grid');
+ if (grid) grid.innerHTML = '<div class="market-empty">Loading…</div>';
+ }
+ try {
+ const url = new URL(PLUGIN_API + '/list', location.origin);
+ if (pluginState.category) url.searchParams.set('category', pluginState.category);
+ if (pluginState.q) url.searchParams.set('q', pluginState.q);
+ if (pluginState.cursor) url.searchParams.set('cursor', pluginState.cursor);
+ const r = await fetch(url);
+ const j = await r.json();
+ const items = j?.data?.items || [];
+ pluginState.items = reset ? items : [...pluginState.items, ...items];
+ pluginState.cursor = j?.data?.next_cursor || null;
+ pluginState.loaded = true;
+ renderPluginGrid();
+ } catch {
+ const grid = $('plugin-grid');
+ if (grid) grid.innerHTML = '<div class="market-empty">Failed to load plugins.</div>';
+ } finally {
+ pluginState.loading = false;
+ }
+}
+
+function renderPluginGrid() {
+ const grid = $('plugin-grid');
+ const more = $('plugin-loadmore');
+ if (!grid) return;
+ const installed = getInstalledIds();
+ if (!pluginState.items.length) {
+ grid.innerHTML = '<div class="market-empty">No plugins found.</div>';
+ if (more) more.hidden = true;
+ return;
+ }
+ grid.innerHTML = pluginState.items.map((p) => renderPluginCard(p, installed)).join('');
+ grid.querySelectorAll('[data-plugin-id]').forEach((btn) => {
+ btn.addEventListener('click', () => {
+ const id = btn.dataset.pluginId;
+ const manifest = pluginState.items.find((p) => p.identifier === id);
+ if (manifest) togglePluginInstall(manifest.manifest_json ?? manifest);
+ });
+ });
+ if (more) more.hidden = !pluginState.cursor;
+}
+
+function renderPluginCard(p, installed) {
+ const manifest = p.manifest_json ?? p;
+ const title = escapeHtml(p.name || manifest?.meta?.title || p.identifier || '?');
+ const desc = escapeHtml(p.description || manifest?.meta?.description || '');
+ const tags = (p.tags || manifest?.meta?.tags || []).slice(0, 3);
+ const toolCount = Array.isArray(manifest?.api) ? manifest.api.length : 0;
+ const isInstalled = installed.has(p.identifier);
+ const cat = escapeHtml(p.category || manifest?.meta?.category || 'general');
+ const icon = (p.name || p.identifier || '?')[0].toUpperCase();
+ return `<div class="plugin-card">
+ <div class="head">
+ <div class="avatar">${icon}</div>
+ <div style="min-width:0;flex:1">
+ <div class="title">${title}</div>
+ <div class="author">${toolCount} tool${toolCount !== 1 ? 's' : ''} · ${cat}</div>
+ </div>
+ </div>
+ <div class="desc">${desc}</div>
+ <div class="plugin-tags">
+ ${tags.map((t) => `<span class="tag-pill">${escapeHtml(t)}</span>`).join('')}
+ </div>
+ <div class="plugin-card-footer">
+ <span class="stat-pill">↓ ${p.install_count || 0}</span>
+ <button class="plugin-install-btn${isInstalled ? ' installed' : ''}"
+ data-plugin-id="${escapeHtml(p.identifier)}">
+ ${isInstalled ? 'Installed ✓' : 'Add to Agent'}
+ </button>
+ </div>
+ </div>`;
+}
+
+// ── Add by URL modal ──────────────────────────────────────────────────────────
+
+function openPluginUrlModal() {
+ const modal = $('plugin-url-modal');
+ const input = $('plugin-url-input');
+ const errEl = $('plugin-url-error');
+ const preview = $('plugin-url-preview');
+ if (!modal) return;
+ input.value = '';
+ errEl.hidden = true;
+ preview.hidden = true;
+ preview.innerHTML = '';
+ modal.hidden = false;
+ input.focus();
+}
+
+function closePluginUrlModal() {
+ const modal = $('plugin-url-modal');
+ if (modal) modal.hidden = true;
+}
+
+async function fetchAndInstallByUrl() {
+ const input = $('plugin-url-input');
+ const errEl = $('plugin-url-error');
+ const preview = $('plugin-url-preview');
+ const fetchBtn = $('plugin-url-fetch');
+ const url = (input?.value || '').trim();
+
+ errEl.hidden = true;
+ preview.hidden = true;
+
+ if (!url) {
+ showPluginUrlError('Please enter a URL.');
+ return;
+ }
+
+ fetchBtn.disabled = true;
+ fetchBtn.textContent = 'Fetching…';
+
+ try {
+ const r = await fetch(`${PLUGIN_API}/import`, {
+ method: 'POST',
+ headers: { 'content-type': 'application/json' },
+ body: JSON.stringify({ manifest_url: url }),
+ });
+ const j = await r.json();
+ if (!r.ok) {
+ showPluginUrlError(j?.error_description || `Error ${r.status}`);
+ return;
+ }
+ const manifest = j?.data?.manifest;
+ if (!manifest) {
+ showPluginUrlError('Server returned no manifest.');
+ return;
+ }
+
+ // Show preview
+ const title = escapeHtml(manifest.meta?.title || manifest.identifier || '?');
+ const desc = escapeHtml(manifest.meta?.description || '');
+ const toolCount = Array.isArray(manifest.api) ? manifest.api.length : 0;
+ preview.innerHTML = `<div class="plugin-preview-head">
+ <strong>${title}</strong>
+ <span class="muted">${toolCount} tool${toolCount !== 1 ? 's' : ''}</span>
+ </div>
+ ${desc ? `<div class="plugin-preview-desc">${desc}</div>` : ''}
+ <button class="plugin-modal-btn plugin-modal-btn-primary" id="plugin-url-install">Install Plugin</button>`;
+ preview.hidden = false;
+
+ $('plugin-url-install').addEventListener('click', () => {
+ saveInstalled(manifest);
+ closePluginUrlModal();
+ // Refresh grid to show updated install state
+ renderPluginGrid();
+ });
+ } catch (err) {
+ showPluginUrlError(err.message || 'Failed to fetch manifest.');
+ } finally {
+ fetchBtn.disabled = false;
+ fetchBtn.textContent = 'Fetch & Validate';
+ }
+}
+
+function showPluginUrlError(msg) {
+ const el = $('plugin-url-error');
+ if (!el) return;
+ el.textContent = msg;
+ el.hidden = false;
+}
+
+// ── Plugin init / wiring ──────────────────────────────────────────────────────
+
+function initPlugins() {
+ // Add by URL button
+ const addBtn = $('plugin-add-url');
+ if (addBtn) addBtn.addEventListener('click', openPluginUrlModal);
+
+ // Modal controls
+ const cancelBtn = $('plugin-url-cancel');
+ if (cancelBtn) cancelBtn.addEventListener('click', closePluginUrlModal);
+
+ const fetchBtn = $('plugin-url-fetch');
+ if (fetchBtn) fetchBtn.addEventListener('click', fetchAndInstallByUrl);
+
+ // Close on overlay click
+ const overlay = $('plugin-url-modal');
+ if (overlay) {
+ overlay.addEventListener('click', (e) => {
+ if (e.target === overlay) closePluginUrlModal();
+ });
+ }
+
+ // Plugin search
+ let pluginSearchTimer;
+ const searchInput = $('plugin-search');
+ if (searchInput) {
+ searchInput.addEventListener('input', (e) => {
+ clearTimeout(pluginSearchTimer);
+ pluginSearchTimer = setTimeout(() => {
+ pluginState.q = e.target.value.trim();
+ loadPlugins(true);
+ }, 200);
+ });
+ }
+
+ // Load more
+ const loadMoreBtn = $('plugin-loadmore');
+ if (loadMoreBtn) loadMoreBtn.addEventListener('click', () => loadPlugins(false));
+
+ // Load categories (lazy — don't block initial page render)
+ loadPluginCategories();
+}
diff --git a/vercel.json b/vercel.json
index 3aa06c846..cc6447d58 100644
--- a/vercel.json
+++ b/vercel.json
@@ -778,6 +778,30 @@
"src": "/discover/(.*)",
"dest": "/discover/$1"
},
+ {
+ "src": "/api/plugins/categories",
+ "dest": "/api/plugins/[action]?action=categories"
+ },
+ {
+ "src": "/api/plugins/list",
+ "dest": "/api/plugins/[action]?action=list"
+ },
+ {
+ "src": "/api/plugins/import",
+ "dest": "/api/plugins/[action]?action=import"
+ },
+ {
+ "src": "/api/plugins/publish",
+ "dest": "/api/plugins/[action]?action=publish"
+ },
+ {
+ "src": "/api/plugins/([^/]+)/install",
+ "dest": "/api/plugins/[action]?action=$1/install"
+ },
+ {
+ "src": "/api/plugins/([^/]+)",
+ "dest": "/api/plugins/[action]?action=$1"
+ },
{
"src": "/api/skills/categories",
"dest": "/api/skills/categories"