OptionalartifactOptionalbackgroundOpt-in background-task TTL cleanup. When present, the purge cron
reaps terminal mastra_background_tasks rows past the TTL as its OWN
failure-isolated duty — the storage-layer belt to a hosting DO's manager
cleanup (which needs the DO alive). Absent => no duty, byte-identical
(background tasks are opt-in). NOT via extraPurgeDuties: this needs its own
try/catch and its own log fields, like every sibling purge duty.
OptionalbuildOpt-in authenticated agent catalog/run router. Structurally typed so this module does not import the server-only agent-host subpath.
OptionalbuildOpt-in goal-objective stage. Mirrors
buildSignalRouter: the host builds its createObjectiveRouter (which needs
the thread-state store from its D1 domains, plus its audit/maxRuns config)
and returns it here, closed over the request's resolved TenantResolver; the
composer mounts it after the signal stage. Both live under /api/threads/*
but do not overlap — goals use the /goal segment, signals the channel
segments. INJECTED rather than built here because createObjectiveRouter lives
in goals/, which imports host-kit — host-kit importing it back would cycle.
Absent (or returns undefined) ⇒ no goal stage, byte-identical.
OptionalbuildCompose approval-driven resume handling. Agent hosts use this to handle agent-thread targets and delegate generic workflow targets to fallback.
OptionalbuildOpt-in schedule CRUD facade. Mirrors buildSignalRouter/
buildObjectiveRouter: the host builds its createScheduleRouter (which needs
the schedules store from its D1 domains + its audit/cap config) and returns it
here, closed over the request's resolved TenantResolver; the composer mounts it
after the goal stage. Its /api/schedules/* routes don't overlap the others.
INJECTED (not built here, typed structurally) because createScheduleRouter
lives in schedules/, which transitively imports host-kit — importing it back
would cycle. Absent (or returns undefined) ⇒ no schedule surface, byte-identical.
OptionalbuildOpt-in signal-ingestion stage. The host builds its
createSignalRouter (which needs its per-thread DO namespace via
createThreadTopology, plus its audit/rate/allowlist config) and returns it
here, closed over the request's resolved TenantResolver; the composer mounts
it after preRoutes, ahead of approvals/runs (its /api/threads/* routes
don't overlap). INJECTED rather than built here because createSignalRouter
lives in signals/, which imports host-kit — host-kit importing it back
would cycle. Absent (or returns undefined) => no signal stage, byte-identical.
The identity seam: env -> TokenVerifier. Called once per fetch (and per scheduled notify), so hosts keep their own per-isolate memoization — re-parsing a token map on every request is pure waste, but that is the host's trade to make.
The cron expressions scheduled() dispatches on. sweep + purge are
required and must never share an invocation. tick is optional for
schedules: when set and scheduleTick is provided, the schedule tick runs
on it as its OWN failure-isolated invocation (a runaway fire pass gets its
own CPU budget, the same rationale that keeps sweep and purge apart). Keep
these byte-equal to wrangler.jsonc's triggers.crons; an unrecognized
expression runs the sweep + purge duties sequentially and logs a
config-error (availability beats purity on a misconfig). Absent tick ⇒ no
schedule-tick invocation, byte-identical.
OptionalextraExtra purge-cron duties (e.g. the showcase's demo-tenant reaper). The
returned fields fold into the ONE combined {type:'maintenance'} log
line. Isolated: a throw here logs a maintenance-error and never blocks
the combined log — though duties SHOULD own their try/catch so their
error surface stays specific.
OptionalnotifyReviewer-facing notification transport (ApprovalNotificationSink) for created records and SLA escalations. Built per invocation from env (transports usually need secrets); undefined = no notifications.
OptionalpreDeployment-specific routes tried AFTER /healthz and BEFORE the approval
and run routers (the showcase mounts its demo sign-in and sandbox reset
here). kit hands over the request's already-built resolver and DO
topology so a pre-route can share them (the reset route authenticates
through the same resolve). Return null to fall through.
OptionalscheduleOpt-in schedule tick. The host builds its createScheduleTick
(which needs the schedules store, its run-start seam — topology.start — and
the run-cap + audit config) and returns the closure here. The composer runs
it on the crons.tick cron as its OWN failure-isolated duty (own try/catch,
own schedule-tick log line). INJECTED (not built here, structurally typed as
() => Promise<unknown>) because createScheduleTick lives in schedules/,
which transitively imports host-kit — host-kit importing it back would cycle.
Absent (or crons.tick unset) ⇒ no tick invocation, byte-identical.
Id for system-created records (the bridge's record creator and the cron maintenance attribution). Must differ from human actor ids or the separation-of-duties check can never fire.
The catalog createRunRouter serves and gates (hosts pass their metas).
OptionalwrapWrap the tenant resolver (e.g. withSubdomainCrossCheck behind an env var).
OptionalwrapWrap the raw-resume thunk (metered like starts on budgeted hosts).
OptionalwrapWrap the run-start thunk (e.g. charge a budget BEFORE the DO round-trip).
When set, the retention purge (runPurgeMaintenance -> the built-in purgeExpiredWorkflowRuns) deletes each expired run's R2 artifacts WITH its snapshot row. The snapshot row is the only enumerable record of a run's artifact keys (R2 keys lead with workflowId — there is no run-level listing without it), so a retention purge without this pairing strands the run's artifacts beyond even purgeTenant's reach. Pass the same TenantArtifactPurger (an R2ArtifactStore) purgeTenant gets; undefined keeps the byte-identical row-only purge. NOT via extraPurgeDuties — that hook runs AFTER the rows are deleted, when the keys are already unenumerable.