@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
@@ -0,0 +1,58 @@
1
+ import { ClientFn } from "../types/core.js";
2
+ import { DocumentAnnotation } from "./types.js";
3
+ /**
4
+ * Parameters to log multiple document annotations
5
+ */
6
+ export interface LogDocumentAnnotationsParams extends ClientFn {
7
+ /**
8
+ * The document annotations to log
9
+ */
10
+ documentAnnotations: DocumentAnnotation[];
11
+ /**
12
+ * If true, the request will be fulfilled synchronously and return the annotation IDs.
13
+ * If false, the request will be processed asynchronously and return null.
14
+ * @default false
15
+ */
16
+ sync?: boolean;
17
+ }
18
+ /**
19
+ * Log multiple document annotations in a single request.
20
+ *
21
+ * Each annotation can be of type "LLM", "CODE", or "HUMAN" and can include a label, score, explanation, and metadata.
22
+ * At least one of label, score, or explanation must be provided for each annotation.
23
+ *
24
+ * @param params - The parameters to log document annotations
25
+ * @returns The IDs of the created annotations
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * const results = await logDocumentAnnotations({
30
+ * documentAnnotations: [
31
+ * {
32
+ * spanId: "123abc",
33
+ * documentPosition: 0,
34
+ * name: "relevance_score",
35
+ * label: "relevant",
36
+ * score: 0.95,
37
+ * annotatorKind: "LLM",
38
+ * explanation: "Document is highly relevant to the query",
39
+ * metadata: {
40
+ * model: "gpt-4"
41
+ * }
42
+ * },
43
+ * {
44
+ * spanId: "123abc",
45
+ * documentPosition: 1,
46
+ * name: "relevance_score",
47
+ * label: "somewhat_relevant",
48
+ * score: 0.6,
49
+ * annotatorKind: "LLM"
50
+ * }
51
+ * ]
52
+ * });
53
+ * ```
54
+ */
55
+ export declare function logDocumentAnnotations({ client: _client, documentAnnotations, sync, }: LogDocumentAnnotationsParams): Promise<{
56
+ id: string;
57
+ }[]>;
58
+ //# sourceMappingURL=logDocumentAnnotations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logDocumentAnnotations.d.ts","sourceRoot":"","sources":["../../../src/spans/logDocumentAnnotations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAA4B,MAAM,SAAS,CAAC;AAEvE;;GAEG;AACH,MAAM,WAAW,4BAA6B,SAAQ,QAAQ;IAC5D;;OAEG;IACH,mBAAmB,EAAE,kBAAkB,EAAE,CAAC;IAC1C;;;;OAIG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAsB,sBAAsB,CAAC,EAC3C,MAAM,EAAE,OAAO,EACf,mBAAmB,EACnB,IAAY,GACb,EAAE,4BAA4B,GAAG,OAAO,CAAC;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,EAAE,CAAC,CAiB1D"}
@@ -0,0 +1,55 @@
1
+ import { createClient } from "../client.js";
2
+ import { toDocumentAnnotationData } from "./types.js";
3
+ /**
4
+ * Log multiple document annotations in a single request.
5
+ *
6
+ * Each annotation can be of type "LLM", "CODE", or "HUMAN" and can include a label, score, explanation, and metadata.
7
+ * At least one of label, score, or explanation must be provided for each annotation.
8
+ *
9
+ * @param params - The parameters to log document annotations
10
+ * @returns The IDs of the created annotations
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const results = await logDocumentAnnotations({
15
+ * documentAnnotations: [
16
+ * {
17
+ * spanId: "123abc",
18
+ * documentPosition: 0,
19
+ * name: "relevance_score",
20
+ * label: "relevant",
21
+ * score: 0.95,
22
+ * annotatorKind: "LLM",
23
+ * explanation: "Document is highly relevant to the query",
24
+ * metadata: {
25
+ * model: "gpt-4"
26
+ * }
27
+ * },
28
+ * {
29
+ * spanId: "123abc",
30
+ * documentPosition: 1,
31
+ * name: "relevance_score",
32
+ * label: "somewhat_relevant",
33
+ * score: 0.6,
34
+ * annotatorKind: "LLM"
35
+ * }
36
+ * ]
37
+ * });
38
+ * ```
39
+ */
40
+ export async function logDocumentAnnotations({ client: _client, documentAnnotations, sync = false, }) {
41
+ const client = _client ?? createClient();
42
+ const { data, error } = await client.POST("/v1/document_annotations", {
43
+ params: {
44
+ query: { sync },
45
+ },
46
+ body: {
47
+ data: documentAnnotations.map(toDocumentAnnotationData),
48
+ },
49
+ });
50
+ if (error) {
51
+ throw new Error(`Failed to log document annotations: ${error}`);
52
+ }
53
+ return data?.data || [];
54
+ }
55
+ //# sourceMappingURL=logDocumentAnnotations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logDocumentAnnotations.js","sourceRoot":"","sources":["../../../src/spans/logDocumentAnnotations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAsB,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAkBvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,EAC3C,MAAM,EAAE,OAAO,EACf,mBAAmB,EACnB,IAAI,GAAG,KAAK,GACiB;IAC7B,MAAM,MAAM,GAAG,OAAO,IAAI,YAAY,EAAE,CAAC;IAEzC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,0BAA0B,EAAE;QACpE,MAAM,EAAE;YACN,KAAK,EAAE,EAAE,IAAI,EAAE;SAChB;QACD,IAAI,EAAE;YACJ,IAAI,EAAE,mBAAmB,CAAC,GAAG,CAAC,wBAAwB,CAAC;SACxD;KACF,CAAC,CAAC;IAEH,IAAI,KAAK,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CAAC,uCAAuC,KAAK,EAAE,CAAC,CAAC;IAClE,CAAC;IAED,OAAO,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC;AAC1B,CAAC"}
@@ -8,6 +8,12 @@ export interface LogSpanAnnotationsParams extends ClientFn {
8
8
  * The span annotations to log
9
9
  */
10
10
  spanAnnotations: SpanAnnotation[];
11
+ /**
12
+ * If true, the request will be fulfilled synchronously and return the annotation IDs.
13
+ * If false, the request will be processed asynchronously and return null.
14
+ * @default false
15
+ */
16
+ sync?: boolean;
11
17
  }
12
18
  /**
13
19
  * Log multiple span annotations in a single request.
@@ -44,7 +50,7 @@ export interface LogSpanAnnotationsParams extends ClientFn {
44
50
  * });
45
51
  * ```
46
52
  */
47
- export declare function logSpanAnnotations({ client: _client, spanAnnotations, }: LogSpanAnnotationsParams): Promise<{
53
+ export declare function logSpanAnnotations({ client: _client, spanAnnotations, sync, }: LogSpanAnnotationsParams): Promise<{
48
54
  id: string;
49
55
  }[]>;
50
56
  //# sourceMappingURL=logSpanAnnotations.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logSpanAnnotations.d.ts","sourceRoot":"","sources":["../../../src/spans/logSpanAnnotations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,cAAc,EAAwB,MAAM,SAAS,CAAC;AAE/D;;GAEG;AACH,MAAM,WAAW,wBAAyB,SAAQ,QAAQ;IACxD;;OAEG;IACH,eAAe,EAAE,cAAc,EAAE,CAAC;CACnC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAsB,kBAAkB,CAAC,EACvC,MAAM,EAAE,OAAO,EACf,eAAe,GAChB,EAAE,wBAAwB,GAAG,OAAO,CAAC;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,EAAE,CAAC,CAkBtD"}
1
+ {"version":3,"file":"logSpanAnnotations.d.ts","sourceRoot":"","sources":["../../../src/spans/logSpanAnnotations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,cAAc,EAAwB,MAAM,SAAS,CAAC;AAE/D;;GAEG;AACH,MAAM,WAAW,wBAAyB,SAAQ,QAAQ;IACxD;;OAEG;IACH,eAAe,EAAE,cAAc,EAAE,CAAC;IAClC;;;;OAIG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAsB,kBAAkB,CAAC,EACvC,MAAM,EAAE,OAAO,EACf,eAAe,EACf,IAAY,GACb,EAAE,wBAAwB,GAAG,OAAO,CAAC;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,EAAE,CAAC,CAiBtD"}
@@ -35,9 +35,12 @@ import { toSpanAnnotationData } from "./types.js";
35
35
  * });
36
36
  * ```
37
37
  */
38
- export async function logSpanAnnotations({ client: _client, spanAnnotations, }) {
38
+ export async function logSpanAnnotations({ client: _client, spanAnnotations, sync = false, }) {
39
39
  const client = _client ?? createClient();
40
40
  const { data, error } = await client.POST("/v1/span_annotations", {
41
+ params: {
42
+ query: { sync },
43
+ },
41
44
  body: {
42
45
  data: spanAnnotations.map(toSpanAnnotationData),
43
46
  },
@@ -45,9 +48,6 @@ export async function logSpanAnnotations({ client: _client, spanAnnotations, })
45
48
  if (error) {
46
49
  throw new Error(`Failed to log span annotations: ${error}`);
47
50
  }
48
- if (!data?.data?.length) {
49
- throw new Error("No annotation IDs returned from server");
50
- }
51
- return data.data;
51
+ return data?.data || [];
52
52
  }
53
53
  //# sourceMappingURL=logSpanAnnotations.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"logSpanAnnotations.js","sourceRoot":"","sources":["../../../src/spans/logSpanAnnotations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAkB,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAY/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,EACvC,MAAM,EAAE,OAAO,EACf,eAAe,GACU;IACzB,MAAM,MAAM,GAAG,OAAO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AAC;IAC9D,CAAC;IAED,OAAO,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC;AAC1B,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import { paths } from "../__generated__/api/v1.js";
2
2
  type SpanAnnotationData = paths["/v1/span_annotations"]["post"]["requestBody"]["content"]["application/json"]["data"][0];
3
+ type SpanDocumentAnnotationData = paths["/v1/document_annotations"]["post"]["requestBody"]["content"]["application/json"]["data"][0];
3
4
  /**
4
5
  * Parameters for a single span annotation
5
6
  */
@@ -20,6 +21,10 @@ export interface SpanAnnotation {
20
21
  * The score assigned by the annotation
21
22
  */
22
23
  score?: number;
24
+ /**
25
+ * Explanation of the annotation result
26
+ */
27
+ explanation?: string;
23
28
  /**
24
29
  * The identifier of the annotation. If provided, the annotation will be updated if it already exists.
25
30
  */
@@ -35,9 +40,52 @@ export interface SpanAnnotation {
35
40
  */
36
41
  annotatorKind?: SpanAnnotationData["annotator_kind"];
37
42
  }
43
+ /**
44
+ * Parameters for a single document annotation
45
+ */
46
+ export interface DocumentAnnotation {
47
+ /**
48
+ * The OpenTelemetry Span ID (hex format without 0x prefix)
49
+ */
50
+ spanId: string;
51
+ /**
52
+ * The 0-based index of the document within the span
53
+ */
54
+ documentPosition: number;
55
+ /**
56
+ * The name of the annotation
57
+ */
58
+ name: string;
59
+ /**
60
+ * The label assigned by the annotation
61
+ */
62
+ label?: string;
63
+ /**
64
+ * The score assigned by the annotation
65
+ */
66
+ score?: number;
67
+ /**
68
+ * Explanation of the annotation result
69
+ */
70
+ explanation?: string;
71
+ /**
72
+ * Metadata for the annotation
73
+ */
74
+ metadata?: Record<string, unknown>;
75
+ /**
76
+ * The kind of annotator used for the annotation
77
+ * Can be "HUMAN", "LLM", or "CODE"
78
+ * @default "HUMAN"
79
+ */
80
+ annotatorKind?: SpanDocumentAnnotationData["annotator_kind"];
81
+ }
38
82
  /**
39
83
  * Convert a SpanAnnotation to the API format
40
84
  */
41
85
  export declare function toSpanAnnotationData(annotation: SpanAnnotation): SpanAnnotationData;
86
+ /**
87
+ * Convert a DocumentAnnotation to the API format
88
+ */
89
+ export declare function toDocumentAnnotationData(annotation: DocumentAnnotation): SpanDocumentAnnotationData;
42
90
  export {};
43
91
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/spans/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAEhD,KAAK,kBAAkB,GACrB,KAAK,CAAC,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,CAAC,SAAS,CAAC,CAAC,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAEjG;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC;;;;OAIG;IACH,aAAa,CAAC,EAAE,kBAAkB,CAAC,gBAAgB,CAAC,CAAC;CACtD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,cAAc,GACzB,kBAAkB,CAapB"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/spans/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAEhD,KAAK,kBAAkB,GACrB,KAAK,CAAC,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,CAAC,SAAS,CAAC,CAAC,kBAAkB,CAAC,CAAC,MAAM,CAA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BAAgB,wBAAwB,CACtC,UAAU,EAAE,kBAAkB,GAC7B,0BAA0B,CAW5B"}
@@ -1,18 +1,51 @@
1
+ /**
2
+ * Build and validate annotation result fields
3
+ */
4
+ function buildAnnotationResult(annotation, annotationType) {
5
+ const result = {};
6
+ // Build result with trimming for string fields
7
+ if (annotation.label !== undefined) {
8
+ result.label = annotation.label.trim() || null;
9
+ }
10
+ if (annotation.score !== undefined) {
11
+ result.score = annotation.score;
12
+ }
13
+ if (annotation.explanation !== undefined) {
14
+ result.explanation = annotation.explanation.trim() || null;
15
+ }
16
+ // Validate that at least one result field is provided
17
+ const hasValidResult = result.label || result.score !== undefined || result.explanation;
18
+ if (!hasValidResult) {
19
+ throw new Error(`At least one of label, score, or explanation must be provided for ${annotationType} annotation`);
20
+ }
21
+ return result;
22
+ }
1
23
  /**
2
24
  * Convert a SpanAnnotation to the API format
3
25
  */
4
26
  export function toSpanAnnotationData(annotation) {
27
+ const result = buildAnnotationResult(annotation, "span");
28
+ return {
29
+ span_id: annotation.spanId.trim(),
30
+ name: annotation.name.trim(),
31
+ annotator_kind: annotation.annotatorKind ?? "HUMAN",
32
+ result,
33
+ metadata: annotation.metadata ?? null,
34
+ identifier: annotation.identifier?.trim() ?? "",
35
+ };
36
+ }
37
+ /**
38
+ * Convert a DocumentAnnotation to the API format
39
+ */
40
+ export function toDocumentAnnotationData(annotation) {
41
+ const result = buildAnnotationResult(annotation, "document");
5
42
  return {
6
- span_id: annotation.spanId,
7
- name: annotation.name,
43
+ span_id: annotation.spanId.trim(),
44
+ document_position: annotation.documentPosition,
45
+ name: annotation.name.trim(),
8
46
  annotator_kind: annotation.annotatorKind ?? "HUMAN",
9
- result: {
10
- label: annotation.label ?? null,
11
- score: annotation.score ?? null,
12
- explanation: null,
13
- },
47
+ result,
14
48
  metadata: annotation.metadata ?? null,
15
- identifier: annotation.identifier ?? "",
16
49
  };
17
50
  }
18
51
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/spans/types.ts"],"names":[],"mappings":"AAyCA;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,UAA0B;IAE1B,OAAO;QACL,OAAO,EAAE,UAAU,CAAC,MAAM;QAC1B,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,cAAc,EAAE,UAAU,CAAC,aAAa,IAAI,OAAO;QACnD,MAAM,EAAE;YACN,KAAK,EAAE,UAAU,CAAC,KAAK,IAAI,IAAI;YAC/B,KAAK,EAAE,UAAU,CAAC,KAAK,IAAI,IAAI;YAC/B,WAAW,EAAE,IAAI;SAClB;QACD,QAAQ,EAAE,UAAU,CAAC,QAAQ,IAAI,IAAI;QACrC,UAAU,EAAE,UAAU,CAAC,UAAU,IAAI,EAAE;KACxC,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/spans/types.ts"],"names":[],"mappings":"AA8FA;;GAEG;AACH,SAAS,qBAAqB,CAC5B,UAGC,EACD,cAAmC;IAEnC,MAAM,MAAM,GAAqB,EAAE,CAAC;IAEpC,+CAA+C;IAC/C,IAAI,UAAU,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QACnC,MAAM,CAAC,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,IAAI,CAAC;IACjD,CAAC;IACD,IAAI,UAAU,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QACnC,MAAM,CAAC,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC;IAClC,CAAC;IACD,IAAI,UAAU,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;QACzC,MAAM,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,IAAI,CAAC;IAC7D,CAAC;IAED,sDAAsD;IACtD,MAAM,cAAc,GAClB,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,IAAI,MAAM,CAAC,WAAW,CAAC;I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