@raindrop-ai/deep-agents 0.0.5 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -60,6 +60,7 @@ type Patch = {
60
60
  output?: string;
61
61
  model?: string;
62
62
  properties?: Record<string, unknown>;
63
+ featureFlags?: Record<string, string>;
63
64
  attachments?: Attachment[];
64
65
  isPending?: boolean;
65
66
  timestamp?: string;
@@ -160,6 +161,7 @@ declare class EventShipper {
160
161
  output?: string;
161
162
  model?: string;
162
163
  properties?: Record<string, unknown>;
164
+ featureFlags?: Record<string, string>;
163
165
  userId?: string;
164
166
  }): Promise<void>;
165
167
  flush(): Promise<void>;
@@ -364,6 +366,42 @@ declare class TraceShipper {
364
366
  shutdown(): Promise<void>;
365
367
  }
366
368
 
369
+ /**
370
+ * Run telemetry egress with OpenTelemetry tracing suppressed.
371
+ *
372
+ * Why this exists
373
+ * ---------------
374
+ * Raindrop integrations ship spans/events over HTTP with the global `fetch`
375
+ * (see {@link ../http.ts `postJson`}). When the host app also runs an OTel
376
+ * fetch/undici instrumentation — e.g. `@vercel/otel`'s `registerOTel`, which
377
+ * every Eve agent installs — that instrumentation wraps *our own* telemetry
378
+ * POSTs in a `fetch POST <endpoint>` span. Those spans are then handed to the
379
+ * very exporter that issued the request, so they get shipped right back to
380
+ * Raindrop and Workshop as standalone "runs" (and, because each export issues
381
+ * another fetch, they feed back on themselves). The result is a run list
382
+ * flooded with `fetch POST .../v1/traces`, `.../events/track_partial` and
383
+ * `.../live` entries that drown out the real agent turns — especially with
384
+ * sub-agents, where every sandbox runs its own instrumentation.
385
+ *
386
+ * The OTel-blessed fix is to mark the active context as "tracing suppressed"
387
+ * around the request; instrumentations check `isTracingSuppressed` and return
388
+ * a no-op span instead of recording one. We do this through a hook stashed on
389
+ * `globalThis` by the Node entrypoint ({@link ../index.node.ts}) so that:
390
+ * - `@opentelemetry/api` / `@opentelemetry/core` stay *optional* — core never
391
+ * hard-depends on them, and the hook is simply absent when they (and thus
392
+ * any instrumentation to suppress) are not installed; and
393
+ * - the browser bundle never pulls in `node:module`, mirroring how core
394
+ * injects `AsyncLocalStorage` via `RAINDROP_ASYNC_LOCAL_STORAGE`.
395
+ *
396
+ * When no hook is present the callback runs unchanged, so suppression is a
397
+ * best-effort no-op rather than a hard requirement.
398
+ */
399
+ /** Hook signature: run `fn` with OTel tracing suppressed, returning its value. */
400
+ type SuppressTracingHook = <T>(fn: () => T) => T;
401
+ declare global {
402
+ var RAINDROP_SUPPRESS_TRACING: SuppressTracingHook | undefined;
403
+ }
404
+
367
405
  type ParentSpanContext = {
368
406
  traceIdB64: string;
369
407
  spanIdB64: string;
@@ -396,6 +434,8 @@ interface RaindropDeepAgentsHandlerOptions {
396
434
  traceShipper: TraceShipper;
397
435
  userId?: string;
398
436
  convoId?: string;
437
+ eventName?: string;
438
+ eventId?: () => string;
399
439
  traceChains?: boolean;
400
440
  }
401
441
  declare class RaindropDeepAgentsHandler extends BaseCallbackHandler {
@@ -404,6 +444,8 @@ declare class RaindropDeepAgentsHandler extends BaseCallbackHandler {
404
444
  private traceShipper;
405
445
  private userId?;
406
446
  private convoId?;
447
+ private eventName?;
448
+ private eventIdSource?;
407
449
  private traceChains;
408
450
  private spans;
409
451
  private rootRunIds;
@@ -445,6 +487,18 @@ interface DeepAgentsOptions {
445
487
  debug?: boolean;
446
488
  userId?: string;
447
489
  convoId?: string;
490
+ /**
491
+ * Event name stamped on every captured event, replacing core's hardcoded
492
+ * `"ai_generation"` default (DEV-1167).
493
+ */
494
+ eventName?: string;
495
+ /**
496
+ * Per-call event-id source, invoked once per captured root agent invocation
497
+ * to mint that event's id (and the linked spans' id), replacing the
498
+ * handler-minted UUID (DEV-1174). A throwing/empty/absent source falls back
499
+ * to a random UUID, so telemetry never crashes the caller.
500
+ */
501
+ eventId?: () => string;
448
502
  /**
449
503
  * Optional Raindrop project slug. When set, every outbound cloud request
450
504
  * carries an `X-Raindrop-Project-Id` header. Unset → no header (the project
package/dist/index.d.ts CHANGED
@@ -60,6 +60,7 @@ type Patch = {
60
60
  output?: string;
61
61
  model?: string;
62
62
  properties?: Record<string, unknown>;
63
+ featureFlags?: Record<string, string>;
63
64
  attachments?: Attachment[];
64
65
  isPending?: boolean;
65
66
  timestamp?: string;
@@ -160,6 +161,7 @@ declare class EventShipper {
160
161
  output?: string;
161
162
  model?: string;
162
163
  properties?: Record<string, unknown>;
164
+ featureFlags?: Record<string, string>;
163
165
  userId?: string;
164
166
  }): Promise<void>;
165
167
  flush(): Promise<void>;
@@ -364,6 +366,42 @@ declare class TraceShipper {
364
366
  shutdown(): Promise<void>;
365
367
  }
366
368
 
369
+ /**
370
+ * Run telemetry egress with OpenTelemetry tracing suppressed.
371
+ *
372
+ * Why this exists
373
+ * ---------------
374
+ * Raindrop integrations ship spans/events over HTTP with the global `fetch`
375
+ * (see {@link ../http.ts `postJson`}). When the host app also runs an OTel
376
+ * fetch/undici instrumentation — e.g. `@vercel/otel`'s `registerOTel`, which
377
+ * every Eve agent installs — that instrumentation wraps *our own* telemetry
378
+ * POSTs in a `fetch POST <endpoint>` span. Those spans are then handed to the
379
+ * very exporter that issued the request, so they get shipped right back to
380
+ * Raindrop and Workshop as standalone "runs" (and, because each export issues
381
+ * another fetch, they feed back on themselves). The result is a run list
382
+ * flooded with `fetch POST .../v1/traces`, `.../events/track_partial` and
383
+ * `.../live` entries that drown out the real agent turns — especially with
384
+ * sub-agents, where every sandbox runs its own instrumentation.
385
+ *
386
+ * The OTel-blessed fix is to mark the active context as "tracing suppressed"
387
+ * around the request; instrumentations check `isTracingSuppressed` and return
388
+ * a no-op span instead of recording one. We do this through a hook stashed on
389
+ * `globalThis` by the Node entrypoint ({@link ../index.node.ts}) so that:
390
+ * - `@opentelemetry/api` / `@opentelemetry/core` stay *optional* — core never
391
+ * hard-depends on them, and the hook is simply absent when they (and thus
392
+ * any instrumentation to suppress) are not installed; and
393
+ * - the browser bundle never pulls in `node:module`, mirroring how core
394
+ * injects `AsyncLocalStorage` via `RAINDROP_ASYNC_LOCAL_STORAGE`.
395
+ *
396
+ * When no hook is present the callback runs unchanged, so suppression is a
397
+ * best-effort no-op rather than a hard requirement.
398
+ */
399
+ /** Hook signature: run `fn` with OTel tracing suppressed, returning its value. */
400
+ type SuppressTracingHook = <T>(fn: () => T) => T;
401
+ declare global {
402
+ var RAINDROP_SUPPRESS_TRACING: SuppressTracingHook | undefined;
403
+ }
404
+
367
405
  type ParentSpanContext = {
368
406
  traceIdB64: string;
369
407
  spanIdB64: string;
@@ -396,6 +434,8 @@ interface RaindropDeepAgentsHandlerOptions {
396
434
  traceShipper: TraceShipper;
397
435
  userId?: string;
398
436
  convoId?: string;
437
+ eventName?: string;
438
+ eventId?: () => string;
399
439
  traceChains?: boolean;
400
440
  }
401
441
  declare class RaindropDeepAgentsHandler extends BaseCallbackHandler {
@@ -404,6 +444,8 @@ declare class RaindropDeepAgentsHandler extends BaseCallbackHandler {
404
444
  private traceShipper;
405
445
  private userId?;
406
446
  private convoId?;
447
+ private eventName?;
448
+ private eventIdSource?;
407
449
  private traceChains;
408
450
  private spans;
409
451
  private rootRunIds;
@@ -445,6 +487,18 @@ interface DeepAgentsOptions {
445
487
  debug?: boolean;
446
488
  userId?: string;
447
489
  convoId?: string;
490
+ /**
491
+ * Event name stamped on every captured event, replacing core's hardcoded
492
+ * `"ai_generation"` default (DEV-1167).
493
+ */
494
+ eventName?: string;
495
+ /**
496
+ * Per-call event-id source, invoked once per captured root agent invocation
497
+ * to mint that event's id (and the linked spans' id), replacing the
498
+ * handler-minted UUID (DEV-1174). A throwing/empty/absent source falls back
499
+ * to a random UUID, so telemetry never crashes the caller.
500
+ */
501
+ eventId?: () => string;
448
502
  /**
449
503
  * Optional Raindrop project slug. When set, every outbound cloud request
450
504
  * carries an `X-Raindrop-Project-Id` header. Unset → no header (the project
package/dist/index.js CHANGED
@@ -28,7 +28,7 @@ module.exports = __toCommonJS(index_exports);
28
28
  // src/callback-handler.ts
29
29
  var import_base = require("@langchain/core/callbacks/base");
30
30
 
31
- // ../core/dist/chunk-SK6EJEO7.js
31
+ // ../core/dist/chunk-267IXHO5.js
32
32
  function getCrypto() {
33
33
  const c = globalThis.crypto;
34
34
  return c;
@@ -83,6 +83,20 @@ function base64Encode(bytes) {
83
83
  }
84
84
  return out;
85
85
  }
86
+ function runWithTracingSuppressed(fn) {
87
+ const hook = globalThis.RAINDROP_SUPPRESS_TRACING;
88
+ if (typeof hook !== "function") return fn();
89
+ let started = false;
90
+ try {
91
+ return hook(() => {
92
+ started = true;
93
+ return fn();
94
+ });
95
+ } catch (err) {
96
+ if (started) throw err;
97
+ return fn();
98
+ }
99
+ }
86
100
  var DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
87
101
  var MAX_RETRY_DELAY_MS = 3e4;
88
102
  function wait(ms) {
@@ -193,15 +207,17 @@ async function postJson(url, body, headers, opts) {
193
207
  const timeoutMs = (_a = opts.timeoutMs) != null ? _a : DEFAULT_REQUEST_TIMEOUT_MS;
194
208
  await withRetry(
195
209
  async () => {
196
- const resp = await fetch(url, {
197
- method: "POST",
198
- headers: {
199
- "Content-Type": "application/json",
200
- ...headers
201
- },
202
- body: JSON.stringify(body),
203
- signal: AbortSignal.timeout(timeoutMs)
204
- });
210
+ const resp = await runWithTracingSuppressed(
211
+ () => fetch(url, {
212
+ method: "POST",
213
+ headers: {
214
+ "Content-Type": "application/json",
215
+ ...headers
216
+ },
217
+ body: JSON.stringify(body),
218
+ signal: AbortSignal.timeout(timeoutMs)
219
+ })
220
+ );
205
221
  if (!resp.ok) {
206
222
  const text = await resp.text().catch(() => "");
207
223
  const err = new Error(
@@ -402,13 +418,16 @@ function projectIdHeaders(projectId) {
402
418
  var SHUTDOWN_DEADLINE_MS = 1e4;
403
419
  var POST_SHUTDOWN_TIMEOUT_MS = 5e3;
404
420
  function mergePatches(target, source) {
405
- var _a, _b, _c, _d;
421
+ var _a, _b, _c, _d, _e, _f;
406
422
  const out = { ...target, ...source };
407
423
  if (target.properties || source.properties) {
408
424
  out.properties = { ...(_a = target.properties) != null ? _a : {}, ...(_b = source.properties) != null ? _b : {} };
409
425
  }
426
+ if (target.featureFlags || source.featureFlags) {
427
+ out.featureFlags = { ...(_c = target.featureFlags) != null ? _c : {}, ...(_d = source.featureFlags) != null ? _d : {} };
428
+ }
410
429
  if (target.attachments || source.attachments) {
411
- out.attachments = [...(_c = target.attachments) != null ? _c : [], ...(_d = source.attachments) != null ? _d : []];
430
+ out.attachments = [...(_e = target.attachments) != null ? _e : [], ...(_f = source.attachments) != null ? _f : []];
412
431
  }
413
432
  return out;
414
433
  }
@@ -678,6 +697,7 @@ var EventShipper = class {
678
697
  ...wizardSession ? { "raindrop.wizardSession": wizardSession } : {},
679
698
  $context: this.context
680
699
  },
700
+ ...accumulated.featureFlags && Object.keys(accumulated.featureFlags).length > 0 ? { feature_flags: accumulated.featureFlags } : {},
681
701
  attachments: accumulated.attachments,
682
702
  is_pending: isPending
683
703
  };
@@ -1149,8 +1169,42 @@ var TraceShipper = class {
1149
1169
  // ../core/dist/index.node.js
1150
1170
  var import_async_hooks = require("async_hooks");
1151
1171
  globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = import_async_hooks.AsyncLocalStorage;
1172
+ var SUPPRESS_TRACING_KEY = /* @__PURE__ */ Symbol.for(
1173
+ "OpenTelemetry SDK Context Key SUPPRESS_TRACING"
1174
+ );
1175
+ function findOtelContextManager() {
1176
+ var _a;
1177
+ for (const sym of Object.getOwnPropertySymbols(globalThis)) {
1178
+ if (!((_a = sym.description) == null ? void 0 : _a.startsWith("opentelemetry.js.api."))) continue;
1179
+ const api = globalThis[sym];
1180
+ const cm = api == null ? void 0 : api.context;
1181
+ if (cm && typeof cm.with === "function" && typeof cm.active === "function") {
1182
+ return cm;
1183
+ }
1184
+ }
1185
+ return void 0;
1186
+ }
1187
+ function installTracingSuppressionHook() {
1188
+ if (typeof globalThis.RAINDROP_SUPPRESS_TRACING === "function") return;
1189
+ const hook = (fn) => {
1190
+ const cm = findOtelContextManager();
1191
+ if (!cm) return fn();
1192
+ return cm.with(cm.active().setValue(SUPPRESS_TRACING_KEY, true), fn);
1193
+ };
1194
+ globalThis.RAINDROP_SUPPRESS_TRACING = hook;
1195
+ }
1196
+ installTracingSuppressionHook();
1152
1197
 
1153
1198
  // src/callback-handler.ts
1199
+ function resolveEventId(source) {
1200
+ if (typeof source !== "function") return randomUUID();
1201
+ try {
1202
+ const id = source();
1203
+ return typeof id === "string" && id.trim() !== "" ? id : randomUUID();
1204
+ } catch {
1205
+ return randomUUID();
1206
+ }
1207
+ }
1154
1208
  function isInternalName(name) {
1155
1209
  if (name.startsWith("Branch:")) return true;
1156
1210
  if (name.startsWith("ChannelWrite")) return true;
@@ -1199,13 +1253,15 @@ var RaindropDeepAgentsHandler = class extends import_base.BaseCallbackHandler {
1199
1253
  this.traceShipper = opts.traceShipper;
1200
1254
  this.userId = opts.userId;
1201
1255
  this.convoId = opts.convoId;
1256
+ this.eventName = opts.eventName;
1257
+ this.eventIdSource = opts.eventId;
1202
1258
  this.traceChains = opts.traceChains ?? true;
1203
1259
  }
1204
1260
  getEventId(runId, parentRunId) {
1205
1261
  const rootId = parentRunId ? this.rootRunIds.get(parentRunId) ?? parentRunId : runId;
1206
1262
  this.rootRunIds.set(runId, rootId);
1207
1263
  if (!this.eventIds.has(rootId)) {
1208
- this.eventIds.set(rootId, randomUUID());
1264
+ this.eventIds.set(rootId, resolveEventId(this.eventIdSource));
1209
1265
  }
1210
1266
  return this.eventIds.get(rootId);
1211
1267
  }
@@ -1234,10 +1290,11 @@ var RaindropDeepAgentsHandler = class extends import_base.BaseCallbackHandler {
1234
1290
  const eventId = this.eventIds.get(rootId);
1235
1291
  if (!eventId) return;
1236
1292
  if (isRoot) {
1237
- if (this.convoId) {
1293
+ if (this.convoId || this.eventName) {
1238
1294
  await this.eventShipper.patch(eventId, {
1239
1295
  userId: this.userId,
1240
1296
  convoId: this.convoId,
1297
+ eventName: this.eventName,
1241
1298
  isPending: true
1242
1299
  });
1243
1300
  }
@@ -1246,6 +1303,7 @@ var RaindropDeepAgentsHandler = class extends import_base.BaseCallbackHandler {
1246
1303
  await this.eventShipper.patch(eventId, {
1247
1304
  userId: this.userId,
1248
1305
  convoId: this.convoId,
1306
+ eventName: this.eventName,
1249
1307
  ...patch,
1250
1308
  isPending: true
1251
1309
  });
@@ -1272,6 +1330,7 @@ var RaindropDeepAgentsHandler = class extends import_base.BaseCallbackHandler {
1272
1330
  await this.eventShipper.patch(eventId, {
1273
1331
  userId: this.userId,
1274
1332
  convoId: this.convoId,
1333
+ eventName: this.eventName,
1275
1334
  input: truncate(prompts.join("\n"), CHAIN_TEXT_MAX_LEN),
1276
1335
  properties: buildProperties(tags, metadata),
1277
1336
  isPending: true
@@ -1305,6 +1364,7 @@ var RaindropDeepAgentsHandler = class extends import_base.BaseCallbackHandler {
1305
1364
  await this.eventShipper.patch(eventId, {
1306
1365
  userId: this.userId,
1307
1366
  convoId: this.convoId,
1367
+ eventName: this.eventName,
1308
1368
  input: inputText,
1309
1369
  properties: buildProperties(tags, metadata),
1310
1370
  isPending: true
@@ -1724,6 +1784,8 @@ function createRaindropDeepAgents(opts) {
1724
1784
  traceShipper,
1725
1785
  userId: opts.userId,
1726
1786
  convoId: opts.convoId,
1787
+ eventName: opts.eventName,
1788
+ eventId: opts.eventId,
1727
1789
  traceChains: opts.traceChains
1728
1790
  });
1729
1791
  return {
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  // src/callback-handler.ts
2
2
  import { BaseCallbackHandler } from "@langchain/core/callbacks/base";
3
3
 
4
- // ../core/dist/chunk-SK6EJEO7.js
4
+ // ../core/dist/chunk-267IXHO5.js
5
5
  function getCrypto() {
6
6
  const c = globalThis.crypto;
7
7
  return c;
@@ -56,6 +56,20 @@ function base64Encode(bytes) {
56
56
  }
57
57
  return out;
58
58
  }
59
+ function runWithTracingSuppressed(fn) {
60
+ const hook = globalThis.RAINDROP_SUPPRESS_TRACING;
61
+ if (typeof hook !== "function") return fn();
62
+ let started = false;
63
+ try {
64
+ return hook(() => {
65
+ started = true;
66
+ return fn();
67
+ });
68
+ } catch (err) {
69
+ if (started) throw err;
70
+ return fn();
71
+ }
72
+ }
59
73
  var DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
60
74
  var MAX_RETRY_DELAY_MS = 3e4;
61
75
  function wait(ms) {
@@ -166,15 +180,17 @@ async function postJson(url, body, headers, opts) {
166
180
  const timeoutMs = (_a = opts.timeoutMs) != null ? _a : DEFAULT_REQUEST_TIMEOUT_MS;
167
181
  await withRetry(
168
182
  async () => {
169
- const resp = await fetch(url, {
170
- method: "POST",
171
- headers: {
172
- "Content-Type": "application/json",
173
- ...headers
174
- },
175
- body: JSON.stringify(body),
176
- signal: AbortSignal.timeout(timeoutMs)
177
- });
183
+ const resp = await runWithTracingSuppressed(
184
+ () => fetch(url, {
185
+ method: "POST",
186
+ headers: {
187
+ "Content-Type": "application/json",
188
+ ...headers
189
+ },
190
+ body: JSON.stringify(body),
191
+ signal: AbortSignal.timeout(timeoutMs)
192
+ })
193
+ );
178
194
  if (!resp.ok) {
179
195
  const text = await resp.text().catch(() => "");
180
196
  const err = new Error(
@@ -375,13 +391,16 @@ function projectIdHeaders(projectId) {
375
391
  var SHUTDOWN_DEADLINE_MS = 1e4;
376
392
  var POST_SHUTDOWN_TIMEOUT_MS = 5e3;
377
393
  function mergePatches(target, source) {
378
- var _a, _b, _c, _d;
394
+ var _a, _b, _c, _d, _e, _f;
379
395
  const out = { ...target, ...source };
380
396
  if (target.properties || source.properties) {
381
397
  out.properties = { ...(_a = target.properties) != null ? _a : {}, ...(_b = source.properties) != null ? _b : {} };
382
398
  }
399
+ if (target.featureFlags || source.featureFlags) {
400
+ out.featureFlags = { ...(_c = target.featureFlags) != null ? _c : {}, ...(_d = source.featureFlags) != null ? _d : {} };
401
+ }
383
402
  if (target.attachments || source.attachments) {
384
- out.attachments = [...(_c = target.attachments) != null ? _c : [], ...(_d = source.attachments) != null ? _d : []];
403
+ out.attachments = [...(_e = target.attachments) != null ? _e : [], ...(_f = source.attachments) != null ? _f : []];
385
404
  }
386
405
  return out;
387
406
  }
@@ -651,6 +670,7 @@ var EventShipper = class {
651
670
  ...wizardSession ? { "raindrop.wizardSession": wizardSession } : {},
652
671
  $context: this.context
653
672
  },
673
+ ...accumulated.featureFlags && Object.keys(accumulated.featureFlags).length > 0 ? { feature_flags: accumulated.featureFlags } : {},
654
674
  attachments: accumulated.attachments,
655
675
  is_pending: isPending
656
676
  };
@@ -1122,8 +1142,42 @@ var TraceShipper = class {
1122
1142
  // ../core/dist/index.node.js
1123
1143
  import { AsyncLocalStorage } from "async_hooks";
1124
1144
  globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = AsyncLocalStorage;
1145
+ var SUPPRESS_TRACING_KEY = /* @__PURE__ */ Symbol.for(
1146
+ "OpenTelemetry SDK Context Key SUPPRESS_TRACING"
1147
+ );
1148
+ function findOtelContextManager() {
1149
+ var _a;
1150
+ for (const sym of Object.getOwnPropertySymbols(globalThis)) {
1151
+ if (!((_a = sym.description) == null ? void 0 : _a.startsWith("opentelemetry.js.api."))) continue;
1152
+ const api = globalThis[sym];
1153
+ const cm = api == null ? void 0 : api.context;
1154
+ if (cm && typeof cm.with === "function" && typeof cm.active === "function") {
1155
+ return cm;
1156
+ }
1157
+ }
1158
+ return void 0;
1159
+ }
1160
+ function installTracingSuppressionHook() {
1161
+ if (typeof globalThis.RAINDROP_SUPPRESS_TRACING === "function") return;
1162
+ const hook = (fn) => {
1163
+ const cm = findOtelContextManager();
1164
+ if (!cm) return fn();
1165
+ return cm.with(cm.active().setValue(SUPPRESS_TRACING_KEY, true), fn);
1166
+ };
1167
+ globalThis.RAINDROP_SUPPRESS_TRACING = hook;
1168
+ }
1169
+ installTracingSuppressionHook();
1125
1170
 
1126
1171
  // src/callback-handler.ts
1172
+ function resolveEventId(source) {
1173
+ if (typeof source !== "function") return randomUUID();
1174
+ try {
1175
+ const id = source();
1176
+ return typeof id === "string" && id.trim() !== "" ? id : randomUUID();
1177
+ } catch {
1178
+ return randomUUID();
1179
+ }
1180
+ }
1127
1181
  function isInternalName(name) {
1128
1182
  if (name.startsWith("Branch:")) return true;
1129
1183
  if (name.startsWith("ChannelWrite")) return true;
@@ -1172,13 +1226,15 @@ var RaindropDeepAgentsHandler = class extends BaseCallbackHandler {
1172
1226
  this.traceShipper = opts.traceShipper;
1173
1227
  this.userId = opts.userId;
1174
1228
  this.convoId = opts.convoId;
1229
+ this.eventName = opts.eventName;
1230
+ this.eventIdSource = opts.eventId;
1175
1231
  this.traceChains = opts.traceChains ?? true;
1176
1232
  }
1177
1233
  getEventId(runId, parentRunId) {
1178
1234
  const rootId = parentRunId ? this.rootRunIds.get(parentRunId) ?? parentRunId : runId;
1179
1235
  this.rootRunIds.set(runId, rootId);
1180
1236
  if (!this.eventIds.has(rootId)) {
1181
- this.eventIds.set(rootId, randomUUID());
1237
+ this.eventIds.set(rootId, resolveEventId(this.eventIdSource));
1182
1238
  }
1183
1239
  return this.eventIds.get(rootId);
1184
1240
  }
@@ -1207,10 +1263,11 @@ var RaindropDeepAgentsHandler = class extends BaseCallbackHandler {
1207
1263
  const eventId = this.eventIds.get(rootId);
1208
1264
  if (!eventId) return;
1209
1265
  if (isRoot) {
1210
- if (this.convoId) {
1266
+ if (this.convoId || this.eventName) {
1211
1267
  await this.eventShipper.patch(eventId, {
1212
1268
  userId: this.userId,
1213
1269
  convoId: this.convoId,
1270
+ eventName: this.eventName,
1214
1271
  isPending: true
1215
1272
  });
1216
1273
  }
@@ -1219,6 +1276,7 @@ var RaindropDeepAgentsHandler = class extends BaseCallbackHandler {
1219
1276
  await this.eventShipper.patch(eventId, {
1220
1277
  userId: this.userId,
1221
1278
  convoId: this.convoId,
1279
+ eventName: this.eventName,
1222
1280
  ...patch,
1223
1281
  isPending: true
1224
1282
  });
@@ -1245,6 +1303,7 @@ var RaindropDeepAgentsHandler = class extends BaseCallbackHandler {
1245
1303
  await this.eventShipper.patch(eventId, {
1246
1304
  userId: this.userId,
1247
1305
  convoId: this.convoId,
1306
+ eventName: this.eventName,
1248
1307
  input: truncate(prompts.join("\n"), CHAIN_TEXT_MAX_LEN),
1249
1308
  properties: buildProperties(tags, metadata),
1250
1309
  isPending: true
@@ -1278,6 +1337,7 @@ var RaindropDeepAgentsHandler = class extends BaseCallbackHandler {
1278
1337
  await this.eventShipper.patch(eventId, {
1279
1338
  userId: this.userId,
1280
1339
  convoId: this.convoId,
1340
+ eventName: this.eventName,
1281
1341
  input: inputText,
1282
1342
  properties: buildProperties(tags, metadata),
1283
1343
  isPending: true
@@ -1697,6 +1757,8 @@ function createRaindropDeepAgents(opts) {
1697
1757
  traceShipper,
1698
1758
  userId: opts.userId,
1699
1759
  convoId: opts.convoId,
1760
+ eventName: opts.eventName,
1761
+ eventId: opts.eventId,
1700
1762
  traceChains: opts.traceChains
1701
1763
  });
1702
1764
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raindrop-ai/deep-agents",
3
- "version": "0.0.5",
3
+ "version": "0.1.0",
4
4
  "description": "Raindrop integration for LangChain Deep Agents",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -36,7 +36,7 @@
36
36
  "typescript": "^5.3.3",
37
37
  "vitest": "^2.1.9",
38
38
  "zod": "^3.23.0",
39
- "@raindrop-ai/core": "0.0.4"
39
+ "@raindrop-ai/core": "0.1.2"
40
40
  },
41
41
  "tsup": {
42
42
  "entry": [