@agent-inspect/viewer 4.3.0 → 4.4.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/dist/index.cjs CHANGED
@@ -78,6 +78,9 @@ function isTraceEvent(value) {
78
78
  case "step_completed": {
79
79
  return typeof value.runId === "string" && typeof value.stepId === "string" && (value.status === "success" || value.status === "error") && typeof value.endTime === "number" && typeof value.durationMs === "number";
80
80
  }
81
+ case "outcome_observed": {
82
+ return typeof value.runId === "string" && typeof value.outcomeId === "string" && typeof value.name === "string" && typeof value.expectation === "string" && (value.status === "passed" || value.status === "failed" || value.status === "unknown" || value.status === "skipped") && typeof value.observedAt === "number";
83
+ }
81
84
  default:
82
85
  return false;
83
86
  }
@@ -95,7 +98,8 @@ var INSPECT_KINDS = [
95
98
  "RESULT",
96
99
  "ERROR",
97
100
  "LOGIC",
98
- "LOG"
101
+ "LOG",
102
+ "OUTCOME"
99
103
  ];
100
104
  var ATTRIBUTION_CONFIDENCES = [
101
105
  "explicit",
@@ -387,6 +391,32 @@ function fromLegacyStepCompleted(event) {
387
391
  if (error) out.error = error;
388
392
  return out;
389
393
  }
394
+ function fromLegacyOutcomeObserved(event) {
395
+ const attrs = event.attributes ?? {};
396
+ const observedAtRaw = attrs.observedAt;
397
+ const observedAt = typeof observedAtRaw === "string" ? Date.parse(observedAtRaw) : typeof observedAtRaw === "number" && Number.isFinite(observedAtRaw) ? observedAtRaw : resolveTimes(event).timestamp;
398
+ const status = attrs.outcomeStatus;
399
+ const out = {
400
+ schemaVersion: "0.1",
401
+ event: "outcome_observed",
402
+ timestamp: observedAt,
403
+ runId: event.runId,
404
+ outcomeId: typeof attrs.outcomeId === "string" ? attrs.outcomeId : event.eventId,
405
+ name: event.name,
406
+ expectation: typeof attrs.expectation === "string" ? attrs.expectation : event.name,
407
+ status: status === "passed" || status === "failed" || status === "unknown" || status === "skipped" ? status : "unknown",
408
+ observedAt
409
+ };
410
+ if (event.parentId !== void 0) out.parentId = event.parentId;
411
+ if (typeof attrs.method === "string") out.method = attrs.method;
412
+ if (attrs.actual !== void 0) out.actual = attrs.actual;
413
+ if (event.outputSummary !== void 0) out.actual = event.outputSummary;
414
+ if (attrs.evidence !== void 0) out.evidence = attrs.evidence;
415
+ return out;
416
+ }
417
+ function fromNativeOutcome(event) {
418
+ return [fromLegacyOutcomeObserved(event)];
419
+ }
390
420
  function fromNativeRun(event) {
391
421
  const { timestamp, startTime, endTime } = resolveTimes(event);
392
422
  const runStatus = mapPersistedStatusToRunStatus(event.status);
@@ -474,9 +504,13 @@ function persistedInspectEventToTraceEvents(event) {
474
504
  if (legacyEvent === "run_completed") return [fromLegacyRunCompleted(event)];
475
505
  if (legacyEvent === "step_started") return [fromLegacyStepStarted(event)];
476
506
  if (legacyEvent === "step_completed") return [fromLegacyStepCompleted(event)];
507
+ if (legacyEvent === "outcome_observed") return [fromLegacyOutcomeObserved(event)];
477
508
  if (event.kind === "RUN") {
478
509
  return fromNativeRun(event);
479
510
  }
511
+ if (event.kind === "OUTCOME") {
512
+ return fromNativeOutcome(event);
513
+ }
480
514
  return fromNativeStep(event);
481
515
  }
482
516
  function persistedInspectEventsToTraceEvents(events, options) {
@@ -676,6 +710,9 @@ function validateEvent(event) {
676
710
  case "step_completed": {
677
711
  return nonEmptyString(event.runId) && nonEmptyString(event.stepId) && (event.status === "success" || event.status === "error") && finiteNumber(event.endTime) && finiteNumber(event.durationMs) && optionalErrorInfo(event.error);
678
712
  }
713
+ case "outcome_observed": {
714
+ return nonEmptyString(event.runId) && nonEmptyString(event.outcomeId) && nonEmptyString(event.name) && nonEmptyString(event.expectation) && (event.status === "passed" || event.status === "failed" || event.status === "unknown" || event.status === "skipped") && finiteNumber(event.observedAt);
715
+ }
679
716
  default:
680
717
  return false;
681
718
  }
@@ -1800,6 +1837,8 @@ function nodeIdForEvent(event) {
1800
1837
  case "step_started":
1801
1838
  case "step_completed":
1802
1839
  return event.stepId;
1840
+ case "outcome_observed":
1841
+ return event.outcomeId;
1803
1842
  default:
1804
1843
  return "unknown";
1805
1844
  }
@@ -1983,6 +2022,39 @@ function traceEventToPersistedInspectEvent(event, options) {
1983
2022
  error
1984
2023
  };
1985
2024
  }
2025
+ case "outcome_observed": {
2026
+ const tsObserved = toIsoTimestamp(event.observedAt);
2027
+ const attributes = compactAttributes({
2028
+ legacyEvent: "outcome_observed",
2029
+ outcomeId: event.outcomeId,
2030
+ outcomeStatus: event.status,
2031
+ expectation: event.expectation,
2032
+ method: event.method,
2033
+ actual: event.actual,
2034
+ evidence: event.evidence,
2035
+ observedAt: tsObserved.iso,
2036
+ invalidTimestamp: tsMain.invalidTimestamp || tsObserved.invalidTimestamp ? true : void 0
2037
+ });
2038
+ const out = {
2039
+ schemaVersion: "0.2",
2040
+ eventId,
2041
+ runId: event.runId,
2042
+ kind: "OUTCOME",
2043
+ name: event.name,
2044
+ status: event.status === "failed" ? "error" : "ok",
2045
+ timestamp: tsMain.iso,
2046
+ confidence: "explicit",
2047
+ source,
2048
+ attributes
2049
+ };
2050
+ if (event.parentId !== void 0) {
2051
+ out.parentId = event.parentId;
2052
+ }
2053
+ if (event.actual !== void 0) {
2054
+ out.outputSummary = event.actual;
2055
+ }
2056
+ return out;
2057
+ }
1986
2058
  default: {
1987
2059
  const _exhaustive = event;
1988
2060
  throw new Error(`Unsupported trace event: ${_exhaustive.event}`);
@@ -2712,7 +2784,7 @@ function sanitizeOpenInferenceAttributes(attributes, pathPrefix) {
2712
2784
  function mapOpenInferenceKind(span, attributes, pathPrefix) {
2713
2785
  const warnings = [];
2714
2786
  const agentInspectKind = attributes["agent_inspect.kind"];
2715
- if (agentInspectKind === "RUN" || agentInspectKind === "AGENT" || agentInspectKind === "LLM" || agentInspectKind === "TOOL" || agentInspectKind === "CHAIN" || agentInspectKind === "RETRIEVER" || agentInspectKind === "DECISION" || agentInspectKind === "RESULT" || agentInspectKind === "ERROR" || agentInspectKind === "LOGIC" || agentInspectKind === "LOG") {
2787
+ if (agentInspectKind === "RUN" || agentInspectKind === "AGENT" || agentInspectKind === "LLM" || agentInspectKind === "TOOL" || agentInspectKind === "CHAIN" || agentInspectKind === "RETRIEVER" || agentInspectKind === "DECISION" || agentInspectKind === "RESULT" || agentInspectKind === "ERROR" || agentInspectKind === "LOGIC" || agentInspectKind === "LOG" || agentInspectKind === "OUTCOME") {
2716
2788
  return { kind: agentInspectKind, warnings };
2717
2789
  }
2718
2790
  const rawKind = readStringField(span, ["kind", "span_kind", "spanKind"]) ?? (typeof attributes["openinference.span.kind"] === "string" ? attributes["openinference.span.kind"] : void 0);
@@ -3233,7 +3305,7 @@ function mapOtlpStatus(status) {
3233
3305
  function readOtlpKind(attributes, pathPrefix) {
3234
3306
  const warnings = [];
3235
3307
  const agentInspectKind = attributes["agent_inspect.kind"];
3236
- if (agentInspectKind === "RUN" || agentInspectKind === "AGENT" || agentInspectKind === "LLM" || agentInspectKind === "TOOL" || agentInspectKind === "CHAIN" || agentInspectKind === "RETRIEVER" || agentInspectKind === "DECISION" || agentInspectKind === "RESULT" || agentInspectKind === "ERROR" || agentInspectKind === "LOGIC" || agentInspectKind === "LOG") {
3308
+ if (agentInspectKind === "RUN" || agentInspectKind === "AGENT" || agentInspectKind === "LLM" || agentInspectKind === "TOOL" || agentInspectKind === "CHAIN" || agentInspectKind === "RETRIEVER" || agentInspectKind === "DECISION" || agentInspectKind === "RESULT" || agentInspectKind === "ERROR" || agentInspectKind === "LOGIC" || agentInspectKind === "LOG" || agentInspectKind === "OUTCOME") {
3237
3309
  return { kind: agentInspectKind, warnings };
3238
3310
  }
3239
3311
  const operation = attributes["gen_ai.operation.name"];