@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.
Files changed (59) hide show
  1. package/README.md +10 -1
  2. package/dist/adk/index.cjs +40 -8
  3. package/dist/adk/index.cjs.map +1 -1
  4. package/dist/adk/index.mjs +40 -8
  5. package/dist/adk/index.mjs.map +1 -1
  6. package/dist/anthropic/index.cjs +40 -8
  7. package/dist/anthropic/index.cjs.map +1 -1
  8. package/dist/anthropic/index.mjs +40 -8
  9. package/dist/anthropic/index.mjs.map +1 -1
  10. package/dist/claude-agent-sdk/index.cjs +40 -8
  11. package/dist/claude-agent-sdk/index.cjs.map +1 -1
  12. package/dist/claude-agent-sdk/index.mjs +40 -8
  13. package/dist/claude-agent-sdk/index.mjs.map +1 -1
  14. package/dist/evaluations/index.cjs +87 -24
  15. package/dist/evaluations/index.cjs.map +1 -1
  16. package/dist/evaluations/index.d.ts +39 -7
  17. package/dist/evaluations/index.mjs +87 -24
  18. package/dist/evaluations/index.mjs.map +1 -1
  19. package/dist/gemini/index.cjs +40 -8
  20. package/dist/gemini/index.cjs.map +1 -1
  21. package/dist/gemini/index.mjs +40 -8
  22. package/dist/gemini/index.mjs.map +1 -1
  23. package/dist/genkit/index.cjs +86 -19
  24. package/dist/genkit/index.cjs.map +1 -1
  25. package/dist/genkit/index.mjs +86 -19
  26. package/dist/genkit/index.mjs.map +1 -1
  27. package/dist/index.cjs +40 -8
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.mjs +40 -8
  30. package/dist/index.mjs.map +1 -1
  31. package/dist/langchain/index.cjs +40 -8
  32. package/dist/langchain/index.cjs.map +1 -1
  33. package/dist/langchain/index.mjs +40 -8
  34. package/dist/langchain/index.mjs.map +1 -1
  35. package/dist/langchain/middleware/index.cjs +40 -8
  36. package/dist/langchain/middleware/index.cjs.map +1 -1
  37. package/dist/langchain/middleware/index.mjs +40 -8
  38. package/dist/langchain/middleware/index.mjs.map +1 -1
  39. package/dist/openai/index.cjs +40 -8
  40. package/dist/openai/index.cjs.map +1 -1
  41. package/dist/openai/index.mjs +40 -8
  42. package/dist/openai/index.mjs.map +1 -1
  43. package/dist/openai-agents/index.cjs +2 -2
  44. package/dist/openai-agents/index.cjs.map +1 -1
  45. package/dist/openai-agents/index.mjs +2 -2
  46. package/dist/openai-agents/index.mjs.map +1 -1
  47. package/dist/otel/index.browser.cjs +39 -7
  48. package/dist/otel/index.browser.cjs.map +1 -1
  49. package/dist/otel/index.browser.mjs +39 -7
  50. package/dist/otel/index.browser.mjs.map +1 -1
  51. package/dist/otel/index.cjs +39 -7
  52. package/dist/otel/index.cjs.map +1 -1
  53. package/dist/otel/index.mjs +39 -7
  54. package/dist/otel/index.mjs.map +1 -1
  55. package/dist/vercel/index.cjs +40 -8
  56. package/dist/vercel/index.cjs.map +1 -1
  57. package/dist/vercel/index.mjs +40 -8
  58. package/dist/vercel/index.mjs.map +1 -1
  59. package/package.json +1 -1
@@ -20,20 +20,52 @@ const withoutMcpCredentials = (config) => {
20
20
  for (const field of MCP_CREDENTIAL_FIELDS) if (field in redacted) redacted[field] = "[REDACTED]";
21
21
  return redacted;
22
22
  };
23
- const normalizeKey = (key) => key.toLowerCase().replace(/[-_]/g, "");
23
+ const normalizeKey = (key) => key.toLowerCase().replace(/[-_\s]/g, "");
24
24
  const isPlainObject = (value) => {
25
25
  if (!isObject(value)) return false;
26
26
  const prototype = Object.getPrototypeOf(value);
27
27
  return prototype === Object.prototype || prototype === null;
28
28
  };
29
+ const MAX_REDACT_DEPTH = 64;
29
30
  /**
30
- * Replaces the value of every key in `keys` (normalized) with `[REDACTED]`, through plain objects and arrays.
31
- * Class instances, such as the MCP client inside an `mcpToTool()` tool, are returned as they are.
31
+ * Replaces the value of every key that `isCredentialKey` accepts (normalized) with `[REDACTED]`, through plain
32
+ * 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
33
+ * `[Truncated]`. Class instances, such as the MCP client inside an `mcpToTool()` tool, are returned as they are.
32
34
  */
33
- function redactKeys(value, keys) {
34
- if (Array.isArray(value)) return value.map((item) => redactKeys(item, keys));
35
+ function redactKeys(value, isCredentialKey, depth = 0) {
36
+ if (depth > MAX_REDACT_DEPTH) return "[Truncated]";
37
+ if (typeof value === "string") return redactJsonString(value, isCredentialKey, depth);
38
+ if (Array.isArray(value)) return value.map((item) => redactKeys(item, isCredentialKey, depth + 1));
35
39
  if (!isPlainObject(value)) return value;
36
- return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, keys.has(normalizeKey(key)) ? "[REDACTED]" : redactKeys(item, keys)]));
40
+ return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, isCredentialKey(normalizeKey(key)) ? "[REDACTED]" : redactKeys(item, isCredentialKey, depth + 1)]));
41
+ }
42
+ const QUOTED_KEY = /["']([^"'\\\s:]{1,128})\\*["']\s*:/g;
43
+ const FORM_FIELD = /(?:^|[?&#;\s'"])([^&=?#;\s'"]+)=/g;
44
+ function namesCredential(text, isCredentialKey) {
45
+ for (const pattern of [QUOTED_KEY, FORM_FIELD]) for (const [, name] of text.matchAll(pattern)) if (isCredentialKey(normalizeKey(name))) return true;
46
+ return false;
47
+ }
48
+ function redactJsonString(value, isCredentialKey, depth) {
49
+ const namesOne = namesCredential(value, isCredentialKey);
50
+ const trimmed = value.trim();
51
+ if (/^[[{"]/.test(trimmed)) {
52
+ let parsed;
53
+ try {
54
+ parsed = JSON.parse(trimmed);
55
+ } catch {
56
+ return namesOne ? "[REDACTED]" : value;
57
+ }
58
+ const redacted = JSON.stringify(redactKeys(parsed, isCredentialKey, depth + 1));
59
+ return namesOne || !serializesTo(parsed, redacted) ? redacted : value;
60
+ }
61
+ return namesOne ? "[REDACTED]" : value;
62
+ }
63
+ function serializesTo(value, json) {
64
+ try {
65
+ return JSON.stringify(value) === json;
66
+ } catch {
67
+ return false;
68
+ }
37
69
  }
38
70
  const GEMINI_TOOL_FIELDS = new Set([
39
71
  "codeExecution",
@@ -64,7 +96,7 @@ const isGeminiTool = (tool) => Object.keys(tool).map(normalizeKey).some((key) =>
64
96
  */
65
97
  function redactGeminiToolDefinition(tool) {
66
98
  if (!isPlainObject(tool)) return isObject(tool) ? { type: "callable_tool" } : tool;
67
- return Object.fromEntries(Object.entries(tool).map(([key, value]) => [key, normalizeKey(key) === GEMINI_SCHEMA_FIELD ? value : redactKeys(toJsonSafeValue(value), GEMINI_CREDENTIAL_KEYS)]));
99
+ return Object.fromEntries(Object.entries(tool).map(([key, value]) => [key, normalizeKey(key) === GEMINI_SCHEMA_FIELD ? value : redactKeys(toJsonSafeValue(value), (key) => GEMINI_CREDENTIAL_KEYS.has(key))]));
68
100
  }
69
101
  /** Hides the credentials of a remote MCP or Gemini tool definition; everything else is kept as sent. */
70
102
  function redactMcpToolDefinition(tool) {
@@ -434,7 +466,7 @@ function sanitizeValues(obj) {
434
466
  }
435
467
  //#endregion
436
468
  //#region package.json
437
- var version = "8.22.4";
469
+ var version = "8.23.0";
438
470
  //#endregion
439
471
  //#region src/serializeError.ts
440
472
  const DEFAULT_MAX_DEPTH = 3;