@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.
Files changed (128) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/LICENSE.md +201 -0
  3. package/README.md +149 -0
  4. package/dist/agent.d.ts +53 -0
  5. package/dist/agent.d.ts.map +1 -0
  6. package/dist/agent.js +508 -0
  7. package/dist/agent.js.map +1 -0
  8. package/dist/backends/tool_sandbox.d.ts +15 -0
  9. package/dist/backends/tool_sandbox.d.ts.map +1 -0
  10. package/dist/backends/tool_sandbox.js +15 -0
  11. package/dist/backends/tool_sandbox.js.map +1 -0
  12. package/dist/backends/toolpod.d.ts +68 -0
  13. package/dist/backends/toolpod.d.ts.map +1 -0
  14. package/dist/backends/toolpod.js +451 -0
  15. package/dist/backends/toolpod.js.map +1 -0
  16. package/dist/call_interrupt.d.ts +20 -0
  17. package/dist/call_interrupt.d.ts.map +1 -0
  18. package/dist/call_interrupt.js +23 -0
  19. package/dist/call_interrupt.js.map +1 -0
  20. package/dist/checkpoint_branch.d.ts +58 -0
  21. package/dist/checkpoint_branch.d.ts.map +1 -0
  22. package/dist/checkpoint_branch.js +239 -0
  23. package/dist/checkpoint_branch.js.map +1 -0
  24. package/dist/checkpointer.d.ts +21 -0
  25. package/dist/checkpointer.d.ts.map +1 -0
  26. package/dist/checkpointer.js +31 -0
  27. package/dist/checkpointer.js.map +1 -0
  28. package/dist/deep_agent.d.ts +49 -0
  29. package/dist/deep_agent.d.ts.map +1 -0
  30. package/dist/deep_agent.js +110 -0
  31. package/dist/deep_agent.js.map +1 -0
  32. package/dist/deep_agent_checkpointer.d.ts +11 -0
  33. package/dist/deep_agent_checkpointer.d.ts.map +1 -0
  34. package/dist/deep_agent_checkpointer.js +19 -0
  35. package/dist/deep_agent_checkpointer.js.map +1 -0
  36. package/dist/deep_agent_task.d.ts +26 -0
  37. package/dist/deep_agent_task.d.ts.map +1 -0
  38. package/dist/deep_agent_task.js +49 -0
  39. package/dist/deep_agent_task.js.map +1 -0
  40. package/dist/durable_deep_agent.d.ts +23 -0
  41. package/dist/durable_deep_agent.d.ts.map +1 -0
  42. package/dist/durable_deep_agent.js +176 -0
  43. package/dist/durable_deep_agent.js.map +1 -0
  44. package/dist/durable_message_identity.d.ts +5 -0
  45. package/dist/durable_message_identity.d.ts.map +1 -0
  46. package/dist/durable_message_identity.js +106 -0
  47. package/dist/durable_message_identity.js.map +1 -0
  48. package/dist/durable_session.d.ts +30 -0
  49. package/dist/durable_session.d.ts.map +1 -0
  50. package/dist/durable_session.js +400 -0
  51. package/dist/durable_session.js.map +1 -0
  52. package/dist/durable_subgraphs.d.ts +13 -0
  53. package/dist/durable_subgraphs.d.ts.map +1 -0
  54. package/dist/durable_subgraphs.js +82 -0
  55. package/dist/durable_subgraphs.js.map +1 -0
  56. package/dist/durable_tools.d.ts +12 -0
  57. package/dist/durable_tools.d.ts.map +1 -0
  58. package/dist/durable_tools.js +41 -0
  59. package/dist/durable_tools.js.map +1 -0
  60. package/dist/execution_session.d.ts +63 -0
  61. package/dist/execution_session.d.ts.map +1 -0
  62. package/dist/execution_session.js +300 -0
  63. package/dist/execution_session.js.map +1 -0
  64. package/dist/index.d.ts +19 -0
  65. package/dist/index.d.ts.map +1 -0
  66. package/dist/index.js +17 -0
  67. package/dist/index.js.map +1 -0
  68. package/dist/llm_adapter.d.ts +41 -0
  69. package/dist/llm_adapter.d.ts.map +1 -0
  70. package/dist/llm_adapter.js +177 -0
  71. package/dist/llm_adapter.js.map +1 -0
  72. package/dist/messages.d.ts +56 -0
  73. package/dist/messages.d.ts.map +1 -0
  74. package/dist/messages.js +592 -0
  75. package/dist/messages.js.map +1 -0
  76. package/dist/node_logger_adapter.d.ts +51 -0
  77. package/dist/node_logger_adapter.d.ts.map +1 -0
  78. package/dist/node_logger_adapter.js +163 -0
  79. package/dist/node_logger_adapter.js.map +1 -0
  80. package/dist/platform_checkpointer.d.ts +70 -0
  81. package/dist/platform_checkpointer.d.ts.map +1 -0
  82. package/dist/platform_checkpointer.js +252 -0
  83. package/dist/platform_checkpointer.js.map +1 -0
  84. package/dist/query.d.ts +103 -0
  85. package/dist/query.d.ts.map +1 -0
  86. package/dist/query.js +623 -0
  87. package/dist/query.js.map +1 -0
  88. package/dist/runtime.d.ts +336 -0
  89. package/dist/runtime.d.ts.map +1 -0
  90. package/dist/runtime.js +881 -0
  91. package/dist/runtime.js.map +1 -0
  92. package/dist/secure_llm.d.ts +93 -0
  93. package/dist/secure_llm.d.ts.map +1 -0
  94. package/dist/secure_llm.js +423 -0
  95. package/dist/secure_llm.js.map +1 -0
  96. package/dist/session_factory.d.ts +6 -0
  97. package/dist/session_factory.d.ts.map +1 -0
  98. package/dist/session_factory.js +29 -0
  99. package/dist/session_factory.js.map +1 -0
  100. package/dist/session_fork.d.ts +76 -0
  101. package/dist/session_fork.d.ts.map +1 -0
  102. package/dist/session_fork.js +428 -0
  103. package/dist/session_fork.js.map +1 -0
  104. package/dist/subagents.d.ts +37 -0
  105. package/dist/subagents.d.ts.map +1 -0
  106. package/dist/subagents.js +67 -0
  107. package/dist/subagents.js.map +1 -0
  108. package/dist/suspend.d.ts +27 -0
  109. package/dist/suspend.d.ts.map +1 -0
  110. package/dist/suspend.js +87 -0
  111. package/dist/suspend.js.map +1 -0
  112. package/dist/thread_id.d.ts +30 -0
  113. package/dist/thread_id.d.ts.map +1 -0
  114. package/dist/thread_id.js +69 -0
  115. package/dist/thread_id.js.map +1 -0
  116. package/dist/workflow_json.d.ts +11 -0
  117. package/dist/workflow_json.d.ts.map +1 -0
  118. package/dist/workflow_json.js +49 -0
  119. package/dist/workflow_json.js.map +1 -0
  120. package/dist/workflow_message.d.ts +11 -0
  121. package/dist/workflow_message.d.ts.map +1 -0
  122. package/dist/workflow_message.js +179 -0
  123. package/dist/workflow_message.js.map +1 -0
  124. package/dist/workflow_state.d.ts +7 -0
  125. package/dist/workflow_state.d.ts.map +1 -0
  126. package/dist/workflow_state.js +62 -0
  127. package/dist/workflow_state.js.map +1 -0
  128. package/package.json +66 -0
@@ -0,0 +1,239 @@
1
+ /** Copy a LangGraph checkpoint branch point into a new thread. */
2
+ import { BaseMessage } from "@langchain/core/messages";
3
+ import { isDeepStrictEqual } from "node:util";
4
+ export function branchPointFromMetadata(metadata) {
5
+ const value = metadata?.["langgraph_branch_point"];
6
+ if (value === undefined)
7
+ return undefined;
8
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
9
+ throw new Error("LangGraph branch point must be an object");
10
+ }
11
+ const threadId = value["thread_id"];
12
+ const checkpointId = value["checkpoint_id"];
13
+ if (typeof threadId !== "string" ||
14
+ threadId.length === 0 ||
15
+ typeof checkpointId !== "string" ||
16
+ checkpointId.length === 0) {
17
+ throw new Error("LangGraph branch point is incomplete");
18
+ }
19
+ return { threadId, checkpointId };
20
+ }
21
+ export function checkpointMetadata(checkpoint) {
22
+ if (checkpoint === undefined)
23
+ return undefined;
24
+ return {
25
+ langgraph_checkpoint: {
26
+ thread_id: checkpoint.threadId,
27
+ checkpoint_id: checkpoint.checkpointId,
28
+ },
29
+ };
30
+ }
31
+ /** Root-graph config for one checkpoint coordinate. */
32
+ function checkpointConfig(source) {
33
+ return {
34
+ configurable: {
35
+ thread_id: source.threadId,
36
+ checkpoint_ns: "",
37
+ checkpoint_id: source.checkpointId,
38
+ },
39
+ };
40
+ }
41
+ /** Root-graph coordinate, or fail closed on a subgraph namespace. */
42
+ function rootGraphCheckpoint(config) {
43
+ const configurable = config.configurable ?? {};
44
+ if ((configurable["checkpoint_ns"] ?? "") !== "") {
45
+ throw new Error("LangGraph checkpoint branching supports root graphs only");
46
+ }
47
+ const threadId = configurable["thread_id"];
48
+ const checkpointId = configurable["checkpoint_id"];
49
+ if (typeof threadId !== "string" || typeof checkpointId !== "string") {
50
+ throw new Error("LangGraph checkpoint coordinate is incomplete");
51
+ }
52
+ return {
53
+ threadId,
54
+ checkpointId,
55
+ };
56
+ }
57
+ function stateUpdates(snapshot, pendingWrites) {
58
+ return snapshot.tasks.flatMap((task) => {
59
+ if (task.error !== undefined && task.error !== null) {
60
+ throw new Error("LangGraph checkpoint branching does not support failed history");
61
+ }
62
+ if (task.state !== undefined && task.state !== null) {
63
+ throw new Error("LangGraph checkpoint branching does not support persistent subgraph history");
64
+ }
65
+ if (task.interrupts.length > 0 &&
66
+ (task.result === undefined || task.result === null)) {
67
+ const values = {};
68
+ for (const [taskId, channel, value] of pendingWrites) {
69
+ if (taskId !== task.id ||
70
+ channel.startsWith("__") ||
71
+ channel.startsWith("branch:")) {
72
+ continue;
73
+ }
74
+ if (channel in values) {
75
+ throw new Error(`Interrupted LangGraph checkpoint task wrote channel ${channel} more than once`);
76
+ }
77
+ values[channel] = value;
78
+ }
79
+ return Object.keys(values).length === 0
80
+ ? []
81
+ : [{ values, asNode: task.name }];
82
+ }
83
+ return [{ values: task.result, asNode: task.name }];
84
+ });
85
+ }
86
+ /**
87
+ * Graph values comparable after a branch copy. `bulkUpdateState` rebuilds
88
+ * messages with new LangChain ids; those must not fail a content match.
89
+ */
90
+ function stateWithoutMessageIds(value) {
91
+ if (value instanceof BaseMessage) {
92
+ const serialized = value.toDict();
93
+ const data = { ...serialized.data };
94
+ delete data.id;
95
+ return stateWithoutMessageIds({ ...serialized, data });
96
+ }
97
+ if (Array.isArray(value))
98
+ return value.map(stateWithoutMessageIds);
99
+ if (value !== null && typeof value === "object") {
100
+ return Object.fromEntries(Object.entries(value).map(([key, nested]) => [
101
+ key,
102
+ stateWithoutMessageIds(nested),
103
+ ]));
104
+ }
105
+ return value;
106
+ }
107
+ /**
108
+ * Load a completed root checkpoint, or fail closed.
109
+ *
110
+ * Fork validates this before CreateBranch so a missing or incomplete history
111
+ * point does not create a branch session (Python
112
+ * `completed_root_checkpoint` parity).
113
+ */
114
+ export async function completedRootCheckpoint(graph, args) {
115
+ const configurable = {
116
+ thread_id: args.threadId,
117
+ checkpoint_ns: "",
118
+ };
119
+ if (args.historyId)
120
+ configurable["checkpoint_id"] = args.historyId;
121
+ const snapshot = await graph.getState({ configurable });
122
+ const found = snapshot.config.configurable ?? {};
123
+ const checkpointId = found["checkpoint_id"];
124
+ if (typeof checkpointId !== "string" || checkpointId === "") {
125
+ throw new Error("session has no completed history to fork from");
126
+ }
127
+ if (found["checkpoint_ns"]) {
128
+ throw new Error("LangGraph checkpoint branching supports root graphs only");
129
+ }
130
+ if (args.historyId && checkpointId !== args.historyId) {
131
+ throw new Error("LangGraph branch point was not found");
132
+ }
133
+ if (snapshot.next.length > 0 || snapshot.tasks.length > 0) {
134
+ throw new Error("history point is not a completed root checkpoint");
135
+ }
136
+ return { threadId: args.threadId, checkpointId };
137
+ }
138
+ /**
139
+ * Build the copyable superstep plan, or raise before any destination write.
140
+ *
141
+ * Port of Python's `checkpoint_replay_plan`; fork builds this before
142
+ * CreateBranch so the copied snapshot is the one that was validated.
143
+ */
144
+ export async function checkpointReplayPlan(graph, source) {
145
+ const checkpointer = graph.checkpointer;
146
+ if (checkpointer === undefined || typeof checkpointer === "boolean") {
147
+ throw new Error("LangGraph checkpoint branching requires a checkpointer");
148
+ }
149
+ const sourceConfig = checkpointConfig(source);
150
+ const selected = await graph.getState(sourceConfig);
151
+ if (!isDeepStrictEqual(rootGraphCheckpoint(selected.config), source)) {
152
+ throw new Error("LangGraph branch point was not found");
153
+ }
154
+ if (selected.next.length > 0 || selected.tasks.length > 0) {
155
+ throw new Error("LangGraph branch point must be a completed root checkpoint");
156
+ }
157
+ const history = [];
158
+ let historyConfig = sourceConfig;
159
+ while (historyConfig !== undefined) {
160
+ const snapshot = await graph.getState(historyConfig);
161
+ rootGraphCheckpoint(snapshot.config);
162
+ history.push(snapshot);
163
+ historyConfig = snapshot.parentConfig;
164
+ }
165
+ const supersteps = [];
166
+ for (const snapshot of history.reverse()) {
167
+ const tuple = await checkpointer.getTuple(snapshot.config);
168
+ const updates = stateUpdates(snapshot, tuple?.pendingWrites ?? []);
169
+ if (updates.length > 0)
170
+ supersteps.push({ updates });
171
+ }
172
+ if (supersteps.length === 0) {
173
+ throw new Error("LangGraph branch point has no checkpoint history");
174
+ }
175
+ return supersteps;
176
+ }
177
+ /**
178
+ * Rebuild `source` in the empty thread named by `targetConfig`.
179
+ *
180
+ * `plan` is the pre-dispatch validated plan from `checkpointReplayPlan`;
181
+ * callers that validated before a side effect pass it so the copy can only
182
+ * materialize that snapshot.
183
+ */
184
+ export async function copyCheckpoint(graph, targetConfig, source, plan) {
185
+ const checkpointer = graph.checkpointer;
186
+ if (checkpointer === undefined || typeof checkpointer === "boolean") {
187
+ throw new Error("LangGraph checkpoint branching requires a checkpointer");
188
+ }
189
+ const targetThreadId = targetConfig.configurable?.["thread_id"];
190
+ if (typeof targetThreadId !== "string") {
191
+ throw new Error("LangGraph branch destination thread is missing");
192
+ }
193
+ for await (const _ of checkpointer.list({ configurable: { thread_id: targetThreadId } }, { limit: 1 })) {
194
+ throw new Error("LangGraph branch destination thread is not empty");
195
+ }
196
+ const supersteps = plan ?? (await checkpointReplayPlan(graph, source));
197
+ const sourceConfig = checkpointConfig(source);
198
+ const selected = await graph.getState(sourceConfig);
199
+ const configurable = {
200
+ ...targetConfig.configurable,
201
+ checkpoint_ns: "",
202
+ };
203
+ delete configurable["checkpoint_id"];
204
+ const copiedConfig = await graph.bulkUpdateState({ ...targetConfig, configurable }, supersteps);
205
+ const copied = await graph.getState(copiedConfig);
206
+ if (copied.next.length > 0 ||
207
+ copied.tasks.length > 0 ||
208
+ !isDeepStrictEqual(stateWithoutMessageIds(copied.values), stateWithoutMessageIds(selected.values))) {
209
+ throw new Error("Copied LangGraph branch point does not match its source");
210
+ }
211
+ }
212
+ /** True when `config`'s thread has no checkpoints yet. */
213
+ export async function destinationThreadIsEmpty(graph, config) {
214
+ const checkpointer = graph.checkpointer;
215
+ if (checkpointer === undefined || typeof checkpointer === "boolean") {
216
+ throw new Error("LangGraph checkpoint branching requires a checkpointer");
217
+ }
218
+ const targetThreadId = config.configurable?.["thread_id"];
219
+ if (typeof targetThreadId !== "string") {
220
+ throw new Error("LangGraph branch destination thread is missing");
221
+ }
222
+ for await (const _ of checkpointer.list({ configurable: { thread_id: targetThreadId } }, { limit: 1 })) {
223
+ return false;
224
+ }
225
+ return true;
226
+ }
227
+ /**
228
+ * Copy `source` onto an empty dest thread.
229
+ *
230
+ * In-app fork already materializes dest; OE still dispatches later dest
231
+ * invokes with the source branch point. If dest already has checkpoints,
232
+ * leave it alone (Python `initialize_checkpoint_branch` parity).
233
+ */
234
+ export async function initializeCheckpointBranch(graph, config, source) {
235
+ if (!(await destinationThreadIsEmpty(graph, config)))
236
+ return;
237
+ await copyCheckpoint(graph, config, source);
238
+ }
239
+ //# sourceMappingURL=checkpoint_branch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkpoint_branch.js","sourceRoot":"","sources":["../src/checkpoint_branch.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAElE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAO9C,MAAM,UAAU,uBAAuB,CACrC,QAAoD;IAEpD,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAC,wBAAwB,CAAC,CAAC;IACnD,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC1C,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACxE,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC9D,CAAC;IACD,MAAM,QAAQ,GAAI,KAAiC,CAAC,WAAW,CAAC,CAAC;IACjE,MAAM,YAAY,GAAI,KAAiC,CAAC,eAAe,CAAC,CAAC;IACzE,IACE,OAAO,QAAQ,KAAK,QAAQ;QAC5B,QAAQ,CAAC,MAAM,KAAK,CAAC;QACrB,OAAO,YAAY,KAAK,QAAQ;QAChC,YAAY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+1,21 @@
1
+ /**
2
+ * Checkpointer hardening for the MongoDB saver.
3
+ *
4
+ * `@langchain/langgraph-checkpoint-mongodb`'s `putWrites` builds a bulk-write
5
+ * from the pending writes and calls `collection.bulkWrite(operations)`
6
+ * unconditionally. When a graph step produces no writes — which deep-agent
7
+ * steps routinely do — `operations` is empty and MongoDB rejects it with
8
+ * `MongoInvalidArgumentError: Invalid BulkOperation, Batch cannot be empty`,
9
+ * surfacing as an AER 500. Persisting zero writes is a no-op, so we short-circuit
10
+ * it. This affects any TypeScript agent using the Mongo checkpointer.
11
+ */
12
+ import type { BaseCheckpointSaver } from "@langchain/langgraph-checkpoint";
13
+ /**
14
+ * Wrap a checkpoint saver so `putWrites` skips empty write batches.
15
+ *
16
+ * Patches the instance in place and returns it. Idempotent and safe on any
17
+ * `BaseCheckpointSaver`; only the empty-batch path is altered, every non-empty
18
+ * call is forwarded unchanged.
19
+ */
20
+ export declare function withEmptyBatchGuard<S extends BaseCheckpointSaver>(saver: S): S;
21
+ //# sourceMappingURL=checkpointer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkpointer.d.ts","sourceRoot":"","sources":["../src/checkpointer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAE3E;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,mBAAmB,EAC/D,KAAK,EAAE,CAAC,GACP,CAAC,CAUH"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Checkpointer hardening for the MongoDB saver.
3
+ *
4
+ * `@langchain/langgraph-checkpoint-mongodb`'s `putWrites` builds a bulk-write
5
+ * from the pending writes and calls `collection.bulkWrite(operations)`
6
+ * unconditionally. When a graph step produces no writes — which deep-agent
7
+ * steps routinely do — `operations` is empty and MongoDB rejects it with
8
+ * `MongoInvalidArgumentError: Invalid BulkOperation, Batch cannot be empty`,
9
+ * surfacing as an AER 500. Persisting zero writes is a no-op, so we short-circuit
10
+ * it. This affects any TypeScript agent using the Mongo checkpointer.
11
+ */
12
+ /**
13
+ * Wrap a checkpoint saver so `putWrites` skips empty write batches.
14
+ *
15
+ * Patches the instance in place and returns it. Idempotent and safe on any
16
+ * `BaseCheckpointSaver`; only the empty-batch path is altered, every non-empty
17
+ * call is forwarded unchanged.
18
+ */
19
+ export function withEmptyBatchGuard(saver) {
20
+ const originalPutWrites = saver.putWrites.bind(saver);
21
+ saver.putWrites = async (config, writes, taskId) => {
22
+ // Only short-circuit the known empty-batch case. Anything else — including a
23
+ // non-array, should the upstream contract change — is forwarded so a real
24
+ // contract violation surfaces instead of silently dropping writes.
25
+ if (Array.isArray(writes) && writes.length === 0)
26
+ return;
27
+ return originalPutWrites(config, writes, taskId);
28
+ };
29
+ return saver;
30
+ }
31
+ //# sourceMappingURL=checkpointer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkpointer.js","sourceRoot":"","sources":["../src/checkpointer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CACjC,KAAQ;IAER,MAAM,iBAAiB,GAAG,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACtD,KAAK,CAAC,SAAS,GAAG,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;QACjD,6EAA6E;QAC7E,0EAA0E;QAC1E,mEAAmE;QACnE,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO;QACzD,OAAO,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACnD,CAAC,CAAC;IACF,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Deep-agent factory for Atlas Agent Engine AER integration.
3
+ *
4
+ * `createAgentEngineDeepAgent` resolves relative skill paths and validates
5
+ * subagent specs before delegating to deepagents (mirroring Python's
6
+ * `deep_agent.py`):
7
+ *
8
+ * - {@link validateSubagentTree} rejects subagent specs with string models,
9
+ * which would bypass OE routing (deepagents instantiates a raw, unwrapped LLM
10
+ * from a string spec).
11
+ *
12
+ */
13
+ import { createDeepAgent } from "deepagents";
14
+ import type { AnyBackendProtocol, AnySubAgent, CreateDeepAgentParams } from "deepagents";
15
+ import type { BaseChatModel } from "@langchain/core/language_models/chat_models";
16
+ import type { StructuredTool } from "@langchain/core/tools";
17
+ import type { BaseCheckpointSaver } from "@langchain/langgraph";
18
+ export interface CreateAgentEngineDeepAgentOptions {
19
+ /** Additional tools for the deep agent. */
20
+ tools?: StructuredTool[];
21
+ /**
22
+ * SubAgent specs. Plain specs with a `model` field must use a model instance,
23
+ * not a string — string models bypass OE routing.
24
+ */
25
+ subagents?: readonly AnySubAgent[];
26
+ /** Custom system instructions. */
27
+ systemPrompt?: string;
28
+ /** Additional middleware, appended after the default durable middleware. */
29
+ middleware?: CreateDeepAgentParams["middleware"];
30
+ /** LangGraph checkpointer for state persistence, HITL, and multi-turn. */
31
+ checkpointer?: BaseCheckpointSaver | boolean;
32
+ /** LangGraph store for skills and shared data. */
33
+ store?: CreateDeepAgentParams["store"];
34
+ /** Parent directories for deepagents' one-level skill discovery. */
35
+ skills?: string[];
36
+ /** Base directory for relative skill paths (set by `App.deepAgent()`). */
37
+ skillsBaseDir?: string;
38
+ }
39
+ /**
40
+ * Create a deep-agent graph pre-configured for Atlas Agent Engine AER. Resolves relative
41
+ * skill paths, validates the subagent tree, then delegates to deepagents'
42
+ * `createDeepAgent`.
43
+ *
44
+ * @param secureLlm A `SecureWrappedLLM` instance — every LLM call is OE-audited.
45
+ * @param backend Backend for filesystem/shell ops; resolved by `App.deepAgent()`.
46
+ * @throws {Error} A subagent spec uses a string model, or nesting exceeds the cap.
47
+ */
48
+ export declare function createAgentEngineDeepAgent(secureLlm: BaseChatModel, backend: AnyBackendProtocol | undefined, options?: CreateAgentEngineDeepAgentOptions): ReturnType<typeof createDeepAgent>;
49
+ //# sourceMappingURL=deep_agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deep_agent.d.ts","sourceRoot":"","sources":["../src/deep_agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EACV,kBAAkB,EAClB,WAAW,EACX,qBAAqB,EACtB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AACjF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAsBhE,MAAM,WAAW,iCAAiC;IAChD,2CAA2C;IAC3C,KAAK,CAAC,EAAE,cAAc,EAAE,CAAC;IACzB;;;OAGG;IACH,SAAS,CAAC,EAAE,SAAS,WAAW,EAAE,CAAC;IACnC,kCAAkC;IAClC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,4EAA4E;IAC5E,UAAU,CAAC,EAAE,qBAAqB,CAAC,YAAY,CAAC,CAAC;IACjD,0EAA0E;IAC1E,YAAY,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC;IAC7C,kDAAkD;IAClD,KAAK,CAAC,EAAE,qBAAqB,CAAC,OAAO,CAAC,CAAC;IACvC,oEAAoE;IACpE,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,0EAA0E;IAC1E,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AA4BD;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,aAAa,EACxB,OAAO,EAAE,kBAAkB,GAAG,SAAS,EACvC,OAAO,GAAE,iCAAsC,GAC9C,UAAU,CAAC,OAAO,eAAe,CAAC,CAyDpC"}
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Deep-agent factory for Atlas Agent Engine AER integration.
3
+ *
4
+ * `createAgentEngineDeepAgent` resolves relative skill paths and validates
5
+ * subagent specs before delegating to deepagents (mirroring Python's
6
+ * `deep_agent.py`):
7
+ *
8
+ * - {@link validateSubagentTree} rejects subagent specs with string models,
9
+ * which would bypass OE routing (deepagents instantiates a raw, unwrapped LLM
10
+ * from a string spec).
11
+ *
12
+ */
13
+ import * as path from "node:path";
14
+ import { createDeepAgent } from "deepagents";
15
+ import { validateSubagentTree } from "./subagents.js";
16
+ import { checkpointerForDeepAgent } from "./deep_agent_checkpointer.js";
17
+ import { createDurableDeepAgentMiddleware } from "./durable_deep_agent.js";
18
+ /** Names of compiled subagent specs whose runnable carries its own checkpointer. */
19
+ function compiledSubagentCheckpointerNames(subagents) {
20
+ const names = new Set();
21
+ for (const spec of subagents ?? []) {
22
+ if ("runnable" in spec &&
23
+ spec.runnable
24
+ ?.checkpointer != null) {
25
+ names.add(spec.name);
26
+ }
27
+ }
28
+ return names;
29
+ }
30
+ function loadSkillPaths(paths, baseDir) {
31
+ if (baseDir === undefined)
32
+ return [...paths];
33
+ return paths.map((skillPath) => path.isAbsolute(skillPath) ? skillPath : path.join(baseDir, skillPath));
34
+ }
35
+ /**
36
+ * Resolve relative per-subagent skill paths against the same base directory as
37
+ * the top-level `skills` list. Compiled (`runnable`) and remote (`graphId`)
38
+ * specs, and specs without a `skills` field, pass through unchanged.
39
+ */
40
+ function loadSubagentSkillPaths(subagents, baseDir) {
41
+ return subagents.map((spec) => {
42
+ if ("runnable" in spec || "graphId" in spec || !("skills" in spec)) {
43
+ return spec;
44
+ }
45
+ const skills = spec.skills;
46
+ if (skills === undefined)
47
+ return spec;
48
+ return { ...spec, skills: loadSkillPaths(skills, baseDir) };
49
+ });
50
+ }
51
+ /**
52
+ * Create a deep-agent graph pre-configured for Atlas Agent Engine AER. Resolves relative
53
+ * skill paths, validates the subagent tree, then delegates to deepagents'
54
+ * `createDeepAgent`.
55
+ *
56
+ * @param secureLlm A `SecureWrappedLLM` instance — every LLM call is OE-audited.
57
+ * @param backend Backend for filesystem/shell ops; resolved by `App.deepAgent()`.
58
+ * @throws {Error} A subagent spec uses a string model, or nesting exceeds the cap.
59
+ */
60
+ export function createAgentEngineDeepAgent(secureLlm, backend, options = {}) {
61
+ validateSubagentTree(options.subagents);
62
+ const forwardedSkills = options.skills !== undefined
63
+ ? loadSkillPaths(options.skills, options.skillsBaseDir)
64
+ : undefined;
65
+ const forwardedSubagents = options.subagents !== undefined
66
+ ? loadSubagentSkillPaths(options.subagents, options.skillsBaseDir)
67
+ : undefined;
68
+ const durableCheckpointer = options.checkpointer !== undefined
69
+ ? checkpointerForDeepAgent(options.checkpointer)
70
+ : undefined;
71
+ // Passed straight through as skills= (not built into a middleware
72
+ // instance here, unlike the Python port): createDeepAgent constructs
73
+ // createSkillsMiddleware itself in three places -- the main agent, the
74
+ // auto-injected general-purpose subagent, and any subagent with its own
75
+ // skills= -- and deepagents-js exports that factory as a frozen ESM
76
+ // binding, so there is no way to substitute a traced wrapper for the
77
+ // other two call sites without dropping skills from them entirely.
78
+ // Python can patch the class in place instead (see skills_tracing.py);
79
+ // no equivalent exists here, so this hook stays untraced in TS.
80
+ // Build via conditional spreads so absent options are omitted rather than
81
+ // set to `undefined` — the package is compiled with
82
+ // `exactOptionalPropertyTypes`, which rejects `undefined` on optional props.
83
+ // `backend` is likewise omitted when undefined so deepagents applies its own
84
+ // default (an in-memory StateBackend).
85
+ return createDeepAgent({
86
+ model: secureLlm,
87
+ ...(options.tools !== undefined && { tools: options.tools }),
88
+ ...(forwardedSubagents !== undefined && { subagents: forwardedSubagents }),
89
+ ...(options.systemPrompt !== undefined && {
90
+ systemPrompt: options.systemPrompt,
91
+ }),
92
+ // Prepended so every agent gets durable local-subagent attribution by
93
+ // default. A per-call-stopped tool batch goes to the model as ordinary
94
+ // interrupted ToolMessages — continuation is the model's call, matching
95
+ // the Python twin.
96
+ middleware: [
97
+ createDurableDeepAgentMiddleware({
98
+ unsupportedSubagentNames: compiledSubagentCheckpointerNames(options.subagents),
99
+ }),
100
+ ...(options.middleware ?? []),
101
+ ],
102
+ ...(durableCheckpointer !== undefined && {
103
+ checkpointer: durableCheckpointer,
104
+ }),
105
+ ...(options.store !== undefined && { store: options.store }),
106
+ ...(forwardedSkills !== undefined && { skills: forwardedSkills }),
107
+ ...(backend !== undefined && { backend }),
108
+ });
109
+ }
110
+ //# sourceMappingURL=deep_agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deep_agent.js","sourceRoot":"","sources":["../src/deep_agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAS7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EAAE,gCAAgC,EAAE,MAAM,yBAAyB,CAAC;AAE3E,oFAAoF;AACpF,SAAS,iCAAiC,CACxC,SAA6C;IAE7C,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAChC,KAAK,MAAM,IAAI,IAAI,SAAS,IAAI,EAAE,EAAE,CAAC;QACnC,IACE,UAAU,IAAI,IAAI;YACjB,IAAkD,CAAC,QAAQ;gBAC1D,EAAE,YAAY,IAAI,IAAI,EACxB,CAAC;YACD,KAAK,CAAC,GAAG,CAAE,IAAyB,CAAC,IAAI,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAwBD,SAAS,cAAc,CAAC,KAAe,EAAE,OAAgB;IACvD,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC;IAC7C,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAC7B,IAAI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BaseCheckpointSaver } from "@langchain/langgraph";
3
+ /**
4
+ * Return the internal-routing view for a platform checkpointer, so a Deep
5
+ * Agent graph participates in durable execution without rejecting its own
6
+ * adapter routing (LangChain's agent factory routes pending ToolCalls through
7
+ * LangGraph Send packets). The view shares the same platform scratch and
8
+ * native savers. Other checkpointers pass through unchanged.
9
+ */
10
+ export declare function checkpointerForDeepAgent<C extends BaseCheckpointSaver<string | number> | boolean | undefined>(checkpointer: C): C;
11
+ //# sourceMappingURL=deep_agent_checkpointer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deep_agent_checkpointer.d.ts","sourceRoot":"","sources":["../src/deep_agent_checkpointer.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAE5D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAIhE;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,CAAC,SAAS,mBAAmB,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,OAAO,GAAG,SAAS,EACpE,YAAY,EAAE,CAAC,GAAG,CAAC,CAQpB"}
@@ -0,0 +1,19 @@
1
+ /** Checkpointer policy for graphs created by Deep Agent. */
2
+ import { PlatformCheckpointer } from "./platform_checkpointer.js";
3
+ /**
4
+ * Return the internal-routing view for a platform checkpointer, so a Deep
5
+ * Agent graph participates in durable execution without rejecting its own
6
+ * adapter routing (LangChain's agent factory routes pending ToolCalls through
7
+ * LangGraph Send packets). The view shares the same platform scratch and
8
+ * native savers. Other checkpointers pass through unchanged.
9
+ */
10
+ export function checkpointerForDeepAgent(checkpointer) {
11
+ if (checkpointer instanceof PlatformCheckpointer) {
12
+ // The view shares the same platform state, so platform-owned lifecycle
13
+ // (scratch release, completion) observes exactly what the deep-agent
14
+ // graph writes.
15
+ return checkpointer.deepAgentView();
16
+ }
17
+ return checkpointer;
18
+ }
19
+ //# sourceMappingURL=deep_agent_checkpointer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deep_agent_checkpointer.js","sourceRoot":"","sources":["../src/deep_agent_checkpointer.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAI5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAElE;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CAEtC,YAAe;IACf,IAAI,YAAY,YAAY,oBAAoB,EAAE,CAAC;QACjD,uEAAuE;QACvE,qEAAqE;QACrE,gBAAgB;QAChB,OAAO,YAAY,CAAC,aAAa,EAAkB,CAAC;IACtD,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Parse Deep Agent `task` tool calls for adapter-owned behavior.
3
+ *
4
+ * Port of `deep_agent_task.py`.
5
+ */
6
+ export declare const DISPATCH_TOOL_NAME = "task";
7
+ export interface DeepAgentTaskCall {
8
+ /** Normalized identity and stream metadata for one `task` call. */
9
+ readonly toolCallId: string;
10
+ readonly subagentName: string;
11
+ readonly description: string;
12
+ }
13
+ /**
14
+ * Normalize one Deep Agent task call, retaining malformed identity as empty.
15
+ * Returns null for tool calls that are not `task` dispatches.
16
+ */
17
+ export declare function parseTaskCall(toolCall: unknown): DeepAgentTaskCall | null;
18
+ /**
19
+ * Yield task calls with IDs from LangChain messages or chunks.
20
+ *
21
+ * Stream attribution historically ignores incomplete tool-call chunks until
22
+ * their stable ID is assembled. Durable dispatch performs its stricter name
23
+ * and ID validation directly through {@link parseTaskCall}.
24
+ */
25
+ export declare function iterTaskCalls(messagesOrChunks: Iterable<unknown>): IterableIterator<DeepAgentTaskCall>;
26
+ //# sourceMappingURL=deep_agent_task.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deep_agent_task.d.ts","sourceRoot":"","sources":["../src/deep_agent_task.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,eAAO,MAAM,kBAAkB,SAAS,CAAC;AAOzC,MAAM,WAAW,iBAAiB;IAChC,mEAAmE;IACnE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,OAAO,GAAG,iBAAiB,GAAG,IAAI,CAczE;AAED;;;;;;GAMG;AACH,wBAAiB,aAAa,CAC5B,gBAAgB,EAAE,QAAQ,CAAC,OAAO,CAAC,GAClC,gBAAgB,CAAC,iBAAiB,CAAC,CASrC"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Parse Deep Agent `task` tool calls for adapter-owned behavior.
3
+ *
4
+ * Port of `deep_agent_task.py`.
5
+ */
6
+ export const DISPATCH_TOOL_NAME = "task";
7
+ function toolCallValue(toolCall, key) {
8
+ if (toolCall === null || typeof toolCall !== "object")
9
+ return undefined;
10
+ return toolCall[key];
11
+ }
12
+ /**
13
+ * Normalize one Deep Agent task call, retaining malformed identity as empty.
14
+ * Returns null for tool calls that are not `task` dispatches.
15
+ */
16
+ export function parseTaskCall(toolCall) {
17
+ if (toolCallValue(toolCall, "name") !== DISPATCH_TOOL_NAME)
18
+ return null;
19
+ const rawId = toolCallValue(toolCall, "id");
20
+ const args = toolCallValue(toolCall, "args");
21
+ const argsDict = args !== null && typeof args === "object" && !Array.isArray(args)
22
+ ? args
23
+ : {};
24
+ return {
25
+ toolCallId: typeof rawId === "string" ? rawId : "",
26
+ subagentName: String(argsDict["subagent_type"] ?? "") || "",
27
+ description: String(argsDict["description"] ?? "") || "",
28
+ };
29
+ }
30
+ /**
31
+ * Yield task calls with IDs from LangChain messages or chunks.
32
+ *
33
+ * Stream attribution historically ignores incomplete tool-call chunks until
34
+ * their stable ID is assembled. Durable dispatch performs its stricter name
35
+ * and ID validation directly through {@link parseTaskCall}.
36
+ */
37
+ export function* iterTaskCalls(messagesOrChunks) {
38
+ for (const message of messagesOrChunks) {
39
+ const toolCalls = message.tool_calls;
40
+ if (!Array.isArray(toolCalls))
41
+ continue;
42
+ for (const toolCall of toolCalls) {
43
+ const parsed = parseTaskCall(toolCall);
44
+ if (parsed !== null && parsed.toolCallId !== "")
45
+ yield parsed;
46
+ }
47
+ }
48
+ }
49
+ //# sourceMappingURL=deep_agent_task.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deep_agent_task.js","sourceRoot":"","sources":["../src/deep_agent_task.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAEzC,SAAS,aAAa,CAAC,QAAiB,EAAE,GAAW;IACnD,IAAI,QAAQ,KAAK,IAAI,IAAI,OAAO,QAAQ,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IACxE,OAAQ,QAAoC,CAAC,GAAG,CAAC,CAAC;AACpD,CAAC;AASD;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,QAAiB;IAC7C,IAAI,aAAa,CAAC,QAAQ,EAAE,MAAM,CAAC,KAAK,kBAAkB;QAAE,OAAO,IAAI,CAAC;IAExE,MAAM,KAAK,GAAG,aAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC5C,MAAM,IAAI,GAAG,aAAa,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC7C,MAAM,QAAQ,GACZ,IAAI,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QAC/D,CAAC,CAAE,IAAgC;QACnC,CAAC,CAAC,EAAE,CAAC;IACT,OAAO;QACL,UAAU,EAAE,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;QAClD,YAAY,EAAE,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE;QAC3D,WAAW,EAAE,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE;KACzD,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,SAAS,CAAC,CAAC,aAAa,CAC5B,gBAAmC;IAEnC,KAAK,MAAM,OAAO,IAAI,gBAAgB,EAAE,CAAC;QACvC,MAAM,SAAS,GAAI,OAAoC,CAAC,UAAU,CAAC;QACnE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC;YAAE,SAAS;QACxC,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;YACjC,MAAM,MAAM,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;YACvC,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,CAAC,UAAU,KAAK,EAAE;gBAAE,MAAM,MAAM,CAAC;QAChE,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Durable operation-path boundaries for Deep Agent task delegation.
3
+ *
4
+ * Deep Agent exposes subagent dispatch through the public `task` tool and
5
+ * middleware hooks, rather than as a compiled child graph:
6
+ * https://docs.langchain.com/oss/javascript/deepagents/subagents
7
+ *
8
+ * Same-step `task` siblings stamp ToolCall-id ordinals after FinalizeStep.
9
+ * Stamping in `afterModel` would key those ordinals to the model step, which
10
+ * FinalizeStep then leaves behind.
11
+ *
12
+ * Port of `durable_deep_agent.py`.
13
+ */
14
+ import { type BaseMessage } from "@langchain/core/messages";
15
+ /**
16
+ * Replace Deep Agent's generated message ids before LangGraph persists them.
17
+ * No-op outside a task scope, so native sessions keep provider ids.
18
+ */
19
+ export declare function stampDeepAgentMessageIds(messages: BaseMessage[]): void;
20
+ export declare function createDurableDeepAgentMiddleware(options: {
21
+ unsupportedSubagentNames?: ReadonlySet<string>;
22
+ }): import("langchain").AgentMiddleware<undefined, undefined, unknown, readonly (import("@langchain/core/tools").ClientTool | import("@langchain/core/tools").ServerTool)[]>;
23
+ //# sourceMappingURL=durable_deep_agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"durable_deep_agent.d.ts","sourceRoot":"","sources":["../src/durable_deep_agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,OAAO,EACL,KAAK,WAAW,EAIjB,MAAM,0BAA0B,CAAC;AAoClC;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,IAAI,CAmBtE;AAuBD,wBAAgB,gCAAgC,CAAC,OAAO,EAAE;IACxD,wBAAwB,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAChD,4KAsHA"}