Skip to content

Built-in flows

The flow seeded for each order type, how seeding works, and the dashboard scenarios that exercise them.

OrderLoop seeds one flow per order type. Each is an ordinary flow: open it in the editor, change it and publish a new version. The list below is rendered from TEMPLATES in packages/core/src/templates.ts, the same builders the seed publishes.

seedFlows (packages/db/src/flows.ts) publishes each template whose flow id doesn’t exist yet as version 1. It runs:

  • in the web app, through ensureSeeded(), the first time a worker isolate lists or loads flows (the dashboard, /flows, a flow page, GET /api/v1/flows) or starts an order with POST /api/v1/orders;
  • in the engine, through ensureTemplates(), before the Replenish Workflow starts a reorder.

Seeding never overwrites a flow that exists, so your edits survive. When a template changes in the code, the editor of a template-based flow offers the new graph as a proposal to review (see Building flows).

Purchase request

tpl-purchase-request

Internal procurement: AI spend classification, budget check, tiered approvals, PO, supplier acknowledgement, goods receipt, 3-way match and payment.

  • Order typePurchase request
  • Nodes20
  • Edges29
Nodes
IdLabelType
requestPurchase requestManual / API
classifyClassify spendClassify
pricePrice linesPrice & quote
budgetBudget checkBudget check
needs_mgrOver $5k?Condition
mgrManager approvalApproval
needs_finOver $20k?Condition
finFinance approvalApproval
poGenerate POGenerate PO
sendSend PO to supplierNotify
ackSupplier acknowledgesWait for event
goodsGoods receivedWait for event
match3-way match3-way match
mismatchResolve mismatchApproval
payPay supplierPay supplier
erpPost to ERPERP sync
doneClosedEnd
reject_noteTell requesterNotify
rejectedRejectedEnd
stalledSupplier unresponsiveEnd

B2B order

tpl-b2b-order

Inbound PO by email: AI extraction, contract pricing, credit check, an agent that triages to auto-approve / approval / clarify, stock reservation, net-30 invoice, shipment and a dunning loop.

  • Order typeB2B order
  • Nodes24
  • Edges30
Nodes
IdLabelType
po_inPO receivedInbound PO email
extractExtract orderExtract order
validateValidateValidate order
priceContract pricingPrice & quote
taxTaxCalculate tax
creditCredit checkCredit check
routerAgent: triageAgent router
clarifyAsk customerNotify
replyCustomer repliesWait for event
approvalSales approvalApproval
reserveReserve stockReserve inventory
invoiceInvoiceGenerate invoice
shipShipCreate shipment
erpPost to ERPERP sync
paidPayment receivedWait for event
dunningDunningLoop
remindPayment reminderNotify
paid_latePayment receivedWait for event
collectionsSend to collectionsNotify
donePaidEnd
unpaidUnpaidEnd
declineDecline orderNotify
declinedDeclinedEnd
backorderOut of stockEnd

Reorder

tpl-reorder

Scheduled replenishment: AI demand forecast for SKUs at their reorder point, PO generation, approval above $10k, supplier acknowledgement, receipt and restock.

  • Order typeReorder
  • Nodes16
  • Edges18
Nodes
IdLabelType
scheduleDaily stock reviewSchedule
forecastForecast demandDemand forecast
anyAnything to order?Condition
priceSupplier costPrice & quote
poReplenishment POGenerate PO
bigOver $10k?Condition
approvalBuyer approvalApproval
submitSubmit to supplierNotify
ackSupplier acknowledgesWait for event
receiptGoods receivedWait for event
restockRestockRestock
erpPost to ERPERP sync
doneRestockedEnd
nothingNothing to orderEnd
skipNot approvedEnd
lateSupplier lateEnd

Subscription

tpl-subscription

Recurring box subscription: authorize, then a billing-period loop (wait → charge → ship) with a dunning retry, continuing as a new run after 12 cycles.

  • Order typeSubscription
  • Nodes18
  • Edges19
Nodes
IdLabelType
signupSubscription signupWebhook
validateValidateValidate order
pricePlan pricePrice & quote
taxTaxCalculate tax
authorizeAuthorize cardAuthorize payment
welcomeWelcome emailNotify
initStart yearSet variables
periodsBilling periodsLoop
renewalUntil renewalWait
chargeCharge renewalCharge
retry_waitDunning delayWait
retryRetry chargeCharge
fulfillShip boxCreate shipment
nextNext cycleSet variables
pausePayment failedNotify
pausedPausedEnd
renewNext yearContinue as new
declinedCard declinedEnd

Storefront order

tpl-storefront-order

Card checkout: store policy, authorize, reserve, ship and capture, then a 30-day return window: RMA label, goods received, restock and a full or partial refund.

  • Order typeStorefront order
  • Nodes26
  • Edges26
Nodes
IdLabelType
checkoutStorefront checkoutWebhook
validateValidateValidate order
priceList pricePrice & quote
taxTaxCalculate tax
policyStore policyPolicy check
rejectExplain rejectionNotify
rejectedRejectedEnd
authorizeAuthorize cardAuthorize payment
reserveReserve stockReserve inventory
shipShipCreate shipment
captureCapture paymentCapture payment
shippedShipping confirmationNotify
windowReturn windowWait for event
rmaReturn labelReturn label
send_labelSend return labelNotify
backReturn receivedWait for event
restockRestockRestock
refundRefundRefund
refundedRefund confirmationNotify
reviewRefund needs reviewNotify
doneFulfilledEnd
returnedReturnedEnd
lostReturn not receivedEnd
declinedCard declinedEnd
shortOut of stockEnd
uncapturedCapture failedEnd

The dashboard’s Demo scenarios start an order on a seeded flow with a canned input (apps/web/app/lib/scenarios.ts). Each exercises a different path:

Scenario Flow Path
B2B PO by email tpl-b2b-order AI extracts lines from an email, contract pricing, the agent router auto-approves, ships, waits for payment
B2B over credit limit tpl-b2b-order cus_contoso is near its limit, so the credit check routes to a person
B2B out of stock tpl-b2b-order meta.simulate: "out_of_stock": the reservation comes up short and the order fails and rolls back
Purchase request tpl-purchase-request Eight laptops: AI classifies spend, manager then finance approve, PO, supplier ack, 3-way match
Reorder (stock review) tpl-reorder The forecast finds SKUs below their reorder point and drafts a replenishment PO
Subscription tpl-subscription Authorize, then a loop of wait → charge → ship
Subscription, card fails tpl-subscription meta.simulate: "charge_fail": the renewal and its retry both fail and the subscription pauses
Storefront order in euros tpl-storefront-order The storefront checkout in EUR: USD prices convert at the stored rate, and the order, capture and webhooks are in euros
Storefront order, returned tpl-storefront-order Ships and captures, then a return: RMA label, restock, refund. A return.requested payload with lines: [{ sku, qty }] restocks only those lines; amount sets a partial refund

The mock connectors read order.meta.simulate, so any order (from the API too) can take a failure path:

Value Effect
out_of_stock Reserve inventory reports every line short
payment_decline Authorize payment takes declined
charge_fail Charge takes failed
three_way_mismatch 3-way match sees an invoice 10% over the PO and takes mismatch

Restarting an order from its page drops meta.simulate, so the retry runs for real.

The Replenish Workflow runs daily (0 6 * * *, set in apps/engine/wrangler.jsonc). It scans for SKUs at or below their reorder point and, if there are any, starts one order on tpl-reorder titled Replenish <skus>. Run stock review now on the back office page starts it on demand.