raindrop-ai 1.0.8 → 1.0.9
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/README.md +42 -0
- package/dist/{chunk-JK73MFZN.mjs → chunk-D3QLE7H4.mjs} +705 -252
- package/dist/{chunk-NELGM2YD.mjs → chunk-GY3TJEAZ.mjs} +10 -3
- package/dist/evals/cli.js +712 -254
- package/dist/evals/cli.mjs +2 -2
- package/dist/{index-BOTg0MlJ.d.mts → index-Bt667HTt.d.mts} +31 -2
- package/dist/{index-BOTg0MlJ.d.ts → index-Bt667HTt.d.ts} +31 -2
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +712 -254
- package/dist/index.mjs +2 -2
- package/dist/tracing/index.d.mts +4 -2
- package/dist/tracing/index.d.ts +4 -2
- package/dist/tracing/index.js +603 -222
- package/dist/tracing/index.mjs +1 -1
- package/package.json +2 -2
package/dist/tracing/index.js
CHANGED
|
@@ -130,7 +130,7 @@ function evalScopeAttributes() {
|
|
|
130
130
|
return { [EVAL_CORRELATION_ID_ATTRIBUTE]: scope.correlationId };
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
// ../core/dist/chunk-
|
|
133
|
+
// ../core/dist/chunk-5OUEKTIO.js
|
|
134
134
|
var require_NameRedactor = __commonJS({
|
|
135
135
|
"../redact-pii/dist/built-ins/NameRedactor.js"(exports2) {
|
|
136
136
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
@@ -224,7 +224,37 @@ var require_SimpleRegexpRedactor = __commonJS({
|
|
|
224
224
|
this.replaceWith = replaceWith;
|
|
225
225
|
this.regexpMatcher = regexpMatcher;
|
|
226
226
|
}
|
|
227
|
-
redact(textToRedact) {
|
|
227
|
+
redact(textToRedact, observe) {
|
|
228
|
+
if (observe) {
|
|
229
|
+
observe(0, 0, "");
|
|
230
|
+
let out = "";
|
|
231
|
+
let end = 0;
|
|
232
|
+
const matcher = new RegExp(this.regexpMatcher.source, this.regexpMatcher.flags);
|
|
233
|
+
let match;
|
|
234
|
+
while ((match = matcher.exec(textToRedact)) !== null) {
|
|
235
|
+
out += textToRedact.slice(end, match.index);
|
|
236
|
+
const captured = match;
|
|
237
|
+
const replacement = this.replaceWith.replace(/\$(\$|&|`|'|[1-9][0-9]?)/g, (token, key) => {
|
|
238
|
+
if (key === "$")
|
|
239
|
+
return "$";
|
|
240
|
+
if (key === "&")
|
|
241
|
+
return captured[0];
|
|
242
|
+
if (key === "`")
|
|
243
|
+
return textToRedact.slice(0, captured.index);
|
|
244
|
+
if (key === "'")
|
|
245
|
+
return textToRedact.slice(captured.index + captured[0].length);
|
|
246
|
+
return Number(key) < captured.length ? captured[Number(key)] || "" : token;
|
|
247
|
+
});
|
|
248
|
+
observe(out.length, match[0].length, replacement);
|
|
249
|
+
out += replacement;
|
|
250
|
+
end = match.index + match[0].length;
|
|
251
|
+
if (!matcher.global)
|
|
252
|
+
break;
|
|
253
|
+
if (match[0].length === 0)
|
|
254
|
+
matcher.lastIndex += 1;
|
|
255
|
+
}
|
|
256
|
+
return out + textToRedact.slice(end);
|
|
257
|
+
}
|
|
228
258
|
return textToRedact.replace(this.regexpMatcher, this.replaceWith);
|
|
229
259
|
}
|
|
230
260
|
};
|
|
@@ -330,9 +360,9 @@ var require_SyncCompositeRedactor = __commonJS({
|
|
|
330
360
|
var SyncCompositeRedactor = class {
|
|
331
361
|
constructor(opts) {
|
|
332
362
|
this.childRedactors = [];
|
|
333
|
-
this.redact = (textToRedact) => {
|
|
363
|
+
this.redact = (textToRedact, observe) => {
|
|
334
364
|
for (const redactor2 of this.childRedactors) {
|
|
335
|
-
textToRedact = redactor2.redact(textToRedact);
|
|
365
|
+
textToRedact = redactor2.redact(textToRedact, observe);
|
|
336
366
|
}
|
|
337
367
|
return textToRedact;
|
|
338
368
|
};
|
|
@@ -1368,6 +1398,12 @@ var TRUNCATION_MARKER = "...[truncated by raindrop]";
|
|
|
1368
1398
|
var BOUNDED_CLONE_MAX_DEPTH = 12;
|
|
1369
1399
|
var BOUNDED_CLONE_SLACK = 256;
|
|
1370
1400
|
var currentDefaultMaxTextFieldChars = DEFAULT_MAX_TEXT_FIELD_CHARS;
|
|
1401
|
+
function resolveMaxTextFieldChars(value) {
|
|
1402
|
+
if (typeof value === "number" && Number.isFinite(value) && value > 0) {
|
|
1403
|
+
return Math.floor(value);
|
|
1404
|
+
}
|
|
1405
|
+
return currentDefaultMaxTextFieldChars;
|
|
1406
|
+
}
|
|
1371
1407
|
function truncateToLimit(text, limit) {
|
|
1372
1408
|
if (limit > TRUNCATION_MARKER.length) {
|
|
1373
1409
|
return text.slice(0, limit - TRUNCATION_MARKER.length) + TRUNCATION_MARKER;
|
|
@@ -1574,8 +1610,62 @@ var PROJECT_ID_HEADER = "X-Raindrop-Project-Id";
|
|
|
1574
1610
|
function projectIdHeaders(projectId) {
|
|
1575
1611
|
return projectId ? { [PROJECT_ID_HEADER]: projectId } : {};
|
|
1576
1612
|
}
|
|
1613
|
+
var PII_MARKERS = /<REDACTED (?:CREDENTIALS|CREDIT CARD NUMBER|EMAIL|SECRET|PHONE NUMBER|ADDRESS|SOCIAL SECURITY NUMBER|DATE OF BIRTH|MEDICAL RECORD NUMBER)>/g;
|
|
1614
|
+
function replacePiiMatches(text, pattern, replace, observe, preservePrefix = true) {
|
|
1615
|
+
observe == null ? void 0 : observe(0, 0, "");
|
|
1616
|
+
let out = "";
|
|
1617
|
+
let end = 0;
|
|
1618
|
+
for (const match of text.matchAll(pattern)) {
|
|
1619
|
+
out += text.slice(end, match.index);
|
|
1620
|
+
const replacement = replace(match);
|
|
1621
|
+
if (replacement !== match[0]) {
|
|
1622
|
+
let prefix = 0;
|
|
1623
|
+
if (preservePrefix) {
|
|
1624
|
+
while (prefix < match[0].length && prefix < replacement.length && match[0][prefix] === replacement[prefix]) prefix++;
|
|
1625
|
+
}
|
|
1626
|
+
observe == null ? void 0 : observe(out.length + prefix, match[0].length - prefix, replacement.slice(prefix));
|
|
1627
|
+
}
|
|
1628
|
+
out += replacement;
|
|
1629
|
+
end = match.index + match[0].length;
|
|
1630
|
+
}
|
|
1631
|
+
return out + text.slice(end);
|
|
1632
|
+
}
|
|
1633
|
+
function redactWithinOriginalLimit(text, maxChars, redact) {
|
|
1634
|
+
let cutoff = Math.min(text.length, maxChars);
|
|
1635
|
+
const redacted = redact(text.slice(0, maxChars + 256), (start, length, replacement) => {
|
|
1636
|
+
if (start >= cutoff) return;
|
|
1637
|
+
cutoff = start + length >= cutoff ? start + replacement.length : cutoff + replacement.length - length;
|
|
1638
|
+
});
|
|
1639
|
+
let prefix = redacted.slice(0, cutoff);
|
|
1640
|
+
if (text.length <= maxChars && prefix.length <= maxChars) return prefix;
|
|
1641
|
+
if (maxChars < TRUNCATION_MARKER.length) return "";
|
|
1642
|
+
const budget = Math.max(0, maxChars - TRUNCATION_MARKER.length);
|
|
1643
|
+
let end = Math.min(prefix.length, budget);
|
|
1644
|
+
for (const marker of prefix.matchAll(PII_MARKERS)) {
|
|
1645
|
+
if (marker.index < end && marker.index + marker[0].length > end) end = marker.index;
|
|
1646
|
+
}
|
|
1647
|
+
prefix = prefix.slice(0, end);
|
|
1648
|
+
return prefix + TRUNCATION_MARKER;
|
|
1649
|
+
}
|
|
1650
|
+
var day = "(?:0?[1-9]|[12][0-9]|3[01])";
|
|
1651
|
+
var month = "(?:0?[1-9]|1[0-2])";
|
|
1652
|
+
var year = "(?:18|19|20)[0-9]{2}";
|
|
1653
|
+
var monthName = "(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)";
|
|
1654
|
+
var date = `(?:${month}/${day}/${year}|${day}-${month}-${year}|${year}-${month}-${day}|${monthName} ${day},? ${year}|${day} ${monthName} ${year})`;
|
|
1655
|
+
var birthDate = new RegExp(
|
|
1656
|
+
`(\\b(?:d\\.?o\\.?b\\.?|date[ _]?of[ _]?birth|born|birthday)[\\t :="']{0,8}(?:on[ ]{1,3})?)${date}(?![\\p{L}\\p{N}_]|T[0-9])`,
|
|
1657
|
+
"giu"
|
|
1658
|
+
);
|
|
1659
|
+
var mrn = /\b((?:MRN|medical record(?: number)?)["']?[\t :#=]{1,8}["']?)([a-z0-9][a-z0-9-]{2,39})\b/gi;
|
|
1660
|
+
var contextualPiiRedactor = {
|
|
1661
|
+
redact(text, observe) {
|
|
1662
|
+
text = replacePiiMatches(text, birthDate, (m) => `${m[1]}<REDACTED DATE OF BIRTH>`, observe);
|
|
1663
|
+
return replacePiiMatches(text, mrn, (m) => /[0-9]/.test(m[2]) ? `${m[1]}<REDACTED MEDICAL RECORD NUMBER>` : m[0], observe);
|
|
1664
|
+
}
|
|
1665
|
+
};
|
|
1577
1666
|
var import_redact_pii = __toESM2(require_dist(), 1);
|
|
1578
1667
|
var DEFAULT_PII_REDACTION_OPTIONS = {
|
|
1668
|
+
customRedactors: { after: [contextualPiiRedactor] },
|
|
1579
1669
|
builtInRedactors: {
|
|
1580
1670
|
credentials: { replaceWith: "<REDACTED CREDENTIALS>" },
|
|
1581
1671
|
creditCardNumber: { replaceWith: "<REDACTED CREDIT CARD NUMBER>" },
|
|
@@ -1595,9 +1685,472 @@ var DEFAULT_PII_REDACTION_OPTIONS = {
|
|
|
1595
1685
|
}
|
|
1596
1686
|
};
|
|
1597
1687
|
var redactor;
|
|
1598
|
-
function redactPiiText(text) {
|
|
1688
|
+
function redactPiiText(text, observe) {
|
|
1599
1689
|
redactor != null ? redactor : redactor = new import_redact_pii.SyncRedactor(DEFAULT_PII_REDACTION_OPTIONS);
|
|
1600
|
-
|
|
1690
|
+
let out = "";
|
|
1691
|
+
let start = 0;
|
|
1692
|
+
for (const marker of text.matchAll(PII_MARKERS)) {
|
|
1693
|
+
const offset2 = out.length;
|
|
1694
|
+
out += redactor.redact(text.slice(start, marker.index), observe && ((at, length, replacement) => observe(offset2 + at, length, replacement))) + marker[0];
|
|
1695
|
+
start = marker.index + marker[0].length;
|
|
1696
|
+
}
|
|
1697
|
+
const offset = out.length;
|
|
1698
|
+
return out + redactor.redact(text.slice(start), observe && ((at, length, replacement) => observe(offset + at, length, replacement)));
|
|
1699
|
+
}
|
|
1700
|
+
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)$/;
|
|
1701
|
+
var CONTENT_KEYS = /* @__PURE__ */ new Set([
|
|
1702
|
+
"ai.prompt.system",
|
|
1703
|
+
"ai.subagent.result",
|
|
1704
|
+
"agent.session.title",
|
|
1705
|
+
// Failed tool calls carry the tool's output in their error text.
|
|
1706
|
+
"error.message",
|
|
1707
|
+
"exception.message",
|
|
1708
|
+
"exception.stacktrace"
|
|
1709
|
+
]);
|
|
1710
|
+
var NON_CONTENT_PREFIXES = [
|
|
1711
|
+
"traceloop.association.properties.",
|
|
1712
|
+
"ai.telemetry.metadata.",
|
|
1713
|
+
"ai.settings.context.",
|
|
1714
|
+
"raindrop.app."
|
|
1715
|
+
];
|
|
1716
|
+
var ASSOCIATION_PROPERTY = /^(?:ai\.telemetry\.metadata\.)?traceloop\.association\.properties\.(.+)$/;
|
|
1717
|
+
var SDK_ASSOCIATION_PROPERTIES = /* @__PURE__ */ new Set([
|
|
1718
|
+
"user_id",
|
|
1719
|
+
"event_id",
|
|
1720
|
+
"convo_id",
|
|
1721
|
+
"event_name"
|
|
1722
|
+
]);
|
|
1723
|
+
function isEventPropertyCopy(key) {
|
|
1724
|
+
var _a;
|
|
1725
|
+
if (key === "ai.telemetry.metadata.raindrop.properties") return true;
|
|
1726
|
+
const name = (_a = ASSOCIATION_PROPERTY.exec(key)) == null ? void 0 : _a[1];
|
|
1727
|
+
return name !== void 0 && !SDK_ASSOCIATION_PROPERTIES.has(name) && !name.startsWith("raindrop.");
|
|
1728
|
+
}
|
|
1729
|
+
var JSON_SIMPLE_ESCAPES = {
|
|
1730
|
+
'"': '"',
|
|
1731
|
+
"\\": "\\",
|
|
1732
|
+
"/": "/",
|
|
1733
|
+
b: "\b",
|
|
1734
|
+
f: "\f",
|
|
1735
|
+
n: "\n",
|
|
1736
|
+
r: "\r",
|
|
1737
|
+
t: " "
|
|
1738
|
+
};
|
|
1739
|
+
function decodeJsonEscapes(text, observe) {
|
|
1740
|
+
if (!text.includes("\\")) return text;
|
|
1741
|
+
let out = "";
|
|
1742
|
+
for (let i = 0; i < text.length; i++) {
|
|
1743
|
+
const ch = text[i];
|
|
1744
|
+
if (ch !== "\\" || i + 1 >= text.length) {
|
|
1745
|
+
out += ch;
|
|
1746
|
+
continue;
|
|
1747
|
+
}
|
|
1748
|
+
const next = text[i + 1];
|
|
1749
|
+
const simple = JSON_SIMPLE_ESCAPES[next];
|
|
1750
|
+
if (simple !== void 0) {
|
|
1751
|
+
observe == null ? void 0 : observe(out.length, 2, simple);
|
|
1752
|
+
out += simple;
|
|
1753
|
+
i += 1;
|
|
1754
|
+
} else if (next === "u" && /^[0-9a-fA-F]{4}$/.test(text.slice(i + 2, i + 6))) {
|
|
1755
|
+
observe == null ? void 0 : observe(out.length, 6, String.fromCharCode(Number.parseInt(text.slice(i + 2, i + 6), 16)));
|
|
1756
|
+
out += String.fromCharCode(Number.parseInt(text.slice(i + 2, i + 6), 16));
|
|
1757
|
+
i += 5;
|
|
1758
|
+
} else {
|
|
1759
|
+
out += ch;
|
|
1760
|
+
}
|
|
1761
|
+
}
|
|
1762
|
+
return out;
|
|
1763
|
+
}
|
|
1764
|
+
function jsonStringBody(value, observe) {
|
|
1765
|
+
if (!observe) return JSON.stringify(value).slice(1, -1);
|
|
1766
|
+
return replacePiiMatches(
|
|
1767
|
+
value,
|
|
1768
|
+
/[\u0000-\u001f"\\]|[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/g,
|
|
1769
|
+
(m) => JSON.stringify(m[0]).slice(1, -1),
|
|
1770
|
+
observe,
|
|
1771
|
+
false
|
|
1772
|
+
);
|
|
1773
|
+
}
|
|
1774
|
+
function redactEncodedBody(raw, cue, observe) {
|
|
1775
|
+
const decoded = decodeJsonEscapes(raw);
|
|
1776
|
+
const edits = [];
|
|
1777
|
+
const redacted = redactCuedValue(decoded, cue, observe && ((...edit) => edits.push(edit)));
|
|
1778
|
+
if (redacted === decoded) return raw;
|
|
1779
|
+
decodeJsonEscapes(raw, observe);
|
|
1780
|
+
for (const edit of edits) observe == null ? void 0 : observe(...edit);
|
|
1781
|
+
return jsonStringBody(redacted, observe);
|
|
1782
|
+
}
|
|
1783
|
+
function redactStringToken(token, cue, observe) {
|
|
1784
|
+
const body = redactEncodedBody(token.slice(1, -1), cue, observe && ((at, length, replacement) => observe(at + 1, length, replacement)));
|
|
1785
|
+
return `"${body}"`;
|
|
1786
|
+
}
|
|
1787
|
+
function contextualCue(key) {
|
|
1788
|
+
switch (key.trim().toLowerCase().replace(/[\s_.\-]/g, "")) {
|
|
1789
|
+
case "dob":
|
|
1790
|
+
case "dateofbirth":
|
|
1791
|
+
case "birthday":
|
|
1792
|
+
case "born":
|
|
1793
|
+
return "DOB: ";
|
|
1794
|
+
case "mrn":
|
|
1795
|
+
case "medicalrecord":
|
|
1796
|
+
case "medicalrecordnumber":
|
|
1797
|
+
return "MRN: ";
|
|
1798
|
+
default:
|
|
1799
|
+
return void 0;
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
function redactCuedValue(value, cue, observe) {
|
|
1803
|
+
const redacted = redactPiiText(value, observe);
|
|
1804
|
+
return cue === void 0 ? redacted : contextualPiiRedactor.redact(cue + redacted, observe && ((at, length, replacement) => {
|
|
1805
|
+
if (length === 0 && replacement === "") {
|
|
1806
|
+
observe(0, 0, "");
|
|
1807
|
+
return;
|
|
1808
|
+
}
|
|
1809
|
+
const prefix = Math.max(0, cue.length - at);
|
|
1810
|
+
observe(Math.max(0, at - cue.length), length - prefix, replacement.slice(prefix));
|
|
1811
|
+
})).slice(cue.length);
|
|
1812
|
+
}
|
|
1813
|
+
function redactLooseJsonText(text, observe) {
|
|
1814
|
+
var _a;
|
|
1815
|
+
if (text.startsWith('"')) {
|
|
1816
|
+
return `"${redactEncodedBody(text.slice(1), void 0, observe && ((at, length, replacement) => observe(at + 1, length, replacement)))}`;
|
|
1817
|
+
}
|
|
1818
|
+
if (!text.includes("\\")) return redactPiiText(text, observe);
|
|
1819
|
+
let pieces = (_a = text.match(/\\u[0-9a-fA-F]{4}|\\["\\/bfnrt]|[\s\S]/g)) != null ? _a : [];
|
|
1820
|
+
const decoded = pieces.map((piece) => decodeJsonEscapes(piece)).join("");
|
|
1821
|
+
let next = [];
|
|
1822
|
+
let read = 0;
|
|
1823
|
+
let delta = 0;
|
|
1824
|
+
let written = 0;
|
|
1825
|
+
const copyTo = (end) => {
|
|
1826
|
+
while (read < end) {
|
|
1827
|
+
const piece = pieces[read++];
|
|
1828
|
+
next.push(piece);
|
|
1829
|
+
written += piece.length;
|
|
1830
|
+
}
|
|
1831
|
+
};
|
|
1832
|
+
const finishPass = () => {
|
|
1833
|
+
copyTo(pieces.length);
|
|
1834
|
+
pieces = next;
|
|
1835
|
+
next = [];
|
|
1836
|
+
read = 0;
|
|
1837
|
+
delta = 0;
|
|
1838
|
+
written = 0;
|
|
1839
|
+
};
|
|
1840
|
+
redactPiiText(decoded, (start, length, replacement) => {
|
|
1841
|
+
if (length === 0 && replacement === "") {
|
|
1842
|
+
finishPass();
|
|
1843
|
+
return;
|
|
1844
|
+
}
|
|
1845
|
+
const at = start - delta;
|
|
1846
|
+
copyTo(at);
|
|
1847
|
+
let rawLength = 0;
|
|
1848
|
+
for (let index = at; index < at + length; index++) rawLength += pieces[index].length;
|
|
1849
|
+
observe == null ? void 0 : observe(written, rawLength, replacement);
|
|
1850
|
+
for (let index = 0; index < replacement.length; index++) next.push(replacement[index]);
|
|
1851
|
+
written += replacement.length;
|
|
1852
|
+
read = at + length;
|
|
1853
|
+
delta += replacement.length - length;
|
|
1854
|
+
});
|
|
1855
|
+
finishPass();
|
|
1856
|
+
return pieces.join("");
|
|
1857
|
+
}
|
|
1858
|
+
function stringTokenEnd(text, start) {
|
|
1859
|
+
for (let i = start + 1; i < text.length; i++) {
|
|
1860
|
+
const ch = text[i];
|
|
1861
|
+
if (ch === "\\") i += 1;
|
|
1862
|
+
else if (ch === '"') return i + 1;
|
|
1863
|
+
}
|
|
1864
|
+
return -1;
|
|
1865
|
+
}
|
|
1866
|
+
function redactJsonLike(text, complete, observe) {
|
|
1867
|
+
var _a, _b;
|
|
1868
|
+
let out = "";
|
|
1869
|
+
let looseStart = 0;
|
|
1870
|
+
const flushLoose = (end) => {
|
|
1871
|
+
if (end > looseStart) {
|
|
1872
|
+
const loose = text.slice(looseStart, end);
|
|
1873
|
+
const offset = out.length;
|
|
1874
|
+
out += complete ? loose : redactLooseJsonText(loose, observe && ((at, length, replacement) => observe(offset + at, length, replacement)));
|
|
1875
|
+
}
|
|
1876
|
+
};
|
|
1877
|
+
let i = text.indexOf('"');
|
|
1878
|
+
while (i !== -1) {
|
|
1879
|
+
const end = stringTokenEnd(text, i);
|
|
1880
|
+
if (end === -1) break;
|
|
1881
|
+
flushLoose(i);
|
|
1882
|
+
let after = end;
|
|
1883
|
+
while (after < text.length && /\s/.test(text[after])) after += 1;
|
|
1884
|
+
const token = text.slice(i, end);
|
|
1885
|
+
if (text[after] === ":") {
|
|
1886
|
+
const cue = contextualCue(decodeJsonEscapes(token.slice(1, -1)));
|
|
1887
|
+
if (cue !== void 0) {
|
|
1888
|
+
let start = after + 1;
|
|
1889
|
+
while (/\s/.test((_a = text[start]) != null ? _a : "")) start += 1;
|
|
1890
|
+
let valueEnd = start;
|
|
1891
|
+
let replacement;
|
|
1892
|
+
const offset2 = out.length + start - i;
|
|
1893
|
+
const valueObserver = observe && ((at, length, replacement2) => observe(offset2 + at, length, replacement2));
|
|
1894
|
+
if (text[start] === '"') {
|
|
1895
|
+
valueEnd = stringTokenEnd(text, start);
|
|
1896
|
+
if (valueEnd === -1) {
|
|
1897
|
+
valueEnd = text.length;
|
|
1898
|
+
replacement = `"${redactEncodedBody(text.slice(start + 1), cue, valueObserver && ((at, length, replacement2) => valueObserver(at + 1, length, replacement2)))}`;
|
|
1899
|
+
} else {
|
|
1900
|
+
replacement = redactStringToken(text.slice(start, valueEnd), cue, valueObserver);
|
|
1901
|
+
}
|
|
1902
|
+
} else if (/[-0-9]/.test((_b = text[start]) != null ? _b : "")) {
|
|
1903
|
+
while (valueEnd < text.length && !/[\s,}\]]/.test(text[valueEnd])) valueEnd += 1;
|
|
1904
|
+
const value = text.slice(start, valueEnd);
|
|
1905
|
+
const redacted = redactCuedValue(value, cue);
|
|
1906
|
+
if (redacted !== value) {
|
|
1907
|
+
replacement = JSON.stringify(redacted);
|
|
1908
|
+
valueObserver == null ? void 0 : valueObserver(0, value.length, replacement);
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
if (replacement !== void 0) {
|
|
1912
|
+
out += text.slice(i, start) + replacement;
|
|
1913
|
+
looseStart = valueEnd;
|
|
1914
|
+
i = text.indexOf('"', valueEnd);
|
|
1915
|
+
continue;
|
|
1916
|
+
}
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
const offset = out.length;
|
|
1920
|
+
out += complete && text[after] === ":" ? token : redactStringToken(token, void 0, observe && ((at, length, replacement) => observe(offset + at, length, replacement)));
|
|
1921
|
+
looseStart = end;
|
|
1922
|
+
i = text.indexOf('"', end);
|
|
1923
|
+
}
|
|
1924
|
+
if (i === -1) {
|
|
1925
|
+
flushLoose(text.length);
|
|
1926
|
+
} else {
|
|
1927
|
+
flushLoose(i);
|
|
1928
|
+
looseStart = i;
|
|
1929
|
+
flushLoose(text.length);
|
|
1930
|
+
}
|
|
1931
|
+
return out;
|
|
1932
|
+
}
|
|
1933
|
+
function redactSpanContent(text, observe) {
|
|
1934
|
+
const head = text.trimStart()[0];
|
|
1935
|
+
if (head !== "{" && head !== "[" && head !== '"') return redactPiiText(text, observe);
|
|
1936
|
+
let complete = true;
|
|
1937
|
+
try {
|
|
1938
|
+
JSON.parse(text);
|
|
1939
|
+
} catch (e) {
|
|
1940
|
+
complete = false;
|
|
1941
|
+
}
|
|
1942
|
+
return redactJsonLike(text, complete, observe);
|
|
1943
|
+
}
|
|
1944
|
+
var NO_SPAN_PII_FIELDS = { exact: /* @__PURE__ */ new Set(), prefixes: [] };
|
|
1945
|
+
function compileSpanPiiFields(names, logPrefix = "[raindrop-ai/core]") {
|
|
1946
|
+
if (!Array.isArray(names) || names.length === 0) return NO_SPAN_PII_FIELDS;
|
|
1947
|
+
const exact = /* @__PURE__ */ new Set();
|
|
1948
|
+
const prefixes = [];
|
|
1949
|
+
for (const name of names) {
|
|
1950
|
+
const valid = typeof name === "string" && !/\s/.test(name) && /^[^*]+\*?$/.test(name);
|
|
1951
|
+
if (!valid) {
|
|
1952
|
+
rateLimitedLog(
|
|
1953
|
+
`${logPrefix}.pii_span_field_invalid`,
|
|
1954
|
+
() => console.warn(
|
|
1955
|
+
`${logPrefix} redactPiiFields: ignoring invalid span attribute ${JSON.stringify(name)}`
|
|
1956
|
+
)
|
|
1957
|
+
);
|
|
1958
|
+
continue;
|
|
1959
|
+
}
|
|
1960
|
+
if (name.endsWith("*")) prefixes.push(name.slice(0, -1));
|
|
1961
|
+
else exact.add(name);
|
|
1962
|
+
}
|
|
1963
|
+
return { exact, prefixes };
|
|
1964
|
+
}
|
|
1965
|
+
function isCallerSelected(key, fields) {
|
|
1966
|
+
return fields.exact.has(key) || fields.prefixes.some((prefix) => key.startsWith(prefix));
|
|
1967
|
+
}
|
|
1968
|
+
function isSpanContentAttributeKey(key, fields = NO_SPAN_PII_FIELDS) {
|
|
1969
|
+
if (isCallerSelected(key, fields) || isEventPropertyCopy(key)) return true;
|
|
1970
|
+
if (NON_CONTENT_PREFIXES.some((prefix) => key.startsWith(prefix))) return false;
|
|
1971
|
+
return CONTENT_KEYS.has(key) || CONTENT_KEY_SUFFIX.test(key);
|
|
1972
|
+
}
|
|
1973
|
+
function redactBoundedContent(text, maxChars) {
|
|
1974
|
+
if (maxChars === void 0) return redactSpanContent(text);
|
|
1975
|
+
return redactWithinOriginalLimit(text, maxChars, redactSpanContent);
|
|
1976
|
+
}
|
|
1977
|
+
function redactOtlpValue(value, maxChars) {
|
|
1978
|
+
var _a;
|
|
1979
|
+
if (typeof value.stringValue === "string") {
|
|
1980
|
+
const redacted = redactBoundedContent(value.stringValue, maxChars);
|
|
1981
|
+
return redacted === value.stringValue ? value : { ...value, stringValue: redacted };
|
|
1982
|
+
}
|
|
1983
|
+
const values = (_a = value.arrayValue) == null ? void 0 : _a.values;
|
|
1984
|
+
if (!values) return value;
|
|
1985
|
+
let changed = false;
|
|
1986
|
+
const next = values.map((item) => {
|
|
1987
|
+
const redacted = redactOtlpValue(item, maxChars);
|
|
1988
|
+
if (redacted !== item) changed = true;
|
|
1989
|
+
return redacted;
|
|
1990
|
+
});
|
|
1991
|
+
return changed ? { ...value, arrayValue: { values: next } } : value;
|
|
1992
|
+
}
|
|
1993
|
+
function redactPiiInOtlpAttributes(attributes, fields = NO_SPAN_PII_FIELDS, maxChars) {
|
|
1994
|
+
let next;
|
|
1995
|
+
for (let i = 0; i < attributes.length; i++) {
|
|
1996
|
+
const attr = attributes[i];
|
|
1997
|
+
if (!attr.value || !isSpanContentAttributeKey(attr.key, fields)) continue;
|
|
1998
|
+
const value = redactOtlpValue(attr.value, maxChars);
|
|
1999
|
+
if (value === attr.value) continue;
|
|
2000
|
+
next != null ? next : next = attributes.slice();
|
|
2001
|
+
next[i] = { ...attr, value };
|
|
2002
|
+
}
|
|
2003
|
+
return next != null ? next : attributes;
|
|
2004
|
+
}
|
|
2005
|
+
function redactPiiInOtlpSpan(span, fields = NO_SPAN_PII_FIELDS, maxChars) {
|
|
2006
|
+
var _a;
|
|
2007
|
+
const attributes = span.attributes && redactPiiInOtlpAttributes(span.attributes, fields, maxChars);
|
|
2008
|
+
const message = (_a = span.status) == null ? void 0 : _a.message;
|
|
2009
|
+
const redactedMessage = message === void 0 ? void 0 : redactBoundedContent(message, maxChars);
|
|
2010
|
+
if (attributes === span.attributes && redactedMessage === message) return span;
|
|
2011
|
+
const status = span.status && redactedMessage !== message ? { ...span.status, message: redactedMessage } : span.status;
|
|
2012
|
+
return { ...span, attributes, status };
|
|
2013
|
+
}
|
|
2014
|
+
function redactPiiInAttributeMap(attributes, fields = NO_SPAN_PII_FIELDS) {
|
|
2015
|
+
let next;
|
|
2016
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
2017
|
+
if (!isSpanContentAttributeKey(key, fields)) continue;
|
|
2018
|
+
let redacted = value;
|
|
2019
|
+
if (typeof value === "string") {
|
|
2020
|
+
redacted = redactSpanContent(value);
|
|
2021
|
+
} else if (Array.isArray(value)) {
|
|
2022
|
+
let changed = false;
|
|
2023
|
+
const items = value.map((item) => {
|
|
2024
|
+
if (typeof item !== "string") return item;
|
|
2025
|
+
const out = redactSpanContent(item);
|
|
2026
|
+
if (out !== item) changed = true;
|
|
2027
|
+
return out;
|
|
2028
|
+
});
|
|
2029
|
+
if (changed) redacted = items;
|
|
2030
|
+
}
|
|
2031
|
+
if (redacted === value) continue;
|
|
2032
|
+
next != null ? next : next = { ...attributes };
|
|
2033
|
+
next[key] = redacted;
|
|
2034
|
+
}
|
|
2035
|
+
return next;
|
|
2036
|
+
}
|
|
2037
|
+
var MASK_FAILED = "<MASK FAILED>";
|
|
2038
|
+
function isPlainObject(value) {
|
|
2039
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
|
|
2040
|
+
const proto = Object.getPrototypeOf(value);
|
|
2041
|
+
return proto === Object.prototype || proto === null;
|
|
2042
|
+
}
|
|
2043
|
+
function isThenable(value) {
|
|
2044
|
+
return typeof value === "object" && value !== null && "then" in value && typeof value.then === "function";
|
|
2045
|
+
}
|
|
2046
|
+
function warn(prefix, context7, reason) {
|
|
2047
|
+
rateLimitedLog(
|
|
2048
|
+
`${prefix}.mask_failed`,
|
|
2049
|
+
() => console.warn(
|
|
2050
|
+
`${prefix} mask function failed on ${context7.kind} ${context7.field} (${reason}); sending ${MASK_FAILED} in its place.`
|
|
2051
|
+
)
|
|
2052
|
+
);
|
|
2053
|
+
}
|
|
2054
|
+
function jsonCopy(value) {
|
|
2055
|
+
const json = JSON.stringify(value);
|
|
2056
|
+
if (json === void 0) throw new TypeError("not JSON-serializable");
|
|
2057
|
+
return JSON.parse(json);
|
|
2058
|
+
}
|
|
2059
|
+
function failed(shape) {
|
|
2060
|
+
if (shape === "string") return MASK_FAILED;
|
|
2061
|
+
if (shape === "object") return { error: MASK_FAILED };
|
|
2062
|
+
return [];
|
|
2063
|
+
}
|
|
2064
|
+
function maskValue(value, context7, mask, prefix) {
|
|
2065
|
+
const shape = typeof value === "string" ? "string" : Array.isArray(value) ? "array" : "object";
|
|
2066
|
+
try {
|
|
2067
|
+
const result = mask(shape === "string" ? value : jsonCopy(value), context7);
|
|
2068
|
+
if (isThenable(result)) {
|
|
2069
|
+
Promise.resolve(result).catch(() => {
|
|
2070
|
+
});
|
|
2071
|
+
warn(prefix, context7, "it returned a promise; mask must be synchronous");
|
|
2072
|
+
return failed(shape);
|
|
2073
|
+
}
|
|
2074
|
+
if (shape === "string") {
|
|
2075
|
+
if (typeof result === "string") return result;
|
|
2076
|
+
} else {
|
|
2077
|
+
const copy = jsonCopy(result);
|
|
2078
|
+
if (shape === "array" ? Array.isArray(copy) : isPlainObject(copy)) return copy;
|
|
2079
|
+
}
|
|
2080
|
+
warn(prefix, context7, `it returned a value that is not ${shape === "string" ? "a string" : `an ${shape}`}`);
|
|
2081
|
+
} catch (err) {
|
|
2082
|
+
warn(prefix, context7, err instanceof Error ? err.name : "threw");
|
|
2083
|
+
}
|
|
2084
|
+
return failed(shape);
|
|
2085
|
+
}
|
|
2086
|
+
function maskOtlpValue(value, context7, mask, prefix) {
|
|
2087
|
+
var _a;
|
|
2088
|
+
if (typeof value.stringValue === "string") {
|
|
2089
|
+
const masked = maskValue(value.stringValue, context7, mask, prefix);
|
|
2090
|
+
return typeof masked === "string" && masked !== value.stringValue ? { ...value, stringValue: masked } : value;
|
|
2091
|
+
}
|
|
2092
|
+
const values = (_a = value.arrayValue) == null ? void 0 : _a.values;
|
|
2093
|
+
if (!values) return value;
|
|
2094
|
+
let changed = false;
|
|
2095
|
+
const next = values.map((item) => {
|
|
2096
|
+
const masked = maskOtlpValue(item, context7, mask, prefix);
|
|
2097
|
+
if (masked !== item) changed = true;
|
|
2098
|
+
return masked;
|
|
2099
|
+
});
|
|
2100
|
+
return changed ? { ...value, arrayValue: { values: next } } : value;
|
|
2101
|
+
}
|
|
2102
|
+
function maskSpanStatusMessage(message, mask, logPrefix = "[raindrop-ai/core]") {
|
|
2103
|
+
if (!mask) return message;
|
|
2104
|
+
const masked = maskValue(message, { kind: "span", field: "status.message" }, mask, logPrefix);
|
|
2105
|
+
return typeof masked === "string" ? masked : MASK_FAILED;
|
|
2106
|
+
}
|
|
2107
|
+
function maskOtlpAttributes(attributes, mask, fields, logPrefix = "[raindrop-ai/core]") {
|
|
2108
|
+
if (!mask) return attributes;
|
|
2109
|
+
let next;
|
|
2110
|
+
for (let i = 0; i < attributes.length; i++) {
|
|
2111
|
+
const attr = attributes[i];
|
|
2112
|
+
if (!attr.value || !isSpanContentAttributeKey(attr.key, fields)) continue;
|
|
2113
|
+
const value = maskOtlpValue(attr.value, { kind: "span", field: attr.key }, mask, logPrefix);
|
|
2114
|
+
if (value === attr.value) continue;
|
|
2115
|
+
next != null ? next : next = attributes.slice();
|
|
2116
|
+
next[i] = { ...attr, value };
|
|
2117
|
+
}
|
|
2118
|
+
return next != null ? next : attributes;
|
|
2119
|
+
}
|
|
2120
|
+
function maskOtlpSpan(span, mask, fields, logPrefix = "[raindrop-ai/core]") {
|
|
2121
|
+
var _a;
|
|
2122
|
+
if (!mask) return span;
|
|
2123
|
+
const attributes = span.attributes && maskOtlpAttributes(span.attributes, mask, fields, logPrefix);
|
|
2124
|
+
const message = (_a = span.status) == null ? void 0 : _a.message;
|
|
2125
|
+
const nextMessage = message === void 0 ? void 0 : maskSpanStatusMessage(message, mask, logPrefix);
|
|
2126
|
+
if (attributes === span.attributes && nextMessage === message) return span;
|
|
2127
|
+
const status = span.status && nextMessage !== message ? { ...span.status, message: nextMessage } : span.status;
|
|
2128
|
+
return { ...span, attributes, status };
|
|
2129
|
+
}
|
|
2130
|
+
function maskAttributeMap(attributes, mask, fields, logPrefix = "[raindrop-ai/core]") {
|
|
2131
|
+
if (!mask) return void 0;
|
|
2132
|
+
let next;
|
|
2133
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
2134
|
+
if (!isSpanContentAttributeKey(key, fields)) continue;
|
|
2135
|
+
const context7 = { kind: "span", field: key };
|
|
2136
|
+
let masked = value;
|
|
2137
|
+
if (typeof value === "string") {
|
|
2138
|
+
masked = maskValue(value, context7, mask, logPrefix);
|
|
2139
|
+
} else if (Array.isArray(value)) {
|
|
2140
|
+
let changed = false;
|
|
2141
|
+
const items = value.map((item) => {
|
|
2142
|
+
if (typeof item !== "string") return item;
|
|
2143
|
+
const out = maskValue(item, context7, mask, logPrefix);
|
|
2144
|
+
if (out !== item) changed = true;
|
|
2145
|
+
return out;
|
|
2146
|
+
});
|
|
2147
|
+
if (changed) masked = items;
|
|
2148
|
+
}
|
|
2149
|
+
if (masked === value) continue;
|
|
2150
|
+
next != null ? next : next = { ...attributes };
|
|
2151
|
+
next[key] = masked;
|
|
2152
|
+
}
|
|
2153
|
+
return next;
|
|
1601
2154
|
}
|
|
1602
2155
|
var PROTECTED_LOCATIONS = new Set(
|
|
1603
2156
|
[
|
|
@@ -1901,211 +2454,6 @@ var DEFAULT_REDACT_ATTRIBUTE_KEYS = [
|
|
|
1901
2454
|
"ai.response.providerMetadata"
|
|
1902
2455
|
];
|
|
1903
2456
|
var REDACT_JSON_ATTRIBUTE_KEYS = new Set(DEFAULT_REDACT_ATTRIBUTE_KEYS);
|
|
1904
|
-
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)$/;
|
|
1905
|
-
var CONTENT_KEYS = /* @__PURE__ */ new Set([
|
|
1906
|
-
"ai.prompt.system",
|
|
1907
|
-
"ai.subagent.result",
|
|
1908
|
-
"agent.session.title",
|
|
1909
|
-
// Failed tool calls carry the tool's output in their error text.
|
|
1910
|
-
"error.message",
|
|
1911
|
-
"exception.message",
|
|
1912
|
-
"exception.stacktrace"
|
|
1913
|
-
]);
|
|
1914
|
-
var NON_CONTENT_PREFIXES = [
|
|
1915
|
-
"traceloop.association.properties.",
|
|
1916
|
-
"ai.telemetry.metadata.",
|
|
1917
|
-
"ai.settings.context.",
|
|
1918
|
-
"raindrop.app."
|
|
1919
|
-
];
|
|
1920
|
-
var JSON_SIMPLE_ESCAPES = {
|
|
1921
|
-
'"': '"',
|
|
1922
|
-
"\\": "\\",
|
|
1923
|
-
"/": "/",
|
|
1924
|
-
b: "\b",
|
|
1925
|
-
f: "\f",
|
|
1926
|
-
n: "\n",
|
|
1927
|
-
r: "\r",
|
|
1928
|
-
t: " "
|
|
1929
|
-
};
|
|
1930
|
-
function decodeJsonEscapes(text) {
|
|
1931
|
-
if (!text.includes("\\")) return text;
|
|
1932
|
-
let out = "";
|
|
1933
|
-
for (let i = 0; i < text.length; i++) {
|
|
1934
|
-
const ch = text[i];
|
|
1935
|
-
if (ch !== "\\" || i + 1 >= text.length) {
|
|
1936
|
-
out += ch;
|
|
1937
|
-
continue;
|
|
1938
|
-
}
|
|
1939
|
-
const next = text[i + 1];
|
|
1940
|
-
const simple = JSON_SIMPLE_ESCAPES[next];
|
|
1941
|
-
if (simple !== void 0) {
|
|
1942
|
-
out += simple;
|
|
1943
|
-
i += 1;
|
|
1944
|
-
} else if (next === "u" && /^[0-9a-fA-F]{4}$/.test(text.slice(i + 2, i + 6))) {
|
|
1945
|
-
out += String.fromCharCode(Number.parseInt(text.slice(i + 2, i + 6), 16));
|
|
1946
|
-
i += 5;
|
|
1947
|
-
} else {
|
|
1948
|
-
out += ch;
|
|
1949
|
-
}
|
|
1950
|
-
}
|
|
1951
|
-
return out;
|
|
1952
|
-
}
|
|
1953
|
-
function jsonStringBody(value) {
|
|
1954
|
-
return JSON.stringify(value).slice(1, -1);
|
|
1955
|
-
}
|
|
1956
|
-
function redactStringToken(token) {
|
|
1957
|
-
const decoded = decodeJsonEscapes(token.slice(1, -1));
|
|
1958
|
-
const redacted = redactPiiText(decoded);
|
|
1959
|
-
return redacted === decoded ? token : `"${jsonStringBody(redacted)}"`;
|
|
1960
|
-
}
|
|
1961
|
-
function redactLooseJsonText(text) {
|
|
1962
|
-
if (text.startsWith('"')) {
|
|
1963
|
-
const decoded2 = decodeJsonEscapes(text.slice(1));
|
|
1964
|
-
const redacted2 = redactPiiText(decoded2);
|
|
1965
|
-
return redacted2 === decoded2 ? text : `"${jsonStringBody(redacted2)}`;
|
|
1966
|
-
}
|
|
1967
|
-
const decoded = decodeJsonEscapes(text);
|
|
1968
|
-
const redacted = redactPiiText(decoded);
|
|
1969
|
-
return redacted === decoded ? text : redacted;
|
|
1970
|
-
}
|
|
1971
|
-
function stringTokenEnd(text, start) {
|
|
1972
|
-
for (let i = start + 1; i < text.length; i++) {
|
|
1973
|
-
const ch = text[i];
|
|
1974
|
-
if (ch === "\\") i += 1;
|
|
1975
|
-
else if (ch === '"') return i + 1;
|
|
1976
|
-
}
|
|
1977
|
-
return -1;
|
|
1978
|
-
}
|
|
1979
|
-
function redactJsonLike(text, complete) {
|
|
1980
|
-
let out = "";
|
|
1981
|
-
let looseStart = 0;
|
|
1982
|
-
const flushLoose = (end) => {
|
|
1983
|
-
if (end > looseStart) {
|
|
1984
|
-
const loose = text.slice(looseStart, end);
|
|
1985
|
-
out += complete ? loose : redactLooseJsonText(loose);
|
|
1986
|
-
}
|
|
1987
|
-
};
|
|
1988
|
-
let i = text.indexOf('"');
|
|
1989
|
-
while (i !== -1) {
|
|
1990
|
-
const end = stringTokenEnd(text, i);
|
|
1991
|
-
if (end === -1) break;
|
|
1992
|
-
flushLoose(i);
|
|
1993
|
-
let after = end;
|
|
1994
|
-
while (after < text.length && /\s/.test(text[after])) after += 1;
|
|
1995
|
-
const token = text.slice(i, end);
|
|
1996
|
-
out += complete && text[after] === ":" ? token : redactStringToken(token);
|
|
1997
|
-
looseStart = end;
|
|
1998
|
-
i = text.indexOf('"', end);
|
|
1999
|
-
}
|
|
2000
|
-
if (i === -1) {
|
|
2001
|
-
flushLoose(text.length);
|
|
2002
|
-
} else {
|
|
2003
|
-
flushLoose(i);
|
|
2004
|
-
looseStart = i;
|
|
2005
|
-
flushLoose(text.length);
|
|
2006
|
-
}
|
|
2007
|
-
return out;
|
|
2008
|
-
}
|
|
2009
|
-
function redactSpanContent(text) {
|
|
2010
|
-
const head = text.trimStart()[0];
|
|
2011
|
-
if (head !== "{" && head !== "[" && head !== '"') return redactPiiText(text);
|
|
2012
|
-
let complete = true;
|
|
2013
|
-
try {
|
|
2014
|
-
JSON.parse(text);
|
|
2015
|
-
} catch (e) {
|
|
2016
|
-
complete = false;
|
|
2017
|
-
}
|
|
2018
|
-
return redactJsonLike(text, complete);
|
|
2019
|
-
}
|
|
2020
|
-
var NO_SPAN_PII_FIELDS = { exact: /* @__PURE__ */ new Set(), prefixes: [] };
|
|
2021
|
-
function compileSpanPiiFields(names, logPrefix = "[raindrop-ai/core]") {
|
|
2022
|
-
if (!Array.isArray(names) || names.length === 0) return NO_SPAN_PII_FIELDS;
|
|
2023
|
-
const exact = /* @__PURE__ */ new Set();
|
|
2024
|
-
const prefixes = [];
|
|
2025
|
-
for (const name of names) {
|
|
2026
|
-
const valid = typeof name === "string" && !/\s/.test(name) && /^[^*]+\*?$/.test(name);
|
|
2027
|
-
if (!valid) {
|
|
2028
|
-
rateLimitedLog(
|
|
2029
|
-
`${logPrefix}.pii_span_field_invalid`,
|
|
2030
|
-
() => console.warn(
|
|
2031
|
-
`${logPrefix} redactPiiFields: ignoring invalid span attribute ${JSON.stringify(name)}`
|
|
2032
|
-
)
|
|
2033
|
-
);
|
|
2034
|
-
continue;
|
|
2035
|
-
}
|
|
2036
|
-
if (name.endsWith("*")) prefixes.push(name.slice(0, -1));
|
|
2037
|
-
else exact.add(name);
|
|
2038
|
-
}
|
|
2039
|
-
return { exact, prefixes };
|
|
2040
|
-
}
|
|
2041
|
-
function isCallerSelected(key, fields) {
|
|
2042
|
-
return fields.exact.has(key) || fields.prefixes.some((prefix) => key.startsWith(prefix));
|
|
2043
|
-
}
|
|
2044
|
-
function isSpanContentAttributeKey(key, fields = NO_SPAN_PII_FIELDS) {
|
|
2045
|
-
if (isCallerSelected(key, fields)) return true;
|
|
2046
|
-
if (NON_CONTENT_PREFIXES.some((prefix) => key.startsWith(prefix))) return false;
|
|
2047
|
-
return CONTENT_KEYS.has(key) || CONTENT_KEY_SUFFIX.test(key);
|
|
2048
|
-
}
|
|
2049
|
-
function redactOtlpValue(value) {
|
|
2050
|
-
var _a;
|
|
2051
|
-
if (typeof value.stringValue === "string") {
|
|
2052
|
-
const redacted = redactSpanContent(value.stringValue);
|
|
2053
|
-
return redacted === value.stringValue ? value : { ...value, stringValue: redacted };
|
|
2054
|
-
}
|
|
2055
|
-
const values = (_a = value.arrayValue) == null ? void 0 : _a.values;
|
|
2056
|
-
if (!values) return value;
|
|
2057
|
-
let changed = false;
|
|
2058
|
-
const next = values.map((item) => {
|
|
2059
|
-
const redacted = redactOtlpValue(item);
|
|
2060
|
-
if (redacted !== item) changed = true;
|
|
2061
|
-
return redacted;
|
|
2062
|
-
});
|
|
2063
|
-
return changed ? { ...value, arrayValue: { values: next } } : value;
|
|
2064
|
-
}
|
|
2065
|
-
function redactPiiInOtlpAttributes(attributes, fields = NO_SPAN_PII_FIELDS) {
|
|
2066
|
-
let next;
|
|
2067
|
-
for (let i = 0; i < attributes.length; i++) {
|
|
2068
|
-
const attr = attributes[i];
|
|
2069
|
-
if (!attr.value || !isSpanContentAttributeKey(attr.key, fields)) continue;
|
|
2070
|
-
const value = redactOtlpValue(attr.value);
|
|
2071
|
-
if (value === attr.value) continue;
|
|
2072
|
-
next != null ? next : next = attributes.slice();
|
|
2073
|
-
next[i] = { ...attr, value };
|
|
2074
|
-
}
|
|
2075
|
-
return next != null ? next : attributes;
|
|
2076
|
-
}
|
|
2077
|
-
function redactPiiInOtlpSpan(span, fields = NO_SPAN_PII_FIELDS) {
|
|
2078
|
-
var _a;
|
|
2079
|
-
const attributes = span.attributes && redactPiiInOtlpAttributes(span.attributes, fields);
|
|
2080
|
-
const message = (_a = span.status) == null ? void 0 : _a.message;
|
|
2081
|
-
const redactedMessage = message === void 0 ? void 0 : redactSpanContent(message);
|
|
2082
|
-
if (attributes === span.attributes && redactedMessage === message) return span;
|
|
2083
|
-
const status = span.status && redactedMessage !== message ? { ...span.status, message: redactedMessage } : span.status;
|
|
2084
|
-
return { ...span, attributes, status };
|
|
2085
|
-
}
|
|
2086
|
-
function redactPiiInAttributeMap(attributes, fields = NO_SPAN_PII_FIELDS) {
|
|
2087
|
-
let next;
|
|
2088
|
-
for (const [key, value] of Object.entries(attributes)) {
|
|
2089
|
-
if (!isSpanContentAttributeKey(key, fields)) continue;
|
|
2090
|
-
let redacted = value;
|
|
2091
|
-
if (typeof value === "string") {
|
|
2092
|
-
redacted = redactSpanContent(value);
|
|
2093
|
-
} else if (Array.isArray(value)) {
|
|
2094
|
-
let changed = false;
|
|
2095
|
-
const items = value.map((item) => {
|
|
2096
|
-
if (typeof item !== "string") return item;
|
|
2097
|
-
const out = redactSpanContent(item);
|
|
2098
|
-
if (out !== item) changed = true;
|
|
2099
|
-
return out;
|
|
2100
|
-
});
|
|
2101
|
-
if (changed) redacted = items;
|
|
2102
|
-
}
|
|
2103
|
-
if (redacted === value) continue;
|
|
2104
|
-
next != null ? next : next = { ...attributes };
|
|
2105
|
-
next[key] = redacted;
|
|
2106
|
-
}
|
|
2107
|
-
return next;
|
|
2108
|
-
}
|
|
2109
2457
|
var UNDELIVERED = Object.freeze({
|
|
2110
2458
|
delivered: false,
|
|
2111
2459
|
timedOut: false,
|
|
@@ -2392,17 +2740,17 @@ var ReplayRoutingSpanExporter = class {
|
|
|
2392
2740
|
return;
|
|
2393
2741
|
}
|
|
2394
2742
|
let remaining = replayGroups.size + (normalSpans.length > 0 ? 1 : 0);
|
|
2395
|
-
let
|
|
2743
|
+
let failed2 = false;
|
|
2396
2744
|
let firstError;
|
|
2397
2745
|
const finish = (result) => {
|
|
2398
2746
|
if (result.code !== EXPORT_SUCCESS) {
|
|
2399
|
-
|
|
2747
|
+
failed2 = true;
|
|
2400
2748
|
firstError != null ? firstError : firstError = result.error;
|
|
2401
2749
|
}
|
|
2402
2750
|
remaining -= 1;
|
|
2403
2751
|
if (remaining === 0) {
|
|
2404
2752
|
resultCallback(
|
|
2405
|
-
firstError ? { code: EXPORT_FAILED, error: firstError } : { code:
|
|
2753
|
+
firstError ? { code: EXPORT_FAILED, error: firstError } : { code: failed2 ? EXPORT_FAILED : EXPORT_SUCCESS }
|
|
2406
2754
|
);
|
|
2407
2755
|
}
|
|
2408
2756
|
};
|
|
@@ -2804,7 +3152,7 @@ function formatEndpoint2(endpoint) {
|
|
|
2804
3152
|
// package.json
|
|
2805
3153
|
var package_default = {
|
|
2806
3154
|
name: "raindrop-ai",
|
|
2807
|
-
version: "1.0.
|
|
3155
|
+
version: "1.0.9",
|
|
2808
3156
|
main: "dist/index.js",
|
|
2809
3157
|
module: "dist/index.mjs",
|
|
2810
3158
|
types: "dist/index.d.ts",
|
|
@@ -3021,6 +3369,7 @@ var DirectTraceShipper = class {
|
|
|
3021
3369
|
this.redactTracePii = opts.redactTracePii;
|
|
3022
3370
|
this.remotePiiConfig = opts.remotePiiConfig;
|
|
3023
3371
|
this.spanPiiFields = opts.spanPiiFields;
|
|
3372
|
+
this.mask = opts.mask;
|
|
3024
3373
|
this.flushIntervalMs = (_d = opts.flushIntervalMs) != null ? _d : 1e3;
|
|
3025
3374
|
this.maxBatchSize = (_e = opts.maxBatchSize) != null ? _e : 50;
|
|
3026
3375
|
this.maxQueueSize = (_f = opts.maxQueueSize) != null ? _f : 5e3;
|
|
@@ -3127,7 +3476,7 @@ var DirectTraceShipper = class {
|
|
|
3127
3476
|
const mirrorUrl = (replayDestination == null ? void 0 : replayDestination.kind) === "workshop" ? replayDestination.url : replayDestination ? void 0 : this.localDebuggerUrl;
|
|
3128
3477
|
const mirrored = mirrorUrl && this.redactsNow() ? this.redactSpanPii(span) : span;
|
|
3129
3478
|
if (mirrorUrl && mirrored) {
|
|
3130
|
-
const body = buildExportTraceServiceRequest2([mirrored]);
|
|
3479
|
+
const body = buildExportTraceServiceRequest2([maskOtlpSpan(mirrored, this.mask, this.spanPiiFields, "[raindrop]")]);
|
|
3131
3480
|
const mirror = mirrorTraceExportToLocalDebugger(body, {
|
|
3132
3481
|
baseUrl: mirrorUrl,
|
|
3133
3482
|
debug: false,
|
|
@@ -3153,7 +3502,7 @@ var DirectTraceShipper = class {
|
|
|
3153
3502
|
/** The span with PII redacted from its input and output; undefined if redaction failed. */
|
|
3154
3503
|
redactSpanPii(span) {
|
|
3155
3504
|
try {
|
|
3156
|
-
return redactPiiInOtlpSpan(span, this.spanPiiFields);
|
|
3505
|
+
return redactPiiInOtlpSpan(span, this.spanPiiFields, resolveMaxTextFieldChars(void 0));
|
|
3157
3506
|
} catch (e) {
|
|
3158
3507
|
return void 0;
|
|
3159
3508
|
}
|
|
@@ -3252,10 +3601,10 @@ var DirectTraceShipper = class {
|
|
|
3252
3601
|
if (!replayDestination && !this.cloudEnabled) continue;
|
|
3253
3602
|
if ((replayDestination == null ? void 0 : replayDestination.kind) === "workshop") continue;
|
|
3254
3603
|
const spans = queuedSpans.map((q) => q.span);
|
|
3255
|
-
const outgoing = redactPii ? spans.flatMap((span) => {
|
|
3604
|
+
const outgoing = (redactPii ? spans.flatMap((span) => {
|
|
3256
3605
|
var _a2;
|
|
3257
3606
|
return (_a2 = this.redactSpanPii(span)) != null ? _a2 : [];
|
|
3258
|
-
}) : spans;
|
|
3607
|
+
}) : spans).map((span) => maskOtlpSpan(span, this.mask, this.spanPiiFields, "[raindrop]"));
|
|
3259
3608
|
if (outgoing.length === 0) continue;
|
|
3260
3609
|
const body = buildExportTraceServiceRequest2(outgoing);
|
|
3261
3610
|
const url = replayDestination ? replayTraceUrl(replayDestination.url) : `${this.baseUrl}traces`;
|
|
@@ -3388,6 +3737,34 @@ function redactSpanPii(span, fields) {
|
|
|
3388
3737
|
copyReplayTraceDestination(span, view);
|
|
3389
3738
|
return view;
|
|
3390
3739
|
}
|
|
3740
|
+
function maskSpan(span, mask, fields) {
|
|
3741
|
+
const attributes = maskAttributeMap(span.attributes, mask, fields, "[raindrop]");
|
|
3742
|
+
const message = span.status.message;
|
|
3743
|
+
const nextMessage = message === void 0 ? void 0 : maskSpanStatusMessage(message, mask, "[raindrop]");
|
|
3744
|
+
let eventsChanged = false;
|
|
3745
|
+
const events = span.events.map((event) => {
|
|
3746
|
+
const eventAttributes = event.attributes && maskAttributeMap(event.attributes, mask, fields, "[raindrop]");
|
|
3747
|
+
if (!eventAttributes) return event;
|
|
3748
|
+
eventsChanged = true;
|
|
3749
|
+
return { ...event, attributes: eventAttributes };
|
|
3750
|
+
});
|
|
3751
|
+
if (!attributes && nextMessage === message && !eventsChanged) return span;
|
|
3752
|
+
const view = Object.create(span);
|
|
3753
|
+
if (attributes) {
|
|
3754
|
+
Object.defineProperty(view, "attributes", { value: attributes, enumerable: true });
|
|
3755
|
+
}
|
|
3756
|
+
if (nextMessage !== message) {
|
|
3757
|
+
Object.defineProperty(view, "status", {
|
|
3758
|
+
value: { ...span.status, message: nextMessage },
|
|
3759
|
+
enumerable: true
|
|
3760
|
+
});
|
|
3761
|
+
}
|
|
3762
|
+
if (eventsChanged) {
|
|
3763
|
+
Object.defineProperty(view, "events", { value: events, enumerable: true });
|
|
3764
|
+
}
|
|
3765
|
+
copyReplayTraceDestination(span, view);
|
|
3766
|
+
return view;
|
|
3767
|
+
}
|
|
3391
3768
|
var PiiRedactingSpanExporter = class {
|
|
3392
3769
|
constructor(inner, options) {
|
|
3393
3770
|
this.inner = inner;
|
|
@@ -3396,7 +3773,7 @@ var PiiRedactingSpanExporter = class {
|
|
|
3396
3773
|
this.pending = /* @__PURE__ */ new Set();
|
|
3397
3774
|
}
|
|
3398
3775
|
export(spans, resultCallback) {
|
|
3399
|
-
const { local, remote, apiUrl, writeKey, spanFields } = this.options;
|
|
3776
|
+
const { local, remote, apiUrl, writeKey, spanFields, mask } = this.options;
|
|
3400
3777
|
const exportContext = import_api2.context.active();
|
|
3401
3778
|
const run = (redact) => {
|
|
3402
3779
|
let outgoing = spans;
|
|
@@ -3409,6 +3786,7 @@ var PiiRedactingSpanExporter = class {
|
|
|
3409
3786
|
}
|
|
3410
3787
|
}
|
|
3411
3788
|
}
|
|
3789
|
+
if (mask) outgoing = outgoing.map((span) => maskSpan(span, mask, spanFields));
|
|
3412
3790
|
try {
|
|
3413
3791
|
import_api2.context.with(exportContext, () => this.inner.export(outgoing, resultCallback));
|
|
3414
3792
|
} catch (e) {
|
|
@@ -5810,6 +6188,7 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
|
|
|
5810
6188
|
redactTracePii,
|
|
5811
6189
|
redactPiiFields,
|
|
5812
6190
|
remotePiiConfig,
|
|
6191
|
+
mask,
|
|
5813
6192
|
...otherOptions
|
|
5814
6193
|
} = options;
|
|
5815
6194
|
const cloudEnabledResolved = cloudEnabled != null ? cloudEnabled : true;
|
|
@@ -5828,7 +6207,8 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
|
|
|
5828
6207
|
remote: remotePiiConfig,
|
|
5829
6208
|
apiUrl: directEndpoint != null ? directEndpoint : apiUrl,
|
|
5830
6209
|
writeKey: cloudEnabledResolved ? writeKey : void 0,
|
|
5831
|
-
spanFields: spanPiiFields
|
|
6210
|
+
spanFields: spanPiiFields,
|
|
6211
|
+
mask: typeof mask === "function" ? mask : void 0
|
|
5832
6212
|
};
|
|
5833
6213
|
if (localTracePii === true) {
|
|
5834
6214
|
requestLocalTracePiiRedaction(piiRedaction2.apiUrl, piiRedaction2.writeKey);
|
|
@@ -5865,7 +6245,8 @@ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
|
|
|
5865
6245
|
flushTimeoutMs,
|
|
5866
6246
|
redactTracePii: localTracePii,
|
|
5867
6247
|
remotePiiConfig,
|
|
5868
|
-
spanPiiFields
|
|
6248
|
+
spanPiiFields,
|
|
6249
|
+
mask: piiRedaction2.mask
|
|
5869
6250
|
}) : void 0;
|
|
5870
6251
|
let traceloopInitialized = false;
|
|
5871
6252
|
let claimedPipeline = false;
|