@arizeai/phoenix-client 3.1.0 → 3.2.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.
Files changed (68) hide show
  1. package/README.md +22 -1
  2. package/dist/esm/__generated__/api/v1.d.ts +185 -47
  3. package/dist/esm/__generated__/api/v1.d.ts.map +1 -1
  4. package/dist/esm/spans/addDocumentAnnotation.d.ts +45 -0
  5. package/dist/esm/spans/addDocumentAnnotation.d.ts.map +1 -0
  6. package/dist/esm/spans/addDocumentAnnotation.js +45 -0
  7. package/dist/esm/spans/addDocumentAnnotation.js.map +1 -0
  8. package/dist/esm/spans/addSpanAnnotation.d.ts +8 -2
  9. package/dist/esm/spans/addSpanAnnotation.d.ts.map +1 -1
  10. package/dist/esm/spans/addSpanAnnotation.js +5 -5
  11. package/dist/esm/spans/addSpanAnnotation.js.map +1 -1
  12. package/dist/esm/spans/index.d.ts +2 -0
  13. package/dist/esm/spans/index.d.ts.map +1 -1
  14. package/dist/esm/spans/index.js +2 -0
  15. package/dist/esm/spans/index.js.map +1 -1
  16. package/dist/esm/spans/logDocumentAnnotations.d.ts +58 -0
  17. package/dist/esm/spans/logDocumentAnnotations.d.ts.map +1 -0
  18. package/dist/esm/spans/logDocumentAnnotations.js +55 -0
  19. package/dist/esm/spans/logDocumentAnnotations.js.map +1 -0
  20. package/dist/esm/spans/logSpanAnnotations.d.ts +7 -1
  21. package/dist/esm/spans/logSpanAnnotations.d.ts.map +1 -1
  22. package/dist/esm/spans/logSpanAnnotations.js +5 -5
  23. package/dist/esm/spans/logSpanAnnotations.js.map +1 -1
  24. package/dist/esm/spans/types.d.ts +48 -0
  25. package/dist/esm/spans/types.d.ts.map +1 -1
  26. package/dist/esm/spans/types.js +41 -8
  27. package/dist/esm/spans/types.js.map +1 -1
  28. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  29. package/dist/esm/utils/formatPromptMessages.d.ts.map +1 -1
  30. package/dist/esm/utils/getPromptBySelector.d.ts.map +1 -1
  31. package/dist/src/__generated__/api/v1.d.ts +185 -47
  32. package/dist/src/__generated__/api/v1.d.ts.map +1 -1
  33. package/dist/src/spans/addDocumentAnnotation.d.ts +45 -0
  34. package/dist/src/spans/addDocumentAnnotation.d.ts.map +1 -0
  35. package/dist/src/spans/addDocumentAnnotation.js +49 -0
  36. package/dist/src/spans/addDocumentAnnotation.js.map +1 -0
  37. package/dist/src/spans/addSpanAnnotation.d.ts +8 -2
  38. package/dist/src/spans/addSpanAnnotation.d.ts.map +1 -1
  39. package/dist/src/spans/addSpanAnnotation.js +6 -6
  40. package/dist/src/spans/addSpanAnnotation.js.map +1 -1
  41. package/dist/src/spans/index.d.ts +2 -0
  42. package/dist/src/spans/index.d.ts.map +1 -1
  43. package/dist/src/spans/index.js +2 -0
  44. package/dist/src/spans/index.js.map +1 -1
  45. package/dist/src/spans/logDocumentAnnotations.d.ts +58 -0
  46. package/dist/src/spans/logDocumentAnnotations.d.ts.map +1 -0
  47. package/dist/src/spans/logDocumentAnnotations.js +58 -0
  48. package/dist/src/spans/logDocumentAnnotations.js.map +1 -0
  49. package/dist/src/spans/logSpanAnnotations.d.ts +7 -1
  50. package/dist/src/spans/logSpanAnnotations.d.ts.map +1 -1
  51. package/dist/src/spans/logSpanAnnotations.js +5 -6
  52. package/dist/src/spans/logSpanAnnotations.js.map +1 -1
  53. package/dist/src/spans/types.d.ts +48 -0
  54. package/dist/src/spans/types.d.ts.map +1 -1
  55. package/dist/src/spans/types.js +45 -10
  56. package/dist/src/spans/types.js.map +1 -1
  57. package/dist/src/utils/formatPromptMessages.d.ts.map +1 -1
  58. package/dist/src/utils/getPromptBySelector.d.ts.map +1 -1
  59. package/dist/tsconfig.tsbuildinfo +1 -1
  60. package/package.json +1 -1
  61. package/src/__generated__/api/v1.d.ts +1240 -1238
  62. package/src/__generated__/api/v1.ts +185 -47
  63. package/src/spans/addDocumentAnnotation.ts +66 -0
  64. package/src/spans/addSpanAnnotation.ts +12 -6
  65. package/src/spans/index.ts +2 -0
  66. package/src/spans/logDocumentAnnotations.ts +79 -0
  67. package/src/spans/logSpanAnnotations.ts +11 -5
  68. package/src/spans/types.ts +112 -8
@@ -3,6 +3,9 @@ import { paths } from "../__generated__/api/v1";
3
3
  type SpanAnnotationData =
4
4
  paths["/v1/span_annotations"]["post"]["requestBody"]["content"]["application/json"]["data"][0];
5
5
 
6
+ type SpanDocumentAnnotationData =
7
+ paths["/v1/document_annotations"]["post"]["requestBody"]["content"]["application/json"]["data"][0];
8
+
6
9
  /**
7
10
  * Parameters for a single span annotation
8
11
  */
@@ -23,6 +26,10 @@ export interface SpanAnnotation {
23
26
  * The score assigned by the annotation
24
27
  */
25
28
  score?: number;
29
+ /**
30
+ * Explanation of the annotation result
31
+ */
32
+ explanation?: string;
26
33
  /**
27
34
  * The identifier of the annotation. If provided, the annotation will be updated if it already exists.
28
35
  */
@@ -39,22 +46,119 @@ export interface SpanAnnotation {
39
46
  annotatorKind?: SpanAnnotationData["annotator_kind"];
40
47
  }
41
48
 
49
+ /**
50
+ * Parameters for a single document annotation
51
+ */
52
+ export interface DocumentAnnotation {
53
+ /**
54
+ * The OpenTelemetry Span ID (hex format without 0x prefix)
55
+ */
56
+ spanId: string;
57
+ /**
58
+ * The 0-based index of the document within the span
59
+ */
60
+ documentPosition: number;
61
+ /**
62
+ * The name of the annotation
63
+ */
64
+ name: string;
65
+ /**
66
+ * The label assigned by the annotation
67
+ */
68
+ label?: string;
69
+ /**
70
+ * The score assigned by the annotation
71
+ */
72
+ score?: number;
73
+ /**
74
+ * Explanation of the annotation result
75
+ */
76
+ explanation?: string;
77
+ /**
78
+ * Metadata for the annotation
79
+ */
80
+ metadata?: Record<string, unknown>;
81
+ /**
82
+ * The kind of annotator used for the annotation
83
+ * Can be "HUMAN", "LLM", or "CODE"
84
+ * @default "HUMAN"
85
+ */
86
+ annotatorKind?: SpanDocumentAnnotationData["annotator_kind"];
87
+ }
88
+
89
+ type AnnotationResult = {
90
+ label?: string | null;
91
+ score?: number | null;
92
+ explanation?: string | null;
93
+ };
94
+
95
+ /**
96
+ * Build and validate annotation result fields
97
+ */
98
+ function buildAnnotationResult(
99
+ annotation: Pick<
100
+ SpanAnnotation | DocumentAnnotation,
101
+ "label" | "score" | "explanation"
102
+ >,
103
+ annotationType: "span" | "document"
104
+ ): AnnotationResult {
105
+ const result: AnnotationResult = {};
106
+
107
+ // Build result with trimming for string fields
108
+ if (annotation.label !== undefined) {
109
+ result.label = annotation.label.trim() || null;
110
+ }
111
+ if (annotation.score !== undefined) {
112
+ result.score = annotation.score;
113
+ }
114
+ if (annotation.explanation !== undefined) {
115
+ result.explanation = annotation.explanation.trim() || null;
116
+ }
117
+
118
+ // Validate that at least one result field is provided
119
+ const hasValidResult =
120
+ result.label || result.score !== undefined || result.explanation;
121
+ if (!hasValidResult) {
122
+ throw new Error(
123
+ `At least one of label, score, or explanation must be provided for ${annotationType} annotation`
124
+ );
125
+ }
126
+
127
+ return result;
128
+ }
129
+
42
130
  /**
43
131
  * Convert a SpanAnnotation to the API format
44
132
  */
45
133
  export function toSpanAnnotationData(
46
134
  annotation: SpanAnnotation
47
135
  ): SpanAnnotationData {
136
+ const result = buildAnnotationResult(annotation, "span");
137
+
138
+ return {
139
+ span_id: annotation.spanId.trim(),
140
+ name: annotation.name.trim(),
141
+ annotator_kind: annotation.annotatorKind ?? "HUMAN",
142
+ result,
143
+ metadata: annotation.metadata ?? null,
144
+ identifier: annotation.identifier?.trim() ?? "",
145
+ };
146
+ }
147
+
148
+ /**
149
+ * Convert a DocumentAnnotation to the API format
150
+ */
151
+ export function toDocumentAnnotationData(
152
+ annotation: DocumentAnnotation
153
+ ): SpanDocumentAnnotationData {
154
+ const result = buildAnnotationResult(annotation, "document");
155
+
48
156
  return {
49
- span_id: annotation.spanId,
50
- name: annotation.name,
157
+ span_id: annotation.spanId.trim(),
158
+ document_position: annotation.documentPosition,
159
+ name: annotation.name.trim(),
51
160
  annotator_kind: annotation.annotatorKind ?? "HUMAN",
52
- result: {
53
- label: annotation.label ?? null,
54
- score: annotation.score ?? null,
55
- explanation: null,
56
- },
161
+ result,
57
162
  metadata: annotation.metadata ?? null,
58
- identifier: annotation.identifier ?? "",
59
163
  };
60
164
  }