@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
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { openAsBlob } from "node:fs";
|
|
2
|
-
import { stat } from "node:fs/promises";
|
|
3
|
-
import { arch, platform, release } from "node:os";
|
|
4
|
-
import { basename, resolve } from "node:path";
|
|
5
|
-
import { cliCommit } from "../version.js";
|
|
6
|
-
import { mimeTypeForPath, readRequestSourceFromEnv, resolveApiBaseUrl, resolveCohubEnvironment } from "@neta-art/cohub";
|
|
7
|
-
import { authSource } from "../auth.js";
|
|
8
|
-
import { createClient } from "../client.js";
|
|
9
|
-
import { collectOption, readPromptContent } from "../command-input.js";
|
|
10
|
-
import { describeError } from "../network-error.js";
|
|
11
|
-
import { error, json as outJson, jsonRequested, spinner } from "../output.js";
|
|
12
|
-
import { readRuntimeDiagnosticEvents } from "../runtime/diagnostics.js";
|
|
13
|
-
import { resolveRuntimeTarget } from "../runtime/launch.js";
|
|
14
|
-
import { runtimeStateRoot } from "../runtime/native/config.js";
|
|
15
|
-
import { explicitSpace } from "../space.js";
|
|
16
|
-
// Shared with the web feedback dialog; cfeed enforces attachment limits server-side.
|
|
17
|
-
const CFEED_ENDPOINT = "https://cfeed.neta.art/api/v1/feedback";
|
|
18
|
-
const CFEED_APP = "cohub";
|
|
19
|
-
const RUNTIME_LOG_MAX_BYTES = 5 * 1024 * 1024;
|
|
20
|
-
const RUNTIME_LOG_EVENTS = 2_000;
|
|
21
|
-
const USER_LOOKUP_TIMEOUT_MS = 3_000;
|
|
22
|
-
const SUBMIT_TIMEOUT_MS = 120_000;
|
|
23
|
-
async function readAttachment(path) {
|
|
24
|
-
const absolute = resolve(path);
|
|
25
|
-
const info = await stat(absolute).catch(() => null);
|
|
26
|
-
if (!info?.isFile())
|
|
27
|
-
return error(`Cannot attach ${path}`, "Pass a path to an existing file");
|
|
28
|
-
const type = mimeTypeForPath(absolute) ?? "application/octet-stream";
|
|
29
|
-
return new File([await openAsBlob(absolute, { type })], basename(absolute), { type });
|
|
30
|
-
}
|
|
31
|
-
async function runtimeLogFile(program, now) {
|
|
32
|
-
const spaceId = await resolveRuntimeTarget(program).catch((cause) => error("Cannot attach Runtime logs", describeError(cause)));
|
|
33
|
-
let events = await readRuntimeDiagnosticEvents(runtimeStateRoot(spaceId), { limit: RUNTIME_LOG_EVENTS });
|
|
34
|
-
let dropped = 0;
|
|
35
|
-
let text = JSON.stringify({ spaceId, dropped, events });
|
|
36
|
-
// Keep the newest events when the log exceeds the budget.
|
|
37
|
-
while (Buffer.byteLength(text) > RUNTIME_LOG_MAX_BYTES && events.length > 0) {
|
|
38
|
-
const count = Math.ceil(events.length / 2);
|
|
39
|
-
events = events.slice(count);
|
|
40
|
-
dropped += count;
|
|
41
|
-
text = JSON.stringify({ spaceId, dropped, events });
|
|
42
|
-
}
|
|
43
|
-
const stamp = now.toISOString().replace(/[-:]/g, "").replace(/\..+$/, "");
|
|
44
|
-
return new File([text], `cohub-runtime-${stamp}.json`, { type: "application/json" });
|
|
45
|
-
}
|
|
46
|
-
async function currentUserUuid() {
|
|
47
|
-
if (!authSource())
|
|
48
|
-
return null;
|
|
49
|
-
let timer;
|
|
50
|
-
const timeout = new Promise((done) => { timer = setTimeout(() => done(null), USER_LOOKUP_TIMEOUT_MS); });
|
|
51
|
-
const lookup = createClient().user.getMe().then((user) => user.uuid ?? null, () => null);
|
|
52
|
-
try {
|
|
53
|
-
return await Promise.race([lookup, timeout]);
|
|
54
|
-
}
|
|
55
|
-
finally {
|
|
56
|
-
clearTimeout(timer);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
async function submitFeedback(content, extra, files) {
|
|
60
|
-
const body = new FormData();
|
|
61
|
-
body.set("app", CFEED_APP);
|
|
62
|
-
body.set("content", content);
|
|
63
|
-
body.set("extra", JSON.stringify(extra));
|
|
64
|
-
for (const file of files)
|
|
65
|
-
body.append("files", file, file.name);
|
|
66
|
-
const response = await fetch(CFEED_ENDPOINT, { method: "POST", body, signal: AbortSignal.timeout(SUBMIT_TIMEOUT_MS) });
|
|
67
|
-
const payload = (await response.json().catch(() => null));
|
|
68
|
-
if (!response.ok)
|
|
69
|
-
throw new Error(payload?.error?.message ?? `${response.status} ${response.statusText}`);
|
|
70
|
-
if (!payload)
|
|
71
|
-
throw new Error("Feedback service returned an empty response");
|
|
72
|
-
return payload;
|
|
73
|
-
}
|
|
74
|
-
export function registerFeedback(program) {
|
|
75
|
-
program
|
|
76
|
-
.command("feedback [message...]")
|
|
77
|
-
.description("Send feedback or a bug report to the Cohub team")
|
|
78
|
-
.option("-f, --file <path>", "Attach a file; repeatable", collectOption, [])
|
|
79
|
-
.option("--runtime-logs", "Attach recent local Runtime diagnostics for the target Space")
|
|
80
|
-
.option("--json", "Output as JSON")
|
|
81
|
-
.addHelpText("after", `
|
|
82
|
-
The message comes from arguments or stdin. CLI version, OS, environment, account,
|
|
83
|
-
and COHUB_* Space/Chat context are attached automatically; your working directory is not.
|
|
84
|
-
|
|
85
|
-
Examples:
|
|
86
|
-
$ cohub feedback "runtime up hangs after sign-in"
|
|
87
|
-
$ cohub feedback "Board export is blurry" -f board.png -f export.log
|
|
88
|
-
$ cohub feedback --runtime-logs "Codex chats stopped syncing"
|
|
89
|
-
$ cat report.md | cohub feedback`)
|
|
90
|
-
.action(async (words, opts) => {
|
|
91
|
-
const asJson = jsonRequested(opts);
|
|
92
|
-
const content = await readPromptContent(words);
|
|
93
|
-
const now = new Date();
|
|
94
|
-
const [files, userUuid] = await Promise.all([
|
|
95
|
-
Promise.all([
|
|
96
|
-
...opts.file.map(readAttachment),
|
|
97
|
-
...(opts.runtimeLogs ? [runtimeLogFile(program, now)] : []),
|
|
98
|
-
]),
|
|
99
|
-
currentUserUuid(),
|
|
100
|
-
]);
|
|
101
|
-
const extra = {
|
|
102
|
-
user_uuid: userUuid,
|
|
103
|
-
cli_version: program.version() ?? null,
|
|
104
|
-
cli_commit: cliCommit(),
|
|
105
|
-
node: process.versions.node,
|
|
106
|
-
os: `${platform()} ${release()}`,
|
|
107
|
-
arch: arch(),
|
|
108
|
-
env: resolveCohubEnvironment(),
|
|
109
|
-
api_base_url: resolveApiBaseUrl(),
|
|
110
|
-
space: explicitSpace(program),
|
|
111
|
-
source: readRequestSourceFromEnv(process.env, { via: "cli" }),
|
|
112
|
-
locale: Intl.DateTimeFormat().resolvedOptions().locale,
|
|
113
|
-
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
114
|
-
tty: Boolean(process.stdout.isTTY),
|
|
115
|
-
has_runtime_logs: Boolean(opts.runtimeLogs),
|
|
116
|
-
};
|
|
117
|
-
const sp = asJson ? null : spinner();
|
|
118
|
-
sp?.start("Sending feedback");
|
|
119
|
-
try {
|
|
120
|
-
const result = await submitFeedback(content, extra, files);
|
|
121
|
-
if (asJson)
|
|
122
|
-
return outJson(result);
|
|
123
|
-
sp?.stop(`Feedback sent · ${result.id}`);
|
|
124
|
-
}
|
|
125
|
-
catch (cause) {
|
|
126
|
-
if (sp)
|
|
127
|
-
process.stderr.write("\n");
|
|
128
|
-
error("Couldn't send feedback", describeError(cause));
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
}
|
|
@@ -1,427 +0,0 @@
|
|
|
1
|
-
import { openAsBlob } from "node:fs";
|
|
2
|
-
import { mkdir, readFile, stat, writeFile } from "node:fs/promises";
|
|
3
|
-
import { basename, dirname, extname, join } from "node:path";
|
|
4
|
-
import { GenerationPolicyError, assertGenerationRequestAllowedByPolicy, mimeTypeForPath, parseGenerationPolicyFromEnv, } from "@neta-art/cohub";
|
|
5
|
-
import { probeMediaInfo } from "@neta-art/cohub/media";
|
|
6
|
-
import { createClient } from "../client.js";
|
|
7
|
-
import { resolveSpace } from "../space.js";
|
|
8
|
-
import { json as outJson, jsonRequested, ok, error, handleHttp, spinner } from "../output.js";
|
|
9
|
-
const frameMediaRoles = new Set(["first_frame", "last_frame"]);
|
|
10
|
-
const referenceMediaRoles = new Set(["reference_image", "reference_video", "reference_audio"]);
|
|
11
|
-
const rolesByMediaType = {
|
|
12
|
-
image: new Set([...frameMediaRoles, "reference_image"]),
|
|
13
|
-
video: new Set(["reference_video"]),
|
|
14
|
-
audio: new Set(["reference_audio"]),
|
|
15
|
-
};
|
|
16
|
-
const mediaRoles = new Set([...frameMediaRoles, ...referenceMediaRoles]);
|
|
17
|
-
function parseValue(value) {
|
|
18
|
-
const trimmed = value.trim();
|
|
19
|
-
if (trimmed === "true")
|
|
20
|
-
return true;
|
|
21
|
-
if (trimmed === "false")
|
|
22
|
-
return false;
|
|
23
|
-
if (/^-?\d+(\.\d+)?$/.test(trimmed))
|
|
24
|
-
return Number(trimmed);
|
|
25
|
-
if ((trimmed.startsWith("{") && trimmed.endsWith("}")) || (trimmed.startsWith("[") && trimmed.endsWith("]"))) {
|
|
26
|
-
try {
|
|
27
|
-
return JSON.parse(trimmed);
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
return value;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return value;
|
|
34
|
-
}
|
|
35
|
-
function parseTextInputs(values) {
|
|
36
|
-
return values.map((value) => {
|
|
37
|
-
const index = value.indexOf("=");
|
|
38
|
-
if (index < 0)
|
|
39
|
-
return error("Invalid --text", "Pass --text <role>=<text>.");
|
|
40
|
-
const role = value.slice(0, index).trim();
|
|
41
|
-
if (!role)
|
|
42
|
-
return error("Invalid --text", "Pass a role: --text <role>=<text>.");
|
|
43
|
-
const text = value.slice(index + 1);
|
|
44
|
-
if (!text)
|
|
45
|
-
return error("Invalid --text", 'Pass text after "=": --text <role>=<text>.');
|
|
46
|
-
return { role, text };
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
function parseParams(param, parameters) {
|
|
50
|
-
const result = parameters ? JSON.parse(parameters) : {};
|
|
51
|
-
for (const item of param ?? []) {
|
|
52
|
-
const index = item.indexOf("=");
|
|
53
|
-
if (index <= 0)
|
|
54
|
-
throw new Error(`Invalid --param value: ${item}`);
|
|
55
|
-
result[item.slice(0, index)] = parseValue(item.slice(index + 1));
|
|
56
|
-
}
|
|
57
|
-
return Object.keys(result).length > 0 ? result : undefined;
|
|
58
|
-
}
|
|
59
|
-
async function pathExists(path) {
|
|
60
|
-
return Boolean(await stat(path).catch(() => null));
|
|
61
|
-
}
|
|
62
|
-
async function parseMediaInput(type, rawValue) {
|
|
63
|
-
const separator = rawValue.indexOf("=");
|
|
64
|
-
if (separator <= 0)
|
|
65
|
-
return { type, value: rawValue };
|
|
66
|
-
const role = rawValue.slice(0, separator).trim();
|
|
67
|
-
if (!mediaRoles.has(role))
|
|
68
|
-
return { type, value: rawValue };
|
|
69
|
-
if (await pathExists(rawValue))
|
|
70
|
-
return { type, value: rawValue };
|
|
71
|
-
if (!rolesByMediaType[type].has(role)) {
|
|
72
|
-
return error("Invalid media role", `${role} cannot be used with --${type}`);
|
|
73
|
-
}
|
|
74
|
-
const value = rawValue.slice(separator + 1).trim();
|
|
75
|
-
if (!value)
|
|
76
|
-
return error("Invalid media input", `--${type} ${role}= requires a path or URL`);
|
|
77
|
-
return { type, value, role };
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Local inputs upload to an unlisted public URL so tasks store a reference, not
|
|
81
|
-
* megabytes of base64. Inline data remains for `--inline`, types the upload
|
|
82
|
-
* does not accept, and failed uploads.
|
|
83
|
-
*/
|
|
84
|
-
async function mediaContent({ type, value, role }, upload) {
|
|
85
|
-
const block = (source) => ({ type, source, ...(role ? { meta: { role } } : {}) });
|
|
86
|
-
if (/^https?:\/\//.test(value))
|
|
87
|
-
return block({ type: "url", url: value });
|
|
88
|
-
const mediaType = mimeTypeForPath(value);
|
|
89
|
-
if (mediaType && /^(image|video|audio)\//.test(mediaType) && upload) {
|
|
90
|
-
try {
|
|
91
|
-
return block({ type: "url", url: await upload(value, mediaType) });
|
|
92
|
-
}
|
|
93
|
-
catch (uploadError) {
|
|
94
|
-
const reason = uploadError instanceof Error ? uploadError.message : String(uploadError);
|
|
95
|
-
process.stderr.write(` Could not upload ${value} (${reason}); sending it inline.\n`);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
const data = await readFile(value);
|
|
99
|
-
return block({
|
|
100
|
-
type: "base64",
|
|
101
|
-
mediaType: mediaType ?? "application/octet-stream",
|
|
102
|
-
data: data.toString("base64"),
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
function validateMediaRoleModes(inputs) {
|
|
106
|
-
const roles = inputs.flatMap(({ role }) => (role ? [role] : []));
|
|
107
|
-
const hasFrameRole = roles.some((role) => frameMediaRoles.has(role));
|
|
108
|
-
const hasReferenceRole = roles.some((role) => referenceMediaRoles.has(role));
|
|
109
|
-
if (hasFrameRole && hasReferenceRole) {
|
|
110
|
-
error("Invalid media role mix", "Use first_frame/last_frame or reference_image/reference_video/reference_audio, not both.");
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
async function saveOutputs(output, outputPath) {
|
|
114
|
-
const outputs = output.filter((block) => block.type === "text" || block.type === "image" || block.type === "video" || block.type === "audio");
|
|
115
|
-
if (outputs.length === 0)
|
|
116
|
-
return [];
|
|
117
|
-
const info = await stat(outputPath).catch(() => null);
|
|
118
|
-
const isSingleFile = outputs.length === 1 && !(info?.isDirectory() ?? false);
|
|
119
|
-
const targetPath = isSingleFile ? outputPath : await resolveOutputDirectory(outputPath, info);
|
|
120
|
-
if (isSingleFile)
|
|
121
|
-
await mkdir(dirname(targetPath), { recursive: true });
|
|
122
|
-
else
|
|
123
|
-
await mkdir(targetPath, { recursive: true });
|
|
124
|
-
const savedPaths = [];
|
|
125
|
-
for (const [i, block] of outputs.entries()) {
|
|
126
|
-
if (block.type === "text") {
|
|
127
|
-
const target = isSingleFile ? targetPath : join(targetPath, `generation-${i + 1}.txt`);
|
|
128
|
-
await writeFile(target, block.text, "utf-8");
|
|
129
|
-
savedPaths.push(target);
|
|
130
|
-
continue;
|
|
131
|
-
}
|
|
132
|
-
const source = block.source;
|
|
133
|
-
const target = isSingleFile ? targetPath : join(targetPath, outputName(block, source.type === "url" ? source.url : undefined, i));
|
|
134
|
-
if (source.type === "url") {
|
|
135
|
-
const response = await fetch(source.url);
|
|
136
|
-
if (!response.ok)
|
|
137
|
-
throw new Error(`Failed to download ${source.url}: HTTP ${response.status}`);
|
|
138
|
-
await writeFile(target, Buffer.from(await response.arrayBuffer()));
|
|
139
|
-
savedPaths.push(target);
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
await writeFile(target, Buffer.from(source.data, "base64"));
|
|
143
|
-
savedPaths.push(target);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return savedPaths;
|
|
147
|
-
}
|
|
148
|
-
async function resolveOutputDirectory(outputPath, info) {
|
|
149
|
-
if (info?.isDirectory() || (!info && !extname(outputPath)))
|
|
150
|
-
return outputPath;
|
|
151
|
-
const ext = extname(outputPath);
|
|
152
|
-
const stem = ext ? basename(outputPath, ext) : basename(outputPath);
|
|
153
|
-
const parent = dirname(outputPath);
|
|
154
|
-
const base = join(parent, `${stem}-outputs`);
|
|
155
|
-
for (let i = 0;; i += 1) {
|
|
156
|
-
const candidate = i === 0 ? base : `${base}-${i + 1}`;
|
|
157
|
-
const candidateInfo = await stat(candidate).catch(() => null);
|
|
158
|
-
if (!candidateInfo || candidateInfo.isDirectory())
|
|
159
|
-
return candidate;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
function outputName(block, url, index) {
|
|
163
|
-
const fromUrl = url ? basename(new URL(url).pathname) : "";
|
|
164
|
-
const label = slugOutputLabel(block);
|
|
165
|
-
if (fromUrl?.includes("."))
|
|
166
|
-
return `generation-${index + 1}-${label}-${fromUrl}`;
|
|
167
|
-
const ext = block.type === "video" ? "mp4" : block.type === "audio" ? "bin" : block.type === "text" ? "txt" : "png";
|
|
168
|
-
return `generation-${index + 1}-${label}.${ext}`;
|
|
169
|
-
}
|
|
170
|
-
function metaRole(block) {
|
|
171
|
-
const role = block.meta?.role;
|
|
172
|
-
return typeof role === "string" && role.length > 0 ? role : undefined;
|
|
173
|
-
}
|
|
174
|
-
function humanizeRole(role) {
|
|
175
|
-
return role.replaceAll("_", " ").replaceAll("-", " ");
|
|
176
|
-
}
|
|
177
|
-
function slugify(value) {
|
|
178
|
-
return value.toLowerCase().replaceAll(/[^a-z0-9]+/g, "-").replaceAll(/^-|-$/g, "") || "output";
|
|
179
|
-
}
|
|
180
|
-
function formatOutputLabel(block) {
|
|
181
|
-
const role = metaRole(block);
|
|
182
|
-
if (!role)
|
|
183
|
-
return block.type;
|
|
184
|
-
const label = humanizeRole(role);
|
|
185
|
-
return block.type === "image" && ["first_frame", "last_frame", "reference_image"].includes(role)
|
|
186
|
-
? label
|
|
187
|
-
: `${block.type} (role: ${role})`;
|
|
188
|
-
}
|
|
189
|
-
function slugOutputLabel(block) {
|
|
190
|
-
return slugify(metaRole(block) ?? block.type);
|
|
191
|
-
}
|
|
192
|
-
const PROBE_TIMEOUT_MS = 3_000;
|
|
193
|
-
/** Size, duration, and frames of image, video, and audio URL outputs, probed in parallel; best effort. */
|
|
194
|
-
async function probeOutputs(output) {
|
|
195
|
-
const signal = AbortSignal.timeout(PROBE_TIMEOUT_MS);
|
|
196
|
-
const probed = await Promise.all(output.map(async (block, index) => {
|
|
197
|
-
if (block.type !== "image" && block.type !== "video" && block.type !== "audio")
|
|
198
|
-
return null;
|
|
199
|
-
if (block.source.type !== "url")
|
|
200
|
-
return null;
|
|
201
|
-
const info = await probeMediaInfo(block.source.url, { type: block.type, signal });
|
|
202
|
-
return Object.keys(info).length > 0 ? { index, ...info } : null;
|
|
203
|
-
}));
|
|
204
|
-
return probed.filter((media) => media !== null);
|
|
205
|
-
}
|
|
206
|
-
function mediaSummary(info) {
|
|
207
|
-
const parts = [
|
|
208
|
-
info?.width && info.height ? `${info.width}×${info.height}` : null,
|
|
209
|
-
info?.durationMs ? `${(info.durationMs / 1000).toFixed(1)}s` : null,
|
|
210
|
-
].filter(Boolean);
|
|
211
|
-
return parts.length > 0 ? ` ${parts.join(" · ")}` : "";
|
|
212
|
-
}
|
|
213
|
-
function printGeneration(output, media) {
|
|
214
|
-
const byIndex = new Map(media.map((info) => [info.index, info]));
|
|
215
|
-
for (const [index, block] of output.entries()) {
|
|
216
|
-
if (block.type === "text") {
|
|
217
|
-
console.log(block.text);
|
|
218
|
-
}
|
|
219
|
-
else if (block.source.type === "url") {
|
|
220
|
-
const info = byIndex.get(index);
|
|
221
|
-
console.log(`${formatOutputLabel(block)}${mediaSummary(info)}: ${block.source.url}`);
|
|
222
|
-
// The last frame chains into the next clip as its first_frame.
|
|
223
|
-
if (info?.lastFrameUrl)
|
|
224
|
-
console.log(` last frame: ${info.lastFrameUrl}`);
|
|
225
|
-
}
|
|
226
|
-
else {
|
|
227
|
-
console.log(`${formatOutputLabel(block)}: base64 ${block.source.mediaType} (${block.source.data.length} chars)`);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
function resumeHint(taskRunId) {
|
|
232
|
-
return `Use \`cohub tasks get ${taskRunId} --json\` to inspect the task later.`;
|
|
233
|
-
}
|
|
234
|
-
function formatElapsed(ms) {
|
|
235
|
-
if (ms < 1000)
|
|
236
|
-
return `${ms}ms`;
|
|
237
|
-
const seconds = Math.floor(ms / 1000);
|
|
238
|
-
if (seconds < 60)
|
|
239
|
-
return `${seconds}s`;
|
|
240
|
-
const minutes = Math.floor(seconds / 60);
|
|
241
|
-
const restSeconds = seconds % 60;
|
|
242
|
-
return restSeconds > 0 ? `${minutes}m ${restSeconds}s` : `${minutes}m`;
|
|
243
|
-
}
|
|
244
|
-
function parseTimeoutMs(value) {
|
|
245
|
-
if (!value)
|
|
246
|
-
return undefined;
|
|
247
|
-
if (!/^\d+$/.test(value.trim()))
|
|
248
|
-
return error("Invalid timeout", "--timeout-ms must be a positive integer");
|
|
249
|
-
const timeoutMs = Number.parseInt(value, 10);
|
|
250
|
-
if (!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0)
|
|
251
|
-
return error("Invalid timeout", "--timeout-ms must be a positive integer");
|
|
252
|
-
return timeoutMs;
|
|
253
|
-
}
|
|
254
|
-
function envValue(name) {
|
|
255
|
-
const value = process.env[name]?.trim();
|
|
256
|
-
return value || undefined;
|
|
257
|
-
}
|
|
258
|
-
function parseMeta(value) {
|
|
259
|
-
if (!value)
|
|
260
|
-
return undefined;
|
|
261
|
-
let parsed;
|
|
262
|
-
try {
|
|
263
|
-
parsed = JSON.parse(value);
|
|
264
|
-
}
|
|
265
|
-
catch {
|
|
266
|
-
return error("Invalid meta", "--meta must be a JSON object");
|
|
267
|
-
}
|
|
268
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
269
|
-
return error("Invalid meta", "--meta must be a JSON object");
|
|
270
|
-
}
|
|
271
|
-
return parsed;
|
|
272
|
-
}
|
|
273
|
-
export function registerGenerations(program) {
|
|
274
|
-
program
|
|
275
|
-
.command("generate")
|
|
276
|
-
.description("Generate multimodal outputs")
|
|
277
|
-
.argument("[prompt]", "Prompt text; optional when --text is given")
|
|
278
|
-
.requiredOption("-m, --model <model>", "Multimodal model ID from `cohub models ls --model-type multimodal`")
|
|
279
|
-
.option("--text <role=text>", "Text input with a role from the model's text inputs (`cohub models show <model>`); repeatable, split at the first =, text sent unchanged", collect, [])
|
|
280
|
-
.option("--image <path-or-url>", "Image input file path or URL; prefix with first_frame=, last_frame=, or reference_image= when needed; repeatable", collect, [])
|
|
281
|
-
.option("--video <path-or-url>", "Video input file path or URL; prefix with reference_video= when needed; repeatable", collect, [])
|
|
282
|
-
.option("--audio <path-or-url>", "Audio input file path or URL; prefix with reference_audio= when needed; repeatable", collect, [])
|
|
283
|
-
.option("--param <key=value>", "Generation parameter; repeatable, values may be JSON/number/boolean", collect, [])
|
|
284
|
-
.option("--parameters <json>", "Generation parameters as a JSON object")
|
|
285
|
-
.option("--meta <json>", "Meta as a JSON object")
|
|
286
|
-
.option("-o, --output <path>", "Save generated output to a file or directory")
|
|
287
|
-
.option("--inline", "Send local input files inline instead of uploading them to an unlisted public URL")
|
|
288
|
-
.option("--async", "Queue the generation task and return immediately")
|
|
289
|
-
.option("--timeout-ms <ms>", "Maximum time to wait in synchronous mode")
|
|
290
|
-
.option("--json", "Output as JSON")
|
|
291
|
-
.addHelpText("after", `
|
|
292
|
-
|
|
293
|
-
Local input files upload to an unlisted public URL before the task is created;
|
|
294
|
-
pass --inline to keep them inside the task instead.
|
|
295
|
-
|
|
296
|
-
Examples:
|
|
297
|
-
cohub models ls --model-type multimodal
|
|
298
|
-
cohub -s <space-id> generate "A calm lake at sunrise" -m <model> -o lake.png
|
|
299
|
-
COHUB_SPACE_ID=<space-id> cohub generate "Restyle this image" -m <model> --image input.png
|
|
300
|
-
cohub -s <space-id> generate "Smooth transition" -m seedance-2-0-fast --image first_frame=https://example.com/first.png --image last_frame=https://example.com/last.png
|
|
301
|
-
cohub -s <space-id> generate "Use these references" -m seedance-2-0-fast --image reference_image=https://example.com/a.png --image reference_image=https://example.com/b.png
|
|
302
|
-
cohub -s <space-id> generate "Lip-sync to the reference take" -m seedance-2-0-fast --image reference_image=https://example.com/portrait.png --audio reference_audio=https://example.com/speech.mp3
|
|
303
|
-
cohub -s <space-id> generate -m song2 --text "prompt=upbeat synthwave" --text "lyrics=[Verse] Neon lights" --param seed=42
|
|
304
|
-
cohub -s <space-id> generate "A calm lake" -m <model> --async
|
|
305
|
-
`)
|
|
306
|
-
.action(async (prompt, opts) => {
|
|
307
|
-
try {
|
|
308
|
-
const texts = parseTextInputs(opts.text);
|
|
309
|
-
if (prompt === undefined && texts.length === 0) {
|
|
310
|
-
return error("Missing prompt", "Pass a prompt or at least one --text <role>=<text>.");
|
|
311
|
-
}
|
|
312
|
-
const spaceId = await resolveSpace(program, { home: true });
|
|
313
|
-
const sessionId = envValue("COHUB_SESSION_ID");
|
|
314
|
-
const inputs = await Promise.all([
|
|
315
|
-
...opts.image.map((value) => parseMediaInput("image", value)),
|
|
316
|
-
...opts.video.map((value) => parseMediaInput("video", value)),
|
|
317
|
-
...opts.audio.map((value) => parseMediaInput("audio", value)),
|
|
318
|
-
]);
|
|
319
|
-
validateMediaRoleModes(inputs);
|
|
320
|
-
for (const { value } of inputs) {
|
|
321
|
-
if (!/^https?:\/\//.test(value) && !(await pathExists(value))) {
|
|
322
|
-
return error("Input not found", value);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
const parameters = parseParams(opts.param, opts.parameters);
|
|
326
|
-
try {
|
|
327
|
-
assertGenerationRequestAllowedByPolicy({
|
|
328
|
-
policy: parseGenerationPolicyFromEnv(process.env),
|
|
329
|
-
model: opts.model,
|
|
330
|
-
parameters,
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
catch (policyError) {
|
|
334
|
-
if (policyError instanceof GenerationPolicyError)
|
|
335
|
-
return error("Generation settings", policyError.message);
|
|
336
|
-
throw policyError;
|
|
337
|
-
}
|
|
338
|
-
const meta = parseMeta(opts.meta);
|
|
339
|
-
const client = createClient();
|
|
340
|
-
// Validate everything first, so rejected requests never upload files.
|
|
341
|
-
const upload = opts.inline ? null : async (path, mimeType) => {
|
|
342
|
-
const asset = await client.publicAssets.uploadGenerationInput({
|
|
343
|
-
spaceId,
|
|
344
|
-
sessionId,
|
|
345
|
-
file: await openAsBlob(path, { type: mimeType }),
|
|
346
|
-
mimeType,
|
|
347
|
-
filename: basename(path),
|
|
348
|
-
});
|
|
349
|
-
process.stderr.write(` Uploaded ${path} to an unlisted public URL; use --inline to keep inputs private.\n`);
|
|
350
|
-
return asset.publicUrl;
|
|
351
|
-
};
|
|
352
|
-
const content = [
|
|
353
|
-
...(prompt === undefined ? [] : [{ type: "text", text: prompt }]),
|
|
354
|
-
...texts.map(({ role, text }) => ({ type: "text", text, meta: { role } })),
|
|
355
|
-
...await Promise.all(inputs.map((input) => mediaContent(input, upload))),
|
|
356
|
-
];
|
|
357
|
-
const created = await client.generations.create({
|
|
358
|
-
spaceId,
|
|
359
|
-
sessionId,
|
|
360
|
-
turnId: envValue("COHUB_TURN_ID"),
|
|
361
|
-
model: opts.model,
|
|
362
|
-
content,
|
|
363
|
-
parameters,
|
|
364
|
-
meta,
|
|
365
|
-
});
|
|
366
|
-
if (opts.async) {
|
|
367
|
-
if (jsonRequested(opts))
|
|
368
|
-
return outJson(created);
|
|
369
|
-
const reserved = created.reservation ? `\n reserved: ${created.reservation.amountUsd} USD` : "";
|
|
370
|
-
return ok(`Generation queued — task ID: ${created.taskRunId}${reserved}\n ${resumeHint(created.taskRunId)}`);
|
|
371
|
-
}
|
|
372
|
-
const spin = spinner();
|
|
373
|
-
let pollCount = 0;
|
|
374
|
-
const waitStartedAt = Date.now();
|
|
375
|
-
if (!jsonRequested(opts)) {
|
|
376
|
-
process.stderr.write(` Generation queued — task ID: ${created.taskRunId}\n`);
|
|
377
|
-
process.stderr.write(` ${resumeHint(created.taskRunId)}\n`);
|
|
378
|
-
spin.start("Generating...");
|
|
379
|
-
}
|
|
380
|
-
const result = await client.generations.wait(created.taskRunId, {
|
|
381
|
-
timeoutMs: parseTimeoutMs(opts.timeoutMs),
|
|
382
|
-
onPoll: () => {
|
|
383
|
-
pollCount += 1;
|
|
384
|
-
spin.update(`Generating... ${formatElapsed(Date.now() - waitStartedAt)}, ${pollCount} polls`);
|
|
385
|
-
},
|
|
386
|
-
});
|
|
387
|
-
if (!jsonRequested(opts))
|
|
388
|
-
spin.stop(`Generation completed — task ID: ${created.taskRunId}, ${formatElapsed(Date.now() - waitStartedAt)}, ${pollCount} polls`);
|
|
389
|
-
const [savedPaths, outputMedia] = await Promise.all([
|
|
390
|
-
opts.output ? saveOutputs(result.output, opts.output) : Promise.resolve([]),
|
|
391
|
-
probeOutputs(result.output),
|
|
392
|
-
]);
|
|
393
|
-
if (jsonRequested(opts)) {
|
|
394
|
-
return outJson({
|
|
395
|
-
...result,
|
|
396
|
-
taskRunId: created.taskRunId,
|
|
397
|
-
...(outputMedia.length > 0 ? { outputMedia } : {}),
|
|
398
|
-
...(savedPaths.length > 0 ? { savedPaths } : {}),
|
|
399
|
-
});
|
|
400
|
-
}
|
|
401
|
-
printGeneration(result.output, outputMedia);
|
|
402
|
-
if (result.requestId || result.cost !== undefined || result.billing) {
|
|
403
|
-
const details = [
|
|
404
|
-
result.requestId ? `request ID: ${result.requestId}` : null,
|
|
405
|
-
result.cost !== undefined ? `official cost: ${result.cost}` : null,
|
|
406
|
-
result.billing ? `billing: ${result.billing.status}` : null,
|
|
407
|
-
result.billing ? `effective amount: ${result.billing.amountUsd}` : null,
|
|
408
|
-
result.billing?.discountMultiplier !== undefined
|
|
409
|
-
? `multiplier: ${result.billing.discountMultiplier}`
|
|
410
|
-
: null,
|
|
411
|
-
result.billing?.reason ? `billing reason: ${result.billing.reason}` : null,
|
|
412
|
-
].filter(Boolean).join(", ");
|
|
413
|
-
if (details)
|
|
414
|
-
process.stderr.write(` ${details}\n`);
|
|
415
|
-
}
|
|
416
|
-
if (savedPaths.length > 0)
|
|
417
|
-
ok(`Saved to ${savedPaths.join(", ")}`);
|
|
418
|
-
}
|
|
419
|
-
catch (e) {
|
|
420
|
-
handleHttp(e);
|
|
421
|
-
}
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
function collect(value, previous) {
|
|
425
|
-
previous.push(value);
|
|
426
|
-
return previous;
|
|
427
|
-
}
|
package/dist/commands/host.d.ts
DELETED
package/dist/commands/host.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export function registerHost(program) {
|
|
2
|
-
program
|
|
3
|
-
.command("host", { hidden: true })
|
|
4
|
-
.description("Machine interface for native desktop hosts")
|
|
5
|
-
.command("serve")
|
|
6
|
-
.description("Answer host bridge requests over stdio, one JSON message per line")
|
|
7
|
-
.action(async () => {
|
|
8
|
-
const { serveHost } = await import("../host/serve.js");
|
|
9
|
-
await serveHost();
|
|
10
|
-
});
|
|
11
|
-
}
|
package/dist/commands/me.d.ts
DELETED