@arizeai/phoenix-client 6.0.0 → 6.1.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 (75) hide show
  1. package/dist/esm/sessions/getSession.d.ts +21 -0
  2. package/dist/esm/sessions/getSession.d.ts.map +1 -0
  3. package/dist/esm/sessions/getSession.js +29 -0
  4. package/dist/esm/sessions/getSession.js.map +1 -0
  5. package/dist/esm/sessions/index.d.ts +2 -0
  6. package/dist/esm/sessions/index.d.ts.map +1 -1
  7. package/dist/esm/sessions/index.js +2 -0
  8. package/dist/esm/sessions/index.js.map +1 -1
  9. package/dist/esm/sessions/listSessions.d.ts +22 -0
  10. package/dist/esm/sessions/listSessions.d.ts.map +1 -0
  11. package/dist/esm/sessions/listSessions.js +47 -0
  12. package/dist/esm/sessions/listSessions.js.map +1 -0
  13. package/dist/esm/sessions/sessionUtils.d.ts +9 -0
  14. package/dist/esm/sessions/sessionUtils.d.ts.map +1 -0
  15. package/dist/esm/sessions/sessionUtils.js +19 -0
  16. package/dist/esm/sessions/sessionUtils.js.map +1 -0
  17. package/dist/esm/spans/getSpanAnnotations.d.ts +2 -2
  18. package/dist/esm/spans/getSpanAnnotations.d.ts.map +1 -1
  19. package/dist/esm/spans/getSpanAnnotations.js +2 -1
  20. package/dist/esm/spans/getSpanAnnotations.js.map +1 -1
  21. package/dist/esm/spans/getSpans.d.ts +2 -2
  22. package/dist/esm/spans/getSpans.d.ts.map +1 -1
  23. package/dist/esm/spans/getSpans.js +2 -1
  24. package/dist/esm/spans/getSpans.js.map +1 -1
  25. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  26. package/dist/esm/types/projects.d.ts +12 -3
  27. package/dist/esm/types/projects.d.ts.map +1 -1
  28. package/dist/esm/types/projects.js +11 -1
  29. package/dist/esm/types/projects.js.map +1 -1
  30. package/dist/esm/types/sessions.d.ts +28 -0
  31. package/dist/esm/types/sessions.d.ts.map +1 -0
  32. package/dist/esm/types/sessions.js +2 -0
  33. package/dist/esm/types/sessions.js.map +1 -0
  34. package/dist/src/sessions/getSession.d.ts +21 -0
  35. package/dist/src/sessions/getSession.d.ts.map +1 -0
  36. package/dist/src/sessions/getSession.js +35 -0
  37. package/dist/src/sessions/getSession.js.map +1 -0
  38. package/dist/src/sessions/index.d.ts +2 -0
  39. package/dist/src/sessions/index.d.ts.map +1 -1
  40. package/dist/src/sessions/index.js +2 -0
  41. package/dist/src/sessions/index.js.map +1 -1
  42. package/dist/src/sessions/listSessions.d.ts +22 -0
  43. package/dist/src/sessions/listSessions.d.ts.map +1 -0
  44. package/dist/src/sessions/listSessions.js +54 -0
  45. package/dist/src/sessions/listSessions.js.map +1 -0
  46. package/dist/src/sessions/sessionUtils.d.ts +9 -0
  47. package/dist/src/sessions/sessionUtils.d.ts.map +1 -0
  48. package/dist/src/sessions/sessionUtils.js +22 -0
  49. package/dist/src/sessions/sessionUtils.js.map +1 -0
  50. package/dist/src/spans/getSpanAnnotations.d.ts +2 -2
  51. package/dist/src/spans/getSpanAnnotations.d.ts.map +1 -1
  52. package/dist/src/spans/getSpanAnnotations.js +2 -1
  53. package/dist/src/spans/getSpanAnnotations.js.map +1 -1
  54. package/dist/src/spans/getSpans.d.ts +2 -2
  55. package/dist/src/spans/getSpans.d.ts.map +1 -1
  56. package/dist/src/spans/getSpans.js +2 -1
  57. package/dist/src/spans/getSpans.js.map +1 -1
  58. package/dist/src/types/projects.d.ts +12 -3
  59. package/dist/src/types/projects.d.ts.map +1 -1
  60. package/dist/src/types/projects.js +12 -0
  61. package/dist/src/types/projects.js.map +1 -1
  62. package/dist/src/types/sessions.d.ts +28 -0
  63. package/dist/src/types/sessions.d.ts.map +1 -0
  64. package/dist/src/types/sessions.js +3 -0
  65. package/dist/src/types/sessions.js.map +1 -0
  66. package/dist/tsconfig.tsbuildinfo +1 -1
  67. package/package.json +1 -1
  68. package/src/sessions/getSession.ts +44 -0
  69. package/src/sessions/index.ts +2 -0
  70. package/src/sessions/listSessions.ts +64 -0
  71. package/src/sessions/sessionUtils.ts +23 -0
  72. package/src/spans/getSpanAnnotations.ts +4 -4
  73. package/src/spans/getSpans.ts +4 -4
  74. package/src/types/projects.ts +20 -3
  75. package/src/types/sessions.ts +29 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arizeai/phoenix-client",
3
- "version": "6.0.0",
3
+ "version": "6.1.0",
4
4
  "description": "A client for the Phoenix API",
5
5
  "keywords": [
6
6
  "arize",
@@ -0,0 +1,44 @@
1
+ import invariant from "tiny-invariant";
2
+
3
+ import { createClient } from "../client";
4
+ import type { ClientFn } from "../types/core";
5
+ import type { Session } from "../types/sessions";
6
+ import { toSession } from "./sessionUtils";
7
+
8
+ export type GetSessionParams = ClientFn & {
9
+ /**
10
+ * The session identifier: either a GlobalID or user-provided session_id string.
11
+ */
12
+ sessionId: string;
13
+ };
14
+
15
+ /**
16
+ * Fetch a single session by its GlobalID or user-provided session_id string.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import { getSession } from "@arizeai/phoenix-client/sessions";
21
+ *
22
+ * const session = await getSession({ sessionId: "my-session-id" });
23
+ * console.log(session.traces.length);
24
+ * ```
25
+ */
26
+ export async function getSession({
27
+ client: _client,
28
+ sessionId,
29
+ }: GetSessionParams): Promise<Session> {
30
+ const client = _client || createClient();
31
+ const { data, error } = await client.GET(
32
+ "/v1/sessions/{session_identifier}",
33
+ {
34
+ params: {
35
+ path: {
36
+ session_identifier: sessionId,
37
+ },
38
+ },
39
+ }
40
+ );
41
+ if (error) throw error;
42
+ invariant(data?.data, "Failed to get session");
43
+ return toSession(data.data);
44
+ }
@@ -1,2 +1,4 @@
1
1
  export * from "./addSessionAnnotation";
2
+ export * from "./getSession";
3
+ export * from "./listSessions";
2
4
  export * from "./logSessionAnnotations";
@@ -0,0 +1,64 @@
1
+ import invariant from "tiny-invariant";
2
+
3
+ import type { components } from "../__generated__/api/v1";
4
+ import { createClient } from "../client";
5
+ import type { ClientFn } from "../types/core";
6
+ import type { ProjectIdentifier } from "../types/projects";
7
+ import { resolveProjectIdentifier } from "../types/projects";
8
+ import type { Session } from "../types/sessions";
9
+ import { toSession } from "./sessionUtils";
10
+
11
+ export type ListSessionsParams = ClientFn & ProjectIdentifier;
12
+
13
+ type SessionsResponse = components["schemas"]["GetSessionsResponseBody"];
14
+
15
+ const DEFAULT_PAGE_SIZE = 100;
16
+
17
+ /**
18
+ * List all sessions for a project with automatic pagination handling.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * import { listSessions } from "@arizeai/phoenix-client/sessions";
23
+ *
24
+ * const sessions = await listSessions({
25
+ * project: "my-project",
26
+ * });
27
+ *
28
+ * for (const session of sessions) {
29
+ * console.log(`Session: ${session.sessionId}, Traces: ${session.traces.length}`);
30
+ * }
31
+ * ```
32
+ */
33
+ export async function listSessions(
34
+ params: ListSessionsParams
35
+ ): Promise<Session[]> {
36
+ const client = params.client || createClient();
37
+ const projectIdentifier = resolveProjectIdentifier(params);
38
+
39
+ const sessions: Session[] = [];
40
+ let cursor: string | null | undefined = null;
41
+
42
+ do {
43
+ const response: { data?: SessionsResponse; error?: unknown } =
44
+ await client.GET("/v1/projects/{project_identifier}/sessions", {
45
+ params: {
46
+ path: {
47
+ project_identifier: projectIdentifier,
48
+ },
49
+ query: {
50
+ cursor,
51
+ limit: DEFAULT_PAGE_SIZE,
52
+ },
53
+ },
54
+ });
55
+
56
+ if (response.error) throw response.error;
57
+ invariant(response.data?.data, "Failed to list sessions");
58
+
59
+ cursor = response.data.next_cursor ?? null;
60
+ sessions.push(...response.data.data.map(toSession));
61
+ } while (cursor != null);
62
+
63
+ return sessions;
64
+ }
@@ -0,0 +1,23 @@
1
+ import type { components } from "../__generated__/api/v1";
2
+ import type { Session } from "../types/sessions";
3
+
4
+ type SessionData = components["schemas"]["SessionData"];
5
+
6
+ /**
7
+ * Convert an API SessionData response to a user-facing Session object.
8
+ */
9
+ export function toSession(data: SessionData): Session {
10
+ return {
11
+ id: data.id,
12
+ sessionId: data.session_id,
13
+ projectId: data.project_id,
14
+ startTime: data.start_time,
15
+ endTime: data.end_time,
16
+ traces: data.traces.map((trace) => ({
17
+ id: trace.id,
18
+ traceId: trace.trace_id,
19
+ startTime: trace.start_time,
20
+ endTime: trace.end_time,
21
+ })),
22
+ };
23
+ }
@@ -1,14 +1,15 @@
1
1
  import type { operations } from "../__generated__/api/v1";
2
2
  import { createClient } from "../client";
3
3
  import type { ClientFn } from "../types/core";
4
- import type { ProjectSelector } from "../types/projects";
4
+ import type { ProjectIdentifier } from "../types/projects";
5
+ import { resolveProjectIdentifier } from "../types/projects";
5
6
 
6
7
  /**
7
8
  * Parameters to get span annotations from a project using auto-generated types
8
9
  */
9
10
  export interface GetSpanAnnotationsParams extends ClientFn {
10
11
  /** The project to get span annotations from */
11
- project: ProjectSelector;
12
+ project: ProjectIdentifier;
12
13
  /** One or more span IDs to fetch annotations for */
13
14
  spanIds: string[];
14
15
  /** Optional list of annotation names to include. If provided, only annotations with these names will be returned. 'note' annotations are excluded by default unless explicitly included in this list. */
@@ -89,8 +90,7 @@ export async function getSpanAnnotations({
89
90
  limit = 100,
90
91
  }: GetSpanAnnotationsParams): Promise<GetSpanAnnotationsResult> {
91
92
  const client = _client ?? createClient();
92
- const projectIdentifier =
93
- "projectId" in project ? project.projectId : project.projectName;
93
+ const projectIdentifier = resolveProjectIdentifier(project);
94
94
 
95
95
  const params: NonNullable<
96
96
  operations["listSpanAnnotationsBySpanIds"]["parameters"]["query"]
@@ -1,14 +1,15 @@
1
1
  import type { operations } from "../__generated__/api/v1";
2
2
  import { createClient } from "../client";
3
3
  import type { ClientFn } from "../types/core";
4
- import type { ProjectSelector } from "../types/projects";
4
+ import type { ProjectIdentifier } from "../types/projects";
5
+ import { resolveProjectIdentifier } from "../types/projects";
5
6
 
6
7
  /**
7
8
  * Parameters to get spans from a project using auto-generated types
8
9
  */
9
10
  export interface GetSpansParams extends ClientFn {
10
11
  /** The project to get spans from */
11
- project: ProjectSelector;
12
+ project: ProjectIdentifier;
12
13
  /** Inclusive lower bound time. Must be a valid ISO 8601 string or Date object. */
13
14
  startTime?: Date | string | null;
14
15
  /** Exclusive upper bound time. Must be a valid ISO 8601 string or Date object. */
@@ -87,8 +88,7 @@ export async function getSpans({
87
88
  endTime,
88
89
  }: GetSpansParams): Promise<GetSpansResult> {
89
90
  const client = _client ?? createClient();
90
- const projectIdentifier =
91
- "projectId" in project ? project.projectId : project.projectName;
91
+ const projectIdentifier = resolveProjectIdentifier(project);
92
92
 
93
93
  const params: NonNullable<operations["getSpans"]["parameters"]["query"]> = {
94
94
  limit,
@@ -1,5 +1,22 @@
1
1
  /**
2
- * A project can be identified by its projectId or projectName
3
- * In the case of a projectName, the name must be url encodable
2
+ * Identifies a project. Accepts any of:
3
+ * - `project` a project ID or name (the server accepts either)
4
+ * - `projectId` — an explicit project ID
5
+ * - `projectName` — an explicit project name
4
6
  */
5
- export type ProjectSelector = { projectId: string } | { projectName: string };
7
+ export type ProjectIdentifier =
8
+ | { project: string }
9
+ | { projectId: string }
10
+ | { projectName: string };
11
+
12
+ /**
13
+ * Resolves a {@link ProjectIdentifier} union to a plain string
14
+ * suitable for the REST `project_identifier` path parameter.
15
+ */
16
+ export function resolveProjectIdentifier(
17
+ identifier: ProjectIdentifier
18
+ ): string {
19
+ if ("project" in identifier) return identifier.project;
20
+ if ("projectId" in identifier) return identifier.projectId;
21
+ return identifier.projectName;
22
+ }
@@ -0,0 +1,29 @@
1
+ import type { Node } from "./core";
2
+
3
+ /**
4
+ * A trace that belongs to a session.
5
+ */
6
+ export interface SessionTrace extends Node {
7
+ /** The unique trace identifier (e.g. OpenTelemetry trace ID) */
8
+ traceId: string;
9
+ /** ISO 8601 timestamp of when the trace started */
10
+ startTime: string;
11
+ /** ISO 8601 timestamp of when the trace ended */
12
+ endTime: string;
13
+ }
14
+
15
+ /**
16
+ * A session representing a group of related traces (e.g. a multi-turn conversation).
17
+ */
18
+ export interface Session extends Node {
19
+ /** The user-provided session identifier */
20
+ sessionId: string;
21
+ /** The ID of the project this session belongs to */
22
+ projectId: string;
23
+ /** ISO 8601 timestamp of when the first trace in the session started */
24
+ startTime: string;
25
+ /** ISO 8601 timestamp of when the last trace in the session ended */
26
+ endTime: string;
27
+ /** The traces that belong to this session */
28
+ traces: SessionTrace[];
29
+ }