@mongodb-js/agent-engine-sdk-langgraph 0.11.3
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/CHANGELOG.md +39 -0
- package/LICENSE.md +201 -0
- package/README.md +149 -0
- package/dist/agent.d.ts +53 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +508 -0
- package/dist/agent.js.map +1 -0
- package/dist/backends/tool_sandbox.d.ts +15 -0
- package/dist/backends/tool_sandbox.d.ts.map +1 -0
- package/dist/backends/tool_sandbox.js +15 -0
- package/dist/backends/tool_sandbox.js.map +1 -0
- package/dist/backends/toolpod.d.ts +68 -0
- package/dist/backends/toolpod.d.ts.map +1 -0
- package/dist/backends/toolpod.js +451 -0
- package/dist/backends/toolpod.js.map +1 -0
- package/dist/call_interrupt.d.ts +20 -0
- package/dist/call_interrupt.d.ts.map +1 -0
- package/dist/call_interrupt.js +23 -0
- package/dist/call_interrupt.js.map +1 -0
- package/dist/checkpoint_branch.d.ts +58 -0
- package/dist/checkpoint_branch.d.ts.map +1 -0
- package/dist/checkpoint_branch.js +239 -0
- package/dist/checkpoint_branch.js.map +1 -0
- package/dist/checkpointer.d.ts +21 -0
- package/dist/checkpointer.d.ts.map +1 -0
- package/dist/checkpointer.js +31 -0
- package/dist/checkpointer.js.map +1 -0
- package/dist/deep_agent.d.ts +49 -0
- package/dist/deep_agent.d.ts.map +1 -0
- package/dist/deep_agent.js +110 -0
- package/dist/deep_agent.js.map +1 -0
- package/dist/deep_agent_checkpointer.d.ts +11 -0
- package/dist/deep_agent_checkpointer.d.ts.map +1 -0
- package/dist/deep_agent_checkpointer.js +19 -0
- package/dist/deep_agent_checkpointer.js.map +1 -0
- package/dist/deep_agent_task.d.ts +26 -0
- package/dist/deep_agent_task.d.ts.map +1 -0
- package/dist/deep_agent_task.js +49 -0
- package/dist/deep_agent_task.js.map +1 -0
- package/dist/durable_deep_agent.d.ts +23 -0
- package/dist/durable_deep_agent.d.ts.map +1 -0
- package/dist/durable_deep_agent.js +176 -0
- package/dist/durable_deep_agent.js.map +1 -0
- package/dist/durable_message_identity.d.ts +5 -0
- package/dist/durable_message_identity.d.ts.map +1 -0
- package/dist/durable_message_identity.js +106 -0
- package/dist/durable_message_identity.js.map +1 -0
- package/dist/durable_session.d.ts +30 -0
- package/dist/durable_session.d.ts.map +1 -0
- package/dist/durable_session.js +400 -0
- package/dist/durable_session.js.map +1 -0
- package/dist/durable_subgraphs.d.ts +13 -0
- package/dist/durable_subgraphs.d.ts.map +1 -0
- package/dist/durable_subgraphs.js +82 -0
- package/dist/durable_subgraphs.js.map +1 -0
- package/dist/durable_tools.d.ts +12 -0
- package/dist/durable_tools.d.ts.map +1 -0
- package/dist/durable_tools.js +41 -0
- package/dist/durable_tools.js.map +1 -0
- package/dist/execution_session.d.ts +63 -0
- package/dist/execution_session.d.ts.map +1 -0
- package/dist/execution_session.js +300 -0
- package/dist/execution_session.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/llm_adapter.d.ts +41 -0
- package/dist/llm_adapter.d.ts.map +1 -0
- package/dist/llm_adapter.js +177 -0
- package/dist/llm_adapter.js.map +1 -0
- package/dist/messages.d.ts +56 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +592 -0
- package/dist/messages.js.map +1 -0
- package/dist/node_logger_adapter.d.ts +51 -0
- package/dist/node_logger_adapter.d.ts.map +1 -0
- package/dist/node_logger_adapter.js +163 -0
- package/dist/node_logger_adapter.js.map +1 -0
- package/dist/platform_checkpointer.d.ts +70 -0
- package/dist/platform_checkpointer.d.ts.map +1 -0
- package/dist/platform_checkpointer.js +252 -0
- package/dist/platform_checkpointer.js.map +1 -0
- package/dist/query.d.ts +103 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +623 -0
- package/dist/query.js.map +1 -0
- package/dist/runtime.d.ts +336 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +881 -0
- package/dist/runtime.js.map +1 -0
- package/dist/secure_llm.d.ts +93 -0
- package/dist/secure_llm.d.ts.map +1 -0
- package/dist/secure_llm.js +423 -0
- package/dist/secure_llm.js.map +1 -0
- package/dist/session_factory.d.ts +6 -0
- package/dist/session_factory.d.ts.map +1 -0
- package/dist/session_factory.js +29 -0
- package/dist/session_factory.js.map +1 -0
- package/dist/session_fork.d.ts +76 -0
- package/dist/session_fork.d.ts.map +1 -0
- package/dist/session_fork.js +428 -0
- package/dist/session_fork.js.map +1 -0
- package/dist/subagents.d.ts +37 -0
- package/dist/subagents.d.ts.map +1 -0
- package/dist/subagents.js +67 -0
- package/dist/subagents.js.map +1 -0
- package/dist/suspend.d.ts +27 -0
- package/dist/suspend.d.ts.map +1 -0
- package/dist/suspend.js +87 -0
- package/dist/suspend.js.map +1 -0
- package/dist/thread_id.d.ts +30 -0
- package/dist/thread_id.d.ts.map +1 -0
- package/dist/thread_id.js +69 -0
- package/dist/thread_id.js.map +1 -0
- package/dist/workflow_json.d.ts +11 -0
- package/dist/workflow_json.d.ts.map +1 -0
- package/dist/workflow_json.js +49 -0
- package/dist/workflow_json.js.map +1 -0
- package/dist/workflow_message.d.ts +11 -0
- package/dist/workflow_message.d.ts.map +1 -0
- package/dist/workflow_message.js +179 -0
- package/dist/workflow_message.js.map +1 -0
- package/dist/workflow_state.d.ts +7 -0
- package/dist/workflow_state.d.ts.map +1 -0
- package/dist/workflow_state.js +62 -0
- package/dist/workflow_state.js.map +1 -0
- package/package.json +66 -0
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentEngineToolPodBackend — routes deep-agent filesystem/shell ops through the
|
|
3
|
+
* secure path (SecureToolWrapper → Orchestration Engine → Tool Pod handlers).
|
|
4
|
+
*
|
|
5
|
+
* Port of Python `agent_engine_sdk_langgraph/backends/toolpod.py`, targeting
|
|
6
|
+
* deepagents' current V2 backend protocol (`SandboxBackendProtocolV2`): every
|
|
7
|
+
* method returns a structured Result object with an optional `error`, so a
|
|
8
|
+
* failure is surfaced through the same channel as success — never thrown into
|
|
9
|
+
* the graph and never leaking internal topology.
|
|
10
|
+
*
|
|
11
|
+
* The active `SecureToolWrapper` is read from the async-context store on every
|
|
12
|
+
* call (not captured at construction): LangGraph builds the backend on one task
|
|
13
|
+
* and invokes it on another, so a captured reference would be stale.
|
|
14
|
+
*
|
|
15
|
+
* Batch downloads (`downloadFiles`) fan out concurrently in native mode, with
|
|
16
|
+
* one `filesystem_download` call per file so OE policy and audit stay
|
|
17
|
+
* independent. Under a durable `AttemptContext` they stay sequential: unkeyed
|
|
18
|
+
* activities are exclusive on the attempt gate, and overlapping them raises
|
|
19
|
+
* CONFLICT.
|
|
20
|
+
*/
|
|
21
|
+
import { currentAttemptContext, getCurrentWrapper, getLogger, PolicyDeniedException, TerminalExecutionError, ToolCallTimeoutError, } from "@mongodb-js/agent-engine-runner-shared";
|
|
22
|
+
const logger = getLogger("agent_engine_sdk_langgraph.backends.toolpod");
|
|
23
|
+
const RETRYABLE = "[RETRYABLE]";
|
|
24
|
+
const NON_RETRYABLE = "[NON-RETRYABLE]";
|
|
25
|
+
const MAX_DOWNLOAD_WORKERS = 16;
|
|
26
|
+
// Cluster-internal DNS suffixes (Kubernetes, consul, .local). Catches things
|
|
27
|
+
// like `db.foo.svc.cluster.local` before the host:port pattern below does.
|
|
28
|
+
const INTERNAL_DNS_RE = /\b[a-z0-9][a-z0-9.-]*\.(?:svc\.cluster\.local|cluster\.local|internal|local)\b/gi;
|
|
29
|
+
// Bracketed IPv6 host:port (`[::1]:8080`, `[fd00::1]:27017`). Runs before the
|
|
30
|
+
// alphanumeric host:port regex — that one's leading `[a-z0-9]` class can't
|
|
31
|
+
// match `[`.
|
|
32
|
+
const IPV6_HOST_PORT_RE = /\[[0-9a-fA-F:]+\]:\d{2,5}/g;
|
|
33
|
+
// `host:port` where port is 2–5 digits. Runs after the DNS replacement so
|
|
34
|
+
// `db.internal:27017` loses its port here rather than being orphaned.
|
|
35
|
+
const HOST_PORT_RE = /\b[a-z0-9][a-z0-9.-]*:\d{2,5}\b/gi;
|
|
36
|
+
// Any remaining multi-segment absolute path.
|
|
37
|
+
const ABS_PATH_RE = /\/[^/\s"'()]+(?:\/[^/\s"'()]*)*/g;
|
|
38
|
+
/**
|
|
39
|
+
* Strip internal topology (workspace path, cluster hostnames/ports, absolute
|
|
40
|
+
* paths) from a handler-supplied error string before it reaches the agent
|
|
41
|
+
* graph. Mirrors Python `_sanitize_handler_error`: the "no internal
|
|
42
|
+
* hostnames/ports/paths" invariant applies to handler errors, not only
|
|
43
|
+
* exception-derived ones. Order matters — host:port pairs are consumed before
|
|
44
|
+
* bare DNS names so a port is never left orphaned.
|
|
45
|
+
*/
|
|
46
|
+
function sanitizeHandlerError(message) {
|
|
47
|
+
let out = message;
|
|
48
|
+
const workspace = process.env["WORKSPACE_DIR"]?.replace(/\/+$/, "");
|
|
49
|
+
if (workspace)
|
|
50
|
+
out = out.split(workspace).join("<workspace>");
|
|
51
|
+
out = out.replace(IPV6_HOST_PORT_RE, "<host>");
|
|
52
|
+
out = out.replace(HOST_PORT_RE, "<host>");
|
|
53
|
+
out = out.replace(INTERNAL_DNS_RE, "<host>");
|
|
54
|
+
return out.replace(ABS_PATH_RE, "<path>");
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Classify a thrown error as retryable or non-retryable and return a generic,
|
|
58
|
+
* topology-free description. Full details are logged by the caller; only this
|
|
59
|
+
* category string reaches the agent. Mirrors Python `_classify_error`.
|
|
60
|
+
*
|
|
61
|
+
* PolicyDenied and programming errors (TypeError/RangeError etc., and the
|
|
62
|
+
* "no wrapper in context" RuntimeError) are non-retryable — retrying with the
|
|
63
|
+
* same inputs can never succeed. Everything else defaults to retryable so the
|
|
64
|
+
* agent doesn't give up on a transient.
|
|
65
|
+
*/
|
|
66
|
+
function classifyError(exc) {
|
|
67
|
+
if (exc instanceof PolicyDeniedException) {
|
|
68
|
+
return `${NON_RETRYABLE} Policy denied this operation`;
|
|
69
|
+
}
|
|
70
|
+
if (exc instanceof TerminalExecutionError) {
|
|
71
|
+
return `${NON_RETRYABLE} This execution already ended`;
|
|
72
|
+
}
|
|
73
|
+
if (exc instanceof ToolCallTimeoutError) {
|
|
74
|
+
// Non-retryable: the call already consumed its whole deadline, so an
|
|
75
|
+
// automatic retry spends another full one to most likely fail the same way.
|
|
76
|
+
// The agent decides whether the work is worth re-attempting.
|
|
77
|
+
return `${NON_RETRYABLE} Operation timed out`;
|
|
78
|
+
}
|
|
79
|
+
if (exc instanceof TypeError ||
|
|
80
|
+
exc instanceof RangeError ||
|
|
81
|
+
exc instanceof ReferenceError ||
|
|
82
|
+
exc instanceof SyntaxError ||
|
|
83
|
+
exc instanceof MissingWrapperError) {
|
|
84
|
+
return `${NON_RETRYABLE} Programming error — retry will not help`;
|
|
85
|
+
}
|
|
86
|
+
return `${RETRYABLE} Operation failed`;
|
|
87
|
+
}
|
|
88
|
+
/** Raised when the backend is used outside an AER execution context. */
|
|
89
|
+
class MissingWrapperError extends Error {
|
|
90
|
+
}
|
|
91
|
+
function getWrapper() {
|
|
92
|
+
const wrapper = getCurrentWrapper();
|
|
93
|
+
if (wrapper == null) {
|
|
94
|
+
throw new MissingWrapperError("No SecureToolWrapper in context — " +
|
|
95
|
+
"AgentEngineToolPodBackend must run inside AER execution");
|
|
96
|
+
}
|
|
97
|
+
return wrapper;
|
|
98
|
+
}
|
|
99
|
+
/** Truthy `error` field on a handler result, sanitized; else undefined. */
|
|
100
|
+
function handlerError(result) {
|
|
101
|
+
const err = result["error"];
|
|
102
|
+
return err ? sanitizeHandlerError(String(err)) : undefined;
|
|
103
|
+
}
|
|
104
|
+
function isObject(v) {
|
|
105
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
106
|
+
}
|
|
107
|
+
/** Human-readable type for protocol-violation messages (`typeof [] === "object"`). */
|
|
108
|
+
function describeType(v) {
|
|
109
|
+
if (v === null)
|
|
110
|
+
return "null";
|
|
111
|
+
if (Array.isArray(v))
|
|
112
|
+
return "array";
|
|
113
|
+
return typeof v;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Backend that routes every operation through Atlas Agent Engine's secure path. Each
|
|
117
|
+
* method delegates to `SecureToolWrapper.executeTool`, which sends the request
|
|
118
|
+
* to the OE for policy approval and audit logging before it runs in the Tool
|
|
119
|
+
* Pod.
|
|
120
|
+
*/
|
|
121
|
+
export class AgentEngineToolPodBackend {
|
|
122
|
+
id = "agent-engine-toolpod";
|
|
123
|
+
/**
|
|
124
|
+
* Execute a Tool Pod handler through the secure wrapper. Returns the wire
|
|
125
|
+
* result on success, or a classified `[RETRYABLE]`/`[NON-RETRYABLE]` error
|
|
126
|
+
* string on failure (exceptions are logged and translated, never rethrown).
|
|
127
|
+
*/
|
|
128
|
+
async call(toolName, args) {
|
|
129
|
+
try {
|
|
130
|
+
const wrapper = getWrapper();
|
|
131
|
+
const raw = await wrapper.executeTool(toolName, args, { isLocal: false });
|
|
132
|
+
if (isObject(raw))
|
|
133
|
+
return { ok: true, result: raw };
|
|
134
|
+
return {
|
|
135
|
+
ok: false,
|
|
136
|
+
error: `${NON_RETRYABLE} ${toolName} protocol violation: ` +
|
|
137
|
+
`expected object, got ${describeType(raw)}`,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
catch (exc) {
|
|
141
|
+
const msg = classifyError(exc);
|
|
142
|
+
logger.warn(`Tool call ${toolName} failed: ${String(exc)}`);
|
|
143
|
+
return { ok: false, error: msg };
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
// ------------------------------------------------------------------
|
|
147
|
+
// Read operations
|
|
148
|
+
// ------------------------------------------------------------------
|
|
149
|
+
async ls(path) {
|
|
150
|
+
const outcome = await this.call("filesystem_ls", { path });
|
|
151
|
+
if (!outcome.ok)
|
|
152
|
+
return { error: outcome.error };
|
|
153
|
+
const { result } = outcome;
|
|
154
|
+
const handlerErr = handlerError(result);
|
|
155
|
+
if (handlerErr !== undefined)
|
|
156
|
+
return { error: handlerErr };
|
|
157
|
+
const entries = result["entries"];
|
|
158
|
+
if (!Array.isArray(entries)) {
|
|
159
|
+
return {
|
|
160
|
+
error: `${NON_RETRYABLE} filesystem_ls protocol violation: 'entries' not an array`,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
return mapFileInfos(entries, "filesystem_ls", "entry");
|
|
164
|
+
}
|
|
165
|
+
async read(filePath, offset = 0, limit = 2000) {
|
|
166
|
+
const outcome = await this.call("filesystem_read", {
|
|
167
|
+
file_path: filePath,
|
|
168
|
+
offset,
|
|
169
|
+
limit,
|
|
170
|
+
});
|
|
171
|
+
if (!outcome.ok)
|
|
172
|
+
return { error: outcome.error };
|
|
173
|
+
const { result } = outcome;
|
|
174
|
+
const handlerErr = handlerError(result);
|
|
175
|
+
if (handlerErr !== undefined)
|
|
176
|
+
return { error: handlerErr };
|
|
177
|
+
const content = result["content"];
|
|
178
|
+
if (typeof content !== "string") {
|
|
179
|
+
return {
|
|
180
|
+
error: `${NON_RETRYABLE} filesystem_read protocol violation: 'content' not a string`,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
return { content, mimeType: "text/plain" };
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Raw read is not backed by a dedicated wire handler; the Tool Pod exposes
|
|
187
|
+
* only line-oriented `filesystem_read`. We wrap its text content in a v2
|
|
188
|
+
* FileData so binary-unaware callers still work. Genuine binary reads should
|
|
189
|
+
* use `downloadFiles`, which carries raw bytes base64-encoded.
|
|
190
|
+
*/
|
|
191
|
+
async readRaw(filePath) {
|
|
192
|
+
const res = await this.read(filePath);
|
|
193
|
+
if (res.error !== undefined)
|
|
194
|
+
return { error: res.error };
|
|
195
|
+
const now = new Date().toISOString();
|
|
196
|
+
const data = {
|
|
197
|
+
content: res.content ?? "",
|
|
198
|
+
mimeType: res.mimeType ?? "text/plain",
|
|
199
|
+
created_at: now,
|
|
200
|
+
modified_at: now,
|
|
201
|
+
};
|
|
202
|
+
return { data };
|
|
203
|
+
}
|
|
204
|
+
async grep(pattern, path, glob) {
|
|
205
|
+
const args = { pattern };
|
|
206
|
+
if (path != null)
|
|
207
|
+
args["path"] = path;
|
|
208
|
+
if (glob != null)
|
|
209
|
+
args["glob"] = glob;
|
|
210
|
+
const outcome = await this.call("filesystem_grep", args);
|
|
211
|
+
if (!outcome.ok)
|
|
212
|
+
return { error: outcome.error };
|
|
213
|
+
const { result } = outcome;
|
|
214
|
+
const handlerErr = handlerError(result);
|
|
215
|
+
if (handlerErr !== undefined)
|
|
216
|
+
return { error: handlerErr };
|
|
217
|
+
const raw = result["matches"];
|
|
218
|
+
if (!Array.isArray(raw)) {
|
|
219
|
+
return {
|
|
220
|
+
error: `${NON_RETRYABLE} filesystem_grep protocol violation: 'matches' not an array`,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
const matches = [];
|
|
224
|
+
for (const m of raw) {
|
|
225
|
+
// Validate each element rather than coercing — an unchecked
|
|
226
|
+
// `Number(o["line"])` / `String(o["path"])` would silently yield `NaN` /
|
|
227
|
+
// `"undefined"` on a malformed element instead of surfacing the
|
|
228
|
+
// protocol violation, matching the array-shape checks above.
|
|
229
|
+
if (!isObject(m) ||
|
|
230
|
+
typeof m["path"] !== "string" ||
|
|
231
|
+
typeof m["line"] !== "number" ||
|
|
232
|
+
typeof m["text"] !== "string") {
|
|
233
|
+
return {
|
|
234
|
+
error: `${NON_RETRYABLE} filesystem_grep protocol violation: malformed match (expected {path: string, line: number, text: string})`,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
matches.push({ path: m["path"], line: m["line"], text: m["text"] });
|
|
238
|
+
}
|
|
239
|
+
return { matches };
|
|
240
|
+
}
|
|
241
|
+
async glob(pattern, path = "/") {
|
|
242
|
+
const outcome = await this.call("filesystem_glob", {
|
|
243
|
+
pattern,
|
|
244
|
+
path,
|
|
245
|
+
});
|
|
246
|
+
if (!outcome.ok)
|
|
247
|
+
return { error: outcome.error };
|
|
248
|
+
const { result } = outcome;
|
|
249
|
+
const handlerErr = handlerError(result);
|
|
250
|
+
if (handlerErr !== undefined)
|
|
251
|
+
return { error: handlerErr };
|
|
252
|
+
const raw = result["matches"];
|
|
253
|
+
if (!Array.isArray(raw)) {
|
|
254
|
+
return {
|
|
255
|
+
error: `${NON_RETRYABLE} filesystem_glob protocol violation: 'matches' not an array`,
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
return mapFileInfos(raw, "filesystem_glob", "match");
|
|
259
|
+
}
|
|
260
|
+
// ------------------------------------------------------------------
|
|
261
|
+
// Write operations
|
|
262
|
+
// ------------------------------------------------------------------
|
|
263
|
+
async write(filePath, content) {
|
|
264
|
+
const outcome = await this.call("filesystem_write", {
|
|
265
|
+
file_path: filePath,
|
|
266
|
+
content,
|
|
267
|
+
});
|
|
268
|
+
if (!outcome.ok)
|
|
269
|
+
return { error: outcome.error };
|
|
270
|
+
const { result } = outcome;
|
|
271
|
+
const handlerErr = handlerError(result);
|
|
272
|
+
if (handlerErr !== undefined)
|
|
273
|
+
return { error: handlerErr };
|
|
274
|
+
const path = result["path"];
|
|
275
|
+
if (typeof path !== "string") {
|
|
276
|
+
return {
|
|
277
|
+
error: `${NON_RETRYABLE} filesystem_write protocol violation: success response missing 'path' string`,
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
return { path };
|
|
281
|
+
}
|
|
282
|
+
async edit(filePath, oldString, newString, replaceAll = false) {
|
|
283
|
+
const outcome = await this.call("filesystem_edit", {
|
|
284
|
+
file_path: filePath,
|
|
285
|
+
old_string: oldString,
|
|
286
|
+
new_string: newString,
|
|
287
|
+
replace_all: replaceAll,
|
|
288
|
+
});
|
|
289
|
+
if (!outcome.ok)
|
|
290
|
+
return { error: outcome.error };
|
|
291
|
+
const { result } = outcome;
|
|
292
|
+
const handlerErr = handlerError(result);
|
|
293
|
+
if (handlerErr !== undefined)
|
|
294
|
+
return { error: handlerErr };
|
|
295
|
+
const occurrences = result["occurrences"];
|
|
296
|
+
if (typeof occurrences !== "number") {
|
|
297
|
+
return {
|
|
298
|
+
error: `${NON_RETRYABLE} filesystem_edit protocol violation: success response missing 'occurrences' int`,
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
return { path: filePath, occurrences };
|
|
302
|
+
}
|
|
303
|
+
// ------------------------------------------------------------------
|
|
304
|
+
// Shell execution
|
|
305
|
+
// ------------------------------------------------------------------
|
|
306
|
+
async execute(command) {
|
|
307
|
+
const outcome = await this.call("shell_execute", { command });
|
|
308
|
+
if (!outcome.ok) {
|
|
309
|
+
return { output: outcome.error, exitCode: 1, truncated: false };
|
|
310
|
+
}
|
|
311
|
+
const { result } = outcome;
|
|
312
|
+
// A framework error (e.g. missing /bin/sh) returns an `error` field
|
|
313
|
+
// alongside a non-zero exit_code and empty output. Surface the sanitized
|
|
314
|
+
// message — otherwise the agent sees only an empty output + exit code and
|
|
315
|
+
// loses the cause — and preserve the handler's exit code.
|
|
316
|
+
const handlerErr = handlerError(result);
|
|
317
|
+
if (handlerErr !== undefined) {
|
|
318
|
+
const code = result["exit_code"];
|
|
319
|
+
return {
|
|
320
|
+
output: handlerErr,
|
|
321
|
+
exitCode: typeof code === "number" ? code : 1,
|
|
322
|
+
truncated: false,
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
const output = result["output"];
|
|
326
|
+
const exitCode = result["exit_code"];
|
|
327
|
+
if (typeof output !== "string" || typeof exitCode !== "number") {
|
|
328
|
+
return {
|
|
329
|
+
output: `${NON_RETRYABLE} shell_execute protocol violation: response must contain str 'output' and int 'exit_code'`,
|
|
330
|
+
exitCode: 1,
|
|
331
|
+
truncated: false,
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
return {
|
|
335
|
+
output,
|
|
336
|
+
exitCode,
|
|
337
|
+
truncated: Boolean(result["truncated"]),
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
// ------------------------------------------------------------------
|
|
341
|
+
// Download / upload
|
|
342
|
+
// ------------------------------------------------------------------
|
|
343
|
+
/**
|
|
344
|
+
* Download a single path. Never throws: failures become error responses.
|
|
345
|
+
*/
|
|
346
|
+
async downloadOne(path) {
|
|
347
|
+
const outcome = await this.call("filesystem_download", {
|
|
348
|
+
file_path: path,
|
|
349
|
+
});
|
|
350
|
+
if (!outcome.ok) {
|
|
351
|
+
return downloadError(path, outcome.error);
|
|
352
|
+
}
|
|
353
|
+
const { result } = outcome;
|
|
354
|
+
const handlerErr = handlerError(result);
|
|
355
|
+
if (handlerErr !== undefined) {
|
|
356
|
+
return downloadError(path, handlerErr);
|
|
357
|
+
}
|
|
358
|
+
const b64 = result["content_base64"];
|
|
359
|
+
if (typeof b64 !== "string") {
|
|
360
|
+
return downloadError(path, `${NON_RETRYABLE} filesystem_download protocol violation: success response missing 'content_base64' field`);
|
|
361
|
+
}
|
|
362
|
+
return {
|
|
363
|
+
path,
|
|
364
|
+
content: new Uint8Array(Buffer.from(b64, "base64")),
|
|
365
|
+
error: null,
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Download files via the audited `filesystem_download` handler — one call per
|
|
370
|
+
* path so each is policy-checked and logged independently — then base64-decode
|
|
371
|
+
* the `content_base64` field into raw bytes. Responses preserve input order;
|
|
372
|
+
* on failure `content` is null and `error` carries a classified message.
|
|
373
|
+
*
|
|
374
|
+
* Native-mode batches fan out on a bounded worker pool so skills loading
|
|
375
|
+
* pays one round-trip of latency instead of a sum. Durable attempts stay
|
|
376
|
+
* sequential: unkeyed activities are exclusive under the attempt gate, and
|
|
377
|
+
* overlapping them raises CONFLICT.
|
|
378
|
+
*/
|
|
379
|
+
async downloadFiles(paths) {
|
|
380
|
+
if (paths.length <= 1 || currentAttemptContext() != null) {
|
|
381
|
+
// Single path skips pool overhead. Durable attempts stay sequential:
|
|
382
|
+
// unkeyed activities are exclusive under the attempt gate, and
|
|
383
|
+
// overlapping them raises CONFLICT.
|
|
384
|
+
const responses = [];
|
|
385
|
+
for (const path of paths) {
|
|
386
|
+
responses.push(await this.downloadOne(path));
|
|
387
|
+
}
|
|
388
|
+
return responses;
|
|
389
|
+
}
|
|
390
|
+
return mapLimited(paths, MAX_DOWNLOAD_WORKERS, (path) => this.downloadOne(path));
|
|
391
|
+
}
|
|
392
|
+
async uploadFiles(files) {
|
|
393
|
+
// Return per-file classified errors rather than throwing — a raw throw
|
|
394
|
+
// would bypass the [RETRYABLE]/[NON-RETRYABLE] contract every other method
|
|
395
|
+
// honours. No wire handler exists for upload yet.
|
|
396
|
+
const err = `${NON_RETRYABLE} uploadFiles is not implemented`;
|
|
397
|
+
return files.map(([path]) => uploadError(path, err));
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Map raw wire entries to `FileInfo[]`, validating each element. A malformed
|
|
402
|
+
* element (not an object, or a non-string `path`) fails the whole result with a
|
|
403
|
+
* protocol-violation error rather than coercing to `String(undefined)` — the
|
|
404
|
+
* same all-or-nothing contract the array-shape checks in `ls`/`glob` use.
|
|
405
|
+
* `handler`/`elem` name the source for the error message.
|
|
406
|
+
*/
|
|
407
|
+
function mapFileInfos(entries, handler, elem) {
|
|
408
|
+
const files = [];
|
|
409
|
+
for (const e of entries) {
|
|
410
|
+
if (!isObject(e) || typeof e["path"] !== "string") {
|
|
411
|
+
return {
|
|
412
|
+
error: `${NON_RETRYABLE} ${handler} protocol violation: malformed ${elem} (expected object with string 'path')`,
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
files.push({ path: e["path"], is_dir: Boolean(e["is_dir"]) });
|
|
416
|
+
}
|
|
417
|
+
return { files };
|
|
418
|
+
}
|
|
419
|
+
// `FileDownloadResponse.error` / `FileUploadResponse.error` are typed as a
|
|
420
|
+
// `FileOperationError` enum in the deepagents protocol. We deliberately ship
|
|
421
|
+
// richer strings — sanitized handler messages and [RETRYABLE]/[NON-RETRYABLE]
|
|
422
|
+
// prefixes — so the agent can tell transients from contract bugs. The cast is
|
|
423
|
+
// parked once on each helper instead of at every call site.
|
|
424
|
+
function downloadError(path, err) {
|
|
425
|
+
return { path, content: null, error: err };
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Run `fn` over `items` with at most `limit` in-flight promises. Result[i]
|
|
429
|
+
* corresponds to items[i] even when completions finish out of order.
|
|
430
|
+
*/
|
|
431
|
+
async function mapLimited(items, limit, fn) {
|
|
432
|
+
const results = new Array(items.length);
|
|
433
|
+
let cursor = 0;
|
|
434
|
+
async function worker() {
|
|
435
|
+
while (cursor < items.length) {
|
|
436
|
+
const index = cursor;
|
|
437
|
+
cursor += 1;
|
|
438
|
+
const item = items[index];
|
|
439
|
+
if (item === undefined)
|
|
440
|
+
return;
|
|
441
|
+
results[index] = await fn(item);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
const workers = Math.min(limit, items.length);
|
|
445
|
+
await Promise.all(Array.from({ length: workers }, () => worker()));
|
|
446
|
+
return results;
|
|
447
|
+
}
|
|
448
|
+
function uploadError(path, err) {
|
|
449
|
+
return { path, error: err };
|
|
450
|
+
}
|
|
451
|
+
//# sourceMappingURL=toolpod.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toolpod.js","sourceRoot":"","sources":["../../src/backends/toolpod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAkBH,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,SAAS,EACT,qBAAqB,EACrB,sBAAsB,EACtB,oBAAoB,GAErB,MAAM,wCAAwC,CAAC;AAEhD,MAAM,MAAM,GAAG,SAAS,CAAC,6CAA6C,CAAC,CAAC;AAExE,MAAM,SAAS,GAAG,aAAa,CAAC;AAChC,MAAM,aAAa,GAAG,iBAAiB,CAAC;AACxC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAEhC,6EAA6E;AAC7E,2EAA2E;AAC3E,MAAM,eAAe,GACnB,k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|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-call Stop opt-in for local (callback-routed) tools.
|
|
3
|
+
*
|
|
4
|
+
* Node has no preemptive cancel: the runtime can stop *waiting* on a tool
|
|
5
|
+
* body, but only the body can stop its own work. A tool branded with
|
|
6
|
+
* {@link withCallInterruptSupport} declares that its body consumes the
|
|
7
|
+
* per-call signal (via `getCallAbortSignal()` from
|
|
8
|
+
* `@mongodb-js/agent-engine-runner-shared`) and stops at its checkpoints.
|
|
9
|
+
* Only branded tools answer a per-call Stop with `interrupted`; unbranded
|
|
10
|
+
* tools honestly answer `not_cancellable` and run out.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Brand a tool as supporting per-call interrupt. The body must honor the
|
|
14
|
+
* signal from `getCallAbortSignal()` — check `signal.aborted` between steps
|
|
15
|
+
* or pass the signal to APIs that accept one (`fetch`, streams).
|
|
16
|
+
*
|
|
17
|
+
* Returns the same tool for chaining at definition time.
|
|
18
|
+
*/
|
|
19
|
+
export declare function withCallInterruptSupport<T>(tool: T): T;
|
|
20
|
+
//# sourceMappingURL=call_interrupt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"call_interrupt.d.ts","sourceRoot":"","sources":["../src/call_interrupt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,CAGtD"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-call Stop opt-in for local (callback-routed) tools.
|
|
3
|
+
*
|
|
4
|
+
* Node has no preemptive cancel: the runtime can stop *waiting* on a tool
|
|
5
|
+
* body, but only the body can stop its own work. A tool branded with
|
|
6
|
+
* {@link withCallInterruptSupport} declares that its body consumes the
|
|
7
|
+
* per-call signal (via `getCallAbortSignal()` from
|
|
8
|
+
* `@mongodb-js/agent-engine-runner-shared`) and stops at its checkpoints.
|
|
9
|
+
* Only branded tools answer a per-call Stop with `interrupted`; unbranded
|
|
10
|
+
* tools honestly answer `not_cancellable` and run out.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Brand a tool as supporting per-call interrupt. The body must honor the
|
|
14
|
+
* signal from `getCallAbortSignal()` — check `signal.aborted` between steps
|
|
15
|
+
* or pass the signal to APIs that accept one (`fetch`, streams).
|
|
16
|
+
*
|
|
17
|
+
* Returns the same tool for chaining at definition time.
|
|
18
|
+
*/
|
|
19
|
+
export function withCallInterruptSupport(tool) {
|
|
20
|
+
tool.supportsCallInterrupt = true;
|
|
21
|
+
return tool;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=call_interrupt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"call_interrupt.js","sourceRoot":"","sources":["../src/call_interrupt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CAAI,IAAO;IAChD,IAA4C,CAAC,qBAAqB,GAAG,IAAI,CAAC;IAC3E,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/** Copy a LangGraph checkpoint branch point into a new thread. */
|
|
2
|
+
import type { RunnableConfig } from "@langchain/core/runnables";
|
|
3
|
+
import type { CompiledStateGraph } from "@langchain/langgraph";
|
|
4
|
+
export interface LangGraphCheckpoint {
|
|
5
|
+
readonly threadId: string;
|
|
6
|
+
readonly checkpointId: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function branchPointFromMetadata(metadata: Record<string, unknown> | null | undefined): LangGraphCheckpoint | undefined;
|
|
9
|
+
export declare function checkpointMetadata(checkpoint: LangGraphCheckpoint | undefined): {
|
|
10
|
+
langgraph_checkpoint: {
|
|
11
|
+
thread_id: string;
|
|
12
|
+
checkpoint_id: string;
|
|
13
|
+
};
|
|
14
|
+
} | undefined;
|
|
15
|
+
/** Replay plan: the source supersteps a branch copy materializes in order. */
|
|
16
|
+
export type CheckpointReplayPlan = Array<{
|
|
17
|
+
updates: Array<{
|
|
18
|
+
values?: unknown;
|
|
19
|
+
asNode?: string;
|
|
20
|
+
}>;
|
|
21
|
+
}>;
|
|
22
|
+
/**
|
|
23
|
+
* Load a completed root checkpoint, or fail closed.
|
|
24
|
+
*
|
|
25
|
+
* Fork validates this before CreateBranch so a missing or incomplete history
|
|
26
|
+
* point does not create a branch session (Python
|
|
27
|
+
* `completed_root_checkpoint` parity).
|
|
28
|
+
*/
|
|
29
|
+
export declare function completedRootCheckpoint(graph: CompiledStateGraph<unknown, unknown>, args: {
|
|
30
|
+
threadId: string;
|
|
31
|
+
historyId: string | null;
|
|
32
|
+
}): Promise<LangGraphCheckpoint>;
|
|
33
|
+
/**
|
|
34
|
+
* Build the copyable superstep plan, or raise before any destination write.
|
|
35
|
+
*
|
|
36
|
+
* Port of Python's `checkpoint_replay_plan`; fork builds this before
|
|
37
|
+
* CreateBranch so the copied snapshot is the one that was validated.
|
|
38
|
+
*/
|
|
39
|
+
export declare function checkpointReplayPlan(graph: CompiledStateGraph<unknown, unknown>, source: LangGraphCheckpoint): Promise<CheckpointReplayPlan>;
|
|
40
|
+
/**
|
|
41
|
+
* Rebuild `source` in the empty thread named by `targetConfig`.
|
|
42
|
+
*
|
|
43
|
+
* `plan` is the pre-dispatch validated plan from `checkpointReplayPlan`;
|
|
44
|
+
* callers that validated before a side effect pass it so the copy can only
|
|
45
|
+
* materialize that snapshot.
|
|
46
|
+
*/
|
|
47
|
+
export declare function copyCheckpoint(graph: CompiledStateGraph<unknown, unknown>, targetConfig: RunnableConfig, source: LangGraphCheckpoint, plan?: CheckpointReplayPlan): Promise<void>;
|
|
48
|
+
/** True when `config`'s thread has no checkpoints yet. */
|
|
49
|
+
export declare function destinationThreadIsEmpty(graph: CompiledStateGraph<unknown, unknown>, config: RunnableConfig): Promise<boolean>;
|
|
50
|
+
/**
|
|
51
|
+
* Copy `source` onto an empty dest thread.
|
|
52
|
+
*
|
|
53
|
+
* In-app fork already materializes dest; OE still dispatches later dest
|
|
54
|
+
* invokes with the source branch point. If dest already has checkpoints,
|
|
55
|
+
* leave it alone (Python `initialize_checkpoint_branch` parity).
|
|
56
|
+
*/
|
|
57
|
+
export declare function initializeCheckpointBranch(graph: CompiledStateGraph<unknown, unknown>, config: RunnableConfig, source: LangGraphCheckpoint): Promise<void>;
|
|
58
|
+
//# sourceMappingURL=checkpoint_branch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkpoint_branch.d.ts","sourceRoot":"","sources":["../src/checkpoint_branch.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAGlE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,KAAK,EAAE,kBAAkB,EAAiB,MAAM,sBAAsB,CAAC;AAG9E,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AAED,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,GACnD,mBAAmB,GAAG,SAAS,CAiBjC;AAED,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,mBAAmB,GAAG,SAAS,GAEzC;IACE,oBAAoB,EAAE;QACpB,SAAS,EAAE,MAAM,CAAC;QAClB,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC;CACH,GACD,SAAS,CAQZ;AAgGD,8EAA8E;AAC9E,MAAM,MAAM,oBAAoB,GAAG,KAAK,CAAC;IACvC,OAAO,EAAE,KAAK,CAAC;QAAE,MAAM,CAAC,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACvD,CAAC,CAAC;AAEH;;;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