Repository navigation
Expand file tree
/
Copy pathanalogy_detail.html
More file actions
658 lines (612 loc) · 22.8 KB
/
Copy pathanalogy_detail.html
File metadata and controls
658 lines (612 loc) · 22.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#FAFAF9">
<title>深度类比 — Phase Detector</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Noto+Serif+SC:wght@400;500;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.css">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.js"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/contrib/auto-render.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<style>
:root {
--bg: #FAFAF9;
--bg-elevated: #FFFFFF;
--bg-card: #F4F4F5;
--border: #E4E4E7;
--border-strong: #D4D4D8;
--text: #18181B;
--text-secondary: #52525B;
--text-muted: #71717A;
--text-dim: #A1A1AA;
--accent: #2563EB;
--accent-dim: rgba(37, 99, 235, 0.08);
--green: #059669;
--amber: #D97706;
--red: #DC2626;
--mono: 'JetBrains Mono', 'Menlo', monospace;
--serif: 'Noto Serif SC', 'Times New Roman', serif;
--sans: 'Inter', -apple-system, system-ui, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
background: var(--bg);
color: var(--text);
font-family: var(--sans);
font-size: 16px;
line-height: 1.75;
-webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
header.site {
border-bottom: 1px solid var(--border);
padding: 20px 0;
position: sticky; top: 0;
background: rgba(250, 250, 249, 0.88);
backdrop-filter: saturate(180%) blur(12px);
z-index: 100;
}
.container { max-width: 820px; margin: 0 auto; padding: 0 24px; }
.nav { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; color: var(--text); }
.brand-mark { width: 20px; height: 20px; border: 1.5px solid var(--accent); border-radius: 50%; position: relative; }
.brand-mark::before { content: ''; position: absolute; inset: 3px; border-radius: 50%; background: var(--accent); }
.brand-beta { font-size: 10px; padding: 2px 6px; background: var(--accent-dim); color: var(--accent); border-radius: 3px; font-weight: 600; }
nav.menu a { margin-left: 20px; font-size: 14px; color: var(--text-muted); }
nav.menu a:hover { color: var(--text); text-decoration: none; }
main { padding: 40px 0 100px; }
.breadcrumb {
font-size: 13px;
color: var(--text-muted);
margin-bottom: 24px;
}
.breadcrumb a { color: var(--text-muted); }
.detail-head {
margin-bottom: 36px;
}
.detail-eyebrow {
font-family: var(--mono);
font-size: 11px;
color: var(--accent);
letter-spacing: 1.5px;
margin-bottom: 12px;
}
.detail-title {
font-family: var(--serif);
font-size: clamp(28px, 3.5vw, 36px);
font-weight: 600;
line-height: 1.25;
letter-spacing: -0.01em;
margin-bottom: 16px;
color: var(--text);
}
.detail-mapping {
display: flex;
align-items: center;
gap: 14px;
flex-wrap: wrap;
padding: 14px 18px;
background: var(--accent-dim);
border-radius: 8px;
font-size: 14px;
}
.detail-mapping__tag {
font-family: var(--mono);
font-size: 11px;
color: var(--text-muted);
letter-spacing: 0.5px;
text-transform: uppercase;
}
.detail-mapping__company {
font-weight: 500;
color: var(--text);
}
.detail-mapping__arrow {
color: var(--accent);
font-weight: 600;
}
.report {
padding: 40px 48px;
background: var(--bg-elevated);
border: 1px solid var(--border);
border-radius: 12px;
color: var(--text-secondary);
}
.report h1, .report h2, .report h3 {
font-family: var(--serif);
color: var(--text);
line-height: 1.3;
letter-spacing: -0.005em;
}
.report h1 { font-size: 28px; margin: 0 0 20px; font-weight: 600; }
.report h2 {
font-size: 22px;
margin: 36px 0 16px;
padding-top: 24px;
border-top: 1px solid var(--border);
font-weight: 600;
}
.report h2:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.report h3 { font-size: 17px; margin: 24px 0 12px; font-weight: 600; color: var(--text); }
.report p { margin: 12px 0; line-height: 1.85; }
.report ul, .report ol { margin: 12px 0 12px 24px; }
.report li { margin: 6px 0; line-height: 1.75; }
.report strong { color: var(--text); font-weight: 600; }
.report code {
font-family: var(--mono);
font-size: 0.88em;
background: var(--bg-card);
padding: 2px 6px;
border-radius: 3px;
color: var(--text);
}
.report blockquote {
border-left: 3px solid var(--accent);
padding: 10px 18px;
margin: 16px 0;
color: var(--text-muted);
background: var(--bg-card);
border-radius: 0 6px 6px 0;
}
.report table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
font-size: 14px;
}
.report th, .report td {
padding: 10px 12px;
border: 1px solid var(--border);
text-align: left;
}
.report th {
background: var(--bg-card);
font-weight: 600;
color: var(--text);
}
.report hr {
border: 0;
border-top: 1px solid var(--border);
margin: 32px 0;
}
.report .katex { color: var(--text); font-size: 1.05em; }
.report .katex-display {
margin: 20px 0;
padding: 14px 16px;
background: var(--bg-card);
border-radius: 6px;
overflow-x: auto;
}
.report .katex-display > .katex { font-size: 1.1em; }
@media (max-width: 520px) {
.report { padding: 24px 22px; }
.report h1 { font-size: 23px; }
.report h2 { font-size: 19px; }
.report .katex { font-size: 0.96em; }
.report .katex-display > .katex { font-size: 1em; }
}
.typing-cursor {
display: inline-block;
color: var(--accent);
font-weight: 600;
animation: cursor-blink 1s steps(2) infinite;
margin-left: 2px;
}
@keyframes cursor-blink {
to { opacity: 0; }
}
.loader {
display: flex;
flex-direction: column;
align-items: center;
gap: 16px;
padding: 80px 20px;
color: var(--text-muted);
}
.loading-dots {
display: inline-flex;
gap: 6px;
}
.loading-dots span {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--accent);
opacity: 0.4;
animation: dot-pulse 1.4s infinite ease-in-out;
}
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dot-pulse {
0%, 60%, 100% { opacity: 0.3; transform: scale(0.9); }
30% { opacity: 1; transform: scale(1.15); }
}
.loader__text { font-size: 14px; text-align: center; }
.loader__elapsed { font-family: var(--mono); font-size: 12px; color: var(--text-dim); }
.error-box {
padding: 40px 32px;
background: #FEF2F2;
border: 1px solid #FECACA;
border-radius: 12px;
color: var(--red);
text-align: center;
}
.back-cta {
margin-top: 32px;
text-align: center;
}
.btn-back {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 10px 20px;
background: transparent;
color: var(--text-secondary);
border: 1px solid var(--border-strong);
border-radius: 8px;
font-size: 14px;
text-decoration: none;
transition: all 0.15s;
}
.btn-back:hover {
border-color: var(--accent);
color: var(--accent);
text-decoration: none;
}
footer.site { padding: 40px 0; border-top: 1px solid var(--border); font-size: 13px; color: var(--text-muted); margin-top: 40px; }
.footer-row { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 20px; }
.footer-links a { color: var(--text-muted); margin-left: 16px; }
</style>
</head>
<body>
<header class="site">
<div class="container nav">
<a href="/phase" class="brand">
<span class="brand-mark"></span>
Phase Detector
<span class="brand-beta">BETA</span>
</a>
<nav class="menu">
<a href="/phase/screener">筛选器</a>
<a href="/phase/analogy">类比引擎</a>
<a href="/phase/redteam">Thesis 红队</a>
</nav>
</div>
</header>
<main>
<div class="container">
<div class="breadcrumb" id="breadcrumb">
<a href="/phase/analogy">类比引擎</a> · 加载中…
</div>
<div id="content"></div>
</div>
</main>
<footer class="site">
<div class="container footer-row">
<div>© 2026 Phase Detector · Structural Analogy Engine</div>
<div class="footer-links">
<a href="/phase">Phase 首页</a>
<a href="https://github.com/dada8899/structural-isomorphism">GitHub</a>
</div>
</div>
</footer>
<script>
const escapeHtml = (s) => String(s || '').replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]));
// Read context from sessionStorage (set by list page)
let context = null;
try {
const raw = sessionStorage.getItem('phase_analogy_detail_ctx');
if (raw) context = JSON.parse(raw);
} catch (_) {}
const ticker = new URLSearchParams(window.location.search).get('t') || (context && context.ticker) || '';
async function init() {
const content = document.getElementById('content');
const bc = document.getElementById('breadcrumb');
if (!context || !context.ticker || !context.target) {
content.innerHTML = `
<div class="error-box">
<p>没有类比上下文。请回到<a href="/phase/analogy${ticker ? '?t=' + encodeURIComponent(ticker) : ''}">类比引擎列表页</a>,从卡片点「深度展开」。</p>
</div>
`;
bc.innerHTML = `<a href="/phase/analogy">类比引擎</a> · 缺少上下文`;
return;
}
const ctk = context.ticker;
const cname = (context.struct && context.struct.name) || ctk;
const tgtCompany = context.target.company || '?';
const tgtPeriod = context.target.period || '?';
document.title = `${cname} × ${tgtCompany} ${tgtPeriod} — Phase Detector`;
bc.innerHTML = `<a href="/phase/analogy?t=${encodeURIComponent(ctk)}">类比引擎 · ${escapeHtml(ctk)}</a> · <span>深度分析</span>`;
// Header
content.innerHTML = `
<div class="detail-head">
<div class="detail-eyebrow">STRUCTURAL ANALOGY · DEEP DIVE</div>
<h1 class="detail-title">${escapeHtml(cname)} <span style="color: var(--text-muted); font-weight: 400;">像</span> ${escapeHtml(tgtCompany)}</h1>
<div class="detail-mapping">
<span class="detail-mapping__tag">当前</span>
<span class="detail-mapping__company">${escapeHtml(cname)} <small style="color: var(--text-muted); font-family: var(--mono);">(${escapeHtml(ctk)})</small></span>
<span class="detail-mapping__arrow">≅</span>
<span class="detail-mapping__tag">历史</span>
<span class="detail-mapping__company">${escapeHtml(tgtCompany)} · ${escapeHtml(tgtPeriod)}</span>
</div>
</div>
<div id="report-slot"></div>
`;
const slot = document.getElementById('report-slot');
const startTs = Date.now();
// 准备流式容器
slot.innerHTML = `
<article class="report" id="live-report">
<div class="loader" id="stream-loader">
<span class="loading-dots"><span></span><span></span><span></span></span>
<div class="loader__text" id="stream-status">连接中…</div>
<span class="loader__elapsed" id="loader-elapsed">0s</span>
</div>
</article>
`;
const timerId = setInterval(() => {
const el = document.getElementById('loader-elapsed');
if (el) el.textContent = Math.round((Date.now() - startTs) / 1000) + 's';
}, 500);
let fullText = '';
let modelName = '';
let lastRenderedLen = 0;
let pendingRender = false;
const liveReport = document.getElementById('live-report');
const statusEl = document.getElementById('stream-status');
// 数学保护:只在真需要的时候跑(每次 regex 很贵)
// 大文本时缓存结果(但我们要每次新增渲染,不缓存)
// 用 String.prototype.split + 简单状态机代替嵌套 regex,避免灾难性回溯
function safeMarkedParse(md) {
if (!window.marked) return escapeHtml(md).replace(/\n/g, '<br>');
// 用有限状态机把 $$..$$ 和 $..$ 提取(避免复杂 lookbehind regex 回溯)
const blocks = [];
let out = '';
let i = 0;
const n = md.length;
while (i < n) {
const c = md[i];
// $$...$$
if (c === '$' && md[i + 1] === '$') {
const end = md.indexOf('$$', i + 2);
if (end >= 0) {
blocks.push(md.slice(i, end + 2));
out += '@@MATHBLK' + (blocks.length - 1) + '@@';
i = end + 2;
continue;
}
}
// \[...\]
if (c === '\\' && md[i + 1] === '[') {
const end = md.indexOf('\\]', i + 2);
if (end >= 0) {
blocks.push(md.slice(i, end + 2));
out += '@@MATHBLK' + (blocks.length - 1) + '@@';
i = end + 2;
continue;
}
}
// \(...\)
if (c === '\\' && md[i + 1] === '(') {
const end = md.indexOf('\\)', i + 2);
if (end >= 0) {
blocks.push(md.slice(i, end + 2));
out += '@@MATHBLK' + (blocks.length - 1) + '@@';
i = end + 2;
continue;
}
}
// inline $...$ (only if not double $$, not escaped)
if (c === '$' && md[i + 1] !== '$' && md[i - 1] !== '\\') {
// find closing $
let j = i + 1;
while (j < n && j < i + 200) {
if (md[j] === '\n') break; // don't cross newlines
if (md[j] === '$' && md[j - 1] !== '\\' && md[j + 1] !== '$') {
break;
}
j++;
}
if (j < n && md[j] === '$') {
blocks.push(md.slice(i, j + 1));
out += '@@MATHBLK' + (blocks.length - 1) + '@@';
i = j + 1;
continue;
}
}
out += c;
i++;
}
let html = window.marked.parse(out);
html = html.replace(/@@MATHBLK(\d+)@@/g, (_, idx) => blocks[Number(idx)] || '');
return html;
}
let renderRafId = null;
function scheduleRender(final) {
if (final) {
// 最终渲染:立即
if (renderRafId) cancelAnimationFrame(renderRafId);
doRender(true);
return;
}
if (pendingRender) return;
pendingRender = true;
// 用 requestAnimationFrame + 最少 600ms 间隔
// 大文本时人眼看每秒 1-2 次更新已经很流畅,过快反而卡
setTimeout(() => {
if (renderRafId) cancelAnimationFrame(renderRafId);
renderRafId = requestAnimationFrame(() => doRender(false));
}, 600);
}
function doRender(final) {
pendingRender = false;
renderRafId = null;
// 如果自上次渲染后没新增 → 跳过
if (!final && fullText.length === lastRenderedLen) return;
lastRenderedLen = fullText.length;
// 流式中保护未闭合的数学块
let renderText = fullText;
if (!final) {
// 找最后一个未闭合的 $$(快速方法:末尾包含奇数个 $$?)
// 简化:如果末尾 100 字符里有 $$ 没闭合,截掉
const tail = renderText.slice(-200);
const doubleCount = (tail.match(/\$\$/g) || []).length;
if (doubleCount % 2 === 1) {
const lastDouble = renderText.lastIndexOf('$$');
if (lastDouble >= 0) renderText = renderText.slice(0, lastDouble);
} else {
// 单 $ 检查(只看末尾 200 字符)
const tail2 = renderText.slice(-200);
const dollarCount = (tail2.replace(/\$\$/g, '').match(/\$/g) || []).length;
if (dollarCount % 2 === 1) {
const lastDollar = renderText.lastIndexOf('$');
if (lastDollar >= 0 && renderText[lastDollar - 1] !== '$' && renderText[lastDollar + 1] !== '$') {
renderText = renderText.slice(0, lastDollar);
}
}
}
}
const html = safeMarkedParse(renderText);
liveReport.innerHTML = html;
if (!final) {
const cursor = document.createElement('span');
cursor.className = 'typing-cursor';
cursor.textContent = '▌';
liveReport.appendChild(cursor);
}
}
function renderLive(final) {
scheduleRender(final);
}
try {
const resp = await fetch('/phase/api/analogy-detail/stream', {
method: 'POST',
headers: {'Content-Type': 'application/json', 'Accept': 'text/event-stream'},
body: JSON.stringify({
ticker: ctk,
struct: context.struct,
target: context.target,
}),
});
if (!resp.ok) {
const text = await resp.text();
throw new Error(`HTTP ${resp.status}: ${text.slice(0, 200)}`);
}
const reader = resp.body.getReader();
const decoder = new TextDecoder();
let buffer = '';
let currentEvent = 'message';
while (true) {
const {value, done} = await reader.read();
if (done) break;
buffer += decoder.decode(value, {stream: true});
// 按 SSE 分割:空行分隔 event
const lines = buffer.split('\n');
buffer = lines.pop() ?? '';
for (const rawLine of lines) {
const line = rawLine.replace(/\r$/, '');
if (!line) {
// event boundary,下一行新 event
currentEvent = 'message';
continue;
}
if (line.startsWith(':')) continue; // comment (OPENROUTER PROCESSING)
if (line.startsWith('event: ')) {
currentEvent = line.slice(7).trim();
continue;
}
if (line.startsWith('data: ')) {
const payload = line.slice(6);
if (payload === '[DONE]') continue;
if (currentEvent === 'meta') {
try {
const meta = JSON.parse(payload);
modelName = meta.model || '';
if (statusEl) statusEl.textContent = `${modelName} 正在深挖…`;
} catch {}
continue;
}
if (currentEvent === 'error') {
try {
const err = JSON.parse(payload);
throw new Error(err.error || '流式错误');
} catch (e) {
throw e;
}
}
if (currentEvent === 'done') continue;
// 正常 message chunk
try {
const chunk = JSON.parse(payload);
const delta = chunk.choices?.[0]?.delta?.content;
if (delta) {
fullText += delta;
renderLive(false);
}
const finishReason = chunk.choices?.[0]?.finish_reason;
if (finishReason === 'length') {
// LLM 因 max_tokens 被截断
fullText += '\n\n> ⚠️ **内容因长度限制被截断**。如需完整分析,请重试(刷新本页)。';
renderLive(true);
}
} catch {}
}
}
}
// 最终渲染
clearInterval(timerId);
renderLive(true);
// KaTeX 一次性渲染(流式中渲染太卡)
if (window.renderMathInElement) {
try {
renderMathInElement(liveReport, {
delimiters: [
{left: '$$', right: '$$', display: true},
{left: '$', right: '$', display: false},
{left: '\\[', right: '\\]', display: true},
{left: '\\(', right: '\\)', display: false},
],
throwOnError: false,
});
} catch {}
}
// 附加返回链接 + 模型标注
const backCta = document.createElement('div');
backCta.className = 'back-cta';
backCta.innerHTML = `<a class="btn-back" href="/phase/analogy?t=${encodeURIComponent(ctk)}">← 回到 ${escapeHtml(ctk)} 的 3 个类比</a>`;
liveReport.insertAdjacentElement('afterend', backCta);
if (modelName) {
const meta = document.createElement('div');
meta.style.cssText = 'text-align: right; margin-top: 16px; font-size: 11px; color: var(--text-dim); font-family: var(--mono);';
meta.textContent = `由 ${modelName} 流式生成 · ${fullText.length} 字符 · 用时 ${Math.round((Date.now() - startTs)/1000)}s`;
backCta.insertAdjacentElement('afterend', meta);
}
} catch (err) {
clearInterval(timerId);
if (!fullText) {
slot.innerHTML = `
<div class="error-box">
<p><strong>生成失败</strong>:${escapeHtml(err.message)}</p>
<p style="margin-top: 12px;"><a href="/phase/analogy?t=${encodeURIComponent(ctk)}">← 返回类比列表</a></p>
</div>
`;
} else {
// 已有部分内容,标注中断
renderLive(true);
const warn = document.createElement('div');
warn.style.cssText = 'margin-top: 16px; padding: 12px 16px; background: #FEF2F2; border-left: 3px solid #DC2626; border-radius: 6px; color: #991B1B; font-size: 13px;';
warn.textContent = `流式中断:${err.message}`;
liveReport.insertAdjacentElement('afterend', warn);
}
}
}
init();
</script>
<script src="/assets/js/product-switcher.js?v=20260417b"></script>
</body>
</html>