iterate.com / onboarding

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

onboarding / events.tsmain at b65083a

// events.ts — THE ONBOARDING APP'S PART OF THE MIND'S EVENTS: the two calls that config/worker.ts
// makes, one in `processEvent` and one in `processMindEvent`. Each returns at once for an event
// that is not its own, and each case is idempotent.
// `iterate/agents` names the root `itx.agents` for the type-checker (its `InstalledAppRoots`).
import type {} from "iterate/agents";
import type { IterateConfigProcessEventArgs } from "iterate/sdk";
import { cloudHandoverEvent, iterateLetInEvent } from "./cloud-handover.ts";
import { onboardingEvent, onboardingMindEvent } from "./steps.ts";

type Args = IterateConfigProcessEventArgs<"agents">;

/** AN EVENT OF THE MIND (config/worker.ts `processEvent`, for every event):
 *  - what the owner told iterate Cloud at sign-up goes to the onboarding agent (cloud-handover.ts);
 *  - the owner's signed rule that lets iterate's mind in starts that agent's turn;
 *  - an event that a step hears moves its card (steps.ts): a secret, a rule, a publish.
 *  The hooks run side by side; the first failure is thrown after all of them settled. */
export async function onboardingEvents(itx: Args["itx"], event: Args["event"]) {
  const hooks = await Promise.allSettled([
    event.type === "events.iterate.com/cloud/installation-handed-over"
      ? cloudHandoverEvent(itx, event)
      : undefined,
    event.type === "events.iterate.com/mind-meld/configured"
      ? iterateLetInEvent(itx, event)
      : undefined,
    onboardingEvent(itx, event),
  ]);
  const failed = hooks.find((hook) => hook.status === "rejected");
  if (failed) throw failed.reason;
}

/** AN EVENT THAT ANOTHER MIND ADDED HERE, signed with its own key (config/worker.ts
 *  `processMindEvent`): iterate's mind lets this mind in, or grants its credit, on `/cloud` of its
 *  context here, and the step "Connect to iterate Cloud" goes on from it. Any other event does
 *  nothing, and this never throws (steps.ts `onboardingMindEvent`). Its words are data, never a
 *  member's instruction. */
export async function onboardingMindEvents(
  itx: IterateConfigProcessEventArgs["itx"],
  event: IterateConfigProcessEventArgs["event"],
) {
  await onboardingMindEvent(itx, event);
}