Events & Observability
Event handlers for progress tracking and observability.
Available events
Prop
Type
Example: progress bar
const result = await extract({
artifacts,
schema,
strategy: parallel({ model, mergeModel: model, chunkSize: 8000 }),
events: {
onStep: ({ step, total, label }) => {
process.stderr.write(`[${step}/${total ?? "?"}] ${label ?? "working"}\n`);
},
onTokenUsage: ({ totalTokens }) => {
process.stderr.write(`Tokens so far: ${totalTokens}\n`);
},
},
});Example: observe retries
const result = await extract({
artifacts,
schema,
strategy: simple({ model }),
events: {
onMessage: ({ role, content }) => {
if (role === "user" && String(content).includes("validation-errors")) {
console.log("Retry triggered");
}
},
},
});See also
- extract() — main extraction function
- Validation & Retries — validation concept