@arizeai/phoenix-client 6.4.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.
- package/dist/esm/__generated__/api/v1.d.ts +149 -0
- package/dist/esm/__generated__/api/v1.d.ts.map +1 -1
- package/dist/esm/client.d.ts +16 -0
- package/dist/esm/client.d.ts.map +1 -1
- package/dist/esm/client.js +55 -0
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/constants/serverRequirements.d.ts +28 -0
- package/dist/esm/constants/serverRequirements.d.ts.map +1 -0
- package/dist/esm/constants/serverRequirements.js +65 -0
- package/dist/esm/constants/serverRequirements.js.map +1 -0
- package/dist/esm/sessions/addSessionAnnotation.d.ts +2 -0
- package/dist/esm/sessions/addSessionAnnotation.d.ts.map +1 -1
- package/dist/esm/sessions/addSessionAnnotation.js +5 -0
- package/dist/esm/sessions/addSessionAnnotation.js.map +1 -1
- package/dist/esm/sessions/deleteSession.d.ts +2 -0
- package/dist/esm/sessions/deleteSession.d.ts.map +1 -1
- package/dist/esm/sessions/deleteSession.js +5 -0
- package/dist/esm/sessions/deleteSession.js.map +1 -1
- package/dist/esm/sessions/deleteSessions.d.ts +2 -0
- package/dist/esm/sessions/deleteSessions.d.ts.map +1 -1
- package/dist/esm/sessions/deleteSessions.js +5 -0
- package/dist/esm/sessions/deleteSessions.js.map +1 -1
- package/dist/esm/sessions/getSession.d.ts +2 -0
- package/dist/esm/sessions/getSession.d.ts.map +1 -1
- package/dist/esm/sessions/getSession.js +5 -0
- package/dist/esm/sessions/getSession.js.map +1 -1
- package/dist/esm/sessions/getSessionTurns.d.ts.map +1 -1
- package/dist/esm/sessions/getSessionTurns.js +1 -0
- package/dist/esm/sessions/getSessionTurns.js.map +1 -1
- package/dist/esm/sessions/listSessions.d.ts +2 -0
- package/dist/esm/sessions/listSessions.d.ts.map +1 -1
- package/dist/esm/sessions/listSessions.js +5 -0
- package/dist/esm/sessions/listSessions.js.map +1 -1
- package/dist/esm/sessions/logSessionAnnotations.d.ts +2 -0
- package/dist/esm/sessions/logSessionAnnotations.d.ts.map +1 -1
- package/dist/esm/sessions/logSessionAnnotations.js +5 -0
- package/dist/esm/sessions/logSessionAnnotations.js.map +1 -1
- package/dist/esm/spans/getSpans.d.ts +2 -0
- package/dist/esm/spans/getSpans.d.ts.map +1 -1
- package/dist/esm/spans/getSpans.js +7 -0
- package/dist/esm/spans/getSpans.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/esm/types/semver.d.ts +3 -0
- package/dist/esm/types/semver.d.ts.map +1 -0
- package/dist/esm/types/semver.js +2 -0
- package/dist/esm/types/semver.js.map +1 -0
- package/dist/esm/types/serverRequirements.d.ts +39 -0
- package/dist/esm/types/serverRequirements.d.ts.map +1 -0
- package/dist/esm/types/serverRequirements.js +14 -0
- package/dist/esm/types/serverRequirements.js.map +1 -0
- package/dist/esm/utils/formatPromptMessages.d.ts.map +1 -1
- package/dist/esm/utils/getPromptBySelector.d.ts.map +1 -1
- package/dist/esm/utils/semverUtils.d.ts +21 -0
- package/dist/esm/utils/semverUtils.d.ts.map +1 -0
- package/dist/esm/utils/semverUtils.js +52 -0
- package/dist/esm/utils/semverUtils.js.map +1 -0
- package/dist/esm/utils/serverVersionUtils.d.ts +47 -0
- package/dist/esm/utils/serverVersionUtils.d.ts.map +1 -0
- package/dist/esm/utils/serverVersionUtils.js +64 -0
- package/dist/esm/utils/serverVersionUtils.js.map +1 -0
- package/dist/src/__generated__/api/v1.d.ts +149 -0
- package/dist/src/__generated__/api/v1.d.ts.map +1 -1
- package/dist/src/client.d.ts +16 -0
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/client.js +57 -2
- package/dist/src/client.js.map +1 -1
- package/dist/src/constants/serverRequirements.d.ts +28 -0
- package/dist/src/constants/serverRequirements.d.ts.map +1 -0
- package/dist/src/constants/serverRequirements.js +68 -0
- package/dist/src/constants/serverRequirements.js.map +1 -0
- package/dist/src/sessions/addSessionAnnotation.d.ts +2 -0
- package/dist/src/sessions/addSessionAnnotation.d.ts.map +1 -1
- package/dist/src/sessions/addSessionAnnotation.js +5 -0
- package/dist/src/sessions/addSessionAnnotation.js.map +1 -1
- package/dist/src/sessions/deleteSession.d.ts +2 -0
- package/dist/src/sessions/deleteSession.d.ts.map +1 -1
- package/dist/src/sessions/deleteSession.js +5 -0
- package/dist/src/sessions/deleteSession.js.map +1 -1
- package/dist/src/sessions/deleteSessions.d.ts +2 -0
- package/dist/src/sessions/deleteSessions.d.ts.map +1 -1
- package/dist/src/sessions/deleteSessions.js +5 -0
- package/dist/src/sessions/deleteSessions.js.map +1 -1
- package/dist/src/sessions/getSession.d.ts +2 -0
- package/dist/src/sessions/getSession.d.ts.map +1 -1
- package/dist/src/sessions/getSession.js +5 -0
- package/dist/src/sessions/getSession.js.map +1 -1
- package/dist/src/sessions/getSessionTurns.d.ts.map +1 -1
- package/dist/src/sessions/getSessionTurns.js +1 -0
- package/dist/src/sessions/getSessionTurns.js.map +1 -1
- package/dist/src/sessions/listSessions.d.ts +2 -0
- package/dist/src/sessions/listSessions.d.ts.map +1 -1
- package/dist/src/sessions/listSessions.js +5 -0
- package/dist/src/sessions/listSessions.js.map +1 -1
- package/dist/src/sessions/logSessionAnnotations.d.ts +2 -0
- package/dist/src/sessions/logSessionAnnotations.d.ts.map +1 -1
- package/dist/src/sessions/logSessionAnnotations.js +5 -0
- package/dist/src/sessions/logSessionAnnotations.js.map +1 -1
- package/dist/src/spans/getSpans.d.ts +2 -0
- package/dist/src/spans/getSpans.d.ts.map +1 -1
- package/dist/src/spans/getSpans.js +7 -0
- package/dist/src/spans/getSpans.js.map +1 -1
- package/dist/src/types/semver.d.ts +3 -0
- package/dist/src/types/semver.d.ts.map +1 -0
- package/dist/src/types/semver.js +3 -0
- package/dist/src/types/semver.js.map +1 -0
- package/dist/src/types/serverRequirements.d.ts +39 -0
- package/dist/src/types/serverRequirements.d.ts.map +1 -0
- package/dist/src/types/serverRequirements.js +15 -0
- package/dist/src/types/serverRequirements.js.map +1 -0
- package/dist/src/utils/formatPromptMessages.d.ts.map +1 -1
- package/dist/src/utils/getPromptBySelector.d.ts.map +1 -1
- package/dist/src/utils/semverUtils.d.ts +21 -0
- package/dist/src/utils/semverUtils.d.ts.map +1 -0
- package/dist/src/utils/semverUtils.js +57 -0
- package/dist/src/utils/semverUtils.js.map +1 -0
- package/dist/src/utils/serverVersionUtils.d.ts +47 -0
- package/dist/src/utils/serverVersionUtils.d.ts.map +1 -0
- package/dist/src/utils/serverVersionUtils.js +68 -0
- package/dist/src/utils/serverVersionUtils.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/__generated__/api/v1.ts +149 -0
- package/src/client.ts +61 -0
- package/src/constants/serverRequirements.ts +77 -0
- package/src/sessions/addSessionAnnotation.ts +5 -0
- package/src/sessions/deleteSession.ts +5 -0
- package/src/sessions/deleteSessions.ts +5 -0
- package/src/sessions/getSession.ts +5 -0
- package/src/sessions/getSessionTurns.ts +1 -0
- package/src/sessions/listSessions.ts +5 -0
- package/src/sessions/logSessionAnnotations.ts +5 -0
- package/src/spans/getSpans.ts +7 -0
- package/src/types/semver.ts +2 -0
- package/src/types/serverRequirements.ts +42 -0
- package/src/utils/semverUtils.ts +66 -0
- package/src/utils/serverVersionUtils.ts +79 -0
package/package.json
CHANGED
|
@@ -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
|
{
|
|
@@ -86,6 +86,7 @@ export async function getSessionTurns({
|
|
|
86
86
|
}: GetSessionTurnsParams): Promise<SessionTurn[]> {
|
|
87
87
|
const client = _client ?? createClient();
|
|
88
88
|
|
|
89
|
+
// getSession already calls ensureSessionsApi internally
|
|
89
90
|
const session: Session = await getSession({ client, sessionId });
|
|
90
91
|
const traces = session.traces;
|
|
91
92
|
if (traces.length === 0) {
|
|
@@ -2,10 +2,12 @@ import invariant from "tiny-invariant";
|
|
|
2
2
|
|
|
3
3
|
import type { components } from "../__generated__/api/v1";
|
|
4
4
|
import { createClient } from "../client";
|
|
5
|
+
import { LIST_PROJECT_SESSIONS } from "../constants/serverRequirements";
|
|
5
6
|
import type { ClientFn } from "../types/core";
|
|
6
7
|
import type { ProjectIdentifier } from "../types/projects";
|
|
7
8
|
import { resolveProjectIdentifier } from "../types/projects";
|
|
8
9
|
import type { Session } from "../types/sessions";
|
|
10
|
+
import { ensureServerCapability } from "../utils/serverVersionUtils";
|
|
9
11
|
import { toSession } from "./sessionUtils";
|
|
10
12
|
|
|
11
13
|
export type ListSessionsParams = ClientFn & ProjectIdentifier;
|
|
@@ -17,6 +19,8 @@ const DEFAULT_PAGE_SIZE = 100;
|
|
|
17
19
|
/**
|
|
18
20
|
* List all sessions for a project with automatic pagination handling.
|
|
19
21
|
*
|
|
22
|
+
* @requires Phoenix server >= 13.5.0
|
|
23
|
+
*
|
|
20
24
|
* @example
|
|
21
25
|
* ```ts
|
|
22
26
|
* import { listSessions } from "@arizeai/phoenix-client/sessions";
|
|
@@ -34,6 +38,7 @@ export async function listSessions(
|
|
|
34
38
|
params: ListSessionsParams
|
|
35
39
|
): Promise<Session[]> {
|
|
36
40
|
const client = params.client || createClient();
|
|
41
|
+
await ensureServerCapability({ client, requirement: LIST_PROJECT_SESSIONS });
|
|
37
42
|
const projectIdentifier = resolveProjectIdentifier(params);
|
|
38
43
|
|
|
39
44
|
const sessions: Session[] = [];
|
|
@@ -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
|
|
|
@@ -28,6 +30,8 @@ export interface LogSessionAnnotationsParams extends ClientFn {
|
|
|
28
30
|
* @param params - The parameters to log session annotations
|
|
29
31
|
* @returns The IDs of the created or updated annotations
|
|
30
32
|
*
|
|
33
|
+
* @requires Phoenix server >= 12.0.0
|
|
34
|
+
*
|
|
31
35
|
* @example
|
|
32
36
|
* ```ts
|
|
33
37
|
* const results = await logSessionAnnotations({
|
|
@@ -60,6 +64,7 @@ export async function logSessionAnnotations({
|
|
|
60
64
|
sync = false,
|
|
61
65
|
}: LogSessionAnnotationsParams): Promise<{ id: string }[]> {
|
|
62
66
|
const client = _client ?? createClient();
|
|
67
|
+
await ensureServerCapability({ client, requirement: ANNOTATE_SESSIONS });
|
|
63
68
|
|
|
64
69
|
const { data, error } = await client.POST("/v1/session_annotations", {
|
|
65
70
|
params: {
|
package/src/spans/getSpans.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { operations } from "../__generated__/api/v1";
|
|
2
2
|
import { createClient } from "../client";
|
|
3
|
+
import { GET_SPANS_TRACE_IDS } from "../constants/serverRequirements";
|
|
3
4
|
import type { ClientFn } from "../types/core";
|
|
4
5
|
import type { ProjectIdentifier } from "../types/projects";
|
|
5
6
|
import { resolveProjectIdentifier } from "../types/projects";
|
|
7
|
+
import { ensureServerCapability } from "../utils/serverVersionUtils";
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* Parameters to get spans from a project using auto-generated types
|
|
@@ -44,6 +46,8 @@ export type GetSpansResult = {
|
|
|
44
46
|
* @param params - The parameters to search for spans
|
|
45
47
|
* @returns A paginated response containing spans and optional next cursor
|
|
46
48
|
*
|
|
49
|
+
* @requires Phoenix server >= 13.9.0 when filtering by `traceIds`
|
|
50
|
+
*
|
|
47
51
|
* @example
|
|
48
52
|
* ```ts
|
|
49
53
|
* // Get recent spans from a project
|
|
@@ -101,6 +105,9 @@ export async function getSpans({
|
|
|
101
105
|
parentId,
|
|
102
106
|
}: GetSpansParams): Promise<GetSpansResult> {
|
|
103
107
|
const client = _client ?? createClient();
|
|
108
|
+
if (traceIds) {
|
|
109
|
+
await ensureServerCapability({ client, requirement: GET_SPANS_TRACE_IDS });
|
|
110
|
+
}
|
|
104
111
|
const projectIdentifier = resolveProjectIdentifier(project);
|
|
105
112
|
|
|
106
113
|
const params: NonNullable<operations["getSpans"]["parameters"]["query"]> = {
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server capability requirements.
|
|
3
|
+
*
|
|
4
|
+
* A "capability" represents a specific server-side feature — such as an HTTP
|
|
5
|
+
* route or query parameter — that is gated behind a minimum Phoenix server
|
|
6
|
+
* version. Each {@link CapabilityRequirement} declares *what* the capability
|
|
7
|
+
* is and *which* server version first introduced it.
|
|
8
|
+
*
|
|
9
|
+
* The client checks these requirements at call time via
|
|
10
|
+
* {@link ensureServerCapability} so that callers get a clear, actionable error
|
|
11
|
+
* instead of an opaque 404 or 400 from an older server.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { SemanticVersion } from "./semver";
|
|
15
|
+
|
|
16
|
+
export interface RouteRequirement {
|
|
17
|
+
kind: "route";
|
|
18
|
+
/** HTTP method (e.g. "GET", "POST", "DELETE"). */
|
|
19
|
+
method: string;
|
|
20
|
+
/** URL path template (e.g. "/v1/sessions/{session_id}"). */
|
|
21
|
+
path: string;
|
|
22
|
+
/** Minimum Phoenix server version as [major, minor, patch]. */
|
|
23
|
+
minServerVersion: SemanticVersion;
|
|
24
|
+
/** Optional human-readable description override. */
|
|
25
|
+
description?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface ParameterRequirement {
|
|
29
|
+
kind: "parameter";
|
|
30
|
+
/** Name of the query/path/header parameter. */
|
|
31
|
+
parameterName: string;
|
|
32
|
+
/** Location of the parameter (e.g. "query", "path", "header"). */
|
|
33
|
+
parameterLocation: string;
|
|
34
|
+
/** The route this parameter belongs to (e.g. "GET /v1/projects/{id}/spans"). */
|
|
35
|
+
route: string;
|
|
36
|
+
/** Minimum Phoenix server version as [major, minor, patch]. */
|
|
37
|
+
minServerVersion: SemanticVersion;
|
|
38
|
+
/** Optional human-readable description override. */
|
|
39
|
+
description?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type CapabilityRequirement = RouteRequirement | ParameterRequirement;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lightweight semantic version utilities.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { SemanticVersion } from "../types/semver";
|
|
6
|
+
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
// Parsing
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Parse a semver-like version string (e.g. "13.14.0") into a triple.
|
|
13
|
+
* Returns `null` if the string is not a valid version.
|
|
14
|
+
*/
|
|
15
|
+
export function parseSemanticVersion(raw: string): SemanticVersion | null {
|
|
16
|
+
const parts = raw.trim().split(".");
|
|
17
|
+
if (parts.length < 3) return null;
|
|
18
|
+
const major = parseInt(parts[0]!, 10);
|
|
19
|
+
const minor = parseInt(parts[1]!, 10);
|
|
20
|
+
const patch = parseInt(parts[2]!, 10);
|
|
21
|
+
if (
|
|
22
|
+
Number.isNaN(major) ||
|
|
23
|
+
Number.isNaN(minor) ||
|
|
24
|
+
Number.isNaN(patch) ||
|
|
25
|
+
major < 0 ||
|
|
26
|
+
minor < 0 ||
|
|
27
|
+
patch < 0
|
|
28
|
+
) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
return [major, minor, patch];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
// Formatting
|
|
36
|
+
// ---------------------------------------------------------------------------
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Format a `SemanticVersion` as a `"major.minor.patch"` string.
|
|
40
|
+
*/
|
|
41
|
+
export function formatVersion(version: SemanticVersion): string {
|
|
42
|
+
return `${version[0]}.${version[1]}.${version[2]}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// ---------------------------------------------------------------------------
|
|
46
|
+
// Comparison
|
|
47
|
+
// ---------------------------------------------------------------------------
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Returns `true` if `version` is greater than or equal to `minVersion`.
|
|
51
|
+
*/
|
|
52
|
+
export function satisfiesMinVersion({
|
|
53
|
+
version,
|
|
54
|
+
minVersion,
|
|
55
|
+
}: {
|
|
56
|
+
version: SemanticVersion;
|
|
57
|
+
minVersion: SemanticVersion;
|
|
58
|
+
}): boolean {
|
|
59
|
+
const [serverVersionMajor, serverVersionMinor, serverVersionPatch] = version;
|
|
60
|
+
const [minVersionMajor, minVersionMinor, minVersionPatch] = minVersion;
|
|
61
|
+
if (serverVersionMajor !== minVersionMajor)
|
|
62
|
+
return serverVersionMajor > minVersionMajor;
|
|
63
|
+
if (serverVersionMinor !== minVersionMinor)
|
|
64
|
+
return serverVersionMinor > minVersionMinor;
|
|
65
|
+
return serverVersionPatch >= minVersionPatch;
|
|
66
|
+
}
|