index.html 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>研创·智核 - InnoCore AI</title>
  7. <style>
  8. * {
  9. margin: 0;
  10. padding: 0;
  11. box-sizing: border-box;
  12. }
  13. body {
  14. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  15. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  16. min-height: 100vh;
  17. color: #333;
  18. }
  19. .container {
  20. max-width: 1200px;
  21. margin: 0 auto;
  22. padding: 20px;
  23. }
  24. header {
  25. text-align: center;
  26. padding: 40px 0;
  27. color: white;
  28. }
  29. header h1 {
  30. font-size: 3rem;
  31. margin-bottom: 10px;
  32. text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  33. }
  34. header p {
  35. font-size: 1.2rem;
  36. opacity: 0.9;
  37. }
  38. .main-content {
  39. background: white;
  40. border-radius: 15px;
  41. padding: 40px;
  42. box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  43. margin-bottom: 30px;
  44. }
  45. .features {
  46. display: grid;
  47. grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  48. gap: 30px;
  49. margin-top: 30px;
  50. }
  51. .feature-card {
  52. background: #f8f9fa;
  53. padding: 25px;
  54. border-radius: 10px;
  55. border-left: 4px solid #667eea;
  56. transition: transform 0.3s ease, box-shadow 0.3s ease;
  57. cursor: pointer;
  58. }
  59. .feature-card:hover {
  60. transform: translateY(-5px);
  61. box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
  62. }
  63. .feature-card.active {
  64. background: #e8f0fe;
  65. border-left-color: #4285f4;
  66. }
  67. .feature-card h3 {
  68. color: #667eea;
  69. margin-bottom: 10px;
  70. font-size: 1.3rem;
  71. }
  72. .feature-card p {
  73. color: #666;
  74. line-height: 1.6;
  75. margin-bottom: 15px;
  76. }
  77. .btn {
  78. background: #667eea;
  79. color: white;
  80. padding: 8px 16px;
  81. border: none;
  82. border-radius: 6px;
  83. cursor: pointer;
  84. font-size: 0.9rem;
  85. transition: background 0.3s ease;
  86. }
  87. .btn:hover {
  88. background: #5a6fd8;
  89. }
  90. .btn:disabled {
  91. background: #ccc;
  92. cursor: not-allowed;
  93. }
  94. .status {
  95. background: #e8f5e8;
  96. border: 1px solid #4caf50;
  97. color: #2e7d32;
  98. padding: 15px;
  99. border-radius: 8px;
  100. margin: 20px 0;
  101. }
  102. .interaction-panel {
  103. background: #f8f9fa;
  104. border-radius: 10px;
  105. padding: 30px;
  106. margin-top: 30px;
  107. display: none;
  108. }
  109. .interaction-panel.active {
  110. display: block;
  111. }
  112. .input-group {
  113. margin-bottom: 20px;
  114. }
  115. .input-group label {
  116. display: block;
  117. margin-bottom: 8px;
  118. font-weight: 600;
  119. color: #333;
  120. }
  121. .input-group input,
  122. .input-group textarea,
  123. .input-group select {
  124. width: 100%;
  125. padding: 12px;
  126. border: 2px solid #e1e5e9;
  127. border-radius: 8px;
  128. font-size: 1rem;
  129. transition: border-color 0.3s ease;
  130. }
  131. .input-group input:focus,
  132. .input-group textarea:focus,
  133. .input-group select:focus {
  134. outline: none;
  135. border-color: #667eea;
  136. }
  137. .input-group textarea {
  138. min-height: 120px;
  139. resize: vertical;
  140. }
  141. .response-area {
  142. background: #f8f9fa;
  143. border: 2px solid #e1e5e9;
  144. border-radius: 8px;
  145. padding: 20px;
  146. margin-top: 20px;
  147. min-height: 200px;
  148. max-height: 500px;
  149. overflow-y: auto;
  150. font-family: 'Consolas', 'Monaco', monospace;
  151. }
  152. .response-area pre {
  153. background: white;
  154. padding: 15px;
  155. border-radius: 6px;
  156. border-left: 4px solid #667eea;
  157. overflow-x: auto;
  158. margin: 10px 0;
  159. font-size: 0.9rem;
  160. line-height: 1.6;
  161. }
  162. .paper-card {
  163. background: white;
  164. border: 1px solid #e1e5e9;
  165. border-radius: 8px;
  166. padding: 20px;
  167. margin: 15px 0;
  168. transition: all 0.3s ease;
  169. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  170. }
  171. .paper-card:hover {
  172. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  173. transform: translateY(-2px);
  174. }
  175. .paper-card h4 {
  176. color: #667eea;
  177. margin-bottom: 10px;
  178. font-size: 1.1rem;
  179. line-height: 1.4;
  180. }
  181. .paper-card .authors {
  182. color: #666;
  183. font-size: 0.9rem;
  184. margin: 8px 0;
  185. }
  186. .paper-card .abstract {
  187. color: #444;
  188. line-height: 1.6;
  189. margin: 12px 0;
  190. font-size: 0.95rem;
  191. }
  192. .paper-card .meta {
  193. display: flex;
  194. gap: 15px;
  195. margin-top: 12px;
  196. font-size: 0.85rem;
  197. color: #888;
  198. }
  199. .paper-card .meta span {
  200. display: inline-flex;
  201. align-items: center;
  202. gap: 5px;
  203. }
  204. .paper-card a {
  205. color: #667eea;
  206. text-decoration: none;
  207. font-weight: 500;
  208. }
  209. .paper-card a:hover {
  210. text-decoration: underline;
  211. }
  212. .result-header {
  213. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  214. color: white;
  215. padding: 15px 20px;
  216. border-radius: 8px 8px 0 0;
  217. margin: -20px -20px 20px -20px;
  218. font-weight: 600;
  219. display: flex;
  220. justify-content: space-between;
  221. align-items: center;
  222. }
  223. .result-stats {
  224. background: rgba(255, 255, 255, 0.2);
  225. padding: 5px 12px;
  226. border-radius: 20px;
  227. font-size: 0.9rem;
  228. }
  229. .loading {
  230. display: none;
  231. text-align: center;
  232. padding: 20px;
  233. color: #667eea;
  234. }
  235. .loading.active {
  236. display: block;
  237. }
  238. .spinner {
  239. border: 3px solid #f3f3f3;
  240. border-top: 3px solid #667eea;
  241. border-radius: 50%;
  242. width: 40px;
  243. height: 40px;
  244. animation: spin 1s linear infinite;
  245. margin: 0 auto 10px;
  246. }
  247. @keyframes spin {
  248. 0% {
  249. transform: rotate(0deg);
  250. }
  251. 100% {
  252. transform: rotate(360deg);
  253. }
  254. }
  255. .error {
  256. background: #ffebee;
  257. border: 1px solid #f44336;
  258. color: #c62828;
  259. padding: 15px;
  260. border-radius: 8px;
  261. margin: 10px 0;
  262. }
  263. .success {
  264. background: #e8f5e8;
  265. border: 1px solid #4caf50;
  266. color: #2e7d32;
  267. padding: 15px;
  268. border-radius: 8px;
  269. margin: 10px 0;
  270. }
  271. .nav-buttons {
  272. display: flex;
  273. gap: 15px;
  274. justify-content: center;
  275. margin: 30px 0;
  276. flex-wrap: wrap;
  277. }
  278. .nav-buttons .btn {
  279. padding: 12px 25px;
  280. font-size: 1rem;
  281. text-decoration: none;
  282. display: inline-block;
  283. }
  284. .file-upload {
  285. border: 2px dashed #667eea;
  286. border-radius: 8px;
  287. padding: 30px;
  288. text-align: center;
  289. cursor: pointer;
  290. transition: background-color 0.3s ease;
  291. }
  292. .file-upload:hover {
  293. background: #f8f9ff;
  294. }
  295. .file-upload.dragover {
  296. background: #e8f0fe;
  297. border-color: #4285f4;
  298. }
  299. .copy-btn {
  300. float: right;
  301. background: rgba(102, 126, 234, 0.1);
  302. border: 1px solid #667eea;
  303. color: #667eea;
  304. padding: 5px 12px;
  305. border-radius: 4px;
  306. cursor: pointer;
  307. font-size: 0.85rem;
  308. transition: all 0.3s ease;
  309. margin-left: 10px;
  310. }
  311. .copy-btn:hover {
  312. background: #667eea;
  313. color: white;
  314. }
  315. .empty-state {
  316. text-align: center;
  317. padding: 40px 20px;
  318. color: #999;
  319. font-size: 1.1rem;
  320. }
  321. .badge {
  322. display: inline-block;
  323. padding: 4px 10px;
  324. border-radius: 12px;
  325. font-size: 0.8rem;
  326. font-weight: 600;
  327. margin-left: 8px;
  328. }
  329. .badge-success {
  330. background: #e8f5e8;
  331. color: #2e7d32;
  332. }
  333. .badge-info {
  334. background: #e3f2fd;
  335. color: #1976d2;
  336. }
  337. .badge-warning {
  338. background: #fff3e0;
  339. color: #f57c00;
  340. }
  341. .json-key {
  342. color: #0066cc;
  343. font-weight: 600;
  344. }
  345. .json-string {
  346. color: #008000;
  347. }
  348. .json-number {
  349. color: #ff6600;
  350. }
  351. .json-boolean {
  352. color: #cc00cc;
  353. font-weight: 600;
  354. }
  355. .json-null {
  356. color: #999;
  357. font-style: italic;
  358. }
  359. .markdown-content {
  360. line-height: 1.8;
  361. color: #333;
  362. }
  363. .markdown-content h1,
  364. .markdown-content h2,
  365. .markdown-content h3 {
  366. color: #667eea;
  367. margin-top: 20px;
  368. margin-bottom: 10px;
  369. }
  370. .markdown-content ul {
  371. list-style-type: disc;
  372. padding-left: 25px;
  373. margin: 15px 0;
  374. }
  375. .markdown-content li {
  376. margin: 10px 0;
  377. line-height: 1.8;
  378. }
  379. .markdown-content strong {
  380. color: #333;
  381. font-weight: 600;
  382. }
  383. .markdown-content code {
  384. background: #f0f0f0;
  385. padding: 2px 6px;
  386. border-radius: 3px;
  387. font-family: 'Consolas', 'Monaco', monospace;
  388. color: #e83e8c;
  389. font-size: 0.9em;
  390. }
  391. .markdown-content pre {
  392. background: #f5f5f5;
  393. padding: 15px;
  394. border-radius: 6px;
  395. overflow-x: auto;
  396. border-left: 4px solid #667eea;
  397. margin: 15px 0;
  398. }
  399. .markdown-content pre code {
  400. background: none;
  401. padding: 0;
  402. color: #333;
  403. }
  404. .markdown-content a {
  405. color: #667eea;
  406. text-decoration: none;
  407. border-bottom: 1px solid #667eea;
  408. }
  409. .markdown-content a:hover {
  410. color: #5a6fd8;
  411. border-bottom-color: #5a6fd8;
  412. }
  413. .markdown-content p {
  414. margin: 12px 0;
  415. line-height: 1.8;
  416. }
  417. </style>
  418. </head>
  419. <body>
  420. <div class="container">
  421. <header>
  422. <h1>🧠 研创·智核</h1>
  423. <p>基于多智能体架构的智能科研助手平台</p>
  424. </header>
  425. <main class="main-content">
  426. <div class="status" id="systemStatus">
  427. ✅ 系统初始化中...
  428. </div>
  429. <div class="nav-buttons">
  430. <a href="/docs" class="btn" target="_blank">📚 API 文档</a>
  431. <a href="/health" class="btn" target="_blank">🔍 健康检查</a>
  432. <button class="btn" onclick="checkSystemStatus()">🔄 刷新状态</button>
  433. </div>
  434. <section>
  435. <h2>🚀 核心功能</h2>
  436. <!-- 工作流模式选择 -->
  437. <div
  438. style="margin-bottom: 20px; padding: 15px; background: #f0f7ff; border-radius: 8px; border-left: 4px solid #667eea;">
  439. <h3 style="margin: 0 0 10px 0; color: #667eea;">🔄 工作模式</h3>
  440. <div style="display: flex; gap: 15px; flex-wrap: wrap;">
  441. <label style="display: flex; align-items: center; cursor: pointer;">
  442. <input type="radio" name="work-mode" value="individual" checked style="margin-right: 8px;">
  443. <span>单独模式 - 独立使用每个智能体</span>
  444. </label>
  445. <label style="display: flex; align-items: center; cursor: pointer;">
  446. <input type="radio" name="work-mode" value="workflow" style="margin-right: 8px;">
  447. <span>协调模式 - 自动化完整工作流 ⭐</span>
  448. </label>
  449. </div>
  450. </div>
  451. <div class="features">
  452. <div class="feature-card" onclick="activateAgent('workflow')" id="workflow-card"
  453. style="display: none; grid-column: 1 / -1; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white;">
  454. <h3>🔄 完整工作流</h3>
  455. <p>自动协调所有智能体:搜索论文 → 深度分析 → 生成引用 → 撰写报告</p>
  456. <button class="btn" style="background: white; color: #667eea;"
  457. onclick="event.stopPropagation(); activateAgent('workflow')">启动工作流</button>
  458. </div>
  459. <div class="feature-card" onclick="activateAgent('hunter')" id="hunter-card">
  460. <h3>🕵️ Hunter Agent</h3>
  461. <p>智能文献搜索与监控,自动抓取 ArXiv、IEEE 等平台的最新论文</p>
  462. <button class="btn" onclick="event.stopPropagation(); activateAgent('hunter')">开始搜索</button>
  463. </div>
  464. <div class="feature-card" onclick="activateAgent('miner')" id="miner-card">
  465. <h3>🧠 Miner Agent</h3>
  466. <p>深度论文分析,挖掘创新点,生成结构化研究报告</p>
  467. <button class="btn" onclick="event.stopPropagation(); activateAgent('miner')">分析论文</button>
  468. </div>
  469. <div class="feature-card" onclick="activateAgent('coach')" id="coach-card">
  470. <h3>✍️ Coach Agent</h3>
  471. <p>个性化写作助手,提供学术润色、风格迁移和实时指导</p>
  472. <button class="btn" onclick="event.stopPropagation(); activateAgent('coach')">写作助手</button>
  473. </div>
  474. <div class="feature-card" onclick="activateAgent('validator')" id="validator-card">
  475. <h3>🔎 Validator Agent</h3>
  476. <p>引用格式校验,确保学术引用的准确性和标准化</p>
  477. <button class="btn" onclick="event.stopPropagation(); activateAgent('validator')">校验引用</button>
  478. </div>
  479. </div>
  480. </section>
  481. <!-- Hunter Agent 交互面板 -->
  482. <div class="interaction-panel" id="hunter-panel">
  483. <h3>🕵️ 文献搜索</h3>
  484. <div class="input-group">
  485. <label for="search-keywords">搜索关键词</label>
  486. <input type="text" id="search-keywords"
  487. placeholder="例如: machine learning, natural language processing">
  488. </div>
  489. <div class="input-group">
  490. <label for="search-source">搜索来源</label>
  491. <select id="search-source">
  492. <option value="arxiv">ArXiv</option>
  493. <option value="ieee">IEEE</option>
  494. <option value="pubmed">PubMed</option>
  495. <option value="all">全部来源</option>
  496. </select>
  497. </div>
  498. <div class="input-group">
  499. <label for="search-limit">论文数量限制</label>
  500. <input type="number" id="search-limit" value="10" min="1" max="50">
  501. </div>
  502. <button class="btn" onclick="executeHunterTask()">开始搜索</button>
  503. <div class="loading" id="hunter-loading">
  504. <div class="spinner"></div>
  505. <p>正在搜索论文...</p>
  506. </div>
  507. <div class="response-area" id="hunter-response"></div>
  508. </div>
  509. <!-- Miner Agent 交互面板 -->
  510. <div class="interaction-panel" id="miner-panel">
  511. <h3>🧠 论文分析</h3>
  512. <div class="input-group">
  513. <label for="paper-upload">上传论文 (PDF)</label>
  514. <div class="file-upload" id="paper-upload-area">
  515. <p>📄 点击或拖拽PDF文件到此处</p>
  516. <input type="file" id="paper-file" accept=".pdf" style="display: none;">
  517. </div>
  518. </div>
  519. <div class="input-group">
  520. <label for="paper-url">或输入论文URL</label>
  521. <input type="url" id="paper-url" placeholder="https://arxiv.org/abs/...">
  522. </div>
  523. <div class="input-group">
  524. <label for="analysis-type">分析类型</label>
  525. <select id="analysis-type">
  526. <option value="summary">内容摘要</option>
  527. <option value="innovation">创新点分析</option>
  528. <option value="comparison">对比分析</option>
  529. <option value="comprehensive">综合分析</option>
  530. </select>
  531. </div>
  532. <button class="btn" onclick="executeMinerTask()">开始分析</button>
  533. <div class="loading" id="miner-loading">
  534. <div class="spinner"></div>
  535. <p>正在分析论文...</p>
  536. </div>
  537. <div class="response-area" id="miner-response"></div>
  538. </div>
  539. <!-- Coach Agent 交互面板 -->
  540. <div class="interaction-panel" id="coach-panel">
  541. <h3>✍️ 写作助手</h3>
  542. <div class="input-group">
  543. <label for="writing-text">您的文本</label>
  544. <textarea id="writing-text" placeholder="请输入需要润色的学术文本..."></textarea>
  545. </div>
  546. <div class="input-group">
  547. <label for="writing-style">写作风格</label>
  548. <select id="writing-style">
  549. <option value="formal">正式学术风格</option>
  550. <option value="nature">Nature风格</option>
  551. <option value="science">Science风格</option>
  552. <option value="ieee">IEEE风格</option>
  553. </select>
  554. </div>
  555. <div class="input-group">
  556. <label for="writing-task">任务类型</label>
  557. <select id="writing-task">
  558. <option value="polish">润色改进</option>
  559. <option value="translate">中译英</option>
  560. <option value="explain">解释概念</option>
  561. <option value="expand">内容扩展</option>
  562. </select>
  563. </div>
  564. <button class="btn" onclick="executeCoachTask()">开始处理</button>
  565. <div class="loading" id="coach-loading">
  566. <div class="spinner"></div>
  567. <p>正在处理文本...</p>
  568. </div>
  569. <div class="response-area" id="coach-response"></div>
  570. </div>
  571. <!-- Validator Agent 交互面板 -->
  572. <div class="interaction-panel" id="validator-panel">
  573. <h3>🔎 引用校验</h3>
  574. <div class="input-group">
  575. <label for="citation-input">引用信息</label>
  576. <textarea id="citation-input" placeholder="请输入引用信息,可以是DOI、标题、或BibTeX格式..."></textarea>
  577. </div>
  578. <div class="input-group">
  579. <label for="citation-format">输出格式</label>
  580. <select id="citation-format">
  581. <option value="bibtex">BibTeX</option>
  582. <option value="apa">APA</option>
  583. <option value="ieee">IEEE</option>
  584. <option value="mla">MLA</option>
  585. </select>
  586. </div>
  587. <button class="btn" onclick="executeValidatorTask()">校验引用</button>
  588. <div class="loading" id="validator-loading">
  589. <div class="spinner"></div>
  590. <p>正在校验引用...</p>
  591. </div>
  592. <div class="response-area" id="validator-response"></div>
  593. </div>
  594. <!-- Workflow 协调面板 -->
  595. <div class="interaction-panel" id="workflow-panel">
  596. <h3>🔄 完整工作流</h3>
  597. <p style="color: #666; margin-bottom: 20px;">自动协调所有智能体完成完整的研究流程</p>
  598. <div class="input-group">
  599. <label for="workflow-keywords">研究关键词</label>
  600. <input type="text" id="workflow-keywords" placeholder="例如: deep learning for computer vision">
  601. </div>
  602. <div class="input-group">
  603. <label for="workflow-limit">搜索论文数量</label>
  604. <select id="workflow-limit">
  605. <option value="3">3篇(快速)</option>
  606. <option value="5" selected>5篇(推荐)</option>
  607. <option value="10">10篇(详细)</option>
  608. </select>
  609. </div>
  610. <div class="input-group">
  611. <label for="workflow-analysis-type">分析类型</label>
  612. <select id="workflow-analysis-type">
  613. <option value="summary">摘要分析</option>
  614. <option value="innovation">创新点分析</option>
  615. <option value="comparison">对比分析</option>
  616. <option value="comprehensive">综合分析</option>
  617. </select>
  618. </div>
  619. <div class="input-group">
  620. <label for="workflow-citation-format">引用格式</label>
  621. <select id="workflow-citation-format">
  622. <option value="bibtex">BibTeX</option>
  623. <option value="apa">APA</option>
  624. <option value="ieee">IEEE</option>
  625. <option value="mla">MLA</option>
  626. </select>
  627. </div>
  628. <div class="input-group">
  629. <label>
  630. <input type="checkbox" id="workflow-generate-report" checked>
  631. 生成综合报告
  632. </label>
  633. </div>
  634. <button class="btn" onclick="executeWorkflow()"
  635. style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);">🚀 启动完整工作流</button>
  636. <div class="loading" id="workflow-loading">
  637. <div class="spinner"></div>
  638. <p>工作流执行中,请稍候...</p>
  639. </div>
  640. <div class="response-area" id="workflow-response"></div>
  641. </div>
  642. </main>
  643. </div>
  644. <script>
  645. let currentAgent = null;
  646. // 页面加载时检查系统状态
  647. document.addEventListener('DOMContentLoaded', function () {
  648. checkSystemStatus();
  649. setupFileUpload();
  650. setupWorkModeSwitch();
  651. });
  652. // 设置工作模式切换
  653. function setupWorkModeSwitch() {
  654. const modeRadios = document.querySelectorAll('input[name="work-mode"]');
  655. modeRadios.forEach(radio => {
  656. radio.addEventListener('change', function () {
  657. const workflowCard = document.getElementById('workflow-card');
  658. if (this.value === 'workflow') {
  659. workflowCard.style.display = 'block';
  660. } else {
  661. workflowCard.style.display = 'none';
  662. }
  663. });
  664. });
  665. }
  666. // 检查系统状态
  667. async function checkSystemStatus() {
  668. const statusDiv = document.getElementById('systemStatus');
  669. try {
  670. const response = await fetch('/health');
  671. const data = await response.json();
  672. if (response.ok) {
  673. statusDiv.className = 'status';
  674. statusDiv.innerHTML = `✅ 系统运行正常 | 状态: ${data.status} | 时间: ${new Date().toLocaleString()}`;
  675. } else {
  676. throw new Error('系统状态异常');
  677. }
  678. } catch (error) {
  679. statusDiv.className = 'error';
  680. statusDiv.innerHTML = `❌ 系统连接失败: ${error.message}`;
  681. }
  682. }
  683. // 激活智能体
  684. function activateAgent(agentType) {
  685. // 重置所有卡片和面板
  686. document.querySelectorAll('.feature-card').forEach(card => {
  687. card.classList.remove('active');
  688. });
  689. document.querySelectorAll('.interaction-panel').forEach(panel => {
  690. panel.classList.remove('active');
  691. });
  692. // 激活选中的智能体
  693. currentAgent = agentType;
  694. document.getElementById(`${agentType}-card`).classList.add('active');
  695. document.getElementById(`${agentType}-panel`).classList.add('active');
  696. }
  697. // 执行Hunter任务
  698. async function executeHunterTask() {
  699. const keywords = document.getElementById('search-keywords').value;
  700. const source = document.getElementById('search-source').value;
  701. const limit = document.getElementById('search-limit').value;
  702. if (!keywords.trim()) {
  703. showError('hunter-response', '请输入搜索关键词');
  704. return;
  705. }
  706. showLoading('hunter-loading');
  707. try {
  708. const response = await fetch('/api/v1/papers/search', {
  709. method: 'POST',
  710. headers: {
  711. 'Content-Type': 'application/json',
  712. },
  713. body: JSON.stringify({
  714. keywords: keywords,
  715. source: source,
  716. limit: parseInt(limit)
  717. })
  718. });
  719. const data = await response.json();
  720. if (response.ok) {
  721. showSuccess('hunter-response', `找到 ${data.papers?.length || 0} 篇相关论文`, data);
  722. } else {
  723. showError('hunter-response', data.detail || '搜索失败');
  724. }
  725. } catch (error) {
  726. showError('hunter-response', `网络错误: ${error.message}`);
  727. } finally {
  728. hideLoading('hunter-loading');
  729. }
  730. }
  731. // 执行Miner任务
  732. async function executeMinerTask() {
  733. const paperUrl = document.getElementById('paper-url').value;
  734. const analysisType = document.getElementById('analysis-type').value;
  735. if (!paperUrl.trim()) {
  736. showError('miner-response', '请输入论文URL或上传PDF文件');
  737. return;
  738. }
  739. showLoading('miner-loading');
  740. try {
  741. const response = await fetch('/api/v1/analysis/analyze', {
  742. method: 'POST',
  743. headers: {
  744. 'Content-Type': 'application/json',
  745. },
  746. body: JSON.stringify({
  747. paper_url: paperUrl,
  748. analysis_type: analysisType
  749. })
  750. });
  751. const data = await response.json();
  752. if (response.ok) {
  753. showSuccess('miner-response', '论文分析完成', data);
  754. } else {
  755. showError('miner-response', data.detail || '分析失败');
  756. }
  757. } catch (error) {
  758. showError('miner-response', `网络错误: ${error.message}`);
  759. } finally {
  760. hideLoading('miner-loading');
  761. }
  762. }
  763. // 执行Coach任务
  764. async function executeCoachTask() {
  765. const text = document.getElementById('writing-text').value;
  766. const style = document.getElementById('writing-style').value;
  767. const task = document.getElementById('writing-task').value;
  768. if (!text.trim()) {
  769. showError('coach-response', '请输入需要处理的文本');
  770. return;
  771. }
  772. showLoading('coach-loading');
  773. try {
  774. const response = await fetch('/api/v1/writing/coach', {
  775. method: 'POST',
  776. headers: {
  777. 'Content-Type': 'application/json',
  778. },
  779. body: JSON.stringify({
  780. text: text,
  781. style: style,
  782. task: task
  783. })
  784. });
  785. const data = await response.json();
  786. if (response.ok) {
  787. showSuccess('coach-response', '文本处理完成', data);
  788. } else {
  789. showError('coach-response', data.detail || '处理失败');
  790. }
  791. } catch (error) {
  792. showError('coach-response', `网络错误: ${error.message}`);
  793. } finally {
  794. hideLoading('coach-loading');
  795. }
  796. }
  797. // 执行Validator任务
  798. async function executeValidatorTask() {
  799. const citation = document.getElementById('citation-input').value;
  800. const format = document.getElementById('citation-format').value;
  801. if (!citation.trim()) {
  802. showError('validator-response', '请输入引用信息');
  803. return;
  804. }
  805. showLoading('validator-loading');
  806. try {
  807. const response = await fetch('/api/v1/citations/validate', {
  808. method: 'POST',
  809. headers: {
  810. 'Content-Type': 'application/json',
  811. },
  812. body: JSON.stringify({
  813. citation: citation,
  814. format: format
  815. })
  816. });
  817. const data = await response.json();
  818. if (response.ok) {
  819. showSuccess('validator-response', '引用校验完成', data);
  820. } else {
  821. showError('validator-response', data.detail || '校验失败');
  822. }
  823. } catch (error) {
  824. showError('validator-response', `网络错误: ${error.message}`);
  825. } finally {
  826. hideLoading('validator-loading');
  827. }
  828. }
  829. // 执行完整工作流
  830. async function executeWorkflow() {
  831. const keywords = document.getElementById('workflow-keywords').value;
  832. const limit = document.getElementById('workflow-limit').value;
  833. const analysisType = document.getElementById('workflow-analysis-type').value;
  834. const citationFormat = document.getElementById('workflow-citation-format').value;
  835. const generateReport = document.getElementById('workflow-generate-report').checked;
  836. if (!keywords.trim()) {
  837. showError('workflow-response', '请输入研究关键词');
  838. return;
  839. }
  840. showLoading('workflow-loading');
  841. try {
  842. const response = await fetch('/api/v1/workflow/complete', {
  843. method: 'POST',
  844. headers: {
  845. 'Content-Type': 'application/json',
  846. },
  847. body: JSON.stringify({
  848. keywords: keywords,
  849. limit: parseInt(limit),
  850. analysis_type: analysisType,
  851. citation_format: citationFormat,
  852. writing_task: generateReport ? 'improve' : null
  853. })
  854. });
  855. const data = await response.json();
  856. if (response.ok) {
  857. showSuccess('workflow-response', '🎉 工作流执行完成!', data);
  858. } else {
  859. showError('workflow-response', data.detail || '工作流执行失败');
  860. }
  861. } catch (error) {
  862. showError('workflow-response', `网络错误: ${error.message}`);
  863. } finally {
  864. hideLoading('workflow-loading');
  865. }
  866. }
  867. // 设置文件上传
  868. function setupFileUpload() {
  869. const uploadArea = document.getElementById('paper-upload-area');
  870. const fileInput = document.getElementById('paper-file');
  871. uploadArea.addEventListener('click', () => fileInput.click());
  872. uploadArea.addEventListener('dragover', (e) => {
  873. e.preventDefault();
  874. uploadArea.classList.add('dragover');
  875. });
  876. uploadArea.addEventListener('dragleave', () => {
  877. uploadArea.classList.remove('dragover');
  878. });
  879. uploadArea.addEventListener('drop', (e) => {
  880. e.preventDefault();
  881. uploadArea.classList.remove('dragover');
  882. const files = e.dataTransfer.files;
  883. if (files.length > 0 && files[0].type === 'application/pdf') {
  884. handleFileUpload(files[0]);
  885. }
  886. });
  887. fileInput.addEventListener('change', (e) => {
  888. if (e.target.files.length > 0) {
  889. handleFileUpload(e.target.files[0]);
  890. }
  891. });
  892. }
  893. // 处理文件上传
  894. async function handleFileUpload(file) {
  895. const formData = new FormData();
  896. formData.append('file', file);
  897. showLoading('miner-loading');
  898. try {
  899. // 使用新的 PDF 解析端点
  900. const response = await fetch('/api/v1/analysis/upload-pdf', {
  901. method: 'POST',
  902. body: formData
  903. });
  904. const data = await response.json();
  905. if (response.ok) {
  906. // 自动填充 URL 字段
  907. document.getElementById('paper-url').value = data.file_path || '';
  908. // 显示解析结果
  909. const uploadInfo = `
  910. <div class="paper-card">
  911. <h4>📄 ${data.title || file.name}</h4>
  912. <div class="authors">
  913. 👥 作者: ${data.authors ? data.authors.join(', ') : '未知'}
  914. </div>
  915. <div class="abstract">
  916. 📝 ${data.abstract || '无摘要'}
  917. </div>
  918. <div class="meta">
  919. <span>📄 ${data.page_count || 0} 页</span>
  920. <span>📊 ${data.word_count || 0} 词</span>
  921. <span>✅ 已解析</span>
  922. </div>
  923. </div>
  924. `;
  925. showSuccess('miner-response', '✅ PDF 文件上传并解析成功!现在可以选择分析类型并开始分析。', {
  926. upload_info: uploadInfo
  927. });
  928. } else {
  929. showError('miner-response', data.detail || '上传失败');
  930. }
  931. } catch (error) {
  932. showError('miner-response', `上传错误: ${error.message}`);
  933. } finally {
  934. hideLoading('miner-loading');
  935. }
  936. }
  937. // 显示加载状态
  938. function showLoading(loadingId) {
  939. document.getElementById(loadingId).classList.add('active');
  940. }
  941. // 隐藏加载状态
  942. function hideLoading(loadingId) {
  943. document.getElementById(loadingId).classList.remove('active');
  944. }
  945. // 显示成功消息
  946. function showSuccess(responseId, message, data = null) {
  947. const responseDiv = document.getElementById(responseId);
  948. let content = `<div class="success">✅ ${message}</div>`;
  949. if (data) {
  950. // 工作流结果
  951. if (data.steps && Array.isArray(data.steps)) {
  952. content += formatWorkflowResult(data);
  953. }
  954. // PDF 上传信息
  955. else if (data.upload_info) {
  956. content += data.upload_info;
  957. }
  958. // 论文搜索结果
  959. else if (data.papers && Array.isArray(data.papers)) {
  960. content += formatPaperResults(data);
  961. }
  962. // 论文分析结果
  963. else if (data.analysis) {
  964. content += formatAnalysisResult(data);
  965. }
  966. // 写作助手结果
  967. else if (data.result && typeof data.result === 'string') {
  968. content += formatWritingResult(data);
  969. }
  970. // 引用校验结果
  971. else if (data.formatted_citation) {
  972. content += formatCitationResult(data);
  973. }
  974. // 其他类型的数据用格式化的 JSON 展示
  975. else {
  976. const jsonStr = JSON.stringify(data, null, 2);
  977. const jsonId = 'json-' + Date.now();
  978. content += `
  979. <div style="position: relative;">
  980. <button class="copy-btn" onclick="copyToClipboard('${jsonId}', event)">📋 复制</button>
  981. <pre id="${jsonId}">${syntaxHighlight(jsonStr)}</pre>
  982. </div>
  983. `;
  984. }
  985. }
  986. responseDiv.innerHTML = content;
  987. }
  988. // 格式化论文搜索结果
  989. function formatPaperResults(data) {
  990. let html = `
  991. <div class="result-header">
  992. <span>📚 搜索结果</span>
  993. <span class="result-stats">共找到 ${data.papers.length} 篇论文</span>
  994. </div>
  995. `;
  996. data.papers.forEach((paper, index) => {
  997. html += `
  998. <div class="paper-card">
  999. <h4>${index + 1}. ${escapeHtml(paper.title)}</h4>
  1000. <div class="authors">
  1001. 👥 作者: ${paper.authors.join(', ')}
  1002. </div>
  1003. <div class="abstract">
  1004. 📝 ${escapeHtml(paper.abstract)}
  1005. </div>
  1006. <div class="meta">
  1007. <span>📅 ${paper.published_date}</span>
  1008. <span>🔗 <a href="${paper.url}" target="_blank">查看原文</a></span>
  1009. ${paper.pdf_url ? `<span>📄 <a href="${paper.pdf_url}" target="_blank">下载PDF</a></span>` : ''}
  1010. <span>🆔 ${paper.id}</span>
  1011. </div>
  1012. </div>
  1013. `;
  1014. });
  1015. return html;
  1016. }
  1017. // 格式化论文分析结果
  1018. function formatAnalysisResult(data) {
  1019. let html = `
  1020. <div class="result-header">
  1021. <span>🧠 论文分析</span>
  1022. <span class="result-stats">${data.analysis_type}</span>
  1023. </div>
  1024. `;
  1025. if (data.paper_info) {
  1026. html += `
  1027. <div class="paper-card">
  1028. <h4>${escapeHtml(data.paper_info.title)}</h4>
  1029. <div class="authors">
  1030. 👥 作者: ${data.paper_info.authors.join(', ')}
  1031. </div>
  1032. <div class="meta">
  1033. <span>📅 ${data.paper_info.published_date}</span>
  1034. <span>🔗 <a href="${data.paper_info.url}" target="_blank">查看原文</a></span>
  1035. <span>🏷️ ${data.paper_info.categories.join(', ')}</span>
  1036. </div>
  1037. </div>
  1038. `;
  1039. }
  1040. const analysisId = 'analysis-' + Date.now();
  1041. html += '<div class="paper-card">';
  1042. html += '<h4>📊 分析结果 <button class="copy-btn" onclick="copyToClipboard(\'' + analysisId + '\', event)" style="float: right;">📋 复制</button></h4>';
  1043. html += '<div class="markdown-content" id="' + analysisId + '">';
  1044. html += renderMarkdown(data.analysis);
  1045. html += '</div>';
  1046. html += '</div>';
  1047. return html;
  1048. }
  1049. // 改进的 Markdown 渲染器
  1050. function renderMarkdown(text) {
  1051. if (!text) return '';
  1052. // 按行处理
  1053. const lines = text.split('\n');
  1054. let html = '';
  1055. let inList = false;
  1056. let listItems = [];
  1057. for (let i = 0; i < lines.length; i++) {
  1058. let line = lines[i];
  1059. // 跳过空行
  1060. if (!line.trim()) {
  1061. if (inList) {
  1062. html += '<ul style="list-style-type: disc; padding-left: 25px; margin: 15px 0;">' + listItems.join('') + '</ul>';
  1063. listItems = [];
  1064. inList = false;
  1065. }
  1066. html += '<br/>';
  1067. continue;
  1068. }
  1069. // 标题 (必须在行首) - 从最长的开始匹配
  1070. const h4Match = line.match(/^####\s+(.+)$/);
  1071. if (h4Match) {
  1072. if (inList) {
  1073. html += '<ul style="list-style-type: disc; padding-left: 25px; margin: 15px 0;">' + listItems.join('') + '</ul>';
  1074. listItems = [];
  1075. inList = false;
  1076. }
  1077. html += '<h4 style="color: #667eea; margin: 15px 0 8px 0; font-size: 1.05rem; font-weight: 600;">' + formatInlineMarkdown(h4Match[1]) + '</h4>';
  1078. continue;
  1079. }
  1080. const h3Match = line.match(/^###\s+(.+)$/);
  1081. if (h3Match) {
  1082. if (inList) {
  1083. html += '<ul style="list-style-type: disc; padding-left: 25px; margin: 15px 0;">' + listItems.join('') + '</ul>';
  1084. listItems = [];
  1085. inList = false;
  1086. }
  1087. html += '<h3 style="color: #667eea; margin: 20px 0 10px 0; font-size: 1.1rem; font-weight: 600;">' + formatInlineMarkdown(h3Match[1]) + '</h3>';
  1088. continue;
  1089. }
  1090. const h2Match = line.match(/^##\s+(.+)$/);
  1091. if (h2Match) {
  1092. if (inList) {
  1093. html += '<ul style="list-style-type: disc; padding-left: 25px; margin: 15px 0;">' + listItems.join('') + '</ul>';
  1094. listItems = [];
  1095. inList = false;
  1096. }
  1097. html += '<h2 style="color: #667eea; margin: 25px 0 15px 0; font-size: 1.3rem; font-weight: 600;">' + formatInlineMarkdown(h2Match[1]) + '</h2>';
  1098. continue;
  1099. }
  1100. const h1Match = line.match(/^#\s+(.+)$/);
  1101. if (h1Match) {
  1102. if (inList) {
  1103. html += '<ul style="list-style-type: disc; padding-left: 25px; margin: 15px 0;">' + listItems.join('') + '</ul>';
  1104. listItems = [];
  1105. inList = false;
  1106. }
  1107. html += '<h1 style="color: #667eea; margin: 30px 0 20px 0; font-size: 1.5rem; font-weight: 600;">' + formatInlineMarkdown(h1Match[1]) + '</h1>';
  1108. continue;
  1109. }
  1110. // 有序列表
  1111. const orderedMatch = line.match(/^(\d+)\.\s+(.+)$/);
  1112. if (orderedMatch) {
  1113. const content = orderedMatch[2];
  1114. const formatted = formatInlineMarkdown(content);
  1115. listItems.push(`<li style="margin: 10px 0; line-height: 1.8;">${formatted}</li>`);
  1116. inList = true;
  1117. continue;
  1118. }
  1119. // 无序列表
  1120. const unorderedMatch = line.match(/^[-*]\s+(.+)$/);
  1121. if (unorderedMatch) {
  1122. const content = unorderedMatch[1];
  1123. const formatted = formatInlineMarkdown(content);
  1124. listItems.push(`<li style="margin: 10px 0; line-height: 1.8;">${formatted}</li>`);
  1125. inList = true;
  1126. continue;
  1127. }
  1128. // 普通段落
  1129. if (inList) {
  1130. html += '<ul style="list-style-type: disc; padding-left: 25px; margin: 15px 0;">' + listItems.join('') + '</ul>';
  1131. listItems = [];
  1132. inList = false;
  1133. }
  1134. const formatted = formatInlineMarkdown(line);
  1135. html += `<p style="margin: 12px 0; line-height: 1.8; color: #444;">${formatted}</p>`;
  1136. }
  1137. // 处理未闭合的列表
  1138. if (inList) {
  1139. html += '<ul style="list-style-type: disc; padding-left: 25px; margin: 15px 0;">' + listItems.join('') + '</ul>';
  1140. }
  1141. return html;
  1142. }
  1143. // 格式化行内 Markdown 元素
  1144. function formatInlineMarkdown(text) {
  1145. // 转义 HTML
  1146. text = escapeHtml(text);
  1147. // 粗体 **text**
  1148. text = text.replace(/\*\*(.+?)\*\*/g, '<strong style="color: #333; font-weight: 600;">$1</strong>');
  1149. // 斜体 *text*
  1150. text = text.replace(/\*(.+?)\*/g, '<em>$1</em>');
  1151. // 行内代码 `code`
  1152. text = text.replace(/`([^`]+)`/g, '<code style="background: #f0f0f0; padding: 2px 6px; border-radius: 3px; font-family: monospace; color: #e83e8c; font-size: 0.9em;">$1</code>');
  1153. // 链接 [text](url)
  1154. text = text.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2" target="_blank" style="color: #667eea; text-decoration: none; border-bottom: 1px solid #667eea;">$1</a>');
  1155. return text;
  1156. }
  1157. // 格式化写作助手结果
  1158. function formatWritingResult(data) {
  1159. let html = `
  1160. <div class="result-header">
  1161. <span>✍️ 写作助手</span>
  1162. <span class="result-stats">${data.task} - ${data.style}</span>
  1163. </div>
  1164. `;
  1165. if (data.original) {
  1166. html += `
  1167. <div class="paper-card">
  1168. <h4>📝 原文</h4>
  1169. <div class="abstract" style="background: #f8f9fa; padding: 15px; border-radius: 6px;">
  1170. ${escapeHtml(data.original)}
  1171. </div>
  1172. </div>
  1173. `;
  1174. }
  1175. const resultId = 'writing-result-' + Date.now();
  1176. html += '<div class="paper-card">';
  1177. html += '<h4>✨ 处理结果 <button class="copy-btn" onclick="copyToClipboard(\'' + resultId + '\', event)" style="float: right;">📋 复制</button></h4>';
  1178. html += '<div class="markdown-content" id="' + resultId + '">';
  1179. html += renderMarkdown(data.result);
  1180. html += '</div>';
  1181. html += '</div>';
  1182. return html;
  1183. }
  1184. // 格式化引用校验结果
  1185. function formatCitationResult(data) {
  1186. const jsonId = 'citation-' + Date.now();
  1187. let html = `
  1188. <div class="result-header">
  1189. <span>🔎 引用校验</span>
  1190. <span class="result-stats">${data.format.toUpperCase()} ${data.verified ? '✅ 已验证' : '⚠️ 未验证'}</span>
  1191. </div>
  1192. `;
  1193. if (data.metadata) {
  1194. const meta = data.metadata;
  1195. // 处理标题
  1196. let title = 'N/A';
  1197. if (meta.title) {
  1198. title = Array.isArray(meta.title) ? meta.title[0] : meta.title;
  1199. }
  1200. // 处理作者
  1201. let authors = 'N/A';
  1202. if (meta.authors) {
  1203. if (Array.isArray(meta.authors)) {
  1204. authors = meta.authors.join(', ');
  1205. } else {
  1206. authors = meta.authors;
  1207. }
  1208. }
  1209. // 处理年份
  1210. let year = 'N/A';
  1211. if (meta.year) {
  1212. year = meta.year;
  1213. } else if (meta.published && meta.published['date-parts']) {
  1214. year = meta.published['date-parts'][0][0];
  1215. }
  1216. // 处理期刊
  1217. let journal = 'N/A';
  1218. if (meta.journal) {
  1219. journal = meta.journal;
  1220. } else if (meta['container-title']) {
  1221. journal = Array.isArray(meta['container-title']) ? meta['container-title'][0] : meta['container-title'];
  1222. }
  1223. html += `
  1224. <div class="paper-card">
  1225. <h4>📄 论文信息</h4>
  1226. <div class="authors">
  1227. 📖 标题: ${escapeHtml(title)}
  1228. </div>
  1229. <div class="authors">
  1230. 👥 作者: ${escapeHtml(authors)}
  1231. </div>
  1232. <div class="meta">
  1233. <span>📅 ${year}</span>
  1234. <span>📚 ${escapeHtml(journal)}</span>
  1235. ${meta.arxiv_id ? `<span>🔗 arXiv:${meta.arxiv_id}</span>` : ''}
  1236. ${meta.doi ? `<span>🔗 DOI:${meta.doi}</span>` : ''}
  1237. </div>
  1238. </div>
  1239. `;
  1240. }
  1241. html += `
  1242. <div class="paper-card">
  1243. <h4>📋 格式化引用 <button class="copy-btn" onclick="copyToClipboard('${jsonId}', event)" style="float: right;">📋 复制</button></h4>
  1244. <pre id="${jsonId}" style="background: white; padding: 15px; border-radius: 6px; border-left: 4px solid #667eea; overflow-x: auto;">${escapeHtml(data.formatted_citation)}</pre>
  1245. </div>
  1246. `;
  1247. if (data.warnings && data.warnings.length > 0) {
  1248. html += `
  1249. <div class="error">
  1250. ⚠️ ${data.warnings.join('; ')}
  1251. </div>
  1252. `;
  1253. }
  1254. return html;
  1255. }
  1256. // 格式化工作流结果
  1257. function formatWorkflowResult(data) {
  1258. let html = `
  1259. <div class="result-header">
  1260. <span>🔄 工作流执行结果</span>
  1261. <span class="result-stats">${data.status === 'completed' ? '✅ 完成' : '⚠️ 部分完成'}</span>
  1262. </div>
  1263. `;
  1264. // 显示摘要
  1265. if (data.summary) {
  1266. html += `
  1267. <div class="paper-card">
  1268. <h4>📊 执行摘要</h4>
  1269. <div class="meta">
  1270. <span>📚 找到 ${data.summary.total_papers} 篇论文</span>
  1271. <span>🧠 分析 ${data.summary.analyzed_papers} 篇</span>
  1272. <span>📝 生成 ${data.summary.generated_citations} 条引用</span>
  1273. </div>
  1274. <p style="margin-top: 10px; color: #666;">关键词: ${data.summary.keywords}</p>
  1275. </div>
  1276. `;
  1277. }
  1278. // 显示各步骤结果
  1279. if (data.steps && data.steps.length > 0) {
  1280. data.steps.forEach((step, index) => {
  1281. const statusIcon = step.status === 'completed' ? '✅' : step.status === 'failed' ? '❌' : '⏳';
  1282. html += `
  1283. <div class="paper-card">
  1284. <h4>${statusIcon} 步骤 ${step.step}: ${step.name}</h4>
  1285. `;
  1286. if (step.status === 'completed' && step.result) {
  1287. // 论文搜索结果
  1288. if (step.result.papers) {
  1289. html += `<p>找到 ${step.result.total_found} 篇论文</p>`;
  1290. step.result.papers.slice(0, 3).forEach((paper, i) => {
  1291. html += `
  1292. <div style="margin: 10px 0; padding: 10px; background: #f8f9fa; border-radius: 5px;">
  1293. <strong>${i + 1}. ${escapeHtml(paper.title)}</strong><br>
  1294. <small>作者: ${paper.authors.slice(0, 3).join(', ')}${paper.authors.length > 3 ? ' et al.' : ''}</small>
  1295. </div>
  1296. `;
  1297. });
  1298. }
  1299. // 分析结果
  1300. if (step.result.analyses) {
  1301. html += `<p>完成 ${step.result.total_analyzed} 篇论文分析</p>`;
  1302. step.result.analyses.forEach((analysis, i) => {
  1303. html += `
  1304. <div style="margin: 10px 0; padding: 10px; background: #f0f7ff; border-radius: 5px;">
  1305. <strong>${i + 1}. ${escapeHtml(analysis.title)}</strong>
  1306. <div class="markdown-content" style="margin-top: 10px;">
  1307. ${renderMarkdown(analysis.analysis.substring(0, 500) + '...')}
  1308. </div>
  1309. </div>
  1310. `;
  1311. });
  1312. }
  1313. // 引用结果
  1314. if (step.result.citations) {
  1315. html += `<p>生成 ${step.result.total_citations} 条引用</p>`;
  1316. const citationId = 'citations-' + Date.now();
  1317. html += `<button class="copy-btn" onclick="copyToClipboard('${citationId}', event)">📋 复制全部引用</button>`;
  1318. html += `<div id="${citationId}" style="margin-top: 10px;">`;
  1319. step.result.citations.forEach((citation, i) => {
  1320. html += `<p style="margin: 5px 0;">${i + 1}. ${escapeHtml(citation.formatted_citation)}</p>`;
  1321. });
  1322. html += '</div>';
  1323. }
  1324. // 报告结果
  1325. if (step.result.report) {
  1326. const reportId = 'report-' + Date.now();
  1327. html += `<button class="copy-btn" onclick="copyToClipboard('${reportId}', event)">📋 复制报告</button>`;
  1328. html += `<div class="markdown-content" id="${reportId}" style="margin-top: 10px;">`;
  1329. html += renderMarkdown(step.result.report);
  1330. html += '</div>';
  1331. }
  1332. } else if (step.status === 'failed') {
  1333. html += `<p style="color: #f44336;">错误: ${step.error}</p>`;
  1334. }
  1335. html += '</div>';
  1336. });
  1337. }
  1338. return html;
  1339. }
  1340. // HTML 转义函数
  1341. function escapeHtml(text) {
  1342. const div = document.createElement('div');
  1343. div.textContent = text;
  1344. return div.innerHTML;
  1345. }
  1346. // JSON 语法高亮
  1347. function syntaxHighlight(json) {
  1348. json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
  1349. return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
  1350. let cls = 'json-number';
  1351. if (/^"/.test(match)) {
  1352. if (/:$/.test(match)) {
  1353. cls = 'json-key';
  1354. } else {
  1355. cls = 'json-string';
  1356. }
  1357. } else if (/true|false/.test(match)) {
  1358. cls = 'json-boolean';
  1359. } else if (/null/.test(match)) {
  1360. cls = 'json-null';
  1361. }
  1362. return '<span class="' + cls + '">' + match + '</span>';
  1363. });
  1364. }
  1365. // 复制到剪贴板
  1366. function copyToClipboard(elementId, event) {
  1367. // 阻止事件冒泡
  1368. if (event) {
  1369. event.preventDefault();
  1370. event.stopPropagation();
  1371. }
  1372. const element = document.getElementById(elementId);
  1373. if (!element) {
  1374. return;
  1375. }
  1376. // 获取纯文本内容
  1377. const text = element.innerText || element.textContent;
  1378. navigator.clipboard.writeText(text).then(() => {
  1379. // 显示复制成功提示
  1380. const btn = event ? event.target : null;
  1381. if (btn) {
  1382. const originalText = btn.textContent;
  1383. btn.textContent = '✅ 已复制';
  1384. btn.style.background = '#4caf50';
  1385. btn.style.color = 'white';
  1386. btn.style.borderColor = '#4caf50';
  1387. setTimeout(() => {
  1388. btn.textContent = originalText;
  1389. btn.style.background = '';
  1390. btn.style.color = '';
  1391. btn.style.borderColor = '';
  1392. }, 2000);
  1393. }
  1394. console.log('已复制 ' + text.length + ' 个字符');
  1395. }).catch(err => {
  1396. console.error('复制失败:', err);
  1397. alert('复制失败,请手动选择文本复制');
  1398. });
  1399. }
  1400. // 显示错误消息
  1401. function showError(responseId, message) {
  1402. const responseDiv = document.getElementById(responseId);
  1403. responseDiv.innerHTML = `
  1404. <div class="error">
  1405. ❌ ${message}
  1406. </div>
  1407. `;
  1408. }
  1409. </script>
  1410. </body>
  1411. </html>