raindrop-ai 1.0.7 → 1.0.8
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-BMYWLBYI.mjs → chunk-JK73MFZN.mjs} +731 -130
- package/dist/{chunk-J2WYJUH7.mjs → chunk-NELGM2YD.mjs} +22 -9
- package/dist/evals/cli.js +754 -146
- package/dist/evals/cli.mjs +2 -2
- package/dist/{index-BXzOiaVu.d.mts → index-BOTg0MlJ.d.mts} +1205 -1187
- package/dist/{index-BXzOiaVu.d.ts → index-BOTg0MlJ.d.ts} +1205 -1187
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +759 -151
- package/dist/index.mjs +2 -2
- package/dist/tracing/index.d.mts +5 -1
- package/dist/tracing/index.d.ts +5 -1
- package/dist/tracing/index.js +985 -456
- package/dist/tracing/index.mjs +1 -1
- package/package.json +2 -2
package/dist/evals/cli.js
CHANGED
|
@@ -1095,7 +1095,7 @@ function evalScopeAttributes() {
|
|
|
1095
1095
|
return { [EVAL_CORRELATION_ID_ATTRIBUTE]: scope.correlationId };
|
|
1096
1096
|
}
|
|
1097
1097
|
|
|
1098
|
-
// ../core/dist/chunk-
|
|
1098
|
+
// ../core/dist/chunk-R5EQZAA5.js
|
|
1099
1099
|
var require_NameRedactor = __commonJS({
|
|
1100
1100
|
"../redact-pii/dist/built-ins/NameRedactor.js"(exports2) {
|
|
1101
1101
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
@@ -1964,9 +1964,9 @@ var SUBAGENT_ABORT_OPERATION_ID = "ai.subagent.failed";
|
|
|
1964
1964
|
var SUBAGENT_ABORT_SPAN_NAME = SUBAGENT_ABORT_OPERATION_ID;
|
|
1965
1965
|
var DEFAULT_DISPATCH_SPAN_NAME = "launch_subagent";
|
|
1966
1966
|
var HANDOFF_TERMINAL_PROPERTY_KEY = HANDOFF_ATTRIBUTE_SUFFIXES.terminal;
|
|
1967
|
-
function defined(
|
|
1967
|
+
function defined(entries2) {
|
|
1968
1968
|
const out = {};
|
|
1969
|
-
for (const [key, value] of Object.entries(
|
|
1969
|
+
for (const [key, value] of Object.entries(entries2)) {
|
|
1970
1970
|
if (typeof value === "string" && value.trim().length > 0) out[key] = value;
|
|
1971
1971
|
}
|
|
1972
1972
|
return out;
|
|
@@ -2040,8 +2040,8 @@ function warnNonConformantIdsOnce(traceId, spanId) {
|
|
|
2040
2040
|
var HANDOFF_HEADER = "x-raindrop-handoff";
|
|
2041
2041
|
var LANGSMITH_TRACE_HEADER = "langsmith-trace";
|
|
2042
2042
|
var LANGSMITH_METADATA_BAGGAGE_KEY = "langsmith-metadata";
|
|
2043
|
-
function encodeBaggage(
|
|
2044
|
-
return Object.entries(
|
|
2043
|
+
function encodeBaggage(entries2) {
|
|
2044
|
+
return Object.entries(entries2).filter((entry) => Boolean(entry[1])).map(([key, value]) => `${key}=${encodeURIComponent(value)}`).join(",");
|
|
2045
2045
|
}
|
|
2046
2046
|
function decodeBaggage(header) {
|
|
2047
2047
|
if (!header) return {};
|
|
@@ -2468,7 +2468,7 @@ async function sendJson(url, body, headers, opts) {
|
|
|
2468
2468
|
resp = await runWithTracingSuppressed(
|
|
2469
2469
|
() => fetch(url, {
|
|
2470
2470
|
method: "POST",
|
|
2471
|
-
redirect: headers["X-Raindrop-Replay-Id"] !== void 0 ? "error" : "follow",
|
|
2471
|
+
redirect: headers["X-Raindrop-Replay-Id"] !== void 0 || opts.followRedirects === false ? "error" : "follow",
|
|
2472
2472
|
headers: {
|
|
2473
2473
|
"Content-Type": "application/json",
|
|
2474
2474
|
...headers
|
|
@@ -2756,7 +2756,8 @@ function mirrorTraceExportToLocalDebugger(body, options = {}) {
|
|
|
2756
2756
|
maxAttempts: 1,
|
|
2757
2757
|
debug: (_a = options.debug) != null ? _a : false,
|
|
2758
2758
|
sdkName: options.sdkName,
|
|
2759
|
-
timeoutMs: LOCAL_DEBUGGER_MIRROR_TIMEOUT_MS
|
|
2759
|
+
timeoutMs: LOCAL_DEBUGGER_MIRROR_TIMEOUT_MS,
|
|
2760
|
+
followRedirects: options.followRedirects
|
|
2760
2761
|
}).catch(() => {
|
|
2761
2762
|
});
|
|
2762
2763
|
}
|
|
@@ -2769,7 +2770,8 @@ function mirrorPartialEventToLocalDebugger(event, options = {}) {
|
|
|
2769
2770
|
maxAttempts: 1,
|
|
2770
2771
|
debug: (_a = options.debug) != null ? _a : false,
|
|
2771
2772
|
sdkName: options.sdkName,
|
|
2772
|
-
timeoutMs: LOCAL_DEBUGGER_MIRROR_TIMEOUT_MS
|
|
2773
|
+
timeoutMs: LOCAL_DEBUGGER_MIRROR_TIMEOUT_MS,
|
|
2774
|
+
followRedirects: options.followRedirects
|
|
2773
2775
|
}).catch(() => {
|
|
2774
2776
|
});
|
|
2775
2777
|
}
|
|
@@ -2790,7 +2792,8 @@ function sendLocalDebuggerLiveEvent(event, options = {}) {
|
|
|
2790
2792
|
{
|
|
2791
2793
|
maxAttempts: 1,
|
|
2792
2794
|
debug: (_b = options.debug) != null ? _b : false,
|
|
2793
|
-
sdkName: options.sdkName
|
|
2795
|
+
sdkName: options.sdkName,
|
|
2796
|
+
followRedirects: options.followRedirects
|
|
2794
2797
|
}
|
|
2795
2798
|
).catch(() => {
|
|
2796
2799
|
});
|
|
@@ -3033,6 +3036,143 @@ var PiiFieldRedactor = class {
|
|
|
3033
3036
|
return out;
|
|
3034
3037
|
}
|
|
3035
3038
|
};
|
|
3039
|
+
var REMOTE_PII_LOOKUP_TIMEOUT_MS = 3e3;
|
|
3040
|
+
var REFRESH_AFTER_MS = 5 * 6e4;
|
|
3041
|
+
var RETRY_AFTER_MS = 3e4;
|
|
3042
|
+
var STATE_KEY2 = /* @__PURE__ */ Symbol.for("raindrop.remotePiiConfig");
|
|
3043
|
+
function entries() {
|
|
3044
|
+
const holder = globalThis;
|
|
3045
|
+
let current = holder[STATE_KEY2];
|
|
3046
|
+
if (!current) {
|
|
3047
|
+
current = /* @__PURE__ */ new Map();
|
|
3048
|
+
holder[STATE_KEY2] = current;
|
|
3049
|
+
}
|
|
3050
|
+
return current;
|
|
3051
|
+
}
|
|
3052
|
+
function isRecord2(value) {
|
|
3053
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3054
|
+
}
|
|
3055
|
+
function baseUrlOf(endpoint) {
|
|
3056
|
+
return endpoint.endsWith("/") ? endpoint : `${endpoint}/`;
|
|
3057
|
+
}
|
|
3058
|
+
function cacheKey(endpoint, writeKey) {
|
|
3059
|
+
return `${baseUrlOf(endpoint)}
|
|
3060
|
+
${writeKey}`;
|
|
3061
|
+
}
|
|
3062
|
+
function parseAnswer(body) {
|
|
3063
|
+
if (!isRecord2(body)) return "unknown";
|
|
3064
|
+
if (!("pii" in body)) return "not_enrolled";
|
|
3065
|
+
const pii = body.pii;
|
|
3066
|
+
if (!isRecord2(pii)) return "unknown";
|
|
3067
|
+
return pii.redact === "on" || pii.redact === "off" ? pii.redact : "unknown";
|
|
3068
|
+
}
|
|
3069
|
+
async function lookup(baseUrl, writeKey) {
|
|
3070
|
+
if (typeof fetch !== "function") return void 0;
|
|
3071
|
+
const controller = typeof AbortController === "function" ? new AbortController() : void 0;
|
|
3072
|
+
const timer = setTimeout(() => controller == null ? void 0 : controller.abort(), REMOTE_PII_LOOKUP_TIMEOUT_MS);
|
|
3073
|
+
if (typeof timer === "object" && "unref" in timer) timer.unref();
|
|
3074
|
+
try {
|
|
3075
|
+
const response = await runWithTracingSuppressed(
|
|
3076
|
+
() => fetch(`${baseUrl}auth`, {
|
|
3077
|
+
method: "POST",
|
|
3078
|
+
headers: { Authorization: `Bearer ${writeKey}`, "Content-Type": "application/json" },
|
|
3079
|
+
body: "{}",
|
|
3080
|
+
signal: controller == null ? void 0 : controller.signal
|
|
3081
|
+
})
|
|
3082
|
+
);
|
|
3083
|
+
if (!response.ok) return void 0;
|
|
3084
|
+
const body = await response.json();
|
|
3085
|
+
return parseAnswer(body);
|
|
3086
|
+
} catch (e) {
|
|
3087
|
+
return void 0;
|
|
3088
|
+
} finally {
|
|
3089
|
+
clearTimeout(timer);
|
|
3090
|
+
}
|
|
3091
|
+
}
|
|
3092
|
+
function entryFor(endpoint, writeKey) {
|
|
3093
|
+
const key = cacheKey(endpoint, writeKey);
|
|
3094
|
+
const all = entries();
|
|
3095
|
+
let entry = all.get(key);
|
|
3096
|
+
if (!entry) {
|
|
3097
|
+
entry = { known: void 0, pending: void 0, nextLookupAt: 0, settled: false };
|
|
3098
|
+
all.set(key, entry);
|
|
3099
|
+
}
|
|
3100
|
+
if (!entry.pending && Date.now() >= entry.nextLookupAt) {
|
|
3101
|
+
const current = entry;
|
|
3102
|
+
current.pending = lookup(baseUrlOf(endpoint), writeKey).then((answer) => {
|
|
3103
|
+
if (answer !== void 0) current.known = answer;
|
|
3104
|
+
current.nextLookupAt = Date.now() + (answer === void 0 ? RETRY_AFTER_MS : REFRESH_AFTER_MS);
|
|
3105
|
+
current.pending = void 0;
|
|
3106
|
+
current.settled = true;
|
|
3107
|
+
});
|
|
3108
|
+
}
|
|
3109
|
+
return entry;
|
|
3110
|
+
}
|
|
3111
|
+
function remotePiiAnswerNow(endpoint, writeKey) {
|
|
3112
|
+
const entry = entryFor(endpoint, writeKey);
|
|
3113
|
+
if (entry.known !== void 0) return entry.known;
|
|
3114
|
+
return entry.settled ? "unknown" : void 0;
|
|
3115
|
+
}
|
|
3116
|
+
async function remotePiiAnswer(endpoint, writeKey, deadlineAt) {
|
|
3117
|
+
var _a;
|
|
3118
|
+
const entry = entryFor(endpoint, writeKey);
|
|
3119
|
+
const now = remotePiiAnswerNow(endpoint, writeKey);
|
|
3120
|
+
if (now !== void 0 || !entry.pending) return now != null ? now : "unknown";
|
|
3121
|
+
const waitMs = Math.min(
|
|
3122
|
+
REMOTE_PII_LOOKUP_TIMEOUT_MS,
|
|
3123
|
+
deadlineAt === void 0 ? Infinity : Math.max(0, deadlineAt - Date.now())
|
|
3124
|
+
);
|
|
3125
|
+
let timer;
|
|
3126
|
+
await Promise.race([
|
|
3127
|
+
entry.pending,
|
|
3128
|
+
new Promise((resolve3) => {
|
|
3129
|
+
timer = setTimeout(resolve3, waitMs);
|
|
3130
|
+
})
|
|
3131
|
+
]);
|
|
3132
|
+
clearTimeout(timer);
|
|
3133
|
+
return (_a = entry.known) != null ? _a : "unknown";
|
|
3134
|
+
}
|
|
3135
|
+
function resolvePiiRedaction(local, remote, answer) {
|
|
3136
|
+
if (local !== void 0) return local;
|
|
3137
|
+
if (!remote) return false;
|
|
3138
|
+
if (answer === "on") return true;
|
|
3139
|
+
if (answer === "off" || answer === "not_enrolled") return false;
|
|
3140
|
+
const whenUnknown = typeof remote === "object" ? remote.whenUnknown : void 0;
|
|
3141
|
+
return whenUnknown !== "local";
|
|
3142
|
+
}
|
|
3143
|
+
function needsLookup(local, remote, writeKey) {
|
|
3144
|
+
return local === void 0 && Boolean(remote) && Boolean(writeKey);
|
|
3145
|
+
}
|
|
3146
|
+
function piiRedactionNow(local, remote, endpoint, writeKey) {
|
|
3147
|
+
if (!needsLookup(local, remote, writeKey)) return local === true;
|
|
3148
|
+
try {
|
|
3149
|
+
const answer = remotePiiAnswerNow(endpoint, writeKey);
|
|
3150
|
+
return answer === void 0 ? void 0 : resolvePiiRedaction(local, remote, answer);
|
|
3151
|
+
} catch (e) {
|
|
3152
|
+
return resolvePiiRedaction(local, remote, "unknown");
|
|
3153
|
+
}
|
|
3154
|
+
}
|
|
3155
|
+
async function piiRedaction(local, remote, endpoint, writeKey, deadlineAt) {
|
|
3156
|
+
if (!needsLookup(local, remote, writeKey)) return local === true;
|
|
3157
|
+
try {
|
|
3158
|
+
return resolvePiiRedaction(local, remote, await remotePiiAnswer(endpoint, writeKey, deadlineAt));
|
|
3159
|
+
} catch (e) {
|
|
3160
|
+
return resolvePiiRedaction(local, remote, "unknown");
|
|
3161
|
+
}
|
|
3162
|
+
}
|
|
3163
|
+
var LOCAL_TRACE_KEY = /* @__PURE__ */ Symbol.for("raindrop.localTracePiiRedaction");
|
|
3164
|
+
function localTraceKeys() {
|
|
3165
|
+
var _a;
|
|
3166
|
+
const holder = globalThis;
|
|
3167
|
+
(_a = holder[LOCAL_TRACE_KEY]) != null ? _a : holder[LOCAL_TRACE_KEY] = /* @__PURE__ */ new Set();
|
|
3168
|
+
return holder[LOCAL_TRACE_KEY];
|
|
3169
|
+
}
|
|
3170
|
+
function requestLocalTracePiiRedaction(endpoint, writeKey) {
|
|
3171
|
+
localTraceKeys().add(cacheKey(endpoint, writeKey != null ? writeKey : ""));
|
|
3172
|
+
}
|
|
3173
|
+
function localTracePiiRedactionRequested(endpoint, writeKey) {
|
|
3174
|
+
return localTraceKeys().has(cacheKey(endpoint, writeKey != null ? writeKey : ""));
|
|
3175
|
+
}
|
|
3036
3176
|
function detectRuntime() {
|
|
3037
3177
|
if (typeof process === "object" && process && typeof process.env === "object" && process.env && typeof process.version === "string") {
|
|
3038
3178
|
return "node";
|
|
@@ -3052,6 +3192,14 @@ function isMissingUserId(value) {
|
|
|
3052
3192
|
const trimmed = value.trim();
|
|
3053
3193
|
return trimmed === "" || PLACEHOLDER_USER_IDS.has(trimmed);
|
|
3054
3194
|
}
|
|
3195
|
+
function snapshotPayload(payload) {
|
|
3196
|
+
try {
|
|
3197
|
+
const json = JSON.stringify(payload);
|
|
3198
|
+
return json === void 0 ? payload : JSON.parse(json);
|
|
3199
|
+
} catch (e) {
|
|
3200
|
+
return payload;
|
|
3201
|
+
}
|
|
3202
|
+
}
|
|
3055
3203
|
var MAX_DEFERRED_SENDS = 1e3;
|
|
3056
3204
|
var POST_SHUTDOWN_TIMEOUT_MS = 5e3;
|
|
3057
3205
|
function appGitOwnerId(prefix) {
|
|
@@ -3158,7 +3306,7 @@ var EventShipper = class {
|
|
|
3158
3306
|
this.sendChains = /* @__PURE__ */ new Map();
|
|
3159
3307
|
this.deferredSends = /* @__PURE__ */ new Set();
|
|
3160
3308
|
this.hasShutdown = false;
|
|
3161
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
3309
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
3162
3310
|
this.appGitContext = (_a = opts.appGitContext) != null ? _a : createAppGitContext(opts.appGit);
|
|
3163
3311
|
this.ownsAppGitContext = opts.appGitContext === void 0;
|
|
3164
3312
|
this.writeKey = (_b = opts.writeKey) == null ? void 0 : _b.trim();
|
|
@@ -3172,6 +3320,7 @@ var EventShipper = class {
|
|
|
3172
3320
|
this.maxTextFieldCharsOpt = opts.maxTextFieldChars;
|
|
3173
3321
|
this.flushTimeoutMs = resolveFlushTimeoutMs(opts.flushTimeoutMs);
|
|
3174
3322
|
this.localDebuggerUrl = (_g = resolveLocalDebuggerBaseUrl(opts.localDebuggerUrl)) != null ? _g : void 0;
|
|
3323
|
+
this.localDebuggerFollowRedirects = (_h = opts.localDebuggerFollowRedirects) != null ? _h : true;
|
|
3175
3324
|
if (this.debug && this.localDebuggerUrl) {
|
|
3176
3325
|
console.log(`${this.prefix} Local debugger mirroring: ${this.localDebuggerUrl}`);
|
|
3177
3326
|
}
|
|
@@ -3179,12 +3328,15 @@ var EventShipper = class {
|
|
|
3179
3328
|
debug: this.debug,
|
|
3180
3329
|
prefix: this.prefix
|
|
3181
3330
|
});
|
|
3182
|
-
this.redactPii = opts.redactPii ===
|
|
3331
|
+
this.redactPii = typeof opts.redactPii === "boolean" ? opts.redactPii : void 0;
|
|
3332
|
+
this.remotePiiConfig = opts.remotePiiConfig;
|
|
3183
3333
|
this.piiFields = new PiiFieldRedactor({
|
|
3184
3334
|
startupFieldMap: opts.redactPiiFields,
|
|
3185
3335
|
logPrefix: this.prefix
|
|
3186
3336
|
});
|
|
3187
|
-
|
|
3337
|
+
const fields = opts.redactPiiFields;
|
|
3338
|
+
const hasPayloadFields = Boolean(fields && (fields.event || fields.signal || fields.identify));
|
|
3339
|
+
if (hasPayloadFields && this.redactPii !== true && !this.remotePiiConfig) {
|
|
3188
3340
|
rateLimitedLog(
|
|
3189
3341
|
`${this.prefix}.pii_fields_without_redaction`,
|
|
3190
3342
|
() => console.warn(
|
|
@@ -3196,8 +3348,8 @@ var EventShipper = class {
|
|
|
3196
3348
|
const runtime = detectRuntime();
|
|
3197
3349
|
this.context = {
|
|
3198
3350
|
library: {
|
|
3199
|
-
name: (
|
|
3200
|
-
version: (
|
|
3351
|
+
name: (_i = opts.libraryName) != null ? _i : "@raindrop-ai/core",
|
|
3352
|
+
version: (_j = opts.libraryVersion) != null ? _j : "0.0.0"
|
|
3201
3353
|
},
|
|
3202
3354
|
metadata: {
|
|
3203
3355
|
jsRuntime: runtime,
|
|
@@ -3538,7 +3690,7 @@ var EventShipper = class {
|
|
|
3538
3690
|
if (!this.enabled) return;
|
|
3539
3691
|
const destination = currentReplayTraceDestination();
|
|
3540
3692
|
if (destination && destination.kind !== "workshop") return;
|
|
3541
|
-
const
|
|
3693
|
+
const items = [
|
|
3542
3694
|
{
|
|
3543
3695
|
event_id: signal.eventId,
|
|
3544
3696
|
signal_name: signal.name,
|
|
@@ -3552,16 +3704,28 @@ var EventShipper = class {
|
|
|
3552
3704
|
...signal.after ? { after: signal.after } : {}
|
|
3553
3705
|
}
|
|
3554
3706
|
}
|
|
3555
|
-
]
|
|
3556
|
-
|
|
3557
|
-
|
|
3707
|
+
];
|
|
3708
|
+
const known = piiRedactionNow(this.redactPii, this.remotePiiConfig, this.baseUrl, this.writeKey);
|
|
3709
|
+
if (known !== void 0) {
|
|
3710
|
+
const body = known ? items.map((item) => this.piiFields.redact("signal", item)) : items;
|
|
3711
|
+
if (!this.writeKey) return;
|
|
3712
|
+
await this.sendDirect("signal", `${this.baseUrl}signals/track`, body);
|
|
3713
|
+
return;
|
|
3714
|
+
}
|
|
3715
|
+
const snapshot = items.map(snapshotPayload);
|
|
3716
|
+
await this.tracked(async () => {
|
|
3717
|
+
const redact = await this.shouldRedactPii();
|
|
3718
|
+
const body = redact ? snapshot.map((item) => this.piiFields.redact("signal", item)) : snapshot;
|
|
3719
|
+
if (!this.writeKey) return;
|
|
3720
|
+
await this.sendDirect("signal", `${this.baseUrl}signals/track`, body, void 0, false);
|
|
3721
|
+
});
|
|
3558
3722
|
}
|
|
3559
3723
|
async identify(users) {
|
|
3560
3724
|
if (!this.enabled) return;
|
|
3561
3725
|
const destination = currentReplayTraceDestination();
|
|
3562
3726
|
if (destination && destination.kind !== "workshop") return;
|
|
3563
3727
|
const list = Array.isArray(users) ? users : [users];
|
|
3564
|
-
const
|
|
3728
|
+
const rows = list.filter((user) => {
|
|
3565
3729
|
if (!(user == null ? void 0 : user.userId) || !user.userId.trim()) {
|
|
3566
3730
|
if (this.debug) {
|
|
3567
3731
|
console.warn(`${this.prefix} skipping identify: missing userId`);
|
|
@@ -3569,24 +3733,34 @@ var EventShipper = class {
|
|
|
3569
3733
|
return false;
|
|
3570
3734
|
}
|
|
3571
3735
|
return true;
|
|
3572
|
-
}).map(
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
}
|
|
3580
|
-
);
|
|
3736
|
+
}).map((user) => {
|
|
3737
|
+
var _a;
|
|
3738
|
+
return {
|
|
3739
|
+
user_id: user.userId,
|
|
3740
|
+
traits: (_a = user.traits) != null ? _a : {}
|
|
3741
|
+
};
|
|
3742
|
+
});
|
|
3581
3743
|
if (!this.writeKey) return;
|
|
3582
|
-
if (
|
|
3583
|
-
|
|
3744
|
+
if (rows.length === 0) return;
|
|
3745
|
+
const known = piiRedactionNow(this.redactPii, this.remotePiiConfig, this.baseUrl, this.writeKey);
|
|
3746
|
+
if (known !== void 0) {
|
|
3747
|
+
const body = known ? rows.map((user) => this.piiFields.redact("identify", user)) : rows;
|
|
3748
|
+
await this.sendDirect("identify", `${this.baseUrl}users/identify`, body);
|
|
3749
|
+
return;
|
|
3750
|
+
}
|
|
3751
|
+
const snapshot = rows.map(snapshotPayload);
|
|
3752
|
+
await this.tracked(async () => {
|
|
3753
|
+
const redact = await this.shouldRedactPii();
|
|
3754
|
+
const body = redact ? snapshot.map((user) => this.piiFields.redact("identify", user)) : snapshot;
|
|
3755
|
+
await this.sendDirect("identify", `${this.baseUrl}users/identify`, body, void 0, false);
|
|
3756
|
+
});
|
|
3584
3757
|
}
|
|
3585
3758
|
/**
|
|
3586
|
-
* Send a signal or identify body. Tracked so `flush()` waits for it
|
|
3587
|
-
*
|
|
3759
|
+
* Send a signal or identify body. Tracked so `flush()` waits for it, unless
|
|
3760
|
+
* the caller already tracks it (`track: false`). A send a flush deadline
|
|
3761
|
+
* deferred is kept and retried later (outside shutdown).
|
|
3588
3762
|
*/
|
|
3589
|
-
async sendDirect(kind, url, body, deadlineAt) {
|
|
3763
|
+
async sendDirect(kind, url, body, deadlineAt, track = true) {
|
|
3590
3764
|
const opts = this.requestOpts(deadlineAt);
|
|
3591
3765
|
if (!opts) {
|
|
3592
3766
|
this.warnShutdownDrop(kind);
|
|
@@ -3594,7 +3768,7 @@ var EventShipper = class {
|
|
|
3594
3768
|
}
|
|
3595
3769
|
const sending = sendJson(url, body, this.requestHeaders(), opts);
|
|
3596
3770
|
const tracked = sending.then(() => void 0);
|
|
3597
|
-
this.inFlight.add(tracked);
|
|
3771
|
+
if (track) this.inFlight.add(tracked);
|
|
3598
3772
|
let outcome;
|
|
3599
3773
|
try {
|
|
3600
3774
|
outcome = await sending;
|
|
@@ -3640,9 +3814,36 @@ var EventShipper = class {
|
|
|
3640
3814
|
() => console.warn(`${this.prefix} failed to send ${what} (dropping): ${reason}`)
|
|
3641
3815
|
);
|
|
3642
3816
|
}
|
|
3643
|
-
/**
|
|
3644
|
-
|
|
3645
|
-
|
|
3817
|
+
/**
|
|
3818
|
+
* Whether to redact PII: `redactPii`, or when it is unset and
|
|
3819
|
+
* `remotePiiConfig` is on, the org's setting. Waits for the org's answer
|
|
3820
|
+
* before the first send, never past `deadlineAt`.
|
|
3821
|
+
*/
|
|
3822
|
+
async shouldRedactPii(deadlineAt) {
|
|
3823
|
+
return piiRedaction(
|
|
3824
|
+
this.redactPii,
|
|
3825
|
+
this.remotePiiConfig,
|
|
3826
|
+
this.baseUrl,
|
|
3827
|
+
this.writeKey,
|
|
3828
|
+
deadlineAt != null ? deadlineAt : this.shutdownDeadlineAt
|
|
3829
|
+
);
|
|
3830
|
+
}
|
|
3831
|
+
/**
|
|
3832
|
+
* Runs `work` (the org lookup, then one `sendDirect` with `track: false`)
|
|
3833
|
+
* as one in-flight send, so a `flush()` started meanwhile waits for both.
|
|
3834
|
+
*/
|
|
3835
|
+
async tracked(work) {
|
|
3836
|
+
const running = Promise.resolve().then(work);
|
|
3837
|
+
const done = running.then(
|
|
3838
|
+
() => void 0,
|
|
3839
|
+
() => void 0
|
|
3840
|
+
);
|
|
3841
|
+
this.inFlight.add(done);
|
|
3842
|
+
try {
|
|
3843
|
+
await running;
|
|
3844
|
+
} finally {
|
|
3845
|
+
this.inFlight.delete(done);
|
|
3846
|
+
}
|
|
3646
3847
|
}
|
|
3647
3848
|
warnShutdownDrop(what) {
|
|
3648
3849
|
rateLimitedLog(
|
|
@@ -3707,7 +3908,7 @@ var EventShipper = class {
|
|
|
3707
3908
|
return "queued";
|
|
3708
3909
|
}
|
|
3709
3910
|
async sendAccumulated(eventId, accumulated, deadlineAt) {
|
|
3710
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j
|
|
3911
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
3711
3912
|
const sticky = (_a = this.sticky.get(eventId)) != null ? _a : {};
|
|
3712
3913
|
const isPending = (_c = (_b = accumulated.isPending) != null ? _b : sticky.isPending) != null ? _c : true;
|
|
3713
3914
|
const knownEventName = (_d = accumulated.eventName) != null ? _d : sticky.eventName;
|
|
@@ -3763,7 +3964,37 @@ var EventShipper = class {
|
|
|
3763
3964
|
attachments: accumulated.attachments,
|
|
3764
3965
|
is_pending: isPending
|
|
3765
3966
|
};
|
|
3766
|
-
const
|
|
3967
|
+
const known = piiRedactionNow(this.redactPii, this.remotePiiConfig, this.baseUrl, this.writeKey);
|
|
3968
|
+
if (known !== void 0) {
|
|
3969
|
+
const payload = known ? this.piiFields.redact("event", unredacted) : unredacted;
|
|
3970
|
+
return this.shipPartial(eventId, accumulated, payload, { eventName, userId, convoId, isPending }, deadlineAt, true);
|
|
3971
|
+
}
|
|
3972
|
+
const snapshot = snapshotPayload(unredacted);
|
|
3973
|
+
const running = this.shouldRedactPii(deadlineAt).then(
|
|
3974
|
+
(redact) => this.shipPartial(
|
|
3975
|
+
eventId,
|
|
3976
|
+
accumulated,
|
|
3977
|
+
redact ? this.piiFields.redact("event", snapshot) : snapshot,
|
|
3978
|
+
{ eventName, userId, convoId, isPending },
|
|
3979
|
+
deadlineAt,
|
|
3980
|
+
false
|
|
3981
|
+
)
|
|
3982
|
+
);
|
|
3983
|
+
const done = running.then(
|
|
3984
|
+
() => void 0,
|
|
3985
|
+
() => void 0
|
|
3986
|
+
);
|
|
3987
|
+
this.inFlight.add(done);
|
|
3988
|
+
try {
|
|
3989
|
+
return await running;
|
|
3990
|
+
} finally {
|
|
3991
|
+
this.inFlight.delete(done);
|
|
3992
|
+
}
|
|
3993
|
+
}
|
|
3994
|
+
/** Sends one redacted partial payload; `track: false` when the caller already tracks it. */
|
|
3995
|
+
async shipPartial(eventId, accumulated, payload, meta, deadlineAt, track) {
|
|
3996
|
+
var _a, _b, _c, _d, _e, _f;
|
|
3997
|
+
const { eventName, userId, convoId, isPending } = meta;
|
|
3767
3998
|
const url = `${this.baseUrl}events/track_partial`;
|
|
3768
3999
|
if (this.debug) {
|
|
3769
4000
|
const sent = payload;
|
|
@@ -3774,20 +4005,21 @@ var EventShipper = class {
|
|
|
3774
4005
|
userId,
|
|
3775
4006
|
convoId,
|
|
3776
4007
|
isPending,
|
|
3777
|
-
inputPreview: preview((
|
|
3778
|
-
outputPreview: preview((
|
|
3779
|
-
attachments: (
|
|
3780
|
-
attachmentKinds: (
|
|
4008
|
+
inputPreview: preview((_a = sent.ai_data) == null ? void 0 : _a.input, 120),
|
|
4009
|
+
outputPreview: preview((_b = sent.ai_data) == null ? void 0 : _b.output, 120),
|
|
4010
|
+
attachments: (_d = (_c = sent.attachments) == null ? void 0 : _c.length) != null ? _d : 0,
|
|
4011
|
+
attachmentKinds: (_f = (_e = sent.attachments) == null ? void 0 : _e.map((a) => ({
|
|
3781
4012
|
type: a.type,
|
|
3782
4013
|
role: a.role,
|
|
3783
4014
|
name: a.name,
|
|
3784
4015
|
valuePreview: preview(a.value, 60)
|
|
3785
|
-
}))) != null ?
|
|
4016
|
+
}))) != null ? _f : [],
|
|
3786
4017
|
endpoint: url
|
|
3787
4018
|
});
|
|
3788
4019
|
}
|
|
3789
4020
|
const mirror = this.localDebuggerUrl ? mirrorPartialEventToLocalDebugger(payload, {
|
|
3790
4021
|
baseUrl: this.localDebuggerUrl,
|
|
4022
|
+
followRedirects: this.localDebuggerFollowRedirects,
|
|
3791
4023
|
writeKey: this.writeKey,
|
|
3792
4024
|
debug: this.debug,
|
|
3793
4025
|
sdkName: this.sdkName
|
|
@@ -3806,7 +4038,7 @@ var EventShipper = class {
|
|
|
3806
4038
|
}
|
|
3807
4039
|
const sending = sendJson(url, payload, this.requestHeaders(), opts);
|
|
3808
4040
|
const combined = Promise.all([mirror, sending.then(() => void 0)]).then(() => void 0);
|
|
3809
|
-
this.inFlight.add(combined);
|
|
4041
|
+
if (track) this.inFlight.add(combined);
|
|
3810
4042
|
let outcome;
|
|
3811
4043
|
try {
|
|
3812
4044
|
outcome = await sending;
|
|
@@ -4002,6 +4234,211 @@ var DEFAULT_REDACT_ATTRIBUTE_KEYS = [
|
|
|
4002
4234
|
"ai.response.providerMetadata"
|
|
4003
4235
|
];
|
|
4004
4236
|
var REDACT_JSON_ATTRIBUTE_KEYS = new Set(DEFAULT_REDACT_ATTRIBUTE_KEYS);
|
|
4237
|
+
var CONTENT_KEY_SUFFIX = /(^|\.)(input|output|inputs|outputs|args|arguments|result|results|content|text|messages|prompt|completion|instructions|system_instructions|reasoning|reasoningText|thinking|toolCalls|tool_calls|object|value|values|intent|query|tool_input)$/;
|
|
4238
|
+
var CONTENT_KEYS = /* @__PURE__ */ new Set([
|
|
4239
|
+
"ai.prompt.system",
|
|
4240
|
+
"ai.subagent.result",
|
|
4241
|
+
"agent.session.title",
|
|
4242
|
+
// Failed tool calls carry the tool's output in their error text.
|
|
4243
|
+
"error.message",
|
|
4244
|
+
"exception.message",
|
|
4245
|
+
"exception.stacktrace"
|
|
4246
|
+
]);
|
|
4247
|
+
var NON_CONTENT_PREFIXES = [
|
|
4248
|
+
"traceloop.association.properties.",
|
|
4249
|
+
"ai.telemetry.metadata.",
|
|
4250
|
+
"ai.settings.context.",
|
|
4251
|
+
"raindrop.app."
|
|
4252
|
+
];
|
|
4253
|
+
var JSON_SIMPLE_ESCAPES = {
|
|
4254
|
+
'"': '"',
|
|
4255
|
+
"\\": "\\",
|
|
4256
|
+
"/": "/",
|
|
4257
|
+
b: "\b",
|
|
4258
|
+
f: "\f",
|
|
4259
|
+
n: "\n",
|
|
4260
|
+
r: "\r",
|
|
4261
|
+
t: " "
|
|
4262
|
+
};
|
|
4263
|
+
function decodeJsonEscapes(text) {
|
|
4264
|
+
if (!text.includes("\\")) return text;
|
|
4265
|
+
let out = "";
|
|
4266
|
+
for (let i = 0; i < text.length; i++) {
|
|
4267
|
+
const ch = text[i];
|
|
4268
|
+
if (ch !== "\\" || i + 1 >= text.length) {
|
|
4269
|
+
out += ch;
|
|
4270
|
+
continue;
|
|
4271
|
+
}
|
|
4272
|
+
const next = text[i + 1];
|
|
4273
|
+
const simple = JSON_SIMPLE_ESCAPES[next];
|
|
4274
|
+
if (simple !== void 0) {
|
|
4275
|
+
out += simple;
|
|
4276
|
+
i += 1;
|
|
4277
|
+
} else if (next === "u" && /^[0-9a-fA-F]{4}$/.test(text.slice(i + 2, i + 6))) {
|
|
4278
|
+
out += String.fromCharCode(Number.parseInt(text.slice(i + 2, i + 6), 16));
|
|
4279
|
+
i += 5;
|
|
4280
|
+
} else {
|
|
4281
|
+
out += ch;
|
|
4282
|
+
}
|
|
4283
|
+
}
|
|
4284
|
+
return out;
|
|
4285
|
+
}
|
|
4286
|
+
function jsonStringBody(value) {
|
|
4287
|
+
return JSON.stringify(value).slice(1, -1);
|
|
4288
|
+
}
|
|
4289
|
+
function redactStringToken(token) {
|
|
4290
|
+
const decoded = decodeJsonEscapes(token.slice(1, -1));
|
|
4291
|
+
const redacted = redactPiiText(decoded);
|
|
4292
|
+
return redacted === decoded ? token : `"${jsonStringBody(redacted)}"`;
|
|
4293
|
+
}
|
|
4294
|
+
function redactLooseJsonText(text) {
|
|
4295
|
+
if (text.startsWith('"')) {
|
|
4296
|
+
const decoded2 = decodeJsonEscapes(text.slice(1));
|
|
4297
|
+
const redacted2 = redactPiiText(decoded2);
|
|
4298
|
+
return redacted2 === decoded2 ? text : `"${jsonStringBody(redacted2)}`;
|
|
4299
|
+
}
|
|
4300
|
+
const decoded = decodeJsonEscapes(text);
|
|
4301
|
+
const redacted = redactPiiText(decoded);
|
|
4302
|
+
return redacted === decoded ? text : redacted;
|
|
4303
|
+
}
|
|
4304
|
+
function stringTokenEnd(text, start) {
|
|
4305
|
+
for (let i = start + 1; i < text.length; i++) {
|
|
4306
|
+
const ch = text[i];
|
|
4307
|
+
if (ch === "\\") i += 1;
|
|
4308
|
+
else if (ch === '"') return i + 1;
|
|
4309
|
+
}
|
|
4310
|
+
return -1;
|
|
4311
|
+
}
|
|
4312
|
+
function redactJsonLike(text, complete) {
|
|
4313
|
+
let out = "";
|
|
4314
|
+
let looseStart = 0;
|
|
4315
|
+
const flushLoose = (end) => {
|
|
4316
|
+
if (end > looseStart) {
|
|
4317
|
+
const loose = text.slice(looseStart, end);
|
|
4318
|
+
out += complete ? loose : redactLooseJsonText(loose);
|
|
4319
|
+
}
|
|
4320
|
+
};
|
|
4321
|
+
let i = text.indexOf('"');
|
|
4322
|
+
while (i !== -1) {
|
|
4323
|
+
const end = stringTokenEnd(text, i);
|
|
4324
|
+
if (end === -1) break;
|
|
4325
|
+
flushLoose(i);
|
|
4326
|
+
let after = end;
|
|
4327
|
+
while (after < text.length && /\s/.test(text[after])) after += 1;
|
|
4328
|
+
const token = text.slice(i, end);
|
|
4329
|
+
out += complete && text[after] === ":" ? token : redactStringToken(token);
|
|
4330
|
+
looseStart = end;
|
|
4331
|
+
i = text.indexOf('"', end);
|
|
4332
|
+
}
|
|
4333
|
+
if (i === -1) {
|
|
4334
|
+
flushLoose(text.length);
|
|
4335
|
+
} else {
|
|
4336
|
+
flushLoose(i);
|
|
4337
|
+
looseStart = i;
|
|
4338
|
+
flushLoose(text.length);
|
|
4339
|
+
}
|
|
4340
|
+
return out;
|
|
4341
|
+
}
|
|
4342
|
+
function redactSpanContent(text) {
|
|
4343
|
+
const head = text.trimStart()[0];
|
|
4344
|
+
if (head !== "{" && head !== "[" && head !== '"') return redactPiiText(text);
|
|
4345
|
+
let complete = true;
|
|
4346
|
+
try {
|
|
4347
|
+
JSON.parse(text);
|
|
4348
|
+
} catch (e) {
|
|
4349
|
+
complete = false;
|
|
4350
|
+
}
|
|
4351
|
+
return redactJsonLike(text, complete);
|
|
4352
|
+
}
|
|
4353
|
+
var NO_SPAN_PII_FIELDS = { exact: /* @__PURE__ */ new Set(), prefixes: [] };
|
|
4354
|
+
function compileSpanPiiFields(names, logPrefix = "[raindrop-ai/core]") {
|
|
4355
|
+
if (!Array.isArray(names) || names.length === 0) return NO_SPAN_PII_FIELDS;
|
|
4356
|
+
const exact = /* @__PURE__ */ new Set();
|
|
4357
|
+
const prefixes = [];
|
|
4358
|
+
for (const name of names) {
|
|
4359
|
+
const valid = typeof name === "string" && !/\s/.test(name) && /^[^*]+\*?$/.test(name);
|
|
4360
|
+
if (!valid) {
|
|
4361
|
+
rateLimitedLog(
|
|
4362
|
+
`${logPrefix}.pii_span_field_invalid`,
|
|
4363
|
+
() => console.warn(
|
|
4364
|
+
`${logPrefix} redactPiiFields: ignoring invalid span attribute ${JSON.stringify(name)}`
|
|
4365
|
+
)
|
|
4366
|
+
);
|
|
4367
|
+
continue;
|
|
4368
|
+
}
|
|
4369
|
+
if (name.endsWith("*")) prefixes.push(name.slice(0, -1));
|
|
4370
|
+
else exact.add(name);
|
|
4371
|
+
}
|
|
4372
|
+
return { exact, prefixes };
|
|
4373
|
+
}
|
|
4374
|
+
function isCallerSelected(key, fields) {
|
|
4375
|
+
return fields.exact.has(key) || fields.prefixes.some((prefix) => key.startsWith(prefix));
|
|
4376
|
+
}
|
|
4377
|
+
function isSpanContentAttributeKey(key, fields = NO_SPAN_PII_FIELDS) {
|
|
4378
|
+
if (isCallerSelected(key, fields)) return true;
|
|
4379
|
+
if (NON_CONTENT_PREFIXES.some((prefix) => key.startsWith(prefix))) return false;
|
|
4380
|
+
return CONTENT_KEYS.has(key) || CONTENT_KEY_SUFFIX.test(key);
|
|
4381
|
+
}
|
|
4382
|
+
function redactOtlpValue(value) {
|
|
4383
|
+
var _a;
|
|
4384
|
+
if (typeof value.stringValue === "string") {
|
|
4385
|
+
const redacted = redactSpanContent(value.stringValue);
|
|
4386
|
+
return redacted === value.stringValue ? value : { ...value, stringValue: redacted };
|
|
4387
|
+
}
|
|
4388
|
+
const values = (_a = value.arrayValue) == null ? void 0 : _a.values;
|
|
4389
|
+
if (!values) return value;
|
|
4390
|
+
let changed = false;
|
|
4391
|
+
const next = values.map((item) => {
|
|
4392
|
+
const redacted = redactOtlpValue(item);
|
|
4393
|
+
if (redacted !== item) changed = true;
|
|
4394
|
+
return redacted;
|
|
4395
|
+
});
|
|
4396
|
+
return changed ? { ...value, arrayValue: { values: next } } : value;
|
|
4397
|
+
}
|
|
4398
|
+
function redactPiiInOtlpAttributes(attributes, fields = NO_SPAN_PII_FIELDS) {
|
|
4399
|
+
let next;
|
|
4400
|
+
for (let i = 0; i < attributes.length; i++) {
|
|
4401
|
+
const attr = attributes[i];
|
|
4402
|
+
if (!attr.value || !isSpanContentAttributeKey(attr.key, fields)) continue;
|
|
4403
|
+
const value = redactOtlpValue(attr.value);
|
|
4404
|
+
if (value === attr.value) continue;
|
|
4405
|
+
next != null ? next : next = attributes.slice();
|
|
4406
|
+
next[i] = { ...attr, value };
|
|
4407
|
+
}
|
|
4408
|
+
return next != null ? next : attributes;
|
|
4409
|
+
}
|
|
4410
|
+
function redactPiiInOtlpSpan(span, fields = NO_SPAN_PII_FIELDS) {
|
|
4411
|
+
var _a;
|
|
4412
|
+
const attributes = span.attributes && redactPiiInOtlpAttributes(span.attributes, fields);
|
|
4413
|
+
const message = (_a = span.status) == null ? void 0 : _a.message;
|
|
4414
|
+
const redactedMessage = message === void 0 ? void 0 : redactSpanContent(message);
|
|
4415
|
+
if (attributes === span.attributes && redactedMessage === message) return span;
|
|
4416
|
+
const status = span.status && redactedMessage !== message ? { ...span.status, message: redactedMessage } : span.status;
|
|
4417
|
+
return { ...span, attributes, status };
|
|
4418
|
+
}
|
|
4419
|
+
function redactPiiInAttributeMap(attributes, fields = NO_SPAN_PII_FIELDS) {
|
|
4420
|
+
let next;
|
|
4421
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
4422
|
+
if (!isSpanContentAttributeKey(key, fields)) continue;
|
|
4423
|
+
let redacted = value;
|
|
4424
|
+
if (typeof value === "string") {
|
|
4425
|
+
redacted = redactSpanContent(value);
|
|
4426
|
+
} else if (Array.isArray(value)) {
|
|
4427
|
+
let changed = false;
|
|
4428
|
+
const items = value.map((item) => {
|
|
4429
|
+
if (typeof item !== "string") return item;
|
|
4430
|
+
const out = redactSpanContent(item);
|
|
4431
|
+
if (out !== item) changed = true;
|
|
4432
|
+
return out;
|
|
4433
|
+
});
|
|
4434
|
+
if (changed) redacted = items;
|
|
4435
|
+
}
|
|
4436
|
+
if (redacted === value) continue;
|
|
4437
|
+
next != null ? next : next = { ...attributes };
|
|
4438
|
+
next[key] = redacted;
|
|
4439
|
+
}
|
|
4440
|
+
return next;
|
|
4441
|
+
}
|
|
4005
4442
|
var UNDELIVERED = Object.freeze({
|
|
4006
4443
|
delivered: false,
|
|
4007
4444
|
timedOut: false,
|
|
@@ -4010,7 +4447,7 @@ var UNDELIVERED = Object.freeze({
|
|
|
4010
4447
|
inFlight: 0
|
|
4011
4448
|
});
|
|
4012
4449
|
var PROMPT_TOOLS_ATTRIBUTE = "ai.prompt.tools";
|
|
4013
|
-
function
|
|
4450
|
+
function isRecord4(value) {
|
|
4014
4451
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4015
4452
|
}
|
|
4016
4453
|
var JSON_SCHEMA_KEYS = [
|
|
@@ -4028,17 +4465,17 @@ var JSON_SCHEMA_KEYS = [
|
|
|
4028
4465
|
"required"
|
|
4029
4466
|
];
|
|
4030
4467
|
function isJsonSchema(value) {
|
|
4031
|
-
if (!
|
|
4468
|
+
if (!isRecord4(value)) return false;
|
|
4032
4469
|
if (typeof value["~standard"] === "object") return false;
|
|
4033
|
-
if (
|
|
4470
|
+
if (isRecord4(value._def) || isRecord4(value._zod)) return false;
|
|
4034
4471
|
if (Object.keys(value).length === 0) return true;
|
|
4035
4472
|
return JSON_SCHEMA_KEYS.some((key) => key in value);
|
|
4036
4473
|
}
|
|
4037
4474
|
function toJsonSchema(value, options) {
|
|
4038
4475
|
if (value === void 0 || value === null) return void 0;
|
|
4039
4476
|
if (isJsonSchema(value)) return value;
|
|
4040
|
-
if (
|
|
4041
|
-
if (
|
|
4477
|
+
if (isRecord4(value) && isJsonSchema(value.jsonSchema)) return value.jsonSchema;
|
|
4478
|
+
if (isRecord4(value) && isJsonSchema(value.json)) return value.json;
|
|
4042
4479
|
if (options == null ? void 0 : options.schema) {
|
|
4043
4480
|
try {
|
|
4044
4481
|
return options.schema(value);
|
|
@@ -4061,23 +4498,23 @@ function functionTool(name, description, schema, options) {
|
|
|
4061
4498
|
}
|
|
4062
4499
|
function normalizeToolDeclaration(tool, options, fallbackName) {
|
|
4063
4500
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
4064
|
-
if (!
|
|
4501
|
+
if (!isRecord4(tool)) return void 0;
|
|
4065
4502
|
if (tool.type === "provider-defined" || tool.type === "provider") {
|
|
4066
4503
|
const name2 = (_b = (_a = pickString(tool.name)) != null ? _a : pickString(tool.id)) != null ? _b : fallbackName;
|
|
4067
4504
|
if (name2 === void 0) return void 0;
|
|
4068
4505
|
const declaration = { type: "provider-defined", name: name2 };
|
|
4069
4506
|
const id = pickString(tool.id);
|
|
4070
4507
|
if (id !== void 0) declaration.id = id;
|
|
4071
|
-
if (
|
|
4508
|
+
if (isRecord4(tool.args)) declaration.args = tool.args;
|
|
4072
4509
|
return declaration;
|
|
4073
4510
|
}
|
|
4074
|
-
if (
|
|
4511
|
+
if (isRecord4(tool.toolSpec)) {
|
|
4075
4512
|
const spec = tool.toolSpec;
|
|
4076
4513
|
const name2 = (_c = pickString(spec.name)) != null ? _c : fallbackName;
|
|
4077
4514
|
if (name2 === void 0) return void 0;
|
|
4078
4515
|
return functionTool(name2, spec.description, spec.inputSchema, options);
|
|
4079
4516
|
}
|
|
4080
|
-
if (
|
|
4517
|
+
if (isRecord4(tool.function)) {
|
|
4081
4518
|
const fn = tool.function;
|
|
4082
4519
|
const name2 = (_d = pickString(fn.name)) != null ? _d : fallbackName;
|
|
4083
4520
|
if (name2 === void 0) return void 0;
|
|
@@ -4103,7 +4540,7 @@ function isGeminiToolGroup(tool) {
|
|
|
4103
4540
|
if (Array.isArray(tool.functionDeclarations)) return true;
|
|
4104
4541
|
const keys = Object.keys(tool);
|
|
4105
4542
|
if (keys.length === 0 || NOT_A_GEMINI_GROUP_KEYS.some((key) => key in tool)) return false;
|
|
4106
|
-
return keys.every((key) =>
|
|
4543
|
+
return keys.every((key) => isRecord4(tool[key]));
|
|
4107
4544
|
}
|
|
4108
4545
|
function expandGeminiTool(tool, options) {
|
|
4109
4546
|
const declarations = [];
|
|
@@ -4113,7 +4550,7 @@ function expandGeminiTool(tool, options) {
|
|
|
4113
4550
|
const normalized = normalizeToolDeclaration(declaration, options);
|
|
4114
4551
|
if (normalized) declarations.push(normalized);
|
|
4115
4552
|
}
|
|
4116
|
-
} else if (
|
|
4553
|
+
} else if (isRecord4(value)) {
|
|
4117
4554
|
declarations.push({ type: "provider-defined", id: key, name: key, args: value });
|
|
4118
4555
|
}
|
|
4119
4556
|
}
|
|
@@ -4123,14 +4560,14 @@ function normalizeToolDeclarations(tools, options) {
|
|
|
4123
4560
|
if (tools === void 0 || tools === null) return void 0;
|
|
4124
4561
|
if (Array.isArray(tools)) {
|
|
4125
4562
|
return tools.flatMap((tool) => {
|
|
4126
|
-
if (
|
|
4563
|
+
if (isRecord4(tool) && isGeminiToolGroup(tool)) {
|
|
4127
4564
|
return expandGeminiTool(tool, options);
|
|
4128
4565
|
}
|
|
4129
4566
|
const declaration = normalizeToolDeclaration(tool, options);
|
|
4130
4567
|
return declaration ? [declaration] : [];
|
|
4131
4568
|
});
|
|
4132
4569
|
}
|
|
4133
|
-
if (!
|
|
4570
|
+
if (!isRecord4(tools)) return void 0;
|
|
4134
4571
|
return Object.entries(tools).flatMap(([key, tool]) => {
|
|
4135
4572
|
const declaration = normalizeToolDeclaration(tool, options, key);
|
|
4136
4573
|
return declaration ? [declaration] : [];
|
|
@@ -8459,7 +8896,7 @@ var SignalEventSchema = external_exports.object({
|
|
|
8459
8896
|
// package.json
|
|
8460
8897
|
var package_default = {
|
|
8461
8898
|
name: "raindrop-ai",
|
|
8462
|
-
version: "1.0.
|
|
8899
|
+
version: "1.0.8",
|
|
8463
8900
|
main: "dist/index.js",
|
|
8464
8901
|
module: "dist/index.mjs",
|
|
8465
8902
|
types: "dist/index.d.ts",
|
|
@@ -8754,10 +9191,10 @@ function authHintForKey(writeKey) {
|
|
|
8754
9191
|
if (!writeKey) return void 0;
|
|
8755
9192
|
return (0, import_node_crypto.createHash)("sha256").update(writeKey, "utf8").digest("hex").slice(0, 8);
|
|
8756
9193
|
}
|
|
8757
|
-
var
|
|
9194
|
+
var STATE_KEY3 = /* @__PURE__ */ Symbol.for("raindrop.tracing.multiProjectState");
|
|
8758
9195
|
function getState() {
|
|
8759
9196
|
const holder = globalThis;
|
|
8760
|
-
let state2 = holder[
|
|
9197
|
+
let state2 = holder[STATE_KEY3];
|
|
8761
9198
|
if (!state2) {
|
|
8762
9199
|
state2 = {
|
|
8763
9200
|
foreignClientSeen: false,
|
|
@@ -8769,7 +9206,7 @@ function getState() {
|
|
|
8769
9206
|
multiKeyWarned: false,
|
|
8770
9207
|
pendingMultiKeyWarning: false
|
|
8771
9208
|
};
|
|
8772
|
-
holder[
|
|
9209
|
+
holder[STATE_KEY3] = state2;
|
|
8773
9210
|
}
|
|
8774
9211
|
return state2;
|
|
8775
9212
|
}
|
|
@@ -8997,11 +9434,8 @@ var import_instrumentation_together = require("@traceloop/instrumentation-togeth
|
|
|
8997
9434
|
var import_instrumentation_vertexai = require("@traceloop/instrumentation-vertexai");
|
|
8998
9435
|
var import_weakref = require("weakref");
|
|
8999
9436
|
|
|
9000
|
-
// src/tracing/direct/
|
|
9001
|
-
|
|
9002
|
-
if (!endpoint) return void 0;
|
|
9003
|
-
return endpoint.endsWith("/") ? endpoint : `${endpoint}/`;
|
|
9004
|
-
}
|
|
9437
|
+
// src/tracing/direct/context.ts
|
|
9438
|
+
var import_api = require("@opentelemetry/api");
|
|
9005
9439
|
|
|
9006
9440
|
// src/tracing/direct/ids.ts
|
|
9007
9441
|
function getCrypto2() {
|
|
@@ -9064,6 +9498,55 @@ function base64ToHex2(base64) {
|
|
|
9064
9498
|
throw new Error("No base64 decoder available in this runtime");
|
|
9065
9499
|
}
|
|
9066
9500
|
|
|
9501
|
+
// src/tracing/direct/context.ts
|
|
9502
|
+
var INVALID_TRACE_ID = "00000000000000000000000000000000";
|
|
9503
|
+
var INVALID_SPAN_ID = "0000000000000000";
|
|
9504
|
+
function hexToBase64(hex) {
|
|
9505
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
9506
|
+
for (let i = 0; i < hex.length; i += 2) {
|
|
9507
|
+
bytes[i / 2] = parseInt(hex.substring(i, i + 2), 16);
|
|
9508
|
+
}
|
|
9509
|
+
return base64Encode2(bytes);
|
|
9510
|
+
}
|
|
9511
|
+
function getExplicitTraceContext(traceId, parentSpanId) {
|
|
9512
|
+
if (!traceId || !parentSpanId || !(0, import_api.isValidTraceId)(traceId) || !(0, import_api.isValidSpanId)(parentSpanId)) {
|
|
9513
|
+
return void 0;
|
|
9514
|
+
}
|
|
9515
|
+
return {
|
|
9516
|
+
traceIdB64: hexToBase64(traceId),
|
|
9517
|
+
parentSpanIdB64: hexToBase64(parentSpanId)
|
|
9518
|
+
};
|
|
9519
|
+
}
|
|
9520
|
+
function getActiveTraceContext() {
|
|
9521
|
+
const activeSpan = import_api.trace.getSpan(import_api.context.active());
|
|
9522
|
+
if (!activeSpan) return {};
|
|
9523
|
+
const spanContext = activeSpan.spanContext();
|
|
9524
|
+
const traceIdHex = spanContext.traceId;
|
|
9525
|
+
const spanIdHex = spanContext.spanId;
|
|
9526
|
+
if (traceIdHex === INVALID_TRACE_ID) return {};
|
|
9527
|
+
return {
|
|
9528
|
+
traceIdB64: hexToBase64(traceIdHex),
|
|
9529
|
+
parentSpanIdB64: spanIdHex !== INVALID_SPAN_ID ? hexToBase64(spanIdHex) : void 0
|
|
9530
|
+
};
|
|
9531
|
+
}
|
|
9532
|
+
function savedParentContext(traceId, parentSpanId) {
|
|
9533
|
+
if (!traceId || !parentSpanId || !(0, import_api.isValidTraceId)(traceId) || !(0, import_api.isValidSpanId)(parentSpanId)) {
|
|
9534
|
+
return void 0;
|
|
9535
|
+
}
|
|
9536
|
+
return import_api.trace.setSpanContext(import_api.context.active(), {
|
|
9537
|
+
traceId,
|
|
9538
|
+
spanId: parentSpanId,
|
|
9539
|
+
traceFlags: import_api.TraceFlags.SAMPLED,
|
|
9540
|
+
isRemote: true
|
|
9541
|
+
});
|
|
9542
|
+
}
|
|
9543
|
+
|
|
9544
|
+
// src/tracing/direct/http.ts
|
|
9545
|
+
function formatEndpoint2(endpoint) {
|
|
9546
|
+
if (!endpoint) return void 0;
|
|
9547
|
+
return endpoint.endsWith("/") ? endpoint : `${endpoint}/`;
|
|
9548
|
+
}
|
|
9549
|
+
|
|
9067
9550
|
// src/tracing/direct/otlp.ts
|
|
9068
9551
|
var libraryVersion = package_default.version;
|
|
9069
9552
|
var SERVICE_NAME = "raindrop-ai";
|
|
@@ -9108,50 +9591,6 @@ function buildExportTraceServiceRequest2(spans) {
|
|
|
9108
9591
|
};
|
|
9109
9592
|
}
|
|
9110
9593
|
|
|
9111
|
-
// src/tracing/direct/context.ts
|
|
9112
|
-
var import_api = require("@opentelemetry/api");
|
|
9113
|
-
var INVALID_TRACE_ID = "00000000000000000000000000000000";
|
|
9114
|
-
var INVALID_SPAN_ID = "0000000000000000";
|
|
9115
|
-
function hexToBase64(hex) {
|
|
9116
|
-
const bytes = new Uint8Array(hex.length / 2);
|
|
9117
|
-
for (let i = 0; i < hex.length; i += 2) {
|
|
9118
|
-
bytes[i / 2] = parseInt(hex.substring(i, i + 2), 16);
|
|
9119
|
-
}
|
|
9120
|
-
return base64Encode2(bytes);
|
|
9121
|
-
}
|
|
9122
|
-
function getExplicitTraceContext(traceId, parentSpanId) {
|
|
9123
|
-
if (!traceId || !parentSpanId || !(0, import_api.isValidTraceId)(traceId) || !(0, import_api.isValidSpanId)(parentSpanId)) {
|
|
9124
|
-
return void 0;
|
|
9125
|
-
}
|
|
9126
|
-
return {
|
|
9127
|
-
traceIdB64: hexToBase64(traceId),
|
|
9128
|
-
parentSpanIdB64: hexToBase64(parentSpanId)
|
|
9129
|
-
};
|
|
9130
|
-
}
|
|
9131
|
-
function getActiveTraceContext() {
|
|
9132
|
-
const activeSpan = import_api.trace.getSpan(import_api.context.active());
|
|
9133
|
-
if (!activeSpan) return {};
|
|
9134
|
-
const spanContext = activeSpan.spanContext();
|
|
9135
|
-
const traceIdHex = spanContext.traceId;
|
|
9136
|
-
const spanIdHex = spanContext.spanId;
|
|
9137
|
-
if (traceIdHex === INVALID_TRACE_ID) return {};
|
|
9138
|
-
return {
|
|
9139
|
-
traceIdB64: hexToBase64(traceIdHex),
|
|
9140
|
-
parentSpanIdB64: spanIdHex !== INVALID_SPAN_ID ? hexToBase64(spanIdHex) : void 0
|
|
9141
|
-
};
|
|
9142
|
-
}
|
|
9143
|
-
function savedParentContext(traceId, parentSpanId) {
|
|
9144
|
-
if (!traceId || !parentSpanId || !(0, import_api.isValidTraceId)(traceId) || !(0, import_api.isValidSpanId)(parentSpanId)) {
|
|
9145
|
-
return void 0;
|
|
9146
|
-
}
|
|
9147
|
-
return import_api.trace.setSpanContext(import_api.context.active(), {
|
|
9148
|
-
traceId,
|
|
9149
|
-
spanId: parentSpanId,
|
|
9150
|
-
traceFlags: import_api.TraceFlags.SAMPLED,
|
|
9151
|
-
isRemote: true
|
|
9152
|
-
});
|
|
9153
|
-
}
|
|
9154
|
-
|
|
9155
9594
|
// src/tracing/direct/shipper.ts
|
|
9156
9595
|
function serializeAssociationValue(value) {
|
|
9157
9596
|
return stringifyBounded(value);
|
|
@@ -9177,6 +9616,9 @@ var DirectTraceShipper = class {
|
|
|
9177
9616
|
this.cloudEnabled = (_c = opts.cloudEnabled) != null ? _c : true;
|
|
9178
9617
|
this.debug = opts.debug;
|
|
9179
9618
|
this.projectId = opts.projectId;
|
|
9619
|
+
this.redactTracePii = opts.redactTracePii;
|
|
9620
|
+
this.remotePiiConfig = opts.remotePiiConfig;
|
|
9621
|
+
this.spanPiiFields = opts.spanPiiFields;
|
|
9180
9622
|
this.flushIntervalMs = (_d = opts.flushIntervalMs) != null ? _d : 1e3;
|
|
9181
9623
|
this.maxBatchSize = (_e = opts.maxBatchSize) != null ? _e : 50;
|
|
9182
9624
|
this.maxQueueSize = (_f = opts.maxQueueSize) != null ? _f : 5e3;
|
|
@@ -9281,8 +9723,9 @@ var DirectTraceShipper = class {
|
|
|
9281
9723
|
base64ToHex2(span.traceId)
|
|
9282
9724
|
);
|
|
9283
9725
|
const mirrorUrl = (replayDestination == null ? void 0 : replayDestination.kind) === "workshop" ? replayDestination.url : replayDestination ? void 0 : this.localDebuggerUrl;
|
|
9284
|
-
|
|
9285
|
-
|
|
9726
|
+
const mirrored = mirrorUrl && this.redactsNow() ? this.redactSpanPii(span) : span;
|
|
9727
|
+
if (mirrorUrl && mirrored) {
|
|
9728
|
+
const body = buildExportTraceServiceRequest2([mirrored]);
|
|
9286
9729
|
const mirror = mirrorTraceExportToLocalDebugger(body, {
|
|
9287
9730
|
baseUrl: mirrorUrl,
|
|
9288
9731
|
debug: false,
|
|
@@ -9296,6 +9739,23 @@ var DirectTraceShipper = class {
|
|
|
9296
9739
|
console.log(`[raindrop] direct shipper: enqueued span "${params.name}"`);
|
|
9297
9740
|
}
|
|
9298
9741
|
}
|
|
9742
|
+
/**
|
|
9743
|
+
* Whether to redact, never waiting: a local mirror uses what is known now,
|
|
9744
|
+
* and a remote setting still being looked up counts as unknown.
|
|
9745
|
+
*/
|
|
9746
|
+
redactsNow() {
|
|
9747
|
+
var _a;
|
|
9748
|
+
const writeKey = this.cloudEnabled ? this.writeKey : void 0;
|
|
9749
|
+
return (_a = piiRedactionNow(this.redactTracePii, this.remotePiiConfig, this.baseUrl, writeKey)) != null ? _a : resolvePiiRedaction(this.redactTracePii, this.remotePiiConfig, "unknown");
|
|
9750
|
+
}
|
|
9751
|
+
/** The span with PII redacted from its input and output; undefined if redaction failed. */
|
|
9752
|
+
redactSpanPii(span) {
|
|
9753
|
+
try {
|
|
9754
|
+
return redactPiiInOtlpSpan(span, this.spanPiiFields);
|
|
9755
|
+
} catch (e) {
|
|
9756
|
+
return void 0;
|
|
9757
|
+
}
|
|
9758
|
+
}
|
|
9299
9759
|
sendToolSpan(params) {
|
|
9300
9760
|
this.sendSpan({
|
|
9301
9761
|
...params,
|
|
@@ -9349,13 +9809,22 @@ var DirectTraceShipper = class {
|
|
|
9349
9809
|
return summarize2(fates, stillRunning, !settled);
|
|
9350
9810
|
}
|
|
9351
9811
|
async drain(deadlineAt) {
|
|
9352
|
-
var _a;
|
|
9812
|
+
var _a, _b;
|
|
9353
9813
|
const fates = [];
|
|
9354
9814
|
if (!this.enabled) return fates;
|
|
9355
9815
|
if (this.timer) {
|
|
9356
9816
|
clearTimeout(this.timer);
|
|
9357
9817
|
this.timer = void 0;
|
|
9358
9818
|
}
|
|
9819
|
+
if (this.queue.length === 0) return fates;
|
|
9820
|
+
const writeKey = this.cloudEnabled ? this.writeKey : void 0;
|
|
9821
|
+
const redactPii = (_a = piiRedactionNow(this.redactTracePii, this.remotePiiConfig, this.baseUrl, writeKey)) != null ? _a : await piiRedaction(
|
|
9822
|
+
this.redactTracePii,
|
|
9823
|
+
this.remotePiiConfig,
|
|
9824
|
+
this.baseUrl,
|
|
9825
|
+
writeKey,
|
|
9826
|
+
deadlineAt
|
|
9827
|
+
);
|
|
9359
9828
|
while (this.queue.length > 0) {
|
|
9360
9829
|
const batch = this.queue.splice(0, this.maxBatchSize);
|
|
9361
9830
|
const opts = this.requestOpts(deadlineAt);
|
|
@@ -9380,12 +9849,18 @@ var DirectTraceShipper = class {
|
|
|
9380
9849
|
for (const [replayDestination, queuedSpans] of groups) {
|
|
9381
9850
|
if (!replayDestination && !this.cloudEnabled) continue;
|
|
9382
9851
|
if ((replayDestination == null ? void 0 : replayDestination.kind) === "workshop") continue;
|
|
9383
|
-
const
|
|
9852
|
+
const spans = queuedSpans.map((q) => q.span);
|
|
9853
|
+
const outgoing = redactPii ? spans.flatMap((span) => {
|
|
9854
|
+
var _a2;
|
|
9855
|
+
return (_a2 = this.redactSpanPii(span)) != null ? _a2 : [];
|
|
9856
|
+
}) : spans;
|
|
9857
|
+
if (outgoing.length === 0) continue;
|
|
9858
|
+
const body = buildExportTraceServiceRequest2(outgoing);
|
|
9384
9859
|
const url = replayDestination ? replayTraceUrl(replayDestination.url) : `${this.baseUrl}traces`;
|
|
9385
9860
|
const headers = replayDestination ? {
|
|
9386
9861
|
Authorization: `Bearer ${replayDestination.apiKey}`,
|
|
9387
9862
|
"X-Raindrop-Replay-Id": replayDestination.replayId,
|
|
9388
|
-
"X-Raindrop-Project-Id": (
|
|
9863
|
+
"X-Raindrop-Project-Id": (_b = replayDestination.projectId) != null ? _b : "default"
|
|
9389
9864
|
} : { Authorization: `Bearer ${this.writeKey}`, ...projectIdHeaders(this.projectId) };
|
|
9390
9865
|
const sending = sendJson(url, body, headers, opts);
|
|
9391
9866
|
const tracked = sending.then(() => void 0);
|
|
@@ -9407,7 +9882,9 @@ var DirectTraceShipper = class {
|
|
|
9407
9882
|
const reason = outcome.status === "cut_off" ? "cut off at the flush deadline (not resent: it may have reached ingest)" : outcome.status === "deferred" ? "not sent before the shutdown deadline" : "error" in outcome && outcome.error ? outcome.error.message : outcome.status;
|
|
9408
9883
|
rateLimitedLog(
|
|
9409
9884
|
"js-sdk.direct.send_failed",
|
|
9410
|
-
() => console.warn(
|
|
9885
|
+
() => console.warn(
|
|
9886
|
+
`[raindrop] direct: failed to send ${queuedSpans.length} spans (dropping): ${reason}`
|
|
9887
|
+
)
|
|
9411
9888
|
);
|
|
9412
9889
|
} else if (this.debug) {
|
|
9413
9890
|
console.log(`[raindrop] direct: sent ${queuedSpans.length} spans`);
|
|
@@ -9481,6 +9958,93 @@ var import_sdk_trace_base = require("@opentelemetry/sdk-trace-base");
|
|
|
9481
9958
|
var import_sdk_trace_node = require("@opentelemetry/sdk-trace-node");
|
|
9482
9959
|
var import_ai_semantic_conventions = require("@traceloop/ai-semantic-conventions");
|
|
9483
9960
|
var ALL_INSTRUMENTATION_LIBRARIES = "all";
|
|
9961
|
+
function redactSpanPii(span, fields) {
|
|
9962
|
+
const attributes = redactPiiInAttributeMap(span.attributes, fields);
|
|
9963
|
+
const message = span.status.message;
|
|
9964
|
+
const redactedMessage = message === void 0 ? void 0 : redactSpanContent(message);
|
|
9965
|
+
let eventsChanged = false;
|
|
9966
|
+
const events = span.events.map((event) => {
|
|
9967
|
+
const eventAttributes = event.attributes && redactPiiInAttributeMap(event.attributes, fields);
|
|
9968
|
+
if (!eventAttributes) return event;
|
|
9969
|
+
eventsChanged = true;
|
|
9970
|
+
return { ...event, attributes: eventAttributes };
|
|
9971
|
+
});
|
|
9972
|
+
if (!attributes && redactedMessage === message && !eventsChanged) return span;
|
|
9973
|
+
const view = Object.create(span);
|
|
9974
|
+
if (attributes) {
|
|
9975
|
+
Object.defineProperty(view, "attributes", { value: attributes, enumerable: true });
|
|
9976
|
+
}
|
|
9977
|
+
if (redactedMessage !== message) {
|
|
9978
|
+
Object.defineProperty(view, "status", {
|
|
9979
|
+
value: { ...span.status, message: redactedMessage },
|
|
9980
|
+
enumerable: true
|
|
9981
|
+
});
|
|
9982
|
+
}
|
|
9983
|
+
if (eventsChanged) {
|
|
9984
|
+
Object.defineProperty(view, "events", { value: events, enumerable: true });
|
|
9985
|
+
}
|
|
9986
|
+
copyReplayTraceDestination(span, view);
|
|
9987
|
+
return view;
|
|
9988
|
+
}
|
|
9989
|
+
var PiiRedactingSpanExporter = class {
|
|
9990
|
+
constructor(inner, options) {
|
|
9991
|
+
this.inner = inner;
|
|
9992
|
+
this.options = options;
|
|
9993
|
+
/** Exports waiting for the org lookup; flush and shutdown wait for them. */
|
|
9994
|
+
this.pending = /* @__PURE__ */ new Set();
|
|
9995
|
+
}
|
|
9996
|
+
export(spans, resultCallback) {
|
|
9997
|
+
const { local, remote, apiUrl, writeKey, spanFields } = this.options;
|
|
9998
|
+
const exportContext = import_api2.context.active();
|
|
9999
|
+
const run = (redact) => {
|
|
10000
|
+
let outgoing = spans;
|
|
10001
|
+
if (redact) {
|
|
10002
|
+
outgoing = [];
|
|
10003
|
+
for (const span of spans) {
|
|
10004
|
+
try {
|
|
10005
|
+
outgoing.push(redactSpanPii(span, spanFields));
|
|
10006
|
+
} catch (e) {
|
|
10007
|
+
}
|
|
10008
|
+
}
|
|
10009
|
+
}
|
|
10010
|
+
try {
|
|
10011
|
+
import_api2.context.with(exportContext, () => this.inner.export(outgoing, resultCallback));
|
|
10012
|
+
} catch (e) {
|
|
10013
|
+
resultCallback({ code: 1 });
|
|
10014
|
+
}
|
|
10015
|
+
};
|
|
10016
|
+
const sharedRequest = localTracePiiRedactionRequested(apiUrl, writeKey);
|
|
10017
|
+
const known = sharedRequest || piiRedactionNow(local, remote, apiUrl, writeKey);
|
|
10018
|
+
if (known !== void 0) {
|
|
10019
|
+
run(known);
|
|
10020
|
+
return;
|
|
10021
|
+
}
|
|
10022
|
+
const handedOff = piiRedaction(local, remote, apiUrl, writeKey).then(
|
|
10023
|
+
(redact) => new Promise((resolve3) => {
|
|
10024
|
+
const callback = resultCallback;
|
|
10025
|
+
resultCallback = (result) => {
|
|
10026
|
+
resolve3();
|
|
10027
|
+
callback(result);
|
|
10028
|
+
};
|
|
10029
|
+
run(redact || localTracePiiRedactionRequested(apiUrl, writeKey));
|
|
10030
|
+
})
|
|
10031
|
+
);
|
|
10032
|
+
this.pending.add(handedOff);
|
|
10033
|
+
void handedOff.finally(() => this.pending.delete(handedOff));
|
|
10034
|
+
}
|
|
10035
|
+
async drainPending() {
|
|
10036
|
+
if (this.pending.size > 0) await Promise.allSettled([...this.pending]);
|
|
10037
|
+
}
|
|
10038
|
+
async shutdown() {
|
|
10039
|
+
await this.drainPending();
|
|
10040
|
+
return this.inner.shutdown();
|
|
10041
|
+
}
|
|
10042
|
+
async forceFlush() {
|
|
10043
|
+
var _a, _b, _c;
|
|
10044
|
+
await this.drainPending();
|
|
10045
|
+
return (_c = (_b = (_a = this.inner).forceFlush) == null ? void 0 : _b.call(_a)) != null ? _c : Promise.resolve();
|
|
10046
|
+
}
|
|
10047
|
+
};
|
|
9484
10048
|
var TRACER_NAME = "@traceloop/node-server-sdk";
|
|
9485
10049
|
var WORKFLOW_NAME_KEY = /* @__PURE__ */ Symbol.for("raindrop.otelCore.workflowName");
|
|
9486
10050
|
var ENTITY_NAME_KEY = /* @__PURE__ */ Symbol.for("raindrop.otelCore.entityName");
|
|
@@ -9510,12 +10074,12 @@ var AI_PROMPT_MESSAGES = "ai.prompt.messages";
|
|
|
9510
10074
|
var AI_PROMPT_TOKENS = "ai.usage.promptTokens";
|
|
9511
10075
|
var AI_COMPLETION_TOKENS = "ai.usage.completionTokens";
|
|
9512
10076
|
var AI_MODEL_PROVIDER = "ai.model.provider";
|
|
9513
|
-
var
|
|
10077
|
+
var STATE_KEY4 = /* @__PURE__ */ Symbol.for("raindrop.otelCore.state");
|
|
9514
10078
|
function getState2() {
|
|
9515
10079
|
var _a;
|
|
9516
10080
|
const holder = globalThis;
|
|
9517
|
-
(_a = holder[
|
|
9518
|
-
return holder[
|
|
10081
|
+
(_a = holder[STATE_KEY4]) != null ? _a : holder[STATE_KEY4] = {};
|
|
10082
|
+
return holder[STATE_KEY4];
|
|
9519
10083
|
}
|
|
9520
10084
|
function parseHeaders(value) {
|
|
9521
10085
|
const headers = {};
|
|
@@ -9716,7 +10280,8 @@ function createSpanProcessor(options) {
|
|
|
9716
10280
|
const apiKey = options.apiKey || process.env.TRACELOOP_API_KEY;
|
|
9717
10281
|
const resolvedHeaders = (_a = options.headers) != null ? _a : process.env.TRACELOOP_HEADERS ? parseHeaders(process.env.TRACELOOP_HEADERS) : { Authorization: `Bearer ${apiKey}` };
|
|
9718
10282
|
const baseExporter = (_b = options.exporter) != null ? _b : new import_exporter_trace_otlp_proto3.OTLPTraceExporter({ url: `${baseUrl}/v1/traces`, headers: resolvedHeaders });
|
|
9719
|
-
const
|
|
10283
|
+
const routed = options.routeReplayTraces ? new ReplayRoutingSpanExporter(baseExporter) : baseExporter;
|
|
10284
|
+
const exporter = options.piiRedaction ? new PiiRedactingSpanExporter(routed, options.piiRedaction) : routed;
|
|
9720
10285
|
const processor = options.disableBatch ? new import_sdk_trace_base.SimpleSpanProcessor(exporter) : new import_sdk_trace_base.BatchSpanProcessor(exporter);
|
|
9721
10286
|
const originalOnStart = processor.onStart.bind(processor);
|
|
9722
10287
|
const originalOnEnd = processor.onEnd.bind(processor);
|
|
@@ -9907,17 +10472,17 @@ function withTool(config, fn, ...args) {
|
|
|
9907
10472
|
}
|
|
9908
10473
|
|
|
9909
10474
|
// src/tracing/exit-flush.ts
|
|
9910
|
-
var
|
|
10475
|
+
var STATE_KEY5 = /* @__PURE__ */ Symbol.for("raindrop.tracing.exitFlushState");
|
|
9911
10476
|
function getState3() {
|
|
9912
10477
|
const holder = globalThis;
|
|
9913
|
-
let state2 = holder[
|
|
10478
|
+
let state2 = holder[STATE_KEY5];
|
|
9914
10479
|
if (!state2) {
|
|
9915
10480
|
state2 = {
|
|
9916
10481
|
clientFlushers: /* @__PURE__ */ new Set(),
|
|
9917
10482
|
pipelineFlushNeeded: false,
|
|
9918
10483
|
handlerRegistered: false
|
|
9919
10484
|
};
|
|
9920
|
-
holder[
|
|
10485
|
+
holder[STATE_KEY5] = state2;
|
|
9921
10486
|
}
|
|
9922
10487
|
return state2;
|
|
9923
10488
|
}
|
|
@@ -11496,6 +12061,7 @@ function createLocalDebuggerSpanProcessor(options) {
|
|
|
11496
12061
|
disableBatch: options.disableBatching,
|
|
11497
12062
|
exporter: localExporter,
|
|
11498
12063
|
headers: {},
|
|
12064
|
+
piiRedaction: options.piiRedaction,
|
|
11499
12065
|
allowedInstrumentationLibraries: options.allowedInstrumentationLibraries
|
|
11500
12066
|
});
|
|
11501
12067
|
} catch (error) {
|
|
@@ -11839,9 +12405,32 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
|
|
|
11839
12405
|
cloudEnabled,
|
|
11840
12406
|
projectId,
|
|
11841
12407
|
flushTimeoutMs,
|
|
12408
|
+
redactTracePii,
|
|
12409
|
+
redactPiiFields,
|
|
12410
|
+
remotePiiConfig,
|
|
11842
12411
|
...otherOptions
|
|
11843
12412
|
} = options;
|
|
11844
12413
|
const cloudEnabledResolved = cloudEnabled != null ? cloudEnabled : true;
|
|
12414
|
+
const localTracePii = typeof redactTracePii === "boolean" ? redactTracePii : void 0;
|
|
12415
|
+
const spanPiiFields = compileSpanPiiFields(redactPiiFields == null ? void 0 : redactPiiFields.span, "[raindrop]");
|
|
12416
|
+
if ((redactPiiFields == null ? void 0 : redactPiiFields.span) && localTracePii !== true && !remotePiiConfig) {
|
|
12417
|
+
rateLimitedLog(
|
|
12418
|
+
"js-sdk.pii_span_fields_without_redaction",
|
|
12419
|
+
() => console.warn(
|
|
12420
|
+
"[raindrop] redactPiiFields.span is set but redactTracePii is off; no span is redacted. Set redactTracePii: true to use it."
|
|
12421
|
+
)
|
|
12422
|
+
);
|
|
12423
|
+
}
|
|
12424
|
+
const piiRedaction2 = {
|
|
12425
|
+
local: localTracePii,
|
|
12426
|
+
remote: remotePiiConfig,
|
|
12427
|
+
apiUrl: directEndpoint != null ? directEndpoint : apiUrl,
|
|
12428
|
+
writeKey: cloudEnabledResolved ? writeKey : void 0,
|
|
12429
|
+
spanFields: spanPiiFields
|
|
12430
|
+
};
|
|
12431
|
+
if (localTracePii === true) {
|
|
12432
|
+
requestLocalTracePiiRedaction(piiRedaction2.apiUrl, piiRedaction2.writeKey);
|
|
12433
|
+
}
|
|
11845
12434
|
const authHint = authHintForKey(writeKey);
|
|
11846
12435
|
const clientTracingExports = !useExternalOtel && cloudEnabledResolved && tracingEnabled !== false;
|
|
11847
12436
|
registerClientKey(authHint, clientTracingExports);
|
|
@@ -11871,7 +12460,10 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
|
|
|
11871
12460
|
localDebuggerUrl,
|
|
11872
12461
|
cloudEnabled: cloudEnabledResolved,
|
|
11873
12462
|
projectId,
|
|
11874
|
-
flushTimeoutMs
|
|
12463
|
+
flushTimeoutMs,
|
|
12464
|
+
redactTracePii: localTracePii,
|
|
12465
|
+
remotePiiConfig,
|
|
12466
|
+
spanPiiFields
|
|
11875
12467
|
}) : void 0;
|
|
11876
12468
|
let traceloopInitialized = false;
|
|
11877
12469
|
let claimedPipeline = false;
|
|
@@ -11910,7 +12502,8 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
|
|
|
11910
12502
|
disableBatching,
|
|
11911
12503
|
allowedInstrumentationLibraries: ALL_INSTRUMENTATION_LIBRARIES,
|
|
11912
12504
|
localDebuggerUrlOpt: localDebuggerUrl,
|
|
11913
|
-
routeReplayTraces: !cloudEnabledResolved
|
|
12505
|
+
routeReplayTraces: !cloudEnabledResolved,
|
|
12506
|
+
piiRedaction: piiRedaction2
|
|
11914
12507
|
});
|
|
11915
12508
|
if (!cloudEnabledResolved) {
|
|
11916
12509
|
if (localDebuggerProcessor) {
|
|
@@ -11936,7 +12529,8 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
|
|
|
11936
12529
|
exporter: new DropSpanExporter(),
|
|
11937
12530
|
routeReplayTraces: true,
|
|
11938
12531
|
disableBatch: disableBatching,
|
|
11939
|
-
allowedInstrumentationLibraries: ALL_INSTRUMENTATION_LIBRARIES
|
|
12532
|
+
allowedInstrumentationLibraries: ALL_INSTRUMENTATION_LIBRARIES,
|
|
12533
|
+
piiRedaction: piiRedaction2
|
|
11940
12534
|
});
|
|
11941
12535
|
initialize({
|
|
11942
12536
|
baseUrl: apiUrl,
|
|
@@ -12008,6 +12602,7 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
|
|
|
12008
12602
|
disableBatch: disableBatching,
|
|
12009
12603
|
processor,
|
|
12010
12604
|
exporter: guardedExporter,
|
|
12605
|
+
piiRedaction: piiRedaction2,
|
|
12011
12606
|
instrumentations: createConfiguredInstrumentations(otherOptions)
|
|
12012
12607
|
});
|
|
12013
12608
|
traceloopInitialized = true;
|
|
@@ -12249,7 +12844,8 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
|
|
|
12249
12844
|
disableBatching,
|
|
12250
12845
|
allowedInstrumentationLibraries: processorOptions == null ? void 0 : processorOptions.allowedInstrumentationLibraries,
|
|
12251
12846
|
localDebuggerUrlOpt: localDebuggerUrl,
|
|
12252
|
-
routeReplayTraces: true
|
|
12847
|
+
routeReplayTraces: true,
|
|
12848
|
+
piiRedaction: piiRedaction2
|
|
12253
12849
|
});
|
|
12254
12850
|
return withV2SpanCompat(
|
|
12255
12851
|
localOnlyProcessor != null ? localOnlyProcessor : {
|
|
@@ -12271,13 +12867,15 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
|
|
|
12271
12867
|
disableBatch: disableBatching,
|
|
12272
12868
|
...processorOptions != null ? processorOptions : {},
|
|
12273
12869
|
routeReplayTraces: true,
|
|
12274
|
-
...headers ? { headers } : {}
|
|
12870
|
+
...headers ? { headers } : {},
|
|
12871
|
+
piiRedaction: piiRedaction2
|
|
12275
12872
|
});
|
|
12276
12873
|
const localDebuggerProcessor = createLocalDebuggerSpanProcessor({
|
|
12277
12874
|
writeKey,
|
|
12278
12875
|
disableBatching,
|
|
12279
12876
|
allowedInstrumentationLibraries: processorOptions == null ? void 0 : processorOptions.allowedInstrumentationLibraries,
|
|
12280
|
-
localDebuggerUrlOpt: localDebuggerUrl
|
|
12877
|
+
localDebuggerUrlOpt: localDebuggerUrl,
|
|
12878
|
+
piiRedaction: piiRedaction2
|
|
12281
12879
|
});
|
|
12282
12880
|
const contextProcessor = new RaindropContextSpanProcessor((properties) => analytics.getAppGitSnapshot(properties));
|
|
12283
12881
|
return withV2SpanCompat(
|
|
@@ -12709,9 +13307,9 @@ var ReplayTraceEvidenceEntrySchema = import_zod6.z.object({
|
|
|
12709
13307
|
});
|
|
12710
13308
|
}
|
|
12711
13309
|
});
|
|
12712
|
-
var ReplayTraceEvidenceSchema = import_zod6.z.array(ReplayTraceEvidenceEntrySchema).superRefine((
|
|
13310
|
+
var ReplayTraceEvidenceSchema = import_zod6.z.array(ReplayTraceEvidenceEntrySchema).superRefine((entries2, context8) => {
|
|
12713
13311
|
const seen = /* @__PURE__ */ new Set();
|
|
12714
|
-
for (const [index, entry] of
|
|
13312
|
+
for (const [index, entry] of entries2.entries()) {
|
|
12715
13313
|
if (seen.has(entry.rowId)) {
|
|
12716
13314
|
context8.addIssue({
|
|
12717
13315
|
code: import_zod6.z.ZodIssueCode.custom,
|
|
@@ -13346,7 +13944,7 @@ async function runReplayRows(client, handle, options) {
|
|
|
13346
13944
|
}
|
|
13347
13945
|
async function readEvalCaseTracePairs(input) {
|
|
13348
13946
|
const deadlineAt = Date.now() + input.waitMs;
|
|
13349
|
-
const
|
|
13947
|
+
const entries2 = await Promise.all(
|
|
13350
13948
|
input.evidence.map(async (evidence) => {
|
|
13351
13949
|
var _a, _b, _c;
|
|
13352
13950
|
let reading = await readEvalCaseTracePair(
|
|
@@ -13387,7 +13985,7 @@ async function readEvalCaseTracePairs(input) {
|
|
|
13387
13985
|
return [evidence.rowId, reading];
|
|
13388
13986
|
})
|
|
13389
13987
|
);
|
|
13390
|
-
return new Map(
|
|
13988
|
+
return new Map(entries2);
|
|
13391
13989
|
}
|
|
13392
13990
|
async function readEvalCaseTracePair(input, evidence, attempt) {
|
|
13393
13991
|
const query = new URLSearchParams({
|
|
@@ -14629,7 +15227,7 @@ async function publishEvalSuite(client, definition, options = {}) {
|
|
|
14629
15227
|
expectedCurrentVersionId: options.expectedCurrentDatasetVersionId
|
|
14630
15228
|
});
|
|
14631
15229
|
}
|
|
14632
|
-
const
|
|
15230
|
+
const entries2 = suite.evaluators.map((entry) => {
|
|
14633
15231
|
if (typeof entry.evaluator === "string") return entry;
|
|
14634
15232
|
if ("kind" in entry.evaluator && entry.evaluator.kind === "program") {
|
|
14635
15233
|
if (!entry.evaluator.expected) {
|
|
@@ -14642,7 +15240,7 @@ async function publishEvalSuite(client, definition, options = {}) {
|
|
|
14642
15240
|
return entry;
|
|
14643
15241
|
});
|
|
14644
15242
|
const evaluators = [];
|
|
14645
|
-
for (const entry of
|
|
15243
|
+
for (const entry of entries2) {
|
|
14646
15244
|
if (typeof entry.evaluator === "string") {
|
|
14647
15245
|
evaluators.push({
|
|
14648
15246
|
...entry,
|
|
@@ -15306,7 +15904,7 @@ var SELF_DIAGNOSTICS_SIGNALS_DEFAULT = {
|
|
|
15306
15904
|
sentiment: "NEGATIVE"
|
|
15307
15905
|
}
|
|
15308
15906
|
};
|
|
15309
|
-
function
|
|
15907
|
+
function isRecord3(value) {
|
|
15310
15908
|
return typeof value === "object" && value !== null;
|
|
15311
15909
|
}
|
|
15312
15910
|
function normalizeSelfDiagnosticsSignals(signals) {
|
|
@@ -15407,7 +16005,7 @@ var Raindrop = class {
|
|
|
15407
16005
|
* retry schedule.
|
|
15408
16006
|
*/
|
|
15409
16007
|
this.hasShutdown = false;
|
|
15410
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j
|
|
16008
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
15411
16009
|
const writeKey = (_a = config.writeKey) != null ? _a : "";
|
|
15412
16010
|
const disabled = (_b = config.disabled) != null ? _b : false;
|
|
15413
16011
|
const localDebuggerUrlOpt = config.localWorkshopUrl === false ? null : config.localWorkshopUrl;
|
|
@@ -15432,7 +16030,8 @@ var Raindrop = class {
|
|
|
15432
16030
|
debug: this.debugLogs,
|
|
15433
16031
|
prefix: "[raindrop]"
|
|
15434
16032
|
});
|
|
15435
|
-
this.redactPii =
|
|
16033
|
+
this.redactPii = config.redactPii;
|
|
16034
|
+
this.remotePiiConfig = config.remotePiiConfig;
|
|
15436
16035
|
this.piiFields = new PiiFieldRedactor({
|
|
15437
16036
|
startupFieldMap: config.redactPiiFields,
|
|
15438
16037
|
logPrefix: "[raindrop]"
|
|
@@ -15446,7 +16045,7 @@ var Raindrop = class {
|
|
|
15446
16045
|
"[raindrop] 'disableTracing' is deprecated and renamed to 'useExternalOtel'. Please update your config: { useExternalOtel: true }"
|
|
15447
16046
|
);
|
|
15448
16047
|
}
|
|
15449
|
-
const useExternalOtel = (
|
|
16048
|
+
const useExternalOtel = (_i = (_h = config.useExternalOtel) != null ? _h : config.disableTracing) != null ? _i : false;
|
|
15450
16049
|
const disableBatching = resolveDisableBatching(config.disableBatching, {
|
|
15451
16050
|
isProduction: process.env.NODE_ENV === "production",
|
|
15452
16051
|
isLocalDebugger: localDebuggerEnabled(this.localDebuggerUrlOpt)
|
|
@@ -15472,7 +16071,8 @@ var Raindrop = class {
|
|
|
15472
16071
|
maxTextFieldChars: config.maxTextFieldChars,
|
|
15473
16072
|
redactPii: this.redactPii,
|
|
15474
16073
|
redactPiiFields: config.redactPiiFields,
|
|
15475
|
-
|
|
16074
|
+
remotePiiConfig: this.remotePiiConfig,
|
|
16075
|
+
wizardSession: (_j = this.wizardSession) != null ? _j : void 0,
|
|
15476
16076
|
flushTimeoutMs: this.flushTimeoutMs
|
|
15477
16077
|
});
|
|
15478
16078
|
try {
|
|
@@ -15496,7 +16096,10 @@ var Raindrop = class {
|
|
|
15496
16096
|
localDebuggerUrl: this.localDebuggerUrlOpt,
|
|
15497
16097
|
cloudEnabled: !this.localOnly,
|
|
15498
16098
|
projectId: this.projectId,
|
|
15499
|
-
flushTimeoutMs: this.flushTimeoutMs
|
|
16099
|
+
flushTimeoutMs: this.flushTimeoutMs,
|
|
16100
|
+
redactTracePii: config.redactTracePii,
|
|
16101
|
+
redactPiiFields: config.redactPiiFields,
|
|
16102
|
+
remotePiiConfig: this.remotePiiConfig
|
|
15500
16103
|
},
|
|
15501
16104
|
this.debugLogs
|
|
15502
16105
|
);
|
|
@@ -15710,7 +16313,7 @@ var Raindrop = class {
|
|
|
15710
16313
|
const onMissingEventId = (_b = options.onMissingEventId) != null ? _b : "warn";
|
|
15711
16314
|
const execute = async (rawInput, context8) => {
|
|
15712
16315
|
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
15713
|
-
const input =
|
|
16316
|
+
const input = isRecord3(rawInput) ? rawInput : void 0;
|
|
15714
16317
|
const fallbackCategory = (_a2 = signalKeys[0]) != null ? _a2 : "unknown";
|
|
15715
16318
|
const categoryCandidate = normalizeEventId(input == null ? void 0 : input["category"]);
|
|
15716
16319
|
const category = categoryCandidate && signalKeySet.has(categoryCandidate) ? categoryCandidate : fallbackCategory;
|
|
@@ -16098,9 +16701,14 @@ var Raindrop = class {
|
|
|
16098
16701
|
}
|
|
16099
16702
|
async sendBatchToApi(events, endpoint, deadlineAt) {
|
|
16100
16703
|
const kind = PII_KIND_BY_ENDPOINT[endpoint];
|
|
16101
|
-
const
|
|
16102
|
-
|
|
16103
|
-
);
|
|
16704
|
+
const writeKey = this.localOnly ? void 0 : this.writeKey;
|
|
16705
|
+
let rows = events.map(({ type, ...event }) => event);
|
|
16706
|
+
let redact = kind !== void 0 && piiRedactionNow(this.redactPii, this.remotePiiConfig, this.apiUrl, writeKey);
|
|
16707
|
+
if (redact === void 0) {
|
|
16708
|
+
rows = rows.map(snapshotPayload);
|
|
16709
|
+
redact = await piiRedaction(this.redactPii, this.remotePiiConfig, this.apiUrl, writeKey, deadlineAt);
|
|
16710
|
+
}
|
|
16711
|
+
const body = rows.map((event) => redact && kind ? this.piiFields.redact(kind, event) : event);
|
|
16104
16712
|
this.mirrorBatchToLocalDebugger(endpoint, body);
|
|
16105
16713
|
if (this.localOnly) {
|
|
16106
16714
|
return void 0;
|