specific-ai-cli 0.0.0-stage → 0.1.1

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 (277) hide show
  1. package/LICENSE +21 -0
  2. package/README.en.md +177 -0
  3. package/README.ja.md +177 -0
  4. package/README.ko.md +177 -0
  5. package/README.md +174 -2
  6. package/README.zh-TW.md +177 -0
  7. package/assets/banner.txt +3 -0
  8. package/dist/cli/argv.js +98 -0
  9. package/dist/cli/commands/auth.js +11 -0
  10. package/dist/cli/commands/config.js +23 -0
  11. package/dist/cli/commands/doctor.js +134 -0
  12. package/dist/cli/commands/platforms.js +24 -0
  13. package/dist/cli/commands/version.js +4 -0
  14. package/dist/cli/confirm.js +22 -0
  15. package/dist/cli/dispatch.js +440 -0
  16. package/dist/cli/help.js +223 -0
  17. package/dist/cli/hints.js +60 -0
  18. package/dist/cli/main.js +18 -0
  19. package/dist/cli/output.js +66 -0
  20. package/dist/core/auth-handlers.js +41 -0
  21. package/dist/core/auth-store.js +119 -0
  22. package/dist/core/capabilities.js +163 -0
  23. package/dist/core/config.js +121 -0
  24. package/dist/core/cookies.js +164 -0
  25. package/dist/core/errors.js +37 -0
  26. package/dist/core/files.js +89 -0
  27. package/dist/core/fsutil.js +52 -0
  28. package/dist/core/hash.js +4 -0
  29. package/dist/core/http.js +331 -0
  30. package/dist/core/image.js +280 -0
  31. package/dist/core/log.js +40 -0
  32. package/dist/core/login.js +191 -0
  33. package/dist/core/mp4.js +130 -0
  34. package/dist/core/normalize.js +207 -0
  35. package/dist/core/options.js +110 -0
  36. package/dist/core/paths.js +38 -0
  37. package/dist/core/pb.js +59 -0
  38. package/dist/core/py.js +181 -0
  39. package/dist/core/rand.js +131 -0
  40. package/dist/core/registry.js +129 -0
  41. package/dist/core/schemas.js +41 -0
  42. package/dist/core/stream.js +104 -0
  43. package/dist/core/toolkit.js +35 -0
  44. package/dist/core/vm.js +73 -0
  45. package/dist/core/vocab.js +157 -0
  46. package/dist/platforms/_shared/impaas.js +410 -0
  47. package/dist/platforms/bilibili/index.js +216 -0
  48. package/dist/platforms/bilibili/web/api.js +806 -0
  49. package/dist/platforms/bilibili/web/client.js +311 -0
  50. package/dist/platforms/bilibili/web/commands.js +783 -0
  51. package/dist/platforms/bilibili/web/ddddocr.js +342 -0
  52. package/dist/platforms/bilibili/web/gaia.js +130 -0
  53. package/dist/platforms/bilibili/web/geetest-manual.js +154 -0
  54. package/dist/platforms/bilibili/web/geetest-vision.js +232 -0
  55. package/dist/platforms/bilibili/web/geetest.js +450 -0
  56. package/dist/platforms/bilibili/web/normalize.js +234 -0
  57. package/dist/platforms/bilibili/web/profile.js +135 -0
  58. package/dist/platforms/bilibili/web/resolve.js +112 -0
  59. package/dist/platforms/bilibili/web/sign.js +223 -0
  60. package/dist/platforms/bilibili/web/upos.js +102 -0
  61. package/dist/platforms/douyin/index.js +142 -0
  62. package/dist/platforms/douyin/web/api.js +863 -0
  63. package/dist/platforms/douyin/web/client.js +413 -0
  64. package/dist/platforms/douyin/web/commands.js +712 -0
  65. package/dist/platforms/douyin/web/creator.js +601 -0
  66. package/dist/platforms/douyin/web/crypto.js +247 -0
  67. package/dist/platforms/douyin/web/dtrait.js +190 -0
  68. package/dist/platforms/douyin/web/im.js +502 -0
  69. package/dist/platforms/douyin/web/image.js +5 -0
  70. package/dist/platforms/douyin/web/live.js +225 -0
  71. package/dist/platforms/douyin/web/mssdk.js +148 -0
  72. package/dist/platforms/douyin/web/normalize.js +326 -0
  73. package/dist/platforms/douyin/web/passport.js +1247 -0
  74. package/dist/platforms/douyin/web/profile.js +221 -0
  75. package/dist/platforms/douyin/web/proto.js +26 -0
  76. package/dist/platforms/douyin/web/resolve.js +88 -0
  77. package/dist/platforms/douyin/web/sign.js +436 -0
  78. package/dist/platforms/douyin/web/tos.js +78 -0
  79. package/dist/platforms/index.js +17 -0
  80. package/dist/platforms/jd/index.js +67 -0
  81. package/dist/platforms/jd/web/aks.js +115 -0
  82. package/dist/platforms/jd/web/api.js +549 -0
  83. package/dist/platforms/jd/web/chat.js +132 -0
  84. package/dist/platforms/jd/web/client.js +470 -0
  85. package/dist/platforms/jd/web/commands.js +557 -0
  86. package/dist/platforms/jd/web/jcap/helper.js +90 -0
  87. package/dist/platforms/jd/web/jcap/host.js +107 -0
  88. package/dist/platforms/jd/web/jcap/lsd.js +300 -0
  89. package/dist/platforms/jd/web/jcap/solver.js +995 -0
  90. package/dist/platforms/jd/web/jcap.js +150 -0
  91. package/dist/platforms/jd/web/js.js +420 -0
  92. package/dist/platforms/jd/web/login.js +775 -0
  93. package/dist/platforms/jd/web/normalize.js +297 -0
  94. package/dist/platforms/jd/web/profile.js +256 -0
  95. package/dist/platforms/jd/web/util.js +175 -0
  96. package/dist/platforms/jd/web/webm.js +133 -0
  97. package/dist/platforms/kuaishou/index.js +98 -0
  98. package/dist/platforms/kuaishou/web/api.js +694 -0
  99. package/dist/platforms/kuaishou/web/captcha-crypto.js +134 -0
  100. package/dist/platforms/kuaishou/web/captcha-fp.js +180 -0
  101. package/dist/platforms/kuaishou/web/captcha.js +273 -0
  102. package/dist/platforms/kuaishou/web/client.js +487 -0
  103. package/dist/platforms/kuaishou/web/commands.js +863 -0
  104. package/dist/platforms/kuaishou/web/gap.js +144 -0
  105. package/dist/platforms/kuaishou/web/gdfp.js +376 -0
  106. package/dist/platforms/kuaishou/web/gql.js +11 -0
  107. package/dist/platforms/kuaishou/web/live.js +125 -0
  108. package/dist/platforms/kuaishou/web/normalize.js +241 -0
  109. package/dist/platforms/kuaishou/web/oracle.js +329 -0
  110. package/dist/platforms/kuaishou/web/profile.js +259 -0
  111. package/dist/platforms/kuaishou/web/resolve.js +84 -0
  112. package/dist/platforms/kuaishou/web/session.js +592 -0
  113. package/dist/platforms/kuaishou/web/sign.js +568 -0
  114. package/dist/platforms/taobao/index.js +56 -0
  115. package/dist/platforms/taobao/web/api.js +96 -0
  116. package/dist/platforms/taobao/web/client.js +102 -0
  117. package/dist/platforms/taobao/web/commands.js +172 -0
  118. package/dist/platforms/taobao/web/im.js +68 -0
  119. package/dist/platforms/taobao/web/normalize.js +103 -0
  120. package/dist/platforms/taobao/web/profile.js +85 -0
  121. package/dist/platforms/taobao/web/resolve.js +51 -0
  122. package/dist/platforms/taobao/web/sign.js +35 -0
  123. package/dist/platforms/tiktok/index.js +120 -0
  124. package/dist/platforms/tiktok/web/api.js +1234 -0
  125. package/dist/platforms/tiktok/web/client.js +362 -0
  126. package/dist/platforms/tiktok/web/commands.js +821 -0
  127. package/dist/platforms/tiktok/web/im.js +133 -0
  128. package/dist/platforms/tiktok/web/jsrun.js +126 -0
  129. package/dist/platforms/tiktok/web/normalize.js +286 -0
  130. package/dist/platforms/tiktok/web/profile.js +169 -0
  131. package/dist/platforms/tiktok/web/resolve.js +156 -0
  132. package/dist/platforms/tiktok/web/sign.js +585 -0
  133. package/dist/platforms/tiktok/web/upload.js +805 -0
  134. package/dist/platforms/tiktok/web/wire.js +490 -0
  135. package/dist/platforms/weibo/index.js +91 -0
  136. package/dist/platforms/weibo/web/api.js +206 -0
  137. package/dist/platforms/weibo/web/client.js +155 -0
  138. package/dist/platforms/weibo/web/commands.js +202 -0
  139. package/dist/platforms/weibo/web/normalize.js +137 -0
  140. package/dist/platforms/weibo/web/profile.js +246 -0
  141. package/dist/platforms/weibo/web/resolve.js +60 -0
  142. package/dist/platforms/weibo/web/sign.js +85 -0
  143. package/dist/platforms/x/index.js +107 -0
  144. package/dist/platforms/x/web/api.js +443 -0
  145. package/dist/platforms/x/web/article.js +212 -0
  146. package/dist/platforms/x/web/client.js +202 -0
  147. package/dist/platforms/x/web/commands.js +363 -0
  148. package/dist/platforms/x/web/graphql.js +108 -0
  149. package/dist/platforms/x/web/normalize.js +235 -0
  150. package/dist/platforms/x/web/profile.js +99 -0
  151. package/dist/platforms/x/web/resolve.js +44 -0
  152. package/dist/platforms/x/web/transaction.js +171 -0
  153. package/dist/platforms/xhs/index.js +101 -0
  154. package/dist/platforms/xhs/web/api.js +278 -0
  155. package/dist/platforms/xhs/web/client.js +540 -0
  156. package/dist/platforms/xhs/web/commands.js +1046 -0
  157. package/dist/platforms/xhs/web/creator-api.js +609 -0
  158. package/dist/platforms/xhs/web/creator.js +203 -0
  159. package/dist/platforms/xhs/web/js.js +194 -0
  160. package/dist/platforms/xhs/web/login.js +230 -0
  161. package/dist/platforms/xhs/web/normalize.js +166 -0
  162. package/dist/platforms/xhs/web/profile.js +127 -0
  163. package/dist/platforms/xhs/web/push.js +361 -0
  164. package/dist/platforms/xhs/web/resolve.js +69 -0
  165. package/dist/platforms/xhs/web/state.js +368 -0
  166. package/dist/platforms/xianyu/index.js +59 -0
  167. package/dist/platforms/xianyu/web/api.js +312 -0
  168. package/dist/platforms/xianyu/web/client.js +134 -0
  169. package/dist/platforms/xianyu/web/commands.js +305 -0
  170. package/dist/platforms/xianyu/web/im.js +73 -0
  171. package/dist/platforms/xianyu/web/normalize.js +123 -0
  172. package/dist/platforms/xianyu/web/profile.js +146 -0
  173. package/dist/platforms/xianyu/web/resolve.js +48 -0
  174. package/dist/platforms/xianyu/web/sign.js +79 -0
  175. package/package.json +77 -4
  176. package/static/douyin/Live.proto +194 -0
  177. package/static/douyin/Request.proto +89 -0
  178. package/static/douyin/Response.proto +46 -0
  179. package/static/douyin/acrawler_runtime/ac_vm.js +2 -0
  180. package/static/douyin/acrawler_runtime/browser_window_shape.json +1 -0
  181. package/static/douyin/acrawler_runtime/canvas_actual_exact.json +1 -0
  182. package/static/douyin/acrawler_runtime/run_ac_node.js +1005 -0
  183. package/static/douyin/acrawler_runtime/runner_window_keys_baseline.txt +240 -0
  184. package/static/douyin/challenge_profile.json +801 -0
  185. package/static/douyin/challenge_template_runner.js +217 -0
  186. package/static/douyin/dtrait_profile.json +66 -0
  187. package/static/douyin/mstoken_common_profile.json +1 -0
  188. package/static/douyin/mstoken_profile.json +214 -0
  189. package/static/jd/h5st5_env.js +750 -0
  190. package/static/jd/h5st5_lib.js +5 -0
  191. package/static/jd/h5st5_server.js +49 -0
  192. package/static/jd/jcap/env/env_core.js +512 -0
  193. package/static/jd/jcap/env/run.js +1307 -0
  194. package/static/jd/jcap/run/jcap_ujb96b.js +39 -0
  195. package/static/jd/package.json +4 -0
  196. package/static/jd/pc_tk_lib.js +1 -0
  197. package/static/jd/pc_tk_server.js +63 -0
  198. package/static/jd/summer_cryptico_runner.js +50 -0
  199. package/static/jd/webm/env/run.js +453 -0
  200. package/static/jd/webm/run/jdwebm-riskhandle.js +49 -0
  201. package/static/kuaishou/bundles/weapon/kwf-0.0.2.2cee19b4b7dec496.js +1 -0
  202. package/static/kuaishou/bundles/weapon/kws-0-0.0.1-obfuscated.4b7f3de1ab0ddcc2.js +1 -0
  203. package/static/kuaishou/bundles/weapon/kws-1-0.0.1-obfuscated.346ebdb1c78df316.js +1 -0
  204. package/static/kuaishou/bundles/weapon/kws-10-0.0.1-obfuscated.a33db41897b983af.js +1 -0
  205. package/static/kuaishou/bundles/weapon/kws-11-0.0.1-obfuscated.5e0a90af726d8a7e.js +1 -0
  206. package/static/kuaishou/bundles/weapon/kws-12-0.0.1-obfuscated.20ea29345706ec8c.js +1 -0
  207. package/static/kuaishou/bundles/weapon/kws-13-0.0.1-obfuscated.6b74e9640ff18648.js +1 -0
  208. package/static/kuaishou/bundles/weapon/kws-14-0.0.1-obfuscated.551e4429d156bf66.js +1 -0
  209. package/static/kuaishou/bundles/weapon/kws-15-0.0.1-obfuscated.8625b087aaba4a60.js +1 -0
  210. package/static/kuaishou/bundles/weapon/kws-16-0.0.1-obfuscated.d5ffa4020f3be99a.js +1 -0
  211. package/static/kuaishou/bundles/weapon/kws-17-0.0.1-obfuscated.6d13e19b22f50a80.js +1 -0
  212. package/static/kuaishou/bundles/weapon/kws-18-0.0.1-obfuscated.6d31405044166289.js +1 -0
  213. package/static/kuaishou/bundles/weapon/kws-19-0.0.1-obfuscated.a9a8d925942f19e4.js +1 -0
  214. package/static/kuaishou/bundles/weapon/kws-2-0.0.1-obfuscated.b849a136ae4a6b3e.js +1 -0
  215. package/static/kuaishou/bundles/weapon/kws-3-0.0.1-obfuscated.f9e77ebf6186e2ac.js +1 -0
  216. package/static/kuaishou/bundles/weapon/kws-4-0.0.1-obfuscated.2c3c155aa52ceb0e.js +1 -0
  217. package/static/kuaishou/bundles/weapon/kws-5-0.0.1-obfuscated.4e553d17691b3c5a.js +1 -0
  218. package/static/kuaishou/bundles/weapon/kws-6-0.0.1-obfuscated.f73ddd3ff13e1217.js +1 -0
  219. package/static/kuaishou/bundles/weapon/kws-7-0.0.1-obfuscated.1628b8729beaab7e.js +1 -0
  220. package/static/kuaishou/bundles/weapon/kws-8-0.0.1-obfuscated.6da6baef7aa81fff.js +1 -0
  221. package/static/kuaishou/bundles/weapon/kws-9-0.0.1-obfuscated.8645d55e5323b743.js +1 -0
  222. package/static/kuaishou/fixtures/current_follow_script_813.network-response +2 -0
  223. package/static/kuaishou/fixtures/live_ws_maps.json +61 -0
  224. package/static/kuaishou/fixtures/live_ws_proto.json +1342 -0
  225. package/static/kuaishou/js/cp-kwf.js +1 -0
  226. package/static/kuaishou/tools/kwf_oracle.js +799 -0
  227. package/static/kuaishou/tools/kws_oracle.js +885 -0
  228. package/static/kuaishou/tools/like_token_oracle.js +70 -0
  229. package/static/taobao/taobao_js_20260407.js +570 -0
  230. package/static/tiktok/Tiktok_Request.json +597 -0
  231. package/static/tiktok/package.json +3 -0
  232. package/static/tiktok/shop_bsid/core.js +1 -0
  233. package/static/tiktok/shop_bsid/env_core.js +512 -0
  234. package/static/tiktok/shop_bsid/loader.js +1 -0
  235. package/static/tiktok/shop_bsid/run.js +753 -0
  236. package/static/tiktok/shop_bsid/sign.js +100 -0
  237. package/static/tiktok/shop_bsid/webmssdk.js +1 -0
  238. package/static/tiktok/shop_bsid/webmssdk_ex.js +1 -0
  239. package/static/tiktok/signing/env/env_core.js +512 -0
  240. package/static/tiktok/signing/env/sign.js +455 -0
  241. package/static/tiktok/signing/sdk_config.json +230 -0
  242. package/static/tiktok/signing/source/webmssdk.js +1 -0
  243. package/static/tiktok/signing/source/webmssdk_ex.js +1 -0
  244. package/static/tiktok/signing/source/webmssdk_legacy.js +1 -0
  245. package/static/x/graphql.json +7777 -0
  246. package/static/x/transaction_l1.json +12 -0
  247. package/static/xhs/package.json +3 -0
  248. package/static/xhs/xhs_core/js/b1.js +210 -0
  249. package/static/xhs/xhs_core/js/mns.js +340 -0
  250. package/static/xhs/xhs_core/js/mns_0101_keystream.json +5 -0
  251. package/static/xhs/xhs_core/js/mns_keystreams.json +1 -0
  252. package/static/xhs/xhs_core/js/sign.js +225 -0
  253. package/static/xhs/xhs_core/js/websectiga_cli.js +220 -0
  254. package/static/xhs/xhs_core/js/websectiga_env.js +512 -0
  255. package/static/xhs/xhs_core/js/xs_common.js +79 -0
  256. package/static/xhs/xhs_creator/js/profile.js +115 -0
  257. package/static/xhs/xhs_creator/js/rap_fingerprint_creator.json +6 -0
  258. package/static/xhs/xhs_creator/js/reference_profile.json +282 -0
  259. package/static/xhs/xhs_creator/js/xhs_creator_sign.js +29 -0
  260. package/static/xhs/xhs_creator/js/xhs_creator_signature.js +23 -0
  261. package/static/xhs/xhs_pc/js/aes_decrypt.js +22 -0
  262. package/static/xhs/xhs_pc/js/aes_encrypt.js +30 -0
  263. package/static/xhs/xhs_pc/js/b1.js +9 -0
  264. package/static/xhs/xhs_pc/js/deflate.js +320 -0
  265. package/static/xhs/xhs_pc/js/mns.js +4 -0
  266. package/static/xhs/xhs_pc/js/profile.js +141 -0
  267. package/static/xhs/xhs_pc/js/rap.js +173 -0
  268. package/static/xhs/xhs_pc/js/rap_cli.js +30 -0
  269. package/static/xhs/xhs_pc/js/rap_crypto.js +73 -0
  270. package/static/xhs/xhs_pc/js/rap_fingerprint_template.json +8 -0
  271. package/static/xhs/xhs_pc/js/reference_profile.json +262 -0
  272. package/static/xhs/xhs_pc/js/sign.js +6 -0
  273. package/static/xhs/xhs_pc/js/web_ssk.js +82 -0
  274. package/static/xhs/xhs_pc/js/xs_common.js +4 -0
  275. package/static/xianyu/et_f.js +2 -0
  276. package/static/xianyu/gen_tfstk.js +410 -0
  277. package/static/xianyu/goofish_js_version_2.js +568 -0
@@ -0,0 +1,278 @@
1
+ import { SpecificAIError } from '../../../core/errors.js';
2
+ import { quote, urlencode } from '../../../core/py.js';
3
+ import * as rand from '../../../core/rand.js';
4
+ import { businessOrder, pcSignedHeaders, splice } from './client.js';
5
+ import { EDITH, insertAfter, LIVE, navigationHeaders, orderedHeaders, PC_ORDER, SO, UA, WEB } from './profile.js';
6
+ /**
7
+ * 上游 apis/xhs_pc_apis.py(XHS_Apis)与 apis/xhs_live.py(XHSLiveAPI)的请求构造,一个函数对应一个上游方法,
8
+ * 字段与顺序照抄(对拍测试逐字节比较)。返回平台原始 JSON(不检查业务码,由调用方 check)。
9
+ */
10
+ const IMAGE_FORMATS = ['jpg', 'webp', 'avif'];
11
+ const BASE36 = '0123456789abcdefghijklmnopqrstuvwxyz';
12
+ /** search_id:base36((ts << 64) + ceil(0x7ffffffe * random))。 */
13
+ export function searchId() {
14
+ let v = (BigInt(rand.now()) << 64n) + BigInt(Math.ceil(0x7ffffffe * rand.random()));
15
+ if (v === 0n)
16
+ return '0';
17
+ let s = '';
18
+ while (v) {
19
+ s = BASE36[Number(v % 36n)] + s;
20
+ v /= 36n;
21
+ }
22
+ return s;
23
+ }
24
+ export const searchRequestId = () => `${Math.ceil(0x7ffffffe * rand.random())}-${rand.now()}`;
25
+ // ================================================================ 主站
26
+ export function userMe(p) {
27
+ return p.request('/api/sns/web/v2/user/me');
28
+ }
29
+ export function userInfo(p, userId) {
30
+ return p.request(splice('/api/sns/web/v1/user/otherinfo', { target_user_id: userId }));
31
+ }
32
+ function notesPage(path) {
33
+ return (p, userId, cursor, xsecToken = '', xsecSource = '') => p.request(splice(path, { num: '30', cursor, user_id: userId, image_formats: 'jpg,webp,avif', xsec_token: xsecToken, xsec_source: xsecSource }));
34
+ }
35
+ /** get_user_note_info / get_user_like_note_info / get_user_collect_note_info。 */
36
+ export const userNotes = notesPage('/api/sns/web/v1/user_posted');
37
+ export const userLikes = notesPage('/api/sns/web/v1/note/like/page');
38
+ export const userCollects = notesPage('/api/sns/web/v2/note/collect/page');
39
+ /** get_note_info。 */
40
+ export function noteInfo(p, noteId, xsecToken, xsecSource = 'pc_search') {
41
+ return p.request('/api/sns/web/v1/feed', { source_note_id: noteId, image_formats: IMAGE_FORMATS, extra: { need_body_topic: '1' }, xsec_source: xsecSource, xsec_token: xsecToken }, 'POST');
42
+ }
43
+ /** get_homefeed_all_channel。 */
44
+ export function homefeedCategories(p) {
45
+ return p.request('/api/sns/web/v1/homefeed/category');
46
+ }
47
+ /** get_homefeed_recommend。 */
48
+ export function homefeed(p, category, cursorScore, refreshType, noteIndex, num = 20, needNum = 10) {
49
+ return p.request('/api/sns/web/v1/homefeed', {
50
+ cursor_score: cursorScore,
51
+ num,
52
+ refresh_type: refreshType,
53
+ note_index: noteIndex,
54
+ unread_begin_note_id: '',
55
+ unread_end_note_id: '',
56
+ unread_note_count: 0,
57
+ category,
58
+ search_key: '',
59
+ need_num: needNum,
60
+ image_formats: IMAGE_FORMATS,
61
+ need_filter_image: false,
62
+ }, 'POST');
63
+ }
64
+ const NOTE_TYPE_TAGS = ['不限', '视频笔记', '普通笔记'];
65
+ const NOTE_TIME_TAGS = ['不限', '一天内', '一周内', '半年内'];
66
+ /**
67
+ * search_note。noteTime(0 不限、1 一天内、2 一周内、3 半年内)非 0 时,上游在请求体末尾加 filters
68
+ * (浏览器默认搜索不带 filters);note_range / pos_distance 不暴露,固定为「不限」。
69
+ */
70
+ export function searchNotes(p, keyword, page = 1, sort = 'general', noteType = 0, sid, noteTime = 0) {
71
+ const data = {
72
+ keyword,
73
+ page,
74
+ page_size: 20,
75
+ search_id: sid ?? searchId(),
76
+ sort,
77
+ note_type: noteType,
78
+ ext_flags: [],
79
+ geo: '',
80
+ image_formats: IMAGE_FORMATS,
81
+ session_id: rand.uuid4(),
82
+ };
83
+ if (noteTime) {
84
+ data.filters = [
85
+ { tags: [sort], type: 'sort_type' },
86
+ { tags: [NOTE_TYPE_TAGS[noteType] ?? '不限'], type: 'filter_note_type' },
87
+ { tags: [NOTE_TIME_TAGS[noteTime] ?? '不限'], type: 'filter_note_time' },
88
+ { tags: ['不限'], type: 'filter_note_range' },
89
+ { tags: ['不限'], type: 'filter_pos_distance' },
90
+ ];
91
+ }
92
+ return p.request('/api/sns/web/v2/search/notes', data, 'POST', { origin: SO });
93
+ }
94
+ /** get_search_keyword:搜索联想词(keyword 只由 urlencode 编码一次)。 */
95
+ export function searchKeyword(p, word) {
96
+ return p.request(splice('/api/sns/web/v1/search/recommend', { keyword: word }));
97
+ }
98
+ /** search_user。 */
99
+ export function searchUsers(p, keyword, page = 1) {
100
+ return p.request('/api/sns/web/v1/search/usersearch', { search_user_request: { keyword, search_id: searchId(), page, page_size: 15, biz_type: 'web_search_user', request_id: searchRequestId() } }, 'POST');
101
+ }
102
+ /** get_note_out_comment。 */
103
+ export function comments(p, noteId, cursor, xsecToken) {
104
+ return p.request(splice('/api/sns/web/v2/comment/page', { note_id: noteId, cursor, top_comment_id: '', image_formats: 'jpg,webp,avif', xsec_token: xsecToken }));
105
+ }
106
+ /** get_note_inner_comment。 */
107
+ export function subComments(p, noteId, rootId, cursor, xsecToken) {
108
+ return p.request(splice('/api/sns/web/v2/comment/sub/page', { note_id: noteId, root_comment_id: rootId, num: '10', cursor, image_formats: 'jpg,webp,avif', top_comment_id: '', xsec_token: xsecToken }));
109
+ }
110
+ /** get_unread_message。 */
111
+ export function unreadCount(p) {
112
+ return p.request('/api/sns/web/unread_count');
113
+ }
114
+ /** get_metions / get_likesAndcollects / get_new_connections。 */
115
+ export function youMessages(p, kind, cursor) {
116
+ return p.request(splice(`/api/sns/web/v1/you/${kind}`, { num: '20', cursor }));
117
+ }
118
+ /** get_trending_queries(热搜词)。 */
119
+ export function trendingQueries(p) {
120
+ return p.request(splice('/api/sns/web/v1/search/trending/query', {
121
+ source: 'UserPage',
122
+ search_type: 'trend',
123
+ last_query: '',
124
+ last_query_time: 0,
125
+ word_request_situation: 'FIRST_ENTER',
126
+ hint_word: '',
127
+ hint_word_type: '',
128
+ hint_word_request_id: '',
129
+ }));
130
+ }
131
+ /** get_user_board(收藏夹列表)。 */
132
+ export function userBoards(p, userId, page = 1, num = 15) {
133
+ return p.request(splice('/api/sns/web/v1/board/user', { user_id: userId, num, page }));
134
+ }
135
+ /** get_celestial_lt:换取私信 / 直播长连的 RWP 登录 token,写进签名状态。 */
136
+ export async function celestialLt(p) {
137
+ const r = await p.request('/api/sns/web/v1/celestial/lt', '', 'GET', { extra: { c_device_id: p.state.tabDeviceId } });
138
+ const d = r?.data ?? {};
139
+ const ttl = d.expiredTime ?? d.expired_time;
140
+ const aLt = String(d.aLt ?? d.a_lt ?? '');
141
+ if (aLt) {
142
+ p.state.rwpToken = {
143
+ aLt,
144
+ rLt: String(d.rLt ?? d.r_lt ?? ''),
145
+ expiredAt: ttl != null && Number.isFinite(Number(ttl)) ? rand.now() + Math.floor((Number(ttl) * 1000) / 2) : null,
146
+ uid: p.userId,
147
+ };
148
+ }
149
+ return r;
150
+ }
151
+ /** get_note_no_water_video:无登录的笔记页导航,取 og:video。 */
152
+ export async function noteVideo(p, noteId) {
153
+ const res = await p.http.request({ url: `${WEB}/explore/${noteId}`, headers: orderedHeaders(navigationHeaders(), PC_ORDER.navigation, null, { optional: ['cookie'] }), cookies: false });
154
+ return /<meta name="og:video" content="(.*?)">/.exec(await res.text())?.[1] ?? null;
155
+ }
156
+ /** get_note_no_water_img:CDN 图片地址换成 ci.xiaohongshu.com 的无水印 JPEG。 */
157
+ export function noWaterImage(url) {
158
+ const strip = (s) => s.split('!', 1)[0].split('?', 1)[0];
159
+ let token;
160
+ if (url.includes('notes_pre_post/'))
161
+ token = 'notes_pre_post/' + strip(url.split('notes_pre_post/')[1]);
162
+ else if (url.includes('spectrum'))
163
+ token = strip(url.split('/').slice(-2).join('/'));
164
+ else if (url.includes('.jpg'))
165
+ token = strip(url.split('/').slice(-3).join('/'));
166
+ else
167
+ token = strip(url.split('/').at(-1));
168
+ return `https://ci.xiaohongshu.com/${token}?imageView2/format/jpeg`;
169
+ }
170
+ // ================================================================ 直播(XHSLiveAPI)
171
+ /**
172
+ * 上游 XHSLiveAPI._request:live-room 域不带 trace 头、referer 后插 xy-common-params;
173
+ * extra_headers 插在 x-s-common 之后(c_device_id 插在 x-xray-traceid 之后)。
174
+ */
175
+ export async function liveRequest(p, origin, api, method = 'GET', data = '', extra = {}) {
176
+ p.sync();
177
+ p.requireSession();
178
+ const context = p.state.nextSignContext(api);
179
+ const b1 = p.state.currentB1(context.now);
180
+ const dslPair = p.state.dslPair(await p.dsl(), rand.now());
181
+ const signed = pcSignedHeaders(p.state, api, data, { b1, dslPair, context, userId: p.userId, clientHints: false, trace: origin !== LIVE });
182
+ let h = signed.headers;
183
+ h.referer = `${WEB}/`;
184
+ h['user-agent'] = UA;
185
+ if (origin === LIVE) {
186
+ // 上游 bug:generate_headers 总会写 x-b3-traceid,live-room 域的头顺序表里没有它,上游这里直接抛错;按实抓去掉
187
+ delete h['x-b3-traceid'];
188
+ h = insertAfter(h, 'xy-common-params', 'platform=web', 'referer');
189
+ }
190
+ for (const [k, v] of Object.entries(extra))
191
+ h = insertAfter(h, k, v, k.toLowerCase() === 'c_device_id' ? 'x-xray-traceid' : 'x-s-common');
192
+ const url = origin + api;
193
+ const cookies = p.wire(url);
194
+ let pairs;
195
+ if (origin === LIVE) {
196
+ let order = method === 'GET' ? PC_ORDER.liveGet : PC_ORDER.livePost;
197
+ if (!('content-type' in h))
198
+ order = order.filter((k) => k !== 'content-type');
199
+ pairs = orderedHeaders(h, order, cookies, { optional: ['xy-common-params', 'x-ratelimit-meta'] });
200
+ }
201
+ else
202
+ pairs = orderedHeaders(h, businessOrder(h, method), cookies);
203
+ return p.json({ method, url, headers: pairs, ...(method === 'POST' ? { body: signed.body } : {}) });
204
+ }
205
+ const liveGet = (p, path, params, extra) => liveRequest(p, LIVE, splice(path, params), 'GET', '', extra);
206
+ export function liveCategories(p) {
207
+ return liveGet(p, '/api/sns/red/live/web/feed/category', {});
208
+ }
209
+ /** square_feed:extra_info 里的 `:` `,` 保持可读。 */
210
+ export function liveSquare(p, category = '', size = 27) {
211
+ const extra = JSON.stringify({ image_formats: IMAGE_FORMATS });
212
+ const query = `source=13&category=${quote(category, '')}&pre_source=${quote('', '')}&extra_info=${quote(extra, ':,')}&size=${size}`;
213
+ return liveRequest(p, LIVE, `/api/sns/red/live/web/feed/v1/squarefeed?${query}`);
214
+ }
215
+ export function liveRoomInfo(p, roomId, requestUserId) {
216
+ if (!requestUserId)
217
+ throw new SpecificAIError('AUTH_REQUIRED', '查看直播间需要当前账号的 user_id', { hint: 'specific-ai xhs auth login' });
218
+ return liveGet(p, '/api/sns/red/live/web/v1/room/current_room_info', { room_id: roomId, request_user_id: requestUserId, source: 'web_live', client_type: 1 }, { 'x-ratelimit-meta': `roomId=${roomId}` });
219
+ }
220
+ export function liveGiftPanel(p, hostId, roomId) {
221
+ return liveGet(p, '/api/sns/red/live/web/gift/v1/gift_panel', { host_id: hostId, room_id: roomId, scene: 'web_gift_panel' });
222
+ }
223
+ /** aggregate_business_info:直播间商品等业务信息。 */
224
+ export function liveBusiness(p, roomId, hostId) {
225
+ return liveGet(p, '/api/sns/red/live/web/v1/room/aggregate_business_info', { room_id: roomId, host_id: hostId, client_type: 1 }, { 'x-ratelimit-meta': `roomId=${roomId}&hostId=${hostId}` });
226
+ }
227
+ export function liveSendComment(p, roomId, comment, hostId) {
228
+ return liveRequest(p, LIVE, '/api/sns/v1/live/web/interaction/send_comment', 'POST', { room_id: roomId, comment, source: 'web_live', client_type: 1 }, { 'x-ratelimit-meta': `roomId=${roomId}&hostId=${hostId}` });
229
+ }
230
+ // ================================================================ 私信(XHSLiveAPI 的 IM 接口,edith 域)
231
+ const im = (p, api, method = 'GET', data = '', extra) => liveRequest(p, EDITH, api, method, data, extra);
232
+ export function chats(p, page = 0, limit = 100) {
233
+ return im(p, `/api/im/web/v3/chats?${urlencode([['limit', limit], ['complete', 'true'], ['page', page], ['source', 'pc']])}`);
234
+ }
235
+ export function messageHistory(p, chatUserId, lastId = 0, limit = 30) {
236
+ return im(p, `/api/im/web/messages/history?${urlencode([['chat_user_id', chatUserId], ['last_id', lastId], ['start_id', 0], ['limit', limit]])}`);
237
+ }
238
+ /** get_group_chats:群聊会话列表(参数与 get_chats 相同)。 */
239
+ export function groupChats(p, page = 0, limit = 100) {
240
+ return im(p, `/api/im/web/chats/group?${urlencode([['limit', limit], ['complete', 'true'], ['page', page], ['source', 'pc']])}`);
241
+ }
242
+ /**
243
+ * get_group_message_history:上游要调用方给出实抓的参数(按给出的顺序编码)。这里按私信记录的同一组游标
244
+ * (group_id、last_id、start_id、limit)给出,last_id 是上一页最早一条的 store_id。
245
+ */
246
+ export function groupMessageHistory(p, groupId, lastId = 0, limit = 30) {
247
+ return im(p, `/api/im/web/red/group/messages/history?${urlencode([['group_id', groupId], ['last_id', lastId], ['start_id', 0], ['limit', limit]])}`);
248
+ }
249
+ /** get_following:当前账号的关注列表(私信页的「选择联系人」用的接口,只能取自己的)。 */
250
+ export function following(p, page = 1, size = 200) {
251
+ return im(p, `/api/im/web/users/following/all?${urlencode([['page', page], ['size', size]])}`);
252
+ }
253
+ /** mark_messages_read:chat_list 每项按实抓字段顺序。 */
254
+ export function markRead(p, chatList) {
255
+ const required = ['chat_id', 'read_store_id', 'unread_count', 'type', 'need_rm_offline'];
256
+ const list = chatList.map((item) => {
257
+ const out = {};
258
+ for (const k of required)
259
+ out[k] = item[k];
260
+ for (const [k, v] of Object.entries(item))
261
+ if (!required.includes(k))
262
+ out[k] = v;
263
+ return out;
264
+ });
265
+ return im(p, '/api/im/web/v2/messages/read', 'POST', { chat_list: list, chat_total_unread_count: 0, mute_chat_total_unread_count: 0, stranger_total_unread_count: 0 }, { 'content-type': 'application/json; charset=UTF-8' });
266
+ }
267
+ /** revoke_message(参数按实抓:chat_user_id、message_id 等由调用方给出)。 */
268
+ export function revokeMessage(p, params) {
269
+ return im(p, '/api/im/web/messages/revoke', 'POST', params);
270
+ }
271
+ /** delete_message(GET,query 按调用方给出的顺序)。 */
272
+ export function deleteMessage(p, params) {
273
+ return im(p, `/api/sns/v6/message/web/delete_msg?${urlencode(params)}`);
274
+ }
275
+ /** send_captured_short_link_message:RSA 加密后的私信 protobuf,经 HTTP 兜底发送。 */
276
+ export function sendShortLink(p, message) {
277
+ return im(p, '/api/im/web/short_link/send_message', 'POST', { message });
278
+ }