@posthog/ai 8.22.4 → 8.23.0
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 +10 -1
- package/dist/adk/index.cjs +40 -8
- package/dist/adk/index.cjs.map +1 -1
- package/dist/adk/index.mjs +40 -8
- package/dist/adk/index.mjs.map +1 -1
- package/dist/anthropic/index.cjs +40 -8
- package/dist/anthropic/index.cjs.map +1 -1
- package/dist/anthropic/index.mjs +40 -8
- package/dist/anthropic/index.mjs.map +1 -1
- package/dist/claude-agent-sdk/index.cjs +40 -8
- package/dist/claude-agent-sdk/index.cjs.map +1 -1
- package/dist/claude-agent-sdk/index.mjs +40 -8
- package/dist/claude-agent-sdk/index.mjs.map +1 -1
- package/dist/evaluations/index.cjs +87 -24
- package/dist/evaluations/index.cjs.map +1 -1
- package/dist/evaluations/index.d.ts +39 -7
- package/dist/evaluations/index.mjs +87 -24
- package/dist/evaluations/index.mjs.map +1 -1
- package/dist/gemini/index.cjs +40 -8
- package/dist/gemini/index.cjs.map +1 -1
- package/dist/gemini/index.mjs +40 -8
- package/dist/gemini/index.mjs.map +1 -1
- package/dist/genkit/index.cjs +86 -19
- package/dist/genkit/index.cjs.map +1 -1
- package/dist/genkit/index.mjs +86 -19
- package/dist/genkit/index.mjs.map +1 -1
- package/dist/index.cjs +40 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +40 -8
- package/dist/index.mjs.map +1 -1
- package/dist/langchain/index.cjs +40 -8
- package/dist/langchain/index.cjs.map +1 -1
- package/dist/langchain/index.mjs +40 -8
- package/dist/langchain/index.mjs.map +1 -1
- package/dist/langchain/middleware/index.cjs +40 -8
- package/dist/langchain/middleware/index.cjs.map +1 -1
- package/dist/langchain/middleware/index.mjs +40 -8
- package/dist/langchain/middleware/index.mjs.map +1 -1
- package/dist/openai/index.cjs +40 -8
- package/dist/openai/index.cjs.map +1 -1
- package/dist/openai/index.mjs +40 -8
- package/dist/openai/index.mjs.map +1 -1
- package/dist/openai-agents/index.cjs +2 -2
- package/dist/openai-agents/index.cjs.map +1 -1
- package/dist/openai-agents/index.mjs +2 -2
- package/dist/openai-agents/index.mjs.map +1 -1
- package/dist/otel/index.browser.cjs +39 -7
- package/dist/otel/index.browser.cjs.map +1 -1
- package/dist/otel/index.browser.mjs +39 -7
- package/dist/otel/index.browser.mjs.map +1 -1
- package/dist/otel/index.cjs +39 -7
- package/dist/otel/index.cjs.map +1 -1
- package/dist/otel/index.mjs +39 -7
- package/dist/otel/index.mjs.map +1 -1
- package/dist/vercel/index.cjs +40 -8
- package/dist/vercel/index.cjs.map +1 -1
- package/dist/vercel/index.mjs +40 -8
- package/dist/vercel/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/anthropic/index.cjs
CHANGED
|
@@ -48,20 +48,52 @@ const withoutMcpCredentials = (config) => {
|
|
|
48
48
|
for (const field of MCP_CREDENTIAL_FIELDS) if (field in redacted) redacted[field] = "[REDACTED]";
|
|
49
49
|
return redacted;
|
|
50
50
|
};
|
|
51
|
-
const normalizeKey = (key) => key.toLowerCase().replace(/[-_]/g, "");
|
|
51
|
+
const normalizeKey = (key) => key.toLowerCase().replace(/[-_\s]/g, "");
|
|
52
52
|
const isPlainObject = (value) => {
|
|
53
53
|
if (!isObject(value)) return false;
|
|
54
54
|
const prototype = Object.getPrototypeOf(value);
|
|
55
55
|
return prototype === Object.prototype || prototype === null;
|
|
56
56
|
};
|
|
57
|
+
const MAX_REDACT_DEPTH = 64;
|
|
57
58
|
/**
|
|
58
|
-
* Replaces the value of every key
|
|
59
|
-
*
|
|
59
|
+
* Replaces the value of every key that `isCredentialKey` accepts (normalized) with `[REDACTED]`, through plain
|
|
60
|
+
* objects, arrays and JSON strings. Other strings that name a credential key or form field are replaced whole, and values nested deeper than 64 levels become
|
|
61
|
+
* `[Truncated]`. Class instances, such as the MCP client inside an `mcpToTool()` tool, are returned as they are.
|
|
60
62
|
*/
|
|
61
|
-
function redactKeys(value,
|
|
62
|
-
if (
|
|
63
|
+
function redactKeys(value, isCredentialKey, depth = 0) {
|
|
64
|
+
if (depth > MAX_REDACT_DEPTH) return "[Truncated]";
|
|
65
|
+
if (typeof value === "string") return redactJsonString(value, isCredentialKey, depth);
|
|
66
|
+
if (Array.isArray(value)) return value.map((item) => redactKeys(item, isCredentialKey, depth + 1));
|
|
63
67
|
if (!isPlainObject(value)) return value;
|
|
64
|
-
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key,
|
|
68
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, isCredentialKey(normalizeKey(key)) ? "[REDACTED]" : redactKeys(item, isCredentialKey, depth + 1)]));
|
|
69
|
+
}
|
|
70
|
+
const QUOTED_KEY = /["']([^"'\\\s:]{1,128})\\*["']\s*:/g;
|
|
71
|
+
const FORM_FIELD = /(?:^|[?&#;\s'"])([^&=?#;\s'"]+)=/g;
|
|
72
|
+
function namesCredential(text, isCredentialKey) {
|
|
73
|
+
for (const pattern of [QUOTED_KEY, FORM_FIELD]) for (const [, name] of text.matchAll(pattern)) if (isCredentialKey(normalizeKey(name))) return true;
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
function redactJsonString(value, isCredentialKey, depth) {
|
|
77
|
+
const namesOne = namesCredential(value, isCredentialKey);
|
|
78
|
+
const trimmed = value.trim();
|
|
79
|
+
if (/^[[{"]/.test(trimmed)) {
|
|
80
|
+
let parsed;
|
|
81
|
+
try {
|
|
82
|
+
parsed = JSON.parse(trimmed);
|
|
83
|
+
} catch {
|
|
84
|
+
return namesOne ? "[REDACTED]" : value;
|
|
85
|
+
}
|
|
86
|
+
const redacted = JSON.stringify(redactKeys(parsed, isCredentialKey, depth + 1));
|
|
87
|
+
return namesOne || !serializesTo(parsed, redacted) ? redacted : value;
|
|
88
|
+
}
|
|
89
|
+
return namesOne ? "[REDACTED]" : value;
|
|
90
|
+
}
|
|
91
|
+
function serializesTo(value, json) {
|
|
92
|
+
try {
|
|
93
|
+
return JSON.stringify(value) === json;
|
|
94
|
+
} catch {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
65
97
|
}
|
|
66
98
|
const GEMINI_TOOL_FIELDS = new Set([
|
|
67
99
|
"codeExecution",
|
|
@@ -92,7 +124,7 @@ const isGeminiTool = (tool) => Object.keys(tool).map(normalizeKey).some((key) =>
|
|
|
92
124
|
*/
|
|
93
125
|
function redactGeminiToolDefinition(tool) {
|
|
94
126
|
if (!isPlainObject(tool)) return isObject(tool) ? { type: "callable_tool" } : tool;
|
|
95
|
-
return Object.fromEntries(Object.entries(tool).map(([key, value]) => [key, normalizeKey(key) === GEMINI_SCHEMA_FIELD ? value : redactKeys((0, _posthog_core.toJsonSafeValue)(value), GEMINI_CREDENTIAL_KEYS)]));
|
|
127
|
+
return Object.fromEntries(Object.entries(tool).map(([key, value]) => [key, normalizeKey(key) === GEMINI_SCHEMA_FIELD ? value : redactKeys((0, _posthog_core.toJsonSafeValue)(value), (key) => GEMINI_CREDENTIAL_KEYS.has(key))]));
|
|
96
128
|
}
|
|
97
129
|
/** Hides the credentials of a remote MCP or Gemini tool definition; everything else is kept as sent. */
|
|
98
130
|
function redactMcpToolDefinition(tool) {
|
|
@@ -569,7 +601,7 @@ function addDefaults(params) {
|
|
|
569
601
|
}
|
|
570
602
|
//#endregion
|
|
571
603
|
//#region package.json
|
|
572
|
-
var version = "8.
|
|
604
|
+
var version = "8.23.0";
|
|
573
605
|
//#endregion
|
|
574
606
|
//#region src/serializeError.ts
|
|
575
607
|
const DEFAULT_MAX_DEPTH = 3;
|