/** * `run_act { act, args }`: one act through the object's own `/v1/act` * dispatch, as the caller (an owner token as the owner, any other as staff). * The answer is the act's own `{ version, changed, made?, notices, token? }`; * a refusal is the dispatch's sentence, its code beside it. */import { isAct, ACTS } from"../../acts.ts";import { Refused } from"../../http.ts";import { fail, requireString, typeData, typeHandler, typeToolContext } from"../context.ts";asyncfunction runAct(ctx: ToolContext, args: Data): Promise<Data> {const names = Object.keys(ACTS).join(", ");const act = requireString(args, "act", `act is required: one of ${names}`);if (!isAct(act)) fail(`there is no act ${JSON.stringify(act)}: the acts are ${names}`, { code: "unknown_act" });const given = args.args;if (given !== undefined && given !== null && (typeof given !== "object" || Array.isArray(given))) fail("args must be an object: the act's own arguments");const actArgs = (given asData | null | undefined) ?? {};try {returnawait ctx.act(act, actArgs); } catch (error) {if (error instanceofRefused) fail(error.message, { code: error.code });throw error; }}exportconst ACTS_HANDLERS: Record<string, Handler> = { run_act: runAct };