Skip to main content

@flow-state-dev/core/prompt-file

Classes​

PromptFileLoadError​

Thrown when a prompt file cannot be read from disk.

Extends​

  • Error

Constructors​

Constructor​
new PromptFileLoadError(message, options?): PromptFileLoadError;
Parameters​
message​

string

options?​
cause?​

unknown

sourcePath?​

string

Returns​

PromptFileLoadError

Overrides​

Error.constructor

Properties​

cause?​
cause?: unknown;
Inherited from​

Error.cause

message​
message: string;
Inherited from​

Error.message

name​
name: string;
Inherited from​

Error.name

sourcePath?​
readonly sourcePath?: string;
stack?​
stack?: string;
Inherited from​

Error.stack


PromptFileParseError​

Thrown when a prompt file's frontmatter, body grammar, or templates are invalid. Carries the source path and the underlying cause.

Extends​

  • Error

Constructors​

Constructor​
new PromptFileParseError(message, options?): PromptFileParseError;
Parameters​
message​

string

options?​
cause?​

unknown

sourcePath?​

string

Returns​

PromptFileParseError

Overrides​

Error.constructor

Properties​

cause?​
cause?: unknown;
Inherited from​

Error.cause

message​
message: string;
Inherited from​

Error.message

name​
name: string;
Inherited from​

Error.name

sourcePath?​
readonly sourcePath?: string;
stack?​
stack?: string;
Inherited from​

Error.stack

Interfaces​

ParsePromptFileOptions​

Options for parsePromptFile.

Properties​

filters?​
filters?: PromptFileFilters;

Custom Liquid filters, scoped to this PromptFile (no global registry).

partials?​
partials?: PromptFilePartials;

Pre-registered partials. The Node loader populates this from sibling .md files; browser consumers pass it explicitly.

sourcePath?​
sourcePath?: string;

Source path, used in error messages and trace capture.


PromptFile​

Parsed prompt file. prompt / user are async renderers wired into the generator config; _meta carries the brand handle and parse metadata.

Properties​

_meta​
readonly _meta: object;
frontmatter​
readonly frontmatter: object;
frontmatter.caching?​
caching?:
| boolean
| {
breakpoints?: "auto" | "manual";
enabled?: boolean;
ttl?: "5m" | "1h";
};
frontmatter.description?​
description?: string;
frontmatter.intent?​
intent?: string;
frontmatter.maxTokens?​
maxTokens?: number;
frontmatter.model?​
model?: string;
frontmatter.name?​
name?: string;
frontmatter.temperature?​
temperature?: number;
hasContextBlock​
readonly hasContextBlock: boolean;
hasUserBlock​
readonly hasUserBlock: boolean;
source​
readonly source: string;
caching?​
readonly caching?: boolean | CachingConfig;
description?​
readonly description?: string;
maxTokens?​
readonly maxTokens?: number;
name?​
readonly name?: string;
prompt​
readonly prompt: BrandedPromptSlot;

System-section renderer. Branded so the generator detects it.

temperature?​
readonly temperature?: number;
user?​
readonly user?: (input, ctx, config?) => Promise<string>;

User-section renderer, present only when the file declares <user>.

Parameters​
input​

unknown

ctx​

BlockContext

config?​

PromptFileConfigView

Returns​

Promise<string>


PromptFileBrand​

The brand handle the generator reads off a PromptFile's prompt closure to drive template-aware composition.

Properties​

frontmatter​
readonly frontmatter: Record<string, unknown>;
hasContextBlock​
readonly hasContextBlock: boolean;
hasUserBlock​
readonly hasUserBlock: boolean;
rawText​
readonly rawText: string;

Raw .md file text, surfaced in the DevTool trace alongside the render.

source​
readonly source: string;

Source path (or "(inline)"), used in error messages and trace capture.

Methods​

renderContext()​
renderContext(scope): Promise<string> | undefined;

Render the <context> body, or undefined when no <context> block.

Parameters​
scope​

PromptFileRenderScope

Returns​

Promise<string> | undefined

renderSystem()​
renderSystem(scope): Promise<string>;

Render the <system> body against the given scope.

Parameters​
scope​

PromptFileRenderScope

Returns​

Promise<string>

renderUser()​
renderUser(scope): Promise<string> | undefined;

Render the <user> body, or undefined when no <user> block.

Parameters​
scope​

PromptFileRenderScope

Returns​

Promise<string> | undefined


PromptFileConfig​

Spreadable subset of a PromptFile that slots into a generator config. caching is normalized to the object form the generator config accepts (frontmatter's caching: true / false becomes { enabled: ... }).

Properties​

caching?​
readonly caching?: CachingConfig;
description?​
readonly description?: string;
maxTokens?​
readonly maxTokens?: number;
name?​
readonly name?: string;
prompt​
readonly prompt: BrandedPromptSlot;
temperature?​
readonly temperature?: number;
user?​
readonly user?: (input, ctx, config?) => Promise<string>;
Parameters​
input​

unknown

ctx​

BlockContext

config?​

PromptFileConfigView

Returns​

Promise<string>


PromptFileConfigView​

The post-resolution generator-config view exposed to templates as config. Constructed by the generator at call time — not the raw config the developer wrote. context is the aggregated tag map.

Properties​

caching?​
readonly caching?: CachingConfig;

Resolved caching config.

context​
readonly context: Record<string, string>;

Aggregated context tag map, keyed by XML tag name. Each value is the rendered string the framework would otherwise place inside the tag.

intent?​
readonly intent?: string;

Original intent string, if the generator declared one.

maxTokens?​
readonly maxTokens?: number;
model?​
readonly model?: string;

Resolved concrete model id (post-intent-resolution).

providerOptions?​
readonly providerOptions?: Record<string, unknown>;
temperature?​
readonly temperature?: number;
tools?​
readonly tools?: string[];

Resolved tool names.


PromptFileRenderScope​

Render scope passed to each section template. input + ctx match what a TypeScript prompt fn receives today; config is the template-only view.

Properties​

config​
readonly config: PromptFileConfigView;
ctx​
readonly ctx: BlockContext;
input​
readonly input: unknown;

Type Aliases​

BrandedPromptSlot​

type BrandedPromptSlot = ((input, ctx, config?) => Promise<string>) & object;

A prompt slot value that carries the PromptFile brand.

Type Declaration​

[PROMPT_FILE_BRAND]​
[PROMPT_FILE_BRAND]: PromptFileBrand;

PromptFileFilter​

type PromptFileFilter = (input, ...args) => unknown;

Liquid filter implementation. First argument is the piped value; the rest are filter arguments. May return a Promise (resolved by async render).

Parameters​

input​

unknown

args​

...unknown[]

Returns​

unknown


PromptFileFilters​

type PromptFileFilters = Record<string, PromptFileFilter>;

Custom Liquid filters, keyed by the name templates invoke them under.


PromptFileFrontmatterData​

type PromptFileFrontmatterData = z.infer<typeof PromptFileFrontmatter>;

PromptFilePartials​

type PromptFilePartials = Record<string, string>;

Pre-registered partials, keyed by the name {% render %} references them under (filename without the .md extension).

Variables​

DEFAULT_PROMPT_FILE_FILTERS​

const DEFAULT_PROMPT_FILE_FILTERS: PromptFileFilters;

The framework-provided filter set, keyed by the name templates invoke them under:

  • fsd_keyValues — object → key: value lines (one per line).
  • fsd_list — array → bullet list; pass "ordered" for a numbered list.
  • fsd_table — array of records → Markdown table; extra args fix the columns.
  • fsd_json — any value → a fenced ```json block, pretty-printed. An undefined value (e.g. an absent key in the lenient \<context\> engine) renders as null so the block stays valid JSON.

PROMPT_FILE_BRAND​

const PROMPT_FILE_BRAND: unique symbol;

Brand key carried on the prompt closure a PromptFile produces. The generator reads it to detect PromptFile-sourced prompts and route them through template-aware composition.


PromptFileFrontmatter​

const PromptFileFrontmatter: z.ZodObject<{
caching: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodObject<{
breakpoints: z.ZodOptional<z.ZodEnum<["auto", "manual"]>>;
enabled: z.ZodOptional<z.ZodBoolean>;
ttl: z.ZodOptional<z.ZodEnum<["5m", "1h"]>>;
}, "strict", z.ZodTypeAny, {
breakpoints?: "auto" | "manual";
enabled?: boolean;
ttl?: "1h" | "5m";
}, {
breakpoints?: "auto" | "manual";
enabled?: boolean;
ttl?: "1h" | "5m";
}>]>>;
description: z.ZodOptional<z.ZodString>;
intent: z.ZodOptional<z.ZodString>;
maxTokens: z.ZodOptional<z.ZodNumber>;
model: z.ZodOptional<z.ZodString>;
name: z.ZodOptional<z.ZodString>;
temperature: z.ZodOptional<z.ZodNumber>;
}, "strict", z.ZodTypeAny, {
caching?: | boolean
| {
breakpoints?: "auto" | "manual";
enabled?: boolean;
ttl?: "1h" | "5m";
};
description?: string;
intent?: string;
maxTokens?: number;
model?: string;
name?: string;
temperature?: number;
}, {
caching?: | boolean
| {
breakpoints?: "auto" | "manual";
enabled?: boolean;
ttl?: "1h" | "5m";
};
description?: string;
intent?: string;
maxTokens?: number;
model?: string;
name?: string;
temperature?: number;
}>;

Zod schema for prompt-file frontmatter. Metadata + scalar config only — no schemas, no tools, no capabilities (those stay in TypeScript).

Functions​

definePromptFile()​

function definePromptFile(promptFile): PromptFileConfig;

Wrap a PromptFile into the spreadable subset that slots into a generator config: { ...definePromptFile(pf), model, tools, ... }. Spread order wins on overlapping fields (e.g. an inline prompt after the spread overrides the file's prompt).

Parameters​

promptFile​

PromptFile

Returns​

PromptFileConfig


getPromptFileBrand()​

function getPromptFileBrand(value): PromptFileBrand | undefined;

Read the PromptFile brand off a prompt-slot value, if present. Scans array slots for the first branded entry. Returns undefined for inline prompts.

Parameters​

value​

unknown

Returns​

PromptFileBrand | undefined


isPromptFile()​

function isPromptFile(value): value is PromptFile;

Narrow an unknown value to a PromptFile: a parsed-file object whose prompt slot carries the brand. Distinguishes a whole PromptFile passed directly as a generator's prompt (prompt: pf) from a bare branded slot (prompt: pf.prompt), a string, a resolver function, or an array.

Parameters​

value​

unknown

Returns​

value is PromptFile


parsePromptFile()​

function parsePromptFile(text, options?): PromptFile;

Parse .md prompt-file text into a PromptFile.

Runs gray-matter over the text, validates frontmatter against the Zod schema, splits the body into role-tagged sections, and compiles each section as a LiquidJS template (custom filters and partials registered first). Section templates render per call against { input, ctx, config }.

Parameters​

text​

string

options?​

ParsePromptFileOptions

Returns​

PromptFile

Throws​

PromptFileParseError on frontmatter parse/validation failure, missing or duplicate <system>/<user>/<context> tags, an empty <system> block, an unknown filter, or a referenced partial that is not registered.