@posthog/ai 8.24.0 → 8.24.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/dist/adk/index.cjs +1 -1
- package/dist/adk/index.mjs +1 -1
- package/dist/anthropic/index.cjs +1 -1
- package/dist/anthropic/index.mjs +1 -1
- package/dist/claude-agent-sdk/index.cjs +1 -1
- package/dist/claude-agent-sdk/index.mjs +1 -1
- package/dist/gemini/index.cjs +162 -13
- package/dist/gemini/index.cjs.map +1 -1
- package/dist/gemini/index.d.ts +2 -1
- package/dist/gemini/index.mjs +140 -13
- package/dist/gemini/index.mjs.map +1 -1
- package/dist/genkit/index.cjs +1 -1
- package/dist/genkit/index.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/langchain/index.cjs +1 -1
- package/dist/langchain/index.mjs +1 -1
- package/dist/langchain/middleware/index.cjs +1 -1
- package/dist/langchain/middleware/index.mjs +1 -1
- package/dist/openai/index.cjs +1 -1
- package/dist/openai/index.mjs +1 -1
- package/dist/openai-agents/index.cjs +1 -1
- package/dist/openai-agents/index.mjs +1 -1
- package/dist/vercel/index.cjs +1 -1
- package/dist/vercel/index.mjs +1 -1
- package/package.json +5 -5
package/dist/adk/index.cjs
CHANGED
|
@@ -3,7 +3,7 @@ let _google_adk = require("@google/adk");
|
|
|
3
3
|
let uuid = require("uuid");
|
|
4
4
|
let _posthog_core = require("@posthog/core");
|
|
5
5
|
//#region package.json
|
|
6
|
-
var version = "8.24.
|
|
6
|
+
var version = "8.24.1";
|
|
7
7
|
//#endregion
|
|
8
8
|
//#region src/typeGuards.ts
|
|
9
9
|
const isObject = (value) => {
|
package/dist/adk/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { BasePlugin } from "@google/adk";
|
|
|
2
2
|
import { v4 } from "uuid";
|
|
3
3
|
import { acceptsEventOptions, eventOptionsAsLegacyProperties, toJsonSafeValue, uuidv7 } from "@posthog/core";
|
|
4
4
|
//#region package.json
|
|
5
|
-
var version = "8.24.
|
|
5
|
+
var version = "8.24.1";
|
|
6
6
|
//#endregion
|
|
7
7
|
//#region src/typeGuards.ts
|
|
8
8
|
const isObject = (value) => {
|
package/dist/anthropic/index.cjs
CHANGED
package/dist/anthropic/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ let _anthropic_ai_claude_agent_sdk = require("@anthropic-ai/claude-agent-sdk");
|
|
|
3
3
|
let uuid = require("uuid");
|
|
4
4
|
let _posthog_core = require("@posthog/core");
|
|
5
5
|
//#region package.json
|
|
6
|
-
var version = "8.24.
|
|
6
|
+
var version = "8.24.1";
|
|
7
7
|
//#endregion
|
|
8
8
|
//#region src/captureAiEvent.ts
|
|
9
9
|
/** @internal */
|
|
@@ -2,7 +2,7 @@ import { SYSTEM_PROMPT_DYNAMIC_BOUNDARY, query as query$1 } from "@anthropic-ai/
|
|
|
2
2
|
import { v4 } from "uuid";
|
|
3
3
|
import { acceptsEventOptions, eventOptionsAsLegacyProperties, toJsonSafeValue, uuidv7 } from "@posthog/core";
|
|
4
4
|
//#region package.json
|
|
5
|
-
var version = "8.24.
|
|
5
|
+
var version = "8.24.1";
|
|
6
6
|
//#endregion
|
|
7
7
|
//#region src/captureAiEvent.ts
|
|
8
8
|
/** @internal */
|
package/dist/gemini/index.cjs
CHANGED
|
@@ -2,8 +2,31 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
+
//#region \0rolldown/runtime.js
|
|
6
|
+
var __create = Object.create;
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
9
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
10
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
14
|
+
key = keys[i];
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: ((k) => from[k]).bind(null, key),
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
//#endregion
|
|
5
27
|
let _posthog_core = require("@posthog/core");
|
|
6
28
|
let _google_genai = require("@google/genai");
|
|
29
|
+
_google_genai = __toESM(_google_genai);
|
|
7
30
|
let uuid = require("uuid");
|
|
8
31
|
//#region src/captureAiEvent.ts
|
|
9
32
|
/** @internal */
|
|
@@ -651,7 +674,7 @@ function addDefaults(params) {
|
|
|
651
674
|
}
|
|
652
675
|
//#endregion
|
|
653
676
|
//#region package.json
|
|
654
|
-
var version = "8.24.
|
|
677
|
+
var version = "8.24.1";
|
|
655
678
|
//#endregion
|
|
656
679
|
//#region src/serializeError.ts
|
|
657
680
|
const DEFAULT_MAX_DEPTH = 3;
|
|
@@ -1157,13 +1180,98 @@ function safeTools(tools) {
|
|
|
1157
1180
|
name: string(record(tool)?.name)
|
|
1158
1181
|
}));
|
|
1159
1182
|
}
|
|
1183
|
+
const USAGE_LIST_KEYS = {
|
|
1184
|
+
cached_tokens_by_modality: ["modality", "tokens"],
|
|
1185
|
+
input_tokens_by_modality: ["modality", "tokens"],
|
|
1186
|
+
output_tokens_by_modality: ["modality", "tokens"],
|
|
1187
|
+
tool_use_tokens_by_modality: ["modality", "tokens"],
|
|
1188
|
+
grounding_tool_count: ["type", "count"]
|
|
1189
|
+
};
|
|
1190
|
+
function mergeHopUsage(usages) {
|
|
1191
|
+
if (usages.length <= 1) return usages[0];
|
|
1192
|
+
const merged = { ...usages[usages.length - 1] };
|
|
1193
|
+
for (const name of new Set(usages.flatMap((usage) => Object.keys(usage)))) {
|
|
1194
|
+
const values = usages.map((usage) => usage[name]).filter((value) => value !== void 0 && value !== null);
|
|
1195
|
+
if (values.every((value) => number(value) !== void 0)) merged[name] = values.reduce((total, value) => total + value, 0);
|
|
1196
|
+
else if (USAGE_LIST_KEYS[name] && values.every(Array.isArray)) {
|
|
1197
|
+
const [keyName, valueName] = USAGE_LIST_KEYS[name];
|
|
1198
|
+
const entries = /* @__PURE__ */ new Map();
|
|
1199
|
+
for (const entry of values.flat()) {
|
|
1200
|
+
const item = record(entry);
|
|
1201
|
+
if (!item) continue;
|
|
1202
|
+
const existing = entries.get(item[keyName]);
|
|
1203
|
+
const total = number(existing?.[valueName]);
|
|
1204
|
+
const value = number(item[valueName]);
|
|
1205
|
+
entries.set(item[keyName], existing && total !== void 0 && value !== void 0 ? {
|
|
1206
|
+
...existing,
|
|
1207
|
+
[valueName]: total + value
|
|
1208
|
+
} : existing ?? item);
|
|
1209
|
+
}
|
|
1210
|
+
merged[name] = [...entries.values()];
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
const initialInputTokens = usages[0].initial_input_tokens ?? usages[0].total_input_tokens;
|
|
1214
|
+
if (initialInputTokens !== void 0) merged.initial_input_tokens = initialInputTokens;
|
|
1215
|
+
return merged;
|
|
1216
|
+
}
|
|
1217
|
+
function positive(value) {
|
|
1218
|
+
const result = number(value);
|
|
1219
|
+
return result !== void 0 && result > 0 ? result : void 0;
|
|
1220
|
+
}
|
|
1221
|
+
function createStreamAbort(options, clientTimeout) {
|
|
1222
|
+
const requestOptions = record(options) ?? {};
|
|
1223
|
+
const fetchOptions = record(requestOptions.fetch_options) ?? record(requestOptions.fetchOptions);
|
|
1224
|
+
const callerSignal = requestOptions.signal ?? fetchOptions?.signal;
|
|
1225
|
+
if (callerSignal !== void 0 && callerSignal !== null && !(callerSignal instanceof AbortSignal)) return void 0;
|
|
1226
|
+
const cancellation = new AbortController();
|
|
1227
|
+
const signals = [cancellation.signal];
|
|
1228
|
+
if (callerSignal) signals.push(callerSignal);
|
|
1229
|
+
const requestTimeout = callerSignal ? void 0 : positive(requestOptions.timeout_ms) ?? positive(requestOptions.timeout);
|
|
1230
|
+
if (requestTimeout !== void 0) signals.push(AbortSignal.timeout(requestTimeout));
|
|
1231
|
+
const hopTimeout = callerSignal || requestTimeout !== void 0 ? void 0 : positive(clientTimeout);
|
|
1232
|
+
const hopTimer = hopTimeout === void 0 ? void 0 : new AbortController();
|
|
1233
|
+
if (hopTimer) signals.push(hopTimer.signal);
|
|
1234
|
+
let timer;
|
|
1235
|
+
let remaining = hopTimeout ?? 0;
|
|
1236
|
+
let resumedAt = 0;
|
|
1237
|
+
const pauseHopTimer = () => {
|
|
1238
|
+
if (timer === void 0) return;
|
|
1239
|
+
clearTimeout(timer);
|
|
1240
|
+
timer = void 0;
|
|
1241
|
+
remaining = Math.max(0, remaining - (Date.now() - resumedAt));
|
|
1242
|
+
};
|
|
1243
|
+
const resumeHopTimer = () => {
|
|
1244
|
+
if (!hopTimer || hopTimer.signal.aborted || timer !== void 0) return;
|
|
1245
|
+
resumedAt = Date.now();
|
|
1246
|
+
timer = setTimeout(() => hopTimer.abort(new DOMException("The operation was aborted due to timeout", "TimeoutError")), remaining);
|
|
1247
|
+
if (typeof timer === "object") timer.unref?.();
|
|
1248
|
+
};
|
|
1249
|
+
const resetHopTimer = () => {
|
|
1250
|
+
pauseHopTimer();
|
|
1251
|
+
remaining = hopTimeout ?? 0;
|
|
1252
|
+
};
|
|
1253
|
+
resumeHopTimer();
|
|
1254
|
+
const signal = signals.length === 1 ? cancellation.signal : AbortSignal.any(signals);
|
|
1255
|
+
return {
|
|
1256
|
+
options: {
|
|
1257
|
+
...requestOptions,
|
|
1258
|
+
signal
|
|
1259
|
+
},
|
|
1260
|
+
abort: () => cancellation.abort(),
|
|
1261
|
+
resumeHopTimer,
|
|
1262
|
+
pauseHopTimer,
|
|
1263
|
+
resetHopTimer
|
|
1264
|
+
};
|
|
1265
|
+
}
|
|
1266
|
+
const needsRequestAbort = "ContinuationInterruptedError" in _google_genai;
|
|
1160
1267
|
function isFailure(status) {
|
|
1161
1268
|
return status === "failed" || status === "cancelled" || status === "incomplete" || status === "budget_exceeded";
|
|
1162
1269
|
}
|
|
1163
1270
|
var WrappedInteractions = class {
|
|
1164
|
-
constructor(client, phClient) {
|
|
1271
|
+
constructor(client, phClient, clientTimeout) {
|
|
1165
1272
|
this.client = client;
|
|
1166
1273
|
this.phClient = phClient;
|
|
1274
|
+
this.clientTimeout = clientTimeout;
|
|
1167
1275
|
}
|
|
1168
1276
|
async create(params, options) {
|
|
1169
1277
|
const { providerParams, posthogParams } = extractPosthogParams(params);
|
|
@@ -1199,12 +1307,16 @@ var WrappedInteractions = class {
|
|
|
1199
1307
|
});
|
|
1200
1308
|
} catch {}
|
|
1201
1309
|
};
|
|
1310
|
+
let streamAbort;
|
|
1202
1311
|
try {
|
|
1203
1312
|
if (!this.client.interactions?.create) throw new Error("Gemini Interactions requires @google/genai 2.18.0 or newer");
|
|
1204
|
-
|
|
1313
|
+
streamAbort = needsRequestAbort && requestData.stream === true && typeof AbortSignal.any === "function" ? createStreamAbort(options, this.clientTimeout) : void 0;
|
|
1314
|
+
const providerOptions = streamAbort ? streamAbort.options : options;
|
|
1315
|
+
const result = await (providerOptions === void 0 ? this.client.interactions.create(request) : this.client.interactions.create(request, providerOptions));
|
|
1205
1316
|
if (requestData.stream === true) {
|
|
1206
1317
|
if (!isStream(result)) throw new Error("Gemini Interactions did not return a stream");
|
|
1207
|
-
|
|
1318
|
+
streamAbort?.pauseHopTimer();
|
|
1319
|
+
return this.wrapStream(result, capture, streamAbort);
|
|
1208
1320
|
}
|
|
1209
1321
|
if (isStream(result)) throw new Error("Gemini Interactions returned an unexpected stream");
|
|
1210
1322
|
const interaction = record(result);
|
|
@@ -1221,11 +1333,16 @@ var WrappedInteractions = class {
|
|
|
1221
1333
|
} catch {}
|
|
1222
1334
|
return result;
|
|
1223
1335
|
} catch (error) {
|
|
1224
|
-
|
|
1336
|
+
streamAbort?.pauseHopTimer();
|
|
1337
|
+
let partialInteraction;
|
|
1338
|
+
try {
|
|
1339
|
+
partialInteraction = record(record(error)?.partialInteraction);
|
|
1340
|
+
} catch {}
|
|
1341
|
+
await capture(partialInteraction, error);
|
|
1225
1342
|
throw error;
|
|
1226
1343
|
}
|
|
1227
1344
|
}
|
|
1228
|
-
wrapStream(stream, capture) {
|
|
1345
|
+
wrapStream(stream, capture, streamAbort) {
|
|
1229
1346
|
const reader = "getReader" in stream && typeof stream.getReader === "function" ? stream.getReader() : void 0;
|
|
1230
1347
|
const iterator = reader ? void 0 : stream[Symbol.asyncIterator]();
|
|
1231
1348
|
let readerReleased = false;
|
|
@@ -1273,6 +1390,10 @@ var WrappedInteractions = class {
|
|
|
1273
1390
|
let interaction;
|
|
1274
1391
|
let latestUsage;
|
|
1275
1392
|
let finalUsage;
|
|
1393
|
+
const previousHopUsages = [];
|
|
1394
|
+
let stepOffset = 0;
|
|
1395
|
+
let hops = 1;
|
|
1396
|
+
let hopBoundary = false;
|
|
1276
1397
|
let error;
|
|
1277
1398
|
let firstTokenTime;
|
|
1278
1399
|
const steps = /* @__PURE__ */ new Map();
|
|
@@ -1280,6 +1401,10 @@ var WrappedInteractions = class {
|
|
|
1280
1401
|
let closed = false;
|
|
1281
1402
|
let cancelled = false;
|
|
1282
1403
|
let captured = false;
|
|
1404
|
+
const stepIndex = (value) => {
|
|
1405
|
+
const index = number(value);
|
|
1406
|
+
return index === void 0 ? void 0 : index + stepOffset;
|
|
1407
|
+
};
|
|
1283
1408
|
const observe = (event) => {
|
|
1284
1409
|
let schemaError;
|
|
1285
1410
|
try {
|
|
@@ -1290,18 +1415,27 @@ var WrappedInteractions = class {
|
|
|
1290
1415
|
const usage = record(record(item?.metadata)?.total_usage) ?? (eventType === "step.stop" ? record(item?.usage) : void 0);
|
|
1291
1416
|
if (usage) latestUsage = { ...usage };
|
|
1292
1417
|
if (eventType === "interaction.created") {
|
|
1418
|
+
if (interaction?.status === "requires_continuation") {
|
|
1419
|
+
hops++;
|
|
1420
|
+
if (finalUsage) previousHopUsages.push(finalUsage);
|
|
1421
|
+
finalUsage = void 0;
|
|
1422
|
+
latestUsage = void 0;
|
|
1423
|
+
stepOffset = steps.size === 0 ? 0 : Math.max(...steps.keys()) + 1;
|
|
1424
|
+
completed = false;
|
|
1425
|
+
error = void 0;
|
|
1426
|
+
}
|
|
1293
1427
|
interaction = { ...record(item?.interaction) };
|
|
1294
1428
|
const initialUsage = record(interaction.usage);
|
|
1295
1429
|
if (initialUsage) latestUsage = { ...initialUsage };
|
|
1296
1430
|
} else if (eventType === "step.start") {
|
|
1297
|
-
const index =
|
|
1431
|
+
const index = stepIndex(item?.index);
|
|
1298
1432
|
const step = record(item?.step);
|
|
1299
1433
|
if (index !== void 0) steps.set(index, {
|
|
1300
1434
|
...step,
|
|
1301
1435
|
content: Array.isArray(step?.content) ? step.content.map((item) => ({ ...record(item) })) : []
|
|
1302
1436
|
});
|
|
1303
1437
|
} else if (eventType === "step.delta") {
|
|
1304
|
-
const index =
|
|
1438
|
+
const index = stepIndex(item?.index);
|
|
1305
1439
|
const delta = record(item?.delta);
|
|
1306
1440
|
const step = index === void 0 ? void 0 : steps.get(index);
|
|
1307
1441
|
if (step && delta?.type === "text" && typeof delta.text === "string") {
|
|
@@ -1334,6 +1468,7 @@ var WrappedInteractions = class {
|
|
|
1334
1468
|
}
|
|
1335
1469
|
if (isFailure(interaction.status)) error = /* @__PURE__ */ new Error(`Gemini interaction ${interaction.status}`);
|
|
1336
1470
|
if (!completed) error = /* @__PURE__ */ new Error("Gemini interaction stream ended without a terminal result");
|
|
1471
|
+
hopBoundary = interaction.status === "requires_continuation";
|
|
1337
1472
|
} else if (eventType === "error") error = /* @__PURE__ */ new Error("Gemini interaction stream failed");
|
|
1338
1473
|
}
|
|
1339
1474
|
} catch {}
|
|
@@ -1342,15 +1477,17 @@ var WrappedInteractions = class {
|
|
|
1342
1477
|
const finish = async (status, providerError) => {
|
|
1343
1478
|
if (captured) return;
|
|
1344
1479
|
captured = true;
|
|
1480
|
+
streamAbort?.pauseHopTimer();
|
|
1345
1481
|
try {
|
|
1346
1482
|
const streamedSteps = [...steps.entries()].sort(([left], [right]) => left - right).map(([, step]) => ({
|
|
1347
1483
|
...step,
|
|
1348
1484
|
arguments: step.argumentChunks === void 0 ? step.arguments : functionArguments(step.argumentChunks)
|
|
1349
1485
|
}));
|
|
1350
|
-
const output = outputFromSteps(Array.isArray(interaction?.steps) && interaction.steps.length > 0 ? interaction.steps : streamedSteps);
|
|
1486
|
+
const output = outputFromSteps(hops === 1 && Array.isArray(interaction?.steps) && interaction.steps.length > 0 ? interaction.steps : streamedSteps);
|
|
1487
|
+
const hopUsage = finalUsage ?? latestUsage;
|
|
1351
1488
|
await capture({
|
|
1352
1489
|
...interaction,
|
|
1353
|
-
usage:
|
|
1490
|
+
usage: mergeHopUsage(hopUsage ? [...previousHopUsages, hopUsage] : previousHopUsages),
|
|
1354
1491
|
...completed ? {} : { status }
|
|
1355
1492
|
}, providerError ?? error ?? (!completed && status === "incomplete" ? /* @__PURE__ */ new Error("Gemini interaction stream ended without completion") : void 0), output, firstTokenTime);
|
|
1356
1493
|
} catch {}
|
|
@@ -1358,7 +1495,17 @@ var WrappedInteractions = class {
|
|
|
1358
1495
|
return new ReadableStream({
|
|
1359
1496
|
async pull(controller) {
|
|
1360
1497
|
try {
|
|
1361
|
-
|
|
1498
|
+
if (hopBoundary) {
|
|
1499
|
+
hopBoundary = false;
|
|
1500
|
+
streamAbort?.resetHopTimer();
|
|
1501
|
+
}
|
|
1502
|
+
streamAbort?.resumeHopTimer();
|
|
1503
|
+
let result;
|
|
1504
|
+
try {
|
|
1505
|
+
result = await next();
|
|
1506
|
+
} finally {
|
|
1507
|
+
streamAbort?.pauseHopTimer();
|
|
1508
|
+
}
|
|
1362
1509
|
if (closed) return;
|
|
1363
1510
|
if (result.done) {
|
|
1364
1511
|
closed = true;
|
|
@@ -1386,7 +1533,9 @@ var WrappedInteractions = class {
|
|
|
1386
1533
|
closed = true;
|
|
1387
1534
|
let cancellationError;
|
|
1388
1535
|
try {
|
|
1389
|
-
|
|
1536
|
+
const cancelling = cancelSource(reason);
|
|
1537
|
+
streamAbort?.abort();
|
|
1538
|
+
await cancelling;
|
|
1390
1539
|
} catch (providerError) {
|
|
1391
1540
|
cancellationError = providerError;
|
|
1392
1541
|
throw providerError;
|
|
@@ -1427,7 +1576,7 @@ var PostHogGoogleGenAI = class {
|
|
|
1427
1576
|
this.phClient = posthog;
|
|
1428
1577
|
this.client = new _google_genai.GoogleGenAI(geminiConfig);
|
|
1429
1578
|
this.models = new WrappedModels(this.client, this.phClient);
|
|
1430
|
-
this.interactions = new WrappedInteractions(this.client, this.phClient);
|
|
1579
|
+
this.interactions = new WrappedInteractions(this.client, this.phClient, geminiConfig.httpOptions?.timeout);
|
|
1431
1580
|
}
|
|
1432
1581
|
};
|
|
1433
1582
|
var WrappedModels = class {
|