@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/openai/index.mjs
CHANGED
|
@@ -10,6 +10,81 @@ const isObject = (value) => {
|
|
|
10
10
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
11
11
|
};
|
|
12
12
|
//#endregion
|
|
13
|
+
//#region src/mcpCredentials.ts
|
|
14
|
+
const MCP_CREDENTIAL_FIELDS = ["headers", "authorization"];
|
|
15
|
+
const MCP_TOOL_TYPES = /* @__PURE__ */ new Set(["mcp", "mcp_server"]);
|
|
16
|
+
const MCP_PROVIDER_TOOL_IDS = /* @__PURE__ */ new Set([
|
|
17
|
+
"openai.mcp",
|
|
18
|
+
"xai.mcp",
|
|
19
|
+
"google.mcp_server"
|
|
20
|
+
]);
|
|
21
|
+
const isMcpProviderTool = (tool) => (tool.type === "provider" || tool.type === "provider-defined") && typeof tool.id === "string" && MCP_PROVIDER_TOOL_IDS.has(tool.id);
|
|
22
|
+
const withoutMcpCredentials = (config) => {
|
|
23
|
+
const redacted = { ...config };
|
|
24
|
+
for (const field of MCP_CREDENTIAL_FIELDS) if (field in redacted) redacted[field] = "[REDACTED]";
|
|
25
|
+
return redacted;
|
|
26
|
+
};
|
|
27
|
+
const normalizeKey = (key) => key.toLowerCase().replace(/[-_]/g, "");
|
|
28
|
+
const isPlainObject = (value) => {
|
|
29
|
+
if (!isObject(value)) return false;
|
|
30
|
+
const prototype = Object.getPrototypeOf(value);
|
|
31
|
+
return prototype === Object.prototype || prototype === null;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Replaces the value of every key in `keys` (normalized) with `[REDACTED]`, through plain objects and arrays.
|
|
35
|
+
* Class instances, such as the MCP client inside an `mcpToTool()` tool, are returned as they are.
|
|
36
|
+
*/
|
|
37
|
+
function redactKeys(value, keys) {
|
|
38
|
+
if (Array.isArray(value)) return value.map((item) => redactKeys(item, keys));
|
|
39
|
+
if (!isPlainObject(value)) return value;
|
|
40
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, keys.has(normalizeKey(key)) ? "[REDACTED]" : redactKeys(item, keys)]));
|
|
41
|
+
}
|
|
42
|
+
const GEMINI_TOOL_FIELDS = new Set([
|
|
43
|
+
"codeExecution",
|
|
44
|
+
"computerUse",
|
|
45
|
+
"enterpriseWebSearch",
|
|
46
|
+
"exaAiSearch",
|
|
47
|
+
"fileSearch",
|
|
48
|
+
"functionDeclarations",
|
|
49
|
+
"googleMaps",
|
|
50
|
+
"googleSearch",
|
|
51
|
+
"googleSearchRetrieval",
|
|
52
|
+
"mcpServers",
|
|
53
|
+
"parallelAiSearch",
|
|
54
|
+
"retrieval",
|
|
55
|
+
"urlContext"
|
|
56
|
+
].map(normalizeKey));
|
|
57
|
+
const GEMINI_SCHEMA_FIELD = normalizeKey("functionDeclarations");
|
|
58
|
+
const GEMINI_CREDENTIAL_KEYS = new Set([
|
|
59
|
+
"apiAuth",
|
|
60
|
+
"authConfig",
|
|
61
|
+
"apiKey",
|
|
62
|
+
"headers"
|
|
63
|
+
].map(normalizeKey));
|
|
64
|
+
const isGeminiTool = (tool) => Object.keys(tool).map(normalizeKey).some((key) => key !== GEMINI_SCHEMA_FIELD && GEMINI_TOOL_FIELDS.has(key));
|
|
65
|
+
/**
|
|
66
|
+
* Masks the credential keys under every field of a `@google/genai` tool except its function declarations.
|
|
67
|
+
* A class-based tool, such as `mcpToTool(client)`, holds a live client with its auth headers, so only a stub is kept.
|
|
68
|
+
*/
|
|
69
|
+
function redactGeminiToolDefinition(tool) {
|
|
70
|
+
if (!isPlainObject(tool)) return isObject(tool) ? { type: "callable_tool" } : tool;
|
|
71
|
+
return Object.fromEntries(Object.entries(tool).map(([key, value]) => [key, normalizeKey(key) === GEMINI_SCHEMA_FIELD ? value : redactKeys(toJsonSafeValue(value), GEMINI_CREDENTIAL_KEYS)]));
|
|
72
|
+
}
|
|
73
|
+
/** Hides the credentials of a remote MCP or Gemini tool definition; everything else is kept as sent. */
|
|
74
|
+
function redactMcpToolDefinition(tool) {
|
|
75
|
+
if (!isObject(tool)) return tool;
|
|
76
|
+
if (typeof tool.type === "string" && MCP_TOOL_TYPES.has(tool.type)) return withoutMcpCredentials(tool);
|
|
77
|
+
if (isMcpProviderTool(tool) && isObject(tool.args)) return {
|
|
78
|
+
...tool,
|
|
79
|
+
args: withoutMcpCredentials(tool.args)
|
|
80
|
+
};
|
|
81
|
+
if (isPlainObject(tool) && isGeminiTool(tool)) return redactGeminiToolDefinition(tool);
|
|
82
|
+
return tool;
|
|
83
|
+
}
|
|
84
|
+
function redactMcpToolCredentials(tools) {
|
|
85
|
+
return Array.isArray(tools) ? tools.map(redactMcpToolDefinition) : tools;
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
13
88
|
//#region src/captureAiEvent.ts
|
|
14
89
|
/** @internal */
|
|
15
90
|
function isFullAiCaptureEnabled(client) {
|
|
@@ -548,7 +623,7 @@ const extractAvailableToolCalls = (provider, params) => {
|
|
|
548
623
|
if (params.tools) return params.tools;
|
|
549
624
|
return null;
|
|
550
625
|
} else if (provider === "gemini") {
|
|
551
|
-
if (params.config && params.config.tools) return params.config.tools;
|
|
626
|
+
if (params.config && Array.isArray(params.config.tools)) return params.config.tools.map(redactGeminiToolDefinition);
|
|
552
627
|
return null;
|
|
553
628
|
} else if (provider === "openai") {
|
|
554
629
|
if (params.tools) return params.tools;
|
|
@@ -631,7 +706,7 @@ function formatOpenAIResponsesInput(input, instructions) {
|
|
|
631
706
|
}
|
|
632
707
|
//#endregion
|
|
633
708
|
//#region package.json
|
|
634
|
-
var version = "8.22.
|
|
709
|
+
var version = "8.22.2";
|
|
635
710
|
//#endregion
|
|
636
711
|
//#region src/serializeError.ts
|
|
637
712
|
const DEFAULT_MAX_DEPTH = 3;
|
|
@@ -770,33 +845,6 @@ function truncateStack(stack) {
|
|
|
770
845
|
return [...lines.slice(0, MAX_STACK_LINES), "... (truncated)"].join("\n");
|
|
771
846
|
}
|
|
772
847
|
//#endregion
|
|
773
|
-
//#region src/mcpCredentials.ts
|
|
774
|
-
const MCP_CREDENTIAL_FIELDS = ["headers", "authorization"];
|
|
775
|
-
const MCP_PROVIDER_TOOL_IDS = /* @__PURE__ */ new Set([
|
|
776
|
-
"openai.mcp",
|
|
777
|
-
"xai.mcp",
|
|
778
|
-
"google.mcp_server"
|
|
779
|
-
]);
|
|
780
|
-
const isMcpProviderTool = (tool) => (tool.type === "provider" || tool.type === "provider-defined") && typeof tool.id === "string" && MCP_PROVIDER_TOOL_IDS.has(tool.id);
|
|
781
|
-
const withoutMcpCredentials = (config) => {
|
|
782
|
-
const redacted = { ...config };
|
|
783
|
-
for (const field of MCP_CREDENTIAL_FIELDS) if (field in redacted) redacted[field] = "[REDACTED]";
|
|
784
|
-
return redacted;
|
|
785
|
-
};
|
|
786
|
-
/** Hides the credentials of a remote MCP tool definition; everything else is kept as sent. */
|
|
787
|
-
function redactMcpToolDefinition(tool) {
|
|
788
|
-
if (!isObject(tool)) return tool;
|
|
789
|
-
if (tool.type === "mcp") return withoutMcpCredentials(tool);
|
|
790
|
-
if (isMcpProviderTool(tool) && isObject(tool.args)) return {
|
|
791
|
-
...tool,
|
|
792
|
-
args: withoutMcpCredentials(tool.args)
|
|
793
|
-
};
|
|
794
|
-
return tool;
|
|
795
|
-
}
|
|
796
|
-
function redactMcpToolCredentials(tools) {
|
|
797
|
-
return Array.isArray(tools) ? tools.map(redactMcpToolDefinition) : tools;
|
|
798
|
-
}
|
|
799
|
-
//#endregion
|
|
800
848
|
//#region src/gatewayWarning.ts
|
|
801
849
|
const POSTHOG_AI_GATEWAY_HOSTS = [
|
|
802
850
|
"gateway.posthog.com",
|