@dornick/hooks
v0.1.0
Published
Dornick hooks — programmatic and declarative lifecycle events for the in-browser agent SDK.
Readme
@dornick/hooks
Lifecycle hooks for the in-browser agent SDK.
An 18-event registry with veto + transform pipelines. Subscribe programmatically (dornick.on("event", handler)) or declaratively via a JSON config block in your Configuration (each event maps to webhook URLs or log lines).
Install
npm i @dornick/hooks@dornick/core already depends on this — install directly only if you're embedding the registry into your own runtime.
Events
sessionStart · sessionEnd · onUserMessage · beforeFieldFill · afterFieldFill · onFileUpload · onComplete · onError · beforeLLMCall · afterLLMCall · beforeExtract · afterExtract · onSkillActivate · onSkillAction · onPlanReady · onCompact · onHandoff · onAbandon.
Six of these are vetoable — return { veto: true, reason } from any handler to block:
onUserMessage · beforeFieldFill · onFileUpload · onSkillActivate · onSkillAction · onPlanReady.
Mutation-capable events let a handler return { mutation: { ... } } to transform the ctx before downstream handlers see it (e.g. lowercasing an email before fill, or rewriting extracted data).
Programmatic
dornick.on("beforeFieldFill", ({ field, value, source }) => {
if (field === "email" && !value.includes("@")) {
return { veto: true, reason: "needs @" };
}
if (source === "agent") {
return { mutation: { value: value.toLowerCase() } };
}
});
dornick.on("onComplete", async ({ data }) => {
await fetch("/api/save", { method: "POST", body: JSON.stringify(data) });
});dornick.on(event, handler) returns a disposer; call it to unsubscribe.
Declarative
In your Configuration:
{
"hooks": {
"onComplete": { "type": "webhook", "url": "https://example.com/done" },
"onFileUpload": { "type": "log", "level": "info", "prefix": "[upload]" },
"beforeFieldFill": [
{ "type": "webhook", "url": "/api/validate", "vetoOnNonOk": true }
]
}
}Supported declarative actions:
{ type: "webhook", url, method?, headers?, vetoOnNonOk?, timeoutMs? }— POSTs the event ctx as JSON.vetoOnNonOk: trueturns any non-2xx response into a veto.{ type: "log", level?, prefix? }— emits toconsole.{info,debug,warn}with an optional prefix.
Each event accepts a single hook or an array. They run in order, and a veto from any handler short-circuits the rest.
Ctx shapes
Every event has a typed ctx and (where applicable) mutation interface. Common ones:
sessionStart { configName: string; startedAt: number }
onUserMessage { text: string } → mutation: { text? }
beforeFieldFill { field, value, source } → mutation: { value? }
afterFieldFill { field, value }
onFileUpload { field, name, mimeType, size, base64 }
onComplete { data: Record<string, unknown> } → mutation: { data? }
onError { error: Error; during: string }
beforeLLMCall { model, provider, systemChars, messageCount, toolCount }
afterLLMCall { model, provider, inputTokens, outputTokens, stopReason, durationMs, ... }Full list: see packages/hooks/src/events.ts.
Links
License
MIT — © Dipankar Sarkar
