@mutagent/cli 0.1.3 → 0.1.4

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/bin/cli.js CHANGED
@@ -200,9 +200,9 @@ function serverURLFromOptions(options) {
200
200
  var SDK_METADATA = {
201
201
  language: "typescript",
202
202
  openapiDocVersion: "2.0.0",
203
- sdkVersion: "0.2.21",
203
+ sdkVersion: "0.2.23",
204
204
  genVersion: "2.812.2",
205
- userAgent: "speakeasy-sdk/typescript 0.2.21 2.812.2 2.0.0 @mutagent/sdk"
205
+ userAgent: "speakeasy-sdk/typescript 0.2.23 2.812.2 2.0.0 @mutagent/sdk"
206
206
  };
207
207
  // ../mutagent-sdk/dist/esm/lib/http.js
208
208
  var DEFAULT_FETCHER = (input, init) => {
@@ -13822,6 +13822,32 @@ async function validateApiKey(apiKey, endpoint) {
13822
13822
  return false;
13823
13823
  }
13824
13824
  }
13825
+ async function fetchOrganizations(apiKey, endpoint) {
13826
+ try {
13827
+ const response = await fetch(`${endpoint}/api/organizations`, {
13828
+ headers: { "x-api-key": apiKey }
13829
+ });
13830
+ if (!response.ok)
13831
+ return [];
13832
+ const data = await response.json();
13833
+ return data.data ?? [];
13834
+ } catch {
13835
+ return [];
13836
+ }
13837
+ }
13838
+ async function fetchWorkspaces(apiKey, endpoint, orgId) {
13839
+ try {
13840
+ const response = await fetch(`${endpoint}/api/workspaces`, {
13841
+ headers: { "x-api-key": apiKey, "x-organization-id": orgId }
13842
+ });
13843
+ if (!response.ok)
13844
+ return [];
13845
+ const data = await response.json();
13846
+ return data.workspaces ?? [];
13847
+ } catch {
13848
+ return [];
13849
+ }
13850
+ }
13825
13851
 
13826
13852
  // src/lib/output.ts
13827
13853
  import chalk from "chalk";
@@ -14111,7 +14137,21 @@ Environment Variables:
14111
14137
  if (!isValid) {
14112
14138
  throw new MutagentError2("INVALID_API_KEY", "Invalid API key or endpoint", "Check your API key and try again");
14113
14139
  }
14114
- saveCredentials(apiKey, endpoint);
14140
+ const orgs = await fetchOrganizations(apiKey, endpoint);
14141
+ let orgId;
14142
+ let wsId;
14143
+ if (orgs.length >= 1 && orgs[0]) {
14144
+ orgId = orgs[0].id;
14145
+ const workspaces = await fetchWorkspaces(apiKey, endpoint, orgId);
14146
+ const defaultWs = workspaces.find((w) => w.isDefault);
14147
+ wsId = defaultWs?.id ?? workspaces[0]?.id;
14148
+ }
14149
+ saveFullCredentials({
14150
+ apiKey,
14151
+ endpoint,
14152
+ workspaceId: wsId,
14153
+ organizationId: orgId
14154
+ });
14115
14155
  output.success("Authenticated successfully");
14116
14156
  if (!isJson) {
14117
14157
  output.info(`Endpoint: ${endpoint}`);
@@ -14208,8 +14248,55 @@ Environment Variables:
14208
14248
  if (!isValid) {
14209
14249
  throw new MutagentError2("INVALID_API_KEY", "Invalid API key or endpoint", "Check your API key and try again");
14210
14250
  }
14211
- saveCredentials(apiKey, endpoint);
14251
+ let selectedOrgId;
14252
+ let selectedOrgName;
14253
+ let selectedWsId;
14254
+ let selectedWsName;
14255
+ const orgs = await fetchOrganizations(apiKey, endpoint);
14256
+ if (orgs.length === 1 && orgs[0]) {
14257
+ selectedOrgId = orgs[0].id;
14258
+ selectedOrgName = orgs[0].name;
14259
+ } else if (orgs.length > 1) {
14260
+ const orgAnswer = await inquirer.prompt([{
14261
+ type: "list",
14262
+ name: "orgId",
14263
+ message: "Select organization:",
14264
+ choices: orgs.map((o) => ({ name: o.name, value: o.id }))
14265
+ }]);
14266
+ selectedOrgId = orgAnswer.orgId;
14267
+ selectedOrgName = orgs.find((o) => o.id === selectedOrgId)?.name;
14268
+ }
14269
+ if (selectedOrgId) {
14270
+ const workspaces = await fetchWorkspaces(apiKey, endpoint, selectedOrgId);
14271
+ const defaultWs = workspaces.find((w) => w.isDefault);
14272
+ if (workspaces.length === 1 && workspaces[0]) {
14273
+ selectedWsId = workspaces[0].id;
14274
+ selectedWsName = workspaces[0].name;
14275
+ } else if (defaultWs) {
14276
+ selectedWsId = defaultWs.id;
14277
+ selectedWsName = defaultWs.name;
14278
+ } else if (workspaces.length > 1) {
14279
+ const wsAnswer = await inquirer.prompt([{
14280
+ type: "list",
14281
+ name: "wsId",
14282
+ message: "Select workspace:",
14283
+ choices: workspaces.map((w) => ({ name: w.name + (w.isDefault ? " (default)" : ""), value: w.id }))
14284
+ }]);
14285
+ selectedWsId = wsAnswer.wsId;
14286
+ selectedWsName = workspaces.find((w) => w.id === selectedWsId)?.name;
14287
+ }
14288
+ }
14289
+ saveFullCredentials({
14290
+ apiKey,
14291
+ endpoint,
14292
+ workspaceId: selectedWsId,
14293
+ organizationId: selectedOrgId
14294
+ });
14212
14295
  output.success("Authenticated successfully");
14296
+ if (selectedOrgName)
14297
+ output.info("Organization: " + selectedOrgName);
14298
+ if (selectedWsName)
14299
+ output.info("Workspace: " + selectedWsName);
14213
14300
  output.info("Endpoint: " + endpoint);
14214
14301
  }
14215
14302
  } catch (error) {
@@ -17150,5 +17237,5 @@ program.addCommand(createWorkspacesCommand());
17150
17237
  program.addCommand(createProvidersCommand());
17151
17238
  program.parse();
17152
17239
 
17153
- //# debugId=478A37FBB111956764756E2164756E21
17240
+ //# debugId=C70269B58C487D9164756E2164756E21
17154
17241
  //# sourceMappingURL=cli.js.map