From e0d1dc4be69671923d7c3e293ce67e3b60c266fb Mon Sep 17 00:00:00 2001 From: weipengzhe <3389096668@qq.com> Date: Mon, 23 Nov 2026 16:34:49 +0800 Subject: [PATCH] Add an AI-powered library for uploaded open-source projects --- .env.pcb.example | 2 + PCB-SERVICE.md | 2 + designer/src/codex-pcb/CodexPcbDock.tsx | 2 +- designer/src/platform/PlatformApp.tsx | 13 +- designer/src/platform/ProjectList.tsx | 3 + .../src/project-library/ProjectLibrary.tsx | 116 +++++ .../src/project-library/ProjectReport.tsx | 117 +++++ .../src/project-library/SourcePreview.tsx | 59 +++ designer/src/project-library/api.ts | 53 +++ .../src/project-library/project-library.css | 93 ++++ designer/vite.config.ts | 7 +- integration/nginx.example.conf | 11 + integration/vibemake-project-library.service | 17 + project_library/.env.example | 9 + project_library/README.md | 15 + project_library/__init__.py | 1 + project_library/app.py | 242 ++++++++++ project_library/auth.py | 36 ++ project_library/engine.py | 416 ++++++++++++++++++ project_library/evidence.py | 398 +++++++++++++++++ project_library/storage.py | 266 +++++++++++ project_library/tests/test_api.py | 101 +++++ project_library/tests/test_evidence.py | 79 ++++ project_library/tests/test_storage.py | 82 ++++ scripts/serve.mjs | 14 +- 25 files changed, 2145 insertions(+), 9 deletions(-) create mode 100644 designer/src/project-library/ProjectLibrary.tsx create mode 100644 designer/src/project-library/ProjectReport.tsx create mode 100644 designer/src/project-library/SourcePreview.tsx create mode 100644 designer/src/project-library/api.ts create mode 100644 designer/src/project-library/project-library.css create mode 100644 integration/vibemake-project-library.service create mode 100644 project_library/.env.example create mode 100644 project_library/README.md create mode 100644 project_library/__init__.py create mode 100644 project_library/app.py create mode 100644 project_library/auth.py create mode 100644 project_library/engine.py create mode 100644 project_library/evidence.py create mode 100644 project_library/storage.py create mode 100644 project_library/tests/test_api.py create mode 100644 project_library/tests/test_evidence.py create mode 100644 project_library/tests/test_storage.py diff --git a/.env.pcb.example b/.env.pcb.example index 69d0f17..4a26c86 100644 --- a/.env.pcb.example +++ b/.env.pcb.example @@ -2,6 +2,8 @@ # Persistent Codex PCB session backend. Override when using a remote installation. PCB_API_TARGET=http://39.105.93.138:8003 PCB_API_ORIGIN=http://127.0.0.1:5173 +# Open-source project library, independent of PCB design jobs: +PCB_LIBRARY_TARGET=http://127.0.0.1:8004 # Account and platform project API, independent of the AI task service: API_TARGET=https://dev-vibemake-api.robotquan.com HOST=127.0.0.1 diff --git a/PCB-SERVICE.md b/PCB-SERVICE.md index 1eaafda..80417da 100644 --- a/PCB-SERVICE.md +++ b/PCB-SERVICE.md @@ -2,6 +2,8 @@ 当前 AI 入口使用新的持久化 Codex 会话服务 `codex_pcb.app`。架构、运行依赖、审核和交付协议见 [CODEX-SESSION.md](CODEX-SESSION.md)。旧 `backend/` 中的固定设计流程及 `backend/providers/codex.py` 不再是网站默认执行入口,旧任务不会自动迁移到新会话。 +开源项目库通过独立服务分析用户上传的 ZIP。部署依赖、账号验证、上传限制及运行方式见[开源项目库部署说明](project_library/README.md)。 + ## 本地前端与代理 要求 Node.js 20+(建议 22 LTS)、npm,以及可访问的新会话后台。 diff --git a/designer/src/codex-pcb/CodexPcbDock.tsx b/designer/src/codex-pcb/CodexPcbDock.tsx index 2d88e55..7be376f 100644 --- a/designer/src/codex-pcb/CodexPcbDock.tsx +++ b/designer/src/codex-pcb/CodexPcbDock.tsx @@ -117,7 +117,7 @@ function ConnectedCodexPcbDock(): JSX.Element { {!open ? <>
setOpened(true)}/>
:
AI PCB 工作台从想法到真实电路板
-
+
{active && task && }
diff --git a/designer/src/platform/PlatformApp.tsx b/designer/src/platform/PlatformApp.tsx index 58b9504..6c55a89 100644 --- a/designer/src/platform/PlatformApp.tsx +++ b/designer/src/platform/PlatformApp.tsx @@ -41,6 +41,7 @@ import type { Route } from '../nav/route.js'; import { PlatformErrorBoundary } from './PlatformErrorBoundary.js'; import { setUiLanguage } from '@ziroeda/common/i18n.js'; const CodexPcbDock = lazy(() => import('../codex-pcb/CodexPcbDock.js').then(m => ({ default: m.CodexPcbDock }))); +const ProjectLibrary = lazy(() => import('../project-library/ProjectLibrary.js')); const EditorHost = lazy(() => import('./EditorHost.js')); const BASE = import.meta.env.BASE_URL; const BUILD = typeof __BUILD_STAMP__ === 'undefined' ? 'dev' : __BUILD_STAMP__; @@ -130,6 +131,7 @@ function Workspace({ } }); const [route, setRoute] = useState(initial.route); + const projectLibrary = !route.code && new URLSearchParams(location.search).get('library') === '1'; const [invalidRoute, setInvalidRoute] = useState(initial.error); const routeRef = useRef(route); const historyIndex = useRef(Number(history.state?.vmPcbIndex) || 0); @@ -308,9 +310,10 @@ function Workspace({ }; }, [leave]); useEffect(() => { - if (!route.code) + if (projectLibrary) document.title = locale === 'zh' ? '开源项目库 | VibeMake' : 'Open-source library | VibeMake'; + else if (!route.code) document.title = locale === 'zh' ? '我的 PCB 项目 | VibeMake' : 'My PCB projects | VibeMake'; - }, [route.code, locale]); + }, [route.code, locale, projectLibrary]); useEffect(() => { runtime?.setLocked(!allowed || auth.status !== 'authenticated' || !api); }, [runtime, allowed, auth.status, api]); @@ -686,6 +689,10 @@ function Workspace({ {tr('登录并开始设计', 'Sign in to start designing')}
+ ) : projectLibrary && auth.record ? ( + {tr('正在打开项目库…', 'Loading library…')}}> + + ) : error ? (

{tr('工程加载失败', 'Could not load project')}

@@ -727,7 +734,7 @@ function Workspace({ importProject={create} /> )} - {(activeWorkbench || new URLSearchParams(location.search).get('ai') === '1') && allowed && api && auth.status === 'authenticated' && ( + {!projectLibrary && (activeWorkbench || new URLSearchParams(location.search).get('ai') === '1') && allowed && api && auth.status === 'authenticated' && ( diff --git a/designer/src/platform/ProjectList.tsx b/designer/src/platform/ProjectList.tsx index 87a0dc8..99003de 100644 --- a/designer/src/platform/ProjectList.tsx +++ b/designer/src/platform/ProjectList.tsx @@ -118,6 +118,9 @@ export function ProjectList({

{tr('我的 PCB 项目', 'My PCB projects')}

+ + {tr('开源项目库', 'Open-source library')} + +
+ { const file = e.target.files?.[0]; e.target.value = ''; void upload(file); }} /> + + {uploadError &&

{uploadError}

} +
+ + {visible ? pickFile(visible.project_id)} uploading={busy} revision={revision} refresh={() => refresh(v => v + 1)} /> + :

{loading || (query && !matches && !searchError) ? '正在读取项目' : query ? '未找到匹配项目' : !error ? '上传第一个开源项目' : '暂时无法读取项目'}

+

{query ? '可以搜索项目名称、器件或文件。' : '支持包含硬件工程、文档和源代码的 ZIP,单个文件上限为 100 MiB。'}

+ {!query && !loading && !error && }
} +
+ ; +} diff --git a/designer/src/project-library/ProjectReport.tsx b/designer/src/project-library/ProjectReport.tsx new file mode 100644 index 0000000..8e22bbf --- /dev/null +++ b/designer/src/project-library/ProjectReport.tsx @@ -0,0 +1,117 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +import { useEffect, useRef, useState } from 'react'; +import { active, download, humanError, json, projectPath, type Answer, type Category, type Evidence, type Project, type ProjectDetail } from './api.js'; +import { SourcePreview } from './SourcePreview.js'; + +const categories: { key: Category; label: string }[] = [ + { key: 'component', label: '器件' }, { key: 'drawing', label: '图纸' }, { key: 'code', label: '代码' }, + { key: 'license', label: '许可证' }, { key: 'gap', label: '待核实' }, +]; +function size(bytes: number) { + if (bytes < 1024) return bytes + ' B'; + if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + ' KiB'; + return (bytes / 1024 / 1024).toFixed(1) + ' MiB'; +} +function Sources({ evidence, open }: { evidence: Evidence[]; open(source: Evidence): void }) { + return
{evidence.map((item, i) => + )}
; +} +export function ProjectReport({ token, row, versions, select, uploadVersion, uploading, revision, refresh }: { + token: string; row: Project; versions: Project[]; select(id: string): void; uploadVersion(): void; + uploading: boolean; revision: number; refresh(): void; +}) { + const [detail, setDetail] = useState(null); + const [error, setError] = useState(''); + const [saveError, setSaveError] = useState(''); + const [busy, setBusy] = useState(false); + const [retrying, setRetrying] = useState(false); + const [tab, setTab] = useState<'report' | 'files' | 'qa'>('report'); + const [category, setCategory] = useState('component'); + const [fileQuery, setFileQuery] = useState(''); + const [limit, setLimit] = useState(100); + const [source, setSource] = useState(null); + const [question, setQuestion] = useState(''); + const [history, setHistory] = useState<{ question: string; answer: Answer }[]>([]); + const [asking, setAsking] = useState(false); + const [askError, setAskError] = useState(''); + const questionRequest = useRef(); + const path = projectPath(row.id); + useEffect(() => { + const controller = new AbortController(); + void json(token, path, { signal: controller.signal }) + .then(result => { if (!controller.signal.aborted) { setDetail(result); setError(''); } }) + .catch(err => { if (!controller.signal.aborted) setError(humanError(err)); }); + return () => controller.abort(); + }, [token, path, revision, row.status, row.stage]); + useEffect(() => () => questionRequest.current?.abort(), []); + const current = detail || row; + const report = detail?.report; + const files = detail?.files || []; + const findings = report?.groups.filter(group => group.category === category) || []; + const filtered = files.filter(file => file.path.toLowerCase().includes(fileQuery.trim().toLowerCase())); + async function archive() { + setBusy(true); setSaveError(''); + try { await download(token, path + '/archive', detail?.archive_name || row.name + '.zip'); } + catch (err) { setSaveError(humanError(err)); } + finally { setBusy(false); } + } + async function retry() { + setRetrying(true); setError(''); + try { setDetail(await json(token, path + '/retry', { method: 'POST' })); refresh(); } + catch (err) { setError(humanError(err)); } + finally { setRetrying(false); } + } + async function ask() { + const prompt = question.trim(); + if (!prompt || questionRequest.current) return; + const controller = new AbortController(); + questionRequest.current = controller; setAsking(true); setAskError(''); + try { + const answer = await json(token, path + '/questions', { + method: 'POST', signal: controller.signal, headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ question: prompt }), + }); + if (!controller.signal.aborted) { setHistory(old => [...old, { question: prompt, answer }]); setQuestion(''); } + } catch (err) { if (!controller.signal.aborted) setAskError(humanError(err)); } + finally { questionRequest.current = undefined; if (!controller.signal.aborted) setAsking(false); } + } + return
+

{row.name}

+

上传 · {current.file_count} 个文件

+
+
+ + {detail?.archive_name}
+ {saveError &&

{saveError}

} + {error &&

{error}

} + {active(current) &&
{current.status === 'queued' ? '已加入分析队列' : 'AI 正在分析项目'} + {current.stage || '进度将自动更新。'}
} + {current.status === 'failed' &&
此次分析未完成{current.error || '未收到详细原因,请重新分析。'} +
} + + {tab === 'report' && (report ?
+

项目概览

{report.summary || '当前资料未给出项目概述。'}

+
{categories.map(c => )}
+
{findings.map((g,i) =>

{g.name}

{g.scope && {g.scope}} +

{g.detail}

{g.evidence?.length > 0 && }
)} + {!findings.length &&

本版本暂未识别到此类条目。

}
+ {!!report.limitations?.length &&
分析范围与局限({report.limitations.length})
    {report.limitations.map((item,i) =>
  • {item}
  • )}
} +
:

{!detail && !error ? '正在读取版本…' : active(current) ? '分析完成后,报告会自动显示在这里。' : '此版本暂无分析报告。'}

)} + {tab === 'files' &&
+
{filtered.slice(0, limit).map(f => )}
+ {!filtered.length &&

{fileQuery ? '没有匹配的文件。' : '当前版本暂无可浏览文件。'}

} + {filtered.length > limit && }
} + {tab === 'qa' &&

询问这个版本

+ {history.map((entry,i) =>

{entry.question}

{entry.answer.text}

)} + {current.status === 'ready' ?
{ e.preventDefault(); void ask(); }}> + +