@neta-art/cohub-cli 10.24.0 → 10.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (368) 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/board-export-resources.js +232 -0
  14. package/dist/chunks/board-export.js +874 -0
  15. package/dist/chunks/board-export2.js +2 -0
  16. package/dist/{board-kernel.js → chunks/board-kernel.js} +18032 -28512
  17. package/dist/chunks/board-kernel2.js +4 -0
  18. package/dist/chunks/board-profile.js +69 -0
  19. package/dist/chunks/board-simulate.js +315 -0
  20. package/dist/chunks/board-time.js +34 -0
  21. package/dist/chunks/boards.js +1943 -0
  22. package/dist/{board-kernel → chunks}/browserAll.js +9 -8
  23. package/dist/chunks/channels.js +64 -0
  24. package/dist/chunks/client.js +12606 -0
  25. package/dist/chunks/command-input.js +17 -0
  26. package/dist/chunks/commander.js +2962 -0
  27. package/dist/chunks/cron-jobs.js +163 -0
  28. package/dist/chunks/daemon.js +545 -0
  29. package/dist/chunks/daemon2.js +2 -0
  30. package/dist/chunks/desktop.js +172 -0
  31. package/dist/chunks/endpoint-options.js +26 -0
  32. package/dist/chunks/env-proxy.js +35 -0
  33. package/dist/chunks/environment.js +154 -0
  34. package/dist/chunks/feedback.js +120 -0
  35. package/dist/chunks/generations.js +379 -0
  36. package/dist/chunks/host.js +9 -0
  37. package/dist/chunks/http-put.js +131 -0
  38. package/dist/chunks/id.js +2416 -0
  39. package/dist/{board-kernel → chunks}/init.js +1 -1
  40. package/dist/chunks/install.js +11959 -0
  41. package/dist/chunks/launch.js +374 -0
  42. package/dist/chunks/local-media.js +47 -0
  43. package/dist/chunks/me.js +134 -0
  44. package/dist/chunks/media.js +315 -0
  45. package/dist/chunks/models.js +242 -0
  46. package/dist/chunks/operands.js +46 -0
  47. package/dist/chunks/package-paths.js +13 -0
  48. package/dist/chunks/policy.js +221 -0
  49. package/dist/chunks/preferences.js +29 -0
  50. package/dist/chunks/profile.js +64 -0
  51. package/dist/chunks/prompts.js +41 -0
  52. package/dist/chunks/public.js +2 -0
  53. package/dist/chunks/public2.js +244 -0
  54. package/dist/chunks/references.js +197 -0
  55. package/dist/chunks/referrals.js +90 -0
  56. package/dist/chunks/rolldown-runtime.js +26 -0
  57. package/dist/chunks/rooms-connect.js +2 -0
  58. package/dist/chunks/rooms-connect2.js +151 -0
  59. package/dist/chunks/rooms-rtc.js +309 -0
  60. package/dist/chunks/rooms.js +211 -0
  61. package/dist/chunks/run.js +220 -0
  62. package/dist/chunks/runtime.js +638 -0
  63. package/dist/chunks/runtime2.js +286 -0
  64. package/dist/chunks/runtimes.js +48 -0
  65. package/dist/chunks/safe-remote-image.js +198 -0
  66. package/dist/chunks/schemas.js +6017 -0
  67. package/dist/chunks/search.js +113 -0
  68. package/dist/chunks/self-update.js +238 -0
  69. package/dist/chunks/serve.js +1246 -0
  70. package/dist/chunks/session-status.js +24 -0
  71. package/dist/chunks/skills.js +35 -0
  72. package/dist/chunks/spaces.js +5080 -0
  73. package/dist/chunks/src.js +405 -0
  74. package/dist/chunks/supervisor.js +2511 -0
  75. package/dist/chunks/supervisor2.js +2 -0
  76. package/dist/chunks/tasks.js +82 -0
  77. package/dist/chunks/themes.js +2898 -0
  78. package/dist/chunks/version.js +2 -0
  79. package/dist/chunks/version2.js +22 -0
  80. package/dist/chunks/version3.js +18 -0
  81. package/dist/chunks/web.js +7 -0
  82. package/dist/{board-kernel → chunks}/webworkerAll.js +1 -1
  83. package/dist/runtime/native/pi-extension.js +174 -166
  84. package/dist/runtime/worker.js +27 -16
  85. package/package.json +8 -9
  86. package/dist/about.d.ts +0 -2
  87. package/dist/about.js +0 -71
  88. package/dist/app-download.d.ts +0 -11
  89. package/dist/app-download.js +0 -252
  90. package/dist/app-ref.d.ts +0 -5
  91. package/dist/app-ref.js +0 -8
  92. package/dist/app-target.d.ts +0 -26
  93. package/dist/app-target.js +0 -55
  94. package/dist/auth.d.ts +0 -45
  95. package/dist/auth.js +0 -307
  96. package/dist/avatar.d.ts +0 -55
  97. package/dist/avatar.js +0 -104
  98. package/dist/board-command-support.d.ts +0 -6
  99. package/dist/board-command-support.js +0 -88
  100. package/dist/board-export-resources.d.ts +0 -12
  101. package/dist/board-export-resources.js +0 -51
  102. package/dist/board-export.d.ts +0 -110
  103. package/dist/board-export.js +0 -592
  104. package/dist/board-fonts.d.ts +0 -11
  105. package/dist/board-fonts.js +0 -10
  106. package/dist/board-gpu/daemon.d.ts +0 -11
  107. package/dist/board-gpu/daemon.js +0 -295
  108. package/dist/board-gpu/index.d.ts +0 -33
  109. package/dist/board-gpu/index.js +0 -189
  110. package/dist/board-gpu/protocol.d.ts +0 -77
  111. package/dist/board-gpu/protocol.js +0 -1
  112. package/dist/board-kernel.d.ts +0 -5
  113. package/dist/board-media-export.d.ts +0 -17
  114. package/dist/board-media-export.js +0 -164
  115. package/dist/board-media.d.ts +0 -5
  116. package/dist/board-media.js +0 -66
  117. package/dist/board-profile.d.ts +0 -21
  118. package/dist/board-profile.js +0 -67
  119. package/dist/board-simulate.d.ts +0 -67
  120. package/dist/board-simulate.js +0 -259
  121. package/dist/board-time.d.ts +0 -3
  122. package/dist/board-time.js +0 -34
  123. package/dist/bootstrap.d.ts +0 -2
  124. package/dist/client.d.ts +0 -5
  125. package/dist/client.js +0 -24
  126. package/dist/command-input.d.ts +0 -4
  127. package/dist/command-input.js +0 -16
  128. package/dist/commands/app-commerce.d.ts +0 -2
  129. package/dist/commands/app-commerce.js +0 -228
  130. package/dist/commands/app-domains.d.ts +0 -2
  131. package/dist/commands/app-domains.js +0 -133
  132. package/dist/commands/apps.d.ts +0 -4
  133. package/dist/commands/apps.js +0 -827
  134. package/dist/commands/auth.d.ts +0 -2
  135. package/dist/commands/auth.js +0 -186
  136. package/dist/commands/boards/authoring.d.ts +0 -2
  137. package/dist/commands/boards/authoring.js +0 -166
  138. package/dist/commands/boards/examples.d.ts +0 -10
  139. package/dist/commands/boards/examples.js +0 -118
  140. package/dist/commands/boards.d.ts +0 -13
  141. package/dist/commands/boards.js +0 -836
  142. package/dist/commands/channels.d.ts +0 -2
  143. package/dist/commands/channels.js +0 -74
  144. package/dist/commands/cron-jobs.d.ts +0 -2
  145. package/dist/commands/cron-jobs.js +0 -155
  146. package/dist/commands/decision.d.ts +0 -4
  147. package/dist/commands/decision.js +0 -113
  148. package/dist/commands/desktop.d.ts +0 -10
  149. package/dist/commands/desktop.js +0 -233
  150. package/dist/commands/feedback.d.ts +0 -2
  151. package/dist/commands/feedback.js +0 -131
  152. package/dist/commands/generations.d.ts +0 -2
  153. package/dist/commands/generations.js +0 -427
  154. package/dist/commands/host.d.ts +0 -2
  155. package/dist/commands/host.js +0 -11
  156. package/dist/commands/me.d.ts +0 -2
  157. package/dist/commands/me.js +0 -121
  158. package/dist/commands/models.d.ts +0 -28
  159. package/dist/commands/models.js +0 -271
  160. package/dist/commands/profile.d.ts +0 -2
  161. package/dist/commands/profile.js +0 -81
  162. package/dist/commands/prompts.d.ts +0 -2
  163. package/dist/commands/prompts.js +0 -37
  164. package/dist/commands/public.d.ts +0 -20
  165. package/dist/commands/public.js +0 -291
  166. package/dist/commands/references.d.ts +0 -2
  167. package/dist/commands/references.js +0 -193
  168. package/dist/commands/referrals.d.ts +0 -2
  169. package/dist/commands/referrals.js +0 -88
  170. package/dist/commands/rooms-connect.d.ts +0 -17
  171. package/dist/commands/rooms-connect.js +0 -140
  172. package/dist/commands/rooms-rtc-binary.d.ts +0 -2
  173. package/dist/commands/rooms-rtc-binary.js +0 -107
  174. package/dist/commands/rooms-rtc.d.ts +0 -21
  175. package/dist/commands/rooms-rtc.js +0 -171
  176. package/dist/commands/rooms.d.ts +0 -3
  177. package/dist/commands/rooms.js +0 -277
  178. package/dist/commands/run.d.ts +0 -13
  179. package/dist/commands/run.js +0 -246
  180. package/dist/commands/runtime.d.ts +0 -3
  181. package/dist/commands/runtime.js +0 -320
  182. package/dist/commands/sandboxd-binary.d.ts +0 -11
  183. package/dist/commands/sandboxd-binary.js +0 -238
  184. package/dist/commands/search.d.ts +0 -2
  185. package/dist/commands/search.js +0 -114
  186. package/dist/commands/session-access.d.ts +0 -2
  187. package/dist/commands/session-access.js +0 -70
  188. package/dist/commands/skills.d.ts +0 -2
  189. package/dist/commands/skills.js +0 -34
  190. package/dist/commands/space-activity.d.ts +0 -26
  191. package/dist/commands/space-activity.js +0 -147
  192. package/dist/commands/space-commerce.d.ts +0 -2
  193. package/dist/commands/space-commerce.js +0 -514
  194. package/dist/commands/space-displays.d.ts +0 -2
  195. package/dist/commands/space-displays.js +0 -620
  196. package/dist/commands/space-files.d.ts +0 -5
  197. package/dist/commands/space-files.js +0 -215
  198. package/dist/commands/space-invitations.d.ts +0 -29
  199. package/dist/commands/space-invitations.js +0 -189
  200. package/dist/commands/space-turns.d.ts +0 -49
  201. package/dist/commands/space-turns.js +0 -205
  202. package/dist/commands/space-wallet.d.ts +0 -2
  203. package/dist/commands/space-wallet.js +0 -141
  204. package/dist/commands/space-webhooks.d.ts +0 -7
  205. package/dist/commands/space-webhooks.js +0 -73
  206. package/dist/commands/spaces.d.ts +0 -25
  207. package/dist/commands/spaces.js +0 -2170
  208. package/dist/commands/tasks.d.ts +0 -8
  209. package/dist/commands/tasks.js +0 -80
  210. package/dist/commands/version.d.ts +0 -2
  211. package/dist/commands/version.js +0 -21
  212. package/dist/endpoint-options.d.ts +0 -4
  213. package/dist/endpoint-options.js +0 -26
  214. package/dist/env-proxy.d.ts +0 -5
  215. package/dist/env-proxy.js +0 -20
  216. package/dist/help-path.d.ts +0 -18
  217. package/dist/help-path.js +0 -223
  218. package/dist/host/auth.d.ts +0 -20
  219. package/dist/host/auth.js +0 -119
  220. package/dist/host/login-env.d.ts +0 -1
  221. package/dist/host/login-env.js +0 -31
  222. package/dist/host/runtime.d.ts +0 -35
  223. package/dist/host/runtime.js +0 -395
  224. package/dist/host/runtimes.d.ts +0 -9
  225. package/dist/host/runtimes.js +0 -42
  226. package/dist/host/serve.d.ts +0 -2
  227. package/dist/host/serve.js +0 -117
  228. package/dist/host/workspaces.d.ts +0 -2
  229. package/dist/host/workspaces.js +0 -18
  230. package/dist/http-put.d.ts +0 -25
  231. package/dist/http-put.js +0 -132
  232. package/dist/index.d.ts +0 -2
  233. package/dist/index.js +0 -129
  234. package/dist/launcher.d.ts +0 -4
  235. package/dist/launcher.js +0 -38
  236. package/dist/local-media.d.ts +0 -2
  237. package/dist/local-media.js +0 -30
  238. package/dist/network-error.d.ts +0 -3
  239. package/dist/network-error.js +0 -22
  240. package/dist/output.d.ts +0 -46
  241. package/dist/output.js +0 -244
  242. package/dist/runtime/archive-store.d.ts +0 -54
  243. package/dist/runtime/archive-store.js +0 -379
  244. package/dist/runtime/cli-path.d.ts +0 -5
  245. package/dist/runtime/cli-path.js +0 -27
  246. package/dist/runtime/codex-usage.d.ts +0 -7
  247. package/dist/runtime/codex-usage.js +0 -11
  248. package/dist/runtime/connection.d.ts +0 -42
  249. package/dist/runtime/connection.js +0 -789
  250. package/dist/runtime/diagnostics.d.ts +0 -107
  251. package/dist/runtime/diagnostics.js +0 -392
  252. package/dist/runtime/harnesses/chained-projection.d.ts +0 -40
  253. package/dist/runtime/harnesses/chained-projection.js +0 -95
  254. package/dist/runtime/harnesses/chained-transcript.d.ts +0 -24
  255. package/dist/runtime/harnesses/chained-transcript.js +0 -62
  256. package/dist/runtime/harnesses/claude-approval.d.ts +0 -34
  257. package/dist/runtime/harnesses/claude-approval.js +0 -124
  258. package/dist/runtime/harnesses/claude-transcript.d.ts +0 -8
  259. package/dist/runtime/harnesses/claude-transcript.js +0 -138
  260. package/dist/runtime/harnesses/claude.d.ts +0 -8
  261. package/dist/runtime/harnesses/claude.js +0 -225
  262. package/dist/runtime/harnesses/codex-approval.d.ts +0 -25
  263. package/dist/runtime/harnesses/codex-approval.js +0 -69
  264. package/dist/runtime/harnesses/codex.d.ts +0 -4
  265. package/dist/runtime/harnesses/codex.js +0 -269
  266. package/dist/runtime/harnesses/cursor-transcript.d.ts +0 -37
  267. package/dist/runtime/harnesses/cursor-transcript.js +0 -183
  268. package/dist/runtime/harnesses/cursor.d.ts +0 -24
  269. package/dist/runtime/harnesses/cursor.js +0 -620
  270. package/dist/runtime/harnesses/index.d.ts +0 -16
  271. package/dist/runtime/harnesses/index.js +0 -73
  272. package/dist/runtime/harnesses/pi.d.ts +0 -4
  273. package/dist/runtime/harnesses/pi.js +0 -247
  274. package/dist/runtime/harnesses/process.d.ts +0 -31
  275. package/dist/runtime/harnesses/process.js +0 -75
  276. package/dist/runtime/harnesses/stream-json.d.ts +0 -48
  277. package/dist/runtime/harnesses/stream-json.js +0 -336
  278. package/dist/runtime/harnesses/types.d.ts +0 -117
  279. package/dist/runtime/harnesses/types.js +0 -1
  280. package/dist/runtime/harnesses/workbuddy-transcript.d.ts +0 -8
  281. package/dist/runtime/harnesses/workbuddy-transcript.js +0 -127
  282. package/dist/runtime/harnesses/workbuddy.d.ts +0 -21
  283. package/dist/runtime/harnesses/workbuddy.js +0 -123
  284. package/dist/runtime/instance.d.ts +0 -20
  285. package/dist/runtime/instance.js +0 -247
  286. package/dist/runtime/json-rpc.d.ts +0 -53
  287. package/dist/runtime/json-rpc.js +0 -212
  288. package/dist/runtime/launch.d.ts +0 -25
  289. package/dist/runtime/launch.js +0 -247
  290. package/dist/runtime/local-workspace.d.ts +0 -15
  291. package/dist/runtime/local-workspace.js +0 -52
  292. package/dist/runtime/model-catalog.d.ts +0 -12
  293. package/dist/runtime/model-catalog.js +0 -84
  294. package/dist/runtime/native/adapters.d.ts +0 -15
  295. package/dist/runtime/native/adapters.js +0 -11
  296. package/dist/runtime/native/approvals.d.ts +0 -18
  297. package/dist/runtime/native/approvals.js +0 -54
  298. package/dist/runtime/native/archive.d.ts +0 -19
  299. package/dist/runtime/native/archive.js +0 -142
  300. package/dist/runtime/native/attach.d.ts +0 -36
  301. package/dist/runtime/native/attach.js +0 -128
  302. package/dist/runtime/native/codex-link.d.ts +0 -60
  303. package/dist/runtime/native/codex-link.js +0 -322
  304. package/dist/runtime/native/config.d.ts +0 -16
  305. package/dist/runtime/native/config.js +0 -24
  306. package/dist/runtime/native/daemon.d.ts +0 -92
  307. package/dist/runtime/native/daemon.js +0 -380
  308. package/dist/runtime/native/execution.d.ts +0 -26
  309. package/dist/runtime/native/execution.js +0 -34
  310. package/dist/runtime/native/identity.d.ts +0 -9
  311. package/dist/runtime/native/identity.js +0 -15
  312. package/dist/runtime/native/ingest.d.ts +0 -263
  313. package/dist/runtime/native/ingest.js +0 -884
  314. package/dist/runtime/native/install.d.ts +0 -9
  315. package/dist/runtime/native/install.js +0 -113
  316. package/dist/runtime/native/paths.d.ts +0 -2
  317. package/dist/runtime/native/paths.js +0 -7
  318. package/dist/runtime/native/pi-extension.d.ts +0 -36
  319. package/dist/runtime/native/pi-link.d.ts +0 -69
  320. package/dist/runtime/native/pi-link.js +0 -269
  321. package/dist/runtime/native/results.d.ts +0 -41
  322. package/dist/runtime/native/results.js +0 -128
  323. package/dist/runtime/native/sessions.d.ts +0 -45
  324. package/dist/runtime/native/sessions.js +0 -87
  325. package/dist/runtime/native/transcript.d.ts +0 -89
  326. package/dist/runtime/native/transcript.js +0 -656
  327. package/dist/runtime/native/translate.d.ts +0 -46
  328. package/dist/runtime/native/translate.js +0 -299
  329. package/dist/runtime/native/transport.d.ts +0 -7
  330. package/dist/runtime/native/transport.js +0 -16
  331. package/dist/runtime/native/version.d.ts +0 -5
  332. package/dist/runtime/native/version.js +0 -21
  333. package/dist/runtime/preferences.d.ts +0 -7
  334. package/dist/runtime/preferences.js +0 -22
  335. package/dist/runtime/presentation.d.ts +0 -32
  336. package/dist/runtime/presentation.js +0 -124
  337. package/dist/runtime/process-group.d.ts +0 -5
  338. package/dist/runtime/process-group.js +0 -161
  339. package/dist/runtime/projection-store.d.ts +0 -27
  340. package/dist/runtime/projection-store.js +0 -30
  341. package/dist/runtime/space-binding.d.ts +0 -48
  342. package/dist/runtime/space-binding.js +0 -342
  343. package/dist/runtime/supervisor.d.ts +0 -19
  344. package/dist/runtime/supervisor.js +0 -441
  345. package/dist/runtime/turn-projection.d.ts +0 -41
  346. package/dist/runtime/turn-projection.js +0 -120
  347. package/dist/runtime/worker.d.ts +0 -1
  348. package/dist/safe-remote-image.d.ts +0 -36
  349. package/dist/safe-remote-image.js +0 -191
  350. package/dist/self-update.d.ts +0 -7
  351. package/dist/self-update.js +0 -202
  352. package/dist/session-status.d.ts +0 -10
  353. package/dist/session-status.js +0 -25
  354. package/dist/space-files/limit.d.ts +0 -2
  355. package/dist/space-files/limit.js +0 -16
  356. package/dist/space-files/operands.d.ts +0 -17
  357. package/dist/space-files/operands.js +0 -33
  358. package/dist/space-files/transfer.d.ts +0 -53
  359. package/dist/space-files/transfer.js +0 -297
  360. package/dist/space-files/upload.d.ts +0 -17
  361. package/dist/space-files/upload.js +0 -76
  362. package/dist/space.d.ts +0 -44
  363. package/dist/space.js +0 -192
  364. package/dist/version.d.ts +0 -2
  365. package/dist/version.js +0 -17
  366. package/dist/web.d.ts +0 -1
  367. package/dist/web.js +0 -4
  368. /package/dist/{board-kernel → chunks}/lexer.js +0 -0
@@ -1,827 +0,0 @@
1
- import { randomUUID } from "node:crypto";
2
- import { basename } from "node:path";
3
- import { getCohubContext, HttpError } from "@neta-art/cohub";
4
- import { createClient, createClientWithAccessToken } from "../client.js";
5
- import { error, handleHttp, json as outJson, jsonRequested, ok, table } from "../output.js";
6
- import { resolveSpace } from "../space.js";
7
- import { downloadApp } from "../app-download.js";
8
- import { getAppByRef, parseAppRef } from "../app-ref.js";
9
- import { checkAppTarget } from "../app-target.js";
10
- import { putBytes, putLocalFile } from "../http-put.js";
11
- import { registerAppCommerce } from "./app-commerce.js";
12
- import { registerAppDomains } from "./app-domains.js";
13
- import { collectPublicUpload } from "./public.js";
14
- const APP_STATUSES = ["published", "disabled"];
15
- const APP_VISIBILITIES = ["public", "space"];
16
- const collectOption = (value, previous = []) => [...previous, value];
17
- function parseChoice(value, name, choices) {
18
- if (choices.includes(value))
19
- return value;
20
- return error(`Invalid ${name}`, `Use one of: ${choices.join(", ")}`);
21
- }
22
- function parseJsonObject(value, name) {
23
- if (!value)
24
- return undefined;
25
- try {
26
- const parsed = JSON.parse(value);
27
- if (parsed && typeof parsed === "object" && !Array.isArray(parsed))
28
- return parsed;
29
- }
30
- catch {
31
- // handled below
32
- }
33
- return error(`Invalid ${name}`, `${name} must be a JSON object`);
34
- }
35
- /** Human-readable version provenance: a session title, a channel, or blank. */
36
- function formatVersionSource(value) {
37
- if (!value || typeof value !== "object")
38
- return "";
39
- const source = value;
40
- if (source?.session)
41
- return source.session.title?.trim() || source.session.id;
42
- return source?.via ? `via ${source.via}` : "";
43
- }
44
- function parseJsonValue(value, name) {
45
- if (!value)
46
- return null;
47
- try {
48
- return JSON.parse(value);
49
- }
50
- catch {
51
- return error(`Invalid ${name}`, `${name} must be valid JSON`);
52
- }
53
- }
54
- function compactObject(input) {
55
- return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== undefined));
56
- }
57
- function withCohubBarMeta(input) {
58
- if (!input.hideCohubBar && !input.showCohubBar)
59
- return input.meta;
60
- const meta = input.meta ? { ...input.meta } : {};
61
- const presentation = meta.presentation && typeof meta.presentation === "object" && !Array.isArray(meta.presentation)
62
- ? { ...meta.presentation }
63
- : {};
64
- if (input.hideCohubBar)
65
- presentation.hideCohubBar = true;
66
- if (input.showCohubBar)
67
- delete presentation.hideCohubBar;
68
- if (Object.keys(presentation).length > 0)
69
- meta.presentation = presentation;
70
- else
71
- delete meta.presentation;
72
- return Object.keys(meta).length > 0 ? meta : null;
73
- }
74
- const MAX_APP_SOURCE_FILES = 1000;
75
- const MAX_APP_SOURCE_BYTES = 1024 * 1024 * 1024;
76
- const APP_SOURCE_UPLOAD_CONCURRENCY = 4;
77
- async function uploadLocalAppSource(client, spaceId, source) {
78
- if (source.targetType === "port")
79
- return null;
80
- const upload = await collectPublicUpload(source.targetRef);
81
- const totalBytes = upload.files.reduce((sum, file) => sum + file.size, 0);
82
- if (upload.files.length > MAX_APP_SOURCE_FILES)
83
- return error("App source is too large", `Use no more than ${MAX_APP_SOURCE_FILES} files.`);
84
- if (totalBytes > MAX_APP_SOURCE_BYTES)
85
- return error("App source is too large", "The total source size must not exceed 1 GiB.");
86
- const uploadId = randomUUID();
87
- const directoryPrefix = source.targetType === "directory" ? upload.destination.replace(/\/$/, "") : "";
88
- const files = new Array(upload.files.length);
89
- let nextIndex = 0;
90
- const workers = Array.from({ length: Math.min(APP_SOURCE_UPLOAD_CONCURRENCY, upload.files.length) }, async () => {
91
- while (nextIndex < upload.files.length) {
92
- const index = nextIndex++;
93
- const file = upload.files[index];
94
- if (!file)
95
- return;
96
- const plan = await client.publicAssets.createUpload({
97
- purpose: "app_source",
98
- uploadProtocol: "presigned_put_v1",
99
- spaceId,
100
- sessionId: uploadId,
101
- file: { size: file.size, mimeType: file.mimeType, filename: basename(file.publicPath) },
102
- });
103
- await putLocalFile({
104
- url: plan.asset.uploadUrl,
105
- filePath: file.localPath,
106
- size: file.size,
107
- headers: plan.asset.uploadHeaders,
108
- label: file.publicPath,
109
- });
110
- const path = directoryPrefix && file.publicPath.startsWith(`${directoryPrefix}/`)
111
- ? file.publicPath.slice(directoryPrefix.length + 1)
112
- : basename(file.publicPath);
113
- files[index] = { path, objectKey: plan.asset.objectKey, size: file.size, mimeType: file.mimeType };
114
- }
115
- });
116
- await Promise.all(workers);
117
- const manifest = JSON.stringify({ kind: "cohub.app-source", version: 1, targetType: source.targetType, files });
118
- const manifestBlob = new Blob([manifest], { type: "application/json" });
119
- const manifestPlan = await client.publicAssets.createUpload({
120
- purpose: "app_source",
121
- uploadProtocol: "presigned_put_v1",
122
- spaceId,
123
- sessionId: uploadId,
124
- file: { size: manifestBlob.size, mimeType: "application/json", filename: "manifest.json" },
125
- });
126
- await putBytes({
127
- url: manifestPlan.asset.uploadUrl,
128
- body: manifestBlob,
129
- size: manifestBlob.size,
130
- headers: manifestPlan.asset.uploadHeaders,
131
- label: "app source manifest",
132
- });
133
- const manifestAsset = manifestPlan.asset;
134
- return { sourceRef: manifestAsset.objectKey, targetRef: source.targetType === "file" ? files[0]?.path ?? "" : "." };
135
- }
136
- function resolveDefaultAppSource() {
137
- return getCohubContext().runtime.kind === "sandbox" ? "workspace" : "local";
138
- }
139
- function resolveTarget(opts) {
140
- const targets = [
141
- opts.file ? { targetType: "file", targetRef: opts.file } : null,
142
- opts.dir ? { targetType: "directory", targetRef: opts.dir } : null,
143
- opts.port ? { targetType: "port", targetRef: opts.port } : null,
144
- ].filter((target) => Boolean(target));
145
- if (targets.length === 0)
146
- return null;
147
- if (targets.length > 1)
148
- return error("Conflicting target", "Use only one of --file, --dir, or --port");
149
- return targets[0] ?? null;
150
- }
151
- function resolveStatus(opts) {
152
- const values = [opts.status, opts.disabled ? "disabled" : undefined].filter(Boolean);
153
- if (values.length > 1)
154
- return error("Conflicting status", "Use only one of --status or --disabled");
155
- return values[0] ? parseChoice(values[0], "status", APP_STATUSES) : "published";
156
- }
157
- /**
158
- * Fail early when a Space-relative `--file` / `--dir` target cannot be a valid
159
- * publish source. The publish worker resolves targets inside the target
160
- * Space's workspace, not on the local filesystem.
161
- */
162
- async function guardAppTarget(client, spaceId, target) {
163
- const failure = await checkAppTarget(client, spaceId, target);
164
- if (failure) {
165
- error(failure.status === 404 ? "Publish target not found" : "Publish target is invalid", `${failure.message} (--${target.targetType === "directory" ? "dir" : "file"} takes a Space workspace path, not a local path).`);
166
- }
167
- }
168
- /**
169
- * Translate the publish worker's bare fs errors (e.g. a target removed between
170
- * preflight and snapshot) into the same explicit wording as the preflight.
171
- */
172
- function translateTargetWorkerError(e) {
173
- if (!(e instanceof HttpError))
174
- return;
175
- if (e.code !== "path_not_found" && e.code !== "not_a_directory" && e.code !== "not_a_file" && e.code !== "symlink_not_supported")
176
- return;
177
- error(e.code === "path_not_found" ? "Publish target not found" : "Publish target is invalid", "The publish target is a Space workspace path; the Space workspace no longer contains a valid target at that path.");
178
- }
179
- function resolveVisibility(value) {
180
- return value ? parseChoice(value, "visibility", APP_VISIBILITIES) : undefined;
181
- }
182
- function printApp(app) {
183
- table([app], [
184
- { key: "id", label: "ID" },
185
- { key: "slug", label: "Slug" },
186
- { key: "status", label: "Status" },
187
- { key: "visibility", label: "Visibility" },
188
- { key: "targetType", label: "Target" },
189
- { key: "targetRef", label: "Ref" },
190
- { key: "latestVersion", label: "Version" },
191
- { key: "publishedAt", label: "Published" },
192
- ]);
193
- }
194
- function printAppDetails(result) {
195
- const lines = [
196
- result.publicUrl ? `Public URL: ${result.publicUrl}` : null,
197
- result.content?.url ? `Content URL: ${result.content.url}` : null,
198
- typeof result.likeCount === "number" ? `Likes: ${result.likeCount}` : null,
199
- ].filter((line) => Boolean(line));
200
- if (lines.length)
201
- console.log(`\n${lines.join("\n")}`);
202
- }
203
- function promotionUrl(publicUrl, promotion) {
204
- if (!publicUrl)
205
- return null;
206
- const url = new URL(publicUrl);
207
- url.searchParams.set("cohub_campaign", promotion.id);
208
- for (const [key, value] of Object.entries(promotion.parameters))
209
- url.searchParams.set(key, value);
210
- return url.toString();
211
- }
212
- function printAppStats(stats) {
213
- table([stats.summary], [
214
- { key: "totalViews", label: "Total" },
215
- { key: "views24h", label: "24h" },
216
- { key: "views7d", label: "7d" },
217
- { key: "views30d", label: "30d" },
218
- ...(stats.summary.totalLikes === undefined ? [] : [{ key: "totalLikes", label: "Likes" }]),
219
- ]);
220
- if (stats.sources.length) {
221
- console.log("");
222
- table(stats.sources, [
223
- { key: "source", label: "Source" },
224
- { key: "views", label: "Views" },
225
- ]);
226
- }
227
- }
228
- export async function getAppStatsByRef(client, app) {
229
- const ref = parseAppRef(app);
230
- if ("id" in ref)
231
- return client.apps.getStats(ref.id);
232
- const detail = await getAppByRef(client, app);
233
- return client.apps.getStats(detail.app.id);
234
- }
235
- async function confirmDelete(opts) {
236
- if (opts.yes)
237
- return;
238
- if (!process.stdin.isTTY || !process.stdout.isTTY)
239
- return error("Confirmation required", "Pass --yes to delete the app.");
240
- process.stdout.write("Deleting an app also removes its versions and viewer grants. Continue? [y/N] ");
241
- const chunks = [];
242
- for await (const chunk of process.stdin) {
243
- chunks.push(chunk);
244
- break;
245
- }
246
- const answer = Buffer.concat(chunks).toString().trim().toLowerCase();
247
- if (answer !== "y" && answer !== "yes")
248
- return error("Cancelled");
249
- }
250
- async function publishAppVersion(id, opts) {
251
- const client = createClient();
252
- try {
253
- const result = await client.apps.publishVersion(id);
254
- if (jsonRequested(opts))
255
- return outJson(result);
256
- ok(`App version updated: v${result.version.version}`);
257
- printApp(result.app);
258
- }
259
- catch (e) {
260
- translateTargetWorkerError(e);
261
- handleHttp(e);
262
- }
263
- }
264
- export function registerApps(program) {
265
- const appsCmd = program
266
- .command("apps")
267
- .description("App management")
268
- // Legacy spelling; hidden from help but still typed by existing scripts.
269
- .alias("works")
270
- .hook("preAction", () => {
271
- if (process.argv.slice(2).includes("works")) {
272
- ok("Deprecated: `cohub works` is now `cohub apps`.");
273
- }
274
- });
275
- appsCmd
276
- .command("ls")
277
- .alias("list")
278
- .description("List apps in the target space")
279
- .option("--json", "Output as JSON")
280
- .action(async (opts) => {
281
- const spaceId = await resolveSpace(appsCmd, { home: true });
282
- const client = createClient();
283
- try {
284
- const result = await client.apps.listBySpace(spaceId);
285
- if (jsonRequested(opts))
286
- return outJson(result);
287
- table(result.apps, [
288
- { key: "id", label: "ID" },
289
- { key: "slug", label: "Slug" },
290
- { key: "status", label: "Status" },
291
- { key: "visibility", label: "Visibility" },
292
- { key: "targetType", label: "Target" },
293
- { key: "targetRef", label: "Ref" },
294
- { key: "latestVersion", label: "Version" },
295
- { key: "publishedAt", label: "Published" },
296
- ]);
297
- }
298
- catch (e) {
299
- handleHttp(e);
300
- }
301
- });
302
- appsCmd
303
- .command("get <app>")
304
- .description("Show app details by id, URL, mention URI, or username/space/app")
305
- .option("--json", "Output as JSON")
306
- .action(async (app, opts) => {
307
- const client = createClient();
308
- try {
309
- const result = await getAppByRef(client, app);
310
- if (jsonRequested(opts))
311
- return outJson(result);
312
- printApp(result.app);
313
- printAppDetails(result);
314
- }
315
- catch (e) {
316
- handleHttp(e);
317
- }
318
- });
319
- appsCmd
320
- .command("stats <app>")
321
- .description("Show view statistics by id, URL, mention URI, or username/space/app")
322
- .option("--json", "Output as JSON")
323
- .action(async (app, opts) => {
324
- const client = createClient();
325
- try {
326
- const result = await getAppStatsByRef(client, app);
327
- if (jsonRequested(opts))
328
- return outJson(result);
329
- printAppStats(result);
330
- }
331
- catch (e) {
332
- handleHttp(e);
333
- }
334
- });
335
- for (const liked of [true, false]) {
336
- appsCmd
337
- .command(`${liked ? "like" : "unlike"} <app>`)
338
- .description(`${liked ? "Like" : "Unlike"} an app by id, URL, mention URI, or username/space/app`)
339
- .option("--json", "Output as JSON")
340
- .action(async (app, opts) => {
341
- const client = createClient();
342
- try {
343
- const ref = parseAppRef(app);
344
- const appId = "id" in ref ? ref.id : (await getAppByRef(client, app)).app.id;
345
- const result = { appId, liked: await client.user.likes.set("app", appId, liked) };
346
- if (jsonRequested(opts))
347
- return outJson(result);
348
- ok(result.liked ? "Liked" : "Unliked");
349
- }
350
- catch (e) {
351
- handleHttp(e);
352
- }
353
- });
354
- }
355
- appsCmd
356
- .command("download <app>")
357
- .description("Download a published file or directory app")
358
- .option("-o, --output <path>", "Output file or directory")
359
- .option("--json", "Output as JSON")
360
- .action(async (app, opts) => {
361
- const client = createClient();
362
- try {
363
- const detail = await getAppByRef(client, app);
364
- const result = await downloadApp(detail, opts.output);
365
- if (jsonRequested(opts))
366
- return outJson(result);
367
- ok(`Downloaded ${result.files} file${result.files === 1 ? "" : "s"} to ${result.output}`);
368
- }
369
- catch (e) {
370
- handleHttp(e);
371
- }
372
- });
373
- const actionsCmd = appsCmd
374
- .command("actions")
375
- .description("Run published App Actions");
376
- actionsCmd
377
- .command("run <app> <action>")
378
- .description("Run an App Action")
379
- .option("--input <json>", "JSON input", "null")
380
- .option("--json", "Output as JSON")
381
- .action(async (appRef, action, opts) => {
382
- const client = createClient();
383
- try {
384
- const ref = parseAppRef(appRef);
385
- const detail = "id" in ref
386
- ? await client.apps.getPublicById(ref.id)
387
- : await client.apps.getBySlug(ref.username, ref.spaceSlug, ref.appSlug);
388
- const session = await client.apps.createSession(detail.app.id);
389
- const appClient = createClientWithAccessToken(session.token);
390
- const result = await appClient.apps.runAction(detail.app.id, action, parseJsonValue(opts.input, "input"));
391
- if (jsonRequested(opts))
392
- return outJson(result);
393
- ok(`App Action queued: ${result.taskRunId}`);
394
- }
395
- catch (e) {
396
- handleHttp(e);
397
- }
398
- });
399
- appsCmd
400
- .command("resolve <appSlug>")
401
- .description("Resolve a published app by owner and space slug")
402
- .option("--owner <username>", "Owner username")
403
- .option("--space-slug <slug>", "Space slug")
404
- .option("--json", "Output as JSON")
405
- .action(async (appSlug, opts) => {
406
- if (!opts.owner?.trim())
407
- return error("Missing owner username", "Pass --owner <username>.");
408
- if (!opts.spaceSlug?.trim())
409
- return error("Missing space slug", "Pass --space-slug <slug>.");
410
- const client = createClient();
411
- try {
412
- const result = await client.apps.getBySlug(opts.owner.trim(), opts.spaceSlug.trim(), appSlug);
413
- if (jsonRequested(opts))
414
- return outJson(result);
415
- printApp(result.app);
416
- printAppDetails(result);
417
- }
418
- catch (e) {
419
- handleHttp(e);
420
- }
421
- });
422
- appsCmd
423
- .command("publish <slug>")
424
- .description("Create or publish an app in the target space")
425
- .option("--source <source>", "Source: workspace or local (auto-detected from runtime by default)")
426
- .option("--file <path>", "Publish a file from the selected source")
427
- .option("--dir <path>", "Publish a directory site from the selected source")
428
- .option("--port <port>", "Publish a public sandbox port")
429
- .option("--disabled", "Create as disabled")
430
- .option("--status <status>", "App status: published, disabled")
431
- .option("--visibility <visibility>", "App visibility: public, space")
432
- .option("--app-scope <scope>", "Scope granted directly to the app runtime (space.view, session.view, file.view, file.edit, taskrun.view, session.prompt.readonly, session.prompt.fullaccess, command.execute)", collectOption, [])
433
- .option("--viewer-scope <scope>", "Deprecated: viewer grants are no longer gated by the app configuration", collectOption, [])
434
- .option("--meta <json>", "App metadata as a JSON object")
435
- .option("--hide-cohub-bar", "Hide the Cohub footer bar on the public app page")
436
- .option("--show-cohub-bar", "Show the Cohub footer bar on the public app page")
437
- .option("--json", "Output as JSON")
438
- .action(async (slug, opts) => {
439
- if (opts.hideCohubBar && opts.showCohubBar)
440
- return error("Conflicting Cohub bar options", "Use either --hide-cohub-bar or --show-cohub-bar.");
441
- const target = resolveTarget(opts);
442
- if (!target)
443
- return error("Missing target", "Use one of --file, --dir, or --port.");
444
- const source = opts.source ? parseChoice(opts.source, "source", ["workspace", "local"]) : resolveDefaultAppSource();
445
- if (target.targetType === "port" && opts.source)
446
- return error("Invalid source", "--source applies only to --file and --dir.");
447
- const spaceId = await resolveSpace(appsCmd, { home: true });
448
- const client = createClient();
449
- let { targetType, targetRef } = target;
450
- let sourceRef = null;
451
- if (source === "local") {
452
- const uploaded = await uploadLocalAppSource(client, spaceId, target);
453
- if (!uploaded)
454
- return error("Invalid source", "--source local applies only to --file and --dir.");
455
- targetRef = uploaded.targetRef;
456
- sourceRef = uploaded.sourceRef;
457
- }
458
- else if (targetType !== "port") {
459
- await guardAppTarget(client, spaceId, { targetType, targetRef });
460
- }
461
- const status = resolveStatus(opts);
462
- const meta = withCohubBarMeta({
463
- meta: parseJsonObject(opts.meta, "meta"),
464
- hideCohubBar: opts.hideCohubBar,
465
- showCohubBar: opts.showCohubBar,
466
- });
467
- const publishMeta = source === "local"
468
- ? { ...(meta ?? {}), runtime: { source: { type: "upload", ref: sourceRef } } }
469
- : meta;
470
- const input = {
471
- spaceId,
472
- slug,
473
- status,
474
- visibility: resolveVisibility(opts.visibility),
475
- targetType: target.targetType,
476
- targetRef,
477
- appScopes: opts.appScope,
478
- allowedViewerScopes: opts.viewerScope,
479
- meta: publishMeta,
480
- };
481
- try {
482
- const result = await client.apps.create(input);
483
- if (jsonRequested(opts))
484
- return outJson(result);
485
- ok(`App published: ${result.app.id}`);
486
- printApp(result.app);
487
- }
488
- catch (e) {
489
- translateTargetWorkerError(e);
490
- if (!(e instanceof HttpError) || e.status !== 409)
491
- handleHttp(e);
492
- try {
493
- const { apps } = await client.apps.listBySpace(spaceId);
494
- const existingApp = apps.find((app) => app.slug === slug);
495
- if (!existingApp)
496
- return handleHttp(e);
497
- const { app } = await client.apps.update(existingApp.id, {
498
- status: status === "published" && existingApp.status !== "published" ? existingApp.status : status,
499
- visibility: resolveVisibility(opts.visibility),
500
- targetType: target.targetType,
501
- targetRef,
502
- appScopes: opts.appScope,
503
- allowedViewerScopes: opts.viewerScope,
504
- meta: publishMeta,
505
- });
506
- const publishedVersion = status === "published"
507
- ? await client.apps.publishVersion(app.id)
508
- : null;
509
- const result = publishedVersion ?? { app };
510
- if (jsonRequested(opts))
511
- return outJson(result);
512
- ok(status === "published" && publishedVersion ? `App version updated: v${publishedVersion.version.version}` : `App updated: ${app.id}`);
513
- printApp(result.app);
514
- }
515
- catch (fallbackError) {
516
- translateTargetWorkerError(fallbackError);
517
- handleHttp(fallbackError);
518
- }
519
- }
520
- });
521
- appsCmd
522
- .command("update <id>")
523
- .description("Update app settings")
524
- .option("--slug <slug>", "New app slug")
525
- .option("--file <path>", "Use a file target (HTML page, board, or any other file) from the Space workspace")
526
- .option("--dir <path>", "Use a directory site target from the Space workspace")
527
- .option("--port <port>", "Use a public sandbox port target")
528
- .option("--disabled", "Set status to disabled")
529
- .option("--status <status>", "App status: published, disabled")
530
- .option("--visibility <visibility>", "App visibility: public, space")
531
- .option("--app-scope <scope>", "Scope granted directly to the app runtime (space.view, session.view, file.view, file.edit, taskrun.view, session.prompt.readonly, session.prompt.fullaccess, command.execute)", collectOption, [])
532
- .option("--viewer-scope <scope>", "Deprecated: viewer grants are no longer gated by the app configuration", collectOption, [])
533
- .option("--clear-app-scopes", "Clear app runtime scopes")
534
- .option("--clear-viewer-scopes", "Deprecated: clear legacy scope metadata")
535
- .option("--meta <json>", "App metadata as a JSON object")
536
- .option("--hide-cohub-bar", "Hide the Cohub footer bar on the public app page")
537
- .option("--show-cohub-bar", "Show the Cohub footer bar on the public app page")
538
- .option("--json", "Output as JSON")
539
- .action(async (id, opts) => {
540
- if (opts.hideCohubBar && opts.showCohubBar)
541
- return error("Conflicting Cohub bar options", "Use either --hide-cohub-bar or --show-cohub-bar.");
542
- const target = resolveTarget(opts);
543
- if (opts.clearAppScopes && opts.appScope?.length)
544
- return error("Conflicting app scopes", "Use either --app-scope or --clear-app-scopes.");
545
- if (opts.clearViewerScopes && opts.viewerScope?.length)
546
- return error("Conflicting viewer scopes", "Use either --viewer-scope or --clear-viewer-scopes.");
547
- const hasMetaUpdate = opts.meta !== undefined || opts.hideCohubBar || opts.showCohubBar;
548
- const client = createClient();
549
- if (target) {
550
- // Resolve the app's home Space so the preflight checks the same
551
- // workspace the publish worker will read from.
552
- try {
553
- const current = await client.apps.get(id);
554
- const { targetType, targetRef } = target;
555
- if (targetType !== "port")
556
- await guardAppTarget(client, current.app.spaceId, { targetType, targetRef });
557
- }
558
- catch {
559
- // The update request below surfaces errors for unknown apps.
560
- }
561
- }
562
- let meta;
563
- if (hasMetaUpdate) {
564
- let baseMeta = opts.meta !== undefined ? parseJsonObject(opts.meta, "meta") ?? null : undefined;
565
- if (baseMeta === undefined && (opts.hideCohubBar || opts.showCohubBar)) {
566
- try {
567
- baseMeta = (await client.apps.get(id)).app.meta;
568
- }
569
- catch (e) {
570
- handleHttp(e);
571
- }
572
- }
573
- meta = withCohubBarMeta({
574
- meta: baseMeta,
575
- hideCohubBar: opts.hideCohubBar,
576
- showCohubBar: opts.showCohubBar,
577
- });
578
- }
579
- const nextStatus = opts.status || opts.disabled ? resolveStatus(opts) : undefined;
580
- const currentApp = nextStatus === "published" ? (await client.apps.get(id)).app : null;
581
- const input = compactObject({
582
- slug: opts.slug,
583
- status: nextStatus === "published" && currentApp?.status !== "published" ? currentApp?.status : nextStatus,
584
- visibility: resolveVisibility(opts.visibility),
585
- targetType: target?.targetType,
586
- targetRef: target?.targetRef,
587
- appScopes: opts.clearAppScopes ? [] : opts.appScope?.length ? opts.appScope : undefined,
588
- allowedViewerScopes: opts.clearViewerScopes ? [] : opts.viewerScope?.length ? opts.viewerScope : undefined,
589
- meta,
590
- });
591
- if (Object.keys(input).length === 0)
592
- return error("Nothing to update", "Pass --slug, --file, --dir, --port, --status, --visibility, --app-scope, --viewer-scope, --clear-app-scopes, --clear-viewer-scopes, --meta, --hide-cohub-bar, or --show-cohub-bar.");
593
- try {
594
- const updated = await client.apps.update(id, input);
595
- const publishedVersion = nextStatus === "published" && currentApp?.status !== "published"
596
- ? await client.apps.publishVersion(updated.app.id)
597
- : null;
598
- const result = publishedVersion ?? { app: updated.app };
599
- if (jsonRequested(opts))
600
- return outJson(result);
601
- ok(publishedVersion ? `App published: v${publishedVersion.version.version}` : "App updated");
602
- printApp(result.app);
603
- }
604
- catch (e) {
605
- translateTargetWorkerError(e);
606
- handleHttp(e);
607
- }
608
- });
609
- appsCmd
610
- .command("publish-version <id>")
611
- .description("Publish or update the current app version")
612
- .option("--json", "Output as JSON")
613
- .action(publishAppVersion);
614
- appsCmd
615
- .command("release <id>", { hidden: true })
616
- .description("Deprecated alias for publish-version")
617
- .option("--json", "Output as JSON")
618
- .action(publishAppVersion);
619
- appsCmd
620
- .command("versions <id>")
621
- .description("List app versions")
622
- .option("--json", "Output as JSON")
623
- .action(async (id, opts) => {
624
- const client = createClient();
625
- try {
626
- const result = await client.apps.listVersions(id);
627
- if (jsonRequested(opts))
628
- return outJson(result);
629
- table(result.versions, [
630
- { key: "version", label: "Version" },
631
- { key: "id", label: "ID" },
632
- { key: "targetType", label: "Target" },
633
- { key: "targetRef", label: "Ref" },
634
- { key: "source", label: "Source", format: formatVersionSource },
635
- { key: "createdAt", label: "Created" },
636
- ]);
637
- }
638
- catch (e) {
639
- handleHttp(e);
640
- }
641
- });
642
- const promotionsCmd = appsCmd.command("promotions").description("App promotion links and analytics");
643
- promotionsCmd
644
- .command("list <app>")
645
- .alias("ls")
646
- .description("List promotion links")
647
- .option("--json", "Output as JSON")
648
- .action(async (appRef, opts) => {
649
- const client = createClient();
650
- try {
651
- const detail = await getAppByRef(client, appRef);
652
- const result = await client.apps.listPromotions(detail.app.id);
653
- const promotions = result.promotions.map((promotion) => ({
654
- ...promotion,
655
- url: promotionUrl(detail.publicUrl, promotion),
656
- }));
657
- if (jsonRequested(opts))
658
- return outJson({ ...result, promotions });
659
- table(promotions, [
660
- { key: "name", label: "Name" },
661
- { key: "provider", label: "Provider" },
662
- { key: "id", label: "ID" },
663
- { key: "url", label: "URL" },
664
- ]);
665
- }
666
- catch (e) {
667
- handleHttp(e);
668
- }
669
- });
670
- promotionsCmd
671
- .command("create <app>")
672
- .description("Create an immutable promotion link")
673
- .requiredOption("--name <name>", "Promotion name")
674
- .option("--provider <provider>", "Promotion provider", "generic")
675
- .option("--utm-id <value>", "UTM campaign ID")
676
- .option("--utm-source <value>", "UTM source")
677
- .option("--utm-medium <value>", "UTM medium")
678
- .option("--utm-campaign <value>", "UTM campaign")
679
- .option("--utm-term <value>", "UTM term")
680
- .option("--utm-content <value>", "UTM content")
681
- .option("--json", "Output as JSON")
682
- .action(async (appRef, opts) => {
683
- const client = createClient();
684
- try {
685
- const detail = await getAppByRef(client, appRef);
686
- const parameters = Object.fromEntries(Object.entries({
687
- utm_id: opts.utmId,
688
- utm_source: opts.utmSource,
689
- utm_medium: opts.utmMedium,
690
- utm_campaign: opts.utmCampaign,
691
- utm_term: opts.utmTerm,
692
- utm_content: opts.utmContent,
693
- }).filter((entry) => typeof entry[1] === "string"));
694
- const result = await client.apps.createPromotion(detail.app.id, {
695
- name: opts.name,
696
- provider: opts.provider,
697
- parameters,
698
- });
699
- const url = promotionUrl(detail.publicUrl, result.promotion);
700
- if (jsonRequested(opts))
701
- return outJson({ ...result, url });
702
- ok("Promotion created");
703
- table([{ ...result.promotion, url }], [
704
- { key: "name", label: "Name" },
705
- { key: "provider", label: "Provider" },
706
- { key: "id", label: "ID" },
707
- { key: "url", label: "URL" },
708
- ]);
709
- }
710
- catch (e) {
711
- handleHttp(e);
712
- }
713
- });
714
- promotionsCmd
715
- .command("stats <app> <promotionId>")
716
- .description("Show promotion analytics")
717
- .option("--json", "Output as JSON")
718
- .action(async (appRef, promotionId, opts) => {
719
- const client = createClient();
720
- try {
721
- const detail = await getAppByRef(client, appRef);
722
- const result = await client.apps.getPromotionStats(detail.app.id, promotionId);
723
- if (jsonRequested(opts))
724
- return outJson(result);
725
- table([{
726
- name: result.promotion.name,
727
- landing: result.summary.landing,
728
- ready: result.summary.ready,
729
- registered: result.summary.registrationCompleted,
730
- paywall: result.summary.paywallViewed,
731
- checkout: result.summary.checkoutStarted,
732
- readyRate: `${(result.summary.readyRate * 100).toFixed(1)}%`,
733
- }], [
734
- { key: "name", label: "Name" },
735
- { key: "landing", label: "Landing" },
736
- { key: "ready", label: "Ready" },
737
- { key: "registered", label: "Registered" },
738
- { key: "paywall", label: "Paywall" },
739
- { key: "checkout", label: "Checkout" },
740
- { key: "readyRate", label: "Ready rate" },
741
- ]);
742
- }
743
- catch (e) {
744
- handleHttp(e);
745
- }
746
- });
747
- registerAppCommerce(appsCmd);
748
- registerAppDomains(appsCmd);
749
- // ── Viewer grants ─────────────────────────────────────────────────────────
750
- appsCmd
751
- .command("authorize <app>")
752
- .description("Grant an app scopes as the current user")
753
- .requiredOption("--scope <scope>", "Scope to grant (repeatable)", collectOption, [])
754
- .option("--space <spaceId>", "Target space; defaults to the app's own space")
755
- .option("--extend", "Add scopes without replacing active grants")
756
- .option("--json", "Output as JSON")
757
- .action(async (appRef, opts) => {
758
- const client = createClient();
759
- try {
760
- const detail = await getAppByRef(client, appRef);
761
- const result = await client.apps.authorize(detail.app.id, {
762
- scopes: opts.scope,
763
- ...(opts.space ? { spaceId: opts.space } : {}),
764
- ...(opts.extend ? { scopeMode: "extend" } : {}),
765
- });
766
- if (jsonRequested(opts))
767
- return outJson(result);
768
- ok(`Granted ${result.grant.scopes.join(", ")} on space ${result.grant.spaceId}`);
769
- }
770
- catch (e) {
771
- handleHttp(e);
772
- }
773
- });
774
- appsCmd
775
- .command("grants <app>")
776
- .description("List your grants for an app")
777
- .option("--json", "Output as JSON")
778
- .action(async (appRef, opts) => {
779
- const client = createClient();
780
- try {
781
- const detail = await getAppByRef(client, appRef);
782
- const result = await client.apps.listMyGrants(detail.app.id);
783
- if (jsonRequested(opts))
784
- return outJson(result);
785
- table(result.grants, [
786
- { key: "id", label: "ID" },
787
- { key: "spaceId", label: "Space" },
788
- { key: "scopes", label: "Scopes" },
789
- { key: "expiresAt", label: "Expires" },
790
- { key: "revokedAt", label: "Revoked" },
791
- ]);
792
- }
793
- catch (e) {
794
- handleHttp(e);
795
- }
796
- });
797
- appsCmd
798
- .command("revoke <app> <grantId>")
799
- .description("Revoke one of your grants for an app")
800
- .action(async (appRef, grantId) => {
801
- const client = createClient();
802
- try {
803
- const detail = await getAppByRef(client, appRef);
804
- await client.apps.revokeMyGrant(detail.app.id, grantId);
805
- ok("Grant revoked");
806
- }
807
- catch (e) {
808
- handleHttp(e);
809
- }
810
- });
811
- appsCmd
812
- .command("rm <id>")
813
- .alias("delete")
814
- .description("Delete an app")
815
- .option("-y, --yes", "Confirm deletion")
816
- .action(async (id, opts) => {
817
- await confirmDelete(opts);
818
- const client = createClient();
819
- try {
820
- await client.apps.delete(id);
821
- ok("App deleted");
822
- }
823
- catch (e) {
824
- handleHttp(e);
825
- }
826
- });
827
- }