@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
@@ -8,6 +8,81 @@ const isObject = (value) => {
8
8
  return value !== null && typeof value === "object" && !Array.isArray(value);
9
9
  };
10
10
  //#endregion
11
+ //#region src/mcpCredentials.ts
12
+ const MCP_CREDENTIAL_FIELDS = ["headers", "authorization"];
13
+ const MCP_TOOL_TYPES = /* @__PURE__ */ new Set(["mcp", "mcp_server"]);
14
+ const MCP_PROVIDER_TOOL_IDS = /* @__PURE__ */ new Set([
15
+ "openai.mcp",
16
+ "xai.mcp",
17
+ "google.mcp_server"
18
+ ]);
19
+ const isMcpProviderTool = (tool) => (tool.type === "provider" || tool.type === "provider-defined") && typeof tool.id === "string" && MCP_PROVIDER_TOOL_IDS.has(tool.id);
20
+ const withoutMcpCredentials = (config) => {
21
+ const redacted = { ...config };
22
+ for (const field of MCP_CREDENTIAL_FIELDS) if (field in redacted) redacted[field] = "[REDACTED]";
23
+ return redacted;
24
+ };
25
+ const normalizeKey = (key) => key.toLowerCase().replace(/[-_]/g, "");
26
+ const isPlainObject = (value) => {
27
+ if (!isObject(value)) return false;
28
+ const prototype = Object.getPrototypeOf(value);
29
+ return prototype === Object.prototype || prototype === null;
30
+ };
31
+ /**
32
+ * Replaces the value of every key in `keys` (normalized) with `[REDACTED]`, through plain objects and arrays.
33
+ * Class instances, such as the MCP client inside an `mcpToTool()` tool, are returned as they are.
34
+ */
35
+ function redactKeys(value, keys) {
36
+ if (Array.isArray(value)) return value.map((item) => redactKeys(item, keys));
37
+ if (!isPlainObject(value)) return value;
38
+ return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, keys.has(normalizeKey(key)) ? "[REDACTED]" : redactKeys(item, keys)]));
39
+ }
40
+ const GEMINI_TOOL_FIELDS = new Set([
41
+ "codeExecution",
42
+ "computerUse",
43
+ "enterpriseWebSearch",
44
+ "exaAiSearch",
45
+ "fileSearch",
46
+ "functionDeclarations",
47
+ "googleMaps",
48
+ "googleSearch",
49
+ "googleSearchRetrieval",
50
+ "mcpServers",
51
+ "parallelAiSearch",
52
+ "retrieval",
53
+ "urlContext"
54
+ ].map(normalizeKey));
55
+ const GEMINI_SCHEMA_FIELD = normalizeKey("functionDeclarations");
56
+ const GEMINI_CREDENTIAL_KEYS = new Set([
57
+ "apiAuth",
58
+ "authConfig",
59
+ "apiKey",
60
+ "headers"
61
+ ].map(normalizeKey));
62
+ const isGeminiTool = (tool) => Object.keys(tool).map(normalizeKey).some((key) => key !== GEMINI_SCHEMA_FIELD && GEMINI_TOOL_FIELDS.has(key));
63
+ /**
64
+ * Masks the credential keys under every field of a `@google/genai` tool except its function declarations.
65
+ * A class-based tool, such as `mcpToTool(client)`, holds a live client with its auth headers, so only a stub is kept.
66
+ */
67
+ function redactGeminiToolDefinition(tool) {
68
+ if (!isPlainObject(tool)) return isObject(tool) ? { type: "callable_tool" } : tool;
69
+ return Object.fromEntries(Object.entries(tool).map(([key, value]) => [key, normalizeKey(key) === GEMINI_SCHEMA_FIELD ? value : redactKeys(toJsonSafeValue(value), GEMINI_CREDENTIAL_KEYS)]));
70
+ }
71
+ /** Hides the credentials of a remote MCP or Gemini tool definition; everything else is kept as sent. */
72
+ function redactMcpToolDefinition(tool) {
73
+ if (!isObject(tool)) return tool;
74
+ if (typeof tool.type === "string" && MCP_TOOL_TYPES.has(tool.type)) return withoutMcpCredentials(tool);
75
+ if (isMcpProviderTool(tool) && isObject(tool.args)) return {
76
+ ...tool,
77
+ args: withoutMcpCredentials(tool.args)
78
+ };
79
+ if (isPlainObject(tool) && isGeminiTool(tool)) return redactGeminiToolDefinition(tool);
80
+ return tool;
81
+ }
82
+ function redactMcpToolCredentials(tools) {
83
+ return Array.isArray(tools) ? tools.map(redactMcpToolDefinition) : tools;
84
+ }
85
+ //#endregion
11
86
  //#region src/captureAiEvent.ts
12
87
  /** @internal */
13
88
  function isFullAiCaptureEnabled(client) {
@@ -470,7 +545,7 @@ const extractAvailableToolCalls = (provider, params) => {
470
545
  if (params.tools) return params.tools;
471
546
  return null;
472
547
  } else if (provider === "gemini") {
473
- if (params.config && params.config.tools) return params.config.tools;
548
+ if (params.config && Array.isArray(params.config.tools)) return params.config.tools.map(redactGeminiToolDefinition);
474
549
  return null;
475
550
  } else if (provider === "openai") {
476
551
  if (params.tools) return params.tools;
@@ -491,7 +566,7 @@ function sanitizeValues(obj) {
491
566
  }
492
567
  //#endregion
493
568
  //#region package.json
494
- var version = "8.22.0";
569
+ var version = "8.22.2";
495
570
  //#endregion
496
571
  //#region src/serializeError.ts
497
572
  const DEFAULT_MAX_DEPTH = 3;
@@ -630,33 +705,6 @@ function truncateStack(stack) {
630
705
  return [...lines.slice(0, MAX_STACK_LINES), "... (truncated)"].join("\n");
631
706
  }
632
707
  //#endregion
633
- //#region src/mcpCredentials.ts
634
- const MCP_CREDENTIAL_FIELDS = ["headers", "authorization"];
635
- const MCP_PROVIDER_TOOL_IDS = /* @__PURE__ */ new Set([
636
- "openai.mcp",
637
- "xai.mcp",
638
- "google.mcp_server"
639
- ]);
640
- const isMcpProviderTool = (tool) => (tool.type === "provider" || tool.type === "provider-defined") && typeof tool.id === "string" && MCP_PROVIDER_TOOL_IDS.has(tool.id);
641
- const withoutMcpCredentials = (config) => {
642
- const redacted = { ...config };
643
- for (const field of MCP_CREDENTIAL_FIELDS) if (field in redacted) redacted[field] = "[REDACTED]";
644
- return redacted;
645
- };
646
- /** Hides the credentials of a remote MCP tool definition; everything else is kept as sent. */
647
- function redactMcpToolDefinition(tool) {
648
- if (!isObject(tool)) return tool;
649
- if (tool.type === "mcp") return withoutMcpCredentials(tool);
650
- if (isMcpProviderTool(tool) && isObject(tool.args)) return {
651
- ...tool,
652
- args: withoutMcpCredentials(tool.args)
653
- };
654
- return tool;
655
- }
656
- function redactMcpToolCredentials(tools) {
657
- return Array.isArray(tools) ? tools.map(redactMcpToolDefinition) : tools;
658
- }
659
- //#endregion
660
708
  //#region src/gatewayWarning.ts
661
709
  const POSTHOG_AI_GATEWAY_HOSTS = [
662
710
  "gateway.posthog.com",