@arizeai/phoenix-client 6.4.0 → 6.5.1
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 +29 -0
- package/dist/esm/constants/serverRequirements.d.ts.map +1 -0
- package/dist/esm/constants/serverRequirements.js +73 -0
- package/dist/esm/constants/serverRequirements.js.map +1 -0
- package/dist/esm/prompts/sdks/toAI.d.ts.map +1 -1
- package/dist/esm/prompts/sdks/toAI.js +29 -6
- package/dist/esm/prompts/sdks/toAI.js.map +1 -1
- 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 +10 -1
- package/dist/esm/spans/getSpans.d.ts.map +1 -1
- package/dist/esm/spans/getSpans.js +20 -1
- package/dist/esm/spans/getSpans.js.map +1 -1
- package/dist/esm/spans/index.d.ts +1 -0
- package/dist/esm/spans/index.d.ts.map +1 -1
- package/dist/esm/spans/index.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/types/spans.d.ts +11 -0
- package/dist/esm/types/spans.d.ts.map +1 -0
- package/dist/esm/types/spans.js +2 -0
- package/dist/esm/types/spans.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 +29 -0
- package/dist/src/constants/serverRequirements.d.ts.map +1 -0
- package/dist/src/constants/serverRequirements.js +76 -0
- package/dist/src/constants/serverRequirements.js.map +1 -0
- package/dist/src/prompts/sdks/toAI.d.ts.map +1 -1
- package/dist/src/prompts/sdks/toAI.js +28 -7
- package/dist/src/prompts/sdks/toAI.js.map +1 -1
- 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 +10 -1
- package/dist/src/spans/getSpans.d.ts.map +1 -1
- package/dist/src/spans/getSpans.js +20 -1
- package/dist/src/spans/getSpans.js.map +1 -1
- package/dist/src/spans/index.d.ts +1 -0
- package/dist/src/spans/index.d.ts.map +1 -1
- package/dist/src/spans/index.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/types/spans.d.ts +11 -0
- package/dist/src/types/spans.d.ts.map +1 -0
- package/dist/src/types/spans.js +3 -0
- package/dist/src/types/spans.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 +86 -0
- package/src/prompts/sdks/toAI.ts +34 -8
- 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 +35 -0
- package/src/spans/index.ts +1 -0
- package/src/types/semver.ts +2 -0
- package/src/types/serverRequirements.ts +42 -0
- package/src/types/spans.ts +12 -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,86 @@
|
|
|
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
|
+
export const GET_SPANS_FILTERS: ParameterRequirement = {
|
|
65
|
+
kind: "parameter",
|
|
66
|
+
parameterName: "span_kind",
|
|
67
|
+
parameterLocation: "query",
|
|
68
|
+
route: "GET /v1/projects/{id}/spans",
|
|
69
|
+
minServerVersion: [13, 15, 0],
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Aggregate list of every known capability requirement.
|
|
74
|
+
*
|
|
75
|
+
* Useful for manifest scanning or startup diagnostics — iterate over this
|
|
76
|
+
* array to check which capabilities the connected server supports.
|
|
77
|
+
*/
|
|
78
|
+
export const ALL_REQUIREMENTS: readonly CapabilityRequirement[] = [
|
|
79
|
+
GET_SESSION,
|
|
80
|
+
DELETE_SESSION,
|
|
81
|
+
DELETE_SESSIONS,
|
|
82
|
+
LIST_PROJECT_SESSIONS,
|
|
83
|
+
ANNOTATE_SESSIONS,
|
|
84
|
+
GET_SPANS_TRACE_IDS,
|
|
85
|
+
GET_SPANS_FILTERS,
|
|
86
|
+
] as const;
|
package/src/prompts/sdks/toAI.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import type { ModelMessage, ToolChoice, ToolSet } from "ai";
|
|
2
2
|
import invariant from "tiny-invariant";
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
safelyConvertMessageToProvider,
|
|
6
|
+
safelyConvertToolChoiceToProvider,
|
|
7
|
+
safelyConvertToolDefinitionToProvider,
|
|
8
|
+
} from "../../schemas/llm/converters";
|
|
9
|
+
import { findToolDefinitionName } from "../../schemas/llm/utils";
|
|
5
10
|
import { formatPromptMessages } from "../../utils/formatPromptMessages";
|
|
6
11
|
import type { Variables, toSDKParamsBase } from "./types";
|
|
7
12
|
|
|
@@ -62,19 +67,40 @@ export const toAI = <V extends Variables>({
|
|
|
62
67
|
return vercelAIMessage;
|
|
63
68
|
});
|
|
64
69
|
|
|
65
|
-
|
|
66
|
-
if (prompt.tools?.tools && prompt.tools
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
let tools: ToolSet | undefined;
|
|
71
|
+
if (prompt.tools?.tools && prompt.tools.tools.length > 0) {
|
|
72
|
+
const toolsRecord: Record<string, unknown> = {};
|
|
73
|
+
for (const tool of prompt.tools.tools) {
|
|
74
|
+
const name = findToolDefinitionName(tool);
|
|
75
|
+
invariant(name, "Tool definition name is not valid");
|
|
76
|
+
const converted = safelyConvertToolDefinitionToProvider({
|
|
77
|
+
toolDefinition: tool,
|
|
78
|
+
targetProvider: "VERCEL_AI",
|
|
79
|
+
});
|
|
80
|
+
invariant(converted, "Tool definition is not valid");
|
|
81
|
+
toolsRecord[name] = converted;
|
|
82
|
+
}
|
|
83
|
+
tools =
|
|
84
|
+
Object.keys(toolsRecord).length > 0
|
|
85
|
+
? (toolsRecord as ToolSet)
|
|
86
|
+
: undefined;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
let toolChoice: PartialAIParams["toolChoice"];
|
|
90
|
+
if (tools && prompt.tools?.tool_choice) {
|
|
91
|
+
toolChoice =
|
|
92
|
+
safelyConvertToolChoiceToProvider({
|
|
93
|
+
toolChoice: prompt.tools.tool_choice,
|
|
94
|
+
targetProvider: "VERCEL_AI",
|
|
95
|
+
}) ?? undefined;
|
|
71
96
|
}
|
|
72
97
|
|
|
73
98
|
// combine base and computed params
|
|
74
99
|
const completionParams: PartialAIParams = {
|
|
75
100
|
...baseCompletionParams,
|
|
76
101
|
messages,
|
|
77
|
-
tools,
|
|
102
|
+
...(tools !== undefined && { tools }),
|
|
103
|
+
...(toolChoice !== undefined && { toolChoice }),
|
|
78
104
|
};
|
|
79
105
|
|
|
80
106
|
return completionParams;
|
|
@@ -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,14 @@
|
|
|
1
1
|
import type { operations } from "../__generated__/api/v1";
|
|
2
2
|
import { createClient } from "../client";
|
|
3
|
+
import {
|
|
4
|
+
GET_SPANS_FILTERS,
|
|
5
|
+
GET_SPANS_TRACE_IDS,
|
|
6
|
+
} from "../constants/serverRequirements";
|
|
3
7
|
import type { ClientFn } from "../types/core";
|
|
4
8
|
import type { ProjectIdentifier } from "../types/projects";
|
|
5
9
|
import { resolveProjectIdentifier } from "../types/projects";
|
|
10
|
+
import type { SpanKindFilter, SpanStatusCode } from "../types/spans";
|
|
11
|
+
import { ensureServerCapability } from "../utils/serverVersionUtils";
|
|
6
12
|
|
|
7
13
|
/**
|
|
8
14
|
* Parameters to get spans from a project using auto-generated types
|
|
@@ -22,6 +28,12 @@ export interface GetSpansParams extends ClientFn {
|
|
|
22
28
|
traceIds?: string[] | null;
|
|
23
29
|
/** Filter by parent span ID. Use `null` or the string `"null"` to get root spans only. */
|
|
24
30
|
parentId?: string | null;
|
|
31
|
+
/** Filter by span name(s) */
|
|
32
|
+
name?: string | string[] | null;
|
|
33
|
+
/** Filter by span kind(s) (LLM, CHAIN, TOOL, RETRIEVER, etc.) */
|
|
34
|
+
spanKind?: SpanKindFilter | SpanKindFilter[] | null;
|
|
35
|
+
/** Filter by status code(s) (OK, ERROR, UNSET) */
|
|
36
|
+
statusCode?: SpanStatusCode | SpanStatusCode[] | null;
|
|
25
37
|
}
|
|
26
38
|
|
|
27
39
|
export type GetSpansResponse = operations["getSpans"]["responses"]["200"];
|
|
@@ -44,6 +56,8 @@ export type GetSpansResult = {
|
|
|
44
56
|
* @param params - The parameters to search for spans
|
|
45
57
|
* @returns A paginated response containing spans and optional next cursor
|
|
46
58
|
*
|
|
59
|
+
* @requires Phoenix server >= 13.9.0 when filtering by `traceIds`
|
|
60
|
+
*
|
|
47
61
|
* @example
|
|
48
62
|
* ```ts
|
|
49
63
|
* // Get recent spans from a project
|
|
@@ -99,8 +113,17 @@ export async function getSpans({
|
|
|
99
113
|
endTime,
|
|
100
114
|
traceIds,
|
|
101
115
|
parentId,
|
|
116
|
+
name,
|
|
117
|
+
spanKind,
|
|
118
|
+
statusCode,
|
|
102
119
|
}: GetSpansParams): Promise<GetSpansResult> {
|
|
103
120
|
const client = _client ?? createClient();
|
|
121
|
+
if (traceIds) {
|
|
122
|
+
await ensureServerCapability({ client, requirement: GET_SPANS_TRACE_IDS });
|
|
123
|
+
}
|
|
124
|
+
if (name != null || spanKind != null || statusCode != null) {
|
|
125
|
+
await ensureServerCapability({ client, requirement: GET_SPANS_FILTERS });
|
|
126
|
+
}
|
|
104
127
|
const projectIdentifier = resolveProjectIdentifier(project);
|
|
105
128
|
|
|
106
129
|
const params: NonNullable<operations["getSpans"]["parameters"]["query"]> = {
|
|
@@ -128,6 +151,18 @@ export async function getSpans({
|
|
|
128
151
|
params.parent_id = parentId === null ? "null" : parentId;
|
|
129
152
|
}
|
|
130
153
|
|
|
154
|
+
if (name) {
|
|
155
|
+
params.name = Array.isArray(name) ? name : [name];
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (spanKind) {
|
|
159
|
+
params.span_kind = Array.isArray(spanKind) ? spanKind : [spanKind];
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (statusCode) {
|
|
163
|
+
params.status_code = Array.isArray(statusCode) ? statusCode : [statusCode];
|
|
164
|
+
}
|
|
165
|
+
|
|
131
166
|
const { data, error } = await client.GET(
|
|
132
167
|
"/v1/projects/{project_identifier}/spans",
|
|
133
168
|
{
|
package/src/spans/index.ts
CHANGED
|
@@ -4,5 +4,6 @@ export * from "./logSpanAnnotations";
|
|
|
4
4
|
export * from "./addDocumentAnnotation";
|
|
5
5
|
export * from "./logDocumentAnnotations";
|
|
6
6
|
export * from "./getSpans";
|
|
7
|
+
export type { SpanKindFilter, SpanStatusCode } from "../types/spans";
|
|
7
8
|
export * from "./getSpanAnnotations";
|
|
8
9
|
export * from "./deleteSpan";
|