@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.
Files changed (53) hide show
  1. package/dist/adk/index.cjs +40 -8
  2. package/dist/adk/index.cjs.map +1 -1
  3. package/dist/adk/index.mjs +40 -8
  4. package/dist/adk/index.mjs.map +1 -1
  5. package/dist/anthropic/index.cjs +40 -8
  6. package/dist/anthropic/index.cjs.map +1 -1
  7. package/dist/anthropic/index.mjs +40 -8
  8. package/dist/anthropic/index.mjs.map +1 -1
  9. package/dist/claude-agent-sdk/index.cjs +40 -8
  10. package/dist/claude-agent-sdk/index.cjs.map +1 -1
  11. package/dist/claude-agent-sdk/index.mjs +40 -8
  12. package/dist/claude-agent-sdk/index.mjs.map +1 -1
  13. package/dist/gemini/index.cjs +40 -8
  14. package/dist/gemini/index.cjs.map +1 -1
  15. package/dist/gemini/index.mjs +40 -8
  16. package/dist/gemini/index.mjs.map +1 -1
  17. package/dist/genkit/index.cjs +86 -19
  18. package/dist/genkit/index.cjs.map +1 -1
  19. package/dist/genkit/index.mjs +86 -19
  20. package/dist/genkit/index.mjs.map +1 -1
  21. package/dist/index.cjs +40 -8
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.mjs +40 -8
  24. package/dist/index.mjs.map +1 -1
  25. package/dist/langchain/index.cjs +40 -8
  26. package/dist/langchain/index.cjs.map +1 -1
  27. package/dist/langchain/index.mjs +40 -8
  28. package/dist/langchain/index.mjs.map +1 -1
  29. package/dist/langchain/middleware/index.cjs +40 -8
  30. package/dist/langchain/middleware/index.cjs.map +1 -1
  31. package/dist/langchain/middleware/index.mjs +40 -8
  32. package/dist/langchain/middleware/index.mjs.map +1 -1
  33. package/dist/openai/index.cjs +40 -8
  34. package/dist/openai/index.cjs.map +1 -1
  35. package/dist/openai/index.mjs +40 -8
  36. package/dist/openai/index.mjs.map +1 -1
  37. package/dist/openai-agents/index.cjs +2 -2
  38. package/dist/openai-agents/index.cjs.map +1 -1
  39. package/dist/openai-agents/index.mjs +2 -2
  40. package/dist/openai-agents/index.mjs.map +1 -1
  41. package/dist/otel/index.browser.cjs +39 -7
  42. package/dist/otel/index.browser.cjs.map +1 -1
  43. package/dist/otel/index.browser.mjs +39 -7
  44. package/dist/otel/index.browser.mjs.map +1 -1
  45. package/dist/otel/index.cjs +39 -7
  46. package/dist/otel/index.cjs.map +1 -1
  47. package/dist/otel/index.mjs +39 -7
  48. package/dist/otel/index.mjs.map +1 -1
  49. package/dist/vercel/index.cjs +40 -8
  50. package/dist/vercel/index.cjs.map +1 -1
  51. package/dist/vercel/index.mjs +40 -8
  52. package/dist/vercel/index.mjs.map +1 -1
  53. package/package.json +3 -3
@@ -3,7 +3,7 @@ let _anthropic_ai_claude_agent_sdk = require("@anthropic-ai/claude-agent-sdk");
3
3
  let uuid = require("uuid");
4
4
  let _posthog_core = require("@posthog/core");
5
5
  //#region package.json
6
- var version = "8.22.4";
6
+ var version = "8.22.5";
7
7
  //#endregion
8
8
  //#region src/captureAiEvent.ts
9
9
  /** @internal */
@@ -114,20 +114,52 @@ const withoutMcpCredentials = (config) => {
114
114
  for (const field of MCP_CREDENTIAL_FIELDS) if (field in redacted) redacted[field] = "[REDACTED]";
115
115
  return redacted;
116
116
  };
117
- const normalizeKey = (key) => key.toLowerCase().replace(/[-_]/g, "");
117
+ const normalizeKey = (key) => key.toLowerCase().replace(/[-_\s]/g, "");
118
118
  const isPlainObject = (value) => {
119
119
  if (!isObject(value)) return false;
120
120
  const prototype = Object.getPrototypeOf(value);
121
121
  return prototype === Object.prototype || prototype === null;
122
122
  };
123
+ const MAX_REDACT_DEPTH = 64;
123
124
  /**
124
- * Replaces the value of every key in `keys` (normalized) with `[REDACTED]`, through plain objects and arrays.
125
- * Class instances, such as the MCP client inside an `mcpToTool()` tool, are returned as they are.
125
+ * Replaces the value of every key that `isCredentialKey` accepts (normalized) with `[REDACTED]`, through plain
126
+ * 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
127
+ * `[Truncated]`. Class instances, such as the MCP client inside an `mcpToTool()` tool, are returned as they are.
126
128
  */
127
- function redactKeys(value, keys) {
128
- if (Array.isArray(value)) return value.map((item) => redactKeys(item, keys));
129
+ function redactKeys(value, isCredentialKey, depth = 0) {
130
+ if (depth > MAX_REDACT_DEPTH) return "[Truncated]";
131
+ if (typeof value === "string") return redactJsonString(value, isCredentialKey, depth);
132
+ if (Array.isArray(value)) return value.map((item) => redactKeys(item, isCredentialKey, depth + 1));
129
133
  if (!isPlainObject(value)) return value;
130
- return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, keys.has(normalizeKey(key)) ? "[REDACTED]" : redactKeys(item, keys)]));
134
+ return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, isCredentialKey(normalizeKey(key)) ? "[REDACTED]" : redactKeys(item, isCredentialKey, depth + 1)]));
135
+ }
136
+ const QUOTED_KEY = /["']([^"'\\\s:]{1,128})\\*["']\s*:/g;
137
+ const FORM_FIELD = /(?:^|[?&#;\s'"])([^&=?#;\s'"]+)=/g;
138
+ function namesCredential(text, isCredentialKey) {
139
+ for (const pattern of [QUOTED_KEY, FORM_FIELD]) for (const [, name] of text.matchAll(pattern)) if (isCredentialKey(normalizeKey(name))) return true;
140
+ return false;
141
+ }
142
+ function redactJsonString(value, isCredentialKey, depth) {
143
+ const namesOne = namesCredential(value, isCredentialKey);
144
+ const trimmed = value.trim();
145
+ if (/^[[{"]/.test(trimmed)) {
146
+ let parsed;
147
+ try {
148
+ parsed = JSON.parse(trimmed);
149
+ } catch {
150
+ return namesOne ? "[REDACTED]" : value;
151
+ }
152
+ const redacted = JSON.stringify(redactKeys(parsed, isCredentialKey, depth + 1));
153
+ return namesOne || !serializesTo(parsed, redacted) ? redacted : value;
154
+ }
155
+ return namesOne ? "[REDACTED]" : value;
156
+ }
157
+ function serializesTo(value, json) {
158
+ try {
159
+ return JSON.stringify(value) === json;
160
+ } catch {
161
+ return false;
162
+ }
131
163
  }
132
164
  const GEMINI_TOOL_FIELDS = new Set([
133
165
  "codeExecution",
@@ -158,7 +190,7 @@ const isGeminiTool = (tool) => Object.keys(tool).map(normalizeKey).some((key) =>
158
190
  */
159
191
  function redactGeminiToolDefinition(tool) {
160
192
  if (!isPlainObject(tool)) return isObject(tool) ? { type: "callable_tool" } : tool;
161
- 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)]));
193
+ 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))]));
162
194
  }
163
195
  /** Hides the credentials of a remote MCP or Gemini tool definition; everything else is kept as sent. */
164
196
  function redactMcpToolDefinition(tool) {