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