@raindrop-ai/ai-sdk 0.0.8 → 0.0.9

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.
@@ -84,7 +84,7 @@ async function postJson(url, body, headers, opts) {
84
84
  // package.json
85
85
  var package_default = {
86
86
  name: "@raindrop-ai/ai-sdk",
87
- version: "0.0.8"};
87
+ version: "0.0.9"};
88
88
 
89
89
  // src/internal/version.ts
90
90
  var libraryName = package_default.name;
@@ -118,13 +118,15 @@ var EventShipper = class {
118
118
  this.sticky = /* @__PURE__ */ new Map();
119
119
  this.timers = /* @__PURE__ */ new Map();
120
120
  this.inFlight = /* @__PURE__ */ new Set();
121
- var _a, _b;
122
- if (!opts.writeKey) throw new Error("[raindrop-ai/ai-sdk] writeKey is required");
123
- this.writeKey = opts.writeKey;
124
- this.baseUrl = (_a = formatEndpoint(opts.endpoint)) != null ? _a : "https://api.raindrop.ai/v1/";
121
+ var _a, _b, _c;
122
+ if (opts.enabled && !opts.writeKey) {
123
+ throw new Error("[raindrop-ai/ai-sdk] writeKey is required when events are enabled");
124
+ }
125
+ this.writeKey = (_a = opts.writeKey) != null ? _a : "";
126
+ this.baseUrl = (_b = formatEndpoint(opts.endpoint)) != null ? _b : "https://api.raindrop.ai/v1/";
125
127
  this.enabled = opts.enabled;
126
128
  this.debug = opts.debug;
127
- this.partialFlushMs = (_b = opts.partialFlushMs) != null ? _b : 1e3;
129
+ this.partialFlushMs = (_c = opts.partialFlushMs) != null ? _c : 1e3;
128
130
  this.context = getRuntimeContext();
129
131
  }
130
132
  isDebugEnabled() {
@@ -472,16 +474,18 @@ var TraceShipper = class {
472
474
  constructor(opts) {
473
475
  this.queue = [];
474
476
  this.inFlight = /* @__PURE__ */ new Set();
475
- var _a, _b, _c, _d;
476
- if (!opts.writeKey) throw new Error("[raindrop-ai/ai-sdk] writeKey is required");
477
- this.writeKey = opts.writeKey;
478
- this.baseUrl = (_a = formatEndpoint(opts.endpoint)) != null ? _a : "https://api.raindrop.ai/v1/";
477
+ var _a, _b, _c, _d, _e;
478
+ if (opts.enabled && !opts.writeKey) {
479
+ throw new Error("[raindrop-ai/ai-sdk] writeKey is required when traces are enabled");
480
+ }
481
+ this.writeKey = (_a = opts.writeKey) != null ? _a : "";
482
+ this.baseUrl = (_b = formatEndpoint(opts.endpoint)) != null ? _b : "https://api.raindrop.ai/v1/";
479
483
  this.enabled = opts.enabled;
480
484
  this.debug = opts.debug;
481
485
  this.debugSpans = opts.debugSpans === true;
482
- this.flushIntervalMs = (_b = opts.flushIntervalMs) != null ? _b : 1e3;
483
- this.maxBatchSize = (_c = opts.maxBatchSize) != null ? _c : 50;
484
- this.maxQueueSize = (_d = opts.maxQueueSize) != null ? _d : 5e3;
486
+ this.flushIntervalMs = (_c = opts.flushIntervalMs) != null ? _c : 1e3;
487
+ this.maxBatchSize = (_d = opts.maxBatchSize) != null ? _d : 50;
488
+ this.maxQueueSize = (_e = opts.maxQueueSize) != null ? _e : 5e3;
485
489
  }
486
490
  isDebugEnabled() {
487
491
  return this.debug;
@@ -1252,6 +1256,14 @@ function warnMissingUserIdOnce() {
1252
1256
  function _resetWarnedMissingUserId() {
1253
1257
  warnedMissingUserId = false;
1254
1258
  }
1259
+ function extractRaindropCallOptions(options) {
1260
+ if (!isRecord(options)) return {};
1261
+ const em = options["metadata"];
1262
+ if (isRecord(em)) return extractRaindropMetadata(em);
1263
+ const telemetry = extractExperimentalTelemetry(options);
1264
+ if (telemetry == null ? void 0 : telemetry.metadata) return extractRaindropMetadata(telemetry.metadata);
1265
+ return {};
1266
+ }
1255
1267
  function extractRaindropMetadata(metadata) {
1256
1268
  if (!metadata || typeof metadata !== "object") return {};
1257
1269
  const result = {};
@@ -1774,7 +1786,7 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
1774
1786
  const operation = `${className}.generate`;
1775
1787
  const wrapTimeCtx = resolveContext(deps.options.context, { operation, args: mergedArgs });
1776
1788
  const telemetry = extractExperimentalTelemetry(mergedArgs);
1777
- const callTimeCtx = extractRaindropMetadata(telemetry == null ? void 0 : telemetry.metadata);
1789
+ const callTimeCtx = extractRaindropCallOptions(mergedArgs);
1778
1790
  const mergedCtx = mergeContexts(wrapTimeCtx, callTimeCtx);
1779
1791
  if (!mergedCtx.userId) warnMissingUserIdOnce();
1780
1792
  const inherited = await getCurrentParentSpanContext();
@@ -1962,7 +1974,7 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
1962
1974
  const operation = `${className}.stream`;
1963
1975
  const wrapTimeCtx = resolveContext(deps.options.context, { operation, args: mergedArgs });
1964
1976
  const telemetry = extractExperimentalTelemetry(mergedArgs);
1965
- const callTimeCtx = extractRaindropMetadata(telemetry == null ? void 0 : telemetry.metadata);
1977
+ const callTimeCtx = extractRaindropCallOptions(mergedArgs);
1966
1978
  const mergedCtx = mergeContexts(wrapTimeCtx, callTimeCtx);
1967
1979
  if (!mergedCtx.userId) warnMissingUserIdOnce();
1968
1980
  const inherited = await getCurrentParentSpanContext();
@@ -2632,18 +2644,26 @@ function envDebugEnabled() {
2632
2644
  }
2633
2645
  function createRaindropAISDK(opts) {
2634
2646
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2635
- const eventsEnabled = ((_a = opts.events) == null ? void 0 : _a.enabled) !== false;
2636
- const tracesEnabled = ((_b = opts.traces) == null ? void 0 : _b.enabled) !== false;
2647
+ const writeKey = opts.writeKey;
2648
+ const eventsRequested = ((_a = opts.events) == null ? void 0 : _a.enabled) !== false;
2649
+ const tracesRequested = ((_b = opts.traces) == null ? void 0 : _b.enabled) !== false;
2650
+ const eventsEnabled = eventsRequested && !!writeKey;
2651
+ const tracesEnabled = tracesRequested && !!writeKey;
2637
2652
  const envDebug = envDebugEnabled();
2653
+ if (!writeKey && (eventsRequested || tracesRequested)) {
2654
+ console.warn(
2655
+ "[raindrop-ai/ai-sdk] writeKey not provided; telemetry shipping is disabled"
2656
+ );
2657
+ }
2638
2658
  const eventShipper = new EventShipper({
2639
- writeKey: opts.writeKey,
2659
+ writeKey,
2640
2660
  endpoint: opts.endpoint,
2641
2661
  enabled: eventsEnabled,
2642
2662
  debug: ((_c = opts.events) == null ? void 0 : _c.debug) === true || envDebug,
2643
2663
  partialFlushMs: (_d = opts.events) == null ? void 0 : _d.partialFlushMs
2644
2664
  });
2645
2665
  const traceShipper = new TraceShipper({
2646
- writeKey: opts.writeKey,
2666
+ writeKey,
2647
2667
  endpoint: opts.endpoint,
2648
2668
  enabled: tracesEnabled,
2649
2669
  debug: ((_e = opts.traces) == null ? void 0 : _e.debug) === true || envDebug,
package/dist/index.d.mts CHANGED
@@ -127,6 +127,48 @@ type EventMetadataOptions = {
127
127
  * ```
128
128
  */
129
129
  declare function eventMetadata(options: EventMetadataOptions): Record<string, string>;
130
+ type AgentCallMetadata = ReturnType<typeof eventMetadata>;
131
+ type NormalizeUnknownAgentOptions<T> = T extends {
132
+ options: infer CallOptions;
133
+ } ? unknown extends CallOptions ? Omit<T, "options"> & {
134
+ options?: never;
135
+ } : T : T;
136
+ /**
137
+ * Wraps an agent instance type so `generate()` and `stream()` accept optional
138
+ * Raindrop call metadata while preserving original return types.
139
+ */
140
+ type AgentWithMetadata<A> = A extends {
141
+ generate: (...args: infer GenerateArgs) => infer GenerateReturn;
142
+ stream: (...args: infer StreamArgs) => infer StreamReturn;
143
+ } ? Omit<A, "generate" | "stream"> & {
144
+ generate(...args: GenerateArgs extends [infer Options, ...infer Rest] ? [NormalizeUnknownAgentOptions<Options> & {
145
+ metadata?: AgentCallMetadata;
146
+ }, ...Rest] : GenerateArgs): GenerateReturn;
147
+ stream(...args: StreamArgs extends [infer Options, ...infer Rest] ? [NormalizeUnknownAgentOptions<Options> & {
148
+ metadata?: AgentCallMetadata;
149
+ }, ...Rest] : StreamArgs): StreamReturn;
150
+ } : A;
151
+ /**
152
+ * Structural wrapper type for AI SDK modules.
153
+ *
154
+ * - AI SDK v6: rewrites `ToolLoopAgent` constructor instance methods to accept
155
+ * `metadata` on `generate/stream`.
156
+ * - AI SDK v4/v5: no `ToolLoopAgent` export, so the type is unchanged.
157
+ */
158
+ type WrappedAISDK<T extends object> = T extends {
159
+ ToolLoopAgent: abstract new (...args: any[]) => any;
160
+ } ? Omit<T, "ToolLoopAgent"> & {
161
+ ToolLoopAgent: new (...args: ConstructorParameters<T["ToolLoopAgent"]>) => AgentWithMetadata<InstanceType<T["ToolLoopAgent"]>>;
162
+ } : T;
163
+ /**
164
+ * Backward-compatible alias for wrapped AI SDK module types.
165
+ *
166
+ * This alias intentionally avoids referencing `import("ai")` to satisfy type
167
+ * resolution without requiring `ai` to be installed.
168
+ *
169
+ * Prefer `WrappedAISDK<typeof ai>` in app code when you have an `ai` import.
170
+ */
171
+ type WrappedAI<T extends object = any> = WrappedAISDK<T>;
130
172
  type Attachment = {
131
173
  attachment_id?: string;
132
174
  name?: string;
@@ -139,7 +181,11 @@ type Attachment = {
139
181
  type: "text" | "image" | "iframe";
140
182
  });
141
183
  type RaindropAISDKOptions = {
142
- writeKey: string;
184
+ /**
185
+ * API write key. If omitted, telemetry shipping is disabled but `wrap()` is
186
+ * still available for a consistent integration surface.
187
+ */
188
+ writeKey?: string;
143
189
  endpoint?: string;
144
190
  traces?: {
145
191
  enabled?: boolean;
@@ -217,7 +263,7 @@ type EventPatch = {
217
263
  timestamp?: string;
218
264
  };
219
265
  type RaindropAISDKClient = {
220
- wrap<T extends object>(aiSDK: T, options?: WrapAISDKOptions): T;
266
+ wrap<T extends object>(aiSDK: T, options?: WrapAISDKOptions): WrappedAISDK<T>;
221
267
  events: {
222
268
  patch(eventId: string, patch: EventPatch): Promise<void>;
223
269
  addAttachments(eventId: string, attachments: Attachment[]): Promise<void>;
@@ -249,4 +295,4 @@ type RaindropAISDKClient = {
249
295
  };
250
296
  declare function createRaindropAISDK(opts: RaindropAISDKOptions): RaindropAISDKClient;
251
297
 
252
- export { type AISDKMessage, type Attachment, type BuildEventPatch, ContextManager, type ContextSpan, type EventBuilder, type EventMetadataOptions, type IdentifyInput, type RaindropAISDKClient, type RaindropAISDKContext, type RaindropAISDKOptions, type WrapAISDKOptions, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent };
298
+ export { type AISDKMessage, type AgentCallMetadata, type AgentWithMetadata, type Attachment, type BuildEventPatch, ContextManager, type ContextSpan, type EventBuilder, type EventMetadataOptions, type IdentifyInput, type RaindropAISDKClient, type RaindropAISDKContext, type RaindropAISDKOptions, type WrapAISDKOptions, type WrappedAI, type WrappedAISDK, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent };
package/dist/index.d.ts CHANGED
@@ -127,6 +127,48 @@ type EventMetadataOptions = {
127
127
  * ```
128
128
  */
129
129
  declare function eventMetadata(options: EventMetadataOptions): Record<string, string>;
130
+ type AgentCallMetadata = ReturnType<typeof eventMetadata>;
131
+ type NormalizeUnknownAgentOptions<T> = T extends {
132
+ options: infer CallOptions;
133
+ } ? unknown extends CallOptions ? Omit<T, "options"> & {
134
+ options?: never;
135
+ } : T : T;
136
+ /**
137
+ * Wraps an agent instance type so `generate()` and `stream()` accept optional
138
+ * Raindrop call metadata while preserving original return types.
139
+ */
140
+ type AgentWithMetadata<A> = A extends {
141
+ generate: (...args: infer GenerateArgs) => infer GenerateReturn;
142
+ stream: (...args: infer StreamArgs) => infer StreamReturn;
143
+ } ? Omit<A, "generate" | "stream"> & {
144
+ generate(...args: GenerateArgs extends [infer Options, ...infer Rest] ? [NormalizeUnknownAgentOptions<Options> & {
145
+ metadata?: AgentCallMetadata;
146
+ }, ...Rest] : GenerateArgs): GenerateReturn;
147
+ stream(...args: StreamArgs extends [infer Options, ...infer Rest] ? [NormalizeUnknownAgentOptions<Options> & {
148
+ metadata?: AgentCallMetadata;
149
+ }, ...Rest] : StreamArgs): StreamReturn;
150
+ } : A;
151
+ /**
152
+ * Structural wrapper type for AI SDK modules.
153
+ *
154
+ * - AI SDK v6: rewrites `ToolLoopAgent` constructor instance methods to accept
155
+ * `metadata` on `generate/stream`.
156
+ * - AI SDK v4/v5: no `ToolLoopAgent` export, so the type is unchanged.
157
+ */
158
+ type WrappedAISDK<T extends object> = T extends {
159
+ ToolLoopAgent: abstract new (...args: any[]) => any;
160
+ } ? Omit<T, "ToolLoopAgent"> & {
161
+ ToolLoopAgent: new (...args: ConstructorParameters<T["ToolLoopAgent"]>) => AgentWithMetadata<InstanceType<T["ToolLoopAgent"]>>;
162
+ } : T;
163
+ /**
164
+ * Backward-compatible alias for wrapped AI SDK module types.
165
+ *
166
+ * This alias intentionally avoids referencing `import("ai")` to satisfy type
167
+ * resolution without requiring `ai` to be installed.
168
+ *
169
+ * Prefer `WrappedAISDK<typeof ai>` in app code when you have an `ai` import.
170
+ */
171
+ type WrappedAI<T extends object = any> = WrappedAISDK<T>;
130
172
  type Attachment = {
131
173
  attachment_id?: string;
132
174
  name?: string;
@@ -139,7 +181,11 @@ type Attachment = {
139
181
  type: "text" | "image" | "iframe";
140
182
  });
141
183
  type RaindropAISDKOptions = {
142
- writeKey: string;
184
+ /**
185
+ * API write key. If omitted, telemetry shipping is disabled but `wrap()` is
186
+ * still available for a consistent integration surface.
187
+ */
188
+ writeKey?: string;
143
189
  endpoint?: string;
144
190
  traces?: {
145
191
  enabled?: boolean;
@@ -217,7 +263,7 @@ type EventPatch = {
217
263
  timestamp?: string;
218
264
  };
219
265
  type RaindropAISDKClient = {
220
- wrap<T extends object>(aiSDK: T, options?: WrapAISDKOptions): T;
266
+ wrap<T extends object>(aiSDK: T, options?: WrapAISDKOptions): WrappedAISDK<T>;
221
267
  events: {
222
268
  patch(eventId: string, patch: EventPatch): Promise<void>;
223
269
  addAttachments(eventId: string, attachments: Attachment[]): Promise<void>;
@@ -249,4 +295,4 @@ type RaindropAISDKClient = {
249
295
  };
250
296
  declare function createRaindropAISDK(opts: RaindropAISDKOptions): RaindropAISDKClient;
251
297
 
252
- export { type AISDKMessage, type Attachment, type BuildEventPatch, ContextManager, type ContextSpan, type EventBuilder, type EventMetadataOptions, type IdentifyInput, type RaindropAISDKClient, type RaindropAISDKContext, type RaindropAISDKOptions, type WrapAISDKOptions, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent };
298
+ export { type AISDKMessage, type AgentCallMetadata, type AgentWithMetadata, type Attachment, type BuildEventPatch, ContextManager, type ContextSpan, type EventBuilder, type EventMetadataOptions, type IdentifyInput, type RaindropAISDKClient, type RaindropAISDKContext, type RaindropAISDKOptions, type WrapAISDKOptions, type WrappedAI, type WrappedAISDK, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent };
package/dist/index.js CHANGED
@@ -86,7 +86,7 @@ async function postJson(url, body, headers, opts) {
86
86
  // package.json
87
87
  var package_default = {
88
88
  name: "@raindrop-ai/ai-sdk",
89
- version: "0.0.8"};
89
+ version: "0.0.9"};
90
90
 
91
91
  // src/internal/version.ts
92
92
  var libraryName = package_default.name;
@@ -120,13 +120,15 @@ var EventShipper = class {
120
120
  this.sticky = /* @__PURE__ */ new Map();
121
121
  this.timers = /* @__PURE__ */ new Map();
122
122
  this.inFlight = /* @__PURE__ */ new Set();
123
- var _a, _b;
124
- if (!opts.writeKey) throw new Error("[raindrop-ai/ai-sdk] writeKey is required");
125
- this.writeKey = opts.writeKey;
126
- this.baseUrl = (_a = formatEndpoint(opts.endpoint)) != null ? _a : "https://api.raindrop.ai/v1/";
123
+ var _a, _b, _c;
124
+ if (opts.enabled && !opts.writeKey) {
125
+ throw new Error("[raindrop-ai/ai-sdk] writeKey is required when events are enabled");
126
+ }
127
+ this.writeKey = (_a = opts.writeKey) != null ? _a : "";
128
+ this.baseUrl = (_b = formatEndpoint(opts.endpoint)) != null ? _b : "https://api.raindrop.ai/v1/";
127
129
  this.enabled = opts.enabled;
128
130
  this.debug = opts.debug;
129
- this.partialFlushMs = (_b = opts.partialFlushMs) != null ? _b : 1e3;
131
+ this.partialFlushMs = (_c = opts.partialFlushMs) != null ? _c : 1e3;
130
132
  this.context = getRuntimeContext();
131
133
  }
132
134
  isDebugEnabled() {
@@ -474,16 +476,18 @@ var TraceShipper = class {
474
476
  constructor(opts) {
475
477
  this.queue = [];
476
478
  this.inFlight = /* @__PURE__ */ new Set();
477
- var _a, _b, _c, _d;
478
- if (!opts.writeKey) throw new Error("[raindrop-ai/ai-sdk] writeKey is required");
479
- this.writeKey = opts.writeKey;
480
- this.baseUrl = (_a = formatEndpoint(opts.endpoint)) != null ? _a : "https://api.raindrop.ai/v1/";
479
+ var _a, _b, _c, _d, _e;
480
+ if (opts.enabled && !opts.writeKey) {
481
+ throw new Error("[raindrop-ai/ai-sdk] writeKey is required when traces are enabled");
482
+ }
483
+ this.writeKey = (_a = opts.writeKey) != null ? _a : "";
484
+ this.baseUrl = (_b = formatEndpoint(opts.endpoint)) != null ? _b : "https://api.raindrop.ai/v1/";
481
485
  this.enabled = opts.enabled;
482
486
  this.debug = opts.debug;
483
487
  this.debugSpans = opts.debugSpans === true;
484
- this.flushIntervalMs = (_b = opts.flushIntervalMs) != null ? _b : 1e3;
485
- this.maxBatchSize = (_c = opts.maxBatchSize) != null ? _c : 50;
486
- this.maxQueueSize = (_d = opts.maxQueueSize) != null ? _d : 5e3;
488
+ this.flushIntervalMs = (_c = opts.flushIntervalMs) != null ? _c : 1e3;
489
+ this.maxBatchSize = (_d = opts.maxBatchSize) != null ? _d : 50;
490
+ this.maxQueueSize = (_e = opts.maxQueueSize) != null ? _e : 5e3;
487
491
  }
488
492
  isDebugEnabled() {
489
493
  return this.debug;
@@ -1254,6 +1258,14 @@ function warnMissingUserIdOnce() {
1254
1258
  function _resetWarnedMissingUserId() {
1255
1259
  warnedMissingUserId = false;
1256
1260
  }
1261
+ function extractRaindropCallOptions(options) {
1262
+ if (!isRecord(options)) return {};
1263
+ const em = options["metadata"];
1264
+ if (isRecord(em)) return extractRaindropMetadata(em);
1265
+ const telemetry = extractExperimentalTelemetry(options);
1266
+ if (telemetry == null ? void 0 : telemetry.metadata) return extractRaindropMetadata(telemetry.metadata);
1267
+ return {};
1268
+ }
1257
1269
  function extractRaindropMetadata(metadata) {
1258
1270
  if (!metadata || typeof metadata !== "object") return {};
1259
1271
  const result = {};
@@ -1776,7 +1788,7 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
1776
1788
  const operation = `${className}.generate`;
1777
1789
  const wrapTimeCtx = resolveContext(deps.options.context, { operation, args: mergedArgs });
1778
1790
  const telemetry = extractExperimentalTelemetry(mergedArgs);
1779
- const callTimeCtx = extractRaindropMetadata(telemetry == null ? void 0 : telemetry.metadata);
1791
+ const callTimeCtx = extractRaindropCallOptions(mergedArgs);
1780
1792
  const mergedCtx = mergeContexts(wrapTimeCtx, callTimeCtx);
1781
1793
  if (!mergedCtx.userId) warnMissingUserIdOnce();
1782
1794
  const inherited = await getCurrentParentSpanContext();
@@ -1964,7 +1976,7 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
1964
1976
  const operation = `${className}.stream`;
1965
1977
  const wrapTimeCtx = resolveContext(deps.options.context, { operation, args: mergedArgs });
1966
1978
  const telemetry = extractExperimentalTelemetry(mergedArgs);
1967
- const callTimeCtx = extractRaindropMetadata(telemetry == null ? void 0 : telemetry.metadata);
1979
+ const callTimeCtx = extractRaindropCallOptions(mergedArgs);
1968
1980
  const mergedCtx = mergeContexts(wrapTimeCtx, callTimeCtx);
1969
1981
  if (!mergedCtx.userId) warnMissingUserIdOnce();
1970
1982
  const inherited = await getCurrentParentSpanContext();
@@ -2634,18 +2646,26 @@ function envDebugEnabled() {
2634
2646
  }
2635
2647
  function createRaindropAISDK(opts) {
2636
2648
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2637
- const eventsEnabled = ((_a = opts.events) == null ? void 0 : _a.enabled) !== false;
2638
- const tracesEnabled = ((_b = opts.traces) == null ? void 0 : _b.enabled) !== false;
2649
+ const writeKey = opts.writeKey;
2650
+ const eventsRequested = ((_a = opts.events) == null ? void 0 : _a.enabled) !== false;
2651
+ const tracesRequested = ((_b = opts.traces) == null ? void 0 : _b.enabled) !== false;
2652
+ const eventsEnabled = eventsRequested && !!writeKey;
2653
+ const tracesEnabled = tracesRequested && !!writeKey;
2639
2654
  const envDebug = envDebugEnabled();
2655
+ if (!writeKey && (eventsRequested || tracesRequested)) {
2656
+ console.warn(
2657
+ "[raindrop-ai/ai-sdk] writeKey not provided; telemetry shipping is disabled"
2658
+ );
2659
+ }
2640
2660
  const eventShipper = new EventShipper({
2641
- writeKey: opts.writeKey,
2661
+ writeKey,
2642
2662
  endpoint: opts.endpoint,
2643
2663
  enabled: eventsEnabled,
2644
2664
  debug: ((_c = opts.events) == null ? void 0 : _c.debug) === true || envDebug,
2645
2665
  partialFlushMs: (_d = opts.events) == null ? void 0 : _d.partialFlushMs
2646
2666
  });
2647
2667
  const traceShipper = new TraceShipper({
2648
- writeKey: opts.writeKey,
2668
+ writeKey,
2649
2669
  endpoint: opts.endpoint,
2650
2670
  enabled: tracesEnabled,
2651
2671
  debug: ((_e = opts.traces) == null ? void 0 : _e.debug) === true || envDebug,
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export { _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './chunk-NFWQZOEK.mjs';
1
+ export { _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './chunk-R5GGKTXI.mjs';
@@ -1,4 +1,4 @@
1
- export { AISDKMessage, Attachment, BuildEventPatch, ContextManager, ContextSpan, EventBuilder, EventMetadataOptions, IdentifyInput, RaindropAISDKClient, RaindropAISDKContext, RaindropAISDKOptions, WrapAISDKOptions, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './index.mjs';
1
+ export { AISDKMessage, AgentCallMetadata, AgentWithMetadata, Attachment, BuildEventPatch, ContextManager, ContextSpan, EventBuilder, EventMetadataOptions, IdentifyInput, RaindropAISDKClient, RaindropAISDKContext, RaindropAISDKOptions, WrapAISDKOptions, WrappedAI, WrappedAISDK, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './index.mjs';
2
2
 
3
3
  declare global {
4
4
  var RAINDROP_ASYNC_LOCAL_STORAGE: (new <T>() => {
@@ -1,4 +1,4 @@
1
- export { AISDKMessage, Attachment, BuildEventPatch, ContextManager, ContextSpan, EventBuilder, EventMetadataOptions, IdentifyInput, RaindropAISDKClient, RaindropAISDKContext, RaindropAISDKOptions, WrapAISDKOptions, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './index.js';
1
+ export { AISDKMessage, AgentCallMetadata, AgentWithMetadata, Attachment, BuildEventPatch, ContextManager, ContextSpan, EventBuilder, EventMetadataOptions, IdentifyInput, RaindropAISDKClient, RaindropAISDKContext, RaindropAISDKOptions, WrapAISDKOptions, WrappedAI, WrappedAISDK, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './index.js';
2
2
 
3
3
  declare global {
4
4
  var RAINDROP_ASYNC_LOCAL_STORAGE: (new <T>() => {
@@ -90,7 +90,7 @@ async function postJson(url, body, headers, opts) {
90
90
  // package.json
91
91
  var package_default = {
92
92
  name: "@raindrop-ai/ai-sdk",
93
- version: "0.0.8"};
93
+ version: "0.0.9"};
94
94
 
95
95
  // src/internal/version.ts
96
96
  var libraryName = package_default.name;
@@ -124,13 +124,15 @@ var EventShipper = class {
124
124
  this.sticky = /* @__PURE__ */ new Map();
125
125
  this.timers = /* @__PURE__ */ new Map();
126
126
  this.inFlight = /* @__PURE__ */ new Set();
127
- var _a, _b;
128
- if (!opts.writeKey) throw new Error("[raindrop-ai/ai-sdk] writeKey is required");
129
- this.writeKey = opts.writeKey;
130
- this.baseUrl = (_a = formatEndpoint(opts.endpoint)) != null ? _a : "https://api.raindrop.ai/v1/";
127
+ var _a, _b, _c;
128
+ if (opts.enabled && !opts.writeKey) {
129
+ throw new Error("[raindrop-ai/ai-sdk] writeKey is required when events are enabled");
130
+ }
131
+ this.writeKey = (_a = opts.writeKey) != null ? _a : "";
132
+ this.baseUrl = (_b = formatEndpoint(opts.endpoint)) != null ? _b : "https://api.raindrop.ai/v1/";
131
133
  this.enabled = opts.enabled;
132
134
  this.debug = opts.debug;
133
- this.partialFlushMs = (_b = opts.partialFlushMs) != null ? _b : 1e3;
135
+ this.partialFlushMs = (_c = opts.partialFlushMs) != null ? _c : 1e3;
134
136
  this.context = getRuntimeContext();
135
137
  }
136
138
  isDebugEnabled() {
@@ -478,16 +480,18 @@ var TraceShipper = class {
478
480
  constructor(opts) {
479
481
  this.queue = [];
480
482
  this.inFlight = /* @__PURE__ */ new Set();
481
- var _a, _b, _c, _d;
482
- if (!opts.writeKey) throw new Error("[raindrop-ai/ai-sdk] writeKey is required");
483
- this.writeKey = opts.writeKey;
484
- this.baseUrl = (_a = formatEndpoint(opts.endpoint)) != null ? _a : "https://api.raindrop.ai/v1/";
483
+ var _a, _b, _c, _d, _e;
484
+ if (opts.enabled && !opts.writeKey) {
485
+ throw new Error("[raindrop-ai/ai-sdk] writeKey is required when traces are enabled");
486
+ }
487
+ this.writeKey = (_a = opts.writeKey) != null ? _a : "";
488
+ this.baseUrl = (_b = formatEndpoint(opts.endpoint)) != null ? _b : "https://api.raindrop.ai/v1/";
485
489
  this.enabled = opts.enabled;
486
490
  this.debug = opts.debug;
487
491
  this.debugSpans = opts.debugSpans === true;
488
- this.flushIntervalMs = (_b = opts.flushIntervalMs) != null ? _b : 1e3;
489
- this.maxBatchSize = (_c = opts.maxBatchSize) != null ? _c : 50;
490
- this.maxQueueSize = (_d = opts.maxQueueSize) != null ? _d : 5e3;
492
+ this.flushIntervalMs = (_c = opts.flushIntervalMs) != null ? _c : 1e3;
493
+ this.maxBatchSize = (_d = opts.maxBatchSize) != null ? _d : 50;
494
+ this.maxQueueSize = (_e = opts.maxQueueSize) != null ? _e : 5e3;
491
495
  }
492
496
  isDebugEnabled() {
493
497
  return this.debug;
@@ -1258,6 +1262,14 @@ function warnMissingUserIdOnce() {
1258
1262
  function _resetWarnedMissingUserId() {
1259
1263
  warnedMissingUserId = false;
1260
1264
  }
1265
+ function extractRaindropCallOptions(options) {
1266
+ if (!isRecord(options)) return {};
1267
+ const em = options["metadata"];
1268
+ if (isRecord(em)) return extractRaindropMetadata(em);
1269
+ const telemetry = extractExperimentalTelemetry(options);
1270
+ if (telemetry == null ? void 0 : telemetry.metadata) return extractRaindropMetadata(telemetry.metadata);
1271
+ return {};
1272
+ }
1261
1273
  function extractRaindropMetadata(metadata) {
1262
1274
  if (!metadata || typeof metadata !== "object") return {};
1263
1275
  const result = {};
@@ -1780,7 +1792,7 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
1780
1792
  const operation = `${className}.generate`;
1781
1793
  const wrapTimeCtx = resolveContext(deps.options.context, { operation, args: mergedArgs });
1782
1794
  const telemetry = extractExperimentalTelemetry(mergedArgs);
1783
- const callTimeCtx = extractRaindropMetadata(telemetry == null ? void 0 : telemetry.metadata);
1795
+ const callTimeCtx = extractRaindropCallOptions(mergedArgs);
1784
1796
  const mergedCtx = mergeContexts(wrapTimeCtx, callTimeCtx);
1785
1797
  if (!mergedCtx.userId) warnMissingUserIdOnce();
1786
1798
  const inherited = await getCurrentParentSpanContext();
@@ -1968,7 +1980,7 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
1968
1980
  const operation = `${className}.stream`;
1969
1981
  const wrapTimeCtx = resolveContext(deps.options.context, { operation, args: mergedArgs });
1970
1982
  const telemetry = extractExperimentalTelemetry(mergedArgs);
1971
- const callTimeCtx = extractRaindropMetadata(telemetry == null ? void 0 : telemetry.metadata);
1983
+ const callTimeCtx = extractRaindropCallOptions(mergedArgs);
1972
1984
  const mergedCtx = mergeContexts(wrapTimeCtx, callTimeCtx);
1973
1985
  if (!mergedCtx.userId) warnMissingUserIdOnce();
1974
1986
  const inherited = await getCurrentParentSpanContext();
@@ -2638,18 +2650,26 @@ function envDebugEnabled() {
2638
2650
  }
2639
2651
  function createRaindropAISDK(opts) {
2640
2652
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2641
- const eventsEnabled = ((_a = opts.events) == null ? void 0 : _a.enabled) !== false;
2642
- const tracesEnabled = ((_b = opts.traces) == null ? void 0 : _b.enabled) !== false;
2653
+ const writeKey = opts.writeKey;
2654
+ const eventsRequested = ((_a = opts.events) == null ? void 0 : _a.enabled) !== false;
2655
+ const tracesRequested = ((_b = opts.traces) == null ? void 0 : _b.enabled) !== false;
2656
+ const eventsEnabled = eventsRequested && !!writeKey;
2657
+ const tracesEnabled = tracesRequested && !!writeKey;
2643
2658
  const envDebug = envDebugEnabled();
2659
+ if (!writeKey && (eventsRequested || tracesRequested)) {
2660
+ console.warn(
2661
+ "[raindrop-ai/ai-sdk] writeKey not provided; telemetry shipping is disabled"
2662
+ );
2663
+ }
2644
2664
  const eventShipper = new EventShipper({
2645
- writeKey: opts.writeKey,
2665
+ writeKey,
2646
2666
  endpoint: opts.endpoint,
2647
2667
  enabled: eventsEnabled,
2648
2668
  debug: ((_c = opts.events) == null ? void 0 : _c.debug) === true || envDebug,
2649
2669
  partialFlushMs: (_d = opts.events) == null ? void 0 : _d.partialFlushMs
2650
2670
  });
2651
2671
  const traceShipper = new TraceShipper({
2652
- writeKey: opts.writeKey,
2672
+ writeKey,
2653
2673
  endpoint: opts.endpoint,
2654
2674
  enabled: tracesEnabled,
2655
2675
  debug: ((_e = opts.traces) == null ? void 0 : _e.debug) === true || envDebug,
@@ -1,4 +1,4 @@
1
- export { _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './chunk-NFWQZOEK.mjs';
1
+ export { _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './chunk-R5GGKTXI.mjs';
2
2
  import { AsyncLocalStorage } from 'async_hooks';
3
3
 
4
4
  globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = AsyncLocalStorage;
@@ -1,4 +1,4 @@
1
- export { AISDKMessage, Attachment, BuildEventPatch, ContextManager, ContextSpan, EventBuilder, EventMetadataOptions, IdentifyInput, RaindropAISDKClient, RaindropAISDKContext, RaindropAISDKOptions, WrapAISDKOptions, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './index.mjs';
1
+ export { AISDKMessage, AgentCallMetadata, AgentWithMetadata, Attachment, BuildEventPatch, ContextManager, ContextSpan, EventBuilder, EventMetadataOptions, IdentifyInput, RaindropAISDKClient, RaindropAISDKContext, RaindropAISDKOptions, WrapAISDKOptions, WrappedAI, WrappedAISDK, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './index.mjs';
2
2
 
3
3
  declare global {
4
4
  var RAINDROP_ASYNC_LOCAL_STORAGE: (new <T>() => {
@@ -1,4 +1,4 @@
1
- export { AISDKMessage, Attachment, BuildEventPatch, ContextManager, ContextSpan, EventBuilder, EventMetadataOptions, IdentifyInput, RaindropAISDKClient, RaindropAISDKContext, RaindropAISDKOptions, WrapAISDKOptions, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './index.js';
1
+ export { AISDKMessage, AgentCallMetadata, AgentWithMetadata, Attachment, BuildEventPatch, ContextManager, ContextSpan, EventBuilder, EventMetadataOptions, IdentifyInput, RaindropAISDKClient, RaindropAISDKContext, RaindropAISDKOptions, WrapAISDKOptions, WrappedAI, WrappedAISDK, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './index.js';
2
2
 
3
3
  declare global {
4
4
  var RAINDROP_ASYNC_LOCAL_STORAGE: (new <T>() => {
@@ -90,7 +90,7 @@ async function postJson(url, body, headers, opts) {
90
90
  // package.json
91
91
  var package_default = {
92
92
  name: "@raindrop-ai/ai-sdk",
93
- version: "0.0.8"};
93
+ version: "0.0.9"};
94
94
 
95
95
  // src/internal/version.ts
96
96
  var libraryName = package_default.name;
@@ -124,13 +124,15 @@ var EventShipper = class {
124
124
  this.sticky = /* @__PURE__ */ new Map();
125
125
  this.timers = /* @__PURE__ */ new Map();
126
126
  this.inFlight = /* @__PURE__ */ new Set();
127
- var _a, _b;
128
- if (!opts.writeKey) throw new Error("[raindrop-ai/ai-sdk] writeKey is required");
129
- this.writeKey = opts.writeKey;
130
- this.baseUrl = (_a = formatEndpoint(opts.endpoint)) != null ? _a : "https://api.raindrop.ai/v1/";
127
+ var _a, _b, _c;
128
+ if (opts.enabled && !opts.writeKey) {
129
+ throw new Error("[raindrop-ai/ai-sdk] writeKey is required when events are enabled");
130
+ }
131
+ this.writeKey = (_a = opts.writeKey) != null ? _a : "";
132
+ this.baseUrl = (_b = formatEndpoint(opts.endpoint)) != null ? _b : "https://api.raindrop.ai/v1/";
131
133
  this.enabled = opts.enabled;
132
134
  this.debug = opts.debug;
133
- this.partialFlushMs = (_b = opts.partialFlushMs) != null ? _b : 1e3;
135
+ this.partialFlushMs = (_c = opts.partialFlushMs) != null ? _c : 1e3;
134
136
  this.context = getRuntimeContext();
135
137
  }
136
138
  isDebugEnabled() {
@@ -478,16 +480,18 @@ var TraceShipper = class {
478
480
  constructor(opts) {
479
481
  this.queue = [];
480
482
  this.inFlight = /* @__PURE__ */ new Set();
481
- var _a, _b, _c, _d;
482
- if (!opts.writeKey) throw new Error("[raindrop-ai/ai-sdk] writeKey is required");
483
- this.writeKey = opts.writeKey;
484
- this.baseUrl = (_a = formatEndpoint(opts.endpoint)) != null ? _a : "https://api.raindrop.ai/v1/";
483
+ var _a, _b, _c, _d, _e;
484
+ if (opts.enabled && !opts.writeKey) {
485
+ throw new Error("[raindrop-ai/ai-sdk] writeKey is required when traces are enabled");
486
+ }
487
+ this.writeKey = (_a = opts.writeKey) != null ? _a : "";
488
+ this.baseUrl = (_b = formatEndpoint(opts.endpoint)) != null ? _b : "https://api.raindrop.ai/v1/";
485
489
  this.enabled = opts.enabled;
486
490
  this.debug = opts.debug;
487
491
  this.debugSpans = opts.debugSpans === true;
488
- this.flushIntervalMs = (_b = opts.flushIntervalMs) != null ? _b : 1e3;
489
- this.maxBatchSize = (_c = opts.maxBatchSize) != null ? _c : 50;
490
- this.maxQueueSize = (_d = opts.maxQueueSize) != null ? _d : 5e3;
492
+ this.flushIntervalMs = (_c = opts.flushIntervalMs) != null ? _c : 1e3;
493
+ this.maxBatchSize = (_d = opts.maxBatchSize) != null ? _d : 50;
494
+ this.maxQueueSize = (_e = opts.maxQueueSize) != null ? _e : 5e3;
491
495
  }
492
496
  isDebugEnabled() {
493
497
  return this.debug;
@@ -1258,6 +1262,14 @@ function warnMissingUserIdOnce() {
1258
1262
  function _resetWarnedMissingUserId() {
1259
1263
  warnedMissingUserId = false;
1260
1264
  }
1265
+ function extractRaindropCallOptions(options) {
1266
+ if (!isRecord(options)) return {};
1267
+ const em = options["metadata"];
1268
+ if (isRecord(em)) return extractRaindropMetadata(em);
1269
+ const telemetry = extractExperimentalTelemetry(options);
1270
+ if (telemetry == null ? void 0 : telemetry.metadata) return extractRaindropMetadata(telemetry.metadata);
1271
+ return {};
1272
+ }
1261
1273
  function extractRaindropMetadata(metadata) {
1262
1274
  if (!metadata || typeof metadata !== "object") return {};
1263
1275
  const result = {};
@@ -1780,7 +1792,7 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
1780
1792
  const operation = `${className}.generate`;
1781
1793
  const wrapTimeCtx = resolveContext(deps.options.context, { operation, args: mergedArgs });
1782
1794
  const telemetry = extractExperimentalTelemetry(mergedArgs);
1783
- const callTimeCtx = extractRaindropMetadata(telemetry == null ? void 0 : telemetry.metadata);
1795
+ const callTimeCtx = extractRaindropCallOptions(mergedArgs);
1784
1796
  const mergedCtx = mergeContexts(wrapTimeCtx, callTimeCtx);
1785
1797
  if (!mergedCtx.userId) warnMissingUserIdOnce();
1786
1798
  const inherited = await getCurrentParentSpanContext();
@@ -1968,7 +1980,7 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
1968
1980
  const operation = `${className}.stream`;
1969
1981
  const wrapTimeCtx = resolveContext(deps.options.context, { operation, args: mergedArgs });
1970
1982
  const telemetry = extractExperimentalTelemetry(mergedArgs);
1971
- const callTimeCtx = extractRaindropMetadata(telemetry == null ? void 0 : telemetry.metadata);
1983
+ const callTimeCtx = extractRaindropCallOptions(mergedArgs);
1972
1984
  const mergedCtx = mergeContexts(wrapTimeCtx, callTimeCtx);
1973
1985
  if (!mergedCtx.userId) warnMissingUserIdOnce();
1974
1986
  const inherited = await getCurrentParentSpanContext();
@@ -2638,18 +2650,26 @@ function envDebugEnabled() {
2638
2650
  }
2639
2651
  function createRaindropAISDK(opts) {
2640
2652
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2641
- const eventsEnabled = ((_a = opts.events) == null ? void 0 : _a.enabled) !== false;
2642
- const tracesEnabled = ((_b = opts.traces) == null ? void 0 : _b.enabled) !== false;
2653
+ const writeKey = opts.writeKey;
2654
+ const eventsRequested = ((_a = opts.events) == null ? void 0 : _a.enabled) !== false;
2655
+ const tracesRequested = ((_b = opts.traces) == null ? void 0 : _b.enabled) !== false;
2656
+ const eventsEnabled = eventsRequested && !!writeKey;
2657
+ const tracesEnabled = tracesRequested && !!writeKey;
2643
2658
  const envDebug = envDebugEnabled();
2659
+ if (!writeKey && (eventsRequested || tracesRequested)) {
2660
+ console.warn(
2661
+ "[raindrop-ai/ai-sdk] writeKey not provided; telemetry shipping is disabled"
2662
+ );
2663
+ }
2644
2664
  const eventShipper = new EventShipper({
2645
- writeKey: opts.writeKey,
2665
+ writeKey,
2646
2666
  endpoint: opts.endpoint,
2647
2667
  enabled: eventsEnabled,
2648
2668
  debug: ((_c = opts.events) == null ? void 0 : _c.debug) === true || envDebug,
2649
2669
  partialFlushMs: (_d = opts.events) == null ? void 0 : _d.partialFlushMs
2650
2670
  });
2651
2671
  const traceShipper = new TraceShipper({
2652
- writeKey: opts.writeKey,
2672
+ writeKey,
2653
2673
  endpoint: opts.endpoint,
2654
2674
  enabled: tracesEnabled,
2655
2675
  debug: ((_e = opts.traces) == null ? void 0 : _e.debug) === true || envDebug,
@@ -1,4 +1,4 @@
1
- export { _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './chunk-NFWQZOEK.mjs';
1
+ export { _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './chunk-R5GGKTXI.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.8",
3
+ "version": "0.0.9",
4
4
  "description": "Standalone Vercel AI SDK integration for Raindrop (events + OTLP/HTTP JSON traces, no OTEL runtime)",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -45,6 +45,9 @@
45
45
  "tsx": "^4.20.3",
46
46
  "typescript": "^5.3.3"
47
47
  },
48
+ "peerDependencies": {
49
+ "ai": ">=4 <7"
50
+ },
48
51
  "tsup": {
49
52
  "entry": [
50
53
  "src/index.ts",