@posthog/ai 8.22.1 → 8.22.2

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 +76 -28
  2. package/dist/adk/index.cjs.map +1 -1
  3. package/dist/adk/index.mjs +76 -28
  4. package/dist/adk/index.mjs.map +1 -1
  5. package/dist/anthropic/index.cjs +77 -29
  6. package/dist/anthropic/index.cjs.map +1 -1
  7. package/dist/anthropic/index.mjs +77 -29
  8. package/dist/anthropic/index.mjs.map +1 -1
  9. package/dist/claude-agent-sdk/index.cjs +76 -28
  10. package/dist/claude-agent-sdk/index.cjs.map +1 -1
  11. package/dist/claude-agent-sdk/index.mjs +76 -28
  12. package/dist/claude-agent-sdk/index.mjs.map +1 -1
  13. package/dist/gemini/index.cjs +77 -29
  14. package/dist/gemini/index.cjs.map +1 -1
  15. package/dist/gemini/index.mjs +77 -29
  16. package/dist/gemini/index.mjs.map +1 -1
  17. package/dist/genkit/index.cjs +84 -41
  18. package/dist/genkit/index.cjs.map +1 -1
  19. package/dist/genkit/index.mjs +84 -41
  20. package/dist/genkit/index.mjs.map +1 -1
  21. package/dist/index.cjs +77 -29
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.mjs +77 -29
  24. package/dist/index.mjs.map +1 -1
  25. package/dist/langchain/index.cjs +76 -28
  26. package/dist/langchain/index.cjs.map +1 -1
  27. package/dist/langchain/index.mjs +77 -29
  28. package/dist/langchain/index.mjs.map +1 -1
  29. package/dist/langchain/middleware/index.cjs +76 -28
  30. package/dist/langchain/middleware/index.cjs.map +1 -1
  31. package/dist/langchain/middleware/index.mjs +77 -29
  32. package/dist/langchain/middleware/index.mjs.map +1 -1
  33. package/dist/openai/index.cjs +77 -29
  34. package/dist/openai/index.cjs.map +1 -1
  35. package/dist/openai/index.mjs +77 -29
  36. package/dist/openai/index.mjs.map +1 -1
  37. package/dist/openai-agents/index.cjs +26 -1
  38. package/dist/openai-agents/index.cjs.map +1 -1
  39. package/dist/openai-agents/index.mjs +26 -1
  40. package/dist/openai-agents/index.mjs.map +1 -1
  41. package/dist/otel/index.browser.cjs +51 -2
  42. package/dist/otel/index.browser.cjs.map +1 -1
  43. package/dist/otel/index.browser.mjs +51 -2
  44. package/dist/otel/index.browser.mjs.map +1 -1
  45. package/dist/otel/index.cjs +51 -2
  46. package/dist/otel/index.cjs.map +1 -1
  47. package/dist/otel/index.mjs +51 -2
  48. package/dist/otel/index.mjs.map +1 -1
  49. package/dist/vercel/index.cjs +77 -29
  50. package/dist/vercel/index.cjs.map +1 -1
  51. package/dist/vercel/index.mjs +77 -29
  52. package/dist/vercel/index.mjs.map +1 -1
  53. package/package.json +2 -2
@@ -14,6 +14,81 @@ const isObject = (value) => {
14
14
  return value !== null && typeof value === "object" && !Array.isArray(value);
15
15
  };
16
16
  //#endregion
17
+ //#region src/mcpCredentials.ts
18
+ const MCP_CREDENTIAL_FIELDS = ["headers", "authorization"];
19
+ const MCP_TOOL_TYPES = /* @__PURE__ */ new Set(["mcp", "mcp_server"]);
20
+ const MCP_PROVIDER_TOOL_IDS = /* @__PURE__ */ new Set([
21
+ "openai.mcp",
22
+ "xai.mcp",
23
+ "google.mcp_server"
24
+ ]);
25
+ const isMcpProviderTool = (tool) => (tool.type === "provider" || tool.type === "provider-defined") && typeof tool.id === "string" && MCP_PROVIDER_TOOL_IDS.has(tool.id);
26
+ const withoutMcpCredentials = (config) => {
27
+ const redacted = { ...config };
28
+ for (const field of MCP_CREDENTIAL_FIELDS) if (field in redacted) redacted[field] = "[REDACTED]";
29
+ return redacted;
30
+ };
31
+ const normalizeKey = (key) => key.toLowerCase().replace(/[-_]/g, "");
32
+ const isPlainObject = (value) => {
33
+ if (!isObject(value)) return false;
34
+ const prototype = Object.getPrototypeOf(value);
35
+ return prototype === Object.prototype || prototype === null;
36
+ };
37
+ /**
38
+ * Replaces the value of every key in `keys` (normalized) with `[REDACTED]`, through plain objects and arrays.
39
+ * Class instances, such as the MCP client inside an `mcpToTool()` tool, are returned as they are.
40
+ */
41
+ function redactKeys(value, keys) {
42
+ if (Array.isArray(value)) return value.map((item) => redactKeys(item, keys));
43
+ if (!isPlainObject(value)) return value;
44
+ return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, keys.has(normalizeKey(key)) ? "[REDACTED]" : redactKeys(item, keys)]));
45
+ }
46
+ const GEMINI_TOOL_FIELDS = new Set([
47
+ "codeExecution",
48
+ "computerUse",
49
+ "enterpriseWebSearch",
50
+ "exaAiSearch",
51
+ "fileSearch",
52
+ "functionDeclarations",
53
+ "googleMaps",
54
+ "googleSearch",
55
+ "googleSearchRetrieval",
56
+ "mcpServers",
57
+ "parallelAiSearch",
58
+ "retrieval",
59
+ "urlContext"
60
+ ].map(normalizeKey));
61
+ const GEMINI_SCHEMA_FIELD = normalizeKey("functionDeclarations");
62
+ const GEMINI_CREDENTIAL_KEYS = new Set([
63
+ "apiAuth",
64
+ "authConfig",
65
+ "apiKey",
66
+ "headers"
67
+ ].map(normalizeKey));
68
+ const isGeminiTool = (tool) => Object.keys(tool).map(normalizeKey).some((key) => key !== GEMINI_SCHEMA_FIELD && GEMINI_TOOL_FIELDS.has(key));
69
+ /**
70
+ * Masks the credential keys under every field of a `@google/genai` tool except its function declarations.
71
+ * A class-based tool, such as `mcpToTool(client)`, holds a live client with its auth headers, so only a stub is kept.
72
+ */
73
+ function redactGeminiToolDefinition(tool) {
74
+ if (!isPlainObject(tool)) return isObject(tool) ? { type: "callable_tool" } : tool;
75
+ 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)]));
76
+ }
77
+ /** Hides the credentials of a remote MCP or Gemini tool definition; everything else is kept as sent. */
78
+ function redactMcpToolDefinition(tool) {
79
+ if (!isObject(tool)) return tool;
80
+ if (typeof tool.type === "string" && MCP_TOOL_TYPES.has(tool.type)) return withoutMcpCredentials(tool);
81
+ if (isMcpProviderTool(tool) && isObject(tool.args)) return {
82
+ ...tool,
83
+ args: withoutMcpCredentials(tool.args)
84
+ };
85
+ if (isPlainObject(tool) && isGeminiTool(tool)) return redactGeminiToolDefinition(tool);
86
+ return tool;
87
+ }
88
+ function redactMcpToolCredentials(tools) {
89
+ return Array.isArray(tools) ? tools.map(redactMcpToolDefinition) : tools;
90
+ }
91
+ //#endregion
17
92
  //#region src/captureAiEvent.ts
18
93
  /** @internal */
19
94
  function isFullAiCaptureEnabled(client) {
@@ -552,7 +627,7 @@ const extractAvailableToolCalls = (provider, params) => {
552
627
  if (params.tools) return params.tools;
553
628
  return null;
554
629
  } else if (provider === "gemini") {
555
- if (params.config && params.config.tools) return params.config.tools;
630
+ if (params.config && Array.isArray(params.config.tools)) return params.config.tools.map(redactGeminiToolDefinition);
556
631
  return null;
557
632
  } else if (provider === "openai") {
558
633
  if (params.tools) return params.tools;
@@ -635,7 +710,7 @@ function formatOpenAIResponsesInput(input, instructions) {
635
710
  }
636
711
  //#endregion
637
712
  //#region package.json
638
- var version = "8.22.1";
713
+ var version = "8.22.2";
639
714
  //#endregion
640
715
  //#region src/serializeError.ts
641
716
  const DEFAULT_MAX_DEPTH = 3;
@@ -774,33 +849,6 @@ function truncateStack(stack) {
774
849
  return [...lines.slice(0, MAX_STACK_LINES), "... (truncated)"].join("\n");
775
850
  }
776
851
  //#endregion
777
- //#region src/mcpCredentials.ts
778
- const MCP_CREDENTIAL_FIELDS = ["headers", "authorization"];
779
- const MCP_PROVIDER_TOOL_IDS = /* @__PURE__ */ new Set([
780
- "openai.mcp",
781
- "xai.mcp",
782
- "google.mcp_server"
783
- ]);
784
- const isMcpProviderTool = (tool) => (tool.type === "provider" || tool.type === "provider-defined") && typeof tool.id === "string" && MCP_PROVIDER_TOOL_IDS.has(tool.id);
785
- const withoutMcpCredentials = (config) => {
786
- const redacted = { ...config };
787
- for (const field of MCP_CREDENTIAL_FIELDS) if (field in redacted) redacted[field] = "[REDACTED]";
788
- return redacted;
789
- };
790
- /** Hides the credentials of a remote MCP tool definition; everything else is kept as sent. */
791
- function redactMcpToolDefinition(tool) {
792
- if (!isObject(tool)) return tool;
793
- if (tool.type === "mcp") return withoutMcpCredentials(tool);
794
- if (isMcpProviderTool(tool) && isObject(tool.args)) return {
795
- ...tool,
796
- args: withoutMcpCredentials(tool.args)
797
- };
798
- return tool;
799
- }
800
- function redactMcpToolCredentials(tools) {
801
- return Array.isArray(tools) ? tools.map(redactMcpToolDefinition) : tools;
802
- }
803
- //#endregion
804
852
  //#region src/gatewayWarning.ts
805
853
  const POSTHOG_AI_GATEWAY_HOSTS = [
806
854
  "gateway.posthog.com",