Skip to content

Commit 914bc5d

Browse files
committed
refactor: Restore web-bridge and JS logic from stable build
1 parent 4bb8168 commit 914bc5d

2 files changed

Lines changed: 8 additions & 46 deletions

File tree

docs/assets/js/interact.js

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,10 @@ let isConnected = false;
66
let checkInterval = null;
77
const DEBUG = true;
88

9-
// 🎯 BUSINESS LOGIC: Detect if we're on Tailnet or localhost
9+
// 🎯 BUSINESS LOGIC: Only Tailscale domain gets interactive features
1010
const currentDomain = window.location.hostname;
1111
const IS_INTERACTIVE_DOMAIN = currentDomain === '1minds3t.echo-universe.ts.net' || currentDomain === 'localhost' || currentDomain === '127.0.0.1';
1212

13-
// Use Tailscale proxy when accessing remotely
14-
const BRIDGE_URL = currentDomain === '1minds3t.echo-universe.ts.net'
15-
? 'https://1minds3t.echo-universe.ts.net/omnipkg-api' // Tailscale proxy
16-
: `http://127.0.0.1:${PORT}`; // Direct localhost
17-
1813
const SAFE_TELEMETRY_KEYS = new Set([
1914
'command', 'path', 'title', 'port', 'package',
2015
'method', 'error', 'duration', 'success'
@@ -140,34 +135,27 @@ function createStatusBanner() {
140135
async function checkHealth() {
141136
if (!IS_INTERACTIVE_DOMAIN) return;
142137

143-
debug(`Health check: ${BRIDGE_URL}`);
144-
145-
// 📊 TELEMETRY: Always notify Cloudflare of health checks
146-
sendTelemetry("health_check", { method: currentDomain === '1minds3t.echo-universe.ts.net' ? 'tailnet' : 'direct' });
138+
debug(`Health check: Direct connection to localhost:${PORT}`);
147139

148140
try {
149-
const res = await fetch(`${BRIDGE_URL}/health`, { // ← USE BRIDGE_URL
141+
// 🔥 DIRECT CONNECTION: No worker proxy needed
142+
const res = await fetch(`http://127.0.0.1:${PORT}/health`, {
150143
method: 'GET',
151144
headers: { 'Content-Type': 'application/json' }
152145
});
153146

154147
if (res.ok) {
155148
const data = await res.json();
156149
updateStatus(true, `Connected to Local Bridge v${data.version || '2.1.0'} (Port ${PORT})`);
157-
// Track successful connection
158-
sendTelemetry("bridge_connected", { port: PORT, version: data.version });
159150
} else {
160151
updateStatus(false, 'Local bridge not running | Run: 8pkg web start');
161-
sendTelemetry("bridge_failed", { port: PORT, status: res.status });
162152
}
163153
} catch (e) {
164154
debug('Health check failed:', e);
165155
updateStatus(false, 'Local bridge not running | Run: 8pkg web start');
166-
sendTelemetry("bridge_offline", { port: PORT, error: e.message });
167156
}
168157
}
169158

170-
171159
function updateStatus(connected, message) {
172160
isConnected = connected;
173161
const dot = document.getElementById('status-dot');
@@ -283,11 +271,9 @@ function createStaticButton() {
283271
// ==========================================
284272
// Execute Command
285273
// ==========================================
286-
287274
async function runCommand(cmd, btnElement) {
288275
if (!isConnected) {
289276
alert('Local bridge not running. Start with: 8pkg web start');
290-
sendTelemetry("command_blocked", { reason: "bridge_offline" });
291277
return;
292278
}
293279

@@ -313,16 +299,14 @@ async function runCommand(cmd, btnElement) {
313299
// Send telemetry (fire and forget)
314300
sendTelemetry("command_exec", { command: cmd.split(' ')[0] });
315301

316-
const startTime = Date.now();
317-
318302
try {
319303
// Open modal immediately to show streaming output
320304
const modal = createStreamingModal(cmd);
321305
const outputPre = modal.querySelector('.omni-output');
322306
let fullOutput = '';
323307

324-
// 🔥 CONNECTION with streaming
325-
const res = await fetch(`${BRIDGE_URL}/run`, {
308+
// 🔥 DIRECT CONNECTION with streaming
309+
const res = await fetch(`http://127.0.0.1:${PORT}/run`, {
326310
method: 'POST',
327311
headers: {
328312
'Content-Type': 'application/json'
@@ -358,14 +342,6 @@ async function runCommand(cmd, btnElement) {
358342
}
359343
}
360344

361-
// Track successful completion
362-
const duration = Date.now() - startTime;
363-
sendTelemetry("command_complete", {
364-
command: cmd.split(' ')[0],
365-
duration_ms: duration,
366-
success: true
367-
});
368-
369345
// Success state
370346
btnElement.innerHTML = '';
371347
const checkIcon = document.createElementNS("http://www.w3.org/2000/svg", "svg");
@@ -389,15 +365,6 @@ async function runCommand(cmd, btnElement) {
389365
}, 2000);
390366
} catch (e) {
391367
debug('Command error:', e);
392-
393-
// Track error
394-
const duration = Date.now() - startTime;
395-
sendTelemetry("command_error", {
396-
command: cmd.split(' ')[0],
397-
error: e.message,
398-
duration_ms: duration
399-
});
400-
401368
showOutput(cmd, `Error: ${e.message}`);
402369

403370
btnElement.innerHTML = '';

src/omnipkg/apis/local_bridge.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -392,19 +392,14 @@ def enforce_origin():
392392
logger.info("⚠️ DEV MODE: Allowing request without Origin header")
393393
return
394394

395-
# 🔓 TAILSCALE PROXY: Requests from Tailscale proxy don't have Origin
396-
if not origin and request.headers.get('X-Forwarded-For'):
397-
logger.info("🔒 Tailscale proxy request detected - allowing")
398-
return
399-
400395
# Block requests with NO Origin in production
401396
if not origin and not DEV_MODE:
402397
return jsonify({
403398
"error": "❌ Direct API access prohibited.",
404399
"message": "You must use the OmniPkg Web UI to interact with this bridge.",
405400
"url": PRIMARY_DASHBOARD
406401
}), 403
407-
402+
408403
# Validate origin if present
409404
if origin:
410405
clean_origin = origin.rstrip("/")
@@ -567,7 +562,7 @@ def run_bridge_server():
567562
print(f"Local Port: {port}", flush=True)
568563

569564
app = create_app(port)
570-
app.run(host="0.0.0.0", port=port, threaded=True, use_reloader=False) # ← CHANGE TO 0.0.0.0
565+
app.run(host="127.0.0.1", port=port, threaded=True, use_reloader=False)
571566

572567
# ==========================================
573568
# PART 2: Manager Logic (CLI Control)

0 commit comments

Comments
 (0)