@posthog/ai 8.22.0 → 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 +144 -75
  34. package/dist/openai/index.cjs.map +1 -1
  35. package/dist/openai/index.mjs +144 -75
  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 +3 -3
@@ -34,6 +34,81 @@ const isObject = (value) => {
34
34
  return value !== null && typeof value === "object" && !Array.isArray(value);
35
35
  };
36
36
  //#endregion
37
+ //#region src/mcpCredentials.ts
38
+ const MCP_CREDENTIAL_FIELDS = ["headers", "authorization"];
39
+ const MCP_TOOL_TYPES = /* @__PURE__ */ new Set(["mcp", "mcp_server"]);
40
+ const MCP_PROVIDER_TOOL_IDS = /* @__PURE__ */ new Set([
41
+ "openai.mcp",
42
+ "xai.mcp",
43
+ "google.mcp_server"
44
+ ]);
45
+ const isMcpProviderTool = (tool) => (tool.type === "provider" || tool.type === "provider-defined") && typeof tool.id === "string" && MCP_PROVIDER_TOOL_IDS.has(tool.id);
46
+ const withoutMcpCredentials = (config) => {
47
+ const redacted = { ...config };
48
+ for (const field of MCP_CREDENTIAL_FIELDS) if (field in redacted) redacted[field] = "[REDACTED]";
49
+ return redacted;
50
+ };
51
+ const normalizeKey = (key) => key.toLowerCase().replace(/[-_]/g, "");
52
+ const isPlainObject = (value) => {
53
+ if (!isObject(value)) return false;
54
+ const prototype = Object.getPrototypeOf(value);
55
+ return prototype === Object.prototype || prototype === null;
56
+ };
57
+ /**
58
+ * Replaces the value of every key in `keys` (normalized) with `[REDACTED]`, through plain objects and arrays.
59
+ * Class instances, such as the MCP client inside an `mcpToTool()` tool, are returned as they are.
60
+ */
61
+ function redactKeys(value, keys) {
62
+ if (Array.isArray(value)) return value.map((item) => redactKeys(item, keys));
63
+ if (!isPlainObject(value)) return value;
64
+ return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, keys.has(normalizeKey(key)) ? "[REDACTED]" : redactKeys(item, keys)]));
65
+ }
66
+ const GEMINI_TOOL_FIELDS = new Set([
67
+ "codeExecution",
68
+ "computerUse",
69
+ "enterpriseWebSearch",
70
+ "exaAiSearch",
71
+ "fileSearch",
72
+ "functionDeclarations",
73
+ "googleMaps",
74
+ "googleSearch",
75
+ "googleSearchRetrieval",
76
+ "mcpServers",
77
+ "parallelAiSearch",
78
+ "retrieval",
79
+ "urlContext"
80
+ ].map(normalizeKey));
81
+ const GEMINI_SCHEMA_FIELD = normalizeKey("functionDeclarations");
82
+ const GEMINI_CREDENTIAL_KEYS = new Set([
83
+ "apiAuth",
84
+ "authConfig",
85
+ "apiKey",
86
+ "headers"
87
+ ].map(normalizeKey));
88
+ const isGeminiTool = (tool) => Object.keys(tool).map(normalizeKey).some((key) => key !== GEMINI_SCHEMA_FIELD && GEMINI_TOOL_FIELDS.has(key));
89
+ /**
90
+ * Masks the credential keys under every field of a `@google/genai` tool except its function declarations.
91
+ * A class-based tool, such as `mcpToTool(client)`, holds a live client with its auth headers, so only a stub is kept.
92
+ */
93
+ function redactGeminiToolDefinition(tool) {
94
+ if (!isPlainObject(tool)) return isObject(tool) ? { type: "callable_tool" } : tool;
95
+ 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)]));
96
+ }
97
+ /** Hides the credentials of a remote MCP or Gemini tool definition; everything else is kept as sent. */
98
+ function redactMcpToolDefinition(tool) {
99
+ if (!isObject(tool)) return tool;
100
+ if (typeof tool.type === "string" && MCP_TOOL_TYPES.has(tool.type)) return withoutMcpCredentials(tool);
101
+ if (isMcpProviderTool(tool) && isObject(tool.args)) return {
102
+ ...tool,
103
+ args: withoutMcpCredentials(tool.args)
104
+ };
105
+ if (isPlainObject(tool) && isGeminiTool(tool)) return redactGeminiToolDefinition(tool);
106
+ return tool;
107
+ }
108
+ function redactMcpToolCredentials(tools) {
109
+ return Array.isArray(tools) ? tools.map(redactMcpToolDefinition) : tools;
110
+ }
111
+ //#endregion
37
112
  //#region src/captureAiEvent.ts
38
113
  /** @internal */
39
114
  function isFullAiCaptureEnabled(client) {
@@ -443,7 +518,7 @@ const extractAvailableToolCalls = (provider, params) => {
443
518
  if (params.tools) return params.tools;
444
519
  return null;
445
520
  } else if (provider === "gemini") {
446
- if (params.config && params.config.tools) return params.config.tools;
521
+ if (params.config && Array.isArray(params.config.tools)) return params.config.tools.map(redactGeminiToolDefinition);
447
522
  return null;
448
523
  } else if (provider === "openai") {
449
524
  if (params.tools) return params.tools;
@@ -494,7 +569,7 @@ function addDefaults(params) {
494
569
  }
495
570
  //#endregion
496
571
  //#region package.json
497
- var version = "8.22.0";
572
+ var version = "8.22.2";
498
573
  //#endregion
499
574
  //#region src/serializeError.ts
500
575
  const DEFAULT_MAX_DEPTH = 3;
@@ -633,33 +708,6 @@ function truncateStack(stack) {
633
708
  return [...lines.slice(0, MAX_STACK_LINES), "... (truncated)"].join("\n");
634
709
  }
635
710
  //#endregion
636
- //#region src/mcpCredentials.ts
637
- const MCP_CREDENTIAL_FIELDS = ["headers", "authorization"];
638
- const MCP_PROVIDER_TOOL_IDS = /* @__PURE__ */ new Set([
639
- "openai.mcp",
640
- "xai.mcp",
641
- "google.mcp_server"
642
- ]);
643
- const isMcpProviderTool = (tool) => (tool.type === "provider" || tool.type === "provider-defined") && typeof tool.id === "string" && MCP_PROVIDER_TOOL_IDS.has(tool.id);
644
- const withoutMcpCredentials = (config) => {
645
- const redacted = { ...config };
646
- for (const field of MCP_CREDENTIAL_FIELDS) if (field in redacted) redacted[field] = "[REDACTED]";
647
- return redacted;
648
- };
649
- /** Hides the credentials of a remote MCP tool definition; everything else is kept as sent. */
650
- function redactMcpToolDefinition(tool) {
651
- if (!isObject(tool)) return tool;
652
- if (tool.type === "mcp") return withoutMcpCredentials(tool);
653
- if (isMcpProviderTool(tool) && isObject(tool.args)) return {
654
- ...tool,
655
- args: withoutMcpCredentials(tool.args)
656
- };
657
- return tool;
658
- }
659
- function redactMcpToolCredentials(tools) {
660
- return Array.isArray(tools) ? tools.map(redactMcpToolDefinition) : tools;
661
- }
662
- //#endregion
663
711
  //#region src/gatewayWarning.ts
664
712
  const POSTHOG_AI_GATEWAY_HOSTS = [
665
713
  "gateway.posthog.com",