@raindrop-ai/ai-sdk 0.0.27 → 0.0.29

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.
@@ -79,6 +79,11 @@ type EventShipperOptions = {
79
79
  libraryName?: string;
80
80
  libraryVersion?: string;
81
81
  defaultEventName?: string;
82
+ /**
83
+ * Explicit Workshop / local debugger URL. Wins over env vars + auto-detect.
84
+ * Pass `null` to opt out of all mirroring (including auto-detect).
85
+ */
86
+ localDebuggerUrl?: string | null;
82
87
  };
83
88
  declare class EventShipper$1 {
84
89
  private baseUrl;
@@ -94,6 +99,8 @@ declare class EventShipper$1 {
94
99
  private sticky;
95
100
  private timers;
96
101
  private inFlight;
102
+ /** URL of the local debugger / Workshop daemon, when one is reachable. */
103
+ private localDebuggerUrl;
97
104
  constructor(opts: EventShipperOptions);
98
105
  isDebugEnabled(): boolean;
99
106
  private authHeaders;
@@ -111,6 +118,82 @@ declare class EventShipper$1 {
111
118
  private flushOne;
112
119
  }
113
120
 
121
+ /**
122
+ * Built-in default list of property names considered secret. Matching is
123
+ * case-insensitive and normalizes camelCase / snake_case / kebab-case (so
124
+ * `apiKey`, `api_key`, and `API-KEY` all match). When `defaultRedactAttribute`
125
+ * (and the recursive `redactSecretsInObject` helper) walk a value, any object
126
+ * key whose normalized form is in this set has its value replaced with the
127
+ * redaction placeholder.
128
+ *
129
+ * Names were chosen to cover the documented Vercel AI Gateway BYOK credential
130
+ * shapes (OpenAI / Anthropic `apiKey`, Bedrock `secretAccessKey` +
131
+ * `sessionToken`, Vertex `privateKey` + `privateKeyId`, etc.) plus generic
132
+ * secret-shaped properties common across other providers. Keys that are not
133
+ * by themselves secret (e.g. AWS `accessKeyId` — analogous to a username, not
134
+ * usable without `secretAccessKey`) are intentionally NOT in this set.
135
+ */
136
+ declare const DEFAULT_SECRET_KEY_NAMES: readonly string[];
137
+ declare const REDACTED_PLACEHOLDER = "[REDACTED]";
138
+ /**
139
+ * Recursively walk `value` and replace any property whose (normalized) name
140
+ * matches one of `secretKeyNames` with `placeholder`. Returns a new object/
141
+ * array; does not mutate the input. Non-object inputs are returned untouched.
142
+ *
143
+ * Cycle-safe via a WeakSet — circular references resolve to `"[CIRCULAR]"`.
144
+ */
145
+ declare function redactSecretsInObject(value: unknown, options?: {
146
+ secretKeyNames?: ReadonlyArray<string>;
147
+ placeholder?: string;
148
+ }): unknown;
149
+ /**
150
+ * Hook fired per OTLP span right before the span is shipped (to the Raindrop
151
+ * API and to a local debugger). Lets callers inspect, rewrite, or drop the
152
+ * entire span — not just individual attributes — which is more flexible than
153
+ * an attribute-level hook (you can rename attributes, add new ones, drop the
154
+ * span outright, etc.).
155
+ *
156
+ * Return values:
157
+ * - `undefined` or the same span: ship the span unchanged.
158
+ * - a new `OtlpSpan`: ship the returned span in place of the original.
159
+ * - `null`: drop the span entirely from every ship path.
160
+ *
161
+ * The hook runs on the hot path — keep it synchronous and side-effect-free.
162
+ * If the hook throws, the span is dropped (fail-closed) so a buggy hook can
163
+ * never accidentally ship raw, un-redacted spans.
164
+ */
165
+ type TransformSpanHook = (span: OtlpSpan) => OtlpSpan | null | undefined;
166
+ /**
167
+ * The built-in OTLP span attributes that carry JSON-serialized user objects
168
+ * the SDK has no schema for (provider options, provider metadata). The
169
+ * default span transformer (`defaultTransformSpan`) parses, recursively
170
+ * scrubs secret-shaped properties, and re-serializes the value of any
171
+ * attribute whose key is in this set. Other attributes — including
172
+ * `ai.prompt.messages` and `ai.toolCall.args` — are passed through unchanged
173
+ * because they may legitimately contain content the caller wants logged;
174
+ * callers who need to scrub those should provide a custom `transformSpan`.
175
+ */
176
+ declare const DEFAULT_REDACT_ATTRIBUTE_KEYS: readonly string[];
177
+ /**
178
+ * Default span transformer. Walks the span's attributes; for every attribute
179
+ * whose key is in `DEFAULT_REDACT_ATTRIBUTE_KEYS`, parses the `stringValue`
180
+ * as JSON, recursively scrubs secret-shaped property names
181
+ * (`DEFAULT_SECRET_KEY_NAMES`), and re-serializes. Returns the same span
182
+ * reference when nothing changed (cheap no-op path); otherwise returns a new
183
+ * `OtlpSpan` with updated `attributes`.
184
+ */
185
+ declare function defaultTransformSpan(span: OtlpSpan): OtlpSpan;
186
+ /**
187
+ * If `key` is one of the JSON-blob attributes we redact by default and
188
+ * `value.stringValue` parses cleanly, return a new `OtlpAnyValue` carrying
189
+ * the scrubbed JSON. Otherwise return `undefined` (signal: no change).
190
+ *
191
+ * Exported because a caller's custom `transformSpan` may want to apply the
192
+ * same per-attribute redaction logic to additional attributes (e.g. their
193
+ * own provider-specific blob).
194
+ */
195
+ declare function redactJsonAttributeValue(key: string, value: OtlpAnyValue): OtlpAnyValue | undefined;
196
+
114
197
  type InternalSpan = {
115
198
  ids: SpanIds;
116
199
  name: string;
@@ -135,6 +218,40 @@ type TraceShipperOptions = {
135
218
  * Pass `null` to opt out of all mirroring (including auto-detect).
136
219
  */
137
220
  localDebuggerUrl?: string | null;
221
+ /**
222
+ * Per-span hook that fires for every OTLP span right before the span is
223
+ * shipped (both to the Raindrop API and to a local debugger). Lets callers
224
+ * inspect, rewrite, or drop entire spans — rename attributes, add new ones,
225
+ * scrub additional secret-shaped values inside `ai.prompt.messages` /
226
+ * `ai.toolCall.args`, etc.
227
+ *
228
+ * Return values:
229
+ * - `undefined` or the same span reference: ship the span unchanged.
230
+ * - a new `OtlpSpan`: ship the returned span in place of the original.
231
+ * - `null`: drop the span entirely from every ship path.
232
+ *
233
+ * The hook runs BEFORE the default redactor (which is the always-on floor
234
+ * for documented BYOK secrets). The default redactor still runs on the
235
+ * post-transform span unless `disableDefaultRedaction` is set, so even if
236
+ * a custom transform overlooks a secret-shaped attribute, the floor catches
237
+ * it.
238
+ *
239
+ * The hook runs on the hot path — keep it synchronous and side-effect-free.
240
+ * If the hook itself throws, the span is dropped (fail-closed) so a buggy
241
+ * hook can never accidentally ship raw, un-redacted spans.
242
+ */
243
+ transformSpan?: TransformSpanHook;
244
+ /**
245
+ * Disable the built-in default span transformer (which scrubs documented
246
+ * secret-shaped properties — `apiKey`, `secretAccessKey`, `privateKey`,
247
+ * etc. — inside `ai.request.providerOptions` and
248
+ * `ai.response.providerMetadata`).
249
+ *
250
+ * Default: `false` (i.e. default redaction is on). Setting this to `true`
251
+ * disables the floor entirely; provide a custom `transformSpan` if you
252
+ * still want some redaction in that case.
253
+ */
254
+ disableDefaultRedaction?: boolean;
138
255
  };
139
256
  declare class TraceShipper$1 {
140
257
  private baseUrl;
@@ -154,7 +271,24 @@ declare class TraceShipper$1 {
154
271
  private inFlight;
155
272
  /** URL of the local debugger / Workshop daemon, when one is reachable. */
156
273
  private localDebuggerUrl;
274
+ private transformSpanHook;
275
+ private disableDefaultRedaction;
157
276
  constructor(opts: TraceShipperOptions);
277
+ /**
278
+ * Apply the user `transformSpan` hook (if any) followed by the default
279
+ * redactor (unless disabled). Returns either the (possibly new) span to
280
+ * ship, or `null` to drop the span entirely.
281
+ *
282
+ * Ordering: user hook runs first so callers can rewrite the span freely
283
+ * (rename attrs, add new ones, scrub things the default doesn't know
284
+ * about). The default redactor then runs on whatever the user produced,
285
+ * acting as the always-on floor for documented BYOK secrets. If the user
286
+ * sets `disableDefaultRedaction: true`, the floor is skipped.
287
+ *
288
+ * Fail-closed: if the user hook throws, the span is dropped — a buggy
289
+ * hook can never accidentally ship raw, un-redacted spans.
290
+ */
291
+ private redactSpan;
158
292
  isDebugEnabled(): boolean;
159
293
  private authHeaders;
160
294
  startSpan(args: {
@@ -168,6 +302,7 @@ declare class TraceShipper$1 {
168
302
  attributes?: Array<OtlpKeyValue | undefined>;
169
303
  startTimeUnixNano?: string;
170
304
  }): InternalSpan;
305
+ private mirrorToLocalDebugger;
171
306
  endSpan(span: InternalSpan, extra?: {
172
307
  attributes?: InternalSpan["attributes"];
173
308
  error?: unknown;
@@ -528,6 +663,40 @@ type RaindropAISDKOptions = {
528
663
  maxQueueSize?: number;
529
664
  debug?: boolean;
530
665
  debugSpans?: boolean;
666
+ /**
667
+ * Per-span hook that fires for every OTLP span right before it's shipped
668
+ * (to the Raindrop API and to a local debugger). Lets callers inspect,
669
+ * rewrite, or drop entire spans — rename attributes, add new ones, scrub
670
+ * additional secret-shaped values inside `ai.prompt.messages` /
671
+ * `ai.toolCall.args`, etc.
672
+ *
673
+ * Return values:
674
+ * - `undefined` or the same span reference: ship the span unchanged.
675
+ * - a new `OtlpSpan`: ship the returned span in place of the original.
676
+ * - `null`: drop the span entirely from every ship path.
677
+ *
678
+ * The hook runs BEFORE the default redactor (the always-on floor for
679
+ * documented BYOK secrets — `apiKey`, `secretAccessKey`, `privateKey`,
680
+ * `accessToken`, etc. — inside `ai.request.providerOptions` and
681
+ * `ai.response.providerMetadata`). The default redactor still runs on
682
+ * the post-transform span unless `disableDefaultRedaction` is set.
683
+ *
684
+ * The hook runs on the hot path — keep it synchronous and
685
+ * side-effect-free. If the hook throws, the span is dropped (fail-closed).
686
+ */
687
+ transformSpan?: TransformSpanHook;
688
+ /**
689
+ * Disable the always-on default redactor that scrubs documented secret-
690
+ * shaped keys (`apiKey`, `secretAccessKey`, `privateKey`, ...) inside
691
+ * `ai.request.providerOptions` and `ai.response.providerMetadata`.
692
+ *
693
+ * Default: `false` (built-in redaction is on — BYOK credentials inside
694
+ * `providerOptions` are stripped automatically). If you set this to
695
+ * `true`, raw provider options will be shipped — only do this if you've
696
+ * verified your callers never put secrets in `providerOptions` or you've
697
+ * supplied your own `transformSpan` hook.
698
+ */
699
+ disableDefaultRedaction?: boolean;
531
700
  };
532
701
  events?: {
533
702
  enabled?: boolean;
@@ -764,4 +933,4 @@ type RaindropAISDKClient = {
764
933
  };
765
934
  declare function createRaindropAISDK(opts: RaindropAISDKOptions): RaindropAISDKClient;
766
935
 
767
- export { type AISDKChatRequestLike, type AISDKChatRequestMessageLike, type AISDKMessage, type AgentCallMetadata, type AgentWithMetadata, type Attachment, type BuildEventPatch, ContextManager, type ContextSpan, type CreateSpanArgs, type EndSpanArgs, type EventBuilder, type EventMetadataOptions, type IdentifyInput, type RaindropAISDKClient, type RaindropAISDKContext, type RaindropAISDKOptions, type RaindropCallMetadata, RaindropTelemetryIntegration, type RaindropTelemetryIntegrationOptions, type SelfDiagnosticsOptions, type SelfDiagnosticsSignalDefinition, type SelfDiagnosticsSignalDefinitions, type StartSpanArgs, type TraceSpan, type WrapAISDKOptions, type WrappedAI, type WrappedAISDK, _resetRaindropCallMetadataStorage, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, eventMetadataFromChatRequest, getContextManager, getCurrentRaindropCallMetadata, readRaindropCallMetadataFromArgs, runWithRaindropCallMetadata, withCurrent };
936
+ export { type AISDKChatRequestLike, type AISDKChatRequestMessageLike, type AISDKMessage, type AgentCallMetadata, type AgentWithMetadata, type Attachment, type BuildEventPatch, ContextManager, type ContextSpan, type CreateSpanArgs, DEFAULT_REDACT_ATTRIBUTE_KEYS, DEFAULT_SECRET_KEY_NAMES, type EndSpanArgs, type EventBuilder, type EventMetadataOptions, type IdentifyInput, type OtlpAnyValue, type OtlpSpan, REDACTED_PLACEHOLDER, type RaindropAISDKClient, type RaindropAISDKContext, type RaindropAISDKOptions, type RaindropCallMetadata, RaindropTelemetryIntegration, type RaindropTelemetryIntegrationOptions, type SelfDiagnosticsOptions, type SelfDiagnosticsSignalDefinition, type SelfDiagnosticsSignalDefinitions, type StartSpanArgs, type TraceSpan, type TransformSpanHook, type WrapAISDKOptions, type WrappedAI, type WrappedAISDK, _resetRaindropCallMetadataStorage, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, defaultTransformSpan, eventMetadata, eventMetadataFromChatRequest, getContextManager, getCurrentRaindropCallMetadata, readRaindropCallMetadataFromArgs, redactJsonAttributeValue, redactSecretsInObject, runWithRaindropCallMetadata, withCurrent };