@raindrop-ai/deep-agents 0.1.1 → 0.1.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.
package/README.md CHANGED
@@ -70,6 +70,34 @@ const raindrop = createRaindropDeepAgents({
70
70
 
71
71
  This sets the `X-Raindrop-Project-Id` header on every event. Omit it (or pass `"default"`) to use your org's default **Production** project — the existing behavior. Single-project orgs need nothing new.
72
72
 
73
+
74
+ ## Application Git identity
75
+
76
+ Each client reports the application commit SHA when it can determine one. Local Git discovery runs in the background and never delays or fails application calls. Automatic branch discovery is off by default.
77
+
78
+ Use `appGit` to override detection or opt out:
79
+
80
+ ```ts
81
+ const raindrop = createRaindropDeepAgents({
82
+ writeKey: "your-write-key",
83
+ appGit: {
84
+ commitSha: "0123456789abcdef0123456789abcdef01234567",
85
+ commitDirty: false,
86
+ branch: "main",
87
+ detectBranch: true,
88
+ sourceDirectory: "/path/to/application",
89
+ },
90
+ });
91
+
92
+ // Disable all application Git reporting.
93
+ const withoutGit = createRaindropDeepAgents({
94
+ writeKey: "your-write-key",
95
+ appGit: false,
96
+ });
97
+ ```
98
+
99
+ `commitSha`, `commitDirty`, and `branch` are explicit overrides. `detectBranch` opts into automatic branch lookup, `sourceDirectory` selects the application repository, and `autoDetect: false` disables automatic sources while retaining explicit values.
100
+
73
101
  ## LangGraph Support
74
102
 
75
103
  Deep Agents is built on LangGraph. The handler automatically:
@@ -111,7 +139,7 @@ The `createRaindropDeepAgents()` factory returns:
111
139
  - **Streaming**: Token-by-token streaming events are not captured individually; only the final aggregated response is tracked.
112
140
  - **Subagent isolation**: When using the `task` tool for subagent delegation, each subagent's callbacks fire independently.
113
141
  - **Concurrent invocations on a shared handler**: A single handler instance keeps one in-flight span map at a time. Running multiple `agent.invoke(...)` calls **concurrently with the same handler** (e.g. `Promise.all([agent.invoke(...), agent.invoke(...)])` with the same `raindrop.handler`) can scramble the linkage between events and traces. Instantiate one `createRaindropDeepAgents()` per concurrent request; sequential invocations on a shared handler are fully supported.
114
- - **Long chain inputs/outputs are truncated**: Chain-level `input` and `output` captured on the root event are truncated to ~8 KB to stay within the SDK's payload-size limit. Per-LLM child events still carry full prompts. Tool payloads are pruned to their cap _before_ JSON serialization, so a multi-MB tool output costs the cap — not the payload — on your event loop (truncated values carry a `...[truncated by raindrop]` marker).
142
+ - **Long inputs/outputs are truncated at `maxTextFieldChars`**: The root event's `input` is the latest user message and its `output` the final response, each capped at the configured `maxTextFieldChars` (default 1,000,000 chars), the same cap the other JavaScript integrations use; the full conversation history lives on the LLM span (`ai.prompt.messages`). Tool payloads are pruned to the cap _before_ JSON serialization, so a multi-MB tool output costs the cap — not the payload — on your event loop (truncated values carry a `...[truncated by raindrop]` marker).
115
143
 
116
144
  ## Testing
117
145
 
package/dist/index.d.mts CHANGED
@@ -42,6 +42,64 @@ type SpanIds = {
42
42
  spanIdB64: string;
43
43
  parentSpanIdB64?: string;
44
44
  };
45
+ /** Kept structural so public integration declarations do not depend on private schemas. */
46
+ type AppGitOptions = {
47
+ commitSha?: string | null;
48
+ commitDirty?: boolean | null;
49
+ branch?: string | null;
50
+ detectBranch?: boolean;
51
+ sourceDirectory?: string;
52
+ autoDetect?: boolean;
53
+ };
54
+ type AppGitSnapshot = Readonly<Record<string, unknown>>;
55
+ type AppGitEnvironment = Readonly<Record<string, string | undefined>>;
56
+ type AppGitLocalResult = {
57
+ commitSha?: string;
58
+ commitDirty?: boolean;
59
+ branch?: string;
60
+ };
61
+ type AppGitOperationOwner = string;
62
+ type AppGitLocalResolver = (sourceDirectory: string | undefined, detectBranch: boolean, completed: (result: AppGitLocalResult) => void) => () => void;
63
+ /** One client owns its defaults; operation snapshots never wait for discovery. */
64
+ declare class AppGitContextImpl {
65
+ private defaults;
66
+ private explicit;
67
+ private explicitKeys;
68
+ private cancel;
69
+ private disposed;
70
+ private operations;
71
+ private operationOverflow;
72
+ private detectBranch;
73
+ private replayBranch;
74
+ private disabled;
75
+ constructor(options: AppGitOptions | false | undefined, runtime?: {
76
+ allowLocalGit?: boolean;
77
+ resolveLocal?: AppGitLocalResolver;
78
+ env?: AppGitEnvironment;
79
+ captureLegacyReplayBranch?: boolean;
80
+ allowDiscovery?: boolean;
81
+ });
82
+ private accept;
83
+ snapshot(properties?: Readonly<Record<string, unknown>>): AppGitSnapshot;
84
+ /** Safe defaults when no operation/span start was observed; never infer identity. */
85
+ snapshotExplicit(properties?: Readonly<Record<string, unknown>>, eventId?: string): AppGitSnapshot;
86
+ /** Existing replay branch reporting stays separate from opt-in event properties. */
87
+ snapshotForReplay(): AppGitSnapshot;
88
+ /** Merge a frozen span snapshot without losing client-authored provenance. */
89
+ mergeSnapshot(base: AppGitSnapshot, properties?: Readonly<Record<string, unknown>>, explicitKeys?: ReadonlySet<string>): AppGitSnapshot;
90
+ /** Shippers belonging to one client share this bounded operation registry. */
91
+ forOperation(eventId: string | undefined, properties?: Readonly<Record<string, unknown>>, owner?: AppGitOperationOwner): AppGitSnapshot;
92
+ releaseOperation(eventId: string, owner: AppGitOperationOwner): void;
93
+ finishOperation(eventId: string): void;
94
+ dispose(): void;
95
+ }
96
+ /** Structural at package boundaries: public SDK bundles contain independent copies of core. */
97
+ type AppGitContext = Pick<AppGitContextImpl, "snapshot" | "snapshotForReplay" | "forOperation" | "finishOperation" | "dispose"> & {
98
+ snapshotExplicit?: AppGitContextImpl["snapshotExplicit"];
99
+ mergeSnapshot?: AppGitContextImpl["mergeSnapshot"];
100
+ releaseOperation?: (eventId: string, owner: AppGitOperationOwner) => void;
101
+ };
102
+ declare const AppGitContext: typeof AppGitContextImpl;
45
103
  type Attachment = {
46
104
  type: string;
47
105
  role: string;
@@ -83,6 +141,9 @@ type SignalInput = {
83
141
  after?: string;
84
142
  };
85
143
  type EventShipperOptions = {
144
+ appGit?: AppGitOptions | false;
145
+ /** Share with the trace shipper so one operation uses one source snapshot. */
146
+ appGitContext?: AppGitContext;
86
147
  writeKey?: string;
87
148
  endpoint?: string;
88
149
  enabled?: boolean;
@@ -114,6 +175,9 @@ type EventShipperOptions = {
114
175
  maxTextFieldChars?: number;
115
176
  };
116
177
  declare class EventShipper {
178
+ private appGitContext;
179
+ private ownsAppGitContext;
180
+ private readonly appGitOwner;
117
181
  private baseUrl;
118
182
  private writeKey?;
119
183
  private enabled;
@@ -144,6 +208,7 @@ declare class EventShipper {
144
208
  /** URL of the local debugger / Workshop daemon, when one is reachable. */
145
209
  private localDebuggerUrl;
146
210
  constructor(opts: EventShipperOptions);
211
+ protected ownAppGitContextForShutdown(): void;
147
212
  isDebugEnabled(): boolean;
148
213
  private authHeaders;
149
214
  private requestHeaders;
@@ -197,6 +262,8 @@ type InternalSpan = {
197
262
  attributes: Array<OtlpKeyValue | undefined>;
198
263
  };
199
264
  type TraceShipperOptions = {
265
+ appGit?: AppGitOptions | false;
266
+ appGitContext?: AppGitContext;
200
267
  writeKey?: string;
201
268
  endpoint?: string;
202
269
  enabled?: boolean;
@@ -265,6 +332,13 @@ type TraceShipperOptions = {
265
332
  maxTextFieldChars?: number;
266
333
  };
267
334
  declare class TraceShipper {
335
+ private appGitContext;
336
+ protected ownsAppGitContext: boolean;
337
+ private readonly appGitOwner;
338
+ private appGitEventIds;
339
+ private appGitActiveSpans;
340
+ private appGitCaptured;
341
+ private appGitAdded;
268
342
  private baseUrl;
269
343
  private writeKey?;
270
344
  private enabled;
@@ -443,6 +517,15 @@ interface RaindropDeepAgentsHandlerOptions {
443
517
  eventName?: string;
444
518
  eventId?: () => string;
445
519
  traceChains?: boolean;
520
+ /**
521
+ * Per-field caps this handler captures against, fixed for its lifetime:
522
+ * `maxTextFieldChars` for span attributes (further reduced by
523
+ * `OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT` as each span is captured, the
524
+ * way the trace shipper applies it), `eventMaxTextFieldChars` for event
525
+ * `input`/`output`. Default to the module-wide cap at construction.
526
+ */
527
+ maxTextFieldChars?: number;
528
+ eventMaxTextFieldChars?: number;
446
529
  }
447
530
  declare class RaindropDeepAgentsHandler extends BaseCallbackHandler {
448
531
  name: string;
@@ -453,6 +536,8 @@ declare class RaindropDeepAgentsHandler extends BaseCallbackHandler {
453
536
  private eventName?;
454
537
  private eventIdSource?;
455
538
  private traceChains;
539
+ private readonly configuredSpanMaxChars;
540
+ private readonly eventMaxChars;
456
541
  private spans;
457
542
  private rootRunIds;
458
543
  private eventIds;
@@ -465,6 +550,7 @@ declare class RaindropDeepAgentsHandler extends BaseCallbackHandler {
465
550
  */
466
551
  _lastRootEventId: string | undefined;
467
552
  constructor(opts: RaindropDeepAgentsHandlerOptions);
553
+ private get spanMaxChars();
468
554
  private getEventId;
469
555
  private getParent;
470
556
  private cleanup;
@@ -513,6 +599,17 @@ interface DeepAgentsOptions {
513
599
  */
514
600
  projectId?: string;
515
601
  traceChains?: boolean;
602
+ /**
603
+ * Per-field character cap for captured text and JSON (`ai.prompt.messages`,
604
+ * `ai.toolCall.args` / `ai.toolCall.result`, event `input` / `output`).
605
+ * A history that does not fit is cut at message boundaries, stays valid
606
+ * JSON and is flagged with `ai.prompt.messages.truncated`. Module-wide,
607
+ * shared with the underlying shippers; omitting it leaves the current cap
608
+ * unchanged. Defaults to 1,000,000.
609
+ */
610
+ maxTextFieldChars?: number;
611
+ /** Application Git identity. Auto-detects commit SHA by default; pass `false` to disable. */
612
+ appGit?: AppGitOptions | false;
516
613
  }
517
614
  type RaindropDeepAgentsClient = {
518
615
  /**
package/dist/index.d.ts CHANGED
@@ -42,6 +42,64 @@ type SpanIds = {
42
42
  spanIdB64: string;
43
43
  parentSpanIdB64?: string;
44
44
  };
45
+ /** Kept structural so public integration declarations do not depend on private schemas. */
46
+ type AppGitOptions = {
47
+ commitSha?: string | null;
48
+ commitDirty?: boolean | null;
49
+ branch?: string | null;
50
+ detectBranch?: boolean;
51
+ sourceDirectory?: string;
52
+ autoDetect?: boolean;
53
+ };
54
+ type AppGitSnapshot = Readonly<Record<string, unknown>>;
55
+ type AppGitEnvironment = Readonly<Record<string, string | undefined>>;
56
+ type AppGitLocalResult = {
57
+ commitSha?: string;
58
+ commitDirty?: boolean;
59
+ branch?: string;
60
+ };
61
+ type AppGitOperationOwner = string;
62
+ type AppGitLocalResolver = (sourceDirectory: string | undefined, detectBranch: boolean, completed: (result: AppGitLocalResult) => void) => () => void;
63
+ /** One client owns its defaults; operation snapshots never wait for discovery. */
64
+ declare class AppGitContextImpl {
65
+ private defaults;
66
+ private explicit;
67
+ private explicitKeys;
68
+ private cancel;
69
+ private disposed;
70
+ private operations;
71
+ private operationOverflow;
72
+ private detectBranch;
73
+ private replayBranch;
74
+ private disabled;
75
+ constructor(options: AppGitOptions | false | undefined, runtime?: {
76
+ allowLocalGit?: boolean;
77
+ resolveLocal?: AppGitLocalResolver;
78
+ env?: AppGitEnvironment;
79
+ captureLegacyReplayBranch?: boolean;
80
+ allowDiscovery?: boolean;
81
+ });
82
+ private accept;
83
+ snapshot(properties?: Readonly<Record<string, unknown>>): AppGitSnapshot;
84
+ /** Safe defaults when no operation/span start was observed; never infer identity. */
85
+ snapshotExplicit(properties?: Readonly<Record<string, unknown>>, eventId?: string): AppGitSnapshot;
86
+ /** Existing replay branch reporting stays separate from opt-in event properties. */
87
+ snapshotForReplay(): AppGitSnapshot;
88
+ /** Merge a frozen span snapshot without losing client-authored provenance. */
89
+ mergeSnapshot(base: AppGitSnapshot, properties?: Readonly<Record<string, unknown>>, explicitKeys?: ReadonlySet<string>): AppGitSnapshot;
90
+ /** Shippers belonging to one client share this bounded operation registry. */
91
+ forOperation(eventId: string | undefined, properties?: Readonly<Record<string, unknown>>, owner?: AppGitOperationOwner): AppGitSnapshot;
92
+ releaseOperation(eventId: string, owner: AppGitOperationOwner): void;
93
+ finishOperation(eventId: string): void;
94
+ dispose(): void;
95
+ }
96
+ /** Structural at package boundaries: public SDK bundles contain independent copies of core. */
97
+ type AppGitContext = Pick<AppGitContextImpl, "snapshot" | "snapshotForReplay" | "forOperation" | "finishOperation" | "dispose"> & {
98
+ snapshotExplicit?: AppGitContextImpl["snapshotExplicit"];
99
+ mergeSnapshot?: AppGitContextImpl["mergeSnapshot"];
100
+ releaseOperation?: (eventId: string, owner: AppGitOperationOwner) => void;
101
+ };
102
+ declare const AppGitContext: typeof AppGitContextImpl;
45
103
  type Attachment = {
46
104
  type: string;
47
105
  role: string;
@@ -83,6 +141,9 @@ type SignalInput = {
83
141
  after?: string;
84
142
  };
85
143
  type EventShipperOptions = {
144
+ appGit?: AppGitOptions | false;
145
+ /** Share with the trace shipper so one operation uses one source snapshot. */
146
+ appGitContext?: AppGitContext;
86
147
  writeKey?: string;
87
148
  endpoint?: string;
88
149
  enabled?: boolean;
@@ -114,6 +175,9 @@ type EventShipperOptions = {
114
175
  maxTextFieldChars?: number;
115
176
  };
116
177
  declare class EventShipper {
178
+ private appGitContext;
179
+ private ownsAppGitContext;
180
+ private readonly appGitOwner;
117
181
  private baseUrl;
118
182
  private writeKey?;
119
183
  private enabled;
@@ -144,6 +208,7 @@ declare class EventShipper {
144
208
  /** URL of the local debugger / Workshop daemon, when one is reachable. */
145
209
  private localDebuggerUrl;
146
210
  constructor(opts: EventShipperOptions);
211
+ protected ownAppGitContextForShutdown(): void;
147
212
  isDebugEnabled(): boolean;
148
213
  private authHeaders;
149
214
  private requestHeaders;
@@ -197,6 +262,8 @@ type InternalSpan = {
197
262
  attributes: Array<OtlpKeyValue | undefined>;
198
263
  };
199
264
  type TraceShipperOptions = {
265
+ appGit?: AppGitOptions | false;
266
+ appGitContext?: AppGitContext;
200
267
  writeKey?: string;
201
268
  endpoint?: string;
202
269
  enabled?: boolean;
@@ -265,6 +332,13 @@ type TraceShipperOptions = {
265
332
  maxTextFieldChars?: number;
266
333
  };
267
334
  declare class TraceShipper {
335
+ private appGitContext;
336
+ protected ownsAppGitContext: boolean;
337
+ private readonly appGitOwner;
338
+ private appGitEventIds;
339
+ private appGitActiveSpans;
340
+ private appGitCaptured;
341
+ private appGitAdded;
268
342
  private baseUrl;
269
343
  private writeKey?;
270
344
  private enabled;
@@ -443,6 +517,15 @@ interface RaindropDeepAgentsHandlerOptions {
443
517
  eventName?: string;
444
518
  eventId?: () => string;
445
519
  traceChains?: boolean;
520
+ /**
521
+ * Per-field caps this handler captures against, fixed for its lifetime:
522
+ * `maxTextFieldChars` for span attributes (further reduced by
523
+ * `OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT` as each span is captured, the
524
+ * way the trace shipper applies it), `eventMaxTextFieldChars` for event
525
+ * `input`/`output`. Default to the module-wide cap at construction.
526
+ */
527
+ maxTextFieldChars?: number;
528
+ eventMaxTextFieldChars?: number;
446
529
  }
447
530
  declare class RaindropDeepAgentsHandler extends BaseCallbackHandler {
448
531
  name: string;
@@ -453,6 +536,8 @@ declare class RaindropDeepAgentsHandler extends BaseCallbackHandler {
453
536
  private eventName?;
454
537
  private eventIdSource?;
455
538
  private traceChains;
539
+ private readonly configuredSpanMaxChars;
540
+ private readonly eventMaxChars;
456
541
  private spans;
457
542
  private rootRunIds;
458
543
  private eventIds;
@@ -465,6 +550,7 @@ declare class RaindropDeepAgentsHandler extends BaseCallbackHandler {
465
550
  */
466
551
  _lastRootEventId: string | undefined;
467
552
  constructor(opts: RaindropDeepAgentsHandlerOptions);
553
+ private get spanMaxChars();
468
554
  private getEventId;
469
555
  private getParent;
470
556
  private cleanup;
@@ -513,6 +599,17 @@ interface DeepAgentsOptions {
513
599
  */
514
600
  projectId?: string;
515
601
  traceChains?: boolean;
602
+ /**
603
+ * Per-field character cap for captured text and JSON (`ai.prompt.messages`,
604
+ * `ai.toolCall.args` / `ai.toolCall.result`, event `input` / `output`).
605
+ * A history that does not fit is cut at message boundaries, stays valid
606
+ * JSON and is flagged with `ai.prompt.messages.truncated`. Module-wide,
607
+ * shared with the underlying shippers; omitting it leaves the current cap
608
+ * unchanged. Defaults to 1,000,000.
609
+ */
610
+ maxTextFieldChars?: number;
611
+ /** Application Git identity. Auto-detects commit SHA by default; pass `false` to disable. */
612
+ appGit?: AppGitOptions | false;
516
613
  }
517
614
  type RaindropDeepAgentsClient = {
518
615
  /**