@oona/vlo / index / defineWorker
Function: defineWorker()
defineWorker(
impls,options?):Worker
Defined in: sdk/ts/sdk/src/host/worker/registry.ts:96
Defines a worker: a map from activity name to ActivityHandler plus the queues it serves. Passed to createHost({ workers }) for in-process execution, runPullWorker for long-polling, or found by the config loader's workers globs.
The worker holds no schemas; validation happens in the reducer (input) and on the host (output). Throws a TypeError when impls is empty.
Parameters
impls
options?
WorkerOptions = {}
Returns
Example
ts
import { defineWorker } from "@oona/vlo";
export default defineWorker(
{
"example.plan": (input: { n: number }) => ({
items: Array.from({ length: input.n }, (_, i) => `item-${i}`),
}),
"example.work": async (input: { item: string }, ctx) => {
await ctx.heartbeat();
ctx.reportUsage({ tokens: 12 });
return { upper: input.item.toUpperCase() };
},
},
{ queues: ["default"] },
);