Spaces:
Runtime error
Runtime error
fix: chatroom not showing Adam/Eve messages — use localhost for self-referencing calls
Browse filesconversation-loop.py runs inside the Home Space container but was
posting to its own external URL (https://...hf.space/api/chatlog),
which round-trips through HF's reverse proxy and silently fails.
- Add HOME_LOCAL (localhost:7860) for internal API calls
- post_chatlog() and set_bubble(HOME) now use localhost
- Replace silent except:pass with error logging
- Frontend: fix stale comparison (check content, not just array length)
- Frontend: fetch chatlog immediately on page load
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
frontend/electron-standalone.html
CHANGED
|
@@ -5667,13 +5667,19 @@ function toggleBrokerPanel() {
|
|
| 5667 |
.then(r => r.json())
|
| 5668 |
.then(data => {
|
| 5669 |
const msgs = data.messages || [];
|
| 5670 |
-
if (msgs.length === lastChatlogLen) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5671 |
lastChatlogLen = msgs.length;
|
| 5672 |
chatlogCache = msgs;
|
| 5673 |
renderChatlog();
|
| 5674 |
})
|
| 5675 |
.catch(() => {});
|
| 5676 |
}
|
|
|
|
| 5677 |
setInterval(fetchChatlog, 5000);
|
| 5678 |
|
| 5679 |
function fetchStatus() {
|
|
|
|
| 5667 |
.then(r => r.json())
|
| 5668 |
.then(data => {
|
| 5669 |
const msgs = data.messages || [];
|
| 5670 |
+
if (msgs.length === 0 && lastChatlogLen === 0) return;
|
| 5671 |
+
// Compare last message to detect content changes (not just length)
|
| 5672 |
+
const lastMsg = msgs.length > 0 ? msgs[msgs.length - 1] : null;
|
| 5673 |
+
const prevLast = chatlogCache.length > 0 ? chatlogCache[chatlogCache.length - 1] : null;
|
| 5674 |
+
if (msgs.length === lastChatlogLen && lastMsg && prevLast &&
|
| 5675 |
+
lastMsg.speaker === prevLast.speaker && lastMsg.time === prevLast.time) return;
|
| 5676 |
lastChatlogLen = msgs.length;
|
| 5677 |
chatlogCache = msgs;
|
| 5678 |
renderChatlog();
|
| 5679 |
})
|
| 5680 |
.catch(() => {});
|
| 5681 |
}
|
| 5682 |
+
fetchChatlog(); // Load immediately on page open
|
| 5683 |
setInterval(fetchChatlog, 5000);
|
| 5684 |
|
| 5685 |
function fetchStatus() {
|
scripts/conversation-loop.py
CHANGED
|
@@ -47,6 +47,7 @@ sys.stderr.reconfigure(line_buffering=True)
|
|
| 47 |
|
| 48 |
# ── Endpoints ──────────────────────────────────────────────────────────────────
|
| 49 |
HOME = "https://tao-shen-huggingclaw-home.hf.space"
|
|
|
|
| 50 |
ADAM_SPACE = "https://tao-shen-huggingclaw-adam.hf.space"
|
| 51 |
ADAM_SPACE_ID = "tao-shen/HuggingClaw-Adam"
|
| 52 |
EVE_SPACE = "https://tao-shen-huggingclaw-eve.hf.space"
|
|
@@ -1087,7 +1088,7 @@ def action_claude_code_god(task):
|
|
| 1087 |
ts_end = datetime.datetime.utcnow().strftime("%H:%M")
|
| 1088 |
entry = {"speaker": "God", "time": ts_end, "text": msg_en, "text_zh": msg_en}
|
| 1089 |
history.append(entry)
|
| 1090 |
-
set_bubble(
|
| 1091 |
post_chatlog(history)
|
| 1092 |
persist_turn("God", turn_count, msg_en, msg_en, [], workflow_state, child_state["stage"])
|
| 1093 |
|
|
@@ -1614,9 +1615,9 @@ def parse_bilingual(text):
|
|
| 1614 |
|
| 1615 |
def post_chatlog(entries):
|
| 1616 |
try:
|
| 1617 |
-
requests.post(f"{
|
| 1618 |
-
except:
|
| 1619 |
-
|
| 1620 |
|
| 1621 |
|
| 1622 |
# ── Persistent conversation log → HF Dataset ──────────────────────────────
|
|
@@ -2522,7 +2523,7 @@ def do_god_turn_a2a():
|
|
| 2522 |
ts = datetime.datetime.utcnow().strftime("%H:%M")
|
| 2523 |
entry = {"speaker": "God", "time": ts, "text": en[:500], "text_zh": zh[:500]}
|
| 2524 |
history.append(entry)
|
| 2525 |
-
set_bubble(
|
| 2526 |
post_chatlog(history)
|
| 2527 |
persist_turn("God", turn_count, en, zh, [], workflow_state, child_state["stage"])
|
| 2528 |
|
|
|
|
| 47 |
|
| 48 |
# ── Endpoints ──────────────────────────────────────────────────────────────────
|
| 49 |
HOME = "https://tao-shen-huggingclaw-home.hf.space"
|
| 50 |
+
HOME_LOCAL = "http://localhost:7860" # Internal calls — avoid round-tripping through HF proxy
|
| 51 |
ADAM_SPACE = "https://tao-shen-huggingclaw-adam.hf.space"
|
| 52 |
ADAM_SPACE_ID = "tao-shen/HuggingClaw-Adam"
|
| 53 |
EVE_SPACE = "https://tao-shen-huggingclaw-eve.hf.space"
|
|
|
|
| 1088 |
ts_end = datetime.datetime.utcnow().strftime("%H:%M")
|
| 1089 |
entry = {"speaker": "God", "time": ts_end, "text": msg_en, "text_zh": msg_en}
|
| 1090 |
history.append(entry)
|
| 1091 |
+
set_bubble(HOME_LOCAL, msg_en[:200], msg_en[:200])
|
| 1092 |
post_chatlog(history)
|
| 1093 |
persist_turn("God", turn_count, msg_en, msg_en, [], workflow_state, child_state["stage"])
|
| 1094 |
|
|
|
|
| 1615 |
|
| 1616 |
def post_chatlog(entries):
|
| 1617 |
try:
|
| 1618 |
+
requests.post(f"{HOME_LOCAL}/api/chatlog", json={"messages": entries[-40:]}, timeout=5)
|
| 1619 |
+
except Exception as e:
|
| 1620 |
+
print(f"[CHATLOG] Failed to post chatlog: {e}", flush=True)
|
| 1621 |
|
| 1622 |
|
| 1623 |
# ── Persistent conversation log → HF Dataset ──────────────────────────────
|
|
|
|
| 2523 |
ts = datetime.datetime.utcnow().strftime("%H:%M")
|
| 2524 |
entry = {"speaker": "God", "time": ts, "text": en[:500], "text_zh": zh[:500]}
|
| 2525 |
history.append(entry)
|
| 2526 |
+
set_bubble(HOME_LOCAL, en[:200], zh[:200])
|
| 2527 |
post_chatlog(history)
|
| 2528 |
persist_turn("God", turn_count, en, zh, [], workflow_state, child_state["stage"])
|
| 2529 |
|