import type { TokenCounter } from './types.js'; /** * What a prompt is made of, so a team can decide which one to fix first. * * ## Why this is not a score * * The obvious shape for "which prompts should we optimise?" is a number out of * a hundred, and it is the wrong shape. `Complexity: 74` cannot be argued with, * cannot be reproduced by hand, and does not tell anybody what to do on Monday. * Worse, the weights that turn four measurements into one number are invented — * and once invented they get tuned until the ranking looks right, which is * fitting the metric to the answer. * * So this returns **the measurements**, each with a definition you can check * against the prompt in front of you, and ranks on the one quantity that is not * a matter of opinion: **what optimising it would actually save.** That figure * comes from running the deterministic rules, not from a formula. * * The structural facts are the *explanation* for a prompt's position in that * ranking, not a substitute for it. "1,204 tokens across 8 sentences" says why * a prompt is worth looking at; "$310 a month recoverable" says whether it is * worth looking at before the other thirty-nine. * * ## What each measurement means, exactly * * - **sentences** — spans ending in `.`, `!`, `?`, `。`, `!`, `?`, or a line * break where the line ends without punctuation (a bullet is a sentence). * Protected content is excluded, so a code block is not forty sentences. * - **tokensPerSentence** — the verbosity signal, and the only ratio here. It * is length-independent: a padded 300-token prompt and a padded 3,000-token * one look the same, which is the point. Reported with units, never as an * index. * - **examples / exampleTokens** — from `findExamples`, the same detector the * advisories use. Few-shot examples are usually the largest single block in * an expensive prompt and the easiest to trim by one. * - **formatTokens** — a restated output format (a JSON schema written out * twice, or written out at all when the API takes a schema parameter). * - **protectedTokens** — code, URLs, placeholders and tags. Counted separately * because **no amount of optimising will touch them**, and a prompt that is * 80% code has far less headroom than its size suggests. Leaving this out is * how a ranking sends somebody to spend an afternoon on a file that cannot * move. */ export interface PromptProfile { tokens: number; /** Tokens that cannot be touched: code, URLs, placeholders, tags. */ protectedTokens: number; sentences: number; /** `tokens / sentences`, rounded to one decimal. Zero when there are none. */ tokensPerSentence: number; examples: number; exampleTokens: number; /** Tokens in a restated output format, or 0. */ formatTokens: number; } /** * Sentences in the mutable part of the prompt. * * Deliberately simple and stated rather than clever. An abbreviation splits a * sentence in two here, and that is accepted: the number is used as a * denominator for a verbosity ratio, where a few percent of noise changes * nothing, and the alternative is a sentence tokeniser this project would then * have to defend. */ export declare function countSentences(prompt: string): number; export interface ProfileOptions { count?: TokenCounter; } /** Measures a prompt. Deterministic, offline, and free. */ export declare function profilePrompt(prompt: string, options?: ProfileOptions): PromptProfile; //# sourceMappingURL=profile.d.ts.map