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.
Seeding
Section titled “Seeding”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 withPOST /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).
The flows
Section titled “The flows”Purchase request
tpl-purchase-requestInternal procurement: AI spend classification, budget check, tiered approvals, PO, supplier acknowledgement, goods receipt, 3-way match and payment.
- Order typePurchase request
- Nodes20
- Edges29
Nodes
| Id | Label | Type |
|---|---|---|
request | Purchase request | Manual / API |
classify | Classify spend | Classify |
price | Price lines | Price & quote |
budget | Budget check | Budget check |
needs_mgr | Over $5k? | Condition |
mgr | Manager approval | Approval |
needs_fin | Over $20k? | Condition |
fin | Finance approval | Approval |
po | Generate PO | Generate PO |
send | Send PO to supplier | Notify |
ack | Supplier acknowledges | Wait for event |
goods | Goods received | Wait for event |
match | 3-way match | 3-way match |
mismatch | Resolve mismatch | Approval |
pay | Pay supplier | Pay supplier |
erp | Post to ERP | ERP sync |
done | Closed | End |
reject_note | Tell requester | Notify |
rejected | Rejected | End |
stalled | Supplier unresponsive | End |
B2B order
tpl-b2b-orderInbound 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
| Id | Label | Type |
|---|---|---|
po_in | PO received | Inbound PO email |
extract | Extract order | Extract order |
validate | Validate | Validate order |
price | Contract pricing | Price & quote |
tax | Tax | Calculate tax |
credit | Credit check | Credit check |
router | Agent: triage | Agent router |
clarify | Ask customer | Notify |
reply | Customer replies | Wait for event |
approval | Sales approval | Approval |
reserve | Reserve stock | Reserve inventory |
invoice | Invoice | Generate invoice |
ship | Ship | Create shipment |
erp | Post to ERP | ERP sync |
paid | Payment received | Wait for event |
dunning | Dunning | Loop |
remind | Payment reminder | Notify |
paid_late | Payment received | Wait for event |
collections | Send to collections | Notify |
done | Paid | End |
unpaid | Unpaid | End |
decline | Decline order | Notify |
declined | Declined | End |
backorder | Out of stock | End |
Reorder
tpl-reorderScheduled 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
| Id | Label | Type |
|---|---|---|
schedule | Daily stock review | Schedule |
forecast | Forecast demand | Demand forecast |
any | Anything to order? | Condition |
price | Supplier cost | Price & quote |
po | Replenishment PO | Generate PO |
big | Over $10k? | Condition |
approval | Buyer approval | Approval |
submit | Submit to supplier | Notify |
ack | Supplier acknowledges | Wait for event |
receipt | Goods received | Wait for event |
restock | Restock | Restock |
erp | Post to ERP | ERP sync |
done | Restocked | End |
nothing | Nothing to order | End |
skip | Not approved | End |
late | Supplier late | End |
Subscription
tpl-subscriptionRecurring 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
| Id | Label | Type |
|---|---|---|
signup | Subscription signup | Webhook |
validate | Validate | Validate order |
price | Plan price | Price & quote |
tax | Tax | Calculate tax |
authorize | Authorize card | Authorize payment |
welcome | Welcome email | Notify |
init | Start year | Set variables |
periods | Billing periods | Loop |
renewal | Until renewal | Wait |
charge | Charge renewal | Charge |
retry_wait | Dunning delay | Wait |
retry | Retry charge | Charge |
fulfill | Ship box | Create shipment |
next | Next cycle | Set variables |
pause | Payment failed | Notify |
paused | Paused | End |
renew | Next year | Continue as new |
declined | Card declined | End |
Storefront order
tpl-storefront-orderCard 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
| Id | Label | Type |
|---|---|---|
checkout | Storefront checkout | Webhook |
validate | Validate | Validate order |
price | List price | Price & quote |
tax | Tax | Calculate tax |
policy | Store policy | Policy check |
reject | Explain rejection | Notify |
rejected | Rejected | End |
authorize | Authorize card | Authorize payment |
reserve | Reserve stock | Reserve inventory |
ship | Ship | Create shipment |
capture | Capture payment | Capture payment |
shipped | Shipping confirmation | Notify |
window | Return window | Wait for event |
rma | Return label | Return label |
send_label | Send return label | Notify |
back | Return received | Wait for event |
restock | Restock | Restock |
refund | Refund | Refund |
refunded | Refund confirmation | Notify |
review | Refund needs review | Notify |
done | Fulfilled | End |
returned | Returned | End |
lost | Return not received | End |
declined | Card declined | End |
short | Out of stock | End |
uncaptured | Capture failed | End |
Scenarios
Section titled “Scenarios”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 |
Simulating failures
Section titled “Simulating failures”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.
Stock review
Section titled “Stock review”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.