@mutagent/cli 0.1.1 → 0.1.3

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
@@ -35,7 +25,7 @@ import { join } from "path";
35
25
  import { existsSync, readFileSync, writeFileSync, mkdirSync } from "fs";
36
26
  var configSchema = z.object({
37
27
  apiKey: z.string().optional(),
38
- endpoint: z.string().default("https://api.mutagent.io/v1"),
28
+ endpoint: z.string().default("https://api.mutagent.io"),
39
29
  format: z.enum(["table", "json"]).default("table"),
40
30
  timeout: z.number().default(30000),
41
31
  defaultWorkspace: z.string().optional(),
@@ -102,7 +92,7 @@ function saveFullCredentials(creds) {
102
92
  const credentials = {
103
93
  ...existingCredentials,
104
94
  apiKey: creds.apiKey,
105
- endpoint: creds.endpoint ?? existingCredentials.endpoint ?? "https://api.mutagent.io/v1",
95
+ endpoint: creds.endpoint ?? existingCredentials.endpoint ?? "https://api.mutagent.io",
106
96
  defaultWorkspace: creds.workspaceId ?? existingCredentials.defaultWorkspace,
107
97
  defaultOrganization: creds.organizationId ?? existingCredentials.defaultOrganization,
108
98
  expiresAt: creds.expiresAt
@@ -195,11 +185,10 @@ function serverURLFromOptions(options) {
195
185
  var SDK_METADATA = {
196
186
  language: "typescript",
197
187
  openapiDocVersion: "2.0.0",
198
- sdkVersion: "0.2.13",
199
- genVersion: "2.811.4",
200
- userAgent: "speakeasy-sdk/typescript 0.2.13 2.811.4 2.0.0 @mutagent/sdk"
188
+ sdkVersion: "0.2.21",
189
+ genVersion: "2.812.2",
190
+ userAgent: "speakeasy-sdk/typescript 0.2.21 2.812.2 2.0.0 @mutagent/sdk"
201
191
  };
202
-
203
192
  // ../mutagent-sdk/dist/esm/lib/http.js
204
193
  var DEFAULT_FETCHER = (input, init) => {
205
194
  if (init == null) {
@@ -364,7 +353,6 @@ function isAbortError(err) {
364
353
  const isGenericErr = "code" in err && typeof err.code === "string" && err.code.toLowerCase() === "econnaborted";
365
354
  return isNative || isLegacyNative || isGenericErr;
366
355
  }
367
-
368
356
  // ../mutagent-sdk/dist/esm/hooks/registration.js
369
357
  function initHooks(hooks) {}
370
358
 
@@ -13272,7 +13260,6 @@ class Mutagent extends ClientSDK {
13272
13260
  return this._traces ?? (this._traces = new Traces(this._options));
13273
13261
  }
13274
13262
  }
13275
-
13276
13263
  // src/lib/errors.ts
13277
13264
  class MutagentError2 extends Error {
13278
13265
  code;
@@ -13338,14 +13325,27 @@ class SDKClientWrapper {
13338
13325
  sdk;
13339
13326
  apiKey;
13340
13327
  endpoint;
13328
+ workspaceId;
13329
+ organizationId;
13341
13330
  constructor(opts) {
13342
13331
  this.apiKey = opts.bearerAuth;
13343
13332
  this.endpoint = opts.serverURL ?? "http://localhost:3003";
13333
+ this.workspaceId = opts.workspaceId;
13334
+ this.organizationId = opts.organizationId;
13335
+ const httpClient = new HTTPClient;
13336
+ httpClient.addHook("beforeRequest", (req) => {
13337
+ if (this.workspaceId)
13338
+ req.headers.set("x-workspace-id", this.workspaceId);
13339
+ if (this.organizationId)
13340
+ req.headers.set("x-organization-id", this.organizationId);
13341
+ return req;
13342
+ });
13344
13343
  this.sdk = new Mutagent({
13345
13344
  security: {
13346
13345
  apiKey: this.apiKey
13347
13346
  },
13348
- serverURL: this.endpoint
13347
+ serverURL: this.endpoint,
13348
+ httpClient
13349
13349
  });
13350
13350
  }
13351
13351
  handleError(error) {
@@ -13370,11 +13370,17 @@ class SDKClientWrapper {
13370
13370
  } else if (optHeaders) {
13371
13371
  extraHeaders = optHeaders;
13372
13372
  }
13373
+ const tenancyHeaders = {};
13374
+ if (this.workspaceId)
13375
+ tenancyHeaders["x-workspace-id"] = this.workspaceId;
13376
+ if (this.organizationId)
13377
+ tenancyHeaders["x-organization-id"] = this.organizationId;
13373
13378
  const response = await fetch(`${this.endpoint}${path}`, {
13374
13379
  ...options,
13375
13380
  headers: {
13376
- Authorization: `Bearer ${this.apiKey}`,
13381
+ "x-api-key": this.apiKey,
13377
13382
  "Content-Type": "application/json",
13383
+ ...tenancyHeaders,
13378
13384
  ...extraHeaders
13379
13385
  }
13380
13386
  });
@@ -13453,7 +13459,7 @@ class SDKClientWrapper {
13453
13459
  async listDatasets(promptId) {
13454
13460
  try {
13455
13461
  const response = await this.request(`/api/prompt/${promptId}/datasets`);
13456
- return response.data;
13462
+ return Array.isArray(response) ? response : response.data;
13457
13463
  } catch (error) {
13458
13464
  this.handleError(error);
13459
13465
  }
@@ -13538,7 +13544,8 @@ class SDKClientWrapper {
13538
13544
  }
13539
13545
  async listTraces(filters) {
13540
13546
  const params = filters ? new URLSearchParams(filters).toString() : "";
13541
- return this.request(`/api/traces${params ? `?${params}` : ""}`);
13547
+ const response = await this.request(`/api/traces${params ? `?${params}` : ""}`);
13548
+ return response.data ?? [];
13542
13549
  }
13543
13550
  async getTrace(id) {
13544
13551
  return this.request(`/api/traces/${id}`);
@@ -13720,7 +13727,7 @@ class SDKClientWrapper {
13720
13727
  const response = await fetch(`${this.endpoint}/api/prompt/${promptId}/execute/stream`, {
13721
13728
  method: "POST",
13722
13729
  headers: {
13723
- Authorization: `Bearer ${this.apiKey}`,
13730
+ "x-api-key": this.apiKey,
13724
13731
  "Content-Type": "application/json",
13725
13732
  Accept: "text/event-stream"
13726
13733
  },
@@ -13780,20 +13787,25 @@ function getSDKClient() {
13780
13787
  if (!apiKey) {
13781
13788
  throw new AuthenticationError;
13782
13789
  }
13783
- const config = loadConfig();
13790
+ const config2 = loadConfig();
13784
13791
  sdkClient = new SDKClientWrapper({
13785
13792
  bearerAuth: apiKey,
13786
- serverURL: config.endpoint
13793
+ serverURL: config2.endpoint,
13794
+ workspaceId: config2.defaultWorkspace,
13795
+ organizationId: config2.defaultOrganization
13787
13796
  });
13788
13797
  }
13789
13798
  return sdkClient;
13790
13799
  }
13791
- function validateApiKey(apiKey, endpoint) {
13792
- const client = new SDKClientWrapper({
13793
- bearerAuth: apiKey,
13794
- serverURL: endpoint
13795
- });
13796
- return client.listPrompts().then(() => true).catch(() => false);
13800
+ async function validateApiKey(apiKey, endpoint) {
13801
+ try {
13802
+ const response = await fetch(`${endpoint}/api/organizations`, {
13803
+ headers: { "x-api-key": apiKey }
13804
+ });
13805
+ return response.ok;
13806
+ } catch {
13807
+ return false;
13808
+ }
13797
13809
  }
13798
13810
  // src/lib/output.ts
13799
13811
  import chalk from "chalk";
@@ -13931,5 +13943,5 @@ export {
13931
13943
  ApiError
13932
13944
  };
13933
13945
 
13934
- //# debugId=753FFCF2CF64C60D64756E2164756E21
13946
+ //# debugId=460687AAB930C83264756E2164756E21
13935
13947
  //# sourceMappingURL=index.js.map