@posthog/ai 8.22.0 → 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 +144 -75
- package/dist/openai/index.cjs.map +1 -1
- package/dist/openai/index.mjs +144 -75
- 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 +3 -3
package/dist/gemini/index.cjs
CHANGED
|
@@ -103,6 +103,81 @@ const isObject = (value) => {
|
|
|
103
103
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
104
104
|
};
|
|
105
105
|
//#endregion
|
|
106
|
+
//#region src/mcpCredentials.ts
|
|
107
|
+
const MCP_CREDENTIAL_FIELDS = ["headers", "authorization"];
|
|
108
|
+
const MCP_TOOL_TYPES = /* @__PURE__ */ new Set(["mcp", "mcp_server"]);
|
|
109
|
+
const MCP_PROVIDER_TOOL_IDS = /* @__PURE__ */ new Set([
|
|
110
|
+
"openai.mcp",
|
|
111
|
+
"xai.mcp",
|
|
112
|
+
"google.mcp_server"
|
|
113
|
+
]);
|
|
114
|
+
const isMcpProviderTool = (tool) => (tool.type === "provider" || tool.type === "provider-defined") && typeof tool.id === "string" && MCP_PROVIDER_TOOL_IDS.has(tool.id);
|
|
115
|
+
const withoutMcpCredentials = (config) => {
|
|
116
|
+
const redacted = { ...config };
|
|
117
|
+
for (const field of MCP_CREDENTIAL_FIELDS) if (field in redacted) redacted[field] = "[REDACTED]";
|
|
118
|
+
return redacted;
|
|
119
|
+
};
|
|
120
|
+
const normalizeKey = (key) => key.toLowerCase().replace(/[-_]/g, "");
|
|
121
|
+
const isPlainObject = (value) => {
|
|
122
|
+
if (!isObject(value)) return false;
|
|
123
|
+
const prototype = Object.getPrototypeOf(value);
|
|
124
|
+
return prototype === Object.prototype || prototype === null;
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Replaces the value of every key in `keys` (normalized) with `[REDACTED]`, through plain objects and arrays.
|
|
128
|
+
* Class instances, such as the MCP client inside an `mcpToTool()` tool, are returned as they are.
|
|
129
|
+
*/
|
|
130
|
+
function redactKeys(value, keys) {
|
|
131
|
+
if (Array.isArray(value)) return value.map((item) => redactKeys(item, keys));
|
|
132
|
+
if (!isPlainObject(value)) return value;
|
|
133
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, keys.has(normalizeKey(key)) ? "[REDACTED]" : redactKeys(item, keys)]));
|
|
134
|
+
}
|
|
135
|
+
const GEMINI_TOOL_FIELDS = new Set([
|
|
136
|
+
"codeExecution",
|
|
137
|
+
"computerUse",
|
|
138
|
+
"enterpriseWebSearch",
|
|
139
|
+
"exaAiSearch",
|
|
140
|
+
"fileSearch",
|
|
141
|
+
"functionDeclarations",
|
|
142
|
+
"googleMaps",
|
|
143
|
+
"googleSearch",
|
|
144
|
+
"googleSearchRetrieval",
|
|
145
|
+
"mcpServers",
|
|
146
|
+
"parallelAiSearch",
|
|
147
|
+
"retrieval",
|
|
148
|
+
"urlContext"
|
|
149
|
+
].map(normalizeKey));
|
|
150
|
+
const GEMINI_SCHEMA_FIELD = normalizeKey("functionDeclarations");
|
|
151
|
+
const GEMINI_CREDENTIAL_KEYS = new Set([
|
|
152
|
+
"apiAuth",
|
|
153
|
+
"authConfig",
|
|
154
|
+
"apiKey",
|
|
155
|
+
"headers"
|
|
156
|
+
].map(normalizeKey));
|
|
157
|
+
const isGeminiTool = (tool) => Object.keys(tool).map(normalizeKey).some((key) => key !== GEMINI_SCHEMA_FIELD && GEMINI_TOOL_FIELDS.has(key));
|
|
158
|
+
/**
|
|
159
|
+
* Masks the credential keys under every field of a `@google/genai` tool except its function declarations.
|
|
160
|
+
* A class-based tool, such as `mcpToTool(client)`, holds a live client with its auth headers, so only a stub is kept.
|
|
161
|
+
*/
|
|
162
|
+
function redactGeminiToolDefinition(tool) {
|
|
163
|
+
if (!isPlainObject(tool)) return isObject(tool) ? { type: "callable_tool" } : tool;
|
|
164
|
+
return Object.fromEntries(Object.entries(tool).map(([key, value]) => [key, normalizeKey(key) === GEMINI_SCHEMA_FIELD ? value : redactKeys((0, _posthog_core.toJsonSafeValue)(value), GEMINI_CREDENTIAL_KEYS)]));
|
|
165
|
+
}
|
|
166
|
+
/** Hides the credentials of a remote MCP or Gemini tool definition; everything else is kept as sent. */
|
|
167
|
+
function redactMcpToolDefinition(tool) {
|
|
168
|
+
if (!isObject(tool)) return tool;
|
|
169
|
+
if (typeof tool.type === "string" && MCP_TOOL_TYPES.has(tool.type)) return withoutMcpCredentials(tool);
|
|
170
|
+
if (isMcpProviderTool(tool) && isObject(tool.args)) return {
|
|
171
|
+
...tool,
|
|
172
|
+
args: withoutMcpCredentials(tool.args)
|
|
173
|
+
};
|
|
174
|
+
if (isPlainObject(tool) && isGeminiTool(tool)) return redactGeminiToolDefinition(tool);
|
|
175
|
+
return tool;
|
|
176
|
+
}
|
|
177
|
+
function redactMcpToolCredentials(tools) {
|
|
178
|
+
return Array.isArray(tools) ? tools.map(redactMcpToolDefinition) : tools;
|
|
179
|
+
}
|
|
180
|
+
//#endregion
|
|
106
181
|
//#region src/sanitization/base64_recognizer.ts
|
|
107
182
|
const DATA_URL_PREFIX_RE = /^data:([^;,\s]+)(?:;[^;,\s]+)*;base64,/i;
|
|
108
183
|
const BASE64_ALPHABET_RE = /^[A-Za-z0-9+/_=-]+$/;
|
|
@@ -493,7 +568,7 @@ const extractAvailableToolCalls = (provider, params) => {
|
|
|
493
568
|
if (params.tools) return params.tools;
|
|
494
569
|
return null;
|
|
495
570
|
} else if (provider === "gemini") {
|
|
496
|
-
if (params.config && params.config.tools) return params.config.tools;
|
|
571
|
+
if (params.config && Array.isArray(params.config.tools)) return params.config.tools.map(redactGeminiToolDefinition);
|
|
497
572
|
return null;
|
|
498
573
|
} else if (provider === "openai") {
|
|
499
574
|
if (params.tools) return params.tools;
|
|
@@ -544,7 +619,7 @@ function addDefaults(params) {
|
|
|
544
619
|
}
|
|
545
620
|
//#endregion
|
|
546
621
|
//#region package.json
|
|
547
|
-
var version = "8.22.
|
|
622
|
+
var version = "8.22.2";
|
|
548
623
|
//#endregion
|
|
549
624
|
//#region src/serializeError.ts
|
|
550
625
|
const DEFAULT_MAX_DEPTH = 3;
|
|
@@ -683,33 +758,6 @@ function truncateStack(stack) {
|
|
|
683
758
|
return [...lines.slice(0, MAX_STACK_LINES), "... (truncated)"].join("\n");
|
|
684
759
|
}
|
|
685
760
|
//#endregion
|
|
686
|
-
//#region src/mcpCredentials.ts
|
|
687
|
-
const MCP_CREDENTIAL_FIELDS = ["headers", "authorization"];
|
|
688
|
-
const MCP_PROVIDER_TOOL_IDS = /* @__PURE__ */ new Set([
|
|
689
|
-
"openai.mcp",
|
|
690
|
-
"xai.mcp",
|
|
691
|
-
"google.mcp_server"
|
|
692
|
-
]);
|
|
693
|
-
const isMcpProviderTool = (tool) => (tool.type === "provider" || tool.type === "provider-defined") && typeof tool.id === "string" && MCP_PROVIDER_TOOL_IDS.has(tool.id);
|
|
694
|
-
const withoutMcpCredentials = (config) => {
|
|
695
|
-
const redacted = { ...config };
|
|
696
|
-
for (const field of MCP_CREDENTIAL_FIELDS) if (field in redacted) redacted[field] = "[REDACTED]";
|
|
697
|
-
return redacted;
|
|
698
|
-
};
|
|
699
|
-
/** Hides the credentials of a remote MCP tool definition; everything else is kept as sent. */
|
|
700
|
-
function redactMcpToolDefinition(tool) {
|
|
701
|
-
if (!isObject(tool)) return tool;
|
|
702
|
-
if (tool.type === "mcp") return withoutMcpCredentials(tool);
|
|
703
|
-
if (isMcpProviderTool(tool) && isObject(tool.args)) return {
|
|
704
|
-
...tool,
|
|
705
|
-
args: withoutMcpCredentials(tool.args)
|
|
706
|
-
};
|
|
707
|
-
return tool;
|
|
708
|
-
}
|
|
709
|
-
function redactMcpToolCredentials(tools) {
|
|
710
|
-
return Array.isArray(tools) ? tools.map(redactMcpToolDefinition) : tools;
|
|
711
|
-
}
|
|
712
|
-
//#endregion
|
|
713
761
|
//#region src/gatewayWarning.ts
|
|
714
762
|
const POSTHOG_AI_GATEWAY_HOSTS = [
|
|
715
763
|
"gateway.posthog.com",
|