@neta-art/cohub-cli 10.23.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 (369) hide show
  1. package/README.md +18 -5
  2. package/bin/cohub.js +4 -1
  3. package/dist/board-gpu/page.js +1566 -71230
  4. package/dist/bootstrap.js +67 -27
  5. package/dist/build.json +1 -1
  6. package/dist/{board-kernel/FilterPipe.js → chunks/Geometry.js} +10447 -10469
  7. package/dist/chunks/about.js +102 -0
  8. package/dist/chunks/app-realtime.js +2216 -0
  9. package/dist/chunks/app-realtime2.js +2 -0
  10. package/dist/chunks/app-ref.js +88 -0
  11. package/dist/chunks/apps.js +1423 -0
  12. package/dist/chunks/auth.js +175 -0
  13. package/dist/chunks/avatar.js +146 -0
  14. package/dist/chunks/board-export-resources.js +232 -0
  15. package/dist/chunks/board-export.js +874 -0
  16. package/dist/chunks/board-export2.js +2 -0
  17. package/dist/{board-kernel.js → chunks/board-kernel.js} +18032 -28512
  18. package/dist/chunks/board-kernel2.js +4 -0
  19. package/dist/chunks/board-profile.js +69 -0
  20. package/dist/chunks/board-simulate.js +315 -0
  21. package/dist/chunks/board-time.js +34 -0
  22. package/dist/chunks/boards.js +1943 -0
  23. package/dist/{board-kernel → chunks}/browserAll.js +9 -8
  24. package/dist/chunks/channels.js +64 -0
  25. package/dist/chunks/client.js +12606 -0
  26. package/dist/chunks/command-input.js +17 -0
  27. package/dist/chunks/commander.js +2962 -0
  28. package/dist/chunks/cron-jobs.js +163 -0
  29. package/dist/chunks/daemon.js +545 -0
  30. package/dist/chunks/daemon2.js +2 -0
  31. package/dist/chunks/desktop.js +172 -0
  32. package/dist/chunks/endpoint-options.js +26 -0
  33. package/dist/chunks/env-proxy.js +35 -0
  34. package/dist/chunks/environment.js +154 -0
  35. package/dist/chunks/feedback.js +120 -0
  36. package/dist/chunks/generations.js +379 -0
  37. package/dist/chunks/host.js +9 -0
  38. package/dist/chunks/http-put.js +131 -0
  39. package/dist/chunks/id.js +2416 -0
  40. package/dist/{board-kernel → chunks}/init.js +1 -1
  41. package/dist/chunks/install.js +11959 -0
  42. package/dist/chunks/launch.js +374 -0
  43. package/dist/chunks/local-media.js +47 -0
  44. package/dist/chunks/me.js +134 -0
  45. package/dist/chunks/media.js +315 -0
  46. package/dist/chunks/models.js +242 -0
  47. package/dist/chunks/operands.js +46 -0
  48. package/dist/chunks/package-paths.js +13 -0
  49. package/dist/chunks/policy.js +221 -0
  50. package/dist/chunks/preferences.js +29 -0
  51. package/dist/chunks/profile.js +64 -0
  52. package/dist/chunks/prompts.js +41 -0
  53. package/dist/chunks/public.js +2 -0
  54. package/dist/chunks/public2.js +244 -0
  55. package/dist/chunks/references.js +197 -0
  56. package/dist/chunks/referrals.js +90 -0
  57. package/dist/chunks/rolldown-runtime.js +26 -0
  58. package/dist/chunks/rooms-connect.js +2 -0
  59. package/dist/chunks/rooms-connect2.js +151 -0
  60. package/dist/chunks/rooms-rtc.js +309 -0
  61. package/dist/chunks/rooms.js +211 -0
  62. package/dist/chunks/run.js +220 -0
  63. package/dist/chunks/runtime.js +638 -0
  64. package/dist/chunks/runtime2.js +286 -0
  65. package/dist/chunks/runtimes.js +48 -0
  66. package/dist/chunks/safe-remote-image.js +198 -0
  67. package/dist/chunks/schemas.js +6017 -0
  68. package/dist/chunks/search.js +113 -0
  69. package/dist/chunks/self-update.js +238 -0
  70. package/dist/chunks/serve.js +1246 -0
  71. package/dist/chunks/session-status.js +24 -0
  72. package/dist/chunks/skills.js +35 -0
  73. package/dist/chunks/spaces.js +5080 -0
  74. package/dist/chunks/src.js +405 -0
  75. package/dist/chunks/supervisor.js +2511 -0
  76. package/dist/chunks/supervisor2.js +2 -0
  77. package/dist/chunks/tasks.js +82 -0
  78. package/dist/chunks/themes.js +2898 -0
  79. package/dist/chunks/version.js +2 -0
  80. package/dist/chunks/version2.js +22 -0
  81. package/dist/chunks/version3.js +18 -0
  82. package/dist/chunks/web.js +7 -0
  83. package/dist/{board-kernel → chunks}/webworkerAll.js +1 -1
  84. package/dist/runtime/native/pi-extension.js +174 -166
  85. package/dist/runtime/worker.js +27 -16
  86. package/package.json +8 -9
  87. package/dist/about.d.ts +0 -2
  88. package/dist/about.js +0 -71
  89. package/dist/app-download.d.ts +0 -11
  90. package/dist/app-download.js +0 -252
  91. package/dist/app-ref.d.ts +0 -5
  92. package/dist/app-ref.js +0 -8
  93. package/dist/app-target.d.ts +0 -26
  94. package/dist/app-target.js +0 -55
  95. package/dist/auth.d.ts +0 -45
  96. package/dist/auth.js +0 -307
  97. package/dist/avatar.d.ts +0 -55
  98. package/dist/avatar.js +0 -104
  99. package/dist/board-command-support.d.ts +0 -6
  100. package/dist/board-command-support.js +0 -88
  101. package/dist/board-export-resources.d.ts +0 -12
  102. package/dist/board-export-resources.js +0 -51
  103. package/dist/board-export.d.ts +0 -110
  104. package/dist/board-export.js +0 -592
  105. package/dist/board-fonts.d.ts +0 -11
  106. package/dist/board-fonts.js +0 -10
  107. package/dist/board-gpu/daemon.d.ts +0 -11
  108. package/dist/board-gpu/daemon.js +0 -295
  109. package/dist/board-gpu/index.d.ts +0 -33
  110. package/dist/board-gpu/index.js +0 -189
  111. package/dist/board-gpu/protocol.d.ts +0 -77
  112. package/dist/board-gpu/protocol.js +0 -1
  113. package/dist/board-kernel.d.ts +0 -5
  114. package/dist/board-media-export.d.ts +0 -17
  115. package/dist/board-media-export.js +0 -164
  116. package/dist/board-media.d.ts +0 -5
  117. package/dist/board-media.js +0 -66
  118. package/dist/board-profile.d.ts +0 -21
  119. package/dist/board-profile.js +0 -67
  120. package/dist/board-simulate.d.ts +0 -67
  121. package/dist/board-simulate.js +0 -259
  122. package/dist/board-time.d.ts +0 -3
  123. package/dist/board-time.js +0 -34
  124. package/dist/bootstrap.d.ts +0 -2
  125. package/dist/client.d.ts +0 -5
  126. package/dist/client.js +0 -24
  127. package/dist/command-input.d.ts +0 -4
  128. package/dist/command-input.js +0 -16
  129. package/dist/commands/app-commerce.d.ts +0 -2
  130. package/dist/commands/app-commerce.js +0 -228
  131. package/dist/commands/app-domains.d.ts +0 -2
  132. package/dist/commands/app-domains.js +0 -133
  133. package/dist/commands/apps.d.ts +0 -4
  134. package/dist/commands/apps.js +0 -827
  135. package/dist/commands/auth.d.ts +0 -2
  136. package/dist/commands/auth.js +0 -186
  137. package/dist/commands/boards/authoring.d.ts +0 -2
  138. package/dist/commands/boards/authoring.js +0 -166
  139. package/dist/commands/boards/examples.d.ts +0 -10
  140. package/dist/commands/boards/examples.js +0 -118
  141. package/dist/commands/boards.d.ts +0 -13
  142. package/dist/commands/boards.js +0 -836
  143. package/dist/commands/channels.d.ts +0 -2
  144. package/dist/commands/channels.js +0 -74
  145. package/dist/commands/cron-jobs.d.ts +0 -2
  146. package/dist/commands/cron-jobs.js +0 -155
  147. package/dist/commands/decision.d.ts +0 -4
  148. package/dist/commands/decision.js +0 -113
  149. package/dist/commands/desktop.d.ts +0 -10
  150. package/dist/commands/desktop.js +0 -233
  151. package/dist/commands/feedback.d.ts +0 -2
  152. package/dist/commands/feedback.js +0 -131
  153. package/dist/commands/generations.d.ts +0 -2
  154. package/dist/commands/generations.js +0 -427
  155. package/dist/commands/host.d.ts +0 -2
  156. package/dist/commands/host.js +0 -11
  157. package/dist/commands/me.d.ts +0 -2
  158. package/dist/commands/me.js +0 -118
  159. package/dist/commands/models.d.ts +0 -28
  160. package/dist/commands/models.js +0 -271
  161. package/dist/commands/profile.d.ts +0 -2
  162. package/dist/commands/profile.js +0 -81
  163. package/dist/commands/prompts.d.ts +0 -2
  164. package/dist/commands/prompts.js +0 -37
  165. package/dist/commands/public.d.ts +0 -20
  166. package/dist/commands/public.js +0 -291
  167. package/dist/commands/references.d.ts +0 -2
  168. package/dist/commands/references.js +0 -193
  169. package/dist/commands/referrals.d.ts +0 -2
  170. package/dist/commands/referrals.js +0 -88
  171. package/dist/commands/rooms-connect.d.ts +0 -17
  172. package/dist/commands/rooms-connect.js +0 -140
  173. package/dist/commands/rooms-rtc-binary.d.ts +0 -2
  174. package/dist/commands/rooms-rtc-binary.js +0 -107
  175. package/dist/commands/rooms-rtc.d.ts +0 -21
  176. package/dist/commands/rooms-rtc.js +0 -171
  177. package/dist/commands/rooms.d.ts +0 -3
  178. package/dist/commands/rooms.js +0 -277
  179. package/dist/commands/run.d.ts +0 -13
  180. package/dist/commands/run.js +0 -246
  181. package/dist/commands/runtime.d.ts +0 -3
  182. package/dist/commands/runtime.js +0 -320
  183. package/dist/commands/sandboxd-binary.d.ts +0 -11
  184. package/dist/commands/sandboxd-binary.js +0 -238
  185. package/dist/commands/search.d.ts +0 -2
  186. package/dist/commands/search.js +0 -114
  187. package/dist/commands/session-access.d.ts +0 -2
  188. package/dist/commands/session-access.js +0 -70
  189. package/dist/commands/skills.d.ts +0 -2
  190. package/dist/commands/skills.js +0 -34
  191. package/dist/commands/space-activity.d.ts +0 -26
  192. package/dist/commands/space-activity.js +0 -147
  193. package/dist/commands/space-commerce.d.ts +0 -2
  194. package/dist/commands/space-commerce.js +0 -514
  195. package/dist/commands/space-displays.d.ts +0 -2
  196. package/dist/commands/space-displays.js +0 -620
  197. package/dist/commands/space-files.d.ts +0 -5
  198. package/dist/commands/space-files.js +0 -215
  199. package/dist/commands/space-invitations.d.ts +0 -29
  200. package/dist/commands/space-invitations.js +0 -189
  201. package/dist/commands/space-turns.d.ts +0 -49
  202. package/dist/commands/space-turns.js +0 -205
  203. package/dist/commands/space-wallet.d.ts +0 -2
  204. package/dist/commands/space-wallet.js +0 -64
  205. package/dist/commands/space-webhooks.d.ts +0 -7
  206. package/dist/commands/space-webhooks.js +0 -73
  207. package/dist/commands/spaces.d.ts +0 -25
  208. package/dist/commands/spaces.js +0 -2139
  209. package/dist/commands/tasks.d.ts +0 -8
  210. package/dist/commands/tasks.js +0 -80
  211. package/dist/commands/version.d.ts +0 -2
  212. package/dist/commands/version.js +0 -21
  213. package/dist/endpoint-options.d.ts +0 -4
  214. package/dist/endpoint-options.js +0 -26
  215. package/dist/env-proxy.d.ts +0 -5
  216. package/dist/env-proxy.js +0 -20
  217. package/dist/help-path.d.ts +0 -18
  218. package/dist/help-path.js +0 -223
  219. package/dist/host/auth.d.ts +0 -20
  220. package/dist/host/auth.js +0 -119
  221. package/dist/host/login-env.d.ts +0 -1
  222. package/dist/host/login-env.js +0 -31
  223. package/dist/host/runtime.d.ts +0 -35
  224. package/dist/host/runtime.js +0 -395
  225. package/dist/host/runtimes.d.ts +0 -9
  226. package/dist/host/runtimes.js +0 -42
  227. package/dist/host/serve.d.ts +0 -2
  228. package/dist/host/serve.js +0 -117
  229. package/dist/host/workspaces.d.ts +0 -2
  230. package/dist/host/workspaces.js +0 -18
  231. package/dist/http-put.d.ts +0 -25
  232. package/dist/http-put.js +0 -132
  233. package/dist/index.d.ts +0 -2
  234. package/dist/index.js +0 -129
  235. package/dist/launcher.d.ts +0 -4
  236. package/dist/launcher.js +0 -38
  237. package/dist/local-media.d.ts +0 -2
  238. package/dist/local-media.js +0 -30
  239. package/dist/network-error.d.ts +0 -3
  240. package/dist/network-error.js +0 -22
  241. package/dist/output.d.ts +0 -46
  242. package/dist/output.js +0 -244
  243. package/dist/runtime/archive-store.d.ts +0 -54
  244. package/dist/runtime/archive-store.js +0 -379
  245. package/dist/runtime/cli-path.d.ts +0 -5
  246. package/dist/runtime/cli-path.js +0 -27
  247. package/dist/runtime/codex-usage.d.ts +0 -7
  248. package/dist/runtime/codex-usage.js +0 -11
  249. package/dist/runtime/connection.d.ts +0 -42
  250. package/dist/runtime/connection.js +0 -789
  251. package/dist/runtime/diagnostics.d.ts +0 -107
  252. package/dist/runtime/diagnostics.js +0 -392
  253. package/dist/runtime/harnesses/chained-projection.d.ts +0 -40
  254. package/dist/runtime/harnesses/chained-projection.js +0 -95
  255. package/dist/runtime/harnesses/chained-transcript.d.ts +0 -24
  256. package/dist/runtime/harnesses/chained-transcript.js +0 -62
  257. package/dist/runtime/harnesses/claude-approval.d.ts +0 -34
  258. package/dist/runtime/harnesses/claude-approval.js +0 -124
  259. package/dist/runtime/harnesses/claude-transcript.d.ts +0 -8
  260. package/dist/runtime/harnesses/claude-transcript.js +0 -138
  261. package/dist/runtime/harnesses/claude.d.ts +0 -8
  262. package/dist/runtime/harnesses/claude.js +0 -225
  263. package/dist/runtime/harnesses/codex-approval.d.ts +0 -25
  264. package/dist/runtime/harnesses/codex-approval.js +0 -69
  265. package/dist/runtime/harnesses/codex.d.ts +0 -4
  266. package/dist/runtime/harnesses/codex.js +0 -269
  267. package/dist/runtime/harnesses/cursor-transcript.d.ts +0 -37
  268. package/dist/runtime/harnesses/cursor-transcript.js +0 -183
  269. package/dist/runtime/harnesses/cursor.d.ts +0 -24
  270. package/dist/runtime/harnesses/cursor.js +0 -620
  271. package/dist/runtime/harnesses/index.d.ts +0 -16
  272. package/dist/runtime/harnesses/index.js +0 -73
  273. package/dist/runtime/harnesses/pi.d.ts +0 -4
  274. package/dist/runtime/harnesses/pi.js +0 -247
  275. package/dist/runtime/harnesses/process.d.ts +0 -31
  276. package/dist/runtime/harnesses/process.js +0 -75
  277. package/dist/runtime/harnesses/stream-json.d.ts +0 -48
  278. package/dist/runtime/harnesses/stream-json.js +0 -336
  279. package/dist/runtime/harnesses/types.d.ts +0 -117
  280. package/dist/runtime/harnesses/types.js +0 -1
  281. package/dist/runtime/harnesses/workbuddy-transcript.d.ts +0 -8
  282. package/dist/runtime/harnesses/workbuddy-transcript.js +0 -127
  283. package/dist/runtime/harnesses/workbuddy.d.ts +0 -21
  284. package/dist/runtime/harnesses/workbuddy.js +0 -123
  285. package/dist/runtime/instance.d.ts +0 -20
  286. package/dist/runtime/instance.js +0 -247
  287. package/dist/runtime/json-rpc.d.ts +0 -53
  288. package/dist/runtime/json-rpc.js +0 -212
  289. package/dist/runtime/launch.d.ts +0 -25
  290. package/dist/runtime/launch.js +0 -247
  291. package/dist/runtime/local-workspace.d.ts +0 -15
  292. package/dist/runtime/local-workspace.js +0 -52
  293. package/dist/runtime/model-catalog.d.ts +0 -12
  294. package/dist/runtime/model-catalog.js +0 -84
  295. package/dist/runtime/native/adapters.d.ts +0 -15
  296. package/dist/runtime/native/adapters.js +0 -11
  297. package/dist/runtime/native/approvals.d.ts +0 -18
  298. package/dist/runtime/native/approvals.js +0 -54
  299. package/dist/runtime/native/archive.d.ts +0 -19
  300. package/dist/runtime/native/archive.js +0 -142
  301. package/dist/runtime/native/attach.d.ts +0 -36
  302. package/dist/runtime/native/attach.js +0 -128
  303. package/dist/runtime/native/codex-link.d.ts +0 -60
  304. package/dist/runtime/native/codex-link.js +0 -322
  305. package/dist/runtime/native/config.d.ts +0 -16
  306. package/dist/runtime/native/config.js +0 -24
  307. package/dist/runtime/native/daemon.d.ts +0 -92
  308. package/dist/runtime/native/daemon.js +0 -380
  309. package/dist/runtime/native/execution.d.ts +0 -26
  310. package/dist/runtime/native/execution.js +0 -34
  311. package/dist/runtime/native/identity.d.ts +0 -9
  312. package/dist/runtime/native/identity.js +0 -15
  313. package/dist/runtime/native/ingest.d.ts +0 -263
  314. package/dist/runtime/native/ingest.js +0 -884
  315. package/dist/runtime/native/install.d.ts +0 -9
  316. package/dist/runtime/native/install.js +0 -113
  317. package/dist/runtime/native/paths.d.ts +0 -2
  318. package/dist/runtime/native/paths.js +0 -7
  319. package/dist/runtime/native/pi-extension.d.ts +0 -36
  320. package/dist/runtime/native/pi-link.d.ts +0 -69
  321. package/dist/runtime/native/pi-link.js +0 -269
  322. package/dist/runtime/native/results.d.ts +0 -41
  323. package/dist/runtime/native/results.js +0 -128
  324. package/dist/runtime/native/sessions.d.ts +0 -45
  325. package/dist/runtime/native/sessions.js +0 -87
  326. package/dist/runtime/native/transcript.d.ts +0 -89
  327. package/dist/runtime/native/transcript.js +0 -656
  328. package/dist/runtime/native/translate.d.ts +0 -46
  329. package/dist/runtime/native/translate.js +0 -299
  330. package/dist/runtime/native/transport.d.ts +0 -7
  331. package/dist/runtime/native/transport.js +0 -16
  332. package/dist/runtime/native/version.d.ts +0 -5
  333. package/dist/runtime/native/version.js +0 -21
  334. package/dist/runtime/preferences.d.ts +0 -7
  335. package/dist/runtime/preferences.js +0 -22
  336. package/dist/runtime/presentation.d.ts +0 -32
  337. package/dist/runtime/presentation.js +0 -124
  338. package/dist/runtime/process-group.d.ts +0 -5
  339. package/dist/runtime/process-group.js +0 -161
  340. package/dist/runtime/projection-store.d.ts +0 -27
  341. package/dist/runtime/projection-store.js +0 -30
  342. package/dist/runtime/space-binding.d.ts +0 -48
  343. package/dist/runtime/space-binding.js +0 -342
  344. package/dist/runtime/supervisor.d.ts +0 -19
  345. package/dist/runtime/supervisor.js +0 -441
  346. package/dist/runtime/turn-projection.d.ts +0 -41
  347. package/dist/runtime/turn-projection.js +0 -120
  348. package/dist/runtime/worker.d.ts +0 -1
  349. package/dist/safe-remote-image.d.ts +0 -36
  350. package/dist/safe-remote-image.js +0 -191
  351. package/dist/self-update.d.ts +0 -7
  352. package/dist/self-update.js +0 -202
  353. package/dist/session-status.d.ts +0 -6
  354. package/dist/session-status.js +0 -16
  355. package/dist/space-files/limit.d.ts +0 -2
  356. package/dist/space-files/limit.js +0 -16
  357. package/dist/space-files/operands.d.ts +0 -17
  358. package/dist/space-files/operands.js +0 -33
  359. package/dist/space-files/transfer.d.ts +0 -53
  360. package/dist/space-files/transfer.js +0 -297
  361. package/dist/space-files/upload.d.ts +0 -17
  362. package/dist/space-files/upload.js +0 -76
  363. package/dist/space.d.ts +0 -44
  364. package/dist/space.js +0 -192
  365. package/dist/version.d.ts +0 -2
  366. package/dist/version.js +0 -17
  367. package/dist/web.d.ts +0 -1
  368. package/dist/web.js +0 -4
  369. /package/dist/{board-kernel → chunks}/lexer.js +0 -0
@@ -0,0 +1,286 @@
1
+ import { v as LOCAL_HARNESSES, y as LOCAL_HARNESS_SPECS } from "./runtime.js";
2
+ import { D as json, J as getRuntimeSpaceBinding, O as jsonRequested, f as stopRuntimeInstance, h as currentIdentityKey, l as requestRuntimeInstance, q as canonicalRuntimeRoot, s as controlRuntimeInstance, t as createClient, u as runtimeInstanceDirectory } from "./client.js";
3
+ import { J as serializeDiagnosticError, K as readRuntimeDiagnosticEvents, W as RuntimeDiagnosticReader, c as runtimeStateRoot, f as diagnosticLevels, g as printRuntimeSummary, h as formatNativeSync, l as writeNativeConfig, m as formatImportProgress, p as formatDiagnostic, q as runtimeDiagnosticsDirectory, r as piExtensionState, s as readNativeConfig, t as installPiExtension, u as atLeastLevel, y as RuntimeArchiveStore } from "./install.js";
4
+ import { a as resolveRuntimeTarget, o as runtimeUp, r as parseRuntimeHarnesses } from "./launch.js";
5
+ import { t as forgetHostRuntime } from "./runtimes.js";
6
+ import { join } from "node:path";
7
+ import { setTimeout } from "node:timers/promises";
8
+ //#region src/commands/runtime.ts
9
+ const reportFailure = (cause) => {
10
+ process.stderr.write(`Runtime failed: ${serializeDiagnosticError(cause).message}\n`);
11
+ process.exitCode = 1;
12
+ };
13
+ const megabytes = (bytes) => `${(bytes / 1024 / 1024).toFixed(1)} MB`;
14
+ /** The bound Space of a directory, with its running Runtime; import and attach act through it. */
15
+ async function boundRuntime(program, dir, space) {
16
+ const identity = currentIdentityKey();
17
+ if (!identity) throw new Error("Sign in first");
18
+ const root = await canonicalRuntimeRoot(dir ?? process.cwd());
19
+ const spaceId = await resolveRuntimeTarget(program, space);
20
+ const binding = await getRuntimeSpaceBinding(root, identity);
21
+ if (!binding || binding.spaceId !== spaceId) throw new Error("Bind this directory with runtime up first");
22
+ return {
23
+ identity,
24
+ root,
25
+ spaceId,
26
+ directory: runtimeInstanceDirectory(identity, spaceId)
27
+ };
28
+ }
29
+ function registerRuntime(program) {
30
+ const runtime = program.command("runtime").description("Connect a local workspace");
31
+ const up = runtime.command("up [dir]").description("Connect local Harnesses and files").option("-s, --space <space>", "Target Space: ID, slug, or username/slug").option("-n, --new", "Create a new Space").option("--name <name>", "New Space name").option("-d, --detach", "Run in the background").option("--harness <name>", `${LOCAL_HARNESSES.join(", ")}; repeatable`, (value, previous) => [...previous, value], []);
32
+ for (const harness of LOCAL_HARNESSES) up.option(`--${harness} <path>`, `${LOCAL_HARNESS_SPECS[harness].label} executable`);
33
+ up.option("--display [screen]", "Share a screen (default: auto when available), or xvfb[:WIDTHxHEIGHT] for a virtual one").option("--no-display", "Disable screen sharing and skip its confirmation").option("-y, --yes", "Accept defaults and authorize local execution, native sync, and screen sharing").option("--verbose", "Show diagnostic details").option("--json", "JSON output").action(async (dir, options) => {
34
+ try {
35
+ await runtimeUp(program, dir, {
36
+ ...options,
37
+ json: jsonRequested(options)
38
+ });
39
+ } catch (cause) {
40
+ reportFailure(cause);
41
+ }
42
+ });
43
+ runtime.command("attach").description("Connect native harnesses to Cohub: install the Pi extension").option("-s, --space <space>", "Target Space: ID, slug, or username/slug").option("--harness <name>", "Pi; repeatable", (value, previous) => [...previous, value], []).option("--json", "JSON output").action(async (options) => {
44
+ try {
45
+ if (!parseRuntimeHarnesses(options.harness.length ? options.harness : ["pi"]).includes("pi")) throw new Error("Only Pi uses an extension; Codex syncs through runtime up's shared app-server");
46
+ const before = await piExtensionState();
47
+ if (before === "foreign") throw new Error("A Pi extension named cohub exists and is not managed by Cohub; move it aside, then retry");
48
+ await installPiExtension();
49
+ const spaceId = await resolveRuntimeTarget(program, options.space).catch(() => null);
50
+ const identity = currentIdentityKey();
51
+ if (spaceId && identity) await controlRuntimeInstance(runtimeInstanceDirectory(identity, spaceId), "reload").catch(() => void 0);
52
+ if (jsonRequested(options)) json({
53
+ harness: "pi",
54
+ extension: "installed",
55
+ updated: before !== "installed"
56
+ });
57
+ else process.stdout.write(before === "installed" ? "Pi extension is up to date\n" : "Pi extension installed. Run /reload in open Pi sessions to connect them\n");
58
+ } catch (cause) {
59
+ reportFailure(cause);
60
+ }
61
+ });
62
+ runtime.command("detach").description("Pause native sync; keep all data").option("-s, --space <space>", "Target Space: ID, slug, or username/slug").option("--harness <name>", `${LOCAL_HARNESSES.join(", ")}; repeatable`, (value, previous) => [...previous, value], []).option("--json", "JSON output").action(async (options) => {
63
+ try {
64
+ const { identity, spaceId, directory } = await boundRuntime(program, void 0, options.space);
65
+ const stateRoot = runtimeStateRoot(spaceId);
66
+ const config = await readNativeConfig(stateRoot, identity);
67
+ const paused = options.harness.length ? parseRuntimeHarnesses(options.harness) : config?.harnesses ?? [...LOCAL_HARNESSES];
68
+ const harnesses = (config?.harnesses ?? []).filter((harness) => !paused.includes(harness));
69
+ if (config) await writeNativeConfig(stateRoot, {
70
+ ...config,
71
+ harnesses,
72
+ codexShared: harnesses.includes("codex") && config.codexShared
73
+ });
74
+ await controlRuntimeInstance(directory, "reload").catch(() => void 0);
75
+ const codexWasShared = Boolean(config?.codexShared) && paused.includes("codex");
76
+ if (jsonRequested(options)) json({
77
+ spaceId,
78
+ harnesses,
79
+ paused,
80
+ enabled: harnesses.length > 0
81
+ });
82
+ else {
83
+ process.stdout.write(harnesses.length ? `Native sync paused for ${paused.join(", ")}; still syncing ${harnesses.join(", ")}\n` : "Native sync paused; all data retained\n");
84
+ if (codexWasShared) process.stdout.write("Codex's shared app-server keeps running; stop it with codex app-server daemon stop\n");
85
+ }
86
+ } catch (cause) {
87
+ reportFailure(cause);
88
+ }
89
+ });
90
+ runtime.command("import [dir]").description("Import earlier local conversations, newest first").option("-s, --space <space>", "Target Space: ID, slug, or username/slug").option("--harness <name>", "Filter by harness; repeatable", (value, previous) => [...previous, value], []).option("--session <id>", "Filter by native session ID").option("--concurrency <count>", `Conversations read in parallel, 1 to 8`, String(4)).option("--dry-run", "Preview without importing").option("-y, --yes", "Skip confirmation").option("--json", "Output as JSON").action(async (dir, options) => {
91
+ const controller = new AbortController();
92
+ const stop = () => controller.abort();
93
+ process.once("SIGINT", stop);
94
+ process.once("SIGTERM", stop);
95
+ const asJson = jsonRequested(options);
96
+ try {
97
+ const concurrency = Number(options.concurrency);
98
+ if (!Number.isSafeInteger(concurrency) || concurrency < 1 || concurrency > 8) throw new Error(`Use a concurrency from 1 to 8`);
99
+ const { spaceId, root, directory } = await boundRuntime(program, dir, options.space);
100
+ const filter = {
101
+ harnesses: options.harness.length ? parseRuntimeHarnesses(options.harness) : [],
102
+ ...options.session ? { nativeSessionId: options.session } : {}
103
+ };
104
+ const control = async (command, timeoutMs = 6e4) => {
105
+ const response = await controlRuntimeInstance(directory, "import", {
106
+ ...filter,
107
+ command,
108
+ concurrency
109
+ }, timeoutMs);
110
+ if (!response) throw new Error("Local Runtime is not running; start it with cohub runtime up");
111
+ return response.result;
112
+ };
113
+ const plan = await control("plan");
114
+ const summary = {
115
+ spaceId,
116
+ root,
117
+ ...plan,
118
+ dryRun: Boolean(options.dryRun)
119
+ };
120
+ if (options.dryRun || !plan.files) {
121
+ if (asJson) json(summary);
122
+ else if (!plan.files) process.stdout.write("No earlier conversations left to import\n");
123
+ else {
124
+ process.stdout.write(`Found ${plan.files} conversation${plan.files === 1 ? "" : "s"} · ${megabytes(plan.bytes)}\n`);
125
+ for (const item of plan.sample) process.stdout.write(` ${item.harness.padEnd(5)} ${new Date(item.mtimeMs).toISOString().slice(0, 16).replace("T", " ")} ${item.nativeSessionId ?? ""} ${item.path}\n`);
126
+ if (plan.files > plan.sample.length) process.stdout.write(` … and ${plan.files - plan.sample.length} more\n`);
127
+ }
128
+ return;
129
+ }
130
+ if (!options.yes) {
131
+ if (!process.stdin.isTTY) throw new Error("Use --yes in non-interactive mode");
132
+ const { createInterface } = await import("node:readline/promises");
133
+ const rl = createInterface({
134
+ input: process.stdin,
135
+ output: process.stderr
136
+ });
137
+ try {
138
+ const answer = await rl.question(`Import ${plan.files} conversation${plan.files === 1 ? "" : "s"} (${megabytes(plan.bytes)}) to Space ${spaceId}? [Y/n] `);
139
+ if (!/^(|y(es)?)$/i.test(answer.trim())) {
140
+ if (asJson) json({
141
+ ...summary,
142
+ cancelled: true
143
+ });
144
+ else process.stdout.write("Import cancelled\n");
145
+ return;
146
+ }
147
+ } finally {
148
+ rl.close();
149
+ }
150
+ }
151
+ let job = await control("start");
152
+ while (!controller.signal.aborted && job.state === "running") {
153
+ if (!asJson && process.stderr.isTTY) process.stderr.write(`\r\x1b[2KImporting ${formatImportProgress(job)}`);
154
+ await setTimeout(500, void 0, { signal: controller.signal }).catch(() => void 0);
155
+ const status = await requestRuntimeInstance(directory);
156
+ if (!status?.native) throw new Error("Local Runtime stopped; the import resumes when it starts again");
157
+ job = status.native.import;
158
+ }
159
+ if (controller.signal.aborted) job = await control("pause", 5e3);
160
+ const paused = job.state === "paused";
161
+ if (asJson) json({
162
+ ...summary,
163
+ ...job,
164
+ paused
165
+ });
166
+ else {
167
+ if (process.stderr.isTTY) process.stderr.write("\r\x1B[2K");
168
+ process.stdout.write(`${paused ? "Paused" : "Imported"} ${formatImportProgress(job)}\n`);
169
+ for (const failure of job.failed) process.stdout.write(`Skipped ${failure.path}: ${failure.message}\n`);
170
+ if (paused) process.stdout.write("Run cohub runtime import again to continue\n");
171
+ }
172
+ if (job.failed.length) process.exitCode = 1;
173
+ } catch (cause) {
174
+ reportFailure(cause);
175
+ } finally {
176
+ process.removeListener("SIGINT", stop);
177
+ process.removeListener("SIGTERM", stop);
178
+ }
179
+ });
180
+ runtime.command("status").description("Local and server status").option("-s, --space <space>", "Target Space: ID, slug, or username/slug").option("--json", "JSON output").action(async (options) => {
181
+ try {
182
+ const spaceId = await resolveRuntimeTarget(program, options.space);
183
+ const identity = currentIdentityKey();
184
+ const local = identity ? await requestRuntimeInstance(runtimeInstanceDirectory(identity, spaceId)) : null;
185
+ const space = createClient().space(spaceId);
186
+ const stateRoot = runtimeStateRoot(spaceId);
187
+ const archives = new RuntimeArchiveStore(join(stateRoot, "archives"));
188
+ const [remote, pendingLocalArchives, failedLocalArchives] = await Promise.all([
189
+ space.getRuntime(void 0, { signal: AbortSignal.timeout(5e3) }).then((value) => ({
190
+ value,
191
+ error: null
192
+ })).catch((error) => ({
193
+ value: null,
194
+ error: serializeDiagnosticError(error).message
195
+ })),
196
+ archives.pendingCount(),
197
+ archives.failedCaptureCount()
198
+ ]);
199
+ const nativeSync = identity ? await readNativeConfig(stateRoot, identity).then((config) => ({
200
+ config,
201
+ error: null
202
+ }), (error) => ({
203
+ config: null,
204
+ error: serializeDiagnosticError(error).message
205
+ })) : {
206
+ config: null,
207
+ error: null
208
+ };
209
+ const result = {
210
+ ...remote.value,
211
+ spaceId,
212
+ local,
213
+ remote: remote.value,
214
+ remoteError: remote.error,
215
+ diagnosticsPath: runtimeDiagnosticsDirectory(stateRoot),
216
+ pendingLocalArchives,
217
+ failedLocalArchives,
218
+ nativeSync: nativeSync.config,
219
+ nativeSyncError: nativeSync.error,
220
+ native: local?.native ?? null
221
+ };
222
+ if (jsonRequested(options)) json(result);
223
+ else {
224
+ if (local) printRuntimeSummary(local);
225
+ else process.stdout.write(`Local process Not running\nSpace ${spaceId}\nLogs ${result.diagnosticsPath}\n`);
226
+ process.stdout.write(`Server ${remote.error ? `Unknown — ${remote.error}` : remote.value?.online ? "Harness connected" : "Offline"}\nArchives ${pendingLocalArchives} pending · ${failedLocalArchives} failed\n`);
227
+ const displays = remote.value?.displays ?? [];
228
+ if (displays.length) process.stdout.write(`Displays ${displays.map((display) => `${display.name || display.id} ${display.width}x${display.height}${display.needs?.length ? ` (needs ${display.needs.join(", ")})` : display.input ? "" : " (view only)"}`).join(" · ")}\n`);
229
+ process.stdout.write(formatNativeSync(nativeSync.config, local?.native, nativeSync.error));
230
+ }
231
+ } catch (cause) {
232
+ reportFailure(cause);
233
+ }
234
+ });
235
+ runtime.command("down").description("Stop this local Runtime; retain all data").option("-s, --space <space>", "Target Space: ID, slug, or username/slug").option("-y, --yes", "Stop even with unconfirmed executions").option("--json", "JSON output").action(async (options) => {
236
+ try {
237
+ const spaceId = await resolveRuntimeTarget(program, options.space);
238
+ const identity = currentIdentityKey();
239
+ if (!identity) throw new Error("Sign in to the Runtime account");
240
+ const local = await stopRuntimeInstance(runtimeInstanceDirectory(identity, spaceId), Boolean(options.yes));
241
+ await forgetHostRuntime(identity, spaceId).catch((cause) => process.stderr.write(`Desktop app may reconnect this folder: ${serializeDiagnosticError(cause).message}\n`));
242
+ if (jsonRequested(options)) json({
243
+ spaceId,
244
+ stopped: true
245
+ });
246
+ else {
247
+ process.stdout.write("Runtime stopped; data retained\n");
248
+ if (local?.native?.codex?.control === "shared") process.stdout.write("Codex's shared app-server keeps running; stop it with codex app-server daemon stop\n");
249
+ }
250
+ } catch (cause) {
251
+ reportFailure(cause);
252
+ }
253
+ });
254
+ runtime.command("logs").description("Read local Runtime diagnostics").option("-s, --space <space>", "Target Space: ID, slug, or username/slug").option("-l, --limit <count>", "Number of events", "100").option("--level <level>", "Minimum level: debug, info, warn, error", "info").option("-f, --follow", "Keep watching").option("--json", "Raw diagnostic events").action(async (options) => {
255
+ const controller = new AbortController();
256
+ const stop = () => controller.abort();
257
+ try {
258
+ const spaceId = await resolveRuntimeTarget(program, options.space);
259
+ const stateRoot = runtimeStateRoot(spaceId);
260
+ const limit = Number(options.limit);
261
+ if (!Number.isSafeInteger(limit) || limit < 1 || limit > 1e4) throw new Error("Use a limit from 1 to 10000");
262
+ if (!diagnosticLevels.includes(options.level)) throw new Error("Use debug, info, warn or error");
263
+ const asJson = jsonRequested(options);
264
+ const reader = new RuntimeDiagnosticReader(stateRoot);
265
+ process.once("SIGINT", stop);
266
+ process.once("SIGTERM", stop);
267
+ do {
268
+ const events = (options.follow ? await reader.read({ limit }) : await readRuntimeDiagnosticEvents(stateRoot, { limit })).filter((event) => atLeastLevel(event.level, options.level));
269
+ if (asJson && !options.follow) json(events);
270
+ else for (const event of events) process.stdout.write(asJson ? `${JSON.stringify(event)}\n` : formatDiagnostic(event, true));
271
+ if (!options.follow) {
272
+ if (!asJson && !events.length) process.stdout.write("No matching diagnostics\n");
273
+ break;
274
+ }
275
+ await setTimeout(1e3, void 0, { signal: controller.signal }).catch(() => void 0);
276
+ } while (!controller.signal.aborted);
277
+ } catch (cause) {
278
+ reportFailure(cause);
279
+ } finally {
280
+ process.removeListener("SIGINT", stop);
281
+ process.removeListener("SIGTERM", stop);
282
+ }
283
+ });
284
+ }
285
+ //#endregion
286
+ export { registerRuntime };
@@ -0,0 +1,48 @@
1
+ import { Q as withRuntimeSpaceBindingsLock } from "./client.js";
2
+ import { homedir } from "node:os";
3
+ import { dirname, join } from "node:path";
4
+ import { randomUUID } from "node:crypto";
5
+ import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
6
+ //#region src/host/runtimes.ts
7
+ const hostRuntimesPath = () => join(homedir(), ".local", "state", "cohub", "host", "runtimes.json");
8
+ async function read(path) {
9
+ let text;
10
+ try {
11
+ text = await readFile(path, "utf8");
12
+ } catch (error) {
13
+ if (error.code === "ENOENT") return [];
14
+ throw error;
15
+ }
16
+ const file = JSON.parse(text);
17
+ if (file.version !== 1 || !Array.isArray(file.runtimes)) throw new Error(`Unsupported desktop Runtime state: ${path}`);
18
+ return file.runtimes.filter((item) => typeof item?.key === "string" && typeof item.spaceId === "string" && typeof item.root === "string");
19
+ }
20
+ async function update(path, change) {
21
+ await withRuntimeSpaceBindingsLock(async () => {
22
+ const before = await read(path);
23
+ const after = change(before);
24
+ if (JSON.stringify(after) === JSON.stringify(before)) return;
25
+ await mkdir(dirname(path), {
26
+ recursive: true,
27
+ mode: 448
28
+ });
29
+ const temporary = `${path}.${randomUUID()}.tmp`;
30
+ try {
31
+ await writeFile(temporary, `${JSON.stringify({
32
+ version: 1,
33
+ runtimes: after
34
+ }, null, 2)}\n`, {
35
+ mode: 384,
36
+ flag: "wx"
37
+ });
38
+ await rename(temporary, path);
39
+ } finally {
40
+ await rm(temporary, { force: true });
41
+ }
42
+ }, { path });
43
+ }
44
+ const hostRuntimes = (key, path = hostRuntimesPath()) => read(path).then((runtimes) => runtimes.filter((item) => item.key === key));
45
+ const rememberHostRuntime = (runtime, path = hostRuntimesPath()) => update(path, (runtimes) => [...runtimes.filter((item) => item.key !== runtime.key || item.spaceId !== runtime.spaceId), runtime]);
46
+ const forgetHostRuntime = (key, spaceId, path = hostRuntimesPath()) => update(path, (runtimes) => runtimes.filter((item) => item.key !== key || item.spaceId !== spaceId));
47
+ //#endregion
48
+ export { hostRuntimes as n, rememberHostRuntime as r, forgetHostRuntime as t };
@@ -0,0 +1,198 @@
1
+ import { ft as isPublicBoardRemoteAddress, pt as normalizeBoardRemoteUrl } from "./id.js";
2
+ import http from "node:http";
3
+ import { isIP } from "node:net";
4
+ import dns from "node:dns/promises";
5
+ import https from "node:https";
6
+ const MAX_REDIRECTS = 3;
7
+ const IMAGE_MIME_TYPES = /* @__PURE__ */ new Set([
8
+ "image/avif",
9
+ "image/gif",
10
+ "image/jpeg",
11
+ "image/png",
12
+ "image/webp"
13
+ ]);
14
+ const AUDIO_MIME_TYPES = /* @__PURE__ */ new Set([
15
+ "audio/mpeg",
16
+ "audio/mp3",
17
+ "audio/mp4",
18
+ "audio/aac",
19
+ "audio/ogg",
20
+ "audio/wav",
21
+ "audio/x-wav",
22
+ "audio/wave",
23
+ "audio/flac",
24
+ "audio/x-flac",
25
+ "audio/webm",
26
+ "audio/opus",
27
+ "application/ogg"
28
+ ]);
29
+ const VIDEO_MIME_TYPES = /* @__PURE__ */ new Set([
30
+ "video/mp4",
31
+ "video/webm",
32
+ "video/quicktime",
33
+ "video/ogg",
34
+ "video/x-matroska"
35
+ ]);
36
+ const REDIRECT_STATUSES = /* @__PURE__ */ new Set([
37
+ 301,
38
+ 302,
39
+ 303,
40
+ 307,
41
+ 308
42
+ ]);
43
+ async function defaultLookup(hostname) {
44
+ return (await dns.lookup(hostname, {
45
+ all: true,
46
+ verbatim: true
47
+ })).map((record) => ({
48
+ address: record.address,
49
+ family: record.family
50
+ }));
51
+ }
52
+ function responseHeaders(input) {
53
+ const headers = new Headers();
54
+ for (const [key, value] of Object.entries(input)) if (Array.isArray(value)) for (const item of value) headers.append(key, item);
55
+ else if (value !== void 0) headers.set(key, value);
56
+ return headers;
57
+ }
58
+ /** Async like `dns.lookup`: a synchronous answer crashes TLS on an immediate connect failure. */
59
+ function pinnedLookup(addresses) {
60
+ const [first] = addresses;
61
+ return (_hostname, options, callback) => {
62
+ process.nextTick(() => options.all ? callback(null, [...addresses]) : callback(null, first.address, first.family));
63
+ };
64
+ }
65
+ function requestPinned(url, addresses, timeoutMs, maxBytes) {
66
+ return new Promise((resolve, reject) => {
67
+ const request = (url.protocol === "https:" ? https : http).request(url, {
68
+ agent: false,
69
+ headers: { Accept: "image/*,audio/*,application/ogg" },
70
+ lookup: pinnedLookup(addresses)
71
+ }, (response) => {
72
+ const status = response.statusCode ?? 0;
73
+ const headers = responseHeaders(response.headers);
74
+ if (REDIRECT_STATUSES.has(status)) {
75
+ response.resume();
76
+ resolve({
77
+ status,
78
+ headers,
79
+ bytes: /* @__PURE__ */ new Uint8Array()
80
+ });
81
+ return;
82
+ }
83
+ const declaredLength = Number(headers.get("content-length") ?? 0);
84
+ if (Number.isFinite(declaredLength) && declaredLength > maxBytes) {
85
+ response.destroy();
86
+ reject(/* @__PURE__ */ new Error(`Media exceeds the ${maxBytes} byte download limit`));
87
+ return;
88
+ }
89
+ const chunks = [];
90
+ let total = 0;
91
+ response.on("data", (chunk) => {
92
+ total += chunk.byteLength;
93
+ if (total > maxBytes) {
94
+ response.destroy(/* @__PURE__ */ new Error(`Media exceeds the ${maxBytes} byte download limit`));
95
+ return;
96
+ }
97
+ chunks.push(chunk);
98
+ });
99
+ response.once("error", reject);
100
+ response.once("end", () => {
101
+ const bytes = new Uint8Array(total);
102
+ let offset = 0;
103
+ for (const chunk of chunks) {
104
+ bytes.set(chunk, offset);
105
+ offset += chunk.byteLength;
106
+ }
107
+ resolve({
108
+ status,
109
+ headers,
110
+ bytes
111
+ });
112
+ });
113
+ });
114
+ request.setTimeout(timeoutMs, () => {
115
+ request.destroy(/* @__PURE__ */ new Error(`Media download timed out after ${timeoutMs}ms`));
116
+ });
117
+ request.once("error", reject);
118
+ request.end();
119
+ });
120
+ }
121
+ function remainingMs(deadline) {
122
+ const remaining = deadline - Date.now();
123
+ if (remaining <= 0) throw new Error("Media download timed out");
124
+ return remaining;
125
+ }
126
+ async function withDeadline(promise, deadline) {
127
+ const timeoutMs = remainingMs(deadline);
128
+ let timer;
129
+ try {
130
+ return await Promise.race([promise, new Promise((_, reject) => {
131
+ timer = setTimeout(() => reject(/* @__PURE__ */ new Error(`Media download timed out after ${timeoutMs}ms`)), timeoutMs);
132
+ })]);
133
+ } finally {
134
+ if (timer) clearTimeout(timer);
135
+ }
136
+ }
137
+ async function resolvePublicUrl(value, lookup, deadline) {
138
+ const normalized = normalizeBoardRemoteUrl(value);
139
+ if (!normalized) throw new Error("Media URL must be a public HTTP(S) URL");
140
+ const url = new URL(normalized);
141
+ const hostname = url.hostname.replace(/^\[|\]$/g, "");
142
+ const addresses = isIP(hostname) ? [{
143
+ address: hostname,
144
+ family: isIP(hostname)
145
+ }] : await withDeadline(lookup(hostname), deadline);
146
+ const [first, ...rest] = addresses;
147
+ if (!first || addresses.some((entry) => !isPublicBoardRemoteAddress(entry.address))) throw new Error("Media URL resolves to a private address");
148
+ return {
149
+ url,
150
+ addresses: [first, ...rest]
151
+ };
152
+ }
153
+ function downloadPublicImage(input, options = {}) {
154
+ return downloadPublicMedia(input, IMAGE_MIME_TYPES, options);
155
+ }
156
+ function downloadPublicAudio(input, options = {}) {
157
+ return downloadPublicMedia(input, AUDIO_MIME_TYPES, {
158
+ maxBytes: 67108864,
159
+ timeoutMs: 3e4,
160
+ ...options
161
+ });
162
+ }
163
+ function downloadPublicVideo(input, options = {}) {
164
+ return downloadPublicMedia(input, VIDEO_MIME_TYPES, {
165
+ maxBytes: 536870912,
166
+ timeoutMs: 12e4,
167
+ ...options
168
+ });
169
+ }
170
+ async function downloadPublicMedia(input, mimeTypes, options) {
171
+ const lookup = options.lookup ?? defaultLookup;
172
+ const requester = options.requester ?? requestPinned;
173
+ const maxBytes = options.maxBytes ?? 16777216;
174
+ const deadline = Date.now() + (options.timeoutMs ?? 15e3);
175
+ let current = input;
176
+ for (let redirect = 0; redirect <= MAX_REDIRECTS; redirect += 1) {
177
+ const { url, addresses } = await resolvePublicUrl(current, lookup, deadline);
178
+ const response = await withDeadline(requester(url, addresses, remainingMs(deadline), maxBytes), deadline);
179
+ if (REDIRECT_STATUSES.has(response.status)) {
180
+ const location = response.headers.get("location");
181
+ if (!location) throw new Error("Media redirect is missing a location");
182
+ if (redirect === MAX_REDIRECTS) throw new Error("Too many media redirects");
183
+ current = new URL(location, url).toString();
184
+ continue;
185
+ }
186
+ if (response.status < 200 || response.status >= 300) throw new Error(`HTTP ${response.status}`);
187
+ if (response.bytes.byteLength > maxBytes) throw new Error(`Media exceeds the ${maxBytes} byte download limit`);
188
+ const mimeType = response.headers.get("content-type")?.split(";", 1)[0]?.trim().toLowerCase();
189
+ if (!mimeType || !mimeTypes.has(mimeType)) throw new Error("Remote resource has an unsupported media type");
190
+ return {
191
+ bytes: response.bytes,
192
+ mimeType
193
+ };
194
+ }
195
+ throw new Error("Too many media redirects");
196
+ }
197
+ //#endregion
198
+ export { downloadPublicImage as n, downloadPublicVideo as r, downloadPublicAudio as t };