@posthog/ai 8.22.1 → 8.22.3

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 +19 -12
  2. package/dist/adk/index.cjs +76 -28
  3. package/dist/adk/index.cjs.map +1 -1
  4. package/dist/adk/index.mjs +76 -28
  5. package/dist/adk/index.mjs.map +1 -1
  6. package/dist/anthropic/index.cjs +77 -29
  7. package/dist/anthropic/index.cjs.map +1 -1
  8. package/dist/anthropic/index.mjs +77 -29
  9. package/dist/anthropic/index.mjs.map +1 -1
  10. package/dist/claude-agent-sdk/index.cjs +76 -28
  11. package/dist/claude-agent-sdk/index.cjs.map +1 -1
  12. package/dist/claude-agent-sdk/index.mjs +76 -28
  13. package/dist/claude-agent-sdk/index.mjs.map +1 -1
  14. package/dist/evaluations/index.cjs +1 -1
  15. package/dist/evaluations/index.cjs.map +1 -1
  16. package/dist/evaluations/index.d.ts +1 -1
  17. package/dist/evaluations/index.mjs +1 -1
  18. package/dist/evaluations/index.mjs.map +1 -1
  19. package/dist/gemini/index.cjs +80 -29
  20. package/dist/gemini/index.cjs.map +1 -1
  21. package/dist/gemini/index.mjs +80 -29
  22. package/dist/gemini/index.mjs.map +1 -1
  23. package/dist/genkit/index.cjs +84 -41
  24. package/dist/genkit/index.cjs.map +1 -1
  25. package/dist/genkit/index.mjs +84 -41
  26. package/dist/genkit/index.mjs.map +1 -1
  27. package/dist/index.cjs +77 -29
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.mjs +77 -29
  30. package/dist/index.mjs.map +1 -1
  31. package/dist/langchain/index.cjs +76 -28
  32. package/dist/langchain/index.cjs.map +1 -1
  33. package/dist/langchain/index.mjs +77 -29
  34. package/dist/langchain/index.mjs.map +1 -1
  35. package/dist/langchain/middleware/index.cjs +76 -28
  36. package/dist/langchain/middleware/index.cjs.map +1 -1
  37. package/dist/langchain/middleware/index.mjs +77 -29
  38. package/dist/langchain/middleware/index.mjs.map +1 -1
  39. package/dist/openai/index.cjs +77 -29
  40. package/dist/openai/index.cjs.map +1 -1
  41. package/dist/openai/index.mjs +77 -29
  42. package/dist/openai/index.mjs.map +1 -1
  43. package/dist/openai-agents/index.cjs +26 -1
  44. package/dist/openai-agents/index.cjs.map +1 -1
  45. package/dist/openai-agents/index.mjs +26 -1
  46. package/dist/openai-agents/index.mjs.map +1 -1
  47. package/dist/otel/index.browser.cjs +51 -2
  48. package/dist/otel/index.browser.cjs.map +1 -1
  49. package/dist/otel/index.browser.mjs +51 -2
  50. package/dist/otel/index.browser.mjs.map +1 -1
  51. package/dist/otel/index.cjs +51 -2
  52. package/dist/otel/index.cjs.map +1 -1
  53. package/dist/otel/index.mjs +51 -2
  54. package/dist/otel/index.mjs.map +1 -1
  55. package/dist/vercel/index.cjs +77 -29
  56. package/dist/vercel/index.cjs.map +1 -1
  57. package/dist/vercel/index.mjs +77 -29
  58. package/dist/vercel/index.mjs.map +1 -1
  59. package/package.json +2 -2
package/dist/index.cjs CHANGED
@@ -9,6 +9,81 @@ const isObject = (value) => {
9
9
  return value !== null && typeof value === "object" && !Array.isArray(value);
10
10
  };
11
11
  //#endregion
12
+ //#region src/mcpCredentials.ts
13
+ const MCP_CREDENTIAL_FIELDS = ["headers", "authorization"];
14
+ const MCP_TOOL_TYPES = /* @__PURE__ */ new Set(["mcp", "mcp_server"]);
15
+ const MCP_PROVIDER_TOOL_IDS = /* @__PURE__ */ new Set([
16
+ "openai.mcp",
17
+ "xai.mcp",
18
+ "google.mcp_server"
19
+ ]);
20
+ const isMcpProviderTool = (tool) => (tool.type === "provider" || tool.type === "provider-defined") && typeof tool.id === "string" && MCP_PROVIDER_TOOL_IDS.has(tool.id);
21
+ const withoutMcpCredentials = (config) => {
22
+ const redacted = { ...config };
23
+ for (const field of MCP_CREDENTIAL_FIELDS) if (field in redacted) redacted[field] = "[REDACTED]";
24
+ return redacted;
25
+ };
26
+ const normalizeKey = (key) => key.toLowerCase().replace(/[-_]/g, "");
27
+ const isPlainObject = (value) => {
28
+ if (!isObject(value)) return false;
29
+ const prototype = Object.getPrototypeOf(value);
30
+ return prototype === Object.prototype || prototype === null;
31
+ };
32
+ /**
33
+ * Replaces the value of every key in `keys` (normalized) with `[REDACTED]`, through plain objects and arrays.
34
+ * Class instances, such as the MCP client inside an `mcpToTool()` tool, are returned as they are.
35
+ */
36
+ function redactKeys(value, keys) {
37
+ if (Array.isArray(value)) return value.map((item) => redactKeys(item, keys));
38
+ if (!isPlainObject(value)) return value;
39
+ return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, keys.has(normalizeKey(key)) ? "[REDACTED]" : redactKeys(item, keys)]));
40
+ }
41
+ const GEMINI_TOOL_FIELDS = new Set([
42
+ "codeExecution",
43
+ "computerUse",
44
+ "enterpriseWebSearch",
45
+ "exaAiSearch",
46
+ "fileSearch",
47
+ "functionDeclarations",
48
+ "googleMaps",
49
+ "googleSearch",
50
+ "googleSearchRetrieval",
51
+ "mcpServers",
52
+ "parallelAiSearch",
53
+ "retrieval",
54
+ "urlContext"
55
+ ].map(normalizeKey));
56
+ const GEMINI_SCHEMA_FIELD = normalizeKey("functionDeclarations");
57
+ const GEMINI_CREDENTIAL_KEYS = new Set([
58
+ "apiAuth",
59
+ "authConfig",
60
+ "apiKey",
61
+ "headers"
62
+ ].map(normalizeKey));
63
+ const isGeminiTool = (tool) => Object.keys(tool).map(normalizeKey).some((key) => key !== GEMINI_SCHEMA_FIELD && GEMINI_TOOL_FIELDS.has(key));
64
+ /**
65
+ * Masks the credential keys under every field of a `@google/genai` tool except its function declarations.
66
+ * A class-based tool, such as `mcpToTool(client)`, holds a live client with its auth headers, so only a stub is kept.
67
+ */
68
+ function redactGeminiToolDefinition(tool) {
69
+ if (!isPlainObject(tool)) return isObject(tool) ? { type: "callable_tool" } : tool;
70
+ 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)]));
71
+ }
72
+ /** Hides the credentials of a remote MCP or Gemini tool definition; everything else is kept as sent. */
73
+ function redactMcpToolDefinition(tool) {
74
+ if (!isObject(tool)) return tool;
75
+ if (typeof tool.type === "string" && MCP_TOOL_TYPES.has(tool.type)) return withoutMcpCredentials(tool);
76
+ if (isMcpProviderTool(tool) && isObject(tool.args)) return {
77
+ ...tool,
78
+ args: withoutMcpCredentials(tool.args)
79
+ };
80
+ if (isPlainObject(tool) && isGeminiTool(tool)) return redactGeminiToolDefinition(tool);
81
+ return tool;
82
+ }
83
+ function redactMcpToolCredentials(tools) {
84
+ return Array.isArray(tools) ? tools.map(redactMcpToolDefinition) : tools;
85
+ }
86
+ //#endregion
12
87
  //#region src/captureAiEvent.ts
13
88
  /** @internal */
14
89
  function isFullAiCaptureEnabled(client) {
@@ -471,7 +546,7 @@ const extractAvailableToolCalls = (provider, params) => {
471
546
  if (params.tools) return params.tools;
472
547
  return null;
473
548
  } else if (provider === "gemini") {
474
- if (params.config && params.config.tools) return params.config.tools;
549
+ if (params.config && Array.isArray(params.config.tools)) return params.config.tools.map(redactGeminiToolDefinition);
475
550
  return null;
476
551
  } else if (provider === "openai") {
477
552
  if (params.tools) return params.tools;
@@ -497,7 +572,7 @@ function sanitizeValues(obj) {
497
572
  }
498
573
  //#endregion
499
574
  //#region package.json
500
- var version = "8.22.1";
575
+ var version = "8.22.3";
501
576
  //#endregion
502
577
  //#region src/serializeError.ts
503
578
  const DEFAULT_MAX_DEPTH = 3;
@@ -636,33 +711,6 @@ function truncateStack(stack) {
636
711
  return [...lines.slice(0, MAX_STACK_LINES), "... (truncated)"].join("\n");
637
712
  }
638
713
  //#endregion
639
- //#region src/mcpCredentials.ts
640
- const MCP_CREDENTIAL_FIELDS = ["headers", "authorization"];
641
- const MCP_PROVIDER_TOOL_IDS = /* @__PURE__ */ new Set([
642
- "openai.mcp",
643
- "xai.mcp",
644
- "google.mcp_server"
645
- ]);
646
- const isMcpProviderTool = (tool) => (tool.type === "provider" || tool.type === "provider-defined") && typeof tool.id === "string" && MCP_PROVIDER_TOOL_IDS.has(tool.id);
647
- const withoutMcpCredentials = (config) => {
648
- const redacted = { ...config };
649
- for (const field of MCP_CREDENTIAL_FIELDS) if (field in redacted) redacted[field] = "[REDACTED]";
650
- return redacted;
651
- };
652
- /** Hides the credentials of a remote MCP tool definition; everything else is kept as sent. */
653
- function redactMcpToolDefinition(tool) {
654
- if (!isObject(tool)) return tool;
655
- if (tool.type === "mcp") return withoutMcpCredentials(tool);
656
- if (isMcpProviderTool(tool) && isObject(tool.args)) return {
657
- ...tool,
658
- args: withoutMcpCredentials(tool.args)
659
- };
660
- return tool;
661
- }
662
- function redactMcpToolCredentials(tools) {
663
- return Array.isArray(tools) ? tools.map(redactMcpToolDefinition) : tools;
664
- }
665
- //#endregion
666
714
  //#region src/gatewayWarning.ts
667
715
  const POSTHOG_AI_GATEWAY_HOSTS = [
668
716
  "gateway.posthog.com",