@raindrop-ai/langchain 0.0.3 → 0.0.4

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
@@ -16,7 +16,7 @@ import { ChatOpenAI } from "@langchain/openai";
16
16
  import { HumanMessage } from "@langchain/core/messages";
17
17
 
18
18
  const raindrop = createRaindropLangChain({
19
- writeKey: "rk_...",
19
+ writeKey: "your-write-key",
20
20
  userId: "user-123",
21
21
  });
22
22
 
@@ -50,6 +50,7 @@ await raindrop.flush();
50
50
  | `traceChains` | `boolean` | `true` | Create spans for chain execution |
51
51
  | `traceRetrievers` | `boolean` | `true` | Create spans for retriever calls |
52
52
  | `filterLangGraphInternals` | `boolean` | `true` | Filter LangGraph-internal chain events and deduplicate LLM callbacks |
53
+ | `maxTextFieldChars` | `number` | `1000000` | Per-field cap for event input/output and serialized span payloads, enforced before/during serialization (truncated values end with `...[truncated by raindrop]`; a stricter `OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT` env var is honored) |
53
54
 
54
55
  ## LangGraph Support
55
56
 
package/dist/index.d.mts CHANGED
@@ -43,7 +43,6 @@ type SpanIds = {
43
43
  spanIdB64: string;
44
44
  parentSpanIdB64?: string;
45
45
  };
46
-
47
46
  type Attachment = {
48
47
  type: string;
49
48
  role: string;
@@ -87,6 +86,19 @@ type EventShipperOptions = {
87
86
  libraryName?: string;
88
87
  libraryVersion?: string;
89
88
  defaultEventName?: string;
89
+ /**
90
+ * Explicit Workshop / local debugger URL. Wins over env vars + auto-detect.
91
+ * Pass `null` to opt out of all mirroring (including auto-detect).
92
+ */
93
+ localDebuggerUrl?: string | null;
94
+ /**
95
+ * Per-field character cap applied to event input/output BEFORE buffering
96
+ * or serialization, so oversized payloads cost the cap — not the payload —
97
+ * on the calling code path. Truncated fields end with
98
+ * `...[truncated by raindrop]` and never exceed the cap, marker included.
99
+ * Defaults to 1,000,000 (matching the Python SDK).
100
+ */
101
+ maxTextFieldChars?: number;
90
102
  };
91
103
  declare class EventShipper {
92
104
  private baseUrl;
@@ -102,9 +114,39 @@ declare class EventShipper {
102
114
  private sticky;
103
115
  private timers;
104
116
  private inFlight;
117
+ private maxTextFieldCharsOpt;
118
+ /**
119
+ * Epoch ms deadline while `shutdown()` is draining; undefined otherwise.
120
+ * Checked before every POST issued during the final flush.
121
+ */
122
+ private shutdownDeadlineAt;
123
+ /**
124
+ * Set once `shutdown()` begins and never cleared. Sends issued after the
125
+ * drain window (stragglers, or flush work the deadline abandoned
126
+ * mid-drain) run as a single short attempt instead of regaining the full
127
+ * retry schedule.
128
+ */
129
+ private hasShutdown;
130
+ /** URL of the local debugger / Workshop daemon, when one is reachable. */
131
+ private localDebuggerUrl;
105
132
  constructor(opts: EventShipperOptions);
106
133
  isDebugEnabled(): boolean;
107
134
  private authHeaders;
135
+ /**
136
+ * Build the retry/timeout options for one POST, honoring the shutdown
137
+ * deadline. Returns `null` when the shutdown drain window is exhausted —
138
+ * the caller must drop the payload (with a rate-limited warning) instead
139
+ * of issuing a request that could outlive process exit.
140
+ *
141
+ * Checked fresh on EVERY send, so a shutdown that begins while the flush
142
+ * path is mid-drain takes effect immediately: no further retries, and the
143
+ * per-attempt timeout is clamped to the remaining window. After
144
+ * `shutdown()` returns (deadline cleared, `hasShutdown` still set),
145
+ * sends — late callers, or flush work the deadline abandoned mid-drain —
146
+ * run as a single short attempt rather than regaining the full retry
147
+ * schedule.
148
+ */
149
+ private requestOpts;
108
150
  patch(eventId: string, patch: Patch): Promise<void>;
109
151
  finish(eventId: string, patch: {
110
152
  output?: string;
@@ -116,8 +158,26 @@ declare class EventShipper {
116
158
  shutdown(): Promise<void>;
117
159
  trackSignal(signal: SignalInput): Promise<void>;
118
160
  identify(users: IdentifyInput | IdentifyInput[]): Promise<void>;
161
+ private warnShutdownDrop;
119
162
  private flushOne;
120
163
  }
164
+ /**
165
+ * Hook fired per OTLP span right before the span is shipped (to the Raindrop
166
+ * API and to a local debugger). Lets callers inspect, rewrite, or drop the
167
+ * entire span — not just individual attributes — which is more flexible than
168
+ * an attribute-level hook (you can rename attributes, add new ones, drop the
169
+ * span outright, etc.).
170
+ *
171
+ * Return values:
172
+ * - `undefined` or the same span: ship the span unchanged.
173
+ * - a new `OtlpSpan`: ship the returned span in place of the original.
174
+ * - `null`: drop the span entirely from every ship path.
175
+ *
176
+ * The hook runs on the hot path — keep it synchronous and side-effect-free.
177
+ * If the hook throws, the span is dropped (fail-closed) so a buggy hook can
178
+ * never accidentally ship raw, un-redacted spans.
179
+ */
180
+ type TransformSpanHook = (span: OtlpSpan) => OtlpSpan | null | undefined;
121
181
 
122
182
  type InternalSpan = {
123
183
  ids: SpanIds;
@@ -138,6 +198,54 @@ type TraceShipperOptions = {
138
198
  sdkName?: string;
139
199
  serviceName?: string;
140
200
  serviceVersion?: string;
201
+ /**
202
+ * Explicit Workshop / local debugger URL. Wins over env vars + auto-detect.
203
+ * Pass `null` to opt out of all mirroring (including auto-detect).
204
+ */
205
+ localDebuggerUrl?: string | null;
206
+ /**
207
+ * Per-span hook that fires for every OTLP span right before the span is
208
+ * shipped (both to the Raindrop API and to a local debugger). Lets callers
209
+ * inspect, rewrite, or drop entire spans — rename attributes, add new ones,
210
+ * scrub additional secret-shaped values inside `ai.prompt.messages` /
211
+ * `ai.toolCall.args`, etc.
212
+ *
213
+ * Return values:
214
+ * - `undefined` or the same span reference: ship the span unchanged.
215
+ * - a new `OtlpSpan`: ship the returned span in place of the original.
216
+ * - `null`: drop the span entirely from every ship path.
217
+ *
218
+ * The hook runs BEFORE the default redactor (which is the always-on floor
219
+ * for documented BYOK secrets). The default redactor still runs on the
220
+ * post-transform span unless `disableDefaultRedaction` is set, so even if
221
+ * a custom transform overlooks a secret-shaped attribute, the floor catches
222
+ * it.
223
+ *
224
+ * The hook runs on the hot path — keep it synchronous and side-effect-free.
225
+ * If the hook itself throws, the span is dropped (fail-closed) so a buggy
226
+ * hook can never accidentally ship raw, un-redacted spans.
227
+ */
228
+ transformSpan?: TransformSpanHook;
229
+ /**
230
+ * Disable the built-in default span transformer (which scrubs documented
231
+ * secret-shaped properties — `apiKey`, `secretAccessKey`, `privateKey`,
232
+ * etc. — inside `ai.request.providerOptions` and
233
+ * `ai.response.providerMetadata`).
234
+ *
235
+ * Default: `false` (i.e. default redaction is on). Setting this to `true`
236
+ * disables the floor entirely; provide a custom `transformSpan` if you
237
+ * still want some redaction in that case.
238
+ */
239
+ disableDefaultRedaction?: boolean;
240
+ /**
241
+ * Per-attribute character cap applied to every span attribute string value
242
+ * right before the span enters a ship path, so a multi-MB prompt/tool
243
+ * payload can never make the batch `JSON.stringify` (which runs on the
244
+ * event loop) cost seconds. Truncated values end with
245
+ * `...[truncated by raindrop]` and never exceed the cap, marker included.
246
+ * Defaults to 1,000,000 (matching the Python SDK).
247
+ */
248
+ maxTextFieldChars?: number;
141
249
  };
142
250
  declare class TraceShipper {
143
251
  private baseUrl;
@@ -155,9 +263,51 @@ declare class TraceShipper {
155
263
  private queue;
156
264
  private timer;
157
265
  private inFlight;
158
- /** URL of the local debugger (from RAINDROP_LOCAL_DEBUGGER env var). */
266
+ /** URL of the local debugger / Workshop daemon, when one is reachable. */
159
267
  private localDebuggerUrl;
268
+ private transformSpanHook;
269
+ private disableDefaultRedaction;
270
+ private maxTextFieldCharsOpt;
271
+ /**
272
+ * Epoch ms deadline while `shutdown()` is draining; undefined otherwise.
273
+ * Checked before every batch POST issued during the final flush.
274
+ */
275
+ private shutdownDeadlineAt;
276
+ /**
277
+ * Set once `shutdown()` begins and never cleared. Sends issued after the
278
+ * drain window (stragglers, or flush work the deadline abandoned
279
+ * mid-drain) run as a single short attempt instead of regaining the full
280
+ * retry schedule.
281
+ */
282
+ private hasShutdown;
160
283
  constructor(opts: TraceShipperOptions);
284
+ /**
285
+ * Cap every string attribute value on the span. O(#attributes) length
286
+ * checks; only oversized values pay a slice. Runs AFTER the redaction
287
+ * pipeline so the default secret-scrub still sees parseable JSON in
288
+ * `ai.request.providerOptions` / `ai.response.providerMetadata` (capping
289
+ * first could cut a JSON blob mid-way, fail the parse, and ship secrets
290
+ * in the surviving prefix).
291
+ *
292
+ * A stricter `OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT` env var is honored
293
+ * for span content, matching the Python SDK and the OTel SDK convention.
294
+ */
295
+ private capSpanAttributes;
296
+ /**
297
+ * Apply the user `transformSpan` hook (if any) followed by the default
298
+ * redactor (unless disabled). Returns either the (possibly new) span to
299
+ * ship, or `null` to drop the span entirely.
300
+ *
301
+ * Ordering: user hook runs first so callers can rewrite the span freely
302
+ * (rename attrs, add new ones, scrub things the default doesn't know
303
+ * about). The default redactor then runs on whatever the user produced,
304
+ * acting as the always-on floor for documented BYOK secrets. If the user
305
+ * sets `disableDefaultRedaction: true`, the floor is skipped.
306
+ *
307
+ * Fail-closed: if the user hook throws, the span is dropped — a buggy
308
+ * hook can never accidentally ship raw, un-redacted spans.
309
+ */
310
+ private redactSpan;
161
311
  isDebugEnabled(): boolean;
162
312
  private authHeaders;
163
313
  startSpan(args: {
@@ -171,6 +321,7 @@ declare class TraceShipper {
171
321
  attributes?: Array<OtlpKeyValue | undefined>;
172
322
  startTimeUnixNano?: string;
173
323
  }): InternalSpan;
324
+ private mirrorToLocalDebugger;
174
325
  endSpan(span: InternalSpan, extra?: {
175
326
  attributes?: InternalSpan["attributes"];
176
327
  error?: unknown;
@@ -191,6 +342,8 @@ declare class TraceShipper {
191
342
  }): void;
192
343
  enqueue(span: OtlpSpan): void;
193
344
  flush(): Promise<void>;
345
+ /** See EventShipper.requestOpts — same shutdown-budget semantics. */
346
+ private requestOpts;
194
347
  shutdown(): Promise<void>;
195
348
  }
196
349
 
@@ -295,6 +448,16 @@ interface LangChainOptions {
295
448
  * Recommended when using LangGraph. Defaults to `true`.
296
449
  */
297
450
  filterLangGraphInternals?: boolean;
451
+ /**
452
+ * Per-field character cap applied to event input/output text and
453
+ * serialized span payloads BEFORE (or during) serialization, so oversized
454
+ * payloads cost the cap — not the payload — on the calling thread.
455
+ * Truncated values end with `...[truncated by raindrop]` and never exceed
456
+ * the cap. Applies module-wide: the last factory call that sets this
457
+ * option wins; omitting it leaves the current cap unchanged. Defaults to
458
+ * 1,000,000.
459
+ */
460
+ maxTextFieldChars?: number;
298
461
  }
299
462
  type RaindropLangChainClient = {
300
463
  handler: RaindropCallbackHandler;
package/dist/index.d.ts CHANGED
@@ -43,7 +43,6 @@ type SpanIds = {
43
43
  spanIdB64: string;
44
44
  parentSpanIdB64?: string;
45
45
  };
46
-
47
46
  type Attachment = {
48
47
  type: string;
49
48
  role: string;
@@ -87,6 +86,19 @@ type EventShipperOptions = {
87
86
  libraryName?: string;
88
87
  libraryVersion?: string;
89
88
  defaultEventName?: string;
89
+ /**
90
+ * Explicit Workshop / local debugger URL. Wins over env vars + auto-detect.
91
+ * Pass `null` to opt out of all mirroring (including auto-detect).
92
+ */
93
+ localDebuggerUrl?: string | null;
94
+ /**
95
+ * Per-field character cap applied to event input/output BEFORE buffering
96
+ * or serialization, so oversized payloads cost the cap — not the payload —
97
+ * on the calling code path. Truncated fields end with
98
+ * `...[truncated by raindrop]` and never exceed the cap, marker included.
99
+ * Defaults to 1,000,000 (matching the Python SDK).
100
+ */
101
+ maxTextFieldChars?: number;
90
102
  };
91
103
  declare class EventShipper {
92
104
  private baseUrl;
@@ -102,9 +114,39 @@ declare class EventShipper {
102
114
  private sticky;
103
115
  private timers;
104
116
  private inFlight;
117
+ private maxTextFieldCharsOpt;
118
+ /**
119
+ * Epoch ms deadline while `shutdown()` is draining; undefined otherwise.
120
+ * Checked before every POST issued during the final flush.
121
+ */
122
+ private shutdownDeadlineAt;
123
+ /**
124
+ * Set once `shutdown()` begins and never cleared. Sends issued after the
125
+ * drain window (stragglers, or flush work the deadline abandoned
126
+ * mid-drain) run as a single short attempt instead of regaining the full
127
+ * retry schedule.
128
+ */
129
+ private hasShutdown;
130
+ /** URL of the local debugger / Workshop daemon, when one is reachable. */
131
+ private localDebuggerUrl;
105
132
  constructor(opts: EventShipperOptions);
106
133
  isDebugEnabled(): boolean;
107
134
  private authHeaders;
135
+ /**
136
+ * Build the retry/timeout options for one POST, honoring the shutdown
137
+ * deadline. Returns `null` when the shutdown drain window is exhausted —
138
+ * the caller must drop the payload (with a rate-limited warning) instead
139
+ * of issuing a request that could outlive process exit.
140
+ *
141
+ * Checked fresh on EVERY send, so a shutdown that begins while the flush
142
+ * path is mid-drain takes effect immediately: no further retries, and the
143
+ * per-attempt timeout is clamped to the remaining window. After
144
+ * `shutdown()` returns (deadline cleared, `hasShutdown` still set),
145
+ * sends — late callers, or flush work the deadline abandoned mid-drain —
146
+ * run as a single short attempt rather than regaining the full retry
147
+ * schedule.
148
+ */
149
+ private requestOpts;
108
150
  patch(eventId: string, patch: Patch): Promise<void>;
109
151
  finish(eventId: string, patch: {
110
152
  output?: string;
@@ -116,8 +158,26 @@ declare class EventShipper {
116
158
  shutdown(): Promise<void>;
117
159
  trackSignal(signal: SignalInput): Promise<void>;
118
160
  identify(users: IdentifyInput | IdentifyInput[]): Promise<void>;
161
+ private warnShutdownDrop;
119
162
  private flushOne;
120
163
  }
164
+ /**
165
+ * Hook fired per OTLP span right before the span is shipped (to the Raindrop
166
+ * API and to a local debugger). Lets callers inspect, rewrite, or drop the
167
+ * entire span — not just individual attributes — which is more flexible than
168
+ * an attribute-level hook (you can rename attributes, add new ones, drop the
169
+ * span outright, etc.).
170
+ *
171
+ * Return values:
172
+ * - `undefined` or the same span: ship the span unchanged.
173
+ * - a new `OtlpSpan`: ship the returned span in place of the original.
174
+ * - `null`: drop the span entirely from every ship path.
175
+ *
176
+ * The hook runs on the hot path — keep it synchronous and side-effect-free.
177
+ * If the hook throws, the span is dropped (fail-closed) so a buggy hook can
178
+ * never accidentally ship raw, un-redacted spans.
179
+ */
180
+ type TransformSpanHook = (span: OtlpSpan) => OtlpSpan | null | undefined;
121
181
 
122
182
  type InternalSpan = {
123
183
  ids: SpanIds;
@@ -138,6 +198,54 @@ type TraceShipperOptions = {
138
198
  sdkName?: string;
139
199
  serviceName?: string;
140
200
  serviceVersion?: string;
201
+ /**
202
+ * Explicit Workshop / local debugger URL. Wins over env vars + auto-detect.
203
+ * Pass `null` to opt out of all mirroring (including auto-detect).
204
+ */
205
+ localDebuggerUrl?: string | null;
206
+ /**
207
+ * Per-span hook that fires for every OTLP span right before the span is
208
+ * shipped (both to the Raindrop API and to a local debugger). Lets callers
209
+ * inspect, rewrite, or drop entire spans — rename attributes, add new ones,
210
+ * scrub additional secret-shaped values inside `ai.prompt.messages` /
211
+ * `ai.toolCall.args`, etc.
212
+ *
213
+ * Return values:
214
+ * - `undefined` or the same span reference: ship the span unchanged.
215
+ * - a new `OtlpSpan`: ship the returned span in place of the original.
216
+ * - `null`: drop the span entirely from every ship path.
217
+ *
218
+ * The hook runs BEFORE the default redactor (which is the always-on floor
219
+ * for documented BYOK secrets). The default redactor still runs on the
220
+ * post-transform span unless `disableDefaultRedaction` is set, so even if
221
+ * a custom transform overlooks a secret-shaped attribute, the floor catches
222
+ * it.
223
+ *
224
+ * The hook runs on the hot path — keep it synchronous and side-effect-free.
225
+ * If the hook itself throws, the span is dropped (fail-closed) so a buggy
226
+ * hook can never accidentally ship raw, un-redacted spans.
227
+ */
228
+ transformSpan?: TransformSpanHook;
229
+ /**
230
+ * Disable the built-in default span transformer (which scrubs documented
231
+ * secret-shaped properties — `apiKey`, `secretAccessKey`, `privateKey`,
232
+ * etc. — inside `ai.request.providerOptions` and
233
+ * `ai.response.providerMetadata`).
234
+ *
235
+ * Default: `false` (i.e. default redaction is on). Setting this to `true`
236
+ * disables the floor entirely; provide a custom `transformSpan` if you
237
+ * still want some redaction in that case.
238
+ */
239
+ disableDefaultRedaction?: boolean;
240
+ /**
241
+ * Per-attribute character cap applied to every span attribute string value
242
+ * right before the span enters a ship path, so a multi-MB prompt/tool
243
+ * payload can never make the batch `JSON.stringify` (which runs on the
244
+ * event loop) cost seconds. Truncated values end with
245
+ * `...[truncated by raindrop]` and never exceed the cap, marker included.
246
+ * Defaults to 1,000,000 (matching the Python SDK).
247
+ */
248
+ maxTextFieldChars?: number;
141
249
  };
142
250
  declare class TraceShipper {
143
251
  private baseUrl;
@@ -155,9 +263,51 @@ declare class TraceShipper {
155
263
  private queue;
156
264
  private timer;
157
265
  private inFlight;
158
- /** URL of the local debugger (from RAINDROP_LOCAL_DEBUGGER env var). */
266
+ /** URL of the local debugger / Workshop daemon, when one is reachable. */
159
267
  private localDebuggerUrl;
268
+ private transformSpanHook;
269
+ private disableDefaultRedaction;
270
+ private maxTextFieldCharsOpt;
271
+ /**
272
+ * Epoch ms deadline while `shutdown()` is draining; undefined otherwise.
273
+ * Checked before every batch POST issued during the final flush.
274
+ */
275
+ private shutdownDeadlineAt;
276
+ /**
277
+ * Set once `shutdown()` begins and never cleared. Sends issued after the
278
+ * drain window (stragglers, or flush work the deadline abandoned
279
+ * mid-drain) run as a single short attempt instead of regaining the full
280
+ * retry schedule.
281
+ */
282
+ private hasShutdown;
160
283
  constructor(opts: TraceShipperOptions);
284
+ /**
285
+ * Cap every string attribute value on the span. O(#attributes) length
286
+ * checks; only oversized values pay a slice. Runs AFTER the redaction
287
+ * pipeline so the default secret-scrub still sees parseable JSON in
288
+ * `ai.request.providerOptions` / `ai.response.providerMetadata` (capping
289
+ * first could cut a JSON blob mid-way, fail the parse, and ship secrets
290
+ * in the surviving prefix).
291
+ *
292
+ * A stricter `OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT` env var is honored
293
+ * for span content, matching the Python SDK and the OTel SDK convention.
294
+ */
295
+ private capSpanAttributes;
296
+ /**
297
+ * Apply the user `transformSpan` hook (if any) followed by the default
298
+ * redactor (unless disabled). Returns either the (possibly new) span to
299
+ * ship, or `null` to drop the span entirely.
300
+ *
301
+ * Ordering: user hook runs first so callers can rewrite the span freely
302
+ * (rename attrs, add new ones, scrub things the default doesn't know
303
+ * about). The default redactor then runs on whatever the user produced,
304
+ * acting as the always-on floor for documented BYOK secrets. If the user
305
+ * sets `disableDefaultRedaction: true`, the floor is skipped.
306
+ *
307
+ * Fail-closed: if the user hook throws, the span is dropped — a buggy
308
+ * hook can never accidentally ship raw, un-redacted spans.
309
+ */
310
+ private redactSpan;
161
311
  isDebugEnabled(): boolean;
162
312
  private authHeaders;
163
313
  startSpan(args: {
@@ -171,6 +321,7 @@ declare class TraceShipper {
171
321
  attributes?: Array<OtlpKeyValue | undefined>;
172
322
  startTimeUnixNano?: string;
173
323
  }): InternalSpan;
324
+ private mirrorToLocalDebugger;
174
325
  endSpan(span: InternalSpan, extra?: {
175
326
  attributes?: InternalSpan["attributes"];
176
327
  error?: unknown;
@@ -191,6 +342,8 @@ declare class TraceShipper {
191
342
  }): void;
192
343
  enqueue(span: OtlpSpan): void;
193
344
  flush(): Promise<void>;
345
+ /** See EventShipper.requestOpts — same shutdown-budget semantics. */
346
+ private requestOpts;
194
347
  shutdown(): Promise<void>;
195
348
  }
196
349
 
@@ -295,6 +448,16 @@ interface LangChainOptions {
295
448
  * Recommended when using LangGraph. Defaults to `true`.
296
449
  */
297
450
  filterLangGraphInternals?: boolean;
451
+ /**
452
+ * Per-field character cap applied to event input/output text and
453
+ * serialized span payloads BEFORE (or during) serialization, so oversized
454
+ * payloads cost the cap — not the payload — on the calling thread.
455
+ * Truncated values end with `...[truncated by raindrop]` and never exceed
456
+ * the cap. Applies module-wide: the last factory call that sets this
457
+ * option wins; omitting it leaves the current cap unchanged. Defaults to
458
+ * 1,000,000.
459
+ */
460
+ maxTextFieldChars?: number;
298
461
  }
299
462
  type RaindropLangChainClient = {
300
463
  handler: RaindropCallbackHandler;