Guard / foldkit-guard
Agents
foldkit-guard/agent reads may from Remote's client Model for
foldkit-agent capability authorize and available checks so agents only
see and invoke actions the user can perform:
ts
import { Agent } from 'foldkit-agent'
import { GuardAgent } from 'foldkit-guard/agent'
const TodoAgent = Agent.forApplication(App).withPrincipal(G.Principal)
// The Todo an id names, read through `Row` from the client's Model.
const todo = Remote.select(Remote.at(Data, App.model.remote), Row)
TodoAgent.expose(Message, {
RequestedArchive: {
description: 'Archive a todo',
authorize: GuardAgent.authorize(Archive.key, ({ input, model }) => todo(input.id).read(model)),
available: GuardAgent.available(Archive.key, model => todo(model.selected).read(model)),
},
})Rowselectsmay. Missing or failed reads refuse dispatch; rules reading another row stay offered and defer to the server check.withPrincipal(G.Principal)aligns the agent's principal type with the server, which still enforces every write independently.