/** * Credits one article's text costs, per language version. Mirrors the * agent's ``CREDITS_ARTICLE_TEXT``; the debit itself happens server-side. */ export const CREDITS_ARTICLE_TEXT: number = 200; /** Credits one generated image costs. Mirrors ``CREDITS_ARTICLE_IMAGE``. */ export const CREDITS_ARTICLE_IMAGE: number = 120; /** Credits one social post costs. Mirrors the agent's ``CREDITS_SOCIAL_POST``. */ export const CREDITS_SOCIAL_POST: number = 25; /** * Credits one generated field (title, description, tags or FAQ) costs per * product. Mirrors the agent's ``CREDITS_PER_GENERATED_FIELD``. */ export const CREDITS_PER_GENERATED_FIELD: number = 10; /** * Credits a content-generation run costs: every field it writes, for every * product, with one field's worth the least a product is billed. * * @param {number} products - Products the run writes for. * @param {number} fields - Fields written per product. * @returns {number} The credits the run debits. */ export const generatedFieldsCostCredits = ( products: number, fields: number ): number => Math.max(0, products) * Math.max(1, fields) * CREDITS_PER_GENERATED_FIELD; /** * Credits one inline fix on a product costs: a single call, or the gap mode's * generate-and-compare pair. Mirror ``CREDITS_INLINE_SINGLE_CALL`` and * ``CREDITS_INLINE_GAP_MODE``. */ export const CREDITS_INLINE_SINGLE_CALL: number = 10; export const CREDITS_INLINE_GAP_MODE: number = 15; /** * Credits generating one piece of content costs across its language versions. * * @param {number} languageCount - Languages generated at once; anything under one reads as one. * @returns {number} The text cost; images are debited separately when generated. */ export const articleCostCredits = (languageCount: number): number => CREDITS_ARTICLE_TEXT * Math.max(1, languageCount); /** * Credits a knowledge-base document costs, by its length in pages of about * 2,000 characters. Mirror the agent's ``KB_DOC_TIER_*`` values. */ export const KB_DOCUMENT_TIERS: ReadonlyArray<{ maxPages: number | null; credits: number; }> = [ { maxPages: 10, credits: 1 }, { maxPages: 50, credits: 5 }, { maxPages: null, credits: 15 }, ]; /** * A credit amount as the label the buttons print, e.g. ``250 credits``. * * @param {number} credits - The amount. * @returns {string} The formatted label. */ export const formatCredits = (credits: number): string => `${credits.toLocaleString('en-US')} ${credits === 1 ? 'credit' : 'credits'}`; /** * Credits a regeneration costs: what writing the row costs in the first * place, so a social post is priced as a post and anything else as an article. * * @param {string | undefined} contentType - The row's content type. * @returns {number} The credits one regeneration debits. */ export const regenerateCostCredits = ( contentType: string | undefined ): number => contentType === 'social' ? CREDITS_SOCIAL_POST : CREDITS_ARTICLE_TEXT; /** * The knowledge base's price, said once beside the button that processes the * files, since every document is billed by its own length. * * @returns {string} The sentence, e.g. ``Each document costs 1 credit up to 10 pages, …``. */ export const kbDocumentCostNote = (): string => { const [small, medium, large] = KB_DOCUMENT_TIERS; return `Each document costs ${formatCredits(small.credits)} up to ${ small.maxPages } pages, ${formatCredits(medium.credits)} up to ${ medium.maxPages } pages and ${formatCredits(large.credits)} beyond.`; };