iterate.com / stdlib

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

stdlib / every-event.tsmain at 41005ca

// every-event.ts — WHAT LOOKS AT EVERY EVENT: config/worker.ts's `processEvent` calls `everyEvent`
// after its own cases, for each event of every context of the mind.
//
// The hooks run side by side. Each returns at once for an event that is not its own. One hook that
// fails does not stop the others: the first failure is thrown after all of them settled.
import type { IterateConfigProcessEventArgs } from "iterate/sdk";
import { agentKindEvent } from "./agent-kinds/agent.ts";
import { agentPrompt } from "./agent-prompt.ts";
import { contextDescriptionsEvent } from "./context-descriptions.ts";

export async function everyEvent(
  itx: IterateConfigProcessEventArgs<"agents">["itx"],
  event: IterateConfigProcessEventArgs["event"],
) {
  const hooks = await Promise.allSettled([
    // the mind's side of the agent: a person's words become the agent's input, and a request for
    // a subagent is answered (agent-kinds/agent.ts)
    agentKindEvent(itx, event),
    // the system prompt of a new agent, once, and again when its files change (agent-prompt.ts)
    agentPrompt(itx, event),
    // what each context is for, the line the mind's catalog shows (context-descriptions.ts)
    contextDescriptionsEvent(itx, event),
  ]);
  const failed = hooks.find((hook) => hook.status === "rejected");
  if (failed) throw failed.reason;
}