@axiom-lattice/core 2.1.16 → 2.1.17

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.js CHANGED
@@ -46,6 +46,7 @@ __export(index_exports, {
46
46
  InMemoryChunkBuffer: () => InMemoryChunkBuffer,
47
47
  InMemoryThreadStore: () => InMemoryThreadStore,
48
48
  LoggerLatticeManager: () => LoggerLatticeManager,
49
+ McpLatticeManager: () => McpLatticeManager,
49
50
  MemoryLatticeManager: () => MemoryLatticeManager,
50
51
  MemoryQueueClient: () => MemoryQueueClient,
51
52
  MemoryScheduleStorage: () => MemoryScheduleStorage,
@@ -55,6 +56,7 @@ __export(index_exports, {
55
56
  PostgresDatabase: () => PostgresDatabase,
56
57
  Protocols: () => Protocols,
57
58
  QueueLatticeManager: () => QueueLatticeManager,
59
+ SandboxLatticeManager: () => SandboxLatticeManager,
58
60
  ScheduleLatticeManager: () => ScheduleLatticeManager,
59
61
  SkillLatticeManager: () => SkillLatticeManager,
60
62
  SqlDatabaseManager: () => SqlDatabaseManager,
@@ -80,6 +82,7 @@ __export(index_exports, {
80
82
  getModelLattice: () => getModelLattice,
81
83
  getNextCronTime: () => getNextCronTime,
82
84
  getQueueLattice: () => getQueueLattice,
85
+ getSandBoxManager: () => getSandBoxManager,
83
86
  getScheduleLattice: () => getScheduleLattice,
84
87
  getStoreLattice: () => getStoreLattice,
85
88
  getToolClient: () => getToolClient,
@@ -89,9 +92,12 @@ __export(index_exports, {
89
92
  getVectorStoreLattice: () => getVectorStoreLattice,
90
93
  hasChunkBuffer: () => hasChunkBuffer,
91
94
  isValidCronExpression: () => isValidCronExpression,
95
+ isValidSandboxName: () => isValidSandboxName,
92
96
  isValidSkillName: () => isValidSkillName,
93
97
  loggerLatticeManager: () => loggerLatticeManager,
98
+ mcpManager: () => mcpManager,
94
99
  modelLatticeManager: () => modelLatticeManager,
100
+ normalizeSandboxName: () => normalizeSandboxName,
95
101
  parseCronExpression: () => parseCronExpression,
96
102
  queueLatticeManager: () => queueLatticeManager,
97
103
  registerAgentLattice: () => registerAgentLattice,
@@ -99,6 +105,7 @@ __export(index_exports, {
99
105
  registerCheckpointSaver: () => registerCheckpointSaver,
100
106
  registerChunkBuffer: () => registerChunkBuffer,
101
107
  registerEmbeddingsLattice: () => registerEmbeddingsLattice,
108
+ registerExistingTool: () => registerExistingTool,
102
109
  registerLoggerLattice: () => registerLoggerLattice,
103
110
  registerModelLattice: () => registerModelLattice,
104
111
  registerQueueLattice: () => registerQueueLattice,
@@ -106,6 +113,7 @@ __export(index_exports, {
106
113
  registerStoreLattice: () => registerStoreLattice,
107
114
  registerToolLattice: () => registerToolLattice,
108
115
  registerVectorStoreLattice: () => registerVectorStoreLattice,
116
+ sandboxLatticeManager: () => sandboxLatticeManager,
109
117
  scheduleLatticeManager: () => scheduleLatticeManager,
110
118
  skillLatticeManager: () => skillLatticeManager,
111
119
  sqlDatabaseManager: () => sqlDatabaseManager,
@@ -619,6 +627,27 @@ var ToolLatticeManager = class _ToolLatticeManager extends BaseLatticeManager {
619
627
  getAllToolDefinitions() {
620
628
  return this.getAllLattices().map((lattice) => lattice.config);
621
629
  }
630
+ /**
631
+ * 注册已有的StructuredTool到Lattice
632
+ * @param key Lattice键名
633
+ * @param tool 已有的StructuredTool实例
634
+ */
635
+ registerExistingTool(key, tool7) {
636
+ const config = {
637
+ name: tool7.name,
638
+ description: tool7.description,
639
+ schema: tool7.schema,
640
+ // StructuredTool的schema已经是Zod兼容的
641
+ needUserApprove: false
642
+ // MCP工具默认不需要用户批准
643
+ };
644
+ const toolLattice = {
645
+ key,
646
+ config,
647
+ client: tool7
648
+ };
649
+ this.register(key, toolLattice);
650
+ }
622
651
  /**
623
652
  * 验证工具输入参数
624
653
  * @param key Lattice键名
@@ -641,6 +670,7 @@ var ToolLatticeManager = class _ToolLatticeManager extends BaseLatticeManager {
641
670
  };
642
671
  var toolLatticeManager = ToolLatticeManager.getInstance();
643
672
  var registerToolLattice = (key, config, executor) => toolLatticeManager.registerLattice(key, config, executor);
673
+ var registerExistingTool = (key, tool7) => toolLatticeManager.registerExistingTool(key, tool7);
644
674
  var getToolLattice = (key) => toolLatticeManager.getToolLattice(key);
645
675
  var getToolDefinition = (key) => toolLatticeManager.getToolDefinition(key);
646
676
  var getToolClient = (key) => toolLatticeManager.getToolClient(key);
@@ -2022,88 +2052,1333 @@ storeLatticeManager.registerLattice(
2022
2052
  "assistant",
2023
2053
  defaultAssistantStore
2024
2054
  );
2025
- storeLatticeManager.registerLattice("default", "skill", defaultSkillStore);
2055
+ storeLatticeManager.registerLattice("default", "skill", defaultSkillStore);
2056
+
2057
+ // src/tool_lattice/load_skills/index.ts
2058
+ var LOAD_SKILLS_DESCRIPTION = `Load all available skills and return their metadata (name, description, license, compatibility, metadata, and subSkills) without the content. This tool returns skill information including hierarchical relationships (subSkills). Use this to discover what skills are available and their structure. Skills can have sub-skills, creating a tree structure for organizing capabilities.`;
2059
+ registerToolLattice(
2060
+ "load_skills",
2061
+ {
2062
+ name: "load_skills",
2063
+ description: LOAD_SKILLS_DESCRIPTION,
2064
+ needUserApprove: false,
2065
+ schema: import_zod7.default.object({})
2066
+ },
2067
+ async () => {
2068
+ try {
2069
+ const storeLattice = getStoreLattice("default", "skill");
2070
+ const skillStore = storeLattice.store;
2071
+ const skills = await skillStore.getAllSkills();
2072
+ const skillsMeta = skills.map((skill) => ({
2073
+ name: skill.name,
2074
+ description: skill.description,
2075
+ license: skill.license,
2076
+ compatibility: skill.compatibility,
2077
+ metadata: skill.metadata,
2078
+ subSkills: skill.subSkills
2079
+ }));
2080
+ return JSON.stringify(skillsMeta, null, 2);
2081
+ } catch (error) {
2082
+ return `Error loading skills: ${error instanceof Error ? error.message : String(error)}`;
2083
+ }
2084
+ }
2085
+ );
2086
+
2087
+ // src/tool_lattice/load_skill_content/index.ts
2088
+ var import_zod8 = __toESM(require("zod"));
2089
+ var LOAD_SKILL_CONTENT_DESCRIPTION = `Load a specific skill's content by name and return its full content including markdown body. This tool returns the complete skill content including frontmatter and markdown body. If the skill has sub-skills defined, they will be listed in the frontmatter. Use this tool to get the complete skill content for a skill that you want to use.`;
2090
+ registerToolLattice(
2091
+ "load_skill_content",
2092
+ {
2093
+ name: "load_skill_content",
2094
+ description: LOAD_SKILL_CONTENT_DESCRIPTION,
2095
+ needUserApprove: false,
2096
+ schema: import_zod8.default.object({
2097
+ skill_name: import_zod8.default.string().describe("The name of the skill to load")
2098
+ })
2099
+ },
2100
+ async (input) => {
2101
+ try {
2102
+ const storeLattice = getStoreLattice("default", "skill");
2103
+ const skillStore = storeLattice.store;
2104
+ const skill = await skillStore.getSkillById(input.skill_name);
2105
+ if (!skill) {
2106
+ const allSkills = await skillStore.getAllSkills();
2107
+ const availableSkills = allSkills.map((s) => s.name).join(", ");
2108
+ return `Skill "${input.skill_name}" not found. Available skills: ${availableSkills}`;
2109
+ }
2110
+ const frontmatter = ["---"];
2111
+ frontmatter.push(`name: ${skill.name}`);
2112
+ frontmatter.push(`description: ${skill.description}`);
2113
+ if (skill.license) {
2114
+ frontmatter.push(`license: ${skill.license}`);
2115
+ }
2116
+ if (skill.compatibility) {
2117
+ frontmatter.push(`compatibility: ${skill.compatibility}`);
2118
+ }
2119
+ if (skill.metadata && Object.keys(skill.metadata).length > 0) {
2120
+ frontmatter.push("metadata:");
2121
+ for (const [key, value] of Object.entries(skill.metadata)) {
2122
+ frontmatter.push(` ${key}: ${value}`);
2123
+ }
2124
+ }
2125
+ if (skill.subSkills && skill.subSkills.length > 0) {
2126
+ frontmatter.push("subSkills:");
2127
+ for (const subSkill of skill.subSkills) {
2128
+ frontmatter.push(` - ${subSkill}`);
2129
+ }
2130
+ }
2131
+ frontmatter.push("---");
2132
+ const content = skill.content || "";
2133
+ return `${frontmatter.join("\n")}
2134
+ ${content}`;
2135
+ } catch (error) {
2136
+ return `Error loading skill content: ${error instanceof Error ? error.message : String(error)}`;
2137
+ }
2138
+ }
2139
+ );
2140
+
2141
+ // src/tool_lattice/code_eval/index.ts
2142
+ var import_zod9 = __toESM(require("zod"));
2143
+
2144
+ // src/sandbox_lattice/SandboxLatticeManager.ts
2145
+ var import_sandbox = require("@agent-infra/sandbox");
2146
+
2147
+ // src/sandbox_lattice/utils.ts
2148
+ function normalizeSandboxName(name) {
2149
+ if (!name || typeof name !== "string") {
2150
+ throw new Error("Sandbox name must be a non-empty string");
2151
+ }
2152
+ let normalized = name.toLowerCase();
2153
+ normalized = normalized.replace(/_/g, "-");
2154
+ normalized = normalized.replace(/[^a-z0-9.-]/g, "");
2155
+ normalized = normalized.replace(/^[.-]+|[.-]+$/g, "");
2156
+ normalized = normalized.replace(/[.-]{2,}/g, "-");
2157
+ normalized = normalized.replace(/^[.-]+|[.-]+$/g, "");
2158
+ if (!normalized) {
2159
+ throw new Error(
2160
+ `Sandbox name "${name}" cannot be normalized to a valid RFC 1123 subdomain name`
2161
+ );
2162
+ }
2163
+ if (!/^[a-z0-9]/.test(normalized)) {
2164
+ normalized = `sandbox-${normalized}`;
2165
+ }
2166
+ if (!/[a-z0-9]$/.test(normalized)) {
2167
+ normalized = `${normalized}-0`;
2168
+ }
2169
+ const rfc1123Pattern = /^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$/;
2170
+ if (!rfc1123Pattern.test(normalized)) {
2171
+ normalized = normalized.replace(/[^a-z0-9-]/g, "-").replace(/^-+|-+$/g, "").replace(/-{2,}/g, "-");
2172
+ if (!/^[a-z0-9]/.test(normalized)) {
2173
+ normalized = `sandbox-${normalized}`;
2174
+ }
2175
+ if (!/[a-z0-9]$/.test(normalized)) {
2176
+ normalized = `${normalized}0`;
2177
+ }
2178
+ }
2179
+ return normalized;
2180
+ }
2181
+ function isValidSandboxName(name) {
2182
+ if (!name || typeof name !== "string") {
2183
+ return false;
2184
+ }
2185
+ const rfc1123Pattern = /^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$/;
2186
+ return rfc1123Pattern.test(name.toLowerCase());
2187
+ }
2188
+
2189
+ // src/sandbox_lattice/SandboxLatticeManager.ts
2190
+ var DefaultSandboxManager = class {
2191
+ constructor(baseURL = "http://localhost:8080") {
2192
+ this.sandboxes = /* @__PURE__ */ new Map();
2193
+ /**
2194
+ * Track in-flight sandbox creation promises by normalized sandbox name.
2195
+ * This ensures that concurrent calls with the same name share the same Promise
2196
+ * and we do not trigger multiple creations for the same sandbox.
2197
+ */
2198
+ this.creatingSandboxes = /* @__PURE__ */ new Map();
2199
+ this.baseURL = baseURL;
2200
+ }
2201
+ async createSandbox(sandboxName) {
2202
+ if (sandboxName === "global") {
2203
+ const client = new import_sandbox.SandboxClient({ baseUrl: `${this.baseURL}/sandbox/global`, environment: "" });
2204
+ this.sandboxes.set("global", client);
2205
+ return client;
2206
+ }
2207
+ const normalizedName = normalizeSandboxName(sandboxName);
2208
+ const existingClient = this.sandboxes.get(normalizedName);
2209
+ if (existingClient) {
2210
+ return existingClient;
2211
+ }
2212
+ const inFlight = this.creatingSandboxes.get(normalizedName);
2213
+ if (inFlight) {
2214
+ return inFlight;
2215
+ }
2216
+ const creationPromise = (async () => {
2217
+ const response = await fetch(`${this.baseURL}/api/v1/sandbox`, {
2218
+ method: "POST",
2219
+ headers: {
2220
+ "Content-Type": "application/json"
2221
+ },
2222
+ body: JSON.stringify({
2223
+ name: normalizedName,
2224
+ image: "enterprise-public-cn-beijing.cr.volces.com/vefaas-public/all-in-one-sandbox:latest"
2225
+ })
2226
+ });
2227
+ if (!response.ok) {
2228
+ throw new Error(`Failed to create sandbox: ${response.statusText}`);
2229
+ }
2230
+ const data = await response.json();
2231
+ const sandboxURL = `${this.baseURL}/sandbox/${normalizedName}`;
2232
+ const client = new import_sandbox.SandboxClient({ baseUrl: sandboxURL, environment: "" });
2233
+ this.sandboxes.set(normalizedName, client);
2234
+ return client;
2235
+ })();
2236
+ this.creatingSandboxes.set(normalizedName, creationPromise);
2237
+ creationPromise.catch(() => {
2238
+ this.creatingSandboxes.delete(normalizedName);
2239
+ }).then(() => {
2240
+ this.creatingSandboxes.delete(normalizedName);
2241
+ });
2242
+ return creationPromise;
2243
+ }
2244
+ async deleteSandbox(sandboxName) {
2245
+ const normalizedName = normalizeSandboxName(sandboxName);
2246
+ if (!this.sandboxes.has(normalizedName)) {
2247
+ throw new Error(`Sandbox ${sandboxName} (normalized: ${normalizedName}) not found`);
2248
+ }
2249
+ const response = await fetch(`${this.baseURL}/api/v1/sandbox/${normalizedName}`, {
2250
+ method: "DELETE"
2251
+ });
2252
+ if (!response.ok) {
2253
+ throw new Error(`Failed to delete sandbox: ${response.statusText}`);
2254
+ }
2255
+ this.sandboxes.delete(normalizedName);
2256
+ }
2257
+ async getSandbox(sandboxName) {
2258
+ const normalizedName = normalizeSandboxName(sandboxName);
2259
+ const client = this.sandboxes.get(normalizedName);
2260
+ if (!client) {
2261
+ throw new Error(`Sandbox ${sandboxName} (normalized: ${normalizedName}) not found`);
2262
+ }
2263
+ return client;
2264
+ }
2265
+ async listSandboxes() {
2266
+ return Array.from(this.sandboxes.values());
2267
+ }
2268
+ async getSandboxStatus(sandboxName) {
2269
+ const normalizedName = normalizeSandboxName(sandboxName);
2270
+ if (!this.sandboxes.has(normalizedName)) {
2271
+ throw new Error(`Sandbox ${sandboxName} (normalized: ${normalizedName}) not found`);
2272
+ }
2273
+ try {
2274
+ const client = this.sandboxes.get(normalizedName);
2275
+ const context = await client.sandbox.getContext();
2276
+ return context.ok ? "active" : "inactive";
2277
+ } catch {
2278
+ return "unknown";
2279
+ }
2280
+ }
2281
+ async getSandboxFromConfig(config) {
2282
+ if (config.sandboxConfig.isolatedLevel === "agent") {
2283
+ return this.createSandbox(config.assistant_id);
2284
+ } else if (config.sandboxConfig.isolatedLevel === "thread") {
2285
+ return this.createSandbox(config.thread_id);
2286
+ } else {
2287
+ return this.createSandbox("global");
2288
+ }
2289
+ }
2290
+ };
2291
+ var SandboxLatticeManager = class _SandboxLatticeManager extends BaseLatticeManager {
2292
+ /**
2293
+ * Get SandboxLatticeManager singleton instance
2294
+ */
2295
+ static getInstance() {
2296
+ if (!_SandboxLatticeManager._instance) {
2297
+ _SandboxLatticeManager._instance = new _SandboxLatticeManager();
2298
+ }
2299
+ return _SandboxLatticeManager._instance;
2300
+ }
2301
+ /**
2302
+ * Get Lattice type prefix
2303
+ */
2304
+ getLatticeType() {
2305
+ return "sandbox_manager";
2306
+ }
2307
+ /**
2308
+ * Register sandbox Lattice
2309
+ * @param key Lattice key name
2310
+ * @param manager Optional sandbox manager. If not provided, will create a default one.
2311
+ * @param baseURL Base URL for sandbox service (used when creating default manager)
2312
+ */
2313
+ registerLattice(key, config) {
2314
+ const { manager, baseURL } = config;
2315
+ const sandboxManager = manager || new DefaultSandboxManager(baseURL);
2316
+ this.register(key, sandboxManager);
2317
+ }
2318
+ /**
2319
+ * Get SandboxLattice
2320
+ * @param key Lattice key name
2321
+ */
2322
+ getSandboxLattice(key) {
2323
+ const sandboxLattice = this.get(key);
2324
+ if (!sandboxLattice) {
2325
+ throw new Error(`SandboxLattice ${key} not found`);
2326
+ }
2327
+ return sandboxLattice;
2328
+ }
2329
+ /**
2330
+ * Get all Lattices
2331
+ */
2332
+ getAllLattices() {
2333
+ return this.getAll();
2334
+ }
2335
+ /**
2336
+ * Check if Lattice exists
2337
+ * @param key Lattice key name
2338
+ */
2339
+ hasLattice(key) {
2340
+ return this.has(key);
2341
+ }
2342
+ /**
2343
+ * Remove Lattice
2344
+ * @param key Lattice key name
2345
+ */
2346
+ removeLattice(key) {
2347
+ return this.remove(key);
2348
+ }
2349
+ /**
2350
+ * Clear all Lattices
2351
+ */
2352
+ clearLattices() {
2353
+ this.clear();
2354
+ }
2355
+ /**
2356
+ * Get Lattice count
2357
+ */
2358
+ getLatticeCount() {
2359
+ return this.count();
2360
+ }
2361
+ /**
2362
+ * Get Lattice key list
2363
+ */
2364
+ getLatticeKeys() {
2365
+ return this.keys();
2366
+ }
2367
+ };
2368
+ var sandboxLatticeManager = SandboxLatticeManager.getInstance();
2369
+ var getSandBoxManager = (key = "default") => {
2370
+ if (!sandboxLatticeManager.hasLattice(key)) {
2371
+ throw new Error(`Sandbox ${key} not configured. Ensure the sandbox manager is registered and the agent is built with connectedSandbox.`);
2372
+ }
2373
+ const sandboxManager = sandboxLatticeManager.getSandboxLattice(key);
2374
+ return sandboxManager;
2375
+ };
2376
+
2377
+ // src/tool_lattice/code_eval/index.ts
2378
+ var CODE_EVAL_DESCRIPTION = `Execute code in Python or JavaScript runtime.
2379
+
2380
+ Args:
2381
+ code: Code to execute
2382
+ language: Programming language ('python', 'javascript')
2383
+
2384
+ Returns:
2385
+ Dict containing output, errors, and execution details`;
2386
+ registerToolLattice(
2387
+ "execute_code",
2388
+ {
2389
+ name: "execute_code",
2390
+ description: CODE_EVAL_DESCRIPTION,
2391
+ needUserApprove: false,
2392
+ schema: import_zod9.default.object({
2393
+ language: import_zod9.default.enum(["python", "javascript"]).describe("Programming language: 'python' or 'javascript'"),
2394
+ code: import_zod9.default.string().describe("Code to execute")
2395
+ })
2396
+ },
2397
+ async (input, exe_config) => {
2398
+ try {
2399
+ const runConfig = exe_config.configurable?.runConfig;
2400
+ const sandboxManager = getSandBoxManager();
2401
+ const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
2402
+ const result = await sandbox.code.executeCode({
2403
+ language: input.language,
2404
+ code: input.code,
2405
+ timeout: 300
2406
+ });
2407
+ if (!result.ok) {
2408
+ const err = result.error;
2409
+ return `Error executing ${input.language} code: ${err?.content?.message + (err?.content?.errors ? `
2410
+ ${err?.content?.errors.join("\n")}` : "")}`;
2411
+ }
2412
+ const data = result.body?.data;
2413
+ if (!data) {
2414
+ return "Error: No response data from sandbox code execution.";
2415
+ }
2416
+ const { stdout = "", stderr = "", exit_code, traceback } = data;
2417
+ const parts = [];
2418
+ if (stdout) {
2419
+ parts.push(`stdout:
2420
+ ${stdout}`);
2421
+ }
2422
+ if (stderr) {
2423
+ parts.push(`stderr:
2424
+ ${stderr}`);
2425
+ }
2426
+ if (traceback && traceback.length > 0) {
2427
+ parts.push(`traceback:
2428
+ ${traceback.join("\n")}`);
2429
+ }
2430
+ parts.push(`exit_code: ${exit_code ?? "\u2014"}`);
2431
+ return parts.length > 0 ? parts.join("\n\n") : `exit_code: ${exit_code ?? 0}`;
2432
+ } catch (e) {
2433
+ return `Error: ${e instanceof Error ? e.message : String(e)}`;
2434
+ }
2435
+ }
2436
+ );
2437
+
2438
+ // src/tool_lattice/code_execute_file/index.ts
2439
+ var import_zod10 = __toESM(require("zod"));
2440
+ var path2 = __toESM(require("path"));
2441
+ var CODE_EXECUTE_FILE_DESCRIPTION = `Execute a code file from the sandbox filesystem. Only supports Python (.py) and JavaScript (.js, .mjs) files. Other file types are not supported. The tool reads the file content and executes it in an isolated sandbox environment. Language is automatically inferred from the file extension. Output is returned via stdout; errors appear in stderr and traceback.`;
2442
+ function inferLanguageFromPath(filePath) {
2443
+ const ext = path2.extname(filePath).toLowerCase();
2444
+ if (ext === ".py") {
2445
+ return "python";
2446
+ } else if (ext === ".js" || ext === ".mjs") {
2447
+ return "javascript";
2448
+ }
2449
+ return null;
2450
+ }
2451
+ registerToolLattice(
2452
+ "execute_code_file",
2453
+ {
2454
+ name: "execute_code_file",
2455
+ description: CODE_EXECUTE_FILE_DESCRIPTION,
2456
+ needUserApprove: false,
2457
+ schema: import_zod10.default.object({
2458
+ file_path: import_zod10.default.string().describe("Path to the code file to execute (absolute path in sandbox filesystem). Only supports .py (Python) and .js/.mjs (JavaScript) files.")
2459
+ })
2460
+ },
2461
+ async (input, exe_config) => {
2462
+ try {
2463
+ const runConfig = exe_config.configurable?.runConfig;
2464
+ const sandboxManager = getSandBoxManager();
2465
+ const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
2466
+ const context = await sandbox.sandbox.getContext();
2467
+ if (!context.ok) {
2468
+ return `Error: ${context.error}`;
2469
+ }
2470
+ const homeDir = context.body?.home_dir;
2471
+ const resolvedFilePath = path2.join(homeDir, input.file_path);
2472
+ const language = inferLanguageFromPath(input.file_path);
2473
+ if (!language) {
2474
+ return `Error: Unsupported file type. This tool only supports Python (.py) and JavaScript (.js, .mjs) files. Other file types cannot be executed.`;
2475
+ }
2476
+ const readResult = await sandbox.file.readFile({
2477
+ file: resolvedFilePath
2478
+ });
2479
+ if (!readResult.ok) {
2480
+ const err = readResult.error;
2481
+ return `Error reading file '${input.file_path}': ${err?.content?.message ?? JSON.stringify(readResult.error)}`;
2482
+ }
2483
+ const fileContent = readResult.body?.data?.content;
2484
+ if (fileContent === void 0 || fileContent === null) {
2485
+ return `Error: File '${input.file_path}' is empty or could not be read.`;
2486
+ }
2487
+ const result = await sandbox.code.executeCode({
2488
+ language,
2489
+ code: fileContent,
2490
+ timeout: 300
2491
+ });
2492
+ if (!result.ok) {
2493
+ const err = result.error;
2494
+ return `Error executing ${language} file '${input.file_path}': ${err?.content?.message ?? JSON.stringify(result.error)}`;
2495
+ }
2496
+ const data = result.body?.data;
2497
+ if (!data) {
2498
+ return "Error: No response data from sandbox code execution.";
2499
+ }
2500
+ const { stdout = "", stderr = "", exit_code, traceback } = data;
2501
+ const parts = [];
2502
+ if (stdout) {
2503
+ parts.push(`stdout:
2504
+ ${stdout}`);
2505
+ }
2506
+ if (stderr) {
2507
+ parts.push(`stderr:
2508
+ ${stderr}`);
2509
+ }
2510
+ if (traceback && traceback.length > 0) {
2511
+ parts.push(`traceback:
2512
+ ${traceback.join("\n")}`);
2513
+ }
2514
+ parts.push(`exit_code: ${exit_code ?? "\u2014"}`);
2515
+ return parts.length > 0 ? parts.join("\n\n") : `exit_code: ${exit_code ?? 0}`;
2516
+ } catch (e) {
2517
+ return `Error: ${e instanceof Error ? e.message : String(e)}`;
2518
+ }
2519
+ }
2520
+ );
2521
+
2522
+ // src/tool_lattice/convert_to_markdown/index.ts
2523
+ var import_zod11 = __toESM(require("zod"));
2524
+ var CONVERT_TO_MARKDOWN_DESCRIPTION = `Convert a resource described by an http:, https:, file: or data: URI to markdown.
2525
+
2526
+ Args:
2527
+ uri (str): The URI to convert. Supported schemes:
2528
+ - http:// or https://: Fetch content from URL
2529
+ - file://: Read content from local file
2530
+ - data:: Decode data URI content
2531
+
2532
+ Returns:
2533
+ str: The content converted to markdown format.`;
2534
+ registerToolLattice(
2535
+ "convert_to_markdown",
2536
+ {
2537
+ name: "convert_to_markdown",
2538
+ description: CONVERT_TO_MARKDOWN_DESCRIPTION,
2539
+ needUserApprove: false,
2540
+ schema: import_zod11.default.object({
2541
+ uri: import_zod11.default.string().describe("The URI to convert.")
2542
+ })
2543
+ },
2544
+ async (input, exe_config) => {
2545
+ try {
2546
+ const runConfig = exe_config.configurable?.runConfig;
2547
+ const sandboxManager = getSandBoxManager();
2548
+ const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
2549
+ sandbox;
2550
+ const result = await sandbox.util.convertToMarkdown({
2551
+ uri: input.uri
2552
+ });
2553
+ if (!result.ok) {
2554
+ return `Error converting to markdown: ${result.error}`;
2555
+ }
2556
+ return result.body.data;
2557
+ } catch (e) {
2558
+ return `Error converting to markdown: ${e instanceof Error ? e.message : String(e)}`;
2559
+ }
2560
+ }
2561
+ );
2562
+
2563
+ // src/tool_lattice/browser/browser_navigate.ts
2564
+ var import_zod12 = __toESM(require("zod"));
2565
+ var BROWSER_NAVIGATE_DESCRIPTION = `Navigate to a URL.
2566
+
2567
+ Args:
2568
+ url (str): The URL to navigate to.
2569
+
2570
+ `;
2571
+ registerToolLattice(
2572
+ "browser_navigate",
2573
+ {
2574
+ name: "browser_navigate",
2575
+ description: BROWSER_NAVIGATE_DESCRIPTION,
2576
+ needUserApprove: false,
2577
+ schema: import_zod12.default.object({
2578
+ url: import_zod12.default.string().describe("The URL to navigate to.")
2579
+ })
2580
+ },
2581
+ async (input, exe_config) => {
2582
+ try {
2583
+ const runConfig = exe_config.configurable?.runConfig;
2584
+ const sandboxManager = getSandBoxManager();
2585
+ const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
2586
+ const result = await sandbox.mcp.executeMcpTool("browser", "browser_navigate", {
2587
+ url: input.url
2588
+ });
2589
+ if (!result.ok) {
2590
+ return `Error navigating to URL: ${JSON.stringify(result.error.content)}`;
2591
+ }
2592
+ return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Navigated to URL";
2593
+ } catch (e) {
2594
+ return `Error navigating to URL: ${e instanceof Error ? e.message : String(e)}`;
2595
+ }
2596
+ }
2597
+ );
2598
+
2599
+ // src/tool_lattice/browser/get_info.ts
2600
+ var BROWSER_GET_INFO_DESCRIPTION = `Get information about browser, like CDP URL, viewport size, etc.
2601
+
2602
+ Args:
2603
+ request (Dict): The incoming request context.
2604
+
2605
+ Returns:
2606
+ Dict containing browser information including CDP URL, viewport dimensions, and other browser metadata.`;
2607
+ registerToolLattice(
2608
+ "browser_get_info",
2609
+ {
2610
+ name: "browser_get_info",
2611
+ description: BROWSER_GET_INFO_DESCRIPTION,
2612
+ needUserApprove: false
2613
+ },
2614
+ async (input, exe_config) => {
2615
+ try {
2616
+ const runConfig = exe_config.configurable?.runConfig;
2617
+ const sandboxManager = getSandBoxManager();
2618
+ const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
2619
+ const result = await sandbox.browser.getInfo();
2620
+ if (!result.ok) {
2621
+ return `Error getting browser info: ${result.error}`;
2622
+ }
2623
+ return JSON.stringify(result.body.data, void 0, 2);
2624
+ } catch (e) {
2625
+ return `Error getting browser info: ${e instanceof Error ? e.message : String(e)}`;
2626
+ }
2627
+ }
2628
+ );
2629
+
2630
+ // src/tool_lattice/browser/browser_go_back.ts
2631
+ var import_zod13 = __toESM(require("zod"));
2632
+ var BROWSER_GO_BACK_DESCRIPTION = `Go back to the previous page.
2633
+
2634
+ Args:
2635
+ None
2636
+
2637
+ `;
2638
+ registerToolLattice(
2639
+ "browser_go_back",
2640
+ {
2641
+ name: "browser_go_back",
2642
+ description: BROWSER_GO_BACK_DESCRIPTION,
2643
+ needUserApprove: false,
2644
+ schema: import_zod13.default.object({})
2645
+ },
2646
+ async (input, exe_config) => {
2647
+ try {
2648
+ const runConfig = exe_config.configurable?.runConfig;
2649
+ const sandboxManager = getSandBoxManager();
2650
+ const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
2651
+ const result = await sandbox.mcp.executeMcpTool("browser", "browser_go_back", {});
2652
+ if (!result.ok) {
2653
+ return `Error going back: ${JSON.stringify(result.error.content)}`;
2654
+ }
2655
+ return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Went back to previous page";
2656
+ } catch (e) {
2657
+ return `Error going back: ${e instanceof Error ? e.message : String(e)}`;
2658
+ }
2659
+ }
2660
+ );
2661
+
2662
+ // src/tool_lattice/browser/browser_go_forward.ts
2663
+ var import_zod14 = __toESM(require("zod"));
2664
+ var BROWSER_GO_FORWARD_DESCRIPTION = `Go forward to the next page.
2665
+
2666
+ Args:
2667
+ None
2668
+
2669
+ `;
2670
+ registerToolLattice(
2671
+ "browser_go_forward",
2672
+ {
2673
+ name: "browser_go_forward",
2674
+ description: BROWSER_GO_FORWARD_DESCRIPTION,
2675
+ needUserApprove: false,
2676
+ schema: import_zod14.default.object({})
2677
+ },
2678
+ async (input, exe_config) => {
2679
+ try {
2680
+ const runConfig = exe_config.configurable?.runConfig;
2681
+ const sandboxManager = getSandBoxManager();
2682
+ const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
2683
+ const result = await sandbox.mcp.executeMcpTool("browser", "browser_go_forward", {});
2684
+ if (!result.ok) {
2685
+ return `Error going forward: ${JSON.stringify(result.error.content)}`;
2686
+ }
2687
+ return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Went forward to next page";
2688
+ } catch (e) {
2689
+ return `Error going forward: ${e instanceof Error ? e.message : String(e)}`;
2690
+ }
2691
+ }
2692
+ );
2693
+
2694
+ // src/tool_lattice/browser/browser_form_input_fill.ts
2695
+ var import_zod15 = __toESM(require("zod"));
2696
+ var BROWSER_FORM_INPUT_FILL_DESCRIPTION = `Fill out an input field, before using the tool, Either 'index' or 'selector' must be provided.
2697
+
2698
+ Args:
2699
+ selector (str): CSS selector for input field, priority use index, if index is not provided, use selector
2700
+ index (int): Index of the element to fill
2701
+ value (str): Value to fill
2702
+ clear (bool): Whether to clear existing text before filling
2703
+
2704
+ `;
2705
+ registerToolLattice(
2706
+ "browser_form_input_fill",
2707
+ {
2708
+ name: "browser_form_input_fill",
2709
+ description: BROWSER_FORM_INPUT_FILL_DESCRIPTION,
2710
+ needUserApprove: false,
2711
+ schema: import_zod15.default.object({
2712
+ selector: import_zod15.default.string().optional().describe("CSS selector for input field, priority use index, if index is not provided, use selector"),
2713
+ index: import_zod15.default.number().optional().describe("Index of the element to fill"),
2714
+ value: import_zod15.default.string().describe("Value to fill"),
2715
+ clear: import_zod15.default.boolean().default(false).describe("Whether to clear existing text before filling")
2716
+ })
2717
+ },
2718
+ async (input, exe_config) => {
2719
+ try {
2720
+ const runConfig = exe_config.configurable?.runConfig;
2721
+ const sandboxManager = getSandBoxManager();
2722
+ const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
2723
+ const result = await sandbox.mcp.executeMcpTool("browser", "browser_form_input_fill", {
2724
+ selector: input.selector,
2725
+ index: input.index,
2726
+ value: input.value,
2727
+ clear: input.clear
2728
+ });
2729
+ if (!result.ok) {
2730
+ return `Error filling input field: ${JSON.stringify(result.error.content)}`;
2731
+ }
2732
+ return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Input field filled successfully";
2733
+ } catch (e) {
2734
+ return `Error filling input field: ${e instanceof Error ? e.message : String(e)}`;
2735
+ }
2736
+ }
2737
+ );
2738
+
2739
+ // src/tool_lattice/browser/browser_get_markdown.ts
2740
+ var import_zod16 = __toESM(require("zod"));
2741
+ var BROWSER_GET_MARKDOWN_DESCRIPTION = `Get the markdown content of the current page.
2742
+
2743
+ Args:
2744
+ None
2745
+
2746
+ `;
2747
+ registerToolLattice(
2748
+ "browser_get_markdown",
2749
+ {
2750
+ name: "browser_get_markdown",
2751
+ description: BROWSER_GET_MARKDOWN_DESCRIPTION,
2752
+ needUserApprove: false,
2753
+ schema: import_zod16.default.object({})
2754
+ },
2755
+ async (input, exe_config) => {
2756
+ try {
2757
+ const runConfig = exe_config.configurable?.runConfig;
2758
+ const sandboxManager = getSandBoxManager();
2759
+ const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
2760
+ const result = await sandbox.mcp.executeMcpTool("browser", "browser_get_markdown", {});
2761
+ if (!result.ok) {
2762
+ return `Error getting markdown content: ${JSON.stringify(result.error.content)}`;
2763
+ }
2764
+ return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Markdown content retrieved";
2765
+ } catch (e) {
2766
+ return `Error getting markdown content: ${e instanceof Error ? e.message : String(e)}`;
2767
+ }
2768
+ }
2769
+ );
2770
+
2771
+ // src/tool_lattice/browser/browser_get_text.ts
2772
+ var import_zod17 = __toESM(require("zod"));
2773
+ var BROWSER_GET_TEXT_DESCRIPTION = `Get the text content of the current page.
2774
+
2775
+ Args:
2776
+ None
2777
+
2778
+ `;
2779
+ registerToolLattice(
2780
+ "browser_get_text",
2781
+ {
2782
+ name: "browser_get_text",
2783
+ description: BROWSER_GET_TEXT_DESCRIPTION,
2784
+ needUserApprove: false,
2785
+ schema: import_zod17.default.object({})
2786
+ },
2787
+ async (input, exe_config) => {
2788
+ try {
2789
+ const runConfig = exe_config.configurable?.runConfig;
2790
+ const sandboxManager = getSandBoxManager();
2791
+ const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
2792
+ const result = await sandbox.mcp.executeMcpTool("browser", "browser_get_text", {});
2793
+ if (!result.ok) {
2794
+ return `Error getting text content: ${JSON.stringify(result.error.content)}`;
2795
+ }
2796
+ return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Text content retrieved";
2797
+ } catch (e) {
2798
+ return `Error getting text content: ${e instanceof Error ? e.message : String(e)}`;
2799
+ }
2800
+ }
2801
+ );
2802
+
2803
+ // src/tool_lattice/browser/browser_read_links.ts
2804
+ var import_zod18 = __toESM(require("zod"));
2805
+ var BROWSER_READ_LINKS_DESCRIPTION = `Get all links on the current page.
2806
+
2807
+ Args:
2808
+ None
2809
+
2810
+ `;
2811
+ registerToolLattice(
2812
+ "browser_read_links",
2813
+ {
2814
+ name: "browser_read_links",
2815
+ description: BROWSER_READ_LINKS_DESCRIPTION,
2816
+ needUserApprove: false,
2817
+ schema: import_zod18.default.object({})
2818
+ },
2819
+ async (input, exe_config) => {
2820
+ try {
2821
+ const runConfig = exe_config.configurable?.runConfig;
2822
+ const sandboxManager = getSandBoxManager();
2823
+ const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
2824
+ const result = await sandbox.mcp.executeMcpTool("browser", "browser_read_links", {});
2825
+ if (!result.ok) {
2826
+ return `Error reading links: ${JSON.stringify(result.error.content)}`;
2827
+ }
2828
+ return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Links retrieved successfully";
2829
+ } catch (e) {
2830
+ return `Error reading links: ${e instanceof Error ? e.message : String(e)}`;
2831
+ }
2832
+ }
2833
+ );
2834
+
2835
+ // src/tool_lattice/browser/browser_new_tab.ts
2836
+ var import_zod19 = __toESM(require("zod"));
2837
+ var BROWSER_NEW_TAB_DESCRIPTION = `Open a new tab.
2838
+
2839
+ Args:
2840
+ url (str): URL to open in the new tab
2841
+
2842
+ `;
2843
+ registerToolLattice(
2844
+ "browser_new_tab",
2845
+ {
2846
+ name: "browser_new_tab",
2847
+ description: BROWSER_NEW_TAB_DESCRIPTION,
2848
+ needUserApprove: false,
2849
+ schema: import_zod19.default.object({
2850
+ url: import_zod19.default.string().describe("URL to open in the new tab")
2851
+ })
2852
+ },
2853
+ async (input, exe_config) => {
2854
+ try {
2855
+ const runConfig = exe_config.configurable?.runConfig;
2856
+ const sandboxManager = getSandBoxManager();
2857
+ const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
2858
+ const result = await sandbox.mcp.executeMcpTool("browser", "browser_new_tab", {
2859
+ url: input.url
2860
+ });
2861
+ if (!result.ok) {
2862
+ return `Error opening new tab: ${JSON.stringify(result.error.content)}`;
2863
+ }
2864
+ return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "New tab opened successfully";
2865
+ } catch (e) {
2866
+ return `Error opening new tab: ${e instanceof Error ? e.message : String(e)}`;
2867
+ }
2868
+ }
2869
+ );
2870
+
2871
+ // src/tool_lattice/browser/browser_tab_list.ts
2872
+ var import_zod20 = __toESM(require("zod"));
2873
+ var BROWSER_TAB_LIST_DESCRIPTION = `Get the list of tabs.
2874
+
2875
+ Args:
2876
+ None
2877
+
2878
+ `;
2879
+ registerToolLattice(
2880
+ "browser_tab_list",
2881
+ {
2882
+ name: "browser_tab_list",
2883
+ description: BROWSER_TAB_LIST_DESCRIPTION,
2884
+ needUserApprove: false,
2885
+ schema: import_zod20.default.object({})
2886
+ },
2887
+ async (input, exe_config) => {
2888
+ try {
2889
+ const runConfig = exe_config.configurable?.runConfig;
2890
+ const sandboxManager = getSandBoxManager();
2891
+ const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
2892
+ const result = await sandbox.mcp.executeMcpTool("browser", "browser_tab_list", {});
2893
+ if (!result.ok) {
2894
+ return `Error getting tab list: ${JSON.stringify(result.error.content)}`;
2895
+ }
2896
+ return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Tab list retrieved successfully";
2897
+ } catch (e) {
2898
+ return `Error getting tab list: ${e instanceof Error ? e.message : String(e)}`;
2899
+ }
2900
+ }
2901
+ );
2902
+
2903
+ // src/tool_lattice/browser/browser_switch_tab.ts
2904
+ var import_zod21 = __toESM(require("zod"));
2905
+ var BROWSER_SWITCH_TAB_DESCRIPTION = `Switch to a specific tab.
2906
+
2907
+ Args:
2908
+ index (int): Tab index to switch to
2909
+
2910
+ `;
2911
+ registerToolLattice(
2912
+ "browser_switch_tab",
2913
+ {
2914
+ name: "browser_switch_tab",
2915
+ description: BROWSER_SWITCH_TAB_DESCRIPTION,
2916
+ needUserApprove: false,
2917
+ schema: import_zod21.default.object({
2918
+ index: import_zod21.default.number().describe("Tab index to switch to")
2919
+ })
2920
+ },
2921
+ async (input, exe_config) => {
2922
+ try {
2923
+ const runConfig = exe_config.configurable?.runConfig;
2924
+ const sandboxManager = getSandBoxManager();
2925
+ const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
2926
+ const result = await sandbox.mcp.executeMcpTool("browser", "browser_switch_tab", {
2927
+ index: input.index
2928
+ });
2929
+ if (!result.ok) {
2930
+ return `Error switching tab: ${JSON.stringify(result.error.content)}`;
2931
+ }
2932
+ return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Tab switched successfully";
2933
+ } catch (e) {
2934
+ return `Error switching tab: ${e instanceof Error ? e.message : String(e)}`;
2935
+ }
2936
+ }
2937
+ );
2938
+
2939
+ // src/tool_lattice/browser/browser_close_tab.ts
2940
+ var import_zod22 = __toESM(require("zod"));
2941
+ var BROWSER_CLOSE_TAB_DESCRIPTION = `Close the current tab.
2942
+
2943
+ Args:
2944
+ None
2945
+
2946
+ `;
2947
+ registerToolLattice(
2948
+ "browser_close_tab",
2949
+ {
2950
+ name: "browser_close_tab",
2951
+ description: BROWSER_CLOSE_TAB_DESCRIPTION,
2952
+ needUserApprove: false,
2953
+ schema: import_zod22.default.object({})
2954
+ },
2955
+ async (input, exe_config) => {
2956
+ try {
2957
+ const runConfig = exe_config.configurable?.runConfig;
2958
+ const sandboxManager = getSandBoxManager();
2959
+ const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
2960
+ const result = await sandbox.mcp.executeMcpTool("browser", "browser_close_tab", {});
2961
+ if (!result.ok) {
2962
+ return `Error closing tab: ${JSON.stringify(result.error.content)}`;
2963
+ }
2964
+ return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Current tab closed successfully";
2965
+ } catch (e) {
2966
+ return `Error closing tab: ${e instanceof Error ? e.message : String(e)}`;
2967
+ }
2968
+ }
2969
+ );
2970
+
2971
+ // src/tool_lattice/browser/browser_evaluate.ts
2972
+ var import_zod23 = __toESM(require("zod"));
2973
+ var BROWSER_EVALUATE_DESCRIPTION = `Execute JavaScript in the browser console.
2974
+
2975
+ Args:
2976
+ script (str): JavaScript code to execute, () => { /* code */ }
2977
+
2978
+ `;
2979
+ registerToolLattice(
2980
+ "browser_evaluate",
2981
+ {
2982
+ name: "browser_evaluate",
2983
+ description: BROWSER_EVALUATE_DESCRIPTION,
2984
+ needUserApprove: false,
2985
+ schema: import_zod23.default.object({
2986
+ script: import_zod23.default.string().describe("JavaScript code to execute, () => { /* code */ }")
2987
+ })
2988
+ },
2989
+ async (input, exe_config) => {
2990
+ try {
2991
+ const runConfig = exe_config.configurable?.runConfig;
2992
+ const sandboxManager = getSandBoxManager();
2993
+ const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
2994
+ const result = await sandbox.mcp.executeMcpTool("browser", "browser_evaluate", {
2995
+ script: input.script
2996
+ });
2997
+ if (!result.ok) {
2998
+ return `Error executing JavaScript: ${JSON.stringify(result.error.content)}`;
2999
+ }
3000
+ return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "JavaScript executed successfully";
3001
+ } catch (e) {
3002
+ return `Error executing JavaScript: ${e instanceof Error ? e.message : String(e)}`;
3003
+ }
3004
+ }
3005
+ );
3006
+
3007
+ // src/tool_lattice/browser/browser_get_download_list.ts
3008
+ var import_zod24 = __toESM(require("zod"));
3009
+ var BROWSER_GET_DOWNLOAD_LIST_DESCRIPTION = `Get the list of downloaded files.
3010
+
3011
+ Args:
3012
+ None
3013
+
3014
+ `;
3015
+ registerToolLattice(
3016
+ "browser_get_download_list",
3017
+ {
3018
+ name: "browser_get_download_list",
3019
+ description: BROWSER_GET_DOWNLOAD_LIST_DESCRIPTION,
3020
+ needUserApprove: false,
3021
+ schema: import_zod24.default.object({})
3022
+ },
3023
+ async (input, exe_config) => {
3024
+ try {
3025
+ const runConfig = exe_config.configurable?.runConfig;
3026
+ const sandboxManager = getSandBoxManager();
3027
+ const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
3028
+ const result = await sandbox.mcp.executeMcpTool("browser", "browser_get_download_list", {});
3029
+ if (!result.ok) {
3030
+ return `Error getting download list: ${JSON.stringify(result.error.content)}`;
3031
+ }
3032
+ return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Download list retrieved successfully";
3033
+ } catch (e) {
3034
+ return `Error getting download list: ${e instanceof Error ? e.message : String(e)}`;
3035
+ }
3036
+ }
3037
+ );
3038
+
3039
+ // src/tool_lattice/browser/browser_screenshot.ts
3040
+ var import_zod25 = __toESM(require("zod"));
3041
+ var BROWSER_SCREENSHOT_DESCRIPTION = `Take a screenshot of the current page or a specific element.
3042
+
3043
+ Args:
3044
+ name (str): Name for the screenshot
3045
+ selector (str): CSS selector for element to screenshot
3046
+ index (int): index of the element to screenshot
3047
+ width (int): Width in pixels (default: viewport width)
3048
+ height (int): Height in pixels (default: viewport height)
3049
+ fullPage (bool): Full page screenshot (default: false)
3050
+ highlight (bool): Highlight the element
3051
+
3052
+ `;
3053
+ registerToolLattice(
3054
+ "browser_screenshot",
3055
+ {
3056
+ name: "browser_screenshot",
3057
+ description: BROWSER_SCREENSHOT_DESCRIPTION,
3058
+ needUserApprove: false,
3059
+ schema: import_zod25.default.object({
3060
+ name: import_zod25.default.string().optional().describe("Name for the screenshot"),
3061
+ selector: import_zod25.default.string().optional().describe("CSS selector for element to screenshot"),
3062
+ index: import_zod25.default.number().optional().describe("index of the element to screenshot"),
3063
+ width: import_zod25.default.number().optional().describe("Width in pixels (default: viewport width)"),
3064
+ height: import_zod25.default.number().optional().describe("Height in pixels (default: viewport height)"),
3065
+ fullPage: import_zod25.default.boolean().optional().describe("Full page screenshot (default: false)"),
3066
+ highlight: import_zod25.default.boolean().default(false).describe("Highlight the element")
3067
+ })
3068
+ },
3069
+ async (input, exe_config) => {
3070
+ try {
3071
+ const runConfig = exe_config.configurable?.runConfig;
3072
+ const sandboxManager = getSandBoxManager();
3073
+ const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
3074
+ const result = await sandbox.mcp.executeMcpTool("browser", "browser_screenshot", {
3075
+ name: input.name,
3076
+ selector: input.selector,
3077
+ index: input.index,
3078
+ width: input.width,
3079
+ height: input.height,
3080
+ fullPage: input.fullPage,
3081
+ highlight: input.highlight
3082
+ });
3083
+ if (!result.ok) {
3084
+ return `Error taking screenshot: ${JSON.stringify(result.error.content)}`;
3085
+ }
3086
+ return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Screenshot taken successfully";
3087
+ } catch (e) {
3088
+ return `Error taking screenshot: ${e instanceof Error ? e.message : String(e)}`;
3089
+ }
3090
+ }
3091
+ );
3092
+
3093
+ // src/tool_lattice/browser/browser_click.ts
3094
+ var import_zod26 = __toESM(require("zod"));
3095
+ var BROWSER_CLICK_DESCRIPTION = `Click an element on the page, before using the tool, use \`browser_get_clickable_elements\` to get the index of the element, but not call \`browser_get_clickable_elements\` multiple times.
3096
+
3097
+ Args:
3098
+ index (int): Index of the element to click
3099
+
3100
+ `;
3101
+ registerToolLattice(
3102
+ "browser_click",
3103
+ {
3104
+ name: "browser_click",
3105
+ description: BROWSER_CLICK_DESCRIPTION,
3106
+ needUserApprove: false,
3107
+ schema: import_zod26.default.object({
3108
+ index: import_zod26.default.number().describe("Index of the element to click")
3109
+ })
3110
+ },
3111
+ async (input, exe_config) => {
3112
+ try {
3113
+ const runConfig = exe_config.configurable?.runConfig;
3114
+ const sandboxManager = getSandBoxManager();
3115
+ const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
3116
+ const result = await sandbox.mcp.executeMcpTool("browser", "browser_click", {
3117
+ index: input.index
3118
+ });
3119
+ if (!result.ok) {
3120
+ return `Error clicking element: ${JSON.stringify(result.error.content)}`;
3121
+ }
3122
+ return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Element clicked successfully";
3123
+ } catch (e) {
3124
+ return `Error clicking element: ${e instanceof Error ? e.message : String(e)}`;
3125
+ }
3126
+ }
3127
+ );
3128
+
3129
+ // src/tool_lattice/browser/browser_select.ts
3130
+ var import_zod27 = __toESM(require("zod"));
3131
+ var BROWSER_SELECT_DESCRIPTION = `Select an element on the page with index, Either 'index' or 'selector' must be provided.
3132
+
3133
+ Args:
3134
+ index (int): Index of the element to select
3135
+ selector (str): CSS selector for element to select
3136
+ value (str): Value to select
3137
+
3138
+ `;
3139
+ registerToolLattice(
3140
+ "browser_select",
3141
+ {
3142
+ name: "browser_select",
3143
+ description: BROWSER_SELECT_DESCRIPTION,
3144
+ needUserApprove: false,
3145
+ schema: import_zod27.default.object({
3146
+ index: import_zod27.default.number().optional().describe("Index of the element to select"),
3147
+ selector: import_zod27.default.string().optional().describe("CSS selector for element to select"),
3148
+ value: import_zod27.default.string().describe("Value to select")
3149
+ })
3150
+ },
3151
+ async (input, exe_config) => {
3152
+ try {
3153
+ const runConfig = exe_config.configurable?.runConfig;
3154
+ const sandboxManager = getSandBoxManager();
3155
+ const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
3156
+ const result = await sandbox.mcp.executeMcpTool("browser", "browser_select", {
3157
+ index: input.index,
3158
+ selector: input.selector,
3159
+ value: input.value
3160
+ });
3161
+ if (!result.ok) {
3162
+ return `Error selecting element: ${JSON.stringify(result.error.content)}`;
3163
+ }
3164
+ return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Element selected successfully";
3165
+ } catch (e) {
3166
+ return `Error selecting element: ${e instanceof Error ? e.message : String(e)}`;
3167
+ }
3168
+ }
3169
+ );
3170
+
3171
+ // src/tool_lattice/browser/browser_hover.ts
3172
+ var import_zod28 = __toESM(require("zod"));
3173
+ var BROWSER_HOVER_DESCRIPTION = `Hover an element on the page, Either 'index' or 'selector' must be provided.
3174
+
3175
+ Args:
3176
+ index (int): Index of the element to hover
3177
+ selector (str): CSS selector for element to hover
3178
+
3179
+ `;
3180
+ registerToolLattice(
3181
+ "browser_hover",
3182
+ {
3183
+ name: "browser_hover",
3184
+ description: BROWSER_HOVER_DESCRIPTION,
3185
+ needUserApprove: false,
3186
+ schema: import_zod28.default.object({
3187
+ index: import_zod28.default.number().optional().describe("Index of the element to hover"),
3188
+ selector: import_zod28.default.string().optional().describe("CSS selector for element to hover")
3189
+ })
3190
+ },
3191
+ async (input, exe_config) => {
3192
+ try {
3193
+ const runConfig = exe_config.configurable?.runConfig;
3194
+ const sandboxManager = getSandBoxManager();
3195
+ const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
3196
+ const result = await sandbox.mcp.executeMcpTool("browser", "browser_hover", {
3197
+ index: input.index,
3198
+ selector: input.selector
3199
+ });
3200
+ if (!result.ok) {
3201
+ return `Error hovering element: ${JSON.stringify(result.error.content)}`;
3202
+ }
3203
+ return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Element hovered successfully";
3204
+ } catch (e) {
3205
+ return `Error hovering element: ${e instanceof Error ? e.message : String(e)}`;
3206
+ }
3207
+ }
3208
+ );
2026
3209
 
2027
- // src/tool_lattice/load_skills/index.ts
2028
- var LOAD_SKILLS_DESCRIPTION = `Load all available skills and return their metadata (name, description, license, compatibility, metadata, and subSkills) without the content. This tool returns skill information including hierarchical relationships (subSkills). Use this to discover what skills are available and their structure. Skills can have sub-skills, creating a tree structure for organizing capabilities.`;
3210
+ // src/tool_lattice/browser/browser_get_clickable_elements.ts
3211
+ var import_zod29 = __toESM(require("zod"));
3212
+ var BROWSER_GET_CLICKABLE_ELEMENTS_DESCRIPTION = `Get the clickable or hoverable or selectable elements on the current page, don't call this tool multiple times.
3213
+
3214
+ Args:
3215
+ None
3216
+
3217
+ `;
2029
3218
  registerToolLattice(
2030
- "load_skills",
3219
+ "browser_get_clickable_elements",
2031
3220
  {
2032
- name: "load_skills",
2033
- description: LOAD_SKILLS_DESCRIPTION,
3221
+ name: "browser_get_clickable_elements",
3222
+ description: BROWSER_GET_CLICKABLE_ELEMENTS_DESCRIPTION,
2034
3223
  needUserApprove: false,
2035
- schema: import_zod7.default.object({})
3224
+ schema: import_zod29.default.object({})
2036
3225
  },
2037
- async () => {
3226
+ async (input, exe_config) => {
2038
3227
  try {
2039
- const storeLattice = getStoreLattice("default", "skill");
2040
- const skillStore = storeLattice.store;
2041
- const skills = await skillStore.getAllSkills();
2042
- const skillsMeta = skills.map((skill) => ({
2043
- name: skill.name,
2044
- description: skill.description,
2045
- license: skill.license,
2046
- compatibility: skill.compatibility,
2047
- metadata: skill.metadata,
2048
- subSkills: skill.subSkills
2049
- }));
2050
- return JSON.stringify(skillsMeta, null, 2);
2051
- } catch (error) {
2052
- return `Error loading skills: ${error instanceof Error ? error.message : String(error)}`;
3228
+ const runConfig = exe_config.configurable?.runConfig;
3229
+ const sandboxManager = getSandBoxManager();
3230
+ const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
3231
+ const result = await sandbox.mcp.executeMcpTool("browser", "browser_get_clickable_elements", {});
3232
+ if (!result.ok) {
3233
+ return `Error getting clickable elements: ${JSON.stringify(result.error.content)}`;
3234
+ }
3235
+ return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Clickable elements retrieved successfully";
3236
+ } catch (e) {
3237
+ return `Error getting clickable elements: ${e instanceof Error ? e.message : String(e)}`;
2053
3238
  }
2054
3239
  }
2055
3240
  );
2056
3241
 
2057
- // src/tool_lattice/load_skill_content/index.ts
2058
- var import_zod8 = __toESM(require("zod"));
2059
- var LOAD_SKILL_CONTENT_DESCRIPTION = `Load a specific skill's content by name and return its full content including markdown body. This tool returns the complete skill content including frontmatter and markdown body. If the skill has sub-skills defined, they will be listed in the frontmatter. Use this tool to get the complete skill content for a skill that you want to use.`;
3242
+ // src/tool_lattice/browser/browser_scroll.ts
3243
+ var import_zod30 = __toESM(require("zod"));
3244
+ var BROWSER_SCROLL_DESCRIPTION = `Scroll the page.
3245
+
3246
+ Args:
3247
+ amount (int): Pixels to scroll (positive for down, negative for up), if the amount is not provided, scroll to the bottom of the page
3248
+
3249
+ `;
2060
3250
  registerToolLattice(
2061
- "load_skill_content",
3251
+ "browser_scroll",
2062
3252
  {
2063
- name: "load_skill_content",
2064
- description: LOAD_SKILL_CONTENT_DESCRIPTION,
3253
+ name: "browser_scroll",
3254
+ description: BROWSER_SCROLL_DESCRIPTION,
2065
3255
  needUserApprove: false,
2066
- schema: import_zod8.default.object({
2067
- skill_name: import_zod8.default.string().describe("The name of the skill to load")
3256
+ schema: import_zod30.default.object({
3257
+ amount: import_zod30.default.number().optional().describe("Pixels to scroll (positive for down, negative for up), if the amount is not provided, scroll to the bottom of the page")
2068
3258
  })
2069
3259
  },
2070
- async (input) => {
3260
+ async (input, exe_config) => {
2071
3261
  try {
2072
- const storeLattice = getStoreLattice("default", "skill");
2073
- const skillStore = storeLattice.store;
2074
- const skill = await skillStore.getSkillById(input.skill_name);
2075
- if (!skill) {
2076
- const allSkills = await skillStore.getAllSkills();
2077
- const availableSkills = allSkills.map((s) => s.name).join(", ");
2078
- return `Skill "${input.skill_name}" not found. Available skills: ${availableSkills}`;
2079
- }
2080
- const frontmatter = ["---"];
2081
- frontmatter.push(`name: ${skill.name}`);
2082
- frontmatter.push(`description: ${skill.description}`);
2083
- if (skill.license) {
2084
- frontmatter.push(`license: ${skill.license}`);
2085
- }
2086
- if (skill.compatibility) {
2087
- frontmatter.push(`compatibility: ${skill.compatibility}`);
3262
+ const runConfig = exe_config.configurable?.runConfig;
3263
+ const sandboxManager = getSandBoxManager();
3264
+ const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
3265
+ const result = await sandbox.mcp.executeMcpTool("browser", "browser_scroll", {
3266
+ amount: input.amount
3267
+ });
3268
+ if (!result.ok) {
3269
+ return `Error scrolling page: ${JSON.stringify(result.error.content)}`;
2088
3270
  }
2089
- if (skill.metadata && Object.keys(skill.metadata).length > 0) {
2090
- frontmatter.push("metadata:");
2091
- for (const [key, value] of Object.entries(skill.metadata)) {
2092
- frontmatter.push(` ${key}: ${value}`);
2093
- }
3271
+ return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Page scrolled successfully";
3272
+ } catch (e) {
3273
+ return `Error scrolling page: ${e instanceof Error ? e.message : String(e)}`;
3274
+ }
3275
+ }
3276
+ );
3277
+
3278
+ // src/tool_lattice/browser/browser_close.ts
3279
+ var import_zod31 = __toESM(require("zod"));
3280
+ var BROWSER_CLOSE_DESCRIPTION = `Close the browser when the task is done and the browser is not needed anymore.
3281
+
3282
+ Args:
3283
+ None
3284
+
3285
+ `;
3286
+ registerToolLattice(
3287
+ "browser_close",
3288
+ {
3289
+ name: "browser_close",
3290
+ description: BROWSER_CLOSE_DESCRIPTION,
3291
+ needUserApprove: false,
3292
+ schema: import_zod31.default.object({})
3293
+ },
3294
+ async (input, exe_config) => {
3295
+ try {
3296
+ const runConfig = exe_config.configurable?.runConfig;
3297
+ const sandboxManager = getSandBoxManager();
3298
+ const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
3299
+ const result = await sandbox.mcp.executeMcpTool("browser", "browser_close", {});
3300
+ if (!result.ok) {
3301
+ return `Error closing browser: ${JSON.stringify(result.error.content)}`;
2094
3302
  }
2095
- if (skill.subSkills && skill.subSkills.length > 0) {
2096
- frontmatter.push("subSkills:");
2097
- for (const subSkill of skill.subSkills) {
2098
- frontmatter.push(` - ${subSkill}`);
2099
- }
3303
+ return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Browser closed successfully";
3304
+ } catch (e) {
3305
+ return `Error closing browser: ${e instanceof Error ? e.message : String(e)}`;
3306
+ }
3307
+ }
3308
+ );
3309
+
3310
+ // src/tool_lattice/browser/browser_press_key.ts
3311
+ var import_zod32 = __toESM(require("zod"));
3312
+ var BROWSER_PRESS_KEY_DESCRIPTION = `Press a key on the keyboard.
3313
+
3314
+ Args:
3315
+ key (str): Name of the key to press or a character to generate, such as Enter, Tab, Escape, Backspace, Delete, Insert, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, ArrowLeft, ArrowRight, ArrowUp, ArrowDown, PageUp, PageDown, Home, End, ShiftLeft, ShiftRight, ControlLeft, ControlRight, AltLeft, AltRight, MetaLeft, MetaRight, CapsLock, PrintScreen, ScrollLock, Pause, ContextMenu
3316
+
3317
+ `;
3318
+ registerToolLattice(
3319
+ "browser_press_key",
3320
+ {
3321
+ name: "browser_press_key",
3322
+ description: BROWSER_PRESS_KEY_DESCRIPTION,
3323
+ needUserApprove: false,
3324
+ schema: import_zod32.default.object({
3325
+ key: import_zod32.default.enum([
3326
+ "Enter",
3327
+ "Tab",
3328
+ "Escape",
3329
+ "Backspace",
3330
+ "Delete",
3331
+ "Insert",
3332
+ "F1",
3333
+ "F2",
3334
+ "F3",
3335
+ "F4",
3336
+ "F5",
3337
+ "F6",
3338
+ "F7",
3339
+ "F8",
3340
+ "F9",
3341
+ "F10",
3342
+ "F11",
3343
+ "F12",
3344
+ "ArrowLeft",
3345
+ "ArrowRight",
3346
+ "ArrowUp",
3347
+ "ArrowDown",
3348
+ "PageUp",
3349
+ "PageDown",
3350
+ "Home",
3351
+ "End",
3352
+ "ShiftLeft",
3353
+ "ShiftRight",
3354
+ "ControlLeft",
3355
+ "ControlRight",
3356
+ "AltLeft",
3357
+ "AltRight",
3358
+ "MetaLeft",
3359
+ "MetaRight",
3360
+ "CapsLock",
3361
+ "PrintScreen",
3362
+ "ScrollLock",
3363
+ "Pause",
3364
+ "ContextMenu"
3365
+ ]).describe("Name of the key to press or a character to generate, such as Enter, Tab, Escape, Backspace, Delete, Insert, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, ArrowLeft, ArrowRight, ArrowUp, ArrowDown, PageUp, PageDown, Home, End, ShiftLeft, ShiftRight, ControlLeft, ControlRight, AltLeft, AltRight, MetaLeft, MetaRight, CapsLock, PrintScreen, ScrollLock, Pause, ContextMenu")
3366
+ })
3367
+ },
3368
+ async (input, exe_config) => {
3369
+ try {
3370
+ const runConfig = exe_config.configurable?.runConfig;
3371
+ const sandboxManager = getSandBoxManager();
3372
+ const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
3373
+ const result = await sandbox.mcp.executeMcpTool("browser", "browser_press_key", {
3374
+ key: input.key
3375
+ });
3376
+ if (!result.ok) {
3377
+ return `Error pressing key: ${JSON.stringify(result.error.content)}`;
2100
3378
  }
2101
- frontmatter.push("---");
2102
- const content = skill.content || "";
2103
- return `${frontmatter.join("\n")}
2104
- ${content}`;
2105
- } catch (error) {
2106
- return `Error loading skill content: ${error instanceof Error ? error.message : String(error)}`;
3379
+ return result.body?.data?.content?.map((item) => item.text).join("\n") ?? `Key ${input.key} pressed successfully`;
3380
+ } catch (e) {
3381
+ return `Error pressing key: ${e instanceof Error ? e.message : String(e)}`;
2107
3382
  }
2108
3383
  }
2109
3384
  );
@@ -2192,7 +3467,7 @@ var memory = new import_langgraph2.MemorySaver();
2192
3467
  registerCheckpointSaver("default", memory);
2193
3468
 
2194
3469
  // src/agent_lattice/builders/state.ts
2195
- var import_zod9 = require("@langchain/langgraph/zod");
3470
+ var import_zod33 = require("@langchain/langgraph/zod");
2196
3471
  var import_langgraph3 = require("@langchain/langgraph");
2197
3472
  var createReactAgentSchema = (schema) => {
2198
3473
  return schema ? import_langgraph3.MessagesZodState.extend(schema.shape) : void 0;
@@ -2210,9 +3485,9 @@ var ReActAgentGraphBuilder = class {
2210
3485
  */
2211
3486
  build(agentLattice, params) {
2212
3487
  const tools = params.tools.map((t) => {
2213
- const tool5 = getToolClient(t.key);
2214
- return tool5;
2215
- }).filter((tool5) => tool5 !== void 0);
3488
+ const tool7 = getToolClient(t.key);
3489
+ return tool7;
3490
+ }).filter((tool7) => tool7 !== void 0);
2216
3491
  const stateSchema2 = createReactAgentSchema(params.stateSchema);
2217
3492
  return (0, import_langchain.createAgent)({
2218
3493
  model: params.model,
@@ -2232,7 +3507,7 @@ var import_langchain7 = require("langchain");
2232
3507
  var import_langchain2 = require("langchain");
2233
3508
  var import_langgraph4 = require("@langchain/langgraph");
2234
3509
  var import_v3 = require("zod/v3");
2235
- var import_zod10 = require("@langchain/langgraph/zod");
3510
+ var import_zod34 = require("@langchain/langgraph/zod");
2236
3511
 
2237
3512
  // src/deep_agent_new/backends/utils.ts
2238
3513
  var import_micromatch = __toESM(require("micromatch"));
@@ -2335,8 +3610,8 @@ function performStringReplacement(content, oldString, newString, replaceAll) {
2335
3610
  const newContent = content.split(oldString).join(newString);
2336
3611
  return [newContent, occurrences];
2337
3612
  }
2338
- function validatePath(path2) {
2339
- const pathStr = path2 || "/";
3613
+ function validatePath(path4) {
3614
+ const pathStr = path4 || "/";
2340
3615
  if (!pathStr || pathStr.trim() === "") {
2341
3616
  throw new Error("Path cannot be empty");
2342
3617
  }
@@ -2346,10 +3621,10 @@ function validatePath(path2) {
2346
3621
  }
2347
3622
  return normalized;
2348
3623
  }
2349
- function globSearchFiles(files, pattern, path2 = "/") {
3624
+ function globSearchFiles(files, pattern, path4 = "/") {
2350
3625
  let normalizedPath;
2351
3626
  try {
2352
- normalizedPath = validatePath(path2);
3627
+ normalizedPath = validatePath(path4);
2353
3628
  } catch {
2354
3629
  return "No files found";
2355
3630
  }
@@ -2359,15 +3634,15 @@ function globSearchFiles(files, pattern, path2 = "/") {
2359
3634
  const effectivePattern = pattern;
2360
3635
  const matches = [];
2361
3636
  for (const [filePath, fileData] of Object.entries(filtered)) {
2362
- let relative = filePath.substring(normalizedPath.length);
2363
- if (relative.startsWith("/")) {
2364
- relative = relative.substring(1);
3637
+ let relative2 = filePath.substring(normalizedPath.length);
3638
+ if (relative2.startsWith("/")) {
3639
+ relative2 = relative2.substring(1);
2365
3640
  }
2366
- if (!relative) {
3641
+ if (!relative2) {
2367
3642
  const parts = filePath.split("/");
2368
- relative = parts[parts.length - 1] || "";
3643
+ relative2 = parts[parts.length - 1] || "";
2369
3644
  }
2370
- if (import_micromatch.default.isMatch(relative, effectivePattern, {
3645
+ if (import_micromatch.default.isMatch(relative2, effectivePattern, {
2371
3646
  dot: true,
2372
3647
  nobrace: false
2373
3648
  })) {
@@ -2380,7 +3655,7 @@ function globSearchFiles(files, pattern, path2 = "/") {
2380
3655
  }
2381
3656
  return matches.map(([fp]) => fp).join("\n");
2382
3657
  }
2383
- function grepMatchesFromFiles(files, pattern, path2 = null, glob = null) {
3658
+ function grepMatchesFromFiles(files, pattern, path4 = null, glob = null) {
2384
3659
  let regex;
2385
3660
  try {
2386
3661
  regex = new RegExp(pattern);
@@ -2389,7 +3664,7 @@ function grepMatchesFromFiles(files, pattern, path2 = null, glob = null) {
2389
3664
  }
2390
3665
  let normalizedPath;
2391
3666
  try {
2392
- normalizedPath = validatePath(path2);
3667
+ normalizedPath = validatePath(path4);
2393
3668
  } catch {
2394
3669
  return [];
2395
3670
  }
@@ -2434,18 +3709,18 @@ var StateBackend = class {
2434
3709
  * @returns List of FileInfo objects for files and directories directly in the directory.
2435
3710
  * Directories have a trailing / in their path and is_dir=true.
2436
3711
  */
2437
- lsInfo(path2) {
3712
+ lsInfo(path4) {
2438
3713
  const files = this.getFiles();
2439
3714
  const infos = [];
2440
3715
  const subdirs = /* @__PURE__ */ new Set();
2441
- const normalizedPath = path2.endsWith("/") ? path2 : path2 + "/";
3716
+ const normalizedPath = path4.endsWith("/") ? path4 : path4 + "/";
2442
3717
  for (const [k, fd] of Object.entries(files)) {
2443
3718
  if (!k.startsWith(normalizedPath)) {
2444
3719
  continue;
2445
3720
  }
2446
- const relative = k.substring(normalizedPath.length);
2447
- if (relative.includes("/")) {
2448
- const subdirName = relative.split("/")[0];
3721
+ const relative2 = k.substring(normalizedPath.length);
3722
+ if (relative2.includes("/")) {
3723
+ const subdirName = relative2.split("/")[0];
2449
3724
  subdirs.add(normalizedPath + subdirName + "/");
2450
3725
  continue;
2451
3726
  }
@@ -2544,16 +3819,16 @@ var StateBackend = class {
2544
3819
  /**
2545
3820
  * Structured search results or error string for invalid input.
2546
3821
  */
2547
- grepRaw(pattern, path2 = "/", glob = null) {
3822
+ grepRaw(pattern, path4 = "/", glob = null) {
2548
3823
  const files = this.getFiles();
2549
- return grepMatchesFromFiles(files, pattern, path2, glob);
3824
+ return grepMatchesFromFiles(files, pattern, path4, glob);
2550
3825
  }
2551
3826
  /**
2552
3827
  * Structured glob matching returning FileInfo objects.
2553
3828
  */
2554
- globInfo(pattern, path2 = "/") {
3829
+ globInfo(pattern, path4 = "/") {
2555
3830
  const files = this.getFiles();
2556
- const result = globSearchFiles(files, pattern, path2);
3831
+ const result = globSearchFiles(files, pattern, path4);
2557
3832
  if (result === "No files found") {
2558
3833
  return [];
2559
3834
  }
@@ -2600,7 +3875,7 @@ function fileDataReducer(left, right) {
2600
3875
  return result;
2601
3876
  }
2602
3877
  var FilesystemStateSchema = import_v3.z.object({
2603
- files: (0, import_zod10.withLangGraph)(
3878
+ files: (0, import_zod34.withLangGraph)(
2604
3879
  import_v3.z.record(import_v3.z.string(), FileDataSchema).default({}),
2605
3880
  {
2606
3881
  reducer: {
@@ -2610,9 +3885,9 @@ var FilesystemStateSchema = import_v3.z.object({
2610
3885
  }
2611
3886
  )
2612
3887
  });
2613
- function getBackend(backend, stateAndStore) {
3888
+ async function getBackend(backend, stateAndStore) {
2614
3889
  if (typeof backend === "function") {
2615
- return backend(stateAndStore);
3890
+ return await backend(stateAndStore);
2616
3891
  }
2617
3892
  return backend;
2618
3893
  }
@@ -2638,11 +3913,11 @@ function createLsTool(backend, options) {
2638
3913
  state: (0, import_langgraph4.getCurrentTaskInput)(config),
2639
3914
  store: config.store
2640
3915
  };
2641
- const resolvedBackend = getBackend(backend, stateAndStore);
2642
- const path2 = input.path || "/";
2643
- const infos = await resolvedBackend.lsInfo(path2);
3916
+ const resolvedBackend = await getBackend(backend, stateAndStore);
3917
+ const path4 = input.path || "/";
3918
+ const infos = await resolvedBackend.lsInfo(path4);
2644
3919
  if (infos.length === 0) {
2645
- return `No files found in ${path2}`;
3920
+ return `No files found in ${path4}`;
2646
3921
  }
2647
3922
  const lines = [];
2648
3923
  for (const info of infos) {
@@ -2672,7 +3947,7 @@ function createReadFileTool(backend, options) {
2672
3947
  state: (0, import_langgraph4.getCurrentTaskInput)(config),
2673
3948
  store: config.store
2674
3949
  };
2675
- const resolvedBackend = getBackend(backend, stateAndStore);
3950
+ const resolvedBackend = await getBackend(backend, stateAndStore);
2676
3951
  const { file_path, offset = 0, limit = 2e3 } = input;
2677
3952
  return await resolvedBackend.read(file_path, offset, limit);
2678
3953
  },
@@ -2695,7 +3970,7 @@ function createWriteFileTool(backend, options) {
2695
3970
  state: (0, import_langgraph4.getCurrentTaskInput)(config),
2696
3971
  store: config.store
2697
3972
  };
2698
- const resolvedBackend = getBackend(backend, stateAndStore);
3973
+ const resolvedBackend = await getBackend(backend, stateAndStore);
2699
3974
  const { file_path, content } = input;
2700
3975
  const result = await resolvedBackend.write(file_path, content);
2701
3976
  if (result.error) {
@@ -2732,7 +4007,7 @@ function createEditFileTool(backend, options) {
2732
4007
  state: (0, import_langgraph4.getCurrentTaskInput)(config),
2733
4008
  store: config.store
2734
4009
  };
2735
- const resolvedBackend = getBackend(backend, stateAndStore);
4010
+ const resolvedBackend = await getBackend(backend, stateAndStore);
2736
4011
  const { file_path, old_string, new_string, replace_all = false } = input;
2737
4012
  const result = await resolvedBackend.edit(
2738
4013
  file_path,
@@ -2776,9 +4051,9 @@ function createGlobTool(backend, options) {
2776
4051
  state: (0, import_langgraph4.getCurrentTaskInput)(config),
2777
4052
  store: config.store
2778
4053
  };
2779
- const resolvedBackend = getBackend(backend, stateAndStore);
2780
- const { pattern, path: path2 = "/" } = input;
2781
- const infos = await resolvedBackend.globInfo(pattern, path2);
4054
+ const resolvedBackend = await getBackend(backend, stateAndStore);
4055
+ const { pattern, path: path4 = "/" } = input;
4056
+ const infos = await resolvedBackend.globInfo(pattern, path4);
2782
4057
  if (infos.length === 0) {
2783
4058
  return `No files found matching pattern '${pattern}'`;
2784
4059
  }
@@ -2802,9 +4077,9 @@ function createGrepTool(backend, options) {
2802
4077
  state: (0, import_langgraph4.getCurrentTaskInput)(config),
2803
4078
  store: config.store
2804
4079
  };
2805
- const resolvedBackend = getBackend(backend, stateAndStore);
2806
- const { pattern, path: path2 = "/", glob = null } = input;
2807
- const result = await resolvedBackend.grepRaw(pattern, path2, glob);
4080
+ const resolvedBackend = await getBackend(backend, stateAndStore);
4081
+ const { pattern, path: path4 = "/", glob = null } = input;
4082
+ const result = await resolvedBackend.grepRaw(pattern, path4, glob);
2808
4083
  if (typeof result === "string") {
2809
4084
  return result;
2810
4085
  }
@@ -2836,7 +4111,7 @@ ${currentFile}:`);
2836
4111
  }
2837
4112
  function createFilesystemMiddleware(options = {}) {
2838
4113
  const {
2839
- backend = (stateAndStore) => new StateBackend(stateAndStore),
4114
+ backend = async (stateAndStore) => new StateBackend(stateAndStore),
2840
4115
  systemPrompt: customSystemPrompt = null,
2841
4116
  customToolDescriptions = null,
2842
4117
  toolTokenLimitBeforeEvict = 2e4
@@ -2881,7 +4156,7 @@ ${systemPrompt}` : systemPrompt;
2881
4156
  state: request.state || {},
2882
4157
  store: request.config?.store
2883
4158
  };
2884
- const resolvedBackend = getBackend(backend, stateAndStore);
4159
+ const resolvedBackend = await getBackend(backend, stateAndStore);
2885
4160
  const sanitizedId = sanitizeToolCallId(
2886
4161
  request.toolCall?.id || msg.tool_call_id
2887
4162
  );
@@ -3723,7 +4998,7 @@ var SUPPORTS_NOFOLLOW = fsSync.constants.O_NOFOLLOW !== void 0;
3723
4998
 
3724
4999
  // src/deep_agent_new/middleware/todos.ts
3725
5000
  var import_langgraph8 = require("@langchain/langgraph");
3726
- var import_zod11 = require("zod");
5001
+ var import_zod35 = require("zod");
3727
5002
  var import_langchain5 = require("langchain");
3728
5003
  var WRITE_TODOS_DESCRIPTION = `Use this tool to create and manage a structured task list for your current work session. This helps you track progress, organize complex tasks, and demonstrate thoroughness to the user.
3729
5004
  It also helps the user understand the progress of the task and overall progress of their requests.
@@ -3951,12 +5226,12 @@ Writing todos takes time and tokens, use it when it is helpful for managing comp
3951
5226
  ## Important To-Do List Usage Notes to Remember
3952
5227
  - The \`write_todos\` tool should never be called multiple times in parallel.
3953
5228
  - Don't be afraid to revise the To-Do list as you go. New information may reveal new tasks that need to be done, or old tasks that are irrelevant.`;
3954
- var TodoStatus = import_zod11.z.enum(["pending", "in_progress", "completed"]).describe("Status of the todo");
3955
- var TodoSchema = import_zod11.z.object({
3956
- content: import_zod11.z.string().describe("Content of the todo item"),
5229
+ var TodoStatus = import_zod35.z.enum(["pending", "in_progress", "completed"]).describe("Status of the todo");
5230
+ var TodoSchema = import_zod35.z.object({
5231
+ content: import_zod35.z.string().describe("Content of the todo item"),
3957
5232
  status: TodoStatus
3958
5233
  });
3959
- var stateSchema = import_zod11.z.object({ todos: import_zod11.z.array(TodoSchema).default([]) });
5234
+ var stateSchema = import_zod35.z.object({ todos: import_zod35.z.array(TodoSchema).default([]) });
3960
5235
  function todoListMiddleware(options) {
3961
5236
  const writeTodos = (0, import_langchain5.tool)(
3962
5237
  ({ todos }, config) => {
@@ -3975,8 +5250,8 @@ function todoListMiddleware(options) {
3975
5250
  {
3976
5251
  name: "write_todos",
3977
5252
  description: options?.toolDescription ?? WRITE_TODOS_DESCRIPTION,
3978
- schema: import_zod11.z.object({
3979
- todos: import_zod11.z.array(TodoSchema).describe("List of todo items to update")
5253
+ schema: import_zod35.z.object({
5254
+ todos: import_zod35.z.array(TodoSchema).describe("List of todo items to update")
3980
5255
  })
3981
5256
  }
3982
5257
  );
@@ -4064,7 +5339,7 @@ function createDeepAgent(params = {}) {
4064
5339
  const finalSystemPrompt = systemPrompt ? `${systemPrompt}
4065
5340
 
4066
5341
  ${BASE_PROMPT}` : BASE_PROMPT;
4067
- const filesystemBackend = backend ? backend : (config) => new StateBackend(config);
5342
+ const filesystemBackend = backend ? backend : async (config) => new StateBackend(config);
4068
5343
  const middleware = [
4069
5344
  // Provides todo list management capabilities for tracking tasks
4070
5345
  todoListMiddleware(),
@@ -4129,6 +5404,303 @@ ${BASE_PROMPT}` : BASE_PROMPT;
4129
5404
  });
4130
5405
  }
4131
5406
 
5407
+ // src/deep_agent_new/backends/sandboxFiles.ts
5408
+ var import_sandbox2 = require("@agent-infra/sandbox");
5409
+ var path3 = __toESM(require("path"));
5410
+ var SandboxFilesystem = class {
5411
+ /**
5412
+ * Create a new SandboxFilesystem instance.
5413
+ *
5414
+ * @param options - Configuration options
5415
+ * @param options.baseURL - Base URL of the sandbox service (default: 'http://localhost:8080')
5416
+ * @param options.maxFileSizeMb - Maximum file size in MB (default: 10)
5417
+ * @param options.sandboxInstance - Optional Sandbox instance (if provided, baseURL is ignored)
5418
+ */
5419
+ constructor(options = {}) {
5420
+ const {
5421
+ baseURL = "http://localhost:8080",
5422
+ workingDirectory = "/",
5423
+ maxFileSizeMb = 10,
5424
+ sandboxInstance
5425
+ } = options;
5426
+ this.sandbox = sandboxInstance || new import_sandbox2.SandboxClient({ baseUrl: baseURL, environment: "" });
5427
+ this.sandbox.mcp.listMcpServers().then((servers) => {
5428
+ });
5429
+ this.sandbox.mcp.listMcpTools("browser").then((tools) => {
5430
+ console.log(tools);
5431
+ });
5432
+ this.baseURL = baseURL;
5433
+ this.maxFileSizeBytes = maxFileSizeMb * 1024 * 1024;
5434
+ this.workingDirectory = workingDirectory;
5435
+ this.homeDir = "/home/gem";
5436
+ }
5437
+ resolvePath(virtualPath) {
5438
+ return path3.join(this.homeDir, this.workingDirectory, virtualPath);
5439
+ }
5440
+ /**
5441
+ * Convert a real filesystem path to a virtual path.
5442
+ *
5443
+ * @param realPath - Real filesystem path
5444
+ * @returns Virtual path starting with /
5445
+ */
5446
+ toVirtualPath(realPath) {
5447
+ const rootPath = path3.join(this.homeDir, this.workingDirectory);
5448
+ const relative2 = path3.relative(rootPath, realPath);
5449
+ const normalized = relative2.split(path3.sep).join("/");
5450
+ return "/" + normalized;
5451
+ }
5452
+ /**
5453
+ * List files and directories in the specified directory (non-recursive).
5454
+ *
5455
+ * @param dirPath - Virtual directory path (must start with /)
5456
+ * @returns List of FileInfo objects for files and directories directly in the directory.
5457
+ * Directories have a trailing / in their path and is_dir=true.
5458
+ */
5459
+ async lsInfo(dirPath) {
5460
+ try {
5461
+ const resolvedPath = this.resolvePath(dirPath);
5462
+ const result = await this.sandbox.file.listPath({
5463
+ path: resolvedPath,
5464
+ recursive: false,
5465
+ show_hidden: false,
5466
+ max_depth: 0,
5467
+ include_size: false,
5468
+ include_permissions: false,
5469
+ sort_by: "name",
5470
+ sort_desc: false
5471
+ });
5472
+ if (!result.ok) {
5473
+ throw result.error;
5474
+ }
5475
+ const files = result.body?.data?.files?.map((file) => ({
5476
+ path: this.toVirtualPath(file.path),
5477
+ is_dir: file.is_directory,
5478
+ size: file.size,
5479
+ modified_at: file.modified_time
5480
+ })) || [];
5481
+ return files;
5482
+ } catch (e) {
5483
+ console.error(`Error listing files in ${dirPath}:`, e);
5484
+ return [];
5485
+ }
5486
+ }
5487
+ /**
5488
+ * Read file content with line numbers.
5489
+ *
5490
+ * @param filePath - Virtual file path (must start with /)
5491
+ * @param offset - Line offset to start reading from (0-indexed)
5492
+ * @param limit - Maximum number of lines to read
5493
+ * @returns Formatted file content with line numbers, or error message
5494
+ */
5495
+ async read(filePath, offset = 0, limit = 1e4) {
5496
+ try {
5497
+ const resolvedPath = this.resolvePath(filePath);
5498
+ let content;
5499
+ const result = await this.sandbox.file.readFile({
5500
+ file: resolvedPath,
5501
+ start_line: offset,
5502
+ end_line: limit
5503
+ });
5504
+ if (!result.ok) {
5505
+ throw result.error;
5506
+ }
5507
+ content = result.body?.data?.content || "";
5508
+ return content;
5509
+ } catch (e) {
5510
+ return `Error: File '${filePath}' not found`;
5511
+ }
5512
+ }
5513
+ /**
5514
+ * Read file content as raw FileData.
5515
+ *
5516
+ * @param filePath - Virtual file path (must start with /)
5517
+ * @returns Raw file content as FileData
5518
+ */
5519
+ async readRaw(filePath) {
5520
+ try {
5521
+ const content = await this.read(filePath);
5522
+ return {
5523
+ content: content.split("\n"),
5524
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
5525
+ modified_at: (/* @__PURE__ */ new Date()).toISOString()
5526
+ };
5527
+ } catch (e) {
5528
+ throw new Error(`Error reading file '${filePath}': ${e.message}`);
5529
+ }
5530
+ }
5531
+ /**
5532
+ * Create a new file with content.
5533
+ * Returns WriteResult. External storage sets filesUpdate=null.
5534
+ *
5535
+ * @param filePath - Virtual file path (must start with /)
5536
+ * @param content - File content as string
5537
+ * @returns WriteResult with error populated on failure
5538
+ */
5539
+ async write(filePath, content) {
5540
+ try {
5541
+ const resolvedPath = this.resolvePath(filePath);
5542
+ const result = await this.sandbox.file.writeFile({
5543
+ file: resolvedPath,
5544
+ content,
5545
+ "encoding": "utf-8",
5546
+ "append": false
5547
+ // sudo: true
5548
+ });
5549
+ if (!result.ok) {
5550
+ console.error(result.error);
5551
+ throw result.error;
5552
+ }
5553
+ return {
5554
+ path: filePath,
5555
+ filesUpdate: {
5556
+ [filePath]: {
5557
+ content: content.split("\n"),
5558
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
5559
+ modified_at: (/* @__PURE__ */ new Date()).toISOString()
5560
+ }
5561
+ }
5562
+ };
5563
+ } catch (e) {
5564
+ throw new Error(`Error writing file '${filePath}': ${e.message}`);
5565
+ }
5566
+ }
5567
+ /**
5568
+ * Edit a file by replacing string occurrences.
5569
+ * Returns EditResult. External storage sets filesUpdate=null.
5570
+ *
5571
+ * @param filePath - Virtual file path (must start with /)
5572
+ * @param oldString - String to find and replace
5573
+ * @param newString - Replacement string
5574
+ * @param replaceAll - If true, replace all occurrences (default: false)
5575
+ * @returns EditResult with error, path, filesUpdate, and occurrences
5576
+ */
5577
+ async edit(filePath, oldString, newString, replaceAll = false) {
5578
+ try {
5579
+ const resolvedPath = this.resolvePath(filePath);
5580
+ const result = await this.sandbox.file.strReplaceEditor({
5581
+ command: "str_replace",
5582
+ path: resolvedPath,
5583
+ old_str: oldString,
5584
+ new_str: newString,
5585
+ replace_mode: replaceAll ? "ALL" : "FIRST"
5586
+ });
5587
+ if (!result.ok) {
5588
+ throw result.error;
5589
+ }
5590
+ return {
5591
+ path: filePath,
5592
+ filesUpdate: null
5593
+ };
5594
+ } catch (e) {
5595
+ throw new Error(`Error editing file '${filePath}': ${e.message}`);
5596
+ }
5597
+ }
5598
+ /**
5599
+ * Structured search results or error string for invalid input.
5600
+ *
5601
+ * Searches file contents for a regex pattern within the sandbox.
5602
+ *
5603
+ * @param pattern - Regex pattern to search for
5604
+ * @param searchPath - Base path to search from (default: "/")
5605
+ * @param glob - Optional glob pattern to filter files (e.g., "*.py")
5606
+ * @returns List of GrepMatch objects or error string for invalid regex
5607
+ */
5608
+ async grepRaw(pattern, searchPath = "/", glob = null) {
5609
+ let baseFull;
5610
+ baseFull = this.resolvePath(searchPath || "/");
5611
+ const result = await this.sandbox.file.findFiles({
5612
+ path: baseFull,
5613
+ glob: glob || "**/*"
5614
+ });
5615
+ if (!result.ok) {
5616
+ throw result.error;
5617
+ }
5618
+ const filePaths = result.body?.data?.files || [];
5619
+ const matches = [];
5620
+ for (const absolutePath of filePaths) {
5621
+ const fileData = await this.sandbox.file.searchInFile({
5622
+ file: absolutePath,
5623
+ regex: pattern
5624
+ });
5625
+ if (!fileData.ok) {
5626
+ continue;
5627
+ }
5628
+ const matchesData = fileData.body?.data?.matches || [];
5629
+ const matchLines = fileData.body?.data?.line_numbers || [];
5630
+ matchesData.forEach((match, index) => {
5631
+ matches.push({
5632
+ path: this.toVirtualPath(absolutePath),
5633
+ line: matchLines[index],
5634
+ text: match
5635
+ });
5636
+ });
5637
+ }
5638
+ return matches;
5639
+ }
5640
+ /**
5641
+ * Structured glob matching returning FileInfo objects.
5642
+ *
5643
+ * @param pattern - Glob pattern (e.g., `*.py`, `**\/*.ts`)
5644
+ * @param searchPath - Base path to search from (default: "/")
5645
+ * @returns List of FileInfo objects matching the pattern
5646
+ */
5647
+ async globInfo(pattern, searchPath = "/") {
5648
+ if (pattern.startsWith("/")) {
5649
+ pattern = pattern.substring(1);
5650
+ }
5651
+ const resolvedSearchPath = this.resolvePath(searchPath);
5652
+ const result = await this.sandbox.file.findFiles({
5653
+ path: resolvedSearchPath,
5654
+ glob: pattern || "**/*"
5655
+ });
5656
+ if (!result.ok) {
5657
+ throw result.error;
5658
+ }
5659
+ const results = [];
5660
+ for (const filePath of result.body?.data?.files || []) {
5661
+ const fileInfo = await this.sandbox.file.listPath({
5662
+ path: filePath,
5663
+ recursive: false,
5664
+ show_hidden: false,
5665
+ max_depth: 1,
5666
+ include_size: false,
5667
+ include_permissions: false
5668
+ });
5669
+ if (!fileInfo.ok) {
5670
+ continue;
5671
+ }
5672
+ results.push({
5673
+ path: this.toVirtualPath(filePath),
5674
+ is_dir: false,
5675
+ size: fileInfo.body?.data?.files?.[0]?.size,
5676
+ modified_at: fileInfo.body?.data?.files?.[0]?.modified_time
5677
+ });
5678
+ }
5679
+ return results;
5680
+ }
5681
+ };
5682
+
5683
+ // src/middlewares/codeEvalMiddleware.ts
5684
+ var import_langchain8 = require("langchain");
5685
+ function createCodeEvalMiddleware(params = {}) {
5686
+ const codeEvalTool = getToolClient("execute_code");
5687
+ const codeExecuteFileTool = getToolClient("execute_code_file");
5688
+ return (0, import_langchain8.createMiddleware)({
5689
+ name: "codeEvalMiddleware",
5690
+ tools: [codeEvalTool, codeExecuteFileTool, getToolClient("convert_to_markdown")]
5691
+ });
5692
+ }
5693
+
5694
+ // src/middlewares/browserMiddleware.ts
5695
+ var import_langchain9 = require("langchain");
5696
+ function createBrowserMiddleware(params = {}) {
5697
+ const browserTools = toolLatticeManager.getAllLattices().filter((tool7) => tool7.key.startsWith("browser_"));
5698
+ return (0, import_langchain9.createMiddleware)({
5699
+ name: "browserMiddleware",
5700
+ tools: browserTools.map((tool7) => tool7.client)
5701
+ });
5702
+ }
5703
+
4132
5704
  // src/agent_lattice/builders/DeepAgentGraphBuilder.ts
4133
5705
  var DeepAgentGraphBuilder = class {
4134
5706
  /**
@@ -4142,7 +5714,7 @@ var DeepAgentGraphBuilder = class {
4142
5714
  const tools = params.tools.map((t) => {
4143
5715
  const toolClient = getToolClient(t.key);
4144
5716
  return toolClient;
4145
- }).filter((tool5) => tool5 !== void 0);
5717
+ }).filter((tool7) => tool7 !== void 0);
4146
5718
  const subagents = params.subAgents.map((sa) => {
4147
5719
  if (sa.client) {
4148
5720
  return {
@@ -4161,6 +5733,35 @@ var DeepAgentGraphBuilder = class {
4161
5733
  };
4162
5734
  }
4163
5735
  });
5736
+ let filesystemBackend;
5737
+ let middlewares = [];
5738
+ if (params.connectedSandbox) {
5739
+ const availabledModules = params.connectedSandbox?.availabledModules || ["filesystem", "code_eval", "browser"];
5740
+ if (availabledModules.includes("filesystem")) {
5741
+ const sandboxManager = sandboxLatticeManager.getSandboxLattice("default");
5742
+ if (!sandboxManager) {
5743
+ throw new Error("Sandbox manager not found");
5744
+ }
5745
+ let sandboxName = "global";
5746
+ if (params.connectedSandbox.isolatedLevel === "agent") {
5747
+ sandboxName = agentLattice.config.key;
5748
+ filesystemBackend = async (agentAndState) => new SandboxFilesystem({
5749
+ sandboxInstance: await sandboxManager.createSandbox(sandboxName)
5750
+ });
5751
+ } else if (params.connectedSandbox.isolatedLevel === "thread") {
5752
+ filesystemBackend = async (agentAndState) => new SandboxFilesystem({
5753
+ sandboxInstance: await sandboxManager.createSandbox(sandboxName)
5754
+ //TODO: add threadId to sandbox
5755
+ });
5756
+ }
5757
+ }
5758
+ if (availabledModules.includes("code_eval")) {
5759
+ middlewares.push(createCodeEvalMiddleware());
5760
+ }
5761
+ if (availabledModules.includes("browser")) {
5762
+ middlewares.push(createBrowserMiddleware());
5763
+ }
5764
+ }
4164
5765
  const deepAgent = createDeepAgent({
4165
5766
  tools,
4166
5767
  model: params.model,
@@ -4168,7 +5769,9 @@ var DeepAgentGraphBuilder = class {
4168
5769
  systemPrompt: params.prompt,
4169
5770
  subagents,
4170
5771
  checkpointer: getCheckpointSaver("default"),
4171
- skillCategories: params.skillCategories
5772
+ skillCategories: params.skillCategories,
5773
+ backend: filesystemBackend,
5774
+ middleware: middlewares
4172
5775
  });
4173
5776
  return deepAgent;
4174
5777
  }
@@ -4282,7 +5885,8 @@ var AgentParamsBuilder = class {
4282
5885
  subAgents: [...subAgents, ...internalSubAgents],
4283
5886
  prompt: agentLattice.config.prompt,
4284
5887
  stateSchema: agentLattice.config.schema,
4285
- skillCategories
5888
+ skillCategories,
5889
+ connectedSandbox: agentLattice.config.connectedSandbox
4286
5890
  };
4287
5891
  }
4288
5892
  };
@@ -6554,6 +8158,106 @@ var SkillLatticeManager = class _SkillLatticeManager extends BaseLatticeManager
6554
8158
  };
6555
8159
  var skillLatticeManager = SkillLatticeManager.getInstance();
6556
8160
 
8161
+ // src/mcp_lattice/McpLatticeManager.ts
8162
+ var import_mcp_adapters = require("@langchain/mcp-adapters");
8163
+ var McpLatticeManager = class _McpLatticeManager extends BaseLatticeManager {
8164
+ constructor() {
8165
+ super(...arguments);
8166
+ this.client = null;
8167
+ this.servers = /* @__PURE__ */ new Map();
8168
+ }
8169
+ static getInstance() {
8170
+ if (!_McpLatticeManager._instance) {
8171
+ _McpLatticeManager._instance = new _McpLatticeManager();
8172
+ }
8173
+ return _McpLatticeManager._instance;
8174
+ }
8175
+ getLatticeType() {
8176
+ return "mcp";
8177
+ }
8178
+ registerServers(servers) {
8179
+ for (const server of servers) {
8180
+ if (this.servers.has(server.name)) {
8181
+ console.warn(`[MCP] Server '${server.name}' already registered, skipping`);
8182
+ continue;
8183
+ }
8184
+ this.servers.set(server.name, server);
8185
+ console.log(`[MCP] Registered server: ${server.name}`);
8186
+ }
8187
+ }
8188
+ addServer(name, connection) {
8189
+ this.registerServers([{ name, connection }]);
8190
+ }
8191
+ removeServer(name) {
8192
+ const deleted = this.servers.delete(name);
8193
+ if (deleted) {
8194
+ console.log(`[MCP] Removed server: ${name}`);
8195
+ }
8196
+ return deleted;
8197
+ }
8198
+ async connect() {
8199
+ if (this.client) {
8200
+ console.warn("[MCP] Client already connected");
8201
+ return;
8202
+ }
8203
+ const serverConfigs = {};
8204
+ for (const [name, info] of this.servers) {
8205
+ serverConfigs[name] = info.connection;
8206
+ }
8207
+ if (Object.keys(serverConfigs).length === 0) {
8208
+ console.warn("[MCP] No servers registered");
8209
+ return;
8210
+ }
8211
+ this.client = new import_mcp_adapters.MultiServerMCPClient({
8212
+ mcpServers: serverConfigs
8213
+ });
8214
+ console.log(`[MCP] Connecting to ${this.servers.size} servers...`);
8215
+ await this.client.initializeConnections();
8216
+ console.log("[MCP] All servers connected");
8217
+ }
8218
+ async disconnect() {
8219
+ if (this.client) {
8220
+ await this.client.close();
8221
+ this.client = null;
8222
+ console.log("[MCP] Disconnected");
8223
+ }
8224
+ }
8225
+ isConnected() {
8226
+ return this.client !== null;
8227
+ }
8228
+ async getAllTools() {
8229
+ if (!this.client) {
8230
+ throw new Error("MCP client not connected");
8231
+ }
8232
+ return this.client.getTools();
8233
+ }
8234
+ getServerNames() {
8235
+ return Array.from(this.servers.keys());
8236
+ }
8237
+ hasServer(name) {
8238
+ return this.servers.has(name);
8239
+ }
8240
+ /**
8241
+ * 将 MCP 工具注册到 Tool Lattice
8242
+ * @param prefix 工具键名前缀,用于区分不同服务器的工具
8243
+ */
8244
+ async registerToolsToToolLattice(prefix) {
8245
+ if (!this.client) {
8246
+ throw new Error("MCP client not connected");
8247
+ }
8248
+ const tools = await this.getAllTools();
8249
+ console.log(`[MCP] Registering ${tools.length} tools to Tool Lattice...`);
8250
+ for (const tool7 of tools) {
8251
+ const toolKey = prefix ? `${prefix}_${tool7.name}` : tool7.name;
8252
+ tool7.name = toolKey;
8253
+ toolLatticeManager.registerExistingTool(toolKey, tool7);
8254
+ console.log(`[MCP] Registered tool: ${toolKey}`);
8255
+ }
8256
+ console.log(`[MCP] Successfully registered ${tools.length} tools to Tool Lattice`);
8257
+ }
8258
+ };
8259
+ var mcpManager = McpLatticeManager.getInstance();
8260
+
6557
8261
  // src/index.ts
6558
8262
  var Protocols = __toESM(require("@axiom-lattice/protocols"));
6559
8263
  // Annotate the CommonJS export names for ESM import in node:
@@ -6574,6 +8278,7 @@ var Protocols = __toESM(require("@axiom-lattice/protocols"));
6574
8278
  InMemoryChunkBuffer,
6575
8279
  InMemoryThreadStore,
6576
8280
  LoggerLatticeManager,
8281
+ McpLatticeManager,
6577
8282
  MemoryLatticeManager,
6578
8283
  MemoryQueueClient,
6579
8284
  MemoryScheduleStorage,
@@ -6583,6 +8288,7 @@ var Protocols = __toESM(require("@axiom-lattice/protocols"));
6583
8288
  PostgresDatabase,
6584
8289
  Protocols,
6585
8290
  QueueLatticeManager,
8291
+ SandboxLatticeManager,
6586
8292
  ScheduleLatticeManager,
6587
8293
  SkillLatticeManager,
6588
8294
  SqlDatabaseManager,
@@ -6608,6 +8314,7 @@ var Protocols = __toESM(require("@axiom-lattice/protocols"));
6608
8314
  getModelLattice,
6609
8315
  getNextCronTime,
6610
8316
  getQueueLattice,
8317
+ getSandBoxManager,
6611
8318
  getScheduleLattice,
6612
8319
  getStoreLattice,
6613
8320
  getToolClient,
@@ -6617,9 +8324,12 @@ var Protocols = __toESM(require("@axiom-lattice/protocols"));
6617
8324
  getVectorStoreLattice,
6618
8325
  hasChunkBuffer,
6619
8326
  isValidCronExpression,
8327
+ isValidSandboxName,
6620
8328
  isValidSkillName,
6621
8329
  loggerLatticeManager,
8330
+ mcpManager,
6622
8331
  modelLatticeManager,
8332
+ normalizeSandboxName,
6623
8333
  parseCronExpression,
6624
8334
  queueLatticeManager,
6625
8335
  registerAgentLattice,
@@ -6627,6 +8337,7 @@ var Protocols = __toESM(require("@axiom-lattice/protocols"));
6627
8337
  registerCheckpointSaver,
6628
8338
  registerChunkBuffer,
6629
8339
  registerEmbeddingsLattice,
8340
+ registerExistingTool,
6630
8341
  registerLoggerLattice,
6631
8342
  registerModelLattice,
6632
8343
  registerQueueLattice,
@@ -6634,6 +8345,7 @@ var Protocols = __toESM(require("@axiom-lattice/protocols"));
6634
8345
  registerStoreLattice,
6635
8346
  registerToolLattice,
6636
8347
  registerVectorStoreLattice,
8348
+ sandboxLatticeManager,
6637
8349
  scheduleLatticeManager,
6638
8350
  skillLatticeManager,
6639
8351
  sqlDatabaseManager,