Line

You are reading the unreleased docs (next). See latest (v0.9)

packages/core/llm-fill

Shared "ask an LLM for one file's full text, but never trust it blindly" step, used by both import.mjs's per-file fill and generators.mjs's fillGeneratedFile.

Core engine, next. Source: packages/core/llm-fill.mjs.

Variables#

OUTPUT_CONTRACT#

const OUTPUT_CONTRACT: string

Defined in: packages/core/llm-fill.mjs:14

Functions#

extractCode()#

extractCode(raw): object

Defined in: packages/core/llm-fill.mjs:26

Pull the file text out of a model response. Order: the whole response is one fence -> its content; exactly one fenced block amid prose -> that block's content (how: 'fence-in-prose'); no fence at all -> the raw trimmed text; two or more fences -> ambiguous, so not guessed at (raw text is returned and will fail validation unless it happens to be code).

Parameters#

raw

any

Returns#

object

code

code: string

how

how: string = 'ambiguous-fences'


requestFileText()#

requestFileText(llm, prompt, llmOptions, __namedParameters?): Promise<{ attempts: number; code?: undefined; preview?: undefined; reason: any; status: string; } | { attempts: number; code: string; preview?: undefined; reason?: undefined; status: string; } | { attempts: number; code?: undefined; preview: string; reason: string; status: string; }>

Defined in: packages/core/llm-fill.mjs:64

Run prompt through llm and return one of: { status: 'filled', code, attempts } { status: 'rejected', reason, attempts, preview } — model answered, output isn't valid code { status: 'failed', reason, attempts } — the provider call itself threw { status: 'cancelled', reason, attempts } — the caller's AbortSignal fired; never retried At most ONE retry, and only after a rejection (a model that just proved it can be non-deterministic gets one corrected re-ask with the reason appended). A thrown provider error is never retried: a missing CLI, dead daemon or rate limit won't fix itself in the next second and a retry would double the cost of every failing file. Unknown-provider config errors (USAGE_ERROR) are rethrown — that's a mistake in the command, not a per-file failure.

Parameters#

llm

any

prompt

any

llmOptions

any

__namedParameters?
retryOnReject?

boolean = true

Returns#

Promise<{ attempts: number; code?: undefined; preview?: undefined; reason: any; status: string; } | { attempts: number; code: string; preview?: undefined; reason?: undefined; status: string; } | { attempts: number; code?: undefined; preview: string; reason: string; status: string; }>


whyNotCode()#

whyNotCode(code): string

Defined in: packages/core/llm-fill.mjs:36

null when code parses as TS/JS(X), else a short human-readable reason.

Parameters#

code

any

Returns#

string