@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
package/README.md CHANGED
@@ -258,7 +258,7 @@ polarity; categorical inputs are lists of keys, usable as `"safe" in categories`
258
258
  arithmetic, comparisons, membership, Boolean operators, conditionals, `number`, `min`, `max`, and
259
259
  `abs`. They accept 1–16 inputs and up to 1,024 characters. Aliases must be unique lowercase
260
260
  identifiers (`[a-z][a-z0-9_]{0,31}`), cannot be formula keywords/functions, and must occur in the
261
- expression. Nested composites and numeric composite `step` values are unsupported.
261
+ expression. Item formulas require reported item scorers. Numeric composite `step` values are unsupported.
262
262
 
263
263
  Calculation mode and output kind are fixed after creation. Pass the complete `composition` to
264
264
  `createVersion`, alongside `config` and optionally `baseVersion`. Source updates never change
@@ -284,6 +284,15 @@ is open creates it again and counts as new usage for a reported result. Older re
284
284
  without outcomes expose `status: null` and `errorCode: null`. Save and restore calculation
285
285
  declarations with the same serialization and recovery methods as reported results.
286
286
 
287
+ ### Experiment scores
288
+
289
+ Use a composite scorer with `scope: 'experiment'` to calculate one score for a completed
290
+ run. Each input references an item scorer version and specifies a statistic such as
291
+ `pass_rate` or `mean`. To set a default for future runs, create or publish the scorer
292
+ with `applyToSuiteKeys: ['agent-ci']` and create runs with `suiteKey: 'agent-ci'`.
293
+ Pass `experimentScorerVersionId` to select a specific version for a run. PostHog pins
294
+ the version on first creation and computes the score from accepted item results.
295
+
287
296
  | Operation | Required scopes |
288
297
  | -------------------------------------- | -------------------------------------------- |
289
298
  | Dataset reads/writes | `dataset:read` / `dataset:write` |
@@ -3,7 +3,7 @@ let _google_adk = require("@google/adk");
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.23.0";
7
7
  //#endregion
8
8
  //#region src/typeGuards.ts
9
9
  const isObject = (value) => {
@@ -24,20 +24,52 @@ const withoutMcpCredentials = (config) => {
24
24
  for (const field of MCP_CREDENTIAL_FIELDS) if (field in redacted) redacted[field] = "[REDACTED]";
25
25
  return redacted;
26
26
  };
27
- const normalizeKey = (key) => key.toLowerCase().replace(/[-_]/g, "");
27
+ const normalizeKey = (key) => key.toLowerCase().replace(/[-_\s]/g, "");
28
28
  const isPlainObject = (value) => {
29
29
  if (!isObject(value)) return false;
30
30
  const prototype = Object.getPrototypeOf(value);
31
31
  return prototype === Object.prototype || prototype === null;
32
32
  };
33
+ const MAX_REDACT_DEPTH = 64;
33
34
  /**
34
- * Replaces the value of every key in `keys` (normalized) with `[REDACTED]`, through plain objects and arrays.
35
- * Class instances, such as the MCP client inside an `mcpToTool()` tool, are returned as they are.
35
+ * Replaces the value of every key that `isCredentialKey` accepts (normalized) with `[REDACTED]`, through plain
36
+ * 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
37
+ * `[Truncated]`. Class instances, such as the MCP client inside an `mcpToTool()` tool, are returned as they are.
36
38
  */
37
- function redactKeys(value, keys) {
38
- if (Array.isArray(value)) return value.map((item) => redactKeys(item, keys));
39
+ function redactKeys(value, isCredentialKey, depth = 0) {
40
+ if (depth > MAX_REDACT_DEPTH) return "[Truncated]";
41
+ if (typeof value === "string") return redactJsonString(value, isCredentialKey, depth);
42
+ if (Array.isArray(value)) return value.map((item) => redactKeys(item, isCredentialKey, depth + 1));
39
43
  if (!isPlainObject(value)) return value;
40
- return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, keys.has(normalizeKey(key)) ? "[REDACTED]" : redactKeys(item, keys)]));
44
+ return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, isCredentialKey(normalizeKey(key)) ? "[REDACTED]" : redactKeys(item, isCredentialKey, depth + 1)]));
45
+ }
46
+ const QUOTED_KEY = /["']([^"'\\\s:]{1,128})\\*["']\s*:/g;
47
+ const FORM_FIELD = /(?:^|[?&#;\s'"])([^&=?#;\s'"]+)=/g;
48
+ function namesCredential(text, isCredentialKey) {
49
+ for (const pattern of [QUOTED_KEY, FORM_FIELD]) for (const [, name] of text.matchAll(pattern)) if (isCredentialKey(normalizeKey(name))) return true;
50
+ return false;
51
+ }
52
+ function redactJsonString(value, isCredentialKey, depth) {
53
+ const namesOne = namesCredential(value, isCredentialKey);
54
+ const trimmed = value.trim();
55
+ if (/^[[{"]/.test(trimmed)) {
56
+ let parsed;
57
+ try {
58
+ parsed = JSON.parse(trimmed);
59
+ } catch {
60
+ return namesOne ? "[REDACTED]" : value;
61
+ }
62
+ const redacted = JSON.stringify(redactKeys(parsed, isCredentialKey, depth + 1));
63
+ return namesOne || !serializesTo(parsed, redacted) ? redacted : value;
64
+ }
65
+ return namesOne ? "[REDACTED]" : value;
66
+ }
67
+ function serializesTo(value, json) {
68
+ try {
69
+ return JSON.stringify(value) === json;
70
+ } catch {
71
+ return false;
72
+ }
41
73
  }
42
74
  const GEMINI_TOOL_FIELDS = new Set([
43
75
  "codeExecution",
@@ -68,7 +100,7 @@ const isGeminiTool = (tool) => Object.keys(tool).map(normalizeKey).some((key) =>
68
100
  */
69
101
  function redactGeminiToolDefinition(tool) {
70
102
  if (!isPlainObject(tool)) return isObject(tool) ? { type: "callable_tool" } : tool;
71
- 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)]));
103
+ 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))]));
72
104
  }
73
105
  /** Hides the credentials of a remote MCP or Gemini tool definition; everything else is kept as sent. */
74
106
  function redactMcpToolDefinition(tool) {