@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
@@ -0,0 +1,309 @@
1
+ import { r as createRealtimeClient } from "./client.js";
2
+ import { s as HttpError } from "./app-realtime.js";
3
+ import { r as readRoomLines } from "./rooms-connect2.js";
4
+ import { spawn } from "node:child_process";
5
+ import { homedir } from "node:os";
6
+ import { createReadStream, createWriteStream } from "node:fs";
7
+ import { join, resolve } from "node:path";
8
+ import { createHash } from "node:crypto";
9
+ import { Readable, Transform } from "node:stream";
10
+ import { chmod, lstat, mkdir, mkdtemp, readFile, rename, rm, writeFile } from "node:fs/promises";
11
+ import { pipeline } from "node:stream/promises";
12
+ import { createGunzip } from "node:zlib";
13
+ const MAX_BINARY_BYTES = 134217728;
14
+ async function digest(path) {
15
+ const hash = createHash("sha256");
16
+ await pipeline(createReadStream(path), hash);
17
+ return hash.digest("hex");
18
+ }
19
+ async function readText(response, limit) {
20
+ if (!response.body) throw new Error("Empty RTC helper response");
21
+ const reader = response.body.getReader();
22
+ const parts = [];
23
+ let bytes = 0;
24
+ try {
25
+ for (;;) {
26
+ const { done, value } = await reader.read();
27
+ if (done) break;
28
+ bytes += value.length;
29
+ if (bytes > limit) throw new Error("RTC helper metadata exceeds the size limit");
30
+ parts.push(value);
31
+ }
32
+ } finally {
33
+ await reader.cancel();
34
+ }
35
+ return Buffer.concat(parts).toString("utf8");
36
+ }
37
+ async function ensureRtcBinary(local) {
38
+ const override = local || process.env.COHUB_RTC_BIN?.trim();
39
+ if (override) {
40
+ if (!(await lstat(override)).isFile()) throw new Error("RTC helper must be a regular file");
41
+ return resolve(override);
42
+ }
43
+ const platform = {
44
+ linux: "linux",
45
+ darwin: "darwin"
46
+ }[process.platform];
47
+ const arch = {
48
+ x64: "amd64",
49
+ arm64: "arm64"
50
+ }[process.arch];
51
+ if (!platform || !arch) throw new Error("Unsupported RTC helper platform; use --helper with a local binary");
52
+ const version = process.env.COHUB_RTC_VERSION?.trim() || "v2.68.0";
53
+ if (!version) throw new Error("No RTC helper release is pinned yet; use --helper or COHUB_RTC_VERSION with a published global release");
54
+ if (!/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,63}$/.test(version)) throw new Error("Invalid RTC helper version");
55
+ const directory = join(homedir(), ".cache", "cohub", "rtc", version, `${platform}-${arch}`);
56
+ const binary = join(directory, "cohub-rtc");
57
+ const checksum = `${binary}.sha256`;
58
+ const expected = await readFile(checksum, "utf8").catch(() => "");
59
+ if (/^[a-f0-9]{64}$/.test(expected) && (await lstat(binary).catch(() => null))?.isFile() && await digest(binary) === expected) return binary;
60
+ await mkdir(directory, { recursive: true });
61
+ const temporary = await mkdtemp(join(directory, ".download-"));
62
+ const base = (process.env.COHUB_RTC_CDN_BASE_URL?.trim() || "https://public.cohub.live/rtc").replace(/\/+$/, "");
63
+ const url = `${base}/${version}/cohub-rtc_${platform}_${arch}.gz`;
64
+ const signal = AbortSignal.timeout(12e4);
65
+ try {
66
+ const manifest = await fetch(`${url}.sha256`, { signal });
67
+ if (!manifest.ok) throw new Error(`RTC helper ${version} is unavailable (${manifest.status}); use --helper with a locally built cohub-rtc`);
68
+ const expectedArchive = (await readText(manifest, 1024)).trim().split(/\s+/)[0];
69
+ if (!expectedArchive || !/^[a-f0-9]{64}$/.test(expectedArchive)) throw new Error("Invalid RTC helper checksum");
70
+ const response = await fetch(url, { signal });
71
+ if (!response.ok || !response.body) throw new Error(`RTC helper download failed (${response.status})`);
72
+ let bytes = 0;
73
+ const bound = () => new Transform({ transform(chunk, _encoding, done) {
74
+ bytes += chunk.length;
75
+ done(bytes > MAX_BINARY_BYTES ? /* @__PURE__ */ new Error("RTC helper exceeds the size limit") : null, chunk);
76
+ } });
77
+ const archive = join(temporary, "archive.gz");
78
+ await pipeline(Readable.fromWeb(response.body), bound(), createWriteStream(archive, { flags: "wx" }), { signal });
79
+ if (await digest(archive) !== expectedArchive) throw new Error("RTC helper checksum mismatch");
80
+ for (const name of ["LICENSE", "NOTICE"]) {
81
+ const response = await fetch(`${base}/${version}/${name}`, { signal });
82
+ if (!response.ok) throw new Error(`RTC helper ${name} is unavailable (${response.status})`);
83
+ const text = await readText(response, 65536);
84
+ await writeFile(join(temporary, name), text, { flag: "wx" });
85
+ await rename(join(temporary, name), join(directory, name));
86
+ }
87
+ const extracted = join(temporary, "cohub-rtc");
88
+ bytes = 0;
89
+ await pipeline(createReadStream(archive), createGunzip(), bound(), createWriteStream(extracted, {
90
+ flags: "wx",
91
+ mode: 448
92
+ }), { signal });
93
+ await chmod(extracted, 448);
94
+ const hash = await digest(extracted);
95
+ await writeFile(join(temporary, "checksum"), hash, { flag: "wx" });
96
+ await rename(extracted, binary);
97
+ await rename(join(temporary, "checksum"), checksum);
98
+ return binary;
99
+ } finally {
100
+ await rm(temporary, {
101
+ recursive: true,
102
+ force: true
103
+ });
104
+ }
105
+ }
106
+ //#endregion
107
+ //#region src/commands/rooms-rtc.ts
108
+ async function runRoomRtc(roomId, options) {
109
+ if (options.delivery !== "reliable" && options.delivery !== "latest") throw new Error("--delivery must be reliable or latest");
110
+ if (options.dataInput && !options.channel) throw new Error("--data-input requires --channel");
111
+ if ([
112
+ options.audio,
113
+ options.video,
114
+ options.dataInput
115
+ ].filter((value) => value === "-").length > 1) throw new Error("Only one input can use stdin");
116
+ const maxBytes = Number(options.maxBytes);
117
+ if (!Number.isSafeInteger(maxBytes) || maxBytes < 0) throw new Error("--max-bytes must be a non-negative safe integer");
118
+ const client = createRealtimeClient();
119
+ const sessions = /* @__PURE__ */ new Set();
120
+ const pending = /* @__PURE__ */ new Set();
121
+ let room;
122
+ let helper;
123
+ let control;
124
+ let exit;
125
+ let killTimer;
126
+ let stopped = false;
127
+ let failure;
128
+ const stop = () => {
129
+ if (stopped) return;
130
+ stopped = true;
131
+ helper?.kill("SIGTERM");
132
+ if (helper) killTimer = setTimeout(() => helper?.kill("SIGKILL"), 5e3);
133
+ };
134
+ const fail = (cause) => {
135
+ failure ??= cause;
136
+ stop();
137
+ };
138
+ const send = (value) => {
139
+ if (!control || control.destroyed || stopped) return;
140
+ const line = `${JSON.stringify(value)}\n`;
141
+ if (Buffer.byteLength(line) > 262144 || control.writableLength > 1048576) throw new Error("RTC control input is too slow or too large");
142
+ control.write(line);
143
+ };
144
+ let previousMembers = "";
145
+ const report = (value) => {
146
+ const output = options.output === "-" ? process.stderr : process.stdout;
147
+ if (output.writableLength > 1048576) throw new Error("RTC output is too slow");
148
+ output.write(`${JSON.stringify(value)}\n`);
149
+ };
150
+ const release = async (sessionId) => {
151
+ if (!sessions.has(sessionId)) return;
152
+ await client.rooms.signalRtc(roomId, {
153
+ method: "DELETE",
154
+ path: `/${sessionId}`
155
+ });
156
+ sessions.delete(sessionId);
157
+ };
158
+ const request = async (message) => {
159
+ try {
160
+ if (![
161
+ "GET",
162
+ "POST",
163
+ "PUT",
164
+ "PATCH",
165
+ "DELETE"
166
+ ].includes(message.method)) throw new Error("Invalid RTC signaling method");
167
+ const opening = message.method === "POST" && message.path === "";
168
+ const body = await client.rooms.signalRtc(roomId, {
169
+ method: message.method,
170
+ path: message.path,
171
+ body: opening ? {
172
+ ticket: "hosted",
173
+ participantId: room?.participantId
174
+ } : message.method === "GET" ? void 0 : message.body
175
+ });
176
+ if (opening && body.sessionId) sessions.add(body.sessionId);
177
+ if (message.method === "GET" && room) {
178
+ const snapshot = await client.rooms.get(roomId);
179
+ send({
180
+ kind: "members",
181
+ body: snapshot.members.map(({ participantId, publications }) => ({
182
+ participantId,
183
+ publications
184
+ }))
185
+ });
186
+ previousMembers = "";
187
+ }
188
+ send({
189
+ kind: "response",
190
+ id: message.id,
191
+ body
192
+ });
193
+ } catch (cause) {
194
+ send({
195
+ kind: "response",
196
+ id: message.id,
197
+ error: cause instanceof Error ? cause.message : String(cause),
198
+ code: cause instanceof HttpError ? cause.code : "RTC_FAILED"
199
+ });
200
+ }
201
+ };
202
+ const track = (task) => {
203
+ pending.add(task);
204
+ task.catch(fail).finally(() => pending.delete(task));
205
+ };
206
+ process.once("SIGINT", stop);
207
+ process.once("SIGTERM", stop);
208
+ process.stdout.on("error", fail);
209
+ process.stderr.on("error", fail);
210
+ try {
211
+ const binary = await ensureRtcBinary(options.helper);
212
+ if (stopped) return;
213
+ room = await client.rooms.connect(roomId);
214
+ if (stopped) return;
215
+ room.onStateChange((state) => {
216
+ try {
217
+ report({
218
+ kind: "room",
219
+ state
220
+ });
221
+ } catch (cause) {
222
+ fail(cause);
223
+ }
224
+ if (state === "closed" || state === "expired") stop();
225
+ });
226
+ helper = spawn(binary, [], { stdio: [
227
+ "inherit",
228
+ "inherit",
229
+ "inherit",
230
+ "pipe",
231
+ "pipe"
232
+ ] });
233
+ control = helper.stdio[3];
234
+ const events = helper.stdio[4];
235
+ control.on("error", fail);
236
+ exit = new Promise((resolve, reject) => {
237
+ helper?.once("error", reject);
238
+ helper?.once("close", (code, signal) => {
239
+ if (killTimer) clearTimeout(killTimer);
240
+ if (code === 0 || stopped && signal === "SIGTERM") resolve();
241
+ else reject(/* @__PURE__ */ new Error(`RTC helper exited with ${signal ?? code}`));
242
+ });
243
+ });
244
+ exit.catch(fail);
245
+ send({
246
+ protocol: 1,
247
+ ...options,
248
+ maxBytes,
249
+ participantId: room.participantId
250
+ });
251
+ const updateMembers = () => {
252
+ const body = room?.members.map(({ participantId, publications }) => ({
253
+ participantId,
254
+ publications
255
+ }));
256
+ const next = JSON.stringify(body);
257
+ if (next === previousMembers) return;
258
+ send({
259
+ kind: "members",
260
+ body
261
+ });
262
+ previousMembers = next;
263
+ };
264
+ room.onMembersChanged(() => {
265
+ try {
266
+ updateMembers();
267
+ } catch (cause) {
268
+ fail(cause);
269
+ }
270
+ });
271
+ updateMembers();
272
+ report({
273
+ kind: "connected",
274
+ roomId,
275
+ participantId: room.participantId
276
+ });
277
+ for await (const line of readRoomLines(events, 262144)) {
278
+ const message = JSON.parse(line);
279
+ if (message.kind === "request") {
280
+ if (pending.size >= 16) throw new Error("Too many pending RTC requests");
281
+ track(request(message));
282
+ } else if (message.kind === "release") await release(message.sessionId);
283
+ else report(message);
284
+ }
285
+ await exit;
286
+ } finally {
287
+ stop();
288
+ await exit?.catch((cause) => {
289
+ failure ??= cause;
290
+ });
291
+ if (killTimer) clearTimeout(killTimer);
292
+ await Promise.allSettled(pending);
293
+ const results = await Promise.allSettled([...sessions].map(release));
294
+ for (const result of results) if (result.status === "rejected") failure ??= result.reason;
295
+ await room?.disconnect().catch((cause) => {
296
+ failure ??= cause;
297
+ });
298
+ await client.disconnect().catch((cause) => {
299
+ failure ??= cause;
300
+ });
301
+ process.removeListener("SIGINT", stop);
302
+ process.removeListener("SIGTERM", stop);
303
+ process.stdout.removeListener("error", fail);
304
+ process.stderr.removeListener("error", fail);
305
+ }
306
+ if (failure) throw failure;
307
+ }
308
+ //#endregion
309
+ export { runRoomRtc };
@@ -0,0 +1,211 @@
1
+ import { C as error, D as json, E as handleHttp, M as truncateText, O as jsonRequested, j as table, k as ok, t as createClient } from "./client.js";
2
+ import { t as getAppByRef } from "./app-ref.js";
3
+ //#region src/commands/rooms.ts
4
+ const DURATION_RE = /^(\d+)(ms|s|m|h|d)?$/i;
5
+ const DURATION_UNITS = {
6
+ ms: 1,
7
+ s: 1e3,
8
+ m: 6e4,
9
+ h: 36e5,
10
+ d: 864e5
11
+ };
12
+ function parseDuration(name, value) {
13
+ const match = DURATION_RE.exec(value.trim());
14
+ if (!match) return error(`Invalid ${name}`, "Use a duration such as 90s, 10m or 2h.");
15
+ return Number(match[1]) * (DURATION_UNITS[(match[2] ?? "s").toLowerCase()] ?? 1e3);
16
+ }
17
+ function seconds(name, value, range) {
18
+ const result = Math.round(parseDuration(name, value) / 1e3);
19
+ if (result < range[0] || result > range[1]) return error(`Invalid ${name}`, `Use a duration from ${formatSeconds(range[0])} to ${formatSeconds(range[1])}.`);
20
+ return result;
21
+ }
22
+ const formatSeconds = (value) => value % 3600 === 0 ? `${value / 3600}h` : value % 60 === 0 ? `${value / 60}m` : `${value}s`;
23
+ const MINUTE = 60;
24
+ const DAY = 1440 * MINUTE;
25
+ function parseJson(name, value) {
26
+ try {
27
+ return JSON.parse(value);
28
+ } catch {
29
+ return error(`Invalid ${name}`, `${name} must be JSON, e.g. '{"text":"hi"}'.`);
30
+ }
31
+ }
32
+ async function readStdin() {
33
+ let input = "";
34
+ for await (const chunk of process.stdin) input += chunk;
35
+ return input;
36
+ }
37
+ function parsePresence(value) {
38
+ const presence = parseJson("presence", value);
39
+ if (presence === null || typeof presence === "object" && !Array.isArray(presence)) return presence;
40
+ return error("Invalid presence", "presence must be a JSON object, or null to clear it.");
41
+ }
42
+ const short = (participantId) => participantId.slice(0, 8);
43
+ function printMembers(view) {
44
+ table(view.members.map((member) => ({
45
+ member: `${short(member.participantId)}${member.participantId === view.participantId ? " (you)" : ""}`,
46
+ kind: member.kind ?? "user",
47
+ model: member.model?.id ?? "",
48
+ presence: member.presence ? truncateText(JSON.stringify(member.presence), 60) : ""
49
+ })), [
50
+ {
51
+ key: "member",
52
+ label: "Member"
53
+ },
54
+ {
55
+ key: "kind",
56
+ label: "Kind"
57
+ },
58
+ {
59
+ key: "model",
60
+ label: "Model"
61
+ },
62
+ {
63
+ key: "presence",
64
+ label: "Presence"
65
+ }
66
+ ]);
67
+ }
68
+ function printView(view) {
69
+ console.log(`Room ${view.room.code} · ${view.room.id}`);
70
+ console.log(`You are ${view.participantId} · sequence ${view.sequence} · expires ${view.room.expiresAt}\n`);
71
+ printMembers(view);
72
+ }
73
+ const formatEvent = (event) => `#${event.sequence} ${event.type} from ${event.self ? "you" : short(event.sender.participantId)} ${JSON.stringify(event.data)}`;
74
+ function printEvents(roomId, page, options) {
75
+ if (page.truncated) console.log("Some earlier events are no longer in the room history.");
76
+ if (page.events.length === 0) console.log("No new events.");
77
+ for (const event of page.events) console.log(formatEvent(event));
78
+ const filter = options.types.map((type) => ` --type '${type}'`).join("");
79
+ const wait = options.wait ? ` --wait ${options.wait}` : "";
80
+ console.log(`\nNext: cohub rooms events ${roomId} --after ${page.cursor}${filter}${wait}`);
81
+ }
82
+ const collect = (value, previous = []) => [...previous, value];
83
+ async function withClient(run) {
84
+ try {
85
+ return await run(createClient());
86
+ } catch (e) {
87
+ return handleHttp(e);
88
+ }
89
+ }
90
+ function registerRooms(program) {
91
+ const rooms = program.command("rooms").description("Take part in App rooms: join, read and publish events, set presence").addHelpText("after", `
92
+ A room belongs to a published App. Join one with an invite from the App
93
+ (room.invite()), or create one for an App you manage. Your seat stays while
94
+ you use it and lapses after --idle without a call.
95
+
96
+ An Agent waits for the room in a background command and wakes when it returns:
97
+ cohub rooms join <invite> --presence '{"name":"Guide"}'
98
+ cohub rooms events <room> --type 'chat.*' --wait 10m
99
+ cohub rooms publish <room> chat.message '{"text":"Hello"}'
100
+ `);
101
+ rooms.command("create").description("Create a room for an App you manage, with an invite and a link to it").requiredOption("--app <app>", "App: ID, URL, or username/space/app").option("--code <code>", "Room code people type or open with ?room=").option("--ttl <duration>", "Room lifetime, 1m to 24h (default 2h)").option("--max <count>", "Most members at once, 2 to 128 (default 16)").option("--seat-per-user", "Give each person one App seat across tabs").option("--json", "Output as JSON").action((opts) => withClient(async (client) => {
102
+ const app = await getAppByRef(client, opts.app);
103
+ const created = await client.rooms.create({
104
+ appId: app.app.id,
105
+ ...opts.code ? { code: opts.code } : {},
106
+ ...opts.ttl ? { expiresInSeconds: seconds("ttl", opts.ttl, [MINUTE, DAY]) } : {},
107
+ ...opts.max ? { maxParticipants: Number(opts.max) } : {},
108
+ ...opts.seatPerUser ? { seatPerUser: true } : {}
109
+ });
110
+ if (jsonRequested(opts)) return json(created);
111
+ console.log(`Room ${created.room.code} · ${created.room.id}`);
112
+ if (created.url) console.log(`Open: ${created.url}`);
113
+ console.log(`Invite (until ${created.expiresAt}):\n${created.invite}\n`);
114
+ console.log(`Join: cohub rooms join <invite>`);
115
+ }));
116
+ rooms.command("join <invite>").description("Take a seat in a room with an invite").option("--presence <json>", "What others see about you, e.g. '{\"name\":\"Guide\"}'").option("--idle <duration>", "Leave after this long without a call, 1m to 24h (default 30m)").option("--json", "Output as JSON").action((invite, opts) => withClient(async (client) => {
117
+ const view = await client.rooms.join({
118
+ invite,
119
+ ...opts.presence !== void 0 ? { presence: parsePresence(opts.presence) } : {},
120
+ ...opts.idle ? { idleSeconds: seconds("idle", opts.idle, [MINUTE, DAY]) } : {}
121
+ });
122
+ if (jsonRequested(opts)) return json(view);
123
+ printView(view);
124
+ console.log(`\nWait for events: cohub rooms events ${view.room.id} --after ${view.sequence} --wait 10m`);
125
+ }));
126
+ rooms.command("connect <room>").description("Stream room events and members over realtime; disconnecting keeps your seat").option("--after <sequence>", "Replay retained events after this sequence").option("--input", "Accept NDJSON publish/send/presence commands on stdin").option("--json", "Output newline-delimited JSON").action(async (roomId, opts) => {
127
+ try {
128
+ const { connectToRoom } = await import("./rooms-connect.js");
129
+ await connectToRoom(roomId, {
130
+ ...opts,
131
+ json: jsonRequested(opts)
132
+ });
133
+ } catch (cause) {
134
+ handleHttp(cause);
135
+ }
136
+ });
137
+ rooms.command("rtc <room>").description("Stream RTC media and data through the Go/Pion helper").option("--helper <path>", "Use a local cohub-rtc binary").option("--channel <name>", "Open a JSON/binary RTC data channel").option("--delivery <policy>", "Data channel delivery: reliable or latest", "reliable").option("--data-input <path>", "NDJSON channel input file or - for stdin").option("--audio <path>", "Audio input file or - for stdin").option("--audio-format <format>", "Audio input: pcm or opus (Ogg)", "pcm").option("--rate <hz>", "Audio sample rate", "48000").option("--channels <count>", "Audio channels", "1").option("--video <path>", "Video input file or - for stdin").option("--video-format <format>", "Video input: i420 or vp8 (IVF)", "i420").option("--size <widthxheight>", "Video frame dimensions").option("--fps <rate>", "Video frame rate", "30").option("--output <directory|->", "Receive framed media into unique .rtc files or binary stdout").option("--receive-format <format>", "Receive rtp packets or raw decoded frames", "rtp").option("--receive-size <widthxheight>", "Decoded I420 output dimensions", "640x360").option("--max-bytes <bytes>", "Stop after this many received bytes; 0 is unlimited", "1073741824").option("--participant <id>", "Only receive this participant's tracks").option("--json", "Output newline-delimited JSON").action(async (roomId, opts) => {
138
+ try {
139
+ const { runRoomRtc } = await import("./rooms-rtc.js");
140
+ await runRoomRtc(roomId, opts);
141
+ } catch (cause) {
142
+ handleHttp(cause);
143
+ }
144
+ });
145
+ rooms.command("get <room>").description("Show the room, its members and your seat").option("--json", "Output as JSON").action((roomId, opts) => withClient(async (client) => {
146
+ const view = await client.rooms.get(roomId);
147
+ if (jsonRequested(opts)) return json(view);
148
+ printView(view);
149
+ }));
150
+ rooms.command("events <room>").description("Read published events, oldest first; --wait holds until someone else publishes").option("--after <sequence>", "Only events after this sequence").option("--type <pattern>", "Event type to include, * matches any text; repeatable", collect).option("--wait <duration>", "Wait up to this long for a new event from someone else").option("--follow", "Keep printing events as they arrive").option("--limit <count>", "Most events to return").option("--json", "Output as JSON").action((roomId, opts) => withClient(async (client) => {
151
+ const types = opts.type ?? [];
152
+ const after = opts.after === void 0 ? void 0 : Number(opts.after);
153
+ if (after !== void 0 && (!Number.isInteger(after) || after < 0)) return error("Invalid --after", "Use a sequence number.");
154
+ const limit = opts.limit === void 0 ? void 0 : Number(opts.limit);
155
+ if (opts.follow) return follow(client, roomId, {
156
+ after,
157
+ types,
158
+ json: jsonRequested(opts)
159
+ });
160
+ const page = await client.rooms.events(roomId, {
161
+ after,
162
+ types,
163
+ ...limit ? { limit } : {},
164
+ ...opts.wait ? { waitMs: parseDuration("wait", opts.wait) } : {}
165
+ });
166
+ if (jsonRequested(opts)) return json(page);
167
+ printEvents(roomId, page, {
168
+ types,
169
+ wait: opts.wait
170
+ });
171
+ }));
172
+ rooms.command("publish <room> <type> [data]").description("Publish an event to everyone in the room; data is JSON, or - for stdin").option("--json", "Output as JSON").action((roomId, type, data, opts) => withClient(async (client) => {
173
+ const payload = data === void 0 ? null : parseJson("data", data === "-" ? await readStdin() : data);
174
+ const result = await client.rooms.publish(roomId, type, payload);
175
+ if (jsonRequested(opts)) return json(result);
176
+ ok(`Published #${result.sequence} ${type}`);
177
+ }));
178
+ rooms.command("presence <room> <json>").description("Set what others see about you; null clears it").option("--json", "Output as JSON").action((roomId, value, opts) => withClient(async (client) => {
179
+ const result = await client.rooms.setPresence(roomId, parsePresence(value));
180
+ if (jsonRequested(opts)) return json(result);
181
+ ok("Presence updated");
182
+ }));
183
+ rooms.command("invite <room>").description("Create an invite to a room you are in").option("--ttl <duration>", "How long the invite admits people (default 10m)").option("--json", "Output as JSON").action((roomId, opts) => withClient(async (client) => {
184
+ const invite = await client.rooms.invite(roomId, opts.ttl ? { expiresInSeconds: seconds("ttl", opts.ttl, [MINUTE, DAY]) } : {});
185
+ if (jsonRequested(opts)) return json(invite);
186
+ console.log(`Invite (until ${invite.expiresAt}):\n${invite.invite}`);
187
+ }));
188
+ rooms.command("leave <room>").description("Give up your seat").option("--json", "Output as JSON").action((roomId, opts) => withClient(async (client) => {
189
+ const result = await client.rooms.leave(roomId);
190
+ if (jsonRequested(opts)) return json(result);
191
+ ok(result.left ? "Left the room" : "You were not in this room");
192
+ }));
193
+ }
194
+ async function follow(client, roomId, input) {
195
+ const controller = new AbortController();
196
+ process.once("SIGINT", () => controller.abort());
197
+ let after = input.after ?? (await client.rooms.get(roomId)).sequence;
198
+ while (!controller.signal.aborted) {
199
+ const page = await client.rooms.events(roomId, {
200
+ after,
201
+ types: input.types,
202
+ waitMs: 25e3,
203
+ signal: controller.signal
204
+ }).catch((e) => controller.signal.aborted ? null : Promise.reject(e));
205
+ if (!page) break;
206
+ for (const event of page.events) console.log(input.json ? JSON.stringify(event) : formatEvent(event));
207
+ after = page.cursor;
208
+ }
209
+ }
210
+ //#endregion
211
+ export { registerRooms };