tasks / app.tsmain at 90c6edb
// app.ts — THE TASKS APP, as config/worker.ts mounts it on tasks.<domain>: a board over the
// markdown files under todo/ in the repo that worker.ts points it at (`tasksApp({ repo })`), or in
// the repo of the mind that `?repo=` names. public/app.js says what the page does, and
// public/tasks-model.js how a file is read as a card. This file only serves the page: the board
// reads and commits through the member's own itx, so there is no backend class and no state here.
// The task sheet edits a file as the Docs app does, through the Docs app's processors
// (/repos/docs, processors/): /processors.json says where they are, in the Docs app's own words.
//
// The calls that an agent keeps a card with (`itx.config.taskOpen`, `taskUpdate`, `followTasks`,
// …) are the files beside this one (cards.js, feed.js, asks.js, askers.js, board.js): the mind's
// config gives each a method of its API (api.ts of /repos/config) and hands feed.js every event.
import { type AppDescription, serveFiles, type IterateConfigEntrypoint } from "iterate/sdk";
import { processorsAnswer } from "@repos/docs/app.ts";
import { openFile } from "@repos/stdlib/open-files.ts";
import theme from "@repos/stdlib/theme.css";
import index from "./index.html";
import files from "./public/";
/** What Tasks says of itself to anyone: the mind's sign-in pages show its name and icon. */
const TASKS: AppDescription = { name: "Tasks", icon: "/icon.svg", for: "members" };
/** `repo`: THE REPO THE BOARD POINTS AT, a path of this mind (`/repos/<name>`). The page shows
* the markdown files under `todo/` of it; `?repo=<name>` shows any other repo for one visit.
* `icon`: the answer for the mind's icon, which every app serves as its own
* (open-files.ts of /repos/stdlib).
* `retiredAgents`: the paths of agents that the mind retired. "Needs a person" marks an ask of
* one as maybe outdated, and asks the task's agent about it in its place. */
export function tasksApp({
repo,
icon,
retiredAgents = [],
}: {
repo: string;
icon: () => Response;
retiredAgents?: string[];
}) {
return {
/** The app's description and icon, for anyone: worker.ts asks this before its guard. */
open: (request: Request) => openFile(request, TASKS, icon),
/** Every request on the app's host. worker.ts guards it, so a member alone gets here. */
async fetch(request: Request, host: Pick<IterateConfigEntrypoint, "auth">) {
const url = new URL(request.url);
// Where the Docs processors' classes are and which version of them this commit holds: the
// answer the Docs app gives, so the task sheet and Docs start one doc's processors under
// one name and never as two copies.
if (url.pathname === "/processors.json") return Response.json(await processorsAnswer());
// the repo worker.ts points the board at: the page asks once, when it loads
if (url.pathname === "/board.json")
return Response.json({ repo, retiredAgents }, { headers: { "cache-control": "no-store" } });
// The page's own socket (/itx) and what @iterate-com/ui's shell asks of its host
// (/.auth/session.json, /.auth/minds.json, /.auth/logout).
const page = host.auth.memberPage(request);
if (page) return page;
// the app's own files, and the theme that every app of this mind shares
return serveFiles(request, { index, files: { ...files, "theme.css": theme } });
},
};
}