nx-kv 0.48.2 → 0.50.0

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 (309) hide show
  1. package/CHANGELOG.md +85 -0
  2. package/README.md +103 -216
  3. package/assets/groups.json +1 -1
  4. package/assets/kv-get/SKILL.md +1 -1
  5. package/assets/kv-get/references/localget.md +2 -2
  6. package/assets/kv-get/references/timegoal-workflow.md +3 -3
  7. package/assets/kv-get/references/timegoal.md +1 -1
  8. package/assets/kv-get/references/wait-workflow.md +2 -3
  9. package/assets/kv-get/references/waitloop.md +3 -3
  10. package/assets/kv-repo/SKILL.md +1 -1
  11. package/assets/kv-submit/SKILL.md +3 -3
  12. package/assets/nx-kv/SKILL.md +111 -76
  13. package/assets/nx-kv/references/agent-workflow.md +58 -47
  14. package/assets/nx-kv/references/localtask-commands.md +179 -0
  15. package/package.json +3 -4
  16. package/src/core/attachmentdb/bodies.ts +193 -0
  17. package/src/core/attachmentdb/docs.ts +158 -33
  18. package/src/core/attachmentdb/ids.ts +27 -1
  19. package/src/core/attachmentdb/mdfile.ts +249 -0
  20. package/src/core/attachmentdb/query.ts +14 -1
  21. package/src/core/attachmentdb/resources.ts +28 -2
  22. package/src/core/attachmentdb.ts +27 -0
  23. package/src/core/config.ts +13 -133
  24. package/src/core/db/bootstrap.ts +5 -5
  25. package/src/core/db/import-json/refs.ts +27 -13
  26. package/src/core/db/migrations/index.ts +9 -0
  27. package/src/core/db/migrations/v2-data.ts +4 -4
  28. package/src/core/db/migrations/v5.sql +100 -0
  29. package/src/core/db/migrations/v6-data.ts +261 -0
  30. package/src/core/db/migrations/v6.sql +67 -0
  31. package/src/core/db/migrations/v7.sql +8 -0
  32. package/src/core/db/seed-templates.ts +3 -1
  33. package/src/core/db/version.ts +12 -1
  34. package/src/core/filekind.ts +95 -0
  35. package/src/core/instruction-template.ts +6 -4
  36. package/src/core/localatt.ts +3 -6
  37. package/src/core/paths.ts +11 -1
  38. package/src/index.ts +0 -2
  39. package/src/modules/docs/actions/_manifest.generated.ts +18 -0
  40. package/src/modules/docs/actions/doc-attach.ts +2 -1
  41. package/src/modules/docs/actions/doc-link-file.ts +28 -0
  42. package/src/modules/docs/actions/doc-mdfile.ts +28 -0
  43. package/src/modules/docs/actions/doc-mdfiles.ts +29 -0
  44. package/src/modules/docs/actions/doc-ref.ts +36 -0
  45. package/src/modules/docs/actions/doc-unbind.ts +34 -0
  46. package/src/modules/docs/actions/doc-update.ts +3 -2
  47. package/src/modules/docs/actions/docs-bind.ts +1 -1
  48. package/src/modules/docs/actions/docs-bindings.ts +108 -0
  49. package/src/modules/docs/actions/docs-notebind.ts +1 -1
  50. package/src/modules/docs/attach.ts +16 -3
  51. package/src/modules/docs/bound-docs.ts +74 -0
  52. package/src/modules/docs/docref.ts +18 -3
  53. package/src/modules/docs/knowledge-md.ts +51 -0
  54. package/src/modules/docs/knowledge.ts +112 -112
  55. package/src/modules/docs/links.ts +7 -1
  56. package/src/modules/docs/mdfile.ts +24 -0
  57. package/src/modules/docs/paths.ts +6 -9
  58. package/src/modules/docs/ref-sync.ts +166 -0
  59. package/src/modules/docs/refs.ts +16 -5
  60. package/src/modules/docs/render.ts +33 -15
  61. package/src/modules/docs/seed.ts +1 -1
  62. package/src/modules/docs/service.ts +300 -30
  63. package/src/modules/docs/store.ts +147 -74
  64. package/src/modules/file/actions/_manifest.generated.ts +0 -9
  65. package/src/modules/file/actions/file-content.ts +3 -4
  66. package/src/modules/file/actions/file-get.ts +2 -3
  67. package/src/modules/file/actions/file-upload.ts +1 -4
  68. package/src/modules/file/service.ts +52 -253
  69. package/src/modules/localtask/action-render.ts +5 -5
  70. package/src/modules/localtask/actions/_manifest.generated.ts +0 -6
  71. package/src/modules/localtask/actions/localtask-attach.ts +4 -2
  72. package/src/modules/localtask/actions/localtask-cancelMany.ts +1 -1
  73. package/src/modules/localtask/actions/localtask-closeMany.ts +4 -3
  74. package/src/modules/localtask/actions/localtask-get.ts +1 -1
  75. package/src/modules/localtask/repo/tasks.ts +12 -6
  76. package/src/modules/localtask/service.ts +0 -2
  77. package/src/modules/localtask/task-ops.ts +4 -4
  78. package/src/modules/localtask/task-remove.ts +33 -16
  79. package/src/modules/localtask/task-templates.ts +2 -3
  80. package/src/modules/localtask/task-view.ts +2 -2
  81. package/src/modules/repos/actions/_manifest.generated.ts +0 -3
  82. package/src/modules/repos/actions/repo-update.ts +2 -4
  83. package/src/modules/repos/cli/render.ts +0 -15
  84. package/src/modules/repos/service/bind-topics.ts +8 -18
  85. package/src/modules/repos/service.ts +1 -1
  86. package/src/modules/repos/transfer/export.ts +4 -1
  87. package/src/modules/setting/actions/setting-set.ts +0 -2
  88. package/src/modules/setting/service.ts +6 -25
  89. package/src/modules/system/actions/bootstrap.ts +2 -31
  90. package/src/modules/system/actions/health.ts +4 -31
  91. package/src/modules/system/routes.ts +1 -1
  92. package/src/modules/tasktool/attach-resource.ts +68 -42
  93. package/src/modules/tasktool/attach-template.ts +73 -54
  94. package/src/modules/tasktool/attach.ts +98 -71
  95. package/src/modules/tasktool/delivery-template.ts +14 -4
  96. package/src/modules/tasktool/doc-inline.ts +63 -29
  97. package/src/modules/tasktool/get.ts +1 -1
  98. package/src/modules/tasktool/groupctx.ts +19 -11
  99. package/src/modules/tasktool/plugins/waitgoal-config.ts +24 -55
  100. package/src/modules/tasktool/plugins/waitgoal.ts +0 -2
  101. package/src/modules/tasktool/preview.ts +2 -3
  102. package/src/modules/tasktool/wait.ts +6 -9
  103. package/src/runtime/cli.ts +3 -15
  104. package/src/runtime/container.ts +1 -5
  105. package/src/runtime/help.ts +1 -4
  106. package/src/runtime/registry.ts +0 -6
  107. package/src/shared/prompt-blocks.ts +37 -33
  108. package/src/shared/task-status.ts +3 -3
  109. package/src/web/frontend/App.tsx +3 -3
  110. package/src/web/frontend/api/cli-tree.json +115 -608
  111. package/src/web/frontend/api/client.generated.ts +88 -401
  112. package/src/web/frontend/components/Introduction/index.tsx +26 -14
  113. package/src/web/frontend/components/Introduction/rail.tsx +28 -3
  114. package/src/web/frontend/components/Introduction/style.css +3 -33
  115. package/src/web/frontend/components/Introduction/use-intro.ts +0 -80
  116. package/src/web/frontend/components/{cloud → attach}/upload.ts +7 -20
  117. package/src/web/frontend/components/bindings/bind-tags.tsx +183 -0
  118. package/src/web/frontend/components/doc/doc-head.tsx +29 -26
  119. package/src/web/frontend/components/icons.tsx +0 -1
  120. package/src/web/frontend/components/layout/crumbs.ts +0 -2
  121. package/src/web/frontend/components/md/ack-rail.tsx +10 -142
  122. package/src/web/frontend/components/md/attach-area.tsx +64 -9
  123. package/src/web/frontend/components/md/attach-common.ts +8 -3
  124. package/src/web/frontend/components/md/attach-modal.tsx +22 -17
  125. package/src/web/frontend/components/md/attach-picker.tsx +2 -2
  126. package/src/web/frontend/components/md/attachments.ts +2 -3
  127. package/src/web/frontend/components/popup/dismiss.ts +1 -1
  128. package/src/web/frontend/components/repos/get-loop-modal.tsx +20 -207
  129. package/src/web/frontend/components/sidebar/index.tsx +32 -6
  130. package/src/web/frontend/components/sidebar/model.ts +71 -0
  131. package/src/web/frontend/components/sidebar/task-children.tsx +41 -20
  132. package/src/web/frontend/components/status-tag/model.ts +1 -1
  133. package/src/web/frontend/components/task-panel/index.tsx +4 -1
  134. package/src/web/frontend/components/task-panel/task-row.tsx +2 -2
  135. package/src/web/frontend/components/tool-acts/modules.ts +0 -3
  136. package/src/web/frontend/components/use-rail-drag.ts +177 -0
  137. package/src/web/frontend/modules/board/ack-rail-pos.ts +17 -7
  138. package/src/web/frontend/modules/board/board-view.ts +2 -2
  139. package/src/web/frontend/modules/board/task-search.ts +81 -0
  140. package/src/web/frontend/modules/md/attach-mention.ts +6 -1
  141. package/src/web/frontend/modules/md/doc-bus.ts +22 -0
  142. package/src/web/frontend/modules/md/md-render.ts +9 -2
  143. package/src/web/frontend/modules/md/styles/chrome.css +25 -0
  144. package/src/web/frontend/modules/md/styles/docs.css +32 -21
  145. package/src/web/frontend/modules/md/styles/shell.css +1 -10
  146. package/src/web/frontend/page/dir/api.ts +7 -0
  147. package/src/web/frontend/page/dir/index.tsx +24 -58
  148. package/src/web/frontend/page/dir/landing.tsx +85 -72
  149. package/src/web/frontend/page/dir/task-actions.ts +17 -5
  150. package/src/web/frontend/page/dir/task-dock-panel.tsx +87 -2
  151. package/src/web/frontend/page/dir/task-dock.ts +21 -10
  152. package/src/web/frontend/page/dir/task-goal.ts +2 -2
  153. package/src/web/frontend/page/dir/task-status-bar.tsx +14 -1
  154. package/src/web/frontend/page/dir/task.tsx +5 -3
  155. package/src/web/frontend/page/doc/api.ts +71 -5
  156. package/src/web/frontend/page/doc/bindings.tsx +240 -0
  157. package/src/web/frontend/page/doc/doc-dock.tsx +159 -0
  158. package/src/web/frontend/page/doc/index.tsx +131 -212
  159. package/src/web/frontend/page/doc/use-wiki-nav.ts +101 -0
  160. package/src/web/frontend/page/group/index.tsx +61 -87
  161. package/src/web/frontend/page/overview/index.tsx +1 -2
  162. package/src/web/frontend/page/refs/api.ts +60 -8
  163. package/src/web/frontend/page/refs/index.tsx +177 -90
  164. package/src/web/frontend/page/refs/style.css +45 -2
  165. package/src/web/frontend/page/repos/doc-search-modal.tsx +7 -0
  166. package/src/web/frontend/page/repos/index.tsx +21 -60
  167. package/src/web/frontend/page/repos/repo-table.tsx +85 -77
  168. package/src/web/frontend/page/settings/index.tsx +3 -27
  169. package/src/web/frontend/page/settings/prompt-template-params.ts +18 -28
  170. package/src/web/frontend/panels.tsx +52 -6
  171. package/src/web/frontend/registry.ts +1 -2
  172. package/src/web/frontend/routes/index.ts +1 -2
  173. package/src/web/frontend/routes/static.ts +2 -3
  174. package/src/web/frontend/store.tsx +1 -8
  175. package/src/web/frontend/style.css +1 -0
  176. package/src/web/frontend/styles/base.css +0 -17
  177. package/src/web/frontend/styles/bindings.css +75 -0
  178. package/src/web/frontend/styles/buttons-cards.css +0 -72
  179. package/src/web/frontend/styles/repos-admin.css +7 -5
  180. package/src/web/frontend/styles-v2/dir.css +1 -9
  181. package/src/web/frontend/styles-v2/shell.css +0 -2
  182. package/src/web/frontend/styles-v2/sidebar.css +12 -0
  183. package/src/web/frontend/styles-v2/views.css +22 -102
  184. package/src/web/frontend/workspace/areas.ts +0 -2
  185. package/src/web/public/assets/Introduction-CohW6Xit.js +6 -0
  186. package/src/web/public/assets/Introduction-Iuxssa-b.css +1 -0
  187. package/src/web/public/assets/app-context-BgpTewyA.js +1 -0
  188. package/src/web/public/assets/{bar-B52NTf_v.js → bar-C2mfoqmj.js} +1 -1
  189. package/src/web/public/assets/{board-view-DABoVkaA.js → board-view-aAIEbSQi.js} +1 -1
  190. package/src/web/public/assets/button-xyR2UROd.js +1 -0
  191. package/src/web/public/assets/composer-launch-eTktHT_f.js +1 -0
  192. package/src/web/public/assets/{composer-panel-DpiU2h50.js → composer-panel-C0OOIXxz.js} +1 -1
  193. package/src/web/public/assets/dag-Gm4RcvEg.js +1 -0
  194. package/src/web/public/assets/dir-PjuMRbWo.js +3 -0
  195. package/src/web/public/assets/group-D94y_Lq6.js +1 -0
  196. package/src/web/public/assets/index-CBJKsJU3.css +1 -0
  197. package/src/web/public/assets/index-Crxdmsux.js +2 -0
  198. package/src/web/public/assets/md-history-CU_1I6ht.js +39 -0
  199. package/src/web/public/assets/{md-parse-b6GY5eBl.js → md-parse-CLyUaUto.js} +1 -1
  200. package/src/web/public/assets/{member-picker-B5I7KuOR.js → member-picker-XT12VRe6.js} +1 -1
  201. package/src/web/public/assets/model-CWJ8_2dN.js +2 -0
  202. package/src/web/public/assets/{overview-B3kHI66i.js → overview-BQm8BLCG.js} +1 -1
  203. package/src/web/public/assets/{progress-CdhFz0Lz.js → progress-CNam3Wuj.js} +2 -2
  204. package/src/web/public/assets/refs-C5idWnUj.css +1 -0
  205. package/src/web/public/assets/refs-ClETk1cj.js +2 -0
  206. package/src/web/public/assets/repos-BioGejZo.js +14 -0
  207. package/src/web/public/assets/route-crumb-Fc68LcQ4.js +1 -0
  208. package/src/web/public/assets/settings-BIzumXLD.js +8 -0
  209. package/src/web/public/assets/status-tag-CBFf_-ae.js +1 -0
  210. package/src/web/public/assets/task-CGmO3I2y.js +11 -0
  211. package/src/web/public/assets/task-row-DRBa11tf.js +1 -0
  212. package/src/web/public/assets/{task-status-DSrx0i66.js → task-status-BHF-y9Aq.js} +2 -1
  213. package/src/web/public/assets/{task-utils-_JAWRAz6.js → task-utils-DjODjVdc.js} +2 -2
  214. package/src/web/public/assets/{templates-CbRyW3PJ.js → templates-j8EzXHXf.js} +1 -1
  215. package/src/web/public/assets/ui-Y0aL-bGk.js +1 -0
  216. package/src/web/public/assets/use-rail-drag-DNfz4Gcx.js +1 -0
  217. package/src/web/public/assets/{workspace-4tw7trV7.js → workspace-D_G-B3TX.js} +4 -4
  218. package/src/web/public/index.html +9 -9
  219. package/assets/nx-kv/references/todo-commands.md +0 -269
  220. package/src/core/attachstore.ts +0 -360
  221. package/src/core/fileapi.ts +0 -267
  222. package/src/core/kvapi.ts +0 -237
  223. package/src/modules/auth/actions/_manifest.generated.ts +0 -26
  224. package/src/modules/auth/actions/auth-login.ts +0 -31
  225. package/src/modules/auth/actions/auth-logout.ts +0 -33
  226. package/src/modules/auth/actions/auth-me.ts +0 -33
  227. package/src/modules/auth/actions/auth-status.ts +0 -41
  228. package/src/modules/auth/index.ts +0 -24
  229. package/src/modules/auth/support.ts +0 -28
  230. package/src/modules/file/actions/file-list.ts +0 -31
  231. package/src/modules/file/actions/file-remove.ts +0 -31
  232. package/src/modules/file/actions/file-sync.ts +0 -33
  233. package/src/modules/localtask/actions/localtask-importRemote.ts +0 -51
  234. package/src/modules/localtask/actions/task-move.ts +0 -67
  235. package/src/modules/localtask/move-prims.ts +0 -170
  236. package/src/modules/localtask/move.ts +0 -174
  237. package/src/modules/localtask/remote-import.ts +0 -159
  238. package/src/modules/repos/actions/repo-ref-backfill.ts +0 -33
  239. package/src/modules/repos/ref-backfill.ts +0 -219
  240. package/src/modules/todo/actions/_manifest.generated.ts +0 -89
  241. package/src/modules/todo/actions/group-add.ts +0 -34
  242. package/src/modules/todo/actions/group-current.ts +0 -36
  243. package/src/modules/todo/actions/group-get.ts +0 -43
  244. package/src/modules/todo/actions/group-list.ts +0 -41
  245. package/src/modules/todo/actions/group-members.ts +0 -41
  246. package/src/modules/todo/actions/group-remove.ts +0 -44
  247. package/src/modules/todo/actions/group-update.ts +0 -37
  248. package/src/modules/todo/actions/group-use.ts +0 -43
  249. package/src/modules/todo/actions/prompt-get.ts +0 -31
  250. package/src/modules/todo/actions/prompt-remove.ts +0 -31
  251. package/src/modules/todo/actions/prompt-set.ts +0 -32
  252. package/src/modules/todo/actions/todo-add.ts +0 -34
  253. package/src/modules/todo/actions/todo-archive.ts +0 -33
  254. package/src/modules/todo/actions/todo-attach.ts +0 -37
  255. package/src/modules/todo/actions/todo-attachments.ts +0 -33
  256. package/src/modules/todo/actions/todo-done.ts +0 -33
  257. package/src/modules/todo/actions/todo-freeze.ts +0 -32
  258. package/src/modules/todo/actions/todo-get.ts +0 -33
  259. package/src/modules/todo/actions/todo-list.ts +0 -32
  260. package/src/modules/todo/actions/todo-remove.ts +0 -32
  261. package/src/modules/todo/actions/todo-unfreeze.ts +0 -34
  262. package/src/modules/todo/actions/todo-update.ts +0 -42
  263. package/src/modules/todo/actions/topic-add.ts +0 -31
  264. package/src/modules/todo/actions/topic-list.ts +0 -35
  265. package/src/modules/todo/actions/topic-remove.ts +0 -36
  266. package/src/modules/todo/attachments.ts +0 -194
  267. package/src/modules/todo/group.ts +0 -207
  268. package/src/modules/todo/index.ts +0 -26
  269. package/src/modules/todo/locate.ts +0 -103
  270. package/src/modules/todo/service.ts +0 -476
  271. package/src/modules/todo/store.ts +0 -176
  272. package/src/modules/todo/support.ts +0 -93
  273. package/src/web/frontend/components/Introduction/docs-modal.tsx +0 -338
  274. package/src/web/frontend/components/cloud/editor.tsx +0 -254
  275. package/src/web/frontend/components/cloud/group-popup.tsx +0 -198
  276. package/src/web/frontend/components/cloud/markdown.tsx +0 -60
  277. package/src/web/frontend/components/migrate/dialog.tsx +0 -120
  278. package/src/web/frontend/components/migrate/undo.tsx +0 -73
  279. package/src/web/frontend/components/migrate/use-move.ts +0 -137
  280. package/src/web/frontend/page/cloud/api.ts +0 -99
  281. package/src/web/frontend/page/cloud/index.tsx +0 -516
  282. package/src/web/frontend/page/dir/deleted-panel.tsx +0 -77
  283. package/src/web/public/assets/Introduction-BcPrmROW.css +0 -1
  284. package/src/web/public/assets/Introduction-Du_dycft.js +0 -6
  285. package/src/web/public/assets/app-context-BASCGAA-.js +0 -1
  286. package/src/web/public/assets/cloud-Droja_aT.js +0 -3
  287. package/src/web/public/assets/composer-launch-mK9Nr6mZ.js +0 -1
  288. package/src/web/public/assets/dag-Ca-wjIxQ.js +0 -1
  289. package/src/web/public/assets/deleted-panel-K9GgfR8t.js +0 -1
  290. package/src/web/public/assets/dir-DacRpcBt.js +0 -5
  291. package/src/web/public/assets/frontmatter-CLLxCmTv.js +0 -2
  292. package/src/web/public/assets/group-TPuU-QVc.js +0 -2
  293. package/src/web/public/assets/index-BkLkooKe.js +0 -2
  294. package/src/web/public/assets/index-DP3qBv1o.css +0 -1
  295. package/src/web/public/assets/md-history-0GBWw4qr.js +0 -39
  296. package/src/web/public/assets/model-Bn2fG6CC.js +0 -2
  297. package/src/web/public/assets/prompt-blocks-BovFd039.js +0 -8
  298. package/src/web/public/assets/refs-BDxfuH6R.js +0 -1
  299. package/src/web/public/assets/refs-CY4i7PoC.css +0 -1
  300. package/src/web/public/assets/repos-C8jRM7wS.js +0 -15
  301. package/src/web/public/assets/repos-ZPiaK93i.css +0 -1
  302. package/src/web/public/assets/route-crumb-QvahotvN.js +0 -1
  303. package/src/web/public/assets/settings-BBcdGLTc.js +0 -1
  304. package/src/web/public/assets/status-tag-BheHByek.js +0 -1
  305. package/src/web/public/assets/task-CUkQaLBZ.js +0 -11
  306. package/src/web/public/assets/tool-bar-BAmT-BI-.js +0 -1
  307. package/src/web/public/assets/upload-BcMhRsMn.js +0 -1
  308. /package/src/web/public/assets/{prompt-blocks-DA4lNJeC.css → button-DA4lNJeC.css} +0 -0
  309. /package/src/web/public/assets/{tool-bar-1h2zairf.css → use-rail-drag-1h2zairf.css} +0 -0
@@ -1,267 +0,0 @@
1
- // 后端文件(图床)客户端 —— 对接 dev_ctr_hello 的 /api/v1/files* 与 /files/:fileId。
2
- //
3
- // 与 kvapi 共用同一套信封判定:**HTTP 恒为 200,成败看 body 里的 `code`**(0 = 成功),
4
- // 所以这里复用 kvapi 导出的 call(),不另写一份解析。
5
- //
6
- // 上传走 multipart(后端 r.GetUploadFile("file")),其余走 JSON。
7
- //
8
- // fileId 是后端生成的不透明串:16 字节随机 → 32 位 hex;原文件名带扩展名时
9
- // 后端会在 id 后再接 `.<ext>`(service/file/file.go 的 newFileId + "." + newExt),
10
- // 所以 id 偶尔带后缀。判定「像不像 fileId」一律走 shared/attach 的 looksLikeFileId。
11
- import { badInput, external, notFound } from './errors.js';
12
- import { loadConfig, normalizeGroupId } from './config.js';
13
- import { call } from './kvapi.js';
14
-
15
- const TIMEOUT_MS = 60000;
16
-
17
- // 扩展名 → Content-Type。上传时按文件名猜:一律 octet-stream 会让浏览器
18
- // 拿到 application/octet-stream 而不内联渲染,图片就「预览不出来」了。
19
- const MIME: Record<string, string> = {
20
- '.png': 'image/png',
21
- '.jpg': 'image/jpeg',
22
- '.jpeg': 'image/jpeg',
23
- '.webp': 'image/webp',
24
- '.gif': 'image/gif',
25
- '.bmp': 'image/bmp',
26
- '.avif': 'image/avif',
27
- '.svg': 'image/svg+xml',
28
- '.ico': 'image/x-icon',
29
- '.pdf': 'application/pdf',
30
- '.doc': 'application/msword',
31
- '.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
32
- '.xls': 'application/vnd.ms-excel',
33
- '.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
34
- '.ppt': 'application/vnd.ms-powerpoint',
35
- '.pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
36
- '.txt': 'text/plain; charset=utf-8',
37
- '.md': 'text/markdown; charset=utf-8',
38
- '.csv': 'text/csv; charset=utf-8',
39
- '.json': 'application/json; charset=utf-8',
40
- '.zip': 'application/zip',
41
- };
42
-
43
- const IMAGE_EXT = new Set(['.png', '.jpg', '.jpeg', '.webp', '.gif', '.bmp', '.avif', '.svg', '.ico']);
44
-
45
- const extOf = (name: unknown): string => {
46
- const m = /(\.[A-Za-z0-9]{1,8})$/.exec(String(name || ''));
47
- return m ? (m[1] ?? '').toLowerCase() : '';
48
- };
49
-
50
- export function contentTypeOf(name: unknown, fallback = 'application/octet-stream'): string {
51
- return MIME[extOf(name)] || fallback;
52
- }
53
-
54
- export function isImageName(name: unknown, contentType = ''): boolean {
55
- const e = extOf(name);
56
- if (e) return IMAGE_EXT.has(e);
57
- return /^image\//i.test(String(contentType));
58
- }
59
-
60
- export interface FileMeta {
61
- fileId: string;
62
- url: string;
63
- accessLevel: string;
64
- size: number;
65
- contentType: string;
66
- groupId: number;
67
- groupName: string;
68
- sha256: string;
69
- md5: string;
70
- tags: string[];
71
- createdAt: string;
72
- expireAt: string;
73
- }
74
-
75
- export function normalizeFileMeta(d: any = {}): FileMeta {
76
- return {
77
- fileId: String(d.fileId ?? ''),
78
- url: String(d.url ?? ''),
79
- accessLevel: String(d.accessLevel ?? ''),
80
- size: Number(d.size) || 0,
81
- contentType: String(d.contentType ?? ''),
82
- groupId: Number(d.groupId) || 0,
83
- groupName: String(d.groupName ?? ''),
84
- sha256: String(d.sha256 ?? ''),
85
- md5: String(d.md5 ?? ''),
86
- tags: Array.isArray(d.tags) ? d.tags.map(String) : [],
87
- createdAt: String(d.createdAt ?? ''),
88
- expireAt: String(d.expireAt ?? ''),
89
- };
90
- }
91
-
92
- const gidQuery = (groupId: unknown): string => {
93
- const n = normalizeGroupId(groupId);
94
- return n === undefined ? '' : `?groupId=${n}`;
95
- };
96
-
97
- /** 出图地址:一律**自己拼**,不用后端回的 url。
98
- * 后端 url 按请求 Host 推断(可能被反代写成内网地址),自己拼才跟 baseUrl 一致,
99
- * 也才在假后端 / 换域名时都可预期。 */
100
- export function accessUrlOf(baseUrl: unknown, fileId: string): string {
101
- return String(baseUrl || '').replace(/\/$/, '') + '/files/' + encodeURIComponent(fileId);
102
- }
103
-
104
- export async function fileAccessUrl(fileId: string): Promise<string> {
105
- const cfg = await loadConfig();
106
- // fileId 可能带扩展名(xxx.docx);encodeURIComponent 不会编码 `.`,安全
107
- return accessUrlOf(cfg.baseUrl, fileId);
108
- }
109
-
110
- // ---- 上传(multipart)----
111
-
112
- async function parseEnvelope(res: Response, ctxLabel: string): Promise<any> {
113
- let envelope: any;
114
- try {
115
- envelope = JSON.parse(await res.text());
116
- } catch {
117
- throw external(`后端返回了非 JSON(HTTP ${res.status}): ${ctxLabel}`);
118
- }
119
- const code = envelope.code ?? res.status;
120
- if (code !== 0) {
121
- if (code === 401) throw badInput('未登录或登录已过期(执行 nx-kv auth login <email>)');
122
- throw external(`后端 code=${code}: ${envelope.message || '(无消息)'}`, { code, path: ctxLabel });
123
- }
124
- return envelope.data ?? null;
125
- }
126
-
127
- /**
128
- * 上传一个文件到当前用户空间(group)。
129
- * buffer 是完整字节:CLI 从本机文件读、面板从 base64 解 —— 两条路共用这一处。
130
- */
131
- export async function fileUpload({
132
- name,
133
- buffer,
134
- contentType,
135
- groupId,
136
- accessLevel = 'public',
137
- tags = [],
138
- key = '',
139
- expireSeconds = 0,
140
- }: {
141
- name?: string;
142
- buffer?: Buffer;
143
- contentType?: string;
144
- groupId?: unknown;
145
- accessLevel?: string;
146
- tags?: string[];
147
- key?: string;
148
- expireSeconds?: number;
149
- } = {}): Promise<FileMeta> {
150
- if (!name) throw badInput('上传必须带文件名');
151
- if (!buffer || !buffer.length) throw badInput('上传内容为空');
152
-
153
- const cfg = await loadConfig();
154
- const url = cfg.baseUrl.replace(/\/$/, '') + '/api/v1/files';
155
- const ct = contentType || contentTypeOf(name);
156
-
157
- const form = new FormData();
158
- form.append('file', new Blob([new Uint8Array(buffer)], { type: ct }), String(name));
159
- form.append('accessLevel', String(accessLevel));
160
- const gid = normalizeGroupId(groupId);
161
- if (gid !== undefined) form.append('groupId', String(gid));
162
- if (expireSeconds) form.append('expireSeconds', String(expireSeconds));
163
- if (key) form.append('key', String(key));
164
- for (const t of tags) form.append('tags', String(t));
165
-
166
- const ctrl = new AbortController();
167
- const timer = setTimeout(() => ctrl.abort(), TIMEOUT_MS);
168
- let res: Response;
169
- try {
170
- // ⚠️ 不能自己设 content-type:multipart 的 boundary 由 FormData 生成,
171
- // 手写一个会丢掉 boundary,后端解析直接失败。
172
- res = await fetch(url, {
173
- method: 'POST',
174
- headers: cfg.token ? { authorization: `Bearer ${cfg.token}` } : {},
175
- body: form,
176
- signal: ctrl.signal,
177
- });
178
- } catch (e) {
179
- if ((e as Error).name === 'AbortError') throw external(`上传超时(${TIMEOUT_MS}ms): ${name}`);
180
- throw external(`无法连接后端 ${cfg.baseUrl}: ${(e as Error).message}`);
181
- } finally {
182
- clearTimeout(timer);
183
- }
184
-
185
- const data = await parseEnvelope(res, 'POST /api/v1/files');
186
- if (!data || !data.fileId) throw external('上传成功但后端未返回 fileId');
187
- return normalizeFileMeta(data);
188
- }
189
-
190
- // ---- 列表 / 元数据 / 删除(JSON)----
191
-
192
- export async function listFiles({ groupId, limit = 100, offset = 0 }: { groupId?: unknown; limit?: number; offset?: number } = {}): Promise<{ total: number; hasMore: boolean; items: FileMeta[] }> {
193
- const n = normalizeGroupId(groupId);
194
- const q = `?limit=${Number(limit) || 100}&offset=${Number(offset) || 0}` + (n === undefined ? '' : `&groupId=${n}`);
195
- const data = await call({ method: 'GET', path: '/api/v1/files' + q });
196
- return {
197
- total: Number(data?.total) || 0,
198
- hasMore: data?.hasMore === true,
199
- items: (data?.items ?? []).map(normalizeFileMeta),
200
- };
201
- }
202
-
203
- /** 一次拉全(分页直到 total 或页数上限),供同步用。
204
- * 上限存在的意义:列表接口异常返回 hasMore=true 时不会把 CLI 卡死。 */
205
- export async function listAllFiles({ groupId, pageSize = 200, maxPages = 50 }: { groupId?: unknown; pageSize?: number; maxPages?: number } = {}): Promise<{ total: number; items: FileMeta[] }> {
206
- const out: FileMeta[] = [];
207
- let total = 0;
208
- for (let page = 0; page < maxPages; page++) {
209
- const r = await listFiles({ groupId, limit: pageSize, offset: page * pageSize });
210
- out.push(...r.items);
211
- total = r.total;
212
- if (!r.items.length || out.length >= total) break;
213
- }
214
- return { total, items: out };
215
- }
216
-
217
- export async function fileInfo(fileId: string, groupId?: unknown): Promise<FileMeta> {
218
- if (!fileId) throw badInput('缺少 fileId');
219
- const data = await call({
220
- method: 'GET',
221
- path: `/api/v1/files/${encodeURIComponent(fileId)}/info` + gidQuery(groupId),
222
- allowMissing: true,
223
- });
224
- if (!data) throw notFound(`附件不存在: ${fileId}(可能已被删除或不在当前工作空间)`);
225
- return normalizeFileMeta(data);
226
- }
227
-
228
- export async function deleteFile(fileId: string, groupId?: unknown): Promise<{ fileId: string; deleted: boolean }> {
229
- if (!fileId) throw badInput('缺少 fileId');
230
- await call({
231
- method: 'DELETE',
232
- path: `/api/v1/files/${encodeURIComponent(fileId)}` + gidQuery(groupId),
233
- });
234
- return { fileId, deleted: true };
235
- }
236
-
237
- /**
238
- * 取文件本体:返回未解析的 fetch Response(调用方 pipe / arrayBuffer)。
239
- * 走的是**无鉴权的出图路由** /files/:fileId —— 与 <img src> 同一条路,
240
- * 所以「浏览器能预览」与「CLI 能下载」在权限上永远一致。
241
- */
242
- export async function openFileStream(fileId: string): Promise<Response> {
243
- if (!fileId) throw badInput('缺少 fileId');
244
- const cfg = await loadConfig();
245
- const url = await fileAccessUrl(fileId);
246
- const ctrl = new AbortController();
247
- const timer = setTimeout(() => ctrl.abort(), TIMEOUT_MS);
248
- let res: Response;
249
- try {
250
- res = await fetch(url, {
251
- headers: cfg.token ? { authorization: `Bearer ${cfg.token}` } : {},
252
- signal: ctrl.signal,
253
- });
254
- } catch (e) {
255
- if ((e as Error).name === 'AbortError') throw external(`下载超时(${TIMEOUT_MS}ms): ${fileId}`);
256
- throw external(`无法连接后端 ${cfg.baseUrl}: ${(e as Error).message}`);
257
- } finally {
258
- clearTimeout(timer);
259
- }
260
- if (!res.ok) throw notFound(`附件下载失败(HTTP ${res.status}): ${fileId}`);
261
- return res;
262
- }
263
-
264
- export async function downloadFile(fileId: string): Promise<Buffer> {
265
- const res = await openFileStream(fileId);
266
- return Buffer.from(await res.arrayBuffer());
267
- }
package/src/core/kvapi.ts DELETED
@@ -1,237 +0,0 @@
1
- // 后端 KV 客户端 —— 对接 47 服务器的 goframe 接口。
2
- //
3
- // 信封约定:**HTTP 状态恒为 200,成败看 body 里的 `code`**(0 = 成功)。
4
- // 这一点与常见的 REST 直觉相反,所以统一收在本文件里判断;
5
- // 上层 service 只看到「成功返回 data / 失败抛异常」,不必各自解析信封。
6
- //
7
- // 端点(来自 Flutter 端 api/goframe/kv/kv_endpoint.dart 与 user/user_auth_service.dart):
8
- // POST /api/v1/user/login { email, password } → { token, userId }
9
- // GET /api/v1/kv/{key}[?groupId=N] → { key, value, expires_at, tags }
10
- // POST /api/v1/kv { key, value, ttl, groupId }
11
- // DELETE /api/v1/kv/{key}[?groupId=N]
12
- // GET /api/v1/kv?limit=&offset=[&groupId=N] → { items, total }
13
- // GET /api/v1/groups → { groups: [...] }
14
- import { badInput, external, notFound } from './errors.js';
15
- import { loadConfig, normalizeGroupId } from './config.js';
16
-
17
- const TIMEOUT_MS = 20000;
18
-
19
- // 信封感知的通用调用器。**导出**是为了让 fileapi 复用同一套
20
- // 「HTTP 恒 200、成败看 code」的判定——两处各写一遍迟早分叉。
21
- //
22
- // 返回值是后端 JSON 的 data 字段,形状随端点变化且不受我方类型约束——
23
- // 统一按 any 处理(外部数据,调用方各自归一化),比摆一个假装精确的类型诚实。
24
- export async function call({
25
- method,
26
- path,
27
- body,
28
- token,
29
- baseUrl,
30
- allowMissing = false,
31
- }: {
32
- method: string;
33
- path: string;
34
- body?: unknown;
35
- token?: string;
36
- baseUrl?: string;
37
- allowMissing?: boolean;
38
- }): Promise<any> {
39
- const cfg = baseUrl ? { baseUrl, token } : await loadConfig();
40
- const url = cfg.baseUrl.replace(/\/$/, '') + path;
41
-
42
- const headers: Record<string, string> = {};
43
- if (cfg.token) headers.authorization = `Bearer ${cfg.token}`;
44
- if (body !== undefined) headers['content-type'] = 'application/json';
45
-
46
- const ctrl = new AbortController();
47
- const timer = setTimeout(() => ctrl.abort(), TIMEOUT_MS);
48
- let res: Response;
49
- try {
50
- res = await fetch(url, {
51
- method,
52
- headers,
53
- body: body === undefined ? undefined : JSON.stringify(body),
54
- signal: ctrl.signal,
55
- });
56
- } catch (e) {
57
- if ((e as Error).name === 'AbortError') throw external(`请求超时(${TIMEOUT_MS}ms): ${method} ${path}`);
58
- throw external(`无法连接后端 ${cfg.baseUrl}: ${(e as Error).message}`);
59
- } finally {
60
- clearTimeout(timer);
61
- }
62
-
63
- let envelope: any;
64
- try {
65
- envelope = JSON.parse(await res.text());
66
- } catch {
67
- throw external(`后端返回了非 JSON(HTTP ${res.status}): ${method} ${path}`);
68
- }
69
-
70
- const code = envelope.code ?? res.status;
71
- if (code !== 0) {
72
- // 401 单独识别成「未登录」——这是 agent 最需要一眼看懂的失败
73
- if (code === 401) throw badInput('未登录或登录已过期(执行 nx-kv auth login <email>)');
74
- // 业务上"这个 key 不存在"不是错误,由调用方决定怎么处理
75
- if (allowMissing && (code === 404 || /not\s*found|不存在/i.test(envelope.message || ''))) {
76
- return null;
77
- }
78
- throw external(`后端 code=${code}: ${envelope.message || '(无消息)'}`, { code, path });
79
- }
80
- return envelope.data ?? null;
81
- }
82
-
83
- const gid = (groupId: unknown): string => {
84
- const n = normalizeGroupId(groupId);
85
- return n === undefined ? '' : `?groupId=${n}`;
86
- };
87
-
88
- // ---- 认证 ----
89
-
90
- export async function login(email: unknown, password: unknown, { baseUrl }: { baseUrl?: string } = {}): Promise<{ token: string; userId: number }> {
91
- if (!email || !password) throw badInput('邮箱与密码不能为空');
92
- const data = await call({
93
- method: 'POST',
94
- path: '/api/v1/user/login',
95
- body: { email, password },
96
- baseUrl,
97
- token: '', // 登录本身不需要 token(显式传空,避免用旧 token)
98
- });
99
- if (!data || !data.token) throw external('登录成功但未返回 token');
100
- return { token: data.token, userId: Number(data.userId ?? data.user?.id ?? 0) };
101
- }
102
-
103
- export async function userInfo(): Promise<any> {
104
- return call({ method: 'GET', path: '/api/v1/user/info' });
105
- }
106
-
107
- // ---- 工作空间 ----
108
-
109
- export interface GroupInfo {
110
- id: number;
111
- name: string;
112
- description: string;
113
- myRole: string;
114
- memberCount: number;
115
- ownerId: number;
116
- createdAt: string;
117
- }
118
-
119
- function normalizeGroup(g: any): GroupInfo {
120
- return {
121
- id: Number(g.id) || 0,
122
- name: g.name ?? '',
123
- description: g.description ?? '',
124
- myRole: g.myRole ?? '',
125
- memberCount: Number(g.memberCount) || 0,
126
- ownerId: Number(g.ownerId) || 0,
127
- createdAt: g.createdAt ?? '',
128
- };
129
- }
130
-
131
- export async function listGroups(): Promise<GroupInfo[]> {
132
- const data = await call({ method: 'GET', path: '/api/v1/groups' });
133
- return (data?.groups ?? []).map(normalizeGroup);
134
- }
135
-
136
- // 建组。返回后端给的完整对象——建完立刻能拿到 id,不必再列一次。
137
- export async function createGroup({ name, description }: { name?: string; description?: string } = {}): Promise<GroupInfo> {
138
- const n = String(name || '').trim();
139
- if (!n) throw badInput('工作空间名称不能为空');
140
- const data = await call({
141
- method: 'POST',
142
- path: '/api/v1/groups',
143
- body: { name: n, description: String(description ?? '') },
144
- });
145
- return normalizeGroup(data?.group ?? {});
146
- }
147
-
148
- // 改名 / 改描述。只发传入的字段(PATCH 语义)。
149
- export async function updateGroup(id: unknown, { name, description }: { name?: string; description?: string } = {}): Promise<GroupInfo> {
150
- const body: Record<string, string> = {};
151
- if (name !== undefined) {
152
- const n = String(name).trim();
153
- if (!n) throw badInput('工作空间名称不能为空');
154
- body.name = n;
155
- }
156
- if (description !== undefined) body.description = String(description);
157
- if (!Object.keys(body).length) throw badInput('至少要给出 --name 或 --description');
158
- const data = await call({ method: 'PATCH', path: `/api/v1/groups/${Number(id)}`, body });
159
- return normalizeGroup(data?.group ?? {});
160
- }
161
-
162
- // 解散工作空间。后端有前置条件:组内不能还有 KV,
163
- // 报错文案会把原因带回来(例如「组内存在 KV,请先删除或转移后再解散组」),
164
- // 这里原样透出——调用方需要知道到底卡在哪一步。
165
- export async function deleteGroup(id: unknown): Promise<{ id: number; deleted: boolean }> {
166
- await call({ method: 'DELETE', path: `/api/v1/groups/${Number(id)}` });
167
- return { id: Number(id), deleted: true };
168
- }
169
-
170
- export async function listGroupMembers(id: unknown): Promise<{ userId: number; email: string; nickname: string; role: string }[]> {
171
- const data = await call({ method: 'GET', path: `/api/v1/groups/${Number(id)}/members` });
172
- return (data?.members ?? []).map((m: any) => ({
173
- userId: Number(m.userId) || 0,
174
- email: m.email ?? '',
175
- nickname: m.nickname ?? '',
176
- role: m.role ?? m.myRole ?? '',
177
- }));
178
- }
179
-
180
- // ---- KV 读写 ----
181
- //
182
- // 注意:后端**没有「单条更新」接口**。任何写都是「读整把 key → 改数组 → 整把覆盖」,
183
- // 所以上层必须先读后写,且两把 key 要一起写(见 modules/todo/service 的契约注释)。
184
-
185
- export interface KvItem {
186
- key: string;
187
- value: any;
188
- expiresAt: unknown;
189
- tags: string[];
190
- }
191
-
192
- // 读一个 key。key 不存在时返回 null(不是错误)。
193
- export async function kvGet(key: string, groupId?: unknown): Promise<KvItem | null> {
194
- const data = await call({
195
- method: 'GET',
196
- path: '/api/v1/kv/' + encodeURIComponent(key) + gid(groupId),
197
- allowMissing: true,
198
- });
199
- if (!data) return null;
200
- return {
201
- key: data.key ?? key,
202
- value: data.value ?? '',
203
- expiresAt: data.expires_at ?? data.expiresAt ?? null,
204
- tags: Array.isArray(data.tags) ? data.tags.map(String) : [],
205
- };
206
- }
207
-
208
- export async function kvSet({ key, value, ttl = 0, groupId }: { key: string; value: unknown; ttl?: number; groupId?: unknown }): Promise<{ key: string; bytes: number }> {
209
- const n = normalizeGroupId(groupId);
210
- const body: Record<string, unknown> = { key, value, ttl };
211
- if (n !== undefined) body.groupId = n;
212
- await call({ method: 'POST', path: '/api/v1/kv', body });
213
- return { key, bytes: Buffer.byteLength(String(value), 'utf8') };
214
- }
215
-
216
- export async function kvDelete(key: string, groupId?: unknown): Promise<{ key: string; deleted: boolean }> {
217
- await call({ method: 'DELETE', path: '/api/v1/kv/' + encodeURIComponent(key) + gid(groupId) });
218
- return { key, deleted: true };
219
- }
220
-
221
- export async function kvList({ limit = 50, offset = 0, groupId }: { limit?: number; offset?: number; groupId?: unknown } = {}): Promise<{ total: number; items: KvItem[] }> {
222
- const n = normalizeGroupId(groupId);
223
- const q = `?limit=${limit}&offset=${offset}` + (n === undefined ? '' : `&groupId=${n}`);
224
- const data = await call({ method: 'GET', path: '/api/v1/kv' + q });
225
- return {
226
- total: Number(data?.total) || 0,
227
- items: (data?.items ?? []).map((it: any) => ({
228
- key: it.key ?? '',
229
- value: it.value ?? '',
230
- expiresAt: it.expires_at ?? it.expiresAt ?? null,
231
- tags: Array.isArray(it.tags) ? it.tags.map(String) : [],
232
- })),
233
- };
234
- }
235
-
236
- // 供 service 层判断「key 不存在」时抛的错(保持错误码语义)
237
- export { notFound };
@@ -1,26 +0,0 @@
1
- // AUTO-GENERATED —— 由 scripts/gen-actions.mjs 生成,勿手改。
2
- //
3
- // 收录本目录下所有继承 ActionBase 的类。**加一条 action = 新建一个文件 +
4
- // 跑 `pnpm gen`**;模块的 index.ts 不需要改。
5
- // 新鲜度由 tests/unit/action-registry.test.mjs 对账。
6
-
7
- import type { ActionBase } from '../../../runtime/action-base.js';
8
- import type { Container } from '../../../runtime/container.js';
9
- import { AuthLoginAction } from './auth-login.js';
10
- import { AuthLogoutAction } from './auth-logout.js';
11
- import { AuthMeAction } from './auth-me.js';
12
- import { AuthStatusAction } from './auth-status.js';
13
-
14
- /** 本模块的全部 action 类(容器按这个顺序建实例)。 */
15
- export const ACTIONS: readonly (new (deps: Container) => ActionBase)[] = [
16
- AuthLoginAction,
17
- AuthLogoutAction,
18
- AuthMeAction,
19
- AuthStatusAction,
20
- ];
21
-
22
- // 再导出类本身:前端 apiclient 的返回类型从这里 type-only 引用(实现即契约)。
23
- export { AuthLoginAction };
24
- export { AuthLogoutAction };
25
- export { AuthMeAction };
26
- export { AuthStatusAction };
@@ -1,31 +0,0 @@
1
- // auth.login —— 由 .tool/migrate-module.mjs 从 legacy 形态迁来(模板形态:一条 action 一个文件)。
2
- //
3
- // 契约(zod schema)就声明在本文件里——入参类型由基类泛型模板封装;本文件只做「声明 + 实现」,业务在服务层。
4
- import { action } from '../../../runtime/action-decorator.js';
5
- import { z } from 'zod';
6
- import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
7
- import { configPathFromEnv as _configPathFromEnv } from '../../../core/config.js';
8
- import { doLogin } from '../support.js';
9
- const configPathFromEnv: any = _configPathFromEnv;
10
-
11
- /** auth.login 的入参契约(CLI 与 HTTP 共用同一份)。 */
12
- const input = z.object({
13
- email: z.string(),
14
- password: z.string().optional().describe("密码(省略则交互式隐藏输入)"),
15
- baseUrl: z.string().optional().describe("后端地址,覆盖默认"),
16
- });
17
-
18
- export class AuthLoginAction extends ActionBase<typeof input> {
19
- @action({
20
- id: 'auth.login',
21
- cli: ['auth', 'login'],
22
- http: ['POST', '/api/auth/login'],
23
- summary: '登录并保存 token 到本机配置',
24
- args: ['email'],
25
- input,
26
- render: (d: any) => `已登录: ${d.email}(userId=${d.userId})\n配置: ${configPathFromEnv()}`,
27
- })
28
- override async run(ctx: ActionInput<this['_input']>) {
29
- return doLogin(ctx);
30
- }
31
- }
@@ -1,33 +0,0 @@
1
- // auth.logout —— 由 .tool/migrate-module.mjs 从 legacy 形态迁来(模板形态:一条 action 一个文件)。
2
- //
3
- // 契约(zod schema)就声明在本文件里——入参类型由基类泛型模板封装;本文件只做「声明 + 实现」,业务在服务层。
4
- import { action } from '../../../runtime/action-decorator.js';
5
- import { z } from 'zod';
6
- import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
7
- import { loadConfig as _loadConfig, saveConfig as _saveConfig } from '../../../core/config.js';
8
- const loadConfig: any = _loadConfig;
9
- const saveConfig: any = _saveConfig;
10
-
11
- /** auth.logout 的入参契约(CLI 与 HTTP 共用同一份)。 */
12
- const input = z.object({
13
-
14
- });
15
-
16
- export class AuthLogoutAction extends ActionBase<typeof input> {
17
- @action({
18
- id: 'auth.logout',
19
- cli: ['auth', 'logout'],
20
- http: ['POST', '/api/auth/logout'],
21
- summary: '清除本机保存的 token',
22
- input,
23
- render: (d: any) => (d.was ? `已登出(原账号 ${d.was})` : '本就未登录'),
24
- })
25
- override async run(_ctx: ActionInput<this['_input']>) {
26
-
27
- const before: any = await loadConfig();
28
- // 只清登录态,保留 baseUrl 与当前工作空间选择
29
- await saveConfig({ ...before, token: '', email: '', userId: 0 });
30
- return { loggedOut: true, was: before.email || '' };
31
-
32
- }
33
- }
@@ -1,33 +0,0 @@
1
- // auth.me —— 由 .tool/migrate-module.mjs 从 legacy 形态迁来(模板形态:一条 action 一个文件)。
2
- //
3
- // 契约(zod schema)就声明在本文件里——入参类型由基类泛型模板封装;本文件只做「声明 + 实现」,业务在服务层。
4
- import { action } from '../../../runtime/action-decorator.js';
5
- import { z } from 'zod';
6
- import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
7
- import { requireAuth as _requireAuth } from '../../../core/config.js';
8
- import { userInfo as _userInfo } from '../../../core/kvapi.js';
9
- const requireAuth: any = _requireAuth;
10
- const userInfo: any = _userInfo;
11
-
12
- /** auth.me 的入参契约(CLI 与 HTTP 共用同一份)。 */
13
- const input = z.object({
14
-
15
- });
16
-
17
- export class AuthMeAction extends ActionBase<typeof input> {
18
- @action({
19
- id: 'auth.me',
20
- cli: ['auth', 'me'],
21
- http: ['GET', '/api/auth/me'],
22
- summary: '向后端确认身份(验证 token 是否仍有效)',
23
- input,
24
- render: (d: any) => JSON.stringify(d, null, 2),
25
- })
26
- override async run(_ctx: ActionInput<this['_input']>) {
27
-
28
- await requireAuth();
29
- const info: any = await userInfo();
30
- return info ?? { ok: true };
31
-
32
- }
33
- }
@@ -1,41 +0,0 @@
1
- // auth.status —— 由 .tool/migrate-module.mjs 从 legacy 形态迁来(模板形态:一条 action 一个文件)。
2
- //
3
- // 契约(zod schema)就声明在本文件里——入参类型由基类泛型模板封装;本文件只做「声明 + 实现」,业务在服务层。
4
- import { action } from '../../../runtime/action-decorator.js';
5
- import { z } from 'zod';
6
- import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
7
- import { loadConfig as _loadConfig, configPathFromEnv as _configPathFromEnv } from '../../../core/config.js';
8
- const loadConfig: any = _loadConfig;
9
- const configPathFromEnv: any = _configPathFromEnv;
10
-
11
- /** auth.status 的入参契约(CLI 与 HTTP 共用同一份)。 */
12
- const input = z.object({
13
-
14
- });
15
-
16
- export class AuthStatusAction extends ActionBase<typeof input> {
17
- @action({
18
- id: 'auth.status',
19
- cli: ['auth', 'status'],
20
- http: ['GET', '/api/auth'],
21
- summary: '查看本机登录态(不请求后端,离线可用)',
22
- input,
23
- render: (d: any) =>
24
- d.loggedIn
25
- ? `已登录: ${d.email}(userId=${d.userId})\n后端: ${d.baseUrl}\n工作空间: ${d.groupId > 0 ? d.groupId : '默认组'}`
26
- : `未登录(nx-kv auth login <email>)\n后端: ${d.baseUrl}`,
27
- })
28
- override async run(_ctx: ActionInput<this['_input']>) {
29
-
30
- const cfg: any = await loadConfig();
31
- return {
32
- loggedIn: !!cfg.token,
33
- email: cfg.email,
34
- userId: cfg.userId,
35
- baseUrl: cfg.baseUrl,
36
- groupId: cfg.groupId,
37
- configPath: configPathFromEnv(),
38
- };
39
-
40
- }
41
- }