@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.
@@ -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.12.1";
6
+ var version = "8.13.1";
7
7
  //#endregion
8
8
  //#region src/captureAiEvent.ts
9
9
  /** @internal */
@@ -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.12.1";
5
+ var version = "8.13.1";
6
6
  //#endregion
7
7
  //#region src/captureAiEvent.ts
8
8
  /** @internal */
@@ -367,7 +367,7 @@ function addDefaults(params) {
367
367
  }
368
368
  //#endregion
369
369
  //#region package.json
370
- var version = "8.12.1";
370
+ var version = "8.13.1";
371
371
  //#endregion
372
372
  //#region src/serializeError.ts
373
373
  const DEFAULT_MAX_DEPTH = 3;
@@ -340,7 +340,7 @@ function addDefaults(params) {
340
340
  }
341
341
  //#endregion
342
342
  //#region package.json
343
- var version = "8.12.1";
343
+ var version = "8.13.1";
344
344
  //#endregion
345
345
  //#region src/serializeError.ts
346
346
  const DEFAULT_MAX_DEPTH = 3;
@@ -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.12.1";
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.12.1";
5
+ var version = "8.13.1";
6
6
  //#endregion
7
7
  //#region src/captureAiEvent.ts
8
8
  /** @internal */
@@ -415,7 +415,7 @@ function addDefaults(params) {
415
415
  }
416
416
  //#endregion
417
417
  //#region package.json
418
- var version = "8.12.1";
418
+ var version = "8.13.1";
419
419
  //#endregion
420
420
  //#region src/serializeError.ts
421
421
  const DEFAULT_MAX_DEPTH = 3;
@@ -411,7 +411,7 @@ function addDefaults(params) {
411
411
  }
412
412
  //#endregion
413
413
  //#region package.json
414
- var version = "8.12.1";
414
+ var version = "8.13.1";
415
415
  //#endregion
416
416
  //#region src/serializeError.ts
417
417
  const DEFAULT_MAX_DEPTH = 3;
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.12.1";
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 that carries a label, in one batch.
1264
+ * Fetch every prompt in one batch.
1258
1265
  *
1259
- * Returns an object mapping prompt name to `PromptRemoteResult`, with each
1260
- * prompt at the version the label points to. Prompts without the label are
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 within the TTL. An app
1265
- * with many prompts can call this once per cache cycle instead of making one
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 prompts by label on the list
1273
- * endpoint (PostHog releases from before September 2026).
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.label;
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 prompts with label "${label}"`);
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 at a label from the paginated list endpoint.
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 query = `token=${encodeURIComponent(this.projectApiKey)}&label=${encodeURIComponent(label)}&content=full`;
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 = `prompts with label "${label}"`;
1437
+ const reference = promptListReference(label);
1418
1438
  const rows = [];
1419
1439
  let pages = 0;
1420
1440
  while (url !== void 0) {