@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
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { C as error, D as json, E as handleHttp, O as jsonRequested, _ as failSpaceTarget, at as DESKTOP_COMMAND_OPEN_TIMEOUT_MS, g as explicitSpace, it as DESKTOP_COMMAND_MAX_TIMEOUT_MS, k as ok, nt as DESKTOP_COMMAND_ACCEPT_TIMEOUT_MS, ot as resolveOpenSurface, rt as DESKTOP_COMMAND_DEFAULT_TIMEOUT_MS, t as createClient, x as resolveSpaceRef, y as resolveBoundSpace } from "./client.js";
|
|
2
|
+
import { s as HttpError } from "./app-realtime.js";
|
|
3
|
+
import { n as parseAppRef, t as getAppByRef } from "./app-ref.js";
|
|
4
|
+
import { readFileSync } from "node:fs";
|
|
5
|
+
//#region src/commands/desktop.ts
|
|
6
|
+
const FILE_SCHEME = "file://";
|
|
7
|
+
const APP_SCHEME = "app://";
|
|
8
|
+
const LEGACY_WORK_SCHEME = "work://";
|
|
9
|
+
/** Never falls back to Home, so a plain target stays eligible for App resolution. */
|
|
10
|
+
async function resolveOptionalSpaceId(command, options = {}) {
|
|
11
|
+
const explicit = explicitSpace(command);
|
|
12
|
+
if (explicit) return resolveSpaceRef(explicit).catch(failSpaceTarget);
|
|
13
|
+
return await resolveBoundSpace(options) ?? void 0;
|
|
14
|
+
}
|
|
15
|
+
function parseFilePath(value) {
|
|
16
|
+
const path = value.slice(7).trim();
|
|
17
|
+
if (!path || path.startsWith("/") || path.includes("\0") || path.split("/").some((segment) => segment === "..") || path.includes("\\")) return error("Invalid file path", "Use a relative Space path after file://.");
|
|
18
|
+
return path;
|
|
19
|
+
}
|
|
20
|
+
function hasFileScheme(value) {
|
|
21
|
+
return value.toLowerCase().startsWith(FILE_SCHEME);
|
|
22
|
+
}
|
|
23
|
+
function hasAppScheme(value) {
|
|
24
|
+
const lowered = value.toLowerCase();
|
|
25
|
+
return lowered.startsWith(APP_SCHEME) || lowered.startsWith(LEGACY_WORK_SCHEME);
|
|
26
|
+
}
|
|
27
|
+
function readCallInput(opts) {
|
|
28
|
+
if (opts.data !== void 0 && opts.input !== void 0) return error("Conflicting input", "Use either --data or --input, not both.");
|
|
29
|
+
const raw = opts.data !== void 0 ? opts.data : opts.input !== void 0 ? opts.input === "-" ? readFileSync(0, "utf-8") : readFileSync(opts.input, "utf-8") : void 0;
|
|
30
|
+
if (raw === void 0) return void 0;
|
|
31
|
+
try {
|
|
32
|
+
return JSON.parse(raw);
|
|
33
|
+
} catch {
|
|
34
|
+
return error("Invalid input", "Call input must be valid JSON.");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function parseTimeout(value) {
|
|
38
|
+
if (!value) return void 0;
|
|
39
|
+
const parsed = Math.floor(Number(value));
|
|
40
|
+
if (!Number.isFinite(parsed) || parsed <= 0 || parsed > 432e5) return error("Invalid timeout", `--timeout-ms must be between 1 and ${DESKTOP_COMMAND_MAX_TIMEOUT_MS} milliseconds.`);
|
|
41
|
+
return parsed;
|
|
42
|
+
}
|
|
43
|
+
async function resolveAppTarget(client, ref) {
|
|
44
|
+
const normalized = hasAppScheme(ref) ? ref.replace(/^[a-zA-Z]+:\/\//, "") : ref;
|
|
45
|
+
const parsed = parseAppRef(normalized);
|
|
46
|
+
const detail = await getAppByRef(client, normalized);
|
|
47
|
+
const declared = detail.app.meta?.presentation?.surface;
|
|
48
|
+
return {
|
|
49
|
+
kind: "app",
|
|
50
|
+
appId: detail.app.id,
|
|
51
|
+
label: detail.app.slug,
|
|
52
|
+
launch: {
|
|
53
|
+
...parsed.search ? { search: parsed.search } : {},
|
|
54
|
+
...parsed.hash ? { hash: parsed.hash } : {}
|
|
55
|
+
},
|
|
56
|
+
...declared === "overlay" || declared === "window" ? { surface: declared } : {}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
async function resolveOpenTarget(client, command, value) {
|
|
60
|
+
if (hasFileScheme(value)) return {
|
|
61
|
+
kind: "file",
|
|
62
|
+
path: parseFilePath(value)
|
|
63
|
+
};
|
|
64
|
+
if (hasAppScheme(value)) return resolveAppTarget(client, value);
|
|
65
|
+
const spaceId = await resolveOptionalSpaceId(command);
|
|
66
|
+
if (spaceId) try {
|
|
67
|
+
await client.space(spaceId).files.read(value);
|
|
68
|
+
return {
|
|
69
|
+
kind: "file",
|
|
70
|
+
path: value
|
|
71
|
+
};
|
|
72
|
+
} catch (cause) {
|
|
73
|
+
if (!(cause instanceof HttpError) || cause.status !== 404) throw cause;
|
|
74
|
+
}
|
|
75
|
+
return resolveAppTarget(client, value);
|
|
76
|
+
}
|
|
77
|
+
function reportDispatch(record) {
|
|
78
|
+
if (record.status !== "pending") {
|
|
79
|
+
reportOutcome(record, Boolean(record.command.call));
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
ok(`Desktop command dispatched (${record.commandId})`);
|
|
83
|
+
}
|
|
84
|
+
function reportOutcome(record, called) {
|
|
85
|
+
if (record.status === "applied") {
|
|
86
|
+
ok(called ? "App window shown and method called" : "Window shown");
|
|
87
|
+
if (record.result !== void 0) console.log(typeof record.result === "string" ? record.result : JSON.stringify(record.result, null, 2));
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
error(`Desktop command ${record.status}`, record.error?.message ?? "The Cohub desktop did not apply this command.");
|
|
91
|
+
}
|
|
92
|
+
async function openWindow(target, opts, command) {
|
|
93
|
+
const callInput = opts.call ? readCallInput(opts) : void 0;
|
|
94
|
+
if (!opts.call && (opts.data !== void 0 || opts.input !== void 0)) return error("Missing --call", "--data and --input only apply together with --call.");
|
|
95
|
+
if (opts.noWait && opts.timeoutMs !== void 0) return error("Conflicting wait options", "Use either --no-wait or --timeout-ms, not both.");
|
|
96
|
+
if (opts.as !== void 0 && opts.as !== "window" && opts.as !== "overlay") return error("Invalid surface", "--as must be one of: window, overlay.");
|
|
97
|
+
const timeoutMs = parseTimeout(opts.timeoutMs);
|
|
98
|
+
const client = createClient();
|
|
99
|
+
try {
|
|
100
|
+
const resolved = await resolveOpenTarget(client, command, target);
|
|
101
|
+
if (resolved.kind === "file" && opts.call) return error("Unsupported option", "--call only applies to app targets.");
|
|
102
|
+
if (resolved.kind === "file" && opts.as) return error("Unsupported option", "--as only applies to app targets.");
|
|
103
|
+
const call = opts.call ? {
|
|
104
|
+
method: opts.call,
|
|
105
|
+
...callInput === void 0 ? {} : { input: callInput }
|
|
106
|
+
} : void 0;
|
|
107
|
+
const input = {
|
|
108
|
+
command: {
|
|
109
|
+
type: "desktop.open",
|
|
110
|
+
target: resolved.kind === "file" ? resolved : {
|
|
111
|
+
kind: "app",
|
|
112
|
+
appId: resolved.appId,
|
|
113
|
+
label: resolved.label,
|
|
114
|
+
...resolved.launch.search || resolved.launch.hash ? { launch: resolved.launch } : {},
|
|
115
|
+
...resolveOpenSurface(opts.as, resolved.surface) ? { surface: "overlay" } : {}
|
|
116
|
+
},
|
|
117
|
+
...call ? { call } : {}
|
|
118
|
+
},
|
|
119
|
+
...opts.client ? { targetClientId: opts.client } : {},
|
|
120
|
+
...opts.commandId ? { commandId: opts.commandId } : {}
|
|
121
|
+
};
|
|
122
|
+
const record = opts.noWait ? (await client.desktop.create(input)).command : await client.desktop.run(input, { timeoutMs });
|
|
123
|
+
if (jsonRequested(opts)) return json(record);
|
|
124
|
+
if (opts.noWait) return reportDispatch(record);
|
|
125
|
+
reportOutcome(record, Boolean(call));
|
|
126
|
+
} catch (e) {
|
|
127
|
+
if (e instanceof Error && e.name === "AppRefParseError") return error(e.message);
|
|
128
|
+
handleHttp(e);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const OPEN_HELP = `
|
|
132
|
+
Commands reach only the desktop that originated the current chat, resolved
|
|
133
|
+
from request provenance. Nothing else can be targeted.
|
|
134
|
+
|
|
135
|
+
Examples:
|
|
136
|
+
cohub desktop open <app-or-file>
|
|
137
|
+
cohub desktop open file://src/main.ts
|
|
138
|
+
cohub desktop open app://alice/studio/launch
|
|
139
|
+
cohub desktop open alice/studio/launch
|
|
140
|
+
cohub desktop open https://cohub.live/alice/studio/w/launch?view=timeline
|
|
141
|
+
cohub desktop open <app-id> --as overlay
|
|
142
|
+
cohub desktop open <app-id> --call selection.get
|
|
143
|
+
cohub desktop open <app-id> --call board.focus --data '{"nodeId":"n1"}'
|
|
144
|
+
`;
|
|
145
|
+
const OPEN_NOTES = `
|
|
146
|
+
Notes:
|
|
147
|
+
- Use file:// and app:// to make the target explicit; the legacy work://
|
|
148
|
+
scheme is still accepted.
|
|
149
|
+
- A plain target checks the explicit Space or current directory Runtime binding for a file before resolving an app; it does not fall back to Home.
|
|
150
|
+
- Opening a window is idempotent; repeating it re-activates the same tab.
|
|
151
|
+
- A desktop that does not respond within ${DESKTOP_COMMAND_ACCEPT_TIMEOUT_MS / 1e3} seconds (closed, asleep, or
|
|
152
|
+
offline) fails fast with no_active_client instead of waiting out the timeout.
|
|
153
|
+
- --as picks the surface: window (a preview tab) or overlay (a transparent
|
|
154
|
+
layer above the workspace). Without it, an App published with
|
|
155
|
+
<meta name="cohub:surface" content="overlay"> opens as an overlay.
|
|
156
|
+
- --call waits for the app to announce readiness, then invokes the method.
|
|
157
|
+
- Which methods exist is up to the app author.
|
|
158
|
+
`;
|
|
159
|
+
function registerOpen(parent, deprecated) {
|
|
160
|
+
parent.command(deprecated ? "preview <app-or-file>" : "open <app-or-file>").description(deprecated ? "Deprecated: use `cohub desktop open`" : "Open a file or app window on the Cohub desktop, optionally calling an app method").option("--call <method>", "Method the app registered via client.app.surface.handle()").option("--data <json>", "Inline JSON input for --call").option("-i, --input <file>", "JSON input file for --call; use - for stdin").option("--client <clientId>", "Target a specific desktop instance of your account").option("--command-id <id>", "Stable id so retries never dispatch twice").option("--no-wait", "Dispatch the command and exit without waiting for a result").option("--as <surface>", "Surface role for app targets: window (default) or overlay").option("--timeout-ms <ms>", `How long to wait for the desktop (default: ${DESKTOP_COMMAND_OPEN_TIMEOUT_MS}, or ${DESKTOP_COMMAND_DEFAULT_TIMEOUT_MS} with --call; max: ${DESKTOP_COMMAND_MAX_TIMEOUT_MS})`).option("--json", "Output as JSON").action(async (target, opts, thisCommand) => {
|
|
161
|
+
if (deprecated) ok("Deprecated: `cohub ui preview` is now `cohub desktop open`.");
|
|
162
|
+
await openWindow(target, opts, thisCommand);
|
|
163
|
+
}).addHelpText("after", deprecated ? OPEN_NOTES : OPEN_HELP + OPEN_NOTES);
|
|
164
|
+
}
|
|
165
|
+
function registerDesktop(program) {
|
|
166
|
+
registerOpen(program.command("desktop").description("Drive the Cohub desktop that started this chat"), false);
|
|
167
|
+
}
|
|
168
|
+
function registerLegacyUi(program) {
|
|
169
|
+
registerOpen(program.command("ui", { hidden: true }).description("Deprecated: use `cohub desktop open`").addHelpText("after", OPEN_HELP), true);
|
|
170
|
+
}
|
|
171
|
+
//#endregion
|
|
172
|
+
export { registerDesktop, registerLegacyUi };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { i as normalizeBaseUrl } from "./environment.js";
|
|
2
|
+
import { i as InvalidArgumentError } from "./commander.js";
|
|
3
|
+
//#region src/endpoint-options.ts
|
|
4
|
+
function setApiBaseUrl(value) {
|
|
5
|
+
const url = normalizeBaseUrl(value);
|
|
6
|
+
if (!url) throw new InvalidArgumentError("API base URL must not be empty");
|
|
7
|
+
process.env.COHUB_BASE_URL = url;
|
|
8
|
+
return url;
|
|
9
|
+
}
|
|
10
|
+
function registerEndpointOptions(program) {
|
|
11
|
+
return program.option("--base-url <url>", "API base URL (overrides COHUB_BASE_URL)", setApiBaseUrl);
|
|
12
|
+
}
|
|
13
|
+
function consumeBaseUrlOption(tokens, index) {
|
|
14
|
+
const token = tokens[index];
|
|
15
|
+
if (token?.startsWith("--base-url=")) {
|
|
16
|
+
setApiBaseUrl(token.slice(11));
|
|
17
|
+
return index;
|
|
18
|
+
}
|
|
19
|
+
if (token !== "--base-url") return null;
|
|
20
|
+
const value = tokens[index + 1];
|
|
21
|
+
if (value === void 0) throw new InvalidArgumentError("--base-url requires a value");
|
|
22
|
+
setApiBaseUrl(value);
|
|
23
|
+
return index + 1;
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { registerEndpointOptions as n, consumeBaseUrlOption as t };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as http$1 from "node:http";
|
|
2
|
+
//#region src/env-proxy.ts
|
|
3
|
+
const PROXY_ENV_KEYS = [
|
|
4
|
+
"http_proxy",
|
|
5
|
+
"https_proxy",
|
|
6
|
+
"HTTP_PROXY",
|
|
7
|
+
"HTTPS_PROXY",
|
|
8
|
+
"all_proxy",
|
|
9
|
+
"ALL_PROXY"
|
|
10
|
+
];
|
|
11
|
+
const USE_ENV_PROXY_FLAG = "--use-env-proxy";
|
|
12
|
+
function proxyEnvPresent(env = process.env) {
|
|
13
|
+
return PROXY_ENV_KEYS.some((key) => Boolean(env[key]?.trim()));
|
|
14
|
+
}
|
|
15
|
+
function envProxyAlreadyEnabled(execArgv = process.execArgv, env = process.env) {
|
|
16
|
+
if (execArgv.includes(USE_ENV_PROXY_FLAG) || env.NODE_USE_ENV_PROXY === "1") return true;
|
|
17
|
+
return (env.NODE_OPTIONS ?? "").split(/\s+/).includes(USE_ENV_PROXY_FLAG);
|
|
18
|
+
}
|
|
19
|
+
function supportsUseEnvProxy(version = process.versions.node) {
|
|
20
|
+
const [major = 0, minor = 0] = version.split(".").map((part) => Number.parseInt(part, 10));
|
|
21
|
+
if (!Number.isFinite(major) || !Number.isFinite(minor)) return false;
|
|
22
|
+
return major >= 24 || major === 22 && minor >= 21;
|
|
23
|
+
}
|
|
24
|
+
function shouldRelaunchWithEnvProxy(execArgv = process.execArgv, env = process.env, nodeVersion = process.versions.node) {
|
|
25
|
+
return supportsUseEnvProxy(nodeVersion) && proxyEnvPresent(env) && !envProxyAlreadyEnabled(execArgv, env);
|
|
26
|
+
}
|
|
27
|
+
const envProxyExecArgv = [USE_ENV_PROXY_FLAG];
|
|
28
|
+
function enableEnvProxy() {
|
|
29
|
+
if (!shouldRelaunchWithEnvProxy()) return true;
|
|
30
|
+
if (typeof http$1.setGlobalProxyFromEnv !== "function") return false;
|
|
31
|
+
http$1.setGlobalProxyFromEnv();
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
export { envProxyExecArgv as n, enableEnvProxy as t };
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
//#region ../sdk/src/types.ts
|
|
2
|
+
/**
|
|
3
|
+
* The full permission vocabulary, mirrored from `@cohub/core` permissions.
|
|
4
|
+
* Kept as a runtime constant so hosts can validate untrusted scopes from
|
|
5
|
+
* app iframes — TypeScript unions cannot constrain cross-window messages.
|
|
6
|
+
*/
|
|
7
|
+
const PERMISSIONS = [
|
|
8
|
+
"space.view",
|
|
9
|
+
"space.edit",
|
|
10
|
+
"space.create",
|
|
11
|
+
"space.label.view",
|
|
12
|
+
"space.label.manage",
|
|
13
|
+
"space.label.assign",
|
|
14
|
+
"session.view",
|
|
15
|
+
"session.edit",
|
|
16
|
+
"session.prompt.readonly",
|
|
17
|
+
"session.prompt.fullaccess",
|
|
18
|
+
"session.access.manage",
|
|
19
|
+
"generation.create",
|
|
20
|
+
"file.view",
|
|
21
|
+
"file.view.filtered",
|
|
22
|
+
"file.edit",
|
|
23
|
+
"checkpoint.view",
|
|
24
|
+
"checkpoint.edit",
|
|
25
|
+
"member.view",
|
|
26
|
+
"member.manage",
|
|
27
|
+
"references.view",
|
|
28
|
+
"channel.view",
|
|
29
|
+
"channel.manage",
|
|
30
|
+
"cronjob.view",
|
|
31
|
+
"cronjob.manage",
|
|
32
|
+
"taskrun.view",
|
|
33
|
+
"command.execute",
|
|
34
|
+
"sandbox.view",
|
|
35
|
+
"sandbox.manage",
|
|
36
|
+
"mod.view",
|
|
37
|
+
"mod.manage",
|
|
38
|
+
"space.commerce.view",
|
|
39
|
+
"space.commerce.manage",
|
|
40
|
+
"app.manage",
|
|
41
|
+
"user.space.list",
|
|
42
|
+
"user.session.list",
|
|
43
|
+
"user.taskrun.list",
|
|
44
|
+
"user.usage.read"
|
|
45
|
+
];
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region ../sdk/src/environment.ts
|
|
48
|
+
const COHUB_ENVIRONMENTS = {
|
|
49
|
+
prod: {
|
|
50
|
+
apiBaseUrl: "https://api.cohub.live",
|
|
51
|
+
webBaseUrl: "https://cohub.live",
|
|
52
|
+
websocketUrl: "wss://gateway.cohub.live/ws",
|
|
53
|
+
voiceInputWebsocketUrl: "wss://gateway.cohub.live/asr/ws"
|
|
54
|
+
},
|
|
55
|
+
dev: {
|
|
56
|
+
apiBaseUrl: "https://api-dev.cohub.live",
|
|
57
|
+
webBaseUrl: "https://dev.cohub.live",
|
|
58
|
+
websocketUrl: "wss://gateway-dev.cohub.live/ws",
|
|
59
|
+
voiceInputWebsocketUrl: "wss://gateway-dev.cohub.live/asr/ws"
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const readProcessEnv = () => {
|
|
63
|
+
return globalThis.process?.env;
|
|
64
|
+
};
|
|
65
|
+
const readRuntimeEnv = () => readProcessEnv()?.ENV;
|
|
66
|
+
/** Existing scoped identity injected into Sandbox command processes. */
|
|
67
|
+
const resolveExecutionToken = () => readProcessEnv()?.COHUB_EXECUTION_TOKEN?.trim() || null;
|
|
68
|
+
function decodeJwtPayload(token) {
|
|
69
|
+
const encoded = token?.split(".")[1];
|
|
70
|
+
if (!encoded) return null;
|
|
71
|
+
try {
|
|
72
|
+
const base64 = encoded.replaceAll("-", "+").replaceAll("_", "/").padEnd(Math.ceil(encoded.length / 4) * 4, "=");
|
|
73
|
+
const decoded = JSON.parse(globalThis.atob(base64));
|
|
74
|
+
return decoded && typeof decoded === "object" ? decoded : null;
|
|
75
|
+
} catch {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const decodeExecutionPayload = () => decodeJwtPayload(resolveExecutionToken());
|
|
80
|
+
const readString = (env, key) => env?.[key]?.trim() || null;
|
|
81
|
+
const readPayloadString = (payload, key) => typeof payload?.[key] === "string" && payload[key] ? payload[key] : null;
|
|
82
|
+
const KNOWN_PERMISSIONS = new Set(PERMISSIONS);
|
|
83
|
+
const readScopes = (payload) => Array.isArray(payload?.scopes) ? payload.scopes.filter((scope) => typeof scope === "string" && KNOWN_PERMISSIONS.has(scope)) : [];
|
|
84
|
+
function getCohubContext() {
|
|
85
|
+
const env = readProcessEnv();
|
|
86
|
+
const token = resolveExecutionToken();
|
|
87
|
+
const runtime = token ? "sandbox" : typeof window !== "undefined" && typeof document !== "undefined" ? "browser" : "local";
|
|
88
|
+
const payload = decodeExecutionPayload();
|
|
89
|
+
if (!token && runtime !== "sandbox") return {
|
|
90
|
+
runtime: { kind: runtime },
|
|
91
|
+
execution: null
|
|
92
|
+
};
|
|
93
|
+
return {
|
|
94
|
+
runtime: { kind: runtime },
|
|
95
|
+
execution: {
|
|
96
|
+
source: readPayloadString(payload, "source"),
|
|
97
|
+
actorUserId: readString(env, "COHUB_USER_UUID") ?? readPayloadString(payload, "actorUserId"),
|
|
98
|
+
viewerUserId: readPayloadString(payload, "viewerUserId"),
|
|
99
|
+
spaceId: readString(env, "COHUB_SPACE_ID") ?? readPayloadString(payload, "spaceId"),
|
|
100
|
+
sessionId: readString(env, "COHUB_SESSION_ID") ?? readPayloadString(payload, "sessionId"),
|
|
101
|
+
turnId: readString(env, "COHUB_TURN_ID") ?? readPayloadString(payload, "turnId"),
|
|
102
|
+
toolCallId: readString(env, "COHUB_TOOL_CALL_ID"),
|
|
103
|
+
sourceClientId: readString(env, "COHUB_SOURCE_CLIENT_ID"),
|
|
104
|
+
taskRunId: readPayloadString(payload, "taskRunId"),
|
|
105
|
+
appId: readPayloadString(payload, "appId"),
|
|
106
|
+
appVersionId: readPayloadString(payload, "appVersionId"),
|
|
107
|
+
action: readPayloadString(payload, "action"),
|
|
108
|
+
scopes: readScopes(payload),
|
|
109
|
+
modelProvider: readString(env, "COHUB_MODEL_PROVIDER"),
|
|
110
|
+
modelId: readString(env, "COHUB_MODEL_ID")
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function resolveExecutionAppId() {
|
|
115
|
+
return readPayloadString(decodeExecutionPayload(), "appId");
|
|
116
|
+
}
|
|
117
|
+
const resolveCohubEnvironment = (env) => {
|
|
118
|
+
if (env) return env;
|
|
119
|
+
return readRuntimeEnv() === "dev" ? "dev" : "prod";
|
|
120
|
+
};
|
|
121
|
+
const normalizeBaseUrl = (url) => url.trim().replace(/\/+$/, "");
|
|
122
|
+
const normalizeWebsocketPath = (input, path, replacePaths = []) => {
|
|
123
|
+
let withProtocol = normalizeBaseUrl(input).replace(/^http:/, "ws:").replace(/^https:/, "wss:");
|
|
124
|
+
for (const replacePath of replacePaths) if (withProtocol.endsWith(replacePath)) {
|
|
125
|
+
withProtocol = withProtocol.slice(0, -replacePath.length);
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
return withProtocol.endsWith(path) ? withProtocol : `${withProtocol}${path}`;
|
|
129
|
+
};
|
|
130
|
+
const normalizeWebsocketUrl = (input) => normalizeWebsocketPath(input, "/ws", ["/asr/ws"]);
|
|
131
|
+
const normalizeVoiceInputWebsocketUrl = (input) => normalizeWebsocketPath(input, "/asr/ws", ["/ws"]);
|
|
132
|
+
const resolveApiBaseUrl = (options = {}) => {
|
|
133
|
+
const baseUrl = options.baseUrl?.trim() || readProcessEnv()?.COHUB_BASE_URL?.trim();
|
|
134
|
+
if (baseUrl) return normalizeBaseUrl(baseUrl);
|
|
135
|
+
return COHUB_ENVIRONMENTS[resolveCohubEnvironment(options.env)].apiBaseUrl;
|
|
136
|
+
};
|
|
137
|
+
const resolveWebBaseUrl = (options = {}) => {
|
|
138
|
+
const url = options.url?.trim() || readProcessEnv()?.COHUB_WEB_URL?.trim();
|
|
139
|
+
if (url) return normalizeBaseUrl(url);
|
|
140
|
+
return COHUB_ENVIRONMENTS[resolveCohubEnvironment(options.env)].webBaseUrl;
|
|
141
|
+
};
|
|
142
|
+
const resolveWebsocketUrl = (options = {}) => {
|
|
143
|
+
const url = options.url?.trim() || readProcessEnv()?.COHUB_WS_URL?.trim();
|
|
144
|
+
if (url) return normalizeWebsocketUrl(url);
|
|
145
|
+
return COHUB_ENVIRONMENTS[resolveCohubEnvironment(options.env)].websocketUrl;
|
|
146
|
+
};
|
|
147
|
+
const resolveVoiceInputWebsocketUrl = (options = {}) => {
|
|
148
|
+
const env = readProcessEnv();
|
|
149
|
+
const url = options.url?.trim() || env?.COHUB_VOICE_WS_URL?.trim() || env?.COHUB_WS_URL?.trim();
|
|
150
|
+
if (url) return normalizeVoiceInputWebsocketUrl(url);
|
|
151
|
+
return COHUB_ENVIRONMENTS[resolveCohubEnvironment(options.env)].voiceInputWebsocketUrl;
|
|
152
|
+
};
|
|
153
|
+
//#endregion
|
|
154
|
+
export { resolveApiBaseUrl as a, resolveExecutionToken as c, resolveWebsocketUrl as d, PERMISSIONS as f, normalizeBaseUrl as i, resolveVoiceInputWebsocketUrl as l, decodeJwtPayload as n, resolveCohubEnvironment as o, getCohubContext as r, resolveExecutionAppId as s, COHUB_ENVIRONMENTS as t, resolveWebBaseUrl as u };
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { r as cliCommit } from "./version2.js";
|
|
2
|
+
import { A as spinner, C as error, D as json, L as authSource, O as jsonRequested, P as describeError, g as explicitSpace, t as createClient } from "./client.js";
|
|
3
|
+
import { o as mimeTypeForPath } from "./id.js";
|
|
4
|
+
import { f as readRequestSourceFromEnv } from "./app-realtime.js";
|
|
5
|
+
import { K as readRuntimeDiagnosticEvents, c as runtimeStateRoot } from "./install.js";
|
|
6
|
+
import { a as resolveApiBaseUrl, o as resolveCohubEnvironment } from "./environment.js";
|
|
7
|
+
import { n as readPromptContent, t as collectOption } from "./command-input.js";
|
|
8
|
+
import { a as resolveRuntimeTarget } from "./launch.js";
|
|
9
|
+
import { arch, platform, release } from "node:os";
|
|
10
|
+
import { openAsBlob } from "node:fs";
|
|
11
|
+
import { basename, resolve } from "node:path";
|
|
12
|
+
import { stat } from "node:fs/promises";
|
|
13
|
+
//#region src/commands/feedback.ts
|
|
14
|
+
const CFEED_ENDPOINT = "https://cfeed.neta.art/api/v1/feedback";
|
|
15
|
+
const CFEED_APP = "cohub";
|
|
16
|
+
const RUNTIME_LOG_MAX_BYTES = 5242880;
|
|
17
|
+
const RUNTIME_LOG_EVENTS = 2e3;
|
|
18
|
+
const USER_LOOKUP_TIMEOUT_MS = 3e3;
|
|
19
|
+
const SUBMIT_TIMEOUT_MS = 12e4;
|
|
20
|
+
async function readAttachment(path) {
|
|
21
|
+
const absolute = resolve(path);
|
|
22
|
+
if (!(await stat(absolute).catch(() => null))?.isFile()) return error(`Cannot attach ${path}`, "Pass a path to an existing file");
|
|
23
|
+
const type = mimeTypeForPath(absolute) ?? "application/octet-stream";
|
|
24
|
+
return new File([await openAsBlob(absolute, { type })], basename(absolute), { type });
|
|
25
|
+
}
|
|
26
|
+
async function runtimeLogFile(program, now) {
|
|
27
|
+
const spaceId = await resolveRuntimeTarget(program).catch((cause) => error("Cannot attach Runtime logs", describeError(cause)));
|
|
28
|
+
let events = await readRuntimeDiagnosticEvents(runtimeStateRoot(spaceId), { limit: RUNTIME_LOG_EVENTS });
|
|
29
|
+
let dropped = 0;
|
|
30
|
+
let text = JSON.stringify({
|
|
31
|
+
spaceId,
|
|
32
|
+
dropped,
|
|
33
|
+
events
|
|
34
|
+
});
|
|
35
|
+
while (Buffer.byteLength(text) > RUNTIME_LOG_MAX_BYTES && events.length > 0) {
|
|
36
|
+
const count = Math.ceil(events.length / 2);
|
|
37
|
+
events = events.slice(count);
|
|
38
|
+
dropped += count;
|
|
39
|
+
text = JSON.stringify({
|
|
40
|
+
spaceId,
|
|
41
|
+
dropped,
|
|
42
|
+
events
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const stamp = now.toISOString().replace(/[-:]/g, "").replace(/\..+$/, "");
|
|
46
|
+
return new File([text], `cohub-runtime-${stamp}.json`, { type: "application/json" });
|
|
47
|
+
}
|
|
48
|
+
async function currentUserUuid() {
|
|
49
|
+
if (!authSource()) return null;
|
|
50
|
+
let timer;
|
|
51
|
+
const timeout = new Promise((done) => {
|
|
52
|
+
timer = setTimeout(() => done(null), USER_LOOKUP_TIMEOUT_MS);
|
|
53
|
+
});
|
|
54
|
+
const lookup = createClient().user.getMe().then((user) => user.uuid ?? null, () => null);
|
|
55
|
+
try {
|
|
56
|
+
return await Promise.race([lookup, timeout]);
|
|
57
|
+
} finally {
|
|
58
|
+
clearTimeout(timer);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async function submitFeedback(content, extra, files) {
|
|
62
|
+
const body = new FormData();
|
|
63
|
+
body.set("app", CFEED_APP);
|
|
64
|
+
body.set("content", content);
|
|
65
|
+
body.set("extra", JSON.stringify(extra));
|
|
66
|
+
for (const file of files) body.append("files", file, file.name);
|
|
67
|
+
const response = await fetch(CFEED_ENDPOINT, {
|
|
68
|
+
method: "POST",
|
|
69
|
+
body,
|
|
70
|
+
signal: AbortSignal.timeout(SUBMIT_TIMEOUT_MS)
|
|
71
|
+
});
|
|
72
|
+
const payload = await response.json().catch(() => null);
|
|
73
|
+
if (!response.ok) throw new Error(payload?.error?.message ?? `${response.status} ${response.statusText}`);
|
|
74
|
+
if (!payload) throw new Error("Feedback service returned an empty response");
|
|
75
|
+
return payload;
|
|
76
|
+
}
|
|
77
|
+
function registerFeedback(program) {
|
|
78
|
+
program.command("feedback [message...]").description("Send feedback or a bug report to the Cohub team").option("-f, --file <path>", "Attach a file; repeatable", collectOption, []).option("--runtime-logs", "Attach recent local Runtime diagnostics for the target Space").option("--json", "Output as JSON").addHelpText("after", `
|
|
79
|
+
The message comes from arguments or stdin. CLI version, OS, environment, account,
|
|
80
|
+
and COHUB_* Space/Chat context are attached automatically; your working directory is not.
|
|
81
|
+
|
|
82
|
+
Examples:
|
|
83
|
+
$ cohub feedback "runtime up hangs after sign-in"
|
|
84
|
+
$ cohub feedback "Board export is blurry" -f board.png -f export.log
|
|
85
|
+
$ cohub feedback --runtime-logs "Codex chats stopped syncing"
|
|
86
|
+
$ cat report.md | cohub feedback`).action(async (words, opts) => {
|
|
87
|
+
const asJson = jsonRequested(opts);
|
|
88
|
+
const content = await readPromptContent(words);
|
|
89
|
+
const now = /* @__PURE__ */ new Date();
|
|
90
|
+
const [files, userUuid] = await Promise.all([Promise.all([...opts.file.map(readAttachment), ...opts.runtimeLogs ? [runtimeLogFile(program, now)] : []]), currentUserUuid()]);
|
|
91
|
+
const extra = {
|
|
92
|
+
user_uuid: userUuid,
|
|
93
|
+
cli_version: program.version() ?? null,
|
|
94
|
+
cli_commit: cliCommit(),
|
|
95
|
+
node: process.versions.node,
|
|
96
|
+
os: `${platform()} ${release()}`,
|
|
97
|
+
arch: arch(),
|
|
98
|
+
env: resolveCohubEnvironment(),
|
|
99
|
+
api_base_url: resolveApiBaseUrl(),
|
|
100
|
+
space: explicitSpace(program),
|
|
101
|
+
source: readRequestSourceFromEnv(process.env, { via: "cli" }),
|
|
102
|
+
locale: Intl.DateTimeFormat().resolvedOptions().locale,
|
|
103
|
+
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
104
|
+
tty: Boolean(process.stdout.isTTY),
|
|
105
|
+
has_runtime_logs: Boolean(opts.runtimeLogs)
|
|
106
|
+
};
|
|
107
|
+
const sp = asJson ? null : spinner();
|
|
108
|
+
sp?.start("Sending feedback");
|
|
109
|
+
try {
|
|
110
|
+
const result = await submitFeedback(content, extra, files);
|
|
111
|
+
if (asJson) return json(result);
|
|
112
|
+
sp?.stop(`Feedback sent · ${result.id}`);
|
|
113
|
+
} catch (cause) {
|
|
114
|
+
if (sp) process.stderr.write("\n");
|
|
115
|
+
error("Couldn't send feedback", describeError(cause));
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
//#endregion
|
|
120
|
+
export { registerFeedback };
|