@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
@@ -7,6 +7,81 @@ const isObject = (value) => {
7
7
  return value !== null && typeof value === "object" && !Array.isArray(value);
8
8
  };
9
9
  //#endregion
10
+ //#region src/mcpCredentials.ts
11
+ const MCP_CREDENTIAL_FIELDS = ["headers", "authorization"];
12
+ const MCP_TOOL_TYPES = /* @__PURE__ */ new Set(["mcp", "mcp_server"]);
13
+ const MCP_PROVIDER_TOOL_IDS = /* @__PURE__ */ new Set([
14
+ "openai.mcp",
15
+ "xai.mcp",
16
+ "google.mcp_server"
17
+ ]);
18
+ const isMcpProviderTool = (tool) => (tool.type === "provider" || tool.type === "provider-defined") && typeof tool.id === "string" && MCP_PROVIDER_TOOL_IDS.has(tool.id);
19
+ const withoutMcpCredentials = (config) => {
20
+ const redacted = { ...config };
21
+ for (const field of MCP_CREDENTIAL_FIELDS) if (field in redacted) redacted[field] = "[REDACTED]";
22
+ return redacted;
23
+ };
24
+ const normalizeKey = (key) => key.toLowerCase().replace(/[-_]/g, "");
25
+ const isPlainObject = (value) => {
26
+ if (!isObject(value)) return false;
27
+ const prototype = Object.getPrototypeOf(value);
28
+ return prototype === Object.prototype || prototype === null;
29
+ };
30
+ /**
31
+ * Replaces the value of every key in `keys` (normalized) with `[REDACTED]`, through plain objects and arrays.
32
+ * Class instances, such as the MCP client inside an `mcpToTool()` tool, are returned as they are.
33
+ */
34
+ function redactKeys(value, keys) {
35
+ if (Array.isArray(value)) return value.map((item) => redactKeys(item, keys));
36
+ if (!isPlainObject(value)) return value;
37
+ return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, keys.has(normalizeKey(key)) ? "[REDACTED]" : redactKeys(item, keys)]));
38
+ }
39
+ const GEMINI_TOOL_FIELDS = new Set([
40
+ "codeExecution",
41
+ "computerUse",
42
+ "enterpriseWebSearch",
43
+ "exaAiSearch",
44
+ "fileSearch",
45
+ "functionDeclarations",
46
+ "googleMaps",
47
+ "googleSearch",
48
+ "googleSearchRetrieval",
49
+ "mcpServers",
50
+ "parallelAiSearch",
51
+ "retrieval",
52
+ "urlContext"
53
+ ].map(normalizeKey));
54
+ const GEMINI_SCHEMA_FIELD = normalizeKey("functionDeclarations");
55
+ const GEMINI_CREDENTIAL_KEYS = new Set([
56
+ "apiAuth",
57
+ "authConfig",
58
+ "apiKey",
59
+ "headers"
60
+ ].map(normalizeKey));
61
+ const isGeminiTool = (tool) => Object.keys(tool).map(normalizeKey).some((key) => key !== GEMINI_SCHEMA_FIELD && GEMINI_TOOL_FIELDS.has(key));
62
+ /**
63
+ * Masks the credential keys under every field of a `@google/genai` tool except its function declarations.
64
+ * A class-based tool, such as `mcpToTool(client)`, holds a live client with its auth headers, so only a stub is kept.
65
+ */
66
+ function redactGeminiToolDefinition(tool) {
67
+ if (!isPlainObject(tool)) return isObject(tool) ? { type: "callable_tool" } : tool;
68
+ return Object.fromEntries(Object.entries(tool).map(([key, value]) => [key, normalizeKey(key) === GEMINI_SCHEMA_FIELD ? value : redactKeys(toJsonSafeValue(value), GEMINI_CREDENTIAL_KEYS)]));
69
+ }
70
+ /** Hides the credentials of a remote MCP or Gemini tool definition; everything else is kept as sent. */
71
+ function redactMcpToolDefinition(tool) {
72
+ if (!isObject(tool)) return tool;
73
+ if (typeof tool.type === "string" && MCP_TOOL_TYPES.has(tool.type)) return withoutMcpCredentials(tool);
74
+ if (isMcpProviderTool(tool) && isObject(tool.args)) return {
75
+ ...tool,
76
+ args: withoutMcpCredentials(tool.args)
77
+ };
78
+ if (isPlainObject(tool) && isGeminiTool(tool)) return redactGeminiToolDefinition(tool);
79
+ return tool;
80
+ }
81
+ function redactMcpToolCredentials(tools) {
82
+ return Array.isArray(tools) ? tools.map(redactMcpToolDefinition) : tools;
83
+ }
84
+ //#endregion
10
85
  //#region src/captureAiEvent.ts
11
86
  /** @internal */
12
87
  function isFullAiCaptureEnabled(client) {
@@ -416,7 +491,7 @@ const extractAvailableToolCalls = (provider, params) => {
416
491
  if (params.tools) return params.tools;
417
492
  return null;
418
493
  } else if (provider === "gemini") {
419
- if (params.config && params.config.tools) return params.config.tools;
494
+ if (params.config && Array.isArray(params.config.tools)) return params.config.tools.map(redactGeminiToolDefinition);
420
495
  return null;
421
496
  } else if (provider === "openai") {
422
497
  if (params.tools) return params.tools;
@@ -467,7 +542,7 @@ function addDefaults(params) {
467
542
  }
468
543
  //#endregion
469
544
  //#region package.json
470
- var version = "8.22.1";
545
+ var version = "8.22.3";
471
546
  //#endregion
472
547
  //#region src/serializeError.ts
473
548
  const DEFAULT_MAX_DEPTH = 3;
@@ -606,33 +681,6 @@ function truncateStack(stack) {
606
681
  return [...lines.slice(0, MAX_STACK_LINES), "... (truncated)"].join("\n");
607
682
  }
608
683
  //#endregion
609
- //#region src/mcpCredentials.ts
610
- const MCP_CREDENTIAL_FIELDS = ["headers", "authorization"];
611
- const MCP_PROVIDER_TOOL_IDS = /* @__PURE__ */ new Set([
612
- "openai.mcp",
613
- "xai.mcp",
614
- "google.mcp_server"
615
- ]);
616
- const isMcpProviderTool = (tool) => (tool.type === "provider" || tool.type === "provider-defined") && typeof tool.id === "string" && MCP_PROVIDER_TOOL_IDS.has(tool.id);
617
- const withoutMcpCredentials = (config) => {
618
- const redacted = { ...config };
619
- for (const field of MCP_CREDENTIAL_FIELDS) if (field in redacted) redacted[field] = "[REDACTED]";
620
- return redacted;
621
- };
622
- /** Hides the credentials of a remote MCP tool definition; everything else is kept as sent. */
623
- function redactMcpToolDefinition(tool) {
624
- if (!isObject(tool)) return tool;
625
- if (tool.type === "mcp") return withoutMcpCredentials(tool);
626
- if (isMcpProviderTool(tool) && isObject(tool.args)) return {
627
- ...tool,
628
- args: withoutMcpCredentials(tool.args)
629
- };
630
- return tool;
631
- }
632
- function redactMcpToolCredentials(tools) {
633
- return Array.isArray(tools) ? tools.map(redactMcpToolDefinition) : tools;
634
- }
635
- //#endregion
636
684
  //#region src/gatewayWarning.ts
637
685
  const POSTHOG_AI_GATEWAY_HOSTS = [
638
686
  "gateway.posthog.com",