@mutagent/cli 0.1.17 → 0.1.19

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/index.js CHANGED
@@ -15,16 +15,6 @@ var __toESM = (mod, isNodeMode, target) => {
15
15
  });
16
16
  return to;
17
17
  };
18
- var __export = (target, all) => {
19
- for (var name in all)
20
- __defProp(target, name, {
21
- get: all[name],
22
- enumerable: true,
23
- configurable: true,
24
- set: (newValue) => all[name] = () => newValue
25
- });
26
- };
27
- var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
28
18
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
29
19
 
30
20
  // src/lib/config.ts
@@ -33,6 +23,23 @@ import { z } from "zod";
33
23
  import { homedir } from "os";
34
24
  import { join } from "path";
35
25
  import { existsSync, readFileSync, writeFileSync, mkdirSync } from "fs";
26
+ var configSchema = z.object({
27
+ apiKey: z.string().optional(),
28
+ endpoint: z.string().default("https://api.mutagent.io"),
29
+ format: z.enum(["table", "json"]).default("table"),
30
+ timeout: z.number().default(30000),
31
+ defaultWorkspace: z.string().optional(),
32
+ defaultOrganization: z.string().optional()
33
+ });
34
+ var credentialsSchema = z.object({
35
+ apiKey: z.string().optional(),
36
+ endpoint: z.string().optional(),
37
+ defaultWorkspace: z.string().optional(),
38
+ defaultOrganization: z.string().optional(),
39
+ expiresAt: z.string().optional()
40
+ }).loose();
41
+ var CREDENTIALS_DIR = join(homedir(), ".config", "mutagent");
42
+ var CREDENTIALS_FILE = join(CREDENTIALS_DIR, "credentials.json");
36
43
  function parseJsonSafe(content, schema) {
37
44
  try {
38
45
  const parsed = JSON.parse(content);
@@ -140,28 +147,78 @@ function setDefaultOrganization(organizationId) {
140
147
  };
141
148
  writeFileSync(CREDENTIALS_FILE, JSON.stringify(updated, null, 2));
142
149
  }
143
- var configSchema, credentialsSchema, CREDENTIALS_DIR, CREDENTIALS_FILE;
144
- var init_config = __esm(() => {
145
- configSchema = z.object({
146
- apiKey: z.string().optional(),
147
- endpoint: z.string().default("https://api.mutagent.io"),
148
- format: z.enum(["table", "json"]).default("table"),
149
- timeout: z.number().default(30000),
150
- defaultWorkspace: z.string().optional(),
151
- defaultOrganization: z.string().optional()
152
- });
153
- credentialsSchema = z.object({
154
- apiKey: z.string().optional(),
155
- endpoint: z.string().optional(),
156
- defaultWorkspace: z.string().optional(),
157
- defaultOrganization: z.string().optional(),
158
- expiresAt: z.string().optional()
159
- }).loose();
160
- CREDENTIALS_DIR = join(homedir(), ".config", "mutagent");
161
- CREDENTIALS_FILE = join(CREDENTIALS_DIR, "credentials.json");
162
- });
150
+ // src/lib/sdk-client.ts
151
+ import { Mutagent, HTTPClient } from "@mutagent/sdk";
163
152
 
164
153
  // src/lib/errors.ts
154
+ class MutagentError extends Error {
155
+ code;
156
+ suggestion;
157
+ exitCode;
158
+ constructor(code, message, suggestion, exitCode = 1) {
159
+ super(message);
160
+ this.code = code;
161
+ this.suggestion = suggestion;
162
+ this.exitCode = exitCode;
163
+ this.name = "MutagentError";
164
+ }
165
+ toJSON() {
166
+ return {
167
+ success: false,
168
+ error: this.message,
169
+ code: this.code,
170
+ suggestedAction: this.suggestion
171
+ };
172
+ }
173
+ }
174
+ var AUTH_REMEDIATION_MESSAGE = [
175
+ "Authentication required. Options:",
176
+ " Interactive: mutagent auth login --browser",
177
+ " Non-interactive: export MUTAGENT_API_KEY=<your-key>",
178
+ " CI/CD: mutagent auth login --api-key <key>"
179
+ ].join(`
180
+ `);
181
+
182
+ class AuthenticationError extends MutagentError {
183
+ suggestions;
184
+ cause;
185
+ constructor(message, options = {}) {
186
+ super("AUTH_REQUIRED", message ?? 'Authentication required. Please run "mutagent auth login"', options.suggestions ? options.suggestions[0] : "Run: mutagent auth login --browser", 2);
187
+ this.suggestions = options.suggestions ?? [
188
+ "mutagent auth login --browser",
189
+ "export MUTAGENT_API_KEY=<your-key>",
190
+ "mutagent auth login --api-key <key>"
191
+ ];
192
+ this.suggestion = options.suggestions ? options.suggestions[0] : "Run: mutagent auth login --browser";
193
+ this.cause = options.cause;
194
+ }
195
+ }
196
+
197
+ class ApiError extends MutagentError {
198
+ statusCode;
199
+ constructor(status, message) {
200
+ super(`API_${String(status)}`, message, status === 401 ? "Check your API key with: mutagent auth status" : undefined, 1);
201
+ this.statusCode = status;
202
+ }
203
+ }
204
+ var WORKSPACE_REMEDIATION_MESSAGE = [
205
+ "Workspace context missing. To fix:",
206
+ " mutagent config set workspace <workspace-id> # Set default workspace",
207
+ " mutagent workspaces list # List available workspaces"
208
+ ].join(`
209
+ `);
210
+
211
+ class WorkspaceContextError extends MutagentError {
212
+ constructor(message) {
213
+ super("WORKSPACE_REQUIRED", message ?? "Workspace context is required but not configured", "Run: mutagent config set workspace <workspace-id>", 3);
214
+ }
215
+ }
216
+
217
+ class ValidationError extends MutagentError {
218
+ constructor(message) {
219
+ super("VALIDATION_ERROR", message, "Check the command syntax with: mutagent <command> --help", 1);
220
+ }
221
+ }
165
222
  function handleError(error, isJson) {
166
223
  if (error instanceof MutagentError) {
167
224
  if (isJson) {
@@ -234,93 +291,14 @@ function handleError(error, isJson) {
234
291
  }
235
292
  const message = error instanceof Error ? error.message : "Unknown error";
236
293
  if (isJson) {
237
- console.log(JSON.stringify({ error: { code: "UNKNOWN_ERROR", message } }, null, 2));
294
+ console.log(JSON.stringify({ success: false, error: message, code: "UNKNOWN_ERROR" }, null, 2));
238
295
  } else {
239
296
  console.error(`Error: ${message}`);
240
297
  }
241
298
  process.exit(1);
242
299
  }
243
- var MutagentError, AUTH_REMEDIATION_MESSAGE, AuthenticationError, ApiError, WORKSPACE_REMEDIATION_MESSAGE, WorkspaceContextError, ValidationError;
244
- var init_errors = __esm(() => {
245
- MutagentError = class MutagentError extends Error {
246
- code;
247
- suggestion;
248
- exitCode;
249
- constructor(code, message, suggestion, exitCode = 1) {
250
- super(message);
251
- this.code = code;
252
- this.suggestion = suggestion;
253
- this.exitCode = exitCode;
254
- this.name = "MutagentError";
255
- }
256
- toJSON() {
257
- return {
258
- error: {
259
- code: this.code,
260
- message: this.message,
261
- suggestion: this.suggestion
262
- }
263
- };
264
- }
265
- };
266
- AUTH_REMEDIATION_MESSAGE = [
267
- "Authentication required. Options:",
268
- " Interactive: mutagent auth login --browser",
269
- " Non-interactive: export MUTAGENT_API_KEY=<your-key>",
270
- " CI/CD: mutagent auth login --api-key <key>"
271
- ].join(`
272
- `);
273
- AuthenticationError = class AuthenticationError extends MutagentError {
274
- suggestions;
275
- cause;
276
- constructor(message, options = {}) {
277
- super("AUTH_REQUIRED", message ?? 'Authentication required. Please run "mutagent auth login"', options.suggestions ? options.suggestions[0] : "Run: mutagent auth login --browser", 2);
278
- this.suggestions = options.suggestions ?? [
279
- "mutagent auth login --browser",
280
- "export MUTAGENT_API_KEY=<your-key>",
281
- "mutagent auth login --api-key <key>"
282
- ];
283
- this.suggestion = options.suggestions ? options.suggestions[0] : "Run: mutagent auth login --browser";
284
- this.cause = options.cause;
285
- }
286
- };
287
- ApiError = class ApiError extends MutagentError {
288
- statusCode;
289
- constructor(status, message) {
290
- super(`API_${String(status)}`, message, status === 401 ? "Check your API key with: mutagent auth status" : undefined, 1);
291
- this.statusCode = status;
292
- }
293
- };
294
- WORKSPACE_REMEDIATION_MESSAGE = [
295
- "Workspace context missing. To fix:",
296
- " mutagent config set workspace <workspace-id> # Set default workspace",
297
- " mutagent workspaces list # List available workspaces"
298
- ].join(`
299
- `);
300
- WorkspaceContextError = class WorkspaceContextError extends MutagentError {
301
- constructor(message) {
302
- super("WORKSPACE_CONTEXT_MISSING", message ?? "Workspace context is required but not configured", "Run: mutagent config set workspace <workspace-id>", 3);
303
- }
304
- };
305
- ValidationError = class ValidationError extends MutagentError {
306
- constructor(message) {
307
- super("VALIDATION_ERROR", message, "Check the command syntax with: mutagent <command> --help", 1);
308
- }
309
- };
310
- });
311
300
 
312
301
  // src/lib/sdk-client.ts
313
- var exports_sdk_client = {};
314
- __export(exports_sdk_client, {
315
- validateApiKey: () => validateApiKey,
316
- resetSDKClient: () => resetSDKClient,
317
- getSDKClient: () => getSDKClient,
318
- fetchWorkspaces: () => fetchWorkspaces,
319
- fetchOrganizations: () => fetchOrganizations,
320
- MutagentSDK: () => SDKClientWrapper
321
- });
322
- import { Mutagent, HTTPClient } from "@mutagent/sdk";
323
-
324
302
  class SDKClientWrapper {
325
303
  sdk;
326
304
  apiKey;
@@ -583,13 +561,6 @@ class SDKClientWrapper {
583
561
  this.handleError(error);
584
562
  }
585
563
  }
586
- async getEvaluationResults(runId) {
587
- try {
588
- return await this.request(`/api/prompts/evaluations/${runId}/result`);
589
- } catch (error) {
590
- this.handleError(error);
591
- }
592
- }
593
564
  async startOptimization(promptId, datasetId, config) {
594
565
  try {
595
566
  return await this.request(`/api/prompt/${promptId}/optimize`, {
@@ -875,6 +846,7 @@ class SDKClientWrapper {
875
846
  }
876
847
  }
877
848
  }
849
+ var sdkClient = null;
878
850
  function getSDKClient() {
879
851
  if (!sdkClient) {
880
852
  const apiKey = getApiKey();
@@ -891,9 +863,6 @@ function getSDKClient() {
891
863
  }
892
864
  return sdkClient;
893
865
  }
894
- function resetSDKClient() {
895
- sdkClient = null;
896
- }
897
866
  async function validateApiKey(apiKey, endpoint) {
898
867
  try {
899
868
  const response = await fetch(`${endpoint}/api/organizations`, {
@@ -930,16 +899,6 @@ async function fetchWorkspaces(apiKey, endpoint, orgId) {
930
899
  return [];
931
900
  }
932
901
  }
933
- var sdkClient = null;
934
- var init_sdk_client = __esm(() => {
935
- init_errors();
936
- init_config();
937
- });
938
-
939
- // src/index.ts
940
- init_config();
941
- init_sdk_client();
942
-
943
902
  // src/lib/output.ts
944
903
  import chalk from "chalk";
945
904
  function getJsonFlag(command) {
@@ -1040,9 +999,14 @@ ${String(data.length)} result(s)`));
1040
999
  console.log(chalk.green(`✓ ${message}`));
1041
1000
  }
1042
1001
  }
1043
- error(message) {
1002
+ error(message, code, suggestedAction) {
1044
1003
  if (this.format === "json") {
1045
- console.log(JSON.stringify({ success: false, error: message }, null, 2));
1004
+ const result = { success: false, error: message };
1005
+ if (code)
1006
+ result.code = code;
1007
+ if (suggestedAction)
1008
+ result.suggestedAction = suggestedAction;
1009
+ console.log(JSON.stringify(result, null, 2));
1046
1010
  } else {
1047
1011
  console.log(chalk.red(`✗ ${message}`));
1048
1012
  }
@@ -1080,7 +1044,6 @@ function createSpinner(text, isJson) {
1080
1044
  }
1081
1045
 
1082
1046
  // src/index.ts
1083
- init_errors();
1084
1047
  var version = "0.1.0";
1085
1048
  export {
1086
1049
  version,
@@ -1095,5 +1058,5 @@ export {
1095
1058
  ApiError
1096
1059
  };
1097
1060
 
1098
- //# debugId=E80AD7A9F475C71F64756E2164756E21
1061
+ //# debugId=00563F4C07D86C5564756E2164756E21
1099
1062
  //# sourceMappingURL=index.js.map