@posthog/ai 8.20.2 → 8.21.1
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 +20 -0
- package/dist/adk/index.cjs +101 -22
- package/dist/adk/index.cjs.map +1 -1
- package/dist/adk/index.d.ts +7 -0
- package/dist/adk/index.mjs +102 -23
- package/dist/adk/index.mjs.map +1 -1
- package/dist/anthropic/index.cjs +92 -9
- package/dist/anthropic/index.cjs.map +1 -1
- package/dist/anthropic/index.d.ts +7 -0
- package/dist/anthropic/index.mjs +93 -10
- package/dist/anthropic/index.mjs.map +1 -1
- package/dist/claude-agent-sdk/index.cjs +107 -21
- package/dist/claude-agent-sdk/index.cjs.map +1 -1
- package/dist/claude-agent-sdk/index.d.ts +6 -0
- package/dist/claude-agent-sdk/index.mjs +108 -22
- package/dist/claude-agent-sdk/index.mjs.map +1 -1
- package/dist/gemini/index.cjs +92 -9
- package/dist/gemini/index.cjs.map +1 -1
- package/dist/gemini/index.d.ts +7 -0
- package/dist/gemini/index.mjs +92 -9
- package/dist/gemini/index.mjs.map +1 -1
- package/dist/genkit/index.cjs +114 -29
- package/dist/genkit/index.cjs.map +1 -1
- package/dist/genkit/index.d.ts +7 -0
- package/dist/genkit/index.mjs +114 -29
- package/dist/genkit/index.mjs.map +1 -1
- package/dist/index.cjs +90 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +11 -0
- package/dist/index.mjs +91 -8
- package/dist/index.mjs.map +1 -1
- package/dist/langchain/index.cjs +75 -7
- package/dist/langchain/index.cjs.map +1 -1
- package/dist/langchain/index.d.ts +7 -0
- package/dist/langchain/index.mjs +75 -7
- package/dist/langchain/index.mjs.map +1 -1
- package/dist/langchain/middleware/index.cjs +75 -7
- package/dist/langchain/middleware/index.cjs.map +1 -1
- package/dist/langchain/middleware/index.d.ts +6 -0
- package/dist/langchain/middleware/index.mjs +75 -7
- package/dist/langchain/middleware/index.mjs.map +1 -1
- package/dist/openai/index.cjs +91 -8
- package/dist/openai/index.cjs.map +1 -1
- package/dist/openai/index.d.ts +7 -0
- package/dist/openai/index.mjs +92 -9
- package/dist/openai/index.mjs.map +1 -1
- package/dist/openai-agents/index.cjs +115 -46
- package/dist/openai-agents/index.cjs.map +1 -1
- package/dist/openai-agents/index.d.ts +7 -0
- package/dist/openai-agents/index.mjs +115 -46
- package/dist/openai-agents/index.mjs.map +1 -1
- package/dist/otel/index.browser.cjs.map +1 -1
- package/dist/otel/index.browser.mjs.map +1 -1
- package/dist/otel/index.cjs.map +1 -1
- package/dist/otel/index.d.ts +3 -3
- package/dist/otel/index.mjs.map +1 -1
- package/dist/vercel/index.cjs +90 -7
- package/dist/vercel/index.cjs.map +1 -1
- package/dist/vercel/index.d.ts +6 -0
- package/dist/vercel/index.mjs +91 -8
- package/dist/vercel/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/langchain/index.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
require("uuid");
|
|
3
|
+
let _posthog_core = require("@posthog/core");
|
|
3
4
|
let _langchain_core_callbacks_base = require("@langchain/core/callbacks/base");
|
|
4
5
|
//#region src/typeGuards.ts
|
|
5
6
|
const isObject = (value) => {
|
|
@@ -11,9 +12,77 @@ const isObject = (value) => {
|
|
|
11
12
|
function isFullAiCaptureEnabled(client) {
|
|
12
13
|
return client?.enableFullAiCapture === true;
|
|
13
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* The caller's distinct id as a string, or undefined when it is missing, empty or only whitespace.
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
function userDistinctId(value) {
|
|
21
|
+
if (!value) return;
|
|
22
|
+
const id = String(value);
|
|
23
|
+
return id.trim() === "" ? void 0 : id;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The caller's per-event options when they are an object. A missing or `null` value means no
|
|
27
|
+
* options. An array or any other value is reported and ignored, so it is never spread.
|
|
28
|
+
*
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
function readAiEventOptions(value) {
|
|
32
|
+
if (value === void 0 || value === null) return;
|
|
33
|
+
if (typeof value === "object" && !Array.isArray(value)) return value;
|
|
34
|
+
console.warn(`[PostHog AI] options must be an object, got ${Array.isArray(value) ? "array" : typeof value}; ignoring them`);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The `properties` and `options` for an AI event. `personless` (no user distinct id) turns person
|
|
38
|
+
* processing off and beats the caller's `process_person_profile`.
|
|
39
|
+
*
|
|
40
|
+
* posthog-node 6 takes the options as they are, so no option is written as a property.
|
|
41
|
+
* posthog-node 5 has no per-event options: each known option is sent as the property that version
|
|
42
|
+
* reads, and an unknown key is dropped.
|
|
43
|
+
*
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
function eventOptionFields(client, properties, options, personless) {
|
|
47
|
+
const userOptions = readAiEventOptions(options);
|
|
48
|
+
if (isPostHogNode6(client)) {
|
|
49
|
+
const eventOptions = {
|
|
50
|
+
...userOptions,
|
|
51
|
+
...personless ? { process_person_profile: false } : {}
|
|
52
|
+
};
|
|
53
|
+
return Object.keys(eventOptions).length > 0 ? {
|
|
54
|
+
properties,
|
|
55
|
+
options: eventOptions
|
|
56
|
+
} : { properties };
|
|
57
|
+
}
|
|
58
|
+
const withOptionProperties = {
|
|
59
|
+
...properties,
|
|
60
|
+
...(0, _posthog_core.eventOptionsAsLegacyProperties)(userOptions)
|
|
61
|
+
};
|
|
62
|
+
if (personless) withOptionProperties.$process_person_profile = false;
|
|
63
|
+
return { properties: withOptionProperties };
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Whether the client is posthog-node 6 or later, the first major with per-event options.
|
|
67
|
+
*
|
|
68
|
+
* @internal
|
|
69
|
+
*/
|
|
70
|
+
function isPostHogNode6(client) {
|
|
71
|
+
return (0, _posthog_core.acceptsEventOptions)(client);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* posthog-node 6 sends every AI event on its capture v1 AI lane; `enableFullAiCapture` then only
|
|
75
|
+
* controls truncation and media redaction. posthog-node 5 keeps the opt-in, so an `@posthog/ai`
|
|
76
|
+
* upgrade never changes how a 5.x client sends.
|
|
77
|
+
*
|
|
78
|
+
* @internal
|
|
79
|
+
*/
|
|
80
|
+
function usesAiLane(client) {
|
|
81
|
+
return isPostHogNode6(client) || isFullAiCaptureEnabled(client);
|
|
82
|
+
}
|
|
14
83
|
/** @internal */
|
|
15
84
|
function captureAiEvent(client, event) {
|
|
16
|
-
if (
|
|
85
|
+
if (usesAiLane(client) && typeof client.captureAi === "function") {
|
|
17
86
|
client.captureAi(event);
|
|
18
87
|
return;
|
|
19
88
|
}
|
|
@@ -318,7 +387,7 @@ function redactMcpToolCredentials(tools) {
|
|
|
318
387
|
}
|
|
319
388
|
//#endregion
|
|
320
389
|
//#region package.json
|
|
321
|
-
var version = "8.
|
|
390
|
+
var version = "8.21.1";
|
|
322
391
|
//#endregion
|
|
323
392
|
//#region src/serializeError.ts
|
|
324
393
|
const DEFAULT_MAX_DEPTH = 3;
|
|
@@ -521,9 +590,10 @@ var LangChainCallbackHandler = class extends _langchain_core_callbacks_base.Base
|
|
|
521
590
|
this.runs = {};
|
|
522
591
|
this.parentTree = {};
|
|
523
592
|
this.client = options.client;
|
|
524
|
-
this.distinctId = options.distinctId;
|
|
593
|
+
this.distinctId = userDistinctId(options.distinctId);
|
|
525
594
|
this.traceId = options.traceId;
|
|
526
595
|
this.properties = options.properties || {};
|
|
596
|
+
this.eventOptions = options.options;
|
|
527
597
|
this.privacyMode = options.privacyMode || false;
|
|
528
598
|
this.groups = options.groups || {};
|
|
529
599
|
this.debug = options.debug || false;
|
|
@@ -736,7 +806,6 @@ var LangChainCallbackHandler = class extends _langchain_core_callbacks_base.Base
|
|
|
736
806
|
};
|
|
737
807
|
if (parentRunId) eventProperties["$ai_parent_id"] = parentRunId;
|
|
738
808
|
Object.assign(eventProperties, this.properties);
|
|
739
|
-
if (!this.distinctId) eventProperties["$process_person_profile"] = false;
|
|
740
809
|
if (outputs instanceof Error) {
|
|
741
810
|
if (isLangGraphControlFlow(outputs)) {
|
|
742
811
|
const interrupts = outputs.interrupts;
|
|
@@ -749,7 +818,7 @@ var LangChainCallbackHandler = class extends _langchain_core_callbacks_base.Base
|
|
|
749
818
|
this._safeCapture({
|
|
750
819
|
distinctId: this.distinctId ? this.distinctId.toString() : runId,
|
|
751
820
|
event: eventName,
|
|
752
|
-
|
|
821
|
+
...eventOptionFields(this.client, eventProperties, this.eventOptions, !this.distinctId),
|
|
753
822
|
groups: this.groups
|
|
754
823
|
});
|
|
755
824
|
}
|
|
@@ -825,11 +894,10 @@ var LangChainCallbackHandler = class extends _langchain_core_callbacks_base.Base
|
|
|
825
894
|
if (completions) eventProperties["$ai_output_choices"] = withPrivacyMode(this.client, this.privacyMode, completions);
|
|
826
895
|
}
|
|
827
896
|
Object.assign(eventProperties, this.properties);
|
|
828
|
-
if (!this.distinctId) eventProperties["$process_person_profile"] = false;
|
|
829
897
|
this._safeCapture({
|
|
830
898
|
distinctId: this.distinctId ? this.distinctId.toString() : traceId,
|
|
831
899
|
event: "$ai_generation",
|
|
832
|
-
|
|
900
|
+
...eventOptionFields(this.client, eventProperties, this.eventOptions, !this.distinctId),
|
|
833
901
|
groups: this.groups
|
|
834
902
|
});
|
|
835
903
|
}
|