@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.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// ../core/dist/chunk-
|
|
1
|
+
// ../core/dist/chunk-VUNUOE2X.js
|
|
2
2
|
function getCrypto() {
|
|
3
3
|
const c = globalThis.crypto;
|
|
4
4
|
return c;
|
|
@@ -221,6 +221,114 @@ function buildExportTraceServiceRequest(spans, serviceName = "raindrop.core", se
|
|
|
221
221
|
]
|
|
222
222
|
};
|
|
223
223
|
}
|
|
224
|
+
var LOCAL_DEBUGGER_ENV_VAR = "RAINDROP_LOCAL_DEBUGGER";
|
|
225
|
+
var WORKSHOP_ENV_VAR = "RAINDROP_WORKSHOP";
|
|
226
|
+
var DEFAULT_LOCAL_WORKSHOP_URL = "http://localhost:5899/v1/";
|
|
227
|
+
function readEnvVar(name) {
|
|
228
|
+
var _a;
|
|
229
|
+
try {
|
|
230
|
+
const env = (_a = globalThis == null ? void 0 : globalThis.process) == null ? void 0 : _a.env;
|
|
231
|
+
if (env && typeof env[name] === "string" && env[name].length > 0) {
|
|
232
|
+
return env[name];
|
|
233
|
+
}
|
|
234
|
+
} catch (e) {
|
|
235
|
+
}
|
|
236
|
+
return void 0;
|
|
237
|
+
}
|
|
238
|
+
function readWorkshopEnv() {
|
|
239
|
+
const raw = readEnvVar(WORKSHOP_ENV_VAR);
|
|
240
|
+
if (raw === void 0) return void 0;
|
|
241
|
+
const trimmed = raw.trim();
|
|
242
|
+
if (trimmed.length === 0) return void 0;
|
|
243
|
+
if (/^https?:\/\//i.test(trimmed)) return { url: trimmed };
|
|
244
|
+
if (/^(1|true|yes|on)$/i.test(trimmed)) return "enable";
|
|
245
|
+
if (/^(0|false|no|off)$/i.test(trimmed)) return "disable";
|
|
246
|
+
return void 0;
|
|
247
|
+
}
|
|
248
|
+
function isLocalDevHost(hostname) {
|
|
249
|
+
if (!hostname) return false;
|
|
250
|
+
if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "0.0.0.0" || hostname === "::1") {
|
|
251
|
+
return true;
|
|
252
|
+
}
|
|
253
|
+
if (hostname.endsWith(".localhost")) return true;
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
function readRuntimeHostname() {
|
|
257
|
+
try {
|
|
258
|
+
const loc = globalThis == null ? void 0 : globalThis.location;
|
|
259
|
+
if (loc && typeof loc.hostname === "string" && loc.hostname.length > 0) {
|
|
260
|
+
return loc.hostname;
|
|
261
|
+
}
|
|
262
|
+
} catch (e) {
|
|
263
|
+
}
|
|
264
|
+
return void 0;
|
|
265
|
+
}
|
|
266
|
+
function shouldAutoEnableLocalWorkshop() {
|
|
267
|
+
if (isLocalDevHost(readRuntimeHostname())) return true;
|
|
268
|
+
if (readEnvVar("NODE_ENV") === "development") return true;
|
|
269
|
+
return false;
|
|
270
|
+
}
|
|
271
|
+
function resolveLocalDebuggerBaseUrl(baseUrl) {
|
|
272
|
+
var _a, _b, _c;
|
|
273
|
+
if (baseUrl === null) return null;
|
|
274
|
+
if (typeof baseUrl === "string" && baseUrl.length > 0) {
|
|
275
|
+
return (_a = formatEndpoint(baseUrl)) != null ? _a : null;
|
|
276
|
+
}
|
|
277
|
+
const explicitUrlEnv = readEnvVar(LOCAL_DEBUGGER_ENV_VAR);
|
|
278
|
+
if (explicitUrlEnv) return (_b = formatEndpoint(explicitUrlEnv)) != null ? _b : null;
|
|
279
|
+
const workshopEnv = readWorkshopEnv();
|
|
280
|
+
if (workshopEnv === "disable") return null;
|
|
281
|
+
if (workshopEnv === "enable") return DEFAULT_LOCAL_WORKSHOP_URL;
|
|
282
|
+
if (workshopEnv && "url" in workshopEnv) return (_c = formatEndpoint(workshopEnv.url)) != null ? _c : null;
|
|
283
|
+
if (shouldAutoEnableLocalWorkshop()) return DEFAULT_LOCAL_WORKSHOP_URL;
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
function localDebuggerEnabled(baseUrl) {
|
|
287
|
+
return resolveLocalDebuggerBaseUrl(baseUrl) !== null;
|
|
288
|
+
}
|
|
289
|
+
function mirrorTraceExportToLocalDebugger(body, options = {}) {
|
|
290
|
+
var _a;
|
|
291
|
+
const baseUrl = resolveLocalDebuggerBaseUrl(options.baseUrl);
|
|
292
|
+
if (!baseUrl) return;
|
|
293
|
+
void postJson(`${baseUrl}traces`, body, {}, {
|
|
294
|
+
maxAttempts: 1,
|
|
295
|
+
debug: (_a = options.debug) != null ? _a : false,
|
|
296
|
+
sdkName: options.sdkName
|
|
297
|
+
}).catch(() => {
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
function mirrorPartialEventToLocalDebugger(event, options = {}) {
|
|
301
|
+
var _a;
|
|
302
|
+
const baseUrl = resolveLocalDebuggerBaseUrl(options.baseUrl);
|
|
303
|
+
if (!baseUrl) return;
|
|
304
|
+
const headers = options.writeKey ? { Authorization: `Bearer ${options.writeKey}` } : {};
|
|
305
|
+
void postJson(`${baseUrl}events/track_partial`, event, headers, {
|
|
306
|
+
maxAttempts: 1,
|
|
307
|
+
debug: (_a = options.debug) != null ? _a : false,
|
|
308
|
+
sdkName: options.sdkName
|
|
309
|
+
}).catch(() => {
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
function sendLocalDebuggerLiveEvent(event, options = {}) {
|
|
313
|
+
var _a, _b;
|
|
314
|
+
const baseUrl = resolveLocalDebuggerBaseUrl(options.baseUrl);
|
|
315
|
+
if (!baseUrl) return;
|
|
316
|
+
void postJson(
|
|
317
|
+
`${baseUrl}live`,
|
|
318
|
+
{
|
|
319
|
+
...event,
|
|
320
|
+
type: event.type,
|
|
321
|
+
timestamp: (_a = event.timestamp) != null ? _a : Date.now()
|
|
322
|
+
},
|
|
323
|
+
{},
|
|
324
|
+
{
|
|
325
|
+
maxAttempts: 1,
|
|
326
|
+
debug: (_b = options.debug) != null ? _b : false,
|
|
327
|
+
sdkName: options.sdkName
|
|
328
|
+
}
|
|
329
|
+
).catch(() => {
|
|
330
|
+
});
|
|
331
|
+
}
|
|
224
332
|
function mergePatches(target, source) {
|
|
225
333
|
var _a, _b, _c, _d;
|
|
226
334
|
const out = { ...target, ...source };
|
|
@@ -238,7 +346,7 @@ var EventShipper = class {
|
|
|
238
346
|
this.sticky = /* @__PURE__ */ new Map();
|
|
239
347
|
this.timers = /* @__PURE__ */ new Map();
|
|
240
348
|
this.inFlight = /* @__PURE__ */ new Set();
|
|
241
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
349
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
242
350
|
this.writeKey = (_a = opts.writeKey) == null ? void 0 : _a.trim();
|
|
243
351
|
this.baseUrl = (_b = formatEndpoint(opts.endpoint)) != null ? _b : "https://api.raindrop.ai/v1/";
|
|
244
352
|
this.enabled = opts.enabled !== false;
|
|
@@ -247,11 +355,15 @@ var EventShipper = class {
|
|
|
247
355
|
this.sdkName = (_d = opts.sdkName) != null ? _d : "core";
|
|
248
356
|
this.prefix = `[raindrop-ai/${this.sdkName}]`;
|
|
249
357
|
this.defaultEventName = (_e = opts.defaultEventName) != null ? _e : "ai_generation";
|
|
358
|
+
this.localDebuggerUrl = (_f = resolveLocalDebuggerBaseUrl(opts.localDebuggerUrl)) != null ? _f : void 0;
|
|
359
|
+
if (this.debug && this.localDebuggerUrl) {
|
|
360
|
+
console.log(`${this.prefix} Local debugger mirroring: ${this.localDebuggerUrl}`);
|
|
361
|
+
}
|
|
250
362
|
const isNode = typeof process !== "undefined" && typeof process.version === "string";
|
|
251
363
|
this.context = {
|
|
252
364
|
library: {
|
|
253
|
-
name: (
|
|
254
|
-
version: (
|
|
365
|
+
name: (_g = opts.libraryName) != null ? _g : "@raindrop-ai/core",
|
|
366
|
+
version: (_h = opts.libraryVersion) != null ? _h : "0.0.0"
|
|
255
367
|
},
|
|
256
368
|
metadata: {
|
|
257
369
|
jsRuntime: isNode ? "node" : "web",
|
|
@@ -337,6 +449,7 @@ var EventShipper = class {
|
|
|
337
449
|
}
|
|
338
450
|
}
|
|
339
451
|
];
|
|
452
|
+
if (!this.writeKey) return;
|
|
340
453
|
const url = `${this.baseUrl}signals/track`;
|
|
341
454
|
try {
|
|
342
455
|
await postJson(url, body, this.authHeaders(), {
|
|
@@ -367,6 +480,7 @@ var EventShipper = class {
|
|
|
367
480
|
traits: (_a = user.traits) != null ? _a : {}
|
|
368
481
|
};
|
|
369
482
|
});
|
|
483
|
+
if (!this.writeKey) return;
|
|
370
484
|
if (body.length === 0) return;
|
|
371
485
|
const url = `${this.baseUrl}users/identify`;
|
|
372
486
|
try {
|
|
@@ -443,6 +557,18 @@ var EventShipper = class {
|
|
|
443
557
|
endpoint: url
|
|
444
558
|
});
|
|
445
559
|
}
|
|
560
|
+
if (this.localDebuggerUrl) {
|
|
561
|
+
mirrorPartialEventToLocalDebugger(payload, {
|
|
562
|
+
baseUrl: this.localDebuggerUrl,
|
|
563
|
+
writeKey: this.writeKey,
|
|
564
|
+
debug: this.debug,
|
|
565
|
+
sdkName: this.sdkName
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
if (!this.writeKey) {
|
|
569
|
+
if (!isPending) this.sticky.delete(eventId);
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
446
572
|
const p = postJson(url, payload, this.authHeaders(), {
|
|
447
573
|
maxAttempts: 3,
|
|
448
574
|
debug: this.debug,
|
|
@@ -467,101 +593,94 @@ var EventShipper = class {
|
|
|
467
593
|
}
|
|
468
594
|
}
|
|
469
595
|
};
|
|
470
|
-
var
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
596
|
+
var DEFAULT_SECRET_KEY_NAMES = [
|
|
597
|
+
"apikey",
|
|
598
|
+
"apisecret",
|
|
599
|
+
"apitoken",
|
|
600
|
+
"secretaccesskey",
|
|
601
|
+
"sessiontoken",
|
|
602
|
+
"privatekey",
|
|
603
|
+
"privatekeyid",
|
|
604
|
+
"clientsecret",
|
|
605
|
+
"accesstoken",
|
|
606
|
+
"refreshtoken",
|
|
607
|
+
"oauthtoken",
|
|
608
|
+
"bearertoken",
|
|
609
|
+
"authorization",
|
|
610
|
+
"password",
|
|
611
|
+
"passphrase"
|
|
612
|
+
];
|
|
613
|
+
var REDACTED_PLACEHOLDER = "[REDACTED]";
|
|
614
|
+
function normalizeKeyName(name) {
|
|
615
|
+
return name.toLowerCase().replace(/[-_.]/g, "");
|
|
616
|
+
}
|
|
617
|
+
function redactSecretsInObject(value, options) {
|
|
618
|
+
var _a, _b;
|
|
619
|
+
const normalizedSecretSet = buildSecretSet((_a = options == null ? void 0 : options.secretKeyNames) != null ? _a : DEFAULT_SECRET_KEY_NAMES);
|
|
620
|
+
const placeholder = (_b = options == null ? void 0 : options.placeholder) != null ? _b : REDACTED_PLACEHOLDER;
|
|
621
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
622
|
+
const walk = (node) => {
|
|
623
|
+
if (node === null || typeof node !== "object") return node;
|
|
624
|
+
if (seen.has(node)) return "[CIRCULAR]";
|
|
625
|
+
seen.add(node);
|
|
626
|
+
if (Array.isArray(node)) {
|
|
627
|
+
return node.map((item) => walk(item));
|
|
628
|
+
}
|
|
629
|
+
const out = {};
|
|
630
|
+
for (const [k, v] of Object.entries(node)) {
|
|
631
|
+
if (normalizedSecretSet.has(normalizeKeyName(k))) {
|
|
632
|
+
out[k] = placeholder;
|
|
633
|
+
} else {
|
|
634
|
+
out[k] = walk(v);
|
|
635
|
+
}
|
|
479
636
|
}
|
|
637
|
+
return out;
|
|
638
|
+
};
|
|
639
|
+
return walk(value);
|
|
640
|
+
}
|
|
641
|
+
function buildSecretSet(names) {
|
|
642
|
+
const set = /* @__PURE__ */ new Set();
|
|
643
|
+
for (const name of names) set.add(normalizeKeyName(name));
|
|
644
|
+
return set;
|
|
645
|
+
}
|
|
646
|
+
var DEFAULT_REDACT_ATTRIBUTE_KEYS = [
|
|
647
|
+
"ai.request.providerOptions",
|
|
648
|
+
"ai.response.providerMetadata"
|
|
649
|
+
];
|
|
650
|
+
function defaultTransformSpan(span) {
|
|
651
|
+
const attrs = span.attributes;
|
|
652
|
+
if (!attrs || attrs.length === 0) return span;
|
|
653
|
+
let nextAttrs;
|
|
654
|
+
for (let i = 0; i < attrs.length; i++) {
|
|
655
|
+
const attr = attrs[i];
|
|
656
|
+
const redacted = redactJsonAttributeValue(attr.key, attr.value);
|
|
657
|
+
if (redacted === void 0) continue;
|
|
658
|
+
if (!nextAttrs) nextAttrs = attrs.slice();
|
|
659
|
+
nextAttrs[i] = { key: attr.key, value: redacted };
|
|
660
|
+
}
|
|
661
|
+
if (!nextAttrs) return span;
|
|
662
|
+
return { ...span, attributes: nextAttrs };
|
|
663
|
+
}
|
|
664
|
+
var REDACT_JSON_ATTRIBUTE_KEYS = new Set(DEFAULT_REDACT_ATTRIBUTE_KEYS);
|
|
665
|
+
function redactJsonAttributeValue(key, value) {
|
|
666
|
+
if (!REDACT_JSON_ATTRIBUTE_KEYS.has(key)) return void 0;
|
|
667
|
+
const json = value.stringValue;
|
|
668
|
+
if (typeof json !== "string" || json.length === 0) return void 0;
|
|
669
|
+
let parsed;
|
|
670
|
+
try {
|
|
671
|
+
parsed = JSON.parse(json);
|
|
480
672
|
} catch (e) {
|
|
673
|
+
return void 0;
|
|
481
674
|
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
function readWorkshopEnv() {
|
|
485
|
-
const raw = readEnvVar(WORKSHOP_ENV_VAR);
|
|
486
|
-
if (raw === void 0) return void 0;
|
|
487
|
-
const trimmed = raw.trim();
|
|
488
|
-
if (trimmed.length === 0) return void 0;
|
|
489
|
-
if (/^https?:\/\//i.test(trimmed)) return { url: trimmed };
|
|
490
|
-
if (/^(1|true|yes|on)$/i.test(trimmed)) return "enable";
|
|
491
|
-
if (/^(0|false|no|off)$/i.test(trimmed)) return "disable";
|
|
492
|
-
return void 0;
|
|
493
|
-
}
|
|
494
|
-
function isLocalDevHost(hostname) {
|
|
495
|
-
if (!hostname) return false;
|
|
496
|
-
if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "0.0.0.0" || hostname === "::1") {
|
|
497
|
-
return true;
|
|
498
|
-
}
|
|
499
|
-
if (hostname.endsWith(".localhost")) return true;
|
|
500
|
-
return false;
|
|
501
|
-
}
|
|
502
|
-
function readRuntimeHostname() {
|
|
675
|
+
const scrubbed = redactSecretsInObject(parsed);
|
|
676
|
+
let scrubbedJson;
|
|
503
677
|
try {
|
|
504
|
-
|
|
505
|
-
if (loc && typeof loc.hostname === "string" && loc.hostname.length > 0) {
|
|
506
|
-
return loc.hostname;
|
|
507
|
-
}
|
|
678
|
+
scrubbedJson = JSON.stringify(scrubbed);
|
|
508
679
|
} catch (e) {
|
|
680
|
+
return void 0;
|
|
509
681
|
}
|
|
510
|
-
return void 0;
|
|
511
|
-
}
|
|
512
|
-
function shouldAutoEnableLocalWorkshop() {
|
|
513
|
-
if (isLocalDevHost(readRuntimeHostname())) return true;
|
|
514
|
-
if (readEnvVar("NODE_ENV") === "development") return true;
|
|
515
|
-
return false;
|
|
516
|
-
}
|
|
517
|
-
function resolveLocalDebuggerBaseUrl(baseUrl) {
|
|
518
|
-
var _a, _b, _c;
|
|
519
|
-
if (baseUrl === null) return null;
|
|
520
|
-
if (typeof baseUrl === "string" && baseUrl.length > 0) {
|
|
521
|
-
return (_a = formatEndpoint(baseUrl)) != null ? _a : null;
|
|
522
|
-
}
|
|
523
|
-
const explicitUrlEnv = readEnvVar(LOCAL_DEBUGGER_ENV_VAR);
|
|
524
|
-
if (explicitUrlEnv) return (_b = formatEndpoint(explicitUrlEnv)) != null ? _b : null;
|
|
525
|
-
const workshopEnv = readWorkshopEnv();
|
|
526
|
-
if (workshopEnv === "disable") return null;
|
|
527
|
-
if (workshopEnv === "enable") return DEFAULT_LOCAL_WORKSHOP_URL;
|
|
528
|
-
if (workshopEnv && "url" in workshopEnv) return (_c = formatEndpoint(workshopEnv.url)) != null ? _c : null;
|
|
529
|
-
if (shouldAutoEnableLocalWorkshop()) return DEFAULT_LOCAL_WORKSHOP_URL;
|
|
530
|
-
return null;
|
|
531
|
-
}
|
|
532
|
-
function localDebuggerEnabled(baseUrl) {
|
|
533
|
-
return resolveLocalDebuggerBaseUrl(baseUrl) !== null;
|
|
534
|
-
}
|
|
535
|
-
function mirrorTraceExportToLocalDebugger(body, options = {}) {
|
|
536
|
-
var _a;
|
|
537
|
-
const baseUrl = resolveLocalDebuggerBaseUrl(options.baseUrl);
|
|
538
|
-
if (!baseUrl) return;
|
|
539
|
-
void postJson(`${baseUrl}traces`, body, {}, {
|
|
540
|
-
maxAttempts: 1,
|
|
541
|
-
debug: (_a = options.debug) != null ? _a : false,
|
|
542
|
-
sdkName: options.sdkName
|
|
543
|
-
}).catch(() => {
|
|
544
|
-
});
|
|
545
|
-
}
|
|
546
|
-
function sendLocalDebuggerLiveEvent(event, options = {}) {
|
|
547
|
-
var _a, _b;
|
|
548
|
-
const baseUrl = resolveLocalDebuggerBaseUrl(options.baseUrl);
|
|
549
|
-
if (!baseUrl) return;
|
|
550
|
-
void postJson(
|
|
551
|
-
`${baseUrl}live`,
|
|
552
|
-
{
|
|
553
|
-
...event,
|
|
554
|
-
type: event.type,
|
|
555
|
-
timestamp: (_a = event.timestamp) != null ? _a : Date.now()
|
|
556
|
-
},
|
|
557
|
-
{},
|
|
558
|
-
{
|
|
559
|
-
maxAttempts: 1,
|
|
560
|
-
debug: (_b = options.debug) != null ? _b : false,
|
|
561
|
-
sdkName: options.sdkName
|
|
562
|
-
}
|
|
563
|
-
).catch(() => {
|
|
564
|
-
});
|
|
682
|
+
if (scrubbedJson === json) return void 0;
|
|
683
|
+
return { stringValue: scrubbedJson };
|
|
565
684
|
}
|
|
566
685
|
var TraceShipper = class {
|
|
567
686
|
constructor(opts) {
|
|
@@ -584,6 +703,42 @@ var TraceShipper = class {
|
|
|
584
703
|
if (this.debug && this.localDebuggerUrl) {
|
|
585
704
|
console.log(`${this.prefix} Local debugger mirroring: ${this.localDebuggerUrl}`);
|
|
586
705
|
}
|
|
706
|
+
this.transformSpanHook = opts.transformSpan;
|
|
707
|
+
this.disableDefaultRedaction = opts.disableDefaultRedaction === true;
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* Apply the user `transformSpan` hook (if any) followed by the default
|
|
711
|
+
* redactor (unless disabled). Returns either the (possibly new) span to
|
|
712
|
+
* ship, or `null` to drop the span entirely.
|
|
713
|
+
*
|
|
714
|
+
* Ordering: user hook runs first so callers can rewrite the span freely
|
|
715
|
+
* (rename attrs, add new ones, scrub things the default doesn't know
|
|
716
|
+
* about). The default redactor then runs on whatever the user produced,
|
|
717
|
+
* acting as the always-on floor for documented BYOK secrets. If the user
|
|
718
|
+
* sets `disableDefaultRedaction: true`, the floor is skipped.
|
|
719
|
+
*
|
|
720
|
+
* Fail-closed: if the user hook throws, the span is dropped — a buggy
|
|
721
|
+
* hook can never accidentally ship raw, un-redacted spans.
|
|
722
|
+
*/
|
|
723
|
+
redactSpan(span) {
|
|
724
|
+
let current = span;
|
|
725
|
+
if (this.transformSpanHook) {
|
|
726
|
+
try {
|
|
727
|
+
const result = this.transformSpanHook(current);
|
|
728
|
+
if (result === null) return null;
|
|
729
|
+
if (result !== void 0) current = result;
|
|
730
|
+
} catch (err) {
|
|
731
|
+
if (this.debug) {
|
|
732
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
733
|
+
console.warn(`${this.prefix} transformSpan hook threw: ${msg}`);
|
|
734
|
+
}
|
|
735
|
+
return null;
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
if (!this.disableDefaultRedaction) {
|
|
739
|
+
current = defaultTransformSpan(current);
|
|
740
|
+
}
|
|
741
|
+
return current;
|
|
587
742
|
}
|
|
588
743
|
isDebugEnabled() {
|
|
589
744
|
return this.debug;
|
|
@@ -601,8 +756,8 @@ var TraceShipper = class {
|
|
|
601
756
|
];
|
|
602
757
|
if ((_b = args.attributes) == null ? void 0 : _b.length) attrs.push(...args.attributes);
|
|
603
758
|
const span = { ids, name: args.name, startTimeUnixNano: started, attributes: attrs };
|
|
604
|
-
|
|
605
|
-
|
|
759
|
+
this.mirrorToLocalDebugger(
|
|
760
|
+
buildOtlpSpan({
|
|
606
761
|
ids: span.ids,
|
|
607
762
|
name: span.name,
|
|
608
763
|
startTimeUnixNano: span.startTimeUnixNano,
|
|
@@ -610,16 +765,21 @@ var TraceShipper = class {
|
|
|
610
765
|
// placeholder — will be updated on endSpan
|
|
611
766
|
attributes: span.attributes,
|
|
612
767
|
status: { code: SpanStatusCode.UNSET }
|
|
613
|
-
})
|
|
614
|
-
|
|
615
|
-
mirrorTraceExportToLocalDebugger(body, {
|
|
616
|
-
baseUrl: this.localDebuggerUrl,
|
|
617
|
-
debug: false,
|
|
618
|
-
sdkName: this.sdkName
|
|
619
|
-
});
|
|
620
|
-
}
|
|
768
|
+
})
|
|
769
|
+
);
|
|
621
770
|
return span;
|
|
622
771
|
}
|
|
772
|
+
mirrorToLocalDebugger(span) {
|
|
773
|
+
if (!this.localDebuggerUrl) return;
|
|
774
|
+
const redacted = this.redactSpan(span);
|
|
775
|
+
if (redacted === null) return;
|
|
776
|
+
const body = buildExportTraceServiceRequest([redacted], this.serviceName, this.serviceVersion);
|
|
777
|
+
mirrorTraceExportToLocalDebugger(body, {
|
|
778
|
+
baseUrl: this.localDebuggerUrl,
|
|
779
|
+
debug: false,
|
|
780
|
+
sdkName: this.sdkName
|
|
781
|
+
});
|
|
782
|
+
}
|
|
623
783
|
endSpan(span, extra) {
|
|
624
784
|
var _a, _b;
|
|
625
785
|
if (span.endTimeUnixNano) return;
|
|
@@ -641,14 +801,7 @@ var TraceShipper = class {
|
|
|
641
801
|
status
|
|
642
802
|
});
|
|
643
803
|
this.enqueue(otlp);
|
|
644
|
-
|
|
645
|
-
const body = buildExportTraceServiceRequest([otlp], this.serviceName, this.serviceVersion);
|
|
646
|
-
mirrorTraceExportToLocalDebugger(body, {
|
|
647
|
-
baseUrl: this.localDebuggerUrl,
|
|
648
|
-
debug: false,
|
|
649
|
-
sdkName: this.sdkName
|
|
650
|
-
});
|
|
651
|
-
}
|
|
804
|
+
this.mirrorToLocalDebugger(otlp);
|
|
652
805
|
}
|
|
653
806
|
createSpan(args) {
|
|
654
807
|
var _a;
|
|
@@ -666,14 +819,7 @@ var TraceShipper = class {
|
|
|
666
819
|
status: args.status
|
|
667
820
|
});
|
|
668
821
|
this.enqueue(otlp);
|
|
669
|
-
|
|
670
|
-
const body = buildExportTraceServiceRequest([otlp], this.serviceName, this.serviceVersion);
|
|
671
|
-
mirrorTraceExportToLocalDebugger(body, {
|
|
672
|
-
baseUrl: this.localDebuggerUrl,
|
|
673
|
-
debug: false,
|
|
674
|
-
sdkName: this.sdkName
|
|
675
|
-
});
|
|
676
|
-
}
|
|
822
|
+
this.mirrorToLocalDebugger(otlp);
|
|
677
823
|
}
|
|
678
824
|
enqueue(span) {
|
|
679
825
|
if (!this.enabled) return;
|
|
@@ -685,10 +831,12 @@ var TraceShipper = class {
|
|
|
685
831
|
)}`
|
|
686
832
|
);
|
|
687
833
|
}
|
|
834
|
+
const redacted = this.redactSpan(span);
|
|
835
|
+
if (redacted === null) return;
|
|
688
836
|
if (this.queue.length >= this.maxQueueSize) {
|
|
689
837
|
this.queue.shift();
|
|
690
838
|
}
|
|
691
|
-
this.queue.push(
|
|
839
|
+
this.queue.push(redacted);
|
|
692
840
|
if (this.queue.length >= this.maxBatchSize) {
|
|
693
841
|
void this.flush().catch(() => {
|
|
694
842
|
});
|
|
@@ -710,6 +858,7 @@ var TraceShipper = class {
|
|
|
710
858
|
}
|
|
711
859
|
while (this.queue.length > 0) {
|
|
712
860
|
const batch = this.queue.splice(0, this.maxBatchSize);
|
|
861
|
+
if (!this.writeKey) continue;
|
|
713
862
|
const body = buildExportTraceServiceRequest(batch, this.serviceName, this.serviceVersion);
|
|
714
863
|
const url = `${this.baseUrl}traces`;
|
|
715
864
|
if (this.debug) {
|
|
@@ -868,7 +1017,7 @@ async function* asyncGeneratorWithCurrent(span, gen) {
|
|
|
868
1017
|
// package.json
|
|
869
1018
|
var package_default = {
|
|
870
1019
|
name: "@raindrop-ai/ai-sdk",
|
|
871
|
-
version: "0.0.
|
|
1020
|
+
version: "0.0.29"};
|
|
872
1021
|
|
|
873
1022
|
// src/internal/version.ts
|
|
874
1023
|
var libraryName = package_default.name;
|
|
@@ -1507,6 +1656,11 @@ function attrsFromGenAiRequest(options) {
|
|
|
1507
1656
|
)
|
|
1508
1657
|
];
|
|
1509
1658
|
}
|
|
1659
|
+
function attrProviderOptions(options) {
|
|
1660
|
+
if (!isRecord(options) || !isRecord(options["providerOptions"])) return void 0;
|
|
1661
|
+
const json = safeJsonWithUint8(options["providerOptions"]);
|
|
1662
|
+
return json ? attrString("ai.request.providerOptions", json) : void 0;
|
|
1663
|
+
}
|
|
1510
1664
|
|
|
1511
1665
|
// src/internal/call-metadata.ts
|
|
1512
1666
|
var SyncFallbackStorage = class {
|
|
@@ -4054,7 +4208,8 @@ function startDoGenerateSpan(operationId, options, modelInfo, parent, ctx) {
|
|
|
4054
4208
|
],
|
|
4055
4209
|
attrString("gen_ai.system", modelInfo.provider),
|
|
4056
4210
|
attrString("gen_ai.request.model", modelInfo.modelId),
|
|
4057
|
-
...attrsFromGenAiRequest(options)
|
|
4211
|
+
...attrsFromGenAiRequest(options),
|
|
4212
|
+
attrProviderOptions(options)
|
|
4058
4213
|
]
|
|
4059
4214
|
});
|
|
4060
4215
|
}
|
|
@@ -4136,7 +4291,8 @@ function startDoStreamSpan(operationId, options, modelInfo, parent, ctx) {
|
|
|
4136
4291
|
],
|
|
4137
4292
|
attrString("gen_ai.system", modelInfo.provider),
|
|
4138
4293
|
attrString("gen_ai.request.model", modelInfo.modelId),
|
|
4139
|
-
...attrsFromGenAiRequest(options)
|
|
4294
|
+
...attrsFromGenAiRequest(options),
|
|
4295
|
+
attrProviderOptions(options)
|
|
4140
4296
|
]
|
|
4141
4297
|
});
|
|
4142
4298
|
}
|
|
@@ -4261,7 +4417,7 @@ function envDebugEnabled() {
|
|
|
4261
4417
|
return flag === "1" || flag === "true";
|
|
4262
4418
|
}
|
|
4263
4419
|
function createRaindropAISDK(opts) {
|
|
4264
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
4420
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
4265
4421
|
const writeKey = opts.writeKey;
|
|
4266
4422
|
const eventsRequested = ((_a = opts.events) == null ? void 0 : _a.enabled) !== false;
|
|
4267
4423
|
const tracesRequested = ((_b = opts.traces) == null ? void 0 : _b.enabled) !== false;
|
|
@@ -4290,7 +4446,9 @@ function createRaindropAISDK(opts) {
|
|
|
4290
4446
|
flushIntervalMs: (_g = opts.traces) == null ? void 0 : _g.flushIntervalMs,
|
|
4291
4447
|
maxBatchSize: (_h = opts.traces) == null ? void 0 : _h.maxBatchSize,
|
|
4292
4448
|
maxQueueSize: (_i = opts.traces) == null ? void 0 : _i.maxQueueSize,
|
|
4293
|
-
localDebuggerUrl
|
|
4449
|
+
localDebuggerUrl,
|
|
4450
|
+
transformSpan: (_j = opts.traces) == null ? void 0 : _j.transformSpan,
|
|
4451
|
+
disableDefaultRedaction: (_k = opts.traces) == null ? void 0 : _k.disableDefaultRedaction
|
|
4294
4452
|
});
|
|
4295
4453
|
return {
|
|
4296
4454
|
wrap(aiSDK, options) {
|
|
@@ -4413,4 +4571,4 @@ function createRaindropAISDK(opts) {
|
|
|
4413
4571
|
};
|
|
4414
4572
|
}
|
|
4415
4573
|
|
|
4416
|
-
export { RaindropTelemetryIntegration, _resetRaindropCallMetadataStorage, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, eventMetadataFromChatRequest, getContextManager, getCurrentRaindropCallMetadata, readRaindropCallMetadataFromArgs, runWithRaindropCallMetadata, withCurrent };
|
|
4574
|
+
export { DEFAULT_REDACT_ATTRIBUTE_KEYS, DEFAULT_SECRET_KEY_NAMES, REDACTED_PLACEHOLDER, RaindropTelemetryIntegration, _resetRaindropCallMetadataStorage, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, defaultTransformSpan, eventMetadata, eventMetadataFromChatRequest, getContextManager, getCurrentRaindropCallMetadata, readRaindropCallMetadataFromArgs, redactJsonAttributeValue, redactSecretsInObject, runWithRaindropCallMetadata, withCurrent };
|
package/dist/index.node.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as AISDKChatRequestLike, a as AISDKChatRequestMessageLike, b as AISDKMessage, c as AgentCallMetadata, d as AgentWithMetadata, e as Attachment, B as BuildEventPatch, C as ContextManager, f as ContextSpan, g as CreateSpanArgs, E as EndSpanArgs,
|
|
1
|
+
export { A as AISDKChatRequestLike, a as AISDKChatRequestMessageLike, b as AISDKMessage, c as AgentCallMetadata, d as AgentWithMetadata, e as Attachment, B as BuildEventPatch, C as ContextManager, f as ContextSpan, g as CreateSpanArgs, D as DEFAULT_REDACT_ATTRIBUTE_KEYS, h as DEFAULT_SECRET_KEY_NAMES, E as EndSpanArgs, i as EventBuilder, j as EventMetadataOptions, I as IdentifyInput, O as OtlpAnyValue, k as OtlpSpan, R as REDACTED_PLACEHOLDER, l as RaindropAISDKClient, m as RaindropAISDKContext, n as RaindropAISDKOptions, o as RaindropCallMetadata, p as RaindropTelemetryIntegration, q as RaindropTelemetryIntegrationOptions, S as SelfDiagnosticsOptions, r as SelfDiagnosticsSignalDefinition, s as SelfDiagnosticsSignalDefinitions, t as StartSpanArgs, T as TraceSpan, u as TransformSpanHook, W as WrapAISDKOptions, v as WrappedAI, w as WrappedAISDK, _ as _resetRaindropCallMetadataStorage, x as _resetWarnedMissingUserId, y as createRaindropAISDK, z as currentSpan, F as defaultTransformSpan, G as eventMetadata, H as eventMetadataFromChatRequest, J as getContextManager, K as getCurrentRaindropCallMetadata, L as readRaindropCallMetadataFromArgs, M as redactJsonAttributeValue, N as redactSecretsInObject, P as runWithRaindropCallMetadata, Q as withCurrent } from './index-DKdCelJA.mjs';
|
|
2
2
|
|
|
3
3
|
declare global {
|
|
4
4
|
var RAINDROP_ASYNC_LOCAL_STORAGE: (new <T>() => {
|
package/dist/index.node.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as AISDKChatRequestLike, a as AISDKChatRequestMessageLike, b as AISDKMessage, c as AgentCallMetadata, d as AgentWithMetadata, e as Attachment, B as BuildEventPatch, C as ContextManager, f as ContextSpan, g as CreateSpanArgs, E as EndSpanArgs,
|
|
1
|
+
export { A as AISDKChatRequestLike, a as AISDKChatRequestMessageLike, b as AISDKMessage, c as AgentCallMetadata, d as AgentWithMetadata, e as Attachment, B as BuildEventPatch, C as ContextManager, f as ContextSpan, g as CreateSpanArgs, D as DEFAULT_REDACT_ATTRIBUTE_KEYS, h as DEFAULT_SECRET_KEY_NAMES, E as EndSpanArgs, i as EventBuilder, j as EventMetadataOptions, I as IdentifyInput, O as OtlpAnyValue, k as OtlpSpan, R as REDACTED_PLACEHOLDER, l as RaindropAISDKClient, m as RaindropAISDKContext, n as RaindropAISDKOptions, o as RaindropCallMetadata, p as RaindropTelemetryIntegration, q as RaindropTelemetryIntegrationOptions, S as SelfDiagnosticsOptions, r as SelfDiagnosticsSignalDefinition, s as SelfDiagnosticsSignalDefinitions, t as StartSpanArgs, T as TraceSpan, u as TransformSpanHook, W as WrapAISDKOptions, v as WrappedAI, w as WrappedAISDK, _ as _resetRaindropCallMetadataStorage, x as _resetWarnedMissingUserId, y as createRaindropAISDK, z as currentSpan, F as defaultTransformSpan, G as eventMetadata, H as eventMetadataFromChatRequest, J as getContextManager, K as getCurrentRaindropCallMetadata, L as readRaindropCallMetadataFromArgs, M as redactJsonAttributeValue, N as redactSecretsInObject, P as runWithRaindropCallMetadata, Q as withCurrent } from './index-DKdCelJA.js';
|
|
2
2
|
|
|
3
3
|
declare global {
|
|
4
4
|
var RAINDROP_ASYNC_LOCAL_STORAGE: (new <T>() => {
|