@vm0/cli 9.82.1 → 9.83.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vm0/cli",
3
- "version": "9.82.1",
3
+ "version": "9.83.0",
4
4
  "description": "CLI application",
5
5
  "repository": {
6
6
  "type": "git",
package/zero.js CHANGED
@@ -9,6 +9,7 @@ import {
9
9
  createZeroAgent,
10
10
  createZeroComputerConnector,
11
11
  createZeroConnectorSession,
12
+ decodeCliTokenPayload,
12
13
  decodeZeroTokenPayload,
13
14
  deleteZeroAgent,
14
15
  deleteZeroComputerConnector,
@@ -73,6 +74,7 @@ import {
73
74
  setZeroOrgVariable,
74
75
  setZeroSecret,
75
76
  setZeroVariable,
77
+ switchZeroOrg,
76
78
  updateZeroAgent,
77
79
  updateZeroAgentInstructions,
78
80
  updateZeroOrg,
@@ -80,7 +82,7 @@ import {
80
82
  updateZeroUserPreferences,
81
83
  upsertZeroOrgModelProvider,
82
84
  withErrorHandler
83
- } from "./chunk-2KN52BP2.js";
85
+ } from "./chunk-Z7ZCVASY.js";
84
86
 
85
87
  // src/zero.ts
86
88
  import { Command as Command55 } from "commander";
@@ -127,7 +129,16 @@ var setCommand = new Command2().name("set").description("Rename your organizatio
127
129
  );
128
130
  }
129
131
  const org = await updateZeroOrg({ slug, force: true });
130
- await saveConfig({ activeOrg: org.slug });
132
+ const token = await getToken();
133
+ if (decodeCliTokenPayload(token)) {
134
+ const result = await switchZeroOrg(org.slug);
135
+ await saveConfig({
136
+ token: result.access_token,
137
+ activeOrg: result.org_slug
138
+ });
139
+ } else {
140
+ await saveConfig({ activeOrg: org.slug });
141
+ }
131
142
  console.log(chalk2.green(`\u2713 Organization updated to ${org.slug}`));
132
143
  console.log();
133
144
  console.log("Your agents will now be namespaced as:");
@@ -171,7 +182,16 @@ var useCommand = new Command4().name("use").description("Switch to a different o
171
182
  if (!target) {
172
183
  throw new Error(`Organization '${slug}' not found or not accessible.`);
173
184
  }
174
- await saveConfig({ activeOrg: slug });
185
+ const token = await getToken();
186
+ if (decodeCliTokenPayload(token)) {
187
+ const result = await switchZeroOrg(slug);
188
+ await saveConfig({
189
+ token: result.access_token,
190
+ activeOrg: result.org_slug
191
+ });
192
+ } else {
193
+ await saveConfig({ activeOrg: slug });
194
+ }
175
195
  console.log(chalk4.green(`\u2713 Switched to organization: ${slug}`));
176
196
  })
177
197
  );
@@ -224,7 +244,7 @@ var leaveCommand = new Command8().name("leave").description("Leave the current o
224
244
  await leaveZeroOrg();
225
245
  const { orgs } = await listZeroOrgs();
226
246
  if (orgs.length === 0) {
227
- await saveConfig({ activeOrg: void 0 });
247
+ await saveConfig({ activeOrg: void 0, token: void 0 });
228
248
  console.log(chalk8.green("\u2713 Left organization."));
229
249
  console.log(
230
250
  chalk8.yellow("No remaining organizations. Run: vm0 auth login")
@@ -232,7 +252,16 @@ var leaveCommand = new Command8().name("leave").description("Leave the current o
232
252
  return;
233
253
  }
234
254
  const nextOrg = orgs[0].slug;
235
- await saveConfig({ activeOrg: nextOrg });
255
+ const token = await getToken();
256
+ if (decodeCliTokenPayload(token)) {
257
+ const result = await switchZeroOrg(nextOrg);
258
+ await saveConfig({
259
+ token: result.access_token,
260
+ activeOrg: result.org_slug
261
+ });
262
+ } else {
263
+ await saveConfig({ activeOrg: nextOrg });
264
+ }
236
265
  console.log(chalk8.green(`\u2713 Left organization. Switched to: ${nextOrg}`));
237
266
  })
238
267
  );
@@ -296,7 +325,8 @@ var setCommand2 = new Command11().name("set").description("Create or update an o
296
325
  } else if (isInteractive()) {
297
326
  const prompted = await promptPassword("Enter secret value:");
298
327
  if (prompted === void 0) {
299
- process.exit(0);
328
+ console.log(chalk11.dim("Cancelled"));
329
+ return;
300
330
  }
301
331
  value = prompted;
302
332
  } else {
@@ -783,6 +813,11 @@ async function handleInteractiveMode() {
783
813
  )
784
814
  });
785
815
  }
816
+ let cancelled = false;
817
+ const onCancel = () => {
818
+ cancelled = true;
819
+ return false;
820
+ };
786
821
  const { modelProviders: configuredProviders } = await listZeroOrgModelProviders();
787
822
  const configuredTypes = new Set(configuredProviders.map((p) => p.type));
788
823
  const annotatedChoices = getSelectableProviderTypes().map((type2) => {
@@ -808,8 +843,12 @@ async function handleInteractiveMode() {
808
843
  message: "Select provider type:",
809
844
  choices: annotatedChoices
810
845
  },
811
- { onCancel: () => process.exit(0) }
846
+ { onCancel }
812
847
  );
848
+ if (cancelled) {
849
+ console.log(chalk18.dim("Cancelled"));
850
+ return null;
851
+ }
813
852
  const type = typeResponse.type;
814
853
  const existingProvider = configuredProviders.find((p) => p.type === type);
815
854
  if (existingProvider) {
@@ -826,8 +865,12 @@ async function handleInteractiveMode() {
826
865
  { title: "Update secret", value: "update" }
827
866
  ]
828
867
  },
829
- { onCancel: () => process.exit(0) }
868
+ { onCancel }
830
869
  );
870
+ if (cancelled) {
871
+ console.log(chalk18.dim("Cancelled"));
872
+ return null;
873
+ }
831
874
  if (actionResponse.action === "keep") {
832
875
  const selectedModel2 = await promptForModelSelection(type);
833
876
  return {
@@ -864,14 +907,19 @@ async function handleInteractiveMode() {
864
907
  message: `Enter your ${secretLabel}:`,
865
908
  validate: (value) => value.length > 0 || `${secretLabel} is required`
866
909
  },
867
- { onCancel: () => process.exit(0) }
910
+ { onCancel }
868
911
  );
912
+ if (cancelled) {
913
+ console.log(chalk18.dim("Cancelled"));
914
+ return null;
915
+ }
869
916
  const secret = secretResponse.secret;
870
917
  const selectedModel = await promptForModelSelection(type);
871
918
  return { type, secret, selectedModel, isInteractiveMode: true };
872
919
  }
873
920
  async function promptSetAsDefault(type, framework, isDefault) {
874
921
  if (isDefault) return;
922
+ let cancelled = false;
875
923
  const response = await prompts2(
876
924
  {
877
925
  type: "confirm",
@@ -879,8 +927,17 @@ async function promptSetAsDefault(type, framework, isDefault) {
879
927
  message: "Set this provider as default?",
880
928
  initial: false
881
929
  },
882
- { onCancel: () => process.exit(0) }
930
+ {
931
+ onCancel: () => {
932
+ cancelled = true;
933
+ return false;
934
+ }
935
+ }
883
936
  );
937
+ if (cancelled) {
938
+ console.log(chalk18.dim("Cancelled"));
939
+ return;
940
+ }
884
941
  if (response.setDefault) {
885
942
  await setZeroOrgModelProviderDefault(type);
886
943
  console.log(chalk18.green(`\u2713 Default for ${framework} set to "${type}"`));
@@ -1040,7 +1097,7 @@ var createCommand = new Command24().name("create").description("Create a new zer
1040
1097
  const content = readFileSync(options.instructionsFile, "utf-8");
1041
1098
  await updateZeroAgentInstructions(agent.agentId, content);
1042
1099
  }
1043
- console.log(chalk21.green(`\u2713 Zero agent '${agent.agentId}' created`));
1100
+ console.log(chalk21.green(`\u2713 Agent "${agent.agentId}" created`));
1044
1101
  console.log(` Agent ID: ${agent.agentId}`);
1045
1102
  console.log(` Connectors: ${agent.connectors.join(", ")}`);
1046
1103
  if (agent.displayName) {
@@ -1083,7 +1140,7 @@ var editCommand = new Command25().name("edit").description("Edit a zero agent").
1083
1140
  const content = readFileSync2(options.instructionsFile, "utf-8");
1084
1141
  await updateZeroAgentInstructions(agentId, content);
1085
1142
  }
1086
- console.log(chalk22.green(`\u2713 Zero agent '${agentId}' updated`));
1143
+ console.log(chalk22.green(`\u2713 Agent "${agentId}" updated`));
1087
1144
  }
1088
1145
  )
1089
1146
  );
@@ -1174,7 +1231,7 @@ var deleteCommand2 = new Command28().name("delete").alias("rm").description("Del
1174
1231
  }
1175
1232
  }
1176
1233
  await deleteZeroAgent(agentId);
1177
- console.log(chalk25.green(`\u2713 Zero agent '${agentId}' deleted`));
1234
+ console.log(chalk25.green(`\u2713 Agent "${agentId}" deleted`));
1178
1235
  })
1179
1236
  );
1180
1237
 
@@ -1399,7 +1456,8 @@ async function connectViaApiToken(connectorType, tokenValue) {
1399
1456
  `${secretConfig.label}${secretConfig.placeholder ? chalk27.dim(` (${secretConfig.placeholder})`) : ""}:`
1400
1457
  );
1401
1458
  if (!value) {
1402
- throw new Error("Cancelled");
1459
+ console.log(chalk27.dim("Cancelled"));
1460
+ return;
1403
1461
  }
1404
1462
  inputSecrets[secretName] = value;
1405
1463
  }
@@ -1411,10 +1469,8 @@ async function connectViaApiToken(connectorType, tokenValue) {
1411
1469
  description: `API token for ${config.label} connector`
1412
1470
  });
1413
1471
  }
1414
- console.log(
1415
- chalk27.green(`
1416
- \u2713 ${config.label} connected successfully via API token!`)
1417
- );
1472
+ console.log(chalk27.green(`
1473
+ \u2713 Connector "${connectorType}" connected`));
1418
1474
  }
1419
1475
  async function connectComputer() {
1420
1476
  await checkComputerDependencies();
@@ -1451,7 +1507,8 @@ async function resolveAuthMethod(connectorType, tokenFlag) {
1451
1507
  ]
1452
1508
  );
1453
1509
  if (!selected) {
1454
- throw new Error("Cancelled");
1510
+ console.log(chalk27.dim("Cancelled"));
1511
+ return null;
1455
1512
  }
1456
1513
  return selected;
1457
1514
  }
@@ -1489,7 +1546,7 @@ The session expires in ${Math.floor(session.expiresIn / 60)} minutes.`
1489
1546
  console.log(
1490
1547
  chalk27.green(`
1491
1548
 
1492
- ${connectorType} connected successfully!`)
1549
+ \u2713 Connector "${connectorType}" connected`)
1493
1550
  );
1494
1551
  return;
1495
1552
  case "expired":
@@ -1520,6 +1577,7 @@ var connectCommand = new Command30().name("connect").description("Connect a thir
1520
1577
  return;
1521
1578
  }
1522
1579
  const authMethod = await resolveAuthMethod(connectorType, options.token);
1580
+ if (!authMethod) return;
1523
1581
  if (authMethod === "api-token") {
1524
1582
  await connectViaApiToken(connectorType, options.token);
1525
1583
  return;
@@ -2216,15 +2274,11 @@ Deploying schedule for agent ${chalk32.cyan(params.agentName)}...`
2216
2274
  });
2217
2275
  return deployResult;
2218
2276
  }
2219
- function displayDeployResult(agentName, deployResult) {
2277
+ function displayDeployResult(scheduleName, deployResult) {
2220
2278
  if (deployResult.created) {
2221
- console.log(
2222
- chalk32.green(`\u2713 Created schedule for agent ${chalk32.cyan(agentName)}`)
2223
- );
2279
+ console.log(chalk32.green(`\u2713 Schedule "${scheduleName}" created`));
2224
2280
  } else {
2225
- console.log(
2226
- chalk32.green(`\u2713 Updated schedule for agent ${chalk32.cyan(agentName)}`)
2227
- );
2281
+ console.log(chalk32.green(`\u2713 Schedule "${scheduleName}" updated`));
2228
2282
  }
2229
2283
  console.log(chalk32.dim(` Timezone: ${deployResult.schedule.timezone}`));
2230
2284
  if (deployResult.schedule.triggerType === "loop" && deployResult.schedule.intervalSeconds != null) {
@@ -2253,9 +2307,7 @@ function displayDeployResult(agentName, deployResult) {
2253
2307
  async function tryEnableSchedule(scheduleName, agentId, agentName) {
2254
2308
  try {
2255
2309
  await enableZeroSchedule({ name: scheduleName, agentId });
2256
- console.log(
2257
- chalk32.green(`\u2713 Enabled schedule for agent ${chalk32.cyan(agentName)}`)
2258
- );
2310
+ console.log(chalk32.green(`\u2713 Schedule "${scheduleName}" enabled`));
2259
2311
  } catch (error) {
2260
2312
  console.error(chalk32.yellow("\u26A0 Failed to enable schedule"));
2261
2313
  if (error instanceof ApiRequestError) {
@@ -2365,7 +2417,7 @@ var setupCommand2 = new Command36().name("setup").description("Create or edit a
2365
2417
  notifyEmail,
2366
2418
  notifySlack
2367
2419
  });
2368
- displayDeployResult(agentName, deployResult);
2420
+ displayDeployResult(scheduleName, deployResult);
2369
2421
  const shouldPromptEnable = deployResult.created || existingSchedule !== void 0 && !existingSchedule.enabled;
2370
2422
  await handleScheduleEnabling({
2371
2423
  scheduleName,
@@ -2536,9 +2588,7 @@ var deleteCommand3 = new Command39().name("delete").alias("rm").description("Del
2536
2588
  name: resolved.name,
2537
2589
  agentId: resolved.agentId
2538
2590
  });
2539
- console.log(
2540
- chalk35.green(`\u2713 Deleted schedule for agent ${chalk35.cyan(agentName)}`)
2541
- );
2591
+ console.log(chalk35.green(`\u2713 Schedule "${resolved.name}" deleted`));
2542
2592
  }
2543
2593
  )
2544
2594
  );
@@ -2559,9 +2609,7 @@ var enableCommand = new Command40().name("enable").description("Enable a zero sc
2559
2609
  name: resolved.name,
2560
2610
  agentId: resolved.agentId
2561
2611
  });
2562
- console.log(
2563
- chalk36.green(`\u2713 Enabled schedule for agent ${chalk36.cyan(agentName)}`)
2564
- );
2612
+ console.log(chalk36.green(`\u2713 Schedule "${resolved.name}" enabled`));
2565
2613
  })
2566
2614
  );
2567
2615
 
@@ -2581,9 +2629,7 @@ var disableCommand = new Command41().name("disable").description("Disable a zero
2581
2629
  name: resolved.name,
2582
2630
  agentId: resolved.agentId
2583
2631
  });
2584
- console.log(
2585
- chalk37.green(`\u2713 Disabled schedule for agent ${chalk37.cyan(agentName)}`)
2586
- );
2632
+ console.log(chalk37.green(`\u2713 Schedule "${resolved.name}" disabled`));
2587
2633
  })
2588
2634
  );
2589
2635
 
@@ -2663,7 +2709,8 @@ var setCommand4 = new Command44().name("set").description("Create or update a se
2663
2709
  } else if (isInteractive()) {
2664
2710
  const prompted = await promptPassword("Enter secret value:");
2665
2711
  if (prompted === void 0) {
2666
- process.exit(0);
2712
+ console.log(chalk39.dim("Cancelled"));
2713
+ return;
2667
2714
  }
2668
2715
  value = prompted;
2669
2716
  } else {
@@ -2878,12 +2925,9 @@ function isInsideSandbox() {
2878
2925
  async function showSandboxInfo() {
2879
2926
  const agentId = process.env.ZERO_AGENT_ID;
2880
2927
  const payload = decodeZeroTokenPayload();
2881
- console.log(chalk45.bold("Agent:"));
2882
- console.log(` ID: ${agentId}`);
2883
- console.log();
2884
- console.log(chalk45.bold("Run:"));
2885
- console.log(` ID: ${payload?.runId ?? chalk45.dim("unavailable")}`);
2886
- console.log(` Org: ${payload?.orgId ?? chalk45.dim("unavailable")}`);
2928
+ console.log(`Agent ID: ${agentId}`);
2929
+ console.log(`Run ID: ${payload?.runId ?? chalk45.dim("unavailable")}`);
2930
+ console.log(`Org ID: ${payload?.orgId ?? chalk45.dim("unavailable")}`);
2887
2931
  if (payload?.capabilities?.length) {
2888
2932
  console.log();
2889
2933
  console.log(chalk45.bold("Capabilities:"));
@@ -2927,46 +2971,40 @@ var COMMAND_CAPABILITY_MAP = {
2927
2971
  slack: "slack:write",
2928
2972
  whoami: null
2929
2973
  };
2930
- function applyCapabilityVisibility(prog) {
2974
+ var DEFAULT_COMMANDS = [
2975
+ zeroOrgCommand,
2976
+ zeroAgentCommand,
2977
+ zeroConnectorCommand,
2978
+ zeroPreferenceCommand,
2979
+ zeroScheduleCommand,
2980
+ zeroSecretCommand,
2981
+ zeroSlackCommand,
2982
+ zeroVariableCommand,
2983
+ zeroWhoamiCommand
2984
+ ];
2985
+ function shouldHideCommand(name, payload) {
2986
+ if (!payload) return false;
2987
+ const requiredCap = COMMAND_CAPABILITY_MAP[name];
2988
+ if (requiredCap === void 0) return true;
2989
+ return requiredCap !== null && !payload.capabilities.includes(requiredCap);
2990
+ }
2991
+ function registerZeroCommands(prog, commands) {
2931
2992
  const token = process.env.ZERO_TOKEN;
2932
- if (!token) return;
2933
- const payload = decodeZeroTokenPayload(token);
2934
- if (!payload) return;
2935
- for (const cmd of prog.commands) {
2936
- const requiredCap = COMMAND_CAPABILITY_MAP[cmd.name()];
2937
- if (requiredCap === void 0) {
2938
- cmd._hidden = true;
2939
- } else if (requiredCap !== null && !payload.capabilities.includes(requiredCap)) {
2940
- cmd._hidden = true;
2941
- }
2993
+ const payload = token ? decodeZeroTokenPayload(token) : void 0;
2994
+ for (const cmd of commands ?? DEFAULT_COMMANDS) {
2995
+ const hidden = shouldHideCommand(cmd.name(), payload);
2996
+ prog.addCommand(cmd, hidden ? { hidden: true } : {});
2942
2997
  }
2943
2998
  }
2944
2999
  var program = new Command55();
2945
- program.name("zero").description("Zero CLI - Manage your zero platform").version("9.82.1");
2946
- program.addCommand(zeroOrgCommand);
2947
- program.addCommand(zeroAgentCommand);
2948
- program.addCommand(zeroConnectorCommand);
2949
- program.addCommand(zeroPreferenceCommand);
2950
- program.addCommand(zeroScheduleCommand);
2951
- program.addCommand(zeroSecretCommand);
2952
- program.addCommand(zeroSlackCommand);
2953
- program.addCommand(zeroVariableCommand);
2954
- program.addCommand(zeroWhoamiCommand);
3000
+ program.name("zero").description("Zero CLI - Manage your zero platform").version("9.83.0");
2955
3001
  if (process.argv[1]?.endsWith("zero.js") || process.argv[1]?.endsWith("zero.ts") || process.argv[1]?.endsWith("zero")) {
2956
- process.stdout.on("error", (err) => {
2957
- if (err.code === "EPIPE") process.exit(0);
2958
- throw err;
2959
- });
2960
- process.stderr.on("error", (err) => {
2961
- if (err.code === "EPIPE") process.exit(0);
2962
- throw err;
2963
- });
2964
3002
  configureGlobalProxyFromEnv();
2965
- applyCapabilityVisibility(program);
3003
+ registerZeroCommands(program);
2966
3004
  program.parse();
2967
3005
  }
2968
3006
  export {
2969
- applyCapabilityVisibility,
2970
- program
3007
+ program,
3008
+ registerZeroCommands
2971
3009
  };
2972
3010
  //# sourceMappingURL=zero.js.map