@phantomcodes/cli 1.1.0 → 1.1.1

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.
@@ -1,2 +1,2 @@
1
1
  /** This release of phantom. `npm version` keeps it equal to the version in package.json. */
2
- export const VERSION = '1.1.0';
2
+ export const VERSION = '1.1.1';
@@ -1,17 +1,21 @@
1
1
  import { die } from "../core/errors.mjs";
2
2
  import { openUrl, out } from "../core/helpers.mjs";
3
3
  import { request } from "../core/request.mjs";
4
- /** The key's plan and its week (GET /plan). */
4
+ import { savedManagement } from "../workspace/command.mjs";
5
+ /** The plan of the key's workspace and its week (GET /plan). */
5
6
  export function getPlan(apiKey, baseUrl) {
6
7
  return request('GET', '/plan', apiKey, undefined, baseUrl);
7
8
  }
8
- /** A Stripe Checkout link that puts `plan` on the key (POST /plan/checkout). */
9
+ /** A Stripe Checkout link that puts `plan` on the key's workspace (POST /plan/checkout). */
9
10
  export function planCheckout(apiKey, plan, baseUrl) {
10
11
  return request('POST', '/plan/checkout', apiKey, { plan }, baseUrl);
11
12
  }
12
- /** A link to Stripe's billing page for the key's plan (POST /plan/portal). */
13
- export function planPortal(apiKey, baseUrl) {
14
- return request('POST', '/plan/portal', apiKey, undefined, baseUrl);
13
+ /**
14
+ * A link to Stripe's billing page for a workspace's plan (POST /plan/portal).
15
+ * It takes the workspace's management credential: an inference key gets 403.
16
+ */
17
+ export function planPortal(credential, baseUrl) {
18
+ return request('POST', '/plan/portal', credential, undefined, baseUrl);
15
19
  }
16
20
  const dollars = (n) => `$${n.toFixed(2)}`;
17
21
  /** `--table` output for `plan`. */
@@ -36,11 +40,12 @@ export function tablePlan(d) {
36
40
  /** What `phantom plan` accepts after `plan`. */
37
41
  const USAGE = 'Use phantom plan, phantom plan pro, phantom plan max or phantom plan manage.';
38
42
  /**
39
- * `phantom plan`: the key's plan and how much of the week is used.
40
- * `phantom plan pro|max` prints a Stripe Checkout link that puts the plan on
41
- * this key, and opens it unless `--no-browser`. `phantom plan manage` does the
42
- * same for Stripe's billing page, where the card changes, the plan switches
43
- * and it cancels. Run by `run()`.
43
+ * `phantom plan`: the plan of the key's workspace and how much of the week is
44
+ * used. `phantom plan pro|max` prints a Stripe Checkout link that puts the
45
+ * plan on that workspace, and opens it unless `--no-browser`. `phantom plan
46
+ * manage` does the same for Stripe's billing page, where the card changes, the
47
+ * plan switches and it cancels; it sends the workspace credential `phantom
48
+ * login` saved, since a key can't manage billing. Run by `run()`.
44
49
  */
45
50
  export async function planCommand(input) {
46
51
  const { io, apiKey, table, baseUrl, flags, subcommand } = input;
@@ -57,7 +62,7 @@ export async function planCommand(input) {
57
62
  open(result.checkout_url);
58
63
  }
59
64
  else if (subcommand === 'manage') {
60
- const result = await planPortal(apiKey, baseUrl);
65
+ const result = await planPortal(savedManagement(input) ?? apiKey, baseUrl);
61
66
  out(result, table, (d) => `Open this link to manage billing: ${d.portal_url}`, io.stdout);
62
67
  open(result.portal_url);
63
68
  }
@@ -27,6 +27,10 @@ function credentials(input) {
27
27
  die('This workspace belongs to a different API address. Run phantom login for this address.', 'workspace_origin');
28
28
  return saved;
29
29
  }
30
+ /** The management credential `phantom login` saved for this API address, or null when it saved none. */
31
+ export function savedManagement(input) {
32
+ return existsSync(credentialPath(input.env)) ? credentials(input).management_credential : null;
33
+ }
30
34
  /** A read from the saved workspace, such as `/spend`, with its management credential. */
31
35
  export async function workspaceGet(input, path) {
32
36
  const saved = credentials(input);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phantomcodes/cli",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "AI inference for your coding agents. Route models, control spending, and fund your workspace.",
5
5
  "keywords": [
6
6
  "phantom",