feat: add HoloLake folder import and official assistant
This commit is contained in:
parent
46bdd0ca73
commit
a360982a9b
12 changed files with 507 additions and 76 deletions
|
|
@ -18,6 +18,8 @@ export default function App() {
|
|||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [agentPanelOpen, setAgentPanelOpen] = useState(true);
|
||||
const [importing, setImporting] = useState(false);
|
||||
const [importMessage, setImportMessage] = useState<string | null>(null);
|
||||
|
||||
const refreshTree = useCallback(async () => {
|
||||
try {
|
||||
|
|
@ -85,6 +87,38 @@ export default function App() {
|
|||
}
|
||||
}, [currentPath, refreshTree]);
|
||||
|
||||
const importFolder = useCallback(async () => {
|
||||
const bridge = (window as any).hololake?.knowledge;
|
||||
if (!bridge?.importFolder) {
|
||||
setError('本地文件夹导入只在 HoloLake 桌面 App 中提供');
|
||||
return;
|
||||
}
|
||||
setImporting(true);
|
||||
setError(null);
|
||||
setImportMessage(null);
|
||||
try {
|
||||
const result = await bridge.importFolder();
|
||||
if (result.cancelled) return;
|
||||
if (!result.imported) {
|
||||
setImportMessage(`没有找到可导入的文档;已跳过 ${result.skipped || 0} 个文件`);
|
||||
return;
|
||||
}
|
||||
await refreshTree();
|
||||
if (result.firstDocument) await openDoc(result.firstDocument);
|
||||
const details = [
|
||||
`已导入 ${result.imported} 篇文档`,
|
||||
result.assets ? `${result.assets} 个图片资源` : '',
|
||||
result.skipped ? `跳过 ${result.skipped} 个暂不支持的文件` : '',
|
||||
result.failed?.length ? `${result.failed.length} 个文件失败` : '',
|
||||
].filter(Boolean).join(' · ');
|
||||
setImportMessage(details);
|
||||
} catch (err: any) {
|
||||
setError(`导入失败: ${err.message}`);
|
||||
} finally {
|
||||
setImporting(false);
|
||||
}
|
||||
}, [openDoc, refreshTree]);
|
||||
|
||||
useEffect(() => {
|
||||
refreshTree();
|
||||
}, [refreshTree]);
|
||||
|
|
@ -101,7 +135,11 @@ export default function App() {
|
|||
>
|
||||
{sidebarOpen ? '◀' : '▶'}
|
||||
</button>
|
||||
<h1 className="kb-title">光湖知识库</h1>
|
||||
<div className="kb-brand-mark" aria-hidden="true" />
|
||||
<div>
|
||||
<h1 className="kb-title">HoloLake</h1>
|
||||
<div className="kb-subtitle">知识空间</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="kb-header-center">
|
||||
<SearchBar onSelect={openDoc} />
|
||||
|
|
@ -131,7 +169,7 @@ export default function App() {
|
|||
onClick={() => setAgentPanelOpen(!agentPanelOpen)}
|
||||
title={agentPanelOpen ? '收起 Agent' : '展开 Agent'}
|
||||
>
|
||||
🌊 Agent
|
||||
HoloLake 助手
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
|
@ -141,11 +179,18 @@ export default function App() {
|
|||
{/* 侧栏 */}
|
||||
{sidebarOpen && (
|
||||
<aside className="kb-sidebar">
|
||||
<div className="kb-workspace-label">当前空间</div>
|
||||
<div className="kb-sidebar-actions">
|
||||
<button className="kb-btn-small" onClick={() => createDoc('')}>
|
||||
+ 根目录文档
|
||||
<button className="kb-btn-import" onClick={importFolder} disabled={importing}>
|
||||
<span className="kb-btn-import-icon">↥</span>
|
||||
{importing ? '正在导入…' : '导入本地文件夹'}
|
||||
</button>
|
||||
<button className="kb-btn-new" onClick={() => createDoc('')}>
|
||||
<span>+</span> 新建页面
|
||||
</button>
|
||||
</div>
|
||||
{importMessage && <div className="kb-import-message">{importMessage}</div>}
|
||||
<div className="kb-tree-heading">页面</div>
|
||||
<DocTree
|
||||
nodes={tree}
|
||||
currentPath={currentPath}
|
||||
|
|
@ -166,9 +211,16 @@ export default function App() {
|
|||
{loading && <div className="kb-loading">加载中...</div>}
|
||||
{!currentDoc && !loading && (
|
||||
<div className="kb-empty">
|
||||
<div className="kb-empty-icon">📖</div>
|
||||
<p>选择左侧文档开始阅读</p>
|
||||
<p className="kb-empty-hint">或点击「+ 根目录文档」创建新文档</p>
|
||||
<div className="kb-empty-card">
|
||||
<div className="kb-empty-orbit"><span /></div>
|
||||
<p className="kb-empty-eyebrow">HOLOLAKE KNOWLEDGE</p>
|
||||
<h2>把已有资料带进知识空间</h2>
|
||||
<p>选择一个本地文件夹。HoloLake 会把可读文档整理成页面,并为这次导入保留 Git 版本记录。</p>
|
||||
<button className="kb-empty-primary" onClick={importFolder} disabled={importing}>
|
||||
{importing ? '正在导入…' : '选择本地文件夹'}
|
||||
</button>
|
||||
<div className="kb-empty-support">支持 Markdown、TXT、CSV、JSON 与 YAML</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{currentDoc && view === 'editor' && (
|
||||
|
|
|
|||
Loading…
Reference in a new issue