@posthog/ai 8.10.0 → 8.10.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 +908 -1198
- package/dist/adk/index.cjs.map +1 -1
- package/dist/adk/index.d.ts +109 -109
- package/dist/adk/index.mjs +907 -1196
- package/dist/adk/index.mjs.map +1 -1
- package/dist/anthropic/index.cjs +927 -1111
- package/dist/anthropic/index.cjs.map +1 -1
- package/dist/anthropic/index.d.ts +34 -33
- package/dist/anthropic/index.mjs +899 -1102
- package/dist/anthropic/index.mjs.map +1 -1
- package/dist/gemini/index.cjs +863 -1108
- package/dist/gemini/index.cjs.map +1 -1
- package/dist/gemini/index.d.ts +38 -35
- package/dist/gemini/index.mjs +858 -1103
- package/dist/gemini/index.mjs.map +1 -1
- package/dist/index.cjs +1218 -1546
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +170 -163
- package/dist/index.mjs +1216 -1544
- package/dist/index.mjs.map +1 -1
- package/dist/langchain/index.cjs +851 -1029
- package/dist/langchain/index.cjs.map +1 -1
- package/dist/langchain/index.d.ts +75 -75
- package/dist/langchain/index.mjs +850 -1027
- package/dist/langchain/index.mjs.map +1 -1
- package/dist/langchain/middleware/index.cjs +1016 -1225
- package/dist/langchain/middleware/index.cjs.map +1 -1
- package/dist/langchain/middleware/index.d.ts +29 -25
- package/dist/langchain/middleware/index.mjs +1015 -1223
- package/dist/langchain/middleware/index.mjs.map +1 -1
- package/dist/openai/index.cjs +1990 -2523
- package/dist/openai/index.cjs.map +1 -1
- package/dist/openai/index.d.ts +106 -104
- package/dist/openai/index.mjs +1985 -2518
- package/dist/openai/index.mjs.map +1 -1
- package/dist/openai-agents/index.cjs +745 -827
- package/dist/openai-agents/index.cjs.map +1 -1
- package/dist/openai-agents/index.d.ts +48 -47
- package/dist/openai-agents/index.mjs +744 -825
- package/dist/openai-agents/index.mjs.map +1 -1
- package/dist/otel/index.cjs +427 -486
- package/dist/otel/index.cjs.map +1 -1
- package/dist/otel/index.d.ts +36 -35
- package/dist/otel/index.mjs +426 -484
- package/dist/otel/index.mjs.map +1 -1
- package/dist/vercel/index.cjs +992 -1343
- package/dist/vercel/index.cjs.map +1 -1
- package/dist/vercel/index.d.ts +21 -16
- package/dist/vercel/index.mjs +991 -1341
- package/dist/vercel/index.mjs.map +1 -1
- package/package.json +15 -14
package/dist/adk/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { BasePlugin, Context, InvocationContext,
|
|
2
|
-
import { Content } from
|
|
3
|
-
import { PostHog } from
|
|
4
|
-
|
|
1
|
+
import { BaseAgent, BasePlugin, BaseTool, Context, InvocationContext, LlmRequest, LlmResponse } from "@google/adk";
|
|
2
|
+
import { Content } from "@google/genai";
|
|
3
|
+
import { PostHog } from "posthog-node";
|
|
4
|
+
//#region src/adk/plugin.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* Resolver for the PostHog distinct ID. Either a static string, or a function
|
|
7
7
|
* that derives it from the ADK model callback context (e.g. from
|
|
@@ -10,30 +10,30 @@ import { PostHog } from 'posthog-node';
|
|
|
10
10
|
*/
|
|
11
11
|
type DistinctIdResolver = string | ((context: Context) => string | null | undefined);
|
|
12
12
|
interface PostHogADKPluginOptions {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
13
|
+
/** The PostHog client used to capture events. */
|
|
14
|
+
client: PostHog;
|
|
15
|
+
/**
|
|
16
|
+
* Distinct ID for the captured events. When omitted, the ADK
|
|
17
|
+
* `callbackContext.userId` is used if present, otherwise events are captured
|
|
18
|
+
* anonymously (personless) keyed by the trace ID.
|
|
19
|
+
*/
|
|
20
|
+
distinctId?: DistinctIdResolver;
|
|
21
|
+
/**
|
|
22
|
+
* Provider label recorded on `$ai_provider`. Defaults to `'gemini'` since ADK
|
|
23
|
+
* defaults to Gemini models. Set this when routing ADK to another provider so
|
|
24
|
+
* PostHog attributes cost to the right model catalog.
|
|
25
|
+
*/
|
|
26
|
+
provider?: string;
|
|
27
|
+
/** Redacts captured input/output content when true. Defaults to false. */
|
|
28
|
+
privacyMode?: boolean;
|
|
29
|
+
/** Group analytics mapping (group type -> group id) attached to every event. */
|
|
30
|
+
groups?: Record<string, string | number>;
|
|
31
|
+
/** Extra properties merged into every captured AI event. */
|
|
32
|
+
properties?: Record<string, unknown>;
|
|
33
|
+
/** Awaits event delivery instead of batching. Useful in serverless environments. */
|
|
34
|
+
captureImmediate?: boolean;
|
|
35
|
+
/** Invoked when the plugin fails to capture an event. Never throws into the model flow. */
|
|
36
|
+
onError?: (error: unknown) => void;
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
39
|
* A Google ADK (`@google/adk`) `BasePlugin` that captures PostHog AI traces,
|
|
@@ -65,85 +65,85 @@ interface PostHogADKPluginOptions {
|
|
|
65
65
|
* ```
|
|
66
66
|
*/
|
|
67
67
|
declare class PostHogADKPlugin extends BasePlugin {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
68
|
+
private readonly _client;
|
|
69
|
+
private readonly _distinctId?;
|
|
70
|
+
private readonly _provider;
|
|
71
|
+
private readonly _privacyMode;
|
|
72
|
+
private readonly _groups?;
|
|
73
|
+
private readonly _properties;
|
|
74
|
+
private readonly _captureImmediate;
|
|
75
|
+
private readonly _onError?;
|
|
76
|
+
/** FIFO of in-flight model calls for each invocation branch and agent. */
|
|
77
|
+
private readonly _pending;
|
|
78
|
+
private readonly _traces;
|
|
79
|
+
private readonly _pendingAgents;
|
|
80
|
+
private readonly _pendingTools;
|
|
81
|
+
constructor(options: PostHogADKPluginOptions);
|
|
82
|
+
beforeRunCallback({ invocationContext }: {
|
|
83
|
+
invocationContext: InvocationContext;
|
|
84
|
+
}): Promise<Content | undefined>;
|
|
85
|
+
afterRunCallback({ invocationContext }: {
|
|
86
|
+
invocationContext: InvocationContext;
|
|
87
|
+
}): Promise<void>;
|
|
88
|
+
beforeAgentCallback({ agent, callbackContext }: {
|
|
89
|
+
agent: BaseAgent;
|
|
90
|
+
callbackContext: Context;
|
|
91
|
+
}): Promise<Content | undefined>;
|
|
92
|
+
afterAgentCallback({ callbackContext }: {
|
|
93
|
+
agent: BaseAgent;
|
|
94
|
+
callbackContext: Context;
|
|
95
|
+
}): Promise<Content | undefined>;
|
|
96
|
+
beforeModelCallback({ callbackContext, llmRequest }: {
|
|
97
|
+
callbackContext: Context;
|
|
98
|
+
llmRequest: LlmRequest;
|
|
99
|
+
}): Promise<LlmResponse | undefined>;
|
|
100
|
+
afterModelCallback({ callbackContext, llmResponse }: {
|
|
101
|
+
callbackContext: Context;
|
|
102
|
+
llmResponse: LlmResponse;
|
|
103
|
+
}): Promise<LlmResponse | undefined>;
|
|
104
|
+
onModelErrorCallback({ callbackContext, llmRequest, error }: {
|
|
105
|
+
callbackContext: Context;
|
|
106
|
+
llmRequest: LlmRequest;
|
|
107
|
+
error: Error;
|
|
108
|
+
}): Promise<LlmResponse | undefined>;
|
|
109
|
+
beforeToolCallback({ tool, toolArgs, toolContext }: {
|
|
110
|
+
tool: BaseTool;
|
|
111
|
+
toolArgs: Record<string, unknown>;
|
|
112
|
+
toolContext: Context;
|
|
113
|
+
}): Promise<Record<string, unknown> | undefined>;
|
|
114
|
+
afterToolCallback({ tool, toolContext, result }: {
|
|
115
|
+
tool: BaseTool;
|
|
116
|
+
toolArgs: Record<string, unknown>;
|
|
117
|
+
toolContext: Context;
|
|
118
|
+
result: Record<string, unknown>;
|
|
119
|
+
}): Promise<Record<string, unknown> | undefined>;
|
|
120
|
+
onToolErrorCallback({ tool, toolContext, error }: {
|
|
121
|
+
tool: BaseTool;
|
|
122
|
+
toolArgs: Record<string, unknown>;
|
|
123
|
+
toolContext: Context;
|
|
124
|
+
error: Error;
|
|
125
|
+
}): Promise<Record<string, unknown> | undefined>;
|
|
126
|
+
private _capture;
|
|
127
|
+
private _captureToolSpan;
|
|
128
|
+
private _captureLifecycleEvent;
|
|
129
|
+
private _resolveDistinctId;
|
|
130
|
+
private _resolveInvocationDistinctId;
|
|
131
|
+
private _rememberContext;
|
|
132
|
+
private _parentSpanId;
|
|
133
|
+
private _pendingKey;
|
|
134
|
+
private _toolKey;
|
|
135
|
+
private _peekPending;
|
|
136
|
+
private _takePending;
|
|
137
|
+
private _takePendingAgent;
|
|
138
|
+
private _takePendingTool;
|
|
139
|
+
private _isNonTerminalStreamResponse;
|
|
140
|
+
private _evictStalePending;
|
|
141
|
+
private _evictStaleQueueEntries;
|
|
142
|
+
private _clearPendingInvocation;
|
|
143
|
+
private _formatInput;
|
|
144
|
+
private _formatOutput;
|
|
145
|
+
private _handleError;
|
|
146
146
|
}
|
|
147
|
-
|
|
148
|
-
export { PostHogADKPlugin };
|
|
149
|
-
|
|
147
|
+
//#endregion
|
|
148
|
+
export { type DistinctIdResolver, PostHogADKPlugin, type PostHogADKPluginOptions };
|
|
149
|
+
//# sourceMappingURL=index.d.ts.map
|