@chainlesschain/personal-data-hub 0.4.28 → 0.4.30

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.
Files changed (204) hide show
  1. package/README.md +13 -5
  2. package/lib/adapters/social-douyin-adb/usage-profile-reader.js +253 -0
  3. package/lib/adapters/social-douyin-adb/watch-history-reader.js +104 -31
  4. package/lib/adapters/social-toutiao-adb/article-reader.js +202 -0
  5. package/lib/analysis-skills/overview.js +24 -4
  6. package/lib/analysis-skills/spending.js +63 -2
  7. package/lib/analysis-skills/timeline.js +11 -6
  8. package/lib/prompt-builder.js +15 -1
  9. package/lib/query-parser.js +38 -8
  10. package/package.json +4 -1
  11. package/__tests__/adapter-guide.test.js +0 -47
  12. package/__tests__/adapter-spec.test.js +0 -78
  13. package/__tests__/adapters/ai-chat-cookie-capture-spec.test.js +0 -211
  14. package/__tests__/adapters/ai-chat-health-checker.test.js +0 -262
  15. package/__tests__/adapters/ai-chat-history.test.js +0 -396
  16. package/__tests__/adapters/ai-chat-http-client.test.js +0 -242
  17. package/__tests__/adapters/ai-chat-vendors.test.js +0 -874
  18. package/__tests__/adapters/alipay-bill-adapter.test.js +0 -538
  19. package/__tests__/adapters/apple-health.test.js +0 -95
  20. package/__tests__/adapters/bank-family.test.js +0 -125
  21. package/__tests__/adapters/biz-tianyancha.test.js +0 -159
  22. package/__tests__/adapters/browser-history-chrome.test.js +0 -377
  23. package/__tests__/adapters/browser-history-edge.test.js +0 -159
  24. package/__tests__/adapters/car-mercedesme.test.js +0 -74
  25. package/__tests__/adapters/doc-baidu-netdisk.test.js +0 -102
  26. package/__tests__/adapters/doc-camscanner.test.js +0 -147
  27. package/__tests__/adapters/doc-platforms.test.js +0 -177
  28. package/__tests__/adapters/edu-huawei-learning-live.test.js +0 -198
  29. package/__tests__/adapters/edu-zuoyebang-live.test.js +0 -226
  30. package/__tests__/adapters/email-adapter-snapshot.test.js +0 -237
  31. package/__tests__/adapters/email-adapter.test.js +0 -742
  32. package/__tests__/adapters/email-classifier.test.js +0 -347
  33. package/__tests__/adapters/email-imap-session.test.js +0 -334
  34. package/__tests__/adapters/email-parser.test.js +0 -244
  35. package/__tests__/adapters/email-pdf-extractor.test.js +0 -529
  36. package/__tests__/adapters/email-providers.test.js +0 -84
  37. package/__tests__/adapters/email-retry-progress.test.js +0 -294
  38. package/__tests__/adapters/email-templates.test.js +0 -822
  39. package/__tests__/adapters/family-23-collectors-scaffold.test.js +0 -182
  40. package/__tests__/adapters/finance-alipay-live.test.js +0 -258
  41. package/__tests__/adapters/finance-dcep.test.js +0 -74
  42. package/__tests__/adapters/fitness-joyrun.test.js +0 -82
  43. package/__tests__/adapters/game-genshin-live.test.js +0 -238
  44. package/__tests__/adapters/game-genshin-scaffold.test.js +0 -108
  45. package/__tests__/adapters/game-honor-of-kings-live.test.js +0 -230
  46. package/__tests__/adapters/git-activity.test.js +0 -222
  47. package/__tests__/adapters/gov-12123.test.js +0 -103
  48. package/__tests__/adapters/gov-ixiamen.test.js +0 -150
  49. package/__tests__/adapters/gov-tax.test.js +0 -135
  50. package/__tests__/adapters/health-meiyou.test.js +0 -125
  51. package/__tests__/adapters/local-files.test.js +0 -264
  52. package/__tests__/adapters/local-im-pc.test.js +0 -154
  53. package/__tests__/adapters/messaging-whatsapp.test.js +0 -289
  54. package/__tests__/adapters/music-kugou.test.js +0 -187
  55. package/__tests__/adapters/music-qq.test.js +0 -112
  56. package/__tests__/adapters/netease-music-live.test.js +0 -244
  57. package/__tests__/adapters/netease-music.test.js +0 -74
  58. package/__tests__/adapters/pc-local-discovery.test.js +0 -141
  59. package/__tests__/adapters/qq-pc-direct-read.test.js +0 -227
  60. package/__tests__/adapters/reading-family.test.js +0 -108
  61. package/__tests__/adapters/recruit-boss.test.js +0 -180
  62. package/__tests__/adapters/shell-history.test.js +0 -180
  63. package/__tests__/adapters/shopping-base.test.js +0 -179
  64. package/__tests__/adapters/shopping-dianping.test.js +0 -239
  65. package/__tests__/adapters/social-bilibili-adb-api-client.test.js +0 -721
  66. package/__tests__/adapters/social-bilibili-adb-chromium-cookies-reader.test.js +0 -346
  67. package/__tests__/adapters/social-bilibili-adb-collector.test.js +0 -284
  68. package/__tests__/adapters/social-bilibili-adb-cookies-extension.test.js +0 -343
  69. package/__tests__/adapters/social-bilibili-adb-snapshot-builder.test.js +0 -296
  70. package/__tests__/adapters/social-csdn.test.js +0 -175
  71. package/__tests__/adapters/social-dongchedi.test.js +0 -165
  72. package/__tests__/adapters/social-douyin-adb-aweme-detail.test.js +0 -165
  73. package/__tests__/adapters/social-douyin-adb-collector.test.js +0 -254
  74. package/__tests__/adapters/social-douyin-adb-db-extension.test.js +0 -114
  75. package/__tests__/adapters/social-douyin-adb-im-db-parser.test.js +0 -304
  76. package/__tests__/adapters/social-douyin-adb-snapshot-builder.test.js +0 -216
  77. package/__tests__/adapters/social-douyin-adb-watch-history.test.js +0 -192
  78. package/__tests__/adapters/social-kuaishou-adb-api-client.test.js +0 -496
  79. package/__tests__/adapters/social-kuaishou-adb-collector.test.js +0 -276
  80. package/__tests__/adapters/social-kuaishou-adb-cookies-extension.test.js +0 -152
  81. package/__tests__/adapters/social-kuaishou-adb-snapshot-builder.test.js +0 -178
  82. package/__tests__/adapters/social-toutiao-adb-account-reader.test.js +0 -135
  83. package/__tests__/adapters/social-toutiao-adb-api-client.test.js +0 -626
  84. package/__tests__/adapters/social-toutiao-adb-collector.test.js +0 -378
  85. package/__tests__/adapters/social-toutiao-adb-cookies-extension.test.js +0 -193
  86. package/__tests__/adapters/social-toutiao-adb-snapshot-builder.test.js +0 -196
  87. package/__tests__/adapters/social-toutiao-kuaishou-scaffold.test.js +0 -311
  88. package/__tests__/adapters/social-weibo-adb-api-client.test.js +0 -362
  89. package/__tests__/adapters/social-weibo-adb-collector.test.js +0 -201
  90. package/__tests__/adapters/social-weibo-adb-cookies-extension.test.js +0 -167
  91. package/__tests__/adapters/social-weibo-adb-snapshot-builder.test.js +0 -189
  92. package/__tests__/adapters/social-xiaohongshu-adb-api-client.test.js +0 -431
  93. package/__tests__/adapters/social-xiaohongshu-adb-collector.test.js +0 -207
  94. package/__tests__/adapters/social-xiaohongshu-adb-cookies-extension.test.js +0 -0
  95. package/__tests__/adapters/social-xiaohongshu-adb-sign-provider-injection.test.js +0 -351
  96. package/__tests__/adapters/social-xiaohongshu-adb-sign.test.js +0 -130
  97. package/__tests__/adapters/social-xiaohongshu-adb-snapshot-builder.test.js +0 -200
  98. package/__tests__/adapters/social-zhihu.test.js +0 -246
  99. package/__tests__/adapters/system-data-adapter.test.js +0 -443
  100. package/__tests__/adapters/system-data-android-ingest.test.js +0 -144
  101. package/__tests__/adapters/system-data-android.test.js +0 -519
  102. package/__tests__/adapters/system-data-disclosure.test.js +0 -153
  103. package/__tests__/adapters/travel-12306.test.js +0 -512
  104. package/__tests__/adapters/travel-amap.test.js +0 -219
  105. package/__tests__/adapters/travel-baidu-map.test.js +0 -305
  106. package/__tests__/adapters/travel-base.test.js +0 -205
  107. package/__tests__/adapters/travel-ctrip.test.js +0 -377
  108. package/__tests__/adapters/travel-didi-consumer.test.js +0 -66
  109. package/__tests__/adapters/travel-didi.test.js +0 -204
  110. package/__tests__/adapters/travel-tencent-map.test.js +0 -207
  111. package/__tests__/adapters/travel-tongcheng.test.js +0 -289
  112. package/__tests__/adapters/video-platforms.test.js +0 -152
  113. package/__tests__/adapters/video-xigua.test.js +0 -106
  114. package/__tests__/adapters/vscode.test.js +0 -299
  115. package/__tests__/adapters/wechat-bootstrap.test.js +0 -240
  116. package/__tests__/adapters/wechat-env-probe.test.js +0 -162
  117. package/__tests__/adapters/wechat-frida-agent.test.js +0 -322
  118. package/__tests__/adapters/wechat-frida-integration.test.js +0 -149
  119. package/__tests__/adapters/wechat-frida-key-provider.test.js +0 -188
  120. package/__tests__/adapters/wechat-md5-key-provider.test.js +0 -101
  121. package/__tests__/adapters/wechat-pc-direct-read.test.js +0 -365
  122. package/__tests__/adapters/wechat-pc-group-topic.test.js +0 -63
  123. package/__tests__/adapters/wechat-pc-v4-sidecar.test.js +0 -72
  124. package/__tests__/adapters/weread.test.js +0 -123
  125. package/__tests__/adapters/wework-pc.test.js +0 -124
  126. package/__tests__/adapters/win-recent.test.js +0 -192
  127. package/__tests__/analysis-skills.test.js +0 -679
  128. package/__tests__/analysis.test.js +0 -1845
  129. package/__tests__/audio-ximalaya-snapshot.test.js +0 -279
  130. package/__tests__/batch.test.js +0 -133
  131. package/__tests__/bridges-cc-kg.test.js +0 -231
  132. package/__tests__/bridges-cc-llm.test.js +0 -191
  133. package/__tests__/bridges-cc-rag.test.js +0 -162
  134. package/__tests__/categories.test.js +0 -92
  135. package/__tests__/e2e/ai-chat-cross-source-journey.test.js +0 -213
  136. package/__tests__/e2e/full-user-journey.test.js +0 -188
  137. package/__tests__/e2e/local-data-adapters-cli.e2e.test.js +0 -146
  138. package/__tests__/entity-resolver-ingest-hook.test.js +0 -177
  139. package/__tests__/entity-resolver-stages.test.js +0 -411
  140. package/__tests__/entity-resolver-vault.test.js +0 -249
  141. package/__tests__/entity-resolver.test.js +0 -526
  142. package/__tests__/fitness-keep-snapshot.test.js +0 -224
  143. package/__tests__/fixtures/entity-resolver-200-mock.json +0 -96
  144. package/__tests__/ids.test.js +0 -45
  145. package/__tests__/integration/ai-chat-history-registry.test.js +0 -228
  146. package/__tests__/integration/aichat-wizard-end-to-end.test.js +0 -282
  147. package/__tests__/integration/cross-adapter-pipelines.test.js +0 -396
  148. package/__tests__/integration/local-data-adapters-pipeline.test.js +0 -373
  149. package/__tests__/integration/social-bilibili-pipeline.test.js +0 -261
  150. package/__tests__/integration/wechat-bootstrap-end-to-end.test.js +0 -390
  151. package/__tests__/key-providers.test.js +0 -126
  152. package/__tests__/kg-derive.test.js +0 -219
  153. package/__tests__/llm-client.test.js +0 -122
  154. package/__tests__/longtail-adapters.test.js +0 -281
  155. package/__tests__/messaging-qq-snapshot.test.js +0 -294
  156. package/__tests__/mobile-extractor-encrypted.test.js +0 -460
  157. package/__tests__/mobile-extractor.test.js +0 -288
  158. package/__tests__/mock-adapter.test.js +0 -93
  159. package/__tests__/prompt-builder.test.js +0 -249
  160. package/__tests__/query-parser.test.js +0 -302
  161. package/__tests__/rag-derive.test.js +0 -169
  162. package/__tests__/registry-readiness.test.js +0 -292
  163. package/__tests__/registry.test.js +0 -420
  164. package/__tests__/salvage-ingest.test.js +0 -97
  165. package/__tests__/schemas.test.js +0 -331
  166. package/__tests__/shopping-adapters.test.js +0 -392
  167. package/__tests__/shopping-eleme-snapshot.test.js +0 -454
  168. package/__tests__/shopping-pinduoduo-snapshot.test.js +0 -484
  169. package/__tests__/shopping-snapshot.test.js +0 -438
  170. package/__tests__/shopping-vipshop-snapshot.test.js +0 -425
  171. package/__tests__/shopping-xianyu-snapshot.test.js +0 -451
  172. package/__tests__/sidecar-contacts-cross-validate.test.js +0 -186
  173. package/__tests__/sidecar-supervisor.test.js +0 -128
  174. package/__tests__/sign-providers.test.js +0 -62
  175. package/__tests__/social-adapters.test.js +0 -280
  176. package/__tests__/social-bilibili-snapshot.test.js +0 -278
  177. package/__tests__/social-douban-snapshot.test.js +0 -351
  178. package/__tests__/social-douyin-im-direct-read.test.js +0 -377
  179. package/__tests__/social-douyin-salvage-collector.test.js +0 -98
  180. package/__tests__/social-douyin-salvage-mapper.test.js +0 -90
  181. package/__tests__/social-douyin-snapshot.test.js +0 -256
  182. package/__tests__/social-kuaishou-snapshot.test.js +0 -362
  183. package/__tests__/social-toutiao-snapshot.test.js +0 -366
  184. package/__tests__/social-weibo-snapshot.test.js +0 -234
  185. package/__tests__/social-weibo-sqlite-device.test.js +0 -174
  186. package/__tests__/social-xiaohongshu-snapshot.test.js +0 -232
  187. package/__tests__/sqlite-leaf-salvage.test.js +0 -97
  188. package/__tests__/travel-adapters.test.js +0 -483
  189. package/__tests__/travel-maps-snapshot.test.js +0 -426
  190. package/__tests__/vault-driver-error.test.js +0 -74
  191. package/__tests__/vault-search-helpers.test.js +0 -104
  192. package/__tests__/vault-search.test.js +0 -423
  193. package/__tests__/vault.test.js +0 -767
  194. package/__tests__/wechat-adapter.test.js +0 -594
  195. package/__tests__/whatsapp-adapter.test.js +0 -138
  196. package/scripts/_make-fixture-all.js +0 -126
  197. package/scripts/_make-fixture-contacts.js +0 -84
  198. package/scripts/evaluate-entity-resolver.js +0 -213
  199. package/scripts/run-native-tests-sandbox.sh +0 -55
  200. package/scripts/smoke-phase-5-5.js +0 -196
  201. package/scripts/smoke-phase-5-7.js +0 -181
  202. package/scripts/smoke-system-data-contacts.js +0 -309
  203. package/scripts/smoke-system-data.js +0 -312
  204. package/vitest.config.js +0 -88
@@ -1,874 +0,0 @@
1
- "use strict";
2
-
3
- import { describe, it, expect } from "vitest";
4
-
5
- const {
6
- AIChatHistoryAdapter,
7
- CookieAuthSession,
8
- HttpClient,
9
- DEFAULT_VENDOR_SPECS,
10
- } = require("../../lib/adapters/ai-chat-history");
11
- const deepseekModule = require("../../lib/adapters/ai-chat-history/vendors/deepseek");
12
- const kimiModule = require("../../lib/adapters/ai-chat-history/vendors/kimi");
13
- const tongyiModule = require("../../lib/adapters/ai-chat-history/vendors/tongyi");
14
- const zhipuModule = require("../../lib/adapters/ai-chat-history/vendors/zhipu");
15
- const hunyuanModule = require("../../lib/adapters/ai-chat-history/vendors/hunyuan");
16
- const qianfanModule = require("../../lib/adapters/ai-chat-history/vendors/qianfan");
17
- const cozeModule = require("../../lib/adapters/ai-chat-history/vendors/coze");
18
- const dreaminaModule = require("../../lib/adapters/ai-chat-history/vendors/dreamina");
19
- const doubaoModule = require("../../lib/adapters/ai-chat-history/vendors/doubao");
20
-
21
- // ─── helpers ─────────────────────────────────────────────────────────────
22
-
23
- function makeResponse({ status = 200, body = {}, headers = {} } = {}) {
24
- return {
25
- status,
26
- ok: status >= 200 && status < 300,
27
- headers: { get: (k) => headers[k.toLowerCase()] || null },
28
- async json() { return body; },
29
- async text() { return JSON.stringify(body); },
30
- };
31
- }
32
-
33
- function makeRoutedFetch(routes) {
34
- const calls = [];
35
- return {
36
- calls,
37
- async fetch(url, init) {
38
- calls.push({ url, init });
39
- for (const [pattern, response] of routes) {
40
- if (typeof pattern === "string" ? url.includes(pattern) : pattern.test(url)) {
41
- if (typeof response === "function") return response(url, init);
42
- return response;
43
- }
44
- }
45
- return makeResponse({ status: 404, body: { error: "no route", url } });
46
- },
47
- };
48
- }
49
-
50
- function makeClock() {
51
- let t = 1_000_000;
52
- return {
53
- now: () => t,
54
- sleep: async (ms) => { t += ms; },
55
- };
56
- }
57
-
58
- function deepseekFixtureClient() {
59
- const fixture = makeRoutedFetch([
60
- ["/user/get_user_info", makeResponse({ body: { code: 0, data: { biz_data: { user_id: "user-1" } } } })],
61
- // Any cursored page returns empty (terminates pagination).
62
- [/fetch_page.*before=/, makeResponse({ body: { data: { biz_data: { chat_sessions: [] } } } })],
63
- // First page (no `before` cursor): newest-first c2, then c1.
64
- ["/chat_session/fetch_page", makeResponse({ body: {
65
- data: { biz_data: { chat_sessions: [
66
- { id: "c2", title: "second chat", model: "deepseek-v3", inserted_at: 200, updated_at: 250 },
67
- { id: "c1", title: "first chat", model: "deepseek-r1", inserted_at: 100, updated_at: 150 },
68
- ] } },
69
- } })],
70
- ["/chat/history_messages", makeResponse({ body: {
71
- data: { biz_data: { chat_messages: [
72
- { id: "m1", role: "USER", content: "hello", inserted_at: 120, parent_id: null },
73
- { id: "m2", role: "ASSISTANT", content: "hi there", inserted_at: 121, parent_id: "m1",
74
- model: "deepseek-r1", thinking_content: "<thinking>...</thinking>", thinking_enabled: true },
75
- ] } },
76
- } })],
77
- ]);
78
- const clk = makeClock();
79
- const httpClient = new HttpClient({
80
- vendor: "deepseek",
81
- rateLimits: { perMinute: 0, minIntervalMs: 0 },
82
- fetch: fixture.fetch, sleep: clk.sleep, now: clk.now,
83
- });
84
- return { httpClient, fixture };
85
- }
86
-
87
- function kimiFixtureClient() {
88
- const fixture = makeRoutedFetch([
89
- ["/api/user", makeResponse({ body: { id: "user-k1", name: "tester" } })],
90
- [/list\?offset=30/, makeResponse({ body: { items: [], total: 1 } })],
91
- [/list\?offset=0/, makeResponse({ body: { items: [
92
- { id: "kc1", name: "kimi convo", created_at: 100, updated_at: 200, message_count: 4 },
93
- ], total: 1 } })],
94
- [/segment\/scroll/, async (_url, init) => {
95
- const body = JSON.parse(init.body);
96
- if (body.last === "0") {
97
- return makeResponse({ body: {
98
- items: [
99
- { id: "km1", role: "user", content: "what is RAG?", created_at: 1000 },
100
- { id: "km2", role: "assistant", content: "RAG stands for...", created_at: 1001, parent_id: "km1" },
101
- ],
102
- has_more: false,
103
- last_id: "km1",
104
- } });
105
- }
106
- return makeResponse({ body: { items: [], has_more: false } });
107
- }],
108
- ]);
109
- const clk = makeClock();
110
- const httpClient = new HttpClient({
111
- vendor: "kimi",
112
- rateLimits: { perMinute: 0, minIntervalMs: 0 },
113
- fetch: fixture.fetch, sleep: clk.sleep, now: clk.now,
114
- });
115
- return { httpClient, fixture };
116
- }
117
-
118
- // ─── DeepSeek ────────────────────────────────────────────────────────────
119
-
120
- describe("DeepSeek vendor — Phase 10.2 wiring", () => {
121
- it("validateCookie returns ok with userId on success", async () => {
122
- const { httpClient } = deepseekFixtureClient();
123
- const session = new CookieAuthSession({ vendor: "deepseek", cookies: [{ name: "userToken", value: "x" }] });
124
- const r = await deepseekModule.SPEC.validateCookie({ httpClient, session, vendor: "deepseek" });
125
- expect(r.ok).toBe(true);
126
- expect(r.userId).toBe("user-1");
127
- });
128
-
129
- it("validateCookie classifies 401 as cookie expired", async () => {
130
- const clk = makeClock();
131
- const fixture = makeRoutedFetch([
132
- ["/get_user_info", makeResponse({ status: 401 })],
133
- ]);
134
- const httpClient = new HttpClient({
135
- vendor: "deepseek",
136
- rateLimits: { perMinute: 0, minIntervalMs: 0 },
137
- fetch: fixture.fetch, sleep: clk.sleep, now: clk.now,
138
- });
139
- const session = new CookieAuthSession({ vendor: "deepseek", cookies: [] });
140
- const r = await deepseekModule.SPEC.validateCookie({ httpClient, session, vendor: "deepseek" });
141
- expect(r.ok).toBe(false);
142
- expect(r.reason).toBe("COOKIE_EXPIRED");
143
- });
144
-
145
- it("listConversations yields RawConversation objects with normalized fields", async () => {
146
- const { httpClient } = deepseekFixtureClient();
147
- const session = new CookieAuthSession({ vendor: "deepseek", cookies: [] });
148
- const out = [];
149
- for await (const c of deepseekModule.SPEC.listConversations({ httpClient, session, vendor: "deepseek" })) {
150
- out.push(c);
151
- }
152
- expect(out.length).toBe(2);
153
- // Newest first (c2) then older (c1).
154
- expect(out[0].originalId).toBe("c2");
155
- expect(out[1].originalId).toBe("c1");
156
- expect(out[1].title).toBe("first chat");
157
- expect(out[1].modelName).toBe("deepseek-r1");
158
- expect(out[1].createdAt).toBe(100_000); // seconds → ms
159
- expect(out[0].vendor).toBe("deepseek");
160
- });
161
-
162
- it("listConversations stops paginating when since watermark satisfied", async () => {
163
- const { httpClient } = deepseekFixtureClient();
164
- const session = new CookieAuthSession({ vendor: "deepseek", cookies: [] });
165
- const out = [];
166
- for await (const c of deepseekModule.SPEC.listConversations(
167
- { httpClient, session, vendor: "deepseek" },
168
- { since: { lastUpdatedAt: 200_000 } },
169
- )) {
170
- out.push(c);
171
- }
172
- // Only c2 (updated_at=250) is newer than since=200; c1 (updated_at=150) is older.
173
- expect(out.length).toBe(1);
174
- expect(out[0].originalId).toBe("c2");
175
- });
176
-
177
- it("listMessages yields user + assistant messages with normalized roles", async () => {
178
- const { httpClient } = deepseekFixtureClient();
179
- const session = new CookieAuthSession({ vendor: "deepseek", cookies: [] });
180
- const out = [];
181
- for await (const m of deepseekModule.SPEC.listMessages({ httpClient, session, vendor: "deepseek" }, "c1")) {
182
- out.push(m);
183
- }
184
- expect(out.length).toBe(2);
185
- expect(out[0].role).toBe("user");
186
- expect(out[0].content.text).toBe("hello");
187
- expect(out[1].role).toBe("assistant");
188
- expect(out[1].modelName).toBe("deepseek-r1");
189
- expect(out[1].extra.thinking).toContain("<thinking>");
190
- expect(out[1].extra.thinkingEnabled).toBe(true);
191
- expect(out[1].parentMessageId).toBe("m1");
192
- });
193
-
194
- it("listMessages tolerates missing biz_data shape", async () => {
195
- const clk = makeClock();
196
- const fixture = makeRoutedFetch([
197
- ["/history_messages", makeResponse({ body: { data: {} } })],
198
- ]);
199
- const httpClient = new HttpClient({
200
- vendor: "deepseek",
201
- rateLimits: { perMinute: 0, minIntervalMs: 0 },
202
- fetch: fixture.fetch, sleep: clk.sleep, now: clk.now,
203
- });
204
- const session = new CookieAuthSession({ vendor: "deepseek", cookies: [] });
205
- const out = [];
206
- for await (const m of deepseekModule.SPEC.listMessages({ httpClient, session, vendor: "deepseek" }, "c1")) {
207
- out.push(m);
208
- }
209
- expect(out).toEqual([]);
210
- });
211
-
212
- it("_toMs handles seconds, ms, and ISO strings", () => {
213
- expect(deepseekModule._internal._toMs(100)).toBe(100_000);
214
- expect(deepseekModule._internal._toMs(1_700_000_000_000)).toBe(1_700_000_000_000);
215
- expect(deepseekModule._internal._toMs("2026-05-20T00:00:00Z")).toBe(Date.parse("2026-05-20T00:00:00Z"));
216
- expect(deepseekModule._internal._toMs(undefined)).toBe(0);
217
- });
218
-
219
- it("_normalizeRole handles uppercase + lowercase", () => {
220
- expect(deepseekModule._internal._normalizeRole("USER")).toBe("user");
221
- expect(deepseekModule._internal._normalizeRole("assistant")).toBe("assistant");
222
- expect(deepseekModule._internal._normalizeRole("SYSTEM")).toBe("system");
223
- expect(deepseekModule._internal._normalizeRole("anything")).toBe("anything");
224
- });
225
- });
226
-
227
- // ─── Kimi ────────────────────────────────────────────────────────────────
228
-
229
- describe("Kimi vendor — Phase 10.2 wiring", () => {
230
- it("validateCookie returns userId on success", async () => {
231
- const { httpClient } = kimiFixtureClient();
232
- const session = new CookieAuthSession({ vendor: "kimi", cookies: [] });
233
- const r = await kimiModule.SPEC.validateCookie({ httpClient, session, vendor: "kimi" });
234
- expect(r.ok).toBe(true);
235
- expect(r.userId).toBe("user-k1");
236
- });
237
-
238
- it("listConversations paginates by offset and respects `total`", async () => {
239
- const { httpClient } = kimiFixtureClient();
240
- const session = new CookieAuthSession({ vendor: "kimi", cookies: [] });
241
- const out = [];
242
- for await (const c of kimiModule.SPEC.listConversations({ httpClient, session, vendor: "kimi" })) {
243
- out.push(c);
244
- }
245
- expect(out.length).toBe(1);
246
- expect(out[0].vendor).toBe("kimi");
247
- expect(out[0].originalId).toBe("kc1");
248
- expect(out[0].title).toBe("kimi convo");
249
- });
250
-
251
- it("listMessages walks cursor + yields chronologically", async () => {
252
- const { httpClient } = kimiFixtureClient();
253
- const session = new CookieAuthSession({ vendor: "kimi", cookies: [] });
254
- const out = [];
255
- for await (const m of kimiModule.SPEC.listMessages({ httpClient, session, vendor: "kimi" }, "kc1")) {
256
- out.push(m);
257
- }
258
- expect(out.length).toBe(2);
259
- expect(out[0].originalId).toBe("km1");
260
- expect(out[0].role).toBe("user");
261
- expect(out[1].originalId).toBe("km2");
262
- expect(out[1].role).toBe("assistant");
263
- expect(out[1].parentMessageId).toBe("km1");
264
- });
265
- });
266
-
267
- // ─── End-to-end via AIChatHistoryAdapter.sync ────────────────────────────
268
-
269
- describe("AIChatHistoryAdapter.sync — wired DeepSeek path E2E", () => {
270
- it("yields conversation + messages via real HttpClient + fixture fetch", async () => {
271
- const clk = makeClock();
272
- const fixture = makeRoutedFetch([
273
- // Cursored page terminates.
274
- [/fetch_page.*before=/, makeResponse({ body: { data: { biz_data: { chat_sessions: [] } } } })],
275
- ["/chat_session/fetch_page", makeResponse({ body: {
276
- data: { biz_data: { chat_sessions: [
277
- { id: "c1", title: "wired test", model: "deepseek-r1", inserted_at: 100, updated_at: 150 },
278
- ] } },
279
- } })],
280
- ["/chat/history_messages", makeResponse({ body: {
281
- data: { biz_data: { chat_messages: [
282
- { id: "m1", role: "USER", content: "hello?", inserted_at: 120 },
283
- { id: "m2", role: "ASSISTANT", content: "hi!", inserted_at: 121, model: "deepseek-r1" },
284
- ] } },
285
- } })],
286
- ]);
287
- const a = new AIChatHistoryAdapter({
288
- fetch: fixture.fetch,
289
- sleep: clk.sleep,
290
- now: clk.now,
291
- });
292
- a.setSession("deepseek", new CookieAuthSession({
293
- vendor: "deepseek",
294
- cookies: [{ name: "userToken", value: "x" }],
295
- }));
296
-
297
- const out = [];
298
- for await (const ev of a.sync({ vendors: ["deepseek"] })) out.push(ev);
299
- expect(out.length).toBe(3); // 1 conv + 2 msgs
300
- expect(out[0].payload.kind).toBe("conversation");
301
- expect(out[0].payload.conversation.title).toBe("wired test");
302
- expect(out[1].payload.kind).toBe("message");
303
- expect(out[1].payload.message.role).toBe("user");
304
- expect(out[2].payload.message.role).toBe("assistant");
305
-
306
- // normalize → events / topics
307
- const batches = out.map((r) => a.normalize(r));
308
- expect(batches[0].topics[0].name).toBe("wired test");
309
- expect(batches[1].events.length).toBe(1);
310
- expect(batches[2].events[0].extra.modelName).toBe("deepseek-r1");
311
- });
312
-
313
- it("emits vendor-cookie-expired sentinel when http layer reports 401", async () => {
314
- const clk = makeClock();
315
- const fixture = makeRoutedFetch([
316
- ["/chat_session/fetch_page", makeResponse({ status: 401 })],
317
- ]);
318
- const a = new AIChatHistoryAdapter({ fetch: fixture.fetch, sleep: clk.sleep, now: clk.now });
319
- a.setSession("deepseek", new CookieAuthSession({ vendor: "deepseek", cookies: [] }));
320
- const out = [];
321
- for await (const ev of a.sync({ vendors: ["deepseek"] })) out.push(ev);
322
- expect(out.length).toBe(1);
323
- expect(out[0].payload.kind).toBe("vendor-cookie-expired");
324
- expect(out[0].payload.vendor).toBe("deepseek");
325
- });
326
-
327
- it("healthCheck reports per-vendor wired result", async () => {
328
- const clk = makeClock();
329
- const fixture = makeRoutedFetch([
330
- ["/get_user_info", makeResponse({ body: { code: 0, data: { biz_data: { user_id: "u" } } } })],
331
- ["/api/user", makeResponse({ body: { id: "k-u" } })],
332
- ]);
333
- const a = new AIChatHistoryAdapter({ fetch: fixture.fetch, sleep: clk.sleep, now: clk.now });
334
- a.setSession("deepseek", new CookieAuthSession({ vendor: "deepseek", cookies: [] }));
335
- a.setSession("kimi", new CookieAuthSession({ vendor: "kimi", cookies: [] }));
336
- const h = await a.healthCheck();
337
- expect(h.perVendor.deepseek.ok).toBe(true);
338
- expect(h.perVendor.deepseek.userId).toBe("u");
339
- expect(h.perVendor.kimi.ok).toBe(true);
340
- expect(h.perVendor.kimi.userId).toBe("k-u");
341
- });
342
- });
343
-
344
- // ─── Tongyi ──────────────────────────────────────────────────────────────
345
-
346
- function tongyiFixtureClient() {
347
- const fixture = makeRoutedFetch([
348
- ["/api/user/info", makeResponse({ body: { success: true, data: { userId: "ali-u1", uid: "ali-u1" } } })],
349
- [/conversation\/list.*pageNum=2/, makeResponse({ body: { data: { list: [] } } })],
350
- ["/dialog/conversation/list", makeResponse({ body: { data: { list: [
351
- { sessionId: "tc1", summary: "通义对话", gmtCreate: 1700000000000, gmtModified: 1700001000000, modelName: "qwen-max", messageCount: 4 },
352
- ] } } })],
353
- ["/dialog/conversation/messages", makeResponse({ body: { data: [
354
- { msgId: "tm1", senderType: "user", content: "你好", createTime: 1700000010000 },
355
- { msgId: "tm2", senderType: "assistant", contents: [{ content: "您好,有什么可以帮您?" }],
356
- createTime: 1700000020000, modelName: "qwen-max" },
357
- ] } })],
358
- ]);
359
- const clk = makeClock();
360
- const httpClient = new HttpClient({
361
- vendor: "tongyi",
362
- rateLimits: { perMinute: 0, minIntervalMs: 0 },
363
- fetch: fixture.fetch, sleep: clk.sleep, now: clk.now,
364
- });
365
- return { httpClient, fixture };
366
- }
367
-
368
- describe("Tongyi vendor — Phase 10.2 wiring", () => {
369
- it("validateCookie returns userId", async () => {
370
- const { httpClient } = tongyiFixtureClient();
371
- const session = new CookieAuthSession({
372
- vendor: "tongyi",
373
- cookies: [{ name: "XSRF-TOKEN", value: "csrf-x" }],
374
- });
375
- const r = await tongyiModule.SPEC.validateCookie({ httpClient, session, vendor: "tongyi" });
376
- expect(r.ok).toBe(true);
377
- expect(r.userId).toBe("ali-u1");
378
- });
379
-
380
- it("listConversations sends X-Csrf-Token header from cookie", async () => {
381
- const { httpClient, fixture } = tongyiFixtureClient();
382
- const session = new CookieAuthSession({
383
- vendor: "tongyi",
384
- cookies: [{ name: "XSRF-TOKEN", value: "csrf-x" }],
385
- });
386
- const out = [];
387
- for await (const c of tongyiModule.SPEC.listConversations({ httpClient, session, vendor: "tongyi" })) {
388
- out.push(c);
389
- }
390
- expect(out.length).toBe(1);
391
- expect(out[0].originalId).toBe("tc1");
392
- // Verify CSRF header injected:
393
- const convCall = fixture.calls.find((c) => c.url.includes("/conversation/list"));
394
- expect(convCall.init.headers["X-Csrf-Token"]).toBe("csrf-x");
395
- });
396
-
397
- it("listMessages joins contents[].content for multi-segment replies", async () => {
398
- const { httpClient } = tongyiFixtureClient();
399
- const session = new CookieAuthSession({ vendor: "tongyi", cookies: [] });
400
- const out = [];
401
- for await (const m of tongyiModule.SPEC.listMessages({ httpClient, session, vendor: "tongyi" }, "tc1")) {
402
- out.push(m);
403
- }
404
- expect(out.length).toBe(2);
405
- expect(out[0].role).toBe("user");
406
- expect(out[1].role).toBe("assistant");
407
- expect(out[1].content.text).toBe("您好,有什么可以帮您?");
408
- expect(out[1].modelName).toBe("qwen-max");
409
- });
410
- });
411
-
412
- // ─── Zhipu ───────────────────────────────────────────────────────────────
413
-
414
- function zhipuFixtureClient() {
415
- const fixture = makeRoutedFetch([
416
- ["/user/info", makeResponse({ body: { status: 0, result: { user_id: "glm-u1" } } })],
417
- [/conversation\/list.*page=2/, makeResponse({ body: { result: { list: [] } } })],
418
- ["/conversation/list", makeResponse({ body: { result: { list: [
419
- { conversation_id: "zc1", title: "GLM-4 测试", create_time: 1700000000, update_time: 1700001000, model: "glm-4" },
420
- ] } } })],
421
- [/conversation\/zc1/, makeResponse({ body: { result: { messages: [
422
- { id: "zm1", role: "user", content: "查一下天气", create_time: 1700000010 },
423
- { id: "zm2", role: "assistant", content: "今天厦门多云", create_time: 1700000020,
424
- tool_calls: [{ name: "web_search", arguments: { query: "厦门天气" } }] },
425
- ] } } })],
426
- ]);
427
- const clk = makeClock();
428
- const httpClient = new HttpClient({
429
- vendor: "zhipu",
430
- rateLimits: { perMinute: 0, minIntervalMs: 0 },
431
- fetch: fixture.fetch, sleep: clk.sleep, now: clk.now,
432
- });
433
- return { httpClient, fixture };
434
- }
435
-
436
- describe("Zhipu vendor — Phase 10.2 wiring", () => {
437
- it("validateCookie returns userId", async () => {
438
- const { httpClient } = zhipuFixtureClient();
439
- const session = new CookieAuthSession({
440
- vendor: "zhipu",
441
- cookies: [{ name: "chatglm_token", value: "tok-x" }],
442
- });
443
- const r = await zhipuModule.SPEC.validateCookie({ httpClient, session, vendor: "zhipu" });
444
- expect(r.ok).toBe(true);
445
- expect(r.userId).toBe("glm-u1");
446
- });
447
-
448
- it("listConversations sends Bearer token from chatglm_token cookie", async () => {
449
- const { httpClient, fixture } = zhipuFixtureClient();
450
- const session = new CookieAuthSession({
451
- vendor: "zhipu",
452
- cookies: [{ name: "chatglm_token", value: "tok-x" }],
453
- });
454
- const out = [];
455
- for await (const c of zhipuModule.SPEC.listConversations({ httpClient, session, vendor: "zhipu" })) {
456
- out.push(c);
457
- }
458
- expect(out.length).toBe(1);
459
- expect(out[0].originalId).toBe("zc1");
460
- expect(out[0].modelName).toBe("glm-4");
461
- const convCall = fixture.calls.find((c) => c.url.includes("/conversation/list"));
462
- expect(convCall.init.headers.Authorization).toBe("Bearer tok-x");
463
- });
464
-
465
- it("listMessages preserves tool_calls in extra", async () => {
466
- const { httpClient } = zhipuFixtureClient();
467
- const session = new CookieAuthSession({ vendor: "zhipu", cookies: [] });
468
- const out = [];
469
- for await (const m of zhipuModule.SPEC.listMessages({ httpClient, session, vendor: "zhipu" }, "zc1")) {
470
- out.push(m);
471
- }
472
- expect(out.length).toBe(2);
473
- expect(out[0].role).toBe("user");
474
- expect(out[1].role).toBe("assistant");
475
- expect(out[1].content.text).toBe("今天厦门多云");
476
- expect(out[1].extra.toolCalls).toEqual([{ name: "web_search", arguments: { query: "厦门天气" } }]);
477
- });
478
- });
479
-
480
- // ─── Hunyuan ─────────────────────────────────────────────────────────────
481
-
482
- function hunyuanFixtureClient() {
483
- const fixture = makeRoutedFetch([
484
- ["/api/user/info", makeResponse({ body: { ret: 0, data: { userId: "hy-u1" } } })],
485
- ["/api/user/conv/list", makeResponse({ body: { data: { list: [
486
- { convId: "hyc1", title: "腾讯元宝对话", createTime: 1700000000000, updateTime: 1700001000000 },
487
- ] } } })],
488
- [/api\/user\/conv\/hyc1\/message\/list/, makeResponse({ body: { data: { messages: [
489
- { msgId: "hym1", speaker: "user", content: "搜下今日新闻", createTime: 1700000010000 },
490
- { msgId: "hym2", speaker: "bot", content: "今日要闻三则...", createTime: 1700000020000,
491
- linkedArticles: [{ title: "央视新闻", url: "https://example.com/a1" }] },
492
- ] } } })],
493
- ]);
494
- const clk = makeClock();
495
- const httpClient = new HttpClient({
496
- vendor: "hunyuan",
497
- rateLimits: { perMinute: 0, minIntervalMs: 0 },
498
- fetch: fixture.fetch, sleep: clk.sleep, now: clk.now,
499
- });
500
- return { httpClient, fixture };
501
- }
502
-
503
- describe("Hunyuan vendor — Phase 10.2 wiring", () => {
504
- it("validateCookie returns userId", async () => {
505
- const { httpClient } = hunyuanFixtureClient();
506
- const session = new CookieAuthSession({ vendor: "hunyuan", cookies: [{ name: "hy_token", value: "t" }] });
507
- const r = await hunyuanModule.SPEC.validateCookie({ httpClient, session, vendor: "hunyuan" });
508
- expect(r.ok).toBe(true);
509
- expect(r.userId).toBe("hy-u1");
510
- });
511
-
512
- it("listConversations yields normalized RawConversation", async () => {
513
- const { httpClient } = hunyuanFixtureClient();
514
- const session = new CookieAuthSession({ vendor: "hunyuan", cookies: [] });
515
- const out = [];
516
- for await (const c of hunyuanModule.SPEC.listConversations({ httpClient, session, vendor: "hunyuan" })) {
517
- out.push(c);
518
- }
519
- expect(out.length).toBe(1);
520
- expect(out[0].originalId).toBe("hyc1");
521
- expect(out[0].title).toBe("腾讯元宝对话");
522
- });
523
-
524
- it("listMessages preserves linkedArticles as attachments + extra", async () => {
525
- const { httpClient } = hunyuanFixtureClient();
526
- const session = new CookieAuthSession({ vendor: "hunyuan", cookies: [] });
527
- const out = [];
528
- for await (const m of hunyuanModule.SPEC.listMessages({ httpClient, session, vendor: "hunyuan" }, "hyc1")) {
529
- out.push(m);
530
- }
531
- expect(out.length).toBe(2);
532
- expect(out[1].role).toBe("assistant");
533
- expect(out[1].extra.linkedArticles).toHaveLength(1);
534
- expect(out[1].content.attachments[0].filename).toBe("央视新闻");
535
- });
536
- });
537
-
538
- // ─── Qianfan ─────────────────────────────────────────────────────────────
539
-
540
- function qianfanFixtureClient() {
541
- const fixture = makeRoutedFetch([
542
- ["/aichat/user/info", makeResponse({ body: { code: 0, data: { uk: "qf-u1" } } })],
543
- ["/aichat/conversation/list", makeResponse({ body: { data: { list: [
544
- { sessionId: "qfc1", sessionName: "文心一言对话", createTime: 1700000000, updateTime: 1700001000 },
545
- ] } } })],
546
- ["/aichat/conversation/getMessages", makeResponse({ body: { data: { messages: [
547
- { messageId: "qm1", role: "user", content: "Python 列表去重", createTime: 1700000010 },
548
- { messageId: "qm2", role: "assistant", content: "可以用 set() 或字典推导...", createTime: 1700000020,
549
- references: [{ title: "Python doc", url: "https://docs.python.org/" }] },
550
- ] } } })],
551
- ]);
552
- const clk = makeClock();
553
- const httpClient = new HttpClient({
554
- vendor: "qianfan",
555
- rateLimits: { perMinute: 0, minIntervalMs: 0 },
556
- fetch: fixture.fetch, sleep: clk.sleep, now: clk.now,
557
- });
558
- return { httpClient, fixture };
559
- }
560
-
561
- describe("Qianfan vendor — Phase 10.2 wiring", () => {
562
- it("validateCookie returns userId", async () => {
563
- const { httpClient } = qianfanFixtureClient();
564
- const session = new CookieAuthSession({ vendor: "qianfan", cookies: [{ name: "BAIDUID", value: "b" }] });
565
- const r = await qianfanModule.SPEC.validateCookie({ httpClient, session, vendor: "qianfan" });
566
- expect(r.ok).toBe(true);
567
- expect(r.userId).toBe("qf-u1");
568
- });
569
-
570
- it("listConversations + listMessages cross-walk", async () => {
571
- const { httpClient } = qianfanFixtureClient();
572
- const session = new CookieAuthSession({ vendor: "qianfan", cookies: [] });
573
- const convs = [];
574
- for await (const c of qianfanModule.SPEC.listConversations({ httpClient, session, vendor: "qianfan" })) {
575
- convs.push(c);
576
- }
577
- expect(convs.length).toBe(1);
578
- const msgs = [];
579
- for await (const m of qianfanModule.SPEC.listMessages({ httpClient, session, vendor: "qianfan" }, convs[0].originalId)) {
580
- msgs.push(m);
581
- }
582
- expect(msgs.length).toBe(2);
583
- expect(msgs[1].extra.references).toHaveLength(1);
584
- });
585
- });
586
-
587
- // ─── Coze ────────────────────────────────────────────────────────────────
588
-
589
- function cozeFixtureClient() {
590
- const fixture = makeRoutedFetch([
591
- ["/api/user/info", makeResponse({ body: { code: 0, data: { user_id: "cz-u1" } } })],
592
- [/conversation\/list.*cursor=last/, makeResponse({ body: { data: { list: [], next_cursor: "" } } })],
593
- ["/api/conversation/list", makeResponse({ body: { data: { list: [
594
- { conversation_id: "cz-c1", title: "agent task", created_at: 1700000000, last_updated_time: 1700001000,
595
- bot_id: "bot-1" },
596
- ], next_cursor: "last" } } })],
597
- [/conversation\/cz-c1\/message/, makeResponse({ body: { data: { message_list: [
598
- { message_id: "czm1", role: "user", content: "搜下 SF 餐厅", created_at: 1700000010 },
599
- { message_id: "czm2", role: "assistant", content: "找到 3 家...", created_at: 1700000020,
600
- tool_calls: [{ name: "places_search", arguments: { city: "SF" } }],
601
- workflow_run_id: "wf-1" },
602
- ] } } })],
603
- ]);
604
- const clk = makeClock();
605
- const httpClient = new HttpClient({
606
- vendor: "coze",
607
- rateLimits: { perMinute: 0, minIntervalMs: 0 },
608
- fetch: fixture.fetch, sleep: clk.sleep, now: clk.now,
609
- });
610
- return { httpClient, fixture };
611
- }
612
-
613
- describe("Coze vendor — Phase 10.2 wiring", () => {
614
- it("validateCookie returns userId", async () => {
615
- const { httpClient } = cozeFixtureClient();
616
- const session = new CookieAuthSession({ vendor: "coze", cookies: [{ name: "s_v_web_id", value: "v" }] });
617
- const r = await cozeModule.SPEC.validateCookie({ httpClient, session, vendor: "coze" });
618
- expect(r.ok).toBe(true);
619
- expect(r.userId).toBe("cz-u1");
620
- });
621
-
622
- it("listConversations carries bot_id in extra", async () => {
623
- const { httpClient } = cozeFixtureClient();
624
- const session = new CookieAuthSession({ vendor: "coze", cookies: [] });
625
- const out = [];
626
- for await (const c of cozeModule.SPEC.listConversations({ httpClient, session, vendor: "coze" })) {
627
- out.push(c);
628
- }
629
- expect(out.length).toBe(1);
630
- expect(out[0].extra.botId).toBe("bot-1");
631
- });
632
-
633
- it("listMessages preserves toolCalls + workflow_run_id", async () => {
634
- const { httpClient } = cozeFixtureClient();
635
- const session = new CookieAuthSession({ vendor: "coze", cookies: [] });
636
- const out = [];
637
- for await (const m of cozeModule.SPEC.listMessages({ httpClient, session, vendor: "coze" }, "cz-c1")) {
638
- out.push(m);
639
- }
640
- expect(out.length).toBe(2);
641
- expect(out[1].extra.toolCalls).toHaveLength(1);
642
- expect(out[1].extra.workflowRunId).toBe("wf-1");
643
- });
644
- });
645
-
646
- // ─── Dreamina ────────────────────────────────────────────────────────────
647
-
648
- function dreaminaFixtureClient() {
649
- const fixture = makeRoutedFetch([
650
- ["/api/user/info", makeResponse({ body: { code: 0, data: { user_id: "dm-u1" } } })],
651
- ["/api/workspace/list", makeResponse({ body: { data: { workspaces: [
652
- { workspace_id: "ws-1", name: "海报设计", create_time: 1700000000, update_time: 1700001000 },
653
- ] } } })],
654
- [/workspace\/ws-1\/items/, makeResponse({ body: { data: { items: [
655
- {
656
- id: "item-1",
657
- prompt: "一只赛博朋克猫头鹰",
658
- model: "jimeng-2.0",
659
- create_time: 1700000100,
660
- complete_time: 1700000130,
661
- outputs: [
662
- { url: "https://cdn.example.com/cat1.png" },
663
- { url: "https://cdn.example.com/cat2.png" },
664
- ],
665
- status: "succeeded",
666
- },
667
- ] } } })],
668
- ]);
669
- const clk = makeClock();
670
- const httpClient = new HttpClient({
671
- vendor: "dreamina",
672
- rateLimits: { perMinute: 0, minIntervalMs: 0 },
673
- fetch: fixture.fetch, sleep: clk.sleep, now: clk.now,
674
- });
675
- return { httpClient, fixture };
676
- }
677
-
678
- describe("Dreamina vendor — Phase 10.2 wiring", () => {
679
- it("validateCookie returns userId", async () => {
680
- const { httpClient } = dreaminaFixtureClient();
681
- const session = new CookieAuthSession({ vendor: "dreamina", cookies: [] });
682
- const r = await dreaminaModule.SPEC.validateCookie({ httpClient, session, vendor: "dreamina" });
683
- expect(r.ok).toBe(true);
684
- expect(r.userId).toBe("dm-u1");
685
- });
686
-
687
- it("workspaces map to RawConversation with kind=creative-workspace", async () => {
688
- const { httpClient } = dreaminaFixtureClient();
689
- const session = new CookieAuthSession({ vendor: "dreamina", cookies: [] });
690
- const out = [];
691
- for await (const c of dreaminaModule.SPEC.listConversations({ httpClient, session, vendor: "dreamina" })) {
692
- out.push(c);
693
- }
694
- expect(out.length).toBe(1);
695
- expect(out[0].title).toBe("海报设计");
696
- expect(out[0].extra.kind).toBe("creative-workspace");
697
- });
698
-
699
- it("items split into user-prompt + assistant-output messages with generatedImages", async () => {
700
- const { httpClient } = dreaminaFixtureClient();
701
- const session = new CookieAuthSession({ vendor: "dreamina", cookies: [] });
702
- const out = [];
703
- for await (const m of dreaminaModule.SPEC.listMessages({ httpClient, session, vendor: "dreamina" }, "ws-1")) {
704
- out.push(m);
705
- }
706
- expect(out.length).toBe(2);
707
- expect(out[0].role).toBe("user");
708
- expect(out[0].content.text).toBe("一只赛博朋克猫头鹰");
709
- expect(out[1].role).toBe("assistant");
710
- expect(out[1].content.generatedImages).toHaveLength(2);
711
- expect(out[1].content.generatedImages[0].url).toMatch(/cat1\.png/);
712
- expect(out[1].parentMessageId).toBe("item-1:prompt");
713
- });
714
- });
715
-
716
- // ─── Doubao 豆包 ────────────────────────────────────────────────────────
717
-
718
- function doubaoFixtureClient() {
719
- const fixture = makeRoutedFetch([
720
- [
721
- "/samantha/user/info",
722
- makeResponse({ body: { code: 0, data: { user_id: "db-u1" } } }),
723
- ],
724
- [
725
- "/samantha/conversation/list",
726
- makeResponse({
727
- body: {
728
- data: {
729
- conversation_list: [
730
- {
731
- conversation_id: "conv-1",
732
- name: "聊聊 Rust",
733
- bot_id: "bot-default",
734
- bot_name: "豆包",
735
- create_time: 1700000000,
736
- last_message_time: 1700001000,
737
- message_count: 4,
738
- },
739
- ],
740
- has_more: false,
741
- cursor: "",
742
- },
743
- },
744
- }),
745
- ],
746
- [
747
- /samantha\/conversation\/conv-1\/message\/list/,
748
- makeResponse({
749
- body: {
750
- data: {
751
- message_list: [
752
- {
753
- id: "m-2",
754
- sender_type: 2,
755
- content: "Rust 的核心是所有权…",
756
- create_time: 1700000060,
757
- bot_id: "bot-default",
758
- },
759
- {
760
- id: "m-1",
761
- sender_type: 1,
762
- content: "讲讲 Rust 的特点",
763
- create_time: 1700000050,
764
- },
765
- ],
766
- has_more: false,
767
- cursor: "",
768
- },
769
- },
770
- }),
771
- ],
772
- ]);
773
- const clk = makeClock();
774
- const httpClient = new HttpClient({
775
- vendor: "doubao",
776
- rateLimits: { perMinute: 0, minIntervalMs: 0 },
777
- fetch: fixture.fetch,
778
- sleep: clk.sleep,
779
- now: clk.now,
780
- });
781
- return { httpClient, fixture };
782
- }
783
-
784
- describe("Doubao vendor — Phase 10.2(+) v0.1 scaffold", () => {
785
- it("validateCookie returns userId from /samantha/user/info", async () => {
786
- const { httpClient } = doubaoFixtureClient();
787
- const session = new CookieAuthSession({ vendor: "doubao", cookies: [] });
788
- const r = await doubaoModule.SPEC.validateCookie({
789
- httpClient,
790
- session,
791
- vendor: "doubao",
792
- });
793
- expect(r.ok).toBe(true);
794
- expect(r.userId).toBe("db-u1");
795
- });
796
-
797
- it("listConversations yields RawConversation with bot_name as modelName", async () => {
798
- const { httpClient } = doubaoFixtureClient();
799
- const session = new CookieAuthSession({ vendor: "doubao", cookies: [] });
800
- const out = [];
801
- for await (const c of doubaoModule.SPEC.listConversations({
802
- httpClient,
803
- session,
804
- vendor: "doubao",
805
- })) {
806
- out.push(c);
807
- }
808
- expect(out.length).toBe(1);
809
- expect(out[0].originalId).toBe("conv-1");
810
- expect(out[0].title).toBe("聊聊 Rust");
811
- expect(out[0].modelName).toBe("豆包");
812
- expect(out[0].extra.botId).toBe("bot-default");
813
- });
814
-
815
- it("listMessages sorts messages chronologically + maps numeric sender_type", async () => {
816
- const { httpClient } = doubaoFixtureClient();
817
- const session = new CookieAuthSession({ vendor: "doubao", cookies: [] });
818
- const out = [];
819
- for await (const m of doubaoModule.SPEC.listMessages(
820
- { httpClient, session, vendor: "doubao" },
821
- "conv-1",
822
- )) {
823
- out.push(m);
824
- }
825
- expect(out.length).toBe(2);
826
- // Re-sorted to chronological even though API returned reverse.
827
- expect(out[0].originalId).toBe("m-1");
828
- expect(out[0].role).toBe("user");
829
- expect(out[0].content.text).toBe("讲讲 Rust 的特点");
830
- expect(out[1].originalId).toBe("m-2");
831
- expect(out[1].role).toBe("assistant");
832
- });
833
-
834
- it("_normalizeRole handles numeric + string + uppercase sender_type", () => {
835
- const { _normalizeRole } = doubaoModule._internal;
836
- expect(_normalizeRole(1)).toBe("user");
837
- expect(_normalizeRole("2")).toBe("assistant");
838
- expect(_normalizeRole("SYSTEM")).toBe("system");
839
- expect(_normalizeRole("assistant")).toBe("assistant");
840
- });
841
-
842
- it("_extractConvList absorbs alternate response field names", () => {
843
- const { _extractConvList, _extractMsgList } = doubaoModule._internal;
844
- expect(_extractConvList({ data: { conversations: [{ id: 1 }] } })).toEqual([
845
- { id: 1 },
846
- ]);
847
- expect(_extractConvList({ data: { list: [{ id: 2 }] } })).toEqual([{ id: 2 }]);
848
- expect(_extractMsgList({ data: { messages: [{ id: "x" }] } })).toEqual([
849
- { id: "x" },
850
- ]);
851
- expect(_extractMsgList({})).toEqual([]);
852
- });
853
- });
854
-
855
- // ─── Spec contract still valid after wiring ──────────────────────────────
856
-
857
- describe("vendor spec post-wire smoke (9 vendors total — 8 live + doubao scaffold)", () => {
858
- it.each([
859
- "deepseek",
860
- "kimi",
861
- "tongyi",
862
- "zhipu",
863
- "hunyuan",
864
- "qianfan",
865
- "coze",
866
- "dreamina",
867
- "doubao",
868
- ])("%s spec still has correct shape", (v) => {
869
- expect(DEFAULT_VENDOR_SPECS[v].name).toBe(v);
870
- expect(typeof DEFAULT_VENDOR_SPECS[v].listConversations).toBe("function");
871
- expect(typeof DEFAULT_VENDOR_SPECS[v].listMessages).toBe("function");
872
- expect(typeof DEFAULT_VENDOR_SPECS[v].validateCookie).toBe("function");
873
- });
874
- });