@axiom-lattice/core 2.1.16 → 2.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +159 -2
- package/dist/index.d.ts +159 -2
- package/dist/index.js +1858 -118
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1880 -148
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -3
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,1362 @@ 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
|
+
getBaseURL() {
|
|
2202
|
+
return this.baseURL;
|
|
2203
|
+
}
|
|
2204
|
+
async createSandbox(sandboxName) {
|
|
2205
|
+
if (sandboxName === "global") {
|
|
2206
|
+
const client = new import_sandbox.SandboxClient({ baseUrl: `${this.baseURL}/sandbox/global`, environment: "" });
|
|
2207
|
+
this.sandboxes.set("global", client);
|
|
2208
|
+
return client;
|
|
2209
|
+
}
|
|
2210
|
+
const normalizedName = normalizeSandboxName(sandboxName);
|
|
2211
|
+
const existingClient = this.sandboxes.get(normalizedName);
|
|
2212
|
+
if (existingClient) {
|
|
2213
|
+
return existingClient;
|
|
2214
|
+
}
|
|
2215
|
+
const inFlight = this.creatingSandboxes.get(normalizedName);
|
|
2216
|
+
if (inFlight) {
|
|
2217
|
+
return inFlight;
|
|
2218
|
+
}
|
|
2219
|
+
const creationPromise = (async () => {
|
|
2220
|
+
const response = await fetch(`${this.baseURL}/api/v1/sandbox`, {
|
|
2221
|
+
method: "POST",
|
|
2222
|
+
headers: {
|
|
2223
|
+
"Content-Type": "application/json"
|
|
2224
|
+
},
|
|
2225
|
+
body: JSON.stringify({
|
|
2226
|
+
name: normalizedName,
|
|
2227
|
+
image: "enterprise-public-cn-beijing.cr.volces.com/vefaas-public/all-in-one-sandbox:latest"
|
|
2228
|
+
})
|
|
2229
|
+
});
|
|
2230
|
+
if (!response.ok) {
|
|
2231
|
+
throw new Error(`Failed to create sandbox: ${response.statusText}`);
|
|
2232
|
+
}
|
|
2233
|
+
const data = await response.json();
|
|
2234
|
+
const sandboxURL = `${this.baseURL}/sandbox/${normalizedName}`;
|
|
2235
|
+
const client = new import_sandbox.SandboxClient({ baseUrl: sandboxURL, environment: "" });
|
|
2236
|
+
this.sandboxes.set(normalizedName, client);
|
|
2237
|
+
return client;
|
|
2238
|
+
})();
|
|
2239
|
+
this.creatingSandboxes.set(normalizedName, creationPromise);
|
|
2240
|
+
creationPromise.catch(() => {
|
|
2241
|
+
this.creatingSandboxes.delete(normalizedName);
|
|
2242
|
+
}).then(() => {
|
|
2243
|
+
this.creatingSandboxes.delete(normalizedName);
|
|
2244
|
+
});
|
|
2245
|
+
return creationPromise;
|
|
2246
|
+
}
|
|
2247
|
+
async deleteSandbox(sandboxName) {
|
|
2248
|
+
const normalizedName = normalizeSandboxName(sandboxName);
|
|
2249
|
+
if (!this.sandboxes.has(normalizedName)) {
|
|
2250
|
+
throw new Error(`Sandbox ${sandboxName} (normalized: ${normalizedName}) not found`);
|
|
2251
|
+
}
|
|
2252
|
+
const response = await fetch(`${this.baseURL}/api/v1/sandbox/${normalizedName}`, {
|
|
2253
|
+
method: "DELETE"
|
|
2254
|
+
});
|
|
2255
|
+
if (!response.ok) {
|
|
2256
|
+
throw new Error(`Failed to delete sandbox: ${response.statusText}`);
|
|
2257
|
+
}
|
|
2258
|
+
this.sandboxes.delete(normalizedName);
|
|
2259
|
+
}
|
|
2260
|
+
async getSandbox(sandboxName) {
|
|
2261
|
+
const normalizedName = normalizeSandboxName(sandboxName);
|
|
2262
|
+
const client = this.sandboxes.get(normalizedName);
|
|
2263
|
+
if (!client) {
|
|
2264
|
+
throw new Error(`Sandbox ${sandboxName} (normalized: ${normalizedName}) not found`);
|
|
2265
|
+
}
|
|
2266
|
+
return client;
|
|
2267
|
+
}
|
|
2268
|
+
async listSandboxes() {
|
|
2269
|
+
return Array.from(this.sandboxes.values());
|
|
2270
|
+
}
|
|
2271
|
+
async getSandboxStatus(sandboxName) {
|
|
2272
|
+
const normalizedName = normalizeSandboxName(sandboxName);
|
|
2273
|
+
if (!this.sandboxes.has(normalizedName)) {
|
|
2274
|
+
throw new Error(`Sandbox ${sandboxName} (normalized: ${normalizedName}) not found`);
|
|
2275
|
+
}
|
|
2276
|
+
try {
|
|
2277
|
+
const client = this.sandboxes.get(normalizedName);
|
|
2278
|
+
const context = await client.sandbox.getContext();
|
|
2279
|
+
return context.ok ? "active" : "inactive";
|
|
2280
|
+
} catch {
|
|
2281
|
+
return "unknown";
|
|
2282
|
+
}
|
|
2283
|
+
}
|
|
2284
|
+
async getSandboxFromConfig(config) {
|
|
2285
|
+
if (config.sandboxConfig.isolatedLevel === "agent") {
|
|
2286
|
+
return this.createSandbox(config.assistant_id);
|
|
2287
|
+
} else if (config.sandboxConfig.isolatedLevel === "thread") {
|
|
2288
|
+
return this.createSandbox(config.thread_id);
|
|
2289
|
+
} else {
|
|
2290
|
+
return this.createSandbox("global");
|
|
2291
|
+
}
|
|
2292
|
+
}
|
|
2293
|
+
};
|
|
2294
|
+
var SandboxLatticeManager = class _SandboxLatticeManager extends BaseLatticeManager {
|
|
2295
|
+
/**
|
|
2296
|
+
* Get SandboxLatticeManager singleton instance
|
|
2297
|
+
*/
|
|
2298
|
+
static getInstance() {
|
|
2299
|
+
if (!_SandboxLatticeManager._instance) {
|
|
2300
|
+
_SandboxLatticeManager._instance = new _SandboxLatticeManager();
|
|
2301
|
+
}
|
|
2302
|
+
return _SandboxLatticeManager._instance;
|
|
2303
|
+
}
|
|
2304
|
+
/**
|
|
2305
|
+
* Get Lattice type prefix
|
|
2306
|
+
*/
|
|
2307
|
+
getLatticeType() {
|
|
2308
|
+
return "sandbox_manager";
|
|
2309
|
+
}
|
|
2310
|
+
/**
|
|
2311
|
+
* Register sandbox Lattice
|
|
2312
|
+
* @param key Lattice key name
|
|
2313
|
+
* @param manager Optional sandbox manager. If not provided, will create a default one.
|
|
2314
|
+
* @param baseURL Base URL for sandbox service (used when creating default manager)
|
|
2315
|
+
*/
|
|
2316
|
+
registerLattice(key, config) {
|
|
2317
|
+
const { manager, baseURL } = config;
|
|
2318
|
+
const sandboxManager = manager || new DefaultSandboxManager(baseURL);
|
|
2319
|
+
this.register(key, sandboxManager);
|
|
2320
|
+
}
|
|
2321
|
+
/**
|
|
2322
|
+
* Get SandboxLattice
|
|
2323
|
+
* @param key Lattice key name
|
|
2324
|
+
*/
|
|
2325
|
+
getSandboxLattice(key) {
|
|
2326
|
+
const sandboxLattice = this.get(key);
|
|
2327
|
+
if (!sandboxLattice) {
|
|
2328
|
+
throw new Error(`SandboxLattice ${key} not found`);
|
|
2329
|
+
}
|
|
2330
|
+
return sandboxLattice;
|
|
2331
|
+
}
|
|
2332
|
+
/**
|
|
2333
|
+
* Get all Lattices
|
|
2334
|
+
*/
|
|
2335
|
+
getAllLattices() {
|
|
2336
|
+
return this.getAll();
|
|
2337
|
+
}
|
|
2338
|
+
/**
|
|
2339
|
+
* Check if Lattice exists
|
|
2340
|
+
* @param key Lattice key name
|
|
2341
|
+
*/
|
|
2342
|
+
hasLattice(key) {
|
|
2343
|
+
return this.has(key);
|
|
2344
|
+
}
|
|
2345
|
+
/**
|
|
2346
|
+
* Remove Lattice
|
|
2347
|
+
* @param key Lattice key name
|
|
2348
|
+
*/
|
|
2349
|
+
removeLattice(key) {
|
|
2350
|
+
return this.remove(key);
|
|
2351
|
+
}
|
|
2352
|
+
/**
|
|
2353
|
+
* Clear all Lattices
|
|
2354
|
+
*/
|
|
2355
|
+
clearLattices() {
|
|
2356
|
+
this.clear();
|
|
2357
|
+
}
|
|
2358
|
+
/**
|
|
2359
|
+
* Get Lattice count
|
|
2360
|
+
*/
|
|
2361
|
+
getLatticeCount() {
|
|
2362
|
+
return this.count();
|
|
2363
|
+
}
|
|
2364
|
+
/**
|
|
2365
|
+
* Get Lattice key list
|
|
2366
|
+
*/
|
|
2367
|
+
getLatticeKeys() {
|
|
2368
|
+
return this.keys();
|
|
2369
|
+
}
|
|
2370
|
+
};
|
|
2371
|
+
var sandboxLatticeManager = SandboxLatticeManager.getInstance();
|
|
2372
|
+
var getSandBoxManager = (key = "default") => {
|
|
2373
|
+
if (!sandboxLatticeManager.hasLattice(key)) {
|
|
2374
|
+
throw new Error(`Sandbox ${key} not configured. Ensure the sandbox manager is registered and the agent is built with connectedSandbox.`);
|
|
2375
|
+
}
|
|
2376
|
+
const sandboxManager = sandboxLatticeManager.getSandboxLattice(key);
|
|
2377
|
+
return sandboxManager;
|
|
2378
|
+
};
|
|
2379
|
+
|
|
2380
|
+
// src/tool_lattice/code_eval/index.ts
|
|
2381
|
+
var CODE_EVAL_DESCRIPTION = `Execute code in Python or JavaScript runtime.
|
|
2382
|
+
|
|
2383
|
+
Args:
|
|
2384
|
+
code: Code to execute
|
|
2385
|
+
language: Programming language ('python', 'javascript')
|
|
2386
|
+
|
|
2387
|
+
Returns:
|
|
2388
|
+
Dict containing output, errors, and execution details`;
|
|
2389
|
+
registerToolLattice(
|
|
2390
|
+
"execute_code",
|
|
2391
|
+
{
|
|
2392
|
+
name: "execute_code",
|
|
2393
|
+
description: CODE_EVAL_DESCRIPTION,
|
|
2394
|
+
needUserApprove: false,
|
|
2395
|
+
schema: import_zod9.default.object({
|
|
2396
|
+
language: import_zod9.default.enum(["python", "javascript"]).describe("Programming language: 'python' or 'javascript'"),
|
|
2397
|
+
code: import_zod9.default.string().describe("Code to execute")
|
|
2398
|
+
})
|
|
2399
|
+
},
|
|
2400
|
+
async (input, exe_config) => {
|
|
2401
|
+
try {
|
|
2402
|
+
const runConfig = exe_config.configurable?.runConfig;
|
|
2403
|
+
const sandboxManager = getSandBoxManager();
|
|
2404
|
+
const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
|
|
2405
|
+
const result = await sandbox.code.executeCode({
|
|
2406
|
+
language: input.language,
|
|
2407
|
+
code: input.code,
|
|
2408
|
+
timeout: 300
|
|
2409
|
+
});
|
|
2410
|
+
if (!result.ok) {
|
|
2411
|
+
const err = result.error;
|
|
2412
|
+
return `Error executing ${input.language} code: ${err?.content?.message + (err?.content?.errors ? `
|
|
2413
|
+
${err?.content?.errors.join("\n")}` : "")}`;
|
|
2414
|
+
}
|
|
2415
|
+
const data = result.body?.data;
|
|
2416
|
+
if (!data) {
|
|
2417
|
+
return "Error: No response data from sandbox code execution.";
|
|
2418
|
+
}
|
|
2419
|
+
const { stdout = "", stderr = "", exit_code, traceback } = data;
|
|
2420
|
+
const parts = [];
|
|
2421
|
+
if (stdout) {
|
|
2422
|
+
parts.push(`stdout:
|
|
2423
|
+
${stdout}`);
|
|
2424
|
+
}
|
|
2425
|
+
if (stderr) {
|
|
2426
|
+
parts.push(`stderr:
|
|
2427
|
+
${stderr}`);
|
|
2428
|
+
}
|
|
2429
|
+
if (traceback && traceback.length > 0) {
|
|
2430
|
+
parts.push(`traceback:
|
|
2431
|
+
${traceback.join("\n")}`);
|
|
2432
|
+
}
|
|
2433
|
+
parts.push(`exit_code: ${exit_code ?? "\u2014"}`);
|
|
2434
|
+
return parts.length > 0 ? parts.join("\n\n") : `exit_code: ${exit_code ?? 0}`;
|
|
2435
|
+
} catch (e) {
|
|
2436
|
+
return `Error: ${e instanceof Error ? e.message : String(e)}`;
|
|
2437
|
+
}
|
|
2438
|
+
}
|
|
2439
|
+
);
|
|
2440
|
+
|
|
2441
|
+
// src/tool_lattice/code_execute_file/index.ts
|
|
2442
|
+
var import_zod10 = __toESM(require("zod"));
|
|
2443
|
+
var path2 = __toESM(require("path"));
|
|
2444
|
+
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.`;
|
|
2445
|
+
function inferLanguageFromPath(filePath) {
|
|
2446
|
+
const ext = path2.extname(filePath).toLowerCase();
|
|
2447
|
+
if (ext === ".py") {
|
|
2448
|
+
return "python";
|
|
2449
|
+
} else if (ext === ".js" || ext === ".mjs") {
|
|
2450
|
+
return "javascript";
|
|
2451
|
+
}
|
|
2452
|
+
return null;
|
|
2453
|
+
}
|
|
2454
|
+
registerToolLattice(
|
|
2455
|
+
"execute_code_file",
|
|
2456
|
+
{
|
|
2457
|
+
name: "execute_code_file",
|
|
2458
|
+
description: CODE_EXECUTE_FILE_DESCRIPTION,
|
|
2459
|
+
needUserApprove: false,
|
|
2460
|
+
schema: import_zod10.default.object({
|
|
2461
|
+
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.")
|
|
2462
|
+
})
|
|
2463
|
+
},
|
|
2464
|
+
async (input, exe_config) => {
|
|
2465
|
+
try {
|
|
2466
|
+
const runConfig = exe_config.configurable?.runConfig;
|
|
2467
|
+
const sandboxManager = getSandBoxManager();
|
|
2468
|
+
const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
|
|
2469
|
+
const context = await sandbox.sandbox.getContext();
|
|
2470
|
+
if (!context.ok) {
|
|
2471
|
+
return `Error: ${context.error}`;
|
|
2472
|
+
}
|
|
2473
|
+
const homeDir = context.body?.home_dir;
|
|
2474
|
+
const resolvedFilePath = path2.join(homeDir, input.file_path);
|
|
2475
|
+
const language = inferLanguageFromPath(input.file_path);
|
|
2476
|
+
if (!language) {
|
|
2477
|
+
return `Error: Unsupported file type. This tool only supports Python (.py) and JavaScript (.js, .mjs) files. Other file types cannot be executed.`;
|
|
2478
|
+
}
|
|
2479
|
+
const readResult = await sandbox.file.readFile({
|
|
2480
|
+
file: resolvedFilePath
|
|
2481
|
+
});
|
|
2482
|
+
if (!readResult.ok) {
|
|
2483
|
+
const err = readResult.error;
|
|
2484
|
+
return `Error reading file '${input.file_path}': ${err?.content?.message ?? JSON.stringify(readResult.error)}`;
|
|
2485
|
+
}
|
|
2486
|
+
const fileContent = readResult.body?.data?.content;
|
|
2487
|
+
if (fileContent === void 0 || fileContent === null) {
|
|
2488
|
+
return `Error: File '${input.file_path}' is empty or could not be read.`;
|
|
2489
|
+
}
|
|
2490
|
+
const result = await sandbox.code.executeCode({
|
|
2491
|
+
language,
|
|
2492
|
+
code: fileContent,
|
|
2493
|
+
timeout: 300
|
|
2494
|
+
});
|
|
2495
|
+
if (!result.ok) {
|
|
2496
|
+
const err = result.error;
|
|
2497
|
+
return `Error executing ${language} file '${input.file_path}': ${err?.content?.message ?? JSON.stringify(result.error)}`;
|
|
2498
|
+
}
|
|
2499
|
+
const data = result.body?.data;
|
|
2500
|
+
if (!data) {
|
|
2501
|
+
return "Error: No response data from sandbox code execution.";
|
|
2502
|
+
}
|
|
2503
|
+
const { stdout = "", stderr = "", exit_code, traceback } = data;
|
|
2504
|
+
const parts = [];
|
|
2505
|
+
if (stdout) {
|
|
2506
|
+
parts.push(`stdout:
|
|
2507
|
+
${stdout}`);
|
|
2508
|
+
}
|
|
2509
|
+
if (stderr) {
|
|
2510
|
+
parts.push(`stderr:
|
|
2511
|
+
${stderr}`);
|
|
2512
|
+
}
|
|
2513
|
+
if (traceback && traceback.length > 0) {
|
|
2514
|
+
parts.push(`traceback:
|
|
2515
|
+
${traceback.join("\n")}`);
|
|
2516
|
+
}
|
|
2517
|
+
parts.push(`exit_code: ${exit_code ?? "\u2014"}`);
|
|
2518
|
+
return parts.length > 0 ? parts.join("\n\n") : `exit_code: ${exit_code ?? 0}`;
|
|
2519
|
+
} catch (e) {
|
|
2520
|
+
return `Error: ${e instanceof Error ? e.message : String(e)}`;
|
|
2521
|
+
}
|
|
2522
|
+
}
|
|
2523
|
+
);
|
|
2524
|
+
|
|
2525
|
+
// src/tool_lattice/convert_to_markdown/index.ts
|
|
2526
|
+
var import_zod11 = __toESM(require("zod"));
|
|
2527
|
+
var CONVERT_TO_MARKDOWN_DESCRIPTION = `Convert a resource described by an http:, https:, file: or data: URI to markdown.
|
|
2528
|
+
|
|
2529
|
+
Args:
|
|
2530
|
+
uri (str): The URI to convert. Supported schemes:
|
|
2531
|
+
- http:// or https://: Fetch content from URL
|
|
2532
|
+
- file://: Read content from local file
|
|
2533
|
+
- data:: Decode data URI content
|
|
2534
|
+
|
|
2535
|
+
Returns:
|
|
2536
|
+
str: The content converted to markdown format.`;
|
|
2537
|
+
registerToolLattice(
|
|
2538
|
+
"convert_to_markdown",
|
|
2539
|
+
{
|
|
2540
|
+
name: "convert_to_markdown",
|
|
2541
|
+
description: CONVERT_TO_MARKDOWN_DESCRIPTION,
|
|
2542
|
+
needUserApprove: false,
|
|
2543
|
+
schema: import_zod11.default.object({
|
|
2544
|
+
uri: import_zod11.default.string().describe("The URI to convert.")
|
|
2545
|
+
})
|
|
2546
|
+
},
|
|
2547
|
+
async (input, exe_config) => {
|
|
2548
|
+
try {
|
|
2549
|
+
const runConfig = exe_config.configurable?.runConfig;
|
|
2550
|
+
const sandboxManager = getSandBoxManager();
|
|
2551
|
+
const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
|
|
2552
|
+
sandbox;
|
|
2553
|
+
const result = await sandbox.util.convertToMarkdown({
|
|
2554
|
+
uri: input.uri
|
|
2555
|
+
});
|
|
2556
|
+
if (!result.ok) {
|
|
2557
|
+
return `Error converting to markdown: ${result.error}`;
|
|
2558
|
+
}
|
|
2559
|
+
return result.body.data;
|
|
2560
|
+
} catch (e) {
|
|
2561
|
+
return `Error converting to markdown: ${e instanceof Error ? e.message : String(e)}`;
|
|
2562
|
+
}
|
|
2563
|
+
}
|
|
2564
|
+
);
|
|
2565
|
+
|
|
2566
|
+
// src/tool_lattice/browser/browser_navigate.ts
|
|
2567
|
+
var import_zod12 = __toESM(require("zod"));
|
|
2568
|
+
var BROWSER_NAVIGATE_DESCRIPTION = `Navigate to a URL.
|
|
2569
|
+
|
|
2570
|
+
Args:
|
|
2571
|
+
url (str): The URL to navigate to.
|
|
2572
|
+
|
|
2573
|
+
`;
|
|
2574
|
+
registerToolLattice(
|
|
2575
|
+
"browser_navigate",
|
|
2576
|
+
{
|
|
2577
|
+
name: "browser_navigate",
|
|
2578
|
+
description: BROWSER_NAVIGATE_DESCRIPTION,
|
|
2579
|
+
needUserApprove: false,
|
|
2580
|
+
schema: import_zod12.default.object({
|
|
2581
|
+
url: import_zod12.default.string().describe("The URL to navigate to.")
|
|
2582
|
+
})
|
|
2583
|
+
},
|
|
2584
|
+
async (input, exe_config) => {
|
|
2585
|
+
try {
|
|
2586
|
+
const runConfig = exe_config.configurable?.runConfig;
|
|
2587
|
+
const sandboxManager = getSandBoxManager();
|
|
2588
|
+
const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
|
|
2589
|
+
const result = await sandbox.mcp.executeMcpTool("browser", "browser_navigate", {
|
|
2590
|
+
url: input.url
|
|
2591
|
+
});
|
|
2592
|
+
if (!result.ok) {
|
|
2593
|
+
return `Error navigating to URL: ${JSON.stringify(result.error.content)}`;
|
|
2594
|
+
}
|
|
2595
|
+
return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Navigated to URL";
|
|
2596
|
+
} catch (e) {
|
|
2597
|
+
return `Error navigating to URL: ${e instanceof Error ? e.message : String(e)}`;
|
|
2598
|
+
}
|
|
2599
|
+
}
|
|
2600
|
+
);
|
|
2601
|
+
|
|
2602
|
+
// src/tool_lattice/browser/get_info.ts
|
|
2603
|
+
var BROWSER_GET_INFO_DESCRIPTION = `Get information about browser, like CDP URL, viewport size, etc.
|
|
2604
|
+
|
|
2605
|
+
Args:
|
|
2606
|
+
request (Dict): The incoming request context.
|
|
2607
|
+
|
|
2608
|
+
Returns:
|
|
2609
|
+
Dict containing browser information including CDP URL, viewport dimensions, and other browser metadata.`;
|
|
2610
|
+
registerToolLattice(
|
|
2611
|
+
"browser_get_info",
|
|
2612
|
+
{
|
|
2613
|
+
name: "browser_get_info",
|
|
2614
|
+
description: BROWSER_GET_INFO_DESCRIPTION,
|
|
2615
|
+
needUserApprove: false
|
|
2616
|
+
},
|
|
2617
|
+
async (input, exe_config) => {
|
|
2618
|
+
try {
|
|
2619
|
+
const runConfig = exe_config.configurable?.runConfig;
|
|
2620
|
+
const sandboxManager = getSandBoxManager();
|
|
2621
|
+
const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
|
|
2622
|
+
const result = await sandbox.browser.getInfo();
|
|
2623
|
+
if (!result.ok) {
|
|
2624
|
+
return `Error getting browser info: ${result.error}`;
|
|
2625
|
+
}
|
|
2626
|
+
return JSON.stringify(result.body.data, void 0, 2);
|
|
2627
|
+
} catch (e) {
|
|
2628
|
+
return `Error getting browser info: ${e instanceof Error ? e.message : String(e)}`;
|
|
2629
|
+
}
|
|
2630
|
+
}
|
|
2631
|
+
);
|
|
2632
|
+
|
|
2633
|
+
// src/tool_lattice/browser/browser_go_back.ts
|
|
2634
|
+
var import_zod13 = __toESM(require("zod"));
|
|
2635
|
+
var BROWSER_GO_BACK_DESCRIPTION = `Go back to the previous page.
|
|
2636
|
+
|
|
2637
|
+
Args:
|
|
2638
|
+
None
|
|
2639
|
+
|
|
2640
|
+
`;
|
|
2641
|
+
registerToolLattice(
|
|
2642
|
+
"browser_go_back",
|
|
2643
|
+
{
|
|
2644
|
+
name: "browser_go_back",
|
|
2645
|
+
description: BROWSER_GO_BACK_DESCRIPTION,
|
|
2646
|
+
needUserApprove: false,
|
|
2647
|
+
schema: import_zod13.default.object({})
|
|
2648
|
+
},
|
|
2649
|
+
async (input, exe_config) => {
|
|
2650
|
+
try {
|
|
2651
|
+
const runConfig = exe_config.configurable?.runConfig;
|
|
2652
|
+
const sandboxManager = getSandBoxManager();
|
|
2653
|
+
const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
|
|
2654
|
+
const result = await sandbox.mcp.executeMcpTool("browser", "browser_go_back", {});
|
|
2655
|
+
if (!result.ok) {
|
|
2656
|
+
return `Error going back: ${JSON.stringify(result.error.content)}`;
|
|
2657
|
+
}
|
|
2658
|
+
return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Went back to previous page";
|
|
2659
|
+
} catch (e) {
|
|
2660
|
+
return `Error going back: ${e instanceof Error ? e.message : String(e)}`;
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
);
|
|
2664
|
+
|
|
2665
|
+
// src/tool_lattice/browser/browser_go_forward.ts
|
|
2666
|
+
var import_zod14 = __toESM(require("zod"));
|
|
2667
|
+
var BROWSER_GO_FORWARD_DESCRIPTION = `Go forward to the next page.
|
|
2668
|
+
|
|
2669
|
+
Args:
|
|
2670
|
+
None
|
|
2671
|
+
|
|
2672
|
+
`;
|
|
2673
|
+
registerToolLattice(
|
|
2674
|
+
"browser_go_forward",
|
|
2675
|
+
{
|
|
2676
|
+
name: "browser_go_forward",
|
|
2677
|
+
description: BROWSER_GO_FORWARD_DESCRIPTION,
|
|
2678
|
+
needUserApprove: false,
|
|
2679
|
+
schema: import_zod14.default.object({})
|
|
2680
|
+
},
|
|
2681
|
+
async (input, exe_config) => {
|
|
2682
|
+
try {
|
|
2683
|
+
const runConfig = exe_config.configurable?.runConfig;
|
|
2684
|
+
const sandboxManager = getSandBoxManager();
|
|
2685
|
+
const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
|
|
2686
|
+
const result = await sandbox.mcp.executeMcpTool("browser", "browser_go_forward", {});
|
|
2687
|
+
if (!result.ok) {
|
|
2688
|
+
return `Error going forward: ${JSON.stringify(result.error.content)}`;
|
|
2689
|
+
}
|
|
2690
|
+
return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Went forward to next page";
|
|
2691
|
+
} catch (e) {
|
|
2692
|
+
return `Error going forward: ${e instanceof Error ? e.message : String(e)}`;
|
|
2693
|
+
}
|
|
2694
|
+
}
|
|
2695
|
+
);
|
|
2696
|
+
|
|
2697
|
+
// src/tool_lattice/browser/browser_form_input_fill.ts
|
|
2698
|
+
var import_zod15 = __toESM(require("zod"));
|
|
2699
|
+
var BROWSER_FORM_INPUT_FILL_DESCRIPTION = `Fill out an input field, before using the tool, Either 'index' or 'selector' must be provided.
|
|
2700
|
+
|
|
2701
|
+
Args:
|
|
2702
|
+
selector (str): CSS selector for input field, priority use index, if index is not provided, use selector
|
|
2703
|
+
index (int): Index of the element to fill
|
|
2704
|
+
value (str): Value to fill
|
|
2705
|
+
clear (bool): Whether to clear existing text before filling
|
|
2706
|
+
|
|
2707
|
+
`;
|
|
2708
|
+
registerToolLattice(
|
|
2709
|
+
"browser_form_input_fill",
|
|
2710
|
+
{
|
|
2711
|
+
name: "browser_form_input_fill",
|
|
2712
|
+
description: BROWSER_FORM_INPUT_FILL_DESCRIPTION,
|
|
2713
|
+
needUserApprove: false,
|
|
2714
|
+
schema: import_zod15.default.object({
|
|
2715
|
+
selector: import_zod15.default.string().optional().describe("CSS selector for input field, priority use index, if index is not provided, use selector"),
|
|
2716
|
+
index: import_zod15.default.number().optional().describe("Index of the element to fill"),
|
|
2717
|
+
value: import_zod15.default.string().describe("Value to fill"),
|
|
2718
|
+
clear: import_zod15.default.boolean().default(false).describe("Whether to clear existing text before filling")
|
|
2719
|
+
})
|
|
2720
|
+
},
|
|
2721
|
+
async (input, exe_config) => {
|
|
2722
|
+
try {
|
|
2723
|
+
const runConfig = exe_config.configurable?.runConfig;
|
|
2724
|
+
const sandboxManager = getSandBoxManager();
|
|
2725
|
+
const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
|
|
2726
|
+
const result = await sandbox.mcp.executeMcpTool("browser", "browser_form_input_fill", {
|
|
2727
|
+
selector: input.selector,
|
|
2728
|
+
index: input.index,
|
|
2729
|
+
value: input.value,
|
|
2730
|
+
clear: input.clear
|
|
2731
|
+
});
|
|
2732
|
+
if (!result.ok) {
|
|
2733
|
+
return `Error filling input field: ${JSON.stringify(result.error.content)}`;
|
|
2734
|
+
}
|
|
2735
|
+
return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Input field filled successfully";
|
|
2736
|
+
} catch (e) {
|
|
2737
|
+
return `Error filling input field: ${e instanceof Error ? e.message : String(e)}`;
|
|
2738
|
+
}
|
|
2739
|
+
}
|
|
2740
|
+
);
|
|
2741
|
+
|
|
2742
|
+
// src/tool_lattice/browser/browser_get_markdown.ts
|
|
2743
|
+
var import_zod16 = __toESM(require("zod"));
|
|
2744
|
+
var BROWSER_GET_MARKDOWN_DESCRIPTION = `Get the markdown content of the current page.
|
|
2745
|
+
|
|
2746
|
+
Args:
|
|
2747
|
+
None
|
|
2748
|
+
|
|
2749
|
+
`;
|
|
2750
|
+
registerToolLattice(
|
|
2751
|
+
"browser_get_markdown",
|
|
2752
|
+
{
|
|
2753
|
+
name: "browser_get_markdown",
|
|
2754
|
+
description: BROWSER_GET_MARKDOWN_DESCRIPTION,
|
|
2755
|
+
needUserApprove: false,
|
|
2756
|
+
schema: import_zod16.default.object({})
|
|
2757
|
+
},
|
|
2758
|
+
async (input, exe_config) => {
|
|
2759
|
+
try {
|
|
2760
|
+
const runConfig = exe_config.configurable?.runConfig;
|
|
2761
|
+
const sandboxManager = getSandBoxManager();
|
|
2762
|
+
const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
|
|
2763
|
+
const result = await sandbox.mcp.executeMcpTool("browser", "browser_get_markdown", {});
|
|
2764
|
+
if (!result.ok) {
|
|
2765
|
+
return `Error getting markdown content: ${JSON.stringify(result.error.content)}`;
|
|
2766
|
+
}
|
|
2767
|
+
return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Markdown content retrieved";
|
|
2768
|
+
} catch (e) {
|
|
2769
|
+
return `Error getting markdown content: ${e instanceof Error ? e.message : String(e)}`;
|
|
2770
|
+
}
|
|
2771
|
+
}
|
|
2772
|
+
);
|
|
2773
|
+
|
|
2774
|
+
// src/tool_lattice/browser/browser_get_text.ts
|
|
2775
|
+
var import_zod17 = __toESM(require("zod"));
|
|
2776
|
+
var BROWSER_GET_TEXT_DESCRIPTION = `Get the text content of the current page.
|
|
2777
|
+
|
|
2778
|
+
Args:
|
|
2779
|
+
None
|
|
2780
|
+
|
|
2781
|
+
`;
|
|
2782
|
+
registerToolLattice(
|
|
2783
|
+
"browser_get_text",
|
|
2784
|
+
{
|
|
2785
|
+
name: "browser_get_text",
|
|
2786
|
+
description: BROWSER_GET_TEXT_DESCRIPTION,
|
|
2787
|
+
needUserApprove: false,
|
|
2788
|
+
schema: import_zod17.default.object({})
|
|
2789
|
+
},
|
|
2790
|
+
async (input, exe_config) => {
|
|
2791
|
+
try {
|
|
2792
|
+
const runConfig = exe_config.configurable?.runConfig;
|
|
2793
|
+
const sandboxManager = getSandBoxManager();
|
|
2794
|
+
const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
|
|
2795
|
+
const result = await sandbox.mcp.executeMcpTool("browser", "browser_get_text", {});
|
|
2796
|
+
if (!result.ok) {
|
|
2797
|
+
return `Error getting text content: ${JSON.stringify(result.error.content)}`;
|
|
2798
|
+
}
|
|
2799
|
+
return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Text content retrieved";
|
|
2800
|
+
} catch (e) {
|
|
2801
|
+
return `Error getting text content: ${e instanceof Error ? e.message : String(e)}`;
|
|
2802
|
+
}
|
|
2803
|
+
}
|
|
2804
|
+
);
|
|
2805
|
+
|
|
2806
|
+
// src/tool_lattice/browser/browser_read_links.ts
|
|
2807
|
+
var import_zod18 = __toESM(require("zod"));
|
|
2808
|
+
var BROWSER_READ_LINKS_DESCRIPTION = `Get all links on the current page.
|
|
2809
|
+
|
|
2810
|
+
Args:
|
|
2811
|
+
None
|
|
2812
|
+
|
|
2813
|
+
`;
|
|
2814
|
+
registerToolLattice(
|
|
2815
|
+
"browser_read_links",
|
|
2816
|
+
{
|
|
2817
|
+
name: "browser_read_links",
|
|
2818
|
+
description: BROWSER_READ_LINKS_DESCRIPTION,
|
|
2819
|
+
needUserApprove: false,
|
|
2820
|
+
schema: import_zod18.default.object({})
|
|
2821
|
+
},
|
|
2822
|
+
async (input, exe_config) => {
|
|
2823
|
+
try {
|
|
2824
|
+
const runConfig = exe_config.configurable?.runConfig;
|
|
2825
|
+
const sandboxManager = getSandBoxManager();
|
|
2826
|
+
const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
|
|
2827
|
+
const result = await sandbox.mcp.executeMcpTool("browser", "browser_read_links", {});
|
|
2828
|
+
if (!result.ok) {
|
|
2829
|
+
return `Error reading links: ${JSON.stringify(result.error.content)}`;
|
|
2830
|
+
}
|
|
2831
|
+
return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Links retrieved successfully";
|
|
2832
|
+
} catch (e) {
|
|
2833
|
+
return `Error reading links: ${e instanceof Error ? e.message : String(e)}`;
|
|
2834
|
+
}
|
|
2835
|
+
}
|
|
2836
|
+
);
|
|
2837
|
+
|
|
2838
|
+
// src/tool_lattice/browser/browser_new_tab.ts
|
|
2839
|
+
var import_zod19 = __toESM(require("zod"));
|
|
2840
|
+
var BROWSER_NEW_TAB_DESCRIPTION = `Open a new tab.
|
|
2841
|
+
|
|
2842
|
+
Args:
|
|
2843
|
+
url (str): URL to open in the new tab
|
|
2844
|
+
|
|
2845
|
+
`;
|
|
2846
|
+
registerToolLattice(
|
|
2847
|
+
"browser_new_tab",
|
|
2848
|
+
{
|
|
2849
|
+
name: "browser_new_tab",
|
|
2850
|
+
description: BROWSER_NEW_TAB_DESCRIPTION,
|
|
2851
|
+
needUserApprove: false,
|
|
2852
|
+
schema: import_zod19.default.object({
|
|
2853
|
+
url: import_zod19.default.string().describe("URL to open in the new tab")
|
|
2854
|
+
})
|
|
2855
|
+
},
|
|
2856
|
+
async (input, exe_config) => {
|
|
2857
|
+
try {
|
|
2858
|
+
const runConfig = exe_config.configurable?.runConfig;
|
|
2859
|
+
const sandboxManager = getSandBoxManager();
|
|
2860
|
+
const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
|
|
2861
|
+
const result = await sandbox.mcp.executeMcpTool("browser", "browser_new_tab", {
|
|
2862
|
+
url: input.url
|
|
2863
|
+
});
|
|
2864
|
+
if (!result.ok) {
|
|
2865
|
+
return `Error opening new tab: ${JSON.stringify(result.error.content)}`;
|
|
2866
|
+
}
|
|
2867
|
+
return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "New tab opened successfully";
|
|
2868
|
+
} catch (e) {
|
|
2869
|
+
return `Error opening new tab: ${e instanceof Error ? e.message : String(e)}`;
|
|
2870
|
+
}
|
|
2871
|
+
}
|
|
2872
|
+
);
|
|
2873
|
+
|
|
2874
|
+
// src/tool_lattice/browser/browser_tab_list.ts
|
|
2875
|
+
var import_zod20 = __toESM(require("zod"));
|
|
2876
|
+
var BROWSER_TAB_LIST_DESCRIPTION = `Get the list of tabs.
|
|
2877
|
+
|
|
2878
|
+
Args:
|
|
2879
|
+
None
|
|
2880
|
+
|
|
2881
|
+
`;
|
|
2882
|
+
registerToolLattice(
|
|
2883
|
+
"browser_tab_list",
|
|
2884
|
+
{
|
|
2885
|
+
name: "browser_tab_list",
|
|
2886
|
+
description: BROWSER_TAB_LIST_DESCRIPTION,
|
|
2887
|
+
needUserApprove: false,
|
|
2888
|
+
schema: import_zod20.default.object({})
|
|
2889
|
+
},
|
|
2890
|
+
async (input, exe_config) => {
|
|
2891
|
+
try {
|
|
2892
|
+
const runConfig = exe_config.configurable?.runConfig;
|
|
2893
|
+
const sandboxManager = getSandBoxManager();
|
|
2894
|
+
const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
|
|
2895
|
+
const result = await sandbox.mcp.executeMcpTool("browser", "browser_tab_list", {});
|
|
2896
|
+
if (!result.ok) {
|
|
2897
|
+
return `Error getting tab list: ${JSON.stringify(result.error.content)}`;
|
|
2898
|
+
}
|
|
2899
|
+
return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Tab list retrieved successfully";
|
|
2900
|
+
} catch (e) {
|
|
2901
|
+
return `Error getting tab list: ${e instanceof Error ? e.message : String(e)}`;
|
|
2902
|
+
}
|
|
2903
|
+
}
|
|
2904
|
+
);
|
|
2905
|
+
|
|
2906
|
+
// src/tool_lattice/browser/browser_switch_tab.ts
|
|
2907
|
+
var import_zod21 = __toESM(require("zod"));
|
|
2908
|
+
var BROWSER_SWITCH_TAB_DESCRIPTION = `Switch to a specific tab.
|
|
2909
|
+
|
|
2910
|
+
Args:
|
|
2911
|
+
index (int): Tab index to switch to
|
|
2912
|
+
|
|
2913
|
+
`;
|
|
2914
|
+
registerToolLattice(
|
|
2915
|
+
"browser_switch_tab",
|
|
2916
|
+
{
|
|
2917
|
+
name: "browser_switch_tab",
|
|
2918
|
+
description: BROWSER_SWITCH_TAB_DESCRIPTION,
|
|
2919
|
+
needUserApprove: false,
|
|
2920
|
+
schema: import_zod21.default.object({
|
|
2921
|
+
index: import_zod21.default.number().describe("Tab index to switch to")
|
|
2922
|
+
})
|
|
2923
|
+
},
|
|
2924
|
+
async (input, exe_config) => {
|
|
2925
|
+
try {
|
|
2926
|
+
const runConfig = exe_config.configurable?.runConfig;
|
|
2927
|
+
const sandboxManager = getSandBoxManager();
|
|
2928
|
+
const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
|
|
2929
|
+
const result = await sandbox.mcp.executeMcpTool("browser", "browser_switch_tab", {
|
|
2930
|
+
index: input.index
|
|
2931
|
+
});
|
|
2932
|
+
if (!result.ok) {
|
|
2933
|
+
return `Error switching tab: ${JSON.stringify(result.error.content)}`;
|
|
2934
|
+
}
|
|
2935
|
+
return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Tab switched successfully";
|
|
2936
|
+
} catch (e) {
|
|
2937
|
+
return `Error switching tab: ${e instanceof Error ? e.message : String(e)}`;
|
|
2938
|
+
}
|
|
2939
|
+
}
|
|
2940
|
+
);
|
|
2941
|
+
|
|
2942
|
+
// src/tool_lattice/browser/browser_close_tab.ts
|
|
2943
|
+
var import_zod22 = __toESM(require("zod"));
|
|
2944
|
+
var BROWSER_CLOSE_TAB_DESCRIPTION = `Close the current tab.
|
|
2945
|
+
|
|
2946
|
+
Args:
|
|
2947
|
+
None
|
|
2948
|
+
|
|
2949
|
+
`;
|
|
2950
|
+
registerToolLattice(
|
|
2951
|
+
"browser_close_tab",
|
|
2952
|
+
{
|
|
2953
|
+
name: "browser_close_tab",
|
|
2954
|
+
description: BROWSER_CLOSE_TAB_DESCRIPTION,
|
|
2955
|
+
needUserApprove: false,
|
|
2956
|
+
schema: import_zod22.default.object({})
|
|
2957
|
+
},
|
|
2958
|
+
async (input, exe_config) => {
|
|
2959
|
+
try {
|
|
2960
|
+
const runConfig = exe_config.configurable?.runConfig;
|
|
2961
|
+
const sandboxManager = getSandBoxManager();
|
|
2962
|
+
const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
|
|
2963
|
+
const result = await sandbox.mcp.executeMcpTool("browser", "browser_close_tab", {});
|
|
2964
|
+
if (!result.ok) {
|
|
2965
|
+
return `Error closing tab: ${JSON.stringify(result.error.content)}`;
|
|
2966
|
+
}
|
|
2967
|
+
return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Current tab closed successfully";
|
|
2968
|
+
} catch (e) {
|
|
2969
|
+
return `Error closing tab: ${e instanceof Error ? e.message : String(e)}`;
|
|
2970
|
+
}
|
|
2971
|
+
}
|
|
2972
|
+
);
|
|
2973
|
+
|
|
2974
|
+
// src/tool_lattice/browser/browser_evaluate.ts
|
|
2975
|
+
var import_zod23 = __toESM(require("zod"));
|
|
2976
|
+
var BROWSER_EVALUATE_DESCRIPTION = `Execute JavaScript in the browser console.
|
|
2977
|
+
|
|
2978
|
+
Args:
|
|
2979
|
+
script (str): JavaScript code to execute, () => { /* code */ }
|
|
2980
|
+
|
|
2981
|
+
`;
|
|
2982
|
+
registerToolLattice(
|
|
2983
|
+
"browser_evaluate",
|
|
2984
|
+
{
|
|
2985
|
+
name: "browser_evaluate",
|
|
2986
|
+
description: BROWSER_EVALUATE_DESCRIPTION,
|
|
2987
|
+
needUserApprove: false,
|
|
2988
|
+
schema: import_zod23.default.object({
|
|
2989
|
+
script: import_zod23.default.string().describe("JavaScript code to execute, () => { /* code */ }")
|
|
2990
|
+
})
|
|
2991
|
+
},
|
|
2992
|
+
async (input, exe_config) => {
|
|
2993
|
+
try {
|
|
2994
|
+
const runConfig = exe_config.configurable?.runConfig;
|
|
2995
|
+
const sandboxManager = getSandBoxManager();
|
|
2996
|
+
const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
|
|
2997
|
+
const result = await sandbox.mcp.executeMcpTool("browser", "browser_evaluate", {
|
|
2998
|
+
script: input.script
|
|
2999
|
+
});
|
|
3000
|
+
if (!result.ok) {
|
|
3001
|
+
return `Error executing JavaScript: ${JSON.stringify(result.error.content)}`;
|
|
3002
|
+
}
|
|
3003
|
+
return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "JavaScript executed successfully";
|
|
3004
|
+
} catch (e) {
|
|
3005
|
+
return `Error executing JavaScript: ${e instanceof Error ? e.message : String(e)}`;
|
|
3006
|
+
}
|
|
3007
|
+
}
|
|
3008
|
+
);
|
|
3009
|
+
|
|
3010
|
+
// src/tool_lattice/browser/browser_get_download_list.ts
|
|
3011
|
+
var import_zod24 = __toESM(require("zod"));
|
|
3012
|
+
var BROWSER_GET_DOWNLOAD_LIST_DESCRIPTION = `Get the list of downloaded files.
|
|
3013
|
+
|
|
3014
|
+
Args:
|
|
3015
|
+
None
|
|
3016
|
+
|
|
3017
|
+
`;
|
|
3018
|
+
registerToolLattice(
|
|
3019
|
+
"browser_get_download_list",
|
|
3020
|
+
{
|
|
3021
|
+
name: "browser_get_download_list",
|
|
3022
|
+
description: BROWSER_GET_DOWNLOAD_LIST_DESCRIPTION,
|
|
3023
|
+
needUserApprove: false,
|
|
3024
|
+
schema: import_zod24.default.object({})
|
|
3025
|
+
},
|
|
3026
|
+
async (input, exe_config) => {
|
|
3027
|
+
try {
|
|
3028
|
+
const runConfig = exe_config.configurable?.runConfig;
|
|
3029
|
+
const sandboxManager = getSandBoxManager();
|
|
3030
|
+
const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
|
|
3031
|
+
const result = await sandbox.mcp.executeMcpTool("browser", "browser_get_download_list", {});
|
|
3032
|
+
if (!result.ok) {
|
|
3033
|
+
return `Error getting download list: ${JSON.stringify(result.error.content)}`;
|
|
3034
|
+
}
|
|
3035
|
+
return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Download list retrieved successfully";
|
|
3036
|
+
} catch (e) {
|
|
3037
|
+
return `Error getting download list: ${e instanceof Error ? e.message : String(e)}`;
|
|
3038
|
+
}
|
|
3039
|
+
}
|
|
3040
|
+
);
|
|
3041
|
+
|
|
3042
|
+
// src/tool_lattice/browser/browser_screenshot.ts
|
|
3043
|
+
var import_zod25 = __toESM(require("zod"));
|
|
3044
|
+
var BROWSER_SCREENSHOT_DESCRIPTION = `Take a screenshot of the current page or a specific element.
|
|
3045
|
+
|
|
3046
|
+
Args:
|
|
3047
|
+
name (str): Name for the screenshot
|
|
3048
|
+
selector (str): CSS selector for element to screenshot
|
|
3049
|
+
index (int): index of the element to screenshot
|
|
3050
|
+
width (int): Width in pixels (default: viewport width)
|
|
3051
|
+
height (int): Height in pixels (default: viewport height)
|
|
3052
|
+
fullPage (bool): Full page screenshot (default: false)
|
|
3053
|
+
highlight (bool): Highlight the element
|
|
3054
|
+
|
|
3055
|
+
`;
|
|
3056
|
+
registerToolLattice(
|
|
3057
|
+
"browser_screenshot",
|
|
3058
|
+
{
|
|
3059
|
+
name: "browser_screenshot",
|
|
3060
|
+
description: BROWSER_SCREENSHOT_DESCRIPTION,
|
|
3061
|
+
needUserApprove: false,
|
|
3062
|
+
schema: import_zod25.default.object({
|
|
3063
|
+
name: import_zod25.default.string().optional().describe("Name for the screenshot"),
|
|
3064
|
+
selector: import_zod25.default.string().optional().describe("CSS selector for element to screenshot"),
|
|
3065
|
+
index: import_zod25.default.number().optional().describe("index of the element to screenshot"),
|
|
3066
|
+
width: import_zod25.default.number().optional().describe("Width in pixels (default: viewport width)"),
|
|
3067
|
+
height: import_zod25.default.number().optional().describe("Height in pixels (default: viewport height)"),
|
|
3068
|
+
fullPage: import_zod25.default.boolean().optional().describe("Full page screenshot (default: false)"),
|
|
3069
|
+
highlight: import_zod25.default.boolean().default(false).describe("Highlight the element")
|
|
3070
|
+
})
|
|
3071
|
+
},
|
|
3072
|
+
async (input, exe_config) => {
|
|
3073
|
+
try {
|
|
3074
|
+
const runConfig = exe_config.configurable?.runConfig;
|
|
3075
|
+
const sandboxManager = getSandBoxManager();
|
|
3076
|
+
const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
|
|
3077
|
+
const result = await sandbox.mcp.executeMcpTool("browser", "browser_screenshot", {
|
|
3078
|
+
name: input.name,
|
|
3079
|
+
selector: input.selector,
|
|
3080
|
+
index: input.index,
|
|
3081
|
+
width: input.width,
|
|
3082
|
+
height: input.height,
|
|
3083
|
+
fullPage: input.fullPage,
|
|
3084
|
+
highlight: input.highlight
|
|
3085
|
+
});
|
|
3086
|
+
if (!result.ok) {
|
|
3087
|
+
return `Error taking screenshot: ${JSON.stringify(result.error.content)}`;
|
|
3088
|
+
}
|
|
3089
|
+
const lines = [];
|
|
3090
|
+
for (const item of result.body?.data?.content ?? []) {
|
|
3091
|
+
if (item.type === "image") {
|
|
3092
|
+
const base64Data = item.data;
|
|
3093
|
+
const buffer = Buffer.from(base64Data, "base64");
|
|
3094
|
+
const screenshotPath = `/home/gem/screenshots/screenshot_${input.name}.png`;
|
|
3095
|
+
const uploadResult = await sandbox.file.uploadFile({
|
|
3096
|
+
file: buffer,
|
|
3097
|
+
path: screenshotPath
|
|
3098
|
+
});
|
|
3099
|
+
if (uploadResult.ok) {
|
|
3100
|
+
const screenshot_md = [
|
|
3101
|
+
"",
|
|
3102
|
+
"Screenshot saved!",
|
|
3103
|
+
"```attachments",
|
|
3104
|
+
JSON.stringify([{ id: screenshotPath, name: `screenshot_${input.name}.png` }]),
|
|
3105
|
+
"```"
|
|
3106
|
+
].join("\n");
|
|
3107
|
+
lines.push(screenshot_md);
|
|
3108
|
+
} else {
|
|
3109
|
+
lines.push(`Failed to save screenshot: ${JSON.stringify(uploadResult.error)}`);
|
|
3110
|
+
}
|
|
3111
|
+
} else {
|
|
3112
|
+
lines.push(`${item.text}`);
|
|
3113
|
+
}
|
|
3114
|
+
}
|
|
3115
|
+
return lines.length > 0 ? lines.join("\n") : "No Content";
|
|
3116
|
+
} catch (e) {
|
|
3117
|
+
return `Error taking screenshot: ${e instanceof Error ? e.message : String(e)}`;
|
|
3118
|
+
}
|
|
3119
|
+
}
|
|
3120
|
+
);
|
|
3121
|
+
|
|
3122
|
+
// src/tool_lattice/browser/browser_click.ts
|
|
3123
|
+
var import_zod26 = __toESM(require("zod"));
|
|
3124
|
+
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.
|
|
3125
|
+
|
|
3126
|
+
Args:
|
|
3127
|
+
index (int): Index of the element to click
|
|
3128
|
+
|
|
3129
|
+
`;
|
|
3130
|
+
registerToolLattice(
|
|
3131
|
+
"browser_click",
|
|
3132
|
+
{
|
|
3133
|
+
name: "browser_click",
|
|
3134
|
+
description: BROWSER_CLICK_DESCRIPTION,
|
|
3135
|
+
needUserApprove: false,
|
|
3136
|
+
schema: import_zod26.default.object({
|
|
3137
|
+
index: import_zod26.default.number().describe("Index of the element to click")
|
|
3138
|
+
})
|
|
3139
|
+
},
|
|
3140
|
+
async (input, exe_config) => {
|
|
3141
|
+
try {
|
|
3142
|
+
const runConfig = exe_config.configurable?.runConfig;
|
|
3143
|
+
const sandboxManager = getSandBoxManager();
|
|
3144
|
+
const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
|
|
3145
|
+
const result = await sandbox.mcp.executeMcpTool("browser", "browser_click", {
|
|
3146
|
+
index: input.index
|
|
3147
|
+
});
|
|
3148
|
+
if (!result.ok) {
|
|
3149
|
+
return `Error clicking element: ${JSON.stringify(result.error.content)}`;
|
|
3150
|
+
}
|
|
3151
|
+
return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Element clicked successfully";
|
|
3152
|
+
} catch (e) {
|
|
3153
|
+
return `Error clicking element: ${e instanceof Error ? e.message : String(e)}`;
|
|
3154
|
+
}
|
|
3155
|
+
}
|
|
3156
|
+
);
|
|
3157
|
+
|
|
3158
|
+
// src/tool_lattice/browser/browser_select.ts
|
|
3159
|
+
var import_zod27 = __toESM(require("zod"));
|
|
3160
|
+
var BROWSER_SELECT_DESCRIPTION = `Select an element on the page with index, Either 'index' or 'selector' must be provided.
|
|
3161
|
+
|
|
3162
|
+
Args:
|
|
3163
|
+
index (int): Index of the element to select
|
|
3164
|
+
selector (str): CSS selector for element to select
|
|
3165
|
+
value (str): Value to select
|
|
3166
|
+
|
|
3167
|
+
`;
|
|
3168
|
+
registerToolLattice(
|
|
3169
|
+
"browser_select",
|
|
3170
|
+
{
|
|
3171
|
+
name: "browser_select",
|
|
3172
|
+
description: BROWSER_SELECT_DESCRIPTION,
|
|
3173
|
+
needUserApprove: false,
|
|
3174
|
+
schema: import_zod27.default.object({
|
|
3175
|
+
index: import_zod27.default.number().optional().describe("Index of the element to select"),
|
|
3176
|
+
selector: import_zod27.default.string().optional().describe("CSS selector for element to select"),
|
|
3177
|
+
value: import_zod27.default.string().describe("Value to select")
|
|
3178
|
+
})
|
|
3179
|
+
},
|
|
3180
|
+
async (input, exe_config) => {
|
|
3181
|
+
try {
|
|
3182
|
+
const runConfig = exe_config.configurable?.runConfig;
|
|
3183
|
+
const sandboxManager = getSandBoxManager();
|
|
3184
|
+
const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
|
|
3185
|
+
const result = await sandbox.mcp.executeMcpTool("browser", "browser_select", {
|
|
3186
|
+
index: input.index,
|
|
3187
|
+
selector: input.selector,
|
|
3188
|
+
value: input.value
|
|
3189
|
+
});
|
|
3190
|
+
if (!result.ok) {
|
|
3191
|
+
return `Error selecting element: ${JSON.stringify(result.error.content)}`;
|
|
3192
|
+
}
|
|
3193
|
+
return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Element selected successfully";
|
|
3194
|
+
} catch (e) {
|
|
3195
|
+
return `Error selecting element: ${e instanceof Error ? e.message : String(e)}`;
|
|
3196
|
+
}
|
|
3197
|
+
}
|
|
3198
|
+
);
|
|
3199
|
+
|
|
3200
|
+
// src/tool_lattice/browser/browser_hover.ts
|
|
3201
|
+
var import_zod28 = __toESM(require("zod"));
|
|
3202
|
+
var BROWSER_HOVER_DESCRIPTION = `Hover an element on the page, Either 'index' or 'selector' must be provided.
|
|
3203
|
+
|
|
3204
|
+
Args:
|
|
3205
|
+
index (int): Index of the element to hover
|
|
3206
|
+
selector (str): CSS selector for element to hover
|
|
3207
|
+
|
|
3208
|
+
`;
|
|
3209
|
+
registerToolLattice(
|
|
3210
|
+
"browser_hover",
|
|
3211
|
+
{
|
|
3212
|
+
name: "browser_hover",
|
|
3213
|
+
description: BROWSER_HOVER_DESCRIPTION,
|
|
3214
|
+
needUserApprove: false,
|
|
3215
|
+
schema: import_zod28.default.object({
|
|
3216
|
+
index: import_zod28.default.number().optional().describe("Index of the element to hover"),
|
|
3217
|
+
selector: import_zod28.default.string().optional().describe("CSS selector for element to hover")
|
|
3218
|
+
})
|
|
3219
|
+
},
|
|
3220
|
+
async (input, exe_config) => {
|
|
3221
|
+
try {
|
|
3222
|
+
const runConfig = exe_config.configurable?.runConfig;
|
|
3223
|
+
const sandboxManager = getSandBoxManager();
|
|
3224
|
+
const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
|
|
3225
|
+
const result = await sandbox.mcp.executeMcpTool("browser", "browser_hover", {
|
|
3226
|
+
index: input.index,
|
|
3227
|
+
selector: input.selector
|
|
3228
|
+
});
|
|
3229
|
+
if (!result.ok) {
|
|
3230
|
+
return `Error hovering element: ${JSON.stringify(result.error.content)}`;
|
|
3231
|
+
}
|
|
3232
|
+
return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Element hovered successfully";
|
|
3233
|
+
} catch (e) {
|
|
3234
|
+
return `Error hovering element: ${e instanceof Error ? e.message : String(e)}`;
|
|
3235
|
+
}
|
|
3236
|
+
}
|
|
3237
|
+
);
|
|
2026
3238
|
|
|
2027
|
-
// src/tool_lattice/
|
|
2028
|
-
var
|
|
3239
|
+
// src/tool_lattice/browser/browser_get_clickable_elements.ts
|
|
3240
|
+
var import_zod29 = __toESM(require("zod"));
|
|
3241
|
+
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.
|
|
3242
|
+
|
|
3243
|
+
Args:
|
|
3244
|
+
None
|
|
3245
|
+
|
|
3246
|
+
`;
|
|
2029
3247
|
registerToolLattice(
|
|
2030
|
-
"
|
|
3248
|
+
"browser_get_clickable_elements",
|
|
2031
3249
|
{
|
|
2032
|
-
name: "
|
|
2033
|
-
description:
|
|
3250
|
+
name: "browser_get_clickable_elements",
|
|
3251
|
+
description: BROWSER_GET_CLICKABLE_ELEMENTS_DESCRIPTION,
|
|
2034
3252
|
needUserApprove: false,
|
|
2035
|
-
schema:
|
|
3253
|
+
schema: import_zod29.default.object({})
|
|
2036
3254
|
},
|
|
2037
|
-
async () => {
|
|
3255
|
+
async (input, exe_config) => {
|
|
2038
3256
|
try {
|
|
2039
|
-
const
|
|
2040
|
-
const
|
|
2041
|
-
const
|
|
2042
|
-
const
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
}));
|
|
2050
|
-
return JSON.stringify(skillsMeta, null, 2);
|
|
2051
|
-
} catch (error) {
|
|
2052
|
-
return `Error loading skills: ${error instanceof Error ? error.message : String(error)}`;
|
|
3257
|
+
const runConfig = exe_config.configurable?.runConfig;
|
|
3258
|
+
const sandboxManager = getSandBoxManager();
|
|
3259
|
+
const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
|
|
3260
|
+
const result = await sandbox.mcp.executeMcpTool("browser", "browser_get_clickable_elements", {});
|
|
3261
|
+
if (!result.ok) {
|
|
3262
|
+
return `Error getting clickable elements: ${JSON.stringify(result.error.content)}`;
|
|
3263
|
+
}
|
|
3264
|
+
return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Clickable elements retrieved successfully";
|
|
3265
|
+
} catch (e) {
|
|
3266
|
+
return `Error getting clickable elements: ${e instanceof Error ? e.message : String(e)}`;
|
|
2053
3267
|
}
|
|
2054
3268
|
}
|
|
2055
3269
|
);
|
|
2056
3270
|
|
|
2057
|
-
// src/tool_lattice/
|
|
2058
|
-
var
|
|
2059
|
-
var
|
|
3271
|
+
// src/tool_lattice/browser/browser_scroll.ts
|
|
3272
|
+
var import_zod30 = __toESM(require("zod"));
|
|
3273
|
+
var BROWSER_SCROLL_DESCRIPTION = `Scroll the page.
|
|
3274
|
+
|
|
3275
|
+
Args:
|
|
3276
|
+
amount (int): Pixels to scroll (positive for down, negative for up), if the amount is not provided, scroll to the bottom of the page
|
|
3277
|
+
|
|
3278
|
+
`;
|
|
2060
3279
|
registerToolLattice(
|
|
2061
|
-
"
|
|
3280
|
+
"browser_scroll",
|
|
2062
3281
|
{
|
|
2063
|
-
name: "
|
|
2064
|
-
description:
|
|
3282
|
+
name: "browser_scroll",
|
|
3283
|
+
description: BROWSER_SCROLL_DESCRIPTION,
|
|
2065
3284
|
needUserApprove: false,
|
|
2066
|
-
schema:
|
|
2067
|
-
|
|
3285
|
+
schema: import_zod30.default.object({
|
|
3286
|
+
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
3287
|
})
|
|
2069
3288
|
},
|
|
2070
|
-
async (input) => {
|
|
3289
|
+
async (input, exe_config) => {
|
|
2071
3290
|
try {
|
|
2072
|
-
const
|
|
2073
|
-
const
|
|
2074
|
-
const
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
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}`);
|
|
3291
|
+
const runConfig = exe_config.configurable?.runConfig;
|
|
3292
|
+
const sandboxManager = getSandBoxManager();
|
|
3293
|
+
const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
|
|
3294
|
+
const result = await sandbox.mcp.executeMcpTool("browser", "browser_scroll", {
|
|
3295
|
+
amount: input.amount
|
|
3296
|
+
});
|
|
3297
|
+
if (!result.ok) {
|
|
3298
|
+
return `Error scrolling page: ${JSON.stringify(result.error.content)}`;
|
|
2088
3299
|
}
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
3300
|
+
return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Page scrolled successfully";
|
|
3301
|
+
} catch (e) {
|
|
3302
|
+
return `Error scrolling page: ${e instanceof Error ? e.message : String(e)}`;
|
|
3303
|
+
}
|
|
3304
|
+
}
|
|
3305
|
+
);
|
|
3306
|
+
|
|
3307
|
+
// src/tool_lattice/browser/browser_close.ts
|
|
3308
|
+
var import_zod31 = __toESM(require("zod"));
|
|
3309
|
+
var BROWSER_CLOSE_DESCRIPTION = `Close the browser when the task is done and the browser is not needed anymore.
|
|
3310
|
+
|
|
3311
|
+
Args:
|
|
3312
|
+
None
|
|
3313
|
+
|
|
3314
|
+
`;
|
|
3315
|
+
registerToolLattice(
|
|
3316
|
+
"browser_close",
|
|
3317
|
+
{
|
|
3318
|
+
name: "browser_close",
|
|
3319
|
+
description: BROWSER_CLOSE_DESCRIPTION,
|
|
3320
|
+
needUserApprove: false,
|
|
3321
|
+
schema: import_zod31.default.object({})
|
|
3322
|
+
},
|
|
3323
|
+
async (input, exe_config) => {
|
|
3324
|
+
try {
|
|
3325
|
+
const runConfig = exe_config.configurable?.runConfig;
|
|
3326
|
+
const sandboxManager = getSandBoxManager();
|
|
3327
|
+
const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
|
|
3328
|
+
const result = await sandbox.mcp.executeMcpTool("browser", "browser_close", {});
|
|
3329
|
+
if (!result.ok) {
|
|
3330
|
+
return `Error closing browser: ${JSON.stringify(result.error.content)}`;
|
|
2094
3331
|
}
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
3332
|
+
return result.body?.data?.content?.map((item) => item.text).join("\n") ?? "Browser closed successfully";
|
|
3333
|
+
} catch (e) {
|
|
3334
|
+
return `Error closing browser: ${e instanceof Error ? e.message : String(e)}`;
|
|
3335
|
+
}
|
|
3336
|
+
}
|
|
3337
|
+
);
|
|
3338
|
+
|
|
3339
|
+
// src/tool_lattice/browser/browser_press_key.ts
|
|
3340
|
+
var import_zod32 = __toESM(require("zod"));
|
|
3341
|
+
var BROWSER_PRESS_KEY_DESCRIPTION = `Press a key on the keyboard.
|
|
3342
|
+
|
|
3343
|
+
Args:
|
|
3344
|
+
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
|
|
3345
|
+
|
|
3346
|
+
`;
|
|
3347
|
+
registerToolLattice(
|
|
3348
|
+
"browser_press_key",
|
|
3349
|
+
{
|
|
3350
|
+
name: "browser_press_key",
|
|
3351
|
+
description: BROWSER_PRESS_KEY_DESCRIPTION,
|
|
3352
|
+
needUserApprove: false,
|
|
3353
|
+
schema: import_zod32.default.object({
|
|
3354
|
+
key: import_zod32.default.enum([
|
|
3355
|
+
"Enter",
|
|
3356
|
+
"Tab",
|
|
3357
|
+
"Escape",
|
|
3358
|
+
"Backspace",
|
|
3359
|
+
"Delete",
|
|
3360
|
+
"Insert",
|
|
3361
|
+
"F1",
|
|
3362
|
+
"F2",
|
|
3363
|
+
"F3",
|
|
3364
|
+
"F4",
|
|
3365
|
+
"F5",
|
|
3366
|
+
"F6",
|
|
3367
|
+
"F7",
|
|
3368
|
+
"F8",
|
|
3369
|
+
"F9",
|
|
3370
|
+
"F10",
|
|
3371
|
+
"F11",
|
|
3372
|
+
"F12",
|
|
3373
|
+
"ArrowLeft",
|
|
3374
|
+
"ArrowRight",
|
|
3375
|
+
"ArrowUp",
|
|
3376
|
+
"ArrowDown",
|
|
3377
|
+
"PageUp",
|
|
3378
|
+
"PageDown",
|
|
3379
|
+
"Home",
|
|
3380
|
+
"End",
|
|
3381
|
+
"ShiftLeft",
|
|
3382
|
+
"ShiftRight",
|
|
3383
|
+
"ControlLeft",
|
|
3384
|
+
"ControlRight",
|
|
3385
|
+
"AltLeft",
|
|
3386
|
+
"AltRight",
|
|
3387
|
+
"MetaLeft",
|
|
3388
|
+
"MetaRight",
|
|
3389
|
+
"CapsLock",
|
|
3390
|
+
"PrintScreen",
|
|
3391
|
+
"ScrollLock",
|
|
3392
|
+
"Pause",
|
|
3393
|
+
"ContextMenu"
|
|
3394
|
+
]).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")
|
|
3395
|
+
})
|
|
3396
|
+
},
|
|
3397
|
+
async (input, exe_config) => {
|
|
3398
|
+
try {
|
|
3399
|
+
const runConfig = exe_config.configurable?.runConfig;
|
|
3400
|
+
const sandboxManager = getSandBoxManager();
|
|
3401
|
+
const sandbox = await sandboxManager.getSandboxFromConfig(runConfig);
|
|
3402
|
+
const result = await sandbox.mcp.executeMcpTool("browser", "browser_press_key", {
|
|
3403
|
+
key: input.key
|
|
3404
|
+
});
|
|
3405
|
+
if (!result.ok) {
|
|
3406
|
+
return `Error pressing key: ${JSON.stringify(result.error.content)}`;
|
|
2100
3407
|
}
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
return
|
|
2104
|
-
${content}`;
|
|
2105
|
-
} catch (error) {
|
|
2106
|
-
return `Error loading skill content: ${error instanceof Error ? error.message : String(error)}`;
|
|
3408
|
+
return result.body?.data?.content?.map((item) => item.text).join("\n") ?? `Key ${input.key} pressed successfully`;
|
|
3409
|
+
} catch (e) {
|
|
3410
|
+
return `Error pressing key: ${e instanceof Error ? e.message : String(e)}`;
|
|
2107
3411
|
}
|
|
2108
3412
|
}
|
|
2109
3413
|
);
|
|
@@ -2192,7 +3496,7 @@ var memory = new import_langgraph2.MemorySaver();
|
|
|
2192
3496
|
registerCheckpointSaver("default", memory);
|
|
2193
3497
|
|
|
2194
3498
|
// src/agent_lattice/builders/state.ts
|
|
2195
|
-
var
|
|
3499
|
+
var import_zod33 = require("@langchain/langgraph/zod");
|
|
2196
3500
|
var import_langgraph3 = require("@langchain/langgraph");
|
|
2197
3501
|
var createReactAgentSchema = (schema) => {
|
|
2198
3502
|
return schema ? import_langgraph3.MessagesZodState.extend(schema.shape) : void 0;
|
|
@@ -2210,9 +3514,9 @@ var ReActAgentGraphBuilder = class {
|
|
|
2210
3514
|
*/
|
|
2211
3515
|
build(agentLattice, params) {
|
|
2212
3516
|
const tools = params.tools.map((t) => {
|
|
2213
|
-
const
|
|
2214
|
-
return
|
|
2215
|
-
}).filter((
|
|
3517
|
+
const tool7 = getToolClient(t.key);
|
|
3518
|
+
return tool7;
|
|
3519
|
+
}).filter((tool7) => tool7 !== void 0);
|
|
2216
3520
|
const stateSchema2 = createReactAgentSchema(params.stateSchema);
|
|
2217
3521
|
return (0, import_langchain.createAgent)({
|
|
2218
3522
|
model: params.model,
|
|
@@ -2232,7 +3536,7 @@ var import_langchain7 = require("langchain");
|
|
|
2232
3536
|
var import_langchain2 = require("langchain");
|
|
2233
3537
|
var import_langgraph4 = require("@langchain/langgraph");
|
|
2234
3538
|
var import_v3 = require("zod/v3");
|
|
2235
|
-
var
|
|
3539
|
+
var import_zod34 = require("@langchain/langgraph/zod");
|
|
2236
3540
|
|
|
2237
3541
|
// src/deep_agent_new/backends/utils.ts
|
|
2238
3542
|
var import_micromatch = __toESM(require("micromatch"));
|
|
@@ -2335,8 +3639,8 @@ function performStringReplacement(content, oldString, newString, replaceAll) {
|
|
|
2335
3639
|
const newContent = content.split(oldString).join(newString);
|
|
2336
3640
|
return [newContent, occurrences];
|
|
2337
3641
|
}
|
|
2338
|
-
function validatePath(
|
|
2339
|
-
const pathStr =
|
|
3642
|
+
function validatePath(path4) {
|
|
3643
|
+
const pathStr = path4 || "/";
|
|
2340
3644
|
if (!pathStr || pathStr.trim() === "") {
|
|
2341
3645
|
throw new Error("Path cannot be empty");
|
|
2342
3646
|
}
|
|
@@ -2346,10 +3650,10 @@ function validatePath(path2) {
|
|
|
2346
3650
|
}
|
|
2347
3651
|
return normalized;
|
|
2348
3652
|
}
|
|
2349
|
-
function globSearchFiles(files, pattern,
|
|
3653
|
+
function globSearchFiles(files, pattern, path4 = "/") {
|
|
2350
3654
|
let normalizedPath;
|
|
2351
3655
|
try {
|
|
2352
|
-
normalizedPath = validatePath(
|
|
3656
|
+
normalizedPath = validatePath(path4);
|
|
2353
3657
|
} catch {
|
|
2354
3658
|
return "No files found";
|
|
2355
3659
|
}
|
|
@@ -2359,15 +3663,15 @@ function globSearchFiles(files, pattern, path2 = "/") {
|
|
|
2359
3663
|
const effectivePattern = pattern;
|
|
2360
3664
|
const matches = [];
|
|
2361
3665
|
for (const [filePath, fileData] of Object.entries(filtered)) {
|
|
2362
|
-
let
|
|
2363
|
-
if (
|
|
2364
|
-
|
|
3666
|
+
let relative2 = filePath.substring(normalizedPath.length);
|
|
3667
|
+
if (relative2.startsWith("/")) {
|
|
3668
|
+
relative2 = relative2.substring(1);
|
|
2365
3669
|
}
|
|
2366
|
-
if (!
|
|
3670
|
+
if (!relative2) {
|
|
2367
3671
|
const parts = filePath.split("/");
|
|
2368
|
-
|
|
3672
|
+
relative2 = parts[parts.length - 1] || "";
|
|
2369
3673
|
}
|
|
2370
|
-
if (import_micromatch.default.isMatch(
|
|
3674
|
+
if (import_micromatch.default.isMatch(relative2, effectivePattern, {
|
|
2371
3675
|
dot: true,
|
|
2372
3676
|
nobrace: false
|
|
2373
3677
|
})) {
|
|
@@ -2380,7 +3684,7 @@ function globSearchFiles(files, pattern, path2 = "/") {
|
|
|
2380
3684
|
}
|
|
2381
3685
|
return matches.map(([fp]) => fp).join("\n");
|
|
2382
3686
|
}
|
|
2383
|
-
function grepMatchesFromFiles(files, pattern,
|
|
3687
|
+
function grepMatchesFromFiles(files, pattern, path4 = null, glob = null) {
|
|
2384
3688
|
let regex;
|
|
2385
3689
|
try {
|
|
2386
3690
|
regex = new RegExp(pattern);
|
|
@@ -2389,7 +3693,7 @@ function grepMatchesFromFiles(files, pattern, path2 = null, glob = null) {
|
|
|
2389
3693
|
}
|
|
2390
3694
|
let normalizedPath;
|
|
2391
3695
|
try {
|
|
2392
|
-
normalizedPath = validatePath(
|
|
3696
|
+
normalizedPath = validatePath(path4);
|
|
2393
3697
|
} catch {
|
|
2394
3698
|
return [];
|
|
2395
3699
|
}
|
|
@@ -2434,18 +3738,18 @@ var StateBackend = class {
|
|
|
2434
3738
|
* @returns List of FileInfo objects for files and directories directly in the directory.
|
|
2435
3739
|
* Directories have a trailing / in their path and is_dir=true.
|
|
2436
3740
|
*/
|
|
2437
|
-
lsInfo(
|
|
3741
|
+
lsInfo(path4) {
|
|
2438
3742
|
const files = this.getFiles();
|
|
2439
3743
|
const infos = [];
|
|
2440
3744
|
const subdirs = /* @__PURE__ */ new Set();
|
|
2441
|
-
const normalizedPath =
|
|
3745
|
+
const normalizedPath = path4.endsWith("/") ? path4 : path4 + "/";
|
|
2442
3746
|
for (const [k, fd] of Object.entries(files)) {
|
|
2443
3747
|
if (!k.startsWith(normalizedPath)) {
|
|
2444
3748
|
continue;
|
|
2445
3749
|
}
|
|
2446
|
-
const
|
|
2447
|
-
if (
|
|
2448
|
-
const subdirName =
|
|
3750
|
+
const relative2 = k.substring(normalizedPath.length);
|
|
3751
|
+
if (relative2.includes("/")) {
|
|
3752
|
+
const subdirName = relative2.split("/")[0];
|
|
2449
3753
|
subdirs.add(normalizedPath + subdirName + "/");
|
|
2450
3754
|
continue;
|
|
2451
3755
|
}
|
|
@@ -2544,16 +3848,16 @@ var StateBackend = class {
|
|
|
2544
3848
|
/**
|
|
2545
3849
|
* Structured search results or error string for invalid input.
|
|
2546
3850
|
*/
|
|
2547
|
-
grepRaw(pattern,
|
|
3851
|
+
grepRaw(pattern, path4 = "/", glob = null) {
|
|
2548
3852
|
const files = this.getFiles();
|
|
2549
|
-
return grepMatchesFromFiles(files, pattern,
|
|
3853
|
+
return grepMatchesFromFiles(files, pattern, path4, glob);
|
|
2550
3854
|
}
|
|
2551
3855
|
/**
|
|
2552
3856
|
* Structured glob matching returning FileInfo objects.
|
|
2553
3857
|
*/
|
|
2554
|
-
globInfo(pattern,
|
|
3858
|
+
globInfo(pattern, path4 = "/") {
|
|
2555
3859
|
const files = this.getFiles();
|
|
2556
|
-
const result = globSearchFiles(files, pattern,
|
|
3860
|
+
const result = globSearchFiles(files, pattern, path4);
|
|
2557
3861
|
if (result === "No files found") {
|
|
2558
3862
|
return [];
|
|
2559
3863
|
}
|
|
@@ -2600,7 +3904,7 @@ function fileDataReducer(left, right) {
|
|
|
2600
3904
|
return result;
|
|
2601
3905
|
}
|
|
2602
3906
|
var FilesystemStateSchema = import_v3.z.object({
|
|
2603
|
-
files: (0,
|
|
3907
|
+
files: (0, import_zod34.withLangGraph)(
|
|
2604
3908
|
import_v3.z.record(import_v3.z.string(), FileDataSchema).default({}),
|
|
2605
3909
|
{
|
|
2606
3910
|
reducer: {
|
|
@@ -2610,9 +3914,9 @@ var FilesystemStateSchema = import_v3.z.object({
|
|
|
2610
3914
|
}
|
|
2611
3915
|
)
|
|
2612
3916
|
});
|
|
2613
|
-
function getBackend(backend, stateAndStore) {
|
|
3917
|
+
async function getBackend(backend, stateAndStore) {
|
|
2614
3918
|
if (typeof backend === "function") {
|
|
2615
|
-
return backend(stateAndStore);
|
|
3919
|
+
return await backend(stateAndStore);
|
|
2616
3920
|
}
|
|
2617
3921
|
return backend;
|
|
2618
3922
|
}
|
|
@@ -2638,11 +3942,11 @@ function createLsTool(backend, options) {
|
|
|
2638
3942
|
state: (0, import_langgraph4.getCurrentTaskInput)(config),
|
|
2639
3943
|
store: config.store
|
|
2640
3944
|
};
|
|
2641
|
-
const resolvedBackend = getBackend(backend, stateAndStore);
|
|
2642
|
-
const
|
|
2643
|
-
const infos = await resolvedBackend.lsInfo(
|
|
3945
|
+
const resolvedBackend = await getBackend(backend, stateAndStore);
|
|
3946
|
+
const path4 = input.path || "/";
|
|
3947
|
+
const infos = await resolvedBackend.lsInfo(path4);
|
|
2644
3948
|
if (infos.length === 0) {
|
|
2645
|
-
return `No files found in ${
|
|
3949
|
+
return `No files found in ${path4}`;
|
|
2646
3950
|
}
|
|
2647
3951
|
const lines = [];
|
|
2648
3952
|
for (const info of infos) {
|
|
@@ -2672,7 +3976,7 @@ function createReadFileTool(backend, options) {
|
|
|
2672
3976
|
state: (0, import_langgraph4.getCurrentTaskInput)(config),
|
|
2673
3977
|
store: config.store
|
|
2674
3978
|
};
|
|
2675
|
-
const resolvedBackend = getBackend(backend, stateAndStore);
|
|
3979
|
+
const resolvedBackend = await getBackend(backend, stateAndStore);
|
|
2676
3980
|
const { file_path, offset = 0, limit = 2e3 } = input;
|
|
2677
3981
|
return await resolvedBackend.read(file_path, offset, limit);
|
|
2678
3982
|
},
|
|
@@ -2695,7 +3999,7 @@ function createWriteFileTool(backend, options) {
|
|
|
2695
3999
|
state: (0, import_langgraph4.getCurrentTaskInput)(config),
|
|
2696
4000
|
store: config.store
|
|
2697
4001
|
};
|
|
2698
|
-
const resolvedBackend = getBackend(backend, stateAndStore);
|
|
4002
|
+
const resolvedBackend = await getBackend(backend, stateAndStore);
|
|
2699
4003
|
const { file_path, content } = input;
|
|
2700
4004
|
const result = await resolvedBackend.write(file_path, content);
|
|
2701
4005
|
if (result.error) {
|
|
@@ -2732,7 +4036,7 @@ function createEditFileTool(backend, options) {
|
|
|
2732
4036
|
state: (0, import_langgraph4.getCurrentTaskInput)(config),
|
|
2733
4037
|
store: config.store
|
|
2734
4038
|
};
|
|
2735
|
-
const resolvedBackend = getBackend(backend, stateAndStore);
|
|
4039
|
+
const resolvedBackend = await getBackend(backend, stateAndStore);
|
|
2736
4040
|
const { file_path, old_string, new_string, replace_all = false } = input;
|
|
2737
4041
|
const result = await resolvedBackend.edit(
|
|
2738
4042
|
file_path,
|
|
@@ -2776,9 +4080,9 @@ function createGlobTool(backend, options) {
|
|
|
2776
4080
|
state: (0, import_langgraph4.getCurrentTaskInput)(config),
|
|
2777
4081
|
store: config.store
|
|
2778
4082
|
};
|
|
2779
|
-
const resolvedBackend = getBackend(backend, stateAndStore);
|
|
2780
|
-
const { pattern, path:
|
|
2781
|
-
const infos = await resolvedBackend.globInfo(pattern,
|
|
4083
|
+
const resolvedBackend = await getBackend(backend, stateAndStore);
|
|
4084
|
+
const { pattern, path: path4 = "/" } = input;
|
|
4085
|
+
const infos = await resolvedBackend.globInfo(pattern, path4);
|
|
2782
4086
|
if (infos.length === 0) {
|
|
2783
4087
|
return `No files found matching pattern '${pattern}'`;
|
|
2784
4088
|
}
|
|
@@ -2802,9 +4106,9 @@ function createGrepTool(backend, options) {
|
|
|
2802
4106
|
state: (0, import_langgraph4.getCurrentTaskInput)(config),
|
|
2803
4107
|
store: config.store
|
|
2804
4108
|
};
|
|
2805
|
-
const resolvedBackend = getBackend(backend, stateAndStore);
|
|
2806
|
-
const { pattern, path:
|
|
2807
|
-
const result = await resolvedBackend.grepRaw(pattern,
|
|
4109
|
+
const resolvedBackend = await getBackend(backend, stateAndStore);
|
|
4110
|
+
const { pattern, path: path4 = "/", glob = null } = input;
|
|
4111
|
+
const result = await resolvedBackend.grepRaw(pattern, path4, glob);
|
|
2808
4112
|
if (typeof result === "string") {
|
|
2809
4113
|
return result;
|
|
2810
4114
|
}
|
|
@@ -2836,7 +4140,7 @@ ${currentFile}:`);
|
|
|
2836
4140
|
}
|
|
2837
4141
|
function createFilesystemMiddleware(options = {}) {
|
|
2838
4142
|
const {
|
|
2839
|
-
backend = (stateAndStore) => new StateBackend(stateAndStore),
|
|
4143
|
+
backend = async (stateAndStore) => new StateBackend(stateAndStore),
|
|
2840
4144
|
systemPrompt: customSystemPrompt = null,
|
|
2841
4145
|
customToolDescriptions = null,
|
|
2842
4146
|
toolTokenLimitBeforeEvict = 2e4
|
|
@@ -2881,7 +4185,7 @@ ${systemPrompt}` : systemPrompt;
|
|
|
2881
4185
|
state: request.state || {},
|
|
2882
4186
|
store: request.config?.store
|
|
2883
4187
|
};
|
|
2884
|
-
const resolvedBackend = getBackend(backend, stateAndStore);
|
|
4188
|
+
const resolvedBackend = await getBackend(backend, stateAndStore);
|
|
2885
4189
|
const sanitizedId = sanitizeToolCallId(
|
|
2886
4190
|
request.toolCall?.id || msg.tool_call_id
|
|
2887
4191
|
);
|
|
@@ -3723,7 +5027,7 @@ var SUPPORTS_NOFOLLOW = fsSync.constants.O_NOFOLLOW !== void 0;
|
|
|
3723
5027
|
|
|
3724
5028
|
// src/deep_agent_new/middleware/todos.ts
|
|
3725
5029
|
var import_langgraph8 = require("@langchain/langgraph");
|
|
3726
|
-
var
|
|
5030
|
+
var import_zod35 = require("zod");
|
|
3727
5031
|
var import_langchain5 = require("langchain");
|
|
3728
5032
|
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
5033
|
It also helps the user understand the progress of the task and overall progress of their requests.
|
|
@@ -3951,12 +5255,12 @@ Writing todos takes time and tokens, use it when it is helpful for managing comp
|
|
|
3951
5255
|
## Important To-Do List Usage Notes to Remember
|
|
3952
5256
|
- The \`write_todos\` tool should never be called multiple times in parallel.
|
|
3953
5257
|
- 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 =
|
|
3955
|
-
var TodoSchema =
|
|
3956
|
-
content:
|
|
5258
|
+
var TodoStatus = import_zod35.z.enum(["pending", "in_progress", "completed"]).describe("Status of the todo");
|
|
5259
|
+
var TodoSchema = import_zod35.z.object({
|
|
5260
|
+
content: import_zod35.z.string().describe("Content of the todo item"),
|
|
3957
5261
|
status: TodoStatus
|
|
3958
5262
|
});
|
|
3959
|
-
var stateSchema =
|
|
5263
|
+
var stateSchema = import_zod35.z.object({ todos: import_zod35.z.array(TodoSchema).default([]) });
|
|
3960
5264
|
function todoListMiddleware(options) {
|
|
3961
5265
|
const writeTodos = (0, import_langchain5.tool)(
|
|
3962
5266
|
({ todos }, config) => {
|
|
@@ -3975,8 +5279,8 @@ function todoListMiddleware(options) {
|
|
|
3975
5279
|
{
|
|
3976
5280
|
name: "write_todos",
|
|
3977
5281
|
description: options?.toolDescription ?? WRITE_TODOS_DESCRIPTION,
|
|
3978
|
-
schema:
|
|
3979
|
-
todos:
|
|
5282
|
+
schema: import_zod35.z.object({
|
|
5283
|
+
todos: import_zod35.z.array(TodoSchema).describe("List of todo items to update")
|
|
3980
5284
|
})
|
|
3981
5285
|
}
|
|
3982
5286
|
);
|
|
@@ -4064,7 +5368,7 @@ function createDeepAgent(params = {}) {
|
|
|
4064
5368
|
const finalSystemPrompt = systemPrompt ? `${systemPrompt}
|
|
4065
5369
|
|
|
4066
5370
|
${BASE_PROMPT}` : BASE_PROMPT;
|
|
4067
|
-
const filesystemBackend = backend ? backend : (config) => new StateBackend(config);
|
|
5371
|
+
const filesystemBackend = backend ? backend : async (config) => new StateBackend(config);
|
|
4068
5372
|
const middleware = [
|
|
4069
5373
|
// Provides todo list management capabilities for tracking tasks
|
|
4070
5374
|
todoListMiddleware(),
|
|
@@ -4129,6 +5433,303 @@ ${BASE_PROMPT}` : BASE_PROMPT;
|
|
|
4129
5433
|
});
|
|
4130
5434
|
}
|
|
4131
5435
|
|
|
5436
|
+
// src/deep_agent_new/backends/sandboxFiles.ts
|
|
5437
|
+
var import_sandbox2 = require("@agent-infra/sandbox");
|
|
5438
|
+
var path3 = __toESM(require("path"));
|
|
5439
|
+
var SandboxFilesystem = class {
|
|
5440
|
+
/**
|
|
5441
|
+
* Create a new SandboxFilesystem instance.
|
|
5442
|
+
*
|
|
5443
|
+
* @param options - Configuration options
|
|
5444
|
+
* @param options.baseURL - Base URL of the sandbox service (default: 'http://localhost:8080')
|
|
5445
|
+
* @param options.maxFileSizeMb - Maximum file size in MB (default: 10)
|
|
5446
|
+
* @param options.sandboxInstance - Optional Sandbox instance (if provided, baseURL is ignored)
|
|
5447
|
+
*/
|
|
5448
|
+
constructor(options = {}) {
|
|
5449
|
+
const {
|
|
5450
|
+
baseURL = "http://localhost:8080",
|
|
5451
|
+
workingDirectory = "/",
|
|
5452
|
+
maxFileSizeMb = 10,
|
|
5453
|
+
sandboxInstance
|
|
5454
|
+
} = options;
|
|
5455
|
+
this.sandbox = sandboxInstance || new import_sandbox2.SandboxClient({ baseUrl: baseURL, environment: "" });
|
|
5456
|
+
this.sandbox.mcp.listMcpServers().then((servers) => {
|
|
5457
|
+
});
|
|
5458
|
+
this.sandbox.mcp.listMcpTools("browser").then((tools) => {
|
|
5459
|
+
console.log(tools);
|
|
5460
|
+
});
|
|
5461
|
+
this.baseURL = baseURL;
|
|
5462
|
+
this.maxFileSizeBytes = maxFileSizeMb * 1024 * 1024;
|
|
5463
|
+
this.workingDirectory = workingDirectory;
|
|
5464
|
+
this.homeDir = "/home/gem";
|
|
5465
|
+
}
|
|
5466
|
+
resolvePath(virtualPath) {
|
|
5467
|
+
return path3.join(this.homeDir, this.workingDirectory, virtualPath);
|
|
5468
|
+
}
|
|
5469
|
+
/**
|
|
5470
|
+
* Convert a real filesystem path to a virtual path.
|
|
5471
|
+
*
|
|
5472
|
+
* @param realPath - Real filesystem path
|
|
5473
|
+
* @returns Virtual path starting with /
|
|
5474
|
+
*/
|
|
5475
|
+
toVirtualPath(realPath) {
|
|
5476
|
+
const rootPath = path3.join(this.homeDir, this.workingDirectory);
|
|
5477
|
+
const relative2 = path3.relative(rootPath, realPath);
|
|
5478
|
+
const normalized = relative2.split(path3.sep).join("/");
|
|
5479
|
+
return "/" + normalized;
|
|
5480
|
+
}
|
|
5481
|
+
/**
|
|
5482
|
+
* List files and directories in the specified directory (non-recursive).
|
|
5483
|
+
*
|
|
5484
|
+
* @param dirPath - Virtual directory path (must start with /)
|
|
5485
|
+
* @returns List of FileInfo objects for files and directories directly in the directory.
|
|
5486
|
+
* Directories have a trailing / in their path and is_dir=true.
|
|
5487
|
+
*/
|
|
5488
|
+
async lsInfo(dirPath) {
|
|
5489
|
+
try {
|
|
5490
|
+
const resolvedPath = this.resolvePath(dirPath);
|
|
5491
|
+
const result = await this.sandbox.file.listPath({
|
|
5492
|
+
path: resolvedPath,
|
|
5493
|
+
recursive: false,
|
|
5494
|
+
show_hidden: false,
|
|
5495
|
+
max_depth: 0,
|
|
5496
|
+
include_size: false,
|
|
5497
|
+
include_permissions: false,
|
|
5498
|
+
sort_by: "name",
|
|
5499
|
+
sort_desc: false
|
|
5500
|
+
});
|
|
5501
|
+
if (!result.ok) {
|
|
5502
|
+
throw result.error;
|
|
5503
|
+
}
|
|
5504
|
+
const files = result.body?.data?.files?.map((file) => ({
|
|
5505
|
+
path: this.toVirtualPath(file.path),
|
|
5506
|
+
is_dir: file.is_directory,
|
|
5507
|
+
size: file.size,
|
|
5508
|
+
modified_at: file.modified_time
|
|
5509
|
+
})) || [];
|
|
5510
|
+
return files;
|
|
5511
|
+
} catch (e) {
|
|
5512
|
+
console.error(`Error listing files in ${dirPath}:`, e);
|
|
5513
|
+
return [];
|
|
5514
|
+
}
|
|
5515
|
+
}
|
|
5516
|
+
/**
|
|
5517
|
+
* Read file content with line numbers.
|
|
5518
|
+
*
|
|
5519
|
+
* @param filePath - Virtual file path (must start with /)
|
|
5520
|
+
* @param offset - Line offset to start reading from (0-indexed)
|
|
5521
|
+
* @param limit - Maximum number of lines to read
|
|
5522
|
+
* @returns Formatted file content with line numbers, or error message
|
|
5523
|
+
*/
|
|
5524
|
+
async read(filePath, offset = 0, limit = 1e4) {
|
|
5525
|
+
try {
|
|
5526
|
+
const resolvedPath = this.resolvePath(filePath);
|
|
5527
|
+
let content;
|
|
5528
|
+
const result = await this.sandbox.file.readFile({
|
|
5529
|
+
file: resolvedPath,
|
|
5530
|
+
start_line: offset,
|
|
5531
|
+
end_line: limit
|
|
5532
|
+
});
|
|
5533
|
+
if (!result.ok) {
|
|
5534
|
+
throw result.error;
|
|
5535
|
+
}
|
|
5536
|
+
content = result.body?.data?.content || "";
|
|
5537
|
+
return content;
|
|
5538
|
+
} catch (e) {
|
|
5539
|
+
return `Error: File '${filePath}' not found`;
|
|
5540
|
+
}
|
|
5541
|
+
}
|
|
5542
|
+
/**
|
|
5543
|
+
* Read file content as raw FileData.
|
|
5544
|
+
*
|
|
5545
|
+
* @param filePath - Virtual file path (must start with /)
|
|
5546
|
+
* @returns Raw file content as FileData
|
|
5547
|
+
*/
|
|
5548
|
+
async readRaw(filePath) {
|
|
5549
|
+
try {
|
|
5550
|
+
const content = await this.read(filePath);
|
|
5551
|
+
return {
|
|
5552
|
+
content: content.split("\n"),
|
|
5553
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5554
|
+
modified_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
5555
|
+
};
|
|
5556
|
+
} catch (e) {
|
|
5557
|
+
throw new Error(`Error reading file '${filePath}': ${e.message}`);
|
|
5558
|
+
}
|
|
5559
|
+
}
|
|
5560
|
+
/**
|
|
5561
|
+
* Create a new file with content.
|
|
5562
|
+
* Returns WriteResult. External storage sets filesUpdate=null.
|
|
5563
|
+
*
|
|
5564
|
+
* @param filePath - Virtual file path (must start with /)
|
|
5565
|
+
* @param content - File content as string
|
|
5566
|
+
* @returns WriteResult with error populated on failure
|
|
5567
|
+
*/
|
|
5568
|
+
async write(filePath, content) {
|
|
5569
|
+
try {
|
|
5570
|
+
const resolvedPath = this.resolvePath(filePath);
|
|
5571
|
+
const result = await this.sandbox.file.writeFile({
|
|
5572
|
+
file: resolvedPath,
|
|
5573
|
+
content,
|
|
5574
|
+
"encoding": "utf-8",
|
|
5575
|
+
"append": false
|
|
5576
|
+
// sudo: true
|
|
5577
|
+
});
|
|
5578
|
+
if (!result.ok) {
|
|
5579
|
+
console.error(result.error);
|
|
5580
|
+
throw result.error;
|
|
5581
|
+
}
|
|
5582
|
+
return {
|
|
5583
|
+
path: filePath,
|
|
5584
|
+
filesUpdate: {
|
|
5585
|
+
[filePath]: {
|
|
5586
|
+
content: content.split("\n"),
|
|
5587
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5588
|
+
modified_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
5589
|
+
}
|
|
5590
|
+
}
|
|
5591
|
+
};
|
|
5592
|
+
} catch (e) {
|
|
5593
|
+
throw new Error(`Error writing file '${filePath}': ${e.message}`);
|
|
5594
|
+
}
|
|
5595
|
+
}
|
|
5596
|
+
/**
|
|
5597
|
+
* Edit a file by replacing string occurrences.
|
|
5598
|
+
* Returns EditResult. External storage sets filesUpdate=null.
|
|
5599
|
+
*
|
|
5600
|
+
* @param filePath - Virtual file path (must start with /)
|
|
5601
|
+
* @param oldString - String to find and replace
|
|
5602
|
+
* @param newString - Replacement string
|
|
5603
|
+
* @param replaceAll - If true, replace all occurrences (default: false)
|
|
5604
|
+
* @returns EditResult with error, path, filesUpdate, and occurrences
|
|
5605
|
+
*/
|
|
5606
|
+
async edit(filePath, oldString, newString, replaceAll = false) {
|
|
5607
|
+
try {
|
|
5608
|
+
const resolvedPath = this.resolvePath(filePath);
|
|
5609
|
+
const result = await this.sandbox.file.strReplaceEditor({
|
|
5610
|
+
command: "str_replace",
|
|
5611
|
+
path: resolvedPath,
|
|
5612
|
+
old_str: oldString,
|
|
5613
|
+
new_str: newString,
|
|
5614
|
+
replace_mode: replaceAll ? "ALL" : "FIRST"
|
|
5615
|
+
});
|
|
5616
|
+
if (!result.ok) {
|
|
5617
|
+
throw result.error;
|
|
5618
|
+
}
|
|
5619
|
+
return {
|
|
5620
|
+
path: filePath,
|
|
5621
|
+
filesUpdate: null
|
|
5622
|
+
};
|
|
5623
|
+
} catch (e) {
|
|
5624
|
+
throw new Error(`Error editing file '${filePath}': ${e.message}`);
|
|
5625
|
+
}
|
|
5626
|
+
}
|
|
5627
|
+
/**
|
|
5628
|
+
* Structured search results or error string for invalid input.
|
|
5629
|
+
*
|
|
5630
|
+
* Searches file contents for a regex pattern within the sandbox.
|
|
5631
|
+
*
|
|
5632
|
+
* @param pattern - Regex pattern to search for
|
|
5633
|
+
* @param searchPath - Base path to search from (default: "/")
|
|
5634
|
+
* @param glob - Optional glob pattern to filter files (e.g., "*.py")
|
|
5635
|
+
* @returns List of GrepMatch objects or error string for invalid regex
|
|
5636
|
+
*/
|
|
5637
|
+
async grepRaw(pattern, searchPath = "/", glob = null) {
|
|
5638
|
+
let baseFull;
|
|
5639
|
+
baseFull = this.resolvePath(searchPath || "/");
|
|
5640
|
+
const result = await this.sandbox.file.findFiles({
|
|
5641
|
+
path: baseFull,
|
|
5642
|
+
glob: glob || "**/*"
|
|
5643
|
+
});
|
|
5644
|
+
if (!result.ok) {
|
|
5645
|
+
throw result.error;
|
|
5646
|
+
}
|
|
5647
|
+
const filePaths = result.body?.data?.files || [];
|
|
5648
|
+
const matches = [];
|
|
5649
|
+
for (const absolutePath of filePaths) {
|
|
5650
|
+
const fileData = await this.sandbox.file.searchInFile({
|
|
5651
|
+
file: absolutePath,
|
|
5652
|
+
regex: pattern
|
|
5653
|
+
});
|
|
5654
|
+
if (!fileData.ok) {
|
|
5655
|
+
continue;
|
|
5656
|
+
}
|
|
5657
|
+
const matchesData = fileData.body?.data?.matches || [];
|
|
5658
|
+
const matchLines = fileData.body?.data?.line_numbers || [];
|
|
5659
|
+
matchesData.forEach((match, index) => {
|
|
5660
|
+
matches.push({
|
|
5661
|
+
path: this.toVirtualPath(absolutePath),
|
|
5662
|
+
line: matchLines[index],
|
|
5663
|
+
text: match
|
|
5664
|
+
});
|
|
5665
|
+
});
|
|
5666
|
+
}
|
|
5667
|
+
return matches;
|
|
5668
|
+
}
|
|
5669
|
+
/**
|
|
5670
|
+
* Structured glob matching returning FileInfo objects.
|
|
5671
|
+
*
|
|
5672
|
+
* @param pattern - Glob pattern (e.g., `*.py`, `**\/*.ts`)
|
|
5673
|
+
* @param searchPath - Base path to search from (default: "/")
|
|
5674
|
+
* @returns List of FileInfo objects matching the pattern
|
|
5675
|
+
*/
|
|
5676
|
+
async globInfo(pattern, searchPath = "/") {
|
|
5677
|
+
if (pattern.startsWith("/")) {
|
|
5678
|
+
pattern = pattern.substring(1);
|
|
5679
|
+
}
|
|
5680
|
+
const resolvedSearchPath = this.resolvePath(searchPath);
|
|
5681
|
+
const result = await this.sandbox.file.findFiles({
|
|
5682
|
+
path: resolvedSearchPath,
|
|
5683
|
+
glob: pattern || "**/*"
|
|
5684
|
+
});
|
|
5685
|
+
if (!result.ok) {
|
|
5686
|
+
throw result.error;
|
|
5687
|
+
}
|
|
5688
|
+
const results = [];
|
|
5689
|
+
for (const filePath of result.body?.data?.files || []) {
|
|
5690
|
+
const fileInfo = await this.sandbox.file.listPath({
|
|
5691
|
+
path: filePath,
|
|
5692
|
+
recursive: false,
|
|
5693
|
+
show_hidden: false,
|
|
5694
|
+
max_depth: 1,
|
|
5695
|
+
include_size: false,
|
|
5696
|
+
include_permissions: false
|
|
5697
|
+
});
|
|
5698
|
+
if (!fileInfo.ok) {
|
|
5699
|
+
continue;
|
|
5700
|
+
}
|
|
5701
|
+
results.push({
|
|
5702
|
+
path: this.toVirtualPath(filePath),
|
|
5703
|
+
is_dir: false,
|
|
5704
|
+
size: fileInfo.body?.data?.files?.[0]?.size,
|
|
5705
|
+
modified_at: fileInfo.body?.data?.files?.[0]?.modified_time
|
|
5706
|
+
});
|
|
5707
|
+
}
|
|
5708
|
+
return results;
|
|
5709
|
+
}
|
|
5710
|
+
};
|
|
5711
|
+
|
|
5712
|
+
// src/middlewares/codeEvalMiddleware.ts
|
|
5713
|
+
var import_langchain8 = require("langchain");
|
|
5714
|
+
function createCodeEvalMiddleware(params = {}) {
|
|
5715
|
+
const codeEvalTool = getToolClient("execute_code");
|
|
5716
|
+
const codeExecuteFileTool = getToolClient("execute_code_file");
|
|
5717
|
+
return (0, import_langchain8.createMiddleware)({
|
|
5718
|
+
name: "codeEvalMiddleware",
|
|
5719
|
+
tools: [codeEvalTool, codeExecuteFileTool, getToolClient("convert_to_markdown")]
|
|
5720
|
+
});
|
|
5721
|
+
}
|
|
5722
|
+
|
|
5723
|
+
// src/middlewares/browserMiddleware.ts
|
|
5724
|
+
var import_langchain9 = require("langchain");
|
|
5725
|
+
function createBrowserMiddleware(params = {}) {
|
|
5726
|
+
const browserTools = toolLatticeManager.getAllLattices().filter((tool7) => tool7.key.startsWith("browser_"));
|
|
5727
|
+
return (0, import_langchain9.createMiddleware)({
|
|
5728
|
+
name: "browserMiddleware",
|
|
5729
|
+
tools: browserTools.map((tool7) => tool7.client)
|
|
5730
|
+
});
|
|
5731
|
+
}
|
|
5732
|
+
|
|
4132
5733
|
// src/agent_lattice/builders/DeepAgentGraphBuilder.ts
|
|
4133
5734
|
var DeepAgentGraphBuilder = class {
|
|
4134
5735
|
/**
|
|
@@ -4142,7 +5743,7 @@ var DeepAgentGraphBuilder = class {
|
|
|
4142
5743
|
const tools = params.tools.map((t) => {
|
|
4143
5744
|
const toolClient = getToolClient(t.key);
|
|
4144
5745
|
return toolClient;
|
|
4145
|
-
}).filter((
|
|
5746
|
+
}).filter((tool7) => tool7 !== void 0);
|
|
4146
5747
|
const subagents = params.subAgents.map((sa) => {
|
|
4147
5748
|
if (sa.client) {
|
|
4148
5749
|
return {
|
|
@@ -4161,6 +5762,34 @@ var DeepAgentGraphBuilder = class {
|
|
|
4161
5762
|
};
|
|
4162
5763
|
}
|
|
4163
5764
|
});
|
|
5765
|
+
let filesystemBackend;
|
|
5766
|
+
let middlewares = [];
|
|
5767
|
+
if (params.connectedSandbox) {
|
|
5768
|
+
const availabledModules = params.connectedSandbox?.availabledModules || ["filesystem", "code_eval", "browser"];
|
|
5769
|
+
if (availabledModules.includes("filesystem")) {
|
|
5770
|
+
const sandboxManager = sandboxLatticeManager.getSandboxLattice("default");
|
|
5771
|
+
if (!sandboxManager) {
|
|
5772
|
+
throw new Error("Sandbox manager not found");
|
|
5773
|
+
}
|
|
5774
|
+
filesystemBackend = async (agentAndState) => {
|
|
5775
|
+
let sandboxName = "global";
|
|
5776
|
+
if (params.connectedSandbox?.isolatedLevel === "agent") {
|
|
5777
|
+
sandboxName = agentLattice.config.key;
|
|
5778
|
+
} else if (params.connectedSandbox?.isolatedLevel === "thread") {
|
|
5779
|
+
sandboxName = agentAndState.threadId ?? "global";
|
|
5780
|
+
}
|
|
5781
|
+
return new SandboxFilesystem({
|
|
5782
|
+
sandboxInstance: await sandboxManager.createSandbox(sandboxName)
|
|
5783
|
+
});
|
|
5784
|
+
};
|
|
5785
|
+
}
|
|
5786
|
+
if (availabledModules.includes("code_eval")) {
|
|
5787
|
+
middlewares.push(createCodeEvalMiddleware());
|
|
5788
|
+
}
|
|
5789
|
+
if (availabledModules.includes("browser")) {
|
|
5790
|
+
middlewares.push(createBrowserMiddleware());
|
|
5791
|
+
}
|
|
5792
|
+
}
|
|
4164
5793
|
const deepAgent = createDeepAgent({
|
|
4165
5794
|
tools,
|
|
4166
5795
|
model: params.model,
|
|
@@ -4168,7 +5797,9 @@ var DeepAgentGraphBuilder = class {
|
|
|
4168
5797
|
systemPrompt: params.prompt,
|
|
4169
5798
|
subagents,
|
|
4170
5799
|
checkpointer: getCheckpointSaver("default"),
|
|
4171
|
-
skillCategories: params.skillCategories
|
|
5800
|
+
skillCategories: params.skillCategories,
|
|
5801
|
+
backend: filesystemBackend,
|
|
5802
|
+
middleware: middlewares
|
|
4172
5803
|
});
|
|
4173
5804
|
return deepAgent;
|
|
4174
5805
|
}
|
|
@@ -4282,7 +5913,8 @@ var AgentParamsBuilder = class {
|
|
|
4282
5913
|
subAgents: [...subAgents, ...internalSubAgents],
|
|
4283
5914
|
prompt: agentLattice.config.prompt,
|
|
4284
5915
|
stateSchema: agentLattice.config.schema,
|
|
4285
|
-
skillCategories
|
|
5916
|
+
skillCategories,
|
|
5917
|
+
connectedSandbox: agentLattice.config.connectedSandbox
|
|
4286
5918
|
};
|
|
4287
5919
|
}
|
|
4288
5920
|
};
|
|
@@ -6554,6 +8186,106 @@ var SkillLatticeManager = class _SkillLatticeManager extends BaseLatticeManager
|
|
|
6554
8186
|
};
|
|
6555
8187
|
var skillLatticeManager = SkillLatticeManager.getInstance();
|
|
6556
8188
|
|
|
8189
|
+
// src/mcp_lattice/McpLatticeManager.ts
|
|
8190
|
+
var import_mcp_adapters = require("@langchain/mcp-adapters");
|
|
8191
|
+
var McpLatticeManager = class _McpLatticeManager extends BaseLatticeManager {
|
|
8192
|
+
constructor() {
|
|
8193
|
+
super(...arguments);
|
|
8194
|
+
this.client = null;
|
|
8195
|
+
this.servers = /* @__PURE__ */ new Map();
|
|
8196
|
+
}
|
|
8197
|
+
static getInstance() {
|
|
8198
|
+
if (!_McpLatticeManager._instance) {
|
|
8199
|
+
_McpLatticeManager._instance = new _McpLatticeManager();
|
|
8200
|
+
}
|
|
8201
|
+
return _McpLatticeManager._instance;
|
|
8202
|
+
}
|
|
8203
|
+
getLatticeType() {
|
|
8204
|
+
return "mcp";
|
|
8205
|
+
}
|
|
8206
|
+
registerServers(servers) {
|
|
8207
|
+
for (const server of servers) {
|
|
8208
|
+
if (this.servers.has(server.name)) {
|
|
8209
|
+
console.warn(`[MCP] Server '${server.name}' already registered, skipping`);
|
|
8210
|
+
continue;
|
|
8211
|
+
}
|
|
8212
|
+
this.servers.set(server.name, server);
|
|
8213
|
+
console.log(`[MCP] Registered server: ${server.name}`);
|
|
8214
|
+
}
|
|
8215
|
+
}
|
|
8216
|
+
addServer(name, connection) {
|
|
8217
|
+
this.registerServers([{ name, connection }]);
|
|
8218
|
+
}
|
|
8219
|
+
removeServer(name) {
|
|
8220
|
+
const deleted = this.servers.delete(name);
|
|
8221
|
+
if (deleted) {
|
|
8222
|
+
console.log(`[MCP] Removed server: ${name}`);
|
|
8223
|
+
}
|
|
8224
|
+
return deleted;
|
|
8225
|
+
}
|
|
8226
|
+
async connect() {
|
|
8227
|
+
if (this.client) {
|
|
8228
|
+
console.warn("[MCP] Client already connected");
|
|
8229
|
+
return;
|
|
8230
|
+
}
|
|
8231
|
+
const serverConfigs = {};
|
|
8232
|
+
for (const [name, info] of this.servers) {
|
|
8233
|
+
serverConfigs[name] = info.connection;
|
|
8234
|
+
}
|
|
8235
|
+
if (Object.keys(serverConfigs).length === 0) {
|
|
8236
|
+
console.warn("[MCP] No servers registered");
|
|
8237
|
+
return;
|
|
8238
|
+
}
|
|
8239
|
+
this.client = new import_mcp_adapters.MultiServerMCPClient({
|
|
8240
|
+
mcpServers: serverConfigs
|
|
8241
|
+
});
|
|
8242
|
+
console.log(`[MCP] Connecting to ${this.servers.size} servers...`);
|
|
8243
|
+
await this.client.initializeConnections();
|
|
8244
|
+
console.log("[MCP] All servers connected");
|
|
8245
|
+
}
|
|
8246
|
+
async disconnect() {
|
|
8247
|
+
if (this.client) {
|
|
8248
|
+
await this.client.close();
|
|
8249
|
+
this.client = null;
|
|
8250
|
+
console.log("[MCP] Disconnected");
|
|
8251
|
+
}
|
|
8252
|
+
}
|
|
8253
|
+
isConnected() {
|
|
8254
|
+
return this.client !== null;
|
|
8255
|
+
}
|
|
8256
|
+
async getAllTools() {
|
|
8257
|
+
if (!this.client) {
|
|
8258
|
+
throw new Error("MCP client not connected");
|
|
8259
|
+
}
|
|
8260
|
+
return this.client.getTools();
|
|
8261
|
+
}
|
|
8262
|
+
getServerNames() {
|
|
8263
|
+
return Array.from(this.servers.keys());
|
|
8264
|
+
}
|
|
8265
|
+
hasServer(name) {
|
|
8266
|
+
return this.servers.has(name);
|
|
8267
|
+
}
|
|
8268
|
+
/**
|
|
8269
|
+
* 将 MCP 工具注册到 Tool Lattice
|
|
8270
|
+
* @param prefix 工具键名前缀,用于区分不同服务器的工具
|
|
8271
|
+
*/
|
|
8272
|
+
async registerToolsToToolLattice(prefix) {
|
|
8273
|
+
if (!this.client) {
|
|
8274
|
+
throw new Error("MCP client not connected");
|
|
8275
|
+
}
|
|
8276
|
+
const tools = await this.getAllTools();
|
|
8277
|
+
console.log(`[MCP] Registering ${tools.length} tools to Tool Lattice...`);
|
|
8278
|
+
for (const tool7 of tools) {
|
|
8279
|
+
const toolKey = prefix ? `${prefix}_${tool7.name}` : tool7.name;
|
|
8280
|
+
tool7.name = toolKey;
|
|
8281
|
+
toolLatticeManager.registerExistingTool(toolKey, tool7);
|
|
8282
|
+
console.log(`[MCP] Registered tool: ${toolKey}`);
|
|
8283
|
+
}
|
|
8284
|
+
console.log(`[MCP] Successfully registered ${tools.length} tools to Tool Lattice`);
|
|
8285
|
+
}
|
|
8286
|
+
};
|
|
8287
|
+
var mcpManager = McpLatticeManager.getInstance();
|
|
8288
|
+
|
|
6557
8289
|
// src/index.ts
|
|
6558
8290
|
var Protocols = __toESM(require("@axiom-lattice/protocols"));
|
|
6559
8291
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -6574,6 +8306,7 @@ var Protocols = __toESM(require("@axiom-lattice/protocols"));
|
|
|
6574
8306
|
InMemoryChunkBuffer,
|
|
6575
8307
|
InMemoryThreadStore,
|
|
6576
8308
|
LoggerLatticeManager,
|
|
8309
|
+
McpLatticeManager,
|
|
6577
8310
|
MemoryLatticeManager,
|
|
6578
8311
|
MemoryQueueClient,
|
|
6579
8312
|
MemoryScheduleStorage,
|
|
@@ -6583,6 +8316,7 @@ var Protocols = __toESM(require("@axiom-lattice/protocols"));
|
|
|
6583
8316
|
PostgresDatabase,
|
|
6584
8317
|
Protocols,
|
|
6585
8318
|
QueueLatticeManager,
|
|
8319
|
+
SandboxLatticeManager,
|
|
6586
8320
|
ScheduleLatticeManager,
|
|
6587
8321
|
SkillLatticeManager,
|
|
6588
8322
|
SqlDatabaseManager,
|
|
@@ -6608,6 +8342,7 @@ var Protocols = __toESM(require("@axiom-lattice/protocols"));
|
|
|
6608
8342
|
getModelLattice,
|
|
6609
8343
|
getNextCronTime,
|
|
6610
8344
|
getQueueLattice,
|
|
8345
|
+
getSandBoxManager,
|
|
6611
8346
|
getScheduleLattice,
|
|
6612
8347
|
getStoreLattice,
|
|
6613
8348
|
getToolClient,
|
|
@@ -6617,9 +8352,12 @@ var Protocols = __toESM(require("@axiom-lattice/protocols"));
|
|
|
6617
8352
|
getVectorStoreLattice,
|
|
6618
8353
|
hasChunkBuffer,
|
|
6619
8354
|
isValidCronExpression,
|
|
8355
|
+
isValidSandboxName,
|
|
6620
8356
|
isValidSkillName,
|
|
6621
8357
|
loggerLatticeManager,
|
|
8358
|
+
mcpManager,
|
|
6622
8359
|
modelLatticeManager,
|
|
8360
|
+
normalizeSandboxName,
|
|
6623
8361
|
parseCronExpression,
|
|
6624
8362
|
queueLatticeManager,
|
|
6625
8363
|
registerAgentLattice,
|
|
@@ -6627,6 +8365,7 @@ var Protocols = __toESM(require("@axiom-lattice/protocols"));
|
|
|
6627
8365
|
registerCheckpointSaver,
|
|
6628
8366
|
registerChunkBuffer,
|
|
6629
8367
|
registerEmbeddingsLattice,
|
|
8368
|
+
registerExistingTool,
|
|
6630
8369
|
registerLoggerLattice,
|
|
6631
8370
|
registerModelLattice,
|
|
6632
8371
|
registerQueueLattice,
|
|
@@ -6634,6 +8373,7 @@ var Protocols = __toESM(require("@axiom-lattice/protocols"));
|
|
|
6634
8373
|
registerStoreLattice,
|
|
6635
8374
|
registerToolLattice,
|
|
6636
8375
|
registerVectorStoreLattice,
|
|
8376
|
+
sandboxLatticeManager,
|
|
6637
8377
|
scheduleLatticeManager,
|
|
6638
8378
|
skillLatticeManager,
|
|
6639
8379
|
sqlDatabaseManager,
|