agentbox-sdk 0.1.600 → 0.1.601
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/agents/index.js
CHANGED
|
@@ -30,11 +30,11 @@ import {
|
|
|
30
30
|
} from "./chunk-GOFJNFAD.js";
|
|
31
31
|
|
|
32
32
|
// src/agents/Agent.ts
|
|
33
|
-
import { randomUUID as
|
|
33
|
+
import { randomUUID as randomUUID4 } from "crypto";
|
|
34
34
|
import path12 from "path";
|
|
35
35
|
|
|
36
36
|
// src/agents/providers/claude-code.ts
|
|
37
|
-
import { randomUUID } from "crypto";
|
|
37
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
38
38
|
|
|
39
39
|
// src/agents/transports/spawn.ts
|
|
40
40
|
import { execFile, spawn } from "child_process";
|
|
@@ -1585,13 +1585,13 @@ async function activateRtk(target) {
|
|
|
1585
1585
|
}
|
|
1586
1586
|
|
|
1587
1587
|
// src/agents/config/setup-manifest.ts
|
|
1588
|
-
import { createHash } from "crypto";
|
|
1588
|
+
import { createHash, randomUUID } from "crypto";
|
|
1589
1589
|
import path6 from "path";
|
|
1590
1590
|
var MANIFEST_FILENAME = "setup-manifest.json";
|
|
1591
|
-
var
|
|
1592
|
-
var
|
|
1591
|
+
var TARGET_MANIFEST_PREFIX = "setup-target.";
|
|
1592
|
+
var INSTALL_SCRIPT_PREFIX = "install.";
|
|
1593
1593
|
var SETUP_ID_FILENAME = "setup.id";
|
|
1594
|
-
var MANIFEST_VERSION =
|
|
1594
|
+
var MANIFEST_VERSION = 2;
|
|
1595
1595
|
function hashArtifact(artifact) {
|
|
1596
1596
|
const hasher = createHash("sha256");
|
|
1597
1597
|
hasher.update(artifact.executable ? "1" : "0");
|
|
@@ -1685,7 +1685,7 @@ ${detail}` : ""}`
|
|
|
1685
1685
|
}
|
|
1686
1686
|
});
|
|
1687
1687
|
}
|
|
1688
|
-
function buildInstallScript(rootDir, installCommandsByKey) {
|
|
1688
|
+
function buildInstallScript(rootDir, targetManifestPath, installCommandsByKey) {
|
|
1689
1689
|
const commandsB64 = Buffer.from(
|
|
1690
1690
|
JSON.stringify(installCommandsByKey),
|
|
1691
1691
|
"utf8"
|
|
@@ -1693,7 +1693,7 @@ function buildInstallScript(rootDir, installCommandsByKey) {
|
|
|
1693
1693
|
return `#!/usr/bin/env bash
|
|
1694
1694
|
set -e
|
|
1695
1695
|
ROOT_DIR=${shellQuote(rootDir)}
|
|
1696
|
-
TARGET_MANIFEST
|
|
1696
|
+
TARGET_MANIFEST=${shellQuote(targetManifestPath)}
|
|
1697
1697
|
EXISTING_MANIFEST="$ROOT_DIR/${MANIFEST_FILENAME}"
|
|
1698
1698
|
export TARGET_MANIFEST EXISTING_MANIFEST
|
|
1699
1699
|
|
|
@@ -1702,7 +1702,8 @@ export TARGET_MANIFEST EXISTING_MANIFEST
|
|
|
1702
1702
|
# emits the commands themselves, NUL-separated, so bash never has to
|
|
1703
1703
|
# deserialize JSON.
|
|
1704
1704
|
STALE_CMDS_FILE="$(mktemp)"
|
|
1705
|
-
|
|
1705
|
+
# This run's target manifest and script are per-run files; remove them.
|
|
1706
|
+
trap 'rm -f "$STALE_CMDS_FILE" "$TARGET_MANIFEST" "$0"' EXIT
|
|
1706
1707
|
COMMANDS_B64=${shellQuote(commandsB64)} \\
|
|
1707
1708
|
MANIFEST_VERSION=${MANIFEST_VERSION} \\
|
|
1708
1709
|
python3 - <<'PY' > "$STALE_CMDS_FILE"
|
|
@@ -1728,15 +1729,36 @@ stale = [
|
|
|
1728
1729
|
for key, hashed in target_cmds.items()
|
|
1729
1730
|
if commands.get(key) is not None and existing_cmds.get(key) != hashed
|
|
1730
1731
|
]
|
|
1731
|
-
|
|
1732
|
+
# Terminate every entry: \`read -d ''\` drops a last entry with no NUL.
|
|
1733
|
+
sys.stdout.write("".join(cmd + "\\0" for cmd in stale))
|
|
1732
1734
|
PY
|
|
1733
1735
|
|
|
1736
|
+
# Run stale commands in parallel, then retry failures one at a time: parallel
|
|
1737
|
+
# \`npx\` calls race on a cold npx cache, and the cache is warm by the retry.
|
|
1738
|
+
FAILED=0
|
|
1734
1739
|
if [ -s "$STALE_CMDS_FILE" ]; then
|
|
1740
|
+
CMDS=()
|
|
1741
|
+
PIDS=()
|
|
1735
1742
|
while IFS= read -r -d '' CMD; do
|
|
1736
1743
|
[ -z "$CMD" ] && continue
|
|
1737
1744
|
bash -c "$CMD" &
|
|
1745
|
+
CMDS+=("$CMD")
|
|
1746
|
+
PIDS+=("$!")
|
|
1738
1747
|
done < "$STALE_CMDS_FILE"
|
|
1739
|
-
|
|
1748
|
+
for i in "\${!PIDS[@]}"; do
|
|
1749
|
+
if ! wait "\${PIDS[$i]}"; then
|
|
1750
|
+
echo "agentbox install failed, retrying: \${CMDS[$i]}" >&2
|
|
1751
|
+
if ! bash -c "\${CMDS[$i]}"; then
|
|
1752
|
+
echo "agentbox install failed: \${CMDS[$i]}" >&2
|
|
1753
|
+
FAILED=1
|
|
1754
|
+
fi
|
|
1755
|
+
fi
|
|
1756
|
+
done
|
|
1757
|
+
fi
|
|
1758
|
+
|
|
1759
|
+
# Keep the old manifest when an install failed so the next run retries it.
|
|
1760
|
+
if [ "$FAILED" -ne 0 ]; then
|
|
1761
|
+
exit 1
|
|
1740
1762
|
fi
|
|
1741
1763
|
|
|
1742
1764
|
# Persist target manifest as the new manifest atomically. Doing this last
|
|
@@ -1745,7 +1767,7 @@ mv "$TARGET_MANIFEST" "$EXISTING_MANIFEST"
|
|
|
1745
1767
|
`;
|
|
1746
1768
|
}
|
|
1747
1769
|
async function applyDifferentialSetup(target, artifacts, installCommands) {
|
|
1748
|
-
|
|
1770
|
+
return time(
|
|
1749
1771
|
debugSetup,
|
|
1750
1772
|
`applyDifferentialSetup ${target.provider}`,
|
|
1751
1773
|
async () => {
|
|
@@ -1763,7 +1785,16 @@ async function applyDifferentialSetup(target, artifacts, installCommands) {
|
|
|
1763
1785
|
])
|
|
1764
1786
|
)
|
|
1765
1787
|
};
|
|
1788
|
+
const runId = randomUUID();
|
|
1766
1789
|
const rootDir = target.layout.rootDir;
|
|
1790
|
+
const targetManifestPath = path6.posix.join(
|
|
1791
|
+
rootDir,
|
|
1792
|
+
`${TARGET_MANIFEST_PREFIX}${runId}.json`
|
|
1793
|
+
);
|
|
1794
|
+
const installScriptPath = path6.posix.join(
|
|
1795
|
+
rootDir,
|
|
1796
|
+
`${INSTALL_SCRIPT_PREFIX}${runId}.sh`
|
|
1797
|
+
);
|
|
1767
1798
|
const tarballEntries = [
|
|
1768
1799
|
...artifacts.map((artifact) => ({
|
|
1769
1800
|
path: artifact.path,
|
|
@@ -1771,22 +1802,36 @@ async function applyDifferentialSetup(target, artifacts, installCommands) {
|
|
|
1771
1802
|
mode: artifact.executable ? 493 : 420
|
|
1772
1803
|
})),
|
|
1773
1804
|
{
|
|
1774
|
-
path:
|
|
1805
|
+
path: targetManifestPath,
|
|
1775
1806
|
content: JSON.stringify(targetForSandbox),
|
|
1776
1807
|
mode: 420
|
|
1777
1808
|
},
|
|
1778
1809
|
{
|
|
1779
|
-
path:
|
|
1780
|
-
content: buildInstallScript(
|
|
1810
|
+
path: installScriptPath,
|
|
1811
|
+
content: buildInstallScript(
|
|
1812
|
+
rootDir,
|
|
1813
|
+
targetManifestPath,
|
|
1814
|
+
installCommandsByKey
|
|
1815
|
+
),
|
|
1781
1816
|
mode: 493
|
|
1782
1817
|
}
|
|
1783
1818
|
];
|
|
1784
|
-
await target.uploadAndRun(
|
|
1819
|
+
const result = await target.uploadAndRun(
|
|
1785
1820
|
tarballEntries,
|
|
1786
|
-
`bash ${shellQuote(
|
|
1821
|
+
`bash ${shellQuote(installScriptPath)}`
|
|
1787
1822
|
);
|
|
1823
|
+
if (result.exitCode !== 0) {
|
|
1824
|
+
const output = result.combinedOutput?.trim();
|
|
1825
|
+
console.warn(
|
|
1826
|
+
`[agentbox] ${target.provider} setup install failed (exit ${result.exitCode}); it will be retried on the next setup${output ? `:
|
|
1827
|
+
${output.slice(-2e3)}` : ""}`
|
|
1828
|
+
);
|
|
1829
|
+
return false;
|
|
1830
|
+
}
|
|
1831
|
+
return true;
|
|
1788
1832
|
},
|
|
1789
|
-
() => ({
|
|
1833
|
+
(ok) => ({
|
|
1834
|
+
ok,
|
|
1790
1835
|
artifacts: artifacts.length,
|
|
1791
1836
|
installCommands: installCommands.length
|
|
1792
1837
|
})
|
|
@@ -3660,7 +3705,7 @@ var ClaudeCodeAgentAdapter = class {
|
|
|
3660
3705
|
return;
|
|
3661
3706
|
}
|
|
3662
3707
|
const env = { ...options.env ?? {}, ...target.env };
|
|
3663
|
-
await Promise.all([
|
|
3708
|
+
const [installed] = await Promise.all([
|
|
3664
3709
|
time(
|
|
3665
3710
|
debugClaude,
|
|
3666
3711
|
"applyDifferentialSetup",
|
|
@@ -3671,7 +3716,7 @@ var ClaudeCodeAgentAdapter = class {
|
|
|
3671
3716
|
if (enableRtk) {
|
|
3672
3717
|
await time(debugClaude, "activateRtk", () => activateRtk(target));
|
|
3673
3718
|
}
|
|
3674
|
-
await markSetupComplete(target, setupId);
|
|
3719
|
+
if (installed) await markSetupComplete(target, setupId);
|
|
3675
3720
|
});
|
|
3676
3721
|
}
|
|
3677
3722
|
async execute(request, sink) {
|
|
@@ -3709,8 +3754,8 @@ ${serialized}` : serialized;
|
|
|
3709
3754
|
() => validateProviderUserInput(request.provider, request.run.input)
|
|
3710
3755
|
);
|
|
3711
3756
|
const userContent = mapToClaudeUserContent(inputParts);
|
|
3712
|
-
const initialUuid =
|
|
3713
|
-
const presetSessionId = request.run.resumeSessionId ??
|
|
3757
|
+
const initialUuid = randomUUID2();
|
|
3758
|
+
const presetSessionId = request.run.resumeSessionId ?? randomUUID2();
|
|
3714
3759
|
sink.setSessionId(presetSessionId);
|
|
3715
3760
|
const baseUrl = await time(
|
|
3716
3761
|
debugClaude,
|
|
@@ -3775,7 +3820,7 @@ ${serialized}` : serialized;
|
|
|
3775
3820
|
sink.onMessage(async (content) => {
|
|
3776
3821
|
const parts = await validateProviderUserInput(request.provider, content);
|
|
3777
3822
|
const mapped = mapToClaudeUserContent(parts);
|
|
3778
|
-
const messageUuid =
|
|
3823
|
+
const messageUuid = randomUUID2();
|
|
3779
3824
|
await fetch(
|
|
3780
3825
|
`${baseUrl}/runs/${encodeURIComponent(request.runId)}/sendMessage`,
|
|
3781
3826
|
{
|
|
@@ -4396,7 +4441,7 @@ async function executeNativeClaude(request, sink, wait = {}) {
|
|
|
4396
4441
|
const input = attachOnly ? [] : await validateProviderUserInput(request.provider, request.run.input);
|
|
4397
4442
|
const parkOption = request.options.provider?.parkBackgroundWork;
|
|
4398
4443
|
const parking = parkOption && "onWake" in parkOption ? parkOption : void 0;
|
|
4399
|
-
const sessionId = request.run.resumeSessionId ??
|
|
4444
|
+
const sessionId = request.run.resumeSessionId ?? randomUUID2();
|
|
4400
4445
|
if (request.run.forkSessionId)
|
|
4401
4446
|
await findParkedNativeSession(request.run.forkSessionId)?.end();
|
|
4402
4447
|
const adopting = request.run.resumeSessionId ? findParkedNativeSession(request.run.resumeSessionId) : void 0;
|
|
@@ -4413,7 +4458,7 @@ async function executeNativeClaude(request, sink, wait = {}) {
|
|
|
4413
4458
|
await stop();
|
|
4414
4459
|
});
|
|
4415
4460
|
sink.setSessionId(sessionId);
|
|
4416
|
-
const messageId =
|
|
4461
|
+
const messageId = randomUUID2();
|
|
4417
4462
|
const userMessage = {
|
|
4418
4463
|
type: "user",
|
|
4419
4464
|
uuid: messageId,
|
|
@@ -5631,8 +5676,13 @@ async function setupCodex(request) {
|
|
|
5631
5676
|
`Could not start Codex app-server: ${launchResult.combinedOutput || launchResult.stderr}`
|
|
5632
5677
|
);
|
|
5633
5678
|
}
|
|
5679
|
+
let installed2;
|
|
5634
5680
|
try {
|
|
5635
|
-
await applyDifferentialSetup(
|
|
5681
|
+
installed2 = await applyDifferentialSetup(
|
|
5682
|
+
target2,
|
|
5683
|
+
skillArtifacts2,
|
|
5684
|
+
installCommands2
|
|
5685
|
+
);
|
|
5636
5686
|
} catch (error) {
|
|
5637
5687
|
await target2.cleanup().catch(() => void 0);
|
|
5638
5688
|
throw error;
|
|
@@ -5640,7 +5690,7 @@ async function setupCodex(request) {
|
|
|
5640
5690
|
if (enableRtk2) {
|
|
5641
5691
|
await time(debugCodex, "activateRtk", () => activateRtk(sharedTarget));
|
|
5642
5692
|
}
|
|
5643
|
-
await markSetupComplete(sharedTarget, setupId2);
|
|
5693
|
+
if (installed2) await markSetupComplete(sharedTarget, setupId2);
|
|
5644
5694
|
return;
|
|
5645
5695
|
}
|
|
5646
5696
|
const target = await createSetupTarget(provider, "shared-setup", options);
|
|
@@ -5663,11 +5713,15 @@ async function setupCodex(request) {
|
|
|
5663
5713
|
await target.cleanup().catch(() => void 0);
|
|
5664
5714
|
throw error;
|
|
5665
5715
|
}
|
|
5666
|
-
await applyDifferentialSetup(
|
|
5716
|
+
const installed = await applyDifferentialSetup(
|
|
5717
|
+
target,
|
|
5718
|
+
allArtifacts,
|
|
5719
|
+
installCommands
|
|
5720
|
+
);
|
|
5667
5721
|
if (enableRtk) {
|
|
5668
5722
|
await time(debugCodex, "activateRtk", () => activateRtk(target));
|
|
5669
5723
|
}
|
|
5670
|
-
await markSetupComplete(target, setupId);
|
|
5724
|
+
if (installed) await markSetupComplete(target, setupId);
|
|
5671
5725
|
}
|
|
5672
5726
|
async function createRuntime(request, inputParts) {
|
|
5673
5727
|
const options = request.options;
|
|
@@ -6345,7 +6399,7 @@ var CodexAgentAdapter = class {
|
|
|
6345
6399
|
};
|
|
6346
6400
|
|
|
6347
6401
|
// src/agents/providers/opencode.ts
|
|
6348
|
-
import { createHash as createHash2, randomBytes, randomUUID as
|
|
6402
|
+
import { createHash as createHash2, randomBytes, randomUUID as randomUUID3 } from "crypto";
|
|
6349
6403
|
import os2 from "os";
|
|
6350
6404
|
import path11 from "path";
|
|
6351
6405
|
var SANDBOX_OPENCODE_PORT = 4096;
|
|
@@ -6690,7 +6744,11 @@ async function ensureSandboxOpenCodeServer(request) {
|
|
|
6690
6744
|
OPENCODE_DISABLE_DEFAULT_PLUGINS: "true",
|
|
6691
6745
|
OPENCODE_ENABLE_QUESTION_TOOL: hasInteractiveQuestions(options) ? "true" : "false"
|
|
6692
6746
|
};
|
|
6693
|
-
await applyDifferentialSetup(
|
|
6747
|
+
const installed = await applyDifferentialSetup(
|
|
6748
|
+
target,
|
|
6749
|
+
allArtifacts,
|
|
6750
|
+
installCommands
|
|
6751
|
+
);
|
|
6694
6752
|
if (enableRtk) {
|
|
6695
6753
|
await time(debugOpencode, "activateRtk", () => activateRtk(target));
|
|
6696
6754
|
}
|
|
@@ -6814,14 +6872,14 @@ ${lastLog}` : "")
|
|
|
6814
6872
|
"OpenCode server started but is not enforcing the capability token (OPENCODE_SERVER_PASSWORD ignored). Upgrade opencode-ai to a version that supports server authentication."
|
|
6815
6873
|
);
|
|
6816
6874
|
}
|
|
6817
|
-
await markSetupComplete(target, setupId);
|
|
6875
|
+
if (installed) await markSetupComplete(target, setupId);
|
|
6818
6876
|
});
|
|
6819
6877
|
}
|
|
6820
6878
|
async function startLocalOpenCodeServer(request) {
|
|
6821
6879
|
const originalOptions = request.options;
|
|
6822
6880
|
const options = {
|
|
6823
6881
|
...originalOptions,
|
|
6824
|
-
stateDirectory: path11.join(originalOptions.stateDirectory ?? path11.join(os2.tmpdir(), "agentbox-native"), "instances",
|
|
6882
|
+
stateDirectory: path11.join(originalOptions.stateDirectory ?? path11.join(os2.tmpdir(), "agentbox-native"), "instances", randomUUID3())
|
|
6825
6883
|
};
|
|
6826
6884
|
let generatedEnv = {};
|
|
6827
6885
|
if (options.configuration !== "native") {
|
|
@@ -8317,7 +8375,7 @@ var Agent = class {
|
|
|
8317
8375
|
throw new Error("AgentRunConfig.resumeParked requires resumeSessionId.");
|
|
8318
8376
|
}
|
|
8319
8377
|
}
|
|
8320
|
-
const runId = runConfig.runId ??
|
|
8378
|
+
const runId = runConfig.runId ?? randomUUID4();
|
|
8321
8379
|
const streamCalledAt = Date.now();
|
|
8322
8380
|
debugAgent("stream() provider=%s runId=%s", this.provider, runId);
|
|
8323
8381
|
const run = new AgentRunController(
|
package/dist/index.js
CHANGED