-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
549 lines (499 loc) · 17.4 KB
/
index.html
File metadata and controls
549 lines (499 loc) · 17.4 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>N.O.V.A. Chat</title>
<style>
:root {
--bg: #f9f8f6; /* 柔和的米白色背景 */
--sidebar-bg: #f0eee9;
--panel: #ffffff;
--text: #2c2c2c;
--text-muted: #666;
--accent: #000000;
--user-msg-bg: #e3f2fd; /* 用户消息浅蓝色 */
--border: #e0e0e0;
--radius: 12px;
--shadow: 0 4px 12px rgba(0,0,0,0.05);
--font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
body {
margin: 0;
font-family: var(--font-sans);
background: var(--bg);
color: var(--text);
height: 100vh;
overflow: hidden;
display: flex;
}
/* 侧边栏样式 */
.sidebar {
width: 260px;
background: var(--sidebar-bg);
border-right: 1px solid var(--border);
display: flex;
flex-direction: column;
transform: translateX(-100%);
position: absolute;
top: 0; bottom: 0; left: 0;
z-index: 100;
transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
box-shadow: 2px 0 10px rgba(0,0,0,0.1);
}
.sidebar.open { transform: translateX(0); }
/* 大屏幕下侧边栏默认显示逻辑可按需调整,这里默认收起需点击打开,或配合JS做响应式 */
@media (min-width: 900px) {
.sidebar { position: relative; transform: translateX(0); box-shadow: none; }
.sidebar-toggle { display: none; } /* 大屏可选择隐藏切换按钮 */
}
.sidebar-header {
padding: 20px;
display: flex;
justify-content: space-between;
align-items: center;
}
.new-chat-btn {
margin: 0 15px;
padding: 10px;
background: var(--panel);
border: 1px solid var(--border);
border-radius: 8px;
cursor: pointer;
display: flex;
align-items: center;
gap: 8px;
font-weight: 500;
color: var(--text);
transition: all 0.2s;
}
.new-chat-btn:hover { background: #fff; box-shadow: var(--shadow); }
.chat-list {
flex: 1;
overflow-y: auto;
padding: 15px;
display: flex;
flex-direction: column;
gap: 8px;
}
.chat-item {
padding: 10px 12px;
border-radius: 8px;
cursor: pointer;
font-size: 14px;
color: var(--text-muted);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
transition: background 0.2s;
}
.chat-item:hover { background: rgba(0,0,0,0.05); color: var(--text); }
.chat-item.active { background: #e0e0e0; color: var(--accent); font-weight: 600; }
/* 主区域 */
.main {
flex: 1;
position: relative;
display: flex;
flex-direction: column;
height: 100%;
background: var(--bg);
}
.topbar {
padding: 15px 20px;
display: flex;
align-items: center;
justify-content: space-between;
z-index: 10;
}
.toggle-btn {
background: none;
border: none;
cursor: pointer;
padding: 8px;
border-radius: 6px;
}
.toggle-btn:hover { background: rgba(0,0,0,0.05); }
/* 聊天记录区域 */
.chat-container {
flex: 1;
overflow-y: auto;
padding: 20px 0;
scroll-behavior: smooth;
display: flex;
flex-direction: column;
align-items: center;
}
.messages-wrapper {
width: 100%;
max-width: 800px;
padding: 0 20px;
padding-bottom: 120px; /* 给底部输入框留空间 */
}
.message {
margin-bottom: 30px;
line-height: 1.6;
animation: fadeIn 0.3s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.message.user {
display: flex;
justify-content: flex-end;
}
.message.user .bubble {
background: var(--user-msg-bg);
padding: 12px 18px;
border-radius: 18px 18px 4px 18px;
color: var(--text);
max-width: 80%;
box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.message.ai {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 8px;
}
.message.ai .bubble {
background: transparent;
padding: 0;
color: var(--text);
max-width: 100%;
}
/* AI 下方的工具栏 (复制/朗读/重试) */
.msg-actions {
display: flex;
gap: 12px;
margin-top: 5px;
opacity: 0;
transition: opacity 0.2s;
}
.message.ai:hover .msg-actions { opacity: 1; } /* 悬停显示 */
.action-btn {
background: none;
border: 1px solid var(--border);
border-radius: 6px;
padding: 4px 8px;
font-size: 12px;
cursor: pointer;
color: var(--text-muted);
display: flex;
align-items: center;
gap: 4px;
transition: all 0.2s;
}
.action-btn:hover { background: #fff; color: var(--accent); border-color: #bbb; }
/* 输入框区域 - 核心交互 */
.input-area {
position: absolute;
bottom: 0; left: 0; right: 0;
padding: 20px;
display: flex;
justify-content: center;
background: linear-gradient(to top, var(--bg) 80%, transparent);
transition: all 0.5s ease;
}
/* 当没有消息时(初始状态),输入框居中 */
.main.empty .input-area {
top: 0; bottom: 0;
align-items: center;
background: var(--bg);
flex-direction: column;
gap: 20px;
}
.main.empty .welcome-text { display: block; }
.welcome-text { display: none; text-align: center; margin-bottom: 20px; }
.welcome-text h1 { font-size: 32px; font-weight: 500; margin: 0 0 10px 0; color: #2c2c2c; }
.input-box {
width: 100%;
max-width: 700px;
background: #fff;
border-radius: 24px;
box-shadow: 0 4px 20px rgba(0,0,0,0.08);
border: 1px solid transparent;
padding: 10px 15px;
display: flex;
align-items: flex-end;
gap: 10px;
transition: all 0.3s;
}
.input-box:focus-within {
border-color: #d0d0d0;
box-shadow: 0 6px 24px rgba(0,0,0,0.12);
}
#input {
flex: 1;
border: none;
resize: none;
padding: 12px 5px;
font-family: var(--font-sans);
font-size: 16px;
outline: none;
max-height: 200px;
min-height: 24px;
color: var(--text);
}
#run {
background: #e0e0e0;
border: none;
border-radius: 50%;
width: 36px;
height: 36px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
color: #555;
transition: background 0.2s;
}
#run:hover { background: #000; color: #fff; }
#run svg { width: 18px; height: 18px; fill: currentColor; }
/* 隐藏元素 */
.hidden { display: none !important; }
</style>
</head>
<body>
<aside class="sidebar" id="sidebar">
<div class="sidebar-header">
<span style="font-weight:700; letter-spacing:-0.5px;">N.O.V.A.</span>
<button class="toggle-btn" onclick="toggleSidebar()" style="background:none; border:none; cursor:pointer">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M18 6L6 18M6 6l12 12"/></svg>
</button>
</div>
<div class="new-chat-btn" id="new-chat">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 5v14M5 12h14"/></svg>
New Chat
</div>
<div class="chat-list" id="chat-list">
</div>
<div style="padding: 15px; border-top:1px solid var(--border);">
<label style="font-size:12px; color:var(--text-muted); display:block; line-height:1.6;">
Snapshot auto-loads locally at startup. Place <code>model.snapshot</code> beside this page.
</label>
</div>
</aside>
<main class="main empty" id="main-container">
<div class="topbar">
<button class="toggle-btn" onclick="toggleSidebar()">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M3 12h18M3 6h18M3 18h18"/></svg>
</button>
<div id="status" style="font-size:12px; color:var(--text-muted); background:rgba(0,0,0,0.05); padding:4px 8px; border-radius:12px;">Idle</div>
</div>
<div class="chat-container" id="scroll-container">
<div class="welcome-text">
<h1>Hey, what's on your mind?</h1>
</div>
<div class="messages-wrapper" id="log-display">
</div>
</div>
<div class="input-area">
<div class="input-box">
<div style="padding:12px 5px; cursor:pointer; color:#999;">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><path d="M12 8v8M8 12h8"/></svg>
</div>
<textarea id="input" rows="1" placeholder="Message Copilot..."></textarea>
<button id="run">
<svg viewBox="0 0 24 24"><path d="M2.01 21L23 12 2.01 3 2 10l15 2-15 2z"/></svg>
</button>
</div>
</div>
<div id="log" style="display:none;"></div>
</main>
<script>
// UI wiring
const statusEl = document.getElementById("status");
const logEl = document.getElementById("log"); // hidden legacy log used by main.js
const logDisplay = document.getElementById("log-display");
const inputEl = document.getElementById("input");
const scrollContainer = document.getElementById("scroll-container");
const sidebar = document.getElementById("sidebar");
const runBtn = document.getElementById("run");
const urlParams = new URLSearchParams(location.search);
const snapshotParam = urlParams.get("snapshot");
const snapshotCandidates = Array.from(new Set([
snapshotParam ? snapshotParam : null,
window.novaSnapshotName || null,
"./model.snapshot",
"./nova_snapshot_latest.snapshot"
].filter(Boolean)));
window.SKIP_TRAINING = true; // snapshot-only mode
window.novaDeferBootstrap = true; // start after snapshot is ready
window.novaOverrides = { enableHeuristics: false };
const messages = [];
let snapshotBuffer = null;
let currentSnapshotName = snapshotCandidates[0] || "./model.snapshot";
let startRequested = false;
const processedLogLines = new Set();
function toggleSidebar() {
sidebar.classList.toggle("open");
}
const appendMessage = (role, text) => {
const row = document.createElement("div");
row.className = `message ${role === "user" ? "user" : "ai"}`;
const bubble = document.createElement("div");
bubble.className = "bubble";
bubble.innerText = text;
row.appendChild(bubble);
if (role !== "user") {
const actions = document.createElement("div");
actions.className = "msg-actions";
const btnCopy = document.createElement("button");
btnCopy.className = "action-btn";
btnCopy.innerHTML = `<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg> Copy`;
btnCopy.onclick = () => {
navigator.clipboard.writeText(text);
btnCopy.textContent = "Copied!";
setTimeout(() => (btnCopy.innerHTML = `<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg> Copy`), 1000);
};
actions.appendChild(btnCopy);
row.appendChild(actions);
}
messages.push({ role, text });
logDisplay.appendChild(row);
scrollContainer.scrollTop = scrollContainer.scrollHeight;
document.getElementById("main-container").classList.toggle("empty", messages.length === 0);
};
const pruneProcessed = () => {
if (processedLogLines.size <= 300) return;
const excess = processedLogLines.size - 300;
const it = processedLogLines.values();
for (let i = 0; i < excess; i += 1) {
processedLogLines.delete(it.next().value);
}
};
const syncFromLog = () => {
const lines = logEl.textContent.split("\n").filter(Boolean);
for (let idx = lines.length - 1; idx >= 0; idx -= 1) {
const rawLine = lines[idx];
if (processedLogLines.has(rawLine)) continue;
processedLogLines.add(rawLine);
const line = rawLine.replace(/^\[[^\]]+\]\s*/, "");
const userMatch = line.match(/^User:\s*(.*)$/i);
if (userMatch && userMatch[1]) {
appendMessage("user", userMatch[1]);
continue;
}
const aiMatch = line.match(/^AI:\s*(.*)$/i);
if (aiMatch && aiMatch[1]) {
appendMessage("ai", aiMatch[1]);
}
}
pruneProcessed();
};
const logObserver = new MutationObserver(syncFromLog);
logObserver.observe(logEl, { childList: true, subtree: true, characterData: true });
// Input helpers
inputEl.addEventListener("keydown", (e) => {
if (e.key === "Enter" && !e.shiftKey) {
e.preventDefault();
runBtn.click();
}
});
inputEl.addEventListener("input", function () {
this.style.height = "auto";
this.style.height = `${this.scrollHeight}px`;
});
const startWhenReady = () => {
if (startRequested) return;
startRequested = true;
const wait = () => {
if (window.startNova && window.novaOverrides.manualSnapshot) {
statusEl.textContent = "Booting with snapshot...";
window.startNova();
} else {
setTimeout(wait, 150);
}
};
wait();
};
const decodeSnapshotBuffer = async () => {
if (!snapshotBuffer) return false;
if (!window.decodeSnapshotBuffer) {
statusEl.textContent = "Waiting for decoder...";
setTimeout(decodeSnapshotBuffer, 150);
return false;
}
try {
const snap = await window.decodeSnapshotBuffer(snapshotBuffer);
if (!snap) throw new Error("parser returned null");
window.novaOverrides.manualSnapshot = snap;
statusEl.textContent = `Snapshot ready (${currentSnapshotName})`;
startWhenReady();
return true;
} catch (err) {
try {
const text = new TextDecoder().decode(new Uint8Array(snapshotBuffer));
const parsed = JSON.parse(text);
if (!parsed) throw new Error("empty JSON");
window.novaOverrides.manualSnapshot = parsed;
statusEl.textContent = `Snapshot ready (${currentSnapshotName})`;
startWhenReady();
return true;
} catch (jsonErr) {
statusEl.textContent = `Snapshot decode failed (${currentSnapshotName})`;
runBtn.disabled = true;
console.error("Snapshot decode failed", currentSnapshotName, err, jsonErr);
return false;
}
} finally {
snapshotBuffer = null;
}
};
const looksLikeHtml = (buffer) => {
const prefix = new Uint8Array(buffer, 0, Math.min(buffer.byteLength, 64));
const asText = new TextDecoder().decode(prefix).toLowerCase();
return asText.includes("<!doctype") || asText.includes("<html");
};
const fetchSnapshot = async () => {
let lastError = null;
for (const candidate of snapshotCandidates) {
currentSnapshotName = candidate;
statusEl.textContent = `Loading snapshot (${candidate})...`;
try {
const res = await fetch(candidate);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const buf = await res.arrayBuffer();
if (!buf || buf.byteLength === 0) throw new Error("empty file");
if (looksLikeHtml(buf)) throw new Error("got HTML instead of snapshot");
snapshotBuffer = buf;
// Ensure decoder is ready before concluding failure.
if (!window.decodeSnapshotBuffer) {
await new Promise((resolve) => {
const wait = () => {
if (window.decodeSnapshotBuffer) return resolve();
setTimeout(wait, 100);
};
wait();
});
}
const ok = await decodeSnapshotBuffer();
if (!ok || !window.novaOverrides.manualSnapshot) {
throw new Error("decode returned null");
}
return true;
} catch (err) {
statusEl.textContent = `Snapshot failed (${candidate}: ${err.message})`;
console.error("Snapshot fetch failed", candidate, err);
snapshotBuffer = null;
lastError = err;
}
}
statusEl.textContent = lastError
? `Snapshot decode failed (last error: ${lastError.message})`
: "Snapshot decode failed (no valid candidate)";
runBtn.disabled = true;
return false;
};
// Auto-load snapshot immediately
fetchSnapshot();
// Sidebar reset chat
document.getElementById("new-chat").onclick = () => {
messages.length = 0;
logDisplay.innerHTML = "";
document.getElementById("main-container").classList.add("empty");
if (window.innerWidth < 900) sidebar.classList.remove("open");
};
</script>
<script type="module" src="./src/main.js"></script>
</body>
</html>