@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,441 +0,0 @@
|
|
|
1
|
-
import { spawn } from "node:child_process";
|
|
2
|
-
import { randomBytes, randomUUID } from "node:crypto";
|
|
3
|
-
import { createServer } from "node:net";
|
|
4
|
-
import { createInterface } from "node:readline";
|
|
5
|
-
import { setTimeout as delay } from "node:timers/promises";
|
|
6
|
-
import { PassThrough } from "node:stream";
|
|
7
|
-
import { resolveWebsocketUrl } from "@neta-art/cohub";
|
|
8
|
-
import { AuthRequiredError, resolveAccessToken } from "../auth.js";
|
|
9
|
-
import { createClient } from "../client.js";
|
|
10
|
-
import { currentIdentityKey } from "../space.js";
|
|
11
|
-
import { CLI_VERSION } from "../version.js";
|
|
12
|
-
import { ensureSandboxdBinary } from "../commands/sandboxd-binary.js";
|
|
13
|
-
import { serveRuntime } from "./connection.js";
|
|
14
|
-
import { discoverHarnesses, refreshHarnesses } from "./harnesses/index.js";
|
|
15
|
-
import { RuntimeDiagnostics, serializeDiagnosticError } from "./diagnostics.js";
|
|
16
|
-
import { ownRuntimeInstance, runtimeInstanceDirectory, UNCONFIRMED_WORK } from "./instance.js";
|
|
17
|
-
import { readRuntimePreferences } from "./preferences.js";
|
|
18
|
-
import { createDiagnosticConsole } from "./presentation.js";
|
|
19
|
-
import { join } from "node:path";
|
|
20
|
-
import { RuntimeArchiveStore } from "./archive-store.js";
|
|
21
|
-
import { appendCliToPath } from "./cli-path.js";
|
|
22
|
-
import { readNativeConfig, runtimeStateRoot } from "./native/config.js";
|
|
23
|
-
import { NativeRuntime } from "./native/daemon.js";
|
|
24
|
-
const DISPLAY_ANSWER_MS = 10_000;
|
|
25
|
-
const ACTIVITY_MS = 60_000;
|
|
26
|
-
export function sandboxOutputLevel(value, stream) {
|
|
27
|
-
const level = typeof value === "string" ? value.toLowerCase() : "";
|
|
28
|
-
if (["debug", "info", "warn", "error"].includes(level))
|
|
29
|
-
return level;
|
|
30
|
-
return stream === "stderr" ? "warn" : "debug";
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Windows cannot hand sandboxd an extra inherited pipe, so control frames use a
|
|
34
|
-
* named pipe instead. Only the first client is accepted; the name is unguessable.
|
|
35
|
-
*/
|
|
36
|
-
async function listenWindowsControlPipe() {
|
|
37
|
-
const path = `\\\\.\\pipe\\cohub-sandboxd-${randomUUID()}`;
|
|
38
|
-
const stream = new PassThrough();
|
|
39
|
-
const server = createServer((socket) => {
|
|
40
|
-
server.close();
|
|
41
|
-
socket.on("error", () => stream.end());
|
|
42
|
-
socket.pipe(stream);
|
|
43
|
-
});
|
|
44
|
-
await new Promise((resolve, reject) => {
|
|
45
|
-
server.once("error", reject);
|
|
46
|
-
server.listen(path, () => { server.removeListener("error", reject); resolve(); });
|
|
47
|
-
});
|
|
48
|
-
return { path, stream, close: () => { server.close(); stream.end(); } };
|
|
49
|
-
}
|
|
50
|
-
export async function runRuntime(config, onState, externalSignal, onDiagnostic) {
|
|
51
|
-
const controller = new AbortController();
|
|
52
|
-
const signal = externalSignal ? AbortSignal.any([externalSignal, controller.signal]) : controller.signal;
|
|
53
|
-
const stop = () => controller.abort();
|
|
54
|
-
process.once("SIGINT", stop);
|
|
55
|
-
process.once("SIGTERM", stop);
|
|
56
|
-
appendCliToPath();
|
|
57
|
-
const client = createClient();
|
|
58
|
-
const space = client.space(config.spaceId);
|
|
59
|
-
const stateRoot = runtimeStateRoot(config.spaceId);
|
|
60
|
-
const archives = new RuntimeArchiveStore(join(stateRoot, "archives"), space);
|
|
61
|
-
const consoleSink = config.background ? undefined : createDiagnosticConsole(config.verbose);
|
|
62
|
-
const diagnostics = new RuntimeDiagnostics({
|
|
63
|
-
root: stateRoot, spaceId: config.spaceId, runtimeId: randomUUID(),
|
|
64
|
-
onEvent: (event) => { consoleSink?.(event); onDiagnostic?.(event); },
|
|
65
|
-
});
|
|
66
|
-
archives.setErrorReporter((error, index) => diagnostics.log("warn", "archive.upload_pending", { error: serializeDiagnosticError(error) }, {
|
|
67
|
-
component: "archive", sessionId: index?.sessionId, turnId: index?.turnId, harness: index?.harness,
|
|
68
|
-
}));
|
|
69
|
-
const native = new NativeRuntime({
|
|
70
|
-
spaceId: config.spaceId, root: config.root, stateRoot, harnesses: config.harnesses, executables: config.executables,
|
|
71
|
-
identity: config.identity, config: await readNativeConfig(stateRoot, config.identity).catch(() => null),
|
|
72
|
-
archives, projectionSource: space, diagnostics,
|
|
73
|
-
});
|
|
74
|
-
let status = {
|
|
75
|
-
spaceId: config.spaceId, root: config.root, runtimeId: diagnostics.runtimeId,
|
|
76
|
-
pid: process.pid, version: CLI_VERSION, harnesses: config.harnesses, background: config.background,
|
|
77
|
-
...(config.display ? { display: config.display } : {}),
|
|
78
|
-
state: "starting", harnessConnected: false, workspaceConnected: false,
|
|
79
|
-
diagnosticsPath: diagnostics.directory,
|
|
80
|
-
};
|
|
81
|
-
const summary = () => ({ ...status, native: native.status() });
|
|
82
|
-
let instance;
|
|
83
|
-
let hasBeenReady = false;
|
|
84
|
-
const update = (patch) => {
|
|
85
|
-
const next = { ...status, ...patch };
|
|
86
|
-
if (next.state !== "stopping" && next.state !== "attention")
|
|
87
|
-
next.state = next.harnessConnected && next.workspaceConnected ? "ready" : hasBeenReady ? "reconnecting" : "starting";
|
|
88
|
-
if (JSON.stringify(status) === JSON.stringify(next))
|
|
89
|
-
return;
|
|
90
|
-
const becameReady = next.state === "ready" && status.state !== "ready";
|
|
91
|
-
status = next;
|
|
92
|
-
if (becameReady) {
|
|
93
|
-
hasBeenReady = true;
|
|
94
|
-
diagnostics.log("info", "runtime.available");
|
|
95
|
-
}
|
|
96
|
-
onState({ ...status });
|
|
97
|
-
instance?.changed();
|
|
98
|
-
};
|
|
99
|
-
let bridgeTask;
|
|
100
|
-
let retryDisconnectedBridge;
|
|
101
|
-
let nativeStarted = false;
|
|
102
|
-
let tokenInFlight = null;
|
|
103
|
-
const executions = new Map();
|
|
104
|
-
let bridgeControl = null;
|
|
105
|
-
let workspace = null;
|
|
106
|
-
let displayAnswer = null;
|
|
107
|
-
const applyKeepAwake = async () => {
|
|
108
|
-
if (bridgeControl?.features.includes("keepAwake"))
|
|
109
|
-
bridgeControl.send({ type: "keepAwake", enabled: (await readRuntimePreferences()).keepAwake });
|
|
110
|
-
};
|
|
111
|
-
const setDisplay = async (spec) => {
|
|
112
|
-
if (bridgeControl && !bridgeControl.features.includes("display"))
|
|
113
|
-
throw new Error("This Runtime cannot change its screen while running; reconnect it");
|
|
114
|
-
if (!spec)
|
|
115
|
-
update({ display: undefined, displayOnRequest: undefined, displayNeeds: undefined });
|
|
116
|
-
if (!bridgeControl) {
|
|
117
|
-
if (!spec)
|
|
118
|
-
return summary();
|
|
119
|
-
throw new Error("The file bridge is restarting; try again");
|
|
120
|
-
}
|
|
121
|
-
const { send } = bridgeControl;
|
|
122
|
-
const before = status.displayOnRequest;
|
|
123
|
-
if (spec)
|
|
124
|
-
update({ displayOnRequest: true });
|
|
125
|
-
const frame = await new Promise((resolve, reject) => {
|
|
126
|
-
const timer = setTimeout(() => {
|
|
127
|
-
displayAnswer = null;
|
|
128
|
-
if (spec)
|
|
129
|
-
send({ type: "display", spec: "" });
|
|
130
|
-
update({ display: undefined, displayOnRequest: undefined, displayNeeds: undefined });
|
|
131
|
-
reject(new Error("The file bridge did not answer"));
|
|
132
|
-
}, DISPLAY_ANSWER_MS);
|
|
133
|
-
displayAnswer = (answer) => {
|
|
134
|
-
if (!answer.error && answer.spec !== spec)
|
|
135
|
-
return;
|
|
136
|
-
clearTimeout(timer);
|
|
137
|
-
displayAnswer = null;
|
|
138
|
-
resolve(answer);
|
|
139
|
-
};
|
|
140
|
-
send({ type: "display", spec });
|
|
141
|
-
});
|
|
142
|
-
if (frame.error) {
|
|
143
|
-
update({ displayOnRequest: before });
|
|
144
|
-
throw new Error(frame.error);
|
|
145
|
-
}
|
|
146
|
-
return summary();
|
|
147
|
-
};
|
|
148
|
-
const token = (forceRefresh = false) => {
|
|
149
|
-
tokenInFlight ??= (async () => {
|
|
150
|
-
if (currentIdentityKey() !== config.identity)
|
|
151
|
-
throw new AuthRequiredError("Runtime account changed; sign in to the original account");
|
|
152
|
-
const value = await resolveAccessToken({ forceRefresh });
|
|
153
|
-
if (!value)
|
|
154
|
-
throw new AuthRequiredError();
|
|
155
|
-
if (currentIdentityKey() !== config.identity)
|
|
156
|
-
throw new AuthRequiredError("Runtime account changed");
|
|
157
|
-
return value;
|
|
158
|
-
})().finally(() => { tokenInFlight = null; });
|
|
159
|
-
return tokenInFlight;
|
|
160
|
-
};
|
|
161
|
-
try {
|
|
162
|
-
instance = await ownRuntimeInstance(runtimeInstanceDirectory(config.identity, config.spaceId), summary, async (force) => {
|
|
163
|
-
if (!force)
|
|
164
|
-
for await (const batch of native.executor.results.pendingBatches()) {
|
|
165
|
-
if (batch.length)
|
|
166
|
-
throw new Error(`${UNCONFIRMED_WORK}. Use down --yes to stop; results and files are retained`);
|
|
167
|
-
}
|
|
168
|
-
update({ state: "stopping" });
|
|
169
|
-
setTimeout(stop, 30);
|
|
170
|
-
}, (action, message) => {
|
|
171
|
-
if (action === "display")
|
|
172
|
-
return setDisplay(String(message.spec ?? ""));
|
|
173
|
-
if (action === "keepAwake")
|
|
174
|
-
return applyKeepAwake();
|
|
175
|
-
if (action === "workspace")
|
|
176
|
-
return Promise.resolve(status.state === "ready" ? workspace : null);
|
|
177
|
-
return native.control(action, message);
|
|
178
|
-
});
|
|
179
|
-
onState({ ...status });
|
|
180
|
-
diagnostics.log("info", "runtime.cli_started", { platform: process.platform, node: process.versions.node, harnesses: config.harnesses });
|
|
181
|
-
const [binary, capabilities] = await Promise.all([
|
|
182
|
-
ensureSandboxdBinary({ onStatus: (message) => diagnostics.log("info", "sandboxd.download", { message }) }),
|
|
183
|
-
config.capabilities ?? discoverHarnesses(config.harnesses, config.executables, config.root),
|
|
184
|
-
]);
|
|
185
|
-
signal.throwIfAborted();
|
|
186
|
-
const url = new URL(resolveWebsocketUrl());
|
|
187
|
-
url.pathname = url.pathname.replace(/\/ws$/, "/runtime/relay");
|
|
188
|
-
const relay = new URL(url);
|
|
189
|
-
relay.pathname = relay.pathname.replace(/\/runtime\/relay$/, "/sandbox/relay");
|
|
190
|
-
const runBridge = async () => {
|
|
191
|
-
let attempts = 0;
|
|
192
|
-
while (!signal.aborted) {
|
|
193
|
-
// A bridge may only register while this process owns the Harness lease.
|
|
194
|
-
if (!status.harnessConnected) {
|
|
195
|
-
await delay(500, undefined, { signal }).catch(() => undefined);
|
|
196
|
-
continue;
|
|
197
|
-
}
|
|
198
|
-
const startedAt = Date.now();
|
|
199
|
-
let refreshTimer;
|
|
200
|
-
let probeTimer;
|
|
201
|
-
let managed = false;
|
|
202
|
-
let childStopped = false;
|
|
203
|
-
let bridgeDisconnected = false;
|
|
204
|
-
let terminating = false;
|
|
205
|
-
let recoveryTimer;
|
|
206
|
-
let controlPipe = null;
|
|
207
|
-
try {
|
|
208
|
-
const initialToken = await token();
|
|
209
|
-
signal.throwIfAborted();
|
|
210
|
-
if (process.platform === "win32")
|
|
211
|
-
controlPipe = await listenWindowsControlPipe();
|
|
212
|
-
const spawnedScreen = status.display ?? "";
|
|
213
|
-
const localToken = randomBytes(32).toString("base64url");
|
|
214
|
-
const bridge = spawn(binary, ["--local", "--space", config.spaceId, "--root", config.root, "--relay", process.env.COHUB_RELAY_URL?.trim() || relay.toString()], {
|
|
215
|
-
stdio: controlPipe ? ["pipe", "pipe", "pipe"] : ["pipe", "pipe", "pipe", "pipe"],
|
|
216
|
-
windowsHide: true,
|
|
217
|
-
env: { ...process.env, COHUB_RELAY_TOKEN: initialToken, COHUB_LOCAL_TOKEN: localToken, COHUB_RUNTIME_ID: status.runtimeId, COHUB_LOG_FORMAT: "json", COHUB_RUNTIME_MANAGED: "1", COHUB_DISPLAY: spawnedScreen, ...(controlPipe ? { COHUB_RUNTIME_CONTROL_PIPE: controlPipe.path } : {}) },
|
|
218
|
-
});
|
|
219
|
-
bridge.stdin?.on("error", () => undefined);
|
|
220
|
-
const closed = new Promise((resolve) => {
|
|
221
|
-
let drainTimer;
|
|
222
|
-
bridge.once("error", (error) => diagnostics.log("error", "sandboxd.process_error", { error: serializeDiagnosticError(error) }));
|
|
223
|
-
bridge.once("exit", (code, exitSignal) => {
|
|
224
|
-
childStopped = true;
|
|
225
|
-
clearTimeout(recoveryTimer);
|
|
226
|
-
recoveryTimer = undefined;
|
|
227
|
-
if (!signal.aborted)
|
|
228
|
-
diagnostics.log("warn", "sandboxd.process_exit", { code, signal: exitSignal });
|
|
229
|
-
// Descendants may still hold inherited pipes. After draining buffered
|
|
230
|
-
// output, close only our ends so supervision can continue.
|
|
231
|
-
drainTimer = setTimeout(() => {
|
|
232
|
-
diagnostics.log("warn", "sandboxd.stdio_drain_timeout");
|
|
233
|
-
for (const stream of bridge.stdio)
|
|
234
|
-
stream?.destroy();
|
|
235
|
-
}, 1000);
|
|
236
|
-
});
|
|
237
|
-
bridge.once("close", () => {
|
|
238
|
-
childStopped = true;
|
|
239
|
-
clearTimeout(drainTimer);
|
|
240
|
-
resolve();
|
|
241
|
-
});
|
|
242
|
-
});
|
|
243
|
-
for (const streamName of ["stdout", "stderr"]) {
|
|
244
|
-
const stream = bridge[streamName];
|
|
245
|
-
if (!stream)
|
|
246
|
-
continue;
|
|
247
|
-
const lines = createInterface({ input: stream });
|
|
248
|
-
lines.on("line", (line) => {
|
|
249
|
-
let parsed = null;
|
|
250
|
-
try {
|
|
251
|
-
const value = JSON.parse(line);
|
|
252
|
-
if (value && typeof value === "object" && !Array.isArray(value))
|
|
253
|
-
parsed = value;
|
|
254
|
-
}
|
|
255
|
-
catch { /* Compatibility with text loggers. */ }
|
|
256
|
-
const data = parsed ? Object.fromEntries(Object.entries(parsed).filter(([key]) => !["msg", "level", "time"].includes(key))) : {};
|
|
257
|
-
diagnostics.log(sandboxOutputLevel(parsed?.level, streamName), "sandboxd.log", { ...data, message: parsed?.msg ?? line }, { component: "sandboxd" });
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
const control = controlPipe ? controlPipe.stream : bridge.stdio[3];
|
|
261
|
-
const events = createInterface({ input: control });
|
|
262
|
-
events.on("line", (line) => {
|
|
263
|
-
try {
|
|
264
|
-
const event = JSON.parse(line);
|
|
265
|
-
if (event.type === "hello")
|
|
266
|
-
managed = true;
|
|
267
|
-
if (event.type === "features") {
|
|
268
|
-
bridgeControl = { features: event.features, send: (frame) => bridge.stdin?.write(`${JSON.stringify(frame)}\n`) };
|
|
269
|
-
void applyKeepAwake().catch(() => undefined);
|
|
270
|
-
if ((status.display ?? "") !== spawnedScreen)
|
|
271
|
-
bridgeControl.send({ type: "display", spec: status.display ?? "" });
|
|
272
|
-
}
|
|
273
|
-
if (event.type === "local" && Number.isInteger(event.port)) {
|
|
274
|
-
workspace = { url: `http://127.0.0.1:${event.port}`, token: localToken };
|
|
275
|
-
update({ direct: true });
|
|
276
|
-
}
|
|
277
|
-
if (event.type === "display") {
|
|
278
|
-
update({ display: event.spec || undefined, displayNeeds: event.needs?.length ? event.needs : undefined });
|
|
279
|
-
displayAnswer?.(event);
|
|
280
|
-
}
|
|
281
|
-
if (event.type === "connected" || event.type === "disconnected") {
|
|
282
|
-
const connected = event.type === "connected";
|
|
283
|
-
bridgeDisconnected = !connected;
|
|
284
|
-
update({ workspaceConnected: connected });
|
|
285
|
-
diagnostics.log(connected ? "info" : "warn", `sandboxd.${event.type}`);
|
|
286
|
-
retryDisconnectedBridge?.();
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
catch {
|
|
290
|
-
diagnostics.log("warn", "sandboxd.control_invalid");
|
|
291
|
-
}
|
|
292
|
-
});
|
|
293
|
-
const refresh = async () => {
|
|
294
|
-
try {
|
|
295
|
-
const next = await token();
|
|
296
|
-
if (!childStopped && managed && !signal.aborted)
|
|
297
|
-
bridge.stdin?.write(`${JSON.stringify({ type: "auth", token: next })}\n`);
|
|
298
|
-
}
|
|
299
|
-
catch (error) {
|
|
300
|
-
diagnostics.log("warn", error instanceof AuthRequiredError ? "runtime.auth_required" : "runtime.auth_token_failed", { error: serializeDiagnosticError(error) });
|
|
301
|
-
}
|
|
302
|
-
if (!childStopped && !signal.aborted)
|
|
303
|
-
refreshTimer = setTimeout(() => void refresh(), 10_000);
|
|
304
|
-
};
|
|
305
|
-
void refresh();
|
|
306
|
-
// Released older sandboxd binaries do not have the private control pipe.
|
|
307
|
-
// Ask the authoritative API instead of parsing human-readable log lines.
|
|
308
|
-
const probe = async () => {
|
|
309
|
-
if (!managed && !childStopped && !signal.aborted) {
|
|
310
|
-
try {
|
|
311
|
-
const remote = await space.getRuntime(undefined, { signal: AbortSignal.any([signal, AbortSignal.timeout(5000)]) });
|
|
312
|
-
if (!childStopped && !managed)
|
|
313
|
-
update({ workspaceConnected: remote.runtimeId === status.runtimeId && remote.workspace?.online === true });
|
|
314
|
-
}
|
|
315
|
-
catch {
|
|
316
|
-
if (!childStopped && !managed)
|
|
317
|
-
update({ workspaceConnected: false });
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
if (!childStopped && !signal.aborted && !managed)
|
|
321
|
-
probeTimer = setTimeout(() => void probe(), 5000);
|
|
322
|
-
};
|
|
323
|
-
probeTimer = setTimeout(() => void probe(), 1000);
|
|
324
|
-
const terminate = () => {
|
|
325
|
-
if (terminating || childStopped)
|
|
326
|
-
return;
|
|
327
|
-
terminating = true;
|
|
328
|
-
clearTimeout(recoveryTimer);
|
|
329
|
-
recoveryTimer = undefined;
|
|
330
|
-
// Windows has no SIGTERM; closing the managed stdin lets sandboxd stop gracefully.
|
|
331
|
-
if (process.platform === "win32")
|
|
332
|
-
bridge.stdin?.end();
|
|
333
|
-
else
|
|
334
|
-
bridge.kill("SIGTERM");
|
|
335
|
-
const timeout = setTimeout(() => bridge.kill("SIGKILL"), 3000);
|
|
336
|
-
void closed.finally(() => clearTimeout(timeout));
|
|
337
|
-
};
|
|
338
|
-
// A managed bridge may be sleeping for five minutes after a lease
|
|
339
|
-
// rejection. Retry only after it reports a lost connection and the
|
|
340
|
-
// Harness has regained its lease; a connected bridge stays untouched.
|
|
341
|
-
retryDisconnectedBridge = () => {
|
|
342
|
-
if (signal.aborted || !status.harnessConnected || !bridgeDisconnected || terminating || childStopped) {
|
|
343
|
-
clearTimeout(recoveryTimer);
|
|
344
|
-
recoveryTimer = undefined;
|
|
345
|
-
}
|
|
346
|
-
else if (!recoveryTimer) {
|
|
347
|
-
// Give the bridge its normal retry and channel reattachment
|
|
348
|
-
// window before replacing a process stuck in config backoff.
|
|
349
|
-
recoveryTimer = setTimeout(() => {
|
|
350
|
-
recoveryTimer = undefined;
|
|
351
|
-
if (!signal.aborted && status.harnessConnected && bridgeDisconnected && !terminating && !childStopped) {
|
|
352
|
-
diagnostics.log("info", "sandboxd.lease_recovery");
|
|
353
|
-
terminate();
|
|
354
|
-
}
|
|
355
|
-
}, 30_000);
|
|
356
|
-
}
|
|
357
|
-
};
|
|
358
|
-
signal.addEventListener("abort", terminate, { once: true });
|
|
359
|
-
if (signal.aborted)
|
|
360
|
-
terminate();
|
|
361
|
-
await closed;
|
|
362
|
-
signal.removeEventListener("abort", terminate);
|
|
363
|
-
}
|
|
364
|
-
catch (error) {
|
|
365
|
-
if (!signal.aborted)
|
|
366
|
-
diagnostics.log("warn", "sandboxd.restart_failed", { error: serializeDiagnosticError(error) });
|
|
367
|
-
}
|
|
368
|
-
finally {
|
|
369
|
-
retryDisconnectedBridge = undefined;
|
|
370
|
-
bridgeControl = null;
|
|
371
|
-
workspace = null;
|
|
372
|
-
childStopped = true;
|
|
373
|
-
controlPipe?.close();
|
|
374
|
-
clearTimeout(refreshTimer);
|
|
375
|
-
clearTimeout(probeTimer);
|
|
376
|
-
clearTimeout(recoveryTimer);
|
|
377
|
-
update({ workspaceConnected: false, direct: undefined });
|
|
378
|
-
}
|
|
379
|
-
if (Date.now() - startedAt > 60_000)
|
|
380
|
-
attempts = 0;
|
|
381
|
-
const backoff = Math.min(30_000, 500 * 2 ** Math.min(attempts++, 6));
|
|
382
|
-
await delay(backoff / 2 + Math.random() * backoff / 2, undefined, { signal }).catch(() => undefined);
|
|
383
|
-
}
|
|
384
|
-
};
|
|
385
|
-
bridgeTask = runBridge();
|
|
386
|
-
const activity = setInterval(() => {
|
|
387
|
-
if (executions.size || native.status().running)
|
|
388
|
-
bridgeControl?.send({ type: "activity" });
|
|
389
|
-
}, ACTIVITY_MS);
|
|
390
|
-
activity.unref();
|
|
391
|
-
signal.addEventListener("abort", () => clearInterval(activity), { once: true });
|
|
392
|
-
await native.start(signal);
|
|
393
|
-
nativeStarted = true;
|
|
394
|
-
let importRequested = Boolean(config.importHistory);
|
|
395
|
-
await serveRuntime({
|
|
396
|
-
spaceId: config.spaceId, cwd: config.root, url: url.toString(), capabilities,
|
|
397
|
-
refreshCapabilities: (current) => refreshHarnesses(current, config.executables, config.root, (harness, error) => diagnostics.log("warn", "runtime.harness_catalog_failed", { harness, error: serializeDiagnosticError(error) })),
|
|
398
|
-
runtimeId: status.runtimeId, diagnostics, token, signal, executor: native.executor, executions,
|
|
399
|
-
onReady: () => { update({ harnessConnected: true }); retryDisconnectedBridge?.(); },
|
|
400
|
-
onDisconnected: () => { native.connect(null); update({ harnessConnected: false }); retryDisconnectedBridge?.(); },
|
|
401
|
-
onNativeStop: (stop) => { native.stop(stop.sessionId, stop.turnId); },
|
|
402
|
-
onApprovalDecision: (decision) => { native.executor.approvals.decide(decision); },
|
|
403
|
-
onNativeChannel: (send, features) => {
|
|
404
|
-
native.connect(send, features);
|
|
405
|
-
if (!importRequested)
|
|
406
|
-
return;
|
|
407
|
-
importRequested = false;
|
|
408
|
-
void native.control("import", { command: "start" }).catch((error) => diagnostics.log("warn", "native.import_failed", { error: serializeDiagnosticError(error) }));
|
|
409
|
-
},
|
|
410
|
-
});
|
|
411
|
-
}
|
|
412
|
-
catch (error) {
|
|
413
|
-
if (!signal.aborted) {
|
|
414
|
-
update({ state: "attention" });
|
|
415
|
-
diagnostics.log("error", "runtime.failed", { error: serializeDiagnosticError(error) });
|
|
416
|
-
throw error;
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
finally {
|
|
420
|
-
controller.abort();
|
|
421
|
-
try {
|
|
422
|
-
await bridgeTask;
|
|
423
|
-
if (nativeStarted)
|
|
424
|
-
await native.close(AbortSignal.timeout(5_000));
|
|
425
|
-
}
|
|
426
|
-
finally {
|
|
427
|
-
try {
|
|
428
|
-
await diagnostics.close();
|
|
429
|
-
}
|
|
430
|
-
finally {
|
|
431
|
-
try {
|
|
432
|
-
await instance?.close();
|
|
433
|
-
}
|
|
434
|
-
finally {
|
|
435
|
-
process.removeListener("SIGINT", stop);
|
|
436
|
-
process.removeListener("SIGTERM", stop);
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { CanonicalProjectionTurn, MessageToolCallsFile, ProjectionInput, ProjectionTarget, SessionTurnRecord, StoredIntermediateMessage, TurnIntermediateMessagesFile } from "@neta-art/cohub";
|
|
2
|
-
export type SessionTurnProjectionClient = {
|
|
3
|
-
session(sessionId: string): {
|
|
4
|
-
turns: {
|
|
5
|
-
listPaginated(options?: {
|
|
6
|
-
cursor?: number;
|
|
7
|
-
limit?: number;
|
|
8
|
-
direction?: "older" | "newer";
|
|
9
|
-
}, request?: {
|
|
10
|
-
signal?: AbortSignal;
|
|
11
|
-
}): Promise<{
|
|
12
|
-
turns: SessionTurnRecord[];
|
|
13
|
-
hasMore: boolean;
|
|
14
|
-
nextCursor: number | undefined;
|
|
15
|
-
}>;
|
|
16
|
-
get(turnId: string, request?: {
|
|
17
|
-
signal?: AbortSignal;
|
|
18
|
-
}): Promise<{
|
|
19
|
-
turn: SessionTurnRecord;
|
|
20
|
-
}>;
|
|
21
|
-
intermediate: {
|
|
22
|
-
get(turnId: string, messagesObjectKey?: string | null, options?: {
|
|
23
|
-
signal?: AbortSignal;
|
|
24
|
-
}): Promise<TurnIntermediateMessagesFile | null>;
|
|
25
|
-
getToolCalls(turnId: string, message: StoredIntermediateMessage, options?: {
|
|
26
|
-
signal?: AbortSignal;
|
|
27
|
-
}): Promise<MessageToolCallsFile | null>;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
export type ProjectionSourceTurn = CanonicalProjectionTurn;
|
|
33
|
-
export declare function listSessionProjectionTurns(source: SessionTurnProjectionClient, sessionId: string, options?: {
|
|
34
|
-
afterSequence?: number | null;
|
|
35
|
-
throughSequence?: number | null;
|
|
36
|
-
excludeTurnId?: string | null;
|
|
37
|
-
signal?: AbortSignal;
|
|
38
|
-
}): Promise<ProjectionSourceTurn[]>;
|
|
39
|
-
export declare function projectTurnBatch(input: Omit<ProjectionInput, "turns"> & {
|
|
40
|
-
turns: ProjectionSourceTurn[];
|
|
41
|
-
}, target: ProjectionTarget): import("@neta-art/cohub").NativeProjection;
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { harnessAdapter } from "./harnesses/index.js";
|
|
2
|
-
const record = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
3
|
-
const iso = (value) => value ?? new Date(0).toISOString();
|
|
4
|
-
const sourceSessionId = (turn) => turn.sourceSessionId ?? turn.sessionId;
|
|
5
|
-
const sourceTurnId = (turn) => turn.sourceTurnId ?? turn.id;
|
|
6
|
-
const userMessageId = (turn) => {
|
|
7
|
-
const value = record(turn.meta).userMessageId;
|
|
8
|
-
return typeof value === "string" && value ? value : `${turn.id}:user`;
|
|
9
|
-
};
|
|
10
|
-
function hydrateToolDetails(content, calls) {
|
|
11
|
-
const byId = new Map(calls.map((call) => [call.id, call]));
|
|
12
|
-
return content.map((block) => {
|
|
13
|
-
if (block.type === "tool_use") {
|
|
14
|
-
const call = byId.get(block.id);
|
|
15
|
-
return call ? { ...block, input: call.input } : block;
|
|
16
|
-
}
|
|
17
|
-
if (block.type === "tool_result") {
|
|
18
|
-
const call = byId.get(block.tool_use_id);
|
|
19
|
-
return call?.result ? { ...block, content: call.result.content ?? block.content, is_error: call.result.isError } : block;
|
|
20
|
-
}
|
|
21
|
-
return block;
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
async function hydrateIntermediateMessage(turn, message, client, signal) {
|
|
25
|
-
signal?.throwIfAborted();
|
|
26
|
-
const toolCalls = await client.turns.intermediate.getToolCalls(turn.id, message, { signal });
|
|
27
|
-
return {
|
|
28
|
-
id: message.id,
|
|
29
|
-
turnId: turn.id,
|
|
30
|
-
role: message.role,
|
|
31
|
-
content: hydrateToolDetails(message.content, toolCalls?.toolCalls ?? []),
|
|
32
|
-
provider: message.provider,
|
|
33
|
-
model: message.model,
|
|
34
|
-
usage: message.usage,
|
|
35
|
-
stopReason: message.stopReason,
|
|
36
|
-
errorMessage: message.errorMessage,
|
|
37
|
-
meta: message.meta,
|
|
38
|
-
sourceSessionId: message.sessionId,
|
|
39
|
-
sequence: message.sequence ?? 0,
|
|
40
|
-
createdAt: iso(message.createdAt),
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
async function mapWithConcurrency(items, concurrency, mapper) {
|
|
44
|
-
const results = new Array(items.length);
|
|
45
|
-
let next = 0;
|
|
46
|
-
const worker = async () => {
|
|
47
|
-
for (;;) {
|
|
48
|
-
const index = next++;
|
|
49
|
-
if (index >= items.length)
|
|
50
|
-
return;
|
|
51
|
-
const item = items[index];
|
|
52
|
-
if (item === undefined)
|
|
53
|
-
return;
|
|
54
|
-
results[index] = await mapper(item);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
await Promise.all(Array.from({ length: Math.min(concurrency, items.length) }, worker));
|
|
58
|
-
return results;
|
|
59
|
-
}
|
|
60
|
-
async function hydrateSessionTurn(turn, client, signal) {
|
|
61
|
-
const sourceId = sourceSessionId(turn);
|
|
62
|
-
const messages = [];
|
|
63
|
-
if (turn.userContent.length) {
|
|
64
|
-
messages.push({
|
|
65
|
-
id: userMessageId(turn), turnId: turn.id, role: "user", content: turn.userContent,
|
|
66
|
-
meta: { userMessageId: userMessageId(turn), turnId: turn.id }, sourceSessionId: sourceId,
|
|
67
|
-
sequence: turn.sequence * 1_000_000, createdAt: iso(turn.createdAt),
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
const objectKey = turn.intermediateIndex?.messagesObjectKey;
|
|
71
|
-
if (!objectKey && (turn.intermediateSummary?.messageCount ?? 0) > 0)
|
|
72
|
-
throw new Error(`Intermediate message index is unavailable for Turn ${turn.id}`);
|
|
73
|
-
if (objectKey) {
|
|
74
|
-
const archive = await client.turns.intermediate.get(turn.id, objectKey, { signal });
|
|
75
|
-
if (!archive)
|
|
76
|
-
throw new Error(`Intermediate messages are unavailable for Turn ${turn.id}`);
|
|
77
|
-
const intermediate = await mapWithConcurrency(archive.messages, 8, (message) => hydrateIntermediateMessage(turn, message, client, signal));
|
|
78
|
-
messages.push(...intermediate.map((message) => ({ ...message, sequence: turn.sequence * 1_000_000 + 100_000 + message.sequence })));
|
|
79
|
-
}
|
|
80
|
-
const hasFinalGenerationResult = messages.some((message) => message.role === "assistant" && message.meta?.messageKind === "generation_result" && ["completed", "failed"].includes(String(message.meta.generationStatus)));
|
|
81
|
-
if (turn.assistantContent?.length && !hasFinalGenerationResult) {
|
|
82
|
-
messages.push({
|
|
83
|
-
id: `${turn.id}:assistant`, turnId: turn.id, role: turn.intent === "compact" ? "system" : "assistant", content: turn.assistantContent,
|
|
84
|
-
provider: turn.provider, model: turn.model, usage: turn.finalUsage, stopReason: turn.stopReason, errorMessage: turn.errorMessage,
|
|
85
|
-
meta: { ...(turn.meta ?? {}), turnId: turn.id, createdAt: turn.createdAt }, sourceSessionId: sourceId,
|
|
86
|
-
sequence: turn.sequence * 1_000_000 + 900_000, createdAt: iso(turn.createdAt),
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
messages.sort((left, right) => left.sequence - right.sequence || left.id.localeCompare(right.id));
|
|
90
|
-
return {
|
|
91
|
-
id: turn.id, sourceSessionId: sourceId, sourceTurnId: sourceTurnId(turn), sequence: turn.sequence,
|
|
92
|
-
status: turn.status, intent: turn.intent, provider: turn.provider, model: turn.model,
|
|
93
|
-
userContent: turn.userContent, assistantContent: turn.assistantContent, meta: turn.meta,
|
|
94
|
-
createdAt: iso(turn.createdAt), startedAt: turn.startedAt, completedAt: turn.completedAt, durationMs: turn.durationMs,
|
|
95
|
-
messages,
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
export async function listSessionProjectionTurns(source, sessionId, options = {}) {
|
|
99
|
-
const client = source.session(sessionId);
|
|
100
|
-
const turns = [];
|
|
101
|
-
const throughSequence = options.throughSequence ?? null;
|
|
102
|
-
let cursor = options.afterSequence && options.afterSequence > 0 ? options.afterSequence : undefined;
|
|
103
|
-
for (;;) {
|
|
104
|
-
options.signal?.throwIfAborted();
|
|
105
|
-
const page = await client.turns.listPaginated({ cursor, limit: 100, direction: "newer" }, { signal: options.signal });
|
|
106
|
-
const visible = page.turns.filter((turn) => (throughSequence == null || turn.sequence <= throughSequence) && turn.id !== options.excludeTurnId && !["queued", "running", "abort_requested"].includes(turn.status));
|
|
107
|
-
turns.push(...visible);
|
|
108
|
-
if (throughSequence != null && page.turns.some((turn) => turn.sequence >= throughSequence))
|
|
109
|
-
break;
|
|
110
|
-
if (!page.hasMore)
|
|
111
|
-
break;
|
|
112
|
-
if (page.nextCursor === undefined || page.nextCursor === cursor)
|
|
113
|
-
throw new Error("Session Turn pagination did not advance");
|
|
114
|
-
cursor = page.nextCursor;
|
|
115
|
-
}
|
|
116
|
-
return mapWithConcurrency(turns, 4, (turn) => hydrateSessionTurn(turn, client, options.signal));
|
|
117
|
-
}
|
|
118
|
-
export function projectTurnBatch(input, target) {
|
|
119
|
-
return harnessAdapter(target).session.project(input);
|
|
120
|
-
}
|
package/dist/runtime/worker.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { type LookupFunction } from "node:net";
|
|
2
|
-
export declare const REMOTE_IMAGE_MAX_BYTES: number;
|
|
3
|
-
export declare const REMOTE_IMAGE_TIMEOUT_MS = 15000;
|
|
4
|
-
type ResolvedAddress = {
|
|
5
|
-
address: string;
|
|
6
|
-
family: 4 | 6;
|
|
7
|
-
};
|
|
8
|
-
type PinnedAddresses = readonly [ResolvedAddress, ...ResolvedAddress[]];
|
|
9
|
-
type Lookup = (hostname: string) => Promise<readonly ResolvedAddress[]>;
|
|
10
|
-
type RemoteResponse = {
|
|
11
|
-
status: number;
|
|
12
|
-
headers: Headers;
|
|
13
|
-
bytes: Uint8Array;
|
|
14
|
-
};
|
|
15
|
-
type Requester = (url: URL, addresses: PinnedAddresses, timeoutMs: number, maxBytes: number) => Promise<RemoteResponse>;
|
|
16
|
-
export type RemoteImageDownloadOptions = {
|
|
17
|
-
lookup?: Lookup;
|
|
18
|
-
requester?: Requester;
|
|
19
|
-
maxBytes?: number;
|
|
20
|
-
timeoutMs?: number;
|
|
21
|
-
};
|
|
22
|
-
/** Async like `dns.lookup`: a synchronous answer crashes TLS on an immediate connect failure. */
|
|
23
|
-
export declare function pinnedLookup(addresses: PinnedAddresses): LookupFunction;
|
|
24
|
-
export declare function downloadPublicImage(input: string, options?: RemoteImageDownloadOptions): Promise<{
|
|
25
|
-
bytes: Uint8Array;
|
|
26
|
-
mimeType: string;
|
|
27
|
-
}>;
|
|
28
|
-
export declare function downloadPublicAudio(input: string, options?: RemoteImageDownloadOptions): Promise<{
|
|
29
|
-
bytes: Uint8Array;
|
|
30
|
-
mimeType: string;
|
|
31
|
-
}>;
|
|
32
|
-
export declare function downloadPublicVideo(input: string, options?: RemoteImageDownloadOptions): Promise<{
|
|
33
|
-
bytes: Uint8Array;
|
|
34
|
-
mimeType: string;
|
|
35
|
-
}>;
|
|
36
|
-
export {};
|