mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 07:50:13 +00:00
feat(cli): show and open the page to manage or cancel a paid plan (#7784)
* feat(cli): show and open the page to manage or cancel a paid plan * chore(cli): drop two comments the names already carry
This commit is contained in:
@@ -2547,13 +2547,20 @@ account shows the change, so an agent's run carries on by itself. The page is on
|
||||
the web app at hyperframes.studio. `HYPERFRAMES_PLANS_URL` and
|
||||
`HYPERFRAMES_CREDITS_URL` point it at another page.
|
||||
|
||||
With no action it shows your plan and, on a paid plan, the page where you manage or cancel it
|
||||
(hyperframes.studio/billing, `HYPERFRAMES_BILLING_URL` points it elsewhere). `--manage` opens that page;
|
||||
when no one is at the terminal it prints the link instead.
|
||||
|
||||
```bash
|
||||
npx hyperframes billing
|
||||
npx hyperframes billing --manage
|
||||
npx hyperframes billing subscribe
|
||||
npx hyperframes billing add-credits --needed 180
|
||||
```
|
||||
|
||||
| Flag | Description |
|
||||
| ----------- | -------------------------------------------------------------------------- |
|
||||
| `--manage` | Open the page to manage or cancel your plan |
|
||||
| `--needed` | Credits the waiting step needs; `add-credits` waits until the balance covers it |
|
||||
| `--feature` | The feature that sent the person here, so a purchase is credited to it |
|
||||
| `--session` | The run to credit the purchase to, with `--feature` |
|
||||
|
||||
@@ -168,6 +168,7 @@ describe("auth status — persisted user block surface", () => {
|
||||
const text = stdout.join("\n");
|
||||
expect(text).toContain("pro plan, 25,000 credits");
|
||||
expect(text).not.toContain("balance unavailable");
|
||||
expect(text).toMatch(/^Manage or cancel your plan: https:\/\/hyperframes\.studio\/billing\?/m);
|
||||
});
|
||||
|
||||
it("surfaces the persisted user block (with resolved display_name) for a file credential", async () => {
|
||||
|
||||
@@ -32,7 +32,7 @@ import {
|
||||
import { refreshIfNeeded } from "../../cloud/auth.js";
|
||||
import { getSystemMeta } from "../../telemetry/system.js";
|
||||
import { c } from "../../ui/colors.js";
|
||||
import { pageUrl, readPlan, type Plan } from "../../heygen/plan.js";
|
||||
import { MANAGE_LABEL, pageUrl, readPlan, type Plan } from "../../heygen/plan.js";
|
||||
import { resolveMusic, resolveVoice } from "../../audio/providers.js";
|
||||
import {
|
||||
buildUnconfiguredJson,
|
||||
@@ -66,7 +66,7 @@ interface VerifiedStatus {
|
||||
apiError: string | null;
|
||||
/** The HyperFrames plan and credits, when the server (or the mock) answers. */
|
||||
plan?: Plan | null;
|
||||
upgradeUrl?: string;
|
||||
planUrl?: string;
|
||||
}
|
||||
|
||||
/** True for credentials resolved from the HyperFrames store (not env). */
|
||||
@@ -284,7 +284,7 @@ function persistedUserJson(u: StoredUserInfo | null): Record<string, unknown> |
|
||||
async function printHumanStatus(s: VerifiedStatus): Promise<void> {
|
||||
const rows = collectStatusRows({
|
||||
...s,
|
||||
...(s.plan?.plan === "none" ? { upgradeUrl: await pageUrl("plans") } : {}),
|
||||
...(s.plan ? { planUrl: await pageUrl(s.plan.plan === "none" ? "plans" : "manage") } : {}),
|
||||
});
|
||||
for (const [label, value] of rows) console.log(`${c.bold(label)} ${value}`);
|
||||
}
|
||||
@@ -311,9 +311,10 @@ function collectStatusRows(s: VerifiedStatus): [string, string][] {
|
||||
rows.push([
|
||||
"HyperFrames:",
|
||||
plan.plan === "none"
|
||||
? `Free · Upgrade to Pro: ${s.upgradeUrl}${tag}`
|
||||
? `Free · Upgrade to Pro: ${s.planUrl}${tag}`
|
||||
: `${plan.plan} plan, ${plan.credits.toLocaleString("en-US")} credits${tag}`,
|
||||
]);
|
||||
if (plan.plan !== "none" && s.planUrl) rows.push([MANAGE_LABEL, s.planUrl]);
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
@@ -177,6 +177,41 @@ describe("billing add-credits", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("billing with no action", () => {
|
||||
const printed = async (rawArgs: string[], read: { plan: string; credits: number } | null) => {
|
||||
held.reads = [read];
|
||||
const log = vi.spyOn(console, "log").mockImplementation(() => undefined);
|
||||
await runCommand(billing, { rawArgs });
|
||||
return log.mock.calls.flat().join("\n");
|
||||
};
|
||||
const MANAGE =
|
||||
/^Manage or cancel your plan: https:\/\/hyperframes\.studio\/billing\?from=cli&utm_source=cli&workspace_hint=sp-1$/m;
|
||||
|
||||
it("shows a paid plan and the page that manages or cancels it, opening nothing", async () => {
|
||||
const out = await printed([], { plan: "pro", credits: 500 });
|
||||
expect(out).toContain("HyperFrames: pro plan, 500 credits");
|
||||
expect(out).toMatch(MANAGE);
|
||||
expect(opened).toEqual([]);
|
||||
});
|
||||
|
||||
it("shows Free with no manage line", async () => {
|
||||
const out = await printed([], { plan: "none", credits: 0 });
|
||||
expect(out).toContain("HyperFrames: Free");
|
||||
expect(out).not.toContain("Manage or cancel");
|
||||
});
|
||||
|
||||
it("--manage opens that page at a terminal", async () => {
|
||||
terminal.attended = true;
|
||||
expect(await printed(["--manage"], { plan: "pro", credits: 500 })).toMatch(MANAGE);
|
||||
expect(new URL(opened[0] ?? "").pathname).toBe("/billing");
|
||||
});
|
||||
|
||||
it("--manage only prints the link when no one is at the terminal", async () => {
|
||||
expect(await printed(["--manage"], null)).toMatch(MANAGE);
|
||||
expect(opened).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("billing without a terminal", () => {
|
||||
it("prints Stripe's checkout link instead of waiting for Enter, and opens only the pricing page", async () => {
|
||||
const log = vi.spyOn(console, "log").mockImplementation(() => undefined);
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
addonBlocks,
|
||||
checkoutSkill,
|
||||
createCheckout,
|
||||
MANAGE_LABEL,
|
||||
money,
|
||||
pageUrl,
|
||||
readOffer,
|
||||
@@ -128,15 +129,29 @@ function reportCheckoutFailure(error: unknown): CheckoutError | null {
|
||||
return error;
|
||||
}
|
||||
|
||||
async function showPlan(open: boolean): Promise<void> {
|
||||
const plan = await readPlan();
|
||||
console.log(`HyperFrames: ${plan ? describe(plan) : "plan unavailable"}`);
|
||||
if (plan?.plan === "none" && !open) return;
|
||||
const url = await pageUrl("manage");
|
||||
console.log(`${MANAGE_LABEL} ${c.accent(url)}`);
|
||||
if (open && !isUnattended()) await openBrowser(url);
|
||||
}
|
||||
|
||||
/** Opens the plans or credits page, then waits until the account shows the change, so the run continues on its own. */
|
||||
export default defineCommand({
|
||||
meta: {
|
||||
name: "billing",
|
||||
description:
|
||||
"Open the HyperFrames plans page (subscribe) or buy add-on credits, used separately from your plan's monthly credits (add-credits), and wait until the person is done",
|
||||
"Show your HyperFrames plan and where to manage or cancel it (--manage opens that page), open the plans page (subscribe) or buy add-on credits, used separately from your plan's monthly credits (add-credits), and wait until the person is done",
|
||||
},
|
||||
args: {
|
||||
action: { type: "positional", description: "subscribe | add-credits", required: true },
|
||||
action: { type: "positional", description: "subscribe | add-credits", required: false },
|
||||
manage: {
|
||||
type: "boolean",
|
||||
description:
|
||||
"Open the page to manage or cancel your plan (prints the link when no one is at the terminal)",
|
||||
},
|
||||
needed: {
|
||||
type: "string",
|
||||
description: "Credits the waiting step needs (add-credits waits until the balance covers it)",
|
||||
@@ -156,6 +171,7 @@ export default defineCommand({
|
||||
},
|
||||
// fallow-ignore-next-line complexity
|
||||
async run({ args }) {
|
||||
if (args.action === undefined) return showPlan(args.manage === true);
|
||||
const action = String(args.action);
|
||||
if (action !== "subscribe" && action !== "add-credits") {
|
||||
console.error(c.error("Use `billing subscribe` or `billing add-credits`."));
|
||||
|
||||
@@ -66,7 +66,7 @@ const GROUPS: Group[] = [
|
||||
"Measure a video file: clock, cuts, events, frames, motion, crops, boxes, eases, look",
|
||||
],
|
||||
["reverse", "Open a reverse-any-video run: note it with HeyGen, then probe the video"],
|
||||
["billing", "Open the HyperFrames plans or credits page and wait until it is done"],
|
||||
["billing", "Show your plan and where to manage or cancel it, or buy a plan or credits"],
|
||||
["templates", "Pull a style template into this project (HyperFrames Pro)"],
|
||||
["info", "Print project metadata"],
|
||||
["compositions", "List all compositions in a project"],
|
||||
|
||||
@@ -81,6 +81,16 @@ describe("pageUrl", () => {
|
||||
expect(await pageUrl("plans")).toBe("https://example.test/plans?from=cli&utm_source=cli");
|
||||
});
|
||||
|
||||
it("links the page that manages or cancels the plan, outside the app", async () => {
|
||||
signedOut();
|
||||
vi.stubEnv("HYPERFRAMES_BILLING_URL", "");
|
||||
expect(await pageUrl("manage")).toBe(
|
||||
"https://hyperframes.studio/billing?from=cli&utm_source=cli",
|
||||
);
|
||||
vi.stubEnv("HYPERFRAMES_BILLING_URL", "https://example.test/billing");
|
||||
expect(await pageUrl("manage")).toBe("https://example.test/billing?from=cli&utm_source=cli");
|
||||
});
|
||||
|
||||
it("carries the workspace the sign-in is bound to on every link, read from account.get", async () => {
|
||||
signedInAs(SPACE);
|
||||
vi.stubEnv("HYPERFRAMES_PLANS_URL", "");
|
||||
|
||||
@@ -74,6 +74,10 @@ export async function readPlan(stop?: AbortSignal): Promise<Plan | null> {
|
||||
const webBase = () => "https://hyperframes.studio";
|
||||
const plansUrl = () => process.env["HYPERFRAMES_PLANS_URL"] || `${webBase()}/pricing`;
|
||||
const creditsUrl = () => process.env["HYPERFRAMES_CREDITS_URL"] || `${webBase()}/pricing`;
|
||||
const manageUrl = () => process.env["HYPERFRAMES_BILLING_URL"] || `${webBase()}/billing`;
|
||||
const PAGES = { plans: plansUrl, credits: creditsUrl, manage: manageUrl };
|
||||
|
||||
export const MANAGE_LABEL = "Manage or cancel your plan:";
|
||||
|
||||
async function signedInSpace(): Promise<string | undefined> {
|
||||
try {
|
||||
@@ -104,9 +108,9 @@ export function cliCheckoutLink(link: string, skill = checkoutSkill()): string {
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
/** A plans or credits page link with what the web side reads, incl. the signed-in `workspace_hint`. */
|
||||
/** A plans, credits or plan-management page link with what the web side reads, incl. the signed-in `workspace_hint`. */
|
||||
export async function pageUrl(
|
||||
kind: "plans" | "credits",
|
||||
kind: keyof typeof PAGES,
|
||||
fields: {
|
||||
needed?: number;
|
||||
tool?: string;
|
||||
@@ -116,7 +120,7 @@ export async function pageUrl(
|
||||
base?: string;
|
||||
} = {},
|
||||
): Promise<string> {
|
||||
const url = new URL(fields.base ?? (kind === "plans" ? plansUrl() : creditsUrl()));
|
||||
const url = new URL(fields.base ?? PAGES[kind]());
|
||||
url.searchParams.set("from", "cli");
|
||||
url.searchParams.set("utm_source", "cli");
|
||||
const skill = checkoutSkill(fields.skill);
|
||||
|
||||
Reference in New Issue
Block a user