Skip to content

Author TypeScript workflows

The workflow’s authoritative definition is one TypeScript module. The browser offers a source editor, diagnostics, capability review, history, diffs, registry snippets, and a compiler-derived graph. AI agents are the primary authoring interface.

Browser edits remain local until you select Save. Invalid source remains in the editor, and txcast warns before navigation discards unsaved source.

import { defineWorkflow, schema } from "@txcast/workflow-sdk"
export default defineWorkflow({
name: "Wait for approval",
description: "Ask a member before continuing.",
input: schema.object({ amount: schema.uint256() }),
output: schema.object({ approvedAmount: schema.uint256() }),
capabilities: {
effects: ["human.confirm"],
networks: [],
controlledAccounts: [],
transactionTargets: {},
httpHosts: [],
notifications: false,
},
async run(ctx, input) {
const response = await ctx.human.confirm({
key: "approve-amount",
title: "Approve the amount",
description: `Approve ${input.amount.toString()} units`,
audience: "any_seated_member",
maxResultBytes: 4_096,
})
if (!response.confirmed) throw new Error("Amount was not approved")
return { approvedAmount: input.amount }
},
})

Input and output schemas drive the start form and validate values at every trust boundary. EVM integers arrive as native JavaScript bigint.

The capability envelope must cover every effect kind the program can reach:

  • EVM networks and controlled accounts;
  • transaction targets per chain;
  • HTTP host patterns;
  • notification channels and audiences.

Prefer exact allowlists. An input-bound account or address should also have a finite allow list when an agent credential has a restricted account grant.

  1. Validate source for compiler diagnostics and capability errors.
  2. Review the complete source, capability envelope, and diagnostics.
  3. Select Save with the latest workflow CAS.

A changed save validates, compiles, prepares the backend artifact, and appends the next immutable revision. The new revision becomes current immediately. Invalid source creates no persisted state. Canonically unchanged source creates no revision.

A version conflict keeps the local source. Read the current workflow, compare the source, and save again only after resolving the conflict. Never overwrite a newer revision without review.

Undo appends the previous source as a new revision. Restore appends any selected historical source as a new revision. Existing runs remain pinned to their selected revisions.

Only the owning seated member can change a workflow. Organisation owners and admins can inspect it but must fork to adapt it. A properly scoped agent acting for the owner may save. A fork creates a new owned workflow with its own valid Version 1. Losing the organisation seat archives the owned workflow without deleting its history or existing runs.