@intellia/workflow-sdk
v0.3.2
Published
TypeScript authoring surface for Hutly workflows
Readme
@intellia/workflow-sdk
TypeScript authoring surface for Hutly workflows. A workflow is written as
ordinary TypeScript — statement order is execution order, and a node's output is
a typed handle, so wiring is checked by tsc before anything is deployed.
npm install @intellia/workflow-sdkA node
import { defineFunction, z } from "@intellia/workflow-sdk";
export default defineFunction({
name: "Summarise",
input: z.object({ text: z.string().max(2000) }),
output: z.object({ wordCount: z.number(), preview: z.string().max(120) }),
async run({ text }) {
return {
wordCount: text.split(/\s+/).filter(Boolean).length,
preview: text.slice(0, 120),
};
},
});A workflow
import { defineWorkflow, z } from "@intellia/workflow-sdk";
import summarise from "./nodes/summarise";
export default defineWorkflow({
name: "SDK smoke test",
slug: "sdk-smoke-test",
trigger: { type: "json", input: z.object({ text: z.string().max(2000) }) },
build(wf, trigger) {
const s = wf.function(summarise, { text: trigger.text });
return wf.output({ wordCount: s.wordCount, preview: s.preview });
},
});Compile it to deployable YAML with the Intellia CLI:
intellia workflow build --entry workflow.tsz is re-exported from this package so a workflow's schemas and the SDK share
one zod instance.
A schedule or a webhook
// schedules/nightly-sweep.schedule.ts
import { defineSchedule } from "@intellia/workflow-sdk";
export default defineSchedule({
slug: "nightly-sweep",
name: "Nightly sweep",
cronExpression: "cron(0 14 * * ? *)",
});Bind it from a workflow by importing the module, the same way a sub-workflow is referenced — the build compiles it to YAML beside its own source, so a renamed resource is a compile error rather than a broken path string:
import NightlySweep from "./schedules/nightly-sweep.schedule";
export default defineWorkflow({
// ...
triggers: { schedules: [{ schedule: NightlySweep, instructions: "Run the sweep" }] },
});slug is the identity a redeploy resolves by, and it is the only identity these
files carry — there is no id in the generated YAML, so it can be rebuilt from
source at any time. Omit it and deploy falls back to the slugified name, which
means renaming then retargets which row is updated.
Typechecking
Zero-config tsc defaults to an ES3 target, which zod's own declarations do not
compile against. Extend the config this package ships:
{ "extends": "@intellia/workflow-sdk/tsconfig.base.json", "include": ["**/*.ts"] }License
MIT
