@arizeai/phoenix-client 6.3.0 → 6.5.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 (147) hide show
  1. package/dist/esm/__generated__/api/v1.d.ts +149 -0
  2. package/dist/esm/__generated__/api/v1.d.ts.map +1 -1
  3. package/dist/esm/client.d.ts +16 -0
  4. package/dist/esm/client.d.ts.map +1 -1
  5. package/dist/esm/client.js +55 -0
  6. package/dist/esm/client.js.map +1 -1
  7. package/dist/esm/constants/serverRequirements.d.ts +28 -0
  8. package/dist/esm/constants/serverRequirements.d.ts.map +1 -0
  9. package/dist/esm/constants/serverRequirements.js +65 -0
  10. package/dist/esm/constants/serverRequirements.js.map +1 -0
  11. package/dist/esm/sessions/addSessionAnnotation.d.ts +2 -0
  12. package/dist/esm/sessions/addSessionAnnotation.d.ts.map +1 -1
  13. package/dist/esm/sessions/addSessionAnnotation.js +5 -0
  14. package/dist/esm/sessions/addSessionAnnotation.js.map +1 -1
  15. package/dist/esm/sessions/deleteSession.d.ts +2 -0
  16. package/dist/esm/sessions/deleteSession.d.ts.map +1 -1
  17. package/dist/esm/sessions/deleteSession.js +5 -0
  18. package/dist/esm/sessions/deleteSession.js.map +1 -1
  19. package/dist/esm/sessions/deleteSessions.d.ts +2 -0
  20. package/dist/esm/sessions/deleteSessions.d.ts.map +1 -1
  21. package/dist/esm/sessions/deleteSessions.js +5 -0
  22. package/dist/esm/sessions/deleteSessions.js.map +1 -1
  23. package/dist/esm/sessions/getSession.d.ts +2 -0
  24. package/dist/esm/sessions/getSession.d.ts.map +1 -1
  25. package/dist/esm/sessions/getSession.js +5 -0
  26. package/dist/esm/sessions/getSession.js.map +1 -1
  27. package/dist/esm/sessions/getSessionTurns.d.ts +72 -0
  28. package/dist/esm/sessions/getSessionTurns.d.ts.map +1 -0
  29. package/dist/esm/sessions/getSessionTurns.js +127 -0
  30. package/dist/esm/sessions/getSessionTurns.js.map +1 -0
  31. package/dist/esm/sessions/index.d.ts +1 -0
  32. package/dist/esm/sessions/index.d.ts.map +1 -1
  33. package/dist/esm/sessions/index.js +1 -0
  34. package/dist/esm/sessions/index.js.map +1 -1
  35. package/dist/esm/sessions/listSessions.d.ts +2 -0
  36. package/dist/esm/sessions/listSessions.d.ts.map +1 -1
  37. package/dist/esm/sessions/listSessions.js +5 -0
  38. package/dist/esm/sessions/listSessions.js.map +1 -1
  39. package/dist/esm/sessions/logSessionAnnotations.d.ts +2 -0
  40. package/dist/esm/sessions/logSessionAnnotations.d.ts.map +1 -1
  41. package/dist/esm/sessions/logSessionAnnotations.js +5 -0
  42. package/dist/esm/sessions/logSessionAnnotations.js.map +1 -1
  43. package/dist/esm/spans/getSpans.d.ts +2 -0
  44. package/dist/esm/spans/getSpans.d.ts.map +1 -1
  45. package/dist/esm/spans/getSpans.js +7 -0
  46. package/dist/esm/spans/getSpans.js.map +1 -1
  47. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  48. package/dist/esm/types/semver.d.ts +3 -0
  49. package/dist/esm/types/semver.d.ts.map +1 -0
  50. package/dist/esm/types/semver.js +2 -0
  51. package/dist/esm/types/semver.js.map +1 -0
  52. package/dist/esm/types/serverRequirements.d.ts +39 -0
  53. package/dist/esm/types/serverRequirements.d.ts.map +1 -0
  54. package/dist/esm/types/serverRequirements.js +14 -0
  55. package/dist/esm/types/serverRequirements.js.map +1 -0
  56. package/dist/esm/utils/formatPromptMessages.d.ts.map +1 -1
  57. package/dist/esm/utils/getPromptBySelector.d.ts.map +1 -1
  58. package/dist/esm/utils/semverUtils.d.ts +21 -0
  59. package/dist/esm/utils/semverUtils.d.ts.map +1 -0
  60. package/dist/esm/utils/semverUtils.js +52 -0
  61. package/dist/esm/utils/semverUtils.js.map +1 -0
  62. package/dist/esm/utils/serverVersionUtils.d.ts +47 -0
  63. package/dist/esm/utils/serverVersionUtils.d.ts.map +1 -0
  64. package/dist/esm/utils/serverVersionUtils.js +64 -0
  65. package/dist/esm/utils/serverVersionUtils.js.map +1 -0
  66. package/dist/src/__generated__/api/v1.d.ts +149 -0
  67. package/dist/src/__generated__/api/v1.d.ts.map +1 -1
  68. package/dist/src/client.d.ts +16 -0
  69. package/dist/src/client.d.ts.map +1 -1
  70. package/dist/src/client.js +57 -2
  71. package/dist/src/client.js.map +1 -1
  72. package/dist/src/constants/serverRequirements.d.ts +28 -0
  73. package/dist/src/constants/serverRequirements.d.ts.map +1 -0
  74. package/dist/src/constants/serverRequirements.js +68 -0
  75. package/dist/src/constants/serverRequirements.js.map +1 -0
  76. package/dist/src/sessions/addSessionAnnotation.d.ts +2 -0
  77. package/dist/src/sessions/addSessionAnnotation.d.ts.map +1 -1
  78. package/dist/src/sessions/addSessionAnnotation.js +5 -0
  79. package/dist/src/sessions/addSessionAnnotation.js.map +1 -1
  80. package/dist/src/sessions/deleteSession.d.ts +2 -0
  81. package/dist/src/sessions/deleteSession.d.ts.map +1 -1
  82. package/dist/src/sessions/deleteSession.js +5 -0
  83. package/dist/src/sessions/deleteSession.js.map +1 -1
  84. package/dist/src/sessions/deleteSessions.d.ts +2 -0
  85. package/dist/src/sessions/deleteSessions.d.ts.map +1 -1
  86. package/dist/src/sessions/deleteSessions.js +5 -0
  87. package/dist/src/sessions/deleteSessions.js.map +1 -1
  88. package/dist/src/sessions/getSession.d.ts +2 -0
  89. package/dist/src/sessions/getSession.d.ts.map +1 -1
  90. package/dist/src/sessions/getSession.js +5 -0
  91. package/dist/src/sessions/getSession.js.map +1 -1
  92. package/dist/src/sessions/getSessionTurns.d.ts +72 -0
  93. package/dist/src/sessions/getSessionTurns.d.ts.map +1 -0
  94. package/dist/src/sessions/getSessionTurns.js +124 -0
  95. package/dist/src/sessions/getSessionTurns.js.map +1 -0
  96. package/dist/src/sessions/index.d.ts +1 -0
  97. package/dist/src/sessions/index.d.ts.map +1 -1
  98. package/dist/src/sessions/index.js +1 -0
  99. package/dist/src/sessions/index.js.map +1 -1
  100. package/dist/src/sessions/listSessions.d.ts +2 -0
  101. package/dist/src/sessions/listSessions.d.ts.map +1 -1
  102. package/dist/src/sessions/listSessions.js +5 -0
  103. package/dist/src/sessions/listSessions.js.map +1 -1
  104. package/dist/src/sessions/logSessionAnnotations.d.ts +2 -0
  105. package/dist/src/sessions/logSessionAnnotations.d.ts.map +1 -1
  106. package/dist/src/sessions/logSessionAnnotations.js +5 -0
  107. package/dist/src/sessions/logSessionAnnotations.js.map +1 -1
  108. package/dist/src/spans/getSpans.d.ts +2 -0
  109. package/dist/src/spans/getSpans.d.ts.map +1 -1
  110. package/dist/src/spans/getSpans.js +7 -0
  111. package/dist/src/spans/getSpans.js.map +1 -1
  112. package/dist/src/types/semver.d.ts +3 -0
  113. package/dist/src/types/semver.d.ts.map +1 -0
  114. package/dist/src/types/semver.js +3 -0
  115. package/dist/src/types/semver.js.map +1 -0
  116. package/dist/src/types/serverRequirements.d.ts +39 -0
  117. package/dist/src/types/serverRequirements.d.ts.map +1 -0
  118. package/dist/src/types/serverRequirements.js +15 -0
  119. package/dist/src/types/serverRequirements.js.map +1 -0
  120. package/dist/src/utils/formatPromptMessages.d.ts.map +1 -1
  121. package/dist/src/utils/getPromptBySelector.d.ts.map +1 -1
  122. package/dist/src/utils/semverUtils.d.ts +21 -0
  123. package/dist/src/utils/semverUtils.d.ts.map +1 -0
  124. package/dist/src/utils/semverUtils.js +57 -0
  125. package/dist/src/utils/semverUtils.js.map +1 -0
  126. package/dist/src/utils/serverVersionUtils.d.ts +47 -0
  127. package/dist/src/utils/serverVersionUtils.d.ts.map +1 -0
  128. package/dist/src/utils/serverVersionUtils.js +68 -0
  129. package/dist/src/utils/serverVersionUtils.js.map +1 -0
  130. package/dist/tsconfig.tsbuildinfo +1 -1
  131. package/package.json +1 -1
  132. package/src/__generated__/api/v1.ts +149 -0
  133. package/src/client.ts +61 -0
  134. package/src/constants/serverRequirements.ts +77 -0
  135. package/src/sessions/addSessionAnnotation.ts +5 -0
  136. package/src/sessions/deleteSession.ts +5 -0
  137. package/src/sessions/deleteSessions.ts +5 -0
  138. package/src/sessions/getSession.ts +5 -0
  139. package/src/sessions/getSessionTurns.ts +220 -0
  140. package/src/sessions/index.ts +1 -0
  141. package/src/sessions/listSessions.ts +5 -0
  142. package/src/sessions/logSessionAnnotations.ts +5 -0
  143. package/src/spans/getSpans.ts +7 -0
  144. package/src/types/semver.ts +2 -0
  145. package/src/types/serverRequirements.ts +42 -0
  146. package/src/utils/semverUtils.ts +66 -0
  147. package/src/utils/serverVersionUtils.ts +79 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arizeai/phoenix-client",
3
- "version": "6.3.0",
3
+ "version": "6.5.0",
4
4
  "description": "A client for the Phoenix API",
5
5
  "keywords": [
6
6
  "arize",
@@ -424,6 +424,23 @@ export interface paths {
424
424
  patch?: never;
425
425
  trace?: never;
426
426
  };
427
+ "/v1/projects/{project_identifier}/traces": {
428
+ parameters: {
429
+ query?: never;
430
+ header?: never;
431
+ path?: never;
432
+ cookie?: never;
433
+ };
434
+ /** List traces for a project */
435
+ get: operations["listProjectTraces"];
436
+ put?: never;
437
+ post?: never;
438
+ delete?: never;
439
+ options?: never;
440
+ head?: never;
441
+ patch?: never;
442
+ trace?: never;
443
+ };
427
444
  "/v1/trace_annotations": {
428
445
  parameters: {
429
446
  query?: never;
@@ -1562,6 +1579,13 @@ export interface components {
1562
1579
  /** Next Cursor */
1563
1580
  next_cursor: string | null;
1564
1581
  };
1582
+ /** GetTracesResponseBody */
1583
+ GetTracesResponseBody: {
1584
+ /** Data */
1585
+ data: components["schemas"]["TraceData"][];
1586
+ /** Next Cursor */
1587
+ next_cursor: string | null;
1588
+ };
1565
1589
  /** GetUsersResponseBody */
1566
1590
  GetUsersResponseBody: {
1567
1591
  /** Data */
@@ -3210,6 +3234,52 @@ export interface components {
3210
3234
  /** Next Cursor */
3211
3235
  next_cursor: string | null;
3212
3236
  };
3237
+ /** TraceData */
3238
+ TraceData: {
3239
+ /** Id */
3240
+ id: string;
3241
+ /** Trace Id */
3242
+ trace_id: string;
3243
+ /** Project Id */
3244
+ project_id: string;
3245
+ /**
3246
+ * Start Time
3247
+ * Format: date-time
3248
+ */
3249
+ start_time: string;
3250
+ /**
3251
+ * End Time
3252
+ * Format: date-time
3253
+ */
3254
+ end_time: string;
3255
+ /** Spans */
3256
+ spans?: components["schemas"]["TraceSpanData"][] | null;
3257
+ };
3258
+ /** TraceSpanData */
3259
+ TraceSpanData: {
3260
+ /** Id */
3261
+ id: string;
3262
+ /** Span Id */
3263
+ span_id: string;
3264
+ /** Parent Id */
3265
+ parent_id: string | null;
3266
+ /** Name */
3267
+ name: string;
3268
+ /** Span Kind */
3269
+ span_kind: string;
3270
+ /** Status Code */
3271
+ status_code: string;
3272
+ /**
3273
+ * Start Time
3274
+ * Format: date-time
3275
+ */
3276
+ start_time: string;
3277
+ /**
3278
+ * End Time
3279
+ * Format: date-time
3280
+ */
3281
+ end_time: string;
3282
+ };
3213
3283
  /** UpdateAnnotationConfigResponseBody */
3214
3284
  UpdateAnnotationConfigResponseBody: {
3215
3285
  /** Data */
@@ -3938,6 +4008,8 @@ export interface operations {
3938
4008
  "metadata_keys[]"?: string[];
3939
4009
  /** @description Column names for auto-assigning examples to splits */
3940
4010
  "split_keys[]"?: string[];
4011
+ /** @description Column names whose object values should be flattened into their selected bucket */
4012
+ "flatten_keys[]"?: string[];
3941
4013
  /** @description Column name for span IDs to link examples back to spans */
3942
4014
  span_id_key?: string;
3943
4015
  /** Format: binary */
@@ -4744,6 +4816,73 @@ export interface operations {
4744
4816
  };
4745
4817
  };
4746
4818
  };
4819
+ listProjectTraces: {
4820
+ parameters: {
4821
+ query?: {
4822
+ /** @description Inclusive lower bound on trace start time (ISO 8601) */
4823
+ start_time?: string | null;
4824
+ /** @description Exclusive upper bound on trace start time (ISO 8601) */
4825
+ end_time?: string | null;
4826
+ /** @description Sort field */
4827
+ sort?: "start_time" | "latency_ms";
4828
+ /** @description Sort direction */
4829
+ order?: "asc" | "desc";
4830
+ /** @description Maximum number of traces to return */
4831
+ limit?: number;
4832
+ /** @description Pagination cursor (Trace GlobalID) */
4833
+ cursor?: string | null;
4834
+ /** @description If true, include full span details for each trace. This significantly increases response size and query latency, especially with large page sizes. Prefer fetching spans lazily for individual traces when possible. */
4835
+ include_spans?: boolean;
4836
+ /** @description List of session identifiers to filter traces by. Each value can be either a session_id string or a session GlobalID. Only traces belonging to the specified sessions will be returned. */
4837
+ session_identifier?: string[] | null;
4838
+ };
4839
+ header?: never;
4840
+ path: {
4841
+ /** @description The project identifier: either project ID or project name. */
4842
+ project_identifier: string;
4843
+ };
4844
+ cookie?: never;
4845
+ };
4846
+ requestBody?: never;
4847
+ responses: {
4848
+ /** @description Successful Response */
4849
+ 200: {
4850
+ headers: {
4851
+ [name: string]: unknown;
4852
+ };
4853
+ content: {
4854
+ "application/json": components["schemas"]["GetTracesResponseBody"];
4855
+ };
4856
+ };
4857
+ /** @description Forbidden */
4858
+ 403: {
4859
+ headers: {
4860
+ [name: string]: unknown;
4861
+ };
4862
+ content: {
4863
+ "text/plain": string;
4864
+ };
4865
+ };
4866
+ /** @description Not Found */
4867
+ 404: {
4868
+ headers: {
4869
+ [name: string]: unknown;
4870
+ };
4871
+ content: {
4872
+ "text/plain": string;
4873
+ };
4874
+ };
4875
+ /** @description Unprocessable Entity */
4876
+ 422: {
4877
+ headers: {
4878
+ [name: string]: unknown;
4879
+ };
4880
+ content: {
4881
+ "text/plain": string;
4882
+ };
4883
+ };
4884
+ };
4885
+ };
4747
4886
  annotateTraces: {
4748
4887
  parameters: {
4749
4888
  query?: {
@@ -4861,6 +5000,10 @@ export interface operations {
4861
5000
  trace_id?: string[] | null;
4862
5001
  /** @description Filter by parent span ID. Use "null" to get root spans only. */
4863
5002
  parent_id?: string | null;
5003
+ /** @description Filter by span name(s) */
5004
+ name?: string[] | null;
5005
+ /** @description Filter by status code(s). Values: OK, ERROR, UNSET */
5006
+ status_code?: string[] | null;
4864
5007
  };
4865
5008
  header?: never;
4866
5009
  path: {
@@ -4924,6 +5067,12 @@ export interface operations {
4924
5067
  trace_id?: string[] | null;
4925
5068
  /** @description Filter by parent span ID. Use "null" to get root spans only. */
4926
5069
  parent_id?: string | null;
5070
+ /** @description Filter by span name(s) */
5071
+ name?: string[] | null;
5072
+ /** @description Filter by span kind(s). Values: LLM, CHAIN, TOOL, RETRIEVER, EMBEDDING, AGENT, RERANKER, GUARDRAIL, EVALUATOR, UNKNOWN */
5073
+ span_kind?: string[] | null;
5074
+ /** @description Filter by status code(s). Values: OK, ERROR, UNSET */
5075
+ status_code?: string[] | null;
4927
5076
  };
4928
5077
  header?: never;
4929
5078
  path: {
package/src/client.ts CHANGED
@@ -12,6 +12,13 @@ import {
12
12
  defaultGetEnvironmentOptions,
13
13
  makeDefaultClientOptions,
14
14
  } from "./config";
15
+ import type { SemanticVersion } from "./types/semver";
16
+ import { parseSemanticVersion } from "./utils/semverUtils";
17
+
18
+ /**
19
+ * The HTTP response header that carries the Phoenix server version string.
20
+ */
21
+ export const PHOENIX_SERVER_VERSION_HEADER = "x-phoenix-server-version";
15
22
 
16
23
  export type pathsV1 = oapiPathsV1;
17
24
  export type componentsV1 = oapiComponentsV1;
@@ -98,10 +105,64 @@ export const createClient = (
98
105
  ) => {
99
106
  const mergedOptions = getMergedOptions(config);
100
107
  const openApiClient = createOpenApiClient<pathsV1>(mergedOptions);
108
+
109
+ // Lazily populated by versionMiddleware from the x-phoenix-server-version
110
+ // response header on the first successful API call. Read via getServerVersion().
111
+ let serverVersion: SemanticVersion | null | undefined;
112
+
113
+ const versionMiddleware: Middleware = {
114
+ onResponse({ response }) {
115
+ if (serverVersion === undefined) {
116
+ const header = response.headers.get(PHOENIX_SERVER_VERSION_HEADER);
117
+ if (header) {
118
+ serverVersion = parseSemanticVersion(header);
119
+ }
120
+ }
121
+ },
122
+ };
123
+
124
+ openApiClient.use(versionMiddleware);
101
125
  openApiClient.use(middleware);
126
+
102
127
  return {
103
128
  ...openApiClient,
104
129
  config: mergedOptions,
130
+ /**
131
+ * Get the Phoenix server version, returning a cached value if available.
132
+ *
133
+ * The version is first populated from the `x-phoenix-server-version`
134
+ * response header on any API call. If no version has been seen yet,
135
+ * this method fetches `GET /arize_phoenix_version` to populate the cache.
136
+ *
137
+ * @throws {Error} If the server version cannot be determined (e.g. the
138
+ * server is unreachable or returned an unparseable version string).
139
+ */
140
+ getServerVersion: async (): Promise<SemanticVersion> => {
141
+ if (serverVersion != null) return serverVersion;
142
+ try {
143
+ const baseUrl = mergedOptions.baseUrl ?? "";
144
+ const headers = mergedOptions.headers
145
+ ? { ...(mergedOptions.headers as Record<string, string>) }
146
+ : {};
147
+ const resp = await fetch(`${baseUrl}/arize_phoenix_version`, {
148
+ headers,
149
+ });
150
+ if (resp.ok) {
151
+ const text = await resp.text();
152
+ const parsed = parseSemanticVersion(text);
153
+ if (parsed) {
154
+ serverVersion = parsed;
155
+ return serverVersion;
156
+ }
157
+ }
158
+ } catch {
159
+ // fall through to throw below
160
+ }
161
+ throw new Error(
162
+ "Phoenix server version could not be determined. " +
163
+ "Please ensure you are connecting to a supported Phoenix server."
164
+ );
165
+ },
105
166
  };
106
167
  };
107
168
 
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Known server capability requirements.
3
+ *
4
+ * Each constant below describes a single Phoenix server capability — an HTTP
5
+ * route or query parameter — together with the minimum server version that
6
+ * supports it. These constants are passed to
7
+ * {@link ensureServerCapability} at call time to produce a clear error when
8
+ * the connected server is too old.
9
+ *
10
+ * When a new version-gated capability is added to the Phoenix REST API, add a
11
+ * corresponding requirement constant here and reference it from the client
12
+ * function that uses it.
13
+ */
14
+
15
+ import type {
16
+ CapabilityRequirement,
17
+ ParameterRequirement,
18
+ RouteRequirement,
19
+ } from "../types/serverRequirements";
20
+
21
+ export const GET_SESSION: RouteRequirement = {
22
+ kind: "route",
23
+ method: "GET",
24
+ path: "/v1/sessions/{session_id}",
25
+ minServerVersion: [13, 5, 0],
26
+ };
27
+
28
+ export const DELETE_SESSION: RouteRequirement = {
29
+ kind: "route",
30
+ method: "DELETE",
31
+ path: "/v1/sessions/{session_id}",
32
+ minServerVersion: [13, 13, 0],
33
+ };
34
+
35
+ export const DELETE_SESSIONS: RouteRequirement = {
36
+ kind: "route",
37
+ method: "POST",
38
+ path: "/v1/sessions/delete",
39
+ minServerVersion: [13, 13, 0],
40
+ };
41
+
42
+ export const LIST_PROJECT_SESSIONS: RouteRequirement = {
43
+ kind: "route",
44
+ method: "GET",
45
+ path: "/v1/projects/{project_id}/sessions",
46
+ minServerVersion: [13, 5, 0],
47
+ };
48
+
49
+ export const ANNOTATE_SESSIONS: RouteRequirement = {
50
+ kind: "route",
51
+ method: "POST",
52
+ path: "/v1/session_annotations",
53
+ minServerVersion: [12, 0, 0],
54
+ };
55
+
56
+ export const GET_SPANS_TRACE_IDS: ParameterRequirement = {
57
+ kind: "parameter",
58
+ parameterName: "trace_id",
59
+ parameterLocation: "query",
60
+ route: "GET /v1/projects/{id}/spans",
61
+ minServerVersion: [13, 9, 0],
62
+ };
63
+
64
+ /**
65
+ * Aggregate list of every known capability requirement.
66
+ *
67
+ * Useful for manifest scanning or startup diagnostics — iterate over this
68
+ * array to check which capabilities the connected server supports.
69
+ */
70
+ export const ALL_REQUIREMENTS: readonly CapabilityRequirement[] = [
71
+ GET_SESSION,
72
+ DELETE_SESSION,
73
+ DELETE_SESSIONS,
74
+ LIST_PROJECT_SESSIONS,
75
+ ANNOTATE_SESSIONS,
76
+ GET_SPANS_TRACE_IDS,
77
+ ] as const;
@@ -1,5 +1,7 @@
1
1
  import { createClient } from "../client";
2
+ import { ANNOTATE_SESSIONS } from "../constants/serverRequirements";
2
3
  import type { ClientFn } from "../types/core";
4
+ import { ensureServerCapability } from "../utils/serverVersionUtils";
3
5
  import type { SessionAnnotation } from "./types";
4
6
  import { toSessionAnnotationData } from "./types";
5
7
 
@@ -25,6 +27,8 @@ export interface AddSessionAnnotationParams extends ClientFn {
25
27
  * @param params - The parameters to add a span annotation
26
28
  * @returns The ID of the created or updated annotation
27
29
  *
30
+ * @requires Phoenix server >= 12.0.0
31
+ *
28
32
  * @example
29
33
  * ```ts
30
34
  * const result = await addSessionAnnotation({
@@ -48,6 +52,7 @@ export async function addSessionAnnotation({
48
52
  sync = false,
49
53
  }: AddSessionAnnotationParams): Promise<{ id: string } | null> {
50
54
  const client = _client ?? createClient();
55
+ await ensureServerCapability({ client, requirement: ANNOTATE_SESSIONS });
51
56
 
52
57
  const { data, error } = await client.POST("/v1/session_annotations", {
53
58
  params: {
@@ -1,5 +1,7 @@
1
1
  import { createClient } from "../client";
2
+ import { DELETE_SESSION } from "../constants/serverRequirements";
2
3
  import type { ClientFn } from "../types/core";
4
+ import { ensureServerCapability } from "../utils/serverVersionUtils";
3
5
 
4
6
  /**
5
7
  * Parameters to delete a session
@@ -25,6 +27,8 @@ export interface DeleteSessionParams extends ClientFn {
25
27
  * @returns Promise that resolves when the session is successfully deleted
26
28
  * @throws Error if the session is not found or deletion fails
27
29
  *
30
+ * @requires Phoenix server >= 13.13.0
31
+ *
28
32
  * @example
29
33
  * ```ts
30
34
  * // Delete by user-provided session ID
@@ -45,6 +49,7 @@ export async function deleteSession({
45
49
  sessionId,
46
50
  }: DeleteSessionParams): Promise<void> {
47
51
  const client = _client ?? createClient();
52
+ await ensureServerCapability({ client, requirement: DELETE_SESSION });
48
53
 
49
54
  const { error } = await client.DELETE("/v1/sessions/{session_identifier}", {
50
55
  params: {
@@ -1,5 +1,7 @@
1
1
  import { createClient } from "../client";
2
+ import { DELETE_SESSIONS } from "../constants/serverRequirements";
2
3
  import type { ClientFn } from "../types/core";
4
+ import { ensureServerCapability } from "../utils/serverVersionUtils";
3
5
 
4
6
  /**
5
7
  * Parameters to bulk delete sessions
@@ -28,6 +30,8 @@ export interface DeleteSessionsParams extends ClientFn {
28
30
  * @returns Promise that resolves when the sessions are successfully deleted
29
31
  * @throws Error if identifiers are mixed types or deletion fails
30
32
  *
33
+ * @requires Phoenix server >= 13.13.0
34
+ *
31
35
  * @example
32
36
  * ```ts
33
37
  * // Delete by user-provided session IDs
@@ -48,6 +52,7 @@ export async function deleteSessions({
48
52
  sessionIds,
49
53
  }: DeleteSessionsParams): Promise<void> {
50
54
  const client = _client ?? createClient();
55
+ await ensureServerCapability({ client, requirement: DELETE_SESSIONS });
51
56
 
52
57
  const { error } = await client.POST("/v1/sessions/delete", {
53
58
  body: {
@@ -1,8 +1,10 @@
1
1
  import invariant from "tiny-invariant";
2
2
 
3
3
  import { createClient } from "../client";
4
+ import { GET_SESSION } from "../constants/serverRequirements";
4
5
  import type { ClientFn } from "../types/core";
5
6
  import type { Session } from "../types/sessions";
7
+ import { ensureServerCapability } from "../utils/serverVersionUtils";
6
8
  import { toSession } from "./sessionUtils";
7
9
 
8
10
  export type GetSessionParams = ClientFn & {
@@ -15,6 +17,8 @@ export type GetSessionParams = ClientFn & {
15
17
  /**
16
18
  * Fetch a single session by its GlobalID or user-provided session_id string.
17
19
  *
20
+ * @requires Phoenix server >= 13.5.0
21
+ *
18
22
  * @example
19
23
  * ```ts
20
24
  * import { getSession } from "@arizeai/phoenix-client/sessions";
@@ -28,6 +32,7 @@ export async function getSession({
28
32
  sessionId,
29
33
  }: GetSessionParams): Promise<Session> {
30
34
  const client = _client || createClient();
35
+ await ensureServerCapability({ client, requirement: GET_SESSION });
31
36
  const { data, error } = await client.GET(
32
37
  "/v1/sessions/{session_identifier}",
33
38
  {
@@ -0,0 +1,220 @@
1
+ import { SemanticConventions } from "@arizeai/openinference-semantic-conventions";
2
+
3
+ import type { components } from "../__generated__/api/v1";
4
+ import { createClient } from "../client";
5
+ import { getSpans } from "../spans/getSpans";
6
+ import type { ClientFn } from "../types/core";
7
+ import type { Session, SessionTrace } from "../types/sessions";
8
+ import { getSession } from "./getSession";
9
+
10
+ type Span = components["schemas"]["Span"];
11
+
12
+ const MAX_TRACE_IDS_PER_BATCH = 50;
13
+
14
+ /**
15
+ * Input or output extracted from a root span's attributes.
16
+ *
17
+ * @experimental this interface is experimental and may change in the future
18
+ */
19
+ export interface SessionTurnIO {
20
+ /** The string value of the input or output */
21
+ value: string;
22
+ /** Optional MIME type (e.g. "text/plain", "application/json") */
23
+ mimeType?: string;
24
+ }
25
+
26
+ /**
27
+ * A single turn in a session, representing one trace's root span input/output.
28
+ *
29
+ * **Note:** A "turn" is derived from a trace's root span. For input/output to appear,
30
+ * the root span must have `input.value` and `output.value` attributes set
31
+ * (per OpenInference semantic conventions). This typically requires instrumentation
32
+ * that records these attributes on the top-level span.
33
+ *
34
+ * @experimental this interface is experimental and may change in the future
35
+ */
36
+ export interface SessionTurn {
37
+ /** The trace ID for this turn */
38
+ traceId: string;
39
+ /** ISO 8601 timestamp of when the trace started */
40
+ startTime: string;
41
+ /** ISO 8601 timestamp of when the trace ended */
42
+ endTime: string;
43
+ /** Input extracted from the root span's attributes */
44
+ input?: SessionTurnIO;
45
+ /** Output extracted from the root span's attributes */
46
+ output?: SessionTurnIO;
47
+ /** The full root span, if found */
48
+ rootSpan?: Span;
49
+ }
50
+
51
+ /**
52
+ * @experimental this interface is experimental and may change in the future
53
+ */
54
+ export interface GetSessionTurnsParams extends ClientFn {
55
+ /** The session identifier: either a GlobalID or user-provided session_id string. */
56
+ sessionId: string;
57
+ }
58
+
59
+ /**
60
+ * Get the turns (root span I/O) for a session.
61
+ *
62
+ * Returns input/output extracted from root spans for each trace, along with
63
+ * the full root span. Turns are ordered by trace start_time.
64
+ *
65
+ * **Note:** A "turn" is derived from a trace's root span. For input/output to appear,
66
+ * the root span must have `input.value` and `output.value` attributes set
67
+ * (per OpenInference semantic conventions). This typically requires instrumentation
68
+ * that records these attributes on the top-level span.
69
+ *
70
+ * @experimental this function is experimental and may change in the future
71
+ *
72
+ * @example
73
+ * ```ts
74
+ * import { getSessionTurns } from "@arizeai/phoenix-client/sessions";
75
+ *
76
+ * const turns = await getSessionTurns({ sessionId: "my-session" });
77
+ * for (const turn of turns) {
78
+ * console.log(`[${turn.startTime}] Input: ${turn.input?.value}`);
79
+ * console.log(`[${turn.startTime}] Output: ${turn.output?.value}`);
80
+ * }
81
+ * ```
82
+ */
83
+ export async function getSessionTurns({
84
+ client: _client,
85
+ sessionId,
86
+ }: GetSessionTurnsParams): Promise<SessionTurn[]> {
87
+ const client = _client ?? createClient();
88
+
89
+ // getSession already calls ensureSessionsApi internally
90
+ const session: Session = await getSession({ client, sessionId });
91
+ const traces = session.traces;
92
+ if (traces.length === 0) {
93
+ return [];
94
+ }
95
+
96
+ const projectId = session.projectId;
97
+ const traceInfo = new Map<string, SessionTrace>(
98
+ traces.map((t) => [t.traceId, t])
99
+ );
100
+ const allTraceIds = [...traceInfo.keys()];
101
+
102
+ // Fetch root spans in batches
103
+ const rootSpansByTrace = new Map<string, Span>();
104
+ for (let i = 0; i < allTraceIds.length; i += MAX_TRACE_IDS_PER_BATCH) {
105
+ const traceIdBatch = allTraceIds.slice(i, i + MAX_TRACE_IDS_PER_BATCH);
106
+ const spans = await getAllRootSpansForBatch({
107
+ client,
108
+ projectId,
109
+ traceIdBatch,
110
+ });
111
+ for (const span of spans) {
112
+ const traceId = span.context.trace_id;
113
+ if (!rootSpansByTrace.has(traceId)) {
114
+ rootSpansByTrace.set(traceId, span);
115
+ }
116
+ }
117
+ }
118
+
119
+ return buildSessionTurns({ allTraceIds, traceInfo, rootSpansByTrace });
120
+ }
121
+
122
+ /**
123
+ * Fetch all root spans for a batch of trace IDs, handling pagination.
124
+ */
125
+ async function getAllRootSpansForBatch({
126
+ client,
127
+ projectId,
128
+ traceIdBatch,
129
+ }: {
130
+ client: ReturnType<typeof createClient>;
131
+ projectId: string;
132
+ traceIdBatch: string[];
133
+ }): Promise<Span[]> {
134
+ const allSpans: Span[] = [];
135
+ let cursor: string | null = null;
136
+
137
+ do {
138
+ const result = await getSpans({
139
+ client,
140
+ project: { projectId },
141
+ traceIds: traceIdBatch,
142
+ parentId: null,
143
+ limit: traceIdBatch.length,
144
+ ...(cursor ? { cursor } : {}),
145
+ });
146
+ allSpans.push(...result.spans);
147
+ cursor = result.nextCursor;
148
+ } while (cursor != null);
149
+
150
+ return allSpans;
151
+ }
152
+
153
+ /**
154
+ * Extract a SessionTurnIO from span attributes for a given prefix.
155
+ */
156
+ function extractIO({
157
+ attrs,
158
+ valueKey,
159
+ mimeTypeKey,
160
+ }: {
161
+ attrs: Record<string, unknown>;
162
+ valueKey: string;
163
+ mimeTypeKey: string;
164
+ }): SessionTurnIO | undefined {
165
+ const value = attrs[valueKey];
166
+ if (value == null) return undefined;
167
+ const io: SessionTurnIO = { value: String(value) };
168
+ const mimeType = attrs[mimeTypeKey];
169
+ if (mimeType != null) {
170
+ io.mimeType = String(mimeType);
171
+ }
172
+ return io;
173
+ }
174
+
175
+ /**
176
+ * Build session turns from trace info and root spans, ordered by start_time.
177
+ */
178
+ function buildSessionTurns({
179
+ allTraceIds,
180
+ traceInfo,
181
+ rootSpansByTrace,
182
+ }: {
183
+ allTraceIds: string[];
184
+ traceInfo: Map<string, SessionTrace>;
185
+ rootSpansByTrace: Map<string, Span>;
186
+ }): SessionTurn[] {
187
+ const turns: SessionTurn[] = [];
188
+
189
+ for (const traceId of allTraceIds) {
190
+ const info = traceInfo.get(traceId);
191
+ if (!info) continue;
192
+
193
+ const turn: SessionTurn = {
194
+ traceId,
195
+ startTime: info.startTime,
196
+ endTime: info.endTime,
197
+ };
198
+
199
+ const rootSpan = rootSpansByTrace.get(traceId);
200
+ if (rootSpan) {
201
+ turn.rootSpan = rootSpan;
202
+ const attrs = rootSpan.attributes ?? {};
203
+ turn.input = extractIO({
204
+ attrs,
205
+ valueKey: SemanticConventions.INPUT_VALUE,
206
+ mimeTypeKey: SemanticConventions.INPUT_MIME_TYPE,
207
+ });
208
+ turn.output = extractIO({
209
+ attrs,
210
+ valueKey: SemanticConventions.OUTPUT_VALUE,
211
+ mimeTypeKey: SemanticConventions.OUTPUT_MIME_TYPE,
212
+ });
213
+ }
214
+
215
+ turns.push(turn);
216
+ }
217
+
218
+ turns.sort((a, b) => a.startTime.localeCompare(b.startTime));
219
+ return turns;
220
+ }
@@ -2,5 +2,6 @@ export * from "./addSessionAnnotation";
2
2
  export * from "./deleteSession";
3
3
  export * from "./deleteSessions";
4
4
  export * from "./getSession";
5
+ export * from "./getSessionTurns";
5
6
  export * from "./listSessions";
6
7
  export * from "./logSessionAnnotations";