agent-inspect 6.31.21 → 6.31.22

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.
Files changed (47) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +1 -1
  3. package/package.json +1 -1
  4. package/packages/cli/dist/{chunk-N5JN26MW.mjs → chunk-EMWA5EKU.mjs} +300 -31
  5. package/packages/cli/dist/chunk-EMWA5EKU.mjs.map +1 -0
  6. package/packages/cli/dist/index.cjs +379 -56
  7. package/packages/cli/dist/index.cjs.map +1 -1
  8. package/packages/cli/dist/index.mjs +75 -31
  9. package/packages/cli/dist/index.mjs.map +1 -1
  10. package/packages/cli/dist/{src-VMGRSTG7.mjs → src-VZHGOLTO.mjs} +3 -3
  11. package/packages/cli/dist/{src-VMGRSTG7.mjs.map → src-VZHGOLTO.mjs.map} +1 -1
  12. package/packages/core/dist/advanced.cjs +247 -5
  13. package/packages/core/dist/advanced.cjs.map +1 -1
  14. package/packages/core/dist/advanced.mjs +6 -5
  15. package/packages/core/dist/advanced.mjs.map +1 -1
  16. package/packages/core/dist/checks.cjs +160 -27
  17. package/packages/core/dist/checks.cjs.map +1 -1
  18. package/packages/core/dist/checks.mjs +2 -1
  19. package/packages/core/dist/chunk-GCZUWY47.mjs +182 -0
  20. package/packages/core/dist/chunk-GCZUWY47.mjs.map +1 -0
  21. package/packages/core/dist/{chunk-JE3TUFAQ.mjs → chunk-RBXD7BNX.mjs} +3 -3
  22. package/packages/core/dist/{chunk-JE3TUFAQ.mjs.map → chunk-RBXD7BNX.mjs.map} +1 -1
  23. package/packages/core/dist/{chunk-YU6XT5A2.mjs → chunk-S4NU55LU.mjs} +45 -3
  24. package/packages/core/dist/chunk-S4NU55LU.mjs.map +1 -0
  25. package/packages/core/dist/{chunk-EIP5CNEL.mjs → chunk-UPGBMRL4.mjs} +49 -3
  26. package/packages/core/dist/chunk-UPGBMRL4.mjs.map +1 -0
  27. package/packages/core/dist/{chunk-4CDX5GDS.mjs → chunk-ZOF6ON65.mjs} +104 -99
  28. package/packages/core/dist/chunk-ZOF6ON65.mjs.map +1 -0
  29. package/packages/core/dist/exporters.cjs +82 -27
  30. package/packages/core/dist/exporters.cjs.map +1 -1
  31. package/packages/core/dist/exporters.mjs +72 -27
  32. package/packages/core/dist/exporters.mjs.map +1 -1
  33. package/packages/core/dist/logs.cjs +197 -1
  34. package/packages/core/dist/logs.cjs.map +1 -1
  35. package/packages/core/dist/logs.mjs +3 -2
  36. package/packages/core/dist/logs.mjs.map +1 -1
  37. package/packages/core/dist/persisted.cjs +197 -1
  38. package/packages/core/dist/persisted.cjs.map +1 -1
  39. package/packages/core/dist/persisted.mjs +4 -3
  40. package/packages/core/dist/persisted.mjs.map +1 -1
  41. package/packages/core/dist/readers.cjs +243 -1
  42. package/packages/core/dist/readers.cjs.map +1 -1
  43. package/packages/core/dist/readers.mjs +4 -3
  44. package/packages/cli/dist/chunk-N5JN26MW.mjs.map +0 -1
  45. package/packages/core/dist/chunk-4CDX5GDS.mjs.map +0 -1
  46. package/packages/core/dist/chunk-EIP5CNEL.mjs.map +0 -1
  47. package/packages/core/dist/chunk-YU6XT5A2.mjs.map +0 -1
@@ -1217,6 +1217,17 @@ function exportOpenInference(tree, options) {
1217
1217
  warnings
1218
1218
  };
1219
1219
  }
1220
+
1221
+ // packages/core/src/persisted/delivery-identity.ts
1222
+ var DELIVERY_CONFLICT_ATTR = "agent_inspect.delivery_conflict";
1223
+ var IDENTITY_CONFLICT_ATTR = {
1224
+ operationId: "agent_inspect.identity_conflict.operation_id",
1225
+ attemptId: "agent_inspect.identity_conflict.attempt_id",
1226
+ retryOf: "agent_inspect.identity_conflict.retry_of",
1227
+ attemptNumber: "agent_inspect.identity_conflict.attempt_number"
1228
+ };
1229
+
1230
+ // packages/core/src/exporters/otlp-json-exporter.ts
1220
1231
  var OTLP_STATUS_CODE_UNSET = 0;
1221
1232
  var OTLP_STATUS_CODE_OK = 1;
1222
1233
  var OTLP_STATUS_CODE_ERROR = 2;
@@ -1266,43 +1277,81 @@ var STRUCTURAL_IDENTITY_KEYS = [
1266
1277
  "attemptNumber",
1267
1278
  "attempt"
1268
1279
  ];
1269
- function pickBoundedIdentityString(bag, key, maxLen) {
1280
+ function nestedBag(bag) {
1270
1281
  if (!bag || typeof bag !== "object") return void 0;
1271
- const direct = bag[key];
1272
- if (typeof direct === "string" && direct.trim() !== "") {
1273
- return direct.trim().slice(0, maxLen);
1274
- }
1275
- const nested = bag.metadata && typeof bag.metadata === "object" ? bag.metadata[key] : void 0;
1276
- if (typeof nested === "string" && nested.trim() !== "") {
1277
- return nested.trim().slice(0, maxLen);
1278
- }
1279
- return void 0;
1282
+ const nested = bag.metadata;
1283
+ if (!nested || typeof nested !== "object" || Array.isArray(nested)) return void 0;
1284
+ return nested;
1285
+ }
1286
+ function pickBoundedIdentityString(bag, key, maxLen) {
1287
+ if (!bag || typeof bag !== "object") return {};
1288
+ const directRaw = bag[key];
1289
+ const nestedRaw = nestedBag(bag)?.[key];
1290
+ const direct = typeof directRaw === "string" && directRaw.trim() !== "" ? directRaw.trim().slice(0, maxLen) : void 0;
1291
+ const nested = typeof nestedRaw === "string" && nestedRaw.trim() !== "" ? nestedRaw.trim().slice(0, maxLen) : void 0;
1292
+ if (direct !== void 0 && nested !== void 0 && direct !== nested) {
1293
+ return { value: direct, conflictAlternate: nested };
1294
+ }
1295
+ if (direct !== void 0) return { value: direct };
1296
+ if (nested !== void 0) return { value: nested };
1297
+ return {};
1280
1298
  }
1281
1299
  function pickBoundedIdentityNumber(bag, key) {
1282
- if (!bag || typeof bag !== "object") return void 0;
1283
- const direct = bag[key];
1284
- if (typeof direct === "number" && Number.isFinite(direct)) return direct;
1285
- const nested = bag.metadata && typeof bag.metadata === "object" ? bag.metadata[key] : void 0;
1286
- if (typeof nested === "number" && Number.isFinite(nested)) return nested;
1287
- return void 0;
1300
+ if (!bag || typeof bag !== "object") return {};
1301
+ const directRaw = bag[key];
1302
+ const nestedRaw = nestedBag(bag)?.[key];
1303
+ const direct = typeof directRaw === "number" && Number.isFinite(directRaw) ? directRaw : void 0;
1304
+ const nested = typeof nestedRaw === "number" && Number.isFinite(nestedRaw) ? nestedRaw : void 0;
1305
+ if (direct !== void 0 && nested !== void 0 && direct !== nested) {
1306
+ return { value: direct, conflictAlternate: nested };
1307
+ }
1308
+ if (direct !== void 0) return { value: direct };
1309
+ if (nested !== void 0) return { value: nested };
1310
+ return {};
1288
1311
  }
1289
1312
  function appendStructuralIdentityAttrs(attrs, meta, maxLen) {
1313
+ const conflicts = [];
1290
1314
  const operationId = pickBoundedIdentityString(meta, "operationId", maxLen);
1291
- if (operationId !== void 0) {
1292
- attrs.push(stringAttr("agent_inspect.operation_id", operationId));
1315
+ if (operationId.value !== void 0) {
1316
+ attrs.push(stringAttr("agent_inspect.operation_id", operationId.value));
1317
+ }
1318
+ if (operationId.conflictAlternate !== void 0) {
1319
+ attrs.push(
1320
+ stringAttr(IDENTITY_CONFLICT_ATTR.operationId, operationId.conflictAlternate)
1321
+ );
1322
+ conflicts.push("operationId");
1293
1323
  }
1294
1324
  const attemptId = pickBoundedIdentityString(meta, "attemptId", maxLen);
1295
- if (attemptId !== void 0) {
1296
- attrs.push(stringAttr("agent_inspect.attempt_id", attemptId));
1325
+ if (attemptId.value !== void 0) {
1326
+ attrs.push(stringAttr("agent_inspect.attempt_id", attemptId.value));
1327
+ }
1328
+ if (attemptId.conflictAlternate !== void 0) {
1329
+ attrs.push(stringAttr(IDENTITY_CONFLICT_ATTR.attemptId, attemptId.conflictAlternate));
1330
+ conflicts.push("attemptId");
1297
1331
  }
1298
1332
  const retryOf = pickBoundedIdentityString(meta, "retryOf", maxLen);
1299
- if (retryOf !== void 0) {
1300
- attrs.push(stringAttr("agent_inspect.retry_of", retryOf));
1333
+ if (retryOf.value !== void 0) {
1334
+ attrs.push(stringAttr("agent_inspect.retry_of", retryOf.value));
1335
+ }
1336
+ if (retryOf.conflictAlternate !== void 0) {
1337
+ attrs.push(stringAttr(IDENTITY_CONFLICT_ATTR.retryOf, retryOf.conflictAlternate));
1338
+ conflicts.push("retryOf");
1339
+ }
1340
+ const attemptNumberPrimary = pickBoundedIdentityNumber(meta, "attemptNumber");
1341
+ const attemptNumber = attemptNumberPrimary.value !== void 0 || attemptNumberPrimary.conflictAlternate !== void 0 ? attemptNumberPrimary : pickBoundedIdentityNumber(meta, "attempt");
1342
+ if (attemptNumber.value !== void 0) {
1343
+ attrs.push(intAttr("agent_inspect.attempt_number", attemptNumber.value));
1301
1344
  }
1302
- const attemptNumber = pickBoundedIdentityNumber(meta, "attemptNumber") ?? pickBoundedIdentityNumber(meta, "attempt");
1303
- if (attemptNumber !== void 0) {
1304
- attrs.push(intAttr("agent_inspect.attempt_number", attemptNumber));
1345
+ if (attemptNumber.conflictAlternate !== void 0) {
1346
+ attrs.push(
1347
+ intAttr(IDENTITY_CONFLICT_ATTR.attemptNumber, attemptNumber.conflictAlternate)
1348
+ );
1349
+ conflicts.push("attemptNumber");
1350
+ }
1351
+ if (meta?.[DELIVERY_CONFLICT_ATTR] === true) {
1352
+ attrs.push(boolAttr(DELIVERY_CONFLICT_ATTR, true));
1305
1353
  }
1354
+ return conflicts;
1306
1355
  }
1307
1356
  function resolveSpanTimes(ev) {
1308
1357
  const startedAtMs = typeof ev.attributes?.startedAtMs === "number" && Number.isFinite(ev.attributes.startedAtMs) ? ev.attributes.startedAtMs : void 0;
@@ -1325,7 +1374,8 @@ function exportOtlpJson(tree, options) {
1325
1374
  "OTLP JSON export uses OTel GenAI-aligned attributes where applicable; experimental until verified against specific collectors.",
1326
1375
  "Not OTLP gRPC/protobuf \u2014 JSON mapping only. Generated locally; no network upload.",
1327
1376
  "Status and span kind use OTLP numeric enums (StatusCode 0/1/2, SpanKind INTERNAL=1).",
1328
- "When present on source events, operationId/attemptId/retryOf/attemptNumber are emitted as bounded agent_inspect.* identity attributes (not a broad attribute dump)."
1377
+ "When present on source events, operationId/attemptId/retryOf/attemptNumber are emitted as bounded agent_inspect.* identity attributes (not a broad attribute dump).",
1378
+ "When direct and nested identity disagree, export prefers direct for non-strict consumers and emits agent_inspect.identity_conflict.* for the nested alternate; this does not certify conflicting identity."
1329
1379
  ];
1330
1380
  const traceId = hexFrom2(`trace:${tree.runId}`, 16);
1331
1381
  const includeAttributes = options?.includeAttributes ?? false;
@@ -1373,11 +1423,16 @@ function exportOtlpJson(tree, options) {
1373
1423
  if (typeof inp === "number") attrs.push(intAttr("gen_ai.usage.input_tokens", inp));
1374
1424
  if (typeof outp === "number") attrs.push(intAttr("gen_ai.usage.output_tokens", outp));
1375
1425
  }
1376
- appendStructuralIdentityAttrs(
1426
+ const identityConflicts = appendStructuralIdentityAttrs(
1377
1427
  attrs,
1378
1428
  meta && typeof meta === "object" ? meta : void 0,
1379
1429
  maxLen
1380
1430
  );
1431
+ if (identityConflicts.length > 0) {
1432
+ warnings.push(
1433
+ `Identity representation conflict on event ${ev.eventId}: ${identityConflicts.join(", ")} (direct preferred; nested retained on agent_inspect.identity_conflict.*).`
1434
+ );
1435
+ }
1381
1436
  if (includeAttributes && meta && typeof meta === "object") {
1382
1437
  const skipKeys = /* @__PURE__ */ new Set([
1383
1438
  "tokens",