@arizeai/phoenix-client 6.0.0 → 6.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/__generated__/api/v1.d.ts +131 -3
- package/dist/esm/__generated__/api/v1.d.ts.map +1 -1
- package/dist/esm/sessions/getSession.d.ts +21 -0
- package/dist/esm/sessions/getSession.d.ts.map +1 -0
- package/dist/esm/sessions/getSession.js +29 -0
- package/dist/esm/sessions/getSession.js.map +1 -0
- package/dist/esm/sessions/index.d.ts +2 -0
- package/dist/esm/sessions/index.d.ts.map +1 -1
- package/dist/esm/sessions/index.js +2 -0
- package/dist/esm/sessions/index.js.map +1 -1
- package/dist/esm/sessions/listSessions.d.ts +22 -0
- package/dist/esm/sessions/listSessions.d.ts.map +1 -0
- package/dist/esm/sessions/listSessions.js +47 -0
- package/dist/esm/sessions/listSessions.js.map +1 -0
- package/dist/esm/sessions/sessionUtils.d.ts +9 -0
- package/dist/esm/sessions/sessionUtils.d.ts.map +1 -0
- package/dist/esm/sessions/sessionUtils.js +19 -0
- package/dist/esm/sessions/sessionUtils.js.map +1 -0
- package/dist/esm/spans/getSpanAnnotations.d.ts +2 -2
- package/dist/esm/spans/getSpanAnnotations.d.ts.map +1 -1
- package/dist/esm/spans/getSpanAnnotations.js +2 -1
- package/dist/esm/spans/getSpanAnnotations.js.map +1 -1
- package/dist/esm/spans/getSpans.d.ts +12 -3
- package/dist/esm/spans/getSpans.d.ts.map +1 -1
- package/dist/esm/spans/getSpans.js +13 -2
- package/dist/esm/spans/getSpans.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/esm/types/projects.d.ts +12 -3
- package/dist/esm/types/projects.d.ts.map +1 -1
- package/dist/esm/types/projects.js +11 -1
- package/dist/esm/types/projects.js.map +1 -1
- package/dist/esm/types/sessions.d.ts +28 -0
- package/dist/esm/types/sessions.d.ts.map +1 -0
- package/dist/esm/types/sessions.js +2 -0
- package/dist/esm/types/sessions.js.map +1 -0
- package/dist/esm/utils/formatPromptMessages.d.ts.map +1 -1
- package/dist/esm/utils/getPromptBySelector.d.ts +1 -1
- package/dist/esm/utils/getPromptBySelector.d.ts.map +1 -1
- package/dist/src/__generated__/api/v1.d.ts +131 -3
- package/dist/src/__generated__/api/v1.d.ts.map +1 -1
- package/dist/src/sessions/getSession.d.ts +21 -0
- package/dist/src/sessions/getSession.d.ts.map +1 -0
- package/dist/src/sessions/getSession.js +35 -0
- package/dist/src/sessions/getSession.js.map +1 -0
- package/dist/src/sessions/index.d.ts +2 -0
- package/dist/src/sessions/index.d.ts.map +1 -1
- package/dist/src/sessions/index.js +2 -0
- package/dist/src/sessions/index.js.map +1 -1
- package/dist/src/sessions/listSessions.d.ts +22 -0
- package/dist/src/sessions/listSessions.d.ts.map +1 -0
- package/dist/src/sessions/listSessions.js +54 -0
- package/dist/src/sessions/listSessions.js.map +1 -0
- package/dist/src/sessions/sessionUtils.d.ts +9 -0
- package/dist/src/sessions/sessionUtils.d.ts.map +1 -0
- package/dist/src/sessions/sessionUtils.js +22 -0
- package/dist/src/sessions/sessionUtils.js.map +1 -0
- package/dist/src/spans/getSpanAnnotations.d.ts +2 -2
- package/dist/src/spans/getSpanAnnotations.d.ts.map +1 -1
- package/dist/src/spans/getSpanAnnotations.js +2 -1
- package/dist/src/spans/getSpanAnnotations.js.map +1 -1
- package/dist/src/spans/getSpans.d.ts +12 -3
- package/dist/src/spans/getSpans.d.ts.map +1 -1
- package/dist/src/spans/getSpans.js +13 -2
- package/dist/src/spans/getSpans.js.map +1 -1
- package/dist/src/types/projects.d.ts +12 -3
- package/dist/src/types/projects.d.ts.map +1 -1
- package/dist/src/types/projects.js +12 -0
- package/dist/src/types/projects.js.map +1 -1
- package/dist/src/types/sessions.d.ts +28 -0
- package/dist/src/types/sessions.d.ts.map +1 -0
- package/dist/src/types/sessions.js +3 -0
- package/dist/src/types/sessions.js.map +1 -0
- package/dist/src/utils/formatPromptMessages.d.ts.map +1 -1
- package/dist/src/utils/getPromptBySelector.d.ts +1 -1
- package/dist/src/utils/getPromptBySelector.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/__generated__/api/v1.ts +131 -3
- package/src/sessions/getSession.ts +44 -0
- package/src/sessions/index.ts +2 -0
- package/src/sessions/listSessions.ts +64 -0
- package/src/sessions/sessionUtils.ts +23 -0
- package/src/spans/getSpanAnnotations.ts +4 -4
- package/src/spans/getSpans.ts +18 -4
- package/src/types/projects.ts +20 -3
- package/src/types/sessions.ts +29 -0
package/package.json
CHANGED
|
@@ -1745,7 +1745,7 @@ export interface components {
|
|
|
1745
1745
|
* ModelProvider
|
|
1746
1746
|
* @enum {string}
|
|
1747
1747
|
*/
|
|
1748
|
-
ModelProvider: "OPENAI" | "AZURE_OPENAI" | "ANTHROPIC" | "GOOGLE" | "DEEPSEEK" | "XAI" | "OLLAMA" | "AWS";
|
|
1748
|
+
ModelProvider: "OPENAI" | "AZURE_OPENAI" | "ANTHROPIC" | "GOOGLE" | "DEEPSEEK" | "XAI" | "OLLAMA" | "AWS" | "CEREBRAS" | "FIREWORKS" | "GROQ" | "MOONSHOT";
|
|
1749
1749
|
/** OAuth2User */
|
|
1750
1750
|
OAuth2User: {
|
|
1751
1751
|
/** Id */
|
|
@@ -2122,6 +2122,37 @@ export interface components {
|
|
|
2122
2122
|
*/
|
|
2123
2123
|
reasoning_effort?: "none" | "minimal" | "low" | "medium" | "high" | "xhigh";
|
|
2124
2124
|
};
|
|
2125
|
+
/** PromptCerebrasInvocationParameters */
|
|
2126
|
+
PromptCerebrasInvocationParameters: {
|
|
2127
|
+
/**
|
|
2128
|
+
* @description discriminator enum property added by openapi-typescript
|
|
2129
|
+
* @enum {string}
|
|
2130
|
+
*/
|
|
2131
|
+
type: "cerebras";
|
|
2132
|
+
cerebras: components["schemas"]["PromptCerebrasInvocationParametersContent"];
|
|
2133
|
+
};
|
|
2134
|
+
/** PromptCerebrasInvocationParametersContent */
|
|
2135
|
+
PromptCerebrasInvocationParametersContent: {
|
|
2136
|
+
/** Temperature */
|
|
2137
|
+
temperature?: number;
|
|
2138
|
+
/** Max Tokens */
|
|
2139
|
+
max_tokens?: number;
|
|
2140
|
+
/** Max Completion Tokens */
|
|
2141
|
+
max_completion_tokens?: number;
|
|
2142
|
+
/** Frequency Penalty */
|
|
2143
|
+
frequency_penalty?: number;
|
|
2144
|
+
/** Presence Penalty */
|
|
2145
|
+
presence_penalty?: number;
|
|
2146
|
+
/** Top P */
|
|
2147
|
+
top_p?: number;
|
|
2148
|
+
/** Seed */
|
|
2149
|
+
seed?: number;
|
|
2150
|
+
/**
|
|
2151
|
+
* Reasoning Effort
|
|
2152
|
+
* @enum {string}
|
|
2153
|
+
*/
|
|
2154
|
+
reasoning_effort?: "none" | "minimal" | "low" | "medium" | "high" | "xhigh";
|
|
2155
|
+
};
|
|
2125
2156
|
/** PromptChatTemplate */
|
|
2126
2157
|
PromptChatTemplate: {
|
|
2127
2158
|
/**
|
|
@@ -2175,6 +2206,37 @@ export interface components {
|
|
|
2175
2206
|
*/
|
|
2176
2207
|
reasoning_effort?: "none" | "minimal" | "low" | "medium" | "high" | "xhigh";
|
|
2177
2208
|
};
|
|
2209
|
+
/** PromptFireworksInvocationParameters */
|
|
2210
|
+
PromptFireworksInvocationParameters: {
|
|
2211
|
+
/**
|
|
2212
|
+
* @description discriminator enum property added by openapi-typescript
|
|
2213
|
+
* @enum {string}
|
|
2214
|
+
*/
|
|
2215
|
+
type: "fireworks";
|
|
2216
|
+
fireworks: components["schemas"]["PromptFireworksInvocationParametersContent"];
|
|
2217
|
+
};
|
|
2218
|
+
/** PromptFireworksInvocationParametersContent */
|
|
2219
|
+
PromptFireworksInvocationParametersContent: {
|
|
2220
|
+
/** Temperature */
|
|
2221
|
+
temperature?: number;
|
|
2222
|
+
/** Max Tokens */
|
|
2223
|
+
max_tokens?: number;
|
|
2224
|
+
/** Max Completion Tokens */
|
|
2225
|
+
max_completion_tokens?: number;
|
|
2226
|
+
/** Frequency Penalty */
|
|
2227
|
+
frequency_penalty?: number;
|
|
2228
|
+
/** Presence Penalty */
|
|
2229
|
+
presence_penalty?: number;
|
|
2230
|
+
/** Top P */
|
|
2231
|
+
top_p?: number;
|
|
2232
|
+
/** Seed */
|
|
2233
|
+
seed?: number;
|
|
2234
|
+
/**
|
|
2235
|
+
* Reasoning Effort
|
|
2236
|
+
* @enum {string}
|
|
2237
|
+
*/
|
|
2238
|
+
reasoning_effort?: "none" | "minimal" | "low" | "medium" | "high" | "xhigh";
|
|
2239
|
+
};
|
|
2178
2240
|
/** PromptGoogleInvocationParameters */
|
|
2179
2241
|
PromptGoogleInvocationParameters: {
|
|
2180
2242
|
/**
|
|
@@ -2201,6 +2263,37 @@ export interface components {
|
|
|
2201
2263
|
/** Top K */
|
|
2202
2264
|
top_k?: number;
|
|
2203
2265
|
};
|
|
2266
|
+
/** PromptGroqInvocationParameters */
|
|
2267
|
+
PromptGroqInvocationParameters: {
|
|
2268
|
+
/**
|
|
2269
|
+
* @description discriminator enum property added by openapi-typescript
|
|
2270
|
+
* @enum {string}
|
|
2271
|
+
*/
|
|
2272
|
+
type: "groq";
|
|
2273
|
+
groq: components["schemas"]["PromptGroqInvocationParametersContent"];
|
|
2274
|
+
};
|
|
2275
|
+
/** PromptGroqInvocationParametersContent */
|
|
2276
|
+
PromptGroqInvocationParametersContent: {
|
|
2277
|
+
/** Temperature */
|
|
2278
|
+
temperature?: number;
|
|
2279
|
+
/** Max Tokens */
|
|
2280
|
+
max_tokens?: number;
|
|
2281
|
+
/** Max Completion Tokens */
|
|
2282
|
+
max_completion_tokens?: number;
|
|
2283
|
+
/** Frequency Penalty */
|
|
2284
|
+
frequency_penalty?: number;
|
|
2285
|
+
/** Presence Penalty */
|
|
2286
|
+
presence_penalty?: number;
|
|
2287
|
+
/** Top P */
|
|
2288
|
+
top_p?: number;
|
|
2289
|
+
/** Seed */
|
|
2290
|
+
seed?: number;
|
|
2291
|
+
/**
|
|
2292
|
+
* Reasoning Effort
|
|
2293
|
+
* @enum {string}
|
|
2294
|
+
*/
|
|
2295
|
+
reasoning_effort?: "none" | "minimal" | "low" | "medium" | "high" | "xhigh";
|
|
2296
|
+
};
|
|
2204
2297
|
/** PromptMessage */
|
|
2205
2298
|
PromptMessage: {
|
|
2206
2299
|
/**
|
|
@@ -2211,6 +2304,37 @@ export interface components {
|
|
|
2211
2304
|
/** Content */
|
|
2212
2305
|
content: string | (components["schemas"]["TextContentPart"] | components["schemas"]["ToolCallContentPart"] | components["schemas"]["ToolResultContentPart"])[];
|
|
2213
2306
|
};
|
|
2307
|
+
/** PromptMoonshotInvocationParameters */
|
|
2308
|
+
PromptMoonshotInvocationParameters: {
|
|
2309
|
+
/**
|
|
2310
|
+
* @description discriminator enum property added by openapi-typescript
|
|
2311
|
+
* @enum {string}
|
|
2312
|
+
*/
|
|
2313
|
+
type: "moonshot";
|
|
2314
|
+
moonshot: components["schemas"]["PromptMoonshotInvocationParametersContent"];
|
|
2315
|
+
};
|
|
2316
|
+
/** PromptMoonshotInvocationParametersContent */
|
|
2317
|
+
PromptMoonshotInvocationParametersContent: {
|
|
2318
|
+
/** Temperature */
|
|
2319
|
+
temperature?: number;
|
|
2320
|
+
/** Max Tokens */
|
|
2321
|
+
max_tokens?: number;
|
|
2322
|
+
/** Max Completion Tokens */
|
|
2323
|
+
max_completion_tokens?: number;
|
|
2324
|
+
/** Frequency Penalty */
|
|
2325
|
+
frequency_penalty?: number;
|
|
2326
|
+
/** Presence Penalty */
|
|
2327
|
+
presence_penalty?: number;
|
|
2328
|
+
/** Top P */
|
|
2329
|
+
top_p?: number;
|
|
2330
|
+
/** Seed */
|
|
2331
|
+
seed?: number;
|
|
2332
|
+
/**
|
|
2333
|
+
* Reasoning Effort
|
|
2334
|
+
* @enum {string}
|
|
2335
|
+
*/
|
|
2336
|
+
reasoning_effort?: "none" | "minimal" | "low" | "medium" | "high" | "xhigh";
|
|
2337
|
+
};
|
|
2214
2338
|
/** PromptOllamaInvocationParameters */
|
|
2215
2339
|
PromptOllamaInvocationParameters: {
|
|
2216
2340
|
/**
|
|
@@ -2397,7 +2521,7 @@ export interface components {
|
|
|
2397
2521
|
template_type: components["schemas"]["PromptTemplateType"];
|
|
2398
2522
|
template_format: components["schemas"]["PromptTemplateFormat"];
|
|
2399
2523
|
/** Invocation Parameters */
|
|
2400
|
-
invocation_parameters: components["schemas"]["PromptOpenAIInvocationParameters"] | components["schemas"]["PromptAzureOpenAIInvocationParameters"] | components["schemas"]["PromptAnthropicInvocationParameters"] | components["schemas"]["PromptGoogleInvocationParameters"] | components["schemas"]["PromptDeepSeekInvocationParameters"] | components["schemas"]["PromptXAIInvocationParameters"] | components["schemas"]["PromptOllamaInvocationParameters"] | components["schemas"]["PromptAwsInvocationParameters"];
|
|
2524
|
+
invocation_parameters: components["schemas"]["PromptOpenAIInvocationParameters"] | components["schemas"]["PromptAzureOpenAIInvocationParameters"] | components["schemas"]["PromptAnthropicInvocationParameters"] | components["schemas"]["PromptGoogleInvocationParameters"] | components["schemas"]["PromptDeepSeekInvocationParameters"] | components["schemas"]["PromptXAIInvocationParameters"] | components["schemas"]["PromptOllamaInvocationParameters"] | components["schemas"]["PromptAwsInvocationParameters"] | components["schemas"]["PromptCerebrasInvocationParameters"] | components["schemas"]["PromptFireworksInvocationParameters"] | components["schemas"]["PromptGroqInvocationParameters"] | components["schemas"]["PromptMoonshotInvocationParameters"];
|
|
2401
2525
|
tools?: components["schemas"]["PromptTools"] | null;
|
|
2402
2526
|
/** Response Format */
|
|
2403
2527
|
response_format?: components["schemas"]["PromptResponseFormatJSONSchema"] | null;
|
|
@@ -2416,7 +2540,7 @@ export interface components {
|
|
|
2416
2540
|
template_type: components["schemas"]["PromptTemplateType"];
|
|
2417
2541
|
template_format: components["schemas"]["PromptTemplateFormat"];
|
|
2418
2542
|
/** Invocation Parameters */
|
|
2419
|
-
invocation_parameters: components["schemas"]["PromptOpenAIInvocationParameters"] | components["schemas"]["PromptAzureOpenAIInvocationParameters"] | components["schemas"]["PromptAnthropicInvocationParameters"] | components["schemas"]["PromptGoogleInvocationParameters"] | components["schemas"]["PromptDeepSeekInvocationParameters"] | components["schemas"]["PromptXAIInvocationParameters"] | components["schemas"]["PromptOllamaInvocationParameters"] | components["schemas"]["PromptAwsInvocationParameters"];
|
|
2543
|
+
invocation_parameters: components["schemas"]["PromptOpenAIInvocationParameters"] | components["schemas"]["PromptAzureOpenAIInvocationParameters"] | components["schemas"]["PromptAnthropicInvocationParameters"] | components["schemas"]["PromptGoogleInvocationParameters"] | components["schemas"]["PromptDeepSeekInvocationParameters"] | components["schemas"]["PromptXAIInvocationParameters"] | components["schemas"]["PromptOllamaInvocationParameters"] | components["schemas"]["PromptAwsInvocationParameters"] | components["schemas"]["PromptCerebrasInvocationParameters"] | components["schemas"]["PromptFireworksInvocationParameters"] | components["schemas"]["PromptGroqInvocationParameters"] | components["schemas"]["PromptMoonshotInvocationParameters"];
|
|
2420
2544
|
tools?: components["schemas"]["PromptTools"] | null;
|
|
2421
2545
|
/** Response Format */
|
|
2422
2546
|
response_format?: components["schemas"]["PromptResponseFormatJSONSchema"] | null;
|
|
@@ -4635,6 +4759,8 @@ export interface operations {
|
|
|
4635
4759
|
start_time?: string | null;
|
|
4636
4760
|
/** @description Exclusive upper bound time */
|
|
4637
4761
|
end_time?: string | null;
|
|
4762
|
+
/** @description Filter by one or more trace IDs */
|
|
4763
|
+
trace_id?: string[] | null;
|
|
4638
4764
|
};
|
|
4639
4765
|
header?: never;
|
|
4640
4766
|
path: {
|
|
@@ -4694,6 +4820,8 @@ export interface operations {
|
|
|
4694
4820
|
start_time?: string | null;
|
|
4695
4821
|
/** @description Exclusive upper bound time */
|
|
4696
4822
|
end_time?: string | null;
|
|
4823
|
+
/** @description Filter by one or more trace IDs */
|
|
4824
|
+
trace_id?: string[] | null;
|
|
4697
4825
|
};
|
|
4698
4826
|
header?: never;
|
|
4699
4827
|
path: {
|
|
@@ -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
|
+
}
|
package/src/sessions/index.ts
CHANGED
|
@@ -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 {
|
|
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:
|
|
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"]
|
package/src/spans/getSpans.ts
CHANGED
|
@@ -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 {
|
|
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:
|
|
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. */
|
|
@@ -17,6 +18,8 @@ export interface GetSpansParams extends ClientFn {
|
|
|
17
18
|
cursor?: string | null;
|
|
18
19
|
/** Maximum number of spans to return */
|
|
19
20
|
limit?: number;
|
|
21
|
+
/** Filter spans by one or more trace IDs */
|
|
22
|
+
traceIds?: string[] | null;
|
|
20
23
|
}
|
|
21
24
|
|
|
22
25
|
export type GetSpansResponse = operations["getSpans"]["responses"]["200"];
|
|
@@ -58,6 +61,13 @@ export type GetSpansResult = {
|
|
|
58
61
|
* limit: 100
|
|
59
62
|
* });
|
|
60
63
|
|
|
64
|
+
*
|
|
65
|
+
* // Get all spans for specific traces (requires Phoenix server >= 13.9.0)
|
|
66
|
+
* const result = await getSpans({
|
|
67
|
+
* client,
|
|
68
|
+
* project: { projectName: "my-project" },
|
|
69
|
+
* traceIds: ["trace-abc-123", "trace-def-456"],
|
|
70
|
+
* });
|
|
61
71
|
*
|
|
62
72
|
* // Paginate through results
|
|
63
73
|
* let cursor: string | undefined;
|
|
@@ -85,10 +95,10 @@ export async function getSpans({
|
|
|
85
95
|
limit = 100,
|
|
86
96
|
startTime,
|
|
87
97
|
endTime,
|
|
98
|
+
traceIds,
|
|
88
99
|
}: GetSpansParams): Promise<GetSpansResult> {
|
|
89
100
|
const client = _client ?? createClient();
|
|
90
|
-
const projectIdentifier =
|
|
91
|
-
"projectId" in project ? project.projectId : project.projectName;
|
|
101
|
+
const projectIdentifier = resolveProjectIdentifier(project);
|
|
92
102
|
|
|
93
103
|
const params: NonNullable<operations["getSpans"]["parameters"]["query"]> = {
|
|
94
104
|
limit,
|
|
@@ -107,6 +117,10 @@ export async function getSpans({
|
|
|
107
117
|
params.end_time = endTime instanceof Date ? endTime.toISOString() : endTime;
|
|
108
118
|
}
|
|
109
119
|
|
|
120
|
+
if (traceIds) {
|
|
121
|
+
params.trace_id = traceIds;
|
|
122
|
+
}
|
|
123
|
+
|
|
110
124
|
const { data, error } = await client.GET(
|
|
111
125
|
"/v1/projects/{project_identifier}/spans",
|
|
112
126
|
{
|
package/src/types/projects.ts
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
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
|
|
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
|
+
}
|