@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.
- package/bin/cohub.js +4 -1
- package/dist/board-gpu/page.js +1566 -71230
- package/dist/bootstrap.js +67 -27
- package/dist/build.json +1 -1
- package/dist/{board-kernel/FilterPipe.js → chunks/Geometry.js} +10447 -10469
- package/dist/chunks/about.js +102 -0
- package/dist/chunks/app-realtime.js +2216 -0
- package/dist/chunks/app-realtime2.js +2 -0
- package/dist/chunks/app-ref.js +88 -0
- package/dist/chunks/apps.js +1423 -0
- package/dist/chunks/auth.js +175 -0
- package/dist/chunks/avatar.js +146 -0
- package/dist/chunks/binary-pins.js +5 -0
- package/dist/chunks/board-export-resources.js +232 -0
- package/dist/chunks/board-export.js +874 -0
- package/dist/chunks/board-export2.js +2 -0
- package/dist/{board-kernel.js → chunks/board-kernel.js} +18032 -28512
- package/dist/chunks/board-kernel2.js +4 -0
- package/dist/chunks/board-profile.js +69 -0
- package/dist/chunks/board-simulate.js +315 -0
- package/dist/chunks/board-time.js +34 -0
- package/dist/chunks/boards.js +1943 -0
- package/dist/{board-kernel → chunks}/browserAll.js +9 -8
- package/dist/chunks/channels.js +64 -0
- package/dist/chunks/client.js +12606 -0
- package/dist/chunks/command-input.js +17 -0
- package/dist/chunks/commander.js +2962 -0
- package/dist/chunks/cron-jobs.js +163 -0
- package/dist/chunks/daemon.js +545 -0
- package/dist/chunks/daemon2.js +2 -0
- package/dist/chunks/desktop.js +172 -0
- package/dist/chunks/endpoint-options.js +26 -0
- package/dist/chunks/env-proxy.js +35 -0
- package/dist/chunks/environment.js +154 -0
- package/dist/chunks/feedback.js +120 -0
- package/dist/chunks/generations.js +379 -0
- package/dist/chunks/host.js +9 -0
- package/dist/chunks/http-put.js +131 -0
- package/dist/chunks/id.js +2416 -0
- package/dist/{board-kernel → chunks}/init.js +1 -1
- package/dist/chunks/install.js +11959 -0
- package/dist/chunks/launch.js +374 -0
- package/dist/chunks/local-media.js +47 -0
- package/dist/chunks/me.js +134 -0
- package/dist/chunks/media.js +315 -0
- package/dist/chunks/models.js +242 -0
- package/dist/chunks/operands.js +46 -0
- package/dist/chunks/package-paths.js +13 -0
- package/dist/chunks/policy.js +221 -0
- package/dist/chunks/preferences.js +29 -0
- package/dist/chunks/profile.js +64 -0
- package/dist/chunks/prompts.js +41 -0
- package/dist/chunks/public.js +2 -0
- package/dist/chunks/public2.js +244 -0
- package/dist/chunks/references.js +197 -0
- package/dist/chunks/referrals.js +90 -0
- package/dist/chunks/rolldown-runtime.js +26 -0
- package/dist/chunks/rooms-connect.js +2 -0
- package/dist/chunks/rooms-connect2.js +151 -0
- package/dist/chunks/rooms-rtc.js +311 -0
- package/dist/chunks/rooms.js +211 -0
- package/dist/chunks/run.js +220 -0
- package/dist/chunks/runtime.js +638 -0
- package/dist/chunks/runtime2.js +286 -0
- package/dist/chunks/runtimes.js +48 -0
- package/dist/chunks/safe-remote-image.js +198 -0
- package/dist/chunks/schemas.js +6017 -0
- package/dist/chunks/search.js +113 -0
- package/dist/chunks/self-update.js +238 -0
- package/dist/chunks/serve.js +1246 -0
- package/dist/chunks/session-status.js +24 -0
- package/dist/chunks/skills.js +35 -0
- package/dist/chunks/spaces.js +5080 -0
- package/dist/chunks/src.js +405 -0
- package/dist/chunks/supervisor.js +2513 -0
- package/dist/chunks/supervisor2.js +2 -0
- package/dist/chunks/tasks.js +82 -0
- package/dist/chunks/themes.js +2898 -0
- package/dist/chunks/version.js +2 -0
- package/dist/chunks/version2.js +22 -0
- package/dist/chunks/version3.js +18 -0
- package/dist/chunks/web.js +7 -0
- package/dist/{board-kernel → chunks}/webworkerAll.js +1 -1
- package/dist/runtime/native/pi-extension.js +174 -166
- package/dist/runtime/worker.js +27 -16
- package/package.json +8 -9
- package/dist/about.d.ts +0 -2
- package/dist/about.js +0 -71
- package/dist/app-download.d.ts +0 -11
- package/dist/app-download.js +0 -252
- package/dist/app-ref.d.ts +0 -5
- package/dist/app-ref.js +0 -8
- package/dist/app-target.d.ts +0 -26
- package/dist/app-target.js +0 -55
- package/dist/auth.d.ts +0 -45
- package/dist/auth.js +0 -307
- package/dist/avatar.d.ts +0 -55
- package/dist/avatar.js +0 -104
- package/dist/board-command-support.d.ts +0 -6
- package/dist/board-command-support.js +0 -88
- package/dist/board-export-resources.d.ts +0 -12
- package/dist/board-export-resources.js +0 -51
- package/dist/board-export.d.ts +0 -110
- package/dist/board-export.js +0 -592
- package/dist/board-fonts.d.ts +0 -11
- package/dist/board-fonts.js +0 -10
- package/dist/board-gpu/daemon.d.ts +0 -11
- package/dist/board-gpu/daemon.js +0 -295
- package/dist/board-gpu/index.d.ts +0 -33
- package/dist/board-gpu/index.js +0 -189
- package/dist/board-gpu/protocol.d.ts +0 -77
- package/dist/board-gpu/protocol.js +0 -1
- package/dist/board-kernel.d.ts +0 -5
- package/dist/board-media-export.d.ts +0 -17
- package/dist/board-media-export.js +0 -164
- package/dist/board-media.d.ts +0 -5
- package/dist/board-media.js +0 -66
- package/dist/board-profile.d.ts +0 -21
- package/dist/board-profile.js +0 -67
- package/dist/board-simulate.d.ts +0 -67
- package/dist/board-simulate.js +0 -259
- package/dist/board-time.d.ts +0 -3
- package/dist/board-time.js +0 -34
- package/dist/bootstrap.d.ts +0 -2
- package/dist/client.d.ts +0 -5
- package/dist/client.js +0 -24
- package/dist/command-input.d.ts +0 -4
- package/dist/command-input.js +0 -16
- package/dist/commands/app-commerce.d.ts +0 -2
- package/dist/commands/app-commerce.js +0 -228
- package/dist/commands/app-domains.d.ts +0 -2
- package/dist/commands/app-domains.js +0 -133
- package/dist/commands/apps.d.ts +0 -4
- package/dist/commands/apps.js +0 -827
- package/dist/commands/auth.d.ts +0 -2
- package/dist/commands/auth.js +0 -186
- package/dist/commands/boards/authoring.d.ts +0 -2
- package/dist/commands/boards/authoring.js +0 -166
- package/dist/commands/boards/examples.d.ts +0 -10
- package/dist/commands/boards/examples.js +0 -118
- package/dist/commands/boards.d.ts +0 -13
- package/dist/commands/boards.js +0 -836
- package/dist/commands/channels.d.ts +0 -2
- package/dist/commands/channels.js +0 -74
- package/dist/commands/cron-jobs.d.ts +0 -2
- package/dist/commands/cron-jobs.js +0 -155
- package/dist/commands/decision.d.ts +0 -4
- package/dist/commands/decision.js +0 -113
- package/dist/commands/desktop.d.ts +0 -10
- package/dist/commands/desktop.js +0 -233
- package/dist/commands/feedback.d.ts +0 -2
- package/dist/commands/feedback.js +0 -131
- package/dist/commands/generations.d.ts +0 -2
- package/dist/commands/generations.js +0 -427
- package/dist/commands/host.d.ts +0 -2
- package/dist/commands/host.js +0 -11
- package/dist/commands/me.d.ts +0 -2
- package/dist/commands/me.js +0 -121
- package/dist/commands/models.d.ts +0 -28
- package/dist/commands/models.js +0 -271
- package/dist/commands/profile.d.ts +0 -2
- package/dist/commands/profile.js +0 -81
- package/dist/commands/prompts.d.ts +0 -2
- package/dist/commands/prompts.js +0 -37
- package/dist/commands/public.d.ts +0 -20
- package/dist/commands/public.js +0 -291
- package/dist/commands/references.d.ts +0 -2
- package/dist/commands/references.js +0 -193
- package/dist/commands/referrals.d.ts +0 -2
- package/dist/commands/referrals.js +0 -88
- package/dist/commands/rooms-connect.d.ts +0 -17
- package/dist/commands/rooms-connect.js +0 -140
- package/dist/commands/rooms-rtc-binary.d.ts +0 -2
- package/dist/commands/rooms-rtc-binary.js +0 -107
- package/dist/commands/rooms-rtc.d.ts +0 -21
- package/dist/commands/rooms-rtc.js +0 -171
- package/dist/commands/rooms.d.ts +0 -3
- package/dist/commands/rooms.js +0 -277
- package/dist/commands/run.d.ts +0 -13
- package/dist/commands/run.js +0 -246
- package/dist/commands/runtime.d.ts +0 -3
- package/dist/commands/runtime.js +0 -320
- package/dist/commands/sandboxd-binary.d.ts +0 -11
- package/dist/commands/sandboxd-binary.js +0 -238
- package/dist/commands/search.d.ts +0 -2
- package/dist/commands/search.js +0 -114
- package/dist/commands/session-access.d.ts +0 -2
- package/dist/commands/session-access.js +0 -70
- package/dist/commands/skills.d.ts +0 -2
- package/dist/commands/skills.js +0 -34
- package/dist/commands/space-activity.d.ts +0 -26
- package/dist/commands/space-activity.js +0 -147
- package/dist/commands/space-commerce.d.ts +0 -2
- package/dist/commands/space-commerce.js +0 -514
- package/dist/commands/space-displays.d.ts +0 -2
- package/dist/commands/space-displays.js +0 -620
- package/dist/commands/space-files.d.ts +0 -5
- package/dist/commands/space-files.js +0 -215
- package/dist/commands/space-invitations.d.ts +0 -29
- package/dist/commands/space-invitations.js +0 -189
- package/dist/commands/space-turns.d.ts +0 -49
- package/dist/commands/space-turns.js +0 -205
- package/dist/commands/space-wallet.d.ts +0 -2
- package/dist/commands/space-wallet.js +0 -141
- package/dist/commands/space-webhooks.d.ts +0 -7
- package/dist/commands/space-webhooks.js +0 -73
- package/dist/commands/spaces.d.ts +0 -25
- package/dist/commands/spaces.js +0 -2170
- package/dist/commands/tasks.d.ts +0 -8
- package/dist/commands/tasks.js +0 -80
- package/dist/commands/version.d.ts +0 -2
- package/dist/commands/version.js +0 -21
- package/dist/endpoint-options.d.ts +0 -4
- package/dist/endpoint-options.js +0 -26
- package/dist/env-proxy.d.ts +0 -5
- package/dist/env-proxy.js +0 -20
- package/dist/help-path.d.ts +0 -18
- package/dist/help-path.js +0 -223
- package/dist/host/auth.d.ts +0 -20
- package/dist/host/auth.js +0 -119
- package/dist/host/login-env.d.ts +0 -1
- package/dist/host/login-env.js +0 -31
- package/dist/host/runtime.d.ts +0 -35
- package/dist/host/runtime.js +0 -395
- package/dist/host/runtimes.d.ts +0 -9
- package/dist/host/runtimes.js +0 -42
- package/dist/host/serve.d.ts +0 -2
- package/dist/host/serve.js +0 -117
- package/dist/host/workspaces.d.ts +0 -2
- package/dist/host/workspaces.js +0 -18
- package/dist/http-put.d.ts +0 -25
- package/dist/http-put.js +0 -132
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -129
- package/dist/launcher.d.ts +0 -4
- package/dist/launcher.js +0 -38
- package/dist/local-media.d.ts +0 -2
- package/dist/local-media.js +0 -30
- package/dist/network-error.d.ts +0 -3
- package/dist/network-error.js +0 -22
- package/dist/output.d.ts +0 -46
- package/dist/output.js +0 -244
- package/dist/runtime/archive-store.d.ts +0 -54
- package/dist/runtime/archive-store.js +0 -379
- package/dist/runtime/cli-path.d.ts +0 -5
- package/dist/runtime/cli-path.js +0 -27
- package/dist/runtime/codex-usage.d.ts +0 -7
- package/dist/runtime/codex-usage.js +0 -11
- package/dist/runtime/connection.d.ts +0 -42
- package/dist/runtime/connection.js +0 -789
- package/dist/runtime/diagnostics.d.ts +0 -107
- package/dist/runtime/diagnostics.js +0 -392
- package/dist/runtime/harnesses/chained-projection.d.ts +0 -40
- package/dist/runtime/harnesses/chained-projection.js +0 -95
- package/dist/runtime/harnesses/chained-transcript.d.ts +0 -24
- package/dist/runtime/harnesses/chained-transcript.js +0 -62
- package/dist/runtime/harnesses/claude-approval.d.ts +0 -34
- package/dist/runtime/harnesses/claude-approval.js +0 -124
- package/dist/runtime/harnesses/claude-transcript.d.ts +0 -8
- package/dist/runtime/harnesses/claude-transcript.js +0 -138
- package/dist/runtime/harnesses/claude.d.ts +0 -8
- package/dist/runtime/harnesses/claude.js +0 -225
- package/dist/runtime/harnesses/codex-approval.d.ts +0 -25
- package/dist/runtime/harnesses/codex-approval.js +0 -69
- package/dist/runtime/harnesses/codex.d.ts +0 -4
- package/dist/runtime/harnesses/codex.js +0 -269
- package/dist/runtime/harnesses/cursor-transcript.d.ts +0 -37
- package/dist/runtime/harnesses/cursor-transcript.js +0 -183
- package/dist/runtime/harnesses/cursor.d.ts +0 -24
- package/dist/runtime/harnesses/cursor.js +0 -620
- package/dist/runtime/harnesses/index.d.ts +0 -16
- package/dist/runtime/harnesses/index.js +0 -73
- package/dist/runtime/harnesses/pi.d.ts +0 -4
- package/dist/runtime/harnesses/pi.js +0 -247
- package/dist/runtime/harnesses/process.d.ts +0 -31
- package/dist/runtime/harnesses/process.js +0 -75
- package/dist/runtime/harnesses/stream-json.d.ts +0 -48
- package/dist/runtime/harnesses/stream-json.js +0 -336
- package/dist/runtime/harnesses/types.d.ts +0 -117
- package/dist/runtime/harnesses/types.js +0 -1
- package/dist/runtime/harnesses/workbuddy-transcript.d.ts +0 -8
- package/dist/runtime/harnesses/workbuddy-transcript.js +0 -127
- package/dist/runtime/harnesses/workbuddy.d.ts +0 -21
- package/dist/runtime/harnesses/workbuddy.js +0 -123
- package/dist/runtime/instance.d.ts +0 -20
- package/dist/runtime/instance.js +0 -247
- package/dist/runtime/json-rpc.d.ts +0 -53
- package/dist/runtime/json-rpc.js +0 -212
- package/dist/runtime/launch.d.ts +0 -25
- package/dist/runtime/launch.js +0 -247
- package/dist/runtime/local-workspace.d.ts +0 -15
- package/dist/runtime/local-workspace.js +0 -52
- package/dist/runtime/model-catalog.d.ts +0 -12
- package/dist/runtime/model-catalog.js +0 -84
- package/dist/runtime/native/adapters.d.ts +0 -15
- package/dist/runtime/native/adapters.js +0 -11
- package/dist/runtime/native/approvals.d.ts +0 -18
- package/dist/runtime/native/approvals.js +0 -54
- package/dist/runtime/native/archive.d.ts +0 -19
- package/dist/runtime/native/archive.js +0 -142
- package/dist/runtime/native/attach.d.ts +0 -36
- package/dist/runtime/native/attach.js +0 -128
- package/dist/runtime/native/codex-link.d.ts +0 -60
- package/dist/runtime/native/codex-link.js +0 -322
- package/dist/runtime/native/config.d.ts +0 -16
- package/dist/runtime/native/config.js +0 -24
- package/dist/runtime/native/daemon.d.ts +0 -92
- package/dist/runtime/native/daemon.js +0 -380
- package/dist/runtime/native/execution.d.ts +0 -26
- package/dist/runtime/native/execution.js +0 -34
- package/dist/runtime/native/identity.d.ts +0 -9
- package/dist/runtime/native/identity.js +0 -15
- package/dist/runtime/native/ingest.d.ts +0 -263
- package/dist/runtime/native/ingest.js +0 -884
- package/dist/runtime/native/install.d.ts +0 -9
- package/dist/runtime/native/install.js +0 -113
- package/dist/runtime/native/paths.d.ts +0 -2
- package/dist/runtime/native/paths.js +0 -7
- package/dist/runtime/native/pi-extension.d.ts +0 -36
- package/dist/runtime/native/pi-link.d.ts +0 -69
- package/dist/runtime/native/pi-link.js +0 -269
- package/dist/runtime/native/results.d.ts +0 -41
- package/dist/runtime/native/results.js +0 -128
- package/dist/runtime/native/sessions.d.ts +0 -45
- package/dist/runtime/native/sessions.js +0 -87
- package/dist/runtime/native/transcript.d.ts +0 -89
- package/dist/runtime/native/transcript.js +0 -656
- package/dist/runtime/native/translate.d.ts +0 -46
- package/dist/runtime/native/translate.js +0 -299
- package/dist/runtime/native/transport.d.ts +0 -7
- package/dist/runtime/native/transport.js +0 -16
- package/dist/runtime/native/version.d.ts +0 -5
- package/dist/runtime/native/version.js +0 -21
- package/dist/runtime/preferences.d.ts +0 -7
- package/dist/runtime/preferences.js +0 -22
- package/dist/runtime/presentation.d.ts +0 -32
- package/dist/runtime/presentation.js +0 -124
- package/dist/runtime/process-group.d.ts +0 -5
- package/dist/runtime/process-group.js +0 -161
- package/dist/runtime/projection-store.d.ts +0 -27
- package/dist/runtime/projection-store.js +0 -30
- package/dist/runtime/space-binding.d.ts +0 -48
- package/dist/runtime/space-binding.js +0 -342
- package/dist/runtime/supervisor.d.ts +0 -19
- package/dist/runtime/supervisor.js +0 -441
- package/dist/runtime/turn-projection.d.ts +0 -41
- package/dist/runtime/turn-projection.js +0 -120
- package/dist/runtime/worker.d.ts +0 -1
- package/dist/safe-remote-image.d.ts +0 -36
- package/dist/safe-remote-image.js +0 -191
- package/dist/self-update.d.ts +0 -7
- package/dist/self-update.js +0 -202
- package/dist/session-status.d.ts +0 -10
- package/dist/session-status.js +0 -25
- package/dist/space-files/limit.d.ts +0 -2
- package/dist/space-files/limit.js +0 -16
- package/dist/space-files/operands.d.ts +0 -17
- package/dist/space-files/operands.js +0 -33
- package/dist/space-files/transfer.d.ts +0 -53
- package/dist/space-files/transfer.js +0 -297
- package/dist/space-files/upload.d.ts +0 -17
- package/dist/space-files/upload.js +0 -76
- package/dist/space.d.ts +0 -44
- package/dist/space.js +0 -192
- package/dist/version.d.ts +0 -2
- package/dist/version.js +0 -17
- package/dist/web.d.ts +0 -1
- package/dist/web.js +0 -4
- /package/dist/{board-kernel → chunks}/lexer.js +0 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { C as error, D as json, E as handleHttp, O as jsonRequested, j as table, k as ok, t as createClient } from "./client.js";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
//#region src/commands/cron-jobs.ts
|
|
4
|
+
function readJsonObject(pathOrJson) {
|
|
5
|
+
const raw = pathOrJson.trim().startsWith("{") ? pathOrJson : readFileSync(pathOrJson, "utf8");
|
|
6
|
+
const parsed = JSON.parse(raw);
|
|
7
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) error("Invalid payload", "Expected a JSON object");
|
|
8
|
+
return parsed;
|
|
9
|
+
}
|
|
10
|
+
function registerCronJobs(program) {
|
|
11
|
+
const cmd = program.command("cron-jobs").description("Scheduled jobs");
|
|
12
|
+
cmd.command("ls [spaceId]").alias("list").description("List scheduled jobs").option("--json", "Output as JSON").action(async (spaceId, opts) => {
|
|
13
|
+
const client = createClient();
|
|
14
|
+
try {
|
|
15
|
+
const result = await client.cronJobs.list(spaceId);
|
|
16
|
+
if (jsonRequested(opts)) return json(result);
|
|
17
|
+
if (result.jobs.length === 0) return console.log(" (empty)");
|
|
18
|
+
table(result.jobs, [
|
|
19
|
+
{
|
|
20
|
+
key: "id",
|
|
21
|
+
label: "ID"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
key: "title",
|
|
25
|
+
label: "Title"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
key: "taskType",
|
|
29
|
+
label: "Type"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
key: "cronExpression",
|
|
33
|
+
label: "Schedule"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
key: "enabled",
|
|
37
|
+
label: "Enabled"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
key: "spaceId",
|
|
41
|
+
label: "Space"
|
|
42
|
+
}
|
|
43
|
+
]);
|
|
44
|
+
} catch (e) {
|
|
45
|
+
handleHttp(e);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
cmd.command("get <id>").description("Show scheduled job").option("--json", "Output as JSON").action(async (id, opts) => {
|
|
49
|
+
const client = createClient();
|
|
50
|
+
try {
|
|
51
|
+
const result = await client.cronJobs.get(id);
|
|
52
|
+
if (jsonRequested(opts)) return json(result);
|
|
53
|
+
table([result.job], [
|
|
54
|
+
{
|
|
55
|
+
key: "id",
|
|
56
|
+
label: "ID"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
key: "title",
|
|
60
|
+
label: "Title"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
key: "taskType",
|
|
64
|
+
label: "Type"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
key: "cronExpression",
|
|
68
|
+
label: "Schedule"
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
key: "timezone",
|
|
72
|
+
label: "Timezone"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
key: "enabled",
|
|
76
|
+
label: "Enabled"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
key: "spaceId",
|
|
80
|
+
label: "Space"
|
|
81
|
+
}
|
|
82
|
+
]);
|
|
83
|
+
} catch (e) {
|
|
84
|
+
handleHttp(e);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
cmd.command("update <id>").description("Update scheduled job").option("--title <title>", "Update title").option("--cron <expression>", "Update cron expression").option("--timezone <timezone>", "Update timezone").option("--payload <jsonOrPath>", "Update payload from JSON string or file").option("--json", "Output as JSON").action(async (id, opts) => {
|
|
88
|
+
const client = createClient();
|
|
89
|
+
try {
|
|
90
|
+
const patch = {};
|
|
91
|
+
if (opts.title !== void 0) patch.title = opts.title;
|
|
92
|
+
if (opts.cron !== void 0) patch.cronExpression = opts.cron;
|
|
93
|
+
if (opts.timezone !== void 0) patch.timezone = opts.timezone;
|
|
94
|
+
if (opts.payload !== void 0) patch.payload = readJsonObject(opts.payload);
|
|
95
|
+
if (Object.keys(patch).length === 0) error("No changes provided", "Use --title, --cron, --timezone, or --payload");
|
|
96
|
+
const result = await client.cronJobs.update(id, patch);
|
|
97
|
+
if (jsonRequested(opts)) return json(result);
|
|
98
|
+
ok(`Cron job updated: ${result.job.id}`);
|
|
99
|
+
} catch (e) {
|
|
100
|
+
if (e instanceof Error && /ENOENT|Unexpected token|JSON/.test(e.message)) error("Invalid payload", e.message);
|
|
101
|
+
handleHttp(e);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
cmd.command("delete <id>").description("Delete scheduled job").action(async (id) => {
|
|
105
|
+
const client = createClient();
|
|
106
|
+
try {
|
|
107
|
+
await client.cronJobs.delete(id);
|
|
108
|
+
ok(`Cron job deleted: ${id}`);
|
|
109
|
+
} catch (e) {
|
|
110
|
+
handleHttp(e);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
cmd.command("toggle <id> <on|off>").description("Enable or pause scheduled job").action(async (id, state) => {
|
|
114
|
+
if (state !== "on" && state !== "off") return error("Invalid state", "Use on or off");
|
|
115
|
+
const enabled = state === "on";
|
|
116
|
+
const client = createClient();
|
|
117
|
+
try {
|
|
118
|
+
await client.cronJobs.toggle(id, enabled);
|
|
119
|
+
ok(`Cron job ${enabled ? "enabled" : "disabled"}: ${id}`);
|
|
120
|
+
} catch (e) {
|
|
121
|
+
handleHttp(e);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
cmd.command("runs <id>").description("List scheduled job runs").option("--limit <limit>", "Page size", "20").option("--cursor <cursor>", "Pagination cursor").option("--json", "Output as JSON").action(async (id, opts) => {
|
|
125
|
+
const client = createClient();
|
|
126
|
+
const limit = Number(opts.limit ?? 20);
|
|
127
|
+
try {
|
|
128
|
+
const result = await client.cronJobs.runs(id, {
|
|
129
|
+
limit: Number.isFinite(limit) ? limit : 20,
|
|
130
|
+
cursor: opts.cursor
|
|
131
|
+
});
|
|
132
|
+
if (jsonRequested(opts)) return json(result);
|
|
133
|
+
if (result.runs.length === 0) return console.log(" (empty)");
|
|
134
|
+
table(result.runs, [
|
|
135
|
+
{
|
|
136
|
+
key: "id",
|
|
137
|
+
label: "ID"
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
key: "status",
|
|
141
|
+
label: "Status"
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
key: "scheduledAt",
|
|
145
|
+
label: "Scheduled"
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
key: "startedAt",
|
|
149
|
+
label: "Started"
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
key: "finishedAt",
|
|
153
|
+
label: "Finished"
|
|
154
|
+
}
|
|
155
|
+
]);
|
|
156
|
+
if (result.pageInfo.hasMore && result.pageInfo.nextCursor) console.log(`\nNext cursor: ${result.pageInfo.nextCursor}`);
|
|
157
|
+
} catch (e) {
|
|
158
|
+
handleHttp(e);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
//#endregion
|
|
163
|
+
export { registerCronJobs };
|
|
@@ -0,0 +1,545 @@
|
|
|
1
|
+
import { t as packagePath } from "./package-paths.js";
|
|
2
|
+
import { t as CLI_VERSION } from "./version2.js";
|
|
3
|
+
import { createServer } from "node:http";
|
|
4
|
+
import { spawn } from "node:child_process";
|
|
5
|
+
import { tmpdir, userInfo } from "node:os";
|
|
6
|
+
import { existsSync, lstatSync, mkdirSync, statSync, unlinkSync } from "node:fs";
|
|
7
|
+
import { basename, join } from "node:path";
|
|
8
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
9
|
+
import { createConnection, createServer as createServer$1 } from "node:net";
|
|
10
|
+
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
|
11
|
+
//#region src/board-gpu/index.ts
|
|
12
|
+
function findBoardGpuBrowser(env = process.env) {
|
|
13
|
+
const named = env.COHUB_CHROME?.trim();
|
|
14
|
+
if (named) return existsSync(named) ? named : null;
|
|
15
|
+
return (process.platform === "darwin" ? [
|
|
16
|
+
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
|
17
|
+
"/Applications/Chromium.app/Contents/MacOS/Chromium",
|
|
18
|
+
"/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"
|
|
19
|
+
] : process.platform === "win32" ? [
|
|
20
|
+
env.PROGRAMFILES,
|
|
21
|
+
env["PROGRAMFILES(X86)"],
|
|
22
|
+
env.LOCALAPPDATA
|
|
23
|
+
].flatMap((root) => root ? [join(root, "Google/Chrome/Application/chrome.exe"), join(root, "Microsoft/Edge/Application/msedge.exe")] : []) : [
|
|
24
|
+
"google-chrome",
|
|
25
|
+
"google-chrome-stable",
|
|
26
|
+
"chromium",
|
|
27
|
+
"chromium-browser",
|
|
28
|
+
"microsoft-edge"
|
|
29
|
+
].flatMap((name) => (env.PATH ?? "").split(":").filter(Boolean).map((dir) => join(dir, name)))).find((path) => existsSync(path)) ?? null;
|
|
30
|
+
}
|
|
31
|
+
const CALL_TIMEOUT_MS = 12e4;
|
|
32
|
+
function devtools(input, output) {
|
|
33
|
+
let next = 0;
|
|
34
|
+
let buffer = "";
|
|
35
|
+
const pending = /* @__PURE__ */ new Map();
|
|
36
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
37
|
+
output.setEncoding("utf8");
|
|
38
|
+
output.on("data", (chunk) => {
|
|
39
|
+
buffer += chunk;
|
|
40
|
+
for (let end = buffer.indexOf("\0"); end >= 0; end = buffer.indexOf("\0")) {
|
|
41
|
+
const raw = buffer.slice(0, end);
|
|
42
|
+
buffer = buffer.slice(end + 1);
|
|
43
|
+
let message;
|
|
44
|
+
try {
|
|
45
|
+
message = JSON.parse(raw);
|
|
46
|
+
} catch {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const waiting = message.id === void 0 ? void 0 : pending.get(message.id);
|
|
50
|
+
if (waiting && message.id !== void 0) {
|
|
51
|
+
pending.delete(message.id);
|
|
52
|
+
if (message.error) waiting.reject(new Error(message.error.message));
|
|
53
|
+
else waiting.resolve(message.result ?? {});
|
|
54
|
+
}
|
|
55
|
+
for (const listener of listeners) listener(message);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
const fail = (error) => {
|
|
59
|
+
for (const waiting of pending.values()) waiting.reject(error);
|
|
60
|
+
pending.clear();
|
|
61
|
+
};
|
|
62
|
+
output.on("close", () => fail(/* @__PURE__ */ new Error("The browser closed.")));
|
|
63
|
+
output.on("error", (error) => fail(error));
|
|
64
|
+
input.on("error", (error) => fail(error));
|
|
65
|
+
return {
|
|
66
|
+
send(method, params = {}, sessionId) {
|
|
67
|
+
const id = ++next;
|
|
68
|
+
return new Promise((resolve, reject) => {
|
|
69
|
+
pending.set(id, {
|
|
70
|
+
resolve,
|
|
71
|
+
reject
|
|
72
|
+
});
|
|
73
|
+
input.write(`${JSON.stringify({
|
|
74
|
+
id,
|
|
75
|
+
method,
|
|
76
|
+
params,
|
|
77
|
+
...sessionId ? { sessionId } : {}
|
|
78
|
+
})}\0`);
|
|
79
|
+
});
|
|
80
|
+
},
|
|
81
|
+
listen(listener) {
|
|
82
|
+
listeners.add(listener);
|
|
83
|
+
},
|
|
84
|
+
fail
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
const PAGE = (fonts) => `<!doctype html><meta charset="utf-8"><style>${fonts.map(({ family, file }) => `@font-face{font-family:"${family}";src:url("fonts/${file}") format("woff2");font-weight:100 900}`).join("")}</style><body>${fonts.map(({ family }) => `<span style="font-family:'${family}'">.</span>`).join("")}<script type="module" src="page.js"><\/script>`;
|
|
88
|
+
async function launchBoardGpuExporter(resources, options) {
|
|
89
|
+
const bundle = packagePath("dist", "board-gpu", "page.js");
|
|
90
|
+
if (!existsSync(bundle)) throw new Error("This CLI build has no GPU exporter; reinstall @neta-art/cohub-cli.");
|
|
91
|
+
const token = randomBytes(16).toString("hex");
|
|
92
|
+
const fonts = resources.fonts.map(({ family, path }) => ({
|
|
93
|
+
family,
|
|
94
|
+
path,
|
|
95
|
+
file: basename(path)
|
|
96
|
+
}));
|
|
97
|
+
const server = createServer(async (request, response) => {
|
|
98
|
+
const url = new URL(request.url ?? "/", "http://127.0.0.1");
|
|
99
|
+
const [, prefix, ...rest] = url.pathname.split("/");
|
|
100
|
+
const route = rest.join("/");
|
|
101
|
+
try {
|
|
102
|
+
if (prefix !== token) throw Object.assign(/* @__PURE__ */ new Error("Not found"), { status: 404 });
|
|
103
|
+
if (route === "") return void response.writeHead(200, { "content-type": "text/html" }).end(PAGE(fonts));
|
|
104
|
+
if (route === "page.js") return void response.writeHead(200, { "content-type": "text/javascript" }).end(await readFile(bundle));
|
|
105
|
+
const font = route.startsWith("fonts/") && fonts.find(({ file }) => file === route.slice(6));
|
|
106
|
+
if (font) return void response.writeHead(200, { "content-type": "font/woff2" }).end(await readFile(font.path));
|
|
107
|
+
if (route === "module") {
|
|
108
|
+
const code = await resources.readModule(url.searchParams.get("path") ?? "");
|
|
109
|
+
response.writeHead(200, { "content-type": "text/javascript" }).end(code);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (route === "asset") {
|
|
113
|
+
const picture = await resources.readPicture(url.searchParams.has("background") ? { background: true } : {
|
|
114
|
+
key: url.searchParams.get("key") ?? "",
|
|
115
|
+
edge: Number(url.searchParams.get("edge")) || 4096
|
|
116
|
+
});
|
|
117
|
+
if (!picture) throw Object.assign(/* @__PURE__ */ new Error("Not found"), { status: 404 });
|
|
118
|
+
response.writeHead(200, { "content-type": picture.mimeType }).end(picture.bytes);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
throw Object.assign(/* @__PURE__ */ new Error("Not found"), { status: 404 });
|
|
122
|
+
} catch (error) {
|
|
123
|
+
response.writeHead(error.status ?? 500).end(error instanceof Error ? error.message : String(error));
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
127
|
+
const port = server.address().port;
|
|
128
|
+
const profile = await mkdtemp(join(tmpdir(), "cohub-board-gpu-"));
|
|
129
|
+
let chrome = null;
|
|
130
|
+
const close = async () => {
|
|
131
|
+
chrome?.kill();
|
|
132
|
+
chrome = null;
|
|
133
|
+
await new Promise((resolve) => server.close(() => resolve()));
|
|
134
|
+
await rm(profile, {
|
|
135
|
+
recursive: true,
|
|
136
|
+
force: true
|
|
137
|
+
}).catch(() => {});
|
|
138
|
+
};
|
|
139
|
+
const start = async (sandbox) => {
|
|
140
|
+
const child = spawn(options.browser, [
|
|
141
|
+
"--headless=new",
|
|
142
|
+
"--remote-debugging-pipe",
|
|
143
|
+
`--user-data-dir=${profile}`,
|
|
144
|
+
"--no-first-run",
|
|
145
|
+
"--no-default-browser-check",
|
|
146
|
+
"--disable-extensions",
|
|
147
|
+
"--disable-background-networking",
|
|
148
|
+
"--mute-audio",
|
|
149
|
+
"--hide-scrollbars",
|
|
150
|
+
"--enable-unsafe-swiftshader",
|
|
151
|
+
...sandbox ? [] : ["--no-sandbox"],
|
|
152
|
+
"about:blank"
|
|
153
|
+
], { stdio: [
|
|
154
|
+
"ignore",
|
|
155
|
+
"ignore",
|
|
156
|
+
"ignore",
|
|
157
|
+
"pipe",
|
|
158
|
+
"pipe"
|
|
159
|
+
] });
|
|
160
|
+
const [, , , input, output] = child.stdio;
|
|
161
|
+
const protocol = devtools(input, output);
|
|
162
|
+
child.once("exit", () => protocol.fail(/* @__PURE__ */ new Error("The browser stopped.")));
|
|
163
|
+
child.once("error", (error) => protocol.fail(error));
|
|
164
|
+
chrome = child;
|
|
165
|
+
return {
|
|
166
|
+
protocol,
|
|
167
|
+
created: await protocol.send("Target.createTarget", { url: "about:blank" })
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
try {
|
|
171
|
+
const { protocol, created } = await start(true).catch(() => {
|
|
172
|
+
chrome?.kill();
|
|
173
|
+
return start(false);
|
|
174
|
+
});
|
|
175
|
+
options.signal?.addEventListener("abort", () => void close(), { once: true });
|
|
176
|
+
const { targetId } = created;
|
|
177
|
+
const { sessionId } = await protocol.send("Target.attachToTarget", {
|
|
178
|
+
targetId,
|
|
179
|
+
flatten: true
|
|
180
|
+
});
|
|
181
|
+
const page = (method, params) => protocol.send(method, params, sessionId);
|
|
182
|
+
let crashed = null;
|
|
183
|
+
protocol.listen((message) => {
|
|
184
|
+
if (message.sessionId === sessionId && message.method === "Runtime.exceptionThrown") crashed ??= String((message.params?.exceptionDetails)?.exception?.description ?? "The export page failed.");
|
|
185
|
+
});
|
|
186
|
+
await page("Runtime.enable");
|
|
187
|
+
await page("Page.enable");
|
|
188
|
+
await page("Page.navigate", { url: `http://127.0.0.1:${port}/${token}/` });
|
|
189
|
+
const call = async (expression, timeoutMs = CALL_TIMEOUT_MS) => {
|
|
190
|
+
let timer;
|
|
191
|
+
const expired = new Promise((_resolve, reject) => {
|
|
192
|
+
timer = setTimeout(() => reject(/* @__PURE__ */ new Error("The GPU exporter stopped responding; a shader may be too heavy to render.")), timeoutMs);
|
|
193
|
+
});
|
|
194
|
+
const reply = await Promise.race([page("Runtime.evaluate", {
|
|
195
|
+
expression,
|
|
196
|
+
awaitPromise: true,
|
|
197
|
+
returnByValue: true
|
|
198
|
+
}), expired]).finally(() => clearTimeout(timer));
|
|
199
|
+
if (reply.exceptionDetails) throw new Error(reply.exceptionDetails.exception?.description?.split("\n")[0] ?? reply.exceptionDetails.text ?? "The export page failed.");
|
|
200
|
+
return reply.result?.value;
|
|
201
|
+
};
|
|
202
|
+
const loaded = () => call("Boolean(globalThis.cohubBoardGpu)", 5e3).catch(() => false);
|
|
203
|
+
for (const started = Date.now(); !await loaded();) {
|
|
204
|
+
if (crashed || Date.now() - started > 2e4) throw new Error(crashed ?? "The GPU exporter did not start.");
|
|
205
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
206
|
+
}
|
|
207
|
+
return {
|
|
208
|
+
browser: options.browser,
|
|
209
|
+
async init(init) {
|
|
210
|
+
await call(`cohubBoardGpu.init(${JSON.stringify(init)})`);
|
|
211
|
+
},
|
|
212
|
+
compile: (shaders) => call(`cohubBoardGpu.compile(${JSON.stringify(shaders)})`),
|
|
213
|
+
profile: (input) => call(`cohubBoardGpu.profile(${JSON.stringify(input)})`, Math.max(CALL_TIMEOUT_MS, input.budgetMs * 2 + 6e4)),
|
|
214
|
+
async render(frame) {
|
|
215
|
+
const { data, ...rest } = await call(`cohubBoardGpu.render(${JSON.stringify(frame)})`);
|
|
216
|
+
return {
|
|
217
|
+
...rest,
|
|
218
|
+
bytes: new Uint8Array(Buffer.from(data, "base64"))
|
|
219
|
+
};
|
|
220
|
+
},
|
|
221
|
+
close
|
|
222
|
+
};
|
|
223
|
+
} catch (error) {
|
|
224
|
+
await close();
|
|
225
|
+
throw error;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
//#endregion
|
|
229
|
+
//#region src/board-gpu/daemon.ts
|
|
230
|
+
const IDLE_MS = 3e5;
|
|
231
|
+
const CONNECT_MS = 2e4;
|
|
232
|
+
const TURN_MS = 2e4;
|
|
233
|
+
function lines(socket, handle) {
|
|
234
|
+
let buffer = "";
|
|
235
|
+
socket.setEncoding("utf8");
|
|
236
|
+
socket.on("data", (chunk) => {
|
|
237
|
+
buffer += chunk;
|
|
238
|
+
for (let end = buffer.indexOf("\n"); end >= 0; end = buffer.indexOf("\n")) {
|
|
239
|
+
const line = buffer.slice(0, end);
|
|
240
|
+
buffer = buffer.slice(end + 1);
|
|
241
|
+
let message;
|
|
242
|
+
try {
|
|
243
|
+
message = JSON.parse(line);
|
|
244
|
+
} catch {
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
handle(message);
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
return (message) => socket.write(`${JSON.stringify(message)}\n`);
|
|
251
|
+
}
|
|
252
|
+
function boardGpuSocket(browser) {
|
|
253
|
+
let page = 0;
|
|
254
|
+
try {
|
|
255
|
+
page = statSync(packagePath("dist", "board-gpu", "page.js")).mtimeMs;
|
|
256
|
+
} catch {}
|
|
257
|
+
const { uid } = userInfo();
|
|
258
|
+
const key = createHash("sha256").update(`${CLI_VERSION}\0${browser}\0${page}\0${uid}`).digest("hex").slice(0, 16);
|
|
259
|
+
if (process.platform === "win32") return join("\\\\.\\pipe", `cohub-board-gpu-${key}`);
|
|
260
|
+
const dir = join(process.env.XDG_RUNTIME_DIR || tmpdir(), `cohub-${uid}`);
|
|
261
|
+
mkdirSync(dir, {
|
|
262
|
+
recursive: true,
|
|
263
|
+
mode: 448
|
|
264
|
+
});
|
|
265
|
+
const stat = lstatSync(dir);
|
|
266
|
+
if (!stat.isDirectory() || stat.uid !== uid || (stat.mode & 63) !== 0) throw new Error(`${dir} is not private to this user.`);
|
|
267
|
+
return join(dir, `board-gpu-${key}.sock`);
|
|
268
|
+
}
|
|
269
|
+
async function serveBoardGpu(browser) {
|
|
270
|
+
const path = boardGpuSocket(browser);
|
|
271
|
+
const queue = [];
|
|
272
|
+
let exporter = null;
|
|
273
|
+
let nextAsk = 0;
|
|
274
|
+
let idle = null;
|
|
275
|
+
const active = () => queue[0] ?? null;
|
|
276
|
+
const ask = (request) => new Promise((resolve, reject) => {
|
|
277
|
+
const caller = active();
|
|
278
|
+
if (!caller || caller.gone) return reject(/* @__PURE__ */ new Error("The caller left."));
|
|
279
|
+
const id = ++nextAsk;
|
|
280
|
+
caller.asks.set(id, resolve);
|
|
281
|
+
caller.send({
|
|
282
|
+
ask: id,
|
|
283
|
+
request
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
const resources = {
|
|
287
|
+
fonts: [],
|
|
288
|
+
async readModule(path) {
|
|
289
|
+
const answer = await ask({
|
|
290
|
+
kind: "module",
|
|
291
|
+
path
|
|
292
|
+
});
|
|
293
|
+
if (answer.error !== void 0 || answer.text === void 0) throw new Error(answer.error ?? `${path} is not available.`);
|
|
294
|
+
return answer.text;
|
|
295
|
+
},
|
|
296
|
+
async readPicture(request) {
|
|
297
|
+
const answer = await ask({
|
|
298
|
+
kind: "picture",
|
|
299
|
+
request
|
|
300
|
+
});
|
|
301
|
+
if (answer.error !== void 0) throw new Error(answer.error);
|
|
302
|
+
return answer.bytes === void 0 ? null : {
|
|
303
|
+
bytes: Buffer.from(answer.bytes, "base64"),
|
|
304
|
+
mimeType: answer.mimeType ?? "application/octet-stream"
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
const { resolveBundledFonts } = await import("./board-export2.js");
|
|
309
|
+
resources.fonts = resolveBundledFonts().flatMap(({ path, family }) => family ? [{
|
|
310
|
+
path,
|
|
311
|
+
family
|
|
312
|
+
}] : []);
|
|
313
|
+
const browserFor = () => exporter ??= launchBoardGpuExporter(resources, { browser }).catch((error) => {
|
|
314
|
+
exporter = null;
|
|
315
|
+
throw error;
|
|
316
|
+
});
|
|
317
|
+
const reset = async () => {
|
|
318
|
+
const current = exporter;
|
|
319
|
+
exporter = null;
|
|
320
|
+
await current?.then((value) => value.close(), () => {});
|
|
321
|
+
};
|
|
322
|
+
const shutdown = async () => {
|
|
323
|
+
await reset();
|
|
324
|
+
server.close();
|
|
325
|
+
process.exit(0);
|
|
326
|
+
};
|
|
327
|
+
const schedule = () => {
|
|
328
|
+
if (idle) clearTimeout(idle);
|
|
329
|
+
idle = queue.length ? null : setTimeout(() => void shutdown(), IDLE_MS);
|
|
330
|
+
};
|
|
331
|
+
const advance = () => {
|
|
332
|
+
active()?.send({ granted: true });
|
|
333
|
+
schedule();
|
|
334
|
+
};
|
|
335
|
+
const release = (caller) => {
|
|
336
|
+
if (!caller.gone || caller.running) return;
|
|
337
|
+
const index = queue.indexOf(caller);
|
|
338
|
+
if (index < 0) return;
|
|
339
|
+
queue.splice(index, 1);
|
|
340
|
+
if (index === 0) advance();
|
|
341
|
+
};
|
|
342
|
+
const server = createServer$1((socket) => {
|
|
343
|
+
const caller = {
|
|
344
|
+
send: () => {},
|
|
345
|
+
asks: /* @__PURE__ */ new Map(),
|
|
346
|
+
running: 0,
|
|
347
|
+
gone: false
|
|
348
|
+
};
|
|
349
|
+
caller.send = lines(socket, (message) => {
|
|
350
|
+
if ("answer" in message) {
|
|
351
|
+
caller.asks.get(message.answer)?.(message);
|
|
352
|
+
caller.asks.delete(message.answer);
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
if (!("method" in message) || active() !== caller) return;
|
|
356
|
+
caller.running++;
|
|
357
|
+
browserFor().then((gpu) => call(gpu, message.method, message.params)).then((result) => caller.send({
|
|
358
|
+
id: message.id,
|
|
359
|
+
result
|
|
360
|
+
}), async (error) => {
|
|
361
|
+
const text = error instanceof Error ? error.message : String(error);
|
|
362
|
+
if (/stopped responding|browser (stopped|closed)|did not start/i.test(text)) await reset();
|
|
363
|
+
caller.send({
|
|
364
|
+
id: message.id,
|
|
365
|
+
error: text
|
|
366
|
+
});
|
|
367
|
+
}).finally(() => {
|
|
368
|
+
caller.running--;
|
|
369
|
+
release(caller);
|
|
370
|
+
});
|
|
371
|
+
});
|
|
372
|
+
const leave = () => {
|
|
373
|
+
if (caller.gone) return;
|
|
374
|
+
caller.gone = true;
|
|
375
|
+
for (const resolve of caller.asks.values()) resolve({
|
|
376
|
+
answer: -1,
|
|
377
|
+
error: "The caller left."
|
|
378
|
+
});
|
|
379
|
+
caller.asks.clear();
|
|
380
|
+
release(caller);
|
|
381
|
+
};
|
|
382
|
+
socket.on("close", leave);
|
|
383
|
+
socket.on("error", leave);
|
|
384
|
+
queue.push(caller);
|
|
385
|
+
if (queue.length === 1) advance();
|
|
386
|
+
});
|
|
387
|
+
await new Promise((resolve, reject) => {
|
|
388
|
+
server.once("error", async (error) => {
|
|
389
|
+
if (error.code !== "EADDRINUSE") return reject(error);
|
|
390
|
+
if (await new Promise((done) => {
|
|
391
|
+
const probe = createConnection(path, () => {
|
|
392
|
+
probe.destroy();
|
|
393
|
+
done(true);
|
|
394
|
+
});
|
|
395
|
+
probe.once("error", () => done(false));
|
|
396
|
+
})) return process.exit(0);
|
|
397
|
+
try {
|
|
398
|
+
unlinkSync(path);
|
|
399
|
+
} catch {}
|
|
400
|
+
server.listen(path, resolve);
|
|
401
|
+
});
|
|
402
|
+
server.listen(path, resolve);
|
|
403
|
+
});
|
|
404
|
+
process.on("SIGTERM", () => void shutdown());
|
|
405
|
+
schedule();
|
|
406
|
+
}
|
|
407
|
+
function call(gpu, method, params) {
|
|
408
|
+
switch (method) {
|
|
409
|
+
case "init": return gpu.init(params);
|
|
410
|
+
case "compile": return gpu.compile(params);
|
|
411
|
+
case "profile": return gpu.profile(params);
|
|
412
|
+
case "render": return gpu.render(params).then(({ bytes, ...rest }) => ({
|
|
413
|
+
...rest,
|
|
414
|
+
data: Buffer.from(bytes).toString("base64")
|
|
415
|
+
}));
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
function startDaemon(browser) {
|
|
419
|
+
const entry = process.argv[1];
|
|
420
|
+
if (!entry) throw new Error("The CLI entry point is unknown.");
|
|
421
|
+
spawn(process.execPath, [
|
|
422
|
+
...process.execArgv,
|
|
423
|
+
entry,
|
|
424
|
+
"boards",
|
|
425
|
+
"gpu-daemon",
|
|
426
|
+
"--browser",
|
|
427
|
+
browser
|
|
428
|
+
], {
|
|
429
|
+
detached: true,
|
|
430
|
+
stdio: "ignore",
|
|
431
|
+
env: process.env
|
|
432
|
+
}).unref();
|
|
433
|
+
}
|
|
434
|
+
function connect(path) {
|
|
435
|
+
return new Promise((resolve, reject) => {
|
|
436
|
+
const socket = createConnection(path, () => resolve(socket));
|
|
437
|
+
socket.once("error", reject);
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
async function connectBoardGpu(resources, options) {
|
|
441
|
+
if (process.env.COHUB_BOARD_GPU_DAEMON === "0") return null;
|
|
442
|
+
const path = boardGpuSocket(options.browser);
|
|
443
|
+
let socket = await connect(path).catch(() => null);
|
|
444
|
+
if (!socket) {
|
|
445
|
+
try {
|
|
446
|
+
startDaemon(options.browser);
|
|
447
|
+
} catch {
|
|
448
|
+
return null;
|
|
449
|
+
}
|
|
450
|
+
for (const started = Date.now(); !socket && Date.now() - started < CONNECT_MS;) {
|
|
451
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
452
|
+
socket = await connect(path).catch(() => null);
|
|
453
|
+
}
|
|
454
|
+
if (!socket) return null;
|
|
455
|
+
}
|
|
456
|
+
const connected = socket;
|
|
457
|
+
const pending = /* @__PURE__ */ new Map();
|
|
458
|
+
let next = 0;
|
|
459
|
+
let granted = () => {};
|
|
460
|
+
const turn = new Promise((resolve) => {
|
|
461
|
+
granted = resolve;
|
|
462
|
+
});
|
|
463
|
+
const fail = (error) => {
|
|
464
|
+
granted(false);
|
|
465
|
+
for (const waiting of pending.values()) waiting.reject(error);
|
|
466
|
+
pending.clear();
|
|
467
|
+
};
|
|
468
|
+
const send = lines(connected, (message) => {
|
|
469
|
+
if ("granted" in message) return granted(true);
|
|
470
|
+
if ("ask" in message) {
|
|
471
|
+
answer(message.request).then((reply) => send({
|
|
472
|
+
answer: message.ask,
|
|
473
|
+
...reply
|
|
474
|
+
}));
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
if ("id" in message && !("method" in message)) {
|
|
478
|
+
const waiting = pending.get(message.id);
|
|
479
|
+
pending.delete(message.id);
|
|
480
|
+
if (message.error !== void 0) waiting?.reject(new Error(message.error));
|
|
481
|
+
else waiting?.resolve(message.result);
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
connected.on("close", () => fail(/* @__PURE__ */ new Error("The shared browser closed.")));
|
|
485
|
+
connected.on("error", (error) => fail(error));
|
|
486
|
+
options.signal?.addEventListener("abort", () => connected.destroy(), { once: true });
|
|
487
|
+
const timer = setTimeout(() => granted(false), TURN_MS);
|
|
488
|
+
const ours = await turn;
|
|
489
|
+
clearTimeout(timer);
|
|
490
|
+
if (!ours) {
|
|
491
|
+
connected.destroy();
|
|
492
|
+
return null;
|
|
493
|
+
}
|
|
494
|
+
async function answer(request) {
|
|
495
|
+
try {
|
|
496
|
+
if (request.kind === "module") return { text: await resources.readModule(request.path) };
|
|
497
|
+
const picture = await resources.readPicture(request.request);
|
|
498
|
+
return picture ? {
|
|
499
|
+
bytes: Buffer.from(picture.bytes).toString("base64"),
|
|
500
|
+
mimeType: picture.mimeType
|
|
501
|
+
} : { missing: true };
|
|
502
|
+
} catch (error) {
|
|
503
|
+
return { error: error instanceof Error ? error.message : String(error) };
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
const request = (method, params) => {
|
|
507
|
+
if (connected.destroyed) return Promise.reject(/* @__PURE__ */ new Error("The shared browser closed."));
|
|
508
|
+
const id = ++next;
|
|
509
|
+
return new Promise((resolve, reject) => {
|
|
510
|
+
pending.set(id, {
|
|
511
|
+
resolve,
|
|
512
|
+
reject
|
|
513
|
+
});
|
|
514
|
+
send({
|
|
515
|
+
id,
|
|
516
|
+
method,
|
|
517
|
+
params
|
|
518
|
+
});
|
|
519
|
+
});
|
|
520
|
+
};
|
|
521
|
+
return {
|
|
522
|
+
browser: options.browser,
|
|
523
|
+
init: (init) => request("init", init),
|
|
524
|
+
compile: (shaders) => request("compile", shaders),
|
|
525
|
+
profile: (input) => request("profile", input),
|
|
526
|
+
async render(frame) {
|
|
527
|
+
const { data, ...rest } = await request("render", frame);
|
|
528
|
+
return {
|
|
529
|
+
...rest,
|
|
530
|
+
bytes: new Uint8Array(Buffer.from(data, "base64"))
|
|
531
|
+
};
|
|
532
|
+
},
|
|
533
|
+
async close() {
|
|
534
|
+
connected.end();
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
async function openBoardGpu(resources, options) {
|
|
539
|
+
const shared = await connectBoardGpu(resources, options).catch(() => null);
|
|
540
|
+
if (shared) return shared;
|
|
541
|
+
options.signal?.throwIfAborted();
|
|
542
|
+
return launchBoardGpuExporter(resources, options);
|
|
543
|
+
}
|
|
544
|
+
//#endregion
|
|
545
|
+
export { findBoardGpuBrowser as a, serveBoardGpu as i, connectBoardGpu as n, openBoardGpu as r, boardGpuSocket as t };
|