@axiom-lattice/core 2.1.50 → 2.1.52
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/index.d.mts +269 -237
- package/dist/index.d.ts +269 -237
- package/dist/index.js +409 -202
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +406 -207
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -32,7 +32,6 @@ var index_exports = {};
|
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
AGENT_TASK_EVENT: () => AGENT_TASK_EVENT,
|
|
34
34
|
Agent: () => Agent,
|
|
35
|
-
AgentConfig: () => import_protocols.AgentConfig,
|
|
36
35
|
AgentInstanceManager: () => AgentInstanceManager,
|
|
37
36
|
AgentLatticeManager: () => AgentLatticeManager,
|
|
38
37
|
AgentManager: () => AgentManager,
|
|
@@ -51,7 +50,6 @@ __export(index_exports, {
|
|
|
51
50
|
EmbeddingsLatticeManager: () => EmbeddingsLatticeManager,
|
|
52
51
|
FileSystemSkillStore: () => FileSystemSkillStore,
|
|
53
52
|
FilesystemBackend: () => FilesystemBackend,
|
|
54
|
-
GraphBuildOptions: () => import_protocols.GraphBuildOptions,
|
|
55
53
|
HumanMessage: () => import_messages4.HumanMessage,
|
|
56
54
|
InMemoryAssistantStore: () => InMemoryAssistantStore,
|
|
57
55
|
InMemoryChunkBuffer: () => InMemoryChunkBuffer,
|
|
@@ -105,9 +103,12 @@ __export(index_exports, {
|
|
|
105
103
|
ThreadStatus: () => ThreadStatus2,
|
|
106
104
|
ToolLatticeManager: () => ToolLatticeManager,
|
|
107
105
|
VectorStoreLatticeManager: () => VectorStoreLatticeManager,
|
|
106
|
+
VolumeFilesystem: () => VolumeFilesystem,
|
|
108
107
|
agentInstanceManager: () => agentInstanceManager,
|
|
109
108
|
agentLatticeManager: () => agentLatticeManager,
|
|
110
109
|
buildGrepResultsDict: () => buildGrepResultsDict,
|
|
110
|
+
buildNamedVolumeName: () => buildNamedVolumeName,
|
|
111
|
+
buildSandboxMetadataEnv: () => buildSandboxMetadataEnv,
|
|
111
112
|
buildSkillFile: () => buildSkillFile,
|
|
112
113
|
checkEmptyContent: () => checkEmptyContent,
|
|
113
114
|
clearEncryptionKeyCache: () => clearEncryptionKeyCache,
|
|
@@ -3481,39 +3482,68 @@ ${serverKeys.map(
|
|
|
3481
3482
|
// src/tool_lattice/code_eval/index.ts
|
|
3482
3483
|
var import_zod15 = __toESM(require("zod"));
|
|
3483
3484
|
|
|
3484
|
-
// src/
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3485
|
+
// src/deep_agent_new/backends/volumeFilesystem.ts
|
|
3486
|
+
var VolumeFilesystem = class {
|
|
3487
|
+
constructor(client) {
|
|
3488
|
+
this.client = client;
|
|
3488
3489
|
}
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
`Sandbox name "${name}" cannot be normalized to a valid RFC 1123 subdomain name`
|
|
3498
|
-
);
|
|
3490
|
+
async lsInfo(path4) {
|
|
3491
|
+
const entries = await this.client.list(path4);
|
|
3492
|
+
return entries.map((entry) => ({
|
|
3493
|
+
path: entry.path,
|
|
3494
|
+
is_dir: entry.kind === "directory",
|
|
3495
|
+
size: entry.size,
|
|
3496
|
+
modified_at: entry.modified ? new Date(entry.modified).toISOString() : void 0
|
|
3497
|
+
}));
|
|
3499
3498
|
}
|
|
3500
|
-
|
|
3501
|
-
|
|
3499
|
+
async read(filePath, offset = 0, limit = 2e3) {
|
|
3500
|
+
const raw = await this.client.read(filePath);
|
|
3501
|
+
const lines = raw.split("\n");
|
|
3502
|
+
const start = Math.max(0, offset);
|
|
3503
|
+
const end = Math.min(lines.length, start + limit);
|
|
3504
|
+
const sliced = lines.slice(start, end);
|
|
3505
|
+
return sliced.map((line, i) => {
|
|
3506
|
+
const lineNum = (start + i + 1).toString().padStart(6, " ");
|
|
3507
|
+
return `${lineNum}|${line}`;
|
|
3508
|
+
}).join("\n");
|
|
3502
3509
|
}
|
|
3503
|
-
|
|
3504
|
-
|
|
3510
|
+
async readRaw(filePath) {
|
|
3511
|
+
const content = await this.client.read(filePath);
|
|
3512
|
+
const lines = content.split("\n");
|
|
3513
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3514
|
+
return {
|
|
3515
|
+
content: lines,
|
|
3516
|
+
created_at: now,
|
|
3517
|
+
modified_at: now
|
|
3518
|
+
};
|
|
3505
3519
|
}
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3520
|
+
grepRaw(_pattern, _path, _glob) {
|
|
3521
|
+
throw new Error("Not supported on volume backend");
|
|
3522
|
+
}
|
|
3523
|
+
globInfo(_pattern, _path) {
|
|
3524
|
+
throw new Error("Not supported on volume backend");
|
|
3525
|
+
}
|
|
3526
|
+
async write(filePath, content) {
|
|
3527
|
+
try {
|
|
3528
|
+
await this.client.write(filePath, content);
|
|
3529
|
+
return { path: filePath, filesUpdate: null };
|
|
3530
|
+
} catch (err) {
|
|
3531
|
+
return { error: String(err) };
|
|
3514
3532
|
}
|
|
3515
3533
|
}
|
|
3516
|
-
|
|
3534
|
+
edit(_filePath, _oldString, _newString, _replaceAll) {
|
|
3535
|
+
throw new Error("Not supported on volume backend");
|
|
3536
|
+
}
|
|
3537
|
+
};
|
|
3538
|
+
|
|
3539
|
+
// src/sandbox_lattice/utils.ts
|
|
3540
|
+
var import_node_crypto = require("crypto");
|
|
3541
|
+
function normalizeSandboxName(name) {
|
|
3542
|
+
if (!name || typeof name !== "string") {
|
|
3543
|
+
throw new Error("Sandbox name must be a non-empty string");
|
|
3544
|
+
}
|
|
3545
|
+
const hash = (0, import_node_crypto.createHash)("sha256").update(name).digest("hex").slice(0, 16);
|
|
3546
|
+
return `n${hash}`;
|
|
3517
3547
|
}
|
|
3518
3548
|
function isValidSandboxName(name) {
|
|
3519
3549
|
if (!name || typeof name !== "string") {
|
|
@@ -3522,6 +3552,24 @@ function isValidSandboxName(name) {
|
|
|
3522
3552
|
const rfc1123Pattern = /^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$/;
|
|
3523
3553
|
return rfc1123Pattern.test(name.toLowerCase());
|
|
3524
3554
|
}
|
|
3555
|
+
function buildSandboxMetadataEnv(config) {
|
|
3556
|
+
if (!config) {
|
|
3557
|
+
return {};
|
|
3558
|
+
}
|
|
3559
|
+
const vars = {};
|
|
3560
|
+
if (config.tenantId) vars.LATTICE_TENANT_ID = config.tenantId;
|
|
3561
|
+
if (config.assistant_id) vars.LATTICE_ASSISTANT_ID = config.assistant_id;
|
|
3562
|
+
if (config.projectId) vars.LATTICE_PROJECT_ID = config.projectId;
|
|
3563
|
+
if (config.workspaceId) vars.LATTICE_WORKSPACE_ID = config.workspaceId;
|
|
3564
|
+
return vars;
|
|
3565
|
+
}
|
|
3566
|
+
|
|
3567
|
+
// src/sandbox_lattice/volumeFsUtils.ts
|
|
3568
|
+
var import_node_crypto2 = require("crypto");
|
|
3569
|
+
function buildNamedVolumeName(prefix, ...parts) {
|
|
3570
|
+
const hash = (0, import_node_crypto2.createHash)("sha256").update(parts.filter((part) => part !== void 0).join("\0")).digest("hex").slice(0, 16);
|
|
3571
|
+
return `${prefix}${hash}`;
|
|
3572
|
+
}
|
|
3525
3573
|
|
|
3526
3574
|
// src/sandbox_lattice/SandboxLatticeManager.ts
|
|
3527
3575
|
function computeSandboxName(config) {
|
|
@@ -3532,7 +3580,7 @@ function computeSandboxName(config) {
|
|
|
3532
3580
|
return normalizeSandboxName(`${config.tenantId ?? "default"}-${config.assistant_id}`);
|
|
3533
3581
|
case "project":
|
|
3534
3582
|
return normalizeSandboxName(
|
|
3535
|
-
`${config.tenantId ?? "default"}-${config.
|
|
3583
|
+
`${config.tenantId ?? "default"}-${config.assistant_id ?? "default"}-${config.projectId ?? "default"}`
|
|
3536
3584
|
);
|
|
3537
3585
|
}
|
|
3538
3586
|
}
|
|
@@ -3594,6 +3642,19 @@ var SandboxLatticeManager = class _SandboxLatticeManager extends BaseLatticeMana
|
|
|
3594
3642
|
});
|
|
3595
3643
|
return this.createSandbox(name, config);
|
|
3596
3644
|
}
|
|
3645
|
+
async getVolumeBackend(config) {
|
|
3646
|
+
const provider = this._requireProvider();
|
|
3647
|
+
if (!provider.createVolumeFsClient) {
|
|
3648
|
+
return null;
|
|
3649
|
+
}
|
|
3650
|
+
const tenantId = config.tenantId ?? "default";
|
|
3651
|
+
if (!config.projectId) {
|
|
3652
|
+
return null;
|
|
3653
|
+
}
|
|
3654
|
+
const volumeName = buildNamedVolumeName("p", "project", tenantId, config.workspaceId, config.projectId);
|
|
3655
|
+
const client = provider.createVolumeFsClient(volumeName);
|
|
3656
|
+
return new VolumeFilesystem(client);
|
|
3657
|
+
}
|
|
3597
3658
|
async createSandbox(name, config) {
|
|
3598
3659
|
const provider = this._requireProvider();
|
|
3599
3660
|
return provider.createSandbox(name, config);
|
|
@@ -5212,21 +5273,28 @@ function truncateIfTooLong(result) {
|
|
|
5212
5273
|
}
|
|
5213
5274
|
return result;
|
|
5214
5275
|
}
|
|
5215
|
-
function validatePath(
|
|
5216
|
-
const pathStr =
|
|
5276
|
+
function validatePath(path4) {
|
|
5277
|
+
const pathStr = path4 || "/";
|
|
5217
5278
|
if (!pathStr || pathStr.trim() === "") {
|
|
5218
5279
|
throw new Error("Path cannot be empty");
|
|
5219
5280
|
}
|
|
5220
|
-
let normalized
|
|
5281
|
+
let normalized;
|
|
5282
|
+
if (pathStr === "~") {
|
|
5283
|
+
normalized = "~/";
|
|
5284
|
+
} else if (pathStr.startsWith("~/")) {
|
|
5285
|
+
normalized = pathStr;
|
|
5286
|
+
} else {
|
|
5287
|
+
normalized = pathStr.startsWith("/") ? pathStr : "/" + pathStr;
|
|
5288
|
+
}
|
|
5221
5289
|
if (!normalized.endsWith("/")) {
|
|
5222
5290
|
normalized += "/";
|
|
5223
5291
|
}
|
|
5224
5292
|
return normalized;
|
|
5225
5293
|
}
|
|
5226
|
-
function globSearchFiles(files, pattern,
|
|
5294
|
+
function globSearchFiles(files, pattern, path4 = "/") {
|
|
5227
5295
|
let normalizedPath;
|
|
5228
5296
|
try {
|
|
5229
|
-
normalizedPath = validatePath(
|
|
5297
|
+
normalizedPath = validatePath(path4);
|
|
5230
5298
|
} catch {
|
|
5231
5299
|
return "No files found";
|
|
5232
5300
|
}
|
|
@@ -5278,7 +5346,7 @@ function formatGrepResults(results, outputMode) {
|
|
|
5278
5346
|
}
|
|
5279
5347
|
return lines.join("\n");
|
|
5280
5348
|
}
|
|
5281
|
-
function grepSearchFiles(files, pattern,
|
|
5349
|
+
function grepSearchFiles(files, pattern, path4 = null, glob = null, outputMode = "files_with_matches") {
|
|
5282
5350
|
let regex;
|
|
5283
5351
|
try {
|
|
5284
5352
|
regex = new RegExp(pattern);
|
|
@@ -5287,7 +5355,7 @@ function grepSearchFiles(files, pattern, path3 = null, glob = null, outputMode =
|
|
|
5287
5355
|
}
|
|
5288
5356
|
let normalizedPath;
|
|
5289
5357
|
try {
|
|
5290
|
-
normalizedPath = validatePath(
|
|
5358
|
+
normalizedPath = validatePath(path4);
|
|
5291
5359
|
} catch {
|
|
5292
5360
|
return "No matches found";
|
|
5293
5361
|
}
|
|
@@ -5319,7 +5387,7 @@ function grepSearchFiles(files, pattern, path3 = null, glob = null, outputMode =
|
|
|
5319
5387
|
}
|
|
5320
5388
|
return formatGrepResults(results, outputMode);
|
|
5321
5389
|
}
|
|
5322
|
-
function grepMatchesFromFiles(files, pattern,
|
|
5390
|
+
function grepMatchesFromFiles(files, pattern, path4 = null, glob = null) {
|
|
5323
5391
|
let regex;
|
|
5324
5392
|
try {
|
|
5325
5393
|
regex = new RegExp(pattern);
|
|
@@ -5328,7 +5396,7 @@ function grepMatchesFromFiles(files, pattern, path3 = null, glob = null) {
|
|
|
5328
5396
|
}
|
|
5329
5397
|
let normalizedPath;
|
|
5330
5398
|
try {
|
|
5331
|
-
normalizedPath = validatePath(
|
|
5399
|
+
normalizedPath = validatePath(path4);
|
|
5332
5400
|
} catch {
|
|
5333
5401
|
return [];
|
|
5334
5402
|
}
|
|
@@ -5389,11 +5457,11 @@ var StateBackend = class {
|
|
|
5389
5457
|
* @returns List of FileInfo objects for files and directories directly in the directory.
|
|
5390
5458
|
* Directories have a trailing / in their path and is_dir=true.
|
|
5391
5459
|
*/
|
|
5392
|
-
lsInfo(
|
|
5460
|
+
lsInfo(path4) {
|
|
5393
5461
|
const files = this.getFiles();
|
|
5394
5462
|
const infos = [];
|
|
5395
5463
|
const subdirs = /* @__PURE__ */ new Set();
|
|
5396
|
-
const normalizedPath =
|
|
5464
|
+
const normalizedPath = path4.endsWith("/") ? path4 : path4 + "/";
|
|
5397
5465
|
for (const [k, fd] of Object.entries(files)) {
|
|
5398
5466
|
if (!k.startsWith(normalizedPath)) {
|
|
5399
5467
|
continue;
|
|
@@ -5499,16 +5567,16 @@ var StateBackend = class {
|
|
|
5499
5567
|
/**
|
|
5500
5568
|
* Structured search results or error string for invalid input.
|
|
5501
5569
|
*/
|
|
5502
|
-
grepRaw(pattern,
|
|
5570
|
+
grepRaw(pattern, path4 = "/", glob = null) {
|
|
5503
5571
|
const files = this.getFiles();
|
|
5504
|
-
return grepMatchesFromFiles(files, pattern,
|
|
5572
|
+
return grepMatchesFromFiles(files, pattern, path4, glob);
|
|
5505
5573
|
}
|
|
5506
5574
|
/**
|
|
5507
5575
|
* Structured glob matching returning FileInfo objects.
|
|
5508
5576
|
*/
|
|
5509
|
-
globInfo(pattern,
|
|
5577
|
+
globInfo(pattern, path4 = "/") {
|
|
5510
5578
|
const files = this.getFiles();
|
|
5511
|
-
const result = globSearchFiles(files, pattern,
|
|
5579
|
+
const result = globSearchFiles(files, pattern, path4);
|
|
5512
5580
|
if (result === "No files found") {
|
|
5513
5581
|
return [];
|
|
5514
5582
|
}
|
|
@@ -5602,10 +5670,10 @@ function createLsTool(backend, options) {
|
|
|
5602
5670
|
...runConfig
|
|
5603
5671
|
};
|
|
5604
5672
|
const resolvedBackend = await getBackend(backend, stateAndStore);
|
|
5605
|
-
const
|
|
5606
|
-
const infos = await resolvedBackend.lsInfo(
|
|
5673
|
+
const path4 = input.path || "/";
|
|
5674
|
+
const infos = await resolvedBackend.lsInfo(path4);
|
|
5607
5675
|
if (infos.length === 0) {
|
|
5608
|
-
return `No files found in ${
|
|
5676
|
+
return `No files found in ${path4}`;
|
|
5609
5677
|
}
|
|
5610
5678
|
const lines = [];
|
|
5611
5679
|
for (const info of infos) {
|
|
@@ -5748,8 +5816,8 @@ function createGlobTool(backend, options) {
|
|
|
5748
5816
|
...runConfig
|
|
5749
5817
|
};
|
|
5750
5818
|
const resolvedBackend = await getBackend(backend, stateAndStore);
|
|
5751
|
-
const { pattern, path:
|
|
5752
|
-
const infos = await resolvedBackend.globInfo(pattern,
|
|
5819
|
+
const { pattern, path: path4 = "/" } = input;
|
|
5820
|
+
const infos = await resolvedBackend.globInfo(pattern, path4);
|
|
5753
5821
|
if (infos.length === 0) {
|
|
5754
5822
|
return `No files found matching pattern '${pattern}'`;
|
|
5755
5823
|
}
|
|
@@ -5776,8 +5844,8 @@ function createGrepTool(backend, options) {
|
|
|
5776
5844
|
...runConfig
|
|
5777
5845
|
};
|
|
5778
5846
|
const resolvedBackend = await getBackend(backend, stateAndStore);
|
|
5779
|
-
const { pattern, path:
|
|
5780
|
-
const result = await resolvedBackend.grepRaw(pattern,
|
|
5847
|
+
const { pattern, path: path4 = "/", glob = null } = input;
|
|
5848
|
+
const result = await resolvedBackend.grepRaw(pattern, path4, glob);
|
|
5781
5849
|
if (typeof result === "string") {
|
|
5782
5850
|
return result;
|
|
5783
5851
|
}
|
|
@@ -13163,13 +13231,13 @@ var StoreBackend = class {
|
|
|
13163
13231
|
* @returns List of FileInfo objects for files and directories directly in the directory.
|
|
13164
13232
|
* Directories have a trailing / in their path and is_dir=true.
|
|
13165
13233
|
*/
|
|
13166
|
-
async lsInfo(
|
|
13234
|
+
async lsInfo(path4) {
|
|
13167
13235
|
const store = this.getStore();
|
|
13168
13236
|
const namespace = this.getNamespace();
|
|
13169
13237
|
const items = await this.searchStorePaginated(store, namespace);
|
|
13170
13238
|
const infos = [];
|
|
13171
13239
|
const subdirs = /* @__PURE__ */ new Set();
|
|
13172
|
-
const normalizedPath =
|
|
13240
|
+
const normalizedPath = path4.endsWith("/") ? path4 : path4 + "/";
|
|
13173
13241
|
for (const item of items) {
|
|
13174
13242
|
const itemKey = String(item.key);
|
|
13175
13243
|
if (!itemKey.startsWith(normalizedPath)) {
|
|
@@ -13287,7 +13355,7 @@ var StoreBackend = class {
|
|
|
13287
13355
|
/**
|
|
13288
13356
|
* Structured search results or error string for invalid input.
|
|
13289
13357
|
*/
|
|
13290
|
-
async grepRaw(pattern,
|
|
13358
|
+
async grepRaw(pattern, path4 = "/", glob = null) {
|
|
13291
13359
|
const store = this.getStore();
|
|
13292
13360
|
const namespace = this.getNamespace();
|
|
13293
13361
|
const items = await this.searchStorePaginated(store, namespace);
|
|
@@ -13299,12 +13367,12 @@ var StoreBackend = class {
|
|
|
13299
13367
|
continue;
|
|
13300
13368
|
}
|
|
13301
13369
|
}
|
|
13302
|
-
return grepMatchesFromFiles(files, pattern,
|
|
13370
|
+
return grepMatchesFromFiles(files, pattern, path4, glob);
|
|
13303
13371
|
}
|
|
13304
13372
|
/**
|
|
13305
13373
|
* Structured glob matching returning FileInfo objects.
|
|
13306
13374
|
*/
|
|
13307
|
-
async globInfo(pattern,
|
|
13375
|
+
async globInfo(pattern, path4 = "/") {
|
|
13308
13376
|
const store = this.getStore();
|
|
13309
13377
|
const namespace = this.getNamespace();
|
|
13310
13378
|
const items = await this.searchStorePaginated(store, namespace);
|
|
@@ -13316,7 +13384,7 @@ var StoreBackend = class {
|
|
|
13316
13384
|
continue;
|
|
13317
13385
|
}
|
|
13318
13386
|
}
|
|
13319
|
-
const result = globSearchFiles(files, pattern,
|
|
13387
|
+
const result = globSearchFiles(files, pattern, path4);
|
|
13320
13388
|
if (result === "No files found") {
|
|
13321
13389
|
return [];
|
|
13322
13390
|
}
|
|
@@ -13365,8 +13433,9 @@ var FilesystemBackend = class {
|
|
|
13365
13433
|
*/
|
|
13366
13434
|
resolvePath(key) {
|
|
13367
13435
|
if (this.virtualMode) {
|
|
13368
|
-
const
|
|
13369
|
-
|
|
13436
|
+
const normalizedKey = key === "~" ? "/" : key.startsWith("~/") ? `/${key.slice(2)}` : key;
|
|
13437
|
+
const vpath = normalizedKey.startsWith("/") ? normalizedKey : "/" + normalizedKey;
|
|
13438
|
+
if (vpath.includes("..") || vpath.includes("~")) {
|
|
13370
13439
|
throw new Error("Path traversal not allowed");
|
|
13371
13440
|
}
|
|
13372
13441
|
const full = path2.resolve(this.cwd, vpath.substring(1));
|
|
@@ -13891,10 +13960,10 @@ var CompositeBackend = class {
|
|
|
13891
13960
|
* @returns List of FileInfo objects with route prefixes added, for files and directories
|
|
13892
13961
|
* directly in the directory. Directories have a trailing / in their path and is_dir=true.
|
|
13893
13962
|
*/
|
|
13894
|
-
async lsInfo(
|
|
13963
|
+
async lsInfo(path4) {
|
|
13895
13964
|
for (const [routePrefix, backend] of this.sortedRoutes) {
|
|
13896
|
-
if (
|
|
13897
|
-
const suffix =
|
|
13965
|
+
if (path4.startsWith(routePrefix.replace(/\/$/, ""))) {
|
|
13966
|
+
const suffix = path4.substring(routePrefix.length);
|
|
13898
13967
|
const searchPath = suffix ? "/" + suffix : "/";
|
|
13899
13968
|
const infos = await backend.lsInfo(searchPath);
|
|
13900
13969
|
const prefixed = [];
|
|
@@ -13907,9 +13976,9 @@ var CompositeBackend = class {
|
|
|
13907
13976
|
return prefixed;
|
|
13908
13977
|
}
|
|
13909
13978
|
}
|
|
13910
|
-
if (
|
|
13979
|
+
if (path4 === "/") {
|
|
13911
13980
|
const results = [];
|
|
13912
|
-
const defaultInfos = await this.default.lsInfo(
|
|
13981
|
+
const defaultInfos = await this.default.lsInfo(path4);
|
|
13913
13982
|
results.push(...defaultInfos);
|
|
13914
13983
|
for (const [routePrefix] of this.sortedRoutes) {
|
|
13915
13984
|
results.push({
|
|
@@ -13922,7 +13991,7 @@ var CompositeBackend = class {
|
|
|
13922
13991
|
results.sort((a, b) => a.path.localeCompare(b.path));
|
|
13923
13992
|
return results;
|
|
13924
13993
|
}
|
|
13925
|
-
return await this.default.lsInfo(
|
|
13994
|
+
return await this.default.lsInfo(path4);
|
|
13926
13995
|
}
|
|
13927
13996
|
/**
|
|
13928
13997
|
* Read file content, routing to appropriate backend.
|
|
@@ -13949,10 +14018,10 @@ var CompositeBackend = class {
|
|
|
13949
14018
|
/**
|
|
13950
14019
|
* Structured search results or error string for invalid input.
|
|
13951
14020
|
*/
|
|
13952
|
-
async grepRaw(pattern,
|
|
14021
|
+
async grepRaw(pattern, path4 = "/", glob = null) {
|
|
13953
14022
|
for (const [routePrefix, backend] of this.sortedRoutes) {
|
|
13954
|
-
if (
|
|
13955
|
-
const searchPath =
|
|
14023
|
+
if (path4.startsWith(routePrefix.replace(/\/$/, ""))) {
|
|
14024
|
+
const searchPath = path4.substring(routePrefix.length - 1);
|
|
13956
14025
|
const raw = await backend.grepRaw(pattern, searchPath || "/", glob);
|
|
13957
14026
|
if (typeof raw === "string") {
|
|
13958
14027
|
return raw;
|
|
@@ -13964,7 +14033,7 @@ var CompositeBackend = class {
|
|
|
13964
14033
|
}
|
|
13965
14034
|
}
|
|
13966
14035
|
const allMatches = [];
|
|
13967
|
-
const rawDefault = await this.default.grepRaw(pattern,
|
|
14036
|
+
const rawDefault = await this.default.grepRaw(pattern, path4, glob);
|
|
13968
14037
|
if (typeof rawDefault === "string") {
|
|
13969
14038
|
return rawDefault;
|
|
13970
14039
|
}
|
|
@@ -13986,11 +14055,11 @@ var CompositeBackend = class {
|
|
|
13986
14055
|
/**
|
|
13987
14056
|
* Structured glob matching returning FileInfo objects.
|
|
13988
14057
|
*/
|
|
13989
|
-
async globInfo(pattern,
|
|
14058
|
+
async globInfo(pattern, path4 = "/") {
|
|
13990
14059
|
const results = [];
|
|
13991
14060
|
for (const [routePrefix, backend] of this.sortedRoutes) {
|
|
13992
|
-
if (
|
|
13993
|
-
const searchPath =
|
|
14061
|
+
if (path4.startsWith(routePrefix.replace(/\/$/, ""))) {
|
|
14062
|
+
const searchPath = path4.substring(routePrefix.length - 1);
|
|
13994
14063
|
const infos = await backend.globInfo(pattern, searchPath || "/");
|
|
13995
14064
|
return infos.map((fi) => ({
|
|
13996
14065
|
...fi,
|
|
@@ -13998,7 +14067,7 @@ var CompositeBackend = class {
|
|
|
13998
14067
|
}));
|
|
13999
14068
|
}
|
|
14000
14069
|
}
|
|
14001
|
-
const defaultInfos = await this.default.globInfo(pattern,
|
|
14070
|
+
const defaultInfos = await this.default.globInfo(pattern, path4);
|
|
14002
14071
|
results.push(...defaultInfos);
|
|
14003
14072
|
for (const [routePrefix, backend] of Object.entries(this.routes)) {
|
|
14004
14073
|
const infos = await backend.globInfo(pattern, "/");
|
|
@@ -14046,11 +14115,11 @@ var MemoryBackend = class {
|
|
|
14046
14115
|
getFiles() {
|
|
14047
14116
|
return Object.fromEntries(this.files);
|
|
14048
14117
|
}
|
|
14049
|
-
lsInfo(
|
|
14118
|
+
lsInfo(path4) {
|
|
14050
14119
|
const files = this.getFiles();
|
|
14051
14120
|
const infos = [];
|
|
14052
14121
|
const subdirs = /* @__PURE__ */ new Set();
|
|
14053
|
-
const normalizedPath =
|
|
14122
|
+
const normalizedPath = path4.endsWith("/") ? path4 : path4 + "/";
|
|
14054
14123
|
for (const [k, fd] of Object.entries(files)) {
|
|
14055
14124
|
if (!k.startsWith(normalizedPath)) {
|
|
14056
14125
|
continue;
|
|
@@ -14125,13 +14194,13 @@ var MemoryBackend = class {
|
|
|
14125
14194
|
this.files.set(filePath, newFileData);
|
|
14126
14195
|
return { path: filePath, filesUpdate: null, occurrences };
|
|
14127
14196
|
}
|
|
14128
|
-
grepRaw(pattern,
|
|
14197
|
+
grepRaw(pattern, path4 = "/", glob = null) {
|
|
14129
14198
|
const files = this.getFiles();
|
|
14130
|
-
return grepMatchesFromFiles(files, pattern,
|
|
14199
|
+
return grepMatchesFromFiles(files, pattern, path4, glob);
|
|
14131
14200
|
}
|
|
14132
|
-
globInfo(pattern,
|
|
14201
|
+
globInfo(pattern, path4 = "/") {
|
|
14133
14202
|
const files = this.getFiles();
|
|
14134
|
-
const result = globSearchFiles(files, pattern,
|
|
14203
|
+
const result = globSearchFiles(files, pattern, path4);
|
|
14135
14204
|
if (result === "No files found") {
|
|
14136
14205
|
return [];
|
|
14137
14206
|
}
|
|
@@ -18173,22 +18242,30 @@ var mcpManager = McpLatticeManager.getInstance();
|
|
|
18173
18242
|
var import_microsandbox = require("microsandbox");
|
|
18174
18243
|
|
|
18175
18244
|
// src/sandbox_lattice/MicrosandboxInstance.ts
|
|
18245
|
+
function exec(native, cmd, opts) {
|
|
18246
|
+
return native.execWith(cmd, (b) => {
|
|
18247
|
+
if (opts?.args) b.args(opts.args);
|
|
18248
|
+
if (opts?.cwd) b.cwd(opts.cwd);
|
|
18249
|
+
if (opts?.timeoutMs) b.timeout(opts.timeoutMs);
|
|
18250
|
+
return b;
|
|
18251
|
+
});
|
|
18252
|
+
}
|
|
18176
18253
|
var MicrosandboxInstance = class {
|
|
18177
18254
|
constructor(name, native) {
|
|
18178
18255
|
this.native = native;
|
|
18179
18256
|
this.file = {
|
|
18180
18257
|
readFile: async (file) => {
|
|
18181
18258
|
const fs3 = this.native.fs();
|
|
18182
|
-
const content = await fs3.
|
|
18259
|
+
const content = await fs3.readToString(file);
|
|
18183
18260
|
return { content };
|
|
18184
18261
|
},
|
|
18185
18262
|
writeFile: async (file, content) => {
|
|
18186
18263
|
const fs3 = this.native.fs();
|
|
18187
18264
|
await fs3.write(file, Buffer.from(content));
|
|
18188
18265
|
},
|
|
18189
|
-
listPath: async (
|
|
18266
|
+
listPath: async (path4, options) => {
|
|
18190
18267
|
const fs3 = this.native.fs();
|
|
18191
|
-
const entries = await fs3.list(
|
|
18268
|
+
const entries = await fs3.list(path4);
|
|
18192
18269
|
const files = (entries || []).map((e) => ({
|
|
18193
18270
|
path: e.path,
|
|
18194
18271
|
is_dir: e.kind === "directory",
|
|
@@ -18197,17 +18274,15 @@ var MicrosandboxInstance = class {
|
|
|
18197
18274
|
}));
|
|
18198
18275
|
return { files };
|
|
18199
18276
|
},
|
|
18200
|
-
findFiles: async (
|
|
18201
|
-
const output = await this.native
|
|
18202
|
-
|
|
18203
|
-
args: ["-c", `find "${path3}" -name "${glob}" -type f`]
|
|
18277
|
+
findFiles: async (path4, glob) => {
|
|
18278
|
+
const output = await exec(this.native, "sh", {
|
|
18279
|
+
args: ["-c", `find "${path4}" -name "${glob}" -type f`]
|
|
18204
18280
|
});
|
|
18205
18281
|
const lines = output.stdout().split("\n").filter(Boolean);
|
|
18206
18282
|
return { files: lines };
|
|
18207
18283
|
},
|
|
18208
18284
|
searchInFile: async (file, regex) => {
|
|
18209
|
-
const output = await this.native
|
|
18210
|
-
cmd: "grep",
|
|
18285
|
+
const output = await exec(this.native, "grep", {
|
|
18211
18286
|
args: ["-n", "-E", regex, file]
|
|
18212
18287
|
});
|
|
18213
18288
|
const lines = output.stdout().split("\n").filter(Boolean);
|
|
@@ -18224,14 +18299,13 @@ var MicrosandboxInstance = class {
|
|
|
18224
18299
|
return { matches, line_numbers };
|
|
18225
18300
|
},
|
|
18226
18301
|
strReplaceEditor: async (params) => {
|
|
18227
|
-
const { path:
|
|
18302
|
+
const { path: path4, old_str, new_str, replace_mode } = params;
|
|
18228
18303
|
const delim = "#";
|
|
18229
18304
|
const escapedOld = old_str.replace(new RegExp(`[\\\\${delim}]`, "g"), "\\$&").replace(/\n/g, "\\n");
|
|
18230
18305
|
const escapedNew = new_str.replace(new RegExp(`[\\\\${delim}]`, "g"), "\\$&").replace(/\n/g, "\\n");
|
|
18231
18306
|
const flag = replace_mode === "ALL" ? "g" : "";
|
|
18232
|
-
await this.native
|
|
18233
|
-
|
|
18234
|
-
args: ["-c", `sed -i 's${delim}${escapedOld}${delim}${escapedNew}${delim}${flag}' "${path3}"`]
|
|
18307
|
+
await exec(this.native, "sh", {
|
|
18308
|
+
args: ["-c", `sed -i 's${delim}${escapedOld}${delim}${escapedNew}${delim}${flag}' "${path4}"`]
|
|
18235
18309
|
});
|
|
18236
18310
|
},
|
|
18237
18311
|
uploadFile: async (params) => {
|
|
@@ -18246,8 +18320,7 @@ var MicrosandboxInstance = class {
|
|
|
18246
18320
|
};
|
|
18247
18321
|
this.shell = {
|
|
18248
18322
|
execCommand: async (params) => {
|
|
18249
|
-
const output = await this.native
|
|
18250
|
-
cmd: "sh",
|
|
18323
|
+
const output = await exec(this.native, "sh", {
|
|
18251
18324
|
args: ["-c", params.command],
|
|
18252
18325
|
cwd: params.exec_dir,
|
|
18253
18326
|
timeoutMs: params.timeout ? params.timeout * 1e3 : void 0
|
|
@@ -18270,7 +18343,7 @@ var MicrosandboxInstance = class {
|
|
|
18270
18343
|
}
|
|
18271
18344
|
async getStatus() {
|
|
18272
18345
|
try {
|
|
18273
|
-
await this.native.
|
|
18346
|
+
await this.native.exec("echo", ["ok"]);
|
|
18274
18347
|
return "running";
|
|
18275
18348
|
} catch {
|
|
18276
18349
|
return "unknown";
|
|
@@ -18297,7 +18370,7 @@ var MicrosandboxProvider = class {
|
|
|
18297
18370
|
this.instances = /* @__PURE__ */ new Map();
|
|
18298
18371
|
this.creating = /* @__PURE__ */ new Map();
|
|
18299
18372
|
}
|
|
18300
|
-
async createSandbox(name) {
|
|
18373
|
+
async createSandbox(name, config) {
|
|
18301
18374
|
const existing = this.instances.get(name);
|
|
18302
18375
|
if (existing) {
|
|
18303
18376
|
return existing;
|
|
@@ -18324,13 +18397,11 @@ var MicrosandboxProvider = class {
|
|
|
18324
18397
|
native = void 0;
|
|
18325
18398
|
}
|
|
18326
18399
|
if (!native) {
|
|
18327
|
-
|
|
18328
|
-
|
|
18329
|
-
|
|
18330
|
-
cpus: this.config.cpus ?? 1,
|
|
18331
|
-
memoryMib: this.config.memoryMib ?? 512,
|
|
18332
|
-
env: this.config.env
|
|
18400
|
+
const builder = import_microsandbox.Sandbox.builder(name).image(this.config.image ?? "python:3.11-slim").cpus(this.config.cpus ?? 1).memory(this.config.memoryMib ?? 512).envs({
|
|
18401
|
+
...this.config.env,
|
|
18402
|
+
...buildSandboxMetadataEnv(config)
|
|
18333
18403
|
});
|
|
18404
|
+
native = await builder.createDetached();
|
|
18334
18405
|
}
|
|
18335
18406
|
const instance = new MicrosandboxInstance(name, native);
|
|
18336
18407
|
this.instances.set(name, instance);
|
|
@@ -18370,31 +18441,92 @@ var MicrosandboxProvider = class {
|
|
|
18370
18441
|
}
|
|
18371
18442
|
};
|
|
18372
18443
|
|
|
18444
|
+
// src/sandbox_lattice/pathUtils.ts
|
|
18445
|
+
var import_path2 = __toESM(require("path"));
|
|
18446
|
+
var SANDBOX_HOME_DIR = "/home/daytona";
|
|
18447
|
+
function normalizeExternalSandboxPath(inputPath) {
|
|
18448
|
+
if (inputPath === "~") {
|
|
18449
|
+
return "~/";
|
|
18450
|
+
}
|
|
18451
|
+
if (inputPath === SANDBOX_HOME_DIR) {
|
|
18452
|
+
return "~/";
|
|
18453
|
+
}
|
|
18454
|
+
if (inputPath.startsWith(`${SANDBOX_HOME_DIR}/`)) {
|
|
18455
|
+
return `~/${inputPath.slice(SANDBOX_HOME_DIR.length + 1)}`;
|
|
18456
|
+
}
|
|
18457
|
+
if (inputPath.startsWith("~/")) {
|
|
18458
|
+
return inputPath;
|
|
18459
|
+
}
|
|
18460
|
+
if (inputPath.startsWith("/")) {
|
|
18461
|
+
return `~${inputPath}`;
|
|
18462
|
+
}
|
|
18463
|
+
return inputPath;
|
|
18464
|
+
}
|
|
18465
|
+
function toSandboxRelativePath(inputPath) {
|
|
18466
|
+
const canonicalPath = normalizeExternalSandboxPath(inputPath);
|
|
18467
|
+
return canonicalPath === "~/" ? "" : canonicalPath.slice(2);
|
|
18468
|
+
}
|
|
18469
|
+
function toSandboxAbsolutePath(inputPath, homeDir = SANDBOX_HOME_DIR) {
|
|
18470
|
+
const relativePath = toSandboxRelativePath(inputPath);
|
|
18471
|
+
return relativePath ? import_path2.default.posix.join(homeDir, relativePath) : homeDir;
|
|
18472
|
+
}
|
|
18473
|
+
function fromSandboxExecutionPath(inputPath, homeDir = SANDBOX_HOME_DIR) {
|
|
18474
|
+
if (inputPath === homeDir) {
|
|
18475
|
+
return "~/";
|
|
18476
|
+
}
|
|
18477
|
+
if (inputPath.startsWith(`${homeDir}/`)) {
|
|
18478
|
+
return `~/${inputPath.slice(homeDir.length + 1)}`;
|
|
18479
|
+
}
|
|
18480
|
+
return normalizeExternalSandboxPath(inputPath);
|
|
18481
|
+
}
|
|
18482
|
+
|
|
18373
18483
|
// src/sandbox_lattice/MicrosandboxRemoteInstance.ts
|
|
18374
18484
|
var MicrosandboxRemoteInstance = class {
|
|
18375
18485
|
constructor(name, client) {
|
|
18376
18486
|
this.client = client;
|
|
18377
18487
|
this.file = {
|
|
18378
18488
|
readFile: async (file) => {
|
|
18379
|
-
const result = await this.client.readFile(
|
|
18489
|
+
const result = await this.client.readFile(
|
|
18490
|
+
this.name,
|
|
18491
|
+
toSandboxAbsolutePath(file, SANDBOX_HOME_DIR)
|
|
18492
|
+
);
|
|
18380
18493
|
return { content: result.content };
|
|
18381
18494
|
},
|
|
18382
18495
|
writeFile: async (file, content) => {
|
|
18383
|
-
await this.client.writeFile(
|
|
18496
|
+
await this.client.writeFile(
|
|
18497
|
+
this.name,
|
|
18498
|
+
toSandboxAbsolutePath(file, SANDBOX_HOME_DIR),
|
|
18499
|
+
content
|
|
18500
|
+
);
|
|
18384
18501
|
},
|
|
18385
|
-
listPath: async (
|
|
18386
|
-
const result = await this.client.listPath(
|
|
18502
|
+
listPath: async (path4, options) => {
|
|
18503
|
+
const result = await this.client.listPath(
|
|
18504
|
+
this.name,
|
|
18505
|
+
toSandboxAbsolutePath(path4, SANDBOX_HOME_DIR),
|
|
18506
|
+
options?.recursive
|
|
18507
|
+
);
|
|
18387
18508
|
const files = result.entries.map((entry) => ({
|
|
18388
|
-
path: entry.path,
|
|
18389
|
-
is_dir: entry.type === "
|
|
18509
|
+
path: fromSandboxExecutionPath(entry.path, SANDBOX_HOME_DIR),
|
|
18510
|
+
is_dir: entry.type === "directory"
|
|
18390
18511
|
}));
|
|
18391
18512
|
return { files };
|
|
18392
18513
|
},
|
|
18393
|
-
findFiles: async (
|
|
18394
|
-
|
|
18514
|
+
findFiles: async (path4, glob) => {
|
|
18515
|
+
const result = await this.client.findFiles(
|
|
18516
|
+
this.name,
|
|
18517
|
+
toSandboxAbsolutePath(path4, SANDBOX_HOME_DIR),
|
|
18518
|
+
glob
|
|
18519
|
+
);
|
|
18520
|
+
return {
|
|
18521
|
+
files: result.files.map((filePath) => fromSandboxExecutionPath(filePath, SANDBOX_HOME_DIR))
|
|
18522
|
+
};
|
|
18395
18523
|
},
|
|
18396
18524
|
searchInFile: async (file, regex) => {
|
|
18397
|
-
const result = await this.client.searchInFile(
|
|
18525
|
+
const result = await this.client.searchInFile(
|
|
18526
|
+
this.name,
|
|
18527
|
+
toSandboxAbsolutePath(file, SANDBOX_HOME_DIR),
|
|
18528
|
+
regex
|
|
18529
|
+
);
|
|
18398
18530
|
return {
|
|
18399
18531
|
matches: result.matches.map((match) => match.content),
|
|
18400
18532
|
line_numbers: result.matches.map((match) => match.line)
|
|
@@ -18402,16 +18534,23 @@ var MicrosandboxRemoteInstance = class {
|
|
|
18402
18534
|
},
|
|
18403
18535
|
strReplaceEditor: async (params) => {
|
|
18404
18536
|
await this.client.replaceInFile(this.name, {
|
|
18405
|
-
path: params.path,
|
|
18537
|
+
path: toSandboxAbsolutePath(params.path, SANDBOX_HOME_DIR),
|
|
18406
18538
|
search: params.old_str,
|
|
18407
18539
|
replace: params.new_str
|
|
18408
18540
|
});
|
|
18409
18541
|
},
|
|
18410
18542
|
uploadFile: async (params) => {
|
|
18411
|
-
await this.client.uploadFile(
|
|
18543
|
+
await this.client.uploadFile(
|
|
18544
|
+
this.name,
|
|
18545
|
+
toSandboxAbsolutePath(params.file, SANDBOX_HOME_DIR),
|
|
18546
|
+
params.data
|
|
18547
|
+
);
|
|
18412
18548
|
},
|
|
18413
18549
|
downloadFile: async (params) => {
|
|
18414
|
-
const result = await this.client.downloadFile(
|
|
18550
|
+
const result = await this.client.downloadFile(
|
|
18551
|
+
this.name,
|
|
18552
|
+
toSandboxAbsolutePath(params.file, SANDBOX_HOME_DIR)
|
|
18553
|
+
);
|
|
18415
18554
|
if (result.contentBase64) {
|
|
18416
18555
|
return Buffer.from(result.contentBase64, "base64");
|
|
18417
18556
|
}
|
|
@@ -18456,6 +18595,7 @@ var MicrosandboxRemoteInstance = class {
|
|
|
18456
18595
|
var MicrosandboxServiceClient = class {
|
|
18457
18596
|
constructor(config) {
|
|
18458
18597
|
this.baseURL = config.baseURL.replace(/\/$/, "");
|
|
18598
|
+
this.apiKey = config.apiKey;
|
|
18459
18599
|
}
|
|
18460
18600
|
async ensureSandbox(name, input) {
|
|
18461
18601
|
return this.request(`/api/sandboxes/${encodeURIComponent(name)}`, {
|
|
@@ -18488,34 +18628,34 @@ var MicrosandboxServiceClient = class {
|
|
|
18488
18628
|
method: "GET"
|
|
18489
18629
|
});
|
|
18490
18630
|
}
|
|
18491
|
-
async readFile(sandboxName,
|
|
18631
|
+
async readFile(sandboxName, path4) {
|
|
18492
18632
|
return this.request("/api/files/read", {
|
|
18493
18633
|
method: "POST",
|
|
18494
|
-
body: { sandboxName, path:
|
|
18634
|
+
body: { sandboxName, path: path4 }
|
|
18495
18635
|
});
|
|
18496
18636
|
}
|
|
18497
|
-
async writeFile(sandboxName,
|
|
18637
|
+
async writeFile(sandboxName, path4, content) {
|
|
18498
18638
|
return this.request("/api/files/write", {
|
|
18499
18639
|
method: "POST",
|
|
18500
|
-
body: { sandboxName, path:
|
|
18640
|
+
body: { sandboxName, path: path4, content }
|
|
18501
18641
|
});
|
|
18502
18642
|
}
|
|
18503
|
-
async listPath(sandboxName,
|
|
18643
|
+
async listPath(sandboxName, path4, recursive) {
|
|
18504
18644
|
return this.request("/api/files/list", {
|
|
18505
18645
|
method: "POST",
|
|
18506
|
-
body: { sandboxName, path:
|
|
18646
|
+
body: { sandboxName, path: path4, recursive }
|
|
18507
18647
|
});
|
|
18508
18648
|
}
|
|
18509
|
-
async findFiles(sandboxName,
|
|
18649
|
+
async findFiles(sandboxName, path4, pattern) {
|
|
18510
18650
|
return this.request("/api/files/find", {
|
|
18511
18651
|
method: "POST",
|
|
18512
|
-
body: { sandboxName, path:
|
|
18652
|
+
body: { sandboxName, path: path4, pattern }
|
|
18513
18653
|
});
|
|
18514
18654
|
}
|
|
18515
|
-
async searchInFile(sandboxName,
|
|
18655
|
+
async searchInFile(sandboxName, path4, query) {
|
|
18516
18656
|
return this.request("/api/files/search", {
|
|
18517
18657
|
method: "POST",
|
|
18518
|
-
body: { sandboxName, path:
|
|
18658
|
+
body: { sandboxName, path: path4, query }
|
|
18519
18659
|
});
|
|
18520
18660
|
}
|
|
18521
18661
|
async replaceInFile(sandboxName, input) {
|
|
@@ -18524,14 +18664,14 @@ var MicrosandboxServiceClient = class {
|
|
|
18524
18664
|
body: { sandboxName, ...input }
|
|
18525
18665
|
});
|
|
18526
18666
|
}
|
|
18527
|
-
async uploadFile(sandboxName,
|
|
18667
|
+
async uploadFile(sandboxName, path4, content) {
|
|
18528
18668
|
return this.request("/api/files/upload", {
|
|
18529
18669
|
method: "POST",
|
|
18530
|
-
body: { sandboxName, path:
|
|
18670
|
+
body: { sandboxName, path: path4, contentBase64: content.toString("base64") }
|
|
18531
18671
|
});
|
|
18532
18672
|
}
|
|
18533
|
-
async downloadFile(sandboxName,
|
|
18534
|
-
const query = new URLSearchParams({ sandboxName, path:
|
|
18673
|
+
async downloadFile(sandboxName, path4) {
|
|
18674
|
+
const query = new URLSearchParams({ sandboxName, path: path4 });
|
|
18535
18675
|
return this.request(`/api/files/download?${query.toString()}`, {
|
|
18536
18676
|
method: "GET"
|
|
18537
18677
|
});
|
|
@@ -18542,33 +18682,109 @@ var MicrosandboxServiceClient = class {
|
|
|
18542
18682
|
body: input
|
|
18543
18683
|
});
|
|
18544
18684
|
}
|
|
18545
|
-
async
|
|
18546
|
-
const
|
|
18685
|
+
async volumeFsRead(volumeName, path4) {
|
|
18686
|
+
const result = await this.request(
|
|
18687
|
+
`/api/volumes/${encodeURIComponent(volumeName)}/fs/read`,
|
|
18688
|
+
{
|
|
18689
|
+
method: "POST",
|
|
18690
|
+
body: { path: path4 }
|
|
18691
|
+
}
|
|
18692
|
+
);
|
|
18693
|
+
return result.content;
|
|
18694
|
+
}
|
|
18695
|
+
async volumeFsWrite(volumeName, path4, content) {
|
|
18696
|
+
await this.request(
|
|
18697
|
+
`/api/volumes/${encodeURIComponent(volumeName)}/fs/write`,
|
|
18698
|
+
{
|
|
18699
|
+
method: "POST",
|
|
18700
|
+
body: { path: path4, content }
|
|
18701
|
+
}
|
|
18702
|
+
);
|
|
18703
|
+
}
|
|
18704
|
+
async volumeFsList(volumeName, path4) {
|
|
18705
|
+
const result = await this.request(
|
|
18706
|
+
`/api/volumes/${encodeURIComponent(volumeName)}/fs/list`,
|
|
18707
|
+
{
|
|
18708
|
+
method: "POST",
|
|
18709
|
+
body: { path: path4 }
|
|
18710
|
+
}
|
|
18711
|
+
);
|
|
18712
|
+
return result.entries;
|
|
18713
|
+
}
|
|
18714
|
+
async volumeFsDownload(volumeName, path4) {
|
|
18715
|
+
const result = await this.request(
|
|
18716
|
+
`/api/volumes/${encodeURIComponent(volumeName)}/fs/download?path=${encodeURIComponent(path4)}`,
|
|
18717
|
+
{
|
|
18718
|
+
method: "GET"
|
|
18719
|
+
}
|
|
18720
|
+
);
|
|
18721
|
+
return Buffer.from(result.contentBase64, "base64");
|
|
18722
|
+
}
|
|
18723
|
+
async volumeFsUpload(volumeName, path4, data) {
|
|
18724
|
+
await this.request(
|
|
18725
|
+
`/api/volumes/${encodeURIComponent(volumeName)}/fs/upload`,
|
|
18726
|
+
{
|
|
18727
|
+
method: "POST",
|
|
18728
|
+
body: { path: path4, contentBase64: data.toString("base64") }
|
|
18729
|
+
}
|
|
18730
|
+
);
|
|
18731
|
+
}
|
|
18732
|
+
async request(path4, init) {
|
|
18733
|
+
const headers = {};
|
|
18734
|
+
if (init.body) {
|
|
18735
|
+
headers["content-type"] = "application/json";
|
|
18736
|
+
}
|
|
18737
|
+
if (this.apiKey) {
|
|
18738
|
+
headers.Authorization = `Bearer ${this.apiKey}`;
|
|
18739
|
+
}
|
|
18740
|
+
const response = await fetch(`${this.baseURL}${path4}`, {
|
|
18547
18741
|
method: init.method,
|
|
18548
|
-
headers:
|
|
18742
|
+
headers: Object.keys(headers).length > 0 ? headers : void 0,
|
|
18549
18743
|
body: init.body ? JSON.stringify(init.body) : void 0
|
|
18550
18744
|
});
|
|
18551
18745
|
if (!response.ok) {
|
|
18552
18746
|
throw new Error(`Microsandbox service request failed: ${response.status} ${response.statusText}`);
|
|
18553
18747
|
}
|
|
18554
18748
|
const payload = await response.json();
|
|
18749
|
+
if (payload?.success === false) {
|
|
18750
|
+
throw new Error(`Microsandbox service request failed: ${payload.error ?? "unsuccessful response envelope"}`);
|
|
18751
|
+
}
|
|
18752
|
+
if (payload?.success !== true || !("data" in payload)) {
|
|
18753
|
+
throw new Error("Microsandbox service returned an invalid success envelope");
|
|
18754
|
+
}
|
|
18555
18755
|
return payload.data;
|
|
18556
18756
|
}
|
|
18557
18757
|
};
|
|
18558
18758
|
|
|
18559
18759
|
// src/sandbox_lattice/providers/MicrosandboxRemoteProvider.ts
|
|
18560
|
-
|
|
18561
|
-
|
|
18562
|
-
|
|
18563
|
-
|
|
18564
|
-
}
|
|
18760
|
+
function parseOptionalNumberEnv(name, fallback) {
|
|
18761
|
+
const rawValue = process.env[name];
|
|
18762
|
+
if (rawValue === void 0) {
|
|
18763
|
+
return fallback;
|
|
18764
|
+
}
|
|
18765
|
+
const parsedValue = Number(rawValue);
|
|
18766
|
+
if (!Number.isFinite(parsedValue)) {
|
|
18767
|
+
throw new Error(`Invalid ${name} environment value: ${rawValue}`);
|
|
18768
|
+
}
|
|
18769
|
+
return parsedValue;
|
|
18770
|
+
}
|
|
18771
|
+
function getDefaultMicrosandboxRemoteConfig() {
|
|
18772
|
+
return {
|
|
18773
|
+
image: process.env.MICROSANDBOX_IMAGE ?? "daytona-cn-shanghai.cr.volces.com/daytona/sandbox:0.0.2",
|
|
18774
|
+
//"daytonaio/sandbox:0.6.0",
|
|
18775
|
+
cpus: parseOptionalNumberEnv("MICROSANDBOX_CPUS", 1),
|
|
18776
|
+
memoryMib: parseOptionalNumberEnv("MICROSANDBOX_MEMORY", 512),
|
|
18777
|
+
user: "root"
|
|
18778
|
+
};
|
|
18779
|
+
}
|
|
18565
18780
|
var MicrosandboxRemoteProvider = class {
|
|
18566
18781
|
constructor(config) {
|
|
18567
18782
|
this.config = config;
|
|
18568
18783
|
this.instances = /* @__PURE__ */ new Map();
|
|
18569
18784
|
this.creating = /* @__PURE__ */ new Map();
|
|
18570
18785
|
this.client = config.client ?? new MicrosandboxServiceClient({
|
|
18571
|
-
baseURL: config.baseURL
|
|
18786
|
+
baseURL: config.baseURL,
|
|
18787
|
+
apiKey: config.apiKey ?? process.env.MICROSANDBOX_API_KEY
|
|
18572
18788
|
});
|
|
18573
18789
|
}
|
|
18574
18790
|
async createSandbox(name, config) {
|
|
@@ -18587,9 +18803,14 @@ var MicrosandboxRemoteProvider = class {
|
|
|
18587
18803
|
return instance;
|
|
18588
18804
|
})();
|
|
18589
18805
|
this.creating.set(name, creation);
|
|
18590
|
-
creation.
|
|
18591
|
-
|
|
18592
|
-
|
|
18806
|
+
creation.then(
|
|
18807
|
+
() => {
|
|
18808
|
+
this.creating.delete(name);
|
|
18809
|
+
},
|
|
18810
|
+
() => {
|
|
18811
|
+
this.creating.delete(name);
|
|
18812
|
+
}
|
|
18813
|
+
);
|
|
18593
18814
|
return creation;
|
|
18594
18815
|
}
|
|
18595
18816
|
async getSandbox(name) {
|
|
@@ -18607,37 +18828,49 @@ var MicrosandboxRemoteProvider = class {
|
|
|
18607
18828
|
await this.client.deleteSandbox(name);
|
|
18608
18829
|
this.instances.delete(name);
|
|
18609
18830
|
}
|
|
18831
|
+
createVolumeFsClient(volumeName) {
|
|
18832
|
+
return {
|
|
18833
|
+
read: (path4) => this.client.volumeFsRead(volumeName, path4),
|
|
18834
|
+
write: (path4, content) => this.client.volumeFsWrite(volumeName, path4, content),
|
|
18835
|
+
list: (path4) => this.client.volumeFsList(volumeName, path4),
|
|
18836
|
+
readRaw: (path4) => this.client.volumeFsDownload(volumeName, path4),
|
|
18837
|
+
writeRaw: (path4, data) => this.client.volumeFsUpload(volumeName, path4, data)
|
|
18838
|
+
};
|
|
18839
|
+
}
|
|
18610
18840
|
async listSandboxes() {
|
|
18611
18841
|
return Array.from(this.instances.values());
|
|
18612
18842
|
}
|
|
18613
18843
|
buildEnsureInput(config) {
|
|
18844
|
+
const defaultMicrosandboxRemoteConfig = getDefaultMicrosandboxRemoteConfig();
|
|
18614
18845
|
return {
|
|
18615
18846
|
image: this.config.image ?? defaultMicrosandboxRemoteConfig.image,
|
|
18616
18847
|
cpus: this.config.cpus ?? defaultMicrosandboxRemoteConfig.cpus,
|
|
18617
18848
|
memoryMib: this.config.memoryMib ?? defaultMicrosandboxRemoteConfig.memoryMib,
|
|
18618
|
-
env:
|
|
18849
|
+
env: {
|
|
18850
|
+
...this.config.env,
|
|
18851
|
+
...buildSandboxMetadataEnv(config)
|
|
18852
|
+
},
|
|
18619
18853
|
volumes: config?.volumes ?? this.buildDefaultVolumes(config)
|
|
18620
18854
|
};
|
|
18621
18855
|
}
|
|
18622
18856
|
buildDefaultVolumes(config) {
|
|
18623
18857
|
const tenantId = config?.tenantId ?? "default";
|
|
18624
18858
|
const volumes = {
|
|
18625
|
-
"/home/
|
|
18859
|
+
"/home/daytona/.agents/skills": {
|
|
18626
18860
|
type: "named",
|
|
18627
|
-
name:
|
|
18861
|
+
name: buildNamedVolumeName("s", "skills", tenantId)
|
|
18628
18862
|
}
|
|
18629
18863
|
};
|
|
18630
18864
|
if (config?.assistant_id) {
|
|
18631
|
-
volumes["/home/
|
|
18865
|
+
volumes["/home/daytona/agent"] = {
|
|
18632
18866
|
type: "named",
|
|
18633
|
-
name:
|
|
18867
|
+
name: buildNamedVolumeName("a", "agent", tenantId, config.assistant_id)
|
|
18634
18868
|
};
|
|
18635
18869
|
}
|
|
18636
18870
|
if (config?.projectId) {
|
|
18637
|
-
|
|
18638
|
-
volumes["/home/microsandbox/project"] = {
|
|
18871
|
+
volumes["/home/daytona/project"] = {
|
|
18639
18872
|
type: "named",
|
|
18640
|
-
name:
|
|
18873
|
+
name: buildNamedVolumeName("p", "project", tenantId, config.workspaceId, config.projectId)
|
|
18641
18874
|
};
|
|
18642
18875
|
}
|
|
18643
18876
|
return volumes;
|
|
@@ -18665,9 +18898,9 @@ var RemoteSandboxInstance = class {
|
|
|
18665
18898
|
throw new Error(String(result.error));
|
|
18666
18899
|
}
|
|
18667
18900
|
},
|
|
18668
|
-
listPath: async (
|
|
18901
|
+
listPath: async (path4, options) => {
|
|
18669
18902
|
const result = await this.client.file.listPath({
|
|
18670
|
-
path:
|
|
18903
|
+
path: path4,
|
|
18671
18904
|
recursive: options?.recursive ?? false
|
|
18672
18905
|
});
|
|
18673
18906
|
if (!result.ok) {
|
|
@@ -18681,8 +18914,8 @@ var RemoteSandboxInstance = class {
|
|
|
18681
18914
|
}));
|
|
18682
18915
|
return { files };
|
|
18683
18916
|
},
|
|
18684
|
-
findFiles: async (
|
|
18685
|
-
const result = await this.client.file.findFiles({ path:
|
|
18917
|
+
findFiles: async (path4, glob) => {
|
|
18918
|
+
const result = await this.client.file.findFiles({ path: path4, glob });
|
|
18686
18919
|
if (!result.ok) {
|
|
18687
18920
|
throw new Error(String(result.error));
|
|
18688
18921
|
}
|
|
@@ -18819,8 +19052,8 @@ var E2BInstance = class {
|
|
|
18819
19052
|
writeFile: async (file, content) => {
|
|
18820
19053
|
await this.native.files.write(file, content);
|
|
18821
19054
|
},
|
|
18822
|
-
listPath: async (
|
|
18823
|
-
const entries = await this.native.files.list(
|
|
19055
|
+
listPath: async (path4, options) => {
|
|
19056
|
+
const entries = await this.native.files.list(path4);
|
|
18824
19057
|
const files = entries.map((e) => ({
|
|
18825
19058
|
path: e.path,
|
|
18826
19059
|
is_dir: e.type === "dir",
|
|
@@ -18829,9 +19062,9 @@ var E2BInstance = class {
|
|
|
18829
19062
|
}));
|
|
18830
19063
|
return { files };
|
|
18831
19064
|
},
|
|
18832
|
-
findFiles: async (
|
|
19065
|
+
findFiles: async (path4, glob) => {
|
|
18833
19066
|
const result = await this.native.commands.run(
|
|
18834
|
-
`find "${
|
|
19067
|
+
`find "${path4}" -name "${glob}" -type f`
|
|
18835
19068
|
);
|
|
18836
19069
|
const lines = result.stdout.split("\n").filter(Boolean);
|
|
18837
19070
|
return { files: lines };
|
|
@@ -18854,13 +19087,13 @@ var E2BInstance = class {
|
|
|
18854
19087
|
return { matches, line_numbers };
|
|
18855
19088
|
},
|
|
18856
19089
|
strReplaceEditor: async (params) => {
|
|
18857
|
-
const { path:
|
|
19090
|
+
const { path: path4, old_str, new_str, replace_mode } = params;
|
|
18858
19091
|
const delim = "#";
|
|
18859
19092
|
const escapedOld = old_str.replace(new RegExp(`[\\\\${delim}]`, "g"), "\\$&").replace(/\n/g, "\\n");
|
|
18860
19093
|
const escapedNew = new_str.replace(new RegExp(`[\\\\${delim}]`, "g"), "\\$&").replace(/\n/g, "\\n");
|
|
18861
19094
|
const flag = replace_mode === "ALL" ? "g" : "";
|
|
18862
19095
|
await this.native.commands.run(
|
|
18863
|
-
`sed -i 's${delim}${escapedOld}${delim}${escapedNew}${delim}${flag}' "${
|
|
19096
|
+
`sed -i 's${delim}${escapedOld}${delim}${escapedNew}${delim}${flag}' "${path4}"`
|
|
18864
19097
|
);
|
|
18865
19098
|
},
|
|
18866
19099
|
uploadFile: async (params) => {
|
|
@@ -18976,26 +19209,18 @@ var DaytonaInstance = class {
|
|
|
18976
19209
|
this.native = native;
|
|
18977
19210
|
this.file = {
|
|
18978
19211
|
readFile: async (file) => {
|
|
18979
|
-
const buffer2 = await this.native.fs.downloadFile(
|
|
19212
|
+
const buffer2 = await this.native.fs.downloadFile(toSandboxRelativePath(file));
|
|
18980
19213
|
return { content: buffer2.toString("utf-8") };
|
|
18981
19214
|
},
|
|
18982
19215
|
writeFile: async (file, content) => {
|
|
18983
|
-
await this.native.fs.uploadFile(Buffer.from(content, "utf-8"),
|
|
19216
|
+
await this.native.fs.uploadFile(Buffer.from(content, "utf-8"), toSandboxRelativePath(file));
|
|
18984
19217
|
},
|
|
18985
|
-
listPath: async (
|
|
18986
|
-
const entries = await this.native.fs.listFiles(
|
|
19218
|
+
listPath: async (path4, options) => {
|
|
19219
|
+
const entries = await this.native.fs.listFiles(toSandboxRelativePath(path4));
|
|
18987
19220
|
const files = entries.map((e) => {
|
|
18988
|
-
|
|
18989
|
-
while (name.startsWith("~/") || name.startsWith("/")) {
|
|
18990
|
-
if (name.startsWith("~/")) {
|
|
18991
|
-
name = name.slice(2);
|
|
18992
|
-
} else if (name.startsWith("/")) {
|
|
18993
|
-
name = name.slice(1);
|
|
18994
|
-
}
|
|
18995
|
-
}
|
|
18996
|
-
const fullPath = name ? `${path3}/${name}`.replace(/\/+/g, "/") : path3;
|
|
19221
|
+
const rawPath = e.name || "";
|
|
18997
19222
|
return {
|
|
18998
|
-
path:
|
|
19223
|
+
path: fromSandboxExecutionPath(rawPath),
|
|
18999
19224
|
is_dir: e.isDir ?? false,
|
|
19000
19225
|
size: e.size,
|
|
19001
19226
|
modified_at: e.modTime ? e.modTime : void 0
|
|
@@ -19003,12 +19228,12 @@ var DaytonaInstance = class {
|
|
|
19003
19228
|
});
|
|
19004
19229
|
return { files };
|
|
19005
19230
|
},
|
|
19006
|
-
findFiles: async (
|
|
19007
|
-
const result = await this.native.fs.searchFiles(
|
|
19008
|
-
return { files: result.files || [] };
|
|
19231
|
+
findFiles: async (path4, glob) => {
|
|
19232
|
+
const result = await this.native.fs.searchFiles(toSandboxRelativePath(path4), glob);
|
|
19233
|
+
return { files: (result.files || []).map((filePath) => fromSandboxExecutionPath(filePath)) };
|
|
19009
19234
|
},
|
|
19010
19235
|
searchInFile: async (file, regex) => {
|
|
19011
|
-
const matches = await this.native.fs.findFiles(
|
|
19236
|
+
const matches = await this.native.fs.findFiles(toSandboxRelativePath(file), regex);
|
|
19012
19237
|
const line_numbers = [];
|
|
19013
19238
|
const matchTexts = [];
|
|
19014
19239
|
for (const match of matches) {
|
|
@@ -19018,8 +19243,8 @@ var DaytonaInstance = class {
|
|
|
19018
19243
|
return { matches: matchTexts, line_numbers };
|
|
19019
19244
|
},
|
|
19020
19245
|
strReplaceEditor: async (params) => {
|
|
19021
|
-
const { path:
|
|
19022
|
-
const relPath =
|
|
19246
|
+
const { path: path4, old_str, new_str, replace_mode } = params;
|
|
19247
|
+
const relPath = toSandboxRelativePath(path4);
|
|
19023
19248
|
if (replace_mode === "ALL") {
|
|
19024
19249
|
await this.native.fs.replaceInFiles([relPath], old_str, new_str);
|
|
19025
19250
|
} else {
|
|
@@ -19033,10 +19258,10 @@ var DaytonaInstance = class {
|
|
|
19033
19258
|
}
|
|
19034
19259
|
},
|
|
19035
19260
|
uploadFile: async (params) => {
|
|
19036
|
-
await this.native.fs.uploadFile(params.data,
|
|
19261
|
+
await this.native.fs.uploadFile(params.data, toSandboxRelativePath(params.file));
|
|
19037
19262
|
},
|
|
19038
19263
|
downloadFile: async (params) => {
|
|
19039
|
-
const buffer2 = await this.native.fs.downloadFile(
|
|
19264
|
+
const buffer2 = await this.native.fs.downloadFile(toSandboxRelativePath(params.file));
|
|
19040
19265
|
return Buffer.isBuffer(buffer2) ? buffer2 : Buffer.from(buffer2);
|
|
19041
19266
|
}
|
|
19042
19267
|
};
|
|
@@ -19057,25 +19282,6 @@ var DaytonaInstance = class {
|
|
|
19057
19282
|
};
|
|
19058
19283
|
this.name = name;
|
|
19059
19284
|
}
|
|
19060
|
-
/**
|
|
19061
|
-
* All sandbox file operations live under the user's home directory (~).
|
|
19062
|
-
* The AI uses virtual paths like "~/agent/file.txt". Daytona SDK expects
|
|
19063
|
-
* relative paths for file operations (they are resolved against ~ automatically),
|
|
19064
|
-
* so we strip the leading "~/" or "/" here.
|
|
19065
|
-
*
|
|
19066
|
-
* Handles edge cases like "~/~/agent/file.txt" by repeatedly stripping prefixes.
|
|
19067
|
-
*/
|
|
19068
|
-
toSandboxHomePath(path3) {
|
|
19069
|
-
let result = path3;
|
|
19070
|
-
while (result.startsWith("~/") || result.startsWith("/")) {
|
|
19071
|
-
if (result.startsWith("~/")) {
|
|
19072
|
-
result = result.slice(2);
|
|
19073
|
-
} else if (result.startsWith("/")) {
|
|
19074
|
-
result = result.slice(1);
|
|
19075
|
-
}
|
|
19076
|
-
}
|
|
19077
|
-
return result;
|
|
19078
|
-
}
|
|
19079
19285
|
async start() {
|
|
19080
19286
|
await this.native.start();
|
|
19081
19287
|
}
|
|
@@ -19417,7 +19623,6 @@ function clearEncryptionKeyCache() {
|
|
|
19417
19623
|
0 && (module.exports = {
|
|
19418
19624
|
AGENT_TASK_EVENT,
|
|
19419
19625
|
Agent,
|
|
19420
|
-
AgentConfig,
|
|
19421
19626
|
AgentInstanceManager,
|
|
19422
19627
|
AgentLatticeManager,
|
|
19423
19628
|
AgentManager,
|
|
@@ -19436,7 +19641,6 @@ function clearEncryptionKeyCache() {
|
|
|
19436
19641
|
EmbeddingsLatticeManager,
|
|
19437
19642
|
FileSystemSkillStore,
|
|
19438
19643
|
FilesystemBackend,
|
|
19439
|
-
GraphBuildOptions,
|
|
19440
19644
|
HumanMessage,
|
|
19441
19645
|
InMemoryAssistantStore,
|
|
19442
19646
|
InMemoryChunkBuffer,
|
|
@@ -19490,9 +19694,12 @@ function clearEncryptionKeyCache() {
|
|
|
19490
19694
|
ThreadStatus,
|
|
19491
19695
|
ToolLatticeManager,
|
|
19492
19696
|
VectorStoreLatticeManager,
|
|
19697
|
+
VolumeFilesystem,
|
|
19493
19698
|
agentInstanceManager,
|
|
19494
19699
|
agentLatticeManager,
|
|
19495
19700
|
buildGrepResultsDict,
|
|
19701
|
+
buildNamedVolumeName,
|
|
19702
|
+
buildSandboxMetadataEnv,
|
|
19496
19703
|
buildSkillFile,
|
|
19497
19704
|
checkEmptyContent,
|
|
19498
19705
|
clearEncryptionKeyCache,
|