import type { Message } from '../types/messages.js'; import type { PromptDefinition, PromptMessageTemplate, PromptModelConfig, PromptReference, RenderedPrompt, RenderOptions } from '../types/prompts.js'; type Trim = S extends ` ${infer R}` ? Trim : S extends `${infer R} ` ? Trim : S; type Head = S extends `${infer H}.${string}` ? H : S; type NameOf = Trim extends `>${string}` ? never : Head>; /** * The variables a template string uses, as a union of names: `'topic' | 'user'` for * `"Write about {{topic}} for {{user.name}}"`. A string that is not a literal gives `string`. */ export type TemplateVariables = string extends S ? string : S extends `${string}{{${infer B}}}${infer R}` ? TemplateVariables> : Acc; /** * What `render()` takes for a prompt with variables `V`, placeholders `H`, and defaults `D`: * every variable without a default is required, and placeholders take arrays of messages. */ export type PromptInput = string extends V ? Record : { [K in Exclude]: unknown; } & { [K in D]?: unknown; } & { [K in H]?: Message[]; }; type RenderArgs = [Exclude] extends [never] ? [variables?: PromptInput, options?: RenderOptions] : [variables: PromptInput, options?: RenderOptions]; /** A defined prompt, compiled once and rendered many times. */ export interface Prompt { /** The prompt's name. */ readonly name: string; /** The definition it was built from, which is what a registry commits. */ readonly definition: PromptDefinition; /** Every variable its templates and placeholders use, sorted. */ readonly variables: readonly string[]; /** Renders a completion request. Throws `PromptRenderError` for missing variables unless told otherwise. */ render(...args: RenderArgs): RenderedPrompt; /** The content version a registry would assign this definition. */ version(): Promise; } /** The input `definePrompt()` infers variable names from. */ export interface PromptSpec { /** The prompt's name, which identifies it in a registry. */ name: string; /** The messages it renders: templates, and placeholders for whole messages. */ messages: ReadonlyArray<{ role: PromptMessageTemplate['role']; content: C; name?: string; } | { placeholder: H; optional?: boolean; }>; /** Named fragments included with `{{> name}}`. */ partials?: Record; /** Request settings versioned with the prompt. */ config?: PromptModelConfig; /** Values for variables the caller may leave out. */ defaults?: { [K in D]: unknown; }; /** Application data. Not part of the version. */ metadata?: Record; } type Segment = string | { path: string[]; }; /** A message template reduced to text and variable lookups, with partials already inlined. */ export type CompiledMessage = { role: PromptMessageTemplate['role']; name?: string; segments: Segment[]; } | { placeholder: string; optional: boolean; }; /** A definition compiled for rendering. */ export interface CompiledPrompt { /** The compiled messages. */ messages: CompiledMessage[]; /** Every variable used, sorted. */ variables: string[]; } /** * Compiles a definition: parses every template, inlines partials, and lists the variables. * * Throws `PromptDefinitionError` for an unknown partial, a partial that includes itself, or a tag * that is not a variable name. */ export declare function compilePrompt(definition: PromptDefinition): CompiledPrompt; /** Renders a compiled prompt into a completion request, recording `reference` in `metadata.prompt`. */ export declare function renderCompiled(compiled: CompiledPrompt, definition: PromptDefinition, variables?: Record, reference?: PromptReference, options?: RenderOptions): RenderedPrompt; /** * Defines a prompt, typing its variables from the template text. * * `render()` then requires every variable without a default, and the prompt can be committed to a * registry as it is. Templates use `{{name}}` and `{{name.path}}` for values and `{{> partial}}` for * named fragments; objects are rendered as JSON. There is no escape syntax: to render a literal * `{{`, pass it in through a variable. * * @example * ```ts * const summarize = definePrompt({ * name: 'summarize', * messages: [ * { role: 'system', content: 'You summarize {{kind}} for {{audience}}.' }, * { placeholder: 'history', optional: true }, * { role: 'user', content: '{{text}}' }, * ], * defaults: { audience: 'engineers' }, * config: { model: 'gpt-5.4-mini', temperature: 0 }, * }); * const request = summarize.render({ kind: 'incident reports', text }); * ``` */ export declare function definePrompt(spec: PromptSpec): Prompt | TemplateVariables

| H, H, D>; export {};