Add MindSpace visual page editor and Plaza local Tunnel deployment.

In-preview HTML editing with undo/redo sync replaces Agent patch auto-save; Plaza runs on local Mac via Cloudflare Tunnel with embed height and CSP fixes.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
John
2026-06-15 22:57:22 -07:00
parent 6ee6fd64dd
commit 25d9c8c364
24 changed files with 1173 additions and 351 deletions
+47
View File
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
# 将 plaza.tkmind.cn 经 Cloudflare Tunnel 指到本机 Plaza:3001
#
# 前置:
# 1. cloudflared 已安装且 ollama-tkmind 隧道在跑
# 2. pnpm dev:plaza 或 next start 监听 :3001
#
# 用法:pnpm setup:plaza-tunnel
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
CF_CONFIG="${CLOUDFLARE_TUNNEL_CONFIG:-/Users/john/Project/ollama/cloudflare/config.yml}"
TUNNEL_NAME="${CLOUDFLARE_TUNNEL_NAME:-ollama-tkmind}"
PLAZA_HOST="${PLAZA_LOCAL_HOST:-plaza.tkmind.cn}"
PLAZA_PORT="${PLAZA_TUNNEL_PORT:-${PLAZA_PORT:-3001}}"
GUI="gui/$(id -u)"
chmod +x "${ROOT}/scripts/patch-plaza-tunnel-config.mjs"
echo "==> 更新 cloudflared ingress${PLAZA_HOST} → 127.0.0.1:${PLAZA_PORT}"
CLOUDFLARE_TUNNEL_CONFIG="${CF_CONFIG}" PLAZA_TUNNEL_PORT="${PLAZA_PORT}" \
node "${ROOT}/scripts/patch-plaza-tunnel-config.mjs"
echo "==> 注册 DNS 路由(${PLAZA_HOST} → 隧道 ${TUNNEL_NAME}"
if cloudflared tunnel route dns list 2>/dev/null | grep -q "${PLAZA_HOST}"; then
echo "DNS 路由已存在,跳过"
else
cloudflared tunnel route dns "${TUNNEL_NAME}" "${PLAZA_HOST}" || {
echo "⚠ DNS 路由失败(可能已在 Cloudflare 控制台手动配置)。继续重启 cloudflared…" >&2
}
fi
echo "==> 重启 cloudflared"
launchctl kickstart -k "${GUI}/com.cloudflare.cloudflared" 2>/dev/null || {
echo "⚠ 未找到 LaunchAgent com.cloudflare.cloudflared,请手动:cloudflared tunnel --config ${CF_CONFIG} run" >&2
}
sleep 2
echo ""
echo "=== Plaza 隧道状态 ==="
curl -s -o /dev/null -w "本机 Plaza :${PLAZA_PORT}/plaza → %{http_code}\n" \
"http://127.0.0.1:${PLAZA_PORT}/plaza" 2>/dev/null || echo "本机 Plaza 未运行(请先 pnpm dev:plaza"
curl -s -o /dev/null -w "外网 ${PLAZA_HOST}/plaza → %{http_code}\n" \
"https://${PLAZA_HOST}/plaza" 2>/dev/null || true
echo ""
echo "日志: ~/Library/Logs/com.cloudflare.cloudflared.log(或 launchctl 配置的路径)"
echo "配置: ${CF_CONFIG}"
+60
View File
@@ -0,0 +1,60 @@
#!/usr/bin/env node
/**
* Add plaza.tkmind.cn ingress to cloudflared config (before catch-all 404).
*
* Usage:
* node scripts/patch-plaza-tunnel-config.mjs
* CLOUDFLARE_TUNNEL_CONFIG=/path/to/config.yml PLAZA_TUNNEL_PORT=3001 node ...
*/
import fs from 'node:fs';
const configPath =
process.env.CLOUDFLARE_TUNNEL_CONFIG ??
'/Users/john/Project/ollama/cloudflare/config.yml';
const plazaPort = Number(process.env.PLAZA_TUNNEL_PORT ?? process.env.PLAZA_PORT ?? 3001);
const plazaHost = process.env.PLAZA_LOCAL_HOST ?? 'plaza.tkmind.cn';
if (!fs.existsSync(configPath)) {
console.error(`错误: 未找到 cloudflared 配置:${configPath}`);
console.error('请设置 CLOUDFLARE_TUNNEL_CONFIG');
process.exit(1);
}
let content = fs.readFileSync(configPath, 'utf8');
if (content.includes(`hostname: ${plazaHost}`)) {
const current = content.match(
new RegExp(`hostname: ${plazaHost.replace('.', '\\.')}[\\s\\S]*?service: (http://[^\\n]+)`),
);
const target = `http://127.0.0.1:${plazaPort}`;
if (current?.[1] === target) {
console.log(`cloudflared 已配置 ${plazaHost}${target}`);
process.exit(0);
}
content = content.replace(
new RegExp(
`(hostname: ${plazaHost.replace('.', '\\.')}[\\s\\S]*?service: )http://127\\.0\\.0\\.1:\\d+`,
),
`$1${target}`,
);
fs.writeFileSync(configPath, content);
console.log(`已更新 ${plazaHost}${target}`);
process.exit(0);
}
const block = ` - hostname: ${plazaHost}
service: http://127.0.0.1:${plazaPort}
originRequest:
connectTimeout: 30s
keepAliveTimeout: 90s
disableChunkedEncoding: false
`;
if (!content.includes('- service: http_status:404')) {
console.error('错误: 配置中未找到 catch-all http_status:404 规则');
process.exit(1);
}
content = content.replace(/\n - service: http_status:404/, `\n${block}\n - service: http_status:404`);
fs.writeFileSync(configPath, content);
console.log(`已添加 ${plazaHost} → http://127.0.0.1:${plazaPort}`);
+1 -1
View File
@@ -183,7 +183,7 @@ export function buildJohnPage(opts) {
text-decoration: none;
box-shadow: 0 8px 28px ${accent}44;
}
.section { max-width: 1100px; margin: 0 auto; padding: 72px 24px; content-visibility: auto; contain-intrinsic-size: auto 360px; }
.section { max-width: 1100px; margin: 0 auto; padding: 72px 24px; }
.section h2 { font-size: 26px; font-weight: 700; margin-bottom: 8px; }
.section .hint { color: rgba(255,255,255,0.38); font-size: 15px; margin-bottom: 36px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; }
+169
View File
@@ -0,0 +1,169 @@
#!/usr/bin/env node
/**
* Plaza 本机正式模式:Portal API + Next.js build/start(供 Cloudflare Tunnel 回源)。
*
* Usage:
* pnpm start:plaza
* pnpm start:plaza -- --skip-build # 跳过 next build(已有 .next 产物时)
*/
import { spawn, execSync } from 'node:child_process';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const root = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
const plazaDir = process.env.PLAZA_APP_DIR ?? path.join(root, '../tkmind_go/ui/plaza');
const portalPort = Number(process.env.H5_PORT ?? 8081);
const plazaPort = Number(process.env.PLAZA_PORT ?? 3001);
const plazaHost = process.env.PLAZA_LOCAL_HOST ?? 'plaza.tkmind.cn';
const plazaPublicBase = (
process.env.PLAZA_PUBLIC_BASE ?? 'https://plaza.tkmind.cn'
).replace(/\/$/, '');
const portalUrl = `http://127.0.0.1:${portalPort}`;
const skipBuild = process.argv.includes('--skip-build');
function loadEnvFile(filePath) {
if (!fs.existsSync(filePath)) return;
for (const line of fs.readFileSync(filePath, 'utf8').split('\n')) {
const trimmed = line.trim();
if (!trimmed || trimmed.startsWith('#')) continue;
const eq = trimmed.indexOf('=');
if (eq < 0) continue;
const key = trimmed.slice(0, eq).trim();
const value = trimmed.slice(eq + 1).trim();
if (!process.env[key]) process.env[key] = value;
}
}
loadEnvFile(path.join(root, '../../.env.local'));
loadEnvFile(path.join(root, '.env'));
function freePort(port) {
try {
execSync(`lsof -ti TCP:${port} -sTCP:LISTEN | xargs kill -9`, { stdio: 'ignore' });
} catch {
// already free
}
}
async function portOpen(port) {
try {
const res = await fetch(`http://127.0.0.1:${port}/auth/status`);
return res.ok;
} catch {
return false;
}
}
async function waitFor(check, label, retries = 120) {
for (let i = 0; i < retries; i += 1) {
try {
if (await check()) return;
} catch {
// still starting
}
await new Promise((resolve) => setTimeout(resolve, 500));
}
throw new Error(`${label} 启动超时`);
}
let portal;
let plaza;
let stopping = false;
function spawnChild(command, args, label, cwd = root, extraEnv = {}) {
const child = spawn(command, args, {
cwd,
env: { ...process.env, NODE_ENV: 'production', ...extraEnv },
stdio: 'inherit',
});
child.on('exit', (code, signal) => {
if (signal || stopping) return;
if (code && code !== 0) {
console.error(`[${label}] exited with code ${code}`);
shutdown(code ?? 1);
}
});
return child;
}
function shutdown(code = 0) {
if (stopping) return;
stopping = true;
portal?.kill('SIGTERM');
plaza?.kill('SIGTERM');
setTimeout(() => process.exit(code), 300);
}
process.on('SIGINT', () => shutdown(0));
process.on('SIGTERM', () => shutdown(0));
if (!fs.existsSync(path.join(plazaDir, 'package.json'))) {
console.error(`未找到 Plaza Next.js${plazaDir}`);
process.exit(1);
}
const mindSpacePublicBase = (
process.env.H5_PUBLIC_BASE_URL ??
process.env.VITE_MINDSPACE_BASE ??
'https://g2.tkmind.cn'
).replace(/\/$/, '');
const plazaEnv = {
PLAZA_API_PROXY: portalUrl,
PLAZA_API_BASE: portalUrl,
PLAZA_PUBLIC_BASE: plazaPublicBase,
NEXT_PUBLIC_API_BASE: plazaPublicBase,
NEXT_PUBLIC_SITE_BASE: plazaPublicBase,
NEXT_PUBLIC_MINDSPACE_BASE: mindSpacePublicBase,
NEXT_PUBLIC_PLAZA_BASE: '/plaza',
};
console.log('==> Plaza 本机正式模式(next build + start');
console.log(` 公开地址 ${plazaPublicBase}/plaza`);
console.log(` 内部端口 ${plazaPort}`);
freePort(plazaPort);
try {
if (!(await portOpen(portalPort))) {
console.log(`==> 启动 Portal @ ${portalUrl}`);
portal = spawnChild('node', ['server.mjs'], 'portal');
await waitFor(() => portOpen(portalPort), 'Portal');
} else {
console.log(`==> Portal 已在运行: ${portalUrl}`);
}
if (!skipBuild) {
console.log('==> 构建 Plaza Next.js(生产)…');
execSync('npm run build', { cwd: plazaDir, stdio: 'inherit', env: { ...process.env, ...plazaEnv } });
} else {
console.log('==> 跳过 next build--skip-build');
}
console.log(`==> 启动 Plaza Next.js 正式服务 (0.0.0.0:${plazaPort})`);
plaza = spawnChild(
'npm',
['run', 'start', '--', '-H', '0.0.0.0', '-p', String(plazaPort)],
'plaza',
plazaDir,
plazaEnv,
);
await waitFor(async () => {
const res = await fetch(`http://127.0.0.1:${plazaPort}/plaza`, {
headers: { Host: plazaHost },
});
return res.ok || res.status === 307 || res.status === 308;
}, 'Plaza Next.js');
console.log('');
console.log('Plaza 正式模式已就绪:');
console.log(` 本机 http://127.0.0.1:${plazaPort}/plaza`);
console.log(` 公网 ${plazaPublicBase}/plaza (需 Cloudflare Tunnel 回源 :${plazaPort}`);
console.log('');
console.log('隧道未配置或外网 502 时:pnpm setup:plaza-tunnel');
} catch (err) {
console.error(err instanceof Error ? err.message : err);
shutdown(1);
}