deepagents 1.16.3 → 1.16.5

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.
@@ -28,12 +28,12 @@ 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");
34
35
  let yaml = require("yaml");
35
36
  yaml = __toESM(yaml, 1);
36
- let _langchain_core_runnables = require("@langchain/core/runnables");
37
37
  let _langchain_core_tools = require("@langchain/core/tools");
38
38
  let _langchain_core_language_models_base = require("@langchain/core/language_models/base");
39
39
  let _langchain_core_utils_function_calling = require("@langchain/core/utils/function_calling");
@@ -57,6 +57,20 @@ function setRealpath(target, fn) {
57
57
  configurable: true
58
58
  });
59
59
  }
60
+ // src/backends/pin.ts
61
+ const PIN = Symbol.for("deepagents.pin");
62
+ function getPin(backend) {
63
+ if (typeof backend !== "object" || backend === null) return;
64
+ const fn = backend[PIN];
65
+ return typeof fn === "function" ? fn : void 0;
66
+ }
67
+ function setPin(target, fn) {
68
+ Object.defineProperty(target, PIN, {
69
+ value: fn,
70
+ enumerable: false,
71
+ configurable: true
72
+ });
73
+ }
60
74
  // src/backends/utils.ts
61
75
  /**
62
76
  * Shared utility functions for memory backend implementations.
@@ -690,6 +704,8 @@ function adaptBackendProtocol(backend) {
690
704
  }
691
705
  const realpath = getRealpath(backend);
692
706
  if (realpath !== void 0) setRealpath(adapted, realpath);
707
+ const pin = getPin(backend);
708
+ if (pin !== void 0) setPin(adapted, pin);
693
709
  const resolveBackendForPath = backend.resolveBackendForPath;
694
710
  if (typeof resolveBackendForPath === "function") Object.defineProperty(adapted, "resolveBackendForPath", {
695
711
  value: (path) => resolveBackendForPath.call(backend, path),
@@ -1742,6 +1758,7 @@ var CompositeBackend = class {
1742
1758
  this.routes = Object.fromEntries(Object.entries(routes).map(([k, v]) => [k.endsWith("/") ? k : `${k}/`, isSandboxProtocol(v) ? adaptSandboxProtocol(v) : adaptBackendProtocol(v)]));
1743
1759
  this.sortedRoutes = Object.entries(this.routes).sort((a, b) => b[0].length - a[0].length);
1744
1760
  setRealpath(this, (path) => this.resolveRealPath(path));
1761
+ setPin(this, (path, options, authorize, operation) => this.runPinned(path, options, authorize, operation));
1745
1762
  }
1746
1763
  /** Delegates to default backend's id if it is a sandbox, otherwise empty string. */
1747
1764
  get id() {
@@ -1783,6 +1800,22 @@ var CompositeBackend = class {
1783
1800
  return realpath === void 0 ? path : await realpath(path);
1784
1801
  }
1785
1802
  /**
1803
+ * Pin via the backend that owns `path`, re-adding the route prefix to the
1804
+ * real path it authorizes. Runs `operation` unpinned when that backend has
1805
+ * no pin hook.
1806
+ */
1807
+ runPinned(path, options, authorize, operation) {
1808
+ for (const [routePrefix, backend] of this.sortedRoutes) if (this.isPathWithinRoute(path, routePrefix)) {
1809
+ const pin = getPin(backend);
1810
+ if (pin === void 0) return operation();
1811
+ const prefix = routePrefix.slice(0, -1);
1812
+ const suffix = path.substring(routePrefix.length);
1813
+ return pin(suffix ? "/" + suffix : "/", options, (realPath) => authorize(prefix + realPath), operation);
1814
+ }
1815
+ const pin = getPin(this.default);
1816
+ return pin === void 0 ? operation() : pin(path, options, authorize, operation);
1817
+ }
1818
+ /**
1786
1819
  * Determine which backend handles this key and strip prefix.
1787
1820
  *
1788
1821
  * @param key - Original file path
@@ -2588,11 +2621,15 @@ async function resolveRealPath(backend, canonical) {
2588
2621
  /**
2589
2622
  * Check whether `path` is permitted under `rules` for `operation`.
2590
2623
  *
2591
- * Returns the canonical path to hand the backend, or an error string to
2592
- * surface to the model. The decision covers every form of the target: the
2593
- * lexical canonical path (dot and empty segments dropped) and, when the
2594
- * backend has a realpath hook, the symlink-resolved path it would actually
2595
- * touch. A deny on either blocks the call.
2624
+ * Returns the canonical path, the `target` to hand the backend for a
2625
+ * single-file operation, or an error string to surface to the model. The
2626
+ * decision covers every form of the target: the lexical canonical path (dot
2627
+ * and empty segments dropped) and, when the backend has a realpath hook, the
2628
+ * symlink-resolved path it would actually touch. A deny on either blocks the
2629
+ * call.
2630
+ *
2631
+ * `target` is the path with its parent resolved once and checked, so a
2632
+ * symlink swapped after the check cannot redirect the operation.
2596
2633
  *
2597
2634
  * Never throws: an invalid path (non-absolute, or containing `..` or `~`), one
2598
2635
  * the backend cannot resolve, or a denied one is a recoverable tool error, not
@@ -2601,18 +2638,64 @@ async function resolveRealPath(backend, canonical) {
2601
2638
  * @internal
2602
2639
  */
2603
2640
  async function checkPermission(backend, rules, operation, path) {
2604
- if (rules.length === 0) return { path };
2641
+ if (rules.length === 0) return {
2642
+ path,
2643
+ target: path
2644
+ };
2605
2645
  let canonical;
2646
+ let target;
2606
2647
  let real;
2607
2648
  try {
2608
2649
  canonical = validatePath(path);
2609
2650
  if (decidePathAccess(rules, operation, canonical) === "deny") return { error: `Error: permission denied for ${operation} on ${canonical}` };
2610
- real = await resolveRealPath(backend, canonical);
2651
+ target = await resolveParentRealPath(backend, canonical);
2652
+ real = await resolveRealPath(backend, target);
2611
2653
  } catch (error) {
2612
2654
  return { error: `Error: ${getErrorMessage$1(error)}` };
2613
2655
  }
2656
+ if (crossesRoute(backend, canonical, target)) return { error: `Error: ${canonical} resolves to ${target}, which is served by a different backend` };
2614
2657
  if (real !== canonical && decidePathAccess(rules, operation, real) === "deny") return { error: `Error: permission denied for ${operation} on ${canonical} (resolves to ${real})` };
2615
- return { path: canonical };
2658
+ return {
2659
+ path: canonical,
2660
+ target
2661
+ };
2662
+ }
2663
+ /**
2664
+ * Run a single-path `operation` on `target` through the backend's pin hook when
2665
+ * rules are configured and the backend has one, so the final decision is made
2666
+ * on the directory the operation actually uses. `isDenied` receives the real
2667
+ * path. Without a hook, `operation` runs on the path `checkPermission` resolved.
2668
+ *
2669
+ * Errors raised here, rather than by `operation`, start with `errorPrefix` so
2670
+ * they match how the calling tool formats backend errors.
2671
+ */
2672
+ async function runBoundToTarget(backend, rules, target, options, isDenied, operation) {
2673
+ const pin = rules.length > 0 ? getPin(backend) : void 0;
2674
+ if (pin === void 0) return operation();
2675
+ const { create, describe, errorPrefix } = options;
2676
+ let operationStarted = false;
2677
+ try {
2678
+ return await pin(target, { create }, (realPath) => {
2679
+ const real = validatePath(realPath);
2680
+ return isDenied(real) ? `${errorPrefix}permission denied for ${describe} (resolves to ${real})` : void 0;
2681
+ }, () => {
2682
+ operationStarted = true;
2683
+ return operation();
2684
+ });
2685
+ } catch (error) {
2686
+ if (operationStarted) throw error;
2687
+ return { error: `${errorPrefix}${describe} failed: ${getErrorMessage$1(error)}` };
2688
+ }
2689
+ }
2690
+ /**
2691
+ * Whether `target` is served by a different `CompositeBackend` route than
2692
+ * `requested`. Symlink resolution must not move an operation to another
2693
+ * backend.
2694
+ */
2695
+ function crossesRoute(backend, requested, target) {
2696
+ const resolveBackendForPath = backend.resolveBackendForPath;
2697
+ if (typeof resolveBackendForPath !== "function" || requested === target) return false;
2698
+ return resolveBackendForPath.call(backend, requested)[0] !== resolveBackendForPath.call(backend, target)[0];
2616
2699
  }
2617
2700
  /**
2618
2701
  * Build an error {@link ToolMessage} for a denied path or a failed backend
@@ -2786,10 +2869,11 @@ function parentPath(path) {
2786
2869
  return `/${parts.slice(0, -1).join("/")}`;
2787
2870
  }
2788
2871
  /**
2789
- * Resolve the path a delete of `target` would actually remove. Backends unlink
2790
- * a symlink leaf rather than following it, so only the parent is resolved.
2872
+ * Resolve symlinks in the parent of `target`, keeping its leaf as given.
2873
+ * Backends refuse to follow (or, for delete, unlink) a symlinked leaf, so this
2874
+ * is the path a single-file operation actually touches.
2791
2875
  */
2792
- async function resolveDeleteRealPath(backend, target) {
2876
+ async function resolveParentRealPath(backend, target) {
2793
2877
  const parts = posixParts(target);
2794
2878
  if (parts.length === 0) return resolveRealPath(backend, target);
2795
2879
  return validatePath(`${await resolveRealPath(backend, parentPath(target))}/${parts[parts.length - 1]}`);
@@ -2956,7 +3040,11 @@ function createReadFileTool(backend, options) {
2956
3040
  if (permission.error !== void 0) return toolError(runtime, "read_file", permission.error);
2957
3041
  const { file_path, offset: requestedOffset = 0, limit: requestedLimit = 100 } = input;
2958
3042
  const { offset, limit } = normalizeReadPagination(requestedOffset, requestedLimit);
2959
- const readResult = await resolvedBackend.read(permission.path, offset, limit);
3043
+ const readResult = await runBoundToTarget(resolvedBackend, permissions, permission.target, {
3044
+ create: false,
3045
+ describe: `read on ${permission.path}`,
3046
+ errorPrefix: ""
3047
+ }, (real) => decidePathAccess(permissions, "read", real) === "deny", async () => resolvedBackend.read(permission.target, offset, limit));
2960
3048
  if (readResult.error) return toolError(runtime, "read_file", `Error: ${readResult.error}`);
2961
3049
  const mimeType = readResult.mimeType ?? getMimeType(file_path);
2962
3050
  if (!isTextMimeType(mimeType)) {
@@ -3040,7 +3128,11 @@ function createWriteFileTool(backend, options) {
3040
3128
  const permission = await checkPermission(resolvedBackend, permissions, "write", input.file_path);
3041
3129
  if (permission.error !== void 0) return toolError(runtime, "write_file", permission.error);
3042
3130
  const { file_path, content } = input;
3043
- const result = await resolvedBackend.write(permission.path, content);
3131
+ const result = await runBoundToTarget(resolvedBackend, permissions, permission.target, {
3132
+ create: true,
3133
+ describe: `write on ${permission.path}`,
3134
+ errorPrefix: "Error: "
3135
+ }, (real) => decidePathAccess(permissions, "write", real) === "deny", async () => resolvedBackend.write(permission.target, content));
3044
3136
  if (result.error) return toolError(runtime, "write_file", result.error);
3045
3137
  const message = new langchain.ToolMessage({
3046
3138
  content: `Successfully wrote to '${file_path}'`,
@@ -3072,7 +3164,11 @@ function createEditFileTool(backend, options) {
3072
3164
  const permission = await checkPermission(resolvedBackend, permissions, "write", input.file_path);
3073
3165
  if (permission.error !== void 0) return toolError(runtime, "edit_file", permission.error);
3074
3166
  const { file_path, old_string, new_string, replace_all = false } = input;
3075
- const result = await resolvedBackend.edit(permission.path, old_string, new_string, replace_all);
3167
+ const result = await runBoundToTarget(resolvedBackend, permissions, permission.target, {
3168
+ create: false,
3169
+ describe: `write on ${permission.path}`,
3170
+ errorPrefix: "Error: "
3171
+ }, (real) => decidePathAccess(permissions, "write", real) === "deny", async () => resolvedBackend.edit(permission.target, old_string, new_string, replace_all));
3076
3172
  if (result.error) return toolError(runtime, "edit_file", result.error);
3077
3173
  const message = new langchain.ToolMessage({
3078
3174
  content: `Successfully replaced ${result.occurrences} occurrence(s) in '${file_path}'`,
@@ -3112,22 +3208,29 @@ function createDeleteTool(backend, options) {
3112
3208
  const hasDescendants = await deleteTargetMayHaveDescendants(resolvedBackend, validatedPath, permissions.length > 0);
3113
3209
  const denyingPatterns = findDeleteDenyPatterns(permissions, validatedPath, hasDescendants);
3114
3210
  if (denyingPatterns.length > 0) return toolError(runtime, "delete", `Error: permission denied for write on ${validatedPath} (matches deny rule(s): ${denyingPatterns.join(", ")})`);
3211
+ let deleteTarget = validatedPath;
3115
3212
  if (permissions.length > 0) {
3116
3213
  let realTarget;
3117
3214
  try {
3118
- realTarget = await resolveDeleteRealPath(resolvedBackend, validatedPath);
3215
+ realTarget = await resolveParentRealPath(resolvedBackend, validatedPath);
3119
3216
  } catch (error) {
3120
3217
  return toolError(runtime, "delete", `Error: ${getErrorMessage$1(error)}`);
3121
3218
  }
3219
+ if (crossesRoute(resolvedBackend, validatedPath, realTarget)) return toolError(runtime, "delete", `Error: ${validatedPath} resolves to ${realTarget}, which is served by a different backend`);
3122
3220
  if (realTarget !== validatedPath) {
3123
3221
  if (findDeleteDenyPatterns(permissions, realTarget, hasDescendants).length > 0) return toolError(runtime, "delete", `Error: permission denied for write on ${validatedPath} (resolves to ${realTarget})`);
3124
3222
  }
3223
+ deleteTarget = realTarget;
3125
3224
  }
3126
3225
  if (!supportsDelete(resolvedBackend)) return toolError(runtime, "delete", `Error: deletion is not available for '${validatedPath}'.`);
3127
- const result = await resolvedBackend.delete(validatedPath);
3226
+ const result = await runBoundToTarget(resolvedBackend, permissions, deleteTarget, {
3227
+ create: false,
3228
+ describe: `write on ${validatedPath}`,
3229
+ errorPrefix: "Error: "
3230
+ }, (real) => findDeleteDenyPatterns(permissions, real, hasDescendants).length > 0, async () => resolvedBackend.delete(deleteTarget));
3128
3231
  if (result.error) return toolError(runtime, "delete", result.error);
3129
3232
  const message = new langchain.ToolMessage({
3130
- content: `Deleted ${result.path ?? validatedPath}`,
3233
+ content: `Deleted ${result.path === void 0 || result.path === deleteTarget ? validatedPath : result.path}`,
3131
3234
  tool_call_id: runtime.toolCall?.id,
3132
3235
  name: "delete",
3133
3236
  metadata: result.metadata
@@ -3563,6 +3666,54 @@ function createFilesystemMiddleware(options = {}) {
3563
3666
  }
3564
3667
  });
3565
3668
  }
3669
+ // src/middleware/refusal.ts
3670
+ /**
3671
+ * The task result reported when a model in the subagent refused.
3672
+ *
3673
+ * @param refusal - The refusal block from the model's reply.
3674
+ */
3675
+ function refusalNotice(refusal) {
3676
+ let notice = "The subagent stopped because a model refused the request.";
3677
+ const category = refusal.extras?.category;
3678
+ if (category) notice += ` Category: ${String(category)}.`;
3679
+ if (refusal.refusal) notice += ` Explanation: "${refusal.refusal}"`;
3680
+ return `${notice} Retrying the same request is unlikely to succeed; rephrase it or continue without it.`;
3681
+ }
3682
+ /**
3683
+ * The refusal block in `message`, if it is a message that refused.
3684
+ *
3685
+ * @param message - The message to check. Callers often take it from an
3686
+ * unchecked cast, so non-messages are treated as no refusal.
3687
+ */
3688
+ function refusalIn(message) {
3689
+ if (!_langchain_core_messages.BaseMessage.isInstance(message)) return void 0;
3690
+ try {
3691
+ return message.contentBlocks.find((block) => block.type === "refusal");
3692
+ } catch {
3693
+ return;
3694
+ }
3695
+ }
3696
+ /**
3697
+ * The task result for an error caused by a refusal, or `undefined` to rethrow it.
3698
+ *
3699
+ * Middleware wraps errors in `MiddlewareError`, so this walks the `cause` chain.
3700
+ *
3701
+ * @param error - The error the subagent run threw.
3702
+ */
3703
+ function refusalNoticeFor(error) {
3704
+ let current = error;
3705
+ while (current) {
3706
+ if (_langchain_core_errors.ModelRefusalError.isInstance(current)) return refusalNotice(refusalIn(current.rawMessage) ?? {
3707
+ type: "refusal",
3708
+ refusal: current.message
3709
+ });
3710
+ if (typeof current === "object" && "aiMessage" in current) {
3711
+ const refusal = refusalIn(current.aiMessage);
3712
+ if (refusal) return refusalNotice(refusal);
3713
+ }
3714
+ current = typeof current === "object" && "cause" in current ? current.cause : void 0;
3715
+ }
3716
+ }
3566
3717
  // src/middleware/summarization.ts
3567
3718
  /**
3568
3719
  * Summarization middleware with backend support for conversation history offloading.
@@ -4515,10 +4666,12 @@ const INVALID_TOOL_MESSAGE_BLOCK_TYPES = [
4515
4666
  /**
4516
4667
  * Create Command with filtered state update from subagent result
4517
4668
  */
4518
- function returnCommandWithStateUpdate(result, toolCallId) {
4669
+ function returnCommandWithStateUpdate(result, toolCallId, checkpointNs) {
4519
4670
  const stateUpdate = filterStateForSubagent(result);
4520
4671
  let content;
4672
+ const refusal = refusalIn(result.messages?.at(-1));
4521
4673
  if (result.structuredResponse != null) content = JSON.stringify(result.structuredResponse);
4674
+ else if (refusal) content = refusalNotice(refusal);
4522
4675
  else {
4523
4676
  const messages = result.messages ?? [];
4524
4677
  content = "Task completed";
@@ -4537,10 +4690,66 @@ function returnCommandWithStateUpdate(result, toolCallId) {
4537
4690
  messages: [new langchain.ToolMessage({
4538
4691
  content,
4539
4692
  tool_call_id: toolCallId,
4540
- name: "task"
4693
+ name: "task",
4694
+ ...checkpointNs ? { artifact: { checkpoint_ns: checkpointNs } } : {}
4541
4695
  })]
4542
4696
  } });
4543
4697
  }
4698
+ function isCompiledGraph(value) {
4699
+ return typeof value === "object" && value !== null && "lg_is_pregel" in value && value.lg_is_pregel === true;
4700
+ }
4701
+ /**
4702
+ * Whether `value` is a plain `RunnableBinding`, such as `withListeners`
4703
+ * returns, and not a subclass. A subclass can override `invoke` with behaviour
4704
+ * that streaming its inner graph would skip, such as the `RunnableRetry` from
4705
+ * `withRetry`.
4706
+ */
4707
+ function isPlainRunnableBinding(value) {
4708
+ return value?.constructor === _langchain_core_runnables.RunnableBinding;
4709
+ }
4710
+ /**
4711
+ * The compiled graph behind a subagent: the subagent itself, the `graph` of a
4712
+ * `createAgent` agent, or the graph a plain `RunnableBinding` wraps.
4713
+ * `undefined` for any other runnable.
4714
+ */
4715
+ function getCompiledGraph(subagent) {
4716
+ const unwrapped = isPlainRunnableBinding(subagent) ? subagent.bound : subagent;
4717
+ if (isCompiledGraph(unwrapped)) return unwrapped;
4718
+ const graph = unwrapped.graph;
4719
+ return isCompiledGraph(graph) ? graph : void 0;
4720
+ }
4721
+ /**
4722
+ * Invoke a subagent, returning its final state and the namespace it
4723
+ * checkpointed under.
4724
+ *
4725
+ * A compiled subagent is streamed rather than invoked so its checkpoint events
4726
+ * report the namespace it saved under. LangGraph changes that namespace from
4727
+ * the `task` call's own for a second run in the same step (`<namespace>|1`)
4728
+ * and for `checkpointer: true` (task ids removed). No checkpoint event means
4729
+ * nothing was saved. Any other runnable is invoked and assumed to save under
4730
+ * the `task` call's namespace.
4731
+ */
4732
+ async function runSubagent(subagent, state, config) {
4733
+ const graph = getCompiledGraph(subagent);
4734
+ if (graph === void 0) return {
4735
+ result: await subagent.invoke(state, config),
4736
+ checkpointNs: config.configurable?.checkpoint_ns
4737
+ };
4738
+ let result = {};
4739
+ let checkpointNs;
4740
+ const options = {
4741
+ ...config,
4742
+ streamMode: ["values", "checkpoints"],
4743
+ outputKeys: graph.outputChannels
4744
+ };
4745
+ const stream = await subagent.stream(state, options);
4746
+ for await (const [mode, chunk] of stream) if (mode === "values") result = chunk;
4747
+ else checkpointNs ??= chunk.config.configurable?.checkpoint_ns;
4748
+ return {
4749
+ result,
4750
+ checkpointNs
4751
+ };
4752
+ }
4544
4753
  /** Drop the trailing in-flight AIMessage with unresolved tool_calls. */
4545
4754
  function stripInFlightAIMessage(messages) {
4546
4755
  const last = messages.at(-1);
@@ -4719,18 +4928,30 @@ function createTaskTool(options) {
4719
4928
  ...config,
4720
4929
  metadata: {
4721
4930
  ...config.metadata,
4722
- lc_agent_name: subagent_type
4931
+ lc_agent_name: subagent_type,
4932
+ ...config.toolCall?.id && { lc_subagent_tool_call_id: config.toolCall.id }
4723
4933
  },
4724
4934
  configurable: {
4725
4935
  ...config.configurable,
4726
4936
  ls_agent_type: "subagent"
4727
4937
  }
4728
4938
  };
4729
- const result = await subagent.invoke(subagentState, subagentConfig);
4939
+ let result;
4940
+ let checkpointNs;
4941
+ try {
4942
+ ({result, checkpointNs} = await runSubagent(subagent, subagentState, subagentConfig));
4943
+ } catch (error) {
4944
+ const notice = refusalNoticeFor(error);
4945
+ if (notice === void 0) throw error;
4946
+ return notice;
4947
+ }
4730
4948
  if (!config.toolCall?.id) {
4731
4949
  if (result.structuredResponse != null) return JSON.stringify(result.structuredResponse);
4732
4950
  const messages = result.messages;
4733
- let content = (messages?.[messages.length - 1])?.content || "Task completed";
4951
+ const lastMessage = messages?.[messages.length - 1];
4952
+ const refusal = refusalIn(lastMessage);
4953
+ if (refusal) return refusalNotice(refusal);
4954
+ let content = lastMessage?.content || "Task completed";
4734
4955
  if (Array.isArray(content)) {
4735
4956
  content = content.filter((block) => !INVALID_TOOL_MESSAGE_BLOCK_TYPES.includes(block.type));
4736
4957
  if (content.length === 0) return "Task completed";
@@ -4738,7 +4959,7 @@ function createTaskTool(options) {
4738
4959
  }
4739
4960
  return content;
4740
4961
  }
4741
- return returnCommandWithStateUpdate(result, config.toolCall.id);
4962
+ return returnCommandWithStateUpdate(result, config.toolCall.id, checkpointNs);
4742
4963
  }
4743
4964
  const taskToolSchema = zod_v4.z.object({
4744
4965
  description: zod_v4.z.string().describe("The task to execute with the selected agent"),
@@ -7178,7 +7399,13 @@ function finalContent(values) {
7178
7399
  }];
7179
7400
  const last = messages[messages.length - 1];
7180
7401
  try {
7181
- return (0, _langchain_core_messages.coerceMessageLikeToMessage)(last).contentBlocks;
7402
+ const message = (0, _langchain_core_messages.coerceMessageLikeToMessage)(last);
7403
+ const refusal = refusalIn(message);
7404
+ if (refusal) return [{
7405
+ type: "text",
7406
+ text: refusalNotice(refusal)
7407
+ }];
7408
+ return message.contentBlocks;
7182
7409
  } catch {
7183
7410
  return [{
7184
7411
  type: "text",
@@ -8664,7 +8891,8 @@ function createDeepAgent(params = {}) {
8664
8891
  backend,
8665
8892
  sources: memory,
8666
8893
  addCacheControl: anthropicModel
8667
- })] : []
8894
+ })] : [],
8895
+ (0, langchain.modelRefusalMiddleware)()
8668
8896
  ]);
8669
8897
  if (subagentProfile.excludedMiddleware.size > 0) subagentMiddleware = subagentMiddleware.filter((middleware) => !subagentProfile.excludedMiddleware.has(middleware.name));
8670
8898
  if (subagentProfile.excludedTools.size > 0) subagentMiddleware.push(createToolExclusionMiddleware(subagentProfile.excludedTools));
@@ -8721,7 +8949,8 @@ function createDeepAgent(params = {}) {
8721
8949
  ...skillsMiddleware,
8722
8950
  ...cacheMiddleware,
8723
8951
  ...memoryMiddleware,
8724
- ...interruptOn ? [(0, langchain.humanInTheLoopMiddleware)({ interruptOn })] : []
8952
+ ...interruptOn ? [(0, langchain.humanInTheLoopMiddleware)({ interruptOn })] : [],
8953
+ (0, langchain.modelRefusalMiddleware)()
8725
8954
  ]);
8726
8955
  if (harnessProfile.excludedMiddleware.size > 0) {
8727
8956
  const excluded = harnessProfile.excludedMiddleware;
@@ -11203,6 +11432,12 @@ Object.defineProperty(exports, "serializeProfile", {
11203
11432
  return serializeProfile;
11204
11433
  }
11205
11434
  });
11435
+ Object.defineProperty(exports, "setPin", {
11436
+ enumerable: true,
11437
+ get: function() {
11438
+ return setPin;
11439
+ }
11440
+ });
11206
11441
  Object.defineProperty(exports, "setRealpath", {
11207
11442
  enumerable: true,
11208
11443
  get: function() {
@@ -11216,4 +11451,4 @@ Object.defineProperty(exports, "skillsMetadataValue", {
11216
11451
  }
11217
11452
  });
11218
11453
 
11219
- //# sourceMappingURL=langsmith-CAjAu64d.cjs.map
11454
+ //# sourceMappingURL=langsmith-CR3a2-Z7.cjs.map