@raindrop-ai/ai-sdk 0.0.41 → 0.1.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.
@@ -4,7 +4,15 @@ var async_hooks = require('async_hooks');
4
4
 
5
5
  // src/index.node.ts
6
6
 
7
- // ../core/dist/chunk-WKRW55KX.js
7
+ // ../core/dist/chunk-Y5LUB7OE.js
8
+ function normalizeFeatureFlags(input) {
9
+ if (Array.isArray(input)) {
10
+ return Object.fromEntries(input.map((name) => [name, "true"]));
11
+ }
12
+ return Object.fromEntries(
13
+ Object.entries(input).map(([k, v]) => [k, String(v)])
14
+ );
15
+ }
8
16
  function getCrypto() {
9
17
  const c = globalThis.crypto;
10
18
  return c;
@@ -439,13 +447,16 @@ function projectIdHeaders(projectId) {
439
447
  var SHUTDOWN_DEADLINE_MS = 1e4;
440
448
  var POST_SHUTDOWN_TIMEOUT_MS = 5e3;
441
449
  function mergePatches(target, source) {
442
- var _a, _b, _c, _d;
450
+ var _a, _b, _c, _d, _e, _f;
443
451
  const out = { ...target, ...source };
444
452
  if (target.properties || source.properties) {
445
453
  out.properties = { ...(_a = target.properties) != null ? _a : {}, ...(_b = source.properties) != null ? _b : {} };
446
454
  }
455
+ if (target.featureFlags || source.featureFlags) {
456
+ out.featureFlags = { ...(_c = target.featureFlags) != null ? _c : {}, ...(_d = source.featureFlags) != null ? _d : {} };
457
+ }
447
458
  if (target.attachments || source.attachments) {
448
- out.attachments = [...(_c = target.attachments) != null ? _c : [], ...(_d = source.attachments) != null ? _d : []];
459
+ out.attachments = [...(_e = target.attachments) != null ? _e : [], ...(_f = source.attachments) != null ? _f : []];
449
460
  }
450
461
  return out;
451
462
  }
@@ -715,6 +726,7 @@ var EventShipper = class {
715
726
  ...wizardSession ? { "raindrop.wizardSession": wizardSession } : {},
716
727
  $context: this.context
717
728
  },
729
+ ...accumulated.featureFlags && Object.keys(accumulated.featureFlags).length > 0 ? { feature_flags: accumulated.featureFlags } : {},
718
730
  attachments: accumulated.attachments,
719
731
  is_pending: isPending
720
732
  };
@@ -1329,7 +1341,7 @@ installTracingSuppressionHook();
1329
1341
  // package.json
1330
1342
  var package_default = {
1331
1343
  name: "@raindrop-ai/ai-sdk",
1332
- version: "0.0.41"};
1344
+ version: "0.1.1"};
1333
1345
 
1334
1346
  // src/internal/version.ts
1335
1347
  var libraryName = package_default.name;
@@ -2751,6 +2763,20 @@ var RaindropTelemetryIntegration = class {
2751
2763
  } else if (properties && typeof properties === "object") {
2752
2764
  result.properties = properties;
2753
2765
  }
2766
+ const featureFlags = metadata["raindrop.featureFlags"];
2767
+ if (typeof featureFlags === "string") {
2768
+ try {
2769
+ const parsed = JSON.parse(featureFlags);
2770
+ if (parsed && typeof parsed === "object") {
2771
+ result.featureFlags = normalizeFeatureFlags(parsed);
2772
+ }
2773
+ } catch (e) {
2774
+ }
2775
+ } else if (featureFlags && typeof featureFlags === "object") {
2776
+ result.featureFlags = normalizeFeatureFlags(
2777
+ featureFlags
2778
+ );
2779
+ }
2754
2780
  return result;
2755
2781
  }
2756
2782
  /**
@@ -2965,7 +2991,7 @@ var RaindropTelemetryIntegration = class {
2965
2991
  * same event ID into a separate canonical row.
2966
2992
  */
2967
2993
  finalizeGenerateEvent(state, output, model, keepPending = false) {
2968
- var _a, _b, _c, _d, _e, _f, _g, _h;
2994
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2969
2995
  const suppressSubagentEvent = state.subagentName !== void 0 && state.subagentToolCallSpan !== void 0;
2970
2996
  if (!this.sendEvents || suppressSubagentEvent) return;
2971
2997
  const callMeta = this.extractRaindropMetadata(state.metadata);
@@ -2978,7 +3004,11 @@ var RaindropTelemetryIntegration = class {
2978
3004
  ...(_f = this.defaultContext) == null ? void 0 : _f.properties,
2979
3005
  ...callMeta.properties
2980
3006
  };
2981
- const convoId = (_h = callMeta.convoId) != null ? _h : (_g = this.defaultContext) == null ? void 0 : _g.convoId;
3007
+ const featureFlags = {
3008
+ ...((_g = this.defaultContext) == null ? void 0 : _g.featureFlags) ? normalizeFeatureFlags(this.defaultContext.featureFlags) : {},
3009
+ ...callMeta.featureFlags
3010
+ };
3011
+ const convoId = (_i = callMeta.convoId) != null ? _i : (_h = this.defaultContext) == null ? void 0 : _h.convoId;
2982
3012
  void this.eventShipper.patch(state.eventId, {
2983
3013
  eventName,
2984
3014
  userId,
@@ -2987,6 +3017,7 @@ var RaindropTelemetryIntegration = class {
2987
3017
  output: cappedOutput,
2988
3018
  model,
2989
3019
  properties: Object.keys(properties).length > 0 ? properties : void 0,
3020
+ featureFlags: Object.keys(featureFlags).length > 0 ? featureFlags : void 0,
2990
3021
  isPending: keepPending
2991
3022
  }).catch((err) => {
2992
3023
  if (this.debug) {
@@ -3310,6 +3341,20 @@ function extractRaindropMetadata(metadata) {
3310
3341
  } else if (properties && typeof properties === "object") {
3311
3342
  result.properties = properties;
3312
3343
  }
3344
+ const featureFlags = metadata["raindrop.featureFlags"];
3345
+ if (typeof featureFlags === "string") {
3346
+ try {
3347
+ const parsed = JSON.parse(featureFlags);
3348
+ if (parsed && typeof parsed === "object") {
3349
+ result.featureFlags = normalizeFeatureFlags(parsed);
3350
+ }
3351
+ } catch (e) {
3352
+ }
3353
+ } else if (featureFlags && typeof featureFlags === "object") {
3354
+ result.featureFlags = normalizeFeatureFlags(
3355
+ featureFlags
3356
+ );
3357
+ }
3313
3358
  return result;
3314
3359
  }
3315
3360
  function mergeContexts(wrapTime, callTime) {
@@ -3324,6 +3369,10 @@ function mergeContexts(wrapTime, callTime) {
3324
3369
  ...callTime.properties
3325
3370
  };
3326
3371
  }
3372
+ if (callTime.featureFlags) {
3373
+ const wrapTimeFlags = wrapTime.featureFlags ? normalizeFeatureFlags(wrapTime.featureFlags) : {};
3374
+ result.featureFlags = { ...wrapTimeFlags, ...callTime.featureFlags };
3375
+ }
3327
3376
  return result;
3328
3377
  }
3329
3378
  function detectAISDKVersion(aiSDK) {
@@ -3636,6 +3685,7 @@ function createFinalize(params) {
3636
3685
  output: defaultOutput,
3637
3686
  model,
3638
3687
  properties: setup.ctx.properties,
3688
+ featureFlags: setup.ctx.featureFlags ? normalizeFeatureFlags(setup.ctx.featureFlags) : void 0,
3639
3689
  attachments: mergeAttachments(setup.ctx.attachments, inputAttachments, outputAttachments)
3640
3690
  };
3641
3691
  const built = await maybeBuildEvent(options.buildEvent, allMessages);
@@ -3689,6 +3739,7 @@ function createFinalize(params) {
3689
3739
  output,
3690
3740
  model: finalModel,
3691
3741
  properties: patch.properties,
3742
+ featureFlags: patch.featureFlags,
3692
3743
  attachments: patch.attachments,
3693
3744
  isPending: keepEventPending
3694
3745
  }).catch((err) => {
@@ -3920,7 +3971,8 @@ function wrapAISDK(aiSDK, deps) {
3920
3971
  eventId: wrapTimeCtx.eventId,
3921
3972
  eventName: wrapTimeCtx.eventName,
3922
3973
  convoId: wrapTimeCtx.convoId,
3923
- properties: wrapTimeCtx.properties
3974
+ properties: wrapTimeCtx.properties,
3975
+ featureFlags: wrapTimeCtx.featureFlags ? normalizeFeatureFlags(wrapTimeCtx.featureFlags) : void 0
3924
3976
  }
3925
3977
  });
3926
3978
  const registerFn = resolveRegisterTelemetry(aiSDK);
@@ -4196,6 +4248,7 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
4196
4248
  output: outputText,
4197
4249
  model,
4198
4250
  properties: ctx.properties,
4251
+ featureFlags: ctx.featureFlags ? normalizeFeatureFlags(ctx.featureFlags) : void 0,
4199
4252
  attachments: mergeAttachments(ctx.attachments, inputAttachments, outputAttachments)
4200
4253
  };
4201
4254
  const built = await maybeBuildEvent(deps.options.buildEvent, allMessages);
@@ -4263,6 +4316,7 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
4263
4316
  output,
4264
4317
  model: finalModel,
4265
4318
  properties: patch.properties,
4319
+ featureFlags: patch.featureFlags,
4266
4320
  attachments: patch.attachments,
4267
4321
  isPending: false
4268
4322
  }).catch((err) => {
@@ -4404,6 +4458,7 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
4404
4458
  output: outputText,
4405
4459
  model,
4406
4460
  properties: ctx.properties,
4461
+ featureFlags: ctx.featureFlags ? normalizeFeatureFlags(ctx.featureFlags) : void 0,
4407
4462
  attachments: mergeAttachments(ctx.attachments, inputAttachments, outputAttachments)
4408
4463
  };
4409
4464
  const built = await maybeBuildEvent(deps.options.buildEvent, allMessages);
@@ -4471,6 +4526,7 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
4471
4526
  output,
4472
4527
  model: finalModel,
4473
4528
  properties: patch.properties,
4529
+ featureFlags: patch.featureFlags,
4474
4530
  attachments: patch.attachments,
4475
4531
  isPending: false
4476
4532
  }).catch((err) => {
@@ -5068,7 +5124,7 @@ async function maybeBuildEvent(buildEvent, messages) {
5068
5124
  }
5069
5125
  }
5070
5126
  function mergeBuildEventPatch(defaults, override) {
5071
- var _a, _b, _c, _d, _e, _f, _g, _h;
5127
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
5072
5128
  if (!override) return defaults;
5073
5129
  return {
5074
5130
  eventName: (_a = override.eventName) != null ? _a : defaults.eventName,
@@ -5076,7 +5132,8 @@ function mergeBuildEventPatch(defaults, override) {
5076
5132
  output: (_c = override.output) != null ? _c : defaults.output,
5077
5133
  model: (_d = override.model) != null ? _d : defaults.model,
5078
5134
  properties: override.properties !== void 0 ? { ...(_e = defaults.properties) != null ? _e : {}, ...(_f = override.properties) != null ? _f : {} } : defaults.properties,
5079
- attachments: override.attachments !== void 0 ? [...(_g = defaults.attachments) != null ? _g : [], ...(_h = override.attachments) != null ? _h : []] : defaults.attachments
5135
+ featureFlags: override.featureFlags !== void 0 ? { ...(_g = defaults.featureFlags) != null ? _g : {}, ...(_h = override.featureFlags) != null ? _h : {} } : defaults.featureFlags,
5136
+ attachments: override.attachments !== void 0 ? [...(_i = defaults.attachments) != null ? _i : [], ...(_j = override.attachments) != null ? _j : []] : defaults.attachments
5080
5137
  };
5081
5138
  }
5082
5139
  function mergeAttachments(...groups) {
@@ -5107,6 +5164,8 @@ function eventMetadata(options) {
5107
5164
  if (options.convoId) result["raindrop.convoId"] = options.convoId;
5108
5165
  if (options.eventName) result["raindrop.eventName"] = options.eventName;
5109
5166
  if (options.properties) result["raindrop.properties"] = JSON.stringify(options.properties);
5167
+ if (options.featureFlags)
5168
+ result["raindrop.featureFlags"] = JSON.stringify(normalizeFeatureFlags(options.featureFlags));
5110
5169
  return result;
5111
5170
  }
5112
5171
  function deriveChatTurnMessageId(request) {
@@ -5211,7 +5270,8 @@ function createRaindropAISDK(opts) {
5211
5270
  "eventId",
5212
5271
  "eventName",
5213
5272
  "convoId",
5214
- "properties"
5273
+ "properties",
5274
+ "featureFlags"
5215
5275
  ];
5216
5276
  let context;
5217
5277
  let subagentWrapping;
@@ -5243,6 +5303,9 @@ function createRaindropAISDK(opts) {
5243
5303
  async setProperties(eventId, properties) {
5244
5304
  await eventShipper.patch(eventId, { properties });
5245
5305
  },
5306
+ async setFeatureFlags(eventId, featureFlags) {
5307
+ await eventShipper.patch(eventId, { featureFlags: normalizeFeatureFlags(featureFlags) });
5308
+ },
5246
5309
  async finish(eventId, patch) {
5247
5310
  await eventShipper.finish(eventId, patch);
5248
5311
  }
@@ -5367,6 +5430,7 @@ exports.eventMetadataFromChatRequest = eventMetadataFromChatRequest;
5367
5430
  exports.getContextManager = getContextManager;
5368
5431
  exports.getCurrentParentToolContext = getCurrentParentToolContext;
5369
5432
  exports.getCurrentRaindropCallMetadata = getCurrentRaindropCallMetadata;
5433
+ exports.normalizeFeatureFlags = normalizeFeatureFlags;
5370
5434
  exports.raindrop = raindrop;
5371
5435
  exports.readRaindropCallMetadataFromArgs = readRaindropCallMetadataFromArgs;
5372
5436
  exports.redactJsonAttributeValue = redactJsonAttributeValue;
@@ -1,4 +1,4 @@
1
- export { DEFAULT_MAX_TEXT_FIELD_CHARS, DEFAULT_REDACT_ATTRIBUTE_KEYS, DEFAULT_SECRET_KEY_NAMES, REDACTED_PLACEHOLDER, RaindropTelemetryIntegration, TRUNCATION_MARKER, _resetParentToolContextStorage, _resetRaindropCallMetadataStorage, _resetWarnedMissingUserId, boundedStringify, capText, clearParentToolContext, createRaindropAISDK, currentSpan, defaultTransformSpan, enterParentToolContext, eventMetadata, eventMetadataFromChatRequest, getContextManager, getCurrentParentToolContext, getCurrentRaindropCallMetadata, raindrop, readRaindropCallMetadataFromArgs, redactJsonAttributeValue, redactSecretsInObject, runWithParentToolContext, runWithRaindropCallMetadata, withCurrent } from './chunk-3EYXAZ2H.mjs';
1
+ export { DEFAULT_MAX_TEXT_FIELD_CHARS, DEFAULT_REDACT_ATTRIBUTE_KEYS, DEFAULT_SECRET_KEY_NAMES, REDACTED_PLACEHOLDER, RaindropTelemetryIntegration, TRUNCATION_MARKER, _resetParentToolContextStorage, _resetRaindropCallMetadataStorage, _resetWarnedMissingUserId, boundedStringify, capText, clearParentToolContext, createRaindropAISDK, currentSpan, defaultTransformSpan, enterParentToolContext, eventMetadata, eventMetadataFromChatRequest, getContextManager, getCurrentParentToolContext, getCurrentRaindropCallMetadata, normalizeFeatureFlags, raindrop, readRaindropCallMetadataFromArgs, redactJsonAttributeValue, redactSecretsInObject, runWithParentToolContext, runWithRaindropCallMetadata, withCurrent } from './chunk-NU5KYBJA.mjs';
2
2
  import { AsyncLocalStorage } from 'async_hooks';
3
3
 
4
4
  globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = AsyncLocalStorage;
@@ -1,4 +1,4 @@
1
- export { A as AISDKChatRequestLike, a as AISDKChatRequestMessageLike, b as AISDKMessage, c as AgentCallMetadata, d as AgentWithMetadata, e as Attachment, B as BuildEventPatch, C as ContextManager, f as ContextSpan, g as CreateSpanArgs, D as DEFAULT_MAX_TEXT_FIELD_CHARS, h as DEFAULT_REDACT_ATTRIBUTE_KEYS, i as DEFAULT_SECRET_KEY_NAMES, E as EndSpanArgs, j as EventBuilder, k as EventMetadataOptions, I as IdentifyInput, O as OtlpAnyValue, l as OtlpSpan, P as ParentToolContext, R as REDACTED_PLACEHOLDER, m as RaindropAISDKClient, n as RaindropAISDKContext, o as RaindropAISDKOptions, p as RaindropCallMetadata, q as RaindropTelemetryIntegration, r as RaindropTelemetryIntegrationOptions, s as RaindropTelemetryOptions, S as SelfDiagnosticsOptions, t as SelfDiagnosticsSignalDefinition, u as SelfDiagnosticsSignalDefinitions, v as SelfDiagnosticsTool, w as SelfDiagnosticsToolInput, x as SelfDiagnosticsToolOptions, y as SelfDiagnosticsToolResult, z as StartSpanArgs, T as TRUNCATION_MARKER, F as TraceSpan, G as TransformSpanHook, W as WrapAISDKOptions, H as WrappedAI, J as WrappedAISDK, _ as _resetParentToolContextStorage, K as _resetRaindropCallMetadataStorage, L as _resetWarnedMissingUserId, M as boundedStringify, N as capText, Q as clearParentToolContext, U as createRaindropAISDK, V as currentSpan, X as defaultTransformSpan, Y as enterParentToolContext, Z as eventMetadata, $ as eventMetadataFromChatRequest, a0 as getContextManager, a1 as getCurrentParentToolContext, a2 as getCurrentRaindropCallMetadata, a3 as raindrop, a4 as readRaindropCallMetadataFromArgs, a5 as redactJsonAttributeValue, a6 as redactSecretsInObject, a7 as runWithParentToolContext, a8 as runWithRaindropCallMetadata, a9 as withCurrent } from './index-BCojLiWV.mjs';
1
+ export { A as AISDKChatRequestLike, a as AISDKChatRequestMessageLike, b as AISDKMessage, c as AgentCallMetadata, d as AgentWithMetadata, e as Attachment, B as BuildEventPatch, C as ContextManager, f as ContextSpan, g as CreateSpanArgs, D as DEFAULT_MAX_TEXT_FIELD_CHARS, h as DEFAULT_REDACT_ATTRIBUTE_KEYS, i as DEFAULT_SECRET_KEY_NAMES, E as EndSpanArgs, j as EventBuilder, k as EventMetadataOptions, F as FeatureFlagValue, l as FeatureFlags, I as IdentifyInput, O as OtlpAnyValue, m as OtlpSpan, P as ParentToolContext, R as REDACTED_PLACEHOLDER, n as RaindropAISDKClient, o as RaindropAISDKContext, p as RaindropAISDKOptions, q as RaindropCallMetadata, r as RaindropTelemetryIntegration, s as RaindropTelemetryIntegrationOptions, t as RaindropTelemetryOptions, S as SelfDiagnosticsOptions, u as SelfDiagnosticsSignalDefinition, v as SelfDiagnosticsSignalDefinitions, w as SelfDiagnosticsTool, x as SelfDiagnosticsToolInput, y as SelfDiagnosticsToolOptions, z as SelfDiagnosticsToolResult, G as StartSpanArgs, T as TRUNCATION_MARKER, H as TraceSpan, J as TransformSpanHook, W as WrapAISDKOptions, K as WrappedAI, L as WrappedAISDK, _ as _resetParentToolContextStorage, M as _resetRaindropCallMetadataStorage, N as _resetWarnedMissingUserId, Q as boundedStringify, U as capText, V as clearParentToolContext, X as createRaindropAISDK, Y as currentSpan, Z as defaultTransformSpan, $ as enterParentToolContext, a0 as eventMetadata, a1 as eventMetadataFromChatRequest, a2 as getContextManager, a3 as getCurrentParentToolContext, a4 as getCurrentRaindropCallMetadata, a5 as normalizeFeatureFlags, a6 as raindrop, a7 as readRaindropCallMetadataFromArgs, a8 as redactJsonAttributeValue, a9 as redactSecretsInObject, aa as runWithParentToolContext, ab as runWithRaindropCallMetadata, ac as withCurrent } from './index-BQwgg9kQ.mjs';
2
2
 
3
3
  declare global {
4
4
  var RAINDROP_ASYNC_LOCAL_STORAGE: (new <T>() => {
@@ -1,4 +1,4 @@
1
- export { A as AISDKChatRequestLike, a as AISDKChatRequestMessageLike, b as AISDKMessage, c as AgentCallMetadata, d as AgentWithMetadata, e as Attachment, B as BuildEventPatch, C as ContextManager, f as ContextSpan, g as CreateSpanArgs, D as DEFAULT_MAX_TEXT_FIELD_CHARS, h as DEFAULT_REDACT_ATTRIBUTE_KEYS, i as DEFAULT_SECRET_KEY_NAMES, E as EndSpanArgs, j as EventBuilder, k as EventMetadataOptions, I as IdentifyInput, O as OtlpAnyValue, l as OtlpSpan, P as ParentToolContext, R as REDACTED_PLACEHOLDER, m as RaindropAISDKClient, n as RaindropAISDKContext, o as RaindropAISDKOptions, p as RaindropCallMetadata, q as RaindropTelemetryIntegration, r as RaindropTelemetryIntegrationOptions, s as RaindropTelemetryOptions, S as SelfDiagnosticsOptions, t as SelfDiagnosticsSignalDefinition, u as SelfDiagnosticsSignalDefinitions, v as SelfDiagnosticsTool, w as SelfDiagnosticsToolInput, x as SelfDiagnosticsToolOptions, y as SelfDiagnosticsToolResult, z as StartSpanArgs, T as TRUNCATION_MARKER, F as TraceSpan, G as TransformSpanHook, W as WrapAISDKOptions, H as WrappedAI, J as WrappedAISDK, _ as _resetParentToolContextStorage, K as _resetRaindropCallMetadataStorage, L as _resetWarnedMissingUserId, M as boundedStringify, N as capText, Q as clearParentToolContext, U as createRaindropAISDK, V as currentSpan, X as defaultTransformSpan, Y as enterParentToolContext, Z as eventMetadata, $ as eventMetadataFromChatRequest, a0 as getContextManager, a1 as getCurrentParentToolContext, a2 as getCurrentRaindropCallMetadata, a3 as raindrop, a4 as readRaindropCallMetadataFromArgs, a5 as redactJsonAttributeValue, a6 as redactSecretsInObject, a7 as runWithParentToolContext, a8 as runWithRaindropCallMetadata, a9 as withCurrent } from './index-BCojLiWV.js';
1
+ export { A as AISDKChatRequestLike, a as AISDKChatRequestMessageLike, b as AISDKMessage, c as AgentCallMetadata, d as AgentWithMetadata, e as Attachment, B as BuildEventPatch, C as ContextManager, f as ContextSpan, g as CreateSpanArgs, D as DEFAULT_MAX_TEXT_FIELD_CHARS, h as DEFAULT_REDACT_ATTRIBUTE_KEYS, i as DEFAULT_SECRET_KEY_NAMES, E as EndSpanArgs, j as EventBuilder, k as EventMetadataOptions, F as FeatureFlagValue, l as FeatureFlags, I as IdentifyInput, O as OtlpAnyValue, m as OtlpSpan, P as ParentToolContext, R as REDACTED_PLACEHOLDER, n as RaindropAISDKClient, o as RaindropAISDKContext, p as RaindropAISDKOptions, q as RaindropCallMetadata, r as RaindropTelemetryIntegration, s as RaindropTelemetryIntegrationOptions, t as RaindropTelemetryOptions, S as SelfDiagnosticsOptions, u as SelfDiagnosticsSignalDefinition, v as SelfDiagnosticsSignalDefinitions, w as SelfDiagnosticsTool, x as SelfDiagnosticsToolInput, y as SelfDiagnosticsToolOptions, z as SelfDiagnosticsToolResult, G as StartSpanArgs, T as TRUNCATION_MARKER, H as TraceSpan, J as TransformSpanHook, W as WrapAISDKOptions, K as WrappedAI, L as WrappedAISDK, _ as _resetParentToolContextStorage, M as _resetRaindropCallMetadataStorage, N as _resetWarnedMissingUserId, Q as boundedStringify, U as capText, V as clearParentToolContext, X as createRaindropAISDK, Y as currentSpan, Z as defaultTransformSpan, $ as enterParentToolContext, a0 as eventMetadata, a1 as eventMetadataFromChatRequest, a2 as getContextManager, a3 as getCurrentParentToolContext, a4 as getCurrentRaindropCallMetadata, a5 as normalizeFeatureFlags, a6 as raindrop, a7 as readRaindropCallMetadataFromArgs, a8 as redactJsonAttributeValue, a9 as redactSecretsInObject, aa as runWithParentToolContext, ab as runWithRaindropCallMetadata, ac as withCurrent } from './index-BQwgg9kQ.js';
2
2
 
3
3
  declare global {
4
4
  var RAINDROP_ASYNC_LOCAL_STORAGE: (new <T>() => {
@@ -4,7 +4,15 @@ var async_hooks = require('async_hooks');
4
4
 
5
5
  // src/index.workers.ts
6
6
 
7
- // ../core/dist/chunk-WKRW55KX.js
7
+ // ../core/dist/chunk-Y5LUB7OE.js
8
+ function normalizeFeatureFlags(input) {
9
+ if (Array.isArray(input)) {
10
+ return Object.fromEntries(input.map((name) => [name, "true"]));
11
+ }
12
+ return Object.fromEntries(
13
+ Object.entries(input).map(([k, v]) => [k, String(v)])
14
+ );
15
+ }
8
16
  function getCrypto() {
9
17
  const c = globalThis.crypto;
10
18
  return c;
@@ -439,13 +447,16 @@ function projectIdHeaders(projectId) {
439
447
  var SHUTDOWN_DEADLINE_MS = 1e4;
440
448
  var POST_SHUTDOWN_TIMEOUT_MS = 5e3;
441
449
  function mergePatches(target, source) {
442
- var _a, _b, _c, _d;
450
+ var _a, _b, _c, _d, _e, _f;
443
451
  const out = { ...target, ...source };
444
452
  if (target.properties || source.properties) {
445
453
  out.properties = { ...(_a = target.properties) != null ? _a : {}, ...(_b = source.properties) != null ? _b : {} };
446
454
  }
455
+ if (target.featureFlags || source.featureFlags) {
456
+ out.featureFlags = { ...(_c = target.featureFlags) != null ? _c : {}, ...(_d = source.featureFlags) != null ? _d : {} };
457
+ }
447
458
  if (target.attachments || source.attachments) {
448
- out.attachments = [...(_c = target.attachments) != null ? _c : [], ...(_d = source.attachments) != null ? _d : []];
459
+ out.attachments = [...(_e = target.attachments) != null ? _e : [], ...(_f = source.attachments) != null ? _f : []];
449
460
  }
450
461
  return out;
451
462
  }
@@ -715,6 +726,7 @@ var EventShipper = class {
715
726
  ...wizardSession ? { "raindrop.wizardSession": wizardSession } : {},
716
727
  $context: this.context
717
728
  },
729
+ ...accumulated.featureFlags && Object.keys(accumulated.featureFlags).length > 0 ? { feature_flags: accumulated.featureFlags } : {},
718
730
  attachments: accumulated.attachments,
719
731
  is_pending: isPending
720
732
  };
@@ -1329,7 +1341,7 @@ installTracingSuppressionHook();
1329
1341
  // package.json
1330
1342
  var package_default = {
1331
1343
  name: "@raindrop-ai/ai-sdk",
1332
- version: "0.0.41"};
1344
+ version: "0.1.1"};
1333
1345
 
1334
1346
  // src/internal/version.ts
1335
1347
  var libraryName = package_default.name;
@@ -2751,6 +2763,20 @@ var RaindropTelemetryIntegration = class {
2751
2763
  } else if (properties && typeof properties === "object") {
2752
2764
  result.properties = properties;
2753
2765
  }
2766
+ const featureFlags = metadata["raindrop.featureFlags"];
2767
+ if (typeof featureFlags === "string") {
2768
+ try {
2769
+ const parsed = JSON.parse(featureFlags);
2770
+ if (parsed && typeof parsed === "object") {
2771
+ result.featureFlags = normalizeFeatureFlags(parsed);
2772
+ }
2773
+ } catch (e) {
2774
+ }
2775
+ } else if (featureFlags && typeof featureFlags === "object") {
2776
+ result.featureFlags = normalizeFeatureFlags(
2777
+ featureFlags
2778
+ );
2779
+ }
2754
2780
  return result;
2755
2781
  }
2756
2782
  /**
@@ -2965,7 +2991,7 @@ var RaindropTelemetryIntegration = class {
2965
2991
  * same event ID into a separate canonical row.
2966
2992
  */
2967
2993
  finalizeGenerateEvent(state, output, model, keepPending = false) {
2968
- var _a, _b, _c, _d, _e, _f, _g, _h;
2994
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2969
2995
  const suppressSubagentEvent = state.subagentName !== void 0 && state.subagentToolCallSpan !== void 0;
2970
2996
  if (!this.sendEvents || suppressSubagentEvent) return;
2971
2997
  const callMeta = this.extractRaindropMetadata(state.metadata);
@@ -2978,7 +3004,11 @@ var RaindropTelemetryIntegration = class {
2978
3004
  ...(_f = this.defaultContext) == null ? void 0 : _f.properties,
2979
3005
  ...callMeta.properties
2980
3006
  };
2981
- const convoId = (_h = callMeta.convoId) != null ? _h : (_g = this.defaultContext) == null ? void 0 : _g.convoId;
3007
+ const featureFlags = {
3008
+ ...((_g = this.defaultContext) == null ? void 0 : _g.featureFlags) ? normalizeFeatureFlags(this.defaultContext.featureFlags) : {},
3009
+ ...callMeta.featureFlags
3010
+ };
3011
+ const convoId = (_i = callMeta.convoId) != null ? _i : (_h = this.defaultContext) == null ? void 0 : _h.convoId;
2982
3012
  void this.eventShipper.patch(state.eventId, {
2983
3013
  eventName,
2984
3014
  userId,
@@ -2987,6 +3017,7 @@ var RaindropTelemetryIntegration = class {
2987
3017
  output: cappedOutput,
2988
3018
  model,
2989
3019
  properties: Object.keys(properties).length > 0 ? properties : void 0,
3020
+ featureFlags: Object.keys(featureFlags).length > 0 ? featureFlags : void 0,
2990
3021
  isPending: keepPending
2991
3022
  }).catch((err) => {
2992
3023
  if (this.debug) {
@@ -3310,6 +3341,20 @@ function extractRaindropMetadata(metadata) {
3310
3341
  } else if (properties && typeof properties === "object") {
3311
3342
  result.properties = properties;
3312
3343
  }
3344
+ const featureFlags = metadata["raindrop.featureFlags"];
3345
+ if (typeof featureFlags === "string") {
3346
+ try {
3347
+ const parsed = JSON.parse(featureFlags);
3348
+ if (parsed && typeof parsed === "object") {
3349
+ result.featureFlags = normalizeFeatureFlags(parsed);
3350
+ }
3351
+ } catch (e) {
3352
+ }
3353
+ } else if (featureFlags && typeof featureFlags === "object") {
3354
+ result.featureFlags = normalizeFeatureFlags(
3355
+ featureFlags
3356
+ );
3357
+ }
3313
3358
  return result;
3314
3359
  }
3315
3360
  function mergeContexts(wrapTime, callTime) {
@@ -3324,6 +3369,10 @@ function mergeContexts(wrapTime, callTime) {
3324
3369
  ...callTime.properties
3325
3370
  };
3326
3371
  }
3372
+ if (callTime.featureFlags) {
3373
+ const wrapTimeFlags = wrapTime.featureFlags ? normalizeFeatureFlags(wrapTime.featureFlags) : {};
3374
+ result.featureFlags = { ...wrapTimeFlags, ...callTime.featureFlags };
3375
+ }
3327
3376
  return result;
3328
3377
  }
3329
3378
  function detectAISDKVersion(aiSDK) {
@@ -3636,6 +3685,7 @@ function createFinalize(params) {
3636
3685
  output: defaultOutput,
3637
3686
  model,
3638
3687
  properties: setup.ctx.properties,
3688
+ featureFlags: setup.ctx.featureFlags ? normalizeFeatureFlags(setup.ctx.featureFlags) : void 0,
3639
3689
  attachments: mergeAttachments(setup.ctx.attachments, inputAttachments, outputAttachments)
3640
3690
  };
3641
3691
  const built = await maybeBuildEvent(options.buildEvent, allMessages);
@@ -3689,6 +3739,7 @@ function createFinalize(params) {
3689
3739
  output,
3690
3740
  model: finalModel,
3691
3741
  properties: patch.properties,
3742
+ featureFlags: patch.featureFlags,
3692
3743
  attachments: patch.attachments,
3693
3744
  isPending: keepEventPending
3694
3745
  }).catch((err) => {
@@ -3920,7 +3971,8 @@ function wrapAISDK(aiSDK, deps) {
3920
3971
  eventId: wrapTimeCtx.eventId,
3921
3972
  eventName: wrapTimeCtx.eventName,
3922
3973
  convoId: wrapTimeCtx.convoId,
3923
- properties: wrapTimeCtx.properties
3974
+ properties: wrapTimeCtx.properties,
3975
+ featureFlags: wrapTimeCtx.featureFlags ? normalizeFeatureFlags(wrapTimeCtx.featureFlags) : void 0
3924
3976
  }
3925
3977
  });
3926
3978
  const registerFn = resolveRegisterTelemetry(aiSDK);
@@ -4196,6 +4248,7 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
4196
4248
  output: outputText,
4197
4249
  model,
4198
4250
  properties: ctx.properties,
4251
+ featureFlags: ctx.featureFlags ? normalizeFeatureFlags(ctx.featureFlags) : void 0,
4199
4252
  attachments: mergeAttachments(ctx.attachments, inputAttachments, outputAttachments)
4200
4253
  };
4201
4254
  const built = await maybeBuildEvent(deps.options.buildEvent, allMessages);
@@ -4263,6 +4316,7 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
4263
4316
  output,
4264
4317
  model: finalModel,
4265
4318
  properties: patch.properties,
4319
+ featureFlags: patch.featureFlags,
4266
4320
  attachments: patch.attachments,
4267
4321
  isPending: false
4268
4322
  }).catch((err) => {
@@ -4404,6 +4458,7 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
4404
4458
  output: outputText,
4405
4459
  model,
4406
4460
  properties: ctx.properties,
4461
+ featureFlags: ctx.featureFlags ? normalizeFeatureFlags(ctx.featureFlags) : void 0,
4407
4462
  attachments: mergeAttachments(ctx.attachments, inputAttachments, outputAttachments)
4408
4463
  };
4409
4464
  const built = await maybeBuildEvent(deps.options.buildEvent, allMessages);
@@ -4471,6 +4526,7 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
4471
4526
  output,
4472
4527
  model: finalModel,
4473
4528
  properties: patch.properties,
4529
+ featureFlags: patch.featureFlags,
4474
4530
  attachments: patch.attachments,
4475
4531
  isPending: false
4476
4532
  }).catch((err) => {
@@ -5068,7 +5124,7 @@ async function maybeBuildEvent(buildEvent, messages) {
5068
5124
  }
5069
5125
  }
5070
5126
  function mergeBuildEventPatch(defaults, override) {
5071
- var _a, _b, _c, _d, _e, _f, _g, _h;
5127
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
5072
5128
  if (!override) return defaults;
5073
5129
  return {
5074
5130
  eventName: (_a = override.eventName) != null ? _a : defaults.eventName,
@@ -5076,7 +5132,8 @@ function mergeBuildEventPatch(defaults, override) {
5076
5132
  output: (_c = override.output) != null ? _c : defaults.output,
5077
5133
  model: (_d = override.model) != null ? _d : defaults.model,
5078
5134
  properties: override.properties !== void 0 ? { ...(_e = defaults.properties) != null ? _e : {}, ...(_f = override.properties) != null ? _f : {} } : defaults.properties,
5079
- attachments: override.attachments !== void 0 ? [...(_g = defaults.attachments) != null ? _g : [], ...(_h = override.attachments) != null ? _h : []] : defaults.attachments
5135
+ featureFlags: override.featureFlags !== void 0 ? { ...(_g = defaults.featureFlags) != null ? _g : {}, ...(_h = override.featureFlags) != null ? _h : {} } : defaults.featureFlags,
5136
+ attachments: override.attachments !== void 0 ? [...(_i = defaults.attachments) != null ? _i : [], ...(_j = override.attachments) != null ? _j : []] : defaults.attachments
5080
5137
  };
5081
5138
  }
5082
5139
  function mergeAttachments(...groups) {
@@ -5107,6 +5164,8 @@ function eventMetadata(options) {
5107
5164
  if (options.convoId) result["raindrop.convoId"] = options.convoId;
5108
5165
  if (options.eventName) result["raindrop.eventName"] = options.eventName;
5109
5166
  if (options.properties) result["raindrop.properties"] = JSON.stringify(options.properties);
5167
+ if (options.featureFlags)
5168
+ result["raindrop.featureFlags"] = JSON.stringify(normalizeFeatureFlags(options.featureFlags));
5110
5169
  return result;
5111
5170
  }
5112
5171
  function deriveChatTurnMessageId(request) {
@@ -5211,7 +5270,8 @@ function createRaindropAISDK(opts) {
5211
5270
  "eventId",
5212
5271
  "eventName",
5213
5272
  "convoId",
5214
- "properties"
5273
+ "properties",
5274
+ "featureFlags"
5215
5275
  ];
5216
5276
  let context;
5217
5277
  let subagentWrapping;
@@ -5243,6 +5303,9 @@ function createRaindropAISDK(opts) {
5243
5303
  async setProperties(eventId, properties) {
5244
5304
  await eventShipper.patch(eventId, { properties });
5245
5305
  },
5306
+ async setFeatureFlags(eventId, featureFlags) {
5307
+ await eventShipper.patch(eventId, { featureFlags: normalizeFeatureFlags(featureFlags) });
5308
+ },
5246
5309
  async finish(eventId, patch) {
5247
5310
  await eventShipper.finish(eventId, patch);
5248
5311
  }
@@ -5369,6 +5432,7 @@ exports.eventMetadataFromChatRequest = eventMetadataFromChatRequest;
5369
5432
  exports.getContextManager = getContextManager;
5370
5433
  exports.getCurrentParentToolContext = getCurrentParentToolContext;
5371
5434
  exports.getCurrentRaindropCallMetadata = getCurrentRaindropCallMetadata;
5435
+ exports.normalizeFeatureFlags = normalizeFeatureFlags;
5372
5436
  exports.raindrop = raindrop;
5373
5437
  exports.readRaindropCallMetadataFromArgs = readRaindropCallMetadataFromArgs;
5374
5438
  exports.redactJsonAttributeValue = redactJsonAttributeValue;
@@ -1,4 +1,4 @@
1
- export { DEFAULT_MAX_TEXT_FIELD_CHARS, DEFAULT_REDACT_ATTRIBUTE_KEYS, DEFAULT_SECRET_KEY_NAMES, REDACTED_PLACEHOLDER, RaindropTelemetryIntegration, TRUNCATION_MARKER, _resetParentToolContextStorage, _resetRaindropCallMetadataStorage, _resetWarnedMissingUserId, boundedStringify, capText, clearParentToolContext, createRaindropAISDK, currentSpan, defaultTransformSpan, enterParentToolContext, eventMetadata, eventMetadataFromChatRequest, getContextManager, getCurrentParentToolContext, getCurrentRaindropCallMetadata, raindrop, readRaindropCallMetadataFromArgs, redactJsonAttributeValue, redactSecretsInObject, runWithParentToolContext, runWithRaindropCallMetadata, withCurrent } from './chunk-3EYXAZ2H.mjs';
1
+ export { DEFAULT_MAX_TEXT_FIELD_CHARS, DEFAULT_REDACT_ATTRIBUTE_KEYS, DEFAULT_SECRET_KEY_NAMES, REDACTED_PLACEHOLDER, RaindropTelemetryIntegration, TRUNCATION_MARKER, _resetParentToolContextStorage, _resetRaindropCallMetadataStorage, _resetWarnedMissingUserId, boundedStringify, capText, clearParentToolContext, createRaindropAISDK, currentSpan, defaultTransformSpan, enterParentToolContext, eventMetadata, eventMetadataFromChatRequest, getContextManager, getCurrentParentToolContext, getCurrentRaindropCallMetadata, normalizeFeatureFlags, raindrop, readRaindropCallMetadataFromArgs, redactJsonAttributeValue, redactSecretsInObject, runWithParentToolContext, runWithRaindropCallMetadata, withCurrent } from './chunk-NU5KYBJA.mjs';
2
2
  import { AsyncLocalStorage } from 'async_hooks';
3
3
 
4
4
  if (!globalThis.RAINDROP_ASYNC_LOCAL_STORAGE) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raindrop-ai/ai-sdk",
3
- "version": "0.0.41",
3
+ "version": "0.1.1",
4
4
  "description": "Standalone Vercel AI SDK integration for Raindrop (events + OTLP/HTTP JSON traces, no OTEL runtime)",
5
5
  "main": "dist/index.node.js",
6
6
  "module": "dist/index.node.mjs",
@@ -37,7 +37,7 @@
37
37
  "tsup": "^8.4.0",
38
38
  "tsx": "^4.20.3",
39
39
  "typescript": "^5.3.3",
40
- "@raindrop-ai/core": "0.0.5"
40
+ "@raindrop-ai/core": "0.1.0"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "ai": ">=4 <8"