@usenaive-sdk/cli 0.12.2 → 0.13.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/README.md +76 -5
- package/dist/client.d.ts +74 -1
- package/dist/client.js +351 -17
- package/dist/client.js.map +1 -1
- package/dist/commands/aeo.js +69 -27
- package/dist/commands/aeo.js.map +1 -1
- package/dist/commands/app-data.js +29 -11
- package/dist/commands/app-data.js.map +1 -1
- package/dist/commands/apps.d.ts +7 -0
- package/dist/commands/apps.js +255 -18
- package/dist/commands/apps.js.map +1 -1
- package/dist/commands/audio.d.ts +9 -0
- package/dist/commands/audio.js +391 -0
- package/dist/commands/audio.js.map +1 -0
- package/dist/commands/auth.d.ts +31 -0
- package/dist/commands/auth.js +403 -0
- package/dist/commands/auth.js.map +1 -0
- package/dist/commands/billing.js +12 -12
- package/dist/commands/billing.js.map +1 -1
- package/dist/commands/brain.d.ts +2 -0
- package/dist/commands/brain.js +1255 -0
- package/dist/commands/brain.js.map +1 -0
- package/dist/commands/browser.js +35 -8
- package/dist/commands/browser.js.map +1 -1
- package/dist/commands/business.js +117 -16
- package/dist/commands/business.js.map +1 -1
- package/dist/commands/clone.d.ts +2 -0
- package/dist/commands/clone.js +203 -0
- package/dist/commands/clone.js.map +1 -0
- package/dist/commands/companies.d.ts +8 -0
- package/dist/commands/companies.js +137 -47
- package/dist/commands/companies.js.map +1 -1
- package/dist/commands/company-data.d.ts +2 -0
- package/dist/commands/company-data.js +168 -0
- package/dist/commands/company-data.js.map +1 -0
- package/dist/commands/compute.js +10 -3
- package/dist/commands/compute.js.map +1 -1
- package/dist/commands/config.d.ts +2 -0
- package/dist/commands/config.js +36 -0
- package/dist/commands/config.js.map +1 -0
- package/dist/commands/connections.d.ts +6 -0
- package/dist/commands/connections.js +29 -1
- package/dist/commands/connections.js.map +1 -1
- package/dist/commands/domains.js +1 -1
- package/dist/commands/ecommerce.js +19 -9
- package/dist/commands/ecommerce.js.map +1 -1
- package/dist/commands/email.js +56 -9
- package/dist/commands/email.js.map +1 -1
- package/dist/commands/env.d.ts +3 -3
- package/dist/commands/env.js +68 -4
- package/dist/commands/env.js.map +1 -1
- package/dist/commands/formation.js +3 -3
- package/dist/commands/identity.js +4 -3
- package/dist/commands/identity.js.map +1 -1
- package/dist/commands/images.js +87 -13
- package/dist/commands/images.js.map +1 -1
- package/dist/commands/init.d.ts +3 -0
- package/dist/commands/init.js +39 -36
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/jobs.js +1 -0
- package/dist/commands/jobs.js.map +1 -1
- package/dist/commands/keys.js +26 -3
- package/dist/commands/keys.js.map +1 -1
- package/dist/commands/legacy-auth.d.ts +27 -0
- package/dist/commands/legacy-auth.js +64 -0
- package/dist/commands/legacy-auth.js.map +1 -0
- package/dist/commands/llm.js +13 -0
- package/dist/commands/llm.js.map +1 -1
- package/dist/commands/login.js +2 -0
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/loops.d.ts +2 -0
- package/dist/commands/loops.js +260 -0
- package/dist/commands/loops.js.map +1 -0
- package/dist/commands/media.js +3 -3
- package/dist/commands/media.js.map +1 -1
- package/dist/commands/mobile.d.ts +4 -0
- package/dist/commands/mobile.js +382 -0
- package/dist/commands/mobile.js.map +1 -0
- package/dist/commands/payments.d.ts +2 -0
- package/dist/commands/payments.js +131 -0
- package/dist/commands/payments.js.map +1 -0
- package/dist/commands/people.d.ts +2 -0
- package/dist/commands/people.js +193 -0
- package/dist/commands/people.js.map +1 -0
- package/dist/commands/phone.js +3 -3
- package/dist/commands/phone.js.map +1 -1
- package/dist/commands/projects.d.ts +13 -0
- package/dist/commands/projects.js +220 -0
- package/dist/commands/projects.js.map +1 -0
- package/dist/commands/register.js +16 -8
- package/dist/commands/register.js.map +1 -1
- package/dist/commands/sandbox.d.ts +2 -0
- package/dist/commands/sandbox.js +245 -0
- package/dist/commands/sandbox.js.map +1 -0
- package/dist/commands/search.js +26 -12
- package/dist/commands/search.js.map +1 -1
- package/dist/commands/seo.js +16 -8
- package/dist/commands/seo.js.map +1 -1
- package/dist/commands/sessions.d.ts +6 -0
- package/dist/commands/sessions.js +109 -0
- package/dist/commands/sessions.js.map +1 -0
- package/dist/commands/social-data.d.ts +2 -0
- package/dist/commands/social-data.js +244 -0
- package/dist/commands/social-data.js.map +1 -0
- package/dist/commands/social.js +8 -6
- package/dist/commands/social.js.map +1 -1
- package/dist/commands/teams.d.ts +69 -0
- package/dist/commands/teams.js +503 -0
- package/dist/commands/teams.js.map +1 -0
- package/dist/commands/up.d.ts +150 -0
- package/dist/commands/up.js +415 -15
- package/dist/commands/up.js.map +1 -1
- package/dist/commands/usage.js +15 -4
- package/dist/commands/usage.js.map +1 -1
- package/dist/commands/use.d.ts +9 -0
- package/dist/commands/use.js +76 -11
- package/dist/commands/use.js.map +1 -1
- package/dist/commands/users.d.ts +8 -0
- package/dist/commands/users.js +28 -9
- package/dist/commands/users.js.map +1 -1
- package/dist/commands/vault.js +28 -1
- package/dist/commands/vault.js.map +1 -1
- package/dist/commands/video.js +190 -270
- package/dist/commands/video.js.map +1 -1
- package/dist/commands/voice.d.ts +2 -0
- package/dist/commands/voice.js +516 -0
- package/dist/commands/voice.js.map +1 -0
- package/dist/commands/wallet.d.ts +2 -0
- package/dist/commands/wallet.js +244 -0
- package/dist/commands/wallet.js.map +1 -0
- package/dist/commands/whoami.js +17 -1
- package/dist/commands/whoami.js.map +1 -1
- package/dist/config.d.ts +24 -1
- package/dist/config.js +36 -7
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +290 -20
- package/dist/index.js.map +1 -1
- package/dist/lib/brain-select.d.ts +193 -0
- package/dist/lib/brain-select.js +403 -0
- package/dist/lib/brain-select.js.map +1 -0
- package/dist/lib/cli-validation.d.ts +12 -0
- package/dist/lib/cli-validation.js +46 -0
- package/dist/lib/cli-validation.js.map +1 -0
- package/dist/lib/deprecation.d.ts +158 -0
- package/dist/lib/deprecation.js +140 -0
- package/dist/lib/deprecation.js.map +1 -0
- package/dist/lib/duration.d.ts +8 -0
- package/dist/lib/duration.js +11 -0
- package/dist/lib/duration.js.map +1 -0
- package/dist/lib/http-response.d.ts +11 -0
- package/dist/lib/http-response.js +96 -0
- package/dist/lib/http-response.js.map +1 -0
- package/dist/lib/pricing.d.ts +132 -0
- package/dist/lib/pricing.js +148 -0
- package/dist/lib/pricing.js.map +1 -0
- package/dist/lib/stream-frames.d.ts +114 -0
- package/dist/lib/stream-frames.js +169 -0
- package/dist/lib/stream-frames.js.map +1 -0
- package/dist/lib/teams-catalog.d.ts +141 -0
- package/dist/lib/teams-catalog.js +765 -0
- package/dist/lib/teams-catalog.js.map +1 -0
- package/dist/lib/unknown-command.d.ts +57 -0
- package/dist/lib/unknown-command.js +93 -0
- package/dist/lib/unknown-command.js.map +1 -0
- package/dist/lib/version-check.d.ts +26 -0
- package/dist/lib/version-check.js +21 -0
- package/dist/lib/version-check.js.map +1 -0
- package/dist/output.d.ts +119 -10
- package/dist/output.js +309 -15
- package/dist/output.js.map +1 -1
- package/dist/prompt.d.ts +17 -0
- package/dist/prompt.js +70 -0
- package/dist/prompt.js.map +1 -0
- package/package.json +11 -6
- package/dist/commands/billing-client.d.ts +0 -2
- package/dist/commands/billing-client.js +0 -271
- package/dist/commands/billing-client.js.map +0 -1
- package/dist/commands/crm-app.d.ts +0 -2
- package/dist/commands/crm-app.js +0 -306
- package/dist/commands/crm-app.js.map +0 -1
- package/dist/commands/crm.d.ts +0 -2
- package/dist/commands/crm.js +0 -319
- package/dist/commands/crm.js.map +0 -1
- package/dist/commands/integrations.d.ts +0 -2
- package/dist/commands/integrations.js +0 -199
- package/dist/commands/integrations.js.map +0 -1
- package/dist/commands/link.d.ts +0 -3
- package/dist/commands/link.js +0 -91
- package/dist/commands/link.js.map +0 -1
- package/dist/commands/operators.d.ts +0 -11
- package/dist/commands/operators.js +0 -120
- package/dist/commands/operators.js.map +0 -1
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { InvalidArgumentError } from "commander";
|
|
2
|
+
/** Same shape the API accepts for `:user_id` / `--user` (uuid or default/me aliases). */
|
|
3
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
4
|
+
const USER_ALIASES = new Set(["default", "me"]);
|
|
5
|
+
export function isTenantUserRef(value) {
|
|
6
|
+
return USER_ALIASES.has(value) || UUID_RE.test(value);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Fail-closed for malformed `--user` before any HTTP call.
|
|
10
|
+
* Mirrors API subject-resolver: non-uuid ids never match → not_found (never a DB 500 / rate-limit burn).
|
|
11
|
+
*/
|
|
12
|
+
export function assertTenantUserRef(user) {
|
|
13
|
+
if (user === undefined || user === "")
|
|
14
|
+
return;
|
|
15
|
+
if (isTenantUserRef(user))
|
|
16
|
+
return;
|
|
17
|
+
throw Object.assign(new Error("User not found"), {
|
|
18
|
+
code: "not_found",
|
|
19
|
+
hint: "The user_id does not exist in your workspace.",
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export function configureStructuredValidation(command) {
|
|
23
|
+
command.exitOverride();
|
|
24
|
+
command.configureOutput({ writeErr: () => { } });
|
|
25
|
+
for (const child of command.commands)
|
|
26
|
+
configureStructuredValidation(child);
|
|
27
|
+
}
|
|
28
|
+
export function parseIntegerOption(value, name, min, max = Number.MAX_SAFE_INTEGER) {
|
|
29
|
+
const parsed = Number(value);
|
|
30
|
+
if (!Number.isSafeInteger(parsed) || parsed < min || parsed > max) {
|
|
31
|
+
throw new InvalidArgumentError(`${name} must be an integer between ${min} and ${max}`);
|
|
32
|
+
}
|
|
33
|
+
return parsed;
|
|
34
|
+
}
|
|
35
|
+
export function commandAction(args) {
|
|
36
|
+
const words = args.filter((arg) => !arg.startsWith("-")).slice(0, 2);
|
|
37
|
+
return words.length > 0 ? words.join(".") : "cli.validation";
|
|
38
|
+
}
|
|
39
|
+
export function cleanCommanderMessage(message) {
|
|
40
|
+
return message.replace(/^error:\s*/i, "").trim() || "Invalid command options";
|
|
41
|
+
}
|
|
42
|
+
export function helpCommand(args) {
|
|
43
|
+
const command = args.filter((arg) => !arg.startsWith("-")).slice(0, 2).join(" ");
|
|
44
|
+
return command ? `naive ${command} --help` : "naive --help";
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=cli-validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-validation.js","sourceRoot":"","sources":["../../src/lib/cli-validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAgB,MAAM,WAAW,CAAC;AAE/D,yFAAyF;AACzF,MAAM,OAAO,GAAG,iEAAiE,CAAC;AAClF,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC;AAEhD,MAAM,UAAU,eAAe,CAAC,KAAa;IAC3C,OAAO,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACxD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAwB;IAC1D,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,EAAE;QAAE,OAAO;IAC9C,IAAI,eAAe,CAAC,IAAI,CAAC;QAAE,OAAO;IAClC,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,gBAAgB,CAAC,EAAE;QAC/C,IAAI,EAAE,WAAoB;QAC1B,IAAI,EAAE,+CAA+C;KACtD,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,6BAA6B,CAAC,OAAgB;IAC5D,OAAO,CAAC,YAAY,EAAE,CAAC;IACvB,OAAO,CAAC,eAAe,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,CAAC,CAAC;IAChD,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,QAAQ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AC,SAAS,OAAO,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one deprecation experience for the CLI (06 §1.9 / §1.10.1).
|
|
3
|
+
*
|
|
4
|
+
* THE RULE THIS FILE EXISTS TO KEEP: a deprecated command KEEPS WORKING. Nothing
|
|
5
|
+
* here refuses, gates, or short-circuits — `markDeprecated` installs a commander
|
|
6
|
+
* `preAction` hook that writes a banner to STDERR and then returns, and the
|
|
7
|
+
* action runs exactly as it did before. Existing users must not break.
|
|
8
|
+
*
|
|
9
|
+
* WHY A preAction HOOK AND NOT A CALL INSIDE EACH HANDLER. A hook on the GROUP
|
|
10
|
+
* fires for every subcommand of that group, including subcommands added later by
|
|
11
|
+
* someone who has never read this file. A per-handler call is a convention, and a
|
|
12
|
+
* convention is a thing that is true until the next PR.
|
|
13
|
+
*
|
|
14
|
+
* WHY STDERR. The CLI's contract is that stdout is `JSON.parse`-able. The banner
|
|
15
|
+
* is for a human; the machine half is `deprecation` on the stdout envelope, set
|
|
16
|
+
* here through `setPendingDeprecation` and consumed by `agentOutput` exactly the
|
|
17
|
+
* way `update` already is.
|
|
18
|
+
*
|
|
19
|
+
* ── THE THREE LOAD-BEARING DETAILS OF THE TEXT ──────────────────────────────
|
|
20
|
+
*
|
|
21
|
+
* 1. THE `[dep.…]` ID is printed because it is the one word an operator can grep
|
|
22
|
+
* across every rendering of the same fact — the CLI banner, the JSON
|
|
23
|
+
* envelope, and (when they land) the openapi extension, the MCP tool
|
|
24
|
+
* description and the dashboard notice. Renderings drift; an id does not.
|
|
25
|
+
*
|
|
26
|
+
* 2. THE "also called" LINE is not decoration. The legacy orchestration runtime
|
|
27
|
+
* has EIGHT in-tree names. A notice that names one leaves seven ways to keep
|
|
28
|
+
* talking about the thing it is retiring.
|
|
29
|
+
*
|
|
30
|
+
* 3. "frozen, no sunset date" is rendered from a CLOSED two-member `Sunset`
|
|
31
|
+
* union. There is no "removal TBD", because a date nobody can keep is how a
|
|
32
|
+
* banner becomes furniture.
|
|
33
|
+
*
|
|
34
|
+
* And `Replacement` is closed for the same reason: a capability that is simply
|
|
35
|
+
* GONE renders as `{kind:"gap", because}`. It cannot be rendered as an empty
|
|
36
|
+
* string, and the reason is required by the type rather than by review. A notice
|
|
37
|
+
* that invents a replacement for a capability that no longer exists is worse than
|
|
38
|
+
* no notice at all.
|
|
39
|
+
*/
|
|
40
|
+
import type { Command } from "commander";
|
|
41
|
+
import { type DeprecationNotice, type NextStep } from "../output.js";
|
|
42
|
+
/** A replacement is a real symbol or an admitted gap. Closed on purpose (R-7). */
|
|
43
|
+
export type Replacement = {
|
|
44
|
+
readonly kind: "use";
|
|
45
|
+
readonly what: string;
|
|
46
|
+
} | {
|
|
47
|
+
readonly kind: "gap";
|
|
48
|
+
readonly because: string;
|
|
49
|
+
};
|
|
50
|
+
/** Frozen, or a date. There is no third member and no "TBD". */
|
|
51
|
+
export type Sunset = {
|
|
52
|
+
readonly kind: "frozen";
|
|
53
|
+
} | {
|
|
54
|
+
readonly kind: "on";
|
|
55
|
+
readonly date: string;
|
|
56
|
+
};
|
|
57
|
+
/** One subcommand of a deprecated group whose capability has no replacement. */
|
|
58
|
+
export interface SubcommandGap {
|
|
59
|
+
readonly sub: string;
|
|
60
|
+
readonly because: string;
|
|
61
|
+
}
|
|
62
|
+
export interface DeprecationSpec {
|
|
63
|
+
/**
|
|
64
|
+
* THE REGISTER'S id, not a derived one.
|
|
65
|
+
*
|
|
66
|
+
* This used to be computed as `dep.${cmd.name()}` — `dep.tasks`, `dep.ceo` —
|
|
67
|
+
* while `packages/api/src/routes/deprecations.ts` mints `dep.primitive.tasks`
|
|
68
|
+
* and emits it in the `X-Naive-Deprecation-Id` response header, whose own
|
|
69
|
+
* comment calls it "the grep handle … the SAME id the openapi operation
|
|
70
|
+
* carries". The dashboard uses the API's spelling too. So the one thing the
|
|
71
|
+
* machine channel exists for — correlating a CLI warning with the HTTP header
|
|
72
|
+
* for the same retirement — matched nothing.
|
|
73
|
+
*
|
|
74
|
+
* Declared rather than derived because the mapping is not a function of the
|
|
75
|
+
* command name: a future group may retire to a `dep.surface.*` row.
|
|
76
|
+
*
|
|
77
|
+
* TWO NAMESPACES, and the difference is real:
|
|
78
|
+
* `dep.primitive.*` / `dep.surface.*` the REST register's own ids. These
|
|
79
|
+
* MUST exist there — `ci/docs-deprecation-parity.mjs` asserts it — so a
|
|
80
|
+
* CLI warning and an `X-Naive-Deprecation-Id` header correlate.
|
|
81
|
+
* `dep.cli.*` a retirement with no REST twin, because the endpoints are
|
|
82
|
+
* gone rather than deprecated (`naive verify`). There is no operation to
|
|
83
|
+
* mark and no header to match, and saying so in the id is better than
|
|
84
|
+
* pointing at a register row that cannot exist.
|
|
85
|
+
*/
|
|
86
|
+
readonly id: string;
|
|
87
|
+
/** One sentence: what this command drives. Rendered after the header. */
|
|
88
|
+
readonly drives: string;
|
|
89
|
+
/** Every other in-tree name for the thing being retired (detail 2 above). */
|
|
90
|
+
readonly alsoCalled: readonly string[];
|
|
91
|
+
readonly replacement: Replacement;
|
|
92
|
+
/** Why the replacement is better. Rendered on the "Why:" line. */
|
|
93
|
+
readonly why: string;
|
|
94
|
+
/** `YYYY-MM` — when the deprecation was declared. */
|
|
95
|
+
readonly since: string;
|
|
96
|
+
readonly sunset: Sunset;
|
|
97
|
+
readonly guide: string;
|
|
98
|
+
/** Subcommands of this group whose capability is gone, with the reason. */
|
|
99
|
+
readonly gaps?: readonly SubcommandGap[];
|
|
100
|
+
}
|
|
101
|
+
export interface DeprecationRecord extends DeprecationSpec {
|
|
102
|
+
/** `naive tasks` — derived from the commander command, never retyped. */
|
|
103
|
+
readonly subject: string;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The eight names the legacy orchestration runtime answers to in this tree.
|
|
107
|
+
* Exported so a staleness check can hold it against the source rather than
|
|
108
|
+
* against memory — a list like this becomes folklore the moment nothing reads it.
|
|
109
|
+
*/
|
|
110
|
+
export declare const LEGACY_RUNTIME_ALIASES: readonly ["orchestration", "warm pool", "instance pool", "Hermes", "sidecar", "container runtime", "hosted runtime", "runtime.pool"];
|
|
111
|
+
/** Build the full record from the commander command plus its spec. */
|
|
112
|
+
export declare function deprecationRecord(cmd: Command, spec: DeprecationSpec): DeprecationRecord;
|
|
113
|
+
/** The machine half — what rides the stdout envelope. */
|
|
114
|
+
export declare function deprecationNotice(rec: DeprecationRecord, status: "deprecated" | "retired"): DeprecationNotice;
|
|
115
|
+
/**
|
|
116
|
+
* The banner, as a string. Pure, so the wording is a test rather than a habit.
|
|
117
|
+
* The first line carries the two facts an operator needs before anything else:
|
|
118
|
+
* it is deprecated, and it KEEPS WORKING.
|
|
119
|
+
*/
|
|
120
|
+
export declare function renderDeprecationBanner(rec: DeprecationRecord): string;
|
|
121
|
+
export declare function _resetDeprecationBannersForTest(): void;
|
|
122
|
+
/**
|
|
123
|
+
* Mark a command group deprecated. The group keeps working; every invocation
|
|
124
|
+
* writes the banner to stderr (once per process) and attaches the machine notice
|
|
125
|
+
* to the next stdout envelope.
|
|
126
|
+
*
|
|
127
|
+
* Returns the record so the caller can assert on it — the registry in index.ts is
|
|
128
|
+
* built from the return values, which is what makes the set of deprecations a
|
|
129
|
+
* value a test can read instead of a side effect it has to observe.
|
|
130
|
+
*/
|
|
131
|
+
export declare function markDeprecated(cmd: Command, spec: DeprecationSpec): DeprecationRecord;
|
|
132
|
+
/**
|
|
133
|
+
* A RETIRED command: it no longer does anything, and saying so is the whole
|
|
134
|
+
* behaviour. Distinct from `markDeprecated`, which never refuses.
|
|
135
|
+
*
|
|
136
|
+
* ── WHY THE CODE IS `deprecated_command` AND WHY IT IS NOT IN THE SERVER UNION ──
|
|
137
|
+
*
|
|
138
|
+
* `platform/kernel/src/errors.ts` holds a 25-member `ErrorCode` union typed as
|
|
139
|
+
* `Record<ErrorCode, number>` in `STATUS_MAP` — it is the set of codes an HTTP
|
|
140
|
+
* RESPONSE can carry, and every member owes a status. `deprecated_command` is
|
|
141
|
+
* minted here, by the CLI, for a command that makes no request at all: there is
|
|
142
|
+
* no response and therefore no status to map. Adding it to that union would put
|
|
143
|
+
* a code the server can never emit into the type that says what the server emits.
|
|
144
|
+
*
|
|
145
|
+
* It is instead the fourth member of the CLI-LOCAL code namespace that already
|
|
146
|
+
* exists in this package and is already relied on by callers:
|
|
147
|
+
* `cli_outdated` and `unknown_subcommand` (lib/unknown-command.ts:8) and
|
|
148
|
+
* `upstream_error` (client.ts:97). All three are minted client-side and none is
|
|
149
|
+
* in the server union. `CLI_LOCAL_ERROR_CODES` below names the set so it stays a
|
|
150
|
+
* declared four rather than a habit.
|
|
151
|
+
*/
|
|
152
|
+
export declare const CLI_LOCAL_ERROR_CODES: readonly ["cli_outdated", "unknown_subcommand", "upstream_error", "deprecated_command"];
|
|
153
|
+
export declare function retiredCommand(opts: {
|
|
154
|
+
action: string;
|
|
155
|
+
message: string;
|
|
156
|
+
recovery_steps: NextStep[];
|
|
157
|
+
notice?: DeprecationNotice;
|
|
158
|
+
}): void;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { agentError, setPendingDeprecation } from "../output.js";
|
|
2
|
+
/**
|
|
3
|
+
* The eight names the legacy orchestration runtime answers to in this tree.
|
|
4
|
+
* Exported so a staleness check can hold it against the source rather than
|
|
5
|
+
* against memory — a list like this becomes folklore the moment nothing reads it.
|
|
6
|
+
*/
|
|
7
|
+
export const LEGACY_RUNTIME_ALIASES = [
|
|
8
|
+
"orchestration",
|
|
9
|
+
"warm pool",
|
|
10
|
+
"instance pool",
|
|
11
|
+
"Hermes",
|
|
12
|
+
"sidecar",
|
|
13
|
+
"container runtime",
|
|
14
|
+
"hosted runtime",
|
|
15
|
+
"runtime.pool",
|
|
16
|
+
];
|
|
17
|
+
const MIGRATION_GUIDE = "https://usenaive.ai/docs/migration-guides/legacy-orchestration-to-durable-teams";
|
|
18
|
+
/** Build the full record from the commander command plus its spec. */
|
|
19
|
+
export function deprecationRecord(cmd, spec) {
|
|
20
|
+
return { ...spec, subject: `naive ${cmd.name()}` };
|
|
21
|
+
}
|
|
22
|
+
/** The machine half — what rides the stdout envelope. */
|
|
23
|
+
export function deprecationNotice(rec, status) {
|
|
24
|
+
return {
|
|
25
|
+
id: rec.id,
|
|
26
|
+
subject: rec.subject,
|
|
27
|
+
status,
|
|
28
|
+
replacement: rec.replacement,
|
|
29
|
+
since: rec.since,
|
|
30
|
+
sunset: rec.sunset.kind === "frozen" ? "frozen" : { on: rec.sunset.date },
|
|
31
|
+
guide: rec.guide,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function sunsetLine(rec) {
|
|
35
|
+
return rec.sunset.kind === "frozen"
|
|
36
|
+
? "frozen, no sunset date"
|
|
37
|
+
: `sunset ${rec.sunset.date}`;
|
|
38
|
+
}
|
|
39
|
+
function replacementLines(rec) {
|
|
40
|
+
if (rec.replacement.kind === "use") {
|
|
41
|
+
return [` Use instead: ${rec.replacement.what}`];
|
|
42
|
+
}
|
|
43
|
+
// The honest row. There is no replacement, and the reason is mandatory.
|
|
44
|
+
return [
|
|
45
|
+
" Use instead: nothing — this capability has no replacement.",
|
|
46
|
+
` Because: ${rec.replacement.because}`,
|
|
47
|
+
];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The banner, as a string. Pure, so the wording is a test rather than a habit.
|
|
51
|
+
* The first line carries the two facts an operator needs before anything else:
|
|
52
|
+
* it is deprecated, and it KEEPS WORKING.
|
|
53
|
+
*/
|
|
54
|
+
export function renderDeprecationBanner(rec) {
|
|
55
|
+
const lines = [];
|
|
56
|
+
lines.push(`⚠ \`${rec.subject}\` is DEPRECATED and will keep working. [${rec.id}]`);
|
|
57
|
+
lines.push(` It drives ${rec.drives}`);
|
|
58
|
+
if (rec.alsoCalled.length > 0) {
|
|
59
|
+
lines.push(` (also called: ${rec.alsoCalled.join(", ")})`);
|
|
60
|
+
}
|
|
61
|
+
lines.push(...replacementLines(rec));
|
|
62
|
+
lines.push(` Why: ${rec.why}`);
|
|
63
|
+
for (const gap of rec.gaps ?? []) {
|
|
64
|
+
lines.push(` No replacement for \`${rec.subject} ${gap.sub}\`: ${gap.because}`);
|
|
65
|
+
}
|
|
66
|
+
lines.push(` Since ${rec.since} · ${sunsetLine(rec)} · migration guide:`);
|
|
67
|
+
lines.push(` ${rec.guide}`);
|
|
68
|
+
return lines.join("\n") + "\n";
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Emitted ids, so the banner appears ONCE per process even when a group's hook
|
|
72
|
+
* and a future subcommand's hook both fire. Exported for tests only.
|
|
73
|
+
*/
|
|
74
|
+
const _emitted = new Set();
|
|
75
|
+
export function _resetDeprecationBannersForTest() {
|
|
76
|
+
_emitted.clear();
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Mark a command group deprecated. The group keeps working; every invocation
|
|
80
|
+
* writes the banner to stderr (once per process) and attaches the machine notice
|
|
81
|
+
* to the next stdout envelope.
|
|
82
|
+
*
|
|
83
|
+
* Returns the record so the caller can assert on it — the registry in index.ts is
|
|
84
|
+
* built from the return values, which is what makes the set of deprecations a
|
|
85
|
+
* value a test can read instead of a side effect it has to observe.
|
|
86
|
+
*/
|
|
87
|
+
export function markDeprecated(cmd, spec) {
|
|
88
|
+
const rec = deprecationRecord(cmd, spec);
|
|
89
|
+
cmd.hook("preAction", () => {
|
|
90
|
+
setPendingDeprecation(deprecationNotice(rec, "deprecated"));
|
|
91
|
+
if (!_emitted.has(rec.id)) {
|
|
92
|
+
_emitted.add(rec.id);
|
|
93
|
+
process.stderr.write(renderDeprecationBanner(rec));
|
|
94
|
+
}
|
|
95
|
+
// and then nothing. The action runs.
|
|
96
|
+
});
|
|
97
|
+
return rec;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* A RETIRED command: it no longer does anything, and saying so is the whole
|
|
101
|
+
* behaviour. Distinct from `markDeprecated`, which never refuses.
|
|
102
|
+
*
|
|
103
|
+
* ── WHY THE CODE IS `deprecated_command` AND WHY IT IS NOT IN THE SERVER UNION ──
|
|
104
|
+
*
|
|
105
|
+
* `platform/kernel/src/errors.ts` holds a 25-member `ErrorCode` union typed as
|
|
106
|
+
* `Record<ErrorCode, number>` in `STATUS_MAP` — it is the set of codes an HTTP
|
|
107
|
+
* RESPONSE can carry, and every member owes a status. `deprecated_command` is
|
|
108
|
+
* minted here, by the CLI, for a command that makes no request at all: there is
|
|
109
|
+
* no response and therefore no status to map. Adding it to that union would put
|
|
110
|
+
* a code the server can never emit into the type that says what the server emits.
|
|
111
|
+
*
|
|
112
|
+
* It is instead the fourth member of the CLI-LOCAL code namespace that already
|
|
113
|
+
* exists in this package and is already relied on by callers:
|
|
114
|
+
* `cli_outdated` and `unknown_subcommand` (lib/unknown-command.ts:8) and
|
|
115
|
+
* `upstream_error` (client.ts:97). All three are minted client-side and none is
|
|
116
|
+
* in the server union. `CLI_LOCAL_ERROR_CODES` below names the set so it stays a
|
|
117
|
+
* declared four rather than a habit.
|
|
118
|
+
*/
|
|
119
|
+
export const CLI_LOCAL_ERROR_CODES = [
|
|
120
|
+
"cli_outdated",
|
|
121
|
+
"unknown_subcommand",
|
|
122
|
+
"upstream_error",
|
|
123
|
+
"deprecated_command",
|
|
124
|
+
];
|
|
125
|
+
export function retiredCommand(opts) {
|
|
126
|
+
if (opts.notice)
|
|
127
|
+
setPendingDeprecation(opts.notice);
|
|
128
|
+
// A retired command's notice cannot ride a success envelope — there isn't one —
|
|
129
|
+
// so in machine mode the id travels on the error object instead.
|
|
130
|
+
agentError({
|
|
131
|
+
action: opts.action,
|
|
132
|
+
error: {
|
|
133
|
+
code: "deprecated_command",
|
|
134
|
+
message: opts.message,
|
|
135
|
+
...(opts.notice && { deprecation: opts.notice }),
|
|
136
|
+
},
|
|
137
|
+
recovery_steps: opts.recovery_steps,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=deprecation.js.map
|
|
@@ -0,0 +1 @@
|
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,WAAW,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;SACjD;QACD,cAAc,EAAE,IAAI,CAAC,cAAc;KACpC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function parseDurationArg(raw) {
|
|
2
|
+
const n = Number(raw);
|
|
3
|
+
if (raw.trim() === "" || !Number.isFinite(n) || n <= 0) {
|
|
4
|
+
return {
|
|
5
|
+
ok: false,
|
|
6
|
+
message: `--duration must be a positive number of seconds (e.g. 5 or 10); got "${raw}"`,
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
return { ok: true, value: n };
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=duration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duration.js","sourceRoot":"","sources":["../../src/lib/duration.ts"],"names":[],"mappings":"AAaA,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC1C,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IACtB,IAAI,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACvD,OAAO;YACL,EAAE,EAAE,KAAK;YACT,OAAO,EAAE,wEAAwE,GAAG,GAAG;SACxF,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface ParsedHttpResponse {
|
|
2
|
+
status: number;
|
|
3
|
+
data: unknown;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Parse an API response without assuming every proxy/error page is JSON.
|
|
7
|
+
* Empty successful responses remain valid; every other non-JSON response is
|
|
8
|
+
* converted to the same structured error shape the CLI already understands.
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseHttpResponse(response: Response): Promise<ParsedHttpResponse>;
|
|
11
|
+
export declare function networkErrorResponse(error: unknown): ParsedHttpResponse;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
const MAX_RESPONSE_PREVIEW = 240;
|
|
2
|
+
function redactSecrets(value) {
|
|
3
|
+
return value
|
|
4
|
+
.replace(/\b((?:nv|dr)_sk_)[A-Za-z0-9._-]+/gi, "$1[redacted]")
|
|
5
|
+
.replace(/\b(Bearer\s+)[A-Za-z0-9._~-]+/gi, "$1[redacted]");
|
|
6
|
+
}
|
|
7
|
+
function safePreview(value) {
|
|
8
|
+
const preview = redactSecrets(value)
|
|
9
|
+
.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, " ")
|
|
10
|
+
.replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi, " ")
|
|
11
|
+
.replace(/<[^>]+>/g, " ")
|
|
12
|
+
.replace(/[\u0000-\u001f\u007f]+/g, " ")
|
|
13
|
+
.replace(/\s+/g, " ")
|
|
14
|
+
.trim()
|
|
15
|
+
.slice(0, MAX_RESPONSE_PREVIEW);
|
|
16
|
+
return preview || undefined;
|
|
17
|
+
}
|
|
18
|
+
function codeForStatus(status) {
|
|
19
|
+
if (status === 401)
|
|
20
|
+
return "unauthorized";
|
|
21
|
+
if (status === 403)
|
|
22
|
+
return "forbidden";
|
|
23
|
+
if (status === 404)
|
|
24
|
+
return "resource_not_found";
|
|
25
|
+
if (status === 429)
|
|
26
|
+
return "rate_limited";
|
|
27
|
+
if (status >= 500)
|
|
28
|
+
return "internal_error";
|
|
29
|
+
return "invalid_input";
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Parse an API response without assuming every proxy/error page is JSON.
|
|
33
|
+
* Empty successful responses remain valid; every other non-JSON response is
|
|
34
|
+
* converted to the same structured error shape the CLI already understands.
|
|
35
|
+
*/
|
|
36
|
+
export async function parseHttpResponse(response) {
|
|
37
|
+
const contentType = response.headers.get("content-type")?.split(";", 1)[0]?.trim() || undefined;
|
|
38
|
+
const text = await response.text();
|
|
39
|
+
const jsonText = text.charCodeAt(0) === 0xfeff ? text.slice(1) : text;
|
|
40
|
+
if (!text.trim()) {
|
|
41
|
+
if (response.ok || response.status === 204)
|
|
42
|
+
return { status: response.status, data: {} };
|
|
43
|
+
return {
|
|
44
|
+
status: response.status,
|
|
45
|
+
data: {
|
|
46
|
+
error: {
|
|
47
|
+
code: codeForStatus(response.status),
|
|
48
|
+
message: `Naive API returned an empty error response (HTTP ${response.status}).`,
|
|
49
|
+
hint: "Retry once; if this persists, the API route or upstream proxy may be unavailable.",
|
|
50
|
+
upstream_status: response.status,
|
|
51
|
+
...(contentType && { content_type: contentType }),
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const looksJson = /(?:^|[+/])json$/i.test(contentType ?? "") || /^[\[{]/.test(jsonText.trim());
|
|
57
|
+
if (looksJson) {
|
|
58
|
+
try {
|
|
59
|
+
return { status: response.status, data: JSON.parse(jsonText) };
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
// Fall through to the structured invalid-response envelope below.
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const normalizedStatus = response.ok ? 502 : response.status;
|
|
66
|
+
const preview = safePreview(text);
|
|
67
|
+
return {
|
|
68
|
+
status: normalizedStatus,
|
|
69
|
+
data: {
|
|
70
|
+
error: {
|
|
71
|
+
code: codeForStatus(normalizedStatus),
|
|
72
|
+
message: `Naive API returned ${contentType ?? "a non-JSON response"} instead of JSON (HTTP ${response.status}).`,
|
|
73
|
+
hint: response.status === 404
|
|
74
|
+
? "The requested API route may not be deployed yet. Check the target environment and retry."
|
|
75
|
+
: "Retry once; if this persists, check API or upstream-provider health.",
|
|
76
|
+
upstream_status: response.status,
|
|
77
|
+
...(contentType && { content_type: contentType }),
|
|
78
|
+
...(preview && { response_preview: preview }),
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
export function networkErrorResponse(error) {
|
|
84
|
+
return {
|
|
85
|
+
status: 503,
|
|
86
|
+
data: {
|
|
87
|
+
error: {
|
|
88
|
+
code: "network_error",
|
|
89
|
+
message: "Could not reach the Naive API.",
|
|
90
|
+
hint: "Check your connection and NAIVE_BASE_URL, then retry.",
|
|
91
|
+
cause: error instanceof Error ? error.message : String(error),
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=http-response.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-response.js","sourceRoot":"","sources":["../../src/lib/http-response.ts"],"names":[],"mappings":"AAAA,MAAM,oBAAoB,GAAG,GAAG,CAAC;AAEjC,SAAS,aAAa,CAAC,KAAa;IAClC,OAAO,KAAK;SACT,OAAO,CAAC,oCAAoC,EAAE,cAAc,CAAC;SAC7D,OAAO,CAAC,iCAAiC,EAAE,cAAc,CAAC,CAAC;AAChE,CAAC;AAED,SAAS,WAAW,CAAC,KAAa;IAChC,MAAM,OAAO,GAAG,aAAa,CAAC,KAAK,CAAC;SACjC,OAAO,CAAC,qCAAqC,EAAE,GAAG,CAAC;SACnD,OAAO,CAAC,mCAAmC,EAAE,GAAG,CAAC;SACjD,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC;SACxB,OAAO,CAAC,yBAAyB,EAAE,GAAG,CAAC;SACvC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;SACpB,IAAI,EAAE;SACN,KAAK,CAAC,CAAC,EAAE,oBAAoB,CAAC,CAAC;IAClC,OAAO,OAAO,IAAI,SAAS,CAAC;AAC9B,CAAC;AAED,SAAS,aAAa,CAAC,MAAc;IACnC,IAAI,MAAM,KAAK,GAAG;QAAE,OAAO,cAAc,CAAC;IAC1C,IAAI,MAAM,KAAK,GAAG;QAAE,OAAO,WAAW,CAAC;IACvC,IAAI,MAAM,KAAK,GAAG;QAAE,OAAO,oBAAoB,CAA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AAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;aAC9D;SACF;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fixed public prices mirrored from the API meters, so CLI copy cannot silently
|
|
3
|
+
* drift from billing. Keep dynamic model costs out of this table.
|
|
4
|
+
*
|
|
5
|
+
* The source of truth is `FIXED_CREDIT_COSTS` in platform/billing/src/pricing.ts
|
|
6
|
+
* and `pricing-parity.test.ts` holds the two equal. This header used to name
|
|
7
|
+
* packages/api/src/lib/pricing.ts — a path the #497 restructure deleted — and
|
|
8
|
+
* to promise a "dogfood contract test" that no file in the repo implemented.
|
|
9
|
+
*/
|
|
10
|
+
export declare const FIXED_CREDIT_COSTS: {
|
|
11
|
+
readonly emailSend: 0.016;
|
|
12
|
+
readonly webSearch: 0.2;
|
|
13
|
+
readonly urlRead: 0.05;
|
|
14
|
+
readonly researchQuick: 0.5;
|
|
15
|
+
readonly researchThorough: 1;
|
|
16
|
+
readonly researchExhaustive: 1.6;
|
|
17
|
+
readonly brainQuery: 0.08;
|
|
18
|
+
readonly brainIngestBase: 0.1;
|
|
19
|
+
readonly brainIngestPerKb: 0.0002;
|
|
20
|
+
readonly brainIngestMaxCredits: 10;
|
|
21
|
+
readonly socialPost: 2.5;
|
|
22
|
+
readonly socialXPost: 0.5;
|
|
23
|
+
readonly socialXPostWithLink: 5;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* The DataForSEO-backed data primitives (seo / aeo / app-data / business /
|
|
27
|
+
* ecommerce), mirrored from `DATA_API_CREDIT_COSTS` in
|
|
28
|
+
* platform/billing/src/pricing.ts, which is where the reasoning, the vendor list
|
|
29
|
+
* price behind each number and the market anchor live. Held equal to it by
|
|
30
|
+
* packages/api/src/__tests__/credit-price-parity.test.ts.
|
|
31
|
+
*
|
|
32
|
+
* These are LIST prices. A charge is additionally floored at 1.2× what the call
|
|
33
|
+
* cost us upstream, so a row-heavy response can settle above the figure quoted
|
|
34
|
+
* here — which is why every CLI hint renders the response's own `credits_used`
|
|
35
|
+
* and only the `--help` epilogues quote this table.
|
|
36
|
+
*/
|
|
37
|
+
export declare const DATA_API_CREDIT_COSTS: {
|
|
38
|
+
readonly seoKeywordsAdsLive: 2;
|
|
39
|
+
readonly seoKeywordsAdsStandard: 1.5;
|
|
40
|
+
readonly seoKeywordsTrendsLive: 0.25;
|
|
41
|
+
readonly seoKeywordsTrendsStandard: 0.2;
|
|
42
|
+
readonly seoBacklinksStandard: 1.8;
|
|
43
|
+
readonly seoBacklinksBulk: 17;
|
|
44
|
+
readonly seoLabsStandard: 0.75;
|
|
45
|
+
readonly seoLabsBulk: 5.4;
|
|
46
|
+
readonly seoLabsHistorical: 10;
|
|
47
|
+
readonly aeoLlmResponsesLive: 1.2;
|
|
48
|
+
readonly aeoLlmResponsesStandard: 1.2;
|
|
49
|
+
readonly aeoLlmScraperLive: 0.16;
|
|
50
|
+
readonly aeoLlmScraperStandard: 0.08;
|
|
51
|
+
readonly appDataAppSearches: 0.85;
|
|
52
|
+
readonly appDataAppList: 0.85;
|
|
53
|
+
readonly appDataAppInfo: 0.05;
|
|
54
|
+
readonly appDataAppReviews: 6;
|
|
55
|
+
readonly businessGoogleInfoLive: 0.13;
|
|
56
|
+
readonly businessGoogleInfoStandard: 0.09;
|
|
57
|
+
readonly businessGoogleUpdatesStandard: 3;
|
|
58
|
+
readonly businessGoogleReviewsStandard: 1.5;
|
|
59
|
+
readonly businessGoogleQaLive: 0.3;
|
|
60
|
+
readonly businessGoogleQaStandard: 0.18;
|
|
61
|
+
readonly businessGoogleHotelLive: 0.1;
|
|
62
|
+
readonly businessGoogleHotelStandard: 0.07;
|
|
63
|
+
readonly businessTrustpilotSearchStandard: 0.34;
|
|
64
|
+
readonly businessTrustpilotReviewsStandard: 0.85;
|
|
65
|
+
readonly businessTripadvisorSearchStandard: 0.85;
|
|
66
|
+
readonly businessTripadvisorReviewsStandard: 1.25;
|
|
67
|
+
readonly businessSocialLive: 0.1;
|
|
68
|
+
readonly ecommerceGoogleProducts: 0.15;
|
|
69
|
+
readonly ecommerceGoogleProductInfo: 0.14;
|
|
70
|
+
readonly ecommerceGoogleSellers: 0.24;
|
|
71
|
+
readonly ecommerceGoogleReviews: 2.2;
|
|
72
|
+
readonly ecommerceAmazonProducts: 0.14;
|
|
73
|
+
readonly ecommerceAmazonAsin: 0.04;
|
|
74
|
+
readonly ecommerceAmazonSellers: 0.14;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* The two row-metered families, whose price is a base plus a per-row rate rather
|
|
78
|
+
* than a flat figure. Mirrored from the same module; `appListingsCredits` /
|
|
79
|
+
* `aeoLlmMentionsCredits` there are the functions that bill.
|
|
80
|
+
*/
|
|
81
|
+
export declare const METERED_DATA_API_CREDITS: {
|
|
82
|
+
readonly llmMentionsBase: 2.4;
|
|
83
|
+
readonly llmMentionsPerRow: 0.024;
|
|
84
|
+
readonly llmMentionsMaxRows: 1000;
|
|
85
|
+
readonly llmMentionsDefaultRows: 100;
|
|
86
|
+
readonly appListingsBase: 2.4;
|
|
87
|
+
readonly appListingsPerItem: 0.024;
|
|
88
|
+
readonly aiKeywordsBase: 0.4;
|
|
89
|
+
readonly aiKeywordsPerKeyword: 0.004;
|
|
90
|
+
};
|
|
91
|
+
/** `2.4 + 0.024 × rows`, the LLM Mentions price the API charges for `rows` rows. */
|
|
92
|
+
export declare function llmMentionsCredits(rows: number): number;
|
|
93
|
+
/** `2.4 + 0.024 × limit`, the live app-listings price for a given `--limit`. */
|
|
94
|
+
export declare function appListingsCredits(limit: number): number;
|
|
95
|
+
export declare function reportedCreditsUsed(data: unknown, fallback: number): number;
|
|
96
|
+
export interface CreditPack {
|
|
97
|
+
id: string;
|
|
98
|
+
credits: number;
|
|
99
|
+
priceInCents: number;
|
|
100
|
+
badge?: string;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The one-time credit packs, mirrored field-for-field from `CREDIT_PACKS` in
|
|
104
|
+
* platform/billing/src/billing.ts — the table `createTopupCheckout` bills
|
|
105
|
+
* Stripe from. The CLI ships to npm with five runtime dependencies and cannot
|
|
106
|
+
* import the billing package, so this is a mirror; `pricing-parity.test.ts`
|
|
107
|
+
* imports both and fails on any divergence.
|
|
108
|
+
*
|
|
109
|
+
* 🔴 EVERY pack figure the CLI prints must come from here. The `--help`
|
|
110
|
+
* epilogue and the `--pack` option description used to carry two independent
|
|
111
|
+
* hand-typed copies, and one of them drifted to a tenth of the real price.
|
|
112
|
+
*/
|
|
113
|
+
export declare const CREDIT_PACKS: readonly CreditPack[];
|
|
114
|
+
/** `$23` — whole dollars, matching how the API renders `getCreditPacks().price`. */
|
|
115
|
+
export declare function packPrice(pack: CreditPack): string;
|
|
116
|
+
/** `medium (500 credits, $23)` — the inline form for an option description. */
|
|
117
|
+
export declare function packInline(pack: CreditPack): string;
|
|
118
|
+
/** One column-aligned row of the pack table in `naive billing --help`. */
|
|
119
|
+
export declare function packRow(pack: CreditPack): string;
|
|
120
|
+
/**
|
|
121
|
+
* The flat 9:16 vertical-reframe / face-tracking fee, in credits, mirrored from
|
|
122
|
+
* `usdToBillableCredits(REFRAME_FEE_USD_PER_JOB)` in
|
|
123
|
+
* platform/billing/src/pricing.ts — the value clipCost() adds to a reframed
|
|
124
|
+
* job's subtotal. Charged once per job, not per clip.
|
|
125
|
+
*
|
|
126
|
+
* The CLI used to advertise this as "typically $0.05–$0.30 per job", which is
|
|
127
|
+
* the band clip-job-cost-audit.md records the CLI advertising while the code
|
|
128
|
+
* charged nothing at all. It is now a flat fee, billed in credits like every
|
|
129
|
+
* other driver, and this constant is held equal to the meter by
|
|
130
|
+
* packages/api/src/__tests__/credit-price-parity.test.ts.
|
|
131
|
+
*/
|
|
132
|
+
export declare const REFRAME_FEE_CREDITS = 4;
|