Skip to content

Verb functions

A Verb function file holds the Function behind one Verb, bound by its file name with no registration.

A file named [Noun].[verb].ts in nouns/ holds the Function behind one Verb. The file name binds it; nothing registers it.

  • nouns/
  • Lease.mdx
  • Lease.renew.tsruns Lease.renew

Reference

TypeScript with one default export. .sb/types/ declares the Noun, each Verb's input type and $ globally, so the file needs no import.

ExportTypeHolds
default(thing: Noun, input: NounVerbInput, $: $) => Promise<Output>The Function: the record, the Verb's typed input, and the client acting as this Function's Worker

The input type is named for the Noun and Verb: renew on Lease takes LeaseRenewInput, compiled from the Verb's entry in the Nouns file.

The kind is read from the code. $.Noun.verb() calls are code, $`…` is one model call, an Agent's tag such as rae`…` is agentic, and a person's tag is a human Task. The caller never sees which ran.

Examples

Minimal

nouns/Lease.renew.ts
export default async (lease: Lease, input: LeaseRenewInput, $: $) => {
  const end = new Date(lease.endsOn)
  end.setMonth(end.getMonth() + input.months)
  return $.Lease.update({ id: lease.$id, endsOn: end.toISOString().slice(0, 10) })
}

Leaseline

Leaseline declares a Lease Noun whose renew Verb takes months and an optional increase (the Nouns file declares them). Renewal extends the end date by the term and raises the rent within the increase the manager allows.

nouns/Lease.renew.ts
export default async (lease: Lease, input: LeaseRenewInput, $: $) => {
  const end = new Date(lease.endsOn)
  end.setMonth(end.getMonth() + input.months)
  const rent = lease.rent && { ...lease.rent, amount: Math.round(lease.rent.amount * (1 + (input.increase ?? 0))) }
  return $.Lease.update({ id: lease.$id, endsOn: end.toISOString().slice(0, 10), rent })
}

The Function never sets status, and update takes no status input. When the Action succeeds, the Verb's Event, Lease.renewed, moves the record to renewed.

What it builds

The SoftwareBuilder compiles the file into one Function Version for the Verb.

  • a Function with kind read from the code
  • each call returns one Action pinned to that Function Version, with input, output and cost
  • the Verb's Event, Lease.renewed, when the Action succeeds

Good to know

  • Without the file, the Verb runs its inherited or default Function.
  • A Verb has one body. This file and a Workflow on the same Verb fail the parse check together.
  • Functions cover cascades, durable steps and agentic kinds.