@arizeai/phoenix-cli 1.3.1 → 1.4.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.
Files changed (69) hide show
  1. package/README.md +99 -13
  2. package/build/banner.d.ts.map +1 -1
  3. package/build/banner.js +11 -2
  4. package/build/banner.js.map +1 -1
  5. package/build/cli.d.ts.map +1 -1
  6. package/build/cli.js +2 -1
  7. package/build/cli.js.map +1 -1
  8. package/build/commands/annotationMutationUtils.d.ts +1 -1
  9. package/build/commands/annotationMutationUtils.d.ts.map +1 -1
  10. package/build/commands/annotationMutationUtils.js +13 -1
  11. package/build/commands/annotationMutationUtils.js.map +1 -1
  12. package/build/commands/auth.d.ts +1 -1
  13. package/build/commands/auth.d.ts.map +1 -1
  14. package/build/commands/auth.js +31 -9
  15. package/build/commands/auth.js.map +1 -1
  16. package/build/commands/chunkArray.d.ts +5 -0
  17. package/build/commands/chunkArray.d.ts.map +1 -0
  18. package/build/commands/chunkArray.js +8 -0
  19. package/build/commands/chunkArray.js.map +1 -0
  20. package/build/commands/formatProfiles.d.ts +40 -0
  21. package/build/commands/formatProfiles.d.ts.map +1 -0
  22. package/build/commands/formatProfiles.js +53 -0
  23. package/build/commands/formatProfiles.js.map +1 -0
  24. package/build/commands/formatSessions.d.ts +17 -5
  25. package/build/commands/formatSessions.d.ts.map +1 -1
  26. package/build/commands/formatSessions.js +52 -10
  27. package/build/commands/formatSessions.js.map +1 -1
  28. package/build/commands/formatSpans.d.ts +3 -1
  29. package/build/commands/formatSpans.d.ts.map +1 -1
  30. package/build/commands/formatSpans.js +8 -7
  31. package/build/commands/formatSpans.js.map +1 -1
  32. package/build/commands/index.d.ts +1 -0
  33. package/build/commands/index.d.ts.map +1 -1
  34. package/build/commands/index.js +1 -0
  35. package/build/commands/index.js.map +1 -1
  36. package/build/commands/noteMutationUtils.d.ts +1 -1
  37. package/build/commands/noteMutationUtils.d.ts.map +1 -1
  38. package/build/commands/noteMutationUtils.js +13 -1
  39. package/build/commands/noteMutationUtils.js.map +1 -1
  40. package/build/commands/profile.d.ts +14 -0
  41. package/build/commands/profile.d.ts.map +1 -0
  42. package/build/commands/profile.js +357 -0
  43. package/build/commands/profile.js.map +1 -0
  44. package/build/commands/session.d.ts +2 -0
  45. package/build/commands/session.d.ts.map +1 -1
  46. package/build/commands/session.js +304 -9
  47. package/build/commands/session.js.map +1 -1
  48. package/build/commands/span.d.ts.map +1 -1
  49. package/build/commands/span.js +6 -1
  50. package/build/commands/span.js.map +1 -1
  51. package/build/commands/spanAnnotations.d.ts.map +1 -1
  52. package/build/commands/spanAnnotations.js +7 -10
  53. package/build/commands/spanAnnotations.js.map +1 -1
  54. package/build/commands/traceAnnotations.d.ts.map +1 -1
  55. package/build/commands/traceAnnotations.js +7 -10
  56. package/build/commands/traceAnnotations.js.map +1 -1
  57. package/build/config.d.ts +39 -4
  58. package/build/config.d.ts.map +1 -1
  59. package/build/config.js +73 -5
  60. package/build/config.js.map +1 -1
  61. package/build/exitCodes.d.ts +5 -3
  62. package/build/exitCodes.d.ts.map +1 -1
  63. package/build/exitCodes.js +5 -3
  64. package/build/exitCodes.js.map +1 -1
  65. package/build/settings.d.ts +113 -5
  66. package/build/settings.d.ts.map +1 -1
  67. package/build/settings.js +263 -5
  68. package/build/settings.js.map +1 -1
  69. package/package.json +4 -4
@@ -1,13 +1,7 @@
1
+ import { chunkArray } from "./chunkArray.js";
1
2
  const DEFAULT_PAGE_LIMIT = 1000;
2
3
  const DEFAULT_TRACE_IDS_CHUNK_SIZE = 100;
3
4
  const DEFAULT_MAX_CONCURRENT = 5;
4
- function chunkArray(items, size) {
5
- const chunks = [];
6
- for (let i = 0; i < items.length; i += size) {
7
- chunks.push(items.slice(i, i + size));
8
- }
9
- return chunks;
10
- }
11
5
  async function fetchTraceAnnotationsForChunk({ client, projectIdentifier, traceIds, includeAnnotationNames, excludeAnnotationNames, pageLimit, }) {
12
6
  const annotations = [];
13
7
  let cursor;
@@ -39,10 +33,13 @@ export async function fetchTraceAnnotations({ client, projectIdentifier, traceId
39
33
  return [];
40
34
  }
41
35
  const uniqueTraceIds = Array.from(new Set(traceIds));
42
- const chunks = chunkArray(uniqueTraceIds, DEFAULT_TRACE_IDS_CHUNK_SIZE);
36
+ const chunks = chunkArray({
37
+ items: uniqueTraceIds,
38
+ size: DEFAULT_TRACE_IDS_CHUNK_SIZE,
39
+ });
43
40
  const allAnnotations = [];
44
- for (let i = 0; i < chunks.length; i += maxConcurrent) {
45
- const batch = chunks.slice(i, i + maxConcurrent);
41
+ for (let index = 0; index < chunks.length; index += maxConcurrent) {
42
+ const batch = chunks.slice(index, index + maxConcurrent);
46
43
  const batchResults = await Promise.all(batch.map((traceIdsChunk) => fetchTraceAnnotationsForChunk({
47
44
  client,
48
45
  projectIdentifier,
@@ -1 +1 @@
1
- {"version":3,"file":"traceAnnotations.js","sourceRoot":"","sources":["../../src/commands/traceAnnotations.ts"],"names":[],"mappings":"AAIA,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAChC,MAAM,4BAA4B,GAAG,GAAG,CAAC;AACzC,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAYjC,SAAS,UAAU,CAAI,KAAU,EAAE,IAAY;IAC7C,MAAM,MAAM,GAAU,EAAE,CAAC;IACzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC;QAC5C,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;IACxC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,KAAK,UAAU,6BAA6B,CAAC,EAC3C,MAAM,EACN,iBAAiB,EACjB,QAAQ,EACR,sBAAsB,EACtB,sBAAsB,EACtB,SAAS,GAQV;IACC,MAAM,WAAW,GAAsB,EAAE,CAAC;IAC1C,IAAI,MAA0B,CAAC;IAE/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GAAG,CAAC,CAAC,aAAa,EAAE,EAAE,CAC1B,6BAA6B,CAAC;YAC5B,MAAM;YACN,iBAAiB;YACjB,QAAQ,EAAE,aAAa;YACvB,sBAAsB;YACtB,sBAAsB;YACtB,SAAS;SACV,CAAC,CACH,CACF,CAAC;QAEF,KAAK,MAAM,MAAM,IAAI,YAAY,EAAE,CAAC;YAClC,cAAc,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC;QACjC,CAAC;IACH,CAAC;IAED,OAAO,cAAc,CAAC;AACxB,CAAC"}
package/build/config.d.ts CHANGED
@@ -24,24 +24,59 @@ export interface PhoenixConfig {
24
24
  headers?: Record<string, string>;
25
25
  }
26
26
  /**
27
- * Load configuration from environment variables
27
+ * Returns built-in defaults. These are the lowest-priority tier and should
28
+ * be applied first so that any explicitly configured source can override them.
29
+ */
30
+ export declare function getBuiltInDefaults(): PhoenixConfig;
31
+ /**
32
+ * Load configuration from environment variables.
33
+ * Only returns values that are explicitly set in the environment — built-in
34
+ * defaults are NOT included, so callers can apply them at the correct tier.
28
35
  */
29
36
  export declare function loadConfigFromEnvironment(): PhoenixConfig;
37
+ /**
38
+ * Load configuration from the active named profile.
39
+ *
40
+ * Resolution order for the profile name:
41
+ * 1. `profileName` argument (from --profile CLI flag)
42
+ * 2. `activeProfile` field in the settings file
43
+ *
44
+ * Uses forgiving mode for the settings file itself — a missing or corrupt
45
+ * file returns an empty config so unrelated commands are never blocked.
46
+ *
47
+ * When a profile is explicitly requested (via `profileName`) but does not
48
+ * resolve to an existing entry, throws `ProfileResolutionError` — silently
49
+ * falling back to defaults could point the user at the wrong Phoenix
50
+ * instance.
51
+ *
52
+ * Returns an empty config only when no profile is explicitly requested and
53
+ * no stored `activeProfile` resolves (silent fallthrough to env / defaults).
54
+ */
55
+ export declare function loadConfigFromProfile(profileName?: string): PhoenixConfig;
30
56
  /**
31
57
  * Resolve configuration from supported sources
32
- * Priority: CLI flags > Environment variables
58
+ * Priority: CLI flags > Environment variables > Active profile > Built-in defaults
33
59
  */
34
60
  export interface ResolveConfigOptions {
35
61
  /**
36
62
  * CLI-provided config values (typically from Commander). `undefined` values are ignored.
37
63
  */
38
64
  cliOptions: Partial<PhoenixConfig>;
65
+ /**
66
+ * Explicit profile name (from --profile flag). When provided, overrides
67
+ * the activeProfile stored in the settings file.
68
+ */
69
+ profileName?: string;
39
70
  }
40
71
  /**
41
72
  * Resolve configuration from supported sources.
42
- * Priority: CLI flags > Environment variables.
73
+ * Priority (highest to lowest):
74
+ * 1. CLI flags
75
+ * 2. Explicitly set environment variables
76
+ * 3. Active profile (from --profile or settings file)
77
+ * 4. Built-in defaults
43
78
  */
44
- export declare function resolveConfig({ cliOptions, }: ResolveConfigOptions): PhoenixConfig;
79
+ export declare function resolveConfig({ cliOptions, profileName, }: ResolveConfigOptions): PhoenixConfig;
45
80
  /**
46
81
  * Validate that required configuration is present
47
82
  */
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,eAAO,MAAM,wBAAwB,0BAA0B,CAAC;AAEhE;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED;;GAEG;AACH,wBAAgB,yBAAyB,IAAI,aAAa,CA2BzD;AAED;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,UAAU,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;CACpC;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,EAC5B,UAAU,GACX,EAAE,oBAAoB,GAAG,aAAa,CAatC;AAED;;GAEG;AACH,MAAM,WAA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;;GAOG;AACH,wBAAgB,aAAa,CAAC,EAC5B,UAAU,EACV,WAAW,GACZ,EAAE,oBAAoB,GAAG,aAAa,CAiBtC;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,MAAM,EAAE,aAAa,CAAC;IACtB;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,EAC7B,MAAM,EACN,eAAsB,GACvB,EAAE,qBAAqB,GAAG;IACzB,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAkBA;AAED;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C;;OAEG;IACH,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,MAAM,GACP,EAAE,4BAA4B,GAAG,MAAM,CAiBvC"}
package/build/config.js CHANGED
@@ -1,15 +1,25 @@
1
1
  import { ENV_PHOENIX_API_KEY, ENV_PHOENIX_CLIENT_HEADERS, ENV_PHOENIX_HOST, getHeadersFromEnvironment, getStrFromEnvironment, } from "@arizeai/phoenix-config";
2
+ import { getProfileByName, getStoredActiveProfile, loadSettings, ProfileResolutionError, } from "./settings.js";
2
3
  /**
3
4
  * Default Phoenix endpoint used when PHOENIX_HOST is not set.
4
5
  */
5
6
  export const DEFAULT_PHOENIX_ENDPOINT = "http://localhost:6006";
6
7
  /**
7
- * Load configuration from environment variables
8
+ * Returns built-in defaults. These are the lowest-priority tier and should
9
+ * be applied first so that any explicitly configured source can override them.
8
10
  */
9
- export function loadConfigFromEnvironment() {
10
- const config = {
11
+ export function getBuiltInDefaults() {
12
+ return {
11
13
  endpoint: DEFAULT_PHOENIX_ENDPOINT,
12
14
  };
15
+ }
16
+ /**
17
+ * Load configuration from environment variables.
18
+ * Only returns values that are explicitly set in the environment — built-in
19
+ * defaults are NOT included, so callers can apply them at the correct tier.
20
+ */
21
+ export function loadConfigFromEnvironment() {
22
+ const config = {};
13
23
  const endpoint = getStrFromEnvironment(ENV_PHOENIX_HOST);
14
24
  if (endpoint) {
15
25
  config.endpoint = endpoint;
@@ -29,16 +39,74 @@ export function loadConfigFromEnvironment() {
29
39
  }
30
40
  return config;
31
41
  }
42
+ /**
43
+ * Load configuration from the active named profile.
44
+ *
45
+ * Resolution order for the profile name:
46
+ * 1. `profileName` argument (from --profile CLI flag)
47
+ * 2. `activeProfile` field in the settings file
48
+ *
49
+ * Uses forgiving mode for the settings file itself — a missing or corrupt
50
+ * file returns an empty config so unrelated commands are never blocked.
51
+ *
52
+ * When a profile is explicitly requested (via `profileName`) but does not
53
+ * resolve to an existing entry, throws `ProfileResolutionError` — silently
54
+ * falling back to defaults could point the user at the wrong Phoenix
55
+ * instance.
56
+ *
57
+ * Returns an empty config only when no profile is explicitly requested and
58
+ * no stored `activeProfile` resolves (silent fallthrough to env / defaults).
59
+ */
60
+ export function loadConfigFromProfile(profileName) {
61
+ const settingsFile = loadSettings();
62
+ if (profileName !== undefined) {
63
+ const active = getProfileByName(settingsFile, profileName);
64
+ if (!active) {
65
+ throw new ProfileResolutionError(`Profile "${profileName}" (from --profile) does not exist. Run \`px profile list\` to see available profiles.`);
66
+ }
67
+ return profileEntryToConfig(active.entry);
68
+ }
69
+ const active = getStoredActiveProfile(settingsFile);
70
+ if (!active) {
71
+ return {};
72
+ }
73
+ return profileEntryToConfig(active.entry);
74
+ }
75
+ /**
76
+ * Project a `ProfileEntry` onto the `PhoenixConfig` shape. Skipped fields
77
+ * (e.g. an apiKey set on a different profile) are simply omitted so the
78
+ * downstream merge in `resolveConfig` can layer env vars / defaults on top.
79
+ */
80
+ function profileEntryToConfig(entry) {
81
+ const config = {};
82
+ if (entry.endpoint)
83
+ config.endpoint = entry.endpoint;
84
+ if (entry.apiKey)
85
+ config.apiKey = entry.apiKey;
86
+ if (entry.project)
87
+ config.project = entry.project;
88
+ if (entry.headers)
89
+ config.headers = entry.headers;
90
+ return config;
91
+ }
32
92
  /**
33
93
  * Resolve configuration from supported sources.
34
- * Priority: CLI flags > Environment variables.
94
+ * Priority (highest to lowest):
95
+ * 1. CLI flags
96
+ * 2. Explicitly set environment variables
97
+ * 3. Active profile (from --profile or settings file)
98
+ * 4. Built-in defaults
35
99
  */
36
- export function resolveConfig({ cliOptions, }) {
100
+ export function resolveConfig({ cliOptions, profileName, }) {
101
+ const builtInDefaults = getBuiltInDefaults();
102
+ const profileConfig = loadConfigFromProfile(profileName);
37
103
  const envConfig = loadConfigFromEnvironment();
38
104
  // Commander (and other callers) may include keys with `undefined` values.
39
105
  // If we spread those over envConfig we would accidentally clobber env vars.
40
106
  const definedCliOptions = Object.fromEntries(Object.entries(cliOptions).filter(([, value]) => value !== undefined));
41
107
  return {
108
+ ...builtInDefaults,
109
+ ...profileConfig,
42
110
  ...envConfig,
43
111
  ...definedCliOptions,
44
112
  };
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,0BAA0B,EAC1B,gBAAgB,EAChB,yBAAyB,EACzB,qBAAqB,GACtB,MAAM,yBAAyB,CAAC;AAEjC;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,uBAAuB,CAAC;AA2BhE;;GAEG;AACH,MAAM,UAAU,yBAAyB;IACvC,MAAM,MAAM,GAAkB;QAC5B,QAAQ,EAAE,wBAAwB;KACnC,CAAC;IAEF,MAAM,QAAQ,GAAG,qBAAqB,CAAC,gBAAgB,CAAC,CAAC;IACzD,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;IAED,MAAM,MAAM,GAAG,qBAAqB,CAAC,mBAAmB,CAAC,CAAC;IAC1D,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED,MAAM,OA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G,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;QAChC,EAAE;QACF,cAAc;QACd,iCAAiC;QACjC,gDAAgD;QAChD,EAAE;QACF,6BAA6B;QAC7B,wCAAwC;QACxC,EAAE;QACF,mBAAmB;QACnB,uEAAuE;KACxE,CAAC;IACF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
@@ -35,9 +35,11 @@ export declare class InvalidArgumentError extends Error {
35
35
  /**
36
36
  * Infer a semantic exit code from an unknown error value.
37
37
  *
38
- * The Fetch API throws a `TypeError` for low-level network failures such as
39
- * connection refused or DNS resolution errors. All other errors fall back to
40
- * the general {@link ExitCode.FAILURE} code.
38
+ * - `InvalidArgumentError` (and subclasses like `ProfileResolutionError`)
39
+ * map to INVALID_ARGUMENT.
40
+ * - The Fetch API throws a `TypeError` for low-level network failures such
41
+ * as connection refused or DNS resolution errors.
42
+ * - All other errors fall back to the general {@link ExitCode.FAILURE} code.
41
43
  */
42
44
  export declare function getExitCodeForError(error: unknown): ExitCode;
43
45
  //# sourceMappingURL=exitCodes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"exitCodes.d.ts","sourceRoot":"","sources":["../src/exitCodes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,QAAQ;IACnB,qCAAqC;;IAErC,sCAAsC;;IAEtC,mCAAmC;;IAEnC,6DAA6D;;IAE7D,oDAAoD;;IAEpD,4DAA4D;;CAEpD,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,QAAQ,CAAC,CAAC,MAAM,OAAO,QAAQ,CAAC,CAAC;AAEhE,qBAAa,oBAAqB,SAAQ,KAAK;gBACjC,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ,CAW5D"}
1
+ {"version":3,"file":"exitCodes.d.ts","sourceRoot":"","sources":["../src/exitCodes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,QAAQ;IACnB,qCAAqC;;IAErC,sCAAsC;;IAEtC,mCAAmC;;IAEnC,6DAA6D;;IAE7D,oDAAoD;;IAEpD,4DAA4D;;CAEpD,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,QAAQ,CAAC,CAAC,MAAM,OAAO,QAAQ,CAAC,CAAC;AAEhE,qBAAa,oBAAqB,SAAQ,KAAK;gBACjC,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ,CAW5D"}
@@ -37,9 +37,11 @@ export class InvalidArgumentError extends Error {
37
37
  /**
38
38
  * Infer a semantic exit code from an unknown error value.
39
39
  *
40
- * The Fetch API throws a `TypeError` for low-level network failures such as
41
- * connection refused or DNS resolution errors. All other errors fall back to
42
- * the general {@link ExitCode.FAILURE} code.
40
+ * - `InvalidArgumentError` (and subclasses like `ProfileResolutionError`)
41
+ * map to INVALID_ARGUMENT.
42
+ * - The Fetch API throws a `TypeError` for low-level network failures such
43
+ * as connection refused or DNS resolution errors.
44
+ * - All other errors fall back to the general {@link ExitCode.FAILURE} code.
43
45
  */
44
46
  export function getExitCodeForError(error) {
45
47
  if (error instanceof InvalidArgumentError) {
@@ -1 +1 @@
1
- {"version":3,"file":"exitCodes.js","sourceRoot":"","sources":["../src/exitCodes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,qCAAqC;IACrC,OAAO,EAAE,CAAC;IACV,sCAAsC;IACtC,OAAO,EAAE,CAAC;IACV,mCAAmC;IACnC,SAAS,EAAE,CAAC;IACZ,6DAA6D;IAC7D,gBAAgB,EAAE,CAAC;IACnB,oDAAoD;IACpD,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CAAC;IAED,kEAAkE;IAClE,8CAA8C;IAC9C,IAAI,KAAK,YAAY,SAAS,EAAE,CAAC;QAC/B,OAAO,QAAQ,CAAC,aAAa,CAAC;IAChC,CAAC;IACD,OAAO,QAAQ,CAAC,OAAO,CAAC;AAC1B,CAAC"}
@@ -1,13 +1,13 @@
1
1
  /**
2
- * Settings storage schema definitions for the Phoenix CLI.
2
+ * Settings storage schema definitions and runtime I/O for the Phoenix CLI.
3
3
  *
4
- * This module exports the Zod schemas and inferred TypeScript types that
5
- * describe the on-disk settings file (`~/.px/settings.json`). Runtime I/O,
6
- * parsing, and profile resolution logic live alongside the CLI commands
7
- * that consume them; this file is the canonical source for
4
+ * The Zod schemas in this file are the canonical source for
8
5
  * `schemas/phoenix-cli-settings.json` (emitted by `scripts/build-schema.ts`).
6
+ * Runtime I/O (path resolution, file read/write, profile lookup) also lives
7
+ * here so the module name matches the on-disk file (`settings.json`).
9
8
  */
10
9
  import { z } from "zod";
10
+ import { InvalidArgumentError } from "./exitCodes.js";
11
11
  export declare const ProfileEntrySchema: z.ZodObject<{
12
12
  endpoint: z.ZodOptional<z.ZodString>;
13
13
  apiKey: z.ZodOptional<z.ZodString>;
@@ -33,4 +33,112 @@ export type ProfileEntry = z.infer<typeof ProfileEntrySchema>;
33
33
  * On-disk schema for the CLI settings file.
34
34
  */
35
35
  export type SettingsFile = z.infer<typeof SettingsFileSchema>;
36
+ /**
37
+ * Typed error thrown by `loadSettings({ strict: true })` when the settings
38
+ * file is malformed or schema-invalid.
39
+ */
40
+ export declare class SettingsFileError extends Error {
41
+ constructor(message: string);
42
+ }
43
+ /**
44
+ * Typed error thrown when an explicitly requested profile (via `--profile`)
45
+ * does not resolve to an existing entry. Extends `InvalidArgumentError` so
46
+ * `getExitCodeForError` maps it to `ExitCode.INVALID_ARGUMENT` automatically.
47
+ */
48
+ export declare class ProfileResolutionError extends InvalidArgumentError {
49
+ constructor(message: string);
50
+ }
51
+ /**
52
+ * Default `$schema` URL written into newly-created settings files so editors
53
+ * (VS Code, JetBrains, etc.) can validate and autocomplete out of the box.
54
+ *
55
+ * Pinned to `main` for now while the schema is still moving. We'll move it
56
+ * to a SchemaStore entry once registered, and at that point this constant
57
+ * becomes the fallback rather than the canonical pointer.
58
+ */
59
+ export declare const DEFAULT_SCHEMA_URL = "https://raw.githubusercontent.com/Arize-ai/phoenix/main/schemas/phoenix-cli-settings.json";
60
+ /**
61
+ * Empty settings state. Used as the forgiving-mode fallback when the file
62
+ * exists but is unreadable or unparseable — see {@link getInitialSettingsFile}
63
+ * for the freshly-created variant that includes `$schema`.
64
+ */
65
+ export declare const DEFAULT_SETTINGS_FILE: SettingsFile;
66
+ /**
67
+ * Settings state used when no file exists yet. Differs from
68
+ * {@link DEFAULT_SETTINGS_FILE} only in that it carries a `$schema` pointer,
69
+ * so the very first `saveSettings` call writes a file editors can validate
70
+ * without users having to add the line themselves. Any subsequent load
71
+ * preserves whatever's already on disk — if a user removes `$schema`, we
72
+ * don't put it back.
73
+ */
74
+ export declare function getInitialSettingsFile(): SettingsFile;
75
+ /**
76
+ * Return true if the profile name contains only alphanumeric characters,
77
+ * hyphens, or underscores. Empty strings and names with whitespace or other
78
+ * special characters are rejected.
79
+ */
80
+ export declare function validateProfileName(name: string): boolean;
81
+ /**
82
+ * Look up a profile entry by name. Returns `undefined` (rather than
83
+ * throwing) when the name does not exist in the profiles record so
84
+ * callers can decide whether a miss is fatal (e.g. an explicit
85
+ * `--profile` flag) or expected (e.g. a stale `activeProfile` pointer).
86
+ *
87
+ * Returns both the name and entry together so callers never need to
88
+ * re-resolve the name separately.
89
+ */
90
+ export declare function getProfileByName(file: SettingsFile, name: string): {
91
+ name: string;
92
+ entry: ProfileEntry;
93
+ } | undefined;
94
+ /**
95
+ * Look up the profile pointed at by `file.activeProfile`. Returns
96
+ * `undefined` when no active profile is set, or when the pointer is
97
+ * stale (the named profile no longer exists). Stale-pointer handling
98
+ * is forgiving by design — callers fall through to env vars / defaults
99
+ * rather than failing.
100
+ */
101
+ export declare function getStoredActiveProfile(file: SettingsFile): {
102
+ name: string;
103
+ entry: ProfileEntry;
104
+ } | undefined;
105
+ /**
106
+ * Return the Phoenix config directory. Respects `XDG_CONFIG_HOME` if set
107
+ * (returns `$XDG_CONFIG_HOME/px`), otherwise falls back to `~/.px`.
108
+ */
109
+ export declare function getConfigDir(): string;
110
+ /**
111
+ * Return the absolute path to the settings config file.
112
+ */
113
+ export declare function getSettingsPath(): string;
114
+ export interface LoadSettingsOptions {
115
+ /** When true, malformed JSON or schema-invalid content throws SettingsFileError. */
116
+ strict?: boolean;
117
+ /** Override the settings file path (used in tests). Defaults to getSettingsPath(). */
118
+ settingsPath?: string;
119
+ }
120
+ /**
121
+ * Load the settings file from disk.
122
+ *
123
+ * - Missing file: returns `getInitialSettingsFile()` — a fresh state that
124
+ * carries `$schema`, so the very first save writes a file editors can
125
+ * validate.
126
+ * - Malformed JSON / schema-invalid, forgiving mode (default): returns
127
+ * `DEFAULT_SETTINGS_FILE` (no `$schema` — we don't want to clobber a user's
128
+ * intentional removal during a forgiving fallback) and writes a warning to
129
+ * stderr.
130
+ * - Malformed JSON / schema-invalid, strict mode: throws `SettingsFileError`.
131
+ */
132
+ export declare function loadSettings(options?: LoadSettingsOptions): SettingsFile;
133
+ export interface SaveSettingsOptions {
134
+ /** Override the settings file path (used in tests). Defaults to getSettingsPath(). */
135
+ settingsPath?: string;
136
+ }
137
+ /**
138
+ * Persist the settings file to disk.
139
+ *
140
+ * Creates the parent directory (and any ancestors) if it does not exist.
141
+ * Writes human-readable JSON with 2-space indentation.
142
+ */
143
+ export declare function saveSettings(data: SettingsFile, options?: SaveSettingsOptions): void;
36
144
  //# sourceMappingURL=settings.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../src/settings.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,kBAA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