deepagents 1.16.4 → 1.17.0
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/{agent-BAuGxPZn.d.ts → agent-CLlZT-Mb.d.ts} +36 -3
- package/dist/{agent-DOFzksfM.d.cts → agent-Di09Mxb3.d.cts} +34 -1
- package/dist/browser.cjs +1 -1
- package/dist/browser.d.cts +1 -1
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/{langsmith-DfobOVRO.js → langsmith-DYAFTn0y.js} +256 -34
- package/dist/langsmith-DYAFTn0y.js.map +1 -0
- package/dist/{langsmith-D_tzVwxp.cjs → langsmith-Fjf2fY1X.cjs} +260 -32
- package/dist/langsmith-Fjf2fY1X.cjs.map +1 -0
- package/dist/node.cjs +2 -2
- package/dist/node.d.cts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/node.js +2 -2
- package/dist/{src-KaJuKnnd.js → src-B8R36RZW.js} +151 -26
- package/dist/src-B8R36RZW.js.map +1 -0
- package/dist/{src-DTOh2Xrc.cjs → src-BC1al3Te.cjs} +151 -26
- package/dist/src-BC1al3Te.cjs.map +1 -0
- package/package.json +4 -4
- package/dist/langsmith-D_tzVwxp.cjs.map +0 -1
- package/dist/langsmith-DfobOVRO.js.map +0 -1
- package/dist/src-DTOh2Xrc.cjs.map +0 -1
- package/dist/src-KaJuKnnd.js.map +0 -1
|
@@ -28,17 +28,18 @@ let micromatch = require("micromatch");
|
|
|
28
28
|
micromatch = __toESM(micromatch, 1);
|
|
29
29
|
let node_crypto = require("node:crypto");
|
|
30
30
|
let _langchain_core_messages = require("@langchain/core/messages");
|
|
31
|
+
let _langchain_core_runnables = require("@langchain/core/runnables");
|
|
31
32
|
let zod = require("zod");
|
|
32
33
|
zod = __toESM(zod, 1);
|
|
33
34
|
let langchain_chat_models_universal = require("langchain/chat_models/universal");
|
|
35
|
+
let _langchain_langgraph_zod = require("@langchain/langgraph/zod");
|
|
36
|
+
let _langchain_core_utils_types = require("@langchain/core/utils/types");
|
|
34
37
|
let yaml = require("yaml");
|
|
35
38
|
yaml = __toESM(yaml, 1);
|
|
36
|
-
let _langchain_core_runnables = require("@langchain/core/runnables");
|
|
37
39
|
let _langchain_core_tools = require("@langchain/core/tools");
|
|
38
40
|
let _langchain_core_language_models_base = require("@langchain/core/language_models/base");
|
|
39
41
|
let _langchain_core_utils_function_calling = require("@langchain/core/utils/function_calling");
|
|
40
42
|
let _langchain_core_utils_json_schema = require("@langchain/core/utils/json_schema");
|
|
41
|
-
let _langchain_core_utils_types = require("@langchain/core/utils/types");
|
|
42
43
|
let _langchain_langgraph_sdk = require("@langchain/langgraph-sdk");
|
|
43
44
|
let langsmith_traceable = require("langsmith/traceable");
|
|
44
45
|
let langsmith = require("langsmith");
|
|
@@ -57,6 +58,20 @@ function setRealpath(target, fn) {
|
|
|
57
58
|
configurable: true
|
|
58
59
|
});
|
|
59
60
|
}
|
|
61
|
+
// src/backends/pin.ts
|
|
62
|
+
const PIN = Symbol.for("deepagents.pin");
|
|
63
|
+
function getPin(backend) {
|
|
64
|
+
if (typeof backend !== "object" || backend === null) return;
|
|
65
|
+
const fn = backend[PIN];
|
|
66
|
+
return typeof fn === "function" ? fn : void 0;
|
|
67
|
+
}
|
|
68
|
+
function setPin(target, fn) {
|
|
69
|
+
Object.defineProperty(target, PIN, {
|
|
70
|
+
value: fn,
|
|
71
|
+
enumerable: false,
|
|
72
|
+
configurable: true
|
|
73
|
+
});
|
|
74
|
+
}
|
|
60
75
|
// src/backends/utils.ts
|
|
61
76
|
/**
|
|
62
77
|
* Shared utility functions for memory backend implementations.
|
|
@@ -690,6 +705,8 @@ function adaptBackendProtocol(backend) {
|
|
|
690
705
|
}
|
|
691
706
|
const realpath = getRealpath(backend);
|
|
692
707
|
if (realpath !== void 0) setRealpath(adapted, realpath);
|
|
708
|
+
const pin = getPin(backend);
|
|
709
|
+
if (pin !== void 0) setPin(adapted, pin);
|
|
693
710
|
const resolveBackendForPath = backend.resolveBackendForPath;
|
|
694
711
|
if (typeof resolveBackendForPath === "function") Object.defineProperty(adapted, "resolveBackendForPath", {
|
|
695
712
|
value: (path) => resolveBackendForPath.call(backend, path),
|
|
@@ -1742,6 +1759,7 @@ var CompositeBackend = class {
|
|
|
1742
1759
|
this.routes = Object.fromEntries(Object.entries(routes).map(([k, v]) => [k.endsWith("/") ? k : `${k}/`, isSandboxProtocol(v) ? adaptSandboxProtocol(v) : adaptBackendProtocol(v)]));
|
|
1743
1760
|
this.sortedRoutes = Object.entries(this.routes).sort((a, b) => b[0].length - a[0].length);
|
|
1744
1761
|
setRealpath(this, (path) => this.resolveRealPath(path));
|
|
1762
|
+
setPin(this, (path, options, authorize, operation) => this.runPinned(path, options, authorize, operation));
|
|
1745
1763
|
}
|
|
1746
1764
|
/** Delegates to default backend's id if it is a sandbox, otherwise empty string. */
|
|
1747
1765
|
get id() {
|
|
@@ -1783,6 +1801,22 @@ var CompositeBackend = class {
|
|
|
1783
1801
|
return realpath === void 0 ? path : await realpath(path);
|
|
1784
1802
|
}
|
|
1785
1803
|
/**
|
|
1804
|
+
* Pin via the backend that owns `path`, re-adding the route prefix to the
|
|
1805
|
+
* real path it authorizes. Runs `operation` unpinned when that backend has
|
|
1806
|
+
* no pin hook.
|
|
1807
|
+
*/
|
|
1808
|
+
runPinned(path, options, authorize, operation) {
|
|
1809
|
+
for (const [routePrefix, backend] of this.sortedRoutes) if (this.isPathWithinRoute(path, routePrefix)) {
|
|
1810
|
+
const pin = getPin(backend);
|
|
1811
|
+
if (pin === void 0) return operation();
|
|
1812
|
+
const prefix = routePrefix.slice(0, -1);
|
|
1813
|
+
const suffix = path.substring(routePrefix.length);
|
|
1814
|
+
return pin(suffix ? "/" + suffix : "/", options, (realPath) => authorize(prefix + realPath), operation);
|
|
1815
|
+
}
|
|
1816
|
+
const pin = getPin(this.default);
|
|
1817
|
+
return pin === void 0 ? operation() : pin(path, options, authorize, operation);
|
|
1818
|
+
}
|
|
1819
|
+
/**
|
|
1786
1820
|
* Determine which backend handles this key and strip prefix.
|
|
1787
1821
|
*
|
|
1788
1822
|
* @param key - Original file path
|
|
@@ -2588,11 +2622,15 @@ async function resolveRealPath(backend, canonical) {
|
|
|
2588
2622
|
/**
|
|
2589
2623
|
* Check whether `path` is permitted under `rules` for `operation`.
|
|
2590
2624
|
*
|
|
2591
|
-
* Returns the canonical path to hand the backend
|
|
2592
|
-
*
|
|
2593
|
-
*
|
|
2594
|
-
* backend has a realpath hook, the
|
|
2595
|
-
* touch. A deny on either blocks the
|
|
2625
|
+
* Returns the canonical path, the `target` to hand the backend for a
|
|
2626
|
+
* single-file operation, or an error string to surface to the model. The
|
|
2627
|
+
* decision covers every form of the target: the lexical canonical path (dot
|
|
2628
|
+
* and empty segments dropped) and, when the backend has a realpath hook, the
|
|
2629
|
+
* symlink-resolved path it would actually touch. A deny on either blocks the
|
|
2630
|
+
* call.
|
|
2631
|
+
*
|
|
2632
|
+
* `target` is the path with its parent resolved once and checked, so a
|
|
2633
|
+
* symlink swapped after the check cannot redirect the operation.
|
|
2596
2634
|
*
|
|
2597
2635
|
* Never throws: an invalid path (non-absolute, or containing `..` or `~`), one
|
|
2598
2636
|
* the backend cannot resolve, or a denied one is a recoverable tool error, not
|
|
@@ -2601,18 +2639,64 @@ async function resolveRealPath(backend, canonical) {
|
|
|
2601
2639
|
* @internal
|
|
2602
2640
|
*/
|
|
2603
2641
|
async function checkPermission(backend, rules, operation, path) {
|
|
2604
|
-
if (rules.length === 0) return {
|
|
2642
|
+
if (rules.length === 0) return {
|
|
2643
|
+
path,
|
|
2644
|
+
target: path
|
|
2645
|
+
};
|
|
2605
2646
|
let canonical;
|
|
2647
|
+
let target;
|
|
2606
2648
|
let real;
|
|
2607
2649
|
try {
|
|
2608
2650
|
canonical = validatePath(path);
|
|
2609
2651
|
if (decidePathAccess(rules, operation, canonical) === "deny") return { error: `Error: permission denied for ${operation} on ${canonical}` };
|
|
2610
|
-
|
|
2652
|
+
target = await resolveParentRealPath(backend, canonical);
|
|
2653
|
+
real = await resolveRealPath(backend, target);
|
|
2611
2654
|
} catch (error) {
|
|
2612
2655
|
return { error: `Error: ${getErrorMessage$1(error)}` };
|
|
2613
2656
|
}
|
|
2657
|
+
if (crossesRoute(backend, canonical, target)) return { error: `Error: ${canonical} resolves to ${target}, which is served by a different backend` };
|
|
2614
2658
|
if (real !== canonical && decidePathAccess(rules, operation, real) === "deny") return { error: `Error: permission denied for ${operation} on ${canonical} (resolves to ${real})` };
|
|
2615
|
-
return {
|
|
2659
|
+
return {
|
|
2660
|
+
path: canonical,
|
|
2661
|
+
target
|
|
2662
|
+
};
|
|
2663
|
+
}
|
|
2664
|
+
/**
|
|
2665
|
+
* Run a single-path `operation` on `target` through the backend's pin hook when
|
|
2666
|
+
* rules are configured and the backend has one, so the final decision is made
|
|
2667
|
+
* on the directory the operation actually uses. `isDenied` receives the real
|
|
2668
|
+
* path. Without a hook, `operation` runs on the path `checkPermission` resolved.
|
|
2669
|
+
*
|
|
2670
|
+
* Errors raised here, rather than by `operation`, start with `errorPrefix` so
|
|
2671
|
+
* they match how the calling tool formats backend errors.
|
|
2672
|
+
*/
|
|
2673
|
+
async function runBoundToTarget(backend, rules, target, options, isDenied, operation) {
|
|
2674
|
+
const pin = rules.length > 0 ? getPin(backend) : void 0;
|
|
2675
|
+
if (pin === void 0) return operation();
|
|
2676
|
+
const { create, describe, errorPrefix } = options;
|
|
2677
|
+
let operationStarted = false;
|
|
2678
|
+
try {
|
|
2679
|
+
return await pin(target, { create }, (realPath) => {
|
|
2680
|
+
const real = validatePath(realPath);
|
|
2681
|
+
return isDenied(real) ? `${errorPrefix}permission denied for ${describe} (resolves to ${real})` : void 0;
|
|
2682
|
+
}, () => {
|
|
2683
|
+
operationStarted = true;
|
|
2684
|
+
return operation();
|
|
2685
|
+
});
|
|
2686
|
+
} catch (error) {
|
|
2687
|
+
if (operationStarted) throw error;
|
|
2688
|
+
return { error: `${errorPrefix}${describe} failed: ${getErrorMessage$1(error)}` };
|
|
2689
|
+
}
|
|
2690
|
+
}
|
|
2691
|
+
/**
|
|
2692
|
+
* Whether `target` is served by a different `CompositeBackend` route than
|
|
2693
|
+
* `requested`. Symlink resolution must not move an operation to another
|
|
2694
|
+
* backend.
|
|
2695
|
+
*/
|
|
2696
|
+
function crossesRoute(backend, requested, target) {
|
|
2697
|
+
const resolveBackendForPath = backend.resolveBackendForPath;
|
|
2698
|
+
if (typeof resolveBackendForPath !== "function" || requested === target) return false;
|
|
2699
|
+
return resolveBackendForPath.call(backend, requested)[0] !== resolveBackendForPath.call(backend, target)[0];
|
|
2616
2700
|
}
|
|
2617
2701
|
/**
|
|
2618
2702
|
* Build an error {@link ToolMessage} for a denied path or a failed backend
|
|
@@ -2786,10 +2870,11 @@ function parentPath(path) {
|
|
|
2786
2870
|
return `/${parts.slice(0, -1).join("/")}`;
|
|
2787
2871
|
}
|
|
2788
2872
|
/**
|
|
2789
|
-
* Resolve
|
|
2790
|
-
*
|
|
2873
|
+
* Resolve symlinks in the parent of `target`, keeping its leaf as given.
|
|
2874
|
+
* Backends refuse to follow (or, for delete, unlink) a symlinked leaf, so this
|
|
2875
|
+
* is the path a single-file operation actually touches.
|
|
2791
2876
|
*/
|
|
2792
|
-
async function
|
|
2877
|
+
async function resolveParentRealPath(backend, target) {
|
|
2793
2878
|
const parts = posixParts(target);
|
|
2794
2879
|
if (parts.length === 0) return resolveRealPath(backend, target);
|
|
2795
2880
|
return validatePath(`${await resolveRealPath(backend, parentPath(target))}/${parts[parts.length - 1]}`);
|
|
@@ -2956,7 +3041,11 @@ function createReadFileTool(backend, options) {
|
|
|
2956
3041
|
if (permission.error !== void 0) return toolError(runtime, "read_file", permission.error);
|
|
2957
3042
|
const { file_path, offset: requestedOffset = 0, limit: requestedLimit = 100 } = input;
|
|
2958
3043
|
const { offset, limit } = normalizeReadPagination(requestedOffset, requestedLimit);
|
|
2959
|
-
const readResult = await resolvedBackend
|
|
3044
|
+
const readResult = await runBoundToTarget(resolvedBackend, permissions, permission.target, {
|
|
3045
|
+
create: false,
|
|
3046
|
+
describe: `read on ${permission.path}`,
|
|
3047
|
+
errorPrefix: ""
|
|
3048
|
+
}, (real) => decidePathAccess(permissions, "read", real) === "deny", async () => resolvedBackend.read(permission.target, offset, limit));
|
|
2960
3049
|
if (readResult.error) return toolError(runtime, "read_file", `Error: ${readResult.error}`);
|
|
2961
3050
|
const mimeType = readResult.mimeType ?? getMimeType(file_path);
|
|
2962
3051
|
if (!isTextMimeType(mimeType)) {
|
|
@@ -3040,7 +3129,11 @@ function createWriteFileTool(backend, options) {
|
|
|
3040
3129
|
const permission = await checkPermission(resolvedBackend, permissions, "write", input.file_path);
|
|
3041
3130
|
if (permission.error !== void 0) return toolError(runtime, "write_file", permission.error);
|
|
3042
3131
|
const { file_path, content } = input;
|
|
3043
|
-
const result = await resolvedBackend
|
|
3132
|
+
const result = await runBoundToTarget(resolvedBackend, permissions, permission.target, {
|
|
3133
|
+
create: true,
|
|
3134
|
+
describe: `write on ${permission.path}`,
|
|
3135
|
+
errorPrefix: "Error: "
|
|
3136
|
+
}, (real) => decidePathAccess(permissions, "write", real) === "deny", async () => resolvedBackend.write(permission.target, content));
|
|
3044
3137
|
if (result.error) return toolError(runtime, "write_file", result.error);
|
|
3045
3138
|
const message = new langchain.ToolMessage({
|
|
3046
3139
|
content: `Successfully wrote to '${file_path}'`,
|
|
@@ -3072,7 +3165,11 @@ function createEditFileTool(backend, options) {
|
|
|
3072
3165
|
const permission = await checkPermission(resolvedBackend, permissions, "write", input.file_path);
|
|
3073
3166
|
if (permission.error !== void 0) return toolError(runtime, "edit_file", permission.error);
|
|
3074
3167
|
const { file_path, old_string, new_string, replace_all = false } = input;
|
|
3075
|
-
const result = await resolvedBackend
|
|
3168
|
+
const result = await runBoundToTarget(resolvedBackend, permissions, permission.target, {
|
|
3169
|
+
create: false,
|
|
3170
|
+
describe: `write on ${permission.path}`,
|
|
3171
|
+
errorPrefix: "Error: "
|
|
3172
|
+
}, (real) => decidePathAccess(permissions, "write", real) === "deny", async () => resolvedBackend.edit(permission.target, old_string, new_string, replace_all));
|
|
3076
3173
|
if (result.error) return toolError(runtime, "edit_file", result.error);
|
|
3077
3174
|
const message = new langchain.ToolMessage({
|
|
3078
3175
|
content: `Successfully replaced ${result.occurrences} occurrence(s) in '${file_path}'`,
|
|
@@ -3112,22 +3209,29 @@ function createDeleteTool(backend, options) {
|
|
|
3112
3209
|
const hasDescendants = await deleteTargetMayHaveDescendants(resolvedBackend, validatedPath, permissions.length > 0);
|
|
3113
3210
|
const denyingPatterns = findDeleteDenyPatterns(permissions, validatedPath, hasDescendants);
|
|
3114
3211
|
if (denyingPatterns.length > 0) return toolError(runtime, "delete", `Error: permission denied for write on ${validatedPath} (matches deny rule(s): ${denyingPatterns.join(", ")})`);
|
|
3212
|
+
let deleteTarget = validatedPath;
|
|
3115
3213
|
if (permissions.length > 0) {
|
|
3116
3214
|
let realTarget;
|
|
3117
3215
|
try {
|
|
3118
|
-
realTarget = await
|
|
3216
|
+
realTarget = await resolveParentRealPath(resolvedBackend, validatedPath);
|
|
3119
3217
|
} catch (error) {
|
|
3120
3218
|
return toolError(runtime, "delete", `Error: ${getErrorMessage$1(error)}`);
|
|
3121
3219
|
}
|
|
3220
|
+
if (crossesRoute(resolvedBackend, validatedPath, realTarget)) return toolError(runtime, "delete", `Error: ${validatedPath} resolves to ${realTarget}, which is served by a different backend`);
|
|
3122
3221
|
if (realTarget !== validatedPath) {
|
|
3123
3222
|
if (findDeleteDenyPatterns(permissions, realTarget, hasDescendants).length > 0) return toolError(runtime, "delete", `Error: permission denied for write on ${validatedPath} (resolves to ${realTarget})`);
|
|
3124
3223
|
}
|
|
3224
|
+
deleteTarget = realTarget;
|
|
3125
3225
|
}
|
|
3126
3226
|
if (!supportsDelete(resolvedBackend)) return toolError(runtime, "delete", `Error: deletion is not available for '${validatedPath}'.`);
|
|
3127
|
-
const result = await resolvedBackend
|
|
3227
|
+
const result = await runBoundToTarget(resolvedBackend, permissions, deleteTarget, {
|
|
3228
|
+
create: false,
|
|
3229
|
+
describe: `write on ${validatedPath}`,
|
|
3230
|
+
errorPrefix: "Error: "
|
|
3231
|
+
}, (real) => findDeleteDenyPatterns(permissions, real, hasDescendants).length > 0, async () => resolvedBackend.delete(deleteTarget));
|
|
3128
3232
|
if (result.error) return toolError(runtime, "delete", result.error);
|
|
3129
3233
|
const message = new langchain.ToolMessage({
|
|
3130
|
-
content: `Deleted ${result.path
|
|
3234
|
+
content: `Deleted ${result.path === void 0 || result.path === deleteTarget ? validatedPath : result.path}`,
|
|
3131
3235
|
tool_call_id: runtime.toolCall?.id,
|
|
3132
3236
|
name: "delete",
|
|
3133
3237
|
metadata: result.metadata
|
|
@@ -4563,7 +4667,7 @@ const INVALID_TOOL_MESSAGE_BLOCK_TYPES = [
|
|
|
4563
4667
|
/**
|
|
4564
4668
|
* Create Command with filtered state update from subagent result
|
|
4565
4669
|
*/
|
|
4566
|
-
function returnCommandWithStateUpdate(result, toolCallId) {
|
|
4670
|
+
function returnCommandWithStateUpdate(result, toolCallId, checkpointNs) {
|
|
4567
4671
|
const stateUpdate = filterStateForSubagent(result);
|
|
4568
4672
|
let content;
|
|
4569
4673
|
const refusal = refusalIn(result.messages?.at(-1));
|
|
@@ -4587,10 +4691,66 @@ function returnCommandWithStateUpdate(result, toolCallId) {
|
|
|
4587
4691
|
messages: [new langchain.ToolMessage({
|
|
4588
4692
|
content,
|
|
4589
4693
|
tool_call_id: toolCallId,
|
|
4590
|
-
name: "task"
|
|
4694
|
+
name: "task",
|
|
4695
|
+
...checkpointNs ? { artifact: { checkpoint_ns: checkpointNs } } : {}
|
|
4591
4696
|
})]
|
|
4592
4697
|
} });
|
|
4593
4698
|
}
|
|
4699
|
+
function isCompiledGraph(value) {
|
|
4700
|
+
return typeof value === "object" && value !== null && "lg_is_pregel" in value && value.lg_is_pregel === true;
|
|
4701
|
+
}
|
|
4702
|
+
/**
|
|
4703
|
+
* Whether `value` is a plain `RunnableBinding`, such as `withListeners`
|
|
4704
|
+
* returns, and not a subclass. A subclass can override `invoke` with behaviour
|
|
4705
|
+
* that streaming its inner graph would skip, such as the `RunnableRetry` from
|
|
4706
|
+
* `withRetry`.
|
|
4707
|
+
*/
|
|
4708
|
+
function isPlainRunnableBinding(value) {
|
|
4709
|
+
return value?.constructor === _langchain_core_runnables.RunnableBinding;
|
|
4710
|
+
}
|
|
4711
|
+
/**
|
|
4712
|
+
* The compiled graph behind a subagent: the subagent itself, the `graph` of a
|
|
4713
|
+
* `createAgent` agent, or the graph a plain `RunnableBinding` wraps.
|
|
4714
|
+
* `undefined` for any other runnable.
|
|
4715
|
+
*/
|
|
4716
|
+
function getCompiledGraph(subagent) {
|
|
4717
|
+
const unwrapped = isPlainRunnableBinding(subagent) ? subagent.bound : subagent;
|
|
4718
|
+
if (isCompiledGraph(unwrapped)) return unwrapped;
|
|
4719
|
+
const graph = unwrapped.graph;
|
|
4720
|
+
return isCompiledGraph(graph) ? graph : void 0;
|
|
4721
|
+
}
|
|
4722
|
+
/**
|
|
4723
|
+
* Invoke a subagent, returning its final state and the namespace it
|
|
4724
|
+
* checkpointed under.
|
|
4725
|
+
*
|
|
4726
|
+
* A compiled subagent is streamed rather than invoked so its checkpoint events
|
|
4727
|
+
* report the namespace it saved under. LangGraph changes that namespace from
|
|
4728
|
+
* the `task` call's own for a second run in the same step (`<namespace>|1`)
|
|
4729
|
+
* and for `checkpointer: true` (task ids removed). No checkpoint event means
|
|
4730
|
+
* nothing was saved. Any other runnable is invoked and assumed to save under
|
|
4731
|
+
* the `task` call's namespace.
|
|
4732
|
+
*/
|
|
4733
|
+
async function runSubagent(subagent, state, config) {
|
|
4734
|
+
const graph = getCompiledGraph(subagent);
|
|
4735
|
+
if (graph === void 0) return {
|
|
4736
|
+
result: await subagent.invoke(state, config),
|
|
4737
|
+
checkpointNs: config.configurable?.checkpoint_ns
|
|
4738
|
+
};
|
|
4739
|
+
let result = {};
|
|
4740
|
+
let checkpointNs;
|
|
4741
|
+
const options = {
|
|
4742
|
+
...config,
|
|
4743
|
+
streamMode: ["values", "checkpoints"],
|
|
4744
|
+
outputKeys: graph.outputChannels
|
|
4745
|
+
};
|
|
4746
|
+
const stream = await subagent.stream(state, options);
|
|
4747
|
+
for await (const [mode, chunk] of stream) if (mode === "values") result = chunk;
|
|
4748
|
+
else checkpointNs ??= chunk.config.configurable?.checkpoint_ns;
|
|
4749
|
+
return {
|
|
4750
|
+
result,
|
|
4751
|
+
checkpointNs
|
|
4752
|
+
};
|
|
4753
|
+
}
|
|
4594
4754
|
/** Drop the trailing in-flight AIMessage with unresolved tool_calls. */
|
|
4595
4755
|
function stripInFlightAIMessage(messages) {
|
|
4596
4756
|
const last = messages.at(-1);
|
|
@@ -4778,8 +4938,9 @@ function createTaskTool(options) {
|
|
|
4778
4938
|
}
|
|
4779
4939
|
};
|
|
4780
4940
|
let result;
|
|
4941
|
+
let checkpointNs;
|
|
4781
4942
|
try {
|
|
4782
|
-
result = await subagent
|
|
4943
|
+
({result, checkpointNs} = await runSubagent(subagent, subagentState, subagentConfig));
|
|
4783
4944
|
} catch (error) {
|
|
4784
4945
|
const notice = refusalNoticeFor(error);
|
|
4785
4946
|
if (notice === void 0) throw error;
|
|
@@ -4799,7 +4960,7 @@ function createTaskTool(options) {
|
|
|
4799
4960
|
}
|
|
4800
4961
|
return content;
|
|
4801
4962
|
}
|
|
4802
|
-
return returnCommandWithStateUpdate(result, config.toolCall.id);
|
|
4963
|
+
return returnCommandWithStateUpdate(result, config.toolCall.id, checkpointNs);
|
|
4803
4964
|
}
|
|
4804
4965
|
const taskToolSchema = zod_v4.z.object({
|
|
4805
4966
|
description: zod_v4.z.string().describe("The task to execute with the selected agent"),
|
|
@@ -4990,6 +5151,45 @@ function createPatchToolCallsMiddleware() {
|
|
|
4990
5151
|
* This module provides pre-configured ReducedValue instances that can be
|
|
4991
5152
|
* reused across different state schemas, similar to LangGraph's messagesValue.
|
|
4992
5153
|
*/
|
|
5154
|
+
const deltaFields = { messages: new _langchain_langgraph.DeltaValue(_langchain_langgraph.MessagesDeltaValue.valueSchema, {
|
|
5155
|
+
inputSchema: _langchain_langgraph.MessagesDeltaValue.inputSchema,
|
|
5156
|
+
reducer: _langchain_langgraph.MessagesDeltaValue.reducer,
|
|
5157
|
+
snapshotFrequency: 50,
|
|
5158
|
+
jsonSchemaExtra: _langchain_langgraph.MessagesDeltaValue.jsonSchemaExtra
|
|
5159
|
+
}) };
|
|
5160
|
+
const defaultStateSchema = new _langchain_langgraph.StateSchema(deltaFields);
|
|
5161
|
+
/**
|
|
5162
|
+
* The state schema of a deep agent or subagent: the caller's fields, plus the
|
|
5163
|
+
* delta channels for every key the caller leaves out.
|
|
5164
|
+
*
|
|
5165
|
+
* A zod schema is copied field by field the way LangChain's `createAgent` reads
|
|
5166
|
+
* one, keeping reducers registered on zod v4 fields, because a StateSchema
|
|
5167
|
+
* cannot hold a zod object. Anything else `createAgent` ignores, so it is
|
|
5168
|
+
* ignored here too. This follows `createAgentState` in langchain 1.6.0
|
|
5169
|
+
* (`dist/agents/annotation.js`); recheck it when langchain changes how it
|
|
5170
|
+
* reads a state schema.
|
|
5171
|
+
*/
|
|
5172
|
+
function deepAgentStateSchema(stateSchema) {
|
|
5173
|
+
if (_langchain_langgraph.StateSchema.isInstance(stateSchema)) return new _langchain_langgraph.StateSchema({
|
|
5174
|
+
...deltaFields,
|
|
5175
|
+
...stateSchema.fields
|
|
5176
|
+
});
|
|
5177
|
+
if (!(0, _langchain_core_utils_types.isInteropZodObject)(stateSchema)) return defaultStateSchema;
|
|
5178
|
+
const fields = {};
|
|
5179
|
+
for (const [key, field] of Object.entries((0, _langchain_core_utils_types.getInteropZodObjectShape)(stateSchema))) {
|
|
5180
|
+
const reducer = (0, _langchain_core_utils_types.isZodSchemaV4)(field) ? _langchain_langgraph_zod.schemaMetaRegistry.get(field)?.reducer : void 0;
|
|
5181
|
+
if (reducer === void 0) fields[key] = field;
|
|
5182
|
+
else if (reducer.schema === void 0) fields[key] = new _langchain_langgraph.ReducedValue(field, { reducer: reducer.fn });
|
|
5183
|
+
else fields[key] = new _langchain_langgraph.ReducedValue(field, {
|
|
5184
|
+
inputSchema: reducer.schema,
|
|
5185
|
+
reducer: reducer.fn
|
|
5186
|
+
});
|
|
5187
|
+
}
|
|
5188
|
+
return new _langchain_langgraph.StateSchema({
|
|
5189
|
+
...deltaFields,
|
|
5190
|
+
...fields
|
|
5191
|
+
});
|
|
5192
|
+
}
|
|
4993
5193
|
/**
|
|
4994
5194
|
* Shared ReducedValue for file data state management.
|
|
4995
5195
|
*
|
|
@@ -7079,24 +7279,45 @@ function describeAsyncSubAgent(spec) {
|
|
|
7079
7279
|
return `- ${spec.name}: ${spec.description}${suffix}`;
|
|
7080
7280
|
}
|
|
7081
7281
|
/**
|
|
7282
|
+
* Streaming for the runs this middleware starts on this deployment.
|
|
7283
|
+
*
|
|
7284
|
+
* An app that shows a subagent's thread, or the parent's thread after a
|
|
7285
|
+
* notification, joins runs it didn't start, and a join gets only what the run
|
|
7286
|
+
* streams. Like an app's own runs, these stream tokens and subgraphs, and keep
|
|
7287
|
+
* their events for a late join.
|
|
7288
|
+
*/
|
|
7289
|
+
const STREAM_OPTIONS = {
|
|
7290
|
+
streamMode: [
|
|
7291
|
+
"values",
|
|
7292
|
+
"updates",
|
|
7293
|
+
"messages-tuple",
|
|
7294
|
+
"custom"
|
|
7295
|
+
],
|
|
7296
|
+
streamSubgraphs: true,
|
|
7297
|
+
streamResumable: true
|
|
7298
|
+
};
|
|
7299
|
+
/**
|
|
7082
7300
|
* The `runs.create` options that link a run to this agent and set the subagent's webhook.
|
|
7083
7301
|
*
|
|
7084
|
-
* A subagent on this deployment runs with this agent's context
|
|
7085
|
-
* takes `context` or `configurable`, not both,
|
|
7086
|
-
* through the thread's metadata.
|
|
7302
|
+
* A subagent on this deployment runs with this agent's context, and streams with
|
|
7303
|
+
* `STREAM_OPTIONS`. The Agent Server takes `context` or `configurable`, not both,
|
|
7304
|
+
* so the parent reference then goes through the thread's metadata.
|
|
7087
7305
|
*/
|
|
7088
7306
|
function runOptions(spec, runtime) {
|
|
7089
|
-
const
|
|
7307
|
+
const options = {
|
|
7308
|
+
...spec.url ? {} : STREAM_OPTIONS,
|
|
7309
|
+
...spec.webhook ? { webhook: spec.webhook } : {}
|
|
7310
|
+
};
|
|
7090
7311
|
const context = spec.url ? void 0 : forwardedContext(runtime.context);
|
|
7091
7312
|
if (context) return {
|
|
7092
|
-
...
|
|
7313
|
+
...options,
|
|
7093
7314
|
context
|
|
7094
7315
|
};
|
|
7095
7316
|
const reference = referenceFor(spec, runtime.config);
|
|
7096
7317
|
return Object.keys(reference).length > 0 ? {
|
|
7097
|
-
...
|
|
7318
|
+
...options,
|
|
7098
7319
|
config: { configurable: { [PARENT_KEY]: reference } }
|
|
7099
|
-
} :
|
|
7320
|
+
} : options;
|
|
7100
7321
|
}
|
|
7101
7322
|
/** A run context as JSON data for another run, without deepagents' parent reference. */
|
|
7102
7323
|
function forwardedContext(context) {
|
|
@@ -7298,6 +7519,7 @@ async function awakeParent(parentThreadId, assistantId, update, context) {
|
|
|
7298
7519
|
await client.runs.create(parentThreadId, assistantId, {
|
|
7299
7520
|
input: { messages: [notificationMessage(update)] },
|
|
7300
7521
|
multitaskStrategy: "reject",
|
|
7522
|
+
...STREAM_OPTIONS,
|
|
7301
7523
|
...context ? { context } : {}
|
|
7302
7524
|
});
|
|
7303
7525
|
} catch {}
|
|
@@ -8811,7 +9033,7 @@ function createDeepAgent(params = {}) {
|
|
|
8811
9033
|
return (0, langchain.createAgent)({
|
|
8812
9034
|
model,
|
|
8813
9035
|
...finalSystemPrompt !== "" && { systemPrompt: finalSystemPrompt },
|
|
8814
|
-
stateSchema,
|
|
9036
|
+
stateSchema: deepAgentStateSchema(stateSchema),
|
|
8815
9037
|
tools: effectiveTools,
|
|
8816
9038
|
middleware,
|
|
8817
9039
|
...responseFormat !== null && { responseFormat },
|
|
@@ -11272,6 +11494,12 @@ Object.defineProperty(exports, "serializeProfile", {
|
|
|
11272
11494
|
return serializeProfile;
|
|
11273
11495
|
}
|
|
11274
11496
|
});
|
|
11497
|
+
Object.defineProperty(exports, "setPin", {
|
|
11498
|
+
enumerable: true,
|
|
11499
|
+
get: function() {
|
|
11500
|
+
return setPin;
|
|
11501
|
+
}
|
|
11502
|
+
});
|
|
11275
11503
|
Object.defineProperty(exports, "setRealpath", {
|
|
11276
11504
|
enumerable: true,
|
|
11277
11505
|
get: function() {
|
|
@@ -11285,4 +11513,4 @@ Object.defineProperty(exports, "skillsMetadataValue", {
|
|
|
11285
11513
|
}
|
|
11286
11514
|
});
|
|
11287
11515
|
|
|
11288
|
-
//# sourceMappingURL=langsmith-
|
|
11516
|
+
//# sourceMappingURL=langsmith-Fjf2fY1X.cjs.map
|