Primitives.org.ai

ai-workflows

Event-driven workflows with the $ context

npm install ai-workflows

Handle events, schedule tasks, and orchestrate processes through the unified $ context.

import { Workflow } from 'ai-workflows'

const workflow = Workflow($ => {
  $.on.Customer.created(async (customer, $) => {
    $.log('New customer:', customer.name)
    await $.send('Email.welcome', { to: customer.email })
  })

  $.every.Monday.at9am(async ($) => {
    $.log('Weekly standup reminder')
  })
})

await workflow.start()

Event Handling

Events follow the Noun.verb pattern:

$.on.Order.placed(handler)
$.on.Payment.completed(handler)
$.on.Customer.upgraded(handler)

Scheduling

Natural language scheduling:

$.every.hour(handler)
$.every.Monday.at9am(handler)
$.every.minutes(30)(handler)
$.every('first Monday of the month', handler)

Exports

ExportDescription
WorkflowCreate workflow with $ context
onStandalone event registration
everyStandalone scheduling
sendEmit events
createTestContextTesting utilities
Was this page helpful?

On this page