mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 01:51:24 +00:00
refactor: rename to openclaw
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import * as fsSync from "node:fs";
|
||||
import fs from "node:fs/promises";
|
||||
import http, { type IncomingMessage, type Server, type ServerResponse } from "node:http";
|
||||
import type { Socket } from "node:net";
|
||||
@@ -59,7 +60,7 @@ function defaultIndexHTML() {
|
||||
return `<!doctype html>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Moltbot Canvas</title>
|
||||
<title>OpenClaw Canvas</title>
|
||||
<style>
|
||||
html, body { height: 100%; margin: 0; background: #000; color: #fff; font: 16px/1.4 -apple-system, BlinkMacSystemFont, system-ui, Segoe UI, Roboto, Helvetica, Arial, sans-serif; }
|
||||
.wrap { min-height: 100%; display: grid; place-items: center; padding: 24px; }
|
||||
@@ -77,7 +78,7 @@ function defaultIndexHTML() {
|
||||
<div class="wrap">
|
||||
<div class="card">
|
||||
<div class="title">
|
||||
<h1>Moltbot Canvas</h1>
|
||||
<h1>OpenClaw Canvas</h1>
|
||||
<div class="sub">Interactive test page (auto-reload enabled)</div>
|
||||
</div>
|
||||
|
||||
@@ -102,46 +103,35 @@ function defaultIndexHTML() {
|
||||
!!(
|
||||
window.webkit &&
|
||||
window.webkit.messageHandlers &&
|
||||
(window.webkit.messageHandlers.moltbotCanvasA2UIAction ||
|
||||
window.webkit.messageHandlers.clawdbotCanvasA2UIAction)
|
||||
window.webkit.messageHandlers.openclawCanvasA2UIAction
|
||||
);
|
||||
const hasAndroid = () =>
|
||||
!!(
|
||||
(window.moltbotCanvasA2UIAction &&
|
||||
typeof window.moltbotCanvasA2UIAction.postMessage === "function") ||
|
||||
(window.clawdbotCanvasA2UIAction &&
|
||||
typeof window.clawdbotCanvasA2UIAction.postMessage === "function")
|
||||
(window.openclawCanvasA2UIAction &&
|
||||
typeof window.openclawCanvasA2UIAction.postMessage === "function")
|
||||
);
|
||||
const legacySend = typeof window.clawdbotSendUserAction === "function" ? window.clawdbotSendUserAction : undefined;
|
||||
if (!window.moltbotSendUserAction && legacySend) {
|
||||
window.moltbotSendUserAction = legacySend;
|
||||
}
|
||||
if (!window.clawdbotSendUserAction && typeof window.moltbotSendUserAction === "function") {
|
||||
window.clawdbotSendUserAction = window.moltbotSendUserAction;
|
||||
}
|
||||
const hasHelper = () =>
|
||||
typeof window.moltbotSendUserAction === "function" ||
|
||||
typeof window.clawdbotSendUserAction === "function";
|
||||
const hasHelper = () => typeof window.openclawSendUserAction === "function";
|
||||
statusEl.innerHTML =
|
||||
"Bridge: " +
|
||||
(hasHelper() ? "<span class='ok'>ready</span>" : "<span class='bad'>missing</span>") +
|
||||
" · iOS=" + (hasIOS() ? "yes" : "no") +
|
||||
" · Android=" + (hasAndroid() ? "yes" : "no");
|
||||
|
||||
window.addEventListener("moltbot:a2ui-action-status", (ev) => {
|
||||
const onStatus = (ev) => {
|
||||
const d = ev && ev.detail || {};
|
||||
log("Action status: id=" + (d.id || "?") + " ok=" + String(!!d.ok) + (d.error ? (" error=" + d.error) : ""));
|
||||
});
|
||||
};
|
||||
window.addEventListener("openclaw:a2ui-action-status", onStatus);
|
||||
|
||||
function send(name, sourceComponentId) {
|
||||
if (!hasHelper()) {
|
||||
log("No action bridge found. Ensure you're viewing this on an iOS/Android Moltbot node canvas.");
|
||||
log("No action bridge found. Ensure you're viewing this on an iOS/Android OpenClaw node canvas.");
|
||||
return;
|
||||
}
|
||||
const sendUserAction =
|
||||
typeof window.moltbotSendUserAction === "function"
|
||||
? window.moltbotSendUserAction
|
||||
: window.clawdbotSendUserAction;
|
||||
typeof window.openclawSendUserAction === "function"
|
||||
? window.openclawSendUserAction
|
||||
: undefined;
|
||||
const ok = sendUserAction({
|
||||
name,
|
||||
surfaceId: "main",
|
||||
@@ -199,7 +189,8 @@ async function resolveFilePath(rootReal: string, urlPath: string) {
|
||||
}
|
||||
|
||||
function isDisabledByEnv() {
|
||||
if (isTruthyEnvValue(process.env.CLAWDBOT_SKIP_CANVAS_HOST)) return true;
|
||||
if (isTruthyEnvValue(process.env.OPENCLAW_SKIP_CANVAS_HOST)) return true;
|
||||
if (isTruthyEnvValue(process.env.OPENCLAW_SKIP_CANVAS_HOST)) return true;
|
||||
if (process.env.NODE_ENV === "test") return true;
|
||||
if (process.env.VITEST) return true;
|
||||
return false;
|
||||
@@ -228,6 +219,18 @@ async function prepareCanvasRoot(rootDir: string) {
|
||||
return rootReal;
|
||||
}
|
||||
|
||||
function resolveDefaultCanvasRoot(): string {
|
||||
const candidates = [path.join(os.homedir(), ".openclaw", "canvas")];
|
||||
const existing = candidates.find((dir) => {
|
||||
try {
|
||||
return fsSync.statSync(dir).isDirectory();
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return existing ?? candidates[0];
|
||||
}
|
||||
|
||||
export async function createCanvasHostHandler(
|
||||
opts: CanvasHostHandlerOpts,
|
||||
): Promise<CanvasHostHandler> {
|
||||
@@ -242,7 +245,7 @@ export async function createCanvasHostHandler(
|
||||
};
|
||||
}
|
||||
|
||||
const rootDir = resolveUserPath(opts.rootDir ?? path.join(os.homedir(), "clawd", "canvas"));
|
||||
const rootDir = resolveUserPath(opts.rootDir ?? resolveDefaultCanvasRoot());
|
||||
const rootReal = await prepareCanvasRoot(rootDir);
|
||||
|
||||
const liveReload = opts.liveReload !== false;
|
||||
@@ -322,13 +325,8 @@ export async function createCanvasHostHandler(
|
||||
|
||||
let urlPath = url.pathname;
|
||||
if (basePath !== "/") {
|
||||
if (urlPath === basePath) {
|
||||
urlPath = "/";
|
||||
} else if (urlPath.startsWith(`${basePath}/`)) {
|
||||
urlPath = urlPath.slice(basePath.length) || "/";
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (urlPath !== basePath && !urlPath.startsWith(`${basePath}/`)) return false;
|
||||
urlPath = urlPath === basePath ? "/" : urlPath.slice(basePath.length) || "/";
|
||||
}
|
||||
|
||||
if (req.method !== "GET" && req.method !== "HEAD") {
|
||||
@@ -344,7 +342,7 @@ export async function createCanvasHostHandler(
|
||||
res.statusCode = 404;
|
||||
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
||||
res.end(
|
||||
`<!doctype html><meta charset="utf-8" /><title>Moltbot Canvas</title><pre>Missing file.\nCreate ${rootDir}/index.html</pre>`,
|
||||
`<!doctype html><meta charset="utf-8" /><title>OpenClaw Canvas</title><pre>Missing file.\nCreate ${rootDir}/index.html</pre>`,
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user