@anythingai/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.
Files changed (2) hide show
  1. package/dist/js/bin.mjs +150 -82
  2. package/package.json +1 -1
package/dist/js/bin.mjs CHANGED
@@ -3069,7 +3069,7 @@ function errorCodeFromHttpStatus(status) {
3069
3069
 
3070
3070
  //#endregion
3071
3071
  //#region package.json
3072
- var version = "0.1.3";
3072
+ var version = "0.1.4";
3073
3073
 
3074
3074
  //#endregion
3075
3075
  //#region generated/core/bodySerializer.gen.ts
@@ -4576,13 +4576,19 @@ var AnythingApiClient = class {
4576
4576
  }));
4577
4577
  }
4578
4578
  async listProjectFiles({ projectGroupId }) {
4579
- return this.toResult(await getV0ApiProjectsByProjectGroupIdFiles({
4580
- client: this.client,
4581
- path: { projectGroupId }
4582
- })).andThen((data) => "files" in data ? ok(data) : err({
4583
- message: "Unexpected API response format",
4584
- status: 200
4585
- }));
4579
+ const fetchOnce = async () => {
4580
+ return this.toResult(await getV0ApiProjectsByProjectGroupIdFiles({
4581
+ client: this.client,
4582
+ path: { projectGroupId }
4583
+ })).andThen((data) => "files" in data ? ok({ files: data.files ?? [] }) : err({
4584
+ message: "Unexpected API response format",
4585
+ status: 200
4586
+ }));
4587
+ };
4588
+ const first = await fetchOnce();
4589
+ if (first.isErr() || first.value.files.length > 0) return first;
4590
+ await new Promise((resolve) => setTimeout(resolve, 750));
4591
+ return fetchOnce();
4586
4592
  }
4587
4593
  async getProjectFile({ projectGroupId, path }) {
4588
4594
  return this.toResult(await getV0ApiProjectsByProjectGroupIdFiles({
@@ -4905,13 +4911,56 @@ function extractErrorCode(details) {
4905
4911
  const parsed = DetailsWithCodeSchema.safeParse(details);
4906
4912
  return parsed.success ? parsed.data.code : null;
4907
4913
  }
4914
+ function resolveErrorCode({ error, exitCode, codeOverride }) {
4915
+ const status = "status" in error ? error.status ?? null : null;
4916
+ const details = "details" in error ? error.details : void 0;
4917
+ return codeOverride ?? extractErrorCode(details) ?? (status === null && exitCode !== void 0 ? errorCodeFromExitCode(exitCode) : errorCodeFromHttpStatus(status));
4918
+ }
4919
+ function outputStreamError({ argv, command, error, hint, exitCode, buildLogs, code: codeOverride }) {
4920
+ const status = "status" in error ? error.status ?? null : null;
4921
+ process.exitCode = exitCode ?? exitCodeFromHttpStatus(status);
4922
+ if (!argv.json && !argv.quiet) {
4923
+ outputError({
4924
+ argv,
4925
+ command,
4926
+ error,
4927
+ hint,
4928
+ exitCode,
4929
+ buildLogs,
4930
+ code: codeOverride
4931
+ });
4932
+ return;
4933
+ }
4934
+ const code = resolveErrorCode({
4935
+ error,
4936
+ exitCode,
4937
+ codeOverride
4938
+ });
4939
+ const retryAfter = "retryAfter" in error && typeof error.retryAfter === "number" ? error.retryAfter : null;
4940
+ const resolvedHint = hint ?? ("hint" in error && typeof error.hint === "string" ? error.hint : void 0);
4941
+ printNdjson({
4942
+ type: "result",
4943
+ ok: false,
4944
+ error: {
4945
+ code,
4946
+ message: error.message,
4947
+ ...resolvedHint ? { hint: resolvedHint } : {},
4948
+ ...retryAfter !== null ? { retry_after_seconds: retryAfter } : {},
4949
+ ...buildLogs ? { buildLogs: buildLogsToLines(buildLogs) } : {}
4950
+ }
4951
+ });
4952
+ }
4908
4953
  function outputError({ argv, command, error, hint, exitCode, buildLogs, code: codeOverride }) {
4909
4954
  const status = "status" in error ? error.status ?? null : null;
4910
4955
  const details = "details" in error ? error.details : void 0;
4911
4956
  const retryAfter = "retryAfter" in error && typeof error.retryAfter === "number" ? error.retryAfter : null;
4912
4957
  const resolvedHint = hint ?? ("hint" in error && typeof error.hint === "string" ? error.hint : void 0);
4913
4958
  process.exitCode = exitCode ?? exitCodeFromHttpStatus(status);
4914
- const code = codeOverride ?? extractErrorCode(details) ?? (status === null && exitCode !== void 0 ? errorCodeFromExitCode(exitCode) : errorCodeFromHttpStatus(status));
4959
+ const code = resolveErrorCode({
4960
+ error,
4961
+ exitCode,
4962
+ codeOverride
4963
+ });
4915
4964
  if (argv.json || argv.quiet) {
4916
4965
  console.log(JSON.stringify({
4917
4966
  ok: false,
@@ -5378,7 +5427,7 @@ async function selectAndSetOrg({ config, json, nonInteractive }) {
5378
5427
  return choice;
5379
5428
  }
5380
5429
  }
5381
- const recommended = orgs.find((org) => BigInt(org.creditBalance) > 0n) ?? orgs[0];
5430
+ const recommended = orgs.find((org) => org.creditsBalance > 0) ?? orgs[0];
5382
5431
  if (!recommended) return null;
5383
5432
  if (!json) {
5384
5433
  console.log();
@@ -8503,7 +8552,7 @@ const llmContextCommand = {
8503
8552
  id: org.id,
8504
8553
  name: org.name,
8505
8554
  plan: org.plan,
8506
- hasCredits: BigInt(org.creditBalance) > 0n
8555
+ hasCredits: org.creditsBalance > 0
8507
8556
  }))
8508
8557
  };
8509
8558
  } catch {}
@@ -8925,18 +8974,6 @@ const membersCommand = {
8925
8974
  handler: () => {}
8926
8975
  };
8927
8976
 
8928
- //#endregion
8929
- //#region src/format-credits.ts
8930
- const HUMAN_READABLE_FACTOR = 10000000n;
8931
- const formatter = Intl.NumberFormat("en", {
8932
- notation: "compact",
8933
- maximumSignificantDigits: 3
8934
- });
8935
- const humanizeCredits = (credits) => {
8936
- const normalized = BigInt(credits) * 100n / HUMAN_READABLE_FACTOR;
8937
- return formatter.format(Math.ceil(Number(normalized) / 100));
8938
- };
8939
-
8940
8977
  //#endregion
8941
8978
  //#region src/commands/org-members.ts
8942
8979
  const orgMembersCommand = {
@@ -9061,9 +9098,6 @@ async function loadOrganizations(argv, command) {
9061
9098
  }
9062
9099
  return result.value.organizations;
9063
9100
  }
9064
- function formatCredits$1(creditBalance) {
9065
- return `${humanizeCredits(creditBalance)} credits`;
9066
- }
9067
9101
  const getCommand = {
9068
9102
  command: "get <organizationId>",
9069
9103
  describe: "Inspect a single organization",
@@ -9099,7 +9133,7 @@ const getCommand = {
9099
9133
  printLabel("ID", organization.id);
9100
9134
  printLabel("Plan", organization.planDisplayName);
9101
9135
  printLabel("Paid", organization.isPaid ? "yes" : "no");
9102
- printLabel("Credits", formatCredits$1(organization.creditBalance));
9136
+ printLabel("Credits", `${organization.creditsBalance} credits`);
9103
9137
  printLabel("Plan Code", organization.plan);
9104
9138
  }
9105
9139
  };
@@ -9603,13 +9637,25 @@ const createCommand = {
9603
9637
  const DEPLOY_POLL_INTERVAL_MS = 3e3;
9604
9638
  const DEPLOY_POLL_TIMEOUT_MS = 6e5;
9605
9639
  const DEPLOY_JITTER_MS = 500;
9640
+ const MAX_CONSECUTIVE_POLL_ERRORS = 5;
9606
9641
  const TERMINAL_STATUSES = new Set(["SUCCESS", "FAILED"]);
9607
9642
  async function waitForDeployment({ client, deploymentId, emit }) {
9608
9643
  const deadline = Date.now() + DEPLOY_POLL_TIMEOUT_MS;
9609
9644
  let lastStatus = null;
9645
+ let consecutiveErrors = 0;
9610
9646
  while (Date.now() < deadline) {
9611
9647
  const result = await client.getDeployment({ deploymentId });
9612
- if (result.isErr()) return err(result.error);
9648
+ if (result.isErr()) {
9649
+ consecutiveErrors += 1;
9650
+ if (consecutiveErrors >= MAX_CONSECUTIVE_POLL_ERRORS) return ok({
9651
+ outcome: "unconfirmed",
9652
+ deploymentId,
9653
+ reason: `Could not confirm deployment status after ${consecutiveErrors} consecutive polling errors (last: ${result.error.message}).`
9654
+ });
9655
+ await setTimeout$1(DEPLOY_POLL_INTERVAL_MS + Math.random() * DEPLOY_JITTER_MS);
9656
+ continue;
9657
+ }
9658
+ consecutiveErrors = 0;
9613
9659
  const { deployment } = result.value;
9614
9660
  if (deployment.status !== lastStatus) {
9615
9661
  lastStatus = deployment.status;
@@ -9636,10 +9682,12 @@ async function waitForDeployment({ client, deploymentId, emit }) {
9636
9682
  * error info if the deployment did not succeed, or null if it succeeded.
9637
9683
  */
9638
9684
  function getDeploymentError({ result, statusCommand }) {
9639
- if (result.outcome === "timeout") return {
9640
- message: `Deployment timed out. Check status with: ${statusCommand}`,
9685
+ if (result.outcome === "timeout" || result.outcome === "unconfirmed") return {
9686
+ message: `${result.outcome === "timeout" ? "Deployment did not reach a terminal status before the wait timed out" : result.reason} The deploy may still be in progress. Resume with: ${statusCommand}`,
9641
9687
  exitCode: 6,
9642
- buildLogs: null
9688
+ buildLogs: null,
9689
+ deploymentId: result.deploymentId,
9690
+ hint: `Resume with: ${statusCommand}`
9643
9691
  };
9644
9692
  if (result.deployment.status === "FAILED") {
9645
9693
  const reason = result.deployment.failureReason ?? null;
@@ -9647,7 +9695,9 @@ function getDeploymentError({ result, statusCommand }) {
9647
9695
  return {
9648
9696
  message: reason ?? (logs ? "Deployment failed. See build logs for details." : "Deployment failed (no logs available)."),
9649
9697
  exitCode: 1,
9650
- buildLogs: logs
9698
+ buildLogs: logs,
9699
+ deploymentId: result.deployment.id,
9700
+ hint: null
9651
9701
  };
9652
9702
  }
9653
9703
  return null;
@@ -9858,11 +9908,12 @@ const publishCommand = {
9858
9908
  argv,
9859
9909
  command: COMMAND$15,
9860
9910
  error: {
9861
- message: deployError.message,
9911
+ message: deployError.deploymentId ? `${deployError.message} (deploymentId: ${deployError.deploymentId})` : deployError.message,
9862
9912
  status: null
9863
9913
  },
9864
9914
  exitCode: deployError.exitCode,
9865
- buildLogs: deployError.buildLogs ?? void 0
9915
+ buildLogs: deployError.buildLogs ?? void 0,
9916
+ hint: deployError.hint ?? void 0
9866
9917
  });
9867
9918
  return;
9868
9919
  }
@@ -9993,20 +10044,24 @@ const list$1 = {
9993
10044
  });
9994
10045
  return;
9995
10046
  }
10047
+ const files = result.value.files;
9996
10048
  if (argv.json && outputSuccess({
9997
10049
  argv,
9998
10050
  command,
9999
- data: result.value
10051
+ data: {
10052
+ files,
10053
+ count: files.length
10054
+ }
10000
10055
  })) return;
10001
10056
  if (argv.quiet) {
10002
- for (const file of result.value.files) console.log(file.path);
10057
+ for (const file of files) console.log(file.path);
10003
10058
  return;
10004
10059
  }
10005
- if (result.value.files.length === 0) {
10060
+ if (files.length === 0) {
10006
10061
  console.log("No files found.");
10007
10062
  return;
10008
10063
  }
10009
- for (const file of result.value.files) console.log(file.path);
10064
+ for (const file of files) console.log(file.path);
10010
10065
  }
10011
10066
  };
10012
10067
  const get$1 = {
@@ -10958,7 +11013,11 @@ const secretEnvironmentChoices = [
10958
11013
  "preview",
10959
11014
  "production"
10960
11015
  ];
10961
- const DEFAULT_SECRET_ENVIRONMENT = "DEVELOPMENT";
11016
+ const ALL_SECRET_ENVIRONMENTS = [
11017
+ "DEVELOPMENT",
11018
+ "PREVIEW",
11019
+ "PRODUCTION"
11020
+ ];
10962
11021
  const add = {
10963
11022
  command: "add <projectId>",
10964
11023
  describe: "Add a secret to an app",
@@ -10977,7 +11036,7 @@ const add = {
10977
11036
  type: "string",
10978
11037
  coerce: (value) => value.toLowerCase(),
10979
11038
  choices: secretEnvironmentChoices,
10980
- describe: "Target environment for the secret"
11039
+ describe: "Target a single environment. Omit to add the secret to all environments (development, preview, production) so it reaches the published app."
10981
11040
  }).option("force", {
10982
11041
  type: "boolean",
10983
11042
  default: false,
@@ -10985,16 +11044,17 @@ const add = {
10985
11044
  }).example("anything projects secrets add <id> --name KEY --value \"secret\"", "Add a secret from an inline value").example("cat secret.txt | anything projects secrets add <id> --name KEY", "Read a secret value from stdin"),
10986
11045
  handler: async (argv) => {
10987
11046
  const command = "projects secrets add";
11047
+ const targetEnvironments = argv.env ? [argv.env.toUpperCase()] : [...ALL_SECRET_ENVIRONMENTS];
10988
11048
  if (argv["dry-run"]) {
10989
11049
  outputDryRun({
10990
11050
  argv,
10991
11051
  command,
10992
- plannedActions: [{
11052
+ plannedActions: targetEnvironments.map((environment) => ({
10993
11053
  action: "add_secret",
10994
11054
  projectGroupId: argv.projectId,
10995
11055
  name: argv.name,
10996
- ...argv.env ? { environment: argv.env.toUpperCase() } : {}
10997
- }]
11056
+ environment
11057
+ }))
10998
11058
  });
10999
11059
  return;
11000
11060
  }
@@ -11032,16 +11092,16 @@ const add = {
11032
11092
  return;
11033
11093
  }
11034
11094
  const client = new AnythingApiClient(config.value);
11035
- const targetEnvironment = argv.env ? argv.env.toUpperCase() : DEFAULT_SECRET_ENVIRONMENT;
11036
11095
  if (!argv.force) {
11037
11096
  const existing = await client.listSecrets({ projectGroupId: argv.projectId });
11038
11097
  if (existing.isOk()) {
11039
- if (existing.value.secrets.find((secret) => secret.displayName === argv.name && secret.environment === targetEnvironment)) {
11098
+ const collisions = targetEnvironments.filter((environment) => existing.value.secrets.some((secret) => secret.displayName === argv.name && secret.environment === environment));
11099
+ if (collisions.length > 0) {
11040
11100
  outputError({
11041
11101
  argv,
11042
11102
  command,
11043
11103
  error: {
11044
- message: `A secret named "${argv.name}" already exists in ${targetEnvironment}.`,
11104
+ message: `A secret named "${argv.name}" already exists in ${collisions.join(", ")}.`,
11045
11105
  status: 409
11046
11106
  },
11047
11107
  hint: "Remove the existing secret first, or pass --force to create a suffixed sibling."
@@ -11050,31 +11110,41 @@ const add = {
11050
11110
  }
11051
11111
  }
11052
11112
  }
11053
- const result = await client.addSecret({
11054
- projectGroupId: argv.projectId,
11055
- displayName: argv.name,
11056
- value: valueResult.value,
11057
- environment: targetEnvironment
11058
- });
11059
- if (result.isErr()) {
11060
- outputError({
11061
- argv,
11062
- command,
11063
- error: result.error
11113
+ const added = [];
11114
+ for (const environment of targetEnvironments) {
11115
+ const result = await client.addSecret({
11116
+ projectGroupId: argv.projectId,
11117
+ displayName: argv.name,
11118
+ value: valueResult.value,
11119
+ environment
11120
+ });
11121
+ if (result.isErr()) {
11122
+ outputError({
11123
+ argv,
11124
+ command,
11125
+ error: result.error
11126
+ });
11127
+ return;
11128
+ }
11129
+ added.push({
11130
+ id: result.value.secret.id,
11131
+ envKey: result.value.secret.envKey,
11132
+ environment: result.value.secret.environment
11064
11133
  });
11065
- return;
11066
11134
  }
11135
+ const environments = added.map((s) => s.environment);
11067
11136
  if (outputSuccess({
11068
11137
  argv,
11069
11138
  command,
11070
- data: result.value,
11071
- primaryId: result.value.secret.id
11139
+ data: {
11140
+ secrets: added,
11141
+ environments
11142
+ },
11143
+ primaryId: added[0]?.id
11072
11144
  })) return;
11073
- const s = result.value.secret;
11074
- printSuccess("Secret added.");
11075
- printLabel("ID", s.id);
11076
- printLabel("Env Key", s.envKey);
11077
- printLabel("Environment", s.environment);
11145
+ printSuccess(`Secret added to ${environments.join(", ")}.`);
11146
+ printLabel("Env Key", added[0]?.envKey ?? argv.name);
11147
+ for (const s of added) printLabel(`ID (${s.environment})`, s.id);
11078
11148
  }
11079
11149
  };
11080
11150
  const remove = {
@@ -11961,7 +12031,7 @@ const shipCommand = {
11961
12031
  apiUrl: argv.apiUrl
11962
12032
  });
11963
12033
  if (config.isErr()) {
11964
- outputError({
12034
+ outputStreamError({
11965
12035
  argv,
11966
12036
  command: COMMAND$4,
11967
12037
  error: {
@@ -11983,7 +12053,7 @@ const shipCommand = {
11983
12053
  nonInteractive: isNonInteractive(argv)
11984
12054
  });
11985
12055
  if (!orgResult.ok) {
11986
- outputError({
12056
+ outputStreamError({
11987
12057
  argv,
11988
12058
  command: COMMAND$4,
11989
12059
  error: {
@@ -12006,7 +12076,7 @@ const shipCommand = {
12006
12076
  name: argv.name ?? null
12007
12077
  });
12008
12078
  if (createResult.isErr()) {
12009
- outputError({
12079
+ outputStreamError({
12010
12080
  argv,
12011
12081
  command: COMMAND$4,
12012
12082
  error: createResult.error
@@ -12034,7 +12104,7 @@ const shipCommand = {
12034
12104
  createNewThread: false
12035
12105
  });
12036
12106
  if (genResult.isErr()) {
12037
- outputError({
12107
+ outputStreamError({
12038
12108
  argv,
12039
12109
  command: COMMAND$4,
12040
12110
  error: genResult.error
@@ -12098,7 +12168,7 @@ const shipCommand = {
12098
12168
  slug: argv.slug ?? null
12099
12169
  });
12100
12170
  if (publishResult.isErr()) {
12101
- outputError({
12171
+ outputStreamError({
12102
12172
  argv,
12103
12173
  command: COMMAND$4,
12104
12174
  error: publishResult.error
@@ -12113,7 +12183,7 @@ const shipCommand = {
12113
12183
  emit
12114
12184
  });
12115
12185
  if (deployResult.isErr()) {
12116
- outputError({
12186
+ outputStreamError({
12117
12187
  argv,
12118
12188
  command: COMMAND$4,
12119
12189
  error: deployResult.error
@@ -12125,15 +12195,16 @@ const shipCommand = {
12125
12195
  statusCommand: `anything projects publish status ${projectGroupId} ${deploymentId}`
12126
12196
  });
12127
12197
  if (deployError) {
12128
- outputError({
12198
+ outputStreamError({
12129
12199
  argv,
12130
12200
  command: COMMAND$4,
12131
12201
  error: {
12132
- message: deployError.message,
12202
+ message: deployError.deploymentId ? `${deployError.message} (deploymentId: ${deployError.deploymentId})` : deployError.message,
12133
12203
  status: null
12134
12204
  },
12135
12205
  exitCode: deployError.exitCode,
12136
- buildLogs: deployError.buildLogs ?? void 0
12206
+ buildLogs: deployError.buildLogs ?? void 0,
12207
+ hint: deployError.hint ?? void 0
12137
12208
  });
12138
12209
  return;
12139
12210
  }
@@ -12799,9 +12870,6 @@ const updateCommand = {
12799
12870
 
12800
12871
  //#endregion
12801
12872
  //#region src/commands/user.ts
12802
- function formatCredits(creditBalance) {
12803
- return `${humanizeCredits(creditBalance)} credits`;
12804
- }
12805
12873
  const COMMAND = "user";
12806
12874
  const userCommand = {
12807
12875
  command: "user",
@@ -12840,14 +12908,14 @@ const userCommand = {
12840
12908
  }
12841
12909
  const activeOrgId = getStoredOrgId();
12842
12910
  const defaultOrganization = result.value.organizations[0] ?? null;
12843
- const organizationWithCredits = result.value.organizations.find((org) => BigInt(org.creditBalance) > 0n) ?? null;
12844
- const recommendedOrganization = defaultOrganization !== null && BigInt(defaultOrganization.creditBalance) > 0n ? defaultOrganization : organizationWithCredits;
12911
+ const organizationWithCredits = result.value.organizations.find((org) => org.creditsBalance > 0) ?? null;
12912
+ const recommendedOrganization = defaultOrganization !== null && defaultOrganization.creditsBalance > 0 ? defaultOrganization : organizationWithCredits;
12845
12913
  const credentialSource = env.ANYTHING_API_KEY ? "env" : configExists() ? "config" : "unknown";
12846
12914
  const checks = {
12847
12915
  hasOrganizations: result.value.organizations.length > 0,
12848
12916
  hasPaidOrganization: result.value.organizations.some((org) => org.isPaid),
12849
12917
  hasCredits: organizationWithCredits !== null,
12850
- defaultOrganizationHasCredits: defaultOrganization !== null ? BigInt(defaultOrganization.creditBalance) > 0n : null
12918
+ defaultOrganizationHasCredits: defaultOrganization !== null ? defaultOrganization.creditsBalance > 0 : null
12851
12919
  };
12852
12920
  const activeOrg = activeOrgId ? result.value.organizations.find((o) => o.id === activeOrgId) ?? null : null;
12853
12921
  if (argv.quiet && !argv.json) {
@@ -12916,7 +12984,7 @@ const userCommand = {
12916
12984
  org.id === activeOrgId ? "*" : "",
12917
12985
  org.name,
12918
12986
  org.planDisplayName,
12919
- formatCredits(org.creditBalance),
12987
+ `${org.creditsBalance} credits`,
12920
12988
  org.id
12921
12989
  ])
12922
12990
  });
@@ -12928,7 +12996,7 @@ const userCommand = {
12928
12996
  if (!activeOrgId && recommendedOrganization !== null) {
12929
12997
  console.log();
12930
12998
  console.log(`No active organization set. Run \`anything orgs set ${recommendedOrganization.id}\` to set one.`);
12931
- } else if (activeOrg !== null && BigInt(activeOrg.creditBalance) === 0n && recommendedOrganization !== null && recommendedOrganization.id !== activeOrg.id) {
12999
+ } else if (activeOrg !== null && activeOrg.creditsBalance === 0 && recommendedOrganization !== null && recommendedOrganization.id !== activeOrg.id) {
12932
13000
  console.log();
12933
13001
  console.log(`Active organization has no credits. Run \`anything orgs set ${recommendedOrganization.id}\` to switch.`);
12934
13002
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anythingai/cli",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "homepage": "https://anything.com/",
5
5
  "license": "MIT",
6
6
  "bin": {