hostlet 0.0.0-stage → 0.1.0-alpha.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 (512) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +233 -2
  3. package/bin/hostlet.js +61 -0
  4. package/console/app/api.js +1223 -0
  5. package/console/app/boot.js +165 -0
  6. package/console/app/cards.js +222 -0
  7. package/console/app/compose-quote.js +127 -0
  8. package/console/app/config-form.js +727 -0
  9. package/console/app/document-drafts.js +62 -0
  10. package/console/app/document-tools.mjs +67 -0
  11. package/console/app/documents.js +106 -0
  12. package/console/app/pages.js +6483 -0
  13. package/console/app/plugins.js +509 -0
  14. package/console/app/preview-tools.js +172 -0
  15. package/console/app/reference-labels.js +118 -0
  16. package/console/app/selection.js +372 -0
  17. package/console/app/store.js +57 -0
  18. package/console/app/text-anchor.js +26 -0
  19. package/console/app/topic-local.js +322 -0
  20. package/console/app/topic-nav.js +414 -0
  21. package/console/app/topic-status.js +109 -0
  22. package/console/app/views.js +43 -0
  23. package/console/apple-touch-icon.png +0 -0
  24. package/console/avatars/agy.svg +34 -0
  25. package/console/avatars/alhena.svg +36 -0
  26. package/console/avatars/castor.svg +38 -0
  27. package/console/avatars/claude.svg +34 -0
  28. package/console/avatars/codex.svg +34 -0
  29. package/console/avatars/devin.svg +34 -0
  30. package/console/avatars/echo.svg +34 -0
  31. package/console/avatars/kimi.svg +33 -0
  32. package/console/avatars/opencode.svg +33 -0
  33. package/console/avatars/pinion.svg +34 -0
  34. package/console/avatars/sprocket.svg +34 -0
  35. package/console/avatars/vela.svg +44 -0
  36. package/console/avatars/wasat.svg +38 -0
  37. package/console/clients/agy.svg +1 -0
  38. package/console/clients/claude.svg +1 -0
  39. package/console/clients/codex.svg +1 -0
  40. package/console/clients/devin.svg +1 -0
  41. package/console/clients/kimi.svg +1 -0
  42. package/console/clients/opencode.svg +1 -0
  43. package/console/favicon.ico +0 -0
  44. package/console/favicon.svg +16 -0
  45. package/console/index.html +99 -0
  46. package/console/pdl/engine/README.md +13 -0
  47. package/console/pdl/engine/anchor.js +195 -0
  48. package/console/pdl/engine/core.js +1340 -0
  49. package/console/pdl/engine/frame.js +1252 -0
  50. package/console/pdl/engine/i18n.js +67 -0
  51. package/console/pdl/engine/pdl-check.js +102 -0
  52. package/console/pdl/engine/pdl-doc.js +353 -0
  53. package/console/pdl/engine/pdl-view.js +280 -0
  54. package/console/pdl/engine/pdl.js +1064 -0
  55. package/console/pdl/engine/platform.js +18 -0
  56. package/console/pdl/engine/proj.js +279 -0
  57. package/console/pdl/engine/theme.js +176 -0
  58. package/console/pdl/engine/tree.js +171 -0
  59. package/console/pdl/engine/units.js +546 -0
  60. package/console/pdl/library/README.md +28 -0
  61. package/console/pdl/library/blocks.js +1512 -0
  62. package/console/pdl/library/buttons.js +86 -0
  63. package/console/pdl/library/capsules.js +130 -0
  64. package/console/pdl/library/charts.js +287 -0
  65. package/console/pdl/library/code.js +98 -0
  66. package/console/pdl/library/css/base.css +12 -0
  67. package/console/pdl/library/css/blocks.css +98 -0
  68. package/console/pdl/library/css/capsules.css +42 -0
  69. package/console/pdl/library/css/catalog-page.css +24 -0
  70. package/console/pdl/library/css/chat.css +100 -0
  71. package/console/pdl/library/css/composer-top.css +145 -0
  72. package/console/pdl/library/css/controls.css +195 -0
  73. package/console/pdl/library/css/drag.css +29 -0
  74. package/console/pdl/library/css/edit-layout.css +93 -0
  75. package/console/pdl/library/css/floating-window.css +30 -0
  76. package/console/pdl/library/css/hover.css +50 -0
  77. package/console/pdl/library/css/label-search.css +37 -0
  78. package/console/pdl/library/css/layers.css +43 -0
  79. package/console/pdl/library/css/library-parts.css +33 -0
  80. package/console/pdl/library/css/library.css +117 -0
  81. package/console/pdl/library/css/member-select.css +34 -0
  82. package/console/pdl/library/css/message.css +72 -0
  83. package/console/pdl/library/css/page.css +104 -0
  84. package/console/pdl/library/css/parts.css +338 -0
  85. package/console/pdl/library/css/responsive.css +40 -0
  86. package/console/pdl/library/css/roles.css +28 -0
  87. package/console/pdl/library/css/rows.css +231 -0
  88. package/console/pdl/library/css/settings-rows.css +37 -0
  89. package/console/pdl/library/css/shell.css +59 -0
  90. package/console/pdl/library/css/stream.css +296 -0
  91. package/console/pdl/library/css/theme-calculator.css +18 -0
  92. package/console/pdl/library/css/thumb-choice.css +69 -0
  93. package/console/pdl/library/css/tweaks.css +16 -0
  94. package/console/pdl/library/css/widgets.css +211 -0
  95. package/console/pdl/library/css/workbench.css +59 -0
  96. package/console/pdl/library/feedback.js +83 -0
  97. package/console/pdl/library/floating-window.mjs +100 -0
  98. package/console/pdl/library/fold.js +238 -0
  99. package/console/pdl/library/format.js +53 -0
  100. package/console/pdl/library/frames.js +123 -0
  101. package/console/pdl/library/icons.js +165 -0
  102. package/console/pdl/library/identity.js +149 -0
  103. package/console/pdl/library/inputs.js +801 -0
  104. package/console/pdl/library/label-search.js +214 -0
  105. package/console/pdl/library/markdown-text.js +115 -0
  106. package/console/pdl/library/markdown.js +150 -0
  107. package/console/pdl/library/media-viewer.js +293 -0
  108. package/console/pdl/library/member-select.mjs +32 -0
  109. package/console/pdl/library/message.js +105 -0
  110. package/console/pdl/library/motion.js +56 -0
  111. package/console/pdl/library/overlays.js +165 -0
  112. package/console/pdl/library/page.js +142 -0
  113. package/console/pdl/library/plugin-form.js +154 -0
  114. package/console/pdl/library/registry.js +198 -0
  115. package/console/pdl/library/rows.js +523 -0
  116. package/console/pdl/library/shell.js +151 -0
  117. package/console/pdl/library/stream.js +58 -0
  118. package/console/pdl/library/tabs.js +259 -0
  119. package/console/pdl/library/theme-calculator.js +300 -0
  120. package/console/pdl/library/widgets.js +114 -0
  121. package/console/pdl/load-order.json +74 -0
  122. package/console/pdl/platform/README.md +3 -0
  123. package/console/pdl/platform/rich-markdown.mjs +17 -0
  124. package/console/pdl/platform/web-links.js +26 -0
  125. package/console/pdl/platform/web.js +80 -0
  126. package/console/sdk-browser/mentions.d.mts +16 -0
  127. package/console/sdk-browser/mentions.mjs +84 -0
  128. package/console/theme/assets.js +21 -0
  129. package/console/theme/theme.json +9417 -0
  130. package/console/theme/tokens.json +444 -0
  131. package/dist/core/a2a.d.ts +288 -0
  132. package/dist/core/a2a.js +2197 -0
  133. package/dist/core/address.d.ts +34 -0
  134. package/dist/core/address.js +33 -0
  135. package/dist/core/approval-inputs.d.ts +17 -0
  136. package/dist/core/approval-inputs.js +70 -0
  137. package/dist/core/archive.d.ts +19 -0
  138. package/dist/core/archive.js +135 -0
  139. package/dist/core/attachments.d.ts +17 -0
  140. package/dist/core/attachments.js +143 -0
  141. package/dist/core/blocked-handoffs.d.ts +132 -0
  142. package/dist/core/blocked-handoffs.js +349 -0
  143. package/dist/core/config-schema.d.ts +124 -0
  144. package/dist/core/config-schema.js +192 -0
  145. package/dist/core/config.d.ts +117 -0
  146. package/dist/core/config.js +638 -0
  147. package/dist/core/disk-usage.d.ts +26 -0
  148. package/dist/core/disk-usage.js +83 -0
  149. package/dist/core/documents.d.ts +9 -0
  150. package/dist/core/documents.js +48 -0
  151. package/dist/core/entry.d.ts +316 -0
  152. package/dist/core/entry.js +711 -0
  153. package/dist/core/home.d.ts +76 -0
  154. package/dist/core/home.js +449 -0
  155. package/dist/core/i18n.d.ts +36 -0
  156. package/dist/core/i18n.js +458 -0
  157. package/dist/core/instances.d.ts +224 -0
  158. package/dist/core/instances.js +1272 -0
  159. package/dist/core/members.d.ts +190 -0
  160. package/dist/core/members.js +358 -0
  161. package/dist/core/mentions.d.ts +12 -0
  162. package/dist/core/mentions.js +49 -0
  163. package/dist/core/messages.d.ts +876 -0
  164. package/dist/core/messages.js +916 -0
  165. package/dist/core/notices.d.ts +88 -0
  166. package/dist/core/notices.js +54 -0
  167. package/dist/core/ops.d.ts +117 -0
  168. package/dist/core/ops.js +146 -0
  169. package/dist/core/package.d.ts +2 -0
  170. package/dist/core/package.js +14 -0
  171. package/dist/core/parts.d.ts +25 -0
  172. package/dist/core/parts.js +119 -0
  173. package/dist/core/plugins/catalog.d.ts +14 -0
  174. package/dist/core/plugins/catalog.js +54 -0
  175. package/dist/core/plugins/external.d.ts +7 -0
  176. package/dist/core/plugins/external.js +921 -0
  177. package/dist/core/plugins/index.d.ts +5 -0
  178. package/dist/core/plugins/index.js +51 -0
  179. package/dist/core/plugins/npm.d.ts +12 -0
  180. package/dist/core/plugins/npm.js +99 -0
  181. package/dist/core/plugins/plugin-manifest.d.ts +12 -0
  182. package/dist/core/plugins/plugin-manifest.js +231 -0
  183. package/dist/core/push.d.ts +22 -0
  184. package/dist/core/push.js +63 -0
  185. package/dist/core/resource.d.ts +77 -0
  186. package/dist/core/resource.js +48 -0
  187. package/dist/core/spawn.d.ts +12 -0
  188. package/dist/core/spawn.js +30 -0
  189. package/dist/core/storage-inventory.d.ts +118 -0
  190. package/dist/core/storage-inventory.js +279 -0
  191. package/dist/core/storage.d.ts +45 -0
  192. package/dist/core/storage.js +602 -0
  193. package/dist/core/store.d.ts +15 -0
  194. package/dist/core/store.js +33 -0
  195. package/dist/core/topic-index.d.ts +19 -0
  196. package/dist/core/topic-index.js +70 -0
  197. package/dist/core/topic-ops.d.ts +139 -0
  198. package/dist/core/topic-ops.js +507 -0
  199. package/dist/core/topic-status.d.ts +32 -0
  200. package/dist/core/topic-status.js +105 -0
  201. package/dist/core/topics.d.ts +327 -0
  202. package/dist/core/topics.js +786 -0
  203. package/dist/core/turn-clients.d.ts +1 -0
  204. package/dist/core/turn-clients.js +5 -0
  205. package/dist/core/types.d.ts +2866 -0
  206. package/dist/core/types.js +166 -0
  207. package/dist/core/util.d.ts +10 -0
  208. package/dist/core/util.js +47 -0
  209. package/dist/main.d.ts +12 -0
  210. package/dist/main.js +82 -0
  211. package/dist/plugins/adapter-acp/index.d.ts +3 -0
  212. package/dist/plugins/adapter-acp/index.js +57 -0
  213. package/dist/plugins/adapter-acp/plugin.yaml +100 -0
  214. package/dist/plugins/adapter-agy/command.d.ts +9 -0
  215. package/dist/plugins/adapter-agy/command.js +34 -0
  216. package/dist/plugins/adapter-agy/index.d.ts +5 -0
  217. package/dist/plugins/adapter-agy/index.js +65 -0
  218. package/dist/plugins/adapter-agy/quota.d.ts +2 -0
  219. package/dist/plugins/adapter-agy/quota.js +155 -0
  220. package/dist/plugins/adapter-agy/terminal.d.ts +6 -0
  221. package/dist/plugins/adapter-agy/terminal.js +132 -0
  222. package/dist/plugins/adapter-agy/version.d.ts +9 -0
  223. package/dist/plugins/adapter-agy/version.js +17 -0
  224. package/dist/plugins/adapter-claude/index.d.ts +43 -0
  225. package/dist/plugins/adapter-claude/index.js +412 -0
  226. package/dist/plugins/adapter-claude/quota.d.ts +14 -0
  227. package/dist/plugins/adapter-claude/quota.js +103 -0
  228. package/dist/plugins/adapter-codex/index.d.ts +4 -0
  229. package/dist/plugins/adapter-codex/index.js +688 -0
  230. package/dist/plugins/adapter-codex/responses-model.d.ts +9 -0
  231. package/dist/plugins/adapter-codex/responses-model.js +82 -0
  232. package/dist/plugins/adapter-kimi/index.d.ts +4 -0
  233. package/dist/plugins/adapter-kimi/index.js +51 -0
  234. package/dist/plugins/adapter-kimi/quota.d.ts +3 -0
  235. package/dist/plugins/adapter-kimi/quota.js +171 -0
  236. package/dist/plugins/adapter-opencode/index.d.ts +12 -0
  237. package/dist/plugins/adapter-opencode/index.js +64 -0
  238. package/dist/plugins/annotations/console/cards.css +189 -0
  239. package/dist/plugins/annotations/console/cards.mjs +439 -0
  240. package/dist/plugins/annotations/console/pdl.json +52 -0
  241. package/dist/plugins/annotations/console/view.mjs +241 -0
  242. package/dist/plugins/annotations/console/window.mjs +219 -0
  243. package/dist/plugins/annotations/followups.d.ts +51 -0
  244. package/dist/plugins/annotations/followups.js +112 -0
  245. package/dist/plugins/annotations/index.d.ts +3 -0
  246. package/dist/plugins/annotations/index.js +298 -0
  247. package/dist/plugins/annotations/plugin.yaml +3 -0
  248. package/dist/plugins/ask-choice/index.d.ts +9 -0
  249. package/dist/plugins/ask-choice/index.js +24 -0
  250. package/dist/plugins/ask-choice/plugin.yaml +2 -0
  251. package/dist/plugins/background/index.d.ts +2 -0
  252. package/dist/plugins/background/index.js +398 -0
  253. package/dist/plugins/background/plugin.yaml +7 -0
  254. package/dist/plugins/builtin.json +37 -0
  255. package/dist/plugins/cards/console/pdl.json +516 -0
  256. package/dist/plugins/cards/console/view.mjs +67 -0
  257. package/dist/plugins/cards/index.d.ts +8 -0
  258. package/dist/plugins/cards/index.js +627 -0
  259. package/dist/plugins/cards/plugin.yaml +3 -0
  260. package/dist/plugins/console/browser.d.ts +2 -0
  261. package/dist/plugins/console/browser.js +115 -0
  262. package/dist/plugins/console/console/pdl.json +38 -0
  263. package/dist/plugins/console/console/view.mjs +26 -0
  264. package/dist/plugins/console/index.d.ts +4 -0
  265. package/dist/plugins/console/index.js +94 -0
  266. package/dist/plugins/console/picker.d.ts +2 -0
  267. package/dist/plugins/console/picker.js +48 -0
  268. package/dist/plugins/console/plugin.yaml +3 -0
  269. package/dist/plugins/console/topic-view.d.ts +3 -0
  270. package/dist/plugins/console/topic-view.js +388 -0
  271. package/dist/plugins/handoff/index.d.ts +2 -0
  272. package/dist/plugins/handoff/index.js +147 -0
  273. package/dist/plugins/handoff/plugin.yaml +8 -0
  274. package/dist/plugins/host-api/index.d.ts +7 -0
  275. package/dist/plugins/host-api/index.js +310 -0
  276. package/dist/plugins/host-api/plugin.yaml +2 -0
  277. package/dist/plugins/host-api/signing.d.ts +63 -0
  278. package/dist/plugins/host-api/signing.js +427 -0
  279. package/dist/plugins/host-api/skills/host-ops/SKILL.md +28 -0
  280. package/dist/plugins/host-api/skills/hostlet-plugin-dev/SKILL.md +38 -0
  281. package/dist/plugins/inbox/index.d.ts +15 -0
  282. package/dist/plugins/inbox/index.js +161 -0
  283. package/dist/plugins/inbox/plugin.yaml +2 -0
  284. package/dist/plugins/keys/account-directories.d.ts +18 -0
  285. package/dist/plugins/keys/account-directories.js +86 -0
  286. package/dist/plugins/keys/account-storage.d.ts +18 -0
  287. package/dist/plugins/keys/account-storage.js +112 -0
  288. package/dist/plugins/keys/console/pdl.json +710 -0
  289. package/dist/plugins/keys/console/view.mjs +619 -0
  290. package/dist/plugins/keys/index.d.ts +7 -0
  291. package/dist/plugins/keys/index.js +842 -0
  292. package/dist/plugins/keys/login-link.d.ts +2 -0
  293. package/dist/plugins/keys/login-link.js +15 -0
  294. package/dist/plugins/keys/plugin.yaml +3 -0
  295. package/dist/plugins/keys/quota-history.d.ts +91 -0
  296. package/dist/plugins/keys/quota-history.js +420 -0
  297. package/dist/plugins/mcp/console/pdl.json +412 -0
  298. package/dist/plugins/mcp/console/view.mjs +207 -0
  299. package/dist/plugins/mcp/index.d.ts +7 -0
  300. package/dist/plugins/mcp/index.js +494 -0
  301. package/dist/plugins/mcp/plugin.yaml +3 -0
  302. package/dist/plugins/member-health/index.d.ts +2 -0
  303. package/dist/plugins/member-health/index.js +478 -0
  304. package/dist/plugins/member-health/plugin.yaml +2 -0
  305. package/dist/plugins/memory/capabilities.d.ts +10 -0
  306. package/dist/plugins/memory/capabilities.js +70 -0
  307. package/dist/plugins/memory/console/pdl.json +459 -0
  308. package/dist/plugins/memory/console/view.mjs +254 -0
  309. package/dist/plugins/memory/corpus.d.ts +60 -0
  310. package/dist/plugins/memory/corpus.js +521 -0
  311. package/dist/plugins/memory/engines/fts-tree-diversity.d.ts +8 -0
  312. package/dist/plugins/memory/engines/fts-tree-diversity.js +49 -0
  313. package/dist/plugins/memory/engines/fts-tree-text.d.ts +12 -0
  314. package/dist/plugins/memory/engines/fts-tree-text.js +93 -0
  315. package/dist/plugins/memory/engines/fts-tree.d.ts +4 -0
  316. package/dist/plugins/memory/engines/fts-tree.js +387 -0
  317. package/dist/plugins/memory/engines/search.d.ts +9 -0
  318. package/dist/plugins/memory/engines/search.js +35 -0
  319. package/dist/plugins/memory/index.d.ts +3 -0
  320. package/dist/plugins/memory/index.js +465 -0
  321. package/dist/plugins/memory/notes.d.ts +22 -0
  322. package/dist/plugins/memory/notes.js +140 -0
  323. package/dist/plugins/memory/plugin.yaml +23 -0
  324. package/dist/plugins/model-profiles/index.d.ts +2 -0
  325. package/dist/plugins/model-profiles/index.js +916 -0
  326. package/dist/plugins/model-profiles/plugin.yaml +13 -0
  327. package/dist/plugins/model-profiles/review-source.d.ts +11 -0
  328. package/dist/plugins/model-profiles/review-source.js +640 -0
  329. package/dist/plugins/model-profiles/rules.d.ts +130 -0
  330. package/dist/plugins/model-profiles/rules.js +729 -0
  331. package/dist/plugins/model-profiles/skills/model-profile/SKILL.md +59 -0
  332. package/dist/plugins/model-profiles/sources.d.ts +61 -0
  333. package/dist/plugins/model-profiles/sources.js +375 -0
  334. package/dist/plugins/model-profiles/storage.d.ts +84 -0
  335. package/dist/plugins/model-profiles/storage.js +315 -0
  336. package/dist/plugins/model-profiles/types.d.ts +179 -0
  337. package/dist/plugins/model-profiles/types.js +12 -0
  338. package/dist/plugins/model-profiles/wakeup.d.ts +29 -0
  339. package/dist/plugins/model-profiles/wakeup.js +390 -0
  340. package/dist/plugins/models/index.d.ts +2 -0
  341. package/dist/plugins/models/index.js +63 -0
  342. package/dist/plugins/models/plugin.yaml +8 -0
  343. package/dist/plugins/ops/collector.d.ts +22 -0
  344. package/dist/plugins/ops/collector.js +48 -0
  345. package/dist/plugins/ops/config.d.ts +11 -0
  346. package/dist/plugins/ops/config.js +13 -0
  347. package/dist/plugins/ops/console/pdl.json +676 -0
  348. package/dist/plugins/ops/console/view.mjs +700 -0
  349. package/dist/plugins/ops/index.d.ts +3 -0
  350. package/dist/plugins/ops/index.js +20 -0
  351. package/dist/plugins/ops/journal.d.ts +7 -0
  352. package/dist/plugins/ops/journal.js +109 -0
  353. package/dist/plugins/ops/metrics.d.ts +3 -0
  354. package/dist/plugins/ops/metrics.js +81 -0
  355. package/dist/plugins/ops/plugin.yaml +63 -0
  356. package/dist/plugins/ops/samples.d.ts +54 -0
  357. package/dist/plugins/ops/samples.js +100 -0
  358. package/dist/plugins/ops/trace.d.ts +3 -0
  359. package/dist/plugins/ops/trace.js +104 -0
  360. package/dist/plugins/ops/usage.d.ts +2 -0
  361. package/dist/plugins/ops/usage.js +152 -0
  362. package/dist/plugins/plans/acceptance.d.ts +284 -0
  363. package/dist/plugins/plans/acceptance.js +247 -0
  364. package/dist/plugins/plans/blocked.d.ts +25 -0
  365. package/dist/plugins/plans/blocked.js +66 -0
  366. package/dist/plugins/plans/console/pdl.json +639 -0
  367. package/dist/plugins/plans/console/view.d.mts +2 -0
  368. package/dist/plugins/plans/console/view.mjs +855 -0
  369. package/dist/plugins/plans/dependencies.d.ts +5 -0
  370. package/dist/plugins/plans/dependencies.js +21 -0
  371. package/dist/plugins/plans/index.d.ts +72 -0
  372. package/dist/plugins/plans/index.js +2057 -0
  373. package/dist/plugins/plans/plugin.yaml +44 -0
  374. package/dist/plugins/plans/progress.d.ts +82 -0
  375. package/dist/plugins/plans/progress.js +516 -0
  376. package/dist/plugins/prompt/index.d.ts +8 -0
  377. package/dist/plugins/prompt/index.js +361 -0
  378. package/dist/plugins/prompt/plugin.yaml +2 -0
  379. package/dist/plugins/recovery/console/pdl.json +50 -0
  380. package/dist/plugins/recovery/console/view.mjs +46 -0
  381. package/dist/plugins/recovery/index.d.ts +9 -0
  382. package/dist/plugins/recovery/index.js +454 -0
  383. package/dist/plugins/recovery/plugin.yaml +9 -0
  384. package/dist/plugins/recovery/probe.d.ts +11 -0
  385. package/dist/plugins/recovery/probe.js +128 -0
  386. package/dist/plugins/restart/console/pdl.json +112 -0
  387. package/dist/plugins/restart/console/view.mjs +85 -0
  388. package/dist/plugins/restart/index.d.ts +10 -0
  389. package/dist/plugins/restart/index.js +669 -0
  390. package/dist/plugins/restart/plugin.yaml +9 -0
  391. package/dist/plugins/restart/scope.d.ts +6 -0
  392. package/dist/plugins/restart/scope.js +44 -0
  393. package/dist/plugins/schedule/console/pdl.json +696 -0
  394. package/dist/plugins/schedule/console/view.mjs +398 -0
  395. package/dist/plugins/schedule/events.d.ts +76 -0
  396. package/dist/plugins/schedule/events.js +158 -0
  397. package/dist/plugins/schedule/index.d.ts +32 -0
  398. package/dist/plugins/schedule/index.js +1199 -0
  399. package/dist/plugins/schedule/plugin.yaml +26 -0
  400. package/dist/plugins/schedule/when.d.ts +14 -0
  401. package/dist/plugins/schedule/when.js +83 -0
  402. package/dist/plugins/sessions/console/pdl.json +259 -0
  403. package/dist/plugins/sessions/console/view.mjs +355 -0
  404. package/dist/plugins/sessions/index.d.ts +3 -0
  405. package/dist/plugins/sessions/index.js +126 -0
  406. package/dist/plugins/sessions/participants.d.ts +28 -0
  407. package/dist/plugins/sessions/participants.js +83 -0
  408. package/dist/plugins/sessions/plugin.yaml +3 -0
  409. package/dist/plugins/signals/console/pdl.json +802 -0
  410. package/dist/plugins/signals/console/view.mjs +284 -0
  411. package/dist/plugins/signals/content.d.ts +31 -0
  412. package/dist/plugins/signals/content.js +151 -0
  413. package/dist/plugins/signals/index.d.ts +2 -0
  414. package/dist/plugins/signals/index.js +601 -0
  415. package/dist/plugins/signals/plugin.yaml +32 -0
  416. package/dist/plugins/signals/skills/signal-sources/SKILL.md +27 -0
  417. package/dist/plugins/skills/console/pdl.json +254 -0
  418. package/dist/plugins/skills/console/view.mjs +204 -0
  419. package/dist/plugins/skills/index.d.ts +11 -0
  420. package/dist/plugins/skills/index.js +567 -0
  421. package/dist/plugins/skills/install.d.ts +69 -0
  422. package/dist/plugins/skills/install.js +265 -0
  423. package/dist/plugins/skills/plugin.yaml +24 -0
  424. package/dist/plugins/skills/safety-scan.d.ts +17 -0
  425. package/dist/plugins/skills/safety-scan.js +78 -0
  426. package/dist/plugins/skills/skills/skill-ops/SKILL.md +29 -0
  427. package/dist/plugins/terminal/console/pdl.json +115 -0
  428. package/dist/plugins/terminal/console/view.mjs +178 -0
  429. package/dist/plugins/terminal/index.d.ts +3 -0
  430. package/dist/plugins/terminal/index.js +204 -0
  431. package/dist/plugins/terminal/plugin.yaml +2 -0
  432. package/dist/plugins/tools/index.d.ts +3 -0
  433. package/dist/plugins/tools/index.js +455 -0
  434. package/dist/plugins/tools/plugin.yaml +2 -0
  435. package/dist/plugins/tools/token.d.ts +61 -0
  436. package/dist/plugins/tools/token.js +179 -0
  437. package/dist/plugins/topic-tools/index.d.ts +9 -0
  438. package/dist/plugins/topic-tools/index.js +29 -0
  439. package/dist/plugins/topic-tools/plugin.yaml +2 -0
  440. package/dist/plugins/topic-tools/skills/topic-tidy/SKILL.md +108 -0
  441. package/dist/plugins/works/console/pdl.json +120 -0
  442. package/dist/plugins/works/console/view.mjs +91 -0
  443. package/dist/plugins/works/document-words.d.ts +50 -0
  444. package/dist/plugins/works/document-words.js +27 -0
  445. package/dist/plugins/works/editors.d.ts +3 -0
  446. package/dist/plugins/works/editors.js +162 -0
  447. package/dist/plugins/works/events.d.ts +58 -0
  448. package/dist/plugins/works/events.js +82 -0
  449. package/dist/plugins/works/files.d.ts +23 -0
  450. package/dist/plugins/works/files.js +53 -0
  451. package/dist/plugins/works/index.d.ts +9 -0
  452. package/dist/plugins/works/index.js +1088 -0
  453. package/dist/plugins/works/plugin.yaml +9 -0
  454. package/dist/plugins/works/preview.d.ts +10 -0
  455. package/dist/plugins/works/preview.js +30 -0
  456. package/dist/plugins/works/project.d.ts +3 -0
  457. package/dist/plugins/works/project.js +245 -0
  458. package/dist/plugins/works/resource.d.ts +28 -0
  459. package/dist/plugins/works/resource.js +71 -0
  460. package/dist/plugins/works/retention.d.ts +36 -0
  461. package/dist/plugins/works/retention.js +295 -0
  462. package/dist/plugins/works/skills/works-ops/SKILL.md +14 -0
  463. package/dist/plugins/works/viewers.d.ts +13 -0
  464. package/dist/plugins/works/viewers.js +87 -0
  465. package/dist/plugins/works/web/anchors.js +94 -0
  466. package/dist/plugins/works/web/document-edit.js +245 -0
  467. package/dist/plugins/works/web/preview-bridge.js +142 -0
  468. package/dist/plugins/works/web/reading-position.js +74 -0
  469. package/dist/plugins/works/web/view.html +1118 -0
  470. package/dist/runtime/runtime.d.ts +210 -0
  471. package/dist/runtime/runtime.js +338 -0
  472. package/dist/sdk/adapter-kit.d.ts +1 -0
  473. package/dist/sdk/adapter-kit.js +1 -0
  474. package/dist/sdk/client.d.ts +163 -0
  475. package/dist/sdk/client.js +43 -0
  476. package/dist/sdk/contracts.d.ts +1263 -0
  477. package/dist/sdk/contracts.js +1 -0
  478. package/dist/sdk/index.d.ts +57 -0
  479. package/dist/sdk/index.js +27 -0
  480. package/dist/sdk/source-choice.d.ts +40 -0
  481. package/dist/sdk/source-choice.js +217 -0
  482. package/dist/sdk/topic-text.d.ts +5 -0
  483. package/dist/sdk/topic-text.js +26 -0
  484. package/dist/sdk/transport.d.ts +12 -0
  485. package/dist/sdk/transport.js +34 -0
  486. package/node_modules/@hostlet/adapter-kit/dist/acp.d.ts +88 -0
  487. package/node_modules/@hostlet/adapter-kit/dist/acp.js +674 -0
  488. package/node_modules/@hostlet/adapter-kit/dist/command.d.ts +18 -0
  489. package/node_modules/@hostlet/adapter-kit/dist/command.js +39 -0
  490. package/node_modules/@hostlet/adapter-kit/dist/index.d.ts +8 -0
  491. package/node_modules/@hostlet/adapter-kit/dist/index.js +6 -0
  492. package/node_modules/@hostlet/adapter-kit/dist/models.d.ts +29 -0
  493. package/node_modules/@hostlet/adapter-kit/dist/models.js +108 -0
  494. package/node_modules/@hostlet/adapter-kit/dist/quota.d.ts +3 -0
  495. package/node_modules/@hostlet/adapter-kit/dist/quota.js +4 -0
  496. package/node_modules/@hostlet/adapter-kit/dist/rpc.d.ts +29 -0
  497. package/node_modules/@hostlet/adapter-kit/dist/rpc.js +84 -0
  498. package/node_modules/@hostlet/adapter-kit/dist/upstream-failure.d.ts +5 -0
  499. package/node_modules/@hostlet/adapter-kit/dist/upstream-failure.js +37 -0
  500. package/node_modules/@hostlet/adapter-kit/package.json +16 -0
  501. package/node_modules/@hostlet/platform/dist/desktop.d.ts +16 -0
  502. package/node_modules/@hostlet/platform/dist/desktop.js +270 -0
  503. package/node_modules/@hostlet/platform/dist/files.d.ts +24 -0
  504. package/node_modules/@hostlet/platform/dist/files.js +113 -0
  505. package/node_modules/@hostlet/platform/dist/index.d.ts +6 -0
  506. package/node_modules/@hostlet/platform/dist/index.js +4 -0
  507. package/node_modules/@hostlet/platform/dist/paths.d.ts +4 -0
  508. package/node_modules/@hostlet/platform/dist/paths.js +9 -0
  509. package/node_modules/@hostlet/platform/dist/process.d.ts +45 -0
  510. package/node_modules/@hostlet/platform/dist/process.js +297 -0
  511. package/node_modules/@hostlet/platform/package.json +14 -0
  512. package/package.json +60 -4
@@ -0,0 +1,627 @@
1
+ import { existsSync, realpathSync, statSync } from 'node:fs';
2
+ import { resolve, sep } from 'node:path';
3
+ import { address, errorText, HttpError, log, object, OWNER_ID, sendUserFile, visibleTo, messageGist, } from 'hostlet/sdk';
4
+ /** How a card is answered: what its kind says before the first dot. */
5
+ const base = (kind) => kind.split('.')[0];
6
+ const cardOf = (message, ask) => ask === undefined
7
+ ? (message?.parts[0]?.type === 'card' && message.parts[0].ask === undefined ? message.parts[0] : undefined)
8
+ : message?.parts.findLast((part) => part.type === 'card' && part.ask === ask);
9
+ const pendingAsk = (part) => part.type === 'card' && part.ask !== undefined && part.state === 'pending';
10
+ const closedAsk = (part) => pendingAsk(part)
11
+ ? { ...part, state: 'closed', rev: part.rev + 1, note: '这一轮结束了' }
12
+ : part;
13
+ const done = (result) => `${result.unconfirmed ? '执行结果待确认' : result.ok ? '已完成' : '失败'}${result.text ? `:${result.text}` : ''}`;
14
+ const whenWords = { approve: '赞成时', reject: '反对时', always: '每票' };
15
+ const under = (text) => text.split('\n').map((line) => ` ${line}`).join('\n');
16
+ /** What was answered, in words. */
17
+ function answerText(card) {
18
+ const { picked = [], text, approved } = card.answer;
19
+ const labels = picked.map((id) => `「${card.options?.find((o) => o.id === id)?.label ?? id}」`).join('');
20
+ if (base(card.kind) === 'approval')
21
+ return `${approved ? '已同意' : '已拒绝'}${labels}${card.answer.remember ? `(${card.remember})` : ''}${text ? `。${text}` : ''}`;
22
+ return labels ? `选了${labels}${text ? `。补充:${text}` : ''}` : text ?? '';
23
+ }
24
+ /**
25
+ * A card in words: what a message's `content` is when the message is a card. Whatever reads text (a member handed
26
+ * the channel, a search, someone looking through the channel file) reads the card as it is now.
27
+ */
28
+ export function cardText(card, name) {
29
+ const approval = base(card.kind) === 'approval';
30
+ const state = card.state === 'closed' ? '已撤回' : card.state === 'pending' ? (approval ? '等批准' : '等答复') : !approval ? '已答' : card.answer?.approved ? '已同意' : '已拒绝';
31
+ const choice = card.answer?.picked?.[0];
32
+ const items = (card.items ?? []).filter((item) => item.option === undefined || card.state === 'pending' || item.option === choice);
33
+ const lines = [`[${[approval ? '审批卡' : '选项卡', ...(approval ? [] : [card.multi ? '多选' : '单选']), state].join(' · ')}]${card.by ? `${name(card.by)} 提请:` : ''}${card.title}`];
34
+ if (card.body)
35
+ lines.push(card.body);
36
+ for (const [i, option] of (card.options ?? []).entries())
37
+ lines.push(`${i + 1}. ${option.label}${option.image ? `(图:${option.image})` : ''}${option.detail ? `\n${under(option.detail)}` : ''}`);
38
+ if (!approval && card.other !== false && card.state === 'pending')
39
+ lines.push('(也可以自己写)');
40
+ for (const [i, item] of items.entries()) {
41
+ const option = card.state === 'pending' && card.options?.find((one) => one.id === item.option);
42
+ const heading = item.title ? `${i + 1}. ${option ? `「${option.label}」` : ''}${item.title}` : option ? `${i + 1}. 「${option.label}」` : '';
43
+ const line = (text) => (heading ? under(text) : text);
44
+ if (heading)
45
+ lines.push(heading);
46
+ if (item.detail)
47
+ lines.push(line(item.detail));
48
+ for (const field of item.inputs ?? []) {
49
+ const filled = card.answer?.filled?.[item.id]?.includes(field.path);
50
+ lines.push(line(`- ${field.label}:${filled ? '已填写' : card.state === 'pending' ? (field.required ? '待机主填写(必填)' : '机主可选填') : '未填写'}`));
51
+ }
52
+ for (const { label, value } of item.fields ?? [])
53
+ lines.push(line(`- ${label}:${value}`));
54
+ if (item.code)
55
+ lines.push(line([item.code.label, '```', item.code.text, '```'].join('\n')));
56
+ }
57
+ const signs = card.signs ?? [];
58
+ if (card.quorum && signs.length) {
59
+ lines.push(`成员签名 ${signs.filter((one) => one.approved).length}/${card.quorum.need}:`);
60
+ for (const one of signs) {
61
+ const values = Object.entries(one.values ?? {}).map(([key, value]) => `${key}=${value}`).join(',');
62
+ lines.push(under(`- ${name(one.by)} ${one.approved ? '赞成' : '反对'}:${one.text}${values ? `(${values})` : ''}`));
63
+ }
64
+ }
65
+ if (card.state === 'pending' && card.quorum?.blocked)
66
+ lines.push(`成员会签已停止:${card.quorum.blocked}。等机主裁决`);
67
+ else if (card.state === 'pending' && card.quorum?.openedAt !== undefined && card.quorum.who.length) {
68
+ const fields = card.quorum.fields ?? [];
69
+ lines.push(`可签名:${card.quorum.who.map(name).join('、')}。用 host_invoke 调 cards.answer(id、rev、approved、text${fields.length ? ',按下列字段填 values' : ''}),每人一票,必须写理由`);
70
+ for (const field of fields) {
71
+ lines.push(under(`- values.${field.key}:${field.label}${field.options ? `(${field.options.join(' / ')})` : ''},${whenWords[field.when]}${field.required ? '必填' : '可填'}`));
72
+ }
73
+ }
74
+ if (card.answer)
75
+ lines.push(card.answer.via === 'quorum' ? `成员会签:${card.answer.approved ? '通过' : '未通过'}` : `${name(card.answer.by)}:${answerText(card)}`);
76
+ const outcome = card.outcome ?? (items.length === 1 ? items[0]?.result : undefined);
77
+ if (outcome)
78
+ lines.push(`执行:${done(outcome)}`);
79
+ if (items.length > 1) {
80
+ for (const [i, item] of items.entries()) {
81
+ if (item.result)
82
+ lines.push(` ${i + 1}. ${item.title} → ${done(item.result)}`);
83
+ else if (outcome && choice !== undefined)
84
+ lines.push(` ${i + 1}. ${item.title} → 未执行`);
85
+ }
86
+ }
87
+ if (card.state === 'closed' && card.note)
88
+ lines.push(`已撤回:${card.note}`);
89
+ return lines.join('\n');
90
+ }
91
+ /** What is asked, as it is kept: checked, and with every option and item under an id of its own. */
92
+ function asked(input) {
93
+ const { kind, title, body, by, data } = input;
94
+ if (typeof kind !== 'string' || !/^(choice|approval)(\.[\w-]+)*$/.test(kind))
95
+ throw new Error(`卡的类型要是 choice 或 approval,或它们下面的一种(approval.名字):${String(kind)}`);
96
+ if (typeof title !== 'string' || !title.trim())
97
+ throw new Error('卡要有一句话说问的是什么(title)');
98
+ const numbered = (list, what, says) => {
99
+ if (!Array.isArray(list) || !list.length)
100
+ throw new Error(`${what}不能是空的`);
101
+ const made = list.map((one, i) => ({ ...one, id: one.id ? String(one.id) : String(i + 1) }));
102
+ if (says && made.some((one) => typeof says(one) !== 'string' || !String(says(one)).trim()))
103
+ throw new Error(`${what}里每一项都要有一句话`);
104
+ if (new Set(made.map((one) => one.id)).size !== made.length)
105
+ throw new Error(`${what}里有两项的 id 一样`);
106
+ return made;
107
+ };
108
+ const choice = base(kind) === 'choice';
109
+ const options = choice || input.options ? numbered(input.options, '选项', (o) => o.label) : undefined;
110
+ if (input.expiresAt !== undefined && (typeof input.expiresAt !== 'number' || !Number.isFinite(input.expiresAt))) {
111
+ throw new Error('expiresAt 要是时间戳');
112
+ }
113
+ const common = {
114
+ kind, title: title.trim(), ...(body ? { body } : {}), ...(input.i18n ? { i18n: input.i18n } : {}),
115
+ ...(by ? { by } : {}), ...(data ? { data } : {}), ...(options ? { options } : {}),
116
+ ...(input.expiresAt !== undefined ? { expiresAt: input.expiresAt } : {}),
117
+ };
118
+ if (choice) {
119
+ if (input.quorum)
120
+ throw new Error('选项卡不能让成员签名,只有不带方案的审批卡可以');
121
+ return { ...common, ...(input.multi ? { multi: true } : {}), ...(input.other === false ? { other: false } : {}) };
122
+ }
123
+ const items = numbered(input.items, '要批的事').map(({ title: itemTitle, fields, code, ...item }, _, list) => {
124
+ const trimmed = typeof itemTitle === 'string' ? itemTitle.trim() : '';
125
+ const validFields = Array.isArray(fields) ? fields.flatMap((field) => {
126
+ if (typeof field?.label !== 'string' || !field.label.trim() || typeof field.value !== 'string' || !field.value.trim())
127
+ return [];
128
+ return [{ label: field.label, value: field.value, ...(field.tone === 'warn' ? { tone: field.tone } : {}) }];
129
+ }) : [];
130
+ const validCode = typeof code?.label === 'string' && code.label.trim() && typeof code.text === 'string' && code.text.trim()
131
+ ? { label: code.label, text: code.text } : undefined;
132
+ if (list.length > 1 && !trimmed)
133
+ throw new Error('要批的事里每一项都要有一句话');
134
+ if (!trimmed && !item.detail?.trim() && !validFields.length && !validCode && !item.inputs?.length) {
135
+ throw new Error('要批的事里每一项都要有内容');
136
+ }
137
+ return {
138
+ ...item,
139
+ ...(trimmed ? { title: trimmed } : {}),
140
+ ...(validFields.length ? { fields: validFields } : {}),
141
+ ...(validCode ? { code: validCode } : {}),
142
+ };
143
+ });
144
+ const quorum = input.quorum && quorumOf(input.quorum, !!options);
145
+ if (items.some((item) => item.inputs?.length) && (quorum || input.remember))
146
+ throw new Error('带机主补填项的卡须由机主逐次批准');
147
+ return {
148
+ ...common, items, ...(input.approve ? { approve: input.approve } : {}), ...(input.reject ? { reject: input.reject } : {}),
149
+ ...(input.remember?.trim() && !input.options ? { remember: input.remember.trim() } : {}),
150
+ ...(quorum ? { quorum } : {}),
151
+ };
152
+ }
153
+ /** Who besides the people asked may sign: checked as it is kept. */
154
+ function quorumOf(quorum, withOptions) {
155
+ const { need, who, openedAt, onReject = 'block', fields, blocked } = quorum;
156
+ if (withOptions)
157
+ throw new Error('带方案的审批卡不能让成员签名');
158
+ if (!Number.isInteger(need) || need < 1)
159
+ throw new Error('quorum.need 要是正整数');
160
+ if (!Array.isArray(who) || who.some((id) => typeof id !== 'string') || new Set(who).size !== who.length)
161
+ throw new Error('quorum.who 是不重复的成员编号');
162
+ if (fields && new Set(fields.map((field) => field.key)).size !== fields.length)
163
+ throw new Error('quorum.fields 里有两项的 key 一样');
164
+ return { need, who, ...(openedAt !== undefined ? { openedAt } : {}), onReject, ...(fields?.length ? { fields } : {}), ...(blocked ? { blocked } : {}) };
165
+ }
166
+ /** What a member gives with its vote, as the card declares it. */
167
+ function fieldValues(fields, approved, values = {}) {
168
+ const stage = approved ? 'approve' : 'reject';
169
+ const unknown = Object.keys(values).find((key) => !fields.some((field) => field.key === key));
170
+ if (unknown !== undefined)
171
+ throw new Error(`这张卡没有 values.${unknown} 这一项`);
172
+ const kept = {};
173
+ for (const field of fields) {
174
+ const value = values[field.key]?.trim();
175
+ if (field.when !== 'always' && field.when !== stage) {
176
+ if (value)
177
+ throw new Error(`values.${field.key}(${field.label})只在${whenWords[field.when]}填`);
178
+ continue;
179
+ }
180
+ if (!value) {
181
+ if (field.required)
182
+ throw new Error(`要填 values.${field.key}(${field.label})`);
183
+ continue;
184
+ }
185
+ if (field.options && !field.options.includes(value))
186
+ throw new Error(`values.${field.key}(${field.label})只能是:${field.options.join('、')}`);
187
+ kept[field.key] = value;
188
+ }
189
+ return Object.keys(kept).length ? kept : undefined;
190
+ }
191
+ /** What a person gave as an answer, checked against the card it answers. */
192
+ function given(card, { picked, text, approved, remember }) {
193
+ const words = text?.trim();
194
+ const chosen = [...new Set(picked ?? [])];
195
+ if (base(card.kind) === 'approval') {
196
+ if (typeof approved !== 'boolean' || (picked && (!approved || !card.options)))
197
+ throw new Error('审批卡的答复是批准或不批准(approved)');
198
+ if (approved && card.options && (chosen.length !== 1 || !card.options.some((option) => option.id === chosen[0]))) {
199
+ throw new Error('批准前请选择一个方案');
200
+ }
201
+ if (remember && (!approved || !card.remember))
202
+ throw new Error('这张卡没有「以后都允许」,或没有批准');
203
+ return { approved, ...(remember ? { remember } : {}), ...(chosen.length ? { picked: chosen } : {}), ...(words ? { text: words } : {}) };
204
+ }
205
+ if (approved !== undefined || remember !== undefined)
206
+ throw new Error('选项卡的答复是选了哪几个(picked)和自己写的话(text)');
207
+ const unknown = chosen.find((id) => !card.options?.some((o) => o.id === id));
208
+ if (unknown !== undefined)
209
+ throw new Error(`这张卡没有这个选项:${unknown}`);
210
+ if (!card.multi && chosen.length > 1)
211
+ throw new Error('这张卡只能选一个');
212
+ if (words && card.other === false)
213
+ throw new Error('这张卡只能在选项里选');
214
+ if (!chosen.length && !words)
215
+ throw new Error('还没有选,也没有写');
216
+ return { picked: chosen, ...(words ? { text: words } : {}) };
217
+ }
218
+ const cardsPlugin = {
219
+ name: 'cards',
220
+ title: '卡片',
221
+ about: '选项、审批和回合权限确认。每张卡在原消息上作答,收件箱引用同一条消息。',
222
+ group: '沟通',
223
+ needs: ['entry', 'members', 'topics', 'messages', 'a2a', 'instances', 'push'],
224
+ start(ctx) {
225
+ const entry = ctx.get('entry');
226
+ const members = ctx.get('members');
227
+ const topics = ctx.get('topics');
228
+ const messages = ctx.get('messages');
229
+ const a2a = ctx.get('a2a');
230
+ const instances = ctx.get('instances');
231
+ const push = ctx.get('push');
232
+ const name = (memberId) => members.get(memberId)?.name ?? memberId;
233
+ const isPerson = (id) => members.get(id)?.kind === 'person';
234
+ const askerOf = (from, by) => from.kind === 'member' && members.get(from.id)?.adapter ? from.id : by;
235
+ const need = (id, ask) => {
236
+ const message = messages.stored(id);
237
+ const card = cardOf(message, ask);
238
+ if (!message || !card)
239
+ throw new HttpError(404, '没有这张卡');
240
+ return { message, card };
241
+ };
242
+ /** The original message is one revision further on. */
243
+ const put = (message, card, tell = []) => {
244
+ const now = { ...card, type: 'card', rev: card.rev + 1 };
245
+ if (now.ask !== undefined) {
246
+ const reply = a2a.reviseReply(message.topicId, message.from.id, message.turnId, (parts) => parts.map((part) => part.type === 'card' && part.ask === now.ask ? now : part));
247
+ if (!reply)
248
+ throw new HttpError(409, '这一轮已经结束了');
249
+ return reply;
250
+ }
251
+ return messages.revise(message.id, {
252
+ content: cardText(now, name), parts: [now, ...message.parts.slice(1)],
253
+ tell: tell.filter((id) => members.canReceive(id)),
254
+ });
255
+ };
256
+ const recordAnswer = (message, card, answer, tell) => {
257
+ const now = put(message, { ...card, state: 'answered', answer }, tell);
258
+ const answered = { message: now, card: cardOf(now, card.ask), answer };
259
+ ctx.runtime.emit('card.answered', answered);
260
+ return answered;
261
+ };
262
+ const consumeAnswer = async (consume, answered) => {
263
+ const { message: { id, from }, card } = answered;
264
+ let outcome;
265
+ try {
266
+ outcome = await consume(answered);
267
+ }
268
+ catch (error) {
269
+ const reason = card.answer?.filled ? '审批执行失败,请核对目标和补填参数' : errorText(error);
270
+ log('cards', `what ${from.id} does with the answer to ${id} failed`, card.answer?.filled ? reason : error);
271
+ outcome = { ok: false, text: reason };
272
+ }
273
+ const latest = messages.get(id);
274
+ const requester = card.by && members.get(card.by)?.enabled && latest && !latest.to.includes(card.by) ? card.by : undefined;
275
+ if (outcome || requester)
276
+ cards.report(id, { ...(outcome ? { outcome } : {}), ...(requester ? { tell: [requester] } : {}) });
277
+ };
278
+ /** Invited members who have not voted no longer need to read a card that does not wait for them. */
279
+ const release = (message) => {
280
+ const card = cardOf(message);
281
+ const voted = new Set(card?.signs?.map((one) => one.by));
282
+ for (const id of card?.quorum?.who ?? [])
283
+ if (!voted.has(id))
284
+ a2a.markRead(message.topicId, id, message.id);
285
+ };
286
+ const changed = (card) => {
287
+ const signs = (card.signs ?? []).map((one) => `${name(one.by)}${one.approved ? '赞成' : '反对'}「${one.text}」`).join('、');
288
+ return `这张卡刚变了(现在是 rev ${card.rev}${signs ? `;已签:${signs}` : ''}),再看一眼`;
289
+ };
290
+ /**
291
+ * Keep the answer that settles a card and hand it to whoever consumes it. Members' votes are offered to the sender
292
+ * first: it may refuse them, and then nothing is settled.
293
+ */
294
+ const settle = (message, card, answer, ask, inputs) => {
295
+ let consumer;
296
+ let prepare;
297
+ let refused;
298
+ const items = answer.approved ? (card.items ?? []).filter((item) => item.option === answer.picked?.[0] && item.inputs?.length) : [];
299
+ const form = items.length > 0;
300
+ if (inputs && (!form || Object.keys(inputs).some((id) => !items.some((item) => item.id === id)))) {
301
+ throw new HttpError(400, '只可提交所批准步骤的补填字段');
302
+ }
303
+ if (form) {
304
+ if (answer.by !== OWNER_ID || answer.via === 'quorum')
305
+ throw new HttpError(403, '补填须由机主本人提交');
306
+ const filled = {};
307
+ for (const item of items) {
308
+ const values = inputs?.[item.id] ?? {};
309
+ if (Object.keys(values).some((path) => !item.inputs.some((field) => field.path === path)))
310
+ throw new HttpError(400, '提交含有卡上未声明的字段');
311
+ const provided = item.inputs.filter((field) => values[field.path]?.trim());
312
+ const missing = item.inputs.find((field) => field.required && !provided.includes(field));
313
+ if (missing)
314
+ throw new HttpError(400, `请填写「${missing.label}」`);
315
+ filled[item.id] = provided.map((field) => field.path);
316
+ }
317
+ answer.filled = filled;
318
+ }
319
+ const deliversAnswer = message.from.kind === 'member' && members.acceptsDelivery(message.from.id);
320
+ if (!deliversAnswer || form) {
321
+ ctx.runtime.emit('card.answering', {
322
+ message, answer, accept: (consume) => { consumer ??= consume; },
323
+ ...(form && { acceptInputs(owner, bind) {
324
+ if (members.ownsSender(owner, message.from.id))
325
+ prepare = bind;
326
+ } }),
327
+ ...(answer.via === 'quorum' ? { refuse: (reason) => { refused ??= reason; } } : {}),
328
+ });
329
+ if (refused !== undefined)
330
+ return { refused };
331
+ if (form) {
332
+ if (!prepare)
333
+ throw new HttpError(409, '负责这张卡的插件现在不能接收补填');
334
+ try {
335
+ consumer = prepare(inputs ?? {});
336
+ }
337
+ catch (error) {
338
+ if (!Object.values(answer.filled).some((paths) => paths.length))
339
+ throw error;
340
+ throw new HttpError(error instanceof HttpError ? error.status : 400, '目标或补填参数未通过校验,请核对所选步骤');
341
+ }
342
+ }
343
+ if (!consumer)
344
+ throw new HttpError(409, '发这张卡的插件现在没在运行,答了也没有人接');
345
+ }
346
+ const answered = recordAnswer(message, card, answer, ask === undefined && deliversAnswer ? [message.from.id] : []);
347
+ if (ask === undefined) {
348
+ a2a.markRead(message.topicId, answer.by, message.id);
349
+ release(answered.message);
350
+ }
351
+ if (consumer) {
352
+ const consume = consumer;
353
+ void Promise.resolve().then(() => consumeAnswer(consume, answered))
354
+ .catch((error) => log('cards', `the outcome of ${message.id} could not be written`, error));
355
+ }
356
+ return answered.message;
357
+ };
358
+ const signed = (message, signature) => {
359
+ a2a.markRead(message.topicId, signature.by, message.id);
360
+ ctx.runtime.emit('card.signed', { message, card: cardOf(message), signature });
361
+ return message;
362
+ };
363
+ /** Members' votes stop counting: the card waits for the people it asks. */
364
+ const block = (message, card, reason, signature) => {
365
+ const now = put(message, { ...card, quorum: { ...card.quorum, blocked: reason } });
366
+ release(now);
367
+ return signature ? signed(now, signature) : now;
368
+ };
369
+ const sign = (message, card, by, said, values, turnId) => {
370
+ const quorum = card.quorum;
371
+ if (quorum.blocked)
372
+ throw new HttpError(409, `成员会签已停止:${quorum.blocked}`);
373
+ if (card.signs?.some((one) => one.by === by))
374
+ throw new HttpError(409, '你已经签过这张卡了');
375
+ const { approved, picked, remember } = said;
376
+ if (typeof approved !== 'boolean' || picked || remember)
377
+ throw new Error('签名的答复是批准或不批准(approved)');
378
+ const text = said.text?.trim();
379
+ if (!text)
380
+ throw new Error('签名要写理由(text)');
381
+ const kept = fieldValues(quorum.fields ?? [], approved, values);
382
+ const signature = { by, at: Date.now(), ...(turnId ? { turnId } : {}), approved, text, ...(kept ? { values: kept } : {}) };
383
+ const signs = [...(card.signs ?? []), signature];
384
+ const settles = approved ? signs.filter((one) => one.approved).length >= quorum.need : quorum.onReject === 'reject';
385
+ if (settles) {
386
+ const result = settle(message, { ...card, signs }, { by, at: signature.at, approved, via: 'quorum', signs });
387
+ if (!('refused' in result))
388
+ return signed(result, signature);
389
+ return block(message, { ...card, signs }, result.refused, signature);
390
+ }
391
+ if (!approved)
392
+ return block(message, { ...card, signs }, `${name(by)} 反对:${text}`, signature);
393
+ return signed(put(message, { ...card, signs }), signature);
394
+ };
395
+ const floorExcerpt = (message) => {
396
+ const clean = message ? messageGist(message).replace(/\s+/g, ' ') : '';
397
+ const chars = [...clean];
398
+ return chars.length > 16 ? `${chars.slice(0, 16).join('')}…` : clean || '原楼';
399
+ };
400
+ const cards = {
401
+ send({ topicId, from, card, to = [OWNER_ID], replyTo, inbox }) {
402
+ if (!to.length || !to.every(isPerson))
403
+ throw new Error('卡是发给人的');
404
+ const asker = askerOf(from, card.by);
405
+ const sourceThread = replyTo === undefined && asker ? a2a.live(topicId).find((turn) => turn.memberId === asker)?.thread : undefined;
406
+ const made = { ...asked(card), rev: 0, state: 'pending' };
407
+ // Who may answer as a person is fixed here: members told about the card later never become one.
408
+ if (made.quorum)
409
+ made.to = to;
410
+ else if (inbox === false)
411
+ throw new Error('不进收件箱的卡要有能签名的成员(quorum)');
412
+ const invited = made.quorum?.openedAt !== undefined ? made.quorum.who : [];
413
+ if (invited.some(isPerson))
414
+ throw new Error('quorum.who 是成员,不是人');
415
+ const parts = [{ type: 'card', ...made }];
416
+ if (sourceThread) {
417
+ parts.push({ type: 'reference', dir: 'in', address: address.message(topicId, sourceThread), title: floorExcerpt(messages.stored(sourceThread)) });
418
+ }
419
+ return a2a.send({ topicId, from, content: cardText(made, name), targets: [...(inbox === false ? [] : to), ...invited], parts, replyTo, threadable: true }).message;
420
+ },
421
+ update(id, patch) {
422
+ const { message, card } = need(id);
423
+ if (card.state !== 'pending')
424
+ throw new Error('这张卡已经不在等答复了,改不了');
425
+ if (card.expiresAt !== undefined && card.expiresAt <= Date.now()) {
426
+ cards.close(id, '这张卡已过期');
427
+ throw new HttpError(409, '这张卡已过期');
428
+ }
429
+ if (card.quorum?.openedAt !== undefined)
430
+ throw new Error('这张卡已经开放给成员签名,改不了');
431
+ const { rev, state, to, answer: _answer, outcome: _outcome, note: _note, signs: _signs, ...was } = card;
432
+ const next = { ...asked({ ...was, ...patch, kind: card.kind }), rev, state, ...(to ? { to } : {}) };
433
+ if (next.quorum && !next.to)
434
+ next.to = message.to.filter(isPerson);
435
+ const invited = next.quorum?.openedAt !== undefined ? next.quorum.who : [];
436
+ if (invited.some(isPerson))
437
+ throw new Error('quorum.who 是成员,不是人');
438
+ return put(message, next, invited);
439
+ },
440
+ report(id, { results = {}, outcome, tell }) {
441
+ const { message, card } = need(id);
442
+ if (card.state !== 'answered')
443
+ throw new Error('这张卡还没有答,没有结果可写');
444
+ const unknown = Object.keys(results).find((key) => !card.items?.some((item) => item.id === key));
445
+ if (unknown !== undefined)
446
+ throw new Error(`这张卡里没有这一项:${unknown}`);
447
+ const items = card.items?.map((item) => (results[item.id] ? { ...item, result: results[item.id] } : item));
448
+ return put(message, { ...card, ...(items ? { items } : {}), ...(outcome ? { outcome } : {}) }, tell);
449
+ },
450
+ close(id, note) {
451
+ const { message, card } = need(id);
452
+ if (card.state !== 'pending')
453
+ throw new HttpError(409, '这张卡已经不在等答复了');
454
+ for (const recipient of message.to)
455
+ a2a.markRead(message.topicId, recipient, message.id);
456
+ const now = put(message, { ...card, state: 'closed', ...(note ? { note } : {}) });
457
+ ctx.runtime.emit('card.closed', { message: now, card: cardOf(now), ...(note ? { note } : {}) });
458
+ return now;
459
+ },
460
+ answer(id, by, { rev, ask, values, turnId, inputs, ...said }) {
461
+ const { message, card } = need(id, ask);
462
+ const person = isPerson(by) && (card.to ?? message.to).includes(by);
463
+ const signer = !isPerson(by) && card.quorum?.openedAt !== undefined && card.quorum.who.includes(by);
464
+ if ((!person && !signer) || !visibleTo(message.visibility, by))
465
+ throw new HttpError(403, '这张卡问的不是你');
466
+ if (card.state !== 'pending')
467
+ throw new HttpError(409, card.state === 'answered' ? '这张卡已经答过了' : '这张卡已经关了');
468
+ if (card.expiresAt !== undefined && card.expiresAt <= Date.now()) {
469
+ cards.close(id, '这张卡已过期');
470
+ throw new HttpError(409, '这张卡已过期');
471
+ }
472
+ if (rev !== card.rev)
473
+ throw new HttpError(409, changed(card));
474
+ if (signer) {
475
+ if (inputs)
476
+ throw new HttpError(403, '补填须由机主本人提交');
477
+ return sign(message, card, by, said, values, turnId);
478
+ }
479
+ if (values !== undefined)
480
+ throw new Error('values 是成员签名时填的');
481
+ const answer = { by, at: Date.now(), ...given(card, said), ...(card.quorum ? { via: 'owner' } : {}) };
482
+ const result = settle(message, card, answer, ask, inputs);
483
+ if ('refused' in result)
484
+ throw new Error('人的答复不能被拒收');
485
+ return result;
486
+ },
487
+ awaitingOutcome: ({ from } = {}) => messages.withPart({ type: 'card', state: 'answered' }).filter((message) => {
488
+ const card = cardOf(message);
489
+ return !!card?.answer?.approved && !card.outcome && (!from || (message.from.kind === from.kind && message.from.id === from.id));
490
+ }),
491
+ get: (id) => {
492
+ const message = messages.get(id);
493
+ return cardOf(message) ? message : undefined;
494
+ },
495
+ pending: ({ topicId, from } = {}) => messages.withPart({ type: 'card', state: 'pending', topicId }).flatMap((message) => {
496
+ if (from && (message.from.kind !== from.kind || message.from.id !== from.id))
497
+ return [];
498
+ if (message.status === 'processing')
499
+ return message.parts.filter(pendingAsk).map((part) => ({ ...message, to: part.to, parts: [part] }));
500
+ return cardOf(message)?.state === 'pending' ? [message] : [];
501
+ }),
502
+ };
503
+ ctx.provide('cards', cards);
504
+ // A person who replies in words to a member's choice card that still waits has answered it with words of their
505
+ // own. The reply is theirs and already goes to the member that asked, so the card only takes the answer down.
506
+ ctx.on('message.appended', ({ message }) => {
507
+ const asking = message.replyTo ? messages.get(message.replyTo) : undefined;
508
+ const card = cardOf(asking);
509
+ if (!asking || !card || card.state !== 'pending' || base(card.kind) !== 'choice' || card.other === false || !message.content.trim())
510
+ return;
511
+ if (asking.from.kind !== 'member' || !message.to.includes(asking.from.id) || message.from.kind !== 'member' || !isPerson(message.from.id) || !asking.to.includes(message.from.id))
512
+ return;
513
+ recordAnswer(asking, card, { by: message.from.id, at: message.createdAt, picked: [], text: message.content.trim() });
514
+ });
515
+ const withdrawPermissionPrompt = instances.registerPermissionPrompt((topicId, memberId, event) => {
516
+ const replyId = a2a.live(topicId).find((turn) => turn.turnId === event.turn)?.messageId;
517
+ const previous = replyId ? cardOf(messages.stored(replyId), event.askId) : undefined;
518
+ const card = {
519
+ type: 'card', kind: 'choice.ask', ask: event.askId, title: event.title, to: [OWNER_ID],
520
+ options: event.options.map(({ id, label }) => ({ id, label })), other: false, rev: previous ? previous.rev + 1 : 0, state: 'pending',
521
+ data: { kinds: Object.fromEntries(event.options.map(({ id, kind }) => [id, kind])) },
522
+ ...(event.details ? { items: [{ id: event.askId, ...event.details }] } : {}),
523
+ };
524
+ return !!a2a.reviseReply(topicId, memberId, event.turn, (parts) => [...parts, card]);
525
+ });
526
+ ctx.on('turn.closing', ({ turn }) => {
527
+ if (turn.parts.some(pendingAsk)) {
528
+ a2a.reviseReply(turn.topicId, turn.memberId, turn.turnId, (parts) => parts.map(closedAsk));
529
+ }
530
+ });
531
+ ctx.effect(async () => {
532
+ withdrawPermissionPrompt();
533
+ const waiting = cards.pending().filter((message) => message.status === 'processing');
534
+ const turns = new Map(waiting.map((message) => [message.turnId, message]));
535
+ await Promise.all([...turns.values()].map((message) => a2a.stop(message.topicId, message.from.id, { force: true })));
536
+ });
537
+ // A previous process may have stopped between saving a question and settling its reply.
538
+ for (const message of messages.withPart({ type: 'card', state: 'pending' })) {
539
+ if (message.seq !== null && message.parts.some(pendingAsk)) {
540
+ messages.revise(message.id, { content: message.content, parts: message.parts.map(closedAsk) });
541
+ }
542
+ }
543
+ const pendingForOwner = (topicId) => cards.pending(topicId ? { topicId } : {})
544
+ .filter((m) => m.to.includes(OWNER_ID) && visibleTo(m.visibility, OWNER_ID));
545
+ ctx.on('push.connected', ({ id }) => push.send('cards.changed', pendingForOwner(), id));
546
+ ctx.effect(() => push.send('cards.changed', []));
547
+ if (ctx.runtime.ready)
548
+ push.send('cards.changed', pendingForOwner());
549
+ ctx.effect(topics.status.source('cards', (ids) => {
550
+ const hits = pendingForOwner(ids?.size === 1 ? ids.values().next().value : undefined);
551
+ const grouped = new Map();
552
+ for (const { topicId } of hits)
553
+ if (!ids || ids.has(topicId))
554
+ grouped.set(topicId, (grouped.get(topicId) ?? 0) + 1);
555
+ return grouped;
556
+ }));
557
+ const refreshCards = ({ message }) => {
558
+ if (message.parts.some((part) => part.type === 'card'))
559
+ topics.status.refresh('cards', message.topicId);
560
+ };
561
+ ctx.on('message.appended', refreshCards);
562
+ ctx.on('message.changed', refreshCards);
563
+ ctx.on('message.deleted', ({ topicId }) => topics.status.refresh('cards', topicId));
564
+ ctx.on('turn.ended', ({ turn }) => topics.status.refresh('cards', turn.topicId));
565
+ ctx.effect(entry.group('cards', '等人答复的选项卡、审批卡和回合里的权限确认'));
566
+ ctx.effect(entry.op({
567
+ name: 'cards.pending',
568
+ about: '还在等你答复的卡,各主题的一起;带 topicId 只要那个主题的。每张是一条消息,卡在它的 parts 里。',
569
+ input: object({ topicId: { type: 'string' } }),
570
+ http: ['GET', '/api/cards'],
571
+ run: ({ topicId }) => pendingForOwner(topicId),
572
+ }));
573
+ ctx.effect(entry.op({
574
+ name: 'cards.withdraw',
575
+ about: '撤回自己仍在等答复的选项卡或审批卡。卡留在原位置,收件箱移除待答项。',
576
+ input: object({
577
+ id: { type: 'string', description: '卡片消息编号(msg_…)' },
578
+ note: { type: 'string', description: '可选的一句撤回说明' },
579
+ }, ['id']),
580
+ http: ['POST', '/api/cards/:id/withdraw'], agent: true,
581
+ run({ id, note }, { member }) {
582
+ const { card, message } = need(id);
583
+ if (!member || member.id !== askerOf(message.from, card.by)) {
584
+ throw new HttpError(403, '只有发起这张卡的成员才能撤回');
585
+ }
586
+ return cards.close(id, note);
587
+ },
588
+ text: (message) => `已撤回(消息 ${message.id})。`,
589
+ }));
590
+ // The picture of an option: a file in the card's topic folder, sent as it is. Not an operation: it answers with a file.
591
+ ctx.effect(entry.route('GET', '/api/cards/:id/image/:option', ({ params, res }) => {
592
+ const { message, card } = need(params.id);
593
+ if (!visibleTo(message.visibility, OWNER_ID))
594
+ throw new HttpError(404, '没有这张卡');
595
+ const image = card.options?.find((o) => o.id === params.option)?.image;
596
+ const dir = topics.get(message.topicId)?.dir;
597
+ const file = image && dir ? resolve(dir, image) : undefined;
598
+ if (!file || !dir || !existsSync(file) || !statSync(file).isFile() || !realpathSync(file).startsWith(realpathSync(dir) + sep))
599
+ throw new HttpError(404, '没有这张图');
600
+ return sendUserFile(res, file);
601
+ }));
602
+ ctx.effect(entry.op({
603
+ name: 'cards.answer',
604
+ about: '答一张卡;被邀请签名的成员用它签名,每人一票并写理由。rev 是卡上的版本。选项卡用 picked 传选项 id,text 传自己写的话。审批卡用 approved 传是否批准,批准有多个方案的卡须用 picked 传一个方案 id;卡上有 remember 时,机主批准可带 remember: true,表示以后都允许。权限确认还要带上卡上的 ask,id 是进行中的回复编号。答过的不能再答。',
605
+ input: object({
606
+ id: { type: 'string' }, rev: { type: 'integer' }, picked: { type: 'array', items: { type: 'string' } }, text: { type: 'string' },
607
+ approved: { type: 'boolean' }, remember: { type: 'boolean' }, ask: { type: 'string' },
608
+ values: { type: 'object', additionalProperties: { type: 'string' }, description: '成员签名时按卡上列出的字段填写' },
609
+ inputs: { type: 'object', secret: true, additionalProperties: { type: 'object', additionalProperties: { type: 'string' } }, description: '机主补填,按卡上步骤 id 与字段路径提交' },
610
+ }, ['id', 'rev']),
611
+ http: ['POST', '/api/cards/:id/answer'], agent: true,
612
+ async run({ id, ...answer }, { member, topicId }) {
613
+ if (member) {
614
+ const turnId = topicId ? a2a.live(topicId).find((turn) => turn.memberId === member.id)?.turnId : undefined;
615
+ return cards.answer(id, member.id, { ...answer, ...(turnId ? { turnId } : {}) });
616
+ }
617
+ const message = answer.ask === undefined ? cards.get(id) : undefined;
618
+ const card = cardOf(message);
619
+ if (message && (card?.to ?? message.to).includes(OWNER_ID) && card?.state === 'pending')
620
+ await ctx.runtime.serial('cards.refresh', message);
621
+ return cards.answer(id, OWNER_ID, answer);
622
+ },
623
+ text: (message) => `已记下(消息 ${message.id},rev ${cardOf(message)?.rev})。`,
624
+ }));
625
+ },
626
+ };
627
+ export default cardsPlugin;
@@ -0,0 +1,3 @@
1
+ pluginId: cards
2
+ foundation: true
3
+ console: console/
@@ -0,0 +1,2 @@
1
+ import type { Ctx, ExternalPluginContext } from 'hostlet/sdk';
2
+ export declare function registerBrowserOpening(ctx: Ctx, config: ExternalPluginContext['config']): void;