iterate.com / stdlib

git clone https://git.iterate.com/repos/stdlib

stdlib / init.tsmain at 41005ca

// init.ts — WHAT RUNS AT EVERY PUBLISH: config/worker.ts's `mind/worker-updated` case calls `init`.
//
// The platform appends `mind/worker-updated` on `/` whenever it publishes the mind's code, which
// is after a push to any repo that the code is loaded from. So these steps run again each time:
// each is idempotent. Each step runs by itself (`step`): a step that throws is reported, and the
// steps after it still run.
import { installAgents } from "iterate/agents/install";
import { reportIssue } from "iterate/lib";
import type { IterateConfigProcessEventArgs } from "iterate/sdk";

/** One step of the publish hook. A step that throws is reported (`config.publish-hook`, in the
 *  Workers' log, with the step's name) and does not stop the steps after it. */
export async function step(name: string, run: () => Promise<unknown>): Promise<void> {
  try {
    await run();
  } catch (error) {
    reportIssue("config.publish-hook", error, { step: name });
  }
}

export async function init(itx: IterateConfigProcessEventArgs<"agents">["itx"]) {
  // The agents: the catalog on /agents and the `itx.agents` rule. The collection's class is
  // exported by agents.ts of this repo, which the mind's code holds as the module
  // `stdlib/agents.ts`.
  await step("agents", () => installAgents(itx, { module: "stdlib/agents.ts" }));
}