arcrun — AI workflow execution engine (clean history)
Self-hosted 開源:WASM 零件 + recipe + cypher-executor,跑在你自己的 Cloudflare。 此為重建的乾淨歷史起點(移除曾誤 commit 的 GCP SA 金鑰,舊歷史保留在 richblack/arcrun 與本地 backup 分支)。含: - acr init --self-hosted installer(建 KV/R2 + codeload 拉預編譯 wasm + wrangler deploy + seed recipe) - recipe push 把關(資料外流提醒 + 打通檢查) - 19 個正當零件預編譯 wasm(claude_api/km_writer/kbdb_upsert_block 排除:違反 DECISIONS §1) - CLI / cypher-executor / registry / 完整 SDD Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useRef } from 'react';
|
||||
import Link from 'next/link';
|
||||
import SiteNav from '../components/SiteNav';
|
||||
|
||||
const API_BASE = process.env.NEXT_PUBLIC_API_BASE ?? 'https://cypher.arcrun.dev';
|
||||
|
||||
export default function ApiDocsPage() {
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const initialized = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (initialized.current || !containerRef.current) return;
|
||||
initialized.current = true;
|
||||
|
||||
// Dynamically load Swagger UI from CDN
|
||||
const link = document.createElement('link');
|
||||
link.rel = 'stylesheet';
|
||||
link.href = 'https://unpkg.com/swagger-ui-dist@5/swagger-ui.css';
|
||||
document.head.appendChild(link);
|
||||
|
||||
const script = document.createElement('script');
|
||||
script.src = 'https://unpkg.com/swagger-ui-dist@5/swagger-ui-bundle.js';
|
||||
script.onload = () => {
|
||||
const SwaggerUIBundle = (window as unknown as { SwaggerUIBundle: (opts: unknown) => void }).SwaggerUIBundle;
|
||||
if (!SwaggerUIBundle || !containerRef.current) return;
|
||||
SwaggerUIBundle({
|
||||
url: `${API_BASE}/openapi.json`,
|
||||
dom_id: '#swagger-ui',
|
||||
presets: [(window as unknown as { SwaggerUIBundle: { presets: { apis: unknown } } }).SwaggerUIBundle.presets.apis],
|
||||
layout: 'BaseLayout',
|
||||
defaultModelsExpandDepth: -1,
|
||||
docExpansion: 'list',
|
||||
filter: true,
|
||||
tryItOutEnabled: true,
|
||||
supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
|
||||
requestInterceptor: (request: { headers: Record<string, string> }) => {
|
||||
// Inject API key from localStorage if present
|
||||
const key = localStorage.getItem('arcrun_api_key');
|
||||
if (key) request.headers['X-Arcrun-API-Key'] = key;
|
||||
return request;
|
||||
},
|
||||
});
|
||||
};
|
||||
document.head.appendChild(script);
|
||||
|
||||
return () => {
|
||||
// cleanup not strictly needed for page navigation
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-[#0a0a0a] text-[#ededed]">
|
||||
<SiteNav currentPath="/api-docs" />
|
||||
|
||||
{/* Header */}
|
||||
<div className="max-w-5xl mx-auto px-6 py-8">
|
||||
<h1 className="text-2xl font-bold text-white mb-2">API Reference</h1>
|
||||
<p className="text-[#555] text-sm mb-2">
|
||||
這是 arcrun 的原始 API。Python / JS lib 是它的包裝,任何能發 HTTP request 的工具都能直接用。
|
||||
</p>
|
||||
<p className="text-[#444] text-xs mb-6">
|
||||
Endpoint: <span className="font-mono text-[#666]">{API_BASE}</span>
|
||||
</p>
|
||||
|
||||
{/* API Key hint */}
|
||||
<div className="bg-[#111] border border-[#222] rounded-lg p-4 mb-8 text-sm">
|
||||
<p className="text-[#666] mb-2">
|
||||
若要在此頁面試打 API,請先設定 API Key:
|
||||
</p>
|
||||
<ApiKeyInput />
|
||||
</div>
|
||||
|
||||
{/* Swagger UI */}
|
||||
<div className="bg-white rounded-xl overflow-hidden" ref={containerRef}>
|
||||
<div id="swagger-ui" className="min-h-96"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ApiKeyInput() {
|
||||
return (
|
||||
<div className="flex gap-2">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="ak_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
className="flex-1 bg-[#0a0a0a] border border-[#2a2a2a] rounded px-3 py-1.5 text-xs font-mono text-[#cdd6f4] focus:outline-none focus:border-indigo-700"
|
||||
onChange={(e) => {
|
||||
if (e.target.value.startsWith('ak_')) {
|
||||
localStorage.setItem('arcrun_api_key', e.target.value);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<span className="text-[#444] text-xs self-center">自動注入到 requests</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
'use client';
|
||||
|
||||
// 九宮格 App Launcher(受 Google Apps menu 啟發)
|
||||
// 規範:matrix/identity/.agents/specs/identity/design.md §2.5
|
||||
// 非白名單 user 看到 mira 等受限 app 顯示為灰色 + tooltip「即將開放」
|
||||
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { MATRIX_APPS, isAppAccessible, type AppEntry } from './apps';
|
||||
|
||||
export default function AppLauncher({ userEmail }: { userEmail: string | null }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const onClickOutside = (e: MouseEvent) => {
|
||||
if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false);
|
||||
};
|
||||
document.addEventListener('mousedown', onClickOutside);
|
||||
return () => document.removeEventListener('mousedown', onClickOutside);
|
||||
}, [open]);
|
||||
|
||||
return (
|
||||
<div className="relative" ref={ref}>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setOpen(o => !o)}
|
||||
aria-label="切換應用"
|
||||
className="flex items-center justify-center w-9 h-9 rounded-md text-[#888] hover:text-white hover:bg-[#1a1a1a] transition-colors"
|
||||
>
|
||||
{/* 九宮格 icon */}
|
||||
<svg width="18" height="18" viewBox="0 0 18 18" fill="currentColor">
|
||||
<circle cx="3" cy="3" r="1.5" /><circle cx="9" cy="3" r="1.5" /><circle cx="15" cy="3" r="1.5" />
|
||||
<circle cx="3" cy="9" r="1.5" /><circle cx="9" cy="9" r="1.5" /><circle cx="15" cy="9" r="1.5" />
|
||||
<circle cx="3" cy="15" r="1.5" /><circle cx="9" cy="15" r="1.5" /><circle cx="15" cy="15" r="1.5" />
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
{open && (
|
||||
<div
|
||||
className="absolute right-0 mt-2 w-72 bg-[#0f0f0f] border border-[#222] rounded-lg shadow-xl p-2 z-50"
|
||||
role="menu"
|
||||
>
|
||||
<div className="grid grid-cols-3 gap-1">
|
||||
{MATRIX_APPS.map(app => (
|
||||
<AppTile key={app.id} app={app} userEmail={userEmail} onClose={() => setOpen(false)} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function AppTile({
|
||||
app,
|
||||
userEmail,
|
||||
onClose,
|
||||
}: {
|
||||
app: AppEntry;
|
||||
userEmail: string | null;
|
||||
onClose: () => void;
|
||||
}) {
|
||||
const accessible = isAppAccessible(app, userEmail);
|
||||
const tooltip = !accessible ? (app.locked_tooltip ?? '即將開放') : (app.description ?? '');
|
||||
|
||||
if (!accessible) {
|
||||
return (
|
||||
<div
|
||||
title={tooltip}
|
||||
className="flex flex-col items-center justify-center gap-1 p-3 rounded-md cursor-not-allowed opacity-40"
|
||||
>
|
||||
<span className="text-2xl grayscale">{app.icon ?? '📦'}</span>
|
||||
<span className="text-xs text-[#666] text-center">{app.name}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<a
|
||||
href={app.url}
|
||||
onClick={onClose}
|
||||
title={tooltip}
|
||||
className="flex flex-col items-center justify-center gap-1 p-3 rounded-md hover:bg-[#1a1a1a] transition-colors text-[#ccc] hover:text-white"
|
||||
>
|
||||
<span className="text-2xl">{app.icon ?? '📦'}</span>
|
||||
<span className="text-xs text-center">{app.name}</span>
|
||||
</a>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
import Link from 'next/link';
|
||||
import AppLauncher from './AppLauncher';
|
||||
|
||||
const API_BASE = process.env.NEXT_PUBLIC_API_BASE ?? 'https://cypher.arcrun.dev';
|
||||
|
||||
type NavUser = {
|
||||
display_name: string;
|
||||
email: string;
|
||||
avatar_url?: string;
|
||||
};
|
||||
|
||||
export default function SiteNav({ currentPath }: { currentPath?: string }) {
|
||||
const [user, setUser] = useState<NavUser | null | undefined>(undefined);
|
||||
|
||||
useEffect(() => {
|
||||
fetch(`${API_BASE}/me`, { credentials: 'include' })
|
||||
.then(r => r.ok ? r.json() as Promise<NavUser> : null)
|
||||
.then(u => setUser(u))
|
||||
.catch(() => setUser(null));
|
||||
}, []);
|
||||
|
||||
const logout = async () => {
|
||||
await fetch(`${API_BASE}/auth/logout`, { method: 'POST', credentials: 'include' });
|
||||
window.location.href = '/';
|
||||
};
|
||||
|
||||
const linkCls = (path: string) =>
|
||||
`transition-colors text-sm ${currentPath === path ? 'text-white' : 'text-[#666] hover:text-white'}`;
|
||||
|
||||
return (
|
||||
<nav className="flex items-center justify-between px-6 py-4 border-b border-[#1a1a1a]">
|
||||
<Link href="/" className="text-white font-bold text-lg tracking-tight hover:opacity-80 transition-opacity">
|
||||
arcrun
|
||||
</Link>
|
||||
|
||||
<div className="flex items-center gap-4 text-sm">
|
||||
<Link href="/integrations" className={linkCls('/integrations')}>Integrations</Link>
|
||||
<Link href="/api-docs" className={linkCls('/api-docs')}>API</Link>
|
||||
<a
|
||||
href="https://github.com/richblack/arcrun"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="text-[#666] hover:text-white transition-colors"
|
||||
>
|
||||
GitHub
|
||||
</a>
|
||||
|
||||
{user === undefined ? (
|
||||
// Loading — placeholder to prevent layout shift
|
||||
<div className="w-20 h-7" />
|
||||
) : user ? (
|
||||
<>
|
||||
<AppLauncher userEmail={user.email} />
|
||||
<Link href="/dashboard" className="flex items-center gap-2 hover:opacity-80 transition-opacity">
|
||||
{user.avatar_url && (
|
||||
// eslint-disable-next-line @next/next/no-img-element
|
||||
<img src={user.avatar_url} alt="" width={26} height={26} className="rounded-full" />
|
||||
)}
|
||||
<span className="text-[#aaa]">{user.display_name}</span>
|
||||
</Link>
|
||||
<button
|
||||
onClick={logout}
|
||||
className="text-[#555] hover:text-[#888] transition-colors cursor-pointer"
|
||||
>
|
||||
登出
|
||||
</button>
|
||||
</>
|
||||
) : (
|
||||
<Link
|
||||
href="/login"
|
||||
className="bg-indigo-600 hover:bg-indigo-500 text-white px-4 py-1.5 rounded-md font-medium transition-colors"
|
||||
>
|
||||
Get API Key
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
// Matrix App Launcher 九宮格清單
|
||||
// 來源:matrix/identity/.agents/specs/identity/apps.json(v0 過渡複製,未來 v1 抽進 @matrix/identity-ui)
|
||||
// 規範:matrix/identity/.agents/specs/identity/design.md §2.5
|
||||
|
||||
export type AppEntry = {
|
||||
id: string;
|
||||
name: string;
|
||||
url: string;
|
||||
icon?: string;
|
||||
description?: string;
|
||||
access?: 'public' | 'allowlist';
|
||||
allowlist_emails?: string[];
|
||||
locked_tooltip?: string;
|
||||
};
|
||||
|
||||
export const MATRIX_APPS: AppEntry[] = [
|
||||
{
|
||||
id: 'arcrun',
|
||||
name: 'Arcrun',
|
||||
url: 'https://arcrun.dev',
|
||||
icon: '🔄',
|
||||
description: '工作流引擎與零件平台',
|
||||
},
|
||||
{
|
||||
id: 'dashboard',
|
||||
name: 'Dashboard',
|
||||
url: 'https://arcrun.dev/dashboard',
|
||||
icon: '🔑',
|
||||
description: 'API Key 管理',
|
||||
},
|
||||
{
|
||||
id: 'integrations',
|
||||
name: 'Integrations',
|
||||
url: 'https://arcrun.dev/integrations',
|
||||
icon: '🧩',
|
||||
description: '服務目錄',
|
||||
},
|
||||
{
|
||||
id: 'mira',
|
||||
name: 'Mira',
|
||||
url: 'https://arcrun.dev/mira',
|
||||
icon: '🌊',
|
||||
description: '個人化 KM 河道',
|
||||
access: 'allowlist',
|
||||
allowlist_emails: ['leo21c@gmail.com'],
|
||||
locked_tooltip: '即將開放',
|
||||
},
|
||||
];
|
||||
|
||||
export function isAppAccessible(app: AppEntry, userEmail: string | null): boolean {
|
||||
if (app.access !== 'allowlist') return true;
|
||||
if (!userEmail) return false;
|
||||
return (app.allowlist_emails ?? []).includes(userEmail);
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useState, useCallback } from 'react';
|
||||
import Link from 'next/link';
|
||||
import SiteNav from '../components/SiteNav';
|
||||
|
||||
const API_BASE = process.env.NEXT_PUBLIC_API_BASE ?? 'https://cypher.arcrun.dev';
|
||||
|
||||
type User = {
|
||||
email: string;
|
||||
display_name: string;
|
||||
avatar_url?: string;
|
||||
api_key: string;
|
||||
provider: string;
|
||||
created_at: string;
|
||||
};
|
||||
|
||||
export default function DashboardPage() {
|
||||
const [user, setUser] = useState<User | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [copied, setCopied] = useState(false);
|
||||
const [rotating, setRotating] = useState(false);
|
||||
const [revoking, setRevoking] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const [showKey, setShowKey] = useState(false);
|
||||
|
||||
const fetchUser = useCallback(async () => {
|
||||
try {
|
||||
const res = await fetch(`${API_BASE}/me`, { credentials: 'include' });
|
||||
if (res.status === 401) {
|
||||
window.location.href = '/login?redirect=/dashboard';
|
||||
return;
|
||||
}
|
||||
if (!res.ok) throw new Error('Failed to fetch user');
|
||||
const data = await res.json() as User;
|
||||
setUser(data);
|
||||
} catch {
|
||||
setError('無法載入用戶資訊,請重新整理。');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
fetchUser();
|
||||
}, [fetchUser]);
|
||||
|
||||
const copyKey = async () => {
|
||||
if (!user) return;
|
||||
await navigator.clipboard.writeText(user.api_key);
|
||||
setCopied(true);
|
||||
setTimeout(() => setCopied(false), 2000);
|
||||
};
|
||||
|
||||
const rotateKey = async () => {
|
||||
if (!confirm('確定要 Rotate API Key 嗎?舊 Key 的 workflow credentials 不會自動遷移。')) return;
|
||||
setRotating(true);
|
||||
setError('');
|
||||
try {
|
||||
const res = await fetch(`${API_BASE}/me/api-key/rotate`, {
|
||||
method: 'PUT',
|
||||
credentials: 'include',
|
||||
});
|
||||
if (!res.ok) throw new Error('rotate failed');
|
||||
const data = await res.json() as { api_key: string; message: string };
|
||||
setUser(prev => prev ? { ...prev, api_key: data.api_key } : null);
|
||||
setShowKey(true);
|
||||
} catch {
|
||||
setError('Rotate 失敗,請稍後重試。');
|
||||
} finally {
|
||||
setRotating(false);
|
||||
}
|
||||
};
|
||||
|
||||
const revokeKey = async () => {
|
||||
if (!confirm('確定要 Revoke API Key 嗎?所有使用此 Key 的服務將立即失效。')) return;
|
||||
setRevoking(true);
|
||||
setError('');
|
||||
try {
|
||||
const res = await fetch(`${API_BASE}/me/api-key`, {
|
||||
method: 'DELETE',
|
||||
credentials: 'include',
|
||||
});
|
||||
if (!res.ok) throw new Error('revoke failed');
|
||||
window.location.href = '/login?revoked=1';
|
||||
} catch {
|
||||
setError('Revoke 失敗,請稍後重試。');
|
||||
} finally {
|
||||
setRevoking(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="min-h-screen bg-[#0a0a0a] flex items-center justify-center">
|
||||
<div className="text-[#444] text-sm animate-pulse">載入中...</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!user) {
|
||||
return (
|
||||
<div className="min-h-screen bg-[#0a0a0a] flex flex-col items-center justify-center gap-4">
|
||||
<p className="text-[#666]">{error || '請先登入。'}</p>
|
||||
<Link href="/login" className="text-indigo-400 hover:text-indigo-300 text-sm">前往登入</Link>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const maskedKey = showKey ? user.api_key : user.api_key.slice(0, 8) + '••••••••••••••••••••••••';
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-[#0a0a0a] text-[#ededed]">
|
||||
<SiteNav currentPath="/dashboard" />
|
||||
|
||||
<main className="max-w-2xl mx-auto px-6 py-12">
|
||||
<h1 className="text-2xl font-bold text-white mb-1">歡迎,{user.display_name}</h1>
|
||||
<p className="text-[#555] text-sm mb-10">
|
||||
登入方式:{user.provider} · 帳號建立於 {new Date(user.created_at).toLocaleDateString('zh-TW')}
|
||||
</p>
|
||||
|
||||
{error && (
|
||||
<div className="bg-red-950/50 border border-red-900/50 text-red-400 text-sm px-4 py-3 rounded-lg mb-6">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* API Key Card */}
|
||||
<div className="bg-[#111] border border-[#222] rounded-2xl p-6 mb-6">
|
||||
<h2 className="text-white font-semibold mb-4">您的 API Key</h2>
|
||||
|
||||
<div className="flex items-center gap-2 mb-4">
|
||||
<div className="flex-1 bg-[#0a0a0a] border border-[#2a2a2a] rounded-lg px-4 py-3 font-mono text-sm text-[#cdd6f4] overflow-hidden text-ellipsis whitespace-nowrap">
|
||||
{maskedKey}
|
||||
</div>
|
||||
<button
|
||||
onClick={() => setShowKey(v => !v)}
|
||||
className="px-3 py-3 text-[#555] hover:text-[#aaa] text-xs border border-[#2a2a2a] rounded-lg transition-colors cursor-pointer whitespace-nowrap"
|
||||
title={showKey ? '隱藏' : '顯示'}
|
||||
>
|
||||
{showKey ? '隱藏' : '顯示'}
|
||||
</button>
|
||||
<button
|
||||
onClick={copyKey}
|
||||
className="px-4 py-3 bg-[#1e1e2e] hover:bg-[#2a2a3e] text-indigo-400 text-xs border border-indigo-900/30 rounded-lg transition-colors cursor-pointer whitespace-nowrap"
|
||||
>
|
||||
{copied ? '已複製!' : '複製'}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="bg-[#0a0a0a] border border-[#1a1a1a] rounded-lg p-4 mb-6 text-xs font-mono text-[#666] space-y-1">
|
||||
<div className="text-[#444] mb-2"># 使用方式</div>
|
||||
<div>Authorization: Bearer {user.api_key.slice(0, 8)}...</div>
|
||||
<div># 或</div>
|
||||
<div>X-Arcrun-API-Key: {user.api_key.slice(0, 8)}...</div>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-3 flex-wrap">
|
||||
<button
|
||||
onClick={rotateKey}
|
||||
disabled={rotating}
|
||||
className="flex-1 border border-[#333] hover:border-[#555] text-[#aaa] hover:text-white px-4 py-2.5 rounded-lg text-sm font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed cursor-pointer"
|
||||
>
|
||||
{rotating ? 'Rotating...' : 'Rotate Key'}
|
||||
</button>
|
||||
<button
|
||||
onClick={revokeKey}
|
||||
disabled={revoking}
|
||||
className="flex-1 border border-red-900/50 hover:border-red-700/50 text-red-500 hover:text-red-400 px-4 py-2.5 rounded-lg text-sm font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed cursor-pointer"
|
||||
>
|
||||
{revoking ? 'Revoking...' : 'Revoke Key'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Quick Start */}
|
||||
<div className="bg-[#111] border border-[#222] rounded-2xl p-6">
|
||||
<h2 className="text-white font-semibold mb-4">快速開始</h2>
|
||||
<div className="space-y-3 text-sm">
|
||||
<div className="flex items-start gap-3">
|
||||
<span className="text-indigo-500 font-mono mt-0.5">1.</span>
|
||||
<div>
|
||||
<div className="text-[#aaa]">安裝 CLI</div>
|
||||
<pre className="bg-[#0a0a0a] border border-[#1a1a1a] rounded-lg px-3 py-2 mt-1 text-xs text-[#cdd6f4] font-mono">npm install -g arcrun</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-start gap-3">
|
||||
<span className="text-indigo-500 font-mono mt-0.5">2.</span>
|
||||
<div>
|
||||
<div className="text-[#aaa]">初始化(已有 API Key 可直接輸入)</div>
|
||||
<pre className="bg-[#0a0a0a] border border-[#1a1a1a] rounded-lg px-3 py-2 mt-1 text-xs text-[#cdd6f4] font-mono">acr init</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-start gap-3">
|
||||
<span className="text-indigo-500 font-mono mt-0.5">3.</span>
|
||||
<div>
|
||||
<div className="text-[#aaa]">設定服務認證</div>
|
||||
<pre className="bg-[#0a0a0a] border border-[#1a1a1a] rounded-lg px-3 py-2 mt-1 text-xs text-[#cdd6f4] font-mono">acr auth-recipe scaffold notion</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-4 mt-6 text-sm">
|
||||
<Link href="/integrations" className="text-indigo-400 hover:text-indigo-300 transition-colors">
|
||||
查看 20 個支援服務 →
|
||||
</Link>
|
||||
<Link href="/api-docs" className="text-indigo-400 hover:text-indigo-300 transition-colors">
|
||||
API 文件 →
|
||||
</Link>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
@@ -0,0 +1,22 @@
|
||||
@import "tailwindcss";
|
||||
|
||||
:root {
|
||||
--background: #0a0a0a;
|
||||
--foreground: #ededed;
|
||||
}
|
||||
|
||||
@theme inline {
|
||||
--color-background: var(--background);
|
||||
--color-foreground: var(--foreground);
|
||||
}
|
||||
|
||||
body {
|
||||
background: var(--background);
|
||||
color: var(--foreground);
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
pre, code {
|
||||
font-family: 'JetBrains Mono', 'Fira Code', Consolas, monospace;
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
export const runtime = 'edge';
|
||||
|
||||
import Link from 'next/link';
|
||||
import SiteNav from '../components/SiteNav';
|
||||
|
||||
type Recipe = {
|
||||
id: string;
|
||||
name: string;
|
||||
primitive: 'static_key' | 'service_account';
|
||||
category: string;
|
||||
secrets: string[];
|
||||
badge?: 'official';
|
||||
};
|
||||
|
||||
const RECIPES: Recipe[] = [
|
||||
// AI / LLM
|
||||
{ id: 'openai', name: 'OpenAI', primitive: 'static_key', category: 'AI', secrets: ['OPENAI_API_KEY'], badge: 'official' },
|
||||
{ id: 'anthropic', name: 'Anthropic', primitive: 'static_key', category: 'AI', secrets: ['ANTHROPIC_API_KEY'], badge: 'official' },
|
||||
// Productivity
|
||||
{ id: 'notion', name: 'Notion', primitive: 'static_key', category: 'Productivity', secrets: ['NOTION_TOKEN'], badge: 'official' },
|
||||
{ id: 'airtable', name: 'Airtable', primitive: 'static_key', category: 'Productivity', secrets: ['AIRTABLE_TOKEN'], badge: 'official' },
|
||||
{ id: 'typeform', name: 'Typeform', primitive: 'static_key', category: 'Productivity', secrets: ['TYPEFORM_TOKEN'], badge: 'official' },
|
||||
{ id: 'jira', name: 'Jira', primitive: 'static_key', category: 'Productivity', secrets: ['JIRA_DOMAIN', 'JIRA_EMAIL', 'JIRA_API_TOKEN'], badge: 'official' },
|
||||
// Communication
|
||||
{ id: 'slack', name: 'Slack', primitive: 'static_key', category: 'Communication', secrets: ['SLACK_TOKEN'], badge: 'official' },
|
||||
{ id: 'discord', name: 'Discord', primitive: 'static_key', category: 'Communication', secrets: ['DISCORD_BOT_TOKEN'], badge: 'official' },
|
||||
{ id: 'twilio', name: 'Twilio', primitive: 'static_key', category: 'Communication', secrets: ['TWILIO_ACCOUNT_SID', 'TWILIO_AUTH_TOKEN'], badge: 'official' },
|
||||
{ id: 'sendgrid', name: 'SendGrid', primitive: 'static_key', category: 'Communication', secrets: ['SENDGRID_API_KEY'], badge: 'official' },
|
||||
{ id: 'resend', name: 'Resend', primitive: 'static_key', category: 'Communication', secrets: ['RESEND_API_KEY'], badge: 'official' },
|
||||
// Dev / Code
|
||||
{ id: 'github', name: 'GitHub', primitive: 'static_key', category: 'Dev', secrets: ['GITHUB_TOKEN'], badge: 'official' },
|
||||
{ id: 'linear', name: 'Linear', primitive: 'static_key', category: 'Dev', secrets: ['LINEAR_API_KEY'], badge: 'official' },
|
||||
{ id: 'supabase', name: 'Supabase', primitive: 'static_key', category: 'Dev', secrets: ['SUPABASE_URL', 'SUPABASE_SERVICE_ROLE_KEY'], badge: 'official' },
|
||||
// Commerce
|
||||
{ id: 'stripe', name: 'Stripe', primitive: 'static_key', category: 'Commerce', secrets: ['STRIPE_SECRET_KEY'], badge: 'official' },
|
||||
{ id: 'shopify', name: 'Shopify', primitive: 'static_key', category: 'Commerce', secrets: ['SHOPIFY_STORE_DOMAIN', 'SHOPIFY_ACCESS_TOKEN'], badge: 'official' },
|
||||
{ id: 'hubspot', name: 'HubSpot', primitive: 'static_key', category: 'Commerce', secrets: ['HUBSPOT_ACCESS_TOKEN'], badge: 'official' },
|
||||
// Google Service Account
|
||||
{ id: 'google_drive_sa', name: 'Google Drive', primitive: 'service_account', category: 'Google', secrets: ['GOOGLE_SERVICE_ACCOUNT_JSON'], badge: 'official' },
|
||||
{ id: 'google_gmail_sa', name: 'Gmail', primitive: 'service_account', category: 'Google', secrets: ['GOOGLE_SERVICE_ACCOUNT_JSON'], badge: 'official' },
|
||||
{ id: 'google_sheets_sa', name: 'Google Sheets', primitive: 'service_account', category: 'Google', secrets: ['GOOGLE_SERVICE_ACCOUNT_JSON'], badge: 'official' },
|
||||
];
|
||||
|
||||
const CATEGORIES = ['All', 'AI', 'Productivity', 'Communication', 'Dev', 'Commerce', 'Google'];
|
||||
|
||||
export default function IntegrationsPage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<{ cat?: string }>;
|
||||
}) {
|
||||
return <IntegrationsContent searchParamsPromise={searchParams} />;
|
||||
}
|
||||
|
||||
async function IntegrationsContent({
|
||||
searchParamsPromise,
|
||||
}: {
|
||||
searchParamsPromise: Promise<{ cat?: string }>;
|
||||
}) {
|
||||
const params = await searchParamsPromise;
|
||||
const cat = params.cat ?? 'All';
|
||||
const filtered = cat === 'All' ? RECIPES : RECIPES.filter(r => r.category === cat);
|
||||
|
||||
const staticCount = RECIPES.filter(r => r.primitive === 'static_key').length;
|
||||
const saCount = RECIPES.filter(r => r.primitive === 'service_account').length;
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-[#0a0a0a] text-[#ededed]">
|
||||
<SiteNav currentPath="/integrations" />
|
||||
|
||||
<div className="max-w-5xl mx-auto px-6 py-12">
|
||||
{/* Header */}
|
||||
<h1 className="text-3xl font-bold text-white mb-2">
|
||||
{RECIPES.length} 個已驗證的認證服務
|
||||
</h1>
|
||||
<p className="text-[#555] mb-2">
|
||||
由 arcrun 團隊維護,每個 recipe 都通過整合測試。
|
||||
</p>
|
||||
<div className="flex gap-4 text-sm text-[#444] mb-8">
|
||||
<span>{staticCount} API Key 類</span>
|
||||
<span>·</span>
|
||||
<span>{saCount} Service Account 類</span>
|
||||
</div>
|
||||
|
||||
{/* Category filter */}
|
||||
<div className="flex gap-2 flex-wrap mb-8">
|
||||
{CATEGORIES.map(c => (
|
||||
<Link
|
||||
key={c}
|
||||
href={c === 'All' ? '/integrations' : `/integrations?cat=${c}`}
|
||||
className={`px-3 py-1.5 rounded-full text-sm transition-colors ${
|
||||
cat === c
|
||||
? 'bg-indigo-600 text-white'
|
||||
: 'bg-[#111] border border-[#222] text-[#666] hover:text-white hover:border-[#444]'
|
||||
}`}
|
||||
>
|
||||
{c}
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Recipe grid */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 mb-12">
|
||||
{filtered.map(recipe => (
|
||||
<RecipeCard key={recipe.id} recipe={recipe} />
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Contribute CTA */}
|
||||
<div className="bg-[#111] border border-[#222] rounded-2xl p-8 text-center">
|
||||
<h2 className="text-white font-semibold text-xl mb-2">找不到你要的服務?</h2>
|
||||
<p className="text-[#555] text-sm mb-4 max-w-lg mx-auto">
|
||||
大部分 API Key 類的服務,填一份 YAML 就能加進來。
|
||||
把 API 文件丟給 AI,五分鐘生成,開 PR 送出。
|
||||
</p>
|
||||
<div className="flex gap-3 justify-center flex-wrap">
|
||||
<a href="https://github.com/richblack/arcrun" target="_blank" rel="noopener noreferrer"
|
||||
className="bg-indigo-600 hover:bg-indigo-500 text-white px-5 py-2.5 rounded-lg text-sm font-medium transition-colors">
|
||||
開始貢獻
|
||||
</a>
|
||||
<a href="https://github.com/richblack/arcrun/blob/main/CONTRIBUTING.md" target="_blank" rel="noopener noreferrer"
|
||||
className="border border-[#333] hover:border-[#555] text-[#aaa] hover:text-white px-5 py-2.5 rounded-lg text-sm font-medium transition-colors">
|
||||
查看 Recipe 格式
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function RecipeCard({ recipe }: { recipe: Recipe }) {
|
||||
const primitiveLabel = recipe.primitive === 'static_key' ? 'API Key' : 'Service Account';
|
||||
const primitiveColor = recipe.primitive === 'static_key' ? 'text-blue-400' : 'text-orange-400';
|
||||
|
||||
return (
|
||||
<div className="bg-[#111] border border-[#1e1e1e] hover:border-[#333] rounded-xl p-5 transition-colors">
|
||||
<div className="flex items-start justify-between mb-3">
|
||||
<div>
|
||||
<h3 className="text-white font-medium">{recipe.name}</h3>
|
||||
<span className={`text-xs font-mono mt-0.5 ${primitiveColor}`}>{primitiveLabel}</span>
|
||||
</div>
|
||||
{recipe.badge === 'official' && (
|
||||
<span className="text-xs bg-indigo-950/50 text-indigo-400 border border-indigo-900/30 px-2 py-0.5 rounded-full">
|
||||
★ 官方
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="text-xs text-[#444] space-y-1">
|
||||
{recipe.secrets.map(s => (
|
||||
<div key={s} className="font-mono flex items-center gap-1">
|
||||
<span className="text-[#333]">›</span> {s}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="mt-4 text-xs">
|
||||
<code className="text-[#555] bg-[#0a0a0a] px-2 py-1 rounded font-mono">
|
||||
acr auth-recipe scaffold {recipe.id}
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import type { Metadata } from "next";
|
||||
import "./globals.css";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "arcrun — Stop fighting OAuth",
|
||||
description: "One API key. Every service. Works anywhere. arcrun handles Google, Notion, GitHub, Slack authentication so your code doesn't have to.",
|
||||
openGraph: {
|
||||
title: "arcrun — Stop fighting OAuth",
|
||||
description: "One API key. Every service. Works anywhere.",
|
||||
url: "https://arcrun.dev",
|
||||
siteName: "arcrun",
|
||||
},
|
||||
};
|
||||
|
||||
export default function RootLayout({
|
||||
children,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
return (
|
||||
<html lang="en" className="h-full">
|
||||
<body className="min-h-full flex flex-col bg-[#0a0a0a] text-[#ededed]">
|
||||
{children}
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
export const runtime = 'edge';
|
||||
|
||||
import Link from 'next/link';
|
||||
|
||||
const API_BASE = process.env.NEXT_PUBLIC_API_BASE ?? 'https://cypher.arcrun.dev';
|
||||
|
||||
export default function LoginPage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<{ error?: string; redirect?: string }>;
|
||||
}) {
|
||||
return (
|
||||
<LoginContent searchParamsPromise={searchParams} />
|
||||
);
|
||||
}
|
||||
|
||||
async function LoginContent({
|
||||
searchParamsPromise,
|
||||
}: {
|
||||
searchParamsPromise: Promise<{ error?: string; redirect?: string }>;
|
||||
}) {
|
||||
const params = await searchParamsPromise;
|
||||
const error = params.error;
|
||||
const redirect = params.redirect ?? '/dashboard';
|
||||
|
||||
const googleUrl = `${API_BASE}/auth/google/start?redirect=${encodeURIComponent(redirect)}`;
|
||||
const githubUrl = `${API_BASE}/auth/github/start?redirect=${encodeURIComponent(redirect)}`;
|
||||
|
||||
const errorMessages: Record<string, string> = {
|
||||
cancelled: '登入已取消。',
|
||||
invalid_state: '安全性驗證失敗,請重試。',
|
||||
server_error: '伺服器錯誤,請稍後重試。',
|
||||
github_email_required: 'GitHub 帳號需要設定公開 Email 才能登入。',
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-[#0a0a0a] flex flex-col items-center justify-center px-6">
|
||||
{/* Logo */}
|
||||
<div className="mb-8 text-center">
|
||||
<Link href="/" className="text-white font-bold text-2xl tracking-tight hover:opacity-80 transition-opacity">
|
||||
arcrun
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
{/* Card */}
|
||||
<div className="w-full max-w-sm bg-[#111] border border-[#222] rounded-2xl p-8">
|
||||
<h1 className="text-xl font-semibold text-white mb-2 text-center">登入或建立帳號</h1>
|
||||
<p className="text-[#555] text-sm text-center mb-8">取得您的 API Key,立即開始使用</p>
|
||||
|
||||
{error && (
|
||||
<div className="bg-red-950/50 border border-red-900/50 text-red-400 text-sm px-4 py-3 rounded-lg mb-6">
|
||||
{errorMessages[error] ?? '登入時發生錯誤,請重試。'}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex flex-col gap-3">
|
||||
{/* Google */}
|
||||
<a href={googleUrl}
|
||||
className="flex items-center justify-center gap-3 bg-white hover:bg-gray-100 text-gray-900 px-4 py-3 rounded-lg font-medium text-sm transition-colors">
|
||||
<GoogleIcon />
|
||||
Continue with Google
|
||||
</a>
|
||||
|
||||
{/* GitHub */}
|
||||
<a href={githubUrl}
|
||||
className="flex items-center justify-center gap-3 bg-[#24292e] hover:bg-[#2f363d] text-white border border-[#444] px-4 py-3 rounded-lg font-medium text-sm transition-colors">
|
||||
<GitHubIcon />
|
||||
Continue with GitHub
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<p className="text-[#444] text-xs text-center mt-6 leading-relaxed">
|
||||
登入即表示您同意我們的服務條款。
|
||||
不需要信用卡。
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<Link href="/" className="mt-6 text-[#444] hover:text-[#888] text-sm transition-colors">
|
||||
← 返回首頁
|
||||
</Link>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function GoogleIcon() {
|
||||
return (
|
||||
<svg width="18" height="18" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z" fill="#4285F4"/>
|
||||
<path d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z" fill="#34A853"/>
|
||||
<path d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z" fill="#FBBC05"/>
|
||||
<path d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z" fill="#EA4335"/>
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
function GitHubIcon() {
|
||||
return (
|
||||
<svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z"/>
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
'use client';
|
||||
|
||||
// Mira 共用 Markdown 渲染器(河道 + Wiki 共用)
|
||||
// SDD: polaris/mira/.agents/specs/mira-app/design.md §3.5.7
|
||||
|
||||
import { useMemo } from 'react';
|
||||
import ReactMarkdown from 'react-markdown';
|
||||
import remarkGfm from 'remark-gfm';
|
||||
|
||||
export function MarkdownView({ text }: { text: string }) {
|
||||
// 兩階段預處理:1. strip Logseq metadata;2. [[entity]] 轉成 markdown link
|
||||
const cleaned = useMemo(() => expandWikilinks(stripLogseqMeta(text)), [text]);
|
||||
return (
|
||||
<div className="mira-md">
|
||||
<ReactMarkdown
|
||||
remarkPlugins={[remarkGfm]}
|
||||
components={{
|
||||
a: ({ href, children, ...rest }) => {
|
||||
const isWikiLink = typeof href === 'string' && href.startsWith('/mira/wiki/');
|
||||
return (
|
||||
<a
|
||||
href={href}
|
||||
{...(isWikiLink ? {} : { target: '_blank', rel: 'noopener noreferrer' })}
|
||||
className="wiki-link"
|
||||
{...rest}
|
||||
>
|
||||
{children}
|
||||
</a>
|
||||
);
|
||||
},
|
||||
// 圖片不直接 inline 顯示(避免大圖打亂 feed),改成連結
|
||||
img: ({ src, alt }) => {
|
||||
const href = typeof src === 'string' ? src : '';
|
||||
return href ? (
|
||||
<a
|
||||
href={href}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="wiki-link"
|
||||
style={{ fontStyle: 'italic' }}
|
||||
>
|
||||
🖼 {alt || 'image'}
|
||||
</a>
|
||||
) : null;
|
||||
},
|
||||
}}
|
||||
>
|
||||
{cleaned}
|
||||
</ReactMarkdown>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Strip Logseq 專屬語法
|
||||
// - 屬性行:`xxx:: yyy`、`collapsed:: true`、`id:: ...`、`logseq.order-list-type:: ...`
|
||||
// - block ref:`((uuid))` 暫時保留為純文字
|
||||
export function stripLogseqMeta(text: string): string {
|
||||
return text
|
||||
.split('\n')
|
||||
.filter((line) => {
|
||||
const trimmed = line.trimStart();
|
||||
if (/^[a-zA-Z][a-zA-Z0-9_.-]*::\s/.test(trimmed)) return false;
|
||||
return true;
|
||||
})
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
// 把 [[entity]] 轉成 markdown link 指向 /mira/wiki/wiki-{entity}
|
||||
// 對應 mira-app design.md §3.6.2 + tasks.md backlog #12
|
||||
export function expandWikilinks(text: string): string {
|
||||
return text.replace(/\[\[([^\[\]\n]+?)\]\]/g, (_, entity: string) => {
|
||||
const e = entity.trim();
|
||||
if (!e) return '[[]]';
|
||||
const url = `/mira/wiki/${encodeURIComponent('wiki-' + e)}`;
|
||||
return `[${e}](${url})`;
|
||||
});
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,87 @@
|
||||
'use client';
|
||||
|
||||
// Mira 子應用 layout
|
||||
// SDD: polaris/mira/.agents/specs/mira-app/design.md §5.5
|
||||
// 規範:白名單 user 進得去;非白名單 user 看到「即將開放」頁
|
||||
// middleware 已做未登入跳 /login?redirect=/mira 檢查(不在這裡重做)
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
import SiteNav from '../components/SiteNav';
|
||||
import { MATRIX_APPS } from '../components/apps';
|
||||
|
||||
const API_BASE = process.env.NEXT_PUBLIC_API_BASE ?? 'https://cypher.arcrun.dev';
|
||||
|
||||
type Me = { email: string; display_name: string; api_key: string };
|
||||
|
||||
const MIRA = MATRIX_APPS.find(a => a.id === 'mira');
|
||||
const ALLOWED = new Set(MIRA?.allowlist_emails ?? []);
|
||||
|
||||
export default function MiraLayout({ children }: { children: React.ReactNode }) {
|
||||
const [me, setMe] = useState<Me | null | undefined>(undefined);
|
||||
|
||||
useEffect(() => {
|
||||
fetch(`${API_BASE}/me`, { credentials: 'include' })
|
||||
.then(r => r.ok ? r.json() as Promise<Me> : null)
|
||||
.then(u => setMe(u))
|
||||
.catch(() => setMe(null));
|
||||
}, []);
|
||||
|
||||
if (me === undefined) {
|
||||
return (
|
||||
<>
|
||||
<SiteNav currentPath="/mira" />
|
||||
<div className="flex-1 flex items-center justify-center text-[#666]">載入中…</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
if (me === null) {
|
||||
// 理論上 middleware 已擋住,但保險
|
||||
if (typeof window !== 'undefined') {
|
||||
window.location.href = '/login?redirect=/mira';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!ALLOWED.has(me.email)) {
|
||||
return (
|
||||
<>
|
||||
<SiteNav currentPath="/mira" />
|
||||
<BetaBlocked email={me.email} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<SiteNav currentPath="/mira" />
|
||||
{children}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function BetaBlocked({ email }: { email: string }) {
|
||||
return (
|
||||
<main className="flex-1 flex items-center justify-center px-6">
|
||||
<div className="max-w-md text-center space-y-4">
|
||||
<div className="text-6xl mb-2">🌊</div>
|
||||
<h1 className="text-3xl font-bold text-white">Mira 仍封測中</h1>
|
||||
<p className="text-[#888] leading-relaxed">
|
||||
Mira 是 arcrun 的個人化 KM 河道,目前僅開放給少數測試用戶。
|
||||
</p>
|
||||
<p className="text-sm text-[#555]">
|
||||
你登入的帳號是 <span className="font-mono text-[#888]">{email}</span>,
|
||||
不在白名單內。準備好對外開放時會公告。
|
||||
</p>
|
||||
<div className="pt-4">
|
||||
<a
|
||||
href="/dashboard"
|
||||
className="inline-block bg-indigo-600 hover:bg-indigo-500 text-white px-5 py-2 rounded-md text-sm font-medium transition-colors"
|
||||
>
|
||||
回 Dashboard
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,861 @@
|
||||
/* Mira — 社群貼文式 KM 河道
|
||||
* 視覺參考:Facebook / X / LinkedIn
|
||||
* Scope 在 .mira-app 容器內,避免汙染 landing 的 Tailwind 樣式
|
||||
*/
|
||||
|
||||
.mira-app {
|
||||
/* Surfaces */
|
||||
--mira-bg-0: #0e0e0d;
|
||||
--mira-bg-1: #1a1a18;
|
||||
--mira-bg-2: #252320;
|
||||
--mira-bg-3: #302d28;
|
||||
|
||||
--mira-line: #2e2c27;
|
||||
--mira-line-soft: #1f1d1a;
|
||||
|
||||
/* Text — 高對比 */
|
||||
--mira-text-1: #f0eee8;
|
||||
--mira-text-2: #c9c4b8;
|
||||
--mira-text-3: #9c968a;
|
||||
--mira-text-4: #6c685e;
|
||||
|
||||
--mira-accent: oklch(0.78 0.13 75);
|
||||
--mira-accent-soft: oklch(0.78 0.13 75 / 0.16);
|
||||
--mira-accent-line: oklch(0.78 0.13 75 / 0.4);
|
||||
|
||||
--mira-conflict: oklch(0.72 0.14 30);
|
||||
--mira-conflict-soft: oklch(0.72 0.14 30 / 0.13);
|
||||
|
||||
--mira-src-logseq: oklch(0.75 0.08 250);
|
||||
--mira-src-mobile: oklch(0.78 0.07 160);
|
||||
--mira-src-tg: oklch(0.78 0.08 220);
|
||||
--mira-src-rss: oklch(0.78 0.08 30);
|
||||
--mira-src-ai: oklch(0.82 0.10 95);
|
||||
|
||||
--mira-radius-sm: 6px;
|
||||
--mira-radius: 10px;
|
||||
--mira-radius-lg: 14px;
|
||||
|
||||
--mira-font-zh: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
|
||||
--mira-font-en: "Inter Tight", "Helvetica Neue", Helvetica, Arial, sans-serif;
|
||||
--mira-font-mono: "JetBrains Mono", "SF Mono", Menlo, monospace;
|
||||
|
||||
background: var(--mira-bg-0);
|
||||
color: var(--mira-text-1);
|
||||
font-family: var(--mira-font-zh);
|
||||
/* 不啟用 palt:保留中文標點全寬,避免標點看起來只有半寬 */
|
||||
-webkit-font-smoothing: antialiased;
|
||||
text-rendering: optimizeLegibility;
|
||||
letter-spacing: 0.01em;
|
||||
line-height: 1.65;
|
||||
min-height: calc(100vh - 73px);
|
||||
}
|
||||
|
||||
.mira-app .mira-num,
|
||||
.mira-app .mira-en {
|
||||
font-family: var(--mira-font-en);
|
||||
letter-spacing: 0;
|
||||
}
|
||||
|
||||
.mira-app .mira-content {
|
||||
max-width: 920px;
|
||||
margin: 0 auto;
|
||||
padding: 24px 16px 80px;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.mira-app .mira-content {
|
||||
padding: 12px 0 60px;
|
||||
}
|
||||
}
|
||||
|
||||
/* ── card 卡片 ── */
|
||||
.mira-app .mira-card {
|
||||
background: var(--mira-bg-1);
|
||||
border: 1px solid var(--mira-line);
|
||||
border-radius: var(--mira-radius);
|
||||
margin-bottom: 12px;
|
||||
/* 不要 overflow: hidden — 會 clip ⋮ menu dropdown */
|
||||
position: relative;
|
||||
}
|
||||
@media (max-width: 640px) {
|
||||
.mira-app .mira-card {
|
||||
border-radius: 0;
|
||||
border-left: none;
|
||||
border-right: none;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
/* ── composer 寫貼文 ── */
|
||||
.mira-app .mira-composer-card {
|
||||
padding: 14px 16px;
|
||||
}
|
||||
.mira-app .mira-composer-row {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
align-items: flex-start;
|
||||
}
|
||||
.mira-app .mira-composer-textarea {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
background: transparent;
|
||||
border: none;
|
||||
outline: none;
|
||||
resize: none;
|
||||
font-family: inherit;
|
||||
font-size: 16px;
|
||||
line-height: 1.65;
|
||||
color: var(--mira-text-1);
|
||||
padding: 8px 0;
|
||||
}
|
||||
.mira-app .mira-composer-textarea::placeholder {
|
||||
color: var(--mira-text-3);
|
||||
}
|
||||
.mira-app .mira-composer-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding-top: 10px;
|
||||
margin-top: 8px;
|
||||
border-top: 1px solid var(--mira-line-soft);
|
||||
margin-left: 52px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
/* ── avatar ── */
|
||||
.mira-app .mira-avatar {
|
||||
border-radius: 50%;
|
||||
flex-shrink: 0;
|
||||
background: var(--mira-bg-2);
|
||||
object-fit: cover;
|
||||
}
|
||||
.mira-app .mira-avatar-fallback {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
background: linear-gradient(135deg, var(--mira-bg-2), var(--mira-bg-3));
|
||||
color: var(--mira-text-1);
|
||||
font-weight: 600;
|
||||
font-family: var(--mira-font-en);
|
||||
}
|
||||
|
||||
/* Mira 自有頭像 — 跟 leo 區分(紫色漸層 + 機器人 emoji) */
|
||||
.mira-app .mira-avatar-mira {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
background: linear-gradient(135deg, oklch(0.45 0.15 280), oklch(0.55 0.18 300));
|
||||
color: #fff;
|
||||
border-radius: 50%;
|
||||
flex-shrink: 0;
|
||||
/* emoji 本身有色彩,背景僅當邊框襯托 */
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
/* ── post 貼文 ── */
|
||||
.mira-app .mira-post {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.mira-app .mira-post-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 14px 16px 10px;
|
||||
}
|
||||
.mira-app .mira-post-author {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
.mira-app .mira-post-name {
|
||||
font-size: 14.5px;
|
||||
font-weight: 600;
|
||||
color: var(--mira-text-1);
|
||||
line-height: 1.3;
|
||||
}
|
||||
.mira-app .mira-post-time {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 12px;
|
||||
color: var(--mira-text-3);
|
||||
font-family: var(--mira-font-en);
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
/* ── post body 內文 ── */
|
||||
.mira-app .mira-post-body {
|
||||
padding: 0 16px 12px;
|
||||
}
|
||||
.mira-app .mira-post-content {
|
||||
font-size: 15px;
|
||||
line-height: 1.7;
|
||||
color: var(--mira-text-1);
|
||||
word-break: break-word;
|
||||
white-space: normal;
|
||||
}
|
||||
.mira-app .mira-post-content-full {
|
||||
/* 展開模式:顯示每個 sub-block 為獨立行,可編輯 */
|
||||
font-size: 14.5px;
|
||||
}
|
||||
|
||||
/* react-markdown render 樣式 */
|
||||
.mira-app .mira-md > *:first-child { margin-top: 0; }
|
||||
.mira-app .mira-md > *:last-child { margin-bottom: 0; }
|
||||
|
||||
.mira-app .mira-md p {
|
||||
margin: 0 0 8px;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.mira-app .mira-md h1,
|
||||
.mira-app .mira-md h2,
|
||||
.mira-app .mira-md h3,
|
||||
.mira-app .mira-md h4,
|
||||
.mira-app .mira-md h5,
|
||||
.mira-app .mira-md h6 {
|
||||
margin: 14px 0 6px;
|
||||
font-weight: 700;
|
||||
color: var(--mira-text-1);
|
||||
line-height: 1.3;
|
||||
}
|
||||
.mira-app .mira-md h1 { font-size: 1.5em; }
|
||||
.mira-app .mira-md h2 { font-size: 1.3em; }
|
||||
.mira-app .mira-md h3 { font-size: 1.15em; font-weight: 600; }
|
||||
.mira-app .mira-md h4,
|
||||
.mira-app .mira-md h5,
|
||||
.mira-app .mira-md h6 { font-size: 1em; font-weight: 600; }
|
||||
|
||||
.mira-app .mira-md ul,
|
||||
.mira-app .mira-md ol {
|
||||
margin: 4px 0 8px;
|
||||
padding-left: 22px;
|
||||
}
|
||||
.mira-app .mira-md ul {
|
||||
list-style: disc;
|
||||
}
|
||||
.mira-app .mira-md ul ul {
|
||||
list-style: circle;
|
||||
}
|
||||
.mira-app .mira-md ul ul ul {
|
||||
list-style: square;
|
||||
}
|
||||
.mira-app .mira-md ol {
|
||||
list-style: decimal;
|
||||
}
|
||||
.mira-app .mira-md ul ul,
|
||||
.mira-app .mira-md ul ol,
|
||||
.mira-app .mira-md ol ul,
|
||||
.mira-app .mira-md ol ol {
|
||||
margin: 4px 0;
|
||||
}
|
||||
.mira-app .mira-md li {
|
||||
margin: 2px 0;
|
||||
line-height: 1.7;
|
||||
}
|
||||
/* GFM task list 的 li 不顯示 bullet(checkbox 取代)*/
|
||||
.mira-app .mira-md li:has(> input[type="checkbox"]) {
|
||||
list-style: none;
|
||||
margin-left: -22px;
|
||||
}
|
||||
.mira-app .mira-md li > p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.mira-app .mira-md blockquote {
|
||||
margin: 8px 0;
|
||||
padding: 4px 12px;
|
||||
border-left: 3px solid var(--mira-line);
|
||||
color: var(--mira-text-2);
|
||||
background: var(--mira-bg-2);
|
||||
border-radius: 0 4px 4px 0;
|
||||
}
|
||||
.mira-app .mira-md blockquote p:last-child { margin-bottom: 0; }
|
||||
|
||||
.mira-app .mira-md hr {
|
||||
border: none;
|
||||
border-top: 1px solid var(--mira-line);
|
||||
margin: 16px 0;
|
||||
}
|
||||
|
||||
.mira-app .mira-md code {
|
||||
font-family: var(--mira-font-mono);
|
||||
font-size: 0.9em;
|
||||
background: var(--mira-bg-2);
|
||||
padding: 1px 5px;
|
||||
border-radius: 4px;
|
||||
border: 1px solid var(--mira-line-soft);
|
||||
}
|
||||
.mira-app .mira-md pre {
|
||||
margin: 8px 0;
|
||||
padding: 12px;
|
||||
background: var(--mira-bg-2);
|
||||
border: 1px solid var(--mira-line-soft);
|
||||
border-radius: 6px;
|
||||
overflow-x: auto;
|
||||
}
|
||||
.mira-app .mira-md pre code {
|
||||
background: transparent;
|
||||
border: none;
|
||||
padding: 0;
|
||||
font-size: 0.85em;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.mira-app .mira-md table {
|
||||
border-collapse: collapse;
|
||||
margin: 8px 0;
|
||||
width: 100%;
|
||||
font-size: 0.95em;
|
||||
}
|
||||
.mira-app .mira-md th,
|
||||
.mira-app .mira-md td {
|
||||
border: 1px solid var(--mira-line);
|
||||
padding: 6px 10px;
|
||||
text-align: left;
|
||||
}
|
||||
.mira-app .mira-md th {
|
||||
background: var(--mira-bg-2);
|
||||
color: var(--mira-text-1);
|
||||
font-weight: 600;
|
||||
}
|
||||
.mira-app .mira-md tr:nth-child(even) {
|
||||
background: rgba(255, 255, 255, 0.02);
|
||||
}
|
||||
|
||||
.mira-app .mira-md strong { color: var(--mira-text-1); font-weight: 700; }
|
||||
.mira-app .mira-md em { font-style: italic; }
|
||||
.mira-app .mira-md del { color: var(--mira-text-3); }
|
||||
|
||||
/* GFM task list */
|
||||
.mira-app .mira-md input[type="checkbox"] {
|
||||
margin-right: 6px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
/* ── show more ── */
|
||||
.mira-app .mira-show-more {
|
||||
background: transparent;
|
||||
border: none;
|
||||
color: var(--mira-accent);
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
padding: 4px 0;
|
||||
margin-top: 4px;
|
||||
font-family: inherit;
|
||||
}
|
||||
.mira-app .mira-show-more:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/* ── footer 互動列 ── */
|
||||
.mira-app .mira-post-footer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
border-top: 1px solid var(--mira-line-soft);
|
||||
padding: 4px 8px;
|
||||
margin: 0 8px;
|
||||
}
|
||||
.mira-app .mira-action-btn {
|
||||
background: transparent;
|
||||
border: none;
|
||||
color: var(--mira-text-2);
|
||||
font-size: 13.5px;
|
||||
font-family: inherit;
|
||||
padding: 8px 14px;
|
||||
cursor: pointer;
|
||||
border-radius: 6px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
transition: background 0.12s, color 0.12s;
|
||||
}
|
||||
.mira-app .mira-action-btn:hover,
|
||||
.mira-app .mira-action-btn:active {
|
||||
background: var(--mira-bg-2);
|
||||
color: var(--mira-text-1);
|
||||
}
|
||||
.mira-app .mira-action-count {
|
||||
font-size: 12px;
|
||||
color: var(--mira-text-3);
|
||||
font-family: var(--mira-font-en);
|
||||
}
|
||||
|
||||
/* ── replies 對整篇的留言 ── */
|
||||
.mira-app .mira-post-replies {
|
||||
background: var(--mira-bg-0);
|
||||
padding: 8px 16px;
|
||||
border-top: 1px solid var(--mira-line-soft);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
.mira-app .mira-show-replies {
|
||||
background: transparent;
|
||||
border: none;
|
||||
color: var(--mira-text-2);
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
padding: 6px 4px;
|
||||
text-align: left;
|
||||
font-family: inherit;
|
||||
font-weight: 500;
|
||||
}
|
||||
.mira-app .mira-show-replies:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
.mira-app .mira-reply-composer {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
padding: 10px 16px;
|
||||
border-top: 1px solid var(--mira-line-soft);
|
||||
background: var(--mira-bg-0);
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
/* ── reply line ── */
|
||||
.mira-app .mira-reply-line {
|
||||
margin-bottom: 6px;
|
||||
padding: 8px 10px;
|
||||
background: var(--mira-bg-1);
|
||||
border-radius: 16px;
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 8px;
|
||||
position: relative;
|
||||
}
|
||||
.mira-app .mira-reply-line.is-ai {
|
||||
background: var(--mira-accent-soft);
|
||||
}
|
||||
/* reply line 內的 ⋮ 永遠顯示(取代 hover only)*/
|
||||
.mira-app .mira-reply-line .mira-menu-wrap {
|
||||
opacity: 1;
|
||||
}
|
||||
.mira-app .mira-reply-icon {
|
||||
font-size: 13px;
|
||||
color: var(--mira-text-2);
|
||||
flex-shrink: 0;
|
||||
margin-top: 2px;
|
||||
}
|
||||
.mira-app .mira-reply-line.is-ai .mira-reply-icon {
|
||||
color: var(--mira-accent);
|
||||
}
|
||||
.mira-app .mira-reply-content {
|
||||
font-size: 13.5px;
|
||||
line-height: 1.6;
|
||||
color: var(--mira-text-1);
|
||||
word-break: break-word;
|
||||
white-space: normal;
|
||||
}
|
||||
.mira-app .mira-reply-nested {
|
||||
margin-left: 20px;
|
||||
margin-top: 4px;
|
||||
padding-left: 8px;
|
||||
border-left: 2px solid var(--mira-line-soft);
|
||||
}
|
||||
|
||||
/* ── source tag ── */
|
||||
.mira-app .src-tag {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
padding: 1px 7px;
|
||||
border-radius: 999px;
|
||||
font-size: 11px;
|
||||
font-family: var(--mira-font-en);
|
||||
letter-spacing: 0.04em;
|
||||
background: var(--mira-bg-2);
|
||||
color: var(--mira-text-2);
|
||||
border: 1px solid var(--mira-line);
|
||||
}
|
||||
.mira-app .src-dot {
|
||||
width: 5px;
|
||||
height: 5px;
|
||||
border-radius: 50%;
|
||||
background: var(--mira-text-3);
|
||||
}
|
||||
.mira-app .src-tag.logseq .src-dot { background: var(--mira-src-logseq); }
|
||||
.mira-app .src-tag.mobile .src-dot { background: var(--mira-src-mobile); }
|
||||
.mira-app .src-tag.tg .src-dot { background: var(--mira-src-tg); }
|
||||
.mira-app .src-tag.rss .src-dot { background: var(--mira-src-rss); }
|
||||
.mira-app .src-tag.ai .src-dot { background: var(--mira-src-ai); }
|
||||
|
||||
/* ── wiki link ── */
|
||||
.mira-app .wiki-link {
|
||||
color: var(--mira-accent);
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
border-bottom: 1px dashed var(--mira-accent-line);
|
||||
padding-bottom: 1px;
|
||||
}
|
||||
.mira-app .wiki-link:hover {
|
||||
background: var(--mira-accent-soft);
|
||||
}
|
||||
|
||||
/* ── empty state ── */
|
||||
.mira-app .empty-state {
|
||||
text-align: center;
|
||||
padding: 80px 20px;
|
||||
color: var(--mira-text-2);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
/* ── icon button ── */
|
||||
.mira-app .mira-icon-btn {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
border-radius: 50%;
|
||||
cursor: pointer;
|
||||
color: var(--mira-text-2);
|
||||
background: transparent;
|
||||
border: none;
|
||||
font-size: 14px;
|
||||
line-height: 1;
|
||||
padding: 0;
|
||||
transition: background 0.12s, color 0.12s;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.mira-app .mira-icon-btn:hover,
|
||||
.mira-app .mira-icon-btn:active {
|
||||
background: var(--mira-bg-2);
|
||||
color: var(--mira-text-1);
|
||||
}
|
||||
.mira-app .mira-icon-btn-vertical {
|
||||
font-size: 20px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0;
|
||||
}
|
||||
|
||||
/* ── ⋮ menu (dropdown) ── */
|
||||
.mira-app .mira-menu-wrap {
|
||||
position: relative;
|
||||
}
|
||||
.mira-app .mira-menu {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: calc(100% + 4px);
|
||||
min-width: 160px;
|
||||
background: var(--mira-bg-1);
|
||||
border: 1px solid var(--mira-line);
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
|
||||
padding: 4px;
|
||||
z-index: 10;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1px;
|
||||
}
|
||||
.mira-app .mira-menu-item {
|
||||
background: transparent;
|
||||
border: none;
|
||||
text-align: left;
|
||||
padding: 10px 14px;
|
||||
border-radius: 5px;
|
||||
color: var(--mira-text-1);
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
font-family: inherit;
|
||||
transition: background 0.12s;
|
||||
}
|
||||
.mira-app .mira-menu-item:hover,
|
||||
.mira-app .mira-menu-item:active {
|
||||
background: var(--mira-bg-2);
|
||||
}
|
||||
.mira-app .mira-menu-item.danger {
|
||||
color: var(--mira-conflict);
|
||||
}
|
||||
.mira-app .mira-menu-item.danger:hover {
|
||||
background: var(--mira-conflict-soft);
|
||||
}
|
||||
|
||||
/* ── block-line(FullContent 模式)── */
|
||||
.mira-app .mira-block-line {
|
||||
position: relative;
|
||||
}
|
||||
.mira-app .mira-block-line .mira-menu-wrap {
|
||||
opacity: 0;
|
||||
transition: opacity 0.12s;
|
||||
}
|
||||
.mira-app .mira-block-line:hover .mira-menu-wrap {
|
||||
opacity: 1;
|
||||
}
|
||||
@media (hover: none) {
|
||||
/* 觸控裝置一律顯示 ⋮ */
|
||||
.mira-app .mira-block-line .mira-menu-wrap {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
.mira-app .mira-menu-wrap:has(.mira-menu) { opacity: 1 !important; }
|
||||
|
||||
/* ── edit textarea ── */
|
||||
.mira-app .mira-edit-textarea {
|
||||
width: 100%;
|
||||
background: var(--mira-bg-0);
|
||||
border: 1px solid var(--mira-accent-line);
|
||||
border-radius: 8px;
|
||||
padding: 10px 12px;
|
||||
font-family: inherit;
|
||||
font-size: 14px;
|
||||
line-height: 1.7;
|
||||
color: var(--mira-text-1);
|
||||
resize: vertical;
|
||||
outline: none;
|
||||
}
|
||||
.mira-app .mira-edit-textarea:focus {
|
||||
border-color: var(--mira-accent);
|
||||
}
|
||||
.mira-app .mira-edit-textarea::placeholder {
|
||||
color: var(--mira-text-3);
|
||||
}
|
||||
.mira-app .mira-edit-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-top: 6px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
/* ── markdown toolbar ── */
|
||||
.mira-app .mira-md-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 6px 8px;
|
||||
background: var(--mira-bg-2);
|
||||
border: 1px solid var(--mira-line);
|
||||
border-bottom: none;
|
||||
border-top-left-radius: 8px;
|
||||
border-top-right-radius: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
/* compact 模式:給 PostComposer 的 actions 列 inline 用 */
|
||||
.mira-app .mira-md-toolbar.compact {
|
||||
padding: 0;
|
||||
background: transparent;
|
||||
border: none;
|
||||
gap: 2px;
|
||||
}
|
||||
.mira-app .mira-md-btn {
|
||||
background: transparent;
|
||||
border: none;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
border-radius: 5px;
|
||||
color: var(--mira-text-2);
|
||||
cursor: pointer;
|
||||
font-size: 13px;
|
||||
font-family: inherit;
|
||||
transition: background 0.12s, color 0.12s;
|
||||
padding: 0;
|
||||
line-height: 1;
|
||||
}
|
||||
.mira-app .mira-md-btn:hover,
|
||||
.mira-app .mira-md-btn:active {
|
||||
background: var(--mira-bg-3);
|
||||
color: var(--mira-text-1);
|
||||
}
|
||||
.mira-app .mira-md-btn em {
|
||||
font-style: italic;
|
||||
font-family: serif;
|
||||
}
|
||||
.mira-app .mira-md-hint {
|
||||
margin-left: auto;
|
||||
font-size: 11px;
|
||||
color: var(--mira-text-3);
|
||||
font-family: var(--mira-font-en);
|
||||
}
|
||||
/* toolbar 之後的 textarea 接續成一塊 */
|
||||
.mira-app .mira-md-toolbar + .mira-edit-textarea {
|
||||
border-top-left-radius: 0;
|
||||
border-top-right-radius: 0;
|
||||
border-top: none;
|
||||
}
|
||||
|
||||
/* ── kbd 提示 ── */
|
||||
.mira-app .mira-kbd {
|
||||
font-size: 11px;
|
||||
color: var(--mira-text-3);
|
||||
font-family: var(--mira-font-en);
|
||||
}
|
||||
|
||||
/* ── messages ── */
|
||||
.mira-app .mira-msg-error {
|
||||
font-size: 12px;
|
||||
color: var(--mira-conflict);
|
||||
}
|
||||
.mira-app .mira-error {
|
||||
padding: 16px;
|
||||
color: var(--mira-conflict);
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
/* ── buttons ── */
|
||||
.mira-app .mira-btn-primary {
|
||||
background: var(--mira-accent);
|
||||
border: none;
|
||||
color: var(--mira-bg-0);
|
||||
font-size: 13px;
|
||||
padding: 8px 18px;
|
||||
border-radius: 999px;
|
||||
cursor: pointer;
|
||||
font-weight: 600;
|
||||
font-family: inherit;
|
||||
transition: opacity 0.12s, background 0.12s;
|
||||
}
|
||||
.mira-app .mira-btn-primary:hover {
|
||||
opacity: 0.9;
|
||||
}
|
||||
.mira-app .mira-btn-primary:disabled,
|
||||
.mira-app .mira-btn-primary.disabled {
|
||||
background: var(--mira-bg-3);
|
||||
color: var(--mira-text-3);
|
||||
cursor: not-allowed;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.mira-app .mira-btn-ghost {
|
||||
background: transparent;
|
||||
border: 1px solid var(--mira-line);
|
||||
color: var(--mira-text-2);
|
||||
font-size: 12px;
|
||||
padding: 6px 14px;
|
||||
border-radius: 999px;
|
||||
cursor: pointer;
|
||||
font-family: inherit;
|
||||
}
|
||||
.mira-app .mira-btn-ghost:hover {
|
||||
background: var(--mira-bg-2);
|
||||
color: var(--mira-text-1);
|
||||
}
|
||||
|
||||
/* ── Mira 思考中(AI reply pending)── */
|
||||
.mira-app .mira-thinking {
|
||||
opacity: 0.7;
|
||||
}
|
||||
.mira-app .mira-thinking-dots::after {
|
||||
content: '⋯';
|
||||
display: inline-block;
|
||||
animation: mira-think-dots 1.4s infinite;
|
||||
}
|
||||
@keyframes mira-think-dots {
|
||||
0%, 100% { opacity: 0.3; }
|
||||
50% { opacity: 1; }
|
||||
}
|
||||
|
||||
/* ── skeleton loader ── */
|
||||
.mira-app .mira-skel {
|
||||
height: 60px;
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
var(--mira-bg-1) 0%,
|
||||
var(--mira-bg-2) 50%,
|
||||
var(--mira-bg-1) 100%
|
||||
);
|
||||
background-size: 200% 100%;
|
||||
animation: mira-skel-shimmer 1.4s ease-in-out infinite;
|
||||
border-radius: 6px;
|
||||
}
|
||||
@keyframes mira-skel-shimmer {
|
||||
0% { background-position: 200% 0; }
|
||||
100% { background-position: -200% 0; }
|
||||
}
|
||||
|
||||
/* ── rel time ── */
|
||||
.mira-app .mira-rel-time {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
/* ── Wiki detail (7B.3g 樹狀渲染) ── */
|
||||
/* .mira-md 已在 §190+ 定義整套 markdown 樣式(河道+wiki 共用),這裡只加 wiki 細節頁的「不破版」保護 */
|
||||
.mira-app .mira-wiki-detail {
|
||||
overflow-wrap: break-word;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
/* 防止長 cypher binding 字串 / URL 撐爆右邊界 */
|
||||
.mira-app .mira-wiki-detail .mira-md li,
|
||||
.mira-app .mira-wiki-detail .mira-md p {
|
||||
overflow-wrap: break-word;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
/* wiki h2/h3 加底線分隔,更像文章 */
|
||||
.mira-app .mira-wiki-detail .mira-md h2 {
|
||||
border-bottom: 1px solid var(--mira-line-soft);
|
||||
padding-bottom: 4px;
|
||||
}
|
||||
|
||||
/* ── Composer popup (P0 #5c 編輯器放大) ── */
|
||||
.mira-app .mira-composer-expand {
|
||||
font-size: 18px;
|
||||
padding: 0 8px;
|
||||
cursor: pointer;
|
||||
color: var(--mira-text-3);
|
||||
}
|
||||
.mira-app .mira-composer-expand:hover {
|
||||
color: var(--mira-text-1);
|
||||
}
|
||||
|
||||
/* backdrop 蓋全頁 + 居中 */
|
||||
.mira-composer-popup-backdrop {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgba(0, 0, 0, 0.6);
|
||||
z-index: 1000;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
/* popup card 大編輯區 */
|
||||
.mira-composer-popup {
|
||||
background: var(--mira-bg-1);
|
||||
border: 1px solid var(--mira-line);
|
||||
border-radius: var(--mira-radius-lg);
|
||||
width: min(800px, 100%);
|
||||
max-height: 90vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
font-family: var(--mira-font-zh);
|
||||
color: var(--mira-text-1);
|
||||
}
|
||||
|
||||
.mira-composer-popup-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 14px 16px;
|
||||
border-bottom: 1px solid var(--mira-line);
|
||||
}
|
||||
|
||||
.mira-composer-popup-title {
|
||||
font-weight: 600;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.mira-composer-popup-textarea {
|
||||
flex: 1;
|
||||
min-height: 320px;
|
||||
padding: 16px;
|
||||
background: transparent;
|
||||
color: var(--mira-text-1);
|
||||
border: none;
|
||||
outline: none;
|
||||
resize: none;
|
||||
font-family: inherit;
|
||||
font-size: 15px;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.mira-composer-popup-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 12px 16px;
|
||||
border-top: 1px solid var(--mira-line);
|
||||
background: var(--mira-bg-0);
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
'use client';
|
||||
|
||||
// Mira 首頁(Profile / KM Hub)
|
||||
// SDD: polaris/mira/.agents/specs/mira-app/design.md §5.2
|
||||
// 這頁是 leo 的 KM 首頁,列出所有同層子頁的入口
|
||||
// 河道 / Wiki 是同層子頁,不是父子關係
|
||||
|
||||
import Link from 'next/link';
|
||||
import './mira.css';
|
||||
|
||||
type Entry = {
|
||||
href: string;
|
||||
emoji: string;
|
||||
title: string;
|
||||
desc: string;
|
||||
status?: 'live' | 'wip' | 'planned';
|
||||
};
|
||||
|
||||
const ENTRIES: Entry[] = [
|
||||
{
|
||||
href: '/mira/feed',
|
||||
emoji: '🌊',
|
||||
title: '河道',
|
||||
desc: '時間軸式貼文流,所有 source 進來的內容都在這',
|
||||
status: 'live',
|
||||
},
|
||||
{
|
||||
href: '/mira/wiki',
|
||||
emoji: '📚',
|
||||
title: 'Wiki',
|
||||
desc: 'leo 的個人觀點累積(Karpathy LLM Wiki 風格)',
|
||||
status: 'live',
|
||||
},
|
||||
{
|
||||
href: '/mira/plan',
|
||||
emoji: '📋',
|
||||
title: '計劃',
|
||||
desc: 'Task 列表 + 狀態切換 + workflow 觸發',
|
||||
status: 'planned',
|
||||
},
|
||||
{
|
||||
href: '/mira/dissent',
|
||||
emoji: '⚔️',
|
||||
title: '異見牆',
|
||||
desc: 'Triplet 列表(含 ai-idea / 矛盾標記)',
|
||||
status: 'planned',
|
||||
},
|
||||
];
|
||||
|
||||
export default function MiraHubPage() {
|
||||
return (
|
||||
<main className="mira-app">
|
||||
<div className="mira-content">
|
||||
<header style={{ padding: '32px 0 24px' }}>
|
||||
<h1 style={{ fontSize: 32, fontWeight: 700, color: '#fff', margin: 0 }}>
|
||||
🦔 Mira
|
||||
</h1>
|
||||
<p style={{ color: '#888', fontSize: 15, marginTop: 6 }}>
|
||||
leo 的個人 KM 系統
|
||||
</p>
|
||||
</header>
|
||||
|
||||
<div style={{ display: 'grid', gap: 12, paddingBottom: 40 }}>
|
||||
{ENTRIES.map((e) => (
|
||||
<EntryCard key={e.href} entry={e} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
function EntryCard({ entry }: { entry: Entry }) {
|
||||
const isClickable = entry.status === 'live';
|
||||
const card = (
|
||||
<div
|
||||
style={{
|
||||
padding: '18px 20px',
|
||||
background: '#1a1a1a',
|
||||
border: '1px solid #2a2a2a',
|
||||
borderRadius: 8,
|
||||
opacity: isClickable ? 1 : 0.5,
|
||||
cursor: isClickable ? 'pointer' : 'not-allowed',
|
||||
transition: 'border-color 0.15s',
|
||||
}}
|
||||
onMouseEnter={(e) => {
|
||||
if (isClickable) e.currentTarget.style.borderColor = '#444';
|
||||
}}
|
||||
onMouseLeave={(e) => {
|
||||
if (isClickable) e.currentTarget.style.borderColor = '#2a2a2a';
|
||||
}}
|
||||
>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 12, marginBottom: 6 }}>
|
||||
<span style={{ fontSize: 24 }}>{entry.emoji}</span>
|
||||
<span style={{ fontSize: 18, fontWeight: 600, color: '#fff' }}>
|
||||
{entry.title}
|
||||
</span>
|
||||
{entry.status === 'planned' && (
|
||||
<span
|
||||
style={{
|
||||
fontSize: 11,
|
||||
padding: '2px 8px',
|
||||
background: '#2a2a3a',
|
||||
color: '#aab',
|
||||
borderRadius: 3,
|
||||
}}
|
||||
>
|
||||
未實作
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div style={{ color: '#888', fontSize: 14, marginLeft: 36 }}>{entry.desc}</div>
|
||||
</div>
|
||||
);
|
||||
return isClickable ? (
|
||||
<Link href={entry.href} style={{ textDecoration: 'none' }}>
|
||||
{card}
|
||||
</Link>
|
||||
) : (
|
||||
card
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,467 @@
|
||||
'use client';
|
||||
|
||||
export const runtime = 'edge';
|
||||
|
||||
// Mira Wiki 單篇頁
|
||||
// SDD: polaris/mira/.agents/specs/mira-app/design.md §5.2 + §3.5.12
|
||||
// 對應 task: 7C.2 + 7B.3g
|
||||
// 路由:/mira/wiki/[pageName]
|
||||
// 顯示:wiki-page parent → wiki-paragraph children (按 facet 分區) → triplet grandchildren
|
||||
// 7B.3g 升級:樹狀渲染 + 折疊 + triplet 跨 wiki 連結化
|
||||
|
||||
import { useEffect, useMemo, useState, use } from 'react';
|
||||
import Link from 'next/link';
|
||||
import { MarkdownView } from '../../_shared/markdown';
|
||||
import '../../mira.css';
|
||||
|
||||
const KBDB_BASE = 'https://kbdb.finally.click';
|
||||
const API_BASE = process.env.NEXT_PUBLIC_API_BASE ?? 'https://cypher.arcrun.dev';
|
||||
|
||||
type Block = {
|
||||
id: string;
|
||||
page_name: string | null;
|
||||
content: string;
|
||||
type: string;
|
||||
parent_id: string | null;
|
||||
tags_json: string | null;
|
||||
source: string | null;
|
||||
created_at: number;
|
||||
updated_at: number;
|
||||
};
|
||||
|
||||
type FacetGroup = {
|
||||
facet: string;
|
||||
paragraphs: Array<{
|
||||
block: Block;
|
||||
triplets: Block[];
|
||||
}>;
|
||||
};
|
||||
|
||||
export default function WikiPagePage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ pageName: string }>;
|
||||
}) {
|
||||
const { pageName } = use(params);
|
||||
const decodedName = decodeURIComponent(pageName);
|
||||
|
||||
const [block, setBlock] = useState<Block | null>(null);
|
||||
const [paragraphs, setParagraphs] = useState<Block[]>([]);
|
||||
const [triplets, setTriplets] = useState<Block[]>([]);
|
||||
const [entitySet, setEntitySet] = useState<Set<string>>(new Set());
|
||||
// Backlinks:所有提到此 entity 的 raw note(V3 wiki_synthesis 在 wiki-page tags 寫 raw:XXX)
|
||||
// 對應 leo 2026-05-17 #2 反饋:「從這本書的條目應該反向連到那篇筆記去」
|
||||
const [backlinkRaws, setBacklinkRaws] = useState<Block[]>([]);
|
||||
const [collapsed, setCollapsed] = useState<Record<string, boolean>>({});
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
async function load() {
|
||||
try {
|
||||
const meRes = await fetch(`${API_BASE}/me`, { credentials: 'include' });
|
||||
if (!meRes.ok) throw new Error('未登入');
|
||||
const me = (await meRes.json()) as { api_key: string };
|
||||
const headers = { Authorization: `Bearer ${me.api_key}` };
|
||||
|
||||
// 1. 抓 wiki-page parent block by page_name
|
||||
const pageRes = await fetch(
|
||||
`${KBDB_BASE}/blocks?page_name=${encodeURIComponent(decodedName)}&limit=1`,
|
||||
{ headers },
|
||||
);
|
||||
if (!pageRes.ok) throw new Error(`KBDB ${pageRes.status}`);
|
||||
const pageData = await pageRes.json();
|
||||
const wikiPage: Block | undefined = pageData.blocks?.[0];
|
||||
if (cancelled) return;
|
||||
if (!wikiPage) {
|
||||
setError(`找不到 wiki page:${decodedName}`);
|
||||
return;
|
||||
}
|
||||
setBlock(wikiPage);
|
||||
|
||||
// 2. 平行撈所有 wiki-paragraph + triplet + wiki-page(跨 wiki 連結用),客戶端 filter by parent_id
|
||||
// KBDB 沒 parent_id server filter(兼 tag filter 還有 KI-3 bug),用 source+type 取再 client-side filter
|
||||
const [paraRes, tripRes, pageListRes] = await Promise.all([
|
||||
fetch(`${KBDB_BASE}/blocks?source=ai-canon-wiki&type=wiki-paragraph&limit=500`, { headers }),
|
||||
fetch(`${KBDB_BASE}/blocks?source=ai-canon-wiki&type=triplet&limit=1000`, { headers }),
|
||||
fetch(`${KBDB_BASE}/blocks?source=ai-canon-wiki&type=wiki-page&limit=500`, { headers }),
|
||||
]);
|
||||
if (!paraRes.ok || !tripRes.ok || !pageListRes.ok) {
|
||||
throw new Error('KBDB tree fetch failed');
|
||||
}
|
||||
const paraData = await paraRes.json();
|
||||
const tripData = await tripRes.json();
|
||||
const pageListData = await pageListRes.json();
|
||||
if (cancelled) return;
|
||||
|
||||
const allParas: Block[] = paraData.blocks ?? [];
|
||||
const allTrips: Block[] = tripData.blocks ?? [];
|
||||
const allPages: Block[] = pageListData.blocks ?? [];
|
||||
|
||||
// 該 wiki-page 的 paragraphs
|
||||
const myParas = allParas
|
||||
.filter((p) => p.parent_id === wikiPage.id)
|
||||
.sort((a, b) => a.created_at - b.created_at);
|
||||
setParagraphs(myParas);
|
||||
|
||||
// 該 wiki-page 範圍內所有 paragraph 的 triplets
|
||||
const paraIdSet = new Set(myParas.map((p) => p.id));
|
||||
const myTrips = allTrips.filter((t) => t.parent_id && paraIdSet.has(t.parent_id));
|
||||
setTriplets(myTrips);
|
||||
|
||||
// 跨 wiki 連結用:所有 wiki-page 的 entity 名稱(content 就是 entity)
|
||||
// 額外把 page_name 也加入(page_name=wiki-{entity})
|
||||
const eset = new Set<string>();
|
||||
for (const p of allPages) {
|
||||
if (p.content) eset.add(p.content.trim());
|
||||
if (p.page_name?.startsWith('wiki-')) {
|
||||
eset.add(p.page_name.slice(5).trim());
|
||||
}
|
||||
}
|
||||
setEntitySet(eset);
|
||||
|
||||
// Backlinks:找此 entity 的所有 wiki-page (可能多次寫入),提取 raw:XXX tag → fetch raw blocks
|
||||
if (wikiPage.type === 'wiki-page' && wikiPage.content) {
|
||||
const sameEntity = allPages.filter((p) => p.content?.trim() === wikiPage.content?.trim());
|
||||
const rawIds = new Set<string>();
|
||||
for (const wp of sameEntity) {
|
||||
try {
|
||||
const tags = JSON.parse(wp.tags_json || '[]') as string[];
|
||||
for (const t of tags) {
|
||||
if (typeof t === 'string' && t.startsWith('raw:')) {
|
||||
rawIds.add(t.slice(4));
|
||||
}
|
||||
}
|
||||
} catch { /* skip */ }
|
||||
}
|
||||
if (rawIds.size > 0) {
|
||||
// 一次撈 raw blocks,page_name 是 unique 一次 query 一個
|
||||
const rawBlocks: Block[] = [];
|
||||
await Promise.all(
|
||||
Array.from(rawIds).map(async (rawId) => {
|
||||
try {
|
||||
// KBDB GET /blocks/:id 直接 by id (走 list with block_id filter)
|
||||
const r = await fetch(`${KBDB_BASE}/blocks/${rawId}`, { headers });
|
||||
if (r.ok) {
|
||||
const data = await r.json();
|
||||
const b = data.blocks?.[0] ?? data;
|
||||
if (b?.id) rawBlocks.push(b as Block);
|
||||
}
|
||||
} catch { /* skip */ }
|
||||
}),
|
||||
);
|
||||
if (!cancelled) {
|
||||
setBacklinkRaws(rawBlocks.sort((a, b) => b.updated_at - a.updated_at));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: any) {
|
||||
if (!cancelled) setError(e?.message ?? 'load failed');
|
||||
} finally {
|
||||
if (!cancelled) setLoading(false);
|
||||
}
|
||||
}
|
||||
load();
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [decodedName]);
|
||||
|
||||
// 按 facet 分區
|
||||
const facetGroups = useMemo<FacetGroup[]>(() => {
|
||||
const groups: Map<string, Array<{ block: Block; triplets: Block[] }>> = new Map();
|
||||
for (const p of paragraphs) {
|
||||
const facet = extractFacet(p.tags_json) ?? '未分類';
|
||||
const myTrips = triplets.filter((t) => t.parent_id === p.id);
|
||||
if (!groups.has(facet)) groups.set(facet, []);
|
||||
groups.get(facet)!.push({ block: p, triplets: myTrips });
|
||||
}
|
||||
return Array.from(groups.entries()).map(([facet, paragraphs]) => ({ facet, paragraphs }));
|
||||
}, [paragraphs, triplets]);
|
||||
|
||||
const isWikiPage = block?.type === 'wiki-page';
|
||||
// 標題:wiki-page 用 content(entity 名稱),其他(index-entry/schema/log/...)用 page_name 剝 prefix
|
||||
// 修 bug:原本一律用 block.content,但 index-entry 的 content 是整篇 markdown,會把整個 content render 成 h1
|
||||
const entity = isWikiPage
|
||||
? (block?.content?.trim() || decodedName.replace(/^wiki-/, ''))
|
||||
: decodedName.replace(/^(wiki|index)-/, '');
|
||||
|
||||
function toggleCollapse(key: string) {
|
||||
setCollapsed((c) => ({ ...c, [key]: !c[key] }));
|
||||
}
|
||||
|
||||
return (
|
||||
<main className="mira-app">
|
||||
<div className="mira-content mira-wiki-detail">
|
||||
<header style={{ padding: '24px 0 16px', borderBottom: '1px solid #2a2a2a' }}>
|
||||
<Link
|
||||
href="/mira/wiki"
|
||||
style={{ color: '#888', fontSize: 14, textDecoration: 'none' }}
|
||||
>
|
||||
← Wiki 索引
|
||||
</Link>
|
||||
<h1 style={{ fontSize: 28, fontWeight: 700, color: '#fff', margin: '8px 0 4px' }}>
|
||||
{entity}
|
||||
</h1>
|
||||
{block && (
|
||||
<div style={{ color: '#666', fontSize: 12 }}>
|
||||
{block.type} ・ updated {new Date(block.updated_at * 1000).toLocaleString('zh-TW')}
|
||||
</div>
|
||||
)}
|
||||
</header>
|
||||
|
||||
{loading && <div style={{ padding: 24, color: '#666' }}>載入中⋯</div>}
|
||||
{error && <div style={{ padding: 24, color: '#e66' }}>{error}</div>}
|
||||
|
||||
{block && !loading && !error && (
|
||||
<>
|
||||
{/* wiki-page tree view */}
|
||||
{isWikiPage && facetGroups.length > 0 && (
|
||||
<article style={{ padding: '8px 0 24px' }}>
|
||||
{facetGroups.map((group) => (
|
||||
<FacetSection
|
||||
key={group.facet}
|
||||
group={group}
|
||||
entitySet={entitySet}
|
||||
collapsed={collapsed}
|
||||
toggleCollapse={toggleCollapse}
|
||||
/>
|
||||
))}
|
||||
</article>
|
||||
)}
|
||||
|
||||
{/* wiki-page 但沒 children:fallback render content */}
|
||||
{isWikiPage && facetGroups.length === 0 && (
|
||||
<article style={{ padding: '8px 0 24px', color: '#888' }}>
|
||||
<em>尚無段落(wiki_synthesis 還沒跑出 children)</em>
|
||||
<MarkdownView text={block.content} />
|
||||
</article>
|
||||
)}
|
||||
|
||||
{/* 非 wiki-page(schema / index / log / index-entry 等):直接 render content */}
|
||||
{!isWikiPage && (
|
||||
<article style={{ padding: '20px 0' }}>
|
||||
<MarkdownView text={block.content} />
|
||||
</article>
|
||||
)}
|
||||
|
||||
{/* Backlinks:提到此 entity 的 raw notes */}
|
||||
{isWikiPage && backlinkRaws.length > 0 && (
|
||||
<section
|
||||
style={{
|
||||
margin: '24px 0 16px',
|
||||
padding: '12px 14px',
|
||||
borderLeft: '3px solid #4a3a2a',
|
||||
background: 'rgba(80, 60, 40, 0.08)',
|
||||
}}
|
||||
>
|
||||
<h3 style={{ margin: '0 0 8px', fontSize: 14, color: '#aab', fontWeight: 600 }}>
|
||||
📎 提到此 entity 的筆記 ({backlinkRaws.length})
|
||||
</h3>
|
||||
<ul style={{ margin: 0, paddingLeft: 18, fontSize: 13, lineHeight: 1.6 }}>
|
||||
{backlinkRaws.map((raw) => {
|
||||
const preview = (raw.content || '').replace(/\n/g, ' ').slice(0, 100);
|
||||
const href = `/mira/feed#page=${encodeURIComponent(raw.page_name || raw.id)}`;
|
||||
return (
|
||||
<li key={raw.id} style={{ marginBottom: 4 }}>
|
||||
<a
|
||||
href={href}
|
||||
style={{ color: '#9ab', textDecoration: 'none' }}
|
||||
title={raw.content || ''}
|
||||
>
|
||||
{preview}
|
||||
{(raw.content || '').length > 100 && '…'}
|
||||
</a>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
</section>
|
||||
)}
|
||||
|
||||
<footer
|
||||
style={{
|
||||
padding: '20px 0',
|
||||
borderTop: '1px solid #1f1f1f',
|
||||
color: '#555',
|
||||
fontSize: 12,
|
||||
}}
|
||||
>
|
||||
<div>id: <span style={{ fontFamily: 'monospace' }}>{block.id}</span></div>
|
||||
<div>type: {block.type}</div>
|
||||
{block.source && <div>source: {block.source}</div>}
|
||||
{block.parent_id && (
|
||||
<div>
|
||||
parent: <span style={{ fontFamily: 'monospace' }}>{block.parent_id}</span>
|
||||
</div>
|
||||
)}
|
||||
{paragraphs.length > 0 && (
|
||||
<div>
|
||||
{paragraphs.length} paragraph(s) ・ {triplets.length} triplet(s)
|
||||
</div>
|
||||
)}
|
||||
</footer>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
function FacetSection({
|
||||
group,
|
||||
entitySet,
|
||||
collapsed,
|
||||
toggleCollapse,
|
||||
}: {
|
||||
group: FacetGroup;
|
||||
entitySet: Set<string>;
|
||||
collapsed: Record<string, boolean>;
|
||||
toggleCollapse: (key: string) => void;
|
||||
}) {
|
||||
const key = `facet:${group.facet}`;
|
||||
const isCollapsed = collapsed[key] ?? false; // 預設展開(leo 看一篇 wiki 時要看內容)
|
||||
|
||||
return (
|
||||
<section style={{ margin: '16px 0', borderLeft: '3px solid #2a3a4a', paddingLeft: 14 }}>
|
||||
<button
|
||||
onClick={() => toggleCollapse(key)}
|
||||
style={{
|
||||
background: 'transparent',
|
||||
border: 'none',
|
||||
color: '#aab',
|
||||
fontSize: 16,
|
||||
fontWeight: 600,
|
||||
padding: '4px 0',
|
||||
cursor: 'pointer',
|
||||
textAlign: 'left',
|
||||
width: '100%',
|
||||
}}
|
||||
>
|
||||
{isCollapsed ? '▸' : '▾'} {group.facet}
|
||||
<span style={{ color: '#555', fontWeight: 400, fontSize: 13, marginLeft: 8 }}>
|
||||
({group.paragraphs.length})
|
||||
</span>
|
||||
</button>
|
||||
{!isCollapsed &&
|
||||
group.paragraphs.map((p) => (
|
||||
<ParagraphBlock
|
||||
key={p.block.id}
|
||||
block={p.block}
|
||||
triplets={p.triplets}
|
||||
entitySet={entitySet}
|
||||
collapsed={collapsed}
|
||||
toggleCollapse={toggleCollapse}
|
||||
/>
|
||||
))}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function ParagraphBlock({
|
||||
block,
|
||||
triplets,
|
||||
entitySet,
|
||||
collapsed,
|
||||
toggleCollapse,
|
||||
}: {
|
||||
block: Block;
|
||||
triplets: Block[];
|
||||
entitySet: Set<string>;
|
||||
collapsed: Record<string, boolean>;
|
||||
toggleCollapse: (key: string) => void;
|
||||
}) {
|
||||
const tripKey = `trip:${block.id}`;
|
||||
const tripsCollapsed = collapsed[tripKey] ?? true; // triplets 預設折疊
|
||||
|
||||
return (
|
||||
<div style={{ margin: '12px 0 16px', paddingLeft: 4 }}>
|
||||
<div style={{ color: '#ddd', lineHeight: 1.7 }}>
|
||||
<MarkdownView text={block.content} />
|
||||
</div>
|
||||
{triplets.length > 0 && (
|
||||
<div style={{ marginTop: 8 }}>
|
||||
<button
|
||||
onClick={() => toggleCollapse(tripKey)}
|
||||
style={{
|
||||
background: 'transparent',
|
||||
border: 'none',
|
||||
color: '#666',
|
||||
fontSize: 12,
|
||||
padding: '2px 0',
|
||||
cursor: 'pointer',
|
||||
}}
|
||||
>
|
||||
{tripsCollapsed ? '▸' : '▾'} 關係 ({triplets.length})
|
||||
</button>
|
||||
{!tripsCollapsed && (
|
||||
<ul style={{ listStyle: 'none', padding: '4px 0 0 12px', margin: 0 }}>
|
||||
{triplets.map((t) => (
|
||||
<li
|
||||
key={t.id}
|
||||
style={{
|
||||
color: '#888',
|
||||
fontSize: 13,
|
||||
padding: '2px 0',
|
||||
fontFamily: 'monospace',
|
||||
}}
|
||||
>
|
||||
<TripletRender content={t.content} entitySet={entitySet} />
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** Render triplet "A >> 關係 >> B" with A/B linkified if they match an existing wiki entity */
|
||||
function TripletRender({
|
||||
content,
|
||||
entitySet,
|
||||
}: {
|
||||
content: string;
|
||||
entitySet: Set<string>;
|
||||
}) {
|
||||
// 切「>>」分 A / 關係 / B
|
||||
const parts = content.split('>>').map((s) => s.trim());
|
||||
if (parts.length !== 3) {
|
||||
return <>{content}</>;
|
||||
}
|
||||
const [a, rel, b] = parts;
|
||||
return (
|
||||
<>
|
||||
<EntityLink name={a} entitySet={entitySet} />{' '}
|
||||
<span style={{ color: '#666' }}>>> {rel} >></span>{' '}
|
||||
<EntityLink name={b} entitySet={entitySet} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function EntityLink({ name, entitySet }: { name: string; entitySet: Set<string> }) {
|
||||
if (entitySet.has(name)) {
|
||||
return (
|
||||
<Link
|
||||
href={`/mira/wiki/${encodeURIComponent(`wiki-${name}`)}`}
|
||||
style={{ color: '#88c0ff', textDecoration: 'none' }}
|
||||
>
|
||||
{name}
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
return <span style={{ color: '#ccc' }}>{name}</span>;
|
||||
}
|
||||
|
||||
function extractFacet(tags_json: string | null | undefined): string | null {
|
||||
if (!tags_json) return null;
|
||||
try {
|
||||
const tags = JSON.parse(tags_json) as string[];
|
||||
const facetTag = tags.find((t) => t.startsWith('facet:'));
|
||||
return facetTag ? facetTag.slice(6) : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,346 @@
|
||||
'use client';
|
||||
|
||||
// Mira Wiki 索引頁
|
||||
// SDD: polaris/mira/.agents/specs/mira-app/design.md §5.2 + §3.5.10
|
||||
// 對應 task: 7C.1
|
||||
// 階段 7-A 已建:mira-wiki-schema、mira-wiki-index(+4 children)、mira-wiki-log(+1 child)
|
||||
// 此頁列出這些 infra block 與既有 wiki-page,方便 leo 在瀏覽器確認 schema 寫得對不對
|
||||
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import Link from 'next/link';
|
||||
import '../mira.css';
|
||||
|
||||
const KBDB_BASE = 'https://kbdb.finally.click';
|
||||
const API_BASE = process.env.NEXT_PUBLIC_API_BASE ?? 'https://cypher.arcrun.dev';
|
||||
|
||||
type Block = {
|
||||
id: string;
|
||||
page_name: string;
|
||||
content: string;
|
||||
type: string;
|
||||
parent_id: string | null;
|
||||
tags_json: string | null;
|
||||
created_at: number;
|
||||
};
|
||||
|
||||
export default function WikiIndexPage() {
|
||||
const [schema, setSchema] = useState<Block | null>(null);
|
||||
const [indexChildren, setIndexChildren] = useState<Block[]>([]);
|
||||
const [logEntries, setLogEntries] = useState<Block[]>([]);
|
||||
const [otherWikiPages, setOtherWikiPages] = useState<Block[]>([]);
|
||||
const [indexEntries, setIndexEntries] = useState<Block[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
async function load() {
|
||||
try {
|
||||
// 先拿 ak_ partner key(同 page.tsx pattern)
|
||||
const meRes = await fetch(`${API_BASE}/me`, { credentials: 'include' });
|
||||
if (!meRes.ok) throw new Error('未登入');
|
||||
const me = (await meRes.json()) as { api_key: string };
|
||||
const headers = { Authorization: `Bearer ${me.api_key}` };
|
||||
|
||||
// 撈所有 type=wiki-page,再 client 端過濾 tags 含 'mira-wiki'
|
||||
// 原本 ?tag=mira-wiki 撞 KBDB worker D1 bug(malformed JSON),改 type filter
|
||||
// 待 KBDB 修 tag filter 後可改回(SDD 待開 kbdb-tag-filter-fix)
|
||||
const res = await fetch(
|
||||
`${KBDB_BASE}/blocks?type=wiki-page&limit=200`,
|
||||
{ headers },
|
||||
);
|
||||
if (!res.ok) throw new Error(`KBDB ${res.status}`);
|
||||
const data = await res.json();
|
||||
if (cancelled) return;
|
||||
const allWikiBlocks: Block[] = data.blocks ?? [];
|
||||
// Client 端過濾:只留 tags 含 'mira-wiki'
|
||||
const blocks: Block[] = allWikiBlocks.filter((b) => {
|
||||
if (!b.tags_json) return false;
|
||||
try {
|
||||
const tags = JSON.parse(b.tags_json) as string[];
|
||||
return tags.includes('mira-wiki');
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
const tagsOf = (b: Block): string[] => {
|
||||
if (!b.tags_json) return [];
|
||||
try {
|
||||
return JSON.parse(b.tags_json) as string[];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
const hasSubtype = (b: Block, st: string) =>
|
||||
tagsOf(b).includes(`subtype:${st}`);
|
||||
const hasAnyInfraSubtype = (b: Block) =>
|
||||
['schema', 'index', 'index-child', 'log', 'log-child'].some((st) => hasSubtype(b, st));
|
||||
const hasMetaTag = (b: Block) =>
|
||||
tagsOf(b).some((t) => t === 'data-source-config' || t === 'source-skill');
|
||||
|
||||
setSchema(blocks.find((b) => hasSubtype(b, 'schema')) ?? null);
|
||||
setIndexChildren(
|
||||
blocks
|
||||
.filter((b) => hasSubtype(b, 'index-child'))
|
||||
.sort((a, b) => a.page_name.localeCompare(b.page_name)),
|
||||
);
|
||||
setLogEntries(
|
||||
blocks
|
||||
.filter((b) => hasSubtype(b, 'log-child'))
|
||||
.sort((a, b) => b.page_name.localeCompare(a.page_name)),
|
||||
);
|
||||
// 真正的 wiki-page paragraphs(排除 infra 跟 meta 配置)
|
||||
setOtherWikiPages(
|
||||
blocks
|
||||
.filter((b) => !hasAnyInfraSubtype(b) && !hasMetaTag(b))
|
||||
.sort((a, b) => (b.created_at ?? 0) - (a.created_at ?? 0)),
|
||||
);
|
||||
|
||||
// 平行撈 index-entry blocks(per-entity 摘要,CC navigation entry point)
|
||||
// 對應 design.md §3.5.12.4.1 / 7B.3f
|
||||
const idxRes = await fetch(
|
||||
`${KBDB_BASE}/blocks?type=index-entry&limit=200`,
|
||||
{ headers },
|
||||
);
|
||||
if (idxRes.ok) {
|
||||
const idxData = await idxRes.json();
|
||||
if (!cancelled) {
|
||||
const idxBlocks: Block[] = idxData.blocks ?? [];
|
||||
setIndexEntries(
|
||||
idxBlocks.sort((a, b) => (a.page_name ?? '').localeCompare(b.page_name ?? '')),
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (e: any) {
|
||||
if (!cancelled) setError(e?.message ?? 'load failed');
|
||||
} finally {
|
||||
if (!cancelled) setLoading(false);
|
||||
}
|
||||
}
|
||||
load();
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, []);
|
||||
|
||||
// Dedupe wiki-pages by entity(content)— 累積式設計每個 raw 各建一個 wiki-page,
|
||||
// 同 entity 多版只在 listing 顯示最新一張卡 + 版本數提示
|
||||
const dedupedWikiPages = useMemo(() => {
|
||||
const groups = new Map<string, { entity: string; latest: Block; versionCount: number }>();
|
||||
for (const p of otherWikiPages) {
|
||||
const entity = (p.content || '').trim() || p.page_name || '?';
|
||||
const existing = groups.get(entity);
|
||||
if (!existing) {
|
||||
groups.set(entity, { entity, latest: p, versionCount: 1 });
|
||||
} else {
|
||||
existing.versionCount++;
|
||||
if ((p.created_at ?? 0) > (existing.latest.created_at ?? 0)) {
|
||||
existing.latest = p;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Array.from(groups.values()).sort(
|
||||
(a, b) => (b.latest.created_at ?? 0) - (a.latest.created_at ?? 0),
|
||||
);
|
||||
}, [otherWikiPages]);
|
||||
|
||||
return (
|
||||
<main className="mira-app">
|
||||
<div className="mira-content">
|
||||
<header style={{ padding: '24px 0 16px', borderBottom: '1px solid #2a2a2a' }}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 12, marginBottom: 4 }}>
|
||||
<Link
|
||||
href="/mira"
|
||||
style={{ color: '#888', fontSize: 14, textDecoration: 'none' }}
|
||||
>
|
||||
← Mira 首頁
|
||||
</Link>
|
||||
</div>
|
||||
<h1 style={{ fontSize: 28, fontWeight: 700, color: '#fff', margin: 0 }}>
|
||||
📚 Mira Wiki
|
||||
</h1>
|
||||
<p style={{ color: '#888', fontSize: 14, marginTop: 4 }}>
|
||||
leo 的個人觀點累積(Karpathy LLM Wiki 風格)
|
||||
</p>
|
||||
</header>
|
||||
|
||||
{loading && <div style={{ padding: 24, color: '#666' }}>載入中⋯</div>}
|
||||
{error && (
|
||||
<div style={{ padding: 24, color: '#e66' }}>讀取失敗:{error}</div>
|
||||
)}
|
||||
|
||||
{!loading && !error && (
|
||||
<>
|
||||
<Section title="📋 Schema(合成規則)">
|
||||
{schema ? (
|
||||
<WikiCardLink page_name={schema.page_name} title="mira-wiki-schema" excerpt="ingest 規則手冊:cypher binding、17 predicates、entity normalize⋯" />
|
||||
) : (
|
||||
<Empty>尚未建立 schema</Empty>
|
||||
)}
|
||||
</Section>
|
||||
|
||||
<Section title="🗂 Index(4 個分類)">
|
||||
{indexChildren.length > 0 ? (
|
||||
<div style={{ display: 'grid', gap: 8 }}>
|
||||
{indexChildren.map((b) => {
|
||||
const tags = b.tags_json ? (JSON.parse(b.tags_json) as string[]) : [];
|
||||
const key = tags.find((t) => t.startsWith('index-key:'))?.replace('index-key:', '') ?? '?';
|
||||
return (
|
||||
<WikiCardLink
|
||||
key={b.id}
|
||||
page_name={b.page_name}
|
||||
title={`${iconForKey(key)} ${key}`}
|
||||
excerpt={firstLineOf(b.content)}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
<Empty>index children 尚未建立</Empty>
|
||||
)}
|
||||
</Section>
|
||||
|
||||
<Section title={`🧭 Index Entries(${indexEntries.length})— CC 看的 entity 摘要`}>
|
||||
{indexEntries.length > 0 ? (
|
||||
<div style={{ display: 'grid', gap: 8 }}>
|
||||
{indexEntries.map((b) => {
|
||||
const entity = (b.page_name ?? '').replace(/^index-/, '');
|
||||
const firstLine = firstLineOf(b.content)
|
||||
.replace(/^#+\s*/, '')
|
||||
.slice(0, 80);
|
||||
return (
|
||||
<WikiCardLink
|
||||
key={b.id}
|
||||
page_name={b.page_name ?? ''}
|
||||
title={entity}
|
||||
excerpt={firstLine || `index for ${entity}`}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
<Empty>尚未有 index-entry(wiki_synthesis 跑完後自動建)</Empty>
|
||||
)}
|
||||
</Section>
|
||||
|
||||
<Section title="📜 Log(每月一筆)">
|
||||
{logEntries.length > 0 ? (
|
||||
<div style={{ display: 'grid', gap: 8 }}>
|
||||
{logEntries.map((b) => (
|
||||
<WikiCardLink
|
||||
key={b.id}
|
||||
page_name={b.page_name}
|
||||
title={b.page_name}
|
||||
excerpt={firstLineOf(b.content)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<Empty>尚未有 log</Empty>
|
||||
)}
|
||||
</Section>
|
||||
|
||||
<Section title={`📖 Wiki Pages(${dedupedWikiPages.length},原 ${otherWikiPages.length} 筆累積版本)`}>
|
||||
{dedupedWikiPages.length > 0 ? (
|
||||
<div style={{ display: 'grid', gap: 8 }}>
|
||||
{dedupedWikiPages.map((g) => (
|
||||
<WikiCardLink
|
||||
key={g.latest.id}
|
||||
page_name={g.latest.page_name}
|
||||
title={g.entity}
|
||||
excerpt={
|
||||
g.versionCount > 1
|
||||
? `${g.versionCount} 版累積 ・ 最新 ${new Date((g.latest.created_at ?? 0) * 1000).toLocaleString('zh-TW')}`
|
||||
: `建立 ${new Date((g.latest.created_at ?? 0) * 1000).toLocaleString('zh-TW')}`
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<Empty>尚未有 wiki page(待 7-B ai-canon-wiki workflow 跑出第一張)</Empty>
|
||||
)}
|
||||
</Section>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
function Section({ title, children }: { title: string; children: React.ReactNode }) {
|
||||
return (
|
||||
<section style={{ padding: '20px 0', borderBottom: '1px solid #1f1f1f' }}>
|
||||
<h2 style={{ fontSize: 16, fontWeight: 600, color: '#ddd', marginBottom: 12 }}>
|
||||
{title}
|
||||
</h2>
|
||||
{children}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function Empty({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<div style={{ color: '#555', fontStyle: 'italic', fontSize: 13 }}>{children}</div>
|
||||
);
|
||||
}
|
||||
|
||||
function WikiCardLink({
|
||||
page_name,
|
||||
title,
|
||||
excerpt,
|
||||
}: {
|
||||
page_name: string;
|
||||
title: string;
|
||||
excerpt: string;
|
||||
}) {
|
||||
return (
|
||||
<Link
|
||||
href={`/mira/wiki/${encodeURIComponent(page_name)}`}
|
||||
style={{
|
||||
display: 'block',
|
||||
padding: '12px 14px',
|
||||
background: '#1a1a1a',
|
||||
border: '1px solid #2a2a2a',
|
||||
borderRadius: 6,
|
||||
textDecoration: 'none',
|
||||
color: 'inherit',
|
||||
}}
|
||||
>
|
||||
<div style={{ color: '#ddd', fontWeight: 500, marginBottom: 4 }}>{title}</div>
|
||||
{excerpt && (
|
||||
<div
|
||||
style={{
|
||||
color: '#888',
|
||||
fontSize: 13,
|
||||
overflow: 'hidden',
|
||||
textOverflow: 'ellipsis',
|
||||
whiteSpace: 'nowrap',
|
||||
}}
|
||||
>
|
||||
{excerpt}
|
||||
</div>
|
||||
)}
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
|
||||
function iconForKey(key: string): string {
|
||||
return (
|
||||
{
|
||||
entities: '🧩',
|
||||
topics: '📂',
|
||||
sources: '🔗',
|
||||
stale: '⚠️',
|
||||
}[key] ?? '•'
|
||||
);
|
||||
}
|
||||
|
||||
function firstLineOf(content: string): string {
|
||||
if (!content) return '';
|
||||
const firstNonHeader = content
|
||||
.split('\n')
|
||||
.map((l) => l.trim())
|
||||
.find((l) => l && !l.startsWith('#') && !l.startsWith('>'));
|
||||
return firstNonHeader ?? '';
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
'use client';
|
||||
|
||||
import { useState, useEffect } from 'react';
|
||||
import Link from 'next/link';
|
||||
import SiteNav from './components/SiteNav';
|
||||
|
||||
const API_BASE = process.env.NEXT_PUBLIC_API_BASE ?? 'https://cypher.arcrun.dev';
|
||||
|
||||
const CODE_DEMOS = {
|
||||
python: `pip install arcrun
|
||||
|
||||
from arcrun import Arcrun
|
||||
|
||||
client = Arcrun() # reads ARCRUN_API_KEY from env
|
||||
|
||||
# One-time setup: upload credential
|
||||
client.auth.setup("notion", token="secret_xxx")
|
||||
|
||||
# Every time after: just bind and use
|
||||
notion = client.auth.bind("notion")
|
||||
pages = notion.get("/pages").json()
|
||||
|
||||
# Works with any of 20+ services
|
||||
drive = client.auth.bind("google_drive_sa")
|
||||
files = drive.get("/files").json()`,
|
||||
|
||||
javascript: `npm install arcrun
|
||||
|
||||
import { Arcrun } from 'arcrun'
|
||||
|
||||
const client = new Arcrun() // reads ARCRUN_API_KEY from env
|
||||
|
||||
// One-time setup: upload credential
|
||||
await client.auth.setup('notion', { token: 'secret_xxx' })
|
||||
|
||||
// Every time after: just bind and use
|
||||
const notion = await client.auth.bind('notion')
|
||||
const pages = await (await notion.get('/pages')).json()
|
||||
|
||||
// Run a deployed workflow
|
||||
const result = await client.workflows.run('my-flow', {
|
||||
email: 'user@example.com'
|
||||
})`,
|
||||
|
||||
http: `# Works with any HTTP tool — curl, n8n, Make, Postman
|
||||
POST ${API_BASE}/webhooks/named/my-workflow/trigger
|
||||
X-Arcrun-API-Key: YOUR_API_KEY
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"email": "user@example.com"
|
||||
}
|
||||
|
||||
# n8n: HTTP Request 節點,貼上即用,不需要安裝任何東西`,
|
||||
};
|
||||
|
||||
export default function HomePage() {
|
||||
const [activeTab, setActiveTab] = useState<'python' | 'javascript' | 'http'>('python');
|
||||
const [isLoggedIn, setIsLoggedIn] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
fetch(`${API_BASE}/me`, { credentials: 'include' })
|
||||
.then(r => { if (r.ok) setIsLoggedIn(true); })
|
||||
.catch(() => {});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col min-h-screen bg-[#0a0a0a] text-[#ededed]">
|
||||
<SiteNav currentPath="/" />
|
||||
|
||||
{/* Hero */}
|
||||
<section className="flex flex-col items-center text-center px-6 pt-24 pb-16">
|
||||
<div className="inline-flex items-center gap-2 bg-[#1a1a2e] text-indigo-400 text-xs px-3 py-1 rounded-full mb-6 border border-indigo-900/50">
|
||||
<span className="w-1.5 h-1.5 bg-indigo-400 rounded-full animate-pulse inline-block"></span>
|
||||
Open Source · Free API Key · No Credit Card
|
||||
</div>
|
||||
|
||||
<h1 className="text-5xl md:text-6xl font-bold text-white mb-4 leading-tight max-w-3xl">
|
||||
Stop fighting OAuth.
|
||||
</h1>
|
||||
<p className="text-xl md:text-2xl text-[#888] mb-3 max-w-2xl">
|
||||
One API key. Every service. Works anywhere.
|
||||
</p>
|
||||
<p className="text-[#555] max-w-xl mb-10">
|
||||
arcrun handles Google, Notion, GitHub, Slack authentication
|
||||
so your Python / JS code doesn't have to.
|
||||
</p>
|
||||
|
||||
<div className="flex gap-3 flex-wrap justify-center">
|
||||
<Link href={isLoggedIn ? '/dashboard' : '/login'}
|
||||
className="bg-indigo-600 hover:bg-indigo-500 text-white px-6 py-3 rounded-lg font-medium transition-colors">
|
||||
{isLoggedIn ? 'Go to Dashboard' : 'Get API Key — Free'}
|
||||
</Link>
|
||||
<a href="https://github.com/richblack/arcrun" target="_blank" rel="noopener noreferrer"
|
||||
className="border border-[#333] hover:border-[#555] text-[#aaa] hover:text-white px-6 py-3 rounded-lg font-medium transition-colors">
|
||||
View on GitHub
|
||||
</a>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* Before / After */}
|
||||
<section className="max-w-4xl mx-auto px-6 pb-16 w-full">
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-4 items-center">
|
||||
<div className="bg-[#111] border border-[#222] rounded-xl p-6">
|
||||
<div className="text-[#555] text-xs mb-3 font-mono uppercase tracking-wider">Before</div>
|
||||
<div className="text-red-400 text-sm font-mono space-y-1 opacity-70">
|
||||
<div>40 行 OAuth 程式碼</div>
|
||||
<div>GCP Console 設定</div>
|
||||
<div>debug 兩天</div>
|
||||
<div>Service Account JSON</div>
|
||||
<div>token 過期再修一次</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center justify-center text-[#333] text-4xl font-thin select-none">→</div>
|
||||
<div className="bg-[#111] border border-indigo-900/50 rounded-xl p-6">
|
||||
<div className="text-indigo-400 text-xs mb-3 font-mono uppercase tracking-wider">After</div>
|
||||
<pre className="text-green-400 text-sm font-mono leading-relaxed">
|
||||
{`from arcrun import auth
|
||||
|
||||
drive = auth.bind(
|
||||
"google_drive"
|
||||
)
|
||||
# done.`}
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* Code Demo */}
|
||||
<section className="max-w-3xl mx-auto px-6 pb-20 w-full">
|
||||
<div className="bg-[#111] border border-[#222] rounded-xl overflow-hidden">
|
||||
<div className="flex border-b border-[#1e1e1e]">
|
||||
{(['python', 'javascript', 'http'] as const).map(tab => (
|
||||
<button
|
||||
key={tab}
|
||||
onClick={() => setActiveTab(tab)}
|
||||
className={`px-5 py-3 text-sm font-medium transition-colors cursor-pointer ${
|
||||
activeTab === tab
|
||||
? 'text-white border-b-2 border-indigo-500 bg-[#0d0d1a]'
|
||||
: 'text-[#555] hover:text-[#aaa]'
|
||||
}`}
|
||||
>
|
||||
{tab === 'python' ? 'Python' : tab === 'javascript' ? 'JavaScript' : 'HTTP / n8n'}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<div className="p-6 overflow-x-auto">
|
||||
<pre className="text-sm text-[#cdd6f4] leading-relaxed">
|
||||
<code>{CODE_DEMOS[activeTab]}</code>
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
{activeTab === 'http' && (
|
||||
<p className="text-[#444] text-sm mt-3 text-center">
|
||||
n8n 用戶:用 HTTP Request 節點,不需要安裝任何東西
|
||||
</p>
|
||||
)}
|
||||
</section>
|
||||
|
||||
{/* Features */}
|
||||
<section className="max-w-4xl mx-auto px-6 pb-20 w-full">
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-6">
|
||||
{[
|
||||
{ title: '20+ 服務開箱即用', desc: 'Google、Notion、GitHub、Slack、OpenAI、Stripe... 全部一個 bind() 搞定。', icon: '🔌' },
|
||||
{ title: 'AI-first 設計', desc: 'Token 消耗極小,YAML workflow 幾十個 token,讓 AI 直接讀寫執行。', icon: '🤖' },
|
||||
{ title: '完全開源', desc: 'MIT 授權。Self-host 在你自己的 Cloudflare,或使用我們的 hosted 服務。', icon: '🔓' },
|
||||
].map(f => (
|
||||
<div key={f.title} className="bg-[#111] border border-[#1e1e1e] rounded-xl p-6">
|
||||
<div className="text-2xl mb-3">{f.icon}</div>
|
||||
<h3 className="text-white font-semibold mb-2">{f.title}</h3>
|
||||
<p className="text-[#555] text-sm leading-relaxed">{f.desc}</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* CTA */}
|
||||
<section className="border-t border-[#1a1a1a] py-16 text-center px-6">
|
||||
<h2 className="text-3xl font-bold text-white mb-3">準備好了嗎?</h2>
|
||||
<p className="text-[#555] mb-8">免費取得 API Key,不需要信用卡。</p>
|
||||
<Link href={isLoggedIn ? '/dashboard' : '/login'}
|
||||
className="bg-indigo-600 hover:bg-indigo-500 text-white px-8 py-3 rounded-lg font-medium transition-colors">
|
||||
{isLoggedIn ? 'Go to Dashboard' : '免費取得 API Key'}
|
||||
</Link>
|
||||
</section>
|
||||
|
||||
{/* Footer */}
|
||||
<footer className="border-t border-[#1a1a1a] py-8 px-6 text-center text-[#333] text-sm mt-auto">
|
||||
<div className="flex items-center justify-center gap-6">
|
||||
<Link href="/integrations" className="hover:text-[#777] transition-colors">Integrations</Link>
|
||||
<Link href="/api-docs" className="hover:text-[#777] transition-colors">API Docs</Link>
|
||||
<a href="https://github.com/richblack/arcrun" target="_blank" rel="noopener noreferrer"
|
||||
className="hover:text-[#777] transition-colors">GitHub</a>
|
||||
</div>
|
||||
<p className="mt-4">arcrun — MIT License</p>
|
||||
</footer>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user