UNPKG

@tanstack/ai

Version:

Type-safe TypeScript AI SDK for streaming chat, tool calling, agents, structured outputs, and multimodal generation.

26 lines (25 loc) • 851 B
//#region src/byok/scrub.ts function maskKey(key) { if (key.length <= 4) return "••"; return key.slice(-4); } /** * Replace each of `secrets` in `text` with `[redacted]`: the raw value, its * JSON-escaped form, and its URL-encoded form. A secret shorter than 6 * characters is left alone, so a tiny value does not redact common words. */ function scrubSecrets(text, secrets) { const forms = /* @__PURE__ */ new Set(); for (const secret of secrets) { if (secret.length < 6) continue; forms.add(secret); forms.add(JSON.stringify(secret).slice(1, -1)); forms.add(encodeURIComponent(secret)); } let scrubbed = text; for (const form of [...forms].sort((a, b) => b.length - a.length)) scrubbed = scrubbed.split(form).join("[redacted]"); return scrubbed; } //#endregion export { maskKey, scrubSecrets }; //# sourceMappingURL=scrub.js.map