@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/commands/public.js
DELETED
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { lstat, readdir } from "node:fs/promises";
|
|
3
|
-
import { basename, relative, resolve } from "node:path";
|
|
4
|
-
import { isTextMime, mimeTypeForPath, } from "@neta-art/cohub";
|
|
5
|
-
import { mediaFacts } from "@neta-art/cohub/media";
|
|
6
|
-
import { createClient } from "../client.js";
|
|
7
|
-
import { HttpPutError, putLocalFile } from "../http-put.js";
|
|
8
|
-
import { localMediaFacts } from "../local-media.js";
|
|
9
|
-
import { error, handleHttp, json as outJson, jsonRequested } from "../output.js";
|
|
10
|
-
import { resolveSpace } from "../space.js";
|
|
11
|
-
const UPLOAD_CONCURRENCY = 4;
|
|
12
|
-
function hasControlCharacters(value) {
|
|
13
|
-
return [...value].some((char) => {
|
|
14
|
-
const code = char.charCodeAt(0);
|
|
15
|
-
return code <= 0x1f || (code >= 0x7f && code <= 0x9f);
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
function terminalText(value) {
|
|
19
|
-
return [...value].map((char) => {
|
|
20
|
-
const code = char.charCodeAt(0);
|
|
21
|
-
return code <= 0x1f || (code >= 0x7f && code <= 0x9f)
|
|
22
|
-
? `\\u${code.toString(16).padStart(4, "0")}`
|
|
23
|
-
: char;
|
|
24
|
-
}).join("");
|
|
25
|
-
}
|
|
26
|
-
function normalizePublicPath(input) {
|
|
27
|
-
const value = input.replace(/\\/g, "/").replace(/^\.\//, "").replace(/\/+$/, "");
|
|
28
|
-
if (!value || value.startsWith("/") || hasControlCharacters(value)) {
|
|
29
|
-
return error("Invalid public path");
|
|
30
|
-
}
|
|
31
|
-
const parts = value.split("/");
|
|
32
|
-
if (parts.some((part) => !part || part === "." || part === "..")) {
|
|
33
|
-
return error("Invalid public path");
|
|
34
|
-
}
|
|
35
|
-
return parts.join("/");
|
|
36
|
-
}
|
|
37
|
-
function contentTypeForPath(path) {
|
|
38
|
-
const mimeType = mimeTypeForPath(path);
|
|
39
|
-
if (!mimeType)
|
|
40
|
-
return "application/octet-stream";
|
|
41
|
-
return isTextMime(mimeType) ? `${mimeType}; charset=utf-8` : mimeType;
|
|
42
|
-
}
|
|
43
|
-
async function walkDirectory(root, directory, destination) {
|
|
44
|
-
const names = await readdir(directory);
|
|
45
|
-
names.sort((left, right) => left.localeCompare(right));
|
|
46
|
-
const files = [];
|
|
47
|
-
for (const name of names) {
|
|
48
|
-
const localPath = resolve(directory, name);
|
|
49
|
-
const info = await lstat(localPath);
|
|
50
|
-
if (info.isSymbolicLink())
|
|
51
|
-
return error("Symlinks are not supported", relative(root, localPath));
|
|
52
|
-
if (info.isDirectory()) {
|
|
53
|
-
files.push(...await walkDirectory(root, localPath, destination));
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
if (!info.isFile())
|
|
57
|
-
continue;
|
|
58
|
-
const nestedPath = relative(root, localPath).replace(/\\/g, "/");
|
|
59
|
-
const publicPath = normalizePublicPath(`${destination}/${nestedPath}`);
|
|
60
|
-
files.push({
|
|
61
|
-
id: randomUUID(),
|
|
62
|
-
localPath,
|
|
63
|
-
publicPath,
|
|
64
|
-
size: info.size,
|
|
65
|
-
mimeType: contentTypeForPath(localPath),
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
return files;
|
|
69
|
-
}
|
|
70
|
-
export async function collectPublicUpload(source, destination) {
|
|
71
|
-
const localPath = resolve(source);
|
|
72
|
-
const info = await lstat(localPath).catch(() => null);
|
|
73
|
-
if (!info)
|
|
74
|
-
return error("Source not found", source);
|
|
75
|
-
if (info.isSymbolicLink())
|
|
76
|
-
return error("Symlinks are not supported", source);
|
|
77
|
-
if (info.isFile()) {
|
|
78
|
-
const publicPath = normalizePublicPath(destination
|
|
79
|
-
? destination.endsWith("/") ? `${destination}${basename(localPath)}` : destination
|
|
80
|
-
: basename(localPath));
|
|
81
|
-
return {
|
|
82
|
-
destination: publicPath,
|
|
83
|
-
entryPath: publicPath,
|
|
84
|
-
files: [{
|
|
85
|
-
id: randomUUID(),
|
|
86
|
-
localPath,
|
|
87
|
-
publicPath,
|
|
88
|
-
size: info.size,
|
|
89
|
-
mimeType: contentTypeForPath(localPath),
|
|
90
|
-
}],
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
if (!info.isDirectory())
|
|
94
|
-
return error("Source must be a file or directory", source);
|
|
95
|
-
const target = normalizePublicPath(destination ?? basename(localPath));
|
|
96
|
-
const files = await walkDirectory(localPath, localPath, target);
|
|
97
|
-
if (files.length === 0)
|
|
98
|
-
return error("Directory contains no files", source);
|
|
99
|
-
const indexPath = `${target}/index.html`;
|
|
100
|
-
return {
|
|
101
|
-
files,
|
|
102
|
-
destination: `${target}/`,
|
|
103
|
-
entryPath: files.some((file) => file.publicPath === indexPath) ? indexPath : null,
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
async function mapSettledWithConcurrency(items, concurrency, mapper) {
|
|
107
|
-
const errors = [];
|
|
108
|
-
let nextIndex = 0;
|
|
109
|
-
const workers = Array.from({ length: Math.min(concurrency, items.length) }, async () => {
|
|
110
|
-
while (nextIndex < items.length) {
|
|
111
|
-
const index = nextIndex++;
|
|
112
|
-
try {
|
|
113
|
-
await mapper(items[index]);
|
|
114
|
-
}
|
|
115
|
-
catch (cause) {
|
|
116
|
-
errors.push(cause instanceof Error ? cause : new Error(String(cause)));
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
await Promise.all(workers);
|
|
121
|
-
return errors;
|
|
122
|
-
}
|
|
123
|
-
async function putPublicFile(file, plan, fetchImpl) {
|
|
124
|
-
try {
|
|
125
|
-
await putLocalFile({
|
|
126
|
-
url: plan.uploadUrl,
|
|
127
|
-
filePath: file.localPath,
|
|
128
|
-
size: file.size,
|
|
129
|
-
headers: plan.headers,
|
|
130
|
-
label: file.publicPath,
|
|
131
|
-
fetch: fetchImpl,
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
catch (error) {
|
|
135
|
-
if (error instanceof HttpPutError && (error.status === 409 || error.status === 412)) {
|
|
136
|
-
throw new Error(`${file.publicPath} already exists. Use --overwrite.`);
|
|
137
|
-
}
|
|
138
|
-
throw error;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
async function publicMediaFacts(files) {
|
|
142
|
-
const facts = new Map();
|
|
143
|
-
const media = files.flatMap((file) => {
|
|
144
|
-
const type = file.mimeType.split("/")[0];
|
|
145
|
-
return type === "image" || type === "video" ? [{ file, type: type }] : [];
|
|
146
|
-
});
|
|
147
|
-
await mapSettledWithConcurrency(media, UPLOAD_CONCURRENCY, async ({ file, type }) => {
|
|
148
|
-
// Facts only help previews; out-of-range ones are dropped rather than failing the upload.
|
|
149
|
-
const found = mediaFacts(await localMediaFacts(file.localPath, type));
|
|
150
|
-
if (found)
|
|
151
|
-
facts.set(file.id, found);
|
|
152
|
-
});
|
|
153
|
-
return facts;
|
|
154
|
-
}
|
|
155
|
-
function uploadFailure(errors) {
|
|
156
|
-
if (errors.length === 1)
|
|
157
|
-
return errors[0];
|
|
158
|
-
const first = errors[0]?.message ?? "Upload failed";
|
|
159
|
-
return new Error(`${first} (${errors.length} files failed)`);
|
|
160
|
-
}
|
|
161
|
-
function publicUrlPrefix(destination, entry) {
|
|
162
|
-
const encodedPath = entry.path.split("/").map(encodeURIComponent).join("/");
|
|
163
|
-
if (!entry.publicUrl.endsWith(encodedPath)) {
|
|
164
|
-
throw new Error(`Invalid public URL for ${entry.path}`);
|
|
165
|
-
}
|
|
166
|
-
const encodedDestination = destination.split("/").map(encodeURIComponent).join("/");
|
|
167
|
-
return `${entry.publicUrl.slice(0, -encodedPath.length)}${encodedDestination}`;
|
|
168
|
-
}
|
|
169
|
-
async function uploadPublic(command, source, destination, opts, deps) {
|
|
170
|
-
const client = deps.createClient?.() ?? createClient();
|
|
171
|
-
const spaceId = await resolveSpace(command, { home: true });
|
|
172
|
-
try {
|
|
173
|
-
const upload = await collectPublicUpload(source, destination);
|
|
174
|
-
const media = await publicMediaFacts(upload.files);
|
|
175
|
-
const plan = await client.space(spaceId).publicFiles.createUpload({
|
|
176
|
-
overwrite: Boolean(opts.overwrite),
|
|
177
|
-
entries: upload.files.map((file) => ({
|
|
178
|
-
id: file.id,
|
|
179
|
-
relativePath: file.publicPath,
|
|
180
|
-
size: file.size,
|
|
181
|
-
mimeType: file.mimeType,
|
|
182
|
-
...(media.has(file.id) ? { media: media.get(file.id) } : {}),
|
|
183
|
-
})),
|
|
184
|
-
});
|
|
185
|
-
if (opts.overwrite && !jsonRequested(opts)) {
|
|
186
|
-
process.stderr.write(`Overwrite enabled for ${upload.destination}\n`);
|
|
187
|
-
}
|
|
188
|
-
const filesById = new Map(upload.files.map((file) => [file.id, file]));
|
|
189
|
-
const plansByPath = new Map(plan.entries.map((entry) => [entry.path, entry]));
|
|
190
|
-
const entryPlan = upload.entryPath ? plansByPath.get(upload.entryPath) : undefined;
|
|
191
|
-
const assetPlans = entryPlan
|
|
192
|
-
? plan.entries.filter((entry) => entry.id !== entryPlan.id)
|
|
193
|
-
: plan.entries;
|
|
194
|
-
const uploadPlans = async (entries) => mapSettledWithConcurrency(entries, UPLOAD_CONCURRENCY, async (entry) => {
|
|
195
|
-
const file = filesById.get(entry.id);
|
|
196
|
-
if (!file)
|
|
197
|
-
throw new Error(`Missing local file for ${entry.path}`);
|
|
198
|
-
await putPublicFile(file, entry, deps.fetch ?? fetch);
|
|
199
|
-
});
|
|
200
|
-
const assetErrors = await uploadPlans(assetPlans);
|
|
201
|
-
if (assetErrors.length > 0)
|
|
202
|
-
throw uploadFailure(assetErrors);
|
|
203
|
-
if (entryPlan) {
|
|
204
|
-
const entryErrors = await uploadPlans([entryPlan]);
|
|
205
|
-
if (entryErrors.length > 0)
|
|
206
|
-
throw uploadFailure(entryErrors);
|
|
207
|
-
}
|
|
208
|
-
const firstPlan = plan.entries[0];
|
|
209
|
-
if (!firstPlan)
|
|
210
|
-
throw new Error("Upload plan contains no files");
|
|
211
|
-
if (jsonRequested(opts)) {
|
|
212
|
-
outJson({
|
|
213
|
-
destination: upload.destination,
|
|
214
|
-
urlPrefix: publicUrlPrefix("", firstPlan),
|
|
215
|
-
files: upload.files.map((file) => ({
|
|
216
|
-
path: file.publicPath,
|
|
217
|
-
size: file.size,
|
|
218
|
-
mimeType: file.mimeType,
|
|
219
|
-
})),
|
|
220
|
-
});
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
if (entryPlan) {
|
|
224
|
-
console.log(entryPlan.publicUrl);
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
const fileLabel = upload.files.length === 1 ? "file" : "files";
|
|
228
|
-
console.log(`Uploaded ${upload.files.length} ${fileLabel} to ${upload.destination}`);
|
|
229
|
-
console.log(`URL prefix: ${publicUrlPrefix(upload.destination, firstPlan)}`);
|
|
230
|
-
}
|
|
231
|
-
catch (exception) {
|
|
232
|
-
handleHttp(exception);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
async function listPublic(command, path, opts, deps) {
|
|
236
|
-
const client = deps.createClient?.() ?? createClient();
|
|
237
|
-
try {
|
|
238
|
-
const publicFiles = client.space(await resolveSpace(command, { home: true })).publicFiles;
|
|
239
|
-
const entries = [];
|
|
240
|
-
let cursor;
|
|
241
|
-
do {
|
|
242
|
-
const page = await publicFiles.list(path ?? "", {
|
|
243
|
-
recursive: opts.recursive,
|
|
244
|
-
limit: 1000,
|
|
245
|
-
cursor,
|
|
246
|
-
});
|
|
247
|
-
if (jsonRequested(opts))
|
|
248
|
-
entries.push(...page.entries);
|
|
249
|
-
else
|
|
250
|
-
for (const entry of page.entries) {
|
|
251
|
-
console.log(`${terminalText(entry.name)}${entry.kind === "directory" ? "/" : ""}`);
|
|
252
|
-
}
|
|
253
|
-
cursor = page.nextCursor ?? undefined;
|
|
254
|
-
} while (cursor);
|
|
255
|
-
if (jsonRequested(opts))
|
|
256
|
-
return outJson({ path: path ?? "", entries, nextCursor: null });
|
|
257
|
-
}
|
|
258
|
-
catch (exception) {
|
|
259
|
-
handleHttp(exception);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
async function printPublicUrl(command, path, deps) {
|
|
263
|
-
const client = deps.createClient?.() ?? createClient();
|
|
264
|
-
try {
|
|
265
|
-
const result = await client.space(await resolveSpace(command, { home: true })).publicFiles.url(path);
|
|
266
|
-
console.log(result.url);
|
|
267
|
-
}
|
|
268
|
-
catch (exception) {
|
|
269
|
-
handleHttp(exception);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
export function registerPublic(program, deps = {}) {
|
|
273
|
-
const publicCommand = program
|
|
274
|
-
.command("public")
|
|
275
|
-
.description("Upload and manage public Space files");
|
|
276
|
-
publicCommand
|
|
277
|
-
.command("upload <source> [destination]")
|
|
278
|
-
.description("Upload a file or directory")
|
|
279
|
-
.option("--overwrite", "Replace existing public files")
|
|
280
|
-
.action((source, destination, opts, command) => uploadPublic(command, source, destination, opts, deps));
|
|
281
|
-
publicCommand
|
|
282
|
-
.command("ls [path]")
|
|
283
|
-
.description("List public files")
|
|
284
|
-
.option("-r, --recursive", "List files recursively")
|
|
285
|
-
.action((path, opts, command) => listPublic(command, path, opts, deps));
|
|
286
|
-
publicCommand
|
|
287
|
-
.command("url <path>")
|
|
288
|
-
.description("Print a public file URL")
|
|
289
|
-
.action((path, _opts, command) => printPublicUrl(command, path, deps));
|
|
290
|
-
return publicCommand;
|
|
291
|
-
}
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import { isUuid, } from "@neta-art/cohub";
|
|
2
|
-
import { createClient } from "../client.js";
|
|
3
|
-
import { formatLocalDateTime, table, json as outJson, jsonRequested, error, handleHttp } from "../output.js";
|
|
4
|
-
const RESOURCE_TYPES = new Set([
|
|
5
|
-
"turn",
|
|
6
|
-
"session",
|
|
7
|
-
"space",
|
|
8
|
-
"checkpoint",
|
|
9
|
-
]);
|
|
10
|
-
const REFERENCE_KINDS = new Set([
|
|
11
|
-
"session_fork",
|
|
12
|
-
"space_fork",
|
|
13
|
-
"checkpoint_fork",
|
|
14
|
-
"mod",
|
|
15
|
-
"mention",
|
|
16
|
-
"tool_call",
|
|
17
|
-
"turn_trigger",
|
|
18
|
-
"agent_tool_file_read",
|
|
19
|
-
"agent_tool_file_write",
|
|
20
|
-
"agent_tool_file_edit",
|
|
21
|
-
"agent_tool_file_ls",
|
|
22
|
-
"agent_tool_file_find",
|
|
23
|
-
"agent_tool_file_grep",
|
|
24
|
-
]);
|
|
25
|
-
const DIRECTIONS = new Set(["out", "in", "both"]);
|
|
26
|
-
const GROUP_BYS = new Set(["kind", "targetType", "target", "sourceType", "day"]);
|
|
27
|
-
function parseSource(value) {
|
|
28
|
-
const idx = value.indexOf(":");
|
|
29
|
-
if (idx <= 0)
|
|
30
|
-
throw new Error("Source must be <type>:<id>, e.g. session:<uuid>");
|
|
31
|
-
const type = value.slice(0, idx);
|
|
32
|
-
const id = value.slice(idx + 1).trim();
|
|
33
|
-
if (!RESOURCE_TYPES.has(type))
|
|
34
|
-
throw new Error(`Invalid resource type: ${type}`);
|
|
35
|
-
if (!id)
|
|
36
|
-
throw new Error("Missing resource id");
|
|
37
|
-
return { type, id };
|
|
38
|
-
}
|
|
39
|
-
function parseKinds(value) {
|
|
40
|
-
const kinds = value?.split(",").map((k) => k.trim()).filter(Boolean);
|
|
41
|
-
if (!kinds?.length)
|
|
42
|
-
return undefined;
|
|
43
|
-
const invalid = kinds.find((k) => !REFERENCE_KINDS.has(k));
|
|
44
|
-
if (invalid)
|
|
45
|
-
throw new Error(`Invalid reference kind: ${invalid}`);
|
|
46
|
-
return [...new Set(kinds)];
|
|
47
|
-
}
|
|
48
|
-
function clampNumber(value, fallback, min, max) {
|
|
49
|
-
const parsed = Number(value ?? fallback);
|
|
50
|
-
if (!Number.isFinite(parsed))
|
|
51
|
-
return fallback;
|
|
52
|
-
return Math.min(Math.max(Math.floor(parsed), min), max);
|
|
53
|
-
}
|
|
54
|
-
const KINDS_HELP = `Kinds:
|
|
55
|
-
structural: session_fork, space_fork, checkpoint_fork, mod
|
|
56
|
-
content: mention, tool_call
|
|
57
|
-
causality: turn_trigger
|
|
58
|
-
file access: agent_tool_file_read, agent_tool_file_write, agent_tool_file_edit,
|
|
59
|
-
agent_tool_file_ls, agent_tool_file_find, agent_tool_file_grep`;
|
|
60
|
-
export function registerReferences(program) {
|
|
61
|
-
const references = program
|
|
62
|
-
.command("references")
|
|
63
|
-
.description("Inspect resource references (forks, mentions, tool calls, mods, file access)")
|
|
64
|
-
.addHelpText("after", "\nAnalysis index for collaboration edges and file heat.\n");
|
|
65
|
-
references
|
|
66
|
-
.command("query")
|
|
67
|
-
.description("List references touching a resource")
|
|
68
|
-
.argument("<source>", "turn:<uuid> | session:<uuid> | space:<uuid> | checkpoint:<uuid>")
|
|
69
|
-
.option("--direction <dir>", "out | in | both", "both")
|
|
70
|
-
.option("--kinds <kinds>", "Comma-separated kinds (see list below)")
|
|
71
|
-
.option("--days <n>", "Only references seen within the last N days")
|
|
72
|
-
.option("--limit <n>", "Maximum rows, 1-500", "200")
|
|
73
|
-
.option("--json", "Output as JSON")
|
|
74
|
-
.addHelpText("after", `
|
|
75
|
-
|
|
76
|
-
${KINDS_HELP}
|
|
77
|
-
|
|
78
|
-
Examples:
|
|
79
|
-
cohub references query turn:<uuid> --kinds agent_tool_file_read,agent_tool_file_write
|
|
80
|
-
cohub references query turn:<uuid> --direction out --kinds turn_trigger
|
|
81
|
-
cohub references query session:<uuid> --json
|
|
82
|
-
cohub references query checkpoint:<uuid> --direction out
|
|
83
|
-
cohub references query space:<uuid> --direction in --kinds mention,tool_call
|
|
84
|
-
cohub references query space:<uuid> --kinds agent_tool_file_read --days 30
|
|
85
|
-
`)
|
|
86
|
-
.action(async (source, opts) => {
|
|
87
|
-
const client = createClient();
|
|
88
|
-
try {
|
|
89
|
-
const ref = parseSource(source);
|
|
90
|
-
const direction = (opts.direction ?? "both");
|
|
91
|
-
if (!DIRECTIONS.has(direction))
|
|
92
|
-
return error(`Invalid direction: ${opts.direction}`);
|
|
93
|
-
const kinds = parseKinds(opts.kinds);
|
|
94
|
-
const days = opts.days ? clampNumber(opts.days, 30, 1, 365) : undefined;
|
|
95
|
-
const limit = clampNumber(opts.limit, 200, 1, 500);
|
|
96
|
-
const result = await client.references.query({
|
|
97
|
-
source: `${ref.type}:${ref.id}`,
|
|
98
|
-
direction,
|
|
99
|
-
kinds,
|
|
100
|
-
days,
|
|
101
|
-
limit,
|
|
102
|
-
});
|
|
103
|
-
if (jsonRequested(opts))
|
|
104
|
-
return outJson(result);
|
|
105
|
-
const rows = result.references.map((r) => ({
|
|
106
|
-
kind: r.kind,
|
|
107
|
-
source: `${r.sourceType}:${r.sourceId.slice(0, 8)}`,
|
|
108
|
-
target: formatTarget(r.targetType, r.targetId),
|
|
109
|
-
count: r.count,
|
|
110
|
-
lastSeen: formatLocalDateTime(r.updatedAt).slice(0, 10),
|
|
111
|
-
}));
|
|
112
|
-
table(rows, [
|
|
113
|
-
{ key: "kind", label: "Kind" },
|
|
114
|
-
{ key: "source", label: "Source" },
|
|
115
|
-
{ key: "target", label: "Target" },
|
|
116
|
-
{ key: "count", label: "Count" },
|
|
117
|
-
{ key: "lastSeen", label: "Last Seen" },
|
|
118
|
-
]);
|
|
119
|
-
}
|
|
120
|
-
catch (e) {
|
|
121
|
-
if (e instanceof Error && (e.message.startsWith("Invalid") || e.message.startsWith("Source must") || e.message.startsWith("Missing"))) {
|
|
122
|
-
return error(e.message);
|
|
123
|
-
}
|
|
124
|
-
handleHttp(e);
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
references
|
|
128
|
-
.command("aggregate")
|
|
129
|
-
.description("Grouped reference counts for a space")
|
|
130
|
-
.argument("<spaceId>", "Space id")
|
|
131
|
-
.option("--group-by <field>", "kind | targetType | target | sourceType | day", "kind")
|
|
132
|
-
.option("--kinds <kinds>", "Comma-separated kinds (see list below)")
|
|
133
|
-
.option("--days <n>", "Only references seen within the last N days")
|
|
134
|
-
.option("--limit <n>", "Maximum groups, 1-500", "200")
|
|
135
|
-
.option("--json", "Output as JSON")
|
|
136
|
-
.addHelpText("after", `
|
|
137
|
-
|
|
138
|
-
${KINDS_HELP}
|
|
139
|
-
|
|
140
|
-
Notes:
|
|
141
|
-
--group-by target: file targets look like {spaceId}:{path}
|
|
142
|
-
|
|
143
|
-
Examples:
|
|
144
|
-
cohub references aggregate <spaceId> --json
|
|
145
|
-
cohub references aggregate <spaceId> --group-by targetType
|
|
146
|
-
cohub references aggregate <spaceId> --group-by target --kinds agent_tool_file_read --limit 20
|
|
147
|
-
cohub references aggregate <spaceId> --group-by day --days 30
|
|
148
|
-
`)
|
|
149
|
-
.action(async (spaceId, opts) => {
|
|
150
|
-
const client = createClient();
|
|
151
|
-
try {
|
|
152
|
-
if (!isUuid(spaceId.trim()))
|
|
153
|
-
return error("Invalid space id");
|
|
154
|
-
const groupBy = (opts.groupBy ?? "kind");
|
|
155
|
-
if (!GROUP_BYS.has(groupBy))
|
|
156
|
-
return error(`Invalid group-by: ${opts.groupBy}`);
|
|
157
|
-
const kinds = parseKinds(opts.kinds);
|
|
158
|
-
const days = opts.days ? clampNumber(opts.days, 30, 1, 365) : undefined;
|
|
159
|
-
const limit = clampNumber(opts.limit, 200, 1, 500);
|
|
160
|
-
const result = await client.references.aggregate({ spaceId: spaceId.trim(), groupBy, kinds, days, limit });
|
|
161
|
-
if (jsonRequested(opts))
|
|
162
|
-
return outJson(result);
|
|
163
|
-
const rows = result.groups.map((g) => ({
|
|
164
|
-
group: g.group,
|
|
165
|
-
references: g.references,
|
|
166
|
-
total: g.total,
|
|
167
|
-
}));
|
|
168
|
-
table(rows, [
|
|
169
|
-
{ key: "group", label: "Group" },
|
|
170
|
-
{ key: "references", label: "References" },
|
|
171
|
-
{ key: "total", label: "Total" },
|
|
172
|
-
]);
|
|
173
|
-
}
|
|
174
|
-
catch (e) {
|
|
175
|
-
if (e instanceof Error && e.message.startsWith("Invalid"))
|
|
176
|
-
return error(e.message);
|
|
177
|
-
handleHttp(e);
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Render a target for the table. File targets are `{spaceId}:{path}`; show the
|
|
183
|
-
* short space id plus the full path rather than blindly truncating.
|
|
184
|
-
*/
|
|
185
|
-
function formatTarget(targetType, targetId) {
|
|
186
|
-
if (targetType === "file") {
|
|
187
|
-
const idx = targetId.indexOf(":");
|
|
188
|
-
if (idx > 0)
|
|
189
|
-
return `file:${targetId.slice(0, 8)}…${targetId.slice(idx)}`;
|
|
190
|
-
return `file:${targetId}`;
|
|
191
|
-
}
|
|
192
|
-
return `${targetType}:${targetId.slice(0, 8)}`;
|
|
193
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { createClient } from "../client.js";
|
|
2
|
-
import { error, formatLocalDateTime, handleHttp, json as outJson, jsonRequested, ok, table } from "../output.js";
|
|
3
|
-
import { webUrl } from "../web.js";
|
|
4
|
-
function referralUrl(code) {
|
|
5
|
-
return webUrl(`/referrals/${code}`);
|
|
6
|
-
}
|
|
7
|
-
async function confirmRotate(opts) {
|
|
8
|
-
if (opts.yes)
|
|
9
|
-
return;
|
|
10
|
-
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
11
|
-
return error("Confirmation required", "Pass --yes to replace the referral link.");
|
|
12
|
-
}
|
|
13
|
-
process.stdout.write("The current referral link will stop working. Continue? [y/N] ");
|
|
14
|
-
const chunks = [];
|
|
15
|
-
for await (const chunk of process.stdin) {
|
|
16
|
-
chunks.push(chunk);
|
|
17
|
-
break;
|
|
18
|
-
}
|
|
19
|
-
const answer = Buffer.concat(chunks).toString().trim().toLowerCase();
|
|
20
|
-
if (answer !== "y" && answer !== "yes")
|
|
21
|
-
return error("Cancelled");
|
|
22
|
-
}
|
|
23
|
-
export function registerReferrals(program) {
|
|
24
|
-
const command = program
|
|
25
|
-
.command("referrals")
|
|
26
|
-
.description("View and manage your referral link")
|
|
27
|
-
.option("--json", "Output as JSON")
|
|
28
|
-
.action(async (opts) => {
|
|
29
|
-
const client = createClient();
|
|
30
|
-
try {
|
|
31
|
-
const result = await client.referrals.getMine();
|
|
32
|
-
const output = { ...result, url: referralUrl(result.code) };
|
|
33
|
-
if (jsonRequested(opts))
|
|
34
|
-
return outJson(output);
|
|
35
|
-
console.log(`\nReferral link: ${output.url}`);
|
|
36
|
-
const { quota } = result;
|
|
37
|
-
const resets = quota.cycleEndsAt ? `, resets ${formatLocalDateTime(quota.cycleEndsAt)}` : "";
|
|
38
|
-
console.log(`Cycle: ${quota.used}/${quota.limit} used, ${quota.reserved} pending, ${quota.available} available${resets}`);
|
|
39
|
-
console.log(`Rewarded: ${result.summary.rewarded}`);
|
|
40
|
-
console.log(`Earned: $${result.summary.earnedUsd.toFixed(2)}\n`);
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
handleHttp(error);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
command
|
|
47
|
-
.command("ls")
|
|
48
|
-
.alias("list")
|
|
49
|
-
.description("List your referrals")
|
|
50
|
-
.option("--json", "Output as JSON")
|
|
51
|
-
.action(async (opts) => {
|
|
52
|
-
const client = createClient();
|
|
53
|
-
try {
|
|
54
|
-
const result = await client.referrals.getMine();
|
|
55
|
-
if (jsonRequested(opts))
|
|
56
|
-
return outJson(result);
|
|
57
|
-
table(result.items, [
|
|
58
|
-
{ key: "id", label: "ID" },
|
|
59
|
-
{ key: "status", label: "Status" },
|
|
60
|
-
{ key: "claimedAt", label: "Claimed", format: formatLocalDateTime },
|
|
61
|
-
{ key: "expiresAt", label: "Expires", format: formatLocalDateTime },
|
|
62
|
-
{ key: "rewardedAt", label: "Rewarded", format: formatLocalDateTime },
|
|
63
|
-
]);
|
|
64
|
-
}
|
|
65
|
-
catch (error) {
|
|
66
|
-
handleHttp(error);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
command
|
|
70
|
-
.command("rotate")
|
|
71
|
-
.description("Replace your referral link")
|
|
72
|
-
.option("-y, --yes", "Confirm replacement")
|
|
73
|
-
.option("--json", "Output as JSON")
|
|
74
|
-
.action(async (opts) => {
|
|
75
|
-
await confirmRotate(opts);
|
|
76
|
-
const client = createClient();
|
|
77
|
-
try {
|
|
78
|
-
const result = await client.referrals.rotateCode();
|
|
79
|
-
const output = { ...result, url: referralUrl(result.code) };
|
|
80
|
-
if (jsonRequested(opts))
|
|
81
|
-
return outJson(output);
|
|
82
|
-
ok(`Referral link rotated: ${output.url}`);
|
|
83
|
-
}
|
|
84
|
-
catch (error) {
|
|
85
|
-
handleHttp(error);
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { Readable } from "node:stream";
|
|
2
|
-
type Input = {
|
|
3
|
-
op: "publish" | "send";
|
|
4
|
-
type: string;
|
|
5
|
-
data: unknown;
|
|
6
|
-
} | {
|
|
7
|
-
op: "presence";
|
|
8
|
-
presence: Record<string, unknown> | null;
|
|
9
|
-
};
|
|
10
|
-
export declare function parseRoomInput(line: string): Input;
|
|
11
|
-
export declare function readRoomLines(input: Readable, maxBytes?: number): AsyncGenerator<string>;
|
|
12
|
-
export declare function connectToRoom(roomId: string, options: {
|
|
13
|
-
after?: string;
|
|
14
|
-
input?: boolean;
|
|
15
|
-
json: boolean;
|
|
16
|
-
}): Promise<void>;
|
|
17
|
-
export {};
|