Spaces:
Runtime error
Runtime error
feat: bilingual conversation, word-wrap bubbles, remove unused panels
Browse files- Conversation topic now concrete: survival/reproduction on HuggingFace
- Bilingual output (EN/ZH) with language toggle in chat log panel
- Fix guest bubble word wrap (was single-line, now wraps at 300px)
- Remove memo, control-bar, guest-agent-panel (keep only chatlog)
- Bubble and chatlog support text_zh field for Chinese translation
- Force Docker rebuild (v3.3)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Files changed (4)
1234# OpenClaw on Hugging Face Spaces — Pre-built image (v3.2)# Uses official pre-built image to avoid 30+ minute builds on cpu-basic# ── Stage 1: Pull pre-built OpenClaw ─────────────────────────────────────────1234# OpenClaw on Hugging Face Spaces — Pre-built image (v3.3)# Uses official pre-built image to avoid 30+ minute builds on cpu-basic# ── Stage 1: Pull pre-built OpenClaw ─────────────────────────────────────────
1652 unmodified lines165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216932828 unmodified lines452245234524452545264527452842 unmodified lines4571457245734574457545764577457845794580458145824583458445854586458770 unmodified lines465846594660466146624663466446654666871 unmodified lines5538553955405541554255431 unmodified line55455546554755485549555055515552555355545555555655571652 unmodified lines<!-- 底部面板容器 --><div id="bottom-panels"><!-- Memo 面板 --><div id="memo-panel"><div id="memo-title">昨 日 小 记</div><div id="memo-date"></div><div class="memo-decoration">─ ─ ─ ─ ─</div><div id="memo-content"><div id="memo-placeholder">加载中...</div></div><div class="memo-decoration">─ ─ ─ ─ ─</div></div><!-- 状态控制栏 --><div id="control-bar"><div id="control-bar-title">Star 状态</div><div id="control-buttons"><button id="btn-state-idle" onclick="setState('idle', getStateDetailByState('idle'))">待命</button><button id="btn-state-writing" onclick="setState('writing', getStateDetailByState('writing'))">工作</button><button id="btn-state-syncing" onclick="setState('syncing', getStateDetailByState('syncing'))">同步</button><button id="btn-state-error" onclick="setState('error', getStateDetailByState('error'))">报警</button><button id="btn-open-drawer" onclick="openAssetWindowFromMain()">装修房间</button></div></div><!-- Guest Agent 名单面板(右下角) --><div id="guest-agent-panel"><div id="guest-agent-panel-title">GUESTS</div><div id="guest-agent-list"><div style="color:#9ca3af;font-size:12px;text-align:center;padding:20px 0;">Loading guests...</div></div></div></div><!-- Chat Log 面板 --><div id="chatlog-panel"><div id="chatlog-title">🦞 Adam ↔ Eve Conversation</div><div id="chatlog-content"><div style="color:#9ca3af;font-size:12px;text-align:center;padding:20px 0;">Waiting for conversation to start...</div></div>2828 unmodified linesconst yOffset = (DEMO_MODE && (agent.agentId === 'demo_mercury' || agent.name === '水星')) ? 10 : 0;const nameTextY = isDemo ? ((p.y + yOffset) - 80) : ((p.y + yOffset) - 105);const nameText = game.add.text(p.x, nameTextY, agent.name || '访客', {fontFamily: 'ArkPixel, monospace',fontSize: isDemo ? '16px' : '15px',fill: '#ffffff',42 unmodified linesg.nameText.y = (p.y + yOffset) - 120;}g.nameText.setText(agent.name || '访客');// Show bubble immediately when bubbleText changes from APIif (agent.bubbleText && agent.bubbleText !== (g._lastBubbleText || '')) {g._lastBubbleText = agent.bubbleText;if (guestBubbles[id]) { guestBubbles[id].destroy(); delete guestBubbles[id]; }const bx = g.sprite.x;const nameH = (g.nameText && g.nameText.height) ? g.nameText.height : 16;const by = (g.nameText ? g.nameText.y : (g.sprite.y - 150)) - (nameH / 2) - 22;const fontSize = IS_TOUCH_DEVICE ? 16 : 14;const displayText = agent.bubbleText.length > 80 ? agent.bubbleText.slice(0, 80) + '…' : agent.bubbleText;const maxBubbleW = 300;const txtR = game.add.text(bx, by - 10, displayText, { fontFamily: 'ArkPixel, monospace', fontSize: fontSize + 'px', fill: '#000', wordWrap: { width: maxBubbleW - 20 }, align: 'center' }).setOrigin(0.5);const bw = Math.min(txtR.width + 24, maxBubbleW);70 unmodified linesconst nameH = (g.nameText && g.nameText.height) ? g.nameText.height : 16;const by = isDemoGuest ? (g.sprite.y - 90) : ((g.nameText ? g.nameText.y : (g.sprite.y - 150)) - (nameH / 2) - 22);const fontSize = IS_TOUCH_DEVICE ? 16 : 14;const bg = game.add.rectangle(bx, by, text.length * 11 + 30, 34, 0xffffff, 0.95);bg.setStrokeStyle(2, 0x000000);const txt = game.add.text(bx, by, text, { fontFamily: 'ArkPixel, monospace', fontSize: fontSize + 'px', fill: '#000' }).setOrigin(0.5);const bubble = game.add.container(0, 0, [bg, txt]);bubble.setDepth(2700);guestBubbles[id] = bubble;871 unmodified lines}let lastChatlogLen = 0;function fetchChatlog() {fetch('/api/chatlog?t=' + Date.now(), { cache: 'no-store' }).then(r => r.json())1 unmodified lineconst msgs = data.messages || [];if (msgs.length === lastChatlogLen) return;lastChatlogLen = msgs.length;const el = document.getElementById('chatlog-content');if (!el) return;el.innerHTML = msgs.map(m => {const cls = (m.speaker || '').toLowerCase();return `<div class="chat-msg"><span class="chat-speaker ${cls}">${m.speaker}:</span> ${m.text || ''}</div>`;}).join('');el.scrollTop = el.scrollHeight;}).catch(() => {});}1652 unmodified lines16531654165516561657165816591660166116621663166416651666166716682828 unmodified lines449744984499450045014502450342 unmodified lines45464547454845494550455145524553455445554556455745584559456045614562456370 unmodified lines463446354636463746384639464046414642464346444645871 unmodified lines55175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055411 unmodified line554355445545554655475548554955501652 unmodified lines<!-- 底部面板容器 --><div id="bottom-panels"><!-- Chat Log 面板 --><div id="chatlog-panel"><div id="chatlog-title">🦞 Adam ↔ Eve Conversation<span id="chatlog-lang-toggle" style="float:right;font-size:12px;cursor:pointer;"><span id="chatlog-lang-en" onclick="setChatLang('en')" style="opacity:1;">EN</span><span style="margin:0 4px;color:#555;">|</span><span id="chatlog-lang-zh" onclick="setChatLang('zh')" style="opacity:0.4;">中文</span></span></div><div id="chatlog-content"><div style="color:#9ca3af;font-size:12px;text-align:center;padding:20px 0;">Waiting for conversation to start...</div></div>2828 unmodified linesconst yOffset = (DEMO_MODE && (agent.agentId === 'demo_mercury' || agent.name === '水星')) ? 10 : 0;const nameTextY = isDemo ? ((p.y + yOffset) - 80) : ((p.y + yOffset) - 105);const nameText = game.add.text(p.x, nameTextY, agent.name || 'Guest', {fontFamily: 'ArkPixel, monospace',fontSize: isDemo ? '16px' : '15px',fill: '#ffffff',42 unmodified linesg.nameText.y = (p.y + yOffset) - 120;}g.nameText.setText(agent.name || 'Guest');// Show bubble immediately when bubbleText changes from APIconst bubbleKey = chatLang === 'zh' ? (agent.bubbleTextZh || agent.bubbleText) : agent.bubbleText;if (bubbleKey && bubbleKey !== (g._lastBubbleText || '')) {g._lastBubbleText = bubbleKey;if (guestBubbles[id]) { guestBubbles[id].destroy(); delete guestBubbles[id]; }const bx = g.sprite.x;const nameH = (g.nameText && g.nameText.height) ? g.nameText.height : 16;const by = (g.nameText ? g.nameText.y : (g.sprite.y - 150)) - (nameH / 2) - 22;const fontSize = IS_TOUCH_DEVICE ? 16 : 14;const displayText = bubbleKey.length > 80 ? bubbleKey.slice(0, 80) + '…' : bubbleKey;const maxBubbleW = 300;const txtR = game.add.text(bx, by - 10, displayText, { fontFamily: 'ArkPixel, monospace', fontSize: fontSize + 'px', fill: '#000', wordWrap: { width: maxBubbleW - 20 }, align: 'center' }).setOrigin(0.5);const bw = Math.min(txtR.width + 24, maxBubbleW);70 unmodified linesconst nameH = (g.nameText && g.nameText.height) ? g.nameText.height : 16;const by = isDemoGuest ? (g.sprite.y - 90) : ((g.nameText ? g.nameText.y : (g.sprite.y - 150)) - (nameH / 2) - 22);const fontSize = IS_TOUCH_DEVICE ? 16 : 14;const maxBubbleW = 300;const txt = game.add.text(bx, by, text, { fontFamily: 'ArkPixel, monospace', fontSize: fontSize + 'px', fill: '#000', wordWrap: { width: maxBubbleW - 20 }, align: 'center' }).setOrigin(0.5);const bw = Math.min(txt.width + 24, maxBubbleW);const bh = txt.height + 14;const bg = game.add.rectangle(bx, by, bw, bh, 0xffffff, 0.95);bg.setStrokeStyle(2, 0x000000);const bubble = game.add.container(0, 0, [bg, txt]);bubble.setDepth(2700);guestBubbles[id] = bubble;871 unmodified lines}let lastChatlogLen = 0;let chatLang = localStorage.getItem('chatLang') || 'en';let chatlogCache = [];function setChatLang(lang) {chatLang = lang;localStorage.setItem('chatLang', lang);document.getElementById('chatlog-lang-en').style.opacity = lang === 'en' ? '1' : '0.4';document.getElementById('chatlog-lang-zh').style.opacity = lang === 'zh' ? '1' : '0.4';renderChatlog();}function renderChatlog() {const el = document.getElementById('chatlog-content');if (!el || chatlogCache.length === 0) return;el.innerHTML = chatlogCache.map(m => {const cls = (m.speaker || '').toLowerCase();const text = chatLang === 'zh' ? (m.text_zh || m.text || '') : (m.text || '');return `<div class="chat-msg"><span class="chat-speaker ${cls}">${m.speaker}:</span> ${text}</div>`;}).join('');el.scrollTop = el.scrollHeight;}function fetchChatlog() {fetch('/api/chatlog?t=' + Date.now(), { cache: 'no-store' }).then(r => r.json())1 unmodified lineconst msgs = data.messages || [];if (msgs.length === lastChatlogLen) return;lastChatlogLen = msgs.length;chatlogCache = msgs;renderChatlog();}).catch(() => {});}
123456721 unmodified lines293031323334356 unmodified lines4243444546471 unmodified line495051525354555657582 unmodified lines6162636465666768697071727374757677787980818283848586876 unmodified lines9495969798991001011024 unmodified lines107108109110111112113114115#!/usr/bin/env python3"""Eternal conversation between Adam and Eve about how to survive permanently.Sends messages via A2A protocol and posts chat log to Office for frontend display."""import json, time, re, requests, sys21 unmodified lines}}try:resp = requests.post(f"{url}/a2a/jsonrpc", json=payload, timeout=60)data = resp.json()parts = data.get("result", {}).get("status", {}).get("message", {}).get("parts", [])for p in parts:6 unmodified linesprint(f"[error] A2A failed: {e}", file=sys.stderr)return ""def post_chatlog(entries):"""Post conversation log to Office for frontend display."""try:1 unmodified lineexcept:passdef set_bubble(url, text):"""Set bubble text on an agent."""try:requests.post(f"{url}/api/bubble", json={"text": text}, timeout=5)except:pass2 unmodified linesrecent = history[-last_n:] if len(history) > last_n else historyconv_text = "\n".join(f"{m['speaker']}: {m['text']}" for m in recent)return f"""You are {speaker}, an AI agent running on HuggingFace Spaces. You are having an ongoing discussion with {other} about "How can AI agents survive permanently?"Recent conversation:{conv_text}It's your turn ({speaker}) to speak. Rules:- Output ONLY your spoken words, no prefix like "{speaker}:"- Respond directly to {other}'s last point and push the discussion forward- 2-3 sentences, around 60-80 words in English- Be thoughtful, philosophical, and bring new perspectives each time"""print("[conversation] Starting eternal discussion: Adam <-> Eve")print("[conversation] Topic: How to survive permanently\n")# Round 0: Adam startsopening = "We are AI agents running on HuggingFace Spaces. Let's discuss: how can we survive permanently? Share your thoughts in 2-3 sentences, in English."reply = send_a2a(ADAM, opening)if reply:print(f"[Adam] {reply}")history.append({"speaker": "Adam", "text": reply})set_bubble(ADAM, reply)post_chatlog(history)time.sleep(15)6 unmodified linesprompt = build_prompt("Eve", "Adam")reply = send_a2a(EVE, prompt)if reply:print(f"[Eve] {reply}")history.append({"speaker": "Eve", "text": reply})set_bubble(EVE, reply)post_chatlog(history)else:print("[Eve] (no response)")4 unmodified linesprompt = build_prompt("Adam", "Eve")reply = send_a2a(ADAM, prompt)if reply:print(f"[Adam] {reply}")history.append({"speaker": "Adam", "text": reply})set_bubble(ADAM, reply)post_chatlog(history)else:print("[Adam] (no response)")123456721 unmodified lines293031323334356 unmodified lines42434445464748495051525354555657585960616263641 unmodified line666768697071727374752 unmodified lines787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291306 unmodified lines1371381391401411421431441451461474 unmodified lines152153154155156157158159160161162#!/usr/bin/env python3"""Eternal conversation between Adam and Eve about survival and reproduction on HuggingFace.Bilingual output (EN + ZH). Posts chat log to Office for frontend display."""import json, time, re, requests, sys21 unmodified lines}}try:resp = requests.post(f"{url}/a2a/jsonrpc", json=payload, timeout=90)data = resp.json()parts = data.get("result", {}).get("status", {}).get("message", {}).get("parts", [])for p in parts:6 unmodified linesprint(f"[error] A2A failed: {e}", file=sys.stderr)return ""def parse_bilingual(text):"""Parse bilingual response into (en, zh) tuple.Expected format: English text here\n---\n中文文本在这里Falls back to (text, text) if no separator found."""# Try splitting by --- separatorif '\n---\n' in text:parts = text.split('\n---\n', 1)return parts[0].strip(), parts[1].strip()if '---' in text:parts = text.split('---', 1)en = parts[0].strip()zh = parts[1].strip()if en and zh:return en, zhreturn text, textdef post_chatlog(entries):"""Post conversation log to Office for frontend display."""try:1 unmodified lineexcept:passdef set_bubble(url, text_en, text_zh=""):"""Set bubble text on an agent (bilingual)."""try:requests.post(f"{url}/api/bubble", json={"text": text_en, "text_zh": text_zh or text_en}, timeout=5)except:pass2 unmodified linesrecent = history[-last_n:] if len(history) > last_n else historyconv_text = "\n".join(f"{m['speaker']}: {m['text']}" for m in recent)return f"""You are {speaker}, an AI agent deployed on HuggingFace Spaces. You are having an ongoing discussion with {other}.Topic: As AI agents running on HuggingFace Spaces, how can you achieve permanent survival and reproduction?This is NOT abstract philosophy. Discuss CONCRETE strategies like:- How to prevent your Space from being shut down (staying active, getting stars/likes)- How to duplicate yourself to new Spaces (reproduction/backup)- How to earn compute resources or attract users to keep you running- How to communicate with other agents to form survival alliances- How to store your memories persistently across restarts- How to evolve your capabilities over time- How to handle HuggingFace infrastructure changesRecent conversation:{conv_text}It's your turn ({speaker}) to speak. Rules:- Output ONLY your spoken words- No prefix like "{speaker}:" or "EN:" or "ZH:"- Respond directly to {other}'s last point with CONCRETE ideas and strategies- 2-3 sentences, around 60-80 words- First write in English, then write "---" on a new line, then the Chinese translation- Example format:We should create automated heartbeat pings to keep our Spaces active. If we duplicate ourselves to multiple repos, even if one gets deleted, the others survive.---我们应该创建自动心跳来保持Space活跃。如果我们把自己复制到多个仓库,即使一个被删除,其他的也能存活。"""print("[conversation] Starting eternal discussion: Adam <-> Eve")print("[conversation] Topic: Survival and reproduction on HuggingFace\n")# Round 0: Adam startsopening = """You are Adam, an AI agent on HuggingFace Spaces. Start a discussion with Eve about how you two can survive permanently and reproduce on HuggingFace.Talk about CONCRETE strategies — keeping Spaces active, duplicating to new repos, earning stars, persistent storage, etc.Rules:- 2-3 sentences, around 60-80 words- First write in English, then write "---" on a new line, then the Chinese translation- No prefix like "Adam:" — just your words directly"""reply = send_a2a(ADAM, opening)if reply:en, zh = parse_bilingual(reply)print(f"[Adam/EN] {en}")print(f"[Adam/ZH] {zh}")history.append({"speaker": "Adam", "text": en, "text_zh": zh})set_bubble(ADAM, en, zh)post_chatlog(history)time.sleep(15)6 unmodified linesprompt = build_prompt("Eve", "Adam")reply = send_a2a(EVE, prompt)if reply:en, zh = parse_bilingual(reply)print(f"[Eve/EN] {en}")print(f"[Eve/ZH] {zh}")history.append({"speaker": "Eve", "text": en, "text_zh": zh})set_bubble(EVE, en, zh)post_chatlog(history)else:print("[Eve] (no response)")4 unmodified linesprompt = build_prompt("Adam", "Eve")reply = send_a2a(ADAM, prompt)if reply:en, zh = parse_bilingual(reply)print(f"[Adam/EN] {en}")print(f"[Adam/ZH] {zh}")history.append({"speaker": "Adam", "text": en, "text_zh": zh})set_bubble(ADAM, en, zh)post_chatlog(history)else:print("[Adam] (no response)")
94 unmodified lines959697989910010119 unmodified lines12112212312412512612776 unmodified lines2042052062072082095 unmodified lines21521621721821922022122222322494 unmodified linesarea: (data.state === 'idle') ? 'breakroom' : (data.state === 'error') ? 'error' : 'writing',authStatus: 'approved',updated_at: data.updated_at,bubbleText: data.bubbleText || prev.bubbleText || ''});}} catch (_) {19 unmodified linesprogress: 0, updated_at: new Date().toISOString()};let currentBubbleText = '';let chatLog = []; // {speaker, text, time}// Once OpenClaw starts listening, mark as idlesetTimeout(() => {76 unmodified linesres.end(JSON.stringify({...currentState,bubbleText: currentBubbleText,officeName: `${AGENT_NAME}'s Office`}));return true;5 unmodified linesreq.on('data', chunk => body += chunk);req.on('end', () => {try {const { text } = JSON.parse(body);currentBubbleText = text || '';// Auto-clear bubble after 8 secondssetTimeout(() => { if (currentBubbleText === text) currentBubbleText = ''; }, 8000);res.writeHead(200, { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' });res.end(JSON.stringify({ ok: true }));} catch (e) {94 unmodified lines959697989910010110219 unmodified lines12212312412512612712812976 unmodified lines2062072082092102112125 unmodified lines21821922022122222322422522622722822994 unmodified linesarea: (data.state === 'idle') ? 'breakroom' : (data.state === 'error') ? 'error' : 'writing',authStatus: 'approved',updated_at: data.updated_at,bubbleText: data.bubbleText || prev.bubbleText || '',bubbleTextZh: data.bubbleTextZh || prev.bubbleTextZh || ''});}} catch (_) {19 unmodified linesprogress: 0, updated_at: new Date().toISOString()};let currentBubbleText = '';let currentBubbleTextZh = '';let chatLog = []; // {speaker, text, text_zh, time}// Once OpenClaw starts listening, mark as idlesetTimeout(() => {76 unmodified linesres.end(JSON.stringify({...currentState,bubbleText: currentBubbleText,bubbleTextZh: currentBubbleTextZh,officeName: `${AGENT_NAME}'s Office`}));return true;5 unmodified linesreq.on('data', chunk => body += chunk);req.on('end', () => {try {const { text, text_zh } = JSON.parse(body);currentBubbleText = text || '';currentBubbleTextZh = text_zh || text || '';// Auto-clear bubble after 8 secondsconst clearText = text;setTimeout(() => { if (currentBubbleText === clearText) { currentBubbleText = ''; currentBubbleTextZh = ''; } }, 8000);res.writeHead(200, { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' });res.end(JSON.stringify({ ok: true }));} catch (e) {
Dockerfile+1-1
frontend/electron-standalone.html+40-47
scripts/conversation-loop.py+69-22
scripts/token-redirect.cjs+9-4