@neta-art/cohub-cli 10.24.0 → 10.25.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 (369) hide show
  1. package/bin/cohub.js +4 -1
  2. package/dist/board-gpu/page.js +1566 -71230
  3. package/dist/bootstrap.js +67 -27
  4. package/dist/build.json +1 -1
  5. package/dist/{board-kernel/FilterPipe.js → chunks/Geometry.js} +10447 -10469
  6. package/dist/chunks/about.js +102 -0
  7. package/dist/chunks/app-realtime.js +2216 -0
  8. package/dist/chunks/app-realtime2.js +2 -0
  9. package/dist/chunks/app-ref.js +88 -0
  10. package/dist/chunks/apps.js +1423 -0
  11. package/dist/chunks/auth.js +175 -0
  12. package/dist/chunks/avatar.js +146 -0
  13. package/dist/chunks/binary-pins.js +5 -0
  14. package/dist/chunks/board-export-resources.js +232 -0
  15. package/dist/chunks/board-export.js +874 -0
  16. package/dist/chunks/board-export2.js +2 -0
  17. package/dist/{board-kernel.js → chunks/board-kernel.js} +18032 -28512
  18. package/dist/chunks/board-kernel2.js +4 -0
  19. package/dist/chunks/board-profile.js +69 -0
  20. package/dist/chunks/board-simulate.js +315 -0
  21. package/dist/chunks/board-time.js +34 -0
  22. package/dist/chunks/boards.js +1943 -0
  23. package/dist/{board-kernel → chunks}/browserAll.js +9 -8
  24. package/dist/chunks/channels.js +64 -0
  25. package/dist/chunks/client.js +12606 -0
  26. package/dist/chunks/command-input.js +17 -0
  27. package/dist/chunks/commander.js +2962 -0
  28. package/dist/chunks/cron-jobs.js +163 -0
  29. package/dist/chunks/daemon.js +545 -0
  30. package/dist/chunks/daemon2.js +2 -0
  31. package/dist/chunks/desktop.js +172 -0
  32. package/dist/chunks/endpoint-options.js +26 -0
  33. package/dist/chunks/env-proxy.js +35 -0
  34. package/dist/chunks/environment.js +154 -0
  35. package/dist/chunks/feedback.js +120 -0
  36. package/dist/chunks/generations.js +379 -0
  37. package/dist/chunks/host.js +9 -0
  38. package/dist/chunks/http-put.js +131 -0
  39. package/dist/chunks/id.js +2416 -0
  40. package/dist/{board-kernel → chunks}/init.js +1 -1
  41. package/dist/chunks/install.js +11959 -0
  42. package/dist/chunks/launch.js +374 -0
  43. package/dist/chunks/local-media.js +47 -0
  44. package/dist/chunks/me.js +134 -0
  45. package/dist/chunks/media.js +315 -0
  46. package/dist/chunks/models.js +242 -0
  47. package/dist/chunks/operands.js +46 -0
  48. package/dist/chunks/package-paths.js +13 -0
  49. package/dist/chunks/policy.js +221 -0
  50. package/dist/chunks/preferences.js +29 -0
  51. package/dist/chunks/profile.js +64 -0
  52. package/dist/chunks/prompts.js +41 -0
  53. package/dist/chunks/public.js +2 -0
  54. package/dist/chunks/public2.js +244 -0
  55. package/dist/chunks/references.js +197 -0
  56. package/dist/chunks/referrals.js +90 -0
  57. package/dist/chunks/rolldown-runtime.js +26 -0
  58. package/dist/chunks/rooms-connect.js +2 -0
  59. package/dist/chunks/rooms-connect2.js +151 -0
  60. package/dist/chunks/rooms-rtc.js +311 -0
  61. package/dist/chunks/rooms.js +211 -0
  62. package/dist/chunks/run.js +220 -0
  63. package/dist/chunks/runtime.js +638 -0
  64. package/dist/chunks/runtime2.js +286 -0
  65. package/dist/chunks/runtimes.js +48 -0
  66. package/dist/chunks/safe-remote-image.js +198 -0
  67. package/dist/chunks/schemas.js +6017 -0
  68. package/dist/chunks/search.js +113 -0
  69. package/dist/chunks/self-update.js +238 -0
  70. package/dist/chunks/serve.js +1246 -0
  71. package/dist/chunks/session-status.js +24 -0
  72. package/dist/chunks/skills.js +35 -0
  73. package/dist/chunks/spaces.js +5080 -0
  74. package/dist/chunks/src.js +405 -0
  75. package/dist/chunks/supervisor.js +2513 -0
  76. package/dist/chunks/supervisor2.js +2 -0
  77. package/dist/chunks/tasks.js +82 -0
  78. package/dist/chunks/themes.js +2898 -0
  79. package/dist/chunks/version.js +2 -0
  80. package/dist/chunks/version2.js +22 -0
  81. package/dist/chunks/version3.js +18 -0
  82. package/dist/chunks/web.js +7 -0
  83. package/dist/{board-kernel → chunks}/webworkerAll.js +1 -1
  84. package/dist/runtime/native/pi-extension.js +174 -166
  85. package/dist/runtime/worker.js +27 -16
  86. package/package.json +8 -9
  87. package/dist/about.d.ts +0 -2
  88. package/dist/about.js +0 -71
  89. package/dist/app-download.d.ts +0 -11
  90. package/dist/app-download.js +0 -252
  91. package/dist/app-ref.d.ts +0 -5
  92. package/dist/app-ref.js +0 -8
  93. package/dist/app-target.d.ts +0 -26
  94. package/dist/app-target.js +0 -55
  95. package/dist/auth.d.ts +0 -45
  96. package/dist/auth.js +0 -307
  97. package/dist/avatar.d.ts +0 -55
  98. package/dist/avatar.js +0 -104
  99. package/dist/board-command-support.d.ts +0 -6
  100. package/dist/board-command-support.js +0 -88
  101. package/dist/board-export-resources.d.ts +0 -12
  102. package/dist/board-export-resources.js +0 -51
  103. package/dist/board-export.d.ts +0 -110
  104. package/dist/board-export.js +0 -592
  105. package/dist/board-fonts.d.ts +0 -11
  106. package/dist/board-fonts.js +0 -10
  107. package/dist/board-gpu/daemon.d.ts +0 -11
  108. package/dist/board-gpu/daemon.js +0 -295
  109. package/dist/board-gpu/index.d.ts +0 -33
  110. package/dist/board-gpu/index.js +0 -189
  111. package/dist/board-gpu/protocol.d.ts +0 -77
  112. package/dist/board-gpu/protocol.js +0 -1
  113. package/dist/board-kernel.d.ts +0 -5
  114. package/dist/board-media-export.d.ts +0 -17
  115. package/dist/board-media-export.js +0 -164
  116. package/dist/board-media.d.ts +0 -5
  117. package/dist/board-media.js +0 -66
  118. package/dist/board-profile.d.ts +0 -21
  119. package/dist/board-profile.js +0 -67
  120. package/dist/board-simulate.d.ts +0 -67
  121. package/dist/board-simulate.js +0 -259
  122. package/dist/board-time.d.ts +0 -3
  123. package/dist/board-time.js +0 -34
  124. package/dist/bootstrap.d.ts +0 -2
  125. package/dist/client.d.ts +0 -5
  126. package/dist/client.js +0 -24
  127. package/dist/command-input.d.ts +0 -4
  128. package/dist/command-input.js +0 -16
  129. package/dist/commands/app-commerce.d.ts +0 -2
  130. package/dist/commands/app-commerce.js +0 -228
  131. package/dist/commands/app-domains.d.ts +0 -2
  132. package/dist/commands/app-domains.js +0 -133
  133. package/dist/commands/apps.d.ts +0 -4
  134. package/dist/commands/apps.js +0 -827
  135. package/dist/commands/auth.d.ts +0 -2
  136. package/dist/commands/auth.js +0 -186
  137. package/dist/commands/boards/authoring.d.ts +0 -2
  138. package/dist/commands/boards/authoring.js +0 -166
  139. package/dist/commands/boards/examples.d.ts +0 -10
  140. package/dist/commands/boards/examples.js +0 -118
  141. package/dist/commands/boards.d.ts +0 -13
  142. package/dist/commands/boards.js +0 -836
  143. package/dist/commands/channels.d.ts +0 -2
  144. package/dist/commands/channels.js +0 -74
  145. package/dist/commands/cron-jobs.d.ts +0 -2
  146. package/dist/commands/cron-jobs.js +0 -155
  147. package/dist/commands/decision.d.ts +0 -4
  148. package/dist/commands/decision.js +0 -113
  149. package/dist/commands/desktop.d.ts +0 -10
  150. package/dist/commands/desktop.js +0 -233
  151. package/dist/commands/feedback.d.ts +0 -2
  152. package/dist/commands/feedback.js +0 -131
  153. package/dist/commands/generations.d.ts +0 -2
  154. package/dist/commands/generations.js +0 -427
  155. package/dist/commands/host.d.ts +0 -2
  156. package/dist/commands/host.js +0 -11
  157. package/dist/commands/me.d.ts +0 -2
  158. package/dist/commands/me.js +0 -121
  159. package/dist/commands/models.d.ts +0 -28
  160. package/dist/commands/models.js +0 -271
  161. package/dist/commands/profile.d.ts +0 -2
  162. package/dist/commands/profile.js +0 -81
  163. package/dist/commands/prompts.d.ts +0 -2
  164. package/dist/commands/prompts.js +0 -37
  165. package/dist/commands/public.d.ts +0 -20
  166. package/dist/commands/public.js +0 -291
  167. package/dist/commands/references.d.ts +0 -2
  168. package/dist/commands/references.js +0 -193
  169. package/dist/commands/referrals.d.ts +0 -2
  170. package/dist/commands/referrals.js +0 -88
  171. package/dist/commands/rooms-connect.d.ts +0 -17
  172. package/dist/commands/rooms-connect.js +0 -140
  173. package/dist/commands/rooms-rtc-binary.d.ts +0 -2
  174. package/dist/commands/rooms-rtc-binary.js +0 -107
  175. package/dist/commands/rooms-rtc.d.ts +0 -21
  176. package/dist/commands/rooms-rtc.js +0 -171
  177. package/dist/commands/rooms.d.ts +0 -3
  178. package/dist/commands/rooms.js +0 -277
  179. package/dist/commands/run.d.ts +0 -13
  180. package/dist/commands/run.js +0 -246
  181. package/dist/commands/runtime.d.ts +0 -3
  182. package/dist/commands/runtime.js +0 -320
  183. package/dist/commands/sandboxd-binary.d.ts +0 -11
  184. package/dist/commands/sandboxd-binary.js +0 -238
  185. package/dist/commands/search.d.ts +0 -2
  186. package/dist/commands/search.js +0 -114
  187. package/dist/commands/session-access.d.ts +0 -2
  188. package/dist/commands/session-access.js +0 -70
  189. package/dist/commands/skills.d.ts +0 -2
  190. package/dist/commands/skills.js +0 -34
  191. package/dist/commands/space-activity.d.ts +0 -26
  192. package/dist/commands/space-activity.js +0 -147
  193. package/dist/commands/space-commerce.d.ts +0 -2
  194. package/dist/commands/space-commerce.js +0 -514
  195. package/dist/commands/space-displays.d.ts +0 -2
  196. package/dist/commands/space-displays.js +0 -620
  197. package/dist/commands/space-files.d.ts +0 -5
  198. package/dist/commands/space-files.js +0 -215
  199. package/dist/commands/space-invitations.d.ts +0 -29
  200. package/dist/commands/space-invitations.js +0 -189
  201. package/dist/commands/space-turns.d.ts +0 -49
  202. package/dist/commands/space-turns.js +0 -205
  203. package/dist/commands/space-wallet.d.ts +0 -2
  204. package/dist/commands/space-wallet.js +0 -141
  205. package/dist/commands/space-webhooks.d.ts +0 -7
  206. package/dist/commands/space-webhooks.js +0 -73
  207. package/dist/commands/spaces.d.ts +0 -25
  208. package/dist/commands/spaces.js +0 -2170
  209. package/dist/commands/tasks.d.ts +0 -8
  210. package/dist/commands/tasks.js +0 -80
  211. package/dist/commands/version.d.ts +0 -2
  212. package/dist/commands/version.js +0 -21
  213. package/dist/endpoint-options.d.ts +0 -4
  214. package/dist/endpoint-options.js +0 -26
  215. package/dist/env-proxy.d.ts +0 -5
  216. package/dist/env-proxy.js +0 -20
  217. package/dist/help-path.d.ts +0 -18
  218. package/dist/help-path.js +0 -223
  219. package/dist/host/auth.d.ts +0 -20
  220. package/dist/host/auth.js +0 -119
  221. package/dist/host/login-env.d.ts +0 -1
  222. package/dist/host/login-env.js +0 -31
  223. package/dist/host/runtime.d.ts +0 -35
  224. package/dist/host/runtime.js +0 -395
  225. package/dist/host/runtimes.d.ts +0 -9
  226. package/dist/host/runtimes.js +0 -42
  227. package/dist/host/serve.d.ts +0 -2
  228. package/dist/host/serve.js +0 -117
  229. package/dist/host/workspaces.d.ts +0 -2
  230. package/dist/host/workspaces.js +0 -18
  231. package/dist/http-put.d.ts +0 -25
  232. package/dist/http-put.js +0 -132
  233. package/dist/index.d.ts +0 -2
  234. package/dist/index.js +0 -129
  235. package/dist/launcher.d.ts +0 -4
  236. package/dist/launcher.js +0 -38
  237. package/dist/local-media.d.ts +0 -2
  238. package/dist/local-media.js +0 -30
  239. package/dist/network-error.d.ts +0 -3
  240. package/dist/network-error.js +0 -22
  241. package/dist/output.d.ts +0 -46
  242. package/dist/output.js +0 -244
  243. package/dist/runtime/archive-store.d.ts +0 -54
  244. package/dist/runtime/archive-store.js +0 -379
  245. package/dist/runtime/cli-path.d.ts +0 -5
  246. package/dist/runtime/cli-path.js +0 -27
  247. package/dist/runtime/codex-usage.d.ts +0 -7
  248. package/dist/runtime/codex-usage.js +0 -11
  249. package/dist/runtime/connection.d.ts +0 -42
  250. package/dist/runtime/connection.js +0 -789
  251. package/dist/runtime/diagnostics.d.ts +0 -107
  252. package/dist/runtime/diagnostics.js +0 -392
  253. package/dist/runtime/harnesses/chained-projection.d.ts +0 -40
  254. package/dist/runtime/harnesses/chained-projection.js +0 -95
  255. package/dist/runtime/harnesses/chained-transcript.d.ts +0 -24
  256. package/dist/runtime/harnesses/chained-transcript.js +0 -62
  257. package/dist/runtime/harnesses/claude-approval.d.ts +0 -34
  258. package/dist/runtime/harnesses/claude-approval.js +0 -124
  259. package/dist/runtime/harnesses/claude-transcript.d.ts +0 -8
  260. package/dist/runtime/harnesses/claude-transcript.js +0 -138
  261. package/dist/runtime/harnesses/claude.d.ts +0 -8
  262. package/dist/runtime/harnesses/claude.js +0 -225
  263. package/dist/runtime/harnesses/codex-approval.d.ts +0 -25
  264. package/dist/runtime/harnesses/codex-approval.js +0 -69
  265. package/dist/runtime/harnesses/codex.d.ts +0 -4
  266. package/dist/runtime/harnesses/codex.js +0 -269
  267. package/dist/runtime/harnesses/cursor-transcript.d.ts +0 -37
  268. package/dist/runtime/harnesses/cursor-transcript.js +0 -183
  269. package/dist/runtime/harnesses/cursor.d.ts +0 -24
  270. package/dist/runtime/harnesses/cursor.js +0 -620
  271. package/dist/runtime/harnesses/index.d.ts +0 -16
  272. package/dist/runtime/harnesses/index.js +0 -73
  273. package/dist/runtime/harnesses/pi.d.ts +0 -4
  274. package/dist/runtime/harnesses/pi.js +0 -247
  275. package/dist/runtime/harnesses/process.d.ts +0 -31
  276. package/dist/runtime/harnesses/process.js +0 -75
  277. package/dist/runtime/harnesses/stream-json.d.ts +0 -48
  278. package/dist/runtime/harnesses/stream-json.js +0 -336
  279. package/dist/runtime/harnesses/types.d.ts +0 -117
  280. package/dist/runtime/harnesses/types.js +0 -1
  281. package/dist/runtime/harnesses/workbuddy-transcript.d.ts +0 -8
  282. package/dist/runtime/harnesses/workbuddy-transcript.js +0 -127
  283. package/dist/runtime/harnesses/workbuddy.d.ts +0 -21
  284. package/dist/runtime/harnesses/workbuddy.js +0 -123
  285. package/dist/runtime/instance.d.ts +0 -20
  286. package/dist/runtime/instance.js +0 -247
  287. package/dist/runtime/json-rpc.d.ts +0 -53
  288. package/dist/runtime/json-rpc.js +0 -212
  289. package/dist/runtime/launch.d.ts +0 -25
  290. package/dist/runtime/launch.js +0 -247
  291. package/dist/runtime/local-workspace.d.ts +0 -15
  292. package/dist/runtime/local-workspace.js +0 -52
  293. package/dist/runtime/model-catalog.d.ts +0 -12
  294. package/dist/runtime/model-catalog.js +0 -84
  295. package/dist/runtime/native/adapters.d.ts +0 -15
  296. package/dist/runtime/native/adapters.js +0 -11
  297. package/dist/runtime/native/approvals.d.ts +0 -18
  298. package/dist/runtime/native/approvals.js +0 -54
  299. package/dist/runtime/native/archive.d.ts +0 -19
  300. package/dist/runtime/native/archive.js +0 -142
  301. package/dist/runtime/native/attach.d.ts +0 -36
  302. package/dist/runtime/native/attach.js +0 -128
  303. package/dist/runtime/native/codex-link.d.ts +0 -60
  304. package/dist/runtime/native/codex-link.js +0 -322
  305. package/dist/runtime/native/config.d.ts +0 -16
  306. package/dist/runtime/native/config.js +0 -24
  307. package/dist/runtime/native/daemon.d.ts +0 -92
  308. package/dist/runtime/native/daemon.js +0 -380
  309. package/dist/runtime/native/execution.d.ts +0 -26
  310. package/dist/runtime/native/execution.js +0 -34
  311. package/dist/runtime/native/identity.d.ts +0 -9
  312. package/dist/runtime/native/identity.js +0 -15
  313. package/dist/runtime/native/ingest.d.ts +0 -263
  314. package/dist/runtime/native/ingest.js +0 -884
  315. package/dist/runtime/native/install.d.ts +0 -9
  316. package/dist/runtime/native/install.js +0 -113
  317. package/dist/runtime/native/paths.d.ts +0 -2
  318. package/dist/runtime/native/paths.js +0 -7
  319. package/dist/runtime/native/pi-extension.d.ts +0 -36
  320. package/dist/runtime/native/pi-link.d.ts +0 -69
  321. package/dist/runtime/native/pi-link.js +0 -269
  322. package/dist/runtime/native/results.d.ts +0 -41
  323. package/dist/runtime/native/results.js +0 -128
  324. package/dist/runtime/native/sessions.d.ts +0 -45
  325. package/dist/runtime/native/sessions.js +0 -87
  326. package/dist/runtime/native/transcript.d.ts +0 -89
  327. package/dist/runtime/native/transcript.js +0 -656
  328. package/dist/runtime/native/translate.d.ts +0 -46
  329. package/dist/runtime/native/translate.js +0 -299
  330. package/dist/runtime/native/transport.d.ts +0 -7
  331. package/dist/runtime/native/transport.js +0 -16
  332. package/dist/runtime/native/version.d.ts +0 -5
  333. package/dist/runtime/native/version.js +0 -21
  334. package/dist/runtime/preferences.d.ts +0 -7
  335. package/dist/runtime/preferences.js +0 -22
  336. package/dist/runtime/presentation.d.ts +0 -32
  337. package/dist/runtime/presentation.js +0 -124
  338. package/dist/runtime/process-group.d.ts +0 -5
  339. package/dist/runtime/process-group.js +0 -161
  340. package/dist/runtime/projection-store.d.ts +0 -27
  341. package/dist/runtime/projection-store.js +0 -30
  342. package/dist/runtime/space-binding.d.ts +0 -48
  343. package/dist/runtime/space-binding.js +0 -342
  344. package/dist/runtime/supervisor.d.ts +0 -19
  345. package/dist/runtime/supervisor.js +0 -441
  346. package/dist/runtime/turn-projection.d.ts +0 -41
  347. package/dist/runtime/turn-projection.js +0 -120
  348. package/dist/runtime/worker.d.ts +0 -1
  349. package/dist/safe-remote-image.d.ts +0 -36
  350. package/dist/safe-remote-image.js +0 -191
  351. package/dist/self-update.d.ts +0 -7
  352. package/dist/self-update.js +0 -202
  353. package/dist/session-status.d.ts +0 -10
  354. package/dist/session-status.js +0 -25
  355. package/dist/space-files/limit.d.ts +0 -2
  356. package/dist/space-files/limit.js +0 -16
  357. package/dist/space-files/operands.d.ts +0 -17
  358. package/dist/space-files/operands.js +0 -33
  359. package/dist/space-files/transfer.d.ts +0 -53
  360. package/dist/space-files/transfer.js +0 -297
  361. package/dist/space-files/upload.d.ts +0 -17
  362. package/dist/space-files/upload.js +0 -76
  363. package/dist/space.d.ts +0 -44
  364. package/dist/space.js +0 -192
  365. package/dist/version.d.ts +0 -2
  366. package/dist/version.js +0 -17
  367. package/dist/web.d.ts +0 -1
  368. package/dist/web.js +0 -4
  369. /package/dist/{board-kernel → chunks}/lexer.js +0 -0
@@ -1,514 +0,0 @@
1
- import { createClient } from "../client.js";
2
- import { error, formatLocalDateTime, handleHttp, json as outJson, jsonRequested, ok, table } from "../output.js";
3
- import { resolveSpace } from "../space.js";
4
- const PRODUCT_STATUSES = ["draft", "active"];
5
- const PRODUCT_UPDATE_STATUSES = ["draft", "active", "archived"];
6
- const PRODUCT_VISIBILITIES = ["public", "private"];
7
- const BENEFIT_STATUSES = ["active", "archived"];
8
- const MIN_PRODUCT_AMOUNT_USD = 0.5;
9
- function requireText(value, label, flag) {
10
- const text = value?.trim();
11
- if (text)
12
- return text;
13
- return error(`Missing ${label}`, `Pass ${flag}.`);
14
- }
15
- function parseChoice(value, label, choices) {
16
- if (value === undefined)
17
- return undefined;
18
- if (choices.includes(value))
19
- return value;
20
- return error(`Invalid ${label}`, `Use one of: ${choices.join(", ")}.`);
21
- }
22
- function parseInteger(value, label, options) {
23
- if (value === undefined)
24
- return options.fallback;
25
- if (!/^-?\d+$/.test(value.trim()))
26
- return error(`Invalid ${label}`, `${label} must be an integer.`);
27
- const parsed = Number.parseInt(value, 10);
28
- if (!Number.isSafeInteger(parsed))
29
- return error(`Invalid ${label}`, `${label} must be a safe integer.`);
30
- if (options.min !== undefined && parsed < options.min)
31
- return error(`Invalid ${label}`, `${label} must be at least ${options.min}.`);
32
- if (options.max !== undefined && parsed > options.max)
33
- return error(`Invalid ${label}`, `${label} must be at most ${options.max}.`);
34
- return parsed;
35
- }
36
- function parseAmountUsd(value) {
37
- const text = requireText(value, "amount", "--amount-usd <amount>");
38
- if (!/^(?:\d+|\d+\.\d{1,2}|\.\d{1,2})$/.test(text)) {
39
- return error("Invalid amount", "--amount-usd must be a USD amount with at most 2 decimals.");
40
- }
41
- const amount = Number(text);
42
- if (!Number.isFinite(amount))
43
- return error("Invalid amount", "--amount-usd must be a finite USD amount.");
44
- if (amount < MIN_PRODUCT_AMOUNT_USD)
45
- return error("Invalid amount", "--amount-usd must be at least 0.5.");
46
- return amount;
47
- }
48
- function parseMetadataJson(value) {
49
- if (value === undefined)
50
- return undefined;
51
- let parsed;
52
- try {
53
- parsed = JSON.parse(value);
54
- }
55
- catch {
56
- return error("Invalid metadata", "--metadata-json must be a JSON object.");
57
- }
58
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
59
- return error("Invalid metadata", "--metadata-json must be a JSON object.");
60
- }
61
- const metadata = {};
62
- for (const [key, item] of Object.entries(parsed)) {
63
- if (typeof item !== "string" && typeof item !== "number" && typeof item !== "boolean") {
64
- return error("Invalid metadata", `Metadata value for "${key}" must be string, number, or boolean.`);
65
- }
66
- if (typeof item === "number" && !Number.isFinite(item)) {
67
- return error("Invalid metadata", `Metadata value for "${key}" must be a finite number.`);
68
- }
69
- metadata[key] = item;
70
- }
71
- return metadata;
72
- }
73
- function compact(input) {
74
- return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== undefined));
75
- }
76
- function formatUsd(amount) {
77
- return `$${amount.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
78
- }
79
- function formatMinorUsd(amountMinor) {
80
- return formatUsd(amountMinor / 100);
81
- }
82
- function printProducts(products) {
83
- table(products.map((product) => ({
84
- key: product.key,
85
- name: product.name,
86
- status: product.status,
87
- visibility: product.visibility,
88
- price: formatUsd(product.pricing.amountUsd),
89
- balance: product.cohubBalance ? formatUsd(product.cohubBalance.amountUsd) : "",
90
- credits: product.display.creditsAmount ?? "",
91
- })), [
92
- { key: "key", label: "Key" },
93
- { key: "name", label: "Name" },
94
- { key: "status", label: "Status" },
95
- { key: "visibility", label: "Visibility" },
96
- { key: "price", label: "Price" },
97
- { key: "balance", label: "Cohub Balance" },
98
- { key: "credits", label: "Credits" },
99
- ]);
100
- }
101
- function printBenefits(benefits) {
102
- table(benefits.map((benefit) => {
103
- let detail;
104
- if (benefit.type === "credits") {
105
- const config = benefit.config;
106
- detail = `${config.amount} credits${config.expiresInDays != null ? ` · ${config.expiresInDays}d` : ""}`;
107
- }
108
- else {
109
- detail = JSON.stringify(benefit.config.metadata);
110
- }
111
- return {
112
- key: benefit.key,
113
- name: benefit.name,
114
- type: benefit.type,
115
- status: benefit.status,
116
- detail,
117
- };
118
- }), [
119
- { key: "key", label: "Key" },
120
- { key: "name", label: "Name" },
121
- { key: "type", label: "Type" },
122
- { key: "status", label: "Status" },
123
- { key: "detail", label: "Detail" },
124
- ]);
125
- }
126
- function printOrders(orders) {
127
- table(orders.map((order) => ({
128
- id: order.id,
129
- product: order.productKeySnapshot,
130
- status: order.status,
131
- amount: formatMinorUsd(order.amountSnapshot),
132
- created: order.createdAt,
133
- })), [
134
- { key: "id", label: "ID" },
135
- { key: "product", label: "Product" },
136
- { key: "status", label: "Status" },
137
- { key: "amount", label: "Amount" },
138
- { key: "created", label: "Created", format: formatLocalDateTime },
139
- ]);
140
- }
141
- async function confirmDanger(opts, detail) {
142
- if (opts.yes)
143
- return;
144
- if (!process.stdin.isTTY || !process.stdout.isTTY)
145
- return error("Confirmation required", `Pass --yes to ${detail}.`);
146
- process.stdout.write(`${detail[0]?.toUpperCase() ?? "C"}${detail.slice(1)}? [y/N] `);
147
- const chunks = [];
148
- for await (const chunk of process.stdin) {
149
- chunks.push(chunk);
150
- break;
151
- }
152
- const answer = Buffer.concat(chunks).toString().trim().toLowerCase();
153
- if (answer !== "y" && answer !== "yes")
154
- return error("Cancelled");
155
- }
156
- async function commerceClient(spacesCmd) {
157
- const spaceId = await resolveSpace(spacesCmd);
158
- return { spaceId, commerce: createClient().space(spaceId).commerce };
159
- }
160
- export function registerSpaceCommerce(spacesCmd) {
161
- const commerceCmd = spacesCmd
162
- .command("commerce")
163
- .description("Manage space commerce")
164
- .addHelpText("after", `
165
- Examples:
166
- cohub -s <space-id> spaces commerce setup
167
- cohub -s <space-id> spaces commerce products list
168
- COHUB_SPACE_ID=<space-id> cohub spaces commerce orders list --limit 10
169
- `);
170
- commerceCmd
171
- .command("setup")
172
- .description("Initialize commerce for the target space")
173
- .option("--json", "Output as JSON")
174
- .action(async (opts) => {
175
- const { commerce } = await commerceClient(spacesCmd);
176
- try {
177
- const result = await commerce.setup();
178
- if (jsonRequested(opts))
179
- return outJson(result);
180
- ok(`Commerce initialized: ${result.businessKey}`);
181
- }
182
- catch (e) {
183
- handleHttp(e);
184
- }
185
- });
186
- const productsCmd = commerceCmd
187
- .command("products")
188
- .description("Manage products")
189
- .addHelpText("after", `
190
- Examples:
191
- cohub -s <space-id> spaces commerce products list
192
- cohub -s <space-id> spaces commerce products create --name "Pro Pack" --amount-usd 9.99
193
- `);
194
- productsCmd
195
- .command("list")
196
- .description("List products")
197
- .option("--json", "Output as JSON")
198
- .action(async (opts) => {
199
- const { commerce } = await commerceClient(spacesCmd);
200
- try {
201
- const result = await commerce.listProducts();
202
- if (jsonRequested(opts))
203
- return outJson(result);
204
- printProducts(result.products);
205
- }
206
- catch (e) {
207
- handleHttp(e);
208
- }
209
- });
210
- productsCmd
211
- .command("create")
212
- .description("Create a product")
213
- .option("--product-key <key>", "Product key override")
214
- .option("--name <name>", "Product name")
215
- .option("--amount-usd <amount>", "One-time price in USD")
216
- .option("--cohub-balance-usd <amount>", "Included Cohub Balance in whole USD")
217
- .option("--description <text>", "Product description")
218
- .option("--status <status>", "Product status: draft, active")
219
- .option("--visibility <visibility>", "Product visibility: public, private")
220
- .option("--json", "Output as JSON")
221
- .action(async (opts) => {
222
- const amountUsd = parseAmountUsd(opts.amountUsd);
223
- const cohubBalanceUsd = opts.cohubBalanceUsd === undefined
224
- ? undefined
225
- : parseInteger(opts.cohubBalanceUsd, "cohub-balance-usd", { fallback: 0, min: 1 });
226
- if (cohubBalanceUsd !== undefined && cohubBalanceUsd > amountUsd) {
227
- return error("Invalid Cohub Balance", "--cohub-balance-usd cannot exceed --amount-usd.");
228
- }
229
- const input = {
230
- key: opts.productKey?.trim() || undefined,
231
- name: requireText(opts.name, "name", "--name <name>"),
232
- description: opts.description,
233
- amountUsd,
234
- cohubBalanceUsd,
235
- status: parseChoice(opts.status, "status", PRODUCT_STATUSES),
236
- visibility: parseChoice(opts.visibility, "visibility", PRODUCT_VISIBILITIES),
237
- };
238
- const { commerce } = await commerceClient(spacesCmd);
239
- try {
240
- const result = await commerce.createProduct(input);
241
- if (jsonRequested(opts))
242
- return outJson(result);
243
- ok(`Product created: ${result.product.key}`);
244
- printProducts([result.product]);
245
- }
246
- catch (e) {
247
- handleHttp(e);
248
- }
249
- });
250
- productsCmd
251
- .command("update")
252
- .description("Update a product")
253
- .option("--product-key <key>", "Product key")
254
- .option("--name <name>", "Product name")
255
- .option("--description <text>", "Product description")
256
- .option("--clear-description", "Clear the product description")
257
- .option("--status <status>", "Product status: draft, active, archived")
258
- .option("--visibility <visibility>", "Product visibility: public, private")
259
- .option("--json", "Output as JSON")
260
- .action(async (opts) => {
261
- if (opts.description !== undefined && opts.clearDescription)
262
- return error("Conflicting description", "Use either --description or --clear-description.");
263
- const productKey = requireText(opts.productKey, "product key", "--product-key <key>");
264
- const input = compact({
265
- name: opts.name,
266
- description: opts.clearDescription ? null : opts.description,
267
- status: parseChoice(opts.status, "status", PRODUCT_UPDATE_STATUSES),
268
- visibility: parseChoice(opts.visibility, "visibility", PRODUCT_VISIBILITIES),
269
- });
270
- if (Object.keys(input).length === 0)
271
- return error("Nothing to update", "Pass --name, --description, --clear-description, --status, or --visibility.");
272
- const { commerce } = await commerceClient(spacesCmd);
273
- try {
274
- const result = await commerce.updateProduct(productKey, input);
275
- if (jsonRequested(opts))
276
- return outJson(result);
277
- ok(`Product updated: ${result.product.key}`);
278
- printProducts([result.product]);
279
- }
280
- catch (e) {
281
- handleHttp(e);
282
- }
283
- });
284
- productsCmd
285
- .command("archive")
286
- .description("Archive a product")
287
- .option("--product-key <key>", "Product key")
288
- .option("-y, --yes", "Confirm archive")
289
- .option("--json", "Output as JSON")
290
- .action(async (opts) => {
291
- const productKey = requireText(opts.productKey, "product key", "--product-key <key>");
292
- await confirmDanger(opts, `archive product "${productKey}"`);
293
- const { commerce } = await commerceClient(spacesCmd);
294
- try {
295
- const result = await commerce.updateProduct(productKey, { status: "archived" });
296
- if (jsonRequested(opts))
297
- return outJson(result);
298
- ok(`Product archived: ${result.product.key}`);
299
- }
300
- catch (e) {
301
- handleHttp(e);
302
- }
303
- });
304
- const benefitsCmd = commerceCmd
305
- .command("benefits")
306
- .description("Manage benefits")
307
- .addHelpText("after", `
308
- Examples:
309
- cohub -s <space-id> spaces commerce benefits list
310
- cohub -s <space-id> spaces commerce benefits create --name "Premium Export" --metadata-json '{"limit":100}'
311
- `);
312
- benefitsCmd
313
- .command("list")
314
- .description("List benefits")
315
- .option("--json", "Output as JSON")
316
- .action(async (opts) => {
317
- const { commerce } = await commerceClient(spacesCmd);
318
- try {
319
- const result = await commerce.listBenefits();
320
- if (jsonRequested(opts))
321
- return outJson(result);
322
- printBenefits(result.benefits);
323
- }
324
- catch (e) {
325
- handleHttp(e);
326
- }
327
- });
328
- benefitsCmd
329
- .command("create")
330
- .description("Create a benefit")
331
- .option("--benefit-key <key>", "Benefit key override")
332
- .option("--name <name>", "Benefit name")
333
- .option("--description <text>", "Benefit description")
334
- .option("--type <type>", "Benefit type: feature, credits (default: feature)")
335
- .option("--amount <n>", "Credit amount (credits type only)")
336
- .option("--expires-in-days <n>", "Credit expiry in days (credits type only)")
337
- .option("--metadata-json <json>", "Benefit metadata JSON object (feature type only)")
338
- .option("--json", "Output as JSON")
339
- .action(async (opts) => {
340
- const name = requireText(opts.name, "name", "--name <name>");
341
- const type = parseChoice(opts.type, "type", ["feature", "credits"]) ?? "feature";
342
- if (type === "credits") {
343
- const amount = parseInteger(opts.amount, "amount", { fallback: 0, min: 1 });
344
- if (amount < 1)
345
- return error("Missing amount", "Pass --amount <n> with a positive integer for credits benefits.");
346
- const input = {
347
- key: opts.benefitKey?.trim() || undefined,
348
- name,
349
- description: opts.description,
350
- type: "credits",
351
- amount,
352
- expiresInDays: opts.expiresInDays !== undefined
353
- ? parseInteger(opts.expiresInDays, "expires-in-days", { fallback: 0, min: 1 })
354
- : undefined,
355
- };
356
- const { commerce } = await commerceClient(spacesCmd);
357
- try {
358
- const result = await commerce.createBenefit(input);
359
- if (jsonRequested(opts))
360
- return outJson(result);
361
- ok(`Benefit created: ${result.benefit.key}`);
362
- printBenefits([result.benefit]);
363
- }
364
- catch (e) {
365
- handleHttp(e);
366
- }
367
- return;
368
- }
369
- const input = {
370
- key: opts.benefitKey?.trim() || undefined,
371
- name,
372
- description: opts.description,
373
- type: "feature",
374
- metadata: parseMetadataJson(opts.metadataJson),
375
- };
376
- const { commerce } = await commerceClient(spacesCmd);
377
- try {
378
- const result = await commerce.createBenefit(input);
379
- if (jsonRequested(opts))
380
- return outJson(result);
381
- ok(`Benefit created: ${result.benefit.key}`);
382
- printBenefits([result.benefit]);
383
- }
384
- catch (e) {
385
- handleHttp(e);
386
- }
387
- });
388
- benefitsCmd
389
- .command("update")
390
- .description("Update a benefit")
391
- .option("--benefit-key <key>", "Benefit key")
392
- .option("--name <name>", "Benefit name")
393
- .option("--description <text>", "Benefit description")
394
- .option("--clear-description", "Clear the benefit description")
395
- .option("--status <status>", "Benefit status: active, archived")
396
- .option("--metadata-json <json>", "Replace metadata with a JSON object")
397
- .option("--json", "Output as JSON")
398
- .action(async (opts) => {
399
- if (opts.description !== undefined && opts.clearDescription)
400
- return error("Conflicting description", "Use either --description or --clear-description.");
401
- const benefitKey = requireText(opts.benefitKey, "benefit key", "--benefit-key <key>");
402
- const input = compact({
403
- name: opts.name,
404
- description: opts.clearDescription ? null : opts.description,
405
- status: parseChoice(opts.status, "status", BENEFIT_STATUSES),
406
- metadata: parseMetadataJson(opts.metadataJson),
407
- });
408
- if (Object.keys(input).length === 0)
409
- return error("Nothing to update", "Pass --name, --description, --clear-description, --status, or --metadata-json.");
410
- const { commerce } = await commerceClient(spacesCmd);
411
- try {
412
- const result = await commerce.updateBenefit(benefitKey, input);
413
- if (jsonRequested(opts))
414
- return outJson(result);
415
- ok(`Benefit updated: ${result.benefit.key}`);
416
- printBenefits([result.benefit]);
417
- }
418
- catch (e) {
419
- handleHttp(e);
420
- }
421
- });
422
- benefitsCmd
423
- .command("archive")
424
- .description("Archive a benefit")
425
- .option("--benefit-key <key>", "Benefit key")
426
- .option("-y, --yes", "Confirm archive")
427
- .option("--json", "Output as JSON")
428
- .action(async (opts) => {
429
- const benefitKey = requireText(opts.benefitKey, "benefit key", "--benefit-key <key>");
430
- await confirmDanger(opts, `archive benefit "${benefitKey}"`);
431
- const { commerce } = await commerceClient(spacesCmd);
432
- try {
433
- const result = await commerce.updateBenefit(benefitKey, { status: "archived" });
434
- if (jsonRequested(opts))
435
- return outJson(result);
436
- ok(`Benefit archived: ${result.benefit.key}`);
437
- }
438
- catch (e) {
439
- handleHttp(e);
440
- }
441
- });
442
- commerceCmd
443
- .command("bind")
444
- .description("Bind a benefit to a product")
445
- .option("--product-key <key>", "Product key")
446
- .option("--benefit-key <key>", "Benefit key")
447
- .option("--json", "Output as JSON")
448
- .action(async (opts) => {
449
- const input = {
450
- productKey: requireText(opts.productKey, "product key", "--product-key <key>"),
451
- benefitKey: requireText(opts.benefitKey, "benefit key", "--benefit-key <key>"),
452
- };
453
- const { commerce } = await commerceClient(spacesCmd);
454
- try {
455
- const result = await commerce.bindProductBenefit(input);
456
- if (jsonRequested(opts))
457
- return outJson(result);
458
- ok(`Benefit bound: ${input.benefitKey} -> ${input.productKey}`);
459
- }
460
- catch (e) {
461
- handleHttp(e);
462
- }
463
- });
464
- commerceCmd
465
- .command("unbind")
466
- .description("Unbind a benefit from a product")
467
- .option("--product-key <key>", "Product key")
468
- .option("--benefit-key <key>", "Benefit key")
469
- .option("-y, --yes", "Confirm unbind")
470
- .option("--json", "Output as JSON")
471
- .action(async (opts) => {
472
- const input = {
473
- productKey: requireText(opts.productKey, "product key", "--product-key <key>"),
474
- benefitKey: requireText(opts.benefitKey, "benefit key", "--benefit-key <key>"),
475
- };
476
- await confirmDanger(opts, `unbind benefit "${input.benefitKey}" from product "${input.productKey}"`);
477
- const { commerce } = await commerceClient(spacesCmd);
478
- try {
479
- const result = await commerce.unbindProductBenefit(input);
480
- if (jsonRequested(opts))
481
- return outJson(result);
482
- ok(`Benefit unbound: ${input.benefitKey} -> ${input.productKey}`);
483
- }
484
- catch (e) {
485
- handleHttp(e);
486
- }
487
- });
488
- const ordersCmd = commerceCmd
489
- .command("orders")
490
- .description("Manage orders");
491
- ordersCmd
492
- .command("list")
493
- .description("List recent orders")
494
- .option("--page <page>", "Page number")
495
- .option("--limit <limit>", "Page size, max 50")
496
- .option("--json", "Output as JSON")
497
- .action(async (opts) => {
498
- const { commerce } = await commerceClient(spacesCmd);
499
- try {
500
- const result = await commerce.listOrders({
501
- page: parseInteger(opts.page, "page", { fallback: 1, min: 1 }),
502
- limit: parseInteger(opts.limit, "limit", { fallback: 20, min: 1, max: 50 }),
503
- });
504
- if (jsonRequested(opts))
505
- return outJson(result);
506
- printOrders(result.orders);
507
- if (result.pagination.hasMore)
508
- console.log(`\nNext page: ${result.pagination.nextPage}`);
509
- }
510
- catch (e) {
511
- handleHttp(e);
512
- }
513
- });
514
- }
@@ -1,2 +0,0 @@
1
- import { type Command } from "commander";
2
- export declare function registerSpaceDisplays(spacesCmd: Command): void;