@raindrop-ai/ai-sdk 0.0.27 → 0.0.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-YP2VKVP7.mjs → chunk-QGI4SABN.mjs} +284 -126
- package/dist/{index-TERu6zvv.d.mts → index-DKdCelJA.d.mts} +170 -1
- package/dist/{index-TERu6zvv.d.ts → index-DKdCelJA.d.ts} +170 -1
- package/dist/index.browser.d.mts +170 -1
- package/dist/index.browser.d.ts +170 -1
- package/dist/index.browser.js +289 -125
- package/dist/index.browser.mjs +284 -126
- package/dist/index.node.d.mts +1 -1
- package/dist/index.node.d.ts +1 -1
- package/dist/index.node.js +289 -125
- package/dist/index.node.mjs +1 -1
- package/dist/index.workers.d.mts +1 -1
- package/dist/index.workers.d.ts +1 -1
- package/dist/index.workers.js +289 -125
- package/dist/index.workers.mjs +1 -1
- package/package.json +1 -1
package/dist/index.browser.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
// ../core/dist/chunk-
|
|
3
|
+
// ../core/dist/chunk-VUNUOE2X.js
|
|
4
4
|
function getCrypto() {
|
|
5
5
|
const c = globalThis.crypto;
|
|
6
6
|
return c;
|
|
@@ -223,6 +223,114 @@ function buildExportTraceServiceRequest(spans, serviceName = "raindrop.core", se
|
|
|
223
223
|
]
|
|
224
224
|
};
|
|
225
225
|
}
|
|
226
|
+
var LOCAL_DEBUGGER_ENV_VAR = "RAINDROP_LOCAL_DEBUGGER";
|
|
227
|
+
var WORKSHOP_ENV_VAR = "RAINDROP_WORKSHOP";
|
|
228
|
+
var DEFAULT_LOCAL_WORKSHOP_URL = "http://localhost:5899/v1/";
|
|
229
|
+
function readEnvVar(name) {
|
|
230
|
+
var _a;
|
|
231
|
+
try {
|
|
232
|
+
const env = (_a = globalThis == null ? void 0 : globalThis.process) == null ? void 0 : _a.env;
|
|
233
|
+
if (env && typeof env[name] === "string" && env[name].length > 0) {
|
|
234
|
+
return env[name];
|
|
235
|
+
}
|
|
236
|
+
} catch (e) {
|
|
237
|
+
}
|
|
238
|
+
return void 0;
|
|
239
|
+
}
|
|
240
|
+
function readWorkshopEnv() {
|
|
241
|
+
const raw = readEnvVar(WORKSHOP_ENV_VAR);
|
|
242
|
+
if (raw === void 0) return void 0;
|
|
243
|
+
const trimmed = raw.trim();
|
|
244
|
+
if (trimmed.length === 0) return void 0;
|
|
245
|
+
if (/^https?:\/\//i.test(trimmed)) return { url: trimmed };
|
|
246
|
+
if (/^(1|true|yes|on)$/i.test(trimmed)) return "enable";
|
|
247
|
+
if (/^(0|false|no|off)$/i.test(trimmed)) return "disable";
|
|
248
|
+
return void 0;
|
|
249
|
+
}
|
|
250
|
+
function isLocalDevHost(hostname) {
|
|
251
|
+
if (!hostname) return false;
|
|
252
|
+
if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "0.0.0.0" || hostname === "::1") {
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
if (hostname.endsWith(".localhost")) return true;
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
function readRuntimeHostname() {
|
|
259
|
+
try {
|
|
260
|
+
const loc = globalThis == null ? void 0 : globalThis.location;
|
|
261
|
+
if (loc && typeof loc.hostname === "string" && loc.hostname.length > 0) {
|
|
262
|
+
return loc.hostname;
|
|
263
|
+
}
|
|
264
|
+
} catch (e) {
|
|
265
|
+
}
|
|
266
|
+
return void 0;
|
|
267
|
+
}
|
|
268
|
+
function shouldAutoEnableLocalWorkshop() {
|
|
269
|
+
if (isLocalDevHost(readRuntimeHostname())) return true;
|
|
270
|
+
if (readEnvVar("NODE_ENV") === "development") return true;
|
|
271
|
+
return false;
|
|
272
|
+
}
|
|
273
|
+
function resolveLocalDebuggerBaseUrl(baseUrl) {
|
|
274
|
+
var _a, _b, _c;
|
|
275
|
+
if (baseUrl === null) return null;
|
|
276
|
+
if (typeof baseUrl === "string" && baseUrl.length > 0) {
|
|
277
|
+
return (_a = formatEndpoint(baseUrl)) != null ? _a : null;
|
|
278
|
+
}
|
|
279
|
+
const explicitUrlEnv = readEnvVar(LOCAL_DEBUGGER_ENV_VAR);
|
|
280
|
+
if (explicitUrlEnv) return (_b = formatEndpoint(explicitUrlEnv)) != null ? _b : null;
|
|
281
|
+
const workshopEnv = readWorkshopEnv();
|
|
282
|
+
if (workshopEnv === "disable") return null;
|
|
283
|
+
if (workshopEnv === "enable") return DEFAULT_LOCAL_WORKSHOP_URL;
|
|
284
|
+
if (workshopEnv && "url" in workshopEnv) return (_c = formatEndpoint(workshopEnv.url)) != null ? _c : null;
|
|
285
|
+
if (shouldAutoEnableLocalWorkshop()) return DEFAULT_LOCAL_WORKSHOP_URL;
|
|
286
|
+
return null;
|
|
287
|
+
}
|
|
288
|
+
function localDebuggerEnabled(baseUrl) {
|
|
289
|
+
return resolveLocalDebuggerBaseUrl(baseUrl) !== null;
|
|
290
|
+
}
|
|
291
|
+
function mirrorTraceExportToLocalDebugger(body, options = {}) {
|
|
292
|
+
var _a;
|
|
293
|
+
const baseUrl = resolveLocalDebuggerBaseUrl(options.baseUrl);
|
|
294
|
+
if (!baseUrl) return;
|
|
295
|
+
void postJson(`${baseUrl}traces`, body, {}, {
|
|
296
|
+
maxAttempts: 1,
|
|
297
|
+
debug: (_a = options.debug) != null ? _a : false,
|
|
298
|
+
sdkName: options.sdkName
|
|
299
|
+
}).catch(() => {
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
function mirrorPartialEventToLocalDebugger(event, options = {}) {
|
|
303
|
+
var _a;
|
|
304
|
+
const baseUrl = resolveLocalDebuggerBaseUrl(options.baseUrl);
|
|
305
|
+
if (!baseUrl) return;
|
|
306
|
+
const headers = options.writeKey ? { Authorization: `Bearer ${options.writeKey}` } : {};
|
|
307
|
+
void postJson(`${baseUrl}events/track_partial`, event, headers, {
|
|
308
|
+
maxAttempts: 1,
|
|
309
|
+
debug: (_a = options.debug) != null ? _a : false,
|
|
310
|
+
sdkName: options.sdkName
|
|
311
|
+
}).catch(() => {
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
function sendLocalDebuggerLiveEvent(event, options = {}) {
|
|
315
|
+
var _a, _b;
|
|
316
|
+
const baseUrl = resolveLocalDebuggerBaseUrl(options.baseUrl);
|
|
317
|
+
if (!baseUrl) return;
|
|
318
|
+
void postJson(
|
|
319
|
+
`${baseUrl}live`,
|
|
320
|
+
{
|
|
321
|
+
...event,
|
|
322
|
+
type: event.type,
|
|
323
|
+
timestamp: (_a = event.timestamp) != null ? _a : Date.now()
|
|
324
|
+
},
|
|
325
|
+
{},
|
|
326
|
+
{
|
|
327
|
+
maxAttempts: 1,
|
|
328
|
+
debug: (_b = options.debug) != null ? _b : false,
|
|
329
|
+
sdkName: options.sdkName
|
|
330
|
+
}
|
|
331
|
+
).catch(() => {
|
|
332
|
+
});
|
|
333
|
+
}
|
|
226
334
|
function mergePatches(target, source) {
|
|
227
335
|
var _a, _b, _c, _d;
|
|
228
336
|
const out = { ...target, ...source };
|
|
@@ -240,7 +348,7 @@ var EventShipper = class {
|
|
|
240
348
|
this.sticky = /* @__PURE__ */ new Map();
|
|
241
349
|
this.timers = /* @__PURE__ */ new Map();
|
|
242
350
|
this.inFlight = /* @__PURE__ */ new Set();
|
|
243
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
351
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
244
352
|
this.writeKey = (_a = opts.writeKey) == null ? void 0 : _a.trim();
|
|
245
353
|
this.baseUrl = (_b = formatEndpoint(opts.endpoint)) != null ? _b : "https://api.raindrop.ai/v1/";
|
|
246
354
|
this.enabled = opts.enabled !== false;
|
|
@@ -249,11 +357,15 @@ var EventShipper = class {
|
|
|
249
357
|
this.sdkName = (_d = opts.sdkName) != null ? _d : "core";
|
|
250
358
|
this.prefix = `[raindrop-ai/${this.sdkName}]`;
|
|
251
359
|
this.defaultEventName = (_e = opts.defaultEventName) != null ? _e : "ai_generation";
|
|
360
|
+
this.localDebuggerUrl = (_f = resolveLocalDebuggerBaseUrl(opts.localDebuggerUrl)) != null ? _f : void 0;
|
|
361
|
+
if (this.debug && this.localDebuggerUrl) {
|
|
362
|
+
console.log(`${this.prefix} Local debugger mirroring: ${this.localDebuggerUrl}`);
|
|
363
|
+
}
|
|
252
364
|
const isNode = typeof process !== "undefined" && typeof process.version === "string";
|
|
253
365
|
this.context = {
|
|
254
366
|
library: {
|
|
255
|
-
name: (
|
|
256
|
-
version: (
|
|
367
|
+
name: (_g = opts.libraryName) != null ? _g : "@raindrop-ai/core",
|
|
368
|
+
version: (_h = opts.libraryVersion) != null ? _h : "0.0.0"
|
|
257
369
|
},
|
|
258
370
|
metadata: {
|
|
259
371
|
jsRuntime: isNode ? "node" : "web",
|
|
@@ -339,6 +451,7 @@ var EventShipper = class {
|
|
|
339
451
|
}
|
|
340
452
|
}
|
|
341
453
|
];
|
|
454
|
+
if (!this.writeKey) return;
|
|
342
455
|
const url = `${this.baseUrl}signals/track`;
|
|
343
456
|
try {
|
|
344
457
|
await postJson(url, body, this.authHeaders(), {
|
|
@@ -369,6 +482,7 @@ var EventShipper = class {
|
|
|
369
482
|
traits: (_a = user.traits) != null ? _a : {}
|
|
370
483
|
};
|
|
371
484
|
});
|
|
485
|
+
if (!this.writeKey) return;
|
|
372
486
|
if (body.length === 0) return;
|
|
373
487
|
const url = `${this.baseUrl}users/identify`;
|
|
374
488
|
try {
|
|
@@ -445,6 +559,18 @@ var EventShipper = class {
|
|
|
445
559
|
endpoint: url
|
|
446
560
|
});
|
|
447
561
|
}
|
|
562
|
+
if (this.localDebuggerUrl) {
|
|
563
|
+
mirrorPartialEventToLocalDebugger(payload, {
|
|
564
|
+
baseUrl: this.localDebuggerUrl,
|
|
565
|
+
writeKey: this.writeKey,
|
|
566
|
+
debug: this.debug,
|
|
567
|
+
sdkName: this.sdkName
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
if (!this.writeKey) {
|
|
571
|
+
if (!isPending) this.sticky.delete(eventId);
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
448
574
|
const p = postJson(url, payload, this.authHeaders(), {
|
|
449
575
|
maxAttempts: 3,
|
|
450
576
|
debug: this.debug,
|
|
@@ -469,101 +595,94 @@ var EventShipper = class {
|
|
|
469
595
|
}
|
|
470
596
|
}
|
|
471
597
|
};
|
|
472
|
-
var
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
598
|
+
var DEFAULT_SECRET_KEY_NAMES = [
|
|
599
|
+
"apikey",
|
|
600
|
+
"apisecret",
|
|
601
|
+
"apitoken",
|
|
602
|
+
"secretaccesskey",
|
|
603
|
+
"sessiontoken",
|
|
604
|
+
"privatekey",
|
|
605
|
+
"privatekeyid",
|
|
606
|
+
"clientsecret",
|
|
607
|
+
"accesstoken",
|
|
608
|
+
"refreshtoken",
|
|
609
|
+
"oauthtoken",
|
|
610
|
+
"bearertoken",
|
|
611
|
+
"authorization",
|
|
612
|
+
"password",
|
|
613
|
+
"passphrase"
|
|
614
|
+
];
|
|
615
|
+
var REDACTED_PLACEHOLDER = "[REDACTED]";
|
|
616
|
+
function normalizeKeyName(name) {
|
|
617
|
+
return name.toLowerCase().replace(/[-_.]/g, "");
|
|
618
|
+
}
|
|
619
|
+
function redactSecretsInObject(value, options) {
|
|
620
|
+
var _a, _b;
|
|
621
|
+
const normalizedSecretSet = buildSecretSet((_a = options == null ? void 0 : options.secretKeyNames) != null ? _a : DEFAULT_SECRET_KEY_NAMES);
|
|
622
|
+
const placeholder = (_b = options == null ? void 0 : options.placeholder) != null ? _b : REDACTED_PLACEHOLDER;
|
|
623
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
624
|
+
const walk = (node) => {
|
|
625
|
+
if (node === null || typeof node !== "object") return node;
|
|
626
|
+
if (seen.has(node)) return "[CIRCULAR]";
|
|
627
|
+
seen.add(node);
|
|
628
|
+
if (Array.isArray(node)) {
|
|
629
|
+
return node.map((item) => walk(item));
|
|
630
|
+
}
|
|
631
|
+
const out = {};
|
|
632
|
+
for (const [k, v] of Object.entries(node)) {
|
|
633
|
+
if (normalizedSecretSet.has(normalizeKeyName(k))) {
|
|
634
|
+
out[k] = placeholder;
|
|
635
|
+
} else {
|
|
636
|
+
out[k] = walk(v);
|
|
637
|
+
}
|
|
481
638
|
}
|
|
639
|
+
return out;
|
|
640
|
+
};
|
|
641
|
+
return walk(value);
|
|
642
|
+
}
|
|
643
|
+
function buildSecretSet(names) {
|
|
644
|
+
const set = /* @__PURE__ */ new Set();
|
|
645
|
+
for (const name of names) set.add(normalizeKeyName(name));
|
|
646
|
+
return set;
|
|
647
|
+
}
|
|
648
|
+
var DEFAULT_REDACT_ATTRIBUTE_KEYS = [
|
|
649
|
+
"ai.request.providerOptions",
|
|
650
|
+
"ai.response.providerMetadata"
|
|
651
|
+
];
|
|
652
|
+
function defaultTransformSpan(span) {
|
|
653
|
+
const attrs = span.attributes;
|
|
654
|
+
if (!attrs || attrs.length === 0) return span;
|
|
655
|
+
let nextAttrs;
|
|
656
|
+
for (let i = 0; i < attrs.length; i++) {
|
|
657
|
+
const attr = attrs[i];
|
|
658
|
+
const redacted = redactJsonAttributeValue(attr.key, attr.value);
|
|
659
|
+
if (redacted === void 0) continue;
|
|
660
|
+
if (!nextAttrs) nextAttrs = attrs.slice();
|
|
661
|
+
nextAttrs[i] = { key: attr.key, value: redacted };
|
|
662
|
+
}
|
|
663
|
+
if (!nextAttrs) return span;
|
|
664
|
+
return { ...span, attributes: nextAttrs };
|
|
665
|
+
}
|
|
666
|
+
var REDACT_JSON_ATTRIBUTE_KEYS = new Set(DEFAULT_REDACT_ATTRIBUTE_KEYS);
|
|
667
|
+
function redactJsonAttributeValue(key, value) {
|
|
668
|
+
if (!REDACT_JSON_ATTRIBUTE_KEYS.has(key)) return void 0;
|
|
669
|
+
const json = value.stringValue;
|
|
670
|
+
if (typeof json !== "string" || json.length === 0) return void 0;
|
|
671
|
+
let parsed;
|
|
672
|
+
try {
|
|
673
|
+
parsed = JSON.parse(json);
|
|
482
674
|
} catch (e) {
|
|
675
|
+
return void 0;
|
|
483
676
|
}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
function readWorkshopEnv() {
|
|
487
|
-
const raw = readEnvVar(WORKSHOP_ENV_VAR);
|
|
488
|
-
if (raw === void 0) return void 0;
|
|
489
|
-
const trimmed = raw.trim();
|
|
490
|
-
if (trimmed.length === 0) return void 0;
|
|
491
|
-
if (/^https?:\/\//i.test(trimmed)) return { url: trimmed };
|
|
492
|
-
if (/^(1|true|yes|on)$/i.test(trimmed)) return "enable";
|
|
493
|
-
if (/^(0|false|no|off)$/i.test(trimmed)) return "disable";
|
|
494
|
-
return void 0;
|
|
495
|
-
}
|
|
496
|
-
function isLocalDevHost(hostname) {
|
|
497
|
-
if (!hostname) return false;
|
|
498
|
-
if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "0.0.0.0" || hostname === "::1") {
|
|
499
|
-
return true;
|
|
500
|
-
}
|
|
501
|
-
if (hostname.endsWith(".localhost")) return true;
|
|
502
|
-
return false;
|
|
503
|
-
}
|
|
504
|
-
function readRuntimeHostname() {
|
|
677
|
+
const scrubbed = redactSecretsInObject(parsed);
|
|
678
|
+
let scrubbedJson;
|
|
505
679
|
try {
|
|
506
|
-
|
|
507
|
-
if (loc && typeof loc.hostname === "string" && loc.hostname.length > 0) {
|
|
508
|
-
return loc.hostname;
|
|
509
|
-
}
|
|
680
|
+
scrubbedJson = JSON.stringify(scrubbed);
|
|
510
681
|
} catch (e) {
|
|
682
|
+
return void 0;
|
|
511
683
|
}
|
|
512
|
-
return void 0;
|
|
513
|
-
}
|
|
514
|
-
function shouldAutoEnableLocalWorkshop() {
|
|
515
|
-
if (isLocalDevHost(readRuntimeHostname())) return true;
|
|
516
|
-
if (readEnvVar("NODE_ENV") === "development") return true;
|
|
517
|
-
return false;
|
|
518
|
-
}
|
|
519
|
-
function resolveLocalDebuggerBaseUrl(baseUrl) {
|
|
520
|
-
var _a, _b, _c;
|
|
521
|
-
if (baseUrl === null) return null;
|
|
522
|
-
if (typeof baseUrl === "string" && baseUrl.length > 0) {
|
|
523
|
-
return (_a = formatEndpoint(baseUrl)) != null ? _a : null;
|
|
524
|
-
}
|
|
525
|
-
const explicitUrlEnv = readEnvVar(LOCAL_DEBUGGER_ENV_VAR);
|
|
526
|
-
if (explicitUrlEnv) return (_b = formatEndpoint(explicitUrlEnv)) != null ? _b : null;
|
|
527
|
-
const workshopEnv = readWorkshopEnv();
|
|
528
|
-
if (workshopEnv === "disable") return null;
|
|
529
|
-
if (workshopEnv === "enable") return DEFAULT_LOCAL_WORKSHOP_URL;
|
|
530
|
-
if (workshopEnv && "url" in workshopEnv) return (_c = formatEndpoint(workshopEnv.url)) != null ? _c : null;
|
|
531
|
-
if (shouldAutoEnableLocalWorkshop()) return DEFAULT_LOCAL_WORKSHOP_URL;
|
|
532
|
-
return null;
|
|
533
|
-
}
|
|
534
|
-
function localDebuggerEnabled(baseUrl) {
|
|
535
|
-
return resolveLocalDebuggerBaseUrl(baseUrl) !== null;
|
|
536
|
-
}
|
|
537
|
-
function mirrorTraceExportToLocalDebugger(body, options = {}) {
|
|
538
|
-
var _a;
|
|
539
|
-
const baseUrl = resolveLocalDebuggerBaseUrl(options.baseUrl);
|
|
540
|
-
if (!baseUrl) return;
|
|
541
|
-
void postJson(`${baseUrl}traces`, body, {}, {
|
|
542
|
-
maxAttempts: 1,
|
|
543
|
-
debug: (_a = options.debug) != null ? _a : false,
|
|
544
|
-
sdkName: options.sdkName
|
|
545
|
-
}).catch(() => {
|
|
546
|
-
});
|
|
547
|
-
}
|
|
548
|
-
function sendLocalDebuggerLiveEvent(event, options = {}) {
|
|
549
|
-
var _a, _b;
|
|
550
|
-
const baseUrl = resolveLocalDebuggerBaseUrl(options.baseUrl);
|
|
551
|
-
if (!baseUrl) return;
|
|
552
|
-
void postJson(
|
|
553
|
-
`${baseUrl}live`,
|
|
554
|
-
{
|
|
555
|
-
...event,
|
|
556
|
-
type: event.type,
|
|
557
|
-
timestamp: (_a = event.timestamp) != null ? _a : Date.now()
|
|
558
|
-
},
|
|
559
|
-
{},
|
|
560
|
-
{
|
|
561
|
-
maxAttempts: 1,
|
|
562
|
-
debug: (_b = options.debug) != null ? _b : false,
|
|
563
|
-
sdkName: options.sdkName
|
|
564
|
-
}
|
|
565
|
-
).catch(() => {
|
|
566
|
-
});
|
|
684
|
+
if (scrubbedJson === json) return void 0;
|
|
685
|
+
return { stringValue: scrubbedJson };
|
|
567
686
|
}
|
|
568
687
|
var TraceShipper = class {
|
|
569
688
|
constructor(opts) {
|
|
@@ -586,6 +705,42 @@ var TraceShipper = class {
|
|
|
586
705
|
if (this.debug && this.localDebuggerUrl) {
|
|
587
706
|
console.log(`${this.prefix} Local debugger mirroring: ${this.localDebuggerUrl}`);
|
|
588
707
|
}
|
|
708
|
+
this.transformSpanHook = opts.transformSpan;
|
|
709
|
+
this.disableDefaultRedaction = opts.disableDefaultRedaction === true;
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* Apply the user `transformSpan` hook (if any) followed by the default
|
|
713
|
+
* redactor (unless disabled). Returns either the (possibly new) span to
|
|
714
|
+
* ship, or `null` to drop the span entirely.
|
|
715
|
+
*
|
|
716
|
+
* Ordering: user hook runs first so callers can rewrite the span freely
|
|
717
|
+
* (rename attrs, add new ones, scrub things the default doesn't know
|
|
718
|
+
* about). The default redactor then runs on whatever the user produced,
|
|
719
|
+
* acting as the always-on floor for documented BYOK secrets. If the user
|
|
720
|
+
* sets `disableDefaultRedaction: true`, the floor is skipped.
|
|
721
|
+
*
|
|
722
|
+
* Fail-closed: if the user hook throws, the span is dropped — a buggy
|
|
723
|
+
* hook can never accidentally ship raw, un-redacted spans.
|
|
724
|
+
*/
|
|
725
|
+
redactSpan(span) {
|
|
726
|
+
let current = span;
|
|
727
|
+
if (this.transformSpanHook) {
|
|
728
|
+
try {
|
|
729
|
+
const result = this.transformSpanHook(current);
|
|
730
|
+
if (result === null) return null;
|
|
731
|
+
if (result !== void 0) current = result;
|
|
732
|
+
} catch (err) {
|
|
733
|
+
if (this.debug) {
|
|
734
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
735
|
+
console.warn(`${this.prefix} transformSpan hook threw: ${msg}`);
|
|
736
|
+
}
|
|
737
|
+
return null;
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
if (!this.disableDefaultRedaction) {
|
|
741
|
+
current = defaultTransformSpan(current);
|
|
742
|
+
}
|
|
743
|
+
return current;
|
|
589
744
|
}
|
|
590
745
|
isDebugEnabled() {
|
|
591
746
|
return this.debug;
|
|
@@ -603,8 +758,8 @@ var TraceShipper = class {
|
|
|
603
758
|
];
|
|
604
759
|
if ((_b = args.attributes) == null ? void 0 : _b.length) attrs.push(...args.attributes);
|
|
605
760
|
const span = { ids, name: args.name, startTimeUnixNano: started, attributes: attrs };
|
|
606
|
-
|
|
607
|
-
|
|
761
|
+
this.mirrorToLocalDebugger(
|
|
762
|
+
buildOtlpSpan({
|
|
608
763
|
ids: span.ids,
|
|
609
764
|
name: span.name,
|
|
610
765
|
startTimeUnixNano: span.startTimeUnixNano,
|
|
@@ -612,16 +767,21 @@ var TraceShipper = class {
|
|
|
612
767
|
// placeholder — will be updated on endSpan
|
|
613
768
|
attributes: span.attributes,
|
|
614
769
|
status: { code: SpanStatusCode.UNSET }
|
|
615
|
-
})
|
|
616
|
-
|
|
617
|
-
mirrorTraceExportToLocalDebugger(body, {
|
|
618
|
-
baseUrl: this.localDebuggerUrl,
|
|
619
|
-
debug: false,
|
|
620
|
-
sdkName: this.sdkName
|
|
621
|
-
});
|
|
622
|
-
}
|
|
770
|
+
})
|
|
771
|
+
);
|
|
623
772
|
return span;
|
|
624
773
|
}
|
|
774
|
+
mirrorToLocalDebugger(span) {
|
|
775
|
+
if (!this.localDebuggerUrl) return;
|
|
776
|
+
const redacted = this.redactSpan(span);
|
|
777
|
+
if (redacted === null) return;
|
|
778
|
+
const body = buildExportTraceServiceRequest([redacted], this.serviceName, this.serviceVersion);
|
|
779
|
+
mirrorTraceExportToLocalDebugger(body, {
|
|
780
|
+
baseUrl: this.localDebuggerUrl,
|
|
781
|
+
debug: false,
|
|
782
|
+
sdkName: this.sdkName
|
|
783
|
+
});
|
|
784
|
+
}
|
|
625
785
|
endSpan(span, extra) {
|
|
626
786
|
var _a, _b;
|
|
627
787
|
if (span.endTimeUnixNano) return;
|
|
@@ -643,14 +803,7 @@ var TraceShipper = class {
|
|
|
643
803
|
status
|
|
644
804
|
});
|
|
645
805
|
this.enqueue(otlp);
|
|
646
|
-
|
|
647
|
-
const body = buildExportTraceServiceRequest([otlp], this.serviceName, this.serviceVersion);
|
|
648
|
-
mirrorTraceExportToLocalDebugger(body, {
|
|
649
|
-
baseUrl: this.localDebuggerUrl,
|
|
650
|
-
debug: false,
|
|
651
|
-
sdkName: this.sdkName
|
|
652
|
-
});
|
|
653
|
-
}
|
|
806
|
+
this.mirrorToLocalDebugger(otlp);
|
|
654
807
|
}
|
|
655
808
|
createSpan(args) {
|
|
656
809
|
var _a;
|
|
@@ -668,14 +821,7 @@ var TraceShipper = class {
|
|
|
668
821
|
status: args.status
|
|
669
822
|
});
|
|
670
823
|
this.enqueue(otlp);
|
|
671
|
-
|
|
672
|
-
const body = buildExportTraceServiceRequest([otlp], this.serviceName, this.serviceVersion);
|
|
673
|
-
mirrorTraceExportToLocalDebugger(body, {
|
|
674
|
-
baseUrl: this.localDebuggerUrl,
|
|
675
|
-
debug: false,
|
|
676
|
-
sdkName: this.sdkName
|
|
677
|
-
});
|
|
678
|
-
}
|
|
824
|
+
this.mirrorToLocalDebugger(otlp);
|
|
679
825
|
}
|
|
680
826
|
enqueue(span) {
|
|
681
827
|
if (!this.enabled) return;
|
|
@@ -687,10 +833,12 @@ var TraceShipper = class {
|
|
|
687
833
|
)}`
|
|
688
834
|
);
|
|
689
835
|
}
|
|
836
|
+
const redacted = this.redactSpan(span);
|
|
837
|
+
if (redacted === null) return;
|
|
690
838
|
if (this.queue.length >= this.maxQueueSize) {
|
|
691
839
|
this.queue.shift();
|
|
692
840
|
}
|
|
693
|
-
this.queue.push(
|
|
841
|
+
this.queue.push(redacted);
|
|
694
842
|
if (this.queue.length >= this.maxBatchSize) {
|
|
695
843
|
void this.flush().catch(() => {
|
|
696
844
|
});
|
|
@@ -712,6 +860,7 @@ var TraceShipper = class {
|
|
|
712
860
|
}
|
|
713
861
|
while (this.queue.length > 0) {
|
|
714
862
|
const batch = this.queue.splice(0, this.maxBatchSize);
|
|
863
|
+
if (!this.writeKey) continue;
|
|
715
864
|
const body = buildExportTraceServiceRequest(batch, this.serviceName, this.serviceVersion);
|
|
716
865
|
const url = `${this.baseUrl}traces`;
|
|
717
866
|
if (this.debug) {
|
|
@@ -870,7 +1019,7 @@ async function* asyncGeneratorWithCurrent(span, gen) {
|
|
|
870
1019
|
// package.json
|
|
871
1020
|
var package_default = {
|
|
872
1021
|
name: "@raindrop-ai/ai-sdk",
|
|
873
|
-
version: "0.0.
|
|
1022
|
+
version: "0.0.29"};
|
|
874
1023
|
|
|
875
1024
|
// src/internal/version.ts
|
|
876
1025
|
var libraryName = package_default.name;
|
|
@@ -1509,6 +1658,11 @@ function attrsFromGenAiRequest(options) {
|
|
|
1509
1658
|
)
|
|
1510
1659
|
];
|
|
1511
1660
|
}
|
|
1661
|
+
function attrProviderOptions(options) {
|
|
1662
|
+
if (!isRecord(options) || !isRecord(options["providerOptions"])) return void 0;
|
|
1663
|
+
const json = safeJsonWithUint8(options["providerOptions"]);
|
|
1664
|
+
return json ? attrString("ai.request.providerOptions", json) : void 0;
|
|
1665
|
+
}
|
|
1512
1666
|
|
|
1513
1667
|
// src/internal/call-metadata.ts
|
|
1514
1668
|
var SyncFallbackStorage = class {
|
|
@@ -4056,7 +4210,8 @@ function startDoGenerateSpan(operationId, options, modelInfo, parent, ctx) {
|
|
|
4056
4210
|
],
|
|
4057
4211
|
attrString("gen_ai.system", modelInfo.provider),
|
|
4058
4212
|
attrString("gen_ai.request.model", modelInfo.modelId),
|
|
4059
|
-
...attrsFromGenAiRequest(options)
|
|
4213
|
+
...attrsFromGenAiRequest(options),
|
|
4214
|
+
attrProviderOptions(options)
|
|
4060
4215
|
]
|
|
4061
4216
|
});
|
|
4062
4217
|
}
|
|
@@ -4138,7 +4293,8 @@ function startDoStreamSpan(operationId, options, modelInfo, parent, ctx) {
|
|
|
4138
4293
|
],
|
|
4139
4294
|
attrString("gen_ai.system", modelInfo.provider),
|
|
4140
4295
|
attrString("gen_ai.request.model", modelInfo.modelId),
|
|
4141
|
-
...attrsFromGenAiRequest(options)
|
|
4296
|
+
...attrsFromGenAiRequest(options),
|
|
4297
|
+
attrProviderOptions(options)
|
|
4142
4298
|
]
|
|
4143
4299
|
});
|
|
4144
4300
|
}
|
|
@@ -4263,7 +4419,7 @@ function envDebugEnabled() {
|
|
|
4263
4419
|
return flag === "1" || flag === "true";
|
|
4264
4420
|
}
|
|
4265
4421
|
function createRaindropAISDK(opts) {
|
|
4266
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
4422
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
4267
4423
|
const writeKey = opts.writeKey;
|
|
4268
4424
|
const eventsRequested = ((_a = opts.events) == null ? void 0 : _a.enabled) !== false;
|
|
4269
4425
|
const tracesRequested = ((_b = opts.traces) == null ? void 0 : _b.enabled) !== false;
|
|
@@ -4292,7 +4448,9 @@ function createRaindropAISDK(opts) {
|
|
|
4292
4448
|
flushIntervalMs: (_g = opts.traces) == null ? void 0 : _g.flushIntervalMs,
|
|
4293
4449
|
maxBatchSize: (_h = opts.traces) == null ? void 0 : _h.maxBatchSize,
|
|
4294
4450
|
maxQueueSize: (_i = opts.traces) == null ? void 0 : _i.maxQueueSize,
|
|
4295
|
-
localDebuggerUrl
|
|
4451
|
+
localDebuggerUrl,
|
|
4452
|
+
transformSpan: (_j = opts.traces) == null ? void 0 : _j.transformSpan,
|
|
4453
|
+
disableDefaultRedaction: (_k = opts.traces) == null ? void 0 : _k.disableDefaultRedaction
|
|
4296
4454
|
});
|
|
4297
4455
|
return {
|
|
4298
4456
|
wrap(aiSDK, options) {
|
|
@@ -4415,15 +4573,21 @@ function createRaindropAISDK(opts) {
|
|
|
4415
4573
|
};
|
|
4416
4574
|
}
|
|
4417
4575
|
|
|
4576
|
+
exports.DEFAULT_REDACT_ATTRIBUTE_KEYS = DEFAULT_REDACT_ATTRIBUTE_KEYS;
|
|
4577
|
+
exports.DEFAULT_SECRET_KEY_NAMES = DEFAULT_SECRET_KEY_NAMES;
|
|
4578
|
+
exports.REDACTED_PLACEHOLDER = REDACTED_PLACEHOLDER;
|
|
4418
4579
|
exports.RaindropTelemetryIntegration = RaindropTelemetryIntegration;
|
|
4419
4580
|
exports._resetRaindropCallMetadataStorage = _resetRaindropCallMetadataStorage;
|
|
4420
4581
|
exports._resetWarnedMissingUserId = _resetWarnedMissingUserId;
|
|
4421
4582
|
exports.createRaindropAISDK = createRaindropAISDK;
|
|
4422
4583
|
exports.currentSpan = currentSpan;
|
|
4584
|
+
exports.defaultTransformSpan = defaultTransformSpan;
|
|
4423
4585
|
exports.eventMetadata = eventMetadata;
|
|
4424
4586
|
exports.eventMetadataFromChatRequest = eventMetadataFromChatRequest;
|
|
4425
4587
|
exports.getContextManager = getContextManager;
|
|
4426
4588
|
exports.getCurrentRaindropCallMetadata = getCurrentRaindropCallMetadata;
|
|
4427
4589
|
exports.readRaindropCallMetadataFromArgs = readRaindropCallMetadataFromArgs;
|
|
4590
|
+
exports.redactJsonAttributeValue = redactJsonAttributeValue;
|
|
4591
|
+
exports.redactSecretsInObject = redactSecretsInObject;
|
|
4428
4592
|
exports.runWithRaindropCallMetadata = runWithRaindropCallMetadata;
|
|
4429
4593
|
exports.withCurrent = withCurrent;
|