@mutagent/cli 0.1.66 → 0.1.67

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
@@ -444,6 +444,7 @@ __export(exports_sdk_client, {
444
444
  getSDKClient: () => getSDKClient,
445
445
  fetchWorkspaces: () => fetchWorkspaces,
446
446
  fetchOrganizations: () => fetchOrganizations,
447
+ ensureSDKContext: () => ensureSDKContext,
447
448
  MutagentSDK: () => SDKClientWrapper
448
449
  });
449
450
  import { Mutagent, HTTPClient } from "@mutagent/sdk";
@@ -900,7 +901,6 @@ class SDKClientWrapper {
900
901
  }
901
902
  async listWorkspaces(filters) {
902
903
  try {
903
- await this.ensureOrganizationId();
904
904
  const response = await this.sdk.workspaces.listWorkspaces({
905
905
  includeInactive: false
906
906
  });
@@ -917,7 +917,6 @@ class SDKClientWrapper {
917
917
  }
918
918
  async getWorkspace(id) {
919
919
  try {
920
- await this.ensureOrganizationId();
921
920
  const response = await this.sdk.workspaces.getWorkspace({
922
921
  wsId: id
923
922
  });
@@ -999,12 +998,26 @@ class SDKClientWrapper {
999
998
  getCurrentOrgId() {
1000
999
  return this.organizationId;
1001
1000
  }
1002
- async ensureOrganizationId() {
1003
- if (this.organizationId)
1001
+ async ensureContext() {
1002
+ if (this.organizationId && this.workspaceId)
1004
1003
  return;
1005
- const orgs = await fetchOrganizations(this.apiKey, this.endpoint);
1006
- if (orgs.length > 0 && orgs[0]) {
1007
- this.organizationId = orgs[0].id;
1004
+ if (!this.organizationId) {
1005
+ const orgs = await fetchOrganizations(this.apiKey, this.endpoint);
1006
+ if (orgs.length > 0 && orgs[0]) {
1007
+ this.organizationId = orgs[0].id;
1008
+ }
1009
+ }
1010
+ if (!this.workspaceId && this.organizationId) {
1011
+ try {
1012
+ const response = await this.sdk.workspaces.listWorkspaces({ includeInactive: false });
1013
+ const workspaces = response.workspaces;
1014
+ if (workspaces.length > 0) {
1015
+ const defaultWs = workspaces.find((ws) => ws.isDefault) ?? workspaces[0];
1016
+ if (defaultWs) {
1017
+ this.workspaceId = defaultWs.id;
1018
+ }
1019
+ }
1020
+ } catch {}
1008
1021
  }
1009
1022
  }
1010
1023
  async testProvider(id) {
@@ -1070,11 +1083,17 @@ function getSDKClient() {
1070
1083
  workspaceId: config.defaultWorkspace,
1071
1084
  organizationId: config.defaultOrganization
1072
1085
  });
1086
+ contextPromise = sdkClient.ensureContext().catch(() => {});
1073
1087
  }
1074
1088
  return sdkClient;
1075
1089
  }
1090
+ async function ensureSDKContext() {
1091
+ if (contextPromise)
1092
+ await contextPromise;
1093
+ }
1076
1094
  function resetSDKClient() {
1077
1095
  sdkClient = null;
1096
+ contextPromise = null;
1078
1097
  }
1079
1098
  async function validateApiKey(apiKey, endpoint) {
1080
1099
  try {
@@ -1112,7 +1131,7 @@ async function fetchWorkspaces(apiKey, endpoint, orgId) {
1112
1131
  return [];
1113
1132
  }
1114
1133
  }
1115
- var sdkClient = null;
1134
+ var sdkClient = null, contextPromise = null;
1116
1135
  var init_sdk_client = __esm(() => {
1117
1136
  init_errors();
1118
1137
  init_config();
@@ -9039,5 +9058,5 @@ program.addCommand(createHooksCommand());
9039
9058
  program.addCommand(createFeedbackCommand());
9040
9059
  program.parse();
9041
9060
 
9042
- //# debugId=EA3BD8A71195D63264756E2164756E21
9061
+ //# debugId=0286B65EFCF4F92064756E2164756E21
9043
9062
  //# sourceMappingURL=cli.js.map