ui-calling

Show something and let the user act on it

Use it when the answer is easier to see than to read (an order's tracking steps, a booking, an invoice) and the user may want to change something from there.

Full example: the demo's order_status (npx ui-calling add order-status gives you a copy).

Contract

describe says what the user asked for; wake: true makes the agent react now. Small events that only add context stay quiet.

export const orderStatus = defineSurface({
  name: "order_status",
  description: "Live status of a customer's order... Use it when the user asks where their order is, when it arrives, or wants to change the delivery.",
  input: z.object({ order_id: z.string().describe("The order to show, e.g. A-1042") }),
  cta: { en: "View order", es: "Ver pedido" },
  data: z.object({ id: z.string(), status: z.enum([/* ... */]), eta: slot, rescheduleOptions: z.array(slot), /* ... */ }),
  events: {
    reschedule_delivery: event(slot, {
      describe: (p) => `User asked to move the delivery to ${p.date}, ${p.window}`,
      wake: true,
    }),
    viewed_items: event(z.object({}), { describe: () => "User expanded the item list" }),
  },
});

Server

Every action returns fresh data, and summarize turns it into the one line the agent reads. That line is how the outcome (the new date, a ticket number) reaches the agent.

export const orderStatusImpl = implement(orderStatus, {
  resolve: async ({ order_id }, ctx) => getOrder(order_id, ctx.subject),
  summarize: (o) => `Order ${o.id}: ${o.status}, delivery ${o.eta.date} ${o.eta.window} to ${o.address}. ...`,
  on: {
    reschedule_delivery: async (slot, ctx) => updateOrder(ctx.input.order_id, ctx.subject, { eta: slot }),
  },
});

Screen

const { status, data, emit, complete, returnUrl } = useSurface(orderStatus);
// ...
await emit("reschedule_delivery", slot); // data updates with what the handler returned
// "Back to chat" closes the link and tells the agent the user is done:
<a href={returnUrl} onClick={() => void complete()}>Back to chat</a>

Try it

With your dev server running, open it for a test user and see what the agent reads back:

npx ui-calling link order-status order_id=A-1042
npx ui-calling events

Watch out

In the ui-calling repo

Not in the package; for reading if you have the repo.

Source: packages/cli/recipes/show-and-act.md