@posthog/ai 8.12.1 → 8.13.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 +1 -1
- package/dist/gemini/index.mjs +1 -1
- package/dist/index.cjs +36 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +22 -12
- package/dist/index.mjs +36 -16
- package/dist/index.mjs.map +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.d.ts +2 -2
- 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 +15 -11
package/dist/adk/index.cjs
CHANGED
package/dist/adk/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { BasePlugin } from "@google/adk";
|
|
|
2
2
|
import { v4 } from "uuid";
|
|
3
3
|
import { toJsonSafeValue, uuidv7 } from "@posthog/core";
|
|
4
4
|
//#region package.json
|
|
5
|
-
var version = "8.
|
|
5
|
+
var version = "8.13.1";
|
|
6
6
|
//#endregion
|
|
7
7
|
//#region src/captureAiEvent.ts
|
|
8
8
|
/** @internal */
|
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.
|
|
6
|
+
var version = "8.13.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 { toJsonSafeValue, uuidv7 } from "@posthog/core";
|
|
4
4
|
//#region package.json
|
|
5
|
-
var version = "8.
|
|
5
|
+
var version = "8.13.1";
|
|
6
6
|
//#endregion
|
|
7
7
|
//#region src/captureAiEvent.ts
|
|
8
8
|
/** @internal */
|
package/dist/gemini/index.cjs
CHANGED
package/dist/gemini/index.mjs
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -396,7 +396,7 @@ function sanitizeValues(obj) {
|
|
|
396
396
|
}
|
|
397
397
|
//#endregion
|
|
398
398
|
//#region package.json
|
|
399
|
-
var version = "8.
|
|
399
|
+
var version = "8.13.1";
|
|
400
400
|
//#endregion
|
|
401
401
|
//#region src/serializeError.ts
|
|
402
402
|
const DEFAULT_MAX_DEPTH = 3;
|
|
@@ -1133,6 +1133,10 @@ function isSameOrigin(url, host) {
|
|
|
1133
1133
|
return false;
|
|
1134
1134
|
}
|
|
1135
1135
|
}
|
|
1136
|
+
/** Formats a batch-fetch reference for logs and errors. */
|
|
1137
|
+
function promptListReference(label) {
|
|
1138
|
+
return label === void 0 ? "all prompts" : `prompts with label "${label}"`;
|
|
1139
|
+
}
|
|
1136
1140
|
/**
|
|
1137
1141
|
* Classify how a list row relates to the requested label, via its all_labels
|
|
1138
1142
|
* field.
|
|
@@ -1188,6 +1192,9 @@ function isPromptsWithPostHog(options) {
|
|
|
1188
1192
|
* // Or fetch all prompts at a label in one request and warm the cache
|
|
1189
1193
|
* const prodPrompts = await prompts.getAll({ label: 'production' })
|
|
1190
1194
|
*
|
|
1195
|
+
* // Or fetch the latest version of every prompt in one request
|
|
1196
|
+
* const allPrompts = await prompts.getAll()
|
|
1197
|
+
*
|
|
1191
1198
|
* // Compile with variables
|
|
1192
1199
|
* const systemPrompt = prompts.compile(result.prompt, {
|
|
1193
1200
|
* company: 'Acme Corp',
|
|
@@ -1254,31 +1261,38 @@ var Prompts = class {
|
|
|
1254
1261
|
}
|
|
1255
1262
|
}
|
|
1256
1263
|
/**
|
|
1257
|
-
* Fetch every prompt
|
|
1264
|
+
* Fetch every prompt in one batch.
|
|
1258
1265
|
*
|
|
1259
|
-
* Returns an object mapping prompt name to `PromptRemoteResult
|
|
1260
|
-
* prompt at the version the label points to
|
|
1261
|
-
* not included.
|
|
1266
|
+
* Returns an object mapping prompt name to `PromptRemoteResult`. With a
|
|
1267
|
+
* label, each prompt is at the version the label points to, and prompts
|
|
1268
|
+
* without the label are not included. Without a label, every prompt is
|
|
1269
|
+
* included at its latest version, matching what `get(name)` returns.
|
|
1262
1270
|
*
|
|
1263
1271
|
* Each fetched prompt is stored in the cache, so later
|
|
1264
|
-
* `get(name, { label })` calls are served from cache
|
|
1265
|
-
* with many prompts can call this once per cache
|
|
1266
|
-
* `get()` request per prompt.
|
|
1272
|
+
* `get(name, { label })` (or plain `get(name)`) calls are served from cache
|
|
1273
|
+
* within the TTL. An app with many prompts can call this once per cache
|
|
1274
|
+
* cycle instead of making one `get()` request per prompt.
|
|
1267
1275
|
*
|
|
1268
1276
|
* Unlike `get()`, there is no `fallback` option, so callers should handle
|
|
1269
1277
|
* the error themselves.
|
|
1270
1278
|
*
|
|
1271
1279
|
* @throws {Error} When the request fails, when the response is malformed,
|
|
1272
|
-
* or when the server does not support fetching
|
|
1273
|
-
* endpoint (PostHog releases from before
|
|
1280
|
+
* or when a label was passed and the server does not support fetching
|
|
1281
|
+
* prompts by label on the list endpoint (PostHog releases from before
|
|
1282
|
+
* September 2026).
|
|
1274
1283
|
*/
|
|
1275
1284
|
async getAll(options) {
|
|
1276
|
-
const label = options
|
|
1285
|
+
const label = options?.label;
|
|
1277
1286
|
const rows = await this.fetchPromptListFromApi(label);
|
|
1287
|
+
const reference = promptListReference(label);
|
|
1278
1288
|
const resolvedRows = [];
|
|
1279
1289
|
const skipped = [];
|
|
1280
1290
|
for (const row of rows) {
|
|
1281
|
-
if (!isPromptApiResponse(row)) throw new Error(`[PostHog Prompts] Invalid response format for
|
|
1291
|
+
if (!isPromptApiResponse(row)) throw new Error(`[PostHog Prompts] Invalid response format for ${reference}`);
|
|
1292
|
+
if (label === void 0) {
|
|
1293
|
+
resolvedRows.push(row);
|
|
1294
|
+
continue;
|
|
1295
|
+
}
|
|
1282
1296
|
const labelState = rowLabelState(row, label);
|
|
1283
1297
|
if (labelState === "absent") throw new Error(`[PostHog Prompts] The server returned a prompt that does not carry label "${label}". It may not support fetching prompts by label on the list endpoint yet. Upgrade PostHog, or fetch prompts one by one with get().`);
|
|
1284
1298
|
if (labelState === "moved") {
|
|
@@ -1287,7 +1301,7 @@ var Prompts = class {
|
|
|
1287
1301
|
}
|
|
1288
1302
|
resolvedRows.push(row);
|
|
1289
1303
|
}
|
|
1290
|
-
if (rows.length > 0 && resolvedRows.length === 0) throw new Error(`[PostHog Prompts] The server returned prompts, but none resolve label "${label}". It may not support fetching prompts by label on the list endpoint yet. Upgrade PostHog, or fetch prompts one by one with get().`);
|
|
1304
|
+
if (label !== void 0 && rows.length > 0 && resolvedRows.length === 0) throw new Error(`[PostHog Prompts] The server returned prompts, but none resolve label "${label}". It may not support fetching prompts by label on the list endpoint yet. Upgrade PostHog, or fetch prompts one by one with get().`);
|
|
1291
1305
|
const now = Date.now();
|
|
1292
1306
|
const results = /* @__PURE__ */ new Map();
|
|
1293
1307
|
for (const row of resolvedRows) {
|
|
@@ -1407,14 +1421,20 @@ var Prompts = class {
|
|
|
1407
1421
|
if (!this.projectApiKey) throw new Error("[PostHog Prompts] projectApiKey is required to fetch prompts. Please provide it when initializing the Prompts instance.");
|
|
1408
1422
|
}
|
|
1409
1423
|
/**
|
|
1410
|
-
* Fetch all prompts
|
|
1424
|
+
* Fetch all prompts from the paginated list endpoint.
|
|
1425
|
+
*
|
|
1426
|
+
* Without a label the endpoint serves the latest version of every prompt;
|
|
1427
|
+
* the param is then omitted entirely, since the server treats any value as
|
|
1428
|
+
* a label name to filter by.
|
|
1429
|
+
*
|
|
1411
1430
|
* Follows pagination links until the last page and returns the raw rows.
|
|
1412
1431
|
*/
|
|
1413
1432
|
async fetchPromptListFromApi(label) {
|
|
1414
1433
|
this.requireCredentials();
|
|
1415
|
-
const
|
|
1434
|
+
const labelQuery = label === void 0 ? "" : `&label=${encodeURIComponent(label)}`;
|
|
1435
|
+
const query = `token=${encodeURIComponent(this.projectApiKey)}${labelQuery}&content=full`;
|
|
1416
1436
|
let url = `${this.host}/api/environments/@current/llm_prompts/?${query}`;
|
|
1417
|
-
const reference =
|
|
1437
|
+
const reference = promptListReference(label);
|
|
1418
1438
|
const rows = [];
|
|
1419
1439
|
let pages = 0;
|
|
1420
1440
|
while (url !== void 0) {
|