@neta-art/cohub-cli 10.24.0 → 10.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/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 +309 -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 +2511 -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
package/dist/host/runtime.js
DELETED
|
@@ -1,395 +0,0 @@
|
|
|
1
|
-
import { spawn } from "node:child_process";
|
|
2
|
-
import { existsSync, mkdirSync, watch } from "node:fs";
|
|
3
|
-
import { opendir, readdir, realpath, stat } from "node:fs/promises";
|
|
4
|
-
import { homedir } from "node:os";
|
|
5
|
-
import { basename, dirname, join, relative, sep } from "node:path";
|
|
6
|
-
import { EXPECTED_IDENTITY_ENV } from "../runtime/launch.js";
|
|
7
|
-
import { controlRuntimeInstance, requestRuntimeInstance, runtimeInstanceDirectory, runtimeInstancesRoot, stopRuntimeInstance, UNCONFIRMED_WORK, watchRuntimeInstance } from "../runtime/instance.js";
|
|
8
|
-
import { readRuntimePreferences, writeRuntimePreferences } from "../runtime/preferences.js";
|
|
9
|
-
import { readRuntimeSpaceBindings, runtimeSpaceBindingsPath } from "../runtime/space-binding.js";
|
|
10
|
-
import { forgetHostRuntime, hostRuntimes, rememberHostRuntime } from "./runtimes.js";
|
|
11
|
-
const MAX_INSTANCES = 256;
|
|
12
|
-
const MAX_FOLDERS = 10_000;
|
|
13
|
-
const MAX_VOLUMES = 16;
|
|
14
|
-
const DISPLAY_CONTROL_MS = 15_000;
|
|
15
|
-
const SHARED_SCREEN = "auto";
|
|
16
|
-
const NO_SCREEN = "";
|
|
17
|
-
const isRunningState = (state) => state === "connecting" || state === "ready";
|
|
18
|
-
const isRunning = (instance) => isRunningState(instance?.state);
|
|
19
|
-
const samePath = (a, b) => process.platform === "win32" ? a.toLowerCase() === b.toLowerCase() : a === b;
|
|
20
|
-
function deviceState(status) {
|
|
21
|
-
if (!status || status.state === "stopping")
|
|
22
|
-
return "stopped";
|
|
23
|
-
if (status.state === "ready")
|
|
24
|
-
return "ready";
|
|
25
|
-
return status.state === "attention" ? "error" : "connecting";
|
|
26
|
-
}
|
|
27
|
-
const isDenied = (error) => ["EPERM", "EACCES"].includes(error.code ?? "");
|
|
28
|
-
function launchFailure(message) {
|
|
29
|
-
if (/non-elevated/.test(message))
|
|
30
|
-
return "elevated";
|
|
31
|
-
if (/EPERM|EACCES|permission denied|operation not permitted/i.test(message))
|
|
32
|
-
return "folder_denied";
|
|
33
|
-
if (/fetch failed|ENOTFOUND|ECONNREFUSED|ETIMEDOUT|EAI_AGAIN|Download of \S+ (failed|timed out)/.test(message))
|
|
34
|
-
return "offline";
|
|
35
|
-
return "failed";
|
|
36
|
-
}
|
|
37
|
-
function hasWindowsShell(env = process.env) {
|
|
38
|
-
if (env.COHUB_BASH)
|
|
39
|
-
return true;
|
|
40
|
-
const roots = [env.ProgramFiles, env["ProgramFiles(x86)"], env.LOCALAPPDATA && join(env.LOCALAPPDATA, "Programs")];
|
|
41
|
-
const directories = (env.PATH ?? env.Path ?? "").split(";").filter((entry) => /[\\/]git[\\/]/i.test(entry));
|
|
42
|
-
return [...roots.flatMap((root) => root ? [join(root, "Git", "bin", "bash.exe")] : []), ...directories.map((entry) => join(entry, "bash.exe")), ...directories.map((entry) => join(dirname(entry), "bin", "bash.exe"))].some((path) => existsSync(path));
|
|
43
|
-
}
|
|
44
|
-
function displayPath(path, home = homedir()) {
|
|
45
|
-
if (process.platform === "win32")
|
|
46
|
-
return path;
|
|
47
|
-
const inside = relative(home, path);
|
|
48
|
-
if (!inside)
|
|
49
|
-
return "~";
|
|
50
|
-
return inside.startsWith("..") || inside.startsWith(sep) ? path : `~/${inside}`;
|
|
51
|
-
}
|
|
52
|
-
async function isDirectory(path) {
|
|
53
|
-
return stat(path).then((info) => info.isDirectory(), () => false);
|
|
54
|
-
}
|
|
55
|
-
async function volumes() {
|
|
56
|
-
const home = homedir();
|
|
57
|
-
const homeVolume = { path: home, label: basename(home) || home };
|
|
58
|
-
if (process.platform === "win32") {
|
|
59
|
-
const drives = await Promise.all([..."CDEFGHIJKLMNOPQRSTUVWXYZ"].map(async (letter) => {
|
|
60
|
-
const path = `${letter}:\\`;
|
|
61
|
-
return await isDirectory(path) ? { path, label: `${letter}:` } : null;
|
|
62
|
-
}));
|
|
63
|
-
return [homeVolume, ...drives.filter((drive) => drive !== null)].slice(0, MAX_VOLUMES);
|
|
64
|
-
}
|
|
65
|
-
if (process.platform === "darwin") {
|
|
66
|
-
const mounted = await readdir("/Volumes").catch(() => []);
|
|
67
|
-
const resolved = await Promise.all(mounted.map(async (name) => {
|
|
68
|
-
const path = await realpath(join("/Volumes", name)).catch(() => null);
|
|
69
|
-
return path ? { path, label: name } : null;
|
|
70
|
-
}));
|
|
71
|
-
return [homeVolume, ...resolved.filter((volume) => volume !== null)].slice(0, MAX_VOLUMES);
|
|
72
|
-
}
|
|
73
|
-
return [homeVolume, { path: "/", label: "/" }];
|
|
74
|
-
}
|
|
75
|
-
export class DeviceRuntimeHost {
|
|
76
|
-
emit;
|
|
77
|
-
options;
|
|
78
|
-
#watchers = [];
|
|
79
|
-
#subscriptions = new Map();
|
|
80
|
-
#debounce;
|
|
81
|
-
#published = "";
|
|
82
|
-
#restoring = Promise.resolve();
|
|
83
|
-
#unwatchable = new Set();
|
|
84
|
-
#transient = new Map();
|
|
85
|
-
#screen = { sharedWith: null, control: false, error: null };
|
|
86
|
-
#publishedScreen = "";
|
|
87
|
-
#shared = new Set();
|
|
88
|
-
#screenWork = Promise.resolve();
|
|
89
|
-
constructor(emit, options) {
|
|
90
|
-
this.emit = emit;
|
|
91
|
-
this.options = options;
|
|
92
|
-
}
|
|
93
|
-
watch() {
|
|
94
|
-
this.#watch();
|
|
95
|
-
void this.restore();
|
|
96
|
-
}
|
|
97
|
-
close() {
|
|
98
|
-
clearTimeout(this.#debounce);
|
|
99
|
-
for (const watcher of this.#watchers)
|
|
100
|
-
watcher.close();
|
|
101
|
-
for (const subscription of this.#subscriptions.values())
|
|
102
|
-
subscription.abort();
|
|
103
|
-
}
|
|
104
|
-
#watch() {
|
|
105
|
-
const bindings = runtimeSpaceBindingsPath();
|
|
106
|
-
const instances = runtimeInstancesRoot();
|
|
107
|
-
mkdirSync(dirname(bindings), { recursive: true, mode: 0o700 });
|
|
108
|
-
mkdirSync(instances, { recursive: true, mode: 0o700 });
|
|
109
|
-
const watchers = [
|
|
110
|
-
watch(dirname(bindings), (_event, name) => { if (!name || name === basename(bindings))
|
|
111
|
-
this.changed(); }),
|
|
112
|
-
watch(instances, { recursive: true }, () => this.changed()),
|
|
113
|
-
];
|
|
114
|
-
this.#watchers = watchers;
|
|
115
|
-
const rewatch = () => {
|
|
116
|
-
if (this.#watchers !== watchers)
|
|
117
|
-
return;
|
|
118
|
-
this.#watchers = [];
|
|
119
|
-
for (const watcher of watchers)
|
|
120
|
-
watcher.close();
|
|
121
|
-
setTimeout(() => { this.#watch(); this.changed(); }, 1_000).unref();
|
|
122
|
-
};
|
|
123
|
-
for (const watcher of watchers)
|
|
124
|
-
watcher.on("error", rewatch);
|
|
125
|
-
}
|
|
126
|
-
changed() {
|
|
127
|
-
clearTimeout(this.#debounce);
|
|
128
|
-
this.#debounce = setTimeout(() => void this.#publish().catch(() => undefined), 100);
|
|
129
|
-
}
|
|
130
|
-
async list() {
|
|
131
|
-
const key = this.options.account();
|
|
132
|
-
if (!key)
|
|
133
|
-
return { instances: [] };
|
|
134
|
-
const bindings = (await readRuntimeSpaceBindings().catch(() => ({ bindings: [] }))).bindings;
|
|
135
|
-
const roots = new Map();
|
|
136
|
-
for (const binding of bindings) {
|
|
137
|
-
if (binding.key !== key)
|
|
138
|
-
continue;
|
|
139
|
-
roots.delete(binding.spaceId);
|
|
140
|
-
roots.set(binding.spaceId, binding.root);
|
|
141
|
-
}
|
|
142
|
-
for (const [spaceId, { root }] of this.#transient)
|
|
143
|
-
if (!roots.has(spaceId))
|
|
144
|
-
roots.set(spaceId, root);
|
|
145
|
-
let screen = { sharedWith: null, control: false, error: null };
|
|
146
|
-
const shared = new Set();
|
|
147
|
-
const hasShell = process.platform !== "win32" || hasWindowsShell();
|
|
148
|
-
const instances = await Promise.all([...roots].slice(-MAX_INSTANCES).map(async ([spaceId, root]) => {
|
|
149
|
-
const directory = runtimeInstanceDirectory(key, spaceId);
|
|
150
|
-
const transient = this.#transient.get(spaceId);
|
|
151
|
-
try {
|
|
152
|
-
const status = await requestRuntimeInstance(directory);
|
|
153
|
-
if (!status && transient)
|
|
154
|
-
return { spaceId, ...transient, label: displayPath(transient.root) };
|
|
155
|
-
if (status)
|
|
156
|
-
this.#subscribe(directory, status.pid);
|
|
157
|
-
if (status?.display) {
|
|
158
|
-
const needs = status.displayNeeds ?? [];
|
|
159
|
-
if (status.displayOnRequest)
|
|
160
|
-
shared.add(spaceId);
|
|
161
|
-
screen = { sharedWith: spaceId, control: !needs.includes("accessibility"), error: needs.includes("screenRecording") ? "screen_recording" : null };
|
|
162
|
-
}
|
|
163
|
-
const path = status?.root ?? root;
|
|
164
|
-
const state = deviceState(status);
|
|
165
|
-
return { spaceId, root: path, label: displayPath(path), state, error: status?.state === "attention" ? "attention" : isRunningState(state) && !hasShell ? "no_shell" : null };
|
|
166
|
-
}
|
|
167
|
-
catch {
|
|
168
|
-
return { spaceId, root, label: displayPath(root), state: "error", error: "unreachable" };
|
|
169
|
-
}
|
|
170
|
-
}));
|
|
171
|
-
this.#screen = screen;
|
|
172
|
-
this.#shared = shared;
|
|
173
|
-
return { instances };
|
|
174
|
-
}
|
|
175
|
-
async browse(path) {
|
|
176
|
-
const target = await realpath(path ?? homedir());
|
|
177
|
-
if (!await isDirectory(target))
|
|
178
|
-
throw new Error("Not a folder");
|
|
179
|
-
const entries = await readdir(target, { withFileTypes: true });
|
|
180
|
-
const folders = (await Promise.all(entries.map(async (entry) => {
|
|
181
|
-
if (entry.name.startsWith("."))
|
|
182
|
-
return null;
|
|
183
|
-
const folder = join(target, entry.name);
|
|
184
|
-
const directory = entry.isDirectory() || (entry.isSymbolicLink() && await isDirectory(folder));
|
|
185
|
-
return directory ? { name: entry.name, path: folder } : null;
|
|
186
|
-
})))
|
|
187
|
-
.filter((folder) => folder !== null)
|
|
188
|
-
.sort((a, b) => a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: "base" }))
|
|
189
|
-
.slice(0, MAX_FOLDERS);
|
|
190
|
-
const key = this.options.account();
|
|
191
|
-
const bindings = key ? (await readRuntimeSpaceBindings().catch(() => ({ bindings: [] }))).bindings : [];
|
|
192
|
-
const parent = dirname(target);
|
|
193
|
-
return {
|
|
194
|
-
path: target,
|
|
195
|
-
label: displayPath(target),
|
|
196
|
-
parent: parent === target ? null : parent,
|
|
197
|
-
spaceId: bindings.filter((binding) => binding.key === key && samePath(binding.root, target)).at(-1)?.spaceId ?? null,
|
|
198
|
-
folders,
|
|
199
|
-
volumes: await volumes(),
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
async connect(spaceId, root) {
|
|
203
|
-
const key = this.options.account();
|
|
204
|
-
if (!key)
|
|
205
|
-
throw new Error("Sign in first");
|
|
206
|
-
const folder = await realpath(root).catch(() => null);
|
|
207
|
-
const current = await this.list();
|
|
208
|
-
if (!folder || !await isDirectory(folder))
|
|
209
|
-
return { ...current, refused: "folder_unavailable" };
|
|
210
|
-
const serving = current.instances.find((instance) => instance.spaceId === spaceId);
|
|
211
|
-
if (isRunning(serving))
|
|
212
|
-
return { ...current, refused: samePath(serving.root, folder) ? null : "space_in_use" };
|
|
213
|
-
if (current.instances.some((instance) => isRunning(instance) && samePath(instance.root, folder)))
|
|
214
|
-
return { ...current, refused: "folder_in_use" };
|
|
215
|
-
const denied = await opendir(folder).then((directory) => directory.close().then(() => false), isDenied);
|
|
216
|
-
if (denied)
|
|
217
|
-
return { ...current, refused: "folder_denied" };
|
|
218
|
-
this.#transient.set(spaceId, { root: folder, state: "connecting", error: null });
|
|
219
|
-
void this.#publish().catch(() => undefined);
|
|
220
|
-
try {
|
|
221
|
-
await this.#launch(key, spaceId, folder);
|
|
222
|
-
await rememberHostRuntime({ key, spaceId, root: folder });
|
|
223
|
-
this.#transient.delete(spaceId);
|
|
224
|
-
}
|
|
225
|
-
catch (error) {
|
|
226
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
227
|
-
process.stderr.write(`Could not connect ${folder}: ${message}\n`);
|
|
228
|
-
this.#transient.set(spaceId, { root: folder, state: "error", error: launchFailure(message) });
|
|
229
|
-
}
|
|
230
|
-
return { ...await this.#publish(), refused: null };
|
|
231
|
-
}
|
|
232
|
-
async disconnect(spaceId, force = false) {
|
|
233
|
-
const key = this.options.account();
|
|
234
|
-
if (!key)
|
|
235
|
-
throw new Error("Sign in first");
|
|
236
|
-
this.#transient.delete(spaceId);
|
|
237
|
-
try {
|
|
238
|
-
await stopRuntimeInstance(runtimeInstanceDirectory(key, spaceId), force);
|
|
239
|
-
}
|
|
240
|
-
catch (error) {
|
|
241
|
-
if (error instanceof Error && error.message.startsWith(UNCONFIRMED_WORK))
|
|
242
|
-
return { ...await this.list(), refused: "unconfirmed_work" };
|
|
243
|
-
throw error;
|
|
244
|
-
}
|
|
245
|
-
await forgetHostRuntime(key, spaceId);
|
|
246
|
-
return { ...await this.#publish(), refused: null };
|
|
247
|
-
}
|
|
248
|
-
async stopAccount() {
|
|
249
|
-
const key = this.options.account();
|
|
250
|
-
if (!key)
|
|
251
|
-
return;
|
|
252
|
-
const { instances } = await this.list();
|
|
253
|
-
await Promise.allSettled(instances.filter(isRunning).map((instance) => stopRuntimeInstance(runtimeInstanceDirectory(key, instance.spaceId), true)));
|
|
254
|
-
this.accountChanged();
|
|
255
|
-
}
|
|
256
|
-
accountChanged() {
|
|
257
|
-
this.#transient.clear();
|
|
258
|
-
}
|
|
259
|
-
async displayStatus() {
|
|
260
|
-
await this.list();
|
|
261
|
-
return this.#screen;
|
|
262
|
-
}
|
|
263
|
-
#serialScreen(work) {
|
|
264
|
-
const run = this.#screenWork.then(work);
|
|
265
|
-
this.#screenWork = run.catch(() => undefined);
|
|
266
|
-
return run;
|
|
267
|
-
}
|
|
268
|
-
share(spaceId) {
|
|
269
|
-
return this.#serialScreen(async () => {
|
|
270
|
-
const key = this.options.account();
|
|
271
|
-
if (!key)
|
|
272
|
-
throw new Error("Sign in first");
|
|
273
|
-
const { instances } = await this.list();
|
|
274
|
-
if (!isRunning(instances.find((instance) => instance.spaceId === spaceId)))
|
|
275
|
-
throw new Error("This device does not serve that Space");
|
|
276
|
-
const previous = this.#screen.sharedWith;
|
|
277
|
-
if (previous && previous !== spaceId)
|
|
278
|
-
await this.#setScreen(key, previous, NO_SCREEN);
|
|
279
|
-
await this.#setScreen(key, spaceId, SHARED_SCREEN);
|
|
280
|
-
await this.#publish();
|
|
281
|
-
return this.#screen;
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
stopSharing() {
|
|
285
|
-
return this.#serialScreen(async () => {
|
|
286
|
-
const key = this.options.account();
|
|
287
|
-
if (!key)
|
|
288
|
-
throw new Error("Sign in first");
|
|
289
|
-
await this.list();
|
|
290
|
-
if (this.#screen.sharedWith)
|
|
291
|
-
await this.#setScreen(key, this.#screen.sharedWith, NO_SCREEN);
|
|
292
|
-
await this.#publish();
|
|
293
|
-
return this.#screen;
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
stopOwnSharing() {
|
|
297
|
-
return this.#serialScreen(async () => {
|
|
298
|
-
const key = this.options.account();
|
|
299
|
-
if (!key)
|
|
300
|
-
return;
|
|
301
|
-
await this.list();
|
|
302
|
-
const results = await Promise.allSettled([...this.#shared].map((spaceId) => this.#setScreen(key, spaceId, NO_SCREEN)));
|
|
303
|
-
for (const result of results)
|
|
304
|
-
if (result.status === "rejected")
|
|
305
|
-
process.stderr.write(`Could not stop sharing the screen: ${String(result.reason)}\n`);
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
async keepAwake(enabled) {
|
|
309
|
-
if (enabled === undefined)
|
|
310
|
-
return (await readRuntimePreferences()).keepAwake;
|
|
311
|
-
await writeRuntimePreferences({ keepAwake: enabled });
|
|
312
|
-
const key = this.options.account();
|
|
313
|
-
if (key) {
|
|
314
|
-
const { instances } = await this.list();
|
|
315
|
-
await Promise.allSettled(instances.filter(isRunning).map((instance) => controlRuntimeInstance(runtimeInstanceDirectory(key, instance.spaceId), "keepAwake")));
|
|
316
|
-
}
|
|
317
|
-
return enabled;
|
|
318
|
-
}
|
|
319
|
-
async #setScreen(key, spaceId, spec) {
|
|
320
|
-
await controlRuntimeInstance(runtimeInstanceDirectory(key, spaceId), "display", { spec }, DISPLAY_CONTROL_MS);
|
|
321
|
-
}
|
|
322
|
-
restore() {
|
|
323
|
-
this.#restoring = this.#restoring.then(async () => {
|
|
324
|
-
const key = this.options.account();
|
|
325
|
-
if (!key)
|
|
326
|
-
return;
|
|
327
|
-
// A failed read skips this restore; nothing is forgotten.
|
|
328
|
-
const { bindings } = await readRuntimeSpaceBindings();
|
|
329
|
-
for (const item of await hostRuntimes(key)) {
|
|
330
|
-
const bound = bindings.filter((binding) => binding.key === key && binding.spaceId === item.spaceId).at(-1);
|
|
331
|
-
if (!bound || !samePath(bound.root, item.root)) {
|
|
332
|
-
await forgetHostRuntime(key, item.spaceId);
|
|
333
|
-
continue;
|
|
334
|
-
}
|
|
335
|
-
const running = await requestRuntimeInstance(runtimeInstanceDirectory(key, item.spaceId)).catch(() => true);
|
|
336
|
-
if (running || !await isDirectory(item.root))
|
|
337
|
-
continue;
|
|
338
|
-
await this.#launch(key, item.spaceId, item.root).catch((error) => {
|
|
339
|
-
process.stderr.write(`Could not reconnect ${item.root}: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
340
|
-
});
|
|
341
|
-
}
|
|
342
|
-
}).catch((error) => {
|
|
343
|
-
process.stderr.write(`Could not restore connected folders: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
344
|
-
}).finally(() => this.changed());
|
|
345
|
-
return this.#restoring;
|
|
346
|
-
}
|
|
347
|
-
async #publish() {
|
|
348
|
-
const runtime = await this.list();
|
|
349
|
-
const serialized = JSON.stringify(runtime);
|
|
350
|
-
if (serialized !== this.#published) {
|
|
351
|
-
this.#published = serialized;
|
|
352
|
-
this.emit("runtime.changed", runtime);
|
|
353
|
-
}
|
|
354
|
-
const screen = JSON.stringify(this.#screen);
|
|
355
|
-
if (screen !== this.#publishedScreen) {
|
|
356
|
-
this.#publishedScreen = screen;
|
|
357
|
-
this.emit("display.changed", this.#screen);
|
|
358
|
-
}
|
|
359
|
-
return runtime;
|
|
360
|
-
}
|
|
361
|
-
#subscribe(directory, pid) {
|
|
362
|
-
const instance = `${directory}:${pid}`;
|
|
363
|
-
if (this.#subscriptions.has(directory) || this.#unwatchable.has(instance))
|
|
364
|
-
return;
|
|
365
|
-
const controller = new AbortController();
|
|
366
|
-
this.#subscriptions.set(directory, controller);
|
|
367
|
-
void watchRuntimeInstance(directory, () => this.changed(), controller.signal).then((streamed) => {
|
|
368
|
-
if (!streamed)
|
|
369
|
-
this.#unwatchable.add(instance);
|
|
370
|
-
}, () => undefined).finally(() => {
|
|
371
|
-
if (this.#subscriptions.get(directory) === controller)
|
|
372
|
-
this.#subscriptions.delete(directory);
|
|
373
|
-
if (!controller.signal.aborted)
|
|
374
|
-
this.changed();
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
async #launch(key, spaceId, root) {
|
|
378
|
-
const env = await this.options.env();
|
|
379
|
-
if (this.options.account() !== key)
|
|
380
|
-
throw new Error("The signed-in account changed");
|
|
381
|
-
const child = spawn(process.execPath, [this.options.cli, "runtime", "up", root, "--space", spaceId, "--detach", "--yes", "--no-display", "--json"], {
|
|
382
|
-
env: { ...env, [EXPECTED_IDENTITY_ENV]: key }, stdio: ["ignore", "ignore", "pipe"], windowsHide: true,
|
|
383
|
-
});
|
|
384
|
-
let stderr = "";
|
|
385
|
-
child.stderr.setEncoding("utf8").on("data", (chunk) => { stderr = `${stderr}${chunk}`.slice(-8_192); });
|
|
386
|
-
const code = await new Promise((resolve, reject) => {
|
|
387
|
-
child.once("error", reject);
|
|
388
|
-
child.once("close", resolve);
|
|
389
|
-
});
|
|
390
|
-
if (code === 0 || code === 2)
|
|
391
|
-
return;
|
|
392
|
-
const reason = stderr.trim().split("\n").at(-1)?.replace(/^Runtime failed: /, "");
|
|
393
|
-
throw new Error(reason || `Runtime exited (${code})`);
|
|
394
|
-
}
|
|
395
|
-
}
|
package/dist/host/runtimes.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export type HostRuntime = {
|
|
2
|
-
key: string;
|
|
3
|
-
spaceId: string;
|
|
4
|
-
root: string;
|
|
5
|
-
};
|
|
6
|
-
export declare const hostRuntimesPath: () => string;
|
|
7
|
-
export declare const hostRuntimes: (key: string, path?: string) => Promise<HostRuntime[]>;
|
|
8
|
-
export declare const rememberHostRuntime: (runtime: HostRuntime, path?: string) => Promise<void>;
|
|
9
|
-
export declare const forgetHostRuntime: (key: string, spaceId: string, path?: string) => Promise<void>;
|
package/dist/host/runtimes.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
3
|
-
import { homedir } from "node:os";
|
|
4
|
-
import { dirname, join } from "node:path";
|
|
5
|
-
import { withRuntimeSpaceBindingsLock } from "../runtime/space-binding.js";
|
|
6
|
-
export const hostRuntimesPath = () => join(homedir(), ".local", "state", "cohub", "host", "runtimes.json");
|
|
7
|
-
// Only a missing file is empty; an unreadable one throws, so it is never overwritten.
|
|
8
|
-
async function read(path) {
|
|
9
|
-
let text;
|
|
10
|
-
try {
|
|
11
|
-
text = await readFile(path, "utf8");
|
|
12
|
-
}
|
|
13
|
-
catch (error) {
|
|
14
|
-
if (error.code === "ENOENT")
|
|
15
|
-
return [];
|
|
16
|
-
throw error;
|
|
17
|
-
}
|
|
18
|
-
const file = JSON.parse(text);
|
|
19
|
-
if (file.version !== 1 || !Array.isArray(file.runtimes))
|
|
20
|
-
throw new Error(`Unsupported desktop Runtime state: ${path}`);
|
|
21
|
-
return file.runtimes.filter((item) => typeof item?.key === "string" && typeof item.spaceId === "string" && typeof item.root === "string");
|
|
22
|
-
}
|
|
23
|
-
async function update(path, change) {
|
|
24
|
-
await withRuntimeSpaceBindingsLock(async () => {
|
|
25
|
-
const before = await read(path);
|
|
26
|
-
const after = change(before);
|
|
27
|
-
if (JSON.stringify(after) === JSON.stringify(before))
|
|
28
|
-
return;
|
|
29
|
-
await mkdir(dirname(path), { recursive: true, mode: 0o700 });
|
|
30
|
-
const temporary = `${path}.${randomUUID()}.tmp`;
|
|
31
|
-
try {
|
|
32
|
-
await writeFile(temporary, `${JSON.stringify({ version: 1, runtimes: after }, null, 2)}\n`, { mode: 0o600, flag: "wx" });
|
|
33
|
-
await rename(temporary, path);
|
|
34
|
-
}
|
|
35
|
-
finally {
|
|
36
|
-
await rm(temporary, { force: true });
|
|
37
|
-
}
|
|
38
|
-
}, { path });
|
|
39
|
-
}
|
|
40
|
-
export const hostRuntimes = (key, path = hostRuntimesPath()) => read(path).then((runtimes) => runtimes.filter((item) => item.key === key));
|
|
41
|
-
export const rememberHostRuntime = (runtime, path = hostRuntimesPath()) => update(path, (runtimes) => [...runtimes.filter((item) => item.key !== runtime.key || item.spaceId !== runtime.spaceId), runtime]);
|
|
42
|
-
export const forgetHostRuntime = (key, spaceId, path = hostRuntimesPath()) => update(path, (runtimes) => runtimes.filter((item) => item.key !== key || item.spaceId !== spaceId));
|
package/dist/host/serve.d.ts
DELETED
package/dist/host/serve.js
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { createInterface } from "node:readline";
|
|
2
|
-
import { fileURLToPath } from "node:url";
|
|
3
|
-
import { HOST_BRIDGE_ERROR, HOST_BRIDGE_METHODS, HOST_SERVICE_CLI_ABOUT, HOST_SERVICE_VERSION, HOST_SERVICE_WORKSPACE_ENDPOINT, HostBridgeErrorClass, hostBridgeRequestSchema, } from "@neta-art/cohub/host-bridge";
|
|
4
|
-
import { describeCli } from "../about.js";
|
|
5
|
-
import { findLocalWorkspace } from "../runtime/local-workspace.js";
|
|
6
|
-
import { currentIdentityKey } from "../space.js";
|
|
7
|
-
import { HostAuth } from "./auth.js";
|
|
8
|
-
import { loginShellEnv } from "./login-env.js";
|
|
9
|
-
import { DeviceRuntimeHost } from "./runtime.js";
|
|
10
|
-
import { callLocalWorkspace } from "./workspaces.js";
|
|
11
|
-
const SCREEN_PLATFORMS = ["darwin", "win32"];
|
|
12
|
-
const CAPABILITIES = ["auth.token", "auth.signIn", "auth.session", "runtime", "runtime.keepAwake", "workspace", ...(SCREEN_PLATFORMS.includes(process.platform) ? ["display"] : [])];
|
|
13
|
-
const SPACE_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
14
|
-
// Shells re-encode requests, and may escape what the page sized as one byte into six.
|
|
15
|
-
const MAX_LINE = 8 * 1024 * 1024;
|
|
16
|
-
const write = (message) => process.stdout.write(`${JSON.stringify(message)}\n`);
|
|
17
|
-
export async function serveHost(entry = fileURLToPath(new URL("../../bin/cohub.js", import.meta.url))) {
|
|
18
|
-
const emit = (name, payload) => write({ type: "event", name, ...(payload === undefined ? {} : { payload }) });
|
|
19
|
-
let environment = null;
|
|
20
|
-
const env = () => (environment ??= loginShellEnv());
|
|
21
|
-
const about = async () => describeCli(await env(), currentIdentityKey());
|
|
22
|
-
const runtime = new DeviceRuntimeHost(emit, {
|
|
23
|
-
cli: entry,
|
|
24
|
-
env,
|
|
25
|
-
account: currentIdentityKey,
|
|
26
|
-
});
|
|
27
|
-
const auth = new HostAuth(emit, () => {
|
|
28
|
-
runtime.accountChanged();
|
|
29
|
-
runtime.changed();
|
|
30
|
-
void runtime.restore();
|
|
31
|
-
});
|
|
32
|
-
const handlers = {
|
|
33
|
-
"auth.getAccessToken": (params) => auth.accessToken(params.forceRefresh === true),
|
|
34
|
-
"auth.getSessionVersion": () => auth.sessionVersion(),
|
|
35
|
-
"auth.getSession": () => auth.session(),
|
|
36
|
-
"auth.signIn": (params) => auth.signIn(typeof params.redirectPath === "string" ? params.redirectPath : undefined),
|
|
37
|
-
"auth.signOut": async () => {
|
|
38
|
-
await runtime.stopAccount().catch((error) => process.stderr.write(`Could not stop Runtimes before signing out: ${error instanceof Error ? error.message : String(error)}\n`));
|
|
39
|
-
return auth.signOut();
|
|
40
|
-
},
|
|
41
|
-
"runtime.list": () => runtime.list(),
|
|
42
|
-
"runtime.browse": (params) => runtime.browse(typeof params.path === "string" ? params.path : undefined),
|
|
43
|
-
"runtime.start": (params) => runtime.connect(String(params.spaceId), String(params.root)),
|
|
44
|
-
"runtime.stop": (params) => runtime.disconnect(String(params.spaceId), params.force === true),
|
|
45
|
-
"runtime.keepAwake": (params) => runtime.keepAwake(typeof params.enabled === "boolean" ? params.enabled : undefined),
|
|
46
|
-
...(CAPABILITIES.includes("display") ? {
|
|
47
|
-
"display.status": () => runtime.displayStatus(),
|
|
48
|
-
"display.share": (params) => runtime.share(String(params.spaceId)),
|
|
49
|
-
"display.stop": () => runtime.stopSharing(),
|
|
50
|
-
} : {}),
|
|
51
|
-
"workspace.call": (params) => callLocalWorkspace(String(params.spaceId), String(params.method), params.params),
|
|
52
|
-
};
|
|
53
|
-
// Asked by the shell itself; absent from hello, so a page can never reach them.
|
|
54
|
-
const shellHandlers = {
|
|
55
|
-
[HOST_SERVICE_CLI_ABOUT]: about,
|
|
56
|
-
[HOST_SERVICE_WORKSPACE_ENDPOINT]: (params) => {
|
|
57
|
-
const spaceId = String(params.spaceId ?? "");
|
|
58
|
-
if (!SPACE_ID.test(spaceId))
|
|
59
|
-
throw new Error("A Space id is required");
|
|
60
|
-
return findLocalWorkspace(spaceId);
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
const answer = async (line) => {
|
|
64
|
-
let raw;
|
|
65
|
-
try {
|
|
66
|
-
raw = JSON.parse(line);
|
|
67
|
-
}
|
|
68
|
-
catch {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
const request = hostBridgeRequestSchema.safeParse(raw);
|
|
72
|
-
if (!request.success)
|
|
73
|
-
return;
|
|
74
|
-
const { id, method } = request.data;
|
|
75
|
-
const fail = (code, message) => write({ type: "response", id, error: { code, message: message.slice(0, 2_000) || "Host call failed" } });
|
|
76
|
-
const name = method;
|
|
77
|
-
const shellHandler = Object.hasOwn(shellHandlers, method) ? shellHandlers[method] : undefined;
|
|
78
|
-
if (shellHandler) {
|
|
79
|
-
try {
|
|
80
|
-
write({ type: "response", id, result: await shellHandler((request.data.params ?? {})) ?? null });
|
|
81
|
-
}
|
|
82
|
-
catch (error) {
|
|
83
|
-
fail(HOST_BRIDGE_ERROR.failed, error instanceof Error ? error.message : String(error));
|
|
84
|
-
}
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
const handler = handlers[name];
|
|
88
|
-
if (!handler)
|
|
89
|
-
return fail(HOST_BRIDGE_ERROR.unsupported, `Unsupported method: ${method}`);
|
|
90
|
-
const shape = HOST_BRIDGE_METHODS[name];
|
|
91
|
-
const params = shape.params.safeParse(request.data.params);
|
|
92
|
-
if (!params.success)
|
|
93
|
-
return fail(HOST_BRIDGE_ERROR.failed, `Invalid params for ${method}`);
|
|
94
|
-
try {
|
|
95
|
-
const result = await handler((params.data ?? {}));
|
|
96
|
-
write({ type: "response", id, result: shape.result.parse(result) });
|
|
97
|
-
}
|
|
98
|
-
catch (error) {
|
|
99
|
-
const denied = ["EPERM", "EACCES"].includes(error.code ?? "");
|
|
100
|
-
const code = error instanceof HostBridgeErrorClass ? error.code : denied ? HOST_BRIDGE_ERROR.denied : HOST_BRIDGE_ERROR.failed;
|
|
101
|
-
fail(code, error instanceof Error ? error.message : String(error));
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
const hello = { type: "hello", version: HOST_SERVICE_VERSION, capabilities: [...CAPABILITIES], methods: Object.keys(handlers) };
|
|
105
|
-
write(hello);
|
|
106
|
-
auth.watch();
|
|
107
|
-
runtime.watch();
|
|
108
|
-
// Probed once off the start-up path, so an About panel opens with its answer ready.
|
|
109
|
-
setTimeout(() => void about().catch(() => undefined), 3_000).unref();
|
|
110
|
-
const input = createInterface({ input: process.stdin, crlfDelay: Infinity });
|
|
111
|
-
input.on("line", (line) => { if (line.length <= MAX_LINE)
|
|
112
|
-
void answer(line); });
|
|
113
|
-
await new Promise((resolve) => input.once("close", resolve));
|
|
114
|
-
auth.close();
|
|
115
|
-
await runtime.stopOwnSharing();
|
|
116
|
-
runtime.close();
|
|
117
|
-
}
|
package/dist/host/workspaces.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { HOST_BRIDGE_ERROR, HostBridgeErrorClass } from "@neta-art/cohub/host-bridge";
|
|
2
|
-
import { LocalWorkspaceRpcError, LocalWorkspaceUnavailableError } from "@neta-art/cohub";
|
|
3
|
-
import { connectLocalWorkspace, findLocalWorkspace } from "../runtime/local-workspace.js";
|
|
4
|
-
export async function callLocalWorkspace(spaceId, method, params) {
|
|
5
|
-
const endpoint = await findLocalWorkspace(spaceId);
|
|
6
|
-
if (endpoint) {
|
|
7
|
-
try {
|
|
8
|
-
return { result: await connectLocalWorkspace(endpoint).call(method, params ?? {}) };
|
|
9
|
-
}
|
|
10
|
-
catch (error) {
|
|
11
|
-
if (error instanceof LocalWorkspaceRpcError)
|
|
12
|
-
return { error: { code: error.rpcErrorCode, message: error.message.slice(0, 4_000) } };
|
|
13
|
-
if (!(error instanceof LocalWorkspaceUnavailableError))
|
|
14
|
-
throw error;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
throw new HostBridgeErrorClass(HOST_BRIDGE_ERROR.unavailable, "This device does not serve that Space");
|
|
18
|
-
}
|
package/dist/http-put.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export declare class HttpPutError extends Error {
|
|
2
|
-
readonly status: number;
|
|
3
|
-
readonly body: string;
|
|
4
|
-
constructor(message: string, status: number, body?: string);
|
|
5
|
-
}
|
|
6
|
-
export type PutRetryOptions = {
|
|
7
|
-
attempts?: number;
|
|
8
|
-
delayMs?: number;
|
|
9
|
-
sleep?: (ms: number) => Promise<void>;
|
|
10
|
-
fetch?: typeof fetch;
|
|
11
|
-
};
|
|
12
|
-
export declare function putLocalFile(input: PutRetryOptions & {
|
|
13
|
-
url: string;
|
|
14
|
-
filePath: string;
|
|
15
|
-
size: number;
|
|
16
|
-
headers?: HeadersInit;
|
|
17
|
-
label: string;
|
|
18
|
-
}): Promise<void>;
|
|
19
|
-
export declare function putBytes(input: PutRetryOptions & {
|
|
20
|
-
url: string;
|
|
21
|
-
body: Blob;
|
|
22
|
-
size?: number;
|
|
23
|
-
headers?: HeadersInit;
|
|
24
|
-
label: string;
|
|
25
|
-
}): Promise<void>;
|