darwin-langgraph 0.2.0-alpha.1 → 0.4.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +348 -0
- package/README.md +108 -3
- package/dist/create-darwin-node.d.ts +55 -0
- package/dist/create-darwin-node.d.ts.map +1 -1
- package/dist/create-darwin-node.js +56 -1
- package/dist/create-darwin-node.js.map +1 -1
- package/dist/darwin-accumulating-annotation.d.ts +81 -0
- package/dist/darwin-accumulating-annotation.d.ts.map +1 -0
- package/dist/darwin-accumulating-annotation.js +144 -0
- package/dist/darwin-accumulating-annotation.js.map +1 -0
- package/dist/darwin-callback-handler.d.ts +161 -2
- package/dist/darwin-callback-handler.d.ts.map +1 -1
- package/dist/darwin-callback-handler.js +417 -25
- package/dist/darwin-callback-handler.js.map +1 -1
- package/dist/errors.d.ts +16 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +19 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +7 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -3
- package/dist/index.js.map +1 -1
- package/dist/to-otel-attributes.d.ts +49 -0
- package/dist/to-otel-attributes.d.ts.map +1 -1
- package/dist/to-otel-attributes.js +38 -2
- package/dist/to-otel-attributes.js.map +1 -1
- package/dist/to-w3c-trace-context.d.ts +81 -0
- package/dist/to-w3c-trace-context.d.ts.map +1 -0
- package/dist/to-w3c-trace-context.js +134 -0
- package/dist/to-w3c-trace-context.js.map +1 -0
- package/dist/token-budget.d.ts +141 -0
- package/dist/token-budget.d.ts.map +1 -0
- package/dist/token-budget.js +225 -0
- package/dist/token-budget.js.map +1 -0
- package/dist/with-darwin-evolution.d.ts +40 -0
- package/dist/with-darwin-evolution.d.ts.map +1 -1
- package/dist/with-darwin-evolution.js +55 -1
- package/dist/with-darwin-evolution.js.map +1 -1
- package/package.json +2 -2
|
@@ -51,6 +51,26 @@
|
|
|
51
51
|
*/
|
|
52
52
|
import { BaseCallbackHandler } from "@langchain/core/callbacks/base";
|
|
53
53
|
import { DarwinEvolutionHookError } from "./errors.js";
|
|
54
|
+
/**
|
|
55
|
+
* Highest `ExecutionTrace.version` this handler natively understands.
|
|
56
|
+
* The forward-compat guard in {@link isExecutionTrace} warns once for
|
|
57
|
+
* higher versions but still emits them (structural shape covers the
|
|
58
|
+
* required fields) so a Darwin upgrade ahead of the adapter doesn't
|
|
59
|
+
* silently drop trajectories.
|
|
60
|
+
*
|
|
61
|
+
* NEW V0.4 (S1235).
|
|
62
|
+
*/
|
|
63
|
+
export const MAX_KNOWN_TRACE_VERSION = 1;
|
|
64
|
+
/** Default cap. Aligned with reasonable LangGraph fan-out (~1k nodes / minute). */
|
|
65
|
+
const DEFAULT_MAX_IN_FLIGHT_RUNS = 1024;
|
|
66
|
+
/** Default size cap for trajectory `onTrajectory` emission (256 KiB). */
|
|
67
|
+
const DEFAULT_MAX_TRAJECTORY_BYTES = 262_144;
|
|
68
|
+
/**
|
|
69
|
+
* Process-wide flag so the unknown-version warning fires once per
|
|
70
|
+
* process even across multiple handler instances. Exported intentionally
|
|
71
|
+
* undefined — re-bound via module-reload in tests.
|
|
72
|
+
*/
|
|
73
|
+
let unknownTraceVersionWarned = false;
|
|
54
74
|
function isExecutionTrace(value) {
|
|
55
75
|
if (!value || typeof value !== "object")
|
|
56
76
|
return false;
|
|
@@ -59,9 +79,61 @@ function isExecutionTrace(value) {
|
|
|
59
79
|
// version. Downstream consumers (e.g. toOtelAttributes) read
|
|
60
80
|
// `toolCalls.length` directly — a malformed trace with missing arrays
|
|
61
81
|
// would crash there. Guard explicitly.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
82
|
+
//
|
|
83
|
+
// V0.4 (S1235): forward-compat — accept v ≥ 1 as long as the structural
|
|
84
|
+
// shape `toolCalls + errors` is preserved. A future Darwin release that
|
|
85
|
+
// bumps the version while adding fields will still flow through; only
|
|
86
|
+
// structurally-incompatible payloads are dropped. We warn once per
|
|
87
|
+
// process when we observe a higher-than-known version so an out-of-date
|
|
88
|
+
// adapter dependency is loud rather than silent.
|
|
89
|
+
if (typeof v.version !== "number" ||
|
|
90
|
+
!Number.isFinite(v.version) ||
|
|
91
|
+
v.version < 1 ||
|
|
92
|
+
!Array.isArray(v.toolCalls) ||
|
|
93
|
+
!Array.isArray(v.errors)) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
if (v.version > MAX_KNOWN_TRACE_VERSION && !unknownTraceVersionWarned) {
|
|
97
|
+
unknownTraceVersionWarned = true;
|
|
98
|
+
console.warn(`[darwin-langgraph] Observed ExecutionTrace.version=${v.version} — ` +
|
|
99
|
+
`this adapter knows up to v${MAX_KNOWN_TRACE_VERSION}. Emitting as ` +
|
|
100
|
+
`compatible v${MAX_KNOWN_TRACE_VERSION}-shape; upgrade darwin-langgraph ` +
|
|
101
|
+
`to access any new fields. Subsequent unknown-version observations ` +
|
|
102
|
+
`are silent.`);
|
|
103
|
+
}
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Build a structurally-compatible BUT minimal stub when a trajectory's
|
|
108
|
+
* serialised size exceeds the configured cap. Preserves the aggregate
|
|
109
|
+
* counts (turns / textBlocks / mcp invocations / errors-count via empty
|
|
110
|
+
* array — counts go through via the dedicated count fields) plus
|
|
111
|
+
* `capturedAt` for traceability. Caller-visible flag
|
|
112
|
+
* `trajectoryTruncated = true` is set on the event payload so consumers
|
|
113
|
+
* can branch on it.
|
|
114
|
+
*/
|
|
115
|
+
function buildTruncatedTrace(t) {
|
|
116
|
+
// R1 P1-2 fix (S1235): shallow-copy `tokenUsage` instead of leaking
|
|
117
|
+
// the original object reference. The original trajectory may carry
|
|
118
|
+
// BigInt fields (some providers expose 64-bit token counts) which
|
|
119
|
+
// downstream JSON.stringify cannot handle — coerce them to Number
|
|
120
|
+
// via the explicit spread/normaliser.
|
|
121
|
+
const tokenUsage = t.tokenUsage
|
|
122
|
+
? Object.fromEntries(Object.entries(t.tokenUsage).map(([k, v]) => [
|
|
123
|
+
k,
|
|
124
|
+
typeof v === "bigint" ? Number(v) : v,
|
|
125
|
+
]))
|
|
126
|
+
: undefined;
|
|
127
|
+
return {
|
|
128
|
+
version: t.version,
|
|
129
|
+
toolCalls: [],
|
|
130
|
+
textBlockCount: t.textBlockCount,
|
|
131
|
+
turnCount: t.turnCount,
|
|
132
|
+
mcpInvocations: t.mcpInvocations,
|
|
133
|
+
errors: [],
|
|
134
|
+
capturedAt: t.capturedAt,
|
|
135
|
+
...(tokenUsage ? { tokenUsage: tokenUsage } : {}),
|
|
136
|
+
};
|
|
65
137
|
}
|
|
66
138
|
function normaliseNodeMap(nodeMap, defaultKey) {
|
|
67
139
|
const resolved = new Map();
|
|
@@ -96,8 +168,48 @@ export class DarwinCallbackHandler extends BaseCallbackHandler {
|
|
|
96
168
|
awaitHandlers = false;
|
|
97
169
|
resolved;
|
|
98
170
|
onTrajectory;
|
|
171
|
+
onToolEvent;
|
|
172
|
+
/**
|
|
173
|
+
* runId → in-flight run state. Map preserves insertion order so the
|
|
174
|
+
* oldest entry is always at `.keys().next().value` for LRU eviction
|
|
175
|
+
* when the cap is exceeded (V0.3 hung-invoke guard).
|
|
176
|
+
*/
|
|
99
177
|
runIdToName = new Map();
|
|
178
|
+
/**
|
|
179
|
+
* V0.4 (R1 P1-1 fix, S1235) — `toolRunId → toolName` cache populated
|
|
180
|
+
* from `handleToolStart` and consumed by `handleToolEnd` /
|
|
181
|
+
* `handleToolError`. LangChain v0.3 `handleToolEnd` does NOT reliably
|
|
182
|
+
* carry the tool name in its signature (the slot was repurposed
|
|
183
|
+
* across releases); reading `output.name` only works for some shapes
|
|
184
|
+
* and yields "<anonymous-tool>" for the common ToolNode case.
|
|
185
|
+
*/
|
|
186
|
+
toolRunIdToName = new Map();
|
|
187
|
+
/**
|
|
188
|
+
* V0.4 (R1 P1-1 fix, S1235) — pending callbacks keyed by parent chain
|
|
189
|
+
* runId so we can also restore the chain's tool name at end-time even
|
|
190
|
+
* after the `toolRunIdToName` entry is cleaned up.
|
|
191
|
+
*/
|
|
192
|
+
maxInFlightRuns;
|
|
193
|
+
/** V0.4 — byte cap before trajectory replacement. */
|
|
194
|
+
maxTrajectoryBytes;
|
|
195
|
+
/**
|
|
196
|
+
* V0.4 (R1 P1-1 fix) — also cap the tool-name cache. Default matches
|
|
197
|
+
* `maxInFlightRuns` since tool runs are children of chain runs.
|
|
198
|
+
*/
|
|
199
|
+
maxInFlightToolRuns;
|
|
200
|
+
/**
|
|
201
|
+
* Pending trajectory dispatches keyed by chain runId. When a chain
|
|
202
|
+
* ends with tools still in flight we hold the dispatch closure here
|
|
203
|
+
* and fire it from the LAST `handleToolEnd` / `handleToolError`.
|
|
204
|
+
*
|
|
205
|
+
* V0.4 (R1 P1-4 fix, S1235).
|
|
206
|
+
*/
|
|
207
|
+
pendingTrajectoryDispatch = new Map();
|
|
100
208
|
warned = false;
|
|
209
|
+
evictionWarned = false;
|
|
210
|
+
toolWarned = false;
|
|
211
|
+
/** V0.4 — once-per-handler warn for trajectory size cap. */
|
|
212
|
+
trajectoryTruncatedWarned = false;
|
|
101
213
|
constructor(opts) {
|
|
102
214
|
super();
|
|
103
215
|
if (!opts || !opts.nodeMap || Object.keys(opts.nodeMap).length === 0) {
|
|
@@ -106,6 +218,37 @@ export class DarwinCallbackHandler extends BaseCallbackHandler {
|
|
|
106
218
|
const defaultKey = opts.defaultTrajectoryKey ?? "darwinTrajectory";
|
|
107
219
|
this.resolved = normaliseNodeMap(opts.nodeMap, defaultKey);
|
|
108
220
|
this.onTrajectory = opts.onTrajectory;
|
|
221
|
+
this.onToolEvent = opts.onToolEvent;
|
|
222
|
+
// V0.3 (S1187): hung-invoke guard. NaN / negative / non-number falls
|
|
223
|
+
// back to default. Infinity disables the cap (opt-out).
|
|
224
|
+
const raw = opts.maxInFlightRuns;
|
|
225
|
+
if (raw === Infinity) {
|
|
226
|
+
this.maxInFlightRuns = Infinity;
|
|
227
|
+
}
|
|
228
|
+
else if (typeof raw === "number" && Number.isFinite(raw) && raw > 0) {
|
|
229
|
+
this.maxInFlightRuns = Math.floor(raw);
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
this.maxInFlightRuns = DEFAULT_MAX_IN_FLIGHT_RUNS;
|
|
233
|
+
}
|
|
234
|
+
// V0.4 (S1235): trajectory size guard. Same shape as maxInFlightRuns.
|
|
235
|
+
const rawBytes = opts.maxTrajectoryBytes;
|
|
236
|
+
if (rawBytes === Infinity) {
|
|
237
|
+
this.maxTrajectoryBytes = Infinity;
|
|
238
|
+
}
|
|
239
|
+
else if (typeof rawBytes === "number" &&
|
|
240
|
+
Number.isFinite(rawBytes) &&
|
|
241
|
+
rawBytes > 0) {
|
|
242
|
+
this.maxTrajectoryBytes = Math.floor(rawBytes);
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
this.maxTrajectoryBytes = DEFAULT_MAX_TRAJECTORY_BYTES;
|
|
246
|
+
}
|
|
247
|
+
// V0.4 (R1 P1-1 fix): tool-name cache cap mirrors the chain cap.
|
|
248
|
+
this.maxInFlightToolRuns =
|
|
249
|
+
this.maxInFlightRuns === Infinity
|
|
250
|
+
? Infinity
|
|
251
|
+
: Math.max(this.maxInFlightRuns, 1) * 4;
|
|
109
252
|
}
|
|
110
253
|
/**
|
|
111
254
|
* Capture the run-id → node-name mapping.
|
|
@@ -117,7 +260,7 @@ export class DarwinCallbackHandler extends BaseCallbackHandler {
|
|
|
117
260
|
* `BaseCallbackHandler` d.ts is undefined for LangGraph chains at
|
|
118
261
|
* runtime — we keep it as a fallback for non-LangGraph chains.
|
|
119
262
|
*/
|
|
120
|
-
handleChainStart(_chain, _inputs, runId, _runType, _tags, metadata, runName,
|
|
263
|
+
handleChainStart(_chain, _inputs, runId, _runType, _tags, metadata, runName, parentRunId, _extra) {
|
|
121
264
|
// Primary source: metadata.langgraph_node (set by LangGraph internals).
|
|
122
265
|
let nodeName;
|
|
123
266
|
if (metadata && typeof metadata === "object") {
|
|
@@ -136,7 +279,33 @@ export class DarwinCallbackHandler extends BaseCallbackHandler {
|
|
|
136
279
|
// makes lookup in handleChainEnd a simple `.has()` check.
|
|
137
280
|
if (!this.resolved.has(nodeName))
|
|
138
281
|
return;
|
|
139
|
-
|
|
282
|
+
// V0.3 (S1187): hung-invoke guard. If we are about to exceed the cap
|
|
283
|
+
// AND the runId is genuinely new (not a re-fire), evict the oldest
|
|
284
|
+
// entry. Map iteration order is insertion order — the first key is
|
|
285
|
+
// the oldest. Warn once per handler instance so a real leak shows up
|
|
286
|
+
// in logs without spamming.
|
|
287
|
+
if (this.maxInFlightRuns !== Infinity &&
|
|
288
|
+
!this.runIdToName.has(runId) &&
|
|
289
|
+
this.runIdToName.size >= this.maxInFlightRuns) {
|
|
290
|
+
const oldest = this.runIdToName.keys().next().value;
|
|
291
|
+
if (oldest !== undefined) {
|
|
292
|
+
this.runIdToName.delete(oldest);
|
|
293
|
+
}
|
|
294
|
+
if (!this.evictionWarned) {
|
|
295
|
+
this.evictionWarned = true;
|
|
296
|
+
console.warn(`[darwin-langgraph] DarwinCallbackHandler: in-flight runs exceeded ` +
|
|
297
|
+
`${this.maxInFlightRuns} — evicting oldest entry. This usually ` +
|
|
298
|
+
`means handleChainEnd / handleChainError did not fire for some ` +
|
|
299
|
+
`runs (worker crash, parent invoke aborted mid-flight, or ` +
|
|
300
|
+
`LangGraph internal bug). Subsequent evictions are silent.`);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
this.runIdToName.set(runId, {
|
|
304
|
+
nodeName,
|
|
305
|
+
parentRunId: typeof parentRunId === "string" ? parentRunId : undefined,
|
|
306
|
+
pendingTools: 0,
|
|
307
|
+
finalized: false,
|
|
308
|
+
});
|
|
140
309
|
}
|
|
141
310
|
/**
|
|
142
311
|
* When a node-chain finishes, look up its name, locate the matching
|
|
@@ -148,45 +317,260 @@ export class DarwinCallbackHandler extends BaseCallbackHandler {
|
|
|
148
317
|
* partial state under its configured name.
|
|
149
318
|
*/
|
|
150
319
|
handleChainEnd(outputs, runId, _parentRunId, _tags, _kwargs) {
|
|
151
|
-
const
|
|
152
|
-
if (!
|
|
153
|
-
return;
|
|
154
|
-
// One-shot cleanup of the mapping so completed runs don't leak.
|
|
155
|
-
// R1 V0.2 Critic Finding 1 (S1185): the `runIdToName.delete` here
|
|
156
|
-
// is the ONLY dedup we need — LangGraph guarantees `handleChainEnd`
|
|
157
|
-
// fires exactly once per `runId`, and after deletion any second
|
|
158
|
-
// call returns early at `if (!runName)`. The pre-V0.2 `firedRuns`
|
|
159
|
-
// Set was redundant AND leaked unbounded — removed.
|
|
160
|
-
this.runIdToName.delete(runId);
|
|
161
|
-
if (!this.onTrajectory)
|
|
320
|
+
const inFlight = this.runIdToName.get(runId);
|
|
321
|
+
if (!inFlight)
|
|
162
322
|
return;
|
|
163
|
-
|
|
323
|
+
// V0.4 (R1 P1-4 fix, S1235): defer the chain-entry cleanup if tool
|
|
324
|
+
// events are still pending. Without this, `handleToolEnd` for a
|
|
325
|
+
// still-executing tool would see `runIdToName.get(parentRunId) ===
|
|
326
|
+
// undefined` and silently drop the tool event. We mark the entry
|
|
327
|
+
// `finalized` so subsequent `handleChainStart` for the SAME runId
|
|
328
|
+
// (which LangGraph never does, but defense-in-depth) is treated as
|
|
329
|
+
// a re-fire and ignored; and we hold the trajectory dispatch in
|
|
330
|
+
// `pendingTrajectoryDispatch` to fire from the last tool callback.
|
|
331
|
+
inFlight.finalized = true;
|
|
332
|
+
if (inFlight.pendingTools === 0) {
|
|
333
|
+
this.runIdToName.delete(runId);
|
|
334
|
+
}
|
|
335
|
+
if (!this.onTrajectory) {
|
|
336
|
+
if (inFlight.pendingTools === 0) {
|
|
337
|
+
// Already cleaned up; nothing more to do.
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
// Caller does not care about the trajectory, just the tool events.
|
|
341
|
+
// No pending dispatch needed; the tool-callback path will clean up
|
|
342
|
+
// the chain entry when pending hits 0.
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
const entry = this.resolved.get(inFlight.nodeName);
|
|
164
346
|
if (!entry)
|
|
165
347
|
return;
|
|
166
348
|
if (outputs === null || typeof outputs !== "object")
|
|
167
349
|
return;
|
|
168
|
-
const
|
|
169
|
-
if (!isExecutionTrace(
|
|
350
|
+
const trajectoryRaw = outputs[entry.trajectoryKey];
|
|
351
|
+
if (!isExecutionTrace(trajectoryRaw))
|
|
170
352
|
return;
|
|
353
|
+
// V0.4 (S1235): size-guard. Run JSON.stringify ONCE and reuse its
|
|
354
|
+
// length for the cap test — the result is discarded, we never log
|
|
355
|
+
// raw payloads. JSON.stringify can throw on circular refs / BigInt
|
|
356
|
+
// / Symbol values; defensive catch keeps the hook robust regardless.
|
|
357
|
+
let serialisedSize = 0;
|
|
358
|
+
try {
|
|
359
|
+
serialisedSize = JSON.stringify(trajectoryRaw).length;
|
|
360
|
+
}
|
|
361
|
+
catch {
|
|
362
|
+
// Unserialisable trajectories are themselves a signal worth
|
|
363
|
+
// surfacing — treat as oversized so consumers see the replacement.
|
|
364
|
+
serialisedSize = Number.POSITIVE_INFINITY;
|
|
365
|
+
}
|
|
366
|
+
let trajectory = trajectoryRaw;
|
|
367
|
+
let trajectoryTruncated = false;
|
|
368
|
+
if (this.maxTrajectoryBytes !== Infinity &&
|
|
369
|
+
serialisedSize > this.maxTrajectoryBytes) {
|
|
370
|
+
trajectory = buildTruncatedTrace(trajectoryRaw);
|
|
371
|
+
trajectoryTruncated = true;
|
|
372
|
+
if (!this.trajectoryTruncatedWarned) {
|
|
373
|
+
this.trajectoryTruncatedWarned = true;
|
|
374
|
+
console.warn(`[darwin-langgraph] DarwinCallbackHandler: trajectory for ` +
|
|
375
|
+
`"${inFlight.nodeName}" was ${serialisedSize} bytes — exceeded ` +
|
|
376
|
+
`${this.maxTrajectoryBytes} byte cap. Emitting structurally-` +
|
|
377
|
+
`compatible minimal stub with the original counts preserved. ` +
|
|
378
|
+
`Set DarwinCallbackHandlerOptions.maxTrajectoryBytes to raise ` +
|
|
379
|
+
`the cap or Infinity to opt out. Subsequent truncations are silent.`);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
171
382
|
const frozen = Object.freeze({ ...outputs });
|
|
383
|
+
// V0.3 (S1187): propagate runId + parentRunId so OTEL exporters,
|
|
384
|
+
// Langfuse, LangSmith, etc. can rebuild the span hierarchy from the
|
|
385
|
+
// event payload alone (no separate runId-tracking side-channel).
|
|
172
386
|
const event = {
|
|
173
|
-
nodeName:
|
|
387
|
+
nodeName: inFlight.nodeName,
|
|
174
388
|
agentName: entry.agentName,
|
|
175
389
|
trajectory,
|
|
176
390
|
finalState: frozen,
|
|
391
|
+
runId,
|
|
392
|
+
...(inFlight.parentRunId !== undefined ? { parentRunId: inFlight.parentRunId } : {}),
|
|
393
|
+
...(trajectoryTruncated ? { trajectoryTruncated: true } : {}),
|
|
177
394
|
};
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
395
|
+
const dispatch = () => {
|
|
396
|
+
void Promise.resolve()
|
|
397
|
+
.then(() => this.onTrajectory(event))
|
|
398
|
+
.catch((err) => this.swallow(err));
|
|
399
|
+
};
|
|
400
|
+
if (inFlight.pendingTools > 0) {
|
|
401
|
+
// V0.4 (R1 P1-4 fix): defer the dispatch until all tool events
|
|
402
|
+
// have surfaced so consumers see tool spans BEFORE the agent span
|
|
403
|
+
// closes. The last tool callback drains this map.
|
|
404
|
+
this.pendingTrajectoryDispatch.set(runId, dispatch);
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
dispatch();
|
|
408
|
+
}
|
|
183
409
|
}
|
|
184
410
|
/**
|
|
185
411
|
* Forget the in-flight runId when a chain errors out. We don't fire
|
|
186
412
|
* the hook on error — the trajectory is by definition incomplete.
|
|
187
413
|
*/
|
|
188
414
|
handleChainError(_err, runId, _parentRunId) {
|
|
415
|
+
// V0.4 (R1 P1-4): on error we discard pending trajectory dispatch —
|
|
416
|
+
// an errored chain has no complete trajectory by definition.
|
|
189
417
|
this.runIdToName.delete(runId);
|
|
418
|
+
this.pendingTrajectoryDispatch.delete(runId);
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* V0.4 (S1235) — tool-chain start event. LangGraph fires `handleToolStart`
|
|
422
|
+
* for every tool-invocation a node performs (whether via `ToolNode`,
|
|
423
|
+
* `createReactAgent`, or a custom tool-call dispatcher). We use the
|
|
424
|
+
* `parentRunId` slot to associate the tool with the tracking node and
|
|
425
|
+
* emit a `DarwinToolEvent` so consumers can build per-tool OTEL spans
|
|
426
|
+
* or progress UIs.
|
|
427
|
+
*
|
|
428
|
+
* If `parentRunId` is missing OR the parent is not a tracked node, the
|
|
429
|
+
* tool event is silently dropped — the handler never surfaces unmapped
|
|
430
|
+
* activity (consistent with the chain-side `resolved.has(nodeName)` gate).
|
|
431
|
+
*/
|
|
432
|
+
handleToolStart(_tool, input, runId, parentRunId, _tags, _metadata, _runType, name) {
|
|
433
|
+
if (typeof parentRunId !== "string")
|
|
434
|
+
return;
|
|
435
|
+
const inFlight = this.runIdToName.get(parentRunId);
|
|
436
|
+
if (!inFlight)
|
|
437
|
+
return;
|
|
438
|
+
const entry = this.resolved.get(inFlight.nodeName);
|
|
439
|
+
if (!entry)
|
|
440
|
+
return;
|
|
441
|
+
const toolName = typeof name === "string" && name.length > 0 ? name : "<anonymous-tool>";
|
|
442
|
+
// V0.4 (R1 P1-1 fix): cache the tool name keyed by tool runId so
|
|
443
|
+
// `handleToolEnd` / `handleToolError` can recover it. The LangChain
|
|
444
|
+
// tool-end signature does NOT carry the name reliably across versions.
|
|
445
|
+
if (this.maxInFlightToolRuns !== Infinity && !this.toolRunIdToName.has(runId)) {
|
|
446
|
+
if (this.toolRunIdToName.size >= this.maxInFlightToolRuns) {
|
|
447
|
+
const oldest = this.toolRunIdToName.keys().next().value;
|
|
448
|
+
if (oldest !== undefined)
|
|
449
|
+
this.toolRunIdToName.delete(oldest);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
this.toolRunIdToName.set(runId, toolName);
|
|
453
|
+
// V0.4 (R1 P1-4 fix): increment pending-tools counter on the chain
|
|
454
|
+
// so `handleChainEnd` knows to defer trajectory dispatch.
|
|
455
|
+
inFlight.pendingTools++;
|
|
456
|
+
if (!this.onToolEvent)
|
|
457
|
+
return;
|
|
458
|
+
const event = {
|
|
459
|
+
nodeName: inFlight.nodeName,
|
|
460
|
+
agentName: entry.agentName,
|
|
461
|
+
toolName,
|
|
462
|
+
phase: "start",
|
|
463
|
+
runId,
|
|
464
|
+
parentRunId,
|
|
465
|
+
...(typeof input === "string" ? { input } : {}),
|
|
466
|
+
};
|
|
467
|
+
this.dispatchToolEvent(event);
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* V0.4 (S1235) — tool-chain end event.
|
|
471
|
+
*/
|
|
472
|
+
handleToolEnd(output, runId, parentRunId) {
|
|
473
|
+
if (typeof parentRunId !== "string")
|
|
474
|
+
return;
|
|
475
|
+
const inFlight = this.runIdToName.get(parentRunId);
|
|
476
|
+
if (!inFlight) {
|
|
477
|
+
// Pending-tools counter is gone with the chain — best-effort
|
|
478
|
+
// cleanup of the tool-name cache only.
|
|
479
|
+
this.toolRunIdToName.delete(runId);
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
const entry = this.resolved.get(inFlight.nodeName);
|
|
483
|
+
if (!entry) {
|
|
484
|
+
this.toolRunIdToName.delete(runId);
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
// V0.4 (R1 P1-1 fix): recover the tool name from the cache populated
|
|
488
|
+
// at `handleToolStart`. Fall back to inspecting `output.name` for
|
|
489
|
+
// adversarial cases where start was missed (eg LangChain version
|
|
490
|
+
// mismatch). Both paths preserve the start/end name symmetry that
|
|
491
|
+
// older revisions broke.
|
|
492
|
+
let toolName = this.toolRunIdToName.get(runId);
|
|
493
|
+
if (!toolName) {
|
|
494
|
+
if (output && typeof output === "object" && "name" in output) {
|
|
495
|
+
const n = output.name;
|
|
496
|
+
if (typeof n === "string" && n.length > 0)
|
|
497
|
+
toolName = n;
|
|
498
|
+
}
|
|
499
|
+
if (!toolName)
|
|
500
|
+
toolName = "<anonymous-tool>";
|
|
501
|
+
}
|
|
502
|
+
this.toolRunIdToName.delete(runId);
|
|
503
|
+
if (this.onToolEvent) {
|
|
504
|
+
const event = {
|
|
505
|
+
nodeName: inFlight.nodeName,
|
|
506
|
+
agentName: entry.agentName,
|
|
507
|
+
toolName,
|
|
508
|
+
phase: "end",
|
|
509
|
+
runId,
|
|
510
|
+
parentRunId,
|
|
511
|
+
output,
|
|
512
|
+
};
|
|
513
|
+
this.dispatchToolEvent(event);
|
|
514
|
+
}
|
|
515
|
+
// V0.4 (R1 P1-4 fix): decrement pending counter and drain the
|
|
516
|
+
// deferred trajectory dispatch if this was the last tool AND
|
|
517
|
+
// handleChainEnd had already fired.
|
|
518
|
+
inFlight.pendingTools = Math.max(0, inFlight.pendingTools - 1);
|
|
519
|
+
if (inFlight.finalized && inFlight.pendingTools === 0) {
|
|
520
|
+
const dispatch = this.pendingTrajectoryDispatch.get(parentRunId);
|
|
521
|
+
if (dispatch) {
|
|
522
|
+
this.pendingTrajectoryDispatch.delete(parentRunId);
|
|
523
|
+
dispatch();
|
|
524
|
+
}
|
|
525
|
+
this.runIdToName.delete(parentRunId);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* V0.4 (S1235) — tool-chain error event.
|
|
530
|
+
*/
|
|
531
|
+
handleToolError(err, runId, parentRunId) {
|
|
532
|
+
if (typeof parentRunId !== "string")
|
|
533
|
+
return;
|
|
534
|
+
const inFlight = this.runIdToName.get(parentRunId);
|
|
535
|
+
if (!inFlight) {
|
|
536
|
+
this.toolRunIdToName.delete(runId);
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
const entry = this.resolved.get(inFlight.nodeName);
|
|
540
|
+
if (!entry) {
|
|
541
|
+
this.toolRunIdToName.delete(runId);
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
// V0.4 (R1 P1-1 fix): recover the tool name from the cache.
|
|
545
|
+
const toolName = this.toolRunIdToName.get(runId) ?? "<anonymous-tool>";
|
|
546
|
+
this.toolRunIdToName.delete(runId);
|
|
547
|
+
if (this.onToolEvent) {
|
|
548
|
+
const event = {
|
|
549
|
+
nodeName: inFlight.nodeName,
|
|
550
|
+
agentName: entry.agentName,
|
|
551
|
+
toolName,
|
|
552
|
+
phase: "error",
|
|
553
|
+
runId,
|
|
554
|
+
parentRunId,
|
|
555
|
+
error: err instanceof Error ? err : new Error(String(err)),
|
|
556
|
+
};
|
|
557
|
+
this.dispatchToolEvent(event);
|
|
558
|
+
}
|
|
559
|
+
// V0.4 (R1 P1-4 fix): mirror the pending-count drain from handleToolEnd.
|
|
560
|
+
inFlight.pendingTools = Math.max(0, inFlight.pendingTools - 1);
|
|
561
|
+
if (inFlight.finalized && inFlight.pendingTools === 0) {
|
|
562
|
+
const dispatch = this.pendingTrajectoryDispatch.get(parentRunId);
|
|
563
|
+
if (dispatch) {
|
|
564
|
+
this.pendingTrajectoryDispatch.delete(parentRunId);
|
|
565
|
+
dispatch();
|
|
566
|
+
}
|
|
567
|
+
this.runIdToName.delete(parentRunId);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
dispatchToolEvent(event) {
|
|
571
|
+
void Promise.resolve()
|
|
572
|
+
.then(() => this.onToolEvent(event))
|
|
573
|
+
.catch((err) => this.swallowTool(err));
|
|
190
574
|
}
|
|
191
575
|
swallow(err) {
|
|
192
576
|
// R1 V0.2 Critic Finding 5 (S1185): do NOT short-circuit on falsy
|
|
@@ -199,6 +583,14 @@ export class DarwinCallbackHandler extends BaseCallbackHandler {
|
|
|
199
583
|
`Subsequent throws will be silent. Original error: ` +
|
|
200
584
|
`${err instanceof Error ? err.message : String(err)}`);
|
|
201
585
|
}
|
|
586
|
+
swallowTool(err) {
|
|
587
|
+
if (this.toolWarned)
|
|
588
|
+
return;
|
|
589
|
+
this.toolWarned = true;
|
|
590
|
+
console.warn(`[darwin-langgraph] DarwinCallbackHandler.onToolEvent threw — swallowed. ` +
|
|
591
|
+
`Subsequent throws will be silent. Original error: ` +
|
|
592
|
+
`${err instanceof Error ? err.message : String(err)}`);
|
|
593
|
+
}
|
|
202
594
|
/**
|
|
203
595
|
* Helper for tests + debug introspection — returns how many in-flight
|
|
204
596
|
* chain runs we are currently tracking. Should be 0 between
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"darwin-callback-handler.js","sourceRoot":"","sources":["../src/darwin-callback-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAIrE,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAgBvD,SAAS,gBAAgB,CAAC,KAAc;IACtC,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACtD,MAAM,CAAC,GAAG,KAAqE,CAAC;IAChF,sEAAsE;IACtE,6DAA6D;IAC7D,sEAAsE;IACtE,uCAAuC;IACvC,OAAO,CACL,CAAC,CAAC,OAAO,KAAK,CAAC;QACf,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CACxB,CAAC;AACJ,CAAC;AAED,SAAS,gBAAgB,CACvB,OAA2C,EAC3C,UAAkB;IAElB,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAgC,CAAC;IACzD,KAAK,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACxD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAA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CACV,2EAA2E;YACzE,oDAAoD;YACpD,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CACxD,CAAC;IACJ,CAAC;IAEO,WAAW,CAAC,GAAY;QAC9B,IAAI,IAAI,CAAC,UAAU;YAAE,OAAO;QAC5B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,OAAO,CAAC,IAAI,CACV,0EAA0E;YACxE,oDAAoD;YACpD,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CACxD,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACI,gBAAgB;QACrB,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IAC/B,CAAC;CACF"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -19,4 +19,20 @@ export declare class DarwinEvolutionHookError extends Error {
|
|
|
19
19
|
cause?: unknown;
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Thrown by `createTokenBudgetCallbacks` when a configured per-invocation
|
|
24
|
+
* token budget is exceeded. The handler attaches the cumulative tokens
|
|
25
|
+
* counted at the moment of the throw so consumers can log / alert.
|
|
26
|
+
*
|
|
27
|
+
* NEW V0.4 (S1235).
|
|
28
|
+
*/
|
|
29
|
+
export declare class DarwinTokenBudgetExceededError extends Error {
|
|
30
|
+
readonly budget: number;
|
|
31
|
+
readonly totalTokens: number;
|
|
32
|
+
readonly providerHint: string | undefined;
|
|
33
|
+
readonly name = "DarwinTokenBudgetExceededError";
|
|
34
|
+
constructor(message: string, budget: number, totalTokens: number, providerHint: string | undefined, options?: {
|
|
35
|
+
cause?: unknown;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
22
38
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,qBAAa,eAAgB,SAAQ,KAAK;aAKtB,SAAS,EAAE,MAAM;IAJnC,SAAyB,IAAI,qBAAqB;gBAGhD,OAAO,EAAE,MAAM,EACC,SAAS,EAAE,MAAM,EACjC,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAIhC;AAED,qBAAa,wBAAyB,SAAQ,KAAK;IACjD,SAAyB,IAAI,8BAA8B;gBAE/C,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAG3D"}
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,qBAAa,eAAgB,SAAQ,KAAK;aAKtB,SAAS,EAAE,MAAM;IAJnC,SAAyB,IAAI,qBAAqB;gBAGhD,OAAO,EAAE,MAAM,EACC,SAAS,EAAE,MAAM,EACjC,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAIhC;AAED,qBAAa,wBAAyB,SAAQ,KAAK;IACjD,SAAyB,IAAI,8BAA8B;gBAE/C,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAG3D;AAED;;;;;;GAMG;AACH,qBAAa,8BAA+B,SAAQ,KAAK;aAKrC,MAAM,EAAE,MAAM;aACd,WAAW,EAAE,MAAM;aACnB,YAAY,EAAE,MAAM,GAAG,SAAS;IANlD,SAAyB,IAAI,oCAAoC;gBAG/D,OAAO,EAAE,MAAM,EACC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,GAAG,SAAS,EAChD,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAIhC"}
|
package/dist/errors.js
CHANGED
|
@@ -20,4 +20,23 @@ export class DarwinEvolutionHookError extends Error {
|
|
|
20
20
|
super(message, options);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Thrown by `createTokenBudgetCallbacks` when a configured per-invocation
|
|
25
|
+
* token budget is exceeded. The handler attaches the cumulative tokens
|
|
26
|
+
* counted at the moment of the throw so consumers can log / alert.
|
|
27
|
+
*
|
|
28
|
+
* NEW V0.4 (S1235).
|
|
29
|
+
*/
|
|
30
|
+
export class DarwinTokenBudgetExceededError extends Error {
|
|
31
|
+
budget;
|
|
32
|
+
totalTokens;
|
|
33
|
+
providerHint;
|
|
34
|
+
name = "DarwinTokenBudgetExceededError";
|
|
35
|
+
constructor(message, budget, totalTokens, providerHint, options) {
|
|
36
|
+
super(message, options);
|
|
37
|
+
this.budget = budget;
|
|
38
|
+
this.totalTokens = totalTokens;
|
|
39
|
+
this.providerHint = providerHint;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
23
42
|
//# sourceMappingURL=errors.js.map
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAKtB;IAJO,IAAI,GAAG,iBAAiB,CAAC;IAElD,YACE,OAAe,EACC,SAAiB,EACjC,OAA6B;QAE7B,KAAK,CAAC,OAAO,EAAE,OAAuB,CAAC,CAAC;QAHxB,cAAS,GAAT,SAAS,CAAQ;IAInC,CAAC;CACF;AAED,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACxB,IAAI,GAAG,0BAA0B,CAAC;IAE3D,YAAY,OAAe,EAAE,OAA6B;QACxD,KAAK,CAAC,OAAO,EAAE,OAAuB,CAAC,CAAC;IAC1C,CAAC;CACF"}
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAKtB;IAJO,IAAI,GAAG,iBAAiB,CAAC;IAElD,YACE,OAAe,EACC,SAAiB,EACjC,OAA6B;QAE7B,KAAK,CAAC,OAAO,EAAE,OAAuB,CAAC,CAAC;QAHxB,cAAS,GAAT,SAAS,CAAQ;IAInC,CAAC;CACF;AAED,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACxB,IAAI,GAAG,0BAA0B,CAAC;IAE3D,YAAY,OAAe,EAAE,OAA6B;QACxD,KAAK,CAAC,OAAO,EAAE,OAAuB,CAAC,CAAC;IAC1C,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,OAAO,8BAA+B,SAAQ,KAAK;IAKrC;IACA;IACA;IANO,IAAI,GAAG,gCAAgC,CAAC;IAEjE,YACE,OAAe,EACC,MAAc,EACd,WAAmB,EACnB,YAAgC,EAChD,OAA6B;QAE7B,KAAK,CAAC,OAAO,EAAE,OAAuB,CAAC,CAAC;QALxB,WAAM,GAAN,MAAM,CAAQ;QACd,gBAAW,GAAX,WAAW,CAAQ;QACnB,iBAAY,GAAZ,YAAY,CAAoB;IAIlD,CAAC;CACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -40,11 +40,15 @@
|
|
|
40
40
|
export { createDarwinNode, type CreateDarwinNodeOptions, type DarwinNodeFn, type DarwinRunOptionsPassthrough, } from "./create-darwin-node.js";
|
|
41
41
|
export { darwinAnnotation, getDarwinChannelSpec, lastWriteWinsTrajectoryReducer, } from "./darwin-annotation.js";
|
|
42
42
|
export { withDarwinEvolution, type DarwinEvolutionOptions, type DarwinNodeMapEntry, type DarwinTrajectoryEvent, } from "./with-darwin-evolution.js";
|
|
43
|
-
export { DarwinCallbackHandler } from "./darwin-callback-handler.js";
|
|
43
|
+
export { DarwinCallbackHandler, MAX_KNOWN_TRACE_VERSION, type DarwinCallbackHandlerOptions, type DarwinToolEvent, } from "./darwin-callback-handler.js";
|
|
44
44
|
export { toOtelAttributes, toolCallToOtelAttributes, type OtelAttributes, type ToOtelAttributesOptions, type ToolCallOtelOptions, } from "./to-otel-attributes.js";
|
|
45
45
|
export { darwinMessagesAnnotation, getMessagesChannelSpec, } from "./darwin-messages-annotation.js";
|
|
46
|
-
export {
|
|
46
|
+
export { darwinAccumulatingAnnotation, getDarwinAccumulatingChannelSpec, darwinTrajectoryAccumulatorReducer, } from "./darwin-accumulating-annotation.js";
|
|
47
|
+
export { TokenBudgetCallbackHandler, createTokenBudgetCallbacks, type TokenBudgetOptions, type TokenBudgetExceedInfo, type TokenBudgetTickInfo, } from "./token-budget.js";
|
|
48
|
+
export { toW3CTraceContext, type ToW3CTraceContextOptions, type W3CTraceContext, } from "./to-w3c-trace-context.js";
|
|
49
|
+
export type { DarwinNodeAttemptInfo } from "./create-darwin-node.js";
|
|
50
|
+
export { DarwinNodeError, DarwinEvolutionHookError, DarwinTokenBudgetExceededError, } from "./errors.js";
|
|
47
51
|
export type { AgentDefinition, DarwinExperiment, ExecutionTrace, MemoryProvider, RunResult, TraceToolCall, TraceTokenUsage, TraceTurnError, } from "./types.js";
|
|
48
52
|
/** Adapter version — sync with `package.json` on every release. */
|
|
49
|
-
export declare const VERSION = "0.
|
|
53
|
+
export declare const VERSION = "0.4.0-alpha.1";
|
|
50
54
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,OAAO,EACL,gBAAgB,EAChB,KAAK,uBAAuB,EAC5B,KAAK,YAAY,EACjB,KAAK,2BAA2B,GACjC,MAAM,yBAAyB,CAAC;AAEjC,OAAO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