@sagentlab/navarch-runtime 0.1.174 → 0.1.176
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/dist/adapters/acp.cjs +3 -2
- package/dist/adapters/antigravity.cjs +3 -2
- package/dist/adapters/claude.cjs +4 -3
- package/dist/adapters/codex.cjs +3 -2
- package/dist/adapters/conversation-process.cjs +2 -1
- package/dist/adapters/muse.cjs +2 -1
- package/dist/adapters/opencode.cjs +3 -2
- package/dist/adapters/pi.cjs +3 -2
- package/dist/adapters/qoder.cjs +2 -1
- package/dist/git-worktree.cjs +15 -8
- package/dist/github-credential.cjs +29 -1
- package/dist/live-transcript.cjs +22 -4
- package/dist/sandbox.cjs +3 -1
- package/dist/session.cjs +47 -28
- package/dist/upload-errors.cjs +30 -0
- package/dist/upload.cjs +34 -7
- package/package.json +1 -1
package/dist/adapters/acp.cjs
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.acpAdapter = void 0;
|
|
7
7
|
exports.runAcpAdapter = runAcpAdapter;
|
|
8
8
|
exports.probeAcpSteering = probeAcpSteering;
|
|
9
|
+
const github_credential_cjs_1 = require("../github-credential.cjs");
|
|
9
10
|
const node_child_process_1 = require("node:child_process");
|
|
10
11
|
const node_fs_1 = require("node:fs");
|
|
11
12
|
const node_os_1 = __importDefault(require("node:os"));
|
|
@@ -320,7 +321,7 @@ function resolveEnvReference(value, env) {
|
|
|
320
321
|
return resolved;
|
|
321
322
|
}
|
|
322
323
|
function spawnAcpAgent(options) {
|
|
323
|
-
const env =
|
|
324
|
+
const env = (0, github_credential_cjs_1.repositoryAgentEnv)(options.env);
|
|
324
325
|
if (!options.dockerExec) {
|
|
325
326
|
return (0, node_child_process_1.spawn)(options.bin, options.extraArgs, {
|
|
326
327
|
detached: process.platform !== "win32",
|
|
@@ -406,7 +407,7 @@ async function speaksAcpV1(context) {
|
|
|
406
407
|
// No session exists yet, so an agent that writes state at startup writes it
|
|
407
408
|
// in the temporary directory, not in the runtime's working directory.
|
|
408
409
|
cwd: node_os_1.default.tmpdir(),
|
|
409
|
-
env:
|
|
410
|
+
env: (0, github_credential_cjs_1.repositoryAgentEnv)(context.env),
|
|
410
411
|
stdio: ["pipe", "pipe", "ignore"],
|
|
411
412
|
});
|
|
412
413
|
const exited = new Promise((resolve) => {
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.antigravityAdapter = exports.ANTIGRAVITY_PROCESS_WRAPPER = void 0;
|
|
7
7
|
exports.runAntigravityAdapter = runAntigravityAdapter;
|
|
8
8
|
exports.normalizeAntigravityOutput = normalizeAntigravityOutput;
|
|
9
|
+
const github_credential_cjs_1 = require("../github-credential.cjs");
|
|
9
10
|
const node_child_process_1 = require("node:child_process");
|
|
10
11
|
const node_path_1 = __importDefault(require("node:path"));
|
|
11
12
|
const node_string_decoder_1 = require("node:string_decoder");
|
|
@@ -268,7 +269,7 @@ async function runProcess(options, args, input) {
|
|
|
268
269
|
return new Promise((resolve) => {
|
|
269
270
|
let stdout = "", stderr = "", timedOut = false, killedByLeaseLoss = false;
|
|
270
271
|
const stdoutDecoder = new node_string_decoder_1.StringDecoder("utf8"), stderrDecoder = new node_string_decoder_1.StringDecoder("utf8");
|
|
271
|
-
const child = (0, node_child_process_1.spawn)(options.bin, args, { cwd: options.cwd, detached: process.platform !== "win32", env: agentEnvironment(
|
|
272
|
+
const child = (0, node_child_process_1.spawn)(options.bin, args, { cwd: options.cwd, detached: process.platform !== "win32", env: agentEnvironment((0, github_credential_cjs_1.repositoryAgentEnv)(options.env)) });
|
|
272
273
|
child.stdin?.on("error", () => undefined);
|
|
273
274
|
child.stdin?.end(input);
|
|
274
275
|
options.onProcessStarted?.(child.pid);
|
|
@@ -328,7 +329,7 @@ async function runDocker(options, args, input) {
|
|
|
328
329
|
return failure("", { exitCode: null, timedOut, killedByLeaseLoss });
|
|
329
330
|
const command = `[ -f /tmp/session.env ] && . /tmp/session.env; cd ${quote(options.cwd)} && exec ${["node", "-e", exports.ANTIGRAVITY_PROCESS_WRAPPER, options.bin, ...args].map(quote).join(" ")}`;
|
|
330
331
|
const result = await runner.run("docker", ["exec", "-i", ...Object.keys(options.env).flatMap((name) => ["--env", name]), containerName, "sh", "-c", command], {
|
|
331
|
-
input, env: agentEnvironment(
|
|
332
|
+
input, env: agentEnvironment((0, github_credential_cjs_1.repositoryAgentEnv)(options.env)), signal: abort.signal,
|
|
332
333
|
onActivity: options.onActivity, onStdout: (chunk) => options.onOutput?.("stdout", chunk), onStderr: (chunk) => options.onOutput?.("stderr", chunk),
|
|
333
334
|
});
|
|
334
335
|
await killing;
|
package/dist/adapters/claude.cjs
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.claudeCodeAdapter = void 0;
|
|
4
4
|
exports.runClaudeCodeAdapter = runClaudeCodeAdapter;
|
|
5
5
|
exports.probeClaudeSteering = probeClaudeSteering;
|
|
6
|
+
const github_credential_cjs_1 = require("../github-credential.cjs");
|
|
6
7
|
const node_child_process_1 = require("node:child_process");
|
|
7
8
|
const node_crypto_1 = require("node:crypto");
|
|
8
9
|
const exit_conditions_cjs_1 = require("../exit-conditions.cjs");
|
|
@@ -307,7 +308,7 @@ async function runOnHost(options, args) {
|
|
|
307
308
|
const child = (0, node_child_process_1.spawn)(options.bin, args, {
|
|
308
309
|
detached: process.platform !== "win32",
|
|
309
310
|
cwd: options.cwd,
|
|
310
|
-
env:
|
|
311
|
+
env: (0, github_credential_cjs_1.repositoryAgentEnv)(options.env),
|
|
311
312
|
});
|
|
312
313
|
// `claude -p` reads the whole prompt from stdin and starts at EOF. A
|
|
313
314
|
// child that exits before reading surfaces through `close`; ignore the
|
|
@@ -401,7 +402,7 @@ async function runOnHostStreaming(options, args, live) {
|
|
|
401
402
|
const child = (0, node_child_process_1.spawn)(options.bin, args, {
|
|
402
403
|
detached: process.platform !== "win32",
|
|
403
404
|
cwd: options.cwd,
|
|
404
|
-
env:
|
|
405
|
+
env: (0, github_credential_cjs_1.repositoryAgentEnv)(options.env),
|
|
405
406
|
});
|
|
406
407
|
let attached = false;
|
|
407
408
|
const detach = () => {
|
|
@@ -646,7 +647,7 @@ function readClaudeHelp(bin, env) {
|
|
|
646
647
|
clearTimeout(timer);
|
|
647
648
|
resolve(text);
|
|
648
649
|
};
|
|
649
|
-
const child = (0, node_child_process_1.spawn)(bin, ["--help"], { env:
|
|
650
|
+
const child = (0, node_child_process_1.spawn)(bin, ["--help"], { env: (0, github_credential_cjs_1.repositoryAgentEnv)(env), stdio: ["ignore", "pipe", "ignore"] });
|
|
650
651
|
const timer = setTimeout(() => {
|
|
651
652
|
child.kill("SIGKILL");
|
|
652
653
|
done("");
|
package/dist/adapters/codex.cjs
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.codexAdapter = void 0;
|
|
4
4
|
exports.runCodexAdapter = runCodexAdapter;
|
|
5
5
|
exports.hasExplicitPermissionPolicy = hasExplicitPermissionPolicy;
|
|
6
|
+
const github_credential_cjs_1 = require("../github-credential.cjs");
|
|
6
7
|
const codex_conversation_cjs_1 = require("./codex-conversation.cjs");
|
|
7
8
|
const node_child_process_1 = require("node:child_process");
|
|
8
9
|
const node_fs_1 = require("node:fs");
|
|
@@ -269,7 +270,7 @@ async function runOnHost(options, args) {
|
|
|
269
270
|
const child = (0, node_child_process_1.spawn)(options.bin, args, {
|
|
270
271
|
detached: process.platform !== "win32",
|
|
271
272
|
cwd: options.cwd,
|
|
272
|
-
env:
|
|
273
|
+
env: (0, github_credential_cjs_1.repositoryAgentEnv)(options.env),
|
|
273
274
|
});
|
|
274
275
|
// `codex exec -` reads the whole prompt from stdin and starts at EOF, so
|
|
275
276
|
// end the pipe after writing it. A child that exits before reading
|
|
@@ -339,7 +340,7 @@ async function runViaDocker(options, args) {
|
|
|
339
340
|
onStdout: (chunk) => options.onOutput?.("stdout", chunk),
|
|
340
341
|
onStderr: (chunk) => options.onOutput?.("stderr", chunk),
|
|
341
342
|
signal: options.signal,
|
|
342
|
-
env:
|
|
343
|
+
env: (0, github_credential_cjs_1.repositoryAgentEnv)(options.env),
|
|
343
344
|
});
|
|
344
345
|
return {
|
|
345
346
|
exitCode: result.code,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.runConversationProcess = runConversationProcess;
|
|
4
|
+
const github_credential_cjs_1 = require("../github-credential.cjs");
|
|
4
5
|
const node_child_process_1 = require("node:child_process");
|
|
5
6
|
const node_perf_hooks_1 = require("node:perf_hooks");
|
|
6
7
|
const kill_agent_cjs_1 = require("../kill-agent.cjs");
|
|
@@ -35,7 +36,7 @@ async function runConversationProcess(options, args, makeParser) {
|
|
|
35
36
|
const child = (0, node_child_process_1.spawn)(options.bin, args, {
|
|
36
37
|
detached: process.platform !== "win32",
|
|
37
38
|
cwd: options.cwd,
|
|
38
|
-
env: options.env,
|
|
39
|
+
env: (0, github_credential_cjs_1.repositoryAgentEnv)(options.env, {}),
|
|
39
40
|
stdio: ["pipe", "pipe", "pipe"],
|
|
40
41
|
});
|
|
41
42
|
child.stdin?.on("error", () => undefined);
|
package/dist/adapters/muse.cjs
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.museAdapter = exports.MUSE_HOST_GUARD_MESSAGE = void 0;
|
|
7
7
|
exports.runMuseAdapter = runMuseAdapter;
|
|
8
8
|
exports.sumMuseSessionCost = sumMuseSessionCost;
|
|
9
|
+
const github_credential_cjs_1 = require("../github-credential.cjs");
|
|
9
10
|
const node_child_process_1 = require("node:child_process");
|
|
10
11
|
const node_fs_1 = require("node:fs");
|
|
11
12
|
const node_path_1 = __importDefault(require("node:path"));
|
|
@@ -461,7 +462,7 @@ async function readMcpServers(configPath, env) {
|
|
|
461
462
|
return result;
|
|
462
463
|
}
|
|
463
464
|
function spawnMuse(options) {
|
|
464
|
-
const env =
|
|
465
|
+
const env = (0, github_credential_cjs_1.repositoryAgentEnv)(options.env);
|
|
465
466
|
delete env.MUSE_PERMISSION_PROFILE_FAIL_OPEN;
|
|
466
467
|
const args = ["serve", ...options.extraArgs];
|
|
467
468
|
if (!options.dockerExec)
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.openCodeAdapter = void 0;
|
|
7
7
|
exports.runOpenCodeAdapter = runOpenCodeAdapter;
|
|
8
8
|
exports.resetOpenCodeLogLevelCache = resetOpenCodeLogLevelCache;
|
|
9
|
+
const github_credential_cjs_1 = require("../github-credential.cjs");
|
|
9
10
|
const node_child_process_1 = require("node:child_process");
|
|
10
11
|
const node_fs_1 = require("node:fs");
|
|
11
12
|
const node_os_1 = __importDefault(require("node:os"));
|
|
@@ -423,7 +424,7 @@ async function runOnHost(options, args, input = "") {
|
|
|
423
424
|
const child = (0, node_child_process_1.spawn)(options.bin, args, {
|
|
424
425
|
detached: process.platform !== "win32",
|
|
425
426
|
cwd: options.cwd,
|
|
426
|
-
env:
|
|
427
|
+
env: (0, github_credential_cjs_1.repositoryAgentEnv)(options.env),
|
|
427
428
|
});
|
|
428
429
|
let capacityError;
|
|
429
430
|
const monitor = capacityMonitor((detail) => {
|
|
@@ -505,7 +506,7 @@ async function runViaDocker(options, args, input) {
|
|
|
505
506
|
signal: controller.signal,
|
|
506
507
|
onStdout: (chunk) => { streamed.stdout = true; monitor.push("stdout", chunk); options.onOutput?.("stdout", chunk); },
|
|
507
508
|
onStderr: (chunk) => { streamed.stderr = true; monitor.push("stderr", chunk); options.onOutput?.("stderr", chunk); },
|
|
508
|
-
env:
|
|
509
|
+
env: (0, github_credential_cjs_1.repositoryAgentEnv)(options.env),
|
|
509
510
|
});
|
|
510
511
|
// Also inspect runners that only return buffered output.
|
|
511
512
|
if (!streamed.stdout)
|
package/dist/adapters/pi.cjs
CHANGED
|
@@ -11,6 +11,7 @@ exports.parsePiJsonEvents = parsePiJsonEvents;
|
|
|
11
11
|
exports.attachPiOutput = attachPiOutput;
|
|
12
12
|
exports.runPiAdapter = runPiAdapter;
|
|
13
13
|
exports.runOnHost = runOnHost;
|
|
14
|
+
const github_credential_cjs_1 = require("../github-credential.cjs");
|
|
14
15
|
const node_child_process_1 = require("node:child_process");
|
|
15
16
|
const node_fs_1 = require("node:fs");
|
|
16
17
|
const node_os_1 = __importDefault(require("node:os"));
|
|
@@ -326,7 +327,7 @@ async function runOnHost(options, args, local = false) {
|
|
|
326
327
|
const child = (0, node_child_process_1.spawn)(options.bin, boundedArgs, {
|
|
327
328
|
detached: process.platform !== "win32",
|
|
328
329
|
cwd: options.cwd,
|
|
329
|
-
env:
|
|
330
|
+
env: (0, github_credential_cjs_1.repositoryAgentEnv)(env),
|
|
330
331
|
});
|
|
331
332
|
// Ignore EPIPE from a child that exits before reading; `close` reports it.
|
|
332
333
|
child.stdin?.on("error", () => undefined);
|
|
@@ -416,7 +417,7 @@ async function runViaDocker(options, args) {
|
|
|
416
417
|
onStdout: (chunk) => options.onOutput?.("stdout", chunk),
|
|
417
418
|
onStderr: (chunk) => options.onOutput?.("stderr", chunk),
|
|
418
419
|
signal: options.signal,
|
|
419
|
-
env:
|
|
420
|
+
env: (0, github_credential_cjs_1.repositoryAgentEnv)(options.env),
|
|
420
421
|
});
|
|
421
422
|
return {
|
|
422
423
|
exitCode: result.code,
|
package/dist/adapters/qoder.cjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.qoderAdapter = void 0;
|
|
4
4
|
exports.runQoderAdapter = runQoderAdapter;
|
|
5
|
+
const github_credential_cjs_1 = require("../github-credential.cjs");
|
|
5
6
|
const node_child_process_1 = require("node:child_process");
|
|
6
7
|
const exit_conditions_cjs_1 = require("../exit-conditions.cjs");
|
|
7
8
|
const kill_agent_cjs_1 = require("../kill-agent.cjs");
|
|
@@ -83,7 +84,7 @@ async function runOnHost(options, args) {
|
|
|
83
84
|
const child = (0, node_child_process_1.spawn)(options.bin, args, {
|
|
84
85
|
detached: process.platform !== "win32",
|
|
85
86
|
cwd: options.cwd,
|
|
86
|
-
env:
|
|
87
|
+
env: (0, github_credential_cjs_1.repositoryAgentEnv)(options.env),
|
|
87
88
|
});
|
|
88
89
|
// `qoder -p` reads the whole prompt from stdin and starts at EOF. A child
|
|
89
90
|
// that exits before reading surfaces through `close`; ignore the EPIPE.
|
package/dist/git-worktree.cjs
CHANGED
|
@@ -7,6 +7,7 @@ exports.GitWorktree = void 0;
|
|
|
7
7
|
exports.proxyCloneUrl = proxyCloneUrl;
|
|
8
8
|
exports.branchSlug = branchSlug;
|
|
9
9
|
exports.hostedCheckpointRef = hostedCheckpointRef;
|
|
10
|
+
const github_credential_cjs_1 = require("./github-credential.cjs");
|
|
10
11
|
const node_path_1 = __importDefault(require("node:path"));
|
|
11
12
|
const abort_cjs_1 = require("./abort.cjs");
|
|
12
13
|
const worktree_janitor_cjs_1 = require("./worktree-janitor.cjs");
|
|
@@ -61,6 +62,7 @@ class GitWorktree {
|
|
|
61
62
|
seedRepositoryPath;
|
|
62
63
|
cloneUrl;
|
|
63
64
|
githubToken;
|
|
65
|
+
credentialUsername;
|
|
64
66
|
githubTokenProvider;
|
|
65
67
|
repoLocalTokenInstalled = false;
|
|
66
68
|
gitGrant;
|
|
@@ -118,14 +120,15 @@ class GitWorktree {
|
|
|
118
120
|
this.runner = options.runner ?? sandbox_cjs_1.nodeCommandRunner;
|
|
119
121
|
this.authRetryDelaysMs = options.authRetryDelaysMs ?? DEFAULT_AUTH_RETRY_DELAYS_MS;
|
|
120
122
|
this.sleep = options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
121
|
-
this.
|
|
122
|
-
this.
|
|
123
|
-
|
|
123
|
+
this.credentialUsername = options.credentialUsername;
|
|
124
|
+
this.gitGrant = options.credentialUsername !== undefined ? undefined : options.gitGrant;
|
|
125
|
+
this.cloneUrl = this.gitGrant
|
|
126
|
+
? proxyCloneUrl(options.cloneUrl, this.gitGrant.proxyBaseUrl)
|
|
124
127
|
: options.cloneUrl;
|
|
125
|
-
this.githubToken =
|
|
126
|
-
this.githubTokenProvider =
|
|
128
|
+
this.githubToken = this.gitGrant ? undefined : options.githubToken;
|
|
129
|
+
this.githubTokenProvider = this.gitGrant ? undefined : options.githubTokenProvider;
|
|
127
130
|
this.workingBranch = options.workingBranch?.trim() || null;
|
|
128
|
-
this.repoLocalGithubToken = options.repoLocalGithubToken;
|
|
131
|
+
this.repoLocalGithubToken = options.credentialUsername !== undefined ? undefined : options.repoLocalGithubToken;
|
|
129
132
|
this.prContinuation = options.prContinuation ?? false;
|
|
130
133
|
this.ownershipCommitIdentity = options.ownershipCommitIdentity ?? { name: "Navarch", email: "runtime@navarch.local" };
|
|
131
134
|
this.hostedCheckpointRef = options.restoreHostedCheckpoint ? hostedCheckpointRef(options.taskId) : null;
|
|
@@ -896,13 +899,17 @@ class GitWorktree {
|
|
|
896
899
|
"-c",
|
|
897
900
|
"credential.helper=",
|
|
898
901
|
"-c",
|
|
899
|
-
|
|
902
|
+
this.credentialUsername !== undefined
|
|
903
|
+
? `credential.helper=${github_credential_cjs_1.REPOSITORY_CREDENTIAL_HELPER}`
|
|
904
|
+
: 'credential.helper=!f() { echo username=x-access-token; echo "password=$GITHUB_TOKEN"; }; f',
|
|
900
905
|
]
|
|
901
906
|
: [];
|
|
902
907
|
const result = await this.runner.run("git", [...credentialArgs, ...args], {
|
|
903
908
|
...options,
|
|
904
909
|
env: githubToken
|
|
905
|
-
?
|
|
910
|
+
? this.credentialUsername !== undefined
|
|
911
|
+
? { ...gitEnvWithoutGithubTokens(), ...(0, github_credential_cjs_1.repositoryCredentialEnv)(this.credentialUsername, githubToken), GIT_TERMINAL_PROMPT: "0" }
|
|
912
|
+
: { ...process.env, GITHUB_TOKEN: githubToken, GIT_TERMINAL_PROMPT: "0" }
|
|
906
913
|
: { ...process.env, GIT_TERMINAL_PROMPT: "0" },
|
|
907
914
|
});
|
|
908
915
|
if (result.code !== 0) {
|
|
@@ -3,8 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.GithubTokenFileRefresher = exports.GITHUB_TOKEN_FILENAME = exports.GITHUB_TOKEN_FILE_RETRY_MS = exports.GITHUB_TOKEN_FILE_REFRESH_MS = exports.GITHUB_CREDENTIAL_SECRET_NAME = void 0;
|
|
6
|
+
exports.REPOSITORY_CREDENTIAL_HELPER = exports.GithubTokenFileRefresher = exports.GITHUB_TOKEN_FILENAME = exports.GITHUB_TOKEN_FILE_RETRY_MS = exports.GITHUB_TOKEN_FILE_REFRESH_MS = exports.GITHUB_CREDENTIAL_SECRET_NAME = void 0;
|
|
7
7
|
exports.githubCredentialDenialSummary = githubCredentialDenialSummary;
|
|
8
|
+
exports.repositoryCloneUrl = repositoryCloneUrl;
|
|
9
|
+
exports.repositoryCredentialEnv = repositoryCredentialEnv;
|
|
10
|
+
exports.repositoryAgentEnv = repositoryAgentEnv;
|
|
8
11
|
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
9
12
|
const node_path_1 = __importDefault(require("node:path"));
|
|
10
13
|
const git_grant_cjs_1 = require("./git-grant.cjs");
|
|
@@ -139,3 +142,28 @@ class GithubTokenFileRefresher {
|
|
|
139
142
|
}
|
|
140
143
|
}
|
|
141
144
|
exports.GithubTokenFileRefresher = GithubTokenFileRefresher;
|
|
145
|
+
/** Resolve the repository URL without a GitHub fallback for Codeup leases. */
|
|
146
|
+
function repositoryCloneUrl(repository, repo) {
|
|
147
|
+
if (repository?.credential_username !== undefined && !repository.clone_url) {
|
|
148
|
+
throw new Error("codeup_clone_url_missing: repository.clone_url is required");
|
|
149
|
+
}
|
|
150
|
+
return repository?.clone_url ?? (repo ? `https://github.com/${repo.replace(/\.git$/, "")}.git` : null);
|
|
151
|
+
}
|
|
152
|
+
/** Codeup credentials use dedicated env names, never GitHub token aliases. */
|
|
153
|
+
exports.REPOSITORY_CREDENTIAL_HELPER = '!f() { printf "%s\\n" "username=$NAVARCH_GIT_CREDENTIAL_USERNAME" "password=$NAVARCH_GIT_CREDENTIAL_TOKEN"; }; f';
|
|
154
|
+
function repositoryCredentialEnv(username, token) {
|
|
155
|
+
if (!username || /[\r\n\0]/.test(username))
|
|
156
|
+
throw new Error("invalid_repository_credential_username");
|
|
157
|
+
if (/[\r\n\0]/.test(token))
|
|
158
|
+
throw new Error("invalid_repository_credential_token");
|
|
159
|
+
return { NAVARCH_GIT_CREDENTIAL_USERNAME: username, NAVARCH_GIT_CREDENTIAL_TOKEN: token };
|
|
160
|
+
}
|
|
161
|
+
/** Merge per-session auth without inheriting GitHub credentials for Codeup. */
|
|
162
|
+
function repositoryAgentEnv(overrides, parent = process.env) {
|
|
163
|
+
const env = { ...parent, ...overrides };
|
|
164
|
+
if (overrides.NAVARCH_GIT_CREDENTIAL_USERNAME !== undefined) {
|
|
165
|
+
delete env.GH_TOKEN;
|
|
166
|
+
delete env.GITHUB_TOKEN;
|
|
167
|
+
}
|
|
168
|
+
return env;
|
|
169
|
+
}
|
package/dist/live-transcript.cjs
CHANGED
|
@@ -4,6 +4,7 @@ exports.LiveTranscriptPublisher = void 0;
|
|
|
4
4
|
exports.renderSessionTranscript = renderSessionTranscript;
|
|
5
5
|
exports.renderLiveTranscript = renderLiveTranscript;
|
|
6
6
|
exports.liveUploadIntervalMs = liveUploadIntervalMs;
|
|
7
|
+
const upload_errors_cjs_1 = require("./upload-errors.cjs");
|
|
7
8
|
/** The shape both the live snapshots and the completion upload use. */
|
|
8
9
|
function renderSessionTranscript(attempts, redact) {
|
|
9
10
|
return attempts
|
|
@@ -46,6 +47,8 @@ function renderLiveTranscript(attempts, currentStdout, redact, knownSecrets = []
|
|
|
46
47
|
/** Signed upload URLs last an hour; refresh well before that. */
|
|
47
48
|
const UPLOAD_URL_TTL_MS = 45 * 60_000;
|
|
48
49
|
const DEFAULT_INTERVAL_MS = 10_000;
|
|
50
|
+
/** Longest wait between retries while storage keeps failing. */
|
|
51
|
+
const MAX_FAILURE_BACKOFF_MS = 5 * 60_000;
|
|
49
52
|
function liveUploadIntervalMs(bytes, baseMs = DEFAULT_INTERVAL_MS) {
|
|
50
53
|
if (bytes > 8 * 1024 * 1024)
|
|
51
54
|
return Math.max(baseMs, 60_000);
|
|
@@ -66,6 +69,7 @@ class LiveTranscriptPublisher {
|
|
|
66
69
|
lastUploaded = "";
|
|
67
70
|
uploadUrl = null;
|
|
68
71
|
published = null;
|
|
72
|
+
failures = 0;
|
|
69
73
|
constructor(options) {
|
|
70
74
|
this.options = options;
|
|
71
75
|
this.now = options.now ?? Date.now;
|
|
@@ -100,7 +104,12 @@ class LiveTranscriptPublisher {
|
|
|
100
104
|
schedule() {
|
|
101
105
|
if (this.timer || this.inFlight || this.stopped || this.paused)
|
|
102
106
|
return;
|
|
103
|
-
const
|
|
107
|
+
const base = liveUploadIntervalMs(this.lastUploaded.length, this.intervalMs);
|
|
108
|
+
// While storage keeps failing, double the wait per failure instead of
|
|
109
|
+
// re-sending a multi-megabyte snapshot into an outage every interval.
|
|
110
|
+
const gap = this.failures
|
|
111
|
+
? Math.max(base, Math.min(base * 2 ** this.failures, MAX_FAILURE_BACKOFF_MS))
|
|
112
|
+
: base;
|
|
104
113
|
const wait = Math.max(0, this.lastUploadedAt + gap - this.now());
|
|
105
114
|
this.timer = setTimeout(() => {
|
|
106
115
|
this.timer = null;
|
|
@@ -129,11 +138,20 @@ class LiveTranscriptPublisher {
|
|
|
129
138
|
await this.options.upload(this.uploadUrl.url, content);
|
|
130
139
|
this.lastUploaded = content;
|
|
131
140
|
this.published = this.uploadUrl.publicUrl;
|
|
141
|
+
if (this.failures)
|
|
142
|
+
this.options.onRecover?.(this.failures);
|
|
143
|
+
this.failures = 0;
|
|
132
144
|
}
|
|
133
145
|
catch (error) {
|
|
134
|
-
// A
|
|
135
|
-
|
|
136
|
-
|
|
146
|
+
// A storage outage says nothing about the signature, so keep the URL;
|
|
147
|
+
// anything else (an expired or rejected signature) gets a fresh one.
|
|
148
|
+
if (!(0, upload_errors_cjs_1.isTransientUploadError)(error))
|
|
149
|
+
this.uploadUrl = null;
|
|
150
|
+
this.failures += 1;
|
|
151
|
+
this.options.onError?.(error, this.failures);
|
|
152
|
+
// Retry the unsent snapshot even if the agent goes quiet.
|
|
153
|
+
if (!this.paused && !this.stopped)
|
|
154
|
+
this.dirty = true;
|
|
137
155
|
}
|
|
138
156
|
finally {
|
|
139
157
|
this.lastUploadedAt = this.now();
|
package/dist/sandbox.cjs
CHANGED
|
@@ -216,7 +216,9 @@ class DockerSandbox {
|
|
|
216
216
|
* running anything that needs the values.
|
|
217
217
|
*/
|
|
218
218
|
async injectEnv(env) {
|
|
219
|
-
const
|
|
219
|
+
const codeup = env.NAVARCH_GIT_CREDENTIAL_USERNAME !== undefined;
|
|
220
|
+
const lines = (codeup ? "unset GH_TOKEN GITHUB_TOKEN\n" : "") + Object.entries(env)
|
|
221
|
+
.filter(([name]) => !codeup || (name !== "GH_TOKEN" && name !== "GITHUB_TOKEN"))
|
|
220
222
|
.map(([k, v]) => `export ${k}=${shellQuote(v)}`)
|
|
221
223
|
.join("\n");
|
|
222
224
|
const result = await this.runner.run("docker", ["exec", "-i", this.name, "sh", "-c", "cat > /tmp/session.env"], { input: lines });
|
package/dist/session.cjs
CHANGED
|
@@ -64,6 +64,9 @@ const DELIVERY_CORRECTION_RETRIES = 1;
|
|
|
64
64
|
*/
|
|
65
65
|
const STEERING_COMPLETION_RESENDS = 3;
|
|
66
66
|
const STEERING_COMPLETION_RESEND_DELAY_MS = 1_000;
|
|
67
|
+
/** Final transcript PUT: 1 s, 2 s, 4 s between attempts rides out a short
|
|
68
|
+
* R2 blip without holding completion for long. */
|
|
69
|
+
const COMPLETION_UPLOAD_RETRY = { attempts: 4, baseDelayMs: 1_000 };
|
|
67
70
|
/**
|
|
68
71
|
* How long an agent process may run before the messages in its prompt count as
|
|
69
72
|
* delivered, when it has printed nothing yet. A launch that fails does so
|
|
@@ -125,7 +128,7 @@ async function runSession(deps, claimed, sessionId) {
|
|
|
125
128
|
// explicit pre-start signal. Otherwise it waits for expiry and bypasses
|
|
126
129
|
// the repeat/backoff policy entirely.
|
|
127
130
|
const { api, config } = deps;
|
|
128
|
-
const { lease_id: leaseId
|
|
131
|
+
const { lease_id: leaseId } = claimed;
|
|
129
132
|
const runtime = claimed.runtime ?? config.agentType;
|
|
130
133
|
const execution = resolveSessionExecution(config, claimed);
|
|
131
134
|
const crashDetail = describeCompletionError(err).slice(0, 1800);
|
|
@@ -192,6 +195,9 @@ async function runClaimedSession(deps, claimed, sessionId, lifecycle) {
|
|
|
192
195
|
// otherwise the grant endpoint decides (409 git_proxy_disabled = mode off).
|
|
193
196
|
// The runtime parent fetches and refreshes the grant; the agent never sees
|
|
194
197
|
// the machine token or a GitHub token in these modes.
|
|
198
|
+
const credentialUsername = bundle.repository?.credential_username;
|
|
199
|
+
const codeup = credentialUsername !== undefined;
|
|
200
|
+
const cloneUrl = (0, github_credential_cjs_1.repositoryCloneUrl)(bundle.repository, task.repo);
|
|
195
201
|
const bundleGitMode = bundle.repository?.git_proxy_mode;
|
|
196
202
|
// Codex's worktree guard is an OS sandbox around the whole agent, git's
|
|
197
203
|
// credential helper included: it denies the session dir and allows only
|
|
@@ -202,7 +208,7 @@ async function runClaimedSession(deps, claimed, sessionId, lifecycle) {
|
|
|
202
208
|
const credentialConsumer = {};
|
|
203
209
|
let gitGrantRefresher;
|
|
204
210
|
let gitGrantEnv;
|
|
205
|
-
if (bundleGitMode !== "off") {
|
|
211
|
+
if (!codeup && bundleGitMode !== "off") {
|
|
206
212
|
const grantPaths = (0, git_grant_cjs_1.gitGrantPaths)(workDir);
|
|
207
213
|
const refresher = new git_grant_cjs_1.GitGrantRefresher({
|
|
208
214
|
api,
|
|
@@ -272,7 +278,7 @@ async function runClaimedSession(deps, claimed, sessionId, lifecycle) {
|
|
|
272
278
|
}
|
|
273
279
|
}
|
|
274
280
|
let gitCredentialRefresh;
|
|
275
|
-
if (!gitGrantMode && managedGithubCredential && secrets["github-pat"]) {
|
|
281
|
+
if (!codeup && !gitGrantMode && managedGithubCredential && secrets["github-pat"]) {
|
|
276
282
|
await node_fs_1.promises.mkdir(gitCredentialDir, { recursive: true, mode: 0o700 });
|
|
277
283
|
const helperPath = node_path_1.default.join(gitCredentialDir, GIT_CREDENTIAL_HELPER_FILENAME);
|
|
278
284
|
await node_fs_1.promises.copyFile(node_path_1.default.resolve(__dirname, "../bin/git-credential-navarch.cjs"), helperPath);
|
|
@@ -286,7 +292,7 @@ async function runClaimedSession(deps, claimed, sessionId, lifecycle) {
|
|
|
286
292
|
await githubTokenRefresher.start(secrets["github-pat"]);
|
|
287
293
|
gitCredentialRefresh = { helperPath, tokenFile };
|
|
288
294
|
}
|
|
289
|
-
const sessionEnv = toEnvMap(secrets, gitCredentialRefresh, config.gitAuthorName, config.gitAuthorEmail, gitGrantEnv);
|
|
295
|
+
const sessionEnv = toEnvMap(secrets, gitCredentialRefresh, config.gitAuthorName, config.gitAuthorEmail, gitGrantEnv, codeup ? { username: credentialUsername, secretName: bundle.repository.credential_secret_name } : undefined);
|
|
290
296
|
// Proxied projects (CX-3.7): the control-plane identity replaces the
|
|
291
297
|
// NAVARCH_GIT_AUTHOR_* default for this session; mode `off` sends none.
|
|
292
298
|
const commitIdentity = (0, commit_attribution_cjs_1.parseCommitIdentity)(bundle.repository?.commit_identity);
|
|
@@ -310,8 +316,6 @@ async function runClaimedSession(deps, claimed, sessionId, lifecycle) {
|
|
|
310
316
|
sessionEnv.GITHUB_TOKEN = "";
|
|
311
317
|
sessionEnv.GH_TOKEN = "";
|
|
312
318
|
}
|
|
313
|
-
const cloneUrl = bundle.repository?.clone_url ??
|
|
314
|
-
(task.repo ? `https://github.com/${task.repo.replace(/\.git$/, "")}.git` : null);
|
|
315
319
|
if (!cloneUrl) {
|
|
316
320
|
const failureSummary = `Project ${task.project_id} has no GitHub repository URL. Set it in Project settings before dispatching work.`;
|
|
317
321
|
await api.completeLease(leaseId, {
|
|
@@ -357,12 +361,13 @@ async function runClaimedSession(deps, claimed, sessionId, lifecycle) {
|
|
|
357
361
|
} } : {}),
|
|
358
362
|
cloneUrl,
|
|
359
363
|
githubToken,
|
|
364
|
+
credentialUsername,
|
|
360
365
|
githubTokenProvider: githubTokenRefresher ? () => githubTokenRefresher.current : undefined,
|
|
361
366
|
workingBranch: bundle.repository?.working_branch,
|
|
362
367
|
deliveryBinding,
|
|
363
368
|
// Grant modes never expose a GitHub token, so the Codex repo-local
|
|
364
369
|
// github-pat bootstrap is not installed.
|
|
365
|
-
repoLocalGithubToken: gitGrantMode ? undefined : secrets["github-pat"],
|
|
370
|
+
repoLocalGithubToken: codeup || gitGrantMode ? undefined : secrets["github-pat"],
|
|
366
371
|
gitGrant: gitGrantEnv
|
|
367
372
|
? {
|
|
368
373
|
proxyBaseUrl: gitGrantEnv.proxyBaseUrl,
|
|
@@ -390,7 +395,7 @@ async function runClaimedSession(deps, claimed, sessionId, lifecycle) {
|
|
|
390
395
|
if (!sha || !/^[a-f0-9]{40}$/i.test(sha))
|
|
391
396
|
throw new Error("Invalid QA run commit");
|
|
392
397
|
for (const args of [["fetch", "origin", sha], ["checkout", "--detach", sha]]) {
|
|
393
|
-
const result = await sandbox_cjs_1.nodeCommandRunner.run("git", args, { cwd: gitWorktree.worktreePath, env:
|
|
398
|
+
const result = await sandbox_cjs_1.nodeCommandRunner.run("git", args, { cwd: gitWorktree.worktreePath, env: (0, github_credential_cjs_1.repositoryAgentEnv)(sessionEnv), signal });
|
|
394
399
|
if (result.code !== 0)
|
|
395
400
|
throw new Error("QA run commit checkout failed");
|
|
396
401
|
}
|
|
@@ -628,7 +633,7 @@ async function runClaimedSession(deps, claimed, sessionId, lifecycle) {
|
|
|
628
633
|
if (issued.length > 0) {
|
|
629
634
|
const merged = (0, user_mcp_servers_cjs_1.mergeUserMcpServers)(sessionMcpConfig, issued, {
|
|
630
635
|
runtime,
|
|
631
|
-
existingEnv:
|
|
636
|
+
existingEnv: (0, github_credential_cjs_1.repositoryAgentEnv)(sessionEnv),
|
|
632
637
|
envReferenced: runtime === "opencode",
|
|
633
638
|
});
|
|
634
639
|
registry.registerAll(merged.secretValues);
|
|
@@ -830,7 +835,7 @@ async function runClaimedSession(deps, claimed, sessionId, lifecycle) {
|
|
|
830
835
|
gitCredentialDir,
|
|
831
836
|
...(gitGrantEnv ? [(0, git_grant_cjs_1.gitGrantPaths)(workDir).dir] : []),
|
|
832
837
|
],
|
|
833
|
-
networkHosts: gitGrantEnv ? [gitGrantEnv.proxyHost] : [],
|
|
838
|
+
networkHosts: codeup ? [new URL(cloneUrl).hostname] : gitGrantEnv ? [gitGrantEnv.proxyHost] : [],
|
|
834
839
|
});
|
|
835
840
|
}
|
|
836
841
|
const restoredCheckpoint = gitWorktree.restoredHostedCheckpoint;
|
|
@@ -928,7 +933,10 @@ async function runClaimedSession(deps, claimed, sessionId, lifecycle) {
|
|
|
928
933
|
},
|
|
929
934
|
upload: upload_cjs_1.uploadTranscript,
|
|
930
935
|
render: () => (0, live_transcript_cjs_1.renderLiveTranscript)(attempts, liveStdout, (text) => (0, redact_cjs_1.redactText)(text, registry.list()), registry.list()),
|
|
931
|
-
onError: (error) => log.warn(`live transcript upload failed for ${leaseId}
|
|
936
|
+
onError: (error, failures) => log.warn(`live transcript upload failed for ${leaseId}` +
|
|
937
|
+
`${failures > 1 ? ` (${failures} in a row; retrying with backoff)` : ""}: ` +
|
|
938
|
+
(0, redact_cjs_1.redactText)(String(error), registry.list())),
|
|
939
|
+
onRecover: (failures) => log.info(`live transcript upload for ${leaseId} recovered after ${failures} failed attempt(s)`),
|
|
932
940
|
});
|
|
933
941
|
const agentBudgetStartedAt = node_perf_hooks_1.performance.now();
|
|
934
942
|
const maxRuntimeMs = task.max_runtime_ms ?? config.sessionTimeoutMs;
|
|
@@ -1263,20 +1271,21 @@ async function runClaimedSession(deps, claimed, sessionId, lifecycle) {
|
|
|
1263
1271
|
log.warn(`worktree HEAD lookup failed for ${leaseId}: ${String(err)}`);
|
|
1264
1272
|
}
|
|
1265
1273
|
let pullRequestUrl = null;
|
|
1266
|
-
let pullRequestLookupFailed =
|
|
1274
|
+
let pullRequestLookupFailed = codeup;
|
|
1267
1275
|
try {
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1276
|
+
if (!codeup)
|
|
1277
|
+
pullRequestUrl = await (0, github_pr_cjs_1.findHeadBranchPullRequestUrl)({
|
|
1278
|
+
repository: bundle.repository?.full_name ?? task.repo,
|
|
1279
|
+
headBranch,
|
|
1280
|
+
headSha,
|
|
1281
|
+
// Keep SHA verification on the exact branch, but do not adopt a
|
|
1282
|
+
// foreign-branch PR as delivery evidence for a root task.
|
|
1283
|
+
allowShaFallback: allowBranchRename,
|
|
1284
|
+
githubToken: gitGrantMode ? gitGrantRefresher?.current?.grant : githubTokenRefresher?.current ?? githubToken,
|
|
1285
|
+
// Grant modes read through the proxy and never use the host's own gh login.
|
|
1286
|
+
apiBaseUrl: gitGrantEnv ? `${gitGrantEnv.proxyBaseUrl.replace(/\/+$/, "")}/api/v3` : undefined,
|
|
1287
|
+
hostTokenProvider: gitGrantMode ? async () => undefined : undefined,
|
|
1288
|
+
});
|
|
1280
1289
|
if (pullRequestUrl)
|
|
1281
1290
|
mapping.evidenceUrls.push(pullRequestUrl);
|
|
1282
1291
|
}
|
|
@@ -1376,7 +1385,9 @@ async function runClaimedSession(deps, claimed, sessionId, lifecycle) {
|
|
|
1376
1385
|
let transcriptUrl;
|
|
1377
1386
|
try {
|
|
1378
1387
|
const { upload_url, public_url } = await api.getTranscriptUploadUrl(leaseId);
|
|
1379
|
-
|
|
1388
|
+
// The final transcript is the one the task view keeps, so ride out a
|
|
1389
|
+
// short storage blip (R2 InternalError 500s) instead of dropping it.
|
|
1390
|
+
await (0, upload_cjs_1.uploadTranscript)(upload_url, transcript, fetch, COMPLETION_UPLOAD_RETRY);
|
|
1380
1391
|
transcriptUrl = public_url;
|
|
1381
1392
|
}
|
|
1382
1393
|
catch (err) {
|
|
@@ -1784,7 +1795,7 @@ function gitGrantCredentialHelper(config) {
|
|
|
1784
1795
|
/** Secret names (lowercased, non-alphanumerics as `_`) that are raw GitHub credentials. */
|
|
1785
1796
|
const GITHUB_CREDENTIAL_SECRETS = new Set(["github_pat", "github_token", "gh_token"]);
|
|
1786
1797
|
/** Uppercases + sanitizes secret names into shell-safe env var names for injectEnv(). */
|
|
1787
|
-
function toEnvMap(secrets, credentialRefreshOrAuthorName, gitAuthorNameOrEmail = "sagentlab", gitAuthorEmail = "z@sagentlab.com", gitGrant) {
|
|
1798
|
+
function toEnvMap(secrets, credentialRefreshOrAuthorName, gitAuthorNameOrEmail = "sagentlab", gitAuthorEmail = "z@sagentlab.com", gitGrant, repositoryCredential) {
|
|
1788
1799
|
// Keep the existing `(secrets, authorName, authorEmail)` call shape while
|
|
1789
1800
|
// accepting a refresh config before the author identity for managed repos.
|
|
1790
1801
|
const gitCredentialRefresh = typeof credentialRefreshOrAuthorName === "string"
|
|
@@ -1798,7 +1809,7 @@ function toEnvMap(secrets, credentialRefreshOrAuthorName, gitAuthorNameOrEmail =
|
|
|
1798
1809
|
: gitAuthorEmail;
|
|
1799
1810
|
const out = {};
|
|
1800
1811
|
for (const [name, value] of Object.entries(secrets)) {
|
|
1801
|
-
if (gitGrant && GITHUB_CREDENTIAL_SECRETS.has(name.toLowerCase().replace(/[^a-z0-9]/g, "_")))
|
|
1812
|
+
if ((gitGrant || repositoryCredential) && GITHUB_CREDENTIAL_SECRETS.has(name.toLowerCase().replace(/[^a-z0-9]/g, "_")))
|
|
1802
1813
|
continue;
|
|
1803
1814
|
out[name.toUpperCase().replace(/[^A-Z0-9_]/g, "_")] = value;
|
|
1804
1815
|
}
|
|
@@ -1827,7 +1838,15 @@ function toEnvMap(secrets, credentialRefreshOrAuthorName, gitAuthorNameOrEmail =
|
|
|
1827
1838
|
["user.name", gitAuthorName],
|
|
1828
1839
|
["user.email", resolvedGitAuthorEmail],
|
|
1829
1840
|
];
|
|
1830
|
-
if (
|
|
1841
|
+
if (repositoryCredential) {
|
|
1842
|
+
const token = secrets[repositoryCredential.secretName];
|
|
1843
|
+
if (!token)
|
|
1844
|
+
throw new Error("repository_credential_missing");
|
|
1845
|
+
Object.assign(out, (0, github_credential_cjs_1.repositoryCredentialEnv)(repositoryCredential.username, token));
|
|
1846
|
+
out.GIT_TERMINAL_PROMPT = "0";
|
|
1847
|
+
gitConfig.unshift(["credential.helper", ""], ["credential.helper", github_credential_cjs_1.REPOSITORY_CREDENTIAL_HELPER]);
|
|
1848
|
+
}
|
|
1849
|
+
if (!repositoryCredential && secrets["github-pat"] && (!out.GITHUB_TOKEN || (gitCredentialRefresh && "tokenFile" in gitCredentialRefresh))) {
|
|
1831
1850
|
out.GITHUB_TOKEN = secrets["github-pat"];
|
|
1832
1851
|
if (gitCredentialRefresh) {
|
|
1833
1852
|
if ("tokenFile" in gitCredentialRefresh) {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Transcript upload failure classification, kept apart from upload.cts so
|
|
4
|
+
* modules that only classify failures (live-transcript.cts) do not depend on
|
|
5
|
+
* the upload implementation that tests replace wholesale.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.TranscriptUploadError = void 0;
|
|
9
|
+
exports.isTransientUploadError = isTransientUploadError;
|
|
10
|
+
/** A failed transcript PUT. `status` is null when no response arrived. */
|
|
11
|
+
class TranscriptUploadError extends Error {
|
|
12
|
+
status;
|
|
13
|
+
constructor(message, status) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.status = status;
|
|
16
|
+
this.name = "TranscriptUploadError";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.TranscriptUploadError = TranscriptUploadError;
|
|
20
|
+
/**
|
|
21
|
+
* Storage-side failures (R2 `InternalError` 500s, 503s, throttling, a dropped
|
|
22
|
+
* connection) say nothing about the signed URL, so the same URL is worth
|
|
23
|
+
* retrying. Any other failure, such as a 403 for an expired signature, needs a
|
|
24
|
+
* fresh URL.
|
|
25
|
+
*/
|
|
26
|
+
function isTransientUploadError(error) {
|
|
27
|
+
if (!(error instanceof TranscriptUploadError))
|
|
28
|
+
return false;
|
|
29
|
+
return error.status === null || error.status === 429 || error.status >= 500;
|
|
30
|
+
}
|
package/dist/upload.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isTransientUploadError = exports.TranscriptUploadError = void 0;
|
|
3
4
|
exports.uploadTranscript = uploadTranscript;
|
|
4
5
|
/**
|
|
5
6
|
* PUTs an already-redacted transcript to the presigned R2 URL the
|
|
@@ -7,18 +8,44 @@ exports.uploadTranscript = uploadTranscript;
|
|
|
7
8
|
* implementation-plan.md WP-07). Kept as its own module so the storage
|
|
8
9
|
* mechanism is a one-function swap if it ever changes.
|
|
9
10
|
*/
|
|
11
|
+
const upload_errors_cjs_1 = require("./upload-errors.cjs");
|
|
12
|
+
Object.defineProperty(exports, "TranscriptUploadError", { enumerable: true, get: function () { return upload_errors_cjs_1.TranscriptUploadError; } });
|
|
13
|
+
Object.defineProperty(exports, "isTransientUploadError", { enumerable: true, get: function () { return upload_errors_cjs_1.isTransientUploadError; } });
|
|
10
14
|
/** Storage error bodies are small JSON blobs; cap in case we get an HTML page. */
|
|
11
15
|
const MAX_ERROR_BODY = 500;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const defaultSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
17
|
+
async function uploadTranscript(uploadUrl, content, fetchImpl = fetch, retry = {}) {
|
|
18
|
+
const attempts = Math.max(1, retry.attempts ?? 1);
|
|
19
|
+
const baseDelayMs = retry.baseDelayMs ?? 1_000;
|
|
20
|
+
const sleep = retry.sleep ?? defaultSleep;
|
|
21
|
+
for (let attempt = 1;; attempt += 1) {
|
|
22
|
+
try {
|
|
23
|
+
await putOnce(uploadUrl, content, fetchImpl);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
if (attempt >= attempts || !(0, upload_errors_cjs_1.isTransientUploadError)(error))
|
|
28
|
+
throw error;
|
|
29
|
+
await sleep(baseDelayMs * 2 ** (attempt - 1));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async function putOnce(uploadUrl, content, fetchImpl) {
|
|
34
|
+
let response;
|
|
35
|
+
try {
|
|
36
|
+
response = await fetchImpl(uploadUrl, {
|
|
37
|
+
method: "PUT",
|
|
38
|
+
headers: { "content-type": "text/plain; charset=utf-8" },
|
|
39
|
+
body: content,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
throw new upload_errors_cjs_1.TranscriptUploadError(`Transcript upload failed: ${String(error)}`, null);
|
|
44
|
+
}
|
|
18
45
|
if (!response.ok) {
|
|
19
46
|
// Include the bounded storage response to distinguish expired signatures
|
|
20
47
|
// from bucket misconfiguration.
|
|
21
|
-
throw new
|
|
48
|
+
throw new upload_errors_cjs_1.TranscriptUploadError(`Transcript upload failed with ${response.status}: ${await readErrorBody(response)}`, response.status);
|
|
22
49
|
}
|
|
23
50
|
}
|
|
24
51
|
async function readErrorBody(response) {
|
package/package.json
CHANGED