@chainlesschain/personal-data-hub 0.4.29 → 0.4.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/forensics/qq-nt-collect.js +190 -0
- package/lib/prompt-builder.js +15 -1
- package/package.json +8 -3
- package/__tests__/adapter-guide.test.js +0 -47
- package/__tests__/adapter-spec.test.js +0 -78
- package/__tests__/adapters/ai-chat-cookie-capture-spec.test.js +0 -211
- package/__tests__/adapters/ai-chat-health-checker.test.js +0 -262
- package/__tests__/adapters/ai-chat-history.test.js +0 -396
- package/__tests__/adapters/ai-chat-http-client.test.js +0 -242
- package/__tests__/adapters/ai-chat-vendors.test.js +0 -874
- package/__tests__/adapters/alipay-bill-adapter.test.js +0 -538
- package/__tests__/adapters/apple-health.test.js +0 -95
- package/__tests__/adapters/bank-family.test.js +0 -125
- package/__tests__/adapters/biz-tianyancha.test.js +0 -159
- package/__tests__/adapters/browser-history-chrome.test.js +0 -377
- package/__tests__/adapters/browser-history-edge.test.js +0 -159
- package/__tests__/adapters/car-mercedesme.test.js +0 -74
- package/__tests__/adapters/doc-baidu-netdisk.test.js +0 -102
- package/__tests__/adapters/doc-camscanner.test.js +0 -147
- package/__tests__/adapters/doc-platforms.test.js +0 -177
- package/__tests__/adapters/edu-huawei-learning-live.test.js +0 -198
- package/__tests__/adapters/edu-zuoyebang-live.test.js +0 -226
- package/__tests__/adapters/email-adapter-snapshot.test.js +0 -237
- package/__tests__/adapters/email-adapter.test.js +0 -742
- package/__tests__/adapters/email-classifier.test.js +0 -347
- package/__tests__/adapters/email-imap-session.test.js +0 -334
- package/__tests__/adapters/email-parser.test.js +0 -244
- package/__tests__/adapters/email-pdf-extractor.test.js +0 -529
- package/__tests__/adapters/email-providers.test.js +0 -84
- package/__tests__/adapters/email-retry-progress.test.js +0 -294
- package/__tests__/adapters/email-templates.test.js +0 -822
- package/__tests__/adapters/family-23-collectors-scaffold.test.js +0 -182
- package/__tests__/adapters/finance-alipay-live.test.js +0 -258
- package/__tests__/adapters/finance-dcep.test.js +0 -74
- package/__tests__/adapters/fitness-joyrun.test.js +0 -82
- package/__tests__/adapters/game-genshin-live.test.js +0 -238
- package/__tests__/adapters/game-genshin-scaffold.test.js +0 -108
- package/__tests__/adapters/game-honor-of-kings-live.test.js +0 -230
- package/__tests__/adapters/git-activity.test.js +0 -222
- package/__tests__/adapters/gov-12123.test.js +0 -103
- package/__tests__/adapters/gov-ixiamen.test.js +0 -150
- package/__tests__/adapters/gov-tax.test.js +0 -135
- package/__tests__/adapters/health-meiyou.test.js +0 -125
- package/__tests__/adapters/local-files.test.js +0 -264
- package/__tests__/adapters/local-im-pc.test.js +0 -154
- package/__tests__/adapters/messaging-whatsapp.test.js +0 -289
- package/__tests__/adapters/music-kugou.test.js +0 -187
- package/__tests__/adapters/music-qq.test.js +0 -112
- package/__tests__/adapters/netease-music-live.test.js +0 -244
- package/__tests__/adapters/netease-music.test.js +0 -74
- package/__tests__/adapters/pc-local-discovery.test.js +0 -141
- package/__tests__/adapters/qq-pc-direct-read.test.js +0 -227
- package/__tests__/adapters/reading-family.test.js +0 -108
- package/__tests__/adapters/recruit-boss.test.js +0 -180
- package/__tests__/adapters/shell-history.test.js +0 -180
- package/__tests__/adapters/shopping-base.test.js +0 -179
- package/__tests__/adapters/shopping-dianping.test.js +0 -239
- package/__tests__/adapters/social-bilibili-adb-api-client.test.js +0 -721
- package/__tests__/adapters/social-bilibili-adb-chromium-cookies-reader.test.js +0 -346
- package/__tests__/adapters/social-bilibili-adb-collector.test.js +0 -284
- package/__tests__/adapters/social-bilibili-adb-cookies-extension.test.js +0 -343
- package/__tests__/adapters/social-bilibili-adb-snapshot-builder.test.js +0 -296
- package/__tests__/adapters/social-csdn.test.js +0 -175
- package/__tests__/adapters/social-dongchedi.test.js +0 -165
- package/__tests__/adapters/social-douyin-adb-aweme-detail.test.js +0 -165
- package/__tests__/adapters/social-douyin-adb-collector.test.js +0 -254
- package/__tests__/adapters/social-douyin-adb-db-extension.test.js +0 -114
- package/__tests__/adapters/social-douyin-adb-im-db-parser.test.js +0 -304
- package/__tests__/adapters/social-douyin-adb-snapshot-builder.test.js +0 -216
- package/__tests__/adapters/social-douyin-adb-usage-profile.test.js +0 -229
- package/__tests__/adapters/social-douyin-adb-watch-history.test.js +0 -269
- package/__tests__/adapters/social-kuaishou-adb-api-client.test.js +0 -496
- package/__tests__/adapters/social-kuaishou-adb-collector.test.js +0 -276
- package/__tests__/adapters/social-kuaishou-adb-cookies-extension.test.js +0 -152
- package/__tests__/adapters/social-kuaishou-adb-snapshot-builder.test.js +0 -178
- package/__tests__/adapters/social-toutiao-adb-account-reader.test.js +0 -135
- package/__tests__/adapters/social-toutiao-adb-api-client.test.js +0 -626
- package/__tests__/adapters/social-toutiao-adb-article.test.js +0 -155
- package/__tests__/adapters/social-toutiao-adb-collector.test.js +0 -378
- package/__tests__/adapters/social-toutiao-adb-cookies-extension.test.js +0 -193
- package/__tests__/adapters/social-toutiao-adb-snapshot-builder.test.js +0 -196
- package/__tests__/adapters/social-toutiao-kuaishou-scaffold.test.js +0 -311
- package/__tests__/adapters/social-weibo-adb-api-client.test.js +0 -362
- package/__tests__/adapters/social-weibo-adb-collector.test.js +0 -201
- package/__tests__/adapters/social-weibo-adb-cookies-extension.test.js +0 -167
- package/__tests__/adapters/social-weibo-adb-snapshot-builder.test.js +0 -189
- package/__tests__/adapters/social-xiaohongshu-adb-api-client.test.js +0 -431
- package/__tests__/adapters/social-xiaohongshu-adb-collector.test.js +0 -207
- package/__tests__/adapters/social-xiaohongshu-adb-cookies-extension.test.js +0 -0
- package/__tests__/adapters/social-xiaohongshu-adb-sign-provider-injection.test.js +0 -351
- package/__tests__/adapters/social-xiaohongshu-adb-sign.test.js +0 -130
- package/__tests__/adapters/social-xiaohongshu-adb-snapshot-builder.test.js +0 -200
- package/__tests__/adapters/social-zhihu.test.js +0 -246
- package/__tests__/adapters/system-data-adapter.test.js +0 -443
- package/__tests__/adapters/system-data-android-ingest.test.js +0 -144
- package/__tests__/adapters/system-data-android.test.js +0 -519
- package/__tests__/adapters/system-data-disclosure.test.js +0 -153
- package/__tests__/adapters/travel-12306.test.js +0 -512
- package/__tests__/adapters/travel-amap.test.js +0 -219
- package/__tests__/adapters/travel-baidu-map.test.js +0 -305
- package/__tests__/adapters/travel-base.test.js +0 -205
- package/__tests__/adapters/travel-ctrip.test.js +0 -377
- package/__tests__/adapters/travel-didi-consumer.test.js +0 -66
- package/__tests__/adapters/travel-didi.test.js +0 -204
- package/__tests__/adapters/travel-tencent-map.test.js +0 -207
- package/__tests__/adapters/travel-tongcheng.test.js +0 -289
- package/__tests__/adapters/video-platforms.test.js +0 -152
- package/__tests__/adapters/video-xigua.test.js +0 -106
- package/__tests__/adapters/vscode.test.js +0 -299
- package/__tests__/adapters/wechat-bootstrap.test.js +0 -240
- package/__tests__/adapters/wechat-env-probe.test.js +0 -162
- package/__tests__/adapters/wechat-frida-agent.test.js +0 -322
- package/__tests__/adapters/wechat-frida-integration.test.js +0 -149
- package/__tests__/adapters/wechat-frida-key-provider.test.js +0 -188
- package/__tests__/adapters/wechat-md5-key-provider.test.js +0 -101
- package/__tests__/adapters/wechat-pc-direct-read.test.js +0 -365
- package/__tests__/adapters/wechat-pc-group-topic.test.js +0 -63
- package/__tests__/adapters/wechat-pc-v4-sidecar.test.js +0 -72
- package/__tests__/adapters/weread.test.js +0 -123
- package/__tests__/adapters/wework-pc.test.js +0 -124
- package/__tests__/adapters/win-recent.test.js +0 -192
- package/__tests__/analysis-skills.test.js +0 -754
- package/__tests__/analysis.test.js +0 -1845
- package/__tests__/audio-ximalaya-snapshot.test.js +0 -279
- package/__tests__/batch.test.js +0 -133
- package/__tests__/bridges-cc-kg.test.js +0 -231
- package/__tests__/bridges-cc-llm.test.js +0 -191
- package/__tests__/bridges-cc-rag.test.js +0 -162
- package/__tests__/categories.test.js +0 -92
- package/__tests__/e2e/ai-chat-cross-source-journey.test.js +0 -213
- package/__tests__/e2e/full-user-journey.test.js +0 -188
- package/__tests__/e2e/local-data-adapters-cli.e2e.test.js +0 -146
- package/__tests__/entity-resolver-ingest-hook.test.js +0 -177
- package/__tests__/entity-resolver-stages.test.js +0 -411
- package/__tests__/entity-resolver-vault.test.js +0 -249
- package/__tests__/entity-resolver.test.js +0 -526
- package/__tests__/fitness-keep-snapshot.test.js +0 -224
- package/__tests__/fixtures/entity-resolver-200-mock.json +0 -96
- package/__tests__/ids.test.js +0 -45
- package/__tests__/integration/ai-chat-history-registry.test.js +0 -228
- package/__tests__/integration/aichat-wizard-end-to-end.test.js +0 -282
- package/__tests__/integration/cross-adapter-pipelines.test.js +0 -396
- package/__tests__/integration/local-data-adapters-pipeline.test.js +0 -373
- package/__tests__/integration/social-bilibili-pipeline.test.js +0 -261
- package/__tests__/integration/wechat-bootstrap-end-to-end.test.js +0 -390
- package/__tests__/key-providers.test.js +0 -126
- package/__tests__/kg-derive.test.js +0 -219
- package/__tests__/llm-client.test.js +0 -122
- package/__tests__/longtail-adapters.test.js +0 -281
- package/__tests__/messaging-qq-snapshot.test.js +0 -294
- package/__tests__/mobile-extractor-encrypted.test.js +0 -460
- package/__tests__/mobile-extractor.test.js +0 -288
- package/__tests__/mock-adapter.test.js +0 -93
- package/__tests__/prompt-builder.test.js +0 -249
- package/__tests__/query-parser.test.js +0 -365
- package/__tests__/rag-derive.test.js +0 -169
- package/__tests__/registry-readiness.test.js +0 -292
- package/__tests__/registry.test.js +0 -420
- package/__tests__/salvage-ingest.test.js +0 -97
- package/__tests__/schemas.test.js +0 -331
- package/__tests__/shopping-adapters.test.js +0 -392
- package/__tests__/shopping-eleme-snapshot.test.js +0 -454
- package/__tests__/shopping-pinduoduo-snapshot.test.js +0 -484
- package/__tests__/shopping-snapshot.test.js +0 -438
- package/__tests__/shopping-vipshop-snapshot.test.js +0 -425
- package/__tests__/shopping-xianyu-snapshot.test.js +0 -451
- package/__tests__/sidecar-contacts-cross-validate.test.js +0 -186
- package/__tests__/sidecar-supervisor.test.js +0 -128
- package/__tests__/sign-providers.test.js +0 -62
- package/__tests__/social-adapters.test.js +0 -280
- package/__tests__/social-bilibili-snapshot.test.js +0 -278
- package/__tests__/social-douban-snapshot.test.js +0 -351
- package/__tests__/social-douyin-im-direct-read.test.js +0 -377
- package/__tests__/social-douyin-salvage-collector.test.js +0 -98
- package/__tests__/social-douyin-salvage-mapper.test.js +0 -90
- package/__tests__/social-douyin-snapshot.test.js +0 -256
- package/__tests__/social-kuaishou-snapshot.test.js +0 -362
- package/__tests__/social-toutiao-snapshot.test.js +0 -366
- package/__tests__/social-weibo-snapshot.test.js +0 -234
- package/__tests__/social-weibo-sqlite-device.test.js +0 -174
- package/__tests__/social-xiaohongshu-snapshot.test.js +0 -232
- package/__tests__/sqlite-leaf-salvage.test.js +0 -97
- package/__tests__/travel-adapters.test.js +0 -483
- package/__tests__/travel-maps-snapshot.test.js +0 -426
- package/__tests__/vault-driver-error.test.js +0 -74
- package/__tests__/vault-search-helpers.test.js +0 -104
- package/__tests__/vault-search.test.js +0 -423
- package/__tests__/vault.test.js +0 -767
- package/__tests__/wechat-adapter.test.js +0 -594
- package/__tests__/whatsapp-adapter.test.js +0 -138
- package/scripts/_make-fixture-all.js +0 -126
- package/scripts/_make-fixture-contacts.js +0 -84
- package/scripts/evaluate-entity-resolver.js +0 -213
- package/scripts/run-native-tests-sandbox.sh +0 -55
- package/scripts/smoke-phase-5-5.js +0 -196
- package/scripts/smoke-phase-5-7.js +0 -181
- package/scripts/smoke-system-data-contacts.js +0 -309
- package/scripts/smoke-system-data.js +0 -312
- package/vitest.config.js +0 -88
|
@@ -1,365 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { describe, it, expect } from "vitest";
|
|
4
|
-
|
|
5
|
-
const {
|
|
6
|
-
parseQuery,
|
|
7
|
-
parseTimeWindow,
|
|
8
|
-
parseFilters,
|
|
9
|
-
parseIntent,
|
|
10
|
-
parseEntityFocus,
|
|
11
|
-
extractEntityTerm,
|
|
12
|
-
extractPersonNameCandidate,
|
|
13
|
-
} = require("../lib/query-parser");
|
|
14
|
-
|
|
15
|
-
// Pin "now" to 2026-05-19 12:00:00 UTC for deterministic windows
|
|
16
|
-
const NOW = new Date("2026-05-19T12:00:00Z").getTime();
|
|
17
|
-
|
|
18
|
-
describe("parseTimeWindow", () => {
|
|
19
|
-
it("今天 → start of today through end of today", () => {
|
|
20
|
-
const w = parseTimeWindow("我今天花了多少?", NOW);
|
|
21
|
-
expect(w).not.toBeNull();
|
|
22
|
-
const startOfDay = new Date(NOW);
|
|
23
|
-
startOfDay.setHours(0, 0, 0, 0);
|
|
24
|
-
expect(w.since).toBe(startOfDay.getTime());
|
|
25
|
-
expect(w.until).toBe(startOfDay.getTime() + 86_400_000 - 1);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it("昨天 → start of yesterday through end of yesterday", () => {
|
|
29
|
-
const w = parseTimeWindow("昨天的订单", NOW);
|
|
30
|
-
expect(w).not.toBeNull();
|
|
31
|
-
expect(w.until - w.since).toBe(86_400_000 - 1);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it("上个月 → full previous calendar month", () => {
|
|
35
|
-
const w = parseTimeWindow("上个月支出", NOW);
|
|
36
|
-
expect(w).not.toBeNull();
|
|
37
|
-
// NOW is 2026-05-19; previous month = 2026-04
|
|
38
|
-
const apr1 = new Date(2026, 3, 1).getTime();
|
|
39
|
-
const may1 = new Date(2026, 4, 1).getTime();
|
|
40
|
-
expect(w.since).toBe(apr1);
|
|
41
|
-
expect(w.until).toBe(may1 - 1);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("本月 → current calendar month", () => {
|
|
45
|
-
const w = parseTimeWindow("本月开销", NOW);
|
|
46
|
-
expect(w).not.toBeNull();
|
|
47
|
-
expect(w.since).toBe(new Date(2026, 4, 1).getTime());
|
|
48
|
-
expect(w.until).toBe(new Date(2026, 5, 1).getTime() - 1);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it("去年 → full previous calendar year", () => {
|
|
52
|
-
const w = parseTimeWindow("去年我去过哪些地方", NOW);
|
|
53
|
-
expect(w.since).toBe(new Date(2025, 0, 1).getTime());
|
|
54
|
-
expect(w.until).toBe(new Date(2025, 11, 1).getTime() + 31 * 86_400_000 - 1);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("最近 30 天 → past 30-day window ending now", () => {
|
|
58
|
-
const w = parseTimeWindow("最近 30 天聊过什么", NOW);
|
|
59
|
-
expect(w.until).toBe(NOW);
|
|
60
|
-
expect(NOW - w.since).toBe(30 * 86_400_000);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it("最近 N 周 / 最近 N 个月 patterns work", () => {
|
|
64
|
-
const week = parseTimeWindow("最近 2 周", NOW);
|
|
65
|
-
expect(NOW - week.since).toBe(14 * 86_400_000);
|
|
66
|
-
|
|
67
|
-
const months = parseTimeWindow("最近 3 个月", NOW);
|
|
68
|
-
expect(months.until).toBe(NOW);
|
|
69
|
-
expect(months.since).toBeLessThan(NOW);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it("最近 N 个月 does NOT month-overflow on a month-end day (regression)", () => {
|
|
73
|
-
// Naive setMonth(getMonth()-1) on Mar 31 lands on "Feb 31" → Mar 3, silently
|
|
74
|
-
// dropping all of February from the window. since must land in February.
|
|
75
|
-
const mar31 = new Date(2026, 2, 31, 12, 0, 0).getTime();
|
|
76
|
-
const since = parseTimeWindow("最近1个月", mar31).since;
|
|
77
|
-
const d = new Date(since);
|
|
78
|
-
expect(d.getFullYear()).toBe(2026);
|
|
79
|
-
expect(d.getMonth()).toBe(1); // February, NOT still March
|
|
80
|
-
expect(d.getDate()).toBe(28); // clamped to Feb's last day
|
|
81
|
-
|
|
82
|
-
// May 31 −1mo → April 30 (April has 30 days), not May 1.
|
|
83
|
-
const may31 = new Date(2026, 4, 31, 12, 0, 0).getTime();
|
|
84
|
-
const aprSince = new Date(parseTimeWindow("最近1个月", may31).since);
|
|
85
|
-
expect(aprSince.getMonth()).toBe(3); // April
|
|
86
|
-
expect(aprSince.getDate()).toBe(30);
|
|
87
|
-
|
|
88
|
-
// mid-month is unaffected: Mar 15 −1mo → Feb 15.
|
|
89
|
-
const mar15 = new Date(2026, 2, 15, 12, 0, 0).getTime();
|
|
90
|
-
expect(new Date(parseTimeWindow("最近1个月", mar15).since).getDate()).toBe(15);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it("YYYY 年 M 月 → that calendar month", () => {
|
|
94
|
-
const w = parseTimeWindow("2024 年 7 月在淘宝下过几单", NOW);
|
|
95
|
-
expect(w.since).toBe(new Date(2024, 6, 1).getTime());
|
|
96
|
-
expect(w.until).toBe(new Date(2024, 7, 1).getTime() - 1);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it("returns null for question without time clue", () => {
|
|
100
|
-
expect(parseTimeWindow("妈妈手机号是多少", NOW)).toBeNull();
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it("returns null for non-string input", () => {
|
|
104
|
-
expect(parseTimeWindow(null)).toBeNull();
|
|
105
|
-
expect(parseTimeWindow(undefined)).toBeNull();
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
describe("parseFilters", () => {
|
|
110
|
-
it("identifies subtype via keywords (Chinese + English)", () => {
|
|
111
|
-
expect(parseFilters("今年在淘宝下了多少单").subtype).toBe("order");
|
|
112
|
-
expect(parseFilters("上个月总共花了多少").subtype).toBe("payment");
|
|
113
|
-
expect(parseFilters("转给妈妈多少钱").subtype).toBe("transfer");
|
|
114
|
-
expect(parseFilters("我今年的收入").subtype).toBe("income");
|
|
115
|
-
expect(parseFilters("我跟妈妈聊了什么").subtype).toBe("message");
|
|
116
|
-
expect(parseFilters("我朋友圈发了啥").subtype).toBe("post");
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it("bare 收到 does not steal non-income subtypes (regression)", () => {
|
|
120
|
-
// 收到 ("receive") used to match income before message → "收到多少消息"
|
|
121
|
-
// was mis-classified as income.
|
|
122
|
-
expect(parseFilters("我收到多少消息").subtype).toBe("message");
|
|
123
|
-
expect(parseFilters("收到的快递").subtype).toBeUndefined();
|
|
124
|
-
expect(parseFilters("收到转账了吗").subtype).toBe("transfer"); // still transfer
|
|
125
|
-
// genuine income keywords still classify
|
|
126
|
-
expect(parseFilters("这个月工资多少").subtype).toBe("income");
|
|
127
|
-
expect(parseFilters("进账多少").subtype).toBe("income");
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it("identifies adapter via keywords (Chinese + English)", () => {
|
|
131
|
-
expect(parseFilters("淘宝今年下了多少单").adapter).toBe("taobao");
|
|
132
|
-
expect(parseFilters("支付宝账单").adapter).toBe("alipay-bill");
|
|
133
|
-
expect(parseFilters("微信里我跟谁聊最多").adapter).toBe("wechat");
|
|
134
|
-
expect(parseFilters("高德历史足迹").adapter).toBe("amap");
|
|
135
|
-
expect(parseFilters("DeepSeek 我之前问过啥").adapter).toBe("ai-chat-history");
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it("returns empty object when no clue", () => {
|
|
139
|
-
expect(parseFilters("hello world")).toEqual({});
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
describe("parseIntent", () => {
|
|
144
|
-
it("sum-amount when 'total ... money' phrasing", () => {
|
|
145
|
-
expect(parseIntent("上个月总共花了多少")).toBe("sum-amount");
|
|
146
|
-
expect(parseIntent("我今年开销加起来")).toBe("sum-amount");
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it("sum-amount for spending questions WITHOUT an explicit 总共/合计", () => {
|
|
150
|
-
// Regression: these very common phrasings previously fell through to
|
|
151
|
-
// intent=list (→ engine returned a row sample instead of the authoritative
|
|
152
|
-
// sumEventAmount total).
|
|
153
|
-
expect(parseIntent("我这个月花了多少钱")).toBe("sum-amount");
|
|
154
|
-
expect(parseIntent("上个月在淘宝花了多少钱")).toBe("sum-amount");
|
|
155
|
-
expect(parseIntent("这个月消费多少")).toBe("sum-amount");
|
|
156
|
-
expect(parseIntent("花了多少")).toBe("sum-amount");
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it("sum-amount for INCOME-side questions (收入/赚/到账)", () => {
|
|
160
|
-
// Regression: income amount words were missing → "总共收入多少" even
|
|
161
|
-
// mis-returned "count". Both with and without 总共.
|
|
162
|
-
expect(parseIntent("这个月收入多少")).toBe("sum-amount");
|
|
163
|
-
expect(parseIntent("我这个月赚了多少")).toBe("sum-amount");
|
|
164
|
-
expect(parseIntent("上个月到账多少")).toBe("sum-amount");
|
|
165
|
-
expect(parseIntent("总共收入多少")).toBe("sum-amount");
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it("count for 多少X / 几X measure-word symmetry (多少条/多少单 were missed)", () => {
|
|
169
|
-
expect(parseIntent("我有多少条朋友圈")).toBe("count");
|
|
170
|
-
expect(parseIntent("下了多少单")).toBe("count");
|
|
171
|
-
expect(parseIntent("发了多少条微博")).toBe("count");
|
|
172
|
-
expect(parseIntent("多少笔交易")).toBe("count");
|
|
173
|
-
expect(parseIntent("几部电影")).toBe("count");
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it("count when 'how many' phrasing", () => {
|
|
177
|
-
expect(parseIntent("最近多少次跟妈妈聊过")).toBe("count");
|
|
178
|
-
expect(parseIntent("我下了几单")).toBe("count");
|
|
179
|
-
// the new sum-amount rule must NOT steal a count question that also
|
|
180
|
-
// mentions spending ("how many TIMES did I spend").
|
|
181
|
-
expect(parseIntent("消费了多少次")).toBe("count");
|
|
182
|
-
expect(parseIntent("花了多少次钱")).toBe("count");
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
it("latest when 'recent / latest'", () => {
|
|
186
|
-
expect(parseIntent("最近一次转账")).toBe("latest");
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
it("list as default", () => {
|
|
190
|
-
expect(parseIntent("妈妈的手机号")).toBe("list");
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
describe("parseEntityFocus", () => {
|
|
195
|
-
it("returns 'persons' for 联系人 / 通讯录 phrasing", () => {
|
|
196
|
-
expect(parseEntityFocus("我有哪些联系人")).toBe("persons");
|
|
197
|
-
expect(parseEntityFocus("通讯录里有多少人")).toBe("persons");
|
|
198
|
-
expect(parseEntityFocus("好友列表谁是张三")).toBe("persons");
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
it("returns 'persons' for phone-number phrasing", () => {
|
|
202
|
-
expect(parseEntityFocus("妈手机号是多少")).toBe("persons");
|
|
203
|
-
expect(parseEntityFocus("王医生的电话号码")).toBe("persons");
|
|
204
|
-
expect(parseEntityFocus("show me my contacts")).toBe("persons");
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
it("returns 'items' for installed-app phrasing", () => {
|
|
208
|
-
expect(parseEntityFocus("我装了哪些 app")).toBe("items");
|
|
209
|
-
expect(parseEntityFocus("有哪些游戏")).toBe("items");
|
|
210
|
-
expect(parseEntityFocus("installed apps")).toBe("items");
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
it("returns null when no focus signal", () => {
|
|
214
|
-
expect(parseEntityFocus("上个月在淘宝花了多少")).toBeNull();
|
|
215
|
-
expect(parseEntityFocus("最近的订单")).toBeNull();
|
|
216
|
-
expect(parseEntityFocus("hello")).toBeNull();
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
it("returns null for non-string / empty input", () => {
|
|
220
|
-
expect(parseEntityFocus("")).toBeNull();
|
|
221
|
-
expect(parseEntityFocus(null)).toBeNull();
|
|
222
|
-
expect(parseEntityFocus(undefined)).toBeNull();
|
|
223
|
-
});
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
describe("parseQuery (integration)", () => {
|
|
227
|
-
it("full parse for spending question", () => {
|
|
228
|
-
const r = parseQuery("上个月在淘宝总共花了多少钱?", { now: NOW });
|
|
229
|
-
expect(r.timeWindow.since).toBe(new Date(2026, 3, 1).getTime());
|
|
230
|
-
expect(r.filters.subtype).toBe("payment");
|
|
231
|
-
expect(r.filters.adapter).toBe("taobao");
|
|
232
|
-
expect(r.intent).toBe("sum-amount");
|
|
233
|
-
expect(r.entityFocus).toBeNull();
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
it("contact question carries entityFocus=persons", () => {
|
|
237
|
-
const r = parseQuery("我有哪些联系人", { now: NOW });
|
|
238
|
-
expect(r.entityFocus).toBe("persons");
|
|
239
|
-
expect(r.intent).toBe("list");
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
it("full parse for footprint question", () => {
|
|
243
|
-
const r = parseQuery("去年我在高德上去过哪些地方", { now: NOW });
|
|
244
|
-
expect(r.timeWindow.since).toBe(new Date(2025, 0, 1).getTime());
|
|
245
|
-
expect(r.filters.adapter).toBe("amap");
|
|
246
|
-
expect(r.intent).toBe("list");
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
it("non-string question returns empty raw + nulls", () => {
|
|
250
|
-
const r = parseQuery(undefined);
|
|
251
|
-
expect(r.raw).toBe("");
|
|
252
|
-
expect(r.timeWindow).toBeNull();
|
|
253
|
-
expect(r.filters).toEqual({});
|
|
254
|
-
});
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
// ─── extractEntityTerm — FTS5 fulltext routing helper ───────────────────
|
|
258
|
-
//
|
|
259
|
-
// 2026-05-24 — Powers AnalysisEngine._gatherFacts intent=list augmentation:
|
|
260
|
-
// when the parser pulls a probable entity-name out of the question, the
|
|
261
|
-
// engine appends vault.searchEvents(q=term) hits to the FACTS pool. Wrong
|
|
262
|
-
// extractions are intentionally non-fatal — they waste a few rows of
|
|
263
|
-
// budget at worst, never lose existing events. Memory:
|
|
264
|
-
// pdh_analysis_engine_intent_routing.md.
|
|
265
|
-
|
|
266
|
-
describe("extractEntityTerm", () => {
|
|
267
|
-
it("extracts named entity from '提到 X 的消息' phrasing", () => {
|
|
268
|
-
expect(extractEntityTerm("提到王老板的消息")).toBe("王老板");
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
it("returns null when only stop-words remain (no entity hint)", () => {
|
|
272
|
-
expect(extractEntityTerm("上个月在淘宝总共花了多少?")).toBeNull();
|
|
273
|
-
expect(extractEntityTerm("在淘宝买了什么")).toBeNull();
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
it("picks the longest remaining chunk when several survive cleaning", () => {
|
|
277
|
-
// 苹果(2) vs 订单(stop) — only 苹果 left.
|
|
278
|
-
expect(extractEntityTerm("苹果的订单")).toBe("苹果");
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
it("strips list/search trigger words ('提到', '查找', '看一下')", () => {
|
|
282
|
-
expect(extractEntityTerm("查找王医生的订单")).toBe("王医生");
|
|
283
|
-
expect(extractEntityTerm("看一下王医生的最新消息")).toBe("王医生");
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
it("strips compound subtype keywords before shorter intent forms", () => {
|
|
287
|
-
// "多少钱" must clear before "多少" leaves stranded "钱". With clean
|
|
288
|
-
// stripping there is no leftover ≥2 char chunk → null.
|
|
289
|
-
expect(extractEntityTerm("我总共花了多少钱")).toBeNull();
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
it("ignores single-character residues (verbs leak through; 1-char names skipped first-pass)", () => {
|
|
293
|
-
// "我妈" → "我" stripped (pronoun), "妈" left as single char → filtered.
|
|
294
|
-
// Documented limitation; first-pass tradeoff for higher precision.
|
|
295
|
-
expect(extractEntityTerm("我妈最近发的微信")).toBeNull();
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
it("handles ASCII entity tokens (≥2 chars)", () => {
|
|
299
|
-
expect(extractEntityTerm("提到 GitHub 的消息")).toBe("GitHub");
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
it("returns null for non-string / empty input", () => {
|
|
303
|
-
expect(extractEntityTerm("")).toBeNull();
|
|
304
|
-
expect(extractEntityTerm(null)).toBeNull();
|
|
305
|
-
expect(extractEntityTerm(undefined)).toBeNull();
|
|
306
|
-
expect(extractEntityTerm(123)).toBeNull();
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
it("does not pick adapter keywords as the entity (handled by filters)", () => {
|
|
310
|
-
// "淘宝" 是 adapter,会被 parseFilters 抽走当 q.adapter;不该再被
|
|
311
|
-
// 当实体名重复 FTS 搜。
|
|
312
|
-
expect(extractEntityTerm("看下淘宝的订单")).toBeNull();
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
it("> 10 char tokens are dropped (probable concatenated noise)", () => {
|
|
316
|
-
// 拼出一个 12 char ASCII token,期望被 length 上限过滤掉
|
|
317
|
-
const r = extractEntityTerm("提到 abcdefghijkl 的消息");
|
|
318
|
-
expect(r).toBeNull();
|
|
319
|
-
});
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
// ─── extractPersonNameCandidate — persons-branch name search ─────────────
|
|
323
|
-
//
|
|
324
|
-
// 2026-05-27 — Powers AnalysisEngine entityFocus=persons name-search
|
|
325
|
-
// short-circuit. Differs from extractEntityTerm in two ways: strips
|
|
326
|
-
// person-FOCUS framing words first (联系人/手机号/etc.) and allows
|
|
327
|
-
// single-char Chinese names from a relation whitelist (妈/爸/姐/...).
|
|
328
|
-
|
|
329
|
-
describe("extractPersonNameCandidate", () => {
|
|
330
|
-
it("extracts multi-char name when present", () => {
|
|
331
|
-
expect(extractPersonNameCandidate("张三的电话号码")).toBe("张三");
|
|
332
|
-
expect(extractPersonNameCandidate("王医生手机号是多少")).toBe("王医生");
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
it("falls back to single-char relation word ('妈', '爸', '姐')", () => {
|
|
336
|
-
expect(extractPersonNameCandidate("妈手机号是多少")).toBe("妈");
|
|
337
|
-
expect(extractPersonNameCandidate("爸的电话")).toBe("爸");
|
|
338
|
-
expect(extractPersonNameCandidate("姐姐的号码")).toBe("姐姐");
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
it("multi-char wins over single-char fallback", () => {
|
|
342
|
-
// "王医生" (3 char) preferred over leaked single "医" / "生".
|
|
343
|
-
expect(extractPersonNameCandidate("王医生的手机号")).toBe("王医生");
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
it("returns null when no name candidate (pure framing)", () => {
|
|
347
|
-
expect(extractPersonNameCandidate("我有哪些联系人")).toBeNull();
|
|
348
|
-
expect(extractPersonNameCandidate("通讯录里有多少人")).toBeNull();
|
|
349
|
-
});
|
|
350
|
-
|
|
351
|
-
it("ignores single-char Chinese outside the relation whitelist", () => {
|
|
352
|
-
// "说" / "看" are not relation chars — should NOT slip through as names.
|
|
353
|
-
expect(extractPersonNameCandidate("说手机号")).toBeNull();
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
it("returns null for non-string / empty input", () => {
|
|
357
|
-
expect(extractPersonNameCandidate("")).toBeNull();
|
|
358
|
-
expect(extractPersonNameCandidate(null)).toBeNull();
|
|
359
|
-
expect(extractPersonNameCandidate(undefined)).toBeNull();
|
|
360
|
-
});
|
|
361
|
-
|
|
362
|
-
it("handles ASCII names ≥2 chars", () => {
|
|
363
|
-
expect(extractPersonNameCandidate("Alice 的电话号码")).toBe("Alice");
|
|
364
|
-
});
|
|
365
|
-
});
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { describe, it, expect } from "vitest";
|
|
4
|
-
|
|
5
|
-
const {
|
|
6
|
-
eventToRagDoc,
|
|
7
|
-
personToRagDoc,
|
|
8
|
-
placeToRagDoc,
|
|
9
|
-
itemToRagDoc,
|
|
10
|
-
topicToRagDoc,
|
|
11
|
-
entityToRagDoc,
|
|
12
|
-
deriveBatchDocs,
|
|
13
|
-
} = require("../lib/rag-derive");
|
|
14
|
-
|
|
15
|
-
const sourceOk = (adapter = "test") => ({
|
|
16
|
-
adapter,
|
|
17
|
-
adapterVersion: "0.1.0",
|
|
18
|
-
capturedAt: 1700000000000,
|
|
19
|
-
capturedBy: "api",
|
|
20
|
-
originalId: "ord-42",
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
describe("eventToRagDoc", () => {
|
|
24
|
-
it("includes title + text + amount + subtype + adapter prose", () => {
|
|
25
|
-
const doc = eventToRagDoc({
|
|
26
|
-
id: "e1",
|
|
27
|
-
type: "event",
|
|
28
|
-
subtype: "order",
|
|
29
|
-
occurredAt: 1700000000000,
|
|
30
|
-
ingestedAt: 1700000000001,
|
|
31
|
-
content: {
|
|
32
|
-
title: "妈妈生日蛋白粉",
|
|
33
|
-
text: "送到妈妈家",
|
|
34
|
-
amount: { value: 288.5, currency: "CNY", direction: "out" },
|
|
35
|
-
},
|
|
36
|
-
source: sourceOk("taobao"),
|
|
37
|
-
});
|
|
38
|
-
expect(doc.id).toBe("e1");
|
|
39
|
-
expect(doc.type).toBe("event");
|
|
40
|
-
expect(doc.text).toContain("妈妈生日蛋白粉");
|
|
41
|
-
expect(doc.text).toContain("送到妈妈家");
|
|
42
|
-
expect(doc.text).toContain("-288.5 CNY");
|
|
43
|
-
expect(doc.text).toContain("type: order");
|
|
44
|
-
expect(doc.text).toContain("from: taobao");
|
|
45
|
-
expect(doc.metadata.subtype).toBe("order");
|
|
46
|
-
expect(doc.metadata.adapter).toBe("taobao");
|
|
47
|
-
expect(doc.metadata.originalId).toBe("ord-42");
|
|
48
|
-
expect(doc.metadata.occurredAt).toBe(1700000000000);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it("'in' direction renders with '+' sign", () => {
|
|
52
|
-
const doc = eventToRagDoc({
|
|
53
|
-
id: "e",
|
|
54
|
-
type: "event",
|
|
55
|
-
subtype: "income",
|
|
56
|
-
occurredAt: 1,
|
|
57
|
-
ingestedAt: 1,
|
|
58
|
-
content: { amount: { value: 5000, currency: "CNY", direction: "in" } },
|
|
59
|
-
source: sourceOk(),
|
|
60
|
-
});
|
|
61
|
-
expect(doc.text).toContain("+5000 CNY");
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it("propagates topics into metadata", () => {
|
|
65
|
-
const doc = eventToRagDoc({
|
|
66
|
-
id: "e",
|
|
67
|
-
type: "event",
|
|
68
|
-
subtype: "message",
|
|
69
|
-
occurredAt: 1,
|
|
70
|
-
ingestedAt: 1,
|
|
71
|
-
content: { text: "hi" },
|
|
72
|
-
source: sourceOk(),
|
|
73
|
-
topics: ["topic-fam"],
|
|
74
|
-
});
|
|
75
|
-
expect(doc.metadata.topics).toEqual(["topic-fam"]);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
describe("personToRagDoc", () => {
|
|
80
|
-
it("packs names + relation + identifiers into searchable text", () => {
|
|
81
|
-
const doc = personToRagDoc({
|
|
82
|
-
id: "p1",
|
|
83
|
-
type: "person",
|
|
84
|
-
subtype: "contact",
|
|
85
|
-
names: ["妈妈", "陈某某"],
|
|
86
|
-
relation: "母亲",
|
|
87
|
-
identifiers: { phone: ["13800001111"], wechatId: "wxid_xyz" },
|
|
88
|
-
ingestedAt: 1,
|
|
89
|
-
source: sourceOk(),
|
|
90
|
-
});
|
|
91
|
-
expect(doc.text).toContain("妈妈");
|
|
92
|
-
expect(doc.text).toContain("陈某某");
|
|
93
|
-
expect(doc.text).toContain("relation: 母亲");
|
|
94
|
-
expect(doc.text).toContain("13800001111");
|
|
95
|
-
expect(doc.text).toContain("wechatId: wxid_xyz");
|
|
96
|
-
expect(doc.metadata.subtype).toBe("contact");
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
describe("placeToRagDoc", () => {
|
|
101
|
-
it("emits name + alias dedup + address + category", () => {
|
|
102
|
-
const doc = placeToRagDoc({
|
|
103
|
-
id: "pl",
|
|
104
|
-
type: "place",
|
|
105
|
-
name: "妈妈家",
|
|
106
|
-
aliases: ["妈妈家", "妈家"],
|
|
107
|
-
address: "厦门思明区",
|
|
108
|
-
category: "home",
|
|
109
|
-
coordinates: { lat: 24.5, lng: 118.1 },
|
|
110
|
-
ingestedAt: 1,
|
|
111
|
-
source: sourceOk(),
|
|
112
|
-
});
|
|
113
|
-
expect(doc.text).toContain("妈妈家");
|
|
114
|
-
expect(doc.text).toContain("妈家");
|
|
115
|
-
expect(doc.text).toContain("厦门思明区");
|
|
116
|
-
expect(doc.text).toContain("category: home");
|
|
117
|
-
expect(doc.metadata.coordinates).toEqual({ lat: 24.5, lng: 118.1 });
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
describe("itemToRagDoc", () => {
|
|
122
|
-
it("includes price + category", () => {
|
|
123
|
-
const doc = itemToRagDoc({
|
|
124
|
-
id: "i",
|
|
125
|
-
type: "item",
|
|
126
|
-
subtype: "product",
|
|
127
|
-
name: "蛋白粉",
|
|
128
|
-
category: "保健品",
|
|
129
|
-
price: { value: 288, currency: "CNY" },
|
|
130
|
-
ingestedAt: 1,
|
|
131
|
-
source: sourceOk(),
|
|
132
|
-
});
|
|
133
|
-
expect(doc.text).toContain("蛋白粉");
|
|
134
|
-
expect(doc.text).toContain("category: 保健品");
|
|
135
|
-
expect(doc.text).toContain("288 CNY");
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
describe("topicToRagDoc + entityToRagDoc + deriveBatchDocs", () => {
|
|
140
|
-
it("topic doc is its name", () => {
|
|
141
|
-
const doc = topicToRagDoc({
|
|
142
|
-
id: "t",
|
|
143
|
-
type: "topic",
|
|
144
|
-
name: "母亲健康",
|
|
145
|
-
ingestedAt: 1,
|
|
146
|
-
source: sourceOk(),
|
|
147
|
-
});
|
|
148
|
-
expect(doc.text).toBe("母亲健康");
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it("entityToRagDoc returns null for unknown types", () => {
|
|
152
|
-
expect(entityToRagDoc(null)).toBeNull();
|
|
153
|
-
expect(entityToRagDoc({ type: "alien" })).toBeNull();
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it("deriveBatchDocs filters empty-text entities", () => {
|
|
157
|
-
const docs = deriveBatchDocs({
|
|
158
|
-
events: [
|
|
159
|
-
// empty text — should be filtered
|
|
160
|
-
{ id: "empty", type: "event", subtype: "message", occurredAt: 1, ingestedAt: 1, content: {}, source: { adapter: "x", adapterVersion: "0.1.0", capturedAt: 1, capturedBy: "api" } },
|
|
161
|
-
// has text
|
|
162
|
-
{ id: "kept", type: "event", subtype: "message", occurredAt: 1, ingestedAt: 1, content: { text: "hi" }, source: { adapter: "x", adapterVersion: "0.1.0", capturedAt: 1, capturedBy: "api" } },
|
|
163
|
-
],
|
|
164
|
-
});
|
|
165
|
-
expect(docs.length).toBe(2); // 'empty' includes 'type: message' + 'from: x' so text is non-empty
|
|
166
|
-
// Both have text because structural prose is added — verify text is non-empty for both
|
|
167
|
-
expect(docs.every((d) => d.text.length > 0)).toBe(true);
|
|
168
|
-
});
|
|
169
|
-
});
|