@neta-art/cohub-cli 10.24.0 → 10.25.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (369) hide show
  1. package/bin/cohub.js +4 -1
  2. package/dist/board-gpu/page.js +1566 -71230
  3. package/dist/bootstrap.js +67 -27
  4. package/dist/build.json +1 -1
  5. package/dist/{board-kernel/FilterPipe.js → chunks/Geometry.js} +10447 -10469
  6. package/dist/chunks/about.js +102 -0
  7. package/dist/chunks/app-realtime.js +2216 -0
  8. package/dist/chunks/app-realtime2.js +2 -0
  9. package/dist/chunks/app-ref.js +88 -0
  10. package/dist/chunks/apps.js +1423 -0
  11. package/dist/chunks/auth.js +175 -0
  12. package/dist/chunks/avatar.js +146 -0
  13. package/dist/chunks/binary-pins.js +5 -0
  14. package/dist/chunks/board-export-resources.js +232 -0
  15. package/dist/chunks/board-export.js +874 -0
  16. package/dist/chunks/board-export2.js +2 -0
  17. package/dist/{board-kernel.js → chunks/board-kernel.js} +18032 -28512
  18. package/dist/chunks/board-kernel2.js +4 -0
  19. package/dist/chunks/board-profile.js +69 -0
  20. package/dist/chunks/board-simulate.js +315 -0
  21. package/dist/chunks/board-time.js +34 -0
  22. package/dist/chunks/boards.js +1943 -0
  23. package/dist/{board-kernel → chunks}/browserAll.js +9 -8
  24. package/dist/chunks/channels.js +64 -0
  25. package/dist/chunks/client.js +12606 -0
  26. package/dist/chunks/command-input.js +17 -0
  27. package/dist/chunks/commander.js +2962 -0
  28. package/dist/chunks/cron-jobs.js +163 -0
  29. package/dist/chunks/daemon.js +545 -0
  30. package/dist/chunks/daemon2.js +2 -0
  31. package/dist/chunks/desktop.js +172 -0
  32. package/dist/chunks/endpoint-options.js +26 -0
  33. package/dist/chunks/env-proxy.js +35 -0
  34. package/dist/chunks/environment.js +154 -0
  35. package/dist/chunks/feedback.js +120 -0
  36. package/dist/chunks/generations.js +379 -0
  37. package/dist/chunks/host.js +9 -0
  38. package/dist/chunks/http-put.js +131 -0
  39. package/dist/chunks/id.js +2416 -0
  40. package/dist/{board-kernel → chunks}/init.js +1 -1
  41. package/dist/chunks/install.js +11959 -0
  42. package/dist/chunks/launch.js +374 -0
  43. package/dist/chunks/local-media.js +47 -0
  44. package/dist/chunks/me.js +134 -0
  45. package/dist/chunks/media.js +315 -0
  46. package/dist/chunks/models.js +242 -0
  47. package/dist/chunks/operands.js +46 -0
  48. package/dist/chunks/package-paths.js +13 -0
  49. package/dist/chunks/policy.js +221 -0
  50. package/dist/chunks/preferences.js +29 -0
  51. package/dist/chunks/profile.js +64 -0
  52. package/dist/chunks/prompts.js +41 -0
  53. package/dist/chunks/public.js +2 -0
  54. package/dist/chunks/public2.js +244 -0
  55. package/dist/chunks/references.js +197 -0
  56. package/dist/chunks/referrals.js +90 -0
  57. package/dist/chunks/rolldown-runtime.js +26 -0
  58. package/dist/chunks/rooms-connect.js +2 -0
  59. package/dist/chunks/rooms-connect2.js +151 -0
  60. package/dist/chunks/rooms-rtc.js +311 -0
  61. package/dist/chunks/rooms.js +211 -0
  62. package/dist/chunks/run.js +220 -0
  63. package/dist/chunks/runtime.js +638 -0
  64. package/dist/chunks/runtime2.js +286 -0
  65. package/dist/chunks/runtimes.js +48 -0
  66. package/dist/chunks/safe-remote-image.js +198 -0
  67. package/dist/chunks/schemas.js +6017 -0
  68. package/dist/chunks/search.js +113 -0
  69. package/dist/chunks/self-update.js +238 -0
  70. package/dist/chunks/serve.js +1246 -0
  71. package/dist/chunks/session-status.js +24 -0
  72. package/dist/chunks/skills.js +35 -0
  73. package/dist/chunks/spaces.js +5080 -0
  74. package/dist/chunks/src.js +405 -0
  75. package/dist/chunks/supervisor.js +2513 -0
  76. package/dist/chunks/supervisor2.js +2 -0
  77. package/dist/chunks/tasks.js +82 -0
  78. package/dist/chunks/themes.js +2898 -0
  79. package/dist/chunks/version.js +2 -0
  80. package/dist/chunks/version2.js +22 -0
  81. package/dist/chunks/version3.js +18 -0
  82. package/dist/chunks/web.js +7 -0
  83. package/dist/{board-kernel → chunks}/webworkerAll.js +1 -1
  84. package/dist/runtime/native/pi-extension.js +174 -166
  85. package/dist/runtime/worker.js +27 -16
  86. package/package.json +8 -9
  87. package/dist/about.d.ts +0 -2
  88. package/dist/about.js +0 -71
  89. package/dist/app-download.d.ts +0 -11
  90. package/dist/app-download.js +0 -252
  91. package/dist/app-ref.d.ts +0 -5
  92. package/dist/app-ref.js +0 -8
  93. package/dist/app-target.d.ts +0 -26
  94. package/dist/app-target.js +0 -55
  95. package/dist/auth.d.ts +0 -45
  96. package/dist/auth.js +0 -307
  97. package/dist/avatar.d.ts +0 -55
  98. package/dist/avatar.js +0 -104
  99. package/dist/board-command-support.d.ts +0 -6
  100. package/dist/board-command-support.js +0 -88
  101. package/dist/board-export-resources.d.ts +0 -12
  102. package/dist/board-export-resources.js +0 -51
  103. package/dist/board-export.d.ts +0 -110
  104. package/dist/board-export.js +0 -592
  105. package/dist/board-fonts.d.ts +0 -11
  106. package/dist/board-fonts.js +0 -10
  107. package/dist/board-gpu/daemon.d.ts +0 -11
  108. package/dist/board-gpu/daemon.js +0 -295
  109. package/dist/board-gpu/index.d.ts +0 -33
  110. package/dist/board-gpu/index.js +0 -189
  111. package/dist/board-gpu/protocol.d.ts +0 -77
  112. package/dist/board-gpu/protocol.js +0 -1
  113. package/dist/board-kernel.d.ts +0 -5
  114. package/dist/board-media-export.d.ts +0 -17
  115. package/dist/board-media-export.js +0 -164
  116. package/dist/board-media.d.ts +0 -5
  117. package/dist/board-media.js +0 -66
  118. package/dist/board-profile.d.ts +0 -21
  119. package/dist/board-profile.js +0 -67
  120. package/dist/board-simulate.d.ts +0 -67
  121. package/dist/board-simulate.js +0 -259
  122. package/dist/board-time.d.ts +0 -3
  123. package/dist/board-time.js +0 -34
  124. package/dist/bootstrap.d.ts +0 -2
  125. package/dist/client.d.ts +0 -5
  126. package/dist/client.js +0 -24
  127. package/dist/command-input.d.ts +0 -4
  128. package/dist/command-input.js +0 -16
  129. package/dist/commands/app-commerce.d.ts +0 -2
  130. package/dist/commands/app-commerce.js +0 -228
  131. package/dist/commands/app-domains.d.ts +0 -2
  132. package/dist/commands/app-domains.js +0 -133
  133. package/dist/commands/apps.d.ts +0 -4
  134. package/dist/commands/apps.js +0 -827
  135. package/dist/commands/auth.d.ts +0 -2
  136. package/dist/commands/auth.js +0 -186
  137. package/dist/commands/boards/authoring.d.ts +0 -2
  138. package/dist/commands/boards/authoring.js +0 -166
  139. package/dist/commands/boards/examples.d.ts +0 -10
  140. package/dist/commands/boards/examples.js +0 -118
  141. package/dist/commands/boards.d.ts +0 -13
  142. package/dist/commands/boards.js +0 -836
  143. package/dist/commands/channels.d.ts +0 -2
  144. package/dist/commands/channels.js +0 -74
  145. package/dist/commands/cron-jobs.d.ts +0 -2
  146. package/dist/commands/cron-jobs.js +0 -155
  147. package/dist/commands/decision.d.ts +0 -4
  148. package/dist/commands/decision.js +0 -113
  149. package/dist/commands/desktop.d.ts +0 -10
  150. package/dist/commands/desktop.js +0 -233
  151. package/dist/commands/feedback.d.ts +0 -2
  152. package/dist/commands/feedback.js +0 -131
  153. package/dist/commands/generations.d.ts +0 -2
  154. package/dist/commands/generations.js +0 -427
  155. package/dist/commands/host.d.ts +0 -2
  156. package/dist/commands/host.js +0 -11
  157. package/dist/commands/me.d.ts +0 -2
  158. package/dist/commands/me.js +0 -121
  159. package/dist/commands/models.d.ts +0 -28
  160. package/dist/commands/models.js +0 -271
  161. package/dist/commands/profile.d.ts +0 -2
  162. package/dist/commands/profile.js +0 -81
  163. package/dist/commands/prompts.d.ts +0 -2
  164. package/dist/commands/prompts.js +0 -37
  165. package/dist/commands/public.d.ts +0 -20
  166. package/dist/commands/public.js +0 -291
  167. package/dist/commands/references.d.ts +0 -2
  168. package/dist/commands/references.js +0 -193
  169. package/dist/commands/referrals.d.ts +0 -2
  170. package/dist/commands/referrals.js +0 -88
  171. package/dist/commands/rooms-connect.d.ts +0 -17
  172. package/dist/commands/rooms-connect.js +0 -140
  173. package/dist/commands/rooms-rtc-binary.d.ts +0 -2
  174. package/dist/commands/rooms-rtc-binary.js +0 -107
  175. package/dist/commands/rooms-rtc.d.ts +0 -21
  176. package/dist/commands/rooms-rtc.js +0 -171
  177. package/dist/commands/rooms.d.ts +0 -3
  178. package/dist/commands/rooms.js +0 -277
  179. package/dist/commands/run.d.ts +0 -13
  180. package/dist/commands/run.js +0 -246
  181. package/dist/commands/runtime.d.ts +0 -3
  182. package/dist/commands/runtime.js +0 -320
  183. package/dist/commands/sandboxd-binary.d.ts +0 -11
  184. package/dist/commands/sandboxd-binary.js +0 -238
  185. package/dist/commands/search.d.ts +0 -2
  186. package/dist/commands/search.js +0 -114
  187. package/dist/commands/session-access.d.ts +0 -2
  188. package/dist/commands/session-access.js +0 -70
  189. package/dist/commands/skills.d.ts +0 -2
  190. package/dist/commands/skills.js +0 -34
  191. package/dist/commands/space-activity.d.ts +0 -26
  192. package/dist/commands/space-activity.js +0 -147
  193. package/dist/commands/space-commerce.d.ts +0 -2
  194. package/dist/commands/space-commerce.js +0 -514
  195. package/dist/commands/space-displays.d.ts +0 -2
  196. package/dist/commands/space-displays.js +0 -620
  197. package/dist/commands/space-files.d.ts +0 -5
  198. package/dist/commands/space-files.js +0 -215
  199. package/dist/commands/space-invitations.d.ts +0 -29
  200. package/dist/commands/space-invitations.js +0 -189
  201. package/dist/commands/space-turns.d.ts +0 -49
  202. package/dist/commands/space-turns.js +0 -205
  203. package/dist/commands/space-wallet.d.ts +0 -2
  204. package/dist/commands/space-wallet.js +0 -141
  205. package/dist/commands/space-webhooks.d.ts +0 -7
  206. package/dist/commands/space-webhooks.js +0 -73
  207. package/dist/commands/spaces.d.ts +0 -25
  208. package/dist/commands/spaces.js +0 -2170
  209. package/dist/commands/tasks.d.ts +0 -8
  210. package/dist/commands/tasks.js +0 -80
  211. package/dist/commands/version.d.ts +0 -2
  212. package/dist/commands/version.js +0 -21
  213. package/dist/endpoint-options.d.ts +0 -4
  214. package/dist/endpoint-options.js +0 -26
  215. package/dist/env-proxy.d.ts +0 -5
  216. package/dist/env-proxy.js +0 -20
  217. package/dist/help-path.d.ts +0 -18
  218. package/dist/help-path.js +0 -223
  219. package/dist/host/auth.d.ts +0 -20
  220. package/dist/host/auth.js +0 -119
  221. package/dist/host/login-env.d.ts +0 -1
  222. package/dist/host/login-env.js +0 -31
  223. package/dist/host/runtime.d.ts +0 -35
  224. package/dist/host/runtime.js +0 -395
  225. package/dist/host/runtimes.d.ts +0 -9
  226. package/dist/host/runtimes.js +0 -42
  227. package/dist/host/serve.d.ts +0 -2
  228. package/dist/host/serve.js +0 -117
  229. package/dist/host/workspaces.d.ts +0 -2
  230. package/dist/host/workspaces.js +0 -18
  231. package/dist/http-put.d.ts +0 -25
  232. package/dist/http-put.js +0 -132
  233. package/dist/index.d.ts +0 -2
  234. package/dist/index.js +0 -129
  235. package/dist/launcher.d.ts +0 -4
  236. package/dist/launcher.js +0 -38
  237. package/dist/local-media.d.ts +0 -2
  238. package/dist/local-media.js +0 -30
  239. package/dist/network-error.d.ts +0 -3
  240. package/dist/network-error.js +0 -22
  241. package/dist/output.d.ts +0 -46
  242. package/dist/output.js +0 -244
  243. package/dist/runtime/archive-store.d.ts +0 -54
  244. package/dist/runtime/archive-store.js +0 -379
  245. package/dist/runtime/cli-path.d.ts +0 -5
  246. package/dist/runtime/cli-path.js +0 -27
  247. package/dist/runtime/codex-usage.d.ts +0 -7
  248. package/dist/runtime/codex-usage.js +0 -11
  249. package/dist/runtime/connection.d.ts +0 -42
  250. package/dist/runtime/connection.js +0 -789
  251. package/dist/runtime/diagnostics.d.ts +0 -107
  252. package/dist/runtime/diagnostics.js +0 -392
  253. package/dist/runtime/harnesses/chained-projection.d.ts +0 -40
  254. package/dist/runtime/harnesses/chained-projection.js +0 -95
  255. package/dist/runtime/harnesses/chained-transcript.d.ts +0 -24
  256. package/dist/runtime/harnesses/chained-transcript.js +0 -62
  257. package/dist/runtime/harnesses/claude-approval.d.ts +0 -34
  258. package/dist/runtime/harnesses/claude-approval.js +0 -124
  259. package/dist/runtime/harnesses/claude-transcript.d.ts +0 -8
  260. package/dist/runtime/harnesses/claude-transcript.js +0 -138
  261. package/dist/runtime/harnesses/claude.d.ts +0 -8
  262. package/dist/runtime/harnesses/claude.js +0 -225
  263. package/dist/runtime/harnesses/codex-approval.d.ts +0 -25
  264. package/dist/runtime/harnesses/codex-approval.js +0 -69
  265. package/dist/runtime/harnesses/codex.d.ts +0 -4
  266. package/dist/runtime/harnesses/codex.js +0 -269
  267. package/dist/runtime/harnesses/cursor-transcript.d.ts +0 -37
  268. package/dist/runtime/harnesses/cursor-transcript.js +0 -183
  269. package/dist/runtime/harnesses/cursor.d.ts +0 -24
  270. package/dist/runtime/harnesses/cursor.js +0 -620
  271. package/dist/runtime/harnesses/index.d.ts +0 -16
  272. package/dist/runtime/harnesses/index.js +0 -73
  273. package/dist/runtime/harnesses/pi.d.ts +0 -4
  274. package/dist/runtime/harnesses/pi.js +0 -247
  275. package/dist/runtime/harnesses/process.d.ts +0 -31
  276. package/dist/runtime/harnesses/process.js +0 -75
  277. package/dist/runtime/harnesses/stream-json.d.ts +0 -48
  278. package/dist/runtime/harnesses/stream-json.js +0 -336
  279. package/dist/runtime/harnesses/types.d.ts +0 -117
  280. package/dist/runtime/harnesses/types.js +0 -1
  281. package/dist/runtime/harnesses/workbuddy-transcript.d.ts +0 -8
  282. package/dist/runtime/harnesses/workbuddy-transcript.js +0 -127
  283. package/dist/runtime/harnesses/workbuddy.d.ts +0 -21
  284. package/dist/runtime/harnesses/workbuddy.js +0 -123
  285. package/dist/runtime/instance.d.ts +0 -20
  286. package/dist/runtime/instance.js +0 -247
  287. package/dist/runtime/json-rpc.d.ts +0 -53
  288. package/dist/runtime/json-rpc.js +0 -212
  289. package/dist/runtime/launch.d.ts +0 -25
  290. package/dist/runtime/launch.js +0 -247
  291. package/dist/runtime/local-workspace.d.ts +0 -15
  292. package/dist/runtime/local-workspace.js +0 -52
  293. package/dist/runtime/model-catalog.d.ts +0 -12
  294. package/dist/runtime/model-catalog.js +0 -84
  295. package/dist/runtime/native/adapters.d.ts +0 -15
  296. package/dist/runtime/native/adapters.js +0 -11
  297. package/dist/runtime/native/approvals.d.ts +0 -18
  298. package/dist/runtime/native/approvals.js +0 -54
  299. package/dist/runtime/native/archive.d.ts +0 -19
  300. package/dist/runtime/native/archive.js +0 -142
  301. package/dist/runtime/native/attach.d.ts +0 -36
  302. package/dist/runtime/native/attach.js +0 -128
  303. package/dist/runtime/native/codex-link.d.ts +0 -60
  304. package/dist/runtime/native/codex-link.js +0 -322
  305. package/dist/runtime/native/config.d.ts +0 -16
  306. package/dist/runtime/native/config.js +0 -24
  307. package/dist/runtime/native/daemon.d.ts +0 -92
  308. package/dist/runtime/native/daemon.js +0 -380
  309. package/dist/runtime/native/execution.d.ts +0 -26
  310. package/dist/runtime/native/execution.js +0 -34
  311. package/dist/runtime/native/identity.d.ts +0 -9
  312. package/dist/runtime/native/identity.js +0 -15
  313. package/dist/runtime/native/ingest.d.ts +0 -263
  314. package/dist/runtime/native/ingest.js +0 -884
  315. package/dist/runtime/native/install.d.ts +0 -9
  316. package/dist/runtime/native/install.js +0 -113
  317. package/dist/runtime/native/paths.d.ts +0 -2
  318. package/dist/runtime/native/paths.js +0 -7
  319. package/dist/runtime/native/pi-extension.d.ts +0 -36
  320. package/dist/runtime/native/pi-link.d.ts +0 -69
  321. package/dist/runtime/native/pi-link.js +0 -269
  322. package/dist/runtime/native/results.d.ts +0 -41
  323. package/dist/runtime/native/results.js +0 -128
  324. package/dist/runtime/native/sessions.d.ts +0 -45
  325. package/dist/runtime/native/sessions.js +0 -87
  326. package/dist/runtime/native/transcript.d.ts +0 -89
  327. package/dist/runtime/native/transcript.js +0 -656
  328. package/dist/runtime/native/translate.d.ts +0 -46
  329. package/dist/runtime/native/translate.js +0 -299
  330. package/dist/runtime/native/transport.d.ts +0 -7
  331. package/dist/runtime/native/transport.js +0 -16
  332. package/dist/runtime/native/version.d.ts +0 -5
  333. package/dist/runtime/native/version.js +0 -21
  334. package/dist/runtime/preferences.d.ts +0 -7
  335. package/dist/runtime/preferences.js +0 -22
  336. package/dist/runtime/presentation.d.ts +0 -32
  337. package/dist/runtime/presentation.js +0 -124
  338. package/dist/runtime/process-group.d.ts +0 -5
  339. package/dist/runtime/process-group.js +0 -161
  340. package/dist/runtime/projection-store.d.ts +0 -27
  341. package/dist/runtime/projection-store.js +0 -30
  342. package/dist/runtime/space-binding.d.ts +0 -48
  343. package/dist/runtime/space-binding.js +0 -342
  344. package/dist/runtime/supervisor.d.ts +0 -19
  345. package/dist/runtime/supervisor.js +0 -441
  346. package/dist/runtime/turn-projection.d.ts +0 -41
  347. package/dist/runtime/turn-projection.js +0 -120
  348. package/dist/runtime/worker.d.ts +0 -1
  349. package/dist/safe-remote-image.d.ts +0 -36
  350. package/dist/safe-remote-image.js +0 -191
  351. package/dist/self-update.d.ts +0 -7
  352. package/dist/self-update.js +0 -202
  353. package/dist/session-status.d.ts +0 -10
  354. package/dist/session-status.js +0 -25
  355. package/dist/space-files/limit.d.ts +0 -2
  356. package/dist/space-files/limit.js +0 -16
  357. package/dist/space-files/operands.d.ts +0 -17
  358. package/dist/space-files/operands.js +0 -33
  359. package/dist/space-files/transfer.d.ts +0 -53
  360. package/dist/space-files/transfer.js +0 -297
  361. package/dist/space-files/upload.d.ts +0 -17
  362. package/dist/space-files/upload.js +0 -76
  363. package/dist/space.d.ts +0 -44
  364. package/dist/space.js +0 -192
  365. package/dist/version.d.ts +0 -2
  366. package/dist/version.js +0 -17
  367. package/dist/web.d.ts +0 -1
  368. package/dist/web.js +0 -4
  369. /package/dist/{board-kernel → chunks}/lexer.js +0 -0
@@ -1,164 +0,0 @@
1
- import { execFile as execFileCallback } from "node:child_process";
2
- import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
3
- import { join } from "node:path";
4
- import { promisify } from "node:util";
5
- import { parseBoardMediaSource } from "@neta-art/cohub/board";
6
- import { createClient } from "./client.js";
7
- import { downloadPublicAudio, downloadPublicVideo } from "./safe-remote-image.js";
8
- const execFile = promisify(execFileCallback);
9
- const CHUNK_SECONDS = 4;
10
- const MAX_DECODE_FPS = 60;
11
- async function ffmpeg(args, signal) {
12
- try {
13
- return await execFile("ffmpeg", ["-v", "error", ...args], { encoding: "utf8", maxBuffer: 2 * 1024 * 1024, signal });
14
- }
15
- catch (error) {
16
- const cause = error;
17
- if (cause.code === "ENOENT")
18
- throw new Error("Exporting video and audio needs ffmpeg. Install ffmpeg and try again.");
19
- throw new Error(`ffmpeg failed: ${(cause.stderr ?? cause.message ?? "unknown error").trim().split("\n").slice(-4).join("\n")}`);
20
- }
21
- }
22
- export function createBoardMediaFiles(spaceId, dir, signal) {
23
- const files = new Map();
24
- const audible = new Map();
25
- const durations = new Map();
26
- const client = createClient();
27
- return {
28
- path(src, kind) {
29
- let pending = files.get(src);
30
- if (!pending) {
31
- const path = join(dir, `media-${files.size}`);
32
- pending = (async () => {
33
- const source = parseBoardMediaSource(src);
34
- if (!source)
35
- throw new Error(`Invalid media source ${src}`);
36
- const { bytes } = source.kind === "file"
37
- ? { bytes: new Uint8Array(await (await client.space(spaceId).files.download(source.value)).blob.arrayBuffer()) }
38
- : await (kind === "video" ? downloadPublicVideo : downloadPublicAudio)(source.value);
39
- await writeFile(path, bytes);
40
- return path;
41
- })();
42
- files.set(src, pending);
43
- }
44
- return pending;
45
- },
46
- async audible(src, kind) {
47
- let pending = audible.get(src);
48
- if (!pending) {
49
- pending = this.path(src, kind).then(async (path) => {
50
- const { stdout } = await execFile("ffprobe", ["-v", "error", "-select_streams", "a", "-show_entries", "stream=index", "-of", "csv=p=0", path], { signal });
51
- return stdout.trim().length > 0;
52
- });
53
- audible.set(src, pending);
54
- }
55
- return pending;
56
- },
57
- async duration(src) {
58
- let pending = durations.get(src);
59
- if (!pending) {
60
- pending = this.path(src, "video").then(async (path) => {
61
- const { stdout } = await execFile("ffprobe", ["-v", "error", "-show_entries", "format=duration", "-of", "csv=p=0", path], { signal });
62
- return Math.max(0, Number(stdout.trim()) * 1000 || 0);
63
- }).catch(() => 0);
64
- durations.set(src, pending);
65
- }
66
- return pending;
67
- },
68
- };
69
- }
70
- export function createBoardVideoFrames(files, dir, options) {
71
- const chunks = new Map();
72
- let decoded = 0;
73
- function lookup(chunk, time, edge) {
74
- if (!chunk || edge > chunk.edge)
75
- return null;
76
- const index = chunk.count === 1 ? (Math.abs(time - chunk.start) < 1 ? 0 : -1) : Math.round(((time - chunk.start) * chunk.fps) / 1000);
77
- return index >= 0 && index < chunk.count ? join(chunk.dir, `${String(index + 1).padStart(5, "0")}.jpg`) : null;
78
- }
79
- async function decode(state, rate, edge) {
80
- const path = await files.path(state.src, "video");
81
- const previous = chunks.get(state.id);
82
- if (previous)
83
- await rm(previous.dir, { recursive: true, force: true });
84
- const chunkDir = join(dir, `frames-${decoded++}`);
85
- await mkdir(chunkDir);
86
- const fps = rate > 0 ? Math.min(MAX_DECODE_FPS, Math.max(1, Math.ceil(options.fps * rate))) : 0;
87
- const scale = `scale=w=${edge}:h=${edge}:force_original_aspect_ratio=decrease`;
88
- await ffmpeg([
89
- "-ss", (state.time / 1000).toFixed(3), "-i", path,
90
- ...(fps ? ["-t", String(CHUNK_SECONDS), "-vf", `fps=${fps},${scale}`] : ["-frames:v", "1", "-vf", scale]),
91
- "-q:v", "3", join(chunkDir, "%05d.jpg"),
92
- ], options.signal);
93
- const count = fps ? Math.max(1, Math.round(CHUNK_SECONDS * fps)) : 1;
94
- const chunk = { src: state.src, start: state.time, fps: fps || 1, count, edge, dir: chunkDir };
95
- chunks.set(state.id, chunk);
96
- return chunk;
97
- }
98
- return {
99
- async frame(state, rate, edge) {
100
- if (state.loop) {
101
- const duration = await files.duration(state.src);
102
- if (duration > 0)
103
- state = { ...state, time: state.time % duration };
104
- }
105
- const current = chunks.get(state.id);
106
- let file = current?.src === state.src ? lookup(current, state.time, edge) : null;
107
- if (!file)
108
- file = lookup(await decode(state, rate, edge), state.time, edge);
109
- return file ? new Uint8Array(await readFile(file).catch(() => Buffer.alloc(0))) : null;
110
- },
111
- };
112
- }
113
- function volumeExpression(span) {
114
- const points = span.volume.map((point) => ({ t: (point.at - span.start) / 1000, v: point.value }));
115
- if (points.every((point) => point.v === points[0]?.v))
116
- return String(points[0]?.v ?? 1);
117
- let expression = String(points.at(-1)?.v ?? 1);
118
- for (let index = points.length - 2; index >= 0; index -= 1) {
119
- const a = points[index];
120
- const b = points[index + 1];
121
- const slope = b.t > a.t ? (b.v - a.v) / (b.t - a.t) : 0;
122
- expression = `if(lt(t,${b.t.toFixed(4)}),${a.v.toFixed(4)}+${slope.toFixed(6)}*(t-${a.t.toFixed(4)}),${expression})`;
123
- }
124
- return `'${expression}'`;
125
- }
126
- function tempo(rate) {
127
- const stages = [];
128
- let rest = rate;
129
- while (rest > 2) {
130
- stages.push("atempo=2");
131
- rest /= 2;
132
- }
133
- while (rest < 0.5) {
134
- stages.push("atempo=0.5");
135
- rest /= 0.5;
136
- }
137
- if (Math.abs(rest - 1) > 1e-4)
138
- stages.push(`atempo=${rest.toFixed(6)}`);
139
- return stages;
140
- }
141
- export async function boardAudioMix(spans, files, firstInput) {
142
- const inputs = [];
143
- const chains = [];
144
- for (const span of spans) {
145
- if (!(await files.audible(span.src, span.kind)))
146
- continue;
147
- const index = firstInput + chains.length;
148
- inputs.push("-i", await files.path(span.src, span.kind));
149
- const length = ((span.end - span.start) * span.rate) / 1000;
150
- const delay = Math.max(0, Math.round(span.start));
151
- const filters = [
152
- `atrim=start=${(span.from / 1000).toFixed(4)}:duration=${length.toFixed(4)}`,
153
- "asetpts=PTS-STARTPTS",
154
- ...tempo(span.rate),
155
- `volume=${volumeExpression(span)}:eval=frame`,
156
- `adelay=${delay}:all=1`,
157
- ];
158
- chains.push(`[${index}:a]${filters.join(",")}[a${chains.length}]`);
159
- }
160
- if (!chains.length)
161
- return null;
162
- const mixed = chains.map((_, index) => `[a${index}]`).join("");
163
- return { inputs, filter: `${chains.join(";")};${mixed}amix=inputs=${chains.length}:duration=longest:dropout_transition=0:normalize=0[aout]` };
164
- }
@@ -1,5 +0,0 @@
1
- import { type BoardDocument, type BoardItem, type BoardMediaFileResolver } from "@neta-art/cohub/board";
2
- export declare function boardMediaFileResolver(spaceId: string): BoardMediaFileResolver;
3
- export declare function settleBoardDocument(spaceId: string, document: BoardDocument): Promise<BoardDocument>;
4
- export declare function settleBoardPatch<T extends Record<string, unknown>>(spaceId: string, patch: T, current: (ids: string[]) => Promise<Record<string, unknown> | null>): Promise<T>;
5
- export declare function settleBoardMediaDurations(spaceId: string, document: BoardDocument, ids: readonly string[]): Promise<Record<string, BoardItem>>;
@@ -1,66 +0,0 @@
1
- import { execFile } from "node:child_process";
2
- import { resolve } from "node:path";
3
- import { promisify } from "node:util";
4
- import { diffMergePatch, mergePatch, parseBoardItem, settleBoardMediaSizes, } from "@neta-art/cohub/board";
5
- import { createClient } from "./client.js";
6
- import { localMediaFacts } from "./local-media.js";
7
- import { WORKSPACE_ROOT } from "./space-files/operands.js";
8
- const isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
9
- export function boardMediaFileResolver(spaceId) {
10
- const local = process.env.COHUB_SPACE_ID === spaceId;
11
- return async (path, type, signal) => {
12
- const file = resolve(WORKSPACE_ROOT, path);
13
- const facts = local && file.startsWith(`${WORKSPACE_ROOT}/`) ? await localMediaFacts(file, type, signal) : null;
14
- const resolved = facts ? null : await createClient().space(spaceId).files.resolve(path, { purpose: "playback", signal }).catch(() => null);
15
- const size = facts ?? resolved?.media;
16
- return size ? { width: size.width, height: size.height } : (resolved?.url ?? null);
17
- };
18
- }
19
- export async function settleBoardDocument(spaceId, document) {
20
- const settled = await settleBoardMediaSizes(document.items, { resolveFile: boardMediaFileResolver(spaceId) });
21
- return Object.keys(settled).length ? { ...document, items: { ...document.items, ...settled } } : document;
22
- }
23
- export async function settleBoardPatch(spaceId, patch, current) {
24
- const items = isRecord(patch.items) ? patch.items : {};
25
- const created = {};
26
- for (const [id, value] of Object.entries(items)) {
27
- if (!isRecord(value) || (value.type !== "image" && value.type !== "video"))
28
- continue;
29
- const parsed = parseBoardItem(value, `items.${id}`);
30
- if (parsed.ok)
31
- created[id] = parsed.item;
32
- }
33
- const existing = Object.keys(created).length ? await current(Object.keys(created)) : null;
34
- if (!existing)
35
- return patch;
36
- for (const [id, item] of Object.entries(existing)) {
37
- if (isRecord(item) && item.type === created[id]?.type)
38
- delete created[id];
39
- }
40
- const settled = await settleBoardMediaSizes(created, { resolveFile: boardMediaFileResolver(spaceId) });
41
- if (!Object.keys(settled).length)
42
- return patch;
43
- const adopted = Object.entries(settled).map(([id, item]) => [id, mergePatch(items[id], diffMergePatch(created[id], item))]);
44
- return { ...patch, items: { ...items, ...Object.fromEntries(adopted) } };
45
- }
46
- const run = promisify(execFile);
47
- export async function settleBoardMediaDurations(spaceId, document, ids) {
48
- const local = process.env.COHUB_SPACE_ID === spaceId;
49
- const settled = {};
50
- for (const id of ids) {
51
- const item = document.items[id];
52
- if ((item?.type !== "video" && item?.type !== "audio") || item.props.snapshot?.durationMs)
53
- continue;
54
- const file = item.props.src.startsWith("http") ? null : resolve(WORKSPACE_ROOT, item.props.src);
55
- const input = file && local && file.startsWith(`${WORKSPACE_ROOT}/`)
56
- ? file
57
- : file ? (await createClient().space(spaceId).files.resolve(item.props.src, { purpose: "playback" }).catch(() => null))?.url : null;
58
- const seconds = input
59
- ? Number((await run("ffprobe", ["-v", "error", "-show_entries", "format=duration", "-of", "csv=p=0", input], { timeout: 15_000 }).catch(() => ({ stdout: "" }))).stdout)
60
- : Number.NaN;
61
- if (!(seconds > 0))
62
- throw new Error(`The length of ${id} is unknown; pass --duration.`);
63
- settled[id] = { ...item, props: { ...item.props, snapshot: { ...item.props.snapshot, durationMs: Math.round(seconds * 1000) } } };
64
- }
65
- return settled;
66
- }
@@ -1,21 +0,0 @@
1
- import { type BoardDocument, type BoardExportRegion } from "@neta-art/cohub/board";
2
- import { type BoardGpuProfile } from "./board-gpu/index.js";
3
- export type BoardProfile = BoardGpuProfile & {
4
- hints: string[];
5
- };
6
- export declare function profileBoard(options: {
7
- spaceId: string;
8
- target: string;
9
- time: number;
10
- animation?: string;
11
- region: BoardExportRegion;
12
- size: {
13
- width: number;
14
- height: number;
15
- };
16
- frames: number;
17
- rounds: number;
18
- budgetMs: number;
19
- withImages: boolean;
20
- }): Promise<BoardProfile>;
21
- export declare function boardProfileHints(document: BoardDocument, profile: BoardGpuProfile): string[];
@@ -1,67 +0,0 @@
1
- import { boardModelFormat } from "@neta-art/cohub/board";
2
- import { gpuResources, loadBoardDocument } from "./board-export.js";
3
- import { openBoardGpu } from "./board-gpu/daemon.js";
4
- import { findBoardGpuBrowser } from "./board-gpu/index.js";
5
- import { BOARD_EXPORT_IMAGE_MEMORY_MIB } from "./board-export-resources.js";
6
- import { buildBoardScene, planBoardExport } from "./board-kernel.js";
7
- import { settleBoardDocument } from "./board-media.js";
8
- const LARGE_OWNER = 4000;
9
- const LARGE_STATE = 512 * 512;
10
- const MANY_EFFECTS = 16;
11
- const LARGE_MODEL = 8 * 1024 ** 2;
12
- export async function profileBoard(options) {
13
- const browser = findBoardGpuBrowser();
14
- if (!browser)
15
- throw new Error("Profiling needs Chrome, Chromium or Edge. Install one, or set COHUB_CHROME to its path.");
16
- const document = await settleBoardDocument(options.spaceId, (await loadBoardDocument(options.spaceId, options.target)).document);
17
- if (options.animation && !document.animations[options.animation])
18
- throw new Error(`Animation ${options.animation} does not exist.`);
19
- const plan = planBoardExport({ scene: buildBoardScene(document), region: options.region, scale: 1, padding: 0 });
20
- if (!plan)
21
- throw new Error("Nothing to profile: the region contains no items.");
22
- const scale = Math.min(options.size.width / plan.world.width, options.size.height / plan.world.height);
23
- const gpu = await openBoardGpu(gpuResources(options.spaceId, document), { browser });
24
- try {
25
- await gpu.init({ document, animation: options.animation ?? null, theme: "dark" });
26
- const profile = await gpu.profile({
27
- time: options.time,
28
- region: options.region,
29
- scale,
30
- frames: options.frames,
31
- rounds: options.rounds,
32
- budgetMs: options.budgetMs,
33
- withImages: options.withImages,
34
- imageMemory: BOARD_EXPORT_IMAGE_MEMORY_MIB * 1024 ** 2,
35
- });
36
- return { ...profile, hints: boardProfileHints(document, profile) };
37
- }
38
- finally {
39
- await gpu.close();
40
- }
41
- }
42
- export function boardProfileHints(document, profile) {
43
- const hints = [];
44
- const share = (ms) => (profile.frame.p50 > 0 ? ms / profile.frame.p50 : 0);
45
- for (const owner of profile.owners) {
46
- if (owner.filter === "always" && share(owner.ms) > 0.1)
47
- hints.push(`${owner.id} redraws everything under it through a filter every frame; name its filter passes and turn them on with ctx.passes() only while they show.`);
48
- const item = document.items[owner.id];
49
- if (item && "size" in item && Math.max(item.size.width, item.size.height) > LARGE_OWNER)
50
- hints.push(`${owner.id} is larger than any view, so its shaders never leave the screen; a Board script, or shaders on the smaller items, draw only what shows.`);
51
- if (owner.boxes && share(owner.ms) > 0.1)
52
- hints.push(`${owner.id} shades every pixel of its box; if its picture changes only every few units, as pixel art or a map does, give the pass texel so it shades once per texel.`);
53
- if (owner.state && owner.state.width * owner.state.height > LARGE_STATE)
54
- hints.push(`${owner.id} steps a ${owner.state.width}×${owner.state.height} state 60 times a second and replays it from the start in exports; keep it as small as reads well.`);
55
- }
56
- const noisy = profile.owners.filter((owner) => owner.ms > 1 && owner.range[1] - owner.range[0] > owner.ms);
57
- if (noisy.length)
58
- hints.push(`${noisy.map((owner) => owner.id).join(", ")} varied more between rounds than ${noisy.length === 1 ? "its" : "their"} median; compare the frame time, or raise --rounds.`);
59
- for (const [id, item] of Object.entries(document.items)) {
60
- const size = item.type === "file" && boardModelFormat(item.props.src, item.props.snapshot?.mimeType) ? (item.props.snapshot?.size ?? 0) : 0;
61
- if (size > LARGE_MODEL)
62
- hints.push(`${id} is a ${(size / 1024 ** 2).toFixed(0)} MB model every viewer downloads for its card, and phones skip past 16 MB; compress it (meshopt or Draco geometry, KTX2 textures).`);
63
- }
64
- if (profile.effects > MANY_EFFECTS)
65
- hints.push(`${profile.effects} items draw with shadows, blurs or color filters, each in its own offscreen pass; present them only while they change, and drop neutral values.`);
66
- return hints;
67
- }
@@ -1,67 +0,0 @@
1
- import type { BoardExportRegion, BoardThemeId } from "@neta-art/cohub/board";
2
- import type { BoardNodeExportFormat } from "@neta-art/cohub/board/export/node";
3
- import type { BoardScriptHarnessPointer, BoardScriptHarnessPress } from "@neta-art/cohub/board/testing";
4
- declare const TOOLS: readonly ["select", "hand", "play", "text", "shape", "draw", "arrow", "frame"];
5
- type Point = {
6
- x: number;
7
- y: number;
8
- };
9
- export type BoardSimulationStep = {
10
- wait: number;
11
- } | {
12
- tool: (typeof TOOLS)[number];
13
- } | {
14
- tap: Point;
15
- input: BoardScriptHarnessPointer;
16
- } | {
17
- drag: Point[];
18
- input: BoardScriptHarnessPointer;
19
- } | {
20
- move: Point[];
21
- input: BoardScriptHarnessPointer;
22
- } | {
23
- pointer: "down" | "move" | "up";
24
- at: Point;
25
- input: BoardScriptHarnessPointer;
26
- } | {
27
- key: string;
28
- } | {
29
- select: string[];
30
- };
31
- export declare function parseBoardSimulationSteps(value: unknown): BoardSimulationStep[];
32
- export type BoardSimulationPress = BoardScriptHarnessPress & {
33
- step: number;
34
- };
35
- export type BoardSimulationResult = {
36
- time: number;
37
- commits: number;
38
- changes: Record<string, unknown>;
39
- errors: Record<string, string>;
40
- presses: BoardSimulationPress[];
41
- warnings: string[];
42
- shaders?: {
43
- count: number;
44
- compiled: boolean;
45
- };
46
- image?: {
47
- bytes: Uint8Array;
48
- width: number;
49
- height: number;
50
- };
51
- };
52
- export declare const BOARD_SIMULATION_TIMEOUT_MS = 120000;
53
- export declare function runBoardSimulation(options: {
54
- spaceId: string;
55
- target: string;
56
- steps: readonly BoardSimulationStep[];
57
- leader: boolean;
58
- timeoutMs?: number;
59
- image?: {
60
- region: BoardExportRegion;
61
- scale: number;
62
- theme: BoardThemeId;
63
- format: BoardNodeExportFormat;
64
- withImages: boolean;
65
- };
66
- }): Promise<BoardSimulationResult>;
67
- export {};
@@ -1,259 +0,0 @@
1
- import { diffMergePatch } from "@neta-art/cohub/board";
2
- import { gpuResources, loadBoardDocument, readSpaceFileBytes, resolveBundledFonts, runBoardExport } from "./board-export.js";
3
- import { openBoardGpu } from "./board-gpu/daemon.js";
4
- import { findBoardGpuBrowser } from "./board-gpu/index.js";
5
- import { boardScriptAttachments, boardShaderParameters, buildBoardScene, checkBoardShader, createBoardScriptHarness, createNodeBoardRenderer, describeBoardScriptLanes, itemBounds, planBoardExport, rectsIntersect, } from "./board-kernel.js";
6
- import { settleBoardDocument } from "./board-media.js";
7
- import { parseBoardTime } from "./board-time.js";
8
- import { createClient } from "./client.js";
9
- const TOOLS = ["select", "hand", "play", "text", "shape", "draw", "arrow", "frame"];
10
- const POINTER_TYPES = ["mouse", "pen", "touch"];
11
- const MAX_STEPS = 10_000;
12
- const MAX_TIME_MS = 600_000;
13
- const FRAME_MS = 1000 / 60;
14
- function point(value, name) {
15
- if (!Array.isArray(value) || value.length !== 2 || !value.every((n) => typeof n === "number" && Number.isFinite(n)))
16
- throw new Error(`${name} must be [x, y]`);
17
- return { x: value[0], y: value[1] };
18
- }
19
- function pointerInput(step, name) {
20
- const pointerType = step.pointerType ?? "mouse";
21
- if (!POINTER_TYPES.includes(pointerType))
22
- throw new Error(`${name}.pointerType must be one of ${POINTER_TYPES.join(", ")}`);
23
- const input = { pointerType: pointerType };
24
- for (const key of ["shiftKey", "altKey", "ctrlKey", "metaKey"]) {
25
- if (step[key] === undefined)
26
- continue;
27
- if (typeof step[key] !== "boolean")
28
- throw new Error(`${name}.${key} must be a boolean`);
29
- input[key] = step[key];
30
- }
31
- return input;
32
- }
33
- export function parseBoardSimulationSteps(value) {
34
- if (!Array.isArray(value))
35
- throw new Error("steps must be an array");
36
- if (value.length > MAX_STEPS)
37
- throw new Error(`steps exceed the limit of ${MAX_STEPS}`);
38
- const steps = value.map(parseStep);
39
- const elapsed = steps.reduce((total, step) => total + ("wait" in step ? step.wait : "tap" in step ? 2 * FRAME_MS : "drag" in step ? (step.drag.length + 1) * FRAME_MS : "move" in step ? step.move.length * FRAME_MS : "pointer" in step ? FRAME_MS : 0), 0);
40
- if (elapsed > MAX_TIME_MS)
41
- throw new Error(`steps exceed ${MAX_TIME_MS / 60_000} minutes of simulated time`);
42
- return steps;
43
- }
44
- function parseStep(entry, index) {
45
- const name = `steps[${index}]`;
46
- if (!entry || typeof entry !== "object" || Array.isArray(entry))
47
- throw new Error(`${name} must be an object`);
48
- const step = entry;
49
- if ("wait" in step) {
50
- const wait = typeof step.wait === "number" ? step.wait : parseBoardTime(String(step.wait), `${name}.wait`);
51
- if (!Number.isFinite(wait) || wait < 0)
52
- throw new Error(`${name}.wait must not be negative`);
53
- return { wait };
54
- }
55
- if ("tool" in step) {
56
- if (!TOOLS.includes(step.tool))
57
- throw new Error(`${name}.tool must be one of ${TOOLS.join(", ")}`);
58
- return { tool: step.tool };
59
- }
60
- if ("tap" in step)
61
- return { tap: point(step.tap, `${name}.tap`), input: pointerInput(step, name) };
62
- if ("drag" in step) {
63
- if (!Array.isArray(step.drag) || step.drag.length < 2)
64
- throw new Error(`${name}.drag must list at least two points`);
65
- return { drag: step.drag.map((entry, at) => point(entry, `${name}.drag[${at}]`)), input: pointerInput(step, name) };
66
- }
67
- if ("move" in step) {
68
- if (!Array.isArray(step.move) || !step.move.length)
69
- throw new Error(`${name}.move must list points`);
70
- return { move: step.move.map((entry, at) => point(entry, `${name}.move[${at}]`)), input: pointerInput(step, name) };
71
- }
72
- if ("pointer" in step) {
73
- if (step.pointer !== "down" && step.pointer !== "move" && step.pointer !== "up")
74
- throw new Error(`${name}.pointer must be down, move or up`);
75
- return { pointer: step.pointer, at: point(step.at, `${name}.at`), input: pointerInput(step, name) };
76
- }
77
- if ("key" in step) {
78
- if (typeof step.key !== "string" || !step.key)
79
- throw new Error(`${name}.key must be a key name`);
80
- return { key: step.key };
81
- }
82
- if ("select" in step) {
83
- if (!Array.isArray(step.select) || !step.select.every((id) => typeof id === "string"))
84
- throw new Error(`${name}.select must list item ids`);
85
- return { select: step.select };
86
- }
87
- throw new Error(`${name} must be one of wait, tool, tap, drag, move, pointer, key or select`);
88
- }
89
- async function run(harness, steps, progress, presses) {
90
- for (const [index, step] of steps.entries()) {
91
- progress.step = index;
92
- let press = null;
93
- if ("wait" in step)
94
- await harness.advance(step.wait);
95
- else if ("tool" in step)
96
- harness.tool = step.tool;
97
- else if ("tap" in step)
98
- press = await harness.tap(step.tap, step.input);
99
- else if ("drag" in step)
100
- press = await harness.drag(step.drag, step.input);
101
- else if ("move" in step)
102
- await harness.move(step.move, step.input);
103
- else if ("pointer" in step)
104
- press = await harness.pointer(step.pointer, step.at, step.input);
105
- else if ("key" in step) {
106
- await harness.key("keydown", step.key);
107
- await harness.key("keyup", step.key);
108
- }
109
- else
110
- await harness.select(step.select);
111
- if (press)
112
- presses.push({ step: index, ...press });
113
- }
114
- }
115
- export const BOARD_SIMULATION_TIMEOUT_MS = 120_000;
116
- function shadersOf(harness) {
117
- const errors = {};
118
- const shaders = [];
119
- for (const { id } of boardScriptAttachments(harness.document)) {
120
- const message = harness.error(id);
121
- const output = harness.output(id);
122
- if (message)
123
- errors[id] = message;
124
- else if (output?.shader)
125
- shaders.push({ id, shader: output.shader, ...(output.parameters ? { parameters: output.parameters } : {}) });
126
- }
127
- return { shaders, errors };
128
- }
129
- async function checkShaders(shaders, spaceId, document) {
130
- const browser = findBoardGpuBrowser();
131
- const exporter = browser ? await openBoardGpu(gpuResources(spaceId, document), { browser }).catch(() => null) : null;
132
- if (exporter) {
133
- try {
134
- return { errors: await exporter.compile(shaders), compiled: true };
135
- }
136
- finally {
137
- await exporter.close();
138
- }
139
- }
140
- const errors = {};
141
- for (const { id, shader, parameters } of shaders) {
142
- try {
143
- checkBoardShader(shader, boardShaderParameters(parameters), id);
144
- }
145
- catch (error) {
146
- errors[id] = error instanceof Error ? error.message : String(error);
147
- }
148
- }
149
- return { errors, compiled: false };
150
- }
151
- export async function runBoardSimulation(options) {
152
- const client = createClient();
153
- const document = await settleBoardDocument(options.spaceId, (await loadBoardDocument(options.spaceId, options.target)).document);
154
- const renderer = await createNodeBoardRenderer({ fonts: resolveBundledFonts() });
155
- const progress = { step: -1, phase: "starting the scripts" };
156
- let harness = null;
157
- let timer;
158
- const timeoutMs = options.timeoutMs ?? BOARD_SIMULATION_TIMEOUT_MS;
159
- let stopped = false;
160
- const expired = new Promise((_resolve, reject) => {
161
- timer = setTimeout(() => {
162
- stopped = true;
163
- const busy = harness ? describeBoardScriptLanes(harness.status()) : [];
164
- const at = harness ? ` at ${Math.round(harness.time)} ms of simulated time` : "";
165
- const step = progress.step >= 0 ? `, step ${progress.step + 1} of ${options.steps.length}` : "";
166
- reject(new Error([
167
- `The simulation did not finish in ${timeoutMs / 1000} s${at}${step}, while ${progress.phase}.`,
168
- ...busy.map((line) => ` ${line}`),
169
- ...(!busy.length && progress.phase === "running the steps" ? [" No script was busy: the scripts keep handing each other work, or a step waits on something else."] : []),
170
- ].join("\n")));
171
- }, timeoutMs);
172
- });
173
- const work = async () => {
174
- harness = await createBoardScriptHarness({
175
- document,
176
- renderer,
177
- leader: options.leader,
178
- readModule: async (path) => new TextDecoder().decode((await readSpaceFileBytes(client, options.spaceId, path)).bytes),
179
- });
180
- const current = harness;
181
- if (stopped) {
182
- current.destroy();
183
- throw new Error("The simulation timed out.");
184
- }
185
- progress.phase = "compiling shaders";
186
- const initial = shadersOf(current);
187
- const early = initial.shaders.length ? await checkShaders(initial.shaders, options.spaceId, current.document) : null;
188
- const presses = [];
189
- if (early && Object.keys(early.errors).length) {
190
- return {
191
- time: Math.round(current.time), commits: 0, changes: {}, errors: { ...initial.errors, ...early.errors }, presses,
192
- warnings: ["Stopped before the steps: fix the shader errors first."],
193
- shaders: { count: initial.shaders.length, compiled: early.compiled },
194
- };
195
- }
196
- progress.phase = "running the steps";
197
- await run(current, options.steps, progress, presses);
198
- progress.phase = "settling the scripts";
199
- await current.flush();
200
- const { shaders, errors } = shadersOf(current);
201
- const checked = new Set(initial.shaders.map(({ id }) => id));
202
- const added = shaders.filter(({ id }) => !checked.has(id));
203
- progress.phase = "compiling shaders";
204
- const late = added.length ? await checkShaders(added, options.spaceId, current.document) : null;
205
- Object.assign(errors, late?.errors);
206
- const compiled = (early?.compiled ?? true) && (late?.compiled ?? true);
207
- const warnings = [...current.emitFailures].map(([id, message]) => `${id}: ${message}`);
208
- const result = {
209
- time: Math.round(current.time),
210
- commits: current.commits.length,
211
- changes: diffMergePatch(document, current.document) ?? {},
212
- errors,
213
- presses,
214
- warnings,
215
- ...(shaders.length ? { shaders: { count: shaders.length, compiled } } : {}),
216
- };
217
- if (options.image) {
218
- progress.phase = "rendering the image";
219
- const shown = await current.shown(options.image.scale);
220
- const gpu = compiled && shaders.length > 0 && !Object.keys(errors).length && shaderShown(current.document, shaders, options.image.region);
221
- const exported = await runBoardExport({
222
- spaceId: options.spaceId,
223
- target: options.target,
224
- ...(gpu
225
- ? { document: current.document, snapshots: await current.snapshot(), renderer: "gpu" }
226
- : { document: shown.document, ...(shown.scripts ? { scripts: shown.scripts } : {}) }),
227
- region: options.image.region,
228
- scale: options.image.scale,
229
- theme: options.image.theme,
230
- background: "paper",
231
- format: options.image.format,
232
- withImages: options.image.withImages,
233
- });
234
- const frame = exported?.frames[0];
235
- if (frame)
236
- result.image = { bytes: frame.bytes, width: frame.width, height: frame.height };
237
- warnings.push(...(exported?.warnings ?? []));
238
- }
239
- return result;
240
- };
241
- try {
242
- return await Promise.race([work(), expired]);
243
- }
244
- finally {
245
- clearTimeout(timer);
246
- harness?.destroy();
247
- renderer.destroy();
248
- }
249
- }
250
- function shaderShown(document, shaders, region) {
251
- const scene = buildBoardScene(document);
252
- const plan = planBoardExport({ scene, region, scale: 1 });
253
- if (!plan)
254
- return false;
255
- return shaders.some(({ id }) => {
256
- const item = scene.get(id);
257
- return !item || rectsIntersect(itemBounds(item.frame), plan.world);
258
- });
259
- }
@@ -1,3 +0,0 @@
1
- export declare function parseBoardTime(value: string, name?: string): number;
2
- export declare function parseBoardTimes(value: string, name?: string, limit?: number): number[];
3
- export declare function formatBoardTime(ms: number): string;