iterate.com / kernel

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

kernel / core / mind-worker / src / config.tsmain at 949894f

// config.ts — THE MIND WORKER'S SETTINGS: the config that every Worker of the mind gets
// (iterate/mind-config), and what this Worker alone is told: its key, the repos the mind is born
// with, which module of them is the mind's code, and the kernel commit it was built from.
import { redacted } from "iterate/app-config";
import { mindConfigOf } from "iterate/mind-config";
import { z } from "zod";

/** A repo that sits directly under `/repos`: `/repos/stdlib`. One level, so that the repos are
 *  siblings and a relative import between them means the same in every mind. */
export const RepoPath = z
  .string()
  .regex(/^\/repos\/[a-z0-9][a-z0-9-]*$/, "a repo path: /repos/<name>");

/** THE REPOS THAT A DEPLOY NAMES FOR A MIND, and which of them holds its code. */
export const MindRepos = z.object({
  /** The kernel's repo and the one that holds the mind's code, as a deploy names them at the
   *  mind's birth. At its first wake the mind makes each one that it does not have yet. One with
   *  an `origin` is cloned from that public git URL, with its history. One whose `origin` is null
   *  is made empty and gets its first commit by a push. The mind's other repos are named by the
   *  entry repo's own package.json, and are made at the same wake (mind/tree.ts `reposNamedIn`).
   *  A later deploy never touches a repo that exists: after birth a repo moves by git alone. */
  repos: z.array(z.object({ path: RepoPath, origin: z.url().nullable() })).min(1),
  /** `module` of the repo `repo` answers every request, mail and event. It names a file of
   *  another repo as `@repos/<repo>/<path>`. The mind publishes the newest commits of the repos
   *  that it loads from whenever one of them moves. */
  entry: z.object({ repo: RepoPath, module: z.string().min(1) }),
});
export type MindRepos = z.infer<typeof MindRepos>;

const own = {
  /** The key the mind signs with: its file URLs, its webhooks' addresses, and who a run is for.
   *  Set by the secret variable `ITERATE__SIGNING_KEY`. Read it with `.exposeSecret()` only where
   *  it signs or verifies. */
  signingKey: redacted(z.string().min(1)),
  ...MindRepos.shape,
  /** The kernel this stack was built from: the commit of the checkout that the deploy ran in,
   *  and whether that checkout had changes that no commit holds. The deploy reads both from
   *  git. */
  kernel: z.object({ commit: z.string().regex(/^[0-9a-f]{40}$/), dirty: z.boolean() }),
};

/** The Worker's config, which `mindConfigOf` parses once for each `env` object. */
export const mindWorkerConfigOf = (env: object) => mindConfigOf(env, own);