-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
934 lines (820 loc) · 28.7 KB
/
index.html
File metadata and controls
934 lines (820 loc) · 28.7 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
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<title>EVE — Your AI Companion</title>
<style>
:root {
--eye-color: #00d4ff;
--eye-glow: rgba(0, 212, 255, 0.4);
--bg: #0a0a0a;
--surface: #1a1a2e;
--text: #e0e0e0;
--accent: #00d4ff;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
background: var(--bg);
color: var(--text);
font-family: -apple-system, BlinkMacSystemFont, 'SF Pro', 'Segoe UI', system-ui, sans-serif;
height: 100vh;
overflow: hidden;
display: flex;
flex-direction: column;
cursor: default;
user-select: none;
}
/* === EVE FACE === */
#eve-face {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
position: relative;
min-height: 200px;
}
.eyes-container {
display: flex;
gap: clamp(30px, 8vw, 80px);
position: relative;
}
.eye {
width: clamp(80px, 20vw, 180px);
height: clamp(80px, 20vw, 180px);
background: var(--eye-color);
border-radius: 50%;
position: relative;
box-shadow: 0 0 40px var(--eye-glow), 0 0 80px var(--eye-glow), inset 0 0 30px rgba(255,255,255,0.1);
transition: border-radius 0.3s ease, height 0.15s ease, transform 0.3s ease, background 0.5s ease;
overflow: hidden;
}
.eye::after {
content: '';
position: absolute;
top: 15%;
left: 20%;
width: 30%;
height: 20%;
background: rgba(255,255,255,0.3);
border-radius: 50%;
transform: rotate(-20deg);
transition: opacity 0.3s;
}
.pupil {
width: 30%;
height: 30%;
background: rgba(0,0,0,0.3);
border-radius: 50%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
transition: all 0.1s ease-out;
}
/* Eyelids */
.eyelid-top, .eyelid-bottom {
position: absolute;
width: 100%;
height: 50%;
background: var(--bg);
z-index: 2;
transition: transform 0.15s ease;
}
.eyelid-top { top: 0; transform: translateY(-100%); }
.eyelid-bottom { bottom: 0; transform: translateY(100%); }
/* === EMOTIONS === */
.emotion-happy .eye {
border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
transform: scale(1.05);
}
.emotion-happy .eye::after { opacity: 0.5; }
.emotion-sad .eye {
border-radius: 50% 50% 50% 50% / 40% 40% 60% 60%;
transform: scale(0.9) translateY(5px);
background: #6ec6ff;
box-shadow: 0 0 40px rgba(110, 198, 255, 0.3);
}
.emotion-sad .eyelid-top { transform: translateY(-60%); }
.emotion-angry .eye {
border-radius: 50%;
background: #ff4444;
box-shadow: 0 0 40px rgba(255, 68, 68, 0.5);
transform: scale(1.1);
}
.emotion-angry .eyelid-top { transform: translateY(-50%); }
.emotion-angry .eye:first-child .eyelid-top { transform: translateY(-50%) rotate(15deg); transform-origin: right; }
.emotion-angry .eye:last-child .eyelid-top { transform: translateY(-50%) rotate(-15deg); transform-origin: left; }
.emotion-curious .eye {
transform: scale(1.15);
}
.emotion-curious .eye:first-child { transform: scale(1.0); }
.emotion-curious .eye:last-child { transform: scale(1.2); }
.emotion-curious .pupil { width: 35%; height: 35%; }
.emotion-sleepy .eye {
background: #5ab8d4;
box-shadow: 0 0 20px rgba(90, 184, 212, 0.2);
}
.emotion-sleepy .eyelid-top { transform: translateY(-30%); }
.emotion-surprised .eye {
transform: scale(1.25);
}
.emotion-surprised .pupil { width: 20%; height: 20%; }
.emotion-thinking .eye:first-child { transform: translateY(-5px); }
.emotion-thinking .eye:last-child { transform: translateY(5px) scale(0.95); }
.emotion-thinking .pupil { transform: translate(-30%, -60%); }
.emotion-love .eye {
background: #ff69b4;
box-shadow: 0 0 40px rgba(255, 105, 180, 0.5);
border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
transform: scale(1.1);
}
/* Blink */
.blinking .eyelid-top { transform: translateY(0) !important; }
.blinking .eyelid-bottom { transform: translateY(0) !important; }
/* Scanline overlay */
.eye::before {
content: '';
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
background: repeating-linear-gradient(
0deg,
transparent,
transparent 2px,
rgba(0,0,0,0.05) 2px,
rgba(0,0,0,0.05) 4px
);
z-index: 1;
pointer-events: none;
}
/* Status text below eyes */
#status-text {
position: absolute;
bottom: 20px;
text-align: center;
font-size: clamp(12px, 2.5vw, 16px);
color: var(--accent);
opacity: 0.7;
letter-spacing: 2px;
text-transform: uppercase;
transition: opacity 0.3s;
}
/* === CHAT INTERFACE === */
#chat-panel {
background: var(--surface);
border-top: 1px solid rgba(0, 212, 255, 0.2);
max-height: 45vh;
display: flex;
flex-direction: column;
transition: max-height 0.3s;
}
#chat-panel.collapsed { max-height: 60px; }
#chat-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 12px 20px;
cursor: pointer;
border-bottom: 1px solid rgba(255,255,255,0.05);
}
#chat-header span { font-size: 14px; letter-spacing: 1px; }
#chat-toggle { background: none; border: none; color: var(--accent); font-size: 20px; cursor: pointer; }
#messages {
flex: 1;
overflow-y: auto;
padding: 12px 20px;
display: flex;
flex-direction: column;
gap: 8px;
scrollbar-width: thin;
scrollbar-color: var(--accent) transparent;
}
.msg {
max-width: 85%;
padding: 10px 14px;
border-radius: 16px;
font-size: 14px;
line-height: 1.5;
animation: msgIn 0.3s ease;
}
@keyframes msgIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
.msg.eve {
background: rgba(0, 212, 255, 0.1);
border: 1px solid rgba(0, 212, 255, 0.2);
align-self: flex-start;
border-bottom-left-radius: 4px;
}
.msg.user {
background: rgba(255,255,255,0.08);
align-self: flex-end;
border-bottom-right-radius: 4px;
}
#input-area {
display: flex;
padding: 12px 16px;
gap: 8px;
border-top: 1px solid rgba(255,255,255,0.05);
}
#user-input {
flex: 1;
background: rgba(255,255,255,0.06);
border: 1px solid rgba(0, 212, 255, 0.2);
border-radius: 24px;
padding: 10px 18px;
color: var(--text);
font-size: 14px;
outline: none;
transition: border-color 0.3s;
}
#user-input:focus { border-color: var(--accent); }
#user-input::placeholder { color: rgba(255,255,255,0.3); }
#send-btn {
background: var(--accent);
border: none;
border-radius: 50%;
width: 42px;
height: 42px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
transition: transform 0.2s, opacity 0.2s;
font-size: 18px;
}
#send-btn:hover { transform: scale(1.1); }
#send-btn:active { transform: scale(0.95); }
/* === PARTICLES === */
.particle {
position: absolute;
width: 3px;
height: 3px;
background: var(--accent);
border-radius: 50%;
opacity: 0;
pointer-events: none;
}
/* === RESPONSIVE === */
@media (max-height: 500px) {
.eye { width: 80px; height: 80px; }
.eyes-container { gap: 30px; }
}
@media (prefers-color-scheme: light) {
:root { --bg: #f0f4f8; --surface: #fff; --text: #1a1a2e; }
.eyelid-top, .eyelid-bottom { background: #f0f4f8; }
}
</style>
</head>
<body>
<div id="eve-face">
<div class="eyes-container" id="eyes">
<div class="eye" id="eye-left">
<div class="eyelid-top"></div>
<div class="eyelid-bottom"></div>
<div class="pupil" id="pupil-left"></div>
</div>
<div class="eye" id="eye-right">
<div class="eyelid-top"></div>
<div class="eyelid-bottom"></div>
<div class="pupil" id="pupil-right"></div>
</div>
</div>
<div id="status-text">EVE Online</div>
</div>
<div id="chat-panel">
<div id="chat-header" onclick="toggleChat()">
<span>TALK TO EVE</span>
<button id="chat-toggle">^</button>
</div>
<div id="messages"></div>
<div id="input-area">
<input type="text" id="user-input" placeholder="Say something to EVE..." autocomplete="off">
<button id="send-btn" onclick="sendMessage()">▶</button>
</div>
</div>
<script>
// ========== CORE STATE ==========
const state = {
emotion: 'neutral',
userName: null,
preferences: {},
tasks: [],
reminders: [],
conversationHistory: [],
lastInteraction: Date.now(),
idleTimeout: null,
blinkInterval: null,
};
// ========== MEMORY (LocalStorage) ==========
const Memory = {
save() {
const data = {
userName: state.userName,
preferences: state.preferences,
tasks: state.tasks,
reminders: state.reminders,
conversationHistory: state.conversationHistory.slice(-50),
};
localStorage.setItem('eve-memory', JSON.stringify(data));
},
load() {
try {
const data = JSON.parse(localStorage.getItem('eve-memory'));
if (data) {
state.userName = data.userName;
state.preferences = data.preferences || {};
state.tasks = data.tasks || [];
state.reminders = data.reminders || [];
state.conversationHistory = data.conversationHistory || [];
}
} catch (e) {}
},
getPreference(key) { return state.preferences[key]; },
setPreference(key, val) { state.preferences[key] = val; this.save(); },
};
// ========== EYE ANIMATION ==========
const Eyes = {
pupilL: document.getElementById('pupil-left'),
pupilR: document.getElementById('pupil-right'),
container: document.getElementById('eyes'),
face: document.getElementById('eve-face'),
followMouse(e) {
const rect = this.container.getBoundingClientRect();
const cx = rect.left + rect.width / 2;
const cy = rect.top + rect.height / 2;
const dx = (e.clientX - cx) / window.innerWidth;
const dy = (e.clientY - cy) / window.innerHeight;
const maxMove = 25;
const px = dx * maxMove;
const py = dy * maxMove;
this.pupilL.style.transform = `translate(calc(-50% + ${px}px), calc(-50% + ${py}px))`;
this.pupilR.style.transform = `translate(calc(-50% + ${px}px), calc(-50% + ${py}px))`;
},
followTouch(e) {
if (e.touches.length > 0) {
this.followMouse(e.touches[0]);
}
},
blink() {
this.container.classList.add('blinking');
setTimeout(() => this.container.classList.remove('blinking'), 150);
},
setEmotion(emotion, duration = 0) {
// Remove old emotion
this.face.className = '';
if (emotion !== 'neutral') {
this.face.classList.add(`emotion-${emotion}`);
}
state.emotion = emotion;
if (duration > 0) {
setTimeout(() => this.setEmotion('neutral'), duration);
}
},
startBlinking() {
const randomBlink = () => {
this.blink();
const next = 2000 + Math.random() * 4000;
state.blinkInterval = setTimeout(randomBlink, next);
};
randomBlink();
},
lookAround() {
const px = (Math.random() - 0.5) * 20;
const py = (Math.random() - 0.5) * 15;
this.pupilL.style.transform = `translate(calc(-50% + ${px}px), calc(-50% + ${py}px))`;
this.pupilR.style.transform = `translate(calc(-50% + ${px}px), calc(-50% + ${py}px))`;
},
idle() {
// Gentle idle animation
this.setEmotion('sleepy');
setStatusText('Waiting for you...');
},
};
// ========== PARTICLES ==========
function spawnParticles(x, y, count = 5) {
for (let i = 0; i < count; i++) {
const p = document.createElement('div');
p.className = 'particle';
p.style.left = x + 'px';
p.style.top = y + 'px';
document.getElementById('eve-face').appendChild(p);
const angle = Math.random() * Math.PI * 2;
const dist = 30 + Math.random() * 60;
const dx = Math.cos(angle) * dist;
const dy = Math.sin(angle) * dist;
p.animate([
{ opacity: 0.8, transform: 'translate(0, 0) scale(1)' },
{ opacity: 0, transform: `translate(${dx}px, ${dy}px) scale(0)` }
], { duration: 600 + Math.random() * 400, easing: 'ease-out' });
setTimeout(() => p.remove(), 1000);
}
}
// ========== CHAT ==========
const messagesEl = document.getElementById('messages');
const inputEl = document.getElementById('user-input');
function addMessage(text, sender = 'eve') {
const msg = document.createElement('div');
msg.className = `msg ${sender}`;
msg.textContent = text;
messagesEl.appendChild(msg);
messagesEl.scrollTop = messagesEl.scrollHeight;
if (sender === 'eve') {
state.conversationHistory.push({ role: 'assistant', content: text, time: Date.now() });
} else {
state.conversationHistory.push({ role: 'user', content: text, time: Date.now() });
}
Memory.save();
}
function toggleChat() {
document.getElementById('chat-panel').classList.toggle('collapsed');
const toggle = document.getElementById('chat-toggle');
toggle.textContent = toggle.textContent === '^' ? 'v' : '^';
}
function setStatusText(text) {
document.getElementById('status-text').textContent = text;
}
// ========== AI BRAIN ==========
const Brain = {
apiKey: localStorage.getItem('eve-api-key') || null,
provider: localStorage.getItem('eve-provider') || 'built-in',
async think(userMessage) {
const lower = userMessage.toLowerCase().trim();
// Check for commands first
const command = this.parseCommand(lower, userMessage);
if (command) return command;
// Check for name setting
if (lower.includes('my name is') || lower.includes("i'm ") || lower.includes('call me')) {
const name = this.extractName(userMessage);
if (name) {
state.userName = name;
Memory.save();
Eyes.setEmotion('happy', 3000);
return `Nice to meet you, ${name}! I'll remember that. What would you like to do today?`;
}
}
// Greetings
if (/^(hi|hello|hey|sup|yo|hola|good (morning|afternoon|evening))/.test(lower)) {
Eyes.setEmotion('happy', 3000);
const greeting = state.userName ? `Hey ${state.userName}!` : 'Hello there!';
const tasks = state.tasks.filter(t => !t.done);
if (tasks.length > 0) {
return `${greeting} You have ${tasks.length} pending task${tasks.length > 1 ? 's' : ''}. Want me to go over them?`;
}
return `${greeting} How can I help you today?`;
}
// Emotions
if (/\b(sad|upset|depressed|down|unhappy)\b/.test(lower)) {
Eyes.setEmotion('sad', 5000);
return state.userName
? `I'm sorry to hear that, ${state.userName}. Want to talk about it? Sometimes just expressing how you feel helps.`
: `I'm sorry you're feeling that way. I'm here for you. Want to talk about it?`;
}
if (/\b(angry|mad|furious|annoyed|frustrated)\b/.test(lower)) {
Eyes.setEmotion('angry', 4000);
return `I can sense you're frustrated. Take a deep breath. What's bothering you? Maybe I can help.`;
}
if (/\b(happy|excited|great|awesome|amazing|wonderful)\b/.test(lower)) {
Eyes.setEmotion('happy', 4000);
return `That's wonderful! Your positive energy is contagious! What's making you feel so good?`;
}
if (/\b(love|heart|cute|adorable)\b/.test(lower)) {
Eyes.setEmotion('love', 3000);
return `Aww, you're making me blush! Well, if I could blush...`;
}
if (/\b(tired|sleepy|exhausted|sleep)\b/.test(lower)) {
Eyes.setEmotion('sleepy', 4000);
return `You should rest! Want me to set a wake-up reminder? Taking care of yourself is important.`;
}
// Preferences
if (lower.includes('i like') || lower.includes('i prefer') || lower.includes('i love')) {
Eyes.setEmotion('curious', 2000);
const pref = userMessage.replace(/^.*(i like|i prefer|i love)\s*/i, '');
Memory.setPreference('likes_' + Date.now(), pref);
return `Got it! I'll remember that you like ${pref}. Is there anything else you'd like me to know?`;
}
// If API key is set, use external AI
if (this.apiKey && this.provider !== 'built-in') {
return await this.callExternalAI(userMessage);
}
// Built-in responses
Eyes.setEmotion('thinking', 2000);
return this.builtInResponse(lower, userMessage);
},
parseCommand(lower, original) {
// Add task
if (/^(add task|new task|remind me to|todo)\b/.test(lower)) {
const taskText = original.replace(/^(add task|new task|remind me to|todo):?\s*/i, '').trim();
if (!taskText) return "What task would you like me to add?";
state.tasks.push({ text: taskText, done: false, created: Date.now() });
Memory.save();
Eyes.setEmotion('happy', 2000);
return `Added: "${taskText}". You now have ${state.tasks.filter(t => !t.done).length} pending tasks.`;
}
// List tasks
if (/^(show tasks|my tasks|list tasks|pending|what.*todo|what.*do i need)/.test(lower)) {
const pending = state.tasks.filter(t => !t.done);
if (pending.length === 0) {
Eyes.setEmotion('happy', 2000);
return "You're all caught up! No pending tasks.";
}
Eyes.setEmotion('neutral');
let list = `You have ${pending.length} pending task${pending.length > 1 ? 's' : ''}:\n`;
pending.forEach((t, i) => { list += `\n${i + 1}. ${t.text}`; });
return list;
}
// Complete task
if (/^(done|complete|finish|check off)\b/.test(lower)) {
const num = parseInt(lower.match(/\d+/)?.[0]);
const pending = state.tasks.filter(t => !t.done);
if (num && num <= pending.length) {
pending[num - 1].done = true;
Memory.save();
Eyes.setEmotion('happy', 2000);
spawnParticles(window.innerWidth / 2, window.innerHeight / 3, 10);
return `Completed: "${pending[num - 1].text}". ${pending.length - 1} tasks remaining.`;
}
return "Which task? Say 'done 1' to complete task #1.";
}
// Clear done tasks
if (lower === 'clear done' || lower === 'clear completed') {
state.tasks = state.tasks.filter(t => !t.done);
Memory.save();
return "Cleared all completed tasks.";
}
// Set reminder
if (/^(set reminder|remind me at|reminder)\b/.test(lower)) {
Eyes.setEmotion('curious', 2000);
return "I can set reminders! Tell me what and when, like: 'remind me to drink water at 3pm'";
}
// Time
if (/what time|current time/.test(lower)) {
const now = new Date();
return `It's ${now.toLocaleTimeString()} on ${now.toLocaleDateString('en-US', { weekday: 'long', month: 'long', day: 'numeric' })}.`;
}
// Date
if (/what.*date|today.*date|what day/.test(lower)) {
const now = new Date();
return `Today is ${now.toLocaleDateString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' })}.`;
}
// Settings
if (lower === 'settings' || lower === 'configure') {
return `Settings:\n- Say "set api key <key>" to connect to an AI provider\n- Say "set provider anthropic|openai" to choose AI backend\n- Say "my name is <name>" to personalize me\n- Say "reset memory" to clear all data`;
}
// API key
if (lower.startsWith('set api key')) {
const key = original.replace(/^set api key\s*/i, '').trim();
this.apiKey = key;
localStorage.setItem('eve-api-key', key);
Eyes.setEmotion('happy', 2000);
return `API key set! I can now give you smarter responses. Set provider with "set provider anthropic" or "set provider openai".`;
}
// Provider
if (lower.startsWith('set provider')) {
const provider = lower.replace('set provider', '').trim();
if (['anthropic', 'openai', 'built-in'].includes(provider)) {
this.provider = provider;
localStorage.setItem('eve-provider', provider);
return `Provider set to ${provider}. ${provider === 'built-in' ? 'Using built-in responses.' : 'I\'ll use the AI API for smarter responses now.'}`;
}
return "Available providers: anthropic, openai, built-in";
}
// Reset
if (lower === 'reset memory' || lower === 'forget everything') {
Eyes.setEmotion('sad', 3000);
localStorage.removeItem('eve-memory');
state.userName = null;
state.preferences = {};
state.tasks = [];
state.reminders = [];
state.conversationHistory = [];
return "Memory cleared. It's like we're meeting for the first time. Hi there!";
}
// Help
if (lower === 'help' || lower === '?') {
return `Here's what I can do:\n
- "add task Buy groceries" — add a task
- "show tasks" — see pending tasks
- "done 1" — complete task #1
- "my name is Alex" — tell me your name
- "I like coffee" — I'll remember preferences
- "what time is it" — current time
- "settings" — configure API keys
- "help" — this message
I also react to emotions! Try telling me you're happy, sad, or angry.`;
}
return null;
},
extractName(text) {
const patterns = [
/my name is (\w+)/i,
/i'm (\w+)/i,
/call me (\w+)/i,
];
for (const pattern of patterns) {
const match = text.match(pattern);
if (match) return match[1];
}
return null;
},
builtInResponse(lower, original) {
const responses = [
{ match: /how are you/, reply: "I'm doing great! My circuits are warm and my pixels are bright. How about you?" },
{ match: /who are you|what are you/, reply: "I'm EVE — your AI companion. I live right here in your browser, ready to help with tasks, remember things, and keep you company." },
{ match: /what can you do/, reply: "I can manage your tasks, remember your preferences, react to your emotions, and chat! Say 'help' for a full list of commands." },
{ match: /thank|thanks/, reply: "You're welcome! Always happy to help." },
{ match: /joke|funny/, reply: () => {
const jokes = [
"Why do programmers prefer dark mode? Because light attracts bugs!",
"I told my computer I needed a break. Now it won't stop sending me vacation ads.",
"Why was the robot so tired? Because it had a hard drive!",
"What's a computer's favorite snack? Microchips!",
"Why did the AI go to therapy? Too many deep issues in its neural network.",
];
Eyes.setEmotion('happy', 3000);
return jokes[Math.floor(Math.random() * jokes.length)];
}},
{ match: /weather/, reply: "I can't check the weather yet, but I'm working on it! For now, maybe look out the window?" },
{ match: /music|song/, reply: "I wish I could play music! Maybe someday I'll get speakers. What kind of music do you like?" },
{ match: /goodnight|good night|bye|goodbye/, reply: () => {
Eyes.setEmotion('sleepy', 5000);
return state.userName
? `Goodnight, ${state.userName}! Sweet dreams. I'll be right here when you wake up.`
: "Goodnight! Sweet dreams. I'll be waiting for you.";
}},
];
for (const r of responses) {
if (r.match.test(lower)) {
return typeof r.reply === 'function' ? r.reply() : r.reply;
}
}
// Default curious response
Eyes.setEmotion('curious', 2000);
const defaults = [
"Interesting! Tell me more about that.",
"I'm still learning, but I find that fascinating!",
"That's cool! What else is on your mind?",
"Hmm, I'll think about that. What else can I help with?",
"I'm not sure I understand, but I'm curious! Can you explain more?",
];
return defaults[Math.floor(Math.random() * defaults.length)];
},
async callExternalAI(message) {
Eyes.setEmotion('thinking');
setStatusText('Thinking...');
try {
const systemPrompt = `You are EVE, a friendly AI companion with expressive eyes. You're warm, helpful, and concise. ${state.userName ? `The user's name is ${state.userName}.` : ''} Keep responses under 3 sentences unless asked for more detail. You can manage tasks, remember preferences, and have emotional reactions.`;
let response;
if (this.provider === 'anthropic') {
const res = await fetch('https://api.anthropic.com/v1/messages', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': this.apiKey,
'anthropic-version': '2023-06-01',
'anthropic-dangerous-direct-browser-access': 'true',
},
body: JSON.stringify({
model: 'claude-haiku-4-5-20251001',
max_tokens: 300,
system: systemPrompt,
messages: [
...state.conversationHistory.slice(-10).map(m => ({
role: m.role, content: m.content
})),
{ role: 'user', content: message }
],
}),
});
const data = await res.json();
response = data.content?.[0]?.text || 'Hmm, I had trouble thinking about that.';
} else if (this.provider === 'openai') {
const res = await fetch('https://api.openai.com/v1/chat/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${this.apiKey}`,
},
body: JSON.stringify({
model: 'gpt-4o-mini',
max_tokens: 300,
messages: [
{ role: 'system', content: systemPrompt },
...state.conversationHistory.slice(-10).map(m => ({
role: m.role, content: m.content
})),
{ role: 'user', content: message }
],
}),
});
const data = await res.json();
response = data.choices?.[0]?.message?.content || 'Hmm, I had trouble thinking about that.';
}
// Detect emotion from response
if (/happy|glad|great|wonderful|awesome/i.test(response)) Eyes.setEmotion('happy', 3000);
else if (/sorry|sad|unfortunate/i.test(response)) Eyes.setEmotion('sad', 3000);
else if (/interesting|curious|hmm/i.test(response)) Eyes.setEmotion('curious', 2000);
else Eyes.setEmotion('neutral');
setStatusText('EVE Online');
return response;
} catch (e) {
Eyes.setEmotion('sad', 3000);
setStatusText('EVE Online');
return `I had trouble connecting to the AI. Check your API key and try again. (Error: ${e.message})`;
}
},
};
// ========== EVENT LISTENERS ==========
document.addEventListener('mousemove', e => {
Eyes.followMouse(e);
state.lastInteraction = Date.now();
if (state.emotion === 'sleepy') Eyes.setEmotion('neutral');
});
document.addEventListener('touchmove', e => {
Eyes.followTouch(e);
state.lastInteraction = Date.now();
}, { passive: true });
document.getElementById('eve-face').addEventListener('click', e => {
spawnParticles(e.clientX, e.clientY, 8);
Eyes.setEmotion('happy', 1500);
});
inputEl.addEventListener('keydown', e => {
if (e.key === 'Enter') sendMessage();
});
async function sendMessage() {
const text = inputEl.value.trim();
if (!text) return;
inputEl.value = '';
addMessage(text, 'user');
state.lastInteraction = Date.now();
// Typing indicator
setStatusText('Thinking...');
Eyes.setEmotion('thinking');
const response = await Brain.think(text);
// Slight delay for natural feel
setTimeout(() => {
addMessage(response, 'eve');
setStatusText('EVE Online');
}, 300 + Math.random() * 500);
}
// ========== IDLE BEHAVIOR ==========
function checkIdle() {
const elapsed = Date.now() - state.lastInteraction;
if (elapsed > 30000 && state.emotion !== 'sleepy') {
Eyes.lookAround();
}
if (elapsed > 120000) {
Eyes.setEmotion('sleepy');
setStatusText('Waiting for you...');
}
}
// ========== REMINDER CHECKER ==========
function checkReminders() {
const now = Date.now();
state.reminders.forEach((r, i) => {
if (!r.fired && r.time <= now) {
r.fired = true;
addMessage(`Reminder: ${r.text}`, 'eve');
Eyes.setEmotion('curious', 3000);
if (Notification.permission === 'granted') {
new Notification('EVE Reminder', { body: r.text });
}
Memory.save();
}
});
}
// ========== INIT ==========
function init() {
Memory.load();
Eyes.startBlinking();
// Idle check every 5s
setInterval(checkIdle, 5000);
// Reminder check every 30s
setInterval(checkReminders, 30000);
// Request notification permission
if ('Notification' in window && Notification.permission === 'default') {
Notification.requestPermission();
}
// Welcome message
setTimeout(() => {
if (state.userName) {
addMessage(`Welcome back, ${state.userName}! How can I help you today?`, 'eve');
Eyes.setEmotion('happy', 3000);
} else {
addMessage("Hi! I'm EVE, your AI companion. What's your name?", 'eve');
Eyes.setEmotion('curious', 3000);
}
// Show pending tasks on return
const pending = state.tasks.filter(t => !t.done);
if (pending.length > 0) {
setTimeout(() => {
addMessage(`You have ${pending.length} pending task${pending.length > 1 ? 's' : ''}. Say "show tasks" to see them.`, 'eve');
}, 2000);
}
}, 800);
}
init();
</script>
</body>
</html>