@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
@@ -3,13 +3,88 @@ 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.0";
6
+ var version = "8.22.2";
7
7
  //#endregion
8
8
  //#region src/typeGuards.ts
9
9
  const isObject = (value) => {
10
10
  return value !== null && typeof value === "object" && !Array.isArray(value);
11
11
  };
12
12
  //#endregion
13
+ //#region src/mcpCredentials.ts
14
+ const MCP_CREDENTIAL_FIELDS = ["headers", "authorization"];
15
+ const MCP_TOOL_TYPES = /* @__PURE__ */ new Set(["mcp", "mcp_server"]);
16
+ const MCP_PROVIDER_TOOL_IDS = /* @__PURE__ */ new Set([
17
+ "openai.mcp",
18
+ "xai.mcp",
19
+ "google.mcp_server"
20
+ ]);
21
+ const isMcpProviderTool = (tool) => (tool.type === "provider" || tool.type === "provider-defined") && typeof tool.id === "string" && MCP_PROVIDER_TOOL_IDS.has(tool.id);
22
+ const withoutMcpCredentials = (config) => {
23
+ const redacted = { ...config };
24
+ for (const field of MCP_CREDENTIAL_FIELDS) if (field in redacted) redacted[field] = "[REDACTED]";
25
+ return redacted;
26
+ };
27
+ const normalizeKey = (key) => key.toLowerCase().replace(/[-_]/g, "");
28
+ const isPlainObject = (value) => {
29
+ if (!isObject(value)) return false;
30
+ const prototype = Object.getPrototypeOf(value);
31
+ return prototype === Object.prototype || prototype === null;
32
+ };
33
+ /**
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.
36
+ */
37
+ function redactKeys(value, keys) {
38
+ if (Array.isArray(value)) return value.map((item) => redactKeys(item, keys));
39
+ if (!isPlainObject(value)) return value;
40
+ return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, keys.has(normalizeKey(key)) ? "[REDACTED]" : redactKeys(item, keys)]));
41
+ }
42
+ const GEMINI_TOOL_FIELDS = new Set([
43
+ "codeExecution",
44
+ "computerUse",
45
+ "enterpriseWebSearch",
46
+ "exaAiSearch",
47
+ "fileSearch",
48
+ "functionDeclarations",
49
+ "googleMaps",
50
+ "googleSearch",
51
+ "googleSearchRetrieval",
52
+ "mcpServers",
53
+ "parallelAiSearch",
54
+ "retrieval",
55
+ "urlContext"
56
+ ].map(normalizeKey));
57
+ const GEMINI_SCHEMA_FIELD = normalizeKey("functionDeclarations");
58
+ const GEMINI_CREDENTIAL_KEYS = new Set([
59
+ "apiAuth",
60
+ "authConfig",
61
+ "apiKey",
62
+ "headers"
63
+ ].map(normalizeKey));
64
+ const isGeminiTool = (tool) => Object.keys(tool).map(normalizeKey).some((key) => key !== GEMINI_SCHEMA_FIELD && GEMINI_TOOL_FIELDS.has(key));
65
+ /**
66
+ * Masks the credential keys under every field of a `@google/genai` tool except its function declarations.
67
+ * A class-based tool, such as `mcpToTool(client)`, holds a live client with its auth headers, so only a stub is kept.
68
+ */
69
+ function redactGeminiToolDefinition(tool) {
70
+ 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)]));
72
+ }
73
+ /** Hides the credentials of a remote MCP or Gemini tool definition; everything else is kept as sent. */
74
+ function redactMcpToolDefinition(tool) {
75
+ if (!isObject(tool)) return tool;
76
+ if (typeof tool.type === "string" && MCP_TOOL_TYPES.has(tool.type)) return withoutMcpCredentials(tool);
77
+ if (isMcpProviderTool(tool) && isObject(tool.args)) return {
78
+ ...tool,
79
+ args: withoutMcpCredentials(tool.args)
80
+ };
81
+ if (isPlainObject(tool) && isGeminiTool(tool)) return redactGeminiToolDefinition(tool);
82
+ return tool;
83
+ }
84
+ function redactMcpToolCredentials(tools) {
85
+ return Array.isArray(tools) ? tools.map(redactMcpToolDefinition) : tools;
86
+ }
87
+ //#endregion
13
88
  //#region src/captureAiEvent.ts
14
89
  /** @internal */
15
90
  function isFullAiCaptureEnabled(client) {
@@ -583,33 +658,6 @@ function truncateStack(stack) {
583
658
  return [...lines.slice(0, MAX_STACK_LINES), "... (truncated)"].join("\n");
584
659
  }
585
660
  //#endregion
586
- //#region src/mcpCredentials.ts
587
- const MCP_CREDENTIAL_FIELDS = ["headers", "authorization"];
588
- const MCP_PROVIDER_TOOL_IDS = /* @__PURE__ */ new Set([
589
- "openai.mcp",
590
- "xai.mcp",
591
- "google.mcp_server"
592
- ]);
593
- const isMcpProviderTool = (tool) => (tool.type === "provider" || tool.type === "provider-defined") && typeof tool.id === "string" && MCP_PROVIDER_TOOL_IDS.has(tool.id);
594
- const withoutMcpCredentials = (config) => {
595
- const redacted = { ...config };
596
- for (const field of MCP_CREDENTIAL_FIELDS) if (field in redacted) redacted[field] = "[REDACTED]";
597
- return redacted;
598
- };
599
- /** Hides the credentials of a remote MCP tool definition; everything else is kept as sent. */
600
- function redactMcpToolDefinition(tool) {
601
- if (!isObject(tool)) return tool;
602
- if (tool.type === "mcp") return withoutMcpCredentials(tool);
603
- if (isMcpProviderTool(tool) && isObject(tool.args)) return {
604
- ...tool,
605
- args: withoutMcpCredentials(tool.args)
606
- };
607
- return tool;
608
- }
609
- function redactMcpToolCredentials(tools) {
610
- return Array.isArray(tools) ? tools.map(redactMcpToolDefinition) : tools;
611
- }
612
- //#endregion
613
661
  //#region src/gatewayWarning.ts
614
662
  const POSTHOG_AI_GATEWAY_HOSTS = [
615
663
  "gateway.posthog.com",