@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
@@ -2,7 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  let _posthog_core = require("@posthog/core");
3
3
  let uuid = require("uuid");
4
4
  //#region package.json
5
- var version = "8.22.0";
5
+ var version = "8.22.2";
6
6
  //#endregion
7
7
  //#region src/captureAiEvent.ts
8
8
  /** @internal */
@@ -99,6 +99,81 @@ const isObject = (value) => {
99
99
  return value !== null && typeof value === "object" && !Array.isArray(value);
100
100
  };
101
101
  //#endregion
102
+ //#region src/mcpCredentials.ts
103
+ const MCP_CREDENTIAL_FIELDS = ["headers", "authorization"];
104
+ const MCP_TOOL_TYPES = /* @__PURE__ */ new Set(["mcp", "mcp_server"]);
105
+ const MCP_PROVIDER_TOOL_IDS = /* @__PURE__ */ new Set([
106
+ "openai.mcp",
107
+ "xai.mcp",
108
+ "google.mcp_server"
109
+ ]);
110
+ const isMcpProviderTool = (tool) => (tool.type === "provider" || tool.type === "provider-defined") && typeof tool.id === "string" && MCP_PROVIDER_TOOL_IDS.has(tool.id);
111
+ const withoutMcpCredentials = (config) => {
112
+ const redacted = { ...config };
113
+ for (const field of MCP_CREDENTIAL_FIELDS) if (field in redacted) redacted[field] = "[REDACTED]";
114
+ return redacted;
115
+ };
116
+ const normalizeKey = (key) => key.toLowerCase().replace(/[-_]/g, "");
117
+ const isPlainObject = (value) => {
118
+ if (!isObject(value)) return false;
119
+ const prototype = Object.getPrototypeOf(value);
120
+ return prototype === Object.prototype || prototype === null;
121
+ };
122
+ /**
123
+ * Replaces the value of every key in `keys` (normalized) with `[REDACTED]`, through plain objects and arrays.
124
+ * Class instances, such as the MCP client inside an `mcpToTool()` tool, are returned as they are.
125
+ */
126
+ function redactKeys(value, keys) {
127
+ if (Array.isArray(value)) return value.map((item) => redactKeys(item, keys));
128
+ if (!isPlainObject(value)) return value;
129
+ return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, keys.has(normalizeKey(key)) ? "[REDACTED]" : redactKeys(item, keys)]));
130
+ }
131
+ const GEMINI_TOOL_FIELDS = new Set([
132
+ "codeExecution",
133
+ "computerUse",
134
+ "enterpriseWebSearch",
135
+ "exaAiSearch",
136
+ "fileSearch",
137
+ "functionDeclarations",
138
+ "googleMaps",
139
+ "googleSearch",
140
+ "googleSearchRetrieval",
141
+ "mcpServers",
142
+ "parallelAiSearch",
143
+ "retrieval",
144
+ "urlContext"
145
+ ].map(normalizeKey));
146
+ const GEMINI_SCHEMA_FIELD = normalizeKey("functionDeclarations");
147
+ const GEMINI_CREDENTIAL_KEYS = new Set([
148
+ "apiAuth",
149
+ "authConfig",
150
+ "apiKey",
151
+ "headers"
152
+ ].map(normalizeKey));
153
+ const isGeminiTool = (tool) => Object.keys(tool).map(normalizeKey).some((key) => key !== GEMINI_SCHEMA_FIELD && GEMINI_TOOL_FIELDS.has(key));
154
+ /**
155
+ * Masks the credential keys under every field of a `@google/genai` tool except its function declarations.
156
+ * A class-based tool, such as `mcpToTool(client)`, holds a live client with its auth headers, so only a stub is kept.
157
+ */
158
+ function redactGeminiToolDefinition(tool) {
159
+ if (!isPlainObject(tool)) return isObject(tool) ? { type: "callable_tool" } : tool;
160
+ 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)]));
161
+ }
162
+ /** Hides the credentials of a remote MCP or Gemini tool definition; everything else is kept as sent. */
163
+ function redactMcpToolDefinition(tool) {
164
+ if (!isObject(tool)) return tool;
165
+ if (typeof tool.type === "string" && MCP_TOOL_TYPES.has(tool.type)) return withoutMcpCredentials(tool);
166
+ if (isMcpProviderTool(tool) && isObject(tool.args)) return {
167
+ ...tool,
168
+ args: withoutMcpCredentials(tool.args)
169
+ };
170
+ if (isPlainObject(tool) && isGeminiTool(tool)) return redactGeminiToolDefinition(tool);
171
+ return tool;
172
+ }
173
+ function redactMcpToolCredentials(tools) {
174
+ return Array.isArray(tools) ? tools.map(redactMcpToolDefinition) : tools;
175
+ }
176
+ //#endregion
102
177
  //#region src/sanitization/base64_recognizer.ts
103
178
  const DATA_URL_PREFIX_RE = /^data:([^;,\s]+)(?:;[^;,\s]+)*;base64,/i;
104
179
  const BASE64_ALPHABET_RE = /^[A-Za-z0-9+/_=-]+$/;
@@ -533,33 +608,6 @@ function truncateStack(stack) {
533
608
  return [...lines.slice(0, MAX_STACK_LINES), "... (truncated)"].join("\n");
534
609
  }
535
610
  //#endregion
536
- //#region src/mcpCredentials.ts
537
- const MCP_CREDENTIAL_FIELDS = ["headers", "authorization"];
538
- const MCP_PROVIDER_TOOL_IDS = /* @__PURE__ */ new Set([
539
- "openai.mcp",
540
- "xai.mcp",
541
- "google.mcp_server"
542
- ]);
543
- const isMcpProviderTool = (tool) => (tool.type === "provider" || tool.type === "provider-defined") && typeof tool.id === "string" && MCP_PROVIDER_TOOL_IDS.has(tool.id);
544
- const withoutMcpCredentials = (config) => {
545
- const redacted = { ...config };
546
- for (const field of MCP_CREDENTIAL_FIELDS) if (field in redacted) redacted[field] = "[REDACTED]";
547
- return redacted;
548
- };
549
- /** Hides the credentials of a remote MCP tool definition; everything else is kept as sent. */
550
- function redactMcpToolDefinition(tool) {
551
- if (!isObject(tool)) return tool;
552
- if (tool.type === "mcp") return withoutMcpCredentials(tool);
553
- if (isMcpProviderTool(tool) && isObject(tool.args)) return {
554
- ...tool,
555
- args: withoutMcpCredentials(tool.args)
556
- };
557
- return tool;
558
- }
559
- function redactMcpToolCredentials(tools) {
560
- return Array.isArray(tools) ? tools.map(redactMcpToolDefinition) : tools;
561
- }
562
- //#endregion
563
611
  //#region src/gatewayWarning.ts
564
612
  const POSTHOG_AI_GATEWAY_HOSTS = [
565
613
  "gateway.posthog.com",
@@ -799,16 +847,16 @@ const MODEL_PARAMETER_KEYS = [
799
847
  "topP",
800
848
  "stopSequences"
801
849
  ];
802
- const CREDENTIAL_KEYS = /* @__PURE__ */ new Set([
803
- "apikey",
804
- "accesstoken",
850
+ const CREDENTIAL_KEYS = new Set([
851
+ "apiKey",
852
+ "accessToken",
805
853
  "authorization",
806
- "clientsecret",
854
+ "clientSecret",
807
855
  "headers",
808
856
  "password",
809
857
  "secret",
810
858
  "token"
811
- ]);
859
+ ].map(normalizeKey));
812
860
  const PROVIDER_NAMES = /* @__PURE__ */ new Map([["googleai", "gemini"], ["vertexai", "vertex"]]);
813
861
  const STACK_ERROR_NAME = /^([A-Za-z_$][\w$]*)(?=:|\n|$)/;
814
862
  /**
@@ -983,13 +1031,13 @@ var PostHogGenkitSpanProcessor = class {
983
1031
  }
984
1032
  _formatState(span, key) {
985
1033
  if (isPrivacyModeEnabled(this._client, this._privacyMode)) return null;
986
- return formatToolResult(redactCredentials(parseAttribute(span, key)), this._client, MAX_OUTPUT_SIZE);
1034
+ return formatToolResult(redactKeys(parseAttribute(span, key), CREDENTIAL_KEYS), this._client, MAX_OUTPUT_SIZE);
987
1035
  }
988
1036
  _formatMessages(messages) {
989
- return formatToolResult(redactCredentials(messages.map((message) => ({
1037
+ return formatToolResult(redactKeys(messages.map((message) => ({
990
1038
  role: message.role === "model" ? "assistant" : message.role,
991
1039
  content: (message.content ?? []).map((part) => formatPart(part, this._client))
992
- }))), this._client, MAX_OUTPUT_SIZE);
1040
+ })), CREDENTIAL_KEYS), this._client, MAX_OUTPUT_SIZE);
993
1041
  }
994
1042
  };
995
1043
  function formatPart(part, client) {
@@ -1038,11 +1086,6 @@ function formatDocument(content, client) {
1038
1086
  if (content.every((part) => typeof part.text === "string")) return content.map((part) => part.text).join("");
1039
1087
  return content.map((part) => formatPart(part, client));
1040
1088
  }
1041
- function redactCredentials(value) {
1042
- if (Array.isArray(value)) return value.map(redactCredentials);
1043
- if (!isObject(value)) return value;
1044
- return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, CREDENTIAL_KEYS.has(key.toLowerCase().replace(/[-_]/g, "")) ? "[REDACTED]" : redactCredentials(item)]));
1045
- }
1046
1089
  /** Genkit stores span input and output as JSON strings. */
1047
1090
  function parseAttribute(span, key) {
1048
1091
  const value = span.attributes[key];