@arizeai/phoenix-client 7.5.0 → 7.6.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 (60) hide show
  1. package/CHANGELOG.md +769 -0
  2. package/dist/esm/__generated__/api/v1.d.ts +748 -202
  3. package/dist/esm/__generated__/api/v1.d.ts.map +1 -1
  4. package/dist/esm/constants/serverRequirements.d.ts +1 -0
  5. package/dist/esm/constants/serverRequirements.d.ts.map +1 -1
  6. package/dist/esm/constants/serverRequirements.js +7 -0
  7. package/dist/esm/constants/serverRequirements.js.map +1 -1
  8. package/dist/esm/prompts/deletePrompt.d.ts +39 -0
  9. package/dist/esm/prompts/deletePrompt.d.ts.map +1 -0
  10. package/dist/esm/prompts/deletePrompt.js +52 -0
  11. package/dist/esm/prompts/deletePrompt.js.map +1 -0
  12. package/dist/esm/prompts/index.d.ts +1 -0
  13. package/dist/esm/prompts/index.d.ts.map +1 -1
  14. package/dist/esm/prompts/index.js +1 -0
  15. package/dist/esm/prompts/index.js.map +1 -1
  16. package/dist/esm/testing/reporter-format.d.ts.map +1 -1
  17. package/dist/esm/testing/reporter-format.js +13 -3
  18. package/dist/esm/testing/reporter-format.js.map +1 -1
  19. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  20. package/dist/esm/types/prompts.d.ts +9 -0
  21. package/dist/esm/types/prompts.d.ts.map +1 -1
  22. package/dist/esm/types/prompts.js.map +1 -1
  23. package/dist/esm/utils/resolvePromptIdentifier.d.ts +17 -0
  24. package/dist/esm/utils/resolvePromptIdentifier.d.ts.map +1 -0
  25. package/dist/esm/utils/resolvePromptIdentifier.js +36 -0
  26. package/dist/esm/utils/resolvePromptIdentifier.js.map +1 -0
  27. package/dist/src/__generated__/api/v1.d.ts +748 -202
  28. package/dist/src/__generated__/api/v1.d.ts.map +1 -1
  29. package/dist/src/constants/serverRequirements.d.ts +1 -0
  30. package/dist/src/constants/serverRequirements.d.ts.map +1 -1
  31. package/dist/src/constants/serverRequirements.js +8 -1
  32. package/dist/src/constants/serverRequirements.js.map +1 -1
  33. package/dist/src/prompts/deletePrompt.d.ts +39 -0
  34. package/dist/src/prompts/deletePrompt.d.ts.map +1 -0
  35. package/dist/src/prompts/deletePrompt.js +55 -0
  36. package/dist/src/prompts/deletePrompt.js.map +1 -0
  37. package/dist/src/prompts/index.d.ts +1 -0
  38. package/dist/src/prompts/index.d.ts.map +1 -1
  39. package/dist/src/prompts/index.js +1 -0
  40. package/dist/src/prompts/index.js.map +1 -1
  41. package/dist/src/testing/reporter-format.d.ts.map +1 -1
  42. package/dist/src/testing/reporter-format.js +13 -3
  43. package/dist/src/testing/reporter-format.js.map +1 -1
  44. package/dist/src/types/prompts.d.ts +9 -0
  45. package/dist/src/types/prompts.d.ts.map +1 -1
  46. package/dist/src/types/prompts.js.map +1 -1
  47. package/dist/src/utils/resolvePromptIdentifier.d.ts +17 -0
  48. package/dist/src/utils/resolvePromptIdentifier.d.ts.map +1 -0
  49. package/dist/src/utils/resolvePromptIdentifier.js +39 -0
  50. package/dist/src/utils/resolvePromptIdentifier.js.map +1 -0
  51. package/dist/tsconfig.tsbuildinfo +1 -1
  52. package/docs/prompts.mdx +19 -1
  53. package/package.json +11 -11
  54. package/src/__generated__/api/v1.ts +748 -202
  55. package/src/constants/serverRequirements.ts +8 -0
  56. package/src/prompts/deletePrompt.ts +70 -0
  57. package/src/prompts/index.ts +1 -0
  58. package/src/testing/reporter-format.ts +13 -3
  59. package/src/types/prompts.ts +10 -0
  60. package/src/utils/resolvePromptIdentifier.ts +41 -0
@@ -138,6 +138,13 @@ export const ADD_SESSION_NOTE_IDENTIFIER: ParameterRequirement = {
138
138
  minServerVersion: [15, 5, 0],
139
139
  };
140
140
 
141
+ export const DELETE_PROMPT: RouteRequirement = {
142
+ kind: "route",
143
+ method: "DELETE",
144
+ path: "/v1/prompts/{prompt_identifier}",
145
+ minServerVersion: [13, 20, 0],
146
+ };
147
+
141
148
  export const PATCH_PROMPT: RouteRequirement = {
142
149
  kind: "route",
143
150
  method: "PATCH",
@@ -224,6 +231,7 @@ export const ALL_REQUIREMENTS: readonly CapabilityRequirement[] = [
224
231
  ADD_TRACE_NOTE_IDENTIFIER,
225
232
  ADD_SPAN_NOTE_IDENTIFIER,
226
233
  ADD_SESSION_NOTE_IDENTIFIER,
234
+ DELETE_PROMPT,
227
235
  PATCH_PROMPT,
228
236
  AGENT_SESSION_CREATE,
229
237
  AGENT_SESSION_LIST,
@@ -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
+ }
@@ -1,5 +1,6 @@
1
1
  export * from "./getPrompt";
2
2
  export * from "./createPrompt";
3
+ export * from "./deletePrompt";
3
4
  export * from "./listPrompts";
4
5
  export * from "./updatePrompt";
5
6
  export * from "./sdks";
@@ -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 their rows fall back to the default miss heuristic.
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. With no criterion for an
343
- * annotation, only a non-positive score counts (keeps zero-config suites quiet).
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;
@@ -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,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
+ }