@raindrop-ai/ai-sdk 0.0.28 → 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-ERNKJNE5.mjs → chunk-QGI4SABN.mjs} +275 -124
- 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 +280 -123
- package/dist/index.browser.mjs +275 -124
- package/dist/index.node.d.mts +1 -1
- package/dist/index.node.d.ts +1 -1
- package/dist/index.node.js +280 -123
- 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 +280 -123
- package/dist/index.workers.mjs +1 -1
- package/package.json +1 -1
package/dist/index.workers.js
CHANGED
|
@@ -4,7 +4,7 @@ var async_hooks = require('async_hooks');
|
|
|
4
4
|
|
|
5
5
|
// src/index.workers.ts
|
|
6
6
|
|
|
7
|
-
// ../core/dist/chunk-
|
|
7
|
+
// ../core/dist/chunk-VUNUOE2X.js
|
|
8
8
|
function getCrypto() {
|
|
9
9
|
const c = globalThis.crypto;
|
|
10
10
|
return c;
|
|
@@ -227,6 +227,114 @@ function buildExportTraceServiceRequest(spans, serviceName = "raindrop.core", se
|
|
|
227
227
|
]
|
|
228
228
|
};
|
|
229
229
|
}
|
|
230
|
+
var LOCAL_DEBUGGER_ENV_VAR = "RAINDROP_LOCAL_DEBUGGER";
|
|
231
|
+
var WORKSHOP_ENV_VAR = "RAINDROP_WORKSHOP";
|
|
232
|
+
var DEFAULT_LOCAL_WORKSHOP_URL = "http://localhost:5899/v1/";
|
|
233
|
+
function readEnvVar(name) {
|
|
234
|
+
var _a;
|
|
235
|
+
try {
|
|
236
|
+
const env = (_a = globalThis == null ? void 0 : globalThis.process) == null ? void 0 : _a.env;
|
|
237
|
+
if (env && typeof env[name] === "string" && env[name].length > 0) {
|
|
238
|
+
return env[name];
|
|
239
|
+
}
|
|
240
|
+
} catch (e) {
|
|
241
|
+
}
|
|
242
|
+
return void 0;
|
|
243
|
+
}
|
|
244
|
+
function readWorkshopEnv() {
|
|
245
|
+
const raw = readEnvVar(WORKSHOP_ENV_VAR);
|
|
246
|
+
if (raw === void 0) return void 0;
|
|
247
|
+
const trimmed = raw.trim();
|
|
248
|
+
if (trimmed.length === 0) return void 0;
|
|
249
|
+
if (/^https?:\/\//i.test(trimmed)) return { url: trimmed };
|
|
250
|
+
if (/^(1|true|yes|on)$/i.test(trimmed)) return "enable";
|
|
251
|
+
if (/^(0|false|no|off)$/i.test(trimmed)) return "disable";
|
|
252
|
+
return void 0;
|
|
253
|
+
}
|
|
254
|
+
function isLocalDevHost(hostname) {
|
|
255
|
+
if (!hostname) return false;
|
|
256
|
+
if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "0.0.0.0" || hostname === "::1") {
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
259
|
+
if (hostname.endsWith(".localhost")) return true;
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
function readRuntimeHostname() {
|
|
263
|
+
try {
|
|
264
|
+
const loc = globalThis == null ? void 0 : globalThis.location;
|
|
265
|
+
if (loc && typeof loc.hostname === "string" && loc.hostname.length > 0) {
|
|
266
|
+
return loc.hostname;
|
|
267
|
+
}
|
|
268
|
+
} catch (e) {
|
|
269
|
+
}
|
|
270
|
+
return void 0;
|
|
271
|
+
}
|
|
272
|
+
function shouldAutoEnableLocalWorkshop() {
|
|
273
|
+
if (isLocalDevHost(readRuntimeHostname())) return true;
|
|
274
|
+
if (readEnvVar("NODE_ENV") === "development") return true;
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
function resolveLocalDebuggerBaseUrl(baseUrl) {
|
|
278
|
+
var _a, _b, _c;
|
|
279
|
+
if (baseUrl === null) return null;
|
|
280
|
+
if (typeof baseUrl === "string" && baseUrl.length > 0) {
|
|
281
|
+
return (_a = formatEndpoint(baseUrl)) != null ? _a : null;
|
|
282
|
+
}
|
|
283
|
+
const explicitUrlEnv = readEnvVar(LOCAL_DEBUGGER_ENV_VAR);
|
|
284
|
+
if (explicitUrlEnv) return (_b = formatEndpoint(explicitUrlEnv)) != null ? _b : null;
|
|
285
|
+
const workshopEnv = readWorkshopEnv();
|
|
286
|
+
if (workshopEnv === "disable") return null;
|
|
287
|
+
if (workshopEnv === "enable") return DEFAULT_LOCAL_WORKSHOP_URL;
|
|
288
|
+
if (workshopEnv && "url" in workshopEnv) return (_c = formatEndpoint(workshopEnv.url)) != null ? _c : null;
|
|
289
|
+
if (shouldAutoEnableLocalWorkshop()) return DEFAULT_LOCAL_WORKSHOP_URL;
|
|
290
|
+
return null;
|
|
291
|
+
}
|
|
292
|
+
function localDebuggerEnabled(baseUrl) {
|
|
293
|
+
return resolveLocalDebuggerBaseUrl(baseUrl) !== null;
|
|
294
|
+
}
|
|
295
|
+
function mirrorTraceExportToLocalDebugger(body, options = {}) {
|
|
296
|
+
var _a;
|
|
297
|
+
const baseUrl = resolveLocalDebuggerBaseUrl(options.baseUrl);
|
|
298
|
+
if (!baseUrl) return;
|
|
299
|
+
void postJson(`${baseUrl}traces`, body, {}, {
|
|
300
|
+
maxAttempts: 1,
|
|
301
|
+
debug: (_a = options.debug) != null ? _a : false,
|
|
302
|
+
sdkName: options.sdkName
|
|
303
|
+
}).catch(() => {
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
function mirrorPartialEventToLocalDebugger(event, options = {}) {
|
|
307
|
+
var _a;
|
|
308
|
+
const baseUrl = resolveLocalDebuggerBaseUrl(options.baseUrl);
|
|
309
|
+
if (!baseUrl) return;
|
|
310
|
+
const headers = options.writeKey ? { Authorization: `Bearer ${options.writeKey}` } : {};
|
|
311
|
+
void postJson(`${baseUrl}events/track_partial`, event, headers, {
|
|
312
|
+
maxAttempts: 1,
|
|
313
|
+
debug: (_a = options.debug) != null ? _a : false,
|
|
314
|
+
sdkName: options.sdkName
|
|
315
|
+
}).catch(() => {
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
function sendLocalDebuggerLiveEvent(event, options = {}) {
|
|
319
|
+
var _a, _b;
|
|
320
|
+
const baseUrl = resolveLocalDebuggerBaseUrl(options.baseUrl);
|
|
321
|
+
if (!baseUrl) return;
|
|
322
|
+
void postJson(
|
|
323
|
+
`${baseUrl}live`,
|
|
324
|
+
{
|
|
325
|
+
...event,
|
|
326
|
+
type: event.type,
|
|
327
|
+
timestamp: (_a = event.timestamp) != null ? _a : Date.now()
|
|
328
|
+
},
|
|
329
|
+
{},
|
|
330
|
+
{
|
|
331
|
+
maxAttempts: 1,
|
|
332
|
+
debug: (_b = options.debug) != null ? _b : false,
|
|
333
|
+
sdkName: options.sdkName
|
|
334
|
+
}
|
|
335
|
+
).catch(() => {
|
|
336
|
+
});
|
|
337
|
+
}
|
|
230
338
|
function mergePatches(target, source) {
|
|
231
339
|
var _a, _b, _c, _d;
|
|
232
340
|
const out = { ...target, ...source };
|
|
@@ -244,7 +352,7 @@ var EventShipper = class {
|
|
|
244
352
|
this.sticky = /* @__PURE__ */ new Map();
|
|
245
353
|
this.timers = /* @__PURE__ */ new Map();
|
|
246
354
|
this.inFlight = /* @__PURE__ */ new Set();
|
|
247
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
355
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
248
356
|
this.writeKey = (_a = opts.writeKey) == null ? void 0 : _a.trim();
|
|
249
357
|
this.baseUrl = (_b = formatEndpoint(opts.endpoint)) != null ? _b : "https://api.raindrop.ai/v1/";
|
|
250
358
|
this.enabled = opts.enabled !== false;
|
|
@@ -253,11 +361,15 @@ var EventShipper = class {
|
|
|
253
361
|
this.sdkName = (_d = opts.sdkName) != null ? _d : "core";
|
|
254
362
|
this.prefix = `[raindrop-ai/${this.sdkName}]`;
|
|
255
363
|
this.defaultEventName = (_e = opts.defaultEventName) != null ? _e : "ai_generation";
|
|
364
|
+
this.localDebuggerUrl = (_f = resolveLocalDebuggerBaseUrl(opts.localDebuggerUrl)) != null ? _f : void 0;
|
|
365
|
+
if (this.debug && this.localDebuggerUrl) {
|
|
366
|
+
console.log(`${this.prefix} Local debugger mirroring: ${this.localDebuggerUrl}`);
|
|
367
|
+
}
|
|
256
368
|
const isNode = typeof process !== "undefined" && typeof process.version === "string";
|
|
257
369
|
this.context = {
|
|
258
370
|
library: {
|
|
259
|
-
name: (
|
|
260
|
-
version: (
|
|
371
|
+
name: (_g = opts.libraryName) != null ? _g : "@raindrop-ai/core",
|
|
372
|
+
version: (_h = opts.libraryVersion) != null ? _h : "0.0.0"
|
|
261
373
|
},
|
|
262
374
|
metadata: {
|
|
263
375
|
jsRuntime: isNode ? "node" : "web",
|
|
@@ -343,6 +455,7 @@ var EventShipper = class {
|
|
|
343
455
|
}
|
|
344
456
|
}
|
|
345
457
|
];
|
|
458
|
+
if (!this.writeKey) return;
|
|
346
459
|
const url = `${this.baseUrl}signals/track`;
|
|
347
460
|
try {
|
|
348
461
|
await postJson(url, body, this.authHeaders(), {
|
|
@@ -373,6 +486,7 @@ var EventShipper = class {
|
|
|
373
486
|
traits: (_a = user.traits) != null ? _a : {}
|
|
374
487
|
};
|
|
375
488
|
});
|
|
489
|
+
if (!this.writeKey) return;
|
|
376
490
|
if (body.length === 0) return;
|
|
377
491
|
const url = `${this.baseUrl}users/identify`;
|
|
378
492
|
try {
|
|
@@ -449,6 +563,18 @@ var EventShipper = class {
|
|
|
449
563
|
endpoint: url
|
|
450
564
|
});
|
|
451
565
|
}
|
|
566
|
+
if (this.localDebuggerUrl) {
|
|
567
|
+
mirrorPartialEventToLocalDebugger(payload, {
|
|
568
|
+
baseUrl: this.localDebuggerUrl,
|
|
569
|
+
writeKey: this.writeKey,
|
|
570
|
+
debug: this.debug,
|
|
571
|
+
sdkName: this.sdkName
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
if (!this.writeKey) {
|
|
575
|
+
if (!isPending) this.sticky.delete(eventId);
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
452
578
|
const p = postJson(url, payload, this.authHeaders(), {
|
|
453
579
|
maxAttempts: 3,
|
|
454
580
|
debug: this.debug,
|
|
@@ -473,101 +599,94 @@ var EventShipper = class {
|
|
|
473
599
|
}
|
|
474
600
|
}
|
|
475
601
|
};
|
|
476
|
-
var
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
602
|
+
var DEFAULT_SECRET_KEY_NAMES = [
|
|
603
|
+
"apikey",
|
|
604
|
+
"apisecret",
|
|
605
|
+
"apitoken",
|
|
606
|
+
"secretaccesskey",
|
|
607
|
+
"sessiontoken",
|
|
608
|
+
"privatekey",
|
|
609
|
+
"privatekeyid",
|
|
610
|
+
"clientsecret",
|
|
611
|
+
"accesstoken",
|
|
612
|
+
"refreshtoken",
|
|
613
|
+
"oauthtoken",
|
|
614
|
+
"bearertoken",
|
|
615
|
+
"authorization",
|
|
616
|
+
"password",
|
|
617
|
+
"passphrase"
|
|
618
|
+
];
|
|
619
|
+
var REDACTED_PLACEHOLDER = "[REDACTED]";
|
|
620
|
+
function normalizeKeyName(name) {
|
|
621
|
+
return name.toLowerCase().replace(/[-_.]/g, "");
|
|
622
|
+
}
|
|
623
|
+
function redactSecretsInObject(value, options) {
|
|
624
|
+
var _a, _b;
|
|
625
|
+
const normalizedSecretSet = buildSecretSet((_a = options == null ? void 0 : options.secretKeyNames) != null ? _a : DEFAULT_SECRET_KEY_NAMES);
|
|
626
|
+
const placeholder = (_b = options == null ? void 0 : options.placeholder) != null ? _b : REDACTED_PLACEHOLDER;
|
|
627
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
628
|
+
const walk = (node) => {
|
|
629
|
+
if (node === null || typeof node !== "object") return node;
|
|
630
|
+
if (seen.has(node)) return "[CIRCULAR]";
|
|
631
|
+
seen.add(node);
|
|
632
|
+
if (Array.isArray(node)) {
|
|
633
|
+
return node.map((item) => walk(item));
|
|
634
|
+
}
|
|
635
|
+
const out = {};
|
|
636
|
+
for (const [k, v] of Object.entries(node)) {
|
|
637
|
+
if (normalizedSecretSet.has(normalizeKeyName(k))) {
|
|
638
|
+
out[k] = placeholder;
|
|
639
|
+
} else {
|
|
640
|
+
out[k] = walk(v);
|
|
641
|
+
}
|
|
485
642
|
}
|
|
643
|
+
return out;
|
|
644
|
+
};
|
|
645
|
+
return walk(value);
|
|
646
|
+
}
|
|
647
|
+
function buildSecretSet(names) {
|
|
648
|
+
const set = /* @__PURE__ */ new Set();
|
|
649
|
+
for (const name of names) set.add(normalizeKeyName(name));
|
|
650
|
+
return set;
|
|
651
|
+
}
|
|
652
|
+
var DEFAULT_REDACT_ATTRIBUTE_KEYS = [
|
|
653
|
+
"ai.request.providerOptions",
|
|
654
|
+
"ai.response.providerMetadata"
|
|
655
|
+
];
|
|
656
|
+
function defaultTransformSpan(span) {
|
|
657
|
+
const attrs = span.attributes;
|
|
658
|
+
if (!attrs || attrs.length === 0) return span;
|
|
659
|
+
let nextAttrs;
|
|
660
|
+
for (let i = 0; i < attrs.length; i++) {
|
|
661
|
+
const attr = attrs[i];
|
|
662
|
+
const redacted = redactJsonAttributeValue(attr.key, attr.value);
|
|
663
|
+
if (redacted === void 0) continue;
|
|
664
|
+
if (!nextAttrs) nextAttrs = attrs.slice();
|
|
665
|
+
nextAttrs[i] = { key: attr.key, value: redacted };
|
|
666
|
+
}
|
|
667
|
+
if (!nextAttrs) return span;
|
|
668
|
+
return { ...span, attributes: nextAttrs };
|
|
669
|
+
}
|
|
670
|
+
var REDACT_JSON_ATTRIBUTE_KEYS = new Set(DEFAULT_REDACT_ATTRIBUTE_KEYS);
|
|
671
|
+
function redactJsonAttributeValue(key, value) {
|
|
672
|
+
if (!REDACT_JSON_ATTRIBUTE_KEYS.has(key)) return void 0;
|
|
673
|
+
const json = value.stringValue;
|
|
674
|
+
if (typeof json !== "string" || json.length === 0) return void 0;
|
|
675
|
+
let parsed;
|
|
676
|
+
try {
|
|
677
|
+
parsed = JSON.parse(json);
|
|
486
678
|
} catch (e) {
|
|
679
|
+
return void 0;
|
|
487
680
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
function readWorkshopEnv() {
|
|
491
|
-
const raw = readEnvVar(WORKSHOP_ENV_VAR);
|
|
492
|
-
if (raw === void 0) return void 0;
|
|
493
|
-
const trimmed = raw.trim();
|
|
494
|
-
if (trimmed.length === 0) return void 0;
|
|
495
|
-
if (/^https?:\/\//i.test(trimmed)) return { url: trimmed };
|
|
496
|
-
if (/^(1|true|yes|on)$/i.test(trimmed)) return "enable";
|
|
497
|
-
if (/^(0|false|no|off)$/i.test(trimmed)) return "disable";
|
|
498
|
-
return void 0;
|
|
499
|
-
}
|
|
500
|
-
function isLocalDevHost(hostname) {
|
|
501
|
-
if (!hostname) return false;
|
|
502
|
-
if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "0.0.0.0" || hostname === "::1") {
|
|
503
|
-
return true;
|
|
504
|
-
}
|
|
505
|
-
if (hostname.endsWith(".localhost")) return true;
|
|
506
|
-
return false;
|
|
507
|
-
}
|
|
508
|
-
function readRuntimeHostname() {
|
|
681
|
+
const scrubbed = redactSecretsInObject(parsed);
|
|
682
|
+
let scrubbedJson;
|
|
509
683
|
try {
|
|
510
|
-
|
|
511
|
-
if (loc && typeof loc.hostname === "string" && loc.hostname.length > 0) {
|
|
512
|
-
return loc.hostname;
|
|
513
|
-
}
|
|
684
|
+
scrubbedJson = JSON.stringify(scrubbed);
|
|
514
685
|
} catch (e) {
|
|
686
|
+
return void 0;
|
|
515
687
|
}
|
|
516
|
-
return void 0;
|
|
517
|
-
}
|
|
518
|
-
function shouldAutoEnableLocalWorkshop() {
|
|
519
|
-
if (isLocalDevHost(readRuntimeHostname())) return true;
|
|
520
|
-
if (readEnvVar("NODE_ENV") === "development") return true;
|
|
521
|
-
return false;
|
|
522
|
-
}
|
|
523
|
-
function resolveLocalDebuggerBaseUrl(baseUrl) {
|
|
524
|
-
var _a, _b, _c;
|
|
525
|
-
if (baseUrl === null) return null;
|
|
526
|
-
if (typeof baseUrl === "string" && baseUrl.length > 0) {
|
|
527
|
-
return (_a = formatEndpoint(baseUrl)) != null ? _a : null;
|
|
528
|
-
}
|
|
529
|
-
const explicitUrlEnv = readEnvVar(LOCAL_DEBUGGER_ENV_VAR);
|
|
530
|
-
if (explicitUrlEnv) return (_b = formatEndpoint(explicitUrlEnv)) != null ? _b : null;
|
|
531
|
-
const workshopEnv = readWorkshopEnv();
|
|
532
|
-
if (workshopEnv === "disable") return null;
|
|
533
|
-
if (workshopEnv === "enable") return DEFAULT_LOCAL_WORKSHOP_URL;
|
|
534
|
-
if (workshopEnv && "url" in workshopEnv) return (_c = formatEndpoint(workshopEnv.url)) != null ? _c : null;
|
|
535
|
-
if (shouldAutoEnableLocalWorkshop()) return DEFAULT_LOCAL_WORKSHOP_URL;
|
|
536
|
-
return null;
|
|
537
|
-
}
|
|
538
|
-
function localDebuggerEnabled(baseUrl) {
|
|
539
|
-
return resolveLocalDebuggerBaseUrl(baseUrl) !== null;
|
|
540
|
-
}
|
|
541
|
-
function mirrorTraceExportToLocalDebugger(body, options = {}) {
|
|
542
|
-
var _a;
|
|
543
|
-
const baseUrl = resolveLocalDebuggerBaseUrl(options.baseUrl);
|
|
544
|
-
if (!baseUrl) return;
|
|
545
|
-
void postJson(`${baseUrl}traces`, body, {}, {
|
|
546
|
-
maxAttempts: 1,
|
|
547
|
-
debug: (_a = options.debug) != null ? _a : false,
|
|
548
|
-
sdkName: options.sdkName
|
|
549
|
-
}).catch(() => {
|
|
550
|
-
});
|
|
551
|
-
}
|
|
552
|
-
function sendLocalDebuggerLiveEvent(event, options = {}) {
|
|
553
|
-
var _a, _b;
|
|
554
|
-
const baseUrl = resolveLocalDebuggerBaseUrl(options.baseUrl);
|
|
555
|
-
if (!baseUrl) return;
|
|
556
|
-
void postJson(
|
|
557
|
-
`${baseUrl}live`,
|
|
558
|
-
{
|
|
559
|
-
...event,
|
|
560
|
-
type: event.type,
|
|
561
|
-
timestamp: (_a = event.timestamp) != null ? _a : Date.now()
|
|
562
|
-
},
|
|
563
|
-
{},
|
|
564
|
-
{
|
|
565
|
-
maxAttempts: 1,
|
|
566
|
-
debug: (_b = options.debug) != null ? _b : false,
|
|
567
|
-
sdkName: options.sdkName
|
|
568
|
-
}
|
|
569
|
-
).catch(() => {
|
|
570
|
-
});
|
|
688
|
+
if (scrubbedJson === json) return void 0;
|
|
689
|
+
return { stringValue: scrubbedJson };
|
|
571
690
|
}
|
|
572
691
|
var TraceShipper = class {
|
|
573
692
|
constructor(opts) {
|
|
@@ -590,6 +709,42 @@ var TraceShipper = class {
|
|
|
590
709
|
if (this.debug && this.localDebuggerUrl) {
|
|
591
710
|
console.log(`${this.prefix} Local debugger mirroring: ${this.localDebuggerUrl}`);
|
|
592
711
|
}
|
|
712
|
+
this.transformSpanHook = opts.transformSpan;
|
|
713
|
+
this.disableDefaultRedaction = opts.disableDefaultRedaction === true;
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* Apply the user `transformSpan` hook (if any) followed by the default
|
|
717
|
+
* redactor (unless disabled). Returns either the (possibly new) span to
|
|
718
|
+
* ship, or `null` to drop the span entirely.
|
|
719
|
+
*
|
|
720
|
+
* Ordering: user hook runs first so callers can rewrite the span freely
|
|
721
|
+
* (rename attrs, add new ones, scrub things the default doesn't know
|
|
722
|
+
* about). The default redactor then runs on whatever the user produced,
|
|
723
|
+
* acting as the always-on floor for documented BYOK secrets. If the user
|
|
724
|
+
* sets `disableDefaultRedaction: true`, the floor is skipped.
|
|
725
|
+
*
|
|
726
|
+
* Fail-closed: if the user hook throws, the span is dropped — a buggy
|
|
727
|
+
* hook can never accidentally ship raw, un-redacted spans.
|
|
728
|
+
*/
|
|
729
|
+
redactSpan(span) {
|
|
730
|
+
let current = span;
|
|
731
|
+
if (this.transformSpanHook) {
|
|
732
|
+
try {
|
|
733
|
+
const result = this.transformSpanHook(current);
|
|
734
|
+
if (result === null) return null;
|
|
735
|
+
if (result !== void 0) current = result;
|
|
736
|
+
} catch (err) {
|
|
737
|
+
if (this.debug) {
|
|
738
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
739
|
+
console.warn(`${this.prefix} transformSpan hook threw: ${msg}`);
|
|
740
|
+
}
|
|
741
|
+
return null;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
if (!this.disableDefaultRedaction) {
|
|
745
|
+
current = defaultTransformSpan(current);
|
|
746
|
+
}
|
|
747
|
+
return current;
|
|
593
748
|
}
|
|
594
749
|
isDebugEnabled() {
|
|
595
750
|
return this.debug;
|
|
@@ -607,8 +762,8 @@ var TraceShipper = class {
|
|
|
607
762
|
];
|
|
608
763
|
if ((_b = args.attributes) == null ? void 0 : _b.length) attrs.push(...args.attributes);
|
|
609
764
|
const span = { ids, name: args.name, startTimeUnixNano: started, attributes: attrs };
|
|
610
|
-
|
|
611
|
-
|
|
765
|
+
this.mirrorToLocalDebugger(
|
|
766
|
+
buildOtlpSpan({
|
|
612
767
|
ids: span.ids,
|
|
613
768
|
name: span.name,
|
|
614
769
|
startTimeUnixNano: span.startTimeUnixNano,
|
|
@@ -616,16 +771,21 @@ var TraceShipper = class {
|
|
|
616
771
|
// placeholder — will be updated on endSpan
|
|
617
772
|
attributes: span.attributes,
|
|
618
773
|
status: { code: SpanStatusCode.UNSET }
|
|
619
|
-
})
|
|
620
|
-
|
|
621
|
-
mirrorTraceExportToLocalDebugger(body, {
|
|
622
|
-
baseUrl: this.localDebuggerUrl,
|
|
623
|
-
debug: false,
|
|
624
|
-
sdkName: this.sdkName
|
|
625
|
-
});
|
|
626
|
-
}
|
|
774
|
+
})
|
|
775
|
+
);
|
|
627
776
|
return span;
|
|
628
777
|
}
|
|
778
|
+
mirrorToLocalDebugger(span) {
|
|
779
|
+
if (!this.localDebuggerUrl) return;
|
|
780
|
+
const redacted = this.redactSpan(span);
|
|
781
|
+
if (redacted === null) return;
|
|
782
|
+
const body = buildExportTraceServiceRequest([redacted], this.serviceName, this.serviceVersion);
|
|
783
|
+
mirrorTraceExportToLocalDebugger(body, {
|
|
784
|
+
baseUrl: this.localDebuggerUrl,
|
|
785
|
+
debug: false,
|
|
786
|
+
sdkName: this.sdkName
|
|
787
|
+
});
|
|
788
|
+
}
|
|
629
789
|
endSpan(span, extra) {
|
|
630
790
|
var _a, _b;
|
|
631
791
|
if (span.endTimeUnixNano) return;
|
|
@@ -647,14 +807,7 @@ var TraceShipper = class {
|
|
|
647
807
|
status
|
|
648
808
|
});
|
|
649
809
|
this.enqueue(otlp);
|
|
650
|
-
|
|
651
|
-
const body = buildExportTraceServiceRequest([otlp], this.serviceName, this.serviceVersion);
|
|
652
|
-
mirrorTraceExportToLocalDebugger(body, {
|
|
653
|
-
baseUrl: this.localDebuggerUrl,
|
|
654
|
-
debug: false,
|
|
655
|
-
sdkName: this.sdkName
|
|
656
|
-
});
|
|
657
|
-
}
|
|
810
|
+
this.mirrorToLocalDebugger(otlp);
|
|
658
811
|
}
|
|
659
812
|
createSpan(args) {
|
|
660
813
|
var _a;
|
|
@@ -672,14 +825,7 @@ var TraceShipper = class {
|
|
|
672
825
|
status: args.status
|
|
673
826
|
});
|
|
674
827
|
this.enqueue(otlp);
|
|
675
|
-
|
|
676
|
-
const body = buildExportTraceServiceRequest([otlp], this.serviceName, this.serviceVersion);
|
|
677
|
-
mirrorTraceExportToLocalDebugger(body, {
|
|
678
|
-
baseUrl: this.localDebuggerUrl,
|
|
679
|
-
debug: false,
|
|
680
|
-
sdkName: this.sdkName
|
|
681
|
-
});
|
|
682
|
-
}
|
|
828
|
+
this.mirrorToLocalDebugger(otlp);
|
|
683
829
|
}
|
|
684
830
|
enqueue(span) {
|
|
685
831
|
if (!this.enabled) return;
|
|
@@ -691,10 +837,12 @@ var TraceShipper = class {
|
|
|
691
837
|
)}`
|
|
692
838
|
);
|
|
693
839
|
}
|
|
840
|
+
const redacted = this.redactSpan(span);
|
|
841
|
+
if (redacted === null) return;
|
|
694
842
|
if (this.queue.length >= this.maxQueueSize) {
|
|
695
843
|
this.queue.shift();
|
|
696
844
|
}
|
|
697
|
-
this.queue.push(
|
|
845
|
+
this.queue.push(redacted);
|
|
698
846
|
if (this.queue.length >= this.maxBatchSize) {
|
|
699
847
|
void this.flush().catch(() => {
|
|
700
848
|
});
|
|
@@ -716,6 +864,7 @@ var TraceShipper = class {
|
|
|
716
864
|
}
|
|
717
865
|
while (this.queue.length > 0) {
|
|
718
866
|
const batch = this.queue.splice(0, this.maxBatchSize);
|
|
867
|
+
if (!this.writeKey) continue;
|
|
719
868
|
const body = buildExportTraceServiceRequest(batch, this.serviceName, this.serviceVersion);
|
|
720
869
|
const url = `${this.baseUrl}traces`;
|
|
721
870
|
if (this.debug) {
|
|
@@ -875,7 +1024,7 @@ globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = async_hooks.AsyncLocalStorage;
|
|
|
875
1024
|
// package.json
|
|
876
1025
|
var package_default = {
|
|
877
1026
|
name: "@raindrop-ai/ai-sdk",
|
|
878
|
-
version: "0.0.
|
|
1027
|
+
version: "0.0.29"};
|
|
879
1028
|
|
|
880
1029
|
// src/internal/version.ts
|
|
881
1030
|
var libraryName = package_default.name;
|
|
@@ -4275,7 +4424,7 @@ function envDebugEnabled() {
|
|
|
4275
4424
|
return flag === "1" || flag === "true";
|
|
4276
4425
|
}
|
|
4277
4426
|
function createRaindropAISDK(opts) {
|
|
4278
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
4427
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
4279
4428
|
const writeKey = opts.writeKey;
|
|
4280
4429
|
const eventsRequested = ((_a = opts.events) == null ? void 0 : _a.enabled) !== false;
|
|
4281
4430
|
const tracesRequested = ((_b = opts.traces) == null ? void 0 : _b.enabled) !== false;
|
|
@@ -4304,7 +4453,9 @@ function createRaindropAISDK(opts) {
|
|
|
4304
4453
|
flushIntervalMs: (_g = opts.traces) == null ? void 0 : _g.flushIntervalMs,
|
|
4305
4454
|
maxBatchSize: (_h = opts.traces) == null ? void 0 : _h.maxBatchSize,
|
|
4306
4455
|
maxQueueSize: (_i = opts.traces) == null ? void 0 : _i.maxQueueSize,
|
|
4307
|
-
localDebuggerUrl
|
|
4456
|
+
localDebuggerUrl,
|
|
4457
|
+
transformSpan: (_j = opts.traces) == null ? void 0 : _j.transformSpan,
|
|
4458
|
+
disableDefaultRedaction: (_k = opts.traces) == null ? void 0 : _k.disableDefaultRedaction
|
|
4308
4459
|
});
|
|
4309
4460
|
return {
|
|
4310
4461
|
wrap(aiSDK, options) {
|
|
@@ -4432,15 +4583,21 @@ if (!globalThis.RAINDROP_ASYNC_LOCAL_STORAGE) {
|
|
|
4432
4583
|
globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = async_hooks.AsyncLocalStorage;
|
|
4433
4584
|
}
|
|
4434
4585
|
|
|
4586
|
+
exports.DEFAULT_REDACT_ATTRIBUTE_KEYS = DEFAULT_REDACT_ATTRIBUTE_KEYS;
|
|
4587
|
+
exports.DEFAULT_SECRET_KEY_NAMES = DEFAULT_SECRET_KEY_NAMES;
|
|
4588
|
+
exports.REDACTED_PLACEHOLDER = REDACTED_PLACEHOLDER;
|
|
4435
4589
|
exports.RaindropTelemetryIntegration = RaindropTelemetryIntegration;
|
|
4436
4590
|
exports._resetRaindropCallMetadataStorage = _resetRaindropCallMetadataStorage;
|
|
4437
4591
|
exports._resetWarnedMissingUserId = _resetWarnedMissingUserId;
|
|
4438
4592
|
exports.createRaindropAISDK = createRaindropAISDK;
|
|
4439
4593
|
exports.currentSpan = currentSpan;
|
|
4594
|
+
exports.defaultTransformSpan = defaultTransformSpan;
|
|
4440
4595
|
exports.eventMetadata = eventMetadata;
|
|
4441
4596
|
exports.eventMetadataFromChatRequest = eventMetadataFromChatRequest;
|
|
4442
4597
|
exports.getContextManager = getContextManager;
|
|
4443
4598
|
exports.getCurrentRaindropCallMetadata = getCurrentRaindropCallMetadata;
|
|
4444
4599
|
exports.readRaindropCallMetadataFromArgs = readRaindropCallMetadataFromArgs;
|
|
4600
|
+
exports.redactJsonAttributeValue = redactJsonAttributeValue;
|
|
4601
|
+
exports.redactSecretsInObject = redactSecretsInObject;
|
|
4445
4602
|
exports.runWithRaindropCallMetadata = runWithRaindropCallMetadata;
|
|
4446
4603
|
exports.withCurrent = withCurrent;
|
package/dist/index.workers.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { RaindropTelemetryIntegration, _resetRaindropCallMetadataStorage, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, eventMetadataFromChatRequest, getContextManager, getCurrentRaindropCallMetadata, readRaindropCallMetadataFromArgs, runWithRaindropCallMetadata, withCurrent } from './chunk-
|
|
1
|
+
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 } from './chunk-QGI4SABN.mjs';
|
|
2
2
|
import { AsyncLocalStorage } from 'async_hooks';
|
|
3
3
|
|
|
4
4
|
if (!globalThis.RAINDROP_ASYNC_LOCAL_STORAGE) {
|
package/package.json
CHANGED