@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.
- package/dist/adk/index.cjs +76 -28
- package/dist/adk/index.cjs.map +1 -1
- package/dist/adk/index.mjs +76 -28
- package/dist/adk/index.mjs.map +1 -1
- package/dist/anthropic/index.cjs +77 -29
- package/dist/anthropic/index.cjs.map +1 -1
- package/dist/anthropic/index.mjs +77 -29
- package/dist/anthropic/index.mjs.map +1 -1
- package/dist/claude-agent-sdk/index.cjs +76 -28
- package/dist/claude-agent-sdk/index.cjs.map +1 -1
- package/dist/claude-agent-sdk/index.mjs +76 -28
- package/dist/claude-agent-sdk/index.mjs.map +1 -1
- package/dist/gemini/index.cjs +77 -29
- package/dist/gemini/index.cjs.map +1 -1
- package/dist/gemini/index.mjs +77 -29
- package/dist/gemini/index.mjs.map +1 -1
- package/dist/genkit/index.cjs +84 -41
- package/dist/genkit/index.cjs.map +1 -1
- package/dist/genkit/index.mjs +84 -41
- package/dist/genkit/index.mjs.map +1 -1
- package/dist/index.cjs +77 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +77 -29
- package/dist/index.mjs.map +1 -1
- package/dist/langchain/index.cjs +76 -28
- package/dist/langchain/index.cjs.map +1 -1
- package/dist/langchain/index.mjs +77 -29
- package/dist/langchain/index.mjs.map +1 -1
- package/dist/langchain/middleware/index.cjs +76 -28
- package/dist/langchain/middleware/index.cjs.map +1 -1
- package/dist/langchain/middleware/index.mjs +77 -29
- package/dist/langchain/middleware/index.mjs.map +1 -1
- package/dist/openai/index.cjs +77 -29
- package/dist/openai/index.cjs.map +1 -1
- package/dist/openai/index.mjs +77 -29
- package/dist/openai/index.mjs.map +1 -1
- package/dist/openai-agents/index.cjs +26 -1
- package/dist/openai-agents/index.cjs.map +1 -1
- package/dist/openai-agents/index.mjs +26 -1
- package/dist/openai-agents/index.mjs.map +1 -1
- package/dist/otel/index.browser.cjs +51 -2
- package/dist/otel/index.browser.cjs.map +1 -1
- package/dist/otel/index.browser.mjs +51 -2
- package/dist/otel/index.browser.mjs.map +1 -1
- package/dist/otel/index.cjs +51 -2
- package/dist/otel/index.cjs.map +1 -1
- package/dist/otel/index.mjs +51 -2
- package/dist/otel/index.mjs.map +1 -1
- package/dist/vercel/index.cjs +77 -29
- package/dist/vercel/index.cjs.map +1 -1
- package/dist/vercel/index.mjs +77 -29
- package/dist/vercel/index.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -2,7 +2,7 @@ import { SYSTEM_PROMPT_DYNAMIC_BOUNDARY, query as query$1 } from "@anthropic-ai/
|
|
|
2
2
|
import { v4 } from "uuid";
|
|
3
3
|
import { acceptsEventOptions, eventOptionsAsLegacyProperties, toJsonSafeValue, uuidv7 } from "@posthog/core";
|
|
4
4
|
//#region package.json
|
|
5
|
-
var version = "8.22.
|
|
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(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+/_=-]+$/;
|
|
@@ -518,33 +593,6 @@ function truncateStack(stack) {
|
|
|
518
593
|
return [...lines.slice(0, MAX_STACK_LINES), "... (truncated)"].join("\n");
|
|
519
594
|
}
|
|
520
595
|
//#endregion
|
|
521
|
-
//#region src/mcpCredentials.ts
|
|
522
|
-
const MCP_CREDENTIAL_FIELDS = ["headers", "authorization"];
|
|
523
|
-
const MCP_PROVIDER_TOOL_IDS = /* @__PURE__ */ new Set([
|
|
524
|
-
"openai.mcp",
|
|
525
|
-
"xai.mcp",
|
|
526
|
-
"google.mcp_server"
|
|
527
|
-
]);
|
|
528
|
-
const isMcpProviderTool = (tool) => (tool.type === "provider" || tool.type === "provider-defined") && typeof tool.id === "string" && MCP_PROVIDER_TOOL_IDS.has(tool.id);
|
|
529
|
-
const withoutMcpCredentials = (config) => {
|
|
530
|
-
const redacted = { ...config };
|
|
531
|
-
for (const field of MCP_CREDENTIAL_FIELDS) if (field in redacted) redacted[field] = "[REDACTED]";
|
|
532
|
-
return redacted;
|
|
533
|
-
};
|
|
534
|
-
/** Hides the credentials of a remote MCP tool definition; everything else is kept as sent. */
|
|
535
|
-
function redactMcpToolDefinition(tool) {
|
|
536
|
-
if (!isObject(tool)) return tool;
|
|
537
|
-
if (tool.type === "mcp") return withoutMcpCredentials(tool);
|
|
538
|
-
if (isMcpProviderTool(tool) && isObject(tool.args)) return {
|
|
539
|
-
...tool,
|
|
540
|
-
args: withoutMcpCredentials(tool.args)
|
|
541
|
-
};
|
|
542
|
-
return tool;
|
|
543
|
-
}
|
|
544
|
-
function redactMcpToolCredentials(tools) {
|
|
545
|
-
return Array.isArray(tools) ? tools.map(redactMcpToolDefinition) : tools;
|
|
546
|
-
}
|
|
547
|
-
//#endregion
|
|
548
596
|
//#region src/gatewayWarning.ts
|
|
549
597
|
const POSTHOG_AI_GATEWAY_HOSTS = [
|
|
550
598
|
"gateway.posthog.com",
|