importFoundation/// What a page act answers beside its own keys (Spec 11 (c), the shared/// rules): the receipt in the page's words and the call that takes the act/// back. The core decides both — the device and member acts/// (`methods/page_acts.rs`), a theme's save, a Mac's host switches — so a phone and a Mac say the same sentence and undo the same way.publicstructActAnswer: Sendable, Equatable {/// "Renamed to Studio Mac", "Removed Rhyn from this database".publicvar receipt: String?/// The call that puts it back; `nil` where nothing can (a removed device/// asks to join again).publicvar undo: ActUndo?publicstaticlet none = ActAnswer(receipt: nil, undo: nil)publicinit(receipt: String?, undo: ActUndo?) {self.receipt = receiptself.undo = undo }/// Read off an act's answer. An answer that says `undoable: false` offers/// no undo whatever else it carries; one with no `undoable` key (a/// database's rename) is undoable when it names its undo.publicinit(_ answer: JSONValue) { receipt = answer["receipt"]?.string.flatMap { $0.isEmpty ? nil : $0 }guard answer["undoable"]?.bool != false,let undo = answer["undo"], let method = undo["method"]?.string, !method.isEmptyelse {self.undo = nilreturn }self.undo = ActUndo(method: method, args: undo["args"] ?? .object([:])) }}/// `undo {method, args}`: the act that takes another back, called as given.publicstructActUndo: Sendable, Equatable {publiclet method: Stringpubliclet args: JSONValuepublicinit(method: String, args: JSONValue) {self.method = methodself.args = args }}extensionCottonCalling {/// Run an act and read its receipt and undo.publicfunc pageAct(_ method: String, _ request: someEncodable) asyncthrows -> ActAnswer {ActAnswer(tryawait callJSON(method, request)) }/// Take an act back: its undo, called as the core named it. Answers the/// undo's own receipt and undo (an undone rename can be redone).publicfunc takeBack(_ undo: ActUndo) asyncthrows -> ActAnswer {ActAnswer(tryawait callJSON(undo.method, undo.args)) }}