Let a conversation's menu show the routines that run in it

The header menu had Tasks but nothing for the schedules whose results
land in that conversation. It now has Schedules, right under Tasks,
opened in a modal that lists only what runs there: a bot's own chat holds
the routines that run nowhere, a workspace only that bot's routines in
it (`routineScopeSql`, tested against SQLite).

The list loads when the modal opens, through
`api/admin/bots/list-routines`, which checks the user chats in that
conversation first, so the page props stay small. `grabCronJobs` gained
an optional `workspace_id`: left out it still means everywhere.

The routines page's row, form and edit modal moved to
`src/components/general/`, and its subtitle to `src/utils/`, since both
the page and the modal use them.
This commit is contained in:
2026-10-23 07:23:15 +01:00
parent 796c53716f
commit 5beb5f3de4
17 changed files with 566 additions and 18 deletions
@@ -1,6 +1,7 @@
import BunSQLite from "@moduletrace/bun-sqlite";
import type { CronJobWithNames } from "@/src/types";
import botFaceSql from "@/src/utils/bot-face-sql";
import routineScopeSql from "@/src/utils/routine-scope/routine-scope-sql";
type Params = {
user_id: number | string;
@@ -8,6 +9,12 @@ type Params = {
* Only this bot's.
*/
bot_id?: number | string;
/**
* With `bot_id`: only the routines of that conversation, here
* (`routineScopeSql`). `null` is the bot's own chat, so it has to be
* given rather than left out to mean "everywhere".
*/
workspace_id?: number | string | null;
/**
* Only this one.
*/
@@ -16,17 +23,30 @@ type Params = {
/**
* The user's schedules with their bot (its face as the user sees it) and
* workspace names, the next to
* run first and paused ones last.
* workspace names, the next to run first and paused ones last. Given a
* `bot_id` and a `workspace_id` (null for its own chat) it is one
* conversation's: the routines that run right there.
*/
export default async function grabCronJobs({ user_id, bot_id, cron_job_id }: Params): Promise<CronJobWithNames[]> {
export default async function grabCronJobs({
user_id,
bot_id,
workspace_id,
cron_job_id,
}: Params): Promise<CronJobWithNames[]> {
const face = botFaceSql({ user_id, prefix: "bot_" });
const where = [`c.user_id = ?`];
const values: (number | string)[] = [user_id];
if (bot_id) {
where.push(`c.bot_id = ?`);
values.push(bot_id);
if (workspace_id === undefined) {
where.push(`c.bot_id = ?`);
values.push(bot_id);
} else {
const scope = routineScopeSql({ bot_id, workspace_id });
where.push(scope.sql);
values.push(...scope.values);
}
}
if (cron_job_id) {