@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.
- package/README.md +19 -12
- 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/evaluations/index.cjs +1 -1
- package/dist/evaluations/index.cjs.map +1 -1
- package/dist/evaluations/index.d.ts +1 -1
- package/dist/evaluations/index.mjs +1 -1
- package/dist/evaluations/index.mjs.map +1 -1
- package/dist/gemini/index.cjs +80 -29
- package/dist/gemini/index.cjs.map +1 -1
- package/dist/gemini/index.mjs +80 -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/adk/index.mjs
CHANGED
|
@@ -2,13 +2,88 @@ import { BasePlugin } from "@google/adk";
|
|
|
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.3";
|
|
6
6
|
//#endregion
|
|
7
7
|
//#region src/typeGuards.ts
|
|
8
8
|
const isObject = (value) => {
|
|
9
9
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
10
10
|
};
|
|
11
11
|
//#endregion
|
|
12
|
+
//#region src/mcpCredentials.ts
|
|
13
|
+
const MCP_CREDENTIAL_FIELDS = ["headers", "authorization"];
|
|
14
|
+
const MCP_TOOL_TYPES = /* @__PURE__ */ new Set(["mcp", "mcp_server"]);
|
|
15
|
+
const MCP_PROVIDER_TOOL_IDS = /* @__PURE__ */ new Set([
|
|
16
|
+
"openai.mcp",
|
|
17
|
+
"xai.mcp",
|
|
18
|
+
"google.mcp_server"
|
|
19
|
+
]);
|
|
20
|
+
const isMcpProviderTool = (tool) => (tool.type === "provider" || tool.type === "provider-defined") && typeof tool.id === "string" && MCP_PROVIDER_TOOL_IDS.has(tool.id);
|
|
21
|
+
const withoutMcpCredentials = (config) => {
|
|
22
|
+
const redacted = { ...config };
|
|
23
|
+
for (const field of MCP_CREDENTIAL_FIELDS) if (field in redacted) redacted[field] = "[REDACTED]";
|
|
24
|
+
return redacted;
|
|
25
|
+
};
|
|
26
|
+
const normalizeKey = (key) => key.toLowerCase().replace(/[-_]/g, "");
|
|
27
|
+
const isPlainObject = (value) => {
|
|
28
|
+
if (!isObject(value)) return false;
|
|
29
|
+
const prototype = Object.getPrototypeOf(value);
|
|
30
|
+
return prototype === Object.prototype || prototype === null;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Replaces the value of every key in `keys` (normalized) with `[REDACTED]`, through plain objects and arrays.
|
|
34
|
+
* Class instances, such as the MCP client inside an `mcpToTool()` tool, are returned as they are.
|
|
35
|
+
*/
|
|
36
|
+
function redactKeys(value, keys) {
|
|
37
|
+
if (Array.isArray(value)) return value.map((item) => redactKeys(item, keys));
|
|
38
|
+
if (!isPlainObject(value)) return value;
|
|
39
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, keys.has(normalizeKey(key)) ? "[REDACTED]" : redactKeys(item, keys)]));
|
|
40
|
+
}
|
|
41
|
+
const GEMINI_TOOL_FIELDS = new Set([
|
|
42
|
+
"codeExecution",
|
|
43
|
+
"computerUse",
|
|
44
|
+
"enterpriseWebSearch",
|
|
45
|
+
"exaAiSearch",
|
|
46
|
+
"fileSearch",
|
|
47
|
+
"functionDeclarations",
|
|
48
|
+
"googleMaps",
|
|
49
|
+
"googleSearch",
|
|
50
|
+
"googleSearchRetrieval",
|
|
51
|
+
"mcpServers",
|
|
52
|
+
"parallelAiSearch",
|
|
53
|
+
"retrieval",
|
|
54
|
+
"urlContext"
|
|
55
|
+
].map(normalizeKey));
|
|
56
|
+
const GEMINI_SCHEMA_FIELD = normalizeKey("functionDeclarations");
|
|
57
|
+
const GEMINI_CREDENTIAL_KEYS = new Set([
|
|
58
|
+
"apiAuth",
|
|
59
|
+
"authConfig",
|
|
60
|
+
"apiKey",
|
|
61
|
+
"headers"
|
|
62
|
+
].map(normalizeKey));
|
|
63
|
+
const isGeminiTool = (tool) => Object.keys(tool).map(normalizeKey).some((key) => key !== GEMINI_SCHEMA_FIELD && GEMINI_TOOL_FIELDS.has(key));
|
|
64
|
+
/**
|
|
65
|
+
* Masks the credential keys under every field of a `@google/genai` tool except its function declarations.
|
|
66
|
+
* A class-based tool, such as `mcpToTool(client)`, holds a live client with its auth headers, so only a stub is kept.
|
|
67
|
+
*/
|
|
68
|
+
function redactGeminiToolDefinition(tool) {
|
|
69
|
+
if (!isPlainObject(tool)) return isObject(tool) ? { type: "callable_tool" } : tool;
|
|
70
|
+
return Object.fromEntries(Object.entries(tool).map(([key, value]) => [key, normalizeKey(key) === GEMINI_SCHEMA_FIELD ? value : redactKeys(toJsonSafeValue(value), GEMINI_CREDENTIAL_KEYS)]));
|
|
71
|
+
}
|
|
72
|
+
/** Hides the credentials of a remote MCP or Gemini tool definition; everything else is kept as sent. */
|
|
73
|
+
function redactMcpToolDefinition(tool) {
|
|
74
|
+
if (!isObject(tool)) return tool;
|
|
75
|
+
if (typeof tool.type === "string" && MCP_TOOL_TYPES.has(tool.type)) return withoutMcpCredentials(tool);
|
|
76
|
+
if (isMcpProviderTool(tool) && isObject(tool.args)) return {
|
|
77
|
+
...tool,
|
|
78
|
+
args: withoutMcpCredentials(tool.args)
|
|
79
|
+
};
|
|
80
|
+
if (isPlainObject(tool) && isGeminiTool(tool)) return redactGeminiToolDefinition(tool);
|
|
81
|
+
return tool;
|
|
82
|
+
}
|
|
83
|
+
function redactMcpToolCredentials(tools) {
|
|
84
|
+
return Array.isArray(tools) ? tools.map(redactMcpToolDefinition) : tools;
|
|
85
|
+
}
|
|
86
|
+
//#endregion
|
|
12
87
|
//#region src/captureAiEvent.ts
|
|
13
88
|
/** @internal */
|
|
14
89
|
function isFullAiCaptureEnabled(client) {
|
|
@@ -582,33 +657,6 @@ function truncateStack(stack) {
|
|
|
582
657
|
return [...lines.slice(0, MAX_STACK_LINES), "... (truncated)"].join("\n");
|
|
583
658
|
}
|
|
584
659
|
//#endregion
|
|
585
|
-
//#region src/mcpCredentials.ts
|
|
586
|
-
const MCP_CREDENTIAL_FIELDS = ["headers", "authorization"];
|
|
587
|
-
const MCP_PROVIDER_TOOL_IDS = /* @__PURE__ */ new Set([
|
|
588
|
-
"openai.mcp",
|
|
589
|
-
"xai.mcp",
|
|
590
|
-
"google.mcp_server"
|
|
591
|
-
]);
|
|
592
|
-
const isMcpProviderTool = (tool) => (tool.type === "provider" || tool.type === "provider-defined") && typeof tool.id === "string" && MCP_PROVIDER_TOOL_IDS.has(tool.id);
|
|
593
|
-
const withoutMcpCredentials = (config) => {
|
|
594
|
-
const redacted = { ...config };
|
|
595
|
-
for (const field of MCP_CREDENTIAL_FIELDS) if (field in redacted) redacted[field] = "[REDACTED]";
|
|
596
|
-
return redacted;
|
|
597
|
-
};
|
|
598
|
-
/** Hides the credentials of a remote MCP tool definition; everything else is kept as sent. */
|
|
599
|
-
function redactMcpToolDefinition(tool) {
|
|
600
|
-
if (!isObject(tool)) return tool;
|
|
601
|
-
if (tool.type === "mcp") return withoutMcpCredentials(tool);
|
|
602
|
-
if (isMcpProviderTool(tool) && isObject(tool.args)) return {
|
|
603
|
-
...tool,
|
|
604
|
-
args: withoutMcpCredentials(tool.args)
|
|
605
|
-
};
|
|
606
|
-
return tool;
|
|
607
|
-
}
|
|
608
|
-
function redactMcpToolCredentials(tools) {
|
|
609
|
-
return Array.isArray(tools) ? tools.map(redactMcpToolDefinition) : tools;
|
|
610
|
-
}
|
|
611
|
-
//#endregion
|
|
612
660
|
//#region src/gatewayWarning.ts
|
|
613
661
|
const POSTHOG_AI_GATEWAY_HOSTS = [
|
|
614
662
|
"gateway.posthog.com",
|