@posthog/ai 8.22.4 → 8.22.5
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/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/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 +3 -3
package/dist/gemini/index.cjs
CHANGED
|
@@ -117,20 +117,52 @@ const withoutMcpCredentials = (config) => {
|
|
|
117
117
|
for (const field of MCP_CREDENTIAL_FIELDS) if (field in redacted) redacted[field] = "[REDACTED]";
|
|
118
118
|
return redacted;
|
|
119
119
|
};
|
|
120
|
-
const normalizeKey = (key) => key.toLowerCase().replace(/[-_]/g, "");
|
|
120
|
+
const normalizeKey = (key) => key.toLowerCase().replace(/[-_\s]/g, "");
|
|
121
121
|
const isPlainObject = (value) => {
|
|
122
122
|
if (!isObject(value)) return false;
|
|
123
123
|
const prototype = Object.getPrototypeOf(value);
|
|
124
124
|
return prototype === Object.prototype || prototype === null;
|
|
125
125
|
};
|
|
126
|
+
const MAX_REDACT_DEPTH = 64;
|
|
126
127
|
/**
|
|
127
|
-
* Replaces the value of every key
|
|
128
|
-
*
|
|
128
|
+
* Replaces the value of every key that `isCredentialKey` accepts (normalized) with `[REDACTED]`, through plain
|
|
129
|
+
* 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
|
|
130
|
+
* `[Truncated]`. Class instances, such as the MCP client inside an `mcpToTool()` tool, are returned as they are.
|
|
129
131
|
*/
|
|
130
|
-
function redactKeys(value,
|
|
131
|
-
if (
|
|
132
|
+
function redactKeys(value, isCredentialKey, depth = 0) {
|
|
133
|
+
if (depth > MAX_REDACT_DEPTH) return "[Truncated]";
|
|
134
|
+
if (typeof value === "string") return redactJsonString(value, isCredentialKey, depth);
|
|
135
|
+
if (Array.isArray(value)) return value.map((item) => redactKeys(item, isCredentialKey, depth + 1));
|
|
132
136
|
if (!isPlainObject(value)) return value;
|
|
133
|
-
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key,
|
|
137
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, isCredentialKey(normalizeKey(key)) ? "[REDACTED]" : redactKeys(item, isCredentialKey, depth + 1)]));
|
|
138
|
+
}
|
|
139
|
+
const QUOTED_KEY = /["']([^"'\\\s:]{1,128})\\*["']\s*:/g;
|
|
140
|
+
const FORM_FIELD = /(?:^|[?&#;\s'"])([^&=?#;\s'"]+)=/g;
|
|
141
|
+
function namesCredential(text, isCredentialKey) {
|
|
142
|
+
for (const pattern of [QUOTED_KEY, FORM_FIELD]) for (const [, name] of text.matchAll(pattern)) if (isCredentialKey(normalizeKey(name))) return true;
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
function redactJsonString(value, isCredentialKey, depth) {
|
|
146
|
+
const namesOne = namesCredential(value, isCredentialKey);
|
|
147
|
+
const trimmed = value.trim();
|
|
148
|
+
if (/^[[{"]/.test(trimmed)) {
|
|
149
|
+
let parsed;
|
|
150
|
+
try {
|
|
151
|
+
parsed = JSON.parse(trimmed);
|
|
152
|
+
} catch {
|
|
153
|
+
return namesOne ? "[REDACTED]" : value;
|
|
154
|
+
}
|
|
155
|
+
const redacted = JSON.stringify(redactKeys(parsed, isCredentialKey, depth + 1));
|
|
156
|
+
return namesOne || !serializesTo(parsed, redacted) ? redacted : value;
|
|
157
|
+
}
|
|
158
|
+
return namesOne ? "[REDACTED]" : value;
|
|
159
|
+
}
|
|
160
|
+
function serializesTo(value, json) {
|
|
161
|
+
try {
|
|
162
|
+
return JSON.stringify(value) === json;
|
|
163
|
+
} catch {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
134
166
|
}
|
|
135
167
|
const GEMINI_TOOL_FIELDS = new Set([
|
|
136
168
|
"codeExecution",
|
|
@@ -161,7 +193,7 @@ const isGeminiTool = (tool) => Object.keys(tool).map(normalizeKey).some((key) =>
|
|
|
161
193
|
*/
|
|
162
194
|
function redactGeminiToolDefinition(tool) {
|
|
163
195
|
if (!isPlainObject(tool)) return isObject(tool) ? { type: "callable_tool" } : tool;
|
|
164
|
-
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)]));
|
|
196
|
+
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))]));
|
|
165
197
|
}
|
|
166
198
|
/** Hides the credentials of a remote MCP or Gemini tool definition; everything else is kept as sent. */
|
|
167
199
|
function redactMcpToolDefinition(tool) {
|
|
@@ -619,7 +651,7 @@ function addDefaults(params) {
|
|
|
619
651
|
}
|
|
620
652
|
//#endregion
|
|
621
653
|
//#region package.json
|
|
622
|
-
var version = "8.22.
|
|
654
|
+
var version = "8.22.5";
|
|
623
655
|
//#endregion
|
|
624
656
|
//#region src/serializeError.ts
|
|
625
657
|
const DEFAULT_MAX_DEPTH = 3;
|