@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
@@ -3,7 +3,7 @@ let _anthropic_ai_claude_agent_sdk = require("@anthropic-ai/claude-agent-sdk");
3
3
  let uuid = require("uuid");
4
4
  let _posthog_core = require("@posthog/core");
5
5
  //#region package.json
6
- var version = "8.22.1";
6
+ var version = "8.22.2";
7
7
  //#endregion
8
8
  //#region src/captureAiEvent.ts
9
9
  /** @internal */
@@ -100,6 +100,81 @@ const isObject = (value) => {
100
100
  return value !== null && typeof value === "object" && !Array.isArray(value);
101
101
  };
102
102
  //#endregion
103
+ //#region src/mcpCredentials.ts
104
+ const MCP_CREDENTIAL_FIELDS = ["headers", "authorization"];
105
+ const MCP_TOOL_TYPES = /* @__PURE__ */ new Set(["mcp", "mcp_server"]);
106
+ const MCP_PROVIDER_TOOL_IDS = /* @__PURE__ */ new Set([
107
+ "openai.mcp",
108
+ "xai.mcp",
109
+ "google.mcp_server"
110
+ ]);
111
+ const isMcpProviderTool = (tool) => (tool.type === "provider" || tool.type === "provider-defined") && typeof tool.id === "string" && MCP_PROVIDER_TOOL_IDS.has(tool.id);
112
+ const withoutMcpCredentials = (config) => {
113
+ const redacted = { ...config };
114
+ for (const field of MCP_CREDENTIAL_FIELDS) if (field in redacted) redacted[field] = "[REDACTED]";
115
+ return redacted;
116
+ };
117
+ const normalizeKey = (key) => key.toLowerCase().replace(/[-_]/g, "");
118
+ const isPlainObject = (value) => {
119
+ if (!isObject(value)) return false;
120
+ const prototype = Object.getPrototypeOf(value);
121
+ return prototype === Object.prototype || prototype === null;
122
+ };
123
+ /**
124
+ * Replaces the value of every key in `keys` (normalized) with `[REDACTED]`, through plain objects and arrays.
125
+ * Class instances, such as the MCP client inside an `mcpToTool()` tool, are returned as they are.
126
+ */
127
+ function redactKeys(value, keys) {
128
+ if (Array.isArray(value)) return value.map((item) => redactKeys(item, keys));
129
+ if (!isPlainObject(value)) return value;
130
+ return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, keys.has(normalizeKey(key)) ? "[REDACTED]" : redactKeys(item, keys)]));
131
+ }
132
+ const GEMINI_TOOL_FIELDS = new Set([
133
+ "codeExecution",
134
+ "computerUse",
135
+ "enterpriseWebSearch",
136
+ "exaAiSearch",
137
+ "fileSearch",
138
+ "functionDeclarations",
139
+ "googleMaps",
140
+ "googleSearch",
141
+ "googleSearchRetrieval",
142
+ "mcpServers",
143
+ "parallelAiSearch",
144
+ "retrieval",
145
+ "urlContext"
146
+ ].map(normalizeKey));
147
+ const GEMINI_SCHEMA_FIELD = normalizeKey("functionDeclarations");
148
+ const GEMINI_CREDENTIAL_KEYS = new Set([
149
+ "apiAuth",
150
+ "authConfig",
151
+ "apiKey",
152
+ "headers"
153
+ ].map(normalizeKey));
154
+ const isGeminiTool = (tool) => Object.keys(tool).map(normalizeKey).some((key) => key !== GEMINI_SCHEMA_FIELD && GEMINI_TOOL_FIELDS.has(key));
155
+ /**
156
+ * Masks the credential keys under every field of a `@google/genai` tool except its function declarations.
157
+ * A class-based tool, such as `mcpToTool(client)`, holds a live client with its auth headers, so only a stub is kept.
158
+ */
159
+ function redactGeminiToolDefinition(tool) {
160
+ if (!isPlainObject(tool)) return isObject(tool) ? { type: "callable_tool" } : tool;
161
+ 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)]));
162
+ }
163
+ /** Hides the credentials of a remote MCP or Gemini tool definition; everything else is kept as sent. */
164
+ function redactMcpToolDefinition(tool) {
165
+ if (!isObject(tool)) return tool;
166
+ if (typeof tool.type === "string" && MCP_TOOL_TYPES.has(tool.type)) return withoutMcpCredentials(tool);
167
+ if (isMcpProviderTool(tool) && isObject(tool.args)) return {
168
+ ...tool,
169
+ args: withoutMcpCredentials(tool.args)
170
+ };
171
+ if (isPlainObject(tool) && isGeminiTool(tool)) return redactGeminiToolDefinition(tool);
172
+ return tool;
173
+ }
174
+ function redactMcpToolCredentials(tools) {
175
+ return Array.isArray(tools) ? tools.map(redactMcpToolDefinition) : tools;
176
+ }
177
+ //#endregion
103
178
  //#region src/sanitization/base64_recognizer.ts
104
179
  const DATA_URL_PREFIX_RE = /^data:([^;,\s]+)(?:;[^;,\s]+)*;base64,/i;
105
180
  const BASE64_ALPHABET_RE = /^[A-Za-z0-9+/_=-]+$/;
@@ -519,33 +594,6 @@ function truncateStack(stack) {
519
594
  return [...lines.slice(0, MAX_STACK_LINES), "... (truncated)"].join("\n");
520
595
  }
521
596
  //#endregion
522
- //#region src/mcpCredentials.ts
523
- const MCP_CREDENTIAL_FIELDS = ["headers", "authorization"];
524
- const MCP_PROVIDER_TOOL_IDS = /* @__PURE__ */ new Set([
525
- "openai.mcp",
526
- "xai.mcp",
527
- "google.mcp_server"
528
- ]);
529
- const isMcpProviderTool = (tool) => (tool.type === "provider" || tool.type === "provider-defined") && typeof tool.id === "string" && MCP_PROVIDER_TOOL_IDS.has(tool.id);
530
- const withoutMcpCredentials = (config) => {
531
- const redacted = { ...config };
532
- for (const field of MCP_CREDENTIAL_FIELDS) if (field in redacted) redacted[field] = "[REDACTED]";
533
- return redacted;
534
- };
535
- /** Hides the credentials of a remote MCP tool definition; everything else is kept as sent. */
536
- function redactMcpToolDefinition(tool) {
537
- if (!isObject(tool)) return tool;
538
- if (tool.type === "mcp") return withoutMcpCredentials(tool);
539
- if (isMcpProviderTool(tool) && isObject(tool.args)) return {
540
- ...tool,
541
- args: withoutMcpCredentials(tool.args)
542
- };
543
- return tool;
544
- }
545
- function redactMcpToolCredentials(tools) {
546
- return Array.isArray(tools) ? tools.map(redactMcpToolDefinition) : tools;
547
- }
548
- //#endregion
549
597
  //#region src/gatewayWarning.ts
550
598
  const POSTHOG_AI_GATEWAY_HOSTS = [
551
599
  "gateway.posthog.com",