Surface / foldkit-surface
Actions
An Action is a capability a consumer may invoke by name with data: an agent's
tool, a page Block's button. It ends in one of the application's own Messages,
so update stays the only place a Message has effects:
ts
import { Action } from 'foldkit-surface'
const AddToCart = Action.define({
name: 'addToCart',
description: 'Add a product to the cart',
input: Schema.Struct({ productId: ProductId }),
toMessage: input => Message.AddedToCart(input),
})
Action.run(AddToCart, { productId: 'p1' }) // Result: the Message, or why the input was refusedAction.run decodes the data as the Action's input before toMessage sees it,
so data from a Document or a tool call never executes. The Action is declared
once: Agent.action(AddToCart) exposes it to an agent, and a page's Catalog
lists it for Blocks to reference by name.