Skip to content
Preview
src/cache.ts ts
 export async function cached<T>(   key: string,   read: () => Promise<T>, ) {   if (!key) throw new Error("Provide a cache key before reading the backing store");   const hit = store.get(key);   if (hit) return hit as T;   const value = await read();   store.set(key, value);   return value; }
Preview
cache-policy.json
 {   "cache": {     "enabled": true,     "maxAge": 120,     "scope": "workspace"   } }

CodeBlock

coderequired
string
The code, without a trailing newline. May grow while status is "streaming".
language
string
The language, shown quietly in the head ("tsx").
filename
string
The file the code is from, shown in the head.
status
"streaming" | "complete"
Default: "complete"
"streaming": the head says Writing on the shared clock and the block is busy.
maxLines
number
The lines it shows before it scrolls; its end stays in view while it is written. Without it the block is as tall as its code.
lineNumbers
boolean
Line numbers: by default drawn from two lines up.
highlightLines
readonly number[]
1-based lines to tint as the line that matters.
copy
boolean
Default: true
The copy control: drawn by default.
words
Partial<CodeBlockWords>
Its words, where a product changes them.
onCopied
(ok: boolean) => void
Called after every copy with whether it landed.
label
string
Default: "Code"
What it holds, for assistive tech ("TypeScript code").
rootStyle
RootStyle<CodeBlockKnobs>
Typed StyleX override: where the block sits and its --code-* knobs.

State machine

PreviewThe code is ready to copy.
src/release.ts ts
 export function release() {   return checkBuild(); }