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