@axiom-lattice/core 2.1.73 → 2.1.75
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 +33 -6
- package/dist/index.d.ts +33 -6
- package/dist/index.js +398 -39
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +396 -39
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.mjs
CHANGED
|
@@ -3059,6 +3059,168 @@ var PostgresDatabase = class {
|
|
|
3059
3059
|
}
|
|
3060
3060
|
}
|
|
3061
3061
|
};
|
|
3062
|
+
var MysqlDatabase = class {
|
|
3063
|
+
constructor(config) {
|
|
3064
|
+
// mysql2.Pool
|
|
3065
|
+
this.connected = false;
|
|
3066
|
+
this.config = config;
|
|
3067
|
+
}
|
|
3068
|
+
async connect() {
|
|
3069
|
+
if (this.connected && this.pool) return;
|
|
3070
|
+
try {
|
|
3071
|
+
const mysql = await import("mysql2/promise");
|
|
3072
|
+
const poolConfig = this.config.connectionString ? { uri: this.config.connectionString } : {
|
|
3073
|
+
host: this.config.host || "localhost",
|
|
3074
|
+
port: this.config.port || 3306,
|
|
3075
|
+
database: this.config.database,
|
|
3076
|
+
user: this.config.user,
|
|
3077
|
+
password: this.config.password,
|
|
3078
|
+
ssl: this.config.ssl ? { rejectUnauthorized: false } : void 0
|
|
3079
|
+
};
|
|
3080
|
+
this.pool = mysql.createPool({
|
|
3081
|
+
...poolConfig,
|
|
3082
|
+
waitForConnections: true,
|
|
3083
|
+
connectionLimit: 10,
|
|
3084
|
+
maxIdle: 10,
|
|
3085
|
+
idleTimeout: 6e4,
|
|
3086
|
+
queueLimit: 0,
|
|
3087
|
+
enableKeepAlive: true,
|
|
3088
|
+
keepAliveInitialDelay: 0
|
|
3089
|
+
});
|
|
3090
|
+
const connection = await this.pool.getConnection();
|
|
3091
|
+
try {
|
|
3092
|
+
await connection.query("SELECT 1");
|
|
3093
|
+
} finally {
|
|
3094
|
+
connection.release();
|
|
3095
|
+
}
|
|
3096
|
+
this.connected = true;
|
|
3097
|
+
} catch (error) {
|
|
3098
|
+
this.connected = false;
|
|
3099
|
+
throw new Error(`Failed to connect to MySQL: ${error}`);
|
|
3100
|
+
}
|
|
3101
|
+
}
|
|
3102
|
+
async disconnect() {
|
|
3103
|
+
if (this.pool) {
|
|
3104
|
+
try {
|
|
3105
|
+
await this.pool.end();
|
|
3106
|
+
} catch (error) {
|
|
3107
|
+
console.warn("Warning: Error closing MySQL pool:", error);
|
|
3108
|
+
} finally {
|
|
3109
|
+
this.pool = null;
|
|
3110
|
+
this.connected = false;
|
|
3111
|
+
}
|
|
3112
|
+
}
|
|
3113
|
+
}
|
|
3114
|
+
async listTables() {
|
|
3115
|
+
await this.ensureConnected();
|
|
3116
|
+
const query = `
|
|
3117
|
+
SELECT TABLE_NAME, TABLE_SCHEMA
|
|
3118
|
+
FROM information_schema.TABLES
|
|
3119
|
+
WHERE TABLE_SCHEMA NOT IN ('mysql', 'information_schema', 'performance_schema', 'sys')
|
|
3120
|
+
AND TABLE_SCHEMA = DATABASE()
|
|
3121
|
+
AND TABLE_TYPE = 'BASE TABLE'
|
|
3122
|
+
ORDER BY TABLE_SCHEMA, TABLE_NAME
|
|
3123
|
+
`;
|
|
3124
|
+
const [rows] = await this.pool.query(query);
|
|
3125
|
+
return rows.map((row) => ({
|
|
3126
|
+
name: row.TABLE_NAME,
|
|
3127
|
+
schema: row.TABLE_SCHEMA
|
|
3128
|
+
}));
|
|
3129
|
+
}
|
|
3130
|
+
async getTableInfo(tables) {
|
|
3131
|
+
await this.ensureConnected();
|
|
3132
|
+
const schemas = [];
|
|
3133
|
+
for (const tableName of tables) {
|
|
3134
|
+
const rawName = tableName.includes(".") ? tableName.split(".").pop() : tableName;
|
|
3135
|
+
const columnQuery = `
|
|
3136
|
+
SELECT
|
|
3137
|
+
c.COLUMN_NAME,
|
|
3138
|
+
c.DATA_TYPE,
|
|
3139
|
+
c.IS_NULLABLE,
|
|
3140
|
+
c.COLUMN_DEFAULT
|
|
3141
|
+
FROM information_schema.COLUMNS c
|
|
3142
|
+
WHERE c.TABLE_NAME = ?
|
|
3143
|
+
AND c.TABLE_SCHEMA = DATABASE()
|
|
3144
|
+
ORDER BY c.ORDINAL_POSITION
|
|
3145
|
+
`;
|
|
3146
|
+
const pkQuery = `
|
|
3147
|
+
SELECT k.COLUMN_NAME
|
|
3148
|
+
FROM information_schema.TABLE_CONSTRAINTS t
|
|
3149
|
+
JOIN information_schema.KEY_COLUMN_USAGE k
|
|
3150
|
+
ON t.CONSTRAINT_NAME = k.CONSTRAINT_NAME
|
|
3151
|
+
AND t.TABLE_SCHEMA = k.TABLE_SCHEMA
|
|
3152
|
+
AND t.TABLE_NAME = k.TABLE_NAME
|
|
3153
|
+
WHERE t.CONSTRAINT_TYPE = 'PRIMARY KEY'
|
|
3154
|
+
AND t.TABLE_NAME = ?
|
|
3155
|
+
AND t.TABLE_SCHEMA = DATABASE()
|
|
3156
|
+
`;
|
|
3157
|
+
const fkQuery = `
|
|
3158
|
+
SELECT
|
|
3159
|
+
k.COLUMN_NAME,
|
|
3160
|
+
k.REFERENCED_TABLE_NAME,
|
|
3161
|
+
k.REFERENCED_COLUMN_NAME
|
|
3162
|
+
FROM information_schema.KEY_COLUMN_USAGE k
|
|
3163
|
+
WHERE k.TABLE_NAME = ?
|
|
3164
|
+
AND k.TABLE_SCHEMA = DATABASE()
|
|
3165
|
+
AND k.REFERENCED_TABLE_NAME IS NOT NULL
|
|
3166
|
+
`;
|
|
3167
|
+
const [columnRows] = await this.pool.query(columnQuery, [rawName]);
|
|
3168
|
+
const [pkRows] = await this.pool.query(pkQuery, [rawName]);
|
|
3169
|
+
const [fkRows] = await this.pool.query(fkQuery, [rawName]);
|
|
3170
|
+
const pkColumns = new Set(pkRows.map((r) => r.COLUMN_NAME));
|
|
3171
|
+
const fkMap = /* @__PURE__ */ new Map();
|
|
3172
|
+
for (const row of fkRows) {
|
|
3173
|
+
fkMap.set(row.COLUMN_NAME, {
|
|
3174
|
+
foreignTable: row.REFERENCED_TABLE_NAME,
|
|
3175
|
+
foreignColumn: row.REFERENCED_COLUMN_NAME
|
|
3176
|
+
});
|
|
3177
|
+
}
|
|
3178
|
+
const columns = columnRows.map((row) => {
|
|
3179
|
+
const fkRef = fkMap.get(row.COLUMN_NAME);
|
|
3180
|
+
return {
|
|
3181
|
+
name: row.COLUMN_NAME,
|
|
3182
|
+
type: row.DATA_TYPE,
|
|
3183
|
+
nullable: row.IS_NULLABLE === "YES",
|
|
3184
|
+
default: row.COLUMN_DEFAULT,
|
|
3185
|
+
isPrimaryKey: pkColumns.has(row.COLUMN_NAME),
|
|
3186
|
+
isForeignKey: fkRef !== void 0,
|
|
3187
|
+
foreignKeyRef: fkRef ? `${fkRef.foreignTable}.${fkRef.foreignColumn}` : void 0
|
|
3188
|
+
};
|
|
3189
|
+
});
|
|
3190
|
+
let sampleRows = [];
|
|
3191
|
+
try {
|
|
3192
|
+
const sampleQuery = `SELECT * FROM \`${rawName}\` LIMIT 3`;
|
|
3193
|
+
const [sampleResult] = await this.pool.query(sampleQuery);
|
|
3194
|
+
sampleRows = sampleResult;
|
|
3195
|
+
} catch {
|
|
3196
|
+
}
|
|
3197
|
+
schemas.push({
|
|
3198
|
+
tableName,
|
|
3199
|
+
columns,
|
|
3200
|
+
sampleRows
|
|
3201
|
+
});
|
|
3202
|
+
}
|
|
3203
|
+
return schemas;
|
|
3204
|
+
}
|
|
3205
|
+
async executeQuery(query) {
|
|
3206
|
+
await this.ensureConnected();
|
|
3207
|
+
const [rows, fields] = await this.pool.query(query);
|
|
3208
|
+
const isSelectResult = Array.isArray(rows);
|
|
3209
|
+
return {
|
|
3210
|
+
rows: isSelectResult ? rows : [],
|
|
3211
|
+
rowCount: isSelectResult ? rows.length : rows.affectedRows || 0,
|
|
3212
|
+
fields: fields?.map((f) => f.name)
|
|
3213
|
+
};
|
|
3214
|
+
}
|
|
3215
|
+
getDatabaseType() {
|
|
3216
|
+
return "mysql";
|
|
3217
|
+
}
|
|
3218
|
+
async ensureConnected() {
|
|
3219
|
+
if (!this.connected) {
|
|
3220
|
+
await this.connect();
|
|
3221
|
+
}
|
|
3222
|
+
}
|
|
3223
|
+
};
|
|
3062
3224
|
var SqlDatabaseManager = class _SqlDatabaseManager {
|
|
3063
3225
|
constructor() {
|
|
3064
3226
|
this.databases = /* @__PURE__ */ new Map();
|
|
@@ -3098,7 +3260,8 @@ var SqlDatabaseManager = class _SqlDatabaseManager {
|
|
|
3098
3260
|
database = new PostgresDatabase(config);
|
|
3099
3261
|
break;
|
|
3100
3262
|
case "mysql":
|
|
3101
|
-
|
|
3263
|
+
database = new MysqlDatabase(config);
|
|
3264
|
+
break;
|
|
3102
3265
|
case "sqlite":
|
|
3103
3266
|
throw new Error("SQLite support not yet implemented");
|
|
3104
3267
|
default:
|
|
@@ -5633,7 +5796,7 @@ var SandboxLatticeManager = class _SandboxLatticeManager extends BaseLatticeMana
|
|
|
5633
5796
|
const tenantId = config.tenantId ?? "default";
|
|
5634
5797
|
const mapping = this._resolveVolumeForPath(config, tenantId, filePath);
|
|
5635
5798
|
if (!mapping) return null;
|
|
5636
|
-
const client = provider.createVolumeFsClient(mapping.volumeName);
|
|
5799
|
+
const client = provider.createVolumeFsClient(mapping.volumeName, mapping.pathPrefix);
|
|
5637
5800
|
return new VolumeFilesystem(stripPrefixClient(client, mapping.pathPrefix), mapping.pathPrefix);
|
|
5638
5801
|
}
|
|
5639
5802
|
_resolveVolumeForPath(config, tenantId, filePath) {
|
|
@@ -18059,9 +18222,7 @@ ${body}` : `${frontmatter}
|
|
|
18059
18222
|
} catch (listError) {
|
|
18060
18223
|
console.log(`[SandboxSkillStore] Skills directory not found, creating: ${skillsDir}`);
|
|
18061
18224
|
try {
|
|
18062
|
-
await sandbox.
|
|
18063
|
-
command: `mkdir -p /root/.agents/skills`
|
|
18064
|
-
});
|
|
18225
|
+
await sandbox.file.createDirectory(skillsDir);
|
|
18065
18226
|
} catch (mkdirError) {
|
|
18066
18227
|
console.error(`[SandboxSkillStore] Failed to create skills directory: ${mkdirError.message}`);
|
|
18067
18228
|
return [];
|
|
@@ -18202,12 +18363,7 @@ ${body}` : `${frontmatter}
|
|
|
18202
18363
|
try {
|
|
18203
18364
|
const sandbox = await this.getSandbox(tenantId, context);
|
|
18204
18365
|
const dirPath = this.getSkillDirectoryPath(tenantId, id);
|
|
18205
|
-
|
|
18206
|
-
command: `rm -rf ${dirPath}`
|
|
18207
|
-
});
|
|
18208
|
-
if (deleteResult.exit_code !== 0) {
|
|
18209
|
-
return false;
|
|
18210
|
-
}
|
|
18366
|
+
await sandbox.file.deletePath(dirPath);
|
|
18211
18367
|
return true;
|
|
18212
18368
|
} catch (error) {
|
|
18213
18369
|
console.error(`Error deleting skill ${id}:`, error);
|
|
@@ -21020,6 +21176,20 @@ var MicrosandboxRemoteInstance = class {
|
|
|
21020
21176
|
return Buffer.from(result.contentBase64, "base64");
|
|
21021
21177
|
}
|
|
21022
21178
|
return Buffer.from(result.content ?? "");
|
|
21179
|
+
},
|
|
21180
|
+
deletePath: async (path3) => {
|
|
21181
|
+
const resolved = normalizeExternalSandboxPath(path3);
|
|
21182
|
+
await this.client.execCommand({
|
|
21183
|
+
sandboxName: this.name,
|
|
21184
|
+
command: `rm -rf "${resolved}"`
|
|
21185
|
+
});
|
|
21186
|
+
},
|
|
21187
|
+
createDirectory: async (path3) => {
|
|
21188
|
+
const resolved = normalizeExternalSandboxPath(path3);
|
|
21189
|
+
await this.client.execCommand({
|
|
21190
|
+
sandboxName: this.name,
|
|
21191
|
+
command: `mkdir -p "${resolved}"`
|
|
21192
|
+
});
|
|
21023
21193
|
}
|
|
21024
21194
|
};
|
|
21025
21195
|
this.shell = {
|
|
@@ -21299,7 +21469,7 @@ var MicrosandboxRemoteProvider = class {
|
|
|
21299
21469
|
this.instances.delete(name);
|
|
21300
21470
|
await this.client.deleteSandbox(name);
|
|
21301
21471
|
}
|
|
21302
|
-
createVolumeFsClient(volumeName) {
|
|
21472
|
+
createVolumeFsClient(volumeName, _pathPrefix) {
|
|
21303
21473
|
return {
|
|
21304
21474
|
read: (path3) => this.client.volumeFsRead(volumeName, path3),
|
|
21305
21475
|
write: (path3, content) => this.client.volumeFsWrite(volumeName, path3, content),
|
|
@@ -21356,50 +21526,84 @@ var MicrosandboxRemoteProvider = class {
|
|
|
21356
21526
|
import { SandboxClient as SandboxClient23 } from "@agent-infra/sandbox";
|
|
21357
21527
|
|
|
21358
21528
|
// src/sandbox_lattice/RemoteSandboxInstance.ts
|
|
21529
|
+
function extractFetcherError(error) {
|
|
21530
|
+
if (typeof error === "string") {
|
|
21531
|
+
return error;
|
|
21532
|
+
}
|
|
21533
|
+
if (error && typeof error === "object") {
|
|
21534
|
+
const e = error;
|
|
21535
|
+
if (typeof e.reason === "string") {
|
|
21536
|
+
switch (e.reason) {
|
|
21537
|
+
case "status-code":
|
|
21538
|
+
return `HTTP ${e.statusCode}: ${JSON.stringify(e.body)}`;
|
|
21539
|
+
case "non-json":
|
|
21540
|
+
return `HTTP ${e.statusCode}: ${e.rawBody}`;
|
|
21541
|
+
case "timeout":
|
|
21542
|
+
return "Request timed out";
|
|
21543
|
+
case "unknown":
|
|
21544
|
+
return typeof e.errorMessage === "string" ? e.errorMessage : "Unknown error";
|
|
21545
|
+
}
|
|
21546
|
+
}
|
|
21547
|
+
if (typeof e.message === "string") {
|
|
21548
|
+
return e.message;
|
|
21549
|
+
}
|
|
21550
|
+
if (typeof e.error === "string") {
|
|
21551
|
+
return e.error;
|
|
21552
|
+
}
|
|
21553
|
+
return JSON.stringify(error);
|
|
21554
|
+
}
|
|
21555
|
+
return String(error);
|
|
21556
|
+
}
|
|
21359
21557
|
var RemoteSandboxInstance = class {
|
|
21360
|
-
constructor(name, client) {
|
|
21558
|
+
constructor(name, client, workspace) {
|
|
21361
21559
|
this.client = client;
|
|
21560
|
+
this.workspace = workspace;
|
|
21362
21561
|
this.file = {
|
|
21363
21562
|
readFile: async (file) => {
|
|
21364
|
-
const
|
|
21563
|
+
const resolved = this.resolvePath(file);
|
|
21564
|
+
const result = await this.client.file.readFile({ file: resolved });
|
|
21365
21565
|
if (!result.ok) {
|
|
21366
|
-
throw new Error(
|
|
21566
|
+
throw new Error(`readFile failed: ${extractFetcherError(result.error)}`);
|
|
21367
21567
|
}
|
|
21368
21568
|
return { content: result.body.data?.content ?? "" };
|
|
21369
21569
|
},
|
|
21370
21570
|
writeFile: async (file, content) => {
|
|
21371
|
-
const
|
|
21571
|
+
const resolved = this.resolvePath(file);
|
|
21572
|
+
const result = await this.client.file.writeFile({ file: resolved, content });
|
|
21372
21573
|
if (!result.ok) {
|
|
21373
|
-
throw new Error(
|
|
21574
|
+
throw new Error(`writeFile failed: ${extractFetcherError(result.error)}`);
|
|
21374
21575
|
}
|
|
21375
21576
|
},
|
|
21376
21577
|
listPath: async (path3, options) => {
|
|
21578
|
+
const resolved = this.resolvePath(path3);
|
|
21377
21579
|
const result = await this.client.file.listPath({
|
|
21378
|
-
path:
|
|
21580
|
+
path: resolved,
|
|
21379
21581
|
recursive: options?.recursive ?? false
|
|
21380
21582
|
});
|
|
21381
21583
|
if (!result.ok) {
|
|
21382
|
-
throw new Error(
|
|
21584
|
+
throw new Error(`listPath failed: ${extractFetcherError(result.error)}`);
|
|
21383
21585
|
}
|
|
21384
21586
|
const files = (result.body.data?.files || []).map((f) => ({
|
|
21385
21587
|
path: f.path,
|
|
21386
|
-
is_dir: f.is_dir
|
|
21387
|
-
size: f.size,
|
|
21588
|
+
is_dir: f.is_dir === true || f.size === null,
|
|
21589
|
+
size: f.size ?? void 0,
|
|
21388
21590
|
modified_at: f.modified_at
|
|
21389
21591
|
}));
|
|
21390
21592
|
return { files };
|
|
21391
21593
|
},
|
|
21392
21594
|
findFiles: async (path3, glob) => {
|
|
21393
|
-
const
|
|
21595
|
+
const resolved = this.resolvePath(path3);
|
|
21596
|
+
const result = await this.client.file.findFiles({ path: resolved, glob });
|
|
21394
21597
|
if (!result.ok) {
|
|
21395
|
-
throw new Error(
|
|
21598
|
+
throw new Error(`findFiles failed: ${extractFetcherError(result.error)}`);
|
|
21396
21599
|
}
|
|
21397
21600
|
return { files: result.body.data?.files || [] };
|
|
21398
21601
|
},
|
|
21399
21602
|
searchInFile: async (file, regex) => {
|
|
21400
|
-
const
|
|
21603
|
+
const resolved = this.resolvePath(file);
|
|
21604
|
+
const result = await this.client.file.searchInFile({ file: resolved, regex });
|
|
21401
21605
|
if (!result.ok) {
|
|
21402
|
-
throw new Error(
|
|
21606
|
+
throw new Error(`searchInFile failed: ${extractFetcherError(result.error)}`);
|
|
21403
21607
|
}
|
|
21404
21608
|
return {
|
|
21405
21609
|
matches: result.body.data?.matches || [],
|
|
@@ -21407,44 +21611,65 @@ var RemoteSandboxInstance = class {
|
|
|
21407
21611
|
};
|
|
21408
21612
|
},
|
|
21409
21613
|
strReplaceEditor: async (params) => {
|
|
21614
|
+
const resolved = this.resolvePath(params.path);
|
|
21410
21615
|
const result = await this.client.file.strReplaceEditor({
|
|
21411
21616
|
command: params.command,
|
|
21412
|
-
path:
|
|
21617
|
+
path: resolved,
|
|
21413
21618
|
old_str: params.old_str,
|
|
21414
21619
|
new_str: params.new_str,
|
|
21415
21620
|
replace_mode: params.replace_mode
|
|
21416
21621
|
});
|
|
21417
21622
|
if (!result.ok) {
|
|
21418
|
-
throw new Error(
|
|
21623
|
+
throw new Error(`strReplaceEditor failed: ${extractFetcherError(result.error)}`);
|
|
21419
21624
|
}
|
|
21420
21625
|
},
|
|
21421
21626
|
uploadFile: async (params) => {
|
|
21627
|
+
const resolved = this.resolvePath(params.file);
|
|
21422
21628
|
const result = await this.client.file.uploadFile({
|
|
21423
21629
|
file: params.data,
|
|
21424
|
-
path:
|
|
21630
|
+
path: resolved
|
|
21425
21631
|
});
|
|
21426
21632
|
if (!result.ok) {
|
|
21427
|
-
throw new Error(
|
|
21633
|
+
throw new Error(`uploadFile failed: ${extractFetcherError(result.error)}`);
|
|
21428
21634
|
}
|
|
21429
21635
|
},
|
|
21430
21636
|
downloadFile: async (params) => {
|
|
21431
|
-
const
|
|
21637
|
+
const resolved = this.resolvePath(params.file);
|
|
21638
|
+
const result = await this.client.file.downloadFile({ path: resolved });
|
|
21432
21639
|
if (!result.ok) {
|
|
21433
|
-
throw new Error(
|
|
21640
|
+
throw new Error(`downloadFile failed: ${extractFetcherError(result.error)}`);
|
|
21434
21641
|
}
|
|
21435
21642
|
const buffer2 = await result.body.arrayBuffer();
|
|
21436
21643
|
return Buffer.from(buffer2);
|
|
21644
|
+
},
|
|
21645
|
+
deletePath: async (path3) => {
|
|
21646
|
+
const resolved = this.resolvePath(path3);
|
|
21647
|
+
const result = await this.client.shell.execCommand({
|
|
21648
|
+
command: `rm -rf "${resolved}"`
|
|
21649
|
+
});
|
|
21650
|
+
if (!result.ok) {
|
|
21651
|
+
throw new Error(`deletePath failed: ${extractFetcherError(result.error)}`);
|
|
21652
|
+
}
|
|
21653
|
+
},
|
|
21654
|
+
createDirectory: async (path3) => {
|
|
21655
|
+
const resolved = this.resolvePath(path3);
|
|
21656
|
+
const result = await this.client.shell.execCommand({
|
|
21657
|
+
command: `mkdir -p "${resolved}"`
|
|
21658
|
+
});
|
|
21659
|
+
if (!result.ok) {
|
|
21660
|
+
throw new Error(`createDirectory failed: ${extractFetcherError(result.error)}`);
|
|
21661
|
+
}
|
|
21437
21662
|
}
|
|
21438
21663
|
};
|
|
21439
21664
|
this.shell = {
|
|
21440
21665
|
execCommand: async (params) => {
|
|
21441
21666
|
const result = await this.client.shell.execCommand({
|
|
21442
21667
|
command: params.command,
|
|
21443
|
-
exec_dir: params.exec_dir,
|
|
21668
|
+
exec_dir: params.exec_dir ? this.resolvePath(params.exec_dir) : void 0,
|
|
21444
21669
|
timeout: params.timeout
|
|
21445
21670
|
});
|
|
21446
21671
|
if (!result.ok) {
|
|
21447
|
-
throw new Error(
|
|
21672
|
+
throw new Error(`execCommand failed: ${extractFetcherError(result.error)}`);
|
|
21448
21673
|
}
|
|
21449
21674
|
return {
|
|
21450
21675
|
output: result.body.data?.output ?? "",
|
|
@@ -21454,6 +21679,15 @@ var RemoteSandboxInstance = class {
|
|
|
21454
21679
|
};
|
|
21455
21680
|
this.name = name;
|
|
21456
21681
|
}
|
|
21682
|
+
resolvePath(file) {
|
|
21683
|
+
if (file.startsWith(this.workspace)) {
|
|
21684
|
+
return file;
|
|
21685
|
+
}
|
|
21686
|
+
if (!file.startsWith("/")) {
|
|
21687
|
+
return `${this.workspace}/${file}`;
|
|
21688
|
+
}
|
|
21689
|
+
return `${this.workspace}${file}`;
|
|
21690
|
+
}
|
|
21457
21691
|
async start() {
|
|
21458
21692
|
}
|
|
21459
21693
|
async stop() {
|
|
@@ -21474,23 +21708,58 @@ var RemoteSandboxInstance = class {
|
|
|
21474
21708
|
};
|
|
21475
21709
|
|
|
21476
21710
|
// src/sandbox_lattice/providers/RemoteSandboxProvider.ts
|
|
21711
|
+
var DEFAULT_WORKSPACE = "/home/gem";
|
|
21477
21712
|
var RemoteSandboxProvider = class {
|
|
21478
21713
|
constructor(config) {
|
|
21479
21714
|
this.config = config;
|
|
21480
21715
|
this.instances = /* @__PURE__ */ new Map();
|
|
21716
|
+
this.creating = /* @__PURE__ */ new Map();
|
|
21717
|
+
this.workspace = DEFAULT_WORKSPACE;
|
|
21718
|
+
this.workspaceResolved = false;
|
|
21481
21719
|
this.client = new SandboxClient23({
|
|
21482
21720
|
baseUrl: config.baseURL,
|
|
21483
21721
|
environment: ""
|
|
21484
21722
|
});
|
|
21485
21723
|
}
|
|
21724
|
+
async resolveWorkspace() {
|
|
21725
|
+
if (this.workspaceResolved) {
|
|
21726
|
+
return this.workspace;
|
|
21727
|
+
}
|
|
21728
|
+
try {
|
|
21729
|
+
const result = await this.client.sandbox.getContext();
|
|
21730
|
+
if (result.ok && result.body.home_dir) {
|
|
21731
|
+
this.workspace = result.body.home_dir;
|
|
21732
|
+
}
|
|
21733
|
+
} catch {
|
|
21734
|
+
}
|
|
21735
|
+
this.workspaceResolved = true;
|
|
21736
|
+
return this.workspace;
|
|
21737
|
+
}
|
|
21486
21738
|
async createSandbox(name, _config) {
|
|
21487
21739
|
const existing = this.instances.get(name);
|
|
21488
21740
|
if (existing) {
|
|
21489
21741
|
return existing;
|
|
21490
21742
|
}
|
|
21491
|
-
const
|
|
21492
|
-
|
|
21493
|
-
|
|
21743
|
+
const inFlight = this.creating.get(name);
|
|
21744
|
+
if (inFlight) {
|
|
21745
|
+
return inFlight;
|
|
21746
|
+
}
|
|
21747
|
+
const creation = (async () => {
|
|
21748
|
+
const workspace = await this.resolveWorkspace();
|
|
21749
|
+
const instance = new RemoteSandboxInstance(name, this.client, workspace);
|
|
21750
|
+
this.instances.set(name, instance);
|
|
21751
|
+
return instance;
|
|
21752
|
+
})();
|
|
21753
|
+
this.creating.set(name, creation);
|
|
21754
|
+
creation.then(
|
|
21755
|
+
() => {
|
|
21756
|
+
this.creating.delete(name);
|
|
21757
|
+
},
|
|
21758
|
+
() => {
|
|
21759
|
+
this.creating.delete(name);
|
|
21760
|
+
}
|
|
21761
|
+
);
|
|
21762
|
+
return creation;
|
|
21494
21763
|
}
|
|
21495
21764
|
async getSandbox(name) {
|
|
21496
21765
|
const instance = this.instances.get(name);
|
|
@@ -21500,9 +21769,7 @@ var RemoteSandboxProvider = class {
|
|
|
21500
21769
|
return instance;
|
|
21501
21770
|
}
|
|
21502
21771
|
async stopSandbox(name) {
|
|
21503
|
-
|
|
21504
|
-
if (instance) {
|
|
21505
|
-
}
|
|
21772
|
+
this.instances.delete(name);
|
|
21506
21773
|
}
|
|
21507
21774
|
async deleteSandbox(name) {
|
|
21508
21775
|
this.instances.delete(name);
|
|
@@ -21510,6 +21777,82 @@ var RemoteSandboxProvider = class {
|
|
|
21510
21777
|
async listSandboxes() {
|
|
21511
21778
|
return Array.from(this.instances.values());
|
|
21512
21779
|
}
|
|
21780
|
+
createVolumeFsClient(_volumeName, pathPrefix) {
|
|
21781
|
+
const workspace = this.workspace;
|
|
21782
|
+
const resolve3 = (p) => {
|
|
21783
|
+
if (!p || p === "/") {
|
|
21784
|
+
if (pathPrefix) {
|
|
21785
|
+
return `${workspace}${pathPrefix}`;
|
|
21786
|
+
}
|
|
21787
|
+
return workspace;
|
|
21788
|
+
}
|
|
21789
|
+
if (p.startsWith(workspace)) {
|
|
21790
|
+
return p;
|
|
21791
|
+
}
|
|
21792
|
+
if (p.startsWith("/")) {
|
|
21793
|
+
return `${workspace}${p}`;
|
|
21794
|
+
}
|
|
21795
|
+
if (pathPrefix) {
|
|
21796
|
+
const mountDir = pathPrefix.replace(/^\//, "");
|
|
21797
|
+
return `${workspace}/${mountDir}/${p}`;
|
|
21798
|
+
}
|
|
21799
|
+
return `${workspace}/${p}`;
|
|
21800
|
+
};
|
|
21801
|
+
return {
|
|
21802
|
+
read: async (path3) => {
|
|
21803
|
+
const resolved = resolve3(path3);
|
|
21804
|
+
const result = await this.client.file.readFile({ file: resolved });
|
|
21805
|
+
if (!result.ok) {
|
|
21806
|
+
throw new Error(`Volume read failed: ${extractFetcherError(result.error)}`);
|
|
21807
|
+
}
|
|
21808
|
+
return result.body.data?.content ?? "";
|
|
21809
|
+
},
|
|
21810
|
+
write: async (path3, content) => {
|
|
21811
|
+
const resolved = resolve3(path3);
|
|
21812
|
+
const result = await this.client.file.writeFile({ file: resolved, content });
|
|
21813
|
+
if (!result.ok) {
|
|
21814
|
+
throw new Error(`Volume write failed: ${extractFetcherError(result.error)}`);
|
|
21815
|
+
}
|
|
21816
|
+
},
|
|
21817
|
+
list: async (path3) => {
|
|
21818
|
+
const resolved = resolve3(path3);
|
|
21819
|
+
const result = await this.client.file.listPath({
|
|
21820
|
+
path: resolved,
|
|
21821
|
+
recursive: false
|
|
21822
|
+
});
|
|
21823
|
+
if (!result.ok) {
|
|
21824
|
+
throw new Error(`Volume list failed: ${extractFetcherError(result.error)}`);
|
|
21825
|
+
}
|
|
21826
|
+
const entries = (result.body.data?.files || []).map((f) => ({
|
|
21827
|
+
path: f.path.startsWith(workspace) ? f.path.slice(workspace.length) : f.path,
|
|
21828
|
+
kind: f.is_dir === true || f.size === null ? "directory" : "file",
|
|
21829
|
+
size: f.size ?? 0,
|
|
21830
|
+
mode: 0,
|
|
21831
|
+
modified: f.modified_at ?? null
|
|
21832
|
+
}));
|
|
21833
|
+
return entries;
|
|
21834
|
+
},
|
|
21835
|
+
readRaw: async (path3) => {
|
|
21836
|
+
const resolved = resolve3(path3);
|
|
21837
|
+
const result = await this.client.file.downloadFile({ path: resolved });
|
|
21838
|
+
if (!result.ok) {
|
|
21839
|
+
throw new Error(`Volume download failed: ${extractFetcherError(result.error)}`);
|
|
21840
|
+
}
|
|
21841
|
+
const buffer2 = await result.body.arrayBuffer();
|
|
21842
|
+
return Buffer.from(buffer2);
|
|
21843
|
+
},
|
|
21844
|
+
writeRaw: async (path3, data) => {
|
|
21845
|
+
const resolved = resolve3(path3);
|
|
21846
|
+
const result = await this.client.file.uploadFile({
|
|
21847
|
+
file: data,
|
|
21848
|
+
path: resolved
|
|
21849
|
+
});
|
|
21850
|
+
if (!result.ok) {
|
|
21851
|
+
throw new Error(`Volume upload failed: ${extractFetcherError(result.error)}`);
|
|
21852
|
+
}
|
|
21853
|
+
}
|
|
21854
|
+
};
|
|
21855
|
+
}
|
|
21513
21856
|
};
|
|
21514
21857
|
|
|
21515
21858
|
// src/sandbox_lattice/providers/E2BProvider.ts
|
|
@@ -21579,6 +21922,12 @@ var E2BInstance = class {
|
|
|
21579
21922
|
downloadFile: async (params) => {
|
|
21580
21923
|
const data = await this.native.files.read(params.file, { format: "bytes" });
|
|
21581
21924
|
return Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
21925
|
+
},
|
|
21926
|
+
deletePath: async (path3) => {
|
|
21927
|
+
await this.native.commands.run(`rm -rf "${path3}"`);
|
|
21928
|
+
},
|
|
21929
|
+
createDirectory: async (path3) => {
|
|
21930
|
+
await this.native.commands.run(`mkdir -p "${path3}"`);
|
|
21582
21931
|
}
|
|
21583
21932
|
};
|
|
21584
21933
|
this.shell = {
|
|
@@ -21745,6 +22094,12 @@ var DaytonaInstance = class {
|
|
|
21745
22094
|
downloadFile: async (params) => {
|
|
21746
22095
|
const buffer2 = await this.native.fs.downloadFile(toRelativePath(params.file));
|
|
21747
22096
|
return Buffer.isBuffer(buffer2) ? buffer2 : Buffer.from(buffer2);
|
|
22097
|
+
},
|
|
22098
|
+
deletePath: async (path3) => {
|
|
22099
|
+
await this.native.process.executeCommand(`rm -rf "${toRelativePath(path3)}"`, void 0, void 0);
|
|
22100
|
+
},
|
|
22101
|
+
createDirectory: async (path3) => {
|
|
22102
|
+
await this.native.process.executeCommand(`mkdir -p "${toRelativePath(path3)}"`, void 0, void 0);
|
|
21748
22103
|
}
|
|
21749
22104
|
};
|
|
21750
22105
|
this.shell = {
|
|
@@ -22150,6 +22505,7 @@ export {
|
|
|
22150
22505
|
MicrosandboxRemoteProvider,
|
|
22151
22506
|
MicrosandboxServiceClient,
|
|
22152
22507
|
ModelLatticeManager,
|
|
22508
|
+
MysqlDatabase,
|
|
22153
22509
|
PinoLoggerClient,
|
|
22154
22510
|
PostgresDatabase,
|
|
22155
22511
|
PrometheusClient,
|
|
@@ -22214,6 +22570,7 @@ export {
|
|
|
22214
22570
|
ensureBuiltinAgentsForTenant,
|
|
22215
22571
|
eventBus,
|
|
22216
22572
|
event_bus_default as eventBusDefault,
|
|
22573
|
+
extractFetcherError,
|
|
22217
22574
|
fileDataToString,
|
|
22218
22575
|
formatContentWithLineNumbers,
|
|
22219
22576
|
formatGrepMatches,
|