@clipwright/core 0.75.2 → 0.77.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.
@@ -141,7 +141,7 @@ export const creatorProfile = z.strictObject({
141
141
  median_comment_rate: z.number().nonnegative().nullable().describe("The median comment_rate of the videos with both counts, four decimals; null " +
142
142
  `under ${CREATOR_COMMENT_NORM_MIN_VIDEOS} such videos.`),
143
143
  cadence: cadenceShape,
144
- voice_proposal: scriptVoice.optional().describe("A script voice proposed from the author's own captions (#1203): their topics and a closing " +
144
+ voice_proposal: scriptVoice.optional().describe("A script voice proposed from the author's own captions: their topics and a closing " +
145
145
  "line they repeat. Third-party text, not saved until passed to brand_kit; it suits only this author's own brand kit."),
146
146
  });
147
147
  const measuredProfile = z.object({
package/dist/design.js CHANGED
@@ -149,7 +149,7 @@ export const extractBrandResponse = z.object({
149
149
  url: z.string(),
150
150
  design: design,
151
151
  resolved: resolvedDesign,
152
- voice: scriptVoice.optional().describe("A proposed script voice read from the page's own words (#1203): third-party text, not " +
152
+ voice: scriptVoice.optional().describe("A proposed script voice read from the page's own words: third-party text, not " +
153
153
  "saved until passed to brand_kit."),
154
154
  brand_name: brandName.optional().describe("A proposed brand name read from the page: third-party text, not saved until passed to " +
155
155
  "brand_kit."),
@@ -4,7 +4,7 @@ import { REVISION_CHARGE_TEXT } from "./edit-revision.js";
4
4
  import { CREATOR_PROFILE_CREDITS, CREATOR_PROFILE_PER_HOUR, CREATOR_PROFILE_VIDEOS } from "./creator-profile.js";
5
5
  import { TREND_FREE_PAGES_PER_DAY, TREND_FREE_SEARCHES_PER_MONTH, TREND_PAGE_PAID_CREDITS, TREND_PAGE_WINDOW_SECONDS, TREND_SEARCH_CREDITS, TREND_SEARCH_MAX_PAGES, TREND_SEARCH_PER_HOUR, TREND_SEARCH_REELS, } from "./trend-search.js";
6
6
  import { FEEDBACK_PER_HOUR } from "./feedback.js";
7
- import { REFERENCE_ANALYSIS_CREDITS, REFERENCE_ANALYSIS_MAX_SECONDS, REFERENCE_ANALYSIS_PER_HOUR, REFERENCE_DATA_CREDITS, REFERENCE_DATA_PER_HOUR } from "./reference-analysis.js";
7
+ import { REFERENCE_ANALYSIS_MAX_SECONDS, REFERENCE_ANALYSIS_PER_HOUR, REFERENCE_DATA_CREDITS, REFERENCE_DATA_PER_HOUR, referenceAnalysisPriceRange } from "./reference-analysis.js";
8
8
  export const ENDPOINT_NOTES = {
9
9
  "GET /v1/public/workflows": "Lists public workflow methods and whether each is available now, without account plans or an account admission claim.",
10
10
  "GET /v1/public/workflows/{id}": "Reads a method's guidance, limitations and what it can do right now.",
@@ -64,12 +64,12 @@ export const ENDPOINT_NOTES = {
64
64
  "GET /v1/assets/{id}": "One live asset with a link signed for an hour. Free.",
65
65
  "POST /v1/assets/{id}": "Renames an asset or changes its role. Free.",
66
66
  "DELETE /v1/assets/{id}": "Deletes an asset: it leaves the list and generations at once, and a daily cleanup removes its file once 7 days have passed. Free.",
67
- "POST /v1/reference-analyses/quote": `Prices an analysis of this asset or link: ${REFERENCE_ANALYSIS_CREDITS} credits, ${REFERENCE_DATA_CREDITS} with mode data, or 0 when ` +
68
- "its live analysis in that mode would answer. Charges nothing.",
69
- "POST /v1/reference-analyses": `Starts reading an MP4 asset, up to ${REFERENCE_ANALYSIS_MAX_SECONDS.full} s, into a reference profile (or, with mode data, up to ` +
70
- `${REFERENCE_ANALYSIS_MAX_SECONDS.data} s, its transcript, hook, scenes and frames) and ` +
71
- "answers at once; the same asset in the same mode answers the same analysis for free. Holds " +
72
- `${REFERENCE_ANALYSIS_CREDITS} credits (${REFERENCE_DATA_CREDITS} for data), charged once it succeeds; a failed one costs nothing. ` +
67
+ "POST /v1/reference-analyses/quote": `Prices an analysis of this asset or link: ${referenceAnalysisPriceRange()} (the most for a link of unknown length), ` +
68
+ `${REFERENCE_DATA_CREDITS} with mode data, or 0 when its live analysis in that mode would answer. Charges nothing.`,
69
+ "POST /v1/reference-analyses": `Starts reading an MP4 asset or a reel, up to ${REFERENCE_ANALYSIS_MAX_SECONDS.full} s, into a reference profile (or, with mode data, ` +
70
+ "its transcript, hook, scenes and frames) and " +
71
+ "answers at once; the same asset in the same mode answers the same analysis for free. Price: " +
72
+ `${referenceAnalysisPriceRange()} (${REFERENCE_DATA_CREDITS} for data), held at the start and charged once it succeeds, the most for a link of unknown length; a failed one costs nothing. ` +
73
73
  `${REFERENCE_ANALYSIS_PER_HOUR} new full and ${REFERENCE_DATA_PER_HOUR} new data analyses per hour.`,
74
74
  "GET /v1/reference-analyses/{id}": "One reference analysis: queued, analyzing, succeeded with reference_profile or data and warnings, or failed with its error. Free.",
75
75
  "POST /v1/creator-profiles/quote": `Prices a creator profile for this link: ${CREATOR_PROFILE_CREDITS} credits, or 0 when a profile of the same creator from the last hour ` +
package/dist/errors.d.ts CHANGED
@@ -52,6 +52,7 @@ export type MaxCreditsExceededError = z.infer<typeof maxCreditsExceededError>;
52
52
  export declare function maxCreditsExceededBody(args: {
53
53
  holdCredits: number;
54
54
  maxCredits: number;
55
+ note?: string | undefined;
55
56
  }): MaxCreditsExceededError;
56
57
  export declare const debtOutstandingError: z.ZodObject<{
57
58
  error: z.ZodObject<{
@@ -71,6 +72,7 @@ export type AccountNotAdmittedError = z.infer<typeof accountNotAdmittedError>;
71
72
  export declare function insufficientCreditsBody(args: {
72
73
  balanceCredits: number;
73
74
  requiredCredits: number;
75
+ note?: string | undefined;
74
76
  }): InsufficientCreditsError;
75
77
  export declare function creditsNeededSentence(args: {
76
78
  balanceCredits: number;
package/dist/errors.js CHANGED
@@ -35,7 +35,7 @@ export function maxCreditsExceededBody(args) {
35
35
  code: "max_credits_exceeded",
36
36
  message: `This call reserves ${args.holdCredits} credits, above its max_credits of ${args.maxCredits}. ` +
37
37
  "Nothing was charged and no run was created. Ask the person to approve the higher amount and retry with max_credits " +
38
- `of at least ${args.holdCredits}, or change the request to cost less.`,
38
+ `of at least ${args.holdCredits}, or change the request to cost less.` + (args.note === undefined ? "" : ` ${args.note}`),
39
39
  hold_credits: args.holdCredits,
40
40
  max_credits: args.maxCredits,
41
41
  },
@@ -59,7 +59,7 @@ export function insufficientCreditsBody(args) {
59
59
  error: {
60
60
  code: "insufficient_credits",
61
61
  message: `${creditsNeededSentence(args)} ` +
62
- "Top up the balance and retry; nothing was charged and no run was created.",
62
+ "Top up the balance and retry; nothing was charged and no run was created." + (args.note === undefined ? "" : ` ${args.note}`),
63
63
  balance_credits: args.balanceCredits,
64
64
  required_credits: args.requiredCredits,
65
65
  },
@@ -85,7 +85,6 @@ export declare const FACELESS_MIN_BASE_CREDITS = 50;
85
85
  export declare const FACELESS_SHOT_CREDITS_PER_SECOND = 30;
86
86
  export declare const FACELESS_MAX_SHOTS = 10;
87
87
  export declare const FACELESS_SHOT_MAX_SEC = 5;
88
- export declare const FACELESS_MAX_CAP_USD_MICROS = 10000000;
89
88
  export declare const facelessShotSecondsCeiling: (shots: number) => number;
90
89
  export declare function facelessPartsBase(images: number, outputFrames: number): number;
91
90
  export declare const FACELESS_EXPLAINER_POSE_PICTURES = 9;
@@ -56,7 +56,6 @@ export const FACELESS_MIN_BASE_CREDITS = DELIVERED_VIDEO_MINIMUM_CREDITS;
56
56
  export const FACELESS_SHOT_CREDITS_PER_SECOND = 30;
57
57
  export const FACELESS_MAX_SHOTS = 10;
58
58
  export const FACELESS_SHOT_MAX_SEC = 5;
59
- export const FACELESS_MAX_CAP_USD_MICROS = 10_000_000;
60
59
  export const facelessShotSecondsCeiling = (shots) => shots * FACELESS_SHOT_MAX_SEC;
61
60
  export function facelessPartsBase(images, outputFrames) {
62
61
  return images * FACELESS_IMAGE_CREDITS + Math.ceil(FACELESS_CREDITS_PER_1500_FRAMES * outputFrames / 1500);
package/dist/openapi.js CHANGED
@@ -161,25 +161,25 @@ export const OPENAPI_ROUTES = {
161
161
  "POST /v1/assets/{id}": { exposure: "public", operationId: "updateAsset", tag: "Assets", params: ASSET,
162
162
  body: named("UpdateAssetRequest", updateAssetRequest), responses: { 200: named("Asset", asset) } },
163
163
  "DELETE /v1/assets/{id}": { exposure: "public", operationId: "deleteAsset", tag: "Assets", params: ASSET, responses: { 204: null } },
164
- "POST /v1/film-drafts": { exposure: "excluded", reason: "Not offered yet: film drafts join the contract when their mode launches (#1291 F2)." },
165
- "POST /v1/film-drafts/{id}/files": { exposure: "excluded", reason: "Not offered yet: film drafts join the contract when their mode launches (#1291 F2)." },
166
- "GET /v1/film-drafts/{id}": { exposure: "excluded", reason: "Not offered yet: film drafts join the contract when their mode launches (#1291 F2)." },
167
- "POST /v1/film-drafts/{id}/check": { exposure: "excluded", reason: "Not offered yet: the film check joins the contract with the drafts it reads (#1356)." },
168
- "POST /v1/film-stills/quote": { exposure: "excluded", reason: "Not offered yet: film runs join the contract when their mode launches (#1337)." },
169
- "POST /v1/film-stills": { exposure: "excluded", reason: "Not offered yet: film runs join the contract when their mode launches (#1337)." },
170
- "POST /v1/film-voices/quote": { exposure: "excluded", reason: "Not offered yet: film runs join the contract when their mode launches (#1337)." },
171
- "POST /v1/film-voices": { exposure: "excluded", reason: "Not offered yet: film runs join the contract when their mode launches (#1337)." },
172
- "POST /v1/film-renders/quote": { exposure: "excluded", reason: "Not offered yet: film runs join the contract when their mode launches (#1337)." },
173
- "POST /v1/film-renders": { exposure: "excluded", reason: "Not offered yet: film runs join the contract when their mode launches (#1337)." },
174
- "POST /v1/film-heroes/quote": { exposure: "excluded", reason: "Not offered yet: film runs join the contract when their mode launches (#1356)." },
175
- "POST /v1/film-heroes": { exposure: "excluded", reason: "Not offered yet: film runs join the contract when their mode launches (#1356)." },
176
- "POST /v1/film-edits/quote": { exposure: "excluded", reason: "Not offered yet: film runs join the contract when their mode launches (#1337)." },
177
- "POST /v1/film-edits": { exposure: "excluded", reason: "Not offered yet: film runs join the contract when their mode launches (#1337)." },
178
- "POST /v1/take-frames/quote": { exposure: "excluded", reason: "Not offered yet: film runs join the contract when their mode launches (#1337)." },
179
- "POST /v1/take-frames": { exposure: "excluded", reason: "Not offered yet: film runs join the contract when their mode launches (#1337)." },
180
- "POST /v1/take-checks/quote": { exposure: "excluded", reason: "Not offered yet: film runs join the contract when their mode launches (#1337)." },
181
- "POST /v1/take-checks": { exposure: "excluded", reason: "Not offered yet: film runs join the contract when their mode launches (#1337)." },
182
- "GET /v1/film-runs/{id}": { exposure: "excluded", reason: "Not offered yet: film runs join the contract when their mode launches (#1337)." },
164
+ "POST /v1/film-drafts": { exposure: "excluded", reason: "Not offered yet: film drafts join the contract when their mode launches." },
165
+ "POST /v1/film-drafts/{id}/files": { exposure: "excluded", reason: "Not offered yet: film drafts join the contract when their mode launches." },
166
+ "GET /v1/film-drafts/{id}": { exposure: "excluded", reason: "Not offered yet: film drafts join the contract when their mode launches." },
167
+ "POST /v1/film-drafts/{id}/check": { exposure: "excluded", reason: "Not offered yet: the film check joins the contract with the drafts it reads." },
168
+ "POST /v1/film-stills/quote": { exposure: "excluded", reason: "Not offered yet: film runs join the contract when their mode launches." },
169
+ "POST /v1/film-stills": { exposure: "excluded", reason: "Not offered yet: film runs join the contract when their mode launches." },
170
+ "POST /v1/film-voices/quote": { exposure: "excluded", reason: "Not offered yet: film runs join the contract when their mode launches." },
171
+ "POST /v1/film-voices": { exposure: "excluded", reason: "Not offered yet: film runs join the contract when their mode launches." },
172
+ "POST /v1/film-renders/quote": { exposure: "excluded", reason: "Not offered yet: film runs join the contract when their mode launches." },
173
+ "POST /v1/film-renders": { exposure: "excluded", reason: "Not offered yet: film runs join the contract when their mode launches." },
174
+ "POST /v1/film-heroes/quote": { exposure: "excluded", reason: "Not offered yet: film runs join the contract when their mode launches." },
175
+ "POST /v1/film-heroes": { exposure: "excluded", reason: "Not offered yet: film runs join the contract when their mode launches." },
176
+ "POST /v1/film-edits/quote": { exposure: "excluded", reason: "Not offered yet: film runs join the contract when their mode launches." },
177
+ "POST /v1/film-edits": { exposure: "excluded", reason: "Not offered yet: film runs join the contract when their mode launches." },
178
+ "POST /v1/take-frames/quote": { exposure: "excluded", reason: "Not offered yet: film runs join the contract when their mode launches." },
179
+ "POST /v1/take-frames": { exposure: "excluded", reason: "Not offered yet: film runs join the contract when their mode launches." },
180
+ "POST /v1/take-checks/quote": { exposure: "excluded", reason: "Not offered yet: film runs join the contract when their mode launches." },
181
+ "POST /v1/take-checks": { exposure: "excluded", reason: "Not offered yet: film runs join the contract when their mode launches." },
182
+ "GET /v1/film-runs/{id}": { exposure: "excluded", reason: "Not offered yet: film runs join the contract when their mode launches." },
183
183
  "POST /v1/film-cuts/check": { exposure: "excluded", reason: "Offered through MCP (check_cut)." },
184
184
  "POST /v1/film-cuts/quote": { exposure: "excluded", reason: "Offered through MCP (quote_cut, render_cut)." },
185
185
  "POST /v1/film-cuts": { exposure: "excluded", reason: "Offered through MCP (quote_cut, render_cut)." },
@@ -188,12 +188,12 @@ export const OPENAPI_ROUTES = {
188
188
  "POST /v1/cuts": { exposure: "excluded", reason: "Offered through MCP (create_cut, get_cut, update_cut)." },
189
189
  "POST /v1/cuts/{id}": { exposure: "excluded", reason: "Offered through MCP (create_cut, get_cut, update_cut)." },
190
190
  "GET /v1/cuts/{id}": { exposure: "excluded", reason: "Offered through MCP (create_cut, get_cut, update_cut)." },
191
- "GET /v1/film-guide": { exposure: "excluded", reason: "Not offered yet: the film guide joins the contract when its mode launches (#1356)." },
192
- "GET /v1/film-kit": { exposure: "excluded", reason: "Not offered yet: the film kit joins the contract when its mode launches (#1356)." },
193
- "GET /v1/ad-guide": { exposure: "excluded", reason: "Not offered yet: the ad guide joins the contract when it opens to every account (#1539)." },
194
- "POST /v1/ads": { exposure: "excluded", reason: "Not offered yet: ad records join the contract with the ad guide, when it opens to every account (#1539)." },
195
- "POST /v1/ads/{id}": { exposure: "excluded", reason: "Not offered yet: ad records join the contract with the ad guide, when it opens to every account (#1539)." },
196
- "GET /v1/ads/{id}": { exposure: "excluded", reason: "Not offered yet: ad records join the contract with the ad guide, when it opens to every account (#1539)." },
191
+ "GET /v1/film-guide": { exposure: "excluded", reason: "Not offered yet: the film guide joins the contract when its mode launches." },
192
+ "GET /v1/film-kit": { exposure: "excluded", reason: "Not offered yet: the film kit joins the contract when its mode launches." },
193
+ "GET /v1/ad-guide": { exposure: "excluded", reason: "Not offered yet: the ad guide joins the contract when it opens to every account." },
194
+ "POST /v1/ads": { exposure: "excluded", reason: "Not offered yet: ad records join the contract with the ad guide, when it opens to every account." },
195
+ "POST /v1/ads/{id}": { exposure: "excluded", reason: "Not offered yet: ad records join the contract with the ad guide, when it opens to every account." },
196
+ "GET /v1/ads/{id}": { exposure: "excluded", reason: "Not offered yet: ad records join the contract with the ad guide, when it opens to every account." },
197
197
  "GET /internal/portfolio-metrics": { exposure: "excluded",
198
198
  reason: "Internal funnel aggregates behind their own secret, outside the client contract (docs/03-api.md section 12)." },
199
199
  "GET /v1/public/workflows": { exposure: "public", operationId: "listWorkflows", tag: "Workflows", anonymous: true,
package/dist/prices.js CHANGED
@@ -8,13 +8,15 @@ import { PRESENTER_ENGINES, SHOT_ENGINES } from "./face-billing.js";
8
8
  import { listGenerationModels } from "./generations.js";
9
9
  import { PARTS_DURATION_TARIFF, PARTS_FACE_TARIFF, PRESENTER_CREDITS_PER_SECOND, PRESENTER_ENGINE_LABELS, SCENE_CREDITS, SHOT_CREDITS_PER_SECOND, SHOT_ENGINE_LABELS } from "./parts-pricing.js";
10
10
  import { UPSCALE_CAPABILITIES, UPSCALE_QUOTE_PATH, UPSCALE_RUN_PATH } from "./upscale.js";
11
- import { REFERENCE_ANALYSIS_CREDITS, REFERENCE_DATA_CREDITS } from "./reference-analysis.js";
11
+ import { REFERENCE_ANALYSIS_TARIFFS, REFERENCE_DATA_CREDITS, referenceAnalysisPriceRange, referenceAnalysisPriceTable, referenceAnalysisSince } from "./reference-analysis.js";
12
12
  import { CREATOR_PROFILE_CREDITS, CREATOR_PROFILE_VIDEOS } from "./creator-profile.js";
13
13
  import { TREND_FREE_PAGES_PER_DAY, TREND_FREE_SEARCHES_PER_MONTH, TREND_PAGE_PAID_CREDITS, TREND_PAGE_WINDOW_SECONDS, TREND_SEARCH_CREDITS, TREND_SEARCH_MAX_PAGES, TREND_SEARCH_REELS, } from "./trend-search.js";
14
14
  import { FILM_MUSIC_BED_CREDITS, MUSIC_BED_CREDITS } from "./music.js";
15
15
  import { HERO_RUNS_PER_HOUR, OWN_FILM_EXTRA_SECOND_CREDITS, OWN_FILM_INCLUDED_SECONDS, OWN_FILM_RENDER_CREDITS, OWN_HERO_POSE_CREDITS, OWN_HERO_POSES, OWN_HERO_FREE_POSES_PER_DAY, OWN_HERO_FREE_POSES_WINDOW_HOURS, OWN_FREE_STILLS, OWN_FREE_STILLS_WINDOW_HOURS, OWN_STILL_CREDITS, OWN_STILLS_MAX_PER_CALL, OWN_VOICE_CREDITS_PER_SECOND, OWN_EDIT_CREDITS, OWN_EDIT_MAX_SECONDS, OWN_TAKE_CHECK_CREDITS, OWN_CUT_BED_CREDITS, OWN_CUT_CREDITS, OWN_CUT_EXTRA_SECOND_CREDITS, OWN_CUT_INCLUDED_SECONDS, OWN_CUT_MAX_NEW_SOUNDS, OWN_CUT_MAX_SECONDS, OWN_CUT_MIN_SECONDS, OWN_CUT_TAKE_SOUND_CREDITS_PER_SECOND, OWN_TAKE_CHECK_PICTURE_CREDITS, OWN_TAKE_CHECK_PICTURE_LONG_CREDITS, OWN_TAKE_FRAMES_MAX, TAKE_PICTURE_SHORT_TIER_SECONDS, OWN_HERO_HEAD_CREDITS, OWN_HERO_MAX_SPRITES, OWN_HERO_SPRITE_CREDITS, OWN_HERO_TALKING_POSES, ownAgentTermsNow, ownHeroCredits } from "./own-agent-price.js";
16
16
  import { CUT_PREVIEW_MAX_STILLS } from "./film-cut.js";
17
17
  export const PRICES_PATH = "/v1/public/prices";
18
+ const referenceAnalysisTableText = (tariff, index) => `${index === 0 ? "By the reel's length, " : `${referenceAnalysisSince(tariff)}, `}` +
19
+ referenceAnalysisPriceTable(tariff).map((row, at) => `${row.credits}${at === 0 ? " credits" : ""} up to ${row.up_to_s} s`).join(", ");
18
20
  export const PRICE_UNITS = ["call", "second", "face_second", "image", "clip", "clip_second", "still", "scene", "track"];
19
21
  export const priceEntryLine = z.strictObject({
20
22
  label: z.string().min(1).nullable(),
@@ -211,8 +213,10 @@ function buildPriceList(offer, diy) {
211
213
  "with no call, interview, presenter_gaze or talking shot and no presenter part longer than about 36 s; any other video renders " +
212
214
  "on HeyGen Avatar IV. Presenter seconds are the seconds a presenter take fills, counted once over the video and rounded up; " +
213
215
  "production seconds are every second of the finished video." })] : []),
214
- paid({ tool: "analyze_reference", route: "POST /v1/reference-analyses", unit: "call", credits: REFERENCE_ANALYSIS_CREDITS,
215
- quote_tool: "quote_analysis", notes: "Held at the start and charged once the analysis succeeds; a failed one costs nothing. " +
216
+ paid({ tool: "analyze_reference", route: "POST /v1/reference-analyses", formula: referenceAnalysisPriceRange(),
217
+ quote_tool: "quote_analysis", notes: `${REFERENCE_ANALYSIS_TARIFFS.map(referenceAnalysisTableText).join("; ")}. ` +
218
+ "A link of unknown length holds the most and is charged by the length. " +
219
+ "Held at the start and charged once the analysis succeeds; a failed one costs nothing. " +
216
220
  "Starting it again on the same asset answers the same analysis for free." }),
217
221
  paid({ tool: "analyze_reference", route: "POST /v1/reference-analyses", variant: "data mode", unit: "call", credits: REFERENCE_DATA_CREDITS,
218
222
  quote_tool: "quote_analysis", notes: "mode: \"data\": duration, size, timed transcript, hook and a frame sheet, without the vision pass. " +
@@ -7,11 +7,29 @@ export declare const ANALYZE_REFERENCE_TASK = "analyze-reference";
7
7
  export declare const ANALYZE_REFERENCE_SKILL = "analyze_reference";
8
8
  export declare const referenceAnalysisId: z.ZodString;
9
9
  export declare const REFERENCE_ANALYSIS_VERSION = 2;
10
- export declare const REFERENCE_ANALYSIS_CREDITS = 70;
11
10
  export declare const REFERENCE_DATA_CREDITS = 10;
11
+ export interface ReferenceAnalysisTariff {
12
+ readonly name: string;
13
+ readonly from: string;
14
+ readonly stepSeconds: number;
15
+ readonly credits: readonly number[];
16
+ }
17
+ export declare const REFERENCE_ANALYSIS_TARIFFS: readonly ReferenceAnalysisTariff[];
18
+ export declare const referenceAnalysisTariff: (name: string) => ReferenceAnalysisTariff | null;
19
+ export declare function referenceAnalysisTariffAt(at: Date): ReferenceAnalysisTariff;
20
+ export declare const referenceAnalysisCeiling: (tariff: ReferenceAnalysisTariff) => number;
21
+ export declare const REFERENCE_ANALYSIS_MIN_PRICED_FPS = 10;
22
+ export declare function referenceAnalysisPrice(tariff: ReferenceAnalysisTariff, durationFrames: number, fps: number): number | null;
23
+ export declare const referenceAnalysisLikelyPrice: (tariff: ReferenceAnalysisTariff, seconds: number) => number | null;
24
+ export declare const referenceAnalysisPriceTable: (tariff: ReferenceAnalysisTariff) => {
25
+ up_to_s: number;
26
+ credits: number;
27
+ }[];
28
+ export declare const referenceAnalysisPriceRange: () => string;
29
+ export declare const referenceAnalysisSince: (tariff: ReferenceAnalysisTariff) => string;
30
+ export declare const referenceLengthUnknownNote: (ceiling: number, refusal: "max_credits" | "balance") => string;
12
31
  export declare const REFERENCE_ANALYSIS_MODES: readonly ["full", "data"];
13
32
  export type ReferenceAnalysisMode = (typeof REFERENCE_ANALYSIS_MODES)[number];
14
- export declare const REFERENCE_ANALYSIS_MODE_CREDITS: Readonly<Record<ReferenceAnalysisMode, number>>;
15
33
  export declare const REFERENCE_ANALYSIS_MAX_SECONDS: Readonly<Record<ReferenceAnalysisMode, number>>;
16
34
  export declare function referenceTooLongMessage(mode: ReferenceAnalysisMode, seconds: number, subject?: string): string | null;
17
35
  export declare const isReferenceTooLongMessage: (line: string) => boolean;
@@ -23,6 +41,8 @@ export declare const REFERENCE_DATA_SHEET_MAX_WIDTH = 1080;
23
41
  export declare const REFERENCE_ANALYSIS_WINDOW_SECONDS = 3600;
24
42
  export declare const REFERENCE_ANALYSIS_WORK_SECONDS = 420;
25
43
  export declare const REFERENCE_ANALYSIS_TASK_MAX_DURATION_SECONDS = 600;
44
+ export declare const REFERENCE_LINK_INGEST_SECONDS: number;
45
+ export declare const REFERENCE_VIDEO_CALL_TIMEOUT_SECONDS = 270;
26
46
  export declare const REFERENCE_ANALYSIS_DEADLINE_SECONDS = 900;
27
47
  export declare const REFERENCE_ANALYSIS_STATES: readonly ["queued", "analyzing", "succeeded", "failed"];
28
48
  export declare const REFERENCE_ANALYSIS_ERRORS: readonly ["timed_out", "analysis_failed", "asset_gone", "enqueue_failed"];
@@ -1474,6 +1494,11 @@ export type ReferenceAnalysis = z.infer<typeof referenceAnalysis>;
1474
1494
  export declare const analysisQuoteResponse: z.ZodObject<{
1475
1495
  asset_id: z.ZodNullable<z.ZodString>;
1476
1496
  credits_estimate: z.ZodNumber;
1497
+ credits_by_length: z.ZodOptional<z.ZodArray<z.ZodObject<{
1498
+ up_to_s: z.ZodNumber;
1499
+ credits: z.ZodNumber;
1500
+ }, z.core.$strict>>>;
1501
+ length_known: z.ZodOptional<z.ZodBoolean>;
1477
1502
  replays_analysis_id: z.ZodNullable<z.ZodString>;
1478
1503
  repeat_note: z.ZodString;
1479
1504
  warnings: z.ZodArray<z.ZodString>;
@@ -12,24 +12,48 @@ export const ANALYZE_REFERENCE_TASK = "analyze-reference";
12
12
  export const ANALYZE_REFERENCE_SKILL = "analyze_reference";
13
13
  export const referenceAnalysisId = z.string().regex(/^ref_[a-f0-9]{32}$/);
14
14
  export const REFERENCE_ANALYSIS_VERSION = 2;
15
- export const REFERENCE_ANALYSIS_CREDITS = 70;
16
15
  export const REFERENCE_DATA_CREDITS = 10;
16
+ export const REFERENCE_ANALYSIS_TARIFFS = [
17
+ { name: "analysis-length-v1", from: "2026-11-22T00:00:00.000Z", stepSeconds: 30, credits: [37, 44, 51, 58, 65, 72] },
18
+ { name: "analysis-length-v2", from: "2026-12-01T00:00:00.000Z", stepSeconds: 30, credits: [66, 80, 93, 107, 120, 134] },
19
+ ];
20
+ export const referenceAnalysisTariff = (name) => REFERENCE_ANALYSIS_TARIFFS.find((tariff) => tariff.name === name) ?? null;
21
+ export function referenceAnalysisTariffAt(at) {
22
+ const started = REFERENCE_ANALYSIS_TARIFFS.filter((tariff) => Date.parse(tariff.from) <= at.getTime());
23
+ return started.at(-1) ?? REFERENCE_ANALYSIS_TARIFFS[0];
24
+ }
25
+ export const referenceAnalysisCeiling = (tariff) => tariff.credits.at(-1);
26
+ export const REFERENCE_ANALYSIS_MIN_PRICED_FPS = 10;
27
+ export function referenceAnalysisPrice(tariff, durationFrames, fps) {
28
+ if (!(durationFrames > 0) || !(fps > 0))
29
+ throw new Error(`a reel of ${durationFrames} frames at ${fps} fps has no price`);
30
+ if (fps < REFERENCE_ANALYSIS_MIN_PRICED_FPS)
31
+ return referenceAnalysisCeiling(tariff);
32
+ if (durationFrames / fps > REFERENCE_ANALYSIS_MAX_SECONDS.full)
33
+ return null;
34
+ const step = Math.max(1, Math.ceil((durationFrames - Math.floor(fps / 2)) / (tariff.stepSeconds * fps)));
35
+ return tariff.credits[Math.min(step, tariff.credits.length) - 1];
36
+ }
37
+ export const referenceAnalysisLikelyPrice = (tariff, seconds) => seconds > 0 ? referenceAnalysisPrice(tariff, Math.round(seconds * 1000), 1000) : null;
38
+ export const referenceAnalysisPriceTable = (tariff) => tariff.credits.map((credits, index) => ({ up_to_s: (index + 1) * tariff.stepSeconds, credits }));
39
+ export const referenceAnalysisPriceRange = () => REFERENCE_ANALYSIS_TARIFFS.map((tariff, index) => `${tariff.credits[0]} to ${referenceAnalysisCeiling(tariff)}${index === 0 ? " credits by the reel's length" : ` ${referenceAnalysisSince(tariff)}`}`).join(", ");
40
+ export const referenceAnalysisSince = (tariff) => "from " + tariff.from.slice(0, 10);
41
+ export const referenceLengthUnknownNote = (ceiling, refusal) => refusal === "max_credits"
42
+ ? `The reel's length is unknown until it is read, so the start holds ${ceiling}; the charge follows the length and never exceeds it. ` +
43
+ "An uploaded clip is quoted at its exact price."
44
+ : `The reel's length is unknown until it is read, so the start holds ${ceiling}, the most a full analysis costs; the charge ` +
45
+ "follows the length. An uploaded clip is held at its exact price.";
17
46
  export const REFERENCE_ANALYSIS_MODES = ["full", "data"];
18
- export const REFERENCE_ANALYSIS_MODE_CREDITS = {
19
- full: REFERENCE_ANALYSIS_CREDITS, data: REFERENCE_DATA_CREDITS,
20
- };
21
47
  export const REFERENCE_ANALYSIS_MAX_SECONDS = {
22
- full: ASSET_VIDEO_MAX_SECONDS, data: ANALYSIS_VIDEO_MAX_SECONDS,
48
+ full: ANALYSIS_VIDEO_MAX_SECONDS, data: ANALYSIS_VIDEO_MAX_SECONDS,
23
49
  };
24
50
  const REFERENCE_TOO_LONG_LEAD = "the reel lasts ";
25
51
  export function referenceTooLongMessage(mode, seconds, subject = "the reel") {
26
52
  const most = REFERENCE_ANALYSIS_MAX_SECONDS[mode];
27
53
  if (seconds <= most)
28
54
  return null;
29
- const lead = `${subject === "the reel" ? REFERENCE_TOO_LONG_LEAD : `${subject} lasts `}${seconds.toFixed(1)} s; a ${mode} analysis reads at most ${most} s`;
30
- return mode === "full" && seconds <= REFERENCE_ANALYSIS_MAX_SECONDS.data
31
- ? `${lead}; start it with mode: "data", which reads reels up to ${REFERENCE_ANALYSIS_MAX_SECONDS.data} s, for ${REFERENCE_DATA_CREDITS} credits`
32
- : `${lead}; use a shorter clip`;
55
+ return `${subject === "the reel" ? REFERENCE_TOO_LONG_LEAD : `${subject} lasts `}${seconds.toFixed(1)} s; a ${mode} analysis reads at most ${most} s; ` +
56
+ "use a shorter clip";
33
57
  }
34
58
  export const isReferenceTooLongMessage = (line) => line.startsWith(REFERENCE_TOO_LONG_LEAD) && / analysis reads at most \d+ s/.test(line);
35
59
  export const REFERENCE_ANALYSIS_PER_HOUR = 10;
@@ -40,6 +64,8 @@ export const REFERENCE_DATA_SHEET_MAX_WIDTH = 1080;
40
64
  export const REFERENCE_ANALYSIS_WINDOW_SECONDS = 3600;
41
65
  export const REFERENCE_ANALYSIS_WORK_SECONDS = 420;
42
66
  export const REFERENCE_ANALYSIS_TASK_MAX_DURATION_SECONDS = 600;
67
+ export const REFERENCE_LINK_INGEST_SECONDS = REFERENCE_ANALYSIS_TASK_MAX_DURATION_SECONDS - REFERENCE_ANALYSIS_WORK_SECONDS - 60;
68
+ export const REFERENCE_VIDEO_CALL_TIMEOUT_SECONDS = 270;
43
69
  export const REFERENCE_ANALYSIS_DEADLINE_SECONDS = 900;
44
70
  export const REFERENCE_ANALYSIS_STATES = ["queued", "analyzing", "succeeded", "failed"];
45
71
  export const REFERENCE_ANALYSIS_ERRORS = ["timed_out", "analysis_failed", "asset_gone", "enqueue_failed"];
@@ -84,11 +110,11 @@ export function classifyReferenceUrl(raw) {
84
110
  }
85
111
  export const analyzeReferenceRequest = z.strictObject({
86
112
  asset_id: assetId.optional().describe(`asset_id of an MP4 asset of this account, at most 100 MiB and ${ASSET_VIDEO_MAX_SECONDS} s, ` +
87
- `or ${ANALYSIS_VIDEO_MAX_SECONDS} s for an analysis_only asset in mode data`),
113
+ `or ${ANALYSIS_VIDEO_MAX_SECONDS} s for an analysis_only asset`),
88
114
  source_url: z.string().url().startsWith("https://").max(2048).optional()
89
115
  .describe(`instead of asset_id: ${REFERENCE_URL_ACCEPTED}; YouTube is refused`),
90
- mode: z.enum(REFERENCE_ANALYSIS_MODES).optional().describe(`full (default, ${REFERENCE_ANALYSIS_CREDITS} credits, reels up to ` +
91
- `${ASSET_VIDEO_MAX_SECONDS} s): the reference_profile. data (${REFERENCE_DATA_CREDITS} credits, reels up to ${ANALYSIS_VIDEO_MAX_SECONDS} s): ` +
116
+ mode: z.enum(REFERENCE_ANALYSIS_MODES).optional().describe(`full (default, ${referenceAnalysisPriceRange()}, reels up to ` +
117
+ `${REFERENCE_ANALYSIS_MAX_SECONDS.full} s): the reference_profile. data (${REFERENCE_DATA_CREDITS} credits, reels up to ${REFERENCE_ANALYSIS_MAX_SECONDS.data} s): ` +
92
118
  "duration, size, timed transcript, scenes between measured cuts, hook and a 3×3 frame sheet, without beats or graphics"),
93
119
  max_credits: maxCreditsField,
94
120
  }).refine((request) => (request.asset_id === undefined) !== (request.source_url === undefined), {
@@ -206,7 +232,7 @@ export const referenceFramesPage = z.strictObject({
206
232
  .describe(`End second, exclusive; at most ${REFERENCE_FRAMES_PAGE_MAX} frames a page.`),
207
233
  });
208
234
  export const REFERENCE_WAIT_MAX_SECONDS = 50;
209
- export const REFERENCE_EXPECTED_SECONDS = { full: 150, data: 45 };
235
+ export const REFERENCE_EXPECTED_SECONDS = { full: 210, data: 45 };
210
236
  export const referenceAnalysisQuery = referenceFramesPage.extend({
211
237
  wait_seconds: z.coerce.number().int().min(0).max(REFERENCE_WAIT_MAX_SECONDS).optional()
212
238
  .describe(`Wait up to this many seconds (at most ${REFERENCE_WAIT_MAX_SECONDS}) for the analysis to finish before answering.`),
@@ -253,6 +279,8 @@ export const referenceAnalysis = z.strictObject({
253
279
  export const analysisQuoteResponse = z.strictObject({
254
280
  asset_id: assetId.nullable(),
255
281
  credits_estimate: z.number().int().nonnegative(),
282
+ credits_by_length: z.array(z.strictObject({ up_to_s: z.number().int().positive(), credits: z.number().int().positive() })).optional(),
283
+ length_known: z.boolean().optional(),
256
284
  replays_analysis_id: referenceAnalysisId.nullable(),
257
285
  repeat_note: z.string(),
258
286
  warnings: z.array(z.string()),
@@ -289,8 +317,8 @@ export const ANALYZE_REFERENCE_DESCRIPTION = "Break down any reel or ad into a r
289
317
  "graphic's label_hint. speakers names who talks, on or off screen, with their caption look; each beat names its speaker, gaze " +
290
318
  "and gestures, each claim citing frames_s. " +
291
319
  "What we cannot draw is in unmapped with a substitute and in warnings. Pass asset_id of an MP4 asset (create_asset " +
292
- `with kind: "video"), at most 100 MiB, or source_url: ${REFERENCE_URL_ACCEPTED}. Full reads reels up to ` +
293
- `${REFERENCE_ANALYSIS_MAX_SECONDS.full} s, data up to ${REFERENCE_ANALYSIS_MAX_SECONDS.data} s (a link or an analysis_only asset); a longer reel ` +
320
+ `with kind: "video"), at most 100 MiB, or source_url: ${REFERENCE_URL_ACCEPTED}. Both modes read reels up to ` +
321
+ `${REFERENCE_ANALYSIS_MAX_SECONDS.full} s (a link or an analysis_only asset; any other asset is at most ${ASSET_VIDEO_MAX_SECONDS} s); a longer reel ` +
294
322
  "is refused at no charge, before its video is downloaded when the platform gives its length, and the error message names the limit. " +
295
323
  "A link becomes an analysis-only asset (asset_id in the answer), and source carries the post's caption, author, engagement, " +
296
324
  "the author's followers and median views with the ratio (x), the top 50 comments and their code words; a number, caption or " +
@@ -299,11 +327,12 @@ export const ANALYZE_REFERENCE_DESCRIPTION = "Break down any reel or ad into a r
299
327
  `mode: "data" skips beats and graphics and answers data: duration, size and fps, the timed ` +
300
328
  "transcript and segments, scenes between measured cuts with their segments, the hook with the post's caption line and its frame, " +
301
329
  "and a 3×3 frame sheet, plus source for a link; no speech gives an empty transcript and a " +
302
- `warning. ${REFERENCE_ANALYSIS_CREDITS} credits for full, ${REFERENCE_DATA_CREDITS} for data, held at the start and charged once it ` +
303
- "succeeds; a failed analysis costs nothing. " +
330
+ `warning. Full costs ${referenceAnalysisPriceRange()}; quote_analysis gives the exact price. A link of unknown length ` +
331
+ `holds the most and is charged by the length. Data costs ${REFERENCE_DATA_CREDITS}. ` +
332
+ "The price is held at the start and charged once it succeeds; a failed analysis costs nothing. " +
304
333
  `${REFERENCE_ANALYSIS_PER_HOUR} new full and ${REFERENCE_DATA_PER_HOUR} new data analyses per hour per account. ` +
305
334
  `Answers at once with state queued; call get_reference_analysis with wait_seconds: ${REFERENCE_WAIT_MAX_SECONDS} until succeeded or failed ` +
306
- "(full about 2–3 minutes, data under one). " +
335
+ "(full about 2–4 minutes, data under one). " +
307
336
  "The same asset, or reel by its full link, in the same mode returns the same analysis, free, unless it " +
308
337
  "failed, and a short vt.tiktok.com or vm.tiktok.com link counts as the full link of its video. An analysis made before frames and speakers existed is redone free " +
309
338
  "once (replaces_analysis_id names the old one, still readable). The asset is not changed. " +
@@ -324,7 +353,9 @@ export const GET_REFERENCE_ANALYSIS_DESCRIPTION = "Read an analysis started by a
324
353
  "0 once failed; repeat_note says " +
325
354
  "what asking again costs. Free.";
326
355
  export const QUOTE_ANALYSIS_DESCRIPTION = "Price analyze_reference for an asset_id or a source_url and a mode before starting it: credits_estimate is what a start " +
327
- `holds and charges once it succeeds (${REFERENCE_ANALYSIS_CREDITS} full, ${REFERENCE_DATA_CREDITS} data), 0 when the ` +
356
+ `holds and, once it succeeds, at most charges: full ${referenceAnalysisPriceRange()}, data ${REFERENCE_DATA_CREDITS}. ` +
357
+ "credits_by_length lists today's full prices; length_known: false means the length is not known yet: the estimate is the most " +
358
+ "and the charge follows the reel's length. It is 0 when the " +
328
359
  "asset or the reel already has an analysis in that mode that a start would answer (replays_analysis_id), and 0 when a start " +
329
360
  "would redo an analysis made before frames and speakers were added. repeat_note says, in a sentence for the user, what asking again costs. A YouTube or " +
330
361
  "unknown link is refused here too. Free; starts nothing.";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clipwright/core",
3
- "version": "0.75.2",
3
+ "version": "0.77.0",
4
4
  "description": "Zod schemas and the shared request/response contract of the Clipwright UGC video API",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,97 +0,0 @@
1
- import { z } from "zod";
2
- declare const plan: z.ZodObject<{
3
- version: z.ZodLiteral<"faceless_image_v1">;
4
- script: z.ZodString;
5
- aspectRatio: z.ZodLiteral<"9:16">;
6
- resolution: z.ZodLiteral<"1080p">;
7
- brollPolicy: z.ZodEnum<{
8
- anyone: "anyone";
9
- no_actor: "no_actor";
10
- no_people: "no_people";
11
- }>;
12
- assets: z.ZodArray<z.ZodObject<{
13
- id: z.ZodString;
14
- role: z.ZodEnum<{
15
- character: "character";
16
- scene: "scene";
17
- style: "style";
18
- }>;
19
- source: z.ZodDiscriminatedUnion<[z.ZodObject<{
20
- kind: z.ZodLiteral<"supplied">;
21
- url: z.ZodURL;
22
- }, z.core.$strict>, z.ZodObject<{
23
- kind: z.ZodLiteral<"generated">;
24
- prompt: z.ZodString;
25
- styleId: z.ZodOptional<z.ZodString>;
26
- characterIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
27
- }, z.core.$strict>], "kind">;
28
- }, z.core.$strict>>;
29
- scenes: z.ZodArray<z.ZodObject<{
30
- id: z.ZodString;
31
- assetId: z.ZodString;
32
- durationFrames: z.ZodNumber;
33
- motion: z.ZodOptional<z.ZodObject<{
34
- direction: z.ZodEnum<{
35
- in: "in";
36
- out: "out";
37
- }>;
38
- amount: z.ZodNumber;
39
- }, z.core.$strict>>;
40
- }, z.core.$strict>>;
41
- }, z.core.$strict>;
42
- export type FacelessImagePlan = z.infer<typeof plan>;
43
- export declare function parseFacelessImagePlan(input: unknown): FacelessImagePlan;
44
- export declare function quoteFacelessImage(input: unknown): {
45
- pricingVersion: "faceless-image-v1-shadow";
46
- aspectRatio: "9:16";
47
- resolution: "1080p";
48
- outputFrames: number;
49
- outputSeconds: number;
50
- credits: number;
51
- customerCreditCeiling: number;
52
- baseGeneratedImages: number;
53
- maxGeneratedImages: number;
54
- retryHeadroom: number;
55
- costBreakdown: {
56
- generatedImages: {
57
- status: "unmeasured";
58
- usd: null;
59
- exposureBasis: "hypothetical_two_attempts_per_generated_asset_within_shared_allowance";
60
- maxPaidAttemptsPerAsset: number;
61
- maxPaidImageCalls: number;
62
- };
63
- tts: {
64
- status: "unmeasured";
65
- usd: null;
66
- };
67
- rendering: {
68
- status: "unmeasured";
69
- usd: null;
70
- };
71
- storage: {
72
- status: "unmeasured";
73
- usd: null;
74
- };
75
- paymentFees: {
76
- status: "unmeasured";
77
- usd: null;
78
- };
79
- paidFailures: {
80
- status: "unmeasured";
81
- usd: null;
82
- };
83
- };
84
- totalCostUsd: null;
85
- contributionMargin: null;
86
- costQualified: boolean;
87
- marginQualified: boolean;
88
- sceneCount: number;
89
- sceneSources: {
90
- sceneId: string;
91
- assetId: string;
92
- sourceKind: "generated" | "supplied";
93
- }[];
94
- maxPaidAttempts: 0;
95
- maxUsdSpend: 0;
96
- };
97
- export {};
@@ -1,143 +0,0 @@
1
- import { z } from "zod";
2
- import { brollPolicy } from "./broll-policy.js";
3
- import { CANVAS_FPS } from "./media-timebase.js";
4
- import { MAX_URL_LENGTH } from "./skills.js";
5
- import { DEFAULT_TTS_MODEL, speechTextFor, TTS_MODEL_CHAR_CAP } from "./voices.js";
6
- const id = z.string().min(1);
7
- const suppliedSource = z.strictObject({
8
- kind: z.literal("supplied"),
9
- url: z.url().max(MAX_URL_LENGTH).refine(url => {
10
- const source = new URL(url);
11
- return source.protocol === "https:" && /\.(png|jpe?g)$/i.test(source.pathname);
12
- }, "supplied image URL must use HTTPS with a PNG or JPEG path suffix"),
13
- });
14
- const generatedSource = z.strictObject({
15
- kind: z.literal("generated"),
16
- prompt: z.string().trim().min(1),
17
- styleId: id.optional(),
18
- characterIds: z.array(id).optional(),
19
- });
20
- const asset = z.strictObject({
21
- id,
22
- role: z.enum(["scene", "style", "character"]),
23
- source: z.discriminatedUnion("kind", [suppliedSource, generatedSource]),
24
- });
25
- const scene = z.strictObject({
26
- id,
27
- assetId: id,
28
- durationFrames: z.number().int().positive().refine(Number.isSafeInteger, "durationFrames must be a safe integer"),
29
- motion: z.strictObject({ direction: z.enum(["in", "out"]), amount: z.number().min(0).lt(1) }).optional(),
30
- });
31
- const plan = z.strictObject({
32
- version: z.literal("faceless_image_v1"),
33
- script: z.string().trim().min(1).refine(text => speechTextFor(text, DEFAULT_TTS_MODEL).length <= TTS_MODEL_CHAR_CAP[DEFAULT_TTS_MODEL], `script exceeds ${DEFAULT_TTS_MODEL} limit of ${TTS_MODEL_CHAR_CAP[DEFAULT_TTS_MODEL]} characters after stress normalization`),
34
- aspectRatio: z.literal("9:16"),
35
- resolution: z.literal("1080p"),
36
- brollPolicy,
37
- assets: z.array(asset).min(1),
38
- scenes: z.array(scene).min(1).max(100),
39
- });
40
- export function parseFacelessImagePlan(input) {
41
- const parsed = plan.parse(input);
42
- const assets = new Map();
43
- for (const entry of parsed.assets) {
44
- if (assets.has(entry.id))
45
- throw new Error(`duplicate faceless IMAGE asset ID: ${entry.id}`);
46
- if (entry.role !== "scene" && entry.source.kind === "generated" &&
47
- (entry.source.styleId !== undefined || entry.source.characterIds !== undefined)) {
48
- throw new Error(`faceless IMAGE references belong on scene assets: ${entry.id}`);
49
- }
50
- assets.set(entry.id, entry);
51
- }
52
- const used = new Set();
53
- const sceneIds = new Set();
54
- let sharedStyleId;
55
- for (const entry of parsed.scenes) {
56
- if (sceneIds.has(entry.id))
57
- throw new Error(`duplicate faceless IMAGE scene ID: ${entry.id}`);
58
- sceneIds.add(entry.id);
59
- const image = assets.get(entry.assetId);
60
- if (image?.role !== "scene")
61
- throw new Error(`faceless IMAGE scene asset missing or wrong role: ${entry.assetId}`);
62
- used.add(image.id);
63
- if (image.source.kind === "generated") {
64
- const style = image.source.styleId === undefined ? undefined : assets.get(image.source.styleId);
65
- if (style?.role !== "style")
66
- throw new Error(`faceless IMAGE style asset missing or wrong role: ${image.id}`);
67
- if (sharedStyleId !== undefined && sharedStyleId !== style.id)
68
- throw new Error("faceless IMAGE scenes require one shared style anchor");
69
- sharedStyleId = style.id;
70
- used.add(style.id);
71
- const characters = image.source.characterIds ?? [];
72
- if (parsed.brollPolicy !== "anyone" && characters.length > 0)
73
- throw new Error("character references require the anyone policy");
74
- if (new Set(characters).size !== characters.length)
75
- throw new Error(`duplicate character reference: ${image.id}`);
76
- for (const characterId of characters) {
77
- const character = assets.get(characterId);
78
- if (character?.role !== "character")
79
- throw new Error(`faceless IMAGE character asset missing or wrong role: ${characterId}`);
80
- used.add(characterId);
81
- }
82
- }
83
- }
84
- for (const entry of parsed.assets) {
85
- if (!used.has(entry.id))
86
- throw new Error(`unreferenced faceless IMAGE asset: ${entry.id}`);
87
- }
88
- const outputFrames = parsed.scenes.reduce((sum, entry) => sum + entry.durationFrames, 0);
89
- if (!Number.isSafeInteger(outputFrames) || outputFrames > 300 * CANVAS_FPS)
90
- throw new Error("faceless IMAGE exceeds 300 seconds");
91
- const maxGeneratedImages = Math.floor((24 * outputFrames) / (60 * CANVAS_FPS));
92
- const baseGeneratedImages = parsed.assets.filter(entry => entry.source.kind === "generated").length;
93
- if (baseGeneratedImages > maxGeneratedImages)
94
- throw new Error("faceless IMAGE exceeds generated image allowance");
95
- return parsed;
96
- }
97
- export function quoteFacelessImage(input) {
98
- const parsed = parseFacelessImagePlan(input);
99
- const outputFrames = parsed.scenes.reduce((sum, entry) => sum + entry.durationFrames, 0);
100
- const maxGeneratedImages = Math.floor((24 * outputFrames) / (60 * CANVAS_FPS));
101
- const baseGeneratedImages = parsed.assets.filter(entry => entry.source.kind === "generated").length;
102
- const raw = (180n * BigInt(outputFrames) + BigInt(60 * CANVAS_FPS - 1)) / BigInt(60 * CANVAS_FPS);
103
- const credits = Number(raw > 200n ? raw : 200n);
104
- const assetById = new Map(parsed.assets.map(entry => [entry.id, entry]));
105
- return {
106
- pricingVersion: "faceless-image-v1-shadow",
107
- aspectRatio: parsed.aspectRatio,
108
- resolution: parsed.resolution,
109
- outputFrames,
110
- outputSeconds: outputFrames / CANVAS_FPS,
111
- credits,
112
- customerCreditCeiling: credits,
113
- baseGeneratedImages,
114
- maxGeneratedImages,
115
- retryHeadroom: maxGeneratedImages - baseGeneratedImages,
116
- costBreakdown: {
117
- generatedImages: {
118
- status: "unmeasured",
119
- usd: null,
120
- exposureBasis: "hypothetical_two_attempts_per_generated_asset_within_shared_allowance",
121
- maxPaidAttemptsPerAsset: 2,
122
- maxPaidImageCalls: Math.min(maxGeneratedImages, 2 * baseGeneratedImages),
123
- },
124
- tts: { status: "unmeasured", usd: null },
125
- rendering: { status: "unmeasured", usd: null },
126
- storage: { status: "unmeasured", usd: null },
127
- paymentFees: { status: "unmeasured", usd: null },
128
- paidFailures: { status: "unmeasured", usd: null },
129
- },
130
- totalCostUsd: null,
131
- contributionMargin: null,
132
- costQualified: false,
133
- marginQualified: false,
134
- sceneCount: parsed.scenes.length,
135
- sceneSources: parsed.scenes.map(entry => ({
136
- sceneId: entry.id,
137
- assetId: entry.assetId,
138
- sourceKind: assetById.get(entry.assetId).source.kind,
139
- })),
140
- maxPaidAttempts: 0,
141
- maxUsdSpend: 0,
142
- };
143
- }