@posthog/ai 8.21.0 → 8.22.0

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 CHANGED
@@ -195,8 +195,8 @@ Set `modelVersion` on `new EvaluationItem({ modelVersion, output })` or
195
195
  that execution. Each item can override the experiment's `modelVersion`; omitted or null values
196
196
  inherit the experiment default on the server. Dataset metadata never supplies this model.
197
197
  Model identifiers must be nonempty strings of at most 255 characters and are preserved without
198
- trimming. Explicit models survive serialization, retries, and recovery. Changing a model requires
199
- a new item UUID because model attribution is part of the immutable execution declaration.
198
+ trimming. For a new model execution, declare a new item UUID. To correct the attribution of an
199
+ accepted item, use `updateItem` with `modelVersion`. Keep the original declaration for upload retries.
200
200
 
201
201
  `scorers` provides create/get/list/update/createVersion/getVersion/listVersions/validateComposition. Configurations
202
202
  are typed by `kind`: `boolean`, `numeric`, or `categorical`. Store `currentVersionId` to pin a
@@ -275,7 +275,9 @@ bulk call before any request is sent.
275
275
  Receipts expose stored `status` and `errorCode`. Input errors propagate as `composite_input_error`;
276
276
  formula or output-rule failures use `composite_formula_error`. Accepted composite errors count
277
277
  toward `expectedResultCount`, while derived results add no uploaded-result billing usage.
278
- Exact retries return stored outcomes, subject to current access checks. Older reported receipts
278
+ For retained results, exact upload retries acknowledge the original outcome and preserve later
279
+ corrections, subject to current access checks. Re-uploading a deleted result while the experiment
280
+ is open creates it again and counts as new usage for a reported result. Older reported receipts
279
281
  without outcomes expose `status: null` and `errorCode: null`. Save and restore calculation
280
282
  declarations with the same serialization and recovery methods as reported results.
281
283
 
@@ -286,11 +288,49 @@ declarations with the same serialization and recovery methods as reported result
286
288
  | Formula validation | Personal key: `llm_analytics:read` |
287
289
  | Experiment create/upload/complete/fail | Personal or project secret key: `offline_evaluation_ingestion:write` |
288
290
  | Experiment tags | Personal key: `evaluation:read` / `evaluation:write` |
291
+ | Item and result revision reads | Personal key: `evaluation:read` |
292
+ | Item, result, and payload mutations | Personal key: `evaluation:write` and evaluation editor access |
293
+
294
+ Reading a result revision, editing or deleting a result or its payload, and deleting an item
295
+ also require `llm_analytics:read` and access to the affected scorers and composite inputs.
289
296
 
290
297
  Feature availability and permissions are enforced by the service. Known ingestion hosts map to
291
298
  the app API host; custom host path prefixes are preserved. Pagination exposes `nextOffset` or,
292
299
  for scorer versions, `nextCursor`. Retain the original filters when requesting the next page.
293
300
 
301
+ ### Correcting an accepted result
302
+
303
+ Use the stored IDs from the upload receipt. You can correct a score even after the experiment
304
+ closes. The service recomputes any dependent composite scores.
305
+
306
+ ```ts
307
+ const experiment = evaluations.resumeExperiment(experimentId)
308
+ const resultId = uploadReceipt.results[0].id
309
+ const revision = await experiment.getResultRevision(resultId)
310
+ const corrected = await experiment.updateResult(resultId, { revision, status: 'ok', value: false })
311
+ await experiment.updateResultPayload(resultId, { revision: corrected, payload: { reasoning: 'Reviewed manually' } })
312
+ ```
313
+
314
+ Use `getItemRevision`, `updateItem`, and `updateItemPayload` for item corrections.
315
+ Omitted fields keep their stored values. An explicit `null` clears a nullable field.
316
+ Each payload shares its owner's revision. A result change also advances the parent item's revision.
317
+ Updates return the current revision, including when an unchanged score keeps the same revision.
318
+ If an update acknowledgment returns a lower revision than you submitted, the promise rejects
319
+ with code `invalid_response` and persistence `unknown`.
320
+
321
+ Passing `payload: {}` stores an empty first payload or preserves the fields of an existing payload.
322
+ Either write advances the owner's revision. A deleted or expired payload rejects even `{}` with
323
+ HTTP 409 `payload_unavailable`. When you change a result's status from `error` to another status,
324
+ the server removes any stored `errorMessage` (wire field `error_message`) from its payload.
325
+
326
+ `deleteItemPayload` and `deleteResultPayload` remove only the stored payload. A deleted payload
327
+ cannot be restored on that record. `deleteItem` permanently removes the item and its results.
328
+ `deleteResult` removes the result and any dependent composites. Each delete takes the stored ID
329
+ and `{ revision }` and resolves to `undefined`.
330
+
331
+ The SDK sends each mutation once. If a write returns HTTP 409 `revision_conflict`, or the
332
+ response is lost, read the current state before deciding whether to submit another change.
333
+
294
334
  ### Recovery, cancellation, and payloads
295
335
 
296
336
  `resumeExperiment(id)` is local and sends no request. Save creation `submission` and item/result
@@ -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.21.0";
6
+ var version = "8.22.0";
7
7
  //#endregion
8
8
  //#region src/typeGuards.ts
9
9
  const isObject = (value) => {
@@ -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.21.0";
5
+ var version = "8.22.0";
6
6
  //#endregion
7
7
  //#region src/typeGuards.ts
8
8
  const isObject = (value) => {
@@ -494,7 +494,7 @@ function addDefaults(params) {
494
494
  }
495
495
  //#endregion
496
496
  //#region package.json
497
- var version = "8.21.0";
497
+ var version = "8.22.0";
498
498
  //#endregion
499
499
  //#region src/serializeError.ts
500
500
  const DEFAULT_MAX_DEPTH = 3;
@@ -1239,7 +1239,7 @@ var WrappedMessages = class extends _anthropic_ai_sdk.default.Messages {
1239
1239
  currentReasoningBlock = null;
1240
1240
  const tool = toolsInProgress.get(chunk.index);
1241
1241
  if (tool) {
1242
- try {
1242
+ if (tool.inputString) try {
1243
1243
  tool.block.function.arguments = JSON.parse(tool.inputString);
1244
1244
  } catch (e) {
1245
1245
  console.error("Error parsing tool input:", e);