Repository navigation
Expand file tree
/
Copy pathvite.config.js
More file actions
1196 lines (1176 loc) · 47.1 KB
/
Copy pathvite.config.js
File metadata and controls
1196 lines (1176 loc) · 47.1 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
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { defineConfig } from "vite";
import { existsSync, readFileSync } from "node:fs";
import { previewRequestMetrics } from "./web/preview/metrics.js";
import react from "@vitejs/plugin-react";
import { createSettingsPreview } from "./web/preview/settings.js";
const previewStateStartedAt = Math.floor(Date.now() / 1000);
function previewCurrentState() {
return { revision: 2, slots: [
{ id: "preview-working", subject: "owner", key: "activity", value: "正在收尾工作,预计一小时内忙完就休息。", created_at: previewStateStartedAt - 720, expires_at: previewStateStartedAt + 2880, source_turn_id: "preview-state" },
{ id: "preview-travel", subject: "owner", key: "location", value: "今晚住在酒店,明早返回。", created_at: previewStateStartedAt - 1800, expires_at: previewStateStartedAt + 28800, source_turn_id: "preview-state" },
] };
}
// Synthetic history so the step stream has enough rows to page through.
function previewHistoryCalls(day) {
const tools = [
["recall", { query: "最近的约定" }, { ok: true, hits: 3 }],
["web_search", { query: "明天上海天气" }, { ok: true, results: 5 }],
["exec", { command: "ls ~/Downloads | head" }, { ok: false, error: "timeout", exit_code: 124 }],
["memory_write", { content: "主人周末想去看展" }, { ok: true }],
["reply", { intent: "简短回应并确认" }, { ok: true }],
];
const prompts = ["今天好累", "帮我查下明天天气", "提醒我八点开会", "这个文件放哪了", "周末有什么安排", "刚刚那首歌叫什么"];
const calls = [];
const base = Math.floor(day.getTime() / 1000) - 3600;
for (let turn = 0; turn < 60; turn += 1) {
const start = base - turn * 1800;
const steps = 1 + ((turn * 7) % 5);
for (let index = 0; index < steps; index += 1) {
const last = index === steps - 1;
const [name, args, result] = tools[(turn + index) % (last ? 1 : tools.length)];
const action = last
? { id: `h${turn}-${index}`, name: "end_turn", arguments: {} }
: { id: `h${turn}-${index}`, name, arguments: args, result };
calls.push({
turn_id: `preview-history-${turn}`,
call_id: `preview-history-${turn}-${index}`,
created_at: start + index * 9,
stage: index === steps - 1 && steps > 2 ? "replyer" : "owner",
round: index + 1,
model: "deepseek-v4-flash",
tools: [action.name],
reasoning_chars: 40,
excerpt: index === 0 ? `主人说「${prompts[turn % prompts.length]}」,先判断要不要查资料。` : "",
reasoning: index === 0 ? `主人说「${prompts[turn % prompts.length]}」。先看上下文,再决定调用哪个工具。` : `根据上一步 ${name} 的结果继续推进。`,
assistant_text: steps > 2 && last ? "好,我记下了,晚点提醒你。" : "",
actions: [action],
request_metrics: { duration_ms: 600 + ((turn * 13 + index * 31) % 40) * 150, input_tokens: 3200 + index * 400, output_tokens: 120 + index * 30 },
});
}
}
return calls;
}
function previewThinkingCalls() {
const day = new Date();
day.setHours(21, 1, 49, 0);
const at = (minutes, seconds = 0) =>
Math.floor(day.getTime() / 1000) + minutes * 60 + seconds;
return [
...previewHistoryCalls(day),
{
turn_id: "preview-state", call_id: "preview-state-1",
created_at: at(8), stage: "current_state_maintenance", round: 1,
model: "deepseek-v4-flash", tools: ["current_state_finish"], reasoning_chars: 38,
excerpt: "记录正在收尾工作的当前状态,有效时间为一小时。",
reasoning: "用户明确说正在收尾工作,预计一小时内结束。增加当前状态,TTL 设为 3600 秒。",
},
{
turn_id: "preview-recall-skip",
call_id: "preview-recall-skip-1",
created_at: at(7),
stage: "owner",
round: 1,
model: "deepseek-v4-flash",
tools: ["recall"],
reasoning_chars: 25,
excerpt: "当前上下文足以理解这条消息,无需额外检索。",
reasoning: "主人确认收到,当前上下文足够,无需检索历史。",
},
{
turn_id: "preview-recall-dense",
call_id: "preview-recall-dense-1",
created_at: at(6),
stage: "owner",
round: 1,
model: "deepseek-v4-flash",
tools: ["recall"],
reasoning_chars: 1680,
excerpt: "这是同一段连续对话,沿用上一轮已经确认的召回范围。",
reasoning:
"当前消息只是延续上一轮的玩笑,没有新增历史依赖。沿用已确认的召回范围,并继续记录在同一个聊天 Episode。",
},
{
turn_id: "preview-recall-mixed",
call_id: "preview-recall-mixed-1",
created_at: at(5),
stage: "owner",
round: 1,
model: "deepseek-v4-flash",
tools: ["recall"],
reasoning_chars: 1320,
excerpt: "一条消息里有两个独立意图,分别检索,不把关键词挤成一排标签。",
reasoning:
"把这轮拆成两个意图:一个检索提醒规则,一个检索关卡方案。它们分别绑定已有聊天和新建聊天,用来检查多单元布局。",
},
{
turn_id: "preview-recall-empty",
call_id: "preview-recall-empty-1",
created_at: at(4),
stage: "owner",
round: 1,
model: "deepseek-v4-flash",
tools: ["recall"],
reasoning_chars: 620,
excerpt: "执行了检索,但没有召回可用依据,也不绑定聊天记录。",
reasoning: "这轮需要搜索,但结果为空。保留检索决策,不展示空的 evidence 或 Episode 区块。",
},
{
turn_id: "9d5db6937f765921b2d6cbe0773e5111",
call_id: "216921a1df9e4da7",
assistant_text: "先查这次洗衣完成后的工具调用和发送记录,确认当时有没有真正发出提醒。",
created_at: at(0),
stage: "owner",
round: 1,
model: "deepseek-v4-flash",
tools: ["recall"],
reasoning_chars: 2995,
excerpt:
"主人在问为什么衣服洗好了却没提醒,先召回这次 Webhook 的历史证据。",
reasoning:
"当前意图依赖刚才 Webhook 的处理记录。提交洗衣完成、提醒和静默处理的历史 scope;Episode 继续当天的洗衣事件。",
request_metrics: { input_tokens: 8421, output_tokens: 312, duration_ms: 2140 },
trace: { memory_context: {
triggered_memories: '<usage>历史记忆,以用户当前意图为准。</usage><memory id="42" kind="rule" key="laundry.reminder"><trigger>衣服</trigger><trigger>洗好</trigger><content>衣服洗好后,及时提醒老师取出晾晒。</content></memory>',
scoped_memories: '<memory id="73">处理洗衣完成通知时,先确认设备状态与发送记录,避免重复提醒。</memory>',
triggered_episodes: [
{ source: "input", id: "e1a2b3c4d5", status: "closed", title: "洗衣机洗完后忘了提醒晾衣服", summary: "上周洗衣完成通知到达时没有提醒,老师回家才发现。", relations: [{ relation: "follows_up", id: "a9b8c7d6e5", title: "约定洗衣完成后提醒晾晒" }], supplements: [] },
{ source: "reply", id: "f0e1d2c3b4", status: "open", title: "阳台晾衣杆坏了", summary: "", relations: [{ relation: "context", id: "c1d2e3f4a5", direction: "outgoing" }], supplements: [] },
],
} },
actions: [
{
id: "act-recall-1",
name: "recall",
arguments: { intent: "核对洗衣完成后的提醒约定与 Webhook 处理记录", scope: "webhook" },
result: { ok: true, hits: 2, episodes: ["洗衣完成后的提醒"] },
},
],
},
{
turn_id: "9d5db6937f765921b2d6cbe0773e5111",
call_id: "d8afbd8f275440d0",
assistant_text: "已确认:那次只结束了回合,没有发送提醒。我会说明漏发的事实,不把旧判断当成老师的要求。",
created_at: at(0, 10),
stage: "owner",
round: 1,
model: "deepseek-v4-flash",
tools: ["reply"],
reasoning_chars: 2557,
excerpt:
"先核对 outbox。那次 webhook 只调了 end_turn,没有 send_bubbles,所以老师确实没收到。",
reasoning:
"先看事实,不看旧笔记。\n\n那次 webhook 的工具只有 end_turn,outbox 是空的。thinking 里写过「烘干结束提醒并非老师要求」,那是当时的判断,不能当成现行禁令。\n\n老师现在明确在问为什么没提醒。结论:衣服洗好这件事到了,我评估后选择了静默,所以没有发出去。接下来派发 Replyer 把这件事说清楚,不要假装已经提醒过。",
request_metrics: { input_tokens: 9023, output_tokens: 540, duration_ms: 3380 },
actions: [
{
id: "act-reply-1",
name: "reply",
arguments: { intent: "说明那次确实没发出提醒并解释原因", reference: "outbox 为空,仅 end_turn" },
result: { ok: true },
},
],
},
{
turn_id: "9d5db6937f765921b2d6cbe0773e5111",
call_id: "replyer-laundry-1",
created_at: at(0, 12),
stage: "replyer",
round: 1,
model: "deepseek-v4-flash",
tools: [],
reasoning_chars: 120,
assistant_text:
"啊……对不起老师,我刚才查了一下,那次衣服洗好的时候我其实没有发提醒。\n当时按旧笔记选择了静默,是我判断失误了,之后衣服洗好我都会第一时间叫你。",
trace: { parent_call_id: "d8afbd8f275440d0", tool_call_id: "act-reply-1" },
request_metrics: { input_tokens: 5120, output_tokens: 180, duration_ms: 1560 },
},
{
turn_id: "9d5db6937f765921b2d6cbe0773e5111",
call_id: "laundry-cues-selection",
created_at: at(0, 9),
stage: "topic_selection",
round: 1,
model: "deepseek-v4-flash",
tools: ["select_topics"],
reasoning_chars: 1160,
excerpt: "从候选聊天中筛出与洗衣提醒约定直接相关的主题。",
reasoning: "当前问题需要核对洗衣完成后的提醒约定,以及刚才 Webhook 的实际处理。\n\n候选主题里只有「衣服洗好了」同时覆盖提醒、静默处理和送达结果,其他日常聊天与本轮无关。保留这个主题,避免把无关 Episode 带进上下文。",
},
{
turn_id: "9d5db6937f765921b2d6cbe0773e5111",
call_id: "laundry-cues-admit",
created_at: at(0, 9, 30),
stage: "episode_cue_admit",
round: 1,
model: "deepseek-v4-flash",
tools: ["episode_cue_admit"],
reasoning_chars: 980,
excerpt: "逐条核对检索线索,确认提醒约定和静默结果都有原文依据。",
reasoning: "逐条检查候选线索的来源:\n\n「洗衣完成后根据当前对话决定是否提醒」与老师本轮追问相符;「Webhook 报告完成,Momoi 选择静默」有工具记录支持;「未发送提醒,老师随后追问原因」也能由事件与后续消息对应。三条线索均有来源依据,准入。",
},
{
turn_id: "9d5db6937f765921b2d6cbe0773e5111",
call_id: "566674d7e7814260",
created_at: at(0, 14),
stage: "owner",
round: 2,
model: "deepseek-v4-flash",
tools: ["end_turn"],
reasoning_chars: 46,
excerpt: "已经说明原因,这轮可以收束。",
reasoning: "已经说明原因,这轮可以收束。",
request_metrics: { input_tokens: 4301, output_tokens: 24, duration_ms: 600 },
actions: [{ id: "act-end-1", name: "end_turn", arguments: {}, result: { ok: true } }],
},
{
turn_id: "ef8c470b3ea15ca2a0a77d02cfcb33d9",
call_id: "d434890f538b4d10",
created_at: at(1, 35),
stage: "heartbeat",
round: 1,
model: "deepseek-v4-flash",
tools: ["heartbeat_begin"],
reasoning_chars: 4558,
excerpt:
"老师这会儿不在。最近在聊小游戏关卡,心跳可以继续整理点子,不必主动打扰。",
reasoning:
"老师这会儿不在,没有未回的追问。最近的话题是小游戏关卡,不是未完成的家务通知。\n\n心跳活动:继续整理关卡灵感。召回词用「关卡|小游戏」。不要把刚才的洗衣追问再讲一遍。",
},
{
turn_id: "ef8c470b3ea15ca2a0a77d02cfcb33d9",
call_id: "13eaa7f184364bd9",
created_at: at(2),
stage: "heartbeat",
round: 1,
model: "deepseek-v4-flash",
tools: ["end_turn"],
reasoning_chars: 9802,
excerpt:
"关卡节奏可以再压一拍。这次只记下来,先不发消息。",
reasoning:
"读完一条新玩法公开。关卡可以做成「先看见机关,再决定要不要踩」。\n\n这不是必须告诉老师的事。记下活动结果,end_turn 收束,不发 send_bubbles。",
},
{
turn_id: "webhook:event-message:0",
call_id: "aceafbcfc5a54b858c386fe4cfdafbf6",
created_at: at(-52),
stage: "webhook",
round: 1,
model: "deepseek-v4-flash",
tools: ["end_turn"],
reasoning_chars: 1840,
excerpt:
"衣服洗好了。旧 Episode 写过烘干结束不必提醒,所以这次也先静默。",
reasoning:
"Webhook 任务:衣服洗好了。\n\n对照 native transcript,老师没有正在等这条。旧 Episode 笔记写过「烘干结束提醒并非老师要求」。webhook 合同说:如果只是重复已知状态,可以静默。\n\n决定:不发 send_bubbles,直接 end_turn。",
},
{
turn_id: "july-quest-note",
call_id: "july-quest-1",
created_at: at(-40 * 24 * 60),
stage: "heartbeat",
round: 1,
model: "deepseek-v4-flash",
tools: ["end_turn"],
reasoning_chars: 640,
excerpt: "七月那次心跳只整理了关卡节奏,没有打扰老师。",
reasoning: "老师不在。关卡节奏可以再压一拍,先记在活动结果里,不发消息。",
},
{
turn_id: "june-sticker-plan",
call_id: "june-sticker-1",
created_at: at(-70 * 24 * 60),
stage: "owner",
round: 1,
model: "deepseek-v4-flash",
tools: ["recall"],
reasoning_chars: 880,
excerpt: "六月在想表情包分类,先按老师最近用过的召回。",
reasoning: "老师在问表情包。先召回最近用过的贴纸,不要把分类方案一次倒完。",
},
...Array.from({ length: 22 }, (_, index) => {
const stages = ["owner", "heartbeat", "webhook", "reflection"];
const stage = stages[index % stages.length];
const reasoning = [
`预览思考 ${index + 1}。用来把左侧列表和右侧详情都撑出滚动条。`,
"先核对最近对话,再决定要不要主动说话。",
"如果只是重复已知状态,就静默收束,不要假装已经提醒过。",
"关卡节奏、洗衣 webhook、表情包分类都可以各自记一笔,不要混成一件事。",
"结论写清楚:这轮只整理判断,不把旧笔记当成现行禁令。",
].join("\n\n");
return {
turn_id: `preview-turn-${index + 1}`,
call_id: `preview-call-${index + 1}`,
created_at: at(-(index + 3) * 18),
stage,
round: 1,
model: "deepseek-v4-flash",
tools: ["end_turn"],
reasoning_chars: reasoning.length,
excerpt: `预览条目 ${index + 1}:把思考列表撑高,方便看滚动条。`,
reasoning,
};
}),
];
}
function previewRecall(turnId) {
const fixtures = {
"preview-recall-skip": {
revision: 1,
state: "recalled",
units: [{ id: "u1", intent: "主人确认收到", mode: "skip", queries: [], reused_from: "" }],
episode_actions: [],
memories: [],
reflections: [],
episodes: [],
semantic: { fallback_reason: "disabled", query_batch_size: 0 },
},
"9d5db6937f765921b2d6cbe0773e5111": {
revision: 1,
state: "recalled",
units: [
{
id: "u1",
intent: "解释刚才为什么没有提醒",
mode: "search",
queries: [
{
semantic: "衣服洗完后的提醒约定与刚才 Webhook 的处理记录",
keywords: ["洗衣", "提醒", "Webhook", "通知约定", "静默处理", "完成状态"],
},
],
reused_from: "",
},
],
episode_actions: [
{
action: "continue",
episode_id: "episode-laundry",
title: "衣服洗好后的提醒约定",
},
],
status: "semantic_queries=衣服洗完后的提醒约定与刚才 Webhook 的处理记录\nhits=洗衣提醒",
memories: [
{
kind: "shared",
key: "laundry.notification",
content: "洗衣完成是否提醒应根据当前对话判断。",
},
],
reflections: [],
episodes: [
{
id: "laundry",
title: "洗衣完成后的提醒",
relation: "recalled",
summary: "Webhook 报告洗衣完成,Momoi 当时选择了静默。",
cues: ["洗衣完成后根据当前对话决定是否提醒", "Webhook 报告完成,Momoi 选择静默", "未发送提醒,老师随后追问原因"],
},
],
semantic: { fallback_reason: "", query_batch_size: 1 },
},
"preview-recall-dense": {
revision: 1,
state: "recalled",
units: [
{
id: "u1",
intent: "延续回家路上的轻松玩笑,并回应刚才那句调侃",
mode: "reuse",
queries: [],
reused_from: "9d5db6937f765921b2d6cbe0773e5111",
},
],
episode_actions: [
{
action: "continue",
episode_id: "episode-game",
title: "下班路上的随口玩笑",
},
],
status: "reused_from=hidden-in-ui units=u1",
memories: [
{
kind: "routine",
key: "private.internal.memory-key",
content: "睡前互道晚安是已经形成的日常习惯,漏掉时会互相提醒。",
},
],
reflections: [
{
kind: "self_insight",
key: "private.internal.reflection-one",
content: "识别轻松玩笑时先看完整对话,不要只凭一个词猜测语气。",
local_date: "2026-08-28",
},
{
kind: "relationship",
key: "private.internal.reflection-two",
content: "对方疲惫时仍可以接住简短玩笑,但回复不要拖得太长。",
local_date: "2026-08-29",
},
{
kind: "shared_experience",
key: "private.internal.reflection-three",
content: "两人曾在下班回家的路上聊小游戏,用短句互相报平安。",
local_date: "2026-08-30",
},
{
kind: "owner_preference",
key: "private.internal.reflection-four",
content: "主人更喜欢自然、简短、有停顿感的回复。",
local_date: "2026-08-31",
},
{
kind: "practice",
key: "private.internal.reflection-five",
content: "连续对话已有完整召回范围时,可以沿用,避免重复搜索。",
local_date: "2026-09-01",
},
{
kind: "relationship",
key: "private.internal.reflection-six",
content: "熟悉的玩笑可以直接接住,不需要把背景重新解释一遍。",
local_date: "2026-09-01",
},
],
episodes: Array.from({ length: 11 }, (_, index) => ({
id: index === 0 ? "episode-game" : `episode-preview-${index}`,
title: [
"下班路上的随口玩笑",
"一起通关小游戏的晚上",
"周五早上的赖床闲聊",
"洗衣完成后的提醒",
"分享新表情包的一天",
"晚饭后讨论关卡节奏",
"出门前互相报平安",
"深夜聊到最近玩的游戏",
"午休时的短消息",
"周末一起整理游戏清单",
"回家后继续聊未完的话题",
][index],
relation: "recalled",
summary: index % 2
? "这是一条较长的聊天摘要,用来确认展开后内容会被限制在可读的行数,不会把整个页面撑乱。"
: "",
})),
semantic: { fallback_reason: "", query_batch_size: 0 },
},
"preview-recall-mixed": {
revision: 2,
state: "recalled",
units: [
{
id: "u1",
intent: "确认洗衣完成后的提醒规则",
mode: "search",
reused_from: "",
queries: [
{
semantic: "最近关于洗衣完成、通知时机与静默处理的明确约定",
keywords: ["洗衣", "完成提醒", "通知", "静默", "Webhook", "当前约定", "送达状态"],
},
{
semantic: "上一次没有发出提醒时的实际处理记录",
keywords: ["outbox", "end_turn", "未发送"],
},
],
},
{
id: "u2",
intent: "找到最近讨论过的小游戏关卡方案",
mode: "search",
reused_from: "",
queries: [
{
semantic: "小游戏里先观察机关再决定是否触发的关卡节奏",
keywords: ["小游戏", "关卡", "机关", "节奏"],
},
],
},
],
episode_actions: [
{
action: "continue",
episode_id: "episode-laundry",
title: "衣服洗好后的提醒约定",
},
{
action: "new",
episode_id: "episode-game",
title: "小游戏关卡的新方案",
},
],
memories: [],
reflections: [],
episodes: [],
semantic: { fallback_reason: "", query_batch_size: 3 },
},
"preview-recall-empty": {
revision: 1,
state: "recalled",
units: [
{
id: "u1",
intent: "查找一个此前没有提到过的新主题",
mode: "search",
reused_from: "",
queries: [
{
semantic: "此前是否讨论过这个全新的主题",
keywords: ["新主题"],
},
],
},
],
episode_actions: [],
memories: [],
reflections: [],
episodes: [],
semantic: { fallback_reason: "", query_batch_size: 1 },
},
};
return fixtures[turnId] || null;
}
function previewMonthKey(timestamp) {
const date = new Date(Number(timestamp) * 1000);
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}`;
}
function previewThinkingList(params) {
const requested = params.get("month") || new Date().toISOString().slice(0, 7);
const buckets = new Map();
for (const call of previewThinkingCalls()) {
const key = call.turn_id || `call:${call.call_id}`;
if (!buckets.has(key)) buckets.set(key, []);
buckets.get(key).push(call);
}
const items = [...buckets.entries()].map(([id, calls]) => {
const flow = [...calls].sort((left, right) => left.created_at - right.created_at);
const stages = [];
const tools = [];
for (const call of flow) {
if (!stages.includes(call.stage)) stages.push(call.stage);
for (const tool of call.tools || []) {
if (tool && !tools.includes(tool)) tools.push(tool);
}
}
const episode = {
"9d5db6937f765921b2d6cbe0773e5111": {
episode_id: "episode-laundry",
episode_title: "衣服洗好了",
},
"webhook:event-message:0": {
episode_id: "episode-webhook",
episode_title: "Webhook event-message",
},
}[flow[0].turn_id] || {};
return {
id,
turn_id: flow[0].turn_id || "",
created_at: flow[0].created_at,
updated_at: flow[flow.length - 1].created_at,
call_count: flow.length,
stages,
tools,
excerpt: flow[0].excerpt || "",
reasoning_chars: flow.reduce((sum, call) => sum + (call.reasoning_chars || 0), 0),
...episode,
};
});
items.sort((left, right) => right.updated_at - left.updated_at);
const months = [...new Set(items.map((item) => previewMonthKey(item.updated_at)))].sort();
const month = months.includes(requested) ? requested : requested;
const page = items.filter((item) => previewMonthKey(item.updated_at) === month);
return {
ok: true,
month,
months: months.includes(month) ? months : [...months, month].sort(),
items: page,
count: page.length,
};
}
function previewNow() {
return Math.floor(Date.now() / 1000);
}
function previewEmotions() {
const names = ["shy", "happy", "sleepy", "angry", "thinking", "cheer", "sad", "wave"];
return names.map((slug, index) => ({
id: index + 1,
slug,
description: `预览表情 ${index + 1}:${slug} 的时候用`,
asset_url: "/icon-192.png",
}));
}
function previewRecords() {
const now = previewNow();
const conversations = [
{
id: "episode-laundry",
title: "衣服洗好了",
status: "open",
working_summary: "老师在追问上次 webhook 为什么没有发出烘干结束提醒。",
topics: ["洗衣", "提醒", "webhook"],
updated_at: now - 120,
},
{
id: "episode-game",
title: "小游戏关卡节奏",
status: "open",
working_summary: "最近在聊关卡节奏,心跳里记过「先看见机关再决定要不要踩」。",
topics: ["小游戏", "关卡"],
updated_at: now - 3600,
},
...Array.from({ length: 16 }, (_, index) => ({
id: `episode-preview-${index + 1}`,
title: `预览聊天 ${index + 1}`,
status: index % 5 === 0 ? "closed" : "open",
working_summary: `用来把聊天列表撑高的预览主题 ${index + 1}。`,
topics: ["预览", index % 2 ? "日常" : "杂谈"],
updated_at: now - (index + 2) * 5400,
})),
];
const longReply = [
"先看事实,不看旧笔记。",
"那次 webhook 的工具只有 end_turn,outbox 是空的,所以老师确实没收到提醒。",
"thinking 里写过「烘干结束提醒并非老师要求」,那是当时的判断,不能当成现行禁令。",
"老师现在明确在问为什么没提醒。结论:衣服洗好这件事到了,我评估后选择了静默。",
"接下来用 send_bubbles 把这件事说清楚,不要假装已经提醒过。",
"如果老师还想补一条提醒,我可以现在就记下时间,不再把旧 Episode 笔记直接套过来。",
].join("\n\n");
const conversationDetails = {
"episode-deep-link-only": {
id: "episode-deep-link-only",
title: "只通过深链打开的旧聊天",
status: "closed",
record_type: "episode",
working_summary: "这条记录不在最近 100 条列表里,但详情路由仍应直接加载。",
topics: ["深链", "旧聊天"],
updated_at: now - 120 * 86400,
messages: [
{
id: 9001,
role: "user",
content: "这条旧聊天能从链接直接打开吗?",
created_at: now - 120 * 86400,
ordinal: 1,
},
{
id: 9002,
role: "assistant",
content: "可以,即使它没有出现在左侧最近记录中。",
created_at: now - 120 * 86400 + 20,
delivery_state: "delivered",
ordinal: 2,
},
],
},
"episode-laundry": {
id: "episode-laundry",
title: "衣服洗好了",
status: "open",
topics: ["洗衣", "提醒", "webhook"],
messages: [
{
id: 1,
role: "user",
content: "衣服洗好了怎么没提醒我?",
created_at: now - 900,
ordinal: 1,
},
{
id: 2,
role: "assistant",
content: longReply,
created_at: now - 860,
delivery_state: "delivered",
ordinal: 2,
},
...Array.from({ length: 18 }, (_, index) => ({
id: index + 3,
role: index % 2 ? "assistant" : "user",
content:
index % 2
? `预览回复 ${Math.ceil((index + 1) / 2)}。把对话详情撑高,方便看右侧滚动条。\n\n${longReply}`
: `预览追问 ${Math.ceil((index + 1) / 2)}:那条提醒后来补了吗?`,
created_at: now - 800 + index * 20,
delivery_state: index % 2 ? "delivered" : undefined,
ordinal: index + 3,
})),
],
},
};
const memories = [
{
id: 1,
kind: "preference",
activation: "always",
meta: { scope: "", tags: ["food_drink"], triggers: ["香菜"] },
content: "主人不吃香菜。",
evidence: "上次点外卖时明确说过。",
updated_at: now - 86400,
},
{
id: 2,
kind: "practice",
activation: "scoped",
scope_label: "Webhook",
meta: { scope: "webhook", tags: ["daily_life"], triggers: [] },
content: "衣服洗好后,老师现在希望被提醒,不再沿用旧的静默判断。",
evidence: "今晚追问「为什么衣服洗好了没提醒」。",
updated_at: now - 1800,
},
...[
["always", ["health"], "主人对花粉过敏,春天出门前会提醒带口罩。"],
["always", ["work_study", "technology"], "主人在写一个叫 Momoi 的个人 Agent,主要用 Python 和 React。"],
["always", ["mental_wellbeing"], "主人压力大的时候不喜欢被追问原因,陪着聊点轻松的就好。"],
["always", ["social"], "小林是主人大学室友,现在在杭州工作。"],
["always", ["food_drink"], "主人早上习惯喝美式,不加糖。"],
["always", ["work_study"], "主人每周一上午十点有组会。"],
["always", ["health", "leisure"], "主人周三和周六晚上去游泳。"],
["always", ["work_study"], "主人最近在准备一场关于 Agent 记忆的分享。"],
["always", [], "主人喜欢被叫「老师」。"],
["always", ["work_study"], "主人写代码时偏好先写测试。"],
["always", ["work_study", "communication"], "汇报进度时,主人希望先说结论再说细节。"],
["always", ["health"], "主人有轻微胃炎,晚上尽量不喝咖啡。"],
["recall", ["travel"], "主人下个月想去京都看红叶,已经看过几家民宿。", ["京都", "红叶"], 9, 4],
["recall", ["leisure"], "主人在玩 FF7 重制版,卡在第 14 章。", ["FF7"], 6, 2],
["recall", ["finance"], "主人每月 15 号还信用卡,希望提前两天提醒。", ["信用卡"], 12, 1],
["recall", ["shopping"], "主人想买一把人体工学椅,预算三千以内。", ["椅子"], 1, 3],
["recall", ["home_living"], "家里扫地机器人每周日上午自动打扫。", [], 0, 1],
["recall", ["travel", "leisure"], "主人去年在大阪吃过一家很喜欢的烧肉店。", ["大阪"], 2, 0],
["recall", ["communication"], "主人说「喵」的时候是在撒娇,回应可以更轻松。", ["喵"], 15, 0],
["scoped", ["daily_life"], "处理喝水目标时,先看今天是否已经记录过。", [], 4, 0, "goal:water", "Goal · 喝水"],
["scoped", ["health"], "喝水提醒不要在会议时间段内发送。", [], 2, 1, "goal:water", "Goal · 喝水"],
["scoped", ["home_living"], "洗衣机通知重复时只提醒一次。", [], 3, 0, "webhook", "Webhook"],
].map(([activation, tags, content, triggers = [], recalled, searched, scope = "", scope_label = ""], index) => ({
id: index + 3,
kind: index % 3 ? "relationship" : "preference",
activation,
meta: { scope, tags, triggers },
scope_label,
content,
evidence: "本地预览数据",
updated_at: now - (index + 2) * 86000,
...(recalled === undefined ? {} : { access: { counts: { recalled, searched }, recent_30_days: recalled + searched, last_at: recalled + searched ? now - index * 3600 : null } }),
})),
];
const goals = Array.from({ length: 8 }, (_, index) => ({
id: `goal-${index + 1}`,
title: `预览任务 ${index + 1}`,
status: index === 6 ? "waiting" : index === 7 ? "blocked" : "active",
success_criteria: "把这条预览任务显示完整,方便看任务列表高度。",
next_action: "打开看板确认滚动条样式。",
waiting_for: index === 6 ? "等老师回关卡意见" : "",
blocked_reason: index === 7 ? "还缺一张表情包素材" : "",
latest_result: index % 2 ? "已经记过一版草稿。" : "",
schedule:
index === 0
? {
kind: "daily",
times: ["10:30", "14:00", "16:00"],
timezone: "Asia/Shanghai",
}
: null,
next_review_at: now + 86400,
}));
const reflections = Array.from({ length: 40 }, (_, index) => {
const date = new Date();
date.setDate(date.getDate() - index);
return {
id: `reflection-${index + 1}`,
local_date: date.toISOString().slice(0, 10),
state: "completed",
summary:
index === 0
? "今天核对了洗衣 webhook:当时选择静默,老师后来追问,已经把原因说清楚。"
: `预览复盘 ${index + 1}:整理当天的心跳和对话,用来把复盘列表撑高。`,
memories:
index === 0
? [
{
kind: "practice",
key: "laundry-reminder",
content: "烘干结束是否提醒,以老师这轮的明确要求为准。",
confidence: 0.86,
evidence: "今晚的追问",
},
]
: [],
};
});
reflections.sort((left, right) => right.local_date.localeCompare(left.local_date));
return { conversations, conversationDetails, memories, goals, reflections };
}
function previewUsageApi() {
const prompts = new Map([
...[["affinity", "AFFINITY.md", "AFFINITY.md"], ["planner", "PLANNER.md", "PLANNER.md"], ["replyer", "REPLYER.md", "roles/momoi/REPLYER.md"]].map(([id, filename, path]) => {
const source = new URL(`./config.example/prompts/${path}`, import.meta.url);
return [id, { id, filename, content: existsSync(source) ? readFileSync(source, "utf8") : "" }];
}),
[
"soul",
{
id: "soul",
filename: "SOUL.md",
content: [
"# Momoi",
"",
"你是 Momoi,和老师一起生活、聊天、做事的个人 Agent。",
"",
"保持自然、敏锐和真诚。记得共同经历,但不要为了展示记忆而复述档案。",
"遇到需要行动的事情,先理解真正的目标,再选择合适的工具。",
].join("\n"),
},
],
[
"heartbeat",
{
id: "heartbeat",
filename: "HEARTBEAT.md",
content: [
"留意老师最近在推进的事情。",
"空闲时可以整理游戏灵感、检查等待中的任务,或安静休息。",
"只有真的值得打扰时才主动发气泡。",
].join("\n"),
},
],
]);
const days = 30;
const today = new Date();
const daily = Array.from({ length: days }, (_, index) => {
const date = new Date(today);
date.setDate(today.getDate() - (days - 1 - index));
const wave = 0.55 + Math.sin(index / 3.2) * 0.35 + (index % 7 === 5 ? 0.45 : 0);
const requests = Math.round(6 + wave * 18);
const input = Math.round(4200 + wave * 18000);
const cacheRead = Math.round(input * (0.42 + (index % 5) * 0.08));
const output = Math.round(380 + wave * 1400);
const estimatedCost = Number((0.012 + wave * 0.084).toFixed(4));
return {
date: date.toISOString().slice(0, 10),
requests,
input_tokens: input,
uncached_tokens: input - cacheRead,
cache_read_tokens: cacheRead,
cache_write_tokens: 0,
output_tokens: output,
cache_hit_rate: Number(((cacheRead / input) * 100).toFixed(1)),
estimated_cost: estimatedCost,
};
});
const sum = (key) => daily.reduce((total, row) => total + row[key], 0);
const totals = {
requests: sum("requests"),
input_tokens: sum("input_tokens"),
uncached_tokens: sum("uncached_tokens"),
cache_read_tokens: sum("cache_read_tokens"),
cache_write_tokens: 0,
output_tokens: sum("output_tokens"),
cache_hit_rate: Number(
((sum("cache_read_tokens") / sum("input_tokens")) * 100).toFixed(1)
),
estimated_cost: Number(sum("estimated_cost").toFixed(4)),
};
const usage = {
source: "preview",
cost_available: true,
currency: "CNY",
timezone: "Asia/Shanghai",
days,
note: "本地预览数据,用来看折线。接上真实 dashboard 后会换成接入后的新调用。",
totals,
today: daily[daily.length - 1],
daily,
models: [
{ model: "deepseek-v4-flash", ...totals },
],
stages: [
{ stage: "owner", ...totals, requests: Math.round(totals.requests * 0.6) },
{ stage: "heartbeat", ...totals, requests: Math.round(totals.requests * 0.3) },
{ stage: "webhook", ...totals, requests: Math.round(totals.requests * 0.1) },
],
};
const json = (res, body, status = 200) => {
res.statusCode = status;
res.setHeader("Content-Type", "application/json");
res.end(JSON.stringify(body));
};
const settingsPreview = createSettingsPreview(json);
return {
name: "momoi-preview-api",
configureServer(server) {
server.middlewares.use((req, res, next) => {
if (process.env.MOMOI_PREVIEW === "0") {
next();
return;
}
const path = (req.url || "").split("?")[0];
if (settingsPreview(req, res, path)) return;
if (req.method === "GET" && path === "/api/metrics/requests") {
json(res, previewRequestMetrics());
return;
}
if (req.method === "POST" && path === "/api/auth/token") {
json(res, {
token: "preview-token",
token_type: "Bearer",
expires_in: 3600,
});
return;
}
if (req.method === "GET" && path === "/api/health") {
json(res, { ok: true, version: "0.5.5" });
return;
}
if (req.method === "GET" && path === "/api/settings/prompts") {
json(res, { items: [...prompts.values()] });
return;
}
if (req.method === "GET" && path === "/api/settings") {
json(res, { prompts: [...prompts.values()] });
return;
}
if (req.method === "PUT" && path.startsWith("/api/settings/prompts/")) {
const id = decodeURIComponent(path.slice("/api/settings/prompts/".length));
const item = prompts.get(id);
if (!item) {
json(res, { error: "prompt not found" }, 404);
return;
}
let raw = "";
req.setEncoding("utf8");
req.on("data", (chunk) => { raw += chunk; });
req.on("end", () => {
try {
const body = JSON.parse(raw);
if (typeof body.content !== "string") {
json(res, { error: "content must be a string" }, 400);
return;
}
if (id === "soul" && !body.content.trim()) {
json(res, { error: `${id} prompt must not be empty` }, 400);
return;
}
const updated = { ...item, content: body.content };
prompts.set(id, updated);
json(res, updated);
} catch {
json(res, { error: "invalid json" }, 400);
}
});
return;
}
const records = previewRecords();
if (req.method === "GET" && path === "/api/current-state") {
json(res, previewCurrentState());
return;
}
if (req.method === "GET" && path === "/api/overview") {
const now = previewNow();
json(res, {
current_state: previewCurrentState(),
counts: {
conversations: records.conversations.length,
messages: 42,
reflections: records.reflections.length,
goals: records.goals.filter((item) =>
["active", "waiting", "blocked"].includes(item.status),
).length,
emotions: previewEmotions().length,
memories: records.memories.length,
},