@mutagent/cli 0.1.65 → 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";
@@ -997,6 +998,28 @@ class SDKClientWrapper {
997
998
  getCurrentOrgId() {
998
999
  return this.organizationId;
999
1000
  }
1001
+ async ensureContext() {
1002
+ if (this.organizationId && this.workspaceId)
1003
+ return;
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 {}
1021
+ }
1022
+ }
1000
1023
  async testProvider(id) {
1001
1024
  try {
1002
1025
  const response = await this.sdk.providerConfigs.testProvider({
@@ -1060,11 +1083,17 @@ function getSDKClient() {
1060
1083
  workspaceId: config.defaultWorkspace,
1061
1084
  organizationId: config.defaultOrganization
1062
1085
  });
1086
+ contextPromise = sdkClient.ensureContext().catch(() => {});
1063
1087
  }
1064
1088
  return sdkClient;
1065
1089
  }
1090
+ async function ensureSDKContext() {
1091
+ if (contextPromise)
1092
+ await contextPromise;
1093
+ }
1066
1094
  function resetSDKClient() {
1067
1095
  sdkClient = null;
1096
+ contextPromise = null;
1068
1097
  }
1069
1098
  async function validateApiKey(apiKey, endpoint) {
1070
1099
  try {
@@ -1102,7 +1131,7 @@ async function fetchWorkspaces(apiKey, endpoint, orgId) {
1102
1131
  return [];
1103
1132
  }
1104
1133
  }
1105
- var sdkClient = null;
1134
+ var sdkClient = null, contextPromise = null;
1106
1135
  var init_sdk_client = __esm(() => {
1107
1136
  init_errors();
1108
1137
  init_config();
@@ -9029,5 +9058,5 @@ program.addCommand(createHooksCommand());
9029
9058
  program.addCommand(createFeedbackCommand());
9030
9059
  program.parse();
9031
9060
 
9032
- //# debugId=E63D3B793E7AE87C64756E2164756E21
9061
+ //# debugId=0286B65EFCF4F92064756E2164756E21
9033
9062
  //# sourceMappingURL=cli.js.map