@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,295 +0,0 @@
1
- import { spawn } from "node:child_process";
2
- import { createHash } from "node:crypto";
3
- import { lstatSync, mkdirSync, statSync, unlinkSync } from "node:fs";
4
- import { createConnection, createServer } from "node:net";
5
- import { tmpdir, userInfo } from "node:os";
6
- import { join } from "node:path";
7
- import { fileURLToPath } from "node:url";
8
- import { launchBoardGpuExporter } from "./index.js";
9
- import { CLI_VERSION } from "../version.js";
10
- const IDLE_MS = 5 * 60_000;
11
- const CONNECT_MS = 20_000;
12
- const TURN_MS = 20_000;
13
- function lines(socket, handle) {
14
- let buffer = "";
15
- socket.setEncoding("utf8");
16
- socket.on("data", (chunk) => {
17
- buffer += chunk;
18
- for (let end = buffer.indexOf("\n"); end >= 0; end = buffer.indexOf("\n")) {
19
- const line = buffer.slice(0, end);
20
- buffer = buffer.slice(end + 1);
21
- let message;
22
- try {
23
- message = JSON.parse(line);
24
- }
25
- catch {
26
- continue;
27
- }
28
- handle(message);
29
- }
30
- });
31
- return (message) => socket.write(`${JSON.stringify(message)}\n`);
32
- }
33
- export function boardGpuSocket(browser) {
34
- let page = 0;
35
- try {
36
- page = statSync(fileURLToPath(new URL("./page.js", import.meta.url))).mtimeMs;
37
- }
38
- catch { }
39
- const { uid } = userInfo();
40
- const key = createHash("sha256").update(`${CLI_VERSION}\0${browser}\0${page}\0${uid}`).digest("hex").slice(0, 16);
41
- if (process.platform === "win32")
42
- return join("\\\\.\\pipe", `cohub-board-gpu-${key}`);
43
- const dir = join(process.env.XDG_RUNTIME_DIR || tmpdir(), `cohub-${uid}`);
44
- mkdirSync(dir, { recursive: true, mode: 0o700 });
45
- const stat = lstatSync(dir);
46
- if (!stat.isDirectory() || stat.uid !== uid || (stat.mode & 0o077) !== 0)
47
- throw new Error(`${dir} is not private to this user.`);
48
- return join(dir, `board-gpu-${key}.sock`);
49
- }
50
- export async function serveBoardGpu(browser) {
51
- const path = boardGpuSocket(browser);
52
- const queue = [];
53
- let exporter = null;
54
- let nextAsk = 0;
55
- let idle = null;
56
- const active = () => queue[0] ?? null;
57
- const ask = (request) => new Promise((resolve, reject) => {
58
- const caller = active();
59
- if (!caller || caller.gone)
60
- return reject(new Error("The caller left."));
61
- const id = ++nextAsk;
62
- caller.asks.set(id, resolve);
63
- caller.send({ ask: id, request });
64
- });
65
- const resources = {
66
- fonts: [],
67
- async readModule(path) {
68
- const answer = await ask({ kind: "module", path });
69
- if (answer.error !== undefined || answer.text === undefined)
70
- throw new Error(answer.error ?? `${path} is not available.`);
71
- return answer.text;
72
- },
73
- async readPicture(request) {
74
- const answer = await ask({ kind: "picture", request });
75
- if (answer.error !== undefined)
76
- throw new Error(answer.error);
77
- return answer.bytes === undefined ? null : { bytes: Buffer.from(answer.bytes, "base64"), mimeType: answer.mimeType ?? "application/octet-stream" };
78
- },
79
- };
80
- const { resolveBundledFonts } = await import("../board-export.js");
81
- resources.fonts = resolveBundledFonts().flatMap(({ path, family }) => (family ? [{ path, family }] : []));
82
- const browserFor = () => (exporter ??= launchBoardGpuExporter(resources, { browser }).catch((error) => {
83
- exporter = null;
84
- throw error;
85
- }));
86
- const reset = async () => {
87
- const current = exporter;
88
- exporter = null;
89
- await current?.then((value) => value.close(), () => { });
90
- };
91
- const shutdown = async () => {
92
- await reset();
93
- server.close();
94
- process.exit(0);
95
- };
96
- const schedule = () => {
97
- if (idle)
98
- clearTimeout(idle);
99
- idle = queue.length ? null : setTimeout(() => void shutdown(), IDLE_MS);
100
- };
101
- const advance = () => {
102
- active()?.send({ granted: true });
103
- schedule();
104
- };
105
- const release = (caller) => {
106
- if (!caller.gone || caller.running)
107
- return;
108
- const index = queue.indexOf(caller);
109
- if (index < 0)
110
- return;
111
- queue.splice(index, 1);
112
- if (index === 0)
113
- advance();
114
- };
115
- const server = createServer((socket) => {
116
- const caller = { send: () => { }, asks: new Map(), running: 0, gone: false };
117
- caller.send = lines(socket, (message) => {
118
- if ("answer" in message) {
119
- caller.asks.get(message.answer)?.(message);
120
- caller.asks.delete(message.answer);
121
- return;
122
- }
123
- if (!("method" in message) || active() !== caller)
124
- return;
125
- caller.running++;
126
- void browserFor()
127
- .then((gpu) => call(gpu, message.method, message.params))
128
- .then((result) => caller.send({ id: message.id, result }), async (error) => {
129
- const text = error instanceof Error ? error.message : String(error);
130
- if (/stopped responding|browser (stopped|closed)|did not start/i.test(text))
131
- await reset();
132
- caller.send({ id: message.id, error: text });
133
- })
134
- .finally(() => {
135
- caller.running--;
136
- release(caller);
137
- });
138
- });
139
- const leave = () => {
140
- if (caller.gone)
141
- return;
142
- caller.gone = true;
143
- for (const resolve of caller.asks.values())
144
- resolve({ answer: -1, error: "The caller left." });
145
- caller.asks.clear();
146
- release(caller);
147
- };
148
- socket.on("close", leave);
149
- socket.on("error", leave);
150
- queue.push(caller);
151
- if (queue.length === 1)
152
- advance();
153
- });
154
- await new Promise((resolve, reject) => {
155
- server.once("error", async (error) => {
156
- if (error.code !== "EADDRINUSE")
157
- return reject(error);
158
- const alive = await new Promise((done) => {
159
- const probe = createConnection(path, () => { probe.destroy(); done(true); });
160
- probe.once("error", () => done(false));
161
- });
162
- if (alive)
163
- return process.exit(0);
164
- try {
165
- unlinkSync(path);
166
- }
167
- catch { }
168
- server.listen(path, resolve);
169
- });
170
- server.listen(path, resolve);
171
- });
172
- process.on("SIGTERM", () => void shutdown());
173
- schedule();
174
- }
175
- function call(gpu, method, params) {
176
- switch (method) {
177
- case "init": return gpu.init(params);
178
- case "compile": return gpu.compile(params);
179
- case "profile": return gpu.profile(params);
180
- case "render": return gpu.render(params).then(({ bytes, ...rest }) => ({ ...rest, data: Buffer.from(bytes).toString("base64") }));
181
- }
182
- }
183
- function startDaemon(browser) {
184
- const entry = process.argv[1];
185
- if (!entry)
186
- throw new Error("The CLI entry point is unknown.");
187
- spawn(process.execPath, [...process.execArgv, entry, "boards", "gpu-daemon", "--browser", browser], {
188
- detached: true,
189
- stdio: "ignore",
190
- env: process.env,
191
- }).unref();
192
- }
193
- function connect(path) {
194
- return new Promise((resolve, reject) => {
195
- const socket = createConnection(path, () => resolve(socket));
196
- socket.once("error", reject);
197
- });
198
- }
199
- export async function connectBoardGpu(resources, options) {
200
- if (process.env.COHUB_BOARD_GPU_DAEMON === "0")
201
- return null;
202
- const path = boardGpuSocket(options.browser);
203
- let socket = await connect(path).catch(() => null);
204
- if (!socket) {
205
- try {
206
- startDaemon(options.browser);
207
- }
208
- catch {
209
- return null;
210
- }
211
- for (const started = Date.now(); !socket && Date.now() - started < CONNECT_MS;) {
212
- await new Promise((resolve) => setTimeout(resolve, 100));
213
- socket = await connect(path).catch(() => null);
214
- }
215
- if (!socket)
216
- return null;
217
- }
218
- const connected = socket;
219
- const pending = new Map();
220
- let next = 0;
221
- let granted = () => { };
222
- const turn = new Promise((resolve) => { granted = resolve; });
223
- const fail = (error) => {
224
- granted(false);
225
- for (const waiting of pending.values())
226
- waiting.reject(error);
227
- pending.clear();
228
- };
229
- const send = lines(connected, (message) => {
230
- if ("granted" in message)
231
- return granted(true);
232
- if ("ask" in message) {
233
- void answer(message.request).then((reply) => send({ answer: message.ask, ...reply }));
234
- return;
235
- }
236
- if ("id" in message && !("method" in message)) {
237
- const waiting = pending.get(message.id);
238
- pending.delete(message.id);
239
- if (message.error !== undefined)
240
- waiting?.reject(new Error(message.error));
241
- else
242
- waiting?.resolve(message.result);
243
- }
244
- });
245
- connected.on("close", () => fail(new Error("The shared browser closed.")));
246
- connected.on("error", (error) => fail(error));
247
- options.signal?.addEventListener("abort", () => connected.destroy(), { once: true });
248
- const timer = setTimeout(() => granted(false), TURN_MS);
249
- const ours = await turn;
250
- clearTimeout(timer);
251
- if (!ours) {
252
- connected.destroy();
253
- return null;
254
- }
255
- async function answer(request) {
256
- try {
257
- if (request.kind === "module")
258
- return { text: await resources.readModule(request.path) };
259
- const picture = await resources.readPicture(request.request);
260
- return picture ? { bytes: Buffer.from(picture.bytes).toString("base64"), mimeType: picture.mimeType } : { missing: true };
261
- }
262
- catch (error) {
263
- return { error: error instanceof Error ? error.message : String(error) };
264
- }
265
- }
266
- const request = (method, params) => {
267
- if (connected.destroyed)
268
- return Promise.reject(new Error("The shared browser closed."));
269
- const id = ++next;
270
- return new Promise((resolve, reject) => {
271
- pending.set(id, { resolve: resolve, reject });
272
- send({ id, method, params });
273
- });
274
- };
275
- return {
276
- browser: options.browser,
277
- init: (init) => request("init", init),
278
- compile: (shaders) => request("compile", shaders),
279
- profile: (input) => request("profile", input),
280
- async render(frame) {
281
- const { data, ...rest } = await request("render", frame);
282
- return { ...rest, bytes: new Uint8Array(Buffer.from(data, "base64")) };
283
- },
284
- async close() {
285
- connected.end();
286
- },
287
- };
288
- }
289
- export async function openBoardGpu(resources, options) {
290
- const shared = await connectBoardGpu(resources, options).catch(() => null);
291
- if (shared)
292
- return shared;
293
- options.signal?.throwIfAborted();
294
- return launchBoardGpuExporter(resources, options);
295
- }
@@ -1,33 +0,0 @@
1
- import type { BoardGpuFrame, BoardGpuInit, BoardGpuProfile, BoardGpuProfileInput, BoardGpuResult, BoardGpuShader } from "./protocol.js";
2
- export type { BoardGpuFrame, BoardGpuProfile, BoardGpuProfileInput, BoardGpuResult, BoardGpuShader } from "./protocol.js";
3
- export declare function findBoardGpuBrowser(env?: NodeJS.ProcessEnv): string | null;
4
- export type BoardGpuResources = {
5
- readModule(path: string): Promise<string>;
6
- readPicture(request: {
7
- key: string;
8
- edge: number;
9
- } | {
10
- background: true;
11
- }): Promise<{
12
- bytes: Uint8Array;
13
- mimeType: string;
14
- } | null>;
15
- fonts: readonly {
16
- family: string;
17
- path: string;
18
- }[];
19
- };
20
- export type BoardGpuExporter = {
21
- readonly browser: string;
22
- init(init: BoardGpuInit): Promise<void>;
23
- render(frame: BoardGpuFrame): Promise<Omit<BoardGpuResult, "data"> & {
24
- bytes: Uint8Array;
25
- }>;
26
- compile(shaders: BoardGpuShader[]): Promise<Record<string, string>>;
27
- profile(input: BoardGpuProfileInput): Promise<BoardGpuProfile>;
28
- close(): Promise<void>;
29
- };
30
- export declare function launchBoardGpuExporter(resources: BoardGpuResources, options: {
31
- browser: string;
32
- signal?: AbortSignal;
33
- }): Promise<BoardGpuExporter>;
@@ -1,189 +0,0 @@
1
- import { spawn } from "node:child_process";
2
- import { randomBytes } from "node:crypto";
3
- import { existsSync } from "node:fs";
4
- import { mkdtemp, readFile, rm } from "node:fs/promises";
5
- import { createServer } from "node:http";
6
- import { tmpdir } from "node:os";
7
- import { basename, join } from "node:path";
8
- import { fileURLToPath } from "node:url";
9
- export function findBoardGpuBrowser(env = process.env) {
10
- const named = env.COHUB_CHROME?.trim();
11
- if (named)
12
- return existsSync(named) ? named : null;
13
- const candidates = process.platform === "darwin"
14
- ? ["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", "/Applications/Chromium.app/Contents/MacOS/Chromium", "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"]
15
- : process.platform === "win32"
16
- ? [env.PROGRAMFILES, env["PROGRAMFILES(X86)"], env.LOCALAPPDATA].flatMap((root) => root ? [join(root, "Google/Chrome/Application/chrome.exe"), join(root, "Microsoft/Edge/Application/msedge.exe")] : [])
17
- : ["google-chrome", "google-chrome-stable", "chromium", "chromium-browser", "microsoft-edge"].flatMap((name) => (env.PATH ?? "").split(":").filter(Boolean).map((dir) => join(dir, name)));
18
- return candidates.find((path) => existsSync(path)) ?? null;
19
- }
20
- const CALL_TIMEOUT_MS = 120_000;
21
- function devtools(input, output) {
22
- let next = 0;
23
- let buffer = "";
24
- const pending = new Map();
25
- const listeners = new Set();
26
- output.setEncoding("utf8");
27
- output.on("data", (chunk) => {
28
- buffer += chunk;
29
- for (let end = buffer.indexOf("\0"); end >= 0; end = buffer.indexOf("\0")) {
30
- const raw = buffer.slice(0, end);
31
- buffer = buffer.slice(end + 1);
32
- let message;
33
- try {
34
- message = JSON.parse(raw);
35
- }
36
- catch {
37
- continue;
38
- }
39
- const waiting = message.id === undefined ? undefined : pending.get(message.id);
40
- if (waiting && message.id !== undefined) {
41
- pending.delete(message.id);
42
- if (message.error)
43
- waiting.reject(new Error(message.error.message));
44
- else
45
- waiting.resolve(message.result ?? {});
46
- }
47
- for (const listener of listeners)
48
- listener(message);
49
- }
50
- });
51
- const fail = (error) => {
52
- for (const waiting of pending.values())
53
- waiting.reject(error);
54
- pending.clear();
55
- };
56
- output.on("close", () => fail(new Error("The browser closed.")));
57
- output.on("error", (error) => fail(error));
58
- input.on("error", (error) => fail(error));
59
- return {
60
- send(method, params = {}, sessionId) {
61
- const id = ++next;
62
- return new Promise((resolve, reject) => {
63
- pending.set(id, { resolve, reject });
64
- input.write(`${JSON.stringify({ id, method, params, ...(sessionId ? { sessionId } : {}) })}\0`);
65
- });
66
- },
67
- listen(listener) {
68
- listeners.add(listener);
69
- },
70
- fail,
71
- };
72
- }
73
- const PAGE = (fonts) => `<!doctype html><meta charset="utf-8"><style>${fonts
74
- .map(({ family, file }) => `@font-face{font-family:"${family}";src:url("fonts/${file}") format("woff2");font-weight:100 900}`)
75
- .join("")}</style><body>${fonts.map(({ family }) => `<span style="font-family:'${family}'">.</span>`).join("")}<script type="module" src="page.js"></script>`;
76
- export async function launchBoardGpuExporter(resources, options) {
77
- const bundle = fileURLToPath(new URL("./page.js", import.meta.url));
78
- if (!existsSync(bundle))
79
- throw new Error("This CLI build has no GPU exporter; reinstall @neta-art/cohub-cli.");
80
- const token = randomBytes(16).toString("hex");
81
- const fonts = resources.fonts.map(({ family, path }) => ({ family, path, file: basename(path) }));
82
- const server = createServer(async (request, response) => {
83
- const url = new URL(request.url ?? "/", "http://127.0.0.1");
84
- const [, prefix, ...rest] = url.pathname.split("/");
85
- const route = rest.join("/");
86
- try {
87
- if (prefix !== token)
88
- throw Object.assign(new Error("Not found"), { status: 404 });
89
- if (route === "")
90
- return void response.writeHead(200, { "content-type": "text/html" }).end(PAGE(fonts));
91
- if (route === "page.js")
92
- return void response.writeHead(200, { "content-type": "text/javascript" }).end(await readFile(bundle));
93
- const font = route.startsWith("fonts/") && fonts.find(({ file }) => file === route.slice(6));
94
- if (font)
95
- return void response.writeHead(200, { "content-type": "font/woff2" }).end(await readFile(font.path));
96
- if (route === "module") {
97
- const code = await resources.readModule(url.searchParams.get("path") ?? "");
98
- return void response.writeHead(200, { "content-type": "text/javascript" }).end(code);
99
- }
100
- if (route === "asset") {
101
- const picture = await resources.readPicture(url.searchParams.has("background")
102
- ? { background: true }
103
- : { key: url.searchParams.get("key") ?? "", edge: Number(url.searchParams.get("edge")) || 4096 });
104
- if (!picture)
105
- throw Object.assign(new Error("Not found"), { status: 404 });
106
- return void response.writeHead(200, { "content-type": picture.mimeType }).end(picture.bytes);
107
- }
108
- throw Object.assign(new Error("Not found"), { status: 404 });
109
- }
110
- catch (error) {
111
- response.writeHead(error.status ?? 500).end(error instanceof Error ? error.message : String(error));
112
- }
113
- });
114
- await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
115
- const port = server.address().port;
116
- const profile = await mkdtemp(join(tmpdir(), "cohub-board-gpu-"));
117
- let chrome = null;
118
- const close = async () => {
119
- chrome?.kill();
120
- chrome = null;
121
- await new Promise((resolve) => server.close(() => resolve()));
122
- await rm(profile, { recursive: true, force: true }).catch(() => { });
123
- };
124
- const start = async (sandbox) => {
125
- const child = spawn(options.browser, [
126
- "--headless=new", "--remote-debugging-pipe", `--user-data-dir=${profile}`, "--no-first-run", "--no-default-browser-check",
127
- "--disable-extensions", "--disable-background-networking", "--mute-audio", "--hide-scrollbars", "--enable-unsafe-swiftshader",
128
- ...(sandbox ? [] : ["--no-sandbox"]), "about:blank",
129
- ], { stdio: ["ignore", "ignore", "ignore", "pipe", "pipe"] });
130
- const [, , , input, output] = child.stdio;
131
- const protocol = devtools(input, output);
132
- child.once("exit", () => protocol.fail(new Error("The browser stopped.")));
133
- child.once("error", (error) => protocol.fail(error));
134
- chrome = child;
135
- return { protocol, created: await protocol.send("Target.createTarget", { url: "about:blank" }) };
136
- };
137
- try {
138
- const { protocol, created } = await start(true).catch(() => {
139
- chrome?.kill();
140
- return start(false);
141
- });
142
- options.signal?.addEventListener("abort", () => void close(), { once: true });
143
- const { targetId } = created;
144
- const { sessionId } = await protocol.send("Target.attachToTarget", { targetId, flatten: true });
145
- const page = (method, params) => protocol.send(method, params, sessionId);
146
- let crashed = null;
147
- protocol.listen((message) => {
148
- if (message.sessionId === sessionId && message.method === "Runtime.exceptionThrown")
149
- crashed ??= String(message.params?.exceptionDetails?.exception?.description ?? "The export page failed.");
150
- });
151
- await page("Runtime.enable");
152
- await page("Page.enable");
153
- await page("Page.navigate", { url: `http://127.0.0.1:${port}/${token}/` });
154
- const call = async (expression, timeoutMs = CALL_TIMEOUT_MS) => {
155
- let timer;
156
- const expired = new Promise((_resolve, reject) => {
157
- timer = setTimeout(() => reject(new Error("The GPU exporter stopped responding; a shader may be too heavy to render.")), timeoutMs);
158
- });
159
- const reply = await Promise.race([page("Runtime.evaluate", { expression, awaitPromise: true, returnByValue: true }), expired])
160
- .finally(() => clearTimeout(timer));
161
- if (reply.exceptionDetails)
162
- throw new Error(reply.exceptionDetails.exception?.description?.split("\n")[0] ?? reply.exceptionDetails.text ?? "The export page failed.");
163
- return reply.result?.value;
164
- };
165
- const loaded = () => call("Boolean(globalThis.cohubBoardGpu)", 5_000).catch(() => false);
166
- for (const started = Date.now(); !(await loaded());) {
167
- if (crashed || Date.now() - started > 20_000)
168
- throw new Error(crashed ?? "The GPU exporter did not start.");
169
- await new Promise((resolve) => setTimeout(resolve, 50));
170
- }
171
- return {
172
- browser: options.browser,
173
- async init(init) {
174
- await call(`cohubBoardGpu.init(${JSON.stringify(init)})`);
175
- },
176
- compile: (shaders) => call(`cohubBoardGpu.compile(${JSON.stringify(shaders)})`),
177
- profile: (input) => call(`cohubBoardGpu.profile(${JSON.stringify(input)})`, Math.max(CALL_TIMEOUT_MS, input.budgetMs * 2 + 60_000)),
178
- async render(frame) {
179
- const { data, ...rest } = await call(`cohubBoardGpu.render(${JSON.stringify(frame)})`);
180
- return { ...rest, bytes: new Uint8Array(Buffer.from(data, "base64")) };
181
- },
182
- close,
183
- };
184
- }
185
- catch (error) {
186
- await close();
187
- throw error;
188
- }
189
- }
@@ -1,77 +0,0 @@
1
- import type { BoardDocument } from "@neta-art/cohub";
2
- import type { BoardScriptParameter, BoardScriptSnapshot, BoardShader } from "@neta-art/cohub/board";
3
- import type { BoardExportRegion, BoardThemeId } from "@neta-art/cohub/board";
4
- import type { BoardExportWarning } from "@neta-art/cohub/board/export";
5
- export type BoardGpuInit = {
6
- document: BoardDocument;
7
- animation: string | null;
8
- theme: BoardThemeId;
9
- snapshots?: Record<string, BoardScriptSnapshot>;
10
- };
11
- export type BoardGpuFrame = {
12
- time: number | null;
13
- region: BoardExportRegion;
14
- camera?: {
15
- width: number;
16
- height: number;
17
- };
18
- scale: number;
19
- padding?: number;
20
- background: "paper" | "transparent";
21
- format: "png" | "jpeg" | "webp";
22
- quality?: number;
23
- withImages: boolean;
24
- imageMemory: number;
25
- assetKeys?: Record<string, string>;
26
- };
27
- export type BoardGpuResult = {
28
- data: string;
29
- width: number;
30
- height: number;
31
- scale: number;
32
- itemCount: number;
33
- warnings: BoardExportWarning[];
34
- };
35
- export type BoardGpuShader = {
36
- id: string;
37
- shader: BoardShader;
38
- parameters?: Record<string, BoardScriptParameter>;
39
- };
40
- export type BoardGpuProfileInput = Pick<BoardGpuFrame, "time" | "region" | "camera" | "scale" | "withImages" | "imageMemory"> & {
41
- frames: number;
42
- rounds: number;
43
- budgetMs: number;
44
- };
45
- export type BoardGpuProfile = {
46
- renderer: string;
47
- gpu: "software" | "hardware";
48
- width: number;
49
- height: number;
50
- frames: number;
51
- rounds: number;
52
- reduced: {
53
- width: number;
54
- height: number;
55
- frames: number;
56
- frameMs: number;
57
- } | null;
58
- elapsedMs: number;
59
- frame: {
60
- p50: number;
61
- p95: number;
62
- };
63
- owners: Array<{
64
- id: string;
65
- ms: number;
66
- range: [number, number];
67
- filter: "none" | "always" | "switchable";
68
- sprites: number;
69
- boxes: number;
70
- state: {
71
- width: number;
72
- height: number;
73
- } | null;
74
- }>;
75
- effects: number;
76
- items: number;
77
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,5 +0,0 @@
1
- export { BOARD_SCRIPT_DRAWING_EXAMPLE, BOARD_SCRIPT_RAIN_EXAMPLE, hasBoardScripts, boardAnimatesScriptParams, boardAssetKey, boardAssetKeySource, boardAutoplayLoops, boardMediaRate, boardMediaSpans, boardTimedMedia, boardScriptAttachments, boardShaderParameters, boardFrameRegions, boardRegionStep, createBoardAnimationSampler, boardSequence, boardSequencePatch, boardPathTrack, boardPlacePatch, boardTextureEdge, boardTexturePixels, buildBoardScene, itemBounds, parseBoardDocument, planBoardExport, rectsIntersect, selectBoardExportAssets, } from "@neta-art/cohub/board";
2
- export { describeBoardExportWarning, prepareBoardExport } from "@neta-art/cohub/board/export";
3
- export { boardRenderTheme, checkBoardShader, createBoardRenderSampler, inspectBoardScene, inspectBoardItems, measureBoardText } from "@neta-art/cohub/board/render";
4
- export { createNodeBoardRenderer, createNodeBoardScriptHost, describeBoardScriptLanes, exportBoardImageBytes } from "@neta-art/cohub/board/export/node";
5
- export { createBoardScriptHarness } from "@neta-art/cohub/board/testing";
@@ -1,17 +0,0 @@
1
- import { type BoardMediaSpan, type BoardMediaState } from "@neta-art/cohub/board";
2
- export declare function createBoardMediaFiles(spaceId: string, dir: string, signal?: AbortSignal): {
3
- path(src: string, kind: "video" | "audio"): Promise<string>;
4
- audible(src: string, kind: "video" | "audio"): Promise<boolean>;
5
- duration(src: string): Promise<number>;
6
- };
7
- export type BoardMediaFiles = ReturnType<typeof createBoardMediaFiles>;
8
- export declare function createBoardVideoFrames(files: BoardMediaFiles, dir: string, options: {
9
- fps: number;
10
- signal?: AbortSignal;
11
- }): {
12
- frame(state: BoardMediaState, rate: number, edge: number): Promise<Uint8Array | null>;
13
- };
14
- export declare function boardAudioMix(spans: readonly BoardMediaSpan[], files: BoardMediaFiles, firstInput: number): Promise<{
15
- inputs: string[];
16
- filter: string;
17
- } | null>;