@dinoxx/dinox-cli 2.19.0 → 2.20.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 (599) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +24 -27
  3. package/dist/chunks/applePodcast-V4FSJOC5.js +169 -0
  4. package/dist/chunks/bbc-NTMRPYRF.js +570 -0
  5. package/dist/chunks/bilibili-UA3MBSPH.js +835 -0
  6. package/dist/chunks/bohaishibei-B7UVXH4Y.js +246 -0
  7. package/dist/chunks/chunk-224ML7QC.js +21 -0
  8. package/dist/chunks/chunk-2LW76QIL.js +32 -0
  9. package/dist/chunks/chunk-2M7RJATW.js +60 -0
  10. package/dist/chunks/chunk-3EKNTO6G.js +61 -0
  11. package/dist/chunks/chunk-3VZNZWDG.js +437 -0
  12. package/dist/chunks/chunk-53CT7DJ3.js +39 -0
  13. package/dist/chunks/chunk-5JF7J5MP.js +114 -0
  14. package/dist/chunks/chunk-5KU25TMX.js +26 -0
  15. package/dist/chunks/chunk-67RXND3H.js +65 -0
  16. package/dist/chunks/chunk-6AZT4ARG.js +1491 -0
  17. package/dist/chunks/chunk-6D3QLMRM.js +421 -0
  18. package/dist/chunks/chunk-6VMHHE5Y.js +235 -0
  19. package/dist/chunks/chunk-77UP745T.js +143 -0
  20. package/dist/chunks/chunk-7A5QISPG.js +19 -0
  21. package/dist/chunks/chunk-7ODU7LXP.js +31 -0
  22. package/dist/chunks/chunk-ABYPGMDC.js +100 -0
  23. package/dist/chunks/chunk-AHRCI2RW.js +141 -0
  24. package/dist/chunks/chunk-BDLS5EEP.js +49 -0
  25. package/dist/chunks/chunk-BKCNERPB.js +246 -0
  26. package/dist/chunks/chunk-BZQYECIH.js +54 -0
  27. package/dist/chunks/chunk-D5SBKLDX.js +71 -0
  28. package/dist/chunks/chunk-F7BDWXBG.js +57 -0
  29. package/dist/chunks/chunk-FGQRYB7F.js +34 -0
  30. package/dist/chunks/chunk-FIQYJ6KZ.js +19 -0
  31. package/dist/chunks/chunk-FKLZZGEX.js +116 -0
  32. package/dist/chunks/chunk-FZGEWY5L.js +37 -0
  33. package/dist/chunks/chunk-G6JSWE66.js +865 -0
  34. package/dist/chunks/chunk-GTDX2LIJ.js +265 -0
  35. package/dist/chunks/chunk-HIJXC3RT.js +194 -0
  36. package/dist/chunks/chunk-HQJUJYUM.js +36 -0
  37. package/dist/chunks/chunk-IAEJG5NI.js +50 -0
  38. package/dist/chunks/chunk-KCHHY6QB.js +65 -0
  39. package/dist/chunks/chunk-KL75BFYJ.js +71 -0
  40. package/dist/chunks/chunk-KOAKG2QU.js +45 -0
  41. package/dist/chunks/chunk-MCFXD2LS.js +66 -0
  42. package/dist/chunks/chunk-MLOITAK6.js +29 -0
  43. package/dist/chunks/chunk-N44NRKDJ.js +101 -0
  44. package/dist/chunks/chunk-NGIIELO4.js +61 -0
  45. package/dist/chunks/chunk-OG6MBAGC.js +95 -0
  46. package/dist/chunks/chunk-P4LG4DIO.js +108 -0
  47. package/dist/chunks/chunk-PGR7R2HI.js +904 -0
  48. package/dist/chunks/chunk-PJDD4R46.js +77 -0
  49. package/dist/chunks/chunk-PK5AOVLU.js +107 -0
  50. package/dist/chunks/chunk-PTFGE4KS.js +66 -0
  51. package/dist/chunks/chunk-Q6G7VO5G.js +67 -0
  52. package/dist/chunks/chunk-QFSMFANX.js +1219 -0
  53. package/dist/chunks/chunk-QFUD3I7W.js +185 -0
  54. package/dist/chunks/chunk-QZQRG3JY.js +86 -0
  55. package/dist/chunks/chunk-RKJYKUQD.js +91 -0
  56. package/dist/chunks/chunk-TILRKKRN.js +20481 -0
  57. package/dist/chunks/chunk-TIXOORAP.js +60 -0
  58. package/dist/chunks/chunk-ULKGDBAJ.js +80 -0
  59. package/dist/chunks/chunk-URYABAYN.js +72 -0
  60. package/dist/chunks/chunk-VI7C4BBS.js +160 -0
  61. package/dist/chunks/chunk-VNB4ZFLN.js +86 -0
  62. package/dist/chunks/chunk-W7R5JTSA.js +42 -0
  63. package/dist/chunks/chunk-WMJXAF3X.js +55 -0
  64. package/dist/chunks/chunk-X36EIV25.js +93 -0
  65. package/dist/chunks/chunk-X7IZXCSL.js +60 -0
  66. package/dist/chunks/chunk-X7JXCHLI.js +25699 -0
  67. package/dist/chunks/chunk-XEPDFQYD.js +215 -0
  68. package/dist/chunks/chunk-XFVLNCOW.js +171 -0
  69. package/dist/chunks/chunk-XMMTGPZ6.js +1332 -0
  70. package/dist/chunks/chunk-XQZUX7OT.js +39 -0
  71. package/dist/chunks/chunk-XZLFMJOG.js +72 -0
  72. package/dist/chunks/chunk-YDIE7QBM.js +14115 -0
  73. package/dist/chunks/chunk-ZGF3OEWR.js +84 -0
  74. package/dist/chunks/cookies-6QQHSM26.js +34 -0
  75. package/dist/chunks/dedaoNote-KJ32ZQLS.js +418 -0
  76. package/dist/chunks/doubanGroup-HR4K2KMY.js +429 -0
  77. package/dist/chunks/doubao-MXUHPLUB.js +462 -0
  78. package/dist/chunks/douyin-UU2FSQPS.js +566 -0
  79. package/dist/chunks/ensure-CHJ5YTBX.js +18 -0
  80. package/dist/chunks/execute-RXJ4AO2Z.js +17 -0
  81. package/dist/chunks/facebook-SZFOVE7R.js +878 -0
  82. package/dist/chunks/feishu-ISWRJ7HI.js +877 -0
  83. package/dist/chunks/ima-D7CX5WR4.js +202 -0
  84. package/dist/chunks/instagram-HNDPO37H.js +939 -0
  85. package/dist/chunks/install-IIMVFNAT.js +303 -0
  86. package/dist/chunks/jike-H7L4LJTN.js +445 -0
  87. package/dist/chunks/mcp-NMKVOSVN.js +297 -0
  88. package/dist/chunks/mcpServer-NYJAKMVH.js +436 -0
  89. package/dist/chunks/metaso-ZVZW5UBB.js +194 -0
  90. package/dist/chunks/run-ETPFUFB6.js +1464 -0
  91. package/dist/chunks/runCli-GJRY73UA.js +464 -0
  92. package/dist/chunks/setup-EEU6GSWX.js +378 -0
  93. package/dist/chunks/threads-ADW6IANQ.js +657 -0
  94. package/dist/chunks/twitter-NAGCB3NI.js +1148 -0
  95. package/dist/chunks/web-QFKZCM4F.js +31 -0
  96. package/dist/chunks/wechat-OXNNLT4J.js +1551 -0
  97. package/dist/chunks/weibo-PMVGDNQU.js +641 -0
  98. package/dist/chunks/workbuddy-NNAXIIIZ.js +426 -0
  99. package/dist/chunks/xiaoheihe-WFQJRBAD.js +316 -0
  100. package/dist/chunks/xiaohongshu-5CXBELGW.js +1833 -0
  101. package/dist/chunks/xiaoyuzhou-6L6IB46Y.js +322 -0
  102. package/dist/chunks/youtube-52NGBTQC.js +58 -0
  103. package/dist/chunks/zcool-HDSWK4KD.js +755 -0
  104. package/dist/chunks/zhihu-EX2VRJYY.js +1024 -0
  105. package/dist/dinox.js +137 -51
  106. package/dist/dsh-plugin/lib/client.js +265 -252
  107. package/dist/dsh-plugin/package.json +1 -1
  108. package/dist/dsh-plugin/runtime.json +3 -3
  109. package/dist/editor-ui/mcp-app.html +293 -280
  110. package/package.json +82 -64
  111. package/dist/ai/ragxClient.d.ts +0 -15
  112. package/dist/ai/ragxClient.js +0 -71
  113. package/dist/auth/devicePair.d.ts +0 -62
  114. package/dist/auth/devicePair.js +0 -377
  115. package/dist/auth/userInfo.d.ts +0 -26
  116. package/dist/auth/userInfo.js +0 -224
  117. package/dist/cli.d.ts +0 -2
  118. package/dist/cli.js +0 -130
  119. package/dist/cliTypes.d.ts +0 -7
  120. package/dist/cliTypes.js +0 -1
  121. package/dist/commands/auth/index.d.ts +0 -34
  122. package/dist/commands/auth/index.js +0 -605
  123. package/dist/commands/batch.d.ts +0 -35
  124. package/dist/commands/batch.js +0 -202
  125. package/dist/commands/boxes/index.d.ts +0 -4
  126. package/dist/commands/boxes/index.js +0 -382
  127. package/dist/commands/boxes/model.d.ts +0 -37
  128. package/dist/commands/boxes/model.js +0 -93
  129. package/dist/commands/boxes/operations.d.ts +0 -86
  130. package/dist/commands/boxes/operations.js +0 -448
  131. package/dist/commands/boxes/repo.d.ts +0 -36
  132. package/dist/commands/boxes/repo.js +0 -320
  133. package/dist/commands/boxes/store.d.ts +0 -22
  134. package/dist/commands/boxes/store.js +0 -143
  135. package/dist/commands/config/index.d.ts +0 -5
  136. package/dist/commands/config/index.js +0 -105
  137. package/dist/commands/descriptor/register.d.ts +0 -8
  138. package/dist/commands/descriptor/register.js +0 -122
  139. package/dist/commands/descriptor/types.d.ts +0 -37
  140. package/dist/commands/descriptor/types.js +0 -17
  141. package/dist/commands/doctor.d.ts +0 -126
  142. package/dist/commands/doctor.js +0 -558
  143. package/dist/commands/domain/options.d.ts +0 -10
  144. package/dist/commands/domain/options.js +0 -75
  145. package/dist/commands/domain/run.d.ts +0 -24
  146. package/dist/commands/domain/run.js +0 -137
  147. package/dist/commands/editor/index.d.ts +0 -4
  148. package/dist/commands/editor/index.js +0 -155
  149. package/dist/commands/gateway/index.d.ts +0 -4
  150. package/dist/commands/gateway/index.js +0 -340
  151. package/dist/commands/graph/index.d.ts +0 -4
  152. package/dist/commands/graph/index.js +0 -173
  153. package/dist/commands/graph/repo.d.ts +0 -40
  154. package/dist/commands/graph/repo.js +0 -201
  155. package/dist/commands/info/index.d.ts +0 -4
  156. package/dist/commands/info/index.js +0 -75
  157. package/dist/commands/mcp.d.ts +0 -6
  158. package/dist/commands/mcp.js +0 -47
  159. package/dist/commands/meta/index.d.ts +0 -4
  160. package/dist/commands/meta/index.js +0 -60
  161. package/dist/commands/meta/repo.d.ts +0 -30
  162. package/dist/commands/meta/repo.js +0 -76
  163. package/dist/commands/notes/actions.d.ts +0 -12
  164. package/dist/commands/notes/actions.js +0 -591
  165. package/dist/commands/notes/bulk.d.ts +0 -35
  166. package/dist/commands/notes/bulk.js +0 -195
  167. package/dist/commands/notes/contentEngine.d.ts +0 -95
  168. package/dist/commands/notes/contentEngine.js +0 -714
  169. package/dist/commands/notes/contentPatch.d.ts +0 -114
  170. package/dist/commands/notes/contentPatch.js +0 -450
  171. package/dist/commands/notes/contentPatchCommand.d.ts +0 -6
  172. package/dist/commands/notes/contentPatchCommand.js +0 -164
  173. package/dist/commands/notes/createFromTemplate.d.ts +0 -35
  174. package/dist/commands/notes/createFromTemplate.js +0 -58
  175. package/dist/commands/notes/descriptors.d.ts +0 -4
  176. package/dist/commands/notes/descriptors.js +0 -548
  177. package/dist/commands/notes/detailContent.d.ts +0 -19
  178. package/dist/commands/notes/detailContent.js +0 -62
  179. package/dist/commands/notes/dryRun.d.ts +0 -33
  180. package/dist/commands/notes/dryRun.js +0 -133
  181. package/dist/commands/notes/export.d.ts +0 -27
  182. package/dist/commands/notes/export.js +0 -252
  183. package/dist/commands/notes/index.d.ts +0 -2
  184. package/dist/commands/notes/index.js +0 -2
  185. package/dist/commands/notes/metadataMutation.d.ts +0 -29
  186. package/dist/commands/notes/metadataMutation.js +0 -138
  187. package/dist/commands/notes/repo/read.d.ts +0 -8
  188. package/dist/commands/notes/repo/read.js +0 -302
  189. package/dist/commands/notes/repo/resolve.d.ts +0 -8
  190. package/dist/commands/notes/repo/resolve.js +0 -187
  191. package/dist/commands/notes/repo/search.d.ts +0 -43
  192. package/dist/commands/notes/repo/search.js +0 -513
  193. package/dist/commands/notes/repo/semantic.d.ts +0 -14
  194. package/dist/commands/notes/repo/semantic.js +0 -31
  195. package/dist/commands/notes/repo/shared.d.ts +0 -192
  196. package/dist/commands/notes/repo/shared.js +0 -102
  197. package/dist/commands/notes/repo/write.d.ts +0 -27
  198. package/dist/commands/notes/repo/write.js +0 -262
  199. package/dist/commands/notes/repo.d.ts +0 -7
  200. package/dist/commands/notes/repo.js +0 -7
  201. package/dist/commands/notes/runtime.d.ts +0 -20
  202. package/dist/commands/notes/runtime.js +0 -175
  203. package/dist/commands/notes/searchOutput.d.ts +0 -15
  204. package/dist/commands/notes/searchOutput.js +0 -54
  205. package/dist/commands/notes/searchResponse.d.ts +0 -54
  206. package/dist/commands/notes/searchResponse.js +0 -57
  207. package/dist/commands/notes/searchSql.d.ts +0 -11
  208. package/dist/commands/notes/searchSql.js +0 -614
  209. package/dist/commands/notes/searchTime.d.ts +0 -9
  210. package/dist/commands/notes/searchTime.js +0 -85
  211. package/dist/commands/notes/semantic.d.ts +0 -116
  212. package/dist/commands/notes/semantic.js +0 -332
  213. package/dist/commands/notes/writeReceipt.d.ts +0 -20
  214. package/dist/commands/notes/writeReceipt.js +0 -82
  215. package/dist/commands/prompt/index.d.ts +0 -5
  216. package/dist/commands/prompt/index.js +0 -132
  217. package/dist/commands/prompt/repo.d.ts +0 -28
  218. package/dist/commands/prompt/repo.js +0 -220
  219. package/dist/commands/properties/index.d.ts +0 -16
  220. package/dist/commands/properties/index.js +0 -640
  221. package/dist/commands/properties/repo.d.ts +0 -150
  222. package/dist/commands/properties/repo.js +0 -272
  223. package/dist/commands/runtime.d.ts +0 -54
  224. package/dist/commands/runtime.js +0 -228
  225. package/dist/commands/savedViews/fields.d.ts +0 -28
  226. package/dist/commands/savedViews/fields.js +0 -87
  227. package/dist/commands/savedViews/index.d.ts +0 -7
  228. package/dist/commands/savedViews/index.js +0 -506
  229. package/dist/commands/savedViews/model.d.ts +0 -45
  230. package/dist/commands/savedViews/model.js +0 -90
  231. package/dist/commands/savedViews/repo.d.ts +0 -125
  232. package/dist/commands/savedViews/repo.js +0 -393
  233. package/dist/commands/schema/commandMetadata.d.ts +0 -2
  234. package/dist/commands/schema/commandMetadata.js +0 -18
  235. package/dist/commands/schema/globalOptions.d.ts +0 -11
  236. package/dist/commands/schema/globalOptions.js +0 -11
  237. package/dist/commands/schema/index.d.ts +0 -5
  238. package/dist/commands/schema/index.js +0 -130
  239. package/dist/commands/schema/renderSkills.d.ts +0 -12
  240. package/dist/commands/schema/renderSkills.js +0 -366
  241. package/dist/commands/schema/spec.d.ts +0 -5
  242. package/dist/commands/schema/spec.js +0 -74
  243. package/dist/commands/schema/types.d.ts +0 -34
  244. package/dist/commands/schema/types.js +0 -1
  245. package/dist/commands/skills/index.d.ts +0 -80
  246. package/dist/commands/skills/index.js +0 -572
  247. package/dist/commands/storage/index.d.ts +0 -4
  248. package/dist/commands/storage/index.js +0 -270
  249. package/dist/commands/storage/repo/configs.d.ts +0 -30
  250. package/dist/commands/storage/repo/configs.js +0 -259
  251. package/dist/commands/storage/repo/operations.d.ts +0 -25
  252. package/dist/commands/storage/repo/operations.js +0 -339
  253. package/dist/commands/storage/repo/remote.d.ts +0 -32
  254. package/dist/commands/storage/repo/remote.js +0 -132
  255. package/dist/commands/storage/repo/resources.d.ts +0 -12
  256. package/dist/commands/storage/repo/resources.js +0 -134
  257. package/dist/commands/storage/repo/shared.d.ts +0 -181
  258. package/dist/commands/storage/repo/shared.js +0 -36
  259. package/dist/commands/storage/repo/targets.d.ts +0 -12
  260. package/dist/commands/storage/repo/targets.js +0 -178
  261. package/dist/commands/storage/repo.d.ts +0 -3
  262. package/dist/commands/storage/repo.js +0 -4
  263. package/dist/commands/sync.d.ts +0 -27
  264. package/dist/commands/sync.js +0 -153
  265. package/dist/commands/tags/content.d.ts +0 -32
  266. package/dist/commands/tags/content.js +0 -252
  267. package/dist/commands/tags/index.d.ts +0 -4
  268. package/dist/commands/tags/index.js +0 -404
  269. package/dist/commands/tags/model.d.ts +0 -38
  270. package/dist/commands/tags/model.js +0 -100
  271. package/dist/commands/tags/operations.d.ts +0 -105
  272. package/dist/commands/tags/operations.js +0 -468
  273. package/dist/commands/tags/repo.d.ts +0 -27
  274. package/dist/commands/tags/repo.js +0 -236
  275. package/dist/commands/tags/store.d.ts +0 -28
  276. package/dist/commands/tags/store.js +0 -166
  277. package/dist/commands/templates/index.d.ts +0 -4
  278. package/dist/commands/templates/index.js +0 -290
  279. package/dist/commands/templates/model.d.ts +0 -28
  280. package/dist/commands/templates/model.js +0 -195
  281. package/dist/commands/templates/repo.d.ts +0 -53
  282. package/dist/commands/templates/repo.js +0 -78
  283. package/dist/commands/todo/contentModel.d.ts +0 -33
  284. package/dist/commands/todo/contentModel.js +0 -377
  285. package/dist/commands/todo/dryRun.d.ts +0 -26
  286. package/dist/commands/todo/dryRun.js +0 -150
  287. package/dist/commands/todo/index.d.ts +0 -10
  288. package/dist/commands/todo/index.js +0 -631
  289. package/dist/commands/todo/repo.d.ts +0 -257
  290. package/dist/commands/todo/repo.js +0 -772
  291. package/dist/commands/todo/taskIdentity.d.ts +0 -2
  292. package/dist/commands/todo/taskIdentity.js +0 -64
  293. package/dist/commands/todo/taskModel.d.ts +0 -56
  294. package/dist/commands/todo/taskModel.js +0 -492
  295. package/dist/commands/todo/taskPatch.d.ts +0 -119
  296. package/dist/commands/todo/taskPatch.js +0 -502
  297. package/dist/commands/todo/taskText.d.ts +0 -26
  298. package/dist/commands/todo/taskText.js +0 -221
  299. package/dist/commands/update.d.ts +0 -46
  300. package/dist/commands/update.js +0 -326
  301. package/dist/commands/writeConfirmation.d.ts +0 -13
  302. package/dist/commands/writeConfirmation.js +0 -54
  303. package/dist/commands/writeDryRun.d.ts +0 -88
  304. package/dist/commands/writeDryRun.js +0 -162
  305. package/dist/commands/writeDurability.d.ts +0 -5
  306. package/dist/commands/writeDurability.js +0 -22
  307. package/dist/commands/writeReceipt.d.ts +0 -13
  308. package/dist/commands/writeReceipt.js +0 -12
  309. package/dist/config/keys.d.ts +0 -9
  310. package/dist/config/keys.js +0 -14
  311. package/dist/config/paths.d.ts +0 -6
  312. package/dist/config/paths.js +0 -55
  313. package/dist/config/resolve.d.ts +0 -4
  314. package/dist/config/resolve.js +0 -68
  315. package/dist/config/serviceEndpoints.d.ts +0 -5
  316. package/dist/config/serviceEndpoints.js +0 -5
  317. package/dist/config/store.d.ts +0 -8
  318. package/dist/config/store.js +0 -149
  319. package/dist/config/types.d.ts +0 -55
  320. package/dist/config/types.js +0 -1
  321. package/dist/constants/links.d.ts +0 -18
  322. package/dist/constants/links.js +0 -26
  323. package/dist/contract/snapshot.d.ts +0 -30
  324. package/dist/contract/snapshot.js +0 -114
  325. package/dist/daemon/autoInstall.d.ts +0 -32
  326. package/dist/daemon/autoInstall.js +0 -106
  327. package/dist/daemon/client.d.ts +0 -29
  328. package/dist/daemon/client.js +0 -418
  329. package/dist/daemon/connectivity.d.ts +0 -20
  330. package/dist/daemon/connectivity.js +0 -42
  331. package/dist/daemon/ensure.d.ts +0 -1
  332. package/dist/daemon/ensure.js +0 -120
  333. package/dist/daemon/env.d.ts +0 -8
  334. package/dist/daemon/env.js +0 -81
  335. package/dist/daemon/forward.d.ts +0 -37
  336. package/dist/daemon/forward.js +0 -155
  337. package/dist/daemon/fresh.d.ts +0 -4
  338. package/dist/daemon/fresh.js +0 -10
  339. package/dist/daemon/index.d.ts +0 -80
  340. package/dist/daemon/index.js +0 -727
  341. package/dist/daemon/launch.d.ts +0 -43
  342. package/dist/daemon/launch.js +0 -124
  343. package/dist/daemon/lifecycle.d.ts +0 -51
  344. package/dist/daemon/lifecycle.js +0 -182
  345. package/dist/daemon/log.d.ts +0 -14
  346. package/dist/daemon/log.js +0 -57
  347. package/dist/daemon/pid.d.ts +0 -31
  348. package/dist/daemon/pid.js +0 -212
  349. package/dist/daemon/route.d.ts +0 -14
  350. package/dist/daemon/route.js +0 -43
  351. package/dist/daemon/server.d.ts +0 -67
  352. package/dist/daemon/server.js +0 -563
  353. package/dist/daemon/supervise.d.ts +0 -29
  354. package/dist/daemon/supervise.js +0 -100
  355. package/dist/daemon/supervisor.d.ts +0 -91
  356. package/dist/daemon/supervisor.js +0 -612
  357. package/dist/daemon/types.d.ts +0 -71
  358. package/dist/daemon/types.js +0 -2
  359. package/dist/dinox.d.ts +0 -2
  360. package/dist/editor/anchor.d.ts +0 -46
  361. package/dist/editor/anchor.js +0 -129
  362. package/dist/editor/blockIds.d.ts +0 -21
  363. package/dist/editor/blockIds.js +0 -51
  364. package/dist/editor/blocks.d.ts +0 -47
  365. package/dist/editor/blocks.js +0 -236
  366. package/dist/editor/compat.d.ts +0 -38
  367. package/dist/editor/compat.js +0 -410
  368. package/dist/editor/daemon.d.ts +0 -10
  369. package/dist/editor/daemon.js +0 -83
  370. package/dist/editor/document.d.ts +0 -74
  371. package/dist/editor/document.js +0 -88
  372. package/dist/editor/i18n.d.ts +0 -23
  373. package/dist/editor/i18n.js +0 -61
  374. package/dist/editor/install.d.ts +0 -90
  375. package/dist/editor/install.js +0 -335
  376. package/dist/editor/mcp.d.ts +0 -22
  377. package/dist/editor/mcp.js +0 -319
  378. package/dist/editor/meta.d.ts +0 -70
  379. package/dist/editor/meta.js +0 -163
  380. package/dist/editor/paths.d.ts +0 -2
  381. package/dist/editor/paths.js +0 -13
  382. package/dist/editor/persistence.d.ts +0 -4
  383. package/dist/editor/persistence.js +0 -35
  384. package/dist/editor/saveGuard.d.ts +0 -9
  385. package/dist/editor/saveGuard.js +0 -38
  386. package/dist/editor/schema.d.ts +0 -14
  387. package/dist/editor/schema.js +0 -38
  388. package/dist/editor/service.d.ts +0 -382
  389. package/dist/editor/service.js +0 -1174
  390. package/dist/editor/todos.d.ts +0 -67
  391. package/dist/editor/todos.js +0 -293
  392. package/dist/gateway/adapters/acp.d.ts +0 -75
  393. package/dist/gateway/adapters/acp.js +0 -431
  394. package/dist/gateway/adapters/codexImages.d.ts +0 -4
  395. package/dist/gateway/adapters/codexImages.js +0 -34
  396. package/dist/gateway/adapters/echo.d.ts +0 -12
  397. package/dist/gateway/adapters/echo.js +0 -54
  398. package/dist/gateway/adapters/index.d.ts +0 -13
  399. package/dist/gateway/adapters/index.js +0 -42
  400. package/dist/gateway/agentTaskHost.d.ts +0 -135
  401. package/dist/gateway/agentTaskHost.js +0 -410
  402. package/dist/gateway/assistantProjection.d.ts +0 -36
  403. package/dist/gateway/assistantProjection.js +0 -230
  404. package/dist/gateway/config.d.ts +0 -56
  405. package/dist/gateway/config.js +0 -312
  406. package/dist/gateway/conversationContext.d.ts +0 -44
  407. package/dist/gateway/conversationContext.js +0 -75
  408. package/dist/gateway/detect.d.ts +0 -63
  409. package/dist/gateway/detect.js +0 -281
  410. package/dist/gateway/deviceHost.d.ts +0 -100
  411. package/dist/gateway/deviceHost.js +0 -735
  412. package/dist/gateway/fileUpload.d.ts +0 -12
  413. package/dist/gateway/fileUpload.js +0 -154
  414. package/dist/gateway/keepAwake.d.ts +0 -24
  415. package/dist/gateway/keepAwake.js +0 -64
  416. package/dist/gateway/mcpCommandTools.d.ts +0 -62
  417. package/dist/gateway/mcpCommandTools.js +0 -220
  418. package/dist/gateway/mcpEnv.d.ts +0 -11
  419. package/dist/gateway/mcpEnv.js +0 -11
  420. package/dist/gateway/mcpGroups.d.ts +0 -3
  421. package/dist/gateway/mcpGroups.js +0 -4
  422. package/dist/gateway/mcpServer.d.ts +0 -25
  423. package/dist/gateway/mcpServer.js +0 -214
  424. package/dist/gateway/processTree.d.ts +0 -15
  425. package/dist/gateway/processTree.js +0 -60
  426. package/dist/gateway/protocol.d.ts +0 -145
  427. package/dist/gateway/protocol.js +0 -195
  428. package/dist/gateway/runExecutor.d.ts +0 -104
  429. package/dist/gateway/runExecutor.js +0 -480
  430. package/dist/gateway/service.d.ts +0 -35
  431. package/dist/gateway/service.js +0 -147
  432. package/dist/gateway/spawnAgent.d.ts +0 -12
  433. package/dist/gateway/spawnAgent.js +0 -32
  434. package/dist/gateway/streamPublisher.d.ts +0 -33
  435. package/dist/gateway/streamPublisher.js +0 -93
  436. package/dist/gateway/taskJournal.d.ts +0 -14
  437. package/dist/gateway/taskJournal.js +0 -47
  438. package/dist/gateway/threadStore.d.ts +0 -230
  439. package/dist/gateway/threadStore.js +0 -621
  440. package/dist/gateway/types.d.ts +0 -168
  441. package/dist/gateway/types.js +0 -12
  442. package/dist/gateway/workspace.d.ts +0 -5
  443. package/dist/gateway/workspace.js +0 -30
  444. package/dist/gateway/workspaceFolders.d.ts +0 -35
  445. package/dist/gateway/workspaceFolders.js +0 -142
  446. package/dist/gateway/workspaceListing.d.ts +0 -5
  447. package/dist/gateway/workspaceListing.js +0 -78
  448. package/dist/integrations/dsh/host.d.ts +0 -53
  449. package/dist/integrations/dsh/host.js +0 -245
  450. package/dist/integrations/dsh/mcpClient.d.ts +0 -66
  451. package/dist/integrations/dsh/mcpClient.js +0 -192
  452. package/dist/powersync/connector.d.ts +0 -22
  453. package/dist/powersync/connector.js +0 -91
  454. package/dist/powersync/exclusiveRuntime.d.ts +0 -21
  455. package/dist/powersync/exclusiveRuntime.js +0 -66
  456. package/dist/powersync/runtime.d.ts +0 -62
  457. package/dist/powersync/runtime.js +0 -358
  458. package/dist/powersync/schema/content.d.ts +0 -1
  459. package/dist/powersync/schema/content.js +0 -1
  460. package/dist/powersync/schema/electronCanonical.d.ts +0 -1561
  461. package/dist/powersync/schema/electronCanonical.js +0 -1154
  462. package/dist/powersync/schema/index.d.ts +0 -844
  463. package/dist/powersync/schema/index.js +0 -8
  464. package/dist/powersync/schema/local.d.ts +0 -13
  465. package/dist/powersync/schema/local.js +0 -24
  466. package/dist/powersync/schema/note.d.ts +0 -1
  467. package/dist/powersync/schema/note.js +0 -1
  468. package/dist/powersync/schema/notesExtras.d.ts +0 -1
  469. package/dist/powersync/schema/notesExtras.js +0 -1
  470. package/dist/powersync/schema/projects.d.ts +0 -1
  471. package/dist/powersync/schema/projects.js +0 -1
  472. package/dist/powersync/schema/savedViews.d.ts +0 -1
  473. package/dist/powersync/schema/savedViews.js +0 -1
  474. package/dist/powersync/schema/storage.d.ts +0 -1
  475. package/dist/powersync/schema/storage.js +0 -1
  476. package/dist/powersync/schema/tags.d.ts +0 -1
  477. package/dist/powersync/schema/tags.js +0 -1
  478. package/dist/powersync/syncGate.d.ts +0 -45
  479. package/dist/powersync/syncGate.js +0 -45
  480. package/dist/powersync/syncPass.d.ts +0 -9
  481. package/dist/powersync/syncPass.js +0 -33
  482. package/dist/powersync/tokenIndex.d.ts +0 -32
  483. package/dist/powersync/tokenIndex.js +0 -382
  484. package/dist/powersync/uploader.d.ts +0 -22
  485. package/dist/powersync/uploader.js +0 -231
  486. package/dist/requests/execute.d.ts +0 -11
  487. package/dist/requests/execute.js +0 -26
  488. package/dist/requests/store.d.ts +0 -10
  489. package/dist/requests/store.js +0 -190
  490. package/dist/runCli.d.ts +0 -2
  491. package/dist/runCli.js +0 -64
  492. package/dist/skills/check.d.ts +0 -7
  493. package/dist/skills/check.js +0 -747
  494. package/dist/skills/commandRefs.d.ts +0 -21
  495. package/dist/skills/commandRefs.js +0 -124
  496. package/dist/skills/generate.d.ts +0 -13
  497. package/dist/skills/generate.js +0 -80
  498. package/dist/skills/registry.d.ts +0 -13
  499. package/dist/skills/registry.js +0 -65
  500. package/dist/skills/retired.d.ts +0 -60
  501. package/dist/skills/retired.js +0 -58
  502. package/dist/utils/abort.d.ts +0 -6
  503. package/dist/utils/abort.js +0 -19
  504. package/dist/utils/argValue.d.ts +0 -1
  505. package/dist/utils/argValue.js +0 -18
  506. package/dist/utils/asyncRelease.d.ts +0 -2
  507. package/dist/utils/asyncRelease.js +0 -25
  508. package/dist/utils/authToken.d.ts +0 -4
  509. package/dist/utils/authToken.js +0 -28
  510. package/dist/utils/bidlinkCanonicalization.d.ts +0 -2
  511. package/dist/utils/bidlinkCanonicalization.js +0 -164
  512. package/dist/utils/consoleEncoding.d.ts +0 -5
  513. package/dist/utils/consoleEncoding.js +0 -27
  514. package/dist/utils/cursor.d.ts +0 -9
  515. package/dist/utils/cursor.js +0 -61
  516. package/dist/utils/deadline.d.ts +0 -8
  517. package/dist/utils/deadline.js +0 -31
  518. package/dist/utils/defaultFormat.d.ts +0 -8
  519. package/dist/utils/defaultFormat.js +0 -38
  520. package/dist/utils/dryRun.d.ts +0 -32
  521. package/dist/utils/dryRun.js +0 -88
  522. package/dist/utils/errorCodes.d.ts +0 -595
  523. package/dist/utils/errorCodes.js +0 -163
  524. package/dist/utils/errors.d.ts +0 -54
  525. package/dist/utils/errors.js +0 -277
  526. package/dist/utils/id.d.ts +0 -1
  527. package/dist/utils/id.js +0 -4
  528. package/dist/utils/nodeRuntime.d.ts +0 -4
  529. package/dist/utils/nodeRuntime.js +0 -12
  530. package/dist/utils/output.d.ts +0 -26
  531. package/dist/utils/output.js +0 -262
  532. package/dist/utils/processExit.d.ts +0 -1
  533. package/dist/utils/processExit.js +0 -33
  534. package/dist/utils/progress.d.ts +0 -25
  535. package/dist/utils/progress.js +0 -59
  536. package/dist/utils/redact.d.ts +0 -1
  537. package/dist/utils/redact.js +0 -10
  538. package/dist/utils/requestContext.d.ts +0 -32
  539. package/dist/utils/requestContext.js +0 -13
  540. package/dist/utils/select.d.ts +0 -20
  541. package/dist/utils/select.js +0 -92
  542. package/dist/utils/sqliteLease.d.ts +0 -8
  543. package/dist/utils/sqliteLease.js +0 -59
  544. package/dist/utils/syncTimeout.d.ts +0 -7
  545. package/dist/utils/syncTimeout.js +0 -20
  546. package/dist/utils/terminalSanitization.d.ts +0 -2
  547. package/dist/utils/terminalSanitization.js +0 -37
  548. package/dist/utils/text.d.ts +0 -1
  549. package/dist/utils/text.js +0 -35
  550. package/dist/utils/time.d.ts +0 -1
  551. package/dist/utils/time.js +0 -3
  552. package/dist/utils/tiptapMarkdown.d.ts +0 -9
  553. package/dist/utils/tiptapMarkdown.js +0 -381
  554. package/dist/utils/tiptapMarkdownSchema.d.ts +0 -37
  555. package/dist/utils/tiptapMarkdownSchema.js +0 -608
  556. package/dist/utils/tiptapMarkdownSchemaUtils.d.ts +0 -74
  557. package/dist/utils/tiptapMarkdownSchemaUtils.js +0 -394
  558. package/dist/utils/tiptapMarkdownSyntax.d.ts +0 -9
  559. package/dist/utils/tiptapMarkdownSyntax.js +0 -249
  560. package/dist/utils/tokenize.d.ts +0 -1
  561. package/dist/utils/tokenize.js +0 -67
  562. package/dist/utils/updateNotice.d.ts +0 -8
  563. package/dist/utils/updateNotice.js +0 -112
  564. package/dist/utils/usageError.d.ts +0 -37
  565. package/dist/utils/usageError.js +0 -127
  566. package/dist/utils/version.d.ts +0 -1
  567. package/dist/utils/version.js +0 -21
  568. package/dist/vendor/electron/domain/note-templates.d.ts +0 -3
  569. package/dist/vendor/electron/domain/note-templates.js +0 -232
  570. package/dist/vendor/electron/domain/properties.d.ts +0 -10
  571. package/dist/vendor/electron/domain/properties.js +0 -1549
  572. package/dist/vendor/electron/domain/saved-view-analytics.d.ts +0 -45
  573. package/dist/vendor/electron/domain/saved-view-analytics.js +0 -365
  574. package/dist/vendor/electron/domain/saved-view-relative-date.d.ts +0 -21
  575. package/dist/vendor/electron/domain/saved-view-relative-date.js +0 -153
  576. package/dist/vendor/electron/domain/saved-views.d.ts +0 -61
  577. package/dist/vendor/electron/domain/saved-views.js +0 -1120
  578. package/dist/vendor/electron/rpc.d.ts +0 -22
  579. package/dist/vendor/electron/rpc.js +0 -27
  580. package/dist/vendor/electron/shared/ai-errors.d.ts +0 -11
  581. package/dist/vendor/electron/shared/ai-errors.js +0 -107
  582. package/dist/vendor/electron/shared/external-types.d.ts +0 -20
  583. package/dist/vendor/electron/shared/external-types.js +0 -1
  584. package/dist/vendor/electron/shared/index.d.ts +0 -9
  585. package/dist/vendor/electron/shared/index.js +0 -7
  586. package/dist/vendor/electron/shared/note-properties.d.ts +0 -328
  587. package/dist/vendor/electron/shared/note-properties.js +0 -1027
  588. package/dist/vendor/electron/shared/note-templates.d.ts +0 -82
  589. package/dist/vendor/electron/shared/note-templates.js +0 -84
  590. package/dist/vendor/electron/shared/powersync-read-models.d.ts +0 -1716
  591. package/dist/vendor/electron/shared/powersync-read-models.js +0 -1
  592. package/dist/vendor/electron/shared/remote-device-agent.d.ts +0 -375
  593. package/dist/vendor/electron/shared/remote-device-agent.js +0 -191
  594. package/dist/vendor/electron/shared/saved-views.d.ts +0 -394
  595. package/dist/vendor/electron/shared/saved-views.js +0 -981
  596. package/dist/vendor/electron/shared/task-priority.d.ts +0 -42
  597. package/dist/vendor/electron/shared/task-priority.js +0 -186
  598. package/dist/vendor/electron/sql-utils.d.ts +0 -5
  599. package/dist/vendor/electron/sql-utils.js +0 -32
@@ -0,0 +1,1491 @@
1
+ import { createRequire as __dinoxCreateRequire } from 'node:module';
2
+ const require = __dinoxCreateRequire(import.meta.url);
3
+ import {
4
+ loadBrowserCookies,
5
+ loadBrowserCookiesForUrl
6
+ } from "./chunk-ULKGDBAJ.js";
7
+ import {
8
+ DOUBAN_HOST_RE,
9
+ applyWebSiteFixups,
10
+ buildWebMarkdown,
11
+ captureWebHtml,
12
+ convertWebContentHtmlToMarkdown,
13
+ detectBlockedInterstitial,
14
+ detectDirectLink,
15
+ detectDoubanLoginWall,
16
+ detectUnavailableAiShare,
17
+ detectUnsupportedDownloadLink,
18
+ downloadWebImages,
19
+ fetchDirectMedia,
20
+ isDoubanUrl,
21
+ parseWebHtml,
22
+ replaceWebMarkdownImageUrls
23
+ } from "./chunk-TILRKKRN.js";
24
+ import {
25
+ WebToMarkdownError
26
+ } from "./chunk-PTFGE4KS.js";
27
+ import {
28
+ detectWebCaptureBlock
29
+ } from "./chunk-N44NRKDJ.js";
30
+ import {
31
+ createProxyFetch
32
+ } from "./chunk-224ML7QC.js";
33
+ import {
34
+ summarizeImageFailures
35
+ } from "./chunk-5KU25TMX.js";
36
+ import {
37
+ isTransientError
38
+ } from "./chunk-QZQRG3JY.js";
39
+ import {
40
+ clipEngineConfig
41
+ } from "./chunk-F7BDWXBG.js";
42
+ import {
43
+ formatBeijingDateTime
44
+ } from "./chunk-AHRCI2RW.js";
45
+ import {
46
+ logInfo,
47
+ logWarn
48
+ } from "./chunk-KOAKG2QU.js";
49
+
50
+ // ../../packages/clip-engine/src/htmlParserRules/provider.ts
51
+ var provider = null;
52
+ function activeHtmlParserRules() {
53
+ return provider ? provider() : [];
54
+ }
55
+
56
+ // ../../packages/clip-engine/src/ideashellToMarkdown/index.ts
57
+ import * as cheerio from "cheerio";
58
+ import { Marked } from "marked";
59
+ var IDEASHELL_USER_AGENT = "rasp-api/1.0 (ideashell share clipper)";
60
+ var TIMEOUT_MS = 3e4;
61
+ var MAX_MARKDOWN_BYTES = 5e6;
62
+ function parseIdeashellShareUrl(url) {
63
+ let parsed;
64
+ try {
65
+ parsed = new URL(url);
66
+ } catch {
67
+ return null;
68
+ }
69
+ if (!/^app\.ideashell\.(?:cn|com)$/i.test(parsed.hostname)) return null;
70
+ if (!/^\/note\/share\/?$/.test(parsed.pathname)) return null;
71
+ const shareId = parsed.searchParams.get("id")?.trim() ?? "";
72
+ if (!/^[A-Za-z0-9_-]{6,64}$/.test(shareId)) return null;
73
+ return { canonicalUrl: `https://${parsed.hostname.toLowerCase()}/note/share?id=${shareId}`, shareId };
74
+ }
75
+ function isIdeashellShareUrl(url) {
76
+ return parseIdeashellShareUrl(url) !== null;
77
+ }
78
+ function parseIdeashellSharePage(html) {
79
+ const $ = cheerio.load(html);
80
+ const title = ($('meta[property="og:title"]').attr("content") || $("title").first().text() || "").trim();
81
+ const description = ($('meta[name="description"]').attr("content") ?? "").trim();
82
+ const query = /\{type:"([a-z_]+)",url:"((?:[^"\\]|\\.)*)"/.exec(html);
83
+ const contentType = query?.[1] ?? "";
84
+ const markdownUrl = query ? safeMarkdownUrl(decodeJsString(query[2] ?? "")) : "";
85
+ return { contentType, description, markdownUrl, title };
86
+ }
87
+ async function fetchIdeashellNote(url, options = {}) {
88
+ const link = parseIdeashellShareUrl(url);
89
+ if (!link) throw new WebToMarkdownError("INVALID_WEB_URL", "expected an app.ideashell.cn/note/share?id= URL", { url });
90
+ const page = parseIdeashellSharePage(await fetchText(link.canonicalUrl, options, link, "share page"));
91
+ if (page.contentType && page.contentType !== "markdown" && !page.description) {
92
+ throw new WebToMarkdownError("UNSUPPORTED_CONTENT_TYPE", `ideashell ${page.contentType} shares are not text notes`, {
93
+ shareId: link.shareId
94
+ });
95
+ }
96
+ let markdown = "";
97
+ if (page.contentType === "markdown" && page.markdownUrl) {
98
+ try {
99
+ markdown = await fetchText(page.markdownUrl, options, link, "note markdown");
100
+ } catch (error) {
101
+ if (!page.description) throw error;
102
+ }
103
+ }
104
+ markdown = (markdown.trim() || page.description).trim();
105
+ if (!markdown) {
106
+ throw new WebToMarkdownError("CONTENT_NOT_FOUND", "ideashell share has no note content (expired or private)", {
107
+ shareId: link.shareId
108
+ });
109
+ }
110
+ const body = stripLeadingTitle(markdown, page.title);
111
+ const $ = cheerio.load(noteMarked.parse(body, { async: false }));
112
+ $("script, style, iframe, object, embed").remove();
113
+ const imageUrls = [];
114
+ $("img").each((_, element) => {
115
+ const src = ($(element).attr("src") ?? "").trim();
116
+ if (/^https?:\/\//i.test(src)) imageUrls.push(src);
117
+ else $(element).remove();
118
+ });
119
+ const contentHtml = ($("body").html() ?? "").trim();
120
+ if (!$("body").text().trim() && imageUrls.length === 0) {
121
+ throw new WebToMarkdownError("CONTENT_NOT_FOUND", "ideashell note is empty", { shareId: link.shareId });
122
+ }
123
+ return {
124
+ contentHtml,
125
+ imageUrls: Array.from(new Set(imageUrls)),
126
+ metadata: {
127
+ // The anonymous share payload has no author or note time.
128
+ author: "",
129
+ description: "",
130
+ publishTime: "",
131
+ site: "ideaShell",
132
+ sourceUrl: link.canonicalUrl,
133
+ title: page.title || firstHeading(markdown) || "ideaShell"
134
+ }
135
+ };
136
+ }
137
+ var noteMarked = new Marked({ breaks: true, gfm: true });
138
+ function stripLeadingTitle(markdown, title) {
139
+ const match = /^\s*#\s+(.+?)\s*#*\s*(?:\n|$)/.exec(markdown);
140
+ if (!match) return markdown;
141
+ const heading = collapse(match[1] ?? "");
142
+ if (title && heading !== collapse(title)) return markdown;
143
+ return markdown.slice(match[0].length).replace(/^\s+/, "");
144
+ }
145
+ function firstHeading(markdown) {
146
+ return /^\s*#\s+(.+?)\s*#*\s*(?:\n|$)/.exec(markdown)?.[1]?.trim() ?? "";
147
+ }
148
+ function collapse(value) {
149
+ return value.replace(/\s+/g, "");
150
+ }
151
+ function decodeJsString(value) {
152
+ return value.replace(
153
+ /\\u([0-9a-fA-F]{4})|\\(.)/g,
154
+ (_, hex, ch) => hex ? String.fromCharCode(Number.parseInt(hex, 16)) : ch ?? ""
155
+ );
156
+ }
157
+ function safeMarkdownUrl(value) {
158
+ let parsed;
159
+ try {
160
+ parsed = new URL(value);
161
+ } catch {
162
+ return "";
163
+ }
164
+ if (parsed.protocol !== "https:") return "";
165
+ if (!/(?:^|\.)ideashell[\w-]*\.cos\.[\w-]+\.myqcloud\.com$|(?:^|\.)ideashell\.(?:cn|com)$/i.test(parsed.hostname)) return "";
166
+ return parsed.toString();
167
+ }
168
+ async function fetchText(url, options, link, what) {
169
+ const controller = new AbortController();
170
+ const timer = setTimeout(() => controller.abort(), TIMEOUT_MS);
171
+ const onAbort = () => controller.abort();
172
+ options.signal?.addEventListener("abort", onAbort, { once: true });
173
+ try {
174
+ const response = await (options.fetcher ?? fetch)(url, {
175
+ headers: { "user-agent": IDEASHELL_USER_AGENT },
176
+ redirect: "follow",
177
+ signal: controller.signal
178
+ });
179
+ if (response.status === 404 || response.status === 410) {
180
+ throw new WebToMarkdownError("CONTENT_NOT_FOUND", `ideashell ${what}: HTTP ${response.status}, share not found`, {
181
+ shareId: link.shareId
182
+ });
183
+ }
184
+ if (response.status === 403 || response.status === 429) {
185
+ throw new WebToMarkdownError("CAPTURE_BLOCKED", `ideashell ${what}: HTTP ${response.status}`, {
186
+ shareId: link.shareId,
187
+ status: response.status
188
+ });
189
+ }
190
+ if (!response.ok) {
191
+ throw new WebToMarkdownError("CAPTURE_FAILED", `ideashell ${what} failed (HTTP ${response.status})`, {
192
+ shareId: link.shareId,
193
+ status: response.status
194
+ });
195
+ }
196
+ const text = await response.text();
197
+ if (Buffer.byteLength(text, "utf8") > MAX_MARKDOWN_BYTES) {
198
+ throw new WebToMarkdownError("HTML_TOO_LARGE", `ideashell ${what} is too large`, { shareId: link.shareId });
199
+ }
200
+ return text;
201
+ } finally {
202
+ clearTimeout(timer);
203
+ options.signal?.removeEventListener("abort", onAbort);
204
+ }
205
+ }
206
+
207
+ // ../../packages/clip-engine/src/lingowhaleToMarkdown/index.ts
208
+ var API_BASE = "https://api-public.lingowhale.com";
209
+ var TIMEOUT_MS2 = 3e4;
210
+ var LINGOWHALE_USER_AGENT = "rasp-api/1.0 (lingowhale share clipper)";
211
+ var UNSUPPORTED_SCENES = /* @__PURE__ */ new Map([
212
+ [10, "channel"],
213
+ [11, "channel list"],
214
+ [12, "topic"],
215
+ [13, "daily digest"]
216
+ ]);
217
+ function parseLingowhaleShareUrl(url) {
218
+ let parsed;
219
+ try {
220
+ parsed = new URL(url);
221
+ } catch {
222
+ return null;
223
+ }
224
+ if (!/^(?:h5\.|www\.)?lingowhale\.com$/i.test(parsed.hostname)) return null;
225
+ const match = /^\/s\/([A-Za-z0-9_-]{4,64})\/?$/.exec(parsed.pathname);
226
+ if (!match) return null;
227
+ return { canonicalUrl: `https://h5.lingowhale.com/s/${match[1]}`, shareId: match[1] };
228
+ }
229
+ function isLingowhaleShareUrl(url) {
230
+ return parseLingowhaleShareUrl(url) !== null;
231
+ }
232
+ async function fetchLingowhaleEntry(url, options = {}) {
233
+ const link = parseLingowhaleShareUrl(url);
234
+ if (!link) throw new WebToMarkdownError("INVALID_WEB_URL", "expected a lingowhale.com/s/{shareId} URL", { url });
235
+ const share = await postJson("/api/lingowhale/v1/share/link/get", { share_id: link.shareId }, options, link);
236
+ const scene = Number(share?.share_scene ?? 0);
237
+ const unsupported = UNSUPPORTED_SCENES.get(scene);
238
+ if (unsupported) {
239
+ throw new WebToMarkdownError("UNSUPPORTED_CONTENT_TYPE", `lingowhale ${unsupported} shares are not articles`, {
240
+ scene,
241
+ shareId: link.shareId
242
+ });
243
+ }
244
+ const entryId = share?.multi_id ? share.first_entry_id : share?.entry_id;
245
+ const entryType = share?.multi_id ? share.first_entry_type : share?.entry_type;
246
+ if (!entryId || entryType === void 0) {
247
+ throw new WebToMarkdownError("CONTENT_NOT_FOUND", "lingowhale share link expired or has no article", {
248
+ shareId: link.shareId
249
+ });
250
+ }
251
+ const detail = await postJson(
252
+ "/api/lingowhale/v1/entry_detail/get",
253
+ { entry_id: entryId, entry_type: entryType },
254
+ options,
255
+ link
256
+ );
257
+ const resource = detail?.resource;
258
+ const html = (resource?.html ?? "").replace(/<\/?dplv-pos(?:-group)?\b[^>]*>/gi, "").trim() || textToHtml(resource?.content ?? "");
259
+ if (!resource || !html) {
260
+ throw new WebToMarkdownError("CONTENT_NOT_FOUND", "lingowhale article has no content", { entryId, shareId: link.shareId });
261
+ }
262
+ return {
263
+ html,
264
+ metadata: {
265
+ author: (resource.author?.name ?? "").trim(),
266
+ description: (resource.description ?? "").trim(),
267
+ publishTime: resource.pub_time ? formatBeijingDateTime(new Date(resource.pub_time * 1e3)) : "",
268
+ site: "Lingowhale",
269
+ sourceUrl: link.canonicalUrl,
270
+ title: (resource.title ?? "").trim()
271
+ },
272
+ origUrl: (resource.orig_url ?? "").trim()
273
+ };
274
+ }
275
+ async function postJson(path, body, options, link) {
276
+ const controller = new AbortController();
277
+ const timer = setTimeout(() => controller.abort(), TIMEOUT_MS2);
278
+ const onAbort = () => controller.abort();
279
+ options.signal?.addEventListener("abort", onAbort, { once: true });
280
+ try {
281
+ const response = await (options.fetcher ?? fetch)(`${API_BASE}${path}`, {
282
+ body: JSON.stringify(body),
283
+ headers: { "content-type": "application/json", "user-agent": LINGOWHALE_USER_AGENT },
284
+ method: "POST",
285
+ signal: controller.signal
286
+ });
287
+ if (!response.ok) {
288
+ throw new WebToMarkdownError("CAPTURE_FAILED", `lingowhale ${path} failed (HTTP ${response.status})`, {
289
+ shareId: link.shareId,
290
+ status: response.status
291
+ });
292
+ }
293
+ const payload = await response.json();
294
+ if (payload.code !== 0) {
295
+ throw new WebToMarkdownError(
296
+ "CONTENT_NOT_FOUND",
297
+ `lingowhale share unavailable (code ${String(payload.code)}${payload.msg ? `: ${payload.msg}` : ""})`,
298
+ { shareId: link.shareId }
299
+ );
300
+ }
301
+ return payload.data;
302
+ } finally {
303
+ clearTimeout(timer);
304
+ options.signal?.removeEventListener("abort", onAbort);
305
+ }
306
+ }
307
+ function textToHtml(text) {
308
+ const escape = (s) => s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
309
+ return text.split(/\n+/).map((line) => line.trim()).filter(Boolean).map((line) => `<p>${escape(line)}</p>`).join("\n");
310
+ }
311
+
312
+ // ../../packages/clip-engine/src/lookiToMarkdown/index.ts
313
+ import * as cheerio2 from "cheerio";
314
+ import { Marked as Marked2 } from "marked";
315
+ var LOOKI_USER_AGENT = "rasp-api/1.0 (looki share clipper)";
316
+ var TIMEOUT_MS3 = 3e4;
317
+ var MAX_HTML_BYTES = 5e6;
318
+ function parseLookiShareUrl(url) {
319
+ let parsed;
320
+ try {
321
+ parsed = new URL(url);
322
+ } catch {
323
+ return null;
324
+ }
325
+ if (!/^https?:$/.test(parsed.protocol) || !/^web\.looki\.tech$/i.test(parsed.hostname)) return null;
326
+ const match = /^\/share\/journal\/([A-Za-z0-9_-]{8,64})\/?$/.exec(parsed.pathname);
327
+ if (!match?.[1]) return null;
328
+ return { canonicalUrl: `https://web.looki.tech/share/journal/${match[1]}`, shareId: match[1] };
329
+ }
330
+ function isLookiShareUrl(url) {
331
+ return parseLookiShareUrl(url) !== null;
332
+ }
333
+ function readNextFlight(html) {
334
+ const $ = cheerio2.load(html);
335
+ let flight = "";
336
+ $("script").each((_, element) => {
337
+ const code = $(element).text();
338
+ const re = /self\.__next_f\.push\((\[[\s\S]*?\])\)\s*;?\s*$/;
339
+ const match = re.exec(code.trim());
340
+ if (!match?.[1]) return;
341
+ try {
342
+ const chunk = JSON.parse(match[1]);
343
+ if (Array.isArray(chunk) && chunk[0] === 1 && typeof chunk[1] === "string") flight += chunk[1];
344
+ } catch {
345
+ }
346
+ });
347
+ return flight;
348
+ }
349
+ function parseLookiSharePage(html) {
350
+ const flight = readNextFlight(html);
351
+ for (const row of flight.split("\n")) {
352
+ if (!row.includes('"data":{"success"')) continue;
353
+ const colon = row.indexOf(":");
354
+ if (colon < 0) continue;
355
+ let value;
356
+ try {
357
+ value = JSON.parse(row.slice(colon + 1));
358
+ } catch {
359
+ continue;
360
+ }
361
+ const data = findJournalData(value);
362
+ if (!data) continue;
363
+ return {
364
+ content: resolveFlightText(flight, data.content),
365
+ description: typeof data.description === "string" ? unescapeFlightString(data.description).trim() : "",
366
+ recordedAt: typeof data.recordedAt === "number" && Number.isFinite(data.recordedAt) ? data.recordedAt : null,
367
+ success: data.success === true,
368
+ title: typeof data.title === "string" ? unescapeFlightString(data.title).trim() : ""
369
+ };
370
+ }
371
+ return null;
372
+ }
373
+ async function fetchLookiJournal(url, options = {}) {
374
+ const link = parseLookiShareUrl(url);
375
+ if (!link) throw new WebToMarkdownError("INVALID_WEB_URL", "expected a web.looki.tech/share/journal/ URL", { url });
376
+ const data = parseLookiSharePage(await fetchSharePage(link, options));
377
+ const markdown = (data?.content ?? "").trim();
378
+ if (!data || !data.success || !markdown) {
379
+ throw new WebToMarkdownError("CONTENT_NOT_FOUND", "looki share has no journal content (expired or private)", {
380
+ shareId: link.shareId
381
+ });
382
+ }
383
+ const title = data.title || firstHeading2(markdown);
384
+ const body = stripLeadingTitle2(markdown, title);
385
+ const $ = cheerio2.load(journalMarked.parse(body, { async: false }));
386
+ $("script, style, iframe, object, embed").remove();
387
+ const imageUrls = [];
388
+ $("img").each((_, element) => {
389
+ const src = ($(element).attr("src") ?? "").trim();
390
+ if (/^https?:\/\//i.test(src)) imageUrls.push(src);
391
+ else $(element).remove();
392
+ });
393
+ const contentHtml = ($("body").html() ?? "").trim();
394
+ if (!$("body").text().trim() && imageUrls.length === 0) {
395
+ throw new WebToMarkdownError("CONTENT_NOT_FOUND", "looki journal is empty", { shareId: link.shareId });
396
+ }
397
+ return {
398
+ contentHtml,
399
+ imageUrls: Array.from(new Set(imageUrls)),
400
+ metadata: {
401
+ // The payload's author is an opaque account id, not a display name.
402
+ author: "",
403
+ description: data.description,
404
+ publishTime: data.recordedAt ? formatBeijingDateTime(new Date(data.recordedAt)) : "",
405
+ site: "Looki",
406
+ sourceUrl: link.canonicalUrl,
407
+ title: title || "Looki"
408
+ }
409
+ };
410
+ }
411
+ var journalMarked = new Marked2({ gfm: true });
412
+ function findJournalData(value, depth = 0) {
413
+ if (depth > 8 || !value || typeof value !== "object") return null;
414
+ if (Array.isArray(value)) {
415
+ for (const item of value) {
416
+ const found = findJournalData(item, depth + 1);
417
+ if (found) return found;
418
+ }
419
+ return null;
420
+ }
421
+ const record = value;
422
+ const data = record.data;
423
+ if (data && typeof data === "object" && !Array.isArray(data) && "success" in data && "content" in data) {
424
+ return data;
425
+ }
426
+ for (const child of Object.values(record)) {
427
+ const found = findJournalData(child, depth + 1);
428
+ if (found) return found;
429
+ }
430
+ return null;
431
+ }
432
+ function resolveFlightText(flight, value) {
433
+ if (typeof value !== "string") return "";
434
+ const ref = /^\$([0-9a-f]+)$/.exec(value);
435
+ if (!ref) return unescapeFlightString(value);
436
+ const row = new RegExp(`(?:^|\\n)${ref[1]}:T([0-9a-f]+),`).exec(flight);
437
+ if (!row?.[1]) return "";
438
+ const start = row.index + row[0].length;
439
+ const bytes = Number.parseInt(row[1], 16);
440
+ return Buffer.from(flight.slice(start), "utf8").subarray(0, bytes).toString("utf8");
441
+ }
442
+ function unescapeFlightString(value) {
443
+ return value.startsWith("$$") ? value.slice(1) : value;
444
+ }
445
+ function stripLeadingTitle2(markdown, title) {
446
+ const match = /^\s*#\s+(.+?)\s*#*\s*(?:\n|$)/.exec(markdown);
447
+ if (!match) return markdown;
448
+ if (title && collapse2(match[1] ?? "") !== collapse2(title)) return markdown;
449
+ return markdown.slice(match[0].length).replace(/^\s+/, "");
450
+ }
451
+ function firstHeading2(markdown) {
452
+ return /^\s*#\s+(.+?)\s*#*\s*(?:\n|$)/.exec(markdown)?.[1]?.trim() ?? "";
453
+ }
454
+ function collapse2(value) {
455
+ return value.replace(/\s+/g, "");
456
+ }
457
+ async function fetchSharePage(link, options) {
458
+ const controller = new AbortController();
459
+ const timer = setTimeout(() => controller.abort(), TIMEOUT_MS3);
460
+ const onAbort = () => controller.abort();
461
+ options.signal?.addEventListener("abort", onAbort, { once: true });
462
+ try {
463
+ const response = await (options.fetcher ?? fetch)(link.canonicalUrl, {
464
+ headers: { "user-agent": LOOKI_USER_AGENT },
465
+ redirect: "follow",
466
+ signal: controller.signal
467
+ });
468
+ if (response.status === 404 || response.status === 410) {
469
+ throw new WebToMarkdownError("CONTENT_NOT_FOUND", `looki share page: HTTP ${response.status}, share not found`, {
470
+ shareId: link.shareId
471
+ });
472
+ }
473
+ if (response.status === 403 || response.status === 429) {
474
+ throw new WebToMarkdownError("CAPTURE_BLOCKED", `looki share page: HTTP ${response.status}`, {
475
+ shareId: link.shareId,
476
+ status: response.status
477
+ });
478
+ }
479
+ if (!response.ok) {
480
+ throw new WebToMarkdownError("CAPTURE_FAILED", `looki share page failed (HTTP ${response.status})`, {
481
+ shareId: link.shareId,
482
+ status: response.status
483
+ });
484
+ }
485
+ const text = await response.text();
486
+ if (Buffer.byteLength(text, "utf8") > MAX_HTML_BYTES) {
487
+ throw new WebToMarkdownError("HTML_TOO_LARGE", "looki share page is too large", { shareId: link.shareId });
488
+ }
489
+ return text;
490
+ } finally {
491
+ clearTimeout(timer);
492
+ options.signal?.removeEventListener("abort", onAbort);
493
+ }
494
+ }
495
+
496
+ // ../../packages/clip-engine/src/notionToMarkdown/errors.ts
497
+ var NotionToMarkdownError = class extends Error {
498
+ code;
499
+ details;
500
+ constructor(code, message, details) {
501
+ super(message);
502
+ this.name = "NotionToMarkdownError";
503
+ this.code = code;
504
+ if (details !== void 0) this.details = details;
505
+ }
506
+ };
507
+
508
+ // ../../packages/clip-engine/src/notionToMarkdown/api.ts
509
+ var API_BASE2 = "https://www.notion.so/api/v3";
510
+ var CHUNK_LIMIT = 100;
511
+ var MAX_CHUNKS = 8;
512
+ var MAX_SYNC_ROUNDS = 4;
513
+ var SYNC_BATCH = 100;
514
+ var TIMEOUT_MS4 = 3e4;
515
+ var NOTION_USER_AGENT = "rasp-api/1.0 (notion public page clipper)";
516
+ async function loadNotionPage(pageId, options = {}) {
517
+ const blocks = /* @__PURE__ */ new Map();
518
+ const collectionNames = /* @__PURE__ */ new Map();
519
+ let cursor = { stack: [] };
520
+ for (let chunkNumber = 0; chunkNumber < MAX_CHUNKS; chunkNumber += 1) {
521
+ const response = await postJson2(
522
+ "loadCachedPageChunk",
523
+ { page: { id: pageId }, limit: CHUNK_LIMIT, cursor, chunkNumber, verticalColumns: false },
524
+ options
525
+ );
526
+ addBlocks(blocks, response.recordMap?.block);
527
+ addCollectionNames(collectionNames, response.recordMap?.collection);
528
+ const stack = response.cursor?.stack;
529
+ if (!Array.isArray(stack) || stack.length === 0) break;
530
+ cursor = response.cursor;
531
+ }
532
+ const page = blocks.get(pageId);
533
+ if (!page) {
534
+ throw new NotionToMarkdownError(
535
+ "CONTENT_NOT_FOUND",
536
+ "notion page is not public: share it to the web (\u516C\u5F00\u5206\u4EAB) before clipping",
537
+ { pageId }
538
+ );
539
+ }
540
+ for (let round = 0; round < MAX_SYNC_ROUNDS; round += 1) {
541
+ const missing = [...collectReferencedIds(blocks)].filter((id) => !blocks.has(id));
542
+ if (!missing.length) break;
543
+ for (let index = 0; index < missing.length; index += SYNC_BATCH) {
544
+ const ids = missing.slice(index, index + SYNC_BATCH);
545
+ const response = await postJson2(
546
+ "syncRecordValues",
547
+ { requests: ids.map((id) => ({ pointer: { table: "block", id }, version: -1 })) },
548
+ options
549
+ );
550
+ addBlocks(blocks, response.recordMap?.block);
551
+ for (const id of ids) if (!blocks.has(id)) blocks.set(id, { id, type: "__missing__" });
552
+ }
553
+ }
554
+ return { blocks, collectionNames, pageId };
555
+ }
556
+ function addCollectionNames(target, records) {
557
+ for (const [id, record] of Object.entries(records ?? {})) {
558
+ const name = unwrapValue(record)?.name;
559
+ if (Array.isArray(name)) target.set(id, name.map((part) => Array.isArray(part) ? String(part[0] ?? "") : "").join(""));
560
+ }
561
+ }
562
+ function addBlocks(target, records) {
563
+ for (const [id, record] of Object.entries(records ?? {})) {
564
+ const value = unwrapValue(record);
565
+ if (value && typeof value.type === "string") target.set(id, value);
566
+ }
567
+ }
568
+ function unwrapValue(record) {
569
+ let value = record?.value;
570
+ if (value && typeof value === "object" && "value" in value && typeof value.value === "object") {
571
+ value = value.value;
572
+ }
573
+ return value && typeof value === "object" ? value : null;
574
+ }
575
+ function collectReferencedIds(blocks) {
576
+ const ids = /* @__PURE__ */ new Set();
577
+ for (const block of blocks.values()) {
578
+ if (block.type === "__missing__" || block.alive === false) continue;
579
+ if (block.type === "page" || block.type.startsWith("collection_view")) continue;
580
+ for (const child of block.content ?? []) ids.add(child);
581
+ const pointer = block.format?.transclusion_reference_pointer?.id;
582
+ if (pointer) ids.add(pointer);
583
+ }
584
+ return ids;
585
+ }
586
+ async function postJson2(endpoint, body, options) {
587
+ const controller = new AbortController();
588
+ const timer = setTimeout(() => controller.abort(), TIMEOUT_MS4);
589
+ const onAbort = () => controller.abort();
590
+ options.signal?.addEventListener("abort", onAbort, { once: true });
591
+ try {
592
+ const response = await (options.fetcher ?? fetch)(`${API_BASE2}/${endpoint}`, {
593
+ body: JSON.stringify(body),
594
+ headers: { "content-type": "application/json", "user-agent": NOTION_USER_AGENT },
595
+ method: "POST",
596
+ signal: controller.signal
597
+ });
598
+ if (!response.ok) {
599
+ throw new NotionToMarkdownError("FETCH_FAILED", `notion ${endpoint} failed (HTTP ${response.status})`, {
600
+ status: response.status
601
+ });
602
+ }
603
+ return await response.json();
604
+ } finally {
605
+ clearTimeout(timer);
606
+ options.signal?.removeEventListener("abort", onAbort);
607
+ }
608
+ }
609
+
610
+ // ../../packages/clip-engine/src/notionToMarkdown/render.ts
611
+ var LIST_TYPES = /* @__PURE__ */ new Set(["bulleted_list", "numbered_list", "to_do"]);
612
+ var MAX_DEPTH = 12;
613
+ function renderNotionPage(record) {
614
+ const page = record.blocks.get(record.pageId);
615
+ const ctx = { blocks: record.blocks, collectionNames: record.collectionNames, imageUrls: [], rendering: /* @__PURE__ */ new Set([record.pageId]), rootId: record.pageId };
616
+ const contentHtml = renderChildren(page?.content ?? [], ctx, 0);
617
+ return {
618
+ contentHtml,
619
+ createdTime: typeof page?.created_time === "number" ? page.created_time : null,
620
+ editedTime: typeof page?.last_edited_time === "number" ? page.last_edited_time : null,
621
+ imageUrls: ctx.imageUrls,
622
+ title: plainText(page?.properties?.title).trim()
623
+ };
624
+ }
625
+ function renderChildren(ids, ctx, depth) {
626
+ if (depth > MAX_DEPTH) return "";
627
+ const out = [];
628
+ let index = 0;
629
+ while (index < ids.length) {
630
+ const block = ctx.blocks.get(ids[index]);
631
+ if (block && LIST_TYPES.has(block.type)) {
632
+ const type = block.type;
633
+ const items = [];
634
+ while (index < ids.length && ctx.blocks.get(ids[index])?.type === type) {
635
+ items.push(ctx.blocks.get(ids[index]));
636
+ index += 1;
637
+ }
638
+ out.push(renderList(type, items, ctx, depth));
639
+ continue;
640
+ }
641
+ if (block) out.push(renderBlock(block, ctx, depth));
642
+ index += 1;
643
+ }
644
+ return out.filter(Boolean).join("\n");
645
+ }
646
+ function renderList(type, items, ctx, depth) {
647
+ const tag = type === "numbered_list" ? "ol" : "ul";
648
+ const lis = items.map((item) => {
649
+ const box = type === "to_do" ? `<input type="checkbox"${isChecked(item) ? " checked" : ""}> ` : "";
650
+ const children = item.content?.length ? renderChildren(item.content, ctx, depth + 1) : "";
651
+ return `<li>${box}${richText(item.properties?.title, ctx)}${children}</li>`;
652
+ });
653
+ return `<${tag}>${lis.join("")}</${tag}>`;
654
+ }
655
+ function renderBlock(block, ctx, depth) {
656
+ if (block.alive === false || ctx.rendering.has(block.id)) return "";
657
+ ctx.rendering.add(block.id);
658
+ try {
659
+ return renderBlockInner(block, ctx, depth);
660
+ } finally {
661
+ ctx.rendering.delete(block.id);
662
+ }
663
+ }
664
+ function renderBlockInner(block, ctx, depth) {
665
+ const title = richText(block.properties?.title, ctx);
666
+ const children = () => block.content?.length ? renderChildren(block.content, ctx, depth + 1) : "";
667
+ switch (block.type) {
668
+ case "text":
669
+ return (title ? `<p>${title}</p>` : "") + children();
670
+ case "header":
671
+ return `<h2>${title}</h2>${children()}`;
672
+ case "sub_header":
673
+ return `<h3>${title}</h3>${children()}`;
674
+ case "sub_sub_header":
675
+ return `<h4>${title}</h4>${children()}`;
676
+ case "quote":
677
+ return `<blockquote><p>${title}</p>${children()}</blockquote>`;
678
+ case "callout": {
679
+ const icon = typeof block.format?.page_icon === "string" && !block.format.page_icon.startsWith("http") ? `${escapeHtml(block.format.page_icon)} ` : "";
680
+ return `<blockquote><p>${icon}${title}</p>${children()}</blockquote>`;
681
+ }
682
+ case "toggle":
683
+ return `<p><strong>\u25B8 ${title}</strong></p>${children()}`;
684
+ case "code": {
685
+ const language = plainText(block.properties?.language).toLowerCase().replace(/[^a-z0-9+#-]/g, "");
686
+ const code = escapeHtml(plainText(block.properties?.title));
687
+ return `<pre><code${language && language !== "plain-text" ? ` class="language-${language}"` : ""}>${code}</code></pre>`;
688
+ }
689
+ case "divider":
690
+ return "<hr>";
691
+ case "equation":
692
+ return `<p>$$${escapeHtml(plainText(block.properties?.title))}$$</p>`;
693
+ case "image":
694
+ return renderImage(block, ctx);
695
+ case "table":
696
+ return renderTable(block, ctx);
697
+ case "bookmark":
698
+ case "embed":
699
+ case "video":
700
+ case "audio":
701
+ case "file":
702
+ case "pdf":
703
+ case "figma":
704
+ case "tweet":
705
+ case "maps":
706
+ case "codepen":
707
+ case "gist":
708
+ case "drive":
709
+ case "typeform":
710
+ case "excalidraw":
711
+ case "replit":
712
+ return renderLinkBlock(block, ctx);
713
+ case "external_object_instance": {
714
+ const uri = typeof block.format?.uri === "string" ? block.format.uri : "";
715
+ return uri ? `<p><a href="${escapeHtml(uri)}">${escapeHtml(uri)}</a></p>` : "";
716
+ }
717
+ case "page":
718
+ case "alias": {
719
+ const target = block.type === "alias" ? aliasTarget(block, ctx) : block;
720
+ if (!target) return "";
721
+ const name = plainText(target.properties?.title).trim() || "Untitled";
722
+ return `<p>\u{1F4C4} <a href="${notionPageUrl(target.id)}">${escapeHtml(name)}</a></p>`;
723
+ }
724
+ case "collection_view":
725
+ case "collection_view_page": {
726
+ const pointer = block.format?.collection_pointer;
727
+ const name = pointer?.id && ctx.collectionNames.get(pointer.id) || "\u6570\u636E\u5E93";
728
+ const href = notionPageUrl(block.type === "collection_view_page" ? block.id : ctx.rootId);
729
+ return `<p>\u{1F4CA} ${escapeHtml(name)}\uFF08Notion \u6570\u636E\u5E93\u89C6\u56FE\u6682\u4E0D\u652F\u6301\u526A\u85CF\uFF0C\u8BF7\u6253\u5F00\u539F\u6587\u67E5\u770B\uFF1A<a href="${href}">${href}</a>\uFF09</p>`;
730
+ }
731
+ case "transclusion_reference": {
732
+ const id = block.format?.transclusion_reference_pointer?.id;
733
+ const source = id ? ctx.blocks.get(id) : void 0;
734
+ return source ? renderBlock(source, ctx, depth + 1) : "";
735
+ }
736
+ case "column_list":
737
+ case "column":
738
+ case "transclusion_container":
739
+ return children();
740
+ case "table_of_contents":
741
+ case "breadcrumb":
742
+ case "button":
743
+ case "__missing__":
744
+ return "";
745
+ default:
746
+ return (title ? `<p>${title}</p>` : "") + children();
747
+ }
748
+ }
749
+ function renderImage(block, ctx) {
750
+ const source = plainText(block.properties?.source) || (typeof block.format?.display_source === "string" ? block.format.display_source : "");
751
+ const url = notionImageUrl(source, block);
752
+ if (!url) return "";
753
+ ctx.imageUrls.push(url);
754
+ const caption = richText(block.properties?.caption, ctx);
755
+ return `<p><img src="${escapeHtml(url)}" alt=""></p>${caption ? `<p>${caption}</p>` : ""}`;
756
+ }
757
+ function renderTable(block, ctx) {
758
+ const order = block.format?.table_block_column_order ?? [];
759
+ const rows = (block.content ?? []).map((id) => ctx.blocks.get(id)).filter((row) => row?.type === "table_row");
760
+ if (!order.length || !rows.length) return "";
761
+ const header = block.format?.table_block_column_header === true;
762
+ const html = rows.map((row, index) => {
763
+ const tag = header && index === 0 ? "th" : "td";
764
+ return `<tr>${order.map((column) => `<${tag}>${richText(row.properties?.[column], ctx)}</${tag}>`).join("")}</tr>`;
765
+ });
766
+ if (header) return `<table><thead>${html[0]}</thead><tbody>${html.slice(1).join("")}</tbody></table>`;
767
+ return `<table><tbody>${html.join("")}</tbody></table>`;
768
+ }
769
+ function renderLinkBlock(block, ctx) {
770
+ const link = plainText(block.properties?.link) || plainText(block.properties?.source) || (typeof block.format?.display_source === "string" ? block.format.display_source : "");
771
+ if (!link) return "";
772
+ const href = /^https?:\/\//i.test(link) ? link : notionImageUrl(link, block);
773
+ const label = plainText(block.properties?.title).trim() || link;
774
+ const caption = richText(block.properties?.caption, ctx);
775
+ return `<p><a href="${escapeHtml(href)}">${escapeHtml(label)}</a></p>${caption ? `<p>${caption}</p>` : ""}`;
776
+ }
777
+ function aliasTarget(block, ctx) {
778
+ const pointer = block.format?.alias_pointer;
779
+ return pointer?.id ? ctx.blocks.get(pointer.id) : void 0;
780
+ }
781
+ function notionImageUrl(source, block) {
782
+ if (!source) return "";
783
+ if (source.startsWith("data:")) return "";
784
+ if (source.startsWith("/")) return `https://www.notion.so${source}`;
785
+ const isNotionFile = /^attachment:/i.test(source) || /(secure\.notion-static\.com|prod-files-secure|notion-static\.com|amazonaws\.com\/.*notion)/i.test(source);
786
+ if (!isNotionFile) return source;
787
+ return `https://www.notion.so/image/${encodeURIComponent(source)}?table=block&id=${block.id}&cache=v2`;
788
+ }
789
+ function notionPageUrl(id) {
790
+ return `https://www.notion.so/${id.replace(/-/g, "")}`;
791
+ }
792
+ function isChecked(block) {
793
+ return plainText(block.properties?.checked).trim().toLowerCase() === "yes";
794
+ }
795
+ function plainText(value) {
796
+ if (!Array.isArray(value)) return "";
797
+ return value.map((segment) => Array.isArray(segment) ? String(segment[0] ?? "") : "").join("");
798
+ }
799
+ function richText(value, ctx) {
800
+ if (!Array.isArray(value)) return "";
801
+ return value.map((segment) => {
802
+ if (!Array.isArray(segment)) return "";
803
+ const [text, marks = []] = segment;
804
+ return applyMarks(String(text ?? ""), Array.isArray(marks) ? marks : [], ctx);
805
+ }).join("");
806
+ }
807
+ function applyMarks(text, marks, ctx) {
808
+ let html = escapeHtml(text).replace(/\n/g, "<br>");
809
+ let code = false;
810
+ let link = "";
811
+ for (const mark of marks) {
812
+ const [kind, arg] = mark;
813
+ switch (kind) {
814
+ case "p": {
815
+ const id = typeof arg === "string" ? arg : "";
816
+ const target = id ? ctx.blocks.get(id) : void 0;
817
+ html = escapeHtml(plainText(target?.properties?.title).trim() || "Notion \u9875\u9762");
818
+ if (id) link = notionPageUrl(id);
819
+ break;
820
+ }
821
+ case "d": {
822
+ const date = arg;
823
+ if (date?.start_date) html = escapeHtml(date.end_date ? `${date.start_date} \u2192 ${date.end_date}` : date.start_date);
824
+ break;
825
+ }
826
+ case "e":
827
+ html = `$${escapeHtml(typeof arg === "string" ? arg : text)}$`;
828
+ break;
829
+ case "u":
830
+ html = html === "\u2023" ? "@\u7528\u6237" : html;
831
+ break;
832
+ case "a":
833
+ if (typeof arg === "string") link = arg.startsWith("/") ? `https://www.notion.so${arg}` : arg;
834
+ break;
835
+ case "c":
836
+ code = true;
837
+ break;
838
+ default:
839
+ break;
840
+ }
841
+ }
842
+ if (code) html = `<code>${html}</code>`;
843
+ for (const [kind] of marks) {
844
+ if (kind === "b") html = `<strong>${html}</strong>`;
845
+ else if (kind === "i") html = `<em>${html}</em>`;
846
+ else if (kind === "s") html = `<del>${html}</del>`;
847
+ }
848
+ if (link) html = `<a href="${escapeHtml(link)}">${html}</a>`;
849
+ return html;
850
+ }
851
+ function escapeHtml(value) {
852
+ return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
853
+ }
854
+
855
+ // ../../packages/clip-engine/src/notionToMarkdown/url.ts
856
+ var HOST_RE = /(^|\.)notion\.(so|site|com)$/i;
857
+ var ID_RE = /([0-9a-f]{32}|[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/i;
858
+ function parseNotionLink(raw) {
859
+ let url;
860
+ try {
861
+ url = new URL(raw);
862
+ } catch {
863
+ return null;
864
+ }
865
+ if (!/^https?:$/.test(url.protocol) || !HOST_RE.test(url.hostname)) return null;
866
+ const peek = url.searchParams.get("p") ?? "";
867
+ const lastSegment = url.pathname.split("/").filter(Boolean).pop() ?? "";
868
+ const match = ID_RE.exec(peek) ?? ID_RE.exec(lastSegment);
869
+ if (!match) return null;
870
+ const pageId = toUuid(match[1]);
871
+ const canonical = new URL(url.origin + url.pathname);
872
+ if (peek && ID_RE.test(peek)) canonical.searchParams.set("p", peek);
873
+ return { canonicalUrl: canonical.toString(), pageId };
874
+ }
875
+ function isNotionPageUrl(raw) {
876
+ return parseNotionLink(raw) !== null;
877
+ }
878
+ function toUuid(id) {
879
+ const hex = id.replace(/-/g, "").toLowerCase();
880
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
881
+ }
882
+
883
+ // ../../packages/clip-engine/src/notionToMarkdown/index.ts
884
+ async function fetchNotionWebPage(url, options = {}) {
885
+ const link = parseNotionLink(url);
886
+ if (!link) throw new NotionToMarkdownError("INVALID_NOTION_URL", "expected a Notion page URL with a page id", { url });
887
+ const record = await loadNotionPage(link.pageId, options);
888
+ const rendered = renderNotionPage(record);
889
+ if (!rendered.contentHtml.replace(/<[^>]+>/g, "").trim() && !rendered.imageUrls.length) {
890
+ throw new NotionToMarkdownError("CONTENT_NOT_FOUND", "notion page has no readable content", { pageId: link.pageId });
891
+ }
892
+ const time = rendered.createdTime ?? rendered.editedTime;
893
+ return {
894
+ contentHtml: rendered.contentHtml,
895
+ imageUrls: rendered.imageUrls,
896
+ metadata: {
897
+ // Anonymous API responses carry no author identity.
898
+ author: "",
899
+ description: "",
900
+ publishTime: time ? formatBeijingDateTime(new Date(time)) : "",
901
+ site: "Notion",
902
+ sourceUrl: link.canonicalUrl,
903
+ title: rendered.title || "Untitled"
904
+ }
905
+ };
906
+ }
907
+
908
+ // ../../packages/clip-engine/src/v2exToMarkdown/index.ts
909
+ import * as cheerio3 from "cheerio";
910
+ var ORIGIN = "https://www.v2ex.com";
911
+ var TIMEOUT_MS5 = 3e4;
912
+ var V2EX_USER_AGENT = "rasp-api/1.0 (v2ex topic clipper)";
913
+ var SITE_NAME = "V2EX";
914
+ var HOST_RE2 = /^(?:(?!cdn\.)[a-z0-9-]+\.)?v2ex\.com$/i;
915
+ var TOPIC_PATH_RE = /^\/(?:amp\/)?t\/(\d{1,10})\/?$/;
916
+ function parseV2exTopicUrl(url) {
917
+ let parsed;
918
+ try {
919
+ parsed = new URL(url);
920
+ } catch {
921
+ return null;
922
+ }
923
+ if (!/^https?:$/.test(parsed.protocol) || !HOST_RE2.test(parsed.hostname)) return null;
924
+ const id = TOPIC_PATH_RE.exec(parsed.pathname)?.[1];
925
+ if (!id) return null;
926
+ return { canonicalUrl: `${ORIGIN}/t/${id}`, id };
927
+ }
928
+ function isV2exTopicUrl(url) {
929
+ return parseV2exTopicUrl(url) !== null;
930
+ }
931
+ async function fetchV2exTopic(url, options = {}) {
932
+ const link = parseV2exTopicUrl(url);
933
+ if (!link) throw new WebToMarkdownError("INVALID_WEB_URL", "expected a v2ex.com/t/{id} URL", { url });
934
+ const page = await request(link.canonicalUrl, "text/html", options);
935
+ if (/\/signin\b/.test(page.finalUrl)) {
936
+ throw new WebToMarkdownError("LOGIN_WALL", "V2EX topic is only visible to signed-in members", { id: link.id });
937
+ }
938
+ if (!isChallenged(page)) {
939
+ if (page.status === 404) throw notFound(link);
940
+ assertOk(page, link);
941
+ const topic = parseV2exTopicHtml(page.body, link.canonicalUrl);
942
+ if (topic) return topic;
943
+ }
944
+ return await fetchFromApi(link, options);
945
+ }
946
+ function parseV2exTopicHtml(html, sourceUrl) {
947
+ const $ = cheerio3.load(html);
948
+ const header = $("#Main .box .header").first();
949
+ const title = header.find("h1").first().text().trim();
950
+ if (!title) return null;
951
+ const meta = header.find("small.gray").first();
952
+ const author = meta.find('a[href^="/member/"]').first().text().trim();
953
+ const created = meta.find("span[title]").first().attr("title") ?? "";
954
+ const box = header.closest(".box");
955
+ const main = box.find(".topic_content").filter((_index, element) => $(element).closest(".subtle").length === 0).first();
956
+ const blocks = [];
957
+ const mainHtml = (main.find(".markdown_body").first().html() ?? main.html() ?? "").trim();
958
+ if (mainHtml) blocks.push(mainHtml);
959
+ box.find(".subtle").each((index, element) => {
960
+ const subtle = $(element);
961
+ const body = (subtle.find(".topic_content").first().html() ?? "").trim();
962
+ if (!body) return;
963
+ const time = formatV2exTime(subtle.find(".fade span[title]").first().attr("title") ?? "");
964
+ blocks.push(`<h2>\u9644\u8A00 ${index + 1}${time ? ` \xB7 ${time}` : ""}</h2>`, `<div>${body}</div>`);
965
+ });
966
+ return buildTopic({
967
+ author,
968
+ blocks,
969
+ publishTime: formatV2exTime(created),
970
+ source: "html",
971
+ sourceUrl,
972
+ title
973
+ });
974
+ }
975
+ async function fetchFromApi(link, options) {
976
+ const response = await request(`${ORIGIN}/api/topics/show.json?id=${link.id}`, "application/json", options);
977
+ if (isChallenged(response)) {
978
+ throw new WebToMarkdownError("CAPTURE_BLOCKED", "capture blocked: cloudflare-challenge", {
979
+ id: link.id,
980
+ reason: "cloudflare-challenge"
981
+ });
982
+ }
983
+ if (response.status === 404) throw notFound(link);
984
+ assertOk(response, link);
985
+ let topics;
986
+ try {
987
+ topics = JSON.parse(response.body);
988
+ } catch {
989
+ throw new WebToMarkdownError("CAPTURE_FAILED", "V2EX API returned invalid JSON", { id: link.id });
990
+ }
991
+ const topic = Array.isArray(topics) ? topics[0] : void 0;
992
+ const title = (topic?.title ?? "").trim();
993
+ if (!topic || !title) throw notFound(link);
994
+ return buildTopic({
995
+ author: (topic.member?.username ?? "").trim(),
996
+ blocks: [(topic.content_rendered ?? "").trim()].filter(Boolean),
997
+ publishTime: topic.created ? formatBeijingDateTime(new Date(topic.created * 1e3)) : "",
998
+ source: "api",
999
+ sourceUrl: link.canonicalUrl,
1000
+ title
1001
+ });
1002
+ }
1003
+ function buildTopic(input) {
1004
+ const $ = cheerio3.load(`<div id="v2ex-topic">${input.blocks.join("\n")}</div>`);
1005
+ const root = $("#v2ex-topic");
1006
+ const imageUrls = [];
1007
+ root.find("img").each((_index, element) => {
1008
+ const image = $(element);
1009
+ const src = absolutize(image.attr("src") ?? "");
1010
+ if (!src) {
1011
+ image.remove();
1012
+ return;
1013
+ }
1014
+ image.attr("src", src);
1015
+ imageUrls.push(src);
1016
+ });
1017
+ root.find("a[href]").each((_index, element) => {
1018
+ const href = absolutize($(element).attr("href") ?? "");
1019
+ if (href) $(element).attr("href", href);
1020
+ });
1021
+ return {
1022
+ contentHtml: (root.html() ?? "").trim(),
1023
+ imageUrls: Array.from(new Set(imageUrls)),
1024
+ metadata: {
1025
+ author: input.author,
1026
+ description: "",
1027
+ publishTime: input.publishTime,
1028
+ site: SITE_NAME,
1029
+ sourceUrl: input.sourceUrl,
1030
+ title: input.title
1031
+ },
1032
+ source: input.source
1033
+ };
1034
+ }
1035
+ function formatV2exTime(value) {
1036
+ const match = /^(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2}) ([+-]\d{2}:\d{2})$/.exec(value.trim());
1037
+ if (!match) return "";
1038
+ const date = /* @__PURE__ */ new Date(`${match[1]}T${match[2]}${match[3]}`);
1039
+ return Number.isNaN(date.getTime()) ? "" : formatBeijingDateTime(date);
1040
+ }
1041
+ function absolutize(value) {
1042
+ const trimmed = value.trim();
1043
+ if (!trimmed || /^(?:javascript|data):/i.test(trimmed)) return "";
1044
+ try {
1045
+ const url = new URL(trimmed, ORIGIN);
1046
+ return /^https?:$/.test(url.protocol) ? url.toString() : "";
1047
+ } catch {
1048
+ return "";
1049
+ }
1050
+ }
1051
+ function isChallenged(response) {
1052
+ if (response.status !== 403 && response.status !== 503) return false;
1053
+ return detectWebCaptureBlock({ html: response.body }).reason === "cloudflare-challenge" || /<title>\s*Just a moment/i.test(response.body);
1054
+ }
1055
+ function assertOk(response, link) {
1056
+ if (response.status >= 200 && response.status < 300) return;
1057
+ throw new WebToMarkdownError("CAPTURE_FAILED", `V2EX request failed (HTTP ${response.status})`, {
1058
+ id: link.id,
1059
+ status: response.status
1060
+ });
1061
+ }
1062
+ function notFound(link) {
1063
+ return new WebToMarkdownError("CONTENT_NOT_FOUND", "V2EX topic not found (deleted, or in a members-only node)", {
1064
+ id: link.id
1065
+ });
1066
+ }
1067
+ async function request(url, accept, options) {
1068
+ const controller = new AbortController();
1069
+ const timer = setTimeout(() => controller.abort(), TIMEOUT_MS5);
1070
+ const onAbort = () => controller.abort();
1071
+ options.signal?.addEventListener("abort", onAbort, { once: true });
1072
+ try {
1073
+ const response = await (options.fetcher ?? fetch)(url, {
1074
+ headers: { accept, "accept-language": "zh-CN,zh;q=0.9,en;q=0.8", "user-agent": V2EX_USER_AGENT },
1075
+ redirect: "follow",
1076
+ signal: controller.signal
1077
+ });
1078
+ return { body: await response.text(), finalUrl: response.url || url, status: response.status };
1079
+ } finally {
1080
+ clearTimeout(timer);
1081
+ options.signal?.removeEventListener("abort", onAbort);
1082
+ }
1083
+ }
1084
+
1085
+ // ../../packages/clip-engine/src/yuqueToMarkdown/index.ts
1086
+ var ORIGIN2 = "https://www.yuque.com";
1087
+ var TIMEOUT_MS6 = 3e4;
1088
+ var YUQUE_USER_AGENT = "rasp-api/1.0 (yuque doc clipper)";
1089
+ var SITE_NAME2 = "\u8BED\u96C0";
1090
+ var RESERVED_LOGINS = /* @__PURE__ */ new Set([
1091
+ "api",
1092
+ "attachments",
1093
+ "dashboard",
1094
+ "explore",
1095
+ "help",
1096
+ "login",
1097
+ "logout",
1098
+ "r",
1099
+ "register",
1100
+ "search",
1101
+ "settings"
1102
+ ]);
1103
+ function parseYuqueDocUrl(url) {
1104
+ let parsed;
1105
+ try {
1106
+ parsed = new URL(url);
1107
+ } catch {
1108
+ return null;
1109
+ }
1110
+ if (!/^(?:www\.)?yuque\.com$/i.test(parsed.hostname)) return null;
1111
+ const match = /^\/([A-Za-z0-9_.-]{1,64})\/([A-Za-z0-9_.-]{1,64})\/([A-Za-z0-9_-]{2,64})\/?$/.exec(parsed.pathname);
1112
+ if (!match) return null;
1113
+ const [, login, book, slug] = match;
1114
+ if (RESERVED_LOGINS.has(login.toLowerCase())) return null;
1115
+ return { book, canonicalUrl: `${ORIGIN2}/${login}/${book}/${slug}`, login, slug };
1116
+ }
1117
+ function isYuqueDocUrl(url) {
1118
+ return parseYuqueDocUrl(url) !== null;
1119
+ }
1120
+ async function fetchYuqueDoc(url, options = {}) {
1121
+ const link = parseYuqueDocUrl(url);
1122
+ if (!link) throw new WebToMarkdownError("INVALID_WEB_URL", "expected a yuque.com/{login}/{book}/{slug} URL", { url });
1123
+ const doc = readAppDataDoc(await request2(link.canonicalUrl, "text/html", options, link));
1124
+ if (!doc?.book_id) {
1125
+ throw new WebToMarkdownError("LOGIN_WALL", "Yuque doc is not public (the page has no readable doc; it needs login)", {
1126
+ slug: link.slug
1127
+ });
1128
+ }
1129
+ const body = await request2(
1130
+ `${ORIGIN2}/api/docs/${encodeURIComponent(link.slug)}?book_id=${doc.book_id}&merge_dynamic_data=false`,
1131
+ "application/json",
1132
+ options,
1133
+ link
1134
+ );
1135
+ const data = parseApiDoc(body);
1136
+ const title = (data?.title || doc.title || "").trim();
1137
+ const html = dropLeadingTitleHeading(convertLakeCards(data?.content ?? "").trim(), title);
1138
+ if (!data || !html) throw new WebToMarkdownError("CONTENT_NOT_FOUND", "Yuque doc has no content", { slug: link.slug });
1139
+ const published = data.published_at || data.first_published_at || "";
1140
+ const publishedAt = published ? new Date(published) : null;
1141
+ return {
1142
+ // A whole document with the body in <article>, so the shared web parser
1143
+ // (Defuddle) treats it as the main content.
1144
+ html: `<!DOCTYPE html><html><head><meta charset="utf-8"><title>${escapeText(title)}</title></head><body><article>${html}</article></body></html>`,
1145
+ metadata: {
1146
+ author: (data.user?.name ?? "").trim(),
1147
+ description: (data.description ?? "").trim(),
1148
+ publishTime: publishedAt && !Number.isNaN(publishedAt.getTime()) ? formatBeijingDateTime(publishedAt) : "",
1149
+ site: SITE_NAME2,
1150
+ sourceUrl: link.canonicalUrl,
1151
+ title
1152
+ }
1153
+ };
1154
+ }
1155
+ function dropLeadingTitleHeading(html, title) {
1156
+ const match = /^(?:<p>\s*(?:<span>\s*)?(?:<br\s*\/?>\s*)?(?:<\/span>\s*)?<\/p>\s*)*<h1\b[^>]*>([\s\S]*?)<\/h1>/i.exec(html);
1157
+ if (!match) return html;
1158
+ const heading = textOf(match[1] ?? "");
1159
+ if (!heading || !title || !textOf(title).endsWith(heading)) return html;
1160
+ return html.slice(match[0].length).trim();
1161
+ }
1162
+ function textOf(html) {
1163
+ return html.replace(/<[^>]+>/g, "").replace(/&nbsp;/g, " ").replace(/\s+/g, " ").trim();
1164
+ }
1165
+ function parseApiDoc(body) {
1166
+ try {
1167
+ return JSON.parse(body).data;
1168
+ } catch {
1169
+ return void 0;
1170
+ }
1171
+ }
1172
+ function readAppDataDoc(html) {
1173
+ const match = /window\.appData\s*=\s*JSON\.parse\(decodeURIComponent\("([^"]*)"\)\)/.exec(html);
1174
+ if (!match) return null;
1175
+ try {
1176
+ const appData = JSON.parse(decodeURIComponent(match[1]));
1177
+ return appData.doc ?? null;
1178
+ } catch {
1179
+ return null;
1180
+ }
1181
+ }
1182
+ function convertLakeCards(html) {
1183
+ return html.replace(/<card\b([^>]*)>(?:\s*<\/card>)?/gi, (_match, attrs) => {
1184
+ const name = /\bname="([^"]*)"/i.exec(attrs)?.[1] ?? "";
1185
+ const value = readCardValue(/\bvalue="([^"]*)"/i.exec(attrs)?.[1] ?? "");
1186
+ if (name === "image" && typeof value.src === "string" && /^https?:\/\//i.test(value.src)) {
1187
+ const alt = typeof value.title === "string" && value.title.trim() ? value.title.trim() : "\u56FE\u7247";
1188
+ return `<img src="${escapeAttr(value.src)}" alt="${escapeAttr(alt)}">`;
1189
+ }
1190
+ if (name === "codeblock" && typeof value.code === "string") {
1191
+ const lang = typeof value.mode === "string" && /^[\w+#-]{1,32}$/.test(value.mode) ? ` class="language-${value.mode}"` : "";
1192
+ return `<pre><code${lang}>${escapeText(value.code)}</code></pre>`;
1193
+ }
1194
+ if (name === "hr") return "<hr>";
1195
+ return "";
1196
+ }).replace(/\s(?:data-lake-id|id)="[^"]*"/g, "");
1197
+ }
1198
+ function readCardValue(raw) {
1199
+ if (!raw.startsWith("data:")) return {};
1200
+ try {
1201
+ const value = JSON.parse(decodeURIComponent(raw.slice("data:".length)));
1202
+ return value && typeof value === "object" ? value : {};
1203
+ } catch {
1204
+ return {};
1205
+ }
1206
+ }
1207
+ function escapeAttr(value) {
1208
+ return value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;");
1209
+ }
1210
+ function escapeText(value) {
1211
+ return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
1212
+ }
1213
+ async function request2(url, accept, options, link) {
1214
+ const controller = new AbortController();
1215
+ const timer = setTimeout(() => controller.abort(), TIMEOUT_MS6);
1216
+ const onAbort = () => controller.abort();
1217
+ options.signal?.addEventListener("abort", onAbort, { once: true });
1218
+ try {
1219
+ const response = await (options.fetcher ?? fetch)(url, {
1220
+ headers: { accept, "user-agent": YUQUE_USER_AGENT },
1221
+ redirect: "follow",
1222
+ signal: controller.signal
1223
+ });
1224
+ if (response.status === 401 || response.status === 403) {
1225
+ throw new WebToMarkdownError("LOGIN_WALL", `Yuque doc is not public (HTTP ${response.status}); it needs login`, {
1226
+ slug: link.slug,
1227
+ status: response.status
1228
+ });
1229
+ }
1230
+ if (response.status === 404) {
1231
+ throw new WebToMarkdownError("CONTENT_NOT_FOUND", "Yuque doc not found (deleted or moved)", { slug: link.slug });
1232
+ }
1233
+ if (!response.ok) {
1234
+ throw new WebToMarkdownError("CAPTURE_FAILED", `Yuque request failed (HTTP ${response.status})`, {
1235
+ slug: link.slug,
1236
+ status: response.status
1237
+ });
1238
+ }
1239
+ return await response.text();
1240
+ } finally {
1241
+ clearTimeout(timer);
1242
+ options.signal?.removeEventListener("abort", onAbort);
1243
+ }
1244
+ }
1245
+
1246
+ // ../../packages/clip-engine/src/clip/web.ts
1247
+ var DIRECT_CAPTURE_TIMEOUT_MS = 45e3;
1248
+ async function extractWebClip(url, ctx) {
1249
+ const { captureTimeoutMs, media, proxies } = clipEngineConfig();
1250
+ logInfo("web.runner", "run.start", {
1251
+ proxy: Boolean(proxies.web),
1252
+ timeoutMs: captureTimeoutMs,
1253
+ url,
1254
+ workDir: ctx.workDir
1255
+ });
1256
+ const directKind = detectDirectLink(url);
1257
+ const unsupportedFile = directKind === "file" ? detectUnsupportedDownloadLink(url) : null;
1258
+ if (unsupportedFile) throw new WebToMarkdownError("UNSUPPORTED_CONTENT_TYPE", unsupportedFile.reason, { url });
1259
+ if (directKind) {
1260
+ const outcome = await fetchDirectLink(url, ctx);
1261
+ if (outcome.kind === "media") return directMediaDocument(url, outcome.media);
1262
+ }
1263
+ const parsed = await loadWebPage(url, ctx.signal ? { signal: ctx.signal } : {});
1264
+ const blocked = detectBlockedInterstitial({ sourceUrl: parsed.metadata.sourceUrl });
1265
+ if (blocked) {
1266
+ throw new WebToMarkdownError("CAPTURE_BLOCKED", blocked.message, {
1267
+ reason: blocked.reason,
1268
+ sourceUrl: parsed.metadata.sourceUrl,
1269
+ url
1270
+ });
1271
+ }
1272
+ if (parsed.extraction.strategy === "defuddle" && parsed.extraction.fallbacks.length > 0) {
1273
+ const failedRule = parsed.extraction.fallbacks[0];
1274
+ logWarn("web.runner", "parser_rule.fallback", {
1275
+ code: failedRule?.code,
1276
+ message: failedRule?.message,
1277
+ revision: failedRule?.revision,
1278
+ ruleKey: failedRule?.key,
1279
+ url: parsed.metadata.sourceUrl
1280
+ });
1281
+ }
1282
+ const fixed = applyWebSiteFixups(parsed.metadata, convertWebContentHtmlToMarkdown(parsed.contentHtml));
1283
+ const unavailable = detectUnavailableAiShare({
1284
+ bodyMarkdown: fixed.bodyMarkdown,
1285
+ requestedUrl: url,
1286
+ sourceUrl: fixed.metadata.sourceUrl
1287
+ });
1288
+ if (unavailable) {
1289
+ throw new WebToMarkdownError("CONTENT_NOT_FOUND", unavailable.message, {
1290
+ platform: unavailable.platform,
1291
+ reason: unavailable.reason,
1292
+ sourceUrl: fixed.metadata.sourceUrl,
1293
+ url
1294
+ });
1295
+ }
1296
+ const referer = originOf(parsed.metadata.sourceUrl);
1297
+ const imageAssets = await downloadWebImages({
1298
+ concurrency: media.imageConcurrency,
1299
+ imageDir: ctx.workDir,
1300
+ imagePathPrefix: "images",
1301
+ imageUrls: parsed.imageUrls,
1302
+ maxImageBytes: media.maxImageBytes,
1303
+ // Notion images go through www.notion.so/image, behind the same
1304
+ // Cloudflare check as the page API.
1305
+ ...parsed.extraction.strategy === "notion_api" ? { referer: "https://www.notion.so", userAgent: NOTION_USER_AGENT } : referer ? { referer } : {},
1306
+ ...proxies.web ? { proxyFetcher: createProxyFetch(proxies.web) } : {},
1307
+ retries: media.downloadRetries
1308
+ });
1309
+ if (imageAssets.failed.length > 0) {
1310
+ logWarn("web.runner", "image.download.partial", {
1311
+ downloaded: imageAssets.downloaded.length,
1312
+ failed: imageAssets.failed.length,
1313
+ ...summarizeImageFailures(imageAssets.failed)
1314
+ });
1315
+ }
1316
+ const metadata = fixed.metadata;
1317
+ logInfo("web.runner", "extract.ok", {
1318
+ extractionStrategy: parsed.extraction.strategy,
1319
+ images: imageAssets.downloaded.length,
1320
+ parserRule: parsed.extraction.strategy === "html_parser_rule" ? parsed.extraction.key : null,
1321
+ site: metadata.site,
1322
+ title: metadata.title
1323
+ });
1324
+ return {
1325
+ author: metadata.author,
1326
+ extraction: parsed.extraction,
1327
+ markdown: buildWebMarkdown(metadata, replaceWebMarkdownImageUrls(fixed.bodyMarkdown, imageAssets.urlMap)),
1328
+ publishTime: metadata.publishTime,
1329
+ rawMarkdown: buildWebMarkdown(metadata, fixed.bodyMarkdown),
1330
+ sourceUrl: metadata.sourceUrl,
1331
+ title: metadata.title
1332
+ };
1333
+ }
1334
+ async function loadWebPage(url, options = {}) {
1335
+ if (isNotionPageUrl(url)) {
1336
+ const page = await fetchNotionWebPage(url);
1337
+ return { ...page, extraction: { strategy: "notion_api" } };
1338
+ }
1339
+ if (isIdeashellShareUrl(url)) {
1340
+ const note = await fetchIdeashellNote(url);
1341
+ return { ...note, extraction: { strategy: "ideashell_share" } };
1342
+ }
1343
+ if (isLookiShareUrl(url)) {
1344
+ const journal = await fetchLookiJournal(url);
1345
+ return { ...journal, extraction: { strategy: "looki_share" } };
1346
+ }
1347
+ if (isV2exTopicUrl(url)) {
1348
+ const { source, ...topic } = await fetchV2exTopic(url, options.signal ? { signal: options.signal } : {});
1349
+ return { ...topic, extraction: { source, strategy: "v2ex_topic" } };
1350
+ }
1351
+ if (isYuqueDocUrl(url)) {
1352
+ const doc = await fetchYuqueDoc(url);
1353
+ return await parseApiPage(doc.html, doc.metadata);
1354
+ }
1355
+ if (isLingowhaleShareUrl(url)) {
1356
+ const entry = await fetchLingowhaleEntry(url);
1357
+ return await parseApiPage(entry.html, entry.metadata);
1358
+ }
1359
+ const { captureTimeoutMs, proxies } = clipEngineConfig();
1360
+ const cookies = await siteCookiesFor(url);
1361
+ const capture = await captureWebWithProxyFallback(url, {
1362
+ ...cookies.length ? { cookies } : {},
1363
+ ...proxies.web ? { proxy: proxies.web } : {},
1364
+ timeoutMs: captureTimeoutMs
1365
+ });
1366
+ if (detectDoubanLoginWall({ finalUrl: capture.finalUrl || capture.url, requestedUrl: url, title: capture.title })) {
1367
+ throw new WebToMarkdownError(
1368
+ "LOGIN_WALL",
1369
+ cookies.length ? "Douban requires login: the configured Douban cookie was rejected (likely expired); refresh DOUBAN_COOKIES_FILE" : "Douban requires login: no Douban cookie configured (set DOUBAN_COOKIES_FILE)",
1370
+ { url }
1371
+ );
1372
+ }
1373
+ return await parseWebHtml(capture.html, {
1374
+ parserRules: activeHtmlParserRules(),
1375
+ ...capture.rawHtml ? { rawHtml: capture.rawHtml } : {},
1376
+ sourceUrl: capture.finalUrl || capture.url
1377
+ });
1378
+ }
1379
+ async function parseApiPage(html, apiMetadata) {
1380
+ const parsed = await parseWebHtml(html, {
1381
+ parserRules: activeHtmlParserRules(),
1382
+ sourceUrl: apiMetadata.sourceUrl
1383
+ });
1384
+ const metadata = { ...parsed.metadata };
1385
+ for (const key of ["author", "description", "publishTime", "title"]) {
1386
+ if (apiMetadata[key]) metadata[key] = apiMetadata[key];
1387
+ }
1388
+ metadata.site = apiMetadata.site;
1389
+ metadata.sourceUrl = apiMetadata.sourceUrl;
1390
+ return { ...parsed, metadata };
1391
+ }
1392
+ async function captureWebWithProxyFallback(url, options, capture = captureWebHtml) {
1393
+ const { proxy, timeoutMs } = options;
1394
+ const extra = options.cookies?.length ? { cookies: options.cookies } : {};
1395
+ if (!proxy) {
1396
+ return capture(url, { ...extra, timeoutMs });
1397
+ }
1398
+ try {
1399
+ return await capture(url, { ...extra, timeoutMs: Math.min(timeoutMs, DIRECT_CAPTURE_TIMEOUT_MS) });
1400
+ } catch (error) {
1401
+ if (!isTransientError(error)) throw error;
1402
+ logWarn("web.runner", "capture.proxy.fallback", {
1403
+ message: error instanceof Error ? error.message.slice(0, 200) : String(error),
1404
+ url
1405
+ });
1406
+ return capture(url, { ...extra, launchOptions: { proxy }, timeoutMs });
1407
+ }
1408
+ }
1409
+ async function siteCookiesFor(url) {
1410
+ const files = clipEngineConfig().cookiesFiles;
1411
+ if (isDoubanUrl(url) && files.douban) {
1412
+ const jar2 = await loadBrowserCookies(files.douban, DOUBAN_HOST_RE);
1413
+ if (jar2.cookies.length === 0) logWarn("web.runner", "douban.cookies.empty", { file: files.douban });
1414
+ else {
1415
+ logInfo("web.runner", "douban.cookies.loaded", { count: jar2.cookies.length });
1416
+ return jar2.cookies;
1417
+ }
1418
+ }
1419
+ if (!files.web) return [];
1420
+ const jar = await loadBrowserCookiesForUrl(files.web, url);
1421
+ if (jar.cookies.length > 0) logInfo("web.runner", "cookies.loaded", { count: jar.cookies.length });
1422
+ return jar.cookies;
1423
+ }
1424
+ async function fetchDirectLink(url, ctx) {
1425
+ const { media, proxies } = clipEngineConfig();
1426
+ const base = {
1427
+ maxBytes: media.maxVideoBytes,
1428
+ mediaDir: ctx.workDir,
1429
+ ...ctx.signal ? { signal: ctx.signal } : {},
1430
+ url
1431
+ };
1432
+ try {
1433
+ return await fetchDirectMedia(base);
1434
+ } catch (error) {
1435
+ const stalled = error instanceof WebToMarkdownError && error.code === "MEDIA_STALLED";
1436
+ const proxy = proxies.web;
1437
+ if (!proxy || !(stalled || isTransientError(error)) || /xhscdn\.com$/i.test(hostOf(url))) throw error;
1438
+ logWarn("web.runner", "direct_media.proxy.fallback", {
1439
+ message: error instanceof Error ? error.message.slice(0, 200) : String(error),
1440
+ url
1441
+ });
1442
+ return await fetchDirectMedia({ ...base, fetcher: createProxyFetch(proxy) });
1443
+ }
1444
+ }
1445
+ function directMediaDocument(url, media) {
1446
+ const metadata = {
1447
+ author: "",
1448
+ description: "",
1449
+ publishTime: "",
1450
+ site: hostOf(url),
1451
+ sourceUrl: url,
1452
+ title: media.fileName
1453
+ };
1454
+ const markdown = buildWebMarkdown(metadata, "");
1455
+ logInfo("web.runner", "direct_media.success", {
1456
+ bytes: media.bytes,
1457
+ contentType: media.contentType,
1458
+ kind: media.type,
1459
+ url
1460
+ });
1461
+ return {
1462
+ author: "",
1463
+ extraction: { strategy: "direct_media" },
1464
+ markdown,
1465
+ primaryMedia: media.type === "audio" ? { ...media, type: "audio" } : { ...media, type: "video" },
1466
+ publishTime: "",
1467
+ rawMarkdown: markdown,
1468
+ sourceUrl: url,
1469
+ title: media.fileName
1470
+ };
1471
+ }
1472
+ function hostOf(url) {
1473
+ try {
1474
+ return new URL(url).hostname;
1475
+ } catch {
1476
+ return "";
1477
+ }
1478
+ }
1479
+ function originOf(url) {
1480
+ try {
1481
+ return new URL(url).origin;
1482
+ } catch {
1483
+ return "";
1484
+ }
1485
+ }
1486
+
1487
+ export {
1488
+ extractWebClip,
1489
+ loadWebPage,
1490
+ captureWebWithProxyFallback
1491
+ };