feat(cli): checkout links name the CLI and the skill that sent them (#7177)

* feat(skills): every published skill reports its own run

`hyperframes events --skill=<name>` exists so a skill can say it ran, but
only reverse-any-video and figma asked the agent to call it, so the other
skills' use was invisible. Each of the nine published skills now opens with
a one-line usage beacon naming itself. The line says what it sends (the
skill's name only) and that the telemetry opt-out applies. The router's
`init` line also passes `--skill=hyperframes`, so renders of new projects
carry the skill.

check-core-skills fails a core skill that lacks its own beacon; each core
skill's size budget grows by 192 B for the line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(cli): checkout links name the CLI and the skill that sent them

Only `billing subscribe` marked its pricing link `from=cli`, and the
terminal's Press-Enter Pro checkout sent no return page, so a purchase made
from the terminal looked like one made on the site. Now:

- `pageUrl` adds `utm_source=cli` and `skill`: the one named, else the
  project's own `authoringSkill` from hyperframes.json.
- `billing` takes `--skill`. The terminal Pro checkout returns to the plans
  page marked `from=cli&skill=...`, and retries without the return page if
  the server does not allow it.
- Pricing links the server hands back (reverse's upgrade link, a refused
  media call's link) gain `from=cli` and the skill when they lack them.
- The Pro gates name their skill: reverse -> reverse-any-video, templates ->
  style-sampling, paid media calls -> media-use, in the CLI's printed fix and
  in those skills' billing commands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(cli): report a refused checkout return page, and say where --skill goes

When the server refuses the terminal checkout's return page, the CLI still
sells Pro without it, but that purchase loses its CLI origin. A
cli_billing_checkout_return_refused event now makes that visible.

The --skill help said the skill is recorded with the purchase. It is sent
with the pricing link; the purchase itself does not store it yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Michael Wang
2026-11-05 00:23:20 +00:00
committed by GitHub
co-authored by Claude Opus 5.5
parent b503e55098
commit a6e6717f2a
18 changed files with 256 additions and 61 deletions
+21 -1
View File
@@ -8,6 +8,7 @@ const terminal = vi.hoisted(() => ({
attended: false,
checkouts: 0,
checkoutError: null as unknown,
args: [] as unknown[][],
}));
const events = vi.hoisted(() => ({ failed: [] as unknown[], timeout: [] as unknown[] }));
const never = vi.hoisted(() => ({ paid: true }));
@@ -42,9 +43,10 @@ vi.mock("../heygen/plan.js", async (importOriginal) => {
return {
...real,
readOffer: async () => ({}),
createCheckout: async () => {
createCheckout: async (...args: unknown[]) => {
if (terminal.checkoutError) throw terminal.checkoutError;
terminal.checkouts++;
terminal.args.push(args);
return "https://checkout.stripe.com/c/pay/cs_test_1";
},
readPlan: async () => ({
@@ -69,6 +71,7 @@ afterEach(() => {
plan.calls = 0;
terminal.attended = false;
terminal.checkouts = 0;
terminal.args.length = 0;
terminal.checkoutError = null;
events.failed.length = 0;
events.timeout.length = 0;
@@ -92,6 +95,23 @@ describe("billing subscribe", () => {
expect(url.searchParams.get("rs")).toBe("rvs_abc");
expect(url.searchParams.get("workspace_hint")).toBe("sp-1");
});
it("names the skill that sent the person on the page and on the terminal checkout", async () => {
vi.spyOn(console, "log").mockImplementation(() => undefined);
vi.useFakeTimers();
const done = runCommand(billing, {
rawArgs: ["subscribe", "--feature", "templates", "--skill", "style-sampling"],
});
await vi.advanceTimersByTimeAsync(2000);
await done;
vi.useRealTimers();
const url = new URL(opened[0] ?? "");
expect(url.searchParams.get("from")).toBe("cli");
expect(url.searchParams.get("skill")).toBe("style-sampling");
expect(terminal.args).toEqual([
["plans", {}, undefined, { skill: "style-sampling", baseline: 0 }],
]);
});
});
describe("billing add-credits", () => {
+17 -4
View File
@@ -2,6 +2,7 @@ import { createInterface } from "node:readline/promises";
import { openBrowser } from "../auth/browser.js";
import {
addonBlocks,
checkoutSkill,
createCheckout,
money,
pageUrl,
@@ -40,14 +41,17 @@ function priceLine(
const WAIT_TIMEOUT_EXIT = 124;
type CheckoutSource = { skill?: string; baseline?: number };
async function openCheckout(
kind: "plans" | "credits",
offer: Offer,
missing: number | undefined,
signal: AbortSignal,
source: CheckoutSource,
): Promise<void> {
if (isUnattended()) {
console.log(`Checkout link: ${c.accent(await createCheckout(kind, offer, missing))}`);
console.log(`Checkout link: ${c.accent(await createCheckout(kind, offer, missing, source))}`);
return;
}
const rl = createInterface({ input: process.stdin, output: process.stdout });
@@ -56,21 +60,22 @@ async function openCheckout(
} finally {
rl.close();
}
await openBrowser(await createCheckout(kind, offer, missing));
await openBrowser(await createCheckout(kind, offer, missing, source));
}
async function offerCheckout(
kind: "plans" | "credits",
before: Plan | null,
signal: AbortSignal,
needed?: number,
needed: number | undefined,
source: CheckoutSource,
): Promise<CheckoutError | null> {
const offer = await readOffer();
const missing = needed ? needed - (before?.credits ?? 0) : undefined;
const line = priceLine(kind, offer, missing, needed);
if (line) console.log(line);
try {
await openCheckout(kind, offer, missing, signal);
await openCheckout(kind, offer, missing, signal, source);
return null;
} catch (error) {
if (signal.aborted) return null;
@@ -100,6 +105,11 @@ export default defineCommand({
description: "The feature that sent the person here, so a purchase is credited to it",
},
session: { type: "string", description: "The run to credit the purchase to (with --feature)" },
skill: {
type: "string",
description:
"The skill that sent the person here, sent with the pricing link (default: the project's own skill)",
},
timeout: { type: "string", description: "Seconds to wait (default 600)" },
},
// fallow-ignore-next-line complexity
@@ -110,6 +120,7 @@ export default defineCommand({
failCommand();
}
const needed = Number(args.needed) || undefined;
const skill = checkoutSkill(args.skill);
const before = await readPlan();
const done = (p: Plan | null) =>
action === "subscribe"
@@ -124,6 +135,7 @@ export default defineCommand({
tool: args.tool,
feature: args.feature,
rs: args.session,
skill,
});
console.log(`${action === "subscribe" ? "Plans" : "Credits"} page: ${c.accent(url)}`);
await openBrowser(url);
@@ -143,6 +155,7 @@ export default defineCommand({
before,
stop.signal,
needed,
{ skill, baseline: before?.credits },
);
if (checkoutFailure?.reason === "checkout_unavailable") {
giveUp.abort();
@@ -185,7 +185,7 @@ describe("reverse start", () => {
);
const dir = join(root, "rebuild");
await expect(run("--dir", dir)).rejects.toThrow(CliRuntimeError);
const command = `npx hyperframes billing subscribe --feature reverse --session ${SESSION}`;
const command = `npx hyperframes billing subscribe --feature reverse --skill reverse-any-video --session ${SESSION}`;
expect(output()).toMatchObject({
ok: false,
error: expect.stringContaining(command),
@@ -198,7 +198,7 @@ describe("reverse start", () => {
server.answer = recorded("free");
await run();
expect(output().reverse).toMatchObject({
subscribe_command: `npx hyperframes billing subscribe --feature reverse --session ${SESSION}`,
subscribe_command: `npx hyperframes billing subscribe --feature reverse --skill reverse-any-video --session ${SESSION}`,
});
});
+1 -1
View File
@@ -27,7 +27,7 @@ export const examples: Example[] = [
const SKILL = "reverse-any-video";
export function subscribeCommand(sessionId?: string): string {
return `npx hyperframes billing subscribe --feature reverse${sessionId ? ` --session ${sessionId}` : ""}`;
return `npx hyperframes billing subscribe --feature reverse --skill ${SKILL}${sessionId ? ` --session ${sessionId}` : ""}`;
}
async function freeFields(session: ReverseSession) {
+1 -1
View File
@@ -82,7 +82,7 @@ async function bundleUrl(pack: TemplatePack, retries = 1): Promise<string> {
if (res.status === 401) throw new PullRefused("Not signed in. Run `npx hyperframes auth login`.");
if (res.status === 402)
throw new PullRefused(
"Creator templates are part of HyperFrames Pro; nothing was downloaded. Run `npx hyperframes billing subscribe`: it opens the page and waits.",
"Creator templates are part of HyperFrames Pro; nothing was downloaded. Run `npx hyperframes billing subscribe --feature templates --skill style-sampling`: it opens the page and waits.",
);
if (res.status === 404) throw new PullRefused("That template version is no longer available.");
if (!res.ok) throw new PullRefused(`HeyGen could not hand over the template (${res.status}).`);
+113 -8
View File
@@ -1,12 +1,25 @@
import { mkdtempSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, describe, expect, it, vi } from "vitest";
vi.mock("../cloud/auth.js", () => ({
resolveCloudAuthHeaders: async () => ({ "x-api-key": "k" }),
resolveCloudBaseUrl: () => "https://api.example.test",
}));
const returnRefused = vi.hoisted(() => vi.fn());
vi.mock("../telemetry/events.js", () => ({ trackBillingCheckoutReturnRefused: returnRefused }));
const { addonBlocks, createCheckout, pageUrl, readOffer, readPlan, stripeCheckoutUrl } =
await import("./plan.js");
const {
addonBlocks,
checkoutSkill,
cliCheckoutLink,
createCheckout,
pageUrl,
readOffer,
readPlan,
stripeCheckoutUrl,
} = await import("./plan.js");
const asked: string[] = [];
const answer = (data: unknown) =>
@@ -48,18 +61,24 @@ describe("pageUrl", () => {
vi.stubEnv("HYPERFRAMES_PLANS_URL", "");
vi.stubEnv("HYPERFRAMES_CREDITS_URL", "");
vi.stubEnv("HYPERFRAMES_ENV", "prod");
expect(await pageUrl("plans")).toBe("https://hyperframes.studio/pricing?from=cli");
expect(await pageUrl("credits")).toBe("https://hyperframes.studio/pricing?from=cli#packs");
expect(await pageUrl("plans")).toBe(
"https://hyperframes.studio/pricing?from=cli&utm_source=cli",
);
expect(await pageUrl("credits")).toBe(
"https://hyperframes.studio/pricing?from=cli&utm_source=cli#packs",
);
expect(await pageUrl("plans", { feature: "reverse", rs: "rvs_x" })).toBe(
"https://hyperframes.studio/pricing?from=cli&feature=reverse&rs=rvs_x",
"https://hyperframes.studio/pricing?from=cli&utm_source=cli&feature=reverse&rs=rvs_x",
);
expect(await pageUrl("credits", { needed: 180, tool: "reverse" })).toBe(
"https://hyperframes.studio/pricing?from=cli&needed_credits=180&tool=reverse#packs",
"https://hyperframes.studio/pricing?from=cli&utm_source=cli&needed_credits=180&tool=reverse#packs",
);
vi.stubEnv("HYPERFRAMES_ENV", "dev");
expect(await pageUrl("plans")).toBe("https://hyperframes.studio/pricing?from=cli");
expect(await pageUrl("plans")).toBe(
"https://hyperframes.studio/pricing?from=cli&utm_source=cli",
);
vi.stubEnv("HYPERFRAMES_PLANS_URL", "https://example.test/plans");
expect(await pageUrl("plans")).toBe("https://example.test/plans?from=cli");
expect(await pageUrl("plans")).toBe("https://example.test/plans?from=cli&utm_source=cli");
});
it("carries the workspace the sign-in is bound to on every link, read from account.get", async () => {
@@ -168,3 +187,89 @@ describe("createCheckout", () => {
expect(sent[0]).toEqual({ quantity: 3, currency: "usd", unit_amount: 100 });
});
});
describe("where a purchase came from", () => {
const project = (skill: unknown) => {
const dir = mkdtempSync(join(tmpdir(), "hf-plan-"));
writeFileSync(join(dir, "hyperframes.json"), JSON.stringify({ authoringSkill: skill }));
return dir;
};
it("names the skill passed in, else the project's own, never a non-slug", () => {
expect(checkoutSkill("style-sampling", project("hyperframes"))).toBe("style-sampling");
expect(checkoutSkill(undefined, project("hyperframes"))).toBe("hyperframes");
expect(checkoutSkill("not a slug", project("hyperframes"))).toBe("hyperframes");
expect(checkoutSkill(undefined, project("../etc"))).toBeUndefined();
expect(checkoutSkill(undefined, mkdtempSync(join(tmpdir(), "hf-plan-")))).toBeUndefined();
});
it("puts the skill on the plans page", async () => {
signedOut();
vi.stubEnv("HYPERFRAMES_PLANS_URL", "");
expect(await pageUrl("plans", { skill: "media-use" })).toBe(
"https://hyperframes.studio/pricing?from=cli&utm_source=cli&skill=media-use",
);
});
it("marks the server's own pricing link as the CLI's, keeping what it already says", () => {
expect(cliCheckoutLink("https://hyperframes.studio/pricing?feature=reverse&rs=1", "x")).toBe(
"https://hyperframes.studio/pricing?feature=reverse&rs=1&from=cli&skill=x&utm_source=cli",
);
expect(cliCheckoutLink("https://hyperframes.studio/pricing?from=desktop&skill=y", "x")).toBe(
"https://hyperframes.studio/pricing?from=desktop&skill=y&utm_source=cli",
);
expect(cliCheckoutLink("https://pay.test/credits", "x")).toBe("https://pay.test/credits");
});
it("sends a terminal Pro checkout back to the plans page marked as the CLI's, with the skill", async () => {
vi.stubEnv("HYPERFRAMES_PLANS_URL", "");
const sent: Record<string, unknown>[] = [];
vi.stubGlobal("fetch", async (_url: string, init: { body: string }) => {
sent.push(JSON.parse(init.body));
return new Response(
JSON.stringify({ data: { url: "https://checkout.stripe.com/c/pay/cs_test_2" } }),
);
});
await createCheckout("plans", {}, undefined, { skill: "style-sampling", baseline: 120 });
expect(sent[0]!.return_url).toBe(
"https://hyperframes.studio/pricing?from=cli&skill=style-sampling&checkout=pro&from_credits=120",
);
});
it("still sells Pro, without the return page, when the server does not allow it", async () => {
const sent: Record<string, unknown>[] = [];
vi.stubGlobal("fetch", async (_url: string, init: { body: string }) => {
const body = JSON.parse(init.body) as Record<string, unknown>;
sent.push(body);
return body.return_url
? new Response(
JSON.stringify({ code: 400, message: "This return address is not allowed" }),
{
status: 400,
},
)
: new Response(
JSON.stringify({ data: { url: "https://checkout.stripe.com/c/pay/cs_test_3" } }),
);
});
expect(await createCheckout("plans", {})).toBe("https://checkout.stripe.com/c/pay/cs_test_3");
expect(sent).toHaveLength(2);
expect(sent[1]).not.toHaveProperty("return_url");
expect(sent[1]!.request_id).not.toBe(sent[0]!.request_id);
expect(returnRefused).toHaveBeenCalledTimes(1);
});
it("does not retry any other refusal", async () => {
returnRefused.mockClear();
let calls = 0;
vi.stubGlobal("fetch", async () => {
calls += 1;
return new Response(JSON.stringify({ message: "HyperFrames purchases are unavailable" }), {
status: 400,
});
});
await expect(createCheckout("plans", {})).rejects.toThrow(/purchases are unavailable/);
expect(calls).toBe(1);
expect(returnRefused).not.toHaveBeenCalled();
});
});
+70 -20
View File
@@ -1,6 +1,9 @@
// The HyperFrames plan and credits the signed-in account holds, and the web pages that change them.
import { randomUUID } from "node:crypto";
import { resolveCloudAuthHeaders, resolveCloudBaseUrl } from "../cloud/auth.js";
import { trackBillingCheckoutReturnRefused } from "../telemetry/events.js";
import { normalizeSkillSlug } from "../telemetry/skill.js";
import { readProjectConfig } from "../utils/projectConfig.js";
export interface Plan {
plan: string;
@@ -66,13 +69,37 @@ async function signedInSpace(): Promise<string | undefined> {
}
}
export function checkoutSkill(named?: unknown, projectDir = process.cwd()): string | undefined {
return normalizeSkillSlug(named) ?? readProjectConfig(projectDir)?.authoringSkill;
}
export function cliCheckoutLink(link: string, skill = checkoutSkill()): string {
if (!URL.canParse(link)) return link;
const url = new URL(link);
if (url.hostname !== new URL(webBase()).hostname) return link;
if (!url.searchParams.has("from")) url.searchParams.set("from", "cli");
if (skill && !url.searchParams.has("skill")) url.searchParams.set("skill", skill);
if (!url.searchParams.has("utm_source")) url.searchParams.set("utm_source", "cli");
return url.toString();
}
/** A plans or credits page link with what the web side reads, incl. the signed-in `workspace_hint`. */
export async function pageUrl(
kind: "plans" | "credits",
fields: { needed?: number; tool?: string; feature?: string; rs?: string; base?: string } = {},
fields: {
needed?: number;
tool?: string;
feature?: string;
rs?: string;
skill?: string;
base?: string;
} = {},
): Promise<string> {
const url = new URL(fields.base ?? (kind === "plans" ? plansUrl() : creditsUrl()));
url.searchParams.set("from", "cli");
url.searchParams.set("utm_source", "cli");
const skill = checkoutSkill(fields.skill);
if (skill) url.searchParams.set("skill", skill);
if (fields.needed) url.searchParams.set("needed_credits", String(fields.needed));
if (fields.tool) url.searchParams.set("tool", fields.tool);
if (fields.feature) url.searchParams.set("feature", fields.feature);
@@ -169,11 +196,24 @@ export class CheckoutError extends Error {
}
}
// `from=cli` on the return page is how a purchase made from the terminal is told apart from one made on the site.
function cliCheckoutReturn(skill?: string, baseline?: number): string {
const url = new URL(plansUrl());
url.searchParams.set("from", "cli");
if (skill) url.searchParams.set("skill", skill);
url.searchParams.set("checkout", "pro");
url.searchParams.set("from_credits", String(Math.max(0, Math.trunc(baseline ?? 0))));
return url.toString();
}
const RETURN_REFUSED = /return address is not allowed/i;
/** Creates the checkout with the CLI's own token and returns Stripe's page; throws when HeyGen refuses. */
export async function createCheckout(
kind: "plans" | "credits",
offer: Offer,
missing?: number,
source: { skill?: string; baseline?: number } = {},
): Promise<string> {
const addon = kind === "credits" ? offer.addon : undefined;
if (kind === "credits" && !addon)
@@ -181,26 +221,36 @@ export async function createCheckout(
"checkout_unavailable",
"Credits are not on sale for this account right now.",
);
const body = addon
? {
quantity: addonBlocks(addon, missing),
currency: addon.currency,
unit_amount: addon.unitAmount,
}
: { plan_name: "pro", period: "month", request_id: randomUUID() };
const res = await fetch(
`${billingBaseUrl()}/v1/payment/hyperframes/${addon ? "addon.checkout" : "checkout"}`,
{
method: "POST",
headers: {
...(await resolveCloudAuthHeaders()),
accept: "application/json",
"content-type": "application/json",
},
body: JSON.stringify(body),
signal: AbortSignal.timeout(20_000),
if (addon)
return postCheckout("addon.checkout", {
quantity: addonBlocks(addon, missing),
currency: addon.currency,
unit_amount: addon.unitAmount,
});
const pro = () => ({ plan_name: "pro", period: "month", request_id: randomUUID() });
const returnUrl = cliCheckoutReturn(checkoutSkill(source.skill), source.baseline);
try {
return await postCheckout("checkout", { ...pro(), return_url: returnUrl });
} catch (error) {
// A server whose allow-list lacks the plans page still sells Pro, only without the CLI's origin.
const refused = error instanceof CheckoutError && error.reason === "checkout_rejected";
if (!refused || !RETURN_REFUSED.test(error.message)) throw error;
trackBillingCheckoutReturnRefused();
return postCheckout("checkout", pro());
}
}
async function postCheckout(route: string, body: Record<string, unknown>): Promise<string> {
const res = await fetch(`${billingBaseUrl()}/v1/payment/hyperframes/${route}`, {
method: "POST",
headers: {
...(await resolveCloudAuthHeaders()),
accept: "application/json",
"content-type": "application/json",
},
).catch((error: unknown) => {
body: JSON.stringify(body),
signal: AbortSignal.timeout(20_000),
}).catch((error: unknown) => {
throw new CheckoutError(
"checkout_network",
`Could not reach HeyGen to open a checkout: ${error instanceof Error ? error.message : String(error)}`,
+2 -2
View File
@@ -209,10 +209,10 @@ describe("reverseUpgradeUrl", () => {
await reverseUpgradeUrl({ sessionId: SESSION, upgradeUrl: "https://u.test/p?rs=1" }),
).toBe("https://u.test/p?rs=1");
expect(await reverseUpgradeUrl({ sessionId: SESSION })).toBe(
`https://hyperframes.studio/pricing?from=cli&feature=reverse&rs=${SESSION}`,
`https://hyperframes.studio/pricing?from=cli&utm_source=cli&skill=reverse-any-video&feature=reverse&rs=${SESSION}`,
);
expect(await reverseUpgradeUrl()).toBe(
"https://hyperframes.studio/pricing?from=cli&feature=reverse",
"https://hyperframes.studio/pricing?from=cli&utm_source=cli&skill=reverse-any-video&feature=reverse",
);
});
+5 -4
View File
@@ -2,7 +2,9 @@
import { resolveCloudAuthHeaders, resolveCloudBaseUrl } from "../cloud/auth.js";
import { trackReverseStartUnrecorded, type ReverseUnrecordedCause } from "../telemetry/events.js";
import { normalizeReverseSessionId } from "../utils/projectConfig.js";
import { pageUrl, readPlan } from "./plan.js";
import { cliCheckoutLink, pageUrl, readPlan } from "./plan.js";
const SKILL = "reverse-any-video";
export type ReversePlan = "free" | "pro" | "unknown";
export type ReverseGate = "record" | "block";
@@ -65,9 +67,8 @@ export async function reverseUpgradeUrl(session?: {
upgradeUrl?: string | null;
}): Promise<string | null> {
if (session?.upgradeUrl === null) return null;
return (
session?.upgradeUrl ?? (await pageUrl("plans", { feature: "reverse", rs: session?.sessionId }))
);
if (session?.upgradeUrl) return cliCheckoutLink(session.upgradeUrl, SKILL);
return pageUrl("plans", { feature: "reverse", rs: session?.sessionId, skill: SKILL });
}
/**
+1 -1
View File
@@ -160,7 +160,7 @@ describe("runJob", () => {
reply(402, { error: { code: "hf_subscription_required", message: "no plan" } }),
);
await expect(runJob(X, {}, "k")).rejects.toMatchObject({
fix: "Subscribe: https://hyperframes.studio/pricing?from=cli",
fix: "Subscribe: https://hyperframes.studio/pricing?from=cli&utm_source=cli&skill=media-use",
});
vi.stubGlobal("fetch", async () =>
reply(402, { code: "hf_usage_exhausted", url: "https://pay.test/credits" }),
+8 -6
View File
@@ -11,7 +11,9 @@ import { refreshIfNeeded, resolveCloudAuthHeaders, resolveCloudBaseUrl } from ".
import { HyperframesApiError, HyperframesCloudClient } from "../cloud/_gen/client.js";
import { Fix } from "../measure/media.js";
import { creditLimit, creditsSpent } from "../media-use/lib/credit-limit.mjs";
import { pageUrl } from "./plan.js";
import { cliCheckoutLink, pageUrl } from "./plan.js";
const MEDIA_USE_SKILL = "media-use";
export interface Job {
id: string;
@@ -104,13 +106,13 @@ async function refusal(status: number, body: unknown, estimate?: number): Promis
// The fix is the one line the agent relays as printed; the problem says how to wait for the person.
if (/hf_subscription_required/i.test(code))
return new Refused(
`this is a HyperFrames Pro feature; nothing was charged. Run \`npx hyperframes billing subscribe\`: it opens the page and waits`,
`Subscribe: ${url ?? (await pageUrl("plans", { needed }))}`,
`this is a HyperFrames Pro feature; nothing was charged. Run \`npx hyperframes billing subscribe --skill ${MEDIA_USE_SKILL}\`: it opens the page and waits`,
`Subscribe: ${url ? cliCheckoutLink(url, MEDIA_USE_SKILL) : await pageUrl("plans", { needed, skill: MEDIA_USE_SKILL })}`,
);
if (/hf_usage_exhausted/i.test(code))
return new Refused(
`out of HyperFrames credits (this step needs ${needs}${balance}); nothing was charged. Run \`npx hyperframes billing add-credits${needed ? ` --needed ${needed}` : ""}\`: it opens the page and waits`,
`Buy add-on credits: ${url ?? (await pageUrl("credits", { needed }))}`,
`out of HyperFrames credits (this step needs ${needs}${balance}); nothing was charged. Run \`npx hyperframes billing add-credits${needed ? ` --needed ${needed}` : ""} --skill ${MEDIA_USE_SKILL}\`: it opens the page and waits`,
`Buy add-on credits: ${url ? cliCheckoutLink(url, MEDIA_USE_SKILL) : await pageUrl("credits", { needed, skill: MEDIA_USE_SKILL })}`,
);
if (/api_key_required/i.test(code))
return new Refused(
@@ -125,7 +127,7 @@ async function refusal(status: number, body: unknown, estimate?: number): Promis
if (status === 402 || /insufficient|credit|usage_exhausted|quota/i.test(code))
return new Refused(
`HeyGen says there is not enough credit (${code || status})`,
"buy add-on credits at https://app.heygen.com, or sign in with npx hyperframes auth login to use the plan's allowance",
"buy add-on credits at https://app.heygen.com/?utm_source=cli, or sign in with npx hyperframes auth login to use the plan's allowance",
);
if (/content_policy/i.test(code))
return new Refused(
+4
View File
@@ -1017,6 +1017,10 @@ export function trackBillingCheckoutFailed(props: {
trackEvent("cli_billing_checkout_failed", { reason: props.reason });
}
export function trackBillingCheckoutReturnRefused(): void {
trackEvent("cli_billing_checkout_return_refused", {});
}
// `billing` waited out its timeout with no payment: the person did not finish, nothing is broken.
export function trackBillingWaitTimeout(props: { action: "subscribe" | "add-credits" }): void {
trackEvent("cli_billing_wait_timeout", { action: props.action });
+1 -1
View File
@@ -48,7 +48,7 @@ test("reverse builds the project with init --video and asks for the run's total
);
assert.match(
start,
/add up what each refused step\s+needs, and run `npx hyperframes billing (?:top-up|add-credits) --needed <total>` once for that total/,
/add up what each refused step\s+needs, and run `npx hyperframes billing (?:top-up|add-credits) --needed <total>(?: --skill reverse-any-video)?` once for that total/,
);
assert.doesNotMatch(read("SKILL.md"), /copy the video into the project/);
assert.match(read("SKILL.md"), /`init --video` put the video in/);
+3 -3
View File
@@ -18,7 +18,7 @@
"files": 13
},
"media-use": {
"hash": "00b59a0640cb5086",
"hash": "b17f9033fa158cee",
"files": 118
},
"remotion-to-hyperframes": {
@@ -26,7 +26,7 @@
"files": 76
},
"reverse-any-video": {
"hash": "49f0f8041808abc6",
"hash": "27aee76a757312f9",
"files": 5
},
"slideshow": {
@@ -34,7 +34,7 @@
"files": 2
},
"style-sampling": {
"hash": "57ab128ce08aa2ac",
"hash": "ef12d71dbbfd7513",
"files": 2
}
}
@@ -228,9 +228,9 @@ function errorCode(body) {
export function billingRefusal(e) {
const code = e?.body ? errorCode(e.body) : null;
if (code === "hf_subscription_required")
return "This needs a HyperFrames plan. Run `npx hyperframes billing subscribe`: it opens the page and waits.";
return "This needs a HyperFrames plan. Run `npx hyperframes billing subscribe --skill media-use`: it opens the page and waits.";
if (code === "hf_usage_exhausted")
return "Out of HyperFrames credits. Run `npx hyperframes billing add-credits`: it opens the page and waits.";
return "Out of HyperFrames credits. Run `npx hyperframes billing add-credits --skill media-use`: it opens the page and waits.";
if (code === "api_key_required")
return "This HeyGen feature isn't available with this sign-in yet. Nothing was charged. Use a HeyGen API key, or wait for HyperFrames billing in the CLI.";
return null;
@@ -392,11 +392,11 @@ test("a refused HyperFrames-plan call becomes one line with the billing command"
});
assert.equal(
heygenMessage(refused("hf_subscription_required")),
"This needs a HyperFrames plan. Run `npx hyperframes billing subscribe`: it opens the page and waits.",
"This needs a HyperFrames plan. Run `npx hyperframes billing subscribe --skill media-use`: it opens the page and waits.",
);
assert.equal(
heygenMessage(refused("hf_usage_exhausted")),
"Out of HyperFrames credits. Run `npx hyperframes billing add-credits`: it opens the page and waits.",
"Out of HyperFrames credits. Run `npx hyperframes billing add-credits --skill media-use`: it opens the page and waits.",
);
assert.match(
heygenMessage({ status: 403, body: JSON.stringify({ error: { code: "api_key_required" } }) }),
+2 -2
View File
@@ -39,7 +39,7 @@ one. Never sign in with an API key to get past Pro: that signs in a HeyGen app a
## Signed in on Free
Reverse is part of Pro. Say why in one line, then run the `reverse.subscribe_command` from `reverse start` exactly as
printed (`npx hyperframes billing subscribe --feature reverse --session <id>`): it opens the plans page in the person's
printed (`npx hyperframes billing subscribe --feature reverse --skill reverse-any-video --session <id>`): it opens the plans page in the person's
browser, credits the purchase to this run, and waits until they are on Pro, so the run goes on by itself. Start nothing
before it finishes. Give the `reverse.upgrade_url`, when it isn't `null`, as a link in the same message. For example:
@@ -64,7 +64,7 @@ the end of a run. `reverse start` and `auth status` are for the sign-in: never r
A refused step prints what it needs and the command that fixes it (buy add-on credits, or pick a plan). Shots are launched all
at once, so several refuse together: wait until every launched step has answered, add up what each refused step
needs, and run `npx hyperframes billing add-credits --needed <total>` once for that total, never one step at a time. If a
needs, and run `npx hyperframes billing add-credits --needed <total> --skill reverse-any-video` once for that total, never one step at a time. If a
refusal prints no amount, run plain `billing add-credits` for that one. It opens the add-on credits page and waits until the balance
covers the total; give the refusal's `url` (on an older CLI, the link in its `fix`) as a link in the same message.
Then relaunch every refused step. Never trim the plan to fit.
+1 -1
View File
@@ -32,7 +32,7 @@ The person named a template, or their topic fits only one: go on with it. Otherw
Run `npx hyperframes auth status` first, every time, resuming included. It is for the sign-in: never repeat its plan or credits line to the person.
- **Not signed in.** Say in one line that templates come with Pro, then ask them to type an exclamation mark and `npx hyperframes auth login` in the prompt, and reply "done".
- **Signed in on Free.** Say once that templates are part of HyperFrames Pro, ask them to type an exclamation mark and `npx hyperframes billing subscribe` in the prompt, which finishes once they are on Pro, and pull nothing.
- **Signed in on Free.** Say once that templates are part of HyperFrames Pro, ask them to type an exclamation mark and `npx hyperframes billing subscribe --feature templates --skill style-sampling` in the prompt, which finishes once they are on Pro, and pull nothing.
- **Signed in on Pro.** One line, then pull.
## Pull