agent-inspect 6.31.7 → 6.31.9

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 (51) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -1
  3. package/package.json +1 -1
  4. package/packages/cli/dist/{chunk-QV73NM25.mjs → chunk-SWUZRRDT.mjs} +158 -21
  5. package/packages/cli/dist/chunk-SWUZRRDT.mjs.map +1 -0
  6. package/packages/cli/dist/index.cjs +312 -52
  7. package/packages/cli/dist/index.cjs.map +1 -1
  8. package/packages/cli/dist/index.mjs +156 -36
  9. package/packages/cli/dist/index.mjs.map +1 -1
  10. package/packages/cli/dist/{src-KFOBXFPN.mjs → src-XFIPYODW.mjs} +3 -3
  11. package/packages/cli/dist/{src-KFOBXFPN.mjs.map → src-XFIPYODW.mjs.map} +1 -1
  12. package/packages/core/dist/advanced.cjs +200 -24
  13. package/packages/core/dist/advanced.cjs.map +1 -1
  14. package/packages/core/dist/advanced.d.cts +1 -1
  15. package/packages/core/dist/advanced.d.ts +1 -1
  16. package/packages/core/dist/advanced.mjs +89 -15
  17. package/packages/core/dist/advanced.mjs.map +1 -1
  18. package/packages/core/dist/checks.mjs +2 -2
  19. package/packages/core/dist/{chunk-LXYPM2ZO.mjs → chunk-2CCRUI42.mjs} +19 -318
  20. package/packages/core/dist/chunk-2CCRUI42.mjs.map +1 -0
  21. package/packages/core/dist/{chunk-QLYUWKK7.mjs → chunk-2IRRUNIN.mjs} +11 -5
  22. package/packages/core/dist/chunk-2IRRUNIN.mjs.map +1 -0
  23. package/packages/core/dist/{chunk-VQUB3WRI.mjs → chunk-3SPBELJB.mjs} +14 -3
  24. package/packages/core/dist/chunk-3SPBELJB.mjs.map +1 -0
  25. package/packages/core/dist/{chunk-3RV3JILQ.mjs → chunk-IJJSPJXV.mjs} +20 -12
  26. package/packages/core/dist/chunk-IJJSPJXV.mjs.map +1 -0
  27. package/packages/core/dist/chunk-L5WLVBW4.mjs +355 -0
  28. package/packages/core/dist/chunk-L5WLVBW4.mjs.map +1 -0
  29. package/packages/core/dist/exporters.cjs +110 -18
  30. package/packages/core/dist/exporters.cjs.map +1 -1
  31. package/packages/core/dist/exporters.mjs +110 -18
  32. package/packages/core/dist/exporters.mjs.map +1 -1
  33. package/packages/core/dist/index.cjs +12 -1
  34. package/packages/core/dist/index.cjs.map +1 -1
  35. package/packages/core/dist/index.mjs +2 -2
  36. package/packages/core/dist/persisted.cjs +344 -9
  37. package/packages/core/dist/persisted.cjs.map +1 -1
  38. package/packages/core/dist/persisted.d.cts +8 -1
  39. package/packages/core/dist/persisted.d.ts +8 -1
  40. package/packages/core/dist/persisted.mjs +3 -2
  41. package/packages/core/dist/persisted.mjs.map +1 -1
  42. package/packages/core/dist/readers.cjs +377 -87
  43. package/packages/core/dist/readers.cjs.map +1 -1
  44. package/packages/core/dist/readers.mjs +3 -3
  45. package/packages/cli/dist/chunk-QV73NM25.mjs.map +0 -1
  46. package/packages/core/dist/chunk-3RV3JILQ.mjs.map +0 -1
  47. package/packages/core/dist/chunk-FWK3Q3OJ.mjs +0 -56
  48. package/packages/core/dist/chunk-FWK3Q3OJ.mjs.map +0 -1
  49. package/packages/core/dist/chunk-LXYPM2ZO.mjs.map +0 -1
  50. package/packages/core/dist/chunk-QLYUWKK7.mjs.map +0 -1
  51. package/packages/core/dist/chunk-VQUB3WRI.mjs.map +0 -1
@@ -740,11 +740,13 @@ function exportOpenInference(tree, options) {
740
740
  endNs = startNs + unixNano(ev.durationMs);
741
741
  }
742
742
  const { openInferenceKind } = mapInspectKindToOI(ev.kind, warnings);
743
+ const meta = ev.attributes;
744
+ const originalSource = typeof meta?.originalSourceType === "string" && meta.originalSourceType.trim() !== "" ? meta.originalSourceType.trim() : ev.source.type;
743
745
  const attrs = {
744
746
  "openinference.span.kind": openInferenceKind,
745
747
  "agent_inspect.kind": ev.kind,
746
748
  "agent_inspect.confidence": ev.confidence,
747
- "agent_inspect.source.type": ev.source.type,
749
+ "agent_inspect.source.type": originalSource,
748
750
  "agent_inspect.run_id": tree.runId,
749
751
  "agent_inspect.event_id": ev.eventId,
750
752
  "agent_inspect.status": ev.status ?? "unset"
@@ -752,9 +754,9 @@ function exportOpenInference(tree, options) {
752
754
  if (ev.durationMs !== void 0) {
753
755
  attrs["agent_inspect.duration_ms"] = ev.durationMs;
754
756
  }
755
- const meta = ev.attributes;
756
- if (meta?.model !== void 0 && typeof meta.model === "string") {
757
- attrs["llm.model_name"] = meta.model;
757
+ const requestModel = (typeof meta?.model === "string" && meta.model.trim() !== "" ? meta.model : void 0) ?? (typeof meta?.modelId === "string" && meta.modelId.trim() !== "" ? meta.modelId : void 0);
758
+ if (requestModel !== void 0) {
759
+ attrs["llm.model_name"] = requestModel;
758
760
  }
759
761
  const tokens = meta?.tokens;
760
762
  if (tokens && typeof tokens === "object" && tokens !== null) {
@@ -764,8 +766,9 @@ function exportOpenInference(tree, options) {
764
766
  if (typeof outp === "number") attrs["llm.token_count.completion"] = outp;
765
767
  }
766
768
  if (includeAttributes && meta && typeof meta === "object") {
769
+ const skipKeys = /* @__PURE__ */ new Set(["tokens", "model", "modelId", "originalSourceType"]);
767
770
  for (const [k, v] of Object.entries(meta)) {
768
- if (k === "tokens" || k === "model") continue;
771
+ if (skipKeys.has(k)) continue;
769
772
  if (v !== void 0 && v !== null && typeof v !== "object") {
770
773
  attrs[`agent_inspect.preview.${k}`] = typeof v === "string" ? v.slice(0, maxLen) : v;
771
774
  }
@@ -883,24 +886,33 @@ function exportOtlpJson(tree, options) {
883
886
  const spanId = hexFrom2(`${tree.runId}:${ev.eventId}`, 8);
884
887
  const parentSpanId = ev.parentId ? hexFrom2(`${tree.runId}:${ev.parentId}`, 8) : void 0;
885
888
  const { startNs, endNs } = resolveSpanTimes(ev);
889
+ const meta = ev.attributes;
890
+ const originalSource = typeof meta?.originalSourceType === "string" && meta.originalSourceType.trim() !== "" ? meta.originalSourceType.trim() : ev.source.type;
886
891
  const attrs = [
887
892
  stringAttr("agent_inspect.kind", ev.kind),
888
893
  stringAttr("agent_inspect.confidence", ev.confidence),
889
- stringAttr("agent_inspect.source.type", ev.source.type),
894
+ stringAttr("agent_inspect.source.type", originalSource),
890
895
  stringAttr("agent_inspect.run_id", tree.runId),
891
896
  stringAttr("agent_inspect.event_id", ev.eventId),
892
897
  stringAttr("agent_inspect.status", ev.status ?? "unset")
893
898
  ];
894
899
  if (ev.durationMs !== void 0) {
895
- attrs.push(intAttr("agent_inspect.duration_ms", ev.durationMs));
900
+ attrs.push(numberAttr("agent_inspect.duration_ms", ev.durationMs));
896
901
  }
897
902
  const op = genAiOperationName(ev.kind);
898
903
  if (op !== void 0) {
899
904
  attrs.push(stringAttr("gen_ai.operation.name", op));
900
905
  }
901
- const meta = ev.attributes;
902
- if (meta?.model !== void 0 && typeof meta.model === "string") {
903
- attrs.push(stringAttr("gen_ai.request.model", meta.model.slice(0, maxLen)));
906
+ const requestModel = (typeof meta?.model === "string" && meta.model.trim() !== "" ? meta.model : void 0) ?? (typeof meta?.modelId === "string" && meta.modelId.trim() !== "" ? meta.modelId : void 0);
907
+ if (requestModel !== void 0) {
908
+ attrs.push(stringAttr("gen_ai.request.model", requestModel.slice(0, maxLen)));
909
+ }
910
+ const responseModel = typeof meta?.responseModelId === "string" && meta.responseModelId.trim() !== "" ? meta.responseModelId : typeof meta?.responseModel === "string" && meta.responseModel.trim() !== "" ? meta.responseModel : void 0;
911
+ if (responseModel !== void 0) {
912
+ attrs.push(stringAttr("gen_ai.response.model", responseModel.slice(0, maxLen)));
913
+ }
914
+ if (typeof meta?.provider === "string" && meta.provider.trim() !== "") {
915
+ attrs.push(stringAttr("gen_ai.provider.name", meta.provider.slice(0, maxLen)));
904
916
  }
905
917
  const tokens = meta?.tokens;
906
918
  if (tokens && typeof tokens === "object" && tokens !== null) {
@@ -910,8 +922,17 @@ function exportOtlpJson(tree, options) {
910
922
  if (typeof outp === "number") attrs.push(intAttr("gen_ai.usage.output_tokens", outp));
911
923
  }
912
924
  if (includeAttributes && meta && typeof meta === "object") {
925
+ const skipKeys = /* @__PURE__ */ new Set([
926
+ "tokens",
927
+ "model",
928
+ "modelId",
929
+ "responseModel",
930
+ "responseModelId",
931
+ "provider",
932
+ "originalSourceType"
933
+ ]);
913
934
  for (const [k, v] of Object.entries(meta)) {
914
- if (k === "tokens" || k === "model") continue;
935
+ if (skipKeys.has(k)) continue;
915
936
  if (typeof v === "string") {
916
937
  attrs.push(stringAttr(`agent_inspect.preview.${k}`, v.slice(0, maxLen)));
917
938
  } else if (typeof v === "number" && Number.isFinite(v)) {
@@ -981,12 +1002,42 @@ function pushPath(errors, path, message) {
981
1002
  function isRecord2(value) {
982
1003
  return value !== null && typeof value === "object" && !Array.isArray(value);
983
1004
  }
1005
+ function isHexId(value, byteLen) {
1006
+ return typeof value === "string" && new RegExp(`^[0-9a-fA-F]{${byteLen * 2}}$`).test(value);
1007
+ }
1008
+ function validateAnyValue(errors, path, value) {
1009
+ if (!isRecord2(value)) {
1010
+ pushPath(errors, path, "must be an AnyValue object");
1011
+ return;
1012
+ }
1013
+ const variants = [
1014
+ "stringValue",
1015
+ "boolValue",
1016
+ "intValue",
1017
+ "doubleValue",
1018
+ "bytesValue",
1019
+ "arrayValue",
1020
+ "kvlistValue"
1021
+ ].filter((key) => value[key] !== void 0);
1022
+ if (variants.length !== 1) {
1023
+ pushPath(
1024
+ errors,
1025
+ path,
1026
+ `AnyValue must set exactly one variant (found ${variants.length}: ${variants.join(",")})`
1027
+ );
1028
+ }
1029
+ if (value.intValue !== void 0) {
1030
+ if (typeof value.intValue !== "string" || !/^-?\d+$/.test(value.intValue)) {
1031
+ pushPath(errors, `${path}.intValue`, "must be a decimal integer string");
1032
+ }
1033
+ }
1034
+ }
984
1035
  function validateOtlpJson(content) {
985
1036
  const errors = [];
986
1037
  const warnings = [
987
1038
  EXPERIMENTAL,
988
1039
  "OTLP JSON mapping uses OTel GenAI-aligned attributes where applicable; collectors may require transformation.",
989
- "protocol-valid \u2260 profile-complete \u2260 fixture-complete \u2014 nested path diagnostics report protocol shape only."
1040
+ "producer-profile checks IDs, timing, and AnyValue shape; historical string enums are reader-compat warnings only."
990
1041
  ];
991
1042
  let parsed;
992
1043
  try {
@@ -1029,11 +1080,26 @@ function validateOtlpJson(content) {
1029
1080
  pushPath(errors, spanPath, "must be an object");
1030
1081
  return;
1031
1082
  }
1032
- if (typeof span.traceId !== "string" || span.traceId.length === 0) {
1033
- pushPath(errors, `${spanPath}.traceId`, "must be a non-empty string");
1083
+ if (!isHexId(span.traceId, 16)) {
1084
+ pushPath(
1085
+ errors,
1086
+ `${spanPath}.traceId`,
1087
+ "must be a 32-char hex trace id (16 bytes)"
1088
+ );
1089
+ }
1090
+ if (!isHexId(span.spanId, 8)) {
1091
+ pushPath(
1092
+ errors,
1093
+ `${spanPath}.spanId`,
1094
+ "must be a 16-char hex span id (8 bytes)"
1095
+ );
1034
1096
  }
1035
- if (typeof span.spanId !== "string" || span.spanId.length === 0) {
1036
- pushPath(errors, `${spanPath}.spanId`, "must be a non-empty string");
1097
+ if (span.parentSpanId !== void 0 && !isHexId(span.parentSpanId, 8)) {
1098
+ pushPath(
1099
+ errors,
1100
+ `${spanPath}.parentSpanId`,
1101
+ "must be a 16-char hex span id when present"
1102
+ );
1037
1103
  }
1038
1104
  if (typeof span.name !== "string") {
1039
1105
  pushPath(errors, `${spanPath}.name`, "must be a string");
@@ -1052,13 +1118,39 @@ function validateOtlpJson(content) {
1052
1118
  "must be a decimal-string 64-bit integer when present"
1053
1119
  );
1054
1120
  }
1121
+ if (typeof span.startTimeUnixNano === "string" && /^\d+$/.test(span.startTimeUnixNano) && typeof span.endTimeUnixNano === "string" && /^\d+$/.test(span.endTimeUnixNano)) {
1122
+ try {
1123
+ if (BigInt(span.endTimeUnixNano) < BigInt(span.startTimeUnixNano)) {
1124
+ pushPath(
1125
+ errors,
1126
+ `${spanPath}.endTimeUnixNano`,
1127
+ "must be >= startTimeUnixNano"
1128
+ );
1129
+ }
1130
+ } catch {
1131
+ pushPath(errors, `${spanPath}.endTimeUnixNano`, "out of integer range");
1132
+ }
1133
+ }
1134
+ if (Array.isArray(span.attributes)) {
1135
+ span.attributes.forEach((attr, ai) => {
1136
+ const attrPath = `${spanPath}.attributes[${ai}]`;
1137
+ if (!isRecord2(attr)) {
1138
+ pushPath(errors, attrPath, "must be an object");
1139
+ return;
1140
+ }
1141
+ if (typeof attr.key !== "string") {
1142
+ pushPath(errors, `${attrPath}.key`, "must be a string");
1143
+ }
1144
+ validateAnyValue(errors, `${attrPath}.value`, attr.value);
1145
+ });
1146
+ }
1055
1147
  if (typeof span.kind === "number") {
1056
1148
  if (!Number.isInteger(span.kind)) {
1057
1149
  pushPath(errors, `${spanPath}.kind`, "must be an integer SpanKind enum");
1058
1150
  }
1059
1151
  } else if (typeof span.kind === "string") {
1060
1152
  warnings.push(
1061
- `${spanPath}.kind: string SpanKind enum is legacy; prefer numeric (INTERNAL=1)`
1153
+ `${spanPath}.kind: string SpanKind is historical reader-compat only; producer wire format uses numeric enums`
1062
1154
  );
1063
1155
  } else if (span.kind !== void 0) {
1064
1156
  pushPath(
@@ -1089,7 +1181,7 @@ function validateOtlpJson(content) {
1089
1181
  );
1090
1182
  } else {
1091
1183
  warnings.push(
1092
- `${spanPath}.status.code: string StatusCode is legacy; prefer numeric 0/1/2`
1184
+ `${spanPath}.status.code: string StatusCode is historical reader-compat only; producer wire format uses numeric 0/1/2`
1093
1185
  );
1094
1186
  }
1095
1187
  } else {