@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/index.mjs
CHANGED
|
@@ -8,6 +8,81 @@ const isObject = (value) => {
|
|
|
8
8
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
9
9
|
};
|
|
10
10
|
//#endregion
|
|
11
|
+
//#region src/mcpCredentials.ts
|
|
12
|
+
const MCP_CREDENTIAL_FIELDS = ["headers", "authorization"];
|
|
13
|
+
const MCP_TOOL_TYPES = /* @__PURE__ */ new Set(["mcp", "mcp_server"]);
|
|
14
|
+
const MCP_PROVIDER_TOOL_IDS = /* @__PURE__ */ new Set([
|
|
15
|
+
"openai.mcp",
|
|
16
|
+
"xai.mcp",
|
|
17
|
+
"google.mcp_server"
|
|
18
|
+
]);
|
|
19
|
+
const isMcpProviderTool = (tool) => (tool.type === "provider" || tool.type === "provider-defined") && typeof tool.id === "string" && MCP_PROVIDER_TOOL_IDS.has(tool.id);
|
|
20
|
+
const withoutMcpCredentials = (config) => {
|
|
21
|
+
const redacted = { ...config };
|
|
22
|
+
for (const field of MCP_CREDENTIAL_FIELDS) if (field in redacted) redacted[field] = "[REDACTED]";
|
|
23
|
+
return redacted;
|
|
24
|
+
};
|
|
25
|
+
const normalizeKey = (key) => key.toLowerCase().replace(/[-_]/g, "");
|
|
26
|
+
const isPlainObject = (value) => {
|
|
27
|
+
if (!isObject(value)) return false;
|
|
28
|
+
const prototype = Object.getPrototypeOf(value);
|
|
29
|
+
return prototype === Object.prototype || prototype === null;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Replaces the value of every key in `keys` (normalized) with `[REDACTED]`, through plain objects and arrays.
|
|
33
|
+
* Class instances, such as the MCP client inside an `mcpToTool()` tool, are returned as they are.
|
|
34
|
+
*/
|
|
35
|
+
function redactKeys(value, keys) {
|
|
36
|
+
if (Array.isArray(value)) return value.map((item) => redactKeys(item, keys));
|
|
37
|
+
if (!isPlainObject(value)) return value;
|
|
38
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, keys.has(normalizeKey(key)) ? "[REDACTED]" : redactKeys(item, keys)]));
|
|
39
|
+
}
|
|
40
|
+
const GEMINI_TOOL_FIELDS = new Set([
|
|
41
|
+
"codeExecution",
|
|
42
|
+
"computerUse",
|
|
43
|
+
"enterpriseWebSearch",
|
|
44
|
+
"exaAiSearch",
|
|
45
|
+
"fileSearch",
|
|
46
|
+
"functionDeclarations",
|
|
47
|
+
"googleMaps",
|
|
48
|
+
"googleSearch",
|
|
49
|
+
"googleSearchRetrieval",
|
|
50
|
+
"mcpServers",
|
|
51
|
+
"parallelAiSearch",
|
|
52
|
+
"retrieval",
|
|
53
|
+
"urlContext"
|
|
54
|
+
].map(normalizeKey));
|
|
55
|
+
const GEMINI_SCHEMA_FIELD = normalizeKey("functionDeclarations");
|
|
56
|
+
const GEMINI_CREDENTIAL_KEYS = new Set([
|
|
57
|
+
"apiAuth",
|
|
58
|
+
"authConfig",
|
|
59
|
+
"apiKey",
|
|
60
|
+
"headers"
|
|
61
|
+
].map(normalizeKey));
|
|
62
|
+
const isGeminiTool = (tool) => Object.keys(tool).map(normalizeKey).some((key) => key !== GEMINI_SCHEMA_FIELD && GEMINI_TOOL_FIELDS.has(key));
|
|
63
|
+
/**
|
|
64
|
+
* Masks the credential keys under every field of a `@google/genai` tool except its function declarations.
|
|
65
|
+
* A class-based tool, such as `mcpToTool(client)`, holds a live client with its auth headers, so only a stub is kept.
|
|
66
|
+
*/
|
|
67
|
+
function redactGeminiToolDefinition(tool) {
|
|
68
|
+
if (!isPlainObject(tool)) return isObject(tool) ? { type: "callable_tool" } : tool;
|
|
69
|
+
return Object.fromEntries(Object.entries(tool).map(([key, value]) => [key, normalizeKey(key) === GEMINI_SCHEMA_FIELD ? value : redactKeys(toJsonSafeValue(value), GEMINI_CREDENTIAL_KEYS)]));
|
|
70
|
+
}
|
|
71
|
+
/** Hides the credentials of a remote MCP or Gemini tool definition; everything else is kept as sent. */
|
|
72
|
+
function redactMcpToolDefinition(tool) {
|
|
73
|
+
if (!isObject(tool)) return tool;
|
|
74
|
+
if (typeof tool.type === "string" && MCP_TOOL_TYPES.has(tool.type)) return withoutMcpCredentials(tool);
|
|
75
|
+
if (isMcpProviderTool(tool) && isObject(tool.args)) return {
|
|
76
|
+
...tool,
|
|
77
|
+
args: withoutMcpCredentials(tool.args)
|
|
78
|
+
};
|
|
79
|
+
if (isPlainObject(tool) && isGeminiTool(tool)) return redactGeminiToolDefinition(tool);
|
|
80
|
+
return tool;
|
|
81
|
+
}
|
|
82
|
+
function redactMcpToolCredentials(tools) {
|
|
83
|
+
return Array.isArray(tools) ? tools.map(redactMcpToolDefinition) : tools;
|
|
84
|
+
}
|
|
85
|
+
//#endregion
|
|
11
86
|
//#region src/captureAiEvent.ts
|
|
12
87
|
/** @internal */
|
|
13
88
|
function isFullAiCaptureEnabled(client) {
|
|
@@ -470,7 +545,7 @@ const extractAvailableToolCalls = (provider, params) => {
|
|
|
470
545
|
if (params.tools) return params.tools;
|
|
471
546
|
return null;
|
|
472
547
|
} else if (provider === "gemini") {
|
|
473
|
-
if (params.config && params.config.tools) return params.config.tools;
|
|
548
|
+
if (params.config && Array.isArray(params.config.tools)) return params.config.tools.map(redactGeminiToolDefinition);
|
|
474
549
|
return null;
|
|
475
550
|
} else if (provider === "openai") {
|
|
476
551
|
if (params.tools) return params.tools;
|
|
@@ -496,7 +571,7 @@ function sanitizeValues(obj) {
|
|
|
496
571
|
}
|
|
497
572
|
//#endregion
|
|
498
573
|
//#region package.json
|
|
499
|
-
var version = "8.22.
|
|
574
|
+
var version = "8.22.3";
|
|
500
575
|
//#endregion
|
|
501
576
|
//#region src/serializeError.ts
|
|
502
577
|
const DEFAULT_MAX_DEPTH = 3;
|
|
@@ -635,33 +710,6 @@ function truncateStack(stack) {
|
|
|
635
710
|
return [...lines.slice(0, MAX_STACK_LINES), "... (truncated)"].join("\n");
|
|
636
711
|
}
|
|
637
712
|
//#endregion
|
|
638
|
-
//#region src/mcpCredentials.ts
|
|
639
|
-
const MCP_CREDENTIAL_FIELDS = ["headers", "authorization"];
|
|
640
|
-
const MCP_PROVIDER_TOOL_IDS = /* @__PURE__ */ new Set([
|
|
641
|
-
"openai.mcp",
|
|
642
|
-
"xai.mcp",
|
|
643
|
-
"google.mcp_server"
|
|
644
|
-
]);
|
|
645
|
-
const isMcpProviderTool = (tool) => (tool.type === "provider" || tool.type === "provider-defined") && typeof tool.id === "string" && MCP_PROVIDER_TOOL_IDS.has(tool.id);
|
|
646
|
-
const withoutMcpCredentials = (config) => {
|
|
647
|
-
const redacted = { ...config };
|
|
648
|
-
for (const field of MCP_CREDENTIAL_FIELDS) if (field in redacted) redacted[field] = "[REDACTED]";
|
|
649
|
-
return redacted;
|
|
650
|
-
};
|
|
651
|
-
/** Hides the credentials of a remote MCP tool definition; everything else is kept as sent. */
|
|
652
|
-
function redactMcpToolDefinition(tool) {
|
|
653
|
-
if (!isObject(tool)) return tool;
|
|
654
|
-
if (tool.type === "mcp") return withoutMcpCredentials(tool);
|
|
655
|
-
if (isMcpProviderTool(tool) && isObject(tool.args)) return {
|
|
656
|
-
...tool,
|
|
657
|
-
args: withoutMcpCredentials(tool.args)
|
|
658
|
-
};
|
|
659
|
-
return tool;
|
|
660
|
-
}
|
|
661
|
-
function redactMcpToolCredentials(tools) {
|
|
662
|
-
return Array.isArray(tools) ? tools.map(redactMcpToolDefinition) : tools;
|
|
663
|
-
}
|
|
664
|
-
//#endregion
|
|
665
713
|
//#region src/gatewayWarning.ts
|
|
666
714
|
const POSTHOG_AI_GATEWAY_HOSTS = [
|
|
667
715
|
"gateway.posthog.com",
|