@posthog/ai 8.22.3 → 8.22.5
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 +40 -8
- package/dist/adk/index.cjs.map +1 -1
- package/dist/adk/index.mjs +40 -8
- package/dist/adk/index.mjs.map +1 -1
- package/dist/anthropic/index.cjs +40 -8
- package/dist/anthropic/index.cjs.map +1 -1
- package/dist/anthropic/index.mjs +40 -8
- package/dist/anthropic/index.mjs.map +1 -1
- package/dist/claude-agent-sdk/index.cjs +40 -8
- package/dist/claude-agent-sdk/index.cjs.map +1 -1
- package/dist/claude-agent-sdk/index.mjs +40 -8
- package/dist/claude-agent-sdk/index.mjs.map +1 -1
- package/dist/gemini/index.cjs +40 -8
- package/dist/gemini/index.cjs.map +1 -1
- package/dist/gemini/index.mjs +40 -8
- package/dist/gemini/index.mjs.map +1 -1
- package/dist/genkit/index.cjs +86 -19
- package/dist/genkit/index.cjs.map +1 -1
- package/dist/genkit/index.mjs +86 -19
- package/dist/genkit/index.mjs.map +1 -1
- package/dist/index.cjs +40 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +40 -8
- package/dist/index.mjs.map +1 -1
- package/dist/langchain/index.cjs +64 -13
- package/dist/langchain/index.cjs.map +1 -1
- package/dist/langchain/index.mjs +64 -13
- package/dist/langchain/index.mjs.map +1 -1
- package/dist/langchain/middleware/index.cjs +64 -13
- package/dist/langchain/middleware/index.cjs.map +1 -1
- package/dist/langchain/middleware/index.mjs +64 -13
- package/dist/langchain/middleware/index.mjs.map +1 -1
- package/dist/openai/index.cjs +40 -8
- package/dist/openai/index.cjs.map +1 -1
- package/dist/openai/index.mjs +40 -8
- package/dist/openai/index.mjs.map +1 -1
- package/dist/openai-agents/index.cjs +2 -2
- package/dist/openai-agents/index.cjs.map +1 -1
- package/dist/openai-agents/index.mjs +2 -2
- package/dist/openai-agents/index.mjs.map +1 -1
- package/dist/otel/index.browser.cjs +39 -7
- package/dist/otel/index.browser.cjs.map +1 -1
- package/dist/otel/index.browser.mjs +39 -7
- package/dist/otel/index.browser.mjs.map +1 -1
- package/dist/otel/index.cjs +39 -7
- package/dist/otel/index.cjs.map +1 -1
- package/dist/otel/index.mjs +39 -7
- package/dist/otel/index.mjs.map +1 -1
- package/dist/vercel/index.cjs +40 -8
- package/dist/vercel/index.cjs.map +1 -1
- package/dist/vercel/index.mjs +40 -8
- package/dist/vercel/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/genkit/index.cjs
CHANGED
|
@@ -2,7 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
let _posthog_core = require("@posthog/core");
|
|
3
3
|
let uuid = require("uuid");
|
|
4
4
|
//#region package.json
|
|
5
|
-
var version = "8.22.
|
|
5
|
+
var version = "8.22.5";
|
|
6
6
|
//#endregion
|
|
7
7
|
//#region src/captureAiEvent.ts
|
|
8
8
|
/** @internal */
|
|
@@ -113,20 +113,52 @@ const withoutMcpCredentials = (config) => {
|
|
|
113
113
|
for (const field of MCP_CREDENTIAL_FIELDS) if (field in redacted) redacted[field] = "[REDACTED]";
|
|
114
114
|
return redacted;
|
|
115
115
|
};
|
|
116
|
-
const normalizeKey = (key) => key.toLowerCase().replace(/[-_]/g, "");
|
|
116
|
+
const normalizeKey = (key) => key.toLowerCase().replace(/[-_\s]/g, "");
|
|
117
117
|
const isPlainObject = (value) => {
|
|
118
118
|
if (!isObject(value)) return false;
|
|
119
119
|
const prototype = Object.getPrototypeOf(value);
|
|
120
120
|
return prototype === Object.prototype || prototype === null;
|
|
121
121
|
};
|
|
122
|
+
const MAX_REDACT_DEPTH = 64;
|
|
122
123
|
/**
|
|
123
|
-
* Replaces the value of every key
|
|
124
|
-
*
|
|
124
|
+
* Replaces the value of every key that `isCredentialKey` accepts (normalized) with `[REDACTED]`, through plain
|
|
125
|
+
* objects, arrays and JSON strings. Other strings that name a credential key or form field are replaced whole, and values nested deeper than 64 levels become
|
|
126
|
+
* `[Truncated]`. Class instances, such as the MCP client inside an `mcpToTool()` tool, are returned as they are.
|
|
125
127
|
*/
|
|
126
|
-
function redactKeys(value,
|
|
127
|
-
if (
|
|
128
|
+
function redactKeys(value, isCredentialKey, depth = 0) {
|
|
129
|
+
if (depth > MAX_REDACT_DEPTH) return "[Truncated]";
|
|
130
|
+
if (typeof value === "string") return redactJsonString(value, isCredentialKey, depth);
|
|
131
|
+
if (Array.isArray(value)) return value.map((item) => redactKeys(item, isCredentialKey, depth + 1));
|
|
128
132
|
if (!isPlainObject(value)) return value;
|
|
129
|
-
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key,
|
|
133
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, isCredentialKey(normalizeKey(key)) ? "[REDACTED]" : redactKeys(item, isCredentialKey, depth + 1)]));
|
|
134
|
+
}
|
|
135
|
+
const QUOTED_KEY = /["']([^"'\\\s:]{1,128})\\*["']\s*:/g;
|
|
136
|
+
const FORM_FIELD = /(?:^|[?&#;\s'"])([^&=?#;\s'"]+)=/g;
|
|
137
|
+
function namesCredential(text, isCredentialKey) {
|
|
138
|
+
for (const pattern of [QUOTED_KEY, FORM_FIELD]) for (const [, name] of text.matchAll(pattern)) if (isCredentialKey(normalizeKey(name))) return true;
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
function redactJsonString(value, isCredentialKey, depth) {
|
|
142
|
+
const namesOne = namesCredential(value, isCredentialKey);
|
|
143
|
+
const trimmed = value.trim();
|
|
144
|
+
if (/^[[{"]/.test(trimmed)) {
|
|
145
|
+
let parsed;
|
|
146
|
+
try {
|
|
147
|
+
parsed = JSON.parse(trimmed);
|
|
148
|
+
} catch {
|
|
149
|
+
return namesOne ? "[REDACTED]" : value;
|
|
150
|
+
}
|
|
151
|
+
const redacted = JSON.stringify(redactKeys(parsed, isCredentialKey, depth + 1));
|
|
152
|
+
return namesOne || !serializesTo(parsed, redacted) ? redacted : value;
|
|
153
|
+
}
|
|
154
|
+
return namesOne ? "[REDACTED]" : value;
|
|
155
|
+
}
|
|
156
|
+
function serializesTo(value, json) {
|
|
157
|
+
try {
|
|
158
|
+
return JSON.stringify(value) === json;
|
|
159
|
+
} catch {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
130
162
|
}
|
|
131
163
|
const GEMINI_TOOL_FIELDS = new Set([
|
|
132
164
|
"codeExecution",
|
|
@@ -157,7 +189,7 @@ const isGeminiTool = (tool) => Object.keys(tool).map(normalizeKey).some((key) =>
|
|
|
157
189
|
*/
|
|
158
190
|
function redactGeminiToolDefinition(tool) {
|
|
159
191
|
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((0, _posthog_core.toJsonSafeValue)(value), GEMINI_CREDENTIAL_KEYS)]));
|
|
192
|
+
return Object.fromEntries(Object.entries(tool).map(([key, value]) => [key, normalizeKey(key) === GEMINI_SCHEMA_FIELD ? value : redactKeys((0, _posthog_core.toJsonSafeValue)(value), (key) => GEMINI_CREDENTIAL_KEYS.has(key))]));
|
|
161
193
|
}
|
|
162
194
|
/** Hides the credentials of a remote MCP or Gemini tool definition; everything else is kept as sent. */
|
|
163
195
|
function redactMcpToolDefinition(tool) {
|
|
@@ -847,16 +879,51 @@ const MODEL_PARAMETER_KEYS = [
|
|
|
847
879
|
"topP",
|
|
848
880
|
"stopSequences"
|
|
849
881
|
];
|
|
850
|
-
const
|
|
851
|
-
"
|
|
852
|
-
"
|
|
853
|
-
"authorization",
|
|
854
|
-
"clientSecret",
|
|
855
|
-
"headers",
|
|
856
|
-
"password",
|
|
882
|
+
const CREDENTIAL_KEY_SUFFIXES = [
|
|
883
|
+
"token",
|
|
884
|
+
"tokens",
|
|
857
885
|
"secret",
|
|
858
|
-
"
|
|
859
|
-
|
|
886
|
+
"secrets",
|
|
887
|
+
"secretkey",
|
|
888
|
+
"password",
|
|
889
|
+
"passwords",
|
|
890
|
+
"passwd",
|
|
891
|
+
"apikey",
|
|
892
|
+
"apikeys",
|
|
893
|
+
"privatekey",
|
|
894
|
+
"accesskey",
|
|
895
|
+
"authorization",
|
|
896
|
+
"cookie",
|
|
897
|
+
"cookies",
|
|
898
|
+
"credential",
|
|
899
|
+
"credentials",
|
|
900
|
+
"headers"
|
|
901
|
+
];
|
|
902
|
+
const TOKEN_COUNT_KEYS = /* @__PURE__ */ new Set([
|
|
903
|
+
"maxtokens",
|
|
904
|
+
"maxoutputtokens",
|
|
905
|
+
"maxcompletiontokens",
|
|
906
|
+
"inputtokens",
|
|
907
|
+
"outputtokens",
|
|
908
|
+
"totaltokens",
|
|
909
|
+
"prompttokens",
|
|
910
|
+
"completiontokens",
|
|
911
|
+
"reasoningtokens",
|
|
912
|
+
"thoughtstokens",
|
|
913
|
+
"cachedtokens",
|
|
914
|
+
"cachedcontenttokens",
|
|
915
|
+
"cachecreationinputtokens",
|
|
916
|
+
"cachereadinputtokens",
|
|
917
|
+
"budgettokens",
|
|
918
|
+
"thinkingtokens",
|
|
919
|
+
"audiotokens",
|
|
920
|
+
"acceptedpredictiontokens",
|
|
921
|
+
"rejectedpredictiontokens"
|
|
922
|
+
]);
|
|
923
|
+
const isCredentialKey = (key) => {
|
|
924
|
+
const name = key.replace(/header$/, "");
|
|
925
|
+
return !TOKEN_COUNT_KEYS.has(name) && CREDENTIAL_KEY_SUFFIXES.some((suffix) => name.endsWith(suffix));
|
|
926
|
+
};
|
|
860
927
|
const PROVIDER_NAMES = /* @__PURE__ */ new Map([["googleai", "gemini"], ["vertexai", "vertex"]]);
|
|
861
928
|
const STACK_ERROR_NAME = /^([A-Za-z_$][\w$]*)(?=:|\n|$)/;
|
|
862
929
|
/**
|
|
@@ -1031,13 +1098,13 @@ var PostHogGenkitSpanProcessor = class {
|
|
|
1031
1098
|
}
|
|
1032
1099
|
_formatState(span, key) {
|
|
1033
1100
|
if (isPrivacyModeEnabled(this._client, this._privacyMode)) return null;
|
|
1034
|
-
return formatToolResult(redactKeys(parseAttribute(span, key),
|
|
1101
|
+
return formatToolResult(redactKeys(parseAttribute(span, key), isCredentialKey), this._client, MAX_OUTPUT_SIZE);
|
|
1035
1102
|
}
|
|
1036
1103
|
_formatMessages(messages) {
|
|
1037
1104
|
return formatToolResult(redactKeys(messages.map((message) => ({
|
|
1038
1105
|
role: message.role === "model" ? "assistant" : message.role,
|
|
1039
1106
|
content: (message.content ?? []).map((part) => formatPart(part, this._client))
|
|
1040
|
-
})),
|
|
1107
|
+
})), isCredentialKey), this._client, MAX_OUTPUT_SIZE);
|
|
1041
1108
|
}
|
|
1042
1109
|
};
|
|
1043
1110
|
function formatPart(part, client) {
|