@raindrop-ai/ai-sdk 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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.2"};
93
+ version: "0.0.3"};
94
94
 
95
95
  // src/internal/version.ts
96
96
  var libraryName = package_default.name;
@@ -137,19 +137,30 @@ var EventShipper = class {
137
137
  return this.debug;
138
138
  }
139
139
  async patch(eventId, patch) {
140
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
140
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
141
141
  if (!this.enabled) return;
142
142
  if (!eventId) return;
143
- const sticky = (_a = this.sticky.get(eventId)) != null ? _a : {};
144
- const existing = (_b = this.buffers.get(eventId)) != null ? _b : {};
143
+ if (this.debug) {
144
+ console.log("[raindrop-ai/ai-sdk] queue patch", {
145
+ eventId,
146
+ userId: patch.userId,
147
+ eventName: patch.eventName,
148
+ hasInput: typeof patch.input === "string" && patch.input.length > 0,
149
+ hasOutput: typeof patch.output === "string" && patch.output.length > 0,
150
+ attachments: (_b = (_a = patch.attachments) == null ? void 0 : _a.length) != null ? _b : 0,
151
+ isPending: patch.isPending
152
+ });
153
+ }
154
+ const sticky = (_c = this.sticky.get(eventId)) != null ? _c : {};
155
+ const existing = (_d = this.buffers.get(eventId)) != null ? _d : {};
145
156
  const merged = mergePatches(existing, patch);
146
- merged.isPending = (_e = (_d = (_c = patch.isPending) != null ? _c : existing.isPending) != null ? _d : sticky.isPending) != null ? _e : true;
157
+ merged.isPending = (_g = (_f = (_e = patch.isPending) != null ? _e : existing.isPending) != null ? _f : sticky.isPending) != null ? _g : true;
147
158
  this.buffers.set(eventId, merged);
148
159
  this.sticky.set(eventId, {
149
- userId: (_f = merged.userId) != null ? _f : sticky.userId,
150
- convoId: (_g = merged.convoId) != null ? _g : sticky.convoId,
151
- eventName: (_h = merged.eventName) != null ? _h : sticky.eventName,
152
- isPending: (_i = merged.isPending) != null ? _i : sticky.isPending
160
+ userId: (_h = merged.userId) != null ? _h : sticky.userId,
161
+ convoId: (_i = merged.convoId) != null ? _i : sticky.convoId,
162
+ eventName: (_j = merged.eventName) != null ? _j : sticky.eventName,
163
+ isPending: (_k = merged.isPending) != null ? _k : sticky.isPending
153
164
  });
154
165
  const t = this.timers.get(eventId);
155
166
  if (t) clearTimeout(t);
@@ -246,7 +257,7 @@ var EventShipper = class {
246
257
  }
247
258
  }
248
259
  async flushOne(eventId) {
249
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
260
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
250
261
  if (!this.enabled) return;
251
262
  const timer = this.timers.get(eventId);
252
263
  if (timer) {
@@ -284,6 +295,24 @@ var EventShipper = class {
284
295
  is_pending: ((_i = (_h = accumulated.isPending) != null ? _h : sticky.isPending) != null ? _i : true) !== false
285
296
  };
286
297
  const url = `${this.baseUrl}events/track_partial`;
298
+ if (this.debug) {
299
+ console.log("[raindrop-ai/ai-sdk] sending track_partial", {
300
+ eventId,
301
+ eventName,
302
+ userId,
303
+ isPending: payload.is_pending,
304
+ inputPreview: typeof accumulated.input === "string" ? accumulated.input.slice(0, 120) : void 0,
305
+ outputPreview: typeof accumulated.output === "string" ? accumulated.output.slice(0, 120) : void 0,
306
+ attachments: (_k = (_j = accumulated.attachments) == null ? void 0 : _j.length) != null ? _k : 0,
307
+ attachmentKinds: (_m = (_l = accumulated.attachments) == null ? void 0 : _l.map((a) => ({
308
+ type: a.type,
309
+ role: a.role,
310
+ name: a.name,
311
+ valuePreview: a.value.slice(0, 60)
312
+ }))) != null ? _m : [],
313
+ endpoint: url
314
+ });
315
+ }
287
316
  const p = postJson(
288
317
  url,
289
318
  payload,
@@ -526,6 +555,12 @@ var TraceShipper = class {
526
555
  const batch = this.queue.splice(0, this.maxBatchSize);
527
556
  const body = buildExportTraceServiceRequest(batch);
528
557
  const url = `${this.baseUrl}traces`;
558
+ if (this.debug) {
559
+ console.log("[raindrop-ai/ai-sdk] sending traces batch", {
560
+ spans: batch.length,
561
+ endpoint: url
562
+ });
563
+ }
529
564
  const p = postJson(
530
565
  url,
531
566
  body,
@@ -863,6 +898,174 @@ function extractFinishReason(result) {
863
898
  }
864
899
  return void 0;
865
900
  }
901
+ function bytesToBase64(bytes) {
902
+ if (typeof Buffer !== "undefined") return Buffer.from(bytes).toString("base64");
903
+ let binary = "";
904
+ for (let i = 0; i < bytes.length; i++) {
905
+ binary += String.fromCharCode(bytes[i]);
906
+ }
907
+ if (typeof btoa === "function") return btoa(binary);
908
+ return "";
909
+ }
910
+ function asDataUrl(value, mediaType) {
911
+ if (value instanceof URL) return value.toString();
912
+ if (typeof value === "string") {
913
+ if (value.startsWith("data:")) return value;
914
+ if (value.startsWith("http://") || value.startsWith("https://")) return value;
915
+ return `data:${mediaType};base64,${value}`;
916
+ }
917
+ if (value instanceof Uint8Array) {
918
+ const base64 = bytesToBase64(value);
919
+ if (!base64) return void 0;
920
+ return `data:${mediaType};base64,${base64}`;
921
+ }
922
+ if (value instanceof ArrayBuffer) {
923
+ const base64 = bytesToBase64(new Uint8Array(value));
924
+ if (!base64) return void 0;
925
+ return `data:${mediaType};base64,${base64}`;
926
+ }
927
+ return void 0;
928
+ }
929
+ function dataPartToAttachmentValue(value) {
930
+ if (typeof value === "string") return value;
931
+ if (value instanceof URL) return value.toString();
932
+ if (value instanceof Uint8Array) return `[binary:${value.byteLength} bytes]`;
933
+ if (value instanceof ArrayBuffer) return `[binary:${value.byteLength} bytes]`;
934
+ return void 0;
935
+ }
936
+ function attachmentMediaType(part) {
937
+ if (typeof part["mediaType"] === "string") return part["mediaType"];
938
+ if (typeof part["mimeType"] === "string") return part["mimeType"];
939
+ const file = part["file"];
940
+ if (isRecord(file)) {
941
+ if (typeof file["mediaType"] === "string") return file["mediaType"];
942
+ if (typeof file["mimeType"] === "string") return file["mimeType"];
943
+ }
944
+ return void 0;
945
+ }
946
+ function attachmentName(part) {
947
+ if (typeof part["filename"] === "string") return part["filename"];
948
+ if (typeof part["name"] === "string") return part["name"];
949
+ const file = part["file"];
950
+ if (isRecord(file)) {
951
+ if (typeof file["filename"] === "string") return file["filename"];
952
+ if (typeof file["name"] === "string") return file["name"];
953
+ }
954
+ return void 0;
955
+ }
956
+ function attachmentData(part) {
957
+ if ("data" in part) return part["data"];
958
+ const file = part["file"];
959
+ if (isRecord(file)) {
960
+ if ("file_data" in file) return file["file_data"];
961
+ if ("data" in file) return file["data"];
962
+ }
963
+ return void 0;
964
+ }
965
+ function contentPartToAttachment(part, role) {
966
+ var _a, _b, _c;
967
+ const partType = part["type"];
968
+ if (typeof partType !== "string") return void 0;
969
+ if (partType === "image") {
970
+ const mediaType = (_a = attachmentMediaType(part)) != null ? _a : "image/png";
971
+ const value = asDataUrl(part["image"], mediaType);
972
+ if (!value) return void 0;
973
+ return { type: "image", role, value };
974
+ }
975
+ if (partType === "image_url") {
976
+ const imageUrlPart = part["image_url"];
977
+ const imageUrlValue = isRecord(imageUrlPart) ? imageUrlPart["url"] : imageUrlPart;
978
+ const value = asDataUrl(imageUrlValue, "image/png");
979
+ if (!value) return void 0;
980
+ return { type: "image", role, value };
981
+ }
982
+ if (partType === "file") {
983
+ const mediaType = attachmentMediaType(part);
984
+ const data = attachmentData(part);
985
+ const isImage = (mediaType == null ? void 0 : mediaType.startsWith("image/")) === true;
986
+ const value = isImage && mediaType ? asDataUrl(data, mediaType) : dataPartToAttachmentValue(data);
987
+ if (!value) return void 0;
988
+ const name = (_c = (_b = attachmentName(part)) != null ? _b : mediaType) != null ? _c : "file";
989
+ return { type: isImage ? "image" : "text", role, name, value };
990
+ }
991
+ return void 0;
992
+ }
993
+ function attachmentsFromContent(content, role) {
994
+ if (!Array.isArray(content)) return void 0;
995
+ const attachments = [];
996
+ for (const part of content) {
997
+ if (!isRecord(part)) continue;
998
+ const attachment = contentPartToAttachment(part, role);
999
+ if (attachment) attachments.push(attachment);
1000
+ }
1001
+ return attachments.length ? attachments : void 0;
1002
+ }
1003
+ function generatedFileToAttachment(file) {
1004
+ var _a, _b, _c, _d;
1005
+ const mediaType = typeof file["mediaType"] === "string" ? file["mediaType"] : typeof file["mimeType"] === "string" ? file["mimeType"] : void 0;
1006
+ const data = (_d = (_c = (_b = (_a = file["base64Data"]) != null ? _a : file["base64"]) != null ? _b : file["uint8ArrayData"]) != null ? _c : file["uint8Array"]) != null ? _d : file["data"];
1007
+ const isImage = (mediaType == null ? void 0 : mediaType.startsWith("image/")) === true;
1008
+ const value = isImage && mediaType ? asDataUrl(data, mediaType) : dataPartToAttachmentValue(data);
1009
+ if (!value) return void 0;
1010
+ const name = typeof file["filename"] === "string" ? file["filename"] : typeof file["name"] === "string" ? file["name"] : mediaType != null ? mediaType : "file";
1011
+ return {
1012
+ type: isImage ? "image" : "text",
1013
+ role: "output",
1014
+ name,
1015
+ value
1016
+ };
1017
+ }
1018
+ async function outputAttachmentsFromFiles(files) {
1019
+ let resolvedFiles = files;
1020
+ if (resolvedFiles && (typeof resolvedFiles === "object" || typeof resolvedFiles === "function") && typeof resolvedFiles.then === "function") {
1021
+ try {
1022
+ resolvedFiles = await resolvedFiles;
1023
+ } catch (e) {
1024
+ return void 0;
1025
+ }
1026
+ }
1027
+ if (!Array.isArray(resolvedFiles)) return void 0;
1028
+ const attachments = [];
1029
+ for (const file of resolvedFiles) {
1030
+ if (!isRecord(file)) continue;
1031
+ const attachment = generatedFileToAttachment(file);
1032
+ if (attachment) attachments.push(attachment);
1033
+ }
1034
+ return attachments.length ? attachments : void 0;
1035
+ }
1036
+ function extractTextFromMessageContent(content) {
1037
+ if (typeof content === "string") return content;
1038
+ if (!Array.isArray(content)) return void 0;
1039
+ let result = "";
1040
+ for (const part of content) {
1041
+ if (!isRecord(part) || part["type"] !== "text" || typeof part["text"] !== "string") continue;
1042
+ result += part["text"];
1043
+ }
1044
+ return result.length ? result : void 0;
1045
+ }
1046
+ function extractInputAttachmentsFromArgs(args) {
1047
+ if (!isRecord(args)) return void 0;
1048
+ const messages = args["messages"];
1049
+ if (!Array.isArray(messages)) return void 0;
1050
+ for (let i = messages.length - 1; i >= 0; i--) {
1051
+ const message = messages[i];
1052
+ if (!isRecord(message) || message["role"] !== "user") continue;
1053
+ return attachmentsFromContent(message["content"], "input");
1054
+ }
1055
+ return void 0;
1056
+ }
1057
+ async function extractOutputAttachmentsFromResult(result) {
1058
+ if (!isRecord(result)) return void 0;
1059
+ const fileAttachments = await outputAttachmentsFromFiles(result["files"]);
1060
+ if (fileAttachments == null ? void 0 : fileAttachments.length) return fileAttachments;
1061
+ const responseMessages = extractResponseMessages(result);
1062
+ for (let i = responseMessages.length - 1; i >= 0; i--) {
1063
+ const message = responseMessages[i];
1064
+ if (!isRecord(message) || message["role"] !== "assistant") continue;
1065
+ return attachmentsFromContent(message["content"], "output");
1066
+ }
1067
+ return attachmentsFromContent(result["content"], "output");
1068
+ }
866
1069
  function lastUserMessageTextFromArgs(args) {
867
1070
  var _a;
868
1071
  if (!isRecord(args)) return void 0;
@@ -872,7 +1075,8 @@ function lastUserMessageTextFromArgs(args) {
872
1075
  const message = messages[i];
873
1076
  if (!isRecord(message) || message["role"] !== "user") continue;
874
1077
  const content = message["content"];
875
- if (typeof content === "string") return content;
1078
+ const text = extractTextFromMessageContent(content);
1079
+ if (text !== void 0) return text;
876
1080
  return (_a = safeJsonWithUint8(content)) != null ? _a : String(content);
877
1081
  }
878
1082
  return void 0;
@@ -887,7 +1091,8 @@ function extractInputFromArgs(args) {
887
1091
  const last = messages[messages.length - 1];
888
1092
  if (isRecord(last)) {
889
1093
  const content = last["content"];
890
- if (typeof content === "string") return content;
1094
+ const text = extractTextFromMessageContent(content);
1095
+ if (text !== void 0) return text;
891
1096
  const asJson = safeJson(content);
892
1097
  if (asJson) return asJson;
893
1098
  }
@@ -921,7 +1126,9 @@ function extractResponseMessages(result) {
921
1126
  if (!isRecord(result)) return [];
922
1127
  const response = result["response"];
923
1128
  if (isRecord(response) && Array.isArray(response["messages"])) {
924
- return response["messages"].filter((message) => isRecord(message) && typeof message["role"] === "string" && "content" in message).map((message) => message);
1129
+ return response["messages"].filter(
1130
+ (message) => isRecord(message) && typeof message["role"] === "string" && "content" in message
1131
+ ).map((message) => message);
925
1132
  }
926
1133
  const steps = result["steps"];
927
1134
  if (Array.isArray(steps) && steps.length > 0) {
@@ -929,7 +1136,9 @@ function extractResponseMessages(result) {
929
1136
  if (isRecord(lastStep) && isRecord(lastStep["response"])) {
930
1137
  const responseMessages = lastStep["response"]["messages"];
931
1138
  if (Array.isArray(responseMessages)) {
932
- return responseMessages.filter((message) => isRecord(message) && typeof message["role"] === "string" && "content" in message).map((message) => message);
1139
+ return responseMessages.filter(
1140
+ (message) => isRecord(message) && typeof message["role"] === "string" && "content" in message
1141
+ ).map((message) => message);
933
1142
  }
934
1143
  }
935
1144
  }
@@ -979,9 +1188,11 @@ function opName(operationId, functionId) {
979
1188
  function toOtlpAttr(key, value) {
980
1189
  if (value === void 0 || value === null) return void 0;
981
1190
  if (typeof value === "string") return attrString(key, value);
982
- if (typeof value === "number") return Number.isInteger(value) ? attrInt(key, value) : attrDouble(key, value);
1191
+ if (typeof value === "number")
1192
+ return Number.isInteger(value) ? attrInt(key, value) : attrDouble(key, value);
983
1193
  if (typeof value === "boolean") return attrBool(key, value);
984
- if (Array.isArray(value) && value.every((v) => typeof v === "string")) return attrStringArray(key, value);
1194
+ if (Array.isArray(value) && value.every((v) => typeof v === "string"))
1195
+ return attrStringArray(key, value);
985
1196
  const asJson = safeJsonWithUint8(value);
986
1197
  return asJson ? attrString(key, asJson) : void 0;
987
1198
  }
@@ -1027,13 +1238,31 @@ function attrsFromSettings(args) {
1027
1238
  function attrsFromGenAiRequest(options) {
1028
1239
  if (!isRecord(options)) return [];
1029
1240
  return [
1030
- attrDouble("gen_ai.request.frequency_penalty", typeof options["frequencyPenalty"] === "number" ? options["frequencyPenalty"] : void 0),
1031
- attrInt("gen_ai.request.max_tokens", typeof options["maxOutputTokens"] === "number" ? options["maxOutputTokens"] : void 0),
1032
- attrDouble("gen_ai.request.presence_penalty", typeof options["presencePenalty"] === "number" ? options["presencePenalty"] : void 0),
1241
+ attrDouble(
1242
+ "gen_ai.request.frequency_penalty",
1243
+ typeof options["frequencyPenalty"] === "number" ? options["frequencyPenalty"] : void 0
1244
+ ),
1245
+ attrInt(
1246
+ "gen_ai.request.max_tokens",
1247
+ typeof options["maxOutputTokens"] === "number" ? options["maxOutputTokens"] : void 0
1248
+ ),
1249
+ attrDouble(
1250
+ "gen_ai.request.presence_penalty",
1251
+ typeof options["presencePenalty"] === "number" ? options["presencePenalty"] : void 0
1252
+ ),
1033
1253
  ...Array.isArray(options["stopSequences"]) && options["stopSequences"].every((x) => typeof x === "string") ? [attrStringArray("gen_ai.request.stop_sequences", options["stopSequences"])] : [],
1034
- attrDouble("gen_ai.request.temperature", typeof options["temperature"] === "number" ? options["temperature"] : void 0),
1035
- attrInt("gen_ai.request.top_k", typeof options["topK"] === "number" ? options["topK"] : void 0),
1036
- attrDouble("gen_ai.request.top_p", typeof options["topP"] === "number" ? options["topP"] : void 0)
1254
+ attrDouble(
1255
+ "gen_ai.request.temperature",
1256
+ typeof options["temperature"] === "number" ? options["temperature"] : void 0
1257
+ ),
1258
+ attrInt(
1259
+ "gen_ai.request.top_k",
1260
+ typeof options["topK"] === "number" ? options["topK"] : void 0
1261
+ ),
1262
+ attrDouble(
1263
+ "gen_ai.request.top_p",
1264
+ typeof options["topP"] === "number" ? options["topP"] : void 0
1265
+ )
1037
1266
  ];
1038
1267
  }
1039
1268
 
@@ -1081,6 +1310,7 @@ function wrapAISDK(aiSDK, deps) {
1081
1310
  const agentClasses = /* @__PURE__ */ new Set(["ToolLoopAgent"]);
1082
1311
  const sendEvents = ((_a = deps.options.send) == null ? void 0 : _a.events) !== false;
1083
1312
  const sendTraces = ((_b = deps.options.send) == null ? void 0 : _b.traces) !== false;
1313
+ const autoAttachmentEnabled = deps.options.autoAttachment !== false;
1084
1314
  const proxyTarget = isModuleNamespace(aiSDK) ? Object.setPrototypeOf({}, aiSDK) : aiSDK;
1085
1315
  return new Proxy(proxyTarget, {
1086
1316
  get(target, prop, receiver) {
@@ -1134,14 +1364,27 @@ function wrapAISDK(aiSDK, deps) {
1134
1364
  ]
1135
1365
  }) : void 0;
1136
1366
  const rootParentForChildren = rootSpan ? { traceIdB64: rootSpan.ids.traceIdB64, spanIdB64: rootSpan.ids.spanIdB64 } : inheritedParent;
1137
- const wrapCtx = { eventId, telemetry, sendTraces, traceShipper: deps.traceShipper, rootParentForChildren };
1367
+ const wrapCtx = {
1368
+ eventId,
1369
+ telemetry,
1370
+ sendTraces,
1371
+ traceShipper: deps.traceShipper,
1372
+ rootParentForChildren
1373
+ };
1138
1374
  const toolCalls = [];
1139
1375
  const argWithWrappedTools = wrapTools(arg, wrapCtx, toolCalls);
1140
- const argWithWrappedModel = wrapModel(argWithWrappedTools, aiSDK, outerOperationId, wrapCtx);
1376
+ const argWithWrappedModel = wrapModel(
1377
+ argWithWrappedTools,
1378
+ aiSDK,
1379
+ outerOperationId,
1380
+ wrapCtx
1381
+ );
1141
1382
  const finalize = async (result, error) => {
1142
1383
  var _a3, _b3, _c2;
1143
1384
  const usage = extractUsage(result);
1144
1385
  const model = extractModel(result);
1386
+ const inputAttachments = autoAttachmentEnabled ? extractInputAttachmentsFromArgs(arg) : void 0;
1387
+ const outputAttachments = autoAttachmentEnabled ? await extractOutputAttachmentsFromResult(result) : void 0;
1145
1388
  const baseMessages = coerceMessagesFromArgs(arg);
1146
1389
  const responseMessages = extractResponseMessages(result);
1147
1390
  const allMessages = [...baseMessages, ...responseMessages];
@@ -1154,7 +1397,7 @@ function wrapAISDK(aiSDK, deps) {
1154
1397
  output: defaultOutput,
1155
1398
  model,
1156
1399
  properties: ctx.properties,
1157
- attachments: ctx.attachments
1400
+ attachments: mergeAttachments(ctx.attachments, inputAttachments, outputAttachments)
1158
1401
  };
1159
1402
  const built = await maybeBuildEvent(deps.options.buildEvent, allMessages);
1160
1403
  const patch = mergeBuildEventPatch(defaultPatch, built);
@@ -1174,7 +1417,10 @@ function wrapAISDK(aiSDK, deps) {
1174
1417
  attrString("ai.response.finishReason", finishReason),
1175
1418
  operation === "generateObject" || operation === "streamObject" ? attrString("ai.response.object", output) : attrString("ai.response.text", output),
1176
1419
  attrString("ai.response.toolCalls", resultToolCalls),
1177
- attrString("ai.response.providerMetadata", safeJsonWithUint8(providerMetadata))
1420
+ attrString(
1421
+ "ai.response.providerMetadata",
1422
+ safeJsonWithUint8(providerMetadata)
1423
+ )
1178
1424
  ],
1179
1425
  attrInt("ai.usage.promptTokens", usage == null ? void 0 : usage.inputTokens),
1180
1426
  attrInt("ai.usage.completionTokens", usage == null ? void 0 : usage.outputTokens),
@@ -1184,7 +1430,12 @@ function wrapAISDK(aiSDK, deps) {
1184
1430
  attrInt("ai.usage.reasoningTokens", reasoningTokens),
1185
1431
  attrInt("ai.usage.cachedInputTokens", cachedInputTokens),
1186
1432
  attrInt("ai.toolCall.count", toolCalls.length),
1187
- ...error ? [attrString("error.message", error instanceof Error ? error.message : String(error))] : []
1433
+ ...error ? [
1434
+ attrString(
1435
+ "error.message",
1436
+ error instanceof Error ? error.message : String(error)
1437
+ )
1438
+ ] : []
1188
1439
  ]
1189
1440
  });
1190
1441
  }
@@ -1200,12 +1451,18 @@ function wrapAISDK(aiSDK, deps) {
1200
1451
  attachments: patch.attachments,
1201
1452
  isPending: false
1202
1453
  }).catch((err) => {
1203
- if (debug) console.warn(`[raindrop-ai/ai-sdk] event patch failed: ${err instanceof Error ? err.message : err}`);
1454
+ if (debug)
1455
+ console.warn(
1456
+ `[raindrop-ai/ai-sdk] event patch failed: ${err instanceof Error ? err.message : err}`
1457
+ );
1204
1458
  });
1205
1459
  }
1206
1460
  };
1207
1461
  const callOriginal = async (...args) => {
1208
- return await original.call(aiSDK, ...args);
1462
+ return await original.call(
1463
+ aiSDK,
1464
+ ...args
1465
+ );
1209
1466
  };
1210
1467
  const runWithContext = async (fn) => {
1211
1468
  if (!rootSpan) return await fn();
@@ -1219,7 +1476,10 @@ function wrapAISDK(aiSDK, deps) {
1219
1476
  try {
1220
1477
  await finalize(result);
1221
1478
  } catch (err) {
1222
- if (debug) console.warn(`[raindrop-ai/ai-sdk] finalize failed: ${err instanceof Error ? err.message : err}`);
1479
+ if (debug)
1480
+ console.warn(
1481
+ `[raindrop-ai/ai-sdk] finalize failed: ${err instanceof Error ? err.message : err}`
1482
+ );
1223
1483
  }
1224
1484
  });
1225
1485
  try {
@@ -1246,7 +1506,10 @@ function wrapAISDK(aiSDK, deps) {
1246
1506
  try {
1247
1507
  await finalize(void 0, error);
1248
1508
  } catch (err) {
1249
- if (debug) console.warn(`[raindrop-ai/ai-sdk] finalize failed: ${err instanceof Error ? err.message : err}`);
1509
+ if (debug)
1510
+ console.warn(
1511
+ `[raindrop-ai/ai-sdk] finalize failed: ${err instanceof Error ? err.message : err}`
1512
+ );
1250
1513
  }
1251
1514
  throw error;
1252
1515
  }
@@ -1260,14 +1523,20 @@ function wrapAISDK(aiSDK, deps) {
1260
1523
  try {
1261
1524
  await finalize(result);
1262
1525
  } catch (err) {
1263
- if (debug) console.warn(`[raindrop-ai/ai-sdk] finalize failed: ${err instanceof Error ? err.message : err}`);
1526
+ if (debug)
1527
+ console.warn(
1528
+ `[raindrop-ai/ai-sdk] finalize failed: ${err instanceof Error ? err.message : err}`
1529
+ );
1264
1530
  }
1265
1531
  return result;
1266
1532
  } catch (error) {
1267
1533
  try {
1268
1534
  await finalize(void 0, error);
1269
1535
  } catch (err) {
1270
- if (debug) console.warn(`[raindrop-ai/ai-sdk] finalize failed: ${err instanceof Error ? err.message : err}`);
1536
+ if (debug)
1537
+ console.warn(
1538
+ `[raindrop-ai/ai-sdk] finalize failed: ${err instanceof Error ? err.message : err}`
1539
+ );
1271
1540
  }
1272
1541
  throw error;
1273
1542
  }
@@ -1319,6 +1588,7 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
1319
1588
  var _a, _b;
1320
1589
  const sendEvents = ((_a = deps.options.send) == null ? void 0 : _a.events) !== false;
1321
1590
  const sendTraces = ((_b = deps.options.send) == null ? void 0 : _b.traces) !== false;
1591
+ const autoAttachmentEnabled = deps.options.autoAttachment !== false;
1322
1592
  return async (...callArgs) => {
1323
1593
  var _a2, _b2, _c, _d;
1324
1594
  const callParams = callArgs[0];
@@ -1362,13 +1632,21 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
1362
1632
  ]
1363
1633
  }) : void 0;
1364
1634
  const rootParentForChildren = rootSpan ? { traceIdB64: rootSpan.ids.traceIdB64, spanIdB64: rootSpan.ids.spanIdB64 } : inheritedParent;
1365
- const wrapCtx = { eventId, telemetry, sendTraces, traceShipper: deps.traceShipper, rootParentForChildren };
1635
+ const wrapCtx = {
1636
+ eventId,
1637
+ telemetry,
1638
+ sendTraces,
1639
+ traceShipper: deps.traceShipper,
1640
+ rootParentForChildren
1641
+ };
1366
1642
  const toolCalls = [];
1367
1643
  const callParamsWithWrappedTools = callParams ? wrapTools(callParams, wrapCtx, toolCalls) : callParams;
1368
1644
  const finalize = async (result, error) => {
1369
1645
  var _a3, _b3, _c2;
1370
1646
  const usage = extractUsage(result);
1371
1647
  const model = extractModel(result);
1648
+ const inputAttachments = autoAttachmentEnabled ? extractInputAttachmentsFromArgs(mergedArgs) : void 0;
1649
+ const outputAttachments = autoAttachmentEnabled ? await extractOutputAttachmentsFromResult(result) : void 0;
1372
1650
  const baseMessages = coerceMessagesFromArgs(mergedArgs);
1373
1651
  const responseMessages = extractResponseMessages(result);
1374
1652
  const allMessages = [...baseMessages, ...responseMessages];
@@ -1379,7 +1657,7 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
1379
1657
  output: outputText,
1380
1658
  model,
1381
1659
  properties: ctx.properties,
1382
- attachments: ctx.attachments
1660
+ attachments: mergeAttachments(ctx.attachments, inputAttachments, outputAttachments)
1383
1661
  };
1384
1662
  const built = await maybeBuildEvent(deps.options.buildEvent, allMessages);
1385
1663
  const patch = mergeBuildEventPatch(defaultPatch, built);
@@ -1409,7 +1687,12 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
1409
1687
  attrInt("ai.usage.reasoningTokens", reasoningTokens),
1410
1688
  attrInt("ai.usage.cachedInputTokens", cachedInputTokens),
1411
1689
  attrInt("ai.toolCall.count", toolCalls.length),
1412
- ...error ? [attrString("error.message", error instanceof Error ? error.message : String(error))] : []
1690
+ ...error ? [
1691
+ attrString(
1692
+ "error.message",
1693
+ error instanceof Error ? error.message : String(error)
1694
+ )
1695
+ ] : []
1413
1696
  ]
1414
1697
  });
1415
1698
  }
@@ -1433,7 +1716,10 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
1433
1716
  attachments: patch.attachments,
1434
1717
  isPending: false
1435
1718
  }).catch((err) => {
1436
- if (debug) console.warn(`[raindrop-ai/ai-sdk] event patch failed: ${err instanceof Error ? err.message : err}`);
1719
+ if (debug)
1720
+ console.warn(
1721
+ `[raindrop-ai/ai-sdk] event patch failed: ${err instanceof Error ? err.message : err}`
1722
+ );
1437
1723
  });
1438
1724
  } else if (debug) {
1439
1725
  console.log(`[raindrop-ai/ai-sdk] Agent ${operation} sendEvents=false, skipping event`);
@@ -1463,14 +1749,20 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
1463
1749
  try {
1464
1750
  await finalize(result);
1465
1751
  } catch (err) {
1466
- if (debug) console.warn(`[raindrop-ai/ai-sdk] finalize failed: ${err instanceof Error ? err.message : err}`);
1752
+ if (debug)
1753
+ console.warn(
1754
+ `[raindrop-ai/ai-sdk] finalize failed: ${err instanceof Error ? err.message : err}`
1755
+ );
1467
1756
  }
1468
1757
  return result;
1469
1758
  } catch (error) {
1470
1759
  try {
1471
1760
  await finalize(void 0, error);
1472
1761
  } catch (err) {
1473
- if (debug) console.warn(`[raindrop-ai/ai-sdk] finalize failed: ${err instanceof Error ? err.message : err}`);
1762
+ if (debug)
1763
+ console.warn(
1764
+ `[raindrop-ai/ai-sdk] finalize failed: ${err instanceof Error ? err.message : err}`
1765
+ );
1474
1766
  }
1475
1767
  throw error;
1476
1768
  }
@@ -1480,6 +1772,7 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
1480
1772
  var _a, _b;
1481
1773
  const sendEvents = ((_a = deps.options.send) == null ? void 0 : _a.events) !== false;
1482
1774
  const sendTraces = ((_b = deps.options.send) == null ? void 0 : _b.traces) !== false;
1775
+ const autoAttachmentEnabled = deps.options.autoAttachment !== false;
1483
1776
  return async (...callArgs) => {
1484
1777
  var _a2, _b2, _c, _d;
1485
1778
  const callParams = callArgs[0];
@@ -1523,13 +1816,21 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
1523
1816
  ]
1524
1817
  }) : void 0;
1525
1818
  const rootParentForChildren = rootSpan ? { traceIdB64: rootSpan.ids.traceIdB64, spanIdB64: rootSpan.ids.spanIdB64 } : inheritedParent;
1526
- const wrapCtx = { eventId, telemetry, sendTraces, traceShipper: deps.traceShipper, rootParentForChildren };
1819
+ const wrapCtx = {
1820
+ eventId,
1821
+ telemetry,
1822
+ sendTraces,
1823
+ traceShipper: deps.traceShipper,
1824
+ rootParentForChildren
1825
+ };
1527
1826
  const toolCalls = [];
1528
1827
  const callParamsWithWrappedTools = callParams ? wrapTools(callParams, wrapCtx, toolCalls) : callParams;
1529
1828
  const finalize = async (result, error) => {
1530
1829
  var _a3, _b3, _c2;
1531
1830
  const usage = extractUsage(result);
1532
1831
  const model = extractModel(result);
1832
+ const inputAttachments = autoAttachmentEnabled ? extractInputAttachmentsFromArgs(mergedArgs) : void 0;
1833
+ const outputAttachments = autoAttachmentEnabled ? await extractOutputAttachmentsFromResult(result) : void 0;
1533
1834
  const baseMessages = coerceMessagesFromArgs(mergedArgs);
1534
1835
  const responseMessages = extractResponseMessages(result);
1535
1836
  const allMessages = [...baseMessages, ...responseMessages];
@@ -1540,7 +1841,7 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
1540
1841
  output: outputText,
1541
1842
  model,
1542
1843
  properties: ctx.properties,
1543
- attachments: ctx.attachments
1844
+ attachments: mergeAttachments(ctx.attachments, inputAttachments, outputAttachments)
1544
1845
  };
1545
1846
  const built = await maybeBuildEvent(deps.options.buildEvent, allMessages);
1546
1847
  const patch = mergeBuildEventPatch(defaultPatch, built);
@@ -1570,7 +1871,12 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
1570
1871
  attrInt("ai.usage.reasoningTokens", reasoningTokens),
1571
1872
  attrInt("ai.usage.cachedInputTokens", cachedInputTokens),
1572
1873
  attrInt("ai.toolCall.count", toolCalls.length),
1573
- ...error ? [attrString("error.message", error instanceof Error ? error.message : String(error))] : []
1874
+ ...error ? [
1875
+ attrString(
1876
+ "error.message",
1877
+ error instanceof Error ? error.message : String(error)
1878
+ )
1879
+ ] : []
1574
1880
  ]
1575
1881
  });
1576
1882
  }
@@ -1594,7 +1900,10 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
1594
1900
  attachments: patch.attachments,
1595
1901
  isPending: false
1596
1902
  }).catch((err) => {
1597
- if (debug) console.warn(`[raindrop-ai/ai-sdk] event patch failed: ${err instanceof Error ? err.message : err}`);
1903
+ if (debug)
1904
+ console.warn(
1905
+ `[raindrop-ai/ai-sdk] event patch failed: ${err instanceof Error ? err.message : err}`
1906
+ );
1598
1907
  });
1599
1908
  } else if (debug) {
1600
1909
  console.log(`[raindrop-ai/ai-sdk] Agent ${operation} sendEvents=false, skipping event`);
@@ -1614,16 +1923,22 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
1614
1923
  eventName: ctx.eventName
1615
1924
  });
1616
1925
  }
1617
- const callParamsWithOnFinish = wrapOnFinish(callParamsWithWrappedTools != null ? callParamsWithWrappedTools : {}, async (result) => {
1618
- if (debug) {
1619
- console.log(`[raindrop-ai/ai-sdk] Agent ${operation} onFinish callback, finalizing...`);
1620
- }
1621
- try {
1622
- await finalize(result);
1623
- } catch (err) {
1624
- if (debug) console.warn(`[raindrop-ai/ai-sdk] finalize failed: ${err instanceof Error ? err.message : err}`);
1926
+ const callParamsWithOnFinish = wrapOnFinish(
1927
+ callParamsWithWrappedTools != null ? callParamsWithWrappedTools : {},
1928
+ async (result) => {
1929
+ if (debug) {
1930
+ console.log(`[raindrop-ai/ai-sdk] Agent ${operation} onFinish callback, finalizing...`);
1931
+ }
1932
+ try {
1933
+ await finalize(result);
1934
+ } catch (err) {
1935
+ if (debug)
1936
+ console.warn(
1937
+ `[raindrop-ai/ai-sdk] finalize failed: ${err instanceof Error ? err.message : err}`
1938
+ );
1939
+ }
1625
1940
  }
1626
- });
1941
+ );
1627
1942
  try {
1628
1943
  const result = await runWithContext(async () => {
1629
1944
  return await stream.call(instance, callParamsWithOnFinish);
@@ -1633,7 +1948,10 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
1633
1948
  try {
1634
1949
  await finalize(void 0, error);
1635
1950
  } catch (err) {
1636
- if (debug) console.warn(`[raindrop-ai/ai-sdk] finalize failed: ${err instanceof Error ? err.message : err}`);
1951
+ if (debug)
1952
+ console.warn(
1953
+ `[raindrop-ai/ai-sdk] finalize failed: ${err instanceof Error ? err.message : err}`
1954
+ );
1637
1955
  }
1638
1956
  throw error;
1639
1957
  }
@@ -1676,7 +1994,9 @@ function wrapToolExecute(name, tool, ctx, toolCalls) {
1676
1994
  if (!span) return;
1677
1995
  if (error) {
1678
1996
  ctx.traceShipper.endSpan(span, {
1679
- attributes: [attrString("error.message", error instanceof Error ? error.message : String(error))]
1997
+ attributes: [
1998
+ attrString("error.message", error instanceof Error ? error.message : String(error))
1999
+ ]
1680
2000
  });
1681
2001
  } else {
1682
2002
  ctx.traceShipper.endSpan(span, {
@@ -1733,7 +2053,11 @@ function wrapToolExecute(name, tool, ctx, toolCalls) {
1733
2053
  };
1734
2054
  if (!toolSpan) return await run();
1735
2055
  return await runWithParentSpanContext(
1736
- { traceIdB64: toolSpan.ids.traceIdB64, spanIdB64: toolSpan.ids.spanIdB64, eventId: ctx.eventId },
2056
+ {
2057
+ traceIdB64: toolSpan.ids.traceIdB64,
2058
+ spanIdB64: toolSpan.ids.spanIdB64,
2059
+ eventId: ctx.eventId
2060
+ },
1737
2061
  run
1738
2062
  );
1739
2063
  })();
@@ -1772,7 +2096,15 @@ function wrapModel(args, aiSDK, outerOperationId, ctx) {
1772
2096
  if (span) endDoGenerateSpan(span, result, modelInfo, ctx);
1773
2097
  return result;
1774
2098
  } catch (error) {
1775
- if (span) ctx.traceShipper.endSpan(span, { attributes: [attrString("error.message", error instanceof Error ? error.message : String(error))] });
2099
+ if (span)
2100
+ ctx.traceShipper.endSpan(span, {
2101
+ attributes: [
2102
+ attrString(
2103
+ "error.message",
2104
+ error instanceof Error ? error.message : String(error)
2105
+ )
2106
+ ]
2107
+ });
1776
2108
  throw error;
1777
2109
  }
1778
2110
  };
@@ -1800,7 +2132,12 @@ function wrapModel(args, aiSDK, outerOperationId, ctx) {
1800
2132
  } catch (error) {
1801
2133
  if (span)
1802
2134
  ctx.traceShipper.endSpan(span, {
1803
- attributes: [attrString("error.message", error instanceof Error ? error.message : String(error))]
2135
+ attributes: [
2136
+ attrString(
2137
+ "error.message",
2138
+ error instanceof Error ? error.message : String(error)
2139
+ )
2140
+ ]
1804
2141
  });
1805
2142
  throw error;
1806
2143
  }
@@ -1826,11 +2163,17 @@ function wrapModel(args, aiSDK, outerOperationId, ctx) {
1826
2163
  ...((_a = ctx.telemetry) == null ? void 0 : _a.recordOutputs) === false ? [] : [
1827
2164
  attrString("ai.response.finishReason", finishReason),
1828
2165
  attrString("ai.response.text", activeText.length ? activeText : void 0),
1829
- attrString("ai.response.toolCalls", safeJsonWithUint8(toolCallsLocal.length ? toolCallsLocal : void 0)),
2166
+ attrString(
2167
+ "ai.response.toolCalls",
2168
+ safeJsonWithUint8(toolCallsLocal.length ? toolCallsLocal : void 0)
2169
+ ),
1830
2170
  attrString("ai.response.id", responseId),
1831
2171
  attrString("ai.response.model", responseModelId),
1832
2172
  attrString("ai.response.timestamp", responseTimestampIso),
1833
- attrString("ai.response.providerMetadata", safeJsonWithUint8(providerMetadata))
2173
+ attrString(
2174
+ "ai.response.providerMetadata",
2175
+ safeJsonWithUint8(providerMetadata)
2176
+ )
1834
2177
  ],
1835
2178
  attrInt("ai.usage.inputTokens", inputTokens),
1836
2179
  attrInt("ai.usage.outputTokens", outputTokens),
@@ -1842,7 +2185,12 @@ function wrapModel(args, aiSDK, outerOperationId, ctx) {
1842
2185
  ...msToFirstChunk !== void 0 ? [attrInt("ai.stream.msToFirstChunk", msToFirstChunk)] : [],
1843
2186
  ...msToFinish !== void 0 ? [attrInt("ai.stream.msToFinish", msToFinish)] : [],
1844
2187
  ...avgOutTokensPerSecond !== void 0 ? [attrDouble("ai.stream.avgOutputTokensPerSecond", avgOutTokensPerSecond)] : [],
1845
- ...error ? [attrString("error.message", error instanceof Error ? error.message : String(error))] : []
2188
+ ...error ? [
2189
+ attrString(
2190
+ "error.message",
2191
+ error instanceof Error ? error.message : String(error)
2192
+ )
2193
+ ] : []
1846
2194
  ]
1847
2195
  });
1848
2196
  };
@@ -1859,15 +2207,20 @@ function wrapModel(args, aiSDK, outerOperationId, ctx) {
1859
2207
  if (firstChunkMs === void 0) firstChunkMs = Date.now();
1860
2208
  if (isRecord(value)) {
1861
2209
  const type = value["type"];
1862
- if (type === "text-delta" && typeof value["textDelta"] === "string") activeText += value["textDelta"];
1863
- if (type === "finish" && typeof value["finishReason"] === "string") finishReason = value["finishReason"];
2210
+ if (type === "text-delta" && typeof value["textDelta"] === "string")
2211
+ activeText += value["textDelta"];
2212
+ if (type === "finish" && typeof value["finishReason"] === "string")
2213
+ finishReason = value["finishReason"];
1864
2214
  if (type === "tool-call") toolCallsLocal.push(value);
1865
2215
  if ("response" in value && isRecord(value["response"])) {
1866
2216
  const response = value["response"];
1867
2217
  if (typeof response["id"] === "string") responseId = response["id"];
1868
- if (typeof response["modelId"] === "string") responseModelId = response["modelId"];
1869
- if (response["timestamp"] instanceof Date) responseTimestampIso = response["timestamp"].toISOString();
1870
- else if (typeof response["timestamp"] === "string") responseTimestampIso = response["timestamp"];
2218
+ if (typeof response["modelId"] === "string")
2219
+ responseModelId = response["modelId"];
2220
+ if (response["timestamp"] instanceof Date)
2221
+ responseTimestampIso = response["timestamp"].toISOString();
2222
+ else if (typeof response["timestamp"] === "string")
2223
+ responseTimestampIso = response["timestamp"];
1871
2224
  }
1872
2225
  if ("usage" in value) usage = value["usage"];
1873
2226
  if ("providerMetadata" in value) providerMetadata = value["providerMetadata"];
@@ -1909,7 +2262,11 @@ function startDoGenerateSpan(operationId, options, modelInfo, parent, ctx) {
1909
2262
  attrString("ai.telemetry.functionId", (_b = ctx.telemetry) == null ? void 0 : _b.functionId),
1910
2263
  attrString("ai.model.provider", modelInfo.provider),
1911
2264
  attrString("ai.model.id", modelInfo.modelId),
1912
- ...((_c = ctx.telemetry) == null ? void 0 : _c.recordInputs) === false ? [] : [attrString("ai.prompt.messages", promptJson), attrStringArray("ai.prompt.tools", toolsJson), attrString("ai.prompt.toolChoice", toolChoiceJson)],
2265
+ ...((_c = ctx.telemetry) == null ? void 0 : _c.recordInputs) === false ? [] : [
2266
+ attrString("ai.prompt.messages", promptJson),
2267
+ attrStringArray("ai.prompt.tools", toolsJson),
2268
+ attrString("ai.prompt.toolChoice", toolChoiceJson)
2269
+ ],
1913
2270
  attrString("gen_ai.system", modelInfo.provider),
1914
2271
  attrString("gen_ai.request.model", modelInfo.modelId),
1915
2272
  ...attrsFromGenAiRequest(options)
@@ -1950,7 +2307,10 @@ function endDoGenerateSpan(span, result, modelInfo, ctx) {
1950
2307
  ...((_a = ctx.telemetry) == null ? void 0 : _a.recordOutputs) === false ? [] : [
1951
2308
  attrString("ai.response.finishReason", finishReason),
1952
2309
  attrString("ai.response.text", extractTextFromLmContent(content)),
1953
- attrString("ai.response.toolCalls", safeJsonWithUint8(extractToolCallsFromLmContent(content))),
2310
+ attrString(
2311
+ "ai.response.toolCalls",
2312
+ safeJsonWithUint8(extractToolCallsFromLmContent(content))
2313
+ ),
1954
2314
  attrString("ai.response.id", responseId),
1955
2315
  attrString("ai.response.model", responseModelId),
1956
2316
  attrString("ai.response.timestamp", responseTimestampIso),
@@ -1984,7 +2344,11 @@ function startDoStreamSpan(operationId, options, modelInfo, parent, ctx) {
1984
2344
  attrString("ai.telemetry.functionId", (_b = ctx.telemetry) == null ? void 0 : _b.functionId),
1985
2345
  attrString("ai.model.provider", modelInfo.provider),
1986
2346
  attrString("ai.model.id", modelInfo.modelId),
1987
- ...((_c = ctx.telemetry) == null ? void 0 : _c.recordInputs) === false ? [] : [attrString("ai.prompt.messages", promptJson), attrStringArray("ai.prompt.tools", toolsJson), attrString("ai.prompt.toolChoice", toolChoiceJson)],
2347
+ ...((_c = ctx.telemetry) == null ? void 0 : _c.recordInputs) === false ? [] : [
2348
+ attrString("ai.prompt.messages", promptJson),
2349
+ attrStringArray("ai.prompt.tools", toolsJson),
2350
+ attrString("ai.prompt.toolChoice", toolChoiceJson)
2351
+ ],
1988
2352
  attrString("gen_ai.system", modelInfo.provider),
1989
2353
  attrString("gen_ai.request.model", modelInfo.modelId),
1990
2354
  ...attrsFromGenAiRequest(options)
@@ -2036,6 +2400,13 @@ function mergeBuildEventPatch(defaults, override) {
2036
2400
  attachments: override.attachments !== void 0 ? [...(_g = defaults.attachments) != null ? _g : [], ...(_h = override.attachments) != null ? _h : []] : defaults.attachments
2037
2401
  };
2038
2402
  }
2403
+ function mergeAttachments(...groups) {
2404
+ const merged = [];
2405
+ for (const group of groups) {
2406
+ if (group == null ? void 0 : group.length) merged.push(...group);
2407
+ }
2408
+ return merged.length ? merged : void 0;
2409
+ }
2039
2410
  function extractNestedTokens(usage, key) {
2040
2411
  if (!isRecord(usage)) return void 0;
2041
2412
  const val = usage[key];
@@ -2055,23 +2426,30 @@ function eventMetadata(options) {
2055
2426
  if (options.properties) result["raindrop.properties"] = JSON.stringify(options.properties);
2056
2427
  return result;
2057
2428
  }
2429
+ function envDebugEnabled() {
2430
+ var _a;
2431
+ if (typeof process === "undefined") return false;
2432
+ const flag = (_a = process.env) == null ? void 0 : _a.RAINDROP_AI_DEBUG;
2433
+ return flag === "1" || flag === "true";
2434
+ }
2058
2435
  function createRaindropAISDK(opts) {
2059
2436
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2060
2437
  const eventsEnabled = ((_a = opts.events) == null ? void 0 : _a.enabled) !== false;
2061
2438
  const tracesEnabled = ((_b = opts.traces) == null ? void 0 : _b.enabled) !== false;
2439
+ const envDebug = envDebugEnabled();
2062
2440
  const eventShipper = new EventShipper({
2063
2441
  writeKey: opts.writeKey,
2064
2442
  endpoint: opts.endpoint,
2065
2443
  enabled: eventsEnabled,
2066
- debug: ((_c = opts.events) == null ? void 0 : _c.debug) === true,
2444
+ debug: ((_c = opts.events) == null ? void 0 : _c.debug) === true || envDebug,
2067
2445
  partialFlushMs: (_d = opts.events) == null ? void 0 : _d.partialFlushMs
2068
2446
  });
2069
2447
  const traceShipper = new TraceShipper({
2070
2448
  writeKey: opts.writeKey,
2071
2449
  endpoint: opts.endpoint,
2072
2450
  enabled: tracesEnabled,
2073
- debug: ((_e = opts.traces) == null ? void 0 : _e.debug) === true,
2074
- debugSpans: ((_f = opts.traces) == null ? void 0 : _f.debugSpans) === true,
2451
+ debug: ((_e = opts.traces) == null ? void 0 : _e.debug) === true || envDebug,
2452
+ debugSpans: ((_f = opts.traces) == null ? void 0 : _f.debugSpans) === true || envDebug,
2075
2453
  flushIntervalMs: (_g = opts.traces) == null ? void 0 : _g.flushIntervalMs,
2076
2454
  maxBatchSize: (_h = opts.traces) == null ? void 0 : _h.maxBatchSize,
2077
2455
  maxQueueSize: (_i = opts.traces) == null ? void 0 : _i.maxQueueSize