@arizeai/phoenix-client 7.5.0 → 7.7.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/CHANGELOG.md +781 -0
- package/README.md +27 -3
- package/dist/esm/__generated__/api/v1.d.ts +749 -203
- package/dist/esm/__generated__/api/v1.d.ts.map +1 -1
- package/dist/esm/constants/serverRequirements.d.ts +2 -0
- package/dist/esm/constants/serverRequirements.d.ts.map +1 -1
- package/dist/esm/constants/serverRequirements.js +14 -0
- package/dist/esm/constants/serverRequirements.js.map +1 -1
- package/dist/esm/projects/index.d.ts +1 -0
- package/dist/esm/projects/index.d.ts.map +1 -1
- package/dist/esm/projects/index.js +1 -0
- package/dist/esm/projects/index.js.map +1 -1
- package/dist/esm/projects/setProjectRetentionPolicy.d.ts +49 -0
- package/dist/esm/projects/setProjectRetentionPolicy.d.ts.map +1 -0
- package/dist/esm/projects/setProjectRetentionPolicy.js +52 -0
- package/dist/esm/projects/setProjectRetentionPolicy.js.map +1 -0
- package/dist/esm/prompts/deletePrompt.d.ts +39 -0
- package/dist/esm/prompts/deletePrompt.d.ts.map +1 -0
- package/dist/esm/prompts/deletePrompt.js +52 -0
- package/dist/esm/prompts/deletePrompt.js.map +1 -0
- package/dist/esm/prompts/index.d.ts +1 -0
- package/dist/esm/prompts/index.d.ts.map +1 -1
- package/dist/esm/prompts/index.js +1 -0
- package/dist/esm/prompts/index.js.map +1 -1
- package/dist/esm/testing/reporter-format.d.ts.map +1 -1
- package/dist/esm/testing/reporter-format.js +13 -3
- package/dist/esm/testing/reporter-format.js.map +1 -1
- package/dist/esm/traces/getTraces.d.ts +1 -1
- package/dist/esm/traces/getTraces.d.ts.map +1 -1
- package/dist/esm/traces/index.d.ts +1 -0
- package/dist/esm/traces/index.d.ts.map +1 -1
- package/dist/esm/traces/index.js +1 -0
- package/dist/esm/traces/index.js.map +1 -1
- package/dist/esm/traces/transferTraces.d.ts +56 -0
- package/dist/esm/traces/transferTraces.d.ts.map +1 -0
- package/dist/esm/traces/transferTraces.js +56 -0
- package/dist/esm/traces/transferTraces.js.map +1 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/esm/types/prompts.d.ts +9 -0
- package/dist/esm/types/prompts.d.ts.map +1 -1
- package/dist/esm/types/prompts.js.map +1 -1
- package/dist/esm/users/getCurrentUser.d.ts +25 -0
- package/dist/esm/users/getCurrentUser.d.ts.map +1 -0
- package/dist/esm/users/getCurrentUser.js +30 -0
- package/dist/esm/users/getCurrentUser.js.map +1 -0
- package/dist/esm/users/index.d.ts +2 -0
- package/dist/esm/users/index.d.ts.map +1 -0
- package/dist/esm/users/index.js +2 -0
- package/dist/esm/users/index.js.map +1 -0
- package/dist/esm/utils/resolvePromptIdentifier.d.ts +17 -0
- package/dist/esm/utils/resolvePromptIdentifier.d.ts.map +1 -0
- package/dist/esm/utils/resolvePromptIdentifier.js +36 -0
- package/dist/esm/utils/resolvePromptIdentifier.js.map +1 -0
- package/dist/src/__generated__/api/v1.d.ts +749 -203
- package/dist/src/__generated__/api/v1.d.ts.map +1 -1
- package/dist/src/constants/serverRequirements.d.ts +2 -0
- package/dist/src/constants/serverRequirements.d.ts.map +1 -1
- package/dist/src/constants/serverRequirements.js +15 -1
- package/dist/src/constants/serverRequirements.js.map +1 -1
- package/dist/src/projects/index.d.ts +1 -0
- package/dist/src/projects/index.d.ts.map +1 -1
- package/dist/src/projects/index.js +1 -0
- package/dist/src/projects/index.js.map +1 -1
- package/dist/src/projects/setProjectRetentionPolicy.d.ts +49 -0
- package/dist/src/projects/setProjectRetentionPolicy.d.ts.map +1 -0
- package/dist/src/projects/setProjectRetentionPolicy.js +59 -0
- package/dist/src/projects/setProjectRetentionPolicy.js.map +1 -0
- package/dist/src/prompts/deletePrompt.d.ts +39 -0
- package/dist/src/prompts/deletePrompt.d.ts.map +1 -0
- package/dist/src/prompts/deletePrompt.js +55 -0
- package/dist/src/prompts/deletePrompt.js.map +1 -0
- package/dist/src/prompts/index.d.ts +1 -0
- package/dist/src/prompts/index.d.ts.map +1 -1
- package/dist/src/prompts/index.js +1 -0
- package/dist/src/prompts/index.js.map +1 -1
- package/dist/src/testing/reporter-format.d.ts.map +1 -1
- package/dist/src/testing/reporter-format.js +13 -3
- package/dist/src/testing/reporter-format.js.map +1 -1
- package/dist/src/traces/getTraces.d.ts +1 -1
- package/dist/src/traces/getTraces.d.ts.map +1 -1
- package/dist/src/traces/index.d.ts +1 -0
- package/dist/src/traces/index.d.ts.map +1 -1
- package/dist/src/traces/index.js +1 -0
- package/dist/src/traces/index.js.map +1 -1
- package/dist/src/traces/transferTraces.d.ts +56 -0
- package/dist/src/traces/transferTraces.d.ts.map +1 -0
- package/dist/src/traces/transferTraces.js +59 -0
- package/dist/src/traces/transferTraces.js.map +1 -0
- package/dist/src/types/prompts.d.ts +9 -0
- package/dist/src/types/prompts.d.ts.map +1 -1
- package/dist/src/types/prompts.js.map +1 -1
- package/dist/src/users/getCurrentUser.d.ts +25 -0
- package/dist/src/users/getCurrentUser.d.ts.map +1 -0
- package/dist/src/users/getCurrentUser.js +36 -0
- package/dist/src/users/getCurrentUser.js.map +1 -0
- package/dist/src/users/index.d.ts +2 -0
- package/dist/src/users/index.d.ts.map +1 -0
- package/dist/src/users/index.js +18 -0
- package/dist/src/users/index.js.map +1 -0
- package/dist/src/utils/resolvePromptIdentifier.d.ts +17 -0
- package/dist/src/utils/resolvePromptIdentifier.d.ts.map +1 -0
- package/dist/src/utils/resolvePromptIdentifier.js +39 -0
- package/dist/src/utils/resolvePromptIdentifier.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/docs/overview.mdx +8 -4
- package/docs/projects.mdx +71 -0
- package/docs/prompts.mdx +19 -1
- package/docs/traces.mdx +28 -2
- package/docs/users.mdx +44 -0
- package/package.json +16 -12
- package/src/__generated__/api/v1.ts +749 -203
- package/src/constants/serverRequirements.ts +16 -0
- package/src/projects/index.ts +1 -0
- package/src/projects/setProjectRetentionPolicy.ts +80 -0
- package/src/prompts/deletePrompt.ts +70 -0
- package/src/prompts/index.ts +1 -0
- package/src/testing/reporter-format.ts +13 -3
- package/src/traces/getTraces.ts +1 -1
- package/src/traces/index.ts +1 -0
- package/src/traces/transferTraces.ts +89 -0
- package/src/types/prompts.ts +10 -0
- package/src/users/getCurrentUser.ts +39 -0
- package/src/users/index.ts +1 -0
- package/src/utils/resolvePromptIdentifier.ts +41 -0
|
@@ -98,6 +98,13 @@ export const LIST_PROJECT_TRACES: RouteRequirement = {
|
|
|
98
98
|
minServerVersion: [13, 15, 0],
|
|
99
99
|
};
|
|
100
100
|
|
|
101
|
+
export const TRANSFER_TRACES: RouteRequirement = {
|
|
102
|
+
kind: "route",
|
|
103
|
+
method: "POST",
|
|
104
|
+
path: "/v1/traces/transfer",
|
|
105
|
+
minServerVersion: [20, 4, 0],
|
|
106
|
+
};
|
|
107
|
+
|
|
101
108
|
export const GET_SPANS_BY_ATTRIBUTE: ParameterRequirement = {
|
|
102
109
|
kind: "parameter",
|
|
103
110
|
parameterName: "attribute",
|
|
@@ -138,6 +145,13 @@ export const ADD_SESSION_NOTE_IDENTIFIER: ParameterRequirement = {
|
|
|
138
145
|
minServerVersion: [15, 5, 0],
|
|
139
146
|
};
|
|
140
147
|
|
|
148
|
+
export const DELETE_PROMPT: RouteRequirement = {
|
|
149
|
+
kind: "route",
|
|
150
|
+
method: "DELETE",
|
|
151
|
+
path: "/v1/prompts/{prompt_identifier}",
|
|
152
|
+
minServerVersion: [13, 20, 0],
|
|
153
|
+
};
|
|
154
|
+
|
|
141
155
|
export const PATCH_PROMPT: RouteRequirement = {
|
|
142
156
|
kind: "route",
|
|
143
157
|
method: "PATCH",
|
|
@@ -220,10 +234,12 @@ export const ALL_REQUIREMENTS: readonly CapabilityRequirement[] = [
|
|
|
220
234
|
GET_SPANS_FILTERS,
|
|
221
235
|
GET_SPANS_BY_ATTRIBUTE,
|
|
222
236
|
LIST_PROJECT_TRACES,
|
|
237
|
+
TRANSFER_TRACES,
|
|
223
238
|
DATASET_UPLOAD_EXAMPLE_IDS,
|
|
224
239
|
ADD_TRACE_NOTE_IDENTIFIER,
|
|
225
240
|
ADD_SPAN_NOTE_IDENTIFIER,
|
|
226
241
|
ADD_SESSION_NOTE_IDENTIFIER,
|
|
242
|
+
DELETE_PROMPT,
|
|
227
243
|
PATCH_PROMPT,
|
|
228
244
|
AGENT_SESSION_CREATE,
|
|
229
245
|
AGENT_SESSION_LIST,
|
package/src/projects/index.ts
CHANGED
|
@@ -0,0 +1,80 @@
|
|
|
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
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The retention-policy assignment returned for a project.
|
|
11
|
+
*/
|
|
12
|
+
export type ProjectRetentionPolicyAssignment =
|
|
13
|
+
components["schemas"]["ProjectRetentionPolicyData"];
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Parameters for assigning or resetting a project's retention policy.
|
|
17
|
+
*/
|
|
18
|
+
export type SetProjectRetentionPolicyParams = ClientFn &
|
|
19
|
+
ProjectIdentifier & {
|
|
20
|
+
/**
|
|
21
|
+
* The GlobalID of an existing trace retention policy, or `null` to reset
|
|
22
|
+
* the project to the default policy.
|
|
23
|
+
*/
|
|
24
|
+
policyId: string | null;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Assign an existing trace retention policy to a project, or reset the project
|
|
29
|
+
* to the default policy.
|
|
30
|
+
*
|
|
31
|
+
* This helper only changes the project's assignment. It does not create,
|
|
32
|
+
* retrieve, update, or delete retention policies.
|
|
33
|
+
*
|
|
34
|
+
* @param params - The project and policy assignment.
|
|
35
|
+
* @param params.project - A project name or GlobalID.
|
|
36
|
+
* @param params.projectId - A project GlobalID.
|
|
37
|
+
* @param params.projectName - A project name.
|
|
38
|
+
* @param params.policyId - An existing policy GlobalID, or `null` to reset.
|
|
39
|
+
* @param params.client - An optional Phoenix client instance.
|
|
40
|
+
* @returns The project's resulting retention-policy assignment.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { setProjectRetentionPolicy } from "@arizeai/phoenix-client/projects";
|
|
45
|
+
*
|
|
46
|
+
* await setProjectRetentionPolicy({
|
|
47
|
+
* projectName: "support-bot",
|
|
48
|
+
* policyId: "UHJvamVjdFRyYWNlUmV0ZW50aW9uUG9saWN5OjI=",
|
|
49
|
+
* });
|
|
50
|
+
*
|
|
51
|
+
* await setProjectRetentionPolicy({
|
|
52
|
+
* projectId: "UHJvamVjdDox",
|
|
53
|
+
* policyId: null,
|
|
54
|
+
* });
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export async function setProjectRetentionPolicy(
|
|
58
|
+
params: SetProjectRetentionPolicyParams
|
|
59
|
+
): Promise<ProjectRetentionPolicyAssignment> {
|
|
60
|
+
const client = params.client ?? createClient();
|
|
61
|
+
const projectIdentifier = resolveProjectIdentifier(params);
|
|
62
|
+
|
|
63
|
+
const { data, error } = await client.PATCH(
|
|
64
|
+
"/v1/projects/{project_identifier}/retention",
|
|
65
|
+
{
|
|
66
|
+
params: {
|
|
67
|
+
path: {
|
|
68
|
+
project_identifier: projectIdentifier,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
body: {
|
|
72
|
+
policy_id: params.policyId,
|
|
73
|
+
},
|
|
74
|
+
}
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
if (error) throw error;
|
|
78
|
+
invariant(data?.data, "Failed to set project retention policy");
|
|
79
|
+
return data.data;
|
|
80
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { createClient } from "../client";
|
|
2
|
+
import { DELETE_PROMPT } from "../constants/serverRequirements";
|
|
3
|
+
import { HttpError } from "../errors";
|
|
4
|
+
import type { ClientFn } from "../types/core";
|
|
5
|
+
import type { PromptIdentifier } from "../types/prompts";
|
|
6
|
+
import { resolvePromptIdentifier } from "../utils/resolvePromptIdentifier";
|
|
7
|
+
import { ensureServerCapability } from "../utils/serverVersionUtils";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Parameters for deleting a prompt.
|
|
11
|
+
*/
|
|
12
|
+
export interface DeletePromptParams extends ClientFn {
|
|
13
|
+
/**
|
|
14
|
+
* The prompt to delete. Selected either by `name` or by `promptId` — the same
|
|
15
|
+
* selector style {@link getPrompt} takes, minus the version-level selectors,
|
|
16
|
+
* which do not identify a prompt.
|
|
17
|
+
*/
|
|
18
|
+
prompt: PromptIdentifier;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Delete a prompt via `DELETE /v1/prompts/{prompt_identifier}`.
|
|
23
|
+
*
|
|
24
|
+
* Deletion cascades: every version of the prompt, along with its version tags
|
|
25
|
+
* and labels, is removed with it. This cannot be undone.
|
|
26
|
+
*
|
|
27
|
+
* @param params - The parameters to delete the prompt.
|
|
28
|
+
* @param params.prompt - The prompt to delete, selected by `name` or `promptId`.
|
|
29
|
+
* @returns A promise that resolves once the prompt is deleted.
|
|
30
|
+
* @throws An error if the prompt does not exist, or if the deletion fails.
|
|
31
|
+
*
|
|
32
|
+
* @requires Phoenix server >= 13.20.0
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { deletePrompt } from "@arizeai/phoenix-client/prompts";
|
|
37
|
+
*
|
|
38
|
+
* // Delete by name
|
|
39
|
+
* await deletePrompt({ prompt: { name: "my-prompt" } });
|
|
40
|
+
*
|
|
41
|
+
* // Delete by prompt id
|
|
42
|
+
* await deletePrompt({ prompt: { promptId: "UHJvbXB0OjE=" } });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export async function deletePrompt({
|
|
46
|
+
client: _client,
|
|
47
|
+
prompt,
|
|
48
|
+
}: DeletePromptParams): Promise<void> {
|
|
49
|
+
const promptIdentifier = resolvePromptIdentifier(prompt);
|
|
50
|
+
|
|
51
|
+
const client = _client ?? createClient();
|
|
52
|
+
await ensureServerCapability({ client, requirement: DELETE_PROMPT });
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
await client.DELETE("/v1/prompts/{prompt_identifier}", {
|
|
56
|
+
params: {
|
|
57
|
+
path: {
|
|
58
|
+
prompt_identifier: promptIdentifier,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
} catch (error) {
|
|
63
|
+
if (error instanceof HttpError && error.status === 404) {
|
|
64
|
+
throw new Error(`Prompt not found: ${promptIdentifier}`, {
|
|
65
|
+
cause: error,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
}
|
package/src/prompts/index.ts
CHANGED
|
@@ -322,7 +322,8 @@ interface AcceptanceBar {
|
|
|
322
322
|
* reused as a per-run heuristic (the suite-level acceptance block still reports
|
|
323
323
|
* the true aggregate verdict). `passRate` criteria decide passing with an
|
|
324
324
|
* arbitrary `passFn` predicate — there is no static numeric bar to highlight
|
|
325
|
-
* against — so
|
|
325
|
+
* against — so those annotations are ignored for per-run misses when any
|
|
326
|
+
* `average` bar exists.
|
|
326
327
|
*/
|
|
327
328
|
function buildAcceptanceBars(suite: SuiteSummary): Map<string, AcceptanceBar> {
|
|
328
329
|
const bars = new Map<string, AcceptanceBar>();
|
|
@@ -339,13 +340,22 @@ function buildAcceptanceBars(suite: SuiteSummary): Map<string, AcceptanceBar> {
|
|
|
339
340
|
/**
|
|
340
341
|
* Whether a passing test's evaluator scores fall short. When maximizing, a
|
|
341
342
|
* boolean `false` or a numeric score below its bar is a miss; when minimizing,
|
|
342
|
-
* a boolean `true` or a score above its bar is a miss.
|
|
343
|
-
*
|
|
343
|
+
* a boolean `true` or a score above its bar is a miss.
|
|
344
|
+
*
|
|
345
|
+
* When the suite has `average` acceptance criteria, only those gated
|
|
346
|
+
* annotations decide per-run misses. That way a minimize metric whose desired
|
|
347
|
+
* value is 0 (e.g. `no_pii_detected`) is not listed as a miss on a correctly
|
|
348
|
+
* classified row. With no average criterion, a non-positive score still counts
|
|
349
|
+
* (keeps zero-config suites quiet).
|
|
344
350
|
*/
|
|
345
351
|
function isMiss(result: TestResult, bars: Map<string, AcceptanceBar>): boolean {
|
|
352
|
+
const hasAverageBars = bars.size > 0;
|
|
346
353
|
for (const ann of result.annotations) {
|
|
347
354
|
if (ann.name === "pass") continue;
|
|
348
355
|
const acceptanceBar = bars.get(ann.name);
|
|
356
|
+
if (hasAverageBars && acceptanceBar === undefined) {
|
|
357
|
+
continue;
|
|
358
|
+
}
|
|
349
359
|
const minimizing = acceptanceBar?.direction === "minimize";
|
|
350
360
|
if (typeof ann.score === "boolean") {
|
|
351
361
|
if (minimizing ? ann.score : !ann.score) return true;
|
package/src/traces/getTraces.ts
CHANGED
|
@@ -22,7 +22,7 @@ export interface GetTracesParams extends ClientFn {
|
|
|
22
22
|
order?: "asc" | "desc";
|
|
23
23
|
/** Maximum number of traces to return */
|
|
24
24
|
limit?: number;
|
|
25
|
-
/** Pagination cursor
|
|
25
|
+
/** Pagination cursor */
|
|
26
26
|
cursor?: string | null;
|
|
27
27
|
/** If true, include full span details for each trace */
|
|
28
28
|
includeSpans?: boolean;
|
package/src/traces/index.ts
CHANGED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { createClient } from "../client";
|
|
2
|
+
import { TRANSFER_TRACES } from "../constants/serverRequirements";
|
|
3
|
+
import type { ClientFn } from "../types/core";
|
|
4
|
+
import { ensureServerCapability } from "../utils/serverVersionUtils";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Parameters for moving traces to another project.
|
|
8
|
+
*/
|
|
9
|
+
export interface TransferTracesParams extends ClientFn {
|
|
10
|
+
/**
|
|
11
|
+
* Trace GlobalIDs or OpenTelemetry trace IDs to move. All traces must
|
|
12
|
+
* currently belong to the same source project.
|
|
13
|
+
*/
|
|
14
|
+
traceIdentifiers: string[];
|
|
15
|
+
/**
|
|
16
|
+
* The destination project name or GlobalID.
|
|
17
|
+
*/
|
|
18
|
+
destinationProjectIdentifier: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The result of moving traces to another project.
|
|
23
|
+
*/
|
|
24
|
+
export interface TransferTracesResult {
|
|
25
|
+
/** The number of distinct traces moved. */
|
|
26
|
+
transferredTraceCount: number;
|
|
27
|
+
/** The destination project's GlobalID. */
|
|
28
|
+
destinationProjectId: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Move traces from one project to another.
|
|
33
|
+
*
|
|
34
|
+
* This operation re-parents the traces; it does not copy them. After the move,
|
|
35
|
+
* the traces no longer appear in their original project. Every trace must
|
|
36
|
+
* currently belong to the same source project.
|
|
37
|
+
*
|
|
38
|
+
* @param params - The parameters for moving traces.
|
|
39
|
+
* @param params.traceIdentifiers - Trace GlobalIDs or OpenTelemetry trace IDs to move.
|
|
40
|
+
* @param params.destinationProjectIdentifier - The destination project name or GlobalID.
|
|
41
|
+
* @returns The number of traces moved and the destination project's GlobalID.
|
|
42
|
+
* @throws {RangeError} If no trace identifiers are provided.
|
|
43
|
+
* @throws {HttpError} If a trace or destination project is missing, the traces
|
|
44
|
+
* belong to multiple source projects, or the transfer otherwise fails.
|
|
45
|
+
*
|
|
46
|
+
* @requires Phoenix server >= 20.4.0
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { transferTraces } from "@arizeai/phoenix-client/traces";
|
|
51
|
+
*
|
|
52
|
+
* const result = await transferTraces({
|
|
53
|
+
* traceIdentifiers: ["8f3a...", "VHJhY2U6Mg=="],
|
|
54
|
+
* destinationProjectIdentifier: "production",
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* console.log(result.transferredTraceCount);
|
|
58
|
+
* console.log(result.destinationProjectId);
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export async function transferTraces({
|
|
62
|
+
client: _client,
|
|
63
|
+
traceIdentifiers,
|
|
64
|
+
destinationProjectIdentifier,
|
|
65
|
+
}: TransferTracesParams): Promise<TransferTracesResult> {
|
|
66
|
+
if (traceIdentifiers.length === 0) {
|
|
67
|
+
throw new RangeError("At least one trace identifier is required");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const client = _client ?? createClient();
|
|
71
|
+
await ensureServerCapability({ client, requirement: TRANSFER_TRACES });
|
|
72
|
+
|
|
73
|
+
const { data, error } = await client.POST("/v1/traces/transfer", {
|
|
74
|
+
body: {
|
|
75
|
+
trace_identifiers: traceIdentifiers,
|
|
76
|
+
destination_project_identifier: destinationProjectIdentifier,
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
if (error) throw error;
|
|
81
|
+
if (!data?.data) {
|
|
82
|
+
throw new Error("Failed to transfer traces: no data returned");
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
transferredTraceCount: data.data.transferred_trace_count,
|
|
87
|
+
destinationProjectId: data.data.destination_project_id,
|
|
88
|
+
};
|
|
89
|
+
}
|
package/src/types/prompts.ts
CHANGED
|
@@ -75,6 +75,16 @@ export type PromptSelector =
|
|
|
75
75
|
| GetPromptByVersionSelector
|
|
76
76
|
| GetPromptByTagSelector;
|
|
77
77
|
|
|
78
|
+
/**
|
|
79
|
+
* A selector for a prompt as a whole, rather than for one of its versions.
|
|
80
|
+
*
|
|
81
|
+
* Narrower than {@link PromptSelector}: a version id or a name + tag picks out a
|
|
82
|
+
* single version, which is not what operations on the prompt itself act on. Use
|
|
83
|
+
* this wherever the API needs the `{prompt_identifier}` path segment — the name
|
|
84
|
+
* and the prompt id are the two things the Phoenix REST API accepts there.
|
|
85
|
+
*/
|
|
86
|
+
export type PromptIdentifier = GetPromptByIdSelector | GetPromptByNameSelector;
|
|
87
|
+
|
|
78
88
|
/**
|
|
79
89
|
* The prompt data needed to create a prompt.
|
|
80
90
|
*/
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
|
|
7
|
+
/** The user profile returned for the current Phoenix client credentials. */
|
|
8
|
+
export type CurrentUser =
|
|
9
|
+
components["schemas"]["GetViewerResponseBody"]["data"];
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Get the currently authenticated user.
|
|
13
|
+
*
|
|
14
|
+
* When authentication is disabled, Phoenix returns an anonymous user with
|
|
15
|
+
* `auth_method: "ANONYMOUS"`.
|
|
16
|
+
*
|
|
17
|
+
* @param params - The parameters for fetching the current user.
|
|
18
|
+
* @param params.client - An optional Phoenix client instance.
|
|
19
|
+
* @returns The current user's generated API profile shape.
|
|
20
|
+
* @throws {HttpError} If the request is not authenticated or is forbidden.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { getCurrentUser } from "@arizeai/phoenix-client/users";
|
|
25
|
+
*
|
|
26
|
+
* const user = await getCurrentUser();
|
|
27
|
+
* console.log(user.auth_method);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export async function getCurrentUser({
|
|
31
|
+
client: _client,
|
|
32
|
+
}: ClientFn = {}): Promise<CurrentUser> {
|
|
33
|
+
const client = _client ?? createClient();
|
|
34
|
+
const { data, error } = await client.GET("/v1/user");
|
|
35
|
+
|
|
36
|
+
if (error) throw error;
|
|
37
|
+
invariant(data?.data, "Failed to get current user");
|
|
38
|
+
return data.data;
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./getCurrentUser";
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { PromptIdentifier } from "../types/prompts";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Resolve a prompt-level selector to the `{prompt_identifier}` path segment the
|
|
5
|
+
* Phoenix REST API expects.
|
|
6
|
+
*
|
|
7
|
+
* Version-level selectors are rejected rather than silently widened: structural
|
|
8
|
+
* typing lets a `{ name, tag }` or `{ versionId }` value reach a
|
|
9
|
+
* {@link PromptIdentifier} parameter, and quietly dropping the version would
|
|
10
|
+
* point the caller at the whole prompt instead of the version they named.
|
|
11
|
+
*
|
|
12
|
+
* @param prompt - the prompt, selected by `name` or by `promptId`
|
|
13
|
+
* @returns The identifier to interpolate into the request path.
|
|
14
|
+
* @throws An error if the selector is empty, or selects a version rather than a
|
|
15
|
+
* prompt.
|
|
16
|
+
*/
|
|
17
|
+
export function resolvePromptIdentifier(prompt: PromptIdentifier): string {
|
|
18
|
+
if ("versionId" in prompt) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
"A prompt version id selects a single version, not a prompt. Select the prompt by name or promptId."
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
if ("tag" in prompt) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
"A tag selects a single version, not a prompt. Select the prompt by name or promptId."
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
if ("promptId" in prompt) {
|
|
29
|
+
if (!prompt.promptId) {
|
|
30
|
+
throw new Error("promptId must be a non-empty prompt id.");
|
|
31
|
+
}
|
|
32
|
+
return prompt.promptId;
|
|
33
|
+
}
|
|
34
|
+
if ("name" in prompt) {
|
|
35
|
+
if (!prompt.name) {
|
|
36
|
+
throw new Error("name must be a non-empty prompt name.");
|
|
37
|
+
}
|
|
38
|
+
return prompt.name;
|
|
39
|
+
}
|
|
40
|
+
throw new Error("A prompt must be selected by either name or promptId.");
|
|
41
|
+
}
|